This is the mail archive of the libc-help@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: RTLD DT_RUNPATH/DT_RPATH processing difference


On 06/28/2017 06:08 AM, Vyacheslav Barinov wrote:
> Hello,
> 
> Recently I started the migration from DT_RPATH to DT_RUNPATH in our distro in
> order to make the LD_LIBRARY_PATH work the right way, and detected that these
> two tags are processed differently in RTLD.
> 
> We have a loader which opens executables (pie ones) with dlopen() and then
> calls main(). This approach allows to speedup running application with large
> number library dependencies.
> 
> Usual application has the following structure:
> 
> app/
>     bin/app
>     lib/library.so
> 
> During the launch procedure 'bin/app' is opened by loader and executed through
> the dlopen().
> 
> In order to load the application-specific library.so the directory is changed
> to app/lib and 'loader' has DT_RPATH set to ":" to allow loading from current
> working directory.
> 
> After changing DT_RPATH to DT_RUNPATH the mechanism stopped working. I
> investigated the elf/dl-load.c and found that 'main_map' and dependent objects
> rpaths are only checked in case of DT_RPATH tag.
> 
> Can someone tell if this behavior is intended or not?

The behaviour is intended and is working as expected.

ELF TIS says:
~~~
The set of directories specified by a given DT_RUNPATH entry is used to find only the immediate dependencies of the executable or shared object containing the DT_RUNPATH entry. That is, it is used only for those dependencies contained in the DT_NEEDED entries of the dynamic structure containing the DT_RUNPATH entry, itself. One object's DT_RUNPATH entry does not affect the search for any other object's dependencies. 
~~~
http://www.sco.com/developers/gabi/latest/ch5.dynamic.html#shobj_dependencies

Therefore the DT_RUNPATH of the loader does not affect the paths used to search
for the dependencies of the application, and that applies to dlopen also.

Roland McGrath commented on this in 2002 (15 years ago):
https://sourceware.org/ml/libc-hacker/2002-11/msg00011.html

To get the behaviour you want you have two options:

(a) Use the prefix you computed as part of the string to dlopen.

(b) Use a DT_RUNPATH in the application which uses $ORIGIN.

Does that answer your question?

-- 
Cheers,
Carlos.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]