11# REQUIRES: riscv
22# RUN: rm -rf %t && split-file %s %t && cd %t
33# RUN: llvm-mc -filetype=obj -triple=riscv64 -mattr=+relax a.s -o a.o
4- # RUN: llvm-readobj -r -x .debug_rnglists -x .debug_loclists a.o | FileCheck %s --check-prefix=REL
5- # RUN: ld.lld -shared --gc-sections a.o -o a.so
6- # RUN: llvm-readelf -x .debug_rnglists -x .debug_loclists a.so | FileCheck %s
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
77
88# REL: .rela.debug_rnglists {
9- # REL-NEXT: 0x0 R_RISCV_SET_ULEB128 w1 0x83
10- # REL-NEXT: 0x0 R_RISCV_SUB_ULEB128 w2 0x0
9+ # REL-NEXT: 0x0 R_RISCV_SET_ULEB128 w1 0x82
10+ # REL-NEXT: 0x0 R_RISCV_SUB_ULEB128 w2 0xFFFFFFFFFFFFFFFF
1111# REL-NEXT: 0x1 R_RISCV_SET_ULEB128 w2 0x78
1212# REL-NEXT: 0x1 R_RISCV_SUB_ULEB128 w1 0x0
1313# REL-NEXT: 0x3 R_RISCV_SET_ULEB128 w1 0x89
2828# REL-NEXT: 0x1 R_RISCV_SUB_ULEB128 x1 0x0
2929# REL-NEXT: }
3030
31+ # REL: Hex dump of section '.gcc_except_table':
32+ # REL-NEXT: 0x00000000 7b800181 01808001 81800180 80800181 {
33+ # REL-NEXT: 0x00000010 808001 .
3134# REL: Hex dump of section '.debug_rnglists':
3235# REL-NEXT: 0x00000000 7b800181 01808001 81800180 80800181 {
3336# REL-NEXT: 0x00000010 808001 .
3437# REL: Hex dump of section '.debug_loclists':
3538# REL-NEXT: 0x00000000 0008 .
3639
40+ # CHECK: Hex dump of section '.gcc_except_table':
41+ # CHECK-NEXT: 0x[[#%x,]] 7ffc0085 01fcff00 858001fc ffff0085 .
42+ # CHECK-NEXT: 0x[[#%x,]] 808001 .
3743# CHECK: Hex dump of section '.debug_rnglists':
3844# CHECK-NEXT: 0x00000000 7ffc0085 01fcff00 858001fc ffff0085 .
3945# CHECK-NEXT: 0x00000010 808001 .
5056
5157# RUN: llvm-mc -filetype=obj -triple=riscv64 -mattr=+relax sub.s -o sub.o
5258# RUN: not ld.lld -shared sub.o 2>&1 | FileCheck %s --check-prefix=SUB
53- # SUB: error: sub.o:(.debug_rnglists+0x8): unknown relocation (61) against symbol w2
59+ # SUB: error: sub.o:(.debug_rnglists+0x8): has non-ABS relocation R_RISCV_SUB_ULEB128 against symbol 'w2'
5460
5561# RUN: llvm-mc -filetype=obj -triple=riscv64 -mattr=+relax unpaired1.s -o unpaired1.o
56- # RUN: not ld.lld -shared unpaired1.o 2>&1 | FileCheck %s --check-prefix=UNPAIRED
62+ # RUN: not ld.lld -shared --threads=1 unpaired1.o 2>&1 | FileCheck %s --check-prefix=UNPAIRED
5763# RUN: llvm-mc -filetype=obj -triple=riscv64 -mattr=+relax unpaired2.s -o unpaired2.o
58- # RUN: not ld.lld -shared unpaired2.o 2>&1 | FileCheck %s --check-prefix=UNPAIRED
64+ # RUN: not ld.lld -shared --threads=1 unpaired2.o 2>&1 | FileCheck %s --check-prefix=UNPAIRED
5965# RUN: llvm-mc -filetype=obj -triple=riscv64 -mattr=+relax unpaired3.s -o unpaired3.o
60- # RUN: not ld.lld -shared unpaired3.o 2>&1 | FileCheck %s --check-prefix=UNPAIRED
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
6168# UNPAIRED: error: {{.*}}.o:(.debug_rnglists+0x8): R_RISCV_SET_ULEB128 not paired with R_RISCV_SUB_SET128
6269
6370# RUN: llvm-mc -filetype=obj -triple=riscv64 -mattr=+relax overflow.s -o overflow.o
64- # RUN: not ld.lld -shared overflow.o 2>&1 | FileCheck %s --check-prefix=OVERFLOW
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'
6573# OVERFLOW: error: overflow.o:(.debug_rnglists+0x8): ULEB128 value 128 exceeds available space; references 'w2'
6674
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
79+
6780#--- a.s
81+ .cfi_startproc
82+ .cfi_lsda 0x1b ,.LLSDA0
83+ .cfi_endproc
84+
6885.section .text .w,"axR"
6986w1:
7087 call foo # 4 bytes after relaxation
7592 call foo # 4 bytes after relaxation
7693x2:
7794
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
106+
78107.section .debug_rnglists
79- .uleb128 w1-w2+131 # initial value: 0x7b
108+ .reloc ., R_RISCV_SET_ULEB128, w1+130
109+ .reloc ., R_RISCV_SUB_ULEB128, w2-1 # non-zero addend for SUB
110+ .byte 0x7b
80111.uleb128 w2-w1+120 # initial value: 0x0180
81112.uleb128 w1-w2+137 # initial value: 0x0181
82113.uleb128 w2-w1+16376 # initial value: 0x018080
@@ -99,13 +130,22 @@ w1: call foo; w2:
99130
100131#--- unpaired1.s
101132w1: call foo; w2:
133+ .section .alloc,"a"
134+ .quad 0
135+ .reloc ., R_RISCV_SET_ULEB128, w2+120
136+ .byte 0x7f
102137.section .debug_rnglists
103138.quad 0 ;
104139.reloc ., R_RISCV_SET_ULEB128, w2+120
105140.byte 0x7f
106141
107142#--- unpaired2.s
108143w1: 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
109149.section .debug_rnglists
110150.quad 0
111151.reloc ., R_RISCV_SET_ULEB128, w2+120
@@ -114,6 +154,11 @@ w1: call foo; w2:
114154
115155#--- unpaired3.s
116156w1: 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
117162.section .debug_rnglists
118163.quad 0
119164.reloc ., R_RISCV_SET_ULEB128, w2+120
@@ -122,8 +167,21 @@ w1: call foo; w2:
122167
123168#--- overflow.s
124169w1: 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
125175.section .debug_rnglists
126176.quad 0
127177.reloc ., R_RISCV_SET_ULEB128, w2+124
128178.reloc ., R_RISCV_SUB_ULEB128, w1
129179.byte 0x7f
180+
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
0 commit comments