[lld] r259831 - Don't push relocation sections onto InputSection<ELFT>::Discarded.RelocSections
Sean Silva via llvm-commits
llvm-commits at lists.llvm.org
Thu Feb 4 13:41:08 PST 2016
Author: silvas
Date: Thu Feb 4 15:41:07 2016
New Revision: 259831
URL: http://llvm.org/viewvc/llvm-project?rev=259831&view=rev
Log:
Don't push relocation sections onto InputSection<ELFT>::Discarded.RelocSections
Summary:
LLVM3.3 (and earlier) would fail to include a relocation section in
the group that the section it was relocating is in. Object files
affected by this issue have been encountered in the wild when using LLD.
This would result in a siutation like:
Section {
Index: 5
Name: .text._Z3fooIiEvv (6)
Type: SHT_PROGBITS (0x1)
Flags [ (0x206)
SHF_ALLOC (0x2)
SHF_EXECINSTR (0x4)
SHF_GROUP (0x200)
]
Address: 0x0
Offset: 0x48
Size: 5
Link: 0
Info: 0
AddressAlignment: 1
EntrySize: 0
}
Section {
Index: 6
Name: .rela.text._Z3fooIiEvv (1)
Type: SHT_RELA (0x4)
Flags [ (0x0)
]
Address: 0x0
Offset: 0x3F0
Size: 24
Link: 8
Info: 5
AddressAlignment: 8
EntrySize: 24
}
In LLD, during symbol resolution, we discard the section containing the
weak symbol, but this amounts to replacing it with
InputSection<ELFT>::Discarded.
When we later saw the corresponding relocation section, we would then
end up pusing onto InputSection<ELFT>::Discarded.RelocSections, which is
bogus.
Reviewers: ruiu, rafael
Subscribers: llvm-commits, Bigcheese
Differential Revision: http://reviews.llvm.org/D16898
Added:
lld/trunk/test/ELF/Inputs/llvm33-rela-outside-group.o
lld/trunk/test/ELF/llvm33-rela-outside-group.s
Modified:
lld/trunk/ELF/InputFiles.cpp
Modified: lld/trunk/ELF/InputFiles.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputFiles.cpp?rev=259831&r1=259830&r2=259831&view=diff
==============================================================================
--- lld/trunk/ELF/InputFiles.cpp (original)
+++ lld/trunk/ELF/InputFiles.cpp Thu Feb 4 15:41:07 2016
@@ -214,6 +214,11 @@ void ObjectFile<ELFT>::initializeSection
fatal("Invalid relocated section index");
InputSectionBase<ELFT> *RelocatedSection =
Sections[RelocatedSectionIndex];
+ // Strictly speaking, a relocation section must be included in the
+ // group of the section it relocates. However, LLVM 3.3 and earlier
+ // would fail to do so, so we gracefully handle that case.
+ if (RelocatedSection == &InputSection<ELFT>::Discarded)
+ continue;
if (!RelocatedSection)
fatal("Unsupported relocation reference");
if (auto *S = dyn_cast<InputSection<ELFT>>(RelocatedSection)) {
Added: lld/trunk/test/ELF/Inputs/llvm33-rela-outside-group.o
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/Inputs/llvm33-rela-outside-group.o?rev=259831&view=auto
==============================================================================
Binary files lld/trunk/test/ELF/Inputs/llvm33-rela-outside-group.o (added) and lld/trunk/test/ELF/Inputs/llvm33-rela-outside-group.o Thu Feb 4 15:41:07 2016 differ
Added: lld/trunk/test/ELF/llvm33-rela-outside-group.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/llvm33-rela-outside-group.s?rev=259831&view=auto
==============================================================================
--- lld/trunk/test/ELF/llvm33-rela-outside-group.s (added)
+++ lld/trunk/test/ELF/llvm33-rela-outside-group.s Thu Feb 4 15:41:07 2016
@@ -0,0 +1,11 @@
+// Input file generated with:
+// llvm33/llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %S/Inputs/llvm33-rela-outside-group.o
+//
+// RUN: ld.lld -shared %S/Inputs/llvm33-rela-outside-group.o %S/Inputs/llvm33-rela-outside-group.o
+
+ .global bar
+ .weak _Z3fooIiEvv
+
+ .section .text._Z3fooIiEvv,"axG", at progbits,_Z3fooIiEvv,comdat
+_Z3fooIiEvv:
+ callq bar
More information about the llvm-commits
mailing list