Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #108540

Re: Finding .so files without setting LD_LIBRARY_PATH

From Jussi Piitulainen <jussi.piitulainen@helsinki.fi>
Newsgroups comp.lang.python
Subject Re: Finding .so files without setting LD_LIBRARY_PATH
Date 2016-05-12 07:55 +0300
Organization A noiseless patient Spider
Message-ID <lf560ujlvt9.fsf@ling.helsinki.fi> (permalink)
References <1463002764.2579.26.camel@mad-scientist.net> <CACL+1at7pLfZ2bMe5FK6GT=GUFq18roqG14t+tV_TXQWftucBA@mail.gmail.com> <mailman.602.1463018971.32212.python-list@python.org>

Show all headers | View raw


eryk sun writes:

> On Wed, May 11, 2016 at 10:39 PM, Paul Smith wrote:
>> Hi all.  I have a locally-built version of Python (2.7.11) that I'm
>> copying around to different systems, running all different versions of
>> GNU/Linux.
> ...
>> What I'd like to do is have a way of setting the library path that
>> Python uses when it tries to load .so files (for example in the ssl
>> module which loads lib-dynload/_ssl.so which links to libssl.so and
>> libcrypto.so), WITHOUT setting LD_LIBRARY_PATH in the environment that
>> Python passes to its children.
>
> An ELF header can contain either an RPATH or a RUNPATH to extend the
> library search path at load time. RPATH is searched before
> LD_LIBRARY_PATH, while RUNPATH is searched after LD_LIBRARY_PATH. Note
> that the Linux loader only uses an embedded RUNPATH when searching for
> the immediate dependencies of an object. Use an RPATH instead if you
> need to extend the path that dlopen searches at runtime (e.g. for
> loading shared libraries via ctypes).
>
> Paths can be defined relative to the object using ${ORIGIN}. For
> example, the following configures a Python build to add a relative
> RPATH:
>
>     $ ./configure LDFLAGS='-Wl,-rpath,\$${ORIGIN}/lib'
>     $ make
>
> Or a RUNPATH:
>
>     $ ./configure LDFLAGS='-Wl,-rpath,\$${ORIGIN}/lib,--enable-new-dtags'
>     $ make
>
> Here's the resulting RPATH in the ELF header:
>
>     $ readelf -d python | grep RPATH
>      0x000000000000000f (RPATH)              Library rpath: [${ORIGIN}/lib]

There's a tool (GPLv3+) called patchelf that can set these in an ELF
binary:

https://nixos.org/patchelf.html
https://github.com/NixOS/patchelf

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Re: Finding .so files without setting LD_LIBRARY_PATH eryk sun <eryksun@gmail.com> - 2016-05-12 03:08 +0100
  Re: Finding .so files without setting LD_LIBRARY_PATH Jussi Piitulainen <jussi.piitulainen@helsinki.fi> - 2016-05-12 07:55 +0300
    Re: Finding .so files without setting LD_LIBRARY_PATH Paul Smith <paul@mad-scientist.net> - 2016-05-12 11:34 -0400

csiph-web