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)
271 /* Encoding of the nop instruction. */
272 #define INSN_NOP 0xd503201f
274 #define aarch64_compute_jump_table_size(htab) \
275 (((htab)->root.srelplt == NULL) ? 0 \
276 : (htab)->root.srelplt->reloc_count * GOT_ENTRY_SIZE)
278 /* The first entry in a procedure linkage table looks like this
279 if the distance between the PLTGOT and the PLT is < 4GB use
280 these PLT entries. Note that the dynamic linker gets &PLTGOT[2]
281 in x16 and needs to work out PLTGOT[1] by using an address of
282 [x16,#-GOT_ENTRY_SIZE]. */
283 static const bfd_byte elfNN_aarch64_small_plt0_entry[PLT_ENTRY_SIZE] =
285 0xf0, 0x7b, 0xbf, 0xa9, /* stp x16, x30, [sp, #-16]! */
286 0x10, 0x00, 0x00, 0x90, /* adrp x16, (GOT+16) */
288 0x11, 0x0A, 0x40, 0xf9, /* ldr x17, [x16, #PLT_GOT+0x10] */
289 0x10, 0x42, 0x00, 0x91, /* add x16, x16,#PLT_GOT+0x10 */
291 0x11, 0x0A, 0x40, 0xb9, /* ldr w17, [x16, #PLT_GOT+0x8] */
292 0x10, 0x22, 0x00, 0x11, /* add w16, w16,#PLT_GOT+0x8 */
294 0x20, 0x02, 0x1f, 0xd6, /* br x17 */
295 0x1f, 0x20, 0x03, 0xd5, /* nop */
296 0x1f, 0x20, 0x03, 0xd5, /* nop */
297 0x1f, 0x20, 0x03, 0xd5, /* nop */
300 /* Per function entry in a procedure linkage table looks like this
301 if the distance between the PLTGOT and the PLT is < 4GB use
302 these PLT entries. */
303 static const bfd_byte elfNN_aarch64_small_plt_entry[PLT_SMALL_ENTRY_SIZE] =
305 0x10, 0x00, 0x00, 0x90, /* adrp x16, PLTGOT + n * 8 */
307 0x11, 0x02, 0x40, 0xf9, /* ldr x17, [x16, PLTGOT + n * 8] */
308 0x10, 0x02, 0x00, 0x91, /* add x16, x16, :lo12:PLTGOT + n * 8 */
310 0x11, 0x02, 0x40, 0xb9, /* ldr w17, [x16, PLTGOT + n * 4] */
311 0x10, 0x02, 0x00, 0x11, /* add w16, w16, :lo12:PLTGOT + n * 4 */
313 0x20, 0x02, 0x1f, 0xd6, /* br x17. */
316 static const bfd_byte
317 elfNN_aarch64_tlsdesc_small_plt_entry[PLT_TLSDESC_ENTRY_SIZE] =
319 0xe2, 0x0f, 0xbf, 0xa9, /* stp x2, x3, [sp, #-16]! */
320 0x02, 0x00, 0x00, 0x90, /* adrp x2, 0 */
321 0x03, 0x00, 0x00, 0x90, /* adrp x3, 0 */
323 0x42, 0x00, 0x40, 0xf9, /* ldr x2, [x2, #0] */
324 0x63, 0x00, 0x00, 0x91, /* add x3, x3, 0 */
326 0x42, 0x00, 0x40, 0xb9, /* ldr w2, [x2, #0] */
327 0x63, 0x00, 0x00, 0x11, /* add w3, w3, 0 */
329 0x40, 0x00, 0x1f, 0xd6, /* br x2 */
330 0x1f, 0x20, 0x03, 0xd5, /* nop */
331 0x1f, 0x20, 0x03, 0xd5, /* nop */
334 #define elf_info_to_howto elfNN_aarch64_info_to_howto
335 #define elf_info_to_howto_rel elfNN_aarch64_info_to_howto
337 #define AARCH64_ELF_ABI_VERSION 0
339 /* In case we're on a 32-bit machine, construct a 64-bit "-1" value. */
340 #define ALL_ONES (~ (bfd_vma) 0)
342 /* Indexed by the bfd interal reloc enumerators.
343 Therefore, the table needs to be synced with BFD_RELOC_AARCH64_*
346 static reloc_howto_type elfNN_aarch64_howto_table[] =
350 /* Basic data relocations. */
352 /* Deprecated, but retained for backwards compatibility. */
353 HOWTO64 (R_AARCH64_NULL, /* type */
355 3, /* size (0 = byte, 1 = short, 2 = long) */
357 FALSE, /* pc_relative */
359 complain_overflow_dont, /* complain_on_overflow */
360 bfd_elf_generic_reloc, /* special_function */
361 "R_AARCH64_NULL", /* name */
362 FALSE, /* partial_inplace */
365 FALSE), /* pcrel_offset */
366 HOWTO (R_AARCH64_NONE, /* type */
368 3, /* size (0 = byte, 1 = short, 2 = long) */
370 FALSE, /* pc_relative */
372 complain_overflow_dont, /* complain_on_overflow */
373 bfd_elf_generic_reloc, /* special_function */
374 "R_AARCH64_NONE", /* name */
375 FALSE, /* partial_inplace */
378 FALSE), /* pcrel_offset */
381 HOWTO64 (AARCH64_R (ABS64), /* type */
383 4, /* size (4 = long long) */
385 FALSE, /* pc_relative */
387 complain_overflow_unsigned, /* complain_on_overflow */
388 bfd_elf_generic_reloc, /* special_function */
389 AARCH64_R_STR (ABS64), /* name */
390 FALSE, /* partial_inplace */
391 ALL_ONES, /* src_mask */
392 ALL_ONES, /* dst_mask */
393 FALSE), /* pcrel_offset */
396 HOWTO (AARCH64_R (ABS32), /* type */
398 2, /* size (0 = byte, 1 = short, 2 = long) */
400 FALSE, /* pc_relative */
402 complain_overflow_unsigned, /* complain_on_overflow */
403 bfd_elf_generic_reloc, /* special_function */
404 AARCH64_R_STR (ABS32), /* name */
405 FALSE, /* partial_inplace */
406 0xffffffff, /* src_mask */
407 0xffffffff, /* dst_mask */
408 FALSE), /* pcrel_offset */
411 HOWTO (AARCH64_R (ABS16), /* type */
413 1, /* size (0 = byte, 1 = short, 2 = long) */
415 FALSE, /* pc_relative */
417 complain_overflow_unsigned, /* complain_on_overflow */
418 bfd_elf_generic_reloc, /* special_function */
419 AARCH64_R_STR (ABS16), /* name */
420 FALSE, /* partial_inplace */
421 0xffff, /* src_mask */
422 0xffff, /* dst_mask */
423 FALSE), /* pcrel_offset */
425 /* .xword: (S+A-P) */
426 HOWTO64 (AARCH64_R (PREL64), /* type */
428 4, /* size (4 = long long) */
430 TRUE, /* pc_relative */
432 complain_overflow_signed, /* complain_on_overflow */
433 bfd_elf_generic_reloc, /* special_function */
434 AARCH64_R_STR (PREL64), /* name */
435 FALSE, /* partial_inplace */
436 ALL_ONES, /* src_mask */
437 ALL_ONES, /* dst_mask */
438 TRUE), /* pcrel_offset */
441 HOWTO (AARCH64_R (PREL32), /* type */
443 2, /* size (0 = byte, 1 = short, 2 = long) */
445 TRUE, /* pc_relative */
447 complain_overflow_signed, /* complain_on_overflow */
448 bfd_elf_generic_reloc, /* special_function */
449 AARCH64_R_STR (PREL32), /* name */
450 FALSE, /* partial_inplace */
451 0xffffffff, /* src_mask */
452 0xffffffff, /* dst_mask */
453 TRUE), /* pcrel_offset */
456 HOWTO (AARCH64_R (PREL16), /* type */
458 1, /* size (0 = byte, 1 = short, 2 = long) */
460 TRUE, /* pc_relative */
462 complain_overflow_signed, /* complain_on_overflow */
463 bfd_elf_generic_reloc, /* special_function */
464 AARCH64_R_STR (PREL16), /* name */
465 FALSE, /* partial_inplace */
466 0xffff, /* src_mask */
467 0xffff, /* dst_mask */
468 TRUE), /* pcrel_offset */
470 /* Group relocations to create a 16, 32, 48 or 64 bit
471 unsigned data or abs address inline. */
473 /* MOVZ: ((S+A) >> 0) & 0xffff */
474 HOWTO (AARCH64_R (MOVW_UABS_G0), /* type */
476 2, /* size (0 = byte, 1 = short, 2 = long) */
478 FALSE, /* pc_relative */
480 complain_overflow_unsigned, /* complain_on_overflow */
481 bfd_elf_generic_reloc, /* special_function */
482 AARCH64_R_STR (MOVW_UABS_G0), /* name */
483 FALSE, /* partial_inplace */
484 0xffff, /* src_mask */
485 0xffff, /* dst_mask */
486 FALSE), /* pcrel_offset */
488 /* MOVK: ((S+A) >> 0) & 0xffff [no overflow check] */
489 HOWTO (AARCH64_R (MOVW_UABS_G0_NC), /* type */
491 2, /* size (0 = byte, 1 = short, 2 = long) */
493 FALSE, /* pc_relative */
495 complain_overflow_dont, /* complain_on_overflow */
496 bfd_elf_generic_reloc, /* special_function */
497 AARCH64_R_STR (MOVW_UABS_G0_NC), /* name */
498 FALSE, /* partial_inplace */
499 0xffff, /* src_mask */
500 0xffff, /* dst_mask */
501 FALSE), /* pcrel_offset */
503 /* MOVZ: ((S+A) >> 16) & 0xffff */
504 HOWTO (AARCH64_R (MOVW_UABS_G1), /* type */
506 2, /* size (0 = byte, 1 = short, 2 = long) */
508 FALSE, /* pc_relative */
510 complain_overflow_unsigned, /* complain_on_overflow */
511 bfd_elf_generic_reloc, /* special_function */
512 AARCH64_R_STR (MOVW_UABS_G1), /* name */
513 FALSE, /* partial_inplace */
514 0xffff, /* src_mask */
515 0xffff, /* dst_mask */
516 FALSE), /* pcrel_offset */
518 /* MOVK: ((S+A) >> 16) & 0xffff [no overflow check] */
519 HOWTO64 (AARCH64_R (MOVW_UABS_G1_NC), /* type */
521 2, /* size (0 = byte, 1 = short, 2 = long) */
523 FALSE, /* pc_relative */
525 complain_overflow_dont, /* complain_on_overflow */
526 bfd_elf_generic_reloc, /* special_function */
527 AARCH64_R_STR (MOVW_UABS_G1_NC), /* name */
528 FALSE, /* partial_inplace */
529 0xffff, /* src_mask */
530 0xffff, /* dst_mask */
531 FALSE), /* pcrel_offset */
533 /* MOVZ: ((S+A) >> 32) & 0xffff */
534 HOWTO64 (AARCH64_R (MOVW_UABS_G2), /* type */
536 2, /* size (0 = byte, 1 = short, 2 = long) */
538 FALSE, /* pc_relative */
540 complain_overflow_unsigned, /* complain_on_overflow */
541 bfd_elf_generic_reloc, /* special_function */
542 AARCH64_R_STR (MOVW_UABS_G2), /* name */
543 FALSE, /* partial_inplace */
544 0xffff, /* src_mask */
545 0xffff, /* dst_mask */
546 FALSE), /* pcrel_offset */
548 /* MOVK: ((S+A) >> 32) & 0xffff [no overflow check] */
549 HOWTO64 (AARCH64_R (MOVW_UABS_G2_NC), /* type */
551 2, /* size (0 = byte, 1 = short, 2 = long) */
553 FALSE, /* pc_relative */
555 complain_overflow_dont, /* complain_on_overflow */
556 bfd_elf_generic_reloc, /* special_function */
557 AARCH64_R_STR (MOVW_UABS_G2_NC), /* name */
558 FALSE, /* partial_inplace */
559 0xffff, /* src_mask */
560 0xffff, /* dst_mask */
561 FALSE), /* pcrel_offset */
563 /* MOVZ: ((S+A) >> 48) & 0xffff */
564 HOWTO64 (AARCH64_R (MOVW_UABS_G3), /* type */
566 2, /* size (0 = byte, 1 = short, 2 = long) */
568 FALSE, /* pc_relative */
570 complain_overflow_unsigned, /* complain_on_overflow */
571 bfd_elf_generic_reloc, /* special_function */
572 AARCH64_R_STR (MOVW_UABS_G3), /* name */
573 FALSE, /* partial_inplace */
574 0xffff, /* src_mask */
575 0xffff, /* dst_mask */
576 FALSE), /* pcrel_offset */
578 /* Group relocations to create high part of a 16, 32, 48 or 64 bit
579 signed data or abs address inline. Will change instruction
580 to MOVN or MOVZ depending on sign of calculated value. */
582 /* MOV[ZN]: ((S+A) >> 0) & 0xffff */
583 HOWTO (AARCH64_R (MOVW_SABS_G0), /* type */
585 2, /* size (0 = byte, 1 = short, 2 = long) */
587 FALSE, /* pc_relative */
589 complain_overflow_signed, /* complain_on_overflow */
590 bfd_elf_generic_reloc, /* special_function */
591 AARCH64_R_STR (MOVW_SABS_G0), /* name */
592 FALSE, /* partial_inplace */
593 0xffff, /* src_mask */
594 0xffff, /* dst_mask */
595 FALSE), /* pcrel_offset */
597 /* MOV[ZN]: ((S+A) >> 16) & 0xffff */
598 HOWTO64 (AARCH64_R (MOVW_SABS_G1), /* type */
600 2, /* size (0 = byte, 1 = short, 2 = long) */
602 FALSE, /* pc_relative */
604 complain_overflow_signed, /* complain_on_overflow */
605 bfd_elf_generic_reloc, /* special_function */
606 AARCH64_R_STR (MOVW_SABS_G1), /* name */
607 FALSE, /* partial_inplace */
608 0xffff, /* src_mask */
609 0xffff, /* dst_mask */
610 FALSE), /* pcrel_offset */
612 /* MOV[ZN]: ((S+A) >> 32) & 0xffff */
613 HOWTO64 (AARCH64_R (MOVW_SABS_G2), /* type */
615 2, /* size (0 = byte, 1 = short, 2 = long) */
617 FALSE, /* pc_relative */
619 complain_overflow_signed, /* complain_on_overflow */
620 bfd_elf_generic_reloc, /* special_function */
621 AARCH64_R_STR (MOVW_SABS_G2), /* name */
622 FALSE, /* partial_inplace */
623 0xffff, /* src_mask */
624 0xffff, /* dst_mask */
625 FALSE), /* pcrel_offset */
627 /* Group relocations to create a 16, 32, 48 or 64 bit
628 PC relative address inline. */
630 /* MOV[NZ]: ((S+A-P) >> 0) & 0xffff */
631 HOWTO64 (AARCH64_R (MOVW_PREL_G0), /* type */
633 2, /* size (0 = byte, 1 = short, 2 = long) */
635 TRUE, /* pc_relative */
637 complain_overflow_signed, /* complain_on_overflow */
638 bfd_elf_generic_reloc, /* special_function */
639 AARCH64_R_STR (MOVW_PREL_G0), /* name */
640 FALSE, /* partial_inplace */
641 0xffff, /* src_mask */
642 0xffff, /* dst_mask */
643 TRUE), /* pcrel_offset */
645 /* MOVK: ((S+A-P) >> 0) & 0xffff [no overflow check] */
646 HOWTO64 (AARCH64_R (MOVW_PREL_G0_NC), /* type */
648 2, /* size (0 = byte, 1 = short, 2 = long) */
650 TRUE, /* pc_relative */
652 complain_overflow_dont, /* complain_on_overflow */
653 bfd_elf_generic_reloc, /* special_function */
654 AARCH64_R_STR (MOVW_PREL_G0_NC), /* name */
655 FALSE, /* partial_inplace */
656 0xffff, /* src_mask */
657 0xffff, /* dst_mask */
658 TRUE), /* pcrel_offset */
660 /* MOV[NZ]: ((S+A-P) >> 16) & 0xffff */
661 HOWTO64 (AARCH64_R (MOVW_PREL_G1), /* type */
663 2, /* size (0 = byte, 1 = short, 2 = long) */
665 TRUE, /* pc_relative */
667 complain_overflow_signed, /* complain_on_overflow */
668 bfd_elf_generic_reloc, /* special_function */
669 AARCH64_R_STR (MOVW_PREL_G1), /* name */
670 FALSE, /* partial_inplace */
671 0xffff, /* src_mask */
672 0xffff, /* dst_mask */
673 TRUE), /* pcrel_offset */
675 /* MOVK: ((S+A-P) >> 16) & 0xffff [no overflow check] */
676 HOWTO64 (AARCH64_R (MOVW_PREL_G1_NC), /* type */
678 2, /* size (0 = byte, 1 = short, 2 = long) */
680 TRUE, /* pc_relative */
682 complain_overflow_dont, /* complain_on_overflow */
683 bfd_elf_generic_reloc, /* special_function */
684 AARCH64_R_STR (MOVW_PREL_G1_NC), /* name */
685 FALSE, /* partial_inplace */
686 0xffff, /* src_mask */
687 0xffff, /* dst_mask */
688 TRUE), /* pcrel_offset */
690 /* MOV[NZ]: ((S+A-P) >> 32) & 0xffff */
691 HOWTO64 (AARCH64_R (MOVW_PREL_G2), /* type */
693 2, /* size (0 = byte, 1 = short, 2 = long) */
695 TRUE, /* pc_relative */
697 complain_overflow_signed, /* complain_on_overflow */
698 bfd_elf_generic_reloc, /* special_function */
699 AARCH64_R_STR (MOVW_PREL_G2), /* name */
700 FALSE, /* partial_inplace */
701 0xffff, /* src_mask */
702 0xffff, /* dst_mask */
703 TRUE), /* pcrel_offset */
705 /* MOVK: ((S+A-P) >> 32) & 0xffff [no overflow check] */
706 HOWTO64 (AARCH64_R (MOVW_PREL_G2_NC), /* type */
708 2, /* size (0 = byte, 1 = short, 2 = long) */
710 TRUE, /* pc_relative */
712 complain_overflow_dont, /* complain_on_overflow */
713 bfd_elf_generic_reloc, /* special_function */
714 AARCH64_R_STR (MOVW_PREL_G2_NC), /* name */
715 FALSE, /* partial_inplace */
716 0xffff, /* src_mask */
717 0xffff, /* dst_mask */
718 TRUE), /* pcrel_offset */
720 /* MOV[NZ]: ((S+A-P) >> 48) & 0xffff */
721 HOWTO64 (AARCH64_R (MOVW_PREL_G3), /* type */
723 2, /* size (0 = byte, 1 = short, 2 = long) */
725 TRUE, /* pc_relative */
727 complain_overflow_dont, /* complain_on_overflow */
728 bfd_elf_generic_reloc, /* special_function */
729 AARCH64_R_STR (MOVW_PREL_G3), /* name */
730 FALSE, /* partial_inplace */
731 0xffff, /* src_mask */
732 0xffff, /* dst_mask */
733 TRUE), /* pcrel_offset */
735 /* Relocations to generate 19, 21 and 33 bit PC-relative load/store
736 addresses: PG(x) is (x & ~0xfff). */
738 /* LD-lit: ((S+A-P) >> 2) & 0x7ffff */
739 HOWTO (AARCH64_R (LD_PREL_LO19), /* type */
741 2, /* size (0 = byte, 1 = short, 2 = long) */
743 TRUE, /* pc_relative */
745 complain_overflow_signed, /* complain_on_overflow */
746 bfd_elf_generic_reloc, /* special_function */
747 AARCH64_R_STR (LD_PREL_LO19), /* name */
748 FALSE, /* partial_inplace */
749 0x7ffff, /* src_mask */
750 0x7ffff, /* dst_mask */
751 TRUE), /* pcrel_offset */
753 /* ADR: (S+A-P) & 0x1fffff */
754 HOWTO (AARCH64_R (ADR_PREL_LO21), /* type */
756 2, /* size (0 = byte, 1 = short, 2 = long) */
758 TRUE, /* pc_relative */
760 complain_overflow_signed, /* complain_on_overflow */
761 bfd_elf_generic_reloc, /* special_function */
762 AARCH64_R_STR (ADR_PREL_LO21), /* name */
763 FALSE, /* partial_inplace */
764 0x1fffff, /* src_mask */
765 0x1fffff, /* dst_mask */
766 TRUE), /* pcrel_offset */
768 /* ADRP: ((PG(S+A)-PG(P)) >> 12) & 0x1fffff */
769 HOWTO (AARCH64_R (ADR_PREL_PG_HI21), /* type */
771 2, /* size (0 = byte, 1 = short, 2 = long) */
773 TRUE, /* pc_relative */
775 complain_overflow_signed, /* complain_on_overflow */
776 bfd_elf_generic_reloc, /* special_function */
777 AARCH64_R_STR (ADR_PREL_PG_HI21), /* name */
778 FALSE, /* partial_inplace */
779 0x1fffff, /* src_mask */
780 0x1fffff, /* dst_mask */
781 TRUE), /* pcrel_offset */
783 /* ADRP: ((PG(S+A)-PG(P)) >> 12) & 0x1fffff [no overflow check] */
784 HOWTO64 (AARCH64_R (ADR_PREL_PG_HI21_NC), /* type */
786 2, /* size (0 = byte, 1 = short, 2 = long) */
788 TRUE, /* pc_relative */
790 complain_overflow_dont, /* complain_on_overflow */
791 bfd_elf_generic_reloc, /* special_function */
792 AARCH64_R_STR (ADR_PREL_PG_HI21_NC), /* name */
793 FALSE, /* partial_inplace */
794 0x1fffff, /* src_mask */
795 0x1fffff, /* dst_mask */
796 TRUE), /* pcrel_offset */
798 /* ADD: (S+A) & 0xfff [no overflow check] */
799 HOWTO (AARCH64_R (ADD_ABS_LO12_NC), /* type */
801 2, /* size (0 = byte, 1 = short, 2 = long) */
803 FALSE, /* pc_relative */
805 complain_overflow_dont, /* complain_on_overflow */
806 bfd_elf_generic_reloc, /* special_function */
807 AARCH64_R_STR (ADD_ABS_LO12_NC), /* name */
808 FALSE, /* partial_inplace */
809 0x3ffc00, /* src_mask */
810 0x3ffc00, /* dst_mask */
811 FALSE), /* pcrel_offset */
813 /* LD/ST8: (S+A) & 0xfff */
814 HOWTO (AARCH64_R (LDST8_ABS_LO12_NC), /* type */
816 2, /* size (0 = byte, 1 = short, 2 = long) */
818 FALSE, /* pc_relative */
820 complain_overflow_dont, /* complain_on_overflow */
821 bfd_elf_generic_reloc, /* special_function */
822 AARCH64_R_STR (LDST8_ABS_LO12_NC), /* name */
823 FALSE, /* partial_inplace */
824 0xfff, /* src_mask */
825 0xfff, /* dst_mask */
826 FALSE), /* pcrel_offset */
828 /* Relocations for control-flow instructions. */
830 /* TBZ/NZ: ((S+A-P) >> 2) & 0x3fff */
831 HOWTO (AARCH64_R (TSTBR14), /* type */
833 2, /* size (0 = byte, 1 = short, 2 = long) */
835 TRUE, /* pc_relative */
837 complain_overflow_signed, /* complain_on_overflow */
838 bfd_elf_generic_reloc, /* special_function */
839 AARCH64_R_STR (TSTBR14), /* name */
840 FALSE, /* partial_inplace */
841 0x3fff, /* src_mask */
842 0x3fff, /* dst_mask */
843 TRUE), /* pcrel_offset */
845 /* B.cond: ((S+A-P) >> 2) & 0x7ffff */
846 HOWTO (AARCH64_R (CONDBR19), /* type */
848 2, /* size (0 = byte, 1 = short, 2 = long) */
850 TRUE, /* pc_relative */
852 complain_overflow_signed, /* complain_on_overflow */
853 bfd_elf_generic_reloc, /* special_function */
854 AARCH64_R_STR (CONDBR19), /* name */
855 FALSE, /* partial_inplace */
856 0x7ffff, /* src_mask */
857 0x7ffff, /* dst_mask */
858 TRUE), /* pcrel_offset */
860 /* B: ((S+A-P) >> 2) & 0x3ffffff */
861 HOWTO (AARCH64_R (JUMP26), /* type */
863 2, /* size (0 = byte, 1 = short, 2 = long) */
865 TRUE, /* pc_relative */
867 complain_overflow_signed, /* complain_on_overflow */
868 bfd_elf_generic_reloc, /* special_function */
869 AARCH64_R_STR (JUMP26), /* name */
870 FALSE, /* partial_inplace */
871 0x3ffffff, /* src_mask */
872 0x3ffffff, /* dst_mask */
873 TRUE), /* pcrel_offset */
875 /* BL: ((S+A-P) >> 2) & 0x3ffffff */
876 HOWTO (AARCH64_R (CALL26), /* type */
878 2, /* size (0 = byte, 1 = short, 2 = long) */
880 TRUE, /* pc_relative */
882 complain_overflow_signed, /* complain_on_overflow */
883 bfd_elf_generic_reloc, /* special_function */
884 AARCH64_R_STR (CALL26), /* name */
885 FALSE, /* partial_inplace */
886 0x3ffffff, /* src_mask */
887 0x3ffffff, /* dst_mask */
888 TRUE), /* pcrel_offset */
890 /* LD/ST16: (S+A) & 0xffe */
891 HOWTO (AARCH64_R (LDST16_ABS_LO12_NC), /* type */
893 2, /* size (0 = byte, 1 = short, 2 = long) */
895 FALSE, /* pc_relative */
897 complain_overflow_dont, /* complain_on_overflow */
898 bfd_elf_generic_reloc, /* special_function */
899 AARCH64_R_STR (LDST16_ABS_LO12_NC), /* name */
900 FALSE, /* partial_inplace */
901 0xffe, /* src_mask */
902 0xffe, /* dst_mask */
903 FALSE), /* pcrel_offset */
905 /* LD/ST32: (S+A) & 0xffc */
906 HOWTO (AARCH64_R (LDST32_ABS_LO12_NC), /* type */
908 2, /* size (0 = byte, 1 = short, 2 = long) */
910 FALSE, /* pc_relative */
912 complain_overflow_dont, /* complain_on_overflow */
913 bfd_elf_generic_reloc, /* special_function */
914 AARCH64_R_STR (LDST32_ABS_LO12_NC), /* name */
915 FALSE, /* partial_inplace */
916 0xffc, /* src_mask */
917 0xffc, /* dst_mask */
918 FALSE), /* pcrel_offset */
920 /* LD/ST64: (S+A) & 0xff8 */
921 HOWTO (AARCH64_R (LDST64_ABS_LO12_NC), /* type */
923 2, /* size (0 = byte, 1 = short, 2 = long) */
925 FALSE, /* pc_relative */
927 complain_overflow_dont, /* complain_on_overflow */
928 bfd_elf_generic_reloc, /* special_function */
929 AARCH64_R_STR (LDST64_ABS_LO12_NC), /* name */
930 FALSE, /* partial_inplace */
931 0xff8, /* src_mask */
932 0xff8, /* dst_mask */
933 FALSE), /* pcrel_offset */
935 /* LD/ST128: (S+A) & 0xff0 */
936 HOWTO (AARCH64_R (LDST128_ABS_LO12_NC), /* type */
938 2, /* size (0 = byte, 1 = short, 2 = long) */
940 FALSE, /* pc_relative */
942 complain_overflow_dont, /* complain_on_overflow */
943 bfd_elf_generic_reloc, /* special_function */
944 AARCH64_R_STR (LDST128_ABS_LO12_NC), /* name */
945 FALSE, /* partial_inplace */
946 0xff0, /* src_mask */
947 0xff0, /* dst_mask */
948 FALSE), /* pcrel_offset */
950 /* Set a load-literal immediate field to bits
951 0x1FFFFC of G(S)-P */
952 HOWTO (AARCH64_R (GOT_LD_PREL19), /* type */
954 2, /* size (0 = byte,1 = short,2 = long) */
956 TRUE, /* pc_relative */
958 complain_overflow_signed, /* complain_on_overflow */
959 bfd_elf_generic_reloc, /* special_function */
960 AARCH64_R_STR (GOT_LD_PREL19), /* name */
961 FALSE, /* partial_inplace */
962 0xffffe0, /* src_mask */
963 0xffffe0, /* dst_mask */
964 TRUE), /* pcrel_offset */
966 /* Get to the page for the GOT entry for the symbol
967 (G(S) - P) using an ADRP instruction. */
968 HOWTO (AARCH64_R (ADR_GOT_PAGE), /* type */
970 2, /* size (0 = byte, 1 = short, 2 = long) */
972 TRUE, /* pc_relative */
974 complain_overflow_dont, /* complain_on_overflow */
975 bfd_elf_generic_reloc, /* special_function */
976 AARCH64_R_STR (ADR_GOT_PAGE), /* name */
977 FALSE, /* partial_inplace */
978 0x1fffff, /* src_mask */
979 0x1fffff, /* dst_mask */
980 TRUE), /* pcrel_offset */
982 /* LD64: GOT offset G(S) & 0xff8 */
983 HOWTO64 (AARCH64_R (LD64_GOT_LO12_NC), /* type */
985 2, /* size (0 = byte, 1 = short, 2 = long) */
987 FALSE, /* pc_relative */
989 complain_overflow_dont, /* complain_on_overflow */
990 bfd_elf_generic_reloc, /* special_function */
991 AARCH64_R_STR (LD64_GOT_LO12_NC), /* name */
992 FALSE, /* partial_inplace */
993 0xff8, /* src_mask */
994 0xff8, /* dst_mask */
995 FALSE), /* pcrel_offset */
997 /* LD32: GOT offset G(S) & 0xffc */
998 HOWTO32 (AARCH64_R (LD32_GOT_LO12_NC), /* type */
1000 2, /* size (0 = byte, 1 = short, 2 = long) */
1002 FALSE, /* pc_relative */
1004 complain_overflow_dont, /* complain_on_overflow */
1005 bfd_elf_generic_reloc, /* special_function */
1006 AARCH64_R_STR (LD32_GOT_LO12_NC), /* name */
1007 FALSE, /* partial_inplace */
1008 0xffc, /* src_mask */
1009 0xffc, /* dst_mask */
1010 FALSE), /* pcrel_offset */
1012 /* Lower 16 bits of GOT offset for the symbol. */
1013 HOWTO64 (AARCH64_R (MOVW_GOTOFF_G0_NC), /* type */
1015 2, /* size (0 = byte, 1 = short, 2 = long) */
1017 FALSE, /* pc_relative */
1019 complain_overflow_dont, /* complain_on_overflow */
1020 bfd_elf_generic_reloc, /* special_function */
1021 AARCH64_R_STR (MOVW_GOTOFF_G0_NC), /* name */
1022 FALSE, /* partial_inplace */
1023 0xffff, /* src_mask */
1024 0xffff, /* dst_mask */
1025 FALSE), /* pcrel_offset */
1027 /* Higher 16 bits of GOT offset for the symbol. */
1028 HOWTO64 (AARCH64_R (MOVW_GOTOFF_G1), /* type */
1029 16, /* rightshift */
1030 2, /* size (0 = byte, 1 = short, 2 = long) */
1032 FALSE, /* pc_relative */
1034 complain_overflow_unsigned, /* complain_on_overflow */
1035 bfd_elf_generic_reloc, /* special_function */
1036 AARCH64_R_STR (MOVW_GOTOFF_G1), /* name */
1037 FALSE, /* partial_inplace */
1038 0xffff, /* src_mask */
1039 0xffff, /* dst_mask */
1040 FALSE), /* pcrel_offset */
1042 /* LD64: GOT offset for the symbol. */
1043 HOWTO64 (AARCH64_R (LD64_GOTOFF_LO15), /* type */
1045 2, /* size (0 = byte, 1 = short, 2 = long) */
1047 FALSE, /* pc_relative */
1049 complain_overflow_unsigned, /* complain_on_overflow */
1050 bfd_elf_generic_reloc, /* special_function */
1051 AARCH64_R_STR (LD64_GOTOFF_LO15), /* name */
1052 FALSE, /* partial_inplace */
1053 0x7ff8, /* src_mask */
1054 0x7ff8, /* dst_mask */
1055 FALSE), /* pcrel_offset */
1057 /* LD32: GOT offset to the page address of GOT table.
1058 (G(S) - PAGE (_GLOBAL_OFFSET_TABLE_)) & 0x5ffc. */
1059 HOWTO32 (AARCH64_R (LD32_GOTPAGE_LO14), /* type */
1061 2, /* size (0 = byte, 1 = short, 2 = long) */
1063 FALSE, /* pc_relative */
1065 complain_overflow_unsigned, /* complain_on_overflow */
1066 bfd_elf_generic_reloc, /* special_function */
1067 AARCH64_R_STR (LD32_GOTPAGE_LO14), /* name */
1068 FALSE, /* partial_inplace */
1069 0x5ffc, /* src_mask */
1070 0x5ffc, /* dst_mask */
1071 FALSE), /* pcrel_offset */
1073 /* LD64: GOT offset to the page address of GOT table.
1074 (G(S) - PAGE (_GLOBAL_OFFSET_TABLE_)) & 0x7ff8. */
1075 HOWTO64 (AARCH64_R (LD64_GOTPAGE_LO15), /* type */
1077 2, /* size (0 = byte, 1 = short, 2 = long) */
1079 FALSE, /* pc_relative */
1081 complain_overflow_unsigned, /* complain_on_overflow */
1082 bfd_elf_generic_reloc, /* special_function */
1083 AARCH64_R_STR (LD64_GOTPAGE_LO15), /* name */
1084 FALSE, /* partial_inplace */
1085 0x7ff8, /* src_mask */
1086 0x7ff8, /* dst_mask */
1087 FALSE), /* pcrel_offset */
1089 /* Get to the page for the GOT entry for the symbol
1090 (G(S) - P) using an ADRP instruction. */
1091 HOWTO (AARCH64_R (TLSGD_ADR_PAGE21), /* type */
1092 12, /* rightshift */
1093 2, /* size (0 = byte, 1 = short, 2 = long) */
1095 TRUE, /* pc_relative */
1097 complain_overflow_dont, /* complain_on_overflow */
1098 bfd_elf_generic_reloc, /* special_function */
1099 AARCH64_R_STR (TLSGD_ADR_PAGE21), /* name */
1100 FALSE, /* partial_inplace */
1101 0x1fffff, /* src_mask */
1102 0x1fffff, /* dst_mask */
1103 TRUE), /* pcrel_offset */
1105 HOWTO (AARCH64_R (TLSGD_ADR_PREL21), /* type */
1107 2, /* size (0 = byte, 1 = short, 2 = long) */
1109 TRUE, /* pc_relative */
1111 complain_overflow_dont, /* complain_on_overflow */
1112 bfd_elf_generic_reloc, /* special_function */
1113 AARCH64_R_STR (TLSGD_ADR_PREL21), /* name */
1114 FALSE, /* partial_inplace */
1115 0x1fffff, /* src_mask */
1116 0x1fffff, /* dst_mask */
1117 TRUE), /* pcrel_offset */
1119 /* ADD: GOT offset G(S) & 0xff8 [no overflow check] */
1120 HOWTO (AARCH64_R (TLSGD_ADD_LO12_NC), /* type */
1122 2, /* size (0 = byte, 1 = short, 2 = long) */
1124 FALSE, /* pc_relative */
1126 complain_overflow_dont, /* complain_on_overflow */
1127 bfd_elf_generic_reloc, /* special_function */
1128 AARCH64_R_STR (TLSGD_ADD_LO12_NC), /* name */
1129 FALSE, /* partial_inplace */
1130 0xfff, /* src_mask */
1131 0xfff, /* dst_mask */
1132 FALSE), /* pcrel_offset */
1134 /* Lower 16 bits of GOT offset to tls_index. */
1135 HOWTO64 (AARCH64_R (TLSGD_MOVW_G0_NC), /* type */
1137 2, /* size (0 = byte, 1 = short, 2 = long) */
1139 FALSE, /* pc_relative */
1141 complain_overflow_dont, /* complain_on_overflow */
1142 bfd_elf_generic_reloc, /* special_function */
1143 AARCH64_R_STR (TLSGD_MOVW_G0_NC), /* name */
1144 FALSE, /* partial_inplace */
1145 0xffff, /* src_mask */
1146 0xffff, /* dst_mask */
1147 FALSE), /* pcrel_offset */
1149 /* Higher 16 bits of GOT offset to tls_index. */
1150 HOWTO64 (AARCH64_R (TLSGD_MOVW_G1), /* type */
1151 16, /* rightshift */
1152 2, /* size (0 = byte, 1 = short, 2 = long) */
1154 FALSE, /* pc_relative */
1156 complain_overflow_unsigned, /* complain_on_overflow */
1157 bfd_elf_generic_reloc, /* special_function */
1158 AARCH64_R_STR (TLSGD_MOVW_G1), /* name */
1159 FALSE, /* partial_inplace */
1160 0xffff, /* src_mask */
1161 0xffff, /* dst_mask */
1162 FALSE), /* pcrel_offset */
1164 HOWTO (AARCH64_R (TLSIE_ADR_GOTTPREL_PAGE21), /* type */
1165 12, /* rightshift */
1166 2, /* size (0 = byte, 1 = short, 2 = long) */
1168 FALSE, /* pc_relative */
1170 complain_overflow_dont, /* complain_on_overflow */
1171 bfd_elf_generic_reloc, /* special_function */
1172 AARCH64_R_STR (TLSIE_ADR_GOTTPREL_PAGE21), /* name */
1173 FALSE, /* partial_inplace */
1174 0x1fffff, /* src_mask */
1175 0x1fffff, /* dst_mask */
1176 FALSE), /* pcrel_offset */
1178 HOWTO64 (AARCH64_R (TLSIE_LD64_GOTTPREL_LO12_NC), /* type */
1180 2, /* size (0 = byte, 1 = short, 2 = long) */
1182 FALSE, /* pc_relative */
1184 complain_overflow_dont, /* complain_on_overflow */
1185 bfd_elf_generic_reloc, /* special_function */
1186 AARCH64_R_STR (TLSIE_LD64_GOTTPREL_LO12_NC), /* name */
1187 FALSE, /* partial_inplace */
1188 0xff8, /* src_mask */
1189 0xff8, /* dst_mask */
1190 FALSE), /* pcrel_offset */
1192 HOWTO32 (AARCH64_R (TLSIE_LD32_GOTTPREL_LO12_NC), /* type */
1194 2, /* size (0 = byte, 1 = short, 2 = long) */
1196 FALSE, /* pc_relative */
1198 complain_overflow_dont, /* complain_on_overflow */
1199 bfd_elf_generic_reloc, /* special_function */
1200 AARCH64_R_STR (TLSIE_LD32_GOTTPREL_LO12_NC), /* name */
1201 FALSE, /* partial_inplace */
1202 0xffc, /* src_mask */
1203 0xffc, /* dst_mask */
1204 FALSE), /* pcrel_offset */
1206 HOWTO (AARCH64_R (TLSIE_LD_GOTTPREL_PREL19), /* type */
1208 2, /* size (0 = byte, 1 = short, 2 = long) */
1210 FALSE, /* pc_relative */
1212 complain_overflow_dont, /* complain_on_overflow */
1213 bfd_elf_generic_reloc, /* special_function */
1214 AARCH64_R_STR (TLSIE_LD_GOTTPREL_PREL19), /* name */
1215 FALSE, /* partial_inplace */
1216 0x1ffffc, /* src_mask */
1217 0x1ffffc, /* dst_mask */
1218 FALSE), /* pcrel_offset */
1220 HOWTO64 (AARCH64_R (TLSIE_MOVW_GOTTPREL_G0_NC), /* type */
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_MOVW_GOTTPREL_G0_NC), /* name */
1229 FALSE, /* partial_inplace */
1230 0xffff, /* src_mask */
1231 0xffff, /* dst_mask */
1232 FALSE), /* pcrel_offset */
1234 HOWTO64 (AARCH64_R (TLSIE_MOVW_GOTTPREL_G1), /* type */
1235 16, /* rightshift */
1236 2, /* size (0 = byte, 1 = short, 2 = long) */
1238 FALSE, /* pc_relative */
1240 complain_overflow_unsigned, /* complain_on_overflow */
1241 bfd_elf_generic_reloc, /* special_function */
1242 AARCH64_R_STR (TLSIE_MOVW_GOTTPREL_G1), /* name */
1243 FALSE, /* partial_inplace */
1244 0xffff, /* src_mask */
1245 0xffff, /* dst_mask */
1246 FALSE), /* pcrel_offset */
1248 /* ADD: bit[23:12] of byte offset to module TLS base address. */
1249 HOWTO (AARCH64_R (TLSLD_ADD_DTPREL_HI12), /* type */
1250 12, /* rightshift */
1251 2, /* size (0 = byte, 1 = short, 2 = long) */
1253 FALSE, /* pc_relative */
1255 complain_overflow_unsigned, /* complain_on_overflow */
1256 bfd_elf_generic_reloc, /* special_function */
1257 AARCH64_R_STR (TLSLD_ADD_DTPREL_HI12), /* name */
1258 FALSE, /* partial_inplace */
1259 0xfff, /* src_mask */
1260 0xfff, /* dst_mask */
1261 FALSE), /* pcrel_offset */
1263 /* Unsigned 12 bit byte offset to module TLS base address. */
1264 HOWTO (AARCH64_R (TLSLD_ADD_DTPREL_LO12), /* type */
1266 2, /* size (0 = byte, 1 = short, 2 = long) */
1268 FALSE, /* pc_relative */
1270 complain_overflow_unsigned, /* complain_on_overflow */
1271 bfd_elf_generic_reloc, /* special_function */
1272 AARCH64_R_STR (TLSLD_ADD_DTPREL_LO12), /* name */
1273 FALSE, /* partial_inplace */
1274 0xfff, /* src_mask */
1275 0xfff, /* dst_mask */
1276 FALSE), /* pcrel_offset */
1278 /* No overflow check version of BFD_RELOC_AARCH64_TLSLD_ADD_DTPREL_LO12. */
1279 HOWTO (AARCH64_R (TLSLD_ADD_DTPREL_LO12_NC), /* type */
1281 2, /* size (0 = byte, 1 = short, 2 = long) */
1283 FALSE, /* pc_relative */
1285 complain_overflow_dont, /* complain_on_overflow */
1286 bfd_elf_generic_reloc, /* special_function */
1287 AARCH64_R_STR (TLSLD_ADD_DTPREL_LO12_NC), /* name */
1288 FALSE, /* partial_inplace */
1289 0xfff, /* src_mask */
1290 0xfff, /* dst_mask */
1291 FALSE), /* pcrel_offset */
1293 /* ADD: GOT offset G(S) & 0xff8 [no overflow check] */
1294 HOWTO (AARCH64_R (TLSLD_ADD_LO12_NC), /* type */
1296 2, /* size (0 = byte, 1 = short, 2 = long) */
1298 FALSE, /* pc_relative */
1300 complain_overflow_dont, /* complain_on_overflow */
1301 bfd_elf_generic_reloc, /* special_function */
1302 AARCH64_R_STR (TLSLD_ADD_LO12_NC), /* name */
1303 FALSE, /* partial_inplace */
1304 0xfff, /* src_mask */
1305 0xfff, /* dst_mask */
1306 FALSE), /* pcrel_offset */
1308 /* Get to the page for the GOT entry for the symbol
1309 (G(S) - P) using an ADRP instruction. */
1310 HOWTO (AARCH64_R (TLSLD_ADR_PAGE21), /* type */
1311 12, /* rightshift */
1312 2, /* size (0 = byte, 1 = short, 2 = long) */
1314 TRUE, /* pc_relative */
1316 complain_overflow_signed, /* complain_on_overflow */
1317 bfd_elf_generic_reloc, /* special_function */
1318 AARCH64_R_STR (TLSLD_ADR_PAGE21), /* name */
1319 FALSE, /* partial_inplace */
1320 0x1fffff, /* src_mask */
1321 0x1fffff, /* dst_mask */
1322 TRUE), /* pcrel_offset */
1324 HOWTO (AARCH64_R (TLSLD_ADR_PREL21), /* type */
1326 2, /* size (0 = byte, 1 = short, 2 = long) */
1328 TRUE, /* pc_relative */
1330 complain_overflow_signed, /* complain_on_overflow */
1331 bfd_elf_generic_reloc, /* special_function */
1332 AARCH64_R_STR (TLSLD_ADR_PREL21), /* name */
1333 FALSE, /* partial_inplace */
1334 0x1fffff, /* src_mask */
1335 0x1fffff, /* dst_mask */
1336 TRUE), /* pcrel_offset */
1338 /* LD/ST16: bit[11:1] of byte offset to module TLS base address. */
1339 HOWTO64 (AARCH64_R (TLSLD_LDST16_DTPREL_LO12), /* type */
1341 2, /* size (0 = byte, 1 = short, 2 = long) */
1343 FALSE, /* pc_relative */
1345 complain_overflow_unsigned, /* complain_on_overflow */
1346 bfd_elf_generic_reloc, /* special_function */
1347 AARCH64_R_STR (TLSLD_LDST16_DTPREL_LO12), /* name */
1348 FALSE, /* partial_inplace */
1349 0x1ffc00, /* src_mask */
1350 0x1ffc00, /* dst_mask */
1351 FALSE), /* pcrel_offset */
1353 /* Same as BFD_RELOC_AARCH64_TLSLD_LDST16_DTPREL_LO12, but no overflow check. */
1354 HOWTO64 (AARCH64_R (TLSLD_LDST16_DTPREL_LO12_NC), /* type */
1356 2, /* size (0 = byte, 1 = short, 2 = long) */
1358 FALSE, /* pc_relative */
1360 complain_overflow_dont, /* complain_on_overflow */
1361 bfd_elf_generic_reloc, /* special_function */
1362 AARCH64_R_STR (TLSLD_LDST16_DTPREL_LO12_NC), /* name */
1363 FALSE, /* partial_inplace */
1364 0x1ffc00, /* src_mask */
1365 0x1ffc00, /* dst_mask */
1366 FALSE), /* pcrel_offset */
1368 /* LD/ST32: bit[11:2] of byte offset to module TLS base address. */
1369 HOWTO64 (AARCH64_R (TLSLD_LDST32_DTPREL_LO12), /* type */
1371 2, /* size (0 = byte, 1 = short, 2 = long) */
1373 FALSE, /* pc_relative */
1375 complain_overflow_unsigned, /* complain_on_overflow */
1376 bfd_elf_generic_reloc, /* special_function */
1377 AARCH64_R_STR (TLSLD_LDST32_DTPREL_LO12), /* name */
1378 FALSE, /* partial_inplace */
1379 0x3ffc00, /* src_mask */
1380 0x3ffc00, /* dst_mask */
1381 FALSE), /* pcrel_offset */
1383 /* Same as BFD_RELOC_AARCH64_TLSLD_LDST32_DTPREL_LO12, but no overflow check. */
1384 HOWTO64 (AARCH64_R (TLSLD_LDST32_DTPREL_LO12_NC), /* type */
1386 2, /* size (0 = byte, 1 = short, 2 = long) */
1388 FALSE, /* pc_relative */
1390 complain_overflow_dont, /* complain_on_overflow */
1391 bfd_elf_generic_reloc, /* special_function */
1392 AARCH64_R_STR (TLSLD_LDST32_DTPREL_LO12_NC), /* name */
1393 FALSE, /* partial_inplace */
1394 0xffc00, /* src_mask */
1395 0xffc00, /* dst_mask */
1396 FALSE), /* pcrel_offset */
1398 /* LD/ST64: bit[11:3] of byte offset to module TLS base address. */
1399 HOWTO64 (AARCH64_R (TLSLD_LDST64_DTPREL_LO12), /* type */
1401 2, /* size (0 = byte, 1 = short, 2 = long) */
1403 FALSE, /* pc_relative */
1405 complain_overflow_unsigned, /* complain_on_overflow */
1406 bfd_elf_generic_reloc, /* special_function */
1407 AARCH64_R_STR (TLSLD_LDST64_DTPREL_LO12), /* name */
1408 FALSE, /* partial_inplace */
1409 0x3ffc00, /* src_mask */
1410 0x3ffc00, /* dst_mask */
1411 FALSE), /* pcrel_offset */
1413 /* Same as BFD_RELOC_AARCH64_TLSLD_LDST64_DTPREL_LO12, but no overflow check. */
1414 HOWTO64 (AARCH64_R (TLSLD_LDST64_DTPREL_LO12_NC), /* type */
1416 2, /* size (0 = byte, 1 = short, 2 = long) */
1418 FALSE, /* pc_relative */
1420 complain_overflow_dont, /* complain_on_overflow */
1421 bfd_elf_generic_reloc, /* special_function */
1422 AARCH64_R_STR (TLSLD_LDST64_DTPREL_LO12_NC), /* name */
1423 FALSE, /* partial_inplace */
1424 0x7fc00, /* src_mask */
1425 0x7fc00, /* dst_mask */
1426 FALSE), /* pcrel_offset */
1428 /* LD/ST8: bit[11:0] of byte offset to module TLS base address. */
1429 HOWTO64 (AARCH64_R (TLSLD_LDST8_DTPREL_LO12), /* type */
1431 2, /* size (0 = byte, 1 = short, 2 = long) */
1433 FALSE, /* pc_relative */
1435 complain_overflow_unsigned, /* complain_on_overflow */
1436 bfd_elf_generic_reloc, /* special_function */
1437 AARCH64_R_STR (TLSLD_LDST8_DTPREL_LO12), /* name */
1438 FALSE, /* partial_inplace */
1439 0x3ffc00, /* src_mask */
1440 0x3ffc00, /* dst_mask */
1441 FALSE), /* pcrel_offset */
1443 /* Same as BFD_RELOC_AARCH64_TLSLD_LDST8_DTPREL_LO12, but no overflow check. */
1444 HOWTO64 (AARCH64_R (TLSLD_LDST8_DTPREL_LO12_NC), /* type */
1446 2, /* size (0 = byte, 1 = short, 2 = long) */
1448 FALSE, /* pc_relative */
1450 complain_overflow_dont, /* complain_on_overflow */
1451 bfd_elf_generic_reloc, /* special_function */
1452 AARCH64_R_STR (TLSLD_LDST8_DTPREL_LO12_NC), /* name */
1453 FALSE, /* partial_inplace */
1454 0x3ffc00, /* src_mask */
1455 0x3ffc00, /* dst_mask */
1456 FALSE), /* pcrel_offset */
1458 /* MOVZ: bit[15:0] of byte offset to module TLS base address. */
1459 HOWTO (AARCH64_R (TLSLD_MOVW_DTPREL_G0), /* type */
1461 2, /* size (0 = byte, 1 = short, 2 = long) */
1463 FALSE, /* pc_relative */
1465 complain_overflow_unsigned, /* complain_on_overflow */
1466 bfd_elf_generic_reloc, /* special_function */
1467 AARCH64_R_STR (TLSLD_MOVW_DTPREL_G0), /* name */
1468 FALSE, /* partial_inplace */
1469 0xffff, /* src_mask */
1470 0xffff, /* dst_mask */
1471 FALSE), /* pcrel_offset */
1473 /* No overflow check version of BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G0. */
1474 HOWTO (AARCH64_R (TLSLD_MOVW_DTPREL_G0_NC), /* type */
1476 2, /* size (0 = byte, 1 = short, 2 = long) */
1478 FALSE, /* pc_relative */
1480 complain_overflow_dont, /* complain_on_overflow */
1481 bfd_elf_generic_reloc, /* special_function */
1482 AARCH64_R_STR (TLSLD_MOVW_DTPREL_G0_NC), /* name */
1483 FALSE, /* partial_inplace */
1484 0xffff, /* src_mask */
1485 0xffff, /* dst_mask */
1486 FALSE), /* pcrel_offset */
1488 /* MOVZ: bit[31:16] of byte offset to module TLS base address. */
1489 HOWTO (AARCH64_R (TLSLD_MOVW_DTPREL_G1), /* type */
1490 16, /* rightshift */
1491 2, /* size (0 = byte, 1 = short, 2 = long) */
1493 FALSE, /* pc_relative */
1495 complain_overflow_unsigned, /* complain_on_overflow */
1496 bfd_elf_generic_reloc, /* special_function */
1497 AARCH64_R_STR (TLSLD_MOVW_DTPREL_G1), /* name */
1498 FALSE, /* partial_inplace */
1499 0xffff, /* src_mask */
1500 0xffff, /* dst_mask */
1501 FALSE), /* pcrel_offset */
1503 /* No overflow check version of BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G1. */
1504 HOWTO64 (AARCH64_R (TLSLD_MOVW_DTPREL_G1_NC), /* type */
1505 16, /* rightshift */
1506 2, /* size (0 = byte, 1 = short, 2 = long) */
1508 FALSE, /* pc_relative */
1510 complain_overflow_dont, /* complain_on_overflow */
1511 bfd_elf_generic_reloc, /* special_function */
1512 AARCH64_R_STR (TLSLD_MOVW_DTPREL_G1_NC), /* name */
1513 FALSE, /* partial_inplace */
1514 0xffff, /* src_mask */
1515 0xffff, /* dst_mask */
1516 FALSE), /* pcrel_offset */
1518 /* MOVZ: bit[47:32] of byte offset to module TLS base address. */
1519 HOWTO64 (AARCH64_R (TLSLD_MOVW_DTPREL_G2), /* type */
1520 32, /* rightshift */
1521 2, /* size (0 = byte, 1 = short, 2 = long) */
1523 FALSE, /* pc_relative */
1525 complain_overflow_unsigned, /* complain_on_overflow */
1526 bfd_elf_generic_reloc, /* special_function */
1527 AARCH64_R_STR (TLSLD_MOVW_DTPREL_G2), /* name */
1528 FALSE, /* partial_inplace */
1529 0xffff, /* src_mask */
1530 0xffff, /* dst_mask */
1531 FALSE), /* pcrel_offset */
1533 HOWTO64 (AARCH64_R (TLSLE_MOVW_TPREL_G2), /* type */
1534 32, /* rightshift */
1535 2, /* size (0 = byte, 1 = short, 2 = long) */
1537 FALSE, /* pc_relative */
1539 complain_overflow_unsigned, /* complain_on_overflow */
1540 bfd_elf_generic_reloc, /* special_function */
1541 AARCH64_R_STR (TLSLE_MOVW_TPREL_G2), /* name */
1542 FALSE, /* partial_inplace */
1543 0xffff, /* src_mask */
1544 0xffff, /* dst_mask */
1545 FALSE), /* pcrel_offset */
1547 HOWTO (AARCH64_R (TLSLE_MOVW_TPREL_G1), /* type */
1548 16, /* rightshift */
1549 2, /* size (0 = byte, 1 = short, 2 = long) */
1551 FALSE, /* pc_relative */
1553 complain_overflow_dont, /* complain_on_overflow */
1554 bfd_elf_generic_reloc, /* special_function */
1555 AARCH64_R_STR (TLSLE_MOVW_TPREL_G1), /* name */
1556 FALSE, /* partial_inplace */
1557 0xffff, /* src_mask */
1558 0xffff, /* dst_mask */
1559 FALSE), /* pcrel_offset */
1561 HOWTO64 (AARCH64_R (TLSLE_MOVW_TPREL_G1_NC), /* type */
1562 16, /* rightshift */
1563 2, /* size (0 = byte, 1 = short, 2 = long) */
1565 FALSE, /* pc_relative */
1567 complain_overflow_dont, /* complain_on_overflow */
1568 bfd_elf_generic_reloc, /* special_function */
1569 AARCH64_R_STR (TLSLE_MOVW_TPREL_G1_NC), /* name */
1570 FALSE, /* partial_inplace */
1571 0xffff, /* src_mask */
1572 0xffff, /* dst_mask */
1573 FALSE), /* pcrel_offset */
1575 HOWTO (AARCH64_R (TLSLE_MOVW_TPREL_G0), /* type */
1577 2, /* size (0 = byte, 1 = short, 2 = long) */
1579 FALSE, /* pc_relative */
1581 complain_overflow_dont, /* complain_on_overflow */
1582 bfd_elf_generic_reloc, /* special_function */
1583 AARCH64_R_STR (TLSLE_MOVW_TPREL_G0), /* name */
1584 FALSE, /* partial_inplace */
1585 0xffff, /* src_mask */
1586 0xffff, /* dst_mask */
1587 FALSE), /* pcrel_offset */
1589 HOWTO (AARCH64_R (TLSLE_MOVW_TPREL_G0_NC), /* type */
1591 2, /* size (0 = byte, 1 = short, 2 = long) */
1593 FALSE, /* pc_relative */
1595 complain_overflow_dont, /* complain_on_overflow */
1596 bfd_elf_generic_reloc, /* special_function */
1597 AARCH64_R_STR (TLSLE_MOVW_TPREL_G0_NC), /* name */
1598 FALSE, /* partial_inplace */
1599 0xffff, /* src_mask */
1600 0xffff, /* dst_mask */
1601 FALSE), /* pcrel_offset */
1603 HOWTO (AARCH64_R (TLSLE_ADD_TPREL_HI12), /* type */
1604 12, /* rightshift */
1605 2, /* size (0 = byte, 1 = short, 2 = long) */
1607 FALSE, /* pc_relative */
1609 complain_overflow_unsigned, /* complain_on_overflow */
1610 bfd_elf_generic_reloc, /* special_function */
1611 AARCH64_R_STR (TLSLE_ADD_TPREL_HI12), /* name */
1612 FALSE, /* partial_inplace */
1613 0xfff, /* src_mask */
1614 0xfff, /* dst_mask */
1615 FALSE), /* pcrel_offset */
1617 HOWTO (AARCH64_R (TLSLE_ADD_TPREL_LO12), /* type */
1619 2, /* size (0 = byte, 1 = short, 2 = long) */
1621 FALSE, /* pc_relative */
1623 complain_overflow_unsigned, /* complain_on_overflow */
1624 bfd_elf_generic_reloc, /* special_function */
1625 AARCH64_R_STR (TLSLE_ADD_TPREL_LO12), /* name */
1626 FALSE, /* partial_inplace */
1627 0xfff, /* src_mask */
1628 0xfff, /* dst_mask */
1629 FALSE), /* pcrel_offset */
1631 HOWTO (AARCH64_R (TLSLE_ADD_TPREL_LO12_NC), /* 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_ADD_TPREL_LO12_NC), /* name */
1640 FALSE, /* partial_inplace */
1641 0xfff, /* src_mask */
1642 0xfff, /* dst_mask */
1643 FALSE), /* pcrel_offset */
1645 /* LD/ST16: bit[11:1] of byte offset to module TLS base address. */
1646 HOWTO (AARCH64_R (TLSLE_LDST16_TPREL_LO12), /* type */
1648 2, /* size (0 = byte, 1 = short, 2 = long) */
1650 FALSE, /* pc_relative */
1652 complain_overflow_unsigned, /* complain_on_overflow */
1653 bfd_elf_generic_reloc, /* special_function */
1654 AARCH64_R_STR (TLSLE_LDST16_TPREL_LO12), /* name */
1655 FALSE, /* partial_inplace */
1656 0x1ffc00, /* src_mask */
1657 0x1ffc00, /* dst_mask */
1658 FALSE), /* pcrel_offset */
1660 /* Same as BFD_RELOC_AARCH64_TLSLE_LDST16_TPREL_LO12, but no overflow check. */
1661 HOWTO (AARCH64_R (TLSLE_LDST16_TPREL_LO12_NC), /* type */
1663 2, /* size (0 = byte, 1 = short, 2 = long) */
1665 FALSE, /* pc_relative */
1667 complain_overflow_dont, /* complain_on_overflow */
1668 bfd_elf_generic_reloc, /* special_function */
1669 AARCH64_R_STR (TLSLE_LDST16_TPREL_LO12_NC), /* name */
1670 FALSE, /* partial_inplace */
1671 0x1ffc00, /* src_mask */
1672 0x1ffc00, /* dst_mask */
1673 FALSE), /* pcrel_offset */
1675 /* LD/ST32: bit[11:2] of byte offset to module TLS base address. */
1676 HOWTO (AARCH64_R (TLSLE_LDST32_TPREL_LO12), /* type */
1678 2, /* size (0 = byte, 1 = short, 2 = long) */
1680 FALSE, /* pc_relative */
1682 complain_overflow_unsigned, /* complain_on_overflow */
1683 bfd_elf_generic_reloc, /* special_function */
1684 AARCH64_R_STR (TLSLE_LDST32_TPREL_LO12), /* name */
1685 FALSE, /* partial_inplace */
1686 0xffc00, /* src_mask */
1687 0xffc00, /* dst_mask */
1688 FALSE), /* pcrel_offset */
1690 /* Same as BFD_RELOC_AARCH64_TLSLE_LDST32_TPREL_LO12, but no overflow check. */
1691 HOWTO (AARCH64_R (TLSLE_LDST32_TPREL_LO12_NC), /* type */
1693 2, /* size (0 = byte, 1 = short, 2 = long) */
1695 FALSE, /* pc_relative */
1697 complain_overflow_dont, /* complain_on_overflow */
1698 bfd_elf_generic_reloc, /* special_function */
1699 AARCH64_R_STR (TLSLE_LDST32_TPREL_LO12_NC), /* name */
1700 FALSE, /* partial_inplace */
1701 0xffc00, /* src_mask */
1702 0xffc00, /* dst_mask */
1703 FALSE), /* pcrel_offset */
1705 /* LD/ST64: bit[11:3] of byte offset to module TLS base address. */
1706 HOWTO (AARCH64_R (TLSLE_LDST64_TPREL_LO12), /* type */
1708 2, /* size (0 = byte, 1 = short, 2 = long) */
1710 FALSE, /* pc_relative */
1712 complain_overflow_unsigned, /* complain_on_overflow */
1713 bfd_elf_generic_reloc, /* special_function */
1714 AARCH64_R_STR (TLSLE_LDST64_TPREL_LO12), /* name */
1715 FALSE, /* partial_inplace */
1716 0x7fc00, /* src_mask */
1717 0x7fc00, /* dst_mask */
1718 FALSE), /* pcrel_offset */
1720 /* Same as BFD_RELOC_AARCH64_TLSLE_LDST64_TPREL_LO12, but no overflow check. */
1721 HOWTO (AARCH64_R (TLSLE_LDST64_TPREL_LO12_NC), /* type */
1723 2, /* size (0 = byte, 1 = short, 2 = long) */
1725 FALSE, /* pc_relative */
1727 complain_overflow_dont, /* complain_on_overflow */
1728 bfd_elf_generic_reloc, /* special_function */
1729 AARCH64_R_STR (TLSLE_LDST64_TPREL_LO12_NC), /* name */
1730 FALSE, /* partial_inplace */
1731 0x7fc00, /* src_mask */
1732 0x7fc00, /* dst_mask */
1733 FALSE), /* pcrel_offset */
1735 /* LD/ST8: bit[11:0] of byte offset to module TLS base address. */
1736 HOWTO (AARCH64_R (TLSLE_LDST8_TPREL_LO12), /* type */
1738 2, /* size (0 = byte, 1 = short, 2 = long) */
1740 FALSE, /* pc_relative */
1742 complain_overflow_unsigned, /* complain_on_overflow */
1743 bfd_elf_generic_reloc, /* special_function */
1744 AARCH64_R_STR (TLSLE_LDST8_TPREL_LO12), /* name */
1745 FALSE, /* partial_inplace */
1746 0x3ffc00, /* src_mask */
1747 0x3ffc00, /* dst_mask */
1748 FALSE), /* pcrel_offset */
1750 /* Same as BFD_RELOC_AARCH64_TLSLE_LDST8_TPREL_LO12, but no overflow check. */
1751 HOWTO (AARCH64_R (TLSLE_LDST8_TPREL_LO12_NC), /* type */
1753 2, /* size (0 = byte, 1 = short, 2 = long) */
1755 FALSE, /* pc_relative */
1757 complain_overflow_dont, /* complain_on_overflow */
1758 bfd_elf_generic_reloc, /* special_function */
1759 AARCH64_R_STR (TLSLE_LDST8_TPREL_LO12_NC), /* name */
1760 FALSE, /* partial_inplace */
1761 0x3ffc00, /* src_mask */
1762 0x3ffc00, /* dst_mask */
1763 FALSE), /* pcrel_offset */
1765 HOWTO (AARCH64_R (TLSDESC_LD_PREL19), /* type */
1767 2, /* size (0 = byte, 1 = short, 2 = long) */
1769 TRUE, /* pc_relative */
1771 complain_overflow_dont, /* complain_on_overflow */
1772 bfd_elf_generic_reloc, /* special_function */
1773 AARCH64_R_STR (TLSDESC_LD_PREL19), /* name */
1774 FALSE, /* partial_inplace */
1775 0x0ffffe0, /* src_mask */
1776 0x0ffffe0, /* dst_mask */
1777 TRUE), /* pcrel_offset */
1779 HOWTO (AARCH64_R (TLSDESC_ADR_PREL21), /* type */
1781 2, /* size (0 = byte, 1 = short, 2 = long) */
1783 TRUE, /* pc_relative */
1785 complain_overflow_dont, /* complain_on_overflow */
1786 bfd_elf_generic_reloc, /* special_function */
1787 AARCH64_R_STR (TLSDESC_ADR_PREL21), /* name */
1788 FALSE, /* partial_inplace */
1789 0x1fffff, /* src_mask */
1790 0x1fffff, /* dst_mask */
1791 TRUE), /* pcrel_offset */
1793 /* Get to the page for the GOT entry for the symbol
1794 (G(S) - P) using an ADRP instruction. */
1795 HOWTO (AARCH64_R (TLSDESC_ADR_PAGE21), /* type */
1796 12, /* rightshift */
1797 2, /* size (0 = byte, 1 = short, 2 = long) */
1799 TRUE, /* pc_relative */
1801 complain_overflow_dont, /* complain_on_overflow */
1802 bfd_elf_generic_reloc, /* special_function */
1803 AARCH64_R_STR (TLSDESC_ADR_PAGE21), /* name */
1804 FALSE, /* partial_inplace */
1805 0x1fffff, /* src_mask */
1806 0x1fffff, /* dst_mask */
1807 TRUE), /* pcrel_offset */
1809 /* LD64: GOT offset G(S) & 0xff8. */
1810 HOWTO64 (AARCH64_R (TLSDESC_LD64_LO12), /* type */
1812 2, /* size (0 = byte, 1 = short, 2 = long) */
1814 FALSE, /* pc_relative */
1816 complain_overflow_dont, /* complain_on_overflow */
1817 bfd_elf_generic_reloc, /* special_function */
1818 AARCH64_R_STR (TLSDESC_LD64_LO12), /* name */
1819 FALSE, /* partial_inplace */
1820 0xff8, /* src_mask */
1821 0xff8, /* dst_mask */
1822 FALSE), /* pcrel_offset */
1824 /* LD32: GOT offset G(S) & 0xffc. */
1825 HOWTO32 (AARCH64_R (TLSDESC_LD32_LO12_NC), /* type */
1827 2, /* size (0 = byte, 1 = short, 2 = long) */
1829 FALSE, /* pc_relative */
1831 complain_overflow_dont, /* complain_on_overflow */
1832 bfd_elf_generic_reloc, /* special_function */
1833 AARCH64_R_STR (TLSDESC_LD32_LO12_NC), /* name */
1834 FALSE, /* partial_inplace */
1835 0xffc, /* src_mask */
1836 0xffc, /* dst_mask */
1837 FALSE), /* pcrel_offset */
1839 /* ADD: GOT offset G(S) & 0xfff. */
1840 HOWTO (AARCH64_R (TLSDESC_ADD_LO12), /* type */
1842 2, /* size (0 = byte, 1 = short, 2 = long) */
1844 FALSE, /* pc_relative */
1846 complain_overflow_dont,/* complain_on_overflow */
1847 bfd_elf_generic_reloc, /* special_function */
1848 AARCH64_R_STR (TLSDESC_ADD_LO12), /* name */
1849 FALSE, /* partial_inplace */
1850 0xfff, /* src_mask */
1851 0xfff, /* dst_mask */
1852 FALSE), /* pcrel_offset */
1854 HOWTO64 (AARCH64_R (TLSDESC_OFF_G1), /* type */
1855 16, /* rightshift */
1856 2, /* size (0 = byte, 1 = short, 2 = long) */
1858 FALSE, /* pc_relative */
1860 complain_overflow_unsigned, /* complain_on_overflow */
1861 bfd_elf_generic_reloc, /* special_function */
1862 AARCH64_R_STR (TLSDESC_OFF_G1), /* name */
1863 FALSE, /* partial_inplace */
1864 0xffff, /* src_mask */
1865 0xffff, /* dst_mask */
1866 FALSE), /* pcrel_offset */
1868 HOWTO64 (AARCH64_R (TLSDESC_OFF_G0_NC), /* type */
1870 2, /* size (0 = byte, 1 = short, 2 = long) */
1872 FALSE, /* pc_relative */
1874 complain_overflow_dont, /* complain_on_overflow */
1875 bfd_elf_generic_reloc, /* special_function */
1876 AARCH64_R_STR (TLSDESC_OFF_G0_NC), /* name */
1877 FALSE, /* partial_inplace */
1878 0xffff, /* src_mask */
1879 0xffff, /* dst_mask */
1880 FALSE), /* pcrel_offset */
1882 HOWTO64 (AARCH64_R (TLSDESC_LDR), /* type */
1884 2, /* size (0 = byte, 1 = short, 2 = long) */
1886 FALSE, /* pc_relative */
1888 complain_overflow_dont, /* complain_on_overflow */
1889 bfd_elf_generic_reloc, /* special_function */
1890 AARCH64_R_STR (TLSDESC_LDR), /* name */
1891 FALSE, /* partial_inplace */
1894 FALSE), /* pcrel_offset */
1896 HOWTO64 (AARCH64_R (TLSDESC_ADD), /* 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), /* name */
1905 FALSE, /* partial_inplace */
1908 FALSE), /* pcrel_offset */
1910 HOWTO (AARCH64_R (TLSDESC_CALL), /* type */
1912 2, /* size (0 = byte, 1 = short, 2 = long) */
1914 FALSE, /* pc_relative */
1916 complain_overflow_dont, /* complain_on_overflow */
1917 bfd_elf_generic_reloc, /* special_function */
1918 AARCH64_R_STR (TLSDESC_CALL), /* name */
1919 FALSE, /* partial_inplace */
1922 FALSE), /* pcrel_offset */
1924 HOWTO (AARCH64_R (COPY), /* type */
1926 2, /* size (0 = byte, 1 = short, 2 = long) */
1928 FALSE, /* pc_relative */
1930 complain_overflow_bitfield, /* complain_on_overflow */
1931 bfd_elf_generic_reloc, /* special_function */
1932 AARCH64_R_STR (COPY), /* name */
1933 TRUE, /* partial_inplace */
1934 0xffffffff, /* src_mask */
1935 0xffffffff, /* dst_mask */
1936 FALSE), /* pcrel_offset */
1938 HOWTO (AARCH64_R (GLOB_DAT), /* type */
1940 2, /* size (0 = byte, 1 = short, 2 = long) */
1942 FALSE, /* pc_relative */
1944 complain_overflow_bitfield, /* complain_on_overflow */
1945 bfd_elf_generic_reloc, /* special_function */
1946 AARCH64_R_STR (GLOB_DAT), /* name */
1947 TRUE, /* partial_inplace */
1948 0xffffffff, /* src_mask */
1949 0xffffffff, /* dst_mask */
1950 FALSE), /* pcrel_offset */
1952 HOWTO (AARCH64_R (JUMP_SLOT), /* type */
1954 2, /* size (0 = byte, 1 = short, 2 = long) */
1956 FALSE, /* pc_relative */
1958 complain_overflow_bitfield, /* complain_on_overflow */
1959 bfd_elf_generic_reloc, /* special_function */
1960 AARCH64_R_STR (JUMP_SLOT), /* name */
1961 TRUE, /* partial_inplace */
1962 0xffffffff, /* src_mask */
1963 0xffffffff, /* dst_mask */
1964 FALSE), /* pcrel_offset */
1966 HOWTO (AARCH64_R (RELATIVE), /* type */
1968 2, /* size (0 = byte, 1 = short, 2 = long) */
1970 FALSE, /* pc_relative */
1972 complain_overflow_bitfield, /* complain_on_overflow */
1973 bfd_elf_generic_reloc, /* special_function */
1974 AARCH64_R_STR (RELATIVE), /* name */
1975 TRUE, /* partial_inplace */
1976 ALL_ONES, /* src_mask */
1977 ALL_ONES, /* dst_mask */
1978 FALSE), /* pcrel_offset */
1980 HOWTO (AARCH64_R (TLS_DTPMOD), /* type */
1982 2, /* size (0 = byte, 1 = short, 2 = long) */
1984 FALSE, /* pc_relative */
1986 complain_overflow_dont, /* complain_on_overflow */
1987 bfd_elf_generic_reloc, /* special_function */
1989 AARCH64_R_STR (TLS_DTPMOD64), /* name */
1991 AARCH64_R_STR (TLS_DTPMOD), /* name */
1993 FALSE, /* partial_inplace */
1995 ALL_ONES, /* dst_mask */
1996 FALSE), /* pc_reloffset */
1998 HOWTO (AARCH64_R (TLS_DTPREL), /* type */
2000 2, /* size (0 = byte, 1 = short, 2 = long) */
2002 FALSE, /* pc_relative */
2004 complain_overflow_dont, /* complain_on_overflow */
2005 bfd_elf_generic_reloc, /* special_function */
2007 AARCH64_R_STR (TLS_DTPREL64), /* name */
2009 AARCH64_R_STR (TLS_DTPREL), /* name */
2011 FALSE, /* partial_inplace */
2013 ALL_ONES, /* dst_mask */
2014 FALSE), /* pcrel_offset */
2016 HOWTO (AARCH64_R (TLS_TPREL), /* type */
2018 2, /* size (0 = byte, 1 = short, 2 = long) */
2020 FALSE, /* pc_relative */
2022 complain_overflow_dont, /* complain_on_overflow */
2023 bfd_elf_generic_reloc, /* special_function */
2025 AARCH64_R_STR (TLS_TPREL64), /* name */
2027 AARCH64_R_STR (TLS_TPREL), /* name */
2029 FALSE, /* partial_inplace */
2031 ALL_ONES, /* dst_mask */
2032 FALSE), /* pcrel_offset */
2034 HOWTO (AARCH64_R (TLSDESC), /* type */
2036 2, /* size (0 = byte, 1 = short, 2 = long) */
2038 FALSE, /* pc_relative */
2040 complain_overflow_dont, /* complain_on_overflow */
2041 bfd_elf_generic_reloc, /* special_function */
2042 AARCH64_R_STR (TLSDESC), /* name */
2043 FALSE, /* partial_inplace */
2045 ALL_ONES, /* dst_mask */
2046 FALSE), /* pcrel_offset */
2048 HOWTO (AARCH64_R (IRELATIVE), /* type */
2050 2, /* size (0 = byte, 1 = short, 2 = long) */
2052 FALSE, /* pc_relative */
2054 complain_overflow_bitfield, /* complain_on_overflow */
2055 bfd_elf_generic_reloc, /* special_function */
2056 AARCH64_R_STR (IRELATIVE), /* name */
2057 FALSE, /* partial_inplace */
2059 ALL_ONES, /* dst_mask */
2060 FALSE), /* pcrel_offset */
2065 static reloc_howto_type elfNN_aarch64_howto_none =
2066 HOWTO (R_AARCH64_NONE, /* type */
2068 3, /* size (0 = byte, 1 = short, 2 = long) */
2070 FALSE, /* pc_relative */
2072 complain_overflow_dont,/* complain_on_overflow */
2073 bfd_elf_generic_reloc, /* special_function */
2074 "R_AARCH64_NONE", /* name */
2075 FALSE, /* partial_inplace */
2078 FALSE); /* pcrel_offset */
2080 /* Given HOWTO, return the bfd internal relocation enumerator. */
2082 static bfd_reloc_code_real_type
2083 elfNN_aarch64_bfd_reloc_from_howto (reloc_howto_type *howto)
2086 = (int) ARRAY_SIZE (elfNN_aarch64_howto_table);
2087 const ptrdiff_t offset
2088 = howto - elfNN_aarch64_howto_table;
2090 if (offset > 0 && offset < size - 1)
2091 return BFD_RELOC_AARCH64_RELOC_START + offset;
2093 if (howto == &elfNN_aarch64_howto_none)
2094 return BFD_RELOC_AARCH64_NONE;
2096 return BFD_RELOC_AARCH64_RELOC_START;
2099 /* Given R_TYPE, return the bfd internal relocation enumerator. */
2101 static bfd_reloc_code_real_type
2102 elfNN_aarch64_bfd_reloc_from_type (bfd *abfd, unsigned int r_type)
2104 static bfd_boolean initialized_p = FALSE;
2105 /* Indexed by R_TYPE, values are offsets in the howto_table. */
2106 static unsigned int offsets[R_AARCH64_end];
2112 for (i = 1; i < ARRAY_SIZE (elfNN_aarch64_howto_table) - 1; ++i)
2113 if (elfNN_aarch64_howto_table[i].type != 0)
2114 offsets[elfNN_aarch64_howto_table[i].type] = i;
2116 initialized_p = TRUE;
2119 if (r_type == R_AARCH64_NONE || r_type == R_AARCH64_NULL)
2120 return BFD_RELOC_AARCH64_NONE;
2122 /* PR 17512: file: b371e70a. */
2123 if (r_type >= R_AARCH64_end)
2125 _bfd_error_handler (_("%pB: unsupported relocation type %#x"),
2127 bfd_set_error (bfd_error_bad_value);
2128 return BFD_RELOC_AARCH64_NONE;
2131 return BFD_RELOC_AARCH64_RELOC_START + offsets[r_type];
2134 struct elf_aarch64_reloc_map
2136 bfd_reloc_code_real_type from;
2137 bfd_reloc_code_real_type to;
2140 /* Map bfd generic reloc to AArch64-specific reloc. */
2141 static const struct elf_aarch64_reloc_map elf_aarch64_reloc_map[] =
2143 {BFD_RELOC_NONE, BFD_RELOC_AARCH64_NONE},
2145 /* Basic data relocations. */
2146 {BFD_RELOC_CTOR, BFD_RELOC_AARCH64_NN},
2147 {BFD_RELOC_64, BFD_RELOC_AARCH64_64},
2148 {BFD_RELOC_32, BFD_RELOC_AARCH64_32},
2149 {BFD_RELOC_16, BFD_RELOC_AARCH64_16},
2150 {BFD_RELOC_64_PCREL, BFD_RELOC_AARCH64_64_PCREL},
2151 {BFD_RELOC_32_PCREL, BFD_RELOC_AARCH64_32_PCREL},
2152 {BFD_RELOC_16_PCREL, BFD_RELOC_AARCH64_16_PCREL},
2155 /* Given the bfd internal relocation enumerator in CODE, return the
2156 corresponding howto entry. */
2158 static reloc_howto_type *
2159 elfNN_aarch64_howto_from_bfd_reloc (bfd_reloc_code_real_type code)
2163 /* Convert bfd generic reloc to AArch64-specific reloc. */
2164 if (code < BFD_RELOC_AARCH64_RELOC_START
2165 || code > BFD_RELOC_AARCH64_RELOC_END)
2166 for (i = 0; i < ARRAY_SIZE (elf_aarch64_reloc_map); i++)
2167 if (elf_aarch64_reloc_map[i].from == code)
2169 code = elf_aarch64_reloc_map[i].to;
2173 if (code > BFD_RELOC_AARCH64_RELOC_START
2174 && code < BFD_RELOC_AARCH64_RELOC_END)
2175 if (elfNN_aarch64_howto_table[code - BFD_RELOC_AARCH64_RELOC_START].type)
2176 return &elfNN_aarch64_howto_table[code - BFD_RELOC_AARCH64_RELOC_START];
2178 if (code == BFD_RELOC_AARCH64_NONE)
2179 return &elfNN_aarch64_howto_none;
2184 static reloc_howto_type *
2185 elfNN_aarch64_howto_from_type (bfd *abfd, unsigned int r_type)
2187 bfd_reloc_code_real_type val;
2188 reloc_howto_type *howto;
2193 bfd_set_error (bfd_error_bad_value);
2198 if (r_type == R_AARCH64_NONE)
2199 return &elfNN_aarch64_howto_none;
2201 val = elfNN_aarch64_bfd_reloc_from_type (abfd, r_type);
2202 howto = elfNN_aarch64_howto_from_bfd_reloc (val);
2207 bfd_set_error (bfd_error_bad_value);
2212 elfNN_aarch64_info_to_howto (bfd *abfd, arelent *bfd_reloc,
2213 Elf_Internal_Rela *elf_reloc)
2215 unsigned int r_type;
2217 r_type = ELFNN_R_TYPE (elf_reloc->r_info);
2218 bfd_reloc->howto = elfNN_aarch64_howto_from_type (abfd, r_type);
2220 if (bfd_reloc->howto == NULL)
2222 /* xgettext:c-format */
2223 _bfd_error_handler (_("%pB: unsupported relocation type %#x"), abfd, r_type);
2229 static reloc_howto_type *
2230 elfNN_aarch64_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED,
2231 bfd_reloc_code_real_type code)
2233 reloc_howto_type *howto = elfNN_aarch64_howto_from_bfd_reloc (code);
2238 bfd_set_error (bfd_error_bad_value);
2242 static reloc_howto_type *
2243 elfNN_aarch64_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED,
2248 for (i = 1; i < ARRAY_SIZE (elfNN_aarch64_howto_table) - 1; ++i)
2249 if (elfNN_aarch64_howto_table[i].name != NULL
2250 && strcasecmp (elfNN_aarch64_howto_table[i].name, r_name) == 0)
2251 return &elfNN_aarch64_howto_table[i];
2256 #define TARGET_LITTLE_SYM aarch64_elfNN_le_vec
2257 #define TARGET_LITTLE_NAME "elfNN-littleaarch64"
2258 #define TARGET_BIG_SYM aarch64_elfNN_be_vec
2259 #define TARGET_BIG_NAME "elfNN-bigaarch64"
2261 /* The linker script knows the section names for placement.
2262 The entry_names are used to do simple name mangling on the stubs.
2263 Given a function name, and its type, the stub can be found. The
2264 name can be changed. The only requirement is the %s be present. */
2265 #define STUB_ENTRY_NAME "__%s_veneer"
2267 /* The name of the dynamic interpreter. This is put in the .interp
2269 #define ELF_DYNAMIC_INTERPRETER "/lib/ld.so.1"
2271 #define AARCH64_MAX_FWD_BRANCH_OFFSET \
2272 (((1 << 25) - 1) << 2)
2273 #define AARCH64_MAX_BWD_BRANCH_OFFSET \
2276 #define AARCH64_MAX_ADRP_IMM ((1 << 20) - 1)
2277 #define AARCH64_MIN_ADRP_IMM (-(1 << 20))
2280 aarch64_valid_for_adrp_p (bfd_vma value, bfd_vma place)
2282 bfd_signed_vma offset = (bfd_signed_vma) (PG (value) - PG (place)) >> 12;
2283 return offset <= AARCH64_MAX_ADRP_IMM && offset >= AARCH64_MIN_ADRP_IMM;
2287 aarch64_valid_branch_p (bfd_vma value, bfd_vma place)
2289 bfd_signed_vma offset = (bfd_signed_vma) (value - place);
2290 return (offset <= AARCH64_MAX_FWD_BRANCH_OFFSET
2291 && offset >= AARCH64_MAX_BWD_BRANCH_OFFSET);
2294 static const uint32_t aarch64_adrp_branch_stub [] =
2296 0x90000010, /* adrp ip0, X */
2297 /* R_AARCH64_ADR_HI21_PCREL(X) */
2298 0x91000210, /* add ip0, ip0, :lo12:X */
2299 /* R_AARCH64_ADD_ABS_LO12_NC(X) */
2300 0xd61f0200, /* br ip0 */
2303 static const uint32_t aarch64_long_branch_stub[] =
2306 0x58000090, /* ldr ip0, 1f */
2308 0x18000090, /* ldr wip0, 1f */
2310 0x10000011, /* adr ip1, #0 */
2311 0x8b110210, /* add ip0, ip0, ip1 */
2312 0xd61f0200, /* br ip0 */
2313 0x00000000, /* 1: .xword or .word
2314 R_AARCH64_PRELNN(X) + 12
2319 static const uint32_t aarch64_erratum_835769_stub[] =
2321 0x00000000, /* Placeholder for multiply accumulate. */
2322 0x14000000, /* b <label> */
2325 static const uint32_t aarch64_erratum_843419_stub[] =
2327 0x00000000, /* Placeholder for LDR instruction. */
2328 0x14000000, /* b <label> */
2331 /* Section name for stubs is the associated section name plus this
2333 #define STUB_SUFFIX ".stub"
2335 enum elf_aarch64_stub_type
2338 aarch64_stub_adrp_branch,
2339 aarch64_stub_long_branch,
2340 aarch64_stub_erratum_835769_veneer,
2341 aarch64_stub_erratum_843419_veneer,
2344 struct elf_aarch64_stub_hash_entry
2346 /* Base hash table entry structure. */
2347 struct bfd_hash_entry root;
2349 /* The stub section. */
2352 /* Offset within stub_sec of the beginning of this stub. */
2353 bfd_vma stub_offset;
2355 /* Given the symbol's value and its section we can determine its final
2356 value when building the stubs (so the stub knows where to jump). */
2357 bfd_vma target_value;
2358 asection *target_section;
2360 enum elf_aarch64_stub_type stub_type;
2362 /* The symbol table entry, if any, that this was derived from. */
2363 struct elf_aarch64_link_hash_entry *h;
2365 /* Destination symbol type */
2366 unsigned char st_type;
2368 /* Where this stub is being called from, or, in the case of combined
2369 stub sections, the first input section in the group. */
2372 /* The name for the local symbol at the start of this stub. The
2373 stub name in the hash table has to be unique; this does not, so
2374 it can be friendlier. */
2377 /* The instruction which caused this stub to be generated (only valid for
2378 erratum 835769 workaround stubs at present). */
2379 uint32_t veneered_insn;
2381 /* In an erratum 843419 workaround stub, the ADRP instruction offset. */
2382 bfd_vma adrp_offset;
2385 /* Used to build a map of a section. This is required for mixed-endian
2388 typedef struct elf_elf_section_map
2393 elf_aarch64_section_map;
2396 typedef struct _aarch64_elf_section_data
2398 struct bfd_elf_section_data elf;
2399 unsigned int mapcount;
2400 unsigned int mapsize;
2401 elf_aarch64_section_map *map;
2403 _aarch64_elf_section_data;
2405 #define elf_aarch64_section_data(sec) \
2406 ((_aarch64_elf_section_data *) elf_section_data (sec))
2408 /* The size of the thread control block which is defined to be two pointers. */
2409 #define TCB_SIZE (ARCH_SIZE/8)*2
2411 struct elf_aarch64_local_symbol
2413 unsigned int got_type;
2414 bfd_signed_vma got_refcount;
2417 /* Offset of the GOTPLT entry reserved for the TLS descriptor. The
2418 offset is from the end of the jump table and reserved entries
2421 The magic value (bfd_vma) -1 indicates that an offset has not be
2423 bfd_vma tlsdesc_got_jump_table_offset;
2426 struct elf_aarch64_obj_tdata
2428 struct elf_obj_tdata root;
2430 /* local symbol descriptors */
2431 struct elf_aarch64_local_symbol *locals;
2433 /* Zero to warn when linking objects with incompatible enum sizes. */
2434 int no_enum_size_warning;
2436 /* Zero to warn when linking objects with incompatible wchar_t sizes. */
2437 int no_wchar_size_warning;
2440 #define elf_aarch64_tdata(bfd) \
2441 ((struct elf_aarch64_obj_tdata *) (bfd)->tdata.any)
2443 #define elf_aarch64_locals(bfd) (elf_aarch64_tdata (bfd)->locals)
2445 #define is_aarch64_elf(bfd) \
2446 (bfd_get_flavour (bfd) == bfd_target_elf_flavour \
2447 && elf_tdata (bfd) != NULL \
2448 && elf_object_id (bfd) == AARCH64_ELF_DATA)
2451 elfNN_aarch64_mkobject (bfd *abfd)
2453 return bfd_elf_allocate_object (abfd, sizeof (struct elf_aarch64_obj_tdata),
2457 #define elf_aarch64_hash_entry(ent) \
2458 ((struct elf_aarch64_link_hash_entry *)(ent))
2460 #define GOT_UNKNOWN 0
2461 #define GOT_NORMAL 1
2462 #define GOT_TLS_GD 2
2463 #define GOT_TLS_IE 4
2464 #define GOT_TLSDESC_GD 8
2466 #define GOT_TLS_GD_ANY_P(type) ((type & GOT_TLS_GD) || (type & GOT_TLSDESC_GD))
2468 /* AArch64 ELF linker hash entry. */
2469 struct elf_aarch64_link_hash_entry
2471 struct elf_link_hash_entry root;
2473 /* Track dynamic relocs copied for this symbol. */
2474 struct elf_dyn_relocs *dyn_relocs;
2476 /* Since PLT entries have variable size, we need to record the
2477 index into .got.plt instead of recomputing it from the PLT
2479 bfd_signed_vma plt_got_offset;
2481 /* Bit mask representing the type of GOT entry(s) if any required by
2483 unsigned int got_type;
2485 /* A pointer to the most recently used stub hash entry against this
2487 struct elf_aarch64_stub_hash_entry *stub_cache;
2489 /* Offset of the GOTPLT entry reserved for the TLS descriptor. The offset
2490 is from the end of the jump table and reserved entries within the PLTGOT.
2492 The magic value (bfd_vma) -1 indicates that an offset has not
2494 bfd_vma tlsdesc_got_jump_table_offset;
2498 elfNN_aarch64_symbol_got_type (struct elf_link_hash_entry *h,
2500 unsigned long r_symndx)
2503 return elf_aarch64_hash_entry (h)->got_type;
2505 if (! elf_aarch64_locals (abfd))
2508 return elf_aarch64_locals (abfd)[r_symndx].got_type;
2511 /* Get the AArch64 elf linker hash table from a link_info structure. */
2512 #define elf_aarch64_hash_table(info) \
2513 ((struct elf_aarch64_link_hash_table *) ((info)->hash))
2515 #define aarch64_stub_hash_lookup(table, string, create, copy) \
2516 ((struct elf_aarch64_stub_hash_entry *) \
2517 bfd_hash_lookup ((table), (string), (create), (copy)))
2519 /* AArch64 ELF linker hash table. */
2520 struct elf_aarch64_link_hash_table
2522 /* The main hash table. */
2523 struct elf_link_hash_table root;
2525 /* Nonzero to force PIC branch veneers. */
2528 /* Fix erratum 835769. */
2529 int fix_erratum_835769;
2531 /* Fix erratum 843419. */
2532 int fix_erratum_843419;
2534 /* Enable ADRP->ADR rewrite for erratum 843419 workaround. */
2535 int fix_erratum_843419_adr;
2537 /* Don't apply link-time values for dynamic relocations. */
2538 int no_apply_dynamic_relocs;
2540 /* The number of bytes in the initial entry in the PLT. */
2541 bfd_size_type plt_header_size;
2543 /* The number of bytes in the subsequent PLT etries. */
2544 bfd_size_type plt_entry_size;
2546 /* Small local sym cache. */
2547 struct sym_cache sym_cache;
2549 /* For convenience in allocate_dynrelocs. */
2552 /* The amount of space used by the reserved portion of the sgotplt
2553 section, plus whatever space is used by the jump slots. */
2554 bfd_vma sgotplt_jump_table_size;
2556 /* The stub hash table. */
2557 struct bfd_hash_table stub_hash_table;
2559 /* Linker stub bfd. */
2562 /* Linker call-backs. */
2563 asection *(*add_stub_section) (const char *, asection *);
2564 void (*layout_sections_again) (void);
2566 /* Array to keep track of which stub sections have been created, and
2567 information on stub grouping. */
2570 /* This is the section to which stubs in the group will be
2573 /* The stub section. */
2577 /* Assorted information used by elfNN_aarch64_size_stubs. */
2578 unsigned int bfd_count;
2579 unsigned int top_index;
2580 asection **input_list;
2582 /* The offset into splt of the PLT entry for the TLS descriptor
2583 resolver. Special values are 0, if not necessary (or not found
2584 to be necessary yet), and -1 if needed but not determined
2586 bfd_vma tlsdesc_plt;
2588 /* The GOT offset for the lazy trampoline. Communicated to the
2589 loader via DT_TLSDESC_GOT. The magic value (bfd_vma) -1
2590 indicates an offset is not allocated. */
2591 bfd_vma dt_tlsdesc_got;
2593 /* Used by local STT_GNU_IFUNC symbols. */
2594 htab_t loc_hash_table;
2595 void * loc_hash_memory;
2598 /* Create an entry in an AArch64 ELF linker hash table. */
2600 static struct bfd_hash_entry *
2601 elfNN_aarch64_link_hash_newfunc (struct bfd_hash_entry *entry,
2602 struct bfd_hash_table *table,
2605 struct elf_aarch64_link_hash_entry *ret =
2606 (struct elf_aarch64_link_hash_entry *) entry;
2608 /* Allocate the structure if it has not already been allocated by a
2611 ret = bfd_hash_allocate (table,
2612 sizeof (struct elf_aarch64_link_hash_entry));
2614 return (struct bfd_hash_entry *) ret;
2616 /* Call the allocation method of the superclass. */
2617 ret = ((struct elf_aarch64_link_hash_entry *)
2618 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry *) ret,
2622 ret->dyn_relocs = NULL;
2623 ret->got_type = GOT_UNKNOWN;
2624 ret->plt_got_offset = (bfd_vma) - 1;
2625 ret->stub_cache = NULL;
2626 ret->tlsdesc_got_jump_table_offset = (bfd_vma) - 1;
2629 return (struct bfd_hash_entry *) ret;
2632 /* Initialize an entry in the stub hash table. */
2634 static struct bfd_hash_entry *
2635 stub_hash_newfunc (struct bfd_hash_entry *entry,
2636 struct bfd_hash_table *table, const char *string)
2638 /* Allocate the structure if it has not already been allocated by a
2642 entry = bfd_hash_allocate (table,
2644 elf_aarch64_stub_hash_entry));
2649 /* Call the allocation method of the superclass. */
2650 entry = bfd_hash_newfunc (entry, table, string);
2653 struct elf_aarch64_stub_hash_entry *eh;
2655 /* Initialize the local fields. */
2656 eh = (struct elf_aarch64_stub_hash_entry *) entry;
2657 eh->adrp_offset = 0;
2658 eh->stub_sec = NULL;
2659 eh->stub_offset = 0;
2660 eh->target_value = 0;
2661 eh->target_section = NULL;
2662 eh->stub_type = aarch64_stub_none;
2670 /* Compute a hash of a local hash entry. We use elf_link_hash_entry
2671 for local symbol so that we can handle local STT_GNU_IFUNC symbols
2672 as global symbol. We reuse indx and dynstr_index for local symbol
2673 hash since they aren't used by global symbols in this backend. */
2676 elfNN_aarch64_local_htab_hash (const void *ptr)
2678 struct elf_link_hash_entry *h
2679 = (struct elf_link_hash_entry *) ptr;
2680 return ELF_LOCAL_SYMBOL_HASH (h->indx, h->dynstr_index);
2683 /* Compare local hash entries. */
2686 elfNN_aarch64_local_htab_eq (const void *ptr1, const void *ptr2)
2688 struct elf_link_hash_entry *h1
2689 = (struct elf_link_hash_entry *) ptr1;
2690 struct elf_link_hash_entry *h2
2691 = (struct elf_link_hash_entry *) ptr2;
2693 return h1->indx == h2->indx && h1->dynstr_index == h2->dynstr_index;
2696 /* Find and/or create a hash entry for local symbol. */
2698 static struct elf_link_hash_entry *
2699 elfNN_aarch64_get_local_sym_hash (struct elf_aarch64_link_hash_table *htab,
2700 bfd *abfd, const Elf_Internal_Rela *rel,
2703 struct elf_aarch64_link_hash_entry e, *ret;
2704 asection *sec = abfd->sections;
2705 hashval_t h = ELF_LOCAL_SYMBOL_HASH (sec->id,
2706 ELFNN_R_SYM (rel->r_info));
2709 e.root.indx = sec->id;
2710 e.root.dynstr_index = ELFNN_R_SYM (rel->r_info);
2711 slot = htab_find_slot_with_hash (htab->loc_hash_table, &e, h,
2712 create ? INSERT : NO_INSERT);
2719 ret = (struct elf_aarch64_link_hash_entry *) *slot;
2723 ret = (struct elf_aarch64_link_hash_entry *)
2724 objalloc_alloc ((struct objalloc *) htab->loc_hash_memory,
2725 sizeof (struct elf_aarch64_link_hash_entry));
2728 memset (ret, 0, sizeof (*ret));
2729 ret->root.indx = sec->id;
2730 ret->root.dynstr_index = ELFNN_R_SYM (rel->r_info);
2731 ret->root.dynindx = -1;
2737 /* Copy the extra info we tack onto an elf_link_hash_entry. */
2740 elfNN_aarch64_copy_indirect_symbol (struct bfd_link_info *info,
2741 struct elf_link_hash_entry *dir,
2742 struct elf_link_hash_entry *ind)
2744 struct elf_aarch64_link_hash_entry *edir, *eind;
2746 edir = (struct elf_aarch64_link_hash_entry *) dir;
2747 eind = (struct elf_aarch64_link_hash_entry *) ind;
2749 if (eind->dyn_relocs != NULL)
2751 if (edir->dyn_relocs != NULL)
2753 struct elf_dyn_relocs **pp;
2754 struct elf_dyn_relocs *p;
2756 /* Add reloc counts against the indirect sym to the direct sym
2757 list. Merge any entries against the same section. */
2758 for (pp = &eind->dyn_relocs; (p = *pp) != NULL;)
2760 struct elf_dyn_relocs *q;
2762 for (q = edir->dyn_relocs; q != NULL; q = q->next)
2763 if (q->sec == p->sec)
2765 q->pc_count += p->pc_count;
2766 q->count += p->count;
2773 *pp = edir->dyn_relocs;
2776 edir->dyn_relocs = eind->dyn_relocs;
2777 eind->dyn_relocs = NULL;
2780 if (ind->root.type == bfd_link_hash_indirect)
2782 /* Copy over PLT info. */
2783 if (dir->got.refcount <= 0)
2785 edir->got_type = eind->got_type;
2786 eind->got_type = GOT_UNKNOWN;
2790 _bfd_elf_link_hash_copy_indirect (info, dir, ind);
2793 /* Destroy an AArch64 elf linker hash table. */
2796 elfNN_aarch64_link_hash_table_free (bfd *obfd)
2798 struct elf_aarch64_link_hash_table *ret
2799 = (struct elf_aarch64_link_hash_table *) obfd->link.hash;
2801 if (ret->loc_hash_table)
2802 htab_delete (ret->loc_hash_table);
2803 if (ret->loc_hash_memory)
2804 objalloc_free ((struct objalloc *) ret->loc_hash_memory);
2806 bfd_hash_table_free (&ret->stub_hash_table);
2807 _bfd_elf_link_hash_table_free (obfd);
2810 /* Create an AArch64 elf linker hash table. */
2812 static struct bfd_link_hash_table *
2813 elfNN_aarch64_link_hash_table_create (bfd *abfd)
2815 struct elf_aarch64_link_hash_table *ret;
2816 bfd_size_type amt = sizeof (struct elf_aarch64_link_hash_table);
2818 ret = bfd_zmalloc (amt);
2822 if (!_bfd_elf_link_hash_table_init
2823 (&ret->root, abfd, elfNN_aarch64_link_hash_newfunc,
2824 sizeof (struct elf_aarch64_link_hash_entry), AARCH64_ELF_DATA))
2830 ret->plt_header_size = PLT_ENTRY_SIZE;
2831 ret->plt_entry_size = PLT_SMALL_ENTRY_SIZE;
2833 ret->dt_tlsdesc_got = (bfd_vma) - 1;
2835 if (!bfd_hash_table_init (&ret->stub_hash_table, stub_hash_newfunc,
2836 sizeof (struct elf_aarch64_stub_hash_entry)))
2838 _bfd_elf_link_hash_table_free (abfd);
2842 ret->loc_hash_table = htab_try_create (1024,
2843 elfNN_aarch64_local_htab_hash,
2844 elfNN_aarch64_local_htab_eq,
2846 ret->loc_hash_memory = objalloc_create ();
2847 if (!ret->loc_hash_table || !ret->loc_hash_memory)
2849 elfNN_aarch64_link_hash_table_free (abfd);
2852 ret->root.root.hash_table_free = elfNN_aarch64_link_hash_table_free;
2854 return &ret->root.root;
2857 /* Perform relocation R_TYPE. Returns TRUE upon success, FALSE otherwise. */
2860 aarch64_relocate (unsigned int r_type, bfd *input_bfd, asection *input_section,
2861 bfd_vma offset, bfd_vma value)
2863 reloc_howto_type *howto;
2866 howto = elfNN_aarch64_howto_from_type (input_bfd, r_type);
2867 place = (input_section->output_section->vma + input_section->output_offset
2870 r_type = elfNN_aarch64_bfd_reloc_from_type (input_bfd, r_type);
2871 value = _bfd_aarch64_elf_resolve_relocation (r_type, place, value, 0, FALSE);
2872 return _bfd_aarch64_elf_put_addend (input_bfd,
2873 input_section->contents + offset, r_type,
2874 howto, value) == bfd_reloc_ok;
2877 static enum elf_aarch64_stub_type
2878 aarch64_select_branch_stub (bfd_vma value, bfd_vma place)
2880 if (aarch64_valid_for_adrp_p (value, place))
2881 return aarch64_stub_adrp_branch;
2882 return aarch64_stub_long_branch;
2885 /* Determine the type of stub needed, if any, for a call. */
2887 static enum elf_aarch64_stub_type
2888 aarch64_type_of_stub (asection *input_sec,
2889 const Elf_Internal_Rela *rel,
2891 unsigned char st_type,
2892 bfd_vma destination)
2895 bfd_signed_vma branch_offset;
2896 unsigned int r_type;
2897 enum elf_aarch64_stub_type stub_type = aarch64_stub_none;
2899 if (st_type != STT_FUNC
2900 && (sym_sec == input_sec))
2903 /* Determine where the call point is. */
2904 location = (input_sec->output_offset
2905 + input_sec->output_section->vma + rel->r_offset);
2907 branch_offset = (bfd_signed_vma) (destination - location);
2909 r_type = ELFNN_R_TYPE (rel->r_info);
2911 /* We don't want to redirect any old unconditional jump in this way,
2912 only one which is being used for a sibcall, where it is
2913 acceptable for the IP0 and IP1 registers to be clobbered. */
2914 if ((r_type == AARCH64_R (CALL26) || r_type == AARCH64_R (JUMP26))
2915 && (branch_offset > AARCH64_MAX_FWD_BRANCH_OFFSET
2916 || branch_offset < AARCH64_MAX_BWD_BRANCH_OFFSET))
2918 stub_type = aarch64_stub_long_branch;
2924 /* Build a name for an entry in the stub hash table. */
2927 elfNN_aarch64_stub_name (const asection *input_section,
2928 const asection *sym_sec,
2929 const struct elf_aarch64_link_hash_entry *hash,
2930 const Elf_Internal_Rela *rel)
2937 len = 8 + 1 + strlen (hash->root.root.root.string) + 1 + 16 + 1;
2938 stub_name = bfd_malloc (len);
2939 if (stub_name != NULL)
2940 snprintf (stub_name, len, "%08x_%s+%" BFD_VMA_FMT "x",
2941 (unsigned int) input_section->id,
2942 hash->root.root.root.string,
2947 len = 8 + 1 + 8 + 1 + 8 + 1 + 16 + 1;
2948 stub_name = bfd_malloc (len);
2949 if (stub_name != NULL)
2950 snprintf (stub_name, len, "%08x_%x:%x+%" BFD_VMA_FMT "x",
2951 (unsigned int) input_section->id,
2952 (unsigned int) sym_sec->id,
2953 (unsigned int) ELFNN_R_SYM (rel->r_info),
2960 /* Return TRUE if symbol H should be hashed in the `.gnu.hash' section. For
2961 executable PLT slots where the executable never takes the address of those
2962 functions, the function symbols are not added to the hash table. */
2965 elf_aarch64_hash_symbol (struct elf_link_hash_entry *h)
2967 if (h->plt.offset != (bfd_vma) -1
2969 && !h->pointer_equality_needed)
2972 return _bfd_elf_hash_symbol (h);
2976 /* Look up an entry in the stub hash. Stub entries are cached because
2977 creating the stub name takes a bit of time. */
2979 static struct elf_aarch64_stub_hash_entry *
2980 elfNN_aarch64_get_stub_entry (const asection *input_section,
2981 const asection *sym_sec,
2982 struct elf_link_hash_entry *hash,
2983 const Elf_Internal_Rela *rel,
2984 struct elf_aarch64_link_hash_table *htab)
2986 struct elf_aarch64_stub_hash_entry *stub_entry;
2987 struct elf_aarch64_link_hash_entry *h =
2988 (struct elf_aarch64_link_hash_entry *) hash;
2989 const asection *id_sec;
2991 if ((input_section->flags & SEC_CODE) == 0)
2994 /* If this input section is part of a group of sections sharing one
2995 stub section, then use the id of the first section in the group.
2996 Stub names need to include a section id, as there may well be
2997 more than one stub used to reach say, printf, and we need to
2998 distinguish between them. */
2999 id_sec = htab->stub_group[input_section->id].link_sec;
3001 if (h != NULL && h->stub_cache != NULL
3002 && h->stub_cache->h == h && h->stub_cache->id_sec == id_sec)
3004 stub_entry = h->stub_cache;
3010 stub_name = elfNN_aarch64_stub_name (id_sec, sym_sec, h, rel);
3011 if (stub_name == NULL)
3014 stub_entry = aarch64_stub_hash_lookup (&htab->stub_hash_table,
3015 stub_name, FALSE, FALSE);
3017 h->stub_cache = stub_entry;
3026 /* Create a stub section. */
3029 _bfd_aarch64_create_stub_section (asection *section,
3030 struct elf_aarch64_link_hash_table *htab)
3036 namelen = strlen (section->name);
3037 len = namelen + sizeof (STUB_SUFFIX);
3038 s_name = bfd_alloc (htab->stub_bfd, len);
3042 memcpy (s_name, section->name, namelen);
3043 memcpy (s_name + namelen, STUB_SUFFIX, sizeof (STUB_SUFFIX));
3044 return (*htab->add_stub_section) (s_name, section);
3048 /* Find or create a stub section for a link section.
3050 Fix or create the stub section used to collect stubs attached to
3051 the specified link section. */
3054 _bfd_aarch64_get_stub_for_link_section (asection *link_section,
3055 struct elf_aarch64_link_hash_table *htab)
3057 if (htab->stub_group[link_section->id].stub_sec == NULL)
3058 htab->stub_group[link_section->id].stub_sec
3059 = _bfd_aarch64_create_stub_section (link_section, htab);
3060 return htab->stub_group[link_section->id].stub_sec;
3064 /* Find or create a stub section in the stub group for an input
3068 _bfd_aarch64_create_or_find_stub_sec (asection *section,
3069 struct elf_aarch64_link_hash_table *htab)
3071 asection *link_sec = htab->stub_group[section->id].link_sec;
3072 return _bfd_aarch64_get_stub_for_link_section (link_sec, htab);
3076 /* Add a new stub entry in the stub group associated with an input
3077 section to the stub hash. Not all fields of the new stub entry are
3080 static struct elf_aarch64_stub_hash_entry *
3081 _bfd_aarch64_add_stub_entry_in_group (const char *stub_name,
3083 struct elf_aarch64_link_hash_table *htab)
3087 struct elf_aarch64_stub_hash_entry *stub_entry;
3089 link_sec = htab->stub_group[section->id].link_sec;
3090 stub_sec = _bfd_aarch64_create_or_find_stub_sec (section, htab);
3092 /* Enter this entry into the linker stub hash table. */
3093 stub_entry = aarch64_stub_hash_lookup (&htab->stub_hash_table, stub_name,
3095 if (stub_entry == NULL)
3097 /* xgettext:c-format */
3098 _bfd_error_handler (_("%pB: cannot create stub entry %s"),
3099 section->owner, stub_name);
3103 stub_entry->stub_sec = stub_sec;
3104 stub_entry->stub_offset = 0;
3105 stub_entry->id_sec = link_sec;
3110 /* Add a new stub entry in the final stub section to the stub hash.
3111 Not all fields of the new stub entry are initialised. */
3113 static struct elf_aarch64_stub_hash_entry *
3114 _bfd_aarch64_add_stub_entry_after (const char *stub_name,
3115 asection *link_section,
3116 struct elf_aarch64_link_hash_table *htab)
3119 struct elf_aarch64_stub_hash_entry *stub_entry;
3121 stub_sec = _bfd_aarch64_get_stub_for_link_section (link_section, htab);
3122 stub_entry = aarch64_stub_hash_lookup (&htab->stub_hash_table, stub_name,
3124 if (stub_entry == NULL)
3126 _bfd_error_handler (_("cannot create stub entry %s"), stub_name);
3130 stub_entry->stub_sec = stub_sec;
3131 stub_entry->stub_offset = 0;
3132 stub_entry->id_sec = link_section;
3139 aarch64_build_one_stub (struct bfd_hash_entry *gen_entry,
3140 void *in_arg ATTRIBUTE_UNUSED)
3142 struct elf_aarch64_stub_hash_entry *stub_entry;
3147 bfd_vma veneered_insn_loc;
3148 bfd_vma veneer_entry_loc;
3149 bfd_signed_vma branch_offset = 0;
3150 unsigned int template_size;
3151 const uint32_t *template;
3154 /* Massage our args to the form they really have. */
3155 stub_entry = (struct elf_aarch64_stub_hash_entry *) gen_entry;
3157 stub_sec = stub_entry->stub_sec;
3159 /* Make a note of the offset within the stubs for this entry. */
3160 stub_entry->stub_offset = stub_sec->size;
3161 loc = stub_sec->contents + stub_entry->stub_offset;
3163 stub_bfd = stub_sec->owner;
3165 /* This is the address of the stub destination. */
3166 sym_value = (stub_entry->target_value
3167 + stub_entry->target_section->output_offset
3168 + stub_entry->target_section->output_section->vma);
3170 if (stub_entry->stub_type == aarch64_stub_long_branch)
3172 bfd_vma place = (stub_entry->stub_offset + stub_sec->output_section->vma
3173 + stub_sec->output_offset);
3175 /* See if we can relax the stub. */
3176 if (aarch64_valid_for_adrp_p (sym_value, place))
3177 stub_entry->stub_type = aarch64_select_branch_stub (sym_value, place);
3180 switch (stub_entry->stub_type)
3182 case aarch64_stub_adrp_branch:
3183 template = aarch64_adrp_branch_stub;
3184 template_size = sizeof (aarch64_adrp_branch_stub);
3186 case aarch64_stub_long_branch:
3187 template = aarch64_long_branch_stub;
3188 template_size = sizeof (aarch64_long_branch_stub);
3190 case aarch64_stub_erratum_835769_veneer:
3191 template = aarch64_erratum_835769_stub;
3192 template_size = sizeof (aarch64_erratum_835769_stub);
3194 case aarch64_stub_erratum_843419_veneer:
3195 template = aarch64_erratum_843419_stub;
3196 template_size = sizeof (aarch64_erratum_843419_stub);
3202 for (i = 0; i < (template_size / sizeof template[0]); i++)
3204 bfd_putl32 (template[i], loc);
3208 template_size = (template_size + 7) & ~7;
3209 stub_sec->size += template_size;
3211 switch (stub_entry->stub_type)
3213 case aarch64_stub_adrp_branch:
3214 if (!aarch64_relocate (AARCH64_R (ADR_PREL_PG_HI21), stub_bfd, stub_sec,
3215 stub_entry->stub_offset, sym_value))
3216 /* The stub would not have been relaxed if the offset was out
3220 if (!aarch64_relocate (AARCH64_R (ADD_ABS_LO12_NC), stub_bfd, stub_sec,
3221 stub_entry->stub_offset + 4, sym_value))
3225 case aarch64_stub_long_branch:
3226 /* We want the value relative to the address 12 bytes back from the
3228 if (!aarch64_relocate (AARCH64_R (PRELNN), stub_bfd, stub_sec,
3229 stub_entry->stub_offset + 16, sym_value + 12))
3233 case aarch64_stub_erratum_835769_veneer:
3234 veneered_insn_loc = stub_entry->target_section->output_section->vma
3235 + stub_entry->target_section->output_offset
3236 + stub_entry->target_value;
3237 veneer_entry_loc = stub_entry->stub_sec->output_section->vma
3238 + stub_entry->stub_sec->output_offset
3239 + stub_entry->stub_offset;
3240 branch_offset = veneered_insn_loc - veneer_entry_loc;
3241 branch_offset >>= 2;
3242 branch_offset &= 0x3ffffff;
3243 bfd_putl32 (stub_entry->veneered_insn,
3244 stub_sec->contents + stub_entry->stub_offset);
3245 bfd_putl32 (template[1] | branch_offset,
3246 stub_sec->contents + stub_entry->stub_offset + 4);
3249 case aarch64_stub_erratum_843419_veneer:
3250 if (!aarch64_relocate (AARCH64_R (JUMP26), stub_bfd, stub_sec,
3251 stub_entry->stub_offset + 4, sym_value + 4))
3262 /* As above, but don't actually build the stub. Just bump offset so
3263 we know stub section sizes. */
3266 aarch64_size_one_stub (struct bfd_hash_entry *gen_entry,
3267 void *in_arg ATTRIBUTE_UNUSED)
3269 struct elf_aarch64_stub_hash_entry *stub_entry;
3272 /* Massage our args to the form they really have. */
3273 stub_entry = (struct elf_aarch64_stub_hash_entry *) gen_entry;
3275 switch (stub_entry->stub_type)
3277 case aarch64_stub_adrp_branch:
3278 size = sizeof (aarch64_adrp_branch_stub);
3280 case aarch64_stub_long_branch:
3281 size = sizeof (aarch64_long_branch_stub);
3283 case aarch64_stub_erratum_835769_veneer:
3284 size = sizeof (aarch64_erratum_835769_stub);
3286 case aarch64_stub_erratum_843419_veneer:
3287 size = sizeof (aarch64_erratum_843419_stub);
3293 size = (size + 7) & ~7;
3294 stub_entry->stub_sec->size += size;
3298 /* External entry points for sizing and building linker stubs. */
3300 /* Set up various things so that we can make a list of input sections
3301 for each output section included in the link. Returns -1 on error,
3302 0 when no stubs will be needed, and 1 on success. */
3305 elfNN_aarch64_setup_section_lists (bfd *output_bfd,
3306 struct bfd_link_info *info)
3309 unsigned int bfd_count;
3310 unsigned int top_id, top_index;
3312 asection **input_list, **list;
3314 struct elf_aarch64_link_hash_table *htab =
3315 elf_aarch64_hash_table (info);
3317 if (!is_elf_hash_table (htab))
3320 /* Count the number of input BFDs and find the top input section id. */
3321 for (input_bfd = info->input_bfds, bfd_count = 0, top_id = 0;
3322 input_bfd != NULL; input_bfd = input_bfd->link.next)
3325 for (section = input_bfd->sections;
3326 section != NULL; section = section->next)
3328 if (top_id < section->id)
3329 top_id = section->id;
3332 htab->bfd_count = bfd_count;
3334 amt = sizeof (struct map_stub) * (top_id + 1);
3335 htab->stub_group = bfd_zmalloc (amt);
3336 if (htab->stub_group == NULL)
3339 /* We can't use output_bfd->section_count here to find the top output
3340 section index as some sections may have been removed, and
3341 _bfd_strip_section_from_output doesn't renumber the indices. */
3342 for (section = output_bfd->sections, top_index = 0;
3343 section != NULL; section = section->next)
3345 if (top_index < section->index)
3346 top_index = section->index;
3349 htab->top_index = top_index;
3350 amt = sizeof (asection *) * (top_index + 1);
3351 input_list = bfd_malloc (amt);
3352 htab->input_list = input_list;
3353 if (input_list == NULL)
3356 /* For sections we aren't interested in, mark their entries with a
3357 value we can check later. */
3358 list = input_list + top_index;
3360 *list = bfd_abs_section_ptr;
3361 while (list-- != input_list);
3363 for (section = output_bfd->sections;
3364 section != NULL; section = section->next)
3366 if ((section->flags & SEC_CODE) != 0)
3367 input_list[section->index] = NULL;
3373 /* Used by elfNN_aarch64_next_input_section and group_sections. */
3374 #define PREV_SEC(sec) (htab->stub_group[(sec)->id].link_sec)
3376 /* The linker repeatedly calls this function for each input section,
3377 in the order that input sections are linked into output sections.
3378 Build lists of input sections to determine groupings between which
3379 we may insert linker stubs. */
3382 elfNN_aarch64_next_input_section (struct bfd_link_info *info, asection *isec)
3384 struct elf_aarch64_link_hash_table *htab =
3385 elf_aarch64_hash_table (info);
3387 if (isec->output_section->index <= htab->top_index)
3389 asection **list = htab->input_list + isec->output_section->index;
3391 if (*list != bfd_abs_section_ptr)
3393 /* Steal the link_sec pointer for our list. */
3394 /* This happens to make the list in reverse order,
3395 which is what we want. */
3396 PREV_SEC (isec) = *list;
3402 /* See whether we can group stub sections together. Grouping stub
3403 sections may result in fewer stubs. More importantly, we need to
3404 put all .init* and .fini* stubs at the beginning of the .init or
3405 .fini output sections respectively, because glibc splits the
3406 _init and _fini functions into multiple parts. Putting a stub in
3407 the middle of a function is not a good idea. */
3410 group_sections (struct elf_aarch64_link_hash_table *htab,
3411 bfd_size_type stub_group_size,
3412 bfd_boolean stubs_always_before_branch)
3414 asection **list = htab->input_list + htab->top_index;
3418 asection *tail = *list;
3420 if (tail == bfd_abs_section_ptr)
3423 while (tail != NULL)
3427 bfd_size_type total;
3431 while ((prev = PREV_SEC (curr)) != NULL
3432 && ((total += curr->output_offset - prev->output_offset)
3436 /* OK, the size from the start of CURR to the end is less
3437 than stub_group_size and thus can be handled by one stub
3438 section. (Or the tail section is itself larger than
3439 stub_group_size, in which case we may be toast.)
3440 We should really be keeping track of the total size of
3441 stubs added here, as stubs contribute to the final output
3445 prev = PREV_SEC (tail);
3446 /* Set up this stub group. */
3447 htab->stub_group[tail->id].link_sec = curr;
3449 while (tail != curr && (tail = prev) != NULL);
3451 /* But wait, there's more! Input sections up to stub_group_size
3452 bytes before the stub section can be handled by it too. */
3453 if (!stubs_always_before_branch)
3457 && ((total += tail->output_offset - prev->output_offset)
3461 prev = PREV_SEC (tail);
3462 htab->stub_group[tail->id].link_sec = curr;
3468 while (list-- != htab->input_list);
3470 free (htab->input_list);
3475 #define AARCH64_BITS(x, pos, n) (((x) >> (pos)) & ((1 << (n)) - 1))
3477 #define AARCH64_RT(insn) AARCH64_BITS (insn, 0, 5)
3478 #define AARCH64_RT2(insn) AARCH64_BITS (insn, 10, 5)
3479 #define AARCH64_RA(insn) AARCH64_BITS (insn, 10, 5)
3480 #define AARCH64_RD(insn) AARCH64_BITS (insn, 0, 5)
3481 #define AARCH64_RN(insn) AARCH64_BITS (insn, 5, 5)
3482 #define AARCH64_RM(insn) AARCH64_BITS (insn, 16, 5)
3484 #define AARCH64_MAC(insn) (((insn) & 0xff000000) == 0x9b000000)
3485 #define AARCH64_BIT(insn, n) AARCH64_BITS (insn, n, 1)
3486 #define AARCH64_OP31(insn) AARCH64_BITS (insn, 21, 3)
3487 #define AARCH64_ZR 0x1f
3489 /* All ld/st ops. See C4-182 of the ARM ARM. The encoding space for
3490 LD_PCREL, LDST_RO, LDST_UI and LDST_UIMM cover prefetch ops. */
3492 #define AARCH64_LD(insn) (AARCH64_BIT (insn, 22) == 1)
3493 #define AARCH64_LDST(insn) (((insn) & 0x0a000000) == 0x08000000)
3494 #define AARCH64_LDST_EX(insn) (((insn) & 0x3f000000) == 0x08000000)
3495 #define AARCH64_LDST_PCREL(insn) (((insn) & 0x3b000000) == 0x18000000)
3496 #define AARCH64_LDST_NAP(insn) (((insn) & 0x3b800000) == 0x28000000)
3497 #define AARCH64_LDSTP_PI(insn) (((insn) & 0x3b800000) == 0x28800000)
3498 #define AARCH64_LDSTP_O(insn) (((insn) & 0x3b800000) == 0x29000000)
3499 #define AARCH64_LDSTP_PRE(insn) (((insn) & 0x3b800000) == 0x29800000)
3500 #define AARCH64_LDST_UI(insn) (((insn) & 0x3b200c00) == 0x38000000)
3501 #define AARCH64_LDST_PIIMM(insn) (((insn) & 0x3b200c00) == 0x38000400)
3502 #define AARCH64_LDST_U(insn) (((insn) & 0x3b200c00) == 0x38000800)
3503 #define AARCH64_LDST_PREIMM(insn) (((insn) & 0x3b200c00) == 0x38000c00)
3504 #define AARCH64_LDST_RO(insn) (((insn) & 0x3b200c00) == 0x38200800)
3505 #define AARCH64_LDST_UIMM(insn) (((insn) & 0x3b000000) == 0x39000000)
3506 #define AARCH64_LDST_SIMD_M(insn) (((insn) & 0xbfbf0000) == 0x0c000000)
3507 #define AARCH64_LDST_SIMD_M_PI(insn) (((insn) & 0xbfa00000) == 0x0c800000)
3508 #define AARCH64_LDST_SIMD_S(insn) (((insn) & 0xbf9f0000) == 0x0d000000)
3509 #define AARCH64_LDST_SIMD_S_PI(insn) (((insn) & 0xbf800000) == 0x0d800000)
3511 /* Classify an INSN if it is indeed a load/store.
3513 Return TRUE if INSN is a LD/ST instruction otherwise return FALSE.
3515 For scalar LD/ST instructions PAIR is FALSE, RT is returned and RT2
3518 For LD/ST pair instructions PAIR is TRUE, RT and RT2 are returned. */
3521 aarch64_mem_op_p (uint32_t insn, unsigned int *rt, unsigned int *rt2,
3522 bfd_boolean *pair, bfd_boolean *load)
3530 /* Bail out quickly if INSN doesn't fall into the load-store
3532 if (!AARCH64_LDST (insn))
3537 if (AARCH64_LDST_EX (insn))
3539 *rt = AARCH64_RT (insn);
3541 if (AARCH64_BIT (insn, 21) == 1)
3544 *rt2 = AARCH64_RT2 (insn);
3546 *load = AARCH64_LD (insn);
3549 else if (AARCH64_LDST_NAP (insn)
3550 || AARCH64_LDSTP_PI (insn)
3551 || AARCH64_LDSTP_O (insn)
3552 || AARCH64_LDSTP_PRE (insn))
3555 *rt = AARCH64_RT (insn);
3556 *rt2 = AARCH64_RT2 (insn);
3557 *load = AARCH64_LD (insn);
3560 else if (AARCH64_LDST_PCREL (insn)
3561 || AARCH64_LDST_UI (insn)
3562 || AARCH64_LDST_PIIMM (insn)
3563 || AARCH64_LDST_U (insn)
3564 || AARCH64_LDST_PREIMM (insn)
3565 || AARCH64_LDST_RO (insn)
3566 || AARCH64_LDST_UIMM (insn))
3568 *rt = AARCH64_RT (insn);
3570 if (AARCH64_LDST_PCREL (insn))
3572 opc = AARCH64_BITS (insn, 22, 2);
3573 v = AARCH64_BIT (insn, 26);
3574 opc_v = opc | (v << 2);
3575 *load = (opc_v == 1 || opc_v == 2 || opc_v == 3
3576 || opc_v == 5 || opc_v == 7);
3579 else if (AARCH64_LDST_SIMD_M (insn)
3580 || AARCH64_LDST_SIMD_M_PI (insn))
3582 *rt = AARCH64_RT (insn);
3583 *load = AARCH64_BIT (insn, 22);
3584 opcode = (insn >> 12) & 0xf;
3611 else if (AARCH64_LDST_SIMD_S (insn)
3612 || AARCH64_LDST_SIMD_S_PI (insn))
3614 *rt = AARCH64_RT (insn);
3615 r = (insn >> 21) & 1;
3616 *load = AARCH64_BIT (insn, 22);
3617 opcode = (insn >> 13) & 0x7;
3629 *rt2 = *rt + (r == 0 ? 2 : 3);
3637 *rt2 = *rt + (r == 0 ? 2 : 3);
3649 /* Return TRUE if INSN is multiply-accumulate. */
3652 aarch64_mlxl_p (uint32_t insn)
3654 uint32_t op31 = AARCH64_OP31 (insn);
3656 if (AARCH64_MAC (insn)
3657 && (op31 == 0 || op31 == 1 || op31 == 5)
3658 /* Exclude MUL instructions which are encoded as a multiple accumulate
3660 && AARCH64_RA (insn) != AARCH64_ZR)
3666 /* Some early revisions of the Cortex-A53 have an erratum (835769) whereby
3667 it is possible for a 64-bit multiply-accumulate instruction to generate an
3668 incorrect result. The details are quite complex and hard to
3669 determine statically, since branches in the code may exist in some
3670 circumstances, but all cases end with a memory (load, store, or
3671 prefetch) instruction followed immediately by the multiply-accumulate
3672 operation. We employ a linker patching technique, by moving the potentially
3673 affected multiply-accumulate instruction into a patch region and replacing
3674 the original instruction with a branch to the patch. This function checks
3675 if INSN_1 is the memory operation followed by a multiply-accumulate
3676 operation (INSN_2). Return TRUE if an erratum sequence is found, FALSE
3677 if INSN_1 and INSN_2 are safe. */
3680 aarch64_erratum_sequence (uint32_t insn_1, uint32_t insn_2)
3690 if (aarch64_mlxl_p (insn_2)
3691 && aarch64_mem_op_p (insn_1, &rt, &rt2, &pair, &load))
3693 /* Any SIMD memory op is independent of the subsequent MLA
3694 by definition of the erratum. */
3695 if (AARCH64_BIT (insn_1, 26))
3698 /* If not SIMD, check for integer memory ops and MLA relationship. */
3699 rn = AARCH64_RN (insn_2);
3700 ra = AARCH64_RA (insn_2);
3701 rm = AARCH64_RM (insn_2);
3703 /* If this is a load and there's a true(RAW) dependency, we are safe
3704 and this is not an erratum sequence. */
3706 (rt == rn || rt == rm || rt == ra
3707 || (pair && (rt2 == rn || rt2 == rm || rt2 == ra))))
3710 /* We conservatively put out stubs for all other cases (including
3718 /* Used to order a list of mapping symbols by address. */
3721 elf_aarch64_compare_mapping (const void *a, const void *b)
3723 const elf_aarch64_section_map *amap = (const elf_aarch64_section_map *) a;
3724 const elf_aarch64_section_map *bmap = (const elf_aarch64_section_map *) b;
3726 if (amap->vma > bmap->vma)
3728 else if (amap->vma < bmap->vma)
3730 else if (amap->type > bmap->type)
3731 /* Ensure results do not depend on the host qsort for objects with
3732 multiple mapping symbols at the same address by sorting on type
3735 else if (amap->type < bmap->type)
3743 _bfd_aarch64_erratum_835769_stub_name (unsigned num_fixes)
3745 char *stub_name = (char *) bfd_malloc
3746 (strlen ("__erratum_835769_veneer_") + 16);
3747 if (stub_name != NULL)
3748 sprintf (stub_name,"__erratum_835769_veneer_%d", num_fixes);
3752 /* Scan for Cortex-A53 erratum 835769 sequence.
3754 Return TRUE else FALSE on abnormal termination. */
3757 _bfd_aarch64_erratum_835769_scan (bfd *input_bfd,
3758 struct bfd_link_info *info,
3759 unsigned int *num_fixes_p)
3762 struct elf_aarch64_link_hash_table *htab = elf_aarch64_hash_table (info);
3763 unsigned int num_fixes = *num_fixes_p;
3768 for (section = input_bfd->sections;
3770 section = section->next)
3772 bfd_byte *contents = NULL;
3773 struct _aarch64_elf_section_data *sec_data;
3776 if (elf_section_type (section) != SHT_PROGBITS
3777 || (elf_section_flags (section) & SHF_EXECINSTR) == 0
3778 || (section->flags & SEC_EXCLUDE) != 0
3779 || (section->sec_info_type == SEC_INFO_TYPE_JUST_SYMS)
3780 || (section->output_section == bfd_abs_section_ptr))
3783 if (elf_section_data (section)->this_hdr.contents != NULL)
3784 contents = elf_section_data (section)->this_hdr.contents;
3785 else if (! bfd_malloc_and_get_section (input_bfd, section, &contents))
3788 sec_data = elf_aarch64_section_data (section);
3790 qsort (sec_data->map, sec_data->mapcount,
3791 sizeof (elf_aarch64_section_map), elf_aarch64_compare_mapping);
3793 for (span = 0; span < sec_data->mapcount; span++)
3795 unsigned int span_start = sec_data->map[span].vma;
3796 unsigned int span_end = ((span == sec_data->mapcount - 1)
3797 ? sec_data->map[0].vma + section->size
3798 : sec_data->map[span + 1].vma);
3800 char span_type = sec_data->map[span].type;
3802 if (span_type == 'd')
3805 for (i = span_start; i + 4 < span_end; i += 4)
3807 uint32_t insn_1 = bfd_getl32 (contents + i);
3808 uint32_t insn_2 = bfd_getl32 (contents + i + 4);
3810 if (aarch64_erratum_sequence (insn_1, insn_2))
3812 struct elf_aarch64_stub_hash_entry *stub_entry;
3813 char *stub_name = _bfd_aarch64_erratum_835769_stub_name (num_fixes);
3817 stub_entry = _bfd_aarch64_add_stub_entry_in_group (stub_name,
3823 stub_entry->stub_type = aarch64_stub_erratum_835769_veneer;
3824 stub_entry->target_section = section;
3825 stub_entry->target_value = i + 4;
3826 stub_entry->veneered_insn = insn_2;
3827 stub_entry->output_name = stub_name;
3832 if (elf_section_data (section)->this_hdr.contents == NULL)
3836 *num_fixes_p = num_fixes;
3842 /* Test if instruction INSN is ADRP. */
3845 _bfd_aarch64_adrp_p (uint32_t insn)
3847 return ((insn & AARCH64_ADRP_OP_MASK) == AARCH64_ADRP_OP);
3851 /* Helper predicate to look for cortex-a53 erratum 843419 sequence 1. */
3854 _bfd_aarch64_erratum_843419_sequence_p (uint32_t insn_1, uint32_t insn_2,
3862 return (aarch64_mem_op_p (insn_2, &rt, &rt2, &pair, &load)
3865 && AARCH64_LDST_UIMM (insn_3)
3866 && AARCH64_RN (insn_3) == AARCH64_RD (insn_1));
3870 /* Test for the presence of Cortex-A53 erratum 843419 instruction sequence.
3872 Return TRUE if section CONTENTS at offset I contains one of the
3873 erratum 843419 sequences, otherwise return FALSE. If a sequence is
3874 seen set P_VENEER_I to the offset of the final LOAD/STORE
3875 instruction in the sequence.
3879 _bfd_aarch64_erratum_843419_p (bfd_byte *contents, bfd_vma vma,
3880 bfd_vma i, bfd_vma span_end,
3881 bfd_vma *p_veneer_i)
3883 uint32_t insn_1 = bfd_getl32 (contents + i);
3885 if (!_bfd_aarch64_adrp_p (insn_1))
3888 if (span_end < i + 12)
3891 uint32_t insn_2 = bfd_getl32 (contents + i + 4);
3892 uint32_t insn_3 = bfd_getl32 (contents + i + 8);
3894 if ((vma & 0xfff) != 0xff8 && (vma & 0xfff) != 0xffc)
3897 if (_bfd_aarch64_erratum_843419_sequence_p (insn_1, insn_2, insn_3))
3899 *p_veneer_i = i + 8;
3903 if (span_end < i + 16)
3906 uint32_t insn_4 = bfd_getl32 (contents + i + 12);
3908 if (_bfd_aarch64_erratum_843419_sequence_p (insn_1, insn_2, insn_4))
3910 *p_veneer_i = i + 12;
3918 /* Resize all stub sections. */
3921 _bfd_aarch64_resize_stubs (struct elf_aarch64_link_hash_table *htab)
3925 /* OK, we've added some stubs. Find out the new size of the
3927 for (section = htab->stub_bfd->sections;
3928 section != NULL; section = section->next)
3930 /* Ignore non-stub sections. */
3931 if (!strstr (section->name, STUB_SUFFIX))
3936 bfd_hash_traverse (&htab->stub_hash_table, aarch64_size_one_stub, htab);
3938 for (section = htab->stub_bfd->sections;
3939 section != NULL; section = section->next)
3941 if (!strstr (section->name, STUB_SUFFIX))
3944 /* Add space for a branch. Add 8 bytes to keep section 8 byte aligned,
3945 as long branch stubs contain a 64-bit address. */
3949 /* Ensure all stub sections have a size which is a multiple of
3950 4096. This is important in order to ensure that the insertion
3951 of stub sections does not in itself move existing code around
3952 in such a way that new errata sequences are created. */
3953 if (htab->fix_erratum_843419)
3955 section->size = BFD_ALIGN (section->size, 0x1000);
3959 /* Construct an erratum 843419 workaround stub name. */
3962 _bfd_aarch64_erratum_843419_stub_name (asection *input_section,
3965 const bfd_size_type len = 8 + 4 + 1 + 8 + 1 + 16 + 1;
3966 char *stub_name = bfd_malloc (len);
3968 if (stub_name != NULL)
3969 snprintf (stub_name, len, "e843419@%04x_%08x_%" BFD_VMA_FMT "x",
3970 input_section->owner->id,
3976 /* Build a stub_entry structure describing an 843419 fixup.
3978 The stub_entry constructed is populated with the bit pattern INSN
3979 of the instruction located at OFFSET within input SECTION.
3981 Returns TRUE on success. */
3984 _bfd_aarch64_erratum_843419_fixup (uint32_t insn,
3985 bfd_vma adrp_offset,
3986 bfd_vma ldst_offset,
3988 struct bfd_link_info *info)
3990 struct elf_aarch64_link_hash_table *htab = elf_aarch64_hash_table (info);
3992 struct elf_aarch64_stub_hash_entry *stub_entry;
3994 stub_name = _bfd_aarch64_erratum_843419_stub_name (section, ldst_offset);
3995 if (stub_name == NULL)
3997 stub_entry = aarch64_stub_hash_lookup (&htab->stub_hash_table, stub_name,
4005 /* We always place an 843419 workaround veneer in the stub section
4006 attached to the input section in which an erratum sequence has
4007 been found. This ensures that later in the link process (in
4008 elfNN_aarch64_write_section) when we copy the veneered
4009 instruction from the input section into the stub section the
4010 copied instruction will have had any relocations applied to it.
4011 If we placed workaround veneers in any other stub section then we
4012 could not assume that all relocations have been processed on the
4013 corresponding input section at the point we output the stub
4016 stub_entry = _bfd_aarch64_add_stub_entry_after (stub_name, section, htab);
4017 if (stub_entry == NULL)
4023 stub_entry->adrp_offset = adrp_offset;
4024 stub_entry->target_value = ldst_offset;
4025 stub_entry->target_section = section;
4026 stub_entry->stub_type = aarch64_stub_erratum_843419_veneer;
4027 stub_entry->veneered_insn = insn;
4028 stub_entry->output_name = stub_name;
4034 /* Scan an input section looking for the signature of erratum 843419.
4036 Scans input SECTION in INPUT_BFD looking for erratum 843419
4037 signatures, for each signature found a stub_entry is created
4038 describing the location of the erratum for subsequent fixup.
4040 Return TRUE on successful scan, FALSE on failure to scan.
4044 _bfd_aarch64_erratum_843419_scan (bfd *input_bfd, asection *section,
4045 struct bfd_link_info *info)
4047 struct elf_aarch64_link_hash_table *htab = elf_aarch64_hash_table (info);
4052 if (elf_section_type (section) != SHT_PROGBITS
4053 || (elf_section_flags (section) & SHF_EXECINSTR) == 0
4054 || (section->flags & SEC_EXCLUDE) != 0
4055 || (section->sec_info_type == SEC_INFO_TYPE_JUST_SYMS)
4056 || (section->output_section == bfd_abs_section_ptr))
4061 bfd_byte *contents = NULL;
4062 struct _aarch64_elf_section_data *sec_data;
4065 if (elf_section_data (section)->this_hdr.contents != NULL)
4066 contents = elf_section_data (section)->this_hdr.contents;
4067 else if (! bfd_malloc_and_get_section (input_bfd, section, &contents))
4070 sec_data = elf_aarch64_section_data (section);
4072 qsort (sec_data->map, sec_data->mapcount,
4073 sizeof (elf_aarch64_section_map), elf_aarch64_compare_mapping);
4075 for (span = 0; span < sec_data->mapcount; span++)
4077 unsigned int span_start = sec_data->map[span].vma;
4078 unsigned int span_end = ((span == sec_data->mapcount - 1)
4079 ? sec_data->map[0].vma + section->size
4080 : sec_data->map[span + 1].vma);
4082 char span_type = sec_data->map[span].type;
4084 if (span_type == 'd')
4087 for (i = span_start; i + 8 < span_end; i += 4)
4089 bfd_vma vma = (section->output_section->vma
4090 + section->output_offset
4094 if (_bfd_aarch64_erratum_843419_p
4095 (contents, vma, i, span_end, &veneer_i))
4097 uint32_t insn = bfd_getl32 (contents + veneer_i);
4099 if (!_bfd_aarch64_erratum_843419_fixup (insn, i, veneer_i,
4106 if (elf_section_data (section)->this_hdr.contents == NULL)
4115 /* Determine and set the size of the stub section for a final link.
4117 The basic idea here is to examine all the relocations looking for
4118 PC-relative calls to a target that is unreachable with a "bl"
4122 elfNN_aarch64_size_stubs (bfd *output_bfd,
4124 struct bfd_link_info *info,
4125 bfd_signed_vma group_size,
4126 asection * (*add_stub_section) (const char *,
4128 void (*layout_sections_again) (void))
4130 bfd_size_type stub_group_size;
4131 bfd_boolean stubs_always_before_branch;
4132 bfd_boolean stub_changed = FALSE;
4133 struct elf_aarch64_link_hash_table *htab = elf_aarch64_hash_table (info);
4134 unsigned int num_erratum_835769_fixes = 0;
4136 /* Propagate mach to stub bfd, because it may not have been
4137 finalized when we created stub_bfd. */
4138 bfd_set_arch_mach (stub_bfd, bfd_get_arch (output_bfd),
4139 bfd_get_mach (output_bfd));
4141 /* Stash our params away. */
4142 htab->stub_bfd = stub_bfd;
4143 htab->add_stub_section = add_stub_section;
4144 htab->layout_sections_again = layout_sections_again;
4145 stubs_always_before_branch = group_size < 0;
4147 stub_group_size = -group_size;
4149 stub_group_size = group_size;
4151 if (stub_group_size == 1)
4153 /* Default values. */
4154 /* AArch64 branch range is +-128MB. The value used is 1MB less. */
4155 stub_group_size = 127 * 1024 * 1024;
4158 group_sections (htab, stub_group_size, stubs_always_before_branch);
4160 (*htab->layout_sections_again) ();
4162 if (htab->fix_erratum_835769)
4166 for (input_bfd = info->input_bfds;
4167 input_bfd != NULL; input_bfd = input_bfd->link.next)
4168 if (!_bfd_aarch64_erratum_835769_scan (input_bfd, info,
4169 &num_erratum_835769_fixes))
4172 _bfd_aarch64_resize_stubs (htab);
4173 (*htab->layout_sections_again) ();
4176 if (htab->fix_erratum_843419)
4180 for (input_bfd = info->input_bfds;
4182 input_bfd = input_bfd->link.next)
4186 for (section = input_bfd->sections;
4188 section = section->next)
4189 if (!_bfd_aarch64_erratum_843419_scan (input_bfd, section, info))
4193 _bfd_aarch64_resize_stubs (htab);
4194 (*htab->layout_sections_again) ();
4201 for (input_bfd = info->input_bfds;
4202 input_bfd != NULL; input_bfd = input_bfd->link.next)
4204 Elf_Internal_Shdr *symtab_hdr;
4206 Elf_Internal_Sym *local_syms = NULL;
4208 /* We'll need the symbol table in a second. */
4209 symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
4210 if (symtab_hdr->sh_info == 0)
4213 /* Walk over each section attached to the input bfd. */
4214 for (section = input_bfd->sections;
4215 section != NULL; section = section->next)
4217 Elf_Internal_Rela *internal_relocs, *irelaend, *irela;
4219 /* If there aren't any relocs, then there's nothing more
4221 if ((section->flags & SEC_RELOC) == 0
4222 || section->reloc_count == 0
4223 || (section->flags & SEC_CODE) == 0)
4226 /* If this section is a link-once section that will be
4227 discarded, then don't create any stubs. */
4228 if (section->output_section == NULL
4229 || section->output_section->owner != output_bfd)
4232 /* Get the relocs. */
4234 = _bfd_elf_link_read_relocs (input_bfd, section, NULL,
4235 NULL, info->keep_memory);
4236 if (internal_relocs == NULL)
4237 goto error_ret_free_local;
4239 /* Now examine each relocation. */
4240 irela = internal_relocs;
4241 irelaend = irela + section->reloc_count;
4242 for (; irela < irelaend; irela++)
4244 unsigned int r_type, r_indx;
4245 enum elf_aarch64_stub_type stub_type;
4246 struct elf_aarch64_stub_hash_entry *stub_entry;
4249 bfd_vma destination;
4250 struct elf_aarch64_link_hash_entry *hash;
4251 const char *sym_name;
4253 const asection *id_sec;
4254 unsigned char st_type;
4257 r_type = ELFNN_R_TYPE (irela->r_info);
4258 r_indx = ELFNN_R_SYM (irela->r_info);
4260 if (r_type >= (unsigned int) R_AARCH64_end)
4262 bfd_set_error (bfd_error_bad_value);
4263 error_ret_free_internal:
4264 if (elf_section_data (section)->relocs == NULL)
4265 free (internal_relocs);
4266 goto error_ret_free_local;
4269 /* Only look for stubs on unconditional branch and
4270 branch and link instructions. */
4271 if (r_type != (unsigned int) AARCH64_R (CALL26)
4272 && r_type != (unsigned int) AARCH64_R (JUMP26))
4275 /* Now determine the call target, its name, value,
4282 if (r_indx < symtab_hdr->sh_info)
4284 /* It's a local symbol. */
4285 Elf_Internal_Sym *sym;
4286 Elf_Internal_Shdr *hdr;
4288 if (local_syms == NULL)
4291 = (Elf_Internal_Sym *) symtab_hdr->contents;
4292 if (local_syms == NULL)
4294 = bfd_elf_get_elf_syms (input_bfd, symtab_hdr,
4295 symtab_hdr->sh_info, 0,
4297 if (local_syms == NULL)
4298 goto error_ret_free_internal;
4301 sym = local_syms + r_indx;
4302 hdr = elf_elfsections (input_bfd)[sym->st_shndx];
4303 sym_sec = hdr->bfd_section;
4305 /* This is an undefined symbol. It can never
4309 if (ELF_ST_TYPE (sym->st_info) != STT_SECTION)
4310 sym_value = sym->st_value;
4311 destination = (sym_value + irela->r_addend
4312 + sym_sec->output_offset
4313 + sym_sec->output_section->vma);
4314 st_type = ELF_ST_TYPE (sym->st_info);
4316 = bfd_elf_string_from_elf_section (input_bfd,
4317 symtab_hdr->sh_link,
4324 e_indx = r_indx - symtab_hdr->sh_info;
4325 hash = ((struct elf_aarch64_link_hash_entry *)
4326 elf_sym_hashes (input_bfd)[e_indx]);
4328 while (hash->root.root.type == bfd_link_hash_indirect
4329 || hash->root.root.type == bfd_link_hash_warning)
4330 hash = ((struct elf_aarch64_link_hash_entry *)
4331 hash->root.root.u.i.link);
4333 if (hash->root.root.type == bfd_link_hash_defined
4334 || hash->root.root.type == bfd_link_hash_defweak)
4336 struct elf_aarch64_link_hash_table *globals =
4337 elf_aarch64_hash_table (info);
4338 sym_sec = hash->root.root.u.def.section;
4339 sym_value = hash->root.root.u.def.value;
4340 /* For a destination in a shared library,
4341 use the PLT stub as target address to
4342 decide whether a branch stub is
4344 if (globals->root.splt != NULL && hash != NULL
4345 && hash->root.plt.offset != (bfd_vma) - 1)
4347 sym_sec = globals->root.splt;
4348 sym_value = hash->root.plt.offset;
4349 if (sym_sec->output_section != NULL)
4350 destination = (sym_value
4351 + sym_sec->output_offset
4353 sym_sec->output_section->vma);
4355 else if (sym_sec->output_section != NULL)
4356 destination = (sym_value + irela->r_addend
4357 + sym_sec->output_offset
4358 + sym_sec->output_section->vma);
4360 else if (hash->root.root.type == bfd_link_hash_undefined
4361 || (hash->root.root.type
4362 == bfd_link_hash_undefweak))
4364 /* For a shared library, use the PLT stub as
4365 target address to decide whether a long
4366 branch stub is needed.
4367 For absolute code, they cannot be handled. */
4368 struct elf_aarch64_link_hash_table *globals =
4369 elf_aarch64_hash_table (info);
4371 if (globals->root.splt != NULL && hash != NULL
4372 && hash->root.plt.offset != (bfd_vma) - 1)
4374 sym_sec = globals->root.splt;
4375 sym_value = hash->root.plt.offset;
4376 if (sym_sec->output_section != NULL)
4377 destination = (sym_value
4378 + sym_sec->output_offset
4380 sym_sec->output_section->vma);
4387 bfd_set_error (bfd_error_bad_value);
4388 goto error_ret_free_internal;
4390 st_type = ELF_ST_TYPE (hash->root.type);
4391 sym_name = hash->root.root.root.string;
4394 /* Determine what (if any) linker stub is needed. */
4395 stub_type = aarch64_type_of_stub (section, irela, sym_sec,
4396 st_type, destination);
4397 if (stub_type == aarch64_stub_none)
4400 /* Support for grouping stub sections. */
4401 id_sec = htab->stub_group[section->id].link_sec;
4403 /* Get the name of this stub. */
4404 stub_name = elfNN_aarch64_stub_name (id_sec, sym_sec, hash,
4407 goto error_ret_free_internal;
4410 aarch64_stub_hash_lookup (&htab->stub_hash_table,
4411 stub_name, FALSE, FALSE);
4412 if (stub_entry != NULL)
4414 /* The proper stub has already been created. */
4416 /* Always update this stub's target since it may have
4417 changed after layout. */
4418 stub_entry->target_value = sym_value + irela->r_addend;
4422 stub_entry = _bfd_aarch64_add_stub_entry_in_group
4423 (stub_name, section, htab);
4424 if (stub_entry == NULL)
4427 goto error_ret_free_internal;
4430 stub_entry->target_value = sym_value + irela->r_addend;
4431 stub_entry->target_section = sym_sec;
4432 stub_entry->stub_type = stub_type;
4433 stub_entry->h = hash;
4434 stub_entry->st_type = st_type;
4436 if (sym_name == NULL)
4437 sym_name = "unnamed";
4438 len = sizeof (STUB_ENTRY_NAME) + strlen (sym_name);
4439 stub_entry->output_name = bfd_alloc (htab->stub_bfd, len);
4440 if (stub_entry->output_name == NULL)
4443 goto error_ret_free_internal;
4446 snprintf (stub_entry->output_name, len, STUB_ENTRY_NAME,
4449 stub_changed = TRUE;
4452 /* We're done with the internal relocs, free them. */
4453 if (elf_section_data (section)->relocs == NULL)
4454 free (internal_relocs);
4461 _bfd_aarch64_resize_stubs (htab);
4463 /* Ask the linker to do its stuff. */
4464 (*htab->layout_sections_again) ();
4465 stub_changed = FALSE;
4470 error_ret_free_local:
4474 /* Build all the stubs associated with the current output file. The
4475 stubs are kept in a hash table attached to the main linker hash
4476 table. We also set up the .plt entries for statically linked PIC
4477 functions here. This function is called via aarch64_elf_finish in the
4481 elfNN_aarch64_build_stubs (struct bfd_link_info *info)
4484 struct bfd_hash_table *table;
4485 struct elf_aarch64_link_hash_table *htab;
4487 htab = elf_aarch64_hash_table (info);
4489 for (stub_sec = htab->stub_bfd->sections;
4490 stub_sec != NULL; stub_sec = stub_sec->next)
4494 /* Ignore non-stub sections. */
4495 if (!strstr (stub_sec->name, STUB_SUFFIX))
4498 /* Allocate memory to hold the linker stubs. */
4499 size = stub_sec->size;
4500 stub_sec->contents = bfd_zalloc (htab->stub_bfd, size);
4501 if (stub_sec->contents == NULL && size != 0)
4505 /* Add a branch around the stub section, and a nop, to keep it 8 byte
4506 aligned, as long branch stubs contain a 64-bit address. */
4507 bfd_putl32 (0x14000000 | (size >> 2), stub_sec->contents);
4508 bfd_putl32 (INSN_NOP, stub_sec->contents + 4);
4509 stub_sec->size += 8;
4512 /* Build the stubs as directed by the stub hash table. */
4513 table = &htab->stub_hash_table;
4514 bfd_hash_traverse (table, aarch64_build_one_stub, info);
4520 /* Add an entry to the code/data map for section SEC. */
4523 elfNN_aarch64_section_map_add (asection *sec, char type, bfd_vma vma)
4525 struct _aarch64_elf_section_data *sec_data =
4526 elf_aarch64_section_data (sec);
4527 unsigned int newidx;
4529 if (sec_data->map == NULL)
4531 sec_data->map = bfd_malloc (sizeof (elf_aarch64_section_map));
4532 sec_data->mapcount = 0;
4533 sec_data->mapsize = 1;
4536 newidx = sec_data->mapcount++;
4538 if (sec_data->mapcount > sec_data->mapsize)
4540 sec_data->mapsize *= 2;
4541 sec_data->map = bfd_realloc_or_free
4542 (sec_data->map, sec_data->mapsize * sizeof (elf_aarch64_section_map));
4547 sec_data->map[newidx].vma = vma;
4548 sec_data->map[newidx].type = type;
4553 /* Initialise maps of insn/data for input BFDs. */
4555 bfd_elfNN_aarch64_init_maps (bfd *abfd)
4557 Elf_Internal_Sym *isymbuf;
4558 Elf_Internal_Shdr *hdr;
4559 unsigned int i, localsyms;
4561 /* Make sure that we are dealing with an AArch64 elf binary. */
4562 if (!is_aarch64_elf (abfd))
4565 if ((abfd->flags & DYNAMIC) != 0)
4568 hdr = &elf_symtab_hdr (abfd);
4569 localsyms = hdr->sh_info;
4571 /* Obtain a buffer full of symbols for this BFD. The hdr->sh_info field
4572 should contain the number of local symbols, which should come before any
4573 global symbols. Mapping symbols are always local. */
4574 isymbuf = bfd_elf_get_elf_syms (abfd, hdr, localsyms, 0, NULL, NULL, NULL);
4576 /* No internal symbols read? Skip this BFD. */
4577 if (isymbuf == NULL)
4580 for (i = 0; i < localsyms; i++)
4582 Elf_Internal_Sym *isym = &isymbuf[i];
4583 asection *sec = bfd_section_from_elf_index (abfd, isym->st_shndx);
4586 if (sec != NULL && ELF_ST_BIND (isym->st_info) == STB_LOCAL)
4588 name = bfd_elf_string_from_elf_section (abfd,
4592 if (bfd_is_aarch64_special_symbol_name
4593 (name, BFD_AARCH64_SPECIAL_SYM_TYPE_MAP))
4594 elfNN_aarch64_section_map_add (sec, name[1], isym->st_value);
4599 /* Set option values needed during linking. */
4601 bfd_elfNN_aarch64_set_options (struct bfd *output_bfd,
4602 struct bfd_link_info *link_info,
4604 int no_wchar_warn, int pic_veneer,
4605 int fix_erratum_835769,
4606 int fix_erratum_843419,
4607 int no_apply_dynamic_relocs)
4609 struct elf_aarch64_link_hash_table *globals;
4611 globals = elf_aarch64_hash_table (link_info);
4612 globals->pic_veneer = pic_veneer;
4613 globals->fix_erratum_835769 = fix_erratum_835769;
4614 globals->fix_erratum_843419 = fix_erratum_843419;
4615 globals->fix_erratum_843419_adr = TRUE;
4616 globals->no_apply_dynamic_relocs = no_apply_dynamic_relocs;
4618 BFD_ASSERT (is_aarch64_elf (output_bfd));
4619 elf_aarch64_tdata (output_bfd)->no_enum_size_warning = no_enum_warn;
4620 elf_aarch64_tdata (output_bfd)->no_wchar_size_warning = no_wchar_warn;
4624 aarch64_calculate_got_entry_vma (struct elf_link_hash_entry *h,
4625 struct elf_aarch64_link_hash_table
4626 *globals, struct bfd_link_info *info,
4627 bfd_vma value, bfd *output_bfd,
4628 bfd_boolean *unresolved_reloc_p)
4630 bfd_vma off = (bfd_vma) - 1;
4631 asection *basegot = globals->root.sgot;
4632 bfd_boolean dyn = globals->root.dynamic_sections_created;
4636 BFD_ASSERT (basegot != NULL);
4637 off = h->got.offset;
4638 BFD_ASSERT (off != (bfd_vma) - 1);
4639 if (!WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, bfd_link_pic (info), h)
4640 || (bfd_link_pic (info)
4641 && SYMBOL_REFERENCES_LOCAL (info, h))
4642 || (ELF_ST_VISIBILITY (h->other)
4643 && h->root.type == bfd_link_hash_undefweak))
4645 /* This is actually a static link, or it is a -Bsymbolic link
4646 and the symbol is defined locally. We must initialize this
4647 entry in the global offset table. Since the offset must
4648 always be a multiple of 8 (4 in the case of ILP32), we use
4649 the least significant bit to record whether we have
4650 initialized it already.
4651 When doing a dynamic link, we create a .rel(a).got relocation
4652 entry to initialize the value. This is done in the
4653 finish_dynamic_symbol routine. */
4658 bfd_put_NN (output_bfd, value, basegot->contents + off);
4663 *unresolved_reloc_p = FALSE;
4665 off = off + basegot->output_section->vma + basegot->output_offset;
4671 /* Change R_TYPE to a more efficient access model where possible,
4672 return the new reloc type. */
4674 static bfd_reloc_code_real_type
4675 aarch64_tls_transition_without_check (bfd_reloc_code_real_type r_type,
4676 struct elf_link_hash_entry *h)
4678 bfd_boolean is_local = h == NULL;
4682 case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21:
4683 case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21:
4685 ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1
4686 : BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21);
4688 case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21:
4690 ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC
4693 case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19:
4695 ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1
4696 : BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19);
4698 case BFD_RELOC_AARCH64_TLSDESC_LDR:
4700 ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC
4701 : BFD_RELOC_AARCH64_NONE);
4703 case BFD_RELOC_AARCH64_TLSDESC_OFF_G0_NC:
4705 ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1_NC
4706 : BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G0_NC);
4708 case BFD_RELOC_AARCH64_TLSDESC_OFF_G1:
4710 ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G2
4711 : BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G1);
4713 case BFD_RELOC_AARCH64_TLSDESC_LDNN_LO12_NC:
4714 case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC:
4716 ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC
4717 : BFD_RELOC_AARCH64_TLSIE_LDNN_GOTTPREL_LO12_NC);
4719 case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21:
4720 return is_local ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1 : r_type;
4722 case BFD_RELOC_AARCH64_TLSIE_LDNN_GOTTPREL_LO12_NC:
4723 return is_local ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC : r_type;
4725 case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19:
4728 case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21:
4730 ? BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_HI12
4731 : BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19);
4733 case BFD_RELOC_AARCH64_TLSDESC_ADD:
4734 case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12:
4735 case BFD_RELOC_AARCH64_TLSDESC_CALL:
4736 /* Instructions with these relocations will become NOPs. */
4737 return BFD_RELOC_AARCH64_NONE;
4739 case BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC:
4740 case BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21:
4741 case BFD_RELOC_AARCH64_TLSLD_ADR_PREL21:
4742 return is_local ? BFD_RELOC_AARCH64_NONE : r_type;
4745 case BFD_RELOC_AARCH64_TLSGD_MOVW_G0_NC:
4747 ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1_NC
4748 : BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G0_NC;
4750 case BFD_RELOC_AARCH64_TLSGD_MOVW_G1:
4752 ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G2
4753 : BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G1;
4764 aarch64_reloc_got_type (bfd_reloc_code_real_type r_type)
4768 case BFD_RELOC_AARCH64_ADR_GOT_PAGE:
4769 case BFD_RELOC_AARCH64_GOT_LD_PREL19:
4770 case BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14:
4771 case BFD_RELOC_AARCH64_LD32_GOT_LO12_NC:
4772 case BFD_RELOC_AARCH64_LD64_GOTOFF_LO15:
4773 case BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15:
4774 case BFD_RELOC_AARCH64_LD64_GOT_LO12_NC:
4775 case BFD_RELOC_AARCH64_MOVW_GOTOFF_G0_NC:
4776 case BFD_RELOC_AARCH64_MOVW_GOTOFF_G1:
4779 case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC:
4780 case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21:
4781 case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21:
4782 case BFD_RELOC_AARCH64_TLSGD_MOVW_G0_NC:
4783 case BFD_RELOC_AARCH64_TLSGD_MOVW_G1:
4784 case BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC:
4785 case BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21:
4786 case BFD_RELOC_AARCH64_TLSLD_ADR_PREL21:
4789 case BFD_RELOC_AARCH64_TLSDESC_ADD:
4790 case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12:
4791 case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21:
4792 case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21:
4793 case BFD_RELOC_AARCH64_TLSDESC_CALL:
4794 case BFD_RELOC_AARCH64_TLSDESC_LD32_LO12_NC:
4795 case BFD_RELOC_AARCH64_TLSDESC_LD64_LO12:
4796 case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19:
4797 case BFD_RELOC_AARCH64_TLSDESC_LDR:
4798 case BFD_RELOC_AARCH64_TLSDESC_OFF_G0_NC:
4799 case BFD_RELOC_AARCH64_TLSDESC_OFF_G1:
4800 return GOT_TLSDESC_GD;
4802 case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21:
4803 case BFD_RELOC_AARCH64_TLSIE_LD32_GOTTPREL_LO12_NC:
4804 case BFD_RELOC_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC:
4805 case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19:
4806 case BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G0_NC:
4807 case BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G1:
4817 aarch64_can_relax_tls (bfd *input_bfd,
4818 struct bfd_link_info *info,
4819 bfd_reloc_code_real_type r_type,
4820 struct elf_link_hash_entry *h,
4821 unsigned long r_symndx)
4823 unsigned int symbol_got_type;
4824 unsigned int reloc_got_type;
4826 if (! IS_AARCH64_TLS_RELAX_RELOC (r_type))
4829 symbol_got_type = elfNN_aarch64_symbol_got_type (h, input_bfd, r_symndx);
4830 reloc_got_type = aarch64_reloc_got_type (r_type);
4832 if (symbol_got_type == GOT_TLS_IE && GOT_TLS_GD_ANY_P (reloc_got_type))
4835 if (!bfd_link_executable (info))
4838 if (h && h->root.type == bfd_link_hash_undefweak)
4844 /* Given the relocation code R_TYPE, return the relaxed bfd reloc
4847 static bfd_reloc_code_real_type
4848 aarch64_tls_transition (bfd *input_bfd,
4849 struct bfd_link_info *info,
4850 unsigned int r_type,
4851 struct elf_link_hash_entry *h,
4852 unsigned long r_symndx)
4854 bfd_reloc_code_real_type bfd_r_type
4855 = elfNN_aarch64_bfd_reloc_from_type (input_bfd, r_type);
4857 if (! aarch64_can_relax_tls (input_bfd, info, bfd_r_type, h, r_symndx))
4860 return aarch64_tls_transition_without_check (bfd_r_type, h);
4863 /* Return the base VMA address which should be subtracted from real addresses
4864 when resolving R_AARCH64_TLS_DTPREL relocation. */
4867 dtpoff_base (struct bfd_link_info *info)
4869 /* If tls_sec is NULL, we should have signalled an error already. */
4870 BFD_ASSERT (elf_hash_table (info)->tls_sec != NULL);
4871 return elf_hash_table (info)->tls_sec->vma;
4874 /* Return the base VMA address which should be subtracted from real addresses
4875 when resolving R_AARCH64_TLS_GOTTPREL64 relocations. */
4878 tpoff_base (struct bfd_link_info *info)
4880 struct elf_link_hash_table *htab = elf_hash_table (info);
4882 /* If tls_sec is NULL, we should have signalled an error already. */
4883 BFD_ASSERT (htab->tls_sec != NULL);
4885 bfd_vma base = align_power ((bfd_vma) TCB_SIZE,
4886 htab->tls_sec->alignment_power);
4887 return htab->tls_sec->vma - base;
4891 symbol_got_offset_ref (bfd *input_bfd, struct elf_link_hash_entry *h,
4892 unsigned long r_symndx)
4894 /* Calculate the address of the GOT entry for symbol
4895 referred to in h. */
4897 return &h->got.offset;
4901 struct elf_aarch64_local_symbol *l;
4903 l = elf_aarch64_locals (input_bfd);
4904 return &l[r_symndx].got_offset;
4909 symbol_got_offset_mark (bfd *input_bfd, struct elf_link_hash_entry *h,
4910 unsigned long r_symndx)
4913 p = symbol_got_offset_ref (input_bfd, h, r_symndx);
4918 symbol_got_offset_mark_p (bfd *input_bfd, struct elf_link_hash_entry *h,
4919 unsigned long r_symndx)
4922 value = * symbol_got_offset_ref (input_bfd, h, r_symndx);
4927 symbol_got_offset (bfd *input_bfd, struct elf_link_hash_entry *h,
4928 unsigned long r_symndx)
4931 value = * symbol_got_offset_ref (input_bfd, h, r_symndx);
4937 symbol_tlsdesc_got_offset_ref (bfd *input_bfd, struct elf_link_hash_entry *h,
4938 unsigned long r_symndx)
4940 /* Calculate the address of the GOT entry for symbol
4941 referred to in h. */
4944 struct elf_aarch64_link_hash_entry *eh;
4945 eh = (struct elf_aarch64_link_hash_entry *) h;
4946 return &eh->tlsdesc_got_jump_table_offset;
4951 struct elf_aarch64_local_symbol *l;
4953 l = elf_aarch64_locals (input_bfd);
4954 return &l[r_symndx].tlsdesc_got_jump_table_offset;
4959 symbol_tlsdesc_got_offset_mark (bfd *input_bfd, struct elf_link_hash_entry *h,
4960 unsigned long r_symndx)
4963 p = symbol_tlsdesc_got_offset_ref (input_bfd, h, r_symndx);
4968 symbol_tlsdesc_got_offset_mark_p (bfd *input_bfd,
4969 struct elf_link_hash_entry *h,
4970 unsigned long r_symndx)
4973 value = * symbol_tlsdesc_got_offset_ref (input_bfd, h, r_symndx);
4978 symbol_tlsdesc_got_offset (bfd *input_bfd, struct elf_link_hash_entry *h,
4979 unsigned long r_symndx)
4982 value = * symbol_tlsdesc_got_offset_ref (input_bfd, h, r_symndx);
4987 /* Data for make_branch_to_erratum_835769_stub(). */
4989 struct erratum_835769_branch_to_stub_data
4991 struct bfd_link_info *info;
4992 asection *output_section;
4996 /* Helper to insert branches to erratum 835769 stubs in the right
4997 places for a particular section. */
5000 make_branch_to_erratum_835769_stub (struct bfd_hash_entry *gen_entry,
5003 struct elf_aarch64_stub_hash_entry *stub_entry;
5004 struct erratum_835769_branch_to_stub_data *data;
5006 unsigned long branch_insn = 0;
5007 bfd_vma veneered_insn_loc, veneer_entry_loc;
5008 bfd_signed_vma branch_offset;
5009 unsigned int target;
5012 stub_entry = (struct elf_aarch64_stub_hash_entry *) gen_entry;
5013 data = (struct erratum_835769_branch_to_stub_data *) in_arg;
5015 if (stub_entry->target_section != data->output_section
5016 || stub_entry->stub_type != aarch64_stub_erratum_835769_veneer)
5019 contents = data->contents;
5020 veneered_insn_loc = stub_entry->target_section->output_section->vma
5021 + stub_entry->target_section->output_offset
5022 + stub_entry->target_value;
5023 veneer_entry_loc = stub_entry->stub_sec->output_section->vma
5024 + stub_entry->stub_sec->output_offset
5025 + stub_entry->stub_offset;
5026 branch_offset = veneer_entry_loc - veneered_insn_loc;
5028 abfd = stub_entry->target_section->owner;
5029 if (!aarch64_valid_branch_p (veneer_entry_loc, veneered_insn_loc))
5031 (_("%pB: error: erratum 835769 stub out "
5032 "of range (input file too large)"), abfd);
5034 target = stub_entry->target_value;
5035 branch_insn = 0x14000000;
5036 branch_offset >>= 2;
5037 branch_offset &= 0x3ffffff;
5038 branch_insn |= branch_offset;
5039 bfd_putl32 (branch_insn, &contents[target]);
5046 _bfd_aarch64_erratum_843419_branch_to_stub (struct bfd_hash_entry *gen_entry,
5049 struct elf_aarch64_stub_hash_entry *stub_entry
5050 = (struct elf_aarch64_stub_hash_entry *) gen_entry;
5051 struct erratum_835769_branch_to_stub_data *data
5052 = (struct erratum_835769_branch_to_stub_data *) in_arg;
5053 struct bfd_link_info *info;
5054 struct elf_aarch64_link_hash_table *htab;
5062 contents = data->contents;
5063 section = data->output_section;
5065 htab = elf_aarch64_hash_table (info);
5067 if (stub_entry->target_section != section
5068 || stub_entry->stub_type != aarch64_stub_erratum_843419_veneer)
5071 insn = bfd_getl32 (contents + stub_entry->target_value);
5073 stub_entry->stub_sec->contents + stub_entry->stub_offset);
5075 place = (section->output_section->vma + section->output_offset
5076 + stub_entry->adrp_offset);
5077 insn = bfd_getl32 (contents + stub_entry->adrp_offset);
5079 if (!_bfd_aarch64_adrp_p (insn))
5082 bfd_signed_vma imm =
5083 (_bfd_aarch64_sign_extend
5084 ((bfd_vma) _bfd_aarch64_decode_adrp_imm (insn) << 12, 33)
5087 if (htab->fix_erratum_843419_adr
5088 && (imm >= AARCH64_MIN_ADRP_IMM && imm <= AARCH64_MAX_ADRP_IMM))
5090 insn = (_bfd_aarch64_reencode_adr_imm (AARCH64_ADR_OP, imm)
5091 | AARCH64_RT (insn));
5092 bfd_putl32 (insn, contents + stub_entry->adrp_offset);
5096 bfd_vma veneered_insn_loc;
5097 bfd_vma veneer_entry_loc;
5098 bfd_signed_vma branch_offset;
5099 uint32_t branch_insn;
5101 veneered_insn_loc = stub_entry->target_section->output_section->vma
5102 + stub_entry->target_section->output_offset
5103 + stub_entry->target_value;
5104 veneer_entry_loc = stub_entry->stub_sec->output_section->vma
5105 + stub_entry->stub_sec->output_offset
5106 + stub_entry->stub_offset;
5107 branch_offset = veneer_entry_loc - veneered_insn_loc;
5109 abfd = stub_entry->target_section->owner;
5110 if (!aarch64_valid_branch_p (veneer_entry_loc, veneered_insn_loc))
5112 (_("%pB: error: erratum 843419 stub out "
5113 "of range (input file too large)"), abfd);
5115 branch_insn = 0x14000000;
5116 branch_offset >>= 2;
5117 branch_offset &= 0x3ffffff;
5118 branch_insn |= branch_offset;
5119 bfd_putl32 (branch_insn, contents + stub_entry->target_value);
5126 elfNN_aarch64_write_section (bfd *output_bfd ATTRIBUTE_UNUSED,
5127 struct bfd_link_info *link_info,
5132 struct elf_aarch64_link_hash_table *globals =
5133 elf_aarch64_hash_table (link_info);
5135 if (globals == NULL)
5138 /* Fix code to point to erratum 835769 stubs. */
5139 if (globals->fix_erratum_835769)
5141 struct erratum_835769_branch_to_stub_data data;
5143 data.info = link_info;
5144 data.output_section = sec;
5145 data.contents = contents;
5146 bfd_hash_traverse (&globals->stub_hash_table,
5147 make_branch_to_erratum_835769_stub, &data);
5150 if (globals->fix_erratum_843419)
5152 struct erratum_835769_branch_to_stub_data data;
5154 data.info = link_info;
5155 data.output_section = sec;
5156 data.contents = contents;
5157 bfd_hash_traverse (&globals->stub_hash_table,
5158 _bfd_aarch64_erratum_843419_branch_to_stub, &data);
5164 /* Return TRUE if RELOC is a relocation against the base of GOT table. */
5167 aarch64_relocation_aginst_gp_p (bfd_reloc_code_real_type reloc)
5169 return (reloc == BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14
5170 || reloc == BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15
5171 || reloc == BFD_RELOC_AARCH64_LD64_GOTOFF_LO15
5172 || reloc == BFD_RELOC_AARCH64_MOVW_GOTOFF_G0_NC
5173 || reloc == BFD_RELOC_AARCH64_MOVW_GOTOFF_G1);
5176 /* Perform a relocation as part of a final link. The input relocation type
5177 should be TLS relaxed. */
5179 static bfd_reloc_status_type
5180 elfNN_aarch64_final_link_relocate (reloc_howto_type *howto,
5183 asection *input_section,
5185 Elf_Internal_Rela *rel,
5187 struct bfd_link_info *info,
5189 struct elf_link_hash_entry *h,
5190 bfd_boolean *unresolved_reloc_p,
5191 bfd_boolean save_addend,
5192 bfd_vma *saved_addend,
5193 Elf_Internal_Sym *sym)
5195 Elf_Internal_Shdr *symtab_hdr;
5196 unsigned int r_type = howto->type;
5197 bfd_reloc_code_real_type bfd_r_type
5198 = elfNN_aarch64_bfd_reloc_from_howto (howto);
5199 unsigned long r_symndx;
5200 bfd_byte *hit_data = contents + rel->r_offset;
5201 bfd_vma place, off, got_entry_addr = 0;
5202 bfd_signed_vma signed_addend;
5203 struct elf_aarch64_link_hash_table *globals;
5204 bfd_boolean weak_undef_p;
5205 bfd_boolean relative_reloc;
5207 bfd_vma orig_value = value;
5208 bfd_boolean resolved_to_zero;
5209 bfd_boolean abs_symbol_p;
5211 globals = elf_aarch64_hash_table (info);
5213 symtab_hdr = &elf_symtab_hdr (input_bfd);
5215 BFD_ASSERT (is_aarch64_elf (input_bfd));
5217 r_symndx = ELFNN_R_SYM (rel->r_info);
5219 place = input_section->output_section->vma
5220 + input_section->output_offset + rel->r_offset;
5222 /* Get addend, accumulating the addend for consecutive relocs
5223 which refer to the same offset. */
5224 signed_addend = saved_addend ? *saved_addend : 0;
5225 signed_addend += rel->r_addend;
5227 weak_undef_p = (h ? h->root.type == bfd_link_hash_undefweak
5228 : bfd_is_und_section (sym_sec));
5229 abs_symbol_p = h != NULL && bfd_is_abs_symbol (&h->root);
5232 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle
5233 it here if it is defined in a non-shared object. */
5235 && h->type == STT_GNU_IFUNC
5242 if ((input_section->flags & SEC_ALLOC) == 0)
5244 /* If this is a SHT_NOTE section without SHF_ALLOC, treat
5245 STT_GNU_IFUNC symbol as STT_FUNC. */
5246 if (elf_section_type (input_section) == SHT_NOTE)
5249 /* Dynamic relocs are not propagated for SEC_DEBUGGING
5250 sections because such sections are not SEC_ALLOC and
5251 thus ld.so will not process them. */
5252 if ((input_section->flags & SEC_DEBUGGING) != 0)
5253 return bfd_reloc_ok;
5255 if (h->root.root.string)
5256 name = h->root.root.string;
5258 name = bfd_elf_sym_name (input_bfd, symtab_hdr, sym, NULL);
5260 /* xgettext:c-format */
5261 (_("%pB(%pA+%#" PRIx64 "): "
5262 "unresolvable %s relocation against symbol `%s'"),
5263 input_bfd, input_section, (uint64_t) rel->r_offset,
5265 bfd_set_error (bfd_error_bad_value);
5266 return bfd_reloc_notsupported;
5268 else if (h->plt.offset == (bfd_vma) -1)
5269 goto bad_ifunc_reloc;
5271 /* STT_GNU_IFUNC symbol must go through PLT. */
5272 plt = globals->root.splt ? globals->root.splt : globals->root.iplt;
5273 value = (plt->output_section->vma + plt->output_offset + h->plt.offset);
5279 if (h->root.root.string)
5280 name = h->root.root.string;
5282 name = bfd_elf_sym_name (input_bfd, symtab_hdr, sym,
5285 /* xgettext:c-format */
5286 (_("%pB: relocation %s against STT_GNU_IFUNC "
5287 "symbol `%s' isn't handled by %s"), input_bfd,
5288 howto->name, name, __FUNCTION__);
5289 bfd_set_error (bfd_error_bad_value);
5290 return bfd_reloc_notsupported;
5292 case BFD_RELOC_AARCH64_NN:
5293 if (rel->r_addend != 0)
5295 if (h->root.root.string)
5296 name = h->root.root.string;
5298 name = bfd_elf_sym_name (input_bfd, symtab_hdr,
5301 /* xgettext:c-format */
5302 (_("%pB: relocation %s against STT_GNU_IFUNC "
5303 "symbol `%s' has non-zero addend: %" PRId64),
5304 input_bfd, howto->name, name, (int64_t) rel->r_addend);
5305 bfd_set_error (bfd_error_bad_value);
5306 return bfd_reloc_notsupported;
5309 /* Generate dynamic relocation only when there is a
5310 non-GOT reference in a shared object. */
5311 if (bfd_link_pic (info) && h->non_got_ref)
5313 Elf_Internal_Rela outrel;
5316 /* Need a dynamic relocation to get the real function
5318 outrel.r_offset = _bfd_elf_section_offset (output_bfd,
5322 if (outrel.r_offset == (bfd_vma) -1
5323 || outrel.r_offset == (bfd_vma) -2)
5326 outrel.r_offset += (input_section->output_section->vma
5327 + input_section->output_offset);
5329 if (h->dynindx == -1
5331 || bfd_link_executable (info))
5333 /* This symbol is resolved locally. */
5334 outrel.r_info = ELFNN_R_INFO (0, AARCH64_R (IRELATIVE));
5335 outrel.r_addend = (h->root.u.def.value
5336 + h->root.u.def.section->output_section->vma
5337 + h->root.u.def.section->output_offset);
5341 outrel.r_info = ELFNN_R_INFO (h->dynindx, r_type);
5342 outrel.r_addend = 0;
5345 sreloc = globals->root.irelifunc;
5346 elf_append_rela (output_bfd, sreloc, &outrel);
5348 /* If this reloc is against an external symbol, we
5349 do not want to fiddle with the addend. Otherwise,
5350 we need to include the symbol value so that it
5351 becomes an addend for the dynamic reloc. For an
5352 internal symbol, we have updated addend. */
5353 return bfd_reloc_ok;
5356 case BFD_RELOC_AARCH64_CALL26:
5357 case BFD_RELOC_AARCH64_JUMP26:
5358 value = _bfd_aarch64_elf_resolve_relocation (bfd_r_type, place, value,
5361 return _bfd_aarch64_elf_put_addend (input_bfd, hit_data, bfd_r_type,
5363 case BFD_RELOC_AARCH64_ADR_GOT_PAGE:
5364 case BFD_RELOC_AARCH64_GOT_LD_PREL19:
5365 case BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14:
5366 case BFD_RELOC_AARCH64_LD32_GOT_LO12_NC:
5367 case BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15:
5368 case BFD_RELOC_AARCH64_MOVW_GOTOFF_G0_NC:
5369 case BFD_RELOC_AARCH64_MOVW_GOTOFF_G1:
5370 case BFD_RELOC_AARCH64_LD64_GOTOFF_LO15:
5371 case BFD_RELOC_AARCH64_LD64_GOT_LO12_NC:
5372 base_got = globals->root.sgot;
5373 off = h->got.offset;
5375 if (base_got == NULL)
5378 if (off == (bfd_vma) -1)
5382 /* We can't use h->got.offset here to save state, or
5383 even just remember the offset, as finish_dynamic_symbol
5384 would use that as offset into .got. */
5386 if (globals->root.splt != NULL)
5388 plt_index = ((h->plt.offset - globals->plt_header_size) /
5389 globals->plt_entry_size);
5390 off = (plt_index + 3) * GOT_ENTRY_SIZE;
5391 base_got = globals->root.sgotplt;
5395 plt_index = h->plt.offset / globals->plt_entry_size;
5396 off = plt_index * GOT_ENTRY_SIZE;
5397 base_got = globals->root.igotplt;
5400 if (h->dynindx == -1
5404 /* This references the local definition. We must
5405 initialize this entry in the global offset table.
5406 Since the offset must always be a multiple of 8,
5407 we use the least significant bit to record
5408 whether we have initialized it already.
5410 When doing a dynamic link, we create a .rela.got
5411 relocation entry to initialize the value. This
5412 is done in the finish_dynamic_symbol routine. */
5417 bfd_put_NN (output_bfd, value,
5418 base_got->contents + off);
5419 /* Note that this is harmless as -1 | 1 still is -1. */
5423 value = (base_got->output_section->vma
5424 + base_got->output_offset + off);
5427 value = aarch64_calculate_got_entry_vma (h, globals, info,
5429 unresolved_reloc_p);
5431 if (aarch64_relocation_aginst_gp_p (bfd_r_type))
5432 addend = (globals->root.sgot->output_section->vma
5433 + globals->root.sgot->output_offset);
5435 value = _bfd_aarch64_elf_resolve_relocation (bfd_r_type, place, value,
5436 addend, weak_undef_p);
5437 return _bfd_aarch64_elf_put_addend (input_bfd, hit_data, bfd_r_type, howto, value);
5438 case BFD_RELOC_AARCH64_ADD_LO12:
5439 case BFD_RELOC_AARCH64_ADR_HI21_PCREL:
5445 resolved_to_zero = (h != NULL
5446 && UNDEFWEAK_NO_DYNAMIC_RELOC (info, h));
5450 case BFD_RELOC_AARCH64_NONE:
5451 case BFD_RELOC_AARCH64_TLSDESC_ADD:
5452 case BFD_RELOC_AARCH64_TLSDESC_CALL:
5453 case BFD_RELOC_AARCH64_TLSDESC_LDR:
5454 *unresolved_reloc_p = FALSE;
5455 return bfd_reloc_ok;
5457 case BFD_RELOC_AARCH64_NN:
5459 /* When generating a shared object or relocatable executable, these
5460 relocations are copied into the output file to be resolved at
5462 if (((bfd_link_pic (info)
5463 || globals->root.is_relocatable_executable)
5464 && (input_section->flags & SEC_ALLOC)
5466 || (ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
5467 && !resolved_to_zero)
5468 || h->root.type != bfd_link_hash_undefweak))
5469 /* Or we are creating an executable, we may need to keep relocations
5470 for symbols satisfied by a dynamic library if we manage to avoid
5471 copy relocs for the symbol. */
5472 || (ELIMINATE_COPY_RELOCS
5473 && !bfd_link_pic (info)
5475 && (input_section->flags & SEC_ALLOC)
5480 || h->root.type == bfd_link_hash_undefweak
5481 || h->root.type == bfd_link_hash_undefined)))
5483 Elf_Internal_Rela outrel;
5485 bfd_boolean skip, relocate;
5488 *unresolved_reloc_p = FALSE;
5493 outrel.r_addend = signed_addend;
5495 _bfd_elf_section_offset (output_bfd, info, input_section,
5497 if (outrel.r_offset == (bfd_vma) - 1)
5499 else if (outrel.r_offset == (bfd_vma) - 2)
5504 else if (abs_symbol_p)
5506 /* Local absolute symbol. */
5507 skip = (h->forced_local || (h->dynindx == -1));
5511 outrel.r_offset += (input_section->output_section->vma
5512 + input_section->output_offset);
5515 memset (&outrel, 0, sizeof outrel);
5518 && (!bfd_link_pic (info)
5519 || !(bfd_link_pie (info) || SYMBOLIC_BIND (info, h))
5520 || !h->def_regular))
5521 outrel.r_info = ELFNN_R_INFO (h->dynindx, r_type);
5526 /* On SVR4-ish systems, the dynamic loader cannot
5527 relocate the text and data segments independently,
5528 so the symbol does not matter. */
5530 relocate = globals->no_apply_dynamic_relocs ? FALSE : TRUE;
5531 outrel.r_info = ELFNN_R_INFO (symbol, AARCH64_R (RELATIVE));
5532 outrel.r_addend += value;
5535 sreloc = elf_section_data (input_section)->sreloc;
5536 if (sreloc == NULL || sreloc->contents == NULL)
5537 return bfd_reloc_notsupported;
5539 loc = sreloc->contents + sreloc->reloc_count++ * RELOC_SIZE (globals);
5540 bfd_elfNN_swap_reloca_out (output_bfd, &outrel, loc);
5542 if (sreloc->reloc_count * RELOC_SIZE (globals) > sreloc->size)
5544 /* Sanity to check that we have previously allocated
5545 sufficient space in the relocation section for the
5546 number of relocations we actually want to emit. */
5550 /* If this reloc is against an external symbol, we do not want to
5551 fiddle with the addend. Otherwise, we need to include the symbol
5552 value so that it becomes an addend for the dynamic reloc. */
5554 return bfd_reloc_ok;
5556 return _bfd_final_link_relocate (howto, input_bfd, input_section,
5557 contents, rel->r_offset, value,
5561 value += signed_addend;
5564 case BFD_RELOC_AARCH64_CALL26:
5565 case BFD_RELOC_AARCH64_JUMP26:
5567 asection *splt = globals->root.splt;
5568 bfd_boolean via_plt_p =
5569 splt != NULL && h != NULL && h->plt.offset != (bfd_vma) - 1;
5571 /* A call to an undefined weak symbol is converted to a jump to
5572 the next instruction unless a PLT entry will be created.
5573 The jump to the next instruction is optimized as a NOP.
5574 Do the same for local undefined symbols. */
5575 if (weak_undef_p && ! via_plt_p)
5577 bfd_putl32 (INSN_NOP, hit_data);
5578 return bfd_reloc_ok;
5581 /* If the call goes through a PLT entry, make sure to
5582 check distance to the right destination address. */
5584 value = (splt->output_section->vma
5585 + splt->output_offset + h->plt.offset);
5587 /* Check if a stub has to be inserted because the destination
5589 struct elf_aarch64_stub_hash_entry *stub_entry = NULL;
5591 /* If the branch destination is directed to plt stub, "value" will be
5592 the final destination, otherwise we should plus signed_addend, it may
5593 contain non-zero value, for example call to local function symbol
5594 which are turned into "sec_sym + sec_off", and sec_off is kept in
5596 if (! aarch64_valid_branch_p (via_plt_p ? value : value + signed_addend,
5598 /* The target is out of reach, so redirect the branch to
5599 the local stub for this function. */
5600 stub_entry = elfNN_aarch64_get_stub_entry (input_section, sym_sec, h,
5602 if (stub_entry != NULL)
5604 value = (stub_entry->stub_offset
5605 + stub_entry->stub_sec->output_offset
5606 + stub_entry->stub_sec->output_section->vma);
5608 /* We have redirected the destination to stub entry address,
5609 so ignore any addend record in the original rela entry. */
5613 value = _bfd_aarch64_elf_resolve_relocation (bfd_r_type, place, value,
5614 signed_addend, weak_undef_p);
5615 *unresolved_reloc_p = FALSE;
5618 case BFD_RELOC_AARCH64_16_PCREL:
5619 case BFD_RELOC_AARCH64_32_PCREL:
5620 case BFD_RELOC_AARCH64_64_PCREL:
5621 case BFD_RELOC_AARCH64_ADR_HI21_NC_PCREL:
5622 case BFD_RELOC_AARCH64_ADR_HI21_PCREL:
5623 case BFD_RELOC_AARCH64_ADR_LO21_PCREL:
5624 case BFD_RELOC_AARCH64_LD_LO19_PCREL:
5625 case BFD_RELOC_AARCH64_MOVW_PREL_G0:
5626 case BFD_RELOC_AARCH64_MOVW_PREL_G0_NC:
5627 case BFD_RELOC_AARCH64_MOVW_PREL_G1:
5628 case BFD_RELOC_AARCH64_MOVW_PREL_G1_NC:
5629 case BFD_RELOC_AARCH64_MOVW_PREL_G2:
5630 case BFD_RELOC_AARCH64_MOVW_PREL_G2_NC:
5631 case BFD_RELOC_AARCH64_MOVW_PREL_G3:
5632 if (bfd_link_pic (info)
5633 && (input_section->flags & SEC_ALLOC) != 0
5634 && (input_section->flags & SEC_READONLY) != 0
5635 && !SYMBOL_REFERENCES_LOCAL (info, h))
5637 int howto_index = bfd_r_type - BFD_RELOC_AARCH64_RELOC_START;
5640 /* xgettext:c-format */
5641 (_("%pB: relocation %s against symbol `%s' which may bind "
5642 "externally can not be used when making a shared object; "
5643 "recompile with -fPIC"),
5644 input_bfd, elfNN_aarch64_howto_table[howto_index].name,
5645 h->root.root.string);
5646 bfd_set_error (bfd_error_bad_value);
5647 return bfd_reloc_notsupported;
5651 case BFD_RELOC_AARCH64_16:
5653 case BFD_RELOC_AARCH64_32:
5655 case BFD_RELOC_AARCH64_ADD_LO12:
5656 case BFD_RELOC_AARCH64_BRANCH19:
5657 case BFD_RELOC_AARCH64_LDST128_LO12:
5658 case BFD_RELOC_AARCH64_LDST16_LO12:
5659 case BFD_RELOC_AARCH64_LDST32_LO12:
5660 case BFD_RELOC_AARCH64_LDST64_LO12:
5661 case BFD_RELOC_AARCH64_LDST8_LO12:
5662 case BFD_RELOC_AARCH64_MOVW_G0:
5663 case BFD_RELOC_AARCH64_MOVW_G0_NC:
5664 case BFD_RELOC_AARCH64_MOVW_G0_S:
5665 case BFD_RELOC_AARCH64_MOVW_G1:
5666 case BFD_RELOC_AARCH64_MOVW_G1_NC:
5667 case BFD_RELOC_AARCH64_MOVW_G1_S:
5668 case BFD_RELOC_AARCH64_MOVW_G2:
5669 case BFD_RELOC_AARCH64_MOVW_G2_NC:
5670 case BFD_RELOC_AARCH64_MOVW_G2_S:
5671 case BFD_RELOC_AARCH64_MOVW_G3:
5672 case BFD_RELOC_AARCH64_TSTBR14:
5673 value = _bfd_aarch64_elf_resolve_relocation (bfd_r_type, place, value,
5674 signed_addend, weak_undef_p);
5677 case BFD_RELOC_AARCH64_ADR_GOT_PAGE:
5678 case BFD_RELOC_AARCH64_GOT_LD_PREL19:
5679 case BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14:
5680 case BFD_RELOC_AARCH64_LD32_GOT_LO12_NC:
5681 case BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15:
5682 case BFD_RELOC_AARCH64_LD64_GOT_LO12_NC:
5683 case BFD_RELOC_AARCH64_LD64_GOTOFF_LO15:
5684 case BFD_RELOC_AARCH64_MOVW_GOTOFF_G0_NC:
5685 case BFD_RELOC_AARCH64_MOVW_GOTOFF_G1:
5686 if (globals->root.sgot == NULL)
5687 BFD_ASSERT (h != NULL);
5689 relative_reloc = FALSE;
5694 /* If a symbol is not dynamic and is not undefined weak, bind it
5695 locally and generate a RELATIVE relocation under PIC mode.
5697 NOTE: one symbol may be referenced by several relocations, we
5698 should only generate one RELATIVE relocation for that symbol.
5699 Therefore, check GOT offset mark first. */
5700 if (h->dynindx == -1
5702 && h->root.type != bfd_link_hash_undefweak
5703 && bfd_link_pic (info)
5704 && !symbol_got_offset_mark_p (input_bfd, h, r_symndx))
5705 relative_reloc = TRUE;
5707 value = aarch64_calculate_got_entry_vma (h, globals, info, value,
5709 unresolved_reloc_p);
5710 /* Record the GOT entry address which will be used when generating
5711 RELATIVE relocation. */
5713 got_entry_addr = value;
5715 if (aarch64_relocation_aginst_gp_p (bfd_r_type))
5716 addend = (globals->root.sgot->output_section->vma
5717 + globals->root.sgot->output_offset);
5718 value = _bfd_aarch64_elf_resolve_relocation (bfd_r_type, place, value,
5719 addend, weak_undef_p);
5724 struct elf_aarch64_local_symbol *locals
5725 = elf_aarch64_locals (input_bfd);
5729 int howto_index = bfd_r_type - BFD_RELOC_AARCH64_RELOC_START;
5731 /* xgettext:c-format */
5732 (_("%pB: local symbol descriptor table be NULL when applying "
5733 "relocation %s against local symbol"),
5734 input_bfd, elfNN_aarch64_howto_table[howto_index].name);
5738 off = symbol_got_offset (input_bfd, h, r_symndx);
5739 base_got = globals->root.sgot;
5740 got_entry_addr = (base_got->output_section->vma
5741 + base_got->output_offset + off);
5743 if (!symbol_got_offset_mark_p (input_bfd, h, r_symndx))
5745 bfd_put_64 (output_bfd, value, base_got->contents + off);
5747 /* For local symbol, we have done absolute relocation in static
5748 linking stage. While for shared library, we need to update the
5749 content of GOT entry according to the shared object's runtime
5750 base address. So, we need to generate a R_AARCH64_RELATIVE reloc
5751 for dynamic linker. */
5752 if (bfd_link_pic (info))
5753 relative_reloc = TRUE;
5755 symbol_got_offset_mark (input_bfd, h, r_symndx);
5758 /* Update the relocation value to GOT entry addr as we have transformed
5759 the direct data access into indirect data access through GOT. */
5760 value = got_entry_addr;
5762 if (aarch64_relocation_aginst_gp_p (bfd_r_type))
5763 addend = base_got->output_section->vma + base_got->output_offset;
5765 value = _bfd_aarch64_elf_resolve_relocation (bfd_r_type, place, value,
5766 addend, weak_undef_p);
5772 Elf_Internal_Rela outrel;
5774 s = globals->root.srelgot;
5778 outrel.r_offset = got_entry_addr;
5779 outrel.r_info = ELFNN_R_INFO (0, AARCH64_R (RELATIVE));
5780 outrel.r_addend = orig_value;
5781 elf_append_rela (output_bfd, s, &outrel);
5785 case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC:
5786 case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21:
5787 case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21:
5788 case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21:
5789 case BFD_RELOC_AARCH64_TLSIE_LD32_GOTTPREL_LO12_NC:
5790 case BFD_RELOC_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC:
5791 case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19:
5792 case BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC:
5793 case BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21:
5794 case BFD_RELOC_AARCH64_TLSLD_ADR_PREL21:
5795 if (globals->root.sgot == NULL)
5796 return bfd_reloc_notsupported;
5798 value = (symbol_got_offset (input_bfd, h, r_symndx)
5799 + globals->root.sgot->output_section->vma
5800 + globals->root.sgot->output_offset);
5802 value = _bfd_aarch64_elf_resolve_relocation (bfd_r_type, place, value,
5804 *unresolved_reloc_p = FALSE;
5807 case BFD_RELOC_AARCH64_TLSGD_MOVW_G0_NC:
5808 case BFD_RELOC_AARCH64_TLSGD_MOVW_G1:
5809 case BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G0_NC:
5810 case BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G1:
5811 if (globals->root.sgot == NULL)
5812 return bfd_reloc_notsupported;
5814 value = symbol_got_offset (input_bfd, h, r_symndx);
5815 value = _bfd_aarch64_elf_resolve_relocation (bfd_r_type, place, value,
5817 *unresolved_reloc_p = FALSE;
5820 case BFD_RELOC_AARCH64_TLSLD_ADD_DTPREL_HI12:
5821 case BFD_RELOC_AARCH64_TLSLD_ADD_DTPREL_LO12:
5822 case BFD_RELOC_AARCH64_TLSLD_ADD_DTPREL_LO12_NC:
5823 case BFD_RELOC_AARCH64_TLSLD_LDST16_DTPREL_LO12:
5824 case BFD_RELOC_AARCH64_TLSLD_LDST16_DTPREL_LO12_NC:
5825 case BFD_RELOC_AARCH64_TLSLD_LDST32_DTPREL_LO12:
5826 case BFD_RELOC_AARCH64_TLSLD_LDST32_DTPREL_LO12_NC:
5827 case BFD_RELOC_AARCH64_TLSLD_LDST64_DTPREL_LO12:
5828 case BFD_RELOC_AARCH64_TLSLD_LDST64_DTPREL_LO12_NC:
5829 case BFD_RELOC_AARCH64_TLSLD_LDST8_DTPREL_LO12:
5830 case BFD_RELOC_AARCH64_TLSLD_LDST8_DTPREL_LO12_NC:
5831 case BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G0:
5832 case BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G0_NC:
5833 case BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G1:
5834 case BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G1_NC:
5835 case BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G2:
5836 value = _bfd_aarch64_elf_resolve_relocation (bfd_r_type, place, value,
5837 signed_addend - dtpoff_base (info),
5841 case BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_HI12:
5842 case BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_LO12:
5843 case BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_LO12_NC:
5844 case BFD_RELOC_AARCH64_TLSLE_LDST16_TPREL_LO12:
5845 case BFD_RELOC_AARCH64_TLSLE_LDST16_TPREL_LO12_NC:
5846 case BFD_RELOC_AARCH64_TLSLE_LDST32_TPREL_LO12:
5847 case BFD_RELOC_AARCH64_TLSLE_LDST32_TPREL_LO12_NC:
5848 case BFD_RELOC_AARCH64_TLSLE_LDST64_TPREL_LO12:
5849 case BFD_RELOC_AARCH64_TLSLE_LDST64_TPREL_LO12_NC:
5850 case BFD_RELOC_AARCH64_TLSLE_LDST8_TPREL_LO12:
5851 case BFD_RELOC_AARCH64_TLSLE_LDST8_TPREL_LO12_NC:
5852 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0:
5853 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC:
5854 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1:
5855 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1_NC:
5856 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G2:
5857 value = _bfd_aarch64_elf_resolve_relocation (bfd_r_type, place, value,
5858 signed_addend - tpoff_base (info),
5860 *unresolved_reloc_p = FALSE;
5863 case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12:
5864 case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21:
5865 case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21:
5866 case BFD_RELOC_AARCH64_TLSDESC_LD32_LO12_NC:
5867 case BFD_RELOC_AARCH64_TLSDESC_LD64_LO12:
5868 case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19:
5869 if (globals->root.sgot == NULL)
5870 return bfd_reloc_notsupported;
5871 value = (symbol_tlsdesc_got_offset (input_bfd, h, r_symndx)
5872 + globals->root.sgotplt->output_section->vma
5873 + globals->root.sgotplt->output_offset
5874 + globals->sgotplt_jump_table_size);
5876 value = _bfd_aarch64_elf_resolve_relocation (bfd_r_type, place, value,
5878 *unresolved_reloc_p = FALSE;
5881 case BFD_RELOC_AARCH64_TLSDESC_OFF_G0_NC:
5882 case BFD_RELOC_AARCH64_TLSDESC_OFF_G1:
5883 if (globals->root.sgot == NULL)
5884 return bfd_reloc_notsupported;
5886 value = (symbol_tlsdesc_got_offset (input_bfd, h, r_symndx)
5887 + globals->root.sgotplt->output_section->vma
5888 + globals->root.sgotplt->output_offset
5889 + globals->sgotplt_jump_table_size);
5891 value -= (globals->root.sgot->output_section->vma
5892 + globals->root.sgot->output_offset);
5894 value = _bfd_aarch64_elf_resolve_relocation (bfd_r_type, place, value,
5896 *unresolved_reloc_p = FALSE;
5900 return bfd_reloc_notsupported;
5904 *saved_addend = value;
5906 /* Only apply the final relocation in a sequence. */
5908 return bfd_reloc_continue;
5910 return _bfd_aarch64_elf_put_addend (input_bfd, hit_data, bfd_r_type,
5914 /* LP64 and ILP32 operates on x- and w-registers respectively.
5915 Next definitions take into account the difference between
5916 corresponding machine codes. R means x-register if the target
5917 arch is LP64, and w-register if the target is ILP32. */
5920 # define add_R0_R0 (0x91000000)
5921 # define add_R0_R0_R1 (0x8b000020)
5922 # define add_R0_R1 (0x91400020)
5923 # define ldr_R0 (0x58000000)
5924 # define ldr_R0_mask(i) (i & 0xffffffe0)
5925 # define ldr_R0_x0 (0xf9400000)
5926 # define ldr_hw_R0 (0xf2a00000)
5927 # define movk_R0 (0xf2800000)
5928 # define movz_R0 (0xd2a00000)
5929 # define movz_hw_R0 (0xd2c00000)
5930 #else /*ARCH_SIZE == 32 */
5931 # define add_R0_R0 (0x11000000)
5932 # define add_R0_R0_R1 (0x0b000020)
5933 # define add_R0_R1 (0x11400020)
5934 # define ldr_R0 (0x18000000)
5935 # define ldr_R0_mask(i) (i & 0xbfffffe0)
5936 # define ldr_R0_x0 (0xb9400000)
5937 # define ldr_hw_R0 (0x72a00000)
5938 # define movk_R0 (0x72800000)
5939 # define movz_R0 (0x52a00000)
5940 # define movz_hw_R0 (0x52c00000)
5943 /* Structure to hold payload for _bfd_aarch64_erratum_843419_clear_stub,
5944 it is used to identify the stub information to reset. */
5946 struct erratum_843419_branch_to_stub_clear_data
5948 bfd_vma adrp_offset;
5949 asection *output_section;
5952 /* Clear the erratum information for GEN_ENTRY if the ADRP_OFFSET and
5953 section inside IN_ARG matches. The clearing is done by setting the
5954 stub_type to none. */
5957 _bfd_aarch64_erratum_843419_clear_stub (struct bfd_hash_entry *gen_entry,
5960 struct elf_aarch64_stub_hash_entry *stub_entry
5961 = (struct elf_aarch64_stub_hash_entry *) gen_entry;
5962 struct erratum_843419_branch_to_stub_clear_data *data
5963 = (struct erratum_843419_branch_to_stub_clear_data *) in_arg;
5965 if (stub_entry->target_section != data->output_section
5966 || stub_entry->stub_type != aarch64_stub_erratum_843419_veneer
5967 || stub_entry->adrp_offset != data->adrp_offset)
5970 /* Change the stub type instead of removing the entry, removing from the hash
5971 table would be slower and we have already reserved the memory for the entry
5972 so there wouldn't be much gain. Changing the stub also keeps around a
5973 record of what was there before. */
5974 stub_entry->stub_type = aarch64_stub_none;
5976 /* We're done and there could have been only one matching stub at that
5977 particular offset, so abort further traversal. */
5981 /* TLS Relaxations may relax an adrp sequence that matches the erratum 843419
5982 sequence. In this case the erratum no longer applies and we need to remove
5983 the entry from the pending stub generation. This clears matching adrp insn
5984 at ADRP_OFFSET in INPUT_SECTION in the stub table defined in GLOBALS. */
5987 clear_erratum_843419_entry (struct elf_aarch64_link_hash_table *globals,
5988 bfd_vma adrp_offset, asection *input_section)
5990 if (globals->fix_erratum_843419)
5992 struct erratum_843419_branch_to_stub_clear_data data;
5993 data.adrp_offset = adrp_offset;
5994 data.output_section = input_section;
5996 bfd_hash_traverse (&globals->stub_hash_table,
5997 _bfd_aarch64_erratum_843419_clear_stub, &data);
6001 /* Handle TLS relaxations. Relaxing is possible for symbols that use
6002 R_AARCH64_TLSDESC_ADR_{PAGE, LD64_LO12_NC, ADD_LO12_NC} during a static
6005 Return bfd_reloc_ok if we're done, bfd_reloc_continue if the caller
6006 is to then call final_link_relocate. Return other values in the
6009 static bfd_reloc_status_type
6010 elfNN_aarch64_tls_relax (struct elf_aarch64_link_hash_table *globals,
6011 bfd *input_bfd, asection *input_section,
6012 bfd_byte *contents, Elf_Internal_Rela *rel,
6013 struct elf_link_hash_entry *h)
6015 bfd_boolean is_local = h == NULL;
6016 unsigned int r_type = ELFNN_R_TYPE (rel->r_info);
6019 BFD_ASSERT (globals && input_bfd && contents && rel);
6021 switch (elfNN_aarch64_bfd_reloc_from_type (input_bfd, r_type))
6023 case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21:
6024 case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21:
6027 /* GD->LE relaxation:
6028 adrp x0, :tlsgd:var => movz R0, :tprel_g1:var
6030 adrp x0, :tlsdesc:var => movz R0, :tprel_g1:var
6032 Where R is x for LP64, and w for ILP32. */
6033 bfd_putl32 (movz_R0, contents + rel->r_offset);
6034 /* We have relaxed the adrp into a mov, we may have to clear any
6035 pending erratum fixes. */
6036 clear_erratum_843419_entry (globals, rel->r_offset, input_section);
6037 return bfd_reloc_continue;
6041 /* GD->IE relaxation:
6042 adrp x0, :tlsgd:var => adrp x0, :gottprel:var
6044 adrp x0, :tlsdesc:var => adrp x0, :gottprel:var
6046 return bfd_reloc_continue;
6049 case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21:
6053 case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19:
6056 /* Tiny TLSDESC->LE relaxation:
6057 ldr x1, :tlsdesc:var => movz R0, #:tprel_g1:var
6058 adr x0, :tlsdesc:var => movk R0, #:tprel_g0_nc:var
6062 Where R is x for LP64, and w for ILP32. */
6063 BFD_ASSERT (ELFNN_R_TYPE (rel[1].r_info) == AARCH64_R (TLSDESC_ADR_PREL21));
6064 BFD_ASSERT (ELFNN_R_TYPE (rel[2].r_info) == AARCH64_R (TLSDESC_CALL));
6066 rel[1].r_info = ELFNN_R_INFO (ELFNN_R_SYM (rel->r_info),
6067 AARCH64_R (TLSLE_MOVW_TPREL_G0_NC));
6068 rel[2].r_info = ELFNN_R_INFO (STN_UNDEF, R_AARCH64_NONE);
6070 bfd_putl32 (movz_R0, contents + rel->r_offset);
6071 bfd_putl32 (movk_R0, contents + rel->r_offset + 4);
6072 bfd_putl32 (INSN_NOP, contents + rel->r_offset + 8);
6073 return bfd_reloc_continue;
6077 /* Tiny TLSDESC->IE relaxation:
6078 ldr x1, :tlsdesc:var => ldr x0, :gottprel:var
6079 adr x0, :tlsdesc:var => nop
6083 BFD_ASSERT (ELFNN_R_TYPE (rel[1].r_info) == AARCH64_R (TLSDESC_ADR_PREL21));
6084 BFD_ASSERT (ELFNN_R_TYPE (rel[2].r_info) == AARCH64_R (TLSDESC_CALL));
6086 rel[1].r_info = ELFNN_R_INFO (STN_UNDEF, R_AARCH64_NONE);
6087 rel[2].r_info = ELFNN_R_INFO (STN_UNDEF, R_AARCH64_NONE);
6089 bfd_putl32 (ldr_R0, contents + rel->r_offset);
6090 bfd_putl32 (INSN_NOP, contents + rel->r_offset + 4);
6091 bfd_putl32 (INSN_NOP, contents + rel->r_offset + 8);
6092 return bfd_reloc_continue;
6095 case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21:
6098 /* Tiny GD->LE relaxation:
6099 adr x0, :tlsgd:var => mrs x1, tpidr_el0
6100 bl __tls_get_addr => add R0, R1, #:tprel_hi12:x, lsl #12
6101 nop => add R0, R0, #:tprel_lo12_nc:x
6103 Where R is x for LP64, and x for Ilp32. */
6105 /* First kill the tls_get_addr reloc on the bl instruction. */
6106 BFD_ASSERT (rel->r_offset + 4 == rel[1].r_offset);
6108 bfd_putl32 (0xd53bd041, contents + rel->r_offset + 0);
6109 bfd_putl32 (add_R0_R1, contents + rel->r_offset + 4);
6110 bfd_putl32 (add_R0_R0, contents + rel->r_offset + 8);
6112 rel[1].r_info = ELFNN_R_INFO (ELFNN_R_SYM (rel->r_info),
6113 AARCH64_R (TLSLE_ADD_TPREL_LO12_NC));
6114 rel[1].r_offset = rel->r_offset + 8;
6116 /* Move the current relocation to the second instruction in
6119 rel->r_info = ELFNN_R_INFO (ELFNN_R_SYM (rel->r_info),
6120 AARCH64_R (TLSLE_ADD_TPREL_HI12));
6121 return bfd_reloc_continue;
6125 /* Tiny GD->IE relaxation:
6126 adr x0, :tlsgd:var => ldr R0, :gottprel:var
6127 bl __tls_get_addr => mrs x1, tpidr_el0
6128 nop => add R0, R0, R1
6130 Where R is x for LP64, and w for Ilp32. */
6132 /* First kill the tls_get_addr reloc on the bl instruction. */
6133 BFD_ASSERT (rel->r_offset + 4 == rel[1].r_offset);
6134 rel[1].r_info = ELFNN_R_INFO (STN_UNDEF, R_AARCH64_NONE);
6136 bfd_putl32 (ldr_R0, contents + rel->r_offset);
6137 bfd_putl32 (0xd53bd041, contents + rel->r_offset + 4);
6138 bfd_putl32 (add_R0_R0_R1, contents + rel->r_offset + 8);
6139 return bfd_reloc_continue;
6143 case BFD_RELOC_AARCH64_TLSGD_MOVW_G1:
6144 BFD_ASSERT (ELFNN_R_TYPE (rel[1].r_info) == AARCH64_R (TLSGD_MOVW_G0_NC));
6145 BFD_ASSERT (rel->r_offset + 12 == rel[2].r_offset);
6146 BFD_ASSERT (ELFNN_R_TYPE (rel[2].r_info) == AARCH64_R (CALL26));
6150 /* Large GD->LE relaxation:
6151 movz x0, #:tlsgd_g1:var => movz x0, #:tprel_g2:var, lsl #32
6152 movk x0, #:tlsgd_g0_nc:var => movk x0, #:tprel_g1_nc:var, lsl #16
6153 add x0, gp, x0 => movk x0, #:tprel_g0_nc:var
6154 bl __tls_get_addr => mrs x1, tpidr_el0
6155 nop => add x0, x0, x1
6157 rel[2].r_info = ELFNN_R_INFO (ELFNN_R_SYM (rel->r_info),
6158 AARCH64_R (TLSLE_MOVW_TPREL_G0_NC));
6159 rel[2].r_offset = rel->r_offset + 8;
6161 bfd_putl32 (movz_hw_R0, contents + rel->r_offset + 0);
6162 bfd_putl32 (ldr_hw_R0, contents + rel->r_offset + 4);
6163 bfd_putl32 (movk_R0, contents + rel->r_offset + 8);
6164 bfd_putl32 (0xd53bd041, contents + rel->r_offset + 12);
6165 bfd_putl32 (add_R0_R0_R1, contents + rel->r_offset + 16);
6169 /* Large GD->IE relaxation:
6170 movz x0, #:tlsgd_g1:var => movz x0, #:gottprel_g1:var, lsl #16
6171 movk x0, #:tlsgd_g0_nc:var => movk x0, #:gottprel_g0_nc:var
6172 add x0, gp, x0 => ldr x0, [gp, x0]
6173 bl __tls_get_addr => mrs x1, tpidr_el0
6174 nop => add x0, x0, x1
6176 rel[2].r_info = ELFNN_R_INFO (STN_UNDEF, R_AARCH64_NONE);
6177 bfd_putl32 (0xd2a80000, contents + rel->r_offset + 0);
6178 bfd_putl32 (ldr_R0, contents + rel->r_offset + 8);
6179 bfd_putl32 (0xd53bd041, contents + rel->r_offset + 12);
6180 bfd_putl32 (add_R0_R0_R1, contents + rel->r_offset + 16);
6182 return bfd_reloc_continue;
6184 case BFD_RELOC_AARCH64_TLSGD_MOVW_G0_NC:
6185 return bfd_reloc_continue;
6188 case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19:
6189 return bfd_reloc_continue;
6191 case BFD_RELOC_AARCH64_TLSDESC_LDNN_LO12_NC:
6194 /* GD->LE relaxation:
6195 ldr xd, [x0, #:tlsdesc_lo12:var] => movk x0, :tprel_g0_nc:var
6197 Where R is x for lp64 mode, and w for ILP32 mode. */
6198 bfd_putl32 (movk_R0, contents + rel->r_offset);
6199 return bfd_reloc_continue;
6203 /* GD->IE relaxation:
6204 ldr xd, [x0, #:tlsdesc_lo12:var] => ldr R0, [x0, #:gottprel_lo12:var]
6206 Where R is x for lp64 mode, and w for ILP32 mode. */
6207 insn = bfd_getl32 (contents + rel->r_offset);
6208 bfd_putl32 (ldr_R0_mask (insn), contents + rel->r_offset);
6209 return bfd_reloc_continue;
6212 case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC:
6215 /* GD->LE relaxation
6216 add x0, #:tlsgd_lo12:var => movk R0, :tprel_g0_nc:var
6217 bl __tls_get_addr => mrs x1, tpidr_el0
6218 nop => add R0, R1, R0
6220 Where R is x for lp64 mode, and w for ILP32 mode. */
6222 /* First kill the tls_get_addr reloc on the bl instruction. */
6223 BFD_ASSERT (rel->r_offset + 4 == rel[1].r_offset);
6224 rel[1].r_info = ELFNN_R_INFO (STN_UNDEF, R_AARCH64_NONE);
6226 bfd_putl32 (movk_R0, contents + rel->r_offset);
6227 bfd_putl32 (0xd53bd041, contents + rel->r_offset + 4);
6228 bfd_putl32 (add_R0_R0_R1, contents + rel->r_offset + 8);
6229 return bfd_reloc_continue;
6233 /* GD->IE relaxation
6234 ADD x0, #:tlsgd_lo12:var => ldr R0, [x0, #:gottprel_lo12:var]
6235 BL __tls_get_addr => mrs x1, tpidr_el0
6237 NOP => add R0, R1, R0
6239 Where R is x for lp64 mode, and w for ilp32 mode. */
6241 BFD_ASSERT (ELFNN_R_TYPE (rel[1].r_info) == AARCH64_R (CALL26));
6243 /* Remove the relocation on the BL instruction. */
6244 rel[1].r_info = ELFNN_R_INFO (STN_UNDEF, R_AARCH64_NONE);
6246 /* We choose to fixup the BL and NOP instructions using the
6247 offset from the second relocation to allow flexibility in
6248 scheduling instructions between the ADD and BL. */
6249 bfd_putl32 (ldr_R0_x0, contents + rel->r_offset);
6250 bfd_putl32 (0xd53bd041, contents + rel[1].r_offset);
6251 bfd_putl32 (add_R0_R0_R1, contents + rel[1].r_offset + 4);
6252 return bfd_reloc_continue;
6255 case BFD_RELOC_AARCH64_TLSDESC_ADD:
6256 case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12:
6257 case BFD_RELOC_AARCH64_TLSDESC_CALL:
6258 /* GD->IE/LE relaxation:
6259 add x0, x0, #:tlsdesc_lo12:var => nop
6262 bfd_putl32 (INSN_NOP, contents + rel->r_offset);
6263 return bfd_reloc_ok;
6265 case BFD_RELOC_AARCH64_TLSDESC_LDR:
6268 /* GD->LE relaxation:
6269 ldr xd, [gp, xn] => movk R0, #:tprel_g0_nc:var
6271 Where R is x for lp64 mode, and w for ILP32 mode. */
6272 bfd_putl32 (movk_R0, contents + rel->r_offset);
6273 return bfd_reloc_continue;
6277 /* GD->IE relaxation:
6278 ldr xd, [gp, xn] => ldr R0, [gp, xn]
6280 Where R is x for lp64 mode, and w for ILP32 mode. */
6281 insn = bfd_getl32 (contents + rel->r_offset);
6282 bfd_putl32 (ldr_R0_mask (insn), contents + rel->r_offset);
6283 return bfd_reloc_ok;
6286 case BFD_RELOC_AARCH64_TLSDESC_OFF_G0_NC:
6287 /* GD->LE relaxation:
6288 movk xd, #:tlsdesc_off_g0_nc:var => movk R0, #:tprel_g1_nc:var, lsl #16
6290 movk xd, #:tlsdesc_off_g0_nc:var => movk Rd, #:gottprel_g0_nc:var
6292 Where R is x for lp64 mode, and w for ILP32 mode. */
6294 bfd_putl32 (ldr_hw_R0, contents + rel->r_offset);
6295 return bfd_reloc_continue;
6297 case BFD_RELOC_AARCH64_TLSDESC_OFF_G1:
6300 /* GD->LE relaxation:
6301 movz xd, #:tlsdesc_off_g1:var => movz R0, #:tprel_g2:var, lsl #32
6303 Where R is x for lp64 mode, and w for ILP32 mode. */
6304 bfd_putl32 (movz_hw_R0, contents + rel->r_offset);
6305 return bfd_reloc_continue;
6309 /* GD->IE relaxation:
6310 movz xd, #:tlsdesc_off_g1:var => movz Rd, #:gottprel_g1:var, lsl #16
6312 Where R is x for lp64 mode, and w for ILP32 mode. */
6313 insn = bfd_getl32 (contents + rel->r_offset);
6314 bfd_putl32 (movz_R0 | (insn & 0x1f), contents + rel->r_offset);
6315 return bfd_reloc_continue;
6318 case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21:
6319 /* IE->LE relaxation:
6320 adrp xd, :gottprel:var => movz Rd, :tprel_g1:var
6322 Where R is x for lp64 mode, and w for ILP32 mode. */
6325 insn = bfd_getl32 (contents + rel->r_offset);
6326 bfd_putl32 (movz_R0 | (insn & 0x1f), contents + rel->r_offset);
6327 /* We have relaxed the adrp into a mov, we may have to clear any
6328 pending erratum fixes. */
6329 clear_erratum_843419_entry (globals, rel->r_offset, input_section);
6331 return bfd_reloc_continue;
6333 case BFD_RELOC_AARCH64_TLSIE_LDNN_GOTTPREL_LO12_NC:
6334 /* IE->LE relaxation:
6335 ldr xd, [xm, #:gottprel_lo12:var] => movk Rd, :tprel_g0_nc:var
6337 Where R is x for lp64 mode, and w for ILP32 mode. */
6340 insn = bfd_getl32 (contents + rel->r_offset);
6341 bfd_putl32 (movk_R0 | (insn & 0x1f), contents + rel->r_offset);
6343 return bfd_reloc_continue;
6345 case BFD_RELOC_AARCH64_TLSLD_ADR_PREL21:
6346 /* LD->LE relaxation (tiny):
6347 adr x0, :tlsldm:x => mrs x0, tpidr_el0
6348 bl __tls_get_addr => add R0, R0, TCB_SIZE
6350 Where R is x for lp64 mode, and w for ilp32 mode. */
6353 BFD_ASSERT (rel->r_offset + 4 == rel[1].r_offset);
6354 BFD_ASSERT (ELFNN_R_TYPE (rel[1].r_info) == AARCH64_R (CALL26));
6355 /* No need of CALL26 relocation for tls_get_addr. */
6356 rel[1].r_info = ELFNN_R_INFO (STN_UNDEF, R_AARCH64_NONE);
6357 bfd_putl32 (0xd53bd040, contents + rel->r_offset + 0);
6358 bfd_putl32 (add_R0_R0 | (TCB_SIZE << 10),
6359 contents + rel->r_offset + 4);
6360 return bfd_reloc_ok;
6362 return bfd_reloc_continue;
6364 case BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21:
6365 /* LD->LE relaxation (small):
6366 adrp x0, :tlsldm:x => mrs x0, tpidr_el0
6370 bfd_putl32 (0xd53bd040, contents + rel->r_offset);
6371 return bfd_reloc_ok;
6373 return bfd_reloc_continue;
6375 case BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC:
6376 /* LD->LE relaxation (small):
6377 add x0, #:tlsldm_lo12:x => add R0, R0, TCB_SIZE
6378 bl __tls_get_addr => nop
6380 Where R is x for lp64 mode, and w for ilp32 mode. */
6383 BFD_ASSERT (rel->r_offset + 4 == rel[1].r_offset);
6384 BFD_ASSERT (ELFNN_R_TYPE (rel[1].r_info) == AARCH64_R (CALL26));
6385 /* No need of CALL26 relocation for tls_get_addr. */
6386 rel[1].r_info = ELFNN_R_INFO (STN_UNDEF, R_AARCH64_NONE);
6387 bfd_putl32 (add_R0_R0 | (TCB_SIZE << 10),
6388 contents + rel->r_offset + 0);
6389 bfd_putl32 (INSN_NOP, contents + rel->r_offset + 4);
6390 return bfd_reloc_ok;
6392 return bfd_reloc_continue;
6395 return bfd_reloc_continue;
6398 return bfd_reloc_ok;
6401 /* Relocate an AArch64 ELF section. */
6404 elfNN_aarch64_relocate_section (bfd *output_bfd,
6405 struct bfd_link_info *info,
6407 asection *input_section,
6409 Elf_Internal_Rela *relocs,
6410 Elf_Internal_Sym *local_syms,
6411 asection **local_sections)
6413 Elf_Internal_Shdr *symtab_hdr;
6414 struct elf_link_hash_entry **sym_hashes;
6415 Elf_Internal_Rela *rel;
6416 Elf_Internal_Rela *relend;
6418 struct elf_aarch64_link_hash_table *globals;
6419 bfd_boolean save_addend = FALSE;
6422 globals = elf_aarch64_hash_table (info);
6424 symtab_hdr = &elf_symtab_hdr (input_bfd);
6425 sym_hashes = elf_sym_hashes (input_bfd);
6428 relend = relocs + input_section->reloc_count;
6429 for (; rel < relend; rel++)
6431 unsigned int r_type;
6432 bfd_reloc_code_real_type bfd_r_type;
6433 bfd_reloc_code_real_type relaxed_bfd_r_type;
6434 reloc_howto_type *howto;
6435 unsigned long r_symndx;
6436 Elf_Internal_Sym *sym;
6438 struct elf_link_hash_entry *h;
6440 bfd_reloc_status_type r;
6443 bfd_boolean unresolved_reloc = FALSE;
6444 char *error_message = NULL;
6446 r_symndx = ELFNN_R_SYM (rel->r_info);
6447 r_type = ELFNN_R_TYPE (rel->r_info);
6449 bfd_reloc.howto = elfNN_aarch64_howto_from_type (input_bfd, r_type);
6450 howto = bfd_reloc.howto;
6453 return _bfd_unrecognized_reloc (input_bfd, input_section, r_type);
6455 bfd_r_type = elfNN_aarch64_bfd_reloc_from_howto (howto);
6461 if (r_symndx < symtab_hdr->sh_info)
6463 sym = local_syms + r_symndx;
6464 sym_type = ELFNN_ST_TYPE (sym->st_info);
6465 sec = local_sections[r_symndx];
6467 /* An object file might have a reference to a local
6468 undefined symbol. This is a daft object file, but we
6469 should at least do something about it. */
6470 if (r_type != R_AARCH64_NONE && r_type != R_AARCH64_NULL
6471 && bfd_is_und_section (sec)
6472 && ELF_ST_BIND (sym->st_info) != STB_WEAK)
6473 (*info->callbacks->undefined_symbol)
6474 (info, bfd_elf_string_from_elf_section
6475 (input_bfd, symtab_hdr->sh_link, sym->st_name),
6476 input_bfd, input_section, rel->r_offset, TRUE);
6478 relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel);
6480 /* Relocate against local STT_GNU_IFUNC symbol. */
6481 if (!bfd_link_relocatable (info)
6482 && ELF_ST_TYPE (sym->st_info) == STT_GNU_IFUNC)
6484 h = elfNN_aarch64_get_local_sym_hash (globals, input_bfd,
6489 /* Set STT_GNU_IFUNC symbol value. */
6490 h->root.u.def.value = sym->st_value;
6491 h->root.u.def.section = sec;
6496 bfd_boolean warned, ignored;
6498 RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel,
6499 r_symndx, symtab_hdr, sym_hashes,
6501 unresolved_reloc, warned, ignored);
6506 if (sec != NULL && discarded_section (sec))
6507 RELOC_AGAINST_DISCARDED_SECTION (info, input_bfd, input_section,
6508 rel, 1, relend, howto, 0, contents);
6510 if (bfd_link_relocatable (info))
6514 name = h->root.root.string;
6517 name = (bfd_elf_string_from_elf_section
6518 (input_bfd, symtab_hdr->sh_link, sym->st_name));
6519 if (name == NULL || *name == '\0')
6520 name = bfd_section_name (input_bfd, sec);
6524 && r_type != R_AARCH64_NONE
6525 && r_type != R_AARCH64_NULL
6527 || h->root.type == bfd_link_hash_defined
6528 || h->root.type == bfd_link_hash_defweak)
6529 && IS_AARCH64_TLS_RELOC (bfd_r_type) != (sym_type == STT_TLS))
6532 ((sym_type == STT_TLS
6533 /* xgettext:c-format */
6534 ? _("%pB(%pA+%#" PRIx64 "): %s used with TLS symbol %s")
6535 /* xgettext:c-format */
6536 : _("%pB(%pA+%#" PRIx64 "): %s used with non-TLS symbol %s")),
6538 input_section, (uint64_t) rel->r_offset, howto->name, name);
6541 /* We relax only if we can see that there can be a valid transition
6542 from a reloc type to another.
6543 We call elfNN_aarch64_final_link_relocate unless we're completely
6544 done, i.e., the relaxation produced the final output we want. */
6546 relaxed_bfd_r_type = aarch64_tls_transition (input_bfd, info, r_type,
6548 if (relaxed_bfd_r_type != bfd_r_type)
6550 bfd_r_type = relaxed_bfd_r_type;
6551 howto = elfNN_aarch64_howto_from_bfd_reloc (bfd_r_type);
6552 BFD_ASSERT (howto != NULL);
6553 r_type = howto->type;
6554 r = elfNN_aarch64_tls_relax (globals, input_bfd, input_section,
6556 unresolved_reloc = 0;
6559 r = bfd_reloc_continue;
6561 /* There may be multiple consecutive relocations for the
6562 same offset. In that case we are supposed to treat the
6563 output of each relocation as the addend for the next. */
6564 if (rel + 1 < relend
6565 && rel->r_offset == rel[1].r_offset
6566 && ELFNN_R_TYPE (rel[1].r_info) != R_AARCH64_NONE
6567 && ELFNN_R_TYPE (rel[1].r_info) != R_AARCH64_NULL)
6570 save_addend = FALSE;
6572 if (r == bfd_reloc_continue)
6573 r = elfNN_aarch64_final_link_relocate (howto, input_bfd, output_bfd,
6574 input_section, contents, rel,
6575 relocation, info, sec,
6576 h, &unresolved_reloc,
6577 save_addend, &addend, sym);
6579 switch (elfNN_aarch64_bfd_reloc_from_type (input_bfd, r_type))
6581 case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC:
6582 case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21:
6583 case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21:
6584 case BFD_RELOC_AARCH64_TLSGD_MOVW_G0_NC:
6585 case BFD_RELOC_AARCH64_TLSGD_MOVW_G1:
6586 case BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC:
6587 case BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21:
6588 case BFD_RELOC_AARCH64_TLSLD_ADR_PREL21:
6589 if (! symbol_got_offset_mark_p (input_bfd, h, r_symndx))
6591 bfd_boolean need_relocs = FALSE;
6596 off = symbol_got_offset (input_bfd, h, r_symndx);
6597 indx = h && h->dynindx != -1 ? h->dynindx : 0;
6600 (!bfd_link_executable (info) || indx != 0) &&
6602 || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
6603 || h->root.type != bfd_link_hash_undefweak);
6605 BFD_ASSERT (globals->root.srelgot != NULL);
6609 Elf_Internal_Rela rela;
6610 rela.r_info = ELFNN_R_INFO (indx, AARCH64_R (TLS_DTPMOD));
6612 rela.r_offset = globals->root.sgot->output_section->vma +
6613 globals->root.sgot->output_offset + off;
6616 loc = globals->root.srelgot->contents;
6617 loc += globals->root.srelgot->reloc_count++
6618 * RELOC_SIZE (htab);
6619 bfd_elfNN_swap_reloca_out (output_bfd, &rela, loc);
6621 bfd_reloc_code_real_type real_type =
6622 elfNN_aarch64_bfd_reloc_from_type (input_bfd, r_type);
6624 if (real_type == BFD_RELOC_AARCH64_TLSLD_ADR_PREL21
6625 || real_type == BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21
6626 || real_type == BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC)
6628 /* For local dynamic, don't generate DTPREL in any case.
6629 Initialize the DTPREL slot into zero, so we get module
6630 base address when invoke runtime TLS resolver. */
6631 bfd_put_NN (output_bfd, 0,
6632 globals->root.sgot->contents + off
6637 bfd_put_NN (output_bfd,
6638 relocation - dtpoff_base (info),
6639 globals->root.sgot->contents + off
6644 /* This TLS symbol is global. We emit a
6645 relocation to fixup the tls offset at load
6648 ELFNN_R_INFO (indx, AARCH64_R (TLS_DTPREL));
6651 (globals->root.sgot->output_section->vma
6652 + globals->root.sgot->output_offset + off
6655 loc = globals->root.srelgot->contents;
6656 loc += globals->root.srelgot->reloc_count++
6657 * RELOC_SIZE (globals);
6658 bfd_elfNN_swap_reloca_out (output_bfd, &rela, loc);
6659 bfd_put_NN (output_bfd, (bfd_vma) 0,
6660 globals->root.sgot->contents + off
6666 bfd_put_NN (output_bfd, (bfd_vma) 1,
6667 globals->root.sgot->contents + off);
6668 bfd_put_NN (output_bfd,
6669 relocation - dtpoff_base (info),
6670 globals->root.sgot->contents + off
6674 symbol_got_offset_mark (input_bfd, h, r_symndx);
6678 case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21:
6679 case BFD_RELOC_AARCH64_TLSIE_LDNN_GOTTPREL_LO12_NC:
6680 case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19:
6681 case BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G0_NC:
6682 case BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G1:
6683 if (! symbol_got_offset_mark_p (input_bfd, h, r_symndx))
6685 bfd_boolean need_relocs = FALSE;
6690 off = symbol_got_offset (input_bfd, h, r_symndx);
6692 indx = h && h->dynindx != -1 ? h->dynindx : 0;
6695 (!bfd_link_executable (info) || indx != 0) &&
6697 || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
6698 || h->root.type != bfd_link_hash_undefweak);
6700 BFD_ASSERT (globals->root.srelgot != NULL);
6704 Elf_Internal_Rela rela;
6707 rela.r_addend = relocation - dtpoff_base (info);
6711 rela.r_info = ELFNN_R_INFO (indx, AARCH64_R (TLS_TPREL));
6712 rela.r_offset = globals->root.sgot->output_section->vma +
6713 globals->root.sgot->output_offset + off;
6715 loc = globals->root.srelgot->contents;
6716 loc += globals->root.srelgot->reloc_count++
6717 * RELOC_SIZE (htab);
6719 bfd_elfNN_swap_reloca_out (output_bfd, &rela, loc);
6721 bfd_put_NN (output_bfd, rela.r_addend,
6722 globals->root.sgot->contents + off);
6725 bfd_put_NN (output_bfd, relocation - tpoff_base (info),
6726 globals->root.sgot->contents + off);
6728 symbol_got_offset_mark (input_bfd, h, r_symndx);
6732 case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12:
6733 case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21:
6734 case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21:
6735 case BFD_RELOC_AARCH64_TLSDESC_LDNN_LO12_NC:
6736 case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19:
6737 case BFD_RELOC_AARCH64_TLSDESC_OFF_G0_NC:
6738 case BFD_RELOC_AARCH64_TLSDESC_OFF_G1:
6739 if (! symbol_tlsdesc_got_offset_mark_p (input_bfd, h, r_symndx))
6741 bfd_boolean need_relocs = FALSE;
6742 int indx = h && h->dynindx != -1 ? h->dynindx : 0;
6743 bfd_vma off = symbol_tlsdesc_got_offset (input_bfd, h, r_symndx);
6745 need_relocs = (h == NULL
6746 || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
6747 || h->root.type != bfd_link_hash_undefweak);
6749 BFD_ASSERT (globals->root.srelgot != NULL);
6750 BFD_ASSERT (globals->root.sgot != NULL);
6755 Elf_Internal_Rela rela;
6756 rela.r_info = ELFNN_R_INFO (indx, AARCH64_R (TLSDESC));
6759 rela.r_offset = (globals->root.sgotplt->output_section->vma
6760 + globals->root.sgotplt->output_offset
6761 + off + globals->sgotplt_jump_table_size);
6764 rela.r_addend = relocation - dtpoff_base (info);
6766 /* Allocate the next available slot in the PLT reloc
6767 section to hold our R_AARCH64_TLSDESC, the next
6768 available slot is determined from reloc_count,
6769 which we step. But note, reloc_count was
6770 artifically moved down while allocating slots for
6771 real PLT relocs such that all of the PLT relocs
6772 will fit above the initial reloc_count and the
6773 extra stuff will fit below. */
6774 loc = globals->root.srelplt->contents;
6775 loc += globals->root.srelplt->reloc_count++
6776 * RELOC_SIZE (globals);
6778 bfd_elfNN_swap_reloca_out (output_bfd, &rela, loc);
6780 bfd_put_NN (output_bfd, (bfd_vma) 0,
6781 globals->root.sgotplt->contents + off +
6782 globals->sgotplt_jump_table_size);
6783 bfd_put_NN (output_bfd, (bfd_vma) 0,
6784 globals->root.sgotplt->contents + off +
6785 globals->sgotplt_jump_table_size +
6789 symbol_tlsdesc_got_offset_mark (input_bfd, h, r_symndx);
6796 /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
6797 because such sections are not SEC_ALLOC and thus ld.so will
6798 not process them. */
6799 if (unresolved_reloc
6800 && !((input_section->flags & SEC_DEBUGGING) != 0
6802 && _bfd_elf_section_offset (output_bfd, info, input_section,
6803 +rel->r_offset) != (bfd_vma) - 1)
6806 /* xgettext:c-format */
6807 (_("%pB(%pA+%#" PRIx64 "): "
6808 "unresolvable %s relocation against symbol `%s'"),
6809 input_bfd, input_section, (uint64_t) rel->r_offset, howto->name,
6810 h->root.root.string);
6814 if (r != bfd_reloc_ok && r != bfd_reloc_continue)
6816 bfd_reloc_code_real_type real_r_type
6817 = elfNN_aarch64_bfd_reloc_from_type (input_bfd, r_type);
6821 case bfd_reloc_overflow:
6822 (*info->callbacks->reloc_overflow)
6823 (info, (h ? &h->root : NULL), name, howto->name, (bfd_vma) 0,
6824 input_bfd, input_section, rel->r_offset);
6825 if (real_r_type == BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15
6826 || real_r_type == BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14)
6828 (*info->callbacks->warning)
6830 _("too many GOT entries for -fpic, "
6831 "please recompile with -fPIC"),
6832 name, input_bfd, input_section, rel->r_offset);
6835 /* Overflow can occur when a variable is referenced with a type
6836 that has a larger alignment than the type with which it was
6838 file1.c: extern int foo; int a (void) { return foo; }
6839 file2.c: char bar, foo, baz;
6840 If the variable is placed into a data section at an offset
6841 that is incompatible with the larger alignment requirement
6842 overflow will occur. (Strictly speaking this is not overflow
6843 but rather an alignment problem, but the bfd_reloc_ error
6844 enum does not have a value to cover that situation).
6846 Try to catch this situation here and provide a more helpful
6847 error message to the user. */
6848 if (addend & ((1 << howto->rightshift) - 1)
6849 /* FIXME: Are we testing all of the appropriate reloc
6851 && (real_r_type == BFD_RELOC_AARCH64_LD_LO19_PCREL
6852 || real_r_type == BFD_RELOC_AARCH64_LDST16_LO12
6853 || real_r_type == BFD_RELOC_AARCH64_LDST32_LO12
6854 || real_r_type == BFD_RELOC_AARCH64_LDST64_LO12
6855 || real_r_type == BFD_RELOC_AARCH64_LDST128_LO12))
6857 info->callbacks->warning
6858 (info, _("one possible cause of this error is that the \
6859 symbol is being referenced in the indicated code as if it had a larger \
6860 alignment than was declared where it was defined"),
6861 name, input_bfd, input_section, rel->r_offset);
6865 case bfd_reloc_undefined:
6866 (*info->callbacks->undefined_symbol)
6867 (info, name, input_bfd, input_section, rel->r_offset, TRUE);
6870 case bfd_reloc_outofrange:
6871 error_message = _("out of range");
6874 case bfd_reloc_notsupported:
6875 error_message = _("unsupported relocation");
6878 case bfd_reloc_dangerous:
6879 /* error_message should already be set. */
6883 error_message = _("unknown error");
6887 BFD_ASSERT (error_message != NULL);
6888 (*info->callbacks->reloc_dangerous)
6889 (info, error_message, input_bfd, input_section, rel->r_offset);
6901 /* Set the right machine number. */
6904 elfNN_aarch64_object_p (bfd *abfd)
6907 bfd_default_set_arch_mach (abfd, bfd_arch_aarch64, bfd_mach_aarch64_ilp32);
6909 bfd_default_set_arch_mach (abfd, bfd_arch_aarch64, bfd_mach_aarch64);
6914 /* Function to keep AArch64 specific flags in the ELF header. */
6917 elfNN_aarch64_set_private_flags (bfd *abfd, flagword flags)
6919 if (elf_flags_init (abfd) && elf_elfheader (abfd)->e_flags != flags)
6924 elf_elfheader (abfd)->e_flags = flags;
6925 elf_flags_init (abfd) = TRUE;
6931 /* Merge backend specific data from an object file to the output
6932 object file when linking. */
6935 elfNN_aarch64_merge_private_bfd_data (bfd *ibfd, struct bfd_link_info *info)
6937 bfd *obfd = info->output_bfd;
6940 bfd_boolean flags_compatible = TRUE;
6943 /* Check if we have the same endianess. */
6944 if (!_bfd_generic_verify_endian_match (ibfd, info))
6947 if (!is_aarch64_elf (ibfd) || !is_aarch64_elf (obfd))
6950 /* The input BFD must have had its flags initialised. */
6951 /* The following seems bogus to me -- The flags are initialized in
6952 the assembler but I don't think an elf_flags_init field is
6953 written into the object. */
6954 /* BFD_ASSERT (elf_flags_init (ibfd)); */
6956 in_flags = elf_elfheader (ibfd)->e_flags;
6957 out_flags = elf_elfheader (obfd)->e_flags;
6959 if (!elf_flags_init (obfd))
6961 /* If the input is the default architecture and had the default
6962 flags then do not bother setting the flags for the output
6963 architecture, instead allow future merges to do this. If no
6964 future merges ever set these flags then they will retain their
6965 uninitialised values, which surprise surprise, correspond
6966 to the default values. */
6967 if (bfd_get_arch_info (ibfd)->the_default
6968 && elf_elfheader (ibfd)->e_flags == 0)
6971 elf_flags_init (obfd) = TRUE;
6972 elf_elfheader (obfd)->e_flags = in_flags;
6974 if (bfd_get_arch (obfd) == bfd_get_arch (ibfd)
6975 && bfd_get_arch_info (obfd)->the_default)
6976 return bfd_set_arch_mach (obfd, bfd_get_arch (ibfd),
6977 bfd_get_mach (ibfd));
6982 /* Identical flags must be compatible. */
6983 if (in_flags == out_flags)
6986 /* Check to see if the input BFD actually contains any sections. If
6987 not, its flags may not have been initialised either, but it
6988 cannot actually cause any incompatiblity. Do not short-circuit
6989 dynamic objects; their section list may be emptied by
6990 elf_link_add_object_symbols.
6992 Also check to see if there are no code sections in the input.
6993 In this case there is no need to check for code specific flags.
6994 XXX - do we need to worry about floating-point format compatability
6995 in data sections ? */
6996 if (!(ibfd->flags & DYNAMIC))
6998 bfd_boolean null_input_bfd = TRUE;
6999 bfd_boolean only_data_sections = TRUE;
7001 for (sec = ibfd->sections; sec != NULL; sec = sec->next)
7003 if ((bfd_get_section_flags (ibfd, sec)
7004 & (SEC_LOAD | SEC_CODE | SEC_HAS_CONTENTS))
7005 == (SEC_LOAD | SEC_CODE | SEC_HAS_CONTENTS))
7006 only_data_sections = FALSE;
7008 null_input_bfd = FALSE;
7012 if (null_input_bfd || only_data_sections)
7016 return flags_compatible;
7019 /* Display the flags field. */
7022 elfNN_aarch64_print_private_bfd_data (bfd *abfd, void *ptr)
7024 FILE *file = (FILE *) ptr;
7025 unsigned long flags;
7027 BFD_ASSERT (abfd != NULL && ptr != NULL);
7029 /* Print normal ELF private data. */
7030 _bfd_elf_print_private_bfd_data (abfd, ptr);
7032 flags = elf_elfheader (abfd)->e_flags;
7033 /* Ignore init flag - it may not be set, despite the flags field
7034 containing valid data. */
7036 /* xgettext:c-format */
7037 fprintf (file, _("private flags = %lx:"), elf_elfheader (abfd)->e_flags);
7040 fprintf (file, _("<Unrecognised flag bits set>"));
7047 /* Find dynamic relocs for H that apply to read-only sections. */
7050 readonly_dynrelocs (struct elf_link_hash_entry *h)
7052 struct elf_dyn_relocs *p;
7054 for (p = elf_aarch64_hash_entry (h)->dyn_relocs; p != NULL; p = p->next)
7056 asection *s = p->sec->output_section;
7058 if (s != NULL && (s->flags & SEC_READONLY) != 0)
7064 /* Return true if we need copy relocation against EH. */
7067 need_copy_relocation_p (struct elf_aarch64_link_hash_entry *eh)
7069 struct elf_dyn_relocs *p;
7072 for (p = eh->dyn_relocs; p != NULL; p = p->next)
7074 /* If there is any pc-relative reference, we need to keep copy relocation
7075 to avoid propagating the relocation into runtime that current glibc
7076 does not support. */
7080 s = p->sec->output_section;
7081 /* Need copy relocation if it's against read-only section. */
7082 if (s != NULL && (s->flags & SEC_READONLY) != 0)
7089 /* Adjust a symbol defined by a dynamic object and referenced by a
7090 regular object. The current definition is in some section of the
7091 dynamic object, but we're not including those sections. We have to
7092 change the definition to something the rest of the link can
7096 elfNN_aarch64_adjust_dynamic_symbol (struct bfd_link_info *info,
7097 struct elf_link_hash_entry *h)
7099 struct elf_aarch64_link_hash_table *htab;
7102 /* If this is a function, put it in the procedure linkage table. We
7103 will fill in the contents of the procedure linkage table later,
7104 when we know the address of the .got section. */
7105 if (h->type == STT_FUNC || h->type == STT_GNU_IFUNC || h->needs_plt)
7107 if (h->plt.refcount <= 0
7108 || (h->type != STT_GNU_IFUNC
7109 && (SYMBOL_CALLS_LOCAL (info, h)
7110 || (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
7111 && h->root.type == bfd_link_hash_undefweak))))
7113 /* This case can occur if we saw a CALL26 reloc in
7114 an input file, but the symbol wasn't referred to
7115 by a dynamic object or all references were
7116 garbage collected. In which case we can end up
7118 h->plt.offset = (bfd_vma) - 1;
7125 /* Otherwise, reset to -1. */
7126 h->plt.offset = (bfd_vma) - 1;
7129 /* If this is a weak symbol, and there is a real definition, the
7130 processor independent code will have arranged for us to see the
7131 real definition first, and we can just use the same value. */
7132 if (h->is_weakalias)
7134 struct elf_link_hash_entry *def = weakdef (h);
7135 BFD_ASSERT (def->root.type == bfd_link_hash_defined);
7136 h->root.u.def.section = def->root.u.def.section;
7137 h->root.u.def.value = def->root.u.def.value;
7138 if (ELIMINATE_COPY_RELOCS || info->nocopyreloc)
7139 h->non_got_ref = def->non_got_ref;
7143 /* If we are creating a shared library, we must presume that the
7144 only references to the symbol are via the global offset table.
7145 For such cases we need not do anything here; the relocations will
7146 be handled correctly by relocate_section. */
7147 if (bfd_link_pic (info))
7150 /* If there are no references to this symbol that do not use the
7151 GOT, we don't need to generate a copy reloc. */
7152 if (!h->non_got_ref)
7155 /* If -z nocopyreloc was given, we won't generate them either. */
7156 if (info->nocopyreloc)
7162 if (ELIMINATE_COPY_RELOCS)
7164 struct elf_aarch64_link_hash_entry *eh;
7165 /* If we don't find any dynamic relocs in read-only sections, then
7166 we'll be keeping the dynamic relocs and avoiding the copy reloc. */
7167 eh = (struct elf_aarch64_link_hash_entry *) h;
7168 if (!need_copy_relocation_p (eh))
7175 /* We must allocate the symbol in our .dynbss section, which will
7176 become part of the .bss section of the executable. There will be
7177 an entry for this symbol in the .dynsym section. The dynamic
7178 object will contain position independent code, so all references
7179 from the dynamic object to this symbol will go through the global
7180 offset table. The dynamic linker will use the .dynsym entry to
7181 determine the address it must put in the global offset table, so
7182 both the dynamic object and the regular object will refer to the
7183 same memory location for the variable. */
7185 htab = elf_aarch64_hash_table (info);
7187 /* We must generate a R_AARCH64_COPY reloc to tell the dynamic linker
7188 to copy the initial value out of the dynamic object and into the
7189 runtime process image. */
7190 if ((h->root.u.def.section->flags & SEC_READONLY) != 0)
7192 s = htab->root.sdynrelro;
7193 srel = htab->root.sreldynrelro;
7197 s = htab->root.sdynbss;
7198 srel = htab->root.srelbss;
7200 if ((h->root.u.def.section->flags & SEC_ALLOC) != 0 && h->size != 0)
7202 srel->size += RELOC_SIZE (htab);
7206 return _bfd_elf_adjust_dynamic_copy (info, h, s);
7211 elfNN_aarch64_allocate_local_symbols (bfd *abfd, unsigned number)
7213 struct elf_aarch64_local_symbol *locals;
7214 locals = elf_aarch64_locals (abfd);
7217 locals = (struct elf_aarch64_local_symbol *)
7218 bfd_zalloc (abfd, number * sizeof (struct elf_aarch64_local_symbol));
7221 elf_aarch64_locals (abfd) = locals;
7226 /* Create the .got section to hold the global offset table. */
7229 aarch64_elf_create_got_section (bfd *abfd, struct bfd_link_info *info)
7231 const struct elf_backend_data *bed = get_elf_backend_data (abfd);
7234 struct elf_link_hash_entry *h;
7235 struct elf_link_hash_table *htab = elf_hash_table (info);
7237 /* This function may be called more than once. */
7238 if (htab->sgot != NULL)
7241 flags = bed->dynamic_sec_flags;
7243 s = bfd_make_section_anyway_with_flags (abfd,
7244 (bed->rela_plts_and_copies_p
7245 ? ".rela.got" : ".rel.got"),
7246 (bed->dynamic_sec_flags
7249 || ! bfd_set_section_alignment (abfd, s, bed->s->log_file_align))
7253 s = bfd_make_section_anyway_with_flags (abfd, ".got", flags);
7255 || !bfd_set_section_alignment (abfd, s, bed->s->log_file_align))
7258 htab->sgot->size += GOT_ENTRY_SIZE;
7260 if (bed->want_got_sym)
7262 /* Define the symbol _GLOBAL_OFFSET_TABLE_ at the start of the .got
7263 (or .got.plt) section. We don't do this in the linker script
7264 because we don't want to define the symbol if we are not creating
7265 a global offset table. */
7266 h = _bfd_elf_define_linkage_sym (abfd, info, s,
7267 "_GLOBAL_OFFSET_TABLE_");
7268 elf_hash_table (info)->hgot = h;
7273 if (bed->want_got_plt)
7275 s = bfd_make_section_anyway_with_flags (abfd, ".got.plt", flags);
7277 || !bfd_set_section_alignment (abfd, s,
7278 bed->s->log_file_align))
7283 /* The first bit of the global offset table is the header. */
7284 s->size += bed->got_header_size;
7289 /* Look through the relocs for a section during the first phase. */
7292 elfNN_aarch64_check_relocs (bfd *abfd, struct bfd_link_info *info,
7293 asection *sec, const Elf_Internal_Rela *relocs)
7295 Elf_Internal_Shdr *symtab_hdr;
7296 struct elf_link_hash_entry **sym_hashes;
7297 const Elf_Internal_Rela *rel;
7298 const Elf_Internal_Rela *rel_end;
7301 struct elf_aarch64_link_hash_table *htab;
7303 if (bfd_link_relocatable (info))
7306 BFD_ASSERT (is_aarch64_elf (abfd));
7308 htab = elf_aarch64_hash_table (info);
7311 symtab_hdr = &elf_symtab_hdr (abfd);
7312 sym_hashes = elf_sym_hashes (abfd);
7314 rel_end = relocs + sec->reloc_count;
7315 for (rel = relocs; rel < rel_end; rel++)
7317 struct elf_link_hash_entry *h;
7318 unsigned int r_symndx;
7319 unsigned int r_type;
7320 bfd_reloc_code_real_type bfd_r_type;
7321 Elf_Internal_Sym *isym;
7323 r_symndx = ELFNN_R_SYM (rel->r_info);
7324 r_type = ELFNN_R_TYPE (rel->r_info);
7326 if (r_symndx >= NUM_SHDR_ENTRIES (symtab_hdr))
7328 /* xgettext:c-format */
7329 _bfd_error_handler (_("%pB: bad symbol index: %d"), abfd, r_symndx);
7333 if (r_symndx < symtab_hdr->sh_info)
7335 /* A local symbol. */
7336 isym = bfd_sym_from_r_symndx (&htab->sym_cache,
7341 /* Check relocation against local STT_GNU_IFUNC symbol. */
7342 if (ELF_ST_TYPE (isym->st_info) == STT_GNU_IFUNC)
7344 h = elfNN_aarch64_get_local_sym_hash (htab, abfd, rel,
7349 /* Fake a STT_GNU_IFUNC symbol. */
7350 h->type = STT_GNU_IFUNC;
7353 h->forced_local = 1;
7354 h->root.type = bfd_link_hash_defined;
7361 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
7362 while (h->root.type == bfd_link_hash_indirect
7363 || h->root.type == bfd_link_hash_warning)
7364 h = (struct elf_link_hash_entry *) h->root.u.i.link;
7367 /* Could be done earlier, if h were already available. */
7368 bfd_r_type = aarch64_tls_transition (abfd, info, r_type, h, r_symndx);
7372 /* If a relocation refers to _GLOBAL_OFFSET_TABLE_, create the .got.
7373 This shows up in particular in an R_AARCH64_PREL64 in large model
7374 when calculating the pc-relative address to .got section which is
7375 used to initialize the gp register. */
7376 if (h->root.root.string
7377 && strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0)
7379 if (htab->root.dynobj == NULL)
7380 htab->root.dynobj = abfd;
7382 if (! aarch64_elf_create_got_section (htab->root.dynobj, info))
7385 BFD_ASSERT (h == htab->root.hgot);
7388 /* Create the ifunc sections for static executables. If we
7389 never see an indirect function symbol nor we are building
7390 a static executable, those sections will be empty and
7391 won't appear in output. */
7397 case BFD_RELOC_AARCH64_ADD_LO12:
7398 case BFD_RELOC_AARCH64_ADR_GOT_PAGE:
7399 case BFD_RELOC_AARCH64_ADR_HI21_PCREL:
7400 case BFD_RELOC_AARCH64_CALL26:
7401 case BFD_RELOC_AARCH64_GOT_LD_PREL19:
7402 case BFD_RELOC_AARCH64_JUMP26:
7403 case BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14:
7404 case BFD_RELOC_AARCH64_LD32_GOT_LO12_NC:
7405 case BFD_RELOC_AARCH64_LD64_GOTOFF_LO15:
7406 case BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15:
7407 case BFD_RELOC_AARCH64_LD64_GOT_LO12_NC:
7408 case BFD_RELOC_AARCH64_MOVW_GOTOFF_G0_NC:
7409 case BFD_RELOC_AARCH64_MOVW_GOTOFF_G1:
7410 case BFD_RELOC_AARCH64_NN:
7411 if (htab->root.dynobj == NULL)
7412 htab->root.dynobj = abfd;
7413 if (!_bfd_elf_create_ifunc_sections (htab->root.dynobj, info))
7418 /* It is referenced by a non-shared object. */
7424 case BFD_RELOC_AARCH64_16:
7426 case BFD_RELOC_AARCH64_32:
7428 if (bfd_link_pic (info) && (sec->flags & SEC_ALLOC) != 0)
7431 /* This is an absolute symbol. It represents a value instead
7433 && (bfd_is_abs_symbol (&h->root)
7434 /* This is an undefined symbol. */
7435 || h->root.type == bfd_link_hash_undefined))
7438 /* For local symbols, defined global symbols in a non-ABS section,
7439 it is assumed that the value is an address. */
7440 int howto_index = bfd_r_type - BFD_RELOC_AARCH64_RELOC_START;
7442 /* xgettext:c-format */
7443 (_("%pB: relocation %s against `%s' can not be used when making "
7445 abfd, elfNN_aarch64_howto_table[howto_index].name,
7446 (h) ? h->root.root.string : "a local symbol");
7447 bfd_set_error (bfd_error_bad_value);
7453 case BFD_RELOC_AARCH64_MOVW_G0_NC:
7454 case BFD_RELOC_AARCH64_MOVW_G1_NC:
7455 case BFD_RELOC_AARCH64_MOVW_G2_NC:
7456 case BFD_RELOC_AARCH64_MOVW_G3:
7457 if (bfd_link_pic (info))
7459 int howto_index = bfd_r_type - BFD_RELOC_AARCH64_RELOC_START;
7461 /* xgettext:c-format */
7462 (_("%pB: relocation %s against `%s' can not be used when making "
7463 "a shared object; recompile with -fPIC"),
7464 abfd, elfNN_aarch64_howto_table[howto_index].name,
7465 (h) ? h->root.root.string : "a local symbol");
7466 bfd_set_error (bfd_error_bad_value);
7471 case BFD_RELOC_AARCH64_16_PCREL:
7472 case BFD_RELOC_AARCH64_32_PCREL:
7473 case BFD_RELOC_AARCH64_64_PCREL:
7474 case BFD_RELOC_AARCH64_ADD_LO12:
7475 case BFD_RELOC_AARCH64_ADR_HI21_NC_PCREL:
7476 case BFD_RELOC_AARCH64_ADR_HI21_PCREL:
7477 case BFD_RELOC_AARCH64_ADR_LO21_PCREL:
7478 case BFD_RELOC_AARCH64_LDST128_LO12:
7479 case BFD_RELOC_AARCH64_LDST16_LO12:
7480 case BFD_RELOC_AARCH64_LDST32_LO12:
7481 case BFD_RELOC_AARCH64_LDST64_LO12:
7482 case BFD_RELOC_AARCH64_LDST8_LO12:
7483 case BFD_RELOC_AARCH64_LD_LO19_PCREL:
7484 if (h == NULL || bfd_link_pic (info))
7488 case BFD_RELOC_AARCH64_NN:
7490 /* We don't need to handle relocs into sections not going into
7491 the "real" output. */
7492 if ((sec->flags & SEC_ALLOC) == 0)
7497 if (!bfd_link_pic (info))
7500 h->plt.refcount += 1;
7501 h->pointer_equality_needed = 1;
7504 /* No need to do anything if we're not creating a shared
7506 if (!(bfd_link_pic (info)
7507 /* If on the other hand, we are creating an executable, we
7508 may need to keep relocations for symbols satisfied by a
7509 dynamic library if we manage to avoid copy relocs for the
7512 NOTE: Currently, there is no support of copy relocs
7513 elimination on pc-relative relocation types, because there is
7514 no dynamic relocation support for them in glibc. We still
7515 record the dynamic symbol reference for them. This is
7516 because one symbol may be referenced by both absolute
7517 relocation (for example, BFD_RELOC_AARCH64_NN) and
7518 pc-relative relocation. We need full symbol reference
7519 information to make correct decision later in
7520 elfNN_aarch64_adjust_dynamic_symbol. */
7521 || (ELIMINATE_COPY_RELOCS
7522 && !bfd_link_pic (info)
7524 && (h->root.type == bfd_link_hash_defweak
7525 || !h->def_regular))))
7529 struct elf_dyn_relocs *p;
7530 struct elf_dyn_relocs **head;
7531 int howto_index = bfd_r_type - BFD_RELOC_AARCH64_RELOC_START;
7533 /* We must copy these reloc types into the output file.
7534 Create a reloc section in dynobj and make room for
7538 if (htab->root.dynobj == NULL)
7539 htab->root.dynobj = abfd;
7541 sreloc = _bfd_elf_make_dynamic_reloc_section
7542 (sec, htab->root.dynobj, LOG_FILE_ALIGN, abfd, /*rela? */ TRUE);
7548 /* If this is a global symbol, we count the number of
7549 relocations we need for this symbol. */
7552 struct elf_aarch64_link_hash_entry *eh;
7553 eh = (struct elf_aarch64_link_hash_entry *) h;
7554 head = &eh->dyn_relocs;
7558 /* Track dynamic relocs needed for local syms too.
7559 We really need local syms available to do this
7565 isym = bfd_sym_from_r_symndx (&htab->sym_cache,
7570 s = bfd_section_from_elf_index (abfd, isym->st_shndx);
7574 /* Beware of type punned pointers vs strict aliasing
7576 vpp = &(elf_section_data (s)->local_dynrel);
7577 head = (struct elf_dyn_relocs **) vpp;
7581 if (p == NULL || p->sec != sec)
7583 bfd_size_type amt = sizeof *p;
7584 p = ((struct elf_dyn_relocs *)
7585 bfd_zalloc (htab->root.dynobj, amt));
7595 if (elfNN_aarch64_howto_table[howto_index].pc_relative)
7600 /* RR: We probably want to keep a consistency check that
7601 there are no dangling GOT_PAGE relocs. */
7602 case BFD_RELOC_AARCH64_ADR_GOT_PAGE:
7603 case BFD_RELOC_AARCH64_GOT_LD_PREL19:
7604 case BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14:
7605 case BFD_RELOC_AARCH64_LD32_GOT_LO12_NC:
7606 case BFD_RELOC_AARCH64_LD64_GOTOFF_LO15:
7607 case BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15:
7608 case BFD_RELOC_AARCH64_LD64_GOT_LO12_NC:
7609 case BFD_RELOC_AARCH64_MOVW_GOTOFF_G0_NC:
7610 case BFD_RELOC_AARCH64_MOVW_GOTOFF_G1:
7611 case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12:
7612 case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21:
7613 case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21:
7614 case BFD_RELOC_AARCH64_TLSDESC_LD32_LO12_NC:
7615 case BFD_RELOC_AARCH64_TLSDESC_LD64_LO12:
7616 case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19:
7617 case BFD_RELOC_AARCH64_TLSDESC_OFF_G0_NC:
7618 case BFD_RELOC_AARCH64_TLSDESC_OFF_G1:
7619 case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC:
7620 case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21:
7621 case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21:
7622 case BFD_RELOC_AARCH64_TLSGD_MOVW_G0_NC:
7623 case BFD_RELOC_AARCH64_TLSGD_MOVW_G1:
7624 case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21:
7625 case BFD_RELOC_AARCH64_TLSIE_LD32_GOTTPREL_LO12_NC:
7626 case BFD_RELOC_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC:
7627 case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19:
7628 case BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G0_NC:
7629 case BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G1:
7630 case BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC:
7631 case BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21:
7632 case BFD_RELOC_AARCH64_TLSLD_ADR_PREL21:
7635 unsigned old_got_type;
7637 got_type = aarch64_reloc_got_type (bfd_r_type);
7641 h->got.refcount += 1;
7642 old_got_type = elf_aarch64_hash_entry (h)->got_type;
7646 struct elf_aarch64_local_symbol *locals;
7648 if (!elfNN_aarch64_allocate_local_symbols
7649 (abfd, symtab_hdr->sh_info))
7652 locals = elf_aarch64_locals (abfd);
7653 BFD_ASSERT (r_symndx < symtab_hdr->sh_info);
7654 locals[r_symndx].got_refcount += 1;
7655 old_got_type = locals[r_symndx].got_type;
7658 /* If a variable is accessed with both general dynamic TLS
7659 methods, two slots may be created. */
7660 if (GOT_TLS_GD_ANY_P (old_got_type) && GOT_TLS_GD_ANY_P (got_type))
7661 got_type |= old_got_type;
7663 /* We will already have issued an error message if there
7664 is a TLS/non-TLS mismatch, based on the symbol type.
7665 So just combine any TLS types needed. */
7666 if (old_got_type != GOT_UNKNOWN && old_got_type != GOT_NORMAL
7667 && got_type != GOT_NORMAL)
7668 got_type |= old_got_type;
7670 /* If the symbol is accessed by both IE and GD methods, we
7671 are able to relax. Turn off the GD flag, without
7672 messing up with any other kind of TLS types that may be
7674 if ((got_type & GOT_TLS_IE) && GOT_TLS_GD_ANY_P (got_type))
7675 got_type &= ~ (GOT_TLSDESC_GD | GOT_TLS_GD);
7677 if (old_got_type != got_type)
7680 elf_aarch64_hash_entry (h)->got_type = got_type;
7683 struct elf_aarch64_local_symbol *locals;
7684 locals = elf_aarch64_locals (abfd);
7685 BFD_ASSERT (r_symndx < symtab_hdr->sh_info);
7686 locals[r_symndx].got_type = got_type;
7690 if (htab->root.dynobj == NULL)
7691 htab->root.dynobj = abfd;
7692 if (! aarch64_elf_create_got_section (htab->root.dynobj, info))
7697 case BFD_RELOC_AARCH64_CALL26:
7698 case BFD_RELOC_AARCH64_JUMP26:
7699 /* If this is a local symbol then we resolve it
7700 directly without creating a PLT entry. */
7705 if (h->plt.refcount <= 0)
7706 h->plt.refcount = 1;
7708 h->plt.refcount += 1;
7719 /* Treat mapping symbols as special target symbols. */
7722 elfNN_aarch64_is_target_special_symbol (bfd *abfd ATTRIBUTE_UNUSED,
7725 return bfd_is_aarch64_special_symbol_name (sym->name,
7726 BFD_AARCH64_SPECIAL_SYM_TYPE_ANY);
7729 /* This is a copy of elf_find_function () from elf.c except that
7730 AArch64 mapping symbols are ignored when looking for function names. */
7733 aarch64_elf_find_function (bfd *abfd ATTRIBUTE_UNUSED,
7737 const char **filename_ptr,
7738 const char **functionname_ptr)
7740 const char *filename = NULL;
7741 asymbol *func = NULL;
7742 bfd_vma low_func = 0;
7745 for (p = symbols; *p != NULL; p++)
7749 q = (elf_symbol_type *) * p;
7751 switch (ELF_ST_TYPE (q->internal_elf_sym.st_info))
7756 filename = bfd_asymbol_name (&q->symbol);
7760 /* Skip mapping symbols. */
7761 if ((q->symbol.flags & BSF_LOCAL)
7762 && (bfd_is_aarch64_special_symbol_name
7763 (q->symbol.name, BFD_AARCH64_SPECIAL_SYM_TYPE_ANY)))
7766 if (bfd_get_section (&q->symbol) == section
7767 && q->symbol.value >= low_func && q->symbol.value <= offset)
7769 func = (asymbol *) q;
7770 low_func = q->symbol.value;
7780 *filename_ptr = filename;
7781 if (functionname_ptr)
7782 *functionname_ptr = bfd_asymbol_name (func);
7788 /* Find the nearest line to a particular section and offset, for error
7789 reporting. This code is a duplicate of the code in elf.c, except
7790 that it uses aarch64_elf_find_function. */
7793 elfNN_aarch64_find_nearest_line (bfd *abfd,
7797 const char **filename_ptr,
7798 const char **functionname_ptr,
7799 unsigned int *line_ptr,
7800 unsigned int *discriminator_ptr)
7802 bfd_boolean found = FALSE;
7804 if (_bfd_dwarf2_find_nearest_line (abfd, symbols, NULL, section, offset,
7805 filename_ptr, functionname_ptr,
7806 line_ptr, discriminator_ptr,
7807 dwarf_debug_sections, 0,
7808 &elf_tdata (abfd)->dwarf2_find_line_info))
7810 if (!*functionname_ptr)
7811 aarch64_elf_find_function (abfd, symbols, section, offset,
7812 *filename_ptr ? NULL : filename_ptr,
7818 /* Skip _bfd_dwarf1_find_nearest_line since no known AArch64
7819 toolchain uses DWARF1. */
7821 if (!_bfd_stab_section_find_nearest_line (abfd, symbols, section, offset,
7822 &found, filename_ptr,
7823 functionname_ptr, line_ptr,
7824 &elf_tdata (abfd)->line_info))
7827 if (found && (*functionname_ptr || *line_ptr))
7830 if (symbols == NULL)
7833 if (!aarch64_elf_find_function (abfd, symbols, section, offset,
7834 filename_ptr, functionname_ptr))
7842 elfNN_aarch64_find_inliner_info (bfd *abfd,
7843 const char **filename_ptr,
7844 const char **functionname_ptr,
7845 unsigned int *line_ptr)
7848 found = _bfd_dwarf2_find_inliner_info
7849 (abfd, filename_ptr,
7850 functionname_ptr, line_ptr, &elf_tdata (abfd)->dwarf2_find_line_info);
7856 elfNN_aarch64_post_process_headers (bfd *abfd,
7857 struct bfd_link_info *link_info)
7859 Elf_Internal_Ehdr *i_ehdrp; /* ELF file header, internal form. */
7861 i_ehdrp = elf_elfheader (abfd);
7862 i_ehdrp->e_ident[EI_ABIVERSION] = AARCH64_ELF_ABI_VERSION;
7864 _bfd_elf_post_process_headers (abfd, link_info);
7867 static enum elf_reloc_type_class
7868 elfNN_aarch64_reloc_type_class (const struct bfd_link_info *info ATTRIBUTE_UNUSED,
7869 const asection *rel_sec ATTRIBUTE_UNUSED,
7870 const Elf_Internal_Rela *rela)
7872 struct elf_aarch64_link_hash_table *htab = elf_aarch64_hash_table (info);
7874 if (htab->root.dynsym != NULL
7875 && htab->root.dynsym->contents != NULL)
7877 /* Check relocation against STT_GNU_IFUNC symbol if there are
7879 bfd *abfd = info->output_bfd;
7880 const struct elf_backend_data *bed = get_elf_backend_data (abfd);
7881 unsigned long r_symndx = ELFNN_R_SYM (rela->r_info);
7882 if (r_symndx != STN_UNDEF)
7884 Elf_Internal_Sym sym;
7885 if (!bed->s->swap_symbol_in (abfd,
7886 (htab->root.dynsym->contents
7887 + r_symndx * bed->s->sizeof_sym),
7890 /* xgettext:c-format */
7891 _bfd_error_handler (_("%pB symbol number %lu references"
7892 " nonexistent SHT_SYMTAB_SHNDX section"),
7894 /* Ideally an error class should be returned here. */
7896 else if (ELF_ST_TYPE (sym.st_info) == STT_GNU_IFUNC)
7897 return reloc_class_ifunc;
7901 switch ((int) ELFNN_R_TYPE (rela->r_info))
7903 case AARCH64_R (IRELATIVE):
7904 return reloc_class_ifunc;
7905 case AARCH64_R (RELATIVE):
7906 return reloc_class_relative;
7907 case AARCH64_R (JUMP_SLOT):
7908 return reloc_class_plt;
7909 case AARCH64_R (COPY):
7910 return reloc_class_copy;
7912 return reloc_class_normal;
7916 /* Handle an AArch64 specific section when reading an object file. This is
7917 called when bfd_section_from_shdr finds a section with an unknown
7921 elfNN_aarch64_section_from_shdr (bfd *abfd,
7922 Elf_Internal_Shdr *hdr,
7923 const char *name, int shindex)
7925 /* There ought to be a place to keep ELF backend specific flags, but
7926 at the moment there isn't one. We just keep track of the
7927 sections by their name, instead. Fortunately, the ABI gives
7928 names for all the AArch64 specific sections, so we will probably get
7930 switch (hdr->sh_type)
7932 case SHT_AARCH64_ATTRIBUTES:
7939 if (!_bfd_elf_make_section_from_shdr (abfd, hdr, name, shindex))
7945 /* A structure used to record a list of sections, independently
7946 of the next and prev fields in the asection structure. */
7947 typedef struct section_list
7950 struct section_list *next;
7951 struct section_list *prev;
7955 /* Unfortunately we need to keep a list of sections for which
7956 an _aarch64_elf_section_data structure has been allocated. This
7957 is because it is possible for functions like elfNN_aarch64_write_section
7958 to be called on a section which has had an elf_data_structure
7959 allocated for it (and so the used_by_bfd field is valid) but
7960 for which the AArch64 extended version of this structure - the
7961 _aarch64_elf_section_data structure - has not been allocated. */
7962 static section_list *sections_with_aarch64_elf_section_data = NULL;
7965 record_section_with_aarch64_elf_section_data (asection *sec)
7967 struct section_list *entry;
7969 entry = bfd_malloc (sizeof (*entry));
7973 entry->next = sections_with_aarch64_elf_section_data;
7975 if (entry->next != NULL)
7976 entry->next->prev = entry;
7977 sections_with_aarch64_elf_section_data = entry;
7980 static struct section_list *
7981 find_aarch64_elf_section_entry (asection *sec)
7983 struct section_list *entry;
7984 static struct section_list *last_entry = NULL;
7986 /* This is a short cut for the typical case where the sections are added
7987 to the sections_with_aarch64_elf_section_data list in forward order and
7988 then looked up here in backwards order. This makes a real difference
7989 to the ld-srec/sec64k.exp linker test. */
7990 entry = sections_with_aarch64_elf_section_data;
7991 if (last_entry != NULL)
7993 if (last_entry->sec == sec)
7995 else if (last_entry->next != NULL && last_entry->next->sec == sec)
7996 entry = last_entry->next;
7999 for (; entry; entry = entry->next)
8000 if (entry->sec == sec)
8004 /* Record the entry prior to this one - it is the entry we are
8005 most likely to want to locate next time. Also this way if we
8006 have been called from
8007 unrecord_section_with_aarch64_elf_section_data () we will not
8008 be caching a pointer that is about to be freed. */
8009 last_entry = entry->prev;
8015 unrecord_section_with_aarch64_elf_section_data (asection *sec)
8017 struct section_list *entry;
8019 entry = find_aarch64_elf_section_entry (sec);
8023 if (entry->prev != NULL)
8024 entry->prev->next = entry->next;
8025 if (entry->next != NULL)
8026 entry->next->prev = entry->prev;
8027 if (entry == sections_with_aarch64_elf_section_data)
8028 sections_with_aarch64_elf_section_data = entry->next;
8037 struct bfd_link_info *info;
8040 int (*func) (void *, const char *, Elf_Internal_Sym *,
8041 asection *, struct elf_link_hash_entry *);
8042 } output_arch_syminfo;
8044 enum map_symbol_type
8051 /* Output a single mapping symbol. */
8054 elfNN_aarch64_output_map_sym (output_arch_syminfo *osi,
8055 enum map_symbol_type type, bfd_vma offset)
8057 static const char *names[2] = { "$x", "$d" };
8058 Elf_Internal_Sym sym;
8060 sym.st_value = (osi->sec->output_section->vma
8061 + osi->sec->output_offset + offset);
8064 sym.st_info = ELF_ST_INFO (STB_LOCAL, STT_NOTYPE);
8065 sym.st_shndx = osi->sec_shndx;
8066 return osi->func (osi->finfo, names[type], &sym, osi->sec, NULL) == 1;
8069 /* Output a single local symbol for a generated stub. */
8072 elfNN_aarch64_output_stub_sym (output_arch_syminfo *osi, const char *name,
8073 bfd_vma offset, bfd_vma size)
8075 Elf_Internal_Sym sym;
8077 sym.st_value = (osi->sec->output_section->vma
8078 + osi->sec->output_offset + offset);
8081 sym.st_info = ELF_ST_INFO (STB_LOCAL, STT_FUNC);
8082 sym.st_shndx = osi->sec_shndx;
8083 return osi->func (osi->finfo, name, &sym, osi->sec, NULL) == 1;
8087 aarch64_map_one_stub (struct bfd_hash_entry *gen_entry, void *in_arg)
8089 struct elf_aarch64_stub_hash_entry *stub_entry;
8093 output_arch_syminfo *osi;
8095 /* Massage our args to the form they really have. */
8096 stub_entry = (struct elf_aarch64_stub_hash_entry *) gen_entry;
8097 osi = (output_arch_syminfo *) in_arg;
8099 stub_sec = stub_entry->stub_sec;
8101 /* Ensure this stub is attached to the current section being
8103 if (stub_sec != osi->sec)
8106 addr = (bfd_vma) stub_entry->stub_offset;
8108 stub_name = stub_entry->output_name;
8110 switch (stub_entry->stub_type)
8112 case aarch64_stub_adrp_branch:
8113 if (!elfNN_aarch64_output_stub_sym (osi, stub_name, addr,
8114 sizeof (aarch64_adrp_branch_stub)))
8116 if (!elfNN_aarch64_output_map_sym (osi, AARCH64_MAP_INSN, addr))
8119 case aarch64_stub_long_branch:
8120 if (!elfNN_aarch64_output_stub_sym
8121 (osi, stub_name, addr, sizeof (aarch64_long_branch_stub)))
8123 if (!elfNN_aarch64_output_map_sym (osi, AARCH64_MAP_INSN, addr))
8125 if (!elfNN_aarch64_output_map_sym (osi, AARCH64_MAP_DATA, addr + 16))
8128 case aarch64_stub_erratum_835769_veneer:
8129 if (!elfNN_aarch64_output_stub_sym (osi, stub_name, addr,
8130 sizeof (aarch64_erratum_835769_stub)))
8132 if (!elfNN_aarch64_output_map_sym (osi, AARCH64_MAP_INSN, addr))
8135 case aarch64_stub_erratum_843419_veneer:
8136 if (!elfNN_aarch64_output_stub_sym (osi, stub_name, addr,
8137 sizeof (aarch64_erratum_843419_stub)))
8139 if (!elfNN_aarch64_output_map_sym (osi, AARCH64_MAP_INSN, addr))
8142 case aarch64_stub_none:
8152 /* Output mapping symbols for linker generated sections. */
8155 elfNN_aarch64_output_arch_local_syms (bfd *output_bfd,
8156 struct bfd_link_info *info,
8158 int (*func) (void *, const char *,
8161 struct elf_link_hash_entry
8164 output_arch_syminfo osi;
8165 struct elf_aarch64_link_hash_table *htab;
8167 htab = elf_aarch64_hash_table (info);
8173 /* Long calls stubs. */
8174 if (htab->stub_bfd && htab->stub_bfd->sections)
8178 for (stub_sec = htab->stub_bfd->sections;
8179 stub_sec != NULL; stub_sec = stub_sec->next)
8181 /* Ignore non-stub sections. */
8182 if (!strstr (stub_sec->name, STUB_SUFFIX))
8187 osi.sec_shndx = _bfd_elf_section_from_bfd_section
8188 (output_bfd, osi.sec->output_section);
8190 /* The first instruction in a stub is always a branch. */
8191 if (!elfNN_aarch64_output_map_sym (&osi, AARCH64_MAP_INSN, 0))
8194 bfd_hash_traverse (&htab->stub_hash_table, aarch64_map_one_stub,
8199 /* Finally, output mapping symbols for the PLT. */
8200 if (!htab->root.splt || htab->root.splt->size == 0)
8203 osi.sec_shndx = _bfd_elf_section_from_bfd_section
8204 (output_bfd, htab->root.splt->output_section);
8205 osi.sec = htab->root.splt;
8207 elfNN_aarch64_output_map_sym (&osi, AARCH64_MAP_INSN, 0);
8213 /* Allocate target specific section data. */
8216 elfNN_aarch64_new_section_hook (bfd *abfd, asection *sec)
8218 if (!sec->used_by_bfd)
8220 _aarch64_elf_section_data *sdata;
8221 bfd_size_type amt = sizeof (*sdata);
8223 sdata = bfd_zalloc (abfd, amt);
8226 sec->used_by_bfd = sdata;
8229 record_section_with_aarch64_elf_section_data (sec);
8231 return _bfd_elf_new_section_hook (abfd, sec);
8236 unrecord_section_via_map_over_sections (bfd *abfd ATTRIBUTE_UNUSED,
8238 void *ignore ATTRIBUTE_UNUSED)
8240 unrecord_section_with_aarch64_elf_section_data (sec);
8244 elfNN_aarch64_close_and_cleanup (bfd *abfd)
8247 bfd_map_over_sections (abfd,
8248 unrecord_section_via_map_over_sections, NULL);
8250 return _bfd_elf_close_and_cleanup (abfd);
8254 elfNN_aarch64_bfd_free_cached_info (bfd *abfd)
8257 bfd_map_over_sections (abfd,
8258 unrecord_section_via_map_over_sections, NULL);
8260 return _bfd_free_cached_info (abfd);
8263 /* Create dynamic sections. This is different from the ARM backend in that
8264 the got, plt, gotplt and their relocation sections are all created in the
8265 standard part of the bfd elf backend. */
8268 elfNN_aarch64_create_dynamic_sections (bfd *dynobj,
8269 struct bfd_link_info *info)
8271 /* We need to create .got section. */
8272 if (!aarch64_elf_create_got_section (dynobj, info))
8275 return _bfd_elf_create_dynamic_sections (dynobj, info);
8279 /* Allocate space in .plt, .got and associated reloc sections for
8283 elfNN_aarch64_allocate_dynrelocs (struct elf_link_hash_entry *h, void *inf)
8285 struct bfd_link_info *info;
8286 struct elf_aarch64_link_hash_table *htab;
8287 struct elf_aarch64_link_hash_entry *eh;
8288 struct elf_dyn_relocs *p;
8290 /* An example of a bfd_link_hash_indirect symbol is versioned
8291 symbol. For example: __gxx_personality_v0(bfd_link_hash_indirect)
8292 -> __gxx_personality_v0(bfd_link_hash_defined)
8294 There is no need to process bfd_link_hash_indirect symbols here
8295 because we will also be presented with the concrete instance of
8296 the symbol and elfNN_aarch64_copy_indirect_symbol () will have been
8297 called to copy all relevant data from the generic to the concrete
8299 if (h->root.type == bfd_link_hash_indirect)
8302 if (h->root.type == bfd_link_hash_warning)
8303 h = (struct elf_link_hash_entry *) h->root.u.i.link;
8305 info = (struct bfd_link_info *) inf;
8306 htab = elf_aarch64_hash_table (info);
8308 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle it
8309 here if it is defined and referenced in a non-shared object. */
8310 if (h->type == STT_GNU_IFUNC
8313 else if (htab->root.dynamic_sections_created && h->plt.refcount > 0)
8315 /* Make sure this symbol is output as a dynamic symbol.
8316 Undefined weak syms won't yet be marked as dynamic. */
8317 if (h->dynindx == -1 && !h->forced_local
8318 && h->root.type == bfd_link_hash_undefweak)
8320 if (!bfd_elf_link_record_dynamic_symbol (info, h))
8324 if (bfd_link_pic (info) || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h))
8326 asection *s = htab->root.splt;
8328 /* If this is the first .plt entry, make room for the special
8331 s->size += htab->plt_header_size;
8333 h->plt.offset = s->size;
8335 /* If this symbol is not defined in a regular file, and we are
8336 not generating a shared library, then set the symbol to this
8337 location in the .plt. This is required to make function
8338 pointers compare as equal between the normal executable and
8339 the shared library. */
8340 if (!bfd_link_pic (info) && !h->def_regular)
8342 h->root.u.def.section = s;
8343 h->root.u.def.value = h->plt.offset;
8346 /* Make room for this entry. For now we only create the
8347 small model PLT entries. We later need to find a way
8348 of relaxing into these from the large model PLT entries. */
8349 s->size += PLT_SMALL_ENTRY_SIZE;
8351 /* We also need to make an entry in the .got.plt section, which
8352 will be placed in the .got section by the linker script. */
8353 htab->root.sgotplt->size += GOT_ENTRY_SIZE;
8355 /* We also need to make an entry in the .rela.plt section. */
8356 htab->root.srelplt->size += RELOC_SIZE (htab);
8358 /* We need to ensure that all GOT entries that serve the PLT
8359 are consecutive with the special GOT slots [0] [1] and
8360 [2]. Any addtional relocations, such as
8361 R_AARCH64_TLSDESC, must be placed after the PLT related
8362 entries. We abuse the reloc_count such that during
8363 sizing we adjust reloc_count to indicate the number of
8364 PLT related reserved entries. In subsequent phases when
8365 filling in the contents of the reloc entries, PLT related
8366 entries are placed by computing their PLT index (0
8367 .. reloc_count). While other none PLT relocs are placed
8368 at the slot indicated by reloc_count and reloc_count is
8371 htab->root.srelplt->reloc_count++;
8375 h->plt.offset = (bfd_vma) - 1;
8381 h->plt.offset = (bfd_vma) - 1;
8385 eh = (struct elf_aarch64_link_hash_entry *) h;
8386 eh->tlsdesc_got_jump_table_offset = (bfd_vma) - 1;
8388 if (h->got.refcount > 0)
8391 unsigned got_type = elf_aarch64_hash_entry (h)->got_type;
8393 h->got.offset = (bfd_vma) - 1;
8395 dyn = htab->root.dynamic_sections_created;
8397 /* Make sure this symbol is output as a dynamic symbol.
8398 Undefined weak syms won't yet be marked as dynamic. */
8399 if (dyn && h->dynindx == -1 && !h->forced_local
8400 && h->root.type == bfd_link_hash_undefweak)
8402 if (!bfd_elf_link_record_dynamic_symbol (info, h))
8406 if (got_type == GOT_UNKNOWN)
8409 else if (got_type == GOT_NORMAL)
8411 h->got.offset = htab->root.sgot->size;
8412 htab->root.sgot->size += GOT_ENTRY_SIZE;
8413 if ((ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
8414 || h->root.type != bfd_link_hash_undefweak)
8415 && (bfd_link_pic (info)
8416 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, 0, h))
8417 /* Undefined weak symbol in static PIE resolves to 0 without
8418 any dynamic relocations. */
8419 && !UNDEFWEAK_NO_DYNAMIC_RELOC (info, h))
8421 htab->root.srelgot->size += RELOC_SIZE (htab);
8427 if (got_type & GOT_TLSDESC_GD)
8429 eh->tlsdesc_got_jump_table_offset =
8430 (htab->root.sgotplt->size
8431 - aarch64_compute_jump_table_size (htab));
8432 htab->root.sgotplt->size += GOT_ENTRY_SIZE * 2;
8433 h->got.offset = (bfd_vma) - 2;
8436 if (got_type & GOT_TLS_GD)
8438 h->got.offset = htab->root.sgot->size;
8439 htab->root.sgot->size += GOT_ENTRY_SIZE * 2;
8442 if (got_type & GOT_TLS_IE)
8444 h->got.offset = htab->root.sgot->size;
8445 htab->root.sgot->size += GOT_ENTRY_SIZE;
8448 indx = h && h->dynindx != -1 ? h->dynindx : 0;
8449 if ((ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
8450 || h->root.type != bfd_link_hash_undefweak)
8451 && (!bfd_link_executable (info)
8453 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, 0, h)))
8455 if (got_type & GOT_TLSDESC_GD)
8457 htab->root.srelplt->size += RELOC_SIZE (htab);
8458 /* Note reloc_count not incremented here! We have
8459 already adjusted reloc_count for this relocation
8462 /* TLSDESC PLT is now needed, but not yet determined. */
8463 htab->tlsdesc_plt = (bfd_vma) - 1;
8466 if (got_type & GOT_TLS_GD)
8467 htab->root.srelgot->size += RELOC_SIZE (htab) * 2;
8469 if (got_type & GOT_TLS_IE)
8470 htab->root.srelgot->size += RELOC_SIZE (htab);
8476 h->got.offset = (bfd_vma) - 1;
8479 if (eh->dyn_relocs == NULL)
8482 /* In the shared -Bsymbolic case, discard space allocated for
8483 dynamic pc-relative relocs against symbols which turn out to be
8484 defined in regular objects. For the normal shared case, discard
8485 space for pc-relative relocs that have become local due to symbol
8486 visibility changes. */
8488 if (bfd_link_pic (info))
8490 /* Relocs that use pc_count are those that appear on a call
8491 insn, or certain REL relocs that can generated via assembly.
8492 We want calls to protected symbols to resolve directly to the
8493 function rather than going via the plt. If people want
8494 function pointer comparisons to work as expected then they
8495 should avoid writing weird assembly. */
8496 if (SYMBOL_CALLS_LOCAL (info, h))
8498 struct elf_dyn_relocs **pp;
8500 for (pp = &eh->dyn_relocs; (p = *pp) != NULL;)
8502 p->count -= p->pc_count;
8511 /* Also discard relocs on undefined weak syms with non-default
8513 if (eh->dyn_relocs != NULL && h->root.type == bfd_link_hash_undefweak)
8515 if (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
8516 || UNDEFWEAK_NO_DYNAMIC_RELOC (info, h))
8517 eh->dyn_relocs = NULL;
8519 /* Make sure undefined weak symbols are output as a dynamic
8521 else if (h->dynindx == -1
8523 && h->root.type == bfd_link_hash_undefweak
8524 && !bfd_elf_link_record_dynamic_symbol (info, h))
8529 else if (ELIMINATE_COPY_RELOCS)
8531 /* For the non-shared case, discard space for relocs against
8532 symbols which turn out to need copy relocs or are not
8538 || (htab->root.dynamic_sections_created
8539 && (h->root.type == bfd_link_hash_undefweak
8540 || h->root.type == bfd_link_hash_undefined))))
8542 /* Make sure this symbol is output as a dynamic symbol.
8543 Undefined weak syms won't yet be marked as dynamic. */
8544 if (h->dynindx == -1
8546 && h->root.type == bfd_link_hash_undefweak
8547 && !bfd_elf_link_record_dynamic_symbol (info, h))
8550 /* If that succeeded, we know we'll be keeping all the
8552 if (h->dynindx != -1)
8556 eh->dyn_relocs = NULL;
8561 /* Finally, allocate space. */
8562 for (p = eh->dyn_relocs; p != NULL; p = p->next)
8566 sreloc = elf_section_data (p->sec)->sreloc;
8568 BFD_ASSERT (sreloc != NULL);
8570 sreloc->size += p->count * RELOC_SIZE (htab);
8576 /* Allocate space in .plt, .got and associated reloc sections for
8577 ifunc dynamic relocs. */
8580 elfNN_aarch64_allocate_ifunc_dynrelocs (struct elf_link_hash_entry *h,
8583 struct bfd_link_info *info;
8584 struct elf_aarch64_link_hash_table *htab;
8585 struct elf_aarch64_link_hash_entry *eh;
8587 /* An example of a bfd_link_hash_indirect symbol is versioned
8588 symbol. For example: __gxx_personality_v0(bfd_link_hash_indirect)
8589 -> __gxx_personality_v0(bfd_link_hash_defined)
8591 There is no need to process bfd_link_hash_indirect symbols here
8592 because we will also be presented with the concrete instance of
8593 the symbol and elfNN_aarch64_copy_indirect_symbol () will have been
8594 called to copy all relevant data from the generic to the concrete
8596 if (h->root.type == bfd_link_hash_indirect)
8599 if (h->root.type == bfd_link_hash_warning)
8600 h = (struct elf_link_hash_entry *) h->root.u.i.link;
8602 info = (struct bfd_link_info *) inf;
8603 htab = elf_aarch64_hash_table (info);
8605 eh = (struct elf_aarch64_link_hash_entry *) h;
8607 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle it
8608 here if it is defined and referenced in a non-shared object. */
8609 if (h->type == STT_GNU_IFUNC
8611 return _bfd_elf_allocate_ifunc_dyn_relocs (info, h,
8614 htab->plt_entry_size,
8615 htab->plt_header_size,
8621 /* Allocate space in .plt, .got and associated reloc sections for
8622 local dynamic relocs. */
8625 elfNN_aarch64_allocate_local_dynrelocs (void **slot, void *inf)
8627 struct elf_link_hash_entry *h
8628 = (struct elf_link_hash_entry *) *slot;
8630 if (h->type != STT_GNU_IFUNC
8634 || h->root.type != bfd_link_hash_defined)
8637 return elfNN_aarch64_allocate_dynrelocs (h, inf);
8640 /* Allocate space in .plt, .got and associated reloc sections for
8641 local ifunc dynamic relocs. */
8644 elfNN_aarch64_allocate_local_ifunc_dynrelocs (void **slot, void *inf)
8646 struct elf_link_hash_entry *h
8647 = (struct elf_link_hash_entry *) *slot;
8649 if (h->type != STT_GNU_IFUNC
8653 || h->root.type != bfd_link_hash_defined)
8656 return elfNN_aarch64_allocate_ifunc_dynrelocs (h, inf);
8659 /* Set DF_TEXTREL if we find any dynamic relocs that apply to
8660 read-only sections. */
8663 maybe_set_textrel (struct elf_link_hash_entry *h, void *info_p)
8667 if (h->root.type == bfd_link_hash_indirect)
8670 sec = readonly_dynrelocs (h);
8673 struct bfd_link_info *info = (struct bfd_link_info *) info_p;
8675 info->flags |= DF_TEXTREL;
8676 info->callbacks->minfo
8677 (_("%pB: dynamic relocation against `%pT' in read-only section `%pA'\n"),
8678 sec->owner, h->root.root.string, sec);
8680 /* Not an error, just cut short the traversal. */
8686 /* This is the most important function of all . Innocuosly named
8690 elfNN_aarch64_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
8691 struct bfd_link_info *info)
8693 struct elf_aarch64_link_hash_table *htab;
8699 htab = elf_aarch64_hash_table ((info));
8700 dynobj = htab->root.dynobj;
8702 BFD_ASSERT (dynobj != NULL);
8704 if (htab->root.dynamic_sections_created)
8706 if (bfd_link_executable (info) && !info->nointerp)
8708 s = bfd_get_linker_section (dynobj, ".interp");
8711 s->size = sizeof ELF_DYNAMIC_INTERPRETER;
8712 s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
8716 /* Set up .got offsets for local syms, and space for local dynamic
8718 for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link.next)
8720 struct elf_aarch64_local_symbol *locals = NULL;
8721 Elf_Internal_Shdr *symtab_hdr;
8725 if (!is_aarch64_elf (ibfd))
8728 for (s = ibfd->sections; s != NULL; s = s->next)
8730 struct elf_dyn_relocs *p;
8732 for (p = (struct elf_dyn_relocs *)
8733 (elf_section_data (s)->local_dynrel); p != NULL; p = p->next)
8735 if (!bfd_is_abs_section (p->sec)
8736 && bfd_is_abs_section (p->sec->output_section))
8738 /* Input section has been discarded, either because
8739 it is a copy of a linkonce section or due to
8740 linker script /DISCARD/, so we'll be discarding
8743 else if (p->count != 0)
8745 srel = elf_section_data (p->sec)->sreloc;
8746 srel->size += p->count * RELOC_SIZE (htab);
8747 if ((p->sec->output_section->flags & SEC_READONLY) != 0)
8748 info->flags |= DF_TEXTREL;
8753 locals = elf_aarch64_locals (ibfd);
8757 symtab_hdr = &elf_symtab_hdr (ibfd);
8758 srel = htab->root.srelgot;
8759 for (i = 0; i < symtab_hdr->sh_info; i++)
8761 locals[i].got_offset = (bfd_vma) - 1;
8762 locals[i].tlsdesc_got_jump_table_offset = (bfd_vma) - 1;
8763 if (locals[i].got_refcount > 0)
8765 unsigned got_type = locals[i].got_type;
8766 if (got_type & GOT_TLSDESC_GD)
8768 locals[i].tlsdesc_got_jump_table_offset =
8769 (htab->root.sgotplt->size
8770 - aarch64_compute_jump_table_size (htab));
8771 htab->root.sgotplt->size += GOT_ENTRY_SIZE * 2;
8772 locals[i].got_offset = (bfd_vma) - 2;
8775 if (got_type & GOT_TLS_GD)
8777 locals[i].got_offset = htab->root.sgot->size;
8778 htab->root.sgot->size += GOT_ENTRY_SIZE * 2;
8781 if (got_type & GOT_TLS_IE
8782 || got_type & GOT_NORMAL)
8784 locals[i].got_offset = htab->root.sgot->size;
8785 htab->root.sgot->size += GOT_ENTRY_SIZE;
8788 if (got_type == GOT_UNKNOWN)
8792 if (bfd_link_pic (info))
8794 if (got_type & GOT_TLSDESC_GD)
8796 htab->root.srelplt->size += RELOC_SIZE (htab);
8797 /* Note RELOC_COUNT not incremented here! */
8798 htab->tlsdesc_plt = (bfd_vma) - 1;
8801 if (got_type & GOT_TLS_GD)
8802 htab->root.srelgot->size += RELOC_SIZE (htab) * 2;
8804 if (got_type & GOT_TLS_IE
8805 || got_type & GOT_NORMAL)
8806 htab->root.srelgot->size += RELOC_SIZE (htab);
8811 locals[i].got_refcount = (bfd_vma) - 1;
8817 /* Allocate global sym .plt and .got entries, and space for global
8818 sym dynamic relocs. */
8819 elf_link_hash_traverse (&htab->root, elfNN_aarch64_allocate_dynrelocs,
8822 /* Allocate global ifunc sym .plt and .got entries, and space for global
8823 ifunc sym dynamic relocs. */
8824 elf_link_hash_traverse (&htab->root, elfNN_aarch64_allocate_ifunc_dynrelocs,
8827 /* Allocate .plt and .got entries, and space for local symbols. */
8828 htab_traverse (htab->loc_hash_table,
8829 elfNN_aarch64_allocate_local_dynrelocs,
8832 /* Allocate .plt and .got entries, and space for local ifunc symbols. */
8833 htab_traverse (htab->loc_hash_table,
8834 elfNN_aarch64_allocate_local_ifunc_dynrelocs,
8837 /* For every jump slot reserved in the sgotplt, reloc_count is
8838 incremented. However, when we reserve space for TLS descriptors,
8839 it's not incremented, so in order to compute the space reserved
8840 for them, it suffices to multiply the reloc count by the jump
8843 if (htab->root.srelplt)
8844 htab->sgotplt_jump_table_size = aarch64_compute_jump_table_size (htab);
8846 if (htab->tlsdesc_plt)
8848 if (htab->root.splt->size == 0)
8849 htab->root.splt->size += PLT_ENTRY_SIZE;
8851 htab->tlsdesc_plt = htab->root.splt->size;
8852 htab->root.splt->size += PLT_TLSDESC_ENTRY_SIZE;
8854 /* If we're not using lazy TLS relocations, don't generate the
8855 GOT entry required. */
8856 if (!(info->flags & DF_BIND_NOW))
8858 htab->dt_tlsdesc_got = htab->root.sgot->size;
8859 htab->root.sgot->size += GOT_ENTRY_SIZE;
8863 /* Init mapping symbols information to use later to distingush between
8864 code and data while scanning for errata. */
8865 if (htab->fix_erratum_835769 || htab->fix_erratum_843419)
8866 for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link.next)
8868 if (!is_aarch64_elf (ibfd))
8870 bfd_elfNN_aarch64_init_maps (ibfd);
8873 /* We now have determined the sizes of the various dynamic sections.
8874 Allocate memory for them. */
8876 for (s = dynobj->sections; s != NULL; s = s->next)
8878 if ((s->flags & SEC_LINKER_CREATED) == 0)
8881 if (s == htab->root.splt
8882 || s == htab->root.sgot
8883 || s == htab->root.sgotplt
8884 || s == htab->root.iplt
8885 || s == htab->root.igotplt
8886 || s == htab->root.sdynbss
8887 || s == htab->root.sdynrelro)
8889 /* Strip this section if we don't need it; see the
8892 else if (CONST_STRNEQ (bfd_get_section_name (dynobj, s), ".rela"))
8894 if (s->size != 0 && s != htab->root.srelplt)
8897 /* We use the reloc_count field as a counter if we need
8898 to copy relocs into the output file. */
8899 if (s != htab->root.srelplt)
8904 /* It's not one of our sections, so don't allocate space. */
8910 /* If we don't need this section, strip it from the
8911 output file. This is mostly to handle .rela.bss and
8912 .rela.plt. We must create both sections in
8913 create_dynamic_sections, because they must be created
8914 before the linker maps input sections to output
8915 sections. The linker does that before
8916 adjust_dynamic_symbol is called, and it is that
8917 function which decides whether anything needs to go
8918 into these sections. */
8919 s->flags |= SEC_EXCLUDE;
8923 if ((s->flags & SEC_HAS_CONTENTS) == 0)
8926 /* Allocate memory for the section contents. We use bfd_zalloc
8927 here in case unused entries are not reclaimed before the
8928 section's contents are written out. This should not happen,
8929 but this way if it does, we get a R_AARCH64_NONE reloc instead
8931 s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->size);
8932 if (s->contents == NULL)
8936 if (htab->root.dynamic_sections_created)
8938 /* Add some entries to the .dynamic section. We fill in the
8939 values later, in elfNN_aarch64_finish_dynamic_sections, but we
8940 must add the entries now so that we get the correct size for
8941 the .dynamic section. The DT_DEBUG entry is filled in by the
8942 dynamic linker and used by the debugger. */
8943 #define add_dynamic_entry(TAG, VAL) \
8944 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
8946 if (bfd_link_executable (info))
8948 if (!add_dynamic_entry (DT_DEBUG, 0))
8952 if (htab->root.splt->size != 0)
8954 if (!add_dynamic_entry (DT_PLTGOT, 0)
8955 || !add_dynamic_entry (DT_PLTRELSZ, 0)
8956 || !add_dynamic_entry (DT_PLTREL, DT_RELA)
8957 || !add_dynamic_entry (DT_JMPREL, 0))
8960 if (htab->tlsdesc_plt
8961 && (!add_dynamic_entry (DT_TLSDESC_PLT, 0)
8962 || !add_dynamic_entry (DT_TLSDESC_GOT, 0)))
8968 if (!add_dynamic_entry (DT_RELA, 0)
8969 || !add_dynamic_entry (DT_RELASZ, 0)
8970 || !add_dynamic_entry (DT_RELAENT, RELOC_SIZE (htab)))
8973 /* If any dynamic relocs apply to a read-only section,
8974 then we need a DT_TEXTREL entry. */
8975 if ((info->flags & DF_TEXTREL) == 0)
8976 elf_link_hash_traverse (&htab->root, maybe_set_textrel, info);
8978 if ((info->flags & DF_TEXTREL) != 0)
8980 if (!add_dynamic_entry (DT_TEXTREL, 0))
8985 #undef add_dynamic_entry
8991 elf_aarch64_update_plt_entry (bfd *output_bfd,
8992 bfd_reloc_code_real_type r_type,
8993 bfd_byte *plt_entry, bfd_vma value)
8995 reloc_howto_type *howto = elfNN_aarch64_howto_from_bfd_reloc (r_type);
8997 /* FIXME: We should check the return value from this function call. */
8998 (void) _bfd_aarch64_elf_put_addend (output_bfd, plt_entry, r_type, howto, value);
9002 elfNN_aarch64_create_small_pltn_entry (struct elf_link_hash_entry *h,
9003 struct elf_aarch64_link_hash_table
9004 *htab, bfd *output_bfd,
9005 struct bfd_link_info *info)
9007 bfd_byte *plt_entry;
9010 bfd_vma gotplt_entry_address;
9011 bfd_vma plt_entry_address;
9012 Elf_Internal_Rela rela;
9014 asection *plt, *gotplt, *relplt;
9016 /* When building a static executable, use .iplt, .igot.plt and
9017 .rela.iplt sections for STT_GNU_IFUNC symbols. */
9018 if (htab->root.splt != NULL)
9020 plt = htab->root.splt;
9021 gotplt = htab->root.sgotplt;
9022 relplt = htab->root.srelplt;
9026 plt = htab->root.iplt;
9027 gotplt = htab->root.igotplt;
9028 relplt = htab->root.irelplt;
9031 /* Get the index in the procedure linkage table which
9032 corresponds to this symbol. This is the index of this symbol
9033 in all the symbols for which we are making plt entries. The
9034 first entry in the procedure linkage table is reserved.
9036 Get the offset into the .got table of the entry that
9037 corresponds to this function. Each .got entry is GOT_ENTRY_SIZE
9038 bytes. The first three are reserved for the dynamic linker.
9040 For static executables, we don't reserve anything. */
9042 if (plt == htab->root.splt)
9044 plt_index = (h->plt.offset - htab->plt_header_size) / htab->plt_entry_size;
9045 got_offset = (plt_index + 3) * GOT_ENTRY_SIZE;
9049 plt_index = h->plt.offset / htab->plt_entry_size;
9050 got_offset = plt_index * GOT_ENTRY_SIZE;
9053 plt_entry = plt->contents + h->plt.offset;
9054 plt_entry_address = plt->output_section->vma
9055 + plt->output_offset + h->plt.offset;
9056 gotplt_entry_address = gotplt->output_section->vma +
9057 gotplt->output_offset + got_offset;
9059 /* Copy in the boiler-plate for the PLTn entry. */
9060 memcpy (plt_entry, elfNN_aarch64_small_plt_entry, PLT_SMALL_ENTRY_SIZE);
9062 /* Fill in the top 21 bits for this: ADRP x16, PLT_GOT + n * 8.
9063 ADRP: ((PG(S+A)-PG(P)) >> 12) & 0x1fffff */
9064 elf_aarch64_update_plt_entry (output_bfd, BFD_RELOC_AARCH64_ADR_HI21_PCREL,
9066 PG (gotplt_entry_address) -
9067 PG (plt_entry_address));
9069 /* Fill in the lo12 bits for the load from the pltgot. */
9070 elf_aarch64_update_plt_entry (output_bfd, BFD_RELOC_AARCH64_LDSTNN_LO12,
9072 PG_OFFSET (gotplt_entry_address));
9074 /* Fill in the lo12 bits for the add from the pltgot entry. */
9075 elf_aarch64_update_plt_entry (output_bfd, BFD_RELOC_AARCH64_ADD_LO12,
9077 PG_OFFSET (gotplt_entry_address));
9079 /* All the GOTPLT Entries are essentially initialized to PLT0. */
9080 bfd_put_NN (output_bfd,
9081 plt->output_section->vma + plt->output_offset,
9082 gotplt->contents + got_offset);
9084 rela.r_offset = gotplt_entry_address;
9086 if (h->dynindx == -1
9087 || ((bfd_link_executable (info)
9088 || ELF_ST_VISIBILITY (h->other) != STV_DEFAULT)
9090 && h->type == STT_GNU_IFUNC))
9092 /* If an STT_GNU_IFUNC symbol is locally defined, generate
9093 R_AARCH64_IRELATIVE instead of R_AARCH64_JUMP_SLOT. */
9094 rela.r_info = ELFNN_R_INFO (0, AARCH64_R (IRELATIVE));
9095 rela.r_addend = (h->root.u.def.value
9096 + h->root.u.def.section->output_section->vma
9097 + h->root.u.def.section->output_offset);
9101 /* Fill in the entry in the .rela.plt section. */
9102 rela.r_info = ELFNN_R_INFO (h->dynindx, AARCH64_R (JUMP_SLOT));
9106 /* Compute the relocation entry to used based on PLT index and do
9107 not adjust reloc_count. The reloc_count has already been adjusted
9108 to account for this entry. */
9109 loc = relplt->contents + plt_index * RELOC_SIZE (htab);
9110 bfd_elfNN_swap_reloca_out (output_bfd, &rela, loc);
9113 /* Size sections even though they're not dynamic. We use it to setup
9114 _TLS_MODULE_BASE_, if needed. */
9117 elfNN_aarch64_always_size_sections (bfd *output_bfd,
9118 struct bfd_link_info *info)
9122 if (bfd_link_relocatable (info))
9125 tls_sec = elf_hash_table (info)->tls_sec;
9129 struct elf_link_hash_entry *tlsbase;
9131 tlsbase = elf_link_hash_lookup (elf_hash_table (info),
9132 "_TLS_MODULE_BASE_", TRUE, TRUE, FALSE);
9136 struct bfd_link_hash_entry *h = NULL;
9137 const struct elf_backend_data *bed =
9138 get_elf_backend_data (output_bfd);
9140 if (!(_bfd_generic_link_add_one_symbol
9141 (info, output_bfd, "_TLS_MODULE_BASE_", BSF_LOCAL,
9142 tls_sec, 0, NULL, FALSE, bed->collect, &h)))
9145 tlsbase->type = STT_TLS;
9146 tlsbase = (struct elf_link_hash_entry *) h;
9147 tlsbase->def_regular = 1;
9148 tlsbase->other = STV_HIDDEN;
9149 (*bed->elf_backend_hide_symbol) (info, tlsbase, TRUE);
9156 /* Finish up dynamic symbol handling. We set the contents of various
9157 dynamic sections here. */
9160 elfNN_aarch64_finish_dynamic_symbol (bfd *output_bfd,
9161 struct bfd_link_info *info,
9162 struct elf_link_hash_entry *h,
9163 Elf_Internal_Sym *sym)
9165 struct elf_aarch64_link_hash_table *htab;
9166 htab = elf_aarch64_hash_table (info);
9168 if (h->plt.offset != (bfd_vma) - 1)
9170 asection *plt, *gotplt, *relplt;
9172 /* This symbol has an entry in the procedure linkage table. Set
9175 /* When building a static executable, use .iplt, .igot.plt and
9176 .rela.iplt sections for STT_GNU_IFUNC symbols. */
9177 if (htab->root.splt != NULL)
9179 plt = htab->root.splt;
9180 gotplt = htab->root.sgotplt;
9181 relplt = htab->root.srelplt;
9185 plt = htab->root.iplt;
9186 gotplt = htab->root.igotplt;
9187 relplt = htab->root.irelplt;
9190 /* This symbol has an entry in the procedure linkage table. Set
9192 if ((h->dynindx == -1
9193 && !((h->forced_local || bfd_link_executable (info))
9195 && h->type == STT_GNU_IFUNC))
9201 elfNN_aarch64_create_small_pltn_entry (h, htab, output_bfd, info);
9202 if (!h->def_regular)
9204 /* Mark the symbol as undefined, rather than as defined in
9205 the .plt section. */
9206 sym->st_shndx = SHN_UNDEF;
9207 /* If the symbol is weak we need to clear the value.
9208 Otherwise, the PLT entry would provide a definition for
9209 the symbol even if the symbol wasn't defined anywhere,
9210 and so the symbol would never be NULL. Leave the value if
9211 there were any relocations where pointer equality matters
9212 (this is a clue for the dynamic linker, to make function
9213 pointer comparisons work between an application and shared
9215 if (!h->ref_regular_nonweak || !h->pointer_equality_needed)
9220 if (h->got.offset != (bfd_vma) - 1
9221 && elf_aarch64_hash_entry (h)->got_type == GOT_NORMAL
9222 /* Undefined weak symbol in static PIE resolves to 0 without
9223 any dynamic relocations. */
9224 && !UNDEFWEAK_NO_DYNAMIC_RELOC (info, h))
9226 Elf_Internal_Rela rela;
9229 /* This symbol has an entry in the global offset table. Set it
9231 if (htab->root.sgot == NULL || htab->root.srelgot == NULL)
9234 rela.r_offset = (htab->root.sgot->output_section->vma
9235 + htab->root.sgot->output_offset
9236 + (h->got.offset & ~(bfd_vma) 1));
9239 && h->type == STT_GNU_IFUNC)
9241 if (bfd_link_pic (info))
9243 /* Generate R_AARCH64_GLOB_DAT. */
9250 if (!h->pointer_equality_needed)
9253 /* For non-shared object, we can't use .got.plt, which
9254 contains the real function address if we need pointer
9255 equality. We load the GOT entry with the PLT entry. */
9256 plt = htab->root.splt ? htab->root.splt : htab->root.iplt;
9257 bfd_put_NN (output_bfd, (plt->output_section->vma
9258 + plt->output_offset
9260 htab->root.sgot->contents
9261 + (h->got.offset & ~(bfd_vma) 1));
9265 else if (bfd_link_pic (info) && SYMBOL_REFERENCES_LOCAL (info, h))
9267 if (!(h->def_regular || ELF_COMMON_DEF_P (h)))
9270 BFD_ASSERT ((h->got.offset & 1) != 0);
9271 rela.r_info = ELFNN_R_INFO (0, AARCH64_R (RELATIVE));
9272 rela.r_addend = (h->root.u.def.value
9273 + h->root.u.def.section->output_section->vma
9274 + h->root.u.def.section->output_offset);
9279 BFD_ASSERT ((h->got.offset & 1) == 0);
9280 bfd_put_NN (output_bfd, (bfd_vma) 0,
9281 htab->root.sgot->contents + h->got.offset);
9282 rela.r_info = ELFNN_R_INFO (h->dynindx, AARCH64_R (GLOB_DAT));
9286 loc = htab->root.srelgot->contents;
9287 loc += htab->root.srelgot->reloc_count++ * RELOC_SIZE (htab);
9288 bfd_elfNN_swap_reloca_out (output_bfd, &rela, loc);
9293 Elf_Internal_Rela rela;
9297 /* This symbol needs a copy reloc. Set it up. */
9298 if (h->dynindx == -1
9299 || (h->root.type != bfd_link_hash_defined
9300 && h->root.type != bfd_link_hash_defweak)
9301 || htab->root.srelbss == NULL)
9304 rela.r_offset = (h->root.u.def.value
9305 + h->root.u.def.section->output_section->vma
9306 + h->root.u.def.section->output_offset);
9307 rela.r_info = ELFNN_R_INFO (h->dynindx, AARCH64_R (COPY));
9309 if (h->root.u.def.section == htab->root.sdynrelro)
9310 s = htab->root.sreldynrelro;
9312 s = htab->root.srelbss;
9313 loc = s->contents + s->reloc_count++ * RELOC_SIZE (htab);
9314 bfd_elfNN_swap_reloca_out (output_bfd, &rela, loc);
9317 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. SYM may
9318 be NULL for local symbols. */
9320 && (h == elf_hash_table (info)->hdynamic
9321 || h == elf_hash_table (info)->hgot))
9322 sym->st_shndx = SHN_ABS;
9327 /* Finish up local dynamic symbol handling. We set the contents of
9328 various dynamic sections here. */
9331 elfNN_aarch64_finish_local_dynamic_symbol (void **slot, void *inf)
9333 struct elf_link_hash_entry *h
9334 = (struct elf_link_hash_entry *) *slot;
9335 struct bfd_link_info *info
9336 = (struct bfd_link_info *) inf;
9338 return elfNN_aarch64_finish_dynamic_symbol (info->output_bfd,
9343 elfNN_aarch64_init_small_plt0_entry (bfd *output_bfd ATTRIBUTE_UNUSED,
9344 struct elf_aarch64_link_hash_table
9347 /* Fill in PLT0. Fixme:RR Note this doesn't distinguish between
9348 small and large plts and at the minute just generates
9351 /* PLT0 of the small PLT looks like this in ELF64 -
9352 stp x16, x30, [sp, #-16]! // Save the reloc and lr on stack.
9353 adrp x16, PLT_GOT + 16 // Get the page base of the GOTPLT
9354 ldr x17, [x16, #:lo12:PLT_GOT+16] // Load the address of the
9356 add x16, x16, #:lo12:PLT_GOT+16 // Load the lo12 bits of the
9357 // GOTPLT entry for this.
9359 PLT0 will be slightly different in ELF32 due to different got entry
9361 bfd_vma plt_got_2nd_ent; /* Address of GOT[2]. */
9365 memcpy (htab->root.splt->contents, elfNN_aarch64_small_plt0_entry,
9367 elf_section_data (htab->root.splt->output_section)->this_hdr.sh_entsize =
9370 plt_got_2nd_ent = (htab->root.sgotplt->output_section->vma
9371 + htab->root.sgotplt->output_offset
9372 + GOT_ENTRY_SIZE * 2);
9374 plt_base = htab->root.splt->output_section->vma +
9375 htab->root.splt->output_offset;
9377 /* Fill in the top 21 bits for this: ADRP x16, PLT_GOT + n * 8.
9378 ADRP: ((PG(S+A)-PG(P)) >> 12) & 0x1fffff */
9379 elf_aarch64_update_plt_entry (output_bfd, BFD_RELOC_AARCH64_ADR_HI21_PCREL,
9380 htab->root.splt->contents + 4,
9381 PG (plt_got_2nd_ent) - PG (plt_base + 4));
9383 elf_aarch64_update_plt_entry (output_bfd, BFD_RELOC_AARCH64_LDSTNN_LO12,
9384 htab->root.splt->contents + 8,
9385 PG_OFFSET (plt_got_2nd_ent));
9387 elf_aarch64_update_plt_entry (output_bfd, BFD_RELOC_AARCH64_ADD_LO12,
9388 htab->root.splt->contents + 12,
9389 PG_OFFSET (plt_got_2nd_ent));
9393 elfNN_aarch64_finish_dynamic_sections (bfd *output_bfd,
9394 struct bfd_link_info *info)
9396 struct elf_aarch64_link_hash_table *htab;
9400 htab = elf_aarch64_hash_table (info);
9401 dynobj = htab->root.dynobj;
9402 sdyn = bfd_get_linker_section (dynobj, ".dynamic");
9404 if (htab->root.dynamic_sections_created)
9406 ElfNN_External_Dyn *dyncon, *dynconend;
9408 if (sdyn == NULL || htab->root.sgot == NULL)
9411 dyncon = (ElfNN_External_Dyn *) sdyn->contents;
9412 dynconend = (ElfNN_External_Dyn *) (sdyn->contents + sdyn->size);
9413 for (; dyncon < dynconend; dyncon++)
9415 Elf_Internal_Dyn dyn;
9418 bfd_elfNN_swap_dyn_in (dynobj, dyncon, &dyn);
9426 s = htab->root.sgotplt;
9427 dyn.d_un.d_ptr = s->output_section->vma + s->output_offset;
9431 s = htab->root.srelplt;
9432 dyn.d_un.d_ptr = s->output_section->vma + s->output_offset;
9436 s = htab->root.srelplt;
9437 dyn.d_un.d_val = s->size;
9440 case DT_TLSDESC_PLT:
9441 s = htab->root.splt;
9442 dyn.d_un.d_ptr = s->output_section->vma + s->output_offset
9443 + htab->tlsdesc_plt;
9446 case DT_TLSDESC_GOT:
9447 s = htab->root.sgot;
9448 dyn.d_un.d_ptr = s->output_section->vma + s->output_offset
9449 + htab->dt_tlsdesc_got;
9453 bfd_elfNN_swap_dyn_out (output_bfd, &dyn, dyncon);
9458 /* Fill in the special first entry in the procedure linkage table. */
9459 if (htab->root.splt && htab->root.splt->size > 0)
9461 elfNN_aarch64_init_small_plt0_entry (output_bfd, htab);
9463 elf_section_data (htab->root.splt->output_section)->
9464 this_hdr.sh_entsize = htab->plt_entry_size;
9467 if (htab->tlsdesc_plt)
9469 bfd_put_NN (output_bfd, (bfd_vma) 0,
9470 htab->root.sgot->contents + htab->dt_tlsdesc_got);
9472 memcpy (htab->root.splt->contents + htab->tlsdesc_plt,
9473 elfNN_aarch64_tlsdesc_small_plt_entry,
9474 sizeof (elfNN_aarch64_tlsdesc_small_plt_entry));
9477 bfd_vma adrp1_addr =
9478 htab->root.splt->output_section->vma
9479 + htab->root.splt->output_offset + htab->tlsdesc_plt + 4;
9481 bfd_vma adrp2_addr = adrp1_addr + 4;
9484 htab->root.sgot->output_section->vma
9485 + htab->root.sgot->output_offset;
9487 bfd_vma pltgot_addr =
9488 htab->root.sgotplt->output_section->vma
9489 + htab->root.sgotplt->output_offset;
9491 bfd_vma dt_tlsdesc_got = got_addr + htab->dt_tlsdesc_got;
9493 bfd_byte *plt_entry =
9494 htab->root.splt->contents + htab->tlsdesc_plt;
9496 /* adrp x2, DT_TLSDESC_GOT */
9497 elf_aarch64_update_plt_entry (output_bfd,
9498 BFD_RELOC_AARCH64_ADR_HI21_PCREL,
9500 (PG (dt_tlsdesc_got)
9501 - PG (adrp1_addr)));
9504 elf_aarch64_update_plt_entry (output_bfd,
9505 BFD_RELOC_AARCH64_ADR_HI21_PCREL,
9508 - PG (adrp2_addr)));
9510 /* ldr x2, [x2, #0] */
9511 elf_aarch64_update_plt_entry (output_bfd,
9512 BFD_RELOC_AARCH64_LDSTNN_LO12,
9514 PG_OFFSET (dt_tlsdesc_got));
9517 elf_aarch64_update_plt_entry (output_bfd,
9518 BFD_RELOC_AARCH64_ADD_LO12,
9520 PG_OFFSET (pltgot_addr));
9525 if (htab->root.sgotplt)
9527 if (bfd_is_abs_section (htab->root.sgotplt->output_section))
9530 (_("discarded output section: `%pA'"), htab->root.sgotplt);
9534 /* Fill in the first three entries in the global offset table. */
9535 if (htab->root.sgotplt->size > 0)
9537 bfd_put_NN (output_bfd, (bfd_vma) 0, htab->root.sgotplt->contents);
9539 /* Write GOT[1] and GOT[2], needed for the dynamic linker. */
9540 bfd_put_NN (output_bfd,
9542 htab->root.sgotplt->contents + GOT_ENTRY_SIZE);
9543 bfd_put_NN (output_bfd,
9545 htab->root.sgotplt->contents + GOT_ENTRY_SIZE * 2);
9548 if (htab->root.sgot)
9550 if (htab->root.sgot->size > 0)
9553 sdyn ? sdyn->output_section->vma + sdyn->output_offset : 0;
9554 bfd_put_NN (output_bfd, addr, htab->root.sgot->contents);
9558 elf_section_data (htab->root.sgotplt->output_section)->
9559 this_hdr.sh_entsize = GOT_ENTRY_SIZE;
9562 if (htab->root.sgot && htab->root.sgot->size > 0)
9563 elf_section_data (htab->root.sgot->output_section)->this_hdr.sh_entsize
9566 /* Fill PLT and GOT entries for local STT_GNU_IFUNC symbols. */
9567 htab_traverse (htab->loc_hash_table,
9568 elfNN_aarch64_finish_local_dynamic_symbol,
9574 /* Return address for Ith PLT stub in section PLT, for relocation REL
9575 or (bfd_vma) -1 if it should not be included. */
9578 elfNN_aarch64_plt_sym_val (bfd_vma i, const asection *plt,
9579 const arelent *rel ATTRIBUTE_UNUSED)
9581 return plt->vma + PLT_ENTRY_SIZE + i * PLT_SMALL_ENTRY_SIZE;
9584 /* Returns TRUE if NAME is an AArch64 mapping symbol.
9585 The ARM ELF standard defines $x (for A64 code) and $d (for data).
9586 It also allows a period initiated suffix to be added to the symbol, ie:
9587 "$[adtx]\.[:sym_char]+". */
9590 is_aarch64_mapping_symbol (const char * name)
9592 return name != NULL /* Paranoia. */
9593 && name[0] == '$' /* Note: if objcopy --prefix-symbols has been used then
9594 the mapping symbols could have acquired a prefix.
9595 We do not support this here, since such symbols no
9596 longer conform to the ARM ELF ABI. */
9597 && (name[1] == 'd' || name[1] == 'x')
9598 && (name[2] == 0 || name[2] == '.');
9599 /* FIXME: Strictly speaking the symbol is only a valid mapping symbol if
9600 any characters that follow the period are legal characters for the body
9601 of a symbol's name. For now we just assume that this is the case. */
9604 /* Make sure that mapping symbols in object files are not removed via the
9605 "strip --strip-unneeded" tool. These symbols might needed in order to
9606 correctly generate linked files. Once an object file has been linked,
9607 it should be safe to remove them. */
9610 elfNN_aarch64_backend_symbol_processing (bfd *abfd, asymbol *sym)
9612 if (((abfd->flags & (EXEC_P | DYNAMIC)) == 0)
9613 && sym->section != bfd_abs_section_ptr
9614 && is_aarch64_mapping_symbol (sym->name))
9615 sym->flags |= BSF_KEEP;
9619 /* We use this so we can override certain functions
9620 (though currently we don't). */
9622 const struct elf_size_info elfNN_aarch64_size_info =
9624 sizeof (ElfNN_External_Ehdr),
9625 sizeof (ElfNN_External_Phdr),
9626 sizeof (ElfNN_External_Shdr),
9627 sizeof (ElfNN_External_Rel),
9628 sizeof (ElfNN_External_Rela),
9629 sizeof (ElfNN_External_Sym),
9630 sizeof (ElfNN_External_Dyn),
9631 sizeof (Elf_External_Note),
9632 4, /* Hash table entry size. */
9633 1, /* Internal relocs per external relocs. */
9634 ARCH_SIZE, /* Arch size. */
9635 LOG_FILE_ALIGN, /* Log_file_align. */
9636 ELFCLASSNN, EV_CURRENT,
9637 bfd_elfNN_write_out_phdrs,
9638 bfd_elfNN_write_shdrs_and_ehdr,
9639 bfd_elfNN_checksum_contents,
9640 bfd_elfNN_write_relocs,
9641 bfd_elfNN_swap_symbol_in,
9642 bfd_elfNN_swap_symbol_out,
9643 bfd_elfNN_slurp_reloc_table,
9644 bfd_elfNN_slurp_symbol_table,
9645 bfd_elfNN_swap_dyn_in,
9646 bfd_elfNN_swap_dyn_out,
9647 bfd_elfNN_swap_reloc_in,
9648 bfd_elfNN_swap_reloc_out,
9649 bfd_elfNN_swap_reloca_in,
9650 bfd_elfNN_swap_reloca_out
9653 #define ELF_ARCH bfd_arch_aarch64
9654 #define ELF_MACHINE_CODE EM_AARCH64
9655 #define ELF_MAXPAGESIZE 0x10000
9656 #define ELF_MINPAGESIZE 0x1000
9657 #define ELF_COMMONPAGESIZE 0x1000
9659 #define bfd_elfNN_close_and_cleanup \
9660 elfNN_aarch64_close_and_cleanup
9662 #define bfd_elfNN_bfd_free_cached_info \
9663 elfNN_aarch64_bfd_free_cached_info
9665 #define bfd_elfNN_bfd_is_target_special_symbol \
9666 elfNN_aarch64_is_target_special_symbol
9668 #define bfd_elfNN_bfd_link_hash_table_create \
9669 elfNN_aarch64_link_hash_table_create
9671 #define bfd_elfNN_bfd_merge_private_bfd_data \
9672 elfNN_aarch64_merge_private_bfd_data
9674 #define bfd_elfNN_bfd_print_private_bfd_data \
9675 elfNN_aarch64_print_private_bfd_data
9677 #define bfd_elfNN_bfd_reloc_type_lookup \
9678 elfNN_aarch64_reloc_type_lookup
9680 #define bfd_elfNN_bfd_reloc_name_lookup \
9681 elfNN_aarch64_reloc_name_lookup
9683 #define bfd_elfNN_bfd_set_private_flags \
9684 elfNN_aarch64_set_private_flags
9686 #define bfd_elfNN_find_inliner_info \
9687 elfNN_aarch64_find_inliner_info
9689 #define bfd_elfNN_find_nearest_line \
9690 elfNN_aarch64_find_nearest_line
9692 #define bfd_elfNN_mkobject \
9693 elfNN_aarch64_mkobject
9695 #define bfd_elfNN_new_section_hook \
9696 elfNN_aarch64_new_section_hook
9698 #define elf_backend_adjust_dynamic_symbol \
9699 elfNN_aarch64_adjust_dynamic_symbol
9701 #define elf_backend_always_size_sections \
9702 elfNN_aarch64_always_size_sections
9704 #define elf_backend_check_relocs \
9705 elfNN_aarch64_check_relocs
9707 #define elf_backend_copy_indirect_symbol \
9708 elfNN_aarch64_copy_indirect_symbol
9710 /* Create .dynbss, and .rela.bss sections in DYNOBJ, and set up shortcuts
9711 to them in our hash. */
9712 #define elf_backend_create_dynamic_sections \
9713 elfNN_aarch64_create_dynamic_sections
9715 #define elf_backend_init_index_section \
9716 _bfd_elf_init_2_index_sections
9718 #define elf_backend_finish_dynamic_sections \
9719 elfNN_aarch64_finish_dynamic_sections
9721 #define elf_backend_finish_dynamic_symbol \
9722 elfNN_aarch64_finish_dynamic_symbol
9724 #define elf_backend_object_p \
9725 elfNN_aarch64_object_p
9727 #define elf_backend_output_arch_local_syms \
9728 elfNN_aarch64_output_arch_local_syms
9730 #define elf_backend_plt_sym_val \
9731 elfNN_aarch64_plt_sym_val
9733 #define elf_backend_post_process_headers \
9734 elfNN_aarch64_post_process_headers
9736 #define elf_backend_relocate_section \
9737 elfNN_aarch64_relocate_section
9739 #define elf_backend_reloc_type_class \
9740 elfNN_aarch64_reloc_type_class
9742 #define elf_backend_section_from_shdr \
9743 elfNN_aarch64_section_from_shdr
9745 #define elf_backend_size_dynamic_sections \
9746 elfNN_aarch64_size_dynamic_sections
9748 #define elf_backend_size_info \
9749 elfNN_aarch64_size_info
9751 #define elf_backend_write_section \
9752 elfNN_aarch64_write_section
9754 #define elf_backend_symbol_processing \
9755 elfNN_aarch64_backend_symbol_processing
9757 #define elf_backend_can_refcount 1
9758 #define elf_backend_can_gc_sections 1
9759 #define elf_backend_plt_readonly 1
9760 #define elf_backend_want_got_plt 1
9761 #define elf_backend_want_plt_sym 0
9762 #define elf_backend_want_dynrelro 1
9763 #define elf_backend_may_use_rel_p 0
9764 #define elf_backend_may_use_rela_p 1
9765 #define elf_backend_default_use_rela_p 1
9766 #define elf_backend_rela_normal 1
9767 #define elf_backend_dtrel_excludes_plt 1
9768 #define elf_backend_got_header_size (GOT_ENTRY_SIZE * 3)
9769 #define elf_backend_default_execstack 0
9770 #define elf_backend_extern_protected_data 1
9771 #define elf_backend_hash_symbol elf_aarch64_hash_symbol
9773 #undef elf_backend_obj_attrs_section
9774 #define elf_backend_obj_attrs_section ".ARM.attributes"
9776 #include "elfNN-target.h"
9778 /* CloudABI support. */
9780 #undef TARGET_LITTLE_SYM
9781 #define TARGET_LITTLE_SYM aarch64_elfNN_le_cloudabi_vec
9782 #undef TARGET_LITTLE_NAME
9783 #define TARGET_LITTLE_NAME "elfNN-littleaarch64-cloudabi"
9784 #undef TARGET_BIG_SYM
9785 #define TARGET_BIG_SYM aarch64_elfNN_be_cloudabi_vec
9786 #undef TARGET_BIG_NAME
9787 #define TARGET_BIG_NAME "elfNN-bigaarch64-cloudabi"
9790 #define ELF_OSABI ELFOSABI_CLOUDABI
9793 #define elfNN_bed elfNN_aarch64_cloudabi_bed
9795 #include "elfNN-target.h"