Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ctypes.CDLL fails on FreeBSD: ld-elf.so.1: Can't find module with TLS index 1 #92828

Open
yurivict opened this issue May 16, 2022 · 0 comments
Open
Labels
type-bug

Comments

@yurivict
Copy link

@yurivict yurivict commented May 16, 2022

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 that fails with the same error message.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-bug
Projects
None yet
Development

No branches or pull requests

1 participant