[ELF] Make SyntheticSection parameter order match InputSection
[llvm-project.git] / lld / test / ELF / aarch64-relocs.s
blob198674c085b54ea1d7e70950700e22556d4d7502
1 # REQUIRES: aarch64
2 # RUN: llvm-mc -filetype=obj -triple=aarch64-unknown-freebsd %s -o %t
3 # RUN: echo '.globl zero; zero = 0' | llvm-mc -filetype=obj -triple=aarch64-unknown-freebsd -o %t2.o
4 # RUN: ld.lld %t %t2.o -o %t2
5 # RUN: llvm-objdump --no-print-imm-hex -d %t2 | FileCheck %s
7 .section .R_AARCH64_ADR_PREL_LO21,"ax",@progbits
8 .globl _start
9 _start:
10 adr x1,msg
11 msg: .asciz "Hello, world\n"
12 msgend:
14 # CHECK: Disassembly of section .R_AARCH64_ADR_PREL_LO21:
15 # CHECK-EMPTY:
16 # CHECK: <_start>:
17 # CHECK: 0: 10000021 adr x1, 0x210124
18 # CHECK: <msg>:
19 # CHECK: 4:
20 # #4 is the adr immediate value.
22 .section .R_AARCH64_ADR_PREL_PG_HI21,"ax",@progbits
23 adrp x1,mystr
24 mystr:
25 .asciz "blah"
26 .size mystr, 4
28 # PAGE(S + A) - PAGE(P) = PAGE(210136) - PAGE(0x210132) = 0
30 # CHECK: Disassembly of section .R_AARCH64_ADR_PREL_PG_HI21:
31 # CHECK-EMPTY:
32 # CHECK-NEXT: <.R_AARCH64_ADR_PREL_PG_HI21>:
33 # CHECK-NEXT: 210132: 90000001 adrp x1, 0x210000
35 .section .R_AARCH64_ADD_ABS_LO12_NC,"ax",@progbits
36 add x0, x0, :lo12:.L.str
37 .L.str:
38 .asciz "blah"
39 .size mystr, 4
41 # S = 0x21013b, A = 0x4
42 # R = (S + A) & 0xFFF = 319
44 # CHECK: Disassembly of section .R_AARCH64_ADD_ABS_LO12_NC:
45 # CHECK-EMPTY:
46 # CHECK-NEXT: <.R_AARCH64_ADD_ABS_LO12_NC>:
47 # CHECK-NEXT: 21013b: 9104fc00 add x0, x0, #319
49 .section .R_AARCH64_LDST64_ABS_LO12_NC,"ax",@progbits
50 ldr x28, [x27, :lo12:foo]
51 foo:
52 .asciz "foo"
53 .size mystr, 3
55 # S = 0x210144, A = 0x4
56 # R = ((S + A) & 0xFFF) << 7 = 0x0000a400
57 # 0x0000a400 | 0xf940177c = 0xf940a77c
58 # CHECK: Disassembly of section .R_AARCH64_LDST64_ABS_LO12_NC:
59 # CHECK-EMPTY:
60 # CHECK-NEXT: <.R_AARCH64_LDST64_ABS_LO12_NC>:
61 # CHECK-NEXT: 210144: f940a77c ldr x28, [x27, #328]
63 .section .SUB,"ax",@progbits
64 nop
65 sub:
66 nop
68 # CHECK: Disassembly of section .SUB:
69 # CHECK-EMPTY:
70 # CHECK-NEXT: <.SUB>:
71 # CHECK-NEXT: 21014c: d503201f nop
72 # CHECK: <sub>:
73 # CHECK-NEXT: 210150: d503201f nop
75 .section .R_AARCH64_CALL26,"ax",@progbits
76 call26:
77 bl sub
79 # S = 0x21014c, A = 0x4, P = 0x210154
80 # R = S + A - P = -0x4 = 0xfffffffc
81 # (R & 0x0ffffffc) >> 2 = 0x03ffffff
82 # 0x94000000 | 0x03ffffff = 0x97ffffff
83 # CHECK: Disassembly of section .R_AARCH64_CALL26:
84 # CHECK-EMPTY:
85 # CHECK-NEXT: <call26>:
86 # CHECK-NEXT: 210154: 97ffffff bl 0x210150
88 .section .R_AARCH64_JUMP26,"ax",@progbits
89 jump26:
90 b sub
92 # S = 0x21014c, A = 0x4, P = 0x210158
93 # R = S + A - P = -0x8 = 0xfffffff8
94 # (R & 0x0ffffffc) >> 2 = 0x03fffffe
95 # 0x14000000 | 0x03fffffe = 0x17fffffe
96 # CHECK: Disassembly of section .R_AARCH64_JUMP26:
97 # CHECK-EMPTY:
98 # CHECK-NEXT: <jump26>:
99 # CHECK-NEXT: 210158: 17fffffe b 0x210150
101 .section .R_AARCH64_LDST32_ABS_LO12_NC,"ax",@progbits
102 ldst32:
103 ldr s4, [x5, :lo12:foo32]
104 foo32:
105 .asciz "foo"
106 .size mystr, 3
108 # S = 0x21015c, A = 0x4
109 # R = ((S + A) & 0xFFC) << 8 = 0x00016000
110 # 0x00016000 | 0xbd4000a4 = 0xbd4160a4
111 # CHECK: Disassembly of section .R_AARCH64_LDST32_ABS_LO12_NC:
112 # CHECK-EMPTY:
113 # CHECK-NEXT: <ldst32>:
114 # CHECK-NEXT: 21015c: bd4160a4 ldr s4, [x5, #352]
116 .section .R_AARCH64_LDST8_ABS_LO12_NC,"ax",@progbits
117 ldst8:
118 ldrsb x11, [x13, :lo12:foo8]
119 foo8:
120 .asciz "foo"
121 .size mystr, 3
123 # S = 0x210164, A = 0x4
124 # R = ((S + A) & 0xFFF) << 10 = 0x0005a000
125 # 0x0005a000 | 0x398001ab = 0x3985a1ab
126 # CHECK: Disassembly of section .R_AARCH64_LDST8_ABS_LO12_NC:
127 # CHECK-EMPTY:
128 # CHECK-NEXT: <ldst8>:
129 # CHECK-NEXT: 210164: 3985a1ab ldrsb x11, [x13, #360]
131 .section .R_AARCH64_LDST128_ABS_LO12_NC,"ax",@progbits
132 ldst128:
133 ldr q20, [x19, #:lo12:foo128]
134 foo128:
135 .asciz "foo"
136 .size mystr, 3
138 # S = 0x21016c, A = 0x4
139 # R = ((S + A) & 0xFF8) << 6 = 0x00005c00
140 # 0x00005c00 | 0x3dc00274 = 0x3dc05e74
141 # CHECK: Disassembly of section .R_AARCH64_LDST128_ABS_LO12_NC:
142 # CHECK-EMPTY:
143 # CHECK: <ldst128>:
144 # CHECK: 21016c: 3dc05e74 ldr q20, [x19, #368]
145 #foo128:
146 # 210170: 66 6f 6f 00 .word
148 .section .R_AARCH64_LDST16_ABS_LO12_NC,"ax",@progbits
149 ldst16:
150 ldr h17, [x19, :lo12:foo16]
151 ldrh w1, [x19, :lo12:foo16]
152 ldrh w2, [x19, :lo12:foo16 + 2]
153 foo16:
154 .asciz "foo"
155 .size mystr, 4
157 # S = 0x210174, A = 0x4
158 # R = ((S + A) & 0x0FFC) << 9 = 0x2f000
159 # 0x2f000 | 0x7d400271 = 0x7d430271
160 # CHECK: Disassembly of section .R_AARCH64_LDST16_ABS_LO12_NC:
161 # CHECK-EMPTY:
162 # CHECK-NEXT: <ldst16>:
163 # CHECK-NEXT: 210174: 7d430271 ldr h17, [x19, #384]
164 # CHECK-NEXT: 210178: 79430261 ldrh w1, [x19, #384]
165 # CHECK-NEXT: 21017c: 79430662 ldrh w2, [x19, #386]
167 .section .R_AARCH64_MOVW_UABS,"ax",@progbits
168 movz1:
169 movk x12, #:abs_g0:zero+0xC
170 movk x12, #:abs_g0_nc:zero+0xF000E000D000C
171 movk x13, #:abs_g1:zero+0xD000C
172 movk x13, #:abs_g1_nc:zero+0xF000E000D000C
173 movk x14, #:abs_g2:zero+0xE000D000C
174 movk x14, #:abs_g2_nc:zero+0xF000E000D000C
175 movz x15, #:abs_g3:zero+0xF000E000D000C
176 movk x16, #:abs_g3:zero+0xF000E000D000C
178 ## 4222124650659840 == (0xF << 48)
179 # CHECK: Disassembly of section .R_AARCH64_MOVW_UABS:
180 # CHECK-EMPTY:
181 # CHECK-NEXT: <movz1>:
182 # CHECK-NEXT: f280018c movk x12, #12
183 # CHECK-NEXT: f280018c movk x12, #12
184 # CHECK-NEXT: f2a001ad movk x13, #13, lsl #16
185 # CHECK-NEXT: f2a001ad movk x13, #13, lsl #16
186 # CHECK-NEXT: f2c001ce movk x14, #14, lsl #32
187 # CHECK-NEXT: f2c001ce movk x14, #14, lsl #32
188 # CHECK-NEXT: d2e001ef mov x15, #4222124650659840
189 # CHECK-NEXT: f2e001f0 movk x16, #15, lsl #48
191 .section .R_AARCH64_MOVW_SABS,"ax",@progbits
192 movz x1, #:abs_g0_s:zero+1
193 movz x1, #:abs_g0_s:zero-1
194 movz x2, #:abs_g1_s:zero+0x20000
195 movz x2, #:abs_g1_s:zero-0x20000
196 movz x3, #:abs_g2_s:zero+0x300000000
197 movz x3, #:abs_g2_s:zero-0x300000000
199 # CHECK: Disassembly of section .R_AARCH64_MOVW_SABS:
200 # CHECK-EMPTY:
201 # CHECK-NEXT: :
202 # CHECK-NEXT: d2800021 mov x1, #1
203 # CHECK-NEXT: 92800001 mov x1, #-1
204 # CHECK-NEXT: d2a00042 mov x2, #131072
205 ## -65537 = 0xfffffffffffeffff
206 # CHECK-NEXT: 92a00022 mov x2, #-65537
207 ## 12884901888 = 0x300000000
208 # CHECK-NEXT: d2c00063 mov x3, #12884901888
209 ## -8589934593 = #0xfffffffdffffffff
210 # CHECK-NEXT: 92c00043 mov x3, #-8589934593
212 .section .R_AARCH64_MOVW_PREL,"ax",@progbits
213 movz x1, #:prel_g0:.+1
214 movz x1, #:prel_g0_nc:.-1
215 movk x1, #:prel_g0:.+1
216 movk x1, #:prel_g0_nc:.-1
217 movz x2, #:prel_g1:.+0x20000
218 movz x2, #:prel_g1_nc:.-0x20000
219 movk x2, #:prel_g1:.+0x20000
220 movk x2, #:prel_g1_nc:.-0x20000
221 movz x3, #:prel_g2:.+0x300000000
222 movz x3, #:prel_g2_nc:.-0x300000000
223 movk x3, #:prel_g2:.+0x300000000
224 movk x3, #:prel_g2_nc:.-0x300000000
225 movz x3, #:prel_g2:.+0x300000000
226 movz x4, #:prel_g3:.+0x4000000000000
227 movz x4, #:prel_g3:.-0x4000000000000
228 movk x4, #:prel_g3:.+0x4000000000000
229 movk x4, #:prel_g3:.-0x4000000000000
231 # CHECK: Disassembly of section .R_AARCH64_MOVW_PREL:
232 # CHECK-EMPTY:
233 # CHECK-NEXT: :
234 # CHECK-NEXT: 2101bc: d2800021 mov x1, #1
235 # CHECK-NEXT: 2101c0: 92800001 mov x1, #-1
236 # CHECK-NEXT: 2101c4: f2800021 movk x1, #1
237 # CHECK-NEXT: 2101c8: f29fffe1 movk x1, #65535
238 # CHECK-NEXT: 2101cc: d2a00042 mov x2, #131072
239 ## -65537 = 0xfffffffffffeffff
240 # CHECK-NEXT: 2101d0: 92a00022 mov x2, #-65537
241 # CHECK-NEXT: 2101d4: f2a00042 movk x2, #2, lsl #16
242 # CHECK-NEXT: 2101d8: f2bfffc2 movk x2, #65534, lsl #16
243 ## 12884901888 = 0x300000000
244 # CHECK-NEXT: 2101dc: d2c00063 mov x3, #12884901888
245 ## -8589934593 = #0xfffffffdffffffff
246 # CHECK-NEXT: 2101e0: 92c00043 mov x3, #-8589934593
247 # CHECK-NEXT: 2101e4: f2c00063 movk x3, #3, lsl #32
248 # CHECK-NEXT: 2101e8: f2dfffa3 movk x3, #65533, lsl #32
249 # CHECK-NEXT: 2101ec: d2c00063 mov x3, #12884901888
250 ## 1125899906842624 = 0x4000000000000
251 # CHECK-NEXT: 2101f0: d2e00084 mov x4, #1125899906842624
252 # CHECK-NEXT: 2101f4: d2ffff84 mov x4, #-1125899906842624
253 # CHECK-NEXT: 2101f8: f2e00084 movk x4, #4, lsl #48
254 # CHECK-NEXT: 2101fc: f2ffff84 movk x4, #65532, lsl #48