1 /* AArch64-specific support for NN-bit ELF.
2 Copyright (C) 2009-2015 Free Software Foundation, Inc.
3 Contributed by ARM Ltd.
5 This file is part of BFD, the Binary File Descriptor library.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; see the file COPYING3. If not,
19 see <http://www.gnu.org/licenses/>. */
21 /* Notes on implementation:
23 Thread Local Store (TLS)
27 The implementation currently supports both traditional TLS and TLS
28 descriptors, but only general dynamic (GD).
30 For traditional TLS the assembler will present us with code
31 fragments of the form:
34 R_AARCH64_TLSGD_ADR_PAGE21(foo)
35 add x0, :tlsgd_lo12:foo
36 R_AARCH64_TLSGD_ADD_LO12_NC(foo)
40 For TLS descriptors the assembler will present us with code
41 fragments of the form:
43 adrp x0, :tlsdesc:foo R_AARCH64_TLSDESC_ADR_PAGE21(foo)
44 ldr x1, [x0, #:tlsdesc_lo12:foo] R_AARCH64_TLSDESC_LD64_LO12(foo)
45 add x0, x0, #:tlsdesc_lo12:foo R_AARCH64_TLSDESC_ADD_LO12(foo)
47 blr x1 R_AARCH64_TLSDESC_CALL(foo)
49 The relocations R_AARCH64_TLSGD_{ADR_PREL21,ADD_LO12_NC} against foo
50 indicate that foo is thread local and should be accessed via the
51 traditional TLS mechanims.
53 The relocations R_AARCH64_TLSDESC_{ADR_PAGE21,LD64_LO12_NC,ADD_LO12_NC}
54 against foo indicate that 'foo' is thread local and should be accessed
55 via a TLS descriptor mechanism.
57 The precise instruction sequence is only relevant from the
58 perspective of linker relaxation which is currently not implemented.
60 The static linker must detect that 'foo' is a TLS object and
61 allocate a double GOT entry. The GOT entry must be created for both
62 global and local TLS symbols. Note that this is different to none
63 TLS local objects which do not need a GOT entry.
65 In the traditional TLS mechanism, the double GOT entry is used to
66 provide the tls_index structure, containing module and offset
67 entries. The static linker places the relocation R_AARCH64_TLS_DTPMOD
68 on the module entry. The loader will subsequently fixup this
69 relocation with the module identity.
71 For global traditional TLS symbols the static linker places an
72 R_AARCH64_TLS_DTPREL relocation on the offset entry. The loader
73 will subsequently fixup the offset. For local TLS symbols the static
74 linker fixes up offset.
76 In the TLS descriptor mechanism the double GOT entry is used to
77 provide the descriptor. The static linker places the relocation
78 R_AARCH64_TLSDESC on the first GOT slot. The loader will
79 subsequently fix this up.
83 The handling of TLS symbols is implemented across a number of
84 different backend functions. The following is a top level view of
85 what processing is performed where.
87 The TLS implementation maintains state information for each TLS
88 symbol. The state information for local and global symbols is kept
89 in different places. Global symbols use generic BFD structures while
90 local symbols use backend specific structures that are allocated and
91 maintained entirely by the backend.
95 elfNN_aarch64_check_relocs()
97 This function is invoked for each relocation.
99 The TLS relocations R_AARCH64_TLSGD_{ADR_PREL21,ADD_LO12_NC} and
100 R_AARCH64_TLSDESC_{ADR_PAGE21,LD64_LO12_NC,ADD_LO12_NC} are
101 spotted. One time creation of local symbol data structures are
102 created when the first local symbol is seen.
104 The reference count for a symbol is incremented. The GOT type for
105 each symbol is marked as general dynamic.
107 elfNN_aarch64_allocate_dynrelocs ()
109 For each global with positive reference count we allocate a double
110 GOT slot. For a traditional TLS symbol we allocate space for two
111 relocation entries on the GOT, for a TLS descriptor symbol we
112 allocate space for one relocation on the slot. Record the GOT offset
115 elfNN_aarch64_size_dynamic_sections ()
117 Iterate all input BFDS, look for in the local symbol data structure
118 constructed earlier for local TLS symbols and allocate them double
119 GOT slots along with space for a single GOT relocation. Update the
120 local symbol structure to record the GOT offset allocated.
122 elfNN_aarch64_relocate_section ()
124 Calls elfNN_aarch64_final_link_relocate ()
126 Emit the relevant TLS relocations against the GOT for each TLS
127 symbol. For local TLS symbols emit the GOT offset directly. The GOT
128 relocations are emitted once the first time a TLS symbol is
129 encountered. The implementation uses the LSB of the GOT offset to
130 flag that the relevant GOT relocations for a symbol have been
131 emitted. All of the TLS code that uses the GOT offset needs to take
132 care to mask out this flag bit before using the offset.
134 elfNN_aarch64_final_link_relocate ()
136 Fixup the R_AARCH64_TLSGD_{ADR_PREL21, ADD_LO12_NC} relocations. */
140 #include "libiberty.h"
142 #include "bfd_stdint.h"
145 #include "objalloc.h"
146 #include "elf/aarch64.h"
147 #include "elfxx-aarch64.h"
152 #define AARCH64_R(NAME) R_AARCH64_ ## NAME
153 #define AARCH64_R_STR(NAME) "R_AARCH64_" #NAME
154 #define HOWTO64(...) HOWTO (__VA_ARGS__)
155 #define HOWTO32(...) EMPTY_HOWTO (0)
156 #define LOG_FILE_ALIGN 3
160 #define AARCH64_R(NAME) R_AARCH64_P32_ ## NAME
161 #define AARCH64_R_STR(NAME) "R_AARCH64_P32_" #NAME
162 #define HOWTO64(...) EMPTY_HOWTO (0)
163 #define HOWTO32(...) HOWTO (__VA_ARGS__)
164 #define LOG_FILE_ALIGN 2
167 #define IS_AARCH64_TLS_RELOC(R_TYPE) \
168 ((R_TYPE) == BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC \
169 || (R_TYPE) == BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21 \
170 || (R_TYPE) == BFD_RELOC_AARCH64_TLSGD_ADR_PREL21 \
171 || (R_TYPE) == BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21 \
172 || (R_TYPE) == BFD_RELOC_AARCH64_TLSIE_LD32_GOTTPREL_LO12_NC \
173 || (R_TYPE) == BFD_RELOC_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC \
174 || (R_TYPE) == BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19 \
175 || (R_TYPE) == BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G0_NC \
176 || (R_TYPE) == BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G1 \
177 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_ADD_DTPREL_LO12 \
178 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_ADD_DTPREL_LO12_NC \
179 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC \
180 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21 \
181 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_ADR_PREL21 \
182 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_HI12 \
183 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_LO12 \
184 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_LO12_NC \
185 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0 \
186 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC \
187 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1 \
188 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1_NC \
189 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G2 \
190 || (R_TYPE) == BFD_RELOC_AARCH64_TLS_DTPMOD \
191 || (R_TYPE) == BFD_RELOC_AARCH64_TLS_DTPREL \
192 || (R_TYPE) == BFD_RELOC_AARCH64_TLS_TPREL \
193 || IS_AARCH64_TLSDESC_RELOC ((R_TYPE)))
195 #define IS_AARCH64_TLS_RELAX_RELOC(R_TYPE) \
196 ((R_TYPE) == BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21 \
197 || (R_TYPE) == BFD_RELOC_AARCH64_TLSGD_ADR_PREL21 \
198 || (R_TYPE) == BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC \
199 || (R_TYPE) == BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21 \
200 || (R_TYPE) == BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19 \
201 || (R_TYPE) == BFD_RELOC_AARCH64_TLSIE_LDNN_GOTTPREL_LO12_NC \
202 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21 \
203 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21 \
204 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_LD_PREL19 \
205 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_LDNN_LO12_NC \
206 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_CALL \
207 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_ADD_LO12_NC)
209 #define IS_AARCH64_TLSDESC_RELOC(R_TYPE) \
210 ((R_TYPE) == BFD_RELOC_AARCH64_TLSDESC \
211 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_ADD \
212 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_ADD_LO12_NC \
213 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21 \
214 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21 \
215 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_CALL \
216 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_LD32_LO12_NC \
217 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_LD64_LO12_NC \
218 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_LDR \
219 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_LD_PREL19 \
220 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_OFF_G0_NC \
221 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_OFF_G1)
223 #define ELIMINATE_COPY_RELOCS 0
225 /* Return size of a relocation entry. HTAB is the bfd's
226 elf_aarch64_link_hash_entry. */
227 #define RELOC_SIZE(HTAB) (sizeof (ElfNN_External_Rela))
229 /* GOT Entry size - 8 bytes in ELF64 and 4 bytes in ELF32. */
230 #define GOT_ENTRY_SIZE (ARCH_SIZE / 8)
231 #define PLT_ENTRY_SIZE (32)
232 #define PLT_SMALL_ENTRY_SIZE (16)
233 #define PLT_TLSDESC_ENTRY_SIZE (32)
235 /* Encoding of the nop instruction */
236 #define INSN_NOP 0xd503201f
238 #define aarch64_compute_jump_table_size(htab) \
239 (((htab)->root.srelplt == NULL) ? 0 \
240 : (htab)->root.srelplt->reloc_count * GOT_ENTRY_SIZE)
242 /* The first entry in a procedure linkage table looks like this
243 if the distance between the PLTGOT and the PLT is < 4GB use
244 these PLT entries. Note that the dynamic linker gets &PLTGOT[2]
245 in x16 and needs to work out PLTGOT[1] by using an address of
246 [x16,#-GOT_ENTRY_SIZE]. */
247 static const bfd_byte elfNN_aarch64_small_plt0_entry[PLT_ENTRY_SIZE] =
249 0xf0, 0x7b, 0xbf, 0xa9, /* stp x16, x30, [sp, #-16]! */
250 0x10, 0x00, 0x00, 0x90, /* adrp x16, (GOT+16) */
252 0x11, 0x0A, 0x40, 0xf9, /* ldr x17, [x16, #PLT_GOT+0x10] */
253 0x10, 0x42, 0x00, 0x91, /* add x16, x16,#PLT_GOT+0x10 */
255 0x11, 0x0A, 0x40, 0xb9, /* ldr w17, [x16, #PLT_GOT+0x8] */
256 0x10, 0x22, 0x00, 0x11, /* add w16, w16,#PLT_GOT+0x8 */
258 0x20, 0x02, 0x1f, 0xd6, /* br x17 */
259 0x1f, 0x20, 0x03, 0xd5, /* nop */
260 0x1f, 0x20, 0x03, 0xd5, /* nop */
261 0x1f, 0x20, 0x03, 0xd5, /* nop */
264 /* Per function entry in a procedure linkage table looks like this
265 if the distance between the PLTGOT and the PLT is < 4GB use
266 these PLT entries. */
267 static const bfd_byte elfNN_aarch64_small_plt_entry[PLT_SMALL_ENTRY_SIZE] =
269 0x10, 0x00, 0x00, 0x90, /* adrp x16, PLTGOT + n * 8 */
271 0x11, 0x02, 0x40, 0xf9, /* ldr x17, [x16, PLTGOT + n * 8] */
272 0x10, 0x02, 0x00, 0x91, /* add x16, x16, :lo12:PLTGOT + n * 8 */
274 0x11, 0x02, 0x40, 0xb9, /* ldr w17, [x16, PLTGOT + n * 4] */
275 0x10, 0x02, 0x00, 0x11, /* add w16, w16, :lo12:PLTGOT + n * 4 */
277 0x20, 0x02, 0x1f, 0xd6, /* br x17. */
280 static const bfd_byte
281 elfNN_aarch64_tlsdesc_small_plt_entry[PLT_TLSDESC_ENTRY_SIZE] =
283 0xe2, 0x0f, 0xbf, 0xa9, /* stp x2, x3, [sp, #-16]! */
284 0x02, 0x00, 0x00, 0x90, /* adrp x2, 0 */
285 0x03, 0x00, 0x00, 0x90, /* adrp x3, 0 */
287 0x42, 0x00, 0x40, 0xf9, /* ldr x2, [x2, #0] */
288 0x63, 0x00, 0x00, 0x91, /* add x3, x3, 0 */
290 0x42, 0x00, 0x40, 0xb9, /* ldr w2, [x2, #0] */
291 0x63, 0x00, 0x00, 0x11, /* add w3, w3, 0 */
293 0x40, 0x00, 0x1f, 0xd6, /* br x2 */
294 0x1f, 0x20, 0x03, 0xd5, /* nop */
295 0x1f, 0x20, 0x03, 0xd5, /* nop */
298 #define elf_info_to_howto elfNN_aarch64_info_to_howto
299 #define elf_info_to_howto_rel elfNN_aarch64_info_to_howto
301 #define AARCH64_ELF_ABI_VERSION 0
303 /* In case we're on a 32-bit machine, construct a 64-bit "-1" value. */
304 #define ALL_ONES (~ (bfd_vma) 0)
306 /* Indexed by the bfd interal reloc enumerators.
307 Therefore, the table needs to be synced with BFD_RELOC_AARCH64_*
310 static reloc_howto_type elfNN_aarch64_howto_table[] =
314 /* Basic data relocations. */
317 HOWTO (R_AARCH64_NULL, /* type */
319 3, /* size (0 = byte, 1 = short, 2 = long) */
321 FALSE, /* pc_relative */
323 complain_overflow_dont, /* complain_on_overflow */
324 bfd_elf_generic_reloc, /* special_function */
325 "R_AARCH64_NULL", /* name */
326 FALSE, /* partial_inplace */
329 FALSE), /* pcrel_offset */
331 HOWTO (R_AARCH64_NONE, /* type */
333 3, /* size (0 = byte, 1 = short, 2 = long) */
335 FALSE, /* pc_relative */
337 complain_overflow_dont, /* complain_on_overflow */
338 bfd_elf_generic_reloc, /* special_function */
339 "R_AARCH64_NONE", /* name */
340 FALSE, /* partial_inplace */
343 FALSE), /* pcrel_offset */
347 HOWTO64 (AARCH64_R (ABS64), /* type */
349 4, /* size (4 = long long) */
351 FALSE, /* pc_relative */
353 complain_overflow_unsigned, /* complain_on_overflow */
354 bfd_elf_generic_reloc, /* special_function */
355 AARCH64_R_STR (ABS64), /* name */
356 FALSE, /* partial_inplace */
357 ALL_ONES, /* src_mask */
358 ALL_ONES, /* dst_mask */
359 FALSE), /* pcrel_offset */
362 HOWTO (AARCH64_R (ABS32), /* type */
364 2, /* size (0 = byte, 1 = short, 2 = long) */
366 FALSE, /* pc_relative */
368 complain_overflow_unsigned, /* complain_on_overflow */
369 bfd_elf_generic_reloc, /* special_function */
370 AARCH64_R_STR (ABS32), /* name */
371 FALSE, /* partial_inplace */
372 0xffffffff, /* src_mask */
373 0xffffffff, /* dst_mask */
374 FALSE), /* pcrel_offset */
377 HOWTO (AARCH64_R (ABS16), /* type */
379 1, /* size (0 = byte, 1 = short, 2 = long) */
381 FALSE, /* pc_relative */
383 complain_overflow_unsigned, /* complain_on_overflow */
384 bfd_elf_generic_reloc, /* special_function */
385 AARCH64_R_STR (ABS16), /* name */
386 FALSE, /* partial_inplace */
387 0xffff, /* src_mask */
388 0xffff, /* dst_mask */
389 FALSE), /* pcrel_offset */
391 /* .xword: (S+A-P) */
392 HOWTO64 (AARCH64_R (PREL64), /* type */
394 4, /* size (4 = long long) */
396 TRUE, /* pc_relative */
398 complain_overflow_signed, /* complain_on_overflow */
399 bfd_elf_generic_reloc, /* special_function */
400 AARCH64_R_STR (PREL64), /* name */
401 FALSE, /* partial_inplace */
402 ALL_ONES, /* src_mask */
403 ALL_ONES, /* dst_mask */
404 TRUE), /* pcrel_offset */
407 HOWTO (AARCH64_R (PREL32), /* type */
409 2, /* size (0 = byte, 1 = short, 2 = long) */
411 TRUE, /* pc_relative */
413 complain_overflow_signed, /* complain_on_overflow */
414 bfd_elf_generic_reloc, /* special_function */
415 AARCH64_R_STR (PREL32), /* name */
416 FALSE, /* partial_inplace */
417 0xffffffff, /* src_mask */
418 0xffffffff, /* dst_mask */
419 TRUE), /* pcrel_offset */
422 HOWTO (AARCH64_R (PREL16), /* type */
424 1, /* size (0 = byte, 1 = short, 2 = long) */
426 TRUE, /* pc_relative */
428 complain_overflow_signed, /* complain_on_overflow */
429 bfd_elf_generic_reloc, /* special_function */
430 AARCH64_R_STR (PREL16), /* name */
431 FALSE, /* partial_inplace */
432 0xffff, /* src_mask */
433 0xffff, /* dst_mask */
434 TRUE), /* pcrel_offset */
436 /* Group relocations to create a 16, 32, 48 or 64 bit
437 unsigned data or abs address inline. */
439 /* MOVZ: ((S+A) >> 0) & 0xffff */
440 HOWTO (AARCH64_R (MOVW_UABS_G0), /* type */
442 2, /* size (0 = byte, 1 = short, 2 = long) */
444 FALSE, /* pc_relative */
446 complain_overflow_unsigned, /* complain_on_overflow */
447 bfd_elf_generic_reloc, /* special_function */
448 AARCH64_R_STR (MOVW_UABS_G0), /* name */
449 FALSE, /* partial_inplace */
450 0xffff, /* src_mask */
451 0xffff, /* dst_mask */
452 FALSE), /* pcrel_offset */
454 /* MOVK: ((S+A) >> 0) & 0xffff [no overflow check] */
455 HOWTO (AARCH64_R (MOVW_UABS_G0_NC), /* type */
457 2, /* size (0 = byte, 1 = short, 2 = long) */
459 FALSE, /* pc_relative */
461 complain_overflow_dont, /* complain_on_overflow */
462 bfd_elf_generic_reloc, /* special_function */
463 AARCH64_R_STR (MOVW_UABS_G0_NC), /* name */
464 FALSE, /* partial_inplace */
465 0xffff, /* src_mask */
466 0xffff, /* dst_mask */
467 FALSE), /* pcrel_offset */
469 /* MOVZ: ((S+A) >> 16) & 0xffff */
470 HOWTO (AARCH64_R (MOVW_UABS_G1), /* type */
472 2, /* size (0 = byte, 1 = short, 2 = long) */
474 FALSE, /* pc_relative */
476 complain_overflow_unsigned, /* complain_on_overflow */
477 bfd_elf_generic_reloc, /* special_function */
478 AARCH64_R_STR (MOVW_UABS_G1), /* name */
479 FALSE, /* partial_inplace */
480 0xffff, /* src_mask */
481 0xffff, /* dst_mask */
482 FALSE), /* pcrel_offset */
484 /* MOVK: ((S+A) >> 16) & 0xffff [no overflow check] */
485 HOWTO64 (AARCH64_R (MOVW_UABS_G1_NC), /* type */
487 2, /* size (0 = byte, 1 = short, 2 = long) */
489 FALSE, /* pc_relative */
491 complain_overflow_dont, /* complain_on_overflow */
492 bfd_elf_generic_reloc, /* special_function */
493 AARCH64_R_STR (MOVW_UABS_G1_NC), /* name */
494 FALSE, /* partial_inplace */
495 0xffff, /* src_mask */
496 0xffff, /* dst_mask */
497 FALSE), /* pcrel_offset */
499 /* MOVZ: ((S+A) >> 32) & 0xffff */
500 HOWTO64 (AARCH64_R (MOVW_UABS_G2), /* type */
502 2, /* size (0 = byte, 1 = short, 2 = long) */
504 FALSE, /* pc_relative */
506 complain_overflow_unsigned, /* complain_on_overflow */
507 bfd_elf_generic_reloc, /* special_function */
508 AARCH64_R_STR (MOVW_UABS_G2), /* name */
509 FALSE, /* partial_inplace */
510 0xffff, /* src_mask */
511 0xffff, /* dst_mask */
512 FALSE), /* pcrel_offset */
514 /* MOVK: ((S+A) >> 32) & 0xffff [no overflow check] */
515 HOWTO64 (AARCH64_R (MOVW_UABS_G2_NC), /* type */
517 2, /* size (0 = byte, 1 = short, 2 = long) */
519 FALSE, /* pc_relative */
521 complain_overflow_dont, /* complain_on_overflow */
522 bfd_elf_generic_reloc, /* special_function */
523 AARCH64_R_STR (MOVW_UABS_G2_NC), /* name */
524 FALSE, /* partial_inplace */
525 0xffff, /* src_mask */
526 0xffff, /* dst_mask */
527 FALSE), /* pcrel_offset */
529 /* MOVZ: ((S+A) >> 48) & 0xffff */
530 HOWTO64 (AARCH64_R (MOVW_UABS_G3), /* type */
532 2, /* size (0 = byte, 1 = short, 2 = long) */
534 FALSE, /* pc_relative */
536 complain_overflow_unsigned, /* complain_on_overflow */
537 bfd_elf_generic_reloc, /* special_function */
538 AARCH64_R_STR (MOVW_UABS_G3), /* name */
539 FALSE, /* partial_inplace */
540 0xffff, /* src_mask */
541 0xffff, /* dst_mask */
542 FALSE), /* pcrel_offset */
544 /* Group relocations to create high part of a 16, 32, 48 or 64 bit
545 signed data or abs address inline. Will change instruction
546 to MOVN or MOVZ depending on sign of calculated value. */
548 /* MOV[ZN]: ((S+A) >> 0) & 0xffff */
549 HOWTO (AARCH64_R (MOVW_SABS_G0), /* type */
551 2, /* size (0 = byte, 1 = short, 2 = long) */
553 FALSE, /* pc_relative */
555 complain_overflow_signed, /* complain_on_overflow */
556 bfd_elf_generic_reloc, /* special_function */
557 AARCH64_R_STR (MOVW_SABS_G0), /* name */
558 FALSE, /* partial_inplace */
559 0xffff, /* src_mask */
560 0xffff, /* dst_mask */
561 FALSE), /* pcrel_offset */
563 /* MOV[ZN]: ((S+A) >> 16) & 0xffff */
564 HOWTO64 (AARCH64_R (MOVW_SABS_G1), /* type */
566 2, /* size (0 = byte, 1 = short, 2 = long) */
568 FALSE, /* pc_relative */
570 complain_overflow_signed, /* complain_on_overflow */
571 bfd_elf_generic_reloc, /* special_function */
572 AARCH64_R_STR (MOVW_SABS_G1), /* name */
573 FALSE, /* partial_inplace */
574 0xffff, /* src_mask */
575 0xffff, /* dst_mask */
576 FALSE), /* pcrel_offset */
578 /* MOV[ZN]: ((S+A) >> 32) & 0xffff */
579 HOWTO64 (AARCH64_R (MOVW_SABS_G2), /* type */
581 2, /* size (0 = byte, 1 = short, 2 = long) */
583 FALSE, /* pc_relative */
585 complain_overflow_signed, /* complain_on_overflow */
586 bfd_elf_generic_reloc, /* special_function */
587 AARCH64_R_STR (MOVW_SABS_G2), /* name */
588 FALSE, /* partial_inplace */
589 0xffff, /* src_mask */
590 0xffff, /* dst_mask */
591 FALSE), /* pcrel_offset */
593 /* Relocations to generate 19, 21 and 33 bit PC-relative load/store
594 addresses: PG(x) is (x & ~0xfff). */
596 /* LD-lit: ((S+A-P) >> 2) & 0x7ffff */
597 HOWTO (AARCH64_R (LD_PREL_LO19), /* type */
599 2, /* size (0 = byte, 1 = short, 2 = long) */
601 TRUE, /* pc_relative */
603 complain_overflow_signed, /* complain_on_overflow */
604 bfd_elf_generic_reloc, /* special_function */
605 AARCH64_R_STR (LD_PREL_LO19), /* name */
606 FALSE, /* partial_inplace */
607 0x7ffff, /* src_mask */
608 0x7ffff, /* dst_mask */
609 TRUE), /* pcrel_offset */
611 /* ADR: (S+A-P) & 0x1fffff */
612 HOWTO (AARCH64_R (ADR_PREL_LO21), /* type */
614 2, /* size (0 = byte, 1 = short, 2 = long) */
616 TRUE, /* pc_relative */
618 complain_overflow_signed, /* complain_on_overflow */
619 bfd_elf_generic_reloc, /* special_function */
620 AARCH64_R_STR (ADR_PREL_LO21), /* name */
621 FALSE, /* partial_inplace */
622 0x1fffff, /* src_mask */
623 0x1fffff, /* dst_mask */
624 TRUE), /* pcrel_offset */
626 /* ADRP: ((PG(S+A)-PG(P)) >> 12) & 0x1fffff */
627 HOWTO (AARCH64_R (ADR_PREL_PG_HI21), /* type */
629 2, /* size (0 = byte, 1 = short, 2 = long) */
631 TRUE, /* pc_relative */
633 complain_overflow_signed, /* complain_on_overflow */
634 bfd_elf_generic_reloc, /* special_function */
635 AARCH64_R_STR (ADR_PREL_PG_HI21), /* name */
636 FALSE, /* partial_inplace */
637 0x1fffff, /* src_mask */
638 0x1fffff, /* dst_mask */
639 TRUE), /* pcrel_offset */
641 /* ADRP: ((PG(S+A)-PG(P)) >> 12) & 0x1fffff [no overflow check] */
642 HOWTO64 (AARCH64_R (ADR_PREL_PG_HI21_NC), /* type */
644 2, /* size (0 = byte, 1 = short, 2 = long) */
646 TRUE, /* pc_relative */
648 complain_overflow_dont, /* complain_on_overflow */
649 bfd_elf_generic_reloc, /* special_function */
650 AARCH64_R_STR (ADR_PREL_PG_HI21_NC), /* name */
651 FALSE, /* partial_inplace */
652 0x1fffff, /* src_mask */
653 0x1fffff, /* dst_mask */
654 TRUE), /* pcrel_offset */
656 /* ADD: (S+A) & 0xfff [no overflow check] */
657 HOWTO (AARCH64_R (ADD_ABS_LO12_NC), /* type */
659 2, /* size (0 = byte, 1 = short, 2 = long) */
661 FALSE, /* pc_relative */
663 complain_overflow_dont, /* complain_on_overflow */
664 bfd_elf_generic_reloc, /* special_function */
665 AARCH64_R_STR (ADD_ABS_LO12_NC), /* name */
666 FALSE, /* partial_inplace */
667 0x3ffc00, /* src_mask */
668 0x3ffc00, /* dst_mask */
669 FALSE), /* pcrel_offset */
671 /* LD/ST8: (S+A) & 0xfff */
672 HOWTO (AARCH64_R (LDST8_ABS_LO12_NC), /* type */
674 2, /* size (0 = byte, 1 = short, 2 = long) */
676 FALSE, /* pc_relative */
678 complain_overflow_dont, /* complain_on_overflow */
679 bfd_elf_generic_reloc, /* special_function */
680 AARCH64_R_STR (LDST8_ABS_LO12_NC), /* name */
681 FALSE, /* partial_inplace */
682 0xfff, /* src_mask */
683 0xfff, /* dst_mask */
684 FALSE), /* pcrel_offset */
686 /* Relocations for control-flow instructions. */
688 /* TBZ/NZ: ((S+A-P) >> 2) & 0x3fff */
689 HOWTO (AARCH64_R (TSTBR14), /* type */
691 2, /* size (0 = byte, 1 = short, 2 = long) */
693 TRUE, /* pc_relative */
695 complain_overflow_signed, /* complain_on_overflow */
696 bfd_elf_generic_reloc, /* special_function */
697 AARCH64_R_STR (TSTBR14), /* name */
698 FALSE, /* partial_inplace */
699 0x3fff, /* src_mask */
700 0x3fff, /* dst_mask */
701 TRUE), /* pcrel_offset */
703 /* B.cond: ((S+A-P) >> 2) & 0x7ffff */
704 HOWTO (AARCH64_R (CONDBR19), /* type */
706 2, /* size (0 = byte, 1 = short, 2 = long) */
708 TRUE, /* pc_relative */
710 complain_overflow_signed, /* complain_on_overflow */
711 bfd_elf_generic_reloc, /* special_function */
712 AARCH64_R_STR (CONDBR19), /* name */
713 FALSE, /* partial_inplace */
714 0x7ffff, /* src_mask */
715 0x7ffff, /* dst_mask */
716 TRUE), /* pcrel_offset */
718 /* B: ((S+A-P) >> 2) & 0x3ffffff */
719 HOWTO (AARCH64_R (JUMP26), /* type */
721 2, /* size (0 = byte, 1 = short, 2 = long) */
723 TRUE, /* pc_relative */
725 complain_overflow_signed, /* complain_on_overflow */
726 bfd_elf_generic_reloc, /* special_function */
727 AARCH64_R_STR (JUMP26), /* name */
728 FALSE, /* partial_inplace */
729 0x3ffffff, /* src_mask */
730 0x3ffffff, /* dst_mask */
731 TRUE), /* pcrel_offset */
733 /* BL: ((S+A-P) >> 2) & 0x3ffffff */
734 HOWTO (AARCH64_R (CALL26), /* type */
736 2, /* size (0 = byte, 1 = short, 2 = long) */
738 TRUE, /* pc_relative */
740 complain_overflow_signed, /* complain_on_overflow */
741 bfd_elf_generic_reloc, /* special_function */
742 AARCH64_R_STR (CALL26), /* name */
743 FALSE, /* partial_inplace */
744 0x3ffffff, /* src_mask */
745 0x3ffffff, /* dst_mask */
746 TRUE), /* pcrel_offset */
748 /* LD/ST16: (S+A) & 0xffe */
749 HOWTO (AARCH64_R (LDST16_ABS_LO12_NC), /* type */
751 2, /* size (0 = byte, 1 = short, 2 = long) */
753 FALSE, /* pc_relative */
755 complain_overflow_dont, /* complain_on_overflow */
756 bfd_elf_generic_reloc, /* special_function */
757 AARCH64_R_STR (LDST16_ABS_LO12_NC), /* name */
758 FALSE, /* partial_inplace */
759 0xffe, /* src_mask */
760 0xffe, /* dst_mask */
761 FALSE), /* pcrel_offset */
763 /* LD/ST32: (S+A) & 0xffc */
764 HOWTO (AARCH64_R (LDST32_ABS_LO12_NC), /* type */
766 2, /* size (0 = byte, 1 = short, 2 = long) */
768 FALSE, /* pc_relative */
770 complain_overflow_dont, /* complain_on_overflow */
771 bfd_elf_generic_reloc, /* special_function */
772 AARCH64_R_STR (LDST32_ABS_LO12_NC), /* name */
773 FALSE, /* partial_inplace */
774 0xffc, /* src_mask */
775 0xffc, /* dst_mask */
776 FALSE), /* pcrel_offset */
778 /* LD/ST64: (S+A) & 0xff8 */
779 HOWTO (AARCH64_R (LDST64_ABS_LO12_NC), /* type */
781 2, /* size (0 = byte, 1 = short, 2 = long) */
783 FALSE, /* pc_relative */
785 complain_overflow_dont, /* complain_on_overflow */
786 bfd_elf_generic_reloc, /* special_function */
787 AARCH64_R_STR (LDST64_ABS_LO12_NC), /* name */
788 FALSE, /* partial_inplace */
789 0xff8, /* src_mask */
790 0xff8, /* dst_mask */
791 FALSE), /* pcrel_offset */
793 /* LD/ST128: (S+A) & 0xff0 */
794 HOWTO (AARCH64_R (LDST128_ABS_LO12_NC), /* type */
796 2, /* size (0 = byte, 1 = short, 2 = long) */
798 FALSE, /* pc_relative */
800 complain_overflow_dont, /* complain_on_overflow */
801 bfd_elf_generic_reloc, /* special_function */
802 AARCH64_R_STR (LDST128_ABS_LO12_NC), /* name */
803 FALSE, /* partial_inplace */
804 0xff0, /* src_mask */
805 0xff0, /* dst_mask */
806 FALSE), /* pcrel_offset */
808 /* Set a load-literal immediate field to bits
809 0x1FFFFC of G(S)-P */
810 HOWTO (AARCH64_R (GOT_LD_PREL19), /* type */
812 2, /* size (0 = byte,1 = short,2 = long) */
814 TRUE, /* pc_relative */
816 complain_overflow_signed, /* complain_on_overflow */
817 bfd_elf_generic_reloc, /* special_function */
818 AARCH64_R_STR (GOT_LD_PREL19), /* name */
819 FALSE, /* partial_inplace */
820 0xffffe0, /* src_mask */
821 0xffffe0, /* dst_mask */
822 TRUE), /* pcrel_offset */
824 /* Get to the page for the GOT entry for the symbol
825 (G(S) - P) using an ADRP instruction. */
826 HOWTO (AARCH64_R (ADR_GOT_PAGE), /* type */
828 2, /* size (0 = byte, 1 = short, 2 = long) */
830 TRUE, /* pc_relative */
832 complain_overflow_dont, /* complain_on_overflow */
833 bfd_elf_generic_reloc, /* special_function */
834 AARCH64_R_STR (ADR_GOT_PAGE), /* name */
835 FALSE, /* partial_inplace */
836 0x1fffff, /* src_mask */
837 0x1fffff, /* dst_mask */
838 TRUE), /* pcrel_offset */
840 /* LD64: GOT offset G(S) & 0xff8 */
841 HOWTO64 (AARCH64_R (LD64_GOT_LO12_NC), /* type */
843 2, /* size (0 = byte, 1 = short, 2 = long) */
845 FALSE, /* pc_relative */
847 complain_overflow_dont, /* complain_on_overflow */
848 bfd_elf_generic_reloc, /* special_function */
849 AARCH64_R_STR (LD64_GOT_LO12_NC), /* name */
850 FALSE, /* partial_inplace */
851 0xff8, /* src_mask */
852 0xff8, /* dst_mask */
853 FALSE), /* pcrel_offset */
855 /* LD32: GOT offset G(S) & 0xffc */
856 HOWTO32 (AARCH64_R (LD32_GOT_LO12_NC), /* type */
858 2, /* size (0 = byte, 1 = short, 2 = long) */
860 FALSE, /* pc_relative */
862 complain_overflow_dont, /* complain_on_overflow */
863 bfd_elf_generic_reloc, /* special_function */
864 AARCH64_R_STR (LD32_GOT_LO12_NC), /* name */
865 FALSE, /* partial_inplace */
866 0xffc, /* src_mask */
867 0xffc, /* dst_mask */
868 FALSE), /* pcrel_offset */
870 /* LD64: GOT offset for the symbol. */
871 HOWTO64 (AARCH64_R (LD64_GOTOFF_LO15), /* type */
873 2, /* size (0 = byte, 1 = short, 2 = long) */
875 FALSE, /* pc_relative */
877 complain_overflow_unsigned, /* complain_on_overflow */
878 bfd_elf_generic_reloc, /* special_function */
879 AARCH64_R_STR (LD64_GOTOFF_LO15), /* name */
880 FALSE, /* partial_inplace */
881 0x7ff8, /* src_mask */
882 0x7ff8, /* dst_mask */
883 FALSE), /* pcrel_offset */
885 /* LD32: GOT offset to the page address of GOT table.
886 (G(S) - PAGE (_GLOBAL_OFFSET_TABLE_)) & 0x5ffc. */
887 HOWTO32 (AARCH64_R (LD32_GOTPAGE_LO14), /* type */
889 2, /* size (0 = byte, 1 = short, 2 = long) */
891 FALSE, /* pc_relative */
893 complain_overflow_unsigned, /* complain_on_overflow */
894 bfd_elf_generic_reloc, /* special_function */
895 AARCH64_R_STR (LD32_GOTPAGE_LO14), /* name */
896 FALSE, /* partial_inplace */
897 0x5ffc, /* src_mask */
898 0x5ffc, /* dst_mask */
899 FALSE), /* pcrel_offset */
901 /* LD64: GOT offset to the page address of GOT table.
902 (G(S) - PAGE (_GLOBAL_OFFSET_TABLE_)) & 0x7ff8. */
903 HOWTO64 (AARCH64_R (LD64_GOTPAGE_LO15), /* type */
905 2, /* size (0 = byte, 1 = short, 2 = long) */
907 FALSE, /* pc_relative */
909 complain_overflow_unsigned, /* complain_on_overflow */
910 bfd_elf_generic_reloc, /* special_function */
911 AARCH64_R_STR (LD64_GOTPAGE_LO15), /* name */
912 FALSE, /* partial_inplace */
913 0x7ff8, /* src_mask */
914 0x7ff8, /* dst_mask */
915 FALSE), /* pcrel_offset */
917 /* Get to the page for the GOT entry for the symbol
918 (G(S) - P) using an ADRP instruction. */
919 HOWTO (AARCH64_R (TLSGD_ADR_PAGE21), /* type */
921 2, /* size (0 = byte, 1 = short, 2 = long) */
923 TRUE, /* pc_relative */
925 complain_overflow_dont, /* complain_on_overflow */
926 bfd_elf_generic_reloc, /* special_function */
927 AARCH64_R_STR (TLSGD_ADR_PAGE21), /* name */
928 FALSE, /* partial_inplace */
929 0x1fffff, /* src_mask */
930 0x1fffff, /* dst_mask */
931 TRUE), /* pcrel_offset */
933 HOWTO (AARCH64_R (TLSGD_ADR_PREL21), /* type */
935 2, /* size (0 = byte, 1 = short, 2 = long) */
937 TRUE, /* pc_relative */
939 complain_overflow_dont, /* complain_on_overflow */
940 bfd_elf_generic_reloc, /* special_function */
941 AARCH64_R_STR (TLSGD_ADR_PREL21), /* name */
942 FALSE, /* partial_inplace */
943 0x1fffff, /* src_mask */
944 0x1fffff, /* dst_mask */
945 TRUE), /* pcrel_offset */
947 /* ADD: GOT offset G(S) & 0xff8 [no overflow check] */
948 HOWTO (AARCH64_R (TLSGD_ADD_LO12_NC), /* type */
950 2, /* size (0 = byte, 1 = short, 2 = long) */
952 FALSE, /* pc_relative */
954 complain_overflow_dont, /* complain_on_overflow */
955 bfd_elf_generic_reloc, /* special_function */
956 AARCH64_R_STR (TLSGD_ADD_LO12_NC), /* name */
957 FALSE, /* partial_inplace */
958 0xfff, /* src_mask */
959 0xfff, /* dst_mask */
960 FALSE), /* pcrel_offset */
962 HOWTO64 (AARCH64_R (TLSIE_MOVW_GOTTPREL_G1), /* type */
964 2, /* size (0 = byte, 1 = short, 2 = long) */
966 FALSE, /* pc_relative */
968 complain_overflow_dont, /* complain_on_overflow */
969 bfd_elf_generic_reloc, /* special_function */
970 AARCH64_R_STR (TLSIE_MOVW_GOTTPREL_G1), /* name */
971 FALSE, /* partial_inplace */
972 0xffff, /* src_mask */
973 0xffff, /* dst_mask */
974 FALSE), /* pcrel_offset */
976 HOWTO64 (AARCH64_R (TLSIE_MOVW_GOTTPREL_G0_NC), /* type */
978 2, /* size (0 = byte, 1 = short, 2 = long) */
980 FALSE, /* pc_relative */
982 complain_overflow_dont, /* complain_on_overflow */
983 bfd_elf_generic_reloc, /* special_function */
984 AARCH64_R_STR (TLSIE_MOVW_GOTTPREL_G0_NC), /* name */
985 FALSE, /* partial_inplace */
986 0xffff, /* src_mask */
987 0xffff, /* dst_mask */
988 FALSE), /* pcrel_offset */
990 HOWTO (AARCH64_R (TLSIE_ADR_GOTTPREL_PAGE21), /* type */
992 2, /* size (0 = byte, 1 = short, 2 = long) */
994 FALSE, /* pc_relative */
996 complain_overflow_dont, /* complain_on_overflow */
997 bfd_elf_generic_reloc, /* special_function */
998 AARCH64_R_STR (TLSIE_ADR_GOTTPREL_PAGE21), /* name */
999 FALSE, /* partial_inplace */
1000 0x1fffff, /* src_mask */
1001 0x1fffff, /* dst_mask */
1002 FALSE), /* pcrel_offset */
1004 HOWTO64 (AARCH64_R (TLSIE_LD64_GOTTPREL_LO12_NC), /* type */
1006 2, /* size (0 = byte, 1 = short, 2 = long) */
1008 FALSE, /* pc_relative */
1010 complain_overflow_dont, /* complain_on_overflow */
1011 bfd_elf_generic_reloc, /* special_function */
1012 AARCH64_R_STR (TLSIE_LD64_GOTTPREL_LO12_NC), /* name */
1013 FALSE, /* partial_inplace */
1014 0xff8, /* src_mask */
1015 0xff8, /* dst_mask */
1016 FALSE), /* pcrel_offset */
1018 HOWTO32 (AARCH64_R (TLSIE_LD32_GOTTPREL_LO12_NC), /* type */
1020 2, /* size (0 = byte, 1 = short, 2 = long) */
1022 FALSE, /* pc_relative */
1024 complain_overflow_dont, /* complain_on_overflow */
1025 bfd_elf_generic_reloc, /* special_function */
1026 AARCH64_R_STR (TLSIE_LD32_GOTTPREL_LO12_NC), /* name */
1027 FALSE, /* partial_inplace */
1028 0xffc, /* src_mask */
1029 0xffc, /* dst_mask */
1030 FALSE), /* pcrel_offset */
1032 HOWTO (AARCH64_R (TLSIE_LD_GOTTPREL_PREL19), /* type */
1034 2, /* size (0 = byte, 1 = short, 2 = long) */
1036 FALSE, /* pc_relative */
1038 complain_overflow_dont, /* complain_on_overflow */
1039 bfd_elf_generic_reloc, /* special_function */
1040 AARCH64_R_STR (TLSIE_LD_GOTTPREL_PREL19), /* name */
1041 FALSE, /* partial_inplace */
1042 0x1ffffc, /* src_mask */
1043 0x1ffffc, /* dst_mask */
1044 FALSE), /* pcrel_offset */
1046 /* Unsigned 12 bit byte offset to module TLS base address. */
1047 HOWTO (AARCH64_R (TLSLD_ADD_DTPREL_LO12), /* type */
1049 2, /* size (0 = byte, 1 = short, 2 = long) */
1051 FALSE, /* pc_relative */
1053 complain_overflow_unsigned, /* complain_on_overflow */
1054 bfd_elf_generic_reloc, /* special_function */
1055 AARCH64_R_STR (TLSLD_ADD_DTPREL_LO12), /* name */
1056 FALSE, /* partial_inplace */
1057 0xfff, /* src_mask */
1058 0xfff, /* dst_mask */
1059 FALSE), /* pcrel_offset */
1061 /* No overflow check version of BFD_RELOC_AARCH64_TLSLD_ADD_DTPREL_LO12. */
1062 HOWTO (AARCH64_R (TLSLD_ADD_DTPREL_LO12_NC), /* type */
1064 2, /* size (0 = byte, 1 = short, 2 = long) */
1066 FALSE, /* pc_relative */
1068 complain_overflow_dont, /* complain_on_overflow */
1069 bfd_elf_generic_reloc, /* special_function */
1070 AARCH64_R_STR (TLSLD_ADD_DTPREL_LO12_NC), /* name */
1071 FALSE, /* partial_inplace */
1072 0xfff, /* src_mask */
1073 0xfff, /* dst_mask */
1074 FALSE), /* pcrel_offset */
1076 /* ADD: GOT offset G(S) & 0xff8 [no overflow check] */
1077 HOWTO (AARCH64_R (TLSLD_ADD_LO12_NC), /* type */
1079 2, /* size (0 = byte, 1 = short, 2 = long) */
1081 FALSE, /* pc_relative */
1083 complain_overflow_dont, /* complain_on_overflow */
1084 bfd_elf_generic_reloc, /* special_function */
1085 AARCH64_R_STR (TLSLD_ADD_LO12_NC), /* name */
1086 FALSE, /* partial_inplace */
1087 0xfff, /* src_mask */
1088 0xfff, /* dst_mask */
1089 FALSE), /* pcrel_offset */
1091 /* Get to the page for the GOT entry for the symbol
1092 (G(S) - P) using an ADRP instruction. */
1093 HOWTO (AARCH64_R (TLSLD_ADR_PAGE21), /* type */
1094 12, /* rightshift */
1095 2, /* size (0 = byte, 1 = short, 2 = long) */
1097 TRUE, /* pc_relative */
1099 complain_overflow_signed, /* complain_on_overflow */
1100 bfd_elf_generic_reloc, /* special_function */
1101 AARCH64_R_STR (TLSLD_ADR_PAGE21), /* name */
1102 FALSE, /* partial_inplace */
1103 0x1fffff, /* src_mask */
1104 0x1fffff, /* dst_mask */
1105 TRUE), /* pcrel_offset */
1107 HOWTO (AARCH64_R (TLSLD_ADR_PREL21), /* type */
1109 2, /* size (0 = byte, 1 = short, 2 = long) */
1111 TRUE, /* pc_relative */
1113 complain_overflow_signed, /* complain_on_overflow */
1114 bfd_elf_generic_reloc, /* special_function */
1115 AARCH64_R_STR (TLSLD_ADR_PREL21), /* name */
1116 FALSE, /* partial_inplace */
1117 0x1fffff, /* src_mask */
1118 0x1fffff, /* dst_mask */
1119 TRUE), /* pcrel_offset */
1121 HOWTO64 (AARCH64_R (TLSLE_MOVW_TPREL_G2), /* type */
1122 32, /* rightshift */
1123 2, /* size (0 = byte, 1 = short, 2 = long) */
1125 FALSE, /* pc_relative */
1127 complain_overflow_unsigned, /* complain_on_overflow */
1128 bfd_elf_generic_reloc, /* special_function */
1129 AARCH64_R_STR (TLSLE_MOVW_TPREL_G2), /* name */
1130 FALSE, /* partial_inplace */
1131 0xffff, /* src_mask */
1132 0xffff, /* dst_mask */
1133 FALSE), /* pcrel_offset */
1135 HOWTO (AARCH64_R (TLSLE_MOVW_TPREL_G1), /* type */
1136 16, /* rightshift */
1137 2, /* size (0 = byte, 1 = short, 2 = long) */
1139 FALSE, /* pc_relative */
1141 complain_overflow_dont, /* complain_on_overflow */
1142 bfd_elf_generic_reloc, /* special_function */
1143 AARCH64_R_STR (TLSLE_MOVW_TPREL_G1), /* name */
1144 FALSE, /* partial_inplace */
1145 0xffff, /* src_mask */
1146 0xffff, /* dst_mask */
1147 FALSE), /* pcrel_offset */
1149 HOWTO64 (AARCH64_R (TLSLE_MOVW_TPREL_G1_NC), /* type */
1150 16, /* rightshift */
1151 2, /* size (0 = byte, 1 = short, 2 = long) */
1153 FALSE, /* pc_relative */
1155 complain_overflow_dont, /* complain_on_overflow */
1156 bfd_elf_generic_reloc, /* special_function */
1157 AARCH64_R_STR (TLSLE_MOVW_TPREL_G1_NC), /* name */
1158 FALSE, /* partial_inplace */
1159 0xffff, /* src_mask */
1160 0xffff, /* dst_mask */
1161 FALSE), /* pcrel_offset */
1163 HOWTO (AARCH64_R (TLSLE_MOVW_TPREL_G0), /* type */
1165 2, /* size (0 = byte, 1 = short, 2 = long) */
1167 FALSE, /* pc_relative */
1169 complain_overflow_dont, /* complain_on_overflow */
1170 bfd_elf_generic_reloc, /* special_function */
1171 AARCH64_R_STR (TLSLE_MOVW_TPREL_G0), /* name */
1172 FALSE, /* partial_inplace */
1173 0xffff, /* src_mask */
1174 0xffff, /* dst_mask */
1175 FALSE), /* pcrel_offset */
1177 HOWTO (AARCH64_R (TLSLE_MOVW_TPREL_G0_NC), /* type */
1179 2, /* size (0 = byte, 1 = short, 2 = long) */
1181 FALSE, /* pc_relative */
1183 complain_overflow_dont, /* complain_on_overflow */
1184 bfd_elf_generic_reloc, /* special_function */
1185 AARCH64_R_STR (TLSLE_MOVW_TPREL_G0_NC), /* name */
1186 FALSE, /* partial_inplace */
1187 0xffff, /* src_mask */
1188 0xffff, /* dst_mask */
1189 FALSE), /* pcrel_offset */
1191 HOWTO (AARCH64_R (TLSLE_ADD_TPREL_HI12), /* type */
1192 12, /* rightshift */
1193 2, /* size (0 = byte, 1 = short, 2 = long) */
1195 FALSE, /* pc_relative */
1197 complain_overflow_unsigned, /* complain_on_overflow */
1198 bfd_elf_generic_reloc, /* special_function */
1199 AARCH64_R_STR (TLSLE_ADD_TPREL_HI12), /* name */
1200 FALSE, /* partial_inplace */
1201 0xfff, /* src_mask */
1202 0xfff, /* dst_mask */
1203 FALSE), /* pcrel_offset */
1205 HOWTO (AARCH64_R (TLSLE_ADD_TPREL_LO12), /* type */
1207 2, /* size (0 = byte, 1 = short, 2 = long) */
1209 FALSE, /* pc_relative */
1211 complain_overflow_unsigned, /* complain_on_overflow */
1212 bfd_elf_generic_reloc, /* special_function */
1213 AARCH64_R_STR (TLSLE_ADD_TPREL_LO12), /* name */
1214 FALSE, /* partial_inplace */
1215 0xfff, /* src_mask */
1216 0xfff, /* dst_mask */
1217 FALSE), /* pcrel_offset */
1219 HOWTO (AARCH64_R (TLSLE_ADD_TPREL_LO12_NC), /* type */
1221 2, /* size (0 = byte, 1 = short, 2 = long) */
1223 FALSE, /* pc_relative */
1225 complain_overflow_dont, /* complain_on_overflow */
1226 bfd_elf_generic_reloc, /* special_function */
1227 AARCH64_R_STR (TLSLE_ADD_TPREL_LO12_NC), /* name */
1228 FALSE, /* partial_inplace */
1229 0xfff, /* src_mask */
1230 0xfff, /* dst_mask */
1231 FALSE), /* pcrel_offset */
1233 HOWTO (AARCH64_R (TLSDESC_LD_PREL19), /* type */
1235 2, /* size (0 = byte, 1 = short, 2 = long) */
1237 TRUE, /* pc_relative */
1239 complain_overflow_dont, /* complain_on_overflow */
1240 bfd_elf_generic_reloc, /* special_function */
1241 AARCH64_R_STR (TLSDESC_LD_PREL19), /* name */
1242 FALSE, /* partial_inplace */
1243 0x0ffffe0, /* src_mask */
1244 0x0ffffe0, /* dst_mask */
1245 TRUE), /* pcrel_offset */
1247 HOWTO (AARCH64_R (TLSDESC_ADR_PREL21), /* type */
1249 2, /* size (0 = byte, 1 = short, 2 = long) */
1251 TRUE, /* pc_relative */
1253 complain_overflow_dont, /* complain_on_overflow */
1254 bfd_elf_generic_reloc, /* special_function */
1255 AARCH64_R_STR (TLSDESC_ADR_PREL21), /* name */
1256 FALSE, /* partial_inplace */
1257 0x1fffff, /* src_mask */
1258 0x1fffff, /* dst_mask */
1259 TRUE), /* pcrel_offset */
1261 /* Get to the page for the GOT entry for the symbol
1262 (G(S) - P) using an ADRP instruction. */
1263 HOWTO (AARCH64_R (TLSDESC_ADR_PAGE21), /* type */
1264 12, /* rightshift */
1265 2, /* size (0 = byte, 1 = short, 2 = long) */
1267 TRUE, /* pc_relative */
1269 complain_overflow_dont, /* complain_on_overflow */
1270 bfd_elf_generic_reloc, /* special_function */
1271 AARCH64_R_STR (TLSDESC_ADR_PAGE21), /* name */
1272 FALSE, /* partial_inplace */
1273 0x1fffff, /* src_mask */
1274 0x1fffff, /* dst_mask */
1275 TRUE), /* pcrel_offset */
1277 /* LD64: GOT offset G(S) & 0xff8. */
1278 HOWTO64 (AARCH64_R (TLSDESC_LD64_LO12_NC), /* type */
1280 2, /* size (0 = byte, 1 = short, 2 = long) */
1282 FALSE, /* pc_relative */
1284 complain_overflow_dont, /* complain_on_overflow */
1285 bfd_elf_generic_reloc, /* special_function */
1286 AARCH64_R_STR (TLSDESC_LD64_LO12_NC), /* name */
1287 FALSE, /* partial_inplace */
1288 0xff8, /* src_mask */
1289 0xff8, /* dst_mask */
1290 FALSE), /* pcrel_offset */
1292 /* LD32: GOT offset G(S) & 0xffc. */
1293 HOWTO32 (AARCH64_R (TLSDESC_LD32_LO12_NC), /* type */
1295 2, /* size (0 = byte, 1 = short, 2 = long) */
1297 FALSE, /* pc_relative */
1299 complain_overflow_dont, /* complain_on_overflow */
1300 bfd_elf_generic_reloc, /* special_function */
1301 AARCH64_R_STR (TLSDESC_LD32_LO12_NC), /* name */
1302 FALSE, /* partial_inplace */
1303 0xffc, /* src_mask */
1304 0xffc, /* dst_mask */
1305 FALSE), /* pcrel_offset */
1307 /* ADD: GOT offset G(S) & 0xfff. */
1308 HOWTO (AARCH64_R (TLSDESC_ADD_LO12_NC), /* type */
1310 2, /* size (0 = byte, 1 = short, 2 = long) */
1312 FALSE, /* pc_relative */
1314 complain_overflow_dont, /* complain_on_overflow */
1315 bfd_elf_generic_reloc, /* special_function */
1316 AARCH64_R_STR (TLSDESC_ADD_LO12_NC), /* name */
1317 FALSE, /* partial_inplace */
1318 0xfff, /* src_mask */
1319 0xfff, /* dst_mask */
1320 FALSE), /* pcrel_offset */
1322 HOWTO64 (AARCH64_R (TLSDESC_OFF_G1), /* type */
1323 16, /* rightshift */
1324 2, /* size (0 = byte, 1 = short, 2 = long) */
1326 FALSE, /* pc_relative */
1328 complain_overflow_dont, /* complain_on_overflow */
1329 bfd_elf_generic_reloc, /* special_function */
1330 AARCH64_R_STR (TLSDESC_OFF_G1), /* name */
1331 FALSE, /* partial_inplace */
1332 0xffff, /* src_mask */
1333 0xffff, /* dst_mask */
1334 FALSE), /* pcrel_offset */
1336 HOWTO64 (AARCH64_R (TLSDESC_OFF_G0_NC), /* type */
1338 2, /* size (0 = byte, 1 = short, 2 = long) */
1340 FALSE, /* pc_relative */
1342 complain_overflow_dont, /* complain_on_overflow */
1343 bfd_elf_generic_reloc, /* special_function */
1344 AARCH64_R_STR (TLSDESC_OFF_G0_NC), /* name */
1345 FALSE, /* partial_inplace */
1346 0xffff, /* src_mask */
1347 0xffff, /* dst_mask */
1348 FALSE), /* pcrel_offset */
1350 HOWTO64 (AARCH64_R (TLSDESC_LDR), /* type */
1352 2, /* size (0 = byte, 1 = short, 2 = long) */
1354 FALSE, /* pc_relative */
1356 complain_overflow_dont, /* complain_on_overflow */
1357 bfd_elf_generic_reloc, /* special_function */
1358 AARCH64_R_STR (TLSDESC_LDR), /* name */
1359 FALSE, /* partial_inplace */
1362 FALSE), /* pcrel_offset */
1364 HOWTO64 (AARCH64_R (TLSDESC_ADD), /* type */
1366 2, /* size (0 = byte, 1 = short, 2 = long) */
1368 FALSE, /* pc_relative */
1370 complain_overflow_dont, /* complain_on_overflow */
1371 bfd_elf_generic_reloc, /* special_function */
1372 AARCH64_R_STR (TLSDESC_ADD), /* name */
1373 FALSE, /* partial_inplace */
1376 FALSE), /* pcrel_offset */
1378 HOWTO (AARCH64_R (TLSDESC_CALL), /* type */
1380 2, /* size (0 = byte, 1 = short, 2 = long) */
1382 FALSE, /* pc_relative */
1384 complain_overflow_dont, /* complain_on_overflow */
1385 bfd_elf_generic_reloc, /* special_function */
1386 AARCH64_R_STR (TLSDESC_CALL), /* name */
1387 FALSE, /* partial_inplace */
1390 FALSE), /* pcrel_offset */
1392 HOWTO (AARCH64_R (COPY), /* type */
1394 2, /* size (0 = byte, 1 = short, 2 = long) */
1396 FALSE, /* pc_relative */
1398 complain_overflow_bitfield, /* complain_on_overflow */
1399 bfd_elf_generic_reloc, /* special_function */
1400 AARCH64_R_STR (COPY), /* name */
1401 TRUE, /* partial_inplace */
1402 0xffffffff, /* src_mask */
1403 0xffffffff, /* dst_mask */
1404 FALSE), /* pcrel_offset */
1406 HOWTO (AARCH64_R (GLOB_DAT), /* type */
1408 2, /* size (0 = byte, 1 = short, 2 = long) */
1410 FALSE, /* pc_relative */
1412 complain_overflow_bitfield, /* complain_on_overflow */
1413 bfd_elf_generic_reloc, /* special_function */
1414 AARCH64_R_STR (GLOB_DAT), /* name */
1415 TRUE, /* partial_inplace */
1416 0xffffffff, /* src_mask */
1417 0xffffffff, /* dst_mask */
1418 FALSE), /* pcrel_offset */
1420 HOWTO (AARCH64_R (JUMP_SLOT), /* type */
1422 2, /* size (0 = byte, 1 = short, 2 = long) */
1424 FALSE, /* pc_relative */
1426 complain_overflow_bitfield, /* complain_on_overflow */
1427 bfd_elf_generic_reloc, /* special_function */
1428 AARCH64_R_STR (JUMP_SLOT), /* name */
1429 TRUE, /* partial_inplace */
1430 0xffffffff, /* src_mask */
1431 0xffffffff, /* dst_mask */
1432 FALSE), /* pcrel_offset */
1434 HOWTO (AARCH64_R (RELATIVE), /* type */
1436 2, /* size (0 = byte, 1 = short, 2 = long) */
1438 FALSE, /* pc_relative */
1440 complain_overflow_bitfield, /* complain_on_overflow */
1441 bfd_elf_generic_reloc, /* special_function */
1442 AARCH64_R_STR (RELATIVE), /* name */
1443 TRUE, /* partial_inplace */
1444 ALL_ONES, /* src_mask */
1445 ALL_ONES, /* dst_mask */
1446 FALSE), /* pcrel_offset */
1448 HOWTO (AARCH64_R (TLS_DTPMOD), /* type */
1450 2, /* size (0 = byte, 1 = short, 2 = long) */
1452 FALSE, /* pc_relative */
1454 complain_overflow_dont, /* complain_on_overflow */
1455 bfd_elf_generic_reloc, /* special_function */
1457 AARCH64_R_STR (TLS_DTPMOD64), /* name */
1459 AARCH64_R_STR (TLS_DTPMOD), /* name */
1461 FALSE, /* partial_inplace */
1463 ALL_ONES, /* dst_mask */
1464 FALSE), /* pc_reloffset */
1466 HOWTO (AARCH64_R (TLS_DTPREL), /* type */
1468 2, /* size (0 = byte, 1 = short, 2 = long) */
1470 FALSE, /* pc_relative */
1472 complain_overflow_dont, /* complain_on_overflow */
1473 bfd_elf_generic_reloc, /* special_function */
1475 AARCH64_R_STR (TLS_DTPREL64), /* name */
1477 AARCH64_R_STR (TLS_DTPREL), /* name */
1479 FALSE, /* partial_inplace */
1481 ALL_ONES, /* dst_mask */
1482 FALSE), /* pcrel_offset */
1484 HOWTO (AARCH64_R (TLS_TPREL), /* type */
1486 2, /* size (0 = byte, 1 = short, 2 = long) */
1488 FALSE, /* pc_relative */
1490 complain_overflow_dont, /* complain_on_overflow */
1491 bfd_elf_generic_reloc, /* special_function */
1493 AARCH64_R_STR (TLS_TPREL64), /* name */
1495 AARCH64_R_STR (TLS_TPREL), /* name */
1497 FALSE, /* partial_inplace */
1499 ALL_ONES, /* dst_mask */
1500 FALSE), /* pcrel_offset */
1502 HOWTO (AARCH64_R (TLSDESC), /* type */
1504 2, /* size (0 = byte, 1 = short, 2 = long) */
1506 FALSE, /* pc_relative */
1508 complain_overflow_dont, /* complain_on_overflow */
1509 bfd_elf_generic_reloc, /* special_function */
1510 AARCH64_R_STR (TLSDESC), /* name */
1511 FALSE, /* partial_inplace */
1513 ALL_ONES, /* dst_mask */
1514 FALSE), /* pcrel_offset */
1516 HOWTO (AARCH64_R (IRELATIVE), /* type */
1518 2, /* size (0 = byte, 1 = short, 2 = long) */
1520 FALSE, /* pc_relative */
1522 complain_overflow_bitfield, /* complain_on_overflow */
1523 bfd_elf_generic_reloc, /* special_function */
1524 AARCH64_R_STR (IRELATIVE), /* name */
1525 FALSE, /* partial_inplace */
1527 ALL_ONES, /* dst_mask */
1528 FALSE), /* pcrel_offset */
1533 static reloc_howto_type elfNN_aarch64_howto_none =
1534 HOWTO (R_AARCH64_NONE, /* type */
1536 3, /* size (0 = byte, 1 = short, 2 = long) */
1538 FALSE, /* pc_relative */
1540 complain_overflow_dont,/* complain_on_overflow */
1541 bfd_elf_generic_reloc, /* special_function */
1542 "R_AARCH64_NONE", /* name */
1543 FALSE, /* partial_inplace */
1546 FALSE); /* pcrel_offset */
1548 /* Given HOWTO, return the bfd internal relocation enumerator. */
1550 static bfd_reloc_code_real_type
1551 elfNN_aarch64_bfd_reloc_from_howto (reloc_howto_type *howto)
1554 = (int) ARRAY_SIZE (elfNN_aarch64_howto_table);
1555 const ptrdiff_t offset
1556 = howto - elfNN_aarch64_howto_table;
1558 if (offset > 0 && offset < size - 1)
1559 return BFD_RELOC_AARCH64_RELOC_START + offset;
1561 if (howto == &elfNN_aarch64_howto_none)
1562 return BFD_RELOC_AARCH64_NONE;
1564 return BFD_RELOC_AARCH64_RELOC_START;
1567 /* Given R_TYPE, return the bfd internal relocation enumerator. */
1569 static bfd_reloc_code_real_type
1570 elfNN_aarch64_bfd_reloc_from_type (unsigned int r_type)
1572 static bfd_boolean initialized_p = FALSE;
1573 /* Indexed by R_TYPE, values are offsets in the howto_table. */
1574 static unsigned int offsets[R_AARCH64_end];
1576 if (initialized_p == FALSE)
1580 for (i = 1; i < ARRAY_SIZE (elfNN_aarch64_howto_table) - 1; ++i)
1581 if (elfNN_aarch64_howto_table[i].type != 0)
1582 offsets[elfNN_aarch64_howto_table[i].type] = i;
1584 initialized_p = TRUE;
1587 if (r_type == R_AARCH64_NONE || r_type == R_AARCH64_NULL)
1588 return BFD_RELOC_AARCH64_NONE;
1590 /* PR 17512: file: b371e70a. */
1591 if (r_type >= R_AARCH64_end)
1593 _bfd_error_handler (_("Invalid AArch64 reloc number: %d"), r_type);
1594 bfd_set_error (bfd_error_bad_value);
1595 return BFD_RELOC_AARCH64_NONE;
1598 return BFD_RELOC_AARCH64_RELOC_START + offsets[r_type];
1601 struct elf_aarch64_reloc_map
1603 bfd_reloc_code_real_type from;
1604 bfd_reloc_code_real_type to;
1607 /* Map bfd generic reloc to AArch64-specific reloc. */
1608 static const struct elf_aarch64_reloc_map elf_aarch64_reloc_map[] =
1610 {BFD_RELOC_NONE, BFD_RELOC_AARCH64_NONE},
1612 /* Basic data relocations. */
1613 {BFD_RELOC_CTOR, BFD_RELOC_AARCH64_NN},
1614 {BFD_RELOC_64, BFD_RELOC_AARCH64_64},
1615 {BFD_RELOC_32, BFD_RELOC_AARCH64_32},
1616 {BFD_RELOC_16, BFD_RELOC_AARCH64_16},
1617 {BFD_RELOC_64_PCREL, BFD_RELOC_AARCH64_64_PCREL},
1618 {BFD_RELOC_32_PCREL, BFD_RELOC_AARCH64_32_PCREL},
1619 {BFD_RELOC_16_PCREL, BFD_RELOC_AARCH64_16_PCREL},
1622 /* Given the bfd internal relocation enumerator in CODE, return the
1623 corresponding howto entry. */
1625 static reloc_howto_type *
1626 elfNN_aarch64_howto_from_bfd_reloc (bfd_reloc_code_real_type code)
1630 /* Convert bfd generic reloc to AArch64-specific reloc. */
1631 if (code < BFD_RELOC_AARCH64_RELOC_START
1632 || code > BFD_RELOC_AARCH64_RELOC_END)
1633 for (i = 0; i < ARRAY_SIZE (elf_aarch64_reloc_map); i++)
1634 if (elf_aarch64_reloc_map[i].from == code)
1636 code = elf_aarch64_reloc_map[i].to;
1640 if (code > BFD_RELOC_AARCH64_RELOC_START
1641 && code < BFD_RELOC_AARCH64_RELOC_END)
1642 if (elfNN_aarch64_howto_table[code - BFD_RELOC_AARCH64_RELOC_START].type)
1643 return &elfNN_aarch64_howto_table[code - BFD_RELOC_AARCH64_RELOC_START];
1645 if (code == BFD_RELOC_AARCH64_NONE)
1646 return &elfNN_aarch64_howto_none;
1651 static reloc_howto_type *
1652 elfNN_aarch64_howto_from_type (unsigned int r_type)
1654 bfd_reloc_code_real_type val;
1655 reloc_howto_type *howto;
1660 bfd_set_error (bfd_error_bad_value);
1665 if (r_type == R_AARCH64_NONE)
1666 return &elfNN_aarch64_howto_none;
1668 val = elfNN_aarch64_bfd_reloc_from_type (r_type);
1669 howto = elfNN_aarch64_howto_from_bfd_reloc (val);
1674 bfd_set_error (bfd_error_bad_value);
1679 elfNN_aarch64_info_to_howto (bfd *abfd ATTRIBUTE_UNUSED, arelent *bfd_reloc,
1680 Elf_Internal_Rela *elf_reloc)
1682 unsigned int r_type;
1684 r_type = ELFNN_R_TYPE (elf_reloc->r_info);
1685 bfd_reloc->howto = elfNN_aarch64_howto_from_type (r_type);
1688 static reloc_howto_type *
1689 elfNN_aarch64_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED,
1690 bfd_reloc_code_real_type code)
1692 reloc_howto_type *howto = elfNN_aarch64_howto_from_bfd_reloc (code);
1697 bfd_set_error (bfd_error_bad_value);
1701 static reloc_howto_type *
1702 elfNN_aarch64_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED,
1707 for (i = 1; i < ARRAY_SIZE (elfNN_aarch64_howto_table) - 1; ++i)
1708 if (elfNN_aarch64_howto_table[i].name != NULL
1709 && strcasecmp (elfNN_aarch64_howto_table[i].name, r_name) == 0)
1710 return &elfNN_aarch64_howto_table[i];
1715 #define TARGET_LITTLE_SYM aarch64_elfNN_le_vec
1716 #define TARGET_LITTLE_NAME "elfNN-littleaarch64"
1717 #define TARGET_BIG_SYM aarch64_elfNN_be_vec
1718 #define TARGET_BIG_NAME "elfNN-bigaarch64"
1720 /* The linker script knows the section names for placement.
1721 The entry_names are used to do simple name mangling on the stubs.
1722 Given a function name, and its type, the stub can be found. The
1723 name can be changed. The only requirement is the %s be present. */
1724 #define STUB_ENTRY_NAME "__%s_veneer"
1726 /* The name of the dynamic interpreter. This is put in the .interp
1728 #define ELF_DYNAMIC_INTERPRETER "/lib/ld.so.1"
1730 #define AARCH64_MAX_FWD_BRANCH_OFFSET \
1731 (((1 << 25) - 1) << 2)
1732 #define AARCH64_MAX_BWD_BRANCH_OFFSET \
1735 #define AARCH64_MAX_ADRP_IMM ((1 << 20) - 1)
1736 #define AARCH64_MIN_ADRP_IMM (-(1 << 20))
1739 aarch64_valid_for_adrp_p (bfd_vma value, bfd_vma place)
1741 bfd_signed_vma offset = (bfd_signed_vma) (PG (value) - PG (place)) >> 12;
1742 return offset <= AARCH64_MAX_ADRP_IMM && offset >= AARCH64_MIN_ADRP_IMM;
1746 aarch64_valid_branch_p (bfd_vma value, bfd_vma place)
1748 bfd_signed_vma offset = (bfd_signed_vma) (value - place);
1749 return (offset <= AARCH64_MAX_FWD_BRANCH_OFFSET
1750 && offset >= AARCH64_MAX_BWD_BRANCH_OFFSET);
1753 static const uint32_t aarch64_adrp_branch_stub [] =
1755 0x90000010, /* adrp ip0, X */
1756 /* R_AARCH64_ADR_HI21_PCREL(X) */
1757 0x91000210, /* add ip0, ip0, :lo12:X */
1758 /* R_AARCH64_ADD_ABS_LO12_NC(X) */
1759 0xd61f0200, /* br ip0 */
1762 static const uint32_t aarch64_long_branch_stub[] =
1765 0x58000090, /* ldr ip0, 1f */
1767 0x18000090, /* ldr wip0, 1f */
1769 0x10000011, /* adr ip1, #0 */
1770 0x8b110210, /* add ip0, ip0, ip1 */
1771 0xd61f0200, /* br ip0 */
1772 0x00000000, /* 1: .xword or .word
1773 R_AARCH64_PRELNN(X) + 12
1778 static const uint32_t aarch64_erratum_835769_stub[] =
1780 0x00000000, /* Placeholder for multiply accumulate. */
1781 0x14000000, /* b <label> */
1784 static const uint32_t aarch64_erratum_843419_stub[] =
1786 0x00000000, /* Placeholder for LDR instruction. */
1787 0x14000000, /* b <label> */
1790 /* Section name for stubs is the associated section name plus this
1792 #define STUB_SUFFIX ".stub"
1794 enum elf_aarch64_stub_type
1797 aarch64_stub_adrp_branch,
1798 aarch64_stub_long_branch,
1799 aarch64_stub_erratum_835769_veneer,
1800 aarch64_stub_erratum_843419_veneer,
1803 struct elf_aarch64_stub_hash_entry
1805 /* Base hash table entry structure. */
1806 struct bfd_hash_entry root;
1808 /* The stub section. */
1811 /* Offset within stub_sec of the beginning of this stub. */
1812 bfd_vma stub_offset;
1814 /* Given the symbol's value and its section we can determine its final
1815 value when building the stubs (so the stub knows where to jump). */
1816 bfd_vma target_value;
1817 asection *target_section;
1819 enum elf_aarch64_stub_type stub_type;
1821 /* The symbol table entry, if any, that this was derived from. */
1822 struct elf_aarch64_link_hash_entry *h;
1824 /* Destination symbol type */
1825 unsigned char st_type;
1827 /* Where this stub is being called from, or, in the case of combined
1828 stub sections, the first input section in the group. */
1831 /* The name for the local symbol at the start of this stub. The
1832 stub name in the hash table has to be unique; this does not, so
1833 it can be friendlier. */
1836 /* The instruction which caused this stub to be generated (only valid for
1837 erratum 835769 workaround stubs at present). */
1838 uint32_t veneered_insn;
1840 /* In an erratum 843419 workaround stub, the ADRP instruction offset. */
1841 bfd_vma adrp_offset;
1844 /* Used to build a map of a section. This is required for mixed-endian
1847 typedef struct elf_elf_section_map
1852 elf_aarch64_section_map;
1855 typedef struct _aarch64_elf_section_data
1857 struct bfd_elf_section_data elf;
1858 unsigned int mapcount;
1859 unsigned int mapsize;
1860 elf_aarch64_section_map *map;
1862 _aarch64_elf_section_data;
1864 #define elf_aarch64_section_data(sec) \
1865 ((_aarch64_elf_section_data *) elf_section_data (sec))
1867 /* The size of the thread control block which is defined to be two pointers. */
1868 #define TCB_SIZE (ARCH_SIZE/8)*2
1870 struct elf_aarch64_local_symbol
1872 unsigned int got_type;
1873 bfd_signed_vma got_refcount;
1876 /* Offset of the GOTPLT entry reserved for the TLS descriptor. The
1877 offset is from the end of the jump table and reserved entries
1880 The magic value (bfd_vma) -1 indicates that an offset has not be
1882 bfd_vma tlsdesc_got_jump_table_offset;
1885 struct elf_aarch64_obj_tdata
1887 struct elf_obj_tdata root;
1889 /* local symbol descriptors */
1890 struct elf_aarch64_local_symbol *locals;
1892 /* Zero to warn when linking objects with incompatible enum sizes. */
1893 int no_enum_size_warning;
1895 /* Zero to warn when linking objects with incompatible wchar_t sizes. */
1896 int no_wchar_size_warning;
1899 #define elf_aarch64_tdata(bfd) \
1900 ((struct elf_aarch64_obj_tdata *) (bfd)->tdata.any)
1902 #define elf_aarch64_locals(bfd) (elf_aarch64_tdata (bfd)->locals)
1904 #define is_aarch64_elf(bfd) \
1905 (bfd_get_flavour (bfd) == bfd_target_elf_flavour \
1906 && elf_tdata (bfd) != NULL \
1907 && elf_object_id (bfd) == AARCH64_ELF_DATA)
1910 elfNN_aarch64_mkobject (bfd *abfd)
1912 return bfd_elf_allocate_object (abfd, sizeof (struct elf_aarch64_obj_tdata),
1916 #define elf_aarch64_hash_entry(ent) \
1917 ((struct elf_aarch64_link_hash_entry *)(ent))
1919 #define GOT_UNKNOWN 0
1920 #define GOT_NORMAL 1
1921 #define GOT_TLS_GD 2
1922 #define GOT_TLS_IE 4
1923 #define GOT_TLSDESC_GD 8
1925 #define GOT_TLS_GD_ANY_P(type) ((type & GOT_TLS_GD) || (type & GOT_TLSDESC_GD))
1927 /* AArch64 ELF linker hash entry. */
1928 struct elf_aarch64_link_hash_entry
1930 struct elf_link_hash_entry root;
1932 /* Track dynamic relocs copied for this symbol. */
1933 struct elf_dyn_relocs *dyn_relocs;
1935 /* Since PLT entries have variable size, we need to record the
1936 index into .got.plt instead of recomputing it from the PLT
1938 bfd_signed_vma plt_got_offset;
1940 /* Bit mask representing the type of GOT entry(s) if any required by
1942 unsigned int got_type;
1944 /* A pointer to the most recently used stub hash entry against this
1946 struct elf_aarch64_stub_hash_entry *stub_cache;
1948 /* Offset of the GOTPLT entry reserved for the TLS descriptor. The offset
1949 is from the end of the jump table and reserved entries within the PLTGOT.
1951 The magic value (bfd_vma) -1 indicates that an offset has not
1953 bfd_vma tlsdesc_got_jump_table_offset;
1957 elfNN_aarch64_symbol_got_type (struct elf_link_hash_entry *h,
1959 unsigned long r_symndx)
1962 return elf_aarch64_hash_entry (h)->got_type;
1964 if (! elf_aarch64_locals (abfd))
1967 return elf_aarch64_locals (abfd)[r_symndx].got_type;
1970 /* Get the AArch64 elf linker hash table from a link_info structure. */
1971 #define elf_aarch64_hash_table(info) \
1972 ((struct elf_aarch64_link_hash_table *) ((info)->hash))
1974 #define aarch64_stub_hash_lookup(table, string, create, copy) \
1975 ((struct elf_aarch64_stub_hash_entry *) \
1976 bfd_hash_lookup ((table), (string), (create), (copy)))
1978 /* AArch64 ELF linker hash table. */
1979 struct elf_aarch64_link_hash_table
1981 /* The main hash table. */
1982 struct elf_link_hash_table root;
1984 /* Nonzero to force PIC branch veneers. */
1987 /* Fix erratum 835769. */
1988 int fix_erratum_835769;
1990 /* Fix erratum 843419. */
1991 int fix_erratum_843419;
1993 /* Enable ADRP->ADR rewrite for erratum 843419 workaround. */
1994 int fix_erratum_843419_adr;
1996 /* The number of bytes in the initial entry in the PLT. */
1997 bfd_size_type plt_header_size;
1999 /* The number of bytes in the subsequent PLT etries. */
2000 bfd_size_type plt_entry_size;
2002 /* Short-cuts to get to dynamic linker sections. */
2006 /* Small local sym cache. */
2007 struct sym_cache sym_cache;
2009 /* For convenience in allocate_dynrelocs. */
2012 /* The amount of space used by the reserved portion of the sgotplt
2013 section, plus whatever space is used by the jump slots. */
2014 bfd_vma sgotplt_jump_table_size;
2016 /* The stub hash table. */
2017 struct bfd_hash_table stub_hash_table;
2019 /* Linker stub bfd. */
2022 /* Linker call-backs. */
2023 asection *(*add_stub_section) (const char *, asection *);
2024 void (*layout_sections_again) (void);
2026 /* Array to keep track of which stub sections have been created, and
2027 information on stub grouping. */
2030 /* This is the section to which stubs in the group will be
2033 /* The stub section. */
2037 /* Assorted information used by elfNN_aarch64_size_stubs. */
2038 unsigned int bfd_count;
2040 asection **input_list;
2042 /* The offset into splt of the PLT entry for the TLS descriptor
2043 resolver. Special values are 0, if not necessary (or not found
2044 to be necessary yet), and -1 if needed but not determined
2046 bfd_vma tlsdesc_plt;
2048 /* The GOT offset for the lazy trampoline. Communicated to the
2049 loader via DT_TLSDESC_GOT. The magic value (bfd_vma) -1
2050 indicates an offset is not allocated. */
2051 bfd_vma dt_tlsdesc_got;
2053 /* Used by local STT_GNU_IFUNC symbols. */
2054 htab_t loc_hash_table;
2055 void * loc_hash_memory;
2058 /* Create an entry in an AArch64 ELF linker hash table. */
2060 static struct bfd_hash_entry *
2061 elfNN_aarch64_link_hash_newfunc (struct bfd_hash_entry *entry,
2062 struct bfd_hash_table *table,
2065 struct elf_aarch64_link_hash_entry *ret =
2066 (struct elf_aarch64_link_hash_entry *) entry;
2068 /* Allocate the structure if it has not already been allocated by a
2071 ret = bfd_hash_allocate (table,
2072 sizeof (struct elf_aarch64_link_hash_entry));
2074 return (struct bfd_hash_entry *) ret;
2076 /* Call the allocation method of the superclass. */
2077 ret = ((struct elf_aarch64_link_hash_entry *)
2078 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry *) ret,
2082 ret->dyn_relocs = NULL;
2083 ret->got_type = GOT_UNKNOWN;
2084 ret->plt_got_offset = (bfd_vma) - 1;
2085 ret->stub_cache = NULL;
2086 ret->tlsdesc_got_jump_table_offset = (bfd_vma) - 1;
2089 return (struct bfd_hash_entry *) ret;
2092 /* Initialize an entry in the stub hash table. */
2094 static struct bfd_hash_entry *
2095 stub_hash_newfunc (struct bfd_hash_entry *entry,
2096 struct bfd_hash_table *table, const char *string)
2098 /* Allocate the structure if it has not already been allocated by a
2102 entry = bfd_hash_allocate (table,
2104 elf_aarch64_stub_hash_entry));
2109 /* Call the allocation method of the superclass. */
2110 entry = bfd_hash_newfunc (entry, table, string);
2113 struct elf_aarch64_stub_hash_entry *eh;
2115 /* Initialize the local fields. */
2116 eh = (struct elf_aarch64_stub_hash_entry *) entry;
2117 eh->adrp_offset = 0;
2118 eh->stub_sec = NULL;
2119 eh->stub_offset = 0;
2120 eh->target_value = 0;
2121 eh->target_section = NULL;
2122 eh->stub_type = aarch64_stub_none;
2130 /* Compute a hash of a local hash entry. We use elf_link_hash_entry
2131 for local symbol so that we can handle local STT_GNU_IFUNC symbols
2132 as global symbol. We reuse indx and dynstr_index for local symbol
2133 hash since they aren't used by global symbols in this backend. */
2136 elfNN_aarch64_local_htab_hash (const void *ptr)
2138 struct elf_link_hash_entry *h
2139 = (struct elf_link_hash_entry *) ptr;
2140 return ELF_LOCAL_SYMBOL_HASH (h->indx, h->dynstr_index);
2143 /* Compare local hash entries. */
2146 elfNN_aarch64_local_htab_eq (const void *ptr1, const void *ptr2)
2148 struct elf_link_hash_entry *h1
2149 = (struct elf_link_hash_entry *) ptr1;
2150 struct elf_link_hash_entry *h2
2151 = (struct elf_link_hash_entry *) ptr2;
2153 return h1->indx == h2->indx && h1->dynstr_index == h2->dynstr_index;
2156 /* Find and/or create a hash entry for local symbol. */
2158 static struct elf_link_hash_entry *
2159 elfNN_aarch64_get_local_sym_hash (struct elf_aarch64_link_hash_table *htab,
2160 bfd *abfd, const Elf_Internal_Rela *rel,
2163 struct elf_aarch64_link_hash_entry e, *ret;
2164 asection *sec = abfd->sections;
2165 hashval_t h = ELF_LOCAL_SYMBOL_HASH (sec->id,
2166 ELFNN_R_SYM (rel->r_info));
2169 e.root.indx = sec->id;
2170 e.root.dynstr_index = ELFNN_R_SYM (rel->r_info);
2171 slot = htab_find_slot_with_hash (htab->loc_hash_table, &e, h,
2172 create ? INSERT : NO_INSERT);
2179 ret = (struct elf_aarch64_link_hash_entry *) *slot;
2183 ret = (struct elf_aarch64_link_hash_entry *)
2184 objalloc_alloc ((struct objalloc *) htab->loc_hash_memory,
2185 sizeof (struct elf_aarch64_link_hash_entry));
2188 memset (ret, 0, sizeof (*ret));
2189 ret->root.indx = sec->id;
2190 ret->root.dynstr_index = ELFNN_R_SYM (rel->r_info);
2191 ret->root.dynindx = -1;
2197 /* Copy the extra info we tack onto an elf_link_hash_entry. */
2200 elfNN_aarch64_copy_indirect_symbol (struct bfd_link_info *info,
2201 struct elf_link_hash_entry *dir,
2202 struct elf_link_hash_entry *ind)
2204 struct elf_aarch64_link_hash_entry *edir, *eind;
2206 edir = (struct elf_aarch64_link_hash_entry *) dir;
2207 eind = (struct elf_aarch64_link_hash_entry *) ind;
2209 if (eind->dyn_relocs != NULL)
2211 if (edir->dyn_relocs != NULL)
2213 struct elf_dyn_relocs **pp;
2214 struct elf_dyn_relocs *p;
2216 /* Add reloc counts against the indirect sym to the direct sym
2217 list. Merge any entries against the same section. */
2218 for (pp = &eind->dyn_relocs; (p = *pp) != NULL;)
2220 struct elf_dyn_relocs *q;
2222 for (q = edir->dyn_relocs; q != NULL; q = q->next)
2223 if (q->sec == p->sec)
2225 q->pc_count += p->pc_count;
2226 q->count += p->count;
2233 *pp = edir->dyn_relocs;
2236 edir->dyn_relocs = eind->dyn_relocs;
2237 eind->dyn_relocs = NULL;
2240 if (ind->root.type == bfd_link_hash_indirect)
2242 /* Copy over PLT info. */
2243 if (dir->got.refcount <= 0)
2245 edir->got_type = eind->got_type;
2246 eind->got_type = GOT_UNKNOWN;
2250 _bfd_elf_link_hash_copy_indirect (info, dir, ind);
2253 /* Destroy an AArch64 elf linker hash table. */
2256 elfNN_aarch64_link_hash_table_free (bfd *obfd)
2258 struct elf_aarch64_link_hash_table *ret
2259 = (struct elf_aarch64_link_hash_table *) obfd->link.hash;
2261 if (ret->loc_hash_table)
2262 htab_delete (ret->loc_hash_table);
2263 if (ret->loc_hash_memory)
2264 objalloc_free ((struct objalloc *) ret->loc_hash_memory);
2266 bfd_hash_table_free (&ret->stub_hash_table);
2267 _bfd_elf_link_hash_table_free (obfd);
2270 /* Create an AArch64 elf linker hash table. */
2272 static struct bfd_link_hash_table *
2273 elfNN_aarch64_link_hash_table_create (bfd *abfd)
2275 struct elf_aarch64_link_hash_table *ret;
2276 bfd_size_type amt = sizeof (struct elf_aarch64_link_hash_table);
2278 ret = bfd_zmalloc (amt);
2282 if (!_bfd_elf_link_hash_table_init
2283 (&ret->root, abfd, elfNN_aarch64_link_hash_newfunc,
2284 sizeof (struct elf_aarch64_link_hash_entry), AARCH64_ELF_DATA))
2290 ret->plt_header_size = PLT_ENTRY_SIZE;
2291 ret->plt_entry_size = PLT_SMALL_ENTRY_SIZE;
2293 ret->dt_tlsdesc_got = (bfd_vma) - 1;
2295 if (!bfd_hash_table_init (&ret->stub_hash_table, stub_hash_newfunc,
2296 sizeof (struct elf_aarch64_stub_hash_entry)))
2298 _bfd_elf_link_hash_table_free (abfd);
2302 ret->loc_hash_table = htab_try_create (1024,
2303 elfNN_aarch64_local_htab_hash,
2304 elfNN_aarch64_local_htab_eq,
2306 ret->loc_hash_memory = objalloc_create ();
2307 if (!ret->loc_hash_table || !ret->loc_hash_memory)
2309 elfNN_aarch64_link_hash_table_free (abfd);
2312 ret->root.root.hash_table_free = elfNN_aarch64_link_hash_table_free;
2314 return &ret->root.root;
2318 aarch64_relocate (unsigned int r_type, bfd *input_bfd, asection *input_section,
2319 bfd_vma offset, bfd_vma value)
2321 reloc_howto_type *howto;
2324 howto = elfNN_aarch64_howto_from_type (r_type);
2325 place = (input_section->output_section->vma + input_section->output_offset
2328 r_type = elfNN_aarch64_bfd_reloc_from_type (r_type);
2329 value = _bfd_aarch64_elf_resolve_relocation (r_type, place, value, 0, FALSE);
2330 return _bfd_aarch64_elf_put_addend (input_bfd,
2331 input_section->contents + offset, r_type,
2335 static enum elf_aarch64_stub_type
2336 aarch64_select_branch_stub (bfd_vma value, bfd_vma place)
2338 if (aarch64_valid_for_adrp_p (value, place))
2339 return aarch64_stub_adrp_branch;
2340 return aarch64_stub_long_branch;
2343 /* Determine the type of stub needed, if any, for a call. */
2345 static enum elf_aarch64_stub_type
2346 aarch64_type_of_stub (struct bfd_link_info *info,
2347 asection *input_sec,
2348 const Elf_Internal_Rela *rel,
2350 unsigned char st_type,
2351 struct elf_aarch64_link_hash_entry *hash,
2352 bfd_vma destination)
2355 bfd_signed_vma branch_offset;
2356 unsigned int r_type;
2357 struct elf_aarch64_link_hash_table *globals;
2358 enum elf_aarch64_stub_type stub_type = aarch64_stub_none;
2359 bfd_boolean via_plt_p;
2361 if (st_type != STT_FUNC
2362 && (sym_sec != bfd_abs_section_ptr))
2365 globals = elf_aarch64_hash_table (info);
2366 via_plt_p = (globals->root.splt != NULL && hash != NULL
2367 && hash->root.plt.offset != (bfd_vma) - 1);
2368 /* Make sure call to plt stub can fit into the branch range. */
2370 destination = (globals->root.splt->output_section->vma
2371 + globals->root.splt->output_offset
2372 + hash->root.plt.offset);
2374 /* Determine where the call point is. */
2375 location = (input_sec->output_offset
2376 + input_sec->output_section->vma + rel->r_offset);
2378 branch_offset = (bfd_signed_vma) (destination - location);
2380 r_type = ELFNN_R_TYPE (rel->r_info);
2382 /* We don't want to redirect any old unconditional jump in this way,
2383 only one which is being used for a sibcall, where it is
2384 acceptable for the IP0 and IP1 registers to be clobbered. */
2385 if ((r_type == AARCH64_R (CALL26) || r_type == AARCH64_R (JUMP26))
2386 && (branch_offset > AARCH64_MAX_FWD_BRANCH_OFFSET
2387 || branch_offset < AARCH64_MAX_BWD_BRANCH_OFFSET))
2389 stub_type = aarch64_stub_long_branch;
2395 /* Build a name for an entry in the stub hash table. */
2398 elfNN_aarch64_stub_name (const asection *input_section,
2399 const asection *sym_sec,
2400 const struct elf_aarch64_link_hash_entry *hash,
2401 const Elf_Internal_Rela *rel)
2408 len = 8 + 1 + strlen (hash->root.root.root.string) + 1 + 16 + 1;
2409 stub_name = bfd_malloc (len);
2410 if (stub_name != NULL)
2411 snprintf (stub_name, len, "%08x_%s+%" BFD_VMA_FMT "x",
2412 (unsigned int) input_section->id,
2413 hash->root.root.root.string,
2418 len = 8 + 1 + 8 + 1 + 8 + 1 + 16 + 1;
2419 stub_name = bfd_malloc (len);
2420 if (stub_name != NULL)
2421 snprintf (stub_name, len, "%08x_%x:%x+%" BFD_VMA_FMT "x",
2422 (unsigned int) input_section->id,
2423 (unsigned int) sym_sec->id,
2424 (unsigned int) ELFNN_R_SYM (rel->r_info),
2431 /* Look up an entry in the stub hash. Stub entries are cached because
2432 creating the stub name takes a bit of time. */
2434 static struct elf_aarch64_stub_hash_entry *
2435 elfNN_aarch64_get_stub_entry (const asection *input_section,
2436 const asection *sym_sec,
2437 struct elf_link_hash_entry *hash,
2438 const Elf_Internal_Rela *rel,
2439 struct elf_aarch64_link_hash_table *htab)
2441 struct elf_aarch64_stub_hash_entry *stub_entry;
2442 struct elf_aarch64_link_hash_entry *h =
2443 (struct elf_aarch64_link_hash_entry *) hash;
2444 const asection *id_sec;
2446 if ((input_section->flags & SEC_CODE) == 0)
2449 /* If this input section is part of a group of sections sharing one
2450 stub section, then use the id of the first section in the group.
2451 Stub names need to include a section id, as there may well be
2452 more than one stub used to reach say, printf, and we need to
2453 distinguish between them. */
2454 id_sec = htab->stub_group[input_section->id].link_sec;
2456 if (h != NULL && h->stub_cache != NULL
2457 && h->stub_cache->h == h && h->stub_cache->id_sec == id_sec)
2459 stub_entry = h->stub_cache;
2465 stub_name = elfNN_aarch64_stub_name (id_sec, sym_sec, h, rel);
2466 if (stub_name == NULL)
2469 stub_entry = aarch64_stub_hash_lookup (&htab->stub_hash_table,
2470 stub_name, FALSE, FALSE);
2472 h->stub_cache = stub_entry;
2481 /* Create a stub section. */
2484 _bfd_aarch64_create_stub_section (asection *section,
2485 struct elf_aarch64_link_hash_table *htab)
2491 namelen = strlen (section->name);
2492 len = namelen + sizeof (STUB_SUFFIX);
2493 s_name = bfd_alloc (htab->stub_bfd, len);
2497 memcpy (s_name, section->name, namelen);
2498 memcpy (s_name + namelen, STUB_SUFFIX, sizeof (STUB_SUFFIX));
2499 return (*htab->add_stub_section) (s_name, section);
2503 /* Find or create a stub section for a link section.
2505 Fix or create the stub section used to collect stubs attached to
2506 the specified link section. */
2509 _bfd_aarch64_get_stub_for_link_section (asection *link_section,
2510 struct elf_aarch64_link_hash_table *htab)
2512 if (htab->stub_group[link_section->id].stub_sec == NULL)
2513 htab->stub_group[link_section->id].stub_sec
2514 = _bfd_aarch64_create_stub_section (link_section, htab);
2515 return htab->stub_group[link_section->id].stub_sec;
2519 /* Find or create a stub section in the stub group for an input
2523 _bfd_aarch64_create_or_find_stub_sec (asection *section,
2524 struct elf_aarch64_link_hash_table *htab)
2526 asection *link_sec = htab->stub_group[section->id].link_sec;
2527 return _bfd_aarch64_get_stub_for_link_section (link_sec, htab);
2531 /* Add a new stub entry in the stub group associated with an input
2532 section to the stub hash. Not all fields of the new stub entry are
2535 static struct elf_aarch64_stub_hash_entry *
2536 _bfd_aarch64_add_stub_entry_in_group (const char *stub_name,
2538 struct elf_aarch64_link_hash_table *htab)
2542 struct elf_aarch64_stub_hash_entry *stub_entry;
2544 link_sec = htab->stub_group[section->id].link_sec;
2545 stub_sec = _bfd_aarch64_create_or_find_stub_sec (section, htab);
2547 /* Enter this entry into the linker stub hash table. */
2548 stub_entry = aarch64_stub_hash_lookup (&htab->stub_hash_table, stub_name,
2550 if (stub_entry == NULL)
2552 (*_bfd_error_handler) (_("%s: cannot create stub entry %s"),
2553 section->owner, stub_name);
2557 stub_entry->stub_sec = stub_sec;
2558 stub_entry->stub_offset = 0;
2559 stub_entry->id_sec = link_sec;
2564 /* Add a new stub entry in the final stub section to the stub hash.
2565 Not all fields of the new stub entry are initialised. */
2567 static struct elf_aarch64_stub_hash_entry *
2568 _bfd_aarch64_add_stub_entry_after (const char *stub_name,
2569 asection *link_section,
2570 struct elf_aarch64_link_hash_table *htab)
2573 struct elf_aarch64_stub_hash_entry *stub_entry;
2575 stub_sec = _bfd_aarch64_get_stub_for_link_section (link_section, htab);
2576 stub_entry = aarch64_stub_hash_lookup (&htab->stub_hash_table, stub_name,
2578 if (stub_entry == NULL)
2580 (*_bfd_error_handler) (_("cannot create stub entry %s"), stub_name);
2584 stub_entry->stub_sec = stub_sec;
2585 stub_entry->stub_offset = 0;
2586 stub_entry->id_sec = link_section;
2593 aarch64_build_one_stub (struct bfd_hash_entry *gen_entry,
2594 void *in_arg ATTRIBUTE_UNUSED)
2596 struct elf_aarch64_stub_hash_entry *stub_entry;
2601 bfd_vma veneered_insn_loc;
2602 bfd_vma veneer_entry_loc;
2603 bfd_signed_vma branch_offset = 0;
2604 unsigned int template_size;
2605 const uint32_t *template;
2608 /* Massage our args to the form they really have. */
2609 stub_entry = (struct elf_aarch64_stub_hash_entry *) gen_entry;
2611 stub_sec = stub_entry->stub_sec;
2613 /* Make a note of the offset within the stubs for this entry. */
2614 stub_entry->stub_offset = stub_sec->size;
2615 loc = stub_sec->contents + stub_entry->stub_offset;
2617 stub_bfd = stub_sec->owner;
2619 /* This is the address of the stub destination. */
2620 sym_value = (stub_entry->target_value
2621 + stub_entry->target_section->output_offset
2622 + stub_entry->target_section->output_section->vma);
2624 if (stub_entry->stub_type == aarch64_stub_long_branch)
2626 bfd_vma place = (stub_entry->stub_offset + stub_sec->output_section->vma
2627 + stub_sec->output_offset);
2629 /* See if we can relax the stub. */
2630 if (aarch64_valid_for_adrp_p (sym_value, place))
2631 stub_entry->stub_type = aarch64_select_branch_stub (sym_value, place);
2634 switch (stub_entry->stub_type)
2636 case aarch64_stub_adrp_branch:
2637 template = aarch64_adrp_branch_stub;
2638 template_size = sizeof (aarch64_adrp_branch_stub);
2640 case aarch64_stub_long_branch:
2641 template = aarch64_long_branch_stub;
2642 template_size = sizeof (aarch64_long_branch_stub);
2644 case aarch64_stub_erratum_835769_veneer:
2645 template = aarch64_erratum_835769_stub;
2646 template_size = sizeof (aarch64_erratum_835769_stub);
2648 case aarch64_stub_erratum_843419_veneer:
2649 template = aarch64_erratum_843419_stub;
2650 template_size = sizeof (aarch64_erratum_843419_stub);
2656 for (i = 0; i < (template_size / sizeof template[0]); i++)
2658 bfd_putl32 (template[i], loc);
2662 template_size = (template_size + 7) & ~7;
2663 stub_sec->size += template_size;
2665 switch (stub_entry->stub_type)
2667 case aarch64_stub_adrp_branch:
2668 if (aarch64_relocate (AARCH64_R (ADR_PREL_PG_HI21), stub_bfd, stub_sec,
2669 stub_entry->stub_offset, sym_value))
2670 /* The stub would not have been relaxed if the offset was out
2674 if (aarch64_relocate (AARCH64_R (ADD_ABS_LO12_NC), stub_bfd, stub_sec,
2675 stub_entry->stub_offset + 4, sym_value))
2679 case aarch64_stub_long_branch:
2680 /* We want the value relative to the address 12 bytes back from the
2682 if (aarch64_relocate (AARCH64_R (PRELNN), stub_bfd, stub_sec,
2683 stub_entry->stub_offset + 16, sym_value + 12))
2687 case aarch64_stub_erratum_835769_veneer:
2688 veneered_insn_loc = stub_entry->target_section->output_section->vma
2689 + stub_entry->target_section->output_offset
2690 + stub_entry->target_value;
2691 veneer_entry_loc = stub_entry->stub_sec->output_section->vma
2692 + stub_entry->stub_sec->output_offset
2693 + stub_entry->stub_offset;
2694 branch_offset = veneered_insn_loc - veneer_entry_loc;
2695 branch_offset >>= 2;
2696 branch_offset &= 0x3ffffff;
2697 bfd_putl32 (stub_entry->veneered_insn,
2698 stub_sec->contents + stub_entry->stub_offset);
2699 bfd_putl32 (template[1] | branch_offset,
2700 stub_sec->contents + stub_entry->stub_offset + 4);
2703 case aarch64_stub_erratum_843419_veneer:
2704 if (aarch64_relocate (AARCH64_R (JUMP26), stub_bfd, stub_sec,
2705 stub_entry->stub_offset + 4, sym_value + 4))
2716 /* As above, but don't actually build the stub. Just bump offset so
2717 we know stub section sizes. */
2720 aarch64_size_one_stub (struct bfd_hash_entry *gen_entry,
2721 void *in_arg ATTRIBUTE_UNUSED)
2723 struct elf_aarch64_stub_hash_entry *stub_entry;
2726 /* Massage our args to the form they really have. */
2727 stub_entry = (struct elf_aarch64_stub_hash_entry *) gen_entry;
2729 switch (stub_entry->stub_type)
2731 case aarch64_stub_adrp_branch:
2732 size = sizeof (aarch64_adrp_branch_stub);
2734 case aarch64_stub_long_branch:
2735 size = sizeof (aarch64_long_branch_stub);
2737 case aarch64_stub_erratum_835769_veneer:
2738 size = sizeof (aarch64_erratum_835769_stub);
2740 case aarch64_stub_erratum_843419_veneer:
2741 size = sizeof (aarch64_erratum_843419_stub);
2747 size = (size + 7) & ~7;
2748 stub_entry->stub_sec->size += size;
2752 /* External entry points for sizing and building linker stubs. */
2754 /* Set up various things so that we can make a list of input sections
2755 for each output section included in the link. Returns -1 on error,
2756 0 when no stubs will be needed, and 1 on success. */
2759 elfNN_aarch64_setup_section_lists (bfd *output_bfd,
2760 struct bfd_link_info *info)
2763 unsigned int bfd_count;
2764 int top_id, top_index;
2766 asection **input_list, **list;
2768 struct elf_aarch64_link_hash_table *htab =
2769 elf_aarch64_hash_table (info);
2771 if (!is_elf_hash_table (htab))
2774 /* Count the number of input BFDs and find the top input section id. */
2775 for (input_bfd = info->input_bfds, bfd_count = 0, top_id = 0;
2776 input_bfd != NULL; input_bfd = input_bfd->link.next)
2779 for (section = input_bfd->sections;
2780 section != NULL; section = section->next)
2782 if (top_id < section->id)
2783 top_id = section->id;
2786 htab->bfd_count = bfd_count;
2788 amt = sizeof (struct map_stub) * (top_id + 1);
2789 htab->stub_group = bfd_zmalloc (amt);
2790 if (htab->stub_group == NULL)
2793 /* We can't use output_bfd->section_count here to find the top output
2794 section index as some sections may have been removed, and
2795 _bfd_strip_section_from_output doesn't renumber the indices. */
2796 for (section = output_bfd->sections, top_index = 0;
2797 section != NULL; section = section->next)
2799 if (top_index < section->index)
2800 top_index = section->index;
2803 htab->top_index = top_index;
2804 amt = sizeof (asection *) * (top_index + 1);
2805 input_list = bfd_malloc (amt);
2806 htab->input_list = input_list;
2807 if (input_list == NULL)
2810 /* For sections we aren't interested in, mark their entries with a
2811 value we can check later. */
2812 list = input_list + top_index;
2814 *list = bfd_abs_section_ptr;
2815 while (list-- != input_list);
2817 for (section = output_bfd->sections;
2818 section != NULL; section = section->next)
2820 if ((section->flags & SEC_CODE) != 0)
2821 input_list[section->index] = NULL;
2827 /* Used by elfNN_aarch64_next_input_section and group_sections. */
2828 #define PREV_SEC(sec) (htab->stub_group[(sec)->id].link_sec)
2830 /* The linker repeatedly calls this function for each input section,
2831 in the order that input sections are linked into output sections.
2832 Build lists of input sections to determine groupings between which
2833 we may insert linker stubs. */
2836 elfNN_aarch64_next_input_section (struct bfd_link_info *info, asection *isec)
2838 struct elf_aarch64_link_hash_table *htab =
2839 elf_aarch64_hash_table (info);
2841 if (isec->output_section->index <= htab->top_index)
2843 asection **list = htab->input_list + isec->output_section->index;
2845 if (*list != bfd_abs_section_ptr)
2847 /* Steal the link_sec pointer for our list. */
2848 /* This happens to make the list in reverse order,
2849 which is what we want. */
2850 PREV_SEC (isec) = *list;
2856 /* See whether we can group stub sections together. Grouping stub
2857 sections may result in fewer stubs. More importantly, we need to
2858 put all .init* and .fini* stubs at the beginning of the .init or
2859 .fini output sections respectively, because glibc splits the
2860 _init and _fini functions into multiple parts. Putting a stub in
2861 the middle of a function is not a good idea. */
2864 group_sections (struct elf_aarch64_link_hash_table *htab,
2865 bfd_size_type stub_group_size,
2866 bfd_boolean stubs_always_before_branch)
2868 asection **list = htab->input_list + htab->top_index;
2872 asection *tail = *list;
2874 if (tail == bfd_abs_section_ptr)
2877 while (tail != NULL)
2881 bfd_size_type total;
2885 while ((prev = PREV_SEC (curr)) != NULL
2886 && ((total += curr->output_offset - prev->output_offset)
2890 /* OK, the size from the start of CURR to the end is less
2891 than stub_group_size and thus can be handled by one stub
2892 section. (Or the tail section is itself larger than
2893 stub_group_size, in which case we may be toast.)
2894 We should really be keeping track of the total size of
2895 stubs added here, as stubs contribute to the final output
2899 prev = PREV_SEC (tail);
2900 /* Set up this stub group. */
2901 htab->stub_group[tail->id].link_sec = curr;
2903 while (tail != curr && (tail = prev) != NULL);
2905 /* But wait, there's more! Input sections up to stub_group_size
2906 bytes before the stub section can be handled by it too. */
2907 if (!stubs_always_before_branch)
2911 && ((total += tail->output_offset - prev->output_offset)
2915 prev = PREV_SEC (tail);
2916 htab->stub_group[tail->id].link_sec = curr;
2922 while (list-- != htab->input_list);
2924 free (htab->input_list);
2929 #define AARCH64_BITS(x, pos, n) (((x) >> (pos)) & ((1 << (n)) - 1))
2931 #define AARCH64_RT(insn) AARCH64_BITS (insn, 0, 5)
2932 #define AARCH64_RT2(insn) AARCH64_BITS (insn, 10, 5)
2933 #define AARCH64_RA(insn) AARCH64_BITS (insn, 10, 5)
2934 #define AARCH64_RD(insn) AARCH64_BITS (insn, 0, 5)
2935 #define AARCH64_RN(insn) AARCH64_BITS (insn, 5, 5)
2936 #define AARCH64_RM(insn) AARCH64_BITS (insn, 16, 5)
2938 #define AARCH64_MAC(insn) (((insn) & 0xff000000) == 0x9b000000)
2939 #define AARCH64_BIT(insn, n) AARCH64_BITS (insn, n, 1)
2940 #define AARCH64_OP31(insn) AARCH64_BITS (insn, 21, 3)
2941 #define AARCH64_ZR 0x1f
2943 /* All ld/st ops. See C4-182 of the ARM ARM. The encoding space for
2944 LD_PCREL, LDST_RO, LDST_UI and LDST_UIMM cover prefetch ops. */
2946 #define AARCH64_LD(insn) (AARCH64_BIT (insn, 22) == 1)
2947 #define AARCH64_LDST(insn) (((insn) & 0x0a000000) == 0x08000000)
2948 #define AARCH64_LDST_EX(insn) (((insn) & 0x3f000000) == 0x08000000)
2949 #define AARCH64_LDST_PCREL(insn) (((insn) & 0x3b000000) == 0x18000000)
2950 #define AARCH64_LDST_NAP(insn) (((insn) & 0x3b800000) == 0x28000000)
2951 #define AARCH64_LDSTP_PI(insn) (((insn) & 0x3b800000) == 0x28800000)
2952 #define AARCH64_LDSTP_O(insn) (((insn) & 0x3b800000) == 0x29000000)
2953 #define AARCH64_LDSTP_PRE(insn) (((insn) & 0x3b800000) == 0x29800000)
2954 #define AARCH64_LDST_UI(insn) (((insn) & 0x3b200c00) == 0x38000000)
2955 #define AARCH64_LDST_PIIMM(insn) (((insn) & 0x3b200c00) == 0x38000400)
2956 #define AARCH64_LDST_U(insn) (((insn) & 0x3b200c00) == 0x38000800)
2957 #define AARCH64_LDST_PREIMM(insn) (((insn) & 0x3b200c00) == 0x38000c00)
2958 #define AARCH64_LDST_RO(insn) (((insn) & 0x3b200c00) == 0x38200800)
2959 #define AARCH64_LDST_UIMM(insn) (((insn) & 0x3b000000) == 0x39000000)
2960 #define AARCH64_LDST_SIMD_M(insn) (((insn) & 0xbfbf0000) == 0x0c000000)
2961 #define AARCH64_LDST_SIMD_M_PI(insn) (((insn) & 0xbfa00000) == 0x0c800000)
2962 #define AARCH64_LDST_SIMD_S(insn) (((insn) & 0xbf9f0000) == 0x0d000000)
2963 #define AARCH64_LDST_SIMD_S_PI(insn) (((insn) & 0xbf800000) == 0x0d800000)
2965 /* Classify an INSN if it is indeed a load/store.
2967 Return TRUE if INSN is a LD/ST instruction otherwise return FALSE.
2969 For scalar LD/ST instructions PAIR is FALSE, RT is returned and RT2
2972 For LD/ST pair instructions PAIR is TRUE, RT and RT2 are returned.
2977 aarch64_mem_op_p (uint32_t insn, unsigned int *rt, unsigned int *rt2,
2978 bfd_boolean *pair, bfd_boolean *load)
2986 /* Bail out quickly if INSN doesn't fall into the the load-store
2988 if (!AARCH64_LDST (insn))
2993 if (AARCH64_LDST_EX (insn))
2995 *rt = AARCH64_RT (insn);
2997 if (AARCH64_BIT (insn, 21) == 1)
3000 *rt2 = AARCH64_RT2 (insn);
3002 *load = AARCH64_LD (insn);
3005 else if (AARCH64_LDST_NAP (insn)
3006 || AARCH64_LDSTP_PI (insn)
3007 || AARCH64_LDSTP_O (insn)
3008 || AARCH64_LDSTP_PRE (insn))
3011 *rt = AARCH64_RT (insn);
3012 *rt2 = AARCH64_RT2 (insn);
3013 *load = AARCH64_LD (insn);
3016 else if (AARCH64_LDST_PCREL (insn)
3017 || AARCH64_LDST_UI (insn)
3018 || AARCH64_LDST_PIIMM (insn)
3019 || AARCH64_LDST_U (insn)
3020 || AARCH64_LDST_PREIMM (insn)
3021 || AARCH64_LDST_RO (insn)
3022 || AARCH64_LDST_UIMM (insn))
3024 *rt = AARCH64_RT (insn);
3026 if (AARCH64_LDST_PCREL (insn))
3028 opc = AARCH64_BITS (insn, 22, 2);
3029 v = AARCH64_BIT (insn, 26);
3030 opc_v = opc | (v << 2);
3031 *load = (opc_v == 1 || opc_v == 2 || opc_v == 3
3032 || opc_v == 5 || opc_v == 7);
3035 else if (AARCH64_LDST_SIMD_M (insn)
3036 || AARCH64_LDST_SIMD_M_PI (insn))
3038 *rt = AARCH64_RT (insn);
3039 *load = AARCH64_BIT (insn, 22);
3040 opcode = (insn >> 12) & 0xf;
3067 else if (AARCH64_LDST_SIMD_S (insn)
3068 || AARCH64_LDST_SIMD_S_PI (insn))
3070 *rt = AARCH64_RT (insn);
3071 r = (insn >> 21) & 1;
3072 *load = AARCH64_BIT (insn, 22);
3073 opcode = (insn >> 13) & 0x7;
3085 *rt2 = *rt + (r == 0 ? 2 : 3);
3093 *rt2 = *rt + (r == 0 ? 2 : 3);
3105 /* Return TRUE if INSN is multiply-accumulate. */
3108 aarch64_mlxl_p (uint32_t insn)
3110 uint32_t op31 = AARCH64_OP31 (insn);
3112 if (AARCH64_MAC (insn)
3113 && (op31 == 0 || op31 == 1 || op31 == 5)
3114 /* Exclude MUL instructions which are encoded as a multiple accumulate
3116 && AARCH64_RA (insn) != AARCH64_ZR)
3122 /* Some early revisions of the Cortex-A53 have an erratum (835769) whereby
3123 it is possible for a 64-bit multiply-accumulate instruction to generate an
3124 incorrect result. The details are quite complex and hard to
3125 determine statically, since branches in the code may exist in some
3126 circumstances, but all cases end with a memory (load, store, or
3127 prefetch) instruction followed immediately by the multiply-accumulate
3128 operation. We employ a linker patching technique, by moving the potentially
3129 affected multiply-accumulate instruction into a patch region and replacing
3130 the original instruction with a branch to the patch. This function checks
3131 if INSN_1 is the memory operation followed by a multiply-accumulate
3132 operation (INSN_2). Return TRUE if an erratum sequence is found, FALSE
3133 if INSN_1 and INSN_2 are safe. */
3136 aarch64_erratum_sequence (uint32_t insn_1, uint32_t insn_2)
3146 if (aarch64_mlxl_p (insn_2)
3147 && aarch64_mem_op_p (insn_1, &rt, &rt2, &pair, &load))
3149 /* Any SIMD memory op is independent of the subsequent MLA
3150 by definition of the erratum. */
3151 if (AARCH64_BIT (insn_1, 26))
3154 /* If not SIMD, check for integer memory ops and MLA relationship. */
3155 rn = AARCH64_RN (insn_2);
3156 ra = AARCH64_RA (insn_2);
3157 rm = AARCH64_RM (insn_2);
3159 /* If this is a load and there's a true(RAW) dependency, we are safe
3160 and this is not an erratum sequence. */
3162 (rt == rn || rt == rm || rt == ra
3163 || (pair && (rt2 == rn || rt2 == rm || rt2 == ra))))
3166 /* We conservatively put out stubs for all other cases (including
3174 /* Used to order a list of mapping symbols by address. */
3177 elf_aarch64_compare_mapping (const void *a, const void *b)
3179 const elf_aarch64_section_map *amap = (const elf_aarch64_section_map *) a;
3180 const elf_aarch64_section_map *bmap = (const elf_aarch64_section_map *) b;
3182 if (amap->vma > bmap->vma)
3184 else if (amap->vma < bmap->vma)
3186 else if (amap->type > bmap->type)
3187 /* Ensure results do not depend on the host qsort for objects with
3188 multiple mapping symbols at the same address by sorting on type
3191 else if (amap->type < bmap->type)
3199 _bfd_aarch64_erratum_835769_stub_name (unsigned num_fixes)
3201 char *stub_name = (char *) bfd_malloc
3202 (strlen ("__erratum_835769_veneer_") + 16);
3203 sprintf (stub_name,"__erratum_835769_veneer_%d", num_fixes);
3207 /* Scan for Cortex-A53 erratum 835769 sequence.
3209 Return TRUE else FALSE on abnormal termination. */
3212 _bfd_aarch64_erratum_835769_scan (bfd *input_bfd,
3213 struct bfd_link_info *info,
3214 unsigned int *num_fixes_p)
3217 struct elf_aarch64_link_hash_table *htab = elf_aarch64_hash_table (info);
3218 unsigned int num_fixes = *num_fixes_p;
3223 for (section = input_bfd->sections;
3225 section = section->next)
3227 bfd_byte *contents = NULL;
3228 struct _aarch64_elf_section_data *sec_data;
3231 if (elf_section_type (section) != SHT_PROGBITS
3232 || (elf_section_flags (section) & SHF_EXECINSTR) == 0
3233 || (section->flags & SEC_EXCLUDE) != 0
3234 || (section->sec_info_type == SEC_INFO_TYPE_JUST_SYMS)
3235 || (section->output_section == bfd_abs_section_ptr))
3238 if (elf_section_data (section)->this_hdr.contents != NULL)
3239 contents = elf_section_data (section)->this_hdr.contents;
3240 else if (! bfd_malloc_and_get_section (input_bfd, section, &contents))
3243 sec_data = elf_aarch64_section_data (section);
3245 qsort (sec_data->map, sec_data->mapcount,
3246 sizeof (elf_aarch64_section_map), elf_aarch64_compare_mapping);
3248 for (span = 0; span < sec_data->mapcount; span++)
3250 unsigned int span_start = sec_data->map[span].vma;
3251 unsigned int span_end = ((span == sec_data->mapcount - 1)
3252 ? sec_data->map[0].vma + section->size
3253 : sec_data->map[span + 1].vma);
3255 char span_type = sec_data->map[span].type;
3257 if (span_type == 'd')
3260 for (i = span_start; i + 4 < span_end; i += 4)
3262 uint32_t insn_1 = bfd_getl32 (contents + i);
3263 uint32_t insn_2 = bfd_getl32 (contents + i + 4);
3265 if (aarch64_erratum_sequence (insn_1, insn_2))
3267 struct elf_aarch64_stub_hash_entry *stub_entry;
3268 char *stub_name = _bfd_aarch64_erratum_835769_stub_name (num_fixes);
3272 stub_entry = _bfd_aarch64_add_stub_entry_in_group (stub_name,
3278 stub_entry->stub_type = aarch64_stub_erratum_835769_veneer;
3279 stub_entry->target_section = section;
3280 stub_entry->target_value = i + 4;
3281 stub_entry->veneered_insn = insn_2;
3282 stub_entry->output_name = stub_name;
3287 if (elf_section_data (section)->this_hdr.contents == NULL)
3291 *num_fixes_p = num_fixes;
3297 /* Test if instruction INSN is ADRP. */
3300 _bfd_aarch64_adrp_p (uint32_t insn)
3302 return ((insn & 0x9f000000) == 0x90000000);
3306 /* Helper predicate to look for cortex-a53 erratum 843419 sequence 1. */
3309 _bfd_aarch64_erratum_843419_sequence_p (uint32_t insn_1, uint32_t insn_2,
3317 return (aarch64_mem_op_p (insn_2, &rt, &rt2, &pair, &load)
3320 && AARCH64_LDST_UIMM (insn_3)
3321 && AARCH64_RN (insn_3) == AARCH64_RD (insn_1));
3325 /* Test for the presence of Cortex-A53 erratum 843419 instruction sequence.
3327 Return TRUE if section CONTENTS at offset I contains one of the
3328 erratum 843419 sequences, otherwise return FALSE. If a sequence is
3329 seen set P_VENEER_I to the offset of the final LOAD/STORE
3330 instruction in the sequence.
3334 _bfd_aarch64_erratum_843419_p (bfd_byte *contents, bfd_vma vma,
3335 bfd_vma i, bfd_vma span_end,
3336 bfd_vma *p_veneer_i)
3338 uint32_t insn_1 = bfd_getl32 (contents + i);
3340 if (!_bfd_aarch64_adrp_p (insn_1))
3343 if (span_end < i + 12)
3346 uint32_t insn_2 = bfd_getl32 (contents + i + 4);
3347 uint32_t insn_3 = bfd_getl32 (contents + i + 8);
3349 if ((vma & 0xfff) != 0xff8 && (vma & 0xfff) != 0xffc)
3352 if (_bfd_aarch64_erratum_843419_sequence_p (insn_1, insn_2, insn_3))
3354 *p_veneer_i = i + 8;
3358 if (span_end < i + 16)
3361 uint32_t insn_4 = bfd_getl32 (contents + i + 12);
3363 if (_bfd_aarch64_erratum_843419_sequence_p (insn_1, insn_2, insn_4))
3365 *p_veneer_i = i + 12;
3373 /* Resize all stub sections. */
3376 _bfd_aarch64_resize_stubs (struct elf_aarch64_link_hash_table *htab)
3380 /* OK, we've added some stubs. Find out the new size of the
3382 for (section = htab->stub_bfd->sections;
3383 section != NULL; section = section->next)
3385 /* Ignore non-stub sections. */
3386 if (!strstr (section->name, STUB_SUFFIX))
3391 bfd_hash_traverse (&htab->stub_hash_table, aarch64_size_one_stub, htab);
3393 for (section = htab->stub_bfd->sections;
3394 section != NULL; section = section->next)
3396 if (!strstr (section->name, STUB_SUFFIX))
3402 /* Ensure all stub sections have a size which is a multiple of
3403 4096. This is important in order to ensure that the insertion
3404 of stub sections does not in itself move existing code around
3405 in such a way that new errata sequences are created. */
3406 if (htab->fix_erratum_843419)
3408 section->size = BFD_ALIGN (section->size, 0x1000);
3413 /* Construct an erratum 843419 workaround stub name.
3417 _bfd_aarch64_erratum_843419_stub_name (asection *input_section,
3420 const bfd_size_type len = 8 + 4 + 1 + 8 + 1 + 16 + 1;
3421 char *stub_name = bfd_malloc (len);
3423 if (stub_name != NULL)
3424 snprintf (stub_name, len, "e843419@%04x_%08x_%" BFD_VMA_FMT "x",
3425 input_section->owner->id,
3431 /* Build a stub_entry structure describing an 843419 fixup.
3433 The stub_entry constructed is populated with the bit pattern INSN
3434 of the instruction located at OFFSET within input SECTION.
3436 Returns TRUE on success. */
3439 _bfd_aarch64_erratum_843419_fixup (uint32_t insn,
3440 bfd_vma adrp_offset,
3441 bfd_vma ldst_offset,
3443 struct bfd_link_info *info)
3445 struct elf_aarch64_link_hash_table *htab = elf_aarch64_hash_table (info);
3447 struct elf_aarch64_stub_hash_entry *stub_entry;
3449 stub_name = _bfd_aarch64_erratum_843419_stub_name (section, ldst_offset);
3450 stub_entry = aarch64_stub_hash_lookup (&htab->stub_hash_table, stub_name,
3458 /* We always place an 843419 workaround veneer in the stub section
3459 attached to the input section in which an erratum sequence has
3460 been found. This ensures that later in the link process (in
3461 elfNN_aarch64_write_section) when we copy the veneered
3462 instruction from the input section into the stub section the
3463 copied instruction will have had any relocations applied to it.
3464 If we placed workaround veneers in any other stub section then we
3465 could not assume that all relocations have been processed on the
3466 corresponding input section at the point we output the stub
3470 stub_entry = _bfd_aarch64_add_stub_entry_after (stub_name, section, htab);
3471 if (stub_entry == NULL)
3477 stub_entry->adrp_offset = adrp_offset;
3478 stub_entry->target_value = ldst_offset;
3479 stub_entry->target_section = section;
3480 stub_entry->stub_type = aarch64_stub_erratum_843419_veneer;
3481 stub_entry->veneered_insn = insn;
3482 stub_entry->output_name = stub_name;
3488 /* Scan an input section looking for the signature of erratum 843419.
3490 Scans input SECTION in INPUT_BFD looking for erratum 843419
3491 signatures, for each signature found a stub_entry is created
3492 describing the location of the erratum for subsequent fixup.
3494 Return TRUE on successful scan, FALSE on failure to scan.
3498 _bfd_aarch64_erratum_843419_scan (bfd *input_bfd, asection *section,
3499 struct bfd_link_info *info)
3501 struct elf_aarch64_link_hash_table *htab = elf_aarch64_hash_table (info);
3506 if (elf_section_type (section) != SHT_PROGBITS
3507 || (elf_section_flags (section) & SHF_EXECINSTR) == 0
3508 || (section->flags & SEC_EXCLUDE) != 0
3509 || (section->sec_info_type == SEC_INFO_TYPE_JUST_SYMS)
3510 || (section->output_section == bfd_abs_section_ptr))
3515 bfd_byte *contents = NULL;
3516 struct _aarch64_elf_section_data *sec_data;
3519 if (elf_section_data (section)->this_hdr.contents != NULL)
3520 contents = elf_section_data (section)->this_hdr.contents;
3521 else if (! bfd_malloc_and_get_section (input_bfd, section, &contents))
3524 sec_data = elf_aarch64_section_data (section);
3526 qsort (sec_data->map, sec_data->mapcount,
3527 sizeof (elf_aarch64_section_map), elf_aarch64_compare_mapping);
3529 for (span = 0; span < sec_data->mapcount; span++)
3531 unsigned int span_start = sec_data->map[span].vma;
3532 unsigned int span_end = ((span == sec_data->mapcount - 1)
3533 ? sec_data->map[0].vma + section->size
3534 : sec_data->map[span + 1].vma);
3536 char span_type = sec_data->map[span].type;
3538 if (span_type == 'd')
3541 for (i = span_start; i + 8 < span_end; i += 4)
3543 bfd_vma vma = (section->output_section->vma
3544 + section->output_offset
3548 if (_bfd_aarch64_erratum_843419_p
3549 (contents, vma, i, span_end, &veneer_i))
3551 uint32_t insn = bfd_getl32 (contents + veneer_i);
3553 if (!_bfd_aarch64_erratum_843419_fixup (insn, i, veneer_i,
3560 if (elf_section_data (section)->this_hdr.contents == NULL)
3569 /* Determine and set the size of the stub section for a final link.
3571 The basic idea here is to examine all the relocations looking for
3572 PC-relative calls to a target that is unreachable with a "bl"
3576 elfNN_aarch64_size_stubs (bfd *output_bfd,
3578 struct bfd_link_info *info,
3579 bfd_signed_vma group_size,
3580 asection * (*add_stub_section) (const char *,
3582 void (*layout_sections_again) (void))
3584 bfd_size_type stub_group_size;
3585 bfd_boolean stubs_always_before_branch;
3586 bfd_boolean stub_changed = FALSE;
3587 struct elf_aarch64_link_hash_table *htab = elf_aarch64_hash_table (info);
3588 unsigned int num_erratum_835769_fixes = 0;
3590 /* Propagate mach to stub bfd, because it may not have been
3591 finalized when we created stub_bfd. */
3592 bfd_set_arch_mach (stub_bfd, bfd_get_arch (output_bfd),
3593 bfd_get_mach (output_bfd));
3595 /* Stash our params away. */
3596 htab->stub_bfd = stub_bfd;
3597 htab->add_stub_section = add_stub_section;
3598 htab->layout_sections_again = layout_sections_again;
3599 stubs_always_before_branch = group_size < 0;
3601 stub_group_size = -group_size;
3603 stub_group_size = group_size;
3605 if (stub_group_size == 1)
3607 /* Default values. */
3608 /* AArch64 branch range is +-128MB. The value used is 1MB less. */
3609 stub_group_size = 127 * 1024 * 1024;
3612 group_sections (htab, stub_group_size, stubs_always_before_branch);
3614 (*htab->layout_sections_again) ();
3616 if (htab->fix_erratum_835769)
3620 for (input_bfd = info->input_bfds;
3621 input_bfd != NULL; input_bfd = input_bfd->link.next)
3622 if (!_bfd_aarch64_erratum_835769_scan (input_bfd, info,
3623 &num_erratum_835769_fixes))
3626 _bfd_aarch64_resize_stubs (htab);
3627 (*htab->layout_sections_again) ();
3630 if (htab->fix_erratum_843419)
3634 for (input_bfd = info->input_bfds;
3636 input_bfd = input_bfd->link.next)
3640 for (section = input_bfd->sections;
3642 section = section->next)
3643 if (!_bfd_aarch64_erratum_843419_scan (input_bfd, section, info))
3647 _bfd_aarch64_resize_stubs (htab);
3648 (*htab->layout_sections_again) ();
3655 for (input_bfd = info->input_bfds;
3656 input_bfd != NULL; input_bfd = input_bfd->link.next)
3658 Elf_Internal_Shdr *symtab_hdr;
3660 Elf_Internal_Sym *local_syms = NULL;
3662 /* We'll need the symbol table in a second. */
3663 symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
3664 if (symtab_hdr->sh_info == 0)
3667 /* Walk over each section attached to the input bfd. */
3668 for (section = input_bfd->sections;
3669 section != NULL; section = section->next)
3671 Elf_Internal_Rela *internal_relocs, *irelaend, *irela;
3673 /* If there aren't any relocs, then there's nothing more
3675 if ((section->flags & SEC_RELOC) == 0
3676 || section->reloc_count == 0
3677 || (section->flags & SEC_CODE) == 0)
3680 /* If this section is a link-once section that will be
3681 discarded, then don't create any stubs. */
3682 if (section->output_section == NULL
3683 || section->output_section->owner != output_bfd)
3686 /* Get the relocs. */
3688 = _bfd_elf_link_read_relocs (input_bfd, section, NULL,
3689 NULL, info->keep_memory);
3690 if (internal_relocs == NULL)
3691 goto error_ret_free_local;
3693 /* Now examine each relocation. */
3694 irela = internal_relocs;
3695 irelaend = irela + section->reloc_count;
3696 for (; irela < irelaend; irela++)
3698 unsigned int r_type, r_indx;
3699 enum elf_aarch64_stub_type stub_type;
3700 struct elf_aarch64_stub_hash_entry *stub_entry;
3703 bfd_vma destination;
3704 struct elf_aarch64_link_hash_entry *hash;
3705 const char *sym_name;
3707 const asection *id_sec;
3708 unsigned char st_type;
3711 r_type = ELFNN_R_TYPE (irela->r_info);
3712 r_indx = ELFNN_R_SYM (irela->r_info);
3714 if (r_type >= (unsigned int) R_AARCH64_end)
3716 bfd_set_error (bfd_error_bad_value);
3717 error_ret_free_internal:
3718 if (elf_section_data (section)->relocs == NULL)
3719 free (internal_relocs);
3720 goto error_ret_free_local;
3723 /* Only look for stubs on unconditional branch and
3724 branch and link instructions. */
3725 if (r_type != (unsigned int) AARCH64_R (CALL26)
3726 && r_type != (unsigned int) AARCH64_R (JUMP26))
3729 /* Now determine the call target, its name, value,
3736 if (r_indx < symtab_hdr->sh_info)
3738 /* It's a local symbol. */
3739 Elf_Internal_Sym *sym;
3740 Elf_Internal_Shdr *hdr;
3742 if (local_syms == NULL)
3745 = (Elf_Internal_Sym *) symtab_hdr->contents;
3746 if (local_syms == NULL)
3748 = bfd_elf_get_elf_syms (input_bfd, symtab_hdr,
3749 symtab_hdr->sh_info, 0,
3751 if (local_syms == NULL)
3752 goto error_ret_free_internal;
3755 sym = local_syms + r_indx;
3756 hdr = elf_elfsections (input_bfd)[sym->st_shndx];
3757 sym_sec = hdr->bfd_section;
3759 /* This is an undefined symbol. It can never
3763 if (ELF_ST_TYPE (sym->st_info) != STT_SECTION)
3764 sym_value = sym->st_value;
3765 destination = (sym_value + irela->r_addend
3766 + sym_sec->output_offset
3767 + sym_sec->output_section->vma);
3768 st_type = ELF_ST_TYPE (sym->st_info);
3770 = bfd_elf_string_from_elf_section (input_bfd,
3771 symtab_hdr->sh_link,
3778 e_indx = r_indx - symtab_hdr->sh_info;
3779 hash = ((struct elf_aarch64_link_hash_entry *)
3780 elf_sym_hashes (input_bfd)[e_indx]);
3782 while (hash->root.root.type == bfd_link_hash_indirect
3783 || hash->root.root.type == bfd_link_hash_warning)
3784 hash = ((struct elf_aarch64_link_hash_entry *)
3785 hash->root.root.u.i.link);
3787 if (hash->root.root.type == bfd_link_hash_defined
3788 || hash->root.root.type == bfd_link_hash_defweak)
3790 struct elf_aarch64_link_hash_table *globals =
3791 elf_aarch64_hash_table (info);
3792 sym_sec = hash->root.root.u.def.section;
3793 sym_value = hash->root.root.u.def.value;
3794 /* For a destination in a shared library,
3795 use the PLT stub as target address to
3796 decide whether a branch stub is
3798 if (globals->root.splt != NULL && hash != NULL
3799 && hash->root.plt.offset != (bfd_vma) - 1)
3801 sym_sec = globals->root.splt;
3802 sym_value = hash->root.plt.offset;
3803 if (sym_sec->output_section != NULL)
3804 destination = (sym_value
3805 + sym_sec->output_offset
3807 sym_sec->output_section->vma);
3809 else if (sym_sec->output_section != NULL)
3810 destination = (sym_value + irela->r_addend
3811 + sym_sec->output_offset
3812 + sym_sec->output_section->vma);
3814 else if (hash->root.root.type == bfd_link_hash_undefined
3815 || (hash->root.root.type
3816 == bfd_link_hash_undefweak))
3818 /* For a shared library, use the PLT stub as
3819 target address to decide whether a long
3820 branch stub is needed.
3821 For absolute code, they cannot be handled. */
3822 struct elf_aarch64_link_hash_table *globals =
3823 elf_aarch64_hash_table (info);
3825 if (globals->root.splt != NULL && hash != NULL
3826 && hash->root.plt.offset != (bfd_vma) - 1)
3828 sym_sec = globals->root.splt;
3829 sym_value = hash->root.plt.offset;
3830 if (sym_sec->output_section != NULL)
3831 destination = (sym_value
3832 + sym_sec->output_offset
3834 sym_sec->output_section->vma);
3841 bfd_set_error (bfd_error_bad_value);
3842 goto error_ret_free_internal;
3844 st_type = ELF_ST_TYPE (hash->root.type);
3845 sym_name = hash->root.root.root.string;
3848 /* Determine what (if any) linker stub is needed. */
3849 stub_type = aarch64_type_of_stub
3850 (info, section, irela, sym_sec, st_type, hash, destination);
3851 if (stub_type == aarch64_stub_none)
3854 /* Support for grouping stub sections. */
3855 id_sec = htab->stub_group[section->id].link_sec;
3857 /* Get the name of this stub. */
3858 stub_name = elfNN_aarch64_stub_name (id_sec, sym_sec, hash,
3861 goto error_ret_free_internal;
3864 aarch64_stub_hash_lookup (&htab->stub_hash_table,
3865 stub_name, FALSE, FALSE);
3866 if (stub_entry != NULL)
3868 /* The proper stub has already been created. */
3873 stub_entry = _bfd_aarch64_add_stub_entry_in_group
3874 (stub_name, section, htab);
3875 if (stub_entry == NULL)
3878 goto error_ret_free_internal;
3881 stub_entry->target_value = sym_value;
3882 stub_entry->target_section = sym_sec;
3883 stub_entry->stub_type = stub_type;
3884 stub_entry->h = hash;
3885 stub_entry->st_type = st_type;
3887 if (sym_name == NULL)
3888 sym_name = "unnamed";
3889 len = sizeof (STUB_ENTRY_NAME) + strlen (sym_name);
3890 stub_entry->output_name = bfd_alloc (htab->stub_bfd, len);
3891 if (stub_entry->output_name == NULL)
3894 goto error_ret_free_internal;
3897 snprintf (stub_entry->output_name, len, STUB_ENTRY_NAME,
3900 stub_changed = TRUE;
3903 /* We're done with the internal relocs, free them. */
3904 if (elf_section_data (section)->relocs == NULL)
3905 free (internal_relocs);
3912 _bfd_aarch64_resize_stubs (htab);
3914 /* Ask the linker to do its stuff. */
3915 (*htab->layout_sections_again) ();
3916 stub_changed = FALSE;
3921 error_ret_free_local:
3925 /* Build all the stubs associated with the current output file. The
3926 stubs are kept in a hash table attached to the main linker hash
3927 table. We also set up the .plt entries for statically linked PIC
3928 functions here. This function is called via aarch64_elf_finish in the
3932 elfNN_aarch64_build_stubs (struct bfd_link_info *info)
3935 struct bfd_hash_table *table;
3936 struct elf_aarch64_link_hash_table *htab;
3938 htab = elf_aarch64_hash_table (info);
3940 for (stub_sec = htab->stub_bfd->sections;
3941 stub_sec != NULL; stub_sec = stub_sec->next)
3945 /* Ignore non-stub sections. */
3946 if (!strstr (stub_sec->name, STUB_SUFFIX))
3949 /* Allocate memory to hold the linker stubs. */
3950 size = stub_sec->size;
3951 stub_sec->contents = bfd_zalloc (htab->stub_bfd, size);
3952 if (stub_sec->contents == NULL && size != 0)
3956 bfd_putl32 (0x14000000 | (size >> 2), stub_sec->contents);
3957 stub_sec->size += 4;
3960 /* Build the stubs as directed by the stub hash table. */
3961 table = &htab->stub_hash_table;
3962 bfd_hash_traverse (table, aarch64_build_one_stub, info);
3968 /* Add an entry to the code/data map for section SEC. */
3971 elfNN_aarch64_section_map_add (asection *sec, char type, bfd_vma vma)
3973 struct _aarch64_elf_section_data *sec_data =
3974 elf_aarch64_section_data (sec);
3975 unsigned int newidx;
3977 if (sec_data->map == NULL)
3979 sec_data->map = bfd_malloc (sizeof (elf_aarch64_section_map));
3980 sec_data->mapcount = 0;
3981 sec_data->mapsize = 1;
3984 newidx = sec_data->mapcount++;
3986 if (sec_data->mapcount > sec_data->mapsize)
3988 sec_data->mapsize *= 2;
3989 sec_data->map = bfd_realloc_or_free
3990 (sec_data->map, sec_data->mapsize * sizeof (elf_aarch64_section_map));
3995 sec_data->map[newidx].vma = vma;
3996 sec_data->map[newidx].type = type;
4001 /* Initialise maps of insn/data for input BFDs. */
4003 bfd_elfNN_aarch64_init_maps (bfd *abfd)
4005 Elf_Internal_Sym *isymbuf;
4006 Elf_Internal_Shdr *hdr;
4007 unsigned int i, localsyms;
4009 /* Make sure that we are dealing with an AArch64 elf binary. */
4010 if (!is_aarch64_elf (abfd))
4013 if ((abfd->flags & DYNAMIC) != 0)
4016 hdr = &elf_symtab_hdr (abfd);
4017 localsyms = hdr->sh_info;
4019 /* Obtain a buffer full of symbols for this BFD. The hdr->sh_info field
4020 should contain the number of local symbols, which should come before any
4021 global symbols. Mapping symbols are always local. */
4022 isymbuf = bfd_elf_get_elf_syms (abfd, hdr, localsyms, 0, NULL, NULL, NULL);
4024 /* No internal symbols read? Skip this BFD. */
4025 if (isymbuf == NULL)
4028 for (i = 0; i < localsyms; i++)
4030 Elf_Internal_Sym *isym = &isymbuf[i];
4031 asection *sec = bfd_section_from_elf_index (abfd, isym->st_shndx);
4034 if (sec != NULL && ELF_ST_BIND (isym->st_info) == STB_LOCAL)
4036 name = bfd_elf_string_from_elf_section (abfd,
4040 if (bfd_is_aarch64_special_symbol_name
4041 (name, BFD_AARCH64_SPECIAL_SYM_TYPE_MAP))
4042 elfNN_aarch64_section_map_add (sec, name[1], isym->st_value);
4047 /* Set option values needed during linking. */
4049 bfd_elfNN_aarch64_set_options (struct bfd *output_bfd,
4050 struct bfd_link_info *link_info,
4052 int no_wchar_warn, int pic_veneer,
4053 int fix_erratum_835769,
4054 int fix_erratum_843419)
4056 struct elf_aarch64_link_hash_table *globals;
4058 globals = elf_aarch64_hash_table (link_info);
4059 globals->pic_veneer = pic_veneer;
4060 globals->fix_erratum_835769 = fix_erratum_835769;
4061 globals->fix_erratum_843419 = fix_erratum_843419;
4062 globals->fix_erratum_843419_adr = TRUE;
4064 BFD_ASSERT (is_aarch64_elf (output_bfd));
4065 elf_aarch64_tdata (output_bfd)->no_enum_size_warning = no_enum_warn;
4066 elf_aarch64_tdata (output_bfd)->no_wchar_size_warning = no_wchar_warn;
4070 aarch64_calculate_got_entry_vma (struct elf_link_hash_entry *h,
4071 struct elf_aarch64_link_hash_table
4072 *globals, struct bfd_link_info *info,
4073 bfd_vma value, bfd *output_bfd,
4074 bfd_boolean *unresolved_reloc_p)
4076 bfd_vma off = (bfd_vma) - 1;
4077 asection *basegot = globals->root.sgot;
4078 bfd_boolean dyn = globals->root.dynamic_sections_created;
4082 BFD_ASSERT (basegot != NULL);
4083 off = h->got.offset;
4084 BFD_ASSERT (off != (bfd_vma) - 1);
4085 if (!WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, bfd_link_pic (info), h)
4086 || (bfd_link_pic (info)
4087 && SYMBOL_REFERENCES_LOCAL (info, h))
4088 || (ELF_ST_VISIBILITY (h->other)
4089 && h->root.type == bfd_link_hash_undefweak))
4091 /* This is actually a static link, or it is a -Bsymbolic link
4092 and the symbol is defined locally. We must initialize this
4093 entry in the global offset table. Since the offset must
4094 always be a multiple of 8 (4 in the case of ILP32), we use
4095 the least significant bit to record whether we have
4096 initialized it already.
4097 When doing a dynamic link, we create a .rel(a).got relocation
4098 entry to initialize the value. This is done in the
4099 finish_dynamic_symbol routine. */
4104 bfd_put_NN (output_bfd, value, basegot->contents + off);
4109 *unresolved_reloc_p = FALSE;
4111 off = off + basegot->output_section->vma + basegot->output_offset;
4117 /* Change R_TYPE to a more efficient access model where possible,
4118 return the new reloc type. */
4120 static bfd_reloc_code_real_type
4121 aarch64_tls_transition_without_check (bfd_reloc_code_real_type r_type,
4122 struct elf_link_hash_entry *h)
4124 bfd_boolean is_local = h == NULL;
4128 case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21:
4129 case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21:
4131 ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1
4132 : BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21);
4134 case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21:
4136 ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC
4139 case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19:
4141 ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1
4142 : BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19);
4144 case BFD_RELOC_AARCH64_TLSDESC_LDNN_LO12_NC:
4145 case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC:
4147 ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC
4148 : BFD_RELOC_AARCH64_TLSIE_LDNN_GOTTPREL_LO12_NC);
4150 case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21:
4151 return is_local ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1 : r_type;
4153 case BFD_RELOC_AARCH64_TLSIE_LDNN_GOTTPREL_LO12_NC:
4154 return is_local ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC : r_type;
4156 case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19:
4159 case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21:
4161 ? BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_HI12
4162 : BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19);
4164 case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12_NC:
4165 case BFD_RELOC_AARCH64_TLSDESC_CALL:
4166 /* Instructions with these relocations will become NOPs. */
4167 return BFD_RELOC_AARCH64_NONE;
4177 aarch64_reloc_got_type (bfd_reloc_code_real_type r_type)
4181 case BFD_RELOC_AARCH64_ADR_GOT_PAGE:
4182 case BFD_RELOC_AARCH64_GOT_LD_PREL19:
4183 case BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14:
4184 case BFD_RELOC_AARCH64_LD32_GOT_LO12_NC:
4185 case BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15:
4186 case BFD_RELOC_AARCH64_LD64_GOT_LO12_NC:
4189 case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC:
4190 case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21:
4191 case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21:
4192 case BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC:
4193 case BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21:
4194 case BFD_RELOC_AARCH64_TLSLD_ADR_PREL21:
4197 case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12_NC:
4198 case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21:
4199 case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21:
4200 case BFD_RELOC_AARCH64_TLSDESC_CALL:
4201 case BFD_RELOC_AARCH64_TLSDESC_LD32_LO12_NC:
4202 case BFD_RELOC_AARCH64_TLSDESC_LD64_LO12_NC:
4203 case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19:
4204 return GOT_TLSDESC_GD;
4206 case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21:
4207 case BFD_RELOC_AARCH64_TLSIE_LD32_GOTTPREL_LO12_NC:
4208 case BFD_RELOC_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC:
4209 case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19:
4219 aarch64_can_relax_tls (bfd *input_bfd,
4220 struct bfd_link_info *info,
4221 bfd_reloc_code_real_type r_type,
4222 struct elf_link_hash_entry *h,
4223 unsigned long r_symndx)
4225 unsigned int symbol_got_type;
4226 unsigned int reloc_got_type;
4228 if (! IS_AARCH64_TLS_RELAX_RELOC (r_type))
4231 symbol_got_type = elfNN_aarch64_symbol_got_type (h, input_bfd, r_symndx);
4232 reloc_got_type = aarch64_reloc_got_type (r_type);
4234 if (symbol_got_type == GOT_TLS_IE && GOT_TLS_GD_ANY_P (reloc_got_type))
4237 if (bfd_link_pic (info))
4240 if (h && h->root.type == bfd_link_hash_undefweak)
4246 /* Given the relocation code R_TYPE, return the relaxed bfd reloc
4249 static bfd_reloc_code_real_type
4250 aarch64_tls_transition (bfd *input_bfd,
4251 struct bfd_link_info *info,
4252 unsigned int r_type,
4253 struct elf_link_hash_entry *h,
4254 unsigned long r_symndx)
4256 bfd_reloc_code_real_type bfd_r_type
4257 = elfNN_aarch64_bfd_reloc_from_type (r_type);
4259 if (! aarch64_can_relax_tls (input_bfd, info, bfd_r_type, h, r_symndx))
4262 return aarch64_tls_transition_without_check (bfd_r_type, h);
4265 /* Return the base VMA address which should be subtracted from real addresses
4266 when resolving R_AARCH64_TLS_DTPREL relocation. */
4269 dtpoff_base (struct bfd_link_info *info)
4271 /* If tls_sec is NULL, we should have signalled an error already. */
4272 BFD_ASSERT (elf_hash_table (info)->tls_sec != NULL);
4273 return elf_hash_table (info)->tls_sec->vma;
4276 /* Return the base VMA address which should be subtracted from real addresses
4277 when resolving R_AARCH64_TLS_GOTTPREL64 relocations. */
4280 tpoff_base (struct bfd_link_info *info)
4282 struct elf_link_hash_table *htab = elf_hash_table (info);
4284 /* If tls_sec is NULL, we should have signalled an error already. */
4285 BFD_ASSERT (htab->tls_sec != NULL);
4287 bfd_vma base = align_power ((bfd_vma) TCB_SIZE,
4288 htab->tls_sec->alignment_power);
4289 return htab->tls_sec->vma - base;
4293 symbol_got_offset_ref (bfd *input_bfd, struct elf_link_hash_entry *h,
4294 unsigned long r_symndx)
4296 /* Calculate the address of the GOT entry for symbol
4297 referred to in h. */
4299 return &h->got.offset;
4303 struct elf_aarch64_local_symbol *l;
4305 l = elf_aarch64_locals (input_bfd);
4306 return &l[r_symndx].got_offset;
4311 symbol_got_offset_mark (bfd *input_bfd, struct elf_link_hash_entry *h,
4312 unsigned long r_symndx)
4315 p = symbol_got_offset_ref (input_bfd, h, r_symndx);
4320 symbol_got_offset_mark_p (bfd *input_bfd, struct elf_link_hash_entry *h,
4321 unsigned long r_symndx)
4324 value = * symbol_got_offset_ref (input_bfd, h, r_symndx);
4329 symbol_got_offset (bfd *input_bfd, struct elf_link_hash_entry *h,
4330 unsigned long r_symndx)
4333 value = * symbol_got_offset_ref (input_bfd, h, r_symndx);
4339 symbol_tlsdesc_got_offset_ref (bfd *input_bfd, struct elf_link_hash_entry *h,
4340 unsigned long r_symndx)
4342 /* Calculate the address of the GOT entry for symbol
4343 referred to in h. */
4346 struct elf_aarch64_link_hash_entry *eh;
4347 eh = (struct elf_aarch64_link_hash_entry *) h;
4348 return &eh->tlsdesc_got_jump_table_offset;
4353 struct elf_aarch64_local_symbol *l;
4355 l = elf_aarch64_locals (input_bfd);
4356 return &l[r_symndx].tlsdesc_got_jump_table_offset;
4361 symbol_tlsdesc_got_offset_mark (bfd *input_bfd, struct elf_link_hash_entry *h,
4362 unsigned long r_symndx)
4365 p = symbol_tlsdesc_got_offset_ref (input_bfd, h, r_symndx);
4370 symbol_tlsdesc_got_offset_mark_p (bfd *input_bfd,
4371 struct elf_link_hash_entry *h,
4372 unsigned long r_symndx)
4375 value = * symbol_tlsdesc_got_offset_ref (input_bfd, h, r_symndx);
4380 symbol_tlsdesc_got_offset (bfd *input_bfd, struct elf_link_hash_entry *h,
4381 unsigned long r_symndx)
4384 value = * symbol_tlsdesc_got_offset_ref (input_bfd, h, r_symndx);
4389 /* Data for make_branch_to_erratum_835769_stub(). */
4391 struct erratum_835769_branch_to_stub_data
4393 struct bfd_link_info *info;
4394 asection *output_section;
4398 /* Helper to insert branches to erratum 835769 stubs in the right
4399 places for a particular section. */
4402 make_branch_to_erratum_835769_stub (struct bfd_hash_entry *gen_entry,
4405 struct elf_aarch64_stub_hash_entry *stub_entry;
4406 struct erratum_835769_branch_to_stub_data *data;
4408 unsigned long branch_insn = 0;
4409 bfd_vma veneered_insn_loc, veneer_entry_loc;
4410 bfd_signed_vma branch_offset;
4411 unsigned int target;
4414 stub_entry = (struct elf_aarch64_stub_hash_entry *) gen_entry;
4415 data = (struct erratum_835769_branch_to_stub_data *) in_arg;
4417 if (stub_entry->target_section != data->output_section
4418 || stub_entry->stub_type != aarch64_stub_erratum_835769_veneer)
4421 contents = data->contents;
4422 veneered_insn_loc = stub_entry->target_section->output_section->vma
4423 + stub_entry->target_section->output_offset
4424 + stub_entry->target_value;
4425 veneer_entry_loc = stub_entry->stub_sec->output_section->vma
4426 + stub_entry->stub_sec->output_offset
4427 + stub_entry->stub_offset;
4428 branch_offset = veneer_entry_loc - veneered_insn_loc;
4430 abfd = stub_entry->target_section->owner;
4431 if (!aarch64_valid_branch_p (veneer_entry_loc, veneered_insn_loc))
4432 (*_bfd_error_handler)
4433 (_("%B: error: Erratum 835769 stub out "
4434 "of range (input file too large)"), abfd);
4436 target = stub_entry->target_value;
4437 branch_insn = 0x14000000;
4438 branch_offset >>= 2;
4439 branch_offset &= 0x3ffffff;
4440 branch_insn |= branch_offset;
4441 bfd_putl32 (branch_insn, &contents[target]);
4448 _bfd_aarch64_erratum_843419_branch_to_stub (struct bfd_hash_entry *gen_entry,
4451 struct elf_aarch64_stub_hash_entry *stub_entry
4452 = (struct elf_aarch64_stub_hash_entry *) gen_entry;
4453 struct erratum_835769_branch_to_stub_data *data
4454 = (struct erratum_835769_branch_to_stub_data *) in_arg;
4455 struct bfd_link_info *info;
4456 struct elf_aarch64_link_hash_table *htab;
4464 contents = data->contents;
4465 section = data->output_section;
4467 htab = elf_aarch64_hash_table (info);
4469 if (stub_entry->target_section != section
4470 || stub_entry->stub_type != aarch64_stub_erratum_843419_veneer)
4473 insn = bfd_getl32 (contents + stub_entry->target_value);
4475 stub_entry->stub_sec->contents + stub_entry->stub_offset);
4477 place = (section->output_section->vma + section->output_offset
4478 + stub_entry->adrp_offset);
4479 insn = bfd_getl32 (contents + stub_entry->adrp_offset);
4481 if ((insn & AARCH64_ADRP_OP_MASK) != AARCH64_ADRP_OP)
4484 bfd_signed_vma imm =
4485 (_bfd_aarch64_sign_extend
4486 ((bfd_vma) _bfd_aarch64_decode_adrp_imm (insn) << 12, 33)
4489 if (htab->fix_erratum_843419_adr
4490 && (imm >= AARCH64_MIN_ADRP_IMM && imm <= AARCH64_MAX_ADRP_IMM))
4492 insn = (_bfd_aarch64_reencode_adr_imm (AARCH64_ADR_OP, imm)
4493 | AARCH64_RT (insn));
4494 bfd_putl32 (insn, contents + stub_entry->adrp_offset);
4498 bfd_vma veneered_insn_loc;
4499 bfd_vma veneer_entry_loc;
4500 bfd_signed_vma branch_offset;
4501 uint32_t branch_insn;
4503 veneered_insn_loc = stub_entry->target_section->output_section->vma
4504 + stub_entry->target_section->output_offset
4505 + stub_entry->target_value;
4506 veneer_entry_loc = stub_entry->stub_sec->output_section->vma
4507 + stub_entry->stub_sec->output_offset
4508 + stub_entry->stub_offset;
4509 branch_offset = veneer_entry_loc - veneered_insn_loc;
4511 abfd = stub_entry->target_section->owner;
4512 if (!aarch64_valid_branch_p (veneer_entry_loc, veneered_insn_loc))
4513 (*_bfd_error_handler)
4514 (_("%B: error: Erratum 843419 stub out "
4515 "of range (input file too large)"), abfd);
4517 branch_insn = 0x14000000;
4518 branch_offset >>= 2;
4519 branch_offset &= 0x3ffffff;
4520 branch_insn |= branch_offset;
4521 bfd_putl32 (branch_insn, contents + stub_entry->target_value);
4528 elfNN_aarch64_write_section (bfd *output_bfd ATTRIBUTE_UNUSED,
4529 struct bfd_link_info *link_info,
4534 struct elf_aarch64_link_hash_table *globals =
4535 elf_aarch64_hash_table (link_info);
4537 if (globals == NULL)
4540 /* Fix code to point to erratum 835769 stubs. */
4541 if (globals->fix_erratum_835769)
4543 struct erratum_835769_branch_to_stub_data data;
4545 data.info = link_info;
4546 data.output_section = sec;
4547 data.contents = contents;
4548 bfd_hash_traverse (&globals->stub_hash_table,
4549 make_branch_to_erratum_835769_stub, &data);
4552 if (globals->fix_erratum_843419)
4554 struct erratum_835769_branch_to_stub_data data;
4556 data.info = link_info;
4557 data.output_section = sec;
4558 data.contents = contents;
4559 bfd_hash_traverse (&globals->stub_hash_table,
4560 _bfd_aarch64_erratum_843419_branch_to_stub, &data);
4566 /* Perform a relocation as part of a final link. */
4567 static bfd_reloc_status_type
4568 elfNN_aarch64_final_link_relocate (reloc_howto_type *howto,
4571 asection *input_section,
4573 Elf_Internal_Rela *rel,
4575 struct bfd_link_info *info,
4577 struct elf_link_hash_entry *h,
4578 bfd_boolean *unresolved_reloc_p,
4579 bfd_boolean save_addend,
4580 bfd_vma *saved_addend,
4581 Elf_Internal_Sym *sym)
4583 Elf_Internal_Shdr *symtab_hdr;
4584 unsigned int r_type = howto->type;
4585 bfd_reloc_code_real_type bfd_r_type
4586 = elfNN_aarch64_bfd_reloc_from_howto (howto);
4587 bfd_reloc_code_real_type new_bfd_r_type;
4588 unsigned long r_symndx;
4589 bfd_byte *hit_data = contents + rel->r_offset;
4591 bfd_signed_vma signed_addend;
4592 struct elf_aarch64_link_hash_table *globals;
4593 bfd_boolean weak_undef_p;
4596 globals = elf_aarch64_hash_table (info);
4598 symtab_hdr = &elf_symtab_hdr (input_bfd);
4600 BFD_ASSERT (is_aarch64_elf (input_bfd));
4602 r_symndx = ELFNN_R_SYM (rel->r_info);
4604 /* It is possible to have linker relaxations on some TLS access
4605 models. Update our information here. */
4606 new_bfd_r_type = aarch64_tls_transition (input_bfd, info, r_type, h, r_symndx);
4607 if (new_bfd_r_type != bfd_r_type)
4609 bfd_r_type = new_bfd_r_type;
4610 howto = elfNN_aarch64_howto_from_bfd_reloc (bfd_r_type);
4611 BFD_ASSERT (howto != NULL);
4612 r_type = howto->type;
4615 place = input_section->output_section->vma
4616 + input_section->output_offset + rel->r_offset;
4618 /* Get addend, accumulating the addend for consecutive relocs
4619 which refer to the same offset. */
4620 signed_addend = saved_addend ? *saved_addend : 0;
4621 signed_addend += rel->r_addend;
4623 weak_undef_p = (h ? h->root.type == bfd_link_hash_undefweak
4624 : bfd_is_und_section (sym_sec));
4626 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle
4627 it here if it is defined in a non-shared object. */
4629 && h->type == STT_GNU_IFUNC
4636 if ((input_section->flags & SEC_ALLOC) == 0
4637 || h->plt.offset == (bfd_vma) -1)
4640 /* STT_GNU_IFUNC symbol must go through PLT. */
4641 plt = globals->root.splt ? globals->root.splt : globals->root.iplt;
4642 value = (plt->output_section->vma + plt->output_offset + h->plt.offset);
4647 if (h->root.root.string)
4648 name = h->root.root.string;
4650 name = bfd_elf_sym_name (input_bfd, symtab_hdr, sym,
4652 (*_bfd_error_handler)
4653 (_("%B: relocation %s against STT_GNU_IFUNC "
4654 "symbol `%s' isn't handled by %s"), input_bfd,
4655 howto->name, name, __FUNCTION__);
4656 bfd_set_error (bfd_error_bad_value);
4659 case BFD_RELOC_AARCH64_NN:
4660 if (rel->r_addend != 0)
4662 if (h->root.root.string)
4663 name = h->root.root.string;
4665 name = bfd_elf_sym_name (input_bfd, symtab_hdr,
4667 (*_bfd_error_handler)
4668 (_("%B: relocation %s against STT_GNU_IFUNC "
4669 "symbol `%s' has non-zero addend: %d"),
4670 input_bfd, howto->name, name, rel->r_addend);
4671 bfd_set_error (bfd_error_bad_value);
4675 /* Generate dynamic relocation only when there is a
4676 non-GOT reference in a shared object. */
4677 if (bfd_link_pic (info) && h->non_got_ref)
4679 Elf_Internal_Rela outrel;
4682 /* Need a dynamic relocation to get the real function
4684 outrel.r_offset = _bfd_elf_section_offset (output_bfd,
4688 if (outrel.r_offset == (bfd_vma) -1
4689 || outrel.r_offset == (bfd_vma) -2)
4692 outrel.r_offset += (input_section->output_section->vma
4693 + input_section->output_offset);
4695 if (h->dynindx == -1
4697 || bfd_link_executable (info))
4699 /* This symbol is resolved locally. */
4700 outrel.r_info = ELFNN_R_INFO (0, AARCH64_R (IRELATIVE));
4701 outrel.r_addend = (h->root.u.def.value
4702 + h->root.u.def.section->output_section->vma
4703 + h->root.u.def.section->output_offset);
4707 outrel.r_info = ELFNN_R_INFO (h->dynindx, r_type);
4708 outrel.r_addend = 0;
4711 sreloc = globals->root.irelifunc;
4712 elf_append_rela (output_bfd, sreloc, &outrel);
4714 /* If this reloc is against an external symbol, we
4715 do not want to fiddle with the addend. Otherwise,
4716 we need to include the symbol value so that it
4717 becomes an addend for the dynamic reloc. For an
4718 internal symbol, we have updated addend. */
4719 return bfd_reloc_ok;
4722 case BFD_RELOC_AARCH64_CALL26:
4723 case BFD_RELOC_AARCH64_JUMP26:
4724 value = _bfd_aarch64_elf_resolve_relocation (bfd_r_type, place, value,
4727 return _bfd_aarch64_elf_put_addend (input_bfd, hit_data, bfd_r_type,
4729 case BFD_RELOC_AARCH64_ADR_GOT_PAGE:
4730 case BFD_RELOC_AARCH64_GOT_LD_PREL19:
4731 case BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14:
4732 case BFD_RELOC_AARCH64_LD32_GOT_LO12_NC:
4733 case BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15:
4734 case BFD_RELOC_AARCH64_LD64_GOT_LO12_NC:
4735 base_got = globals->root.sgot;
4736 off = h->got.offset;
4738 if (base_got == NULL)
4741 if (off == (bfd_vma) -1)
4745 /* We can't use h->got.offset here to save state, or
4746 even just remember the offset, as finish_dynamic_symbol
4747 would use that as offset into .got. */
4749 if (globals->root.splt != NULL)
4751 plt_index = ((h->plt.offset - globals->plt_header_size) /
4752 globals->plt_entry_size);
4753 off = (plt_index + 3) * GOT_ENTRY_SIZE;
4754 base_got = globals->root.sgotplt;
4758 plt_index = h->plt.offset / globals->plt_entry_size;
4759 off = plt_index * GOT_ENTRY_SIZE;
4760 base_got = globals->root.igotplt;
4763 if (h->dynindx == -1
4767 /* This references the local definition. We must
4768 initialize this entry in the global offset table.
4769 Since the offset must always be a multiple of 8,
4770 we use the least significant bit to record
4771 whether we have initialized it already.
4773 When doing a dynamic link, we create a .rela.got
4774 relocation entry to initialize the value. This
4775 is done in the finish_dynamic_symbol routine. */
4780 bfd_put_NN (output_bfd, value,
4781 base_got->contents + off);
4782 /* Note that this is harmless as -1 | 1 still is -1. */
4786 value = (base_got->output_section->vma
4787 + base_got->output_offset + off);
4790 value = aarch64_calculate_got_entry_vma (h, globals, info,
4792 unresolved_reloc_p);
4793 if (bfd_r_type == BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15
4794 || bfd_r_type == BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14)
4795 addend = (globals->root.sgot->output_section->vma
4796 + globals->root.sgot->output_offset);
4797 value = _bfd_aarch64_elf_resolve_relocation (bfd_r_type, place, value,
4798 addend, weak_undef_p);
4799 return _bfd_aarch64_elf_put_addend (input_bfd, hit_data, bfd_r_type, howto, value);
4800 case BFD_RELOC_AARCH64_ADD_LO12:
4801 case BFD_RELOC_AARCH64_ADR_HI21_PCREL:
4808 case BFD_RELOC_AARCH64_NONE:
4809 case BFD_RELOC_AARCH64_TLSDESC_CALL:
4810 *unresolved_reloc_p = FALSE;
4811 return bfd_reloc_ok;
4813 case BFD_RELOC_AARCH64_NN:
4815 /* When generating a shared object or relocatable executable, these
4816 relocations are copied into the output file to be resolved at
4818 if (((bfd_link_pic (info) == TRUE)
4819 || globals->root.is_relocatable_executable)
4820 && (input_section->flags & SEC_ALLOC)
4822 || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
4823 || h->root.type != bfd_link_hash_undefweak))
4825 Elf_Internal_Rela outrel;
4827 bfd_boolean skip, relocate;
4830 *unresolved_reloc_p = FALSE;
4835 outrel.r_addend = signed_addend;
4837 _bfd_elf_section_offset (output_bfd, info, input_section,
4839 if (outrel.r_offset == (bfd_vma) - 1)
4841 else if (outrel.r_offset == (bfd_vma) - 2)
4847 outrel.r_offset += (input_section->output_section->vma
4848 + input_section->output_offset);
4851 memset (&outrel, 0, sizeof outrel);
4854 && (!bfd_link_pic (info)
4855 || !SYMBOLIC_BIND (info, h)
4856 || !h->def_regular))
4857 outrel.r_info = ELFNN_R_INFO (h->dynindx, r_type);
4862 /* On SVR4-ish systems, the dynamic loader cannot
4863 relocate the text and data segments independently,
4864 so the symbol does not matter. */
4866 outrel.r_info = ELFNN_R_INFO (symbol, AARCH64_R (RELATIVE));
4867 outrel.r_addend += value;
4870 sreloc = elf_section_data (input_section)->sreloc;
4871 if (sreloc == NULL || sreloc->contents == NULL)
4872 return bfd_reloc_notsupported;
4874 loc = sreloc->contents + sreloc->reloc_count++ * RELOC_SIZE (globals);
4875 bfd_elfNN_swap_reloca_out (output_bfd, &outrel, loc);
4877 if (sreloc->reloc_count * RELOC_SIZE (globals) > sreloc->size)
4879 /* Sanity to check that we have previously allocated
4880 sufficient space in the relocation section for the
4881 number of relocations we actually want to emit. */
4885 /* If this reloc is against an external symbol, we do not want to
4886 fiddle with the addend. Otherwise, we need to include the symbol
4887 value so that it becomes an addend for the dynamic reloc. */
4889 return bfd_reloc_ok;
4891 return _bfd_final_link_relocate (howto, input_bfd, input_section,
4892 contents, rel->r_offset, value,
4896 value += signed_addend;
4899 case BFD_RELOC_AARCH64_CALL26:
4900 case BFD_RELOC_AARCH64_JUMP26:
4902 asection *splt = globals->root.splt;
4903 bfd_boolean via_plt_p =
4904 splt != NULL && h != NULL && h->plt.offset != (bfd_vma) - 1;
4906 /* A call to an undefined weak symbol is converted to a jump to
4907 the next instruction unless a PLT entry will be created.
4908 The jump to the next instruction is optimized as a NOP.
4909 Do the same for local undefined symbols. */
4910 if (weak_undef_p && ! via_plt_p)
4912 bfd_putl32 (INSN_NOP, hit_data);
4913 return bfd_reloc_ok;
4916 /* If the call goes through a PLT entry, make sure to
4917 check distance to the right destination address. */
4919 value = (splt->output_section->vma
4920 + splt->output_offset + h->plt.offset);
4922 /* Check if a stub has to be inserted because the destination
4924 struct elf_aarch64_stub_hash_entry *stub_entry = NULL;
4925 if (! aarch64_valid_branch_p (value, place))
4926 /* The target is out of reach, so redirect the branch to
4927 the local stub for this function. */
4928 stub_entry = elfNN_aarch64_get_stub_entry (input_section, sym_sec, h,
4930 if (stub_entry != NULL)
4931 value = (stub_entry->stub_offset
4932 + stub_entry->stub_sec->output_offset
4933 + stub_entry->stub_sec->output_section->vma);
4935 value = _bfd_aarch64_elf_resolve_relocation (bfd_r_type, place, value,
4936 signed_addend, weak_undef_p);
4937 *unresolved_reloc_p = FALSE;
4940 case BFD_RELOC_AARCH64_16_PCREL:
4941 case BFD_RELOC_AARCH64_32_PCREL:
4942 case BFD_RELOC_AARCH64_64_PCREL:
4943 case BFD_RELOC_AARCH64_ADR_HI21_NC_PCREL:
4944 case BFD_RELOC_AARCH64_ADR_HI21_PCREL:
4945 case BFD_RELOC_AARCH64_ADR_LO21_PCREL:
4946 case BFD_RELOC_AARCH64_LD_LO19_PCREL:
4947 if (bfd_link_pic (info)
4948 && (input_section->flags & SEC_ALLOC) != 0
4949 && (input_section->flags & SEC_READONLY) != 0
4953 int howto_index = bfd_r_type - BFD_RELOC_AARCH64_RELOC_START;
4955 (*_bfd_error_handler)
4956 (_("%B: relocation %s against external symbol `%s' can not be used"
4957 " when making a shared object; recompile with -fPIC"),
4958 input_bfd, elfNN_aarch64_howto_table[howto_index].name,
4959 h->root.root.string);
4960 bfd_set_error (bfd_error_bad_value);
4964 case BFD_RELOC_AARCH64_16:
4966 case BFD_RELOC_AARCH64_32:
4968 case BFD_RELOC_AARCH64_ADD_LO12:
4969 case BFD_RELOC_AARCH64_BRANCH19:
4970 case BFD_RELOC_AARCH64_LDST128_LO12:
4971 case BFD_RELOC_AARCH64_LDST16_LO12:
4972 case BFD_RELOC_AARCH64_LDST32_LO12:
4973 case BFD_RELOC_AARCH64_LDST64_LO12:
4974 case BFD_RELOC_AARCH64_LDST8_LO12:
4975 case BFD_RELOC_AARCH64_MOVW_G0:
4976 case BFD_RELOC_AARCH64_MOVW_G0_NC:
4977 case BFD_RELOC_AARCH64_MOVW_G0_S:
4978 case BFD_RELOC_AARCH64_MOVW_G1:
4979 case BFD_RELOC_AARCH64_MOVW_G1_NC:
4980 case BFD_RELOC_AARCH64_MOVW_G1_S:
4981 case BFD_RELOC_AARCH64_MOVW_G2:
4982 case BFD_RELOC_AARCH64_MOVW_G2_NC:
4983 case BFD_RELOC_AARCH64_MOVW_G2_S:
4984 case BFD_RELOC_AARCH64_MOVW_G3:
4985 case BFD_RELOC_AARCH64_TSTBR14:
4986 value = _bfd_aarch64_elf_resolve_relocation (bfd_r_type, place, value,
4987 signed_addend, weak_undef_p);
4990 case BFD_RELOC_AARCH64_ADR_GOT_PAGE:
4991 case BFD_RELOC_AARCH64_GOT_LD_PREL19:
4992 case BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14:
4993 case BFD_RELOC_AARCH64_LD32_GOT_LO12_NC:
4994 case BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15:
4995 case BFD_RELOC_AARCH64_LD64_GOT_LO12_NC:
4996 if (globals->root.sgot == NULL)
4997 BFD_ASSERT (h != NULL);
5002 value = aarch64_calculate_got_entry_vma (h, globals, info, value,
5004 unresolved_reloc_p);
5005 if (bfd_r_type == BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15
5006 || bfd_r_type == BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14)
5007 addend = (globals->root.sgot->output_section->vma
5008 + globals->root.sgot->output_offset);
5009 value = _bfd_aarch64_elf_resolve_relocation (bfd_r_type, place, value,
5010 addend, weak_undef_p);
5015 struct elf_aarch64_local_symbol *locals
5016 = elf_aarch64_locals (input_bfd);
5020 int howto_index = bfd_r_type - BFD_RELOC_AARCH64_RELOC_START;
5021 (*_bfd_error_handler)
5022 (_("%B: Local symbol descriptor table be NULL when applying "
5023 "relocation %s against local symbol"),
5024 input_bfd, elfNN_aarch64_howto_table[howto_index].name);
5028 off = symbol_got_offset (input_bfd, h, r_symndx);
5029 base_got = globals->root.sgot;
5030 bfd_vma got_entry_addr = (base_got->output_section->vma
5031 + base_got->output_offset + off);
5033 if (!symbol_got_offset_mark_p (input_bfd, h, r_symndx))
5035 bfd_put_64 (output_bfd, value, base_got->contents + off);
5037 if (bfd_link_pic (info))
5040 Elf_Internal_Rela outrel;
5042 /* For local symbol, we have done absolute relocation in static
5043 linking stageh. While for share library, we need to update
5044 the content of GOT entry according to the share objects
5045 loading base address. So we need to generate a
5046 R_AARCH64_RELATIVE reloc for dynamic linker. */
5047 s = globals->root.srelgot;
5051 outrel.r_offset = got_entry_addr;
5052 outrel.r_info = ELFNN_R_INFO (0, AARCH64_R (RELATIVE));
5053 outrel.r_addend = value;
5054 elf_append_rela (output_bfd, s, &outrel);
5057 symbol_got_offset_mark (input_bfd, h, r_symndx);
5060 /* Update the relocation value to GOT entry addr as we have transformed
5061 the direct data access into indirect data access through GOT. */
5062 value = got_entry_addr;
5064 if (bfd_r_type == BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15
5065 || bfd_r_type == BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14)
5066 addend = base_got->output_section->vma + base_got->output_offset;
5068 value = _bfd_aarch64_elf_resolve_relocation (bfd_r_type, place, value,
5069 addend, weak_undef_p);
5074 case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC:
5075 case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21:
5076 case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21:
5077 case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21:
5078 case BFD_RELOC_AARCH64_TLSIE_LD32_GOTTPREL_LO12_NC:
5079 case BFD_RELOC_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC:
5080 case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19:
5081 case BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC:
5082 case BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21:
5083 case BFD_RELOC_AARCH64_TLSLD_ADR_PREL21:
5084 if (globals->root.sgot == NULL)
5085 return bfd_reloc_notsupported;
5087 value = (symbol_got_offset (input_bfd, h, r_symndx)
5088 + globals->root.sgot->output_section->vma
5089 + globals->root.sgot->output_offset);
5091 value = _bfd_aarch64_elf_resolve_relocation (bfd_r_type, place, value,
5093 *unresolved_reloc_p = FALSE;
5096 case BFD_RELOC_AARCH64_TLSLD_ADD_DTPREL_LO12:
5097 case BFD_RELOC_AARCH64_TLSLD_ADD_DTPREL_LO12_NC:
5098 value = _bfd_aarch64_elf_resolve_relocation (bfd_r_type, place, value,
5099 signed_addend - dtpoff_base (info),
5103 case BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_HI12:
5104 case BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_LO12:
5105 case BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_LO12_NC:
5106 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0:
5107 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC:
5108 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1:
5109 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1_NC:
5110 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G2:
5111 value = _bfd_aarch64_elf_resolve_relocation (bfd_r_type, place, value,
5112 signed_addend - tpoff_base (info),
5114 *unresolved_reloc_p = FALSE;
5117 case BFD_RELOC_AARCH64_TLSDESC_ADD:
5118 case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12_NC:
5119 case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21:
5120 case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21:
5121 case BFD_RELOC_AARCH64_TLSDESC_LD32_LO12_NC:
5122 case BFD_RELOC_AARCH64_TLSDESC_LD64_LO12_NC:
5123 case BFD_RELOC_AARCH64_TLSDESC_LDR:
5124 case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19:
5125 if (globals->root.sgot == NULL)
5126 return bfd_reloc_notsupported;
5127 value = (symbol_tlsdesc_got_offset (input_bfd, h, r_symndx)
5128 + globals->root.sgotplt->output_section->vma
5129 + globals->root.sgotplt->output_offset
5130 + globals->sgotplt_jump_table_size);
5132 value = _bfd_aarch64_elf_resolve_relocation (bfd_r_type, place, value,
5134 *unresolved_reloc_p = FALSE;
5138 return bfd_reloc_notsupported;
5142 *saved_addend = value;
5144 /* Only apply the final relocation in a sequence. */
5146 return bfd_reloc_continue;
5148 return _bfd_aarch64_elf_put_addend (input_bfd, hit_data, bfd_r_type,
5152 /* Handle TLS relaxations. Relaxing is possible for symbols that use
5153 R_AARCH64_TLSDESC_ADR_{PAGE, LD64_LO12_NC, ADD_LO12_NC} during a static
5156 Return bfd_reloc_ok if we're done, bfd_reloc_continue if the caller
5157 is to then call final_link_relocate. Return other values in the
5160 static bfd_reloc_status_type
5161 elfNN_aarch64_tls_relax (struct elf_aarch64_link_hash_table *globals,
5162 bfd *input_bfd, bfd_byte *contents,
5163 Elf_Internal_Rela *rel, struct elf_link_hash_entry *h)
5165 bfd_boolean is_local = h == NULL;
5166 unsigned int r_type = ELFNN_R_TYPE (rel->r_info);
5169 BFD_ASSERT (globals && input_bfd && contents && rel);
5171 switch (elfNN_aarch64_bfd_reloc_from_type (r_type))
5173 case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21:
5174 case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21:
5177 /* GD->LE relaxation:
5178 adrp x0, :tlsgd:var => movz x0, :tprel_g1:var
5180 adrp x0, :tlsdesc:var => movz x0, :tprel_g1:var
5182 bfd_putl32 (0xd2a00000, contents + rel->r_offset);
5183 return bfd_reloc_continue;
5187 /* GD->IE relaxation:
5188 adrp x0, :tlsgd:var => adrp x0, :gottprel:var
5190 adrp x0, :tlsdesc:var => adrp x0, :gottprel:var
5192 return bfd_reloc_continue;
5195 case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21:
5199 case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19:
5202 /* Tiny TLSDESC->LE relaxation:
5203 ldr x1, :tlsdesc:var => movz x0, #:tprel_g1:var
5204 adr x0, :tlsdesc:var => movk x0, #:tprel_g0_nc:var
5208 BFD_ASSERT (ELFNN_R_TYPE (rel[1].r_info) == AARCH64_R (TLSDESC_ADR_PREL21));
5209 BFD_ASSERT (ELFNN_R_TYPE (rel[2].r_info) == AARCH64_R (TLSDESC_CALL));
5211 rel[1].r_info = ELFNN_R_INFO (ELFNN_R_SYM (rel->r_info),
5212 AARCH64_R (TLSLE_MOVW_TPREL_G0_NC));
5213 rel[2].r_info = ELFNN_R_INFO (STN_UNDEF, R_AARCH64_NONE);
5215 bfd_putl32 (0xd2a00000, contents + rel->r_offset);
5216 bfd_putl32 (0xf2800000, contents + rel->r_offset + 4);
5217 bfd_putl32 (INSN_NOP, contents + rel->r_offset + 8);
5218 return bfd_reloc_continue;
5222 /* Tiny TLSDESC->IE relaxation:
5223 ldr x1, :tlsdesc:var => ldr x0, :gottprel:var
5224 adr x0, :tlsdesc:var => nop
5228 BFD_ASSERT (ELFNN_R_TYPE (rel[1].r_info) == AARCH64_R (TLSDESC_ADR_PREL21));
5229 BFD_ASSERT (ELFNN_R_TYPE (rel[2].r_info) == AARCH64_R (TLSDESC_CALL));
5231 rel[1].r_info = ELFNN_R_INFO (STN_UNDEF, R_AARCH64_NONE);
5232 rel[2].r_info = ELFNN_R_INFO (STN_UNDEF, R_AARCH64_NONE);
5234 bfd_putl32 (0x58000000, contents + rel->r_offset);
5235 bfd_putl32 (INSN_NOP, contents + rel->r_offset + 4);
5236 bfd_putl32 (INSN_NOP, contents + rel->r_offset + 8);
5237 return bfd_reloc_continue;
5240 case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21:
5243 /* Tiny GD->LE relaxation:
5244 adr x0, :tlsgd:var => mrs x1, tpidr_el0
5245 bl __tls_get_addr => add x0, x1, #:tprel_hi12:x, lsl #12
5246 nop => add x0, x0, #:tprel_lo12_nc:x
5249 /* First kill the tls_get_addr reloc on the bl instruction. */
5250 BFD_ASSERT (rel->r_offset + 4 == rel[1].r_offset);
5252 bfd_putl32 (0xd53bd041, contents + rel->r_offset + 0);
5253 bfd_putl32 (0x91400020, contents + rel->r_offset + 4);
5254 bfd_putl32 (0x91000000, contents + rel->r_offset + 8);
5256 rel[1].r_info = ELFNN_R_INFO (ELFNN_R_SYM (rel->r_info),
5257 AARCH64_R (TLSLE_ADD_TPREL_LO12_NC));
5258 rel[1].r_offset = rel->r_offset + 8;
5260 /* Move the current relocation to the second instruction in
5263 rel->r_info = ELFNN_R_INFO (ELFNN_R_SYM (rel->r_info),
5264 AARCH64_R (TLSLE_ADD_TPREL_HI12));
5265 return bfd_reloc_continue;
5269 /* Tiny GD->IE relaxation:
5270 adr x0, :tlsgd:var => ldr x0, :gottprel:var
5271 bl __tls_get_addr => mrs x1, tpidr_el0
5272 nop => add x0, x0, x1
5275 /* First kill the tls_get_addr reloc on the bl instruction. */
5276 BFD_ASSERT (rel->r_offset + 4 == rel[1].r_offset);
5277 rel[1].r_info = ELFNN_R_INFO (STN_UNDEF, R_AARCH64_NONE);
5279 bfd_putl32 (0x58000000, contents + rel->r_offset);
5280 bfd_putl32 (0xd53bd041, contents + rel->r_offset + 4);
5281 bfd_putl32 (0x8b000020, contents + rel->r_offset + 8);
5282 return bfd_reloc_continue;
5285 case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19:
5286 return bfd_reloc_continue;
5288 case BFD_RELOC_AARCH64_TLSDESC_LDNN_LO12_NC:
5291 /* GD->LE relaxation:
5292 ldr xd, [x0, #:tlsdesc_lo12:var] => movk x0, :tprel_g0_nc:var
5294 bfd_putl32 (0xf2800000, contents + rel->r_offset);
5295 return bfd_reloc_continue;
5299 /* GD->IE relaxation:
5300 ldr xd, [x0, #:tlsdesc_lo12:var] => ldr x0, [x0, #:gottprel_lo12:var]
5302 insn = bfd_getl32 (contents + rel->r_offset);
5304 bfd_putl32 (insn, contents + rel->r_offset);
5305 return bfd_reloc_continue;
5308 case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC:
5311 /* GD->LE relaxation
5312 add x0, #:tlsgd_lo12:var => movk x0, :tprel_g0_nc:var
5313 bl __tls_get_addr => mrs x1, tpidr_el0
5314 nop => add x0, x1, x0
5317 /* First kill the tls_get_addr reloc on the bl instruction. */
5318 BFD_ASSERT (rel->r_offset + 4 == rel[1].r_offset);
5319 rel[1].r_info = ELFNN_R_INFO (STN_UNDEF, R_AARCH64_NONE);
5321 bfd_putl32 (0xf2800000, contents + rel->r_offset);
5322 bfd_putl32 (0xd53bd041, contents + rel->r_offset + 4);
5323 bfd_putl32 (0x8b000020, contents + rel->r_offset + 8);
5324 return bfd_reloc_continue;
5328 /* GD->IE relaxation
5329 ADD x0, #:tlsgd_lo12:var => ldr x0, [x0, #:gottprel_lo12:var]
5330 BL __tls_get_addr => mrs x1, tpidr_el0
5332 NOP => add x0, x1, x0
5335 BFD_ASSERT (ELFNN_R_TYPE (rel[1].r_info) == AARCH64_R (CALL26));
5337 /* Remove the relocation on the BL instruction. */
5338 rel[1].r_info = ELFNN_R_INFO (STN_UNDEF, R_AARCH64_NONE);
5340 bfd_putl32 (0xf9400000, contents + rel->r_offset);
5342 /* We choose to fixup the BL and NOP instructions using the
5343 offset from the second relocation to allow flexibility in
5344 scheduling instructions between the ADD and BL. */
5345 bfd_putl32 (0xd53bd041, contents + rel[1].r_offset);
5346 bfd_putl32 (0x8b000020, contents + rel[1].r_offset + 4);
5347 return bfd_reloc_continue;
5350 case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12_NC:
5351 case BFD_RELOC_AARCH64_TLSDESC_CALL:
5352 /* GD->IE/LE relaxation:
5353 add x0, x0, #:tlsdesc_lo12:var => nop
5356 bfd_putl32 (INSN_NOP, contents + rel->r_offset);
5357 return bfd_reloc_ok;
5359 case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21:
5360 /* IE->LE relaxation:
5361 adrp xd, :gottprel:var => movz xd, :tprel_g1:var
5365 insn = bfd_getl32 (contents + rel->r_offset);
5366 bfd_putl32 (0xd2a00000 | (insn & 0x1f), contents + rel->r_offset);
5368 return bfd_reloc_continue;
5370 case BFD_RELOC_AARCH64_TLSIE_LDNN_GOTTPREL_LO12_NC:
5371 /* IE->LE relaxation:
5372 ldr xd, [xm, #:gottprel_lo12:var] => movk xd, :tprel_g0_nc:var
5376 insn = bfd_getl32 (contents + rel->r_offset);
5377 bfd_putl32 (0xf2800000 | (insn & 0x1f), contents + rel->r_offset);
5379 return bfd_reloc_continue;
5382 return bfd_reloc_continue;
5385 return bfd_reloc_ok;
5388 /* Relocate an AArch64 ELF section. */
5391 elfNN_aarch64_relocate_section (bfd *output_bfd,
5392 struct bfd_link_info *info,
5394 asection *input_section,
5396 Elf_Internal_Rela *relocs,
5397 Elf_Internal_Sym *local_syms,
5398 asection **local_sections)
5400 Elf_Internal_Shdr *symtab_hdr;
5401 struct elf_link_hash_entry **sym_hashes;
5402 Elf_Internal_Rela *rel;
5403 Elf_Internal_Rela *relend;
5405 struct elf_aarch64_link_hash_table *globals;
5406 bfd_boolean save_addend = FALSE;
5409 globals = elf_aarch64_hash_table (info);
5411 symtab_hdr = &elf_symtab_hdr (input_bfd);
5412 sym_hashes = elf_sym_hashes (input_bfd);
5415 relend = relocs + input_section->reloc_count;
5416 for (; rel < relend; rel++)
5418 unsigned int r_type;
5419 bfd_reloc_code_real_type bfd_r_type;
5420 bfd_reloc_code_real_type relaxed_bfd_r_type;
5421 reloc_howto_type *howto;
5422 unsigned long r_symndx;
5423 Elf_Internal_Sym *sym;
5425 struct elf_link_hash_entry *h;
5427 bfd_reloc_status_type r;
5430 bfd_boolean unresolved_reloc = FALSE;
5431 char *error_message = NULL;
5433 r_symndx = ELFNN_R_SYM (rel->r_info);
5434 r_type = ELFNN_R_TYPE (rel->r_info);
5436 bfd_reloc.howto = elfNN_aarch64_howto_from_type (r_type);
5437 howto = bfd_reloc.howto;
5441 (*_bfd_error_handler)
5442 (_("%B: unrecognized relocation (0x%x) in section `%A'"),
5443 input_bfd, input_section, r_type);
5446 bfd_r_type = elfNN_aarch64_bfd_reloc_from_howto (howto);
5452 if (r_symndx < symtab_hdr->sh_info)
5454 sym = local_syms + r_symndx;
5455 sym_type = ELFNN_ST_TYPE (sym->st_info);
5456 sec = local_sections[r_symndx];
5458 /* An object file might have a reference to a local
5459 undefined symbol. This is a daft object file, but we
5460 should at least do something about it. */
5461 if (r_type != R_AARCH64_NONE && r_type != R_AARCH64_NULL
5462 && bfd_is_und_section (sec)
5463 && ELF_ST_BIND (sym->st_info) != STB_WEAK)
5465 if (!info->callbacks->undefined_symbol
5466 (info, bfd_elf_string_from_elf_section
5467 (input_bfd, symtab_hdr->sh_link, sym->st_name),
5468 input_bfd, input_section, rel->r_offset, TRUE))
5472 relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel);
5474 /* Relocate against local STT_GNU_IFUNC symbol. */
5475 if (!bfd_link_relocatable (info)
5476 && ELF_ST_TYPE (sym->st_info) == STT_GNU_IFUNC)
5478 h = elfNN_aarch64_get_local_sym_hash (globals, input_bfd,
5483 /* Set STT_GNU_IFUNC symbol value. */
5484 h->root.u.def.value = sym->st_value;
5485 h->root.u.def.section = sec;
5490 bfd_boolean warned, ignored;
5492 RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel,
5493 r_symndx, symtab_hdr, sym_hashes,
5495 unresolved_reloc, warned, ignored);
5500 if (sec != NULL && discarded_section (sec))
5501 RELOC_AGAINST_DISCARDED_SECTION (info, input_bfd, input_section,
5502 rel, 1, relend, howto, 0, contents);
5504 if (bfd_link_relocatable (info))
5508 name = h->root.root.string;
5511 name = (bfd_elf_string_from_elf_section
5512 (input_bfd, symtab_hdr->sh_link, sym->st_name));
5513 if (name == NULL || *name == '\0')
5514 name = bfd_section_name (input_bfd, sec);
5518 && r_type != R_AARCH64_NONE
5519 && r_type != R_AARCH64_NULL
5521 || h->root.type == bfd_link_hash_defined
5522 || h->root.type == bfd_link_hash_defweak)
5523 && IS_AARCH64_TLS_RELOC (bfd_r_type) != (sym_type == STT_TLS))
5525 (*_bfd_error_handler)
5526 ((sym_type == STT_TLS
5527 ? _("%B(%A+0x%lx): %s used with TLS symbol %s")
5528 : _("%B(%A+0x%lx): %s used with non-TLS symbol %s")),
5530 input_section, (long) rel->r_offset, howto->name, name);
5533 /* We relax only if we can see that there can be a valid transition
5534 from a reloc type to another.
5535 We call elfNN_aarch64_final_link_relocate unless we're completely
5536 done, i.e., the relaxation produced the final output we want. */
5538 relaxed_bfd_r_type = aarch64_tls_transition (input_bfd, info, r_type,
5540 if (relaxed_bfd_r_type != bfd_r_type)
5542 bfd_r_type = relaxed_bfd_r_type;
5543 howto = elfNN_aarch64_howto_from_bfd_reloc (bfd_r_type);
5544 BFD_ASSERT (howto != NULL);
5545 r_type = howto->type;
5546 r = elfNN_aarch64_tls_relax (globals, input_bfd, contents, rel, h);
5547 unresolved_reloc = 0;
5550 r = bfd_reloc_continue;
5552 /* There may be multiple consecutive relocations for the
5553 same offset. In that case we are supposed to treat the
5554 output of each relocation as the addend for the next. */
5555 if (rel + 1 < relend
5556 && rel->r_offset == rel[1].r_offset
5557 && ELFNN_R_TYPE (rel[1].r_info) != R_AARCH64_NONE
5558 && ELFNN_R_TYPE (rel[1].r_info) != R_AARCH64_NULL)
5561 save_addend = FALSE;
5563 if (r == bfd_reloc_continue)
5564 r = elfNN_aarch64_final_link_relocate (howto, input_bfd, output_bfd,
5565 input_section, contents, rel,
5566 relocation, info, sec,
5567 h, &unresolved_reloc,
5568 save_addend, &addend, sym);
5570 switch (elfNN_aarch64_bfd_reloc_from_type (r_type))
5572 case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC:
5573 case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21:
5574 case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21:
5575 case BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC:
5576 case BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21:
5577 case BFD_RELOC_AARCH64_TLSLD_ADR_PREL21:
5578 if (! symbol_got_offset_mark_p (input_bfd, h, r_symndx))
5580 bfd_boolean need_relocs = FALSE;
5585 off = symbol_got_offset (input_bfd, h, r_symndx);
5586 indx = h && h->dynindx != -1 ? h->dynindx : 0;
5589 (bfd_link_pic (info) || indx != 0) &&
5591 || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
5592 || h->root.type != bfd_link_hash_undefweak);
5594 BFD_ASSERT (globals->root.srelgot != NULL);
5598 Elf_Internal_Rela rela;
5599 rela.r_info = ELFNN_R_INFO (indx, AARCH64_R (TLS_DTPMOD));
5601 rela.r_offset = globals->root.sgot->output_section->vma +
5602 globals->root.sgot->output_offset + off;
5605 loc = globals->root.srelgot->contents;
5606 loc += globals->root.srelgot->reloc_count++
5607 * RELOC_SIZE (htab);
5608 bfd_elfNN_swap_reloca_out (output_bfd, &rela, loc);
5610 bfd_reloc_code_real_type real_type =
5611 elfNN_aarch64_bfd_reloc_from_type (r_type);
5613 if (real_type == BFD_RELOC_AARCH64_TLSLD_ADR_PREL21
5614 || real_type == BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21
5615 || real_type == BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC)
5617 /* For local dynamic, don't generate DTPREL in any case.
5618 Initialize the DTPREL slot into zero, so we get module
5619 base address when invoke runtime TLS resolver. */
5620 bfd_put_NN (output_bfd, 0,
5621 globals->root.sgot->contents + off
5626 bfd_put_NN (output_bfd,
5627 relocation - dtpoff_base (info),
5628 globals->root.sgot->contents + off
5633 /* This TLS symbol is global. We emit a
5634 relocation to fixup the tls offset at load
5637 ELFNN_R_INFO (indx, AARCH64_R (TLS_DTPREL));
5640 (globals->root.sgot->output_section->vma
5641 + globals->root.sgot->output_offset + off
5644 loc = globals->root.srelgot->contents;
5645 loc += globals->root.srelgot->reloc_count++
5646 * RELOC_SIZE (globals);
5647 bfd_elfNN_swap_reloca_out (output_bfd, &rela, loc);
5648 bfd_put_NN (output_bfd, (bfd_vma) 0,
5649 globals->root.sgot->contents + off
5655 bfd_put_NN (output_bfd, (bfd_vma) 1,
5656 globals->root.sgot->contents + off);
5657 bfd_put_NN (output_bfd,
5658 relocation - dtpoff_base (info),
5659 globals->root.sgot->contents + off
5663 symbol_got_offset_mark (input_bfd, h, r_symndx);
5667 case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21:
5668 case BFD_RELOC_AARCH64_TLSIE_LDNN_GOTTPREL_LO12_NC:
5669 case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19:
5670 if (! symbol_got_offset_mark_p (input_bfd, h, r_symndx))
5672 bfd_boolean need_relocs = FALSE;
5677 off = symbol_got_offset (input_bfd, h, r_symndx);
5679 indx = h && h->dynindx != -1 ? h->dynindx : 0;
5682 (bfd_link_pic (info) || indx != 0) &&
5684 || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
5685 || h->root.type != bfd_link_hash_undefweak);
5687 BFD_ASSERT (globals->root.srelgot != NULL);
5691 Elf_Internal_Rela rela;
5694 rela.r_addend = relocation - dtpoff_base (info);
5698 rela.r_info = ELFNN_R_INFO (indx, AARCH64_R (TLS_TPREL));
5699 rela.r_offset = globals->root.sgot->output_section->vma +
5700 globals->root.sgot->output_offset + off;
5702 loc = globals->root.srelgot->contents;
5703 loc += globals->root.srelgot->reloc_count++
5704 * RELOC_SIZE (htab);
5706 bfd_elfNN_swap_reloca_out (output_bfd, &rela, loc);
5708 bfd_put_NN (output_bfd, rela.r_addend,
5709 globals->root.sgot->contents + off);
5712 bfd_put_NN (output_bfd, relocation - tpoff_base (info),
5713 globals->root.sgot->contents + off);
5715 symbol_got_offset_mark (input_bfd, h, r_symndx);
5719 case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12_NC:
5720 case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21:
5721 case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21:
5722 case BFD_RELOC_AARCH64_TLSDESC_LDNN_LO12_NC:
5723 case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19:
5724 if (! symbol_tlsdesc_got_offset_mark_p (input_bfd, h, r_symndx))
5726 bfd_boolean need_relocs = FALSE;
5727 int indx = h && h->dynindx != -1 ? h->dynindx : 0;
5728 bfd_vma off = symbol_tlsdesc_got_offset (input_bfd, h, r_symndx);
5730 need_relocs = (h == NULL
5731 || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
5732 || h->root.type != bfd_link_hash_undefweak);
5734 BFD_ASSERT (globals->root.srelgot != NULL);
5735 BFD_ASSERT (globals->root.sgot != NULL);
5740 Elf_Internal_Rela rela;
5741 rela.r_info = ELFNN_R_INFO (indx, AARCH64_R (TLSDESC));
5744 rela.r_offset = (globals->root.sgotplt->output_section->vma
5745 + globals->root.sgotplt->output_offset
5746 + off + globals->sgotplt_jump_table_size);
5749 rela.r_addend = relocation - dtpoff_base (info);
5751 /* Allocate the next available slot in the PLT reloc
5752 section to hold our R_AARCH64_TLSDESC, the next
5753 available slot is determined from reloc_count,
5754 which we step. But note, reloc_count was
5755 artifically moved down while allocating slots for
5756 real PLT relocs such that all of the PLT relocs
5757 will fit above the initial reloc_count and the
5758 extra stuff will fit below. */
5759 loc = globals->root.srelplt->contents;
5760 loc += globals->root.srelplt->reloc_count++
5761 * RELOC_SIZE (globals);
5763 bfd_elfNN_swap_reloca_out (output_bfd, &rela, loc);
5765 bfd_put_NN (output_bfd, (bfd_vma) 0,
5766 globals->root.sgotplt->contents + off +
5767 globals->sgotplt_jump_table_size);
5768 bfd_put_NN (output_bfd, (bfd_vma) 0,
5769 globals->root.sgotplt->contents + off +
5770 globals->sgotplt_jump_table_size +
5774 symbol_tlsdesc_got_offset_mark (input_bfd, h, r_symndx);
5785 /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
5786 because such sections are not SEC_ALLOC and thus ld.so will
5787 not process them. */
5788 if (unresolved_reloc
5789 && !((input_section->flags & SEC_DEBUGGING) != 0
5791 && _bfd_elf_section_offset (output_bfd, info, input_section,
5792 +rel->r_offset) != (bfd_vma) - 1)
5794 (*_bfd_error_handler)
5796 ("%B(%A+0x%lx): unresolvable %s relocation against symbol `%s'"),
5797 input_bfd, input_section, (long) rel->r_offset, howto->name,
5798 h->root.root.string);
5802 if (r != bfd_reloc_ok && r != bfd_reloc_continue)
5804 bfd_reloc_code_real_type real_r_type
5805 = elfNN_aarch64_bfd_reloc_from_type (r_type);
5809 case bfd_reloc_overflow:
5810 if (!(*info->callbacks->reloc_overflow)
5811 (info, (h ? &h->root : NULL), name, howto->name, (bfd_vma) 0,
5812 input_bfd, input_section, rel->r_offset))
5814 if (real_r_type == BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15
5815 || real_r_type == BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14)
5817 (*info->callbacks->warning)
5819 _("Too many GOT entries for -fpic, "
5820 "please recompile with -fPIC"),
5821 name, input_bfd, input_section, rel->r_offset);
5826 case bfd_reloc_undefined:
5827 if (!((*info->callbacks->undefined_symbol)
5828 (info, name, input_bfd, input_section,
5829 rel->r_offset, TRUE)))
5833 case bfd_reloc_outofrange:
5834 error_message = _("out of range");
5837 case bfd_reloc_notsupported:
5838 error_message = _("unsupported relocation");
5841 case bfd_reloc_dangerous:
5842 /* error_message should already be set. */
5846 error_message = _("unknown error");
5850 BFD_ASSERT (error_message != NULL);
5851 if (!((*info->callbacks->reloc_dangerous)
5852 (info, error_message, input_bfd, input_section,
5863 /* Set the right machine number. */
5866 elfNN_aarch64_object_p (bfd *abfd)
5869 bfd_default_set_arch_mach (abfd, bfd_arch_aarch64, bfd_mach_aarch64_ilp32);
5871 bfd_default_set_arch_mach (abfd, bfd_arch_aarch64, bfd_mach_aarch64);
5876 /* Function to keep AArch64 specific flags in the ELF header. */
5879 elfNN_aarch64_set_private_flags (bfd *abfd, flagword flags)
5881 if (elf_flags_init (abfd) && elf_elfheader (abfd)->e_flags != flags)
5886 elf_elfheader (abfd)->e_flags = flags;
5887 elf_flags_init (abfd) = TRUE;
5893 /* Merge backend specific data from an object file to the output
5894 object file when linking. */
5897 elfNN_aarch64_merge_private_bfd_data (bfd *ibfd, bfd *obfd)
5901 bfd_boolean flags_compatible = TRUE;
5904 /* Check if we have the same endianess. */
5905 if (!_bfd_generic_verify_endian_match (ibfd, obfd))
5908 if (!is_aarch64_elf (ibfd) || !is_aarch64_elf (obfd))
5911 /* The input BFD must have had its flags initialised. */
5912 /* The following seems bogus to me -- The flags are initialized in
5913 the assembler but I don't think an elf_flags_init field is
5914 written into the object. */
5915 /* BFD_ASSERT (elf_flags_init (ibfd)); */
5917 in_flags = elf_elfheader (ibfd)->e_flags;
5918 out_flags = elf_elfheader (obfd)->e_flags;
5920 if (!elf_flags_init (obfd))
5922 /* If the input is the default architecture and had the default
5923 flags then do not bother setting the flags for the output
5924 architecture, instead allow future merges to do this. If no
5925 future merges ever set these flags then they will retain their
5926 uninitialised values, which surprise surprise, correspond
5927 to the default values. */
5928 if (bfd_get_arch_info (ibfd)->the_default
5929 && elf_elfheader (ibfd)->e_flags == 0)
5932 elf_flags_init (obfd) = TRUE;
5933 elf_elfheader (obfd)->e_flags = in_flags;
5935 if (bfd_get_arch (obfd) == bfd_get_arch (ibfd)
5936 && bfd_get_arch_info (obfd)->the_default)
5937 return bfd_set_arch_mach (obfd, bfd_get_arch (ibfd),
5938 bfd_get_mach (ibfd));
5943 /* Identical flags must be compatible. */
5944 if (in_flags == out_flags)
5947 /* Check to see if the input BFD actually contains any sections. If
5948 not, its flags may not have been initialised either, but it
5949 cannot actually cause any incompatiblity. Do not short-circuit
5950 dynamic objects; their section list may be emptied by
5951 elf_link_add_object_symbols.
5953 Also check to see if there are no code sections in the input.
5954 In this case there is no need to check for code specific flags.
5955 XXX - do we need to worry about floating-point format compatability
5956 in data sections ? */
5957 if (!(ibfd->flags & DYNAMIC))
5959 bfd_boolean null_input_bfd = TRUE;
5960 bfd_boolean only_data_sections = TRUE;
5962 for (sec = ibfd->sections; sec != NULL; sec = sec->next)
5964 if ((bfd_get_section_flags (ibfd, sec)
5965 & (SEC_LOAD | SEC_CODE | SEC_HAS_CONTENTS))
5966 == (SEC_LOAD | SEC_CODE | SEC_HAS_CONTENTS))
5967 only_data_sections = FALSE;
5969 null_input_bfd = FALSE;
5973 if (null_input_bfd || only_data_sections)
5977 return flags_compatible;
5980 /* Display the flags field. */
5983 elfNN_aarch64_print_private_bfd_data (bfd *abfd, void *ptr)
5985 FILE *file = (FILE *) ptr;
5986 unsigned long flags;
5988 BFD_ASSERT (abfd != NULL && ptr != NULL);
5990 /* Print normal ELF private data. */
5991 _bfd_elf_print_private_bfd_data (abfd, ptr);
5993 flags = elf_elfheader (abfd)->e_flags;
5994 /* Ignore init flag - it may not be set, despite the flags field
5995 containing valid data. */
5997 /* xgettext:c-format */
5998 fprintf (file, _("private flags = %lx:"), elf_elfheader (abfd)->e_flags);
6001 fprintf (file, _("<Unrecognised flag bits set>"));
6008 /* Update the got entry reference counts for the section being removed. */
6011 elfNN_aarch64_gc_sweep_hook (bfd *abfd,
6012 struct bfd_link_info *info,
6014 const Elf_Internal_Rela * relocs)
6016 struct elf_aarch64_link_hash_table *htab;
6017 Elf_Internal_Shdr *symtab_hdr;
6018 struct elf_link_hash_entry **sym_hashes;
6019 struct elf_aarch64_local_symbol *locals;
6020 const Elf_Internal_Rela *rel, *relend;
6022 if (bfd_link_relocatable (info))
6025 htab = elf_aarch64_hash_table (info);
6030 elf_section_data (sec)->local_dynrel = NULL;
6032 symtab_hdr = &elf_symtab_hdr (abfd);
6033 sym_hashes = elf_sym_hashes (abfd);
6035 locals = elf_aarch64_locals (abfd);
6037 relend = relocs + sec->reloc_count;
6038 for (rel = relocs; rel < relend; rel++)
6040 unsigned long r_symndx;
6041 unsigned int r_type;
6042 struct elf_link_hash_entry *h = NULL;
6044 r_symndx = ELFNN_R_SYM (rel->r_info);
6046 if (r_symndx >= symtab_hdr->sh_info)
6049 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
6050 while (h->root.type == bfd_link_hash_indirect
6051 || h->root.type == bfd_link_hash_warning)
6052 h = (struct elf_link_hash_entry *) h->root.u.i.link;
6056 Elf_Internal_Sym *isym;
6058 /* A local symbol. */
6059 isym = bfd_sym_from_r_symndx (&htab->sym_cache,
6062 /* Check relocation against local STT_GNU_IFUNC symbol. */
6064 && ELF_ST_TYPE (isym->st_info) == STT_GNU_IFUNC)
6066 h = elfNN_aarch64_get_local_sym_hash (htab, abfd, rel, FALSE);
6074 struct elf_aarch64_link_hash_entry *eh;
6075 struct elf_dyn_relocs **pp;
6076 struct elf_dyn_relocs *p;
6078 eh = (struct elf_aarch64_link_hash_entry *) h;
6080 for (pp = &eh->dyn_relocs; (p = *pp) != NULL; pp = &p->next)
6083 /* Everything must go for SEC. */
6089 r_type = ELFNN_R_TYPE (rel->r_info);
6090 switch (aarch64_tls_transition (abfd,info, r_type, h ,r_symndx))
6092 case BFD_RELOC_AARCH64_ADR_GOT_PAGE:
6093 case BFD_RELOC_AARCH64_GOT_LD_PREL19:
6094 case BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14:
6095 case BFD_RELOC_AARCH64_LD32_GOT_LO12_NC:
6096 case BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15:
6097 case BFD_RELOC_AARCH64_LD64_GOT_LO12_NC:
6098 case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12_NC:
6099 case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21:
6100 case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21:
6101 case BFD_RELOC_AARCH64_TLSDESC_LD32_LO12_NC:
6102 case BFD_RELOC_AARCH64_TLSDESC_LD64_LO12_NC:
6103 case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19:
6104 case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC:
6105 case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21:
6106 case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21:
6107 case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21:
6108 case BFD_RELOC_AARCH64_TLSIE_LD32_GOTTPREL_LO12_NC:
6109 case BFD_RELOC_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC:
6110 case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19:
6111 case BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC:
6112 case BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21:
6113 case BFD_RELOC_AARCH64_TLSLD_ADR_PREL21:
6116 if (h->got.refcount > 0)
6117 h->got.refcount -= 1;
6119 if (h->type == STT_GNU_IFUNC)
6121 if (h->plt.refcount > 0)
6122 h->plt.refcount -= 1;
6125 else if (locals != NULL)
6127 if (locals[r_symndx].got_refcount > 0)
6128 locals[r_symndx].got_refcount -= 1;
6132 case BFD_RELOC_AARCH64_CALL26:
6133 case BFD_RELOC_AARCH64_JUMP26:
6134 /* If this is a local symbol then we resolve it
6135 directly without creating a PLT entry. */
6139 if (h->plt.refcount > 0)
6140 h->plt.refcount -= 1;
6143 case BFD_RELOC_AARCH64_ADR_HI21_NC_PCREL:
6144 case BFD_RELOC_AARCH64_ADR_HI21_PCREL:
6145 case BFD_RELOC_AARCH64_ADR_LO21_PCREL:
6146 case BFD_RELOC_AARCH64_MOVW_G0_NC:
6147 case BFD_RELOC_AARCH64_MOVW_G1_NC:
6148 case BFD_RELOC_AARCH64_MOVW_G2_NC:
6149 case BFD_RELOC_AARCH64_MOVW_G3:
6150 case BFD_RELOC_AARCH64_NN:
6151 if (h != NULL && bfd_link_executable (info))
6153 if (h->plt.refcount > 0)
6154 h->plt.refcount -= 1;
6166 /* Adjust a symbol defined by a dynamic object and referenced by a
6167 regular object. The current definition is in some section of the
6168 dynamic object, but we're not including those sections. We have to
6169 change the definition to something the rest of the link can
6173 elfNN_aarch64_adjust_dynamic_symbol (struct bfd_link_info *info,
6174 struct elf_link_hash_entry *h)
6176 struct elf_aarch64_link_hash_table *htab;
6179 /* If this is a function, put it in the procedure linkage table. We
6180 will fill in the contents of the procedure linkage table later,
6181 when we know the address of the .got section. */
6182 if (h->type == STT_FUNC || h->type == STT_GNU_IFUNC || h->needs_plt)
6184 if (h->plt.refcount <= 0
6185 || (h->type != STT_GNU_IFUNC
6186 && (SYMBOL_CALLS_LOCAL (info, h)
6187 || (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
6188 && h->root.type == bfd_link_hash_undefweak))))
6190 /* This case can occur if we saw a CALL26 reloc in
6191 an input file, but the symbol wasn't referred to
6192 by a dynamic object or all references were
6193 garbage collected. In which case we can end up
6195 h->plt.offset = (bfd_vma) - 1;
6202 /* Otherwise, reset to -1. */
6203 h->plt.offset = (bfd_vma) - 1;
6206 /* If this is a weak symbol, and there is a real definition, the
6207 processor independent code will have arranged for us to see the
6208 real definition first, and we can just use the same value. */
6209 if (h->u.weakdef != NULL)
6211 BFD_ASSERT (h->u.weakdef->root.type == bfd_link_hash_defined
6212 || h->u.weakdef->root.type == bfd_link_hash_defweak);
6213 h->root.u.def.section = h->u.weakdef->root.u.def.section;
6214 h->root.u.def.value = h->u.weakdef->root.u.def.value;
6215 if (ELIMINATE_COPY_RELOCS || info->nocopyreloc)
6216 h->non_got_ref = h->u.weakdef->non_got_ref;
6220 /* If we are creating a shared library, we must presume that the
6221 only references to the symbol are via the global offset table.
6222 For such cases we need not do anything here; the relocations will
6223 be handled correctly by relocate_section. */
6224 if (bfd_link_pic (info))
6227 /* If there are no references to this symbol that do not use the
6228 GOT, we don't need to generate a copy reloc. */
6229 if (!h->non_got_ref)
6232 /* If -z nocopyreloc was given, we won't generate them either. */
6233 if (info->nocopyreloc)
6239 /* We must allocate the symbol in our .dynbss section, which will
6240 become part of the .bss section of the executable. There will be
6241 an entry for this symbol in the .dynsym section. The dynamic
6242 object will contain position independent code, so all references
6243 from the dynamic object to this symbol will go through the global
6244 offset table. The dynamic linker will use the .dynsym entry to
6245 determine the address it must put in the global offset table, so
6246 both the dynamic object and the regular object will refer to the
6247 same memory location for the variable. */
6249 htab = elf_aarch64_hash_table (info);
6251 /* We must generate a R_AARCH64_COPY reloc to tell the dynamic linker
6252 to copy the initial value out of the dynamic object and into the
6253 runtime process image. */
6254 if ((h->root.u.def.section->flags & SEC_ALLOC) != 0 && h->size != 0)
6256 htab->srelbss->size += RELOC_SIZE (htab);
6262 return _bfd_elf_adjust_dynamic_copy (info, h, s);
6267 elfNN_aarch64_allocate_local_symbols (bfd *abfd, unsigned number)
6269 struct elf_aarch64_local_symbol *locals;
6270 locals = elf_aarch64_locals (abfd);
6273 locals = (struct elf_aarch64_local_symbol *)
6274 bfd_zalloc (abfd, number * sizeof (struct elf_aarch64_local_symbol));
6277 elf_aarch64_locals (abfd) = locals;
6282 /* Create the .got section to hold the global offset table. */
6285 aarch64_elf_create_got_section (bfd *abfd, struct bfd_link_info *info)
6287 const struct elf_backend_data *bed = get_elf_backend_data (abfd);
6290 struct elf_link_hash_entry *h;
6291 struct elf_link_hash_table *htab = elf_hash_table (info);
6293 /* This function may be called more than once. */
6294 s = bfd_get_linker_section (abfd, ".got");
6298 flags = bed->dynamic_sec_flags;
6300 s = bfd_make_section_anyway_with_flags (abfd,
6301 (bed->rela_plts_and_copies_p
6302 ? ".rela.got" : ".rel.got"),
6303 (bed->dynamic_sec_flags
6306 || ! bfd_set_section_alignment (abfd, s, bed->s->log_file_align))
6310 s = bfd_make_section_anyway_with_flags (abfd, ".got", flags);
6312 || !bfd_set_section_alignment (abfd, s, bed->s->log_file_align))
6315 htab->sgot->size += GOT_ENTRY_SIZE;
6317 if (bed->want_got_sym)
6319 /* Define the symbol _GLOBAL_OFFSET_TABLE_ at the start of the .got
6320 (or .got.plt) section. We don't do this in the linker script
6321 because we don't want to define the symbol if we are not creating
6322 a global offset table. */
6323 h = _bfd_elf_define_linkage_sym (abfd, info, s,
6324 "_GLOBAL_OFFSET_TABLE_");
6325 elf_hash_table (info)->hgot = h;
6330 if (bed->want_got_plt)
6332 s = bfd_make_section_anyway_with_flags (abfd, ".got.plt", flags);
6334 || !bfd_set_section_alignment (abfd, s,
6335 bed->s->log_file_align))
6340 /* The first bit of the global offset table is the header. */
6341 s->size += bed->got_header_size;
6346 /* Look through the relocs for a section during the first phase. */
6349 elfNN_aarch64_check_relocs (bfd *abfd, struct bfd_link_info *info,
6350 asection *sec, const Elf_Internal_Rela *relocs)
6352 Elf_Internal_Shdr *symtab_hdr;
6353 struct elf_link_hash_entry **sym_hashes;
6354 const Elf_Internal_Rela *rel;
6355 const Elf_Internal_Rela *rel_end;
6358 struct elf_aarch64_link_hash_table *htab;
6360 if (bfd_link_relocatable (info))
6363 BFD_ASSERT (is_aarch64_elf (abfd));
6365 htab = elf_aarch64_hash_table (info);
6368 symtab_hdr = &elf_symtab_hdr (abfd);
6369 sym_hashes = elf_sym_hashes (abfd);
6371 rel_end = relocs + sec->reloc_count;
6372 for (rel = relocs; rel < rel_end; rel++)
6374 struct elf_link_hash_entry *h;
6375 unsigned long r_symndx;
6376 unsigned int r_type;
6377 bfd_reloc_code_real_type bfd_r_type;
6378 Elf_Internal_Sym *isym;
6380 r_symndx = ELFNN_R_SYM (rel->r_info);
6381 r_type = ELFNN_R_TYPE (rel->r_info);
6383 if (r_symndx >= NUM_SHDR_ENTRIES (symtab_hdr))
6385 (*_bfd_error_handler) (_("%B: bad symbol index: %d"), abfd,
6390 if (r_symndx < symtab_hdr->sh_info)
6392 /* A local symbol. */
6393 isym = bfd_sym_from_r_symndx (&htab->sym_cache,
6398 /* Check relocation against local STT_GNU_IFUNC symbol. */
6399 if (ELF_ST_TYPE (isym->st_info) == STT_GNU_IFUNC)
6401 h = elfNN_aarch64_get_local_sym_hash (htab, abfd, rel,
6406 /* Fake a STT_GNU_IFUNC symbol. */
6407 h->type = STT_GNU_IFUNC;
6410 h->forced_local = 1;
6411 h->root.type = bfd_link_hash_defined;
6418 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
6419 while (h->root.type == bfd_link_hash_indirect
6420 || h->root.type == bfd_link_hash_warning)
6421 h = (struct elf_link_hash_entry *) h->root.u.i.link;
6423 /* PR15323, ref flags aren't set for references in the same
6425 h->root.non_ir_ref = 1;
6428 /* Could be done earlier, if h were already available. */
6429 bfd_r_type = aarch64_tls_transition (abfd, info, r_type, h, r_symndx);
6433 /* Create the ifunc sections for static executables. If we
6434 never see an indirect function symbol nor we are building
6435 a static executable, those sections will be empty and
6436 won't appear in output. */
6442 case BFD_RELOC_AARCH64_ADD_LO12:
6443 case BFD_RELOC_AARCH64_ADR_GOT_PAGE:
6444 case BFD_RELOC_AARCH64_ADR_HI21_PCREL:
6445 case BFD_RELOC_AARCH64_CALL26:
6446 case BFD_RELOC_AARCH64_GOT_LD_PREL19:
6447 case BFD_RELOC_AARCH64_JUMP26:
6448 case BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14:
6449 case BFD_RELOC_AARCH64_LD32_GOT_LO12_NC:
6450 case BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15:
6451 case BFD_RELOC_AARCH64_LD64_GOT_LO12_NC:
6452 case BFD_RELOC_AARCH64_NN:
6453 if (htab->root.dynobj == NULL)
6454 htab->root.dynobj = abfd;
6455 if (!_bfd_elf_create_ifunc_sections (htab->root.dynobj, info))
6460 /* It is referenced by a non-shared object. */
6462 h->root.non_ir_ref = 1;
6467 case BFD_RELOC_AARCH64_NN:
6469 /* We don't need to handle relocs into sections not going into
6470 the "real" output. */
6471 if ((sec->flags & SEC_ALLOC) == 0)
6476 if (!bfd_link_pic (info))
6479 h->plt.refcount += 1;
6480 h->pointer_equality_needed = 1;
6483 /* No need to do anything if we're not creating a shared
6485 if (! bfd_link_pic (info))
6489 struct elf_dyn_relocs *p;
6490 struct elf_dyn_relocs **head;
6492 /* We must copy these reloc types into the output file.
6493 Create a reloc section in dynobj and make room for
6497 if (htab->root.dynobj == NULL)
6498 htab->root.dynobj = abfd;
6500 sreloc = _bfd_elf_make_dynamic_reloc_section
6501 (sec, htab->root.dynobj, LOG_FILE_ALIGN, abfd, /*rela? */ TRUE);
6507 /* If this is a global symbol, we count the number of
6508 relocations we need for this symbol. */
6511 struct elf_aarch64_link_hash_entry *eh;
6512 eh = (struct elf_aarch64_link_hash_entry *) h;
6513 head = &eh->dyn_relocs;
6517 /* Track dynamic relocs needed for local syms too.
6518 We really need local syms available to do this
6524 isym = bfd_sym_from_r_symndx (&htab->sym_cache,
6529 s = bfd_section_from_elf_index (abfd, isym->st_shndx);
6533 /* Beware of type punned pointers vs strict aliasing
6535 vpp = &(elf_section_data (s)->local_dynrel);
6536 head = (struct elf_dyn_relocs **) vpp;
6540 if (p == NULL || p->sec != sec)
6542 bfd_size_type amt = sizeof *p;
6543 p = ((struct elf_dyn_relocs *)
6544 bfd_zalloc (htab->root.dynobj, amt));
6557 /* RR: We probably want to keep a consistency check that
6558 there are no dangling GOT_PAGE relocs. */
6559 case BFD_RELOC_AARCH64_ADR_GOT_PAGE:
6560 case BFD_RELOC_AARCH64_GOT_LD_PREL19:
6561 case BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14:
6562 case BFD_RELOC_AARCH64_LD32_GOT_LO12_NC:
6563 case BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15:
6564 case BFD_RELOC_AARCH64_LD64_GOT_LO12_NC:
6565 case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12_NC:
6566 case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21:
6567 case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21:
6568 case BFD_RELOC_AARCH64_TLSDESC_LD32_LO12_NC:
6569 case BFD_RELOC_AARCH64_TLSDESC_LD64_LO12_NC:
6570 case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19:
6571 case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC:
6572 case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21:
6573 case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21:
6574 case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21:
6575 case BFD_RELOC_AARCH64_TLSIE_LD32_GOTTPREL_LO12_NC:
6576 case BFD_RELOC_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC:
6577 case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19:
6578 case BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC:
6579 case BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21:
6580 case BFD_RELOC_AARCH64_TLSLD_ADR_PREL21:
6583 unsigned old_got_type;
6585 got_type = aarch64_reloc_got_type (bfd_r_type);
6589 h->got.refcount += 1;
6590 old_got_type = elf_aarch64_hash_entry (h)->got_type;
6594 struct elf_aarch64_local_symbol *locals;
6596 if (!elfNN_aarch64_allocate_local_symbols
6597 (abfd, symtab_hdr->sh_info))
6600 locals = elf_aarch64_locals (abfd);
6601 BFD_ASSERT (r_symndx < symtab_hdr->sh_info);
6602 locals[r_symndx].got_refcount += 1;
6603 old_got_type = locals[r_symndx].got_type;
6606 /* If a variable is accessed with both general dynamic TLS
6607 methods, two slots may be created. */
6608 if (GOT_TLS_GD_ANY_P (old_got_type) && GOT_TLS_GD_ANY_P (got_type))
6609 got_type |= old_got_type;
6611 /* We will already have issued an error message if there
6612 is a TLS/non-TLS mismatch, based on the symbol type.
6613 So just combine any TLS types needed. */
6614 if (old_got_type != GOT_UNKNOWN && old_got_type != GOT_NORMAL
6615 && got_type != GOT_NORMAL)
6616 got_type |= old_got_type;
6618 /* If the symbol is accessed by both IE and GD methods, we
6619 are able to relax. Turn off the GD flag, without
6620 messing up with any other kind of TLS types that may be
6622 if ((got_type & GOT_TLS_IE) && GOT_TLS_GD_ANY_P (got_type))
6623 got_type &= ~ (GOT_TLSDESC_GD | GOT_TLS_GD);
6625 if (old_got_type != got_type)
6628 elf_aarch64_hash_entry (h)->got_type = got_type;
6631 struct elf_aarch64_local_symbol *locals;
6632 locals = elf_aarch64_locals (abfd);
6633 BFD_ASSERT (r_symndx < symtab_hdr->sh_info);
6634 locals[r_symndx].got_type = got_type;
6638 if (htab->root.dynobj == NULL)
6639 htab->root.dynobj = abfd;
6640 if (! aarch64_elf_create_got_section (htab->root.dynobj, info))
6645 case BFD_RELOC_AARCH64_MOVW_G0_NC:
6646 case BFD_RELOC_AARCH64_MOVW_G1_NC:
6647 case BFD_RELOC_AARCH64_MOVW_G2_NC:
6648 case BFD_RELOC_AARCH64_MOVW_G3:
6649 if (bfd_link_pic (info))
6651 int howto_index = bfd_r_type - BFD_RELOC_AARCH64_RELOC_START;
6652 (*_bfd_error_handler)
6653 (_("%B: relocation %s against `%s' can not be used when making "
6654 "a shared object; recompile with -fPIC"),
6655 abfd, elfNN_aarch64_howto_table[howto_index].name,
6656 (h) ? h->root.root.string : "a local symbol");
6657 bfd_set_error (bfd_error_bad_value);
6661 case BFD_RELOC_AARCH64_ADR_HI21_NC_PCREL:
6662 case BFD_RELOC_AARCH64_ADR_HI21_PCREL:
6663 case BFD_RELOC_AARCH64_ADR_LO21_PCREL:
6664 if (h != NULL && bfd_link_executable (info))
6666 /* If this reloc is in a read-only section, we might
6667 need a copy reloc. We can't check reliably at this
6668 stage whether the section is read-only, as input
6669 sections have not yet been mapped to output sections.
6670 Tentatively set the flag for now, and correct in
6671 adjust_dynamic_symbol. */
6673 h->plt.refcount += 1;
6674 h->pointer_equality_needed = 1;
6676 /* FIXME:: RR need to handle these in shared libraries
6677 and essentially bomb out as these being non-PIC
6678 relocations in shared libraries. */
6681 case BFD_RELOC_AARCH64_CALL26:
6682 case BFD_RELOC_AARCH64_JUMP26:
6683 /* If this is a local symbol then we resolve it
6684 directly without creating a PLT entry. */
6689 if (h->plt.refcount <= 0)
6690 h->plt.refcount = 1;
6692 h->plt.refcount += 1;
6703 /* Treat mapping symbols as special target symbols. */
6706 elfNN_aarch64_is_target_special_symbol (bfd *abfd ATTRIBUTE_UNUSED,
6709 return bfd_is_aarch64_special_symbol_name (sym->name,
6710 BFD_AARCH64_SPECIAL_SYM_TYPE_ANY);
6713 /* This is a copy of elf_find_function () from elf.c except that
6714 AArch64 mapping symbols are ignored when looking for function names. */
6717 aarch64_elf_find_function (bfd *abfd ATTRIBUTE_UNUSED,
6721 const char **filename_ptr,
6722 const char **functionname_ptr)
6724 const char *filename = NULL;
6725 asymbol *func = NULL;
6726 bfd_vma low_func = 0;
6729 for (p = symbols; *p != NULL; p++)
6733 q = (elf_symbol_type *) * p;
6735 switch (ELF_ST_TYPE (q->internal_elf_sym.st_info))
6740 filename = bfd_asymbol_name (&q->symbol);
6744 /* Skip mapping symbols. */
6745 if ((q->symbol.flags & BSF_LOCAL)
6746 && (bfd_is_aarch64_special_symbol_name
6747 (q->symbol.name, BFD_AARCH64_SPECIAL_SYM_TYPE_ANY)))
6750 if (bfd_get_section (&q->symbol) == section
6751 && q->symbol.value >= low_func && q->symbol.value <= offset)
6753 func = (asymbol *) q;
6754 low_func = q->symbol.value;
6764 *filename_ptr = filename;
6765 if (functionname_ptr)
6766 *functionname_ptr = bfd_asymbol_name (func);
6772 /* Find the nearest line to a particular section and offset, for error
6773 reporting. This code is a duplicate of the code in elf.c, except
6774 that it uses aarch64_elf_find_function. */
6777 elfNN_aarch64_find_nearest_line (bfd *abfd,
6781 const char **filename_ptr,
6782 const char **functionname_ptr,
6783 unsigned int *line_ptr,
6784 unsigned int *discriminator_ptr)
6786 bfd_boolean found = FALSE;
6788 if (_bfd_dwarf2_find_nearest_line (abfd, symbols, NULL, section, offset,
6789 filename_ptr, functionname_ptr,
6790 line_ptr, discriminator_ptr,
6791 dwarf_debug_sections, 0,
6792 &elf_tdata (abfd)->dwarf2_find_line_info))
6794 if (!*functionname_ptr)
6795 aarch64_elf_find_function (abfd, symbols, section, offset,
6796 *filename_ptr ? NULL : filename_ptr,
6802 /* Skip _bfd_dwarf1_find_nearest_line since no known AArch64
6803 toolchain uses DWARF1. */
6805 if (!_bfd_stab_section_find_nearest_line (abfd, symbols, section, offset,
6806 &found, filename_ptr,
6807 functionname_ptr, line_ptr,
6808 &elf_tdata (abfd)->line_info))
6811 if (found && (*functionname_ptr || *line_ptr))
6814 if (symbols == NULL)
6817 if (!aarch64_elf_find_function (abfd, symbols, section, offset,
6818 filename_ptr, functionname_ptr))
6826 elfNN_aarch64_find_inliner_info (bfd *abfd,
6827 const char **filename_ptr,
6828 const char **functionname_ptr,
6829 unsigned int *line_ptr)
6832 found = _bfd_dwarf2_find_inliner_info
6833 (abfd, filename_ptr,
6834 functionname_ptr, line_ptr, &elf_tdata (abfd)->dwarf2_find_line_info);
6840 elfNN_aarch64_post_process_headers (bfd *abfd,
6841 struct bfd_link_info *link_info)
6843 Elf_Internal_Ehdr *i_ehdrp; /* ELF file header, internal form. */
6845 i_ehdrp = elf_elfheader (abfd);
6846 i_ehdrp->e_ident[EI_ABIVERSION] = AARCH64_ELF_ABI_VERSION;
6848 _bfd_elf_post_process_headers (abfd, link_info);
6851 static enum elf_reloc_type_class
6852 elfNN_aarch64_reloc_type_class (const struct bfd_link_info *info ATTRIBUTE_UNUSED,
6853 const asection *rel_sec ATTRIBUTE_UNUSED,
6854 const Elf_Internal_Rela *rela)
6856 switch ((int) ELFNN_R_TYPE (rela->r_info))
6858 case AARCH64_R (RELATIVE):
6859 return reloc_class_relative;
6860 case AARCH64_R (JUMP_SLOT):
6861 return reloc_class_plt;
6862 case AARCH64_R (COPY):
6863 return reloc_class_copy;
6865 return reloc_class_normal;
6869 /* Handle an AArch64 specific section when reading an object file. This is
6870 called when bfd_section_from_shdr finds a section with an unknown
6874 elfNN_aarch64_section_from_shdr (bfd *abfd,
6875 Elf_Internal_Shdr *hdr,
6876 const char *name, int shindex)
6878 /* There ought to be a place to keep ELF backend specific flags, but
6879 at the moment there isn't one. We just keep track of the
6880 sections by their name, instead. Fortunately, the ABI gives
6881 names for all the AArch64 specific sections, so we will probably get
6883 switch (hdr->sh_type)
6885 case SHT_AARCH64_ATTRIBUTES:
6892 if (!_bfd_elf_make_section_from_shdr (abfd, hdr, name, shindex))
6898 /* A structure used to record a list of sections, independently
6899 of the next and prev fields in the asection structure. */
6900 typedef struct section_list
6903 struct section_list *next;
6904 struct section_list *prev;
6908 /* Unfortunately we need to keep a list of sections for which
6909 an _aarch64_elf_section_data structure has been allocated. This
6910 is because it is possible for functions like elfNN_aarch64_write_section
6911 to be called on a section which has had an elf_data_structure
6912 allocated for it (and so the used_by_bfd field is valid) but
6913 for which the AArch64 extended version of this structure - the
6914 _aarch64_elf_section_data structure - has not been allocated. */
6915 static section_list *sections_with_aarch64_elf_section_data = NULL;
6918 record_section_with_aarch64_elf_section_data (asection *sec)
6920 struct section_list *entry;
6922 entry = bfd_malloc (sizeof (*entry));
6926 entry->next = sections_with_aarch64_elf_section_data;
6928 if (entry->next != NULL)
6929 entry->next->prev = entry;
6930 sections_with_aarch64_elf_section_data = entry;
6933 static struct section_list *
6934 find_aarch64_elf_section_entry (asection *sec)
6936 struct section_list *entry;
6937 static struct section_list *last_entry = NULL;
6939 /* This is a short cut for the typical case where the sections are added
6940 to the sections_with_aarch64_elf_section_data list in forward order and
6941 then looked up here in backwards order. This makes a real difference
6942 to the ld-srec/sec64k.exp linker test. */
6943 entry = sections_with_aarch64_elf_section_data;
6944 if (last_entry != NULL)
6946 if (last_entry->sec == sec)
6948 else if (last_entry->next != NULL && last_entry->next->sec == sec)
6949 entry = last_entry->next;
6952 for (; entry; entry = entry->next)
6953 if (entry->sec == sec)
6957 /* Record the entry prior to this one - it is the entry we are
6958 most likely to want to locate next time. Also this way if we
6959 have been called from
6960 unrecord_section_with_aarch64_elf_section_data () we will not
6961 be caching a pointer that is about to be freed. */
6962 last_entry = entry->prev;
6968 unrecord_section_with_aarch64_elf_section_data (asection *sec)
6970 struct section_list *entry;
6972 entry = find_aarch64_elf_section_entry (sec);
6976 if (entry->prev != NULL)
6977 entry->prev->next = entry->next;
6978 if (entry->next != NULL)
6979 entry->next->prev = entry->prev;
6980 if (entry == sections_with_aarch64_elf_section_data)
6981 sections_with_aarch64_elf_section_data = entry->next;
6990 struct bfd_link_info *info;
6993 int (*func) (void *, const char *, Elf_Internal_Sym *,
6994 asection *, struct elf_link_hash_entry *);
6995 } output_arch_syminfo;
6997 enum map_symbol_type
7004 /* Output a single mapping symbol. */
7007 elfNN_aarch64_output_map_sym (output_arch_syminfo *osi,
7008 enum map_symbol_type type, bfd_vma offset)
7010 static const char *names[2] = { "$x", "$d" };
7011 Elf_Internal_Sym sym;
7013 sym.st_value = (osi->sec->output_section->vma
7014 + osi->sec->output_offset + offset);
7017 sym.st_info = ELF_ST_INFO (STB_LOCAL, STT_NOTYPE);
7018 sym.st_shndx = osi->sec_shndx;
7019 return osi->func (osi->finfo, names[type], &sym, osi->sec, NULL) == 1;
7024 /* Output mapping symbols for PLT entries associated with H. */
7027 elfNN_aarch64_output_plt_map (struct elf_link_hash_entry *h, void *inf)
7029 output_arch_syminfo *osi = (output_arch_syminfo *) inf;
7032 if (h->root.type == bfd_link_hash_indirect)
7035 if (h->root.type == bfd_link_hash_warning)
7036 /* When warning symbols are created, they **replace** the "real"
7037 entry in the hash table, thus we never get to see the real
7038 symbol in a hash traversal. So look at it now. */
7039 h = (struct elf_link_hash_entry *) h->root.u.i.link;
7041 if (h->plt.offset == (bfd_vma) - 1)
7044 addr = h->plt.offset;
7047 if (!elfNN_aarch64_output_map_sym (osi, AARCH64_MAP_INSN, addr))
7054 /* Output a single local symbol for a generated stub. */
7057 elfNN_aarch64_output_stub_sym (output_arch_syminfo *osi, const char *name,
7058 bfd_vma offset, bfd_vma size)
7060 Elf_Internal_Sym sym;
7062 sym.st_value = (osi->sec->output_section->vma
7063 + osi->sec->output_offset + offset);
7066 sym.st_info = ELF_ST_INFO (STB_LOCAL, STT_FUNC);
7067 sym.st_shndx = osi->sec_shndx;
7068 return osi->func (osi->finfo, name, &sym, osi->sec, NULL) == 1;
7072 aarch64_map_one_stub (struct bfd_hash_entry *gen_entry, void *in_arg)
7074 struct elf_aarch64_stub_hash_entry *stub_entry;
7078 output_arch_syminfo *osi;
7080 /* Massage our args to the form they really have. */
7081 stub_entry = (struct elf_aarch64_stub_hash_entry *) gen_entry;
7082 osi = (output_arch_syminfo *) in_arg;
7084 stub_sec = stub_entry->stub_sec;
7086 /* Ensure this stub is attached to the current section being
7088 if (stub_sec != osi->sec)
7091 addr = (bfd_vma) stub_entry->stub_offset;
7093 stub_name = stub_entry->output_name;
7095 switch (stub_entry->stub_type)
7097 case aarch64_stub_adrp_branch:
7098 if (!elfNN_aarch64_output_stub_sym (osi, stub_name, addr,
7099 sizeof (aarch64_adrp_branch_stub)))
7101 if (!elfNN_aarch64_output_map_sym (osi, AARCH64_MAP_INSN, addr))
7104 case aarch64_stub_long_branch:
7105 if (!elfNN_aarch64_output_stub_sym
7106 (osi, stub_name, addr, sizeof (aarch64_long_branch_stub)))
7108 if (!elfNN_aarch64_output_map_sym (osi, AARCH64_MAP_INSN, addr))
7110 if (!elfNN_aarch64_output_map_sym (osi, AARCH64_MAP_DATA, addr + 16))
7113 case aarch64_stub_erratum_835769_veneer:
7114 if (!elfNN_aarch64_output_stub_sym (osi, stub_name, addr,
7115 sizeof (aarch64_erratum_835769_stub)))
7117 if (!elfNN_aarch64_output_map_sym (osi, AARCH64_MAP_INSN, addr))
7120 case aarch64_stub_erratum_843419_veneer:
7121 if (!elfNN_aarch64_output_stub_sym (osi, stub_name, addr,
7122 sizeof (aarch64_erratum_843419_stub)))
7124 if (!elfNN_aarch64_output_map_sym (osi, AARCH64_MAP_INSN, addr))
7135 /* Output mapping symbols for linker generated sections. */
7138 elfNN_aarch64_output_arch_local_syms (bfd *output_bfd,
7139 struct bfd_link_info *info,
7141 int (*func) (void *, const char *,
7144 struct elf_link_hash_entry
7147 output_arch_syminfo osi;
7148 struct elf_aarch64_link_hash_table *htab;
7150 htab = elf_aarch64_hash_table (info);
7156 /* Long calls stubs. */
7157 if (htab->stub_bfd && htab->stub_bfd->sections)
7161 for (stub_sec = htab->stub_bfd->sections;
7162 stub_sec != NULL; stub_sec = stub_sec->next)
7164 /* Ignore non-stub sections. */
7165 if (!strstr (stub_sec->name, STUB_SUFFIX))
7170 osi.sec_shndx = _bfd_elf_section_from_bfd_section
7171 (output_bfd, osi.sec->output_section);
7173 /* The first instruction in a stub is always a branch. */
7174 if (!elfNN_aarch64_output_map_sym (&osi, AARCH64_MAP_INSN, 0))
7177 bfd_hash_traverse (&htab->stub_hash_table, aarch64_map_one_stub,
7182 /* Finally, output mapping symbols for the PLT. */
7183 if (!htab->root.splt || htab->root.splt->size == 0)
7186 /* For now live without mapping symbols for the plt. */
7187 osi.sec_shndx = _bfd_elf_section_from_bfd_section
7188 (output_bfd, htab->root.splt->output_section);
7189 osi.sec = htab->root.splt;
7191 elf_link_hash_traverse (&htab->root, elfNN_aarch64_output_plt_map,
7198 /* Allocate target specific section data. */
7201 elfNN_aarch64_new_section_hook (bfd *abfd, asection *sec)
7203 if (!sec->used_by_bfd)
7205 _aarch64_elf_section_data *sdata;
7206 bfd_size_type amt = sizeof (*sdata);
7208 sdata = bfd_zalloc (abfd, amt);
7211 sec->used_by_bfd = sdata;
7214 record_section_with_aarch64_elf_section_data (sec);
7216 return _bfd_elf_new_section_hook (abfd, sec);
7221 unrecord_section_via_map_over_sections (bfd *abfd ATTRIBUTE_UNUSED,
7223 void *ignore ATTRIBUTE_UNUSED)
7225 unrecord_section_with_aarch64_elf_section_data (sec);
7229 elfNN_aarch64_close_and_cleanup (bfd *abfd)
7232 bfd_map_over_sections (abfd,
7233 unrecord_section_via_map_over_sections, NULL);
7235 return _bfd_elf_close_and_cleanup (abfd);
7239 elfNN_aarch64_bfd_free_cached_info (bfd *abfd)
7242 bfd_map_over_sections (abfd,
7243 unrecord_section_via_map_over_sections, NULL);
7245 return _bfd_free_cached_info (abfd);
7248 /* Create dynamic sections. This is different from the ARM backend in that
7249 the got, plt, gotplt and their relocation sections are all created in the
7250 standard part of the bfd elf backend. */
7253 elfNN_aarch64_create_dynamic_sections (bfd *dynobj,
7254 struct bfd_link_info *info)
7256 struct elf_aarch64_link_hash_table *htab;
7258 /* We need to create .got section. */
7259 if (!aarch64_elf_create_got_section (dynobj, info))
7262 if (!_bfd_elf_create_dynamic_sections (dynobj, info))
7265 htab = elf_aarch64_hash_table (info);
7266 htab->sdynbss = bfd_get_linker_section (dynobj, ".dynbss");
7267 if (!bfd_link_pic (info))
7268 htab->srelbss = bfd_get_linker_section (dynobj, ".rela.bss");
7270 if (!htab->sdynbss || (!bfd_link_pic (info) && !htab->srelbss))
7277 /* Allocate space in .plt, .got and associated reloc sections for
7281 elfNN_aarch64_allocate_dynrelocs (struct elf_link_hash_entry *h, void *inf)
7283 struct bfd_link_info *info;
7284 struct elf_aarch64_link_hash_table *htab;
7285 struct elf_aarch64_link_hash_entry *eh;
7286 struct elf_dyn_relocs *p;
7288 /* An example of a bfd_link_hash_indirect symbol is versioned
7289 symbol. For example: __gxx_personality_v0(bfd_link_hash_indirect)
7290 -> __gxx_personality_v0(bfd_link_hash_defined)
7292 There is no need to process bfd_link_hash_indirect symbols here
7293 because we will also be presented with the concrete instance of
7294 the symbol and elfNN_aarch64_copy_indirect_symbol () will have been
7295 called to copy all relevant data from the generic to the concrete
7298 if (h->root.type == bfd_link_hash_indirect)
7301 if (h->root.type == bfd_link_hash_warning)
7302 h = (struct elf_link_hash_entry *) h->root.u.i.link;
7304 info = (struct bfd_link_info *) inf;
7305 htab = elf_aarch64_hash_table (info);
7307 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle it
7308 here if it is defined and referenced in a non-shared object. */
7309 if (h->type == STT_GNU_IFUNC
7312 else if (htab->root.dynamic_sections_created && h->plt.refcount > 0)
7314 /* Make sure this symbol is output as a dynamic symbol.
7315 Undefined weak syms won't yet be marked as dynamic. */
7316 if (h->dynindx == -1 && !h->forced_local)
7318 if (!bfd_elf_link_record_dynamic_symbol (info, h))
7322 if (bfd_link_pic (info) || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h))
7324 asection *s = htab->root.splt;
7326 /* If this is the first .plt entry, make room for the special
7329 s->size += htab->plt_header_size;
7331 h->plt.offset = s->size;
7333 /* If this symbol is not defined in a regular file, and we are
7334 not generating a shared library, then set the symbol to this
7335 location in the .plt. This is required to make function
7336 pointers compare as equal between the normal executable and
7337 the shared library. */
7338 if (!bfd_link_pic (info) && !h->def_regular)
7340 h->root.u.def.section = s;
7341 h->root.u.def.value = h->plt.offset;
7344 /* Make room for this entry. For now we only create the
7345 small model PLT entries. We later need to find a way
7346 of relaxing into these from the large model PLT entries. */
7347 s->size += PLT_SMALL_ENTRY_SIZE;
7349 /* We also need to make an entry in the .got.plt section, which
7350 will be placed in the .got section by the linker script. */
7351 htab->root.sgotplt->size += GOT_ENTRY_SIZE;
7353 /* We also need to make an entry in the .rela.plt section. */
7354 htab->root.srelplt->size += RELOC_SIZE (htab);
7356 /* We need to ensure that all GOT entries that serve the PLT
7357 are consecutive with the special GOT slots [0] [1] and
7358 [2]. Any addtional relocations, such as
7359 R_AARCH64_TLSDESC, must be placed after the PLT related
7360 entries. We abuse the reloc_count such that during
7361 sizing we adjust reloc_count to indicate the number of
7362 PLT related reserved entries. In subsequent phases when
7363 filling in the contents of the reloc entries, PLT related
7364 entries are placed by computing their PLT index (0
7365 .. reloc_count). While other none PLT relocs are placed
7366 at the slot indicated by reloc_count and reloc_count is
7369 htab->root.srelplt->reloc_count++;
7373 h->plt.offset = (bfd_vma) - 1;
7379 h->plt.offset = (bfd_vma) - 1;
7383 eh = (struct elf_aarch64_link_hash_entry *) h;
7384 eh->tlsdesc_got_jump_table_offset = (bfd_vma) - 1;
7386 if (h->got.refcount > 0)
7389 unsigned got_type = elf_aarch64_hash_entry (h)->got_type;
7391 h->got.offset = (bfd_vma) - 1;
7393 dyn = htab->root.dynamic_sections_created;
7395 /* Make sure this symbol is output as a dynamic symbol.
7396 Undefined weak syms won't yet be marked as dynamic. */
7397 if (dyn && h->dynindx == -1 && !h->forced_local)
7399 if (!bfd_elf_link_record_dynamic_symbol (info, h))
7403 if (got_type == GOT_UNKNOWN)
7406 else if (got_type == GOT_NORMAL)
7408 h->got.offset = htab->root.sgot->size;
7409 htab->root.sgot->size += GOT_ENTRY_SIZE;
7410 if ((ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
7411 || h->root.type != bfd_link_hash_undefweak)
7412 && (bfd_link_pic (info)
7413 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, 0, h)))
7415 htab->root.srelgot->size += RELOC_SIZE (htab);
7421 if (got_type & GOT_TLSDESC_GD)
7423 eh->tlsdesc_got_jump_table_offset =
7424 (htab->root.sgotplt->size
7425 - aarch64_compute_jump_table_size (htab));
7426 htab->root.sgotplt->size += GOT_ENTRY_SIZE * 2;
7427 h->got.offset = (bfd_vma) - 2;
7430 if (got_type & GOT_TLS_GD)
7432 h->got.offset = htab->root.sgot->size;
7433 htab->root.sgot->size += GOT_ENTRY_SIZE * 2;
7436 if (got_type & GOT_TLS_IE)
7438 h->got.offset = htab->root.sgot->size;
7439 htab->root.sgot->size += GOT_ENTRY_SIZE;
7442 indx = h && h->dynindx != -1 ? h->dynindx : 0;
7443 if ((ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
7444 || h->root.type != bfd_link_hash_undefweak)
7445 && (bfd_link_pic (info)
7447 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, 0, h)))
7449 if (got_type & GOT_TLSDESC_GD)
7451 htab->root.srelplt->size += RELOC_SIZE (htab);
7452 /* Note reloc_count not incremented here! We have
7453 already adjusted reloc_count for this relocation
7456 /* TLSDESC PLT is now needed, but not yet determined. */
7457 htab->tlsdesc_plt = (bfd_vma) - 1;
7460 if (got_type & GOT_TLS_GD)
7461 htab->root.srelgot->size += RELOC_SIZE (htab) * 2;
7463 if (got_type & GOT_TLS_IE)
7464 htab->root.srelgot->size += RELOC_SIZE (htab);
7470 h->got.offset = (bfd_vma) - 1;
7473 if (eh->dyn_relocs == NULL)
7476 /* In the shared -Bsymbolic case, discard space allocated for
7477 dynamic pc-relative relocs against symbols which turn out to be
7478 defined in regular objects. For the normal shared case, discard
7479 space for pc-relative relocs that have become local due to symbol
7480 visibility changes. */
7482 if (bfd_link_pic (info))
7484 /* Relocs that use pc_count are those that appear on a call
7485 insn, or certain REL relocs that can generated via assembly.
7486 We want calls to protected symbols to resolve directly to the
7487 function rather than going via the plt. If people want
7488 function pointer comparisons to work as expected then they
7489 should avoid writing weird assembly. */
7490 if (SYMBOL_CALLS_LOCAL (info, h))
7492 struct elf_dyn_relocs **pp;
7494 for (pp = &eh->dyn_relocs; (p = *pp) != NULL;)
7496 p->count -= p->pc_count;
7505 /* Also discard relocs on undefined weak syms with non-default
7507 if (eh->dyn_relocs != NULL && h->root.type == bfd_link_hash_undefweak)
7509 if (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT)
7510 eh->dyn_relocs = NULL;
7512 /* Make sure undefined weak symbols are output as a dynamic
7514 else if (h->dynindx == -1
7516 && !bfd_elf_link_record_dynamic_symbol (info, h))
7521 else if (ELIMINATE_COPY_RELOCS)
7523 /* For the non-shared case, discard space for relocs against
7524 symbols which turn out to need copy relocs or are not
7530 || (htab->root.dynamic_sections_created
7531 && (h->root.type == bfd_link_hash_undefweak
7532 || h->root.type == bfd_link_hash_undefined))))
7534 /* Make sure this symbol is output as a dynamic symbol.
7535 Undefined weak syms won't yet be marked as dynamic. */
7536 if (h->dynindx == -1
7538 && !bfd_elf_link_record_dynamic_symbol (info, h))
7541 /* If that succeeded, we know we'll be keeping all the
7543 if (h->dynindx != -1)
7547 eh->dyn_relocs = NULL;
7552 /* Finally, allocate space. */
7553 for (p = eh->dyn_relocs; p != NULL; p = p->next)
7557 sreloc = elf_section_data (p->sec)->sreloc;
7559 BFD_ASSERT (sreloc != NULL);
7561 sreloc->size += p->count * RELOC_SIZE (htab);
7567 /* Allocate space in .plt, .got and associated reloc sections for
7568 ifunc dynamic relocs. */
7571 elfNN_aarch64_allocate_ifunc_dynrelocs (struct elf_link_hash_entry *h,
7574 struct bfd_link_info *info;
7575 struct elf_aarch64_link_hash_table *htab;
7576 struct elf_aarch64_link_hash_entry *eh;
7578 /* An example of a bfd_link_hash_indirect symbol is versioned
7579 symbol. For example: __gxx_personality_v0(bfd_link_hash_indirect)
7580 -> __gxx_personality_v0(bfd_link_hash_defined)
7582 There is no need to process bfd_link_hash_indirect symbols here
7583 because we will also be presented with the concrete instance of
7584 the symbol and elfNN_aarch64_copy_indirect_symbol () will have been
7585 called to copy all relevant data from the generic to the concrete
7588 if (h->root.type == bfd_link_hash_indirect)
7591 if (h->root.type == bfd_link_hash_warning)
7592 h = (struct elf_link_hash_entry *) h->root.u.i.link;
7594 info = (struct bfd_link_info *) inf;
7595 htab = elf_aarch64_hash_table (info);
7597 eh = (struct elf_aarch64_link_hash_entry *) h;
7599 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle it
7600 here if it is defined and referenced in a non-shared object. */
7601 if (h->type == STT_GNU_IFUNC
7603 return _bfd_elf_allocate_ifunc_dyn_relocs (info, h,
7605 htab->plt_entry_size,
7606 htab->plt_header_size,
7611 /* Allocate space in .plt, .got and associated reloc sections for
7612 local dynamic relocs. */
7615 elfNN_aarch64_allocate_local_dynrelocs (void **slot, void *inf)
7617 struct elf_link_hash_entry *h
7618 = (struct elf_link_hash_entry *) *slot;
7620 if (h->type != STT_GNU_IFUNC
7624 || h->root.type != bfd_link_hash_defined)
7627 return elfNN_aarch64_allocate_dynrelocs (h, inf);
7630 /* Allocate space in .plt, .got and associated reloc sections for
7631 local ifunc dynamic relocs. */
7634 elfNN_aarch64_allocate_local_ifunc_dynrelocs (void **slot, void *inf)
7636 struct elf_link_hash_entry *h
7637 = (struct elf_link_hash_entry *) *slot;
7639 if (h->type != STT_GNU_IFUNC
7643 || h->root.type != bfd_link_hash_defined)
7646 return elfNN_aarch64_allocate_ifunc_dynrelocs (h, inf);
7649 /* Find any dynamic relocs that apply to read-only sections. */
7652 aarch64_readonly_dynrelocs (struct elf_link_hash_entry * h, void * inf)
7654 struct elf_aarch64_link_hash_entry * eh;
7655 struct elf_dyn_relocs * p;
7657 eh = (struct elf_aarch64_link_hash_entry *) h;
7658 for (p = eh->dyn_relocs; p != NULL; p = p->next)
7660 asection *s = p->sec;
7662 if (s != NULL && (s->flags & SEC_READONLY) != 0)
7664 struct bfd_link_info *info = (struct bfd_link_info *) inf;
7666 info->flags |= DF_TEXTREL;
7668 /* Not an error, just cut short the traversal. */
7675 /* This is the most important function of all . Innocuosly named
7678 elfNN_aarch64_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
7679 struct bfd_link_info *info)
7681 struct elf_aarch64_link_hash_table *htab;
7687 htab = elf_aarch64_hash_table ((info));
7688 dynobj = htab->root.dynobj;
7690 BFD_ASSERT (dynobj != NULL);
7692 if (htab->root.dynamic_sections_created)
7694 if (bfd_link_executable (info))
7696 s = bfd_get_linker_section (dynobj, ".interp");
7699 s->size = sizeof ELF_DYNAMIC_INTERPRETER;
7700 s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
7704 /* Set up .got offsets for local syms, and space for local dynamic
7706 for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link.next)
7708 struct elf_aarch64_local_symbol *locals = NULL;
7709 Elf_Internal_Shdr *symtab_hdr;
7713 if (!is_aarch64_elf (ibfd))
7716 for (s = ibfd->sections; s != NULL; s = s->next)
7718 struct elf_dyn_relocs *p;
7720 for (p = (struct elf_dyn_relocs *)
7721 (elf_section_data (s)->local_dynrel); p != NULL; p = p->next)
7723 if (!bfd_is_abs_section (p->sec)
7724 && bfd_is_abs_section (p->sec->output_section))
7726 /* Input section has been discarded, either because
7727 it is a copy of a linkonce section or due to
7728 linker script /DISCARD/, so we'll be discarding
7731 else if (p->count != 0)
7733 srel = elf_section_data (p->sec)->sreloc;
7734 srel->size += p->count * RELOC_SIZE (htab);
7735 if ((p->sec->output_section->flags & SEC_READONLY) != 0)
7736 info->flags |= DF_TEXTREL;
7741 locals = elf_aarch64_locals (ibfd);
7745 symtab_hdr = &elf_symtab_hdr (ibfd);
7746 srel = htab->root.srelgot;
7747 for (i = 0; i < symtab_hdr->sh_info; i++)
7749 locals[i].got_offset = (bfd_vma) - 1;
7750 locals[i].tlsdesc_got_jump_table_offset = (bfd_vma) - 1;
7751 if (locals[i].got_refcount > 0)
7753 unsigned got_type = locals[i].got_type;
7754 if (got_type & GOT_TLSDESC_GD)
7756 locals[i].tlsdesc_got_jump_table_offset =
7757 (htab->root.sgotplt->size
7758 - aarch64_compute_jump_table_size (htab));
7759 htab->root.sgotplt->size += GOT_ENTRY_SIZE * 2;
7760 locals[i].got_offset = (bfd_vma) - 2;
7763 if (got_type & GOT_TLS_GD)
7765 locals[i].got_offset = htab->root.sgot->size;
7766 htab->root.sgot->size += GOT_ENTRY_SIZE * 2;
7769 if (got_type & GOT_TLS_IE
7770 || got_type & GOT_NORMAL)
7772 locals[i].got_offset = htab->root.sgot->size;
7773 htab->root.sgot->size += GOT_ENTRY_SIZE;
7776 if (got_type == GOT_UNKNOWN)
7780 if (bfd_link_pic (info))
7782 if (got_type & GOT_TLSDESC_GD)
7784 htab->root.srelplt->size += RELOC_SIZE (htab);
7785 /* Note RELOC_COUNT not incremented here! */
7786 htab->tlsdesc_plt = (bfd_vma) - 1;
7789 if (got_type & GOT_TLS_GD)
7790 htab->root.srelgot->size += RELOC_SIZE (htab) * 2;
7792 if (got_type & GOT_TLS_IE
7793 || got_type & GOT_NORMAL)
7794 htab->root.srelgot->size += RELOC_SIZE (htab);
7799 locals[i].got_refcount = (bfd_vma) - 1;
7805 /* Allocate global sym .plt and .got entries, and space for global
7806 sym dynamic relocs. */
7807 elf_link_hash_traverse (&htab->root, elfNN_aarch64_allocate_dynrelocs,
7810 /* Allocate global ifunc sym .plt and .got entries, and space for global
7811 ifunc sym dynamic relocs. */
7812 elf_link_hash_traverse (&htab->root, elfNN_aarch64_allocate_ifunc_dynrelocs,
7815 /* Allocate .plt and .got entries, and space for local symbols. */
7816 htab_traverse (htab->loc_hash_table,
7817 elfNN_aarch64_allocate_local_dynrelocs,
7820 /* Allocate .plt and .got entries, and space for local ifunc symbols. */
7821 htab_traverse (htab->loc_hash_table,
7822 elfNN_aarch64_allocate_local_ifunc_dynrelocs,
7825 /* For every jump slot reserved in the sgotplt, reloc_count is
7826 incremented. However, when we reserve space for TLS descriptors,
7827 it's not incremented, so in order to compute the space reserved
7828 for them, it suffices to multiply the reloc count by the jump
7831 if (htab->root.srelplt)
7832 htab->sgotplt_jump_table_size = aarch64_compute_jump_table_size (htab);
7834 if (htab->tlsdesc_plt)
7836 if (htab->root.splt->size == 0)
7837 htab->root.splt->size += PLT_ENTRY_SIZE;
7839 htab->tlsdesc_plt = htab->root.splt->size;
7840 htab->root.splt->size += PLT_TLSDESC_ENTRY_SIZE;
7842 /* If we're not using lazy TLS relocations, don't generate the
7843 GOT entry required. */
7844 if (!(info->flags & DF_BIND_NOW))
7846 htab->dt_tlsdesc_got = htab->root.sgot->size;
7847 htab->root.sgot->size += GOT_ENTRY_SIZE;
7851 /* Init mapping symbols information to use later to distingush between
7852 code and data while scanning for errata. */
7853 if (htab->fix_erratum_835769 || htab->fix_erratum_843419)
7854 for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link.next)
7856 if (!is_aarch64_elf (ibfd))
7858 bfd_elfNN_aarch64_init_maps (ibfd);
7861 /* We now have determined the sizes of the various dynamic sections.
7862 Allocate memory for them. */
7864 for (s = dynobj->sections; s != NULL; s = s->next)
7866 if ((s->flags & SEC_LINKER_CREATED) == 0)
7869 if (s == htab->root.splt
7870 || s == htab->root.sgot
7871 || s == htab->root.sgotplt
7872 || s == htab->root.iplt
7873 || s == htab->root.igotplt || s == htab->sdynbss)
7875 /* Strip this section if we don't need it; see the
7878 else if (CONST_STRNEQ (bfd_get_section_name (dynobj, s), ".rela"))
7880 if (s->size != 0 && s != htab->root.srelplt)
7883 /* We use the reloc_count field as a counter if we need
7884 to copy relocs into the output file. */
7885 if (s != htab->root.srelplt)
7890 /* It's not one of our sections, so don't allocate space. */
7896 /* If we don't need this section, strip it from the
7897 output file. This is mostly to handle .rela.bss and
7898 .rela.plt. We must create both sections in
7899 create_dynamic_sections, because they must be created
7900 before the linker maps input sections to output
7901 sections. The linker does that before
7902 adjust_dynamic_symbol is called, and it is that
7903 function which decides whether anything needs to go
7904 into these sections. */
7906 s->flags |= SEC_EXCLUDE;
7910 if ((s->flags & SEC_HAS_CONTENTS) == 0)
7913 /* Allocate memory for the section contents. We use bfd_zalloc
7914 here in case unused entries are not reclaimed before the
7915 section's contents are written out. This should not happen,
7916 but this way if it does, we get a R_AARCH64_NONE reloc instead
7918 s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->size);
7919 if (s->contents == NULL)
7923 if (htab->root.dynamic_sections_created)
7925 /* Add some entries to the .dynamic section. We fill in the
7926 values later, in elfNN_aarch64_finish_dynamic_sections, but we
7927 must add the entries now so that we get the correct size for
7928 the .dynamic section. The DT_DEBUG entry is filled in by the
7929 dynamic linker and used by the debugger. */
7930 #define add_dynamic_entry(TAG, VAL) \
7931 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
7933 if (bfd_link_executable (info))
7935 if (!add_dynamic_entry (DT_DEBUG, 0))
7939 if (htab->root.splt->size != 0)
7941 if (!add_dynamic_entry (DT_PLTGOT, 0)
7942 || !add_dynamic_entry (DT_PLTRELSZ, 0)
7943 || !add_dynamic_entry (DT_PLTREL, DT_RELA)
7944 || !add_dynamic_entry (DT_JMPREL, 0))
7947 if (htab->tlsdesc_plt
7948 && (!add_dynamic_entry (DT_TLSDESC_PLT, 0)
7949 || !add_dynamic_entry (DT_TLSDESC_GOT, 0)))
7955 if (!add_dynamic_entry (DT_RELA, 0)
7956 || !add_dynamic_entry (DT_RELASZ, 0)
7957 || !add_dynamic_entry (DT_RELAENT, RELOC_SIZE (htab)))
7960 /* If any dynamic relocs apply to a read-only section,
7961 then we need a DT_TEXTREL entry. */
7962 if ((info->flags & DF_TEXTREL) == 0)
7963 elf_link_hash_traverse (& htab->root, aarch64_readonly_dynrelocs,
7966 if ((info->flags & DF_TEXTREL) != 0)
7968 if (!add_dynamic_entry (DT_TEXTREL, 0))
7973 #undef add_dynamic_entry
7979 elf_aarch64_update_plt_entry (bfd *output_bfd,
7980 bfd_reloc_code_real_type r_type,
7981 bfd_byte *plt_entry, bfd_vma value)
7983 reloc_howto_type *howto = elfNN_aarch64_howto_from_bfd_reloc (r_type);
7985 _bfd_aarch64_elf_put_addend (output_bfd, plt_entry, r_type, howto, value);
7989 elfNN_aarch64_create_small_pltn_entry (struct elf_link_hash_entry *h,
7990 struct elf_aarch64_link_hash_table
7991 *htab, bfd *output_bfd,
7992 struct bfd_link_info *info)
7994 bfd_byte *plt_entry;
7997 bfd_vma gotplt_entry_address;
7998 bfd_vma plt_entry_address;
7999 Elf_Internal_Rela rela;
8001 asection *plt, *gotplt, *relplt;
8003 /* When building a static executable, use .iplt, .igot.plt and
8004 .rela.iplt sections for STT_GNU_IFUNC symbols. */
8005 if (htab->root.splt != NULL)
8007 plt = htab->root.splt;
8008 gotplt = htab->root.sgotplt;
8009 relplt = htab->root.srelplt;
8013 plt = htab->root.iplt;
8014 gotplt = htab->root.igotplt;
8015 relplt = htab->root.irelplt;
8018 /* Get the index in the procedure linkage table which
8019 corresponds to this symbol. This is the index of this symbol
8020 in all the symbols for which we are making plt entries. The
8021 first entry in the procedure linkage table is reserved.
8023 Get the offset into the .got table of the entry that
8024 corresponds to this function. Each .got entry is GOT_ENTRY_SIZE
8025 bytes. The first three are reserved for the dynamic linker.
8027 For static executables, we don't reserve anything. */
8029 if (plt == htab->root.splt)
8031 plt_index = (h->plt.offset - htab->plt_header_size) / htab->plt_entry_size;
8032 got_offset = (plt_index + 3) * GOT_ENTRY_SIZE;
8036 plt_index = h->plt.offset / htab->plt_entry_size;
8037 got_offset = plt_index * GOT_ENTRY_SIZE;
8040 plt_entry = plt->contents + h->plt.offset;
8041 plt_entry_address = plt->output_section->vma
8042 + plt->output_offset + h->plt.offset;
8043 gotplt_entry_address = gotplt->output_section->vma +
8044 gotplt->output_offset + got_offset;
8046 /* Copy in the boiler-plate for the PLTn entry. */
8047 memcpy (plt_entry, elfNN_aarch64_small_plt_entry, PLT_SMALL_ENTRY_SIZE);
8049 /* Fill in the top 21 bits for this: ADRP x16, PLT_GOT + n * 8.
8050 ADRP: ((PG(S+A)-PG(P)) >> 12) & 0x1fffff */
8051 elf_aarch64_update_plt_entry (output_bfd, BFD_RELOC_AARCH64_ADR_HI21_PCREL,
8053 PG (gotplt_entry_address) -
8054 PG (plt_entry_address));
8056 /* Fill in the lo12 bits for the load from the pltgot. */
8057 elf_aarch64_update_plt_entry (output_bfd, BFD_RELOC_AARCH64_LDSTNN_LO12,
8059 PG_OFFSET (gotplt_entry_address));
8061 /* Fill in the lo12 bits for the add from the pltgot entry. */
8062 elf_aarch64_update_plt_entry (output_bfd, BFD_RELOC_AARCH64_ADD_LO12,
8064 PG_OFFSET (gotplt_entry_address));
8066 /* All the GOTPLT Entries are essentially initialized to PLT0. */
8067 bfd_put_NN (output_bfd,
8068 plt->output_section->vma + plt->output_offset,
8069 gotplt->contents + got_offset);
8071 rela.r_offset = gotplt_entry_address;
8073 if (h->dynindx == -1
8074 || ((bfd_link_executable (info)
8075 || ELF_ST_VISIBILITY (h->other) != STV_DEFAULT)
8077 && h->type == STT_GNU_IFUNC))
8079 /* If an STT_GNU_IFUNC symbol is locally defined, generate
8080 R_AARCH64_IRELATIVE instead of R_AARCH64_JUMP_SLOT. */
8081 rela.r_info = ELFNN_R_INFO (0, AARCH64_R (IRELATIVE));
8082 rela.r_addend = (h->root.u.def.value
8083 + h->root.u.def.section->output_section->vma
8084 + h->root.u.def.section->output_offset);
8088 /* Fill in the entry in the .rela.plt section. */
8089 rela.r_info = ELFNN_R_INFO (h->dynindx, AARCH64_R (JUMP_SLOT));
8093 /* Compute the relocation entry to used based on PLT index and do
8094 not adjust reloc_count. The reloc_count has already been adjusted
8095 to account for this entry. */
8096 loc = relplt->contents + plt_index * RELOC_SIZE (htab);
8097 bfd_elfNN_swap_reloca_out (output_bfd, &rela, loc);
8100 /* Size sections even though they're not dynamic. We use it to setup
8101 _TLS_MODULE_BASE_, if needed. */
8104 elfNN_aarch64_always_size_sections (bfd *output_bfd,
8105 struct bfd_link_info *info)
8109 if (bfd_link_relocatable (info))
8112 tls_sec = elf_hash_table (info)->tls_sec;
8116 struct elf_link_hash_entry *tlsbase;
8118 tlsbase = elf_link_hash_lookup (elf_hash_table (info),
8119 "_TLS_MODULE_BASE_", TRUE, TRUE, FALSE);
8123 struct bfd_link_hash_entry *h = NULL;
8124 const struct elf_backend_data *bed =
8125 get_elf_backend_data (output_bfd);
8127 if (!(_bfd_generic_link_add_one_symbol
8128 (info, output_bfd, "_TLS_MODULE_BASE_", BSF_LOCAL,
8129 tls_sec, 0, NULL, FALSE, bed->collect, &h)))
8132 tlsbase->type = STT_TLS;
8133 tlsbase = (struct elf_link_hash_entry *) h;
8134 tlsbase->def_regular = 1;
8135 tlsbase->other = STV_HIDDEN;
8136 (*bed->elf_backend_hide_symbol) (info, tlsbase, TRUE);
8143 /* Finish up dynamic symbol handling. We set the contents of various
8144 dynamic sections here. */
8146 elfNN_aarch64_finish_dynamic_symbol (bfd *output_bfd,
8147 struct bfd_link_info *info,
8148 struct elf_link_hash_entry *h,
8149 Elf_Internal_Sym *sym)
8151 struct elf_aarch64_link_hash_table *htab;
8152 htab = elf_aarch64_hash_table (info);
8154 if (h->plt.offset != (bfd_vma) - 1)
8156 asection *plt, *gotplt, *relplt;
8158 /* This symbol has an entry in the procedure linkage table. Set
8161 /* When building a static executable, use .iplt, .igot.plt and
8162 .rela.iplt sections for STT_GNU_IFUNC symbols. */
8163 if (htab->root.splt != NULL)
8165 plt = htab->root.splt;
8166 gotplt = htab->root.sgotplt;
8167 relplt = htab->root.srelplt;
8171 plt = htab->root.iplt;
8172 gotplt = htab->root.igotplt;
8173 relplt = htab->root.irelplt;
8176 /* This symbol has an entry in the procedure linkage table. Set
8178 if ((h->dynindx == -1
8179 && !((h->forced_local || bfd_link_executable (info))
8181 && h->type == STT_GNU_IFUNC))
8187 elfNN_aarch64_create_small_pltn_entry (h, htab, output_bfd, info);
8188 if (!h->def_regular)
8190 /* Mark the symbol as undefined, rather than as defined in
8191 the .plt section. */
8192 sym->st_shndx = SHN_UNDEF;
8193 /* If the symbol is weak we need to clear the value.
8194 Otherwise, the PLT entry would provide a definition for
8195 the symbol even if the symbol wasn't defined anywhere,
8196 and so the symbol would never be NULL. Leave the value if
8197 there were any relocations where pointer equality matters
8198 (this is a clue for the dynamic linker, to make function
8199 pointer comparisons work between an application and shared
8201 if (!h->ref_regular_nonweak || !h->pointer_equality_needed)
8206 if (h->got.offset != (bfd_vma) - 1
8207 && elf_aarch64_hash_entry (h)->got_type == GOT_NORMAL)
8209 Elf_Internal_Rela rela;
8212 /* This symbol has an entry in the global offset table. Set it
8214 if (htab->root.sgot == NULL || htab->root.srelgot == NULL)
8217 rela.r_offset = (htab->root.sgot->output_section->vma
8218 + htab->root.sgot->output_offset
8219 + (h->got.offset & ~(bfd_vma) 1));
8222 && h->type == STT_GNU_IFUNC)
8224 if (bfd_link_pic (info))
8226 /* Generate R_AARCH64_GLOB_DAT. */
8233 if (!h->pointer_equality_needed)
8236 /* For non-shared object, we can't use .got.plt, which
8237 contains the real function address if we need pointer
8238 equality. We load the GOT entry with the PLT entry. */
8239 plt = htab->root.splt ? htab->root.splt : htab->root.iplt;
8240 bfd_put_NN (output_bfd, (plt->output_section->vma
8241 + plt->output_offset
8243 htab->root.sgot->contents
8244 + (h->got.offset & ~(bfd_vma) 1));
8248 else if (bfd_link_pic (info) && SYMBOL_REFERENCES_LOCAL (info, h))
8250 if (!h->def_regular)
8253 BFD_ASSERT ((h->got.offset & 1) != 0);
8254 rela.r_info = ELFNN_R_INFO (0, AARCH64_R (RELATIVE));
8255 rela.r_addend = (h->root.u.def.value
8256 + h->root.u.def.section->output_section->vma
8257 + h->root.u.def.section->output_offset);
8262 BFD_ASSERT ((h->got.offset & 1) == 0);
8263 bfd_put_NN (output_bfd, (bfd_vma) 0,
8264 htab->root.sgot->contents + h->got.offset);
8265 rela.r_info = ELFNN_R_INFO (h->dynindx, AARCH64_R (GLOB_DAT));
8269 loc = htab->root.srelgot->contents;
8270 loc += htab->root.srelgot->reloc_count++ * RELOC_SIZE (htab);
8271 bfd_elfNN_swap_reloca_out (output_bfd, &rela, loc);
8276 Elf_Internal_Rela rela;
8279 /* This symbol needs a copy reloc. Set it up. */
8281 if (h->dynindx == -1
8282 || (h->root.type != bfd_link_hash_defined
8283 && h->root.type != bfd_link_hash_defweak)
8284 || htab->srelbss == NULL)
8287 rela.r_offset = (h->root.u.def.value
8288 + h->root.u.def.section->output_section->vma
8289 + h->root.u.def.section->output_offset);
8290 rela.r_info = ELFNN_R_INFO (h->dynindx, AARCH64_R (COPY));
8292 loc = htab->srelbss->contents;
8293 loc += htab->srelbss->reloc_count++ * RELOC_SIZE (htab);
8294 bfd_elfNN_swap_reloca_out (output_bfd, &rela, loc);
8297 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. SYM may
8298 be NULL for local symbols. */
8300 && (h == elf_hash_table (info)->hdynamic
8301 || h == elf_hash_table (info)->hgot))
8302 sym->st_shndx = SHN_ABS;
8307 /* Finish up local dynamic symbol handling. We set the contents of
8308 various dynamic sections here. */
8311 elfNN_aarch64_finish_local_dynamic_symbol (void **slot, void *inf)
8313 struct elf_link_hash_entry *h
8314 = (struct elf_link_hash_entry *) *slot;
8315 struct bfd_link_info *info
8316 = (struct bfd_link_info *) inf;
8318 return elfNN_aarch64_finish_dynamic_symbol (info->output_bfd,
8323 elfNN_aarch64_init_small_plt0_entry (bfd *output_bfd ATTRIBUTE_UNUSED,
8324 struct elf_aarch64_link_hash_table
8327 /* Fill in PLT0. Fixme:RR Note this doesn't distinguish between
8328 small and large plts and at the minute just generates
8331 /* PLT0 of the small PLT looks like this in ELF64 -
8332 stp x16, x30, [sp, #-16]! // Save the reloc and lr on stack.
8333 adrp x16, PLT_GOT + 16 // Get the page base of the GOTPLT
8334 ldr x17, [x16, #:lo12:PLT_GOT+16] // Load the address of the
8336 add x16, x16, #:lo12:PLT_GOT+16 // Load the lo12 bits of the
8337 // GOTPLT entry for this.
8339 PLT0 will be slightly different in ELF32 due to different got entry
8342 bfd_vma plt_got_2nd_ent; /* Address of GOT[2]. */
8346 memcpy (htab->root.splt->contents, elfNN_aarch64_small_plt0_entry,
8348 elf_section_data (htab->root.splt->output_section)->this_hdr.sh_entsize =
8351 plt_got_2nd_ent = (htab->root.sgotplt->output_section->vma
8352 + htab->root.sgotplt->output_offset
8353 + GOT_ENTRY_SIZE * 2);
8355 plt_base = htab->root.splt->output_section->vma +
8356 htab->root.splt->output_offset;
8358 /* Fill in the top 21 bits for this: ADRP x16, PLT_GOT + n * 8.
8359 ADRP: ((PG(S+A)-PG(P)) >> 12) & 0x1fffff */
8360 elf_aarch64_update_plt_entry (output_bfd, BFD_RELOC_AARCH64_ADR_HI21_PCREL,
8361 htab->root.splt->contents + 4,
8362 PG (plt_got_2nd_ent) - PG (plt_base + 4));
8364 elf_aarch64_update_plt_entry (output_bfd, BFD_RELOC_AARCH64_LDSTNN_LO12,
8365 htab->root.splt->contents + 8,
8366 PG_OFFSET (plt_got_2nd_ent));
8368 elf_aarch64_update_plt_entry (output_bfd, BFD_RELOC_AARCH64_ADD_LO12,
8369 htab->root.splt->contents + 12,
8370 PG_OFFSET (plt_got_2nd_ent));
8374 elfNN_aarch64_finish_dynamic_sections (bfd *output_bfd,
8375 struct bfd_link_info *info)
8377 struct elf_aarch64_link_hash_table *htab;
8381 htab = elf_aarch64_hash_table (info);
8382 dynobj = htab->root.dynobj;
8383 sdyn = bfd_get_linker_section (dynobj, ".dynamic");
8385 if (htab->root.dynamic_sections_created)
8387 ElfNN_External_Dyn *dyncon, *dynconend;
8389 if (sdyn == NULL || htab->root.sgot == NULL)
8392 dyncon = (ElfNN_External_Dyn *) sdyn->contents;
8393 dynconend = (ElfNN_External_Dyn *) (sdyn->contents + sdyn->size);
8394 for (; dyncon < dynconend; dyncon++)
8396 Elf_Internal_Dyn dyn;
8399 bfd_elfNN_swap_dyn_in (dynobj, dyncon, &dyn);
8407 s = htab->root.sgotplt;
8408 dyn.d_un.d_ptr = s->output_section->vma + s->output_offset;
8412 dyn.d_un.d_ptr = htab->root.srelplt->output_section->vma;
8416 s = htab->root.srelplt;
8417 dyn.d_un.d_val = s->size;
8421 /* The procedure linkage table relocs (DT_JMPREL) should
8422 not be included in the overall relocs (DT_RELA).
8423 Therefore, we override the DT_RELASZ entry here to
8424 make it not include the JMPREL relocs. Since the
8425 linker script arranges for .rela.plt to follow all
8426 other relocation sections, we don't have to worry
8427 about changing the DT_RELA entry. */
8428 if (htab->root.srelplt != NULL)
8430 s = htab->root.srelplt;
8431 dyn.d_un.d_val -= s->size;
8435 case DT_TLSDESC_PLT:
8436 s = htab->root.splt;
8437 dyn.d_un.d_ptr = s->output_section->vma + s->output_offset
8438 + htab->tlsdesc_plt;
8441 case DT_TLSDESC_GOT:
8442 s = htab->root.sgot;
8443 dyn.d_un.d_ptr = s->output_section->vma + s->output_offset
8444 + htab->dt_tlsdesc_got;
8448 bfd_elfNN_swap_dyn_out (output_bfd, &dyn, dyncon);
8453 /* Fill in the special first entry in the procedure linkage table. */
8454 if (htab->root.splt && htab->root.splt->size > 0)
8456 elfNN_aarch64_init_small_plt0_entry (output_bfd, htab);
8458 elf_section_data (htab->root.splt->output_section)->
8459 this_hdr.sh_entsize = htab->plt_entry_size;
8462 if (htab->tlsdesc_plt)
8464 bfd_put_NN (output_bfd, (bfd_vma) 0,
8465 htab->root.sgot->contents + htab->dt_tlsdesc_got);
8467 memcpy (htab->root.splt->contents + htab->tlsdesc_plt,
8468 elfNN_aarch64_tlsdesc_small_plt_entry,
8469 sizeof (elfNN_aarch64_tlsdesc_small_plt_entry));
8472 bfd_vma adrp1_addr =
8473 htab->root.splt->output_section->vma
8474 + htab->root.splt->output_offset + htab->tlsdesc_plt + 4;
8476 bfd_vma adrp2_addr = adrp1_addr + 4;
8479 htab->root.sgot->output_section->vma
8480 + htab->root.sgot->output_offset;
8482 bfd_vma pltgot_addr =
8483 htab->root.sgotplt->output_section->vma
8484 + htab->root.sgotplt->output_offset;
8486 bfd_vma dt_tlsdesc_got = got_addr + htab->dt_tlsdesc_got;
8488 bfd_byte *plt_entry =
8489 htab->root.splt->contents + htab->tlsdesc_plt;
8491 /* adrp x2, DT_TLSDESC_GOT */
8492 elf_aarch64_update_plt_entry (output_bfd,
8493 BFD_RELOC_AARCH64_ADR_HI21_PCREL,
8495 (PG (dt_tlsdesc_got)
8496 - PG (adrp1_addr)));
8499 elf_aarch64_update_plt_entry (output_bfd,
8500 BFD_RELOC_AARCH64_ADR_HI21_PCREL,
8503 - PG (adrp2_addr)));
8505 /* ldr x2, [x2, #0] */
8506 elf_aarch64_update_plt_entry (output_bfd,
8507 BFD_RELOC_AARCH64_LDSTNN_LO12,
8509 PG_OFFSET (dt_tlsdesc_got));
8512 elf_aarch64_update_plt_entry (output_bfd,
8513 BFD_RELOC_AARCH64_ADD_LO12,
8515 PG_OFFSET (pltgot_addr));
8520 if (htab->root.sgotplt)
8522 if (bfd_is_abs_section (htab->root.sgotplt->output_section))
8524 (*_bfd_error_handler)
8525 (_("discarded output section: `%A'"), htab->root.sgotplt);
8529 /* Fill in the first three entries in the global offset table. */
8530 if (htab->root.sgotplt->size > 0)
8532 bfd_put_NN (output_bfd, (bfd_vma) 0, htab->root.sgotplt->contents);
8534 /* Write GOT[1] and GOT[2], needed for the dynamic linker. */
8535 bfd_put_NN (output_bfd,
8537 htab->root.sgotplt->contents + GOT_ENTRY_SIZE);
8538 bfd_put_NN (output_bfd,
8540 htab->root.sgotplt->contents + GOT_ENTRY_SIZE * 2);
8543 if (htab->root.sgot)
8545 if (htab->root.sgot->size > 0)
8548 sdyn ? sdyn->output_section->vma + sdyn->output_offset : 0;
8549 bfd_put_NN (output_bfd, addr, htab->root.sgot->contents);
8553 elf_section_data (htab->root.sgotplt->output_section)->
8554 this_hdr.sh_entsize = GOT_ENTRY_SIZE;
8557 if (htab->root.sgot && htab->root.sgot->size > 0)
8558 elf_section_data (htab->root.sgot->output_section)->this_hdr.sh_entsize
8561 /* Fill PLT and GOT entries for local STT_GNU_IFUNC symbols. */
8562 htab_traverse (htab->loc_hash_table,
8563 elfNN_aarch64_finish_local_dynamic_symbol,
8569 /* Return address for Ith PLT stub in section PLT, for relocation REL
8570 or (bfd_vma) -1 if it should not be included. */
8573 elfNN_aarch64_plt_sym_val (bfd_vma i, const asection *plt,
8574 const arelent *rel ATTRIBUTE_UNUSED)
8576 return plt->vma + PLT_ENTRY_SIZE + i * PLT_SMALL_ENTRY_SIZE;
8580 /* We use this so we can override certain functions
8581 (though currently we don't). */
8583 const struct elf_size_info elfNN_aarch64_size_info =
8585 sizeof (ElfNN_External_Ehdr),
8586 sizeof (ElfNN_External_Phdr),
8587 sizeof (ElfNN_External_Shdr),
8588 sizeof (ElfNN_External_Rel),
8589 sizeof (ElfNN_External_Rela),
8590 sizeof (ElfNN_External_Sym),
8591 sizeof (ElfNN_External_Dyn),
8592 sizeof (Elf_External_Note),
8593 4, /* Hash table entry size. */
8594 1, /* Internal relocs per external relocs. */
8595 ARCH_SIZE, /* Arch size. */
8596 LOG_FILE_ALIGN, /* Log_file_align. */
8597 ELFCLASSNN, EV_CURRENT,
8598 bfd_elfNN_write_out_phdrs,
8599 bfd_elfNN_write_shdrs_and_ehdr,
8600 bfd_elfNN_checksum_contents,
8601 bfd_elfNN_write_relocs,
8602 bfd_elfNN_swap_symbol_in,
8603 bfd_elfNN_swap_symbol_out,
8604 bfd_elfNN_slurp_reloc_table,
8605 bfd_elfNN_slurp_symbol_table,
8606 bfd_elfNN_swap_dyn_in,
8607 bfd_elfNN_swap_dyn_out,
8608 bfd_elfNN_swap_reloc_in,
8609 bfd_elfNN_swap_reloc_out,
8610 bfd_elfNN_swap_reloca_in,
8611 bfd_elfNN_swap_reloca_out
8614 #define ELF_ARCH bfd_arch_aarch64
8615 #define ELF_MACHINE_CODE EM_AARCH64
8616 #define ELF_MAXPAGESIZE 0x10000
8617 #define ELF_MINPAGESIZE 0x1000
8618 #define ELF_COMMONPAGESIZE 0x1000
8620 #define bfd_elfNN_close_and_cleanup \
8621 elfNN_aarch64_close_and_cleanup
8623 #define bfd_elfNN_bfd_free_cached_info \
8624 elfNN_aarch64_bfd_free_cached_info
8626 #define bfd_elfNN_bfd_is_target_special_symbol \
8627 elfNN_aarch64_is_target_special_symbol
8629 #define bfd_elfNN_bfd_link_hash_table_create \
8630 elfNN_aarch64_link_hash_table_create
8632 #define bfd_elfNN_bfd_merge_private_bfd_data \
8633 elfNN_aarch64_merge_private_bfd_data
8635 #define bfd_elfNN_bfd_print_private_bfd_data \
8636 elfNN_aarch64_print_private_bfd_data
8638 #define bfd_elfNN_bfd_reloc_type_lookup \
8639 elfNN_aarch64_reloc_type_lookup
8641 #define bfd_elfNN_bfd_reloc_name_lookup \
8642 elfNN_aarch64_reloc_name_lookup
8644 #define bfd_elfNN_bfd_set_private_flags \
8645 elfNN_aarch64_set_private_flags
8647 #define bfd_elfNN_find_inliner_info \
8648 elfNN_aarch64_find_inliner_info
8650 #define bfd_elfNN_find_nearest_line \
8651 elfNN_aarch64_find_nearest_line
8653 #define bfd_elfNN_mkobject \
8654 elfNN_aarch64_mkobject
8656 #define bfd_elfNN_new_section_hook \
8657 elfNN_aarch64_new_section_hook
8659 #define elf_backend_adjust_dynamic_symbol \
8660 elfNN_aarch64_adjust_dynamic_symbol
8662 #define elf_backend_always_size_sections \
8663 elfNN_aarch64_always_size_sections
8665 #define elf_backend_check_relocs \
8666 elfNN_aarch64_check_relocs
8668 #define elf_backend_copy_indirect_symbol \
8669 elfNN_aarch64_copy_indirect_symbol
8671 /* Create .dynbss, and .rela.bss sections in DYNOBJ, and set up shortcuts
8672 to them in our hash. */
8673 #define elf_backend_create_dynamic_sections \
8674 elfNN_aarch64_create_dynamic_sections
8676 #define elf_backend_init_index_section \
8677 _bfd_elf_init_2_index_sections
8679 #define elf_backend_finish_dynamic_sections \
8680 elfNN_aarch64_finish_dynamic_sections
8682 #define elf_backend_finish_dynamic_symbol \
8683 elfNN_aarch64_finish_dynamic_symbol
8685 #define elf_backend_gc_sweep_hook \
8686 elfNN_aarch64_gc_sweep_hook
8688 #define elf_backend_object_p \
8689 elfNN_aarch64_object_p
8691 #define elf_backend_output_arch_local_syms \
8692 elfNN_aarch64_output_arch_local_syms
8694 #define elf_backend_plt_sym_val \
8695 elfNN_aarch64_plt_sym_val
8697 #define elf_backend_post_process_headers \
8698 elfNN_aarch64_post_process_headers
8700 #define elf_backend_relocate_section \
8701 elfNN_aarch64_relocate_section
8703 #define elf_backend_reloc_type_class \
8704 elfNN_aarch64_reloc_type_class
8706 #define elf_backend_section_from_shdr \
8707 elfNN_aarch64_section_from_shdr
8709 #define elf_backend_size_dynamic_sections \
8710 elfNN_aarch64_size_dynamic_sections
8712 #define elf_backend_size_info \
8713 elfNN_aarch64_size_info
8715 #define elf_backend_write_section \
8716 elfNN_aarch64_write_section
8718 #define elf_backend_can_refcount 1
8719 #define elf_backend_can_gc_sections 1
8720 #define elf_backend_plt_readonly 1
8721 #define elf_backend_want_got_plt 1
8722 #define elf_backend_want_plt_sym 0
8723 #define elf_backend_may_use_rel_p 0
8724 #define elf_backend_may_use_rela_p 1
8725 #define elf_backend_default_use_rela_p 1
8726 #define elf_backend_rela_normal 1
8727 #define elf_backend_got_header_size (GOT_ENTRY_SIZE * 3)
8728 #define elf_backend_default_execstack 0
8729 #define elf_backend_extern_protected_data 1
8731 #undef elf_backend_obj_attrs_section
8732 #define elf_backend_obj_attrs_section ".ARM.attributes"
8734 #include "elfNN-target.h"