Skip to content

Commit 2c6fae1

Browse files
committed
ELF: Discard .ARM.exidx sections for empty functions instead of misordering them.
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. Differential Revision: https://reviews.llvm.org/D69744
1 parent 664f84e commit 2c6fae1

File tree

2 files changed

+44
-5
lines changed

2 files changed

+44
-5
lines changed

lld/ELF/SyntheticSections.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3164,12 +3164,10 @@ static bool isValidExidxSectionDep(InputSection *isec) {
31643164

31653165
bool ARMExidxSyntheticSection::addSection(InputSection *isec) {
31663166
if (isec->type == SHT_ARM_EXIDX) {
3167-
if (InputSection* dep = isec->getLinkOrderDep())
3168-
if (isValidExidxSectionDep(dep)) {
3167+
if (InputSection *dep = isec->getLinkOrderDep())
3168+
if (isValidExidxSectionDep(dep))
31693169
exidxSections.push_back(isec);
3170-
return true;
3171-
}
3172-
return false;
3170+
return true;
31733171
}
31743172

31753173
if (isValidExidxSectionDep(isec)) {

lld/test/ELF/arm-exidx-empty-fn.s

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// REQUIRES: arm
2+
// RUN: llvm-mc -filetype=obj -triple=armv7a-none-linux-gnueabi %s -o %t.o
3+
// RUN: ld.lld %t.o -o %t -shared
4+
5+
// RUN: llvm-readelf --unwind %t | FileCheck %s
6+
7+
// Check that any exidx sections for empty functions are discarded.
8+
9+
// CHECK: Entries [
10+
// CHECK-NEXT: Entry {
11+
// CHECK-NEXT: FunctionAddress:
12+
// CHECK-NEXT: Model: CantUnwind
13+
// CHECK-NEXT: }
14+
// CHECK-NEXT: Entry {
15+
// CHECK-NEXT: FunctionAddress:
16+
// CHECK-NEXT: Model: CantUnwind
17+
// CHECK-NEXT: }
18+
// CHECK-NEXT: ]
19+
20+
.section .text.f0,"ax",%progbits
21+
.globl f0
22+
f0:
23+
.fnstart
24+
bx lr
25+
.cantunwind
26+
.fnend
27+
28+
.section .text.f1,"ax",%progbits
29+
.globl f1
30+
f1:
31+
.fnstart
32+
.cantunwind
33+
.fnend
34+
35+
.section .text.f2,"ax",%progbits
36+
.globl f2
37+
f2:
38+
.fnstart
39+
bx lr
40+
.cantunwind
41+
.fnend

0 commit comments

Comments
 (0)