xref: /llvm-project/llvm/test/MC/RISCV/riscv64-64b-pcrel.s (revision ffa829c4c5d1cda6b5df3f70cec82888bfc39af9)
1# RUN: llvm-mc -triple riscv64-unknown-linux-gnu -filetype obj %s -o %t
2# RUN: llvm-readobj -r %t | FileCheck %s
3# RUN: llvm-objdump -s %t | FileCheck %s --check-prefix=CONTENT
4
5# CHECK:      Relocations [
6# CHECK-NEXT:   Section ({{.*}}) .rela.note {
7# CHECK-NEXT:     0x0 R_RISCV_ADD64 extern 0x0
8# CHECK-NEXT:     0x0 R_RISCV_SUB64 note 0x0
9# CHECK-NEXT:   }
10# CHECK-NEXT:   Section ({{.*}}) .rela.rodata {
11# CHECK-NEXT:     0x0 R_RISCV_ADD64 extern 0x0
12# CHECK-NEXT:     0x0 R_RISCV_SUB64 rodata 0x0
13# CHECK-NEXT:   }
14# CHECK-NEXT:   Section ({{.*}}) .rela.alloc_w {
15# CHECK-NEXT:     0x0 R_RISCV_ADD64 extern 0x0
16# CHECK-NEXT:     0x0 R_RISCV_SUB64 w 0x0
17# CHECK-NEXT:     0x8 R_RISCV_ADD64 w 0x0
18# CHECK-NEXT:     0x8 R_RISCV_SUB64 extern 0x0
19# CHECK-NEXT:     0x10 R_RISCV_ADD32 x 0x0
20# CHECK-NEXT:     0x10 R_RISCV_SUB32 w 0x0
21# CHECK-NEXT:     0x18 R_RISCV_ADD32 .L.str 0x0
22# CHECK-NEXT:     0x18 R_RISCV_SUB32 w 0x0
23# CHECK-NEXT:   }
24# CHECK-NEXT:   Section ({{.*}}) .rela.alloc_x {
25# CHECK-NEXT:     0x0 R_RISCV_ADD64 y 0x0
26# CHECK-NEXT:     0x0 R_RISCV_SUB64 x 0x0
27# CHECK-NEXT:   }
28# CHECK-NEXT:   Section ({{.*}}) .rela.alloc_y {
29# CHECK-NEXT:     0x0 R_RISCV_ADD64 x 0x0
30# CHECK-NEXT:     0x0 R_RISCV_SUB64 y 0x0
31# CHECK-NEXT:   }
32# CHECK-NEXT:   Section ({{.*}}) .rela.nonalloc_w {
33# CHECK-NEXT:     0x0 R_RISCV_ADD64 extern 0x0
34# CHECK-NEXT:     0x0 R_RISCV_SUB64 nw 0x0
35# CHECK-NEXT:     0x8 R_RISCV_ADD64 nw 0x0
36# CHECK-NEXT:     0x8 R_RISCV_SUB64 extern 0x0
37# CHECK-NEXT:   }
38# CHECK-NEXT:   Section ({{.*}}) .rela.nonalloc_x {
39# CHECK-NEXT:     0x0 R_RISCV_ADD64 ny 0x0
40# CHECK-NEXT:     0x0 R_RISCV_SUB64 nx 0x0
41# CHECK-NEXT:   }
42# CHECK-NEXT:   Section ({{.*}}) .rela.nonalloc_y {
43# CHECK-NEXT:     0x0 R_RISCV_ADD64 nx 0x0
44# CHECK-NEXT:     0x0 R_RISCV_SUB64 ny 0x0
45# CHECK-NEXT:   }
46# CHECK-NEXT: ]
47
48# CONTENT:      Contents of section .alloc_w:
49# CONTENT-NEXT:  0000 00000000 00000000 00000000 00000000
50# CONTENT-NEXT:  0010 00000000 1c000000 00000000
51
52.section .note,"a",@note; note:
53.quad extern-note
54.section .rodata,"a",@progbits; rodata:
55.quad extern-rodata
56
57.section .alloc_w,"aw",@progbits; w:
58.quad extern-w   # extern is undefined
59.quad w-extern
60.long x-w        # A is later defined in another section
61.long w1-w       # A is later defined in the same section
62.long .L.str-w   # A is temporary
63w1:
64
65.section .alloc_x,"aw",@progbits; x:
66.quad y-x
67.section .alloc_y,"aw",@progbits; y:
68.quad x-y
69
70.section .nonalloc_w; nw:
71.quad extern-nw
72.quad nw-extern
73.section .nonalloc_x; nx:
74.quad ny-nx
75.section .nonalloc_y; ny:
76.quad nx-ny
77
78## -gdwarf-aranges generated assembly expects no relocation.
79## Otherwise, a .Lsec_end0 symbol (defined at the end of .rodata.str1.1)
80## will be rejected by linkers.
81.section .rodata.str1.1,"aMS",@progbits,1
82.L.str:
83  .asciz  "hello"
84.section .rodata.str1.1,"aMS",@progbits,1
85.Lsec_end0:
86.section .debug_aranges,"",@progbits
87.quad .Lsec_end0-.L.str
88
89## .apple_names/.apple_types are fixed-size and do not need fixups.
90## llvm-dwarfdump --apple-names does not process R_RISCV_{ADD,SUB}32 in them.
91## See llvm/test/DebugInfo/Generic/accel-table-hash-collisions.ll
92	.section	.apple_types
93        .word 0
94        .word .Ltypes0-.apple_types
95.Ltypes0:
96