[lld] r287280 - Always compute sh_link for SHF_LINK_ORDER sections.
Rafael Espindola via llvm-commits
llvm-commits at lists.llvm.org
Thu Nov 17 15:16:39 PST 2016
Author: rafael
Date: Thu Nov 17 17:16:39 2016
New Revision: 287280
URL: http://llvm.org/viewvc/llvm-project?rev=287280&view=rev
Log:
Always compute sh_link for SHF_LINK_ORDER sections.
Since the output has a section table too, it is meaningful to compute
the sh_link. In a more practical note, the binutils' strip crashes if
sh_link is not set for SHT_ARM_EXIDX.
Added:
lld/trunk/test/ELF/arm-exidx-link.s
Modified:
lld/trunk/ELF/OutputSections.cpp
lld/trunk/test/ELF/arm-exidx-canunwind.s
lld/trunk/test/ELF/arm-exidx-order.s
lld/trunk/test/ELF/arm-exidx-output.s
Modified: lld/trunk/ELF/OutputSections.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/OutputSections.cpp?rev=287280&r1=287279&r2=287280&view=diff
==============================================================================
--- lld/trunk/ELF/OutputSections.cpp (original)
+++ lld/trunk/ELF/OutputSections.cpp Thu Nov 17 17:16:39 2016
@@ -400,25 +400,19 @@ OutputSection<ELFT>::OutputSection(Strin
}
template <class ELFT> void OutputSection<ELFT>::finalize() {
- if (!Config->Relocatable) {
- // SHF_LINK_ORDER only has meaning in relocatable objects
- this->Flags &= ~SHF_LINK_ORDER;
- return;
- }
-
- uint32_t Type = this->Type;
if ((this->Flags & SHF_LINK_ORDER) && !this->Sections.empty()) {
- // When doing a relocatable link we must preserve the link order
- // dependency of sections with the SHF_LINK_ORDER flag. The dependency
- // is indicated by the sh_link field. We need to translate the
- // InputSection sh_link to the OutputSection sh_link, all InputSections
- // in the OutputSection have the same dependency.
+ // We must preserve the link order dependency of sections with the
+ // SHF_LINK_ORDER flag. The dependency is indicated by the sh_link field. We
+ // need to translate the InputSection sh_link to the OutputSection sh_link,
+ // all InputSections in the OutputSection have the same dependency.
if (auto *D = this->Sections.front()->getLinkOrderDep())
this->Link = D->OutSec->SectionIndex;
}
- if (Type != SHT_RELA && Type != SHT_REL)
+ uint32_t Type = this->Type;
+ if (!Config->Relocatable || (Type != SHT_RELA && Type != SHT_REL))
return;
+
this->Link = In<ELFT>::SymTab->OutSec->SectionIndex;
// sh_info for SHT_REL[A] sections should contain the section header index of
// the section to which the relocation applies.
Modified: lld/trunk/test/ELF/arm-exidx-canunwind.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/arm-exidx-canunwind.s?rev=287280&r1=287279&r2=287280&view=diff
==============================================================================
--- lld/trunk/test/ELF/arm-exidx-canunwind.s (original)
+++ lld/trunk/test/ELF/arm-exidx-canunwind.s Thu Nov 17 17:16:39 2016
@@ -76,8 +76,9 @@ _start:
// CHECK-PT: Name: .ARM.exidx
// CHECK-PT-NEXT: Type: SHT_ARM_EXIDX (0x70000001)
-// CHECK-PT-NEXT: Flags [ (0x2)
-// CHECK-PT-NEXT: SHF_ALLOC (0x2)
+// CHECK-PT-NEXT: Flags [
+// CHECK-PT-NEXT: SHF_ALLOC
+// CHECK-PT-NEXT: SHF_LINK_ORDER
// CHECK-PT-NEXT: ]
// CHECK-PT-NEXT: Address: 0x100D4
// CHECK-PT-NEXT: Offset: 0xD4
Added: lld/trunk/test/ELF/arm-exidx-link.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/arm-exidx-link.s?rev=287280&view=auto
==============================================================================
--- lld/trunk/test/ELF/arm-exidx-link.s (added)
+++ lld/trunk/test/ELF/arm-exidx-link.s Thu Nov 17 17:16:39 2016
@@ -0,0 +1,24 @@
+// RUN: llvm-mc -filetype=obj -triple=armv7a-none-linux-gnueabi %s -o %t.o
+// RUN: ld.lld %t.o -o %t.so -shared
+// RUN: llvm-readobj -s %t.so | FileCheck %s
+
+// CHECK: Name: .ARM.exidx
+// CHECK-NEXT: Type: SHT_ARM_EXIDX
+// CHECK-NEXT: Flags [
+// CHECK-NEXT: SHF_ALLOC
+// CHECK-NEXT: SHF_LINK_ORDER
+// CHECK-NEXT: ]
+// CHECK-NEXT: Address:
+// CHECK-NEXT: Offset:
+// CHECK-NEXT: Size:
+// CHECK-NEXT: Link: [[INDEX:.*]]
+
+// CHECK: Index: [[INDEX]]
+// CHECK-NEXT: Name: .text
+
+
+ f:
+ .fnstart
+ bx lr
+ .cantunwind
+ .fnend
Modified: lld/trunk/test/ELF/arm-exidx-order.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/arm-exidx-order.s?rev=287280&r1=287279&r2=287280&view=diff
==============================================================================
--- lld/trunk/test/ELF/arm-exidx-order.s (original)
+++ lld/trunk/test/ELF/arm-exidx-order.s Thu Nov 17 17:16:39 2016
@@ -103,8 +103,9 @@ f3:
// the .ARM.exidx output section
// CHECK-PT: Name: .ARM.exidx
// CHECK-PT-NEXT: Type: SHT_ARM_EXIDX (0x70000001)
-// CHECK-PT-NEXT: Flags [ (0x2)
-// CHECK-PT-NEXT: SHF_ALLOC (0x2)
+// CHECK-PT-NEXT: Flags [
+// CHECK-PT-NEXT: SHF_ALLOC
+// CHECK-PT-NEXT: SHF_LINK_ORDER
// CHECK-PT-NEXT: ]
// CHECK-PT-NEXT: Address: 0x100D4
// CHECK-PT-NEXT: Offset: 0xD4
Modified: lld/trunk/test/ELF/arm-exidx-output.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/arm-exidx-output.s?rev=287280&r1=287279&r2=287280&view=diff
==============================================================================
--- lld/trunk/test/ELF/arm-exidx-output.s (original)
+++ lld/trunk/test/ELF/arm-exidx-output.s Thu Nov 17 17:16:39 2016
@@ -35,8 +35,9 @@ f2:
// CHECK: Section {
// CHECK: Name: .ARM.exidx
// CHECK-NEXT: Type: SHT_ARM_EXIDX (0x70000001)
-// CHECK-NEXT: Flags [ (0x2)
-// CHECK-NEXT: SHF_ALLOC (0x2)
+// CHECK-NEXT: Flags [
+// CHECK-NEXT: SHF_ALLOC
+// CHECK-NEXT: SHF_LINK_ORDER
// CHECK-NEXT: ]
// CHECK-NOT: Name: .ARM.exidx.text.f1
More information about the llvm-commits
mailing list