• 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 -filetype=obj < %s | llvm-objdump -triple=arm64-linux-gnu - -r | FileCheck %s --check-prefix=CHECK-OBJ
3
4   add x0, x2, #:lo12:sym
5// CHECK: add x0, x2, :lo12:sym
6// CHECK-OBJ: 0 R_AARCH64_ADD_ABS_LO12_NC sym
7
8   add x5, x7, #:dtprel_lo12:sym
9// CHECK: add x5, x7, :dtprel_lo12:sym
10// CHECK-OBJ: 4 R_AARCH64_TLSLD_ADD_DTPREL_LO12 sym
11
12   add x9, x12, #:dtprel_lo12_nc:sym
13// CHECK: add x9, x12, :dtprel_lo12_nc:sym
14// CHECK-OBJ: 8 R_AARCH64_TLSLD_ADD_DTPREL_LO12_NC sym
15
16   add x20, x30, #:tprel_lo12:sym
17// CHECK: add x20, x30, :tprel_lo12:sym
18// CHECK-OBJ: c R_AARCH64_TLSLE_ADD_TPREL_LO12 sym
19
20   add x9, x12, #:tprel_lo12_nc:sym
21// CHECK: add x9, x12, :tprel_lo12_nc:sym
22// CHECK-OBJ: 10 R_AARCH64_TLSLE_ADD_TPREL_LO12_NC sym
23
24   add x5, x0, #:tlsdesc_lo12:sym
25// CHECK: add x5, x0, :tlsdesc_lo12:sym
26// CHECK-OBJ: 14 R_AARCH64_TLSDESC_ADD_LO12_NC sym
27
28        add x0, x2, #:lo12:sym+8
29// CHECK: add x0, x2, :lo12:sym
30// CHECK-OBJ: 18 R_AARCH64_ADD_ABS_LO12_NC sym+8
31
32   add x5, x7, #:dtprel_lo12:sym+1
33// CHECK: add x5, x7, :dtprel_lo12:sym+1
34// CHECK-OBJ: 1c R_AARCH64_TLSLD_ADD_DTPREL_LO12 sym+1
35
36   add x9, x12, #:dtprel_lo12_nc:sym+2
37// CHECK: add x9, x12, :dtprel_lo12_nc:sym+2
38// CHECK-OBJ:20 R_AARCH64_TLSLD_ADD_DTPREL_LO12_NC sym+2
39
40   add x20, x30, #:tprel_lo12:sym+12
41// CHECK: add x20, x30, :tprel_lo12:sym+12
42// CHECK-OBJ: 24 R_AARCH64_TLSLE_ADD_TPREL_LO12 sym+12
43
44   add x9, x12, #:tprel_lo12_nc:sym+54
45// CHECK: add x9, x12, :tprel_lo12_nc:sym+54
46// CHECK-OBJ: 28 R_AARCH64_TLSLE_ADD_TPREL_LO12_NC sym+54
47
48   add x5, x0, #:tlsdesc_lo12:sym+70
49// CHECK: add x5, x0, :tlsdesc_lo12:sym+70
50// CHECK-OBJ: 2c R_AARCH64_TLSDESC_ADD_LO12_NC sym+70
51
52        .hword sym + 4 - .
53// CHECK-OBJ: 30 R_AARCH64_PREL16 sym+4
54        .word sym - . + 8
55// CHECK-OBJ: 32 R_AARCH64_PREL32 sym+8
56        .xword sym-.
57// CHECK-OBJ: 36 R_AARCH64_PREL64 sym{{$}}
58
59        .hword sym
60// CHECK-OBJ: 3e R_AARCH64_ABS16 sym
61        .word sym+1
62// CHECK-OBJ: 40 R_AARCH64_ABS32 sym+1
63        .xword sym+16
64// CHECK-OBJ: 44 R_AARCH64_ABS64 sym+16
65
66   adrp x0, sym
67// CHECK: adrp x0, sym
68// CHECK-OBJ: 4c R_AARCH64_ADR_PREL_PG_HI21 sym
69
70   adrp x15, :got:sym
71// CHECK: adrp x15, :got:sym
72// CHECK-OBJ: 50 R_AARCH64_ADR_GOT_PAGE sym
73
74   adrp x29, :gottprel:sym
75// CHECK: adrp x29, :gottprel:sym
76// CHECK-OBJ: 54 R_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21 sym
77
78   adrp x2, :tlsdesc:sym
79// CHECK: adrp x2, :tlsdesc:sym
80// CHECK-OBJ: 58 R_AARCH64_TLSDESC_ADR_PAGE21 sym
81
82   // LLVM is not competent enough to do this relocation because the
83   // page boundary could occur anywhere after linking. A relocation
84   // is needed.
85   adrp x3, trickQuestion
86   .global trickQuestion
87trickQuestion:
88// CHECK: adrp x3, trickQuestion
89// CHECK-OBJ: 5c R_AARCH64_ADR_PREL_PG_HI21 trickQuestion
90
91   ldrb w2, [x3, :lo12:sym]
92   ldrsb w5, [x7, #:lo12:sym]
93   ldrsb x11, [x13, :lo12:sym]
94   ldr b17, [x19, #:lo12:sym]
95// CHECK: ldrb w2, [x3, :lo12:sym]
96// CHECK: ldrsb w5, [x7, :lo12:sym]
97// CHECK: ldrsb x11, [x13, :lo12:sym]
98// CHECK: ldr b17, [x19, :lo12:sym]
99// CHECK-OBJ: R_AARCH64_LDST8_ABS_LO12_NC sym
100// CHECK-OBJ: R_AARCH64_LDST8_ABS_LO12_NC sym
101// CHECK-OBJ: R_AARCH64_LDST8_ABS_LO12_NC sym
102// CHECK-OBJ: R_AARCH64_LDST8_ABS_LO12_NC sym
103
104   ldrb w23, [x29, #:dtprel_lo12_nc:sym]
105   ldrsb w23, [x19, #:dtprel_lo12:sym]
106   ldrsb x17, [x13, :dtprel_lo12_nc:sym]
107   ldr b11, [x7, #:dtprel_lo12:sym]
108// CHECK: ldrb w23, [x29, :dtprel_lo12_nc:sym]
109// CHECK: ldrsb w23, [x19, :dtprel_lo12:sym]
110// CHECK: ldrsb x17, [x13, :dtprel_lo12_nc:sym]
111// CHECK: ldr b11, [x7, :dtprel_lo12:sym]
112// CHECK-OBJ: R_AARCH64_TLSLD_LDST8_DTPREL_LO12_NC sym
113// CHECK-OBJ: R_AARCH64_TLSLD_LDST8_DTPREL_LO12 sym
114// CHECK-OBJ: R_AARCH64_TLSLD_LDST8_DTPREL_LO12_NC sym
115// CHECK-OBJ: R_AARCH64_TLSLD_LDST8_DTPREL_LO12 sym
116
117   ldrb w1, [x2, :tprel_lo12:sym]
118   ldrsb w3, [x4, #:tprel_lo12_nc:sym]
119   ldrsb x5, [x6, :tprel_lo12:sym]
120   ldr b7, [x8, #:tprel_lo12_nc:sym]
121// CHECK: ldrb w1, [x2, :tprel_lo12:sym]
122// CHECK: ldrsb w3, [x4, :tprel_lo12_nc:sym]
123// CHECK: ldrsb x5, [x6, :tprel_lo12:sym]
124// CHECK: ldr b7, [x8, :tprel_lo12_nc:sym]
125// CHECK-OBJ: R_AARCH64_TLSLE_LDST8_TPREL_LO12 sym
126// CHECK-OBJ: R_AARCH64_TLSLE_LDST8_TPREL_LO12_NC sym
127// CHECK-OBJ: R_AARCH64_TLSLE_LDST8_TPREL_LO12 sym
128// CHECK-OBJ: R_AARCH64_TLSLE_LDST8_TPREL_LO12_NC sym
129
130   ldrh w2, [x3, #:lo12:sym]
131   ldrsh w5, [x7, :lo12:sym]
132   ldrsh x11, [x13, #:lo12:sym]
133   ldr h17, [x19, :lo12:sym]
134// CHECK: ldrh w2, [x3, :lo12:sym]
135// CHECK: ldrsh w5, [x7, :lo12:sym]
136// CHECK: ldrsh x11, [x13, :lo12:sym]
137// CHECK: ldr h17, [x19, :lo12:sym]
138// CHECK-OBJ: R_AARCH64_LDST16_ABS_LO12_NC sym
139// CHECK-OBJ: R_AARCH64_LDST16_ABS_LO12_NC sym
140// CHECK-OBJ: R_AARCH64_LDST16_ABS_LO12_NC sym
141// CHECK-OBJ: R_AARCH64_LDST16_ABS_LO12_NC sym
142
143   ldrh w23, [x29, #:dtprel_lo12_nc:sym]
144   ldrsh w23, [x19, :dtprel_lo12:sym]
145   ldrsh x17, [x13, :dtprel_lo12_nc:sym]
146   ldr h11, [x7, #:dtprel_lo12:sym]
147// CHECK: ldrh w23, [x29, :dtprel_lo12_nc:sym]
148// CHECK: ldrsh w23, [x19, :dtprel_lo12:sym]
149// CHECK: ldrsh x17, [x13, :dtprel_lo12_nc:sym]
150// CHECK: ldr h11, [x7, :dtprel_lo12:sym]
151// CHECK-OBJ: R_AARCH64_TLSLD_LDST16_DTPREL_LO12_NC sym
152// CHECK-OBJ: R_AARCH64_TLSLD_LDST16_DTPREL_LO12 sym
153// CHECK-OBJ: R_AARCH64_TLSLD_LDST16_DTPREL_LO12_NC sym
154// CHECK-OBJ: R_AARCH64_TLSLD_LDST16_DTPREL_LO12 sym
155
156   ldrh w1, [x2, :tprel_lo12:sym]
157   ldrsh w3, [x4, #:tprel_lo12_nc:sym]
158   ldrsh x5, [x6, :tprel_lo12:sym]
159   ldr h7, [x8, #:tprel_lo12_nc:sym]
160// CHECK: ldrh w1, [x2, :tprel_lo12:sym]
161// CHECK: ldrsh w3, [x4, :tprel_lo12_nc:sym]
162// CHECK: ldrsh x5, [x6, :tprel_lo12:sym]
163// CHECK: ldr h7, [x8, :tprel_lo12_nc:sym]
164// CHECK-OBJ: R_AARCH64_TLSLE_LDST16_TPREL_LO12 sym
165// CHECK-OBJ: R_AARCH64_TLSLE_LDST16_TPREL_LO12_NC sym
166// CHECK-OBJ: R_AARCH64_TLSLE_LDST16_TPREL_LO12 sym
167// CHECK-OBJ: R_AARCH64_TLSLE_LDST16_TPREL_LO12_NC sym
168
169   ldr w1, [x2, #:lo12:sym]
170   ldrsw x3, [x4, #:lo12:sym]
171   ldr s4, [x5, :lo12:sym]
172// CHECK: ldr w1, [x2, :lo12:sym]
173// CHECK: ldrsw x3, [x4, :lo12:sym]
174// CHECK: ldr s4, [x5, :lo12:sym]
175// CHECK-OBJ: R_AARCH64_LDST32_ABS_LO12_NC sym
176// CHECK-OBJ: R_AARCH64_LDST32_ABS_LO12_NC sym
177// CHECK-OBJ: R_AARCH64_LDST32_ABS_LO12_NC sym
178
179   ldr w1, [x2, :dtprel_lo12:sym]
180   ldrsw x3, [x4, #:dtprel_lo12_nc:sym]
181   ldr s4, [x5, #:dtprel_lo12_nc:sym]
182// CHECK: ldr w1, [x2, :dtprel_lo12:sym]
183// CHECK: ldrsw x3, [x4, :dtprel_lo12_nc:sym]
184// CHECK: ldr s4, [x5, :dtprel_lo12_nc:sym]
185// CHECK-OBJ: R_AARCH64_TLSLD_LDST32_DTPREL_LO12 sym
186// CHECK-OBJ: R_AARCH64_TLSLD_LDST32_DTPREL_LO12_NC sym
187// CHECK-OBJ: R_AARCH64_TLSLD_LDST32_DTPREL_LO12_NC sym
188
189
190   ldr w1, [x2, #:tprel_lo12:sym]
191   ldrsw x3, [x4, :tprel_lo12_nc:sym]
192   ldr s4, [x5, :tprel_lo12_nc:sym]
193// CHECK: ldr w1, [x2, :tprel_lo12:sym]
194// CHECK: ldrsw x3, [x4, :tprel_lo12_nc:sym]
195// CHECK: ldr s4, [x5, :tprel_lo12_nc:sym]
196// CHECK-OBJ: R_AARCH64_TLSLE_LDST32_TPREL_LO12 sym
197// CHECK-OBJ: R_AARCH64_TLSLE_LDST32_TPREL_LO12_NC sym
198// CHECK-OBJ: R_AARCH64_TLSLE_LDST32_TPREL_LO12_NC sym
199
200   ldr x28, [x27, :lo12:sym]
201   ldr d26, [x25, #:lo12:sym]
202// CHECK: ldr x28, [x27, :lo12:sym]
203// CHECK: ldr d26, [x25, :lo12:sym]
204// CHECK-OBJ: R_AARCH64_LDST64_ABS_LO12_NC sym
205// CHECK-OBJ: R_AARCH64_LDST64_ABS_LO12_NC sym
206
207   ldr x24, [x23, #:got_lo12:sym]
208   ldr d22, [x21, :got_lo12:sym]
209// CHECK: ldr x24, [x23, :got_lo12:sym]
210// CHECK: ldr d22, [x21, :got_lo12:sym]
211// CHECK-OBJ: R_AARCH64_LD64_GOT_LO12_NC sym
212// CHECK-OBJ: R_AARCH64_LD64_GOT_LO12_NC sym
213
214   ldr x24, [x23, :dtprel_lo12_nc:sym]
215   ldr d22, [x21, #:dtprel_lo12:sym]
216// CHECK: ldr x24, [x23, :dtprel_lo12_nc:sym]
217// CHECK: ldr d22, [x21, :dtprel_lo12:sym]
218// CHECK-OBJ: R_AARCH64_TLSLD_LDST64_DTPREL_LO12_NC sym
219// CHECK-OBJ: R_AARCH64_TLSLD_LDST64_DTPREL_LO12 sym
220
221   ldr x24, [x23, #:tprel_lo12:sym]
222   ldr d22, [x21, :tprel_lo12_nc:sym]
223// CHECK: ldr x24, [x23, :tprel_lo12:sym]
224// CHECK: ldr d22, [x21, :tprel_lo12_nc:sym]
225// CHECK-OBJ: R_AARCH64_TLSLE_LDST64_TPREL_LO12 sym
226// CHECK-OBJ: R_AARCH64_TLSLE_LDST64_TPREL_LO12_NC sym
227
228   ldr x24, [x23, :gottprel_lo12:sym]
229   ldr d22, [x21, #:gottprel_lo12:sym]
230// CHECK: ldr x24, [x23, :gottprel_lo12:sym]
231// CHECK: ldr d22, [x21, :gottprel_lo12:sym]
232// CHECK-OBJ: R_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC sym
233// CHECK-OBJ: R_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC sym
234
235   ldr x24, [x23, #:tlsdesc_lo12:sym]
236   ldr d22, [x21, :tlsdesc_lo12:sym]
237// CHECK: ldr x24, [x23, :tlsdesc_lo12:sym]
238// CHECK: ldr d22, [x21, :tlsdesc_lo12:sym]
239// CHECK-OBJ: R_AARCH64_TLSDESC_LD64_LO12_NC sym
240// CHECK-OBJ: R_AARCH64_TLSDESC_LD64_LO12_NC sym
241
242   ldr q20, [x19, #:lo12:sym]
243// CHECK: ldr q20, [x19, :lo12:sym]
244// CHECK-OBJ: R_AARCH64_LDST128_ABS_LO12_NC sym
245
246// Since relocated instructions print without a '#', that syntax should
247// certainly be accepted when assembling.
248   add x3, x5, :lo12:imm
249// CHECK: add x3, x5, :lo12:imm
250