[PATCH] D69744: ELF: Discard .ARM.exidx sections for empty functions instead of misordering them.

Peter Collingbourne via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Nov 1 19:00:08 PDT 2019


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

The logic added in r372781 caused ARMExidxSyntheticSection::addSection()
to return false for exidx sections without a link order dep that passed
isValidExidxSectionDep(). This included exidx sections for empty functions. As
a result, such exidx sections would end up treated like ordinary sections and
would end up being laid out before the ARMExidxSyntheticSection, most likely in
the wrong order relative to the exidx entries in the ARMExidxSyntheticSection,
breaking the orderedness invariant relied upon by unwinders. Fix this by
simply discarding such sections.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D69744

Files:
  lld/ELF/SyntheticSections.cpp
  lld/test/ELF/empty-fn-exidx.s


Index: lld/test/ELF/empty-fn-exidx.s
===================================================================
--- /dev/null
+++ lld/test/ELF/empty-fn-exidx.s
@@ -0,0 +1,42 @@
+// REQUIRES: arm
+// RUN: llvm-mc -filetype=obj -triple=armv7a-none-linux-gnueabi %s -o %t.o
+// RUN: ld.lld %t.o -o %t -shared
+
+// RUN: llvm-readelf --unwind %t | FileCheck %s
+
+// Check that any exidx sections for empty functions are discarded.
+
+// CHECK:      SectionOffset: 0x[[EXIDX_OFFSET:.*]]
+// CHECK-NEXT: Entries [
+// CHECK-NEXT:   Entry {
+// CHECK-NEXT:     FunctionAddress:
+// CHECK-NEXT:     Model: CantUnwind
+// CHECK-NEXT:   }
+// CHECK-NEXT:   Entry {
+// CHECK-NEXT:     FunctionAddress:
+// CHECK-NEXT:     Model: CantUnwind
+// CHECK-NEXT:   }
+// CHECK-NEXT: ]
+
+.section .text.f0,"ax",%progbits
+.globl f0
+f0:
+.fnstart
+bx lr
+.cantunwind
+.fnend
+
+.section .text.f1,"ax",%progbits
+.globl f1
+f1:
+.fnstart
+.cantunwind
+.fnend
+
+.section .text.f2,"ax",%progbits
+.globl f2
+f2:
+.fnstart
+bx lr
+.cantunwind
+.fnend
Index: lld/ELF/SyntheticSections.cpp
===================================================================
--- lld/ELF/SyntheticSections.cpp
+++ lld/ELF/SyntheticSections.cpp
@@ -3164,12 +3164,10 @@
 
 bool ARMExidxSyntheticSection::addSection(InputSection *isec) {
   if (isec->type == SHT_ARM_EXIDX) {
-    if (InputSection* dep = isec->getLinkOrderDep())
-      if (isValidExidxSectionDep(dep)) {
+    if (InputSection *dep = isec->getLinkOrderDep())
+      if (isValidExidxSectionDep(dep))
         exidxSections.push_back(isec);
-        return true;
-      }
-    return false;
+    return true;
   }
 
   if (isValidExidxSectionDep(isec)) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D69744.227558.patch
Type: text/x-patch
Size: 1671 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20191102/f8fba448/attachment-0001.bin>


More information about the llvm-commits mailing list