Skip to content

Commit 9f65f5a

Browse files
committed
[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
1 parent fe667e8 commit 9f65f5a

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

lld/ELF/Writer.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -681,6 +681,15 @@ static bool shouldKeepInSymtab(const Defined &sym) {
681681
if (config->copyRelocs && sym.used)
682682
return true;
683683

684+
// Exclude local symbols pointing to .ARM.exidx sections.
685+
// They are probably mapping symbols "$d", which are optional for these
686+
// sections. After merging the .ARM.exidx sections, some of these symbols
687+
// may become dangling. The easiest way to avoid the issue is not to add
688+
// them to the symbol table from the beginning.
689+
if (config->emachine == EM_ARM && sym.section &&
690+
sym.section->type == SHT_ARM_EXIDX)
691+
return false;
692+
684693
if (config->discard == DiscardPolicy::None)
685694
return true;
686695
if (config->discard == DiscardPolicy::All)
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// REQUIRES: arm
2+
// RUN: llvm-mc -filetype=obj -triple=armv7a-none-linux-gnueabi %s -o %t
3+
// RUN: ld.lld %t -o %t2
4+
// RUN: llvm-readelf -s %t2 | FileCheck %s
5+
// CHECK-NOT: $d.exidx.foo
6+
7+
/// Test that symbols which point to input .ARM.exidx sections are eliminated.
8+
/// These symbols might be produced, for example, by GNU tools.
9+
10+
.syntax unified
11+
.section .text.foo,"axG",%progbits,foo,comdat
12+
foo:
13+
bx lr
14+
15+
/// GNU as adds mapping symbols "$d" for .ARM.exidx sections it generates.
16+
/// llvm-mc does not do that, so reproduce that manually.
17+
.section .ARM.exidx.text.foo,"ao?",%0x70000001,.text.foo
18+
$d.exidx.foo:
19+
.reloc 0, R_ARM_NONE, __aeabi_unwind_cpp_pr0
20+
.long .text.foo(PREL31)
21+
.long 0x80b0b0b0
22+
23+
.section .text.h,"ax"
24+
.global __aeabi_unwind_cpp_pr0
25+
__aeabi_unwind_cpp_pr0:
26+
bx lr

0 commit comments

Comments
 (0)