This is an archive of the discontinued LLVM Phabricator instance.

[ELF] - Prevent relocation overflow against .bss in some cases.
AbandonedPublic

Authored by grimar on Jul 4 2018, 2:27 AM.

Details

Summary

This is https://bugs.llvm.org/show_bug.cgi?id=38037

When we add files:
https://github.com/llvm-mirror/lld/blob/master/ELF/Driver.cpp#L1267

We might add "COMMON" input sections, which are later
changes their name to ".bss" (in getOutputSectionName):
https://github.com/llvm-mirror/lld/blob/master/ELF/SymbolTable.cpp#L461
and placed to ".bss" output section.

Since we are adding the files first,
it results in such ".bss" created out of order and placed
at the start. Itself it is not a huge issue, perhaps, but the problem
appears when such "COMMON" sections (common symbols) are huge.

In PR, usr/lib/gcc/x86_64-linux-gnu/5.4.0/crtbegin.o is the first
in the command line and it has a R_X86_64_PC32 relocation against its own ".bss".
But because of LLD, which places huge input ".bss" created for user's SHN_COMMON symbol
at the beginning of the output section, relocation overflows.

The patch fixes the issue by moving all early created synthetics to the end of the input sections list.

Diff Detail

Event Timeline

grimar created this revision.Jul 4 2018, 2:27 AM
ruiu added a comment.Jul 5 2018, 11:02 AM

I doubt if the benefit of this patch exceeds the increased complexity. Isn't this a corner case where no one can really say this is a bug? Can't you simply fix your linker script instead of lld?

grimar added a comment.Jul 6 2018, 1:13 AM

I doubt if the benefit of this patch exceeds the increased complexity. Isn't this a corner case where no one can really say this is a bug?

GNU linkers have no problems with supporting that. If the user wants to create a large common symbol, why not?
It is an unlucky specific of our implementation that we create "COMMON" input sections out of order in the first place.
If we would create sections in the same order as objects are specified in the command line, we would not have this issue.

Isn't another our patches that try to workaround possible relocations overflow do something the same (reordering the sections)?

Can't you simply fix your linker script instead of lld?

There is no linker script used in the initial PR.

grimar abandoned this revision.Sep 21 2018, 4:42 AM
azat added a subscriber: azat.Oct 17 2021, 10:57 AM