[PATCH] D42748: [ELF] Don't create a .dynamic section when linking with -Bstatic

Fangrui Song via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue May 21 06:11:41 PDT 2019


MaskRay added a comment.
Herald added a subscriber: atanasyan.
Herald added a project: LLVM.

@arichardson
If the MIPS problem was similar to https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=236165 ,
moving away from &_DYNAMIC will be a more reliable approach.
To check if an executable is dynamically linked, inspecting PT_INTERP is a better choice.

Checking if a weak undefined symbol has zero address is unreliale.
Some compilers may produce a GOT-generating relocation, some may produce an absolute relocation.
After linking, you may see the relocation resolved to static 0, or see a dynamic relocation (if at runtime there is some module providing the dynamic symbol, the weak reference will resolve to non-zero)

Quoting http://www.sco.com/developers/gabi/latest/ch4.symtab.html

> The behavior of weak symbols in areas not specified by this document is implementation defined. Weak symbols are intended primarily for use in system software. Applications using weak symbols are unreliable since changes in the runtime environment might cause the execution to fail.

Regarding this patch. Actually, -Bstatic (synonym of -static in ld.bfd and lld) just means: "don't look for libfoo.so when a -lfoo is seen, before next -Bdynamic". I think it is weird to use it to decide whether we should emit .dynamic . (In the compiler drivers (gcc/clang/etc), -static mean static linking, but that is different from -Bstatic/-static in ld.bfd/lld.)

This change neither improves similarity with ld.bfd nor makes behaviors reasonable that suits lld (the internals of lld are very different from ld.bfd, some behaviors of ld.bfd may not suit lld). The logic to emit .dynamic .dynsym .dynstr etc in the 3 linkers:

lld: has_dso || --shared || --pie || --export-dynamic
gold: has_dso || --shared || --pie
bfd: `(--shared || --pie) || ((not -r) && info->nointerp && (info->export_dynamic || info->dynamic))` && some (almost always true) conditions

@ed I want to knore more about your motivation to add --export-dynamic to the condition in D29982 <https://reviews.llvm.org/D29982>. Why do you need .dynamic in a position dependent executable for CloudABI, which has no shared object dependency on the linker command line?


Repository:
  rLLD LLVM Linker

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D42748/new/

https://reviews.llvm.org/D42748





More information about the llvm-commits mailing list