[ELF] Refine isExported/isPreemptible condition
[llvm-project.git] / lld / test / ELF / riscv-reloc-leb128.s
blob0bdc1eb18269dddfd82a6975902d8536598757e8
1 # REQUIRES: riscv
2 # RUN: rm -rf %t && split-file %s %t && cd %t
3 # RUN: llvm-mc -filetype=obj -triple=riscv64 -mattr=+relax a.s -o a.o
4 # RUN: llvm-readobj -r -x .gcc_except_table -x .debug_rnglists -x .debug_loclists a.o | FileCheck %s --check-prefix=REL
5 # RUN: ld.lld -shared --gc-sections --noinhibit-exec a.o -o a.so
6 # RUN: llvm-readelf -x .gcc_except_table -x .debug_rnglists -x .debug_loclists a.so | FileCheck %s
8 # REL: .rela.debug_rnglists {
9 # REL-NEXT: 0x0 R_RISCV_SET_ULEB128 w1 0x82
10 # REL-NEXT: 0x0 R_RISCV_SUB_ULEB128 w2 0xFFFFFFFFFFFFFFFF
11 # REL-NEXT: 0x1 R_RISCV_SET_ULEB128 w2 0x78
12 # REL-NEXT: 0x1 R_RISCV_SUB_ULEB128 w1 0x0
13 # REL-NEXT: 0x3 R_RISCV_SET_ULEB128 w1 0x89
14 # REL-NEXT: 0x3 R_RISCV_SUB_ULEB128 w2 0x0
15 # REL-NEXT: 0x5 R_RISCV_SET_ULEB128 w2 0x3FF8
16 # REL-NEXT: 0x5 R_RISCV_SUB_ULEB128 w1 0x0
17 # REL-NEXT: 0x8 R_RISCV_SET_ULEB128 w1 0x4009
18 # REL-NEXT: 0x8 R_RISCV_SUB_ULEB128 w2 0x0
19 # REL-NEXT: 0xB R_RISCV_SET_ULEB128 w2 0x1FFFF8
20 # REL-NEXT: 0xB R_RISCV_SUB_ULEB128 w1 0x0
21 # REL-NEXT: 0xF R_RISCV_SET_ULEB128 w1 0x200009
22 # REL-NEXT: 0xF R_RISCV_SUB_ULEB128 w2 0x0
23 # REL-NEXT: }
24 # REL: .rela.debug_loclists {
25 # REL-NEXT: 0x0 R_RISCV_SET_ULEB128 w2 0x3
26 # REL-NEXT: 0x0 R_RISCV_SUB_ULEB128 w1 0x4
27 # REL-NEXT: 0x1 R_RISCV_SET_ULEB128 x2 0x0
28 # REL-NEXT: 0x1 R_RISCV_SUB_ULEB128 x1 0x0
29 # REL-NEXT: }
31 # REL: Hex dump of section '.gcc_except_table':
32 # REL-NEXT: 0x00000000 7b800181 01808001 81800180 80800181 {
33 # REL-NEXT: 0x00000010 808001 .
34 # REL: Hex dump of section '.debug_rnglists':
35 # REL-NEXT: 0x00000000 7b800181 01808001 81800180 80800181 {
36 # REL-NEXT: 0x00000010 808001 .
37 # REL: Hex dump of section '.debug_loclists':
38 # REL-NEXT: 0x00000000 0008 .
40 # CHECK: Hex dump of section '.gcc_except_table':
41 # CHECK-NEXT: 0x[[#%x,]] 7ffc0085 01fcff00 858001fc ffff0085 .
42 # CHECK-NEXT: 0x[[#%x,]] 808001 .
43 # CHECK: Hex dump of section '.debug_rnglists':
44 # CHECK-NEXT: 0x00000000 7ffc0085 01fcff00 858001fc ffff0085 .
45 # CHECK-NEXT: 0x00000010 808001 .
46 # CHECK: Hex dump of section '.debug_loclists':
47 # CHECK-NEXT: 0x00000000 0300 .
49 # RUN: ld.lld -shared --gc-sections -z dead-reloc-in-nonalloc=.debug_loclists=0x7f a.o -o a127.so
50 # RUN: llvm-readelf -x .debug_loclists a127.so | FileCheck %s --check-prefix=CHECK127
51 # CHECK127: Hex dump of section '.debug_loclists':
52 # CHECK127-NEXT: 0x00000000 037f .
54 # RUN: not ld.lld -shared --gc-sections -z dead-reloc-in-nonalloc=.debug_loclists=0x80 a.o 2>&1 | FileCheck %s --check-prefix=CHECK128
55 # CHECK128: error: a.o:(.debug_loclists+0x1): ULEB128 value 128 exceeds available space; references 'x2'
57 # RUN: llvm-mc -filetype=obj -triple=riscv64 -mattr=+relax sub.s -o sub.o
58 # RUN: not ld.lld -shared sub.o 2>&1 | FileCheck %s --check-prefix=SUB
59 # SUB: error: sub.o:(.debug_rnglists+0x8): has non-ABS relocation R_RISCV_SUB_ULEB128 against symbol 'w2'
61 # RUN: llvm-mc -filetype=obj -triple=riscv64 -mattr=+relax unpaired1.s -o unpaired1.o
62 # RUN: not ld.lld -shared --threads=1 unpaired1.o 2>&1 | FileCheck %s --check-prefix=UNPAIRED
63 # RUN: llvm-mc -filetype=obj -triple=riscv64 -mattr=+relax unpaired2.s -o unpaired2.o
64 # RUN: not ld.lld -shared --threads=1 unpaired2.o 2>&1 | FileCheck %s --check-prefix=UNPAIRED
65 # RUN: llvm-mc -filetype=obj -triple=riscv64 -mattr=+relax unpaired3.s -o unpaired3.o
66 # RUN: not ld.lld -shared --threads=1 unpaired3.o 2>&1 | FileCheck %s --check-prefix=UNPAIRED
67 # UNPAIRED: error: {{.*}}.o:(.alloc+0x8): R_RISCV_SET_ULEB128 not paired with R_RISCV_SUB_SET128
68 # UNPAIRED: error: {{.*}}.o:(.debug_rnglists+0x8): R_RISCV_SET_ULEB128 not paired with R_RISCV_SUB_SET128
70 # RUN: llvm-mc -filetype=obj -triple=riscv64 -mattr=+relax overflow.s -o overflow.o
71 # RUN: not ld.lld -shared --threads=1 overflow.o 2>&1 | FileCheck %s --check-prefix=OVERFLOW
72 # OVERFLOW: error: overflow.o:(.alloc+0x8): ULEB128 value 128 exceeds available space; references 'w2'
73 # OVERFLOW: error: overflow.o:(.debug_rnglists+0x8): ULEB128 value 128 exceeds available space; references 'w2'
75 # RUN: llvm-mc -filetype=obj -triple=riscv64 -mattr=+relax preemptable.s -o preemptable.o
76 # RUN: not ld.lld -shared --threads=1 preemptable.o 2>&1 | FileCheck %s --check-prefix=PREEMPTABLE --implicit-check-not=error:
77 # PREEMPTABLE: error: relocation R_RISCV_SET_ULEB128 cannot be used against symbol 'w2'; recompile with -fPIC
78 # PREEMPTABLE: error: relocation R_RISCV_SUB_ULEB128 cannot be used against symbol 'w1'; recompile with -fPIC
80 #--- a.s
81 .cfi_startproc
82 .cfi_lsda 0x1b,.LLSDA0
83 .cfi_endproc
85 .section .text.w,"axR"
86 w1:
87 call foo # 4 bytes after relaxation
88 w2:
90 .section .text.x,"ax"
91 x1:
92 call foo # 4 bytes after relaxation
93 x2:
95 .section .gcc_except_table,"a"
96 .LLSDA0:
97 .reloc ., R_RISCV_SET_ULEB128, w1+130
98 .reloc ., R_RISCV_SUB_ULEB128, w2-1 # non-zero addend for SUB
99 .byte 0x7b
100 .uleb128 w2-w1+120 # initial value: 0x0180
101 .uleb128 w1-w2+137 # initial value: 0x0181
102 .uleb128 w2-w1+16376 # initial value: 0x018080
103 .uleb128 w1-w2+16393 # initial value: 0x018081
104 .uleb128 w2-w1+2097144 # initial value: 0x01808080
105 .uleb128 w1-w2+2097161 # initial value: 0x01808081
107 .section .debug_rnglists
108 .reloc ., R_RISCV_SET_ULEB128, w1+130
109 .reloc ., R_RISCV_SUB_ULEB128, w2-1 # non-zero addend for SUB
110 .byte 0x7b
111 .uleb128 w2-w1+120 # initial value: 0x0180
112 .uleb128 w1-w2+137 # initial value: 0x0181
113 .uleb128 w2-w1+16376 # initial value: 0x018080
114 .uleb128 w1-w2+16393 # initial value: 0x018081
115 .uleb128 w2-w1+2097144 # initial value: 0x01808080
116 .uleb128 w1-w2+2097161 # initial value: 0x01808081
118 .section .debug_loclists
119 .reloc ., R_RISCV_SET_ULEB128, w2+3
120 .reloc ., R_RISCV_SUB_ULEB128, w1+4 # SUB with a non-zero addend
121 .byte 0
122 .uleb128 x2-x1 # references discarded symbols
124 #--- sub.s
125 w1: call foo; w2:
126 .section .debug_rnglists
127 .quad 0;
128 .reloc ., R_RISCV_SUB_ULEB128, w2+120
129 .byte 0x7f
131 #--- unpaired1.s
132 w1: call foo; w2:
133 .section .alloc,"a"
134 .quad 0
135 .reloc ., R_RISCV_SET_ULEB128, w2+120
136 .byte 0x7f
137 .section .debug_rnglists
138 .quad 0;
139 .reloc ., R_RISCV_SET_ULEB128, w2+120
140 .byte 0x7f
142 #--- unpaired2.s
143 w1: call foo; w2:
144 .section .alloc,"a"
145 .quad 0
146 .reloc ., R_RISCV_SET_ULEB128, w2+120
147 .reloc .+1, R_RISCV_SUB_ULEB128, w1
148 .byte 0x7f
149 .section .debug_rnglists
150 .quad 0
151 .reloc ., R_RISCV_SET_ULEB128, w2+120
152 .reloc .+1, R_RISCV_SUB_ULEB128, w1
153 .byte 0x7f
155 #--- unpaired3.s
156 w1: call foo; w2:
157 .section .alloc,"a"
158 .quad 0
159 .reloc ., R_RISCV_SET_ULEB128, w2+120
160 .reloc ., R_RISCV_SUB64, w1
161 .byte 0x7f
162 .section .debug_rnglists
163 .quad 0
164 .reloc ., R_RISCV_SET_ULEB128, w2+120
165 .reloc ., R_RISCV_SUB64, w1
166 .byte 0x7f
168 #--- overflow.s
169 w1: call foo; w2:
170 .section .alloc,"a"
171 .quad 0
172 .reloc ., R_RISCV_SET_ULEB128, w2+124
173 .reloc ., R_RISCV_SUB_ULEB128, w1
174 .byte 0x7f
175 .section .debug_rnglists
176 .quad 0
177 .reloc ., R_RISCV_SET_ULEB128, w2+124
178 .reloc ., R_RISCV_SUB_ULEB128, w1
179 .byte 0x7f
181 #--- preemptable.s
182 .globl w1, w2
183 w1: call foo; w2:
184 .section .alloc,"a"
185 .uleb128 w2-w1
186 .section .debug_rnglists
187 .uleb128 w2-w1