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);
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
--- /dev/null
+# 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
.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: ]
--- /dev/null
+# 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