[PATCH] D68094: ELF: Don't merge SHF_LINK_ORDER sections in relocatable links.

Peter Collingbourne via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 26 11:38:06 PDT 2019


pcc created this revision.
pcc added reviewers: ruiu, MaskRay, grimar, peter.smith.
Herald added subscribers: arichardson, emaste.
Herald added a reviewer: espindola.
Herald added a project: LLVM.

Merging SHF_LINK_ORDER sections can affect semantics if the sh_link
fields point to different sections.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D68094

Files:
  lld/ELF/LinkerScript.cpp
  lld/test/ELF/arm-exidx-relocatable.s
  lld/test/ELF/relocatable-linkorder.s


Index: lld/test/ELF/relocatable-linkorder.s
===================================================================
--- /dev/null
+++ lld/test/ELF/relocatable-linkorder.s
@@ -0,0 +1,25 @@
+// REQUIRES: x86
+// RUN: llvm-mc %s -o %t.o -filetype=obj --triple=x86_64-unknown-linux
+// RUN: ld.lld %t.o -o %t -r
+// RUN: llvm-readelf -S %t | FileCheck %s
+
+// Test that SHF_LINK_ORDER sections with different linked sections
+// aren't merged.
+
+.section .text.f1,"ax", at progbits
+.globl f1
+f1:
+ret
+
+.section .text.f2,"ax", at progbits
+.globl f1
+f2:
+ret
+
+// CHECK: foo
+.section foo,"ao", at progbits,.text.f1,unique,1
+.quad 1
+
+// CHECK: foo
+.section foo,"ao", at progbits,.text.f2,unique,2
+.quad 2
Index: lld/test/ELF/arm-exidx-relocatable.s
===================================================================
--- lld/test/ELF/arm-exidx-relocatable.s
+++ lld/test/ELF/arm-exidx-relocatable.s
@@ -53,7 +53,7 @@
 // CHECK-NEXT:    ]
 // CHECK-NEXT:    Address
 // CHECK-NEXT:    Offset:
-// CHECK-NEXT:    Size: 24
+// CHECK-NEXT:    Size: 8
 // CHECK-NEXT:    Link: 1
 
 
@@ -130,3 +130,15 @@
 // CHECK-NEXT:    Offset:
 // CHECK-NEXT:    Size: 8
 // CHECK-NEXT:    Link: 16
+
+
+// CHECK:         Name: .ARM.exidx
+// CHECK-NEXT:    Type: SHT_ARM_EXIDX (0x70000001)
+// CHECK-NEXT:    Flags [ (0x82)
+// CHECK-NEXT:      SHF_ALLOC (0x2)
+// CHECK-NEXT:      SHF_LINK_ORDER (0x80)
+// CHECK-NEXT:    ]
+// CHECK-NEXT:    Address
+// CHECK-NEXT:    Offset:
+// CHECK-NEXT:    Size: 16
+// CHECK-NEXT:    Link: 1
Index: lld/ELF/LinkerScript.cpp
===================================================================
--- lld/ELF/LinkerScript.cpp
+++ lld/ELF/LinkerScript.cpp
@@ -576,7 +576,12 @@
   // However, for the -r option, we want to pass through all section groups
   // as-is because adding/removing members or merging them with other groups
   // change their semantics.
-  if (isec->type == SHT_GROUP || (isec->flags & SHF_GROUP))
+  //
+  // Similarly, merging two SHF_LINK_ORDER sections with different sh_link
+  // fields will change their semantics, so we also pass SHF_LINK_ORDER sections
+  // through as-is in -r links.
+  if (isec->type == SHT_GROUP || (isec->flags & SHF_GROUP) ||
+      (config->relocatable && (isec->flags & SHF_LINK_ORDER)))
     return createSection(isec, outsecName);
 
   // Imagine .zed : { *(.foo) *(.bar) } script. Both foo and bar may have


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D68094.221994.patch
Type: text/x-patch
Size: 2380 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190926/faa5109c/attachment.bin>


More information about the llvm-commits mailing list