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?
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.