Re: ctypes.util.test() fails: _dlopen does not handle ld scripts

eryk sun <[email protected]> Fri, 30 Jun 2017 04:19:09 +0000
Newsgroups gmane.comp.python.ctypes
Message-ID <CACL+1augufEqS_Rp+RvpQt_zkpm3q-R-VJSOOoV1RBzs56K6FQ@mail.gmail.com>
On Thu, Jun 29, 2017 at 7:31 PM, Sebastian M. Ernst
<[email protected]> wrote:
>
> the test routine in ctypes.util fails - across multiple Python versions.
> I am studying ctypes code to better understand it and found it this way.
> The problem occurs in CPython 2.7, 3.4 and 3.6(.1) - I attached two
> examples below this email. The error is identical:
> OSError: /usr/lib64/libm.so: invalid ELF header

libm.so is a linker script that's used when linking an executable or
shared library. You can read about it via `man ld` or online. The
libm.so script specifies a group consisting of /lib64/libm.so.6,
/usr/lib64/libmvec_nonshared.a, and /lib64/libmvec.so.1, with the
latter added as an ELF header DT_NEEDED tag only if it sources a
required symbol and isn't included already by other needed libraries.

The ctypes test is wrong. The runtime loader searches LD_LIBRARY_PATH
(if defined), DT_RUNPATH of the executable (if defined), the loader
cache file, "/etc/ld.so.cache", and finally the system
architecture-specific /lib and /usr/lib. It finds libm.so in
/usr/lib64, but the correct library name is libm.so.6 in /lib64. For
example:

    >>> from ctypes.util import find_library
    >>> find_library('m')
    'libm.so.6'

    >>> find_library('mvec')
    'libmvec.so.1'

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot