This is the mail archive of the
libc-help@sourceware.org
mailing list for the glibc project.
Re: RTLD DT_RUNPATH/DT_RPATH processing difference
- From: Vyacheslav Barinov <v dot barinov at samsung dot com>
- To: Carlos O'Donell <carlos at redhat dot com>
- Cc: libc-help at sourceware dot org, Merzlyakov Alexey <alexey dot merzlyakov at samsung dot com>
- Date: Thu, 29 Jun 2017 09:58:03 +0300
- Subject: Re: RTLD DT_RUNPATH/DT_RPATH processing difference
- Authentication-results: sourceware.org; auth=none
- Cms-type: 201P
- References: <CGME20170628100821eucas1p16f3dd4b36f8e472fa3898bedf83711ec@eucas1p1.samsung.com> <87d19otofi.fsf@samsung.com> <36ba4b3f-adf1-6294-ca10-52c5e4d7bbe9@redhat.com>
Carlos O'Donell <carlos@redhat.com> writes:
> 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?
Hello,
Yes, thank you very much for explanation and links, I think we'll use one of
options you mentioned.
Best Regards,
Vyacheslav Barinov