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?

Isac Casapu
  • 1,163
  • 13
  • 21
  • Possible duplicate of [Dynamic linking with rpath not working under Ubuntu 17.10](https://stackoverflow.com/questions/47117443/dynamic-linking-with-rpath-not-working-under-ubuntu-17-10) – Employed Russian Aug 22 '18 at 01:53
  • @EmployedRussian - I've narrowed the scope of the question to only deal with creating an RPATH header. – Isac Casapu Aug 23 '18 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). – xvorsx Jan 15 '23 at 17:33

1 Answers1

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.

Employed Russian
  • 199,314
  • 34
  • 295
  • 362