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

Konstantin Belousov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue May 21 06:33:53 PDT 2019


kib added a comment.

In D42748#1510087 <https://reviews.llvm.org/D42748#1510087>, @MaskRay wrote:

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


Perhaps first you should define what features of static binaries you depend on.  In fact PT_INTERP is not absolutely needed to have any of the dynamic feature, in principle rtld.c can be linked from crt1.o.  And if we (FreeBSD) decide to support dlopen(3) from static binaries, this is what would happen.  We already got a small dynamic linker in crt1.o to support ifunc relocations.

Absence of the DYNAMIC segment is rather good indication that a lot of dynamic features are indeed not used, so &_DYNAMIC == 0 is probably quite good check except that it is broken.


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