1 /* AArch64-specific support for NN-bit ELF.
2 Copyright (C) 2009-2019 Free Software Foundation, Inc.
3 Contributed by ARM Ltd.
5 This file is part of BFD, the Binary File Descriptor library.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; see the file COPYING3. If not,
19 see <http://www.gnu.org/licenses/>. */
21 /* Notes on implementation:
23 Thread Local Store (TLS)
27 The implementation currently supports both traditional TLS and TLS
28 descriptors, but only general dynamic (GD).
30 For traditional TLS the assembler will present us with code
31 fragments of the form:
34 R_AARCH64_TLSGD_ADR_PAGE21(foo)
35 add x0, :tlsgd_lo12:foo
36 R_AARCH64_TLSGD_ADD_LO12_NC(foo)
40 For TLS descriptors the assembler will present us with code
41 fragments of the form:
43 adrp x0, :tlsdesc:foo R_AARCH64_TLSDESC_ADR_PAGE21(foo)
44 ldr x1, [x0, #:tlsdesc_lo12:foo] R_AARCH64_TLSDESC_LD64_LO12(foo)
45 add x0, x0, #:tlsdesc_lo12:foo R_AARCH64_TLSDESC_ADD_LO12(foo)
47 blr x1 R_AARCH64_TLSDESC_CALL(foo)
49 The relocations R_AARCH64_TLSGD_{ADR_PREL21,ADD_LO12_NC} against foo
50 indicate that foo is thread local and should be accessed via the
51 traditional TLS mechanims.
53 The relocations R_AARCH64_TLSDESC_{ADR_PAGE21,LD64_LO12_NC,ADD_LO12_NC}
54 against foo indicate that 'foo' is thread local and should be accessed
55 via a TLS descriptor mechanism.
57 The precise instruction sequence is only relevant from the
58 perspective of linker relaxation which is currently not implemented.
60 The static linker must detect that 'foo' is a TLS object and
61 allocate a double GOT entry. The GOT entry must be created for both
62 global and local TLS symbols. Note that this is different to none
63 TLS local objects which do not need a GOT entry.
65 In the traditional TLS mechanism, the double GOT entry is used to
66 provide the tls_index structure, containing module and offset
67 entries. The static linker places the relocation R_AARCH64_TLS_DTPMOD
68 on the module entry. The loader will subsequently fixup this
69 relocation with the module identity.
71 For global traditional TLS symbols the static linker places an
72 R_AARCH64_TLS_DTPREL relocation on the offset entry. The loader
73 will subsequently fixup the offset. For local TLS symbols the static
74 linker fixes up offset.
76 In the TLS descriptor mechanism the double GOT entry is used to
77 provide the descriptor. The static linker places the relocation
78 R_AARCH64_TLSDESC on the first GOT slot. The loader will
79 subsequently fix this up.
83 The handling of TLS symbols is implemented across a number of
84 different backend functions. The following is a top level view of
85 what processing is performed where.
87 The TLS implementation maintains state information for each TLS
88 symbol. The state information for local and global symbols is kept
89 in different places. Global symbols use generic BFD structures while
90 local symbols use backend specific structures that are allocated and
91 maintained entirely by the backend.
95 elfNN_aarch64_check_relocs()
97 This function is invoked for each relocation.
99 The TLS relocations R_AARCH64_TLSGD_{ADR_PREL21,ADD_LO12_NC} and
100 R_AARCH64_TLSDESC_{ADR_PAGE21,LD64_LO12_NC,ADD_LO12_NC} are
101 spotted. One time creation of local symbol data structures are
102 created when the first local symbol is seen.
104 The reference count for a symbol is incremented. The GOT type for
105 each symbol is marked as general dynamic.
107 elfNN_aarch64_allocate_dynrelocs ()
109 For each global with positive reference count we allocate a double
110 GOT slot. For a traditional TLS symbol we allocate space for two
111 relocation entries on the GOT, for a TLS descriptor symbol we
112 allocate space for one relocation on the slot. Record the GOT offset
115 elfNN_aarch64_size_dynamic_sections ()
117 Iterate all input BFDS, look for in the local symbol data structure
118 constructed earlier for local TLS symbols and allocate them double
119 GOT slots along with space for a single GOT relocation. Update the
120 local symbol structure to record the GOT offset allocated.
122 elfNN_aarch64_relocate_section ()
124 Calls elfNN_aarch64_final_link_relocate ()
126 Emit the relevant TLS relocations against the GOT for each TLS
127 symbol. For local TLS symbols emit the GOT offset directly. The GOT
128 relocations are emitted once the first time a TLS symbol is
129 encountered. The implementation uses the LSB of the GOT offset to
130 flag that the relevant GOT relocations for a symbol have been
131 emitted. All of the TLS code that uses the GOT offset needs to take
132 care to mask out this flag bit before using the offset.
134 elfNN_aarch64_final_link_relocate ()
136 Fixup the R_AARCH64_TLSGD_{ADR_PREL21, ADD_LO12_NC} relocations. */
140 #include "libiberty.h"
144 #include "objalloc.h"
145 #include "elf/aarch64.h"
146 #include "elfxx-aarch64.h"
151 #define AARCH64_R(NAME) R_AARCH64_ ## NAME
152 #define AARCH64_R_STR(NAME) "R_AARCH64_" #NAME
153 #define HOWTO64(...) HOWTO (__VA_ARGS__)
154 #define HOWTO32(...) EMPTY_HOWTO (0)
155 #define LOG_FILE_ALIGN 3
156 #define BFD_RELOC_AARCH64_TLSDESC_LD64_LO12_NC BFD_RELOC_AARCH64_TLSDESC_LD64_LO12
160 #define AARCH64_R(NAME) R_AARCH64_P32_ ## NAME
161 #define AARCH64_R_STR(NAME) "R_AARCH64_P32_" #NAME
162 #define HOWTO64(...) EMPTY_HOWTO (0)
163 #define HOWTO32(...) HOWTO (__VA_ARGS__)
164 #define LOG_FILE_ALIGN 2
165 #define BFD_RELOC_AARCH64_TLSDESC_LD32_LO12 BFD_RELOC_AARCH64_TLSDESC_LD32_LO12_NC
166 #define R_AARCH64_P32_TLSDESC_ADD_LO12 R_AARCH64_P32_TLSDESC_ADD_LO12_NC
169 #define IS_AARCH64_TLS_RELOC(R_TYPE) \
170 ((R_TYPE) == BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC \
171 || (R_TYPE) == BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21 \
172 || (R_TYPE) == BFD_RELOC_AARCH64_TLSGD_ADR_PREL21 \
173 || (R_TYPE) == BFD_RELOC_AARCH64_TLSGD_MOVW_G0_NC \
174 || (R_TYPE) == BFD_RELOC_AARCH64_TLSGD_MOVW_G1 \
175 || (R_TYPE) == BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21 \
176 || (R_TYPE) == BFD_RELOC_AARCH64_TLSIE_LD32_GOTTPREL_LO12_NC \
177 || (R_TYPE) == BFD_RELOC_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC \
178 || (R_TYPE) == BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19 \
179 || (R_TYPE) == BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G0_NC \
180 || (R_TYPE) == BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G1 \
181 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_ADD_DTPREL_HI12 \
182 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_ADD_DTPREL_LO12 \
183 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_ADD_DTPREL_LO12_NC \
184 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC \
185 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21 \
186 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_ADR_PREL21 \
187 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_LDST16_DTPREL_LO12 \
188 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_LDST16_DTPREL_LO12_NC \
189 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_LDST32_DTPREL_LO12 \
190 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_LDST32_DTPREL_LO12_NC \
191 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_LDST64_DTPREL_LO12 \
192 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_LDST64_DTPREL_LO12_NC \
193 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_LDST8_DTPREL_LO12 \
194 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_LDST8_DTPREL_LO12_NC \
195 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G0 \
196 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G0_NC \
197 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G1 \
198 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G1_NC \
199 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G2 \
200 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_HI12 \
201 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_LO12 \
202 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_LO12_NC \
203 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_LDST16_TPREL_LO12 \
204 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_LDST16_TPREL_LO12_NC \
205 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_LDST32_TPREL_LO12 \
206 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_LDST32_TPREL_LO12_NC \
207 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_LDST64_TPREL_LO12 \
208 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_LDST64_TPREL_LO12_NC \
209 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_LDST8_TPREL_LO12 \
210 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_LDST8_TPREL_LO12_NC \
211 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0 \
212 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC \
213 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1 \
214 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1_NC \
215 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G2 \
216 || (R_TYPE) == BFD_RELOC_AARCH64_TLS_DTPMOD \
217 || (R_TYPE) == BFD_RELOC_AARCH64_TLS_DTPREL \
218 || (R_TYPE) == BFD_RELOC_AARCH64_TLS_TPREL \
219 || IS_AARCH64_TLSDESC_RELOC ((R_TYPE)))
221 #define IS_AARCH64_TLS_RELAX_RELOC(R_TYPE) \
222 ((R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_ADD \
223 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_ADD_LO12 \
224 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21 \
225 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21 \
226 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_CALL \
227 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_LD_PREL19 \
228 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_LDNN_LO12_NC \
229 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_LDR \
230 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_OFF_G0_NC \
231 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_OFF_G1 \
232 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_LDR \
233 || (R_TYPE) == BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21 \
234 || (R_TYPE) == BFD_RELOC_AARCH64_TLSGD_ADR_PREL21 \
235 || (R_TYPE) == BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC \
236 || (R_TYPE) == BFD_RELOC_AARCH64_TLSGD_MOVW_G0_NC \
237 || (R_TYPE) == BFD_RELOC_AARCH64_TLSGD_MOVW_G1 \
238 || (R_TYPE) == BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21 \
239 || (R_TYPE) == BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19 \
240 || (R_TYPE) == BFD_RELOC_AARCH64_TLSIE_LDNN_GOTTPREL_LO12_NC \
241 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC \
242 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21 \
243 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_ADR_PREL21)
245 #define IS_AARCH64_TLSDESC_RELOC(R_TYPE) \
246 ((R_TYPE) == BFD_RELOC_AARCH64_TLSDESC \
247 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_ADD \
248 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_ADD_LO12 \
249 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21 \
250 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21 \
251 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_CALL \
252 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_LD32_LO12_NC \
253 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_LD64_LO12 \
254 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_LDR \
255 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_LD_PREL19 \
256 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_OFF_G0_NC \
257 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_OFF_G1)
259 #define ELIMINATE_COPY_RELOCS 1
261 /* Return size of a relocation entry. HTAB is the bfd's
262 elf_aarch64_link_hash_entry. */
263 #define RELOC_SIZE(HTAB) (sizeof (ElfNN_External_Rela))
265 /* GOT Entry size - 8 bytes in ELF64 and 4 bytes in ELF32. */
266 #define GOT_ENTRY_SIZE (ARCH_SIZE / 8)
267 #define PLT_ENTRY_SIZE (32)
268 #define PLT_SMALL_ENTRY_SIZE (16)
269 #define PLT_TLSDESC_ENTRY_SIZE (32)
270 /* PLT sizes with BTI insn. */
271 #define PLT_BTI_ENTRY_SIZE (36)
272 #define PLT_BTI_SMALL_ENTRY_SIZE (20)
273 #define PLT_BTI_TLSDESC_ENTRY_SIZE (36)
275 /* Encoding of the nop instruction. */
276 #define INSN_NOP 0xd503201f
278 #define aarch64_compute_jump_table_size(htab) \
279 (((htab)->root.srelplt == NULL) ? 0 \
280 : (htab)->root.srelplt->reloc_count * GOT_ENTRY_SIZE)
282 /* The first entry in a procedure linkage table looks like this
283 if the distance between the PLTGOT and the PLT is < 4GB use
284 these PLT entries. Note that the dynamic linker gets &PLTGOT[2]
285 in x16 and needs to work out PLTGOT[1] by using an address of
286 [x16,#-GOT_ENTRY_SIZE]. */
287 static const bfd_byte elfNN_aarch64_small_plt0_entry[PLT_ENTRY_SIZE] =
289 0xf0, 0x7b, 0xbf, 0xa9, /* stp x16, x30, [sp, #-16]! */
290 0x10, 0x00, 0x00, 0x90, /* adrp x16, (GOT+16) */
292 0x11, 0x0A, 0x40, 0xf9, /* ldr x17, [x16, #PLT_GOT+0x10] */
293 0x10, 0x42, 0x00, 0x91, /* add x16, x16,#PLT_GOT+0x10 */
295 0x11, 0x0A, 0x40, 0xb9, /* ldr w17, [x16, #PLT_GOT+0x8] */
296 0x10, 0x22, 0x00, 0x11, /* add w16, w16,#PLT_GOT+0x8 */
298 0x20, 0x02, 0x1f, 0xd6, /* br x17 */
299 0x1f, 0x20, 0x03, 0xd5, /* nop */
300 0x1f, 0x20, 0x03, 0xd5, /* nop */
301 0x1f, 0x20, 0x03, 0xd5, /* nop */
304 static const bfd_byte elfNN_aarch64_small_plt0_bti_entry[PLT_BTI_ENTRY_SIZE] =
306 0x5f, 0x24, 0x03, 0xd5, /* bti c. */
307 0xf0, 0x7b, 0xbf, 0xa9, /* stp x16, x30, [sp, #-16]! */
308 0x10, 0x00, 0x00, 0x90, /* adrp x16, (GOT+16) */
310 0x11, 0x0A, 0x40, 0xf9, /* ldr x17, [x16, #PLT_GOT+0x10] */
311 0x10, 0x42, 0x00, 0x91, /* add x16, x16,#PLT_GOT+0x10 */
313 0x11, 0x0A, 0x40, 0xb9, /* ldr w17, [x16, #PLT_GOT+0x8] */
314 0x10, 0x22, 0x00, 0x11, /* add w16, w16,#PLT_GOT+0x8 */
316 0x20, 0x02, 0x1f, 0xd6, /* br x17 */
317 0x1f, 0x20, 0x03, 0xd5, /* nop */
318 0x1f, 0x20, 0x03, 0xd5, /* nop */
319 0x1f, 0x20, 0x03, 0xd5, /* nop */
322 /* Per function entry in a procedure linkage table looks like this
323 if the distance between the PLTGOT and the PLT is < 4GB use
324 these PLT entries. Use BTI versions of the PLTs when enabled. */
325 static const bfd_byte elfNN_aarch64_small_plt_entry[PLT_SMALL_ENTRY_SIZE] =
327 0x10, 0x00, 0x00, 0x90, /* adrp x16, PLTGOT + n * 8 */
329 0x11, 0x02, 0x40, 0xf9, /* ldr x17, [x16, PLTGOT + n * 8] */
330 0x10, 0x02, 0x00, 0x91, /* add x16, x16, :lo12:PLTGOT + n * 8 */
332 0x11, 0x02, 0x40, 0xb9, /* ldr w17, [x16, PLTGOT + n * 4] */
333 0x10, 0x02, 0x00, 0x11, /* add w16, w16, :lo12:PLTGOT + n * 4 */
335 0x20, 0x02, 0x1f, 0xd6, /* br x17. */
338 static const bfd_byte
339 elfNN_aarch64_small_plt_bti_entry[PLT_BTI_SMALL_ENTRY_SIZE] =
341 0x5f, 0x24, 0x03, 0xd5, /* bti c. */
342 0x10, 0x00, 0x00, 0x90, /* adrp x16, PLTGOT + n * 8 */
344 0x11, 0x02, 0x40, 0xf9, /* ldr x17, [x16, PLTGOT + n * 8] */
345 0x10, 0x02, 0x00, 0x91, /* add x16, x16, :lo12:PLTGOT + n * 8 */
347 0x11, 0x02, 0x40, 0xb9, /* ldr w17, [x16, PLTGOT + n * 4] */
348 0x10, 0x02, 0x00, 0x11, /* add w16, w16, :lo12:PLTGOT + n * 4 */
350 0x20, 0x02, 0x1f, 0xd6, /* br x17. */
353 static const bfd_byte
354 elfNN_aarch64_tlsdesc_small_plt_entry[PLT_TLSDESC_ENTRY_SIZE] =
356 0xe2, 0x0f, 0xbf, 0xa9, /* stp x2, x3, [sp, #-16]! */
357 0x02, 0x00, 0x00, 0x90, /* adrp x2, 0 */
358 0x03, 0x00, 0x00, 0x90, /* adrp x3, 0 */
360 0x42, 0x00, 0x40, 0xf9, /* ldr x2, [x2, #0] */
361 0x63, 0x00, 0x00, 0x91, /* add x3, x3, 0 */
363 0x42, 0x00, 0x40, 0xb9, /* ldr w2, [x2, #0] */
364 0x63, 0x00, 0x00, 0x11, /* add w3, w3, 0 */
366 0x40, 0x00, 0x1f, 0xd6, /* br x2 */
367 0x1f, 0x20, 0x03, 0xd5, /* nop */
368 0x1f, 0x20, 0x03, 0xd5, /* nop */
371 static const bfd_byte
372 elfNN_aarch64_tlsdesc_small_plt_bti_entry[PLT_BTI_TLSDESC_ENTRY_SIZE] =
374 0x5f, 0x24, 0x03, 0xd5, /* bti c. */
375 0xe2, 0x0f, 0xbf, 0xa9, /* stp x2, x3, [sp, #-16]! */
376 0x02, 0x00, 0x00, 0x90, /* adrp x2, 0 */
377 0x03, 0x00, 0x00, 0x90, /* adrp x3, 0 */
379 0x42, 0x00, 0x40, 0xf9, /* ldr x2, [x2, #0] */
380 0x63, 0x00, 0x00, 0x91, /* add x3, x3, 0 */
382 0x42, 0x00, 0x40, 0xb9, /* ldr w2, [x2, #0] */
383 0x63, 0x00, 0x00, 0x11, /* add w3, w3, 0 */
385 0x40, 0x00, 0x1f, 0xd6, /* br x2 */
386 0x1f, 0x20, 0x03, 0xd5, /* nop */
387 0x1f, 0x20, 0x03, 0xd5, /* nop */
390 #define elf_info_to_howto elfNN_aarch64_info_to_howto
391 #define elf_info_to_howto_rel elfNN_aarch64_info_to_howto
393 #define AARCH64_ELF_ABI_VERSION 0
395 /* In case we're on a 32-bit machine, construct a 64-bit "-1" value. */
396 #define ALL_ONES (~ (bfd_vma) 0)
398 /* Indexed by the bfd interal reloc enumerators.
399 Therefore, the table needs to be synced with BFD_RELOC_AARCH64_*
402 static reloc_howto_type elfNN_aarch64_howto_table[] =
406 /* Basic data relocations. */
408 /* Deprecated, but retained for backwards compatibility. */
409 HOWTO64 (R_AARCH64_NULL, /* type */
411 3, /* size (0 = byte, 1 = short, 2 = long) */
413 FALSE, /* pc_relative */
415 complain_overflow_dont, /* complain_on_overflow */
416 bfd_elf_generic_reloc, /* special_function */
417 "R_AARCH64_NULL", /* name */
418 FALSE, /* partial_inplace */
421 FALSE), /* pcrel_offset */
422 HOWTO (R_AARCH64_NONE, /* type */
424 3, /* size (0 = byte, 1 = short, 2 = long) */
426 FALSE, /* pc_relative */
428 complain_overflow_dont, /* complain_on_overflow */
429 bfd_elf_generic_reloc, /* special_function */
430 "R_AARCH64_NONE", /* name */
431 FALSE, /* partial_inplace */
434 FALSE), /* pcrel_offset */
437 HOWTO64 (AARCH64_R (ABS64), /* type */
439 4, /* size (4 = long long) */
441 FALSE, /* pc_relative */
443 complain_overflow_unsigned, /* complain_on_overflow */
444 bfd_elf_generic_reloc, /* special_function */
445 AARCH64_R_STR (ABS64), /* name */
446 FALSE, /* partial_inplace */
447 ALL_ONES, /* src_mask */
448 ALL_ONES, /* dst_mask */
449 FALSE), /* pcrel_offset */
452 HOWTO (AARCH64_R (ABS32), /* type */
454 2, /* size (0 = byte, 1 = short, 2 = long) */
456 FALSE, /* pc_relative */
458 complain_overflow_unsigned, /* complain_on_overflow */
459 bfd_elf_generic_reloc, /* special_function */
460 AARCH64_R_STR (ABS32), /* name */
461 FALSE, /* partial_inplace */
462 0xffffffff, /* src_mask */
463 0xffffffff, /* dst_mask */
464 FALSE), /* pcrel_offset */
467 HOWTO (AARCH64_R (ABS16), /* type */
469 1, /* size (0 = byte, 1 = short, 2 = long) */
471 FALSE, /* pc_relative */
473 complain_overflow_unsigned, /* complain_on_overflow */
474 bfd_elf_generic_reloc, /* special_function */
475 AARCH64_R_STR (ABS16), /* name */
476 FALSE, /* partial_inplace */
477 0xffff, /* src_mask */
478 0xffff, /* dst_mask */
479 FALSE), /* pcrel_offset */
481 /* .xword: (S+A-P) */
482 HOWTO64 (AARCH64_R (PREL64), /* type */
484 4, /* size (4 = long long) */
486 TRUE, /* pc_relative */
488 complain_overflow_signed, /* complain_on_overflow */
489 bfd_elf_generic_reloc, /* special_function */
490 AARCH64_R_STR (PREL64), /* name */
491 FALSE, /* partial_inplace */
492 ALL_ONES, /* src_mask */
493 ALL_ONES, /* dst_mask */
494 TRUE), /* pcrel_offset */
497 HOWTO (AARCH64_R (PREL32), /* type */
499 2, /* size (0 = byte, 1 = short, 2 = long) */
501 TRUE, /* pc_relative */
503 complain_overflow_signed, /* complain_on_overflow */
504 bfd_elf_generic_reloc, /* special_function */
505 AARCH64_R_STR (PREL32), /* name */
506 FALSE, /* partial_inplace */
507 0xffffffff, /* src_mask */
508 0xffffffff, /* dst_mask */
509 TRUE), /* pcrel_offset */
512 HOWTO (AARCH64_R (PREL16), /* type */
514 1, /* size (0 = byte, 1 = short, 2 = long) */
516 TRUE, /* pc_relative */
518 complain_overflow_signed, /* complain_on_overflow */
519 bfd_elf_generic_reloc, /* special_function */
520 AARCH64_R_STR (PREL16), /* name */
521 FALSE, /* partial_inplace */
522 0xffff, /* src_mask */
523 0xffff, /* dst_mask */
524 TRUE), /* pcrel_offset */
526 /* Group relocations to create a 16, 32, 48 or 64 bit
527 unsigned data or abs address inline. */
529 /* MOVZ: ((S+A) >> 0) & 0xffff */
530 HOWTO (AARCH64_R (MOVW_UABS_G0), /* type */
532 2, /* size (0 = byte, 1 = short, 2 = long) */
534 FALSE, /* pc_relative */
536 complain_overflow_unsigned, /* complain_on_overflow */
537 bfd_elf_generic_reloc, /* special_function */
538 AARCH64_R_STR (MOVW_UABS_G0), /* name */
539 FALSE, /* partial_inplace */
540 0xffff, /* src_mask */
541 0xffff, /* dst_mask */
542 FALSE), /* pcrel_offset */
544 /* MOVK: ((S+A) >> 0) & 0xffff [no overflow check] */
545 HOWTO (AARCH64_R (MOVW_UABS_G0_NC), /* type */
547 2, /* size (0 = byte, 1 = short, 2 = long) */
549 FALSE, /* pc_relative */
551 complain_overflow_dont, /* complain_on_overflow */
552 bfd_elf_generic_reloc, /* special_function */
553 AARCH64_R_STR (MOVW_UABS_G0_NC), /* name */
554 FALSE, /* partial_inplace */
555 0xffff, /* src_mask */
556 0xffff, /* dst_mask */
557 FALSE), /* pcrel_offset */
559 /* MOVZ: ((S+A) >> 16) & 0xffff */
560 HOWTO (AARCH64_R (MOVW_UABS_G1), /* type */
562 2, /* size (0 = byte, 1 = short, 2 = long) */
564 FALSE, /* pc_relative */
566 complain_overflow_unsigned, /* complain_on_overflow */
567 bfd_elf_generic_reloc, /* special_function */
568 AARCH64_R_STR (MOVW_UABS_G1), /* name */
569 FALSE, /* partial_inplace */
570 0xffff, /* src_mask */
571 0xffff, /* dst_mask */
572 FALSE), /* pcrel_offset */
574 /* MOVK: ((S+A) >> 16) & 0xffff [no overflow check] */
575 HOWTO64 (AARCH64_R (MOVW_UABS_G1_NC), /* type */
577 2, /* size (0 = byte, 1 = short, 2 = long) */
579 FALSE, /* pc_relative */
581 complain_overflow_dont, /* complain_on_overflow */
582 bfd_elf_generic_reloc, /* special_function */
583 AARCH64_R_STR (MOVW_UABS_G1_NC), /* name */
584 FALSE, /* partial_inplace */
585 0xffff, /* src_mask */
586 0xffff, /* dst_mask */
587 FALSE), /* pcrel_offset */
589 /* MOVZ: ((S+A) >> 32) & 0xffff */
590 HOWTO64 (AARCH64_R (MOVW_UABS_G2), /* type */
592 2, /* size (0 = byte, 1 = short, 2 = long) */
594 FALSE, /* pc_relative */
596 complain_overflow_unsigned, /* complain_on_overflow */
597 bfd_elf_generic_reloc, /* special_function */
598 AARCH64_R_STR (MOVW_UABS_G2), /* name */
599 FALSE, /* partial_inplace */
600 0xffff, /* src_mask */
601 0xffff, /* dst_mask */
602 FALSE), /* pcrel_offset */
604 /* MOVK: ((S+A) >> 32) & 0xffff [no overflow check] */
605 HOWTO64 (AARCH64_R (MOVW_UABS_G2_NC), /* type */
607 2, /* size (0 = byte, 1 = short, 2 = long) */
609 FALSE, /* pc_relative */
611 complain_overflow_dont, /* complain_on_overflow */
612 bfd_elf_generic_reloc, /* special_function */
613 AARCH64_R_STR (MOVW_UABS_G2_NC), /* name */
614 FALSE, /* partial_inplace */
615 0xffff, /* src_mask */
616 0xffff, /* dst_mask */
617 FALSE), /* pcrel_offset */
619 /* MOVZ: ((S+A) >> 48) & 0xffff */
620 HOWTO64 (AARCH64_R (MOVW_UABS_G3), /* type */
622 2, /* size (0 = byte, 1 = short, 2 = long) */
624 FALSE, /* pc_relative */
626 complain_overflow_unsigned, /* complain_on_overflow */
627 bfd_elf_generic_reloc, /* special_function */
628 AARCH64_R_STR (MOVW_UABS_G3), /* name */
629 FALSE, /* partial_inplace */
630 0xffff, /* src_mask */
631 0xffff, /* dst_mask */
632 FALSE), /* pcrel_offset */
634 /* Group relocations to create high part of a 16, 32, 48 or 64 bit
635 signed data or abs address inline. Will change instruction
636 to MOVN or MOVZ depending on sign of calculated value. */
638 /* MOV[ZN]: ((S+A) >> 0) & 0xffff */
639 HOWTO (AARCH64_R (MOVW_SABS_G0), /* type */
641 2, /* size (0 = byte, 1 = short, 2 = long) */
643 FALSE, /* pc_relative */
645 complain_overflow_signed, /* complain_on_overflow */
646 bfd_elf_generic_reloc, /* special_function */
647 AARCH64_R_STR (MOVW_SABS_G0), /* name */
648 FALSE, /* partial_inplace */
649 0xffff, /* src_mask */
650 0xffff, /* dst_mask */
651 FALSE), /* pcrel_offset */
653 /* MOV[ZN]: ((S+A) >> 16) & 0xffff */
654 HOWTO64 (AARCH64_R (MOVW_SABS_G1), /* type */
656 2, /* size (0 = byte, 1 = short, 2 = long) */
658 FALSE, /* pc_relative */
660 complain_overflow_signed, /* complain_on_overflow */
661 bfd_elf_generic_reloc, /* special_function */
662 AARCH64_R_STR (MOVW_SABS_G1), /* name */
663 FALSE, /* partial_inplace */
664 0xffff, /* src_mask */
665 0xffff, /* dst_mask */
666 FALSE), /* pcrel_offset */
668 /* MOV[ZN]: ((S+A) >> 32) & 0xffff */
669 HOWTO64 (AARCH64_R (MOVW_SABS_G2), /* type */
671 2, /* size (0 = byte, 1 = short, 2 = long) */
673 FALSE, /* pc_relative */
675 complain_overflow_signed, /* complain_on_overflow */
676 bfd_elf_generic_reloc, /* special_function */
677 AARCH64_R_STR (MOVW_SABS_G2), /* name */
678 FALSE, /* partial_inplace */
679 0xffff, /* src_mask */
680 0xffff, /* dst_mask */
681 FALSE), /* pcrel_offset */
683 /* Group relocations to create a 16, 32, 48 or 64 bit
684 PC relative address inline. */
686 /* MOV[NZ]: ((S+A-P) >> 0) & 0xffff */
687 HOWTO64 (AARCH64_R (MOVW_PREL_G0), /* type */
689 2, /* size (0 = byte, 1 = short, 2 = long) */
691 TRUE, /* pc_relative */
693 complain_overflow_signed, /* complain_on_overflow */
694 bfd_elf_generic_reloc, /* special_function */
695 AARCH64_R_STR (MOVW_PREL_G0), /* name */
696 FALSE, /* partial_inplace */
697 0xffff, /* src_mask */
698 0xffff, /* dst_mask */
699 TRUE), /* pcrel_offset */
701 /* MOVK: ((S+A-P) >> 0) & 0xffff [no overflow check] */
702 HOWTO64 (AARCH64_R (MOVW_PREL_G0_NC), /* type */
704 2, /* size (0 = byte, 1 = short, 2 = long) */
706 TRUE, /* pc_relative */
708 complain_overflow_dont, /* complain_on_overflow */
709 bfd_elf_generic_reloc, /* special_function */
710 AARCH64_R_STR (MOVW_PREL_G0_NC), /* name */
711 FALSE, /* partial_inplace */
712 0xffff, /* src_mask */
713 0xffff, /* dst_mask */
714 TRUE), /* pcrel_offset */
716 /* MOV[NZ]: ((S+A-P) >> 16) & 0xffff */
717 HOWTO64 (AARCH64_R (MOVW_PREL_G1), /* type */
719 2, /* size (0 = byte, 1 = short, 2 = long) */
721 TRUE, /* pc_relative */
723 complain_overflow_signed, /* complain_on_overflow */
724 bfd_elf_generic_reloc, /* special_function */
725 AARCH64_R_STR (MOVW_PREL_G1), /* name */
726 FALSE, /* partial_inplace */
727 0xffff, /* src_mask */
728 0xffff, /* dst_mask */
729 TRUE), /* pcrel_offset */
731 /* MOVK: ((S+A-P) >> 16) & 0xffff [no overflow check] */
732 HOWTO64 (AARCH64_R (MOVW_PREL_G1_NC), /* type */
734 2, /* size (0 = byte, 1 = short, 2 = long) */
736 TRUE, /* pc_relative */
738 complain_overflow_dont, /* complain_on_overflow */
739 bfd_elf_generic_reloc, /* special_function */
740 AARCH64_R_STR (MOVW_PREL_G1_NC), /* name */
741 FALSE, /* partial_inplace */
742 0xffff, /* src_mask */
743 0xffff, /* dst_mask */
744 TRUE), /* pcrel_offset */
746 /* MOV[NZ]: ((S+A-P) >> 32) & 0xffff */
747 HOWTO64 (AARCH64_R (MOVW_PREL_G2), /* type */
749 2, /* size (0 = byte, 1 = short, 2 = long) */
751 TRUE, /* pc_relative */
753 complain_overflow_signed, /* complain_on_overflow */
754 bfd_elf_generic_reloc, /* special_function */
755 AARCH64_R_STR (MOVW_PREL_G2), /* name */
756 FALSE, /* partial_inplace */
757 0xffff, /* src_mask */
758 0xffff, /* dst_mask */
759 TRUE), /* pcrel_offset */
761 /* MOVK: ((S+A-P) >> 32) & 0xffff [no overflow check] */
762 HOWTO64 (AARCH64_R (MOVW_PREL_G2_NC), /* type */
764 2, /* size (0 = byte, 1 = short, 2 = long) */
766 TRUE, /* pc_relative */
768 complain_overflow_dont, /* complain_on_overflow */
769 bfd_elf_generic_reloc, /* special_function */
770 AARCH64_R_STR (MOVW_PREL_G2_NC), /* name */
771 FALSE, /* partial_inplace */
772 0xffff, /* src_mask */
773 0xffff, /* dst_mask */
774 TRUE), /* pcrel_offset */
776 /* MOV[NZ]: ((S+A-P) >> 48) & 0xffff */
777 HOWTO64 (AARCH64_R (MOVW_PREL_G3), /* type */
779 2, /* size (0 = byte, 1 = short, 2 = long) */
781 TRUE, /* pc_relative */
783 complain_overflow_dont, /* complain_on_overflow */
784 bfd_elf_generic_reloc, /* special_function */
785 AARCH64_R_STR (MOVW_PREL_G3), /* name */
786 FALSE, /* partial_inplace */
787 0xffff, /* src_mask */
788 0xffff, /* dst_mask */
789 TRUE), /* pcrel_offset */
791 /* Relocations to generate 19, 21 and 33 bit PC-relative load/store
792 addresses: PG(x) is (x & ~0xfff). */
794 /* LD-lit: ((S+A-P) >> 2) & 0x7ffff */
795 HOWTO (AARCH64_R (LD_PREL_LO19), /* type */
797 2, /* size (0 = byte, 1 = short, 2 = long) */
799 TRUE, /* pc_relative */
801 complain_overflow_signed, /* complain_on_overflow */
802 bfd_elf_generic_reloc, /* special_function */
803 AARCH64_R_STR (LD_PREL_LO19), /* name */
804 FALSE, /* partial_inplace */
805 0x7ffff, /* src_mask */
806 0x7ffff, /* dst_mask */
807 TRUE), /* pcrel_offset */
809 /* ADR: (S+A-P) & 0x1fffff */
810 HOWTO (AARCH64_R (ADR_PREL_LO21), /* type */
812 2, /* size (0 = byte, 1 = short, 2 = long) */
814 TRUE, /* pc_relative */
816 complain_overflow_signed, /* complain_on_overflow */
817 bfd_elf_generic_reloc, /* special_function */
818 AARCH64_R_STR (ADR_PREL_LO21), /* name */
819 FALSE, /* partial_inplace */
820 0x1fffff, /* src_mask */
821 0x1fffff, /* dst_mask */
822 TRUE), /* pcrel_offset */
824 /* ADRP: ((PG(S+A)-PG(P)) >> 12) & 0x1fffff */
825 HOWTO (AARCH64_R (ADR_PREL_PG_HI21), /* type */
827 2, /* size (0 = byte, 1 = short, 2 = long) */
829 TRUE, /* pc_relative */
831 complain_overflow_signed, /* complain_on_overflow */
832 bfd_elf_generic_reloc, /* special_function */
833 AARCH64_R_STR (ADR_PREL_PG_HI21), /* name */
834 FALSE, /* partial_inplace */
835 0x1fffff, /* src_mask */
836 0x1fffff, /* dst_mask */
837 TRUE), /* pcrel_offset */
839 /* ADRP: ((PG(S+A)-PG(P)) >> 12) & 0x1fffff [no overflow check] */
840 HOWTO64 (AARCH64_R (ADR_PREL_PG_HI21_NC), /* type */
842 2, /* size (0 = byte, 1 = short, 2 = long) */
844 TRUE, /* pc_relative */
846 complain_overflow_dont, /* complain_on_overflow */
847 bfd_elf_generic_reloc, /* special_function */
848 AARCH64_R_STR (ADR_PREL_PG_HI21_NC), /* name */
849 FALSE, /* partial_inplace */
850 0x1fffff, /* src_mask */
851 0x1fffff, /* dst_mask */
852 TRUE), /* pcrel_offset */
854 /* ADD: (S+A) & 0xfff [no overflow check] */
855 HOWTO (AARCH64_R (ADD_ABS_LO12_NC), /* type */
857 2, /* size (0 = byte, 1 = short, 2 = long) */
859 FALSE, /* pc_relative */
861 complain_overflow_dont, /* complain_on_overflow */
862 bfd_elf_generic_reloc, /* special_function */
863 AARCH64_R_STR (ADD_ABS_LO12_NC), /* name */
864 FALSE, /* partial_inplace */
865 0x3ffc00, /* src_mask */
866 0x3ffc00, /* dst_mask */
867 FALSE), /* pcrel_offset */
869 /* LD/ST8: (S+A) & 0xfff */
870 HOWTO (AARCH64_R (LDST8_ABS_LO12_NC), /* type */
872 2, /* size (0 = byte, 1 = short, 2 = long) */
874 FALSE, /* pc_relative */
876 complain_overflow_dont, /* complain_on_overflow */
877 bfd_elf_generic_reloc, /* special_function */
878 AARCH64_R_STR (LDST8_ABS_LO12_NC), /* name */
879 FALSE, /* partial_inplace */
880 0xfff, /* src_mask */
881 0xfff, /* dst_mask */
882 FALSE), /* pcrel_offset */
884 /* Relocations for control-flow instructions. */
886 /* TBZ/NZ: ((S+A-P) >> 2) & 0x3fff */
887 HOWTO (AARCH64_R (TSTBR14), /* type */
889 2, /* size (0 = byte, 1 = short, 2 = long) */
891 TRUE, /* pc_relative */
893 complain_overflow_signed, /* complain_on_overflow */
894 bfd_elf_generic_reloc, /* special_function */
895 AARCH64_R_STR (TSTBR14), /* name */
896 FALSE, /* partial_inplace */
897 0x3fff, /* src_mask */
898 0x3fff, /* dst_mask */
899 TRUE), /* pcrel_offset */
901 /* B.cond: ((S+A-P) >> 2) & 0x7ffff */
902 HOWTO (AARCH64_R (CONDBR19), /* type */
904 2, /* size (0 = byte, 1 = short, 2 = long) */
906 TRUE, /* pc_relative */
908 complain_overflow_signed, /* complain_on_overflow */
909 bfd_elf_generic_reloc, /* special_function */
910 AARCH64_R_STR (CONDBR19), /* name */
911 FALSE, /* partial_inplace */
912 0x7ffff, /* src_mask */
913 0x7ffff, /* dst_mask */
914 TRUE), /* pcrel_offset */
916 /* B: ((S+A-P) >> 2) & 0x3ffffff */
917 HOWTO (AARCH64_R (JUMP26), /* type */
919 2, /* size (0 = byte, 1 = short, 2 = long) */
921 TRUE, /* pc_relative */
923 complain_overflow_signed, /* complain_on_overflow */
924 bfd_elf_generic_reloc, /* special_function */
925 AARCH64_R_STR (JUMP26), /* name */
926 FALSE, /* partial_inplace */
927 0x3ffffff, /* src_mask */
928 0x3ffffff, /* dst_mask */
929 TRUE), /* pcrel_offset */
931 /* BL: ((S+A-P) >> 2) & 0x3ffffff */
932 HOWTO (AARCH64_R (CALL26), /* type */
934 2, /* size (0 = byte, 1 = short, 2 = long) */
936 TRUE, /* pc_relative */
938 complain_overflow_signed, /* complain_on_overflow */
939 bfd_elf_generic_reloc, /* special_function */
940 AARCH64_R_STR (CALL26), /* name */
941 FALSE, /* partial_inplace */
942 0x3ffffff, /* src_mask */
943 0x3ffffff, /* dst_mask */
944 TRUE), /* pcrel_offset */
946 /* LD/ST16: (S+A) & 0xffe */
947 HOWTO (AARCH64_R (LDST16_ABS_LO12_NC), /* type */
949 2, /* size (0 = byte, 1 = short, 2 = long) */
951 FALSE, /* pc_relative */
953 complain_overflow_dont, /* complain_on_overflow */
954 bfd_elf_generic_reloc, /* special_function */
955 AARCH64_R_STR (LDST16_ABS_LO12_NC), /* name */
956 FALSE, /* partial_inplace */
957 0xffe, /* src_mask */
958 0xffe, /* dst_mask */
959 FALSE), /* pcrel_offset */
961 /* LD/ST32: (S+A) & 0xffc */
962 HOWTO (AARCH64_R (LDST32_ABS_LO12_NC), /* type */
964 2, /* size (0 = byte, 1 = short, 2 = long) */
966 FALSE, /* pc_relative */
968 complain_overflow_dont, /* complain_on_overflow */
969 bfd_elf_generic_reloc, /* special_function */
970 AARCH64_R_STR (LDST32_ABS_LO12_NC), /* name */
971 FALSE, /* partial_inplace */
972 0xffc, /* src_mask */
973 0xffc, /* dst_mask */
974 FALSE), /* pcrel_offset */
976 /* LD/ST64: (S+A) & 0xff8 */
977 HOWTO (AARCH64_R (LDST64_ABS_LO12_NC), /* type */
979 2, /* size (0 = byte, 1 = short, 2 = long) */
981 FALSE, /* pc_relative */
983 complain_overflow_dont, /* complain_on_overflow */
984 bfd_elf_generic_reloc, /* special_function */
985 AARCH64_R_STR (LDST64_ABS_LO12_NC), /* name */
986 FALSE, /* partial_inplace */
987 0xff8, /* src_mask */
988 0xff8, /* dst_mask */
989 FALSE), /* pcrel_offset */
991 /* LD/ST128: (S+A) & 0xff0 */
992 HOWTO (AARCH64_R (LDST128_ABS_LO12_NC), /* type */
994 2, /* size (0 = byte, 1 = short, 2 = long) */
996 FALSE, /* pc_relative */
998 complain_overflow_dont, /* complain_on_overflow */
999 bfd_elf_generic_reloc, /* special_function */
1000 AARCH64_R_STR (LDST128_ABS_LO12_NC), /* name */
1001 FALSE, /* partial_inplace */
1002 0xff0, /* src_mask */
1003 0xff0, /* dst_mask */
1004 FALSE), /* pcrel_offset */
1006 /* Set a load-literal immediate field to bits
1007 0x1FFFFC of G(S)-P */
1008 HOWTO (AARCH64_R (GOT_LD_PREL19), /* type */
1010 2, /* size (0 = byte,1 = short,2 = long) */
1012 TRUE, /* pc_relative */
1014 complain_overflow_signed, /* complain_on_overflow */
1015 bfd_elf_generic_reloc, /* special_function */
1016 AARCH64_R_STR (GOT_LD_PREL19), /* name */
1017 FALSE, /* partial_inplace */
1018 0xffffe0, /* src_mask */
1019 0xffffe0, /* dst_mask */
1020 TRUE), /* pcrel_offset */
1022 /* Get to the page for the GOT entry for the symbol
1023 (G(S) - P) using an ADRP instruction. */
1024 HOWTO (AARCH64_R (ADR_GOT_PAGE), /* type */
1025 12, /* rightshift */
1026 2, /* size (0 = byte, 1 = short, 2 = long) */
1028 TRUE, /* pc_relative */
1030 complain_overflow_dont, /* complain_on_overflow */
1031 bfd_elf_generic_reloc, /* special_function */
1032 AARCH64_R_STR (ADR_GOT_PAGE), /* name */
1033 FALSE, /* partial_inplace */
1034 0x1fffff, /* src_mask */
1035 0x1fffff, /* dst_mask */
1036 TRUE), /* pcrel_offset */
1038 /* LD64: GOT offset G(S) & 0xff8 */
1039 HOWTO64 (AARCH64_R (LD64_GOT_LO12_NC), /* type */
1041 2, /* size (0 = byte, 1 = short, 2 = long) */
1043 FALSE, /* pc_relative */
1045 complain_overflow_dont, /* complain_on_overflow */
1046 bfd_elf_generic_reloc, /* special_function */
1047 AARCH64_R_STR (LD64_GOT_LO12_NC), /* name */
1048 FALSE, /* partial_inplace */
1049 0xff8, /* src_mask */
1050 0xff8, /* dst_mask */
1051 FALSE), /* pcrel_offset */
1053 /* LD32: GOT offset G(S) & 0xffc */
1054 HOWTO32 (AARCH64_R (LD32_GOT_LO12_NC), /* type */
1056 2, /* size (0 = byte, 1 = short, 2 = long) */
1058 FALSE, /* pc_relative */
1060 complain_overflow_dont, /* complain_on_overflow */
1061 bfd_elf_generic_reloc, /* special_function */
1062 AARCH64_R_STR (LD32_GOT_LO12_NC), /* name */
1063 FALSE, /* partial_inplace */
1064 0xffc, /* src_mask */
1065 0xffc, /* dst_mask */
1066 FALSE), /* pcrel_offset */
1068 /* Lower 16 bits of GOT offset for the symbol. */
1069 HOWTO64 (AARCH64_R (MOVW_GOTOFF_G0_NC), /* type */
1071 2, /* size (0 = byte, 1 = short, 2 = long) */
1073 FALSE, /* pc_relative */
1075 complain_overflow_dont, /* complain_on_overflow */
1076 bfd_elf_generic_reloc, /* special_function */
1077 AARCH64_R_STR (MOVW_GOTOFF_G0_NC), /* name */
1078 FALSE, /* partial_inplace */
1079 0xffff, /* src_mask */
1080 0xffff, /* dst_mask */
1081 FALSE), /* pcrel_offset */
1083 /* Higher 16 bits of GOT offset for the symbol. */
1084 HOWTO64 (AARCH64_R (MOVW_GOTOFF_G1), /* type */
1085 16, /* rightshift */
1086 2, /* size (0 = byte, 1 = short, 2 = long) */
1088 FALSE, /* pc_relative */
1090 complain_overflow_unsigned, /* complain_on_overflow */
1091 bfd_elf_generic_reloc, /* special_function */
1092 AARCH64_R_STR (MOVW_GOTOFF_G1), /* name */
1093 FALSE, /* partial_inplace */
1094 0xffff, /* src_mask */
1095 0xffff, /* dst_mask */
1096 FALSE), /* pcrel_offset */
1098 /* LD64: GOT offset for the symbol. */
1099 HOWTO64 (AARCH64_R (LD64_GOTOFF_LO15), /* type */
1101 2, /* size (0 = byte, 1 = short, 2 = long) */
1103 FALSE, /* pc_relative */
1105 complain_overflow_unsigned, /* complain_on_overflow */
1106 bfd_elf_generic_reloc, /* special_function */
1107 AARCH64_R_STR (LD64_GOTOFF_LO15), /* name */
1108 FALSE, /* partial_inplace */
1109 0x7ff8, /* src_mask */
1110 0x7ff8, /* dst_mask */
1111 FALSE), /* pcrel_offset */
1113 /* LD32: GOT offset to the page address of GOT table.
1114 (G(S) - PAGE (_GLOBAL_OFFSET_TABLE_)) & 0x5ffc. */
1115 HOWTO32 (AARCH64_R (LD32_GOTPAGE_LO14), /* type */
1117 2, /* size (0 = byte, 1 = short, 2 = long) */
1119 FALSE, /* pc_relative */
1121 complain_overflow_unsigned, /* complain_on_overflow */
1122 bfd_elf_generic_reloc, /* special_function */
1123 AARCH64_R_STR (LD32_GOTPAGE_LO14), /* name */
1124 FALSE, /* partial_inplace */
1125 0x5ffc, /* src_mask */
1126 0x5ffc, /* dst_mask */
1127 FALSE), /* pcrel_offset */
1129 /* LD64: GOT offset to the page address of GOT table.
1130 (G(S) - PAGE (_GLOBAL_OFFSET_TABLE_)) & 0x7ff8. */
1131 HOWTO64 (AARCH64_R (LD64_GOTPAGE_LO15), /* type */
1133 2, /* size (0 = byte, 1 = short, 2 = long) */
1135 FALSE, /* pc_relative */
1137 complain_overflow_unsigned, /* complain_on_overflow */
1138 bfd_elf_generic_reloc, /* special_function */
1139 AARCH64_R_STR (LD64_GOTPAGE_LO15), /* name */
1140 FALSE, /* partial_inplace */
1141 0x7ff8, /* src_mask */
1142 0x7ff8, /* dst_mask */
1143 FALSE), /* pcrel_offset */
1145 /* Get to the page for the GOT entry for the symbol
1146 (G(S) - P) using an ADRP instruction. */
1147 HOWTO (AARCH64_R (TLSGD_ADR_PAGE21), /* type */
1148 12, /* rightshift */
1149 2, /* size (0 = byte, 1 = short, 2 = long) */
1151 TRUE, /* pc_relative */
1153 complain_overflow_dont, /* complain_on_overflow */
1154 bfd_elf_generic_reloc, /* special_function */
1155 AARCH64_R_STR (TLSGD_ADR_PAGE21), /* name */
1156 FALSE, /* partial_inplace */
1157 0x1fffff, /* src_mask */
1158 0x1fffff, /* dst_mask */
1159 TRUE), /* pcrel_offset */
1161 HOWTO (AARCH64_R (TLSGD_ADR_PREL21), /* type */
1163 2, /* size (0 = byte, 1 = short, 2 = long) */
1165 TRUE, /* pc_relative */
1167 complain_overflow_dont, /* complain_on_overflow */
1168 bfd_elf_generic_reloc, /* special_function */
1169 AARCH64_R_STR (TLSGD_ADR_PREL21), /* name */
1170 FALSE, /* partial_inplace */
1171 0x1fffff, /* src_mask */
1172 0x1fffff, /* dst_mask */
1173 TRUE), /* pcrel_offset */
1175 /* ADD: GOT offset G(S) & 0xff8 [no overflow check] */
1176 HOWTO (AARCH64_R (TLSGD_ADD_LO12_NC), /* type */
1178 2, /* size (0 = byte, 1 = short, 2 = long) */
1180 FALSE, /* pc_relative */
1182 complain_overflow_dont, /* complain_on_overflow */
1183 bfd_elf_generic_reloc, /* special_function */
1184 AARCH64_R_STR (TLSGD_ADD_LO12_NC), /* name */
1185 FALSE, /* partial_inplace */
1186 0xfff, /* src_mask */
1187 0xfff, /* dst_mask */
1188 FALSE), /* pcrel_offset */
1190 /* Lower 16 bits of GOT offset to tls_index. */
1191 HOWTO64 (AARCH64_R (TLSGD_MOVW_G0_NC), /* type */
1193 2, /* size (0 = byte, 1 = short, 2 = long) */
1195 FALSE, /* pc_relative */
1197 complain_overflow_dont, /* complain_on_overflow */
1198 bfd_elf_generic_reloc, /* special_function */
1199 AARCH64_R_STR (TLSGD_MOVW_G0_NC), /* name */
1200 FALSE, /* partial_inplace */
1201 0xffff, /* src_mask */
1202 0xffff, /* dst_mask */
1203 FALSE), /* pcrel_offset */
1205 /* Higher 16 bits of GOT offset to tls_index. */
1206 HOWTO64 (AARCH64_R (TLSGD_MOVW_G1), /* type */
1207 16, /* rightshift */
1208 2, /* size (0 = byte, 1 = short, 2 = long) */
1210 FALSE, /* pc_relative */
1212 complain_overflow_unsigned, /* complain_on_overflow */
1213 bfd_elf_generic_reloc, /* special_function */
1214 AARCH64_R_STR (TLSGD_MOVW_G1), /* name */
1215 FALSE, /* partial_inplace */
1216 0xffff, /* src_mask */
1217 0xffff, /* dst_mask */
1218 FALSE), /* pcrel_offset */
1220 HOWTO (AARCH64_R (TLSIE_ADR_GOTTPREL_PAGE21), /* type */
1221 12, /* rightshift */
1222 2, /* size (0 = byte, 1 = short, 2 = long) */
1224 FALSE, /* pc_relative */
1226 complain_overflow_dont, /* complain_on_overflow */
1227 bfd_elf_generic_reloc, /* special_function */
1228 AARCH64_R_STR (TLSIE_ADR_GOTTPREL_PAGE21), /* name */
1229 FALSE, /* partial_inplace */
1230 0x1fffff, /* src_mask */
1231 0x1fffff, /* dst_mask */
1232 FALSE), /* pcrel_offset */
1234 HOWTO64 (AARCH64_R (TLSIE_LD64_GOTTPREL_LO12_NC), /* type */
1236 2, /* size (0 = byte, 1 = short, 2 = long) */
1238 FALSE, /* pc_relative */
1240 complain_overflow_dont, /* complain_on_overflow */
1241 bfd_elf_generic_reloc, /* special_function */
1242 AARCH64_R_STR (TLSIE_LD64_GOTTPREL_LO12_NC), /* name */
1243 FALSE, /* partial_inplace */
1244 0xff8, /* src_mask */
1245 0xff8, /* dst_mask */
1246 FALSE), /* pcrel_offset */
1248 HOWTO32 (AARCH64_R (TLSIE_LD32_GOTTPREL_LO12_NC), /* type */
1250 2, /* size (0 = byte, 1 = short, 2 = long) */
1252 FALSE, /* pc_relative */
1254 complain_overflow_dont, /* complain_on_overflow */
1255 bfd_elf_generic_reloc, /* special_function */
1256 AARCH64_R_STR (TLSIE_LD32_GOTTPREL_LO12_NC), /* name */
1257 FALSE, /* partial_inplace */
1258 0xffc, /* src_mask */
1259 0xffc, /* dst_mask */
1260 FALSE), /* pcrel_offset */
1262 HOWTO (AARCH64_R (TLSIE_LD_GOTTPREL_PREL19), /* type */
1264 2, /* size (0 = byte, 1 = short, 2 = long) */
1266 FALSE, /* pc_relative */
1268 complain_overflow_dont, /* complain_on_overflow */
1269 bfd_elf_generic_reloc, /* special_function */
1270 AARCH64_R_STR (TLSIE_LD_GOTTPREL_PREL19), /* name */
1271 FALSE, /* partial_inplace */
1272 0x1ffffc, /* src_mask */
1273 0x1ffffc, /* dst_mask */
1274 FALSE), /* pcrel_offset */
1276 HOWTO64 (AARCH64_R (TLSIE_MOVW_GOTTPREL_G0_NC), /* type */
1278 2, /* size (0 = byte, 1 = short, 2 = long) */
1280 FALSE, /* pc_relative */
1282 complain_overflow_dont, /* complain_on_overflow */
1283 bfd_elf_generic_reloc, /* special_function */
1284 AARCH64_R_STR (TLSIE_MOVW_GOTTPREL_G0_NC), /* name */
1285 FALSE, /* partial_inplace */
1286 0xffff, /* src_mask */
1287 0xffff, /* dst_mask */
1288 FALSE), /* pcrel_offset */
1290 HOWTO64 (AARCH64_R (TLSIE_MOVW_GOTTPREL_G1), /* type */
1291 16, /* rightshift */
1292 2, /* size (0 = byte, 1 = short, 2 = long) */
1294 FALSE, /* pc_relative */
1296 complain_overflow_unsigned, /* complain_on_overflow */
1297 bfd_elf_generic_reloc, /* special_function */
1298 AARCH64_R_STR (TLSIE_MOVW_GOTTPREL_G1), /* name */
1299 FALSE, /* partial_inplace */
1300 0xffff, /* src_mask */
1301 0xffff, /* dst_mask */
1302 FALSE), /* pcrel_offset */
1304 /* ADD: bit[23:12] of byte offset to module TLS base address. */
1305 HOWTO (AARCH64_R (TLSLD_ADD_DTPREL_HI12), /* type */
1306 12, /* rightshift */
1307 2, /* size (0 = byte, 1 = short, 2 = long) */
1309 FALSE, /* pc_relative */
1311 complain_overflow_unsigned, /* complain_on_overflow */
1312 bfd_elf_generic_reloc, /* special_function */
1313 AARCH64_R_STR (TLSLD_ADD_DTPREL_HI12), /* name */
1314 FALSE, /* partial_inplace */
1315 0xfff, /* src_mask */
1316 0xfff, /* dst_mask */
1317 FALSE), /* pcrel_offset */
1319 /* Unsigned 12 bit byte offset to module TLS base address. */
1320 HOWTO (AARCH64_R (TLSLD_ADD_DTPREL_LO12), /* type */
1322 2, /* size (0 = byte, 1 = short, 2 = long) */
1324 FALSE, /* pc_relative */
1326 complain_overflow_unsigned, /* complain_on_overflow */
1327 bfd_elf_generic_reloc, /* special_function */
1328 AARCH64_R_STR (TLSLD_ADD_DTPREL_LO12), /* name */
1329 FALSE, /* partial_inplace */
1330 0xfff, /* src_mask */
1331 0xfff, /* dst_mask */
1332 FALSE), /* pcrel_offset */
1334 /* No overflow check version of BFD_RELOC_AARCH64_TLSLD_ADD_DTPREL_LO12. */
1335 HOWTO (AARCH64_R (TLSLD_ADD_DTPREL_LO12_NC), /* type */
1337 2, /* size (0 = byte, 1 = short, 2 = long) */
1339 FALSE, /* pc_relative */
1341 complain_overflow_dont, /* complain_on_overflow */
1342 bfd_elf_generic_reloc, /* special_function */
1343 AARCH64_R_STR (TLSLD_ADD_DTPREL_LO12_NC), /* name */
1344 FALSE, /* partial_inplace */
1345 0xfff, /* src_mask */
1346 0xfff, /* dst_mask */
1347 FALSE), /* pcrel_offset */
1349 /* ADD: GOT offset G(S) & 0xff8 [no overflow check] */
1350 HOWTO (AARCH64_R (TLSLD_ADD_LO12_NC), /* type */
1352 2, /* size (0 = byte, 1 = short, 2 = long) */
1354 FALSE, /* pc_relative */
1356 complain_overflow_dont, /* complain_on_overflow */
1357 bfd_elf_generic_reloc, /* special_function */
1358 AARCH64_R_STR (TLSLD_ADD_LO12_NC), /* name */
1359 FALSE, /* partial_inplace */
1360 0xfff, /* src_mask */
1361 0xfff, /* dst_mask */
1362 FALSE), /* pcrel_offset */
1364 /* Get to the page for the GOT entry for the symbol
1365 (G(S) - P) using an ADRP instruction. */
1366 HOWTO (AARCH64_R (TLSLD_ADR_PAGE21), /* type */
1367 12, /* rightshift */
1368 2, /* size (0 = byte, 1 = short, 2 = long) */
1370 TRUE, /* pc_relative */
1372 complain_overflow_signed, /* complain_on_overflow */
1373 bfd_elf_generic_reloc, /* special_function */
1374 AARCH64_R_STR (TLSLD_ADR_PAGE21), /* name */
1375 FALSE, /* partial_inplace */
1376 0x1fffff, /* src_mask */
1377 0x1fffff, /* dst_mask */
1378 TRUE), /* pcrel_offset */
1380 HOWTO (AARCH64_R (TLSLD_ADR_PREL21), /* type */
1382 2, /* size (0 = byte, 1 = short, 2 = long) */
1384 TRUE, /* pc_relative */
1386 complain_overflow_signed, /* complain_on_overflow */
1387 bfd_elf_generic_reloc, /* special_function */
1388 AARCH64_R_STR (TLSLD_ADR_PREL21), /* name */
1389 FALSE, /* partial_inplace */
1390 0x1fffff, /* src_mask */
1391 0x1fffff, /* dst_mask */
1392 TRUE), /* pcrel_offset */
1394 /* LD/ST16: bit[11:1] of byte offset to module TLS base address. */
1395 HOWTO64 (AARCH64_R (TLSLD_LDST16_DTPREL_LO12), /* type */
1397 2, /* size (0 = byte, 1 = short, 2 = long) */
1399 FALSE, /* pc_relative */
1401 complain_overflow_unsigned, /* complain_on_overflow */
1402 bfd_elf_generic_reloc, /* special_function */
1403 AARCH64_R_STR (TLSLD_LDST16_DTPREL_LO12), /* name */
1404 FALSE, /* partial_inplace */
1405 0x1ffc00, /* src_mask */
1406 0x1ffc00, /* dst_mask */
1407 FALSE), /* pcrel_offset */
1409 /* Same as BFD_RELOC_AARCH64_TLSLD_LDST16_DTPREL_LO12, but no overflow check. */
1410 HOWTO64 (AARCH64_R (TLSLD_LDST16_DTPREL_LO12_NC), /* type */
1412 2, /* size (0 = byte, 1 = short, 2 = long) */
1414 FALSE, /* pc_relative */
1416 complain_overflow_dont, /* complain_on_overflow */
1417 bfd_elf_generic_reloc, /* special_function */
1418 AARCH64_R_STR (TLSLD_LDST16_DTPREL_LO12_NC), /* name */
1419 FALSE, /* partial_inplace */
1420 0x1ffc00, /* src_mask */
1421 0x1ffc00, /* dst_mask */
1422 FALSE), /* pcrel_offset */
1424 /* LD/ST32: bit[11:2] of byte offset to module TLS base address. */
1425 HOWTO64 (AARCH64_R (TLSLD_LDST32_DTPREL_LO12), /* type */
1427 2, /* size (0 = byte, 1 = short, 2 = long) */
1429 FALSE, /* pc_relative */
1431 complain_overflow_unsigned, /* complain_on_overflow */
1432 bfd_elf_generic_reloc, /* special_function */
1433 AARCH64_R_STR (TLSLD_LDST32_DTPREL_LO12), /* name */
1434 FALSE, /* partial_inplace */
1435 0x3ffc00, /* src_mask */
1436 0x3ffc00, /* dst_mask */
1437 FALSE), /* pcrel_offset */
1439 /* Same as BFD_RELOC_AARCH64_TLSLD_LDST32_DTPREL_LO12, but no overflow check. */
1440 HOWTO64 (AARCH64_R (TLSLD_LDST32_DTPREL_LO12_NC), /* type */
1442 2, /* size (0 = byte, 1 = short, 2 = long) */
1444 FALSE, /* pc_relative */
1446 complain_overflow_dont, /* complain_on_overflow */
1447 bfd_elf_generic_reloc, /* special_function */
1448 AARCH64_R_STR (TLSLD_LDST32_DTPREL_LO12_NC), /* name */
1449 FALSE, /* partial_inplace */
1450 0xffc00, /* src_mask */
1451 0xffc00, /* dst_mask */
1452 FALSE), /* pcrel_offset */
1454 /* LD/ST64: bit[11:3] of byte offset to module TLS base address. */
1455 HOWTO64 (AARCH64_R (TLSLD_LDST64_DTPREL_LO12), /* type */
1457 2, /* size (0 = byte, 1 = short, 2 = long) */
1459 FALSE, /* pc_relative */
1461 complain_overflow_unsigned, /* complain_on_overflow */
1462 bfd_elf_generic_reloc, /* special_function */
1463 AARCH64_R_STR (TLSLD_LDST64_DTPREL_LO12), /* name */
1464 FALSE, /* partial_inplace */
1465 0x3ffc00, /* src_mask */
1466 0x3ffc00, /* dst_mask */
1467 FALSE), /* pcrel_offset */
1469 /* Same as BFD_RELOC_AARCH64_TLSLD_LDST64_DTPREL_LO12, but no overflow check. */
1470 HOWTO64 (AARCH64_R (TLSLD_LDST64_DTPREL_LO12_NC), /* type */
1472 2, /* size (0 = byte, 1 = short, 2 = long) */
1474 FALSE, /* pc_relative */
1476 complain_overflow_dont, /* complain_on_overflow */
1477 bfd_elf_generic_reloc, /* special_function */
1478 AARCH64_R_STR (TLSLD_LDST64_DTPREL_LO12_NC), /* name */
1479 FALSE, /* partial_inplace */
1480 0x7fc00, /* src_mask */
1481 0x7fc00, /* dst_mask */
1482 FALSE), /* pcrel_offset */
1484 /* LD/ST8: bit[11:0] of byte offset to module TLS base address. */
1485 HOWTO64 (AARCH64_R (TLSLD_LDST8_DTPREL_LO12), /* type */
1487 2, /* size (0 = byte, 1 = short, 2 = long) */
1489 FALSE, /* pc_relative */
1491 complain_overflow_unsigned, /* complain_on_overflow */
1492 bfd_elf_generic_reloc, /* special_function */
1493 AARCH64_R_STR (TLSLD_LDST8_DTPREL_LO12), /* name */
1494 FALSE, /* partial_inplace */
1495 0x3ffc00, /* src_mask */
1496 0x3ffc00, /* dst_mask */
1497 FALSE), /* pcrel_offset */
1499 /* Same as BFD_RELOC_AARCH64_TLSLD_LDST8_DTPREL_LO12, but no overflow check. */
1500 HOWTO64 (AARCH64_R (TLSLD_LDST8_DTPREL_LO12_NC), /* type */
1502 2, /* size (0 = byte, 1 = short, 2 = long) */
1504 FALSE, /* pc_relative */
1506 complain_overflow_dont, /* complain_on_overflow */
1507 bfd_elf_generic_reloc, /* special_function */
1508 AARCH64_R_STR (TLSLD_LDST8_DTPREL_LO12_NC), /* name */
1509 FALSE, /* partial_inplace */
1510 0x3ffc00, /* src_mask */
1511 0x3ffc00, /* dst_mask */
1512 FALSE), /* pcrel_offset */
1514 /* MOVZ: bit[15:0] of byte offset to module TLS base address. */
1515 HOWTO (AARCH64_R (TLSLD_MOVW_DTPREL_G0), /* type */
1517 2, /* size (0 = byte, 1 = short, 2 = long) */
1519 FALSE, /* pc_relative */
1521 complain_overflow_unsigned, /* complain_on_overflow */
1522 bfd_elf_generic_reloc, /* special_function */
1523 AARCH64_R_STR (TLSLD_MOVW_DTPREL_G0), /* name */
1524 FALSE, /* partial_inplace */
1525 0xffff, /* src_mask */
1526 0xffff, /* dst_mask */
1527 FALSE), /* pcrel_offset */
1529 /* No overflow check version of BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G0. */
1530 HOWTO (AARCH64_R (TLSLD_MOVW_DTPREL_G0_NC), /* type */
1532 2, /* size (0 = byte, 1 = short, 2 = long) */
1534 FALSE, /* pc_relative */
1536 complain_overflow_dont, /* complain_on_overflow */
1537 bfd_elf_generic_reloc, /* special_function */
1538 AARCH64_R_STR (TLSLD_MOVW_DTPREL_G0_NC), /* name */
1539 FALSE, /* partial_inplace */
1540 0xffff, /* src_mask */
1541 0xffff, /* dst_mask */
1542 FALSE), /* pcrel_offset */
1544 /* MOVZ: bit[31:16] of byte offset to module TLS base address. */
1545 HOWTO (AARCH64_R (TLSLD_MOVW_DTPREL_G1), /* type */
1546 16, /* rightshift */
1547 2, /* size (0 = byte, 1 = short, 2 = long) */
1549 FALSE, /* pc_relative */
1551 complain_overflow_unsigned, /* complain_on_overflow */
1552 bfd_elf_generic_reloc, /* special_function */
1553 AARCH64_R_STR (TLSLD_MOVW_DTPREL_G1), /* name */
1554 FALSE, /* partial_inplace */
1555 0xffff, /* src_mask */
1556 0xffff, /* dst_mask */
1557 FALSE), /* pcrel_offset */
1559 /* No overflow check version of BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G1. */
1560 HOWTO64 (AARCH64_R (TLSLD_MOVW_DTPREL_G1_NC), /* type */
1561 16, /* rightshift */
1562 2, /* size (0 = byte, 1 = short, 2 = long) */
1564 FALSE, /* pc_relative */
1566 complain_overflow_dont, /* complain_on_overflow */
1567 bfd_elf_generic_reloc, /* special_function */
1568 AARCH64_R_STR (TLSLD_MOVW_DTPREL_G1_NC), /* name */
1569 FALSE, /* partial_inplace */
1570 0xffff, /* src_mask */
1571 0xffff, /* dst_mask */
1572 FALSE), /* pcrel_offset */
1574 /* MOVZ: bit[47:32] of byte offset to module TLS base address. */
1575 HOWTO64 (AARCH64_R (TLSLD_MOVW_DTPREL_G2), /* type */
1576 32, /* rightshift */
1577 2, /* size (0 = byte, 1 = short, 2 = long) */
1579 FALSE, /* pc_relative */
1581 complain_overflow_unsigned, /* complain_on_overflow */
1582 bfd_elf_generic_reloc, /* special_function */
1583 AARCH64_R_STR (TLSLD_MOVW_DTPREL_G2), /* name */
1584 FALSE, /* partial_inplace */
1585 0xffff, /* src_mask */
1586 0xffff, /* dst_mask */
1587 FALSE), /* pcrel_offset */
1589 HOWTO64 (AARCH64_R (TLSLE_MOVW_TPREL_G2), /* type */
1590 32, /* rightshift */
1591 2, /* size (0 = byte, 1 = short, 2 = long) */
1593 FALSE, /* pc_relative */
1595 complain_overflow_unsigned, /* complain_on_overflow */
1596 bfd_elf_generic_reloc, /* special_function */
1597 AARCH64_R_STR (TLSLE_MOVW_TPREL_G2), /* name */
1598 FALSE, /* partial_inplace */
1599 0xffff, /* src_mask */
1600 0xffff, /* dst_mask */
1601 FALSE), /* pcrel_offset */
1603 HOWTO (AARCH64_R (TLSLE_MOVW_TPREL_G1), /* type */
1604 16, /* rightshift */
1605 2, /* size (0 = byte, 1 = short, 2 = long) */
1607 FALSE, /* pc_relative */
1609 complain_overflow_dont, /* complain_on_overflow */
1610 bfd_elf_generic_reloc, /* special_function */
1611 AARCH64_R_STR (TLSLE_MOVW_TPREL_G1), /* name */
1612 FALSE, /* partial_inplace */
1613 0xffff, /* src_mask */
1614 0xffff, /* dst_mask */
1615 FALSE), /* pcrel_offset */
1617 HOWTO64 (AARCH64_R (TLSLE_MOVW_TPREL_G1_NC), /* type */
1618 16, /* rightshift */
1619 2, /* size (0 = byte, 1 = short, 2 = long) */
1621 FALSE, /* pc_relative */
1623 complain_overflow_dont, /* complain_on_overflow */
1624 bfd_elf_generic_reloc, /* special_function */
1625 AARCH64_R_STR (TLSLE_MOVW_TPREL_G1_NC), /* name */
1626 FALSE, /* partial_inplace */
1627 0xffff, /* src_mask */
1628 0xffff, /* dst_mask */
1629 FALSE), /* pcrel_offset */
1631 HOWTO (AARCH64_R (TLSLE_MOVW_TPREL_G0), /* type */
1633 2, /* size (0 = byte, 1 = short, 2 = long) */
1635 FALSE, /* pc_relative */
1637 complain_overflow_dont, /* complain_on_overflow */
1638 bfd_elf_generic_reloc, /* special_function */
1639 AARCH64_R_STR (TLSLE_MOVW_TPREL_G0), /* name */
1640 FALSE, /* partial_inplace */
1641 0xffff, /* src_mask */
1642 0xffff, /* dst_mask */
1643 FALSE), /* pcrel_offset */
1645 HOWTO (AARCH64_R (TLSLE_MOVW_TPREL_G0_NC), /* type */
1647 2, /* size (0 = byte, 1 = short, 2 = long) */
1649 FALSE, /* pc_relative */
1651 complain_overflow_dont, /* complain_on_overflow */
1652 bfd_elf_generic_reloc, /* special_function */
1653 AARCH64_R_STR (TLSLE_MOVW_TPREL_G0_NC), /* name */
1654 FALSE, /* partial_inplace */
1655 0xffff, /* src_mask */
1656 0xffff, /* dst_mask */
1657 FALSE), /* pcrel_offset */
1659 HOWTO (AARCH64_R (TLSLE_ADD_TPREL_HI12), /* type */
1660 12, /* rightshift */
1661 2, /* size (0 = byte, 1 = short, 2 = long) */
1663 FALSE, /* pc_relative */
1665 complain_overflow_unsigned, /* complain_on_overflow */
1666 bfd_elf_generic_reloc, /* special_function */
1667 AARCH64_R_STR (TLSLE_ADD_TPREL_HI12), /* name */
1668 FALSE, /* partial_inplace */
1669 0xfff, /* src_mask */
1670 0xfff, /* dst_mask */
1671 FALSE), /* pcrel_offset */
1673 HOWTO (AARCH64_R (TLSLE_ADD_TPREL_LO12), /* type */
1675 2, /* size (0 = byte, 1 = short, 2 = long) */
1677 FALSE, /* pc_relative */
1679 complain_overflow_unsigned, /* complain_on_overflow */
1680 bfd_elf_generic_reloc, /* special_function */
1681 AARCH64_R_STR (TLSLE_ADD_TPREL_LO12), /* name */
1682 FALSE, /* partial_inplace */
1683 0xfff, /* src_mask */
1684 0xfff, /* dst_mask */
1685 FALSE), /* pcrel_offset */
1687 HOWTO (AARCH64_R (TLSLE_ADD_TPREL_LO12_NC), /* type */
1689 2, /* size (0 = byte, 1 = short, 2 = long) */
1691 FALSE, /* pc_relative */
1693 complain_overflow_dont, /* complain_on_overflow */
1694 bfd_elf_generic_reloc, /* special_function */
1695 AARCH64_R_STR (TLSLE_ADD_TPREL_LO12_NC), /* name */
1696 FALSE, /* partial_inplace */
1697 0xfff, /* src_mask */
1698 0xfff, /* dst_mask */
1699 FALSE), /* pcrel_offset */
1701 /* LD/ST16: bit[11:1] of byte offset to module TLS base address. */
1702 HOWTO (AARCH64_R (TLSLE_LDST16_TPREL_LO12), /* type */
1704 2, /* size (0 = byte, 1 = short, 2 = long) */
1706 FALSE, /* pc_relative */
1708 complain_overflow_unsigned, /* complain_on_overflow */
1709 bfd_elf_generic_reloc, /* special_function */
1710 AARCH64_R_STR (TLSLE_LDST16_TPREL_LO12), /* name */
1711 FALSE, /* partial_inplace */
1712 0x1ffc00, /* src_mask */
1713 0x1ffc00, /* dst_mask */
1714 FALSE), /* pcrel_offset */
1716 /* Same as BFD_RELOC_AARCH64_TLSLE_LDST16_TPREL_LO12, but no overflow check. */
1717 HOWTO (AARCH64_R (TLSLE_LDST16_TPREL_LO12_NC), /* type */
1719 2, /* size (0 = byte, 1 = short, 2 = long) */
1721 FALSE, /* pc_relative */
1723 complain_overflow_dont, /* complain_on_overflow */
1724 bfd_elf_generic_reloc, /* special_function */
1725 AARCH64_R_STR (TLSLE_LDST16_TPREL_LO12_NC), /* name */
1726 FALSE, /* partial_inplace */
1727 0x1ffc00, /* src_mask */
1728 0x1ffc00, /* dst_mask */
1729 FALSE), /* pcrel_offset */
1731 /* LD/ST32: bit[11:2] of byte offset to module TLS base address. */
1732 HOWTO (AARCH64_R (TLSLE_LDST32_TPREL_LO12), /* type */
1734 2, /* size (0 = byte, 1 = short, 2 = long) */
1736 FALSE, /* pc_relative */
1738 complain_overflow_unsigned, /* complain_on_overflow */
1739 bfd_elf_generic_reloc, /* special_function */
1740 AARCH64_R_STR (TLSLE_LDST32_TPREL_LO12), /* name */
1741 FALSE, /* partial_inplace */
1742 0xffc00, /* src_mask */
1743 0xffc00, /* dst_mask */
1744 FALSE), /* pcrel_offset */
1746 /* Same as BFD_RELOC_AARCH64_TLSLE_LDST32_TPREL_LO12, but no overflow check. */
1747 HOWTO (AARCH64_R (TLSLE_LDST32_TPREL_LO12_NC), /* type */
1749 2, /* size (0 = byte, 1 = short, 2 = long) */
1751 FALSE, /* pc_relative */
1753 complain_overflow_dont, /* complain_on_overflow */
1754 bfd_elf_generic_reloc, /* special_function */
1755 AARCH64_R_STR (TLSLE_LDST32_TPREL_LO12_NC), /* name */
1756 FALSE, /* partial_inplace */
1757 0xffc00, /* src_mask */
1758 0xffc00, /* dst_mask */
1759 FALSE), /* pcrel_offset */
1761 /* LD/ST64: bit[11:3] of byte offset to module TLS base address. */
1762 HOWTO (AARCH64_R (TLSLE_LDST64_TPREL_LO12), /* type */
1764 2, /* size (0 = byte, 1 = short, 2 = long) */
1766 FALSE, /* pc_relative */
1768 complain_overflow_unsigned, /* complain_on_overflow */
1769 bfd_elf_generic_reloc, /* special_function */
1770 AARCH64_R_STR (TLSLE_LDST64_TPREL_LO12), /* name */
1771 FALSE, /* partial_inplace */
1772 0x7fc00, /* src_mask */
1773 0x7fc00, /* dst_mask */
1774 FALSE), /* pcrel_offset */
1776 /* Same as BFD_RELOC_AARCH64_TLSLE_LDST64_TPREL_LO12, but no overflow check. */
1777 HOWTO (AARCH64_R (TLSLE_LDST64_TPREL_LO12_NC), /* type */
1779 2, /* size (0 = byte, 1 = short, 2 = long) */
1781 FALSE, /* pc_relative */
1783 complain_overflow_dont, /* complain_on_overflow */
1784 bfd_elf_generic_reloc, /* special_function */
1785 AARCH64_R_STR (TLSLE_LDST64_TPREL_LO12_NC), /* name */
1786 FALSE, /* partial_inplace */
1787 0x7fc00, /* src_mask */
1788 0x7fc00, /* dst_mask */
1789 FALSE), /* pcrel_offset */
1791 /* LD/ST8: bit[11:0] of byte offset to module TLS base address. */
1792 HOWTO (AARCH64_R (TLSLE_LDST8_TPREL_LO12), /* type */
1794 2, /* size (0 = byte, 1 = short, 2 = long) */
1796 FALSE, /* pc_relative */
1798 complain_overflow_unsigned, /* complain_on_overflow */
1799 bfd_elf_generic_reloc, /* special_function */
1800 AARCH64_R_STR (TLSLE_LDST8_TPREL_LO12), /* name */
1801 FALSE, /* partial_inplace */
1802 0x3ffc00, /* src_mask */
1803 0x3ffc00, /* dst_mask */
1804 FALSE), /* pcrel_offset */
1806 /* Same as BFD_RELOC_AARCH64_TLSLE_LDST8_TPREL_LO12, but no overflow check. */
1807 HOWTO (AARCH64_R (TLSLE_LDST8_TPREL_LO12_NC), /* type */
1809 2, /* size (0 = byte, 1 = short, 2 = long) */
1811 FALSE, /* pc_relative */
1813 complain_overflow_dont, /* complain_on_overflow */
1814 bfd_elf_generic_reloc, /* special_function */
1815 AARCH64_R_STR (TLSLE_LDST8_TPREL_LO12_NC), /* name */
1816 FALSE, /* partial_inplace */
1817 0x3ffc00, /* src_mask */
1818 0x3ffc00, /* dst_mask */
1819 FALSE), /* pcrel_offset */
1821 HOWTO (AARCH64_R (TLSDESC_LD_PREL19), /* type */
1823 2, /* size (0 = byte, 1 = short, 2 = long) */
1825 TRUE, /* pc_relative */
1827 complain_overflow_dont, /* complain_on_overflow */
1828 bfd_elf_generic_reloc, /* special_function */
1829 AARCH64_R_STR (TLSDESC_LD_PREL19), /* name */
1830 FALSE, /* partial_inplace */
1831 0x0ffffe0, /* src_mask */
1832 0x0ffffe0, /* dst_mask */
1833 TRUE), /* pcrel_offset */
1835 HOWTO (AARCH64_R (TLSDESC_ADR_PREL21), /* type */
1837 2, /* size (0 = byte, 1 = short, 2 = long) */
1839 TRUE, /* pc_relative */
1841 complain_overflow_dont, /* complain_on_overflow */
1842 bfd_elf_generic_reloc, /* special_function */
1843 AARCH64_R_STR (TLSDESC_ADR_PREL21), /* name */
1844 FALSE, /* partial_inplace */
1845 0x1fffff, /* src_mask */
1846 0x1fffff, /* dst_mask */
1847 TRUE), /* pcrel_offset */
1849 /* Get to the page for the GOT entry for the symbol
1850 (G(S) - P) using an ADRP instruction. */
1851 HOWTO (AARCH64_R (TLSDESC_ADR_PAGE21), /* type */
1852 12, /* rightshift */
1853 2, /* size (0 = byte, 1 = short, 2 = long) */
1855 TRUE, /* pc_relative */
1857 complain_overflow_dont, /* complain_on_overflow */
1858 bfd_elf_generic_reloc, /* special_function */
1859 AARCH64_R_STR (TLSDESC_ADR_PAGE21), /* name */
1860 FALSE, /* partial_inplace */
1861 0x1fffff, /* src_mask */
1862 0x1fffff, /* dst_mask */
1863 TRUE), /* pcrel_offset */
1865 /* LD64: GOT offset G(S) & 0xff8. */
1866 HOWTO64 (AARCH64_R (TLSDESC_LD64_LO12), /* type */
1868 2, /* size (0 = byte, 1 = short, 2 = long) */
1870 FALSE, /* pc_relative */
1872 complain_overflow_dont, /* complain_on_overflow */
1873 bfd_elf_generic_reloc, /* special_function */
1874 AARCH64_R_STR (TLSDESC_LD64_LO12), /* name */
1875 FALSE, /* partial_inplace */
1876 0xff8, /* src_mask */
1877 0xff8, /* dst_mask */
1878 FALSE), /* pcrel_offset */
1880 /* LD32: GOT offset G(S) & 0xffc. */
1881 HOWTO32 (AARCH64_R (TLSDESC_LD32_LO12_NC), /* type */
1883 2, /* size (0 = byte, 1 = short, 2 = long) */
1885 FALSE, /* pc_relative */
1887 complain_overflow_dont, /* complain_on_overflow */
1888 bfd_elf_generic_reloc, /* special_function */
1889 AARCH64_R_STR (TLSDESC_LD32_LO12_NC), /* name */
1890 FALSE, /* partial_inplace */
1891 0xffc, /* src_mask */
1892 0xffc, /* dst_mask */
1893 FALSE), /* pcrel_offset */
1895 /* ADD: GOT offset G(S) & 0xfff. */
1896 HOWTO (AARCH64_R (TLSDESC_ADD_LO12), /* type */
1898 2, /* size (0 = byte, 1 = short, 2 = long) */
1900 FALSE, /* pc_relative */
1902 complain_overflow_dont,/* complain_on_overflow */
1903 bfd_elf_generic_reloc, /* special_function */
1904 AARCH64_R_STR (TLSDESC_ADD_LO12), /* name */
1905 FALSE, /* partial_inplace */
1906 0xfff, /* src_mask */
1907 0xfff, /* dst_mask */
1908 FALSE), /* pcrel_offset */
1910 HOWTO64 (AARCH64_R (TLSDESC_OFF_G1), /* type */
1911 16, /* rightshift */
1912 2, /* size (0 = byte, 1 = short, 2 = long) */
1914 FALSE, /* pc_relative */
1916 complain_overflow_unsigned, /* complain_on_overflow */
1917 bfd_elf_generic_reloc, /* special_function */
1918 AARCH64_R_STR (TLSDESC_OFF_G1), /* name */
1919 FALSE, /* partial_inplace */
1920 0xffff, /* src_mask */
1921 0xffff, /* dst_mask */
1922 FALSE), /* pcrel_offset */
1924 HOWTO64 (AARCH64_R (TLSDESC_OFF_G0_NC), /* type */
1926 2, /* size (0 = byte, 1 = short, 2 = long) */
1928 FALSE, /* pc_relative */
1930 complain_overflow_dont, /* complain_on_overflow */
1931 bfd_elf_generic_reloc, /* special_function */
1932 AARCH64_R_STR (TLSDESC_OFF_G0_NC), /* name */
1933 FALSE, /* partial_inplace */
1934 0xffff, /* src_mask */
1935 0xffff, /* dst_mask */
1936 FALSE), /* pcrel_offset */
1938 HOWTO64 (AARCH64_R (TLSDESC_LDR), /* type */
1940 2, /* size (0 = byte, 1 = short, 2 = long) */
1942 FALSE, /* pc_relative */
1944 complain_overflow_dont, /* complain_on_overflow */
1945 bfd_elf_generic_reloc, /* special_function */
1946 AARCH64_R_STR (TLSDESC_LDR), /* name */
1947 FALSE, /* partial_inplace */
1950 FALSE), /* pcrel_offset */
1952 HOWTO64 (AARCH64_R (TLSDESC_ADD), /* type */
1954 2, /* size (0 = byte, 1 = short, 2 = long) */
1956 FALSE, /* pc_relative */
1958 complain_overflow_dont, /* complain_on_overflow */
1959 bfd_elf_generic_reloc, /* special_function */
1960 AARCH64_R_STR (TLSDESC_ADD), /* name */
1961 FALSE, /* partial_inplace */
1964 FALSE), /* pcrel_offset */
1966 HOWTO (AARCH64_R (TLSDESC_CALL), /* type */
1968 2, /* size (0 = byte, 1 = short, 2 = long) */
1970 FALSE, /* pc_relative */
1972 complain_overflow_dont, /* complain_on_overflow */
1973 bfd_elf_generic_reloc, /* special_function */
1974 AARCH64_R_STR (TLSDESC_CALL), /* name */
1975 FALSE, /* partial_inplace */
1978 FALSE), /* pcrel_offset */
1980 HOWTO (AARCH64_R (COPY), /* type */
1982 2, /* size (0 = byte, 1 = short, 2 = long) */
1984 FALSE, /* pc_relative */
1986 complain_overflow_bitfield, /* complain_on_overflow */
1987 bfd_elf_generic_reloc, /* special_function */
1988 AARCH64_R_STR (COPY), /* name */
1989 TRUE, /* partial_inplace */
1990 0xffffffff, /* src_mask */
1991 0xffffffff, /* dst_mask */
1992 FALSE), /* pcrel_offset */
1994 HOWTO (AARCH64_R (GLOB_DAT), /* type */
1996 2, /* size (0 = byte, 1 = short, 2 = long) */
1998 FALSE, /* pc_relative */
2000 complain_overflow_bitfield, /* complain_on_overflow */
2001 bfd_elf_generic_reloc, /* special_function */
2002 AARCH64_R_STR (GLOB_DAT), /* name */
2003 TRUE, /* partial_inplace */
2004 0xffffffff, /* src_mask */
2005 0xffffffff, /* dst_mask */
2006 FALSE), /* pcrel_offset */
2008 HOWTO (AARCH64_R (JUMP_SLOT), /* type */
2010 2, /* size (0 = byte, 1 = short, 2 = long) */
2012 FALSE, /* pc_relative */
2014 complain_overflow_bitfield, /* complain_on_overflow */
2015 bfd_elf_generic_reloc, /* special_function */
2016 AARCH64_R_STR (JUMP_SLOT), /* name */
2017 TRUE, /* partial_inplace */
2018 0xffffffff, /* src_mask */
2019 0xffffffff, /* dst_mask */
2020 FALSE), /* pcrel_offset */
2022 HOWTO (AARCH64_R (RELATIVE), /* type */
2024 2, /* size (0 = byte, 1 = short, 2 = long) */
2026 FALSE, /* pc_relative */
2028 complain_overflow_bitfield, /* complain_on_overflow */
2029 bfd_elf_generic_reloc, /* special_function */
2030 AARCH64_R_STR (RELATIVE), /* name */
2031 TRUE, /* partial_inplace */
2032 ALL_ONES, /* src_mask */
2033 ALL_ONES, /* dst_mask */
2034 FALSE), /* pcrel_offset */
2036 HOWTO (AARCH64_R (TLS_DTPMOD), /* type */
2038 2, /* size (0 = byte, 1 = short, 2 = long) */
2040 FALSE, /* pc_relative */
2042 complain_overflow_dont, /* complain_on_overflow */
2043 bfd_elf_generic_reloc, /* special_function */
2045 AARCH64_R_STR (TLS_DTPMOD64), /* name */
2047 AARCH64_R_STR (TLS_DTPMOD), /* name */
2049 FALSE, /* partial_inplace */
2051 ALL_ONES, /* dst_mask */
2052 FALSE), /* pc_reloffset */
2054 HOWTO (AARCH64_R (TLS_DTPREL), /* type */
2056 2, /* size (0 = byte, 1 = short, 2 = long) */
2058 FALSE, /* pc_relative */
2060 complain_overflow_dont, /* complain_on_overflow */
2061 bfd_elf_generic_reloc, /* special_function */
2063 AARCH64_R_STR (TLS_DTPREL64), /* name */
2065 AARCH64_R_STR (TLS_DTPREL), /* name */
2067 FALSE, /* partial_inplace */
2069 ALL_ONES, /* dst_mask */
2070 FALSE), /* pcrel_offset */
2072 HOWTO (AARCH64_R (TLS_TPREL), /* type */
2074 2, /* size (0 = byte, 1 = short, 2 = long) */
2076 FALSE, /* pc_relative */
2078 complain_overflow_dont, /* complain_on_overflow */
2079 bfd_elf_generic_reloc, /* special_function */
2081 AARCH64_R_STR (TLS_TPREL64), /* name */
2083 AARCH64_R_STR (TLS_TPREL), /* name */
2085 FALSE, /* partial_inplace */
2087 ALL_ONES, /* dst_mask */
2088 FALSE), /* pcrel_offset */
2090 HOWTO (AARCH64_R (TLSDESC), /* type */
2092 2, /* size (0 = byte, 1 = short, 2 = long) */
2094 FALSE, /* pc_relative */
2096 complain_overflow_dont, /* complain_on_overflow */
2097 bfd_elf_generic_reloc, /* special_function */
2098 AARCH64_R_STR (TLSDESC), /* name */
2099 FALSE, /* partial_inplace */
2101 ALL_ONES, /* dst_mask */
2102 FALSE), /* pcrel_offset */
2104 HOWTO (AARCH64_R (IRELATIVE), /* type */
2106 2, /* size (0 = byte, 1 = short, 2 = long) */
2108 FALSE, /* pc_relative */
2110 complain_overflow_bitfield, /* complain_on_overflow */
2111 bfd_elf_generic_reloc, /* special_function */
2112 AARCH64_R_STR (IRELATIVE), /* name */
2113 FALSE, /* partial_inplace */
2115 ALL_ONES, /* dst_mask */
2116 FALSE), /* pcrel_offset */
2121 static reloc_howto_type elfNN_aarch64_howto_none =
2122 HOWTO (R_AARCH64_NONE, /* type */
2124 3, /* size (0 = byte, 1 = short, 2 = long) */
2126 FALSE, /* pc_relative */
2128 complain_overflow_dont,/* complain_on_overflow */
2129 bfd_elf_generic_reloc, /* special_function */
2130 "R_AARCH64_NONE", /* name */
2131 FALSE, /* partial_inplace */
2134 FALSE); /* pcrel_offset */
2136 /* Given HOWTO, return the bfd internal relocation enumerator. */
2138 static bfd_reloc_code_real_type
2139 elfNN_aarch64_bfd_reloc_from_howto (reloc_howto_type *howto)
2142 = (int) ARRAY_SIZE (elfNN_aarch64_howto_table);
2143 const ptrdiff_t offset
2144 = howto - elfNN_aarch64_howto_table;
2146 if (offset > 0 && offset < size - 1)
2147 return BFD_RELOC_AARCH64_RELOC_START + offset;
2149 if (howto == &elfNN_aarch64_howto_none)
2150 return BFD_RELOC_AARCH64_NONE;
2152 return BFD_RELOC_AARCH64_RELOC_START;
2155 /* Given R_TYPE, return the bfd internal relocation enumerator. */
2157 static bfd_reloc_code_real_type
2158 elfNN_aarch64_bfd_reloc_from_type (bfd *abfd, unsigned int r_type)
2160 static bfd_boolean initialized_p = FALSE;
2161 /* Indexed by R_TYPE, values are offsets in the howto_table. */
2162 static unsigned int offsets[R_AARCH64_end];
2168 for (i = 1; i < ARRAY_SIZE (elfNN_aarch64_howto_table) - 1; ++i)
2169 if (elfNN_aarch64_howto_table[i].type != 0)
2170 offsets[elfNN_aarch64_howto_table[i].type] = i;
2172 initialized_p = TRUE;
2175 if (r_type == R_AARCH64_NONE || r_type == R_AARCH64_NULL)
2176 return BFD_RELOC_AARCH64_NONE;
2178 /* PR 17512: file: b371e70a. */
2179 if (r_type >= R_AARCH64_end)
2181 _bfd_error_handler (_("%pB: unsupported relocation type %#x"),
2183 bfd_set_error (bfd_error_bad_value);
2184 return BFD_RELOC_AARCH64_NONE;
2187 return BFD_RELOC_AARCH64_RELOC_START + offsets[r_type];
2190 struct elf_aarch64_reloc_map
2192 bfd_reloc_code_real_type from;
2193 bfd_reloc_code_real_type to;
2196 /* Map bfd generic reloc to AArch64-specific reloc. */
2197 static const struct elf_aarch64_reloc_map elf_aarch64_reloc_map[] =
2199 {BFD_RELOC_NONE, BFD_RELOC_AARCH64_NONE},
2201 /* Basic data relocations. */
2202 {BFD_RELOC_CTOR, BFD_RELOC_AARCH64_NN},
2203 {BFD_RELOC_64, BFD_RELOC_AARCH64_64},
2204 {BFD_RELOC_32, BFD_RELOC_AARCH64_32},
2205 {BFD_RELOC_16, BFD_RELOC_AARCH64_16},
2206 {BFD_RELOC_64_PCREL, BFD_RELOC_AARCH64_64_PCREL},
2207 {BFD_RELOC_32_PCREL, BFD_RELOC_AARCH64_32_PCREL},
2208 {BFD_RELOC_16_PCREL, BFD_RELOC_AARCH64_16_PCREL},
2211 /* Given the bfd internal relocation enumerator in CODE, return the
2212 corresponding howto entry. */
2214 static reloc_howto_type *
2215 elfNN_aarch64_howto_from_bfd_reloc (bfd_reloc_code_real_type code)
2219 /* Convert bfd generic reloc to AArch64-specific reloc. */
2220 if (code < BFD_RELOC_AARCH64_RELOC_START
2221 || code > BFD_RELOC_AARCH64_RELOC_END)
2222 for (i = 0; i < ARRAY_SIZE (elf_aarch64_reloc_map); i++)
2223 if (elf_aarch64_reloc_map[i].from == code)
2225 code = elf_aarch64_reloc_map[i].to;
2229 if (code > BFD_RELOC_AARCH64_RELOC_START
2230 && code < BFD_RELOC_AARCH64_RELOC_END)
2231 if (elfNN_aarch64_howto_table[code - BFD_RELOC_AARCH64_RELOC_START].type)
2232 return &elfNN_aarch64_howto_table[code - BFD_RELOC_AARCH64_RELOC_START];
2234 if (code == BFD_RELOC_AARCH64_NONE)
2235 return &elfNN_aarch64_howto_none;
2240 static reloc_howto_type *
2241 elfNN_aarch64_howto_from_type (bfd *abfd, unsigned int r_type)
2243 bfd_reloc_code_real_type val;
2244 reloc_howto_type *howto;
2249 bfd_set_error (bfd_error_bad_value);
2254 if (r_type == R_AARCH64_NONE)
2255 return &elfNN_aarch64_howto_none;
2257 val = elfNN_aarch64_bfd_reloc_from_type (abfd, r_type);
2258 howto = elfNN_aarch64_howto_from_bfd_reloc (val);
2263 bfd_set_error (bfd_error_bad_value);
2268 elfNN_aarch64_info_to_howto (bfd *abfd, arelent *bfd_reloc,
2269 Elf_Internal_Rela *elf_reloc)
2271 unsigned int r_type;
2273 r_type = ELFNN_R_TYPE (elf_reloc->r_info);
2274 bfd_reloc->howto = elfNN_aarch64_howto_from_type (abfd, r_type);
2276 if (bfd_reloc->howto == NULL)
2278 /* xgettext:c-format */
2279 _bfd_error_handler (_("%pB: unsupported relocation type %#x"), abfd, r_type);
2285 static reloc_howto_type *
2286 elfNN_aarch64_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED,
2287 bfd_reloc_code_real_type code)
2289 reloc_howto_type *howto = elfNN_aarch64_howto_from_bfd_reloc (code);
2294 bfd_set_error (bfd_error_bad_value);
2298 static reloc_howto_type *
2299 elfNN_aarch64_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED,
2304 for (i = 1; i < ARRAY_SIZE (elfNN_aarch64_howto_table) - 1; ++i)
2305 if (elfNN_aarch64_howto_table[i].name != NULL
2306 && strcasecmp (elfNN_aarch64_howto_table[i].name, r_name) == 0)
2307 return &elfNN_aarch64_howto_table[i];
2312 #define TARGET_LITTLE_SYM aarch64_elfNN_le_vec
2313 #define TARGET_LITTLE_NAME "elfNN-littleaarch64"
2314 #define TARGET_BIG_SYM aarch64_elfNN_be_vec
2315 #define TARGET_BIG_NAME "elfNN-bigaarch64"
2317 /* The linker script knows the section names for placement.
2318 The entry_names are used to do simple name mangling on the stubs.
2319 Given a function name, and its type, the stub can be found. The
2320 name can be changed. The only requirement is the %s be present. */
2321 #define STUB_ENTRY_NAME "__%s_veneer"
2323 /* The name of the dynamic interpreter. This is put in the .interp
2325 #define ELF_DYNAMIC_INTERPRETER "/lib/ld.so.1"
2327 #define AARCH64_MAX_FWD_BRANCH_OFFSET \
2328 (((1 << 25) - 1) << 2)
2329 #define AARCH64_MAX_BWD_BRANCH_OFFSET \
2332 #define AARCH64_MAX_ADRP_IMM ((1 << 20) - 1)
2333 #define AARCH64_MIN_ADRP_IMM (-(1 << 20))
2336 aarch64_valid_for_adrp_p (bfd_vma value, bfd_vma place)
2338 bfd_signed_vma offset = (bfd_signed_vma) (PG (value) - PG (place)) >> 12;
2339 return offset <= AARCH64_MAX_ADRP_IMM && offset >= AARCH64_MIN_ADRP_IMM;
2343 aarch64_valid_branch_p (bfd_vma value, bfd_vma place)
2345 bfd_signed_vma offset = (bfd_signed_vma) (value - place);
2346 return (offset <= AARCH64_MAX_FWD_BRANCH_OFFSET
2347 && offset >= AARCH64_MAX_BWD_BRANCH_OFFSET);
2350 static const uint32_t aarch64_adrp_branch_stub [] =
2352 0x90000010, /* adrp ip0, X */
2353 /* R_AARCH64_ADR_HI21_PCREL(X) */
2354 0x91000210, /* add ip0, ip0, :lo12:X */
2355 /* R_AARCH64_ADD_ABS_LO12_NC(X) */
2356 0xd61f0200, /* br ip0 */
2359 static const uint32_t aarch64_long_branch_stub[] =
2362 0x58000090, /* ldr ip0, 1f */
2364 0x18000090, /* ldr wip0, 1f */
2366 0x10000011, /* adr ip1, #0 */
2367 0x8b110210, /* add ip0, ip0, ip1 */
2368 0xd61f0200, /* br ip0 */
2369 0x00000000, /* 1: .xword or .word
2370 R_AARCH64_PRELNN(X) + 12
2375 static const uint32_t aarch64_erratum_835769_stub[] =
2377 0x00000000, /* Placeholder for multiply accumulate. */
2378 0x14000000, /* b <label> */
2381 static const uint32_t aarch64_erratum_843419_stub[] =
2383 0x00000000, /* Placeholder for LDR instruction. */
2384 0x14000000, /* b <label> */
2387 /* Section name for stubs is the associated section name plus this
2389 #define STUB_SUFFIX ".stub"
2391 enum elf_aarch64_stub_type
2394 aarch64_stub_adrp_branch,
2395 aarch64_stub_long_branch,
2396 aarch64_stub_erratum_835769_veneer,
2397 aarch64_stub_erratum_843419_veneer,
2400 struct elf_aarch64_stub_hash_entry
2402 /* Base hash table entry structure. */
2403 struct bfd_hash_entry root;
2405 /* The stub section. */
2408 /* Offset within stub_sec of the beginning of this stub. */
2409 bfd_vma stub_offset;
2411 /* Given the symbol's value and its section we can determine its final
2412 value when building the stubs (so the stub knows where to jump). */
2413 bfd_vma target_value;
2414 asection *target_section;
2416 enum elf_aarch64_stub_type stub_type;
2418 /* The symbol table entry, if any, that this was derived from. */
2419 struct elf_aarch64_link_hash_entry *h;
2421 /* Destination symbol type */
2422 unsigned char st_type;
2424 /* Where this stub is being called from, or, in the case of combined
2425 stub sections, the first input section in the group. */
2428 /* The name for the local symbol at the start of this stub. The
2429 stub name in the hash table has to be unique; this does not, so
2430 it can be friendlier. */
2433 /* The instruction which caused this stub to be generated (only valid for
2434 erratum 835769 workaround stubs at present). */
2435 uint32_t veneered_insn;
2437 /* In an erratum 843419 workaround stub, the ADRP instruction offset. */
2438 bfd_vma adrp_offset;
2441 /* Used to build a map of a section. This is required for mixed-endian
2444 typedef struct elf_elf_section_map
2449 elf_aarch64_section_map;
2452 typedef struct _aarch64_elf_section_data
2454 struct bfd_elf_section_data elf;
2455 unsigned int mapcount;
2456 unsigned int mapsize;
2457 elf_aarch64_section_map *map;
2459 _aarch64_elf_section_data;
2461 #define elf_aarch64_section_data(sec) \
2462 ((_aarch64_elf_section_data *) elf_section_data (sec))
2464 /* The size of the thread control block which is defined to be two pointers. */
2465 #define TCB_SIZE (ARCH_SIZE/8)*2
2467 struct elf_aarch64_local_symbol
2469 unsigned int got_type;
2470 bfd_signed_vma got_refcount;
2473 /* Offset of the GOTPLT entry reserved for the TLS descriptor. The
2474 offset is from the end of the jump table and reserved entries
2477 The magic value (bfd_vma) -1 indicates that an offset has not be
2479 bfd_vma tlsdesc_got_jump_table_offset;
2482 struct elf_aarch64_obj_tdata
2484 struct elf_obj_tdata root;
2486 /* local symbol descriptors */
2487 struct elf_aarch64_local_symbol *locals;
2489 /* Zero to warn when linking objects with incompatible enum sizes. */
2490 int no_enum_size_warning;
2492 /* Zero to warn when linking objects with incompatible wchar_t sizes. */
2493 int no_wchar_size_warning;
2495 /* All GNU_PROPERTY_AARCH64_FEATURE_1_AND properties. */
2496 uint32_t gnu_and_prop;
2498 /* Zero to warn when linking objects with incompatible
2499 GNU_PROPERTY_AARCH64_FEATURE_1_BTI. */
2502 /* PLT type based on security. */
2503 aarch64_plt_type plt_type;
2506 #define elf_aarch64_tdata(bfd) \
2507 ((struct elf_aarch64_obj_tdata *) (bfd)->tdata.any)
2509 #define elf_aarch64_locals(bfd) (elf_aarch64_tdata (bfd)->locals)
2511 #define is_aarch64_elf(bfd) \
2512 (bfd_get_flavour (bfd) == bfd_target_elf_flavour \
2513 && elf_tdata (bfd) != NULL \
2514 && elf_object_id (bfd) == AARCH64_ELF_DATA)
2517 elfNN_aarch64_mkobject (bfd *abfd)
2519 return bfd_elf_allocate_object (abfd, sizeof (struct elf_aarch64_obj_tdata),
2523 #define elf_aarch64_hash_entry(ent) \
2524 ((struct elf_aarch64_link_hash_entry *)(ent))
2526 #define GOT_UNKNOWN 0
2527 #define GOT_NORMAL 1
2528 #define GOT_TLS_GD 2
2529 #define GOT_TLS_IE 4
2530 #define GOT_TLSDESC_GD 8
2532 #define GOT_TLS_GD_ANY_P(type) ((type & GOT_TLS_GD) || (type & GOT_TLSDESC_GD))
2534 /* AArch64 ELF linker hash entry. */
2535 struct elf_aarch64_link_hash_entry
2537 struct elf_link_hash_entry root;
2539 /* Track dynamic relocs copied for this symbol. */
2540 struct elf_dyn_relocs *dyn_relocs;
2542 /* Since PLT entries have variable size, we need to record the
2543 index into .got.plt instead of recomputing it from the PLT
2545 bfd_signed_vma plt_got_offset;
2547 /* Bit mask representing the type of GOT entry(s) if any required by
2549 unsigned int got_type;
2551 /* A pointer to the most recently used stub hash entry against this
2553 struct elf_aarch64_stub_hash_entry *stub_cache;
2555 /* Offset of the GOTPLT entry reserved for the TLS descriptor. The offset
2556 is from the end of the jump table and reserved entries within the PLTGOT.
2558 The magic value (bfd_vma) -1 indicates that an offset has not
2560 bfd_vma tlsdesc_got_jump_table_offset;
2564 elfNN_aarch64_symbol_got_type (struct elf_link_hash_entry *h,
2566 unsigned long r_symndx)
2569 return elf_aarch64_hash_entry (h)->got_type;
2571 if (! elf_aarch64_locals (abfd))
2574 return elf_aarch64_locals (abfd)[r_symndx].got_type;
2577 /* Get the AArch64 elf linker hash table from a link_info structure. */
2578 #define elf_aarch64_hash_table(info) \
2579 ((struct elf_aarch64_link_hash_table *) ((info)->hash))
2581 #define aarch64_stub_hash_lookup(table, string, create, copy) \
2582 ((struct elf_aarch64_stub_hash_entry *) \
2583 bfd_hash_lookup ((table), (string), (create), (copy)))
2585 /* AArch64 ELF linker hash table. */
2586 struct elf_aarch64_link_hash_table
2588 /* The main hash table. */
2589 struct elf_link_hash_table root;
2591 /* Nonzero to force PIC branch veneers. */
2594 /* Fix erratum 835769. */
2595 int fix_erratum_835769;
2597 /* Fix erratum 843419. */
2598 int fix_erratum_843419;
2600 /* Enable ADRP->ADR rewrite for erratum 843419 workaround. */
2601 int fix_erratum_843419_adr;
2603 /* Don't apply link-time values for dynamic relocations. */
2604 int no_apply_dynamic_relocs;
2606 /* The number of bytes in the initial entry in the PLT. */
2607 bfd_size_type plt_header_size;
2609 /* The bytes of the initial PLT entry. */
2610 const bfd_byte *plt0_entry;
2612 /* The number of bytes in the subsequent PLT entries. */
2613 bfd_size_type plt_entry_size;
2615 /* The bytes of the subsequent PLT entry. */
2616 const bfd_byte *plt_entry;
2618 /* Small local sym cache. */
2619 struct sym_cache sym_cache;
2621 /* For convenience in allocate_dynrelocs. */
2624 /* The amount of space used by the reserved portion of the sgotplt
2625 section, plus whatever space is used by the jump slots. */
2626 bfd_vma sgotplt_jump_table_size;
2628 /* The stub hash table. */
2629 struct bfd_hash_table stub_hash_table;
2631 /* Linker stub bfd. */
2634 /* Linker call-backs. */
2635 asection *(*add_stub_section) (const char *, asection *);
2636 void (*layout_sections_again) (void);
2638 /* Array to keep track of which stub sections have been created, and
2639 information on stub grouping. */
2642 /* This is the section to which stubs in the group will be
2645 /* The stub section. */
2649 /* Assorted information used by elfNN_aarch64_size_stubs. */
2650 unsigned int bfd_count;
2651 unsigned int top_index;
2652 asection **input_list;
2654 /* The offset into splt of the PLT entry for the TLS descriptor
2655 resolver. Special values are 0, if not necessary (or not found
2656 to be necessary yet), and -1 if needed but not determined
2658 bfd_vma tlsdesc_plt;
2660 /* The number of bytes in the PLT enty for the TLS descriptor. */
2661 bfd_size_type tlsdesc_plt_entry_size;
2663 /* The GOT offset for the lazy trampoline. Communicated to the
2664 loader via DT_TLSDESC_GOT. The magic value (bfd_vma) -1
2665 indicates an offset is not allocated. */
2666 bfd_vma dt_tlsdesc_got;
2668 /* Used by local STT_GNU_IFUNC symbols. */
2669 htab_t loc_hash_table;
2670 void * loc_hash_memory;
2673 /* Create an entry in an AArch64 ELF linker hash table. */
2675 static struct bfd_hash_entry *
2676 elfNN_aarch64_link_hash_newfunc (struct bfd_hash_entry *entry,
2677 struct bfd_hash_table *table,
2680 struct elf_aarch64_link_hash_entry *ret =
2681 (struct elf_aarch64_link_hash_entry *) entry;
2683 /* Allocate the structure if it has not already been allocated by a
2686 ret = bfd_hash_allocate (table,
2687 sizeof (struct elf_aarch64_link_hash_entry));
2689 return (struct bfd_hash_entry *) ret;
2691 /* Call the allocation method of the superclass. */
2692 ret = ((struct elf_aarch64_link_hash_entry *)
2693 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry *) ret,
2697 ret->dyn_relocs = NULL;
2698 ret->got_type = GOT_UNKNOWN;
2699 ret->plt_got_offset = (bfd_vma) - 1;
2700 ret->stub_cache = NULL;
2701 ret->tlsdesc_got_jump_table_offset = (bfd_vma) - 1;
2704 return (struct bfd_hash_entry *) ret;
2707 /* Initialize an entry in the stub hash table. */
2709 static struct bfd_hash_entry *
2710 stub_hash_newfunc (struct bfd_hash_entry *entry,
2711 struct bfd_hash_table *table, const char *string)
2713 /* Allocate the structure if it has not already been allocated by a
2717 entry = bfd_hash_allocate (table,
2719 elf_aarch64_stub_hash_entry));
2724 /* Call the allocation method of the superclass. */
2725 entry = bfd_hash_newfunc (entry, table, string);
2728 struct elf_aarch64_stub_hash_entry *eh;
2730 /* Initialize the local fields. */
2731 eh = (struct elf_aarch64_stub_hash_entry *) entry;
2732 eh->adrp_offset = 0;
2733 eh->stub_sec = NULL;
2734 eh->stub_offset = 0;
2735 eh->target_value = 0;
2736 eh->target_section = NULL;
2737 eh->stub_type = aarch64_stub_none;
2745 /* Compute a hash of a local hash entry. We use elf_link_hash_entry
2746 for local symbol so that we can handle local STT_GNU_IFUNC symbols
2747 as global symbol. We reuse indx and dynstr_index for local symbol
2748 hash since they aren't used by global symbols in this backend. */
2751 elfNN_aarch64_local_htab_hash (const void *ptr)
2753 struct elf_link_hash_entry *h
2754 = (struct elf_link_hash_entry *) ptr;
2755 return ELF_LOCAL_SYMBOL_HASH (h->indx, h->dynstr_index);
2758 /* Compare local hash entries. */
2761 elfNN_aarch64_local_htab_eq (const void *ptr1, const void *ptr2)
2763 struct elf_link_hash_entry *h1
2764 = (struct elf_link_hash_entry *) ptr1;
2765 struct elf_link_hash_entry *h2
2766 = (struct elf_link_hash_entry *) ptr2;
2768 return h1->indx == h2->indx && h1->dynstr_index == h2->dynstr_index;
2771 /* Find and/or create a hash entry for local symbol. */
2773 static struct elf_link_hash_entry *
2774 elfNN_aarch64_get_local_sym_hash (struct elf_aarch64_link_hash_table *htab,
2775 bfd *abfd, const Elf_Internal_Rela *rel,
2778 struct elf_aarch64_link_hash_entry e, *ret;
2779 asection *sec = abfd->sections;
2780 hashval_t h = ELF_LOCAL_SYMBOL_HASH (sec->id,
2781 ELFNN_R_SYM (rel->r_info));
2784 e.root.indx = sec->id;
2785 e.root.dynstr_index = ELFNN_R_SYM (rel->r_info);
2786 slot = htab_find_slot_with_hash (htab->loc_hash_table, &e, h,
2787 create ? INSERT : NO_INSERT);
2794 ret = (struct elf_aarch64_link_hash_entry *) *slot;
2798 ret = (struct elf_aarch64_link_hash_entry *)
2799 objalloc_alloc ((struct objalloc *) htab->loc_hash_memory,
2800 sizeof (struct elf_aarch64_link_hash_entry));
2803 memset (ret, 0, sizeof (*ret));
2804 ret->root.indx = sec->id;
2805 ret->root.dynstr_index = ELFNN_R_SYM (rel->r_info);
2806 ret->root.dynindx = -1;
2812 /* Copy the extra info we tack onto an elf_link_hash_entry. */
2815 elfNN_aarch64_copy_indirect_symbol (struct bfd_link_info *info,
2816 struct elf_link_hash_entry *dir,
2817 struct elf_link_hash_entry *ind)
2819 struct elf_aarch64_link_hash_entry *edir, *eind;
2821 edir = (struct elf_aarch64_link_hash_entry *) dir;
2822 eind = (struct elf_aarch64_link_hash_entry *) ind;
2824 if (eind->dyn_relocs != NULL)
2826 if (edir->dyn_relocs != NULL)
2828 struct elf_dyn_relocs **pp;
2829 struct elf_dyn_relocs *p;
2831 /* Add reloc counts against the indirect sym to the direct sym
2832 list. Merge any entries against the same section. */
2833 for (pp = &eind->dyn_relocs; (p = *pp) != NULL;)
2835 struct elf_dyn_relocs *q;
2837 for (q = edir->dyn_relocs; q != NULL; q = q->next)
2838 if (q->sec == p->sec)
2840 q->pc_count += p->pc_count;
2841 q->count += p->count;
2848 *pp = edir->dyn_relocs;
2851 edir->dyn_relocs = eind->dyn_relocs;
2852 eind->dyn_relocs = NULL;
2855 if (ind->root.type == bfd_link_hash_indirect)
2857 /* Copy over PLT info. */
2858 if (dir->got.refcount <= 0)
2860 edir->got_type = eind->got_type;
2861 eind->got_type = GOT_UNKNOWN;
2865 _bfd_elf_link_hash_copy_indirect (info, dir, ind);
2868 /* Destroy an AArch64 elf linker hash table. */
2871 elfNN_aarch64_link_hash_table_free (bfd *obfd)
2873 struct elf_aarch64_link_hash_table *ret
2874 = (struct elf_aarch64_link_hash_table *) obfd->link.hash;
2876 if (ret->loc_hash_table)
2877 htab_delete (ret->loc_hash_table);
2878 if (ret->loc_hash_memory)
2879 objalloc_free ((struct objalloc *) ret->loc_hash_memory);
2881 bfd_hash_table_free (&ret->stub_hash_table);
2882 _bfd_elf_link_hash_table_free (obfd);
2885 /* Create an AArch64 elf linker hash table. */
2887 static struct bfd_link_hash_table *
2888 elfNN_aarch64_link_hash_table_create (bfd *abfd)
2890 struct elf_aarch64_link_hash_table *ret;
2891 bfd_size_type amt = sizeof (struct elf_aarch64_link_hash_table);
2893 ret = bfd_zmalloc (amt);
2897 if (!_bfd_elf_link_hash_table_init
2898 (&ret->root, abfd, elfNN_aarch64_link_hash_newfunc,
2899 sizeof (struct elf_aarch64_link_hash_entry), AARCH64_ELF_DATA))
2905 ret->plt_header_size = PLT_ENTRY_SIZE;
2906 ret->plt0_entry = elfNN_aarch64_small_plt0_entry;
2907 ret->plt_entry_size = PLT_SMALL_ENTRY_SIZE;
2908 ret->plt_entry = elfNN_aarch64_small_plt_entry;
2909 ret->tlsdesc_plt_entry_size = PLT_TLSDESC_ENTRY_SIZE;
2911 ret->dt_tlsdesc_got = (bfd_vma) - 1;
2913 if (!bfd_hash_table_init (&ret->stub_hash_table, stub_hash_newfunc,
2914 sizeof (struct elf_aarch64_stub_hash_entry)))
2916 _bfd_elf_link_hash_table_free (abfd);
2920 ret->loc_hash_table = htab_try_create (1024,
2921 elfNN_aarch64_local_htab_hash,
2922 elfNN_aarch64_local_htab_eq,
2924 ret->loc_hash_memory = objalloc_create ();
2925 if (!ret->loc_hash_table || !ret->loc_hash_memory)
2927 elfNN_aarch64_link_hash_table_free (abfd);
2930 ret->root.root.hash_table_free = elfNN_aarch64_link_hash_table_free;
2932 return &ret->root.root;
2935 /* Perform relocation R_TYPE. Returns TRUE upon success, FALSE otherwise. */
2938 aarch64_relocate (unsigned int r_type, bfd *input_bfd, asection *input_section,
2939 bfd_vma offset, bfd_vma value)
2941 reloc_howto_type *howto;
2944 howto = elfNN_aarch64_howto_from_type (input_bfd, r_type);
2945 place = (input_section->output_section->vma + input_section->output_offset
2948 r_type = elfNN_aarch64_bfd_reloc_from_type (input_bfd, r_type);
2949 value = _bfd_aarch64_elf_resolve_relocation (r_type, place, value, 0, FALSE);
2950 return _bfd_aarch64_elf_put_addend (input_bfd,
2951 input_section->contents + offset, r_type,
2952 howto, value) == bfd_reloc_ok;
2955 static enum elf_aarch64_stub_type
2956 aarch64_select_branch_stub (bfd_vma value, bfd_vma place)
2958 if (aarch64_valid_for_adrp_p (value, place))
2959 return aarch64_stub_adrp_branch;
2960 return aarch64_stub_long_branch;
2963 /* Determine the type of stub needed, if any, for a call. */
2965 static enum elf_aarch64_stub_type
2966 aarch64_type_of_stub (asection *input_sec,
2967 const Elf_Internal_Rela *rel,
2969 unsigned char st_type,
2970 bfd_vma destination)
2973 bfd_signed_vma branch_offset;
2974 unsigned int r_type;
2975 enum elf_aarch64_stub_type stub_type = aarch64_stub_none;
2977 if (st_type != STT_FUNC
2978 && (sym_sec == input_sec))
2981 /* Determine where the call point is. */
2982 location = (input_sec->output_offset
2983 + input_sec->output_section->vma + rel->r_offset);
2985 branch_offset = (bfd_signed_vma) (destination - location);
2987 r_type = ELFNN_R_TYPE (rel->r_info);
2989 /* We don't want to redirect any old unconditional jump in this way,
2990 only one which is being used for a sibcall, where it is
2991 acceptable for the IP0 and IP1 registers to be clobbered. */
2992 if ((r_type == AARCH64_R (CALL26) || r_type == AARCH64_R (JUMP26))
2993 && (branch_offset > AARCH64_MAX_FWD_BRANCH_OFFSET
2994 || branch_offset < AARCH64_MAX_BWD_BRANCH_OFFSET))
2996 stub_type = aarch64_stub_long_branch;
3002 /* Build a name for an entry in the stub hash table. */
3005 elfNN_aarch64_stub_name (const asection *input_section,
3006 const asection *sym_sec,
3007 const struct elf_aarch64_link_hash_entry *hash,
3008 const Elf_Internal_Rela *rel)
3015 len = 8 + 1 + strlen (hash->root.root.root.string) + 1 + 16 + 1;
3016 stub_name = bfd_malloc (len);
3017 if (stub_name != NULL)
3018 snprintf (stub_name, len, "%08x_%s+%" BFD_VMA_FMT "x",
3019 (unsigned int) input_section->id,
3020 hash->root.root.root.string,
3025 len = 8 + 1 + 8 + 1 + 8 + 1 + 16 + 1;
3026 stub_name = bfd_malloc (len);
3027 if (stub_name != NULL)
3028 snprintf (stub_name, len, "%08x_%x:%x+%" BFD_VMA_FMT "x",
3029 (unsigned int) input_section->id,
3030 (unsigned int) sym_sec->id,
3031 (unsigned int) ELFNN_R_SYM (rel->r_info),
3038 /* Return TRUE if symbol H should be hashed in the `.gnu.hash' section. For
3039 executable PLT slots where the executable never takes the address of those
3040 functions, the function symbols are not added to the hash table. */
3043 elf_aarch64_hash_symbol (struct elf_link_hash_entry *h)
3045 if (h->plt.offset != (bfd_vma) -1
3047 && !h->pointer_equality_needed)
3050 return _bfd_elf_hash_symbol (h);
3054 /* Look up an entry in the stub hash. Stub entries are cached because
3055 creating the stub name takes a bit of time. */
3057 static struct elf_aarch64_stub_hash_entry *
3058 elfNN_aarch64_get_stub_entry (const asection *input_section,
3059 const asection *sym_sec,
3060 struct elf_link_hash_entry *hash,
3061 const Elf_Internal_Rela *rel,
3062 struct elf_aarch64_link_hash_table *htab)
3064 struct elf_aarch64_stub_hash_entry *stub_entry;
3065 struct elf_aarch64_link_hash_entry *h =
3066 (struct elf_aarch64_link_hash_entry *) hash;
3067 const asection *id_sec;
3069 if ((input_section->flags & SEC_CODE) == 0)
3072 /* If this input section is part of a group of sections sharing one
3073 stub section, then use the id of the first section in the group.
3074 Stub names need to include a section id, as there may well be
3075 more than one stub used to reach say, printf, and we need to
3076 distinguish between them. */
3077 id_sec = htab->stub_group[input_section->id].link_sec;
3079 if (h != NULL && h->stub_cache != NULL
3080 && h->stub_cache->h == h && h->stub_cache->id_sec == id_sec)
3082 stub_entry = h->stub_cache;
3088 stub_name = elfNN_aarch64_stub_name (id_sec, sym_sec, h, rel);
3089 if (stub_name == NULL)
3092 stub_entry = aarch64_stub_hash_lookup (&htab->stub_hash_table,
3093 stub_name, FALSE, FALSE);
3095 h->stub_cache = stub_entry;
3104 /* Create a stub section. */
3107 _bfd_aarch64_create_stub_section (asection *section,
3108 struct elf_aarch64_link_hash_table *htab)
3114 namelen = strlen (section->name);
3115 len = namelen + sizeof (STUB_SUFFIX);
3116 s_name = bfd_alloc (htab->stub_bfd, len);
3120 memcpy (s_name, section->name, namelen);
3121 memcpy (s_name + namelen, STUB_SUFFIX, sizeof (STUB_SUFFIX));
3122 return (*htab->add_stub_section) (s_name, section);
3126 /* Find or create a stub section for a link section.
3128 Fix or create the stub section used to collect stubs attached to
3129 the specified link section. */
3132 _bfd_aarch64_get_stub_for_link_section (asection *link_section,
3133 struct elf_aarch64_link_hash_table *htab)
3135 if (htab->stub_group[link_section->id].stub_sec == NULL)
3136 htab->stub_group[link_section->id].stub_sec
3137 = _bfd_aarch64_create_stub_section (link_section, htab);
3138 return htab->stub_group[link_section->id].stub_sec;
3142 /* Find or create a stub section in the stub group for an input
3146 _bfd_aarch64_create_or_find_stub_sec (asection *section,
3147 struct elf_aarch64_link_hash_table *htab)
3149 asection *link_sec = htab->stub_group[section->id].link_sec;
3150 return _bfd_aarch64_get_stub_for_link_section (link_sec, htab);
3154 /* Add a new stub entry in the stub group associated with an input
3155 section to the stub hash. Not all fields of the new stub entry are
3158 static struct elf_aarch64_stub_hash_entry *
3159 _bfd_aarch64_add_stub_entry_in_group (const char *stub_name,
3161 struct elf_aarch64_link_hash_table *htab)
3165 struct elf_aarch64_stub_hash_entry *stub_entry;
3167 link_sec = htab->stub_group[section->id].link_sec;
3168 stub_sec = _bfd_aarch64_create_or_find_stub_sec (section, htab);
3170 /* Enter this entry into the linker stub hash table. */
3171 stub_entry = aarch64_stub_hash_lookup (&htab->stub_hash_table, stub_name,
3173 if (stub_entry == NULL)
3175 /* xgettext:c-format */
3176 _bfd_error_handler (_("%pB: cannot create stub entry %s"),
3177 section->owner, stub_name);
3181 stub_entry->stub_sec = stub_sec;
3182 stub_entry->stub_offset = 0;
3183 stub_entry->id_sec = link_sec;
3188 /* Add a new stub entry in the final stub section to the stub hash.
3189 Not all fields of the new stub entry are initialised. */
3191 static struct elf_aarch64_stub_hash_entry *
3192 _bfd_aarch64_add_stub_entry_after (const char *stub_name,
3193 asection *link_section,
3194 struct elf_aarch64_link_hash_table *htab)
3197 struct elf_aarch64_stub_hash_entry *stub_entry;
3199 stub_sec = _bfd_aarch64_get_stub_for_link_section (link_section, htab);
3200 stub_entry = aarch64_stub_hash_lookup (&htab->stub_hash_table, stub_name,
3202 if (stub_entry == NULL)
3204 _bfd_error_handler (_("cannot create stub entry %s"), stub_name);
3208 stub_entry->stub_sec = stub_sec;
3209 stub_entry->stub_offset = 0;
3210 stub_entry->id_sec = link_section;
3217 aarch64_build_one_stub (struct bfd_hash_entry *gen_entry,
3218 void *in_arg ATTRIBUTE_UNUSED)
3220 struct elf_aarch64_stub_hash_entry *stub_entry;
3225 bfd_vma veneered_insn_loc;
3226 bfd_vma veneer_entry_loc;
3227 bfd_signed_vma branch_offset = 0;
3228 unsigned int template_size;
3229 const uint32_t *template;
3232 /* Massage our args to the form they really have. */
3233 stub_entry = (struct elf_aarch64_stub_hash_entry *) gen_entry;
3235 stub_sec = stub_entry->stub_sec;
3237 /* Make a note of the offset within the stubs for this entry. */
3238 stub_entry->stub_offset = stub_sec->size;
3239 loc = stub_sec->contents + stub_entry->stub_offset;
3241 stub_bfd = stub_sec->owner;
3243 /* This is the address of the stub destination. */
3244 sym_value = (stub_entry->target_value
3245 + stub_entry->target_section->output_offset
3246 + stub_entry->target_section->output_section->vma);
3248 if (stub_entry->stub_type == aarch64_stub_long_branch)
3250 bfd_vma place = (stub_entry->stub_offset + stub_sec->output_section->vma
3251 + stub_sec->output_offset);
3253 /* See if we can relax the stub. */
3254 if (aarch64_valid_for_adrp_p (sym_value, place))
3255 stub_entry->stub_type = aarch64_select_branch_stub (sym_value, place);
3258 switch (stub_entry->stub_type)
3260 case aarch64_stub_adrp_branch:
3261 template = aarch64_adrp_branch_stub;
3262 template_size = sizeof (aarch64_adrp_branch_stub);
3264 case aarch64_stub_long_branch:
3265 template = aarch64_long_branch_stub;
3266 template_size = sizeof (aarch64_long_branch_stub);
3268 case aarch64_stub_erratum_835769_veneer:
3269 template = aarch64_erratum_835769_stub;
3270 template_size = sizeof (aarch64_erratum_835769_stub);
3272 case aarch64_stub_erratum_843419_veneer:
3273 template = aarch64_erratum_843419_stub;
3274 template_size = sizeof (aarch64_erratum_843419_stub);
3280 for (i = 0; i < (template_size / sizeof template[0]); i++)
3282 bfd_putl32 (template[i], loc);
3286 template_size = (template_size + 7) & ~7;
3287 stub_sec->size += template_size;
3289 switch (stub_entry->stub_type)
3291 case aarch64_stub_adrp_branch:
3292 if (!aarch64_relocate (AARCH64_R (ADR_PREL_PG_HI21), stub_bfd, stub_sec,
3293 stub_entry->stub_offset, sym_value))
3294 /* The stub would not have been relaxed if the offset was out
3298 if (!aarch64_relocate (AARCH64_R (ADD_ABS_LO12_NC), stub_bfd, stub_sec,
3299 stub_entry->stub_offset + 4, sym_value))
3303 case aarch64_stub_long_branch:
3304 /* We want the value relative to the address 12 bytes back from the
3306 if (!aarch64_relocate (AARCH64_R (PRELNN), stub_bfd, stub_sec,
3307 stub_entry->stub_offset + 16, sym_value + 12))
3311 case aarch64_stub_erratum_835769_veneer:
3312 veneered_insn_loc = stub_entry->target_section->output_section->vma
3313 + stub_entry->target_section->output_offset
3314 + stub_entry->target_value;
3315 veneer_entry_loc = stub_entry->stub_sec->output_section->vma
3316 + stub_entry->stub_sec->output_offset
3317 + stub_entry->stub_offset;
3318 branch_offset = veneered_insn_loc - veneer_entry_loc;
3319 branch_offset >>= 2;
3320 branch_offset &= 0x3ffffff;
3321 bfd_putl32 (stub_entry->veneered_insn,
3322 stub_sec->contents + stub_entry->stub_offset);
3323 bfd_putl32 (template[1] | branch_offset,
3324 stub_sec->contents + stub_entry->stub_offset + 4);
3327 case aarch64_stub_erratum_843419_veneer:
3328 if (!aarch64_relocate (AARCH64_R (JUMP26), stub_bfd, stub_sec,
3329 stub_entry->stub_offset + 4, sym_value + 4))
3340 /* As above, but don't actually build the stub. Just bump offset so
3341 we know stub section sizes. */
3344 aarch64_size_one_stub (struct bfd_hash_entry *gen_entry,
3345 void *in_arg ATTRIBUTE_UNUSED)
3347 struct elf_aarch64_stub_hash_entry *stub_entry;
3350 /* Massage our args to the form they really have. */
3351 stub_entry = (struct elf_aarch64_stub_hash_entry *) gen_entry;
3353 switch (stub_entry->stub_type)
3355 case aarch64_stub_adrp_branch:
3356 size = sizeof (aarch64_adrp_branch_stub);
3358 case aarch64_stub_long_branch:
3359 size = sizeof (aarch64_long_branch_stub);
3361 case aarch64_stub_erratum_835769_veneer:
3362 size = sizeof (aarch64_erratum_835769_stub);
3364 case aarch64_stub_erratum_843419_veneer:
3365 size = sizeof (aarch64_erratum_843419_stub);
3371 size = (size + 7) & ~7;
3372 stub_entry->stub_sec->size += size;
3376 /* External entry points for sizing and building linker stubs. */
3378 /* Set up various things so that we can make a list of input sections
3379 for each output section included in the link. Returns -1 on error,
3380 0 when no stubs will be needed, and 1 on success. */
3383 elfNN_aarch64_setup_section_lists (bfd *output_bfd,
3384 struct bfd_link_info *info)
3387 unsigned int bfd_count;
3388 unsigned int top_id, top_index;
3390 asection **input_list, **list;
3392 struct elf_aarch64_link_hash_table *htab =
3393 elf_aarch64_hash_table (info);
3395 if (!is_elf_hash_table (htab))
3398 /* Count the number of input BFDs and find the top input section id. */
3399 for (input_bfd = info->input_bfds, bfd_count = 0, top_id = 0;
3400 input_bfd != NULL; input_bfd = input_bfd->link.next)
3403 for (section = input_bfd->sections;
3404 section != NULL; section = section->next)
3406 if (top_id < section->id)
3407 top_id = section->id;
3410 htab->bfd_count = bfd_count;
3412 amt = sizeof (struct map_stub) * (top_id + 1);
3413 htab->stub_group = bfd_zmalloc (amt);
3414 if (htab->stub_group == NULL)
3417 /* We can't use output_bfd->section_count here to find the top output
3418 section index as some sections may have been removed, and
3419 _bfd_strip_section_from_output doesn't renumber the indices. */
3420 for (section = output_bfd->sections, top_index = 0;
3421 section != NULL; section = section->next)
3423 if (top_index < section->index)
3424 top_index = section->index;
3427 htab->top_index = top_index;
3428 amt = sizeof (asection *) * (top_index + 1);
3429 input_list = bfd_malloc (amt);
3430 htab->input_list = input_list;
3431 if (input_list == NULL)
3434 /* For sections we aren't interested in, mark their entries with a
3435 value we can check later. */
3436 list = input_list + top_index;
3438 *list = bfd_abs_section_ptr;
3439 while (list-- != input_list);
3441 for (section = output_bfd->sections;
3442 section != NULL; section = section->next)
3444 if ((section->flags & SEC_CODE) != 0)
3445 input_list[section->index] = NULL;
3451 /* Used by elfNN_aarch64_next_input_section and group_sections. */
3452 #define PREV_SEC(sec) (htab->stub_group[(sec)->id].link_sec)
3454 /* The linker repeatedly calls this function for each input section,
3455 in the order that input sections are linked into output sections.
3456 Build lists of input sections to determine groupings between which
3457 we may insert linker stubs. */
3460 elfNN_aarch64_next_input_section (struct bfd_link_info *info, asection *isec)
3462 struct elf_aarch64_link_hash_table *htab =
3463 elf_aarch64_hash_table (info);
3465 if (isec->output_section->index <= htab->top_index)
3467 asection **list = htab->input_list + isec->output_section->index;
3469 if (*list != bfd_abs_section_ptr)
3471 /* Steal the link_sec pointer for our list. */
3472 /* This happens to make the list in reverse order,
3473 which is what we want. */
3474 PREV_SEC (isec) = *list;
3480 /* See whether we can group stub sections together. Grouping stub
3481 sections may result in fewer stubs. More importantly, we need to
3482 put all .init* and .fini* stubs at the beginning of the .init or
3483 .fini output sections respectively, because glibc splits the
3484 _init and _fini functions into multiple parts. Putting a stub in
3485 the middle of a function is not a good idea. */
3488 group_sections (struct elf_aarch64_link_hash_table *htab,
3489 bfd_size_type stub_group_size,
3490 bfd_boolean stubs_always_before_branch)
3492 asection **list = htab->input_list + htab->top_index;
3496 asection *tail = *list;
3498 if (tail == bfd_abs_section_ptr)
3501 while (tail != NULL)
3505 bfd_size_type total;
3509 while ((prev = PREV_SEC (curr)) != NULL
3510 && ((total += curr->output_offset - prev->output_offset)
3514 /* OK, the size from the start of CURR to the end is less
3515 than stub_group_size and thus can be handled by one stub
3516 section. (Or the tail section is itself larger than
3517 stub_group_size, in which case we may be toast.)
3518 We should really be keeping track of the total size of
3519 stubs added here, as stubs contribute to the final output
3523 prev = PREV_SEC (tail);
3524 /* Set up this stub group. */
3525 htab->stub_group[tail->id].link_sec = curr;
3527 while (tail != curr && (tail = prev) != NULL);
3529 /* But wait, there's more! Input sections up to stub_group_size
3530 bytes before the stub section can be handled by it too. */
3531 if (!stubs_always_before_branch)
3535 && ((total += tail->output_offset - prev->output_offset)
3539 prev = PREV_SEC (tail);
3540 htab->stub_group[tail->id].link_sec = curr;
3546 while (list-- != htab->input_list);
3548 free (htab->input_list);
3553 #define AARCH64_BITS(x, pos, n) (((x) >> (pos)) & ((1 << (n)) - 1))
3555 #define AARCH64_RT(insn) AARCH64_BITS (insn, 0, 5)
3556 #define AARCH64_RT2(insn) AARCH64_BITS (insn, 10, 5)
3557 #define AARCH64_RA(insn) AARCH64_BITS (insn, 10, 5)
3558 #define AARCH64_RD(insn) AARCH64_BITS (insn, 0, 5)
3559 #define AARCH64_RN(insn) AARCH64_BITS (insn, 5, 5)
3560 #define AARCH64_RM(insn) AARCH64_BITS (insn, 16, 5)
3562 #define AARCH64_MAC(insn) (((insn) & 0xff000000) == 0x9b000000)
3563 #define AARCH64_BIT(insn, n) AARCH64_BITS (insn, n, 1)
3564 #define AARCH64_OP31(insn) AARCH64_BITS (insn, 21, 3)
3565 #define AARCH64_ZR 0x1f
3567 /* All ld/st ops. See C4-182 of the ARM ARM. The encoding space for
3568 LD_PCREL, LDST_RO, LDST_UI and LDST_UIMM cover prefetch ops. */
3570 #define AARCH64_LD(insn) (AARCH64_BIT (insn, 22) == 1)
3571 #define AARCH64_LDST(insn) (((insn) & 0x0a000000) == 0x08000000)
3572 #define AARCH64_LDST_EX(insn) (((insn) & 0x3f000000) == 0x08000000)
3573 #define AARCH64_LDST_PCREL(insn) (((insn) & 0x3b000000) == 0x18000000)
3574 #define AARCH64_LDST_NAP(insn) (((insn) & 0x3b800000) == 0x28000000)
3575 #define AARCH64_LDSTP_PI(insn) (((insn) & 0x3b800000) == 0x28800000)
3576 #define AARCH64_LDSTP_O(insn) (((insn) & 0x3b800000) == 0x29000000)
3577 #define AARCH64_LDSTP_PRE(insn) (((insn) & 0x3b800000) == 0x29800000)
3578 #define AARCH64_LDST_UI(insn) (((insn) & 0x3b200c00) == 0x38000000)
3579 #define AARCH64_LDST_PIIMM(insn) (((insn) & 0x3b200c00) == 0x38000400)
3580 #define AARCH64_LDST_U(insn) (((insn) & 0x3b200c00) == 0x38000800)
3581 #define AARCH64_LDST_PREIMM(insn) (((insn) & 0x3b200c00) == 0x38000c00)
3582 #define AARCH64_LDST_RO(insn) (((insn) & 0x3b200c00) == 0x38200800)
3583 #define AARCH64_LDST_UIMM(insn) (((insn) & 0x3b000000) == 0x39000000)
3584 #define AARCH64_LDST_SIMD_M(insn) (((insn) & 0xbfbf0000) == 0x0c000000)
3585 #define AARCH64_LDST_SIMD_M_PI(insn) (((insn) & 0xbfa00000) == 0x0c800000)
3586 #define AARCH64_LDST_SIMD_S(insn) (((insn) & 0xbf9f0000) == 0x0d000000)
3587 #define AARCH64_LDST_SIMD_S_PI(insn) (((insn) & 0xbf800000) == 0x0d800000)
3589 /* Classify an INSN if it is indeed a load/store.
3591 Return TRUE if INSN is a LD/ST instruction otherwise return FALSE.
3593 For scalar LD/ST instructions PAIR is FALSE, RT is returned and RT2
3596 For LD/ST pair instructions PAIR is TRUE, RT and RT2 are returned. */
3599 aarch64_mem_op_p (uint32_t insn, unsigned int *rt, unsigned int *rt2,
3600 bfd_boolean *pair, bfd_boolean *load)
3608 /* Bail out quickly if INSN doesn't fall into the load-store
3610 if (!AARCH64_LDST (insn))
3615 if (AARCH64_LDST_EX (insn))
3617 *rt = AARCH64_RT (insn);
3619 if (AARCH64_BIT (insn, 21) == 1)
3622 *rt2 = AARCH64_RT2 (insn);
3624 *load = AARCH64_LD (insn);
3627 else if (AARCH64_LDST_NAP (insn)
3628 || AARCH64_LDSTP_PI (insn)
3629 || AARCH64_LDSTP_O (insn)
3630 || AARCH64_LDSTP_PRE (insn))
3633 *rt = AARCH64_RT (insn);
3634 *rt2 = AARCH64_RT2 (insn);
3635 *load = AARCH64_LD (insn);
3638 else if (AARCH64_LDST_PCREL (insn)
3639 || AARCH64_LDST_UI (insn)
3640 || AARCH64_LDST_PIIMM (insn)
3641 || AARCH64_LDST_U (insn)
3642 || AARCH64_LDST_PREIMM (insn)
3643 || AARCH64_LDST_RO (insn)
3644 || AARCH64_LDST_UIMM (insn))
3646 *rt = AARCH64_RT (insn);
3648 if (AARCH64_LDST_PCREL (insn))
3650 opc = AARCH64_BITS (insn, 22, 2);
3651 v = AARCH64_BIT (insn, 26);
3652 opc_v = opc | (v << 2);
3653 *load = (opc_v == 1 || opc_v == 2 || opc_v == 3
3654 || opc_v == 5 || opc_v == 7);
3657 else if (AARCH64_LDST_SIMD_M (insn)
3658 || AARCH64_LDST_SIMD_M_PI (insn))
3660 *rt = AARCH64_RT (insn);
3661 *load = AARCH64_BIT (insn, 22);
3662 opcode = (insn >> 12) & 0xf;
3689 else if (AARCH64_LDST_SIMD_S (insn)
3690 || AARCH64_LDST_SIMD_S_PI (insn))
3692 *rt = AARCH64_RT (insn);
3693 r = (insn >> 21) & 1;
3694 *load = AARCH64_BIT (insn, 22);
3695 opcode = (insn >> 13) & 0x7;
3707 *rt2 = *rt + (r == 0 ? 2 : 3);
3715 *rt2 = *rt + (r == 0 ? 2 : 3);
3727 /* Return TRUE if INSN is multiply-accumulate. */
3730 aarch64_mlxl_p (uint32_t insn)
3732 uint32_t op31 = AARCH64_OP31 (insn);
3734 if (AARCH64_MAC (insn)
3735 && (op31 == 0 || op31 == 1 || op31 == 5)
3736 /* Exclude MUL instructions which are encoded as a multiple accumulate
3738 && AARCH64_RA (insn) != AARCH64_ZR)
3744 /* Some early revisions of the Cortex-A53 have an erratum (835769) whereby
3745 it is possible for a 64-bit multiply-accumulate instruction to generate an
3746 incorrect result. The details are quite complex and hard to
3747 determine statically, since branches in the code may exist in some
3748 circumstances, but all cases end with a memory (load, store, or
3749 prefetch) instruction followed immediately by the multiply-accumulate
3750 operation. We employ a linker patching technique, by moving the potentially
3751 affected multiply-accumulate instruction into a patch region and replacing
3752 the original instruction with a branch to the patch. This function checks
3753 if INSN_1 is the memory operation followed by a multiply-accumulate
3754 operation (INSN_2). Return TRUE if an erratum sequence is found, FALSE
3755 if INSN_1 and INSN_2 are safe. */
3758 aarch64_erratum_sequence (uint32_t insn_1, uint32_t insn_2)
3768 if (aarch64_mlxl_p (insn_2)
3769 && aarch64_mem_op_p (insn_1, &rt, &rt2, &pair, &load))
3771 /* Any SIMD memory op is independent of the subsequent MLA
3772 by definition of the erratum. */
3773 if (AARCH64_BIT (insn_1, 26))
3776 /* If not SIMD, check for integer memory ops and MLA relationship. */
3777 rn = AARCH64_RN (insn_2);
3778 ra = AARCH64_RA (insn_2);
3779 rm = AARCH64_RM (insn_2);
3781 /* If this is a load and there's a true(RAW) dependency, we are safe
3782 and this is not an erratum sequence. */
3784 (rt == rn || rt == rm || rt == ra
3785 || (pair && (rt2 == rn || rt2 == rm || rt2 == ra))))
3788 /* We conservatively put out stubs for all other cases (including
3796 /* Used to order a list of mapping symbols by address. */
3799 elf_aarch64_compare_mapping (const void *a, const void *b)
3801 const elf_aarch64_section_map *amap = (const elf_aarch64_section_map *) a;
3802 const elf_aarch64_section_map *bmap = (const elf_aarch64_section_map *) b;
3804 if (amap->vma > bmap->vma)
3806 else if (amap->vma < bmap->vma)
3808 else if (amap->type > bmap->type)
3809 /* Ensure results do not depend on the host qsort for objects with
3810 multiple mapping symbols at the same address by sorting on type
3813 else if (amap->type < bmap->type)
3821 _bfd_aarch64_erratum_835769_stub_name (unsigned num_fixes)
3823 char *stub_name = (char *) bfd_malloc
3824 (strlen ("__erratum_835769_veneer_") + 16);
3825 if (stub_name != NULL)
3826 sprintf (stub_name,"__erratum_835769_veneer_%d", num_fixes);
3830 /* Scan for Cortex-A53 erratum 835769 sequence.
3832 Return TRUE else FALSE on abnormal termination. */
3835 _bfd_aarch64_erratum_835769_scan (bfd *input_bfd,
3836 struct bfd_link_info *info,
3837 unsigned int *num_fixes_p)
3840 struct elf_aarch64_link_hash_table *htab = elf_aarch64_hash_table (info);
3841 unsigned int num_fixes = *num_fixes_p;
3846 for (section = input_bfd->sections;
3848 section = section->next)
3850 bfd_byte *contents = NULL;
3851 struct _aarch64_elf_section_data *sec_data;
3854 if (elf_section_type (section) != SHT_PROGBITS
3855 || (elf_section_flags (section) & SHF_EXECINSTR) == 0
3856 || (section->flags & SEC_EXCLUDE) != 0
3857 || (section->sec_info_type == SEC_INFO_TYPE_JUST_SYMS)
3858 || (section->output_section == bfd_abs_section_ptr))
3861 if (elf_section_data (section)->this_hdr.contents != NULL)
3862 contents = elf_section_data (section)->this_hdr.contents;
3863 else if (! bfd_malloc_and_get_section (input_bfd, section, &contents))
3866 sec_data = elf_aarch64_section_data (section);
3868 qsort (sec_data->map, sec_data->mapcount,
3869 sizeof (elf_aarch64_section_map), elf_aarch64_compare_mapping);
3871 for (span = 0; span < sec_data->mapcount; span++)
3873 unsigned int span_start = sec_data->map[span].vma;
3874 unsigned int span_end = ((span == sec_data->mapcount - 1)
3875 ? sec_data->map[0].vma + section->size
3876 : sec_data->map[span + 1].vma);
3878 char span_type = sec_data->map[span].type;
3880 if (span_type == 'd')
3883 for (i = span_start; i + 4 < span_end; i += 4)
3885 uint32_t insn_1 = bfd_getl32 (contents + i);
3886 uint32_t insn_2 = bfd_getl32 (contents + i + 4);
3888 if (aarch64_erratum_sequence (insn_1, insn_2))
3890 struct elf_aarch64_stub_hash_entry *stub_entry;
3891 char *stub_name = _bfd_aarch64_erratum_835769_stub_name (num_fixes);
3895 stub_entry = _bfd_aarch64_add_stub_entry_in_group (stub_name,
3901 stub_entry->stub_type = aarch64_stub_erratum_835769_veneer;
3902 stub_entry->target_section = section;
3903 stub_entry->target_value = i + 4;
3904 stub_entry->veneered_insn = insn_2;
3905 stub_entry->output_name = stub_name;
3910 if (elf_section_data (section)->this_hdr.contents == NULL)
3914 *num_fixes_p = num_fixes;
3920 /* Test if instruction INSN is ADRP. */
3923 _bfd_aarch64_adrp_p (uint32_t insn)
3925 return ((insn & AARCH64_ADRP_OP_MASK) == AARCH64_ADRP_OP);
3929 /* Helper predicate to look for cortex-a53 erratum 843419 sequence 1. */
3932 _bfd_aarch64_erratum_843419_sequence_p (uint32_t insn_1, uint32_t insn_2,
3940 return (aarch64_mem_op_p (insn_2, &rt, &rt2, &pair, &load)
3943 && AARCH64_LDST_UIMM (insn_3)
3944 && AARCH64_RN (insn_3) == AARCH64_RD (insn_1));
3948 /* Test for the presence of Cortex-A53 erratum 843419 instruction sequence.
3950 Return TRUE if section CONTENTS at offset I contains one of the
3951 erratum 843419 sequences, otherwise return FALSE. If a sequence is
3952 seen set P_VENEER_I to the offset of the final LOAD/STORE
3953 instruction in the sequence.
3957 _bfd_aarch64_erratum_843419_p (bfd_byte *contents, bfd_vma vma,
3958 bfd_vma i, bfd_vma span_end,
3959 bfd_vma *p_veneer_i)
3961 uint32_t insn_1 = bfd_getl32 (contents + i);
3963 if (!_bfd_aarch64_adrp_p (insn_1))
3966 if (span_end < i + 12)
3969 uint32_t insn_2 = bfd_getl32 (contents + i + 4);
3970 uint32_t insn_3 = bfd_getl32 (contents + i + 8);
3972 if ((vma & 0xfff) != 0xff8 && (vma & 0xfff) != 0xffc)
3975 if (_bfd_aarch64_erratum_843419_sequence_p (insn_1, insn_2, insn_3))
3977 *p_veneer_i = i + 8;
3981 if (span_end < i + 16)
3984 uint32_t insn_4 = bfd_getl32 (contents + i + 12);
3986 if (_bfd_aarch64_erratum_843419_sequence_p (insn_1, insn_2, insn_4))
3988 *p_veneer_i = i + 12;
3996 /* Resize all stub sections. */
3999 _bfd_aarch64_resize_stubs (struct elf_aarch64_link_hash_table *htab)
4003 /* OK, we've added some stubs. Find out the new size of the
4005 for (section = htab->stub_bfd->sections;
4006 section != NULL; section = section->next)
4008 /* Ignore non-stub sections. */
4009 if (!strstr (section->name, STUB_SUFFIX))
4014 bfd_hash_traverse (&htab->stub_hash_table, aarch64_size_one_stub, htab);
4016 for (section = htab->stub_bfd->sections;
4017 section != NULL; section = section->next)
4019 if (!strstr (section->name, STUB_SUFFIX))
4022 /* Add space for a branch. Add 8 bytes to keep section 8 byte aligned,
4023 as long branch stubs contain a 64-bit address. */
4027 /* Ensure all stub sections have a size which is a multiple of
4028 4096. This is important in order to ensure that the insertion
4029 of stub sections does not in itself move existing code around
4030 in such a way that new errata sequences are created. */
4031 if (htab->fix_erratum_843419)
4033 section->size = BFD_ALIGN (section->size, 0x1000);
4037 /* Construct an erratum 843419 workaround stub name. */
4040 _bfd_aarch64_erratum_843419_stub_name (asection *input_section,
4043 const bfd_size_type len = 8 + 4 + 1 + 8 + 1 + 16 + 1;
4044 char *stub_name = bfd_malloc (len);
4046 if (stub_name != NULL)
4047 snprintf (stub_name, len, "e843419@%04x_%08x_%" BFD_VMA_FMT "x",
4048 input_section->owner->id,
4054 /* Build a stub_entry structure describing an 843419 fixup.
4056 The stub_entry constructed is populated with the bit pattern INSN
4057 of the instruction located at OFFSET within input SECTION.
4059 Returns TRUE on success. */
4062 _bfd_aarch64_erratum_843419_fixup (uint32_t insn,
4063 bfd_vma adrp_offset,
4064 bfd_vma ldst_offset,
4066 struct bfd_link_info *info)
4068 struct elf_aarch64_link_hash_table *htab = elf_aarch64_hash_table (info);
4070 struct elf_aarch64_stub_hash_entry *stub_entry;
4072 stub_name = _bfd_aarch64_erratum_843419_stub_name (section, ldst_offset);
4073 if (stub_name == NULL)
4075 stub_entry = aarch64_stub_hash_lookup (&htab->stub_hash_table, stub_name,
4083 /* We always place an 843419 workaround veneer in the stub section
4084 attached to the input section in which an erratum sequence has
4085 been found. This ensures that later in the link process (in
4086 elfNN_aarch64_write_section) when we copy the veneered
4087 instruction from the input section into the stub section the
4088 copied instruction will have had any relocations applied to it.
4089 If we placed workaround veneers in any other stub section then we
4090 could not assume that all relocations have been processed on the
4091 corresponding input section at the point we output the stub
4094 stub_entry = _bfd_aarch64_add_stub_entry_after (stub_name, section, htab);
4095 if (stub_entry == NULL)
4101 stub_entry->adrp_offset = adrp_offset;
4102 stub_entry->target_value = ldst_offset;
4103 stub_entry->target_section = section;
4104 stub_entry->stub_type = aarch64_stub_erratum_843419_veneer;
4105 stub_entry->veneered_insn = insn;
4106 stub_entry->output_name = stub_name;
4112 /* Scan an input section looking for the signature of erratum 843419.
4114 Scans input SECTION in INPUT_BFD looking for erratum 843419
4115 signatures, for each signature found a stub_entry is created
4116 describing the location of the erratum for subsequent fixup.
4118 Return TRUE on successful scan, FALSE on failure to scan.
4122 _bfd_aarch64_erratum_843419_scan (bfd *input_bfd, asection *section,
4123 struct bfd_link_info *info)
4125 struct elf_aarch64_link_hash_table *htab = elf_aarch64_hash_table (info);
4130 if (elf_section_type (section) != SHT_PROGBITS
4131 || (elf_section_flags (section) & SHF_EXECINSTR) == 0
4132 || (section->flags & SEC_EXCLUDE) != 0
4133 || (section->sec_info_type == SEC_INFO_TYPE_JUST_SYMS)
4134 || (section->output_section == bfd_abs_section_ptr))
4139 bfd_byte *contents = NULL;
4140 struct _aarch64_elf_section_data *sec_data;
4143 if (elf_section_data (section)->this_hdr.contents != NULL)
4144 contents = elf_section_data (section)->this_hdr.contents;
4145 else if (! bfd_malloc_and_get_section (input_bfd, section, &contents))
4148 sec_data = elf_aarch64_section_data (section);
4150 qsort (sec_data->map, sec_data->mapcount,
4151 sizeof (elf_aarch64_section_map), elf_aarch64_compare_mapping);
4153 for (span = 0; span < sec_data->mapcount; span++)
4155 unsigned int span_start = sec_data->map[span].vma;
4156 unsigned int span_end = ((span == sec_data->mapcount - 1)
4157 ? sec_data->map[0].vma + section->size
4158 : sec_data->map[span + 1].vma);
4160 char span_type = sec_data->map[span].type;
4162 if (span_type == 'd')
4165 for (i = span_start; i + 8 < span_end; i += 4)
4167 bfd_vma vma = (section->output_section->vma
4168 + section->output_offset
4172 if (_bfd_aarch64_erratum_843419_p
4173 (contents, vma, i, span_end, &veneer_i))
4175 uint32_t insn = bfd_getl32 (contents + veneer_i);
4177 if (!_bfd_aarch64_erratum_843419_fixup (insn, i, veneer_i,
4184 if (elf_section_data (section)->this_hdr.contents == NULL)
4193 /* Determine and set the size of the stub section for a final link.
4195 The basic idea here is to examine all the relocations looking for
4196 PC-relative calls to a target that is unreachable with a "bl"
4200 elfNN_aarch64_size_stubs (bfd *output_bfd,
4202 struct bfd_link_info *info,
4203 bfd_signed_vma group_size,
4204 asection * (*add_stub_section) (const char *,
4206 void (*layout_sections_again) (void))
4208 bfd_size_type stub_group_size;
4209 bfd_boolean stubs_always_before_branch;
4210 bfd_boolean stub_changed = FALSE;
4211 struct elf_aarch64_link_hash_table *htab = elf_aarch64_hash_table (info);
4212 unsigned int num_erratum_835769_fixes = 0;
4214 /* Propagate mach to stub bfd, because it may not have been
4215 finalized when we created stub_bfd. */
4216 bfd_set_arch_mach (stub_bfd, bfd_get_arch (output_bfd),
4217 bfd_get_mach (output_bfd));
4219 /* Stash our params away. */
4220 htab->stub_bfd = stub_bfd;
4221 htab->add_stub_section = add_stub_section;
4222 htab->layout_sections_again = layout_sections_again;
4223 stubs_always_before_branch = group_size < 0;
4225 stub_group_size = -group_size;
4227 stub_group_size = group_size;
4229 if (stub_group_size == 1)
4231 /* Default values. */
4232 /* AArch64 branch range is +-128MB. The value used is 1MB less. */
4233 stub_group_size = 127 * 1024 * 1024;
4236 group_sections (htab, stub_group_size, stubs_always_before_branch);
4238 (*htab->layout_sections_again) ();
4240 if (htab->fix_erratum_835769)
4244 for (input_bfd = info->input_bfds;
4245 input_bfd != NULL; input_bfd = input_bfd->link.next)
4246 if (!_bfd_aarch64_erratum_835769_scan (input_bfd, info,
4247 &num_erratum_835769_fixes))
4250 _bfd_aarch64_resize_stubs (htab);
4251 (*htab->layout_sections_again) ();
4254 if (htab->fix_erratum_843419)
4258 for (input_bfd = info->input_bfds;
4260 input_bfd = input_bfd->link.next)
4264 for (section = input_bfd->sections;
4266 section = section->next)
4267 if (!_bfd_aarch64_erratum_843419_scan (input_bfd, section, info))
4271 _bfd_aarch64_resize_stubs (htab);
4272 (*htab->layout_sections_again) ();
4279 for (input_bfd = info->input_bfds;
4280 input_bfd != NULL; input_bfd = input_bfd->link.next)
4282 Elf_Internal_Shdr *symtab_hdr;
4284 Elf_Internal_Sym *local_syms = NULL;
4286 /* We'll need the symbol table in a second. */
4287 symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
4288 if (symtab_hdr->sh_info == 0)
4291 /* Walk over each section attached to the input bfd. */
4292 for (section = input_bfd->sections;
4293 section != NULL; section = section->next)
4295 Elf_Internal_Rela *internal_relocs, *irelaend, *irela;
4297 /* If there aren't any relocs, then there's nothing more
4299 if ((section->flags & SEC_RELOC) == 0
4300 || section->reloc_count == 0
4301 || (section->flags & SEC_CODE) == 0)
4304 /* If this section is a link-once section that will be
4305 discarded, then don't create any stubs. */
4306 if (section->output_section == NULL
4307 || section->output_section->owner != output_bfd)
4310 /* Get the relocs. */
4312 = _bfd_elf_link_read_relocs (input_bfd, section, NULL,
4313 NULL, info->keep_memory);
4314 if (internal_relocs == NULL)
4315 goto error_ret_free_local;
4317 /* Now examine each relocation. */
4318 irela = internal_relocs;
4319 irelaend = irela + section->reloc_count;
4320 for (; irela < irelaend; irela++)
4322 unsigned int r_type, r_indx;
4323 enum elf_aarch64_stub_type stub_type;
4324 struct elf_aarch64_stub_hash_entry *stub_entry;
4327 bfd_vma destination;
4328 struct elf_aarch64_link_hash_entry *hash;
4329 const char *sym_name;
4331 const asection *id_sec;
4332 unsigned char st_type;
4335 r_type = ELFNN_R_TYPE (irela->r_info);
4336 r_indx = ELFNN_R_SYM (irela->r_info);
4338 if (r_type >= (unsigned int) R_AARCH64_end)
4340 bfd_set_error (bfd_error_bad_value);
4341 error_ret_free_internal:
4342 if (elf_section_data (section)->relocs == NULL)
4343 free (internal_relocs);
4344 goto error_ret_free_local;
4347 /* Only look for stubs on unconditional branch and
4348 branch and link instructions. */
4349 if (r_type != (unsigned int) AARCH64_R (CALL26)
4350 && r_type != (unsigned int) AARCH64_R (JUMP26))
4353 /* Now determine the call target, its name, value,
4360 if (r_indx < symtab_hdr->sh_info)
4362 /* It's a local symbol. */
4363 Elf_Internal_Sym *sym;
4364 Elf_Internal_Shdr *hdr;
4366 if (local_syms == NULL)
4369 = (Elf_Internal_Sym *) symtab_hdr->contents;
4370 if (local_syms == NULL)
4372 = bfd_elf_get_elf_syms (input_bfd, symtab_hdr,
4373 symtab_hdr->sh_info, 0,
4375 if (local_syms == NULL)
4376 goto error_ret_free_internal;
4379 sym = local_syms + r_indx;
4380 hdr = elf_elfsections (input_bfd)[sym->st_shndx];
4381 sym_sec = hdr->bfd_section;
4383 /* This is an undefined symbol. It can never
4387 if (ELF_ST_TYPE (sym->st_info) != STT_SECTION)
4388 sym_value = sym->st_value;
4389 destination = (sym_value + irela->r_addend
4390 + sym_sec->output_offset
4391 + sym_sec->output_section->vma);
4392 st_type = ELF_ST_TYPE (sym->st_info);
4394 = bfd_elf_string_from_elf_section (input_bfd,
4395 symtab_hdr->sh_link,
4402 e_indx = r_indx - symtab_hdr->sh_info;
4403 hash = ((struct elf_aarch64_link_hash_entry *)
4404 elf_sym_hashes (input_bfd)[e_indx]);
4406 while (hash->root.root.type == bfd_link_hash_indirect
4407 || hash->root.root.type == bfd_link_hash_warning)
4408 hash = ((struct elf_aarch64_link_hash_entry *)
4409 hash->root.root.u.i.link);
4411 if (hash->root.root.type == bfd_link_hash_defined
4412 || hash->root.root.type == bfd_link_hash_defweak)
4414 struct elf_aarch64_link_hash_table *globals =
4415 elf_aarch64_hash_table (info);
4416 sym_sec = hash->root.root.u.def.section;
4417 sym_value = hash->root.root.u.def.value;
4418 /* For a destination in a shared library,
4419 use the PLT stub as target address to
4420 decide whether a branch stub is
4422 if (globals->root.splt != NULL && hash != NULL
4423 && hash->root.plt.offset != (bfd_vma) - 1)
4425 sym_sec = globals->root.splt;
4426 sym_value = hash->root.plt.offset;
4427 if (sym_sec->output_section != NULL)
4428 destination = (sym_value
4429 + sym_sec->output_offset
4431 sym_sec->output_section->vma);
4433 else if (sym_sec->output_section != NULL)
4434 destination = (sym_value + irela->r_addend
4435 + sym_sec->output_offset
4436 + sym_sec->output_section->vma);
4438 else if (hash->root.root.type == bfd_link_hash_undefined
4439 || (hash->root.root.type
4440 == bfd_link_hash_undefweak))
4442 /* For a shared library, use the PLT stub as
4443 target address to decide whether a long
4444 branch stub is needed.
4445 For absolute code, they cannot be handled. */
4446 struct elf_aarch64_link_hash_table *globals =
4447 elf_aarch64_hash_table (info);
4449 if (globals->root.splt != NULL && hash != NULL
4450 && hash->root.plt.offset != (bfd_vma) - 1)
4452 sym_sec = globals->root.splt;
4453 sym_value = hash->root.plt.offset;
4454 if (sym_sec->output_section != NULL)
4455 destination = (sym_value
4456 + sym_sec->output_offset
4458 sym_sec->output_section->vma);
4465 bfd_set_error (bfd_error_bad_value);
4466 goto error_ret_free_internal;
4468 st_type = ELF_ST_TYPE (hash->root.type);
4469 sym_name = hash->root.root.root.string;
4472 /* Determine what (if any) linker stub is needed. */
4473 stub_type = aarch64_type_of_stub (section, irela, sym_sec,
4474 st_type, destination);
4475 if (stub_type == aarch64_stub_none)
4478 /* Support for grouping stub sections. */
4479 id_sec = htab->stub_group[section->id].link_sec;
4481 /* Get the name of this stub. */
4482 stub_name = elfNN_aarch64_stub_name (id_sec, sym_sec, hash,
4485 goto error_ret_free_internal;
4488 aarch64_stub_hash_lookup (&htab->stub_hash_table,
4489 stub_name, FALSE, FALSE);
4490 if (stub_entry != NULL)
4492 /* The proper stub has already been created. */
4494 /* Always update this stub's target since it may have
4495 changed after layout. */
4496 stub_entry->target_value = sym_value + irela->r_addend;
4500 stub_entry = _bfd_aarch64_add_stub_entry_in_group
4501 (stub_name, section, htab);
4502 if (stub_entry == NULL)
4505 goto error_ret_free_internal;
4508 stub_entry->target_value = sym_value + irela->r_addend;
4509 stub_entry->target_section = sym_sec;
4510 stub_entry->stub_type = stub_type;
4511 stub_entry->h = hash;
4512 stub_entry->st_type = st_type;
4514 if (sym_name == NULL)
4515 sym_name = "unnamed";
4516 len = sizeof (STUB_ENTRY_NAME) + strlen (sym_name);
4517 stub_entry->output_name = bfd_alloc (htab->stub_bfd, len);
4518 if (stub_entry->output_name == NULL)
4521 goto error_ret_free_internal;
4524 snprintf (stub_entry->output_name, len, STUB_ENTRY_NAME,
4527 stub_changed = TRUE;
4530 /* We're done with the internal relocs, free them. */
4531 if (elf_section_data (section)->relocs == NULL)
4532 free (internal_relocs);
4539 _bfd_aarch64_resize_stubs (htab);
4541 /* Ask the linker to do its stuff. */
4542 (*htab->layout_sections_again) ();
4543 stub_changed = FALSE;
4548 error_ret_free_local:
4552 /* Build all the stubs associated with the current output file. The
4553 stubs are kept in a hash table attached to the main linker hash
4554 table. We also set up the .plt entries for statically linked PIC
4555 functions here. This function is called via aarch64_elf_finish in the
4559 elfNN_aarch64_build_stubs (struct bfd_link_info *info)
4562 struct bfd_hash_table *table;
4563 struct elf_aarch64_link_hash_table *htab;
4565 htab = elf_aarch64_hash_table (info);
4567 for (stub_sec = htab->stub_bfd->sections;
4568 stub_sec != NULL; stub_sec = stub_sec->next)
4572 /* Ignore non-stub sections. */
4573 if (!strstr (stub_sec->name, STUB_SUFFIX))
4576 /* Allocate memory to hold the linker stubs. */
4577 size = stub_sec->size;
4578 stub_sec->contents = bfd_zalloc (htab->stub_bfd, size);
4579 if (stub_sec->contents == NULL && size != 0)
4583 /* Add a branch around the stub section, and a nop, to keep it 8 byte
4584 aligned, as long branch stubs contain a 64-bit address. */
4585 bfd_putl32 (0x14000000 | (size >> 2), stub_sec->contents);
4586 bfd_putl32 (INSN_NOP, stub_sec->contents + 4);
4587 stub_sec->size += 8;
4590 /* Build the stubs as directed by the stub hash table. */
4591 table = &htab->stub_hash_table;
4592 bfd_hash_traverse (table, aarch64_build_one_stub, info);
4598 /* Add an entry to the code/data map for section SEC. */
4601 elfNN_aarch64_section_map_add (asection *sec, char type, bfd_vma vma)
4603 struct _aarch64_elf_section_data *sec_data =
4604 elf_aarch64_section_data (sec);
4605 unsigned int newidx;
4607 if (sec_data->map == NULL)
4609 sec_data->map = bfd_malloc (sizeof (elf_aarch64_section_map));
4610 sec_data->mapcount = 0;
4611 sec_data->mapsize = 1;
4614 newidx = sec_data->mapcount++;
4616 if (sec_data->mapcount > sec_data->mapsize)
4618 sec_data->mapsize *= 2;
4619 sec_data->map = bfd_realloc_or_free
4620 (sec_data->map, sec_data->mapsize * sizeof (elf_aarch64_section_map));
4625 sec_data->map[newidx].vma = vma;
4626 sec_data->map[newidx].type = type;
4631 /* Initialise maps of insn/data for input BFDs. */
4633 bfd_elfNN_aarch64_init_maps (bfd *abfd)
4635 Elf_Internal_Sym *isymbuf;
4636 Elf_Internal_Shdr *hdr;
4637 unsigned int i, localsyms;
4639 /* Make sure that we are dealing with an AArch64 elf binary. */
4640 if (!is_aarch64_elf (abfd))
4643 if ((abfd->flags & DYNAMIC) != 0)
4646 hdr = &elf_symtab_hdr (abfd);
4647 localsyms = hdr->sh_info;
4649 /* Obtain a buffer full of symbols for this BFD. The hdr->sh_info field
4650 should contain the number of local symbols, which should come before any
4651 global symbols. Mapping symbols are always local. */
4652 isymbuf = bfd_elf_get_elf_syms (abfd, hdr, localsyms, 0, NULL, NULL, NULL);
4654 /* No internal symbols read? Skip this BFD. */
4655 if (isymbuf == NULL)
4658 for (i = 0; i < localsyms; i++)
4660 Elf_Internal_Sym *isym = &isymbuf[i];
4661 asection *sec = bfd_section_from_elf_index (abfd, isym->st_shndx);
4664 if (sec != NULL && ELF_ST_BIND (isym->st_info) == STB_LOCAL)
4666 name = bfd_elf_string_from_elf_section (abfd,
4670 if (bfd_is_aarch64_special_symbol_name
4671 (name, BFD_AARCH64_SPECIAL_SYM_TYPE_MAP))
4672 elfNN_aarch64_section_map_add (sec, name[1], isym->st_value);
4678 setup_plt_values (struct bfd_link_info *link_info,
4679 aarch64_plt_type plt_type)
4681 struct elf_aarch64_link_hash_table *globals;
4682 globals = elf_aarch64_hash_table (link_info);
4684 if (plt_type == PLT_BTI)
4686 globals->plt_header_size = PLT_BTI_ENTRY_SIZE;
4687 globals->plt0_entry = elfNN_aarch64_small_plt0_bti_entry;
4688 globals->tlsdesc_plt_entry_size = PLT_BTI_TLSDESC_ENTRY_SIZE;
4690 /* Only in ET_EXEC we need PLTn with BTI. */
4691 if (bfd_link_pde (link_info))
4693 globals->plt_entry_size = PLT_BTI_SMALL_ENTRY_SIZE;
4694 globals->plt_entry = elfNN_aarch64_small_plt_bti_entry;
4699 /* Set option values needed during linking. */
4701 bfd_elfNN_aarch64_set_options (struct bfd *output_bfd,
4702 struct bfd_link_info *link_info,
4704 int no_wchar_warn, int pic_veneer,
4705 int fix_erratum_835769,
4706 int fix_erratum_843419,
4707 int no_apply_dynamic_relocs,
4708 aarch64_bti_pac_info bp_info)
4710 struct elf_aarch64_link_hash_table *globals;
4712 globals = elf_aarch64_hash_table (link_info);
4713 globals->pic_veneer = pic_veneer;
4714 globals->fix_erratum_835769 = fix_erratum_835769;
4715 globals->fix_erratum_843419 = fix_erratum_843419;
4716 globals->fix_erratum_843419_adr = TRUE;
4717 globals->no_apply_dynamic_relocs = no_apply_dynamic_relocs;
4719 BFD_ASSERT (is_aarch64_elf (output_bfd));
4720 elf_aarch64_tdata (output_bfd)->no_enum_size_warning = no_enum_warn;
4721 elf_aarch64_tdata (output_bfd)->no_wchar_size_warning = no_wchar_warn;
4723 switch (bp_info.bti_type)
4726 elf_aarch64_tdata (output_bfd)->no_bti_warn = 0;
4727 elf_aarch64_tdata (output_bfd)->gnu_and_prop
4728 |= GNU_PROPERTY_AARCH64_FEATURE_1_BTI;
4734 elf_aarch64_tdata (output_bfd)->plt_type = bp_info.plt_type;
4735 setup_plt_values (link_info, bp_info.plt_type);
4739 aarch64_calculate_got_entry_vma (struct elf_link_hash_entry *h,
4740 struct elf_aarch64_link_hash_table
4741 *globals, struct bfd_link_info *info,
4742 bfd_vma value, bfd *output_bfd,
4743 bfd_boolean *unresolved_reloc_p)
4745 bfd_vma off = (bfd_vma) - 1;
4746 asection *basegot = globals->root.sgot;
4747 bfd_boolean dyn = globals->root.dynamic_sections_created;
4751 BFD_ASSERT (basegot != NULL);
4752 off = h->got.offset;
4753 BFD_ASSERT (off != (bfd_vma) - 1);
4754 if (!WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, bfd_link_pic (info), h)
4755 || (bfd_link_pic (info)
4756 && SYMBOL_REFERENCES_LOCAL (info, h))
4757 || (ELF_ST_VISIBILITY (h->other)
4758 && h->root.type == bfd_link_hash_undefweak))
4760 /* This is actually a static link, or it is a -Bsymbolic link
4761 and the symbol is defined locally. We must initialize this
4762 entry in the global offset table. Since the offset must
4763 always be a multiple of 8 (4 in the case of ILP32), we use
4764 the least significant bit to record whether we have
4765 initialized it already.
4766 When doing a dynamic link, we create a .rel(a).got relocation
4767 entry to initialize the value. This is done in the
4768 finish_dynamic_symbol routine. */
4773 bfd_put_NN (output_bfd, value, basegot->contents + off);
4778 *unresolved_reloc_p = FALSE;
4780 off = off + basegot->output_section->vma + basegot->output_offset;
4786 /* Change R_TYPE to a more efficient access model where possible,
4787 return the new reloc type. */
4789 static bfd_reloc_code_real_type
4790 aarch64_tls_transition_without_check (bfd_reloc_code_real_type r_type,
4791 struct elf_link_hash_entry *h)
4793 bfd_boolean is_local = h == NULL;
4797 case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21:
4798 case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21:
4800 ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1
4801 : BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21);
4803 case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21:
4805 ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC
4808 case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19:
4810 ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1
4811 : BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19);
4813 case BFD_RELOC_AARCH64_TLSDESC_LDR:
4815 ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC
4816 : BFD_RELOC_AARCH64_NONE);
4818 case BFD_RELOC_AARCH64_TLSDESC_OFF_G0_NC:
4820 ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1_NC
4821 : BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G0_NC);
4823 case BFD_RELOC_AARCH64_TLSDESC_OFF_G1:
4825 ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G2
4826 : BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G1);
4828 case BFD_RELOC_AARCH64_TLSDESC_LDNN_LO12_NC:
4829 case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC:
4831 ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC
4832 : BFD_RELOC_AARCH64_TLSIE_LDNN_GOTTPREL_LO12_NC);
4834 case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21:
4835 return is_local ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1 : r_type;
4837 case BFD_RELOC_AARCH64_TLSIE_LDNN_GOTTPREL_LO12_NC:
4838 return is_local ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC : r_type;
4840 case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19:
4843 case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21:
4845 ? BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_HI12
4846 : BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19);
4848 case BFD_RELOC_AARCH64_TLSDESC_ADD:
4849 case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12:
4850 case BFD_RELOC_AARCH64_TLSDESC_CALL:
4851 /* Instructions with these relocations will become NOPs. */
4852 return BFD_RELOC_AARCH64_NONE;
4854 case BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC:
4855 case BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21:
4856 case BFD_RELOC_AARCH64_TLSLD_ADR_PREL21:
4857 return is_local ? BFD_RELOC_AARCH64_NONE : r_type;
4860 case BFD_RELOC_AARCH64_TLSGD_MOVW_G0_NC:
4862 ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1_NC
4863 : BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G0_NC;
4865 case BFD_RELOC_AARCH64_TLSGD_MOVW_G1:
4867 ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G2
4868 : BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G1;
4879 aarch64_reloc_got_type (bfd_reloc_code_real_type r_type)
4883 case BFD_RELOC_AARCH64_ADR_GOT_PAGE:
4884 case BFD_RELOC_AARCH64_GOT_LD_PREL19:
4885 case BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14:
4886 case BFD_RELOC_AARCH64_LD32_GOT_LO12_NC:
4887 case BFD_RELOC_AARCH64_LD64_GOTOFF_LO15:
4888 case BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15:
4889 case BFD_RELOC_AARCH64_LD64_GOT_LO12_NC:
4890 case BFD_RELOC_AARCH64_MOVW_GOTOFF_G0_NC:
4891 case BFD_RELOC_AARCH64_MOVW_GOTOFF_G1:
4894 case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC:
4895 case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21:
4896 case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21:
4897 case BFD_RELOC_AARCH64_TLSGD_MOVW_G0_NC:
4898 case BFD_RELOC_AARCH64_TLSGD_MOVW_G1:
4899 case BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC:
4900 case BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21:
4901 case BFD_RELOC_AARCH64_TLSLD_ADR_PREL21:
4904 case BFD_RELOC_AARCH64_TLSDESC_ADD:
4905 case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12:
4906 case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21:
4907 case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21:
4908 case BFD_RELOC_AARCH64_TLSDESC_CALL:
4909 case BFD_RELOC_AARCH64_TLSDESC_LD32_LO12_NC:
4910 case BFD_RELOC_AARCH64_TLSDESC_LD64_LO12:
4911 case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19:
4912 case BFD_RELOC_AARCH64_TLSDESC_LDR:
4913 case BFD_RELOC_AARCH64_TLSDESC_OFF_G0_NC:
4914 case BFD_RELOC_AARCH64_TLSDESC_OFF_G1:
4915 return GOT_TLSDESC_GD;
4917 case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21:
4918 case BFD_RELOC_AARCH64_TLSIE_LD32_GOTTPREL_LO12_NC:
4919 case BFD_RELOC_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC:
4920 case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19:
4921 case BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G0_NC:
4922 case BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G1:
4932 aarch64_can_relax_tls (bfd *input_bfd,
4933 struct bfd_link_info *info,
4934 bfd_reloc_code_real_type r_type,
4935 struct elf_link_hash_entry *h,
4936 unsigned long r_symndx)
4938 unsigned int symbol_got_type;
4939 unsigned int reloc_got_type;
4941 if (! IS_AARCH64_TLS_RELAX_RELOC (r_type))
4944 symbol_got_type = elfNN_aarch64_symbol_got_type (h, input_bfd, r_symndx);
4945 reloc_got_type = aarch64_reloc_got_type (r_type);
4947 if (symbol_got_type == GOT_TLS_IE && GOT_TLS_GD_ANY_P (reloc_got_type))
4950 if (!bfd_link_executable (info))
4953 if (h && h->root.type == bfd_link_hash_undefweak)
4959 /* Given the relocation code R_TYPE, return the relaxed bfd reloc
4962 static bfd_reloc_code_real_type
4963 aarch64_tls_transition (bfd *input_bfd,
4964 struct bfd_link_info *info,
4965 unsigned int r_type,
4966 struct elf_link_hash_entry *h,
4967 unsigned long r_symndx)
4969 bfd_reloc_code_real_type bfd_r_type
4970 = elfNN_aarch64_bfd_reloc_from_type (input_bfd, r_type);
4972 if (! aarch64_can_relax_tls (input_bfd, info, bfd_r_type, h, r_symndx))
4975 return aarch64_tls_transition_without_check (bfd_r_type, h);
4978 /* Return the base VMA address which should be subtracted from real addresses
4979 when resolving R_AARCH64_TLS_DTPREL relocation. */
4982 dtpoff_base (struct bfd_link_info *info)
4984 /* If tls_sec is NULL, we should have signalled an error already. */
4985 BFD_ASSERT (elf_hash_table (info)->tls_sec != NULL);
4986 return elf_hash_table (info)->tls_sec->vma;
4989 /* Return the base VMA address which should be subtracted from real addresses
4990 when resolving R_AARCH64_TLS_GOTTPREL64 relocations. */
4993 tpoff_base (struct bfd_link_info *info)
4995 struct elf_link_hash_table *htab = elf_hash_table (info);
4997 /* If tls_sec is NULL, we should have signalled an error already. */
4998 BFD_ASSERT (htab->tls_sec != NULL);
5000 bfd_vma base = align_power ((bfd_vma) TCB_SIZE,
5001 htab->tls_sec->alignment_power);
5002 return htab->tls_sec->vma - base;
5006 symbol_got_offset_ref (bfd *input_bfd, struct elf_link_hash_entry *h,
5007 unsigned long r_symndx)
5009 /* Calculate the address of the GOT entry for symbol
5010 referred to in h. */
5012 return &h->got.offset;
5016 struct elf_aarch64_local_symbol *l;
5018 l = elf_aarch64_locals (input_bfd);
5019 return &l[r_symndx].got_offset;
5024 symbol_got_offset_mark (bfd *input_bfd, struct elf_link_hash_entry *h,
5025 unsigned long r_symndx)
5028 p = symbol_got_offset_ref (input_bfd, h, r_symndx);
5033 symbol_got_offset_mark_p (bfd *input_bfd, struct elf_link_hash_entry *h,
5034 unsigned long r_symndx)
5037 value = * symbol_got_offset_ref (input_bfd, h, r_symndx);
5042 symbol_got_offset (bfd *input_bfd, struct elf_link_hash_entry *h,
5043 unsigned long r_symndx)
5046 value = * symbol_got_offset_ref (input_bfd, h, r_symndx);
5052 symbol_tlsdesc_got_offset_ref (bfd *input_bfd, struct elf_link_hash_entry *h,
5053 unsigned long r_symndx)
5055 /* Calculate the address of the GOT entry for symbol
5056 referred to in h. */
5059 struct elf_aarch64_link_hash_entry *eh;
5060 eh = (struct elf_aarch64_link_hash_entry *) h;
5061 return &eh->tlsdesc_got_jump_table_offset;
5066 struct elf_aarch64_local_symbol *l;
5068 l = elf_aarch64_locals (input_bfd);
5069 return &l[r_symndx].tlsdesc_got_jump_table_offset;
5074 symbol_tlsdesc_got_offset_mark (bfd *input_bfd, struct elf_link_hash_entry *h,
5075 unsigned long r_symndx)
5078 p = symbol_tlsdesc_got_offset_ref (input_bfd, h, r_symndx);
5083 symbol_tlsdesc_got_offset_mark_p (bfd *input_bfd,
5084 struct elf_link_hash_entry *h,
5085 unsigned long r_symndx)
5088 value = * symbol_tlsdesc_got_offset_ref (input_bfd, h, r_symndx);
5093 symbol_tlsdesc_got_offset (bfd *input_bfd, struct elf_link_hash_entry *h,
5094 unsigned long r_symndx)
5097 value = * symbol_tlsdesc_got_offset_ref (input_bfd, h, r_symndx);
5102 /* Data for make_branch_to_erratum_835769_stub(). */
5104 struct erratum_835769_branch_to_stub_data
5106 struct bfd_link_info *info;
5107 asection *output_section;
5111 /* Helper to insert branches to erratum 835769 stubs in the right
5112 places for a particular section. */
5115 make_branch_to_erratum_835769_stub (struct bfd_hash_entry *gen_entry,
5118 struct elf_aarch64_stub_hash_entry *stub_entry;
5119 struct erratum_835769_branch_to_stub_data *data;
5121 unsigned long branch_insn = 0;
5122 bfd_vma veneered_insn_loc, veneer_entry_loc;
5123 bfd_signed_vma branch_offset;
5124 unsigned int target;
5127 stub_entry = (struct elf_aarch64_stub_hash_entry *) gen_entry;
5128 data = (struct erratum_835769_branch_to_stub_data *) in_arg;
5130 if (stub_entry->target_section != data->output_section
5131 || stub_entry->stub_type != aarch64_stub_erratum_835769_veneer)
5134 contents = data->contents;
5135 veneered_insn_loc = stub_entry->target_section->output_section->vma
5136 + stub_entry->target_section->output_offset
5137 + stub_entry->target_value;
5138 veneer_entry_loc = stub_entry->stub_sec->output_section->vma
5139 + stub_entry->stub_sec->output_offset
5140 + stub_entry->stub_offset;
5141 branch_offset = veneer_entry_loc - veneered_insn_loc;
5143 abfd = stub_entry->target_section->owner;
5144 if (!aarch64_valid_branch_p (veneer_entry_loc, veneered_insn_loc))
5146 (_("%pB: error: erratum 835769 stub out "
5147 "of range (input file too large)"), abfd);
5149 target = stub_entry->target_value;
5150 branch_insn = 0x14000000;
5151 branch_offset >>= 2;
5152 branch_offset &= 0x3ffffff;
5153 branch_insn |= branch_offset;
5154 bfd_putl32 (branch_insn, &contents[target]);
5161 _bfd_aarch64_erratum_843419_branch_to_stub (struct bfd_hash_entry *gen_entry,
5164 struct elf_aarch64_stub_hash_entry *stub_entry
5165 = (struct elf_aarch64_stub_hash_entry *) gen_entry;
5166 struct erratum_835769_branch_to_stub_data *data
5167 = (struct erratum_835769_branch_to_stub_data *) in_arg;
5168 struct bfd_link_info *info;
5169 struct elf_aarch64_link_hash_table *htab;
5177 contents = data->contents;
5178 section = data->output_section;
5180 htab = elf_aarch64_hash_table (info);
5182 if (stub_entry->target_section != section
5183 || stub_entry->stub_type != aarch64_stub_erratum_843419_veneer)
5186 insn = bfd_getl32 (contents + stub_entry->target_value);
5188 stub_entry->stub_sec->contents + stub_entry->stub_offset);
5190 place = (section->output_section->vma + section->output_offset
5191 + stub_entry->adrp_offset);
5192 insn = bfd_getl32 (contents + stub_entry->adrp_offset);
5194 if (!_bfd_aarch64_adrp_p (insn))
5197 bfd_signed_vma imm =
5198 (_bfd_aarch64_sign_extend
5199 ((bfd_vma) _bfd_aarch64_decode_adrp_imm (insn) << 12, 33)
5202 if (htab->fix_erratum_843419_adr
5203 && (imm >= AARCH64_MIN_ADRP_IMM && imm <= AARCH64_MAX_ADRP_IMM))
5205 insn = (_bfd_aarch64_reencode_adr_imm (AARCH64_ADR_OP, imm)
5206 | AARCH64_RT (insn));
5207 bfd_putl32 (insn, contents + stub_entry->adrp_offset);
5211 bfd_vma veneered_insn_loc;
5212 bfd_vma veneer_entry_loc;
5213 bfd_signed_vma branch_offset;
5214 uint32_t branch_insn;
5216 veneered_insn_loc = stub_entry->target_section->output_section->vma
5217 + stub_entry->target_section->output_offset
5218 + stub_entry->target_value;
5219 veneer_entry_loc = stub_entry->stub_sec->output_section->vma
5220 + stub_entry->stub_sec->output_offset
5221 + stub_entry->stub_offset;
5222 branch_offset = veneer_entry_loc - veneered_insn_loc;
5224 abfd = stub_entry->target_section->owner;
5225 if (!aarch64_valid_branch_p (veneer_entry_loc, veneered_insn_loc))
5227 (_("%pB: error: erratum 843419 stub out "
5228 "of range (input file too large)"), abfd);
5230 branch_insn = 0x14000000;
5231 branch_offset >>= 2;
5232 branch_offset &= 0x3ffffff;
5233 branch_insn |= branch_offset;
5234 bfd_putl32 (branch_insn, contents + stub_entry->target_value);
5241 elfNN_aarch64_write_section (bfd *output_bfd ATTRIBUTE_UNUSED,
5242 struct bfd_link_info *link_info,
5247 struct elf_aarch64_link_hash_table *globals =
5248 elf_aarch64_hash_table (link_info);
5250 if (globals == NULL)
5253 /* Fix code to point to erratum 835769 stubs. */
5254 if (globals->fix_erratum_835769)
5256 struct erratum_835769_branch_to_stub_data data;
5258 data.info = link_info;
5259 data.output_section = sec;
5260 data.contents = contents;
5261 bfd_hash_traverse (&globals->stub_hash_table,
5262 make_branch_to_erratum_835769_stub, &data);
5265 if (globals->fix_erratum_843419)
5267 struct erratum_835769_branch_to_stub_data data;
5269 data.info = link_info;
5270 data.output_section = sec;
5271 data.contents = contents;
5272 bfd_hash_traverse (&globals->stub_hash_table,
5273 _bfd_aarch64_erratum_843419_branch_to_stub, &data);
5279 /* Return TRUE if RELOC is a relocation against the base of GOT table. */
5282 aarch64_relocation_aginst_gp_p (bfd_reloc_code_real_type reloc)
5284 return (reloc == BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14
5285 || reloc == BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15
5286 || reloc == BFD_RELOC_AARCH64_LD64_GOTOFF_LO15
5287 || reloc == BFD_RELOC_AARCH64_MOVW_GOTOFF_G0_NC
5288 || reloc == BFD_RELOC_AARCH64_MOVW_GOTOFF_G1);
5291 /* Perform a relocation as part of a final link. The input relocation type
5292 should be TLS relaxed. */
5294 static bfd_reloc_status_type
5295 elfNN_aarch64_final_link_relocate (reloc_howto_type *howto,
5298 asection *input_section,
5300 Elf_Internal_Rela *rel,
5302 struct bfd_link_info *info,
5304 struct elf_link_hash_entry *h,
5305 bfd_boolean *unresolved_reloc_p,
5306 bfd_boolean save_addend,
5307 bfd_vma *saved_addend,
5308 Elf_Internal_Sym *sym)
5310 Elf_Internal_Shdr *symtab_hdr;
5311 unsigned int r_type = howto->type;
5312 bfd_reloc_code_real_type bfd_r_type
5313 = elfNN_aarch64_bfd_reloc_from_howto (howto);
5314 unsigned long r_symndx;
5315 bfd_byte *hit_data = contents + rel->r_offset;
5316 bfd_vma place, off, got_entry_addr = 0;
5317 bfd_signed_vma signed_addend;
5318 struct elf_aarch64_link_hash_table *globals;
5319 bfd_boolean weak_undef_p;
5320 bfd_boolean relative_reloc;
5322 bfd_vma orig_value = value;
5323 bfd_boolean resolved_to_zero;
5324 bfd_boolean abs_symbol_p;
5326 globals = elf_aarch64_hash_table (info);
5328 symtab_hdr = &elf_symtab_hdr (input_bfd);
5330 BFD_ASSERT (is_aarch64_elf (input_bfd));
5332 r_symndx = ELFNN_R_SYM (rel->r_info);
5334 place = input_section->output_section->vma
5335 + input_section->output_offset + rel->r_offset;
5337 /* Get addend, accumulating the addend for consecutive relocs
5338 which refer to the same offset. */
5339 signed_addend = saved_addend ? *saved_addend : 0;
5340 signed_addend += rel->r_addend;
5342 weak_undef_p = (h ? h->root.type == bfd_link_hash_undefweak
5343 : bfd_is_und_section (sym_sec));
5344 abs_symbol_p = h != NULL && bfd_is_abs_symbol (&h->root);
5347 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle
5348 it here if it is defined in a non-shared object. */
5350 && h->type == STT_GNU_IFUNC
5357 if ((input_section->flags & SEC_ALLOC) == 0)
5359 /* If this is a SHT_NOTE section without SHF_ALLOC, treat
5360 STT_GNU_IFUNC symbol as STT_FUNC. */
5361 if (elf_section_type (input_section) == SHT_NOTE)
5364 /* Dynamic relocs are not propagated for SEC_DEBUGGING
5365 sections because such sections are not SEC_ALLOC and
5366 thus ld.so will not process them. */
5367 if ((input_section->flags & SEC_DEBUGGING) != 0)
5368 return bfd_reloc_ok;
5370 if (h->root.root.string)
5371 name = h->root.root.string;
5373 name = bfd_elf_sym_name (input_bfd, symtab_hdr, sym, NULL);
5375 /* xgettext:c-format */
5376 (_("%pB(%pA+%#" PRIx64 "): "
5377 "unresolvable %s relocation against symbol `%s'"),
5378 input_bfd, input_section, (uint64_t) rel->r_offset,
5380 bfd_set_error (bfd_error_bad_value);
5381 return bfd_reloc_notsupported;
5383 else if (h->plt.offset == (bfd_vma) -1)
5384 goto bad_ifunc_reloc;
5386 /* STT_GNU_IFUNC symbol must go through PLT. */
5387 plt = globals->root.splt ? globals->root.splt : globals->root.iplt;
5388 value = (plt->output_section->vma + plt->output_offset + h->plt.offset);
5394 if (h->root.root.string)
5395 name = h->root.root.string;
5397 name = bfd_elf_sym_name (input_bfd, symtab_hdr, sym,
5400 /* xgettext:c-format */
5401 (_("%pB: relocation %s against STT_GNU_IFUNC "
5402 "symbol `%s' isn't handled by %s"), input_bfd,
5403 howto->name, name, __FUNCTION__);
5404 bfd_set_error (bfd_error_bad_value);
5405 return bfd_reloc_notsupported;
5407 case BFD_RELOC_AARCH64_NN:
5408 if (rel->r_addend != 0)
5410 if (h->root.root.string)
5411 name = h->root.root.string;
5413 name = bfd_elf_sym_name (input_bfd, symtab_hdr,
5416 /* xgettext:c-format */
5417 (_("%pB: relocation %s against STT_GNU_IFUNC "
5418 "symbol `%s' has non-zero addend: %" PRId64),
5419 input_bfd, howto->name, name, (int64_t) rel->r_addend);
5420 bfd_set_error (bfd_error_bad_value);
5421 return bfd_reloc_notsupported;
5424 /* Generate dynamic relocation only when there is a
5425 non-GOT reference in a shared object. */
5426 if (bfd_link_pic (info) && h->non_got_ref)
5428 Elf_Internal_Rela outrel;
5431 /* Need a dynamic relocation to get the real function
5433 outrel.r_offset = _bfd_elf_section_offset (output_bfd,
5437 if (outrel.r_offset == (bfd_vma) -1
5438 || outrel.r_offset == (bfd_vma) -2)
5441 outrel.r_offset += (input_section->output_section->vma
5442 + input_section->output_offset);
5444 if (h->dynindx == -1
5446 || bfd_link_executable (info))
5448 /* This symbol is resolved locally. */
5449 outrel.r_info = ELFNN_R_INFO (0, AARCH64_R (IRELATIVE));
5450 outrel.r_addend = (h->root.u.def.value
5451 + h->root.u.def.section->output_section->vma
5452 + h->root.u.def.section->output_offset);
5456 outrel.r_info = ELFNN_R_INFO (h->dynindx, r_type);
5457 outrel.r_addend = 0;
5460 sreloc = globals->root.irelifunc;
5461 elf_append_rela (output_bfd, sreloc, &outrel);
5463 /* If this reloc is against an external symbol, we
5464 do not want to fiddle with the addend. Otherwise,
5465 we need to include the symbol value so that it
5466 becomes an addend for the dynamic reloc. For an
5467 internal symbol, we have updated addend. */
5468 return bfd_reloc_ok;
5471 case BFD_RELOC_AARCH64_CALL26:
5472 case BFD_RELOC_AARCH64_JUMP26:
5473 value = _bfd_aarch64_elf_resolve_relocation (bfd_r_type, place, value,
5476 return _bfd_aarch64_elf_put_addend (input_bfd, hit_data, bfd_r_type,
5478 case BFD_RELOC_AARCH64_ADR_GOT_PAGE:
5479 case BFD_RELOC_AARCH64_GOT_LD_PREL19:
5480 case BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14:
5481 case BFD_RELOC_AARCH64_LD32_GOT_LO12_NC:
5482 case BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15:
5483 case BFD_RELOC_AARCH64_MOVW_GOTOFF_G0_NC:
5484 case BFD_RELOC_AARCH64_MOVW_GOTOFF_G1:
5485 case BFD_RELOC_AARCH64_LD64_GOTOFF_LO15:
5486 case BFD_RELOC_AARCH64_LD64_GOT_LO12_NC:
5487 base_got = globals->root.sgot;
5488 off = h->got.offset;
5490 if (base_got == NULL)
5493 if (off == (bfd_vma) -1)
5497 /* We can't use h->got.offset here to save state, or
5498 even just remember the offset, as finish_dynamic_symbol
5499 would use that as offset into .got. */
5501 if (globals->root.splt != NULL)
5503 plt_index = ((h->plt.offset - globals->plt_header_size) /
5504 globals->plt_entry_size);
5505 off = (plt_index + 3) * GOT_ENTRY_SIZE;
5506 base_got = globals->root.sgotplt;
5510 plt_index = h->plt.offset / globals->plt_entry_size;
5511 off = plt_index * GOT_ENTRY_SIZE;
5512 base_got = globals->root.igotplt;
5515 if (h->dynindx == -1
5519 /* This references the local definition. We must
5520 initialize this entry in the global offset table.
5521 Since the offset must always be a multiple of 8,
5522 we use the least significant bit to record
5523 whether we have initialized it already.
5525 When doing a dynamic link, we create a .rela.got
5526 relocation entry to initialize the value. This
5527 is done in the finish_dynamic_symbol routine. */
5532 bfd_put_NN (output_bfd, value,
5533 base_got->contents + off);
5534 /* Note that this is harmless as -1 | 1 still is -1. */
5538 value = (base_got->output_section->vma
5539 + base_got->output_offset + off);
5542 value = aarch64_calculate_got_entry_vma (h, globals, info,
5544 unresolved_reloc_p);
5546 if (aarch64_relocation_aginst_gp_p (bfd_r_type))
5547 addend = (globals->root.sgot->output_section->vma
5548 + globals->root.sgot->output_offset);
5550 value = _bfd_aarch64_elf_resolve_relocation (bfd_r_type, place, value,
5551 addend, weak_undef_p);
5552 return _bfd_aarch64_elf_put_addend (input_bfd, hit_data, bfd_r_type, howto, value);
5553 case BFD_RELOC_AARCH64_ADD_LO12:
5554 case BFD_RELOC_AARCH64_ADR_HI21_PCREL:
5560 resolved_to_zero = (h != NULL
5561 && UNDEFWEAK_NO_DYNAMIC_RELOC (info, h));
5565 case BFD_RELOC_AARCH64_NONE:
5566 case BFD_RELOC_AARCH64_TLSDESC_ADD:
5567 case BFD_RELOC_AARCH64_TLSDESC_CALL:
5568 case BFD_RELOC_AARCH64_TLSDESC_LDR:
5569 *unresolved_reloc_p = FALSE;
5570 return bfd_reloc_ok;
5572 case BFD_RELOC_AARCH64_NN:
5574 /* When generating a shared object or relocatable executable, these
5575 relocations are copied into the output file to be resolved at
5577 if (((bfd_link_pic (info)
5578 || globals->root.is_relocatable_executable)
5579 && (input_section->flags & SEC_ALLOC)
5581 || (ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
5582 && !resolved_to_zero)
5583 || h->root.type != bfd_link_hash_undefweak))
5584 /* Or we are creating an executable, we may need to keep relocations
5585 for symbols satisfied by a dynamic library if we manage to avoid
5586 copy relocs for the symbol. */
5587 || (ELIMINATE_COPY_RELOCS
5588 && !bfd_link_pic (info)
5590 && (input_section->flags & SEC_ALLOC)
5595 || h->root.type == bfd_link_hash_undefweak
5596 || h->root.type == bfd_link_hash_undefined)))
5598 Elf_Internal_Rela outrel;
5600 bfd_boolean skip, relocate;
5603 *unresolved_reloc_p = FALSE;
5608 outrel.r_addend = signed_addend;
5610 _bfd_elf_section_offset (output_bfd, info, input_section,
5612 if (outrel.r_offset == (bfd_vma) - 1)
5614 else if (outrel.r_offset == (bfd_vma) - 2)
5619 else if (abs_symbol_p)
5621 /* Local absolute symbol. */
5622 skip = (h->forced_local || (h->dynindx == -1));
5626 outrel.r_offset += (input_section->output_section->vma
5627 + input_section->output_offset);
5630 memset (&outrel, 0, sizeof outrel);
5633 && (!bfd_link_pic (info)
5634 || !(bfd_link_pie (info) || SYMBOLIC_BIND (info, h))
5635 || !h->def_regular))
5636 outrel.r_info = ELFNN_R_INFO (h->dynindx, r_type);
5641 /* On SVR4-ish systems, the dynamic loader cannot
5642 relocate the text and data segments independently,
5643 so the symbol does not matter. */
5645 relocate = globals->no_apply_dynamic_relocs ? FALSE : TRUE;
5646 outrel.r_info = ELFNN_R_INFO (symbol, AARCH64_R (RELATIVE));
5647 outrel.r_addend += value;
5650 sreloc = elf_section_data (input_section)->sreloc;
5651 if (sreloc == NULL || sreloc->contents == NULL)
5652 return bfd_reloc_notsupported;
5654 loc = sreloc->contents + sreloc->reloc_count++ * RELOC_SIZE (globals);
5655 bfd_elfNN_swap_reloca_out (output_bfd, &outrel, loc);
5657 if (sreloc->reloc_count * RELOC_SIZE (globals) > sreloc->size)
5659 /* Sanity to check that we have previously allocated
5660 sufficient space in the relocation section for the
5661 number of relocations we actually want to emit. */
5665 /* If this reloc is against an external symbol, we do not want to
5666 fiddle with the addend. Otherwise, we need to include the symbol
5667 value so that it becomes an addend for the dynamic reloc. */
5669 return bfd_reloc_ok;
5671 return _bfd_final_link_relocate (howto, input_bfd, input_section,
5672 contents, rel->r_offset, value,
5676 value += signed_addend;
5679 case BFD_RELOC_AARCH64_CALL26:
5680 case BFD_RELOC_AARCH64_JUMP26:
5682 asection *splt = globals->root.splt;
5683 bfd_boolean via_plt_p =
5684 splt != NULL && h != NULL && h->plt.offset != (bfd_vma) - 1;
5686 /* A call to an undefined weak symbol is converted to a jump to
5687 the next instruction unless a PLT entry will be created.
5688 The jump to the next instruction is optimized as a NOP.
5689 Do the same for local undefined symbols. */
5690 if (weak_undef_p && ! via_plt_p)
5692 bfd_putl32 (INSN_NOP, hit_data);
5693 return bfd_reloc_ok;
5696 /* If the call goes through a PLT entry, make sure to
5697 check distance to the right destination address. */
5699 value = (splt->output_section->vma
5700 + splt->output_offset + h->plt.offset);
5702 /* Check if a stub has to be inserted because the destination
5704 struct elf_aarch64_stub_hash_entry *stub_entry = NULL;
5706 /* If the branch destination is directed to plt stub, "value" will be
5707 the final destination, otherwise we should plus signed_addend, it may
5708 contain non-zero value, for example call to local function symbol
5709 which are turned into "sec_sym + sec_off", and sec_off is kept in
5711 if (! aarch64_valid_branch_p (via_plt_p ? value : value + signed_addend,
5713 /* The target is out of reach, so redirect the branch to
5714 the local stub for this function. */
5715 stub_entry = elfNN_aarch64_get_stub_entry (input_section, sym_sec, h,
5717 if (stub_entry != NULL)
5719 value = (stub_entry->stub_offset
5720 + stub_entry->stub_sec->output_offset
5721 + stub_entry->stub_sec->output_section->vma);
5723 /* We have redirected the destination to stub entry address,
5724 so ignore any addend record in the original rela entry. */
5728 value = _bfd_aarch64_elf_resolve_relocation (bfd_r_type, place, value,
5729 signed_addend, weak_undef_p);
5730 *unresolved_reloc_p = FALSE;
5733 case BFD_RELOC_AARCH64_16_PCREL:
5734 case BFD_RELOC_AARCH64_32_PCREL:
5735 case BFD_RELOC_AARCH64_64_PCREL:
5736 case BFD_RELOC_AARCH64_ADR_HI21_NC_PCREL:
5737 case BFD_RELOC_AARCH64_ADR_HI21_PCREL:
5738 case BFD_RELOC_AARCH64_ADR_LO21_PCREL:
5739 case BFD_RELOC_AARCH64_LD_LO19_PCREL:
5740 case BFD_RELOC_AARCH64_MOVW_PREL_G0:
5741 case BFD_RELOC_AARCH64_MOVW_PREL_G0_NC:
5742 case BFD_RELOC_AARCH64_MOVW_PREL_G1:
5743 case BFD_RELOC_AARCH64_MOVW_PREL_G1_NC:
5744 case BFD_RELOC_AARCH64_MOVW_PREL_G2:
5745 case BFD_RELOC_AARCH64_MOVW_PREL_G2_NC:
5746 case BFD_RELOC_AARCH64_MOVW_PREL_G3:
5747 if (bfd_link_pic (info)
5748 && (input_section->flags & SEC_ALLOC) != 0
5749 && (input_section->flags & SEC_READONLY) != 0
5750 && !SYMBOL_REFERENCES_LOCAL (info, h))
5752 int howto_index = bfd_r_type - BFD_RELOC_AARCH64_RELOC_START;
5755 /* xgettext:c-format */
5756 (_("%pB: relocation %s against symbol `%s' which may bind "
5757 "externally can not be used when making a shared object; "
5758 "recompile with -fPIC"),
5759 input_bfd, elfNN_aarch64_howto_table[howto_index].name,
5760 h->root.root.string);
5761 bfd_set_error (bfd_error_bad_value);
5762 return bfd_reloc_notsupported;
5766 case BFD_RELOC_AARCH64_16:
5768 case BFD_RELOC_AARCH64_32:
5770 case BFD_RELOC_AARCH64_ADD_LO12:
5771 case BFD_RELOC_AARCH64_BRANCH19:
5772 case BFD_RELOC_AARCH64_LDST128_LO12:
5773 case BFD_RELOC_AARCH64_LDST16_LO12:
5774 case BFD_RELOC_AARCH64_LDST32_LO12:
5775 case BFD_RELOC_AARCH64_LDST64_LO12:
5776 case BFD_RELOC_AARCH64_LDST8_LO12:
5777 case BFD_RELOC_AARCH64_MOVW_G0:
5778 case BFD_RELOC_AARCH64_MOVW_G0_NC:
5779 case BFD_RELOC_AARCH64_MOVW_G0_S:
5780 case BFD_RELOC_AARCH64_MOVW_G1:
5781 case BFD_RELOC_AARCH64_MOVW_G1_NC:
5782 case BFD_RELOC_AARCH64_MOVW_G1_S:
5783 case BFD_RELOC_AARCH64_MOVW_G2:
5784 case BFD_RELOC_AARCH64_MOVW_G2_NC:
5785 case BFD_RELOC_AARCH64_MOVW_G2_S:
5786 case BFD_RELOC_AARCH64_MOVW_G3:
5787 case BFD_RELOC_AARCH64_TSTBR14:
5788 value = _bfd_aarch64_elf_resolve_relocation (bfd_r_type, place, value,
5789 signed_addend, weak_undef_p);
5792 case BFD_RELOC_AARCH64_ADR_GOT_PAGE:
5793 case BFD_RELOC_AARCH64_GOT_LD_PREL19:
5794 case BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14:
5795 case BFD_RELOC_AARCH64_LD32_GOT_LO12_NC:
5796 case BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15:
5797 case BFD_RELOC_AARCH64_LD64_GOT_LO12_NC:
5798 case BFD_RELOC_AARCH64_LD64_GOTOFF_LO15:
5799 case BFD_RELOC_AARCH64_MOVW_GOTOFF_G0_NC:
5800 case BFD_RELOC_AARCH64_MOVW_GOTOFF_G1:
5801 if (globals->root.sgot == NULL)
5802 BFD_ASSERT (h != NULL);
5804 relative_reloc = FALSE;
5809 /* If a symbol is not dynamic and is not undefined weak, bind it
5810 locally and generate a RELATIVE relocation under PIC mode.
5812 NOTE: one symbol may be referenced by several relocations, we
5813 should only generate one RELATIVE relocation for that symbol.
5814 Therefore, check GOT offset mark first. */
5815 if (h->dynindx == -1
5817 && h->root.type != bfd_link_hash_undefweak
5818 && bfd_link_pic (info)
5819 && !symbol_got_offset_mark_p (input_bfd, h, r_symndx))
5820 relative_reloc = TRUE;
5822 value = aarch64_calculate_got_entry_vma (h, globals, info, value,
5824 unresolved_reloc_p);
5825 /* Record the GOT entry address which will be used when generating
5826 RELATIVE relocation. */
5828 got_entry_addr = value;
5830 if (aarch64_relocation_aginst_gp_p (bfd_r_type))
5831 addend = (globals->root.sgot->output_section->vma
5832 + globals->root.sgot->output_offset);
5833 value = _bfd_aarch64_elf_resolve_relocation (bfd_r_type, place, value,
5834 addend, weak_undef_p);
5839 struct elf_aarch64_local_symbol *locals
5840 = elf_aarch64_locals (input_bfd);
5844 int howto_index = bfd_r_type - BFD_RELOC_AARCH64_RELOC_START;
5846 /* xgettext:c-format */
5847 (_("%pB: local symbol descriptor table be NULL when applying "
5848 "relocation %s against local symbol"),
5849 input_bfd, elfNN_aarch64_howto_table[howto_index].name);
5853 off = symbol_got_offset (input_bfd, h, r_symndx);
5854 base_got = globals->root.sgot;
5855 got_entry_addr = (base_got->output_section->vma
5856 + base_got->output_offset + off);
5858 if (!symbol_got_offset_mark_p (input_bfd, h, r_symndx))
5860 bfd_put_64 (output_bfd, value, base_got->contents + off);
5862 /* For local symbol, we have done absolute relocation in static
5863 linking stage. While for shared library, we need to update the
5864 content of GOT entry according to the shared object's runtime
5865 base address. So, we need to generate a R_AARCH64_RELATIVE reloc
5866 for dynamic linker. */
5867 if (bfd_link_pic (info))
5868 relative_reloc = TRUE;
5870 symbol_got_offset_mark (input_bfd, h, r_symndx);
5873 /* Update the relocation value to GOT entry addr as we have transformed
5874 the direct data access into indirect data access through GOT. */
5875 value = got_entry_addr;
5877 if (aarch64_relocation_aginst_gp_p (bfd_r_type))
5878 addend = base_got->output_section->vma + base_got->output_offset;
5880 value = _bfd_aarch64_elf_resolve_relocation (bfd_r_type, place, value,
5881 addend, weak_undef_p);
5887 Elf_Internal_Rela outrel;
5889 s = globals->root.srelgot;
5893 outrel.r_offset = got_entry_addr;
5894 outrel.r_info = ELFNN_R_INFO (0, AARCH64_R (RELATIVE));
5895 outrel.r_addend = orig_value;
5896 elf_append_rela (output_bfd, s, &outrel);
5900 case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC:
5901 case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21:
5902 case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21:
5903 case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21:
5904 case BFD_RELOC_AARCH64_TLSIE_LD32_GOTTPREL_LO12_NC:
5905 case BFD_RELOC_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC:
5906 case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19:
5907 case BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC:
5908 case BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21:
5909 case BFD_RELOC_AARCH64_TLSLD_ADR_PREL21:
5910 if (globals->root.sgot == NULL)
5911 return bfd_reloc_notsupported;
5913 value = (symbol_got_offset (input_bfd, h, r_symndx)
5914 + globals->root.sgot->output_section->vma
5915 + globals->root.sgot->output_offset);
5917 value = _bfd_aarch64_elf_resolve_relocation (bfd_r_type, place, value,
5919 *unresolved_reloc_p = FALSE;
5922 case BFD_RELOC_AARCH64_TLSGD_MOVW_G0_NC:
5923 case BFD_RELOC_AARCH64_TLSGD_MOVW_G1:
5924 case BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G0_NC:
5925 case BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G1:
5926 if (globals->root.sgot == NULL)
5927 return bfd_reloc_notsupported;
5929 value = symbol_got_offset (input_bfd, h, r_symndx);
5930 value = _bfd_aarch64_elf_resolve_relocation (bfd_r_type, place, value,
5932 *unresolved_reloc_p = FALSE;
5935 case BFD_RELOC_AARCH64_TLSLD_ADD_DTPREL_HI12:
5936 case BFD_RELOC_AARCH64_TLSLD_ADD_DTPREL_LO12:
5937 case BFD_RELOC_AARCH64_TLSLD_ADD_DTPREL_LO12_NC:
5938 case BFD_RELOC_AARCH64_TLSLD_LDST16_DTPREL_LO12:
5939 case BFD_RELOC_AARCH64_TLSLD_LDST16_DTPREL_LO12_NC:
5940 case BFD_RELOC_AARCH64_TLSLD_LDST32_DTPREL_LO12:
5941 case BFD_RELOC_AARCH64_TLSLD_LDST32_DTPREL_LO12_NC:
5942 case BFD_RELOC_AARCH64_TLSLD_LDST64_DTPREL_LO12:
5943 case BFD_RELOC_AARCH64_TLSLD_LDST64_DTPREL_LO12_NC:
5944 case BFD_RELOC_AARCH64_TLSLD_LDST8_DTPREL_LO12:
5945 case BFD_RELOC_AARCH64_TLSLD_LDST8_DTPREL_LO12_NC:
5946 case BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G0:
5947 case BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G0_NC:
5948 case BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G1:
5949 case BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G1_NC:
5950 case BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G2:
5951 value = _bfd_aarch64_elf_resolve_relocation (bfd_r_type, place, value,
5952 signed_addend - dtpoff_base (info),
5956 case BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_HI12:
5957 case BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_LO12:
5958 case BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_LO12_NC:
5959 case BFD_RELOC_AARCH64_TLSLE_LDST16_TPREL_LO12:
5960 case BFD_RELOC_AARCH64_TLSLE_LDST16_TPREL_LO12_NC:
5961 case BFD_RELOC_AARCH64_TLSLE_LDST32_TPREL_LO12:
5962 case BFD_RELOC_AARCH64_TLSLE_LDST32_TPREL_LO12_NC:
5963 case BFD_RELOC_AARCH64_TLSLE_LDST64_TPREL_LO12:
5964 case BFD_RELOC_AARCH64_TLSLE_LDST64_TPREL_LO12_NC:
5965 case BFD_RELOC_AARCH64_TLSLE_LDST8_TPREL_LO12:
5966 case BFD_RELOC_AARCH64_TLSLE_LDST8_TPREL_LO12_NC:
5967 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0:
5968 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC:
5969 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1:
5970 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1_NC:
5971 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G2:
5972 value = _bfd_aarch64_elf_resolve_relocation (bfd_r_type, place, value,
5973 signed_addend - tpoff_base (info),
5975 *unresolved_reloc_p = FALSE;
5978 case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12:
5979 case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21:
5980 case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21:
5981 case BFD_RELOC_AARCH64_TLSDESC_LD32_LO12_NC:
5982 case BFD_RELOC_AARCH64_TLSDESC_LD64_LO12:
5983 case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19:
5984 if (globals->root.sgot == NULL)
5985 return bfd_reloc_notsupported;
5986 value = (symbol_tlsdesc_got_offset (input_bfd, h, r_symndx)
5987 + globals->root.sgotplt->output_section->vma
5988 + globals->root.sgotplt->output_offset
5989 + globals->sgotplt_jump_table_size);
5991 value = _bfd_aarch64_elf_resolve_relocation (bfd_r_type, place, value,
5993 *unresolved_reloc_p = FALSE;
5996 case BFD_RELOC_AARCH64_TLSDESC_OFF_G0_NC:
5997 case BFD_RELOC_AARCH64_TLSDESC_OFF_G1:
5998 if (globals->root.sgot == NULL)
5999 return bfd_reloc_notsupported;
6001 value = (symbol_tlsdesc_got_offset (input_bfd, h, r_symndx)
6002 + globals->root.sgotplt->output_section->vma
6003 + globals->root.sgotplt->output_offset
6004 + globals->sgotplt_jump_table_size);
6006 value -= (globals->root.sgot->output_section->vma
6007 + globals->root.sgot->output_offset);
6009 value = _bfd_aarch64_elf_resolve_relocation (bfd_r_type, place, value,
6011 *unresolved_reloc_p = FALSE;
6015 return bfd_reloc_notsupported;
6019 *saved_addend = value;
6021 /* Only apply the final relocation in a sequence. */
6023 return bfd_reloc_continue;
6025 return _bfd_aarch64_elf_put_addend (input_bfd, hit_data, bfd_r_type,
6029 /* LP64 and ILP32 operates on x- and w-registers respectively.
6030 Next definitions take into account the difference between
6031 corresponding machine codes. R means x-register if the target
6032 arch is LP64, and w-register if the target is ILP32. */
6035 # define add_R0_R0 (0x91000000)
6036 # define add_R0_R0_R1 (0x8b000020)
6037 # define add_R0_R1 (0x91400020)
6038 # define ldr_R0 (0x58000000)
6039 # define ldr_R0_mask(i) (i & 0xffffffe0)
6040 # define ldr_R0_x0 (0xf9400000)
6041 # define ldr_hw_R0 (0xf2a00000)
6042 # define movk_R0 (0xf2800000)
6043 # define movz_R0 (0xd2a00000)
6044 # define movz_hw_R0 (0xd2c00000)
6045 #else /*ARCH_SIZE == 32 */
6046 # define add_R0_R0 (0x11000000)
6047 # define add_R0_R0_R1 (0x0b000020)
6048 # define add_R0_R1 (0x11400020)
6049 # define ldr_R0 (0x18000000)
6050 # define ldr_R0_mask(i) (i & 0xbfffffe0)
6051 # define ldr_R0_x0 (0xb9400000)
6052 # define ldr_hw_R0 (0x72a00000)
6053 # define movk_R0 (0x72800000)
6054 # define movz_R0 (0x52a00000)
6055 # define movz_hw_R0 (0x52c00000)
6058 /* Structure to hold payload for _bfd_aarch64_erratum_843419_clear_stub,
6059 it is used to identify the stub information to reset. */
6061 struct erratum_843419_branch_to_stub_clear_data
6063 bfd_vma adrp_offset;
6064 asection *output_section;
6067 /* Clear the erratum information for GEN_ENTRY if the ADRP_OFFSET and
6068 section inside IN_ARG matches. The clearing is done by setting the
6069 stub_type to none. */
6072 _bfd_aarch64_erratum_843419_clear_stub (struct bfd_hash_entry *gen_entry,
6075 struct elf_aarch64_stub_hash_entry *stub_entry
6076 = (struct elf_aarch64_stub_hash_entry *) gen_entry;
6077 struct erratum_843419_branch_to_stub_clear_data *data
6078 = (struct erratum_843419_branch_to_stub_clear_data *) in_arg;
6080 if (stub_entry->target_section != data->output_section
6081 || stub_entry->stub_type != aarch64_stub_erratum_843419_veneer
6082 || stub_entry->adrp_offset != data->adrp_offset)
6085 /* Change the stub type instead of removing the entry, removing from the hash
6086 table would be slower and we have already reserved the memory for the entry
6087 so there wouldn't be much gain. Changing the stub also keeps around a
6088 record of what was there before. */
6089 stub_entry->stub_type = aarch64_stub_none;
6091 /* We're done and there could have been only one matching stub at that
6092 particular offset, so abort further traversal. */
6096 /* TLS Relaxations may relax an adrp sequence that matches the erratum 843419
6097 sequence. In this case the erratum no longer applies and we need to remove
6098 the entry from the pending stub generation. This clears matching adrp insn
6099 at ADRP_OFFSET in INPUT_SECTION in the stub table defined in GLOBALS. */
6102 clear_erratum_843419_entry (struct elf_aarch64_link_hash_table *globals,
6103 bfd_vma adrp_offset, asection *input_section)
6105 if (globals->fix_erratum_843419)
6107 struct erratum_843419_branch_to_stub_clear_data data;
6108 data.adrp_offset = adrp_offset;
6109 data.output_section = input_section;
6111 bfd_hash_traverse (&globals->stub_hash_table,
6112 _bfd_aarch64_erratum_843419_clear_stub, &data);
6116 /* Handle TLS relaxations. Relaxing is possible for symbols that use
6117 R_AARCH64_TLSDESC_ADR_{PAGE, LD64_LO12_NC, ADD_LO12_NC} during a static
6120 Return bfd_reloc_ok if we're done, bfd_reloc_continue if the caller
6121 is to then call final_link_relocate. Return other values in the
6124 static bfd_reloc_status_type
6125 elfNN_aarch64_tls_relax (struct elf_aarch64_link_hash_table *globals,
6126 bfd *input_bfd, asection *input_section,
6127 bfd_byte *contents, Elf_Internal_Rela *rel,
6128 struct elf_link_hash_entry *h)
6130 bfd_boolean is_local = h == NULL;
6131 unsigned int r_type = ELFNN_R_TYPE (rel->r_info);
6134 BFD_ASSERT (globals && input_bfd && contents && rel);
6136 switch (elfNN_aarch64_bfd_reloc_from_type (input_bfd, r_type))
6138 case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21:
6139 case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21:
6142 /* GD->LE relaxation:
6143 adrp x0, :tlsgd:var => movz R0, :tprel_g1:var
6145 adrp x0, :tlsdesc:var => movz R0, :tprel_g1:var
6147 Where R is x for LP64, and w for ILP32. */
6148 bfd_putl32 (movz_R0, contents + rel->r_offset);
6149 /* We have relaxed the adrp into a mov, we may have to clear any
6150 pending erratum fixes. */
6151 clear_erratum_843419_entry (globals, rel->r_offset, input_section);
6152 return bfd_reloc_continue;
6156 /* GD->IE relaxation:
6157 adrp x0, :tlsgd:var => adrp x0, :gottprel:var
6159 adrp x0, :tlsdesc:var => adrp x0, :gottprel:var
6161 return bfd_reloc_continue;
6164 case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21:
6168 case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19:
6171 /* Tiny TLSDESC->LE relaxation:
6172 ldr x1, :tlsdesc:var => movz R0, #:tprel_g1:var
6173 adr x0, :tlsdesc:var => movk R0, #:tprel_g0_nc:var
6177 Where R is x for LP64, and w for ILP32. */
6178 BFD_ASSERT (ELFNN_R_TYPE (rel[1].r_info) == AARCH64_R (TLSDESC_ADR_PREL21));
6179 BFD_ASSERT (ELFNN_R_TYPE (rel[2].r_info) == AARCH64_R (TLSDESC_CALL));
6181 rel[1].r_info = ELFNN_R_INFO (ELFNN_R_SYM (rel->r_info),
6182 AARCH64_R (TLSLE_MOVW_TPREL_G0_NC));
6183 rel[2].r_info = ELFNN_R_INFO (STN_UNDEF, R_AARCH64_NONE);
6185 bfd_putl32 (movz_R0, contents + rel->r_offset);
6186 bfd_putl32 (movk_R0, contents + rel->r_offset + 4);
6187 bfd_putl32 (INSN_NOP, contents + rel->r_offset + 8);
6188 return bfd_reloc_continue;
6192 /* Tiny TLSDESC->IE relaxation:
6193 ldr x1, :tlsdesc:var => ldr x0, :gottprel:var
6194 adr x0, :tlsdesc:var => nop
6198 BFD_ASSERT (ELFNN_R_TYPE (rel[1].r_info) == AARCH64_R (TLSDESC_ADR_PREL21));
6199 BFD_ASSERT (ELFNN_R_TYPE (rel[2].r_info) == AARCH64_R (TLSDESC_CALL));
6201 rel[1].r_info = ELFNN_R_INFO (STN_UNDEF, R_AARCH64_NONE);
6202 rel[2].r_info = ELFNN_R_INFO (STN_UNDEF, R_AARCH64_NONE);
6204 bfd_putl32 (ldr_R0, contents + rel->r_offset);
6205 bfd_putl32 (INSN_NOP, contents + rel->r_offset + 4);
6206 bfd_putl32 (INSN_NOP, contents + rel->r_offset + 8);
6207 return bfd_reloc_continue;
6210 case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21:
6213 /* Tiny GD->LE relaxation:
6214 adr x0, :tlsgd:var => mrs x1, tpidr_el0
6215 bl __tls_get_addr => add R0, R1, #:tprel_hi12:x, lsl #12
6216 nop => add R0, R0, #:tprel_lo12_nc:x
6218 Where R is x for LP64, and x for Ilp32. */
6220 /* First kill the tls_get_addr reloc on the bl instruction. */
6221 BFD_ASSERT (rel->r_offset + 4 == rel[1].r_offset);
6223 bfd_putl32 (0xd53bd041, contents + rel->r_offset + 0);
6224 bfd_putl32 (add_R0_R1, contents + rel->r_offset + 4);
6225 bfd_putl32 (add_R0_R0, contents + rel->r_offset + 8);
6227 rel[1].r_info = ELFNN_R_INFO (ELFNN_R_SYM (rel->r_info),
6228 AARCH64_R (TLSLE_ADD_TPREL_LO12_NC));
6229 rel[1].r_offset = rel->r_offset + 8;
6231 /* Move the current relocation to the second instruction in
6234 rel->r_info = ELFNN_R_INFO (ELFNN_R_SYM (rel->r_info),
6235 AARCH64_R (TLSLE_ADD_TPREL_HI12));
6236 return bfd_reloc_continue;
6240 /* Tiny GD->IE relaxation:
6241 adr x0, :tlsgd:var => ldr R0, :gottprel:var
6242 bl __tls_get_addr => mrs x1, tpidr_el0
6243 nop => add R0, R0, R1
6245 Where R is x for LP64, and w for Ilp32. */
6247 /* First kill the tls_get_addr reloc on the bl instruction. */
6248 BFD_ASSERT (rel->r_offset + 4 == rel[1].r_offset);
6249 rel[1].r_info = ELFNN_R_INFO (STN_UNDEF, R_AARCH64_NONE);
6251 bfd_putl32 (ldr_R0, contents + rel->r_offset);
6252 bfd_putl32 (0xd53bd041, contents + rel->r_offset + 4);
6253 bfd_putl32 (add_R0_R0_R1, contents + rel->r_offset + 8);
6254 return bfd_reloc_continue;
6258 case BFD_RELOC_AARCH64_TLSGD_MOVW_G1:
6259 BFD_ASSERT (ELFNN_R_TYPE (rel[1].r_info) == AARCH64_R (TLSGD_MOVW_G0_NC));
6260 BFD_ASSERT (rel->r_offset + 12 == rel[2].r_offset);
6261 BFD_ASSERT (ELFNN_R_TYPE (rel[2].r_info) == AARCH64_R (CALL26));
6265 /* Large GD->LE relaxation:
6266 movz x0, #:tlsgd_g1:var => movz x0, #:tprel_g2:var, lsl #32
6267 movk x0, #:tlsgd_g0_nc:var => movk x0, #:tprel_g1_nc:var, lsl #16
6268 add x0, gp, x0 => movk x0, #:tprel_g0_nc:var
6269 bl __tls_get_addr => mrs x1, tpidr_el0
6270 nop => add x0, x0, x1
6272 rel[2].r_info = ELFNN_R_INFO (ELFNN_R_SYM (rel->r_info),
6273 AARCH64_R (TLSLE_MOVW_TPREL_G0_NC));
6274 rel[2].r_offset = rel->r_offset + 8;
6276 bfd_putl32 (movz_hw_R0, contents + rel->r_offset + 0);
6277 bfd_putl32 (ldr_hw_R0, contents + rel->r_offset + 4);
6278 bfd_putl32 (movk_R0, contents + rel->r_offset + 8);
6279 bfd_putl32 (0xd53bd041, contents + rel->r_offset + 12);
6280 bfd_putl32 (add_R0_R0_R1, contents + rel->r_offset + 16);
6284 /* Large GD->IE relaxation:
6285 movz x0, #:tlsgd_g1:var => movz x0, #:gottprel_g1:var, lsl #16
6286 movk x0, #:tlsgd_g0_nc:var => movk x0, #:gottprel_g0_nc:var
6287 add x0, gp, x0 => ldr x0, [gp, x0]
6288 bl __tls_get_addr => mrs x1, tpidr_el0
6289 nop => add x0, x0, x1
6291 rel[2].r_info = ELFNN_R_INFO (STN_UNDEF, R_AARCH64_NONE);
6292 bfd_putl32 (0xd2a80000, contents + rel->r_offset + 0);
6293 bfd_putl32 (ldr_R0, contents + rel->r_offset + 8);
6294 bfd_putl32 (0xd53bd041, contents + rel->r_offset + 12);
6295 bfd_putl32 (add_R0_R0_R1, contents + rel->r_offset + 16);
6297 return bfd_reloc_continue;
6299 case BFD_RELOC_AARCH64_TLSGD_MOVW_G0_NC:
6300 return bfd_reloc_continue;
6303 case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19:
6304 return bfd_reloc_continue;
6306 case BFD_RELOC_AARCH64_TLSDESC_LDNN_LO12_NC:
6309 /* GD->LE relaxation:
6310 ldr xd, [x0, #:tlsdesc_lo12:var] => movk x0, :tprel_g0_nc:var
6312 Where R is x for lp64 mode, and w for ILP32 mode. */
6313 bfd_putl32 (movk_R0, contents + rel->r_offset);
6314 return bfd_reloc_continue;
6318 /* GD->IE relaxation:
6319 ldr xd, [x0, #:tlsdesc_lo12:var] => ldr R0, [x0, #:gottprel_lo12:var]
6321 Where R is x for lp64 mode, and w for ILP32 mode. */
6322 insn = bfd_getl32 (contents + rel->r_offset);
6323 bfd_putl32 (ldr_R0_mask (insn), contents + rel->r_offset);
6324 return bfd_reloc_continue;
6327 case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC:
6330 /* GD->LE relaxation
6331 add x0, #:tlsgd_lo12:var => movk R0, :tprel_g0_nc:var
6332 bl __tls_get_addr => mrs x1, tpidr_el0
6333 nop => add R0, R1, R0
6335 Where R is x for lp64 mode, and w for ILP32 mode. */
6337 /* First kill the tls_get_addr reloc on the bl instruction. */
6338 BFD_ASSERT (rel->r_offset + 4 == rel[1].r_offset);
6339 rel[1].r_info = ELFNN_R_INFO (STN_UNDEF, R_AARCH64_NONE);
6341 bfd_putl32 (movk_R0, contents + rel->r_offset);
6342 bfd_putl32 (0xd53bd041, contents + rel->r_offset + 4);
6343 bfd_putl32 (add_R0_R0_R1, contents + rel->r_offset + 8);
6344 return bfd_reloc_continue;
6348 /* GD->IE relaxation
6349 ADD x0, #:tlsgd_lo12:var => ldr R0, [x0, #:gottprel_lo12:var]
6350 BL __tls_get_addr => mrs x1, tpidr_el0
6352 NOP => add R0, R1, R0
6354 Where R is x for lp64 mode, and w for ilp32 mode. */
6356 BFD_ASSERT (ELFNN_R_TYPE (rel[1].r_info) == AARCH64_R (CALL26));
6358 /* Remove the relocation on the BL instruction. */
6359 rel[1].r_info = ELFNN_R_INFO (STN_UNDEF, R_AARCH64_NONE);
6361 /* We choose to fixup the BL and NOP instructions using the
6362 offset from the second relocation to allow flexibility in
6363 scheduling instructions between the ADD and BL. */
6364 bfd_putl32 (ldr_R0_x0, contents + rel->r_offset);
6365 bfd_putl32 (0xd53bd041, contents + rel[1].r_offset);
6366 bfd_putl32 (add_R0_R0_R1, contents + rel[1].r_offset + 4);
6367 return bfd_reloc_continue;
6370 case BFD_RELOC_AARCH64_TLSDESC_ADD:
6371 case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12:
6372 case BFD_RELOC_AARCH64_TLSDESC_CALL:
6373 /* GD->IE/LE relaxation:
6374 add x0, x0, #:tlsdesc_lo12:var => nop
6377 bfd_putl32 (INSN_NOP, contents + rel->r_offset);
6378 return bfd_reloc_ok;
6380 case BFD_RELOC_AARCH64_TLSDESC_LDR:
6383 /* GD->LE relaxation:
6384 ldr xd, [gp, xn] => movk R0, #:tprel_g0_nc:var
6386 Where R is x for lp64 mode, and w for ILP32 mode. */
6387 bfd_putl32 (movk_R0, contents + rel->r_offset);
6388 return bfd_reloc_continue;
6392 /* GD->IE relaxation:
6393 ldr xd, [gp, xn] => ldr R0, [gp, xn]
6395 Where R is x for lp64 mode, and w for ILP32 mode. */
6396 insn = bfd_getl32 (contents + rel->r_offset);
6397 bfd_putl32 (ldr_R0_mask (insn), contents + rel->r_offset);
6398 return bfd_reloc_ok;
6401 case BFD_RELOC_AARCH64_TLSDESC_OFF_G0_NC:
6402 /* GD->LE relaxation:
6403 movk xd, #:tlsdesc_off_g0_nc:var => movk R0, #:tprel_g1_nc:var, lsl #16
6405 movk xd, #:tlsdesc_off_g0_nc:var => movk Rd, #:gottprel_g0_nc:var
6407 Where R is x for lp64 mode, and w for ILP32 mode. */
6409 bfd_putl32 (ldr_hw_R0, contents + rel->r_offset);
6410 return bfd_reloc_continue;
6412 case BFD_RELOC_AARCH64_TLSDESC_OFF_G1:
6415 /* GD->LE relaxation:
6416 movz xd, #:tlsdesc_off_g1:var => movz R0, #:tprel_g2:var, lsl #32
6418 Where R is x for lp64 mode, and w for ILP32 mode. */
6419 bfd_putl32 (movz_hw_R0, contents + rel->r_offset);
6420 return bfd_reloc_continue;
6424 /* GD->IE relaxation:
6425 movz xd, #:tlsdesc_off_g1:var => movz Rd, #:gottprel_g1:var, lsl #16
6427 Where R is x for lp64 mode, and w for ILP32 mode. */
6428 insn = bfd_getl32 (contents + rel->r_offset);
6429 bfd_putl32 (movz_R0 | (insn & 0x1f), contents + rel->r_offset);
6430 return bfd_reloc_continue;
6433 case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21:
6434 /* IE->LE relaxation:
6435 adrp xd, :gottprel:var => movz Rd, :tprel_g1:var
6437 Where R is x for lp64 mode, and w for ILP32 mode. */
6440 insn = bfd_getl32 (contents + rel->r_offset);
6441 bfd_putl32 (movz_R0 | (insn & 0x1f), contents + rel->r_offset);
6442 /* We have relaxed the adrp into a mov, we may have to clear any
6443 pending erratum fixes. */
6444 clear_erratum_843419_entry (globals, rel->r_offset, input_section);
6446 return bfd_reloc_continue;
6448 case BFD_RELOC_AARCH64_TLSIE_LDNN_GOTTPREL_LO12_NC:
6449 /* IE->LE relaxation:
6450 ldr xd, [xm, #:gottprel_lo12:var] => movk Rd, :tprel_g0_nc:var
6452 Where R is x for lp64 mode, and w for ILP32 mode. */
6455 insn = bfd_getl32 (contents + rel->r_offset);
6456 bfd_putl32 (movk_R0 | (insn & 0x1f), contents + rel->r_offset);
6458 return bfd_reloc_continue;
6460 case BFD_RELOC_AARCH64_TLSLD_ADR_PREL21:
6461 /* LD->LE relaxation (tiny):
6462 adr x0, :tlsldm:x => mrs x0, tpidr_el0
6463 bl __tls_get_addr => add R0, R0, TCB_SIZE
6465 Where R is x for lp64 mode, and w for ilp32 mode. */
6468 BFD_ASSERT (rel->r_offset + 4 == rel[1].r_offset);
6469 BFD_ASSERT (ELFNN_R_TYPE (rel[1].r_info) == AARCH64_R (CALL26));
6470 /* No need of CALL26 relocation for tls_get_addr. */
6471 rel[1].r_info = ELFNN_R_INFO (STN_UNDEF, R_AARCH64_NONE);
6472 bfd_putl32 (0xd53bd040, contents + rel->r_offset + 0);
6473 bfd_putl32 (add_R0_R0 | (TCB_SIZE << 10),
6474 contents + rel->r_offset + 4);
6475 return bfd_reloc_ok;
6477 return bfd_reloc_continue;
6479 case BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21:
6480 /* LD->LE relaxation (small):
6481 adrp x0, :tlsldm:x => mrs x0, tpidr_el0
6485 bfd_putl32 (0xd53bd040, contents + rel->r_offset);
6486 return bfd_reloc_ok;
6488 return bfd_reloc_continue;
6490 case BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC:
6491 /* LD->LE relaxation (small):
6492 add x0, #:tlsldm_lo12:x => add R0, R0, TCB_SIZE
6493 bl __tls_get_addr => nop
6495 Where R is x for lp64 mode, and w for ilp32 mode. */
6498 BFD_ASSERT (rel->r_offset + 4 == rel[1].r_offset);
6499 BFD_ASSERT (ELFNN_R_TYPE (rel[1].r_info) == AARCH64_R (CALL26));
6500 /* No need of CALL26 relocation for tls_get_addr. */
6501 rel[1].r_info = ELFNN_R_INFO (STN_UNDEF, R_AARCH64_NONE);
6502 bfd_putl32 (add_R0_R0 | (TCB_SIZE << 10),
6503 contents + rel->r_offset + 0);
6504 bfd_putl32 (INSN_NOP, contents + rel->r_offset + 4);
6505 return bfd_reloc_ok;
6507 return bfd_reloc_continue;
6510 return bfd_reloc_continue;
6513 return bfd_reloc_ok;
6516 /* Relocate an AArch64 ELF section. */
6519 elfNN_aarch64_relocate_section (bfd *output_bfd,
6520 struct bfd_link_info *info,
6522 asection *input_section,
6524 Elf_Internal_Rela *relocs,
6525 Elf_Internal_Sym *local_syms,
6526 asection **local_sections)
6528 Elf_Internal_Shdr *symtab_hdr;
6529 struct elf_link_hash_entry **sym_hashes;
6530 Elf_Internal_Rela *rel;
6531 Elf_Internal_Rela *relend;
6533 struct elf_aarch64_link_hash_table *globals;
6534 bfd_boolean save_addend = FALSE;
6537 globals = elf_aarch64_hash_table (info);
6539 symtab_hdr = &elf_symtab_hdr (input_bfd);
6540 sym_hashes = elf_sym_hashes (input_bfd);
6543 relend = relocs + input_section->reloc_count;
6544 for (; rel < relend; rel++)
6546 unsigned int r_type;
6547 bfd_reloc_code_real_type bfd_r_type;
6548 bfd_reloc_code_real_type relaxed_bfd_r_type;
6549 reloc_howto_type *howto;
6550 unsigned long r_symndx;
6551 Elf_Internal_Sym *sym;
6553 struct elf_link_hash_entry *h;
6555 bfd_reloc_status_type r;
6558 bfd_boolean unresolved_reloc = FALSE;
6559 char *error_message = NULL;
6561 r_symndx = ELFNN_R_SYM (rel->r_info);
6562 r_type = ELFNN_R_TYPE (rel->r_info);
6564 bfd_reloc.howto = elfNN_aarch64_howto_from_type (input_bfd, r_type);
6565 howto = bfd_reloc.howto;
6568 return _bfd_unrecognized_reloc (input_bfd, input_section, r_type);
6570 bfd_r_type = elfNN_aarch64_bfd_reloc_from_howto (howto);
6576 if (r_symndx < symtab_hdr->sh_info)
6578 sym = local_syms + r_symndx;
6579 sym_type = ELFNN_ST_TYPE (sym->st_info);
6580 sec = local_sections[r_symndx];
6582 /* An object file might have a reference to a local
6583 undefined symbol. This is a daft object file, but we
6584 should at least do something about it. */
6585 if (r_type != R_AARCH64_NONE && r_type != R_AARCH64_NULL
6586 && bfd_is_und_section (sec)
6587 && ELF_ST_BIND (sym->st_info) != STB_WEAK)
6588 (*info->callbacks->undefined_symbol)
6589 (info, bfd_elf_string_from_elf_section
6590 (input_bfd, symtab_hdr->sh_link, sym->st_name),
6591 input_bfd, input_section, rel->r_offset, TRUE);
6593 relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel);
6595 /* Relocate against local STT_GNU_IFUNC symbol. */
6596 if (!bfd_link_relocatable (info)
6597 && ELF_ST_TYPE (sym->st_info) == STT_GNU_IFUNC)
6599 h = elfNN_aarch64_get_local_sym_hash (globals, input_bfd,
6604 /* Set STT_GNU_IFUNC symbol value. */
6605 h->root.u.def.value = sym->st_value;
6606 h->root.u.def.section = sec;
6611 bfd_boolean warned, ignored;
6613 RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel,
6614 r_symndx, symtab_hdr, sym_hashes,
6616 unresolved_reloc, warned, ignored);
6621 if (sec != NULL && discarded_section (sec))
6622 RELOC_AGAINST_DISCARDED_SECTION (info, input_bfd, input_section,
6623 rel, 1, relend, howto, 0, contents);
6625 if (bfd_link_relocatable (info))
6629 name = h->root.root.string;
6632 name = (bfd_elf_string_from_elf_section
6633 (input_bfd, symtab_hdr->sh_link, sym->st_name));
6634 if (name == NULL || *name == '\0')
6635 name = bfd_section_name (input_bfd, sec);
6639 && r_type != R_AARCH64_NONE
6640 && r_type != R_AARCH64_NULL
6642 || h->root.type == bfd_link_hash_defined
6643 || h->root.type == bfd_link_hash_defweak)
6644 && IS_AARCH64_TLS_RELOC (bfd_r_type) != (sym_type == STT_TLS))
6647 ((sym_type == STT_TLS
6648 /* xgettext:c-format */
6649 ? _("%pB(%pA+%#" PRIx64 "): %s used with TLS symbol %s")
6650 /* xgettext:c-format */
6651 : _("%pB(%pA+%#" PRIx64 "): %s used with non-TLS symbol %s")),
6653 input_section, (uint64_t) rel->r_offset, howto->name, name);
6656 /* We relax only if we can see that there can be a valid transition
6657 from a reloc type to another.
6658 We call elfNN_aarch64_final_link_relocate unless we're completely
6659 done, i.e., the relaxation produced the final output we want. */
6661 relaxed_bfd_r_type = aarch64_tls_transition (input_bfd, info, r_type,
6663 if (relaxed_bfd_r_type != bfd_r_type)
6665 bfd_r_type = relaxed_bfd_r_type;
6666 howto = elfNN_aarch64_howto_from_bfd_reloc (bfd_r_type);
6667 BFD_ASSERT (howto != NULL);
6668 r_type = howto->type;
6669 r = elfNN_aarch64_tls_relax (globals, input_bfd, input_section,
6671 unresolved_reloc = 0;
6674 r = bfd_reloc_continue;
6676 /* There may be multiple consecutive relocations for the
6677 same offset. In that case we are supposed to treat the
6678 output of each relocation as the addend for the next. */
6679 if (rel + 1 < relend
6680 && rel->r_offset == rel[1].r_offset
6681 && ELFNN_R_TYPE (rel[1].r_info) != R_AARCH64_NONE
6682 && ELFNN_R_TYPE (rel[1].r_info) != R_AARCH64_NULL)
6685 save_addend = FALSE;
6687 if (r == bfd_reloc_continue)
6688 r = elfNN_aarch64_final_link_relocate (howto, input_bfd, output_bfd,
6689 input_section, contents, rel,
6690 relocation, info, sec,
6691 h, &unresolved_reloc,
6692 save_addend, &addend, sym);
6694 switch (elfNN_aarch64_bfd_reloc_from_type (input_bfd, r_type))
6696 case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC:
6697 case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21:
6698 case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21:
6699 case BFD_RELOC_AARCH64_TLSGD_MOVW_G0_NC:
6700 case BFD_RELOC_AARCH64_TLSGD_MOVW_G1:
6701 case BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC:
6702 case BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21:
6703 case BFD_RELOC_AARCH64_TLSLD_ADR_PREL21:
6704 if (! symbol_got_offset_mark_p (input_bfd, h, r_symndx))
6706 bfd_boolean need_relocs = FALSE;
6711 off = symbol_got_offset (input_bfd, h, r_symndx);
6712 indx = h && h->dynindx != -1 ? h->dynindx : 0;
6715 (!bfd_link_executable (info) || indx != 0) &&
6717 || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
6718 || h->root.type != bfd_link_hash_undefweak);
6720 BFD_ASSERT (globals->root.srelgot != NULL);
6724 Elf_Internal_Rela rela;
6725 rela.r_info = ELFNN_R_INFO (indx, AARCH64_R (TLS_DTPMOD));
6727 rela.r_offset = globals->root.sgot->output_section->vma +
6728 globals->root.sgot->output_offset + off;
6731 loc = globals->root.srelgot->contents;
6732 loc += globals->root.srelgot->reloc_count++
6733 * RELOC_SIZE (htab);
6734 bfd_elfNN_swap_reloca_out (output_bfd, &rela, loc);
6736 bfd_reloc_code_real_type real_type =
6737 elfNN_aarch64_bfd_reloc_from_type (input_bfd, r_type);
6739 if (real_type == BFD_RELOC_AARCH64_TLSLD_ADR_PREL21
6740 || real_type == BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21
6741 || real_type == BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC)
6743 /* For local dynamic, don't generate DTPREL in any case.
6744 Initialize the DTPREL slot into zero, so we get module
6745 base address when invoke runtime TLS resolver. */
6746 bfd_put_NN (output_bfd, 0,
6747 globals->root.sgot->contents + off
6752 bfd_put_NN (output_bfd,
6753 relocation - dtpoff_base (info),
6754 globals->root.sgot->contents + off
6759 /* This TLS symbol is global. We emit a
6760 relocation to fixup the tls offset at load
6763 ELFNN_R_INFO (indx, AARCH64_R (TLS_DTPREL));
6766 (globals->root.sgot->output_section->vma
6767 + globals->root.sgot->output_offset + off
6770 loc = globals->root.srelgot->contents;
6771 loc += globals->root.srelgot->reloc_count++
6772 * RELOC_SIZE (globals);
6773 bfd_elfNN_swap_reloca_out (output_bfd, &rela, loc);
6774 bfd_put_NN (output_bfd, (bfd_vma) 0,
6775 globals->root.sgot->contents + off
6781 bfd_put_NN (output_bfd, (bfd_vma) 1,
6782 globals->root.sgot->contents + off);
6783 bfd_put_NN (output_bfd,
6784 relocation - dtpoff_base (info),
6785 globals->root.sgot->contents + off
6789 symbol_got_offset_mark (input_bfd, h, r_symndx);
6793 case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21:
6794 case BFD_RELOC_AARCH64_TLSIE_LDNN_GOTTPREL_LO12_NC:
6795 case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19:
6796 case BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G0_NC:
6797 case BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G1:
6798 if (! symbol_got_offset_mark_p (input_bfd, h, r_symndx))
6800 bfd_boolean need_relocs = FALSE;
6805 off = symbol_got_offset (input_bfd, h, r_symndx);
6807 indx = h && h->dynindx != -1 ? h->dynindx : 0;
6810 (!bfd_link_executable (info) || indx != 0) &&
6812 || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
6813 || h->root.type != bfd_link_hash_undefweak);
6815 BFD_ASSERT (globals->root.srelgot != NULL);
6819 Elf_Internal_Rela rela;
6822 rela.r_addend = relocation - dtpoff_base (info);
6826 rela.r_info = ELFNN_R_INFO (indx, AARCH64_R (TLS_TPREL));
6827 rela.r_offset = globals->root.sgot->output_section->vma +
6828 globals->root.sgot->output_offset + off;
6830 loc = globals->root.srelgot->contents;
6831 loc += globals->root.srelgot->reloc_count++
6832 * RELOC_SIZE (htab);
6834 bfd_elfNN_swap_reloca_out (output_bfd, &rela, loc);
6836 bfd_put_NN (output_bfd, rela.r_addend,
6837 globals->root.sgot->contents + off);
6840 bfd_put_NN (output_bfd, relocation - tpoff_base (info),
6841 globals->root.sgot->contents + off);
6843 symbol_got_offset_mark (input_bfd, h, r_symndx);
6847 case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12:
6848 case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21:
6849 case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21:
6850 case BFD_RELOC_AARCH64_TLSDESC_LDNN_LO12_NC:
6851 case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19:
6852 case BFD_RELOC_AARCH64_TLSDESC_OFF_G0_NC:
6853 case BFD_RELOC_AARCH64_TLSDESC_OFF_G1:
6854 if (! symbol_tlsdesc_got_offset_mark_p (input_bfd, h, r_symndx))
6856 bfd_boolean need_relocs = FALSE;
6857 int indx = h && h->dynindx != -1 ? h->dynindx : 0;
6858 bfd_vma off = symbol_tlsdesc_got_offset (input_bfd, h, r_symndx);
6860 need_relocs = (h == NULL
6861 || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
6862 || h->root.type != bfd_link_hash_undefweak);
6864 BFD_ASSERT (globals->root.srelgot != NULL);
6865 BFD_ASSERT (globals->root.sgot != NULL);
6870 Elf_Internal_Rela rela;
6871 rela.r_info = ELFNN_R_INFO (indx, AARCH64_R (TLSDESC));
6874 rela.r_offset = (globals->root.sgotplt->output_section->vma
6875 + globals->root.sgotplt->output_offset
6876 + off + globals->sgotplt_jump_table_size);
6879 rela.r_addend = relocation - dtpoff_base (info);
6881 /* Allocate the next available slot in the PLT reloc
6882 section to hold our R_AARCH64_TLSDESC, the next
6883 available slot is determined from reloc_count,
6884 which we step. But note, reloc_count was
6885 artifically moved down while allocating slots for
6886 real PLT relocs such that all of the PLT relocs
6887 will fit above the initial reloc_count and the
6888 extra stuff will fit below. */
6889 loc = globals->root.srelplt->contents;
6890 loc += globals->root.srelplt->reloc_count++
6891 * RELOC_SIZE (globals);
6893 bfd_elfNN_swap_reloca_out (output_bfd, &rela, loc);
6895 bfd_put_NN (output_bfd, (bfd_vma) 0,
6896 globals->root.sgotplt->contents + off +
6897 globals->sgotplt_jump_table_size);
6898 bfd_put_NN (output_bfd, (bfd_vma) 0,
6899 globals->root.sgotplt->contents + off +
6900 globals->sgotplt_jump_table_size +
6904 symbol_tlsdesc_got_offset_mark (input_bfd, h, r_symndx);
6911 /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
6912 because such sections are not SEC_ALLOC and thus ld.so will
6913 not process them. */
6914 if (unresolved_reloc
6915 && !((input_section->flags & SEC_DEBUGGING) != 0
6917 && _bfd_elf_section_offset (output_bfd, info, input_section,
6918 +rel->r_offset) != (bfd_vma) - 1)
6921 /* xgettext:c-format */
6922 (_("%pB(%pA+%#" PRIx64 "): "
6923 "unresolvable %s relocation against symbol `%s'"),
6924 input_bfd, input_section, (uint64_t) rel->r_offset, howto->name,
6925 h->root.root.string);
6929 if (r != bfd_reloc_ok && r != bfd_reloc_continue)
6931 bfd_reloc_code_real_type real_r_type
6932 = elfNN_aarch64_bfd_reloc_from_type (input_bfd, r_type);
6936 case bfd_reloc_overflow:
6937 (*info->callbacks->reloc_overflow)
6938 (info, (h ? &h->root : NULL), name, howto->name, (bfd_vma) 0,
6939 input_bfd, input_section, rel->r_offset);
6940 if (real_r_type == BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15
6941 || real_r_type == BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14)
6943 (*info->callbacks->warning)
6945 _("too many GOT entries for -fpic, "
6946 "please recompile with -fPIC"),
6947 name, input_bfd, input_section, rel->r_offset);
6950 /* Overflow can occur when a variable is referenced with a type
6951 that has a larger alignment than the type with which it was
6953 file1.c: extern int foo; int a (void) { return foo; }
6954 file2.c: char bar, foo, baz;
6955 If the variable is placed into a data section at an offset
6956 that is incompatible with the larger alignment requirement
6957 overflow will occur. (Strictly speaking this is not overflow
6958 but rather an alignment problem, but the bfd_reloc_ error
6959 enum does not have a value to cover that situation).
6961 Try to catch this situation here and provide a more helpful
6962 error message to the user. */
6963 if (addend & ((1 << howto->rightshift) - 1)
6964 /* FIXME: Are we testing all of the appropriate reloc
6966 && (real_r_type == BFD_RELOC_AARCH64_LD_LO19_PCREL
6967 || real_r_type == BFD_RELOC_AARCH64_LDST16_LO12
6968 || real_r_type == BFD_RELOC_AARCH64_LDST32_LO12
6969 || real_r_type == BFD_RELOC_AARCH64_LDST64_LO12
6970 || real_r_type == BFD_RELOC_AARCH64_LDST128_LO12))
6972 info->callbacks->warning
6973 (info, _("one possible cause of this error is that the \
6974 symbol is being referenced in the indicated code as if it had a larger \
6975 alignment than was declared where it was defined"),
6976 name, input_bfd, input_section, rel->r_offset);
6980 case bfd_reloc_undefined:
6981 (*info->callbacks->undefined_symbol)
6982 (info, name, input_bfd, input_section, rel->r_offset, TRUE);
6985 case bfd_reloc_outofrange:
6986 error_message = _("out of range");
6989 case bfd_reloc_notsupported:
6990 error_message = _("unsupported relocation");
6993 case bfd_reloc_dangerous:
6994 /* error_message should already be set. */
6998 error_message = _("unknown error");
7002 BFD_ASSERT (error_message != NULL);
7003 (*info->callbacks->reloc_dangerous)
7004 (info, error_message, input_bfd, input_section, rel->r_offset);
7016 /* Set the right machine number. */
7019 elfNN_aarch64_object_p (bfd *abfd)
7022 bfd_default_set_arch_mach (abfd, bfd_arch_aarch64, bfd_mach_aarch64_ilp32);
7024 bfd_default_set_arch_mach (abfd, bfd_arch_aarch64, bfd_mach_aarch64);
7029 /* Function to keep AArch64 specific flags in the ELF header. */
7032 elfNN_aarch64_set_private_flags (bfd *abfd, flagword flags)
7034 if (elf_flags_init (abfd) && elf_elfheader (abfd)->e_flags != flags)
7039 elf_elfheader (abfd)->e_flags = flags;
7040 elf_flags_init (abfd) = TRUE;
7046 /* Merge backend specific data from an object file to the output
7047 object file when linking. */
7050 elfNN_aarch64_merge_private_bfd_data (bfd *ibfd, struct bfd_link_info *info)
7052 bfd *obfd = info->output_bfd;
7055 bfd_boolean flags_compatible = TRUE;
7058 /* Check if we have the same endianess. */
7059 if (!_bfd_generic_verify_endian_match (ibfd, info))
7062 if (!is_aarch64_elf (ibfd) || !is_aarch64_elf (obfd))
7065 /* The input BFD must have had its flags initialised. */
7066 /* The following seems bogus to me -- The flags are initialized in
7067 the assembler but I don't think an elf_flags_init field is
7068 written into the object. */
7069 /* BFD_ASSERT (elf_flags_init (ibfd)); */
7071 in_flags = elf_elfheader (ibfd)->e_flags;
7072 out_flags = elf_elfheader (obfd)->e_flags;
7074 if (!elf_flags_init (obfd))
7076 /* If the input is the default architecture and had the default
7077 flags then do not bother setting the flags for the output
7078 architecture, instead allow future merges to do this. If no
7079 future merges ever set these flags then they will retain their
7080 uninitialised values, which surprise surprise, correspond
7081 to the default values. */
7082 if (bfd_get_arch_info (ibfd)->the_default
7083 && elf_elfheader (ibfd)->e_flags == 0)
7086 elf_flags_init (obfd) = TRUE;
7087 elf_elfheader (obfd)->e_flags = in_flags;
7089 if (bfd_get_arch (obfd) == bfd_get_arch (ibfd)
7090 && bfd_get_arch_info (obfd)->the_default)
7091 return bfd_set_arch_mach (obfd, bfd_get_arch (ibfd),
7092 bfd_get_mach (ibfd));
7097 /* Identical flags must be compatible. */
7098 if (in_flags == out_flags)
7101 /* Check to see if the input BFD actually contains any sections. If
7102 not, its flags may not have been initialised either, but it
7103 cannot actually cause any incompatiblity. Do not short-circuit
7104 dynamic objects; their section list may be emptied by
7105 elf_link_add_object_symbols.
7107 Also check to see if there are no code sections in the input.
7108 In this case there is no need to check for code specific flags.
7109 XXX - do we need to worry about floating-point format compatability
7110 in data sections ? */
7111 if (!(ibfd->flags & DYNAMIC))
7113 bfd_boolean null_input_bfd = TRUE;
7114 bfd_boolean only_data_sections = TRUE;
7116 for (sec = ibfd->sections; sec != NULL; sec = sec->next)
7118 if ((bfd_get_section_flags (ibfd, sec)
7119 & (SEC_LOAD | SEC_CODE | SEC_HAS_CONTENTS))
7120 == (SEC_LOAD | SEC_CODE | SEC_HAS_CONTENTS))
7121 only_data_sections = FALSE;
7123 null_input_bfd = FALSE;
7127 if (null_input_bfd || only_data_sections)
7131 return flags_compatible;
7134 /* Display the flags field. */
7137 elfNN_aarch64_print_private_bfd_data (bfd *abfd, void *ptr)
7139 FILE *file = (FILE *) ptr;
7140 unsigned long flags;
7142 BFD_ASSERT (abfd != NULL && ptr != NULL);
7144 /* Print normal ELF private data. */
7145 _bfd_elf_print_private_bfd_data (abfd, ptr);
7147 flags = elf_elfheader (abfd)->e_flags;
7148 /* Ignore init flag - it may not be set, despite the flags field
7149 containing valid data. */
7151 /* xgettext:c-format */
7152 fprintf (file, _("private flags = %lx:"), elf_elfheader (abfd)->e_flags);
7155 fprintf (file, _("<Unrecognised flag bits set>"));
7162 /* Find dynamic relocs for H that apply to read-only sections. */
7165 readonly_dynrelocs (struct elf_link_hash_entry *h)
7167 struct elf_dyn_relocs *p;
7169 for (p = elf_aarch64_hash_entry (h)->dyn_relocs; p != NULL; p = p->next)
7171 asection *s = p->sec->output_section;
7173 if (s != NULL && (s->flags & SEC_READONLY) != 0)
7179 /* Return true if we need copy relocation against EH. */
7182 need_copy_relocation_p (struct elf_aarch64_link_hash_entry *eh)
7184 struct elf_dyn_relocs *p;
7187 for (p = eh->dyn_relocs; p != NULL; p = p->next)
7189 /* If there is any pc-relative reference, we need to keep copy relocation
7190 to avoid propagating the relocation into runtime that current glibc
7191 does not support. */
7195 s = p->sec->output_section;
7196 /* Need copy relocation if it's against read-only section. */
7197 if (s != NULL && (s->flags & SEC_READONLY) != 0)
7204 /* Adjust a symbol defined by a dynamic object and referenced by a
7205 regular object. The current definition is in some section of the
7206 dynamic object, but we're not including those sections. We have to
7207 change the definition to something the rest of the link can
7211 elfNN_aarch64_adjust_dynamic_symbol (struct bfd_link_info *info,
7212 struct elf_link_hash_entry *h)
7214 struct elf_aarch64_link_hash_table *htab;
7217 /* If this is a function, put it in the procedure linkage table. We
7218 will fill in the contents of the procedure linkage table later,
7219 when we know the address of the .got section. */
7220 if (h->type == STT_FUNC || h->type == STT_GNU_IFUNC || h->needs_plt)
7222 if (h->plt.refcount <= 0
7223 || (h->type != STT_GNU_IFUNC
7224 && (SYMBOL_CALLS_LOCAL (info, h)
7225 || (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
7226 && h->root.type == bfd_link_hash_undefweak))))
7228 /* This case can occur if we saw a CALL26 reloc in
7229 an input file, but the symbol wasn't referred to
7230 by a dynamic object or all references were
7231 garbage collected. In which case we can end up
7233 h->plt.offset = (bfd_vma) - 1;
7240 /* Otherwise, reset to -1. */
7241 h->plt.offset = (bfd_vma) - 1;
7244 /* If this is a weak symbol, and there is a real definition, the
7245 processor independent code will have arranged for us to see the
7246 real definition first, and we can just use the same value. */
7247 if (h->is_weakalias)
7249 struct elf_link_hash_entry *def = weakdef (h);
7250 BFD_ASSERT (def->root.type == bfd_link_hash_defined);
7251 h->root.u.def.section = def->root.u.def.section;
7252 h->root.u.def.value = def->root.u.def.value;
7253 if (ELIMINATE_COPY_RELOCS || info->nocopyreloc)
7254 h->non_got_ref = def->non_got_ref;
7258 /* If we are creating a shared library, we must presume that the
7259 only references to the symbol are via the global offset table.
7260 For such cases we need not do anything here; the relocations will
7261 be handled correctly by relocate_section. */
7262 if (bfd_link_pic (info))
7265 /* If there are no references to this symbol that do not use the
7266 GOT, we don't need to generate a copy reloc. */
7267 if (!h->non_got_ref)
7270 /* If -z nocopyreloc was given, we won't generate them either. */
7271 if (info->nocopyreloc)
7277 if (ELIMINATE_COPY_RELOCS)
7279 struct elf_aarch64_link_hash_entry *eh;
7280 /* If we don't find any dynamic relocs in read-only sections, then
7281 we'll be keeping the dynamic relocs and avoiding the copy reloc. */
7282 eh = (struct elf_aarch64_link_hash_entry *) h;
7283 if (!need_copy_relocation_p (eh))
7290 /* We must allocate the symbol in our .dynbss section, which will
7291 become part of the .bss section of the executable. There will be
7292 an entry for this symbol in the .dynsym section. The dynamic
7293 object will contain position independent code, so all references
7294 from the dynamic object to this symbol will go through the global
7295 offset table. The dynamic linker will use the .dynsym entry to
7296 determine the address it must put in the global offset table, so
7297 both the dynamic object and the regular object will refer to the
7298 same memory location for the variable. */
7300 htab = elf_aarch64_hash_table (info);
7302 /* We must generate a R_AARCH64_COPY reloc to tell the dynamic linker
7303 to copy the initial value out of the dynamic object and into the
7304 runtime process image. */
7305 if ((h->root.u.def.section->flags & SEC_READONLY) != 0)
7307 s = htab->root.sdynrelro;
7308 srel = htab->root.sreldynrelro;
7312 s = htab->root.sdynbss;
7313 srel = htab->root.srelbss;
7315 if ((h->root.u.def.section->flags & SEC_ALLOC) != 0 && h->size != 0)
7317 srel->size += RELOC_SIZE (htab);
7321 return _bfd_elf_adjust_dynamic_copy (info, h, s);
7326 elfNN_aarch64_allocate_local_symbols (bfd *abfd, unsigned number)
7328 struct elf_aarch64_local_symbol *locals;
7329 locals = elf_aarch64_locals (abfd);
7332 locals = (struct elf_aarch64_local_symbol *)
7333 bfd_zalloc (abfd, number * sizeof (struct elf_aarch64_local_symbol));
7336 elf_aarch64_locals (abfd) = locals;
7341 /* Create the .got section to hold the global offset table. */
7344 aarch64_elf_create_got_section (bfd *abfd, struct bfd_link_info *info)
7346 const struct elf_backend_data *bed = get_elf_backend_data (abfd);
7349 struct elf_link_hash_entry *h;
7350 struct elf_link_hash_table *htab = elf_hash_table (info);
7352 /* This function may be called more than once. */
7353 if (htab->sgot != NULL)
7356 flags = bed->dynamic_sec_flags;
7358 s = bfd_make_section_anyway_with_flags (abfd,
7359 (bed->rela_plts_and_copies_p
7360 ? ".rela.got" : ".rel.got"),
7361 (bed->dynamic_sec_flags
7364 || ! bfd_set_section_alignment (abfd, s, bed->s->log_file_align))
7368 s = bfd_make_section_anyway_with_flags (abfd, ".got", flags);
7370 || !bfd_set_section_alignment (abfd, s, bed->s->log_file_align))
7373 htab->sgot->size += GOT_ENTRY_SIZE;
7375 if (bed->want_got_sym)
7377 /* Define the symbol _GLOBAL_OFFSET_TABLE_ at the start of the .got
7378 (or .got.plt) section. We don't do this in the linker script
7379 because we don't want to define the symbol if we are not creating
7380 a global offset table. */
7381 h = _bfd_elf_define_linkage_sym (abfd, info, s,
7382 "_GLOBAL_OFFSET_TABLE_");
7383 elf_hash_table (info)->hgot = h;
7388 if (bed->want_got_plt)
7390 s = bfd_make_section_anyway_with_flags (abfd, ".got.plt", flags);
7392 || !bfd_set_section_alignment (abfd, s,
7393 bed->s->log_file_align))
7398 /* The first bit of the global offset table is the header. */
7399 s->size += bed->got_header_size;
7404 /* Look through the relocs for a section during the first phase. */
7407 elfNN_aarch64_check_relocs (bfd *abfd, struct bfd_link_info *info,
7408 asection *sec, const Elf_Internal_Rela *relocs)
7410 Elf_Internal_Shdr *symtab_hdr;
7411 struct elf_link_hash_entry **sym_hashes;
7412 const Elf_Internal_Rela *rel;
7413 const Elf_Internal_Rela *rel_end;
7416 struct elf_aarch64_link_hash_table *htab;
7418 if (bfd_link_relocatable (info))
7421 BFD_ASSERT (is_aarch64_elf (abfd));
7423 htab = elf_aarch64_hash_table (info);
7426 symtab_hdr = &elf_symtab_hdr (abfd);
7427 sym_hashes = elf_sym_hashes (abfd);
7429 rel_end = relocs + sec->reloc_count;
7430 for (rel = relocs; rel < rel_end; rel++)
7432 struct elf_link_hash_entry *h;
7433 unsigned int r_symndx;
7434 unsigned int r_type;
7435 bfd_reloc_code_real_type bfd_r_type;
7436 Elf_Internal_Sym *isym;
7438 r_symndx = ELFNN_R_SYM (rel->r_info);
7439 r_type = ELFNN_R_TYPE (rel->r_info);
7441 if (r_symndx >= NUM_SHDR_ENTRIES (symtab_hdr))
7443 /* xgettext:c-format */
7444 _bfd_error_handler (_("%pB: bad symbol index: %d"), abfd, r_symndx);
7448 if (r_symndx < symtab_hdr->sh_info)
7450 /* A local symbol. */
7451 isym = bfd_sym_from_r_symndx (&htab->sym_cache,
7456 /* Check relocation against local STT_GNU_IFUNC symbol. */
7457 if (ELF_ST_TYPE (isym->st_info) == STT_GNU_IFUNC)
7459 h = elfNN_aarch64_get_local_sym_hash (htab, abfd, rel,
7464 /* Fake a STT_GNU_IFUNC symbol. */
7465 h->type = STT_GNU_IFUNC;
7468 h->forced_local = 1;
7469 h->root.type = bfd_link_hash_defined;
7476 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
7477 while (h->root.type == bfd_link_hash_indirect
7478 || h->root.type == bfd_link_hash_warning)
7479 h = (struct elf_link_hash_entry *) h->root.u.i.link;
7482 /* Could be done earlier, if h were already available. */
7483 bfd_r_type = aarch64_tls_transition (abfd, info, r_type, h, r_symndx);
7487 /* If a relocation refers to _GLOBAL_OFFSET_TABLE_, create the .got.
7488 This shows up in particular in an R_AARCH64_PREL64 in large model
7489 when calculating the pc-relative address to .got section which is
7490 used to initialize the gp register. */
7491 if (h->root.root.string
7492 && strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0)
7494 if (htab->root.dynobj == NULL)
7495 htab->root.dynobj = abfd;
7497 if (! aarch64_elf_create_got_section (htab->root.dynobj, info))
7500 BFD_ASSERT (h == htab->root.hgot);
7503 /* Create the ifunc sections for static executables. If we
7504 never see an indirect function symbol nor we are building
7505 a static executable, those sections will be empty and
7506 won't appear in output. */
7512 case BFD_RELOC_AARCH64_ADD_LO12:
7513 case BFD_RELOC_AARCH64_ADR_GOT_PAGE:
7514 case BFD_RELOC_AARCH64_ADR_HI21_PCREL:
7515 case BFD_RELOC_AARCH64_CALL26:
7516 case BFD_RELOC_AARCH64_GOT_LD_PREL19:
7517 case BFD_RELOC_AARCH64_JUMP26:
7518 case BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14:
7519 case BFD_RELOC_AARCH64_LD32_GOT_LO12_NC:
7520 case BFD_RELOC_AARCH64_LD64_GOTOFF_LO15:
7521 case BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15:
7522 case BFD_RELOC_AARCH64_LD64_GOT_LO12_NC:
7523 case BFD_RELOC_AARCH64_MOVW_GOTOFF_G0_NC:
7524 case BFD_RELOC_AARCH64_MOVW_GOTOFF_G1:
7525 case BFD_RELOC_AARCH64_NN:
7526 if (htab->root.dynobj == NULL)
7527 htab->root.dynobj = abfd;
7528 if (!_bfd_elf_create_ifunc_sections (htab->root.dynobj, info))
7533 /* It is referenced by a non-shared object. */
7539 case BFD_RELOC_AARCH64_16:
7541 case BFD_RELOC_AARCH64_32:
7543 if (bfd_link_pic (info) && (sec->flags & SEC_ALLOC) != 0)
7546 /* This is an absolute symbol. It represents a value instead
7548 && (bfd_is_abs_symbol (&h->root)
7549 /* This is an undefined symbol. */
7550 || h->root.type == bfd_link_hash_undefined))
7553 /* For local symbols, defined global symbols in a non-ABS section,
7554 it is assumed that the value is an address. */
7555 int howto_index = bfd_r_type - BFD_RELOC_AARCH64_RELOC_START;
7557 /* xgettext:c-format */
7558 (_("%pB: relocation %s against `%s' can not be used when making "
7560 abfd, elfNN_aarch64_howto_table[howto_index].name,
7561 (h) ? h->root.root.string : "a local symbol");
7562 bfd_set_error (bfd_error_bad_value);
7568 case BFD_RELOC_AARCH64_MOVW_G0_NC:
7569 case BFD_RELOC_AARCH64_MOVW_G1_NC:
7570 case BFD_RELOC_AARCH64_MOVW_G2_NC:
7571 case BFD_RELOC_AARCH64_MOVW_G3:
7572 if (bfd_link_pic (info))
7574 int howto_index = bfd_r_type - BFD_RELOC_AARCH64_RELOC_START;
7576 /* xgettext:c-format */
7577 (_("%pB: relocation %s against `%s' can not be used when making "
7578 "a shared object; recompile with -fPIC"),
7579 abfd, elfNN_aarch64_howto_table[howto_index].name,
7580 (h) ? h->root.root.string : "a local symbol");
7581 bfd_set_error (bfd_error_bad_value);
7586 case BFD_RELOC_AARCH64_16_PCREL:
7587 case BFD_RELOC_AARCH64_32_PCREL:
7588 case BFD_RELOC_AARCH64_64_PCREL:
7589 case BFD_RELOC_AARCH64_ADD_LO12:
7590 case BFD_RELOC_AARCH64_ADR_HI21_NC_PCREL:
7591 case BFD_RELOC_AARCH64_ADR_HI21_PCREL:
7592 case BFD_RELOC_AARCH64_ADR_LO21_PCREL:
7593 case BFD_RELOC_AARCH64_LDST128_LO12:
7594 case BFD_RELOC_AARCH64_LDST16_LO12:
7595 case BFD_RELOC_AARCH64_LDST32_LO12:
7596 case BFD_RELOC_AARCH64_LDST64_LO12:
7597 case BFD_RELOC_AARCH64_LDST8_LO12:
7598 case BFD_RELOC_AARCH64_LD_LO19_PCREL:
7599 if (h == NULL || bfd_link_pic (info))
7603 case BFD_RELOC_AARCH64_NN:
7605 /* We don't need to handle relocs into sections not going into
7606 the "real" output. */
7607 if ((sec->flags & SEC_ALLOC) == 0)
7612 if (!bfd_link_pic (info))
7615 h->plt.refcount += 1;
7616 h->pointer_equality_needed = 1;
7619 /* No need to do anything if we're not creating a shared
7621 if (!(bfd_link_pic (info)
7622 /* If on the other hand, we are creating an executable, we
7623 may need to keep relocations for symbols satisfied by a
7624 dynamic library if we manage to avoid copy relocs for the
7627 NOTE: Currently, there is no support of copy relocs
7628 elimination on pc-relative relocation types, because there is
7629 no dynamic relocation support for them in glibc. We still
7630 record the dynamic symbol reference for them. This is
7631 because one symbol may be referenced by both absolute
7632 relocation (for example, BFD_RELOC_AARCH64_NN) and
7633 pc-relative relocation. We need full symbol reference
7634 information to make correct decision later in
7635 elfNN_aarch64_adjust_dynamic_symbol. */
7636 || (ELIMINATE_COPY_RELOCS
7637 && !bfd_link_pic (info)
7639 && (h->root.type == bfd_link_hash_defweak
7640 || !h->def_regular))))
7644 struct elf_dyn_relocs *p;
7645 struct elf_dyn_relocs **head;
7646 int howto_index = bfd_r_type - BFD_RELOC_AARCH64_RELOC_START;
7648 /* We must copy these reloc types into the output file.
7649 Create a reloc section in dynobj and make room for
7653 if (htab->root.dynobj == NULL)
7654 htab->root.dynobj = abfd;
7656 sreloc = _bfd_elf_make_dynamic_reloc_section
7657 (sec, htab->root.dynobj, LOG_FILE_ALIGN, abfd, /*rela? */ TRUE);
7663 /* If this is a global symbol, we count the number of
7664 relocations we need for this symbol. */
7667 struct elf_aarch64_link_hash_entry *eh;
7668 eh = (struct elf_aarch64_link_hash_entry *) h;
7669 head = &eh->dyn_relocs;
7673 /* Track dynamic relocs needed for local syms too.
7674 We really need local syms available to do this
7680 isym = bfd_sym_from_r_symndx (&htab->sym_cache,
7685 s = bfd_section_from_elf_index (abfd, isym->st_shndx);
7689 /* Beware of type punned pointers vs strict aliasing
7691 vpp = &(elf_section_data (s)->local_dynrel);
7692 head = (struct elf_dyn_relocs **) vpp;
7696 if (p == NULL || p->sec != sec)
7698 bfd_size_type amt = sizeof *p;
7699 p = ((struct elf_dyn_relocs *)
7700 bfd_zalloc (htab->root.dynobj, amt));
7710 if (elfNN_aarch64_howto_table[howto_index].pc_relative)
7715 /* RR: We probably want to keep a consistency check that
7716 there are no dangling GOT_PAGE relocs. */
7717 case BFD_RELOC_AARCH64_ADR_GOT_PAGE:
7718 case BFD_RELOC_AARCH64_GOT_LD_PREL19:
7719 case BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14:
7720 case BFD_RELOC_AARCH64_LD32_GOT_LO12_NC:
7721 case BFD_RELOC_AARCH64_LD64_GOTOFF_LO15:
7722 case BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15:
7723 case BFD_RELOC_AARCH64_LD64_GOT_LO12_NC:
7724 case BFD_RELOC_AARCH64_MOVW_GOTOFF_G0_NC:
7725 case BFD_RELOC_AARCH64_MOVW_GOTOFF_G1:
7726 case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12:
7727 case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21:
7728 case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21:
7729 case BFD_RELOC_AARCH64_TLSDESC_LD32_LO12_NC:
7730 case BFD_RELOC_AARCH64_TLSDESC_LD64_LO12:
7731 case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19:
7732 case BFD_RELOC_AARCH64_TLSDESC_OFF_G0_NC:
7733 case BFD_RELOC_AARCH64_TLSDESC_OFF_G1:
7734 case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC:
7735 case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21:
7736 case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21:
7737 case BFD_RELOC_AARCH64_TLSGD_MOVW_G0_NC:
7738 case BFD_RELOC_AARCH64_TLSGD_MOVW_G1:
7739 case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21:
7740 case BFD_RELOC_AARCH64_TLSIE_LD32_GOTTPREL_LO12_NC:
7741 case BFD_RELOC_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC:
7742 case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19:
7743 case BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G0_NC:
7744 case BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G1:
7745 case BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC:
7746 case BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21:
7747 case BFD_RELOC_AARCH64_TLSLD_ADR_PREL21:
7750 unsigned old_got_type;
7752 got_type = aarch64_reloc_got_type (bfd_r_type);
7756 h->got.refcount += 1;
7757 old_got_type = elf_aarch64_hash_entry (h)->got_type;
7761 struct elf_aarch64_local_symbol *locals;
7763 if (!elfNN_aarch64_allocate_local_symbols
7764 (abfd, symtab_hdr->sh_info))
7767 locals = elf_aarch64_locals (abfd);
7768 BFD_ASSERT (r_symndx < symtab_hdr->sh_info);
7769 locals[r_symndx].got_refcount += 1;
7770 old_got_type = locals[r_symndx].got_type;
7773 /* If a variable is accessed with both general dynamic TLS
7774 methods, two slots may be created. */
7775 if (GOT_TLS_GD_ANY_P (old_got_type) && GOT_TLS_GD_ANY_P (got_type))
7776 got_type |= old_got_type;
7778 /* We will already have issued an error message if there
7779 is a TLS/non-TLS mismatch, based on the symbol type.
7780 So just combine any TLS types needed. */
7781 if (old_got_type != GOT_UNKNOWN && old_got_type != GOT_NORMAL
7782 && got_type != GOT_NORMAL)
7783 got_type |= old_got_type;
7785 /* If the symbol is accessed by both IE and GD methods, we
7786 are able to relax. Turn off the GD flag, without
7787 messing up with any other kind of TLS types that may be
7789 if ((got_type & GOT_TLS_IE) && GOT_TLS_GD_ANY_P (got_type))
7790 got_type &= ~ (GOT_TLSDESC_GD | GOT_TLS_GD);
7792 if (old_got_type != got_type)
7795 elf_aarch64_hash_entry (h)->got_type = got_type;
7798 struct elf_aarch64_local_symbol *locals;
7799 locals = elf_aarch64_locals (abfd);
7800 BFD_ASSERT (r_symndx < symtab_hdr->sh_info);
7801 locals[r_symndx].got_type = got_type;
7805 if (htab->root.dynobj == NULL)
7806 htab->root.dynobj = abfd;
7807 if (! aarch64_elf_create_got_section (htab->root.dynobj, info))
7812 case BFD_RELOC_AARCH64_CALL26:
7813 case BFD_RELOC_AARCH64_JUMP26:
7814 /* If this is a local symbol then we resolve it
7815 directly without creating a PLT entry. */
7820 if (h->plt.refcount <= 0)
7821 h->plt.refcount = 1;
7823 h->plt.refcount += 1;
7834 /* Treat mapping symbols as special target symbols. */
7837 elfNN_aarch64_is_target_special_symbol (bfd *abfd ATTRIBUTE_UNUSED,
7840 return bfd_is_aarch64_special_symbol_name (sym->name,
7841 BFD_AARCH64_SPECIAL_SYM_TYPE_ANY);
7844 /* This is a copy of elf_find_function () from elf.c except that
7845 AArch64 mapping symbols are ignored when looking for function names. */
7848 aarch64_elf_find_function (bfd *abfd ATTRIBUTE_UNUSED,
7852 const char **filename_ptr,
7853 const char **functionname_ptr)
7855 const char *filename = NULL;
7856 asymbol *func = NULL;
7857 bfd_vma low_func = 0;
7860 for (p = symbols; *p != NULL; p++)
7864 q = (elf_symbol_type *) * p;
7866 switch (ELF_ST_TYPE (q->internal_elf_sym.st_info))
7871 filename = bfd_asymbol_name (&q->symbol);
7875 /* Skip mapping symbols. */
7876 if ((q->symbol.flags & BSF_LOCAL)
7877 && (bfd_is_aarch64_special_symbol_name
7878 (q->symbol.name, BFD_AARCH64_SPECIAL_SYM_TYPE_ANY)))
7881 if (bfd_get_section (&q->symbol) == section
7882 && q->symbol.value >= low_func && q->symbol.value <= offset)
7884 func = (asymbol *) q;
7885 low_func = q->symbol.value;
7895 *filename_ptr = filename;
7896 if (functionname_ptr)
7897 *functionname_ptr = bfd_asymbol_name (func);
7903 /* Find the nearest line to a particular section and offset, for error
7904 reporting. This code is a duplicate of the code in elf.c, except
7905 that it uses aarch64_elf_find_function. */
7908 elfNN_aarch64_find_nearest_line (bfd *abfd,
7912 const char **filename_ptr,
7913 const char **functionname_ptr,
7914 unsigned int *line_ptr,
7915 unsigned int *discriminator_ptr)
7917 bfd_boolean found = FALSE;
7919 if (_bfd_dwarf2_find_nearest_line (abfd, symbols, NULL, section, offset,
7920 filename_ptr, functionname_ptr,
7921 line_ptr, discriminator_ptr,
7922 dwarf_debug_sections, 0,
7923 &elf_tdata (abfd)->dwarf2_find_line_info))
7925 if (!*functionname_ptr)
7926 aarch64_elf_find_function (abfd, symbols, section, offset,
7927 *filename_ptr ? NULL : filename_ptr,
7933 /* Skip _bfd_dwarf1_find_nearest_line since no known AArch64
7934 toolchain uses DWARF1. */
7936 if (!_bfd_stab_section_find_nearest_line (abfd, symbols, section, offset,
7937 &found, filename_ptr,
7938 functionname_ptr, line_ptr,
7939 &elf_tdata (abfd)->line_info))
7942 if (found && (*functionname_ptr || *line_ptr))
7945 if (symbols == NULL)
7948 if (!aarch64_elf_find_function (abfd, symbols, section, offset,
7949 filename_ptr, functionname_ptr))
7957 elfNN_aarch64_find_inliner_info (bfd *abfd,
7958 const char **filename_ptr,
7959 const char **functionname_ptr,
7960 unsigned int *line_ptr)
7963 found = _bfd_dwarf2_find_inliner_info
7964 (abfd, filename_ptr,
7965 functionname_ptr, line_ptr, &elf_tdata (abfd)->dwarf2_find_line_info);
7971 elfNN_aarch64_post_process_headers (bfd *abfd,
7972 struct bfd_link_info *link_info)
7974 Elf_Internal_Ehdr *i_ehdrp; /* ELF file header, internal form. */
7976 i_ehdrp = elf_elfheader (abfd);
7977 i_ehdrp->e_ident[EI_ABIVERSION] = AARCH64_ELF_ABI_VERSION;
7979 _bfd_elf_post_process_headers (abfd, link_info);
7982 static enum elf_reloc_type_class
7983 elfNN_aarch64_reloc_type_class (const struct bfd_link_info *info ATTRIBUTE_UNUSED,
7984 const asection *rel_sec ATTRIBUTE_UNUSED,
7985 const Elf_Internal_Rela *rela)
7987 struct elf_aarch64_link_hash_table *htab = elf_aarch64_hash_table (info);
7989 if (htab->root.dynsym != NULL
7990 && htab->root.dynsym->contents != NULL)
7992 /* Check relocation against STT_GNU_IFUNC symbol if there are
7994 bfd *abfd = info->output_bfd;
7995 const struct elf_backend_data *bed = get_elf_backend_data (abfd);
7996 unsigned long r_symndx = ELFNN_R_SYM (rela->r_info);
7997 if (r_symndx != STN_UNDEF)
7999 Elf_Internal_Sym sym;
8000 if (!bed->s->swap_symbol_in (abfd,
8001 (htab->root.dynsym->contents
8002 + r_symndx * bed->s->sizeof_sym),
8005 /* xgettext:c-format */
8006 _bfd_error_handler (_("%pB symbol number %lu references"
8007 " nonexistent SHT_SYMTAB_SHNDX section"),
8009 /* Ideally an error class should be returned here. */
8011 else if (ELF_ST_TYPE (sym.st_info) == STT_GNU_IFUNC)
8012 return reloc_class_ifunc;
8016 switch ((int) ELFNN_R_TYPE (rela->r_info))
8018 case AARCH64_R (IRELATIVE):
8019 return reloc_class_ifunc;
8020 case AARCH64_R (RELATIVE):
8021 return reloc_class_relative;
8022 case AARCH64_R (JUMP_SLOT):
8023 return reloc_class_plt;
8024 case AARCH64_R (COPY):
8025 return reloc_class_copy;
8027 return reloc_class_normal;
8031 /* Handle an AArch64 specific section when reading an object file. This is
8032 called when bfd_section_from_shdr finds a section with an unknown
8036 elfNN_aarch64_section_from_shdr (bfd *abfd,
8037 Elf_Internal_Shdr *hdr,
8038 const char *name, int shindex)
8040 /* There ought to be a place to keep ELF backend specific flags, but
8041 at the moment there isn't one. We just keep track of the
8042 sections by their name, instead. Fortunately, the ABI gives
8043 names for all the AArch64 specific sections, so we will probably get
8045 switch (hdr->sh_type)
8047 case SHT_AARCH64_ATTRIBUTES:
8054 if (!_bfd_elf_make_section_from_shdr (abfd, hdr, name, shindex))
8060 /* A structure used to record a list of sections, independently
8061 of the next and prev fields in the asection structure. */
8062 typedef struct section_list
8065 struct section_list *next;
8066 struct section_list *prev;
8070 /* Unfortunately we need to keep a list of sections for which
8071 an _aarch64_elf_section_data structure has been allocated. This
8072 is because it is possible for functions like elfNN_aarch64_write_section
8073 to be called on a section which has had an elf_data_structure
8074 allocated for it (and so the used_by_bfd field is valid) but
8075 for which the AArch64 extended version of this structure - the
8076 _aarch64_elf_section_data structure - has not been allocated. */
8077 static section_list *sections_with_aarch64_elf_section_data = NULL;
8080 record_section_with_aarch64_elf_section_data (asection *sec)
8082 struct section_list *entry;
8084 entry = bfd_malloc (sizeof (*entry));
8088 entry->next = sections_with_aarch64_elf_section_data;
8090 if (entry->next != NULL)
8091 entry->next->prev = entry;
8092 sections_with_aarch64_elf_section_data = entry;
8095 static struct section_list *
8096 find_aarch64_elf_section_entry (asection *sec)
8098 struct section_list *entry;
8099 static struct section_list *last_entry = NULL;
8101 /* This is a short cut for the typical case where the sections are added
8102 to the sections_with_aarch64_elf_section_data list in forward order and
8103 then looked up here in backwards order. This makes a real difference
8104 to the ld-srec/sec64k.exp linker test. */
8105 entry = sections_with_aarch64_elf_section_data;
8106 if (last_entry != NULL)
8108 if (last_entry->sec == sec)
8110 else if (last_entry->next != NULL && last_entry->next->sec == sec)
8111 entry = last_entry->next;
8114 for (; entry; entry = entry->next)
8115 if (entry->sec == sec)
8119 /* Record the entry prior to this one - it is the entry we are
8120 most likely to want to locate next time. Also this way if we
8121 have been called from
8122 unrecord_section_with_aarch64_elf_section_data () we will not
8123 be caching a pointer that is about to be freed. */
8124 last_entry = entry->prev;
8130 unrecord_section_with_aarch64_elf_section_data (asection *sec)
8132 struct section_list *entry;
8134 entry = find_aarch64_elf_section_entry (sec);
8138 if (entry->prev != NULL)
8139 entry->prev->next = entry->next;
8140 if (entry->next != NULL)
8141 entry->next->prev = entry->prev;
8142 if (entry == sections_with_aarch64_elf_section_data)
8143 sections_with_aarch64_elf_section_data = entry->next;
8152 struct bfd_link_info *info;
8155 int (*func) (void *, const char *, Elf_Internal_Sym *,
8156 asection *, struct elf_link_hash_entry *);
8157 } output_arch_syminfo;
8159 enum map_symbol_type
8166 /* Output a single mapping symbol. */
8169 elfNN_aarch64_output_map_sym (output_arch_syminfo *osi,
8170 enum map_symbol_type type, bfd_vma offset)
8172 static const char *names[2] = { "$x", "$d" };
8173 Elf_Internal_Sym sym;
8175 sym.st_value = (osi->sec->output_section->vma
8176 + osi->sec->output_offset + offset);
8179 sym.st_info = ELF_ST_INFO (STB_LOCAL, STT_NOTYPE);
8180 sym.st_shndx = osi->sec_shndx;
8181 return osi->func (osi->finfo, names[type], &sym, osi->sec, NULL) == 1;
8184 /* Output a single local symbol for a generated stub. */
8187 elfNN_aarch64_output_stub_sym (output_arch_syminfo *osi, const char *name,
8188 bfd_vma offset, bfd_vma size)
8190 Elf_Internal_Sym sym;
8192 sym.st_value = (osi->sec->output_section->vma
8193 + osi->sec->output_offset + offset);
8196 sym.st_info = ELF_ST_INFO (STB_LOCAL, STT_FUNC);
8197 sym.st_shndx = osi->sec_shndx;
8198 return osi->func (osi->finfo, name, &sym, osi->sec, NULL) == 1;
8202 aarch64_map_one_stub (struct bfd_hash_entry *gen_entry, void *in_arg)
8204 struct elf_aarch64_stub_hash_entry *stub_entry;
8208 output_arch_syminfo *osi;
8210 /* Massage our args to the form they really have. */
8211 stub_entry = (struct elf_aarch64_stub_hash_entry *) gen_entry;
8212 osi = (output_arch_syminfo *) in_arg;
8214 stub_sec = stub_entry->stub_sec;
8216 /* Ensure this stub is attached to the current section being
8218 if (stub_sec != osi->sec)
8221 addr = (bfd_vma) stub_entry->stub_offset;
8223 stub_name = stub_entry->output_name;
8225 switch (stub_entry->stub_type)
8227 case aarch64_stub_adrp_branch:
8228 if (!elfNN_aarch64_output_stub_sym (osi, stub_name, addr,
8229 sizeof (aarch64_adrp_branch_stub)))
8231 if (!elfNN_aarch64_output_map_sym (osi, AARCH64_MAP_INSN, addr))
8234 case aarch64_stub_long_branch:
8235 if (!elfNN_aarch64_output_stub_sym
8236 (osi, stub_name, addr, sizeof (aarch64_long_branch_stub)))
8238 if (!elfNN_aarch64_output_map_sym (osi, AARCH64_MAP_INSN, addr))
8240 if (!elfNN_aarch64_output_map_sym (osi, AARCH64_MAP_DATA, addr + 16))
8243 case aarch64_stub_erratum_835769_veneer:
8244 if (!elfNN_aarch64_output_stub_sym (osi, stub_name, addr,
8245 sizeof (aarch64_erratum_835769_stub)))
8247 if (!elfNN_aarch64_output_map_sym (osi, AARCH64_MAP_INSN, addr))
8250 case aarch64_stub_erratum_843419_veneer:
8251 if (!elfNN_aarch64_output_stub_sym (osi, stub_name, addr,
8252 sizeof (aarch64_erratum_843419_stub)))
8254 if (!elfNN_aarch64_output_map_sym (osi, AARCH64_MAP_INSN, addr))
8257 case aarch64_stub_none:
8267 /* Output mapping symbols for linker generated sections. */
8270 elfNN_aarch64_output_arch_local_syms (bfd *output_bfd,
8271 struct bfd_link_info *info,
8273 int (*func) (void *, const char *,
8276 struct elf_link_hash_entry
8279 output_arch_syminfo osi;
8280 struct elf_aarch64_link_hash_table *htab;
8282 htab = elf_aarch64_hash_table (info);
8288 /* Long calls stubs. */
8289 if (htab->stub_bfd && htab->stub_bfd->sections)
8293 for (stub_sec = htab->stub_bfd->sections;
8294 stub_sec != NULL; stub_sec = stub_sec->next)
8296 /* Ignore non-stub sections. */
8297 if (!strstr (stub_sec->name, STUB_SUFFIX))
8302 osi.sec_shndx = _bfd_elf_section_from_bfd_section
8303 (output_bfd, osi.sec->output_section);
8305 /* The first instruction in a stub is always a branch. */
8306 if (!elfNN_aarch64_output_map_sym (&osi, AARCH64_MAP_INSN, 0))
8309 bfd_hash_traverse (&htab->stub_hash_table, aarch64_map_one_stub,
8314 /* Finally, output mapping symbols for the PLT. */
8315 if (!htab->root.splt || htab->root.splt->size == 0)
8318 osi.sec_shndx = _bfd_elf_section_from_bfd_section
8319 (output_bfd, htab->root.splt->output_section);
8320 osi.sec = htab->root.splt;
8322 elfNN_aarch64_output_map_sym (&osi, AARCH64_MAP_INSN, 0);
8328 /* Allocate target specific section data. */
8331 elfNN_aarch64_new_section_hook (bfd *abfd, asection *sec)
8333 if (!sec->used_by_bfd)
8335 _aarch64_elf_section_data *sdata;
8336 bfd_size_type amt = sizeof (*sdata);
8338 sdata = bfd_zalloc (abfd, amt);
8341 sec->used_by_bfd = sdata;
8344 record_section_with_aarch64_elf_section_data (sec);
8346 return _bfd_elf_new_section_hook (abfd, sec);
8351 unrecord_section_via_map_over_sections (bfd *abfd ATTRIBUTE_UNUSED,
8353 void *ignore ATTRIBUTE_UNUSED)
8355 unrecord_section_with_aarch64_elf_section_data (sec);
8359 elfNN_aarch64_close_and_cleanup (bfd *abfd)
8362 bfd_map_over_sections (abfd,
8363 unrecord_section_via_map_over_sections, NULL);
8365 return _bfd_elf_close_and_cleanup (abfd);
8369 elfNN_aarch64_bfd_free_cached_info (bfd *abfd)
8372 bfd_map_over_sections (abfd,
8373 unrecord_section_via_map_over_sections, NULL);
8375 return _bfd_free_cached_info (abfd);
8378 /* Create dynamic sections. This is different from the ARM backend in that
8379 the got, plt, gotplt and their relocation sections are all created in the
8380 standard part of the bfd elf backend. */
8383 elfNN_aarch64_create_dynamic_sections (bfd *dynobj,
8384 struct bfd_link_info *info)
8386 /* We need to create .got section. */
8387 if (!aarch64_elf_create_got_section (dynobj, info))
8390 return _bfd_elf_create_dynamic_sections (dynobj, info);
8394 /* Allocate space in .plt, .got and associated reloc sections for
8398 elfNN_aarch64_allocate_dynrelocs (struct elf_link_hash_entry *h, void *inf)
8400 struct bfd_link_info *info;
8401 struct elf_aarch64_link_hash_table *htab;
8402 struct elf_aarch64_link_hash_entry *eh;
8403 struct elf_dyn_relocs *p;
8405 /* An example of a bfd_link_hash_indirect symbol is versioned
8406 symbol. For example: __gxx_personality_v0(bfd_link_hash_indirect)
8407 -> __gxx_personality_v0(bfd_link_hash_defined)
8409 There is no need to process bfd_link_hash_indirect symbols here
8410 because we will also be presented with the concrete instance of
8411 the symbol and elfNN_aarch64_copy_indirect_symbol () will have been
8412 called to copy all relevant data from the generic to the concrete
8414 if (h->root.type == bfd_link_hash_indirect)
8417 if (h->root.type == bfd_link_hash_warning)
8418 h = (struct elf_link_hash_entry *) h->root.u.i.link;
8420 info = (struct bfd_link_info *) inf;
8421 htab = elf_aarch64_hash_table (info);
8423 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle it
8424 here if it is defined and referenced in a non-shared object. */
8425 if (h->type == STT_GNU_IFUNC
8428 else if (htab->root.dynamic_sections_created && h->plt.refcount > 0)
8430 /* Make sure this symbol is output as a dynamic symbol.
8431 Undefined weak syms won't yet be marked as dynamic. */
8432 if (h->dynindx == -1 && !h->forced_local
8433 && h->root.type == bfd_link_hash_undefweak)
8435 if (!bfd_elf_link_record_dynamic_symbol (info, h))
8439 if (bfd_link_pic (info) || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h))
8441 asection *s = htab->root.splt;
8443 /* If this is the first .plt entry, make room for the special
8446 s->size += htab->plt_header_size;
8448 h->plt.offset = s->size;
8450 /* If this symbol is not defined in a regular file, and we are
8451 not generating a shared library, then set the symbol to this
8452 location in the .plt. This is required to make function
8453 pointers compare as equal between the normal executable and
8454 the shared library. */
8455 if (!bfd_link_pic (info) && !h->def_regular)
8457 h->root.u.def.section = s;
8458 h->root.u.def.value = h->plt.offset;
8461 /* Make room for this entry. For now we only create the
8462 small model PLT entries. We later need to find a way
8463 of relaxing into these from the large model PLT entries. */
8464 s->size += htab->plt_entry_size;
8466 /* We also need to make an entry in the .got.plt section, which
8467 will be placed in the .got section by the linker script. */
8468 htab->root.sgotplt->size += GOT_ENTRY_SIZE;
8470 /* We also need to make an entry in the .rela.plt section. */
8471 htab->root.srelplt->size += RELOC_SIZE (htab);
8473 /* We need to ensure that all GOT entries that serve the PLT
8474 are consecutive with the special GOT slots [0] [1] and
8475 [2]. Any addtional relocations, such as
8476 R_AARCH64_TLSDESC, must be placed after the PLT related
8477 entries. We abuse the reloc_count such that during
8478 sizing we adjust reloc_count to indicate the number of
8479 PLT related reserved entries. In subsequent phases when
8480 filling in the contents of the reloc entries, PLT related
8481 entries are placed by computing their PLT index (0
8482 .. reloc_count). While other none PLT relocs are placed
8483 at the slot indicated by reloc_count and reloc_count is
8486 htab->root.srelplt->reloc_count++;
8490 h->plt.offset = (bfd_vma) - 1;
8496 h->plt.offset = (bfd_vma) - 1;
8500 eh = (struct elf_aarch64_link_hash_entry *) h;
8501 eh->tlsdesc_got_jump_table_offset = (bfd_vma) - 1;
8503 if (h->got.refcount > 0)
8506 unsigned got_type = elf_aarch64_hash_entry (h)->got_type;
8508 h->got.offset = (bfd_vma) - 1;
8510 dyn = htab->root.dynamic_sections_created;
8512 /* Make sure this symbol is output as a dynamic symbol.
8513 Undefined weak syms won't yet be marked as dynamic. */
8514 if (dyn && h->dynindx == -1 && !h->forced_local
8515 && h->root.type == bfd_link_hash_undefweak)
8517 if (!bfd_elf_link_record_dynamic_symbol (info, h))
8521 if (got_type == GOT_UNKNOWN)
8524 else if (got_type == GOT_NORMAL)
8526 h->got.offset = htab->root.sgot->size;
8527 htab->root.sgot->size += GOT_ENTRY_SIZE;
8528 if ((ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
8529 || h->root.type != bfd_link_hash_undefweak)
8530 && (bfd_link_pic (info)
8531 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, 0, h))
8532 /* Undefined weak symbol in static PIE resolves to 0 without
8533 any dynamic relocations. */
8534 && !UNDEFWEAK_NO_DYNAMIC_RELOC (info, h))
8536 htab->root.srelgot->size += RELOC_SIZE (htab);
8542 if (got_type & GOT_TLSDESC_GD)
8544 eh->tlsdesc_got_jump_table_offset =
8545 (htab->root.sgotplt->size
8546 - aarch64_compute_jump_table_size (htab));
8547 htab->root.sgotplt->size += GOT_ENTRY_SIZE * 2;
8548 h->got.offset = (bfd_vma) - 2;
8551 if (got_type & GOT_TLS_GD)
8553 h->got.offset = htab->root.sgot->size;
8554 htab->root.sgot->size += GOT_ENTRY_SIZE * 2;
8557 if (got_type & GOT_TLS_IE)
8559 h->got.offset = htab->root.sgot->size;
8560 htab->root.sgot->size += GOT_ENTRY_SIZE;
8563 indx = h && h->dynindx != -1 ? h->dynindx : 0;
8564 if ((ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
8565 || h->root.type != bfd_link_hash_undefweak)
8566 && (!bfd_link_executable (info)
8568 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, 0, h)))
8570 if (got_type & GOT_TLSDESC_GD)
8572 htab->root.srelplt->size += RELOC_SIZE (htab);
8573 /* Note reloc_count not incremented here! We have
8574 already adjusted reloc_count for this relocation
8577 /* TLSDESC PLT is now needed, but not yet determined. */
8578 htab->tlsdesc_plt = (bfd_vma) - 1;
8581 if (got_type & GOT_TLS_GD)
8582 htab->root.srelgot->size += RELOC_SIZE (htab) * 2;
8584 if (got_type & GOT_TLS_IE)
8585 htab->root.srelgot->size += RELOC_SIZE (htab);
8591 h->got.offset = (bfd_vma) - 1;
8594 if (eh->dyn_relocs == NULL)
8597 /* In the shared -Bsymbolic case, discard space allocated for
8598 dynamic pc-relative relocs against symbols which turn out to be
8599 defined in regular objects. For the normal shared case, discard
8600 space for pc-relative relocs that have become local due to symbol
8601 visibility changes. */
8603 if (bfd_link_pic (info))
8605 /* Relocs that use pc_count are those that appear on a call
8606 insn, or certain REL relocs that can generated via assembly.
8607 We want calls to protected symbols to resolve directly to the
8608 function rather than going via the plt. If people want
8609 function pointer comparisons to work as expected then they
8610 should avoid writing weird assembly. */
8611 if (SYMBOL_CALLS_LOCAL (info, h))
8613 struct elf_dyn_relocs **pp;
8615 for (pp = &eh->dyn_relocs; (p = *pp) != NULL;)
8617 p->count -= p->pc_count;
8626 /* Also discard relocs on undefined weak syms with non-default
8628 if (eh->dyn_relocs != NULL && h->root.type == bfd_link_hash_undefweak)
8630 if (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
8631 || UNDEFWEAK_NO_DYNAMIC_RELOC (info, h))
8632 eh->dyn_relocs = NULL;
8634 /* Make sure undefined weak symbols are output as a dynamic
8636 else if (h->dynindx == -1
8638 && h->root.type == bfd_link_hash_undefweak
8639 && !bfd_elf_link_record_dynamic_symbol (info, h))
8644 else if (ELIMINATE_COPY_RELOCS)
8646 /* For the non-shared case, discard space for relocs against
8647 symbols which turn out to need copy relocs or are not
8653 || (htab->root.dynamic_sections_created
8654 && (h->root.type == bfd_link_hash_undefweak
8655 || h->root.type == bfd_link_hash_undefined))))
8657 /* Make sure this symbol is output as a dynamic symbol.
8658 Undefined weak syms won't yet be marked as dynamic. */
8659 if (h->dynindx == -1
8661 && h->root.type == bfd_link_hash_undefweak
8662 && !bfd_elf_link_record_dynamic_symbol (info, h))
8665 /* If that succeeded, we know we'll be keeping all the
8667 if (h->dynindx != -1)
8671 eh->dyn_relocs = NULL;
8676 /* Finally, allocate space. */
8677 for (p = eh->dyn_relocs; p != NULL; p = p->next)
8681 sreloc = elf_section_data (p->sec)->sreloc;
8683 BFD_ASSERT (sreloc != NULL);
8685 sreloc->size += p->count * RELOC_SIZE (htab);
8691 /* Allocate space in .plt, .got and associated reloc sections for
8692 ifunc dynamic relocs. */
8695 elfNN_aarch64_allocate_ifunc_dynrelocs (struct elf_link_hash_entry *h,
8698 struct bfd_link_info *info;
8699 struct elf_aarch64_link_hash_table *htab;
8700 struct elf_aarch64_link_hash_entry *eh;
8702 /* An example of a bfd_link_hash_indirect symbol is versioned
8703 symbol. For example: __gxx_personality_v0(bfd_link_hash_indirect)
8704 -> __gxx_personality_v0(bfd_link_hash_defined)
8706 There is no need to process bfd_link_hash_indirect symbols here
8707 because we will also be presented with the concrete instance of
8708 the symbol and elfNN_aarch64_copy_indirect_symbol () will have been
8709 called to copy all relevant data from the generic to the concrete
8711 if (h->root.type == bfd_link_hash_indirect)
8714 if (h->root.type == bfd_link_hash_warning)
8715 h = (struct elf_link_hash_entry *) h->root.u.i.link;
8717 info = (struct bfd_link_info *) inf;
8718 htab = elf_aarch64_hash_table (info);
8720 eh = (struct elf_aarch64_link_hash_entry *) h;
8722 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle it
8723 here if it is defined and referenced in a non-shared object. */
8724 if (h->type == STT_GNU_IFUNC
8726 return _bfd_elf_allocate_ifunc_dyn_relocs (info, h,
8729 htab->plt_entry_size,
8730 htab->plt_header_size,
8736 /* Allocate space in .plt, .got and associated reloc sections for
8737 local dynamic relocs. */
8740 elfNN_aarch64_allocate_local_dynrelocs (void **slot, void *inf)
8742 struct elf_link_hash_entry *h
8743 = (struct elf_link_hash_entry *) *slot;
8745 if (h->type != STT_GNU_IFUNC
8749 || h->root.type != bfd_link_hash_defined)
8752 return elfNN_aarch64_allocate_dynrelocs (h, inf);
8755 /* Allocate space in .plt, .got and associated reloc sections for
8756 local ifunc dynamic relocs. */
8759 elfNN_aarch64_allocate_local_ifunc_dynrelocs (void **slot, void *inf)
8761 struct elf_link_hash_entry *h
8762 = (struct elf_link_hash_entry *) *slot;
8764 if (h->type != STT_GNU_IFUNC
8768 || h->root.type != bfd_link_hash_defined)
8771 return elfNN_aarch64_allocate_ifunc_dynrelocs (h, inf);
8774 /* Set DF_TEXTREL if we find any dynamic relocs that apply to
8775 read-only sections. */
8778 maybe_set_textrel (struct elf_link_hash_entry *h, void *info_p)
8782 if (h->root.type == bfd_link_hash_indirect)
8785 sec = readonly_dynrelocs (h);
8788 struct bfd_link_info *info = (struct bfd_link_info *) info_p;
8790 info->flags |= DF_TEXTREL;
8791 info->callbacks->minfo
8792 (_("%pB: dynamic relocation against `%pT' in read-only section `%pA'\n"),
8793 sec->owner, h->root.root.string, sec);
8795 /* Not an error, just cut short the traversal. */
8801 /* This is the most important function of all . Innocuosly named
8805 elfNN_aarch64_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
8806 struct bfd_link_info *info)
8808 struct elf_aarch64_link_hash_table *htab;
8814 htab = elf_aarch64_hash_table ((info));
8815 dynobj = htab->root.dynobj;
8817 BFD_ASSERT (dynobj != NULL);
8819 if (htab->root.dynamic_sections_created)
8821 if (bfd_link_executable (info) && !info->nointerp)
8823 s = bfd_get_linker_section (dynobj, ".interp");
8826 s->size = sizeof ELF_DYNAMIC_INTERPRETER;
8827 s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
8831 /* Set up .got offsets for local syms, and space for local dynamic
8833 for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link.next)
8835 struct elf_aarch64_local_symbol *locals = NULL;
8836 Elf_Internal_Shdr *symtab_hdr;
8840 if (!is_aarch64_elf (ibfd))
8843 for (s = ibfd->sections; s != NULL; s = s->next)
8845 struct elf_dyn_relocs *p;
8847 for (p = (struct elf_dyn_relocs *)
8848 (elf_section_data (s)->local_dynrel); p != NULL; p = p->next)
8850 if (!bfd_is_abs_section (p->sec)
8851 && bfd_is_abs_section (p->sec->output_section))
8853 /* Input section has been discarded, either because
8854 it is a copy of a linkonce section or due to
8855 linker script /DISCARD/, so we'll be discarding
8858 else if (p->count != 0)
8860 srel = elf_section_data (p->sec)->sreloc;
8861 srel->size += p->count * RELOC_SIZE (htab);
8862 if ((p->sec->output_section->flags & SEC_READONLY) != 0)
8863 info->flags |= DF_TEXTREL;
8868 locals = elf_aarch64_locals (ibfd);
8872 symtab_hdr = &elf_symtab_hdr (ibfd);
8873 srel = htab->root.srelgot;
8874 for (i = 0; i < symtab_hdr->sh_info; i++)
8876 locals[i].got_offset = (bfd_vma) - 1;
8877 locals[i].tlsdesc_got_jump_table_offset = (bfd_vma) - 1;
8878 if (locals[i].got_refcount > 0)
8880 unsigned got_type = locals[i].got_type;
8881 if (got_type & GOT_TLSDESC_GD)
8883 locals[i].tlsdesc_got_jump_table_offset =
8884 (htab->root.sgotplt->size
8885 - aarch64_compute_jump_table_size (htab));
8886 htab->root.sgotplt->size += GOT_ENTRY_SIZE * 2;
8887 locals[i].got_offset = (bfd_vma) - 2;
8890 if (got_type & GOT_TLS_GD)
8892 locals[i].got_offset = htab->root.sgot->size;
8893 htab->root.sgot->size += GOT_ENTRY_SIZE * 2;
8896 if (got_type & GOT_TLS_IE
8897 || got_type & GOT_NORMAL)
8899 locals[i].got_offset = htab->root.sgot->size;
8900 htab->root.sgot->size += GOT_ENTRY_SIZE;
8903 if (got_type == GOT_UNKNOWN)
8907 if (bfd_link_pic (info))
8909 if (got_type & GOT_TLSDESC_GD)
8911 htab->root.srelplt->size += RELOC_SIZE (htab);
8912 /* Note RELOC_COUNT not incremented here! */
8913 htab->tlsdesc_plt = (bfd_vma) - 1;
8916 if (got_type & GOT_TLS_GD)
8917 htab->root.srelgot->size += RELOC_SIZE (htab) * 2;
8919 if (got_type & GOT_TLS_IE
8920 || got_type & GOT_NORMAL)
8921 htab->root.srelgot->size += RELOC_SIZE (htab);
8926 locals[i].got_refcount = (bfd_vma) - 1;
8932 /* Allocate global sym .plt and .got entries, and space for global
8933 sym dynamic relocs. */
8934 elf_link_hash_traverse (&htab->root, elfNN_aarch64_allocate_dynrelocs,
8937 /* Allocate global ifunc sym .plt and .got entries, and space for global
8938 ifunc sym dynamic relocs. */
8939 elf_link_hash_traverse (&htab->root, elfNN_aarch64_allocate_ifunc_dynrelocs,
8942 /* Allocate .plt and .got entries, and space for local symbols. */
8943 htab_traverse (htab->loc_hash_table,
8944 elfNN_aarch64_allocate_local_dynrelocs,
8947 /* Allocate .plt and .got entries, and space for local ifunc symbols. */
8948 htab_traverse (htab->loc_hash_table,
8949 elfNN_aarch64_allocate_local_ifunc_dynrelocs,
8952 /* For every jump slot reserved in the sgotplt, reloc_count is
8953 incremented. However, when we reserve space for TLS descriptors,
8954 it's not incremented, so in order to compute the space reserved
8955 for them, it suffices to multiply the reloc count by the jump
8958 if (htab->root.srelplt)
8959 htab->sgotplt_jump_table_size = aarch64_compute_jump_table_size (htab);
8961 if (htab->tlsdesc_plt)
8963 if (htab->root.splt->size == 0)
8964 htab->root.splt->size += htab->plt_header_size;
8966 htab->tlsdesc_plt = htab->root.splt->size;
8967 htab->root.splt->size += htab->tlsdesc_plt_entry_size;
8969 /* If we're not using lazy TLS relocations, don't generate the
8970 GOT entry required. */
8971 if (!(info->flags & DF_BIND_NOW))
8973 htab->dt_tlsdesc_got = htab->root.sgot->size;
8974 htab->root.sgot->size += GOT_ENTRY_SIZE;
8978 /* Init mapping symbols information to use later to distingush between
8979 code and data while scanning for errata. */
8980 if (htab->fix_erratum_835769 || htab->fix_erratum_843419)
8981 for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link.next)
8983 if (!is_aarch64_elf (ibfd))
8985 bfd_elfNN_aarch64_init_maps (ibfd);
8988 /* We now have determined the sizes of the various dynamic sections.
8989 Allocate memory for them. */
8991 for (s = dynobj->sections; s != NULL; s = s->next)
8993 if ((s->flags & SEC_LINKER_CREATED) == 0)
8996 if (s == htab->root.splt
8997 || s == htab->root.sgot
8998 || s == htab->root.sgotplt
8999 || s == htab->root.iplt
9000 || s == htab->root.igotplt
9001 || s == htab->root.sdynbss
9002 || s == htab->root.sdynrelro)
9004 /* Strip this section if we don't need it; see the
9007 else if (CONST_STRNEQ (bfd_get_section_name (dynobj, s), ".rela"))
9009 if (s->size != 0 && s != htab->root.srelplt)
9012 /* We use the reloc_count field as a counter if we need
9013 to copy relocs into the output file. */
9014 if (s != htab->root.srelplt)
9019 /* It's not one of our sections, so don't allocate space. */
9025 /* If we don't need this section, strip it from the
9026 output file. This is mostly to handle .rela.bss and
9027 .rela.plt. We must create both sections in
9028 create_dynamic_sections, because they must be created
9029 before the linker maps input sections to output
9030 sections. The linker does that before
9031 adjust_dynamic_symbol is called, and it is that
9032 function which decides whether anything needs to go
9033 into these sections. */
9034 s->flags |= SEC_EXCLUDE;
9038 if ((s->flags & SEC_HAS_CONTENTS) == 0)
9041 /* Allocate memory for the section contents. We use bfd_zalloc
9042 here in case unused entries are not reclaimed before the
9043 section's contents are written out. This should not happen,
9044 but this way if it does, we get a R_AARCH64_NONE reloc instead
9046 s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->size);
9047 if (s->contents == NULL)
9051 if (htab->root.dynamic_sections_created)
9053 /* Add some entries to the .dynamic section. We fill in the
9054 values later, in elfNN_aarch64_finish_dynamic_sections, but we
9055 must add the entries now so that we get the correct size for
9056 the .dynamic section. The DT_DEBUG entry is filled in by the
9057 dynamic linker and used by the debugger. */
9058 #define add_dynamic_entry(TAG, VAL) \
9059 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
9061 if (bfd_link_executable (info))
9063 if (!add_dynamic_entry (DT_DEBUG, 0))
9067 if (htab->root.splt->size != 0)
9069 if (!add_dynamic_entry (DT_PLTGOT, 0)
9070 || !add_dynamic_entry (DT_PLTRELSZ, 0)
9071 || !add_dynamic_entry (DT_PLTREL, DT_RELA)
9072 || !add_dynamic_entry (DT_JMPREL, 0))
9075 if (htab->tlsdesc_plt
9076 && (!add_dynamic_entry (DT_TLSDESC_PLT, 0)
9077 || !add_dynamic_entry (DT_TLSDESC_GOT, 0)))
9080 if ((elf_aarch64_tdata (output_bfd)->plt_type == PLT_BTI)
9081 && !add_dynamic_entry (DT_AARCH64_BTI_PLT, 0))
9087 if (!add_dynamic_entry (DT_RELA, 0)
9088 || !add_dynamic_entry (DT_RELASZ, 0)
9089 || !add_dynamic_entry (DT_RELAENT, RELOC_SIZE (htab)))
9092 /* If any dynamic relocs apply to a read-only section,
9093 then we need a DT_TEXTREL entry. */
9094 if ((info->flags & DF_TEXTREL) == 0)
9095 elf_link_hash_traverse (&htab->root, maybe_set_textrel, info);
9097 if ((info->flags & DF_TEXTREL) != 0)
9099 if (!add_dynamic_entry (DT_TEXTREL, 0))
9104 #undef add_dynamic_entry
9110 elf_aarch64_update_plt_entry (bfd *output_bfd,
9111 bfd_reloc_code_real_type r_type,
9112 bfd_byte *plt_entry, bfd_vma value)
9114 reloc_howto_type *howto = elfNN_aarch64_howto_from_bfd_reloc (r_type);
9116 /* FIXME: We should check the return value from this function call. */
9117 (void) _bfd_aarch64_elf_put_addend (output_bfd, plt_entry, r_type, howto, value);
9121 elfNN_aarch64_create_small_pltn_entry (struct elf_link_hash_entry *h,
9122 struct elf_aarch64_link_hash_table
9123 *htab, bfd *output_bfd,
9124 struct bfd_link_info *info)
9126 bfd_byte *plt_entry;
9129 bfd_vma gotplt_entry_address;
9130 bfd_vma plt_entry_address;
9131 Elf_Internal_Rela rela;
9133 asection *plt, *gotplt, *relplt;
9135 /* When building a static executable, use .iplt, .igot.plt and
9136 .rela.iplt sections for STT_GNU_IFUNC symbols. */
9137 if (htab->root.splt != NULL)
9139 plt = htab->root.splt;
9140 gotplt = htab->root.sgotplt;
9141 relplt = htab->root.srelplt;
9145 plt = htab->root.iplt;
9146 gotplt = htab->root.igotplt;
9147 relplt = htab->root.irelplt;
9150 /* Get the index in the procedure linkage table which
9151 corresponds to this symbol. This is the index of this symbol
9152 in all the symbols for which we are making plt entries. The
9153 first entry in the procedure linkage table is reserved.
9155 Get the offset into the .got table of the entry that
9156 corresponds to this function. Each .got entry is GOT_ENTRY_SIZE
9157 bytes. The first three are reserved for the dynamic linker.
9159 For static executables, we don't reserve anything. */
9161 if (plt == htab->root.splt)
9163 plt_index = (h->plt.offset - htab->plt_header_size) / htab->plt_entry_size;
9164 got_offset = (plt_index + 3) * GOT_ENTRY_SIZE;
9168 plt_index = h->plt.offset / htab->plt_entry_size;
9169 got_offset = plt_index * GOT_ENTRY_SIZE;
9172 plt_entry = plt->contents + h->plt.offset;
9173 plt_entry_address = plt->output_section->vma
9174 + plt->output_offset + h->plt.offset;
9175 gotplt_entry_address = gotplt->output_section->vma +
9176 gotplt->output_offset + got_offset;
9178 /* Copy in the boiler-plate for the PLTn entry. */
9179 memcpy (plt_entry, htab->plt_entry, htab->plt_entry_size);
9181 /* First instruction in BTI enabled PLT stub is a BTI
9182 instruction so skip it. */
9183 if (elf_aarch64_tdata (output_bfd)->plt_type & PLT_BTI
9184 && elf_elfheader (output_bfd)->e_type == ET_EXEC)
9185 plt_entry = plt_entry + 4;
9187 /* Fill in the top 21 bits for this: ADRP x16, PLT_GOT + n * 8.
9188 ADRP: ((PG(S+A)-PG(P)) >> 12) & 0x1fffff */
9189 elf_aarch64_update_plt_entry (output_bfd, BFD_RELOC_AARCH64_ADR_HI21_PCREL,
9191 PG (gotplt_entry_address) -
9192 PG (plt_entry_address));
9194 /* Fill in the lo12 bits for the load from the pltgot. */
9195 elf_aarch64_update_plt_entry (output_bfd, BFD_RELOC_AARCH64_LDSTNN_LO12,
9197 PG_OFFSET (gotplt_entry_address));
9199 /* Fill in the lo12 bits for the add from the pltgot entry. */
9200 elf_aarch64_update_plt_entry (output_bfd, BFD_RELOC_AARCH64_ADD_LO12,
9202 PG_OFFSET (gotplt_entry_address));
9204 /* All the GOTPLT Entries are essentially initialized to PLT0. */
9205 bfd_put_NN (output_bfd,
9206 plt->output_section->vma + plt->output_offset,
9207 gotplt->contents + got_offset);
9209 rela.r_offset = gotplt_entry_address;
9211 if (h->dynindx == -1
9212 || ((bfd_link_executable (info)
9213 || ELF_ST_VISIBILITY (h->other) != STV_DEFAULT)
9215 && h->type == STT_GNU_IFUNC))
9217 /* If an STT_GNU_IFUNC symbol is locally defined, generate
9218 R_AARCH64_IRELATIVE instead of R_AARCH64_JUMP_SLOT. */
9219 rela.r_info = ELFNN_R_INFO (0, AARCH64_R (IRELATIVE));
9220 rela.r_addend = (h->root.u.def.value
9221 + h->root.u.def.section->output_section->vma
9222 + h->root.u.def.section->output_offset);
9226 /* Fill in the entry in the .rela.plt section. */
9227 rela.r_info = ELFNN_R_INFO (h->dynindx, AARCH64_R (JUMP_SLOT));
9231 /* Compute the relocation entry to used based on PLT index and do
9232 not adjust reloc_count. The reloc_count has already been adjusted
9233 to account for this entry. */
9234 loc = relplt->contents + plt_index * RELOC_SIZE (htab);
9235 bfd_elfNN_swap_reloca_out (output_bfd, &rela, loc);
9238 /* Size sections even though they're not dynamic. We use it to setup
9239 _TLS_MODULE_BASE_, if needed. */
9242 elfNN_aarch64_always_size_sections (bfd *output_bfd,
9243 struct bfd_link_info *info)
9247 if (bfd_link_relocatable (info))
9250 tls_sec = elf_hash_table (info)->tls_sec;
9254 struct elf_link_hash_entry *tlsbase;
9256 tlsbase = elf_link_hash_lookup (elf_hash_table (info),
9257 "_TLS_MODULE_BASE_", TRUE, TRUE, FALSE);
9261 struct bfd_link_hash_entry *h = NULL;
9262 const struct elf_backend_data *bed =
9263 get_elf_backend_data (output_bfd);
9265 if (!(_bfd_generic_link_add_one_symbol
9266 (info, output_bfd, "_TLS_MODULE_BASE_", BSF_LOCAL,
9267 tls_sec, 0, NULL, FALSE, bed->collect, &h)))
9270 tlsbase->type = STT_TLS;
9271 tlsbase = (struct elf_link_hash_entry *) h;
9272 tlsbase->def_regular = 1;
9273 tlsbase->other = STV_HIDDEN;
9274 (*bed->elf_backend_hide_symbol) (info, tlsbase, TRUE);
9281 /* Finish up dynamic symbol handling. We set the contents of various
9282 dynamic sections here. */
9285 elfNN_aarch64_finish_dynamic_symbol (bfd *output_bfd,
9286 struct bfd_link_info *info,
9287 struct elf_link_hash_entry *h,
9288 Elf_Internal_Sym *sym)
9290 struct elf_aarch64_link_hash_table *htab;
9291 htab = elf_aarch64_hash_table (info);
9293 if (h->plt.offset != (bfd_vma) - 1)
9295 asection *plt, *gotplt, *relplt;
9297 /* This symbol has an entry in the procedure linkage table. Set
9300 /* When building a static executable, use .iplt, .igot.plt and
9301 .rela.iplt sections for STT_GNU_IFUNC symbols. */
9302 if (htab->root.splt != NULL)
9304 plt = htab->root.splt;
9305 gotplt = htab->root.sgotplt;
9306 relplt = htab->root.srelplt;
9310 plt = htab->root.iplt;
9311 gotplt = htab->root.igotplt;
9312 relplt = htab->root.irelplt;
9315 /* This symbol has an entry in the procedure linkage table. Set
9317 if ((h->dynindx == -1
9318 && !((h->forced_local || bfd_link_executable (info))
9320 && h->type == STT_GNU_IFUNC))
9326 elfNN_aarch64_create_small_pltn_entry (h, htab, output_bfd, info);
9327 if (!h->def_regular)
9329 /* Mark the symbol as undefined, rather than as defined in
9330 the .plt section. */
9331 sym->st_shndx = SHN_UNDEF;
9332 /* If the symbol is weak we need to clear the value.
9333 Otherwise, the PLT entry would provide a definition for
9334 the symbol even if the symbol wasn't defined anywhere,
9335 and so the symbol would never be NULL. Leave the value if
9336 there were any relocations where pointer equality matters
9337 (this is a clue for the dynamic linker, to make function
9338 pointer comparisons work between an application and shared
9340 if (!h->ref_regular_nonweak || !h->pointer_equality_needed)
9345 if (h->got.offset != (bfd_vma) - 1
9346 && elf_aarch64_hash_entry (h)->got_type == GOT_NORMAL
9347 /* Undefined weak symbol in static PIE resolves to 0 without
9348 any dynamic relocations. */
9349 && !UNDEFWEAK_NO_DYNAMIC_RELOC (info, h))
9351 Elf_Internal_Rela rela;
9354 /* This symbol has an entry in the global offset table. Set it
9356 if (htab->root.sgot == NULL || htab->root.srelgot == NULL)
9359 rela.r_offset = (htab->root.sgot->output_section->vma
9360 + htab->root.sgot->output_offset
9361 + (h->got.offset & ~(bfd_vma) 1));
9364 && h->type == STT_GNU_IFUNC)
9366 if (bfd_link_pic (info))
9368 /* Generate R_AARCH64_GLOB_DAT. */
9375 if (!h->pointer_equality_needed)
9378 /* For non-shared object, we can't use .got.plt, which
9379 contains the real function address if we need pointer
9380 equality. We load the GOT entry with the PLT entry. */
9381 plt = htab->root.splt ? htab->root.splt : htab->root.iplt;
9382 bfd_put_NN (output_bfd, (plt->output_section->vma
9383 + plt->output_offset
9385 htab->root.sgot->contents
9386 + (h->got.offset & ~(bfd_vma) 1));
9390 else if (bfd_link_pic (info) && SYMBOL_REFERENCES_LOCAL (info, h))
9392 if (!(h->def_regular || ELF_COMMON_DEF_P (h)))
9395 BFD_ASSERT ((h->got.offset & 1) != 0);
9396 rela.r_info = ELFNN_R_INFO (0, AARCH64_R (RELATIVE));
9397 rela.r_addend = (h->root.u.def.value
9398 + h->root.u.def.section->output_section->vma
9399 + h->root.u.def.section->output_offset);
9404 BFD_ASSERT ((h->got.offset & 1) == 0);
9405 bfd_put_NN (output_bfd, (bfd_vma) 0,
9406 htab->root.sgot->contents + h->got.offset);
9407 rela.r_info = ELFNN_R_INFO (h->dynindx, AARCH64_R (GLOB_DAT));
9411 loc = htab->root.srelgot->contents;
9412 loc += htab->root.srelgot->reloc_count++ * RELOC_SIZE (htab);
9413 bfd_elfNN_swap_reloca_out (output_bfd, &rela, loc);
9418 Elf_Internal_Rela rela;
9422 /* This symbol needs a copy reloc. Set it up. */
9423 if (h->dynindx == -1
9424 || (h->root.type != bfd_link_hash_defined
9425 && h->root.type != bfd_link_hash_defweak)
9426 || htab->root.srelbss == NULL)
9429 rela.r_offset = (h->root.u.def.value
9430 + h->root.u.def.section->output_section->vma
9431 + h->root.u.def.section->output_offset);
9432 rela.r_info = ELFNN_R_INFO (h->dynindx, AARCH64_R (COPY));
9434 if (h->root.u.def.section == htab->root.sdynrelro)
9435 s = htab->root.sreldynrelro;
9437 s = htab->root.srelbss;
9438 loc = s->contents + s->reloc_count++ * RELOC_SIZE (htab);
9439 bfd_elfNN_swap_reloca_out (output_bfd, &rela, loc);
9442 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. SYM may
9443 be NULL for local symbols. */
9445 && (h == elf_hash_table (info)->hdynamic
9446 || h == elf_hash_table (info)->hgot))
9447 sym->st_shndx = SHN_ABS;
9452 /* Finish up local dynamic symbol handling. We set the contents of
9453 various dynamic sections here. */
9456 elfNN_aarch64_finish_local_dynamic_symbol (void **slot, void *inf)
9458 struct elf_link_hash_entry *h
9459 = (struct elf_link_hash_entry *) *slot;
9460 struct bfd_link_info *info
9461 = (struct bfd_link_info *) inf;
9463 return elfNN_aarch64_finish_dynamic_symbol (info->output_bfd,
9468 elfNN_aarch64_init_small_plt0_entry (bfd *output_bfd ATTRIBUTE_UNUSED,
9469 struct elf_aarch64_link_hash_table
9472 /* Fill in PLT0. Fixme:RR Note this doesn't distinguish between
9473 small and large plts and at the minute just generates
9476 /* PLT0 of the small PLT looks like this in ELF64 -
9477 stp x16, x30, [sp, #-16]! // Save the reloc and lr on stack.
9478 adrp x16, PLT_GOT + 16 // Get the page base of the GOTPLT
9479 ldr x17, [x16, #:lo12:PLT_GOT+16] // Load the address of the
9481 add x16, x16, #:lo12:PLT_GOT+16 // Load the lo12 bits of the
9482 // GOTPLT entry for this.
9484 PLT0 will be slightly different in ELF32 due to different got entry
9486 bfd_vma plt_got_2nd_ent; /* Address of GOT[2]. */
9490 memcpy (htab->root.splt->contents, htab->plt0_entry,
9491 htab->plt_header_size);
9492 elf_section_data (htab->root.splt->output_section)->this_hdr.sh_entsize =
9493 htab->plt_header_size;
9495 plt_got_2nd_ent = (htab->root.sgotplt->output_section->vma
9496 + htab->root.sgotplt->output_offset
9497 + GOT_ENTRY_SIZE * 2);
9499 plt_base = htab->root.splt->output_section->vma +
9500 htab->root.splt->output_offset;
9502 /* First instruction in BTI enabled PLT stub is a BTI
9503 instruction so skip it. */
9504 bfd_byte *plt0_entry = htab->root.splt->contents;
9505 if (elf_aarch64_tdata (output_bfd)->plt_type & PLT_BTI)
9506 plt0_entry = plt0_entry + 4;
9508 /* Fill in the top 21 bits for this: ADRP x16, PLT_GOT + n * 8.
9509 ADRP: ((PG(S+A)-PG(P)) >> 12) & 0x1fffff */
9510 elf_aarch64_update_plt_entry (output_bfd, BFD_RELOC_AARCH64_ADR_HI21_PCREL,
9512 PG (plt_got_2nd_ent) - PG (plt_base + 4));
9514 elf_aarch64_update_plt_entry (output_bfd, BFD_RELOC_AARCH64_LDSTNN_LO12,
9516 PG_OFFSET (plt_got_2nd_ent));
9518 elf_aarch64_update_plt_entry (output_bfd, BFD_RELOC_AARCH64_ADD_LO12,
9520 PG_OFFSET (plt_got_2nd_ent));
9524 elfNN_aarch64_finish_dynamic_sections (bfd *output_bfd,
9525 struct bfd_link_info *info)
9527 struct elf_aarch64_link_hash_table *htab;
9531 htab = elf_aarch64_hash_table (info);
9532 dynobj = htab->root.dynobj;
9533 sdyn = bfd_get_linker_section (dynobj, ".dynamic");
9535 if (htab->root.dynamic_sections_created)
9537 ElfNN_External_Dyn *dyncon, *dynconend;
9539 if (sdyn == NULL || htab->root.sgot == NULL)
9542 dyncon = (ElfNN_External_Dyn *) sdyn->contents;
9543 dynconend = (ElfNN_External_Dyn *) (sdyn->contents + sdyn->size);
9544 for (; dyncon < dynconend; dyncon++)
9546 Elf_Internal_Dyn dyn;
9549 bfd_elfNN_swap_dyn_in (dynobj, dyncon, &dyn);
9557 s = htab->root.sgotplt;
9558 dyn.d_un.d_ptr = s->output_section->vma + s->output_offset;
9562 s = htab->root.srelplt;
9563 dyn.d_un.d_ptr = s->output_section->vma + s->output_offset;
9567 s = htab->root.srelplt;
9568 dyn.d_un.d_val = s->size;
9571 case DT_TLSDESC_PLT:
9572 s = htab->root.splt;
9573 dyn.d_un.d_ptr = s->output_section->vma + s->output_offset
9574 + htab->tlsdesc_plt;
9577 case DT_TLSDESC_GOT:
9578 s = htab->root.sgot;
9579 dyn.d_un.d_ptr = s->output_section->vma + s->output_offset
9580 + htab->dt_tlsdesc_got;
9584 bfd_elfNN_swap_dyn_out (output_bfd, &dyn, dyncon);
9589 /* Fill in the special first entry in the procedure linkage table. */
9590 if (htab->root.splt && htab->root.splt->size > 0)
9592 elfNN_aarch64_init_small_plt0_entry (output_bfd, htab);
9594 elf_section_data (htab->root.splt->output_section)->
9595 this_hdr.sh_entsize = htab->plt_entry_size;
9598 if (htab->tlsdesc_plt)
9600 bfd_put_NN (output_bfd, (bfd_vma) 0,
9601 htab->root.sgot->contents + htab->dt_tlsdesc_got);
9603 const bfd_byte *entry = elfNN_aarch64_tlsdesc_small_plt_entry;
9604 htab->tlsdesc_plt_entry_size = PLT_TLSDESC_ENTRY_SIZE;
9606 aarch64_plt_type type = elf_aarch64_tdata (output_bfd)->plt_type;
9607 if (type == PLT_BTI)
9609 entry = elfNN_aarch64_tlsdesc_small_plt_bti_entry;
9610 htab->tlsdesc_plt_entry_size = PLT_BTI_TLSDESC_ENTRY_SIZE;
9613 memcpy (htab->root.splt->contents + htab->tlsdesc_plt,
9614 entry, htab->tlsdesc_plt_entry_size);
9617 bfd_vma adrp1_addr =
9618 htab->root.splt->output_section->vma
9619 + htab->root.splt->output_offset + htab->tlsdesc_plt + 4;
9621 bfd_vma adrp2_addr = adrp1_addr + 4;
9624 htab->root.sgot->output_section->vma
9625 + htab->root.sgot->output_offset;
9627 bfd_vma pltgot_addr =
9628 htab->root.sgotplt->output_section->vma
9629 + htab->root.sgotplt->output_offset;
9631 bfd_vma dt_tlsdesc_got = got_addr + htab->dt_tlsdesc_got;
9633 bfd_byte *plt_entry =
9634 htab->root.splt->contents + htab->tlsdesc_plt;
9636 /* First instruction in BTI enabled PLT stub is a BTI
9637 instruction so skip it. */
9640 plt_entry = plt_entry + 4;
9641 adrp1_addr = adrp1_addr + 4;
9642 adrp2_addr = adrp2_addr + 4;
9645 /* adrp x2, DT_TLSDESC_GOT */
9646 elf_aarch64_update_plt_entry (output_bfd,
9647 BFD_RELOC_AARCH64_ADR_HI21_PCREL,
9649 (PG (dt_tlsdesc_got)
9650 - PG (adrp1_addr)));
9653 elf_aarch64_update_plt_entry (output_bfd,
9654 BFD_RELOC_AARCH64_ADR_HI21_PCREL,
9657 - PG (adrp2_addr)));
9659 /* ldr x2, [x2, #0] */
9660 elf_aarch64_update_plt_entry (output_bfd,
9661 BFD_RELOC_AARCH64_LDSTNN_LO12,
9663 PG_OFFSET (dt_tlsdesc_got));
9666 elf_aarch64_update_plt_entry (output_bfd,
9667 BFD_RELOC_AARCH64_ADD_LO12,
9669 PG_OFFSET (pltgot_addr));
9674 if (htab->root.sgotplt)
9676 if (bfd_is_abs_section (htab->root.sgotplt->output_section))
9679 (_("discarded output section: `%pA'"), htab->root.sgotplt);
9683 /* Fill in the first three entries in the global offset table. */
9684 if (htab->root.sgotplt->size > 0)
9686 bfd_put_NN (output_bfd, (bfd_vma) 0, htab->root.sgotplt->contents);
9688 /* Write GOT[1] and GOT[2], needed for the dynamic linker. */
9689 bfd_put_NN (output_bfd,
9691 htab->root.sgotplt->contents + GOT_ENTRY_SIZE);
9692 bfd_put_NN (output_bfd,
9694 htab->root.sgotplt->contents + GOT_ENTRY_SIZE * 2);
9697 if (htab->root.sgot)
9699 if (htab->root.sgot->size > 0)
9702 sdyn ? sdyn->output_section->vma + sdyn->output_offset : 0;
9703 bfd_put_NN (output_bfd, addr, htab->root.sgot->contents);
9707 elf_section_data (htab->root.sgotplt->output_section)->
9708 this_hdr.sh_entsize = GOT_ENTRY_SIZE;
9711 if (htab->root.sgot && htab->root.sgot->size > 0)
9712 elf_section_data (htab->root.sgot->output_section)->this_hdr.sh_entsize
9715 /* Fill PLT and GOT entries for local STT_GNU_IFUNC symbols. */
9716 htab_traverse (htab->loc_hash_table,
9717 elfNN_aarch64_finish_local_dynamic_symbol,
9723 /* Check if BTI enabled PLTs are needed. Returns the type needed. */
9724 static aarch64_plt_type
9725 get_plt_type (bfd *abfd)
9727 aarch64_plt_type ret = PLT_NORMAL;
9728 bfd_byte *contents, *extdyn, *extdynend;
9729 asection *sec = bfd_get_section_by_name (abfd, ".dynamic");
9730 if (!sec || !bfd_malloc_and_get_section (abfd, sec, &contents))
9733 extdynend = contents + sec->size;
9734 for (; extdyn < extdynend; extdyn += sizeof (ElfNN_External_Dyn))
9736 Elf_Internal_Dyn dyn;
9737 bfd_elfNN_swap_dyn_in (abfd, extdyn, &dyn);
9739 /* Let's check the processor specific dynamic array tags. */
9740 bfd_vma tag = dyn.d_tag;
9741 if (tag < DT_LOPROC || tag > DT_HIPROC)
9746 case DT_AARCH64_BTI_PLT:
9758 elfNN_aarch64_get_synthetic_symtab (bfd *abfd,
9765 elf_aarch64_tdata (abfd)->plt_type = get_plt_type (abfd);
9766 return _bfd_elf_get_synthetic_symtab (abfd, symcount, syms,
9767 dynsymcount, dynsyms, ret);
9770 /* Return address for Ith PLT stub in section PLT, for relocation REL
9771 or (bfd_vma) -1 if it should not be included. */
9774 elfNN_aarch64_plt_sym_val (bfd_vma i, const asection *plt,
9775 const arelent *rel ATTRIBUTE_UNUSED)
9777 size_t plt0_size = PLT_ENTRY_SIZE;
9778 size_t pltn_size = PLT_SMALL_ENTRY_SIZE;
9780 if (elf_aarch64_tdata (plt->owner)->plt_type == PLT_BTI)
9782 plt0_size = PLT_BTI_ENTRY_SIZE;
9783 if (elf_elfheader (plt->owner)->e_type == ET_EXEC)
9784 pltn_size = PLT_BTI_SMALL_ENTRY_SIZE;
9786 return plt->vma + plt0_size + i * pltn_size;
9789 /* Returns TRUE if NAME is an AArch64 mapping symbol.
9790 The ARM ELF standard defines $x (for A64 code) and $d (for data).
9791 It also allows a period initiated suffix to be added to the symbol, ie:
9792 "$[adtx]\.[:sym_char]+". */
9795 is_aarch64_mapping_symbol (const char * name)
9797 return name != NULL /* Paranoia. */
9798 && name[0] == '$' /* Note: if objcopy --prefix-symbols has been used then
9799 the mapping symbols could have acquired a prefix.
9800 We do not support this here, since such symbols no
9801 longer conform to the ARM ELF ABI. */
9802 && (name[1] == 'd' || name[1] == 'x')
9803 && (name[2] == 0 || name[2] == '.');
9804 /* FIXME: Strictly speaking the symbol is only a valid mapping symbol if
9805 any characters that follow the period are legal characters for the body
9806 of a symbol's name. For now we just assume that this is the case. */
9809 /* Make sure that mapping symbols in object files are not removed via the
9810 "strip --strip-unneeded" tool. These symbols might needed in order to
9811 correctly generate linked files. Once an object file has been linked,
9812 it should be safe to remove them. */
9815 elfNN_aarch64_backend_symbol_processing (bfd *abfd, asymbol *sym)
9817 if (((abfd->flags & (EXEC_P | DYNAMIC)) == 0)
9818 && sym->section != bfd_abs_section_ptr
9819 && is_aarch64_mapping_symbol (sym->name))
9820 sym->flags |= BSF_KEEP;
9823 /* Implement elf_backend_setup_gnu_properties for AArch64. It serves as a
9824 wrapper function for _bfd_aarch64_elf_link_setup_gnu_properties to account
9825 for the effect of GNU properties of the output_bfd. */
9827 elfNN_aarch64_link_setup_gnu_properties (struct bfd_link_info *info)
9829 uint32_t prop = elf_aarch64_tdata (info->output_bfd)->gnu_and_prop;
9830 bfd *pbfd = _bfd_aarch64_elf_link_setup_gnu_properties (info, &prop);
9831 elf_aarch64_tdata (info->output_bfd)->gnu_and_prop = prop;
9832 elf_aarch64_tdata (info->output_bfd)->plt_type
9833 |= (prop & GNU_PROPERTY_AARCH64_FEATURE_1_BTI) ? PLT_BTI : 0;
9834 setup_plt_values (info, elf_aarch64_tdata (info->output_bfd)->plt_type);
9838 /* Implement elf_backend_merge_gnu_properties for AArch64. It serves as a
9839 wrapper function for _bfd_aarch64_elf_merge_gnu_properties to account
9840 for the effect of GNU properties of the output_bfd. */
9842 elfNN_aarch64_merge_gnu_properties (struct bfd_link_info *info,
9844 elf_property *aprop,
9845 elf_property *bprop)
9848 = elf_aarch64_tdata (info->output_bfd)->gnu_and_prop;
9850 /* If output has been marked with BTI using command line argument, give out
9851 warning if necessary. */
9852 if ((prop & GNU_PROPERTY_AARCH64_FEATURE_1_BTI)
9853 && (!elf_aarch64_tdata (info->output_bfd)->no_bti_warn))
9855 if ((aprop && !(aprop->u.number & GNU_PROPERTY_AARCH64_FEATURE_1_BTI))
9856 || (bprop && !(bprop->u.number & GNU_PROPERTY_AARCH64_FEATURE_1_BTI))
9857 /* If either property is NULL, it means its bfd did not have any
9859 || !aprop || !bprop)
9861 _bfd_error_handler (_("warning: BTI turned on by --force-bti when "
9862 "all inputs do not have BTI in NOTE section."));
9866 return _bfd_aarch64_elf_merge_gnu_properties (info, abfd, aprop,
9870 /* We use this so we can override certain functions
9871 (though currently we don't). */
9873 const struct elf_size_info elfNN_aarch64_size_info =
9875 sizeof (ElfNN_External_Ehdr),
9876 sizeof (ElfNN_External_Phdr),
9877 sizeof (ElfNN_External_Shdr),
9878 sizeof (ElfNN_External_Rel),
9879 sizeof (ElfNN_External_Rela),
9880 sizeof (ElfNN_External_Sym),
9881 sizeof (ElfNN_External_Dyn),
9882 sizeof (Elf_External_Note),
9883 4, /* Hash table entry size. */
9884 1, /* Internal relocs per external relocs. */
9885 ARCH_SIZE, /* Arch size. */
9886 LOG_FILE_ALIGN, /* Log_file_align. */
9887 ELFCLASSNN, EV_CURRENT,
9888 bfd_elfNN_write_out_phdrs,
9889 bfd_elfNN_write_shdrs_and_ehdr,
9890 bfd_elfNN_checksum_contents,
9891 bfd_elfNN_write_relocs,
9892 bfd_elfNN_swap_symbol_in,
9893 bfd_elfNN_swap_symbol_out,
9894 bfd_elfNN_slurp_reloc_table,
9895 bfd_elfNN_slurp_symbol_table,
9896 bfd_elfNN_swap_dyn_in,
9897 bfd_elfNN_swap_dyn_out,
9898 bfd_elfNN_swap_reloc_in,
9899 bfd_elfNN_swap_reloc_out,
9900 bfd_elfNN_swap_reloca_in,
9901 bfd_elfNN_swap_reloca_out
9904 #define ELF_ARCH bfd_arch_aarch64
9905 #define ELF_MACHINE_CODE EM_AARCH64
9906 #define ELF_MAXPAGESIZE 0x10000
9907 #define ELF_MINPAGESIZE 0x1000
9908 #define ELF_COMMONPAGESIZE 0x1000
9910 #define bfd_elfNN_close_and_cleanup \
9911 elfNN_aarch64_close_and_cleanup
9913 #define bfd_elfNN_bfd_free_cached_info \
9914 elfNN_aarch64_bfd_free_cached_info
9916 #define bfd_elfNN_bfd_is_target_special_symbol \
9917 elfNN_aarch64_is_target_special_symbol
9919 #define bfd_elfNN_bfd_link_hash_table_create \
9920 elfNN_aarch64_link_hash_table_create
9922 #define bfd_elfNN_bfd_merge_private_bfd_data \
9923 elfNN_aarch64_merge_private_bfd_data
9925 #define bfd_elfNN_bfd_print_private_bfd_data \
9926 elfNN_aarch64_print_private_bfd_data
9928 #define bfd_elfNN_bfd_reloc_type_lookup \
9929 elfNN_aarch64_reloc_type_lookup
9931 #define bfd_elfNN_bfd_reloc_name_lookup \
9932 elfNN_aarch64_reloc_name_lookup
9934 #define bfd_elfNN_bfd_set_private_flags \
9935 elfNN_aarch64_set_private_flags
9937 #define bfd_elfNN_find_inliner_info \
9938 elfNN_aarch64_find_inliner_info
9940 #define bfd_elfNN_find_nearest_line \
9941 elfNN_aarch64_find_nearest_line
9943 #define bfd_elfNN_get_synthetic_symtab \
9944 elfNN_aarch64_get_synthetic_symtab
9946 #define bfd_elfNN_mkobject \
9947 elfNN_aarch64_mkobject
9949 #define bfd_elfNN_new_section_hook \
9950 elfNN_aarch64_new_section_hook
9952 #define elf_backend_adjust_dynamic_symbol \
9953 elfNN_aarch64_adjust_dynamic_symbol
9955 #define elf_backend_always_size_sections \
9956 elfNN_aarch64_always_size_sections
9958 #define elf_backend_check_relocs \
9959 elfNN_aarch64_check_relocs
9961 #define elf_backend_copy_indirect_symbol \
9962 elfNN_aarch64_copy_indirect_symbol
9964 /* Create .dynbss, and .rela.bss sections in DYNOBJ, and set up shortcuts
9965 to them in our hash. */
9966 #define elf_backend_create_dynamic_sections \
9967 elfNN_aarch64_create_dynamic_sections
9969 #define elf_backend_init_index_section \
9970 _bfd_elf_init_2_index_sections
9972 #define elf_backend_finish_dynamic_sections \
9973 elfNN_aarch64_finish_dynamic_sections
9975 #define elf_backend_finish_dynamic_symbol \
9976 elfNN_aarch64_finish_dynamic_symbol
9978 #define elf_backend_object_p \
9979 elfNN_aarch64_object_p
9981 #define elf_backend_output_arch_local_syms \
9982 elfNN_aarch64_output_arch_local_syms
9984 #define elf_backend_plt_sym_val \
9985 elfNN_aarch64_plt_sym_val
9987 #define elf_backend_post_process_headers \
9988 elfNN_aarch64_post_process_headers
9990 #define elf_backend_relocate_section \
9991 elfNN_aarch64_relocate_section
9993 #define elf_backend_reloc_type_class \
9994 elfNN_aarch64_reloc_type_class
9996 #define elf_backend_section_from_shdr \
9997 elfNN_aarch64_section_from_shdr
9999 #define elf_backend_size_dynamic_sections \
10000 elfNN_aarch64_size_dynamic_sections
10002 #define elf_backend_size_info \
10003 elfNN_aarch64_size_info
10005 #define elf_backend_write_section \
10006 elfNN_aarch64_write_section
10008 #define elf_backend_symbol_processing \
10009 elfNN_aarch64_backend_symbol_processing
10011 #define elf_backend_setup_gnu_properties \
10012 elfNN_aarch64_link_setup_gnu_properties
10014 #define elf_backend_merge_gnu_properties \
10015 elfNN_aarch64_merge_gnu_properties
10017 #define elf_backend_can_refcount 1
10018 #define elf_backend_can_gc_sections 1
10019 #define elf_backend_plt_readonly 1
10020 #define elf_backend_want_got_plt 1
10021 #define elf_backend_want_plt_sym 0
10022 #define elf_backend_want_dynrelro 1
10023 #define elf_backend_may_use_rel_p 0
10024 #define elf_backend_may_use_rela_p 1
10025 #define elf_backend_default_use_rela_p 1
10026 #define elf_backend_rela_normal 1
10027 #define elf_backend_dtrel_excludes_plt 1
10028 #define elf_backend_got_header_size (GOT_ENTRY_SIZE * 3)
10029 #define elf_backend_default_execstack 0
10030 #define elf_backend_extern_protected_data 1
10031 #define elf_backend_hash_symbol elf_aarch64_hash_symbol
10033 #undef elf_backend_obj_attrs_section
10034 #define elf_backend_obj_attrs_section ".ARM.attributes"
10036 #include "elfNN-target.h"
10038 /* CloudABI support. */
10040 #undef TARGET_LITTLE_SYM
10041 #define TARGET_LITTLE_SYM aarch64_elfNN_le_cloudabi_vec
10042 #undef TARGET_LITTLE_NAME
10043 #define TARGET_LITTLE_NAME "elfNN-littleaarch64-cloudabi"
10044 #undef TARGET_BIG_SYM
10045 #define TARGET_BIG_SYM aarch64_elfNN_be_cloudabi_vec
10046 #undef TARGET_BIG_NAME
10047 #define TARGET_BIG_NAME "elfNN-bigaarch64-cloudabi"
10050 #define ELF_OSABI ELFOSABI_CLOUDABI
10053 #define elfNN_bed elfNN_aarch64_cloudabi_bed
10055 #include "elfNN-target.h"