This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: ld and rpath in .so
- From: Carlos O'Donell <carlos at redhat dot com>
- To: Andrew Bell <andrew dot bell dot ia at gmail dot com>, Binutils <binutils at sourceware dot org>
- Date: Wed, 23 Jan 2019 20:20:29 -0500
- Subject: Re: ld and rpath in .so
- References: <CACJ51z2ztXJQZoLcSDscgXhT-pMmu0983e_vXApt1B6TWnMTRA@mail.gmail.com> <CACJ51z3-E_UKp1_W=GN6iyN5=+CDcbmBZN2NgRoPqyEZ4KR0Lg@mail.gmail.com>
On 1/23/19 7:58 PM, Andrew Bell wrote:
> I have learned that the conda toolchain is built as a cross-toolchain,
> which I believe explains ld ignoring rpath for secondary dependencies.
A cross-toolchain should not ignore rpath, but it may be setup to honour
a sysroot prefix which is pre-pended to the rpath.
> Thanks for reading.
>
> On Wed, Jan 23, 2019, 5:38 PM Andrew Bell <andrew.bell.ia@gmail.com wrote:
>
>> Hi,
>>
>> My understanding is that ld will use the RPATH in a shared object to
>> locate secondary shared objects when linking an executable.
Which link? Static link or dynamic link?
At static link time it's the value of -Wl,-rpath or -Wl,-rpath-link.
At dynamic link time it's the value of DT_RPATH in the dyanmic section.
>> I'm trying to build a conda package and this doesn't seem to be
>> happening. I can use readelf to verify that the RPATH is set in the linked
>> library to point to the directory containing the secondary libraries, but
>> when I link my executable with the linked library, I get an error saying
>> that the secondary libraries can't be found. Using -rpath-link on the
>> command line to explicitly specify the path that's embedded in the linked
>> library rpath resolves the issue (though -rpath on the command line
>> fails). I'm using ld through g++ 7.3.
You have this backward. Using -rpath embeds the path via DT_RPATH, but
using -rpath-link does not.
Searching -rpath for a cross-linker *requires* --with-sysroot.
>> Is there some circumstance that would cause ld to ignore the
>> rpath embedded in a linked library when attempting to locate a NEEDED
>> item? Am I misunderstanding something in the way ld locates secondary
>> libraries?
Yes, you need a sysroot path.
--
Cheers,
Carlos.