[lld] r328299 - [ELF] - Another fix for "LLD crashes with --emit-relocs when trying to proccess .eh_frame"
George Rimar via llvm-commits
llvm-commits at lists.llvm.org
Fri Mar 23 02:18:31 PDT 2018
Author: grimar
Date: Fri Mar 23 02:18:31 2018
New Revision: 328299
URL: http://llvm.org/viewvc/llvm-project?rev=328299&view=rev
Log:
[ELF] - Another fix for "LLD crashes with --emit-relocs when trying to proccess .eh_frame"
This fixes PR36367 which is about segfault when --emit-relocs is
used together with .eh_frame sections which happens because
of reordering of regular and .rel[a] sections.
Path changes loop that iterates over input sections to create
relocation target sections first.
Differential revision: https://reviews.llvm.org/D44679
Added:
lld/trunk/test/ELF/emit-relocs-eh-frame.s
lld/trunk/test/ELF/linkerscript/eh-frame-emit-relocs.s
Modified:
lld/trunk/ELF/LinkerScript.cpp
lld/trunk/test/ELF/emit-relocs-shared.s
lld/trunk/test/ELF/emit-relocs.s
Modified: lld/trunk/ELF/LinkerScript.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/LinkerScript.cpp?rev=328299&r1=328298&r2=328299&view=diff
==============================================================================
--- lld/trunk/ELF/LinkerScript.cpp (original)
+++ lld/trunk/ELF/LinkerScript.cpp Fri Mar 23 02:18:31 2018
@@ -629,11 +629,11 @@ static OutputSection *addInputSec(String
void LinkerScript::addOrphanSections() {
unsigned End = SectionCommands.size();
StringMap<OutputSection *> Map;
-
std::vector<OutputSection *> V;
- for (InputSectionBase *S : InputSections) {
+
+ auto Add = [&](InputSectionBase *S) {
if (!S->Live || S->Parent)
- continue;
+ return;
StringRef Name = getOutputSectionName(S);
@@ -645,12 +645,25 @@ void LinkerScript::addOrphanSections() {
if (OutputSection *Sec =
findByName(makeArrayRef(SectionCommands).slice(0, End), Name)) {
Sec->addSection(cast<InputSection>(S));
- continue;
+ return;
}
if (OutputSection *OS = addInputSec(Map, S, Name))
V.push_back(OS);
assert(S->getOutputSection()->SectionIndex == UINT32_MAX);
+ };
+
+ // For futher --emit-reloc handling code we need target output section
+ // to be created before we create relocation output section, so we want
+ // to create target sections first. We do not want priority handling
+ // for synthetic sections because them are special.
+ for (InputSectionBase *IS : InputSections) {
+ if ((IS->Type == SHT_REL || IS->Type == SHT_RELA) &&
+ !isa<SyntheticSection>(IS))
+ if (auto *Rel = cast<InputSection>(IS)->getRelocatedSection())
+ if (auto *RelIS = dyn_cast_or_null<InputSectionBase>(Rel->Parent))
+ Add(RelIS);
+ Add(IS);
}
// If no SECTIONS command was given, we should insert sections commands
Added: lld/trunk/test/ELF/emit-relocs-eh-frame.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/emit-relocs-eh-frame.s?rev=328299&view=auto
==============================================================================
--- lld/trunk/test/ELF/emit-relocs-eh-frame.s (added)
+++ lld/trunk/test/ELF/emit-relocs-eh-frame.s Fri Mar 23 02:18:31 2018
@@ -0,0 +1,16 @@
+# REQUIRES: x86
+# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t1.o
+# RUN: ld.lld --emit-relocs %t1.o -o %t
+# RUN: llvm-readobj -r %t | FileCheck %s
+
+# CHECK: Relocations [
+# CHECK-NEXT: Section {{.*}} .rela.eh_frame {
+# CHECK-NEXT: 0x{{.*}} R_X86_64_PC32 .text 0x0
+# CHECK-NEXT: }
+# CHECK-NEXT: ]
+
+.text
+.globl foo
+foo:
+ .cfi_startproc
+ .cfi_endproc
Modified: lld/trunk/test/ELF/emit-relocs-shared.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/emit-relocs-shared.s?rev=328299&r1=328298&r2=328299&view=diff
==============================================================================
--- lld/trunk/test/ELF/emit-relocs-shared.s (original)
+++ lld/trunk/test/ELF/emit-relocs-shared.s Fri Mar 23 02:18:31 2018
@@ -7,10 +7,10 @@
.quad foo
# CHECK: Relocations [
-# CHECK-NEXT: Section (4) .rela.dyn {
+# CHECK-NEXT: Section {{.*}} .rela.dyn {
# CHECK-NEXT: 0x1000 R_X86_64_64 foo 0x0
# CHECK-NEXT: }
-# CHECK-NEXT: Section (8) .rela.data {
+# CHECK-NEXT: Section {{.*}} .rela.data {
# CHECK-NEXT: 0x1000 R_X86_64_64 foo 0x0
# CHECK-NEXT: }
# CHECK-NEXT: ]
Modified: lld/trunk/test/ELF/emit-relocs.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/emit-relocs.s?rev=328299&r1=328298&r2=328299&view=diff
==============================================================================
--- lld/trunk/test/ELF/emit-relocs.s (original)
+++ lld/trunk/test/ELF/emit-relocs.s Fri Mar 23 02:18:31 2018
@@ -13,7 +13,7 @@
# CHECK: Section {
# CHECK: Index: 2
-# CHECK-NEXT: Name: .rela.text
+# CHECK: Name: .rela.text
# CHECK-NEXT: Type: SHT_RELA
# CHECK-NEXT: Flags [
# CHECK-NEXT: SHF_INFO_LINK
Added: lld/trunk/test/ELF/linkerscript/eh-frame-emit-relocs.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/linkerscript/eh-frame-emit-relocs.s?rev=328299&view=auto
==============================================================================
--- lld/trunk/test/ELF/linkerscript/eh-frame-emit-relocs.s (added)
+++ lld/trunk/test/ELF/linkerscript/eh-frame-emit-relocs.s Fri Mar 23 02:18:31 2018
@@ -0,0 +1,13 @@
+# REQUIRES: x86
+# RUN: echo "SECTIONS { .foo : { *(.eh_frame) } }" > %t.script
+# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o
+# RUN: ld.lld --emit-relocs %t.o -T %t.script -o %t
+# RUN: llvm-objdump -section-headers %t | FileCheck %s
+
+# CHECK-NOT: eh_frame
+# CHECK: .rela.foo
+# CHECK-NOT: eh_frame
+
+.text
+ .cfi_startproc
+ .cfi_endproc
More information about the llvm-commits
mailing list