<NME> arm-exidx-output.s
<BEF> // REQUIRES: arm
// RUN: llvm-mc -filetype=obj -triple=armv7a-none-linux-gnueabi %s -o %t
// RUN: ld.lld %t -o %t2
// RUN: llvm-readobj --sections %t2 | FileCheck %s

// Check that only a single .ARM.exidx output section is created when
// there are input sections of the form .ARM.exidx.<section-name>. The
// assembler creates the .ARM.exidx input sections with the .cantunwind
// directive
 .syntax unified
 .section .text, "ax",%progbits
 .globl _start
_start:
 .fnstart
 bx lr
 .cantunwind
 .fnend

 .section .text.f1, "ax", %progbits
 .globl f1
f1:
 .fnstart
 bx lr
 .cantunwind
 .fnend

 .section .text.f2, "ax", %progbits
 .globl f2
f2:
 .fnstart
 bx lr
 .cantunwind
 .fnend

// CHECK:         Section {
// CHECK:         Name: .ARM.exidx
// CHECK-NEXT:    Type: SHT_ARM_EXIDX (0x70000001)
// CHECK-NEXT:    Flags [ (0x2)
// CHECK-NEXT:      SHF_ALLOC (0x2)
// CHECK-NEXT:    ]

// CHECK-NOT:     Name: .ARM.exidx.text.f1
// CHECK-NOT:     Name: .ARM.exidx.text.f2

<MSG> 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.

git-svn-id: f6089bf0e6284f307027cef4f64114ee9ebb0424@287280 91177308-0d34-0410-b5e6-96231b3b80d8

<DFF> @@ -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

