xref: /llvm-project/llvm/test/MC/RISCV/leb128.s (revision 1df5ea29b43690b6622db2cad7b745607ca4de6a)
1# RUN: llvm-mc -filetype=obj -triple=riscv32 -mattr=-relax %s -o %t
2# RUN: llvm-readobj -r -x .alloc_w %t| FileCheck %s
3# RUN: llvm-mc -filetype=obj -triple=riscv32 -mattr=+relax %s -o %t.relax
4# RUN: llvm-readobj -r -x .alloc_w %t.relax | FileCheck %s --check-prefixes=CHECK,RELAX
5
6# RUN: llvm-mc -filetype=obj -triple=riscv64 -mattr=-relax %s -o %t
7# RUN: llvm-readobj -r -x .alloc_w %t | FileCheck %s
8# RUN: llvm-mc -filetype=obj -triple=riscv64 -mattr=+relax %s -o %t.relax
9# RUN: llvm-readobj -r -x .alloc_w %t.relax | FileCheck %s --check-prefixes=CHECK,RELAX
10
11## Test temporary workaround for suppressting relocations for actually-non-foldable
12## DWARF v5 DW_LLE_offset_pair/DW_RLE_offset_pair.
13# RUN: llvm-mc -filetype=obj -triple=riscv64 -mattr=-relax -riscv-uleb128-reloc=0 %s -o %t0
14# RUN: llvm-readobj -r -x .alloc_w %t0 | FileCheck %s --check-prefix=CHECK0
15# RUN: llvm-mc -filetype=obj -triple=riscv64 -mattr=+relax -riscv-uleb128-reloc=0 %s -o %t0.relax
16# RUN: llvm-readobj -r -x .alloc_w %t0.relax | FileCheck %s --check-prefixes=CHECK0,RELAX0
17
18# RUN: not llvm-mc -filetype=obj -triple=riscv64 -mattr=-relax --defsym ERR=1 %s -o /dev/null 2>&1 | \
19# RUN:   FileCheck %s --check-prefix=ERR
20# RUN: not llvm-mc -filetype=obj -triple=riscv64 -mattr=+relax --defsym ERR=1 %s -o /dev/null 2>&1 | \
21# RUN:   FileCheck %s --check-prefix=ERR
22
23# CHECK0:      Relocations [
24# CHECK0-NEXT:   .rela.alloc_w {
25# CHECK0-NEXT:     0x2 R_RISCV_CALL_PLT foo 0x0
26# RELAX0-NEXT:     0x2 R_RISCV_RELAX - 0x0
27# CHECK0-NEXT:   }
28# CHECK0-NEXT: ]
29
30# CHECK:      Relocations [
31# CHECK-NEXT:   .rela.alloc_w {
32# CHECK-NEXT:     0x0 R_RISCV_SET_ULEB128 w1 0x0
33# CHECK-NEXT:     0x0 R_RISCV_SUB_ULEB128 w 0x0
34# RELAX-NEXT:     0x1 R_RISCV_SET_ULEB128 w2 0x0
35# RELAX-NEXT:     0x1 R_RISCV_SUB_ULEB128 w1 0x0
36# CHECK-NEXT:     0x2 R_RISCV_CALL_PLT foo 0x0
37# RELAX-NEXT:     0x2 R_RISCV_RELAX - 0x0
38# RELAX-NEXT:     0xA R_RISCV_SET_ULEB128 w2 0x0
39# RELAX-NEXT:     0xA R_RISCV_SUB_ULEB128 w1 0x0
40# RELAX-NEXT:     0xB R_RISCV_SET_ULEB128 w2 0x78
41# RELAX-NEXT:     0xB R_RISCV_SUB_ULEB128 w1 0x0
42# RELAX-NEXT:     0xD R_RISCV_SET_ULEB128 w1 0x0
43# RELAX-NEXT:     0xD R_RISCV_SUB_ULEB128 w2 0x0
44# CHECK-NEXT:   }
45# CHECK-NEXT: ]
46
47## R_RISCV_SET_ULEB128 relocated locations contain values not accounting for linker relaxation.
48# CHECK:      Hex dump of section '.alloc_w':
49# CHECK-NEXT: 0x00000000 02089700 0000e780 00000880 01f8ffff ................
50# CHECK-NEXT: 0x00000010 ffffffff ffff01                     .......
51
52.section .alloc_w,"ax",@progbits; w:
53.uleb128 w1-w       # w1 is later defined in the same section
54.uleb128 w2-w1      # w1 and w2 are separated by a linker relaxable instruction
55w1:
56  call foo
57w2:
58.uleb128 w2-w1      # 0x08
59.uleb128 w2-w1+120  # 0x0180
60.uleb128 -(w2-w1)   # 0x01fffffffffffffffff8
61
62.ifdef ERR
63# ERR: :[[#@LINE+1]]:16: error: .uleb128 expression is not absolute
64.uleb128 extern-w   # extern is undefined
65# ERR: :[[#@LINE+1]]:11: error: .uleb128 expression is not absolute
66.uleb128 w-extern
67# ERR: :[[#@LINE+1]]:11: error: .uleb128 expression is not absolute
68.uleb128 x-w        # x is later defined in another section
69
70.section .alloc_x,"aw",@progbits; x:
71# ERR: :[[#@LINE+1]]:11: error: .uleb128 expression is not absolute
72.uleb128 y-x
73.section .alloc_y,"aw",@progbits; y:
74# ERR: :[[#@LINE+1]]:11: error: .uleb128 expression is not absolute
75.uleb128 x-y
76
77# ERR: :[[#@LINE+1]]:10: error: .uleb128 expression is not absolute
78.uleb128 extern
79# ERR: :[[#@LINE+1]]:10: error: .uleb128 expression is not absolute
80.uleb128 y
81.endif
82