[lld] 9f65f5a - [LLD][ELF] Eliminate symbols of merged .ARM.exidx sections.

Igor Kudrin via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 28 05:02:29 PDT 2020


Author: Igor Kudrin
Date: 2020-04-28T18:58:40+07:00
New Revision: 9f65f5acca1926f6175fee5ec9ea277a42904c57

URL: https://github.com/llvm/llvm-project/commit/9f65f5acca1926f6175fee5ec9ea277a42904c57
DIFF: https://github.com/llvm/llvm-project/commit/9f65f5acca1926f6175fee5ec9ea277a42904c57.diff

LOG: [LLD][ELF] Eliminate symbols of merged .ARM.exidx sections.

GNU tools generate mapping symbols "$d" for .ARM.exidx sections. The
symbols are added to the symbol table much earlier than the merging
takes place, and after that, they become dangling. Before the patch,
LLD output those symbols as SHN_ABS with the value of 0. The patch
removes such symbols from the symbol table.

Differential Revision: https://reviews.llvm.org/D78820

Added: 
    lld/test/ELF/arm-exidx-mapping-symbols.s

Modified: 
    lld/ELF/Writer.cpp

Removed: 
    


################################################################################
diff  --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp
index 03fe0fe92aa0..bca5989861f9 100644
--- a/lld/ELF/Writer.cpp
+++ b/lld/ELF/Writer.cpp
@@ -681,6 +681,15 @@ static bool shouldKeepInSymtab(const Defined &sym) {
   if (config->copyRelocs && sym.used)
     return true;
 
+  // Exclude local symbols pointing to .ARM.exidx sections.
+  // They are probably mapping symbols "$d", which are optional for these
+  // sections. After merging the .ARM.exidx sections, some of these symbols
+  // may become dangling. The easiest way to avoid the issue is not to add
+  // them to the symbol table from the beginning.
+  if (config->emachine == EM_ARM && sym.section &&
+      sym.section->type == SHT_ARM_EXIDX)
+    return false;
+
   if (config->discard == DiscardPolicy::None)
     return true;
   if (config->discard == DiscardPolicy::All)

diff  --git a/lld/test/ELF/arm-exidx-mapping-symbols.s b/lld/test/ELF/arm-exidx-mapping-symbols.s
new file mode 100644
index 000000000000..623eba630ed3
--- /dev/null
+++ b/lld/test/ELF/arm-exidx-mapping-symbols.s
@@ -0,0 +1,26 @@
+// REQUIRES: arm
+// RUN: llvm-mc -filetype=obj -triple=armv7a-none-linux-gnueabi %s -o %t
+// RUN: ld.lld %t -o %t2
+// RUN: llvm-readelf -s %t2 | FileCheck %s
+// CHECK-NOT: $d.exidx.foo
+
+/// Test that symbols which point to input .ARM.exidx sections are eliminated.
+/// These symbols might be produced, for example, by GNU tools.
+
+    .syntax unified
+    .section .text.foo,"axG",%progbits,foo,comdat
+foo:
+    bx lr
+
+/// GNU as adds mapping symbols "$d" for .ARM.exidx sections it generates.
+/// llvm-mc does not do that, so reproduce that manually.
+    .section .ARM.exidx.text.foo,"ao?",%0x70000001,.text.foo
+$d.exidx.foo:
+    .reloc 0, R_ARM_NONE, __aeabi_unwind_cpp_pr0
+    .long .text.foo(PREL31)
+    .long 0x80b0b0b0
+
+    .section .text.h,"ax"
+    .global __aeabi_unwind_cpp_pr0
+__aeabi_unwind_cpp_pr0:
+    bx lr


        


More information about the llvm-commits mailing list