[obj2yaml] - Fix a comment. NFC.
[llvm-complete.git] / test / MC / RISCV / linker-relaxation.s
blob411c7f888702784995ea50610344e86942c3b961
1 # RUN: llvm-mc -filetype=obj -triple riscv32 -mattr=+relax < %s \
2 # RUN: | llvm-readobj -r | FileCheck -check-prefix=RELAX-RELOC %s
3 # RUN: llvm-mc -filetype=obj -triple riscv32 -mattr=-relax < %s \
4 # RUN: | llvm-readobj -r | FileCheck -check-prefix=NORELAX-RELOC %s
5 # RUN: llvm-mc -triple riscv32 -mattr=+relax < %s -show-encoding \
6 # RUN: | FileCheck -check-prefix=RELAX-FIXUP %s
7 # RUN: llvm-mc -filetype=obj -triple riscv64 -mattr=+relax < %s \
8 # RUN: | llvm-readobj -r | FileCheck -check-prefix=RELAX-RELOC %s
9 # RUN: llvm-mc -filetype=obj -triple riscv64 -mattr=-relax < %s \
10 # RUN: | llvm-readobj -r | FileCheck -check-prefix=NORELAX-RELOC %s
11 # RUN: llvm-mc -triple riscv64 -mattr=+relax < %s -show-encoding \
12 # RUN: | FileCheck -check-prefix=RELAX-FIXUP %s
14 .long foo
16 call foo
17 # NORELAX-RELOC: R_RISCV_CALL foo 0x0
18 # NORELAX-RELOC-NOT: R_RISCV_RELAX
19 # RELAX-RELOC: R_RISCV_CALL foo 0x0
20 # RELAX-RELOC: R_RISCV_RELAX - 0x0
21 # RELAX-FIXUP: fixup A - offset: 0, value: foo, kind: fixup_riscv_call
22 # RELAX-FIXUP: fixup B - offset: 0, value: 0, kind: fixup_riscv_relax
24 lui t1, %hi(foo)
25 # NORELAX-RELOC: R_RISCV_HI20 foo 0x0
26 # NORELAX-RELOC-NOT: R_RISCV_RELAX
27 # RELAX-RELOC: R_RISCV_HI20 foo 0x0
28 # RELAX-RELOC: R_RISCV_RELAX - 0x0
29 # RELAX-FIXUP: fixup A - offset: 0, value: %hi(foo), kind: fixup_riscv_hi20
30 # RELAX-FIXUP: fixup B - offset: 0, value: 0, kind: fixup_riscv_relax
32 addi t1, t1, %lo(foo)
33 # NORELAX-RELOC: R_RISCV_LO12_I foo 0x0
34 # NORELAX-RELOC-NOT: R_RISCV_RELAX
35 # RELAX-RELOC: R_RISCV_LO12_I foo 0x0
36 # RELAX-RELOC: R_RISCV_RELAX - 0x0
37 # RELAX-FIXUP: fixup A - offset: 0, value: %lo(foo), kind: fixup_riscv_lo12_i
38 # RELAX-FIXUP: fixup B - offset: 0, value: 0, kind: fixup_riscv_relax
40 sb t1, %lo(foo)(a2)
41 # NORELAX-RELOC: R_RISCV_LO12_S foo 0x0
42 # NORELAX-RELOC-NOT: R_RISCV_RELAX
43 # RELAX-RELOC: R_RISCV_LO12_S foo 0x0
44 # RELAX-RELOC: R_RISCV_RELAX - 0x0
45 # RELAX-FIXUP: fixup A - offset: 0, value: %lo(foo), kind: fixup_riscv_lo12_s
46 # RELAX-FIXUP: fixup B - offset: 0, value: 0, kind: fixup_riscv_relax
49 auipc t1, %pcrel_hi(foo)
50 # NORELAX-RELOC: R_RISCV_PCREL_HI20 foo 0x0
51 # NORELAX-RELOC-NOT: R_RISCV_RELAX
52 # RELAX-RELOC: R_RISCV_PCREL_HI20 foo 0x0
53 # RELAX-RELOC: R_RISCV_RELAX - 0x0
54 # RELAX-FIXUP: fixup A - offset: 0, value: %pcrel_hi(foo), kind: fixup_riscv_pcrel_hi20
55 # RELAX-FIXUP: fixup B - offset: 0, value: 0, kind: fixup_riscv_relax
57 addi t1, t1, %pcrel_lo(1b)
58 # NORELAX-RELOC: R_RISCV_PCREL_LO12_I .Ltmp0 0x0
59 # NORELAX-RELOC-NOT: R_RISCV_RELAX
60 # RELAX-RELOC: R_RISCV_PCREL_LO12_I .Ltmp0 0x0
61 # RELAX-RELOC: R_RISCV_RELAX - 0x0
62 # RELAX-FIXUP: fixup A - offset: 0, value: %pcrel_lo(.Ltmp0), kind: fixup_riscv_pcrel_lo12_i
63 # RELAX-FIXUP: fixup B - offset: 0, value: 0, kind: fixup_riscv_relax
65 sb t1, %pcrel_lo(1b)(a2)
66 # NORELAX-RELOC: R_RISCV_PCREL_LO12_S .Ltmp0 0x0
67 # NORELAX-RELOC-NOT: R_RISCV_RELAX
68 # RELAX-RELOC: R_RISCV_PCREL_LO12_S .Ltmp0 0x0
69 # RELAX-RELOC: R_RISCV_RELAX - 0x0
70 # RELAX-FIXUP: fixup A - offset: 0, value: %pcrel_lo(.Ltmp0), kind: fixup_riscv_pcrel_lo12_s
71 # RELAX-FIXUP: fixup B - offset: 0, value: 0, kind: fixup_riscv_relax
74 # Check behaviour when a locally defined symbol is referenced.
75 bar:
77 beq s1, s1, bar
78 # NORELAX-RELOC-NOT: R_RISCV_BRANCH
79 # RELAX-RELOC: R_RISCV_BRANCH bar 0x0
80 # RELAX-FIXUP: fixup A - offset: 0, value: bar, kind: fixup_riscv_branch
81 # RELAX-FIXUP-NOT: fixup B - offset: 0, value: 0, kind: fixup_riscv_relax
83 call bar
84 # NORELAX-RELOC-NOT: R_RISCV_CALL
85 # NORELAX-RELOC-NOT: R_RISCV_RELAX
86 # RELAX-RELOC: R_RISCV_CALL bar 0x0
87 # RELAX-RELOC: R_RISCV_RELAX - 0x0
88 # RELAX-FIXUP: fixup A - offset: 0, value: bar, kind: fixup_riscv_call
89 # RELAX-FIXUP: fixup B - offset: 0, value: 0, kind: fixup_riscv_relax
91 lui t1, %hi(bar)
92 # NORELAX-RELOC: R_RISCV_HI20 bar 0x0
93 # NORELAX-RELOC-NOT: R_RISCV_RELAX
94 # RELAX-RELOC: R_RISCV_HI20 bar 0x0
95 # RELAX-RELOC: R_RISCV_RELAX - 0x0
96 # RELAX-FIXUP: fixup A - offset: 0, value: %hi(bar), kind: fixup_riscv_hi20
97 # RELAX-FIXUP: fixup B - offset: 0, value: 0, kind: fixup_riscv_relax
99 addi t1, t1, %lo(bar)
100 # NORELAX-RELOC: R_RISCV_LO12_I bar 0x0
101 # NORELAX-RELOC-NOT: R_RISCV_RELAX
102 # RELAX-RELOC: R_RISCV_LO12_I bar 0x0
103 # RELAX-RELOC: R_RISCV_RELAX - 0x0
104 # RELAX-FIXUP: fixup A - offset: 0, value: %lo(bar), kind: fixup_riscv_lo12_i
105 # RELAX-FIXUP: fixup B - offset: 0, value: 0, kind: fixup_riscv_relax
107 sb t1, %lo(bar)(a2)
108 # NORELAX-RELOC: R_RISCV_LO12_S bar 0x0
109 # NORELAX-RELOC-NOT: R_RISCV_RELAX
110 # RELAX-RELOC: R_RISCV_LO12_S bar 0x0
111 # RELAX-RELOC: R_RISCV_RELAX - 0x0
112 # RELAX-FIXUP: fixup A - offset: 0, value: %lo(bar), kind: fixup_riscv_lo12_s
113 # RELAX-FIXUP: fixup B - offset: 0, value: 0, kind: fixup_riscv_relax
116 auipc t1, %pcrel_hi(bar)
117 # NORELAX-RELOC-NOT: R_RISCV_PCREL_HI20
118 # NORELAX-RELOC-NOT: R_RISCV_RELAX
119 # RELAX-RELOC: R_RISCV_PCREL_HI20 bar 0x0
120 # RELAX-RELOC: R_RISCV_RELAX - 0x0
121 # RELAX-FIXUP: fixup A - offset: 0, value: %pcrel_hi(bar), kind: fixup_riscv_pcrel_hi20
122 # RELAX-FIXUP: fixup B - offset: 0, value: 0, kind: fixup_riscv_relax
124 addi t1, t1, %pcrel_lo(2b)
125 # NORELAX-RELOC-NOT: R_RISCV_PCREL_LO12_I
126 # NORELAX-RELOC-NOT: R_RISCV_RELAX
127 # RELAX-RELOC: R_RISCV_PCREL_LO12_I .Ltmp1 0x0
128 # RELAX-RELOC: R_RISCV_RELAX - 0x0
129 # RELAX-FIXUP: fixup A - offset: 0, value: %pcrel_lo(.Ltmp1), kind: fixup_riscv_pcrel_lo12_i
130 # RELAX-FIXUP: fixup B - offset: 0, value: 0, kind: fixup_riscv_relax
132 sb t1, %pcrel_lo(2b)(a2)
133 # NORELAX-RELOC-NOT: R_RISCV_PCREL_LO12_S
134 # NORELAX-RELOC-NOT: R_RISCV_RELAX
135 # RELAX-RELOC: R_RISCV_PCREL_LO12_S .Ltmp1 0x0
136 # RELAX-RELOC: R_RISCV_RELAX - 0x0
137 # RELAX-FIXUP: fixup A - offset: 0, value: %pcrel_lo(.Ltmp1), kind: fixup_riscv_pcrel_lo12_s
138 # RELAX-FIXUP: fixup B - offset: 0, value: 0, kind: fixup_riscv_relax
140 # Check that a relocation is not emitted for a symbol difference which has
141 # been folded to a fixup with an absolute value. This can happen when a
142 # difference expression refers to two symbols, at least one of which is
143 # not defined at the point it is referenced. Then during *assembler*
144 # relaxation when both symbols have become defined the difference may be folded
145 # down to a fixup simply containing the absolute value. We want to ensure that
146 # we don't force a relocation to be emitted for this absolute value even
147 # when linker relaxation is enabled. The reason for this is that one instance
148 # where this pattern appears in in the .eh_frame section (the CIE 'length'
149 # field), and the .eh_frame section cannot be parsed by the linker unless the
150 # fixup has been resolved to a concrete value instead of a relocation.
151 .data
153 .word hi-lo
154 .quad hi-lo
155 # NORELAX-RELOC-NOT: R_RISCV_32
156 # NORELAX-RELOC-NOT: R_RISCV_64
157 # RELAX-RELOC-NOT: R_RISCV_32
158 # RELAX-RELOC-NOT: R_RISCV_64