Skip to content

Commit 555b611

Browse files
committed
fixup! [ELF] Handle relocations in synthetic .eh_frame with a non-zero offset within the output section
1 parent 8524373 commit 555b611

File tree

8 files changed

+114
-125
lines changed

8 files changed

+114
-125
lines changed

lld/ELF/Arch/AArch64.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -770,10 +770,8 @@ void AArch64::relocateAlloc(InputSectionBase &sec, uint8_t *buf) const {
770770
uint64_t secAddr = sec.getOutputSection()->addr;
771771
if (auto *s = dyn_cast<InputSection>(&sec))
772772
secAddr += s->outSecOff;
773-
else if (auto *ehIn = dyn_cast<EhInputSection>(&sec)) {
774-
SyntheticSection *ehFrame = ehIn->getParent();
775-
secAddr += ehFrame->outSecOff;
776-
}
773+
else if (auto *ehIn = dyn_cast<EhInputSection>(&sec))
774+
secAddr += ehIn->getParent()->outSecOff;
777775
AArch64Relaxer relaxer(sec.relocs());
778776
for (size_t i = 0, size = sec.relocs().size(); i != size; ++i) {
779777
const Relocation &rel = sec.relocs()[i];

lld/ELF/Arch/PPC64.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1563,10 +1563,8 @@ void PPC64::relocateAlloc(InputSectionBase &sec, uint8_t *buf) const {
15631563
uint64_t secAddr = sec.getOutputSection()->addr;
15641564
if (auto *s = dyn_cast<InputSection>(&sec))
15651565
secAddr += s->outSecOff;
1566-
else if (auto *ehIn = dyn_cast<EhInputSection>(&sec)) {
1567-
SyntheticSection *ehFrame = ehIn->getParent();
1568-
secAddr += ehFrame->outSecOff;
1569-
}
1566+
else if (auto *ehIn = dyn_cast<EhInputSection>(&sec))
1567+
secAddr += ehIn->getParent()->outSecOff;
15701568
uint64_t lastPPCRelaxedRelocOff = -1;
15711569
for (const Relocation &rel : sec.relocs()) {
15721570
uint8_t *loc = buf + rel.offset;

lld/ELF/Arch/X86_64.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -989,10 +989,8 @@ void X86_64::relocateAlloc(InputSectionBase &sec, uint8_t *buf) const {
989989
uint64_t secAddr = sec.getOutputSection()->addr;
990990
if (auto *s = dyn_cast<InputSection>(&sec))
991991
secAddr += s->outSecOff;
992-
else if (auto *ehIn = dyn_cast<EhInputSection>(&sec)) {
993-
SyntheticSection *ehFrame = ehIn->getParent();
994-
secAddr += ehFrame->outSecOff;
995-
}
992+
else if (auto *ehIn = dyn_cast<EhInputSection>(&sec))
993+
secAddr += ehIn->getParent()->outSecOff;
996994
for (const Relocation &rel : sec.relocs()) {
997995
if (rel.expr == R_NONE) // See deleteFallThruJmpInsn
998996
continue;

lld/ELF/Target.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,10 +159,8 @@ void TargetInfo::relocateAlloc(InputSectionBase &sec, uint8_t *buf) const {
159159
uint64_t secAddr = sec.getOutputSection()->addr;
160160
if (auto *s = dyn_cast<InputSection>(&sec))
161161
secAddr += s->outSecOff;
162-
else if (auto *ehIn = dyn_cast<EhInputSection>(&sec)) {
163-
SyntheticSection *ehFrame = ehIn->getParent();
164-
secAddr += ehFrame->outSecOff;
165-
}
162+
else if (auto *ehIn = dyn_cast<EhInputSection>(&sec))
163+
secAddr += ehIn->getParent()->outSecOff;
166164
for (const Relocation &rel : sec.relocs()) {
167165
uint8_t *loc = buf + rel.offset;
168166
const uint64_t val = SignExtend64(
Lines changed: 26 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,45 @@
11
// REQUIRES: aarch64
2-
// RUN: rm -rf %t && split-file %s %t
2+
// RUN: rm -rf %t && split-file %s %t && cd %t
33

4-
// RUN: llvm-mc -filetype=obj -triple=aarch64 %t/a.s -o %t/a.o
5-
// RUN: ld.lld %t/a.o -T %t/eh-frame-non-zero-offset.t -o %t/non-zero
6-
// RUN: llvm-readelf --program-headers --unwind --symbols -x .eh_frame %t/non-zero | FileCheck --check-prefix=NONZERO %s
7-
// RUN: ld.lld %t/a.o -T %t/eh-frame-zero-offset.t -o %t/zero
8-
// RUN: llvm-readelf --program-headers --unwind --symbols -x .eh_frame %t/zero | FileCheck --check-prefix=ZERO %s
4+
// RUN: llvm-mc -filetype=obj -triple=aarch64 a.s -o a.o
5+
// RUN: ld.lld a.o -T eh-frame-non-zero-offset.t -o non-zero
6+
// RUN: llvm-readelf --program-headers --unwind --symbols -x .eh_frame non-zero | FileCheck --check-prefix=NONZERO %s
7+
// RUN: ld.lld a.o -T eh-frame-zero-offset.t -o zero
8+
// RUN: llvm-readelf --program-headers --unwind --symbols -x .eh_frame zero | FileCheck --check-prefix=ZERO %s
99

10-
// NONZERO: {{[0-9]+}}: 0000000000000080 {{.*}} __eh_frame_start
11-
// NONZERO-NEXT: {{[0-9]+}}: 00000000000000ac {{.*}} __eh_frame_end
10+
// NONZERO: {{[0-9]+}}: 0000000000000088 {{.*}} __eh_frame_start
11+
// NONZERO-NEXT: {{[0-9]+}}: 00000000000000b4 {{.*}} __eh_frame_end
1212

13-
// NONZERO: 0x00000078 00000000 00000000 10000000 00000000
14-
// NONZERO-NEXT: 0x00000088 017a5200 017c1e01 1b0c1f00 10000000
15-
// NONZERO-NEXT: 0x00000098 18000000 64ffffff 08000000 00000000
16-
// NONZERO-NEXT: 0x000000a8 00000000
13+
// NONZERO: 0x00000088 10000000 00000000 017a5200 017c1e01
14+
// NONZERO-NEXT: 0x00000098 1b0c1f00 10000000 18000000 5cffffff
15+
// NONZERO-NEXT: 0x000000a8 04000000 00000000 00000000
1716

18-
// ZERO: {{[0-9]+}}: 0000000000000080 {{.*}} __eh_frame_start
19-
// ZERO-NEXT: {{[0-9]+}}: 00000000000000ac {{.*}} __eh_frame_end
17+
// ZERO: {{[0-9]+}}: 0000000000000008 {{.*}} __eh_frame_start
18+
// ZERO-NEXT: {{[0-9]+}}: 0000000000000034 {{.*}} __eh_frame_end
2019

21-
// ZERO: 0x00000080 10000000 00000000 017a5200 017c1e01
22-
// ZERO-NEXT: 0x00000090 1b0c1f00 10000000 18000000 64ffffff
23-
// ZERO-NEXT: 0x000000a0 08000000 00000000 00000000
20+
// ZERO: 0x00000008 10000000 00000000 017a5200 017c1e01
21+
// ZERO-NEXT: 0x00000018 1b0c1f00 10000000 18000000 dcffffff
22+
// ZERO-NEXT: 0x00000028 04000000 00000000 00000000
2423

2524
//--- eh-frame-non-zero-offset.t
2625
SECTIONS {
2726
.text : { *(.text .text.*) }
2827
.eh_frame : {
29-
/* Alignment padding within .eh_frame */
30-
. = ALIGN(128);
31-
__eh_frame_start = .;
32-
*(.eh_frame .eh_frame.*) ;
33-
__eh_frame_end = .;
28+
/* Padding within .eh_frame */
29+
. += 128;
30+
__eh_frame_start = .;
31+
*(.eh_frame) ;
32+
__eh_frame_end = .;
3433
}
3534
}
3635

3736
//--- eh-frame-zero-offset.t
3837
SECTIONS {
3938
.text : { *(.text .text.*) }
40-
.eh_frame : ALIGN(128) {
41-
__eh_frame_start = .;
42-
*(.eh_frame .eh_frame.*) ;
43-
__eh_frame_end = .;
39+
.eh_frame : {
40+
__eh_frame_start = .;
41+
*(.eh_frame) ;
42+
__eh_frame_end = .;
4443
}
4544
}
4645

@@ -50,6 +49,5 @@ SECTIONS {
5049
.type f1, %function
5150
f1:
5251
.cfi_startproc
53-
nop
54-
nop
52+
.space 4
5553
.cfi_endproc

lld/test/ELF/eh-frame-nonzero-offset-arm.s

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,45 @@
11
// REQUIRES: arm
2-
// RUN: rm -rf %t && split-file %s %t
2+
// RUN: rm -rf %t && split-file %s %t && cd %t
33

4-
// RUN: llvm-mc -filetype=obj -triple=arm %t/a.s -o %t/a.o
5-
// RUN: ld.lld %t/a.o -T %t/eh-frame-non-zero-offset.t -o %t/non-zero
6-
// RUN: llvm-readelf --program-headers --unwind --symbols -x .eh_frame %t/non-zero | FileCheck --check-prefix=NONZERO %s
7-
// RUN: ld.lld %t/a.o -T %t/eh-frame-zero-offset.t -o %t/zero
8-
// RUN: llvm-readelf --program-headers --unwind --symbols -x .eh_frame %t/zero | FileCheck --check-prefix=ZERO %s
4+
// RUN: llvm-mc -filetype=obj -triple=arm a.s -o a.o
5+
// RUN: ld.lld a.o -T eh-frame-non-zero-offset.t -o non-zero
6+
// RUN: llvm-readelf --program-headers --unwind --symbols -x .eh_frame non-zero | FileCheck --check-prefix=NONZERO %s
7+
// RUN: ld.lld a.o -T eh-frame-zero-offset.t -o zero
8+
// RUN: llvm-readelf --program-headers --unwind --symbols -x .eh_frame zero | FileCheck --check-prefix=ZERO %s
99

10-
// NONZERO: {{[0-9]+}}: 00000080 {{.*}} __eh_frame_start
11-
// NONZERO-NEXT: {{[0-9]+}}: 000000ac {{.*}} __eh_frame_end
10+
// NONZERO: {{[0-9]+}}: 00000084 {{.*}} __eh_frame_start
11+
// NONZERO-NEXT: {{[0-9]+}}: 000000b0 {{.*}} __eh_frame_end
1212

13-
// NONZERO: 0x00000074 00000000 00000000 00000000 10000000
14-
// NONZERO-NEXT: 0x00000084 00000000 017a5200 017c0e01 1b0c0d00
15-
// NONZERO-NEXT: 0x00000094 10000000 18000000 64ffffff 04000000
16-
// NONZERO-NEXT: 0x000000a4 00000000 00000000
13+
// NONZERO: 0x00000084 10000000 00000000 017a5200 017c0e01
14+
// NONZERO-NEXT: 0x00000094 1b0c0d00 10000000 18000000 60ffffff
15+
// NONZERO-NEXT: 0x000000a4 04000000 00000000 00000000
1716

18-
// ZERO: {{[0-9]+}}: 00000080 {{.*}} __eh_frame_start
19-
// ZERO-NEXT: {{[0-9]+}}: 000000ac {{.*}} __eh_frame_end
17+
// ZERO: {{[0-9]+}}: 00000004 {{.*}} __eh_frame_start
18+
// ZERO-NEXT: {{[0-9]+}}: 00000030 {{.*}} __eh_frame_end
2019

21-
// ZERO: 0x00000080 10000000 00000000 017a5200 017c0e01
22-
// ZERO-NEXT: 0x00000090 1b0c0d00 10000000 18000000 64ffffff
23-
// ZERO-NEXT: 0x000000a0 04000000 00000000 00000000
20+
// ZERO: 0x00000004 10000000 00000000 017a5200 017c0e01
21+
// ZERO-NEXT: 0x00000014 1b0c0d00 10000000 18000000 e0ffffff
22+
// ZERO-NEXT: 0x00000024 04000000 00000000 00000000
2423

2524
//--- eh-frame-non-zero-offset.t
2625
SECTIONS {
2726
.text : { *(.text .text.*) }
2827
.eh_frame : {
29-
/* Alignment padding within .eh_frame */
30-
. = ALIGN(128);
31-
__eh_frame_start = .;
32-
*(.eh_frame .eh_frame.*) ;
33-
__eh_frame_end = .;
28+
/* Padding within .eh_frame */
29+
. += 128;
30+
__eh_frame_start = .;
31+
*(.eh_frame) ;
32+
__eh_frame_end = .;
3433
}
3534
}
3635

3736
//--- eh-frame-zero-offset.t
3837
SECTIONS {
3938
.text : { *(.text .text.*) }
40-
.eh_frame : ALIGN(128) {
41-
__eh_frame_start = .;
42-
*(.eh_frame .eh_frame.*) ;
43-
__eh_frame_end = .;
39+
.eh_frame : {
40+
__eh_frame_start = .;
41+
*(.eh_frame) ;
42+
__eh_frame_end = .;
4443
}
4544
}
4645

lld/test/ELF/eh-frame-nonzero-offset-ppc.s

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,45 @@
11
// REQUIRES: ppc
2-
// RUN: rm -rf %t && split-file %s %t
2+
// RUN: rm -rf %t && split-file %s %t && cd %t
33

4-
// RUN: llvm-mc -filetype=obj -triple=ppc64le %t/a.s -o %t/a.o
5-
// RUN: ld.lld %t/a.o -T %t/eh-frame-non-zero-offset.t -o %t/non-zero
6-
// RUN: llvm-readelf --program-headers --unwind --symbols -x .eh_frame %t/non-zero | FileCheck --check-prefix=NONZERO %s
7-
// RUN: ld.lld %t/a.o -T %t/eh-frame-zero-offset.t -o %t/zero
8-
// RUN: llvm-readelf --program-headers --unwind --symbols -x .eh_frame %t/zero | FileCheck --check-prefix=ZERO %s
4+
// RUN: llvm-mc -filetype=obj -triple=ppc64le a.s -o a.o
5+
// RUN: ld.lld a.o -T eh-frame-non-zero-offset.t -o non-zero
6+
// RUN: llvm-readelf --program-headers --unwind --symbols -x .eh_frame non-zero | FileCheck --check-prefix=NONZERO %s
7+
// RUN: ld.lld a.o -T eh-frame-zero-offset.t -o zero
8+
// RUN: llvm-readelf --program-headers --unwind --symbols -x .eh_frame zero | FileCheck --check-prefix=ZERO %s
99

10-
// NONZERO: {{[0-9]+}}: 0000000000000080 {{.*}} __eh_frame_start
11-
// NONZERO-NEXT: {{[0-9]+}}: 00000000000000ac {{.*}} __eh_frame_end
10+
// NONZERO: {{[0-9]+}}: 0000000000000088 {{.*}} __eh_frame_start
11+
// NONZERO-NEXT: {{[0-9]+}}: 00000000000000b4 {{.*}} __eh_frame_end
1212

13-
// NONZERO: 0x00000078 00000000 00000000 10000000 00000000
14-
// NONZERO-NEXT: 0x00000088 017a5200 04784101 1b0c0100 10000000
15-
// NONZERO-NEXT: 0x00000098 18000000 64ffffff 04000000 00000000
16-
// NONZERO-NEXT: 0x000000a8 00000000
13+
// NONZERO: 0x00000088 10000000 00000000 017a5200 04784101
14+
// NONZERO-NEXT: 0x00000098 1b0c0100 10000000 18000000 5cffffff
15+
// NONZERO-NEXT: 0x000000a8 04000000 00000000 00000000
1716

18-
// ZERO: {{[0-9]+}}: 0000000000000080 {{.*}} __eh_frame_start
19-
// ZERO-NEXT: {{[0-9]+}}: 00000000000000ac {{.*}} __eh_frame_end
17+
// ZERO: {{[0-9]+}}: 0000000000000008 {{.*}} __eh_frame_start
18+
// ZERO-NEXT: {{[0-9]+}}: 0000000000000034 {{.*}} __eh_frame_end
2019

21-
// ZERO: 0x00000080 10000000 00000000 017a5200 04784101
22-
// ZERO-NEXT: 0x00000090 1b0c0100 10000000 18000000 64ffffff
23-
// ZERO-NEXT: 0x000000a0 04000000 00000000 00000000
20+
// ZERO: 0x00000008 10000000 00000000 017a5200 04784101
21+
// ZERO-NEXT: 0x00000018 1b0c0100 10000000 18000000 dcffffff
22+
// ZERO-NEXT: 0x00000028 04000000 00000000 00000000
2423

2524
//--- eh-frame-non-zero-offset.t
2625
SECTIONS {
2726
.text : { *(.text .text.*) }
2827
.eh_frame : {
29-
/* Alignment padding within .eh_frame */
30-
. = ALIGN(128);
31-
__eh_frame_start = .;
32-
*(.eh_frame .eh_frame.*) ;
33-
__eh_frame_end = .;
28+
/* Padding within .eh_frame */
29+
. += 128;
30+
__eh_frame_start = .;
31+
*(.eh_frame) ;
32+
__eh_frame_end = .;
3433
}
3534
}
3635

3736
//--- eh-frame-zero-offset.t
3837
SECTIONS {
3938
.text : { *(.text .text.*) }
40-
.eh_frame : ALIGN(128) {
41-
__eh_frame_start = .;
42-
*(.eh_frame .eh_frame.*) ;
43-
__eh_frame_end = .;
39+
.eh_frame : {
40+
__eh_frame_start = .;
41+
*(.eh_frame) ;
42+
__eh_frame_end = .;
4443
}
4544
}
4645

lld/test/ELF/eh-frame-nonzero-offset-x86.s

Lines changed: 30 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,54 @@
11
// REQUIRES: x86
2-
// RUN: rm -rf %t && split-file %s %t
2+
// RUN: rm -rf %t && split-file %s %t && cd %t
33

4-
// RUN: llvm-mc -filetype=obj -triple=x86_64 %t/a.s -o %t/a.o
5-
// RUN: ld.lld %t/a.o -T %t/eh-frame-non-zero-offset.t -o %t/non-zero
6-
// RUN: llvm-readelf --program-headers --unwind --symbols -x .eh_frame %t/non-zero | FileCheck --check-prefix=NONZERO %s
7-
// RUN: ld.lld %t/a.o -T %t/eh-frame-zero-offset.t -o %t/zero
8-
// RUN: llvm-readelf --program-headers --unwind --symbols -x .eh_frame %t/zero | FileCheck --check-prefix=ZERO %s
4+
// RUN: llvm-mc -filetype=obj -triple=x86_64 a.s -o a.o
5+
// RUN: ld.lld a.o -T eh-frame-non-zero-offset.t -o non-zero
6+
// RUN: llvm-readelf --program-headers --unwind --symbols -x .eh_frame non-zero | FileCheck --check-prefix=NONZERO %s
7+
// RUN: ld.lld a.o -T eh-frame-zero-offset.t -o zero
8+
// RUN: llvm-readelf --program-headers --unwind --symbols -x .eh_frame zero | FileCheck --check-prefix=ZERO %s
99

10-
// NONZERO: {{[0-9]+}}: 0000000000000080 {{.*}} __eh_frame_start
11-
// NONZERO-NEXT: {{[0-9]+}}: 00000000000000b4 {{.*}} __eh_frame_end
10+
// NONZERO: {{[0-9]+}}: 0000000000000088 {{.*}} __eh_frame_start
11+
// NONZERO-NEXT: {{[0-9]+}}: 00000000000000bc {{.*}} __eh_frame_end
1212

13-
// NONZERO: 0x00000078 00000000 00000000 14000000 00000000
14-
// NONZERO-NEXT: 0x00000088 017a5200 01781001 1b0c0708 90010000
15-
// NONZERO-NEXT: 0x00000098 14000000 1c000000 60ffffff 04000000
16-
// NONZERO-NEXT: 0x000000a8 00000000 00000000 00000000
13+
// NONZERO: 0x00000088 14000000 00000000 017a5200 01781001
14+
// NONZERO-NEXT: 0x00000098 1b0c0708 90010000 14000000 1c000000
15+
// NONZERO-NEXT: 0x000000a8 58ffffff 04000000 00000000 00000000
16+
// NONZERO-NEXT: 0x000000b8 00000000
1717

18-
// ZERO: {{[0-9]+}}: 0000000000000080 {{.*}} __eh_frame_start
19-
// ZERO-NEXT: {{[0-9]+}}: 00000000000000b4 {{.*}} __eh_frame_end
18+
// ZERO: {{[0-9]+}}: 0000000000000008 {{.*}} __eh_frame_start
19+
// ZERO-NEXT: {{[0-9]+}}: 000000000000003c {{.*}} __eh_frame_end
2020

21-
// ZERO: 0x00000080 14000000 00000000 017a5200 01781001
22-
// ZERO-NEXT: 0x00000090 1b0c0708 90010000 14000000 1c000000
23-
// ZERO-NEXT: 0x000000a0 60ffffff 04000000 00000000 00000000
24-
// ZERO-NEXT: 0x000000b0 00000000
21+
// ZERO: 0x00000008 14000000 00000000 017a5200 01781001
22+
// ZERO-NEXT: 0x00000018 1b0c0708 90010000 14000000 1c000000
23+
// ZERO-NEXT: 0x00000028 d8ffffff 04000000 00000000 00000000
24+
// ZERO-NEXT: 0x00000038 00000000
2525

2626
//--- eh-frame-non-zero-offset.t
2727
SECTIONS {
2828
.text : { *(.text .text.*) }
2929
.eh_frame : {
30-
/* Alignment padding within .eh_frame */
31-
. = ALIGN(128);
32-
__eh_frame_start = .;
33-
*(.eh_frame .eh_frame.*) ;
34-
__eh_frame_end = .;
30+
/* Padding within .eh_frame */
31+
. += 128;
32+
__eh_frame_start = .;
33+
*(.eh_frame) ;
34+
__eh_frame_end = .;
3535
}
3636
}
3737

3838
//--- eh-frame-zero-offset.t
3939
SECTIONS {
4040
.text : { *(.text .text.*) }
41-
.eh_frame : ALIGN(128) {
42-
__eh_frame_start = .;
43-
*(.eh_frame .eh_frame.*) ;
44-
__eh_frame_end = .;
41+
.eh_frame : {
42+
__eh_frame_start = .;
43+
*(.eh_frame) ;
44+
__eh_frame_end = .;
4545
}
4646
}
4747

4848
//--- a.s
49-
.section .text
50-
.globl f1
49+
.section .text.01, "ax",%progbits
50+
.global f1
51+
.type f1, %function
5152
f1:
5253
.cfi_startproc
5354
.space 4

0 commit comments

Comments
 (0)