This fixes https://llvm.org/bugs/show_bug.cgi?id=23036
Details
Diff Detail
Event Timeline
Sample output:
davide@rabbit1:/exps/llvm/build/bin % ./clang test.c -shared -Wl,-rpath=/plop -Wl,--disable-new-dtags -o test1.so
davide@rabbit1:/exps/llvm/build/bin % readelf --dynamic ./test1.so | grep PATH
0x000000000000000f (RPATH) Library rpath: [/plop]
davide@rabbit1:/exps/llvm/build/bin % ./clang test.c -shared -Wl,-rpath=/plop -Wl,--enable-new-dtags -o test1.so
davide@rabbit1:/exps/llvm/build/bin % readelf --dynamic ./test1.so | grep PATH
0x000000000000001d (RUNPATH) Library runpath: [/plop]
include/lld/ReaderWriter/ELFLinkingContext.h | ||
---|---|---|
295 | This is not a popular option, so please add more comments on this feature for readers of this code. We should mention that, if the flag is set, we emit DT_RUNPATH instead of DT_RPATH. They are functionally equivalent, but the former has lower precedence than the latter (in terms of other variables like LD_LIBRARY_PATH). | |
297 | Both functions sound like setters of the variable. Maybe we should name the getter getEnableNewDTags? It's not consistent with the others, but in most places we use "get" for getters. | |
lib/Driver/GnuLdDriver.cpp | ||
629 | I prefer this if (parseArgs->hasArg(OPT_enable_newdtags)) ctx->setEnableNewDtags(true); |
include/lld/ReaderWriter/ELFLinkingContext.h | ||
---|---|---|
295 | There is another difference according to a thread[1] on switching gold to enable it by default : DT_RUNPATH is used only for direct dependencies, while DT_RPATH is also used for indirect dependencies. [1] https://sourceware.org/ml/binutils/2014-02/msg00031.html |
It is actually a very popular option, it is mostly hidden because for example:
- clang for instance is always passing --enable-new-dtags by default.
- Gentoo activates it by default https://sources.gentoo.org/cgi-bin/viewvc.cgi/gentoo/src/patchsets/binutils/2.25/76_all_use-new-ld-dtags.patch?diff_format=s&view=log&pathrev=HEAD
--new-enable-dtags has been made to workaround an issue
- Dragonfly BSD is another example: http://gitweb.dragonflybsd.org/dragonfly.git/commit/0d2ea3af92127a10961ca1d0332ec09bb20d5703
this option has been made to allow to workaround issues with DT_RPATH by allowing to make it respect LD_LIBRARY_PATH useful for example for inplace regression test in build system
It is only popular on system that implemented the same brain-dead LD_LIBRARY_PATH behavior as glibc did.
Anyways, my point is that the change to the linker for this feature might
be trivial, so it'd be easy to understand what is done here. But it would
not help readers of the code understand why we want to do that. So I wanted
to add a comment on that (a brief comment should suffice).
LGTM
lib/ReaderWriter/ELF/OutputELFWriter.h | ||
---|---|---|
283 | You can remove parentheses around _ctx.getEnableNewDtags(). |
Note that the brain-dead LD_LIBRARY_PATH is required by the spec (gabi41.pdf, pg 93). I'm not sure if Solaris actually implemented that though, or if it was just a documentation bug.
I wonder if we should just enable DT_RUNPATH for all targets where we know the rtld supports it.
This is not a popular option, so please add more comments on this feature for readers of this code. We should mention that, if the flag is set, we emit DT_RUNPATH instead of DT_RPATH. They are functionally equivalent, but the former has lower precedence than the latter (in terms of other variables like LD_LIBRARY_PATH).