2

I have a Linux shared-object, which links dynamically with some shared-objects, and some of them in turn link dynamically further with additional shared-objects, requiring indirect dynamic linking. To find those SOs I embed an RPATH header into my top-level SO by passing linker flags to G++ as in:

 -Xlinker -rpath -Xlinker $ORIGIN/../my/libs

This works on both Ubuntu 16.04 and CentOS 7.x (with G++ 7.3 from DevToolset 7). However, when performing this build on Ubuntu 18.04, it embeds a RUNPATH header instead. Unlike RPATH, RUNPATH is only considered for finding SOs required by my top-level SO, but not for indirect dynamic linking of subsequent SOs that they require.

I've confirmed that the change from RPATH to RUNPATH causes the issue. When I use an SO built on Ubuntu 16.04, that has an RPATH header, indirect linking works properly. When I change the RPATH header to a RUNPATH header using chrpath -c, indirect linking breaks, on both Ubuntu 18.04 and Ubuntu 16.04.

How can I get the linker to use RPATH on Ubuntu 18.04? Alternatively, how can I accomplish the inverse of chrpath -c - change a RUNPATH header into an RPATH?

3
  • Possible duplicate of Dynamic linking with rpath not working under Ubuntu 17.10 Commented Aug 22, 2018 at 1:53
  • @EmployedRussian - I've narrowed the scope of the question to only deal with creating an RPATH header. Commented Aug 23, 2018 at 12:05
  • Wow, this question answers the problem I have (I was wondering about the difference of the indirect links based on the expirience, but was not able to find any info on it). Commented Jan 15, 2023 at 17:33

2 Answers 2

6

How can I get RUNPATH to be passed down to subsequent SOs during indirect linking?

As explained in this answer, you can't.

The best approach is to fix all libraries to be self-sufficient (have their own correct RUNPATH).

If you can't do that, use RPATH instead of RUNPATH, by adding -Wl,--disable-new-dtags to the link line.

Sign up to request clarification or add additional context in comments.

Comments

0

There is no good tool to do this, but you can manually edit the DT_RUNPATH byte of the dynamic section of the elf binary to 0, which will reverse the change of behavior.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.