Skip to content

Commit 718fd90

Browse files
committed
ELF,test: Make tests not rely on PPC64 .TOC.
`.quad .TOC.@tocbase` leads to a R_PPC64_TOC relocation referencing 0. GNU Assembler does not define .TOC. . Fix reliance on the .TOC. symbol.
1 parent 89aef7e commit 718fd90

File tree

2 files changed

+24
-21
lines changed

2 files changed

+24
-21
lines changed

lld/test/ELF/ppc64-long-branch-pi.s

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,20 @@
1515
# RUN: llvm-objdump -d --no-show-raw-insn %t.so | FileCheck %s
1616

1717
# SEC-PIE: Name Type Address Off Size ES Flg Lk Inf Al
18-
# SEC-PIE: .got PROGBITS 0000000002002110 2012110 000008 00 WA 0 0 8
19-
# SEC-PIE: .branch_lt NOBITS 0000000002002120 2012120 000020 00 WA 0 0 8
18+
# SEC-PIE: .got PROGBITS 0000000002002120 2012120 000010 00 WA 0 0 8
19+
# SEC-PIE: .branch_lt NOBITS 0000000002002138 2012138 000020 00 WA 0 0 8
2020

2121
# SEC-SHARED: Name Type Address Off Size ES Flg Lk Inf Al
22-
# SEC-SHARED: .got PROGBITS 00000000020020f0 20120f0 000008 00 WA 0 0 8
23-
# SEC-SHARED: .branch_lt NOBITS 0000000002002100 2012100 000020 00 WA 0 0 8
22+
# SEC-SHARED: .got PROGBITS 0000000002002100 2012100 000010 00 WA 0 0 8
23+
# SEC-SHARED: .branch_lt NOBITS 0000000002002118 2012118 000020 00 WA 0 0 8
2424

2525
# RELOC: .rela.dyn {
26-
# RELOC-NEXT: 0x2002118 R_PPC64_RELATIVE - 0x2012110
27-
# RELOC-NEXT: 0x2002120 R_PPC64_RELATIVE - 0x2002000
28-
# RELOC-NEXT: 0x2002128 R_PPC64_RELATIVE - 0x2002008
29-
# RELOC-NEXT: 0x2002130 R_PPC64_RELATIVE - 0x200200C
30-
# RELOC-NEXT: 0x2002138 R_PPC64_RELATIVE - 0x2000
26+
# RELOC-NEXT: 0x2002128 R_PPC64_RELATIVE - 0x2002000
27+
# RELOC-NEXT: 0x2002130 R_PPC64_RELATIVE - 0x2012120
28+
# RELOC-NEXT: 0x2002138 R_PPC64_RELATIVE - 0x2002000
29+
# RELOC-NEXT: 0x2002140 R_PPC64_RELATIVE - 0x2002008
30+
# RELOC-NEXT: 0x2002148 R_PPC64_RELATIVE - 0x200200C
31+
# RELOC-NEXT: 0x2002150 R_PPC64_RELATIVE - 0x2000
3132
# RELOC-NEXT: }
3233

3334
# CHECK: <_start>:
@@ -36,24 +37,24 @@
3637
# CHECK-NEXT: bl 0x2030
3738
# CHECK-NEXT: bl 0x2050
3839

39-
## &.branch_lt[0] - .TOC. = .branch_lt - (.got+0x8000) = -32752
40+
## &.branch_lt[0] - .TOC. = .branch_lt - (.got+0x8000) = -32744
4041
# CHECK: <__long_branch_>:
4142
# CHECK-NEXT: 2010: addis 12, 2, 0
42-
# CHECK-NEXT: ld 12, -32752(12)
43+
# CHECK-NEXT: ld 12, -32744(12)
4344
# CHECK-NEXT: mtctr 12
4445
# CHECK-NEXT: bctr
4546

46-
## &.branch_lt[1] - .TOC. = .branch_lt - (.got+0x8000) = -32744
47+
## &.branch_lt[1] - .TOC. = .branch_lt - (.got+0x8000) = -32736
4748
# CHECK: <__long_branch_>:
4849
# CHECK-NEXT: 2030: addis 12, 2, 0
49-
# CHECK-NEXT: ld 12, -32744(12)
50+
# CHECK-NEXT: ld 12, -32736(12)
5051
# CHECK-NEXT: mtctr 12
5152
# CHECK-NEXT: bctr
5253

53-
## &.branch_lt[2] - .TOC. = .branch_lt - (.got+0x8000) = -32736
54+
## &.branch_lt[2] - .TOC. = .branch_lt - (.got+0x8000) = -32728
5455
# CHECK: <__long_branch_>:
5556
# CHECK-NEXT: 2050: addis 12, 2, 0
56-
# CHECK-NEXT: ld 12, -32736(12)
57+
# CHECK-NEXT: ld 12, -32728(12)
5758
# CHECK-NEXT: mtctr 12
5859
# CHECK-NEXT: bctr
5960

@@ -68,12 +69,12 @@ bl .text_high+0xc # Need a thunk
6869
# CHECK: <high_target>:
6970
# CHECK-NEXT: 2002000: bl 0x2004
7071
# CHECK-NEXT: bl 0x2004
71-
# CHECK-NEXT: bl 0x2002010
72+
# CHECK-NEXT: bl 0x2002020
7273

73-
## &.branch_lt[3] - .TOC. = .branch_lt - (.got+0x8000) = -32728
74+
## &.branch_lt[3] - .TOC. = .branch_lt - (.got+0x8000) = -32720
7475
# CHECK: <__long_branch_>:
75-
# CHECK-NEXT: 2002010: addis 12, 2, 0
76-
# CHECK-NEXT: ld 12, -32728(12)
76+
# CHECK-NEXT: 2002020: addis 12, 2, 0
77+
# CHECK-NEXT: ld 12, -32720(12)
7778
# CHECK-NEXT: mtctr 12
7879
# CHECK-NEXT: bctr
7980

@@ -85,6 +86,8 @@ bl .text_low # Need a thunk
8586
blr
8687

8788
## Force creation of .got
89+
addis 3, 2, .text_high@got@ha
90+
8891
## The R_PPC64_RELATIVE makes sure .rela.dyn survives removeUnusedSyntheticSections.
8992
.section .data
9093
.quad .TOC.@tocbase

lld/test/ELF/ppc64-relocs.s

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22

33
# RUN: llvm-mc -filetype=obj -triple=powerpc64le-unknown-linux %s -o %t.o
44
# RUN: ld.lld --no-toc-optimize %t.o -o %t
5-
# RUN: llvm-readelf -x .rodata -x .R_PPC64_TOC -x .eh_frame %t | FileCheck %s --check-prefix=DATALE
5+
# RUN: llvm-readelf -x .rodata -x .R_PPC64_TOC %t | FileCheck %s --check-prefix=DATALE
66
# RUN: llvm-objdump -d --no-show-raw-insn %t | FileCheck %s
77

88
# RUN: llvm-mc -filetype=obj -triple=powerpc64-unknown-linux %s -o %t.o
99
# RUN: ld.lld --no-toc-optimize %t.o -o %t
10-
# RUN: llvm-readelf -x .rodata -x .R_PPC64_TOC -x .eh_frame %t | FileCheck %s --check-prefix=DATABE
10+
# RUN: llvm-readelf -x .rodata -x .R_PPC64_TOC %t | FileCheck %s --check-prefix=DATABE
1111
# RUN: llvm-objdump -d --no-show-raw-insn %t | FileCheck %s
1212

1313
.text

0 commit comments

Comments
 (0)