• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// RUN: llvm-mc -triple=arm64-linux-gnu -o - < %s | FileCheck %s
2// RUN: llvm-mc -triple=arm64-linux-gnu -show-encoding -o - < %s | \
3// RUN:   FileCheck --check-prefix=CHECK-ENCODING %s
4// RUN: llvm-mc -triple=arm64-linux-gnu -filetype=obj < %s | \
5// RUN:   llvm-objdump --triple=arm64-linux-gnu - -r | \
6// RUN:   FileCheck %s --check-prefix=CHECK-OBJ-LP64
7
8   add x0, x2, #:lo12:sym
9   add x0, x2, #:lo12:sym+12
10   add x0, x2, #:lo12:sym-3
11// CHECK: add x0, x2, :lo12:sym
12// CHECK: add x0, x2, :lo12:sym+12
13// CHECK: add x0, x2, :lo12:sym-3
14// CHECK-OBJ-LP64:  0 R_AARCH64_ADD_ABS_LO12_NC sym
15// CHECK-OBJ-LP64:  4 R_AARCH64_ADD_ABS_LO12_NC sym+0xc
16// CHECK-OBJ-LP64:  8 R_AARCH64_ADD_ABS_LO12_NC sym-0x3
17
18   add x5, x7, #:dtprel_lo12:sym
19// CHECK: add x5, x7, :dtprel_lo12:sym
20// CHECK-OBJ-LP64: c R_AARCH64_TLSLD_ADD_DTPREL_LO12 sym
21
22   add x9, x12, #:dtprel_lo12_nc:sym
23// CHECK: add x9, x12, :dtprel_lo12_nc:sym
24// CHECK-OBJ-LP64: 10 R_AARCH64_TLSLD_ADD_DTPREL_LO12_NC sym
25
26   add x20, x30, #:tprel_lo12:sym
27// CHECK: add x20, x30, :tprel_lo12:sym
28// CHECK-OBJ-LP64: 14 R_AARCH64_TLSLE_ADD_TPREL_LO12 sym
29
30   add x9, x12, #:tprel_lo12_nc:sym
31// CHECK: add x9, x12, :tprel_lo12_nc:sym
32// CHECK-OBJ-LP64: 18 R_AARCH64_TLSLE_ADD_TPREL_LO12_NC sym
33
34   add x5, x0, #:tlsdesc_lo12:sym
35// CHECK: add x5, x0, :tlsdesc_lo12:sym
36// CHECK-OBJ-LP64: 1c R_AARCH64_TLSDESC_ADD_LO12 sym
37
38        add x0, x2, #:lo12:sym+8
39// CHECK: add x0, x2, :lo12:sym
40// CHECK-OBJ-LP64: 20 R_AARCH64_ADD_ABS_LO12_NC sym+0x8
41
42   add x5, x7, #:dtprel_lo12:sym+1
43// CHECK: add x5, x7, :dtprel_lo12:sym+1
44// CHECK-OBJ-LP64: 24 R_AARCH64_TLSLD_ADD_DTPREL_LO12 sym+0x1
45
46   add x9, x12, #:dtprel_lo12_nc:sym+2
47// CHECK: add x9, x12, :dtprel_lo12_nc:sym+2
48// CHECK-OBJ-LP64: 28 R_AARCH64_TLSLD_ADD_DTPREL_LO12_NC sym+0x2
49
50   add x20, x30, #:tprel_lo12:sym+12
51// CHECK: add x20, x30, :tprel_lo12:sym+12
52// CHECK-OBJ-LP64: 2c R_AARCH64_TLSLE_ADD_TPREL_LO12 sym+0xc
53
54   add x9, x12, #:tprel_lo12_nc:sym+54
55// CHECK: add x9, x12, :tprel_lo12_nc:sym+54
56// CHECK-OBJ-LP64: 30 R_AARCH64_TLSLE_ADD_TPREL_LO12_NC sym+0x36
57
58   add x5, x0, #:tlsdesc_lo12:sym+70
59// CHECK: add x5, x0, :tlsdesc_lo12:sym+70
60// CHECK-OBJ-LP64: 34 R_AARCH64_TLSDESC_ADD_LO12 sym+0x46
61
62        .hword sym + 4 - .
63// CHECK-OBJ-LP64: 38 R_AARCH64_PREL16 sym+0x4
64        .word sym - . + 8
65// CHECK-OBJ-LP64: 3a R_AARCH64_PREL32 sym+0x8
66        .xword sym-.
67// CHECK-OBJ-LP64: 3e R_AARCH64_PREL64 sym{{$}}
68
69        .hword sym
70// CHECK-OBJ-LP64: 46 R_AARCH64_ABS16 sym
71        .word sym+1
72// CHECK-OBJ-LP64: 48 R_AARCH64_ABS32 sym+0x1
73        .xword sym+16
74// CHECK-OBJ-LP64: 4c R_AARCH64_ABS64 sym+0x10
75
76   adrp x0, sym
77// CHECK: adrp x0, sym
78// CHECK-OBJ-LP64: 54 R_AARCH64_ADR_PREL_PG_HI21 sym
79
80   adrp x15, :got:sym
81// CHECK: adrp x15, :got:sym
82// CHECK-OBJ-LP64: 58 R_AARCH64_ADR_GOT_PAGE sym
83
84   adrp x29, :gottprel:sym
85// CHECK: adrp x29, :gottprel:sym
86// CHECK-OBJ-LP64: 5c R_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21 sym
87
88   adrp x2, :tlsdesc:sym
89// CHECK: adrp x2, :tlsdesc:sym
90// CHECK-OBJ-LP64: 60 R_AARCH64_TLSDESC_ADR_PAGE21 sym
91
92   // LLVM is not competent enough to do this relocation because the
93   // page boundary could occur anywhere after linking. A relocation
94   // is needed.
95   adrp x3, trickQuestion
96   .global trickQuestion
97trickQuestion:
98// CHECK: adrp x3, trickQuestion
99// CHECK-OBJ-LP64: 64 R_AARCH64_ADR_PREL_PG_HI21 trickQuestion
100
101   ldrb w2, [x3, :lo12:sym]
102   ldrsb w5, [x7, #:lo12:sym]
103   ldrsb x11, [x13, :lo12:sym]
104   ldr b17, [x19, #:lo12:sym]
105   ldrb w2, [x3, :lo12:sym+15]
106   ldrsb w5, [x7, #:lo12:sym-2]
107   ldr b17, [x19, #:lo12:sym+4]
108// CHECK: ldrb w2, [x3, :lo12:sym]
109// CHECK: ldrsb w5, [x7, :lo12:sym]
110// CHECK: ldrsb x11, [x13, :lo12:sym]
111// CHECK: ldr b17, [x19, :lo12:sym]
112// CHECK: ldrb w2, [x3, :lo12:sym+15]
113// CHECK: ldrsb w5, [x7, :lo12:sym-2]
114// CHECK: ldr b17, [x19, :lo12:sym+4]
115// CHECK-OBJ-LP64: R_AARCH64_LDST8_ABS_LO12_NC sym
116// CHECK-OBJ-LP64: R_AARCH64_LDST8_ABS_LO12_NC sym
117// CHECK-OBJ-LP64: R_AARCH64_LDST8_ABS_LO12_NC sym
118// CHECK-OBJ-LP64: R_AARCH64_LDST8_ABS_LO12_NC sym
119// CHECK-OBJ-LP64: R_AARCH64_LDST8_ABS_LO12_NC sym+0xf
120// CHECK-OBJ-LP64: R_AARCH64_LDST8_ABS_LO12_NC sym-0x2
121// CHECK-OBJ-LP64: R_AARCH64_LDST8_ABS_LO12_NC sym+0x4
122
123   ldrb w23, [x29, #:dtprel_lo12_nc:sym]
124   ldrsb w23, [x19, #:dtprel_lo12:sym]
125   ldrsb x17, [x13, :dtprel_lo12_nc:sym]
126   ldr b11, [x7, #:dtprel_lo12:sym]
127   ldrb w23, [x29, #:dtprel_lo12_nc:sym+2]
128// CHECK: ldrb w23, [x29, :dtprel_lo12_nc:sym]
129// CHECK: ldrsb w23, [x19, :dtprel_lo12:sym]
130// CHECK: ldrsb x17, [x13, :dtprel_lo12_nc:sym]
131// CHECK: ldr b11, [x7, :dtprel_lo12:sym]
132// CHECK: ldrb w23, [x29, :dtprel_lo12_nc:sym+2]
133// CHECK-OBJ-LP64: R_AARCH64_TLSLD_LDST8_DTPREL_LO12_NC sym
134// CHECK-OBJ-LP64: R_AARCH64_TLSLD_LDST8_DTPREL_LO12 sym
135// CHECK-OBJ-LP64: R_AARCH64_TLSLD_LDST8_DTPREL_LO12_NC sym
136// CHECK-OBJ-LP64: R_AARCH64_TLSLD_LDST8_DTPREL_LO12 sym
137// CHECK-OBJ-LP64: R_AARCH64_TLSLD_LDST8_DTPREL_LO12_NC sym+0x2
138
139   ldrb w1, [x2, :tprel_lo12:sym]
140   ldrsb w3, [x4, #:tprel_lo12_nc:sym]
141   ldrsb x5, [x6, :tprel_lo12:sym]
142   ldr b7, [x8, #:tprel_lo12_nc:sym]
143// CHECK: ldrb w1, [x2, :tprel_lo12:sym]
144// CHECK: ldrsb w3, [x4, :tprel_lo12_nc:sym]
145// CHECK: ldrsb x5, [x6, :tprel_lo12:sym]
146// CHECK: ldr b7, [x8, :tprel_lo12_nc:sym]
147// CHECK-OBJ-LP64: R_AARCH64_TLSLE_LDST8_TPREL_LO12 sym
148// CHECK-OBJ-LP64: R_AARCH64_TLSLE_LDST8_TPREL_LO12_NC sym
149// CHECK-OBJ-LP64: R_AARCH64_TLSLE_LDST8_TPREL_LO12 sym
150// CHECK-OBJ-LP64: R_AARCH64_TLSLE_LDST8_TPREL_LO12_NC sym
151
152   ldrh w2, [x3, #:lo12:sym]
153   ldrsh w5, [x7, :lo12:sym]
154   ldrsh x11, [x13, #:lo12:sym]
155   ldr h17, [x19, :lo12:sym]
156   ldrh w2, [x3, #:lo12:sym+4]
157// CHECK: ldrh w2, [x3, :lo12:sym]
158// CHECK: ldrsh w5, [x7, :lo12:sym]
159// CHECK: ldrsh x11, [x13, :lo12:sym]
160// CHECK: ldr h17, [x19, :lo12:sym]
161// CHECK: ldrh w2, [x3, :lo12:sym+4]
162// CHECK-OBJ-LP64: R_AARCH64_LDST16_ABS_LO12_NC sym
163// CHECK-OBJ-LP64: R_AARCH64_LDST16_ABS_LO12_NC sym
164// CHECK-OBJ-LP64: R_AARCH64_LDST16_ABS_LO12_NC sym
165// CHECK-OBJ-LP64: R_AARCH64_LDST16_ABS_LO12_NC sym
166// CHECK-OBJ-LP64: R_AARCH64_LDST16_ABS_LO12_NC sym+0x4
167
168   ldrh w23, [x29, #:dtprel_lo12_nc:sym]
169   ldrsh w23, [x19, :dtprel_lo12:sym]
170   ldrsh x17, [x13, :dtprel_lo12_nc:sym]
171   ldr h11, [x7, #:dtprel_lo12:sym]
172// CHECK: ldrh w23, [x29, :dtprel_lo12_nc:sym]
173// CHECK: ldrsh w23, [x19, :dtprel_lo12:sym]
174// CHECK: ldrsh x17, [x13, :dtprel_lo12_nc:sym]
175// CHECK: ldr h11, [x7, :dtprel_lo12:sym]
176// CHECK-OBJ-LP64: R_AARCH64_TLSLD_LDST16_DTPREL_LO12_NC sym
177// CHECK-OBJ-LP64: R_AARCH64_TLSLD_LDST16_DTPREL_LO12 sym
178// CHECK-OBJ-LP64: R_AARCH64_TLSLD_LDST16_DTPREL_LO12_NC sym
179// CHECK-OBJ-LP64: R_AARCH64_TLSLD_LDST16_DTPREL_LO12 sym
180
181   ldrh w1, [x2, :tprel_lo12:sym]
182   ldrsh w3, [x4, #:tprel_lo12_nc:sym]
183   ldrsh x5, [x6, :tprel_lo12:sym]
184   ldr h7, [x8, #:tprel_lo12_nc:sym]
185// CHECK: ldrh w1, [x2, :tprel_lo12:sym]
186// CHECK: ldrsh w3, [x4, :tprel_lo12_nc:sym]
187// CHECK: ldrsh x5, [x6, :tprel_lo12:sym]
188// CHECK: ldr h7, [x8, :tprel_lo12_nc:sym]
189// CHECK-OBJ-LP64: R_AARCH64_TLSLE_LDST16_TPREL_LO12 sym
190// CHECK-OBJ-LP64: R_AARCH64_TLSLE_LDST16_TPREL_LO12_NC sym
191// CHECK-OBJ-LP64: R_AARCH64_TLSLE_LDST16_TPREL_LO12 sym
192// CHECK-OBJ-LP64: R_AARCH64_TLSLE_LDST16_TPREL_LO12_NC sym
193
194   ldr w1, [x2, #:lo12:sym]
195   ldrsw x3, [x4, #:lo12:sym]
196   ldr s4, [x5, :lo12:sym]
197// CHECK: ldr w1, [x2, :lo12:sym]
198// CHECK: ldrsw x3, [x4, :lo12:sym]
199// CHECK: ldr s4, [x5, :lo12:sym]
200// CHECK-OBJ-LP64: R_AARCH64_LDST32_ABS_LO12_NC sym
201// CHECK-OBJ-LP64: R_AARCH64_LDST32_ABS_LO12_NC sym
202// CHECK-OBJ-LP64: R_AARCH64_LDST32_ABS_LO12_NC sym
203
204   ldr w1, [x2, :dtprel_lo12:sym]
205   ldrsw x3, [x4, #:dtprel_lo12_nc:sym]
206   ldr s4, [x5, #:dtprel_lo12_nc:sym]
207// CHECK: ldr w1, [x2, :dtprel_lo12:sym]
208// CHECK: ldrsw x3, [x4, :dtprel_lo12_nc:sym]
209// CHECK: ldr s4, [x5, :dtprel_lo12_nc:sym]
210// CHECK-OBJ-LP64: R_AARCH64_TLSLD_LDST32_DTPREL_LO12 sym
211// CHECK-OBJ-LP64: R_AARCH64_TLSLD_LDST32_DTPREL_LO12_NC sym
212// CHECK-OBJ-LP64: R_AARCH64_TLSLD_LDST32_DTPREL_LO12_NC sym
213
214
215   ldr w1, [x2, #:tprel_lo12:sym]
216   ldrsw x3, [x4, :tprel_lo12_nc:sym]
217   ldr s4, [x5, :tprel_lo12_nc:sym]
218// CHECK: ldr w1, [x2, :tprel_lo12:sym]
219// CHECK: ldrsw x3, [x4, :tprel_lo12_nc:sym]
220// CHECK: ldr s4, [x5, :tprel_lo12_nc:sym]
221// CHECK-OBJ-LP64: R_AARCH64_TLSLE_LDST32_TPREL_LO12 sym
222// CHECK-OBJ-LP64: R_AARCH64_TLSLE_LDST32_TPREL_LO12_NC sym
223// CHECK-OBJ-LP64: R_AARCH64_TLSLE_LDST32_TPREL_LO12_NC sym
224
225   ldr x28, [x27, :lo12:sym]
226   ldr d26, [x25, #:lo12:sym]
227   ldr x28, [x27, :lo12:sym+10]
228   ldr x28, [x27, :lo12:sym-15]
229// CHECK: ldr x28, [x27, :lo12:sym]
230// CHECK: ldr d26, [x25, :lo12:sym]
231// CHECK: ldr x28, [x27, :lo12:sym+10]
232// CHECK: ldr x28, [x27, :lo12:sym-15]
233// CHECK-OBJ-LP64: R_AARCH64_LDST64_ABS_LO12_NC sym
234// CHECK-OBJ-LP64: R_AARCH64_LDST64_ABS_LO12_NC sym
235// CHECK-OBJ-LP64: R_AARCH64_LDST64_ABS_LO12_NC sym+0xa
236// CHECK-OBJ-LP64: R_AARCH64_LDST64_ABS_LO12_NC sym-0xf
237
238   ldr x24, [x23, #:got_lo12:sym]
239   ldr d22, [x21, :got_lo12:sym]
240   ldr x24, [x23, :got_lo12:sym+7]
241// CHECK: ldr x24, [x23, :got_lo12:sym]
242// CHECK: ldr d22, [x21, :got_lo12:sym]
243// CHECK: ldr x24, [x23, :got_lo12:sym+7]
244// CHECK-OBJ-LP64: R_AARCH64_LD64_GOT_LO12_NC sym
245// CHECK-OBJ-LP64: R_AARCH64_LD64_GOT_LO12_NC sym
246// CHECK-OBJ-LP64: R_AARCH64_LD64_GOT_LO12_NC sym+0x7
247
248   ldr x24, [x23, :dtprel_lo12_nc:sym]
249   ldr d22, [x21, #:dtprel_lo12:sym]
250// CHECK: ldr x24, [x23, :dtprel_lo12_nc:sym]
251// CHECK: ldr d22, [x21, :dtprel_lo12:sym]
252// CHECK-OBJ-LP64: R_AARCH64_TLSLD_LDST64_DTPREL_LO12_NC sym
253// CHECK-OBJ-LP64: R_AARCH64_TLSLD_LDST64_DTPREL_LO12 sym
254
255   ldr q24, [x23, :dtprel_lo12_nc:sym]
256   ldr q22, [x21, #:dtprel_lo12:sym]
257// CHECK: ldr q24, [x23, :dtprel_lo12_nc:sym]
258// CHECK: ldr q22, [x21, :dtprel_lo12:sym]
259// CHECK-OBJ-LP64: R_AARCH64_TLSLD_LDST128_DTPREL_LO12_NC sym
260// CHECK-OBJ-LP64: R_AARCH64_TLSLD_LDST128_DTPREL_LO12 sym
261
262   ldr x24, [x23, #:tprel_lo12:sym]
263   ldr d22, [x21, :tprel_lo12_nc:sym]
264// CHECK: ldr x24, [x23, :tprel_lo12:sym]
265// CHECK: ldr d22, [x21, :tprel_lo12_nc:sym]
266// CHECK-OBJ-LP64: R_AARCH64_TLSLE_LDST64_TPREL_LO12 sym
267// CHECK-OBJ-LP64: R_AARCH64_TLSLE_LDST64_TPREL_LO12_NC sym
268
269   ldr q24, [x23, #:tprel_lo12:sym]
270   ldr q22, [x21, :tprel_lo12_nc:sym]
271// CHECK: ldr q24, [x23, :tprel_lo12:sym]
272// CHECK: ldr q22, [x21, :tprel_lo12_nc:sym]
273// CHECK-OBJ-LP64: R_AARCH64_TLSLE_LDST128_TPREL_LO12 sym
274// CHECK-OBJ-LP64: R_AARCH64_TLSLE_LDST128_TPREL_LO12_NC sym
275
276   ldr x24, [x23, :gottprel_lo12:sym]
277   ldr d22, [x21, #:gottprel_lo12:sym]
278// CHECK: ldr x24, [x23, :gottprel_lo12:sym]
279// CHECK: ldr d22, [x21, :gottprel_lo12:sym]
280// CHECK-OBJ-LP64: R_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC sym
281// CHECK-OBJ-LP64: R_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC sym
282
283   ldr x24, [x23, #:tlsdesc_lo12:sym]
284   ldr d22, [x21, :tlsdesc_lo12:sym]
285// CHECK: ldr x24, [x23, :tlsdesc_lo12:sym]
286// CHECK: ldr d22, [x21, :tlsdesc_lo12:sym]
287// CHECK-OBJ-LP64: R_AARCH64_TLSDESC_LD64_LO12 sym
288// CHECK-OBJ-LP64: R_AARCH64_TLSDESC_LD64_LO12 sym
289
290   ldr q20, [x19, #:lo12:sym]
291// CHECK: ldr q20, [x19, :lo12:sym]
292// CHECK-OBJ-LP64: R_AARCH64_LDST128_ABS_LO12_NC sym
293// check encoding here, since encoding test doesn't belong with TLS encoding
294// tests, as it isn't a TLS relocation.
295// CHECK-ENCODING: ldr q20, [x19, :lo12:sym] // encoding: [0x74,0bAAAAAA10,0b11AAAAAA,0x3d]
296// CHECK-ENCODING-NEXT:  0, value: :lo12:sym, kind: fixup_aarch64_ldst_imm12_scale16
297
298// Since relocated instructions print without a '#', that syntax should
299// certainly be accepted when assembling.
300   add x3, x5, :lo12:imm
301// CHECK: add x3, x5, :lo12:imm
302
303   ldr x24, #:got:sym
304   ldr d22, :got:sym
305// CHECK: ldr x24, :got:sym
306// CHECK: ldr d22, :got:sym
307// CHECK-OBJ-LP64: R_AARCH64_GOT_LD_PREL19 sym
308// CHECK-OBJ-LP64: R_AARCH64_GOT_LD_PREL19 sym