Re: [ctypes-users] ctypes.util.test() fails: _dlopen does not handle ld scripts
Brought to you by:
theller
From: eryk s. <er...@gm...> - 2017-06-30 04:19:57
|
On Thu, Jun 29, 2017 at 7:31 PM, Sebastian M. Ernst <er...@pl...> 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' |