This is an archive of the discontinued LLVM Phabricator instance.

[GNU] Implement --enable-new-dtags/--disable-new-dtags
ClosedPublic

Authored by davide on Apr 5 2015, 6:37 PM.

Diff Detail

Event Timeline

davide updated this revision to Diff 23262.Apr 5 2015, 6:37 PM
davide retitled this revision from to [GNU] Implement --enable-new-dtags/--disable-new-dtags.
davide updated this object.
davide edited the test plan for this revision. (Show Details)
davide added reviewers: ruiu, shankarke.
davide set the repository for this revision to rL LLVM.
davide added a project: lld.
davide added a subscriber: Unknown Object (MLST).

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]

emaste added a subscriber: emaste.Apr 5 2015, 7:34 PM
ruiu added inline comments.Apr 5 2015, 7:38 PM
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);
emaste added inline comments.Apr 6 2015, 10:12 AM
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

bapt added a subscriber: bapt.Apr 6 2015, 10:32 AM

It is actually a very popular option, it is mostly hidden because for example:

--new-enable-dtags has been made to workaround an issue

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

joerg added a subscriber: joerg.Apr 6 2015, 2:11 PM

It is only popular on system that implemented the same brain-dead LD_LIBRARY_PATH behavior as glibc did.

ruiu edited edge metadata.Apr 6 2015, 2:16 PM

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

davide updated this revision to Diff 23294.Apr 6 2015, 2:35 PM
davide edited edge metadata.
davide removed rL LLVM as the repository for this revision.

Updated.

davide set the repository for this revision to rL LLVM.Apr 6 2015, 2:36 PM
ruiu accepted this revision.Apr 6 2015, 2:38 PM
ruiu edited edge metadata.

LGTM

lib/ReaderWriter/ELF/OutputELFWriter.h
283

You can remove parentheses around _ctx.getEnableNewDtags().

This revision is now accepted and ready to land.Apr 6 2015, 2:38 PM
davide closed this revision.Apr 6 2015, 2:51 PM
emaste added a comment.Apr 6 2015, 3:42 PM
In D8836#152189, @joerg wrote:

It is only popular on system that implemented the same brain-dead LD_LIBRARY_PATH behavior as glibc did.

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.