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_ADR_PAGE21 \
178 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_ADR_PREL21 \
179 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_HI12 \
180 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_LO12 \
181 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_LO12_NC \
182 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0 \
183 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC \
184 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1 \
185 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1_NC \
186 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G2 \
187 || (R_TYPE) == BFD_RELOC_AARCH64_TLS_DTPMOD \
188 || (R_TYPE) == BFD_RELOC_AARCH64_TLS_DTPREL \
189 || (R_TYPE) == BFD_RELOC_AARCH64_TLS_TPREL \
190 || IS_AARCH64_TLSDESC_RELOC ((R_TYPE)))
192 #define IS_AARCH64_TLSDESC_RELOC(R_TYPE) \
193 ((R_TYPE) == BFD_RELOC_AARCH64_TLSDESC \
194 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_ADD \
195 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_ADD_LO12_NC \
196 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21 \
197 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21 \
198 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_CALL \
199 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_LD32_LO12_NC \
200 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_LD64_LO12_NC \
201 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_LDR \
202 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_LD_PREL19 \
203 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_OFF_G0_NC \
204 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_OFF_G1)
206 #define ELIMINATE_COPY_RELOCS 0
208 /* Return size of a relocation entry. HTAB is the bfd's
209 elf_aarch64_link_hash_entry. */
210 #define RELOC_SIZE(HTAB) (sizeof (ElfNN_External_Rela))
212 /* GOT Entry size - 8 bytes in ELF64 and 4 bytes in ELF32. */
213 #define GOT_ENTRY_SIZE (ARCH_SIZE / 8)
214 #define PLT_ENTRY_SIZE (32)
215 #define PLT_SMALL_ENTRY_SIZE (16)
216 #define PLT_TLSDESC_ENTRY_SIZE (32)
218 /* Encoding of the nop instruction */
219 #define INSN_NOP 0xd503201f
221 #define aarch64_compute_jump_table_size(htab) \
222 (((htab)->root.srelplt == NULL) ? 0 \
223 : (htab)->root.srelplt->reloc_count * GOT_ENTRY_SIZE)
225 /* The first entry in a procedure linkage table looks like this
226 if the distance between the PLTGOT and the PLT is < 4GB use
227 these PLT entries. Note that the dynamic linker gets &PLTGOT[2]
228 in x16 and needs to work out PLTGOT[1] by using an address of
229 [x16,#-GOT_ENTRY_SIZE]. */
230 static const bfd_byte elfNN_aarch64_small_plt0_entry[PLT_ENTRY_SIZE] =
232 0xf0, 0x7b, 0xbf, 0xa9, /* stp x16, x30, [sp, #-16]! */
233 0x10, 0x00, 0x00, 0x90, /* adrp x16, (GOT+16) */
235 0x11, 0x0A, 0x40, 0xf9, /* ldr x17, [x16, #PLT_GOT+0x10] */
236 0x10, 0x42, 0x00, 0x91, /* add x16, x16,#PLT_GOT+0x10 */
238 0x11, 0x0A, 0x40, 0xb9, /* ldr w17, [x16, #PLT_GOT+0x8] */
239 0x10, 0x22, 0x00, 0x11, /* add w16, w16,#PLT_GOT+0x8 */
241 0x20, 0x02, 0x1f, 0xd6, /* br x17 */
242 0x1f, 0x20, 0x03, 0xd5, /* nop */
243 0x1f, 0x20, 0x03, 0xd5, /* nop */
244 0x1f, 0x20, 0x03, 0xd5, /* nop */
247 /* Per function entry in a procedure linkage table looks like this
248 if the distance between the PLTGOT and the PLT is < 4GB use
249 these PLT entries. */
250 static const bfd_byte elfNN_aarch64_small_plt_entry[PLT_SMALL_ENTRY_SIZE] =
252 0x10, 0x00, 0x00, 0x90, /* adrp x16, PLTGOT + n * 8 */
254 0x11, 0x02, 0x40, 0xf9, /* ldr x17, [x16, PLTGOT + n * 8] */
255 0x10, 0x02, 0x00, 0x91, /* add x16, x16, :lo12:PLTGOT + n * 8 */
257 0x11, 0x02, 0x40, 0xb9, /* ldr w17, [x16, PLTGOT + n * 4] */
258 0x10, 0x02, 0x00, 0x11, /* add w16, w16, :lo12:PLTGOT + n * 4 */
260 0x20, 0x02, 0x1f, 0xd6, /* br x17. */
263 static const bfd_byte
264 elfNN_aarch64_tlsdesc_small_plt_entry[PLT_TLSDESC_ENTRY_SIZE] =
266 0xe2, 0x0f, 0xbf, 0xa9, /* stp x2, x3, [sp, #-16]! */
267 0x02, 0x00, 0x00, 0x90, /* adrp x2, 0 */
268 0x03, 0x00, 0x00, 0x90, /* adrp x3, 0 */
270 0x42, 0x00, 0x40, 0xf9, /* ldr x2, [x2, #0] */
271 0x63, 0x00, 0x00, 0x91, /* add x3, x3, 0 */
273 0x42, 0x00, 0x40, 0xb9, /* ldr w2, [x2, #0] */
274 0x63, 0x00, 0x00, 0x11, /* add w3, w3, 0 */
276 0x40, 0x00, 0x1f, 0xd6, /* br x2 */
277 0x1f, 0x20, 0x03, 0xd5, /* nop */
278 0x1f, 0x20, 0x03, 0xd5, /* nop */
281 #define elf_info_to_howto elfNN_aarch64_info_to_howto
282 #define elf_info_to_howto_rel elfNN_aarch64_info_to_howto
284 #define AARCH64_ELF_ABI_VERSION 0
286 /* In case we're on a 32-bit machine, construct a 64-bit "-1" value. */
287 #define ALL_ONES (~ (bfd_vma) 0)
289 /* Indexed by the bfd interal reloc enumerators.
290 Therefore, the table needs to be synced with BFD_RELOC_AARCH64_*
293 static reloc_howto_type elfNN_aarch64_howto_table[] =
297 /* Basic data relocations. */
300 HOWTO (R_AARCH64_NULL, /* type */
302 3, /* size (0 = byte, 1 = short, 2 = long) */
304 FALSE, /* pc_relative */
306 complain_overflow_dont, /* complain_on_overflow */
307 bfd_elf_generic_reloc, /* special_function */
308 "R_AARCH64_NULL", /* name */
309 FALSE, /* partial_inplace */
312 FALSE), /* pcrel_offset */
314 HOWTO (R_AARCH64_NONE, /* type */
316 3, /* size (0 = byte, 1 = short, 2 = long) */
318 FALSE, /* pc_relative */
320 complain_overflow_dont, /* complain_on_overflow */
321 bfd_elf_generic_reloc, /* special_function */
322 "R_AARCH64_NONE", /* name */
323 FALSE, /* partial_inplace */
326 FALSE), /* pcrel_offset */
330 HOWTO64 (AARCH64_R (ABS64), /* type */
332 4, /* size (4 = long long) */
334 FALSE, /* pc_relative */
336 complain_overflow_unsigned, /* complain_on_overflow */
337 bfd_elf_generic_reloc, /* special_function */
338 AARCH64_R_STR (ABS64), /* name */
339 FALSE, /* partial_inplace */
340 ALL_ONES, /* src_mask */
341 ALL_ONES, /* dst_mask */
342 FALSE), /* pcrel_offset */
345 HOWTO (AARCH64_R (ABS32), /* type */
347 2, /* size (0 = byte, 1 = short, 2 = long) */
349 FALSE, /* pc_relative */
351 complain_overflow_unsigned, /* complain_on_overflow */
352 bfd_elf_generic_reloc, /* special_function */
353 AARCH64_R_STR (ABS32), /* name */
354 FALSE, /* partial_inplace */
355 0xffffffff, /* src_mask */
356 0xffffffff, /* dst_mask */
357 FALSE), /* pcrel_offset */
360 HOWTO (AARCH64_R (ABS16), /* type */
362 1, /* size (0 = byte, 1 = short, 2 = long) */
364 FALSE, /* pc_relative */
366 complain_overflow_unsigned, /* complain_on_overflow */
367 bfd_elf_generic_reloc, /* special_function */
368 AARCH64_R_STR (ABS16), /* name */
369 FALSE, /* partial_inplace */
370 0xffff, /* src_mask */
371 0xffff, /* dst_mask */
372 FALSE), /* pcrel_offset */
374 /* .xword: (S+A-P) */
375 HOWTO64 (AARCH64_R (PREL64), /* type */
377 4, /* size (4 = long long) */
379 TRUE, /* pc_relative */
381 complain_overflow_signed, /* complain_on_overflow */
382 bfd_elf_generic_reloc, /* special_function */
383 AARCH64_R_STR (PREL64), /* name */
384 FALSE, /* partial_inplace */
385 ALL_ONES, /* src_mask */
386 ALL_ONES, /* dst_mask */
387 TRUE), /* pcrel_offset */
390 HOWTO (AARCH64_R (PREL32), /* type */
392 2, /* size (0 = byte, 1 = short, 2 = long) */
394 TRUE, /* pc_relative */
396 complain_overflow_signed, /* complain_on_overflow */
397 bfd_elf_generic_reloc, /* special_function */
398 AARCH64_R_STR (PREL32), /* name */
399 FALSE, /* partial_inplace */
400 0xffffffff, /* src_mask */
401 0xffffffff, /* dst_mask */
402 TRUE), /* pcrel_offset */
405 HOWTO (AARCH64_R (PREL16), /* type */
407 1, /* size (0 = byte, 1 = short, 2 = long) */
409 TRUE, /* pc_relative */
411 complain_overflow_signed, /* complain_on_overflow */
412 bfd_elf_generic_reloc, /* special_function */
413 AARCH64_R_STR (PREL16), /* name */
414 FALSE, /* partial_inplace */
415 0xffff, /* src_mask */
416 0xffff, /* dst_mask */
417 TRUE), /* pcrel_offset */
419 /* Group relocations to create a 16, 32, 48 or 64 bit
420 unsigned data or abs address inline. */
422 /* MOVZ: ((S+A) >> 0) & 0xffff */
423 HOWTO (AARCH64_R (MOVW_UABS_G0), /* type */
425 2, /* size (0 = byte, 1 = short, 2 = long) */
427 FALSE, /* pc_relative */
429 complain_overflow_unsigned, /* complain_on_overflow */
430 bfd_elf_generic_reloc, /* special_function */
431 AARCH64_R_STR (MOVW_UABS_G0), /* name */
432 FALSE, /* partial_inplace */
433 0xffff, /* src_mask */
434 0xffff, /* dst_mask */
435 FALSE), /* pcrel_offset */
437 /* MOVK: ((S+A) >> 0) & 0xffff [no overflow check] */
438 HOWTO (AARCH64_R (MOVW_UABS_G0_NC), /* type */
440 2, /* size (0 = byte, 1 = short, 2 = long) */
442 FALSE, /* pc_relative */
444 complain_overflow_dont, /* complain_on_overflow */
445 bfd_elf_generic_reloc, /* special_function */
446 AARCH64_R_STR (MOVW_UABS_G0_NC), /* name */
447 FALSE, /* partial_inplace */
448 0xffff, /* src_mask */
449 0xffff, /* dst_mask */
450 FALSE), /* pcrel_offset */
452 /* MOVZ: ((S+A) >> 16) & 0xffff */
453 HOWTO (AARCH64_R (MOVW_UABS_G1), /* type */
455 2, /* size (0 = byte, 1 = short, 2 = long) */
457 FALSE, /* pc_relative */
459 complain_overflow_unsigned, /* complain_on_overflow */
460 bfd_elf_generic_reloc, /* special_function */
461 AARCH64_R_STR (MOVW_UABS_G1), /* name */
462 FALSE, /* partial_inplace */
463 0xffff, /* src_mask */
464 0xffff, /* dst_mask */
465 FALSE), /* pcrel_offset */
467 /* MOVK: ((S+A) >> 16) & 0xffff [no overflow check] */
468 HOWTO64 (AARCH64_R (MOVW_UABS_G1_NC), /* type */
470 2, /* size (0 = byte, 1 = short, 2 = long) */
472 FALSE, /* pc_relative */
474 complain_overflow_dont, /* complain_on_overflow */
475 bfd_elf_generic_reloc, /* special_function */
476 AARCH64_R_STR (MOVW_UABS_G1_NC), /* name */
477 FALSE, /* partial_inplace */
478 0xffff, /* src_mask */
479 0xffff, /* dst_mask */
480 FALSE), /* pcrel_offset */
482 /* MOVZ: ((S+A) >> 32) & 0xffff */
483 HOWTO64 (AARCH64_R (MOVW_UABS_G2), /* type */
485 2, /* size (0 = byte, 1 = short, 2 = long) */
487 FALSE, /* pc_relative */
489 complain_overflow_unsigned, /* complain_on_overflow */
490 bfd_elf_generic_reloc, /* special_function */
491 AARCH64_R_STR (MOVW_UABS_G2), /* name */
492 FALSE, /* partial_inplace */
493 0xffff, /* src_mask */
494 0xffff, /* dst_mask */
495 FALSE), /* pcrel_offset */
497 /* MOVK: ((S+A) >> 32) & 0xffff [no overflow check] */
498 HOWTO64 (AARCH64_R (MOVW_UABS_G2_NC), /* type */
500 2, /* size (0 = byte, 1 = short, 2 = long) */
502 FALSE, /* pc_relative */
504 complain_overflow_dont, /* complain_on_overflow */
505 bfd_elf_generic_reloc, /* special_function */
506 AARCH64_R_STR (MOVW_UABS_G2_NC), /* name */
507 FALSE, /* partial_inplace */
508 0xffff, /* src_mask */
509 0xffff, /* dst_mask */
510 FALSE), /* pcrel_offset */
512 /* MOVZ: ((S+A) >> 48) & 0xffff */
513 HOWTO64 (AARCH64_R (MOVW_UABS_G3), /* type */
515 2, /* size (0 = byte, 1 = short, 2 = long) */
517 FALSE, /* pc_relative */
519 complain_overflow_unsigned, /* complain_on_overflow */
520 bfd_elf_generic_reloc, /* special_function */
521 AARCH64_R_STR (MOVW_UABS_G3), /* name */
522 FALSE, /* partial_inplace */
523 0xffff, /* src_mask */
524 0xffff, /* dst_mask */
525 FALSE), /* pcrel_offset */
527 /* Group relocations to create high part of a 16, 32, 48 or 64 bit
528 signed data or abs address inline. Will change instruction
529 to MOVN or MOVZ depending on sign of calculated value. */
531 /* MOV[ZN]: ((S+A) >> 0) & 0xffff */
532 HOWTO (AARCH64_R (MOVW_SABS_G0), /* type */
534 2, /* size (0 = byte, 1 = short, 2 = long) */
536 FALSE, /* pc_relative */
538 complain_overflow_signed, /* complain_on_overflow */
539 bfd_elf_generic_reloc, /* special_function */
540 AARCH64_R_STR (MOVW_SABS_G0), /* name */
541 FALSE, /* partial_inplace */
542 0xffff, /* src_mask */
543 0xffff, /* dst_mask */
544 FALSE), /* pcrel_offset */
546 /* MOV[ZN]: ((S+A) >> 16) & 0xffff */
547 HOWTO64 (AARCH64_R (MOVW_SABS_G1), /* type */
549 2, /* size (0 = byte, 1 = short, 2 = long) */
551 FALSE, /* pc_relative */
553 complain_overflow_signed, /* complain_on_overflow */
554 bfd_elf_generic_reloc, /* special_function */
555 AARCH64_R_STR (MOVW_SABS_G1), /* name */
556 FALSE, /* partial_inplace */
557 0xffff, /* src_mask */
558 0xffff, /* dst_mask */
559 FALSE), /* pcrel_offset */
561 /* MOV[ZN]: ((S+A) >> 32) & 0xffff */
562 HOWTO64 (AARCH64_R (MOVW_SABS_G2), /* type */
564 2, /* size (0 = byte, 1 = short, 2 = long) */
566 FALSE, /* pc_relative */
568 complain_overflow_signed, /* complain_on_overflow */
569 bfd_elf_generic_reloc, /* special_function */
570 AARCH64_R_STR (MOVW_SABS_G2), /* name */
571 FALSE, /* partial_inplace */
572 0xffff, /* src_mask */
573 0xffff, /* dst_mask */
574 FALSE), /* pcrel_offset */
576 /* Relocations to generate 19, 21 and 33 bit PC-relative load/store
577 addresses: PG(x) is (x & ~0xfff). */
579 /* LD-lit: ((S+A-P) >> 2) & 0x7ffff */
580 HOWTO (AARCH64_R (LD_PREL_LO19), /* type */
582 2, /* size (0 = byte, 1 = short, 2 = long) */
584 TRUE, /* pc_relative */
586 complain_overflow_signed, /* complain_on_overflow */
587 bfd_elf_generic_reloc, /* special_function */
588 AARCH64_R_STR (LD_PREL_LO19), /* name */
589 FALSE, /* partial_inplace */
590 0x7ffff, /* src_mask */
591 0x7ffff, /* dst_mask */
592 TRUE), /* pcrel_offset */
594 /* ADR: (S+A-P) & 0x1fffff */
595 HOWTO (AARCH64_R (ADR_PREL_LO21), /* type */
597 2, /* size (0 = byte, 1 = short, 2 = long) */
599 TRUE, /* pc_relative */
601 complain_overflow_signed, /* complain_on_overflow */
602 bfd_elf_generic_reloc, /* special_function */
603 AARCH64_R_STR (ADR_PREL_LO21), /* name */
604 FALSE, /* partial_inplace */
605 0x1fffff, /* src_mask */
606 0x1fffff, /* dst_mask */
607 TRUE), /* pcrel_offset */
609 /* ADRP: ((PG(S+A)-PG(P)) >> 12) & 0x1fffff */
610 HOWTO (AARCH64_R (ADR_PREL_PG_HI21), /* type */
612 2, /* size (0 = byte, 1 = short, 2 = long) */
614 TRUE, /* pc_relative */
616 complain_overflow_signed, /* complain_on_overflow */
617 bfd_elf_generic_reloc, /* special_function */
618 AARCH64_R_STR (ADR_PREL_PG_HI21), /* name */
619 FALSE, /* partial_inplace */
620 0x1fffff, /* src_mask */
621 0x1fffff, /* dst_mask */
622 TRUE), /* pcrel_offset */
624 /* ADRP: ((PG(S+A)-PG(P)) >> 12) & 0x1fffff [no overflow check] */
625 HOWTO64 (AARCH64_R (ADR_PREL_PG_HI21_NC), /* type */
627 2, /* size (0 = byte, 1 = short, 2 = long) */
629 TRUE, /* pc_relative */
631 complain_overflow_dont, /* complain_on_overflow */
632 bfd_elf_generic_reloc, /* special_function */
633 AARCH64_R_STR (ADR_PREL_PG_HI21_NC), /* name */
634 FALSE, /* partial_inplace */
635 0x1fffff, /* src_mask */
636 0x1fffff, /* dst_mask */
637 TRUE), /* pcrel_offset */
639 /* ADD: (S+A) & 0xfff [no overflow check] */
640 HOWTO (AARCH64_R (ADD_ABS_LO12_NC), /* type */
642 2, /* size (0 = byte, 1 = short, 2 = long) */
644 FALSE, /* pc_relative */
646 complain_overflow_dont, /* complain_on_overflow */
647 bfd_elf_generic_reloc, /* special_function */
648 AARCH64_R_STR (ADD_ABS_LO12_NC), /* name */
649 FALSE, /* partial_inplace */
650 0x3ffc00, /* src_mask */
651 0x3ffc00, /* dst_mask */
652 FALSE), /* pcrel_offset */
654 /* LD/ST8: (S+A) & 0xfff */
655 HOWTO (AARCH64_R (LDST8_ABS_LO12_NC), /* type */
657 2, /* size (0 = byte, 1 = short, 2 = long) */
659 FALSE, /* pc_relative */
661 complain_overflow_dont, /* complain_on_overflow */
662 bfd_elf_generic_reloc, /* special_function */
663 AARCH64_R_STR (LDST8_ABS_LO12_NC), /* name */
664 FALSE, /* partial_inplace */
665 0xfff, /* src_mask */
666 0xfff, /* dst_mask */
667 FALSE), /* pcrel_offset */
669 /* Relocations for control-flow instructions. */
671 /* TBZ/NZ: ((S+A-P) >> 2) & 0x3fff */
672 HOWTO (AARCH64_R (TSTBR14), /* type */
674 2, /* size (0 = byte, 1 = short, 2 = long) */
676 TRUE, /* pc_relative */
678 complain_overflow_signed, /* complain_on_overflow */
679 bfd_elf_generic_reloc, /* special_function */
680 AARCH64_R_STR (TSTBR14), /* name */
681 FALSE, /* partial_inplace */
682 0x3fff, /* src_mask */
683 0x3fff, /* dst_mask */
684 TRUE), /* pcrel_offset */
686 /* B.cond: ((S+A-P) >> 2) & 0x7ffff */
687 HOWTO (AARCH64_R (CONDBR19), /* type */
689 2, /* size (0 = byte, 1 = short, 2 = long) */
691 TRUE, /* pc_relative */
693 complain_overflow_signed, /* complain_on_overflow */
694 bfd_elf_generic_reloc, /* special_function */
695 AARCH64_R_STR (CONDBR19), /* name */
696 FALSE, /* partial_inplace */
697 0x7ffff, /* src_mask */
698 0x7ffff, /* dst_mask */
699 TRUE), /* pcrel_offset */
701 /* B: ((S+A-P) >> 2) & 0x3ffffff */
702 HOWTO (AARCH64_R (JUMP26), /* type */
704 2, /* size (0 = byte, 1 = short, 2 = long) */
706 TRUE, /* pc_relative */
708 complain_overflow_signed, /* complain_on_overflow */
709 bfd_elf_generic_reloc, /* special_function */
710 AARCH64_R_STR (JUMP26), /* name */
711 FALSE, /* partial_inplace */
712 0x3ffffff, /* src_mask */
713 0x3ffffff, /* dst_mask */
714 TRUE), /* pcrel_offset */
716 /* BL: ((S+A-P) >> 2) & 0x3ffffff */
717 HOWTO (AARCH64_R (CALL26), /* type */
719 2, /* size (0 = byte, 1 = short, 2 = long) */
721 TRUE, /* pc_relative */
723 complain_overflow_signed, /* complain_on_overflow */
724 bfd_elf_generic_reloc, /* special_function */
725 AARCH64_R_STR (CALL26), /* name */
726 FALSE, /* partial_inplace */
727 0x3ffffff, /* src_mask */
728 0x3ffffff, /* dst_mask */
729 TRUE), /* pcrel_offset */
731 /* LD/ST16: (S+A) & 0xffe */
732 HOWTO (AARCH64_R (LDST16_ABS_LO12_NC), /* type */
734 2, /* size (0 = byte, 1 = short, 2 = long) */
736 FALSE, /* pc_relative */
738 complain_overflow_dont, /* complain_on_overflow */
739 bfd_elf_generic_reloc, /* special_function */
740 AARCH64_R_STR (LDST16_ABS_LO12_NC), /* name */
741 FALSE, /* partial_inplace */
742 0xffe, /* src_mask */
743 0xffe, /* dst_mask */
744 FALSE), /* pcrel_offset */
746 /* LD/ST32: (S+A) & 0xffc */
747 HOWTO (AARCH64_R (LDST32_ABS_LO12_NC), /* type */
749 2, /* size (0 = byte, 1 = short, 2 = long) */
751 FALSE, /* pc_relative */
753 complain_overflow_dont, /* complain_on_overflow */
754 bfd_elf_generic_reloc, /* special_function */
755 AARCH64_R_STR (LDST32_ABS_LO12_NC), /* name */
756 FALSE, /* partial_inplace */
757 0xffc, /* src_mask */
758 0xffc, /* dst_mask */
759 FALSE), /* pcrel_offset */
761 /* LD/ST64: (S+A) & 0xff8 */
762 HOWTO (AARCH64_R (LDST64_ABS_LO12_NC), /* type */
764 2, /* size (0 = byte, 1 = short, 2 = long) */
766 FALSE, /* pc_relative */
768 complain_overflow_dont, /* complain_on_overflow */
769 bfd_elf_generic_reloc, /* special_function */
770 AARCH64_R_STR (LDST64_ABS_LO12_NC), /* name */
771 FALSE, /* partial_inplace */
772 0xff8, /* src_mask */
773 0xff8, /* dst_mask */
774 FALSE), /* pcrel_offset */
776 /* LD/ST128: (S+A) & 0xff0 */
777 HOWTO (AARCH64_R (LDST128_ABS_LO12_NC), /* type */
779 2, /* size (0 = byte, 1 = short, 2 = long) */
781 FALSE, /* pc_relative */
783 complain_overflow_dont, /* complain_on_overflow */
784 bfd_elf_generic_reloc, /* special_function */
785 AARCH64_R_STR (LDST128_ABS_LO12_NC), /* name */
786 FALSE, /* partial_inplace */
787 0xff0, /* src_mask */
788 0xff0, /* dst_mask */
789 FALSE), /* pcrel_offset */
791 /* Set a load-literal immediate field to bits
792 0x1FFFFC of G(S)-P */
793 HOWTO (AARCH64_R (GOT_LD_PREL19), /* type */
795 2, /* size (0 = byte,1 = short,2 = long) */
797 TRUE, /* pc_relative */
799 complain_overflow_signed, /* complain_on_overflow */
800 bfd_elf_generic_reloc, /* special_function */
801 AARCH64_R_STR (GOT_LD_PREL19), /* name */
802 FALSE, /* partial_inplace */
803 0xffffe0, /* src_mask */
804 0xffffe0, /* dst_mask */
805 TRUE), /* pcrel_offset */
807 /* Get to the page for the GOT entry for the symbol
808 (G(S) - P) using an ADRP instruction. */
809 HOWTO (AARCH64_R (ADR_GOT_PAGE), /* type */
811 2, /* size (0 = byte, 1 = short, 2 = long) */
813 TRUE, /* pc_relative */
815 complain_overflow_dont, /* complain_on_overflow */
816 bfd_elf_generic_reloc, /* special_function */
817 AARCH64_R_STR (ADR_GOT_PAGE), /* name */
818 FALSE, /* partial_inplace */
819 0x1fffff, /* src_mask */
820 0x1fffff, /* dst_mask */
821 TRUE), /* pcrel_offset */
823 /* LD64: GOT offset G(S) & 0xff8 */
824 HOWTO64 (AARCH64_R (LD64_GOT_LO12_NC), /* type */
826 2, /* size (0 = byte, 1 = short, 2 = long) */
828 FALSE, /* pc_relative */
830 complain_overflow_dont, /* complain_on_overflow */
831 bfd_elf_generic_reloc, /* special_function */
832 AARCH64_R_STR (LD64_GOT_LO12_NC), /* name */
833 FALSE, /* partial_inplace */
834 0xff8, /* src_mask */
835 0xff8, /* dst_mask */
836 FALSE), /* pcrel_offset */
838 /* LD32: GOT offset G(S) & 0xffc */
839 HOWTO32 (AARCH64_R (LD32_GOT_LO12_NC), /* type */
841 2, /* size (0 = byte, 1 = short, 2 = long) */
843 FALSE, /* pc_relative */
845 complain_overflow_dont, /* complain_on_overflow */
846 bfd_elf_generic_reloc, /* special_function */
847 AARCH64_R_STR (LD32_GOT_LO12_NC), /* name */
848 FALSE, /* partial_inplace */
849 0xffc, /* src_mask */
850 0xffc, /* dst_mask */
851 FALSE), /* pcrel_offset */
853 /* LD64: GOT offset for the symbol. */
854 HOWTO64 (AARCH64_R (LD64_GOTOFF_LO15), /* type */
856 2, /* size (0 = byte, 1 = short, 2 = long) */
858 FALSE, /* pc_relative */
860 complain_overflow_unsigned, /* complain_on_overflow */
861 bfd_elf_generic_reloc, /* special_function */
862 AARCH64_R_STR (LD64_GOTOFF_LO15), /* name */
863 FALSE, /* partial_inplace */
864 0x7ff8, /* src_mask */
865 0x7ff8, /* dst_mask */
866 FALSE), /* pcrel_offset */
868 /* LD32: GOT offset to the page address of GOT table.
869 (G(S) - PAGE (_GLOBAL_OFFSET_TABLE_)) & 0x5ffc. */
870 HOWTO32 (AARCH64_R (LD32_GOTPAGE_LO14), /* 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 (LD32_GOTPAGE_LO14), /* name */
879 FALSE, /* partial_inplace */
880 0x5ffc, /* src_mask */
881 0x5ffc, /* dst_mask */
882 FALSE), /* pcrel_offset */
884 /* LD64: GOT offset to the page address of GOT table.
885 (G(S) - PAGE (_GLOBAL_OFFSET_TABLE_)) & 0x7ff8. */
886 HOWTO64 (AARCH64_R (LD64_GOTPAGE_LO15), /* 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 (LD64_GOTPAGE_LO15), /* name */
895 FALSE, /* partial_inplace */
896 0x7ff8, /* src_mask */
897 0x7ff8, /* dst_mask */
898 FALSE), /* pcrel_offset */
900 /* Get to the page for the GOT entry for the symbol
901 (G(S) - P) using an ADRP instruction. */
902 HOWTO (AARCH64_R (TLSGD_ADR_PAGE21), /* type */
904 2, /* size (0 = byte, 1 = short, 2 = long) */
906 TRUE, /* pc_relative */
908 complain_overflow_dont, /* complain_on_overflow */
909 bfd_elf_generic_reloc, /* special_function */
910 AARCH64_R_STR (TLSGD_ADR_PAGE21), /* name */
911 FALSE, /* partial_inplace */
912 0x1fffff, /* src_mask */
913 0x1fffff, /* dst_mask */
914 TRUE), /* pcrel_offset */
916 HOWTO (AARCH64_R (TLSGD_ADR_PREL21), /* type */
918 2, /* size (0 = byte, 1 = short, 2 = long) */
920 TRUE, /* pc_relative */
922 complain_overflow_dont, /* complain_on_overflow */
923 bfd_elf_generic_reloc, /* special_function */
924 AARCH64_R_STR (TLSGD_ADR_PREL21), /* name */
925 FALSE, /* partial_inplace */
926 0x1fffff, /* src_mask */
927 0x1fffff, /* dst_mask */
928 TRUE), /* pcrel_offset */
930 /* ADD: GOT offset G(S) & 0xff8 [no overflow check] */
931 HOWTO (AARCH64_R (TLSGD_ADD_LO12_NC), /* type */
933 2, /* size (0 = byte, 1 = short, 2 = long) */
935 FALSE, /* pc_relative */
937 complain_overflow_dont, /* complain_on_overflow */
938 bfd_elf_generic_reloc, /* special_function */
939 AARCH64_R_STR (TLSGD_ADD_LO12_NC), /* name */
940 FALSE, /* partial_inplace */
941 0xfff, /* src_mask */
942 0xfff, /* dst_mask */
943 FALSE), /* pcrel_offset */
945 HOWTO64 (AARCH64_R (TLSIE_MOVW_GOTTPREL_G1), /* type */
947 2, /* size (0 = byte, 1 = short, 2 = long) */
949 FALSE, /* pc_relative */
951 complain_overflow_dont, /* complain_on_overflow */
952 bfd_elf_generic_reloc, /* special_function */
953 AARCH64_R_STR (TLSIE_MOVW_GOTTPREL_G1), /* name */
954 FALSE, /* partial_inplace */
955 0xffff, /* src_mask */
956 0xffff, /* dst_mask */
957 FALSE), /* pcrel_offset */
959 HOWTO64 (AARCH64_R (TLSIE_MOVW_GOTTPREL_G0_NC), /* type */
961 2, /* size (0 = byte, 1 = short, 2 = long) */
963 FALSE, /* pc_relative */
965 complain_overflow_dont, /* complain_on_overflow */
966 bfd_elf_generic_reloc, /* special_function */
967 AARCH64_R_STR (TLSIE_MOVW_GOTTPREL_G0_NC), /* name */
968 FALSE, /* partial_inplace */
969 0xffff, /* src_mask */
970 0xffff, /* dst_mask */
971 FALSE), /* pcrel_offset */
973 HOWTO (AARCH64_R (TLSIE_ADR_GOTTPREL_PAGE21), /* type */
975 2, /* size (0 = byte, 1 = short, 2 = long) */
977 FALSE, /* pc_relative */
979 complain_overflow_dont, /* complain_on_overflow */
980 bfd_elf_generic_reloc, /* special_function */
981 AARCH64_R_STR (TLSIE_ADR_GOTTPREL_PAGE21), /* name */
982 FALSE, /* partial_inplace */
983 0x1fffff, /* src_mask */
984 0x1fffff, /* dst_mask */
985 FALSE), /* pcrel_offset */
987 HOWTO64 (AARCH64_R (TLSIE_LD64_GOTTPREL_LO12_NC), /* type */
989 2, /* size (0 = byte, 1 = short, 2 = long) */
991 FALSE, /* pc_relative */
993 complain_overflow_dont, /* complain_on_overflow */
994 bfd_elf_generic_reloc, /* special_function */
995 AARCH64_R_STR (TLSIE_LD64_GOTTPREL_LO12_NC), /* name */
996 FALSE, /* partial_inplace */
997 0xff8, /* src_mask */
998 0xff8, /* dst_mask */
999 FALSE), /* pcrel_offset */
1001 HOWTO32 (AARCH64_R (TLSIE_LD32_GOTTPREL_LO12_NC), /* type */
1003 2, /* size (0 = byte, 1 = short, 2 = long) */
1005 FALSE, /* pc_relative */
1007 complain_overflow_dont, /* complain_on_overflow */
1008 bfd_elf_generic_reloc, /* special_function */
1009 AARCH64_R_STR (TLSIE_LD32_GOTTPREL_LO12_NC), /* name */
1010 FALSE, /* partial_inplace */
1011 0xffc, /* src_mask */
1012 0xffc, /* dst_mask */
1013 FALSE), /* pcrel_offset */
1015 HOWTO (AARCH64_R (TLSIE_LD_GOTTPREL_PREL19), /* type */
1017 2, /* size (0 = byte, 1 = short, 2 = long) */
1019 FALSE, /* pc_relative */
1021 complain_overflow_dont, /* complain_on_overflow */
1022 bfd_elf_generic_reloc, /* special_function */
1023 AARCH64_R_STR (TLSIE_LD_GOTTPREL_PREL19), /* name */
1024 FALSE, /* partial_inplace */
1025 0x1ffffc, /* src_mask */
1026 0x1ffffc, /* dst_mask */
1027 FALSE), /* pcrel_offset */
1029 /* Get to the page for the GOT entry for the symbol
1030 (G(S) - P) using an ADRP instruction. */
1031 HOWTO (AARCH64_R (TLSLD_ADR_PAGE21), /* type */
1032 12, /* rightshift */
1033 2, /* size (0 = byte, 1 = short, 2 = long) */
1035 TRUE, /* pc_relative */
1037 complain_overflow_signed, /* complain_on_overflow */
1038 bfd_elf_generic_reloc, /* special_function */
1039 AARCH64_R_STR (TLSLD_ADR_PAGE21), /* name */
1040 FALSE, /* partial_inplace */
1041 0x1fffff, /* src_mask */
1042 0x1fffff, /* dst_mask */
1043 TRUE), /* pcrel_offset */
1045 HOWTO (AARCH64_R (TLSLD_ADR_PREL21), /* type */
1047 2, /* size (0 = byte, 1 = short, 2 = long) */
1049 TRUE, /* pc_relative */
1051 complain_overflow_signed, /* complain_on_overflow */
1052 bfd_elf_generic_reloc, /* special_function */
1053 AARCH64_R_STR (TLSLD_ADR_PREL21), /* name */
1054 FALSE, /* partial_inplace */
1055 0x1fffff, /* src_mask */
1056 0x1fffff, /* dst_mask */
1057 TRUE), /* pcrel_offset */
1059 HOWTO64 (AARCH64_R (TLSLE_MOVW_TPREL_G2), /* type */
1060 32, /* rightshift */
1061 2, /* size (0 = byte, 1 = short, 2 = long) */
1063 FALSE, /* pc_relative */
1065 complain_overflow_unsigned, /* complain_on_overflow */
1066 bfd_elf_generic_reloc, /* special_function */
1067 AARCH64_R_STR (TLSLE_MOVW_TPREL_G2), /* name */
1068 FALSE, /* partial_inplace */
1069 0xffff, /* src_mask */
1070 0xffff, /* dst_mask */
1071 FALSE), /* pcrel_offset */
1073 HOWTO (AARCH64_R (TLSLE_MOVW_TPREL_G1), /* type */
1074 16, /* rightshift */
1075 2, /* size (0 = byte, 1 = short, 2 = long) */
1077 FALSE, /* pc_relative */
1079 complain_overflow_dont, /* complain_on_overflow */
1080 bfd_elf_generic_reloc, /* special_function */
1081 AARCH64_R_STR (TLSLE_MOVW_TPREL_G1), /* name */
1082 FALSE, /* partial_inplace */
1083 0xffff, /* src_mask */
1084 0xffff, /* dst_mask */
1085 FALSE), /* pcrel_offset */
1087 HOWTO64 (AARCH64_R (TLSLE_MOVW_TPREL_G1_NC), /* type */
1088 16, /* rightshift */
1089 2, /* size (0 = byte, 1 = short, 2 = long) */
1091 FALSE, /* pc_relative */
1093 complain_overflow_dont, /* complain_on_overflow */
1094 bfd_elf_generic_reloc, /* special_function */
1095 AARCH64_R_STR (TLSLE_MOVW_TPREL_G1_NC), /* name */
1096 FALSE, /* partial_inplace */
1097 0xffff, /* src_mask */
1098 0xffff, /* dst_mask */
1099 FALSE), /* pcrel_offset */
1101 HOWTO (AARCH64_R (TLSLE_MOVW_TPREL_G0), /* type */
1103 2, /* size (0 = byte, 1 = short, 2 = long) */
1105 FALSE, /* pc_relative */
1107 complain_overflow_dont, /* complain_on_overflow */
1108 bfd_elf_generic_reloc, /* special_function */
1109 AARCH64_R_STR (TLSLE_MOVW_TPREL_G0), /* name */
1110 FALSE, /* partial_inplace */
1111 0xffff, /* src_mask */
1112 0xffff, /* dst_mask */
1113 FALSE), /* pcrel_offset */
1115 HOWTO (AARCH64_R (TLSLE_MOVW_TPREL_G0_NC), /* type */
1117 2, /* size (0 = byte, 1 = short, 2 = long) */
1119 FALSE, /* pc_relative */
1121 complain_overflow_dont, /* complain_on_overflow */
1122 bfd_elf_generic_reloc, /* special_function */
1123 AARCH64_R_STR (TLSLE_MOVW_TPREL_G0_NC), /* name */
1124 FALSE, /* partial_inplace */
1125 0xffff, /* src_mask */
1126 0xffff, /* dst_mask */
1127 FALSE), /* pcrel_offset */
1129 HOWTO (AARCH64_R (TLSLE_ADD_TPREL_HI12), /* type */
1130 12, /* rightshift */
1131 2, /* size (0 = byte, 1 = short, 2 = long) */
1133 FALSE, /* pc_relative */
1135 complain_overflow_unsigned, /* complain_on_overflow */
1136 bfd_elf_generic_reloc, /* special_function */
1137 AARCH64_R_STR (TLSLE_ADD_TPREL_HI12), /* name */
1138 FALSE, /* partial_inplace */
1139 0xfff, /* src_mask */
1140 0xfff, /* dst_mask */
1141 FALSE), /* pcrel_offset */
1143 HOWTO (AARCH64_R (TLSLE_ADD_TPREL_LO12), /* type */
1145 2, /* size (0 = byte, 1 = short, 2 = long) */
1147 FALSE, /* pc_relative */
1149 complain_overflow_unsigned, /* complain_on_overflow */
1150 bfd_elf_generic_reloc, /* special_function */
1151 AARCH64_R_STR (TLSLE_ADD_TPREL_LO12), /* name */
1152 FALSE, /* partial_inplace */
1153 0xfff, /* src_mask */
1154 0xfff, /* dst_mask */
1155 FALSE), /* pcrel_offset */
1157 HOWTO (AARCH64_R (TLSLE_ADD_TPREL_LO12_NC), /* type */
1159 2, /* size (0 = byte, 1 = short, 2 = long) */
1161 FALSE, /* pc_relative */
1163 complain_overflow_dont, /* complain_on_overflow */
1164 bfd_elf_generic_reloc, /* special_function */
1165 AARCH64_R_STR (TLSLE_ADD_TPREL_LO12_NC), /* name */
1166 FALSE, /* partial_inplace */
1167 0xfff, /* src_mask */
1168 0xfff, /* dst_mask */
1169 FALSE), /* pcrel_offset */
1171 HOWTO (AARCH64_R (TLSDESC_LD_PREL19), /* type */
1173 2, /* size (0 = byte, 1 = short, 2 = long) */
1175 TRUE, /* pc_relative */
1177 complain_overflow_dont, /* complain_on_overflow */
1178 bfd_elf_generic_reloc, /* special_function */
1179 AARCH64_R_STR (TLSDESC_LD_PREL19), /* name */
1180 FALSE, /* partial_inplace */
1181 0x0ffffe0, /* src_mask */
1182 0x0ffffe0, /* dst_mask */
1183 TRUE), /* pcrel_offset */
1185 HOWTO (AARCH64_R (TLSDESC_ADR_PREL21), /* type */
1187 2, /* size (0 = byte, 1 = short, 2 = long) */
1189 TRUE, /* pc_relative */
1191 complain_overflow_dont, /* complain_on_overflow */
1192 bfd_elf_generic_reloc, /* special_function */
1193 AARCH64_R_STR (TLSDESC_ADR_PREL21), /* name */
1194 FALSE, /* partial_inplace */
1195 0x1fffff, /* src_mask */
1196 0x1fffff, /* dst_mask */
1197 TRUE), /* pcrel_offset */
1199 /* Get to the page for the GOT entry for the symbol
1200 (G(S) - P) using an ADRP instruction. */
1201 HOWTO (AARCH64_R (TLSDESC_ADR_PAGE21), /* type */
1202 12, /* rightshift */
1203 2, /* size (0 = byte, 1 = short, 2 = long) */
1205 TRUE, /* pc_relative */
1207 complain_overflow_dont, /* complain_on_overflow */
1208 bfd_elf_generic_reloc, /* special_function */
1209 AARCH64_R_STR (TLSDESC_ADR_PAGE21), /* name */
1210 FALSE, /* partial_inplace */
1211 0x1fffff, /* src_mask */
1212 0x1fffff, /* dst_mask */
1213 TRUE), /* pcrel_offset */
1215 /* LD64: GOT offset G(S) & 0xff8. */
1216 HOWTO64 (AARCH64_R (TLSDESC_LD64_LO12_NC), /* type */
1218 2, /* size (0 = byte, 1 = short, 2 = long) */
1220 FALSE, /* pc_relative */
1222 complain_overflow_dont, /* complain_on_overflow */
1223 bfd_elf_generic_reloc, /* special_function */
1224 AARCH64_R_STR (TLSDESC_LD64_LO12_NC), /* name */
1225 FALSE, /* partial_inplace */
1226 0xff8, /* src_mask */
1227 0xff8, /* dst_mask */
1228 FALSE), /* pcrel_offset */
1230 /* LD32: GOT offset G(S) & 0xffc. */
1231 HOWTO32 (AARCH64_R (TLSDESC_LD32_LO12_NC), /* type */
1233 2, /* size (0 = byte, 1 = short, 2 = long) */
1235 FALSE, /* pc_relative */
1237 complain_overflow_dont, /* complain_on_overflow */
1238 bfd_elf_generic_reloc, /* special_function */
1239 AARCH64_R_STR (TLSDESC_LD32_LO12_NC), /* name */
1240 FALSE, /* partial_inplace */
1241 0xffc, /* src_mask */
1242 0xffc, /* dst_mask */
1243 FALSE), /* pcrel_offset */
1245 /* ADD: GOT offset G(S) & 0xfff. */
1246 HOWTO (AARCH64_R (TLSDESC_ADD_LO12_NC), /* type */
1248 2, /* size (0 = byte, 1 = short, 2 = long) */
1250 FALSE, /* pc_relative */
1252 complain_overflow_dont, /* complain_on_overflow */
1253 bfd_elf_generic_reloc, /* special_function */
1254 AARCH64_R_STR (TLSDESC_ADD_LO12_NC), /* name */
1255 FALSE, /* partial_inplace */
1256 0xfff, /* src_mask */
1257 0xfff, /* dst_mask */
1258 FALSE), /* pcrel_offset */
1260 HOWTO64 (AARCH64_R (TLSDESC_OFF_G1), /* type */
1261 16, /* rightshift */
1262 2, /* size (0 = byte, 1 = short, 2 = long) */
1264 FALSE, /* pc_relative */
1266 complain_overflow_dont, /* complain_on_overflow */
1267 bfd_elf_generic_reloc, /* special_function */
1268 AARCH64_R_STR (TLSDESC_OFF_G1), /* name */
1269 FALSE, /* partial_inplace */
1270 0xffff, /* src_mask */
1271 0xffff, /* dst_mask */
1272 FALSE), /* pcrel_offset */
1274 HOWTO64 (AARCH64_R (TLSDESC_OFF_G0_NC), /* type */
1276 2, /* size (0 = byte, 1 = short, 2 = long) */
1278 FALSE, /* pc_relative */
1280 complain_overflow_dont, /* complain_on_overflow */
1281 bfd_elf_generic_reloc, /* special_function */
1282 AARCH64_R_STR (TLSDESC_OFF_G0_NC), /* name */
1283 FALSE, /* partial_inplace */
1284 0xffff, /* src_mask */
1285 0xffff, /* dst_mask */
1286 FALSE), /* pcrel_offset */
1288 HOWTO64 (AARCH64_R (TLSDESC_LDR), /* type */
1290 2, /* size (0 = byte, 1 = short, 2 = long) */
1292 FALSE, /* pc_relative */
1294 complain_overflow_dont, /* complain_on_overflow */
1295 bfd_elf_generic_reloc, /* special_function */
1296 AARCH64_R_STR (TLSDESC_LDR), /* name */
1297 FALSE, /* partial_inplace */
1300 FALSE), /* pcrel_offset */
1302 HOWTO64 (AARCH64_R (TLSDESC_ADD), /* type */
1304 2, /* size (0 = byte, 1 = short, 2 = long) */
1306 FALSE, /* pc_relative */
1308 complain_overflow_dont, /* complain_on_overflow */
1309 bfd_elf_generic_reloc, /* special_function */
1310 AARCH64_R_STR (TLSDESC_ADD), /* name */
1311 FALSE, /* partial_inplace */
1314 FALSE), /* pcrel_offset */
1316 HOWTO (AARCH64_R (TLSDESC_CALL), /* type */
1318 2, /* size (0 = byte, 1 = short, 2 = long) */
1320 FALSE, /* pc_relative */
1322 complain_overflow_dont, /* complain_on_overflow */
1323 bfd_elf_generic_reloc, /* special_function */
1324 AARCH64_R_STR (TLSDESC_CALL), /* name */
1325 FALSE, /* partial_inplace */
1328 FALSE), /* pcrel_offset */
1330 HOWTO (AARCH64_R (COPY), /* type */
1332 2, /* size (0 = byte, 1 = short, 2 = long) */
1334 FALSE, /* pc_relative */
1336 complain_overflow_bitfield, /* complain_on_overflow */
1337 bfd_elf_generic_reloc, /* special_function */
1338 AARCH64_R_STR (COPY), /* name */
1339 TRUE, /* partial_inplace */
1340 0xffffffff, /* src_mask */
1341 0xffffffff, /* dst_mask */
1342 FALSE), /* pcrel_offset */
1344 HOWTO (AARCH64_R (GLOB_DAT), /* type */
1346 2, /* size (0 = byte, 1 = short, 2 = long) */
1348 FALSE, /* pc_relative */
1350 complain_overflow_bitfield, /* complain_on_overflow */
1351 bfd_elf_generic_reloc, /* special_function */
1352 AARCH64_R_STR (GLOB_DAT), /* name */
1353 TRUE, /* partial_inplace */
1354 0xffffffff, /* src_mask */
1355 0xffffffff, /* dst_mask */
1356 FALSE), /* pcrel_offset */
1358 HOWTO (AARCH64_R (JUMP_SLOT), /* type */
1360 2, /* size (0 = byte, 1 = short, 2 = long) */
1362 FALSE, /* pc_relative */
1364 complain_overflow_bitfield, /* complain_on_overflow */
1365 bfd_elf_generic_reloc, /* special_function */
1366 AARCH64_R_STR (JUMP_SLOT), /* name */
1367 TRUE, /* partial_inplace */
1368 0xffffffff, /* src_mask */
1369 0xffffffff, /* dst_mask */
1370 FALSE), /* pcrel_offset */
1372 HOWTO (AARCH64_R (RELATIVE), /* type */
1374 2, /* size (0 = byte, 1 = short, 2 = long) */
1376 FALSE, /* pc_relative */
1378 complain_overflow_bitfield, /* complain_on_overflow */
1379 bfd_elf_generic_reloc, /* special_function */
1380 AARCH64_R_STR (RELATIVE), /* name */
1381 TRUE, /* partial_inplace */
1382 ALL_ONES, /* src_mask */
1383 ALL_ONES, /* dst_mask */
1384 FALSE), /* pcrel_offset */
1386 HOWTO (AARCH64_R (TLS_DTPMOD), /* type */
1388 2, /* size (0 = byte, 1 = short, 2 = long) */
1390 FALSE, /* pc_relative */
1392 complain_overflow_dont, /* complain_on_overflow */
1393 bfd_elf_generic_reloc, /* special_function */
1395 AARCH64_R_STR (TLS_DTPMOD64), /* name */
1397 AARCH64_R_STR (TLS_DTPMOD), /* name */
1399 FALSE, /* partial_inplace */
1401 ALL_ONES, /* dst_mask */
1402 FALSE), /* pc_reloffset */
1404 HOWTO (AARCH64_R (TLS_DTPREL), /* type */
1406 2, /* size (0 = byte, 1 = short, 2 = long) */
1408 FALSE, /* pc_relative */
1410 complain_overflow_dont, /* complain_on_overflow */
1411 bfd_elf_generic_reloc, /* special_function */
1413 AARCH64_R_STR (TLS_DTPREL64), /* name */
1415 AARCH64_R_STR (TLS_DTPREL), /* name */
1417 FALSE, /* partial_inplace */
1419 ALL_ONES, /* dst_mask */
1420 FALSE), /* pcrel_offset */
1422 HOWTO (AARCH64_R (TLS_TPREL), /* type */
1424 2, /* size (0 = byte, 1 = short, 2 = long) */
1426 FALSE, /* pc_relative */
1428 complain_overflow_dont, /* complain_on_overflow */
1429 bfd_elf_generic_reloc, /* special_function */
1431 AARCH64_R_STR (TLS_TPREL64), /* name */
1433 AARCH64_R_STR (TLS_TPREL), /* name */
1435 FALSE, /* partial_inplace */
1437 ALL_ONES, /* dst_mask */
1438 FALSE), /* pcrel_offset */
1440 HOWTO (AARCH64_R (TLSDESC), /* type */
1442 2, /* size (0 = byte, 1 = short, 2 = long) */
1444 FALSE, /* pc_relative */
1446 complain_overflow_dont, /* complain_on_overflow */
1447 bfd_elf_generic_reloc, /* special_function */
1448 AARCH64_R_STR (TLSDESC), /* name */
1449 FALSE, /* partial_inplace */
1451 ALL_ONES, /* dst_mask */
1452 FALSE), /* pcrel_offset */
1454 HOWTO (AARCH64_R (IRELATIVE), /* type */
1456 2, /* size (0 = byte, 1 = short, 2 = long) */
1458 FALSE, /* pc_relative */
1460 complain_overflow_bitfield, /* complain_on_overflow */
1461 bfd_elf_generic_reloc, /* special_function */
1462 AARCH64_R_STR (IRELATIVE), /* name */
1463 FALSE, /* partial_inplace */
1465 ALL_ONES, /* dst_mask */
1466 FALSE), /* pcrel_offset */
1471 static reloc_howto_type elfNN_aarch64_howto_none =
1472 HOWTO (R_AARCH64_NONE, /* type */
1474 3, /* size (0 = byte, 1 = short, 2 = long) */
1476 FALSE, /* pc_relative */
1478 complain_overflow_dont,/* complain_on_overflow */
1479 bfd_elf_generic_reloc, /* special_function */
1480 "R_AARCH64_NONE", /* name */
1481 FALSE, /* partial_inplace */
1484 FALSE); /* pcrel_offset */
1486 /* Given HOWTO, return the bfd internal relocation enumerator. */
1488 static bfd_reloc_code_real_type
1489 elfNN_aarch64_bfd_reloc_from_howto (reloc_howto_type *howto)
1492 = (int) ARRAY_SIZE (elfNN_aarch64_howto_table);
1493 const ptrdiff_t offset
1494 = howto - elfNN_aarch64_howto_table;
1496 if (offset > 0 && offset < size - 1)
1497 return BFD_RELOC_AARCH64_RELOC_START + offset;
1499 if (howto == &elfNN_aarch64_howto_none)
1500 return BFD_RELOC_AARCH64_NONE;
1502 return BFD_RELOC_AARCH64_RELOC_START;
1505 /* Given R_TYPE, return the bfd internal relocation enumerator. */
1507 static bfd_reloc_code_real_type
1508 elfNN_aarch64_bfd_reloc_from_type (unsigned int r_type)
1510 static bfd_boolean initialized_p = FALSE;
1511 /* Indexed by R_TYPE, values are offsets in the howto_table. */
1512 static unsigned int offsets[R_AARCH64_end];
1514 if (initialized_p == FALSE)
1518 for (i = 1; i < ARRAY_SIZE (elfNN_aarch64_howto_table) - 1; ++i)
1519 if (elfNN_aarch64_howto_table[i].type != 0)
1520 offsets[elfNN_aarch64_howto_table[i].type] = i;
1522 initialized_p = TRUE;
1525 if (r_type == R_AARCH64_NONE || r_type == R_AARCH64_NULL)
1526 return BFD_RELOC_AARCH64_NONE;
1528 /* PR 17512: file: b371e70a. */
1529 if (r_type >= R_AARCH64_end)
1531 _bfd_error_handler (_("Invalid AArch64 reloc number: %d"), r_type);
1532 bfd_set_error (bfd_error_bad_value);
1533 return BFD_RELOC_AARCH64_NONE;
1536 return BFD_RELOC_AARCH64_RELOC_START + offsets[r_type];
1539 struct elf_aarch64_reloc_map
1541 bfd_reloc_code_real_type from;
1542 bfd_reloc_code_real_type to;
1545 /* Map bfd generic reloc to AArch64-specific reloc. */
1546 static const struct elf_aarch64_reloc_map elf_aarch64_reloc_map[] =
1548 {BFD_RELOC_NONE, BFD_RELOC_AARCH64_NONE},
1550 /* Basic data relocations. */
1551 {BFD_RELOC_CTOR, BFD_RELOC_AARCH64_NN},
1552 {BFD_RELOC_64, BFD_RELOC_AARCH64_64},
1553 {BFD_RELOC_32, BFD_RELOC_AARCH64_32},
1554 {BFD_RELOC_16, BFD_RELOC_AARCH64_16},
1555 {BFD_RELOC_64_PCREL, BFD_RELOC_AARCH64_64_PCREL},
1556 {BFD_RELOC_32_PCREL, BFD_RELOC_AARCH64_32_PCREL},
1557 {BFD_RELOC_16_PCREL, BFD_RELOC_AARCH64_16_PCREL},
1560 /* Given the bfd internal relocation enumerator in CODE, return the
1561 corresponding howto entry. */
1563 static reloc_howto_type *
1564 elfNN_aarch64_howto_from_bfd_reloc (bfd_reloc_code_real_type code)
1568 /* Convert bfd generic reloc to AArch64-specific reloc. */
1569 if (code < BFD_RELOC_AARCH64_RELOC_START
1570 || code > BFD_RELOC_AARCH64_RELOC_END)
1571 for (i = 0; i < ARRAY_SIZE (elf_aarch64_reloc_map); i++)
1572 if (elf_aarch64_reloc_map[i].from == code)
1574 code = elf_aarch64_reloc_map[i].to;
1578 if (code > BFD_RELOC_AARCH64_RELOC_START
1579 && code < BFD_RELOC_AARCH64_RELOC_END)
1580 if (elfNN_aarch64_howto_table[code - BFD_RELOC_AARCH64_RELOC_START].type)
1581 return &elfNN_aarch64_howto_table[code - BFD_RELOC_AARCH64_RELOC_START];
1583 if (code == BFD_RELOC_AARCH64_NONE)
1584 return &elfNN_aarch64_howto_none;
1589 static reloc_howto_type *
1590 elfNN_aarch64_howto_from_type (unsigned int r_type)
1592 bfd_reloc_code_real_type val;
1593 reloc_howto_type *howto;
1598 bfd_set_error (bfd_error_bad_value);
1603 if (r_type == R_AARCH64_NONE)
1604 return &elfNN_aarch64_howto_none;
1606 val = elfNN_aarch64_bfd_reloc_from_type (r_type);
1607 howto = elfNN_aarch64_howto_from_bfd_reloc (val);
1612 bfd_set_error (bfd_error_bad_value);
1617 elfNN_aarch64_info_to_howto (bfd *abfd ATTRIBUTE_UNUSED, arelent *bfd_reloc,
1618 Elf_Internal_Rela *elf_reloc)
1620 unsigned int r_type;
1622 r_type = ELFNN_R_TYPE (elf_reloc->r_info);
1623 bfd_reloc->howto = elfNN_aarch64_howto_from_type (r_type);
1626 static reloc_howto_type *
1627 elfNN_aarch64_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED,
1628 bfd_reloc_code_real_type code)
1630 reloc_howto_type *howto = elfNN_aarch64_howto_from_bfd_reloc (code);
1635 bfd_set_error (bfd_error_bad_value);
1639 static reloc_howto_type *
1640 elfNN_aarch64_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED,
1645 for (i = 1; i < ARRAY_SIZE (elfNN_aarch64_howto_table) - 1; ++i)
1646 if (elfNN_aarch64_howto_table[i].name != NULL
1647 && strcasecmp (elfNN_aarch64_howto_table[i].name, r_name) == 0)
1648 return &elfNN_aarch64_howto_table[i];
1653 #define TARGET_LITTLE_SYM aarch64_elfNN_le_vec
1654 #define TARGET_LITTLE_NAME "elfNN-littleaarch64"
1655 #define TARGET_BIG_SYM aarch64_elfNN_be_vec
1656 #define TARGET_BIG_NAME "elfNN-bigaarch64"
1658 /* The linker script knows the section names for placement.
1659 The entry_names are used to do simple name mangling on the stubs.
1660 Given a function name, and its type, the stub can be found. The
1661 name can be changed. The only requirement is the %s be present. */
1662 #define STUB_ENTRY_NAME "__%s_veneer"
1664 /* The name of the dynamic interpreter. This is put in the .interp
1666 #define ELF_DYNAMIC_INTERPRETER "/lib/ld.so.1"
1668 #define AARCH64_MAX_FWD_BRANCH_OFFSET \
1669 (((1 << 25) - 1) << 2)
1670 #define AARCH64_MAX_BWD_BRANCH_OFFSET \
1673 #define AARCH64_MAX_ADRP_IMM ((1 << 20) - 1)
1674 #define AARCH64_MIN_ADRP_IMM (-(1 << 20))
1677 aarch64_valid_for_adrp_p (bfd_vma value, bfd_vma place)
1679 bfd_signed_vma offset = (bfd_signed_vma) (PG (value) - PG (place)) >> 12;
1680 return offset <= AARCH64_MAX_ADRP_IMM && offset >= AARCH64_MIN_ADRP_IMM;
1684 aarch64_valid_branch_p (bfd_vma value, bfd_vma place)
1686 bfd_signed_vma offset = (bfd_signed_vma) (value - place);
1687 return (offset <= AARCH64_MAX_FWD_BRANCH_OFFSET
1688 && offset >= AARCH64_MAX_BWD_BRANCH_OFFSET);
1691 static const uint32_t aarch64_adrp_branch_stub [] =
1693 0x90000010, /* adrp ip0, X */
1694 /* R_AARCH64_ADR_HI21_PCREL(X) */
1695 0x91000210, /* add ip0, ip0, :lo12:X */
1696 /* R_AARCH64_ADD_ABS_LO12_NC(X) */
1697 0xd61f0200, /* br ip0 */
1700 static const uint32_t aarch64_long_branch_stub[] =
1703 0x58000090, /* ldr ip0, 1f */
1705 0x18000090, /* ldr wip0, 1f */
1707 0x10000011, /* adr ip1, #0 */
1708 0x8b110210, /* add ip0, ip0, ip1 */
1709 0xd61f0200, /* br ip0 */
1710 0x00000000, /* 1: .xword or .word
1711 R_AARCH64_PRELNN(X) + 12
1716 static const uint32_t aarch64_erratum_835769_stub[] =
1718 0x00000000, /* Placeholder for multiply accumulate. */
1719 0x14000000, /* b <label> */
1722 static const uint32_t aarch64_erratum_843419_stub[] =
1724 0x00000000, /* Placeholder for LDR instruction. */
1725 0x14000000, /* b <label> */
1728 /* Section name for stubs is the associated section name plus this
1730 #define STUB_SUFFIX ".stub"
1732 enum elf_aarch64_stub_type
1735 aarch64_stub_adrp_branch,
1736 aarch64_stub_long_branch,
1737 aarch64_stub_erratum_835769_veneer,
1738 aarch64_stub_erratum_843419_veneer,
1741 struct elf_aarch64_stub_hash_entry
1743 /* Base hash table entry structure. */
1744 struct bfd_hash_entry root;
1746 /* The stub section. */
1749 /* Offset within stub_sec of the beginning of this stub. */
1750 bfd_vma stub_offset;
1752 /* Given the symbol's value and its section we can determine its final
1753 value when building the stubs (so the stub knows where to jump). */
1754 bfd_vma target_value;
1755 asection *target_section;
1757 enum elf_aarch64_stub_type stub_type;
1759 /* The symbol table entry, if any, that this was derived from. */
1760 struct elf_aarch64_link_hash_entry *h;
1762 /* Destination symbol type */
1763 unsigned char st_type;
1765 /* Where this stub is being called from, or, in the case of combined
1766 stub sections, the first input section in the group. */
1769 /* The name for the local symbol at the start of this stub. The
1770 stub name in the hash table has to be unique; this does not, so
1771 it can be friendlier. */
1774 /* The instruction which caused this stub to be generated (only valid for
1775 erratum 835769 workaround stubs at present). */
1776 uint32_t veneered_insn;
1778 /* In an erratum 843419 workaround stub, the ADRP instruction offset. */
1779 bfd_vma adrp_offset;
1782 /* Used to build a map of a section. This is required for mixed-endian
1785 typedef struct elf_elf_section_map
1790 elf_aarch64_section_map;
1793 typedef struct _aarch64_elf_section_data
1795 struct bfd_elf_section_data elf;
1796 unsigned int mapcount;
1797 unsigned int mapsize;
1798 elf_aarch64_section_map *map;
1800 _aarch64_elf_section_data;
1802 #define elf_aarch64_section_data(sec) \
1803 ((_aarch64_elf_section_data *) elf_section_data (sec))
1805 /* The size of the thread control block which is defined to be two pointers. */
1806 #define TCB_SIZE (ARCH_SIZE/8)*2
1808 struct elf_aarch64_local_symbol
1810 unsigned int got_type;
1811 bfd_signed_vma got_refcount;
1814 /* Offset of the GOTPLT entry reserved for the TLS descriptor. The
1815 offset is from the end of the jump table and reserved entries
1818 The magic value (bfd_vma) -1 indicates that an offset has not be
1820 bfd_vma tlsdesc_got_jump_table_offset;
1823 struct elf_aarch64_obj_tdata
1825 struct elf_obj_tdata root;
1827 /* local symbol descriptors */
1828 struct elf_aarch64_local_symbol *locals;
1830 /* Zero to warn when linking objects with incompatible enum sizes. */
1831 int no_enum_size_warning;
1833 /* Zero to warn when linking objects with incompatible wchar_t sizes. */
1834 int no_wchar_size_warning;
1837 #define elf_aarch64_tdata(bfd) \
1838 ((struct elf_aarch64_obj_tdata *) (bfd)->tdata.any)
1840 #define elf_aarch64_locals(bfd) (elf_aarch64_tdata (bfd)->locals)
1842 #define is_aarch64_elf(bfd) \
1843 (bfd_get_flavour (bfd) == bfd_target_elf_flavour \
1844 && elf_tdata (bfd) != NULL \
1845 && elf_object_id (bfd) == AARCH64_ELF_DATA)
1848 elfNN_aarch64_mkobject (bfd *abfd)
1850 return bfd_elf_allocate_object (abfd, sizeof (struct elf_aarch64_obj_tdata),
1854 #define elf_aarch64_hash_entry(ent) \
1855 ((struct elf_aarch64_link_hash_entry *)(ent))
1857 #define GOT_UNKNOWN 0
1858 #define GOT_NORMAL 1
1859 #define GOT_TLS_GD 2
1860 #define GOT_TLS_IE 4
1861 #define GOT_TLSDESC_GD 8
1863 #define GOT_TLS_GD_ANY_P(type) ((type & GOT_TLS_GD) || (type & GOT_TLSDESC_GD))
1865 /* AArch64 ELF linker hash entry. */
1866 struct elf_aarch64_link_hash_entry
1868 struct elf_link_hash_entry root;
1870 /* Track dynamic relocs copied for this symbol. */
1871 struct elf_dyn_relocs *dyn_relocs;
1873 /* Since PLT entries have variable size, we need to record the
1874 index into .got.plt instead of recomputing it from the PLT
1876 bfd_signed_vma plt_got_offset;
1878 /* Bit mask representing the type of GOT entry(s) if any required by
1880 unsigned int got_type;
1882 /* A pointer to the most recently used stub hash entry against this
1884 struct elf_aarch64_stub_hash_entry *stub_cache;
1886 /* Offset of the GOTPLT entry reserved for the TLS descriptor. The offset
1887 is from the end of the jump table and reserved entries within the PLTGOT.
1889 The magic value (bfd_vma) -1 indicates that an offset has not
1891 bfd_vma tlsdesc_got_jump_table_offset;
1895 elfNN_aarch64_symbol_got_type (struct elf_link_hash_entry *h,
1897 unsigned long r_symndx)
1900 return elf_aarch64_hash_entry (h)->got_type;
1902 if (! elf_aarch64_locals (abfd))
1905 return elf_aarch64_locals (abfd)[r_symndx].got_type;
1908 /* Get the AArch64 elf linker hash table from a link_info structure. */
1909 #define elf_aarch64_hash_table(info) \
1910 ((struct elf_aarch64_link_hash_table *) ((info)->hash))
1912 #define aarch64_stub_hash_lookup(table, string, create, copy) \
1913 ((struct elf_aarch64_stub_hash_entry *) \
1914 bfd_hash_lookup ((table), (string), (create), (copy)))
1916 /* AArch64 ELF linker hash table. */
1917 struct elf_aarch64_link_hash_table
1919 /* The main hash table. */
1920 struct elf_link_hash_table root;
1922 /* Nonzero to force PIC branch veneers. */
1925 /* Fix erratum 835769. */
1926 int fix_erratum_835769;
1928 /* Fix erratum 843419. */
1929 int fix_erratum_843419;
1931 /* Enable ADRP->ADR rewrite for erratum 843419 workaround. */
1932 int fix_erratum_843419_adr;
1934 /* The number of bytes in the initial entry in the PLT. */
1935 bfd_size_type plt_header_size;
1937 /* The number of bytes in the subsequent PLT etries. */
1938 bfd_size_type plt_entry_size;
1940 /* Short-cuts to get to dynamic linker sections. */
1944 /* Small local sym cache. */
1945 struct sym_cache sym_cache;
1947 /* For convenience in allocate_dynrelocs. */
1950 /* The amount of space used by the reserved portion of the sgotplt
1951 section, plus whatever space is used by the jump slots. */
1952 bfd_vma sgotplt_jump_table_size;
1954 /* The stub hash table. */
1955 struct bfd_hash_table stub_hash_table;
1957 /* Linker stub bfd. */
1960 /* Linker call-backs. */
1961 asection *(*add_stub_section) (const char *, asection *);
1962 void (*layout_sections_again) (void);
1964 /* Array to keep track of which stub sections have been created, and
1965 information on stub grouping. */
1968 /* This is the section to which stubs in the group will be
1971 /* The stub section. */
1975 /* Assorted information used by elfNN_aarch64_size_stubs. */
1976 unsigned int bfd_count;
1978 asection **input_list;
1980 /* The offset into splt of the PLT entry for the TLS descriptor
1981 resolver. Special values are 0, if not necessary (or not found
1982 to be necessary yet), and -1 if needed but not determined
1984 bfd_vma tlsdesc_plt;
1986 /* The GOT offset for the lazy trampoline. Communicated to the
1987 loader via DT_TLSDESC_GOT. The magic value (bfd_vma) -1
1988 indicates an offset is not allocated. */
1989 bfd_vma dt_tlsdesc_got;
1991 /* Used by local STT_GNU_IFUNC symbols. */
1992 htab_t loc_hash_table;
1993 void * loc_hash_memory;
1996 /* Create an entry in an AArch64 ELF linker hash table. */
1998 static struct bfd_hash_entry *
1999 elfNN_aarch64_link_hash_newfunc (struct bfd_hash_entry *entry,
2000 struct bfd_hash_table *table,
2003 struct elf_aarch64_link_hash_entry *ret =
2004 (struct elf_aarch64_link_hash_entry *) entry;
2006 /* Allocate the structure if it has not already been allocated by a
2009 ret = bfd_hash_allocate (table,
2010 sizeof (struct elf_aarch64_link_hash_entry));
2012 return (struct bfd_hash_entry *) ret;
2014 /* Call the allocation method of the superclass. */
2015 ret = ((struct elf_aarch64_link_hash_entry *)
2016 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry *) ret,
2020 ret->dyn_relocs = NULL;
2021 ret->got_type = GOT_UNKNOWN;
2022 ret->plt_got_offset = (bfd_vma) - 1;
2023 ret->stub_cache = NULL;
2024 ret->tlsdesc_got_jump_table_offset = (bfd_vma) - 1;
2027 return (struct bfd_hash_entry *) ret;
2030 /* Initialize an entry in the stub hash table. */
2032 static struct bfd_hash_entry *
2033 stub_hash_newfunc (struct bfd_hash_entry *entry,
2034 struct bfd_hash_table *table, const char *string)
2036 /* Allocate the structure if it has not already been allocated by a
2040 entry = bfd_hash_allocate (table,
2042 elf_aarch64_stub_hash_entry));
2047 /* Call the allocation method of the superclass. */
2048 entry = bfd_hash_newfunc (entry, table, string);
2051 struct elf_aarch64_stub_hash_entry *eh;
2053 /* Initialize the local fields. */
2054 eh = (struct elf_aarch64_stub_hash_entry *) entry;
2055 eh->adrp_offset = 0;
2056 eh->stub_sec = NULL;
2057 eh->stub_offset = 0;
2058 eh->target_value = 0;
2059 eh->target_section = NULL;
2060 eh->stub_type = aarch64_stub_none;
2068 /* Compute a hash of a local hash entry. We use elf_link_hash_entry
2069 for local symbol so that we can handle local STT_GNU_IFUNC symbols
2070 as global symbol. We reuse indx and dynstr_index for local symbol
2071 hash since they aren't used by global symbols in this backend. */
2074 elfNN_aarch64_local_htab_hash (const void *ptr)
2076 struct elf_link_hash_entry *h
2077 = (struct elf_link_hash_entry *) ptr;
2078 return ELF_LOCAL_SYMBOL_HASH (h->indx, h->dynstr_index);
2081 /* Compare local hash entries. */
2084 elfNN_aarch64_local_htab_eq (const void *ptr1, const void *ptr2)
2086 struct elf_link_hash_entry *h1
2087 = (struct elf_link_hash_entry *) ptr1;
2088 struct elf_link_hash_entry *h2
2089 = (struct elf_link_hash_entry *) ptr2;
2091 return h1->indx == h2->indx && h1->dynstr_index == h2->dynstr_index;
2094 /* Find and/or create a hash entry for local symbol. */
2096 static struct elf_link_hash_entry *
2097 elfNN_aarch64_get_local_sym_hash (struct elf_aarch64_link_hash_table *htab,
2098 bfd *abfd, const Elf_Internal_Rela *rel,
2101 struct elf_aarch64_link_hash_entry e, *ret;
2102 asection *sec = abfd->sections;
2103 hashval_t h = ELF_LOCAL_SYMBOL_HASH (sec->id,
2104 ELFNN_R_SYM (rel->r_info));
2107 e.root.indx = sec->id;
2108 e.root.dynstr_index = ELFNN_R_SYM (rel->r_info);
2109 slot = htab_find_slot_with_hash (htab->loc_hash_table, &e, h,
2110 create ? INSERT : NO_INSERT);
2117 ret = (struct elf_aarch64_link_hash_entry *) *slot;
2121 ret = (struct elf_aarch64_link_hash_entry *)
2122 objalloc_alloc ((struct objalloc *) htab->loc_hash_memory,
2123 sizeof (struct elf_aarch64_link_hash_entry));
2126 memset (ret, 0, sizeof (*ret));
2127 ret->root.indx = sec->id;
2128 ret->root.dynstr_index = ELFNN_R_SYM (rel->r_info);
2129 ret->root.dynindx = -1;
2135 /* Copy the extra info we tack onto an elf_link_hash_entry. */
2138 elfNN_aarch64_copy_indirect_symbol (struct bfd_link_info *info,
2139 struct elf_link_hash_entry *dir,
2140 struct elf_link_hash_entry *ind)
2142 struct elf_aarch64_link_hash_entry *edir, *eind;
2144 edir = (struct elf_aarch64_link_hash_entry *) dir;
2145 eind = (struct elf_aarch64_link_hash_entry *) ind;
2147 if (eind->dyn_relocs != NULL)
2149 if (edir->dyn_relocs != NULL)
2151 struct elf_dyn_relocs **pp;
2152 struct elf_dyn_relocs *p;
2154 /* Add reloc counts against the indirect sym to the direct sym
2155 list. Merge any entries against the same section. */
2156 for (pp = &eind->dyn_relocs; (p = *pp) != NULL;)
2158 struct elf_dyn_relocs *q;
2160 for (q = edir->dyn_relocs; q != NULL; q = q->next)
2161 if (q->sec == p->sec)
2163 q->pc_count += p->pc_count;
2164 q->count += p->count;
2171 *pp = edir->dyn_relocs;
2174 edir->dyn_relocs = eind->dyn_relocs;
2175 eind->dyn_relocs = NULL;
2178 if (ind->root.type == bfd_link_hash_indirect)
2180 /* Copy over PLT info. */
2181 if (dir->got.refcount <= 0)
2183 edir->got_type = eind->got_type;
2184 eind->got_type = GOT_UNKNOWN;
2188 _bfd_elf_link_hash_copy_indirect (info, dir, ind);
2191 /* Destroy an AArch64 elf linker hash table. */
2194 elfNN_aarch64_link_hash_table_free (bfd *obfd)
2196 struct elf_aarch64_link_hash_table *ret
2197 = (struct elf_aarch64_link_hash_table *) obfd->link.hash;
2199 if (ret->loc_hash_table)
2200 htab_delete (ret->loc_hash_table);
2201 if (ret->loc_hash_memory)
2202 objalloc_free ((struct objalloc *) ret->loc_hash_memory);
2204 bfd_hash_table_free (&ret->stub_hash_table);
2205 _bfd_elf_link_hash_table_free (obfd);
2208 /* Create an AArch64 elf linker hash table. */
2210 static struct bfd_link_hash_table *
2211 elfNN_aarch64_link_hash_table_create (bfd *abfd)
2213 struct elf_aarch64_link_hash_table *ret;
2214 bfd_size_type amt = sizeof (struct elf_aarch64_link_hash_table);
2216 ret = bfd_zmalloc (amt);
2220 if (!_bfd_elf_link_hash_table_init
2221 (&ret->root, abfd, elfNN_aarch64_link_hash_newfunc,
2222 sizeof (struct elf_aarch64_link_hash_entry), AARCH64_ELF_DATA))
2228 ret->plt_header_size = PLT_ENTRY_SIZE;
2229 ret->plt_entry_size = PLT_SMALL_ENTRY_SIZE;
2231 ret->dt_tlsdesc_got = (bfd_vma) - 1;
2233 if (!bfd_hash_table_init (&ret->stub_hash_table, stub_hash_newfunc,
2234 sizeof (struct elf_aarch64_stub_hash_entry)))
2236 _bfd_elf_link_hash_table_free (abfd);
2240 ret->loc_hash_table = htab_try_create (1024,
2241 elfNN_aarch64_local_htab_hash,
2242 elfNN_aarch64_local_htab_eq,
2244 ret->loc_hash_memory = objalloc_create ();
2245 if (!ret->loc_hash_table || !ret->loc_hash_memory)
2247 elfNN_aarch64_link_hash_table_free (abfd);
2250 ret->root.root.hash_table_free = elfNN_aarch64_link_hash_table_free;
2252 return &ret->root.root;
2256 aarch64_relocate (unsigned int r_type, bfd *input_bfd, asection *input_section,
2257 bfd_vma offset, bfd_vma value)
2259 reloc_howto_type *howto;
2262 howto = elfNN_aarch64_howto_from_type (r_type);
2263 place = (input_section->output_section->vma + input_section->output_offset
2266 r_type = elfNN_aarch64_bfd_reloc_from_type (r_type);
2267 value = _bfd_aarch64_elf_resolve_relocation (r_type, place, value, 0, FALSE);
2268 return _bfd_aarch64_elf_put_addend (input_bfd,
2269 input_section->contents + offset, r_type,
2273 static enum elf_aarch64_stub_type
2274 aarch64_select_branch_stub (bfd_vma value, bfd_vma place)
2276 if (aarch64_valid_for_adrp_p (value, place))
2277 return aarch64_stub_adrp_branch;
2278 return aarch64_stub_long_branch;
2281 /* Determine the type of stub needed, if any, for a call. */
2283 static enum elf_aarch64_stub_type
2284 aarch64_type_of_stub (struct bfd_link_info *info,
2285 asection *input_sec,
2286 const Elf_Internal_Rela *rel,
2287 unsigned char st_type,
2288 struct elf_aarch64_link_hash_entry *hash,
2289 bfd_vma destination)
2292 bfd_signed_vma branch_offset;
2293 unsigned int r_type;
2294 struct elf_aarch64_link_hash_table *globals;
2295 enum elf_aarch64_stub_type stub_type = aarch64_stub_none;
2296 bfd_boolean via_plt_p;
2298 if (st_type != STT_FUNC)
2301 globals = elf_aarch64_hash_table (info);
2302 via_plt_p = (globals->root.splt != NULL && hash != NULL
2303 && hash->root.plt.offset != (bfd_vma) - 1);
2308 /* Determine where the call point is. */
2309 location = (input_sec->output_offset
2310 + input_sec->output_section->vma + rel->r_offset);
2312 branch_offset = (bfd_signed_vma) (destination - location);
2314 r_type = ELFNN_R_TYPE (rel->r_info);
2316 /* We don't want to redirect any old unconditional jump in this way,
2317 only one which is being used for a sibcall, where it is
2318 acceptable for the IP0 and IP1 registers to be clobbered. */
2319 if ((r_type == AARCH64_R (CALL26) || r_type == AARCH64_R (JUMP26))
2320 && (branch_offset > AARCH64_MAX_FWD_BRANCH_OFFSET
2321 || branch_offset < AARCH64_MAX_BWD_BRANCH_OFFSET))
2323 stub_type = aarch64_stub_long_branch;
2329 /* Build a name for an entry in the stub hash table. */
2332 elfNN_aarch64_stub_name (const asection *input_section,
2333 const asection *sym_sec,
2334 const struct elf_aarch64_link_hash_entry *hash,
2335 const Elf_Internal_Rela *rel)
2342 len = 8 + 1 + strlen (hash->root.root.root.string) + 1 + 16 + 1;
2343 stub_name = bfd_malloc (len);
2344 if (stub_name != NULL)
2345 snprintf (stub_name, len, "%08x_%s+%" BFD_VMA_FMT "x",
2346 (unsigned int) input_section->id,
2347 hash->root.root.root.string,
2352 len = 8 + 1 + 8 + 1 + 8 + 1 + 16 + 1;
2353 stub_name = bfd_malloc (len);
2354 if (stub_name != NULL)
2355 snprintf (stub_name, len, "%08x_%x:%x+%" BFD_VMA_FMT "x",
2356 (unsigned int) input_section->id,
2357 (unsigned int) sym_sec->id,
2358 (unsigned int) ELFNN_R_SYM (rel->r_info),
2365 /* Look up an entry in the stub hash. Stub entries are cached because
2366 creating the stub name takes a bit of time. */
2368 static struct elf_aarch64_stub_hash_entry *
2369 elfNN_aarch64_get_stub_entry (const asection *input_section,
2370 const asection *sym_sec,
2371 struct elf_link_hash_entry *hash,
2372 const Elf_Internal_Rela *rel,
2373 struct elf_aarch64_link_hash_table *htab)
2375 struct elf_aarch64_stub_hash_entry *stub_entry;
2376 struct elf_aarch64_link_hash_entry *h =
2377 (struct elf_aarch64_link_hash_entry *) hash;
2378 const asection *id_sec;
2380 if ((input_section->flags & SEC_CODE) == 0)
2383 /* If this input section is part of a group of sections sharing one
2384 stub section, then use the id of the first section in the group.
2385 Stub names need to include a section id, as there may well be
2386 more than one stub used to reach say, printf, and we need to
2387 distinguish between them. */
2388 id_sec = htab->stub_group[input_section->id].link_sec;
2390 if (h != NULL && h->stub_cache != NULL
2391 && h->stub_cache->h == h && h->stub_cache->id_sec == id_sec)
2393 stub_entry = h->stub_cache;
2399 stub_name = elfNN_aarch64_stub_name (id_sec, sym_sec, h, rel);
2400 if (stub_name == NULL)
2403 stub_entry = aarch64_stub_hash_lookup (&htab->stub_hash_table,
2404 stub_name, FALSE, FALSE);
2406 h->stub_cache = stub_entry;
2415 /* Create a stub section. */
2418 _bfd_aarch64_create_stub_section (asection *section,
2419 struct elf_aarch64_link_hash_table *htab)
2425 namelen = strlen (section->name);
2426 len = namelen + sizeof (STUB_SUFFIX);
2427 s_name = bfd_alloc (htab->stub_bfd, len);
2431 memcpy (s_name, section->name, namelen);
2432 memcpy (s_name + namelen, STUB_SUFFIX, sizeof (STUB_SUFFIX));
2433 return (*htab->add_stub_section) (s_name, section);
2437 /* Find or create a stub section for a link section.
2439 Fix or create the stub section used to collect stubs attached to
2440 the specified link section. */
2443 _bfd_aarch64_get_stub_for_link_section (asection *link_section,
2444 struct elf_aarch64_link_hash_table *htab)
2446 if (htab->stub_group[link_section->id].stub_sec == NULL)
2447 htab->stub_group[link_section->id].stub_sec
2448 = _bfd_aarch64_create_stub_section (link_section, htab);
2449 return htab->stub_group[link_section->id].stub_sec;
2453 /* Find or create a stub section in the stub group for an input
2457 _bfd_aarch64_create_or_find_stub_sec (asection *section,
2458 struct elf_aarch64_link_hash_table *htab)
2460 asection *link_sec = htab->stub_group[section->id].link_sec;
2461 return _bfd_aarch64_get_stub_for_link_section (link_sec, htab);
2465 /* Add a new stub entry in the stub group associated with an input
2466 section to the stub hash. Not all fields of the new stub entry are
2469 static struct elf_aarch64_stub_hash_entry *
2470 _bfd_aarch64_add_stub_entry_in_group (const char *stub_name,
2472 struct elf_aarch64_link_hash_table *htab)
2476 struct elf_aarch64_stub_hash_entry *stub_entry;
2478 link_sec = htab->stub_group[section->id].link_sec;
2479 stub_sec = _bfd_aarch64_create_or_find_stub_sec (section, htab);
2481 /* Enter this entry into the linker stub hash table. */
2482 stub_entry = aarch64_stub_hash_lookup (&htab->stub_hash_table, stub_name,
2484 if (stub_entry == NULL)
2486 (*_bfd_error_handler) (_("%s: cannot create stub entry %s"),
2487 section->owner, stub_name);
2491 stub_entry->stub_sec = stub_sec;
2492 stub_entry->stub_offset = 0;
2493 stub_entry->id_sec = link_sec;
2498 /* Add a new stub entry in the final stub section to the stub hash.
2499 Not all fields of the new stub entry are initialised. */
2501 static struct elf_aarch64_stub_hash_entry *
2502 _bfd_aarch64_add_stub_entry_after (const char *stub_name,
2503 asection *link_section,
2504 struct elf_aarch64_link_hash_table *htab)
2507 struct elf_aarch64_stub_hash_entry *stub_entry;
2509 stub_sec = _bfd_aarch64_get_stub_for_link_section (link_section, htab);
2510 stub_entry = aarch64_stub_hash_lookup (&htab->stub_hash_table, stub_name,
2512 if (stub_entry == NULL)
2514 (*_bfd_error_handler) (_("cannot create stub entry %s"), stub_name);
2518 stub_entry->stub_sec = stub_sec;
2519 stub_entry->stub_offset = 0;
2520 stub_entry->id_sec = link_section;
2527 aarch64_build_one_stub (struct bfd_hash_entry *gen_entry,
2528 void *in_arg ATTRIBUTE_UNUSED)
2530 struct elf_aarch64_stub_hash_entry *stub_entry;
2535 bfd_vma veneered_insn_loc;
2536 bfd_vma veneer_entry_loc;
2537 bfd_signed_vma branch_offset = 0;
2538 unsigned int template_size;
2539 const uint32_t *template;
2542 /* Massage our args to the form they really have. */
2543 stub_entry = (struct elf_aarch64_stub_hash_entry *) gen_entry;
2545 stub_sec = stub_entry->stub_sec;
2547 /* Make a note of the offset within the stubs for this entry. */
2548 stub_entry->stub_offset = stub_sec->size;
2549 loc = stub_sec->contents + stub_entry->stub_offset;
2551 stub_bfd = stub_sec->owner;
2553 /* This is the address of the stub destination. */
2554 sym_value = (stub_entry->target_value
2555 + stub_entry->target_section->output_offset
2556 + stub_entry->target_section->output_section->vma);
2558 if (stub_entry->stub_type == aarch64_stub_long_branch)
2560 bfd_vma place = (stub_entry->stub_offset + stub_sec->output_section->vma
2561 + stub_sec->output_offset);
2563 /* See if we can relax the stub. */
2564 if (aarch64_valid_for_adrp_p (sym_value, place))
2565 stub_entry->stub_type = aarch64_select_branch_stub (sym_value, place);
2568 switch (stub_entry->stub_type)
2570 case aarch64_stub_adrp_branch:
2571 template = aarch64_adrp_branch_stub;
2572 template_size = sizeof (aarch64_adrp_branch_stub);
2574 case aarch64_stub_long_branch:
2575 template = aarch64_long_branch_stub;
2576 template_size = sizeof (aarch64_long_branch_stub);
2578 case aarch64_stub_erratum_835769_veneer:
2579 template = aarch64_erratum_835769_stub;
2580 template_size = sizeof (aarch64_erratum_835769_stub);
2582 case aarch64_stub_erratum_843419_veneer:
2583 template = aarch64_erratum_843419_stub;
2584 template_size = sizeof (aarch64_erratum_843419_stub);
2590 for (i = 0; i < (template_size / sizeof template[0]); i++)
2592 bfd_putl32 (template[i], loc);
2596 template_size = (template_size + 7) & ~7;
2597 stub_sec->size += template_size;
2599 switch (stub_entry->stub_type)
2601 case aarch64_stub_adrp_branch:
2602 if (aarch64_relocate (AARCH64_R (ADR_PREL_PG_HI21), stub_bfd, stub_sec,
2603 stub_entry->stub_offset, sym_value))
2604 /* The stub would not have been relaxed if the offset was out
2608 if (aarch64_relocate (AARCH64_R (ADD_ABS_LO12_NC), stub_bfd, stub_sec,
2609 stub_entry->stub_offset + 4, sym_value))
2613 case aarch64_stub_long_branch:
2614 /* We want the value relative to the address 12 bytes back from the
2616 if (aarch64_relocate (AARCH64_R (PRELNN), stub_bfd, stub_sec,
2617 stub_entry->stub_offset + 16, sym_value + 12))
2621 case aarch64_stub_erratum_835769_veneer:
2622 veneered_insn_loc = stub_entry->target_section->output_section->vma
2623 + stub_entry->target_section->output_offset
2624 + stub_entry->target_value;
2625 veneer_entry_loc = stub_entry->stub_sec->output_section->vma
2626 + stub_entry->stub_sec->output_offset
2627 + stub_entry->stub_offset;
2628 branch_offset = veneered_insn_loc - veneer_entry_loc;
2629 branch_offset >>= 2;
2630 branch_offset &= 0x3ffffff;
2631 bfd_putl32 (stub_entry->veneered_insn,
2632 stub_sec->contents + stub_entry->stub_offset);
2633 bfd_putl32 (template[1] | branch_offset,
2634 stub_sec->contents + stub_entry->stub_offset + 4);
2637 case aarch64_stub_erratum_843419_veneer:
2638 if (aarch64_relocate (AARCH64_R (JUMP26), stub_bfd, stub_sec,
2639 stub_entry->stub_offset + 4, sym_value + 4))
2650 /* As above, but don't actually build the stub. Just bump offset so
2651 we know stub section sizes. */
2654 aarch64_size_one_stub (struct bfd_hash_entry *gen_entry,
2655 void *in_arg ATTRIBUTE_UNUSED)
2657 struct elf_aarch64_stub_hash_entry *stub_entry;
2660 /* Massage our args to the form they really have. */
2661 stub_entry = (struct elf_aarch64_stub_hash_entry *) gen_entry;
2663 switch (stub_entry->stub_type)
2665 case aarch64_stub_adrp_branch:
2666 size = sizeof (aarch64_adrp_branch_stub);
2668 case aarch64_stub_long_branch:
2669 size = sizeof (aarch64_long_branch_stub);
2671 case aarch64_stub_erratum_835769_veneer:
2672 size = sizeof (aarch64_erratum_835769_stub);
2674 case aarch64_stub_erratum_843419_veneer:
2675 size = sizeof (aarch64_erratum_843419_stub);
2681 size = (size + 7) & ~7;
2682 stub_entry->stub_sec->size += size;
2686 /* External entry points for sizing and building linker stubs. */
2688 /* Set up various things so that we can make a list of input sections
2689 for each output section included in the link. Returns -1 on error,
2690 0 when no stubs will be needed, and 1 on success. */
2693 elfNN_aarch64_setup_section_lists (bfd *output_bfd,
2694 struct bfd_link_info *info)
2697 unsigned int bfd_count;
2698 int top_id, top_index;
2700 asection **input_list, **list;
2702 struct elf_aarch64_link_hash_table *htab =
2703 elf_aarch64_hash_table (info);
2705 if (!is_elf_hash_table (htab))
2708 /* Count the number of input BFDs and find the top input section id. */
2709 for (input_bfd = info->input_bfds, bfd_count = 0, top_id = 0;
2710 input_bfd != NULL; input_bfd = input_bfd->link.next)
2713 for (section = input_bfd->sections;
2714 section != NULL; section = section->next)
2716 if (top_id < section->id)
2717 top_id = section->id;
2720 htab->bfd_count = bfd_count;
2722 amt = sizeof (struct map_stub) * (top_id + 1);
2723 htab->stub_group = bfd_zmalloc (amt);
2724 if (htab->stub_group == NULL)
2727 /* We can't use output_bfd->section_count here to find the top output
2728 section index as some sections may have been removed, and
2729 _bfd_strip_section_from_output doesn't renumber the indices. */
2730 for (section = output_bfd->sections, top_index = 0;
2731 section != NULL; section = section->next)
2733 if (top_index < section->index)
2734 top_index = section->index;
2737 htab->top_index = top_index;
2738 amt = sizeof (asection *) * (top_index + 1);
2739 input_list = bfd_malloc (amt);
2740 htab->input_list = input_list;
2741 if (input_list == NULL)
2744 /* For sections we aren't interested in, mark their entries with a
2745 value we can check later. */
2746 list = input_list + top_index;
2748 *list = bfd_abs_section_ptr;
2749 while (list-- != input_list);
2751 for (section = output_bfd->sections;
2752 section != NULL; section = section->next)
2754 if ((section->flags & SEC_CODE) != 0)
2755 input_list[section->index] = NULL;
2761 /* Used by elfNN_aarch64_next_input_section and group_sections. */
2762 #define PREV_SEC(sec) (htab->stub_group[(sec)->id].link_sec)
2764 /* The linker repeatedly calls this function for each input section,
2765 in the order that input sections are linked into output sections.
2766 Build lists of input sections to determine groupings between which
2767 we may insert linker stubs. */
2770 elfNN_aarch64_next_input_section (struct bfd_link_info *info, asection *isec)
2772 struct elf_aarch64_link_hash_table *htab =
2773 elf_aarch64_hash_table (info);
2775 if (isec->output_section->index <= htab->top_index)
2777 asection **list = htab->input_list + isec->output_section->index;
2779 if (*list != bfd_abs_section_ptr)
2781 /* Steal the link_sec pointer for our list. */
2782 /* This happens to make the list in reverse order,
2783 which is what we want. */
2784 PREV_SEC (isec) = *list;
2790 /* See whether we can group stub sections together. Grouping stub
2791 sections may result in fewer stubs. More importantly, we need to
2792 put all .init* and .fini* stubs at the beginning of the .init or
2793 .fini output sections respectively, because glibc splits the
2794 _init and _fini functions into multiple parts. Putting a stub in
2795 the middle of a function is not a good idea. */
2798 group_sections (struct elf_aarch64_link_hash_table *htab,
2799 bfd_size_type stub_group_size,
2800 bfd_boolean stubs_always_before_branch)
2802 asection **list = htab->input_list + htab->top_index;
2806 asection *tail = *list;
2808 if (tail == bfd_abs_section_ptr)
2811 while (tail != NULL)
2815 bfd_size_type total;
2819 while ((prev = PREV_SEC (curr)) != NULL
2820 && ((total += curr->output_offset - prev->output_offset)
2824 /* OK, the size from the start of CURR to the end is less
2825 than stub_group_size and thus can be handled by one stub
2826 section. (Or the tail section is itself larger than
2827 stub_group_size, in which case we may be toast.)
2828 We should really be keeping track of the total size of
2829 stubs added here, as stubs contribute to the final output
2833 prev = PREV_SEC (tail);
2834 /* Set up this stub group. */
2835 htab->stub_group[tail->id].link_sec = curr;
2837 while (tail != curr && (tail = prev) != NULL);
2839 /* But wait, there's more! Input sections up to stub_group_size
2840 bytes before the stub section can be handled by it too. */
2841 if (!stubs_always_before_branch)
2845 && ((total += tail->output_offset - prev->output_offset)
2849 prev = PREV_SEC (tail);
2850 htab->stub_group[tail->id].link_sec = curr;
2856 while (list-- != htab->input_list);
2858 free (htab->input_list);
2863 #define AARCH64_BITS(x, pos, n) (((x) >> (pos)) & ((1 << (n)) - 1))
2865 #define AARCH64_RT(insn) AARCH64_BITS (insn, 0, 5)
2866 #define AARCH64_RT2(insn) AARCH64_BITS (insn, 10, 5)
2867 #define AARCH64_RA(insn) AARCH64_BITS (insn, 10, 5)
2868 #define AARCH64_RD(insn) AARCH64_BITS (insn, 0, 5)
2869 #define AARCH64_RN(insn) AARCH64_BITS (insn, 5, 5)
2870 #define AARCH64_RM(insn) AARCH64_BITS (insn, 16, 5)
2872 #define AARCH64_MAC(insn) (((insn) & 0xff000000) == 0x9b000000)
2873 #define AARCH64_BIT(insn, n) AARCH64_BITS (insn, n, 1)
2874 #define AARCH64_OP31(insn) AARCH64_BITS (insn, 21, 3)
2875 #define AARCH64_ZR 0x1f
2877 /* All ld/st ops. See C4-182 of the ARM ARM. The encoding space for
2878 LD_PCREL, LDST_RO, LDST_UI and LDST_UIMM cover prefetch ops. */
2880 #define AARCH64_LD(insn) (AARCH64_BIT (insn, 22) == 1)
2881 #define AARCH64_LDST(insn) (((insn) & 0x0a000000) == 0x08000000)
2882 #define AARCH64_LDST_EX(insn) (((insn) & 0x3f000000) == 0x08000000)
2883 #define AARCH64_LDST_PCREL(insn) (((insn) & 0x3b000000) == 0x18000000)
2884 #define AARCH64_LDST_NAP(insn) (((insn) & 0x3b800000) == 0x28000000)
2885 #define AARCH64_LDSTP_PI(insn) (((insn) & 0x3b800000) == 0x28800000)
2886 #define AARCH64_LDSTP_O(insn) (((insn) & 0x3b800000) == 0x29000000)
2887 #define AARCH64_LDSTP_PRE(insn) (((insn) & 0x3b800000) == 0x29800000)
2888 #define AARCH64_LDST_UI(insn) (((insn) & 0x3b200c00) == 0x38000000)
2889 #define AARCH64_LDST_PIIMM(insn) (((insn) & 0x3b200c00) == 0x38000400)
2890 #define AARCH64_LDST_U(insn) (((insn) & 0x3b200c00) == 0x38000800)
2891 #define AARCH64_LDST_PREIMM(insn) (((insn) & 0x3b200c00) == 0x38000c00)
2892 #define AARCH64_LDST_RO(insn) (((insn) & 0x3b200c00) == 0x38200800)
2893 #define AARCH64_LDST_UIMM(insn) (((insn) & 0x3b000000) == 0x39000000)
2894 #define AARCH64_LDST_SIMD_M(insn) (((insn) & 0xbfbf0000) == 0x0c000000)
2895 #define AARCH64_LDST_SIMD_M_PI(insn) (((insn) & 0xbfa00000) == 0x0c800000)
2896 #define AARCH64_LDST_SIMD_S(insn) (((insn) & 0xbf9f0000) == 0x0d000000)
2897 #define AARCH64_LDST_SIMD_S_PI(insn) (((insn) & 0xbf800000) == 0x0d800000)
2899 /* Classify an INSN if it is indeed a load/store.
2901 Return TRUE if INSN is a LD/ST instruction otherwise return FALSE.
2903 For scalar LD/ST instructions PAIR is FALSE, RT is returned and RT2
2906 For LD/ST pair instructions PAIR is TRUE, RT and RT2 are returned.
2911 aarch64_mem_op_p (uint32_t insn, unsigned int *rt, unsigned int *rt2,
2912 bfd_boolean *pair, bfd_boolean *load)
2920 /* Bail out quickly if INSN doesn't fall into the the load-store
2922 if (!AARCH64_LDST (insn))
2927 if (AARCH64_LDST_EX (insn))
2929 *rt = AARCH64_RT (insn);
2931 if (AARCH64_BIT (insn, 21) == 1)
2934 *rt2 = AARCH64_RT2 (insn);
2936 *load = AARCH64_LD (insn);
2939 else if (AARCH64_LDST_NAP (insn)
2940 || AARCH64_LDSTP_PI (insn)
2941 || AARCH64_LDSTP_O (insn)
2942 || AARCH64_LDSTP_PRE (insn))
2945 *rt = AARCH64_RT (insn);
2946 *rt2 = AARCH64_RT2 (insn);
2947 *load = AARCH64_LD (insn);
2950 else if (AARCH64_LDST_PCREL (insn)
2951 || AARCH64_LDST_UI (insn)
2952 || AARCH64_LDST_PIIMM (insn)
2953 || AARCH64_LDST_U (insn)
2954 || AARCH64_LDST_PREIMM (insn)
2955 || AARCH64_LDST_RO (insn)
2956 || AARCH64_LDST_UIMM (insn))
2958 *rt = AARCH64_RT (insn);
2960 if (AARCH64_LDST_PCREL (insn))
2962 opc = AARCH64_BITS (insn, 22, 2);
2963 v = AARCH64_BIT (insn, 26);
2964 opc_v = opc | (v << 2);
2965 *load = (opc_v == 1 || opc_v == 2 || opc_v == 3
2966 || opc_v == 5 || opc_v == 7);
2969 else if (AARCH64_LDST_SIMD_M (insn)
2970 || AARCH64_LDST_SIMD_M_PI (insn))
2972 *rt = AARCH64_RT (insn);
2973 *load = AARCH64_BIT (insn, 22);
2974 opcode = (insn >> 12) & 0xf;
3001 else if (AARCH64_LDST_SIMD_S (insn)
3002 || AARCH64_LDST_SIMD_S_PI (insn))
3004 *rt = AARCH64_RT (insn);
3005 r = (insn >> 21) & 1;
3006 *load = AARCH64_BIT (insn, 22);
3007 opcode = (insn >> 13) & 0x7;
3019 *rt2 = *rt + (r == 0 ? 2 : 3);
3027 *rt2 = *rt + (r == 0 ? 2 : 3);
3039 /* Return TRUE if INSN is multiply-accumulate. */
3042 aarch64_mlxl_p (uint32_t insn)
3044 uint32_t op31 = AARCH64_OP31 (insn);
3046 if (AARCH64_MAC (insn)
3047 && (op31 == 0 || op31 == 1 || op31 == 5)
3048 /* Exclude MUL instructions which are encoded as a multiple accumulate
3050 && AARCH64_RA (insn) != AARCH64_ZR)
3056 /* Some early revisions of the Cortex-A53 have an erratum (835769) whereby
3057 it is possible for a 64-bit multiply-accumulate instruction to generate an
3058 incorrect result. The details are quite complex and hard to
3059 determine statically, since branches in the code may exist in some
3060 circumstances, but all cases end with a memory (load, store, or
3061 prefetch) instruction followed immediately by the multiply-accumulate
3062 operation. We employ a linker patching technique, by moving the potentially
3063 affected multiply-accumulate instruction into a patch region and replacing
3064 the original instruction with a branch to the patch. This function checks
3065 if INSN_1 is the memory operation followed by a multiply-accumulate
3066 operation (INSN_2). Return TRUE if an erratum sequence is found, FALSE
3067 if INSN_1 and INSN_2 are safe. */
3070 aarch64_erratum_sequence (uint32_t insn_1, uint32_t insn_2)
3080 if (aarch64_mlxl_p (insn_2)
3081 && aarch64_mem_op_p (insn_1, &rt, &rt2, &pair, &load))
3083 /* Any SIMD memory op is independent of the subsequent MLA
3084 by definition of the erratum. */
3085 if (AARCH64_BIT (insn_1, 26))
3088 /* If not SIMD, check for integer memory ops and MLA relationship. */
3089 rn = AARCH64_RN (insn_2);
3090 ra = AARCH64_RA (insn_2);
3091 rm = AARCH64_RM (insn_2);
3093 /* If this is a load and there's a true(RAW) dependency, we are safe
3094 and this is not an erratum sequence. */
3096 (rt == rn || rt == rm || rt == ra
3097 || (pair && (rt2 == rn || rt2 == rm || rt2 == ra))))
3100 /* We conservatively put out stubs for all other cases (including
3108 /* Used to order a list of mapping symbols by address. */
3111 elf_aarch64_compare_mapping (const void *a, const void *b)
3113 const elf_aarch64_section_map *amap = (const elf_aarch64_section_map *) a;
3114 const elf_aarch64_section_map *bmap = (const elf_aarch64_section_map *) b;
3116 if (amap->vma > bmap->vma)
3118 else if (amap->vma < bmap->vma)
3120 else if (amap->type > bmap->type)
3121 /* Ensure results do not depend on the host qsort for objects with
3122 multiple mapping symbols at the same address by sorting on type
3125 else if (amap->type < bmap->type)
3133 _bfd_aarch64_erratum_835769_stub_name (unsigned num_fixes)
3135 char *stub_name = (char *) bfd_malloc
3136 (strlen ("__erratum_835769_veneer_") + 16);
3137 sprintf (stub_name,"__erratum_835769_veneer_%d", num_fixes);
3141 /* Scan for Cortex-A53 erratum 835769 sequence.
3143 Return TRUE else FALSE on abnormal termination. */
3146 _bfd_aarch64_erratum_835769_scan (bfd *input_bfd,
3147 struct bfd_link_info *info,
3148 unsigned int *num_fixes_p)
3151 struct elf_aarch64_link_hash_table *htab = elf_aarch64_hash_table (info);
3152 unsigned int num_fixes = *num_fixes_p;
3157 for (section = input_bfd->sections;
3159 section = section->next)
3161 bfd_byte *contents = NULL;
3162 struct _aarch64_elf_section_data *sec_data;
3165 if (elf_section_type (section) != SHT_PROGBITS
3166 || (elf_section_flags (section) & SHF_EXECINSTR) == 0
3167 || (section->flags & SEC_EXCLUDE) != 0
3168 || (section->sec_info_type == SEC_INFO_TYPE_JUST_SYMS)
3169 || (section->output_section == bfd_abs_section_ptr))
3172 if (elf_section_data (section)->this_hdr.contents != NULL)
3173 contents = elf_section_data (section)->this_hdr.contents;
3174 else if (! bfd_malloc_and_get_section (input_bfd, section, &contents))
3177 sec_data = elf_aarch64_section_data (section);
3179 qsort (sec_data->map, sec_data->mapcount,
3180 sizeof (elf_aarch64_section_map), elf_aarch64_compare_mapping);
3182 for (span = 0; span < sec_data->mapcount; span++)
3184 unsigned int span_start = sec_data->map[span].vma;
3185 unsigned int span_end = ((span == sec_data->mapcount - 1)
3186 ? sec_data->map[0].vma + section->size
3187 : sec_data->map[span + 1].vma);
3189 char span_type = sec_data->map[span].type;
3191 if (span_type == 'd')
3194 for (i = span_start; i + 4 < span_end; i += 4)
3196 uint32_t insn_1 = bfd_getl32 (contents + i);
3197 uint32_t insn_2 = bfd_getl32 (contents + i + 4);
3199 if (aarch64_erratum_sequence (insn_1, insn_2))
3201 struct elf_aarch64_stub_hash_entry *stub_entry;
3202 char *stub_name = _bfd_aarch64_erratum_835769_stub_name (num_fixes);
3206 stub_entry = _bfd_aarch64_add_stub_entry_in_group (stub_name,
3212 stub_entry->stub_type = aarch64_stub_erratum_835769_veneer;
3213 stub_entry->target_section = section;
3214 stub_entry->target_value = i + 4;
3215 stub_entry->veneered_insn = insn_2;
3216 stub_entry->output_name = stub_name;
3221 if (elf_section_data (section)->this_hdr.contents == NULL)
3225 *num_fixes_p = num_fixes;
3231 /* Test if instruction INSN is ADRP. */
3234 _bfd_aarch64_adrp_p (uint32_t insn)
3236 return ((insn & 0x9f000000) == 0x90000000);
3240 /* Helper predicate to look for cortex-a53 erratum 843419 sequence 1. */
3243 _bfd_aarch64_erratum_843419_sequence_p (uint32_t insn_1, uint32_t insn_2,
3251 return (aarch64_mem_op_p (insn_2, &rt, &rt2, &pair, &load)
3254 && AARCH64_LDST_UIMM (insn_3)
3255 && AARCH64_RN (insn_3) == AARCH64_RD (insn_1));
3259 /* Test for the presence of Cortex-A53 erratum 843419 instruction sequence.
3261 Return TRUE if section CONTENTS at offset I contains one of the
3262 erratum 843419 sequences, otherwise return FALSE. If a sequence is
3263 seen set P_VENEER_I to the offset of the final LOAD/STORE
3264 instruction in the sequence.
3268 _bfd_aarch64_erratum_843419_p (bfd_byte *contents, bfd_vma vma,
3269 bfd_vma i, bfd_vma span_end,
3270 bfd_vma *p_veneer_i)
3272 uint32_t insn_1 = bfd_getl32 (contents + i);
3274 if (!_bfd_aarch64_adrp_p (insn_1))
3277 if (span_end < i + 12)
3280 uint32_t insn_2 = bfd_getl32 (contents + i + 4);
3281 uint32_t insn_3 = bfd_getl32 (contents + i + 8);
3283 if ((vma & 0xfff) != 0xff8 && (vma & 0xfff) != 0xffc)
3286 if (_bfd_aarch64_erratum_843419_sequence_p (insn_1, insn_2, insn_3))
3288 *p_veneer_i = i + 8;
3292 if (span_end < i + 16)
3295 uint32_t insn_4 = bfd_getl32 (contents + i + 12);
3297 if (_bfd_aarch64_erratum_843419_sequence_p (insn_1, insn_2, insn_4))
3299 *p_veneer_i = i + 12;
3307 /* Resize all stub sections. */
3310 _bfd_aarch64_resize_stubs (struct elf_aarch64_link_hash_table *htab)
3314 /* OK, we've added some stubs. Find out the new size of the
3316 for (section = htab->stub_bfd->sections;
3317 section != NULL; section = section->next)
3319 /* Ignore non-stub sections. */
3320 if (!strstr (section->name, STUB_SUFFIX))
3325 bfd_hash_traverse (&htab->stub_hash_table, aarch64_size_one_stub, htab);
3327 for (section = htab->stub_bfd->sections;
3328 section != NULL; section = section->next)
3330 if (!strstr (section->name, STUB_SUFFIX))
3336 /* Ensure all stub sections have a size which is a multiple of
3337 4096. This is important in order to ensure that the insertion
3338 of stub sections does not in itself move existing code around
3339 in such a way that new errata sequences are created. */
3340 if (htab->fix_erratum_843419)
3342 section->size = BFD_ALIGN (section->size, 0x1000);
3347 /* Construct an erratum 843419 workaround stub name.
3351 _bfd_aarch64_erratum_843419_stub_name (asection *input_section,
3354 const bfd_size_type len = 8 + 4 + 1 + 8 + 1 + 16 + 1;
3355 char *stub_name = bfd_malloc (len);
3357 if (stub_name != NULL)
3358 snprintf (stub_name, len, "e843419@%04x_%08x_%" BFD_VMA_FMT "x",
3359 input_section->owner->id,
3365 /* Build a stub_entry structure describing an 843419 fixup.
3367 The stub_entry constructed is populated with the bit pattern INSN
3368 of the instruction located at OFFSET within input SECTION.
3370 Returns TRUE on success. */
3373 _bfd_aarch64_erratum_843419_fixup (uint32_t insn,
3374 bfd_vma adrp_offset,
3375 bfd_vma ldst_offset,
3377 struct bfd_link_info *info)
3379 struct elf_aarch64_link_hash_table *htab = elf_aarch64_hash_table (info);
3381 struct elf_aarch64_stub_hash_entry *stub_entry;
3383 stub_name = _bfd_aarch64_erratum_843419_stub_name (section, ldst_offset);
3384 stub_entry = aarch64_stub_hash_lookup (&htab->stub_hash_table, stub_name,
3392 /* We always place an 843419 workaround veneer in the stub section
3393 attached to the input section in which an erratum sequence has
3394 been found. This ensures that later in the link process (in
3395 elfNN_aarch64_write_section) when we copy the veneered
3396 instruction from the input section into the stub section the
3397 copied instruction will have had any relocations applied to it.
3398 If we placed workaround veneers in any other stub section then we
3399 could not assume that all relocations have been processed on the
3400 corresponding input section at the point we output the stub
3404 stub_entry = _bfd_aarch64_add_stub_entry_after (stub_name, section, htab);
3405 if (stub_entry == NULL)
3411 stub_entry->adrp_offset = adrp_offset;
3412 stub_entry->target_value = ldst_offset;
3413 stub_entry->target_section = section;
3414 stub_entry->stub_type = aarch64_stub_erratum_843419_veneer;
3415 stub_entry->veneered_insn = insn;
3416 stub_entry->output_name = stub_name;
3422 /* Scan an input section looking for the signature of erratum 843419.
3424 Scans input SECTION in INPUT_BFD looking for erratum 843419
3425 signatures, for each signature found a stub_entry is created
3426 describing the location of the erratum for subsequent fixup.
3428 Return TRUE on successful scan, FALSE on failure to scan.
3432 _bfd_aarch64_erratum_843419_scan (bfd *input_bfd, asection *section,
3433 struct bfd_link_info *info)
3435 struct elf_aarch64_link_hash_table *htab = elf_aarch64_hash_table (info);
3440 if (elf_section_type (section) != SHT_PROGBITS
3441 || (elf_section_flags (section) & SHF_EXECINSTR) == 0
3442 || (section->flags & SEC_EXCLUDE) != 0
3443 || (section->sec_info_type == SEC_INFO_TYPE_JUST_SYMS)
3444 || (section->output_section == bfd_abs_section_ptr))
3449 bfd_byte *contents = NULL;
3450 struct _aarch64_elf_section_data *sec_data;
3453 if (elf_section_data (section)->this_hdr.contents != NULL)
3454 contents = elf_section_data (section)->this_hdr.contents;
3455 else if (! bfd_malloc_and_get_section (input_bfd, section, &contents))
3458 sec_data = elf_aarch64_section_data (section);
3460 qsort (sec_data->map, sec_data->mapcount,
3461 sizeof (elf_aarch64_section_map), elf_aarch64_compare_mapping);
3463 for (span = 0; span < sec_data->mapcount; span++)
3465 unsigned int span_start = sec_data->map[span].vma;
3466 unsigned int span_end = ((span == sec_data->mapcount - 1)
3467 ? sec_data->map[0].vma + section->size
3468 : sec_data->map[span + 1].vma);
3470 char span_type = sec_data->map[span].type;
3472 if (span_type == 'd')
3475 for (i = span_start; i + 8 < span_end; i += 4)
3477 bfd_vma vma = (section->output_section->vma
3478 + section->output_offset
3482 if (_bfd_aarch64_erratum_843419_p
3483 (contents, vma, i, span_end, &veneer_i))
3485 uint32_t insn = bfd_getl32 (contents + veneer_i);
3487 if (!_bfd_aarch64_erratum_843419_fixup (insn, i, veneer_i,
3494 if (elf_section_data (section)->this_hdr.contents == NULL)
3503 /* Determine and set the size of the stub section for a final link.
3505 The basic idea here is to examine all the relocations looking for
3506 PC-relative calls to a target that is unreachable with a "bl"
3510 elfNN_aarch64_size_stubs (bfd *output_bfd,
3512 struct bfd_link_info *info,
3513 bfd_signed_vma group_size,
3514 asection * (*add_stub_section) (const char *,
3516 void (*layout_sections_again) (void))
3518 bfd_size_type stub_group_size;
3519 bfd_boolean stubs_always_before_branch;
3520 bfd_boolean stub_changed = FALSE;
3521 struct elf_aarch64_link_hash_table *htab = elf_aarch64_hash_table (info);
3522 unsigned int num_erratum_835769_fixes = 0;
3524 /* Propagate mach to stub bfd, because it may not have been
3525 finalized when we created stub_bfd. */
3526 bfd_set_arch_mach (stub_bfd, bfd_get_arch (output_bfd),
3527 bfd_get_mach (output_bfd));
3529 /* Stash our params away. */
3530 htab->stub_bfd = stub_bfd;
3531 htab->add_stub_section = add_stub_section;
3532 htab->layout_sections_again = layout_sections_again;
3533 stubs_always_before_branch = group_size < 0;
3535 stub_group_size = -group_size;
3537 stub_group_size = group_size;
3539 if (stub_group_size == 1)
3541 /* Default values. */
3542 /* AArch64 branch range is +-128MB. The value used is 1MB less. */
3543 stub_group_size = 127 * 1024 * 1024;
3546 group_sections (htab, stub_group_size, stubs_always_before_branch);
3548 (*htab->layout_sections_again) ();
3550 if (htab->fix_erratum_835769)
3554 for (input_bfd = info->input_bfds;
3555 input_bfd != NULL; input_bfd = input_bfd->link.next)
3556 if (!_bfd_aarch64_erratum_835769_scan (input_bfd, info,
3557 &num_erratum_835769_fixes))
3560 _bfd_aarch64_resize_stubs (htab);
3561 (*htab->layout_sections_again) ();
3564 if (htab->fix_erratum_843419)
3568 for (input_bfd = info->input_bfds;
3570 input_bfd = input_bfd->link.next)
3574 for (section = input_bfd->sections;
3576 section = section->next)
3577 if (!_bfd_aarch64_erratum_843419_scan (input_bfd, section, info))
3581 _bfd_aarch64_resize_stubs (htab);
3582 (*htab->layout_sections_again) ();
3589 for (input_bfd = info->input_bfds;
3590 input_bfd != NULL; input_bfd = input_bfd->link.next)
3592 Elf_Internal_Shdr *symtab_hdr;
3594 Elf_Internal_Sym *local_syms = NULL;
3596 /* We'll need the symbol table in a second. */
3597 symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
3598 if (symtab_hdr->sh_info == 0)
3601 /* Walk over each section attached to the input bfd. */
3602 for (section = input_bfd->sections;
3603 section != NULL; section = section->next)
3605 Elf_Internal_Rela *internal_relocs, *irelaend, *irela;
3607 /* If there aren't any relocs, then there's nothing more
3609 if ((section->flags & SEC_RELOC) == 0
3610 || section->reloc_count == 0
3611 || (section->flags & SEC_CODE) == 0)
3614 /* If this section is a link-once section that will be
3615 discarded, then don't create any stubs. */
3616 if (section->output_section == NULL
3617 || section->output_section->owner != output_bfd)
3620 /* Get the relocs. */
3622 = _bfd_elf_link_read_relocs (input_bfd, section, NULL,
3623 NULL, info->keep_memory);
3624 if (internal_relocs == NULL)
3625 goto error_ret_free_local;
3627 /* Now examine each relocation. */
3628 irela = internal_relocs;
3629 irelaend = irela + section->reloc_count;
3630 for (; irela < irelaend; irela++)
3632 unsigned int r_type, r_indx;
3633 enum elf_aarch64_stub_type stub_type;
3634 struct elf_aarch64_stub_hash_entry *stub_entry;
3637 bfd_vma destination;
3638 struct elf_aarch64_link_hash_entry *hash;
3639 const char *sym_name;
3641 const asection *id_sec;
3642 unsigned char st_type;
3645 r_type = ELFNN_R_TYPE (irela->r_info);
3646 r_indx = ELFNN_R_SYM (irela->r_info);
3648 if (r_type >= (unsigned int) R_AARCH64_end)
3650 bfd_set_error (bfd_error_bad_value);
3651 error_ret_free_internal:
3652 if (elf_section_data (section)->relocs == NULL)
3653 free (internal_relocs);
3654 goto error_ret_free_local;
3657 /* Only look for stubs on unconditional branch and
3658 branch and link instructions. */
3659 if (r_type != (unsigned int) AARCH64_R (CALL26)
3660 && r_type != (unsigned int) AARCH64_R (JUMP26))
3663 /* Now determine the call target, its name, value,
3670 if (r_indx < symtab_hdr->sh_info)
3672 /* It's a local symbol. */
3673 Elf_Internal_Sym *sym;
3674 Elf_Internal_Shdr *hdr;
3676 if (local_syms == NULL)
3679 = (Elf_Internal_Sym *) symtab_hdr->contents;
3680 if (local_syms == NULL)
3682 = bfd_elf_get_elf_syms (input_bfd, symtab_hdr,
3683 symtab_hdr->sh_info, 0,
3685 if (local_syms == NULL)
3686 goto error_ret_free_internal;
3689 sym = local_syms + r_indx;
3690 hdr = elf_elfsections (input_bfd)[sym->st_shndx];
3691 sym_sec = hdr->bfd_section;
3693 /* This is an undefined symbol. It can never
3697 if (ELF_ST_TYPE (sym->st_info) != STT_SECTION)
3698 sym_value = sym->st_value;
3699 destination = (sym_value + irela->r_addend
3700 + sym_sec->output_offset
3701 + sym_sec->output_section->vma);
3702 st_type = ELF_ST_TYPE (sym->st_info);
3704 = bfd_elf_string_from_elf_section (input_bfd,
3705 symtab_hdr->sh_link,
3712 e_indx = r_indx - symtab_hdr->sh_info;
3713 hash = ((struct elf_aarch64_link_hash_entry *)
3714 elf_sym_hashes (input_bfd)[e_indx]);
3716 while (hash->root.root.type == bfd_link_hash_indirect
3717 || hash->root.root.type == bfd_link_hash_warning)
3718 hash = ((struct elf_aarch64_link_hash_entry *)
3719 hash->root.root.u.i.link);
3721 if (hash->root.root.type == bfd_link_hash_defined
3722 || hash->root.root.type == bfd_link_hash_defweak)
3724 struct elf_aarch64_link_hash_table *globals =
3725 elf_aarch64_hash_table (info);
3726 sym_sec = hash->root.root.u.def.section;
3727 sym_value = hash->root.root.u.def.value;
3728 /* For a destination in a shared library,
3729 use the PLT stub as target address to
3730 decide whether a branch stub is
3732 if (globals->root.splt != NULL && hash != NULL
3733 && hash->root.plt.offset != (bfd_vma) - 1)
3735 sym_sec = globals->root.splt;
3736 sym_value = hash->root.plt.offset;
3737 if (sym_sec->output_section != NULL)
3738 destination = (sym_value
3739 + sym_sec->output_offset
3741 sym_sec->output_section->vma);
3743 else if (sym_sec->output_section != NULL)
3744 destination = (sym_value + irela->r_addend
3745 + sym_sec->output_offset
3746 + sym_sec->output_section->vma);
3748 else if (hash->root.root.type == bfd_link_hash_undefined
3749 || (hash->root.root.type
3750 == bfd_link_hash_undefweak))
3752 /* For a shared library, use the PLT stub as
3753 target address to decide whether a long
3754 branch stub is needed.
3755 For absolute code, they cannot be handled. */
3756 struct elf_aarch64_link_hash_table *globals =
3757 elf_aarch64_hash_table (info);
3759 if (globals->root.splt != NULL && hash != NULL
3760 && hash->root.plt.offset != (bfd_vma) - 1)
3762 sym_sec = globals->root.splt;
3763 sym_value = hash->root.plt.offset;
3764 if (sym_sec->output_section != NULL)
3765 destination = (sym_value
3766 + sym_sec->output_offset
3768 sym_sec->output_section->vma);
3775 bfd_set_error (bfd_error_bad_value);
3776 goto error_ret_free_internal;
3778 st_type = ELF_ST_TYPE (hash->root.type);
3779 sym_name = hash->root.root.root.string;
3782 /* Determine what (if any) linker stub is needed. */
3783 stub_type = aarch64_type_of_stub
3784 (info, section, irela, st_type, hash, destination);
3785 if (stub_type == aarch64_stub_none)
3788 /* Support for grouping stub sections. */
3789 id_sec = htab->stub_group[section->id].link_sec;
3791 /* Get the name of this stub. */
3792 stub_name = elfNN_aarch64_stub_name (id_sec, sym_sec, hash,
3795 goto error_ret_free_internal;
3798 aarch64_stub_hash_lookup (&htab->stub_hash_table,
3799 stub_name, FALSE, FALSE);
3800 if (stub_entry != NULL)
3802 /* The proper stub has already been created. */
3807 stub_entry = _bfd_aarch64_add_stub_entry_in_group
3808 (stub_name, section, htab);
3809 if (stub_entry == NULL)
3812 goto error_ret_free_internal;
3815 stub_entry->target_value = sym_value;
3816 stub_entry->target_section = sym_sec;
3817 stub_entry->stub_type = stub_type;
3818 stub_entry->h = hash;
3819 stub_entry->st_type = st_type;
3821 if (sym_name == NULL)
3822 sym_name = "unnamed";
3823 len = sizeof (STUB_ENTRY_NAME) + strlen (sym_name);
3824 stub_entry->output_name = bfd_alloc (htab->stub_bfd, len);
3825 if (stub_entry->output_name == NULL)
3828 goto error_ret_free_internal;
3831 snprintf (stub_entry->output_name, len, STUB_ENTRY_NAME,
3834 stub_changed = TRUE;
3837 /* We're done with the internal relocs, free them. */
3838 if (elf_section_data (section)->relocs == NULL)
3839 free (internal_relocs);
3846 _bfd_aarch64_resize_stubs (htab);
3848 /* Ask the linker to do its stuff. */
3849 (*htab->layout_sections_again) ();
3850 stub_changed = FALSE;
3855 error_ret_free_local:
3859 /* Build all the stubs associated with the current output file. The
3860 stubs are kept in a hash table attached to the main linker hash
3861 table. We also set up the .plt entries for statically linked PIC
3862 functions here. This function is called via aarch64_elf_finish in the
3866 elfNN_aarch64_build_stubs (struct bfd_link_info *info)
3869 struct bfd_hash_table *table;
3870 struct elf_aarch64_link_hash_table *htab;
3872 htab = elf_aarch64_hash_table (info);
3874 for (stub_sec = htab->stub_bfd->sections;
3875 stub_sec != NULL; stub_sec = stub_sec->next)
3879 /* Ignore non-stub sections. */
3880 if (!strstr (stub_sec->name, STUB_SUFFIX))
3883 /* Allocate memory to hold the linker stubs. */
3884 size = stub_sec->size;
3885 stub_sec->contents = bfd_zalloc (htab->stub_bfd, size);
3886 if (stub_sec->contents == NULL && size != 0)
3890 bfd_putl32 (0x14000000 | (size >> 2), stub_sec->contents);
3891 stub_sec->size += 4;
3894 /* Build the stubs as directed by the stub hash table. */
3895 table = &htab->stub_hash_table;
3896 bfd_hash_traverse (table, aarch64_build_one_stub, info);
3902 /* Add an entry to the code/data map for section SEC. */
3905 elfNN_aarch64_section_map_add (asection *sec, char type, bfd_vma vma)
3907 struct _aarch64_elf_section_data *sec_data =
3908 elf_aarch64_section_data (sec);
3909 unsigned int newidx;
3911 if (sec_data->map == NULL)
3913 sec_data->map = bfd_malloc (sizeof (elf_aarch64_section_map));
3914 sec_data->mapcount = 0;
3915 sec_data->mapsize = 1;
3918 newidx = sec_data->mapcount++;
3920 if (sec_data->mapcount > sec_data->mapsize)
3922 sec_data->mapsize *= 2;
3923 sec_data->map = bfd_realloc_or_free
3924 (sec_data->map, sec_data->mapsize * sizeof (elf_aarch64_section_map));
3929 sec_data->map[newidx].vma = vma;
3930 sec_data->map[newidx].type = type;
3935 /* Initialise maps of insn/data for input BFDs. */
3937 bfd_elfNN_aarch64_init_maps (bfd *abfd)
3939 Elf_Internal_Sym *isymbuf;
3940 Elf_Internal_Shdr *hdr;
3941 unsigned int i, localsyms;
3943 /* Make sure that we are dealing with an AArch64 elf binary. */
3944 if (!is_aarch64_elf (abfd))
3947 if ((abfd->flags & DYNAMIC) != 0)
3950 hdr = &elf_symtab_hdr (abfd);
3951 localsyms = hdr->sh_info;
3953 /* Obtain a buffer full of symbols for this BFD. The hdr->sh_info field
3954 should contain the number of local symbols, which should come before any
3955 global symbols. Mapping symbols are always local. */
3956 isymbuf = bfd_elf_get_elf_syms (abfd, hdr, localsyms, 0, NULL, NULL, NULL);
3958 /* No internal symbols read? Skip this BFD. */
3959 if (isymbuf == NULL)
3962 for (i = 0; i < localsyms; i++)
3964 Elf_Internal_Sym *isym = &isymbuf[i];
3965 asection *sec = bfd_section_from_elf_index (abfd, isym->st_shndx);
3968 if (sec != NULL && ELF_ST_BIND (isym->st_info) == STB_LOCAL)
3970 name = bfd_elf_string_from_elf_section (abfd,
3974 if (bfd_is_aarch64_special_symbol_name
3975 (name, BFD_AARCH64_SPECIAL_SYM_TYPE_MAP))
3976 elfNN_aarch64_section_map_add (sec, name[1], isym->st_value);
3981 /* Set option values needed during linking. */
3983 bfd_elfNN_aarch64_set_options (struct bfd *output_bfd,
3984 struct bfd_link_info *link_info,
3986 int no_wchar_warn, int pic_veneer,
3987 int fix_erratum_835769,
3988 int fix_erratum_843419)
3990 struct elf_aarch64_link_hash_table *globals;
3992 globals = elf_aarch64_hash_table (link_info);
3993 globals->pic_veneer = pic_veneer;
3994 globals->fix_erratum_835769 = fix_erratum_835769;
3995 globals->fix_erratum_843419 = fix_erratum_843419;
3996 globals->fix_erratum_843419_adr = TRUE;
3998 BFD_ASSERT (is_aarch64_elf (output_bfd));
3999 elf_aarch64_tdata (output_bfd)->no_enum_size_warning = no_enum_warn;
4000 elf_aarch64_tdata (output_bfd)->no_wchar_size_warning = no_wchar_warn;
4004 aarch64_calculate_got_entry_vma (struct elf_link_hash_entry *h,
4005 struct elf_aarch64_link_hash_table
4006 *globals, struct bfd_link_info *info,
4007 bfd_vma value, bfd *output_bfd,
4008 bfd_boolean *unresolved_reloc_p)
4010 bfd_vma off = (bfd_vma) - 1;
4011 asection *basegot = globals->root.sgot;
4012 bfd_boolean dyn = globals->root.dynamic_sections_created;
4016 BFD_ASSERT (basegot != NULL);
4017 off = h->got.offset;
4018 BFD_ASSERT (off != (bfd_vma) - 1);
4019 if (!WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h)
4021 && SYMBOL_REFERENCES_LOCAL (info, h))
4022 || (ELF_ST_VISIBILITY (h->other)
4023 && h->root.type == bfd_link_hash_undefweak))
4025 /* This is actually a static link, or it is a -Bsymbolic link
4026 and the symbol is defined locally. We must initialize this
4027 entry in the global offset table. Since the offset must
4028 always be a multiple of 8 (4 in the case of ILP32), we use
4029 the least significant bit to record whether we have
4030 initialized it already.
4031 When doing a dynamic link, we create a .rel(a).got relocation
4032 entry to initialize the value. This is done in the
4033 finish_dynamic_symbol routine. */
4038 bfd_put_NN (output_bfd, value, basegot->contents + off);
4043 *unresolved_reloc_p = FALSE;
4045 off = off + basegot->output_section->vma + basegot->output_offset;
4051 /* Change R_TYPE to a more efficient access model where possible,
4052 return the new reloc type. */
4054 static bfd_reloc_code_real_type
4055 aarch64_tls_transition_without_check (bfd_reloc_code_real_type r_type,
4056 struct elf_link_hash_entry *h)
4058 bfd_boolean is_local = h == NULL;
4062 case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21:
4063 case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21:
4065 ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1
4066 : BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21);
4068 case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21:
4070 ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC
4073 case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19:
4075 ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1
4076 : BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19);
4078 case BFD_RELOC_AARCH64_TLSDESC_LDNN_LO12_NC:
4079 case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC:
4081 ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC
4082 : BFD_RELOC_AARCH64_TLSIE_LDNN_GOTTPREL_LO12_NC);
4084 case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21:
4085 return is_local ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1 : r_type;
4087 case BFD_RELOC_AARCH64_TLSIE_LDNN_GOTTPREL_LO12_NC:
4088 return is_local ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC : r_type;
4090 case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19:
4093 case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21:
4095 ? BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_HI12
4096 : BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19);
4098 case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12_NC:
4099 case BFD_RELOC_AARCH64_TLSDESC_CALL:
4100 /* Instructions with these relocations will become NOPs. */
4101 return BFD_RELOC_AARCH64_NONE;
4111 aarch64_reloc_got_type (bfd_reloc_code_real_type r_type)
4115 case BFD_RELOC_AARCH64_ADR_GOT_PAGE:
4116 case BFD_RELOC_AARCH64_GOT_LD_PREL19:
4117 case BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14:
4118 case BFD_RELOC_AARCH64_LD32_GOT_LO12_NC:
4119 case BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15:
4120 case BFD_RELOC_AARCH64_LD64_GOT_LO12_NC:
4123 case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC:
4124 case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21:
4125 case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21:
4126 case BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21:
4127 case BFD_RELOC_AARCH64_TLSLD_ADR_PREL21:
4130 case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12_NC:
4131 case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21:
4132 case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21:
4133 case BFD_RELOC_AARCH64_TLSDESC_CALL:
4134 case BFD_RELOC_AARCH64_TLSDESC_LD32_LO12_NC:
4135 case BFD_RELOC_AARCH64_TLSDESC_LD64_LO12_NC:
4136 case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19:
4137 return GOT_TLSDESC_GD;
4139 case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21:
4140 case BFD_RELOC_AARCH64_TLSIE_LD32_GOTTPREL_LO12_NC:
4141 case BFD_RELOC_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC:
4142 case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19:
4145 case BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_HI12:
4146 case BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_LO12:
4147 case BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_LO12_NC:
4148 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0:
4149 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC:
4150 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1:
4151 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1_NC:
4152 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G2:
4162 aarch64_can_relax_tls (bfd *input_bfd,
4163 struct bfd_link_info *info,
4164 bfd_reloc_code_real_type r_type,
4165 struct elf_link_hash_entry *h,
4166 unsigned long r_symndx)
4168 unsigned int symbol_got_type;
4169 unsigned int reloc_got_type;
4171 if (! IS_AARCH64_TLS_RELOC (r_type))
4174 symbol_got_type = elfNN_aarch64_symbol_got_type (h, input_bfd, r_symndx);
4175 reloc_got_type = aarch64_reloc_got_type (r_type);
4177 if (symbol_got_type == GOT_TLS_IE && GOT_TLS_GD_ANY_P (reloc_got_type))
4183 if (h && h->root.type == bfd_link_hash_undefweak)
4189 /* Given the relocation code R_TYPE, return the relaxed bfd reloc
4192 static bfd_reloc_code_real_type
4193 aarch64_tls_transition (bfd *input_bfd,
4194 struct bfd_link_info *info,
4195 unsigned int r_type,
4196 struct elf_link_hash_entry *h,
4197 unsigned long r_symndx)
4199 bfd_reloc_code_real_type bfd_r_type
4200 = elfNN_aarch64_bfd_reloc_from_type (r_type);
4202 if (! aarch64_can_relax_tls (input_bfd, info, bfd_r_type, h, r_symndx))
4205 return aarch64_tls_transition_without_check (bfd_r_type, h);
4208 /* Return the base VMA address which should be subtracted from real addresses
4209 when resolving R_AARCH64_TLS_DTPREL relocation. */
4212 dtpoff_base (struct bfd_link_info *info)
4214 /* If tls_sec is NULL, we should have signalled an error already. */
4215 BFD_ASSERT (elf_hash_table (info)->tls_sec != NULL);
4216 return elf_hash_table (info)->tls_sec->vma;
4219 /* Return the base VMA address which should be subtracted from real addresses
4220 when resolving R_AARCH64_TLS_GOTTPREL64 relocations. */
4223 tpoff_base (struct bfd_link_info *info)
4225 struct elf_link_hash_table *htab = elf_hash_table (info);
4227 /* If tls_sec is NULL, we should have signalled an error already. */
4228 BFD_ASSERT (htab->tls_sec != NULL);
4230 bfd_vma base = align_power ((bfd_vma) TCB_SIZE,
4231 htab->tls_sec->alignment_power);
4232 return htab->tls_sec->vma - base;
4236 symbol_got_offset_ref (bfd *input_bfd, struct elf_link_hash_entry *h,
4237 unsigned long r_symndx)
4239 /* Calculate the address of the GOT entry for symbol
4240 referred to in h. */
4242 return &h->got.offset;
4246 struct elf_aarch64_local_symbol *l;
4248 l = elf_aarch64_locals (input_bfd);
4249 return &l[r_symndx].got_offset;
4254 symbol_got_offset_mark (bfd *input_bfd, struct elf_link_hash_entry *h,
4255 unsigned long r_symndx)
4258 p = symbol_got_offset_ref (input_bfd, h, r_symndx);
4263 symbol_got_offset_mark_p (bfd *input_bfd, struct elf_link_hash_entry *h,
4264 unsigned long r_symndx)
4267 value = * symbol_got_offset_ref (input_bfd, h, r_symndx);
4272 symbol_got_offset (bfd *input_bfd, struct elf_link_hash_entry *h,
4273 unsigned long r_symndx)
4276 value = * symbol_got_offset_ref (input_bfd, h, r_symndx);
4282 symbol_tlsdesc_got_offset_ref (bfd *input_bfd, struct elf_link_hash_entry *h,
4283 unsigned long r_symndx)
4285 /* Calculate the address of the GOT entry for symbol
4286 referred to in h. */
4289 struct elf_aarch64_link_hash_entry *eh;
4290 eh = (struct elf_aarch64_link_hash_entry *) h;
4291 return &eh->tlsdesc_got_jump_table_offset;
4296 struct elf_aarch64_local_symbol *l;
4298 l = elf_aarch64_locals (input_bfd);
4299 return &l[r_symndx].tlsdesc_got_jump_table_offset;
4304 symbol_tlsdesc_got_offset_mark (bfd *input_bfd, struct elf_link_hash_entry *h,
4305 unsigned long r_symndx)
4308 p = symbol_tlsdesc_got_offset_ref (input_bfd, h, r_symndx);
4313 symbol_tlsdesc_got_offset_mark_p (bfd *input_bfd,
4314 struct elf_link_hash_entry *h,
4315 unsigned long r_symndx)
4318 value = * symbol_tlsdesc_got_offset_ref (input_bfd, h, r_symndx);
4323 symbol_tlsdesc_got_offset (bfd *input_bfd, struct elf_link_hash_entry *h,
4324 unsigned long r_symndx)
4327 value = * symbol_tlsdesc_got_offset_ref (input_bfd, h, r_symndx);
4332 /* Data for make_branch_to_erratum_835769_stub(). */
4334 struct erratum_835769_branch_to_stub_data
4336 struct bfd_link_info *info;
4337 asection *output_section;
4341 /* Helper to insert branches to erratum 835769 stubs in the right
4342 places for a particular section. */
4345 make_branch_to_erratum_835769_stub (struct bfd_hash_entry *gen_entry,
4348 struct elf_aarch64_stub_hash_entry *stub_entry;
4349 struct erratum_835769_branch_to_stub_data *data;
4351 unsigned long branch_insn = 0;
4352 bfd_vma veneered_insn_loc, veneer_entry_loc;
4353 bfd_signed_vma branch_offset;
4354 unsigned int target;
4357 stub_entry = (struct elf_aarch64_stub_hash_entry *) gen_entry;
4358 data = (struct erratum_835769_branch_to_stub_data *) in_arg;
4360 if (stub_entry->target_section != data->output_section
4361 || stub_entry->stub_type != aarch64_stub_erratum_835769_veneer)
4364 contents = data->contents;
4365 veneered_insn_loc = stub_entry->target_section->output_section->vma
4366 + stub_entry->target_section->output_offset
4367 + stub_entry->target_value;
4368 veneer_entry_loc = stub_entry->stub_sec->output_section->vma
4369 + stub_entry->stub_sec->output_offset
4370 + stub_entry->stub_offset;
4371 branch_offset = veneer_entry_loc - veneered_insn_loc;
4373 abfd = stub_entry->target_section->owner;
4374 if (!aarch64_valid_branch_p (veneer_entry_loc, veneered_insn_loc))
4375 (*_bfd_error_handler)
4376 (_("%B: error: Erratum 835769 stub out "
4377 "of range (input file too large)"), abfd);
4379 target = stub_entry->target_value;
4380 branch_insn = 0x14000000;
4381 branch_offset >>= 2;
4382 branch_offset &= 0x3ffffff;
4383 branch_insn |= branch_offset;
4384 bfd_putl32 (branch_insn, &contents[target]);
4391 _bfd_aarch64_erratum_843419_branch_to_stub (struct bfd_hash_entry *gen_entry,
4394 struct elf_aarch64_stub_hash_entry *stub_entry
4395 = (struct elf_aarch64_stub_hash_entry *) gen_entry;
4396 struct erratum_835769_branch_to_stub_data *data
4397 = (struct erratum_835769_branch_to_stub_data *) in_arg;
4398 struct bfd_link_info *info;
4399 struct elf_aarch64_link_hash_table *htab;
4407 contents = data->contents;
4408 section = data->output_section;
4410 htab = elf_aarch64_hash_table (info);
4412 if (stub_entry->target_section != section
4413 || stub_entry->stub_type != aarch64_stub_erratum_843419_veneer)
4416 insn = bfd_getl32 (contents + stub_entry->target_value);
4418 stub_entry->stub_sec->contents + stub_entry->stub_offset);
4420 place = (section->output_section->vma + section->output_offset
4421 + stub_entry->adrp_offset);
4422 insn = bfd_getl32 (contents + stub_entry->adrp_offset);
4424 if ((insn & AARCH64_ADRP_OP_MASK) != AARCH64_ADRP_OP)
4427 bfd_signed_vma imm =
4428 (_bfd_aarch64_sign_extend
4429 ((bfd_vma) _bfd_aarch64_decode_adrp_imm (insn) << 12, 33)
4432 if (htab->fix_erratum_843419_adr
4433 && (imm >= AARCH64_MIN_ADRP_IMM && imm <= AARCH64_MAX_ADRP_IMM))
4435 insn = (_bfd_aarch64_reencode_adr_imm (AARCH64_ADR_OP, imm)
4436 | AARCH64_RT (insn));
4437 bfd_putl32 (insn, contents + stub_entry->adrp_offset);
4441 bfd_vma veneered_insn_loc;
4442 bfd_vma veneer_entry_loc;
4443 bfd_signed_vma branch_offset;
4444 uint32_t branch_insn;
4446 veneered_insn_loc = stub_entry->target_section->output_section->vma
4447 + stub_entry->target_section->output_offset
4448 + stub_entry->target_value;
4449 veneer_entry_loc = stub_entry->stub_sec->output_section->vma
4450 + stub_entry->stub_sec->output_offset
4451 + stub_entry->stub_offset;
4452 branch_offset = veneer_entry_loc - veneered_insn_loc;
4454 abfd = stub_entry->target_section->owner;
4455 if (!aarch64_valid_branch_p (veneer_entry_loc, veneered_insn_loc))
4456 (*_bfd_error_handler)
4457 (_("%B: error: Erratum 843419 stub out "
4458 "of range (input file too large)"), abfd);
4460 branch_insn = 0x14000000;
4461 branch_offset >>= 2;
4462 branch_offset &= 0x3ffffff;
4463 branch_insn |= branch_offset;
4464 bfd_putl32 (branch_insn, contents + stub_entry->target_value);
4471 elfNN_aarch64_write_section (bfd *output_bfd ATTRIBUTE_UNUSED,
4472 struct bfd_link_info *link_info,
4477 struct elf_aarch64_link_hash_table *globals =
4478 elf_aarch64_hash_table (link_info);
4480 if (globals == NULL)
4483 /* Fix code to point to erratum 835769 stubs. */
4484 if (globals->fix_erratum_835769)
4486 struct erratum_835769_branch_to_stub_data data;
4488 data.info = link_info;
4489 data.output_section = sec;
4490 data.contents = contents;
4491 bfd_hash_traverse (&globals->stub_hash_table,
4492 make_branch_to_erratum_835769_stub, &data);
4495 if (globals->fix_erratum_843419)
4497 struct erratum_835769_branch_to_stub_data data;
4499 data.info = link_info;
4500 data.output_section = sec;
4501 data.contents = contents;
4502 bfd_hash_traverse (&globals->stub_hash_table,
4503 _bfd_aarch64_erratum_843419_branch_to_stub, &data);
4509 /* Perform a relocation as part of a final link. */
4510 static bfd_reloc_status_type
4511 elfNN_aarch64_final_link_relocate (reloc_howto_type *howto,
4514 asection *input_section,
4516 Elf_Internal_Rela *rel,
4518 struct bfd_link_info *info,
4520 struct elf_link_hash_entry *h,
4521 bfd_boolean *unresolved_reloc_p,
4522 bfd_boolean save_addend,
4523 bfd_vma *saved_addend,
4524 Elf_Internal_Sym *sym)
4526 Elf_Internal_Shdr *symtab_hdr;
4527 unsigned int r_type = howto->type;
4528 bfd_reloc_code_real_type bfd_r_type
4529 = elfNN_aarch64_bfd_reloc_from_howto (howto);
4530 bfd_reloc_code_real_type new_bfd_r_type;
4531 unsigned long r_symndx;
4532 bfd_byte *hit_data = contents + rel->r_offset;
4534 bfd_signed_vma signed_addend;
4535 struct elf_aarch64_link_hash_table *globals;
4536 bfd_boolean weak_undef_p;
4539 globals = elf_aarch64_hash_table (info);
4541 symtab_hdr = &elf_symtab_hdr (input_bfd);
4543 BFD_ASSERT (is_aarch64_elf (input_bfd));
4545 r_symndx = ELFNN_R_SYM (rel->r_info);
4547 /* It is possible to have linker relaxations on some TLS access
4548 models. Update our information here. */
4549 new_bfd_r_type = aarch64_tls_transition (input_bfd, info, r_type, h, r_symndx);
4550 if (new_bfd_r_type != bfd_r_type)
4552 bfd_r_type = new_bfd_r_type;
4553 howto = elfNN_aarch64_howto_from_bfd_reloc (bfd_r_type);
4554 BFD_ASSERT (howto != NULL);
4555 r_type = howto->type;
4558 place = input_section->output_section->vma
4559 + input_section->output_offset + rel->r_offset;
4561 /* Get addend, accumulating the addend for consecutive relocs
4562 which refer to the same offset. */
4563 signed_addend = saved_addend ? *saved_addend : 0;
4564 signed_addend += rel->r_addend;
4566 weak_undef_p = (h ? h->root.type == bfd_link_hash_undefweak
4567 : bfd_is_und_section (sym_sec));
4569 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle
4570 it here if it is defined in a non-shared object. */
4572 && h->type == STT_GNU_IFUNC
4579 if ((input_section->flags & SEC_ALLOC) == 0
4580 || h->plt.offset == (bfd_vma) -1)
4583 /* STT_GNU_IFUNC symbol must go through PLT. */
4584 plt = globals->root.splt ? globals->root.splt : globals->root.iplt;
4585 value = (plt->output_section->vma + plt->output_offset + h->plt.offset);
4590 if (h->root.root.string)
4591 name = h->root.root.string;
4593 name = bfd_elf_sym_name (input_bfd, symtab_hdr, sym,
4595 (*_bfd_error_handler)
4596 (_("%B: relocation %s against STT_GNU_IFUNC "
4597 "symbol `%s' isn't handled by %s"), input_bfd,
4598 howto->name, name, __FUNCTION__);
4599 bfd_set_error (bfd_error_bad_value);
4602 case BFD_RELOC_AARCH64_NN:
4603 if (rel->r_addend != 0)
4605 if (h->root.root.string)
4606 name = h->root.root.string;
4608 name = bfd_elf_sym_name (input_bfd, symtab_hdr,
4610 (*_bfd_error_handler)
4611 (_("%B: relocation %s against STT_GNU_IFUNC "
4612 "symbol `%s' has non-zero addend: %d"),
4613 input_bfd, howto->name, name, rel->r_addend);
4614 bfd_set_error (bfd_error_bad_value);
4618 /* Generate dynamic relocation only when there is a
4619 non-GOT reference in a shared object. */
4620 if (info->shared && h->non_got_ref)
4622 Elf_Internal_Rela outrel;
4625 /* Need a dynamic relocation to get the real function
4627 outrel.r_offset = _bfd_elf_section_offset (output_bfd,
4631 if (outrel.r_offset == (bfd_vma) -1
4632 || outrel.r_offset == (bfd_vma) -2)
4635 outrel.r_offset += (input_section->output_section->vma
4636 + input_section->output_offset);
4638 if (h->dynindx == -1
4640 || info->executable)
4642 /* This symbol is resolved locally. */
4643 outrel.r_info = ELFNN_R_INFO (0, AARCH64_R (IRELATIVE));
4644 outrel.r_addend = (h->root.u.def.value
4645 + h->root.u.def.section->output_section->vma
4646 + h->root.u.def.section->output_offset);
4650 outrel.r_info = ELFNN_R_INFO (h->dynindx, r_type);
4651 outrel.r_addend = 0;
4654 sreloc = globals->root.irelifunc;
4655 elf_append_rela (output_bfd, sreloc, &outrel);
4657 /* If this reloc is against an external symbol, we
4658 do not want to fiddle with the addend. Otherwise,
4659 we need to include the symbol value so that it
4660 becomes an addend for the dynamic reloc. For an
4661 internal symbol, we have updated addend. */
4662 return bfd_reloc_ok;
4665 case BFD_RELOC_AARCH64_CALL26:
4666 case BFD_RELOC_AARCH64_JUMP26:
4667 value = _bfd_aarch64_elf_resolve_relocation (bfd_r_type, place, value,
4670 return _bfd_aarch64_elf_put_addend (input_bfd, hit_data, bfd_r_type,
4672 case BFD_RELOC_AARCH64_ADR_GOT_PAGE:
4673 case BFD_RELOC_AARCH64_GOT_LD_PREL19:
4674 case BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14:
4675 case BFD_RELOC_AARCH64_LD32_GOT_LO12_NC:
4676 case BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15:
4677 case BFD_RELOC_AARCH64_LD64_GOT_LO12_NC:
4678 base_got = globals->root.sgot;
4679 off = h->got.offset;
4681 if (base_got == NULL)
4684 if (off == (bfd_vma) -1)
4688 /* We can't use h->got.offset here to save state, or
4689 even just remember the offset, as finish_dynamic_symbol
4690 would use that as offset into .got. */
4692 if (globals->root.splt != NULL)
4694 plt_index = ((h->plt.offset - globals->plt_header_size) /
4695 globals->plt_entry_size);
4696 off = (plt_index + 3) * GOT_ENTRY_SIZE;
4697 base_got = globals->root.sgotplt;
4701 plt_index = h->plt.offset / globals->plt_entry_size;
4702 off = plt_index * GOT_ENTRY_SIZE;
4703 base_got = globals->root.igotplt;
4706 if (h->dynindx == -1
4710 /* This references the local definition. We must
4711 initialize this entry in the global offset table.
4712 Since the offset must always be a multiple of 8,
4713 we use the least significant bit to record
4714 whether we have initialized it already.
4716 When doing a dynamic link, we create a .rela.got
4717 relocation entry to initialize the value. This
4718 is done in the finish_dynamic_symbol routine. */
4723 bfd_put_NN (output_bfd, value,
4724 base_got->contents + off);
4725 /* Note that this is harmless as -1 | 1 still is -1. */
4729 value = (base_got->output_section->vma
4730 + base_got->output_offset + off);
4733 value = aarch64_calculate_got_entry_vma (h, globals, info,
4735 unresolved_reloc_p);
4736 if (bfd_r_type == BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15
4737 || bfd_r_type == BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14)
4738 addend = (globals->root.sgot->output_section->vma
4739 + globals->root.sgot->output_offset);
4740 value = _bfd_aarch64_elf_resolve_relocation (bfd_r_type, place, value,
4741 addend, weak_undef_p);
4742 return _bfd_aarch64_elf_put_addend (input_bfd, hit_data, bfd_r_type, howto, value);
4743 case BFD_RELOC_AARCH64_ADD_LO12:
4744 case BFD_RELOC_AARCH64_ADR_HI21_PCREL:
4751 case BFD_RELOC_AARCH64_NONE:
4752 case BFD_RELOC_AARCH64_TLSDESC_CALL:
4753 *unresolved_reloc_p = FALSE;
4754 return bfd_reloc_ok;
4756 case BFD_RELOC_AARCH64_NN:
4758 /* When generating a shared object or relocatable executable, these
4759 relocations are copied into the output file to be resolved at
4761 if (((info->shared == TRUE) || globals->root.is_relocatable_executable)
4762 && (input_section->flags & SEC_ALLOC)
4764 || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
4765 || h->root.type != bfd_link_hash_undefweak))
4767 Elf_Internal_Rela outrel;
4769 bfd_boolean skip, relocate;
4772 *unresolved_reloc_p = FALSE;
4777 outrel.r_addend = signed_addend;
4779 _bfd_elf_section_offset (output_bfd, info, input_section,
4781 if (outrel.r_offset == (bfd_vma) - 1)
4783 else if (outrel.r_offset == (bfd_vma) - 2)
4789 outrel.r_offset += (input_section->output_section->vma
4790 + input_section->output_offset);
4793 memset (&outrel, 0, sizeof outrel);
4796 && (!info->shared || !SYMBOLIC_BIND (info, h) || !h->def_regular))
4797 outrel.r_info = ELFNN_R_INFO (h->dynindx, r_type);
4802 /* On SVR4-ish systems, the dynamic loader cannot
4803 relocate the text and data segments independently,
4804 so the symbol does not matter. */
4806 outrel.r_info = ELFNN_R_INFO (symbol, AARCH64_R (RELATIVE));
4807 outrel.r_addend += value;
4810 sreloc = elf_section_data (input_section)->sreloc;
4811 if (sreloc == NULL || sreloc->contents == NULL)
4812 return bfd_reloc_notsupported;
4814 loc = sreloc->contents + sreloc->reloc_count++ * RELOC_SIZE (globals);
4815 bfd_elfNN_swap_reloca_out (output_bfd, &outrel, loc);
4817 if (sreloc->reloc_count * RELOC_SIZE (globals) > sreloc->size)
4819 /* Sanity to check that we have previously allocated
4820 sufficient space in the relocation section for the
4821 number of relocations we actually want to emit. */
4825 /* If this reloc is against an external symbol, we do not want to
4826 fiddle with the addend. Otherwise, we need to include the symbol
4827 value so that it becomes an addend for the dynamic reloc. */
4829 return bfd_reloc_ok;
4831 return _bfd_final_link_relocate (howto, input_bfd, input_section,
4832 contents, rel->r_offset, value,
4836 value += signed_addend;
4839 case BFD_RELOC_AARCH64_CALL26:
4840 case BFD_RELOC_AARCH64_JUMP26:
4842 asection *splt = globals->root.splt;
4843 bfd_boolean via_plt_p =
4844 splt != NULL && h != NULL && h->plt.offset != (bfd_vma) - 1;
4846 /* A call to an undefined weak symbol is converted to a jump to
4847 the next instruction unless a PLT entry will be created.
4848 The jump to the next instruction is optimized as a NOP.
4849 Do the same for local undefined symbols. */
4850 if (weak_undef_p && ! via_plt_p)
4852 bfd_putl32 (INSN_NOP, hit_data);
4853 return bfd_reloc_ok;
4856 /* If the call goes through a PLT entry, make sure to
4857 check distance to the right destination address. */
4860 value = (splt->output_section->vma
4861 + splt->output_offset + h->plt.offset);
4862 *unresolved_reloc_p = FALSE;
4865 /* If the target symbol is global and marked as a function the
4866 relocation applies a function call or a tail call. In this
4867 situation we can veneer out of range branches. The veneers
4868 use IP0 and IP1 hence cannot be used arbitrary out of range
4869 branches that occur within the body of a function. */
4870 if (h && h->type == STT_FUNC)
4872 /* Check if a stub has to be inserted because the destination
4874 if (! aarch64_valid_branch_p (value, place))
4876 /* The target is out of reach, so redirect the branch to
4877 the local stub for this function. */
4878 struct elf_aarch64_stub_hash_entry *stub_entry;
4879 stub_entry = elfNN_aarch64_get_stub_entry (input_section,
4882 if (stub_entry != NULL)
4883 value = (stub_entry->stub_offset
4884 + stub_entry->stub_sec->output_offset
4885 + stub_entry->stub_sec->output_section->vma);
4889 value = _bfd_aarch64_elf_resolve_relocation (bfd_r_type, place, value,
4890 signed_addend, weak_undef_p);
4893 case BFD_RELOC_AARCH64_16_PCREL:
4894 case BFD_RELOC_AARCH64_32_PCREL:
4895 case BFD_RELOC_AARCH64_64_PCREL:
4896 case BFD_RELOC_AARCH64_ADR_HI21_NC_PCREL:
4897 case BFD_RELOC_AARCH64_ADR_HI21_PCREL:
4898 case BFD_RELOC_AARCH64_ADR_LO21_PCREL:
4899 case BFD_RELOC_AARCH64_LD_LO19_PCREL:
4901 && (input_section->flags & SEC_ALLOC) != 0
4902 && (input_section->flags & SEC_READONLY) != 0
4906 int howto_index = bfd_r_type - BFD_RELOC_AARCH64_RELOC_START;
4908 (*_bfd_error_handler)
4909 (_("%B: relocation %s against external symbol `%s' can not be used"
4910 " when making a shared object; recompile with -fPIC"),
4911 input_bfd, elfNN_aarch64_howto_table[howto_index].name,
4912 h->root.root.string);
4913 bfd_set_error (bfd_error_bad_value);
4917 case BFD_RELOC_AARCH64_16:
4919 case BFD_RELOC_AARCH64_32:
4921 case BFD_RELOC_AARCH64_ADD_LO12:
4922 case BFD_RELOC_AARCH64_BRANCH19:
4923 case BFD_RELOC_AARCH64_LDST128_LO12:
4924 case BFD_RELOC_AARCH64_LDST16_LO12:
4925 case BFD_RELOC_AARCH64_LDST32_LO12:
4926 case BFD_RELOC_AARCH64_LDST64_LO12:
4927 case BFD_RELOC_AARCH64_LDST8_LO12:
4928 case BFD_RELOC_AARCH64_MOVW_G0:
4929 case BFD_RELOC_AARCH64_MOVW_G0_NC:
4930 case BFD_RELOC_AARCH64_MOVW_G0_S:
4931 case BFD_RELOC_AARCH64_MOVW_G1:
4932 case BFD_RELOC_AARCH64_MOVW_G1_NC:
4933 case BFD_RELOC_AARCH64_MOVW_G1_S:
4934 case BFD_RELOC_AARCH64_MOVW_G2:
4935 case BFD_RELOC_AARCH64_MOVW_G2_NC:
4936 case BFD_RELOC_AARCH64_MOVW_G2_S:
4937 case BFD_RELOC_AARCH64_MOVW_G3:
4938 case BFD_RELOC_AARCH64_TSTBR14:
4939 value = _bfd_aarch64_elf_resolve_relocation (bfd_r_type, place, value,
4940 signed_addend, weak_undef_p);
4943 case BFD_RELOC_AARCH64_ADR_GOT_PAGE:
4944 case BFD_RELOC_AARCH64_GOT_LD_PREL19:
4945 case BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14:
4946 case BFD_RELOC_AARCH64_LD32_GOT_LO12_NC:
4947 case BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15:
4948 case BFD_RELOC_AARCH64_LD64_GOT_LO12_NC:
4949 if (globals->root.sgot == NULL)
4950 BFD_ASSERT (h != NULL);
4955 value = aarch64_calculate_got_entry_vma (h, globals, info, value,
4957 unresolved_reloc_p);
4958 if (bfd_r_type == BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15
4959 || bfd_r_type == BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14)
4960 addend = (globals->root.sgot->output_section->vma
4961 + globals->root.sgot->output_offset);
4962 value = _bfd_aarch64_elf_resolve_relocation (bfd_r_type, place, value,
4963 addend, weak_undef_p);
4968 struct elf_aarch64_local_symbol *locals
4969 = elf_aarch64_locals (input_bfd);
4973 int howto_index = bfd_r_type - BFD_RELOC_AARCH64_RELOC_START;
4974 (*_bfd_error_handler)
4975 (_("%B: Local symbol descriptor table be NULL when applying "
4976 "relocation %s against local symbol"),
4977 input_bfd, elfNN_aarch64_howto_table[howto_index].name);
4981 off = symbol_got_offset (input_bfd, h, r_symndx);
4982 base_got = globals->root.sgot;
4983 bfd_vma got_entry_addr = (base_got->output_section->vma
4984 + base_got->output_offset + off);
4986 if (!symbol_got_offset_mark_p (input_bfd, h, r_symndx))
4988 bfd_put_64 (output_bfd, value, base_got->contents + off);
4993 Elf_Internal_Rela outrel;
4995 /* For local symbol, we have done absolute relocation in static
4996 linking stageh. While for share library, we need to update
4997 the content of GOT entry according to the share objects
4998 loading base address. So we need to generate a
4999 R_AARCH64_RELATIVE reloc for dynamic linker. */
5000 s = globals->root.srelgot;
5004 outrel.r_offset = got_entry_addr;
5005 outrel.r_info = ELFNN_R_INFO (0, AARCH64_R (RELATIVE));
5006 outrel.r_addend = value;
5007 elf_append_rela (output_bfd, s, &outrel);
5010 symbol_got_offset_mark (input_bfd, h, r_symndx);
5013 /* Update the relocation value to GOT entry addr as we have transformed
5014 the direct data access into indirect data access through GOT. */
5015 value = got_entry_addr;
5017 if (bfd_r_type == BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15
5018 || bfd_r_type == BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14)
5019 addend = base_got->output_section->vma + base_got->output_offset;
5021 value = _bfd_aarch64_elf_resolve_relocation (bfd_r_type, place, value,
5022 addend, weak_undef_p);
5027 case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC:
5028 case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21:
5029 case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21:
5030 case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21:
5031 case BFD_RELOC_AARCH64_TLSIE_LD32_GOTTPREL_LO12_NC:
5032 case BFD_RELOC_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC:
5033 case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19:
5034 case BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21:
5035 case BFD_RELOC_AARCH64_TLSLD_ADR_PREL21:
5036 if (globals->root.sgot == NULL)
5037 return bfd_reloc_notsupported;
5039 value = (symbol_got_offset (input_bfd, h, r_symndx)
5040 + globals->root.sgot->output_section->vma
5041 + globals->root.sgot->output_offset);
5043 value = _bfd_aarch64_elf_resolve_relocation (bfd_r_type, place, value,
5045 *unresolved_reloc_p = FALSE;
5048 case BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_HI12:
5049 case BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_LO12:
5050 case BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_LO12_NC:
5051 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0:
5052 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC:
5053 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1:
5054 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1_NC:
5055 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G2:
5056 value = _bfd_aarch64_elf_resolve_relocation (bfd_r_type, place, value,
5057 signed_addend - tpoff_base (info),
5059 *unresolved_reloc_p = FALSE;
5062 case BFD_RELOC_AARCH64_TLSDESC_ADD:
5063 case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12_NC:
5064 case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21:
5065 case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21:
5066 case BFD_RELOC_AARCH64_TLSDESC_LD32_LO12_NC:
5067 case BFD_RELOC_AARCH64_TLSDESC_LD64_LO12_NC:
5068 case BFD_RELOC_AARCH64_TLSDESC_LDR:
5069 case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19:
5070 if (globals->root.sgot == NULL)
5071 return bfd_reloc_notsupported;
5072 value = (symbol_tlsdesc_got_offset (input_bfd, h, r_symndx)
5073 + globals->root.sgotplt->output_section->vma
5074 + globals->root.sgotplt->output_offset
5075 + globals->sgotplt_jump_table_size);
5077 value = _bfd_aarch64_elf_resolve_relocation (bfd_r_type, place, value,
5079 *unresolved_reloc_p = FALSE;
5083 return bfd_reloc_notsupported;
5087 *saved_addend = value;
5089 /* Only apply the final relocation in a sequence. */
5091 return bfd_reloc_continue;
5093 return _bfd_aarch64_elf_put_addend (input_bfd, hit_data, bfd_r_type,
5097 /* Handle TLS relaxations. Relaxing is possible for symbols that use
5098 R_AARCH64_TLSDESC_ADR_{PAGE, LD64_LO12_NC, ADD_LO12_NC} during a static
5101 Return bfd_reloc_ok if we're done, bfd_reloc_continue if the caller
5102 is to then call final_link_relocate. Return other values in the
5105 static bfd_reloc_status_type
5106 elfNN_aarch64_tls_relax (struct elf_aarch64_link_hash_table *globals,
5107 bfd *input_bfd, bfd_byte *contents,
5108 Elf_Internal_Rela *rel, struct elf_link_hash_entry *h)
5110 bfd_boolean is_local = h == NULL;
5111 unsigned int r_type = ELFNN_R_TYPE (rel->r_info);
5114 BFD_ASSERT (globals && input_bfd && contents && rel);
5116 switch (elfNN_aarch64_bfd_reloc_from_type (r_type))
5118 case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21:
5119 case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21:
5122 /* GD->LE relaxation:
5123 adrp x0, :tlsgd:var => movz x0, :tprel_g1:var
5125 adrp x0, :tlsdesc:var => movz x0, :tprel_g1:var
5127 bfd_putl32 (0xd2a00000, contents + rel->r_offset);
5128 return bfd_reloc_continue;
5132 /* GD->IE relaxation:
5133 adrp x0, :tlsgd:var => adrp x0, :gottprel:var
5135 adrp x0, :tlsdesc:var => adrp x0, :gottprel:var
5137 return bfd_reloc_continue;
5140 case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21:
5144 case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19:
5147 /* Tiny TLSDESC->LE relaxation:
5148 ldr x1, :tlsdesc:var => movz x0, #:tprel_g1:var
5149 adr x0, :tlsdesc:var => movk x0, #:tprel_g0_nc:var
5153 BFD_ASSERT (ELFNN_R_TYPE (rel[1].r_info) == AARCH64_R (TLSDESC_ADR_PREL21));
5154 BFD_ASSERT (ELFNN_R_TYPE (rel[2].r_info) == AARCH64_R (TLSDESC_CALL));
5156 rel[1].r_info = ELFNN_R_INFO (ELFNN_R_SYM (rel->r_info),
5157 AARCH64_R (TLSLE_MOVW_TPREL_G0_NC));
5158 rel[2].r_info = ELFNN_R_INFO (STN_UNDEF, R_AARCH64_NONE);
5160 bfd_putl32 (0xd2a00000, contents + rel->r_offset);
5161 bfd_putl32 (0xf2800000, contents + rel->r_offset + 4);
5162 bfd_putl32 (INSN_NOP, contents + rel->r_offset + 8);
5163 return bfd_reloc_continue;
5167 /* Tiny TLSDESC->IE relaxation:
5168 ldr x1, :tlsdesc:var => ldr x0, :gottprel:var
5169 adr x0, :tlsdesc:var => nop
5173 BFD_ASSERT (ELFNN_R_TYPE (rel[1].r_info) == AARCH64_R (TLSDESC_ADR_PREL21));
5174 BFD_ASSERT (ELFNN_R_TYPE (rel[2].r_info) == AARCH64_R (TLSDESC_CALL));
5176 rel[1].r_info = ELFNN_R_INFO (STN_UNDEF, R_AARCH64_NONE);
5177 rel[2].r_info = ELFNN_R_INFO (STN_UNDEF, R_AARCH64_NONE);
5179 bfd_putl32 (0x58000000, contents + rel->r_offset);
5180 bfd_putl32 (INSN_NOP, contents + rel->r_offset + 4);
5181 bfd_putl32 (INSN_NOP, contents + rel->r_offset + 8);
5182 return bfd_reloc_continue;
5185 case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21:
5188 /* Tiny GD->LE relaxation:
5189 adr x0, :tlsgd:var => mrs x1, tpidr_el0
5190 bl __tls_get_addr => add x0, x1, #:tprel_hi12:x, lsl #12
5191 nop => add x0, x0, #:tprel_lo12_nc:x
5194 /* First kill the tls_get_addr reloc on the bl instruction. */
5195 BFD_ASSERT (rel->r_offset + 4 == rel[1].r_offset);
5197 bfd_putl32 (0xd53bd041, contents + rel->r_offset + 0);
5198 bfd_putl32 (0x91400020, contents + rel->r_offset + 4);
5199 bfd_putl32 (0x91000000, contents + rel->r_offset + 8);
5201 rel[1].r_info = ELFNN_R_INFO (ELFNN_R_SYM (rel->r_info),
5202 AARCH64_R (TLSLE_ADD_TPREL_LO12_NC));
5203 rel[1].r_offset = rel->r_offset + 8;
5205 /* Move the current relocation to the second instruction in
5208 rel->r_info = ELFNN_R_INFO (ELFNN_R_SYM (rel->r_info),
5209 AARCH64_R (TLSLE_ADD_TPREL_HI12));
5210 return bfd_reloc_continue;
5214 /* Tiny GD->IE relaxation:
5215 adr x0, :tlsgd:var => ldr x0, :gottprel:var
5216 bl __tls_get_addr => mrs x1, tpidr_el0
5217 nop => add x0, x0, x1
5220 /* First kill the tls_get_addr reloc on the bl instruction. */
5221 BFD_ASSERT (rel->r_offset + 4 == rel[1].r_offset);
5222 rel[1].r_info = ELFNN_R_INFO (STN_UNDEF, R_AARCH64_NONE);
5224 bfd_putl32 (0x58000000, contents + rel->r_offset);
5225 bfd_putl32 (0xd53bd041, contents + rel->r_offset + 4);
5226 bfd_putl32 (0x8b000020, contents + rel->r_offset + 8);
5227 return bfd_reloc_continue;
5230 case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19:
5231 return bfd_reloc_continue;
5233 case BFD_RELOC_AARCH64_TLSDESC_LDNN_LO12_NC:
5236 /* GD->LE relaxation:
5237 ldr xd, [x0, #:tlsdesc_lo12:var] => movk x0, :tprel_g0_nc:var
5239 bfd_putl32 (0xf2800000, contents + rel->r_offset);
5240 return bfd_reloc_continue;
5244 /* GD->IE relaxation:
5245 ldr xd, [x0, #:tlsdesc_lo12:var] => ldr x0, [x0, #:gottprel_lo12:var]
5247 insn = bfd_getl32 (contents + rel->r_offset);
5249 bfd_putl32 (insn, contents + rel->r_offset);
5250 return bfd_reloc_continue;
5253 case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC:
5256 /* GD->LE relaxation
5257 add x0, #:tlsgd_lo12:var => movk x0, :tprel_g0_nc:var
5258 bl __tls_get_addr => mrs x1, tpidr_el0
5259 nop => add x0, x1, x0
5262 /* First kill the tls_get_addr reloc on the bl instruction. */
5263 BFD_ASSERT (rel->r_offset + 4 == rel[1].r_offset);
5264 rel[1].r_info = ELFNN_R_INFO (STN_UNDEF, R_AARCH64_NONE);
5266 bfd_putl32 (0xf2800000, contents + rel->r_offset);
5267 bfd_putl32 (0xd53bd041, contents + rel->r_offset + 4);
5268 bfd_putl32 (0x8b000020, contents + rel->r_offset + 8);
5269 return bfd_reloc_continue;
5273 /* GD->IE relaxation
5274 ADD x0, #:tlsgd_lo12:var => ldr x0, [x0, #:gottprel_lo12:var]
5275 BL __tls_get_addr => mrs x1, tpidr_el0
5277 NOP => add x0, x1, x0
5280 BFD_ASSERT (ELFNN_R_TYPE (rel[1].r_info) == AARCH64_R (CALL26));
5282 /* Remove the relocation on the BL instruction. */
5283 rel[1].r_info = ELFNN_R_INFO (STN_UNDEF, R_AARCH64_NONE);
5285 bfd_putl32 (0xf9400000, contents + rel->r_offset);
5287 /* We choose to fixup the BL and NOP instructions using the
5288 offset from the second relocation to allow flexibility in
5289 scheduling instructions between the ADD and BL. */
5290 bfd_putl32 (0xd53bd041, contents + rel[1].r_offset);
5291 bfd_putl32 (0x8b000020, contents + rel[1].r_offset + 4);
5292 return bfd_reloc_continue;
5295 case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12_NC:
5296 case BFD_RELOC_AARCH64_TLSDESC_CALL:
5297 /* GD->IE/LE relaxation:
5298 add x0, x0, #:tlsdesc_lo12:var => nop
5301 bfd_putl32 (INSN_NOP, contents + rel->r_offset);
5302 return bfd_reloc_ok;
5304 case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21:
5305 /* IE->LE relaxation:
5306 adrp xd, :gottprel:var => movz xd, :tprel_g1:var
5310 insn = bfd_getl32 (contents + rel->r_offset);
5311 bfd_putl32 (0xd2a00000 | (insn & 0x1f), contents + rel->r_offset);
5313 return bfd_reloc_continue;
5315 case BFD_RELOC_AARCH64_TLSIE_LDNN_GOTTPREL_LO12_NC:
5316 /* IE->LE relaxation:
5317 ldr xd, [xm, #:gottprel_lo12:var] => movk xd, :tprel_g0_nc:var
5321 insn = bfd_getl32 (contents + rel->r_offset);
5322 bfd_putl32 (0xf2800000 | (insn & 0x1f), contents + rel->r_offset);
5324 return bfd_reloc_continue;
5327 return bfd_reloc_continue;
5330 return bfd_reloc_ok;
5333 /* Relocate an AArch64 ELF section. */
5336 elfNN_aarch64_relocate_section (bfd *output_bfd,
5337 struct bfd_link_info *info,
5339 asection *input_section,
5341 Elf_Internal_Rela *relocs,
5342 Elf_Internal_Sym *local_syms,
5343 asection **local_sections)
5345 Elf_Internal_Shdr *symtab_hdr;
5346 struct elf_link_hash_entry **sym_hashes;
5347 Elf_Internal_Rela *rel;
5348 Elf_Internal_Rela *relend;
5350 struct elf_aarch64_link_hash_table *globals;
5351 bfd_boolean save_addend = FALSE;
5354 globals = elf_aarch64_hash_table (info);
5356 symtab_hdr = &elf_symtab_hdr (input_bfd);
5357 sym_hashes = elf_sym_hashes (input_bfd);
5360 relend = relocs + input_section->reloc_count;
5361 for (; rel < relend; rel++)
5363 unsigned int r_type;
5364 bfd_reloc_code_real_type bfd_r_type;
5365 bfd_reloc_code_real_type relaxed_bfd_r_type;
5366 reloc_howto_type *howto;
5367 unsigned long r_symndx;
5368 Elf_Internal_Sym *sym;
5370 struct elf_link_hash_entry *h;
5372 bfd_reloc_status_type r;
5375 bfd_boolean unresolved_reloc = FALSE;
5376 char *error_message = NULL;
5378 r_symndx = ELFNN_R_SYM (rel->r_info);
5379 r_type = ELFNN_R_TYPE (rel->r_info);
5381 bfd_reloc.howto = elfNN_aarch64_howto_from_type (r_type);
5382 howto = bfd_reloc.howto;
5386 (*_bfd_error_handler)
5387 (_("%B: unrecognized relocation (0x%x) in section `%A'"),
5388 input_bfd, input_section, r_type);
5391 bfd_r_type = elfNN_aarch64_bfd_reloc_from_howto (howto);
5397 if (r_symndx < symtab_hdr->sh_info)
5399 sym = local_syms + r_symndx;
5400 sym_type = ELFNN_ST_TYPE (sym->st_info);
5401 sec = local_sections[r_symndx];
5403 /* An object file might have a reference to a local
5404 undefined symbol. This is a daft object file, but we
5405 should at least do something about it. */
5406 if (r_type != R_AARCH64_NONE && r_type != R_AARCH64_NULL
5407 && bfd_is_und_section (sec)
5408 && ELF_ST_BIND (sym->st_info) != STB_WEAK)
5410 if (!info->callbacks->undefined_symbol
5411 (info, bfd_elf_string_from_elf_section
5412 (input_bfd, symtab_hdr->sh_link, sym->st_name),
5413 input_bfd, input_section, rel->r_offset, TRUE))
5417 relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel);
5419 /* Relocate against local STT_GNU_IFUNC symbol. */
5420 if (!info->relocatable
5421 && ELF_ST_TYPE (sym->st_info) == STT_GNU_IFUNC)
5423 h = elfNN_aarch64_get_local_sym_hash (globals, input_bfd,
5428 /* Set STT_GNU_IFUNC symbol value. */
5429 h->root.u.def.value = sym->st_value;
5430 h->root.u.def.section = sec;
5435 bfd_boolean warned, ignored;
5437 RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel,
5438 r_symndx, symtab_hdr, sym_hashes,
5440 unresolved_reloc, warned, ignored);
5445 if (sec != NULL && discarded_section (sec))
5446 RELOC_AGAINST_DISCARDED_SECTION (info, input_bfd, input_section,
5447 rel, 1, relend, howto, 0, contents);
5449 if (info->relocatable)
5453 name = h->root.root.string;
5456 name = (bfd_elf_string_from_elf_section
5457 (input_bfd, symtab_hdr->sh_link, sym->st_name));
5458 if (name == NULL || *name == '\0')
5459 name = bfd_section_name (input_bfd, sec);
5463 && r_type != R_AARCH64_NONE
5464 && r_type != R_AARCH64_NULL
5466 || h->root.type == bfd_link_hash_defined
5467 || h->root.type == bfd_link_hash_defweak)
5468 && IS_AARCH64_TLS_RELOC (bfd_r_type) != (sym_type == STT_TLS))
5470 (*_bfd_error_handler)
5471 ((sym_type == STT_TLS
5472 ? _("%B(%A+0x%lx): %s used with TLS symbol %s")
5473 : _("%B(%A+0x%lx): %s used with non-TLS symbol %s")),
5475 input_section, (long) rel->r_offset, howto->name, name);
5478 /* We relax only if we can see that there can be a valid transition
5479 from a reloc type to another.
5480 We call elfNN_aarch64_final_link_relocate unless we're completely
5481 done, i.e., the relaxation produced the final output we want. */
5483 relaxed_bfd_r_type = aarch64_tls_transition (input_bfd, info, r_type,
5485 if (relaxed_bfd_r_type != bfd_r_type)
5487 bfd_r_type = relaxed_bfd_r_type;
5488 howto = elfNN_aarch64_howto_from_bfd_reloc (bfd_r_type);
5489 BFD_ASSERT (howto != NULL);
5490 r_type = howto->type;
5491 r = elfNN_aarch64_tls_relax (globals, input_bfd, contents, rel, h);
5492 unresolved_reloc = 0;
5495 r = bfd_reloc_continue;
5497 /* There may be multiple consecutive relocations for the
5498 same offset. In that case we are supposed to treat the
5499 output of each relocation as the addend for the next. */
5500 if (rel + 1 < relend
5501 && rel->r_offset == rel[1].r_offset
5502 && ELFNN_R_TYPE (rel[1].r_info) != R_AARCH64_NONE
5503 && ELFNN_R_TYPE (rel[1].r_info) != R_AARCH64_NULL)
5506 save_addend = FALSE;
5508 if (r == bfd_reloc_continue)
5509 r = elfNN_aarch64_final_link_relocate (howto, input_bfd, output_bfd,
5510 input_section, contents, rel,
5511 relocation, info, sec,
5512 h, &unresolved_reloc,
5513 save_addend, &addend, sym);
5515 switch (elfNN_aarch64_bfd_reloc_from_type (r_type))
5517 case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC:
5518 case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21:
5519 case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21:
5520 case BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21:
5521 case BFD_RELOC_AARCH64_TLSLD_ADR_PREL21:
5522 if (! symbol_got_offset_mark_p (input_bfd, h, r_symndx))
5524 bfd_boolean need_relocs = FALSE;
5529 off = symbol_got_offset (input_bfd, h, r_symndx);
5530 indx = h && h->dynindx != -1 ? h->dynindx : 0;
5533 (info->shared || indx != 0) &&
5535 || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
5536 || h->root.type != bfd_link_hash_undefweak);
5538 BFD_ASSERT (globals->root.srelgot != NULL);
5542 Elf_Internal_Rela rela;
5543 rela.r_info = ELFNN_R_INFO (indx, AARCH64_R (TLS_DTPMOD));
5545 rela.r_offset = globals->root.sgot->output_section->vma +
5546 globals->root.sgot->output_offset + off;
5549 loc = globals->root.srelgot->contents;
5550 loc += globals->root.srelgot->reloc_count++
5551 * RELOC_SIZE (htab);
5552 bfd_elfNN_swap_reloca_out (output_bfd, &rela, loc);
5554 bfd_reloc_code_real_type real_type =
5555 elfNN_aarch64_bfd_reloc_from_type (r_type);
5557 if (real_type == BFD_RELOC_AARCH64_TLSLD_ADR_PREL21
5558 || real_type == BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21)
5560 /* For local dynamic, don't generate DTPREL in any case.
5561 Initialize the DTPREL slot into zero, so we get module
5562 base address when invoke runtime TLS resolver. */
5563 bfd_put_NN (output_bfd, 0,
5564 globals->root.sgot->contents + off
5569 bfd_put_NN (output_bfd,
5570 relocation - dtpoff_base (info),
5571 globals->root.sgot->contents + off
5576 /* This TLS symbol is global. We emit a
5577 relocation to fixup the tls offset at load
5580 ELFNN_R_INFO (indx, AARCH64_R (TLS_DTPREL));
5583 (globals->root.sgot->output_section->vma
5584 + globals->root.sgot->output_offset + off
5587 loc = globals->root.srelgot->contents;
5588 loc += globals->root.srelgot->reloc_count++
5589 * RELOC_SIZE (globals);
5590 bfd_elfNN_swap_reloca_out (output_bfd, &rela, loc);
5591 bfd_put_NN (output_bfd, (bfd_vma) 0,
5592 globals->root.sgot->contents + off
5598 bfd_put_NN (output_bfd, (bfd_vma) 1,
5599 globals->root.sgot->contents + off);
5600 bfd_put_NN (output_bfd,
5601 relocation - dtpoff_base (info),
5602 globals->root.sgot->contents + off
5606 symbol_got_offset_mark (input_bfd, h, r_symndx);
5610 case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21:
5611 case BFD_RELOC_AARCH64_TLSIE_LDNN_GOTTPREL_LO12_NC:
5612 case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19:
5613 if (! symbol_got_offset_mark_p (input_bfd, h, r_symndx))
5615 bfd_boolean need_relocs = FALSE;
5620 off = symbol_got_offset (input_bfd, h, r_symndx);
5622 indx = h && h->dynindx != -1 ? h->dynindx : 0;
5625 (info->shared || indx != 0) &&
5627 || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
5628 || h->root.type != bfd_link_hash_undefweak);
5630 BFD_ASSERT (globals->root.srelgot != NULL);
5634 Elf_Internal_Rela rela;
5637 rela.r_addend = relocation - dtpoff_base (info);
5641 rela.r_info = ELFNN_R_INFO (indx, AARCH64_R (TLS_TPREL));
5642 rela.r_offset = globals->root.sgot->output_section->vma +
5643 globals->root.sgot->output_offset + off;
5645 loc = globals->root.srelgot->contents;
5646 loc += globals->root.srelgot->reloc_count++
5647 * RELOC_SIZE (htab);
5649 bfd_elfNN_swap_reloca_out (output_bfd, &rela, loc);
5651 bfd_put_NN (output_bfd, rela.r_addend,
5652 globals->root.sgot->contents + off);
5655 bfd_put_NN (output_bfd, relocation - tpoff_base (info),
5656 globals->root.sgot->contents + off);
5658 symbol_got_offset_mark (input_bfd, h, r_symndx);
5662 case BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_HI12:
5663 case BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_LO12:
5664 case BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_LO12_NC:
5665 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0:
5666 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC:
5667 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1:
5668 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1_NC:
5669 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G2:
5672 case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12_NC:
5673 case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21:
5674 case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21:
5675 case BFD_RELOC_AARCH64_TLSDESC_LDNN_LO12_NC:
5676 case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19:
5677 if (! symbol_tlsdesc_got_offset_mark_p (input_bfd, h, r_symndx))
5679 bfd_boolean need_relocs = FALSE;
5680 int indx = h && h->dynindx != -1 ? h->dynindx : 0;
5681 bfd_vma off = symbol_tlsdesc_got_offset (input_bfd, h, r_symndx);
5683 need_relocs = (h == NULL
5684 || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
5685 || h->root.type != bfd_link_hash_undefweak);
5687 BFD_ASSERT (globals->root.srelgot != NULL);
5688 BFD_ASSERT (globals->root.sgot != NULL);
5693 Elf_Internal_Rela rela;
5694 rela.r_info = ELFNN_R_INFO (indx, AARCH64_R (TLSDESC));
5697 rela.r_offset = (globals->root.sgotplt->output_section->vma
5698 + globals->root.sgotplt->output_offset
5699 + off + globals->sgotplt_jump_table_size);
5702 rela.r_addend = relocation - dtpoff_base (info);
5704 /* Allocate the next available slot in the PLT reloc
5705 section to hold our R_AARCH64_TLSDESC, the next
5706 available slot is determined from reloc_count,
5707 which we step. But note, reloc_count was
5708 artifically moved down while allocating slots for
5709 real PLT relocs such that all of the PLT relocs
5710 will fit above the initial reloc_count and the
5711 extra stuff will fit below. */
5712 loc = globals->root.srelplt->contents;
5713 loc += globals->root.srelplt->reloc_count++
5714 * RELOC_SIZE (globals);
5716 bfd_elfNN_swap_reloca_out (output_bfd, &rela, loc);
5718 bfd_put_NN (output_bfd, (bfd_vma) 0,
5719 globals->root.sgotplt->contents + off +
5720 globals->sgotplt_jump_table_size);
5721 bfd_put_NN (output_bfd, (bfd_vma) 0,
5722 globals->root.sgotplt->contents + off +
5723 globals->sgotplt_jump_table_size +
5727 symbol_tlsdesc_got_offset_mark (input_bfd, h, r_symndx);
5738 /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
5739 because such sections are not SEC_ALLOC and thus ld.so will
5740 not process them. */
5741 if (unresolved_reloc
5742 && !((input_section->flags & SEC_DEBUGGING) != 0
5744 && _bfd_elf_section_offset (output_bfd, info, input_section,
5745 +rel->r_offset) != (bfd_vma) - 1)
5747 (*_bfd_error_handler)
5749 ("%B(%A+0x%lx): unresolvable %s relocation against symbol `%s'"),
5750 input_bfd, input_section, (long) rel->r_offset, howto->name,
5751 h->root.root.string);
5755 if (r != bfd_reloc_ok && r != bfd_reloc_continue)
5759 case bfd_reloc_overflow:
5760 if (!(*info->callbacks->reloc_overflow)
5761 (info, (h ? &h->root : NULL), name, howto->name, (bfd_vma) 0,
5762 input_bfd, input_section, rel->r_offset))
5766 case bfd_reloc_undefined:
5767 if (!((*info->callbacks->undefined_symbol)
5768 (info, name, input_bfd, input_section,
5769 rel->r_offset, TRUE)))
5773 case bfd_reloc_outofrange:
5774 error_message = _("out of range");
5777 case bfd_reloc_notsupported:
5778 error_message = _("unsupported relocation");
5781 case bfd_reloc_dangerous:
5782 /* error_message should already be set. */
5786 error_message = _("unknown error");
5790 BFD_ASSERT (error_message != NULL);
5791 if (!((*info->callbacks->reloc_dangerous)
5792 (info, error_message, input_bfd, input_section,
5803 /* Set the right machine number. */
5806 elfNN_aarch64_object_p (bfd *abfd)
5809 bfd_default_set_arch_mach (abfd, bfd_arch_aarch64, bfd_mach_aarch64_ilp32);
5811 bfd_default_set_arch_mach (abfd, bfd_arch_aarch64, bfd_mach_aarch64);
5816 /* Function to keep AArch64 specific flags in the ELF header. */
5819 elfNN_aarch64_set_private_flags (bfd *abfd, flagword flags)
5821 if (elf_flags_init (abfd) && elf_elfheader (abfd)->e_flags != flags)
5826 elf_elfheader (abfd)->e_flags = flags;
5827 elf_flags_init (abfd) = TRUE;
5833 /* Merge backend specific data from an object file to the output
5834 object file when linking. */
5837 elfNN_aarch64_merge_private_bfd_data (bfd *ibfd, bfd *obfd)
5841 bfd_boolean flags_compatible = TRUE;
5844 /* Check if we have the same endianess. */
5845 if (!_bfd_generic_verify_endian_match (ibfd, obfd))
5848 if (!is_aarch64_elf (ibfd) || !is_aarch64_elf (obfd))
5851 /* The input BFD must have had its flags initialised. */
5852 /* The following seems bogus to me -- The flags are initialized in
5853 the assembler but I don't think an elf_flags_init field is
5854 written into the object. */
5855 /* BFD_ASSERT (elf_flags_init (ibfd)); */
5857 in_flags = elf_elfheader (ibfd)->e_flags;
5858 out_flags = elf_elfheader (obfd)->e_flags;
5860 if (!elf_flags_init (obfd))
5862 /* If the input is the default architecture and had the default
5863 flags then do not bother setting the flags for the output
5864 architecture, instead allow future merges to do this. If no
5865 future merges ever set these flags then they will retain their
5866 uninitialised values, which surprise surprise, correspond
5867 to the default values. */
5868 if (bfd_get_arch_info (ibfd)->the_default
5869 && elf_elfheader (ibfd)->e_flags == 0)
5872 elf_flags_init (obfd) = TRUE;
5873 elf_elfheader (obfd)->e_flags = in_flags;
5875 if (bfd_get_arch (obfd) == bfd_get_arch (ibfd)
5876 && bfd_get_arch_info (obfd)->the_default)
5877 return bfd_set_arch_mach (obfd, bfd_get_arch (ibfd),
5878 bfd_get_mach (ibfd));
5883 /* Identical flags must be compatible. */
5884 if (in_flags == out_flags)
5887 /* Check to see if the input BFD actually contains any sections. If
5888 not, its flags may not have been initialised either, but it
5889 cannot actually cause any incompatiblity. Do not short-circuit
5890 dynamic objects; their section list may be emptied by
5891 elf_link_add_object_symbols.
5893 Also check to see if there are no code sections in the input.
5894 In this case there is no need to check for code specific flags.
5895 XXX - do we need to worry about floating-point format compatability
5896 in data sections ? */
5897 if (!(ibfd->flags & DYNAMIC))
5899 bfd_boolean null_input_bfd = TRUE;
5900 bfd_boolean only_data_sections = TRUE;
5902 for (sec = ibfd->sections; sec != NULL; sec = sec->next)
5904 if ((bfd_get_section_flags (ibfd, sec)
5905 & (SEC_LOAD | SEC_CODE | SEC_HAS_CONTENTS))
5906 == (SEC_LOAD | SEC_CODE | SEC_HAS_CONTENTS))
5907 only_data_sections = FALSE;
5909 null_input_bfd = FALSE;
5913 if (null_input_bfd || only_data_sections)
5917 return flags_compatible;
5920 /* Display the flags field. */
5923 elfNN_aarch64_print_private_bfd_data (bfd *abfd, void *ptr)
5925 FILE *file = (FILE *) ptr;
5926 unsigned long flags;
5928 BFD_ASSERT (abfd != NULL && ptr != NULL);
5930 /* Print normal ELF private data. */
5931 _bfd_elf_print_private_bfd_data (abfd, ptr);
5933 flags = elf_elfheader (abfd)->e_flags;
5934 /* Ignore init flag - it may not be set, despite the flags field
5935 containing valid data. */
5937 /* xgettext:c-format */
5938 fprintf (file, _("private flags = %lx:"), elf_elfheader (abfd)->e_flags);
5941 fprintf (file, _("<Unrecognised flag bits set>"));
5948 /* Update the got entry reference counts for the section being removed. */
5951 elfNN_aarch64_gc_sweep_hook (bfd *abfd,
5952 struct bfd_link_info *info,
5954 const Elf_Internal_Rela * relocs)
5956 struct elf_aarch64_link_hash_table *htab;
5957 Elf_Internal_Shdr *symtab_hdr;
5958 struct elf_link_hash_entry **sym_hashes;
5959 struct elf_aarch64_local_symbol *locals;
5960 const Elf_Internal_Rela *rel, *relend;
5962 if (info->relocatable)
5965 htab = elf_aarch64_hash_table (info);
5970 elf_section_data (sec)->local_dynrel = NULL;
5972 symtab_hdr = &elf_symtab_hdr (abfd);
5973 sym_hashes = elf_sym_hashes (abfd);
5975 locals = elf_aarch64_locals (abfd);
5977 relend = relocs + sec->reloc_count;
5978 for (rel = relocs; rel < relend; rel++)
5980 unsigned long r_symndx;
5981 unsigned int r_type;
5982 struct elf_link_hash_entry *h = NULL;
5984 r_symndx = ELFNN_R_SYM (rel->r_info);
5986 if (r_symndx >= symtab_hdr->sh_info)
5989 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
5990 while (h->root.type == bfd_link_hash_indirect
5991 || h->root.type == bfd_link_hash_warning)
5992 h = (struct elf_link_hash_entry *) h->root.u.i.link;
5996 Elf_Internal_Sym *isym;
5998 /* A local symbol. */
5999 isym = bfd_sym_from_r_symndx (&htab->sym_cache,
6002 /* Check relocation against local STT_GNU_IFUNC symbol. */
6004 && ELF_ST_TYPE (isym->st_info) == STT_GNU_IFUNC)
6006 h = elfNN_aarch64_get_local_sym_hash (htab, abfd, rel, FALSE);
6014 struct elf_aarch64_link_hash_entry *eh;
6015 struct elf_dyn_relocs **pp;
6016 struct elf_dyn_relocs *p;
6018 eh = (struct elf_aarch64_link_hash_entry *) h;
6020 for (pp = &eh->dyn_relocs; (p = *pp) != NULL; pp = &p->next)
6023 /* Everything must go for SEC. */
6029 r_type = ELFNN_R_TYPE (rel->r_info);
6030 switch (aarch64_tls_transition (abfd,info, r_type, h ,r_symndx))
6032 case BFD_RELOC_AARCH64_ADR_GOT_PAGE:
6033 case BFD_RELOC_AARCH64_GOT_LD_PREL19:
6034 case BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14:
6035 case BFD_RELOC_AARCH64_LD32_GOT_LO12_NC:
6036 case BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15:
6037 case BFD_RELOC_AARCH64_LD64_GOT_LO12_NC:
6038 case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12_NC:
6039 case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21:
6040 case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21:
6041 case BFD_RELOC_AARCH64_TLSDESC_LD32_LO12_NC:
6042 case BFD_RELOC_AARCH64_TLSDESC_LD64_LO12_NC:
6043 case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19:
6044 case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC:
6045 case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21:
6046 case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21:
6047 case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21:
6048 case BFD_RELOC_AARCH64_TLSIE_LD32_GOTTPREL_LO12_NC:
6049 case BFD_RELOC_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC:
6050 case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19:
6051 case BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21:
6052 case BFD_RELOC_AARCH64_TLSLD_ADR_PREL21:
6053 case BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_HI12:
6054 case BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_LO12:
6055 case BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_LO12_NC:
6056 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0:
6057 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC:
6058 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1:
6059 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1_NC:
6060 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G2:
6063 if (h->got.refcount > 0)
6064 h->got.refcount -= 1;
6066 if (h->type == STT_GNU_IFUNC)
6068 if (h->plt.refcount > 0)
6069 h->plt.refcount -= 1;
6072 else if (locals != NULL)
6074 if (locals[r_symndx].got_refcount > 0)
6075 locals[r_symndx].got_refcount -= 1;
6079 case BFD_RELOC_AARCH64_CALL26:
6080 case BFD_RELOC_AARCH64_JUMP26:
6081 /* If this is a local symbol then we resolve it
6082 directly without creating a PLT entry. */
6086 if (h->plt.refcount > 0)
6087 h->plt.refcount -= 1;
6090 case BFD_RELOC_AARCH64_ADR_HI21_NC_PCREL:
6091 case BFD_RELOC_AARCH64_ADR_HI21_PCREL:
6092 case BFD_RELOC_AARCH64_ADR_LO21_PCREL:
6093 case BFD_RELOC_AARCH64_MOVW_G0_NC:
6094 case BFD_RELOC_AARCH64_MOVW_G1_NC:
6095 case BFD_RELOC_AARCH64_MOVW_G2_NC:
6096 case BFD_RELOC_AARCH64_MOVW_G3:
6097 case BFD_RELOC_AARCH64_NN:
6098 if (h != NULL && info->executable)
6100 if (h->plt.refcount > 0)
6101 h->plt.refcount -= 1;
6113 /* Adjust a symbol defined by a dynamic object and referenced by a
6114 regular object. The current definition is in some section of the
6115 dynamic object, but we're not including those sections. We have to
6116 change the definition to something the rest of the link can
6120 elfNN_aarch64_adjust_dynamic_symbol (struct bfd_link_info *info,
6121 struct elf_link_hash_entry *h)
6123 struct elf_aarch64_link_hash_table *htab;
6126 /* If this is a function, put it in the procedure linkage table. We
6127 will fill in the contents of the procedure linkage table later,
6128 when we know the address of the .got section. */
6129 if (h->type == STT_FUNC || h->type == STT_GNU_IFUNC || h->needs_plt)
6131 if (h->plt.refcount <= 0
6132 || (h->type != STT_GNU_IFUNC
6133 && (SYMBOL_CALLS_LOCAL (info, h)
6134 || (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
6135 && h->root.type == bfd_link_hash_undefweak))))
6137 /* This case can occur if we saw a CALL26 reloc in
6138 an input file, but the symbol wasn't referred to
6139 by a dynamic object or all references were
6140 garbage collected. In which case we can end up
6142 h->plt.offset = (bfd_vma) - 1;
6149 /* Otherwise, reset to -1. */
6150 h->plt.offset = (bfd_vma) - 1;
6153 /* If this is a weak symbol, and there is a real definition, the
6154 processor independent code will have arranged for us to see the
6155 real definition first, and we can just use the same value. */
6156 if (h->u.weakdef != NULL)
6158 BFD_ASSERT (h->u.weakdef->root.type == bfd_link_hash_defined
6159 || h->u.weakdef->root.type == bfd_link_hash_defweak);
6160 h->root.u.def.section = h->u.weakdef->root.u.def.section;
6161 h->root.u.def.value = h->u.weakdef->root.u.def.value;
6162 if (ELIMINATE_COPY_RELOCS || info->nocopyreloc)
6163 h->non_got_ref = h->u.weakdef->non_got_ref;
6167 /* If we are creating a shared library, we must presume that the
6168 only references to the symbol are via the global offset table.
6169 For such cases we need not do anything here; the relocations will
6170 be handled correctly by relocate_section. */
6174 /* If there are no references to this symbol that do not use the
6175 GOT, we don't need to generate a copy reloc. */
6176 if (!h->non_got_ref)
6179 /* If -z nocopyreloc was given, we won't generate them either. */
6180 if (info->nocopyreloc)
6186 /* We must allocate the symbol in our .dynbss section, which will
6187 become part of the .bss section of the executable. There will be
6188 an entry for this symbol in the .dynsym section. The dynamic
6189 object will contain position independent code, so all references
6190 from the dynamic object to this symbol will go through the global
6191 offset table. The dynamic linker will use the .dynsym entry to
6192 determine the address it must put in the global offset table, so
6193 both the dynamic object and the regular object will refer to the
6194 same memory location for the variable. */
6196 htab = elf_aarch64_hash_table (info);
6198 /* We must generate a R_AARCH64_COPY reloc to tell the dynamic linker
6199 to copy the initial value out of the dynamic object and into the
6200 runtime process image. */
6201 if ((h->root.u.def.section->flags & SEC_ALLOC) != 0 && h->size != 0)
6203 htab->srelbss->size += RELOC_SIZE (htab);
6209 return _bfd_elf_adjust_dynamic_copy (info, h, s);
6214 elfNN_aarch64_allocate_local_symbols (bfd *abfd, unsigned number)
6216 struct elf_aarch64_local_symbol *locals;
6217 locals = elf_aarch64_locals (abfd);
6220 locals = (struct elf_aarch64_local_symbol *)
6221 bfd_zalloc (abfd, number * sizeof (struct elf_aarch64_local_symbol));
6224 elf_aarch64_locals (abfd) = locals;
6229 /* Create the .got section to hold the global offset table. */
6232 aarch64_elf_create_got_section (bfd *abfd, struct bfd_link_info *info)
6234 const struct elf_backend_data *bed = get_elf_backend_data (abfd);
6237 struct elf_link_hash_entry *h;
6238 struct elf_link_hash_table *htab = elf_hash_table (info);
6240 /* This function may be called more than once. */
6241 s = bfd_get_linker_section (abfd, ".got");
6245 flags = bed->dynamic_sec_flags;
6247 s = bfd_make_section_anyway_with_flags (abfd,
6248 (bed->rela_plts_and_copies_p
6249 ? ".rela.got" : ".rel.got"),
6250 (bed->dynamic_sec_flags
6253 || ! bfd_set_section_alignment (abfd, s, bed->s->log_file_align))
6257 s = bfd_make_section_anyway_with_flags (abfd, ".got", flags);
6259 || !bfd_set_section_alignment (abfd, s, bed->s->log_file_align))
6262 htab->sgot->size += GOT_ENTRY_SIZE;
6264 if (bed->want_got_sym)
6266 /* Define the symbol _GLOBAL_OFFSET_TABLE_ at the start of the .got
6267 (or .got.plt) section. We don't do this in the linker script
6268 because we don't want to define the symbol if we are not creating
6269 a global offset table. */
6270 h = _bfd_elf_define_linkage_sym (abfd, info, s,
6271 "_GLOBAL_OFFSET_TABLE_");
6272 elf_hash_table (info)->hgot = h;
6277 if (bed->want_got_plt)
6279 s = bfd_make_section_anyway_with_flags (abfd, ".got.plt", flags);
6281 || !bfd_set_section_alignment (abfd, s,
6282 bed->s->log_file_align))
6287 /* The first bit of the global offset table is the header. */
6288 s->size += bed->got_header_size;
6293 /* Look through the relocs for a section during the first phase. */
6296 elfNN_aarch64_check_relocs (bfd *abfd, struct bfd_link_info *info,
6297 asection *sec, const Elf_Internal_Rela *relocs)
6299 Elf_Internal_Shdr *symtab_hdr;
6300 struct elf_link_hash_entry **sym_hashes;
6301 const Elf_Internal_Rela *rel;
6302 const Elf_Internal_Rela *rel_end;
6305 struct elf_aarch64_link_hash_table *htab;
6307 if (info->relocatable)
6310 BFD_ASSERT (is_aarch64_elf (abfd));
6312 htab = elf_aarch64_hash_table (info);
6315 symtab_hdr = &elf_symtab_hdr (abfd);
6316 sym_hashes = elf_sym_hashes (abfd);
6318 rel_end = relocs + sec->reloc_count;
6319 for (rel = relocs; rel < rel_end; rel++)
6321 struct elf_link_hash_entry *h;
6322 unsigned long r_symndx;
6323 unsigned int r_type;
6324 bfd_reloc_code_real_type bfd_r_type;
6325 Elf_Internal_Sym *isym;
6327 r_symndx = ELFNN_R_SYM (rel->r_info);
6328 r_type = ELFNN_R_TYPE (rel->r_info);
6330 if (r_symndx >= NUM_SHDR_ENTRIES (symtab_hdr))
6332 (*_bfd_error_handler) (_("%B: bad symbol index: %d"), abfd,
6337 if (r_symndx < symtab_hdr->sh_info)
6339 /* A local symbol. */
6340 isym = bfd_sym_from_r_symndx (&htab->sym_cache,
6345 /* Check relocation against local STT_GNU_IFUNC symbol. */
6346 if (ELF_ST_TYPE (isym->st_info) == STT_GNU_IFUNC)
6348 h = elfNN_aarch64_get_local_sym_hash (htab, abfd, rel,
6353 /* Fake a STT_GNU_IFUNC symbol. */
6354 h->type = STT_GNU_IFUNC;
6357 h->forced_local = 1;
6358 h->root.type = bfd_link_hash_defined;
6365 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
6366 while (h->root.type == bfd_link_hash_indirect
6367 || h->root.type == bfd_link_hash_warning)
6368 h = (struct elf_link_hash_entry *) h->root.u.i.link;
6370 /* PR15323, ref flags aren't set for references in the same
6372 h->root.non_ir_ref = 1;
6375 /* Could be done earlier, if h were already available. */
6376 bfd_r_type = aarch64_tls_transition (abfd, info, r_type, h, r_symndx);
6380 /* Create the ifunc sections for static executables. If we
6381 never see an indirect function symbol nor we are building
6382 a static executable, those sections will be empty and
6383 won't appear in output. */
6389 case BFD_RELOC_AARCH64_ADD_LO12:
6390 case BFD_RELOC_AARCH64_ADR_GOT_PAGE:
6391 case BFD_RELOC_AARCH64_ADR_HI21_PCREL:
6392 case BFD_RELOC_AARCH64_CALL26:
6393 case BFD_RELOC_AARCH64_GOT_LD_PREL19:
6394 case BFD_RELOC_AARCH64_JUMP26:
6395 case BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14:
6396 case BFD_RELOC_AARCH64_LD32_GOT_LO12_NC:
6397 case BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15:
6398 case BFD_RELOC_AARCH64_LD64_GOT_LO12_NC:
6399 case BFD_RELOC_AARCH64_NN:
6400 if (htab->root.dynobj == NULL)
6401 htab->root.dynobj = abfd;
6402 if (!_bfd_elf_create_ifunc_sections (htab->root.dynobj, info))
6407 /* It is referenced by a non-shared object. */
6409 h->root.non_ir_ref = 1;
6414 case BFD_RELOC_AARCH64_NN:
6416 /* We don't need to handle relocs into sections not going into
6417 the "real" output. */
6418 if ((sec->flags & SEC_ALLOC) == 0)
6426 h->plt.refcount += 1;
6427 h->pointer_equality_needed = 1;
6430 /* No need to do anything if we're not creating a shared
6436 struct elf_dyn_relocs *p;
6437 struct elf_dyn_relocs **head;
6439 /* We must copy these reloc types into the output file.
6440 Create a reloc section in dynobj and make room for
6444 if (htab->root.dynobj == NULL)
6445 htab->root.dynobj = abfd;
6447 sreloc = _bfd_elf_make_dynamic_reloc_section
6448 (sec, htab->root.dynobj, LOG_FILE_ALIGN, abfd, /*rela? */ TRUE);
6454 /* If this is a global symbol, we count the number of
6455 relocations we need for this symbol. */
6458 struct elf_aarch64_link_hash_entry *eh;
6459 eh = (struct elf_aarch64_link_hash_entry *) h;
6460 head = &eh->dyn_relocs;
6464 /* Track dynamic relocs needed for local syms too.
6465 We really need local syms available to do this
6471 isym = bfd_sym_from_r_symndx (&htab->sym_cache,
6476 s = bfd_section_from_elf_index (abfd, isym->st_shndx);
6480 /* Beware of type punned pointers vs strict aliasing
6482 vpp = &(elf_section_data (s)->local_dynrel);
6483 head = (struct elf_dyn_relocs **) vpp;
6487 if (p == NULL || p->sec != sec)
6489 bfd_size_type amt = sizeof *p;
6490 p = ((struct elf_dyn_relocs *)
6491 bfd_zalloc (htab->root.dynobj, amt));
6504 /* RR: We probably want to keep a consistency check that
6505 there are no dangling GOT_PAGE relocs. */
6506 case BFD_RELOC_AARCH64_ADR_GOT_PAGE:
6507 case BFD_RELOC_AARCH64_GOT_LD_PREL19:
6508 case BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14:
6509 case BFD_RELOC_AARCH64_LD32_GOT_LO12_NC:
6510 case BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15:
6511 case BFD_RELOC_AARCH64_LD64_GOT_LO12_NC:
6512 case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12_NC:
6513 case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21:
6514 case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21:
6515 case BFD_RELOC_AARCH64_TLSDESC_LD32_LO12_NC:
6516 case BFD_RELOC_AARCH64_TLSDESC_LD64_LO12_NC:
6517 case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19:
6518 case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC:
6519 case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21:
6520 case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21:
6521 case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21:
6522 case BFD_RELOC_AARCH64_TLSIE_LD32_GOTTPREL_LO12_NC:
6523 case BFD_RELOC_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC:
6524 case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19:
6525 case BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21:
6526 case BFD_RELOC_AARCH64_TLSLD_ADR_PREL21:
6527 case BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_HI12:
6528 case BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_LO12:
6529 case BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_LO12_NC:
6530 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0:
6531 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC:
6532 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1:
6533 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1_NC:
6534 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G2:
6537 unsigned old_got_type;
6539 got_type = aarch64_reloc_got_type (bfd_r_type);
6543 h->got.refcount += 1;
6544 old_got_type = elf_aarch64_hash_entry (h)->got_type;
6548 struct elf_aarch64_local_symbol *locals;
6550 if (!elfNN_aarch64_allocate_local_symbols
6551 (abfd, symtab_hdr->sh_info))
6554 locals = elf_aarch64_locals (abfd);
6555 BFD_ASSERT (r_symndx < symtab_hdr->sh_info);
6556 locals[r_symndx].got_refcount += 1;
6557 old_got_type = locals[r_symndx].got_type;
6560 /* If a variable is accessed with both general dynamic TLS
6561 methods, two slots may be created. */
6562 if (GOT_TLS_GD_ANY_P (old_got_type) && GOT_TLS_GD_ANY_P (got_type))
6563 got_type |= old_got_type;
6565 /* We will already have issued an error message if there
6566 is a TLS/non-TLS mismatch, based on the symbol type.
6567 So just combine any TLS types needed. */
6568 if (old_got_type != GOT_UNKNOWN && old_got_type != GOT_NORMAL
6569 && got_type != GOT_NORMAL)
6570 got_type |= old_got_type;
6572 /* If the symbol is accessed by both IE and GD methods, we
6573 are able to relax. Turn off the GD flag, without
6574 messing up with any other kind of TLS types that may be
6576 if ((got_type & GOT_TLS_IE) && GOT_TLS_GD_ANY_P (got_type))
6577 got_type &= ~ (GOT_TLSDESC_GD | GOT_TLS_GD);
6579 if (old_got_type != got_type)
6582 elf_aarch64_hash_entry (h)->got_type = got_type;
6585 struct elf_aarch64_local_symbol *locals;
6586 locals = elf_aarch64_locals (abfd);
6587 BFD_ASSERT (r_symndx < symtab_hdr->sh_info);
6588 locals[r_symndx].got_type = got_type;
6592 if (htab->root.dynobj == NULL)
6593 htab->root.dynobj = abfd;
6594 if (! aarch64_elf_create_got_section (htab->root.dynobj, info))
6599 case BFD_RELOC_AARCH64_MOVW_G0_NC:
6600 case BFD_RELOC_AARCH64_MOVW_G1_NC:
6601 case BFD_RELOC_AARCH64_MOVW_G2_NC:
6602 case BFD_RELOC_AARCH64_MOVW_G3:
6605 int howto_index = bfd_r_type - BFD_RELOC_AARCH64_RELOC_START;
6606 (*_bfd_error_handler)
6607 (_("%B: relocation %s against `%s' can not be used when making "
6608 "a shared object; recompile with -fPIC"),
6609 abfd, elfNN_aarch64_howto_table[howto_index].name,
6610 (h) ? h->root.root.string : "a local symbol");
6611 bfd_set_error (bfd_error_bad_value);
6615 case BFD_RELOC_AARCH64_ADR_HI21_NC_PCREL:
6616 case BFD_RELOC_AARCH64_ADR_HI21_PCREL:
6617 case BFD_RELOC_AARCH64_ADR_LO21_PCREL:
6618 if (h != NULL && info->executable)
6620 /* If this reloc is in a read-only section, we might
6621 need a copy reloc. We can't check reliably at this
6622 stage whether the section is read-only, as input
6623 sections have not yet been mapped to output sections.
6624 Tentatively set the flag for now, and correct in
6625 adjust_dynamic_symbol. */
6627 h->plt.refcount += 1;
6628 h->pointer_equality_needed = 1;
6630 /* FIXME:: RR need to handle these in shared libraries
6631 and essentially bomb out as these being non-PIC
6632 relocations in shared libraries. */
6635 case BFD_RELOC_AARCH64_CALL26:
6636 case BFD_RELOC_AARCH64_JUMP26:
6637 /* If this is a local symbol then we resolve it
6638 directly without creating a PLT entry. */
6643 if (h->plt.refcount <= 0)
6644 h->plt.refcount = 1;
6646 h->plt.refcount += 1;
6657 /* Treat mapping symbols as special target symbols. */
6660 elfNN_aarch64_is_target_special_symbol (bfd *abfd ATTRIBUTE_UNUSED,
6663 return bfd_is_aarch64_special_symbol_name (sym->name,
6664 BFD_AARCH64_SPECIAL_SYM_TYPE_ANY);
6667 /* This is a copy of elf_find_function () from elf.c except that
6668 AArch64 mapping symbols are ignored when looking for function names. */
6671 aarch64_elf_find_function (bfd *abfd ATTRIBUTE_UNUSED,
6675 const char **filename_ptr,
6676 const char **functionname_ptr)
6678 const char *filename = NULL;
6679 asymbol *func = NULL;
6680 bfd_vma low_func = 0;
6683 for (p = symbols; *p != NULL; p++)
6687 q = (elf_symbol_type *) * p;
6689 switch (ELF_ST_TYPE (q->internal_elf_sym.st_info))
6694 filename = bfd_asymbol_name (&q->symbol);
6698 /* Skip mapping symbols. */
6699 if ((q->symbol.flags & BSF_LOCAL)
6700 && (bfd_is_aarch64_special_symbol_name
6701 (q->symbol.name, BFD_AARCH64_SPECIAL_SYM_TYPE_ANY)))
6704 if (bfd_get_section (&q->symbol) == section
6705 && q->symbol.value >= low_func && q->symbol.value <= offset)
6707 func = (asymbol *) q;
6708 low_func = q->symbol.value;
6718 *filename_ptr = filename;
6719 if (functionname_ptr)
6720 *functionname_ptr = bfd_asymbol_name (func);
6726 /* Find the nearest line to a particular section and offset, for error
6727 reporting. This code is a duplicate of the code in elf.c, except
6728 that it uses aarch64_elf_find_function. */
6731 elfNN_aarch64_find_nearest_line (bfd *abfd,
6735 const char **filename_ptr,
6736 const char **functionname_ptr,
6737 unsigned int *line_ptr,
6738 unsigned int *discriminator_ptr)
6740 bfd_boolean found = FALSE;
6742 if (_bfd_dwarf2_find_nearest_line (abfd, symbols, NULL, section, offset,
6743 filename_ptr, functionname_ptr,
6744 line_ptr, discriminator_ptr,
6745 dwarf_debug_sections, 0,
6746 &elf_tdata (abfd)->dwarf2_find_line_info))
6748 if (!*functionname_ptr)
6749 aarch64_elf_find_function (abfd, symbols, section, offset,
6750 *filename_ptr ? NULL : filename_ptr,
6756 /* Skip _bfd_dwarf1_find_nearest_line since no known AArch64
6757 toolchain uses DWARF1. */
6759 if (!_bfd_stab_section_find_nearest_line (abfd, symbols, section, offset,
6760 &found, filename_ptr,
6761 functionname_ptr, line_ptr,
6762 &elf_tdata (abfd)->line_info))
6765 if (found && (*functionname_ptr || *line_ptr))
6768 if (symbols == NULL)
6771 if (!aarch64_elf_find_function (abfd, symbols, section, offset,
6772 filename_ptr, functionname_ptr))
6780 elfNN_aarch64_find_inliner_info (bfd *abfd,
6781 const char **filename_ptr,
6782 const char **functionname_ptr,
6783 unsigned int *line_ptr)
6786 found = _bfd_dwarf2_find_inliner_info
6787 (abfd, filename_ptr,
6788 functionname_ptr, line_ptr, &elf_tdata (abfd)->dwarf2_find_line_info);
6794 elfNN_aarch64_post_process_headers (bfd *abfd,
6795 struct bfd_link_info *link_info)
6797 Elf_Internal_Ehdr *i_ehdrp; /* ELF file header, internal form. */
6799 i_ehdrp = elf_elfheader (abfd);
6800 i_ehdrp->e_ident[EI_ABIVERSION] = AARCH64_ELF_ABI_VERSION;
6802 _bfd_elf_post_process_headers (abfd, link_info);
6805 static enum elf_reloc_type_class
6806 elfNN_aarch64_reloc_type_class (const struct bfd_link_info *info ATTRIBUTE_UNUSED,
6807 const asection *rel_sec ATTRIBUTE_UNUSED,
6808 const Elf_Internal_Rela *rela)
6810 switch ((int) ELFNN_R_TYPE (rela->r_info))
6812 case AARCH64_R (RELATIVE):
6813 return reloc_class_relative;
6814 case AARCH64_R (JUMP_SLOT):
6815 return reloc_class_plt;
6816 case AARCH64_R (COPY):
6817 return reloc_class_copy;
6819 return reloc_class_normal;
6823 /* Handle an AArch64 specific section when reading an object file. This is
6824 called when bfd_section_from_shdr finds a section with an unknown
6828 elfNN_aarch64_section_from_shdr (bfd *abfd,
6829 Elf_Internal_Shdr *hdr,
6830 const char *name, int shindex)
6832 /* There ought to be a place to keep ELF backend specific flags, but
6833 at the moment there isn't one. We just keep track of the
6834 sections by their name, instead. Fortunately, the ABI gives
6835 names for all the AArch64 specific sections, so we will probably get
6837 switch (hdr->sh_type)
6839 case SHT_AARCH64_ATTRIBUTES:
6846 if (!_bfd_elf_make_section_from_shdr (abfd, hdr, name, shindex))
6852 /* A structure used to record a list of sections, independently
6853 of the next and prev fields in the asection structure. */
6854 typedef struct section_list
6857 struct section_list *next;
6858 struct section_list *prev;
6862 /* Unfortunately we need to keep a list of sections for which
6863 an _aarch64_elf_section_data structure has been allocated. This
6864 is because it is possible for functions like elfNN_aarch64_write_section
6865 to be called on a section which has had an elf_data_structure
6866 allocated for it (and so the used_by_bfd field is valid) but
6867 for which the AArch64 extended version of this structure - the
6868 _aarch64_elf_section_data structure - has not been allocated. */
6869 static section_list *sections_with_aarch64_elf_section_data = NULL;
6872 record_section_with_aarch64_elf_section_data (asection *sec)
6874 struct section_list *entry;
6876 entry = bfd_malloc (sizeof (*entry));
6880 entry->next = sections_with_aarch64_elf_section_data;
6882 if (entry->next != NULL)
6883 entry->next->prev = entry;
6884 sections_with_aarch64_elf_section_data = entry;
6887 static struct section_list *
6888 find_aarch64_elf_section_entry (asection *sec)
6890 struct section_list *entry;
6891 static struct section_list *last_entry = NULL;
6893 /* This is a short cut for the typical case where the sections are added
6894 to the sections_with_aarch64_elf_section_data list in forward order and
6895 then looked up here in backwards order. This makes a real difference
6896 to the ld-srec/sec64k.exp linker test. */
6897 entry = sections_with_aarch64_elf_section_data;
6898 if (last_entry != NULL)
6900 if (last_entry->sec == sec)
6902 else if (last_entry->next != NULL && last_entry->next->sec == sec)
6903 entry = last_entry->next;
6906 for (; entry; entry = entry->next)
6907 if (entry->sec == sec)
6911 /* Record the entry prior to this one - it is the entry we are
6912 most likely to want to locate next time. Also this way if we
6913 have been called from
6914 unrecord_section_with_aarch64_elf_section_data () we will not
6915 be caching a pointer that is about to be freed. */
6916 last_entry = entry->prev;
6922 unrecord_section_with_aarch64_elf_section_data (asection *sec)
6924 struct section_list *entry;
6926 entry = find_aarch64_elf_section_entry (sec);
6930 if (entry->prev != NULL)
6931 entry->prev->next = entry->next;
6932 if (entry->next != NULL)
6933 entry->next->prev = entry->prev;
6934 if (entry == sections_with_aarch64_elf_section_data)
6935 sections_with_aarch64_elf_section_data = entry->next;
6944 struct bfd_link_info *info;
6947 int (*func) (void *, const char *, Elf_Internal_Sym *,
6948 asection *, struct elf_link_hash_entry *);
6949 } output_arch_syminfo;
6951 enum map_symbol_type
6958 /* Output a single mapping symbol. */
6961 elfNN_aarch64_output_map_sym (output_arch_syminfo *osi,
6962 enum map_symbol_type type, bfd_vma offset)
6964 static const char *names[2] = { "$x", "$d" };
6965 Elf_Internal_Sym sym;
6967 sym.st_value = (osi->sec->output_section->vma
6968 + osi->sec->output_offset + offset);
6971 sym.st_info = ELF_ST_INFO (STB_LOCAL, STT_NOTYPE);
6972 sym.st_shndx = osi->sec_shndx;
6973 return osi->func (osi->finfo, names[type], &sym, osi->sec, NULL) == 1;
6978 /* Output mapping symbols for PLT entries associated with H. */
6981 elfNN_aarch64_output_plt_map (struct elf_link_hash_entry *h, void *inf)
6983 output_arch_syminfo *osi = (output_arch_syminfo *) inf;
6986 if (h->root.type == bfd_link_hash_indirect)
6989 if (h->root.type == bfd_link_hash_warning)
6990 /* When warning symbols are created, they **replace** the "real"
6991 entry in the hash table, thus we never get to see the real
6992 symbol in a hash traversal. So look at it now. */
6993 h = (struct elf_link_hash_entry *) h->root.u.i.link;
6995 if (h->plt.offset == (bfd_vma) - 1)
6998 addr = h->plt.offset;
7001 if (!elfNN_aarch64_output_map_sym (osi, AARCH64_MAP_INSN, addr))
7008 /* Output a single local symbol for a generated stub. */
7011 elfNN_aarch64_output_stub_sym (output_arch_syminfo *osi, const char *name,
7012 bfd_vma offset, bfd_vma size)
7014 Elf_Internal_Sym sym;
7016 sym.st_value = (osi->sec->output_section->vma
7017 + osi->sec->output_offset + offset);
7020 sym.st_info = ELF_ST_INFO (STB_LOCAL, STT_FUNC);
7021 sym.st_shndx = osi->sec_shndx;
7022 return osi->func (osi->finfo, name, &sym, osi->sec, NULL) == 1;
7026 aarch64_map_one_stub (struct bfd_hash_entry *gen_entry, void *in_arg)
7028 struct elf_aarch64_stub_hash_entry *stub_entry;
7032 output_arch_syminfo *osi;
7034 /* Massage our args to the form they really have. */
7035 stub_entry = (struct elf_aarch64_stub_hash_entry *) gen_entry;
7036 osi = (output_arch_syminfo *) in_arg;
7038 stub_sec = stub_entry->stub_sec;
7040 /* Ensure this stub is attached to the current section being
7042 if (stub_sec != osi->sec)
7045 addr = (bfd_vma) stub_entry->stub_offset;
7047 stub_name = stub_entry->output_name;
7049 switch (stub_entry->stub_type)
7051 case aarch64_stub_adrp_branch:
7052 if (!elfNN_aarch64_output_stub_sym (osi, stub_name, addr,
7053 sizeof (aarch64_adrp_branch_stub)))
7055 if (!elfNN_aarch64_output_map_sym (osi, AARCH64_MAP_INSN, addr))
7058 case aarch64_stub_long_branch:
7059 if (!elfNN_aarch64_output_stub_sym
7060 (osi, stub_name, addr, sizeof (aarch64_long_branch_stub)))
7062 if (!elfNN_aarch64_output_map_sym (osi, AARCH64_MAP_INSN, addr))
7064 if (!elfNN_aarch64_output_map_sym (osi, AARCH64_MAP_DATA, addr + 16))
7067 case aarch64_stub_erratum_835769_veneer:
7068 if (!elfNN_aarch64_output_stub_sym (osi, stub_name, addr,
7069 sizeof (aarch64_erratum_835769_stub)))
7071 if (!elfNN_aarch64_output_map_sym (osi, AARCH64_MAP_INSN, addr))
7074 case aarch64_stub_erratum_843419_veneer:
7075 if (!elfNN_aarch64_output_stub_sym (osi, stub_name, addr,
7076 sizeof (aarch64_erratum_843419_stub)))
7078 if (!elfNN_aarch64_output_map_sym (osi, AARCH64_MAP_INSN, addr))
7089 /* Output mapping symbols for linker generated sections. */
7092 elfNN_aarch64_output_arch_local_syms (bfd *output_bfd,
7093 struct bfd_link_info *info,
7095 int (*func) (void *, const char *,
7098 struct elf_link_hash_entry
7101 output_arch_syminfo osi;
7102 struct elf_aarch64_link_hash_table *htab;
7104 htab = elf_aarch64_hash_table (info);
7110 /* Long calls stubs. */
7111 if (htab->stub_bfd && htab->stub_bfd->sections)
7115 for (stub_sec = htab->stub_bfd->sections;
7116 stub_sec != NULL; stub_sec = stub_sec->next)
7118 /* Ignore non-stub sections. */
7119 if (!strstr (stub_sec->name, STUB_SUFFIX))
7124 osi.sec_shndx = _bfd_elf_section_from_bfd_section
7125 (output_bfd, osi.sec->output_section);
7127 /* The first instruction in a stub is always a branch. */
7128 if (!elfNN_aarch64_output_map_sym (&osi, AARCH64_MAP_INSN, 0))
7131 bfd_hash_traverse (&htab->stub_hash_table, aarch64_map_one_stub,
7136 /* Finally, output mapping symbols for the PLT. */
7137 if (!htab->root.splt || htab->root.splt->size == 0)
7140 /* For now live without mapping symbols for the plt. */
7141 osi.sec_shndx = _bfd_elf_section_from_bfd_section
7142 (output_bfd, htab->root.splt->output_section);
7143 osi.sec = htab->root.splt;
7145 elf_link_hash_traverse (&htab->root, elfNN_aarch64_output_plt_map,
7152 /* Allocate target specific section data. */
7155 elfNN_aarch64_new_section_hook (bfd *abfd, asection *sec)
7157 if (!sec->used_by_bfd)
7159 _aarch64_elf_section_data *sdata;
7160 bfd_size_type amt = sizeof (*sdata);
7162 sdata = bfd_zalloc (abfd, amt);
7165 sec->used_by_bfd = sdata;
7168 record_section_with_aarch64_elf_section_data (sec);
7170 return _bfd_elf_new_section_hook (abfd, sec);
7175 unrecord_section_via_map_over_sections (bfd *abfd ATTRIBUTE_UNUSED,
7177 void *ignore ATTRIBUTE_UNUSED)
7179 unrecord_section_with_aarch64_elf_section_data (sec);
7183 elfNN_aarch64_close_and_cleanup (bfd *abfd)
7186 bfd_map_over_sections (abfd,
7187 unrecord_section_via_map_over_sections, NULL);
7189 return _bfd_elf_close_and_cleanup (abfd);
7193 elfNN_aarch64_bfd_free_cached_info (bfd *abfd)
7196 bfd_map_over_sections (abfd,
7197 unrecord_section_via_map_over_sections, NULL);
7199 return _bfd_free_cached_info (abfd);
7202 /* Create dynamic sections. This is different from the ARM backend in that
7203 the got, plt, gotplt and their relocation sections are all created in the
7204 standard part of the bfd elf backend. */
7207 elfNN_aarch64_create_dynamic_sections (bfd *dynobj,
7208 struct bfd_link_info *info)
7210 struct elf_aarch64_link_hash_table *htab;
7212 /* We need to create .got section. */
7213 if (!aarch64_elf_create_got_section (dynobj, info))
7216 if (!_bfd_elf_create_dynamic_sections (dynobj, info))
7219 htab = elf_aarch64_hash_table (info);
7220 htab->sdynbss = bfd_get_linker_section (dynobj, ".dynbss");
7222 htab->srelbss = bfd_get_linker_section (dynobj, ".rela.bss");
7224 if (!htab->sdynbss || (!info->shared && !htab->srelbss))
7231 /* Allocate space in .plt, .got and associated reloc sections for
7235 elfNN_aarch64_allocate_dynrelocs (struct elf_link_hash_entry *h, void *inf)
7237 struct bfd_link_info *info;
7238 struct elf_aarch64_link_hash_table *htab;
7239 struct elf_aarch64_link_hash_entry *eh;
7240 struct elf_dyn_relocs *p;
7242 /* An example of a bfd_link_hash_indirect symbol is versioned
7243 symbol. For example: __gxx_personality_v0(bfd_link_hash_indirect)
7244 -> __gxx_personality_v0(bfd_link_hash_defined)
7246 There is no need to process bfd_link_hash_indirect symbols here
7247 because we will also be presented with the concrete instance of
7248 the symbol and elfNN_aarch64_copy_indirect_symbol () will have been
7249 called to copy all relevant data from the generic to the concrete
7252 if (h->root.type == bfd_link_hash_indirect)
7255 if (h->root.type == bfd_link_hash_warning)
7256 h = (struct elf_link_hash_entry *) h->root.u.i.link;
7258 info = (struct bfd_link_info *) inf;
7259 htab = elf_aarch64_hash_table (info);
7261 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle it
7262 here if it is defined and referenced in a non-shared object. */
7263 if (h->type == STT_GNU_IFUNC
7266 else if (htab->root.dynamic_sections_created && h->plt.refcount > 0)
7268 /* Make sure this symbol is output as a dynamic symbol.
7269 Undefined weak syms won't yet be marked as dynamic. */
7270 if (h->dynindx == -1 && !h->forced_local)
7272 if (!bfd_elf_link_record_dynamic_symbol (info, h))
7276 if (info->shared || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h))
7278 asection *s = htab->root.splt;
7280 /* If this is the first .plt entry, make room for the special
7283 s->size += htab->plt_header_size;
7285 h->plt.offset = s->size;
7287 /* If this symbol is not defined in a regular file, and we are
7288 not generating a shared library, then set the symbol to this
7289 location in the .plt. This is required to make function
7290 pointers compare as equal between the normal executable and
7291 the shared library. */
7292 if (!info->shared && !h->def_regular)
7294 h->root.u.def.section = s;
7295 h->root.u.def.value = h->plt.offset;
7298 /* Make room for this entry. For now we only create the
7299 small model PLT entries. We later need to find a way
7300 of relaxing into these from the large model PLT entries. */
7301 s->size += PLT_SMALL_ENTRY_SIZE;
7303 /* We also need to make an entry in the .got.plt section, which
7304 will be placed in the .got section by the linker script. */
7305 htab->root.sgotplt->size += GOT_ENTRY_SIZE;
7307 /* We also need to make an entry in the .rela.plt section. */
7308 htab->root.srelplt->size += RELOC_SIZE (htab);
7310 /* We need to ensure that all GOT entries that serve the PLT
7311 are consecutive with the special GOT slots [0] [1] and
7312 [2]. Any addtional relocations, such as
7313 R_AARCH64_TLSDESC, must be placed after the PLT related
7314 entries. We abuse the reloc_count such that during
7315 sizing we adjust reloc_count to indicate the number of
7316 PLT related reserved entries. In subsequent phases when
7317 filling in the contents of the reloc entries, PLT related
7318 entries are placed by computing their PLT index (0
7319 .. reloc_count). While other none PLT relocs are placed
7320 at the slot indicated by reloc_count and reloc_count is
7323 htab->root.srelplt->reloc_count++;
7327 h->plt.offset = (bfd_vma) - 1;
7333 h->plt.offset = (bfd_vma) - 1;
7337 eh = (struct elf_aarch64_link_hash_entry *) h;
7338 eh->tlsdesc_got_jump_table_offset = (bfd_vma) - 1;
7340 if (h->got.refcount > 0)
7343 unsigned got_type = elf_aarch64_hash_entry (h)->got_type;
7345 h->got.offset = (bfd_vma) - 1;
7347 dyn = htab->root.dynamic_sections_created;
7349 /* Make sure this symbol is output as a dynamic symbol.
7350 Undefined weak syms won't yet be marked as dynamic. */
7351 if (dyn && h->dynindx == -1 && !h->forced_local)
7353 if (!bfd_elf_link_record_dynamic_symbol (info, h))
7357 if (got_type == GOT_UNKNOWN)
7360 else if (got_type == GOT_NORMAL)
7362 h->got.offset = htab->root.sgot->size;
7363 htab->root.sgot->size += GOT_ENTRY_SIZE;
7364 if ((ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
7365 || h->root.type != bfd_link_hash_undefweak)
7367 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, 0, h)))
7369 htab->root.srelgot->size += RELOC_SIZE (htab);
7375 if (got_type & GOT_TLSDESC_GD)
7377 eh->tlsdesc_got_jump_table_offset =
7378 (htab->root.sgotplt->size
7379 - aarch64_compute_jump_table_size (htab));
7380 htab->root.sgotplt->size += GOT_ENTRY_SIZE * 2;
7381 h->got.offset = (bfd_vma) - 2;
7384 if (got_type & GOT_TLS_GD)
7386 h->got.offset = htab->root.sgot->size;
7387 htab->root.sgot->size += GOT_ENTRY_SIZE * 2;
7390 if (got_type & GOT_TLS_IE)
7392 h->got.offset = htab->root.sgot->size;
7393 htab->root.sgot->size += GOT_ENTRY_SIZE;
7396 indx = h && h->dynindx != -1 ? h->dynindx : 0;
7397 if ((ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
7398 || h->root.type != bfd_link_hash_undefweak)
7401 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, 0, h)))
7403 if (got_type & GOT_TLSDESC_GD)
7405 htab->root.srelplt->size += RELOC_SIZE (htab);
7406 /* Note reloc_count not incremented here! We have
7407 already adjusted reloc_count for this relocation
7410 /* TLSDESC PLT is now needed, but not yet determined. */
7411 htab->tlsdesc_plt = (bfd_vma) - 1;
7414 if (got_type & GOT_TLS_GD)
7415 htab->root.srelgot->size += RELOC_SIZE (htab) * 2;
7417 if (got_type & GOT_TLS_IE)
7418 htab->root.srelgot->size += RELOC_SIZE (htab);
7424 h->got.offset = (bfd_vma) - 1;
7427 if (eh->dyn_relocs == NULL)
7430 /* In the shared -Bsymbolic case, discard space allocated for
7431 dynamic pc-relative relocs against symbols which turn out to be
7432 defined in regular objects. For the normal shared case, discard
7433 space for pc-relative relocs that have become local due to symbol
7434 visibility changes. */
7438 /* Relocs that use pc_count are those that appear on a call
7439 insn, or certain REL relocs that can generated via assembly.
7440 We want calls to protected symbols to resolve directly to the
7441 function rather than going via the plt. If people want
7442 function pointer comparisons to work as expected then they
7443 should avoid writing weird assembly. */
7444 if (SYMBOL_CALLS_LOCAL (info, h))
7446 struct elf_dyn_relocs **pp;
7448 for (pp = &eh->dyn_relocs; (p = *pp) != NULL;)
7450 p->count -= p->pc_count;
7459 /* Also discard relocs on undefined weak syms with non-default
7461 if (eh->dyn_relocs != NULL && h->root.type == bfd_link_hash_undefweak)
7463 if (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT)
7464 eh->dyn_relocs = NULL;
7466 /* Make sure undefined weak symbols are output as a dynamic
7468 else if (h->dynindx == -1
7470 && !bfd_elf_link_record_dynamic_symbol (info, h))
7475 else if (ELIMINATE_COPY_RELOCS)
7477 /* For the non-shared case, discard space for relocs against
7478 symbols which turn out to need copy relocs or are not
7484 || (htab->root.dynamic_sections_created
7485 && (h->root.type == bfd_link_hash_undefweak
7486 || h->root.type == bfd_link_hash_undefined))))
7488 /* Make sure this symbol is output as a dynamic symbol.
7489 Undefined weak syms won't yet be marked as dynamic. */
7490 if (h->dynindx == -1
7492 && !bfd_elf_link_record_dynamic_symbol (info, h))
7495 /* If that succeeded, we know we'll be keeping all the
7497 if (h->dynindx != -1)
7501 eh->dyn_relocs = NULL;
7506 /* Finally, allocate space. */
7507 for (p = eh->dyn_relocs; p != NULL; p = p->next)
7511 sreloc = elf_section_data (p->sec)->sreloc;
7513 BFD_ASSERT (sreloc != NULL);
7515 sreloc->size += p->count * RELOC_SIZE (htab);
7521 /* Allocate space in .plt, .got and associated reloc sections for
7522 ifunc dynamic relocs. */
7525 elfNN_aarch64_allocate_ifunc_dynrelocs (struct elf_link_hash_entry *h,
7528 struct bfd_link_info *info;
7529 struct elf_aarch64_link_hash_table *htab;
7530 struct elf_aarch64_link_hash_entry *eh;
7532 /* An example of a bfd_link_hash_indirect symbol is versioned
7533 symbol. For example: __gxx_personality_v0(bfd_link_hash_indirect)
7534 -> __gxx_personality_v0(bfd_link_hash_defined)
7536 There is no need to process bfd_link_hash_indirect symbols here
7537 because we will also be presented with the concrete instance of
7538 the symbol and elfNN_aarch64_copy_indirect_symbol () will have been
7539 called to copy all relevant data from the generic to the concrete
7542 if (h->root.type == bfd_link_hash_indirect)
7545 if (h->root.type == bfd_link_hash_warning)
7546 h = (struct elf_link_hash_entry *) h->root.u.i.link;
7548 info = (struct bfd_link_info *) inf;
7549 htab = elf_aarch64_hash_table (info);
7551 eh = (struct elf_aarch64_link_hash_entry *) h;
7553 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle it
7554 here if it is defined and referenced in a non-shared object. */
7555 if (h->type == STT_GNU_IFUNC
7557 return _bfd_elf_allocate_ifunc_dyn_relocs (info, h,
7559 htab->plt_entry_size,
7560 htab->plt_header_size,
7565 /* Allocate space in .plt, .got and associated reloc sections for
7566 local dynamic relocs. */
7569 elfNN_aarch64_allocate_local_dynrelocs (void **slot, void *inf)
7571 struct elf_link_hash_entry *h
7572 = (struct elf_link_hash_entry *) *slot;
7574 if (h->type != STT_GNU_IFUNC
7578 || h->root.type != bfd_link_hash_defined)
7581 return elfNN_aarch64_allocate_dynrelocs (h, inf);
7584 /* Allocate space in .plt, .got and associated reloc sections for
7585 local ifunc dynamic relocs. */
7588 elfNN_aarch64_allocate_local_ifunc_dynrelocs (void **slot, void *inf)
7590 struct elf_link_hash_entry *h
7591 = (struct elf_link_hash_entry *) *slot;
7593 if (h->type != STT_GNU_IFUNC
7597 || h->root.type != bfd_link_hash_defined)
7600 return elfNN_aarch64_allocate_ifunc_dynrelocs (h, inf);
7603 /* Find any dynamic relocs that apply to read-only sections. */
7606 aarch64_readonly_dynrelocs (struct elf_link_hash_entry * h, void * inf)
7608 struct elf_aarch64_link_hash_entry * eh;
7609 struct elf_dyn_relocs * p;
7611 eh = (struct elf_aarch64_link_hash_entry *) h;
7612 for (p = eh->dyn_relocs; p != NULL; p = p->next)
7614 asection *s = p->sec;
7616 if (s != NULL && (s->flags & SEC_READONLY) != 0)
7618 struct bfd_link_info *info = (struct bfd_link_info *) inf;
7620 info->flags |= DF_TEXTREL;
7622 /* Not an error, just cut short the traversal. */
7629 /* This is the most important function of all . Innocuosly named
7632 elfNN_aarch64_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
7633 struct bfd_link_info *info)
7635 struct elf_aarch64_link_hash_table *htab;
7641 htab = elf_aarch64_hash_table ((info));
7642 dynobj = htab->root.dynobj;
7644 BFD_ASSERT (dynobj != NULL);
7646 if (htab->root.dynamic_sections_created)
7648 if (info->executable)
7650 s = bfd_get_linker_section (dynobj, ".interp");
7653 s->size = sizeof ELF_DYNAMIC_INTERPRETER;
7654 s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
7658 /* Set up .got offsets for local syms, and space for local dynamic
7660 for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link.next)
7662 struct elf_aarch64_local_symbol *locals = NULL;
7663 Elf_Internal_Shdr *symtab_hdr;
7667 if (!is_aarch64_elf (ibfd))
7670 for (s = ibfd->sections; s != NULL; s = s->next)
7672 struct elf_dyn_relocs *p;
7674 for (p = (struct elf_dyn_relocs *)
7675 (elf_section_data (s)->local_dynrel); p != NULL; p = p->next)
7677 if (!bfd_is_abs_section (p->sec)
7678 && bfd_is_abs_section (p->sec->output_section))
7680 /* Input section has been discarded, either because
7681 it is a copy of a linkonce section or due to
7682 linker script /DISCARD/, so we'll be discarding
7685 else if (p->count != 0)
7687 srel = elf_section_data (p->sec)->sreloc;
7688 srel->size += p->count * RELOC_SIZE (htab);
7689 if ((p->sec->output_section->flags & SEC_READONLY) != 0)
7690 info->flags |= DF_TEXTREL;
7695 locals = elf_aarch64_locals (ibfd);
7699 symtab_hdr = &elf_symtab_hdr (ibfd);
7700 srel = htab->root.srelgot;
7701 for (i = 0; i < symtab_hdr->sh_info; i++)
7703 locals[i].got_offset = (bfd_vma) - 1;
7704 locals[i].tlsdesc_got_jump_table_offset = (bfd_vma) - 1;
7705 if (locals[i].got_refcount > 0)
7707 unsigned got_type = locals[i].got_type;
7708 if (got_type & GOT_TLSDESC_GD)
7710 locals[i].tlsdesc_got_jump_table_offset =
7711 (htab->root.sgotplt->size
7712 - aarch64_compute_jump_table_size (htab));
7713 htab->root.sgotplt->size += GOT_ENTRY_SIZE * 2;
7714 locals[i].got_offset = (bfd_vma) - 2;
7717 if (got_type & GOT_TLS_GD)
7719 locals[i].got_offset = htab->root.sgot->size;
7720 htab->root.sgot->size += GOT_ENTRY_SIZE * 2;
7723 if (got_type & GOT_TLS_IE
7724 || got_type & GOT_NORMAL)
7726 locals[i].got_offset = htab->root.sgot->size;
7727 htab->root.sgot->size += GOT_ENTRY_SIZE;
7730 if (got_type == GOT_UNKNOWN)
7736 if (got_type & GOT_TLSDESC_GD)
7738 htab->root.srelplt->size += RELOC_SIZE (htab);
7739 /* Note RELOC_COUNT not incremented here! */
7740 htab->tlsdesc_plt = (bfd_vma) - 1;
7743 if (got_type & GOT_TLS_GD)
7744 htab->root.srelgot->size += RELOC_SIZE (htab) * 2;
7746 if (got_type & GOT_TLS_IE
7747 || got_type & GOT_NORMAL)
7748 htab->root.srelgot->size += RELOC_SIZE (htab);
7753 locals[i].got_refcount = (bfd_vma) - 1;
7759 /* Allocate global sym .plt and .got entries, and space for global
7760 sym dynamic relocs. */
7761 elf_link_hash_traverse (&htab->root, elfNN_aarch64_allocate_dynrelocs,
7764 /* Allocate global ifunc sym .plt and .got entries, and space for global
7765 ifunc sym dynamic relocs. */
7766 elf_link_hash_traverse (&htab->root, elfNN_aarch64_allocate_ifunc_dynrelocs,
7769 /* Allocate .plt and .got entries, and space for local symbols. */
7770 htab_traverse (htab->loc_hash_table,
7771 elfNN_aarch64_allocate_local_dynrelocs,
7774 /* Allocate .plt and .got entries, and space for local ifunc symbols. */
7775 htab_traverse (htab->loc_hash_table,
7776 elfNN_aarch64_allocate_local_ifunc_dynrelocs,
7779 /* For every jump slot reserved in the sgotplt, reloc_count is
7780 incremented. However, when we reserve space for TLS descriptors,
7781 it's not incremented, so in order to compute the space reserved
7782 for them, it suffices to multiply the reloc count by the jump
7785 if (htab->root.srelplt)
7786 htab->sgotplt_jump_table_size = aarch64_compute_jump_table_size (htab);
7788 if (htab->tlsdesc_plt)
7790 if (htab->root.splt->size == 0)
7791 htab->root.splt->size += PLT_ENTRY_SIZE;
7793 htab->tlsdesc_plt = htab->root.splt->size;
7794 htab->root.splt->size += PLT_TLSDESC_ENTRY_SIZE;
7796 /* If we're not using lazy TLS relocations, don't generate the
7797 GOT entry required. */
7798 if (!(info->flags & DF_BIND_NOW))
7800 htab->dt_tlsdesc_got = htab->root.sgot->size;
7801 htab->root.sgot->size += GOT_ENTRY_SIZE;
7805 /* Init mapping symbols information to use later to distingush between
7806 code and data while scanning for errata. */
7807 if (htab->fix_erratum_835769 || htab->fix_erratum_843419)
7808 for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link.next)
7810 if (!is_aarch64_elf (ibfd))
7812 bfd_elfNN_aarch64_init_maps (ibfd);
7815 /* We now have determined the sizes of the various dynamic sections.
7816 Allocate memory for them. */
7818 for (s = dynobj->sections; s != NULL; s = s->next)
7820 if ((s->flags & SEC_LINKER_CREATED) == 0)
7823 if (s == htab->root.splt
7824 || s == htab->root.sgot
7825 || s == htab->root.sgotplt
7826 || s == htab->root.iplt
7827 || s == htab->root.igotplt || s == htab->sdynbss)
7829 /* Strip this section if we don't need it; see the
7832 else if (CONST_STRNEQ (bfd_get_section_name (dynobj, s), ".rela"))
7834 if (s->size != 0 && s != htab->root.srelplt)
7837 /* We use the reloc_count field as a counter if we need
7838 to copy relocs into the output file. */
7839 if (s != htab->root.srelplt)
7844 /* It's not one of our sections, so don't allocate space. */
7850 /* If we don't need this section, strip it from the
7851 output file. This is mostly to handle .rela.bss and
7852 .rela.plt. We must create both sections in
7853 create_dynamic_sections, because they must be created
7854 before the linker maps input sections to output
7855 sections. The linker does that before
7856 adjust_dynamic_symbol is called, and it is that
7857 function which decides whether anything needs to go
7858 into these sections. */
7860 s->flags |= SEC_EXCLUDE;
7864 if ((s->flags & SEC_HAS_CONTENTS) == 0)
7867 /* Allocate memory for the section contents. We use bfd_zalloc
7868 here in case unused entries are not reclaimed before the
7869 section's contents are written out. This should not happen,
7870 but this way if it does, we get a R_AARCH64_NONE reloc instead
7872 s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->size);
7873 if (s->contents == NULL)
7877 if (htab->root.dynamic_sections_created)
7879 /* Add some entries to the .dynamic section. We fill in the
7880 values later, in elfNN_aarch64_finish_dynamic_sections, but we
7881 must add the entries now so that we get the correct size for
7882 the .dynamic section. The DT_DEBUG entry is filled in by the
7883 dynamic linker and used by the debugger. */
7884 #define add_dynamic_entry(TAG, VAL) \
7885 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
7887 if (info->executable)
7889 if (!add_dynamic_entry (DT_DEBUG, 0))
7893 if (htab->root.splt->size != 0)
7895 if (!add_dynamic_entry (DT_PLTGOT, 0)
7896 || !add_dynamic_entry (DT_PLTRELSZ, 0)
7897 || !add_dynamic_entry (DT_PLTREL, DT_RELA)
7898 || !add_dynamic_entry (DT_JMPREL, 0))
7901 if (htab->tlsdesc_plt
7902 && (!add_dynamic_entry (DT_TLSDESC_PLT, 0)
7903 || !add_dynamic_entry (DT_TLSDESC_GOT, 0)))
7909 if (!add_dynamic_entry (DT_RELA, 0)
7910 || !add_dynamic_entry (DT_RELASZ, 0)
7911 || !add_dynamic_entry (DT_RELAENT, RELOC_SIZE (htab)))
7914 /* If any dynamic relocs apply to a read-only section,
7915 then we need a DT_TEXTREL entry. */
7916 if ((info->flags & DF_TEXTREL) == 0)
7917 elf_link_hash_traverse (& htab->root, aarch64_readonly_dynrelocs,
7920 if ((info->flags & DF_TEXTREL) != 0)
7922 if (!add_dynamic_entry (DT_TEXTREL, 0))
7927 #undef add_dynamic_entry
7933 elf_aarch64_update_plt_entry (bfd *output_bfd,
7934 bfd_reloc_code_real_type r_type,
7935 bfd_byte *plt_entry, bfd_vma value)
7937 reloc_howto_type *howto = elfNN_aarch64_howto_from_bfd_reloc (r_type);
7939 _bfd_aarch64_elf_put_addend (output_bfd, plt_entry, r_type, howto, value);
7943 elfNN_aarch64_create_small_pltn_entry (struct elf_link_hash_entry *h,
7944 struct elf_aarch64_link_hash_table
7945 *htab, bfd *output_bfd,
7946 struct bfd_link_info *info)
7948 bfd_byte *plt_entry;
7951 bfd_vma gotplt_entry_address;
7952 bfd_vma plt_entry_address;
7953 Elf_Internal_Rela rela;
7955 asection *plt, *gotplt, *relplt;
7957 /* When building a static executable, use .iplt, .igot.plt and
7958 .rela.iplt sections for STT_GNU_IFUNC symbols. */
7959 if (htab->root.splt != NULL)
7961 plt = htab->root.splt;
7962 gotplt = htab->root.sgotplt;
7963 relplt = htab->root.srelplt;
7967 plt = htab->root.iplt;
7968 gotplt = htab->root.igotplt;
7969 relplt = htab->root.irelplt;
7972 /* Get the index in the procedure linkage table which
7973 corresponds to this symbol. This is the index of this symbol
7974 in all the symbols for which we are making plt entries. The
7975 first entry in the procedure linkage table is reserved.
7977 Get the offset into the .got table of the entry that
7978 corresponds to this function. Each .got entry is GOT_ENTRY_SIZE
7979 bytes. The first three are reserved for the dynamic linker.
7981 For static executables, we don't reserve anything. */
7983 if (plt == htab->root.splt)
7985 plt_index = (h->plt.offset - htab->plt_header_size) / htab->plt_entry_size;
7986 got_offset = (plt_index + 3) * GOT_ENTRY_SIZE;
7990 plt_index = h->plt.offset / htab->plt_entry_size;
7991 got_offset = plt_index * GOT_ENTRY_SIZE;
7994 plt_entry = plt->contents + h->plt.offset;
7995 plt_entry_address = plt->output_section->vma
7996 + plt->output_offset + h->plt.offset;
7997 gotplt_entry_address = gotplt->output_section->vma +
7998 gotplt->output_offset + got_offset;
8000 /* Copy in the boiler-plate for the PLTn entry. */
8001 memcpy (plt_entry, elfNN_aarch64_small_plt_entry, PLT_SMALL_ENTRY_SIZE);
8003 /* Fill in the top 21 bits for this: ADRP x16, PLT_GOT + n * 8.
8004 ADRP: ((PG(S+A)-PG(P)) >> 12) & 0x1fffff */
8005 elf_aarch64_update_plt_entry (output_bfd, BFD_RELOC_AARCH64_ADR_HI21_PCREL,
8007 PG (gotplt_entry_address) -
8008 PG (plt_entry_address));
8010 /* Fill in the lo12 bits for the load from the pltgot. */
8011 elf_aarch64_update_plt_entry (output_bfd, BFD_RELOC_AARCH64_LDSTNN_LO12,
8013 PG_OFFSET (gotplt_entry_address));
8015 /* Fill in the lo12 bits for the add from the pltgot entry. */
8016 elf_aarch64_update_plt_entry (output_bfd, BFD_RELOC_AARCH64_ADD_LO12,
8018 PG_OFFSET (gotplt_entry_address));
8020 /* All the GOTPLT Entries are essentially initialized to PLT0. */
8021 bfd_put_NN (output_bfd,
8022 plt->output_section->vma + plt->output_offset,
8023 gotplt->contents + got_offset);
8025 rela.r_offset = gotplt_entry_address;
8027 if (h->dynindx == -1
8028 || ((info->executable
8029 || ELF_ST_VISIBILITY (h->other) != STV_DEFAULT)
8031 && h->type == STT_GNU_IFUNC))
8033 /* If an STT_GNU_IFUNC symbol is locally defined, generate
8034 R_AARCH64_IRELATIVE instead of R_AARCH64_JUMP_SLOT. */
8035 rela.r_info = ELFNN_R_INFO (0, AARCH64_R (IRELATIVE));
8036 rela.r_addend = (h->root.u.def.value
8037 + h->root.u.def.section->output_section->vma
8038 + h->root.u.def.section->output_offset);
8042 /* Fill in the entry in the .rela.plt section. */
8043 rela.r_info = ELFNN_R_INFO (h->dynindx, AARCH64_R (JUMP_SLOT));
8047 /* Compute the relocation entry to used based on PLT index and do
8048 not adjust reloc_count. The reloc_count has already been adjusted
8049 to account for this entry. */
8050 loc = relplt->contents + plt_index * RELOC_SIZE (htab);
8051 bfd_elfNN_swap_reloca_out (output_bfd, &rela, loc);
8054 /* Size sections even though they're not dynamic. We use it to setup
8055 _TLS_MODULE_BASE_, if needed. */
8058 elfNN_aarch64_always_size_sections (bfd *output_bfd,
8059 struct bfd_link_info *info)
8063 if (info->relocatable)
8066 tls_sec = elf_hash_table (info)->tls_sec;
8070 struct elf_link_hash_entry *tlsbase;
8072 tlsbase = elf_link_hash_lookup (elf_hash_table (info),
8073 "_TLS_MODULE_BASE_", TRUE, TRUE, FALSE);
8077 struct bfd_link_hash_entry *h = NULL;
8078 const struct elf_backend_data *bed =
8079 get_elf_backend_data (output_bfd);
8081 if (!(_bfd_generic_link_add_one_symbol
8082 (info, output_bfd, "_TLS_MODULE_BASE_", BSF_LOCAL,
8083 tls_sec, 0, NULL, FALSE, bed->collect, &h)))
8086 tlsbase->type = STT_TLS;
8087 tlsbase = (struct elf_link_hash_entry *) h;
8088 tlsbase->def_regular = 1;
8089 tlsbase->other = STV_HIDDEN;
8090 (*bed->elf_backend_hide_symbol) (info, tlsbase, TRUE);
8097 /* Finish up dynamic symbol handling. We set the contents of various
8098 dynamic sections here. */
8100 elfNN_aarch64_finish_dynamic_symbol (bfd *output_bfd,
8101 struct bfd_link_info *info,
8102 struct elf_link_hash_entry *h,
8103 Elf_Internal_Sym *sym)
8105 struct elf_aarch64_link_hash_table *htab;
8106 htab = elf_aarch64_hash_table (info);
8108 if (h->plt.offset != (bfd_vma) - 1)
8110 asection *plt, *gotplt, *relplt;
8112 /* This symbol has an entry in the procedure linkage table. Set
8115 /* When building a static executable, use .iplt, .igot.plt and
8116 .rela.iplt sections for STT_GNU_IFUNC symbols. */
8117 if (htab->root.splt != NULL)
8119 plt = htab->root.splt;
8120 gotplt = htab->root.sgotplt;
8121 relplt = htab->root.srelplt;
8125 plt = htab->root.iplt;
8126 gotplt = htab->root.igotplt;
8127 relplt = htab->root.irelplt;
8130 /* This symbol has an entry in the procedure linkage table. Set
8132 if ((h->dynindx == -1
8133 && !((h->forced_local || info->executable)
8135 && h->type == STT_GNU_IFUNC))
8141 elfNN_aarch64_create_small_pltn_entry (h, htab, output_bfd, info);
8142 if (!h->def_regular)
8144 /* Mark the symbol as undefined, rather than as defined in
8145 the .plt section. */
8146 sym->st_shndx = SHN_UNDEF;
8147 /* If the symbol is weak we need to clear the value.
8148 Otherwise, the PLT entry would provide a definition for
8149 the symbol even if the symbol wasn't defined anywhere,
8150 and so the symbol would never be NULL. Leave the value if
8151 there were any relocations where pointer equality matters
8152 (this is a clue for the dynamic linker, to make function
8153 pointer comparisons work between an application and shared
8155 if (!h->ref_regular_nonweak || !h->pointer_equality_needed)
8160 if (h->got.offset != (bfd_vma) - 1
8161 && elf_aarch64_hash_entry (h)->got_type == GOT_NORMAL)
8163 Elf_Internal_Rela rela;
8166 /* This symbol has an entry in the global offset table. Set it
8168 if (htab->root.sgot == NULL || htab->root.srelgot == NULL)
8171 rela.r_offset = (htab->root.sgot->output_section->vma
8172 + htab->root.sgot->output_offset
8173 + (h->got.offset & ~(bfd_vma) 1));
8176 && h->type == STT_GNU_IFUNC)
8180 /* Generate R_AARCH64_GLOB_DAT. */
8187 if (!h->pointer_equality_needed)
8190 /* For non-shared object, we can't use .got.plt, which
8191 contains the real function address if we need pointer
8192 equality. We load the GOT entry with the PLT entry. */
8193 plt = htab->root.splt ? htab->root.splt : htab->root.iplt;
8194 bfd_put_NN (output_bfd, (plt->output_section->vma
8195 + plt->output_offset
8197 htab->root.sgot->contents
8198 + (h->got.offset & ~(bfd_vma) 1));
8202 else if (info->shared && SYMBOL_REFERENCES_LOCAL (info, h))
8204 if (!h->def_regular)
8207 BFD_ASSERT ((h->got.offset & 1) != 0);
8208 rela.r_info = ELFNN_R_INFO (0, AARCH64_R (RELATIVE));
8209 rela.r_addend = (h->root.u.def.value
8210 + h->root.u.def.section->output_section->vma
8211 + h->root.u.def.section->output_offset);
8216 BFD_ASSERT ((h->got.offset & 1) == 0);
8217 bfd_put_NN (output_bfd, (bfd_vma) 0,
8218 htab->root.sgot->contents + h->got.offset);
8219 rela.r_info = ELFNN_R_INFO (h->dynindx, AARCH64_R (GLOB_DAT));
8223 loc = htab->root.srelgot->contents;
8224 loc += htab->root.srelgot->reloc_count++ * RELOC_SIZE (htab);
8225 bfd_elfNN_swap_reloca_out (output_bfd, &rela, loc);
8230 Elf_Internal_Rela rela;
8233 /* This symbol needs a copy reloc. Set it up. */
8235 if (h->dynindx == -1
8236 || (h->root.type != bfd_link_hash_defined
8237 && h->root.type != bfd_link_hash_defweak)
8238 || htab->srelbss == NULL)
8241 rela.r_offset = (h->root.u.def.value
8242 + h->root.u.def.section->output_section->vma
8243 + h->root.u.def.section->output_offset);
8244 rela.r_info = ELFNN_R_INFO (h->dynindx, AARCH64_R (COPY));
8246 loc = htab->srelbss->contents;
8247 loc += htab->srelbss->reloc_count++ * RELOC_SIZE (htab);
8248 bfd_elfNN_swap_reloca_out (output_bfd, &rela, loc);
8251 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. SYM may
8252 be NULL for local symbols. */
8254 && (h == elf_hash_table (info)->hdynamic
8255 || h == elf_hash_table (info)->hgot))
8256 sym->st_shndx = SHN_ABS;
8261 /* Finish up local dynamic symbol handling. We set the contents of
8262 various dynamic sections here. */
8265 elfNN_aarch64_finish_local_dynamic_symbol (void **slot, void *inf)
8267 struct elf_link_hash_entry *h
8268 = (struct elf_link_hash_entry *) *slot;
8269 struct bfd_link_info *info
8270 = (struct bfd_link_info *) inf;
8272 return elfNN_aarch64_finish_dynamic_symbol (info->output_bfd,
8277 elfNN_aarch64_init_small_plt0_entry (bfd *output_bfd ATTRIBUTE_UNUSED,
8278 struct elf_aarch64_link_hash_table
8281 /* Fill in PLT0. Fixme:RR Note this doesn't distinguish between
8282 small and large plts and at the minute just generates
8285 /* PLT0 of the small PLT looks like this in ELF64 -
8286 stp x16, x30, [sp, #-16]! // Save the reloc and lr on stack.
8287 adrp x16, PLT_GOT + 16 // Get the page base of the GOTPLT
8288 ldr x17, [x16, #:lo12:PLT_GOT+16] // Load the address of the
8290 add x16, x16, #:lo12:PLT_GOT+16 // Load the lo12 bits of the
8291 // GOTPLT entry for this.
8293 PLT0 will be slightly different in ELF32 due to different got entry
8296 bfd_vma plt_got_2nd_ent; /* Address of GOT[2]. */
8300 memcpy (htab->root.splt->contents, elfNN_aarch64_small_plt0_entry,
8302 elf_section_data (htab->root.splt->output_section)->this_hdr.sh_entsize =
8305 plt_got_2nd_ent = (htab->root.sgotplt->output_section->vma
8306 + htab->root.sgotplt->output_offset
8307 + GOT_ENTRY_SIZE * 2);
8309 plt_base = htab->root.splt->output_section->vma +
8310 htab->root.splt->output_offset;
8312 /* Fill in the top 21 bits for this: ADRP x16, PLT_GOT + n * 8.
8313 ADRP: ((PG(S+A)-PG(P)) >> 12) & 0x1fffff */
8314 elf_aarch64_update_plt_entry (output_bfd, BFD_RELOC_AARCH64_ADR_HI21_PCREL,
8315 htab->root.splt->contents + 4,
8316 PG (plt_got_2nd_ent) - PG (plt_base + 4));
8318 elf_aarch64_update_plt_entry (output_bfd, BFD_RELOC_AARCH64_LDSTNN_LO12,
8319 htab->root.splt->contents + 8,
8320 PG_OFFSET (plt_got_2nd_ent));
8322 elf_aarch64_update_plt_entry (output_bfd, BFD_RELOC_AARCH64_ADD_LO12,
8323 htab->root.splt->contents + 12,
8324 PG_OFFSET (plt_got_2nd_ent));
8328 elfNN_aarch64_finish_dynamic_sections (bfd *output_bfd,
8329 struct bfd_link_info *info)
8331 struct elf_aarch64_link_hash_table *htab;
8335 htab = elf_aarch64_hash_table (info);
8336 dynobj = htab->root.dynobj;
8337 sdyn = bfd_get_linker_section (dynobj, ".dynamic");
8339 if (htab->root.dynamic_sections_created)
8341 ElfNN_External_Dyn *dyncon, *dynconend;
8343 if (sdyn == NULL || htab->root.sgot == NULL)
8346 dyncon = (ElfNN_External_Dyn *) sdyn->contents;
8347 dynconend = (ElfNN_External_Dyn *) (sdyn->contents + sdyn->size);
8348 for (; dyncon < dynconend; dyncon++)
8350 Elf_Internal_Dyn dyn;
8353 bfd_elfNN_swap_dyn_in (dynobj, dyncon, &dyn);
8361 s = htab->root.sgotplt;
8362 dyn.d_un.d_ptr = s->output_section->vma + s->output_offset;
8366 dyn.d_un.d_ptr = htab->root.srelplt->output_section->vma;
8370 s = htab->root.srelplt;
8371 dyn.d_un.d_val = s->size;
8375 /* The procedure linkage table relocs (DT_JMPREL) should
8376 not be included in the overall relocs (DT_RELA).
8377 Therefore, we override the DT_RELASZ entry here to
8378 make it not include the JMPREL relocs. Since the
8379 linker script arranges for .rela.plt to follow all
8380 other relocation sections, we don't have to worry
8381 about changing the DT_RELA entry. */
8382 if (htab->root.srelplt != NULL)
8384 s = htab->root.srelplt;
8385 dyn.d_un.d_val -= s->size;
8389 case DT_TLSDESC_PLT:
8390 s = htab->root.splt;
8391 dyn.d_un.d_ptr = s->output_section->vma + s->output_offset
8392 + htab->tlsdesc_plt;
8395 case DT_TLSDESC_GOT:
8396 s = htab->root.sgot;
8397 dyn.d_un.d_ptr = s->output_section->vma + s->output_offset
8398 + htab->dt_tlsdesc_got;
8402 bfd_elfNN_swap_dyn_out (output_bfd, &dyn, dyncon);
8407 /* Fill in the special first entry in the procedure linkage table. */
8408 if (htab->root.splt && htab->root.splt->size > 0)
8410 elfNN_aarch64_init_small_plt0_entry (output_bfd, htab);
8412 elf_section_data (htab->root.splt->output_section)->
8413 this_hdr.sh_entsize = htab->plt_entry_size;
8416 if (htab->tlsdesc_plt)
8418 bfd_put_NN (output_bfd, (bfd_vma) 0,
8419 htab->root.sgot->contents + htab->dt_tlsdesc_got);
8421 memcpy (htab->root.splt->contents + htab->tlsdesc_plt,
8422 elfNN_aarch64_tlsdesc_small_plt_entry,
8423 sizeof (elfNN_aarch64_tlsdesc_small_plt_entry));
8426 bfd_vma adrp1_addr =
8427 htab->root.splt->output_section->vma
8428 + htab->root.splt->output_offset + htab->tlsdesc_plt + 4;
8430 bfd_vma adrp2_addr = adrp1_addr + 4;
8433 htab->root.sgot->output_section->vma
8434 + htab->root.sgot->output_offset;
8436 bfd_vma pltgot_addr =
8437 htab->root.sgotplt->output_section->vma
8438 + htab->root.sgotplt->output_offset;
8440 bfd_vma dt_tlsdesc_got = got_addr + htab->dt_tlsdesc_got;
8442 bfd_byte *plt_entry =
8443 htab->root.splt->contents + htab->tlsdesc_plt;
8445 /* adrp x2, DT_TLSDESC_GOT */
8446 elf_aarch64_update_plt_entry (output_bfd,
8447 BFD_RELOC_AARCH64_ADR_HI21_PCREL,
8449 (PG (dt_tlsdesc_got)
8450 - PG (adrp1_addr)));
8453 elf_aarch64_update_plt_entry (output_bfd,
8454 BFD_RELOC_AARCH64_ADR_HI21_PCREL,
8457 - PG (adrp2_addr)));
8459 /* ldr x2, [x2, #0] */
8460 elf_aarch64_update_plt_entry (output_bfd,
8461 BFD_RELOC_AARCH64_LDSTNN_LO12,
8463 PG_OFFSET (dt_tlsdesc_got));
8466 elf_aarch64_update_plt_entry (output_bfd,
8467 BFD_RELOC_AARCH64_ADD_LO12,
8469 PG_OFFSET (pltgot_addr));
8474 if (htab->root.sgotplt)
8476 if (bfd_is_abs_section (htab->root.sgotplt->output_section))
8478 (*_bfd_error_handler)
8479 (_("discarded output section: `%A'"), htab->root.sgotplt);
8483 /* Fill in the first three entries in the global offset table. */
8484 if (htab->root.sgotplt->size > 0)
8486 bfd_put_NN (output_bfd, (bfd_vma) 0, htab->root.sgotplt->contents);
8488 /* Write GOT[1] and GOT[2], needed for the dynamic linker. */
8489 bfd_put_NN (output_bfd,
8491 htab->root.sgotplt->contents + GOT_ENTRY_SIZE);
8492 bfd_put_NN (output_bfd,
8494 htab->root.sgotplt->contents + GOT_ENTRY_SIZE * 2);
8497 if (htab->root.sgot)
8499 if (htab->root.sgot->size > 0)
8502 sdyn ? sdyn->output_section->vma + sdyn->output_offset : 0;
8503 bfd_put_NN (output_bfd, addr, htab->root.sgot->contents);
8507 elf_section_data (htab->root.sgotplt->output_section)->
8508 this_hdr.sh_entsize = GOT_ENTRY_SIZE;
8511 if (htab->root.sgot && htab->root.sgot->size > 0)
8512 elf_section_data (htab->root.sgot->output_section)->this_hdr.sh_entsize
8515 /* Fill PLT and GOT entries for local STT_GNU_IFUNC symbols. */
8516 htab_traverse (htab->loc_hash_table,
8517 elfNN_aarch64_finish_local_dynamic_symbol,
8523 /* Return address for Ith PLT stub in section PLT, for relocation REL
8524 or (bfd_vma) -1 if it should not be included. */
8527 elfNN_aarch64_plt_sym_val (bfd_vma i, const asection *plt,
8528 const arelent *rel ATTRIBUTE_UNUSED)
8530 return plt->vma + PLT_ENTRY_SIZE + i * PLT_SMALL_ENTRY_SIZE;
8534 /* We use this so we can override certain functions
8535 (though currently we don't). */
8537 const struct elf_size_info elfNN_aarch64_size_info =
8539 sizeof (ElfNN_External_Ehdr),
8540 sizeof (ElfNN_External_Phdr),
8541 sizeof (ElfNN_External_Shdr),
8542 sizeof (ElfNN_External_Rel),
8543 sizeof (ElfNN_External_Rela),
8544 sizeof (ElfNN_External_Sym),
8545 sizeof (ElfNN_External_Dyn),
8546 sizeof (Elf_External_Note),
8547 4, /* Hash table entry size. */
8548 1, /* Internal relocs per external relocs. */
8549 ARCH_SIZE, /* Arch size. */
8550 LOG_FILE_ALIGN, /* Log_file_align. */
8551 ELFCLASSNN, EV_CURRENT,
8552 bfd_elfNN_write_out_phdrs,
8553 bfd_elfNN_write_shdrs_and_ehdr,
8554 bfd_elfNN_checksum_contents,
8555 bfd_elfNN_write_relocs,
8556 bfd_elfNN_swap_symbol_in,
8557 bfd_elfNN_swap_symbol_out,
8558 bfd_elfNN_slurp_reloc_table,
8559 bfd_elfNN_slurp_symbol_table,
8560 bfd_elfNN_swap_dyn_in,
8561 bfd_elfNN_swap_dyn_out,
8562 bfd_elfNN_swap_reloc_in,
8563 bfd_elfNN_swap_reloc_out,
8564 bfd_elfNN_swap_reloca_in,
8565 bfd_elfNN_swap_reloca_out
8568 #define ELF_ARCH bfd_arch_aarch64
8569 #define ELF_MACHINE_CODE EM_AARCH64
8570 #define ELF_MAXPAGESIZE 0x10000
8571 #define ELF_MINPAGESIZE 0x1000
8572 #define ELF_COMMONPAGESIZE 0x1000
8574 #define bfd_elfNN_close_and_cleanup \
8575 elfNN_aarch64_close_and_cleanup
8577 #define bfd_elfNN_bfd_free_cached_info \
8578 elfNN_aarch64_bfd_free_cached_info
8580 #define bfd_elfNN_bfd_is_target_special_symbol \
8581 elfNN_aarch64_is_target_special_symbol
8583 #define bfd_elfNN_bfd_link_hash_table_create \
8584 elfNN_aarch64_link_hash_table_create
8586 #define bfd_elfNN_bfd_merge_private_bfd_data \
8587 elfNN_aarch64_merge_private_bfd_data
8589 #define bfd_elfNN_bfd_print_private_bfd_data \
8590 elfNN_aarch64_print_private_bfd_data
8592 #define bfd_elfNN_bfd_reloc_type_lookup \
8593 elfNN_aarch64_reloc_type_lookup
8595 #define bfd_elfNN_bfd_reloc_name_lookup \
8596 elfNN_aarch64_reloc_name_lookup
8598 #define bfd_elfNN_bfd_set_private_flags \
8599 elfNN_aarch64_set_private_flags
8601 #define bfd_elfNN_find_inliner_info \
8602 elfNN_aarch64_find_inliner_info
8604 #define bfd_elfNN_find_nearest_line \
8605 elfNN_aarch64_find_nearest_line
8607 #define bfd_elfNN_mkobject \
8608 elfNN_aarch64_mkobject
8610 #define bfd_elfNN_new_section_hook \
8611 elfNN_aarch64_new_section_hook
8613 #define elf_backend_adjust_dynamic_symbol \
8614 elfNN_aarch64_adjust_dynamic_symbol
8616 #define elf_backend_always_size_sections \
8617 elfNN_aarch64_always_size_sections
8619 #define elf_backend_check_relocs \
8620 elfNN_aarch64_check_relocs
8622 #define elf_backend_copy_indirect_symbol \
8623 elfNN_aarch64_copy_indirect_symbol
8625 /* Create .dynbss, and .rela.bss sections in DYNOBJ, and set up shortcuts
8626 to them in our hash. */
8627 #define elf_backend_create_dynamic_sections \
8628 elfNN_aarch64_create_dynamic_sections
8630 #define elf_backend_init_index_section \
8631 _bfd_elf_init_2_index_sections
8633 #define elf_backend_finish_dynamic_sections \
8634 elfNN_aarch64_finish_dynamic_sections
8636 #define elf_backend_finish_dynamic_symbol \
8637 elfNN_aarch64_finish_dynamic_symbol
8639 #define elf_backend_gc_sweep_hook \
8640 elfNN_aarch64_gc_sweep_hook
8642 #define elf_backend_object_p \
8643 elfNN_aarch64_object_p
8645 #define elf_backend_output_arch_local_syms \
8646 elfNN_aarch64_output_arch_local_syms
8648 #define elf_backend_plt_sym_val \
8649 elfNN_aarch64_plt_sym_val
8651 #define elf_backend_post_process_headers \
8652 elfNN_aarch64_post_process_headers
8654 #define elf_backend_relocate_section \
8655 elfNN_aarch64_relocate_section
8657 #define elf_backend_reloc_type_class \
8658 elfNN_aarch64_reloc_type_class
8660 #define elf_backend_section_from_shdr \
8661 elfNN_aarch64_section_from_shdr
8663 #define elf_backend_size_dynamic_sections \
8664 elfNN_aarch64_size_dynamic_sections
8666 #define elf_backend_size_info \
8667 elfNN_aarch64_size_info
8669 #define elf_backend_write_section \
8670 elfNN_aarch64_write_section
8672 #define elf_backend_can_refcount 1
8673 #define elf_backend_can_gc_sections 1
8674 #define elf_backend_plt_readonly 1
8675 #define elf_backend_want_got_plt 1
8676 #define elf_backend_want_plt_sym 0
8677 #define elf_backend_may_use_rel_p 0
8678 #define elf_backend_may_use_rela_p 1
8679 #define elf_backend_default_use_rela_p 1
8680 #define elf_backend_rela_normal 1
8681 #define elf_backend_got_header_size (GOT_ENTRY_SIZE * 3)
8682 #define elf_backend_default_execstack 0
8683 #define elf_backend_extern_protected_data 1
8685 #undef elf_backend_obj_attrs_section
8686 #define elf_backend_obj_attrs_section ".ARM.attributes"
8688 #include "elfNN-target.h"