New GitHub issue #92828 from yurivict:<br>

<hr>

<pre>
This code fails on FreeBSD 13 with Python-3.8:
```
import os
import sys
import ctypes
from ctypes.util import find_library

_RTLD_NOLOAD = os.RTLD_NOLOAD
_SYSTEM_UINT = ctypes.c_uint64 if sys.maxsize > 2 ** 32 else ctypes.c_uint32
_SYSTEM_UINT_HALF = ctypes.c_uint32 if sys.maxsize > 2 ** 32 else ctypes.c_uint16

class _dl_phdr_info(ctypes.Structure):
    _fields_ = [
        ("dlpi_addr", _SYSTEM_UINT),  # Base address of object
        ("dlpi_name", ctypes.c_char_p),  # path to the library
        ("dlpi_phdr", ctypes.c_void_p),  # pointer on dlpi_headers
        ("dlpi_phnum", _SYSTEM_UINT_HALF),  # number of elements in dlpi_phdr
    ]

def match_library_callback(info, size, data):
    print("match_library_callback")
    # Get the path of the current library
    filepath = info.contents.dlpi_name
    if filepath:
        filepath = filepath.decode("utf-8")

        # Store the library controller if it is supported and selected
        self._make_controller_from_path(filepath)
        return 0

libc_name = find_library("c")
print("libc_name="+libc_name)
libc = ctypes.CDLL(libc_name, mode=_RTLD_NOLOAD)

c_func_signature = ctypes.CFUNCTYPE(
            ctypes.c_int,  # Return type
            ctypes.POINTER(_dl_phdr_info),
            ctypes.c_size_t,
            ctypes.c_char_p,
)
c_match_library_callback = c_func_signature(match_library_callback)
data = ctypes.c_char_p(b"")

libc.dl_iterate_phdr(c_match_library_callback, data) # failing line
```

It fails with the message:
```
ld-elf.so.1: Can't find module with TLS index 1
```

This code is from the Python library  [threadpoolctl](https://github.com/joblib/threadpoolctl/issues/125) that fails with the same error message.
</pre>

<hr>

<a href="https://github.com/python/cpython/issues/92828">View on GitHub</a>
<p>Labels: type-bug</p>
<p>Assignee: </p>