Skip to content

Commit c73c047

Browse files
committed
Add test for got symbols relaxation.
Similar to aarch64-adrp-ldr-got-symbols.s.
1 parent 0d37ae9 commit c73c047

File tree

1 file changed

+90
-0
lines changed

1 file changed

+90
-0
lines changed
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
## This test verifies that the pair pcalau12i + ld.w/d is relaxed/not relaxed
2+
## depending on the target symbol properties.
3+
4+
# REQUIRES: loongarch
5+
# RUN: rm -rf %t && split-file %s %t && cd %t
6+
7+
# RUN: llvm-mc --filetype=obj --triple=loongarch32 -mattr=+relax symbols.s -o symbols.32.o
8+
# RUN: llvm-mc --filetype=obj --triple=loongarch64 -mattr=+relax symbols.s -o symbols.64.o
9+
# RUN: llvm-mc --filetype=obj --triple=loongarch32 -mattr=+relax abs.s -o abs.32.o
10+
# RUN: llvm-mc --filetype=obj --triple=loongarch64 -mattr=+relax abs.s -o abs.64.o
11+
12+
# RUN: ld.lld --shared -Tlinker.t symbols.32.o abs.32.o -o symbols.32.so
13+
# RUN: ld.lld --shared -Tlinker.t symbols.64.o abs.64.o -o symbols.64.so
14+
# RUN: llvm-objdump -d --no-show-raw-insn symbols.32.so | FileCheck --check-prefixes=LIB %s
15+
# RUN: llvm-objdump -d --no-show-raw-insn symbols.64.so | FileCheck --check-prefixes=LIB %s
16+
17+
# RUN: ld.lld -Tlinker.t -z undefs symbols.32.o abs.32.o -o symbols.32
18+
# RUN: ld.lld -Tlinker.t -z undefs symbols.64.o abs.64.o -o symbols.64
19+
# RUN: llvm-objdump -d --no-show-raw-insn symbols.32 | FileCheck --check-prefixes=EXE %s
20+
# RUN: llvm-objdump -d --no-show-raw-insn symbols.64 | FileCheck --check-prefixes=EXE %s
21+
22+
23+
## Symbol 'hidden_sym' is nonpreemptible, the relaxation should be applied.
24+
LIB: pcaddi $a0, {{[0-9]+}}
25+
## Symbol 'global_sym' is preemptible, no relaxations should be applied.
26+
LIB-NEXT: pcalau12i $a1, 4
27+
LIB-NEXT: ld.{{[wd]}} $a1, $a1, {{[0-9]+}}
28+
## Symbol 'undefined_sym' is undefined, no relaxations should be applied.
29+
LIB-NEXT: pcalau12i $a2, 4
30+
LIB-NEXT: ld.{{[wd]}} $a2, $a2, {{[0-9]+}}
31+
## Symbol 'ifunc_sym' is STT_GNU_IFUNC, no relaxations should be applied.
32+
LIB-NEXT: pcalau12i $a3, 4
33+
LIB-NEXT: ld.{{[wd]}} $a3, $a3, {{[0-9]+}}
34+
## Symbol 'abs_sym' is absolute, no relaxations should be applied.
35+
LIB-NEXT: pcalau12i $a4, 4
36+
LIB-NEXT: ld.{{[wd]}} $a4, $a4, {{[0-9]+}}
37+
38+
39+
## Symbol 'hidden_sym' is nonpreemptible, the relaxation should be applied.
40+
EXE: pcaddi $a0, {{[0-9]+}}
41+
## Symbol 'global_sym' is nonpreemptible, the relaxation should be applied.
42+
EXE-NEXT: pcaddi $a1, {{[0-9]+}}
43+
## Symbol 'undefined_sym' is undefined, no relaxations should be applied.
44+
EXE-NEXT: pcalau12i $a2, 4
45+
EXE-NEXT: ld.{{[wd]}} $a2, $a2, {{[0-9]+}}
46+
## Symbol 'ifunc_sym' is STT_GNU_IFUNC, no relaxations should be applied.
47+
EXE-NEXT: pcalau12i $a3, 4
48+
EXE-NEXT: ld.{{[wd]}} $a3, $a3, {{[0-9]+}}
49+
## Symbol 'abs_sym' is absolute, relaxations may be applied in -no-pie mode.
50+
EXE-NEXT: pcaddi $a4, -{{[0-9]+}}
51+
52+
53+
## The linker script ensures that .rodata and .text are near (>4M) so that
54+
## the pcalau12i+ld.w/d pair can be relaxed to pcaddi.
55+
#--- linker.t
56+
SECTIONS {
57+
.text 0x10000: { *(.text) }
58+
.rodata 0x14000: { *(.rodata) }
59+
}
60+
61+
# This symbol is defined in a separate file to prevent the definition from
62+
# being folded into the instructions that reference it.
63+
#--- abs.s
64+
.global abs_sym
65+
.hidden abs_sym
66+
abs_sym = 0x1000
67+
68+
#--- symbols.s
69+
.rodata
70+
.hidden hidden_sym
71+
hidden_sym:
72+
.word 10
73+
74+
.global global_sym
75+
global_sym:
76+
.word 10
77+
78+
.text
79+
.type ifunc_sym STT_GNU_IFUNC
80+
.hidden ifunc_sym
81+
ifunc_sym:
82+
nop
83+
84+
.global _start
85+
_start:
86+
la.got $a0, hidden_sym
87+
la.got $a1, global_sym
88+
la.got $a2, undefined_sym
89+
la.got $a3, ifunc_sym
90+
la.got $a4, abs_sym

0 commit comments

Comments
 (0)