[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
Wed May 22 02:19:23 PDT 2019


kib added a comment.

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

> From the description
>
> > This also causes a .dynamic section, the _DYNAMIC symtbol and a PT_DYNAMIC header to be added to the output file. This causes problems for example when trying to run such a binary on FreeBSD MIPS.
>
> What I know is just that the presence of `_DYNAMIC` caused a problem but I don't have more information why it caused the problem. Without more information I can only conjecture. My intuition says it is more likely a problem if the dynamic is absent in some scenarios, I don't understand how the presence (though probably unexpected by you) caused a problem.


The C Runtime (cumulative of crt1.o and libc.so/libc.a) contains a lot of code like `if (&_DYNAMIC != NULL)` used as a test for the static/dynamic situation.  Look at the https://github.com/freebsd/freebsd/blob/master/lib/csu/amd64/crt1.c#L62, there are many more.  I believe it was mentioned many times in the discussion.

> 
> 
>> 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.
> 
> @kib So to answer your question, I need more information.
> 
>> And if we (FreeBSD) decide to support dlopen(3) from static binaries
> 
> And if you decide to support static pie, you also need `_DYNAMIC`.

Are you sure about this ?  For static PIE, as I understand, we miss some kind of relocator in  csu.  For the relocator to work, all we need is to find the relocation section' boundaries.  See for instance https://github.com/freebsd/freebsd/blob/master/lib/csu/common/ignore_init.c#L52 how we find iplt relocations in static binaries.  I would expect that a similar approach works for non-iplt.


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