{'commit': 'diff --git a/ELF/OutputSections.cpp b/ELF/OutputSections.cpp\nindex f0b1ecef9..4bf95294a 100644\n--- a/ELF/OutputSections.cpp\n+++ b/ELF/OutputSections.cpp\n@@ -400,25 +400,19 @@ OutputSection<ELFT>::OutputSection(StringRef Name, uint32_t Type, uintX_t Flags)\n }\n \n template <class ELFT> void OutputSection<ELFT>::finalize() {\n-  if (!Config->Relocatable) {\n-    // SHF_LINK_ORDER only has meaning in relocatable objects\n-    this->Flags &= ~SHF_LINK_ORDER;\n-    return;\n-  }\n-\n-  uint32_t Type = this->Type;\n   if ((this->Flags & SHF_LINK_ORDER) && !this->Sections.empty()) {\n-    // When doing a relocatable link we must preserve the link order\n-    // dependency of sections with the SHF_LINK_ORDER flag. The dependency\n-    // is indicated by the sh_link field. We need to translate the\n-    // InputSection sh_link to the OutputSection sh_link, all InputSections\n-    // in the OutputSection have the same dependency.\n+    // We must preserve the link order dependency of sections with the\n+    // SHF_LINK_ORDER flag. The dependency is indicated by the sh_link field. We\n+    // need to translate the InputSection sh_link to the OutputSection sh_link,\n+    // all InputSections in the OutputSection have the same dependency.\n     if (auto *D = this->Sections.front()->getLinkOrderDep())\n       this->Link = D->OutSec->SectionIndex;\n   }\n \n-  if (Type != SHT_RELA && Type != SHT_REL)\n+  uint32_t Type = this->Type;\n+  if (!Config->Relocatable || (Type != SHT_RELA && Type != SHT_REL))\n     return;\n+\n   this->Link = In<ELFT>::SymTab->OutSec->SectionIndex;\n   // sh_info for SHT_REL[A] sections should contain the section header index of\n   // the section to which the relocation applies.\ndiff --git a/test/ELF/arm-exidx-canunwind.s b/test/ELF/arm-exidx-canunwind.s\nindex 746348011..0607ce332 100644\n--- a/test/ELF/arm-exidx-canunwind.s\n+++ b/test/ELF/arm-exidx-canunwind.s\n@@ -76,8 +76,9 @@ _start:\n \n // CHECK-PT:          Name: .ARM.exidx\n // CHECK-PT-NEXT:     Type: SHT_ARM_EXIDX (0x70000001)\n-// CHECK-PT-NEXT:     Flags [ (0x2)\n-// CHECK-PT-NEXT:       SHF_ALLOC (0x2)\n+// CHECK-PT-NEXT:     Flags [\n+// CHECK-PT-NEXT:       SHF_ALLOC\n+// CHECK-PT-NEXT:       SHF_LINK_ORDER\n // CHECK-PT-NEXT:     ]\n // CHECK-PT-NEXT:     Address: 0x100D4\n // CHECK-PT-NEXT:     Offset: 0xD4\ndiff --git a/test/ELF/arm-exidx-link.s b/test/ELF/arm-exidx-link.s\nnew file mode 100644\nindex 000000000..005bfff20\n--- /dev/null\n+++ b/test/ELF/arm-exidx-link.s\n@@ -0,0 +1,24 @@\n+// RUN: llvm-mc -filetype=obj -triple=armv7a-none-linux-gnueabi %s -o %t.o\n+// RUN: ld.lld %t.o -o %t.so -shared\n+// RUN: llvm-readobj -s %t.so | FileCheck %s\n+\n+// CHECK:      Name: .ARM.exidx\n+// CHECK-NEXT: Type: SHT_ARM_EXIDX\n+// CHECK-NEXT: Flags [\n+// CHECK-NEXT:   SHF_ALLOC\n+// CHECK-NEXT:   SHF_LINK_ORDER\n+// CHECK-NEXT: ]\n+// CHECK-NEXT: Address:\n+// CHECK-NEXT: Offset:\n+// CHECK-NEXT: Size:\n+// CHECK-NEXT: Link: [[INDEX:.*]]\n+\n+// CHECK:      Index: [[INDEX]]\n+// CHECK-NEXT: Name: .text\n+\n+\n+        f:\n+\t.fnstart\n+\tbx\tlr\n+\t.cantunwind\n+\t.fnend\ndiff --git a/test/ELF/arm-exidx-order.s b/test/ELF/arm-exidx-order.s\nindex 416c50f9d..5f6dbebec 100644\n--- a/test/ELF/arm-exidx-order.s\n+++ b/test/ELF/arm-exidx-order.s\n@@ -103,8 +103,9 @@ f3:\n // the .ARM.exidx output section\n // CHECK-PT:          Name: .ARM.exidx\n // CHECK-PT-NEXT:     Type: SHT_ARM_EXIDX (0x70000001)\n-// CHECK-PT-NEXT:     Flags [ (0x2)\n-// CHECK-PT-NEXT:       SHF_ALLOC (0x2)\n+// CHECK-PT-NEXT:     Flags [\n+// CHECK-PT-NEXT:       SHF_ALLOC\n+// CHECK-PT-NEXT:       SHF_LINK_ORDER\n // CHECK-PT-NEXT:     ]\n // CHECK-PT-NEXT:     Address: 0x100D4\n // CHECK-PT-NEXT:     Offset: 0xD4\ndiff --git a/test/ELF/arm-exidx-output.s b/test/ELF/arm-exidx-output.s\nindex 49bbb6c69..dca43a359 100644\n--- a/test/ELF/arm-exidx-output.s\n+++ b/test/ELF/arm-exidx-output.s\n@@ -35,8 +35,9 @@ f2:\n // CHECK:         Section {\n // CHECK:         Name: .ARM.exidx\n // CHECK-NEXT:    Type: SHT_ARM_EXIDX (0x70000001)\n-// CHECK-NEXT:    Flags [ (0x2)\n-// CHECK-NEXT:      SHF_ALLOC (0x2)\n+// CHECK-NEXT:    Flags [\n+// CHECK-NEXT:      SHF_ALLOC\n+// CHECK-NEXT:      SHF_LINK_ORDER\n // CHECK-NEXT:    ]\n \n // CHECK-NOT:     Name: .ARM.exidx.text.f1\n', 'commit_subject': 'Always compute sh_link for SHF_LINK_ORDER sections.', 'repo_name': 'llvm-mirror/lld', 'committer': {'name': 'Rafael Espindola', 'email': '6b31706989f3cf9466bfddbf48eab0c43e646ba8@gmail.com', 'time_sec': '1479424599', 'tz_offset': '0', 'date': {'seconds': '1479424599'}}, 'commit_tree': '0cd39c8493305bb0a43c443a9bb750ddaf80ca3d', 'commit_message': "Always compute sh_link for SHF_LINK_ORDER sections.\n\nSince the output has a section table too, it is meaningful to compute\nthe sh_link. In a more practical note, the binutils' strip crashes if\nsh_link is not set for SHT_ARM_EXIDX.\n\ngit-svn-id: f6089bf0e6284f307027cef4f64114ee9ebb0424@287280 91177308-0d34-0410-b5e6-96231b3b80d8\n", 'language_name': 'Python', 'license': 'apache-2.0', 'hunks': '@@ -35,8 +35,9 @@ f2:\n // CHECK:         Section {\n // CHECK:         Name: .ARM.exidx\n // CHECK-NEXT:    Type: SHT_ARM_EXIDX (0x70000001)\n-// CHECK-NEXT:    Flags [ (0x2)\n-// CHECK-NEXT:      SHF_ALLOC (0x2)\n+// CHECK-NEXT:    Flags [\n+// CHECK-NEXT:      SHF_ALLOC\n+// CHECK-NEXT:      SHF_LINK_ORDER\n // CHECK-NEXT:    ]\n \n // CHECK-NOT:     Name: .ARM.exidx.text.f1\n', 'addition_count': 3, 'deletion_count': 2, 'src_file': 'a/test/ELF/arm-exidx-output.s', 'tgt_file': 'b/test/ELF/arm-exidx-output.s', 'file_extension': '.s', 'before_file': '// REQUIRES: arm\n// RUN: llvm-mc -filetype=obj -triple=armv7a-none-linux-gnueabi %s -o %t\n// RUN: ld.lld %t -o %t2\n// RUN: llvm-readobj --sections %t2 | FileCheck %s\n\n// Check that only a single .ARM.exidx output section is created when\n// there are input sections of the form .ARM.exidx.<section-name>. The\n// assembler creates the .ARM.exidx input sections with the .cantunwind\n// directive\n .syntax unified\n .section .text, "ax",%progbits\n .globl _start\n_start:\n .fnstart\n bx lr\n .cantunwind\n .fnend\n\n .section .text.f1, "ax", %progbits\n .globl f1\nf1:\n .fnstart\n bx lr\n .cantunwind\n .fnend\n\n .section .text.f2, "ax", %progbits\n .globl f2\nf2:\n .fnstart\n bx lr\n .cantunwind\n .fnend\n\n// CHECK:         Section {\n// CHECK:         Name: .ARM.exidx\n// CHECK-NEXT:    Type: SHT_ARM_EXIDX (0x70000001)\n// CHECK-NEXT:    Flags [ (0x2)\n// CHECK-NEXT:      SHF_ALLOC (0x2)\n// CHECK-NEXT:    ]\n\n// CHECK-NOT:     Name: .ARM.exidx.text.f1\n// CHECK-NOT:     Name: .ARM.exidx.text.f2\n', 'message': "Always compute sh_link for SHF_LINK_ORDER sections.\n\nSince the output has a section table too, it is meaningful to compute\nthe sh_link. In a more practical note, the binutils' strip crashes if\nsh_link is not set for SHT_ARM_EXIDX.\n\ngit-svn-id: f6089bf0e6284f307027cef4f64114ee9ebb0424@287280 91177308-0d34-0410-b5e6-96231b3b80d8\n", 'author_name': 'Rafael Espindola', 'lang': 's'}