1 /* AArch64-specific support for NN-bit ELF.
2 Copyright (C) 2009-2015 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"
142 #include "bfd_stdint.h"
145 #include "objalloc.h"
146 #include "elf/aarch64.h"
147 #include "elfxx-aarch64.h"
152 #define AARCH64_R(NAME) R_AARCH64_ ## NAME
153 #define AARCH64_R_STR(NAME) "R_AARCH64_" #NAME
154 #define HOWTO64(...) HOWTO (__VA_ARGS__)
155 #define HOWTO32(...) EMPTY_HOWTO (0)
156 #define LOG_FILE_ALIGN 3
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
167 #define IS_AARCH64_TLS_RELOC(R_TYPE) \
168 ((R_TYPE) == BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC \
169 || (R_TYPE) == BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21 \
170 || (R_TYPE) == BFD_RELOC_AARCH64_TLSGD_ADR_PREL21 \
171 || (R_TYPE) == BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21 \
172 || (R_TYPE) == BFD_RELOC_AARCH64_TLSIE_LD32_GOTTPREL_LO12_NC \
173 || (R_TYPE) == BFD_RELOC_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC \
174 || (R_TYPE) == BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19 \
175 || (R_TYPE) == BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G0_NC \
176 || (R_TYPE) == BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G1 \
177 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_ADD_DTPREL_LO12 \
178 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC \
179 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21 \
180 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_ADR_PREL21 \
181 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_HI12 \
182 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_LO12 \
183 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_LO12_NC \
184 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0 \
185 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC \
186 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1 \
187 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1_NC \
188 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G2 \
189 || (R_TYPE) == BFD_RELOC_AARCH64_TLS_DTPMOD \
190 || (R_TYPE) == BFD_RELOC_AARCH64_TLS_DTPREL \
191 || (R_TYPE) == BFD_RELOC_AARCH64_TLS_TPREL \
192 || IS_AARCH64_TLSDESC_RELOC ((R_TYPE)))
194 #define IS_AARCH64_TLS_RELAX_RELOC(R_TYPE) \
195 ((R_TYPE) == BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21 \
196 || (R_TYPE) == BFD_RELOC_AARCH64_TLSGD_ADR_PREL21 \
197 || (R_TYPE) == BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC \
198 || (R_TYPE) == BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21 \
199 || (R_TYPE) == BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19 \
200 || (R_TYPE) == BFD_RELOC_AARCH64_TLSIE_LDNN_GOTTPREL_LO12_NC \
201 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21 \
202 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21 \
203 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_LD_PREL19 \
204 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_LDNN_LO12_NC \
205 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_CALL \
206 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_ADD_LO12_NC)
208 #define IS_AARCH64_TLSDESC_RELOC(R_TYPE) \
209 ((R_TYPE) == BFD_RELOC_AARCH64_TLSDESC \
210 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_ADD \
211 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_ADD_LO12_NC \
212 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21 \
213 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21 \
214 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_CALL \
215 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_LD32_LO12_NC \
216 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_LD64_LO12_NC \
217 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_LDR \
218 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_LD_PREL19 \
219 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_OFF_G0_NC \
220 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_OFF_G1)
222 #define ELIMINATE_COPY_RELOCS 0
224 /* Return size of a relocation entry. HTAB is the bfd's
225 elf_aarch64_link_hash_entry. */
226 #define RELOC_SIZE(HTAB) (sizeof (ElfNN_External_Rela))
228 /* GOT Entry size - 8 bytes in ELF64 and 4 bytes in ELF32. */
229 #define GOT_ENTRY_SIZE (ARCH_SIZE / 8)
230 #define PLT_ENTRY_SIZE (32)
231 #define PLT_SMALL_ENTRY_SIZE (16)
232 #define PLT_TLSDESC_ENTRY_SIZE (32)
234 /* Encoding of the nop instruction */
235 #define INSN_NOP 0xd503201f
237 #define aarch64_compute_jump_table_size(htab) \
238 (((htab)->root.srelplt == NULL) ? 0 \
239 : (htab)->root.srelplt->reloc_count * GOT_ENTRY_SIZE)
241 /* The first entry in a procedure linkage table looks like this
242 if the distance between the PLTGOT and the PLT is < 4GB use
243 these PLT entries. Note that the dynamic linker gets &PLTGOT[2]
244 in x16 and needs to work out PLTGOT[1] by using an address of
245 [x16,#-GOT_ENTRY_SIZE]. */
246 static const bfd_byte elfNN_aarch64_small_plt0_entry[PLT_ENTRY_SIZE] =
248 0xf0, 0x7b, 0xbf, 0xa9, /* stp x16, x30, [sp, #-16]! */
249 0x10, 0x00, 0x00, 0x90, /* adrp x16, (GOT+16) */
251 0x11, 0x0A, 0x40, 0xf9, /* ldr x17, [x16, #PLT_GOT+0x10] */
252 0x10, 0x42, 0x00, 0x91, /* add x16, x16,#PLT_GOT+0x10 */
254 0x11, 0x0A, 0x40, 0xb9, /* ldr w17, [x16, #PLT_GOT+0x8] */
255 0x10, 0x22, 0x00, 0x11, /* add w16, w16,#PLT_GOT+0x8 */
257 0x20, 0x02, 0x1f, 0xd6, /* br x17 */
258 0x1f, 0x20, 0x03, 0xd5, /* nop */
259 0x1f, 0x20, 0x03, 0xd5, /* nop */
260 0x1f, 0x20, 0x03, 0xd5, /* nop */
263 /* Per function entry in a procedure linkage table looks like this
264 if the distance between the PLTGOT and the PLT is < 4GB use
265 these PLT entries. */
266 static const bfd_byte elfNN_aarch64_small_plt_entry[PLT_SMALL_ENTRY_SIZE] =
268 0x10, 0x00, 0x00, 0x90, /* adrp x16, PLTGOT + n * 8 */
270 0x11, 0x02, 0x40, 0xf9, /* ldr x17, [x16, PLTGOT + n * 8] */
271 0x10, 0x02, 0x00, 0x91, /* add x16, x16, :lo12:PLTGOT + n * 8 */
273 0x11, 0x02, 0x40, 0xb9, /* ldr w17, [x16, PLTGOT + n * 4] */
274 0x10, 0x02, 0x00, 0x11, /* add w16, w16, :lo12:PLTGOT + n * 4 */
276 0x20, 0x02, 0x1f, 0xd6, /* br x17. */
279 static const bfd_byte
280 elfNN_aarch64_tlsdesc_small_plt_entry[PLT_TLSDESC_ENTRY_SIZE] =
282 0xe2, 0x0f, 0xbf, 0xa9, /* stp x2, x3, [sp, #-16]! */
283 0x02, 0x00, 0x00, 0x90, /* adrp x2, 0 */
284 0x03, 0x00, 0x00, 0x90, /* adrp x3, 0 */
286 0x42, 0x00, 0x40, 0xf9, /* ldr x2, [x2, #0] */
287 0x63, 0x00, 0x00, 0x91, /* add x3, x3, 0 */
289 0x42, 0x00, 0x40, 0xb9, /* ldr w2, [x2, #0] */
290 0x63, 0x00, 0x00, 0x11, /* add w3, w3, 0 */
292 0x40, 0x00, 0x1f, 0xd6, /* br x2 */
293 0x1f, 0x20, 0x03, 0xd5, /* nop */
294 0x1f, 0x20, 0x03, 0xd5, /* nop */
297 #define elf_info_to_howto elfNN_aarch64_info_to_howto
298 #define elf_info_to_howto_rel elfNN_aarch64_info_to_howto
300 #define AARCH64_ELF_ABI_VERSION 0
302 /* In case we're on a 32-bit machine, construct a 64-bit "-1" value. */
303 #define ALL_ONES (~ (bfd_vma) 0)
305 /* Indexed by the bfd interal reloc enumerators.
306 Therefore, the table needs to be synced with BFD_RELOC_AARCH64_*
309 static reloc_howto_type elfNN_aarch64_howto_table[] =
313 /* Basic data relocations. */
316 HOWTO (R_AARCH64_NULL, /* type */
318 3, /* size (0 = byte, 1 = short, 2 = long) */
320 FALSE, /* pc_relative */
322 complain_overflow_dont, /* complain_on_overflow */
323 bfd_elf_generic_reloc, /* special_function */
324 "R_AARCH64_NULL", /* name */
325 FALSE, /* partial_inplace */
328 FALSE), /* pcrel_offset */
330 HOWTO (R_AARCH64_NONE, /* type */
332 3, /* size (0 = byte, 1 = short, 2 = long) */
334 FALSE, /* pc_relative */
336 complain_overflow_dont, /* complain_on_overflow */
337 bfd_elf_generic_reloc, /* special_function */
338 "R_AARCH64_NONE", /* name */
339 FALSE, /* partial_inplace */
342 FALSE), /* pcrel_offset */
346 HOWTO64 (AARCH64_R (ABS64), /* type */
348 4, /* size (4 = long long) */
350 FALSE, /* pc_relative */
352 complain_overflow_unsigned, /* complain_on_overflow */
353 bfd_elf_generic_reloc, /* special_function */
354 AARCH64_R_STR (ABS64), /* name */
355 FALSE, /* partial_inplace */
356 ALL_ONES, /* src_mask */
357 ALL_ONES, /* dst_mask */
358 FALSE), /* pcrel_offset */
361 HOWTO (AARCH64_R (ABS32), /* type */
363 2, /* size (0 = byte, 1 = short, 2 = long) */
365 FALSE, /* pc_relative */
367 complain_overflow_unsigned, /* complain_on_overflow */
368 bfd_elf_generic_reloc, /* special_function */
369 AARCH64_R_STR (ABS32), /* name */
370 FALSE, /* partial_inplace */
371 0xffffffff, /* src_mask */
372 0xffffffff, /* dst_mask */
373 FALSE), /* pcrel_offset */
376 HOWTO (AARCH64_R (ABS16), /* type */
378 1, /* size (0 = byte, 1 = short, 2 = long) */
380 FALSE, /* pc_relative */
382 complain_overflow_unsigned, /* complain_on_overflow */
383 bfd_elf_generic_reloc, /* special_function */
384 AARCH64_R_STR (ABS16), /* name */
385 FALSE, /* partial_inplace */
386 0xffff, /* src_mask */
387 0xffff, /* dst_mask */
388 FALSE), /* pcrel_offset */
390 /* .xword: (S+A-P) */
391 HOWTO64 (AARCH64_R (PREL64), /* type */
393 4, /* size (4 = long long) */
395 TRUE, /* pc_relative */
397 complain_overflow_signed, /* complain_on_overflow */
398 bfd_elf_generic_reloc, /* special_function */
399 AARCH64_R_STR (PREL64), /* name */
400 FALSE, /* partial_inplace */
401 ALL_ONES, /* src_mask */
402 ALL_ONES, /* dst_mask */
403 TRUE), /* pcrel_offset */
406 HOWTO (AARCH64_R (PREL32), /* type */
408 2, /* size (0 = byte, 1 = short, 2 = long) */
410 TRUE, /* pc_relative */
412 complain_overflow_signed, /* complain_on_overflow */
413 bfd_elf_generic_reloc, /* special_function */
414 AARCH64_R_STR (PREL32), /* name */
415 FALSE, /* partial_inplace */
416 0xffffffff, /* src_mask */
417 0xffffffff, /* dst_mask */
418 TRUE), /* pcrel_offset */
421 HOWTO (AARCH64_R (PREL16), /* type */
423 1, /* size (0 = byte, 1 = short, 2 = long) */
425 TRUE, /* pc_relative */
427 complain_overflow_signed, /* complain_on_overflow */
428 bfd_elf_generic_reloc, /* special_function */
429 AARCH64_R_STR (PREL16), /* name */
430 FALSE, /* partial_inplace */
431 0xffff, /* src_mask */
432 0xffff, /* dst_mask */
433 TRUE), /* pcrel_offset */
435 /* Group relocations to create a 16, 32, 48 or 64 bit
436 unsigned data or abs address inline. */
438 /* MOVZ: ((S+A) >> 0) & 0xffff */
439 HOWTO (AARCH64_R (MOVW_UABS_G0), /* type */
441 2, /* size (0 = byte, 1 = short, 2 = long) */
443 FALSE, /* pc_relative */
445 complain_overflow_unsigned, /* complain_on_overflow */
446 bfd_elf_generic_reloc, /* special_function */
447 AARCH64_R_STR (MOVW_UABS_G0), /* name */
448 FALSE, /* partial_inplace */
449 0xffff, /* src_mask */
450 0xffff, /* dst_mask */
451 FALSE), /* pcrel_offset */
453 /* MOVK: ((S+A) >> 0) & 0xffff [no overflow check] */
454 HOWTO (AARCH64_R (MOVW_UABS_G0_NC), /* type */
456 2, /* size (0 = byte, 1 = short, 2 = long) */
458 FALSE, /* pc_relative */
460 complain_overflow_dont, /* complain_on_overflow */
461 bfd_elf_generic_reloc, /* special_function */
462 AARCH64_R_STR (MOVW_UABS_G0_NC), /* name */
463 FALSE, /* partial_inplace */
464 0xffff, /* src_mask */
465 0xffff, /* dst_mask */
466 FALSE), /* pcrel_offset */
468 /* MOVZ: ((S+A) >> 16) & 0xffff */
469 HOWTO (AARCH64_R (MOVW_UABS_G1), /* type */
471 2, /* size (0 = byte, 1 = short, 2 = long) */
473 FALSE, /* pc_relative */
475 complain_overflow_unsigned, /* complain_on_overflow */
476 bfd_elf_generic_reloc, /* special_function */
477 AARCH64_R_STR (MOVW_UABS_G1), /* name */
478 FALSE, /* partial_inplace */
479 0xffff, /* src_mask */
480 0xffff, /* dst_mask */
481 FALSE), /* pcrel_offset */
483 /* MOVK: ((S+A) >> 16) & 0xffff [no overflow check] */
484 HOWTO64 (AARCH64_R (MOVW_UABS_G1_NC), /* type */
486 2, /* size (0 = byte, 1 = short, 2 = long) */
488 FALSE, /* pc_relative */
490 complain_overflow_dont, /* complain_on_overflow */
491 bfd_elf_generic_reloc, /* special_function */
492 AARCH64_R_STR (MOVW_UABS_G1_NC), /* name */
493 FALSE, /* partial_inplace */
494 0xffff, /* src_mask */
495 0xffff, /* dst_mask */
496 FALSE), /* pcrel_offset */
498 /* MOVZ: ((S+A) >> 32) & 0xffff */
499 HOWTO64 (AARCH64_R (MOVW_UABS_G2), /* type */
501 2, /* size (0 = byte, 1 = short, 2 = long) */
503 FALSE, /* pc_relative */
505 complain_overflow_unsigned, /* complain_on_overflow */
506 bfd_elf_generic_reloc, /* special_function */
507 AARCH64_R_STR (MOVW_UABS_G2), /* name */
508 FALSE, /* partial_inplace */
509 0xffff, /* src_mask */
510 0xffff, /* dst_mask */
511 FALSE), /* pcrel_offset */
513 /* MOVK: ((S+A) >> 32) & 0xffff [no overflow check] */
514 HOWTO64 (AARCH64_R (MOVW_UABS_G2_NC), /* type */
516 2, /* size (0 = byte, 1 = short, 2 = long) */
518 FALSE, /* pc_relative */
520 complain_overflow_dont, /* complain_on_overflow */
521 bfd_elf_generic_reloc, /* special_function */
522 AARCH64_R_STR (MOVW_UABS_G2_NC), /* name */
523 FALSE, /* partial_inplace */
524 0xffff, /* src_mask */
525 0xffff, /* dst_mask */
526 FALSE), /* pcrel_offset */
528 /* MOVZ: ((S+A) >> 48) & 0xffff */
529 HOWTO64 (AARCH64_R (MOVW_UABS_G3), /* type */
531 2, /* size (0 = byte, 1 = short, 2 = long) */
533 FALSE, /* pc_relative */
535 complain_overflow_unsigned, /* complain_on_overflow */
536 bfd_elf_generic_reloc, /* special_function */
537 AARCH64_R_STR (MOVW_UABS_G3), /* name */
538 FALSE, /* partial_inplace */
539 0xffff, /* src_mask */
540 0xffff, /* dst_mask */
541 FALSE), /* pcrel_offset */
543 /* Group relocations to create high part of a 16, 32, 48 or 64 bit
544 signed data or abs address inline. Will change instruction
545 to MOVN or MOVZ depending on sign of calculated value. */
547 /* MOV[ZN]: ((S+A) >> 0) & 0xffff */
548 HOWTO (AARCH64_R (MOVW_SABS_G0), /* type */
550 2, /* size (0 = byte, 1 = short, 2 = long) */
552 FALSE, /* pc_relative */
554 complain_overflow_signed, /* complain_on_overflow */
555 bfd_elf_generic_reloc, /* special_function */
556 AARCH64_R_STR (MOVW_SABS_G0), /* name */
557 FALSE, /* partial_inplace */
558 0xffff, /* src_mask */
559 0xffff, /* dst_mask */
560 FALSE), /* pcrel_offset */
562 /* MOV[ZN]: ((S+A) >> 16) & 0xffff */
563 HOWTO64 (AARCH64_R (MOVW_SABS_G1), /* type */
565 2, /* size (0 = byte, 1 = short, 2 = long) */
567 FALSE, /* pc_relative */
569 complain_overflow_signed, /* complain_on_overflow */
570 bfd_elf_generic_reloc, /* special_function */
571 AARCH64_R_STR (MOVW_SABS_G1), /* name */
572 FALSE, /* partial_inplace */
573 0xffff, /* src_mask */
574 0xffff, /* dst_mask */
575 FALSE), /* pcrel_offset */
577 /* MOV[ZN]: ((S+A) >> 32) & 0xffff */
578 HOWTO64 (AARCH64_R (MOVW_SABS_G2), /* type */
580 2, /* size (0 = byte, 1 = short, 2 = long) */
582 FALSE, /* pc_relative */
584 complain_overflow_signed, /* complain_on_overflow */
585 bfd_elf_generic_reloc, /* special_function */
586 AARCH64_R_STR (MOVW_SABS_G2), /* name */
587 FALSE, /* partial_inplace */
588 0xffff, /* src_mask */
589 0xffff, /* dst_mask */
590 FALSE), /* pcrel_offset */
592 /* Relocations to generate 19, 21 and 33 bit PC-relative load/store
593 addresses: PG(x) is (x & ~0xfff). */
595 /* LD-lit: ((S+A-P) >> 2) & 0x7ffff */
596 HOWTO (AARCH64_R (LD_PREL_LO19), /* type */
598 2, /* size (0 = byte, 1 = short, 2 = long) */
600 TRUE, /* pc_relative */
602 complain_overflow_signed, /* complain_on_overflow */
603 bfd_elf_generic_reloc, /* special_function */
604 AARCH64_R_STR (LD_PREL_LO19), /* name */
605 FALSE, /* partial_inplace */
606 0x7ffff, /* src_mask */
607 0x7ffff, /* dst_mask */
608 TRUE), /* pcrel_offset */
610 /* ADR: (S+A-P) & 0x1fffff */
611 HOWTO (AARCH64_R (ADR_PREL_LO21), /* type */
613 2, /* size (0 = byte, 1 = short, 2 = long) */
615 TRUE, /* pc_relative */
617 complain_overflow_signed, /* complain_on_overflow */
618 bfd_elf_generic_reloc, /* special_function */
619 AARCH64_R_STR (ADR_PREL_LO21), /* name */
620 FALSE, /* partial_inplace */
621 0x1fffff, /* src_mask */
622 0x1fffff, /* dst_mask */
623 TRUE), /* pcrel_offset */
625 /* ADRP: ((PG(S+A)-PG(P)) >> 12) & 0x1fffff */
626 HOWTO (AARCH64_R (ADR_PREL_PG_HI21), /* type */
628 2, /* size (0 = byte, 1 = short, 2 = long) */
630 TRUE, /* pc_relative */
632 complain_overflow_signed, /* complain_on_overflow */
633 bfd_elf_generic_reloc, /* special_function */
634 AARCH64_R_STR (ADR_PREL_PG_HI21), /* name */
635 FALSE, /* partial_inplace */
636 0x1fffff, /* src_mask */
637 0x1fffff, /* dst_mask */
638 TRUE), /* pcrel_offset */
640 /* ADRP: ((PG(S+A)-PG(P)) >> 12) & 0x1fffff [no overflow check] */
641 HOWTO64 (AARCH64_R (ADR_PREL_PG_HI21_NC), /* type */
643 2, /* size (0 = byte, 1 = short, 2 = long) */
645 TRUE, /* pc_relative */
647 complain_overflow_dont, /* complain_on_overflow */
648 bfd_elf_generic_reloc, /* special_function */
649 AARCH64_R_STR (ADR_PREL_PG_HI21_NC), /* name */
650 FALSE, /* partial_inplace */
651 0x1fffff, /* src_mask */
652 0x1fffff, /* dst_mask */
653 TRUE), /* pcrel_offset */
655 /* ADD: (S+A) & 0xfff [no overflow check] */
656 HOWTO (AARCH64_R (ADD_ABS_LO12_NC), /* type */
658 2, /* size (0 = byte, 1 = short, 2 = long) */
660 FALSE, /* pc_relative */
662 complain_overflow_dont, /* complain_on_overflow */
663 bfd_elf_generic_reloc, /* special_function */
664 AARCH64_R_STR (ADD_ABS_LO12_NC), /* name */
665 FALSE, /* partial_inplace */
666 0x3ffc00, /* src_mask */
667 0x3ffc00, /* dst_mask */
668 FALSE), /* pcrel_offset */
670 /* LD/ST8: (S+A) & 0xfff */
671 HOWTO (AARCH64_R (LDST8_ABS_LO12_NC), /* type */
673 2, /* size (0 = byte, 1 = short, 2 = long) */
675 FALSE, /* pc_relative */
677 complain_overflow_dont, /* complain_on_overflow */
678 bfd_elf_generic_reloc, /* special_function */
679 AARCH64_R_STR (LDST8_ABS_LO12_NC), /* name */
680 FALSE, /* partial_inplace */
681 0xfff, /* src_mask */
682 0xfff, /* dst_mask */
683 FALSE), /* pcrel_offset */
685 /* Relocations for control-flow instructions. */
687 /* TBZ/NZ: ((S+A-P) >> 2) & 0x3fff */
688 HOWTO (AARCH64_R (TSTBR14), /* type */
690 2, /* size (0 = byte, 1 = short, 2 = long) */
692 TRUE, /* pc_relative */
694 complain_overflow_signed, /* complain_on_overflow */
695 bfd_elf_generic_reloc, /* special_function */
696 AARCH64_R_STR (TSTBR14), /* name */
697 FALSE, /* partial_inplace */
698 0x3fff, /* src_mask */
699 0x3fff, /* dst_mask */
700 TRUE), /* pcrel_offset */
702 /* B.cond: ((S+A-P) >> 2) & 0x7ffff */
703 HOWTO (AARCH64_R (CONDBR19), /* type */
705 2, /* size (0 = byte, 1 = short, 2 = long) */
707 TRUE, /* pc_relative */
709 complain_overflow_signed, /* complain_on_overflow */
710 bfd_elf_generic_reloc, /* special_function */
711 AARCH64_R_STR (CONDBR19), /* name */
712 FALSE, /* partial_inplace */
713 0x7ffff, /* src_mask */
714 0x7ffff, /* dst_mask */
715 TRUE), /* pcrel_offset */
717 /* B: ((S+A-P) >> 2) & 0x3ffffff */
718 HOWTO (AARCH64_R (JUMP26), /* type */
720 2, /* size (0 = byte, 1 = short, 2 = long) */
722 TRUE, /* pc_relative */
724 complain_overflow_signed, /* complain_on_overflow */
725 bfd_elf_generic_reloc, /* special_function */
726 AARCH64_R_STR (JUMP26), /* name */
727 FALSE, /* partial_inplace */
728 0x3ffffff, /* src_mask */
729 0x3ffffff, /* dst_mask */
730 TRUE), /* pcrel_offset */
732 /* BL: ((S+A-P) >> 2) & 0x3ffffff */
733 HOWTO (AARCH64_R (CALL26), /* type */
735 2, /* size (0 = byte, 1 = short, 2 = long) */
737 TRUE, /* pc_relative */
739 complain_overflow_signed, /* complain_on_overflow */
740 bfd_elf_generic_reloc, /* special_function */
741 AARCH64_R_STR (CALL26), /* name */
742 FALSE, /* partial_inplace */
743 0x3ffffff, /* src_mask */
744 0x3ffffff, /* dst_mask */
745 TRUE), /* pcrel_offset */
747 /* LD/ST16: (S+A) & 0xffe */
748 HOWTO (AARCH64_R (LDST16_ABS_LO12_NC), /* type */
750 2, /* size (0 = byte, 1 = short, 2 = long) */
752 FALSE, /* pc_relative */
754 complain_overflow_dont, /* complain_on_overflow */
755 bfd_elf_generic_reloc, /* special_function */
756 AARCH64_R_STR (LDST16_ABS_LO12_NC), /* name */
757 FALSE, /* partial_inplace */
758 0xffe, /* src_mask */
759 0xffe, /* dst_mask */
760 FALSE), /* pcrel_offset */
762 /* LD/ST32: (S+A) & 0xffc */
763 HOWTO (AARCH64_R (LDST32_ABS_LO12_NC), /* type */
765 2, /* size (0 = byte, 1 = short, 2 = long) */
767 FALSE, /* pc_relative */
769 complain_overflow_dont, /* complain_on_overflow */
770 bfd_elf_generic_reloc, /* special_function */
771 AARCH64_R_STR (LDST32_ABS_LO12_NC), /* name */
772 FALSE, /* partial_inplace */
773 0xffc, /* src_mask */
774 0xffc, /* dst_mask */
775 FALSE), /* pcrel_offset */
777 /* LD/ST64: (S+A) & 0xff8 */
778 HOWTO (AARCH64_R (LDST64_ABS_LO12_NC), /* type */
780 2, /* size (0 = byte, 1 = short, 2 = long) */
782 FALSE, /* pc_relative */
784 complain_overflow_dont, /* complain_on_overflow */
785 bfd_elf_generic_reloc, /* special_function */
786 AARCH64_R_STR (LDST64_ABS_LO12_NC), /* name */
787 FALSE, /* partial_inplace */
788 0xff8, /* src_mask */
789 0xff8, /* dst_mask */
790 FALSE), /* pcrel_offset */
792 /* LD/ST128: (S+A) & 0xff0 */
793 HOWTO (AARCH64_R (LDST128_ABS_LO12_NC), /* type */
795 2, /* size (0 = byte, 1 = short, 2 = long) */
797 FALSE, /* pc_relative */
799 complain_overflow_dont, /* complain_on_overflow */
800 bfd_elf_generic_reloc, /* special_function */
801 AARCH64_R_STR (LDST128_ABS_LO12_NC), /* name */
802 FALSE, /* partial_inplace */
803 0xff0, /* src_mask */
804 0xff0, /* dst_mask */
805 FALSE), /* pcrel_offset */
807 /* Set a load-literal immediate field to bits
808 0x1FFFFC of G(S)-P */
809 HOWTO (AARCH64_R (GOT_LD_PREL19), /* type */
811 2, /* size (0 = byte,1 = short,2 = long) */
813 TRUE, /* pc_relative */
815 complain_overflow_signed, /* complain_on_overflow */
816 bfd_elf_generic_reloc, /* special_function */
817 AARCH64_R_STR (GOT_LD_PREL19), /* name */
818 FALSE, /* partial_inplace */
819 0xffffe0, /* src_mask */
820 0xffffe0, /* dst_mask */
821 TRUE), /* pcrel_offset */
823 /* Get to the page for the GOT entry for the symbol
824 (G(S) - P) using an ADRP instruction. */
825 HOWTO (AARCH64_R (ADR_GOT_PAGE), /* type */
827 2, /* size (0 = byte, 1 = short, 2 = long) */
829 TRUE, /* pc_relative */
831 complain_overflow_dont, /* complain_on_overflow */
832 bfd_elf_generic_reloc, /* special_function */
833 AARCH64_R_STR (ADR_GOT_PAGE), /* name */
834 FALSE, /* partial_inplace */
835 0x1fffff, /* src_mask */
836 0x1fffff, /* dst_mask */
837 TRUE), /* pcrel_offset */
839 /* LD64: GOT offset G(S) & 0xff8 */
840 HOWTO64 (AARCH64_R (LD64_GOT_LO12_NC), /* type */
842 2, /* size (0 = byte, 1 = short, 2 = long) */
844 FALSE, /* pc_relative */
846 complain_overflow_dont, /* complain_on_overflow */
847 bfd_elf_generic_reloc, /* special_function */
848 AARCH64_R_STR (LD64_GOT_LO12_NC), /* name */
849 FALSE, /* partial_inplace */
850 0xff8, /* src_mask */
851 0xff8, /* dst_mask */
852 FALSE), /* pcrel_offset */
854 /* LD32: GOT offset G(S) & 0xffc */
855 HOWTO32 (AARCH64_R (LD32_GOT_LO12_NC), /* type */
857 2, /* size (0 = byte, 1 = short, 2 = long) */
859 FALSE, /* pc_relative */
861 complain_overflow_dont, /* complain_on_overflow */
862 bfd_elf_generic_reloc, /* special_function */
863 AARCH64_R_STR (LD32_GOT_LO12_NC), /* name */
864 FALSE, /* partial_inplace */
865 0xffc, /* src_mask */
866 0xffc, /* dst_mask */
867 FALSE), /* pcrel_offset */
869 /* LD64: GOT offset for the symbol. */
870 HOWTO64 (AARCH64_R (LD64_GOTOFF_LO15), /* type */
872 2, /* size (0 = byte, 1 = short, 2 = long) */
874 FALSE, /* pc_relative */
876 complain_overflow_unsigned, /* complain_on_overflow */
877 bfd_elf_generic_reloc, /* special_function */
878 AARCH64_R_STR (LD64_GOTOFF_LO15), /* name */
879 FALSE, /* partial_inplace */
880 0x7ff8, /* src_mask */
881 0x7ff8, /* dst_mask */
882 FALSE), /* pcrel_offset */
884 /* LD32: GOT offset to the page address of GOT table.
885 (G(S) - PAGE (_GLOBAL_OFFSET_TABLE_)) & 0x5ffc. */
886 HOWTO32 (AARCH64_R (LD32_GOTPAGE_LO14), /* type */
888 2, /* size (0 = byte, 1 = short, 2 = long) */
890 FALSE, /* pc_relative */
892 complain_overflow_unsigned, /* complain_on_overflow */
893 bfd_elf_generic_reloc, /* special_function */
894 AARCH64_R_STR (LD32_GOTPAGE_LO14), /* name */
895 FALSE, /* partial_inplace */
896 0x5ffc, /* src_mask */
897 0x5ffc, /* dst_mask */
898 FALSE), /* pcrel_offset */
900 /* LD64: GOT offset to the page address of GOT table.
901 (G(S) - PAGE (_GLOBAL_OFFSET_TABLE_)) & 0x7ff8. */
902 HOWTO64 (AARCH64_R (LD64_GOTPAGE_LO15), /* type */
904 2, /* size (0 = byte, 1 = short, 2 = long) */
906 FALSE, /* pc_relative */
908 complain_overflow_unsigned, /* complain_on_overflow */
909 bfd_elf_generic_reloc, /* special_function */
910 AARCH64_R_STR (LD64_GOTPAGE_LO15), /* name */
911 FALSE, /* partial_inplace */
912 0x7ff8, /* src_mask */
913 0x7ff8, /* dst_mask */
914 FALSE), /* pcrel_offset */
916 /* Get to the page for the GOT entry for the symbol
917 (G(S) - P) using an ADRP instruction. */
918 HOWTO (AARCH64_R (TLSGD_ADR_PAGE21), /* type */
920 2, /* size (0 = byte, 1 = short, 2 = long) */
922 TRUE, /* pc_relative */
924 complain_overflow_dont, /* complain_on_overflow */
925 bfd_elf_generic_reloc, /* special_function */
926 AARCH64_R_STR (TLSGD_ADR_PAGE21), /* name */
927 FALSE, /* partial_inplace */
928 0x1fffff, /* src_mask */
929 0x1fffff, /* dst_mask */
930 TRUE), /* pcrel_offset */
932 HOWTO (AARCH64_R (TLSGD_ADR_PREL21), /* type */
934 2, /* size (0 = byte, 1 = short, 2 = long) */
936 TRUE, /* pc_relative */
938 complain_overflow_dont, /* complain_on_overflow */
939 bfd_elf_generic_reloc, /* special_function */
940 AARCH64_R_STR (TLSGD_ADR_PREL21), /* name */
941 FALSE, /* partial_inplace */
942 0x1fffff, /* src_mask */
943 0x1fffff, /* dst_mask */
944 TRUE), /* pcrel_offset */
946 /* ADD: GOT offset G(S) & 0xff8 [no overflow check] */
947 HOWTO (AARCH64_R (TLSGD_ADD_LO12_NC), /* type */
949 2, /* size (0 = byte, 1 = short, 2 = long) */
951 FALSE, /* pc_relative */
953 complain_overflow_dont, /* complain_on_overflow */
954 bfd_elf_generic_reloc, /* special_function */
955 AARCH64_R_STR (TLSGD_ADD_LO12_NC), /* name */
956 FALSE, /* partial_inplace */
957 0xfff, /* src_mask */
958 0xfff, /* dst_mask */
959 FALSE), /* pcrel_offset */
961 HOWTO64 (AARCH64_R (TLSIE_MOVW_GOTTPREL_G1), /* type */
963 2, /* size (0 = byte, 1 = short, 2 = long) */
965 FALSE, /* pc_relative */
967 complain_overflow_dont, /* complain_on_overflow */
968 bfd_elf_generic_reloc, /* special_function */
969 AARCH64_R_STR (TLSIE_MOVW_GOTTPREL_G1), /* name */
970 FALSE, /* partial_inplace */
971 0xffff, /* src_mask */
972 0xffff, /* dst_mask */
973 FALSE), /* pcrel_offset */
975 HOWTO64 (AARCH64_R (TLSIE_MOVW_GOTTPREL_G0_NC), /* type */
977 2, /* size (0 = byte, 1 = short, 2 = long) */
979 FALSE, /* pc_relative */
981 complain_overflow_dont, /* complain_on_overflow */
982 bfd_elf_generic_reloc, /* special_function */
983 AARCH64_R_STR (TLSIE_MOVW_GOTTPREL_G0_NC), /* name */
984 FALSE, /* partial_inplace */
985 0xffff, /* src_mask */
986 0xffff, /* dst_mask */
987 FALSE), /* pcrel_offset */
989 HOWTO (AARCH64_R (TLSIE_ADR_GOTTPREL_PAGE21), /* type */
991 2, /* size (0 = byte, 1 = short, 2 = long) */
993 FALSE, /* pc_relative */
995 complain_overflow_dont, /* complain_on_overflow */
996 bfd_elf_generic_reloc, /* special_function */
997 AARCH64_R_STR (TLSIE_ADR_GOTTPREL_PAGE21), /* name */
998 FALSE, /* partial_inplace */
999 0x1fffff, /* src_mask */
1000 0x1fffff, /* dst_mask */
1001 FALSE), /* pcrel_offset */
1003 HOWTO64 (AARCH64_R (TLSIE_LD64_GOTTPREL_LO12_NC), /* type */
1005 2, /* size (0 = byte, 1 = short, 2 = long) */
1007 FALSE, /* pc_relative */
1009 complain_overflow_dont, /* complain_on_overflow */
1010 bfd_elf_generic_reloc, /* special_function */
1011 AARCH64_R_STR (TLSIE_LD64_GOTTPREL_LO12_NC), /* name */
1012 FALSE, /* partial_inplace */
1013 0xff8, /* src_mask */
1014 0xff8, /* dst_mask */
1015 FALSE), /* pcrel_offset */
1017 HOWTO32 (AARCH64_R (TLSIE_LD32_GOTTPREL_LO12_NC), /* type */
1019 2, /* size (0 = byte, 1 = short, 2 = long) */
1021 FALSE, /* pc_relative */
1023 complain_overflow_dont, /* complain_on_overflow */
1024 bfd_elf_generic_reloc, /* special_function */
1025 AARCH64_R_STR (TLSIE_LD32_GOTTPREL_LO12_NC), /* name */
1026 FALSE, /* partial_inplace */
1027 0xffc, /* src_mask */
1028 0xffc, /* dst_mask */
1029 FALSE), /* pcrel_offset */
1031 HOWTO (AARCH64_R (TLSIE_LD_GOTTPREL_PREL19), /* type */
1033 2, /* size (0 = byte, 1 = short, 2 = long) */
1035 FALSE, /* pc_relative */
1037 complain_overflow_dont, /* complain_on_overflow */
1038 bfd_elf_generic_reloc, /* special_function */
1039 AARCH64_R_STR (TLSIE_LD_GOTTPREL_PREL19), /* name */
1040 FALSE, /* partial_inplace */
1041 0x1ffffc, /* src_mask */
1042 0x1ffffc, /* dst_mask */
1043 FALSE), /* pcrel_offset */
1045 /* Unsigned 12 bit byte offset to module TLS base address. */
1046 HOWTO (AARCH64_R (TLSLD_ADD_DTPREL_LO12), /* type */
1048 2, /* size (0 = byte, 1 = short, 2 = long) */
1050 FALSE, /* pc_relative */
1052 complain_overflow_unsigned, /* complain_on_overflow */
1053 bfd_elf_generic_reloc, /* special_function */
1054 AARCH64_R_STR (TLSLD_ADD_DTPREL_LO12), /* name */
1055 FALSE, /* partial_inplace */
1056 0xfff, /* src_mask */
1057 0xfff, /* dst_mask */
1058 FALSE), /* pcrel_offset */
1060 /* ADD: GOT offset G(S) & 0xff8 [no overflow check] */
1061 HOWTO (AARCH64_R (TLSLD_ADD_LO12_NC), /* type */
1063 2, /* size (0 = byte, 1 = short, 2 = long) */
1065 FALSE, /* pc_relative */
1067 complain_overflow_dont, /* complain_on_overflow */
1068 bfd_elf_generic_reloc, /* special_function */
1069 AARCH64_R_STR (TLSLD_ADD_LO12_NC), /* name */
1070 FALSE, /* partial_inplace */
1071 0xfff, /* src_mask */
1072 0xfff, /* dst_mask */
1073 FALSE), /* pcrel_offset */
1075 /* Get to the page for the GOT entry for the symbol
1076 (G(S) - P) using an ADRP instruction. */
1077 HOWTO (AARCH64_R (TLSLD_ADR_PAGE21), /* type */
1078 12, /* rightshift */
1079 2, /* size (0 = byte, 1 = short, 2 = long) */
1081 TRUE, /* pc_relative */
1083 complain_overflow_signed, /* complain_on_overflow */
1084 bfd_elf_generic_reloc, /* special_function */
1085 AARCH64_R_STR (TLSLD_ADR_PAGE21), /* name */
1086 FALSE, /* partial_inplace */
1087 0x1fffff, /* src_mask */
1088 0x1fffff, /* dst_mask */
1089 TRUE), /* pcrel_offset */
1091 HOWTO (AARCH64_R (TLSLD_ADR_PREL21), /* type */
1093 2, /* size (0 = byte, 1 = short, 2 = long) */
1095 TRUE, /* pc_relative */
1097 complain_overflow_signed, /* complain_on_overflow */
1098 bfd_elf_generic_reloc, /* special_function */
1099 AARCH64_R_STR (TLSLD_ADR_PREL21), /* name */
1100 FALSE, /* partial_inplace */
1101 0x1fffff, /* src_mask */
1102 0x1fffff, /* dst_mask */
1103 TRUE), /* pcrel_offset */
1105 HOWTO64 (AARCH64_R (TLSLE_MOVW_TPREL_G2), /* type */
1106 32, /* rightshift */
1107 2, /* size (0 = byte, 1 = short, 2 = long) */
1109 FALSE, /* pc_relative */
1111 complain_overflow_unsigned, /* complain_on_overflow */
1112 bfd_elf_generic_reloc, /* special_function */
1113 AARCH64_R_STR (TLSLE_MOVW_TPREL_G2), /* name */
1114 FALSE, /* partial_inplace */
1115 0xffff, /* src_mask */
1116 0xffff, /* dst_mask */
1117 FALSE), /* pcrel_offset */
1119 HOWTO (AARCH64_R (TLSLE_MOVW_TPREL_G1), /* type */
1120 16, /* rightshift */
1121 2, /* size (0 = byte, 1 = short, 2 = long) */
1123 FALSE, /* pc_relative */
1125 complain_overflow_dont, /* complain_on_overflow */
1126 bfd_elf_generic_reloc, /* special_function */
1127 AARCH64_R_STR (TLSLE_MOVW_TPREL_G1), /* name */
1128 FALSE, /* partial_inplace */
1129 0xffff, /* src_mask */
1130 0xffff, /* dst_mask */
1131 FALSE), /* pcrel_offset */
1133 HOWTO64 (AARCH64_R (TLSLE_MOVW_TPREL_G1_NC), /* type */
1134 16, /* rightshift */
1135 2, /* size (0 = byte, 1 = short, 2 = long) */
1137 FALSE, /* pc_relative */
1139 complain_overflow_dont, /* complain_on_overflow */
1140 bfd_elf_generic_reloc, /* special_function */
1141 AARCH64_R_STR (TLSLE_MOVW_TPREL_G1_NC), /* name */
1142 FALSE, /* partial_inplace */
1143 0xffff, /* src_mask */
1144 0xffff, /* dst_mask */
1145 FALSE), /* pcrel_offset */
1147 HOWTO (AARCH64_R (TLSLE_MOVW_TPREL_G0), /* type */
1149 2, /* size (0 = byte, 1 = short, 2 = long) */
1151 FALSE, /* pc_relative */
1153 complain_overflow_dont, /* complain_on_overflow */
1154 bfd_elf_generic_reloc, /* special_function */
1155 AARCH64_R_STR (TLSLE_MOVW_TPREL_G0), /* name */
1156 FALSE, /* partial_inplace */
1157 0xffff, /* src_mask */
1158 0xffff, /* dst_mask */
1159 FALSE), /* pcrel_offset */
1161 HOWTO (AARCH64_R (TLSLE_MOVW_TPREL_G0_NC), /* type */
1163 2, /* size (0 = byte, 1 = short, 2 = long) */
1165 FALSE, /* pc_relative */
1167 complain_overflow_dont, /* complain_on_overflow */
1168 bfd_elf_generic_reloc, /* special_function */
1169 AARCH64_R_STR (TLSLE_MOVW_TPREL_G0_NC), /* name */
1170 FALSE, /* partial_inplace */
1171 0xffff, /* src_mask */
1172 0xffff, /* dst_mask */
1173 FALSE), /* pcrel_offset */
1175 HOWTO (AARCH64_R (TLSLE_ADD_TPREL_HI12), /* type */
1176 12, /* rightshift */
1177 2, /* size (0 = byte, 1 = short, 2 = long) */
1179 FALSE, /* pc_relative */
1181 complain_overflow_unsigned, /* complain_on_overflow */
1182 bfd_elf_generic_reloc, /* special_function */
1183 AARCH64_R_STR (TLSLE_ADD_TPREL_HI12), /* name */
1184 FALSE, /* partial_inplace */
1185 0xfff, /* src_mask */
1186 0xfff, /* dst_mask */
1187 FALSE), /* pcrel_offset */
1189 HOWTO (AARCH64_R (TLSLE_ADD_TPREL_LO12), /* type */
1191 2, /* size (0 = byte, 1 = short, 2 = long) */
1193 FALSE, /* pc_relative */
1195 complain_overflow_unsigned, /* complain_on_overflow */
1196 bfd_elf_generic_reloc, /* special_function */
1197 AARCH64_R_STR (TLSLE_ADD_TPREL_LO12), /* name */
1198 FALSE, /* partial_inplace */
1199 0xfff, /* src_mask */
1200 0xfff, /* dst_mask */
1201 FALSE), /* pcrel_offset */
1203 HOWTO (AARCH64_R (TLSLE_ADD_TPREL_LO12_NC), /* type */
1205 2, /* size (0 = byte, 1 = short, 2 = long) */
1207 FALSE, /* pc_relative */
1209 complain_overflow_dont, /* complain_on_overflow */
1210 bfd_elf_generic_reloc, /* special_function */
1211 AARCH64_R_STR (TLSLE_ADD_TPREL_LO12_NC), /* name */
1212 FALSE, /* partial_inplace */
1213 0xfff, /* src_mask */
1214 0xfff, /* dst_mask */
1215 FALSE), /* pcrel_offset */
1217 HOWTO (AARCH64_R (TLSDESC_LD_PREL19), /* type */
1219 2, /* size (0 = byte, 1 = short, 2 = long) */
1221 TRUE, /* pc_relative */
1223 complain_overflow_dont, /* complain_on_overflow */
1224 bfd_elf_generic_reloc, /* special_function */
1225 AARCH64_R_STR (TLSDESC_LD_PREL19), /* name */
1226 FALSE, /* partial_inplace */
1227 0x0ffffe0, /* src_mask */
1228 0x0ffffe0, /* dst_mask */
1229 TRUE), /* pcrel_offset */
1231 HOWTO (AARCH64_R (TLSDESC_ADR_PREL21), /* type */
1233 2, /* size (0 = byte, 1 = short, 2 = long) */
1235 TRUE, /* pc_relative */
1237 complain_overflow_dont, /* complain_on_overflow */
1238 bfd_elf_generic_reloc, /* special_function */
1239 AARCH64_R_STR (TLSDESC_ADR_PREL21), /* name */
1240 FALSE, /* partial_inplace */
1241 0x1fffff, /* src_mask */
1242 0x1fffff, /* dst_mask */
1243 TRUE), /* pcrel_offset */
1245 /* Get to the page for the GOT entry for the symbol
1246 (G(S) - P) using an ADRP instruction. */
1247 HOWTO (AARCH64_R (TLSDESC_ADR_PAGE21), /* type */
1248 12, /* rightshift */
1249 2, /* size (0 = byte, 1 = short, 2 = long) */
1251 TRUE, /* pc_relative */
1253 complain_overflow_dont, /* complain_on_overflow */
1254 bfd_elf_generic_reloc, /* special_function */
1255 AARCH64_R_STR (TLSDESC_ADR_PAGE21), /* name */
1256 FALSE, /* partial_inplace */
1257 0x1fffff, /* src_mask */
1258 0x1fffff, /* dst_mask */
1259 TRUE), /* pcrel_offset */
1261 /* LD64: GOT offset G(S) & 0xff8. */
1262 HOWTO64 (AARCH64_R (TLSDESC_LD64_LO12_NC), /* type */
1264 2, /* size (0 = byte, 1 = short, 2 = long) */
1266 FALSE, /* pc_relative */
1268 complain_overflow_dont, /* complain_on_overflow */
1269 bfd_elf_generic_reloc, /* special_function */
1270 AARCH64_R_STR (TLSDESC_LD64_LO12_NC), /* name */
1271 FALSE, /* partial_inplace */
1272 0xff8, /* src_mask */
1273 0xff8, /* dst_mask */
1274 FALSE), /* pcrel_offset */
1276 /* LD32: GOT offset G(S) & 0xffc. */
1277 HOWTO32 (AARCH64_R (TLSDESC_LD32_LO12_NC), /* type */
1279 2, /* size (0 = byte, 1 = short, 2 = long) */
1281 FALSE, /* pc_relative */
1283 complain_overflow_dont, /* complain_on_overflow */
1284 bfd_elf_generic_reloc, /* special_function */
1285 AARCH64_R_STR (TLSDESC_LD32_LO12_NC), /* name */
1286 FALSE, /* partial_inplace */
1287 0xffc, /* src_mask */
1288 0xffc, /* dst_mask */
1289 FALSE), /* pcrel_offset */
1291 /* ADD: GOT offset G(S) & 0xfff. */
1292 HOWTO (AARCH64_R (TLSDESC_ADD_LO12_NC), /* type */
1294 2, /* size (0 = byte, 1 = short, 2 = long) */
1296 FALSE, /* pc_relative */
1298 complain_overflow_dont, /* complain_on_overflow */
1299 bfd_elf_generic_reloc, /* special_function */
1300 AARCH64_R_STR (TLSDESC_ADD_LO12_NC), /* name */
1301 FALSE, /* partial_inplace */
1302 0xfff, /* src_mask */
1303 0xfff, /* dst_mask */
1304 FALSE), /* pcrel_offset */
1306 HOWTO64 (AARCH64_R (TLSDESC_OFF_G1), /* type */
1307 16, /* rightshift */
1308 2, /* size (0 = byte, 1 = short, 2 = long) */
1310 FALSE, /* pc_relative */
1312 complain_overflow_dont, /* complain_on_overflow */
1313 bfd_elf_generic_reloc, /* special_function */
1314 AARCH64_R_STR (TLSDESC_OFF_G1), /* name */
1315 FALSE, /* partial_inplace */
1316 0xffff, /* src_mask */
1317 0xffff, /* dst_mask */
1318 FALSE), /* pcrel_offset */
1320 HOWTO64 (AARCH64_R (TLSDESC_OFF_G0_NC), /* type */
1322 2, /* size (0 = byte, 1 = short, 2 = long) */
1324 FALSE, /* pc_relative */
1326 complain_overflow_dont, /* complain_on_overflow */
1327 bfd_elf_generic_reloc, /* special_function */
1328 AARCH64_R_STR (TLSDESC_OFF_G0_NC), /* name */
1329 FALSE, /* partial_inplace */
1330 0xffff, /* src_mask */
1331 0xffff, /* dst_mask */
1332 FALSE), /* pcrel_offset */
1334 HOWTO64 (AARCH64_R (TLSDESC_LDR), /* type */
1336 2, /* size (0 = byte, 1 = short, 2 = long) */
1338 FALSE, /* pc_relative */
1340 complain_overflow_dont, /* complain_on_overflow */
1341 bfd_elf_generic_reloc, /* special_function */
1342 AARCH64_R_STR (TLSDESC_LDR), /* name */
1343 FALSE, /* partial_inplace */
1346 FALSE), /* pcrel_offset */
1348 HOWTO64 (AARCH64_R (TLSDESC_ADD), /* type */
1350 2, /* size (0 = byte, 1 = short, 2 = long) */
1352 FALSE, /* pc_relative */
1354 complain_overflow_dont, /* complain_on_overflow */
1355 bfd_elf_generic_reloc, /* special_function */
1356 AARCH64_R_STR (TLSDESC_ADD), /* name */
1357 FALSE, /* partial_inplace */
1360 FALSE), /* pcrel_offset */
1362 HOWTO (AARCH64_R (TLSDESC_CALL), /* type */
1364 2, /* size (0 = byte, 1 = short, 2 = long) */
1366 FALSE, /* pc_relative */
1368 complain_overflow_dont, /* complain_on_overflow */
1369 bfd_elf_generic_reloc, /* special_function */
1370 AARCH64_R_STR (TLSDESC_CALL), /* name */
1371 FALSE, /* partial_inplace */
1374 FALSE), /* pcrel_offset */
1376 HOWTO (AARCH64_R (COPY), /* type */
1378 2, /* size (0 = byte, 1 = short, 2 = long) */
1380 FALSE, /* pc_relative */
1382 complain_overflow_bitfield, /* complain_on_overflow */
1383 bfd_elf_generic_reloc, /* special_function */
1384 AARCH64_R_STR (COPY), /* name */
1385 TRUE, /* partial_inplace */
1386 0xffffffff, /* src_mask */
1387 0xffffffff, /* dst_mask */
1388 FALSE), /* pcrel_offset */
1390 HOWTO (AARCH64_R (GLOB_DAT), /* type */
1392 2, /* size (0 = byte, 1 = short, 2 = long) */
1394 FALSE, /* pc_relative */
1396 complain_overflow_bitfield, /* complain_on_overflow */
1397 bfd_elf_generic_reloc, /* special_function */
1398 AARCH64_R_STR (GLOB_DAT), /* name */
1399 TRUE, /* partial_inplace */
1400 0xffffffff, /* src_mask */
1401 0xffffffff, /* dst_mask */
1402 FALSE), /* pcrel_offset */
1404 HOWTO (AARCH64_R (JUMP_SLOT), /* type */
1406 2, /* size (0 = byte, 1 = short, 2 = long) */
1408 FALSE, /* pc_relative */
1410 complain_overflow_bitfield, /* complain_on_overflow */
1411 bfd_elf_generic_reloc, /* special_function */
1412 AARCH64_R_STR (JUMP_SLOT), /* name */
1413 TRUE, /* partial_inplace */
1414 0xffffffff, /* src_mask */
1415 0xffffffff, /* dst_mask */
1416 FALSE), /* pcrel_offset */
1418 HOWTO (AARCH64_R (RELATIVE), /* type */
1420 2, /* size (0 = byte, 1 = short, 2 = long) */
1422 FALSE, /* pc_relative */
1424 complain_overflow_bitfield, /* complain_on_overflow */
1425 bfd_elf_generic_reloc, /* special_function */
1426 AARCH64_R_STR (RELATIVE), /* name */
1427 TRUE, /* partial_inplace */
1428 ALL_ONES, /* src_mask */
1429 ALL_ONES, /* dst_mask */
1430 FALSE), /* pcrel_offset */
1432 HOWTO (AARCH64_R (TLS_DTPMOD), /* type */
1434 2, /* size (0 = byte, 1 = short, 2 = long) */
1436 FALSE, /* pc_relative */
1438 complain_overflow_dont, /* complain_on_overflow */
1439 bfd_elf_generic_reloc, /* special_function */
1441 AARCH64_R_STR (TLS_DTPMOD64), /* name */
1443 AARCH64_R_STR (TLS_DTPMOD), /* name */
1445 FALSE, /* partial_inplace */
1447 ALL_ONES, /* dst_mask */
1448 FALSE), /* pc_reloffset */
1450 HOWTO (AARCH64_R (TLS_DTPREL), /* type */
1452 2, /* size (0 = byte, 1 = short, 2 = long) */
1454 FALSE, /* pc_relative */
1456 complain_overflow_dont, /* complain_on_overflow */
1457 bfd_elf_generic_reloc, /* special_function */
1459 AARCH64_R_STR (TLS_DTPREL64), /* name */
1461 AARCH64_R_STR (TLS_DTPREL), /* name */
1463 FALSE, /* partial_inplace */
1465 ALL_ONES, /* dst_mask */
1466 FALSE), /* pcrel_offset */
1468 HOWTO (AARCH64_R (TLS_TPREL), /* type */
1470 2, /* size (0 = byte, 1 = short, 2 = long) */
1472 FALSE, /* pc_relative */
1474 complain_overflow_dont, /* complain_on_overflow */
1475 bfd_elf_generic_reloc, /* special_function */
1477 AARCH64_R_STR (TLS_TPREL64), /* name */
1479 AARCH64_R_STR (TLS_TPREL), /* name */
1481 FALSE, /* partial_inplace */
1483 ALL_ONES, /* dst_mask */
1484 FALSE), /* pcrel_offset */
1486 HOWTO (AARCH64_R (TLSDESC), /* type */
1488 2, /* size (0 = byte, 1 = short, 2 = long) */
1490 FALSE, /* pc_relative */
1492 complain_overflow_dont, /* complain_on_overflow */
1493 bfd_elf_generic_reloc, /* special_function */
1494 AARCH64_R_STR (TLSDESC), /* name */
1495 FALSE, /* partial_inplace */
1497 ALL_ONES, /* dst_mask */
1498 FALSE), /* pcrel_offset */
1500 HOWTO (AARCH64_R (IRELATIVE), /* type */
1502 2, /* size (0 = byte, 1 = short, 2 = long) */
1504 FALSE, /* pc_relative */
1506 complain_overflow_bitfield, /* complain_on_overflow */
1507 bfd_elf_generic_reloc, /* special_function */
1508 AARCH64_R_STR (IRELATIVE), /* name */
1509 FALSE, /* partial_inplace */
1511 ALL_ONES, /* dst_mask */
1512 FALSE), /* pcrel_offset */
1517 static reloc_howto_type elfNN_aarch64_howto_none =
1518 HOWTO (R_AARCH64_NONE, /* type */
1520 3, /* size (0 = byte, 1 = short, 2 = long) */
1522 FALSE, /* pc_relative */
1524 complain_overflow_dont,/* complain_on_overflow */
1525 bfd_elf_generic_reloc, /* special_function */
1526 "R_AARCH64_NONE", /* name */
1527 FALSE, /* partial_inplace */
1530 FALSE); /* pcrel_offset */
1532 /* Given HOWTO, return the bfd internal relocation enumerator. */
1534 static bfd_reloc_code_real_type
1535 elfNN_aarch64_bfd_reloc_from_howto (reloc_howto_type *howto)
1538 = (int) ARRAY_SIZE (elfNN_aarch64_howto_table);
1539 const ptrdiff_t offset
1540 = howto - elfNN_aarch64_howto_table;
1542 if (offset > 0 && offset < size - 1)
1543 return BFD_RELOC_AARCH64_RELOC_START + offset;
1545 if (howto == &elfNN_aarch64_howto_none)
1546 return BFD_RELOC_AARCH64_NONE;
1548 return BFD_RELOC_AARCH64_RELOC_START;
1551 /* Given R_TYPE, return the bfd internal relocation enumerator. */
1553 static bfd_reloc_code_real_type
1554 elfNN_aarch64_bfd_reloc_from_type (unsigned int r_type)
1556 static bfd_boolean initialized_p = FALSE;
1557 /* Indexed by R_TYPE, values are offsets in the howto_table. */
1558 static unsigned int offsets[R_AARCH64_end];
1560 if (initialized_p == FALSE)
1564 for (i = 1; i < ARRAY_SIZE (elfNN_aarch64_howto_table) - 1; ++i)
1565 if (elfNN_aarch64_howto_table[i].type != 0)
1566 offsets[elfNN_aarch64_howto_table[i].type] = i;
1568 initialized_p = TRUE;
1571 if (r_type == R_AARCH64_NONE || r_type == R_AARCH64_NULL)
1572 return BFD_RELOC_AARCH64_NONE;
1574 /* PR 17512: file: b371e70a. */
1575 if (r_type >= R_AARCH64_end)
1577 _bfd_error_handler (_("Invalid AArch64 reloc number: %d"), r_type);
1578 bfd_set_error (bfd_error_bad_value);
1579 return BFD_RELOC_AARCH64_NONE;
1582 return BFD_RELOC_AARCH64_RELOC_START + offsets[r_type];
1585 struct elf_aarch64_reloc_map
1587 bfd_reloc_code_real_type from;
1588 bfd_reloc_code_real_type to;
1591 /* Map bfd generic reloc to AArch64-specific reloc. */
1592 static const struct elf_aarch64_reloc_map elf_aarch64_reloc_map[] =
1594 {BFD_RELOC_NONE, BFD_RELOC_AARCH64_NONE},
1596 /* Basic data relocations. */
1597 {BFD_RELOC_CTOR, BFD_RELOC_AARCH64_NN},
1598 {BFD_RELOC_64, BFD_RELOC_AARCH64_64},
1599 {BFD_RELOC_32, BFD_RELOC_AARCH64_32},
1600 {BFD_RELOC_16, BFD_RELOC_AARCH64_16},
1601 {BFD_RELOC_64_PCREL, BFD_RELOC_AARCH64_64_PCREL},
1602 {BFD_RELOC_32_PCREL, BFD_RELOC_AARCH64_32_PCREL},
1603 {BFD_RELOC_16_PCREL, BFD_RELOC_AARCH64_16_PCREL},
1606 /* Given the bfd internal relocation enumerator in CODE, return the
1607 corresponding howto entry. */
1609 static reloc_howto_type *
1610 elfNN_aarch64_howto_from_bfd_reloc (bfd_reloc_code_real_type code)
1614 /* Convert bfd generic reloc to AArch64-specific reloc. */
1615 if (code < BFD_RELOC_AARCH64_RELOC_START
1616 || code > BFD_RELOC_AARCH64_RELOC_END)
1617 for (i = 0; i < ARRAY_SIZE (elf_aarch64_reloc_map); i++)
1618 if (elf_aarch64_reloc_map[i].from == code)
1620 code = elf_aarch64_reloc_map[i].to;
1624 if (code > BFD_RELOC_AARCH64_RELOC_START
1625 && code < BFD_RELOC_AARCH64_RELOC_END)
1626 if (elfNN_aarch64_howto_table[code - BFD_RELOC_AARCH64_RELOC_START].type)
1627 return &elfNN_aarch64_howto_table[code - BFD_RELOC_AARCH64_RELOC_START];
1629 if (code == BFD_RELOC_AARCH64_NONE)
1630 return &elfNN_aarch64_howto_none;
1635 static reloc_howto_type *
1636 elfNN_aarch64_howto_from_type (unsigned int r_type)
1638 bfd_reloc_code_real_type val;
1639 reloc_howto_type *howto;
1644 bfd_set_error (bfd_error_bad_value);
1649 if (r_type == R_AARCH64_NONE)
1650 return &elfNN_aarch64_howto_none;
1652 val = elfNN_aarch64_bfd_reloc_from_type (r_type);
1653 howto = elfNN_aarch64_howto_from_bfd_reloc (val);
1658 bfd_set_error (bfd_error_bad_value);
1663 elfNN_aarch64_info_to_howto (bfd *abfd ATTRIBUTE_UNUSED, arelent *bfd_reloc,
1664 Elf_Internal_Rela *elf_reloc)
1666 unsigned int r_type;
1668 r_type = ELFNN_R_TYPE (elf_reloc->r_info);
1669 bfd_reloc->howto = elfNN_aarch64_howto_from_type (r_type);
1672 static reloc_howto_type *
1673 elfNN_aarch64_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED,
1674 bfd_reloc_code_real_type code)
1676 reloc_howto_type *howto = elfNN_aarch64_howto_from_bfd_reloc (code);
1681 bfd_set_error (bfd_error_bad_value);
1685 static reloc_howto_type *
1686 elfNN_aarch64_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED,
1691 for (i = 1; i < ARRAY_SIZE (elfNN_aarch64_howto_table) - 1; ++i)
1692 if (elfNN_aarch64_howto_table[i].name != NULL
1693 && strcasecmp (elfNN_aarch64_howto_table[i].name, r_name) == 0)
1694 return &elfNN_aarch64_howto_table[i];
1699 #define TARGET_LITTLE_SYM aarch64_elfNN_le_vec
1700 #define TARGET_LITTLE_NAME "elfNN-littleaarch64"
1701 #define TARGET_BIG_SYM aarch64_elfNN_be_vec
1702 #define TARGET_BIG_NAME "elfNN-bigaarch64"
1704 /* The linker script knows the section names for placement.
1705 The entry_names are used to do simple name mangling on the stubs.
1706 Given a function name, and its type, the stub can be found. The
1707 name can be changed. The only requirement is the %s be present. */
1708 #define STUB_ENTRY_NAME "__%s_veneer"
1710 /* The name of the dynamic interpreter. This is put in the .interp
1712 #define ELF_DYNAMIC_INTERPRETER "/lib/ld.so.1"
1714 #define AARCH64_MAX_FWD_BRANCH_OFFSET \
1715 (((1 << 25) - 1) << 2)
1716 #define AARCH64_MAX_BWD_BRANCH_OFFSET \
1719 #define AARCH64_MAX_ADRP_IMM ((1 << 20) - 1)
1720 #define AARCH64_MIN_ADRP_IMM (-(1 << 20))
1723 aarch64_valid_for_adrp_p (bfd_vma value, bfd_vma place)
1725 bfd_signed_vma offset = (bfd_signed_vma) (PG (value) - PG (place)) >> 12;
1726 return offset <= AARCH64_MAX_ADRP_IMM && offset >= AARCH64_MIN_ADRP_IMM;
1730 aarch64_valid_branch_p (bfd_vma value, bfd_vma place)
1732 bfd_signed_vma offset = (bfd_signed_vma) (value - place);
1733 return (offset <= AARCH64_MAX_FWD_BRANCH_OFFSET
1734 && offset >= AARCH64_MAX_BWD_BRANCH_OFFSET);
1737 static const uint32_t aarch64_adrp_branch_stub [] =
1739 0x90000010, /* adrp ip0, X */
1740 /* R_AARCH64_ADR_HI21_PCREL(X) */
1741 0x91000210, /* add ip0, ip0, :lo12:X */
1742 /* R_AARCH64_ADD_ABS_LO12_NC(X) */
1743 0xd61f0200, /* br ip0 */
1746 static const uint32_t aarch64_long_branch_stub[] =
1749 0x58000090, /* ldr ip0, 1f */
1751 0x18000090, /* ldr wip0, 1f */
1753 0x10000011, /* adr ip1, #0 */
1754 0x8b110210, /* add ip0, ip0, ip1 */
1755 0xd61f0200, /* br ip0 */
1756 0x00000000, /* 1: .xword or .word
1757 R_AARCH64_PRELNN(X) + 12
1762 static const uint32_t aarch64_erratum_835769_stub[] =
1764 0x00000000, /* Placeholder for multiply accumulate. */
1765 0x14000000, /* b <label> */
1768 static const uint32_t aarch64_erratum_843419_stub[] =
1770 0x00000000, /* Placeholder for LDR instruction. */
1771 0x14000000, /* b <label> */
1774 /* Section name for stubs is the associated section name plus this
1776 #define STUB_SUFFIX ".stub"
1778 enum elf_aarch64_stub_type
1781 aarch64_stub_adrp_branch,
1782 aarch64_stub_long_branch,
1783 aarch64_stub_erratum_835769_veneer,
1784 aarch64_stub_erratum_843419_veneer,
1787 struct elf_aarch64_stub_hash_entry
1789 /* Base hash table entry structure. */
1790 struct bfd_hash_entry root;
1792 /* The stub section. */
1795 /* Offset within stub_sec of the beginning of this stub. */
1796 bfd_vma stub_offset;
1798 /* Given the symbol's value and its section we can determine its final
1799 value when building the stubs (so the stub knows where to jump). */
1800 bfd_vma target_value;
1801 asection *target_section;
1803 enum elf_aarch64_stub_type stub_type;
1805 /* The symbol table entry, if any, that this was derived from. */
1806 struct elf_aarch64_link_hash_entry *h;
1808 /* Destination symbol type */
1809 unsigned char st_type;
1811 /* Where this stub is being called from, or, in the case of combined
1812 stub sections, the first input section in the group. */
1815 /* The name for the local symbol at the start of this stub. The
1816 stub name in the hash table has to be unique; this does not, so
1817 it can be friendlier. */
1820 /* The instruction which caused this stub to be generated (only valid for
1821 erratum 835769 workaround stubs at present). */
1822 uint32_t veneered_insn;
1824 /* In an erratum 843419 workaround stub, the ADRP instruction offset. */
1825 bfd_vma adrp_offset;
1828 /* Used to build a map of a section. This is required for mixed-endian
1831 typedef struct elf_elf_section_map
1836 elf_aarch64_section_map;
1839 typedef struct _aarch64_elf_section_data
1841 struct bfd_elf_section_data elf;
1842 unsigned int mapcount;
1843 unsigned int mapsize;
1844 elf_aarch64_section_map *map;
1846 _aarch64_elf_section_data;
1848 #define elf_aarch64_section_data(sec) \
1849 ((_aarch64_elf_section_data *) elf_section_data (sec))
1851 /* The size of the thread control block which is defined to be two pointers. */
1852 #define TCB_SIZE (ARCH_SIZE/8)*2
1854 struct elf_aarch64_local_symbol
1856 unsigned int got_type;
1857 bfd_signed_vma got_refcount;
1860 /* Offset of the GOTPLT entry reserved for the TLS descriptor. The
1861 offset is from the end of the jump table and reserved entries
1864 The magic value (bfd_vma) -1 indicates that an offset has not be
1866 bfd_vma tlsdesc_got_jump_table_offset;
1869 struct elf_aarch64_obj_tdata
1871 struct elf_obj_tdata root;
1873 /* local symbol descriptors */
1874 struct elf_aarch64_local_symbol *locals;
1876 /* Zero to warn when linking objects with incompatible enum sizes. */
1877 int no_enum_size_warning;
1879 /* Zero to warn when linking objects with incompatible wchar_t sizes. */
1880 int no_wchar_size_warning;
1883 #define elf_aarch64_tdata(bfd) \
1884 ((struct elf_aarch64_obj_tdata *) (bfd)->tdata.any)
1886 #define elf_aarch64_locals(bfd) (elf_aarch64_tdata (bfd)->locals)
1888 #define is_aarch64_elf(bfd) \
1889 (bfd_get_flavour (bfd) == bfd_target_elf_flavour \
1890 && elf_tdata (bfd) != NULL \
1891 && elf_object_id (bfd) == AARCH64_ELF_DATA)
1894 elfNN_aarch64_mkobject (bfd *abfd)
1896 return bfd_elf_allocate_object (abfd, sizeof (struct elf_aarch64_obj_tdata),
1900 #define elf_aarch64_hash_entry(ent) \
1901 ((struct elf_aarch64_link_hash_entry *)(ent))
1903 #define GOT_UNKNOWN 0
1904 #define GOT_NORMAL 1
1905 #define GOT_TLS_GD 2
1906 #define GOT_TLS_IE 4
1907 #define GOT_TLSDESC_GD 8
1909 #define GOT_TLS_GD_ANY_P(type) ((type & GOT_TLS_GD) || (type & GOT_TLSDESC_GD))
1911 /* AArch64 ELF linker hash entry. */
1912 struct elf_aarch64_link_hash_entry
1914 struct elf_link_hash_entry root;
1916 /* Track dynamic relocs copied for this symbol. */
1917 struct elf_dyn_relocs *dyn_relocs;
1919 /* Since PLT entries have variable size, we need to record the
1920 index into .got.plt instead of recomputing it from the PLT
1922 bfd_signed_vma plt_got_offset;
1924 /* Bit mask representing the type of GOT entry(s) if any required by
1926 unsigned int got_type;
1928 /* A pointer to the most recently used stub hash entry against this
1930 struct elf_aarch64_stub_hash_entry *stub_cache;
1932 /* Offset of the GOTPLT entry reserved for the TLS descriptor. The offset
1933 is from the end of the jump table and reserved entries within the PLTGOT.
1935 The magic value (bfd_vma) -1 indicates that an offset has not
1937 bfd_vma tlsdesc_got_jump_table_offset;
1941 elfNN_aarch64_symbol_got_type (struct elf_link_hash_entry *h,
1943 unsigned long r_symndx)
1946 return elf_aarch64_hash_entry (h)->got_type;
1948 if (! elf_aarch64_locals (abfd))
1951 return elf_aarch64_locals (abfd)[r_symndx].got_type;
1954 /* Get the AArch64 elf linker hash table from a link_info structure. */
1955 #define elf_aarch64_hash_table(info) \
1956 ((struct elf_aarch64_link_hash_table *) ((info)->hash))
1958 #define aarch64_stub_hash_lookup(table, string, create, copy) \
1959 ((struct elf_aarch64_stub_hash_entry *) \
1960 bfd_hash_lookup ((table), (string), (create), (copy)))
1962 /* AArch64 ELF linker hash table. */
1963 struct elf_aarch64_link_hash_table
1965 /* The main hash table. */
1966 struct elf_link_hash_table root;
1968 /* Nonzero to force PIC branch veneers. */
1971 /* Fix erratum 835769. */
1972 int fix_erratum_835769;
1974 /* Fix erratum 843419. */
1975 int fix_erratum_843419;
1977 /* Enable ADRP->ADR rewrite for erratum 843419 workaround. */
1978 int fix_erratum_843419_adr;
1980 /* The number of bytes in the initial entry in the PLT. */
1981 bfd_size_type plt_header_size;
1983 /* The number of bytes in the subsequent PLT etries. */
1984 bfd_size_type plt_entry_size;
1986 /* Short-cuts to get to dynamic linker sections. */
1990 /* Small local sym cache. */
1991 struct sym_cache sym_cache;
1993 /* For convenience in allocate_dynrelocs. */
1996 /* The amount of space used by the reserved portion of the sgotplt
1997 section, plus whatever space is used by the jump slots. */
1998 bfd_vma sgotplt_jump_table_size;
2000 /* The stub hash table. */
2001 struct bfd_hash_table stub_hash_table;
2003 /* Linker stub bfd. */
2006 /* Linker call-backs. */
2007 asection *(*add_stub_section) (const char *, asection *);
2008 void (*layout_sections_again) (void);
2010 /* Array to keep track of which stub sections have been created, and
2011 information on stub grouping. */
2014 /* This is the section to which stubs in the group will be
2017 /* The stub section. */
2021 /* Assorted information used by elfNN_aarch64_size_stubs. */
2022 unsigned int bfd_count;
2024 asection **input_list;
2026 /* The offset into splt of the PLT entry for the TLS descriptor
2027 resolver. Special values are 0, if not necessary (or not found
2028 to be necessary yet), and -1 if needed but not determined
2030 bfd_vma tlsdesc_plt;
2032 /* The GOT offset for the lazy trampoline. Communicated to the
2033 loader via DT_TLSDESC_GOT. The magic value (bfd_vma) -1
2034 indicates an offset is not allocated. */
2035 bfd_vma dt_tlsdesc_got;
2037 /* Used by local STT_GNU_IFUNC symbols. */
2038 htab_t loc_hash_table;
2039 void * loc_hash_memory;
2042 /* Create an entry in an AArch64 ELF linker hash table. */
2044 static struct bfd_hash_entry *
2045 elfNN_aarch64_link_hash_newfunc (struct bfd_hash_entry *entry,
2046 struct bfd_hash_table *table,
2049 struct elf_aarch64_link_hash_entry *ret =
2050 (struct elf_aarch64_link_hash_entry *) entry;
2052 /* Allocate the structure if it has not already been allocated by a
2055 ret = bfd_hash_allocate (table,
2056 sizeof (struct elf_aarch64_link_hash_entry));
2058 return (struct bfd_hash_entry *) ret;
2060 /* Call the allocation method of the superclass. */
2061 ret = ((struct elf_aarch64_link_hash_entry *)
2062 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry *) ret,
2066 ret->dyn_relocs = NULL;
2067 ret->got_type = GOT_UNKNOWN;
2068 ret->plt_got_offset = (bfd_vma) - 1;
2069 ret->stub_cache = NULL;
2070 ret->tlsdesc_got_jump_table_offset = (bfd_vma) - 1;
2073 return (struct bfd_hash_entry *) ret;
2076 /* Initialize an entry in the stub hash table. */
2078 static struct bfd_hash_entry *
2079 stub_hash_newfunc (struct bfd_hash_entry *entry,
2080 struct bfd_hash_table *table, const char *string)
2082 /* Allocate the structure if it has not already been allocated by a
2086 entry = bfd_hash_allocate (table,
2088 elf_aarch64_stub_hash_entry));
2093 /* Call the allocation method of the superclass. */
2094 entry = bfd_hash_newfunc (entry, table, string);
2097 struct elf_aarch64_stub_hash_entry *eh;
2099 /* Initialize the local fields. */
2100 eh = (struct elf_aarch64_stub_hash_entry *) entry;
2101 eh->adrp_offset = 0;
2102 eh->stub_sec = NULL;
2103 eh->stub_offset = 0;
2104 eh->target_value = 0;
2105 eh->target_section = NULL;
2106 eh->stub_type = aarch64_stub_none;
2114 /* Compute a hash of a local hash entry. We use elf_link_hash_entry
2115 for local symbol so that we can handle local STT_GNU_IFUNC symbols
2116 as global symbol. We reuse indx and dynstr_index for local symbol
2117 hash since they aren't used by global symbols in this backend. */
2120 elfNN_aarch64_local_htab_hash (const void *ptr)
2122 struct elf_link_hash_entry *h
2123 = (struct elf_link_hash_entry *) ptr;
2124 return ELF_LOCAL_SYMBOL_HASH (h->indx, h->dynstr_index);
2127 /* Compare local hash entries. */
2130 elfNN_aarch64_local_htab_eq (const void *ptr1, const void *ptr2)
2132 struct elf_link_hash_entry *h1
2133 = (struct elf_link_hash_entry *) ptr1;
2134 struct elf_link_hash_entry *h2
2135 = (struct elf_link_hash_entry *) ptr2;
2137 return h1->indx == h2->indx && h1->dynstr_index == h2->dynstr_index;
2140 /* Find and/or create a hash entry for local symbol. */
2142 static struct elf_link_hash_entry *
2143 elfNN_aarch64_get_local_sym_hash (struct elf_aarch64_link_hash_table *htab,
2144 bfd *abfd, const Elf_Internal_Rela *rel,
2147 struct elf_aarch64_link_hash_entry e, *ret;
2148 asection *sec = abfd->sections;
2149 hashval_t h = ELF_LOCAL_SYMBOL_HASH (sec->id,
2150 ELFNN_R_SYM (rel->r_info));
2153 e.root.indx = sec->id;
2154 e.root.dynstr_index = ELFNN_R_SYM (rel->r_info);
2155 slot = htab_find_slot_with_hash (htab->loc_hash_table, &e, h,
2156 create ? INSERT : NO_INSERT);
2163 ret = (struct elf_aarch64_link_hash_entry *) *slot;
2167 ret = (struct elf_aarch64_link_hash_entry *)
2168 objalloc_alloc ((struct objalloc *) htab->loc_hash_memory,
2169 sizeof (struct elf_aarch64_link_hash_entry));
2172 memset (ret, 0, sizeof (*ret));
2173 ret->root.indx = sec->id;
2174 ret->root.dynstr_index = ELFNN_R_SYM (rel->r_info);
2175 ret->root.dynindx = -1;
2181 /* Copy the extra info we tack onto an elf_link_hash_entry. */
2184 elfNN_aarch64_copy_indirect_symbol (struct bfd_link_info *info,
2185 struct elf_link_hash_entry *dir,
2186 struct elf_link_hash_entry *ind)
2188 struct elf_aarch64_link_hash_entry *edir, *eind;
2190 edir = (struct elf_aarch64_link_hash_entry *) dir;
2191 eind = (struct elf_aarch64_link_hash_entry *) ind;
2193 if (eind->dyn_relocs != NULL)
2195 if (edir->dyn_relocs != NULL)
2197 struct elf_dyn_relocs **pp;
2198 struct elf_dyn_relocs *p;
2200 /* Add reloc counts against the indirect sym to the direct sym
2201 list. Merge any entries against the same section. */
2202 for (pp = &eind->dyn_relocs; (p = *pp) != NULL;)
2204 struct elf_dyn_relocs *q;
2206 for (q = edir->dyn_relocs; q != NULL; q = q->next)
2207 if (q->sec == p->sec)
2209 q->pc_count += p->pc_count;
2210 q->count += p->count;
2217 *pp = edir->dyn_relocs;
2220 edir->dyn_relocs = eind->dyn_relocs;
2221 eind->dyn_relocs = NULL;
2224 if (ind->root.type == bfd_link_hash_indirect)
2226 /* Copy over PLT info. */
2227 if (dir->got.refcount <= 0)
2229 edir->got_type = eind->got_type;
2230 eind->got_type = GOT_UNKNOWN;
2234 _bfd_elf_link_hash_copy_indirect (info, dir, ind);
2237 /* Destroy an AArch64 elf linker hash table. */
2240 elfNN_aarch64_link_hash_table_free (bfd *obfd)
2242 struct elf_aarch64_link_hash_table *ret
2243 = (struct elf_aarch64_link_hash_table *) obfd->link.hash;
2245 if (ret->loc_hash_table)
2246 htab_delete (ret->loc_hash_table);
2247 if (ret->loc_hash_memory)
2248 objalloc_free ((struct objalloc *) ret->loc_hash_memory);
2250 bfd_hash_table_free (&ret->stub_hash_table);
2251 _bfd_elf_link_hash_table_free (obfd);
2254 /* Create an AArch64 elf linker hash table. */
2256 static struct bfd_link_hash_table *
2257 elfNN_aarch64_link_hash_table_create (bfd *abfd)
2259 struct elf_aarch64_link_hash_table *ret;
2260 bfd_size_type amt = sizeof (struct elf_aarch64_link_hash_table);
2262 ret = bfd_zmalloc (amt);
2266 if (!_bfd_elf_link_hash_table_init
2267 (&ret->root, abfd, elfNN_aarch64_link_hash_newfunc,
2268 sizeof (struct elf_aarch64_link_hash_entry), AARCH64_ELF_DATA))
2274 ret->plt_header_size = PLT_ENTRY_SIZE;
2275 ret->plt_entry_size = PLT_SMALL_ENTRY_SIZE;
2277 ret->dt_tlsdesc_got = (bfd_vma) - 1;
2279 if (!bfd_hash_table_init (&ret->stub_hash_table, stub_hash_newfunc,
2280 sizeof (struct elf_aarch64_stub_hash_entry)))
2282 _bfd_elf_link_hash_table_free (abfd);
2286 ret->loc_hash_table = htab_try_create (1024,
2287 elfNN_aarch64_local_htab_hash,
2288 elfNN_aarch64_local_htab_eq,
2290 ret->loc_hash_memory = objalloc_create ();
2291 if (!ret->loc_hash_table || !ret->loc_hash_memory)
2293 elfNN_aarch64_link_hash_table_free (abfd);
2296 ret->root.root.hash_table_free = elfNN_aarch64_link_hash_table_free;
2298 return &ret->root.root;
2302 aarch64_relocate (unsigned int r_type, bfd *input_bfd, asection *input_section,
2303 bfd_vma offset, bfd_vma value)
2305 reloc_howto_type *howto;
2308 howto = elfNN_aarch64_howto_from_type (r_type);
2309 place = (input_section->output_section->vma + input_section->output_offset
2312 r_type = elfNN_aarch64_bfd_reloc_from_type (r_type);
2313 value = _bfd_aarch64_elf_resolve_relocation (r_type, place, value, 0, FALSE);
2314 return _bfd_aarch64_elf_put_addend (input_bfd,
2315 input_section->contents + offset, r_type,
2319 static enum elf_aarch64_stub_type
2320 aarch64_select_branch_stub (bfd_vma value, bfd_vma place)
2322 if (aarch64_valid_for_adrp_p (value, place))
2323 return aarch64_stub_adrp_branch;
2324 return aarch64_stub_long_branch;
2327 /* Determine the type of stub needed, if any, for a call. */
2329 static enum elf_aarch64_stub_type
2330 aarch64_type_of_stub (struct bfd_link_info *info,
2331 asection *input_sec,
2332 const Elf_Internal_Rela *rel,
2334 unsigned char st_type,
2335 struct elf_aarch64_link_hash_entry *hash,
2336 bfd_vma destination)
2339 bfd_signed_vma branch_offset;
2340 unsigned int r_type;
2341 struct elf_aarch64_link_hash_table *globals;
2342 enum elf_aarch64_stub_type stub_type = aarch64_stub_none;
2343 bfd_boolean via_plt_p;
2345 if (st_type != STT_FUNC
2346 && (sym_sec != bfd_abs_section_ptr))
2349 globals = elf_aarch64_hash_table (info);
2350 via_plt_p = (globals->root.splt != NULL && hash != NULL
2351 && hash->root.plt.offset != (bfd_vma) - 1);
2352 /* Make sure call to plt stub can fit into the branch range. */
2354 destination = (globals->root.splt->output_section->vma
2355 + globals->root.splt->output_offset
2356 + hash->root.plt.offset);
2358 /* Determine where the call point is. */
2359 location = (input_sec->output_offset
2360 + input_sec->output_section->vma + rel->r_offset);
2362 branch_offset = (bfd_signed_vma) (destination - location);
2364 r_type = ELFNN_R_TYPE (rel->r_info);
2366 /* We don't want to redirect any old unconditional jump in this way,
2367 only one which is being used for a sibcall, where it is
2368 acceptable for the IP0 and IP1 registers to be clobbered. */
2369 if ((r_type == AARCH64_R (CALL26) || r_type == AARCH64_R (JUMP26))
2370 && (branch_offset > AARCH64_MAX_FWD_BRANCH_OFFSET
2371 || branch_offset < AARCH64_MAX_BWD_BRANCH_OFFSET))
2373 stub_type = aarch64_stub_long_branch;
2379 /* Build a name for an entry in the stub hash table. */
2382 elfNN_aarch64_stub_name (const asection *input_section,
2383 const asection *sym_sec,
2384 const struct elf_aarch64_link_hash_entry *hash,
2385 const Elf_Internal_Rela *rel)
2392 len = 8 + 1 + strlen (hash->root.root.root.string) + 1 + 16 + 1;
2393 stub_name = bfd_malloc (len);
2394 if (stub_name != NULL)
2395 snprintf (stub_name, len, "%08x_%s+%" BFD_VMA_FMT "x",
2396 (unsigned int) input_section->id,
2397 hash->root.root.root.string,
2402 len = 8 + 1 + 8 + 1 + 8 + 1 + 16 + 1;
2403 stub_name = bfd_malloc (len);
2404 if (stub_name != NULL)
2405 snprintf (stub_name, len, "%08x_%x:%x+%" BFD_VMA_FMT "x",
2406 (unsigned int) input_section->id,
2407 (unsigned int) sym_sec->id,
2408 (unsigned int) ELFNN_R_SYM (rel->r_info),
2415 /* Look up an entry in the stub hash. Stub entries are cached because
2416 creating the stub name takes a bit of time. */
2418 static struct elf_aarch64_stub_hash_entry *
2419 elfNN_aarch64_get_stub_entry (const asection *input_section,
2420 const asection *sym_sec,
2421 struct elf_link_hash_entry *hash,
2422 const Elf_Internal_Rela *rel,
2423 struct elf_aarch64_link_hash_table *htab)
2425 struct elf_aarch64_stub_hash_entry *stub_entry;
2426 struct elf_aarch64_link_hash_entry *h =
2427 (struct elf_aarch64_link_hash_entry *) hash;
2428 const asection *id_sec;
2430 if ((input_section->flags & SEC_CODE) == 0)
2433 /* If this input section is part of a group of sections sharing one
2434 stub section, then use the id of the first section in the group.
2435 Stub names need to include a section id, as there may well be
2436 more than one stub used to reach say, printf, and we need to
2437 distinguish between them. */
2438 id_sec = htab->stub_group[input_section->id].link_sec;
2440 if (h != NULL && h->stub_cache != NULL
2441 && h->stub_cache->h == h && h->stub_cache->id_sec == id_sec)
2443 stub_entry = h->stub_cache;
2449 stub_name = elfNN_aarch64_stub_name (id_sec, sym_sec, h, rel);
2450 if (stub_name == NULL)
2453 stub_entry = aarch64_stub_hash_lookup (&htab->stub_hash_table,
2454 stub_name, FALSE, FALSE);
2456 h->stub_cache = stub_entry;
2465 /* Create a stub section. */
2468 _bfd_aarch64_create_stub_section (asection *section,
2469 struct elf_aarch64_link_hash_table *htab)
2475 namelen = strlen (section->name);
2476 len = namelen + sizeof (STUB_SUFFIX);
2477 s_name = bfd_alloc (htab->stub_bfd, len);
2481 memcpy (s_name, section->name, namelen);
2482 memcpy (s_name + namelen, STUB_SUFFIX, sizeof (STUB_SUFFIX));
2483 return (*htab->add_stub_section) (s_name, section);
2487 /* Find or create a stub section for a link section.
2489 Fix or create the stub section used to collect stubs attached to
2490 the specified link section. */
2493 _bfd_aarch64_get_stub_for_link_section (asection *link_section,
2494 struct elf_aarch64_link_hash_table *htab)
2496 if (htab->stub_group[link_section->id].stub_sec == NULL)
2497 htab->stub_group[link_section->id].stub_sec
2498 = _bfd_aarch64_create_stub_section (link_section, htab);
2499 return htab->stub_group[link_section->id].stub_sec;
2503 /* Find or create a stub section in the stub group for an input
2507 _bfd_aarch64_create_or_find_stub_sec (asection *section,
2508 struct elf_aarch64_link_hash_table *htab)
2510 asection *link_sec = htab->stub_group[section->id].link_sec;
2511 return _bfd_aarch64_get_stub_for_link_section (link_sec, htab);
2515 /* Add a new stub entry in the stub group associated with an input
2516 section to the stub hash. Not all fields of the new stub entry are
2519 static struct elf_aarch64_stub_hash_entry *
2520 _bfd_aarch64_add_stub_entry_in_group (const char *stub_name,
2522 struct elf_aarch64_link_hash_table *htab)
2526 struct elf_aarch64_stub_hash_entry *stub_entry;
2528 link_sec = htab->stub_group[section->id].link_sec;
2529 stub_sec = _bfd_aarch64_create_or_find_stub_sec (section, htab);
2531 /* Enter this entry into the linker stub hash table. */
2532 stub_entry = aarch64_stub_hash_lookup (&htab->stub_hash_table, stub_name,
2534 if (stub_entry == NULL)
2536 (*_bfd_error_handler) (_("%s: cannot create stub entry %s"),
2537 section->owner, stub_name);
2541 stub_entry->stub_sec = stub_sec;
2542 stub_entry->stub_offset = 0;
2543 stub_entry->id_sec = link_sec;
2548 /* Add a new stub entry in the final stub section to the stub hash.
2549 Not all fields of the new stub entry are initialised. */
2551 static struct elf_aarch64_stub_hash_entry *
2552 _bfd_aarch64_add_stub_entry_after (const char *stub_name,
2553 asection *link_section,
2554 struct elf_aarch64_link_hash_table *htab)
2557 struct elf_aarch64_stub_hash_entry *stub_entry;
2559 stub_sec = _bfd_aarch64_get_stub_for_link_section (link_section, htab);
2560 stub_entry = aarch64_stub_hash_lookup (&htab->stub_hash_table, stub_name,
2562 if (stub_entry == NULL)
2564 (*_bfd_error_handler) (_("cannot create stub entry %s"), stub_name);
2568 stub_entry->stub_sec = stub_sec;
2569 stub_entry->stub_offset = 0;
2570 stub_entry->id_sec = link_section;
2577 aarch64_build_one_stub (struct bfd_hash_entry *gen_entry,
2578 void *in_arg ATTRIBUTE_UNUSED)
2580 struct elf_aarch64_stub_hash_entry *stub_entry;
2585 bfd_vma veneered_insn_loc;
2586 bfd_vma veneer_entry_loc;
2587 bfd_signed_vma branch_offset = 0;
2588 unsigned int template_size;
2589 const uint32_t *template;
2592 /* Massage our args to the form they really have. */
2593 stub_entry = (struct elf_aarch64_stub_hash_entry *) gen_entry;
2595 stub_sec = stub_entry->stub_sec;
2597 /* Make a note of the offset within the stubs for this entry. */
2598 stub_entry->stub_offset = stub_sec->size;
2599 loc = stub_sec->contents + stub_entry->stub_offset;
2601 stub_bfd = stub_sec->owner;
2603 /* This is the address of the stub destination. */
2604 sym_value = (stub_entry->target_value
2605 + stub_entry->target_section->output_offset
2606 + stub_entry->target_section->output_section->vma);
2608 if (stub_entry->stub_type == aarch64_stub_long_branch)
2610 bfd_vma place = (stub_entry->stub_offset + stub_sec->output_section->vma
2611 + stub_sec->output_offset);
2613 /* See if we can relax the stub. */
2614 if (aarch64_valid_for_adrp_p (sym_value, place))
2615 stub_entry->stub_type = aarch64_select_branch_stub (sym_value, place);
2618 switch (stub_entry->stub_type)
2620 case aarch64_stub_adrp_branch:
2621 template = aarch64_adrp_branch_stub;
2622 template_size = sizeof (aarch64_adrp_branch_stub);
2624 case aarch64_stub_long_branch:
2625 template = aarch64_long_branch_stub;
2626 template_size = sizeof (aarch64_long_branch_stub);
2628 case aarch64_stub_erratum_835769_veneer:
2629 template = aarch64_erratum_835769_stub;
2630 template_size = sizeof (aarch64_erratum_835769_stub);
2632 case aarch64_stub_erratum_843419_veneer:
2633 template = aarch64_erratum_843419_stub;
2634 template_size = sizeof (aarch64_erratum_843419_stub);
2640 for (i = 0; i < (template_size / sizeof template[0]); i++)
2642 bfd_putl32 (template[i], loc);
2646 template_size = (template_size + 7) & ~7;
2647 stub_sec->size += template_size;
2649 switch (stub_entry->stub_type)
2651 case aarch64_stub_adrp_branch:
2652 if (aarch64_relocate (AARCH64_R (ADR_PREL_PG_HI21), stub_bfd, stub_sec,
2653 stub_entry->stub_offset, sym_value))
2654 /* The stub would not have been relaxed if the offset was out
2658 if (aarch64_relocate (AARCH64_R (ADD_ABS_LO12_NC), stub_bfd, stub_sec,
2659 stub_entry->stub_offset + 4, sym_value))
2663 case aarch64_stub_long_branch:
2664 /* We want the value relative to the address 12 bytes back from the
2666 if (aarch64_relocate (AARCH64_R (PRELNN), stub_bfd, stub_sec,
2667 stub_entry->stub_offset + 16, sym_value + 12))
2671 case aarch64_stub_erratum_835769_veneer:
2672 veneered_insn_loc = stub_entry->target_section->output_section->vma
2673 + stub_entry->target_section->output_offset
2674 + stub_entry->target_value;
2675 veneer_entry_loc = stub_entry->stub_sec->output_section->vma
2676 + stub_entry->stub_sec->output_offset
2677 + stub_entry->stub_offset;
2678 branch_offset = veneered_insn_loc - veneer_entry_loc;
2679 branch_offset >>= 2;
2680 branch_offset &= 0x3ffffff;
2681 bfd_putl32 (stub_entry->veneered_insn,
2682 stub_sec->contents + stub_entry->stub_offset);
2683 bfd_putl32 (template[1] | branch_offset,
2684 stub_sec->contents + stub_entry->stub_offset + 4);
2687 case aarch64_stub_erratum_843419_veneer:
2688 if (aarch64_relocate (AARCH64_R (JUMP26), stub_bfd, stub_sec,
2689 stub_entry->stub_offset + 4, sym_value + 4))
2700 /* As above, but don't actually build the stub. Just bump offset so
2701 we know stub section sizes. */
2704 aarch64_size_one_stub (struct bfd_hash_entry *gen_entry,
2705 void *in_arg ATTRIBUTE_UNUSED)
2707 struct elf_aarch64_stub_hash_entry *stub_entry;
2710 /* Massage our args to the form they really have. */
2711 stub_entry = (struct elf_aarch64_stub_hash_entry *) gen_entry;
2713 switch (stub_entry->stub_type)
2715 case aarch64_stub_adrp_branch:
2716 size = sizeof (aarch64_adrp_branch_stub);
2718 case aarch64_stub_long_branch:
2719 size = sizeof (aarch64_long_branch_stub);
2721 case aarch64_stub_erratum_835769_veneer:
2722 size = sizeof (aarch64_erratum_835769_stub);
2724 case aarch64_stub_erratum_843419_veneer:
2725 size = sizeof (aarch64_erratum_843419_stub);
2731 size = (size + 7) & ~7;
2732 stub_entry->stub_sec->size += size;
2736 /* External entry points for sizing and building linker stubs. */
2738 /* Set up various things so that we can make a list of input sections
2739 for each output section included in the link. Returns -1 on error,
2740 0 when no stubs will be needed, and 1 on success. */
2743 elfNN_aarch64_setup_section_lists (bfd *output_bfd,
2744 struct bfd_link_info *info)
2747 unsigned int bfd_count;
2748 int top_id, top_index;
2750 asection **input_list, **list;
2752 struct elf_aarch64_link_hash_table *htab =
2753 elf_aarch64_hash_table (info);
2755 if (!is_elf_hash_table (htab))
2758 /* Count the number of input BFDs and find the top input section id. */
2759 for (input_bfd = info->input_bfds, bfd_count = 0, top_id = 0;
2760 input_bfd != NULL; input_bfd = input_bfd->link.next)
2763 for (section = input_bfd->sections;
2764 section != NULL; section = section->next)
2766 if (top_id < section->id)
2767 top_id = section->id;
2770 htab->bfd_count = bfd_count;
2772 amt = sizeof (struct map_stub) * (top_id + 1);
2773 htab->stub_group = bfd_zmalloc (amt);
2774 if (htab->stub_group == NULL)
2777 /* We can't use output_bfd->section_count here to find the top output
2778 section index as some sections may have been removed, and
2779 _bfd_strip_section_from_output doesn't renumber the indices. */
2780 for (section = output_bfd->sections, top_index = 0;
2781 section != NULL; section = section->next)
2783 if (top_index < section->index)
2784 top_index = section->index;
2787 htab->top_index = top_index;
2788 amt = sizeof (asection *) * (top_index + 1);
2789 input_list = bfd_malloc (amt);
2790 htab->input_list = input_list;
2791 if (input_list == NULL)
2794 /* For sections we aren't interested in, mark their entries with a
2795 value we can check later. */
2796 list = input_list + top_index;
2798 *list = bfd_abs_section_ptr;
2799 while (list-- != input_list);
2801 for (section = output_bfd->sections;
2802 section != NULL; section = section->next)
2804 if ((section->flags & SEC_CODE) != 0)
2805 input_list[section->index] = NULL;
2811 /* Used by elfNN_aarch64_next_input_section and group_sections. */
2812 #define PREV_SEC(sec) (htab->stub_group[(sec)->id].link_sec)
2814 /* The linker repeatedly calls this function for each input section,
2815 in the order that input sections are linked into output sections.
2816 Build lists of input sections to determine groupings between which
2817 we may insert linker stubs. */
2820 elfNN_aarch64_next_input_section (struct bfd_link_info *info, asection *isec)
2822 struct elf_aarch64_link_hash_table *htab =
2823 elf_aarch64_hash_table (info);
2825 if (isec->output_section->index <= htab->top_index)
2827 asection **list = htab->input_list + isec->output_section->index;
2829 if (*list != bfd_abs_section_ptr)
2831 /* Steal the link_sec pointer for our list. */
2832 /* This happens to make the list in reverse order,
2833 which is what we want. */
2834 PREV_SEC (isec) = *list;
2840 /* See whether we can group stub sections together. Grouping stub
2841 sections may result in fewer stubs. More importantly, we need to
2842 put all .init* and .fini* stubs at the beginning of the .init or
2843 .fini output sections respectively, because glibc splits the
2844 _init and _fini functions into multiple parts. Putting a stub in
2845 the middle of a function is not a good idea. */
2848 group_sections (struct elf_aarch64_link_hash_table *htab,
2849 bfd_size_type stub_group_size,
2850 bfd_boolean stubs_always_before_branch)
2852 asection **list = htab->input_list + htab->top_index;
2856 asection *tail = *list;
2858 if (tail == bfd_abs_section_ptr)
2861 while (tail != NULL)
2865 bfd_size_type total;
2869 while ((prev = PREV_SEC (curr)) != NULL
2870 && ((total += curr->output_offset - prev->output_offset)
2874 /* OK, the size from the start of CURR to the end is less
2875 than stub_group_size and thus can be handled by one stub
2876 section. (Or the tail section is itself larger than
2877 stub_group_size, in which case we may be toast.)
2878 We should really be keeping track of the total size of
2879 stubs added here, as stubs contribute to the final output
2883 prev = PREV_SEC (tail);
2884 /* Set up this stub group. */
2885 htab->stub_group[tail->id].link_sec = curr;
2887 while (tail != curr && (tail = prev) != NULL);
2889 /* But wait, there's more! Input sections up to stub_group_size
2890 bytes before the stub section can be handled by it too. */
2891 if (!stubs_always_before_branch)
2895 && ((total += tail->output_offset - prev->output_offset)
2899 prev = PREV_SEC (tail);
2900 htab->stub_group[tail->id].link_sec = curr;
2906 while (list-- != htab->input_list);
2908 free (htab->input_list);
2913 #define AARCH64_BITS(x, pos, n) (((x) >> (pos)) & ((1 << (n)) - 1))
2915 #define AARCH64_RT(insn) AARCH64_BITS (insn, 0, 5)
2916 #define AARCH64_RT2(insn) AARCH64_BITS (insn, 10, 5)
2917 #define AARCH64_RA(insn) AARCH64_BITS (insn, 10, 5)
2918 #define AARCH64_RD(insn) AARCH64_BITS (insn, 0, 5)
2919 #define AARCH64_RN(insn) AARCH64_BITS (insn, 5, 5)
2920 #define AARCH64_RM(insn) AARCH64_BITS (insn, 16, 5)
2922 #define AARCH64_MAC(insn) (((insn) & 0xff000000) == 0x9b000000)
2923 #define AARCH64_BIT(insn, n) AARCH64_BITS (insn, n, 1)
2924 #define AARCH64_OP31(insn) AARCH64_BITS (insn, 21, 3)
2925 #define AARCH64_ZR 0x1f
2927 /* All ld/st ops. See C4-182 of the ARM ARM. The encoding space for
2928 LD_PCREL, LDST_RO, LDST_UI and LDST_UIMM cover prefetch ops. */
2930 #define AARCH64_LD(insn) (AARCH64_BIT (insn, 22) == 1)
2931 #define AARCH64_LDST(insn) (((insn) & 0x0a000000) == 0x08000000)
2932 #define AARCH64_LDST_EX(insn) (((insn) & 0x3f000000) == 0x08000000)
2933 #define AARCH64_LDST_PCREL(insn) (((insn) & 0x3b000000) == 0x18000000)
2934 #define AARCH64_LDST_NAP(insn) (((insn) & 0x3b800000) == 0x28000000)
2935 #define AARCH64_LDSTP_PI(insn) (((insn) & 0x3b800000) == 0x28800000)
2936 #define AARCH64_LDSTP_O(insn) (((insn) & 0x3b800000) == 0x29000000)
2937 #define AARCH64_LDSTP_PRE(insn) (((insn) & 0x3b800000) == 0x29800000)
2938 #define AARCH64_LDST_UI(insn) (((insn) & 0x3b200c00) == 0x38000000)
2939 #define AARCH64_LDST_PIIMM(insn) (((insn) & 0x3b200c00) == 0x38000400)
2940 #define AARCH64_LDST_U(insn) (((insn) & 0x3b200c00) == 0x38000800)
2941 #define AARCH64_LDST_PREIMM(insn) (((insn) & 0x3b200c00) == 0x38000c00)
2942 #define AARCH64_LDST_RO(insn) (((insn) & 0x3b200c00) == 0x38200800)
2943 #define AARCH64_LDST_UIMM(insn) (((insn) & 0x3b000000) == 0x39000000)
2944 #define AARCH64_LDST_SIMD_M(insn) (((insn) & 0xbfbf0000) == 0x0c000000)
2945 #define AARCH64_LDST_SIMD_M_PI(insn) (((insn) & 0xbfa00000) == 0x0c800000)
2946 #define AARCH64_LDST_SIMD_S(insn) (((insn) & 0xbf9f0000) == 0x0d000000)
2947 #define AARCH64_LDST_SIMD_S_PI(insn) (((insn) & 0xbf800000) == 0x0d800000)
2949 /* Classify an INSN if it is indeed a load/store.
2951 Return TRUE if INSN is a LD/ST instruction otherwise return FALSE.
2953 For scalar LD/ST instructions PAIR is FALSE, RT is returned and RT2
2956 For LD/ST pair instructions PAIR is TRUE, RT and RT2 are returned.
2961 aarch64_mem_op_p (uint32_t insn, unsigned int *rt, unsigned int *rt2,
2962 bfd_boolean *pair, bfd_boolean *load)
2970 /* Bail out quickly if INSN doesn't fall into the the load-store
2972 if (!AARCH64_LDST (insn))
2977 if (AARCH64_LDST_EX (insn))
2979 *rt = AARCH64_RT (insn);
2981 if (AARCH64_BIT (insn, 21) == 1)
2984 *rt2 = AARCH64_RT2 (insn);
2986 *load = AARCH64_LD (insn);
2989 else if (AARCH64_LDST_NAP (insn)
2990 || AARCH64_LDSTP_PI (insn)
2991 || AARCH64_LDSTP_O (insn)
2992 || AARCH64_LDSTP_PRE (insn))
2995 *rt = AARCH64_RT (insn);
2996 *rt2 = AARCH64_RT2 (insn);
2997 *load = AARCH64_LD (insn);
3000 else if (AARCH64_LDST_PCREL (insn)
3001 || AARCH64_LDST_UI (insn)
3002 || AARCH64_LDST_PIIMM (insn)
3003 || AARCH64_LDST_U (insn)
3004 || AARCH64_LDST_PREIMM (insn)
3005 || AARCH64_LDST_RO (insn)
3006 || AARCH64_LDST_UIMM (insn))
3008 *rt = AARCH64_RT (insn);
3010 if (AARCH64_LDST_PCREL (insn))
3012 opc = AARCH64_BITS (insn, 22, 2);
3013 v = AARCH64_BIT (insn, 26);
3014 opc_v = opc | (v << 2);
3015 *load = (opc_v == 1 || opc_v == 2 || opc_v == 3
3016 || opc_v == 5 || opc_v == 7);
3019 else if (AARCH64_LDST_SIMD_M (insn)
3020 || AARCH64_LDST_SIMD_M_PI (insn))
3022 *rt = AARCH64_RT (insn);
3023 *load = AARCH64_BIT (insn, 22);
3024 opcode = (insn >> 12) & 0xf;
3051 else if (AARCH64_LDST_SIMD_S (insn)
3052 || AARCH64_LDST_SIMD_S_PI (insn))
3054 *rt = AARCH64_RT (insn);
3055 r = (insn >> 21) & 1;
3056 *load = AARCH64_BIT (insn, 22);
3057 opcode = (insn >> 13) & 0x7;
3069 *rt2 = *rt + (r == 0 ? 2 : 3);
3077 *rt2 = *rt + (r == 0 ? 2 : 3);
3089 /* Return TRUE if INSN is multiply-accumulate. */
3092 aarch64_mlxl_p (uint32_t insn)
3094 uint32_t op31 = AARCH64_OP31 (insn);
3096 if (AARCH64_MAC (insn)
3097 && (op31 == 0 || op31 == 1 || op31 == 5)
3098 /* Exclude MUL instructions which are encoded as a multiple accumulate
3100 && AARCH64_RA (insn) != AARCH64_ZR)
3106 /* Some early revisions of the Cortex-A53 have an erratum (835769) whereby
3107 it is possible for a 64-bit multiply-accumulate instruction to generate an
3108 incorrect result. The details are quite complex and hard to
3109 determine statically, since branches in the code may exist in some
3110 circumstances, but all cases end with a memory (load, store, or
3111 prefetch) instruction followed immediately by the multiply-accumulate
3112 operation. We employ a linker patching technique, by moving the potentially
3113 affected multiply-accumulate instruction into a patch region and replacing
3114 the original instruction with a branch to the patch. This function checks
3115 if INSN_1 is the memory operation followed by a multiply-accumulate
3116 operation (INSN_2). Return TRUE if an erratum sequence is found, FALSE
3117 if INSN_1 and INSN_2 are safe. */
3120 aarch64_erratum_sequence (uint32_t insn_1, uint32_t insn_2)
3130 if (aarch64_mlxl_p (insn_2)
3131 && aarch64_mem_op_p (insn_1, &rt, &rt2, &pair, &load))
3133 /* Any SIMD memory op is independent of the subsequent MLA
3134 by definition of the erratum. */
3135 if (AARCH64_BIT (insn_1, 26))
3138 /* If not SIMD, check for integer memory ops and MLA relationship. */
3139 rn = AARCH64_RN (insn_2);
3140 ra = AARCH64_RA (insn_2);
3141 rm = AARCH64_RM (insn_2);
3143 /* If this is a load and there's a true(RAW) dependency, we are safe
3144 and this is not an erratum sequence. */
3146 (rt == rn || rt == rm || rt == ra
3147 || (pair && (rt2 == rn || rt2 == rm || rt2 == ra))))
3150 /* We conservatively put out stubs for all other cases (including
3158 /* Used to order a list of mapping symbols by address. */
3161 elf_aarch64_compare_mapping (const void *a, const void *b)
3163 const elf_aarch64_section_map *amap = (const elf_aarch64_section_map *) a;
3164 const elf_aarch64_section_map *bmap = (const elf_aarch64_section_map *) b;
3166 if (amap->vma > bmap->vma)
3168 else if (amap->vma < bmap->vma)
3170 else if (amap->type > bmap->type)
3171 /* Ensure results do not depend on the host qsort for objects with
3172 multiple mapping symbols at the same address by sorting on type
3175 else if (amap->type < bmap->type)
3183 _bfd_aarch64_erratum_835769_stub_name (unsigned num_fixes)
3185 char *stub_name = (char *) bfd_malloc
3186 (strlen ("__erratum_835769_veneer_") + 16);
3187 sprintf (stub_name,"__erratum_835769_veneer_%d", num_fixes);
3191 /* Scan for Cortex-A53 erratum 835769 sequence.
3193 Return TRUE else FALSE on abnormal termination. */
3196 _bfd_aarch64_erratum_835769_scan (bfd *input_bfd,
3197 struct bfd_link_info *info,
3198 unsigned int *num_fixes_p)
3201 struct elf_aarch64_link_hash_table *htab = elf_aarch64_hash_table (info);
3202 unsigned int num_fixes = *num_fixes_p;
3207 for (section = input_bfd->sections;
3209 section = section->next)
3211 bfd_byte *contents = NULL;
3212 struct _aarch64_elf_section_data *sec_data;
3215 if (elf_section_type (section) != SHT_PROGBITS
3216 || (elf_section_flags (section) & SHF_EXECINSTR) == 0
3217 || (section->flags & SEC_EXCLUDE) != 0
3218 || (section->sec_info_type == SEC_INFO_TYPE_JUST_SYMS)
3219 || (section->output_section == bfd_abs_section_ptr))
3222 if (elf_section_data (section)->this_hdr.contents != NULL)
3223 contents = elf_section_data (section)->this_hdr.contents;
3224 else if (! bfd_malloc_and_get_section (input_bfd, section, &contents))
3227 sec_data = elf_aarch64_section_data (section);
3229 qsort (sec_data->map, sec_data->mapcount,
3230 sizeof (elf_aarch64_section_map), elf_aarch64_compare_mapping);
3232 for (span = 0; span < sec_data->mapcount; span++)
3234 unsigned int span_start = sec_data->map[span].vma;
3235 unsigned int span_end = ((span == sec_data->mapcount - 1)
3236 ? sec_data->map[0].vma + section->size
3237 : sec_data->map[span + 1].vma);
3239 char span_type = sec_data->map[span].type;
3241 if (span_type == 'd')
3244 for (i = span_start; i + 4 < span_end; i += 4)
3246 uint32_t insn_1 = bfd_getl32 (contents + i);
3247 uint32_t insn_2 = bfd_getl32 (contents + i + 4);
3249 if (aarch64_erratum_sequence (insn_1, insn_2))
3251 struct elf_aarch64_stub_hash_entry *stub_entry;
3252 char *stub_name = _bfd_aarch64_erratum_835769_stub_name (num_fixes);
3256 stub_entry = _bfd_aarch64_add_stub_entry_in_group (stub_name,
3262 stub_entry->stub_type = aarch64_stub_erratum_835769_veneer;
3263 stub_entry->target_section = section;
3264 stub_entry->target_value = i + 4;
3265 stub_entry->veneered_insn = insn_2;
3266 stub_entry->output_name = stub_name;
3271 if (elf_section_data (section)->this_hdr.contents == NULL)
3275 *num_fixes_p = num_fixes;
3281 /* Test if instruction INSN is ADRP. */
3284 _bfd_aarch64_adrp_p (uint32_t insn)
3286 return ((insn & 0x9f000000) == 0x90000000);
3290 /* Helper predicate to look for cortex-a53 erratum 843419 sequence 1. */
3293 _bfd_aarch64_erratum_843419_sequence_p (uint32_t insn_1, uint32_t insn_2,
3301 return (aarch64_mem_op_p (insn_2, &rt, &rt2, &pair, &load)
3304 && AARCH64_LDST_UIMM (insn_3)
3305 && AARCH64_RN (insn_3) == AARCH64_RD (insn_1));
3309 /* Test for the presence of Cortex-A53 erratum 843419 instruction sequence.
3311 Return TRUE if section CONTENTS at offset I contains one of the
3312 erratum 843419 sequences, otherwise return FALSE. If a sequence is
3313 seen set P_VENEER_I to the offset of the final LOAD/STORE
3314 instruction in the sequence.
3318 _bfd_aarch64_erratum_843419_p (bfd_byte *contents, bfd_vma vma,
3319 bfd_vma i, bfd_vma span_end,
3320 bfd_vma *p_veneer_i)
3322 uint32_t insn_1 = bfd_getl32 (contents + i);
3324 if (!_bfd_aarch64_adrp_p (insn_1))
3327 if (span_end < i + 12)
3330 uint32_t insn_2 = bfd_getl32 (contents + i + 4);
3331 uint32_t insn_3 = bfd_getl32 (contents + i + 8);
3333 if ((vma & 0xfff) != 0xff8 && (vma & 0xfff) != 0xffc)
3336 if (_bfd_aarch64_erratum_843419_sequence_p (insn_1, insn_2, insn_3))
3338 *p_veneer_i = i + 8;
3342 if (span_end < i + 16)
3345 uint32_t insn_4 = bfd_getl32 (contents + i + 12);
3347 if (_bfd_aarch64_erratum_843419_sequence_p (insn_1, insn_2, insn_4))
3349 *p_veneer_i = i + 12;
3357 /* Resize all stub sections. */
3360 _bfd_aarch64_resize_stubs (struct elf_aarch64_link_hash_table *htab)
3364 /* OK, we've added some stubs. Find out the new size of the
3366 for (section = htab->stub_bfd->sections;
3367 section != NULL; section = section->next)
3369 /* Ignore non-stub sections. */
3370 if (!strstr (section->name, STUB_SUFFIX))
3375 bfd_hash_traverse (&htab->stub_hash_table, aarch64_size_one_stub, htab);
3377 for (section = htab->stub_bfd->sections;
3378 section != NULL; section = section->next)
3380 if (!strstr (section->name, STUB_SUFFIX))
3386 /* Ensure all stub sections have a size which is a multiple of
3387 4096. This is important in order to ensure that the insertion
3388 of stub sections does not in itself move existing code around
3389 in such a way that new errata sequences are created. */
3390 if (htab->fix_erratum_843419)
3392 section->size = BFD_ALIGN (section->size, 0x1000);
3397 /* Construct an erratum 843419 workaround stub name.
3401 _bfd_aarch64_erratum_843419_stub_name (asection *input_section,
3404 const bfd_size_type len = 8 + 4 + 1 + 8 + 1 + 16 + 1;
3405 char *stub_name = bfd_malloc (len);
3407 if (stub_name != NULL)
3408 snprintf (stub_name, len, "e843419@%04x_%08x_%" BFD_VMA_FMT "x",
3409 input_section->owner->id,
3415 /* Build a stub_entry structure describing an 843419 fixup.
3417 The stub_entry constructed is populated with the bit pattern INSN
3418 of the instruction located at OFFSET within input SECTION.
3420 Returns TRUE on success. */
3423 _bfd_aarch64_erratum_843419_fixup (uint32_t insn,
3424 bfd_vma adrp_offset,
3425 bfd_vma ldst_offset,
3427 struct bfd_link_info *info)
3429 struct elf_aarch64_link_hash_table *htab = elf_aarch64_hash_table (info);
3431 struct elf_aarch64_stub_hash_entry *stub_entry;
3433 stub_name = _bfd_aarch64_erratum_843419_stub_name (section, ldst_offset);
3434 stub_entry = aarch64_stub_hash_lookup (&htab->stub_hash_table, stub_name,
3442 /* We always place an 843419 workaround veneer in the stub section
3443 attached to the input section in which an erratum sequence has
3444 been found. This ensures that later in the link process (in
3445 elfNN_aarch64_write_section) when we copy the veneered
3446 instruction from the input section into the stub section the
3447 copied instruction will have had any relocations applied to it.
3448 If we placed workaround veneers in any other stub section then we
3449 could not assume that all relocations have been processed on the
3450 corresponding input section at the point we output the stub
3454 stub_entry = _bfd_aarch64_add_stub_entry_after (stub_name, section, htab);
3455 if (stub_entry == NULL)
3461 stub_entry->adrp_offset = adrp_offset;
3462 stub_entry->target_value = ldst_offset;
3463 stub_entry->target_section = section;
3464 stub_entry->stub_type = aarch64_stub_erratum_843419_veneer;
3465 stub_entry->veneered_insn = insn;
3466 stub_entry->output_name = stub_name;
3472 /* Scan an input section looking for the signature of erratum 843419.
3474 Scans input SECTION in INPUT_BFD looking for erratum 843419
3475 signatures, for each signature found a stub_entry is created
3476 describing the location of the erratum for subsequent fixup.
3478 Return TRUE on successful scan, FALSE on failure to scan.
3482 _bfd_aarch64_erratum_843419_scan (bfd *input_bfd, asection *section,
3483 struct bfd_link_info *info)
3485 struct elf_aarch64_link_hash_table *htab = elf_aarch64_hash_table (info);
3490 if (elf_section_type (section) != SHT_PROGBITS
3491 || (elf_section_flags (section) & SHF_EXECINSTR) == 0
3492 || (section->flags & SEC_EXCLUDE) != 0
3493 || (section->sec_info_type == SEC_INFO_TYPE_JUST_SYMS)
3494 || (section->output_section == bfd_abs_section_ptr))
3499 bfd_byte *contents = NULL;
3500 struct _aarch64_elf_section_data *sec_data;
3503 if (elf_section_data (section)->this_hdr.contents != NULL)
3504 contents = elf_section_data (section)->this_hdr.contents;
3505 else if (! bfd_malloc_and_get_section (input_bfd, section, &contents))
3508 sec_data = elf_aarch64_section_data (section);
3510 qsort (sec_data->map, sec_data->mapcount,
3511 sizeof (elf_aarch64_section_map), elf_aarch64_compare_mapping);
3513 for (span = 0; span < sec_data->mapcount; span++)
3515 unsigned int span_start = sec_data->map[span].vma;
3516 unsigned int span_end = ((span == sec_data->mapcount - 1)
3517 ? sec_data->map[0].vma + section->size
3518 : sec_data->map[span + 1].vma);
3520 char span_type = sec_data->map[span].type;
3522 if (span_type == 'd')
3525 for (i = span_start; i + 8 < span_end; i += 4)
3527 bfd_vma vma = (section->output_section->vma
3528 + section->output_offset
3532 if (_bfd_aarch64_erratum_843419_p
3533 (contents, vma, i, span_end, &veneer_i))
3535 uint32_t insn = bfd_getl32 (contents + veneer_i);
3537 if (!_bfd_aarch64_erratum_843419_fixup (insn, i, veneer_i,
3544 if (elf_section_data (section)->this_hdr.contents == NULL)
3553 /* Determine and set the size of the stub section for a final link.
3555 The basic idea here is to examine all the relocations looking for
3556 PC-relative calls to a target that is unreachable with a "bl"
3560 elfNN_aarch64_size_stubs (bfd *output_bfd,
3562 struct bfd_link_info *info,
3563 bfd_signed_vma group_size,
3564 asection * (*add_stub_section) (const char *,
3566 void (*layout_sections_again) (void))
3568 bfd_size_type stub_group_size;
3569 bfd_boolean stubs_always_before_branch;
3570 bfd_boolean stub_changed = FALSE;
3571 struct elf_aarch64_link_hash_table *htab = elf_aarch64_hash_table (info);
3572 unsigned int num_erratum_835769_fixes = 0;
3574 /* Propagate mach to stub bfd, because it may not have been
3575 finalized when we created stub_bfd. */
3576 bfd_set_arch_mach (stub_bfd, bfd_get_arch (output_bfd),
3577 bfd_get_mach (output_bfd));
3579 /* Stash our params away. */
3580 htab->stub_bfd = stub_bfd;
3581 htab->add_stub_section = add_stub_section;
3582 htab->layout_sections_again = layout_sections_again;
3583 stubs_always_before_branch = group_size < 0;
3585 stub_group_size = -group_size;
3587 stub_group_size = group_size;
3589 if (stub_group_size == 1)
3591 /* Default values. */
3592 /* AArch64 branch range is +-128MB. The value used is 1MB less. */
3593 stub_group_size = 127 * 1024 * 1024;
3596 group_sections (htab, stub_group_size, stubs_always_before_branch);
3598 (*htab->layout_sections_again) ();
3600 if (htab->fix_erratum_835769)
3604 for (input_bfd = info->input_bfds;
3605 input_bfd != NULL; input_bfd = input_bfd->link.next)
3606 if (!_bfd_aarch64_erratum_835769_scan (input_bfd, info,
3607 &num_erratum_835769_fixes))
3610 _bfd_aarch64_resize_stubs (htab);
3611 (*htab->layout_sections_again) ();
3614 if (htab->fix_erratum_843419)
3618 for (input_bfd = info->input_bfds;
3620 input_bfd = input_bfd->link.next)
3624 for (section = input_bfd->sections;
3626 section = section->next)
3627 if (!_bfd_aarch64_erratum_843419_scan (input_bfd, section, info))
3631 _bfd_aarch64_resize_stubs (htab);
3632 (*htab->layout_sections_again) ();
3639 for (input_bfd = info->input_bfds;
3640 input_bfd != NULL; input_bfd = input_bfd->link.next)
3642 Elf_Internal_Shdr *symtab_hdr;
3644 Elf_Internal_Sym *local_syms = NULL;
3646 /* We'll need the symbol table in a second. */
3647 symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
3648 if (symtab_hdr->sh_info == 0)
3651 /* Walk over each section attached to the input bfd. */
3652 for (section = input_bfd->sections;
3653 section != NULL; section = section->next)
3655 Elf_Internal_Rela *internal_relocs, *irelaend, *irela;
3657 /* If there aren't any relocs, then there's nothing more
3659 if ((section->flags & SEC_RELOC) == 0
3660 || section->reloc_count == 0
3661 || (section->flags & SEC_CODE) == 0)
3664 /* If this section is a link-once section that will be
3665 discarded, then don't create any stubs. */
3666 if (section->output_section == NULL
3667 || section->output_section->owner != output_bfd)
3670 /* Get the relocs. */
3672 = _bfd_elf_link_read_relocs (input_bfd, section, NULL,
3673 NULL, info->keep_memory);
3674 if (internal_relocs == NULL)
3675 goto error_ret_free_local;
3677 /* Now examine each relocation. */
3678 irela = internal_relocs;
3679 irelaend = irela + section->reloc_count;
3680 for (; irela < irelaend; irela++)
3682 unsigned int r_type, r_indx;
3683 enum elf_aarch64_stub_type stub_type;
3684 struct elf_aarch64_stub_hash_entry *stub_entry;
3687 bfd_vma destination;
3688 struct elf_aarch64_link_hash_entry *hash;
3689 const char *sym_name;
3691 const asection *id_sec;
3692 unsigned char st_type;
3695 r_type = ELFNN_R_TYPE (irela->r_info);
3696 r_indx = ELFNN_R_SYM (irela->r_info);
3698 if (r_type >= (unsigned int) R_AARCH64_end)
3700 bfd_set_error (bfd_error_bad_value);
3701 error_ret_free_internal:
3702 if (elf_section_data (section)->relocs == NULL)
3703 free (internal_relocs);
3704 goto error_ret_free_local;
3707 /* Only look for stubs on unconditional branch and
3708 branch and link instructions. */
3709 if (r_type != (unsigned int) AARCH64_R (CALL26)
3710 && r_type != (unsigned int) AARCH64_R (JUMP26))
3713 /* Now determine the call target, its name, value,
3720 if (r_indx < symtab_hdr->sh_info)
3722 /* It's a local symbol. */
3723 Elf_Internal_Sym *sym;
3724 Elf_Internal_Shdr *hdr;
3726 if (local_syms == NULL)
3729 = (Elf_Internal_Sym *) symtab_hdr->contents;
3730 if (local_syms == NULL)
3732 = bfd_elf_get_elf_syms (input_bfd, symtab_hdr,
3733 symtab_hdr->sh_info, 0,
3735 if (local_syms == NULL)
3736 goto error_ret_free_internal;
3739 sym = local_syms + r_indx;
3740 hdr = elf_elfsections (input_bfd)[sym->st_shndx];
3741 sym_sec = hdr->bfd_section;
3743 /* This is an undefined symbol. It can never
3747 if (ELF_ST_TYPE (sym->st_info) != STT_SECTION)
3748 sym_value = sym->st_value;
3749 destination = (sym_value + irela->r_addend
3750 + sym_sec->output_offset
3751 + sym_sec->output_section->vma);
3752 st_type = ELF_ST_TYPE (sym->st_info);
3754 = bfd_elf_string_from_elf_section (input_bfd,
3755 symtab_hdr->sh_link,
3762 e_indx = r_indx - symtab_hdr->sh_info;
3763 hash = ((struct elf_aarch64_link_hash_entry *)
3764 elf_sym_hashes (input_bfd)[e_indx]);
3766 while (hash->root.root.type == bfd_link_hash_indirect
3767 || hash->root.root.type == bfd_link_hash_warning)
3768 hash = ((struct elf_aarch64_link_hash_entry *)
3769 hash->root.root.u.i.link);
3771 if (hash->root.root.type == bfd_link_hash_defined
3772 || hash->root.root.type == bfd_link_hash_defweak)
3774 struct elf_aarch64_link_hash_table *globals =
3775 elf_aarch64_hash_table (info);
3776 sym_sec = hash->root.root.u.def.section;
3777 sym_value = hash->root.root.u.def.value;
3778 /* For a destination in a shared library,
3779 use the PLT stub as target address to
3780 decide whether a branch stub is
3782 if (globals->root.splt != NULL && hash != NULL
3783 && hash->root.plt.offset != (bfd_vma) - 1)
3785 sym_sec = globals->root.splt;
3786 sym_value = hash->root.plt.offset;
3787 if (sym_sec->output_section != NULL)
3788 destination = (sym_value
3789 + sym_sec->output_offset
3791 sym_sec->output_section->vma);
3793 else if (sym_sec->output_section != NULL)
3794 destination = (sym_value + irela->r_addend
3795 + sym_sec->output_offset
3796 + sym_sec->output_section->vma);
3798 else if (hash->root.root.type == bfd_link_hash_undefined
3799 || (hash->root.root.type
3800 == bfd_link_hash_undefweak))
3802 /* For a shared library, use the PLT stub as
3803 target address to decide whether a long
3804 branch stub is needed.
3805 For absolute code, they cannot be handled. */
3806 struct elf_aarch64_link_hash_table *globals =
3807 elf_aarch64_hash_table (info);
3809 if (globals->root.splt != NULL && hash != NULL
3810 && hash->root.plt.offset != (bfd_vma) - 1)
3812 sym_sec = globals->root.splt;
3813 sym_value = hash->root.plt.offset;
3814 if (sym_sec->output_section != NULL)
3815 destination = (sym_value
3816 + sym_sec->output_offset
3818 sym_sec->output_section->vma);
3825 bfd_set_error (bfd_error_bad_value);
3826 goto error_ret_free_internal;
3828 st_type = ELF_ST_TYPE (hash->root.type);
3829 sym_name = hash->root.root.root.string;
3832 /* Determine what (if any) linker stub is needed. */
3833 stub_type = aarch64_type_of_stub
3834 (info, section, irela, sym_sec, st_type, hash, destination);
3835 if (stub_type == aarch64_stub_none)
3838 /* Support for grouping stub sections. */
3839 id_sec = htab->stub_group[section->id].link_sec;
3841 /* Get the name of this stub. */
3842 stub_name = elfNN_aarch64_stub_name (id_sec, sym_sec, hash,
3845 goto error_ret_free_internal;
3848 aarch64_stub_hash_lookup (&htab->stub_hash_table,
3849 stub_name, FALSE, FALSE);
3850 if (stub_entry != NULL)
3852 /* The proper stub has already been created. */
3857 stub_entry = _bfd_aarch64_add_stub_entry_in_group
3858 (stub_name, section, htab);
3859 if (stub_entry == NULL)
3862 goto error_ret_free_internal;
3865 stub_entry->target_value = sym_value;
3866 stub_entry->target_section = sym_sec;
3867 stub_entry->stub_type = stub_type;
3868 stub_entry->h = hash;
3869 stub_entry->st_type = st_type;
3871 if (sym_name == NULL)
3872 sym_name = "unnamed";
3873 len = sizeof (STUB_ENTRY_NAME) + strlen (sym_name);
3874 stub_entry->output_name = bfd_alloc (htab->stub_bfd, len);
3875 if (stub_entry->output_name == NULL)
3878 goto error_ret_free_internal;
3881 snprintf (stub_entry->output_name, len, STUB_ENTRY_NAME,
3884 stub_changed = TRUE;
3887 /* We're done with the internal relocs, free them. */
3888 if (elf_section_data (section)->relocs == NULL)
3889 free (internal_relocs);
3896 _bfd_aarch64_resize_stubs (htab);
3898 /* Ask the linker to do its stuff. */
3899 (*htab->layout_sections_again) ();
3900 stub_changed = FALSE;
3905 error_ret_free_local:
3909 /* Build all the stubs associated with the current output file. The
3910 stubs are kept in a hash table attached to the main linker hash
3911 table. We also set up the .plt entries for statically linked PIC
3912 functions here. This function is called via aarch64_elf_finish in the
3916 elfNN_aarch64_build_stubs (struct bfd_link_info *info)
3919 struct bfd_hash_table *table;
3920 struct elf_aarch64_link_hash_table *htab;
3922 htab = elf_aarch64_hash_table (info);
3924 for (stub_sec = htab->stub_bfd->sections;
3925 stub_sec != NULL; stub_sec = stub_sec->next)
3929 /* Ignore non-stub sections. */
3930 if (!strstr (stub_sec->name, STUB_SUFFIX))
3933 /* Allocate memory to hold the linker stubs. */
3934 size = stub_sec->size;
3935 stub_sec->contents = bfd_zalloc (htab->stub_bfd, size);
3936 if (stub_sec->contents == NULL && size != 0)
3940 bfd_putl32 (0x14000000 | (size >> 2), stub_sec->contents);
3941 stub_sec->size += 4;
3944 /* Build the stubs as directed by the stub hash table. */
3945 table = &htab->stub_hash_table;
3946 bfd_hash_traverse (table, aarch64_build_one_stub, info);
3952 /* Add an entry to the code/data map for section SEC. */
3955 elfNN_aarch64_section_map_add (asection *sec, char type, bfd_vma vma)
3957 struct _aarch64_elf_section_data *sec_data =
3958 elf_aarch64_section_data (sec);
3959 unsigned int newidx;
3961 if (sec_data->map == NULL)
3963 sec_data->map = bfd_malloc (sizeof (elf_aarch64_section_map));
3964 sec_data->mapcount = 0;
3965 sec_data->mapsize = 1;
3968 newidx = sec_data->mapcount++;
3970 if (sec_data->mapcount > sec_data->mapsize)
3972 sec_data->mapsize *= 2;
3973 sec_data->map = bfd_realloc_or_free
3974 (sec_data->map, sec_data->mapsize * sizeof (elf_aarch64_section_map));
3979 sec_data->map[newidx].vma = vma;
3980 sec_data->map[newidx].type = type;
3985 /* Initialise maps of insn/data for input BFDs. */
3987 bfd_elfNN_aarch64_init_maps (bfd *abfd)
3989 Elf_Internal_Sym *isymbuf;
3990 Elf_Internal_Shdr *hdr;
3991 unsigned int i, localsyms;
3993 /* Make sure that we are dealing with an AArch64 elf binary. */
3994 if (!is_aarch64_elf (abfd))
3997 if ((abfd->flags & DYNAMIC) != 0)
4000 hdr = &elf_symtab_hdr (abfd);
4001 localsyms = hdr->sh_info;
4003 /* Obtain a buffer full of symbols for this BFD. The hdr->sh_info field
4004 should contain the number of local symbols, which should come before any
4005 global symbols. Mapping symbols are always local. */
4006 isymbuf = bfd_elf_get_elf_syms (abfd, hdr, localsyms, 0, NULL, NULL, NULL);
4008 /* No internal symbols read? Skip this BFD. */
4009 if (isymbuf == NULL)
4012 for (i = 0; i < localsyms; i++)
4014 Elf_Internal_Sym *isym = &isymbuf[i];
4015 asection *sec = bfd_section_from_elf_index (abfd, isym->st_shndx);
4018 if (sec != NULL && ELF_ST_BIND (isym->st_info) == STB_LOCAL)
4020 name = bfd_elf_string_from_elf_section (abfd,
4024 if (bfd_is_aarch64_special_symbol_name
4025 (name, BFD_AARCH64_SPECIAL_SYM_TYPE_MAP))
4026 elfNN_aarch64_section_map_add (sec, name[1], isym->st_value);
4031 /* Set option values needed during linking. */
4033 bfd_elfNN_aarch64_set_options (struct bfd *output_bfd,
4034 struct bfd_link_info *link_info,
4036 int no_wchar_warn, int pic_veneer,
4037 int fix_erratum_835769,
4038 int fix_erratum_843419)
4040 struct elf_aarch64_link_hash_table *globals;
4042 globals = elf_aarch64_hash_table (link_info);
4043 globals->pic_veneer = pic_veneer;
4044 globals->fix_erratum_835769 = fix_erratum_835769;
4045 globals->fix_erratum_843419 = fix_erratum_843419;
4046 globals->fix_erratum_843419_adr = TRUE;
4048 BFD_ASSERT (is_aarch64_elf (output_bfd));
4049 elf_aarch64_tdata (output_bfd)->no_enum_size_warning = no_enum_warn;
4050 elf_aarch64_tdata (output_bfd)->no_wchar_size_warning = no_wchar_warn;
4054 aarch64_calculate_got_entry_vma (struct elf_link_hash_entry *h,
4055 struct elf_aarch64_link_hash_table
4056 *globals, struct bfd_link_info *info,
4057 bfd_vma value, bfd *output_bfd,
4058 bfd_boolean *unresolved_reloc_p)
4060 bfd_vma off = (bfd_vma) - 1;
4061 asection *basegot = globals->root.sgot;
4062 bfd_boolean dyn = globals->root.dynamic_sections_created;
4066 BFD_ASSERT (basegot != NULL);
4067 off = h->got.offset;
4068 BFD_ASSERT (off != (bfd_vma) - 1);
4069 if (!WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, bfd_link_pic (info), h)
4070 || (bfd_link_pic (info)
4071 && SYMBOL_REFERENCES_LOCAL (info, h))
4072 || (ELF_ST_VISIBILITY (h->other)
4073 && h->root.type == bfd_link_hash_undefweak))
4075 /* This is actually a static link, or it is a -Bsymbolic link
4076 and the symbol is defined locally. We must initialize this
4077 entry in the global offset table. Since the offset must
4078 always be a multiple of 8 (4 in the case of ILP32), we use
4079 the least significant bit to record whether we have
4080 initialized it already.
4081 When doing a dynamic link, we create a .rel(a).got relocation
4082 entry to initialize the value. This is done in the
4083 finish_dynamic_symbol routine. */
4088 bfd_put_NN (output_bfd, value, basegot->contents + off);
4093 *unresolved_reloc_p = FALSE;
4095 off = off + basegot->output_section->vma + basegot->output_offset;
4101 /* Change R_TYPE to a more efficient access model where possible,
4102 return the new reloc type. */
4104 static bfd_reloc_code_real_type
4105 aarch64_tls_transition_without_check (bfd_reloc_code_real_type r_type,
4106 struct elf_link_hash_entry *h)
4108 bfd_boolean is_local = h == NULL;
4112 case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21:
4113 case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21:
4115 ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1
4116 : BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21);
4118 case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21:
4120 ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC
4123 case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19:
4125 ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1
4126 : BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19);
4128 case BFD_RELOC_AARCH64_TLSDESC_LDNN_LO12_NC:
4129 case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC:
4131 ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC
4132 : BFD_RELOC_AARCH64_TLSIE_LDNN_GOTTPREL_LO12_NC);
4134 case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21:
4135 return is_local ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1 : r_type;
4137 case BFD_RELOC_AARCH64_TLSIE_LDNN_GOTTPREL_LO12_NC:
4138 return is_local ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC : r_type;
4140 case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19:
4143 case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21:
4145 ? BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_HI12
4146 : BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19);
4148 case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12_NC:
4149 case BFD_RELOC_AARCH64_TLSDESC_CALL:
4150 /* Instructions with these relocations will become NOPs. */
4151 return BFD_RELOC_AARCH64_NONE;
4161 aarch64_reloc_got_type (bfd_reloc_code_real_type r_type)
4165 case BFD_RELOC_AARCH64_ADR_GOT_PAGE:
4166 case BFD_RELOC_AARCH64_GOT_LD_PREL19:
4167 case BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14:
4168 case BFD_RELOC_AARCH64_LD32_GOT_LO12_NC:
4169 case BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15:
4170 case BFD_RELOC_AARCH64_LD64_GOT_LO12_NC:
4173 case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC:
4174 case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21:
4175 case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21:
4176 case BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC:
4177 case BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21:
4178 case BFD_RELOC_AARCH64_TLSLD_ADR_PREL21:
4181 case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12_NC:
4182 case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21:
4183 case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21:
4184 case BFD_RELOC_AARCH64_TLSDESC_CALL:
4185 case BFD_RELOC_AARCH64_TLSDESC_LD32_LO12_NC:
4186 case BFD_RELOC_AARCH64_TLSDESC_LD64_LO12_NC:
4187 case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19:
4188 return GOT_TLSDESC_GD;
4190 case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21:
4191 case BFD_RELOC_AARCH64_TLSIE_LD32_GOTTPREL_LO12_NC:
4192 case BFD_RELOC_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC:
4193 case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19:
4203 aarch64_can_relax_tls (bfd *input_bfd,
4204 struct bfd_link_info *info,
4205 bfd_reloc_code_real_type r_type,
4206 struct elf_link_hash_entry *h,
4207 unsigned long r_symndx)
4209 unsigned int symbol_got_type;
4210 unsigned int reloc_got_type;
4212 if (! IS_AARCH64_TLS_RELAX_RELOC (r_type))
4215 symbol_got_type = elfNN_aarch64_symbol_got_type (h, input_bfd, r_symndx);
4216 reloc_got_type = aarch64_reloc_got_type (r_type);
4218 if (symbol_got_type == GOT_TLS_IE && GOT_TLS_GD_ANY_P (reloc_got_type))
4221 if (bfd_link_pic (info))
4224 if (h && h->root.type == bfd_link_hash_undefweak)
4230 /* Given the relocation code R_TYPE, return the relaxed bfd reloc
4233 static bfd_reloc_code_real_type
4234 aarch64_tls_transition (bfd *input_bfd,
4235 struct bfd_link_info *info,
4236 unsigned int r_type,
4237 struct elf_link_hash_entry *h,
4238 unsigned long r_symndx)
4240 bfd_reloc_code_real_type bfd_r_type
4241 = elfNN_aarch64_bfd_reloc_from_type (r_type);
4243 if (! aarch64_can_relax_tls (input_bfd, info, bfd_r_type, h, r_symndx))
4246 return aarch64_tls_transition_without_check (bfd_r_type, h);
4249 /* Return the base VMA address which should be subtracted from real addresses
4250 when resolving R_AARCH64_TLS_DTPREL relocation. */
4253 dtpoff_base (struct bfd_link_info *info)
4255 /* If tls_sec is NULL, we should have signalled an error already. */
4256 BFD_ASSERT (elf_hash_table (info)->tls_sec != NULL);
4257 return elf_hash_table (info)->tls_sec->vma;
4260 /* Return the base VMA address which should be subtracted from real addresses
4261 when resolving R_AARCH64_TLS_GOTTPREL64 relocations. */
4264 tpoff_base (struct bfd_link_info *info)
4266 struct elf_link_hash_table *htab = elf_hash_table (info);
4268 /* If tls_sec is NULL, we should have signalled an error already. */
4269 BFD_ASSERT (htab->tls_sec != NULL);
4271 bfd_vma base = align_power ((bfd_vma) TCB_SIZE,
4272 htab->tls_sec->alignment_power);
4273 return htab->tls_sec->vma - base;
4277 symbol_got_offset_ref (bfd *input_bfd, struct elf_link_hash_entry *h,
4278 unsigned long r_symndx)
4280 /* Calculate the address of the GOT entry for symbol
4281 referred to in h. */
4283 return &h->got.offset;
4287 struct elf_aarch64_local_symbol *l;
4289 l = elf_aarch64_locals (input_bfd);
4290 return &l[r_symndx].got_offset;
4295 symbol_got_offset_mark (bfd *input_bfd, struct elf_link_hash_entry *h,
4296 unsigned long r_symndx)
4299 p = symbol_got_offset_ref (input_bfd, h, r_symndx);
4304 symbol_got_offset_mark_p (bfd *input_bfd, struct elf_link_hash_entry *h,
4305 unsigned long r_symndx)
4308 value = * symbol_got_offset_ref (input_bfd, h, r_symndx);
4313 symbol_got_offset (bfd *input_bfd, struct elf_link_hash_entry *h,
4314 unsigned long r_symndx)
4317 value = * symbol_got_offset_ref (input_bfd, h, r_symndx);
4323 symbol_tlsdesc_got_offset_ref (bfd *input_bfd, struct elf_link_hash_entry *h,
4324 unsigned long r_symndx)
4326 /* Calculate the address of the GOT entry for symbol
4327 referred to in h. */
4330 struct elf_aarch64_link_hash_entry *eh;
4331 eh = (struct elf_aarch64_link_hash_entry *) h;
4332 return &eh->tlsdesc_got_jump_table_offset;
4337 struct elf_aarch64_local_symbol *l;
4339 l = elf_aarch64_locals (input_bfd);
4340 return &l[r_symndx].tlsdesc_got_jump_table_offset;
4345 symbol_tlsdesc_got_offset_mark (bfd *input_bfd, struct elf_link_hash_entry *h,
4346 unsigned long r_symndx)
4349 p = symbol_tlsdesc_got_offset_ref (input_bfd, h, r_symndx);
4354 symbol_tlsdesc_got_offset_mark_p (bfd *input_bfd,
4355 struct elf_link_hash_entry *h,
4356 unsigned long r_symndx)
4359 value = * symbol_tlsdesc_got_offset_ref (input_bfd, h, r_symndx);
4364 symbol_tlsdesc_got_offset (bfd *input_bfd, struct elf_link_hash_entry *h,
4365 unsigned long r_symndx)
4368 value = * symbol_tlsdesc_got_offset_ref (input_bfd, h, r_symndx);
4373 /* Data for make_branch_to_erratum_835769_stub(). */
4375 struct erratum_835769_branch_to_stub_data
4377 struct bfd_link_info *info;
4378 asection *output_section;
4382 /* Helper to insert branches to erratum 835769 stubs in the right
4383 places for a particular section. */
4386 make_branch_to_erratum_835769_stub (struct bfd_hash_entry *gen_entry,
4389 struct elf_aarch64_stub_hash_entry *stub_entry;
4390 struct erratum_835769_branch_to_stub_data *data;
4392 unsigned long branch_insn = 0;
4393 bfd_vma veneered_insn_loc, veneer_entry_loc;
4394 bfd_signed_vma branch_offset;
4395 unsigned int target;
4398 stub_entry = (struct elf_aarch64_stub_hash_entry *) gen_entry;
4399 data = (struct erratum_835769_branch_to_stub_data *) in_arg;
4401 if (stub_entry->target_section != data->output_section
4402 || stub_entry->stub_type != aarch64_stub_erratum_835769_veneer)
4405 contents = data->contents;
4406 veneered_insn_loc = stub_entry->target_section->output_section->vma
4407 + stub_entry->target_section->output_offset
4408 + stub_entry->target_value;
4409 veneer_entry_loc = stub_entry->stub_sec->output_section->vma
4410 + stub_entry->stub_sec->output_offset
4411 + stub_entry->stub_offset;
4412 branch_offset = veneer_entry_loc - veneered_insn_loc;
4414 abfd = stub_entry->target_section->owner;
4415 if (!aarch64_valid_branch_p (veneer_entry_loc, veneered_insn_loc))
4416 (*_bfd_error_handler)
4417 (_("%B: error: Erratum 835769 stub out "
4418 "of range (input file too large)"), abfd);
4420 target = stub_entry->target_value;
4421 branch_insn = 0x14000000;
4422 branch_offset >>= 2;
4423 branch_offset &= 0x3ffffff;
4424 branch_insn |= branch_offset;
4425 bfd_putl32 (branch_insn, &contents[target]);
4432 _bfd_aarch64_erratum_843419_branch_to_stub (struct bfd_hash_entry *gen_entry,
4435 struct elf_aarch64_stub_hash_entry *stub_entry
4436 = (struct elf_aarch64_stub_hash_entry *) gen_entry;
4437 struct erratum_835769_branch_to_stub_data *data
4438 = (struct erratum_835769_branch_to_stub_data *) in_arg;
4439 struct bfd_link_info *info;
4440 struct elf_aarch64_link_hash_table *htab;
4448 contents = data->contents;
4449 section = data->output_section;
4451 htab = elf_aarch64_hash_table (info);
4453 if (stub_entry->target_section != section
4454 || stub_entry->stub_type != aarch64_stub_erratum_843419_veneer)
4457 insn = bfd_getl32 (contents + stub_entry->target_value);
4459 stub_entry->stub_sec->contents + stub_entry->stub_offset);
4461 place = (section->output_section->vma + section->output_offset
4462 + stub_entry->adrp_offset);
4463 insn = bfd_getl32 (contents + stub_entry->adrp_offset);
4465 if ((insn & AARCH64_ADRP_OP_MASK) != AARCH64_ADRP_OP)
4468 bfd_signed_vma imm =
4469 (_bfd_aarch64_sign_extend
4470 ((bfd_vma) _bfd_aarch64_decode_adrp_imm (insn) << 12, 33)
4473 if (htab->fix_erratum_843419_adr
4474 && (imm >= AARCH64_MIN_ADRP_IMM && imm <= AARCH64_MAX_ADRP_IMM))
4476 insn = (_bfd_aarch64_reencode_adr_imm (AARCH64_ADR_OP, imm)
4477 | AARCH64_RT (insn));
4478 bfd_putl32 (insn, contents + stub_entry->adrp_offset);
4482 bfd_vma veneered_insn_loc;
4483 bfd_vma veneer_entry_loc;
4484 bfd_signed_vma branch_offset;
4485 uint32_t branch_insn;
4487 veneered_insn_loc = stub_entry->target_section->output_section->vma
4488 + stub_entry->target_section->output_offset
4489 + stub_entry->target_value;
4490 veneer_entry_loc = stub_entry->stub_sec->output_section->vma
4491 + stub_entry->stub_sec->output_offset
4492 + stub_entry->stub_offset;
4493 branch_offset = veneer_entry_loc - veneered_insn_loc;
4495 abfd = stub_entry->target_section->owner;
4496 if (!aarch64_valid_branch_p (veneer_entry_loc, veneered_insn_loc))
4497 (*_bfd_error_handler)
4498 (_("%B: error: Erratum 843419 stub out "
4499 "of range (input file too large)"), abfd);
4501 branch_insn = 0x14000000;
4502 branch_offset >>= 2;
4503 branch_offset &= 0x3ffffff;
4504 branch_insn |= branch_offset;
4505 bfd_putl32 (branch_insn, contents + stub_entry->target_value);
4512 elfNN_aarch64_write_section (bfd *output_bfd ATTRIBUTE_UNUSED,
4513 struct bfd_link_info *link_info,
4518 struct elf_aarch64_link_hash_table *globals =
4519 elf_aarch64_hash_table (link_info);
4521 if (globals == NULL)
4524 /* Fix code to point to erratum 835769 stubs. */
4525 if (globals->fix_erratum_835769)
4527 struct erratum_835769_branch_to_stub_data data;
4529 data.info = link_info;
4530 data.output_section = sec;
4531 data.contents = contents;
4532 bfd_hash_traverse (&globals->stub_hash_table,
4533 make_branch_to_erratum_835769_stub, &data);
4536 if (globals->fix_erratum_843419)
4538 struct erratum_835769_branch_to_stub_data data;
4540 data.info = link_info;
4541 data.output_section = sec;
4542 data.contents = contents;
4543 bfd_hash_traverse (&globals->stub_hash_table,
4544 _bfd_aarch64_erratum_843419_branch_to_stub, &data);
4550 /* Perform a relocation as part of a final link. */
4551 static bfd_reloc_status_type
4552 elfNN_aarch64_final_link_relocate (reloc_howto_type *howto,
4555 asection *input_section,
4557 Elf_Internal_Rela *rel,
4559 struct bfd_link_info *info,
4561 struct elf_link_hash_entry *h,
4562 bfd_boolean *unresolved_reloc_p,
4563 bfd_boolean save_addend,
4564 bfd_vma *saved_addend,
4565 Elf_Internal_Sym *sym)
4567 Elf_Internal_Shdr *symtab_hdr;
4568 unsigned int r_type = howto->type;
4569 bfd_reloc_code_real_type bfd_r_type
4570 = elfNN_aarch64_bfd_reloc_from_howto (howto);
4571 bfd_reloc_code_real_type new_bfd_r_type;
4572 unsigned long r_symndx;
4573 bfd_byte *hit_data = contents + rel->r_offset;
4575 bfd_signed_vma signed_addend;
4576 struct elf_aarch64_link_hash_table *globals;
4577 bfd_boolean weak_undef_p;
4580 globals = elf_aarch64_hash_table (info);
4582 symtab_hdr = &elf_symtab_hdr (input_bfd);
4584 BFD_ASSERT (is_aarch64_elf (input_bfd));
4586 r_symndx = ELFNN_R_SYM (rel->r_info);
4588 /* It is possible to have linker relaxations on some TLS access
4589 models. Update our information here. */
4590 new_bfd_r_type = aarch64_tls_transition (input_bfd, info, r_type, h, r_symndx);
4591 if (new_bfd_r_type != bfd_r_type)
4593 bfd_r_type = new_bfd_r_type;
4594 howto = elfNN_aarch64_howto_from_bfd_reloc (bfd_r_type);
4595 BFD_ASSERT (howto != NULL);
4596 r_type = howto->type;
4599 place = input_section->output_section->vma
4600 + input_section->output_offset + rel->r_offset;
4602 /* Get addend, accumulating the addend for consecutive relocs
4603 which refer to the same offset. */
4604 signed_addend = saved_addend ? *saved_addend : 0;
4605 signed_addend += rel->r_addend;
4607 weak_undef_p = (h ? h->root.type == bfd_link_hash_undefweak
4608 : bfd_is_und_section (sym_sec));
4610 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle
4611 it here if it is defined in a non-shared object. */
4613 && h->type == STT_GNU_IFUNC
4620 if ((input_section->flags & SEC_ALLOC) == 0
4621 || h->plt.offset == (bfd_vma) -1)
4624 /* STT_GNU_IFUNC symbol must go through PLT. */
4625 plt = globals->root.splt ? globals->root.splt : globals->root.iplt;
4626 value = (plt->output_section->vma + plt->output_offset + h->plt.offset);
4631 if (h->root.root.string)
4632 name = h->root.root.string;
4634 name = bfd_elf_sym_name (input_bfd, symtab_hdr, sym,
4636 (*_bfd_error_handler)
4637 (_("%B: relocation %s against STT_GNU_IFUNC "
4638 "symbol `%s' isn't handled by %s"), input_bfd,
4639 howto->name, name, __FUNCTION__);
4640 bfd_set_error (bfd_error_bad_value);
4643 case BFD_RELOC_AARCH64_NN:
4644 if (rel->r_addend != 0)
4646 if (h->root.root.string)
4647 name = h->root.root.string;
4649 name = bfd_elf_sym_name (input_bfd, symtab_hdr,
4651 (*_bfd_error_handler)
4652 (_("%B: relocation %s against STT_GNU_IFUNC "
4653 "symbol `%s' has non-zero addend: %d"),
4654 input_bfd, howto->name, name, rel->r_addend);
4655 bfd_set_error (bfd_error_bad_value);
4659 /* Generate dynamic relocation only when there is a
4660 non-GOT reference in a shared object. */
4661 if (bfd_link_pic (info) && h->non_got_ref)
4663 Elf_Internal_Rela outrel;
4666 /* Need a dynamic relocation to get the real function
4668 outrel.r_offset = _bfd_elf_section_offset (output_bfd,
4672 if (outrel.r_offset == (bfd_vma) -1
4673 || outrel.r_offset == (bfd_vma) -2)
4676 outrel.r_offset += (input_section->output_section->vma
4677 + input_section->output_offset);
4679 if (h->dynindx == -1
4681 || bfd_link_executable (info))
4683 /* This symbol is resolved locally. */
4684 outrel.r_info = ELFNN_R_INFO (0, AARCH64_R (IRELATIVE));
4685 outrel.r_addend = (h->root.u.def.value
4686 + h->root.u.def.section->output_section->vma
4687 + h->root.u.def.section->output_offset);
4691 outrel.r_info = ELFNN_R_INFO (h->dynindx, r_type);
4692 outrel.r_addend = 0;
4695 sreloc = globals->root.irelifunc;
4696 elf_append_rela (output_bfd, sreloc, &outrel);
4698 /* If this reloc is against an external symbol, we
4699 do not want to fiddle with the addend. Otherwise,
4700 we need to include the symbol value so that it
4701 becomes an addend for the dynamic reloc. For an
4702 internal symbol, we have updated addend. */
4703 return bfd_reloc_ok;
4706 case BFD_RELOC_AARCH64_CALL26:
4707 case BFD_RELOC_AARCH64_JUMP26:
4708 value = _bfd_aarch64_elf_resolve_relocation (bfd_r_type, place, value,
4711 return _bfd_aarch64_elf_put_addend (input_bfd, hit_data, bfd_r_type,
4713 case BFD_RELOC_AARCH64_ADR_GOT_PAGE:
4714 case BFD_RELOC_AARCH64_GOT_LD_PREL19:
4715 case BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14:
4716 case BFD_RELOC_AARCH64_LD32_GOT_LO12_NC:
4717 case BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15:
4718 case BFD_RELOC_AARCH64_LD64_GOT_LO12_NC:
4719 base_got = globals->root.sgot;
4720 off = h->got.offset;
4722 if (base_got == NULL)
4725 if (off == (bfd_vma) -1)
4729 /* We can't use h->got.offset here to save state, or
4730 even just remember the offset, as finish_dynamic_symbol
4731 would use that as offset into .got. */
4733 if (globals->root.splt != NULL)
4735 plt_index = ((h->plt.offset - globals->plt_header_size) /
4736 globals->plt_entry_size);
4737 off = (plt_index + 3) * GOT_ENTRY_SIZE;
4738 base_got = globals->root.sgotplt;
4742 plt_index = h->plt.offset / globals->plt_entry_size;
4743 off = plt_index * GOT_ENTRY_SIZE;
4744 base_got = globals->root.igotplt;
4747 if (h->dynindx == -1
4751 /* This references the local definition. We must
4752 initialize this entry in the global offset table.
4753 Since the offset must always be a multiple of 8,
4754 we use the least significant bit to record
4755 whether we have initialized it already.
4757 When doing a dynamic link, we create a .rela.got
4758 relocation entry to initialize the value. This
4759 is done in the finish_dynamic_symbol routine. */
4764 bfd_put_NN (output_bfd, value,
4765 base_got->contents + off);
4766 /* Note that this is harmless as -1 | 1 still is -1. */
4770 value = (base_got->output_section->vma
4771 + base_got->output_offset + off);
4774 value = aarch64_calculate_got_entry_vma (h, globals, info,
4776 unresolved_reloc_p);
4777 if (bfd_r_type == BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15
4778 || bfd_r_type == BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14)
4779 addend = (globals->root.sgot->output_section->vma
4780 + globals->root.sgot->output_offset);
4781 value = _bfd_aarch64_elf_resolve_relocation (bfd_r_type, place, value,
4782 addend, weak_undef_p);
4783 return _bfd_aarch64_elf_put_addend (input_bfd, hit_data, bfd_r_type, howto, value);
4784 case BFD_RELOC_AARCH64_ADD_LO12:
4785 case BFD_RELOC_AARCH64_ADR_HI21_PCREL:
4792 case BFD_RELOC_AARCH64_NONE:
4793 case BFD_RELOC_AARCH64_TLSDESC_CALL:
4794 *unresolved_reloc_p = FALSE;
4795 return bfd_reloc_ok;
4797 case BFD_RELOC_AARCH64_NN:
4799 /* When generating a shared object or relocatable executable, these
4800 relocations are copied into the output file to be resolved at
4802 if (((bfd_link_pic (info) == TRUE)
4803 || globals->root.is_relocatable_executable)
4804 && (input_section->flags & SEC_ALLOC)
4806 || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
4807 || h->root.type != bfd_link_hash_undefweak))
4809 Elf_Internal_Rela outrel;
4811 bfd_boolean skip, relocate;
4814 *unresolved_reloc_p = FALSE;
4819 outrel.r_addend = signed_addend;
4821 _bfd_elf_section_offset (output_bfd, info, input_section,
4823 if (outrel.r_offset == (bfd_vma) - 1)
4825 else if (outrel.r_offset == (bfd_vma) - 2)
4831 outrel.r_offset += (input_section->output_section->vma
4832 + input_section->output_offset);
4835 memset (&outrel, 0, sizeof outrel);
4838 && (!bfd_link_pic (info)
4839 || !SYMBOLIC_BIND (info, h)
4840 || !h->def_regular))
4841 outrel.r_info = ELFNN_R_INFO (h->dynindx, r_type);
4846 /* On SVR4-ish systems, the dynamic loader cannot
4847 relocate the text and data segments independently,
4848 so the symbol does not matter. */
4850 outrel.r_info = ELFNN_R_INFO (symbol, AARCH64_R (RELATIVE));
4851 outrel.r_addend += value;
4854 sreloc = elf_section_data (input_section)->sreloc;
4855 if (sreloc == NULL || sreloc->contents == NULL)
4856 return bfd_reloc_notsupported;
4858 loc = sreloc->contents + sreloc->reloc_count++ * RELOC_SIZE (globals);
4859 bfd_elfNN_swap_reloca_out (output_bfd, &outrel, loc);
4861 if (sreloc->reloc_count * RELOC_SIZE (globals) > sreloc->size)
4863 /* Sanity to check that we have previously allocated
4864 sufficient space in the relocation section for the
4865 number of relocations we actually want to emit. */
4869 /* If this reloc is against an external symbol, we do not want to
4870 fiddle with the addend. Otherwise, we need to include the symbol
4871 value so that it becomes an addend for the dynamic reloc. */
4873 return bfd_reloc_ok;
4875 return _bfd_final_link_relocate (howto, input_bfd, input_section,
4876 contents, rel->r_offset, value,
4880 value += signed_addend;
4883 case BFD_RELOC_AARCH64_CALL26:
4884 case BFD_RELOC_AARCH64_JUMP26:
4886 asection *splt = globals->root.splt;
4887 bfd_boolean via_plt_p =
4888 splt != NULL && h != NULL && h->plt.offset != (bfd_vma) - 1;
4890 /* A call to an undefined weak symbol is converted to a jump to
4891 the next instruction unless a PLT entry will be created.
4892 The jump to the next instruction is optimized as a NOP.
4893 Do the same for local undefined symbols. */
4894 if (weak_undef_p && ! via_plt_p)
4896 bfd_putl32 (INSN_NOP, hit_data);
4897 return bfd_reloc_ok;
4900 /* If the call goes through a PLT entry, make sure to
4901 check distance to the right destination address. */
4903 value = (splt->output_section->vma
4904 + splt->output_offset + h->plt.offset);
4906 /* Check if a stub has to be inserted because the destination
4908 struct elf_aarch64_stub_hash_entry *stub_entry = NULL;
4909 if (! aarch64_valid_branch_p (value, place))
4910 /* The target is out of reach, so redirect the branch to
4911 the local stub for this function. */
4912 stub_entry = elfNN_aarch64_get_stub_entry (input_section, sym_sec, h,
4914 if (stub_entry != NULL)
4915 value = (stub_entry->stub_offset
4916 + stub_entry->stub_sec->output_offset
4917 + stub_entry->stub_sec->output_section->vma);
4919 value = _bfd_aarch64_elf_resolve_relocation (bfd_r_type, place, value,
4920 signed_addend, weak_undef_p);
4921 *unresolved_reloc_p = FALSE;
4924 case BFD_RELOC_AARCH64_16_PCREL:
4925 case BFD_RELOC_AARCH64_32_PCREL:
4926 case BFD_RELOC_AARCH64_64_PCREL:
4927 case BFD_RELOC_AARCH64_ADR_HI21_NC_PCREL:
4928 case BFD_RELOC_AARCH64_ADR_HI21_PCREL:
4929 case BFD_RELOC_AARCH64_ADR_LO21_PCREL:
4930 case BFD_RELOC_AARCH64_LD_LO19_PCREL:
4931 if (bfd_link_pic (info)
4932 && (input_section->flags & SEC_ALLOC) != 0
4933 && (input_section->flags & SEC_READONLY) != 0
4937 int howto_index = bfd_r_type - BFD_RELOC_AARCH64_RELOC_START;
4939 (*_bfd_error_handler)
4940 (_("%B: relocation %s against external symbol `%s' can not be used"
4941 " when making a shared object; recompile with -fPIC"),
4942 input_bfd, elfNN_aarch64_howto_table[howto_index].name,
4943 h->root.root.string);
4944 bfd_set_error (bfd_error_bad_value);
4948 case BFD_RELOC_AARCH64_16:
4950 case BFD_RELOC_AARCH64_32:
4952 case BFD_RELOC_AARCH64_ADD_LO12:
4953 case BFD_RELOC_AARCH64_BRANCH19:
4954 case BFD_RELOC_AARCH64_LDST128_LO12:
4955 case BFD_RELOC_AARCH64_LDST16_LO12:
4956 case BFD_RELOC_AARCH64_LDST32_LO12:
4957 case BFD_RELOC_AARCH64_LDST64_LO12:
4958 case BFD_RELOC_AARCH64_LDST8_LO12:
4959 case BFD_RELOC_AARCH64_MOVW_G0:
4960 case BFD_RELOC_AARCH64_MOVW_G0_NC:
4961 case BFD_RELOC_AARCH64_MOVW_G0_S:
4962 case BFD_RELOC_AARCH64_MOVW_G1:
4963 case BFD_RELOC_AARCH64_MOVW_G1_NC:
4964 case BFD_RELOC_AARCH64_MOVW_G1_S:
4965 case BFD_RELOC_AARCH64_MOVW_G2:
4966 case BFD_RELOC_AARCH64_MOVW_G2_NC:
4967 case BFD_RELOC_AARCH64_MOVW_G2_S:
4968 case BFD_RELOC_AARCH64_MOVW_G3:
4969 case BFD_RELOC_AARCH64_TSTBR14:
4970 value = _bfd_aarch64_elf_resolve_relocation (bfd_r_type, place, value,
4971 signed_addend, weak_undef_p);
4974 case BFD_RELOC_AARCH64_ADR_GOT_PAGE:
4975 case BFD_RELOC_AARCH64_GOT_LD_PREL19:
4976 case BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14:
4977 case BFD_RELOC_AARCH64_LD32_GOT_LO12_NC:
4978 case BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15:
4979 case BFD_RELOC_AARCH64_LD64_GOT_LO12_NC:
4980 if (globals->root.sgot == NULL)
4981 BFD_ASSERT (h != NULL);
4986 value = aarch64_calculate_got_entry_vma (h, globals, info, value,
4988 unresolved_reloc_p);
4989 if (bfd_r_type == BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15
4990 || bfd_r_type == BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14)
4991 addend = (globals->root.sgot->output_section->vma
4992 + globals->root.sgot->output_offset);
4993 value = _bfd_aarch64_elf_resolve_relocation (bfd_r_type, place, value,
4994 addend, weak_undef_p);
4999 struct elf_aarch64_local_symbol *locals
5000 = elf_aarch64_locals (input_bfd);
5004 int howto_index = bfd_r_type - BFD_RELOC_AARCH64_RELOC_START;
5005 (*_bfd_error_handler)
5006 (_("%B: Local symbol descriptor table be NULL when applying "
5007 "relocation %s against local symbol"),
5008 input_bfd, elfNN_aarch64_howto_table[howto_index].name);
5012 off = symbol_got_offset (input_bfd, h, r_symndx);
5013 base_got = globals->root.sgot;
5014 bfd_vma got_entry_addr = (base_got->output_section->vma
5015 + base_got->output_offset + off);
5017 if (!symbol_got_offset_mark_p (input_bfd, h, r_symndx))
5019 bfd_put_64 (output_bfd, value, base_got->contents + off);
5021 if (bfd_link_pic (info))
5024 Elf_Internal_Rela outrel;
5026 /* For local symbol, we have done absolute relocation in static
5027 linking stageh. While for share library, we need to update
5028 the content of GOT entry according to the share objects
5029 loading base address. So we need to generate a
5030 R_AARCH64_RELATIVE reloc for dynamic linker. */
5031 s = globals->root.srelgot;
5035 outrel.r_offset = got_entry_addr;
5036 outrel.r_info = ELFNN_R_INFO (0, AARCH64_R (RELATIVE));
5037 outrel.r_addend = value;
5038 elf_append_rela (output_bfd, s, &outrel);
5041 symbol_got_offset_mark (input_bfd, h, r_symndx);
5044 /* Update the relocation value to GOT entry addr as we have transformed
5045 the direct data access into indirect data access through GOT. */
5046 value = got_entry_addr;
5048 if (bfd_r_type == BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15
5049 || bfd_r_type == BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14)
5050 addend = base_got->output_section->vma + base_got->output_offset;
5052 value = _bfd_aarch64_elf_resolve_relocation (bfd_r_type, place, value,
5053 addend, weak_undef_p);
5058 case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC:
5059 case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21:
5060 case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21:
5061 case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21:
5062 case BFD_RELOC_AARCH64_TLSIE_LD32_GOTTPREL_LO12_NC:
5063 case BFD_RELOC_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC:
5064 case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19:
5065 case BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC:
5066 case BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21:
5067 case BFD_RELOC_AARCH64_TLSLD_ADR_PREL21:
5068 if (globals->root.sgot == NULL)
5069 return bfd_reloc_notsupported;
5071 value = (symbol_got_offset (input_bfd, h, r_symndx)
5072 + globals->root.sgot->output_section->vma
5073 + globals->root.sgot->output_offset);
5075 value = _bfd_aarch64_elf_resolve_relocation (bfd_r_type, place, value,
5077 *unresolved_reloc_p = FALSE;
5080 case BFD_RELOC_AARCH64_TLSLD_ADD_DTPREL_LO12:
5081 value = _bfd_aarch64_elf_resolve_relocation (bfd_r_type, place, value,
5082 signed_addend - dtpoff_base (info),
5086 case BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_HI12:
5087 case BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_LO12:
5088 case BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_LO12_NC:
5089 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0:
5090 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC:
5091 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1:
5092 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1_NC:
5093 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G2:
5094 value = _bfd_aarch64_elf_resolve_relocation (bfd_r_type, place, value,
5095 signed_addend - tpoff_base (info),
5097 *unresolved_reloc_p = FALSE;
5100 case BFD_RELOC_AARCH64_TLSDESC_ADD:
5101 case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12_NC:
5102 case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21:
5103 case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21:
5104 case BFD_RELOC_AARCH64_TLSDESC_LD32_LO12_NC:
5105 case BFD_RELOC_AARCH64_TLSDESC_LD64_LO12_NC:
5106 case BFD_RELOC_AARCH64_TLSDESC_LDR:
5107 case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19:
5108 if (globals->root.sgot == NULL)
5109 return bfd_reloc_notsupported;
5110 value = (symbol_tlsdesc_got_offset (input_bfd, h, r_symndx)
5111 + globals->root.sgotplt->output_section->vma
5112 + globals->root.sgotplt->output_offset
5113 + globals->sgotplt_jump_table_size);
5115 value = _bfd_aarch64_elf_resolve_relocation (bfd_r_type, place, value,
5117 *unresolved_reloc_p = FALSE;
5121 return bfd_reloc_notsupported;
5125 *saved_addend = value;
5127 /* Only apply the final relocation in a sequence. */
5129 return bfd_reloc_continue;
5131 return _bfd_aarch64_elf_put_addend (input_bfd, hit_data, bfd_r_type,
5135 /* Handle TLS relaxations. Relaxing is possible for symbols that use
5136 R_AARCH64_TLSDESC_ADR_{PAGE, LD64_LO12_NC, ADD_LO12_NC} during a static
5139 Return bfd_reloc_ok if we're done, bfd_reloc_continue if the caller
5140 is to then call final_link_relocate. Return other values in the
5143 static bfd_reloc_status_type
5144 elfNN_aarch64_tls_relax (struct elf_aarch64_link_hash_table *globals,
5145 bfd *input_bfd, bfd_byte *contents,
5146 Elf_Internal_Rela *rel, struct elf_link_hash_entry *h)
5148 bfd_boolean is_local = h == NULL;
5149 unsigned int r_type = ELFNN_R_TYPE (rel->r_info);
5152 BFD_ASSERT (globals && input_bfd && contents && rel);
5154 switch (elfNN_aarch64_bfd_reloc_from_type (r_type))
5156 case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21:
5157 case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21:
5160 /* GD->LE relaxation:
5161 adrp x0, :tlsgd:var => movz x0, :tprel_g1:var
5163 adrp x0, :tlsdesc:var => movz x0, :tprel_g1:var
5165 bfd_putl32 (0xd2a00000, contents + rel->r_offset);
5166 return bfd_reloc_continue;
5170 /* GD->IE relaxation:
5171 adrp x0, :tlsgd:var => adrp x0, :gottprel:var
5173 adrp x0, :tlsdesc:var => adrp x0, :gottprel:var
5175 return bfd_reloc_continue;
5178 case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21:
5182 case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19:
5185 /* Tiny TLSDESC->LE relaxation:
5186 ldr x1, :tlsdesc:var => movz x0, #:tprel_g1:var
5187 adr x0, :tlsdesc:var => movk x0, #:tprel_g0_nc:var
5191 BFD_ASSERT (ELFNN_R_TYPE (rel[1].r_info) == AARCH64_R (TLSDESC_ADR_PREL21));
5192 BFD_ASSERT (ELFNN_R_TYPE (rel[2].r_info) == AARCH64_R (TLSDESC_CALL));
5194 rel[1].r_info = ELFNN_R_INFO (ELFNN_R_SYM (rel->r_info),
5195 AARCH64_R (TLSLE_MOVW_TPREL_G0_NC));
5196 rel[2].r_info = ELFNN_R_INFO (STN_UNDEF, R_AARCH64_NONE);
5198 bfd_putl32 (0xd2a00000, contents + rel->r_offset);
5199 bfd_putl32 (0xf2800000, contents + rel->r_offset + 4);
5200 bfd_putl32 (INSN_NOP, contents + rel->r_offset + 8);
5201 return bfd_reloc_continue;
5205 /* Tiny TLSDESC->IE relaxation:
5206 ldr x1, :tlsdesc:var => ldr x0, :gottprel:var
5207 adr x0, :tlsdesc:var => nop
5211 BFD_ASSERT (ELFNN_R_TYPE (rel[1].r_info) == AARCH64_R (TLSDESC_ADR_PREL21));
5212 BFD_ASSERT (ELFNN_R_TYPE (rel[2].r_info) == AARCH64_R (TLSDESC_CALL));
5214 rel[1].r_info = ELFNN_R_INFO (STN_UNDEF, R_AARCH64_NONE);
5215 rel[2].r_info = ELFNN_R_INFO (STN_UNDEF, R_AARCH64_NONE);
5217 bfd_putl32 (0x58000000, contents + rel->r_offset);
5218 bfd_putl32 (INSN_NOP, contents + rel->r_offset + 4);
5219 bfd_putl32 (INSN_NOP, contents + rel->r_offset + 8);
5220 return bfd_reloc_continue;
5223 case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21:
5226 /* Tiny GD->LE relaxation:
5227 adr x0, :tlsgd:var => mrs x1, tpidr_el0
5228 bl __tls_get_addr => add x0, x1, #:tprel_hi12:x, lsl #12
5229 nop => add x0, x0, #:tprel_lo12_nc:x
5232 /* First kill the tls_get_addr reloc on the bl instruction. */
5233 BFD_ASSERT (rel->r_offset + 4 == rel[1].r_offset);
5235 bfd_putl32 (0xd53bd041, contents + rel->r_offset + 0);
5236 bfd_putl32 (0x91400020, contents + rel->r_offset + 4);
5237 bfd_putl32 (0x91000000, contents + rel->r_offset + 8);
5239 rel[1].r_info = ELFNN_R_INFO (ELFNN_R_SYM (rel->r_info),
5240 AARCH64_R (TLSLE_ADD_TPREL_LO12_NC));
5241 rel[1].r_offset = rel->r_offset + 8;
5243 /* Move the current relocation to the second instruction in
5246 rel->r_info = ELFNN_R_INFO (ELFNN_R_SYM (rel->r_info),
5247 AARCH64_R (TLSLE_ADD_TPREL_HI12));
5248 return bfd_reloc_continue;
5252 /* Tiny GD->IE relaxation:
5253 adr x0, :tlsgd:var => ldr x0, :gottprel:var
5254 bl __tls_get_addr => mrs x1, tpidr_el0
5255 nop => add x0, x0, x1
5258 /* First kill the tls_get_addr reloc on the bl instruction. */
5259 BFD_ASSERT (rel->r_offset + 4 == rel[1].r_offset);
5260 rel[1].r_info = ELFNN_R_INFO (STN_UNDEF, R_AARCH64_NONE);
5262 bfd_putl32 (0x58000000, contents + rel->r_offset);
5263 bfd_putl32 (0xd53bd041, contents + rel->r_offset + 4);
5264 bfd_putl32 (0x8b000020, contents + rel->r_offset + 8);
5265 return bfd_reloc_continue;
5268 case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19:
5269 return bfd_reloc_continue;
5271 case BFD_RELOC_AARCH64_TLSDESC_LDNN_LO12_NC:
5274 /* GD->LE relaxation:
5275 ldr xd, [x0, #:tlsdesc_lo12:var] => movk x0, :tprel_g0_nc:var
5277 bfd_putl32 (0xf2800000, contents + rel->r_offset);
5278 return bfd_reloc_continue;
5282 /* GD->IE relaxation:
5283 ldr xd, [x0, #:tlsdesc_lo12:var] => ldr x0, [x0, #:gottprel_lo12:var]
5285 insn = bfd_getl32 (contents + rel->r_offset);
5287 bfd_putl32 (insn, contents + rel->r_offset);
5288 return bfd_reloc_continue;
5291 case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC:
5294 /* GD->LE relaxation
5295 add x0, #:tlsgd_lo12:var => movk x0, :tprel_g0_nc:var
5296 bl __tls_get_addr => mrs x1, tpidr_el0
5297 nop => add x0, x1, x0
5300 /* First kill the tls_get_addr reloc on the bl instruction. */
5301 BFD_ASSERT (rel->r_offset + 4 == rel[1].r_offset);
5302 rel[1].r_info = ELFNN_R_INFO (STN_UNDEF, R_AARCH64_NONE);
5304 bfd_putl32 (0xf2800000, contents + rel->r_offset);
5305 bfd_putl32 (0xd53bd041, contents + rel->r_offset + 4);
5306 bfd_putl32 (0x8b000020, contents + rel->r_offset + 8);
5307 return bfd_reloc_continue;
5311 /* GD->IE relaxation
5312 ADD x0, #:tlsgd_lo12:var => ldr x0, [x0, #:gottprel_lo12:var]
5313 BL __tls_get_addr => mrs x1, tpidr_el0
5315 NOP => add x0, x1, x0
5318 BFD_ASSERT (ELFNN_R_TYPE (rel[1].r_info) == AARCH64_R (CALL26));
5320 /* Remove the relocation on the BL instruction. */
5321 rel[1].r_info = ELFNN_R_INFO (STN_UNDEF, R_AARCH64_NONE);
5323 bfd_putl32 (0xf9400000, contents + rel->r_offset);
5325 /* We choose to fixup the BL and NOP instructions using the
5326 offset from the second relocation to allow flexibility in
5327 scheduling instructions between the ADD and BL. */
5328 bfd_putl32 (0xd53bd041, contents + rel[1].r_offset);
5329 bfd_putl32 (0x8b000020, contents + rel[1].r_offset + 4);
5330 return bfd_reloc_continue;
5333 case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12_NC:
5334 case BFD_RELOC_AARCH64_TLSDESC_CALL:
5335 /* GD->IE/LE relaxation:
5336 add x0, x0, #:tlsdesc_lo12:var => nop
5339 bfd_putl32 (INSN_NOP, contents + rel->r_offset);
5340 return bfd_reloc_ok;
5342 case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21:
5343 /* IE->LE relaxation:
5344 adrp xd, :gottprel:var => movz xd, :tprel_g1:var
5348 insn = bfd_getl32 (contents + rel->r_offset);
5349 bfd_putl32 (0xd2a00000 | (insn & 0x1f), contents + rel->r_offset);
5351 return bfd_reloc_continue;
5353 case BFD_RELOC_AARCH64_TLSIE_LDNN_GOTTPREL_LO12_NC:
5354 /* IE->LE relaxation:
5355 ldr xd, [xm, #:gottprel_lo12:var] => movk xd, :tprel_g0_nc:var
5359 insn = bfd_getl32 (contents + rel->r_offset);
5360 bfd_putl32 (0xf2800000 | (insn & 0x1f), contents + rel->r_offset);
5362 return bfd_reloc_continue;
5365 return bfd_reloc_continue;
5368 return bfd_reloc_ok;
5371 /* Relocate an AArch64 ELF section. */
5374 elfNN_aarch64_relocate_section (bfd *output_bfd,
5375 struct bfd_link_info *info,
5377 asection *input_section,
5379 Elf_Internal_Rela *relocs,
5380 Elf_Internal_Sym *local_syms,
5381 asection **local_sections)
5383 Elf_Internal_Shdr *symtab_hdr;
5384 struct elf_link_hash_entry **sym_hashes;
5385 Elf_Internal_Rela *rel;
5386 Elf_Internal_Rela *relend;
5388 struct elf_aarch64_link_hash_table *globals;
5389 bfd_boolean save_addend = FALSE;
5392 globals = elf_aarch64_hash_table (info);
5394 symtab_hdr = &elf_symtab_hdr (input_bfd);
5395 sym_hashes = elf_sym_hashes (input_bfd);
5398 relend = relocs + input_section->reloc_count;
5399 for (; rel < relend; rel++)
5401 unsigned int r_type;
5402 bfd_reloc_code_real_type bfd_r_type;
5403 bfd_reloc_code_real_type relaxed_bfd_r_type;
5404 reloc_howto_type *howto;
5405 unsigned long r_symndx;
5406 Elf_Internal_Sym *sym;
5408 struct elf_link_hash_entry *h;
5410 bfd_reloc_status_type r;
5413 bfd_boolean unresolved_reloc = FALSE;
5414 char *error_message = NULL;
5416 r_symndx = ELFNN_R_SYM (rel->r_info);
5417 r_type = ELFNN_R_TYPE (rel->r_info);
5419 bfd_reloc.howto = elfNN_aarch64_howto_from_type (r_type);
5420 howto = bfd_reloc.howto;
5424 (*_bfd_error_handler)
5425 (_("%B: unrecognized relocation (0x%x) in section `%A'"),
5426 input_bfd, input_section, r_type);
5429 bfd_r_type = elfNN_aarch64_bfd_reloc_from_howto (howto);
5435 if (r_symndx < symtab_hdr->sh_info)
5437 sym = local_syms + r_symndx;
5438 sym_type = ELFNN_ST_TYPE (sym->st_info);
5439 sec = local_sections[r_symndx];
5441 /* An object file might have a reference to a local
5442 undefined symbol. This is a daft object file, but we
5443 should at least do something about it. */
5444 if (r_type != R_AARCH64_NONE && r_type != R_AARCH64_NULL
5445 && bfd_is_und_section (sec)
5446 && ELF_ST_BIND (sym->st_info) != STB_WEAK)
5448 if (!info->callbacks->undefined_symbol
5449 (info, bfd_elf_string_from_elf_section
5450 (input_bfd, symtab_hdr->sh_link, sym->st_name),
5451 input_bfd, input_section, rel->r_offset, TRUE))
5455 relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel);
5457 /* Relocate against local STT_GNU_IFUNC symbol. */
5458 if (!bfd_link_relocatable (info)
5459 && ELF_ST_TYPE (sym->st_info) == STT_GNU_IFUNC)
5461 h = elfNN_aarch64_get_local_sym_hash (globals, input_bfd,
5466 /* Set STT_GNU_IFUNC symbol value. */
5467 h->root.u.def.value = sym->st_value;
5468 h->root.u.def.section = sec;
5473 bfd_boolean warned, ignored;
5475 RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel,
5476 r_symndx, symtab_hdr, sym_hashes,
5478 unresolved_reloc, warned, ignored);
5483 if (sec != NULL && discarded_section (sec))
5484 RELOC_AGAINST_DISCARDED_SECTION (info, input_bfd, input_section,
5485 rel, 1, relend, howto, 0, contents);
5487 if (bfd_link_relocatable (info))
5491 name = h->root.root.string;
5494 name = (bfd_elf_string_from_elf_section
5495 (input_bfd, symtab_hdr->sh_link, sym->st_name));
5496 if (name == NULL || *name == '\0')
5497 name = bfd_section_name (input_bfd, sec);
5501 && r_type != R_AARCH64_NONE
5502 && r_type != R_AARCH64_NULL
5504 || h->root.type == bfd_link_hash_defined
5505 || h->root.type == bfd_link_hash_defweak)
5506 && IS_AARCH64_TLS_RELOC (bfd_r_type) != (sym_type == STT_TLS))
5508 (*_bfd_error_handler)
5509 ((sym_type == STT_TLS
5510 ? _("%B(%A+0x%lx): %s used with TLS symbol %s")
5511 : _("%B(%A+0x%lx): %s used with non-TLS symbol %s")),
5513 input_section, (long) rel->r_offset, howto->name, name);
5516 /* We relax only if we can see that there can be a valid transition
5517 from a reloc type to another.
5518 We call elfNN_aarch64_final_link_relocate unless we're completely
5519 done, i.e., the relaxation produced the final output we want. */
5521 relaxed_bfd_r_type = aarch64_tls_transition (input_bfd, info, r_type,
5523 if (relaxed_bfd_r_type != bfd_r_type)
5525 bfd_r_type = relaxed_bfd_r_type;
5526 howto = elfNN_aarch64_howto_from_bfd_reloc (bfd_r_type);
5527 BFD_ASSERT (howto != NULL);
5528 r_type = howto->type;
5529 r = elfNN_aarch64_tls_relax (globals, input_bfd, contents, rel, h);
5530 unresolved_reloc = 0;
5533 r = bfd_reloc_continue;
5535 /* There may be multiple consecutive relocations for the
5536 same offset. In that case we are supposed to treat the
5537 output of each relocation as the addend for the next. */
5538 if (rel + 1 < relend
5539 && rel->r_offset == rel[1].r_offset
5540 && ELFNN_R_TYPE (rel[1].r_info) != R_AARCH64_NONE
5541 && ELFNN_R_TYPE (rel[1].r_info) != R_AARCH64_NULL)
5544 save_addend = FALSE;
5546 if (r == bfd_reloc_continue)
5547 r = elfNN_aarch64_final_link_relocate (howto, input_bfd, output_bfd,
5548 input_section, contents, rel,
5549 relocation, info, sec,
5550 h, &unresolved_reloc,
5551 save_addend, &addend, sym);
5553 switch (elfNN_aarch64_bfd_reloc_from_type (r_type))
5555 case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC:
5556 case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21:
5557 case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21:
5558 case BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC:
5559 case BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21:
5560 case BFD_RELOC_AARCH64_TLSLD_ADR_PREL21:
5561 if (! symbol_got_offset_mark_p (input_bfd, h, r_symndx))
5563 bfd_boolean need_relocs = FALSE;
5568 off = symbol_got_offset (input_bfd, h, r_symndx);
5569 indx = h && h->dynindx != -1 ? h->dynindx : 0;
5572 (bfd_link_pic (info) || indx != 0) &&
5574 || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
5575 || h->root.type != bfd_link_hash_undefweak);
5577 BFD_ASSERT (globals->root.srelgot != NULL);
5581 Elf_Internal_Rela rela;
5582 rela.r_info = ELFNN_R_INFO (indx, AARCH64_R (TLS_DTPMOD));
5584 rela.r_offset = globals->root.sgot->output_section->vma +
5585 globals->root.sgot->output_offset + off;
5588 loc = globals->root.srelgot->contents;
5589 loc += globals->root.srelgot->reloc_count++
5590 * RELOC_SIZE (htab);
5591 bfd_elfNN_swap_reloca_out (output_bfd, &rela, loc);
5593 bfd_reloc_code_real_type real_type =
5594 elfNN_aarch64_bfd_reloc_from_type (r_type);
5596 if (real_type == BFD_RELOC_AARCH64_TLSLD_ADR_PREL21
5597 || real_type == BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21
5598 || real_type == BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC)
5600 /* For local dynamic, don't generate DTPREL in any case.
5601 Initialize the DTPREL slot into zero, so we get module
5602 base address when invoke runtime TLS resolver. */
5603 bfd_put_NN (output_bfd, 0,
5604 globals->root.sgot->contents + off
5609 bfd_put_NN (output_bfd,
5610 relocation - dtpoff_base (info),
5611 globals->root.sgot->contents + off
5616 /* This TLS symbol is global. We emit a
5617 relocation to fixup the tls offset at load
5620 ELFNN_R_INFO (indx, AARCH64_R (TLS_DTPREL));
5623 (globals->root.sgot->output_section->vma
5624 + globals->root.sgot->output_offset + off
5627 loc = globals->root.srelgot->contents;
5628 loc += globals->root.srelgot->reloc_count++
5629 * RELOC_SIZE (globals);
5630 bfd_elfNN_swap_reloca_out (output_bfd, &rela, loc);
5631 bfd_put_NN (output_bfd, (bfd_vma) 0,
5632 globals->root.sgot->contents + off
5638 bfd_put_NN (output_bfd, (bfd_vma) 1,
5639 globals->root.sgot->contents + off);
5640 bfd_put_NN (output_bfd,
5641 relocation - dtpoff_base (info),
5642 globals->root.sgot->contents + off
5646 symbol_got_offset_mark (input_bfd, h, r_symndx);
5650 case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21:
5651 case BFD_RELOC_AARCH64_TLSIE_LDNN_GOTTPREL_LO12_NC:
5652 case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19:
5653 if (! symbol_got_offset_mark_p (input_bfd, h, r_symndx))
5655 bfd_boolean need_relocs = FALSE;
5660 off = symbol_got_offset (input_bfd, h, r_symndx);
5662 indx = h && h->dynindx != -1 ? h->dynindx : 0;
5665 (bfd_link_pic (info) || indx != 0) &&
5667 || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
5668 || h->root.type != bfd_link_hash_undefweak);
5670 BFD_ASSERT (globals->root.srelgot != NULL);
5674 Elf_Internal_Rela rela;
5677 rela.r_addend = relocation - dtpoff_base (info);
5681 rela.r_info = ELFNN_R_INFO (indx, AARCH64_R (TLS_TPREL));
5682 rela.r_offset = globals->root.sgot->output_section->vma +
5683 globals->root.sgot->output_offset + off;
5685 loc = globals->root.srelgot->contents;
5686 loc += globals->root.srelgot->reloc_count++
5687 * RELOC_SIZE (htab);
5689 bfd_elfNN_swap_reloca_out (output_bfd, &rela, loc);
5691 bfd_put_NN (output_bfd, rela.r_addend,
5692 globals->root.sgot->contents + off);
5695 bfd_put_NN (output_bfd, relocation - tpoff_base (info),
5696 globals->root.sgot->contents + off);
5698 symbol_got_offset_mark (input_bfd, h, r_symndx);
5702 case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12_NC:
5703 case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21:
5704 case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21:
5705 case BFD_RELOC_AARCH64_TLSDESC_LDNN_LO12_NC:
5706 case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19:
5707 if (! symbol_tlsdesc_got_offset_mark_p (input_bfd, h, r_symndx))
5709 bfd_boolean need_relocs = FALSE;
5710 int indx = h && h->dynindx != -1 ? h->dynindx : 0;
5711 bfd_vma off = symbol_tlsdesc_got_offset (input_bfd, h, r_symndx);
5713 need_relocs = (h == NULL
5714 || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
5715 || h->root.type != bfd_link_hash_undefweak);
5717 BFD_ASSERT (globals->root.srelgot != NULL);
5718 BFD_ASSERT (globals->root.sgot != NULL);
5723 Elf_Internal_Rela rela;
5724 rela.r_info = ELFNN_R_INFO (indx, AARCH64_R (TLSDESC));
5727 rela.r_offset = (globals->root.sgotplt->output_section->vma
5728 + globals->root.sgotplt->output_offset
5729 + off + globals->sgotplt_jump_table_size);
5732 rela.r_addend = relocation - dtpoff_base (info);
5734 /* Allocate the next available slot in the PLT reloc
5735 section to hold our R_AARCH64_TLSDESC, the next
5736 available slot is determined from reloc_count,
5737 which we step. But note, reloc_count was
5738 artifically moved down while allocating slots for
5739 real PLT relocs such that all of the PLT relocs
5740 will fit above the initial reloc_count and the
5741 extra stuff will fit below. */
5742 loc = globals->root.srelplt->contents;
5743 loc += globals->root.srelplt->reloc_count++
5744 * RELOC_SIZE (globals);
5746 bfd_elfNN_swap_reloca_out (output_bfd, &rela, loc);
5748 bfd_put_NN (output_bfd, (bfd_vma) 0,
5749 globals->root.sgotplt->contents + off +
5750 globals->sgotplt_jump_table_size);
5751 bfd_put_NN (output_bfd, (bfd_vma) 0,
5752 globals->root.sgotplt->contents + off +
5753 globals->sgotplt_jump_table_size +
5757 symbol_tlsdesc_got_offset_mark (input_bfd, h, r_symndx);
5768 /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
5769 because such sections are not SEC_ALLOC and thus ld.so will
5770 not process them. */
5771 if (unresolved_reloc
5772 && !((input_section->flags & SEC_DEBUGGING) != 0
5774 && _bfd_elf_section_offset (output_bfd, info, input_section,
5775 +rel->r_offset) != (bfd_vma) - 1)
5777 (*_bfd_error_handler)
5779 ("%B(%A+0x%lx): unresolvable %s relocation against symbol `%s'"),
5780 input_bfd, input_section, (long) rel->r_offset, howto->name,
5781 h->root.root.string);
5785 if (r != bfd_reloc_ok && r != bfd_reloc_continue)
5787 bfd_reloc_code_real_type real_r_type
5788 = elfNN_aarch64_bfd_reloc_from_type (r_type);
5792 case bfd_reloc_overflow:
5793 if (!(*info->callbacks->reloc_overflow)
5794 (info, (h ? &h->root : NULL), name, howto->name, (bfd_vma) 0,
5795 input_bfd, input_section, rel->r_offset))
5797 if (real_r_type == BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15
5798 || real_r_type == BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14)
5800 (*info->callbacks->warning)
5802 _("Too many GOT entries for -fpic, "
5803 "please recompile with -fPIC"),
5804 name, input_bfd, input_section, rel->r_offset);
5809 case bfd_reloc_undefined:
5810 if (!((*info->callbacks->undefined_symbol)
5811 (info, name, input_bfd, input_section,
5812 rel->r_offset, TRUE)))
5816 case bfd_reloc_outofrange:
5817 error_message = _("out of range");
5820 case bfd_reloc_notsupported:
5821 error_message = _("unsupported relocation");
5824 case bfd_reloc_dangerous:
5825 /* error_message should already be set. */
5829 error_message = _("unknown error");
5833 BFD_ASSERT (error_message != NULL);
5834 if (!((*info->callbacks->reloc_dangerous)
5835 (info, error_message, input_bfd, input_section,
5846 /* Set the right machine number. */
5849 elfNN_aarch64_object_p (bfd *abfd)
5852 bfd_default_set_arch_mach (abfd, bfd_arch_aarch64, bfd_mach_aarch64_ilp32);
5854 bfd_default_set_arch_mach (abfd, bfd_arch_aarch64, bfd_mach_aarch64);
5859 /* Function to keep AArch64 specific flags in the ELF header. */
5862 elfNN_aarch64_set_private_flags (bfd *abfd, flagword flags)
5864 if (elf_flags_init (abfd) && elf_elfheader (abfd)->e_flags != flags)
5869 elf_elfheader (abfd)->e_flags = flags;
5870 elf_flags_init (abfd) = TRUE;
5876 /* Merge backend specific data from an object file to the output
5877 object file when linking. */
5880 elfNN_aarch64_merge_private_bfd_data (bfd *ibfd, bfd *obfd)
5884 bfd_boolean flags_compatible = TRUE;
5887 /* Check if we have the same endianess. */
5888 if (!_bfd_generic_verify_endian_match (ibfd, obfd))
5891 if (!is_aarch64_elf (ibfd) || !is_aarch64_elf (obfd))
5894 /* The input BFD must have had its flags initialised. */
5895 /* The following seems bogus to me -- The flags are initialized in
5896 the assembler but I don't think an elf_flags_init field is
5897 written into the object. */
5898 /* BFD_ASSERT (elf_flags_init (ibfd)); */
5900 in_flags = elf_elfheader (ibfd)->e_flags;
5901 out_flags = elf_elfheader (obfd)->e_flags;
5903 if (!elf_flags_init (obfd))
5905 /* If the input is the default architecture and had the default
5906 flags then do not bother setting the flags for the output
5907 architecture, instead allow future merges to do this. If no
5908 future merges ever set these flags then they will retain their
5909 uninitialised values, which surprise surprise, correspond
5910 to the default values. */
5911 if (bfd_get_arch_info (ibfd)->the_default
5912 && elf_elfheader (ibfd)->e_flags == 0)
5915 elf_flags_init (obfd) = TRUE;
5916 elf_elfheader (obfd)->e_flags = in_flags;
5918 if (bfd_get_arch (obfd) == bfd_get_arch (ibfd)
5919 && bfd_get_arch_info (obfd)->the_default)
5920 return bfd_set_arch_mach (obfd, bfd_get_arch (ibfd),
5921 bfd_get_mach (ibfd));
5926 /* Identical flags must be compatible. */
5927 if (in_flags == out_flags)
5930 /* Check to see if the input BFD actually contains any sections. If
5931 not, its flags may not have been initialised either, but it
5932 cannot actually cause any incompatiblity. Do not short-circuit
5933 dynamic objects; their section list may be emptied by
5934 elf_link_add_object_symbols.
5936 Also check to see if there are no code sections in the input.
5937 In this case there is no need to check for code specific flags.
5938 XXX - do we need to worry about floating-point format compatability
5939 in data sections ? */
5940 if (!(ibfd->flags & DYNAMIC))
5942 bfd_boolean null_input_bfd = TRUE;
5943 bfd_boolean only_data_sections = TRUE;
5945 for (sec = ibfd->sections; sec != NULL; sec = sec->next)
5947 if ((bfd_get_section_flags (ibfd, sec)
5948 & (SEC_LOAD | SEC_CODE | SEC_HAS_CONTENTS))
5949 == (SEC_LOAD | SEC_CODE | SEC_HAS_CONTENTS))
5950 only_data_sections = FALSE;
5952 null_input_bfd = FALSE;
5956 if (null_input_bfd || only_data_sections)
5960 return flags_compatible;
5963 /* Display the flags field. */
5966 elfNN_aarch64_print_private_bfd_data (bfd *abfd, void *ptr)
5968 FILE *file = (FILE *) ptr;
5969 unsigned long flags;
5971 BFD_ASSERT (abfd != NULL && ptr != NULL);
5973 /* Print normal ELF private data. */
5974 _bfd_elf_print_private_bfd_data (abfd, ptr);
5976 flags = elf_elfheader (abfd)->e_flags;
5977 /* Ignore init flag - it may not be set, despite the flags field
5978 containing valid data. */
5980 /* xgettext:c-format */
5981 fprintf (file, _("private flags = %lx:"), elf_elfheader (abfd)->e_flags);
5984 fprintf (file, _("<Unrecognised flag bits set>"));
5991 /* Update the got entry reference counts for the section being removed. */
5994 elfNN_aarch64_gc_sweep_hook (bfd *abfd,
5995 struct bfd_link_info *info,
5997 const Elf_Internal_Rela * relocs)
5999 struct elf_aarch64_link_hash_table *htab;
6000 Elf_Internal_Shdr *symtab_hdr;
6001 struct elf_link_hash_entry **sym_hashes;
6002 struct elf_aarch64_local_symbol *locals;
6003 const Elf_Internal_Rela *rel, *relend;
6005 if (bfd_link_relocatable (info))
6008 htab = elf_aarch64_hash_table (info);
6013 elf_section_data (sec)->local_dynrel = NULL;
6015 symtab_hdr = &elf_symtab_hdr (abfd);
6016 sym_hashes = elf_sym_hashes (abfd);
6018 locals = elf_aarch64_locals (abfd);
6020 relend = relocs + sec->reloc_count;
6021 for (rel = relocs; rel < relend; rel++)
6023 unsigned long r_symndx;
6024 unsigned int r_type;
6025 struct elf_link_hash_entry *h = NULL;
6027 r_symndx = ELFNN_R_SYM (rel->r_info);
6029 if (r_symndx >= symtab_hdr->sh_info)
6032 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
6033 while (h->root.type == bfd_link_hash_indirect
6034 || h->root.type == bfd_link_hash_warning)
6035 h = (struct elf_link_hash_entry *) h->root.u.i.link;
6039 Elf_Internal_Sym *isym;
6041 /* A local symbol. */
6042 isym = bfd_sym_from_r_symndx (&htab->sym_cache,
6045 /* Check relocation against local STT_GNU_IFUNC symbol. */
6047 && ELF_ST_TYPE (isym->st_info) == STT_GNU_IFUNC)
6049 h = elfNN_aarch64_get_local_sym_hash (htab, abfd, rel, FALSE);
6057 struct elf_aarch64_link_hash_entry *eh;
6058 struct elf_dyn_relocs **pp;
6059 struct elf_dyn_relocs *p;
6061 eh = (struct elf_aarch64_link_hash_entry *) h;
6063 for (pp = &eh->dyn_relocs; (p = *pp) != NULL; pp = &p->next)
6066 /* Everything must go for SEC. */
6072 r_type = ELFNN_R_TYPE (rel->r_info);
6073 switch (aarch64_tls_transition (abfd,info, r_type, h ,r_symndx))
6075 case BFD_RELOC_AARCH64_ADR_GOT_PAGE:
6076 case BFD_RELOC_AARCH64_GOT_LD_PREL19:
6077 case BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14:
6078 case BFD_RELOC_AARCH64_LD32_GOT_LO12_NC:
6079 case BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15:
6080 case BFD_RELOC_AARCH64_LD64_GOT_LO12_NC:
6081 case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12_NC:
6082 case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21:
6083 case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21:
6084 case BFD_RELOC_AARCH64_TLSDESC_LD32_LO12_NC:
6085 case BFD_RELOC_AARCH64_TLSDESC_LD64_LO12_NC:
6086 case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19:
6087 case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC:
6088 case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21:
6089 case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21:
6090 case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21:
6091 case BFD_RELOC_AARCH64_TLSIE_LD32_GOTTPREL_LO12_NC:
6092 case BFD_RELOC_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC:
6093 case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19:
6094 case BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC:
6095 case BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21:
6096 case BFD_RELOC_AARCH64_TLSLD_ADR_PREL21:
6099 if (h->got.refcount > 0)
6100 h->got.refcount -= 1;
6102 if (h->type == STT_GNU_IFUNC)
6104 if (h->plt.refcount > 0)
6105 h->plt.refcount -= 1;
6108 else if (locals != NULL)
6110 if (locals[r_symndx].got_refcount > 0)
6111 locals[r_symndx].got_refcount -= 1;
6115 case BFD_RELOC_AARCH64_CALL26:
6116 case BFD_RELOC_AARCH64_JUMP26:
6117 /* If this is a local symbol then we resolve it
6118 directly without creating a PLT entry. */
6122 if (h->plt.refcount > 0)
6123 h->plt.refcount -= 1;
6126 case BFD_RELOC_AARCH64_ADR_HI21_NC_PCREL:
6127 case BFD_RELOC_AARCH64_ADR_HI21_PCREL:
6128 case BFD_RELOC_AARCH64_ADR_LO21_PCREL:
6129 case BFD_RELOC_AARCH64_MOVW_G0_NC:
6130 case BFD_RELOC_AARCH64_MOVW_G1_NC:
6131 case BFD_RELOC_AARCH64_MOVW_G2_NC:
6132 case BFD_RELOC_AARCH64_MOVW_G3:
6133 case BFD_RELOC_AARCH64_NN:
6134 if (h != NULL && bfd_link_executable (info))
6136 if (h->plt.refcount > 0)
6137 h->plt.refcount -= 1;
6149 /* Adjust a symbol defined by a dynamic object and referenced by a
6150 regular object. The current definition is in some section of the
6151 dynamic object, but we're not including those sections. We have to
6152 change the definition to something the rest of the link can
6156 elfNN_aarch64_adjust_dynamic_symbol (struct bfd_link_info *info,
6157 struct elf_link_hash_entry *h)
6159 struct elf_aarch64_link_hash_table *htab;
6162 /* If this is a function, put it in the procedure linkage table. We
6163 will fill in the contents of the procedure linkage table later,
6164 when we know the address of the .got section. */
6165 if (h->type == STT_FUNC || h->type == STT_GNU_IFUNC || h->needs_plt)
6167 if (h->plt.refcount <= 0
6168 || (h->type != STT_GNU_IFUNC
6169 && (SYMBOL_CALLS_LOCAL (info, h)
6170 || (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
6171 && h->root.type == bfd_link_hash_undefweak))))
6173 /* This case can occur if we saw a CALL26 reloc in
6174 an input file, but the symbol wasn't referred to
6175 by a dynamic object or all references were
6176 garbage collected. In which case we can end up
6178 h->plt.offset = (bfd_vma) - 1;
6185 /* Otherwise, reset to -1. */
6186 h->plt.offset = (bfd_vma) - 1;
6189 /* If this is a weak symbol, and there is a real definition, the
6190 processor independent code will have arranged for us to see the
6191 real definition first, and we can just use the same value. */
6192 if (h->u.weakdef != NULL)
6194 BFD_ASSERT (h->u.weakdef->root.type == bfd_link_hash_defined
6195 || h->u.weakdef->root.type == bfd_link_hash_defweak);
6196 h->root.u.def.section = h->u.weakdef->root.u.def.section;
6197 h->root.u.def.value = h->u.weakdef->root.u.def.value;
6198 if (ELIMINATE_COPY_RELOCS || info->nocopyreloc)
6199 h->non_got_ref = h->u.weakdef->non_got_ref;
6203 /* If we are creating a shared library, we must presume that the
6204 only references to the symbol are via the global offset table.
6205 For such cases we need not do anything here; the relocations will
6206 be handled correctly by relocate_section. */
6207 if (bfd_link_pic (info))
6210 /* If there are no references to this symbol that do not use the
6211 GOT, we don't need to generate a copy reloc. */
6212 if (!h->non_got_ref)
6215 /* If -z nocopyreloc was given, we won't generate them either. */
6216 if (info->nocopyreloc)
6222 /* We must allocate the symbol in our .dynbss section, which will
6223 become part of the .bss section of the executable. There will be
6224 an entry for this symbol in the .dynsym section. The dynamic
6225 object will contain position independent code, so all references
6226 from the dynamic object to this symbol will go through the global
6227 offset table. The dynamic linker will use the .dynsym entry to
6228 determine the address it must put in the global offset table, so
6229 both the dynamic object and the regular object will refer to the
6230 same memory location for the variable. */
6232 htab = elf_aarch64_hash_table (info);
6234 /* We must generate a R_AARCH64_COPY reloc to tell the dynamic linker
6235 to copy the initial value out of the dynamic object and into the
6236 runtime process image. */
6237 if ((h->root.u.def.section->flags & SEC_ALLOC) != 0 && h->size != 0)
6239 htab->srelbss->size += RELOC_SIZE (htab);
6245 return _bfd_elf_adjust_dynamic_copy (info, h, s);
6250 elfNN_aarch64_allocate_local_symbols (bfd *abfd, unsigned number)
6252 struct elf_aarch64_local_symbol *locals;
6253 locals = elf_aarch64_locals (abfd);
6256 locals = (struct elf_aarch64_local_symbol *)
6257 bfd_zalloc (abfd, number * sizeof (struct elf_aarch64_local_symbol));
6260 elf_aarch64_locals (abfd) = locals;
6265 /* Create the .got section to hold the global offset table. */
6268 aarch64_elf_create_got_section (bfd *abfd, struct bfd_link_info *info)
6270 const struct elf_backend_data *bed = get_elf_backend_data (abfd);
6273 struct elf_link_hash_entry *h;
6274 struct elf_link_hash_table *htab = elf_hash_table (info);
6276 /* This function may be called more than once. */
6277 s = bfd_get_linker_section (abfd, ".got");
6281 flags = bed->dynamic_sec_flags;
6283 s = bfd_make_section_anyway_with_flags (abfd,
6284 (bed->rela_plts_and_copies_p
6285 ? ".rela.got" : ".rel.got"),
6286 (bed->dynamic_sec_flags
6289 || ! bfd_set_section_alignment (abfd, s, bed->s->log_file_align))
6293 s = bfd_make_section_anyway_with_flags (abfd, ".got", flags);
6295 || !bfd_set_section_alignment (abfd, s, bed->s->log_file_align))
6298 htab->sgot->size += GOT_ENTRY_SIZE;
6300 if (bed->want_got_sym)
6302 /* Define the symbol _GLOBAL_OFFSET_TABLE_ at the start of the .got
6303 (or .got.plt) section. We don't do this in the linker script
6304 because we don't want to define the symbol if we are not creating
6305 a global offset table. */
6306 h = _bfd_elf_define_linkage_sym (abfd, info, s,
6307 "_GLOBAL_OFFSET_TABLE_");
6308 elf_hash_table (info)->hgot = h;
6313 if (bed->want_got_plt)
6315 s = bfd_make_section_anyway_with_flags (abfd, ".got.plt", flags);
6317 || !bfd_set_section_alignment (abfd, s,
6318 bed->s->log_file_align))
6323 /* The first bit of the global offset table is the header. */
6324 s->size += bed->got_header_size;
6329 /* Look through the relocs for a section during the first phase. */
6332 elfNN_aarch64_check_relocs (bfd *abfd, struct bfd_link_info *info,
6333 asection *sec, const Elf_Internal_Rela *relocs)
6335 Elf_Internal_Shdr *symtab_hdr;
6336 struct elf_link_hash_entry **sym_hashes;
6337 const Elf_Internal_Rela *rel;
6338 const Elf_Internal_Rela *rel_end;
6341 struct elf_aarch64_link_hash_table *htab;
6343 if (bfd_link_relocatable (info))
6346 BFD_ASSERT (is_aarch64_elf (abfd));
6348 htab = elf_aarch64_hash_table (info);
6351 symtab_hdr = &elf_symtab_hdr (abfd);
6352 sym_hashes = elf_sym_hashes (abfd);
6354 rel_end = relocs + sec->reloc_count;
6355 for (rel = relocs; rel < rel_end; rel++)
6357 struct elf_link_hash_entry *h;
6358 unsigned long r_symndx;
6359 unsigned int r_type;
6360 bfd_reloc_code_real_type bfd_r_type;
6361 Elf_Internal_Sym *isym;
6363 r_symndx = ELFNN_R_SYM (rel->r_info);
6364 r_type = ELFNN_R_TYPE (rel->r_info);
6366 if (r_symndx >= NUM_SHDR_ENTRIES (symtab_hdr))
6368 (*_bfd_error_handler) (_("%B: bad symbol index: %d"), abfd,
6373 if (r_symndx < symtab_hdr->sh_info)
6375 /* A local symbol. */
6376 isym = bfd_sym_from_r_symndx (&htab->sym_cache,
6381 /* Check relocation against local STT_GNU_IFUNC symbol. */
6382 if (ELF_ST_TYPE (isym->st_info) == STT_GNU_IFUNC)
6384 h = elfNN_aarch64_get_local_sym_hash (htab, abfd, rel,
6389 /* Fake a STT_GNU_IFUNC symbol. */
6390 h->type = STT_GNU_IFUNC;
6393 h->forced_local = 1;
6394 h->root.type = bfd_link_hash_defined;
6401 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
6402 while (h->root.type == bfd_link_hash_indirect
6403 || h->root.type == bfd_link_hash_warning)
6404 h = (struct elf_link_hash_entry *) h->root.u.i.link;
6406 /* PR15323, ref flags aren't set for references in the same
6408 h->root.non_ir_ref = 1;
6411 /* Could be done earlier, if h were already available. */
6412 bfd_r_type = aarch64_tls_transition (abfd, info, r_type, h, r_symndx);
6416 /* Create the ifunc sections for static executables. If we
6417 never see an indirect function symbol nor we are building
6418 a static executable, those sections will be empty and
6419 won't appear in output. */
6425 case BFD_RELOC_AARCH64_ADD_LO12:
6426 case BFD_RELOC_AARCH64_ADR_GOT_PAGE:
6427 case BFD_RELOC_AARCH64_ADR_HI21_PCREL:
6428 case BFD_RELOC_AARCH64_CALL26:
6429 case BFD_RELOC_AARCH64_GOT_LD_PREL19:
6430 case BFD_RELOC_AARCH64_JUMP26:
6431 case BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14:
6432 case BFD_RELOC_AARCH64_LD32_GOT_LO12_NC:
6433 case BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15:
6434 case BFD_RELOC_AARCH64_LD64_GOT_LO12_NC:
6435 case BFD_RELOC_AARCH64_NN:
6436 if (htab->root.dynobj == NULL)
6437 htab->root.dynobj = abfd;
6438 if (!_bfd_elf_create_ifunc_sections (htab->root.dynobj, info))
6443 /* It is referenced by a non-shared object. */
6445 h->root.non_ir_ref = 1;
6450 case BFD_RELOC_AARCH64_NN:
6452 /* We don't need to handle relocs into sections not going into
6453 the "real" output. */
6454 if ((sec->flags & SEC_ALLOC) == 0)
6459 if (!bfd_link_pic (info))
6462 h->plt.refcount += 1;
6463 h->pointer_equality_needed = 1;
6466 /* No need to do anything if we're not creating a shared
6468 if (! bfd_link_pic (info))
6472 struct elf_dyn_relocs *p;
6473 struct elf_dyn_relocs **head;
6475 /* We must copy these reloc types into the output file.
6476 Create a reloc section in dynobj and make room for
6480 if (htab->root.dynobj == NULL)
6481 htab->root.dynobj = abfd;
6483 sreloc = _bfd_elf_make_dynamic_reloc_section
6484 (sec, htab->root.dynobj, LOG_FILE_ALIGN, abfd, /*rela? */ TRUE);
6490 /* If this is a global symbol, we count the number of
6491 relocations we need for this symbol. */
6494 struct elf_aarch64_link_hash_entry *eh;
6495 eh = (struct elf_aarch64_link_hash_entry *) h;
6496 head = &eh->dyn_relocs;
6500 /* Track dynamic relocs needed for local syms too.
6501 We really need local syms available to do this
6507 isym = bfd_sym_from_r_symndx (&htab->sym_cache,
6512 s = bfd_section_from_elf_index (abfd, isym->st_shndx);
6516 /* Beware of type punned pointers vs strict aliasing
6518 vpp = &(elf_section_data (s)->local_dynrel);
6519 head = (struct elf_dyn_relocs **) vpp;
6523 if (p == NULL || p->sec != sec)
6525 bfd_size_type amt = sizeof *p;
6526 p = ((struct elf_dyn_relocs *)
6527 bfd_zalloc (htab->root.dynobj, amt));
6540 /* RR: We probably want to keep a consistency check that
6541 there are no dangling GOT_PAGE relocs. */
6542 case BFD_RELOC_AARCH64_ADR_GOT_PAGE:
6543 case BFD_RELOC_AARCH64_GOT_LD_PREL19:
6544 case BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14:
6545 case BFD_RELOC_AARCH64_LD32_GOT_LO12_NC:
6546 case BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15:
6547 case BFD_RELOC_AARCH64_LD64_GOT_LO12_NC:
6548 case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12_NC:
6549 case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21:
6550 case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21:
6551 case BFD_RELOC_AARCH64_TLSDESC_LD32_LO12_NC:
6552 case BFD_RELOC_AARCH64_TLSDESC_LD64_LO12_NC:
6553 case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19:
6554 case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC:
6555 case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21:
6556 case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21:
6557 case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21:
6558 case BFD_RELOC_AARCH64_TLSIE_LD32_GOTTPREL_LO12_NC:
6559 case BFD_RELOC_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC:
6560 case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19:
6561 case BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC:
6562 case BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21:
6563 case BFD_RELOC_AARCH64_TLSLD_ADR_PREL21:
6566 unsigned old_got_type;
6568 got_type = aarch64_reloc_got_type (bfd_r_type);
6572 h->got.refcount += 1;
6573 old_got_type = elf_aarch64_hash_entry (h)->got_type;
6577 struct elf_aarch64_local_symbol *locals;
6579 if (!elfNN_aarch64_allocate_local_symbols
6580 (abfd, symtab_hdr->sh_info))
6583 locals = elf_aarch64_locals (abfd);
6584 BFD_ASSERT (r_symndx < symtab_hdr->sh_info);
6585 locals[r_symndx].got_refcount += 1;
6586 old_got_type = locals[r_symndx].got_type;
6589 /* If a variable is accessed with both general dynamic TLS
6590 methods, two slots may be created. */
6591 if (GOT_TLS_GD_ANY_P (old_got_type) && GOT_TLS_GD_ANY_P (got_type))
6592 got_type |= old_got_type;
6594 /* We will already have issued an error message if there
6595 is a TLS/non-TLS mismatch, based on the symbol type.
6596 So just combine any TLS types needed. */
6597 if (old_got_type != GOT_UNKNOWN && old_got_type != GOT_NORMAL
6598 && got_type != GOT_NORMAL)
6599 got_type |= old_got_type;
6601 /* If the symbol is accessed by both IE and GD methods, we
6602 are able to relax. Turn off the GD flag, without
6603 messing up with any other kind of TLS types that may be
6605 if ((got_type & GOT_TLS_IE) && GOT_TLS_GD_ANY_P (got_type))
6606 got_type &= ~ (GOT_TLSDESC_GD | GOT_TLS_GD);
6608 if (old_got_type != got_type)
6611 elf_aarch64_hash_entry (h)->got_type = got_type;
6614 struct elf_aarch64_local_symbol *locals;
6615 locals = elf_aarch64_locals (abfd);
6616 BFD_ASSERT (r_symndx < symtab_hdr->sh_info);
6617 locals[r_symndx].got_type = got_type;
6621 if (htab->root.dynobj == NULL)
6622 htab->root.dynobj = abfd;
6623 if (! aarch64_elf_create_got_section (htab->root.dynobj, info))
6628 case BFD_RELOC_AARCH64_MOVW_G0_NC:
6629 case BFD_RELOC_AARCH64_MOVW_G1_NC:
6630 case BFD_RELOC_AARCH64_MOVW_G2_NC:
6631 case BFD_RELOC_AARCH64_MOVW_G3:
6632 if (bfd_link_pic (info))
6634 int howto_index = bfd_r_type - BFD_RELOC_AARCH64_RELOC_START;
6635 (*_bfd_error_handler)
6636 (_("%B: relocation %s against `%s' can not be used when making "
6637 "a shared object; recompile with -fPIC"),
6638 abfd, elfNN_aarch64_howto_table[howto_index].name,
6639 (h) ? h->root.root.string : "a local symbol");
6640 bfd_set_error (bfd_error_bad_value);
6644 case BFD_RELOC_AARCH64_ADR_HI21_NC_PCREL:
6645 case BFD_RELOC_AARCH64_ADR_HI21_PCREL:
6646 case BFD_RELOC_AARCH64_ADR_LO21_PCREL:
6647 if (h != NULL && bfd_link_executable (info))
6649 /* If this reloc is in a read-only section, we might
6650 need a copy reloc. We can't check reliably at this
6651 stage whether the section is read-only, as input
6652 sections have not yet been mapped to output sections.
6653 Tentatively set the flag for now, and correct in
6654 adjust_dynamic_symbol. */
6656 h->plt.refcount += 1;
6657 h->pointer_equality_needed = 1;
6659 /* FIXME:: RR need to handle these in shared libraries
6660 and essentially bomb out as these being non-PIC
6661 relocations in shared libraries. */
6664 case BFD_RELOC_AARCH64_CALL26:
6665 case BFD_RELOC_AARCH64_JUMP26:
6666 /* If this is a local symbol then we resolve it
6667 directly without creating a PLT entry. */
6672 if (h->plt.refcount <= 0)
6673 h->plt.refcount = 1;
6675 h->plt.refcount += 1;
6686 /* Treat mapping symbols as special target symbols. */
6689 elfNN_aarch64_is_target_special_symbol (bfd *abfd ATTRIBUTE_UNUSED,
6692 return bfd_is_aarch64_special_symbol_name (sym->name,
6693 BFD_AARCH64_SPECIAL_SYM_TYPE_ANY);
6696 /* This is a copy of elf_find_function () from elf.c except that
6697 AArch64 mapping symbols are ignored when looking for function names. */
6700 aarch64_elf_find_function (bfd *abfd ATTRIBUTE_UNUSED,
6704 const char **filename_ptr,
6705 const char **functionname_ptr)
6707 const char *filename = NULL;
6708 asymbol *func = NULL;
6709 bfd_vma low_func = 0;
6712 for (p = symbols; *p != NULL; p++)
6716 q = (elf_symbol_type *) * p;
6718 switch (ELF_ST_TYPE (q->internal_elf_sym.st_info))
6723 filename = bfd_asymbol_name (&q->symbol);
6727 /* Skip mapping symbols. */
6728 if ((q->symbol.flags & BSF_LOCAL)
6729 && (bfd_is_aarch64_special_symbol_name
6730 (q->symbol.name, BFD_AARCH64_SPECIAL_SYM_TYPE_ANY)))
6733 if (bfd_get_section (&q->symbol) == section
6734 && q->symbol.value >= low_func && q->symbol.value <= offset)
6736 func = (asymbol *) q;
6737 low_func = q->symbol.value;
6747 *filename_ptr = filename;
6748 if (functionname_ptr)
6749 *functionname_ptr = bfd_asymbol_name (func);
6755 /* Find the nearest line to a particular section and offset, for error
6756 reporting. This code is a duplicate of the code in elf.c, except
6757 that it uses aarch64_elf_find_function. */
6760 elfNN_aarch64_find_nearest_line (bfd *abfd,
6764 const char **filename_ptr,
6765 const char **functionname_ptr,
6766 unsigned int *line_ptr,
6767 unsigned int *discriminator_ptr)
6769 bfd_boolean found = FALSE;
6771 if (_bfd_dwarf2_find_nearest_line (abfd, symbols, NULL, section, offset,
6772 filename_ptr, functionname_ptr,
6773 line_ptr, discriminator_ptr,
6774 dwarf_debug_sections, 0,
6775 &elf_tdata (abfd)->dwarf2_find_line_info))
6777 if (!*functionname_ptr)
6778 aarch64_elf_find_function (abfd, symbols, section, offset,
6779 *filename_ptr ? NULL : filename_ptr,
6785 /* Skip _bfd_dwarf1_find_nearest_line since no known AArch64
6786 toolchain uses DWARF1. */
6788 if (!_bfd_stab_section_find_nearest_line (abfd, symbols, section, offset,
6789 &found, filename_ptr,
6790 functionname_ptr, line_ptr,
6791 &elf_tdata (abfd)->line_info))
6794 if (found && (*functionname_ptr || *line_ptr))
6797 if (symbols == NULL)
6800 if (!aarch64_elf_find_function (abfd, symbols, section, offset,
6801 filename_ptr, functionname_ptr))
6809 elfNN_aarch64_find_inliner_info (bfd *abfd,
6810 const char **filename_ptr,
6811 const char **functionname_ptr,
6812 unsigned int *line_ptr)
6815 found = _bfd_dwarf2_find_inliner_info
6816 (abfd, filename_ptr,
6817 functionname_ptr, line_ptr, &elf_tdata (abfd)->dwarf2_find_line_info);
6823 elfNN_aarch64_post_process_headers (bfd *abfd,
6824 struct bfd_link_info *link_info)
6826 Elf_Internal_Ehdr *i_ehdrp; /* ELF file header, internal form. */
6828 i_ehdrp = elf_elfheader (abfd);
6829 i_ehdrp->e_ident[EI_ABIVERSION] = AARCH64_ELF_ABI_VERSION;
6831 _bfd_elf_post_process_headers (abfd, link_info);
6834 static enum elf_reloc_type_class
6835 elfNN_aarch64_reloc_type_class (const struct bfd_link_info *info ATTRIBUTE_UNUSED,
6836 const asection *rel_sec ATTRIBUTE_UNUSED,
6837 const Elf_Internal_Rela *rela)
6839 switch ((int) ELFNN_R_TYPE (rela->r_info))
6841 case AARCH64_R (RELATIVE):
6842 return reloc_class_relative;
6843 case AARCH64_R (JUMP_SLOT):
6844 return reloc_class_plt;
6845 case AARCH64_R (COPY):
6846 return reloc_class_copy;
6848 return reloc_class_normal;
6852 /* Handle an AArch64 specific section when reading an object file. This is
6853 called when bfd_section_from_shdr finds a section with an unknown
6857 elfNN_aarch64_section_from_shdr (bfd *abfd,
6858 Elf_Internal_Shdr *hdr,
6859 const char *name, int shindex)
6861 /* There ought to be a place to keep ELF backend specific flags, but
6862 at the moment there isn't one. We just keep track of the
6863 sections by their name, instead. Fortunately, the ABI gives
6864 names for all the AArch64 specific sections, so we will probably get
6866 switch (hdr->sh_type)
6868 case SHT_AARCH64_ATTRIBUTES:
6875 if (!_bfd_elf_make_section_from_shdr (abfd, hdr, name, shindex))
6881 /* A structure used to record a list of sections, independently
6882 of the next and prev fields in the asection structure. */
6883 typedef struct section_list
6886 struct section_list *next;
6887 struct section_list *prev;
6891 /* Unfortunately we need to keep a list of sections for which
6892 an _aarch64_elf_section_data structure has been allocated. This
6893 is because it is possible for functions like elfNN_aarch64_write_section
6894 to be called on a section which has had an elf_data_structure
6895 allocated for it (and so the used_by_bfd field is valid) but
6896 for which the AArch64 extended version of this structure - the
6897 _aarch64_elf_section_data structure - has not been allocated. */
6898 static section_list *sections_with_aarch64_elf_section_data = NULL;
6901 record_section_with_aarch64_elf_section_data (asection *sec)
6903 struct section_list *entry;
6905 entry = bfd_malloc (sizeof (*entry));
6909 entry->next = sections_with_aarch64_elf_section_data;
6911 if (entry->next != NULL)
6912 entry->next->prev = entry;
6913 sections_with_aarch64_elf_section_data = entry;
6916 static struct section_list *
6917 find_aarch64_elf_section_entry (asection *sec)
6919 struct section_list *entry;
6920 static struct section_list *last_entry = NULL;
6922 /* This is a short cut for the typical case where the sections are added
6923 to the sections_with_aarch64_elf_section_data list in forward order and
6924 then looked up here in backwards order. This makes a real difference
6925 to the ld-srec/sec64k.exp linker test. */
6926 entry = sections_with_aarch64_elf_section_data;
6927 if (last_entry != NULL)
6929 if (last_entry->sec == sec)
6931 else if (last_entry->next != NULL && last_entry->next->sec == sec)
6932 entry = last_entry->next;
6935 for (; entry; entry = entry->next)
6936 if (entry->sec == sec)
6940 /* Record the entry prior to this one - it is the entry we are
6941 most likely to want to locate next time. Also this way if we
6942 have been called from
6943 unrecord_section_with_aarch64_elf_section_data () we will not
6944 be caching a pointer that is about to be freed. */
6945 last_entry = entry->prev;
6951 unrecord_section_with_aarch64_elf_section_data (asection *sec)
6953 struct section_list *entry;
6955 entry = find_aarch64_elf_section_entry (sec);
6959 if (entry->prev != NULL)
6960 entry->prev->next = entry->next;
6961 if (entry->next != NULL)
6962 entry->next->prev = entry->prev;
6963 if (entry == sections_with_aarch64_elf_section_data)
6964 sections_with_aarch64_elf_section_data = entry->next;
6973 struct bfd_link_info *info;
6976 int (*func) (void *, const char *, Elf_Internal_Sym *,
6977 asection *, struct elf_link_hash_entry *);
6978 } output_arch_syminfo;
6980 enum map_symbol_type
6987 /* Output a single mapping symbol. */
6990 elfNN_aarch64_output_map_sym (output_arch_syminfo *osi,
6991 enum map_symbol_type type, bfd_vma offset)
6993 static const char *names[2] = { "$x", "$d" };
6994 Elf_Internal_Sym sym;
6996 sym.st_value = (osi->sec->output_section->vma
6997 + osi->sec->output_offset + offset);
7000 sym.st_info = ELF_ST_INFO (STB_LOCAL, STT_NOTYPE);
7001 sym.st_shndx = osi->sec_shndx;
7002 return osi->func (osi->finfo, names[type], &sym, osi->sec, NULL) == 1;
7007 /* Output mapping symbols for PLT entries associated with H. */
7010 elfNN_aarch64_output_plt_map (struct elf_link_hash_entry *h, void *inf)
7012 output_arch_syminfo *osi = (output_arch_syminfo *) inf;
7015 if (h->root.type == bfd_link_hash_indirect)
7018 if (h->root.type == bfd_link_hash_warning)
7019 /* When warning symbols are created, they **replace** the "real"
7020 entry in the hash table, thus we never get to see the real
7021 symbol in a hash traversal. So look at it now. */
7022 h = (struct elf_link_hash_entry *) h->root.u.i.link;
7024 if (h->plt.offset == (bfd_vma) - 1)
7027 addr = h->plt.offset;
7030 if (!elfNN_aarch64_output_map_sym (osi, AARCH64_MAP_INSN, addr))
7037 /* Output a single local symbol for a generated stub. */
7040 elfNN_aarch64_output_stub_sym (output_arch_syminfo *osi, const char *name,
7041 bfd_vma offset, bfd_vma size)
7043 Elf_Internal_Sym sym;
7045 sym.st_value = (osi->sec->output_section->vma
7046 + osi->sec->output_offset + offset);
7049 sym.st_info = ELF_ST_INFO (STB_LOCAL, STT_FUNC);
7050 sym.st_shndx = osi->sec_shndx;
7051 return osi->func (osi->finfo, name, &sym, osi->sec, NULL) == 1;
7055 aarch64_map_one_stub (struct bfd_hash_entry *gen_entry, void *in_arg)
7057 struct elf_aarch64_stub_hash_entry *stub_entry;
7061 output_arch_syminfo *osi;
7063 /* Massage our args to the form they really have. */
7064 stub_entry = (struct elf_aarch64_stub_hash_entry *) gen_entry;
7065 osi = (output_arch_syminfo *) in_arg;
7067 stub_sec = stub_entry->stub_sec;
7069 /* Ensure this stub is attached to the current section being
7071 if (stub_sec != osi->sec)
7074 addr = (bfd_vma) stub_entry->stub_offset;
7076 stub_name = stub_entry->output_name;
7078 switch (stub_entry->stub_type)
7080 case aarch64_stub_adrp_branch:
7081 if (!elfNN_aarch64_output_stub_sym (osi, stub_name, addr,
7082 sizeof (aarch64_adrp_branch_stub)))
7084 if (!elfNN_aarch64_output_map_sym (osi, AARCH64_MAP_INSN, addr))
7087 case aarch64_stub_long_branch:
7088 if (!elfNN_aarch64_output_stub_sym
7089 (osi, stub_name, addr, sizeof (aarch64_long_branch_stub)))
7091 if (!elfNN_aarch64_output_map_sym (osi, AARCH64_MAP_INSN, addr))
7093 if (!elfNN_aarch64_output_map_sym (osi, AARCH64_MAP_DATA, addr + 16))
7096 case aarch64_stub_erratum_835769_veneer:
7097 if (!elfNN_aarch64_output_stub_sym (osi, stub_name, addr,
7098 sizeof (aarch64_erratum_835769_stub)))
7100 if (!elfNN_aarch64_output_map_sym (osi, AARCH64_MAP_INSN, addr))
7103 case aarch64_stub_erratum_843419_veneer:
7104 if (!elfNN_aarch64_output_stub_sym (osi, stub_name, addr,
7105 sizeof (aarch64_erratum_843419_stub)))
7107 if (!elfNN_aarch64_output_map_sym (osi, AARCH64_MAP_INSN, addr))
7118 /* Output mapping symbols for linker generated sections. */
7121 elfNN_aarch64_output_arch_local_syms (bfd *output_bfd,
7122 struct bfd_link_info *info,
7124 int (*func) (void *, const char *,
7127 struct elf_link_hash_entry
7130 output_arch_syminfo osi;
7131 struct elf_aarch64_link_hash_table *htab;
7133 htab = elf_aarch64_hash_table (info);
7139 /* Long calls stubs. */
7140 if (htab->stub_bfd && htab->stub_bfd->sections)
7144 for (stub_sec = htab->stub_bfd->sections;
7145 stub_sec != NULL; stub_sec = stub_sec->next)
7147 /* Ignore non-stub sections. */
7148 if (!strstr (stub_sec->name, STUB_SUFFIX))
7153 osi.sec_shndx = _bfd_elf_section_from_bfd_section
7154 (output_bfd, osi.sec->output_section);
7156 /* The first instruction in a stub is always a branch. */
7157 if (!elfNN_aarch64_output_map_sym (&osi, AARCH64_MAP_INSN, 0))
7160 bfd_hash_traverse (&htab->stub_hash_table, aarch64_map_one_stub,
7165 /* Finally, output mapping symbols for the PLT. */
7166 if (!htab->root.splt || htab->root.splt->size == 0)
7169 /* For now live without mapping symbols for the plt. */
7170 osi.sec_shndx = _bfd_elf_section_from_bfd_section
7171 (output_bfd, htab->root.splt->output_section);
7172 osi.sec = htab->root.splt;
7174 elf_link_hash_traverse (&htab->root, elfNN_aarch64_output_plt_map,
7181 /* Allocate target specific section data. */
7184 elfNN_aarch64_new_section_hook (bfd *abfd, asection *sec)
7186 if (!sec->used_by_bfd)
7188 _aarch64_elf_section_data *sdata;
7189 bfd_size_type amt = sizeof (*sdata);
7191 sdata = bfd_zalloc (abfd, amt);
7194 sec->used_by_bfd = sdata;
7197 record_section_with_aarch64_elf_section_data (sec);
7199 return _bfd_elf_new_section_hook (abfd, sec);
7204 unrecord_section_via_map_over_sections (bfd *abfd ATTRIBUTE_UNUSED,
7206 void *ignore ATTRIBUTE_UNUSED)
7208 unrecord_section_with_aarch64_elf_section_data (sec);
7212 elfNN_aarch64_close_and_cleanup (bfd *abfd)
7215 bfd_map_over_sections (abfd,
7216 unrecord_section_via_map_over_sections, NULL);
7218 return _bfd_elf_close_and_cleanup (abfd);
7222 elfNN_aarch64_bfd_free_cached_info (bfd *abfd)
7225 bfd_map_over_sections (abfd,
7226 unrecord_section_via_map_over_sections, NULL);
7228 return _bfd_free_cached_info (abfd);
7231 /* Create dynamic sections. This is different from the ARM backend in that
7232 the got, plt, gotplt and their relocation sections are all created in the
7233 standard part of the bfd elf backend. */
7236 elfNN_aarch64_create_dynamic_sections (bfd *dynobj,
7237 struct bfd_link_info *info)
7239 struct elf_aarch64_link_hash_table *htab;
7241 /* We need to create .got section. */
7242 if (!aarch64_elf_create_got_section (dynobj, info))
7245 if (!_bfd_elf_create_dynamic_sections (dynobj, info))
7248 htab = elf_aarch64_hash_table (info);
7249 htab->sdynbss = bfd_get_linker_section (dynobj, ".dynbss");
7250 if (!bfd_link_pic (info))
7251 htab->srelbss = bfd_get_linker_section (dynobj, ".rela.bss");
7253 if (!htab->sdynbss || (!bfd_link_pic (info) && !htab->srelbss))
7260 /* Allocate space in .plt, .got and associated reloc sections for
7264 elfNN_aarch64_allocate_dynrelocs (struct elf_link_hash_entry *h, void *inf)
7266 struct bfd_link_info *info;
7267 struct elf_aarch64_link_hash_table *htab;
7268 struct elf_aarch64_link_hash_entry *eh;
7269 struct elf_dyn_relocs *p;
7271 /* An example of a bfd_link_hash_indirect symbol is versioned
7272 symbol. For example: __gxx_personality_v0(bfd_link_hash_indirect)
7273 -> __gxx_personality_v0(bfd_link_hash_defined)
7275 There is no need to process bfd_link_hash_indirect symbols here
7276 because we will also be presented with the concrete instance of
7277 the symbol and elfNN_aarch64_copy_indirect_symbol () will have been
7278 called to copy all relevant data from the generic to the concrete
7281 if (h->root.type == bfd_link_hash_indirect)
7284 if (h->root.type == bfd_link_hash_warning)
7285 h = (struct elf_link_hash_entry *) h->root.u.i.link;
7287 info = (struct bfd_link_info *) inf;
7288 htab = elf_aarch64_hash_table (info);
7290 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle it
7291 here if it is defined and referenced in a non-shared object. */
7292 if (h->type == STT_GNU_IFUNC
7295 else if (htab->root.dynamic_sections_created && h->plt.refcount > 0)
7297 /* Make sure this symbol is output as a dynamic symbol.
7298 Undefined weak syms won't yet be marked as dynamic. */
7299 if (h->dynindx == -1 && !h->forced_local)
7301 if (!bfd_elf_link_record_dynamic_symbol (info, h))
7305 if (bfd_link_pic (info) || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h))
7307 asection *s = htab->root.splt;
7309 /* If this is the first .plt entry, make room for the special
7312 s->size += htab->plt_header_size;
7314 h->plt.offset = s->size;
7316 /* If this symbol is not defined in a regular file, and we are
7317 not generating a shared library, then set the symbol to this
7318 location in the .plt. This is required to make function
7319 pointers compare as equal between the normal executable and
7320 the shared library. */
7321 if (!bfd_link_pic (info) && !h->def_regular)
7323 h->root.u.def.section = s;
7324 h->root.u.def.value = h->plt.offset;
7327 /* Make room for this entry. For now we only create the
7328 small model PLT entries. We later need to find a way
7329 of relaxing into these from the large model PLT entries. */
7330 s->size += PLT_SMALL_ENTRY_SIZE;
7332 /* We also need to make an entry in the .got.plt section, which
7333 will be placed in the .got section by the linker script. */
7334 htab->root.sgotplt->size += GOT_ENTRY_SIZE;
7336 /* We also need to make an entry in the .rela.plt section. */
7337 htab->root.srelplt->size += RELOC_SIZE (htab);
7339 /* We need to ensure that all GOT entries that serve the PLT
7340 are consecutive with the special GOT slots [0] [1] and
7341 [2]. Any addtional relocations, such as
7342 R_AARCH64_TLSDESC, must be placed after the PLT related
7343 entries. We abuse the reloc_count such that during
7344 sizing we adjust reloc_count to indicate the number of
7345 PLT related reserved entries. In subsequent phases when
7346 filling in the contents of the reloc entries, PLT related
7347 entries are placed by computing their PLT index (0
7348 .. reloc_count). While other none PLT relocs are placed
7349 at the slot indicated by reloc_count and reloc_count is
7352 htab->root.srelplt->reloc_count++;
7356 h->plt.offset = (bfd_vma) - 1;
7362 h->plt.offset = (bfd_vma) - 1;
7366 eh = (struct elf_aarch64_link_hash_entry *) h;
7367 eh->tlsdesc_got_jump_table_offset = (bfd_vma) - 1;
7369 if (h->got.refcount > 0)
7372 unsigned got_type = elf_aarch64_hash_entry (h)->got_type;
7374 h->got.offset = (bfd_vma) - 1;
7376 dyn = htab->root.dynamic_sections_created;
7378 /* Make sure this symbol is output as a dynamic symbol.
7379 Undefined weak syms won't yet be marked as dynamic. */
7380 if (dyn && h->dynindx == -1 && !h->forced_local)
7382 if (!bfd_elf_link_record_dynamic_symbol (info, h))
7386 if (got_type == GOT_UNKNOWN)
7389 else if (got_type == GOT_NORMAL)
7391 h->got.offset = htab->root.sgot->size;
7392 htab->root.sgot->size += GOT_ENTRY_SIZE;
7393 if ((ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
7394 || h->root.type != bfd_link_hash_undefweak)
7395 && (bfd_link_pic (info)
7396 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, 0, h)))
7398 htab->root.srelgot->size += RELOC_SIZE (htab);
7404 if (got_type & GOT_TLSDESC_GD)
7406 eh->tlsdesc_got_jump_table_offset =
7407 (htab->root.sgotplt->size
7408 - aarch64_compute_jump_table_size (htab));
7409 htab->root.sgotplt->size += GOT_ENTRY_SIZE * 2;
7410 h->got.offset = (bfd_vma) - 2;
7413 if (got_type & GOT_TLS_GD)
7415 h->got.offset = htab->root.sgot->size;
7416 htab->root.sgot->size += GOT_ENTRY_SIZE * 2;
7419 if (got_type & GOT_TLS_IE)
7421 h->got.offset = htab->root.sgot->size;
7422 htab->root.sgot->size += GOT_ENTRY_SIZE;
7425 indx = h && h->dynindx != -1 ? h->dynindx : 0;
7426 if ((ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
7427 || h->root.type != bfd_link_hash_undefweak)
7428 && (bfd_link_pic (info)
7430 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, 0, h)))
7432 if (got_type & GOT_TLSDESC_GD)
7434 htab->root.srelplt->size += RELOC_SIZE (htab);
7435 /* Note reloc_count not incremented here! We have
7436 already adjusted reloc_count for this relocation
7439 /* TLSDESC PLT is now needed, but not yet determined. */
7440 htab->tlsdesc_plt = (bfd_vma) - 1;
7443 if (got_type & GOT_TLS_GD)
7444 htab->root.srelgot->size += RELOC_SIZE (htab) * 2;
7446 if (got_type & GOT_TLS_IE)
7447 htab->root.srelgot->size += RELOC_SIZE (htab);
7453 h->got.offset = (bfd_vma) - 1;
7456 if (eh->dyn_relocs == NULL)
7459 /* In the shared -Bsymbolic case, discard space allocated for
7460 dynamic pc-relative relocs against symbols which turn out to be
7461 defined in regular objects. For the normal shared case, discard
7462 space for pc-relative relocs that have become local due to symbol
7463 visibility changes. */
7465 if (bfd_link_pic (info))
7467 /* Relocs that use pc_count are those that appear on a call
7468 insn, or certain REL relocs that can generated via assembly.
7469 We want calls to protected symbols to resolve directly to the
7470 function rather than going via the plt. If people want
7471 function pointer comparisons to work as expected then they
7472 should avoid writing weird assembly. */
7473 if (SYMBOL_CALLS_LOCAL (info, h))
7475 struct elf_dyn_relocs **pp;
7477 for (pp = &eh->dyn_relocs; (p = *pp) != NULL;)
7479 p->count -= p->pc_count;
7488 /* Also discard relocs on undefined weak syms with non-default
7490 if (eh->dyn_relocs != NULL && h->root.type == bfd_link_hash_undefweak)
7492 if (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT)
7493 eh->dyn_relocs = NULL;
7495 /* Make sure undefined weak symbols are output as a dynamic
7497 else if (h->dynindx == -1
7499 && !bfd_elf_link_record_dynamic_symbol (info, h))
7504 else if (ELIMINATE_COPY_RELOCS)
7506 /* For the non-shared case, discard space for relocs against
7507 symbols which turn out to need copy relocs or are not
7513 || (htab->root.dynamic_sections_created
7514 && (h->root.type == bfd_link_hash_undefweak
7515 || h->root.type == bfd_link_hash_undefined))))
7517 /* Make sure this symbol is output as a dynamic symbol.
7518 Undefined weak syms won't yet be marked as dynamic. */
7519 if (h->dynindx == -1
7521 && !bfd_elf_link_record_dynamic_symbol (info, h))
7524 /* If that succeeded, we know we'll be keeping all the
7526 if (h->dynindx != -1)
7530 eh->dyn_relocs = NULL;
7535 /* Finally, allocate space. */
7536 for (p = eh->dyn_relocs; p != NULL; p = p->next)
7540 sreloc = elf_section_data (p->sec)->sreloc;
7542 BFD_ASSERT (sreloc != NULL);
7544 sreloc->size += p->count * RELOC_SIZE (htab);
7550 /* Allocate space in .plt, .got and associated reloc sections for
7551 ifunc dynamic relocs. */
7554 elfNN_aarch64_allocate_ifunc_dynrelocs (struct elf_link_hash_entry *h,
7557 struct bfd_link_info *info;
7558 struct elf_aarch64_link_hash_table *htab;
7559 struct elf_aarch64_link_hash_entry *eh;
7561 /* An example of a bfd_link_hash_indirect symbol is versioned
7562 symbol. For example: __gxx_personality_v0(bfd_link_hash_indirect)
7563 -> __gxx_personality_v0(bfd_link_hash_defined)
7565 There is no need to process bfd_link_hash_indirect symbols here
7566 because we will also be presented with the concrete instance of
7567 the symbol and elfNN_aarch64_copy_indirect_symbol () will have been
7568 called to copy all relevant data from the generic to the concrete
7571 if (h->root.type == bfd_link_hash_indirect)
7574 if (h->root.type == bfd_link_hash_warning)
7575 h = (struct elf_link_hash_entry *) h->root.u.i.link;
7577 info = (struct bfd_link_info *) inf;
7578 htab = elf_aarch64_hash_table (info);
7580 eh = (struct elf_aarch64_link_hash_entry *) h;
7582 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle it
7583 here if it is defined and referenced in a non-shared object. */
7584 if (h->type == STT_GNU_IFUNC
7586 return _bfd_elf_allocate_ifunc_dyn_relocs (info, h,
7588 htab->plt_entry_size,
7589 htab->plt_header_size,
7594 /* Allocate space in .plt, .got and associated reloc sections for
7595 local dynamic relocs. */
7598 elfNN_aarch64_allocate_local_dynrelocs (void **slot, void *inf)
7600 struct elf_link_hash_entry *h
7601 = (struct elf_link_hash_entry *) *slot;
7603 if (h->type != STT_GNU_IFUNC
7607 || h->root.type != bfd_link_hash_defined)
7610 return elfNN_aarch64_allocate_dynrelocs (h, inf);
7613 /* Allocate space in .plt, .got and associated reloc sections for
7614 local ifunc dynamic relocs. */
7617 elfNN_aarch64_allocate_local_ifunc_dynrelocs (void **slot, void *inf)
7619 struct elf_link_hash_entry *h
7620 = (struct elf_link_hash_entry *) *slot;
7622 if (h->type != STT_GNU_IFUNC
7626 || h->root.type != bfd_link_hash_defined)
7629 return elfNN_aarch64_allocate_ifunc_dynrelocs (h, inf);
7632 /* Find any dynamic relocs that apply to read-only sections. */
7635 aarch64_readonly_dynrelocs (struct elf_link_hash_entry * h, void * inf)
7637 struct elf_aarch64_link_hash_entry * eh;
7638 struct elf_dyn_relocs * p;
7640 eh = (struct elf_aarch64_link_hash_entry *) h;
7641 for (p = eh->dyn_relocs; p != NULL; p = p->next)
7643 asection *s = p->sec;
7645 if (s != NULL && (s->flags & SEC_READONLY) != 0)
7647 struct bfd_link_info *info = (struct bfd_link_info *) inf;
7649 info->flags |= DF_TEXTREL;
7651 /* Not an error, just cut short the traversal. */
7658 /* This is the most important function of all . Innocuosly named
7661 elfNN_aarch64_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
7662 struct bfd_link_info *info)
7664 struct elf_aarch64_link_hash_table *htab;
7670 htab = elf_aarch64_hash_table ((info));
7671 dynobj = htab->root.dynobj;
7673 BFD_ASSERT (dynobj != NULL);
7675 if (htab->root.dynamic_sections_created)
7677 if (bfd_link_executable (info))
7679 s = bfd_get_linker_section (dynobj, ".interp");
7682 s->size = sizeof ELF_DYNAMIC_INTERPRETER;
7683 s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
7687 /* Set up .got offsets for local syms, and space for local dynamic
7689 for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link.next)
7691 struct elf_aarch64_local_symbol *locals = NULL;
7692 Elf_Internal_Shdr *symtab_hdr;
7696 if (!is_aarch64_elf (ibfd))
7699 for (s = ibfd->sections; s != NULL; s = s->next)
7701 struct elf_dyn_relocs *p;
7703 for (p = (struct elf_dyn_relocs *)
7704 (elf_section_data (s)->local_dynrel); p != NULL; p = p->next)
7706 if (!bfd_is_abs_section (p->sec)
7707 && bfd_is_abs_section (p->sec->output_section))
7709 /* Input section has been discarded, either because
7710 it is a copy of a linkonce section or due to
7711 linker script /DISCARD/, so we'll be discarding
7714 else if (p->count != 0)
7716 srel = elf_section_data (p->sec)->sreloc;
7717 srel->size += p->count * RELOC_SIZE (htab);
7718 if ((p->sec->output_section->flags & SEC_READONLY) != 0)
7719 info->flags |= DF_TEXTREL;
7724 locals = elf_aarch64_locals (ibfd);
7728 symtab_hdr = &elf_symtab_hdr (ibfd);
7729 srel = htab->root.srelgot;
7730 for (i = 0; i < symtab_hdr->sh_info; i++)
7732 locals[i].got_offset = (bfd_vma) - 1;
7733 locals[i].tlsdesc_got_jump_table_offset = (bfd_vma) - 1;
7734 if (locals[i].got_refcount > 0)
7736 unsigned got_type = locals[i].got_type;
7737 if (got_type & GOT_TLSDESC_GD)
7739 locals[i].tlsdesc_got_jump_table_offset =
7740 (htab->root.sgotplt->size
7741 - aarch64_compute_jump_table_size (htab));
7742 htab->root.sgotplt->size += GOT_ENTRY_SIZE * 2;
7743 locals[i].got_offset = (bfd_vma) - 2;
7746 if (got_type & GOT_TLS_GD)
7748 locals[i].got_offset = htab->root.sgot->size;
7749 htab->root.sgot->size += GOT_ENTRY_SIZE * 2;
7752 if (got_type & GOT_TLS_IE
7753 || got_type & GOT_NORMAL)
7755 locals[i].got_offset = htab->root.sgot->size;
7756 htab->root.sgot->size += GOT_ENTRY_SIZE;
7759 if (got_type == GOT_UNKNOWN)
7763 if (bfd_link_pic (info))
7765 if (got_type & GOT_TLSDESC_GD)
7767 htab->root.srelplt->size += RELOC_SIZE (htab);
7768 /* Note RELOC_COUNT not incremented here! */
7769 htab->tlsdesc_plt = (bfd_vma) - 1;
7772 if (got_type & GOT_TLS_GD)
7773 htab->root.srelgot->size += RELOC_SIZE (htab) * 2;
7775 if (got_type & GOT_TLS_IE
7776 || got_type & GOT_NORMAL)
7777 htab->root.srelgot->size += RELOC_SIZE (htab);
7782 locals[i].got_refcount = (bfd_vma) - 1;
7788 /* Allocate global sym .plt and .got entries, and space for global
7789 sym dynamic relocs. */
7790 elf_link_hash_traverse (&htab->root, elfNN_aarch64_allocate_dynrelocs,
7793 /* Allocate global ifunc sym .plt and .got entries, and space for global
7794 ifunc sym dynamic relocs. */
7795 elf_link_hash_traverse (&htab->root, elfNN_aarch64_allocate_ifunc_dynrelocs,
7798 /* Allocate .plt and .got entries, and space for local symbols. */
7799 htab_traverse (htab->loc_hash_table,
7800 elfNN_aarch64_allocate_local_dynrelocs,
7803 /* Allocate .plt and .got entries, and space for local ifunc symbols. */
7804 htab_traverse (htab->loc_hash_table,
7805 elfNN_aarch64_allocate_local_ifunc_dynrelocs,
7808 /* For every jump slot reserved in the sgotplt, reloc_count is
7809 incremented. However, when we reserve space for TLS descriptors,
7810 it's not incremented, so in order to compute the space reserved
7811 for them, it suffices to multiply the reloc count by the jump
7814 if (htab->root.srelplt)
7815 htab->sgotplt_jump_table_size = aarch64_compute_jump_table_size (htab);
7817 if (htab->tlsdesc_plt)
7819 if (htab->root.splt->size == 0)
7820 htab->root.splt->size += PLT_ENTRY_SIZE;
7822 htab->tlsdesc_plt = htab->root.splt->size;
7823 htab->root.splt->size += PLT_TLSDESC_ENTRY_SIZE;
7825 /* If we're not using lazy TLS relocations, don't generate the
7826 GOT entry required. */
7827 if (!(info->flags & DF_BIND_NOW))
7829 htab->dt_tlsdesc_got = htab->root.sgot->size;
7830 htab->root.sgot->size += GOT_ENTRY_SIZE;
7834 /* Init mapping symbols information to use later to distingush between
7835 code and data while scanning for errata. */
7836 if (htab->fix_erratum_835769 || htab->fix_erratum_843419)
7837 for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link.next)
7839 if (!is_aarch64_elf (ibfd))
7841 bfd_elfNN_aarch64_init_maps (ibfd);
7844 /* We now have determined the sizes of the various dynamic sections.
7845 Allocate memory for them. */
7847 for (s = dynobj->sections; s != NULL; s = s->next)
7849 if ((s->flags & SEC_LINKER_CREATED) == 0)
7852 if (s == htab->root.splt
7853 || s == htab->root.sgot
7854 || s == htab->root.sgotplt
7855 || s == htab->root.iplt
7856 || s == htab->root.igotplt || s == htab->sdynbss)
7858 /* Strip this section if we don't need it; see the
7861 else if (CONST_STRNEQ (bfd_get_section_name (dynobj, s), ".rela"))
7863 if (s->size != 0 && s != htab->root.srelplt)
7866 /* We use the reloc_count field as a counter if we need
7867 to copy relocs into the output file. */
7868 if (s != htab->root.srelplt)
7873 /* It's not one of our sections, so don't allocate space. */
7879 /* If we don't need this section, strip it from the
7880 output file. This is mostly to handle .rela.bss and
7881 .rela.plt. We must create both sections in
7882 create_dynamic_sections, because they must be created
7883 before the linker maps input sections to output
7884 sections. The linker does that before
7885 adjust_dynamic_symbol is called, and it is that
7886 function which decides whether anything needs to go
7887 into these sections. */
7889 s->flags |= SEC_EXCLUDE;
7893 if ((s->flags & SEC_HAS_CONTENTS) == 0)
7896 /* Allocate memory for the section contents. We use bfd_zalloc
7897 here in case unused entries are not reclaimed before the
7898 section's contents are written out. This should not happen,
7899 but this way if it does, we get a R_AARCH64_NONE reloc instead
7901 s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->size);
7902 if (s->contents == NULL)
7906 if (htab->root.dynamic_sections_created)
7908 /* Add some entries to the .dynamic section. We fill in the
7909 values later, in elfNN_aarch64_finish_dynamic_sections, but we
7910 must add the entries now so that we get the correct size for
7911 the .dynamic section. The DT_DEBUG entry is filled in by the
7912 dynamic linker and used by the debugger. */
7913 #define add_dynamic_entry(TAG, VAL) \
7914 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
7916 if (bfd_link_executable (info))
7918 if (!add_dynamic_entry (DT_DEBUG, 0))
7922 if (htab->root.splt->size != 0)
7924 if (!add_dynamic_entry (DT_PLTGOT, 0)
7925 || !add_dynamic_entry (DT_PLTRELSZ, 0)
7926 || !add_dynamic_entry (DT_PLTREL, DT_RELA)
7927 || !add_dynamic_entry (DT_JMPREL, 0))
7930 if (htab->tlsdesc_plt
7931 && (!add_dynamic_entry (DT_TLSDESC_PLT, 0)
7932 || !add_dynamic_entry (DT_TLSDESC_GOT, 0)))
7938 if (!add_dynamic_entry (DT_RELA, 0)
7939 || !add_dynamic_entry (DT_RELASZ, 0)
7940 || !add_dynamic_entry (DT_RELAENT, RELOC_SIZE (htab)))
7943 /* If any dynamic relocs apply to a read-only section,
7944 then we need a DT_TEXTREL entry. */
7945 if ((info->flags & DF_TEXTREL) == 0)
7946 elf_link_hash_traverse (& htab->root, aarch64_readonly_dynrelocs,
7949 if ((info->flags & DF_TEXTREL) != 0)
7951 if (!add_dynamic_entry (DT_TEXTREL, 0))
7956 #undef add_dynamic_entry
7962 elf_aarch64_update_plt_entry (bfd *output_bfd,
7963 bfd_reloc_code_real_type r_type,
7964 bfd_byte *plt_entry, bfd_vma value)
7966 reloc_howto_type *howto = elfNN_aarch64_howto_from_bfd_reloc (r_type);
7968 _bfd_aarch64_elf_put_addend (output_bfd, plt_entry, r_type, howto, value);
7972 elfNN_aarch64_create_small_pltn_entry (struct elf_link_hash_entry *h,
7973 struct elf_aarch64_link_hash_table
7974 *htab, bfd *output_bfd,
7975 struct bfd_link_info *info)
7977 bfd_byte *plt_entry;
7980 bfd_vma gotplt_entry_address;
7981 bfd_vma plt_entry_address;
7982 Elf_Internal_Rela rela;
7984 asection *plt, *gotplt, *relplt;
7986 /* When building a static executable, use .iplt, .igot.plt and
7987 .rela.iplt sections for STT_GNU_IFUNC symbols. */
7988 if (htab->root.splt != NULL)
7990 plt = htab->root.splt;
7991 gotplt = htab->root.sgotplt;
7992 relplt = htab->root.srelplt;
7996 plt = htab->root.iplt;
7997 gotplt = htab->root.igotplt;
7998 relplt = htab->root.irelplt;
8001 /* Get the index in the procedure linkage table which
8002 corresponds to this symbol. This is the index of this symbol
8003 in all the symbols for which we are making plt entries. The
8004 first entry in the procedure linkage table is reserved.
8006 Get the offset into the .got table of the entry that
8007 corresponds to this function. Each .got entry is GOT_ENTRY_SIZE
8008 bytes. The first three are reserved for the dynamic linker.
8010 For static executables, we don't reserve anything. */
8012 if (plt == htab->root.splt)
8014 plt_index = (h->plt.offset - htab->plt_header_size) / htab->plt_entry_size;
8015 got_offset = (plt_index + 3) * GOT_ENTRY_SIZE;
8019 plt_index = h->plt.offset / htab->plt_entry_size;
8020 got_offset = plt_index * GOT_ENTRY_SIZE;
8023 plt_entry = plt->contents + h->plt.offset;
8024 plt_entry_address = plt->output_section->vma
8025 + plt->output_offset + h->plt.offset;
8026 gotplt_entry_address = gotplt->output_section->vma +
8027 gotplt->output_offset + got_offset;
8029 /* Copy in the boiler-plate for the PLTn entry. */
8030 memcpy (plt_entry, elfNN_aarch64_small_plt_entry, PLT_SMALL_ENTRY_SIZE);
8032 /* Fill in the top 21 bits for this: ADRP x16, PLT_GOT + n * 8.
8033 ADRP: ((PG(S+A)-PG(P)) >> 12) & 0x1fffff */
8034 elf_aarch64_update_plt_entry (output_bfd, BFD_RELOC_AARCH64_ADR_HI21_PCREL,
8036 PG (gotplt_entry_address) -
8037 PG (plt_entry_address));
8039 /* Fill in the lo12 bits for the load from the pltgot. */
8040 elf_aarch64_update_plt_entry (output_bfd, BFD_RELOC_AARCH64_LDSTNN_LO12,
8042 PG_OFFSET (gotplt_entry_address));
8044 /* Fill in the lo12 bits for the add from the pltgot entry. */
8045 elf_aarch64_update_plt_entry (output_bfd, BFD_RELOC_AARCH64_ADD_LO12,
8047 PG_OFFSET (gotplt_entry_address));
8049 /* All the GOTPLT Entries are essentially initialized to PLT0. */
8050 bfd_put_NN (output_bfd,
8051 plt->output_section->vma + plt->output_offset,
8052 gotplt->contents + got_offset);
8054 rela.r_offset = gotplt_entry_address;
8056 if (h->dynindx == -1
8057 || ((bfd_link_executable (info)
8058 || ELF_ST_VISIBILITY (h->other) != STV_DEFAULT)
8060 && h->type == STT_GNU_IFUNC))
8062 /* If an STT_GNU_IFUNC symbol is locally defined, generate
8063 R_AARCH64_IRELATIVE instead of R_AARCH64_JUMP_SLOT. */
8064 rela.r_info = ELFNN_R_INFO (0, AARCH64_R (IRELATIVE));
8065 rela.r_addend = (h->root.u.def.value
8066 + h->root.u.def.section->output_section->vma
8067 + h->root.u.def.section->output_offset);
8071 /* Fill in the entry in the .rela.plt section. */
8072 rela.r_info = ELFNN_R_INFO (h->dynindx, AARCH64_R (JUMP_SLOT));
8076 /* Compute the relocation entry to used based on PLT index and do
8077 not adjust reloc_count. The reloc_count has already been adjusted
8078 to account for this entry. */
8079 loc = relplt->contents + plt_index * RELOC_SIZE (htab);
8080 bfd_elfNN_swap_reloca_out (output_bfd, &rela, loc);
8083 /* Size sections even though they're not dynamic. We use it to setup
8084 _TLS_MODULE_BASE_, if needed. */
8087 elfNN_aarch64_always_size_sections (bfd *output_bfd,
8088 struct bfd_link_info *info)
8092 if (bfd_link_relocatable (info))
8095 tls_sec = elf_hash_table (info)->tls_sec;
8099 struct elf_link_hash_entry *tlsbase;
8101 tlsbase = elf_link_hash_lookup (elf_hash_table (info),
8102 "_TLS_MODULE_BASE_", TRUE, TRUE, FALSE);
8106 struct bfd_link_hash_entry *h = NULL;
8107 const struct elf_backend_data *bed =
8108 get_elf_backend_data (output_bfd);
8110 if (!(_bfd_generic_link_add_one_symbol
8111 (info, output_bfd, "_TLS_MODULE_BASE_", BSF_LOCAL,
8112 tls_sec, 0, NULL, FALSE, bed->collect, &h)))
8115 tlsbase->type = STT_TLS;
8116 tlsbase = (struct elf_link_hash_entry *) h;
8117 tlsbase->def_regular = 1;
8118 tlsbase->other = STV_HIDDEN;
8119 (*bed->elf_backend_hide_symbol) (info, tlsbase, TRUE);
8126 /* Finish up dynamic symbol handling. We set the contents of various
8127 dynamic sections here. */
8129 elfNN_aarch64_finish_dynamic_symbol (bfd *output_bfd,
8130 struct bfd_link_info *info,
8131 struct elf_link_hash_entry *h,
8132 Elf_Internal_Sym *sym)
8134 struct elf_aarch64_link_hash_table *htab;
8135 htab = elf_aarch64_hash_table (info);
8137 if (h->plt.offset != (bfd_vma) - 1)
8139 asection *plt, *gotplt, *relplt;
8141 /* This symbol has an entry in the procedure linkage table. Set
8144 /* When building a static executable, use .iplt, .igot.plt and
8145 .rela.iplt sections for STT_GNU_IFUNC symbols. */
8146 if (htab->root.splt != NULL)
8148 plt = htab->root.splt;
8149 gotplt = htab->root.sgotplt;
8150 relplt = htab->root.srelplt;
8154 plt = htab->root.iplt;
8155 gotplt = htab->root.igotplt;
8156 relplt = htab->root.irelplt;
8159 /* This symbol has an entry in the procedure linkage table. Set
8161 if ((h->dynindx == -1
8162 && !((h->forced_local || bfd_link_executable (info))
8164 && h->type == STT_GNU_IFUNC))
8170 elfNN_aarch64_create_small_pltn_entry (h, htab, output_bfd, info);
8171 if (!h->def_regular)
8173 /* Mark the symbol as undefined, rather than as defined in
8174 the .plt section. */
8175 sym->st_shndx = SHN_UNDEF;
8176 /* If the symbol is weak we need to clear the value.
8177 Otherwise, the PLT entry would provide a definition for
8178 the symbol even if the symbol wasn't defined anywhere,
8179 and so the symbol would never be NULL. Leave the value if
8180 there were any relocations where pointer equality matters
8181 (this is a clue for the dynamic linker, to make function
8182 pointer comparisons work between an application and shared
8184 if (!h->ref_regular_nonweak || !h->pointer_equality_needed)
8189 if (h->got.offset != (bfd_vma) - 1
8190 && elf_aarch64_hash_entry (h)->got_type == GOT_NORMAL)
8192 Elf_Internal_Rela rela;
8195 /* This symbol has an entry in the global offset table. Set it
8197 if (htab->root.sgot == NULL || htab->root.srelgot == NULL)
8200 rela.r_offset = (htab->root.sgot->output_section->vma
8201 + htab->root.sgot->output_offset
8202 + (h->got.offset & ~(bfd_vma) 1));
8205 && h->type == STT_GNU_IFUNC)
8207 if (bfd_link_pic (info))
8209 /* Generate R_AARCH64_GLOB_DAT. */
8216 if (!h->pointer_equality_needed)
8219 /* For non-shared object, we can't use .got.plt, which
8220 contains the real function address if we need pointer
8221 equality. We load the GOT entry with the PLT entry. */
8222 plt = htab->root.splt ? htab->root.splt : htab->root.iplt;
8223 bfd_put_NN (output_bfd, (plt->output_section->vma
8224 + plt->output_offset
8226 htab->root.sgot->contents
8227 + (h->got.offset & ~(bfd_vma) 1));
8231 else if (bfd_link_pic (info) && SYMBOL_REFERENCES_LOCAL (info, h))
8233 if (!h->def_regular)
8236 BFD_ASSERT ((h->got.offset & 1) != 0);
8237 rela.r_info = ELFNN_R_INFO (0, AARCH64_R (RELATIVE));
8238 rela.r_addend = (h->root.u.def.value
8239 + h->root.u.def.section->output_section->vma
8240 + h->root.u.def.section->output_offset);
8245 BFD_ASSERT ((h->got.offset & 1) == 0);
8246 bfd_put_NN (output_bfd, (bfd_vma) 0,
8247 htab->root.sgot->contents + h->got.offset);
8248 rela.r_info = ELFNN_R_INFO (h->dynindx, AARCH64_R (GLOB_DAT));
8252 loc = htab->root.srelgot->contents;
8253 loc += htab->root.srelgot->reloc_count++ * RELOC_SIZE (htab);
8254 bfd_elfNN_swap_reloca_out (output_bfd, &rela, loc);
8259 Elf_Internal_Rela rela;
8262 /* This symbol needs a copy reloc. Set it up. */
8264 if (h->dynindx == -1
8265 || (h->root.type != bfd_link_hash_defined
8266 && h->root.type != bfd_link_hash_defweak)
8267 || htab->srelbss == NULL)
8270 rela.r_offset = (h->root.u.def.value
8271 + h->root.u.def.section->output_section->vma
8272 + h->root.u.def.section->output_offset);
8273 rela.r_info = ELFNN_R_INFO (h->dynindx, AARCH64_R (COPY));
8275 loc = htab->srelbss->contents;
8276 loc += htab->srelbss->reloc_count++ * RELOC_SIZE (htab);
8277 bfd_elfNN_swap_reloca_out (output_bfd, &rela, loc);
8280 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. SYM may
8281 be NULL for local symbols. */
8283 && (h == elf_hash_table (info)->hdynamic
8284 || h == elf_hash_table (info)->hgot))
8285 sym->st_shndx = SHN_ABS;
8290 /* Finish up local dynamic symbol handling. We set the contents of
8291 various dynamic sections here. */
8294 elfNN_aarch64_finish_local_dynamic_symbol (void **slot, void *inf)
8296 struct elf_link_hash_entry *h
8297 = (struct elf_link_hash_entry *) *slot;
8298 struct bfd_link_info *info
8299 = (struct bfd_link_info *) inf;
8301 return elfNN_aarch64_finish_dynamic_symbol (info->output_bfd,
8306 elfNN_aarch64_init_small_plt0_entry (bfd *output_bfd ATTRIBUTE_UNUSED,
8307 struct elf_aarch64_link_hash_table
8310 /* Fill in PLT0. Fixme:RR Note this doesn't distinguish between
8311 small and large plts and at the minute just generates
8314 /* PLT0 of the small PLT looks like this in ELF64 -
8315 stp x16, x30, [sp, #-16]! // Save the reloc and lr on stack.
8316 adrp x16, PLT_GOT + 16 // Get the page base of the GOTPLT
8317 ldr x17, [x16, #:lo12:PLT_GOT+16] // Load the address of the
8319 add x16, x16, #:lo12:PLT_GOT+16 // Load the lo12 bits of the
8320 // GOTPLT entry for this.
8322 PLT0 will be slightly different in ELF32 due to different got entry
8325 bfd_vma plt_got_2nd_ent; /* Address of GOT[2]. */
8329 memcpy (htab->root.splt->contents, elfNN_aarch64_small_plt0_entry,
8331 elf_section_data (htab->root.splt->output_section)->this_hdr.sh_entsize =
8334 plt_got_2nd_ent = (htab->root.sgotplt->output_section->vma
8335 + htab->root.sgotplt->output_offset
8336 + GOT_ENTRY_SIZE * 2);
8338 plt_base = htab->root.splt->output_section->vma +
8339 htab->root.splt->output_offset;
8341 /* Fill in the top 21 bits for this: ADRP x16, PLT_GOT + n * 8.
8342 ADRP: ((PG(S+A)-PG(P)) >> 12) & 0x1fffff */
8343 elf_aarch64_update_plt_entry (output_bfd, BFD_RELOC_AARCH64_ADR_HI21_PCREL,
8344 htab->root.splt->contents + 4,
8345 PG (plt_got_2nd_ent) - PG (plt_base + 4));
8347 elf_aarch64_update_plt_entry (output_bfd, BFD_RELOC_AARCH64_LDSTNN_LO12,
8348 htab->root.splt->contents + 8,
8349 PG_OFFSET (plt_got_2nd_ent));
8351 elf_aarch64_update_plt_entry (output_bfd, BFD_RELOC_AARCH64_ADD_LO12,
8352 htab->root.splt->contents + 12,
8353 PG_OFFSET (plt_got_2nd_ent));
8357 elfNN_aarch64_finish_dynamic_sections (bfd *output_bfd,
8358 struct bfd_link_info *info)
8360 struct elf_aarch64_link_hash_table *htab;
8364 htab = elf_aarch64_hash_table (info);
8365 dynobj = htab->root.dynobj;
8366 sdyn = bfd_get_linker_section (dynobj, ".dynamic");
8368 if (htab->root.dynamic_sections_created)
8370 ElfNN_External_Dyn *dyncon, *dynconend;
8372 if (sdyn == NULL || htab->root.sgot == NULL)
8375 dyncon = (ElfNN_External_Dyn *) sdyn->contents;
8376 dynconend = (ElfNN_External_Dyn *) (sdyn->contents + sdyn->size);
8377 for (; dyncon < dynconend; dyncon++)
8379 Elf_Internal_Dyn dyn;
8382 bfd_elfNN_swap_dyn_in (dynobj, dyncon, &dyn);
8390 s = htab->root.sgotplt;
8391 dyn.d_un.d_ptr = s->output_section->vma + s->output_offset;
8395 dyn.d_un.d_ptr = htab->root.srelplt->output_section->vma;
8399 s = htab->root.srelplt;
8400 dyn.d_un.d_val = s->size;
8404 /* The procedure linkage table relocs (DT_JMPREL) should
8405 not be included in the overall relocs (DT_RELA).
8406 Therefore, we override the DT_RELASZ entry here to
8407 make it not include the JMPREL relocs. Since the
8408 linker script arranges for .rela.plt to follow all
8409 other relocation sections, we don't have to worry
8410 about changing the DT_RELA entry. */
8411 if (htab->root.srelplt != NULL)
8413 s = htab->root.srelplt;
8414 dyn.d_un.d_val -= s->size;
8418 case DT_TLSDESC_PLT:
8419 s = htab->root.splt;
8420 dyn.d_un.d_ptr = s->output_section->vma + s->output_offset
8421 + htab->tlsdesc_plt;
8424 case DT_TLSDESC_GOT:
8425 s = htab->root.sgot;
8426 dyn.d_un.d_ptr = s->output_section->vma + s->output_offset
8427 + htab->dt_tlsdesc_got;
8431 bfd_elfNN_swap_dyn_out (output_bfd, &dyn, dyncon);
8436 /* Fill in the special first entry in the procedure linkage table. */
8437 if (htab->root.splt && htab->root.splt->size > 0)
8439 elfNN_aarch64_init_small_plt0_entry (output_bfd, htab);
8441 elf_section_data (htab->root.splt->output_section)->
8442 this_hdr.sh_entsize = htab->plt_entry_size;
8445 if (htab->tlsdesc_plt)
8447 bfd_put_NN (output_bfd, (bfd_vma) 0,
8448 htab->root.sgot->contents + htab->dt_tlsdesc_got);
8450 memcpy (htab->root.splt->contents + htab->tlsdesc_plt,
8451 elfNN_aarch64_tlsdesc_small_plt_entry,
8452 sizeof (elfNN_aarch64_tlsdesc_small_plt_entry));
8455 bfd_vma adrp1_addr =
8456 htab->root.splt->output_section->vma
8457 + htab->root.splt->output_offset + htab->tlsdesc_plt + 4;
8459 bfd_vma adrp2_addr = adrp1_addr + 4;
8462 htab->root.sgot->output_section->vma
8463 + htab->root.sgot->output_offset;
8465 bfd_vma pltgot_addr =
8466 htab->root.sgotplt->output_section->vma
8467 + htab->root.sgotplt->output_offset;
8469 bfd_vma dt_tlsdesc_got = got_addr + htab->dt_tlsdesc_got;
8471 bfd_byte *plt_entry =
8472 htab->root.splt->contents + htab->tlsdesc_plt;
8474 /* adrp x2, DT_TLSDESC_GOT */
8475 elf_aarch64_update_plt_entry (output_bfd,
8476 BFD_RELOC_AARCH64_ADR_HI21_PCREL,
8478 (PG (dt_tlsdesc_got)
8479 - PG (adrp1_addr)));
8482 elf_aarch64_update_plt_entry (output_bfd,
8483 BFD_RELOC_AARCH64_ADR_HI21_PCREL,
8486 - PG (adrp2_addr)));
8488 /* ldr x2, [x2, #0] */
8489 elf_aarch64_update_plt_entry (output_bfd,
8490 BFD_RELOC_AARCH64_LDSTNN_LO12,
8492 PG_OFFSET (dt_tlsdesc_got));
8495 elf_aarch64_update_plt_entry (output_bfd,
8496 BFD_RELOC_AARCH64_ADD_LO12,
8498 PG_OFFSET (pltgot_addr));
8503 if (htab->root.sgotplt)
8505 if (bfd_is_abs_section (htab->root.sgotplt->output_section))
8507 (*_bfd_error_handler)
8508 (_("discarded output section: `%A'"), htab->root.sgotplt);
8512 /* Fill in the first three entries in the global offset table. */
8513 if (htab->root.sgotplt->size > 0)
8515 bfd_put_NN (output_bfd, (bfd_vma) 0, htab->root.sgotplt->contents);
8517 /* Write GOT[1] and GOT[2], needed for the dynamic linker. */
8518 bfd_put_NN (output_bfd,
8520 htab->root.sgotplt->contents + GOT_ENTRY_SIZE);
8521 bfd_put_NN (output_bfd,
8523 htab->root.sgotplt->contents + GOT_ENTRY_SIZE * 2);
8526 if (htab->root.sgot)
8528 if (htab->root.sgot->size > 0)
8531 sdyn ? sdyn->output_section->vma + sdyn->output_offset : 0;
8532 bfd_put_NN (output_bfd, addr, htab->root.sgot->contents);
8536 elf_section_data (htab->root.sgotplt->output_section)->
8537 this_hdr.sh_entsize = GOT_ENTRY_SIZE;
8540 if (htab->root.sgot && htab->root.sgot->size > 0)
8541 elf_section_data (htab->root.sgot->output_section)->this_hdr.sh_entsize
8544 /* Fill PLT and GOT entries for local STT_GNU_IFUNC symbols. */
8545 htab_traverse (htab->loc_hash_table,
8546 elfNN_aarch64_finish_local_dynamic_symbol,
8552 /* Return address for Ith PLT stub in section PLT, for relocation REL
8553 or (bfd_vma) -1 if it should not be included. */
8556 elfNN_aarch64_plt_sym_val (bfd_vma i, const asection *plt,
8557 const arelent *rel ATTRIBUTE_UNUSED)
8559 return plt->vma + PLT_ENTRY_SIZE + i * PLT_SMALL_ENTRY_SIZE;
8563 /* We use this so we can override certain functions
8564 (though currently we don't). */
8566 const struct elf_size_info elfNN_aarch64_size_info =
8568 sizeof (ElfNN_External_Ehdr),
8569 sizeof (ElfNN_External_Phdr),
8570 sizeof (ElfNN_External_Shdr),
8571 sizeof (ElfNN_External_Rel),
8572 sizeof (ElfNN_External_Rela),
8573 sizeof (ElfNN_External_Sym),
8574 sizeof (ElfNN_External_Dyn),
8575 sizeof (Elf_External_Note),
8576 4, /* Hash table entry size. */
8577 1, /* Internal relocs per external relocs. */
8578 ARCH_SIZE, /* Arch size. */
8579 LOG_FILE_ALIGN, /* Log_file_align. */
8580 ELFCLASSNN, EV_CURRENT,
8581 bfd_elfNN_write_out_phdrs,
8582 bfd_elfNN_write_shdrs_and_ehdr,
8583 bfd_elfNN_checksum_contents,
8584 bfd_elfNN_write_relocs,
8585 bfd_elfNN_swap_symbol_in,
8586 bfd_elfNN_swap_symbol_out,
8587 bfd_elfNN_slurp_reloc_table,
8588 bfd_elfNN_slurp_symbol_table,
8589 bfd_elfNN_swap_dyn_in,
8590 bfd_elfNN_swap_dyn_out,
8591 bfd_elfNN_swap_reloc_in,
8592 bfd_elfNN_swap_reloc_out,
8593 bfd_elfNN_swap_reloca_in,
8594 bfd_elfNN_swap_reloca_out
8597 #define ELF_ARCH bfd_arch_aarch64
8598 #define ELF_MACHINE_CODE EM_AARCH64
8599 #define ELF_MAXPAGESIZE 0x10000
8600 #define ELF_MINPAGESIZE 0x1000
8601 #define ELF_COMMONPAGESIZE 0x1000
8603 #define bfd_elfNN_close_and_cleanup \
8604 elfNN_aarch64_close_and_cleanup
8606 #define bfd_elfNN_bfd_free_cached_info \
8607 elfNN_aarch64_bfd_free_cached_info
8609 #define bfd_elfNN_bfd_is_target_special_symbol \
8610 elfNN_aarch64_is_target_special_symbol
8612 #define bfd_elfNN_bfd_link_hash_table_create \
8613 elfNN_aarch64_link_hash_table_create
8615 #define bfd_elfNN_bfd_merge_private_bfd_data \
8616 elfNN_aarch64_merge_private_bfd_data
8618 #define bfd_elfNN_bfd_print_private_bfd_data \
8619 elfNN_aarch64_print_private_bfd_data
8621 #define bfd_elfNN_bfd_reloc_type_lookup \
8622 elfNN_aarch64_reloc_type_lookup
8624 #define bfd_elfNN_bfd_reloc_name_lookup \
8625 elfNN_aarch64_reloc_name_lookup
8627 #define bfd_elfNN_bfd_set_private_flags \
8628 elfNN_aarch64_set_private_flags
8630 #define bfd_elfNN_find_inliner_info \
8631 elfNN_aarch64_find_inliner_info
8633 #define bfd_elfNN_find_nearest_line \
8634 elfNN_aarch64_find_nearest_line
8636 #define bfd_elfNN_mkobject \
8637 elfNN_aarch64_mkobject
8639 #define bfd_elfNN_new_section_hook \
8640 elfNN_aarch64_new_section_hook
8642 #define elf_backend_adjust_dynamic_symbol \
8643 elfNN_aarch64_adjust_dynamic_symbol
8645 #define elf_backend_always_size_sections \
8646 elfNN_aarch64_always_size_sections
8648 #define elf_backend_check_relocs \
8649 elfNN_aarch64_check_relocs
8651 #define elf_backend_copy_indirect_symbol \
8652 elfNN_aarch64_copy_indirect_symbol
8654 /* Create .dynbss, and .rela.bss sections in DYNOBJ, and set up shortcuts
8655 to them in our hash. */
8656 #define elf_backend_create_dynamic_sections \
8657 elfNN_aarch64_create_dynamic_sections
8659 #define elf_backend_init_index_section \
8660 _bfd_elf_init_2_index_sections
8662 #define elf_backend_finish_dynamic_sections \
8663 elfNN_aarch64_finish_dynamic_sections
8665 #define elf_backend_finish_dynamic_symbol \
8666 elfNN_aarch64_finish_dynamic_symbol
8668 #define elf_backend_gc_sweep_hook \
8669 elfNN_aarch64_gc_sweep_hook
8671 #define elf_backend_object_p \
8672 elfNN_aarch64_object_p
8674 #define elf_backend_output_arch_local_syms \
8675 elfNN_aarch64_output_arch_local_syms
8677 #define elf_backend_plt_sym_val \
8678 elfNN_aarch64_plt_sym_val
8680 #define elf_backend_post_process_headers \
8681 elfNN_aarch64_post_process_headers
8683 #define elf_backend_relocate_section \
8684 elfNN_aarch64_relocate_section
8686 #define elf_backend_reloc_type_class \
8687 elfNN_aarch64_reloc_type_class
8689 #define elf_backend_section_from_shdr \
8690 elfNN_aarch64_section_from_shdr
8692 #define elf_backend_size_dynamic_sections \
8693 elfNN_aarch64_size_dynamic_sections
8695 #define elf_backend_size_info \
8696 elfNN_aarch64_size_info
8698 #define elf_backend_write_section \
8699 elfNN_aarch64_write_section
8701 #define elf_backend_can_refcount 1
8702 #define elf_backend_can_gc_sections 1
8703 #define elf_backend_plt_readonly 1
8704 #define elf_backend_want_got_plt 1
8705 #define elf_backend_want_plt_sym 0
8706 #define elf_backend_may_use_rel_p 0
8707 #define elf_backend_may_use_rela_p 1
8708 #define elf_backend_default_use_rela_p 1
8709 #define elf_backend_rela_normal 1
8710 #define elf_backend_got_header_size (GOT_ENTRY_SIZE * 3)
8711 #define elf_backend_default_execstack 0
8712 #define elf_backend_extern_protected_data 1
8714 #undef elf_backend_obj_attrs_section
8715 #define elf_backend_obj_attrs_section ".ARM.attributes"
8717 #include "elfNN-target.h"