1 /* AArch64-specific support for NN-bit ELF.
2 Copyright (C) 2009-2014 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_ADR_PAGE21 \
169 || (R_TYPE) == BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC \
170 || (R_TYPE) == BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G1 \
171 || (R_TYPE) == BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G0_NC \
172 || (R_TYPE) == BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21 \
173 || (R_TYPE) == BFD_RELOC_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC \
174 || (R_TYPE) == BFD_RELOC_AARCH64_TLSIE_LD32_GOTTPREL_LO12_NC \
175 || (R_TYPE) == BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19 \
176 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_LO12 \
177 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_HI12 \
178 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_LO12_NC \
179 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G2 \
180 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1 \
181 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1_NC \
182 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0 \
183 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC \
184 || (R_TYPE) == BFD_RELOC_AARCH64_TLS_DTPMOD \
185 || (R_TYPE) == BFD_RELOC_AARCH64_TLS_DTPREL \
186 || (R_TYPE) == BFD_RELOC_AARCH64_TLS_TPREL \
187 || IS_AARCH64_TLSDESC_RELOC ((R_TYPE)))
189 #define IS_AARCH64_TLSDESC_RELOC(R_TYPE) \
190 ((R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_LD_PREL19 \
191 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21 \
192 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21 \
193 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_ADD_LO12_NC \
194 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_LD64_LO12_NC \
195 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_LD32_LO12_NC \
196 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_OFF_G1 \
197 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_OFF_G0_NC \
198 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_LDR \
199 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_ADD \
200 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_CALL \
201 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC)
203 #define ELIMINATE_COPY_RELOCS 0
205 /* Return size of a relocation entry. HTAB is the bfd's
206 elf_aarch64_link_hash_entry. */
207 #define RELOC_SIZE(HTAB) (sizeof (ElfNN_External_Rela))
209 /* GOT Entry size - 8 bytes in ELF64 and 4 bytes in ELF32. */
210 #define GOT_ENTRY_SIZE (ARCH_SIZE / 8)
211 #define PLT_ENTRY_SIZE (32)
212 #define PLT_SMALL_ENTRY_SIZE (16)
213 #define PLT_TLSDESC_ENTRY_SIZE (32)
215 /* Encoding of the nop instruction */
216 #define INSN_NOP 0xd503201f
218 #define aarch64_compute_jump_table_size(htab) \
219 (((htab)->root.srelplt == NULL) ? 0 \
220 : (htab)->root.srelplt->reloc_count * GOT_ENTRY_SIZE)
222 /* The first entry in a procedure linkage table looks like this
223 if the distance between the PLTGOT and the PLT is < 4GB use
224 these PLT entries. Note that the dynamic linker gets &PLTGOT[2]
225 in x16 and needs to work out PLTGOT[1] by using an address of
226 [x16,#-GOT_ENTRY_SIZE]. */
227 static const bfd_byte elfNN_aarch64_small_plt0_entry[PLT_ENTRY_SIZE] =
229 0xf0, 0x7b, 0xbf, 0xa9, /* stp x16, x30, [sp, #-16]! */
230 0x10, 0x00, 0x00, 0x90, /* adrp x16, (GOT+16) */
232 0x11, 0x0A, 0x40, 0xf9, /* ldr x17, [x16, #PLT_GOT+0x10] */
233 0x10, 0x42, 0x00, 0x91, /* add x16, x16,#PLT_GOT+0x10 */
235 0x11, 0x0A, 0x40, 0xb9, /* ldr w17, [x16, #PLT_GOT+0x8] */
236 0x10, 0x22, 0x00, 0x11, /* add w16, w16,#PLT_GOT+0x8 */
238 0x20, 0x02, 0x1f, 0xd6, /* br x17 */
239 0x1f, 0x20, 0x03, 0xd5, /* nop */
240 0x1f, 0x20, 0x03, 0xd5, /* nop */
241 0x1f, 0x20, 0x03, 0xd5, /* nop */
244 /* Per function entry in a procedure linkage table looks like this
245 if the distance between the PLTGOT and the PLT is < 4GB use
246 these PLT entries. */
247 static const bfd_byte elfNN_aarch64_small_plt_entry[PLT_SMALL_ENTRY_SIZE] =
249 0x10, 0x00, 0x00, 0x90, /* adrp x16, PLTGOT + n * 8 */
251 0x11, 0x02, 0x40, 0xf9, /* ldr x17, [x16, PLTGOT + n * 8] */
252 0x10, 0x02, 0x00, 0x91, /* add x16, x16, :lo12:PLTGOT + n * 8 */
254 0x11, 0x02, 0x40, 0xb9, /* ldr w17, [x16, PLTGOT + n * 4] */
255 0x10, 0x02, 0x00, 0x11, /* add w16, w16, :lo12:PLTGOT + n * 4 */
257 0x20, 0x02, 0x1f, 0xd6, /* br x17. */
260 static const bfd_byte
261 elfNN_aarch64_tlsdesc_small_plt_entry[PLT_TLSDESC_ENTRY_SIZE] =
263 0xe2, 0x0f, 0xbf, 0xa9, /* stp x2, x3, [sp, #-16]! */
264 0x02, 0x00, 0x00, 0x90, /* adrp x2, 0 */
265 0x03, 0x00, 0x00, 0x90, /* adrp x3, 0 */
267 0x42, 0x00, 0x40, 0xf9, /* ldr x2, [x2, #0] */
268 0x63, 0x00, 0x00, 0x91, /* add x3, x3, 0 */
270 0x42, 0x00, 0x40, 0xb9, /* ldr w2, [x2, #0] */
271 0x63, 0x00, 0x00, 0x11, /* add w3, w3, 0 */
273 0x40, 0x00, 0x1f, 0xd6, /* br x2 */
274 0x1f, 0x20, 0x03, 0xd5, /* nop */
275 0x1f, 0x20, 0x03, 0xd5, /* nop */
278 #define elf_info_to_howto elfNN_aarch64_info_to_howto
279 #define elf_info_to_howto_rel elfNN_aarch64_info_to_howto
281 #define AARCH64_ELF_ABI_VERSION 0
283 /* In case we're on a 32-bit machine, construct a 64-bit "-1" value. */
284 #define ALL_ONES (~ (bfd_vma) 0)
286 /* Indexed by the bfd interal reloc enumerators.
287 Therefore, the table needs to be synced with BFD_RELOC_AARCH64_*
290 static reloc_howto_type elfNN_aarch64_howto_table[] =
294 /* Basic data relocations. */
297 HOWTO (R_AARCH64_NULL, /* type */
299 0, /* size (0 = byte, 1 = short, 2 = long) */
301 FALSE, /* pc_relative */
303 complain_overflow_dont, /* complain_on_overflow */
304 bfd_elf_generic_reloc, /* special_function */
305 "R_AARCH64_NULL", /* name */
306 FALSE, /* partial_inplace */
309 FALSE), /* pcrel_offset */
311 HOWTO (R_AARCH64_NONE, /* type */
313 0, /* size (0 = byte, 1 = short, 2 = long) */
315 FALSE, /* pc_relative */
317 complain_overflow_dont, /* complain_on_overflow */
318 bfd_elf_generic_reloc, /* special_function */
319 "R_AARCH64_NONE", /* name */
320 FALSE, /* partial_inplace */
323 FALSE), /* pcrel_offset */
327 HOWTO64 (AARCH64_R (ABS64), /* type */
329 4, /* size (4 = long long) */
331 FALSE, /* pc_relative */
333 complain_overflow_unsigned, /* complain_on_overflow */
334 bfd_elf_generic_reloc, /* special_function */
335 AARCH64_R_STR (ABS64), /* name */
336 FALSE, /* partial_inplace */
337 ALL_ONES, /* src_mask */
338 ALL_ONES, /* dst_mask */
339 FALSE), /* pcrel_offset */
342 HOWTO (AARCH64_R (ABS32), /* type */
344 2, /* size (0 = byte, 1 = short, 2 = long) */
346 FALSE, /* pc_relative */
348 complain_overflow_unsigned, /* complain_on_overflow */
349 bfd_elf_generic_reloc, /* special_function */
350 AARCH64_R_STR (ABS32), /* name */
351 FALSE, /* partial_inplace */
352 0xffffffff, /* src_mask */
353 0xffffffff, /* dst_mask */
354 FALSE), /* pcrel_offset */
357 HOWTO (AARCH64_R (ABS16), /* type */
359 1, /* size (0 = byte, 1 = short, 2 = long) */
361 FALSE, /* pc_relative */
363 complain_overflow_unsigned, /* complain_on_overflow */
364 bfd_elf_generic_reloc, /* special_function */
365 AARCH64_R_STR (ABS16), /* name */
366 FALSE, /* partial_inplace */
367 0xffff, /* src_mask */
368 0xffff, /* dst_mask */
369 FALSE), /* pcrel_offset */
371 /* .xword: (S+A-P) */
372 HOWTO64 (AARCH64_R (PREL64), /* type */
374 4, /* size (4 = long long) */
376 TRUE, /* pc_relative */
378 complain_overflow_signed, /* complain_on_overflow */
379 bfd_elf_generic_reloc, /* special_function */
380 AARCH64_R_STR (PREL64), /* name */
381 FALSE, /* partial_inplace */
382 ALL_ONES, /* src_mask */
383 ALL_ONES, /* dst_mask */
384 TRUE), /* pcrel_offset */
387 HOWTO (AARCH64_R (PREL32), /* type */
389 2, /* size (0 = byte, 1 = short, 2 = long) */
391 TRUE, /* pc_relative */
393 complain_overflow_signed, /* complain_on_overflow */
394 bfd_elf_generic_reloc, /* special_function */
395 AARCH64_R_STR (PREL32), /* name */
396 FALSE, /* partial_inplace */
397 0xffffffff, /* src_mask */
398 0xffffffff, /* dst_mask */
399 TRUE), /* pcrel_offset */
402 HOWTO (AARCH64_R (PREL16), /* type */
404 1, /* size (0 = byte, 1 = short, 2 = long) */
406 TRUE, /* pc_relative */
408 complain_overflow_signed, /* complain_on_overflow */
409 bfd_elf_generic_reloc, /* special_function */
410 AARCH64_R_STR (PREL16), /* name */
411 FALSE, /* partial_inplace */
412 0xffff, /* src_mask */
413 0xffff, /* dst_mask */
414 TRUE), /* pcrel_offset */
416 /* Group relocations to create a 16, 32, 48 or 64 bit
417 unsigned data or abs address inline. */
419 /* MOVZ: ((S+A) >> 0) & 0xffff */
420 HOWTO (AARCH64_R (MOVW_UABS_G0), /* type */
422 2, /* size (0 = byte, 1 = short, 2 = long) */
424 FALSE, /* pc_relative */
426 complain_overflow_unsigned, /* complain_on_overflow */
427 bfd_elf_generic_reloc, /* special_function */
428 AARCH64_R_STR (MOVW_UABS_G0), /* name */
429 FALSE, /* partial_inplace */
430 0xffff, /* src_mask */
431 0xffff, /* dst_mask */
432 FALSE), /* pcrel_offset */
434 /* MOVK: ((S+A) >> 0) & 0xffff [no overflow check] */
435 HOWTO (AARCH64_R (MOVW_UABS_G0_NC), /* type */
437 2, /* size (0 = byte, 1 = short, 2 = long) */
439 FALSE, /* pc_relative */
441 complain_overflow_dont, /* complain_on_overflow */
442 bfd_elf_generic_reloc, /* special_function */
443 AARCH64_R_STR (MOVW_UABS_G0_NC), /* name */
444 FALSE, /* partial_inplace */
445 0xffff, /* src_mask */
446 0xffff, /* dst_mask */
447 FALSE), /* pcrel_offset */
449 /* MOVZ: ((S+A) >> 16) & 0xffff */
450 HOWTO (AARCH64_R (MOVW_UABS_G1), /* type */
452 2, /* size (0 = byte, 1 = short, 2 = long) */
454 FALSE, /* pc_relative */
456 complain_overflow_unsigned, /* complain_on_overflow */
457 bfd_elf_generic_reloc, /* special_function */
458 AARCH64_R_STR (MOVW_UABS_G1), /* name */
459 FALSE, /* partial_inplace */
460 0xffff, /* src_mask */
461 0xffff, /* dst_mask */
462 FALSE), /* pcrel_offset */
464 /* MOVK: ((S+A) >> 16) & 0xffff [no overflow check] */
465 HOWTO64 (AARCH64_R (MOVW_UABS_G1_NC), /* type */
467 2, /* size (0 = byte, 1 = short, 2 = long) */
469 FALSE, /* pc_relative */
471 complain_overflow_dont, /* complain_on_overflow */
472 bfd_elf_generic_reloc, /* special_function */
473 AARCH64_R_STR (MOVW_UABS_G1_NC), /* name */
474 FALSE, /* partial_inplace */
475 0xffff, /* src_mask */
476 0xffff, /* dst_mask */
477 FALSE), /* pcrel_offset */
479 /* MOVZ: ((S+A) >> 32) & 0xffff */
480 HOWTO64 (AARCH64_R (MOVW_UABS_G2), /* type */
482 2, /* size (0 = byte, 1 = short, 2 = long) */
484 FALSE, /* pc_relative */
486 complain_overflow_unsigned, /* complain_on_overflow */
487 bfd_elf_generic_reloc, /* special_function */
488 AARCH64_R_STR (MOVW_UABS_G2), /* name */
489 FALSE, /* partial_inplace */
490 0xffff, /* src_mask */
491 0xffff, /* dst_mask */
492 FALSE), /* pcrel_offset */
494 /* MOVK: ((S+A) >> 32) & 0xffff [no overflow check] */
495 HOWTO64 (AARCH64_R (MOVW_UABS_G2_NC), /* type */
497 2, /* size (0 = byte, 1 = short, 2 = long) */
499 FALSE, /* pc_relative */
501 complain_overflow_dont, /* complain_on_overflow */
502 bfd_elf_generic_reloc, /* special_function */
503 AARCH64_R_STR (MOVW_UABS_G2_NC), /* name */
504 FALSE, /* partial_inplace */
505 0xffff, /* src_mask */
506 0xffff, /* dst_mask */
507 FALSE), /* pcrel_offset */
509 /* MOVZ: ((S+A) >> 48) & 0xffff */
510 HOWTO64 (AARCH64_R (MOVW_UABS_G3), /* type */
512 2, /* size (0 = byte, 1 = short, 2 = long) */
514 FALSE, /* pc_relative */
516 complain_overflow_unsigned, /* complain_on_overflow */
517 bfd_elf_generic_reloc, /* special_function */
518 AARCH64_R_STR (MOVW_UABS_G3), /* name */
519 FALSE, /* partial_inplace */
520 0xffff, /* src_mask */
521 0xffff, /* dst_mask */
522 FALSE), /* pcrel_offset */
524 /* Group relocations to create high part of a 16, 32, 48 or 64 bit
525 signed data or abs address inline. Will change instruction
526 to MOVN or MOVZ depending on sign of calculated value. */
528 /* MOV[ZN]: ((S+A) >> 0) & 0xffff */
529 HOWTO (AARCH64_R (MOVW_SABS_G0), /* type */
531 2, /* size (0 = byte, 1 = short, 2 = long) */
533 FALSE, /* pc_relative */
535 complain_overflow_signed, /* complain_on_overflow */
536 bfd_elf_generic_reloc, /* special_function */
537 AARCH64_R_STR (MOVW_SABS_G0), /* name */
538 FALSE, /* partial_inplace */
539 0xffff, /* src_mask */
540 0xffff, /* dst_mask */
541 FALSE), /* pcrel_offset */
543 /* MOV[ZN]: ((S+A) >> 16) & 0xffff */
544 HOWTO64 (AARCH64_R (MOVW_SABS_G1), /* type */
546 2, /* size (0 = byte, 1 = short, 2 = long) */
548 FALSE, /* pc_relative */
550 complain_overflow_signed, /* complain_on_overflow */
551 bfd_elf_generic_reloc, /* special_function */
552 AARCH64_R_STR (MOVW_SABS_G1), /* name */
553 FALSE, /* partial_inplace */
554 0xffff, /* src_mask */
555 0xffff, /* dst_mask */
556 FALSE), /* pcrel_offset */
558 /* MOV[ZN]: ((S+A) >> 32) & 0xffff */
559 HOWTO64 (AARCH64_R (MOVW_SABS_G2), /* type */
561 2, /* size (0 = byte, 1 = short, 2 = long) */
563 FALSE, /* pc_relative */
565 complain_overflow_signed, /* complain_on_overflow */
566 bfd_elf_generic_reloc, /* special_function */
567 AARCH64_R_STR (MOVW_SABS_G2), /* name */
568 FALSE, /* partial_inplace */
569 0xffff, /* src_mask */
570 0xffff, /* dst_mask */
571 FALSE), /* pcrel_offset */
573 /* Relocations to generate 19, 21 and 33 bit PC-relative load/store
574 addresses: PG(x) is (x & ~0xfff). */
576 /* LD-lit: ((S+A-P) >> 2) & 0x7ffff */
577 HOWTO (AARCH64_R (LD_PREL_LO19), /* type */
579 2, /* size (0 = byte, 1 = short, 2 = long) */
581 TRUE, /* pc_relative */
583 complain_overflow_signed, /* complain_on_overflow */
584 bfd_elf_generic_reloc, /* special_function */
585 AARCH64_R_STR (LD_PREL_LO19), /* name */
586 FALSE, /* partial_inplace */
587 0x7ffff, /* src_mask */
588 0x7ffff, /* dst_mask */
589 TRUE), /* pcrel_offset */
591 /* ADR: (S+A-P) & 0x1fffff */
592 HOWTO (AARCH64_R (ADR_PREL_LO21), /* type */
594 2, /* size (0 = byte, 1 = short, 2 = long) */
596 TRUE, /* pc_relative */
598 complain_overflow_signed, /* complain_on_overflow */
599 bfd_elf_generic_reloc, /* special_function */
600 AARCH64_R_STR (ADR_PREL_LO21), /* name */
601 FALSE, /* partial_inplace */
602 0x1fffff, /* src_mask */
603 0x1fffff, /* dst_mask */
604 TRUE), /* pcrel_offset */
606 /* ADRP: ((PG(S+A)-PG(P)) >> 12) & 0x1fffff */
607 HOWTO (AARCH64_R (ADR_PREL_PG_HI21), /* type */
609 2, /* size (0 = byte, 1 = short, 2 = long) */
611 TRUE, /* pc_relative */
613 complain_overflow_signed, /* complain_on_overflow */
614 bfd_elf_generic_reloc, /* special_function */
615 AARCH64_R_STR (ADR_PREL_PG_HI21), /* name */
616 FALSE, /* partial_inplace */
617 0x1fffff, /* src_mask */
618 0x1fffff, /* dst_mask */
619 TRUE), /* pcrel_offset */
621 /* ADRP: ((PG(S+A)-PG(P)) >> 12) & 0x1fffff [no overflow check] */
622 HOWTO64 (AARCH64_R (ADR_PREL_PG_HI21_NC), /* type */
624 2, /* size (0 = byte, 1 = short, 2 = long) */
626 TRUE, /* pc_relative */
628 complain_overflow_dont, /* complain_on_overflow */
629 bfd_elf_generic_reloc, /* special_function */
630 AARCH64_R_STR (ADR_PREL_PG_HI21_NC), /* name */
631 FALSE, /* partial_inplace */
632 0x1fffff, /* src_mask */
633 0x1fffff, /* dst_mask */
634 TRUE), /* pcrel_offset */
636 /* ADD: (S+A) & 0xfff [no overflow check] */
637 HOWTO (AARCH64_R (ADD_ABS_LO12_NC), /* type */
639 2, /* size (0 = byte, 1 = short, 2 = long) */
641 FALSE, /* pc_relative */
643 complain_overflow_dont, /* complain_on_overflow */
644 bfd_elf_generic_reloc, /* special_function */
645 AARCH64_R_STR (ADD_ABS_LO12_NC), /* name */
646 FALSE, /* partial_inplace */
647 0x3ffc00, /* src_mask */
648 0x3ffc00, /* dst_mask */
649 FALSE), /* pcrel_offset */
651 /* LD/ST8: (S+A) & 0xfff */
652 HOWTO (AARCH64_R (LDST8_ABS_LO12_NC), /* type */
654 2, /* size (0 = byte, 1 = short, 2 = long) */
656 FALSE, /* pc_relative */
658 complain_overflow_dont, /* complain_on_overflow */
659 bfd_elf_generic_reloc, /* special_function */
660 AARCH64_R_STR (LDST8_ABS_LO12_NC), /* name */
661 FALSE, /* partial_inplace */
662 0xfff, /* src_mask */
663 0xfff, /* dst_mask */
664 FALSE), /* pcrel_offset */
666 /* Relocations for control-flow instructions. */
668 /* TBZ/NZ: ((S+A-P) >> 2) & 0x3fff */
669 HOWTO (AARCH64_R (TSTBR14), /* type */
671 2, /* size (0 = byte, 1 = short, 2 = long) */
673 TRUE, /* pc_relative */
675 complain_overflow_signed, /* complain_on_overflow */
676 bfd_elf_generic_reloc, /* special_function */
677 AARCH64_R_STR (TSTBR14), /* name */
678 FALSE, /* partial_inplace */
679 0x3fff, /* src_mask */
680 0x3fff, /* dst_mask */
681 TRUE), /* pcrel_offset */
683 /* B.cond: ((S+A-P) >> 2) & 0x7ffff */
684 HOWTO (AARCH64_R (CONDBR19), /* type */
686 2, /* size (0 = byte, 1 = short, 2 = long) */
688 TRUE, /* pc_relative */
690 complain_overflow_signed, /* complain_on_overflow */
691 bfd_elf_generic_reloc, /* special_function */
692 AARCH64_R_STR (CONDBR19), /* name */
693 FALSE, /* partial_inplace */
694 0x7ffff, /* src_mask */
695 0x7ffff, /* dst_mask */
696 TRUE), /* pcrel_offset */
698 /* B: ((S+A-P) >> 2) & 0x3ffffff */
699 HOWTO (AARCH64_R (JUMP26), /* type */
701 2, /* size (0 = byte, 1 = short, 2 = long) */
703 TRUE, /* pc_relative */
705 complain_overflow_signed, /* complain_on_overflow */
706 bfd_elf_generic_reloc, /* special_function */
707 AARCH64_R_STR (JUMP26), /* name */
708 FALSE, /* partial_inplace */
709 0x3ffffff, /* src_mask */
710 0x3ffffff, /* dst_mask */
711 TRUE), /* pcrel_offset */
713 /* BL: ((S+A-P) >> 2) & 0x3ffffff */
714 HOWTO (AARCH64_R (CALL26), /* type */
716 2, /* size (0 = byte, 1 = short, 2 = long) */
718 TRUE, /* pc_relative */
720 complain_overflow_signed, /* complain_on_overflow */
721 bfd_elf_generic_reloc, /* special_function */
722 AARCH64_R_STR (CALL26), /* name */
723 FALSE, /* partial_inplace */
724 0x3ffffff, /* src_mask */
725 0x3ffffff, /* dst_mask */
726 TRUE), /* pcrel_offset */
728 /* LD/ST16: (S+A) & 0xffe */
729 HOWTO (AARCH64_R (LDST16_ABS_LO12_NC), /* type */
731 2, /* size (0 = byte, 1 = short, 2 = long) */
733 FALSE, /* pc_relative */
735 complain_overflow_dont, /* complain_on_overflow */
736 bfd_elf_generic_reloc, /* special_function */
737 AARCH64_R_STR (LDST16_ABS_LO12_NC), /* name */
738 FALSE, /* partial_inplace */
739 0xffe, /* src_mask */
740 0xffe, /* dst_mask */
741 FALSE), /* pcrel_offset */
743 /* LD/ST32: (S+A) & 0xffc */
744 HOWTO (AARCH64_R (LDST32_ABS_LO12_NC), /* type */
746 2, /* size (0 = byte, 1 = short, 2 = long) */
748 FALSE, /* pc_relative */
750 complain_overflow_dont, /* complain_on_overflow */
751 bfd_elf_generic_reloc, /* special_function */
752 AARCH64_R_STR (LDST32_ABS_LO12_NC), /* name */
753 FALSE, /* partial_inplace */
754 0xffc, /* src_mask */
755 0xffc, /* dst_mask */
756 FALSE), /* pcrel_offset */
758 /* LD/ST64: (S+A) & 0xff8 */
759 HOWTO (AARCH64_R (LDST64_ABS_LO12_NC), /* type */
761 2, /* size (0 = byte, 1 = short, 2 = long) */
763 FALSE, /* pc_relative */
765 complain_overflow_dont, /* complain_on_overflow */
766 bfd_elf_generic_reloc, /* special_function */
767 AARCH64_R_STR (LDST64_ABS_LO12_NC), /* name */
768 FALSE, /* partial_inplace */
769 0xff8, /* src_mask */
770 0xff8, /* dst_mask */
771 FALSE), /* pcrel_offset */
773 /* LD/ST128: (S+A) & 0xff0 */
774 HOWTO (AARCH64_R (LDST128_ABS_LO12_NC), /* type */
776 2, /* size (0 = byte, 1 = short, 2 = long) */
778 FALSE, /* pc_relative */
780 complain_overflow_dont, /* complain_on_overflow */
781 bfd_elf_generic_reloc, /* special_function */
782 AARCH64_R_STR (LDST128_ABS_LO12_NC), /* name */
783 FALSE, /* partial_inplace */
784 0xff0, /* src_mask */
785 0xff0, /* dst_mask */
786 FALSE), /* pcrel_offset */
788 /* Set a load-literal immediate field to bits
789 0x1FFFFC of G(S)-P */
790 HOWTO (AARCH64_R (GOT_LD_PREL19), /* type */
792 2, /* size (0 = byte,1 = short,2 = long) */
794 TRUE, /* pc_relative */
796 complain_overflow_signed, /* complain_on_overflow */
797 bfd_elf_generic_reloc, /* special_function */
798 AARCH64_R_STR (GOT_LD_PREL19), /* name */
799 FALSE, /* partial_inplace */
800 0xffffe0, /* src_mask */
801 0xffffe0, /* dst_mask */
802 TRUE), /* pcrel_offset */
804 /* Get to the page for the GOT entry for the symbol
805 (G(S) - P) using an ADRP instruction. */
806 HOWTO (AARCH64_R (ADR_GOT_PAGE), /* type */
808 2, /* size (0 = byte, 1 = short, 2 = long) */
810 TRUE, /* pc_relative */
812 complain_overflow_dont, /* complain_on_overflow */
813 bfd_elf_generic_reloc, /* special_function */
814 AARCH64_R_STR (ADR_GOT_PAGE), /* name */
815 FALSE, /* partial_inplace */
816 0x1fffff, /* src_mask */
817 0x1fffff, /* dst_mask */
818 TRUE), /* pcrel_offset */
820 /* LD64: GOT offset G(S) & 0xff8 */
821 HOWTO64 (AARCH64_R (LD64_GOT_LO12_NC), /* type */
823 2, /* size (0 = byte, 1 = short, 2 = long) */
825 FALSE, /* pc_relative */
827 complain_overflow_dont, /* complain_on_overflow */
828 bfd_elf_generic_reloc, /* special_function */
829 AARCH64_R_STR (LD64_GOT_LO12_NC), /* name */
830 FALSE, /* partial_inplace */
831 0xff8, /* src_mask */
832 0xff8, /* dst_mask */
833 FALSE), /* pcrel_offset */
835 /* LD32: GOT offset G(S) & 0xffc */
836 HOWTO32 (AARCH64_R (LD32_GOT_LO12_NC), /* type */
838 2, /* size (0 = byte, 1 = short, 2 = long) */
840 FALSE, /* pc_relative */
842 complain_overflow_dont, /* complain_on_overflow */
843 bfd_elf_generic_reloc, /* special_function */
844 AARCH64_R_STR (LD32_GOT_LO12_NC), /* name */
845 FALSE, /* partial_inplace */
846 0xffc, /* src_mask */
847 0xffc, /* dst_mask */
848 FALSE), /* pcrel_offset */
850 /* Get to the page for the GOT entry for the symbol
851 (G(S) - P) using an ADRP instruction. */
852 HOWTO (AARCH64_R (TLSGD_ADR_PAGE21), /* type */
854 2, /* size (0 = byte, 1 = short, 2 = long) */
856 TRUE, /* pc_relative */
858 complain_overflow_dont, /* complain_on_overflow */
859 bfd_elf_generic_reloc, /* special_function */
860 AARCH64_R_STR (TLSGD_ADR_PAGE21), /* name */
861 FALSE, /* partial_inplace */
862 0x1fffff, /* src_mask */
863 0x1fffff, /* dst_mask */
864 TRUE), /* pcrel_offset */
866 /* ADD: GOT offset G(S) & 0xff8 [no overflow check] */
867 HOWTO (AARCH64_R (TLSGD_ADD_LO12_NC), /* type */
869 2, /* size (0 = byte, 1 = short, 2 = long) */
871 FALSE, /* pc_relative */
873 complain_overflow_dont, /* complain_on_overflow */
874 bfd_elf_generic_reloc, /* special_function */
875 AARCH64_R_STR (TLSGD_ADD_LO12_NC), /* name */
876 FALSE, /* partial_inplace */
877 0xfff, /* src_mask */
878 0xfff, /* dst_mask */
879 FALSE), /* pcrel_offset */
881 HOWTO64 (AARCH64_R (TLSIE_MOVW_GOTTPREL_G1), /* type */
883 2, /* size (0 = byte, 1 = short, 2 = long) */
885 FALSE, /* pc_relative */
887 complain_overflow_dont, /* complain_on_overflow */
888 bfd_elf_generic_reloc, /* special_function */
889 AARCH64_R_STR (TLSIE_MOVW_GOTTPREL_G1), /* name */
890 FALSE, /* partial_inplace */
891 0xffff, /* src_mask */
892 0xffff, /* dst_mask */
893 FALSE), /* pcrel_offset */
895 HOWTO64 (AARCH64_R (TLSIE_MOVW_GOTTPREL_G0_NC), /* type */
897 2, /* size (0 = byte, 1 = short, 2 = long) */
899 FALSE, /* pc_relative */
901 complain_overflow_dont, /* complain_on_overflow */
902 bfd_elf_generic_reloc, /* special_function */
903 AARCH64_R_STR (TLSIE_MOVW_GOTTPREL_G0_NC), /* name */
904 FALSE, /* partial_inplace */
905 0xffff, /* src_mask */
906 0xffff, /* dst_mask */
907 FALSE), /* pcrel_offset */
909 HOWTO (AARCH64_R (TLSIE_ADR_GOTTPREL_PAGE21), /* type */
911 2, /* size (0 = byte, 1 = short, 2 = long) */
913 FALSE, /* pc_relative */
915 complain_overflow_dont, /* complain_on_overflow */
916 bfd_elf_generic_reloc, /* special_function */
917 AARCH64_R_STR (TLSIE_ADR_GOTTPREL_PAGE21), /* name */
918 FALSE, /* partial_inplace */
919 0x1fffff, /* src_mask */
920 0x1fffff, /* dst_mask */
921 FALSE), /* pcrel_offset */
923 HOWTO64 (AARCH64_R (TLSIE_LD64_GOTTPREL_LO12_NC), /* type */
925 2, /* size (0 = byte, 1 = short, 2 = long) */
927 FALSE, /* pc_relative */
929 complain_overflow_dont, /* complain_on_overflow */
930 bfd_elf_generic_reloc, /* special_function */
931 AARCH64_R_STR (TLSIE_LD64_GOTTPREL_LO12_NC), /* name */
932 FALSE, /* partial_inplace */
933 0xff8, /* src_mask */
934 0xff8, /* dst_mask */
935 FALSE), /* pcrel_offset */
937 HOWTO32 (AARCH64_R (TLSIE_LD32_GOTTPREL_LO12_NC), /* type */
939 2, /* size (0 = byte, 1 = short, 2 = long) */
941 FALSE, /* pc_relative */
943 complain_overflow_dont, /* complain_on_overflow */
944 bfd_elf_generic_reloc, /* special_function */
945 AARCH64_R_STR (TLSIE_LD32_GOTTPREL_LO12_NC), /* name */
946 FALSE, /* partial_inplace */
947 0xffc, /* src_mask */
948 0xffc, /* dst_mask */
949 FALSE), /* pcrel_offset */
951 HOWTO (AARCH64_R (TLSIE_LD_GOTTPREL_PREL19), /* type */
953 2, /* size (0 = byte, 1 = short, 2 = long) */
955 FALSE, /* pc_relative */
957 complain_overflow_dont, /* complain_on_overflow */
958 bfd_elf_generic_reloc, /* special_function */
959 AARCH64_R_STR (TLSIE_LD_GOTTPREL_PREL19), /* name */
960 FALSE, /* partial_inplace */
961 0x1ffffc, /* src_mask */
962 0x1ffffc, /* dst_mask */
963 FALSE), /* pcrel_offset */
965 HOWTO64 (AARCH64_R (TLSLE_MOVW_TPREL_G2), /* type */
967 2, /* size (0 = byte, 1 = short, 2 = long) */
969 FALSE, /* pc_relative */
971 complain_overflow_dont, /* complain_on_overflow */
972 bfd_elf_generic_reloc, /* special_function */
973 AARCH64_R_STR (TLSLE_MOVW_TPREL_G2), /* name */
974 FALSE, /* partial_inplace */
975 0xffff, /* src_mask */
976 0xffff, /* dst_mask */
977 FALSE), /* pcrel_offset */
979 HOWTO (AARCH64_R (TLSLE_MOVW_TPREL_G1), /* type */
981 2, /* size (0 = byte, 1 = short, 2 = long) */
983 FALSE, /* pc_relative */
985 complain_overflow_dont, /* complain_on_overflow */
986 bfd_elf_generic_reloc, /* special_function */
987 AARCH64_R_STR (TLSLE_MOVW_TPREL_G1), /* name */
988 FALSE, /* partial_inplace */
989 0xffff, /* src_mask */
990 0xffff, /* dst_mask */
991 FALSE), /* pcrel_offset */
993 HOWTO64 (AARCH64_R (TLSLE_MOVW_TPREL_G1_NC), /* type */
995 2, /* size (0 = byte, 1 = short, 2 = long) */
997 FALSE, /* pc_relative */
999 complain_overflow_dont, /* complain_on_overflow */
1000 bfd_elf_generic_reloc, /* special_function */
1001 AARCH64_R_STR (TLSLE_MOVW_TPREL_G1_NC), /* name */
1002 FALSE, /* partial_inplace */
1003 0xffff, /* src_mask */
1004 0xffff, /* dst_mask */
1005 FALSE), /* pcrel_offset */
1007 HOWTO (AARCH64_R (TLSLE_MOVW_TPREL_G0), /* type */
1009 2, /* size (0 = byte, 1 = short, 2 = long) */
1011 FALSE, /* pc_relative */
1013 complain_overflow_dont, /* complain_on_overflow */
1014 bfd_elf_generic_reloc, /* special_function */
1015 AARCH64_R_STR (TLSLE_MOVW_TPREL_G0), /* name */
1016 FALSE, /* partial_inplace */
1017 0xffff, /* src_mask */
1018 0xffff, /* dst_mask */
1019 FALSE), /* pcrel_offset */
1021 HOWTO (AARCH64_R (TLSLE_MOVW_TPREL_G0_NC), /* type */
1023 2, /* size (0 = byte, 1 = short, 2 = long) */
1025 FALSE, /* pc_relative */
1027 complain_overflow_dont, /* complain_on_overflow */
1028 bfd_elf_generic_reloc, /* special_function */
1029 AARCH64_R_STR (TLSLE_MOVW_TPREL_G0_NC), /* name */
1030 FALSE, /* partial_inplace */
1031 0xffff, /* src_mask */
1032 0xffff, /* dst_mask */
1033 FALSE), /* pcrel_offset */
1035 HOWTO (AARCH64_R (TLSLE_ADD_TPREL_HI12), /* type */
1036 12, /* rightshift */
1037 2, /* size (0 = byte, 1 = short, 2 = long) */
1039 FALSE, /* pc_relative */
1041 complain_overflow_dont, /* complain_on_overflow */
1042 bfd_elf_generic_reloc, /* special_function */
1043 AARCH64_R_STR (TLSLE_ADD_TPREL_HI12), /* name */
1044 FALSE, /* partial_inplace */
1045 0xfff, /* src_mask */
1046 0xfff, /* dst_mask */
1047 FALSE), /* pcrel_offset */
1049 HOWTO (AARCH64_R (TLSLE_ADD_TPREL_LO12), /* type */
1051 2, /* size (0 = byte, 1 = short, 2 = long) */
1053 FALSE, /* pc_relative */
1055 complain_overflow_dont, /* complain_on_overflow */
1056 bfd_elf_generic_reloc, /* special_function */
1057 AARCH64_R_STR (TLSLE_ADD_TPREL_LO12), /* name */
1058 FALSE, /* partial_inplace */
1059 0xfff, /* src_mask */
1060 0xfff, /* dst_mask */
1061 FALSE), /* pcrel_offset */
1063 HOWTO (AARCH64_R (TLSLE_ADD_TPREL_LO12_NC), /* type */
1065 2, /* size (0 = byte, 1 = short, 2 = long) */
1067 FALSE, /* pc_relative */
1069 complain_overflow_dont, /* complain_on_overflow */
1070 bfd_elf_generic_reloc, /* special_function */
1071 AARCH64_R_STR (TLSLE_ADD_TPREL_LO12_NC), /* name */
1072 FALSE, /* partial_inplace */
1073 0xfff, /* src_mask */
1074 0xfff, /* dst_mask */
1075 FALSE), /* pcrel_offset */
1077 HOWTO (AARCH64_R (TLSDESC_LD_PREL19), /* type */
1079 2, /* size (0 = byte, 1 = short, 2 = long) */
1081 TRUE, /* pc_relative */
1083 complain_overflow_dont, /* complain_on_overflow */
1084 bfd_elf_generic_reloc, /* special_function */
1085 AARCH64_R_STR (TLSDESC_LD_PREL19), /* name */
1086 FALSE, /* partial_inplace */
1087 0x1ffffc, /* src_mask */
1088 0x1ffffc, /* dst_mask */
1089 TRUE), /* pcrel_offset */
1091 HOWTO (AARCH64_R (TLSDESC_ADR_PREL21), /* type */
1093 2, /* size (0 = byte, 1 = short, 2 = long) */
1095 TRUE, /* pc_relative */
1097 complain_overflow_dont, /* complain_on_overflow */
1098 bfd_elf_generic_reloc, /* special_function */
1099 AARCH64_R_STR (TLSDESC_ADR_PREL21), /* name */
1100 FALSE, /* partial_inplace */
1101 0x1fffff, /* src_mask */
1102 0x1fffff, /* dst_mask */
1103 TRUE), /* pcrel_offset */
1105 /* Get to the page for the GOT entry for the symbol
1106 (G(S) - P) using an ADRP instruction. */
1107 HOWTO (AARCH64_R (TLSDESC_ADR_PAGE21), /* type */
1108 12, /* rightshift */
1109 2, /* size (0 = byte, 1 = short, 2 = long) */
1111 TRUE, /* pc_relative */
1113 complain_overflow_dont, /* complain_on_overflow */
1114 bfd_elf_generic_reloc, /* special_function */
1115 AARCH64_R_STR (TLSDESC_ADR_PAGE21), /* name */
1116 FALSE, /* partial_inplace */
1117 0x1fffff, /* src_mask */
1118 0x1fffff, /* dst_mask */
1119 TRUE), /* pcrel_offset */
1121 /* LD64: GOT offset G(S) & 0xff8. */
1122 HOWTO64 (AARCH64_R (TLSDESC_LD64_LO12_NC), /* type */
1124 2, /* size (0 = byte, 1 = short, 2 = long) */
1126 FALSE, /* pc_relative */
1128 complain_overflow_dont, /* complain_on_overflow */
1129 bfd_elf_generic_reloc, /* special_function */
1130 AARCH64_R_STR (TLSDESC_LD64_LO12_NC), /* name */
1131 FALSE, /* partial_inplace */
1132 0xff8, /* src_mask */
1133 0xff8, /* dst_mask */
1134 FALSE), /* pcrel_offset */
1136 /* LD32: GOT offset G(S) & 0xffc. */
1137 HOWTO32 (AARCH64_R (TLSDESC_LD32_LO12_NC), /* type */
1139 2, /* size (0 = byte, 1 = short, 2 = long) */
1141 FALSE, /* pc_relative */
1143 complain_overflow_dont, /* complain_on_overflow */
1144 bfd_elf_generic_reloc, /* special_function */
1145 AARCH64_R_STR (TLSDESC_LD32_LO12_NC), /* name */
1146 FALSE, /* partial_inplace */
1147 0xffc, /* src_mask */
1148 0xffc, /* dst_mask */
1149 FALSE), /* pcrel_offset */
1151 /* ADD: GOT offset G(S) & 0xfff. */
1152 HOWTO (AARCH64_R (TLSDESC_ADD_LO12_NC), /* type */
1154 2, /* size (0 = byte, 1 = short, 2 = long) */
1156 FALSE, /* pc_relative */
1158 complain_overflow_dont, /* complain_on_overflow */
1159 bfd_elf_generic_reloc, /* special_function */
1160 AARCH64_R_STR (TLSDESC_ADD_LO12_NC), /* name */
1161 FALSE, /* partial_inplace */
1162 0xfff, /* src_mask */
1163 0xfff, /* dst_mask */
1164 FALSE), /* pcrel_offset */
1166 HOWTO64 (AARCH64_R (TLSDESC_OFF_G1), /* type */
1167 16, /* rightshift */
1168 2, /* size (0 = byte, 1 = short, 2 = long) */
1170 FALSE, /* pc_relative */
1172 complain_overflow_dont, /* complain_on_overflow */
1173 bfd_elf_generic_reloc, /* special_function */
1174 AARCH64_R_STR (TLSDESC_OFF_G1), /* name */
1175 FALSE, /* partial_inplace */
1176 0xffff, /* src_mask */
1177 0xffff, /* dst_mask */
1178 FALSE), /* pcrel_offset */
1180 HOWTO64 (AARCH64_R (TLSDESC_OFF_G0_NC), /* type */
1182 2, /* size (0 = byte, 1 = short, 2 = long) */
1184 FALSE, /* pc_relative */
1186 complain_overflow_dont, /* complain_on_overflow */
1187 bfd_elf_generic_reloc, /* special_function */
1188 AARCH64_R_STR (TLSDESC_OFF_G0_NC), /* name */
1189 FALSE, /* partial_inplace */
1190 0xffff, /* src_mask */
1191 0xffff, /* dst_mask */
1192 FALSE), /* pcrel_offset */
1194 HOWTO64 (AARCH64_R (TLSDESC_LDR), /* type */
1196 2, /* size (0 = byte, 1 = short, 2 = long) */
1198 FALSE, /* pc_relative */
1200 complain_overflow_dont, /* complain_on_overflow */
1201 bfd_elf_generic_reloc, /* special_function */
1202 AARCH64_R_STR (TLSDESC_LDR), /* name */
1203 FALSE, /* partial_inplace */
1206 FALSE), /* pcrel_offset */
1208 HOWTO64 (AARCH64_R (TLSDESC_ADD), /* type */
1210 2, /* size (0 = byte, 1 = short, 2 = long) */
1212 FALSE, /* pc_relative */
1214 complain_overflow_dont, /* complain_on_overflow */
1215 bfd_elf_generic_reloc, /* special_function */
1216 AARCH64_R_STR (TLSDESC_ADD), /* name */
1217 FALSE, /* partial_inplace */
1220 FALSE), /* pcrel_offset */
1222 HOWTO (AARCH64_R (TLSDESC_CALL), /* type */
1224 2, /* size (0 = byte, 1 = short, 2 = long) */
1226 FALSE, /* pc_relative */
1228 complain_overflow_dont, /* complain_on_overflow */
1229 bfd_elf_generic_reloc, /* special_function */
1230 AARCH64_R_STR (TLSDESC_CALL), /* name */
1231 FALSE, /* partial_inplace */
1234 FALSE), /* pcrel_offset */
1236 HOWTO (AARCH64_R (COPY), /* type */
1238 2, /* size (0 = byte, 1 = short, 2 = long) */
1240 FALSE, /* pc_relative */
1242 complain_overflow_bitfield, /* complain_on_overflow */
1243 bfd_elf_generic_reloc, /* special_function */
1244 AARCH64_R_STR (COPY), /* name */
1245 TRUE, /* partial_inplace */
1246 0xffffffff, /* src_mask */
1247 0xffffffff, /* dst_mask */
1248 FALSE), /* pcrel_offset */
1250 HOWTO (AARCH64_R (GLOB_DAT), /* type */
1252 2, /* size (0 = byte, 1 = short, 2 = long) */
1254 FALSE, /* pc_relative */
1256 complain_overflow_bitfield, /* complain_on_overflow */
1257 bfd_elf_generic_reloc, /* special_function */
1258 AARCH64_R_STR (GLOB_DAT), /* name */
1259 TRUE, /* partial_inplace */
1260 0xffffffff, /* src_mask */
1261 0xffffffff, /* dst_mask */
1262 FALSE), /* pcrel_offset */
1264 HOWTO (AARCH64_R (JUMP_SLOT), /* type */
1266 2, /* size (0 = byte, 1 = short, 2 = long) */
1268 FALSE, /* pc_relative */
1270 complain_overflow_bitfield, /* complain_on_overflow */
1271 bfd_elf_generic_reloc, /* special_function */
1272 AARCH64_R_STR (JUMP_SLOT), /* name */
1273 TRUE, /* partial_inplace */
1274 0xffffffff, /* src_mask */
1275 0xffffffff, /* dst_mask */
1276 FALSE), /* pcrel_offset */
1278 HOWTO (AARCH64_R (RELATIVE), /* type */
1280 2, /* size (0 = byte, 1 = short, 2 = long) */
1282 FALSE, /* pc_relative */
1284 complain_overflow_bitfield, /* complain_on_overflow */
1285 bfd_elf_generic_reloc, /* special_function */
1286 AARCH64_R_STR (RELATIVE), /* name */
1287 TRUE, /* partial_inplace */
1288 ALL_ONES, /* src_mask */
1289 ALL_ONES, /* dst_mask */
1290 FALSE), /* pcrel_offset */
1292 HOWTO (AARCH64_R (TLS_DTPMOD), /* type */
1294 2, /* size (0 = byte, 1 = short, 2 = long) */
1296 FALSE, /* pc_relative */
1298 complain_overflow_dont, /* complain_on_overflow */
1299 bfd_elf_generic_reloc, /* special_function */
1301 AARCH64_R_STR (TLS_DTPMOD64), /* name */
1303 AARCH64_R_STR (TLS_DTPMOD), /* name */
1305 FALSE, /* partial_inplace */
1307 ALL_ONES, /* dst_mask */
1308 FALSE), /* pc_reloffset */
1310 HOWTO (AARCH64_R (TLS_DTPREL), /* type */
1312 2, /* size (0 = byte, 1 = short, 2 = long) */
1314 FALSE, /* pc_relative */
1316 complain_overflow_dont, /* complain_on_overflow */
1317 bfd_elf_generic_reloc, /* special_function */
1319 AARCH64_R_STR (TLS_DTPREL64), /* name */
1321 AARCH64_R_STR (TLS_DTPREL), /* name */
1323 FALSE, /* partial_inplace */
1325 ALL_ONES, /* dst_mask */
1326 FALSE), /* pcrel_offset */
1328 HOWTO (AARCH64_R (TLS_TPREL), /* type */
1330 2, /* size (0 = byte, 1 = short, 2 = long) */
1332 FALSE, /* pc_relative */
1334 complain_overflow_dont, /* complain_on_overflow */
1335 bfd_elf_generic_reloc, /* special_function */
1337 AARCH64_R_STR (TLS_TPREL64), /* name */
1339 AARCH64_R_STR (TLS_TPREL), /* name */
1341 FALSE, /* partial_inplace */
1343 ALL_ONES, /* dst_mask */
1344 FALSE), /* pcrel_offset */
1346 HOWTO (AARCH64_R (TLSDESC), /* type */
1348 2, /* size (0 = byte, 1 = short, 2 = long) */
1350 FALSE, /* pc_relative */
1352 complain_overflow_dont, /* complain_on_overflow */
1353 bfd_elf_generic_reloc, /* special_function */
1354 AARCH64_R_STR (TLSDESC), /* name */
1355 FALSE, /* partial_inplace */
1357 ALL_ONES, /* dst_mask */
1358 FALSE), /* pcrel_offset */
1360 HOWTO (AARCH64_R (IRELATIVE), /* type */
1362 2, /* size (0 = byte, 1 = short, 2 = long) */
1364 FALSE, /* pc_relative */
1366 complain_overflow_bitfield, /* complain_on_overflow */
1367 bfd_elf_generic_reloc, /* special_function */
1368 AARCH64_R_STR (IRELATIVE), /* name */
1369 FALSE, /* partial_inplace */
1371 ALL_ONES, /* dst_mask */
1372 FALSE), /* pcrel_offset */
1377 static reloc_howto_type elfNN_aarch64_howto_none =
1378 HOWTO (R_AARCH64_NONE, /* type */
1380 0, /* 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 "R_AARCH64_NONE", /* name */
1387 FALSE, /* partial_inplace */
1390 FALSE); /* pcrel_offset */
1392 /* Given HOWTO, return the bfd internal relocation enumerator. */
1394 static bfd_reloc_code_real_type
1395 elfNN_aarch64_bfd_reloc_from_howto (reloc_howto_type *howto)
1398 = (int) ARRAY_SIZE (elfNN_aarch64_howto_table);
1399 const ptrdiff_t offset
1400 = howto - elfNN_aarch64_howto_table;
1402 if (offset > 0 && offset < size - 1)
1403 return BFD_RELOC_AARCH64_RELOC_START + offset;
1405 if (howto == &elfNN_aarch64_howto_none)
1406 return BFD_RELOC_AARCH64_NONE;
1408 return BFD_RELOC_AARCH64_RELOC_START;
1411 /* Given R_TYPE, return the bfd internal relocation enumerator. */
1413 static bfd_reloc_code_real_type
1414 elfNN_aarch64_bfd_reloc_from_type (unsigned int r_type)
1416 static bfd_boolean initialized_p = FALSE;
1417 /* Indexed by R_TYPE, values are offsets in the howto_table. */
1418 static unsigned int offsets[R_AARCH64_end];
1420 if (initialized_p == FALSE)
1424 for (i = 1; i < ARRAY_SIZE (elfNN_aarch64_howto_table) - 1; ++i)
1425 if (elfNN_aarch64_howto_table[i].type != 0)
1426 offsets[elfNN_aarch64_howto_table[i].type] = i;
1428 initialized_p = TRUE;
1431 if (r_type == R_AARCH64_NONE || r_type == R_AARCH64_NULL)
1432 return BFD_RELOC_AARCH64_NONE;
1434 return BFD_RELOC_AARCH64_RELOC_START + offsets[r_type];
1437 struct elf_aarch64_reloc_map
1439 bfd_reloc_code_real_type from;
1440 bfd_reloc_code_real_type to;
1443 /* Map bfd generic reloc to AArch64-specific reloc. */
1444 static const struct elf_aarch64_reloc_map elf_aarch64_reloc_map[] =
1446 {BFD_RELOC_NONE, BFD_RELOC_AARCH64_NONE},
1448 /* Basic data relocations. */
1449 {BFD_RELOC_CTOR, BFD_RELOC_AARCH64_NN},
1450 {BFD_RELOC_64, BFD_RELOC_AARCH64_64},
1451 {BFD_RELOC_32, BFD_RELOC_AARCH64_32},
1452 {BFD_RELOC_16, BFD_RELOC_AARCH64_16},
1453 {BFD_RELOC_64_PCREL, BFD_RELOC_AARCH64_64_PCREL},
1454 {BFD_RELOC_32_PCREL, BFD_RELOC_AARCH64_32_PCREL},
1455 {BFD_RELOC_16_PCREL, BFD_RELOC_AARCH64_16_PCREL},
1458 /* Given the bfd internal relocation enumerator in CODE, return the
1459 corresponding howto entry. */
1461 static reloc_howto_type *
1462 elfNN_aarch64_howto_from_bfd_reloc (bfd_reloc_code_real_type code)
1466 /* Convert bfd generic reloc to AArch64-specific reloc. */
1467 if (code < BFD_RELOC_AARCH64_RELOC_START
1468 || code > BFD_RELOC_AARCH64_RELOC_END)
1469 for (i = 0; i < ARRAY_SIZE (elf_aarch64_reloc_map); i++)
1470 if (elf_aarch64_reloc_map[i].from == code)
1472 code = elf_aarch64_reloc_map[i].to;
1476 if (code > BFD_RELOC_AARCH64_RELOC_START
1477 && code < BFD_RELOC_AARCH64_RELOC_END)
1478 if (elfNN_aarch64_howto_table[code - BFD_RELOC_AARCH64_RELOC_START].type)
1479 return &elfNN_aarch64_howto_table[code - BFD_RELOC_AARCH64_RELOC_START];
1481 if (code == BFD_RELOC_AARCH64_NONE)
1482 return &elfNN_aarch64_howto_none;
1487 static reloc_howto_type *
1488 elfNN_aarch64_howto_from_type (unsigned int r_type)
1490 bfd_reloc_code_real_type val;
1491 reloc_howto_type *howto;
1496 bfd_set_error (bfd_error_bad_value);
1501 if (r_type == R_AARCH64_NONE)
1502 return &elfNN_aarch64_howto_none;
1504 val = elfNN_aarch64_bfd_reloc_from_type (r_type);
1505 howto = elfNN_aarch64_howto_from_bfd_reloc (val);
1510 bfd_set_error (bfd_error_bad_value);
1515 elfNN_aarch64_info_to_howto (bfd *abfd ATTRIBUTE_UNUSED, arelent *bfd_reloc,
1516 Elf_Internal_Rela *elf_reloc)
1518 unsigned int r_type;
1520 r_type = ELFNN_R_TYPE (elf_reloc->r_info);
1521 bfd_reloc->howto = elfNN_aarch64_howto_from_type (r_type);
1524 static reloc_howto_type *
1525 elfNN_aarch64_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED,
1526 bfd_reloc_code_real_type code)
1528 reloc_howto_type *howto = elfNN_aarch64_howto_from_bfd_reloc (code);
1533 bfd_set_error (bfd_error_bad_value);
1537 static reloc_howto_type *
1538 elfNN_aarch64_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED,
1543 for (i = 1; i < ARRAY_SIZE (elfNN_aarch64_howto_table) - 1; ++i)
1544 if (elfNN_aarch64_howto_table[i].name != NULL
1545 && strcasecmp (elfNN_aarch64_howto_table[i].name, r_name) == 0)
1546 return &elfNN_aarch64_howto_table[i];
1551 #define TARGET_LITTLE_SYM aarch64_elfNN_le_vec
1552 #define TARGET_LITTLE_NAME "elfNN-littleaarch64"
1553 #define TARGET_BIG_SYM aarch64_elfNN_be_vec
1554 #define TARGET_BIG_NAME "elfNN-bigaarch64"
1556 /* The linker script knows the section names for placement.
1557 The entry_names are used to do simple name mangling on the stubs.
1558 Given a function name, and its type, the stub can be found. The
1559 name can be changed. The only requirement is the %s be present. */
1560 #define STUB_ENTRY_NAME "__%s_veneer"
1562 /* The name of the dynamic interpreter. This is put in the .interp
1564 #define ELF_DYNAMIC_INTERPRETER "/lib/ld.so.1"
1566 #define AARCH64_MAX_FWD_BRANCH_OFFSET \
1567 (((1 << 25) - 1) << 2)
1568 #define AARCH64_MAX_BWD_BRANCH_OFFSET \
1571 #define AARCH64_MAX_ADRP_IMM ((1 << 20) - 1)
1572 #define AARCH64_MIN_ADRP_IMM (-(1 << 20))
1575 aarch64_valid_for_adrp_p (bfd_vma value, bfd_vma place)
1577 bfd_signed_vma offset = (bfd_signed_vma) (PG (value) - PG (place)) >> 12;
1578 return offset <= AARCH64_MAX_ADRP_IMM && offset >= AARCH64_MIN_ADRP_IMM;
1582 aarch64_valid_branch_p (bfd_vma value, bfd_vma place)
1584 bfd_signed_vma offset = (bfd_signed_vma) (value - place);
1585 return (offset <= AARCH64_MAX_FWD_BRANCH_OFFSET
1586 && offset >= AARCH64_MAX_BWD_BRANCH_OFFSET);
1589 static const uint32_t aarch64_adrp_branch_stub [] =
1591 0x90000010, /* adrp ip0, X */
1592 /* R_AARCH64_ADR_HI21_PCREL(X) */
1593 0x91000210, /* add ip0, ip0, :lo12:X */
1594 /* R_AARCH64_ADD_ABS_LO12_NC(X) */
1595 0xd61f0200, /* br ip0 */
1598 static const uint32_t aarch64_long_branch_stub[] =
1601 0x58000090, /* ldr ip0, 1f */
1603 0x18000090, /* ldr wip0, 1f */
1605 0x10000011, /* adr ip1, #0 */
1606 0x8b110210, /* add ip0, ip0, ip1 */
1607 0xd61f0200, /* br ip0 */
1608 0x00000000, /* 1: .xword or .word
1609 R_AARCH64_PRELNN(X) + 12
1614 static const uint32_t aarch64_erratum_835769_stub[] =
1616 0x00000000, /* Placeholder for multiply accumulate. */
1617 0x14000000, /* b <label> */
1620 /* Section name for stubs is the associated section name plus this
1622 #define STUB_SUFFIX ".stub"
1624 enum elf_aarch64_stub_type
1627 aarch64_stub_adrp_branch,
1628 aarch64_stub_long_branch,
1629 aarch64_stub_erratum_835769_veneer,
1632 struct elf_aarch64_stub_hash_entry
1634 /* Base hash table entry structure. */
1635 struct bfd_hash_entry root;
1637 /* The stub section. */
1640 /* Offset within stub_sec of the beginning of this stub. */
1641 bfd_vma stub_offset;
1643 /* Given the symbol's value and its section we can determine its final
1644 value when building the stubs (so the stub knows where to jump). */
1645 bfd_vma target_value;
1646 asection *target_section;
1648 enum elf_aarch64_stub_type stub_type;
1650 /* The symbol table entry, if any, that this was derived from. */
1651 struct elf_aarch64_link_hash_entry *h;
1653 /* Destination symbol type */
1654 unsigned char st_type;
1656 /* Where this stub is being called from, or, in the case of combined
1657 stub sections, the first input section in the group. */
1660 /* The name for the local symbol at the start of this stub. The
1661 stub name in the hash table has to be unique; this does not, so
1662 it can be friendlier. */
1665 /* The instruction which caused this stub to be generated (only valid for
1666 erratum 835769 workaround stubs at present). */
1667 uint32_t veneered_insn;
1670 /* Used to build a map of a section. This is required for mixed-endian
1673 typedef struct elf_elf_section_map
1678 elf_aarch64_section_map;
1681 typedef struct _aarch64_elf_section_data
1683 struct bfd_elf_section_data elf;
1684 unsigned int mapcount;
1685 unsigned int mapsize;
1686 elf_aarch64_section_map *map;
1688 _aarch64_elf_section_data;
1690 #define elf_aarch64_section_data(sec) \
1691 ((_aarch64_elf_section_data *) elf_section_data (sec))
1693 /* A fix-descriptor for erratum 835769. */
1694 struct aarch64_erratum_835769_fix
1699 uint32_t veneered_insn;
1701 enum elf_aarch64_stub_type stub_type;
1704 /* The size of the thread control block which is defined to be two pointers. */
1705 #define TCB_SIZE (ARCH_SIZE/8)*2
1707 struct elf_aarch64_local_symbol
1709 unsigned int got_type;
1710 bfd_signed_vma got_refcount;
1713 /* Offset of the GOTPLT entry reserved for the TLS descriptor. The
1714 offset is from the end of the jump table and reserved entries
1717 The magic value (bfd_vma) -1 indicates that an offset has not be
1719 bfd_vma tlsdesc_got_jump_table_offset;
1722 struct elf_aarch64_obj_tdata
1724 struct elf_obj_tdata root;
1726 /* local symbol descriptors */
1727 struct elf_aarch64_local_symbol *locals;
1729 /* Zero to warn when linking objects with incompatible enum sizes. */
1730 int no_enum_size_warning;
1732 /* Zero to warn when linking objects with incompatible wchar_t sizes. */
1733 int no_wchar_size_warning;
1736 #define elf_aarch64_tdata(bfd) \
1737 ((struct elf_aarch64_obj_tdata *) (bfd)->tdata.any)
1739 #define elf_aarch64_locals(bfd) (elf_aarch64_tdata (bfd)->locals)
1741 #define is_aarch64_elf(bfd) \
1742 (bfd_get_flavour (bfd) == bfd_target_elf_flavour \
1743 && elf_tdata (bfd) != NULL \
1744 && elf_object_id (bfd) == AARCH64_ELF_DATA)
1747 elfNN_aarch64_mkobject (bfd *abfd)
1749 return bfd_elf_allocate_object (abfd, sizeof (struct elf_aarch64_obj_tdata),
1753 #define elf_aarch64_hash_entry(ent) \
1754 ((struct elf_aarch64_link_hash_entry *)(ent))
1756 #define GOT_UNKNOWN 0
1757 #define GOT_NORMAL 1
1758 #define GOT_TLS_GD 2
1759 #define GOT_TLS_IE 4
1760 #define GOT_TLSDESC_GD 8
1762 #define GOT_TLS_GD_ANY_P(type) ((type & GOT_TLS_GD) || (type & GOT_TLSDESC_GD))
1764 /* AArch64 ELF linker hash entry. */
1765 struct elf_aarch64_link_hash_entry
1767 struct elf_link_hash_entry root;
1769 /* Track dynamic relocs copied for this symbol. */
1770 struct elf_dyn_relocs *dyn_relocs;
1772 /* Since PLT entries have variable size, we need to record the
1773 index into .got.plt instead of recomputing it from the PLT
1775 bfd_signed_vma plt_got_offset;
1777 /* Bit mask representing the type of GOT entry(s) if any required by
1779 unsigned int got_type;
1781 /* A pointer to the most recently used stub hash entry against this
1783 struct elf_aarch64_stub_hash_entry *stub_cache;
1785 /* Offset of the GOTPLT entry reserved for the TLS descriptor. The offset
1786 is from the end of the jump table and reserved entries within the PLTGOT.
1788 The magic value (bfd_vma) -1 indicates that an offset has not
1790 bfd_vma tlsdesc_got_jump_table_offset;
1794 elfNN_aarch64_symbol_got_type (struct elf_link_hash_entry *h,
1796 unsigned long r_symndx)
1799 return elf_aarch64_hash_entry (h)->got_type;
1801 if (! elf_aarch64_locals (abfd))
1804 return elf_aarch64_locals (abfd)[r_symndx].got_type;
1807 /* Get the AArch64 elf linker hash table from a link_info structure. */
1808 #define elf_aarch64_hash_table(info) \
1809 ((struct elf_aarch64_link_hash_table *) ((info)->hash))
1811 #define aarch64_stub_hash_lookup(table, string, create, copy) \
1812 ((struct elf_aarch64_stub_hash_entry *) \
1813 bfd_hash_lookup ((table), (string), (create), (copy)))
1815 /* AArch64 ELF linker hash table. */
1816 struct elf_aarch64_link_hash_table
1818 /* The main hash table. */
1819 struct elf_link_hash_table root;
1821 /* Nonzero to force PIC branch veneers. */
1824 /* Fix erratum 835769. */
1825 int fix_erratum_835769;
1827 /* A table of fix locations for erratum 835769. This holds erratum
1828 fix locations between elfNN_aarch64_size_stubs() and
1829 elfNN_aarch64_write_section(). */
1830 struct aarch64_erratum_835769_fix *aarch64_erratum_835769_fixes;
1831 unsigned int num_aarch64_erratum_835769_fixes;
1833 /* The number of bytes in the initial entry in the PLT. */
1834 bfd_size_type plt_header_size;
1836 /* The number of bytes in the subsequent PLT etries. */
1837 bfd_size_type plt_entry_size;
1839 /* Short-cuts to get to dynamic linker sections. */
1843 /* Small local sym cache. */
1844 struct sym_cache sym_cache;
1846 /* For convenience in allocate_dynrelocs. */
1849 /* The amount of space used by the reserved portion of the sgotplt
1850 section, plus whatever space is used by the jump slots. */
1851 bfd_vma sgotplt_jump_table_size;
1853 /* The stub hash table. */
1854 struct bfd_hash_table stub_hash_table;
1856 /* Linker stub bfd. */
1859 /* Linker call-backs. */
1860 asection *(*add_stub_section) (const char *, asection *);
1861 void (*layout_sections_again) (void);
1863 /* Array to keep track of which stub sections have been created, and
1864 information on stub grouping. */
1867 /* This is the section to which stubs in the group will be
1870 /* The stub section. */
1874 /* Assorted information used by elfNN_aarch64_size_stubs. */
1875 unsigned int bfd_count;
1877 asection **input_list;
1879 /* The offset into splt of the PLT entry for the TLS descriptor
1880 resolver. Special values are 0, if not necessary (or not found
1881 to be necessary yet), and -1 if needed but not determined
1883 bfd_vma tlsdesc_plt;
1885 /* The GOT offset for the lazy trampoline. Communicated to the
1886 loader via DT_TLSDESC_GOT. The magic value (bfd_vma) -1
1887 indicates an offset is not allocated. */
1888 bfd_vma dt_tlsdesc_got;
1890 /* Used by local STT_GNU_IFUNC symbols. */
1891 htab_t loc_hash_table;
1892 void * loc_hash_memory;
1895 /* Create an entry in an AArch64 ELF linker hash table. */
1897 static struct bfd_hash_entry *
1898 elfNN_aarch64_link_hash_newfunc (struct bfd_hash_entry *entry,
1899 struct bfd_hash_table *table,
1902 struct elf_aarch64_link_hash_entry *ret =
1903 (struct elf_aarch64_link_hash_entry *) entry;
1905 /* Allocate the structure if it has not already been allocated by a
1908 ret = bfd_hash_allocate (table,
1909 sizeof (struct elf_aarch64_link_hash_entry));
1911 return (struct bfd_hash_entry *) ret;
1913 /* Call the allocation method of the superclass. */
1914 ret = ((struct elf_aarch64_link_hash_entry *)
1915 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry *) ret,
1919 ret->dyn_relocs = NULL;
1920 ret->got_type = GOT_UNKNOWN;
1921 ret->plt_got_offset = (bfd_vma) - 1;
1922 ret->stub_cache = NULL;
1923 ret->tlsdesc_got_jump_table_offset = (bfd_vma) - 1;
1926 return (struct bfd_hash_entry *) ret;
1929 /* Initialize an entry in the stub hash table. */
1931 static struct bfd_hash_entry *
1932 stub_hash_newfunc (struct bfd_hash_entry *entry,
1933 struct bfd_hash_table *table, const char *string)
1935 /* Allocate the structure if it has not already been allocated by a
1939 entry = bfd_hash_allocate (table,
1941 elf_aarch64_stub_hash_entry));
1946 /* Call the allocation method of the superclass. */
1947 entry = bfd_hash_newfunc (entry, table, string);
1950 struct elf_aarch64_stub_hash_entry *eh;
1952 /* Initialize the local fields. */
1953 eh = (struct elf_aarch64_stub_hash_entry *) entry;
1954 eh->stub_sec = NULL;
1955 eh->stub_offset = 0;
1956 eh->target_value = 0;
1957 eh->target_section = NULL;
1958 eh->stub_type = aarch64_stub_none;
1966 /* Compute a hash of a local hash entry. We use elf_link_hash_entry
1967 for local symbol so that we can handle local STT_GNU_IFUNC symbols
1968 as global symbol. We reuse indx and dynstr_index for local symbol
1969 hash since they aren't used by global symbols in this backend. */
1972 elfNN_aarch64_local_htab_hash (const void *ptr)
1974 struct elf_link_hash_entry *h
1975 = (struct elf_link_hash_entry *) ptr;
1976 return ELF_LOCAL_SYMBOL_HASH (h->indx, h->dynstr_index);
1979 /* Compare local hash entries. */
1982 elfNN_aarch64_local_htab_eq (const void *ptr1, const void *ptr2)
1984 struct elf_link_hash_entry *h1
1985 = (struct elf_link_hash_entry *) ptr1;
1986 struct elf_link_hash_entry *h2
1987 = (struct elf_link_hash_entry *) ptr2;
1989 return h1->indx == h2->indx && h1->dynstr_index == h2->dynstr_index;
1992 /* Find and/or create a hash entry for local symbol. */
1994 static struct elf_link_hash_entry *
1995 elfNN_aarch64_get_local_sym_hash (struct elf_aarch64_link_hash_table *htab,
1996 bfd *abfd, const Elf_Internal_Rela *rel,
1999 struct elf_aarch64_link_hash_entry e, *ret;
2000 asection *sec = abfd->sections;
2001 hashval_t h = ELF_LOCAL_SYMBOL_HASH (sec->id,
2002 ELFNN_R_SYM (rel->r_info));
2005 e.root.indx = sec->id;
2006 e.root.dynstr_index = ELFNN_R_SYM (rel->r_info);
2007 slot = htab_find_slot_with_hash (htab->loc_hash_table, &e, h,
2008 create ? INSERT : NO_INSERT);
2015 ret = (struct elf_aarch64_link_hash_entry *) *slot;
2019 ret = (struct elf_aarch64_link_hash_entry *)
2020 objalloc_alloc ((struct objalloc *) htab->loc_hash_memory,
2021 sizeof (struct elf_aarch64_link_hash_entry));
2024 memset (ret, 0, sizeof (*ret));
2025 ret->root.indx = sec->id;
2026 ret->root.dynstr_index = ELFNN_R_SYM (rel->r_info);
2027 ret->root.dynindx = -1;
2033 /* Copy the extra info we tack onto an elf_link_hash_entry. */
2036 elfNN_aarch64_copy_indirect_symbol (struct bfd_link_info *info,
2037 struct elf_link_hash_entry *dir,
2038 struct elf_link_hash_entry *ind)
2040 struct elf_aarch64_link_hash_entry *edir, *eind;
2042 edir = (struct elf_aarch64_link_hash_entry *) dir;
2043 eind = (struct elf_aarch64_link_hash_entry *) ind;
2045 if (eind->dyn_relocs != NULL)
2047 if (edir->dyn_relocs != NULL)
2049 struct elf_dyn_relocs **pp;
2050 struct elf_dyn_relocs *p;
2052 /* Add reloc counts against the indirect sym to the direct sym
2053 list. Merge any entries against the same section. */
2054 for (pp = &eind->dyn_relocs; (p = *pp) != NULL;)
2056 struct elf_dyn_relocs *q;
2058 for (q = edir->dyn_relocs; q != NULL; q = q->next)
2059 if (q->sec == p->sec)
2061 q->pc_count += p->pc_count;
2062 q->count += p->count;
2069 *pp = edir->dyn_relocs;
2072 edir->dyn_relocs = eind->dyn_relocs;
2073 eind->dyn_relocs = NULL;
2076 if (ind->root.type == bfd_link_hash_indirect)
2078 /* Copy over PLT info. */
2079 if (dir->got.refcount <= 0)
2081 edir->got_type = eind->got_type;
2082 eind->got_type = GOT_UNKNOWN;
2086 _bfd_elf_link_hash_copy_indirect (info, dir, ind);
2089 /* Destroy an AArch64 elf linker hash table. */
2092 elfNN_aarch64_link_hash_table_free (bfd *obfd)
2094 struct elf_aarch64_link_hash_table *ret
2095 = (struct elf_aarch64_link_hash_table *) obfd->link.hash;
2097 if (ret->loc_hash_table)
2098 htab_delete (ret->loc_hash_table);
2099 if (ret->loc_hash_memory)
2100 objalloc_free ((struct objalloc *) ret->loc_hash_memory);
2102 bfd_hash_table_free (&ret->stub_hash_table);
2103 _bfd_elf_link_hash_table_free (obfd);
2106 /* Create an AArch64 elf linker hash table. */
2108 static struct bfd_link_hash_table *
2109 elfNN_aarch64_link_hash_table_create (bfd *abfd)
2111 struct elf_aarch64_link_hash_table *ret;
2112 bfd_size_type amt = sizeof (struct elf_aarch64_link_hash_table);
2114 ret = bfd_zmalloc (amt);
2118 if (!_bfd_elf_link_hash_table_init
2119 (&ret->root, abfd, elfNN_aarch64_link_hash_newfunc,
2120 sizeof (struct elf_aarch64_link_hash_entry), AARCH64_ELF_DATA))
2126 ret->plt_header_size = PLT_ENTRY_SIZE;
2127 ret->plt_entry_size = PLT_SMALL_ENTRY_SIZE;
2129 ret->dt_tlsdesc_got = (bfd_vma) - 1;
2131 if (!bfd_hash_table_init (&ret->stub_hash_table, stub_hash_newfunc,
2132 sizeof (struct elf_aarch64_stub_hash_entry)))
2134 _bfd_elf_link_hash_table_free (abfd);
2138 ret->loc_hash_table = htab_try_create (1024,
2139 elfNN_aarch64_local_htab_hash,
2140 elfNN_aarch64_local_htab_eq,
2142 ret->loc_hash_memory = objalloc_create ();
2143 if (!ret->loc_hash_table || !ret->loc_hash_memory)
2145 elfNN_aarch64_link_hash_table_free (abfd);
2148 ret->root.root.hash_table_free = elfNN_aarch64_link_hash_table_free;
2150 return &ret->root.root;
2154 aarch64_relocate (unsigned int r_type, bfd *input_bfd, asection *input_section,
2155 bfd_vma offset, bfd_vma value)
2157 reloc_howto_type *howto;
2160 howto = elfNN_aarch64_howto_from_type (r_type);
2161 place = (input_section->output_section->vma + input_section->output_offset
2164 r_type = elfNN_aarch64_bfd_reloc_from_type (r_type);
2165 value = _bfd_aarch64_elf_resolve_relocation (r_type, place, value, 0, FALSE);
2166 return _bfd_aarch64_elf_put_addend (input_bfd,
2167 input_section->contents + offset, r_type,
2171 static enum elf_aarch64_stub_type
2172 aarch64_select_branch_stub (bfd_vma value, bfd_vma place)
2174 if (aarch64_valid_for_adrp_p (value, place))
2175 return aarch64_stub_adrp_branch;
2176 return aarch64_stub_long_branch;
2179 /* Determine the type of stub needed, if any, for a call. */
2181 static enum elf_aarch64_stub_type
2182 aarch64_type_of_stub (struct bfd_link_info *info,
2183 asection *input_sec,
2184 const Elf_Internal_Rela *rel,
2185 unsigned char st_type,
2186 struct elf_aarch64_link_hash_entry *hash,
2187 bfd_vma destination)
2190 bfd_signed_vma branch_offset;
2191 unsigned int r_type;
2192 struct elf_aarch64_link_hash_table *globals;
2193 enum elf_aarch64_stub_type stub_type = aarch64_stub_none;
2194 bfd_boolean via_plt_p;
2196 if (st_type != STT_FUNC)
2199 globals = elf_aarch64_hash_table (info);
2200 via_plt_p = (globals->root.splt != NULL && hash != NULL
2201 && hash->root.plt.offset != (bfd_vma) - 1);
2206 /* Determine where the call point is. */
2207 location = (input_sec->output_offset
2208 + input_sec->output_section->vma + rel->r_offset);
2210 branch_offset = (bfd_signed_vma) (destination - location);
2212 r_type = ELFNN_R_TYPE (rel->r_info);
2214 /* We don't want to redirect any old unconditional jump in this way,
2215 only one which is being used for a sibcall, where it is
2216 acceptable for the IP0 and IP1 registers to be clobbered. */
2217 if ((r_type == AARCH64_R (CALL26) || r_type == AARCH64_R (JUMP26))
2218 && (branch_offset > AARCH64_MAX_FWD_BRANCH_OFFSET
2219 || branch_offset < AARCH64_MAX_BWD_BRANCH_OFFSET))
2221 stub_type = aarch64_stub_long_branch;
2227 /* Build a name for an entry in the stub hash table. */
2230 elfNN_aarch64_stub_name (const asection *input_section,
2231 const asection *sym_sec,
2232 const struct elf_aarch64_link_hash_entry *hash,
2233 const Elf_Internal_Rela *rel)
2240 len = 8 + 1 + strlen (hash->root.root.root.string) + 1 + 16 + 1;
2241 stub_name = bfd_malloc (len);
2242 if (stub_name != NULL)
2243 snprintf (stub_name, len, "%08x_%s+%" BFD_VMA_FMT "x",
2244 (unsigned int) input_section->id,
2245 hash->root.root.root.string,
2250 len = 8 + 1 + 8 + 1 + 8 + 1 + 16 + 1;
2251 stub_name = bfd_malloc (len);
2252 if (stub_name != NULL)
2253 snprintf (stub_name, len, "%08x_%x:%x+%" BFD_VMA_FMT "x",
2254 (unsigned int) input_section->id,
2255 (unsigned int) sym_sec->id,
2256 (unsigned int) ELFNN_R_SYM (rel->r_info),
2263 /* Look up an entry in the stub hash. Stub entries are cached because
2264 creating the stub name takes a bit of time. */
2266 static struct elf_aarch64_stub_hash_entry *
2267 elfNN_aarch64_get_stub_entry (const asection *input_section,
2268 const asection *sym_sec,
2269 struct elf_link_hash_entry *hash,
2270 const Elf_Internal_Rela *rel,
2271 struct elf_aarch64_link_hash_table *htab)
2273 struct elf_aarch64_stub_hash_entry *stub_entry;
2274 struct elf_aarch64_link_hash_entry *h =
2275 (struct elf_aarch64_link_hash_entry *) hash;
2276 const asection *id_sec;
2278 if ((input_section->flags & SEC_CODE) == 0)
2281 /* If this input section is part of a group of sections sharing one
2282 stub section, then use the id of the first section in the group.
2283 Stub names need to include a section id, as there may well be
2284 more than one stub used to reach say, printf, and we need to
2285 distinguish between them. */
2286 id_sec = htab->stub_group[input_section->id].link_sec;
2288 if (h != NULL && h->stub_cache != NULL
2289 && h->stub_cache->h == h && h->stub_cache->id_sec == id_sec)
2291 stub_entry = h->stub_cache;
2297 stub_name = elfNN_aarch64_stub_name (id_sec, sym_sec, h, rel);
2298 if (stub_name == NULL)
2301 stub_entry = aarch64_stub_hash_lookup (&htab->stub_hash_table,
2302 stub_name, FALSE, FALSE);
2304 h->stub_cache = stub_entry;
2312 /* Add a new stub entry to the stub hash. Not all fields of the new
2313 stub entry are initialised. */
2315 static struct elf_aarch64_stub_hash_entry *
2316 elfNN_aarch64_add_stub (const char *stub_name,
2318 struct elf_aarch64_link_hash_table *htab)
2322 struct elf_aarch64_stub_hash_entry *stub_entry;
2324 link_sec = htab->stub_group[section->id].link_sec;
2325 stub_sec = htab->stub_group[section->id].stub_sec;
2326 if (stub_sec == NULL)
2328 stub_sec = htab->stub_group[link_sec->id].stub_sec;
2329 if (stub_sec == NULL)
2335 namelen = strlen (link_sec->name);
2336 len = namelen + sizeof (STUB_SUFFIX);
2337 s_name = bfd_alloc (htab->stub_bfd, len);
2341 memcpy (s_name, link_sec->name, namelen);
2342 memcpy (s_name + namelen, STUB_SUFFIX, sizeof (STUB_SUFFIX));
2343 stub_sec = (*htab->add_stub_section) (s_name, link_sec);
2344 if (stub_sec == NULL)
2346 htab->stub_group[link_sec->id].stub_sec = stub_sec;
2348 htab->stub_group[section->id].stub_sec = stub_sec;
2351 /* Enter this entry into the linker stub hash table. */
2352 stub_entry = aarch64_stub_hash_lookup (&htab->stub_hash_table, stub_name,
2354 if (stub_entry == NULL)
2356 (*_bfd_error_handler) (_("%s: cannot create stub entry %s"),
2357 section->owner, stub_name);
2361 stub_entry->stub_sec = stub_sec;
2362 stub_entry->stub_offset = 0;
2363 stub_entry->id_sec = link_sec;
2369 aarch64_build_one_stub (struct bfd_hash_entry *gen_entry,
2370 void *in_arg ATTRIBUTE_UNUSED)
2372 struct elf_aarch64_stub_hash_entry *stub_entry;
2377 bfd_vma veneered_insn_loc;
2378 bfd_vma veneer_entry_loc;
2379 bfd_signed_vma branch_offset = 0;
2380 unsigned int template_size;
2381 const uint32_t *template;
2384 /* Massage our args to the form they really have. */
2385 stub_entry = (struct elf_aarch64_stub_hash_entry *) gen_entry;
2387 stub_sec = stub_entry->stub_sec;
2389 /* Make a note of the offset within the stubs for this entry. */
2390 stub_entry->stub_offset = stub_sec->size;
2391 loc = stub_sec->contents + stub_entry->stub_offset;
2393 stub_bfd = stub_sec->owner;
2395 /* This is the address of the stub destination. */
2396 sym_value = (stub_entry->target_value
2397 + stub_entry->target_section->output_offset
2398 + stub_entry->target_section->output_section->vma);
2400 if (stub_entry->stub_type == aarch64_stub_long_branch)
2402 bfd_vma place = (stub_entry->stub_offset + stub_sec->output_section->vma
2403 + stub_sec->output_offset);
2405 /* See if we can relax the stub. */
2406 if (aarch64_valid_for_adrp_p (sym_value, place))
2407 stub_entry->stub_type = aarch64_select_branch_stub (sym_value, place);
2410 switch (stub_entry->stub_type)
2412 case aarch64_stub_adrp_branch:
2413 template = aarch64_adrp_branch_stub;
2414 template_size = sizeof (aarch64_adrp_branch_stub);
2416 case aarch64_stub_long_branch:
2417 template = aarch64_long_branch_stub;
2418 template_size = sizeof (aarch64_long_branch_stub);
2420 case aarch64_stub_erratum_835769_veneer:
2421 template = aarch64_erratum_835769_stub;
2422 template_size = sizeof (aarch64_erratum_835769_stub);
2429 for (i = 0; i < (template_size / sizeof template[0]); i++)
2431 bfd_putl32 (template[i], loc);
2435 template_size = (template_size + 7) & ~7;
2436 stub_sec->size += template_size;
2438 switch (stub_entry->stub_type)
2440 case aarch64_stub_adrp_branch:
2441 if (aarch64_relocate (AARCH64_R (ADR_PREL_PG_HI21), stub_bfd, stub_sec,
2442 stub_entry->stub_offset, sym_value))
2443 /* The stub would not have been relaxed if the offset was out
2447 _bfd_final_link_relocate
2448 (elfNN_aarch64_howto_from_type (AARCH64_R (ADD_ABS_LO12_NC)),
2452 stub_entry->stub_offset + 4,
2457 case aarch64_stub_long_branch:
2458 /* We want the value relative to the address 12 bytes back from the
2460 _bfd_final_link_relocate (elfNN_aarch64_howto_from_type
2461 (AARCH64_R (PRELNN)), stub_bfd, stub_sec,
2463 stub_entry->stub_offset + 16,
2467 case aarch64_stub_erratum_835769_veneer:
2468 veneered_insn_loc = stub_entry->target_section->output_section->vma
2469 + stub_entry->target_section->output_offset
2470 + stub_entry->target_value;
2471 veneer_entry_loc = stub_entry->stub_sec->output_section->vma
2472 + stub_entry->stub_sec->output_offset
2473 + stub_entry->stub_offset;
2474 branch_offset = veneered_insn_loc - veneer_entry_loc;
2475 branch_offset >>= 2;
2476 branch_offset &= 0x3ffffff;
2477 bfd_putl32 (stub_entry->veneered_insn,
2478 stub_sec->contents + stub_entry->stub_offset);
2479 bfd_putl32 (template[1] | branch_offset,
2480 stub_sec->contents + stub_entry->stub_offset + 4);
2490 /* As above, but don't actually build the stub. Just bump offset so
2491 we know stub section sizes. */
2494 aarch64_size_one_stub (struct bfd_hash_entry *gen_entry,
2495 void *in_arg ATTRIBUTE_UNUSED)
2497 struct elf_aarch64_stub_hash_entry *stub_entry;
2500 /* Massage our args to the form they really have. */
2501 stub_entry = (struct elf_aarch64_stub_hash_entry *) gen_entry;
2503 switch (stub_entry->stub_type)
2505 case aarch64_stub_adrp_branch:
2506 size = sizeof (aarch64_adrp_branch_stub);
2508 case aarch64_stub_long_branch:
2509 size = sizeof (aarch64_long_branch_stub);
2511 case aarch64_stub_erratum_835769_veneer:
2512 size = sizeof (aarch64_erratum_835769_stub);
2520 size = (size + 7) & ~7;
2521 stub_entry->stub_sec->size += size;
2525 /* External entry points for sizing and building linker stubs. */
2527 /* Set up various things so that we can make a list of input sections
2528 for each output section included in the link. Returns -1 on error,
2529 0 when no stubs will be needed, and 1 on success. */
2532 elfNN_aarch64_setup_section_lists (bfd *output_bfd,
2533 struct bfd_link_info *info)
2536 unsigned int bfd_count;
2537 int top_id, top_index;
2539 asection **input_list, **list;
2541 struct elf_aarch64_link_hash_table *htab =
2542 elf_aarch64_hash_table (info);
2544 if (!is_elf_hash_table (htab))
2547 /* Count the number of input BFDs and find the top input section id. */
2548 for (input_bfd = info->input_bfds, bfd_count = 0, top_id = 0;
2549 input_bfd != NULL; input_bfd = input_bfd->link.next)
2552 for (section = input_bfd->sections;
2553 section != NULL; section = section->next)
2555 if (top_id < section->id)
2556 top_id = section->id;
2559 htab->bfd_count = bfd_count;
2561 amt = sizeof (struct map_stub) * (top_id + 1);
2562 htab->stub_group = bfd_zmalloc (amt);
2563 if (htab->stub_group == NULL)
2566 /* We can't use output_bfd->section_count here to find the top output
2567 section index as some sections may have been removed, and
2568 _bfd_strip_section_from_output doesn't renumber the indices. */
2569 for (section = output_bfd->sections, top_index = 0;
2570 section != NULL; section = section->next)
2572 if (top_index < section->index)
2573 top_index = section->index;
2576 htab->top_index = top_index;
2577 amt = sizeof (asection *) * (top_index + 1);
2578 input_list = bfd_malloc (amt);
2579 htab->input_list = input_list;
2580 if (input_list == NULL)
2583 /* For sections we aren't interested in, mark their entries with a
2584 value we can check later. */
2585 list = input_list + top_index;
2587 *list = bfd_abs_section_ptr;
2588 while (list-- != input_list);
2590 for (section = output_bfd->sections;
2591 section != NULL; section = section->next)
2593 if ((section->flags & SEC_CODE) != 0)
2594 input_list[section->index] = NULL;
2600 /* Used by elfNN_aarch64_next_input_section and group_sections. */
2601 #define PREV_SEC(sec) (htab->stub_group[(sec)->id].link_sec)
2603 /* The linker repeatedly calls this function for each input section,
2604 in the order that input sections are linked into output sections.
2605 Build lists of input sections to determine groupings between which
2606 we may insert linker stubs. */
2609 elfNN_aarch64_next_input_section (struct bfd_link_info *info, asection *isec)
2611 struct elf_aarch64_link_hash_table *htab =
2612 elf_aarch64_hash_table (info);
2614 if (isec->output_section->index <= htab->top_index)
2616 asection **list = htab->input_list + isec->output_section->index;
2618 if (*list != bfd_abs_section_ptr)
2620 /* Steal the link_sec pointer for our list. */
2621 /* This happens to make the list in reverse order,
2622 which is what we want. */
2623 PREV_SEC (isec) = *list;
2629 /* See whether we can group stub sections together. Grouping stub
2630 sections may result in fewer stubs. More importantly, we need to
2631 put all .init* and .fini* stubs at the beginning of the .init or
2632 .fini output sections respectively, because glibc splits the
2633 _init and _fini functions into multiple parts. Putting a stub in
2634 the middle of a function is not a good idea. */
2637 group_sections (struct elf_aarch64_link_hash_table *htab,
2638 bfd_size_type stub_group_size,
2639 bfd_boolean stubs_always_before_branch)
2641 asection **list = htab->input_list + htab->top_index;
2645 asection *tail = *list;
2647 if (tail == bfd_abs_section_ptr)
2650 while (tail != NULL)
2654 bfd_size_type total;
2658 while ((prev = PREV_SEC (curr)) != NULL
2659 && ((total += curr->output_offset - prev->output_offset)
2663 /* OK, the size from the start of CURR to the end is less
2664 than stub_group_size and thus can be handled by one stub
2665 section. (Or the tail section is itself larger than
2666 stub_group_size, in which case we may be toast.)
2667 We should really be keeping track of the total size of
2668 stubs added here, as stubs contribute to the final output
2672 prev = PREV_SEC (tail);
2673 /* Set up this stub group. */
2674 htab->stub_group[tail->id].link_sec = curr;
2676 while (tail != curr && (tail = prev) != NULL);
2678 /* But wait, there's more! Input sections up to stub_group_size
2679 bytes before the stub section can be handled by it too. */
2680 if (!stubs_always_before_branch)
2684 && ((total += tail->output_offset - prev->output_offset)
2688 prev = PREV_SEC (tail);
2689 htab->stub_group[tail->id].link_sec = curr;
2695 while (list-- != htab->input_list);
2697 free (htab->input_list);
2702 #define AARCH64_BITS(x, pos, n) (((x) >> (pos)) & ((1 << (n)) - 1))
2704 #define AARCH64_RT(insn) AARCH64_BITS (insn, 0, 5)
2705 #define AARCH64_RT2(insn) AARCH64_BITS (insn, 10, 5)
2706 #define AARCH64_RA(insn) AARCH64_BITS (insn, 10, 5)
2707 #define AARCH64_RD(insn) AARCH64_BITS (insn, 0, 5)
2708 #define AARCH64_RN(insn) AARCH64_BITS (insn, 5, 5)
2709 #define AARCH64_RM(insn) AARCH64_BITS (insn, 16, 5)
2711 #define AARCH64_MAC(insn) (((insn) & 0xff000000) == 0x9b000000)
2712 #define AARCH64_BIT(insn, n) AARCH64_BITS (insn, n, 1)
2713 #define AARCH64_OP31(insn) AARCH64_BITS (insn, 21, 3)
2714 #define AARCH64_ZR 0x1f
2716 /* All ld/st ops. See C4-182 of the ARM ARM. The encoding space for
2717 LD_PCREL, LDST_RO, LDST_UI and LDST_UIMM cover prefetch ops. */
2719 #define AARCH64_LD(insn) (AARCH64_BIT (insn, 22) == 1)
2720 #define AARCH64_LDST(insn) (((insn) & 0x0a000000) == 0x08000000)
2721 #define AARCH64_LDST_EX(insn) (((insn) & 0x3f000000) == 0x08000000)
2722 #define AARCH64_LDST_PCREL(insn) (((insn) & 0x3b000000) == 0x18000000)
2723 #define AARCH64_LDST_NAP(insn) (((insn) & 0x3b800000) == 0x28000000)
2724 #define AARCH64_LDSTP_PI(insn) (((insn) & 0x3b800000) == 0x28800000)
2725 #define AARCH64_LDSTP_O(insn) (((insn) & 0x3b800000) == 0x29000000)
2726 #define AARCH64_LDSTP_PRE(insn) (((insn) & 0x3b800000) == 0x29800000)
2727 #define AARCH64_LDST_UI(insn) (((insn) & 0x3b200c00) == 0x38000000)
2728 #define AARCH64_LDST_PIIMM(insn) (((insn) & 0x3b200c00) == 0x38000400)
2729 #define AARCH64_LDST_U(insn) (((insn) & 0x3b200c00) == 0x38000800)
2730 #define AARCH64_LDST_PREIMM(insn) (((insn) & 0x3b200c00) == 0x38000c00)
2731 #define AARCH64_LDST_RO(insn) (((insn) & 0x3b200c00) == 0x38200800)
2732 #define AARCH64_LDST_UIMM(insn) (((insn) & 0x3b000000) == 0x39000000)
2733 #define AARCH64_LDST_SIMD_M(insn) (((insn) & 0xbfbf0000) == 0x0c000000)
2734 #define AARCH64_LDST_SIMD_M_PI(insn) (((insn) & 0xbfa00000) == 0x0c800000)
2735 #define AARCH64_LDST_SIMD_S(insn) (((insn) & 0xbf9f0000) == 0x0d000000)
2736 #define AARCH64_LDST_SIMD_S_PI(insn) (((insn) & 0xbf800000) == 0x0d800000)
2738 /* Classify an INSN if it is indeed a load/store. Return TRUE if INSN
2739 is a load/store along with the Rt and Rtn. Return FALSE if not a
2743 aarch64_mem_op_p (uint32_t insn, unsigned int *rt, unsigned int *rtn,
2744 bfd_boolean *pair, bfd_boolean *load)
2752 /* Bail out quickly if INSN doesn't fall into the the load-store
2754 if (!AARCH64_LDST (insn))
2759 if (AARCH64_LDST_EX (insn))
2761 *rt = AARCH64_RT (insn);
2763 if (AARCH64_BIT (insn, 21) == 1)
2766 *rtn = AARCH64_RT2 (insn);
2768 *load = AARCH64_LD (insn);
2771 else if (AARCH64_LDST_NAP (insn)
2772 || AARCH64_LDSTP_PI (insn)
2773 || AARCH64_LDSTP_O (insn)
2774 || AARCH64_LDSTP_PRE (insn))
2777 *rt = AARCH64_RT (insn);
2778 *rtn = AARCH64_RT2 (insn);
2779 *load = AARCH64_LD (insn);
2782 else if (AARCH64_LDST_PCREL (insn)
2783 || AARCH64_LDST_UI (insn)
2784 || AARCH64_LDST_PIIMM (insn)
2785 || AARCH64_LDST_U (insn)
2786 || AARCH64_LDST_PREIMM (insn)
2787 || AARCH64_LDST_RO (insn)
2788 || AARCH64_LDST_UIMM (insn))
2790 *rt = AARCH64_RT (insn);
2792 if (AARCH64_LDST_PCREL (insn))
2794 opc = AARCH64_BITS (insn, 22, 2);
2795 v = AARCH64_BIT (insn, 26);
2796 opc_v = opc | (v << 2);
2797 *load = (opc_v == 1 || opc_v == 2 || opc_v == 3
2798 || opc_v == 5 || opc_v == 7);
2801 else if (AARCH64_LDST_SIMD_M (insn)
2802 || AARCH64_LDST_SIMD_M_PI (insn))
2804 *rt = AARCH64_RT (insn);
2805 *load = AARCH64_BIT (insn, 22);
2806 opcode = (insn >> 12) & 0xf;
2833 else if (AARCH64_LDST_SIMD_S (insn)
2834 || AARCH64_LDST_SIMD_S_PI (insn))
2836 *rt = AARCH64_RT (insn);
2837 r = (insn >> 21) & 1;
2838 *load = AARCH64_BIT (insn, 22);
2839 opcode = (insn >> 13) & 0x7;
2851 *rtn = *rt + (r == 0 ? 2 : 3);
2859 *rtn = *rt + (r == 0 ? 2 : 3);
2871 /* Return TRUE if INSN is multiply-accumulate. */
2874 aarch64_mlxl_p (uint32_t insn)
2876 uint32_t op31 = AARCH64_OP31 (insn);
2878 if (AARCH64_MAC (insn)
2879 && (op31 == 0 || op31 == 1 || op31 == 5)
2880 /* Exclude MUL instructions which are encoded as a multiple accumulate
2882 && AARCH64_RA (insn) != AARCH64_ZR)
2888 /* Some early revisions of the Cortex-A53 have an erratum (835769) whereby
2889 it is possible for a 64-bit multiply-accumulate instruction to generate an
2890 incorrect result. The details are quite complex and hard to
2891 determine statically, since branches in the code may exist in some
2892 circumstances, but all cases end with a memory (load, store, or
2893 prefetch) instruction followed immediately by the multiply-accumulate
2894 operation. We employ a linker patching technique, by moving the potentially
2895 affected multiply-accumulate instruction into a patch region and replacing
2896 the original instruction with a branch to the patch. This function checks
2897 if INSN_1 is the memory operation followed by a multiply-accumulate
2898 operation (INSN_2). Return TRUE if an erratum sequence is found, FALSE
2899 if INSN_1 and INSN_2 are safe. */
2902 aarch64_erratum_sequence (uint32_t insn_1, uint32_t insn_2)
2912 if (aarch64_mlxl_p (insn_2)
2913 && aarch64_mem_op_p (insn_1, &rt, &rtn, &pair, &load))
2915 /* Any SIMD memory op is independent of the subsequent MLA
2916 by definition of the erratum. */
2917 if (AARCH64_BIT (insn_1, 26))
2920 /* If not SIMD, check for integer memory ops and MLA relationship. */
2921 rn = AARCH64_RN (insn_2);
2922 ra = AARCH64_RA (insn_2);
2923 rm = AARCH64_RM (insn_2);
2925 /* If this is a load and there's a true(RAW) dependency, we are safe
2926 and this is not an erratum sequence. */
2928 (rt == rn || rt == rm || rt == ra
2929 || (pair && (rtn == rn || rtn == rm || rtn == ra))))
2932 /* We conservatively put out stubs for all other cases (including
2941 erratum_835769_scan (bfd *input_bfd,
2942 struct bfd_link_info *info,
2943 struct aarch64_erratum_835769_fix **fixes_p,
2944 unsigned int *num_fixes_p,
2945 unsigned int *fix_table_size_p)
2948 struct elf_aarch64_link_hash_table *htab = elf_aarch64_hash_table (info);
2949 struct aarch64_erratum_835769_fix *fixes = *fixes_p;
2950 unsigned int num_fixes = *num_fixes_p;
2951 unsigned int fix_table_size = *fix_table_size_p;
2956 for (section = input_bfd->sections;
2958 section = section->next)
2960 bfd_byte *contents = NULL;
2961 struct _aarch64_elf_section_data *sec_data;
2964 if (elf_section_type (section) != SHT_PROGBITS
2965 || (elf_section_flags (section) & SHF_EXECINSTR) == 0
2966 || (section->flags & SEC_EXCLUDE) != 0
2967 || (section->sec_info_type == SEC_INFO_TYPE_JUST_SYMS)
2968 || (section->output_section == bfd_abs_section_ptr))
2971 if (elf_section_data (section)->this_hdr.contents != NULL)
2972 contents = elf_section_data (section)->this_hdr.contents;
2973 else if (! bfd_malloc_and_get_section (input_bfd, section, &contents))
2976 sec_data = elf_aarch64_section_data (section);
2977 for (span = 0; span < sec_data->mapcount; span++)
2979 unsigned int span_start = sec_data->map[span].vma;
2980 unsigned int span_end = ((span == sec_data->mapcount - 1)
2981 ? sec_data->map[0].vma + section->size
2982 : sec_data->map[span + 1].vma);
2984 char span_type = sec_data->map[span].type;
2986 if (span_type == 'd')
2989 for (i = span_start; i + 4 < span_end; i += 4)
2991 uint32_t insn_1 = bfd_getl32 (contents + i);
2992 uint32_t insn_2 = bfd_getl32 (contents + i + 4);
2994 if (aarch64_erratum_sequence (insn_1, insn_2))
2996 char *stub_name = NULL;
2997 stub_name = (char *) bfd_malloc
2998 (strlen ("__erratum_835769_veneer_") + 16);
2999 if (stub_name != NULL)
3001 (stub_name,"__erratum_835769_veneer_%d", num_fixes);
3005 if (num_fixes == fix_table_size)
3007 fix_table_size *= 2;
3009 (struct aarch64_erratum_835769_fix *)
3011 sizeof (struct aarch64_erratum_835769_fix)
3017 fixes[num_fixes].input_bfd = input_bfd;
3018 fixes[num_fixes].section = section;
3019 fixes[num_fixes].offset = i + 4;
3020 fixes[num_fixes].veneered_insn = insn_2;
3021 fixes[num_fixes].stub_name = stub_name;
3022 fixes[num_fixes].stub_type = aarch64_stub_erratum_835769_veneer;
3027 if (elf_section_data (section)->this_hdr.contents == NULL)
3032 *num_fixes_p = num_fixes;
3033 *fix_table_size_p = fix_table_size;
3037 /* Find or create a stub section. Returns a pointer to the stub section, and
3038 the section to which the stub section will be attached (in *LINK_SEC_P).
3039 LINK_SEC_P may be NULL. */
3042 elf_aarch64_create_or_find_stub_sec (asection **link_sec_p, asection *section,
3043 struct elf_aarch64_link_hash_table *htab)
3048 link_sec = htab->stub_group[section->id].link_sec;
3049 BFD_ASSERT (link_sec != NULL);
3050 stub_sec = htab->stub_group[section->id].stub_sec;
3052 if (stub_sec == NULL)
3054 stub_sec = htab->stub_group[link_sec->id].stub_sec;
3055 if (stub_sec == NULL)
3061 namelen = strlen (link_sec->name);
3062 len = namelen + sizeof (STUB_SUFFIX);
3063 s_name = (char *) bfd_alloc (htab->stub_bfd, len);
3067 memcpy (s_name, link_sec->name, namelen);
3068 memcpy (s_name + namelen, STUB_SUFFIX, sizeof (STUB_SUFFIX));
3069 stub_sec = (*htab->add_stub_section) (s_name, link_sec);
3071 if (stub_sec == NULL)
3073 htab->stub_group[link_sec->id].stub_sec = stub_sec;
3075 htab->stub_group[section->id].stub_sec = stub_sec;
3079 *link_sec_p = link_sec;
3084 /* Determine and set the size of the stub section for a final link.
3086 The basic idea here is to examine all the relocations looking for
3087 PC-relative calls to a target that is unreachable with a "bl"
3091 elfNN_aarch64_size_stubs (bfd *output_bfd,
3093 struct bfd_link_info *info,
3094 bfd_signed_vma group_size,
3095 asection * (*add_stub_section) (const char *,
3097 void (*layout_sections_again) (void))
3099 bfd_size_type stub_group_size;
3100 bfd_boolean stubs_always_before_branch;
3101 bfd_boolean stub_changed = 0;
3102 struct elf_aarch64_link_hash_table *htab = elf_aarch64_hash_table (info);
3103 struct aarch64_erratum_835769_fix *erratum_835769_fixes = NULL;
3104 unsigned int num_erratum_835769_fixes = 0;
3105 unsigned int erratum_835769_fix_table_size = 10;
3108 if (htab->fix_erratum_835769)
3110 erratum_835769_fixes
3111 = (struct aarch64_erratum_835769_fix *)
3113 (sizeof (struct aarch64_erratum_835769_fix) *
3114 erratum_835769_fix_table_size);
3115 if (erratum_835769_fixes == NULL)
3116 goto error_ret_free_local;
3119 /* Propagate mach to stub bfd, because it may not have been
3120 finalized when we created stub_bfd. */
3121 bfd_set_arch_mach (stub_bfd, bfd_get_arch (output_bfd),
3122 bfd_get_mach (output_bfd));
3124 /* Stash our params away. */
3125 htab->stub_bfd = stub_bfd;
3126 htab->add_stub_section = add_stub_section;
3127 htab->layout_sections_again = layout_sections_again;
3128 stubs_always_before_branch = group_size < 0;
3130 stub_group_size = -group_size;
3132 stub_group_size = group_size;
3134 if (stub_group_size == 1)
3136 /* Default values. */
3137 /* AArch64 branch range is +-128MB. The value used is 1MB less. */
3138 stub_group_size = 127 * 1024 * 1024;
3141 group_sections (htab, stub_group_size, stubs_always_before_branch);
3146 unsigned int bfd_indx;
3148 unsigned prev_num_erratum_835769_fixes = num_erratum_835769_fixes;
3150 num_erratum_835769_fixes = 0;
3151 for (input_bfd = info->input_bfds, bfd_indx = 0;
3152 input_bfd != NULL; input_bfd = input_bfd->link.next, bfd_indx++)
3154 Elf_Internal_Shdr *symtab_hdr;
3156 Elf_Internal_Sym *local_syms = NULL;
3158 /* We'll need the symbol table in a second. */
3159 symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
3160 if (symtab_hdr->sh_info == 0)
3163 /* Walk over each section attached to the input bfd. */
3164 for (section = input_bfd->sections;
3165 section != NULL; section = section->next)
3167 Elf_Internal_Rela *internal_relocs, *irelaend, *irela;
3169 /* If there aren't any relocs, then there's nothing more
3171 if ((section->flags & SEC_RELOC) == 0
3172 || section->reloc_count == 0
3173 || (section->flags & SEC_CODE) == 0)
3176 /* If this section is a link-once section that will be
3177 discarded, then don't create any stubs. */
3178 if (section->output_section == NULL
3179 || section->output_section->owner != output_bfd)
3182 /* Get the relocs. */
3184 = _bfd_elf_link_read_relocs (input_bfd, section, NULL,
3185 NULL, info->keep_memory);
3186 if (internal_relocs == NULL)
3187 goto error_ret_free_local;
3189 /* Now examine each relocation. */
3190 irela = internal_relocs;
3191 irelaend = irela + section->reloc_count;
3192 for (; irela < irelaend; irela++)
3194 unsigned int r_type, r_indx;
3195 enum elf_aarch64_stub_type stub_type;
3196 struct elf_aarch64_stub_hash_entry *stub_entry;
3199 bfd_vma destination;
3200 struct elf_aarch64_link_hash_entry *hash;
3201 const char *sym_name;
3203 const asection *id_sec;
3204 unsigned char st_type;
3207 r_type = ELFNN_R_TYPE (irela->r_info);
3208 r_indx = ELFNN_R_SYM (irela->r_info);
3210 if (r_type >= (unsigned int) R_AARCH64_end)
3212 bfd_set_error (bfd_error_bad_value);
3213 error_ret_free_internal:
3214 if (elf_section_data (section)->relocs == NULL)
3215 free (internal_relocs);
3216 goto error_ret_free_local;
3219 /* Only look for stubs on unconditional branch and
3220 branch and link instructions. */
3221 if (r_type != (unsigned int) AARCH64_R (CALL26)
3222 && r_type != (unsigned int) AARCH64_R (JUMP26))
3225 /* Now determine the call target, its name, value,
3232 if (r_indx < symtab_hdr->sh_info)
3234 /* It's a local symbol. */
3235 Elf_Internal_Sym *sym;
3236 Elf_Internal_Shdr *hdr;
3238 if (local_syms == NULL)
3241 = (Elf_Internal_Sym *) symtab_hdr->contents;
3242 if (local_syms == NULL)
3244 = bfd_elf_get_elf_syms (input_bfd, symtab_hdr,
3245 symtab_hdr->sh_info, 0,
3247 if (local_syms == NULL)
3248 goto error_ret_free_internal;
3251 sym = local_syms + r_indx;
3252 hdr = elf_elfsections (input_bfd)[sym->st_shndx];
3253 sym_sec = hdr->bfd_section;
3255 /* This is an undefined symbol. It can never
3259 if (ELF_ST_TYPE (sym->st_info) != STT_SECTION)
3260 sym_value = sym->st_value;
3261 destination = (sym_value + irela->r_addend
3262 + sym_sec->output_offset
3263 + sym_sec->output_section->vma);
3264 st_type = ELF_ST_TYPE (sym->st_info);
3266 = bfd_elf_string_from_elf_section (input_bfd,
3267 symtab_hdr->sh_link,
3274 e_indx = r_indx - symtab_hdr->sh_info;
3275 hash = ((struct elf_aarch64_link_hash_entry *)
3276 elf_sym_hashes (input_bfd)[e_indx]);
3278 while (hash->root.root.type == bfd_link_hash_indirect
3279 || hash->root.root.type == bfd_link_hash_warning)
3280 hash = ((struct elf_aarch64_link_hash_entry *)
3281 hash->root.root.u.i.link);
3283 if (hash->root.root.type == bfd_link_hash_defined
3284 || hash->root.root.type == bfd_link_hash_defweak)
3286 struct elf_aarch64_link_hash_table *globals =
3287 elf_aarch64_hash_table (info);
3288 sym_sec = hash->root.root.u.def.section;
3289 sym_value = hash->root.root.u.def.value;
3290 /* For a destination in a shared library,
3291 use the PLT stub as target address to
3292 decide whether a branch stub is
3294 if (globals->root.splt != NULL && hash != NULL
3295 && hash->root.plt.offset != (bfd_vma) - 1)
3297 sym_sec = globals->root.splt;
3298 sym_value = hash->root.plt.offset;
3299 if (sym_sec->output_section != NULL)
3300 destination = (sym_value
3301 + sym_sec->output_offset
3303 sym_sec->output_section->vma);
3305 else if (sym_sec->output_section != NULL)
3306 destination = (sym_value + irela->r_addend
3307 + sym_sec->output_offset
3308 + sym_sec->output_section->vma);
3310 else if (hash->root.root.type == bfd_link_hash_undefined
3311 || (hash->root.root.type
3312 == bfd_link_hash_undefweak))
3314 /* For a shared library, use the PLT stub as
3315 target address to decide whether a long
3316 branch stub is needed.
3317 For absolute code, they cannot be handled. */
3318 struct elf_aarch64_link_hash_table *globals =
3319 elf_aarch64_hash_table (info);
3321 if (globals->root.splt != NULL && hash != NULL
3322 && hash->root.plt.offset != (bfd_vma) - 1)
3324 sym_sec = globals->root.splt;
3325 sym_value = hash->root.plt.offset;
3326 if (sym_sec->output_section != NULL)
3327 destination = (sym_value
3328 + sym_sec->output_offset
3330 sym_sec->output_section->vma);
3337 bfd_set_error (bfd_error_bad_value);
3338 goto error_ret_free_internal;
3340 st_type = ELF_ST_TYPE (hash->root.type);
3341 sym_name = hash->root.root.root.string;
3344 /* Determine what (if any) linker stub is needed. */
3345 stub_type = aarch64_type_of_stub
3346 (info, section, irela, st_type, hash, destination);
3347 if (stub_type == aarch64_stub_none)
3350 /* Support for grouping stub sections. */
3351 id_sec = htab->stub_group[section->id].link_sec;
3353 /* Get the name of this stub. */
3354 stub_name = elfNN_aarch64_stub_name (id_sec, sym_sec, hash,
3357 goto error_ret_free_internal;
3360 aarch64_stub_hash_lookup (&htab->stub_hash_table,
3361 stub_name, FALSE, FALSE);
3362 if (stub_entry != NULL)
3364 /* The proper stub has already been created. */
3369 stub_entry = elfNN_aarch64_add_stub (stub_name, section,
3371 if (stub_entry == NULL)
3374 goto error_ret_free_internal;
3377 stub_entry->target_value = sym_value;
3378 stub_entry->target_section = sym_sec;
3379 stub_entry->stub_type = stub_type;
3380 stub_entry->h = hash;
3381 stub_entry->st_type = st_type;
3383 if (sym_name == NULL)
3384 sym_name = "unnamed";
3385 len = sizeof (STUB_ENTRY_NAME) + strlen (sym_name);
3386 stub_entry->output_name = bfd_alloc (htab->stub_bfd, len);
3387 if (stub_entry->output_name == NULL)
3390 goto error_ret_free_internal;
3393 snprintf (stub_entry->output_name, len, STUB_ENTRY_NAME,
3396 stub_changed = TRUE;
3399 /* We're done with the internal relocs, free them. */
3400 if (elf_section_data (section)->relocs == NULL)
3401 free (internal_relocs);
3404 if (htab->fix_erratum_835769)
3406 /* Scan for sequences which might trigger erratum 835769. */
3407 if (erratum_835769_scan (input_bfd, info, &erratum_835769_fixes,
3408 &num_erratum_835769_fixes,
3409 &erratum_835769_fix_table_size) != 0)
3410 goto error_ret_free_local;
3414 if (prev_num_erratum_835769_fixes != num_erratum_835769_fixes)
3415 stub_changed = TRUE;
3420 /* OK, we've added some stubs. Find out the new size of the
3422 for (stub_sec = htab->stub_bfd->sections;
3423 stub_sec != NULL; stub_sec = stub_sec->next)
3425 /* Ignore non-stub sections. */
3426 if (!strstr (stub_sec->name, STUB_SUFFIX))
3431 bfd_hash_traverse (&htab->stub_hash_table, aarch64_size_one_stub, htab);
3433 /* Add erratum 835769 veneers to stub section sizes too. */
3434 if (htab->fix_erratum_835769)
3435 for (i = 0; i < num_erratum_835769_fixes; i++)
3437 stub_sec = elf_aarch64_create_or_find_stub_sec (NULL,
3438 erratum_835769_fixes[i].section, htab);
3440 if (stub_sec == NULL)
3441 goto error_ret_free_local;
3443 stub_sec->size += 8;
3446 /* Ask the linker to do its stuff. */
3447 (*htab->layout_sections_again) ();
3448 stub_changed = FALSE;
3451 /* Add stubs for erratum 835769 fixes now. */
3452 if (htab->fix_erratum_835769)
3454 for (i = 0; i < num_erratum_835769_fixes; i++)
3456 struct elf_aarch64_stub_hash_entry *stub_entry;
3457 char *stub_name = erratum_835769_fixes[i].stub_name;
3458 asection *section = erratum_835769_fixes[i].section;
3459 unsigned int section_id = erratum_835769_fixes[i].section->id;
3460 asection *link_sec = htab->stub_group[section_id].link_sec;
3461 asection *stub_sec = htab->stub_group[section_id].stub_sec;
3463 stub_entry = aarch64_stub_hash_lookup (&htab->stub_hash_table,
3464 stub_name, TRUE, FALSE);
3465 if (stub_entry == NULL)
3467 (*_bfd_error_handler) (_("%s: cannot create stub entry %s"),
3473 stub_entry->stub_sec = stub_sec;
3474 stub_entry->stub_offset = 0;
3475 stub_entry->id_sec = link_sec;
3476 stub_entry->stub_type = erratum_835769_fixes[i].stub_type;
3477 stub_entry->target_section = section;
3478 stub_entry->target_value = erratum_835769_fixes[i].offset;
3479 stub_entry->veneered_insn = erratum_835769_fixes[i].veneered_insn;
3480 stub_entry->output_name = erratum_835769_fixes[i].stub_name;
3483 /* Stash the erratum 835769 fix array for use later in
3484 elfNN_aarch64_write_section(). */
3485 htab->aarch64_erratum_835769_fixes = erratum_835769_fixes;
3486 htab->num_aarch64_erratum_835769_fixes = num_erratum_835769_fixes;
3490 htab->aarch64_erratum_835769_fixes = NULL;
3491 htab->num_aarch64_erratum_835769_fixes = 0;
3496 error_ret_free_local:
3500 /* Build all the stubs associated with the current output file. The
3501 stubs are kept in a hash table attached to the main linker hash
3502 table. We also set up the .plt entries for statically linked PIC
3503 functions here. This function is called via aarch64_elf_finish in the
3507 elfNN_aarch64_build_stubs (struct bfd_link_info *info)
3510 struct bfd_hash_table *table;
3511 struct elf_aarch64_link_hash_table *htab;
3513 htab = elf_aarch64_hash_table (info);
3515 for (stub_sec = htab->stub_bfd->sections;
3516 stub_sec != NULL; stub_sec = stub_sec->next)
3520 /* Ignore non-stub sections. */
3521 if (!strstr (stub_sec->name, STUB_SUFFIX))
3524 /* Allocate memory to hold the linker stubs. */
3525 size = stub_sec->size;
3526 stub_sec->contents = bfd_zalloc (htab->stub_bfd, size);
3527 if (stub_sec->contents == NULL && size != 0)
3532 /* Build the stubs as directed by the stub hash table. */
3533 table = &htab->stub_hash_table;
3534 bfd_hash_traverse (table, aarch64_build_one_stub, info);
3540 /* Add an entry to the code/data map for section SEC. */
3543 elfNN_aarch64_section_map_add (asection *sec, char type, bfd_vma vma)
3545 struct _aarch64_elf_section_data *sec_data =
3546 elf_aarch64_section_data (sec);
3547 unsigned int newidx;
3549 if (sec_data->map == NULL)
3551 sec_data->map = bfd_malloc (sizeof (elf_aarch64_section_map));
3552 sec_data->mapcount = 0;
3553 sec_data->mapsize = 1;
3556 newidx = sec_data->mapcount++;
3558 if (sec_data->mapcount > sec_data->mapsize)
3560 sec_data->mapsize *= 2;
3561 sec_data->map = bfd_realloc_or_free
3562 (sec_data->map, sec_data->mapsize * sizeof (elf_aarch64_section_map));
3567 sec_data->map[newidx].vma = vma;
3568 sec_data->map[newidx].type = type;
3573 /* Initialise maps of insn/data for input BFDs. */
3575 bfd_elfNN_aarch64_init_maps (bfd *abfd)
3577 Elf_Internal_Sym *isymbuf;
3578 Elf_Internal_Shdr *hdr;
3579 unsigned int i, localsyms;
3581 /* Make sure that we are dealing with an AArch64 elf binary. */
3582 if (!is_aarch64_elf (abfd))
3585 if ((abfd->flags & DYNAMIC) != 0)
3588 hdr = &elf_symtab_hdr (abfd);
3589 localsyms = hdr->sh_info;
3591 /* Obtain a buffer full of symbols for this BFD. The hdr->sh_info field
3592 should contain the number of local symbols, which should come before any
3593 global symbols. Mapping symbols are always local. */
3594 isymbuf = bfd_elf_get_elf_syms (abfd, hdr, localsyms, 0, NULL, NULL, NULL);
3596 /* No internal symbols read? Skip this BFD. */
3597 if (isymbuf == NULL)
3600 for (i = 0; i < localsyms; i++)
3602 Elf_Internal_Sym *isym = &isymbuf[i];
3603 asection *sec = bfd_section_from_elf_index (abfd, isym->st_shndx);
3606 if (sec != NULL && ELF_ST_BIND (isym->st_info) == STB_LOCAL)
3608 name = bfd_elf_string_from_elf_section (abfd,
3612 if (bfd_is_aarch64_special_symbol_name
3613 (name, BFD_AARCH64_SPECIAL_SYM_TYPE_MAP))
3614 elfNN_aarch64_section_map_add (sec, name[1], isym->st_value);
3619 /* Set option values needed during linking. */
3621 bfd_elfNN_aarch64_set_options (struct bfd *output_bfd,
3622 struct bfd_link_info *link_info,
3624 int no_wchar_warn, int pic_veneer,
3625 int fix_erratum_835769)
3627 struct elf_aarch64_link_hash_table *globals;
3629 globals = elf_aarch64_hash_table (link_info);
3630 globals->pic_veneer = pic_veneer;
3631 globals->fix_erratum_835769 = fix_erratum_835769;
3633 BFD_ASSERT (is_aarch64_elf (output_bfd));
3634 elf_aarch64_tdata (output_bfd)->no_enum_size_warning = no_enum_warn;
3635 elf_aarch64_tdata (output_bfd)->no_wchar_size_warning = no_wchar_warn;
3639 aarch64_calculate_got_entry_vma (struct elf_link_hash_entry *h,
3640 struct elf_aarch64_link_hash_table
3641 *globals, struct bfd_link_info *info,
3642 bfd_vma value, bfd *output_bfd,
3643 bfd_boolean *unresolved_reloc_p)
3645 bfd_vma off = (bfd_vma) - 1;
3646 asection *basegot = globals->root.sgot;
3647 bfd_boolean dyn = globals->root.dynamic_sections_created;
3651 BFD_ASSERT (basegot != NULL);
3652 off = h->got.offset;
3653 BFD_ASSERT (off != (bfd_vma) - 1);
3654 if (!WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h)
3656 && SYMBOL_REFERENCES_LOCAL (info, h))
3657 || (ELF_ST_VISIBILITY (h->other)
3658 && h->root.type == bfd_link_hash_undefweak))
3660 /* This is actually a static link, or it is a -Bsymbolic link
3661 and the symbol is defined locally. We must initialize this
3662 entry in the global offset table. Since the offset must
3663 always be a multiple of 8 (4 in the case of ILP32), we use
3664 the least significant bit to record whether we have
3665 initialized it already.
3666 When doing a dynamic link, we create a .rel(a).got relocation
3667 entry to initialize the value. This is done in the
3668 finish_dynamic_symbol routine. */
3673 bfd_put_NN (output_bfd, value, basegot->contents + off);
3678 *unresolved_reloc_p = FALSE;
3680 off = off + basegot->output_section->vma + basegot->output_offset;
3686 /* Change R_TYPE to a more efficient access model where possible,
3687 return the new reloc type. */
3689 static bfd_reloc_code_real_type
3690 aarch64_tls_transition_without_check (bfd_reloc_code_real_type r_type,
3691 struct elf_link_hash_entry *h)
3693 bfd_boolean is_local = h == NULL;
3697 case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21:
3698 case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21:
3700 ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1
3701 : BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21);
3703 case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC:
3704 case BFD_RELOC_AARCH64_TLSDESC_LDNN_LO12_NC:
3706 ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC
3707 : BFD_RELOC_AARCH64_TLSIE_LDNN_GOTTPREL_LO12_NC);
3709 case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21:
3710 return is_local ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1 : r_type;
3712 case BFD_RELOC_AARCH64_TLSIE_LDNN_GOTTPREL_LO12_NC:
3713 return is_local ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC : r_type;
3715 case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12_NC:
3716 case BFD_RELOC_AARCH64_TLSDESC_CALL:
3717 /* Instructions with these relocations will become NOPs. */
3718 return BFD_RELOC_AARCH64_NONE;
3728 aarch64_reloc_got_type (bfd_reloc_code_real_type r_type)
3732 case BFD_RELOC_AARCH64_LD64_GOT_LO12_NC:
3733 case BFD_RELOC_AARCH64_LD32_GOT_LO12_NC:
3734 case BFD_RELOC_AARCH64_ADR_GOT_PAGE:
3735 case BFD_RELOC_AARCH64_GOT_LD_PREL19:
3738 case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21:
3739 case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC:
3742 case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12_NC:
3743 case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21:
3744 case BFD_RELOC_AARCH64_TLSDESC_CALL:
3745 case BFD_RELOC_AARCH64_TLSDESC_LD64_LO12_NC:
3746 case BFD_RELOC_AARCH64_TLSDESC_LD32_LO12_NC:
3747 return GOT_TLSDESC_GD;
3749 case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21:
3750 case BFD_RELOC_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC:
3751 case BFD_RELOC_AARCH64_TLSIE_LD32_GOTTPREL_LO12_NC:
3754 case BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_HI12:
3755 case BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_LO12:
3756 case BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_LO12_NC:
3757 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0:
3758 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC:
3759 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1:
3760 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1_NC:
3761 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G2:
3771 aarch64_can_relax_tls (bfd *input_bfd,
3772 struct bfd_link_info *info,
3773 bfd_reloc_code_real_type r_type,
3774 struct elf_link_hash_entry *h,
3775 unsigned long r_symndx)
3777 unsigned int symbol_got_type;
3778 unsigned int reloc_got_type;
3780 if (! IS_AARCH64_TLS_RELOC (r_type))
3783 symbol_got_type = elfNN_aarch64_symbol_got_type (h, input_bfd, r_symndx);
3784 reloc_got_type = aarch64_reloc_got_type (r_type);
3786 if (symbol_got_type == GOT_TLS_IE && GOT_TLS_GD_ANY_P (reloc_got_type))
3792 if (h && h->root.type == bfd_link_hash_undefweak)
3798 /* Given the relocation code R_TYPE, return the relaxed bfd reloc
3801 static bfd_reloc_code_real_type
3802 aarch64_tls_transition (bfd *input_bfd,
3803 struct bfd_link_info *info,
3804 unsigned int r_type,
3805 struct elf_link_hash_entry *h,
3806 unsigned long r_symndx)
3808 bfd_reloc_code_real_type bfd_r_type
3809 = elfNN_aarch64_bfd_reloc_from_type (r_type);
3811 if (! aarch64_can_relax_tls (input_bfd, info, bfd_r_type, h, r_symndx))
3814 return aarch64_tls_transition_without_check (bfd_r_type, h);
3817 /* Return the base VMA address which should be subtracted from real addresses
3818 when resolving R_AARCH64_TLS_DTPREL relocation. */
3821 dtpoff_base (struct bfd_link_info *info)
3823 /* If tls_sec is NULL, we should have signalled an error already. */
3824 BFD_ASSERT (elf_hash_table (info)->tls_sec != NULL);
3825 return elf_hash_table (info)->tls_sec->vma;
3828 /* Return the base VMA address which should be subtracted from real addresses
3829 when resolving R_AARCH64_TLS_GOTTPREL64 relocations. */
3832 tpoff_base (struct bfd_link_info *info)
3834 struct elf_link_hash_table *htab = elf_hash_table (info);
3836 /* If tls_sec is NULL, we should have signalled an error already. */
3837 BFD_ASSERT (htab->tls_sec != NULL);
3839 bfd_vma base = align_power ((bfd_vma) TCB_SIZE,
3840 htab->tls_sec->alignment_power);
3841 return htab->tls_sec->vma - base;
3845 symbol_got_offset_ref (bfd *input_bfd, struct elf_link_hash_entry *h,
3846 unsigned long r_symndx)
3848 /* Calculate the address of the GOT entry for symbol
3849 referred to in h. */
3851 return &h->got.offset;
3855 struct elf_aarch64_local_symbol *l;
3857 l = elf_aarch64_locals (input_bfd);
3858 return &l[r_symndx].got_offset;
3863 symbol_got_offset_mark (bfd *input_bfd, struct elf_link_hash_entry *h,
3864 unsigned long r_symndx)
3867 p = symbol_got_offset_ref (input_bfd, h, r_symndx);
3872 symbol_got_offset_mark_p (bfd *input_bfd, struct elf_link_hash_entry *h,
3873 unsigned long r_symndx)
3876 value = * symbol_got_offset_ref (input_bfd, h, r_symndx);
3881 symbol_got_offset (bfd *input_bfd, struct elf_link_hash_entry *h,
3882 unsigned long r_symndx)
3885 value = * symbol_got_offset_ref (input_bfd, h, r_symndx);
3891 symbol_tlsdesc_got_offset_ref (bfd *input_bfd, struct elf_link_hash_entry *h,
3892 unsigned long r_symndx)
3894 /* Calculate the address of the GOT entry for symbol
3895 referred to in h. */
3898 struct elf_aarch64_link_hash_entry *eh;
3899 eh = (struct elf_aarch64_link_hash_entry *) h;
3900 return &eh->tlsdesc_got_jump_table_offset;
3905 struct elf_aarch64_local_symbol *l;
3907 l = elf_aarch64_locals (input_bfd);
3908 return &l[r_symndx].tlsdesc_got_jump_table_offset;
3913 symbol_tlsdesc_got_offset_mark (bfd *input_bfd, struct elf_link_hash_entry *h,
3914 unsigned long r_symndx)
3917 p = symbol_tlsdesc_got_offset_ref (input_bfd, h, r_symndx);
3922 symbol_tlsdesc_got_offset_mark_p (bfd *input_bfd,
3923 struct elf_link_hash_entry *h,
3924 unsigned long r_symndx)
3927 value = * symbol_tlsdesc_got_offset_ref (input_bfd, h, r_symndx);
3932 symbol_tlsdesc_got_offset (bfd *input_bfd, struct elf_link_hash_entry *h,
3933 unsigned long r_symndx)
3936 value = * symbol_tlsdesc_got_offset_ref (input_bfd, h, r_symndx);
3941 /* Data for make_branch_to_erratum_835769_stub(). */
3943 struct erratum_835769_branch_to_stub_data
3945 asection *output_section;
3949 /* Helper to insert branches to erratum 835769 stubs in the right
3950 places for a particular section. */
3953 make_branch_to_erratum_835769_stub (struct bfd_hash_entry *gen_entry,
3956 struct elf_aarch64_stub_hash_entry *stub_entry;
3957 struct erratum_835769_branch_to_stub_data *data;
3959 unsigned long branch_insn = 0;
3960 bfd_vma veneered_insn_loc, veneer_entry_loc;
3961 bfd_signed_vma branch_offset;
3962 unsigned int target;
3965 stub_entry = (struct elf_aarch64_stub_hash_entry *) gen_entry;
3966 data = (struct erratum_835769_branch_to_stub_data *) in_arg;
3968 if (stub_entry->target_section != data->output_section
3969 || stub_entry->stub_type != aarch64_stub_erratum_835769_veneer)
3972 contents = data->contents;
3973 veneered_insn_loc = stub_entry->target_section->output_section->vma
3974 + stub_entry->target_section->output_offset
3975 + stub_entry->target_value;
3976 veneer_entry_loc = stub_entry->stub_sec->output_section->vma
3977 + stub_entry->stub_sec->output_offset
3978 + stub_entry->stub_offset;
3979 branch_offset = veneer_entry_loc - veneered_insn_loc;
3981 abfd = stub_entry->target_section->owner;
3982 if (!aarch64_valid_branch_p (veneer_entry_loc, veneered_insn_loc))
3983 (*_bfd_error_handler)
3984 (_("%B: error: Erratum 835769 stub out "
3985 "of range (input file too large)"), abfd);
3987 target = stub_entry->target_value;
3988 branch_insn = 0x14000000;
3989 branch_offset >>= 2;
3990 branch_offset &= 0x3ffffff;
3991 branch_insn |= branch_offset;
3992 bfd_putl32 (branch_insn, &contents[target]);
3998 elfNN_aarch64_write_section (bfd *output_bfd ATTRIBUTE_UNUSED,
3999 struct bfd_link_info *link_info,
4004 struct elf_aarch64_link_hash_table *globals =
4005 elf_aarch64_hash_table (link_info);
4007 if (globals == NULL)
4010 /* Fix code to point to erratum 835769 stubs. */
4011 if (globals->fix_erratum_835769)
4013 struct erratum_835769_branch_to_stub_data data;
4015 data.output_section = sec;
4016 data.contents = contents;
4017 bfd_hash_traverse (&globals->stub_hash_table,
4018 make_branch_to_erratum_835769_stub, &data);
4024 /* Perform a relocation as part of a final link. */
4025 static bfd_reloc_status_type
4026 elfNN_aarch64_final_link_relocate (reloc_howto_type *howto,
4029 asection *input_section,
4031 Elf_Internal_Rela *rel,
4033 struct bfd_link_info *info,
4035 struct elf_link_hash_entry *h,
4036 bfd_boolean *unresolved_reloc_p,
4037 bfd_boolean save_addend,
4038 bfd_vma *saved_addend,
4039 Elf_Internal_Sym *sym)
4041 Elf_Internal_Shdr *symtab_hdr;
4042 unsigned int r_type = howto->type;
4043 bfd_reloc_code_real_type bfd_r_type
4044 = elfNN_aarch64_bfd_reloc_from_howto (howto);
4045 bfd_reloc_code_real_type new_bfd_r_type;
4046 unsigned long r_symndx;
4047 bfd_byte *hit_data = contents + rel->r_offset;
4049 bfd_signed_vma signed_addend;
4050 struct elf_aarch64_link_hash_table *globals;
4051 bfd_boolean weak_undef_p;
4053 globals = elf_aarch64_hash_table (info);
4055 symtab_hdr = &elf_symtab_hdr (input_bfd);
4057 BFD_ASSERT (is_aarch64_elf (input_bfd));
4059 r_symndx = ELFNN_R_SYM (rel->r_info);
4061 /* It is possible to have linker relaxations on some TLS access
4062 models. Update our information here. */
4063 new_bfd_r_type = aarch64_tls_transition (input_bfd, info, r_type, h, r_symndx);
4064 if (new_bfd_r_type != bfd_r_type)
4066 bfd_r_type = new_bfd_r_type;
4067 howto = elfNN_aarch64_howto_from_bfd_reloc (bfd_r_type);
4068 BFD_ASSERT (howto != NULL);
4069 r_type = howto->type;
4072 place = input_section->output_section->vma
4073 + input_section->output_offset + rel->r_offset;
4075 /* Get addend, accumulating the addend for consecutive relocs
4076 which refer to the same offset. */
4077 signed_addend = saved_addend ? *saved_addend : 0;
4078 signed_addend += rel->r_addend;
4080 weak_undef_p = (h ? h->root.type == bfd_link_hash_undefweak
4081 : bfd_is_und_section (sym_sec));
4083 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle
4084 it here if it is defined in a non-shared object. */
4086 && h->type == STT_GNU_IFUNC
4094 if ((input_section->flags & SEC_ALLOC) == 0
4095 || h->plt.offset == (bfd_vma) -1)
4098 /* STT_GNU_IFUNC symbol must go through PLT. */
4099 plt = globals->root.splt ? globals->root.splt : globals->root.iplt;
4100 value = (plt->output_section->vma + plt->output_offset + h->plt.offset);
4105 if (h->root.root.string)
4106 name = h->root.root.string;
4108 name = bfd_elf_sym_name (input_bfd, symtab_hdr, sym,
4110 (*_bfd_error_handler)
4111 (_("%B: relocation %s against STT_GNU_IFUNC "
4112 "symbol `%s' isn't handled by %s"), input_bfd,
4113 howto->name, name, __FUNCTION__);
4114 bfd_set_error (bfd_error_bad_value);
4117 case BFD_RELOC_AARCH64_NN:
4118 if (rel->r_addend != 0)
4120 if (h->root.root.string)
4121 name = h->root.root.string;
4123 name = bfd_elf_sym_name (input_bfd, symtab_hdr,
4125 (*_bfd_error_handler)
4126 (_("%B: relocation %s against STT_GNU_IFUNC "
4127 "symbol `%s' has non-zero addend: %d"),
4128 input_bfd, howto->name, name, rel->r_addend);
4129 bfd_set_error (bfd_error_bad_value);
4133 /* Generate dynamic relocation only when there is a
4134 non-GOT reference in a shared object. */
4135 if (info->shared && h->non_got_ref)
4137 Elf_Internal_Rela outrel;
4140 /* Need a dynamic relocation to get the real function
4142 outrel.r_offset = _bfd_elf_section_offset (output_bfd,
4146 if (outrel.r_offset == (bfd_vma) -1
4147 || outrel.r_offset == (bfd_vma) -2)
4150 outrel.r_offset += (input_section->output_section->vma
4151 + input_section->output_offset);
4153 if (h->dynindx == -1
4155 || info->executable)
4157 /* This symbol is resolved locally. */
4158 outrel.r_info = ELFNN_R_INFO (0, AARCH64_R (IRELATIVE));
4159 outrel.r_addend = (h->root.u.def.value
4160 + h->root.u.def.section->output_section->vma
4161 + h->root.u.def.section->output_offset);
4165 outrel.r_info = ELFNN_R_INFO (h->dynindx, r_type);
4166 outrel.r_addend = 0;
4169 sreloc = globals->root.irelifunc;
4170 elf_append_rela (output_bfd, sreloc, &outrel);
4172 /* If this reloc is against an external symbol, we
4173 do not want to fiddle with the addend. Otherwise,
4174 we need to include the symbol value so that it
4175 becomes an addend for the dynamic reloc. For an
4176 internal symbol, we have updated addend. */
4177 return bfd_reloc_ok;
4180 case BFD_RELOC_AARCH64_JUMP26:
4181 case BFD_RELOC_AARCH64_CALL26:
4182 value = _bfd_aarch64_elf_resolve_relocation (bfd_r_type, place, value,
4185 return _bfd_aarch64_elf_put_addend (input_bfd, hit_data, bfd_r_type,
4187 case BFD_RELOC_AARCH64_LD64_GOT_LO12_NC:
4188 case BFD_RELOC_AARCH64_LD32_GOT_LO12_NC:
4189 case BFD_RELOC_AARCH64_ADR_GOT_PAGE:
4190 case BFD_RELOC_AARCH64_GOT_LD_PREL19:
4191 base_got = globals->root.sgot;
4192 off = h->got.offset;
4194 if (base_got == NULL)
4197 if (off == (bfd_vma) -1)
4201 /* We can't use h->got.offset here to save state, or
4202 even just remember the offset, as finish_dynamic_symbol
4203 would use that as offset into .got. */
4205 if (globals->root.splt != NULL)
4207 plt_index = ((h->plt.offset - globals->plt_header_size) /
4208 globals->plt_entry_size);
4209 off = (plt_index + 3) * GOT_ENTRY_SIZE;
4210 base_got = globals->root.sgotplt;
4214 plt_index = h->plt.offset / globals->plt_entry_size;
4215 off = plt_index * GOT_ENTRY_SIZE;
4216 base_got = globals->root.igotplt;
4219 if (h->dynindx == -1
4223 /* This references the local definition. We must
4224 initialize this entry in the global offset table.
4225 Since the offset must always be a multiple of 8,
4226 we use the least significant bit to record
4227 whether we have initialized it already.
4229 When doing a dynamic link, we create a .rela.got
4230 relocation entry to initialize the value. This
4231 is done in the finish_dynamic_symbol routine. */
4236 bfd_put_NN (output_bfd, value,
4237 base_got->contents + off);
4238 /* Note that this is harmless as -1 | 1 still is -1. */
4242 value = (base_got->output_section->vma
4243 + base_got->output_offset + off);
4246 value = aarch64_calculate_got_entry_vma (h, globals, info,
4248 unresolved_reloc_p);
4249 value = _bfd_aarch64_elf_resolve_relocation (bfd_r_type, place, value,
4251 return _bfd_aarch64_elf_put_addend (input_bfd, hit_data, bfd_r_type, howto, value);
4252 case BFD_RELOC_AARCH64_ADR_HI21_PCREL:
4253 case BFD_RELOC_AARCH64_ADD_LO12:
4260 case BFD_RELOC_AARCH64_NONE:
4261 case BFD_RELOC_AARCH64_TLSDESC_CALL:
4262 *unresolved_reloc_p = FALSE;
4263 return bfd_reloc_ok;
4265 case BFD_RELOC_AARCH64_NN:
4267 /* When generating a shared object or relocatable executable, these
4268 relocations are copied into the output file to be resolved at
4270 if (((info->shared == TRUE) || globals->root.is_relocatable_executable)
4271 && (input_section->flags & SEC_ALLOC)
4273 || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
4274 || h->root.type != bfd_link_hash_undefweak))
4276 Elf_Internal_Rela outrel;
4278 bfd_boolean skip, relocate;
4281 *unresolved_reloc_p = FALSE;
4286 outrel.r_addend = signed_addend;
4288 _bfd_elf_section_offset (output_bfd, info, input_section,
4290 if (outrel.r_offset == (bfd_vma) - 1)
4292 else if (outrel.r_offset == (bfd_vma) - 2)
4298 outrel.r_offset += (input_section->output_section->vma
4299 + input_section->output_offset);
4302 memset (&outrel, 0, sizeof outrel);
4305 && (!info->shared || !info->symbolic || !h->def_regular))
4306 outrel.r_info = ELFNN_R_INFO (h->dynindx, r_type);
4311 /* On SVR4-ish systems, the dynamic loader cannot
4312 relocate the text and data segments independently,
4313 so the symbol does not matter. */
4315 outrel.r_info = ELFNN_R_INFO (symbol, AARCH64_R (RELATIVE));
4316 outrel.r_addend += value;
4319 sreloc = elf_section_data (input_section)->sreloc;
4320 if (sreloc == NULL || sreloc->contents == NULL)
4321 return bfd_reloc_notsupported;
4323 loc = sreloc->contents + sreloc->reloc_count++ * RELOC_SIZE (globals);
4324 bfd_elfNN_swap_reloca_out (output_bfd, &outrel, loc);
4326 if (sreloc->reloc_count * RELOC_SIZE (globals) > sreloc->size)
4328 /* Sanity to check that we have previously allocated
4329 sufficient space in the relocation section for the
4330 number of relocations we actually want to emit. */
4334 /* If this reloc is against an external symbol, we do not want to
4335 fiddle with the addend. Otherwise, we need to include the symbol
4336 value so that it becomes an addend for the dynamic reloc. */
4338 return bfd_reloc_ok;
4340 return _bfd_final_link_relocate (howto, input_bfd, input_section,
4341 contents, rel->r_offset, value,
4345 value += signed_addend;
4348 case BFD_RELOC_AARCH64_JUMP26:
4349 case BFD_RELOC_AARCH64_CALL26:
4351 asection *splt = globals->root.splt;
4352 bfd_boolean via_plt_p =
4353 splt != NULL && h != NULL && h->plt.offset != (bfd_vma) - 1;
4355 /* A call to an undefined weak symbol is converted to a jump to
4356 the next instruction unless a PLT entry will be created.
4357 The jump to the next instruction is optimized as a NOP.
4358 Do the same for local undefined symbols. */
4359 if (weak_undef_p && ! via_plt_p)
4361 bfd_putl32 (INSN_NOP, hit_data);
4362 return bfd_reloc_ok;
4365 /* If the call goes through a PLT entry, make sure to
4366 check distance to the right destination address. */
4369 value = (splt->output_section->vma
4370 + splt->output_offset + h->plt.offset);
4371 *unresolved_reloc_p = FALSE;
4374 /* If the target symbol is global and marked as a function the
4375 relocation applies a function call or a tail call. In this
4376 situation we can veneer out of range branches. The veneers
4377 use IP0 and IP1 hence cannot be used arbitrary out of range
4378 branches that occur within the body of a function. */
4379 if (h && h->type == STT_FUNC)
4381 /* Check if a stub has to be inserted because the destination
4383 if (! aarch64_valid_branch_p (value, place))
4385 /* The target is out of reach, so redirect the branch to
4386 the local stub for this function. */
4387 struct elf_aarch64_stub_hash_entry *stub_entry;
4388 stub_entry = elfNN_aarch64_get_stub_entry (input_section,
4391 if (stub_entry != NULL)
4392 value = (stub_entry->stub_offset
4393 + stub_entry->stub_sec->output_offset
4394 + stub_entry->stub_sec->output_section->vma);
4398 value = _bfd_aarch64_elf_resolve_relocation (bfd_r_type, place, value,
4399 signed_addend, weak_undef_p);
4402 case BFD_RELOC_AARCH64_16:
4404 case BFD_RELOC_AARCH64_32:
4406 case BFD_RELOC_AARCH64_ADD_LO12:
4407 case BFD_RELOC_AARCH64_ADR_LO21_PCREL:
4408 case BFD_RELOC_AARCH64_ADR_HI21_PCREL:
4409 case BFD_RELOC_AARCH64_ADR_HI21_NC_PCREL:
4410 case BFD_RELOC_AARCH64_BRANCH19:
4411 case BFD_RELOC_AARCH64_LD_LO19_PCREL:
4412 case BFD_RELOC_AARCH64_LDST8_LO12:
4413 case BFD_RELOC_AARCH64_LDST16_LO12:
4414 case BFD_RELOC_AARCH64_LDST32_LO12:
4415 case BFD_RELOC_AARCH64_LDST64_LO12:
4416 case BFD_RELOC_AARCH64_LDST128_LO12:
4417 case BFD_RELOC_AARCH64_MOVW_G0_S:
4418 case BFD_RELOC_AARCH64_MOVW_G1_S:
4419 case BFD_RELOC_AARCH64_MOVW_G2_S:
4420 case BFD_RELOC_AARCH64_MOVW_G0:
4421 case BFD_RELOC_AARCH64_MOVW_G0_NC:
4422 case BFD_RELOC_AARCH64_MOVW_G1:
4423 case BFD_RELOC_AARCH64_MOVW_G1_NC:
4424 case BFD_RELOC_AARCH64_MOVW_G2:
4425 case BFD_RELOC_AARCH64_MOVW_G2_NC:
4426 case BFD_RELOC_AARCH64_MOVW_G3:
4427 case BFD_RELOC_AARCH64_16_PCREL:
4428 case BFD_RELOC_AARCH64_32_PCREL:
4429 case BFD_RELOC_AARCH64_64_PCREL:
4430 case BFD_RELOC_AARCH64_TSTBR14:
4431 value = _bfd_aarch64_elf_resolve_relocation (bfd_r_type, place, value,
4432 signed_addend, weak_undef_p);
4435 case BFD_RELOC_AARCH64_LD64_GOT_LO12_NC:
4436 case BFD_RELOC_AARCH64_LD32_GOT_LO12_NC:
4437 case BFD_RELOC_AARCH64_ADR_GOT_PAGE:
4438 case BFD_RELOC_AARCH64_GOT_LD_PREL19:
4439 if (globals->root.sgot == NULL)
4440 BFD_ASSERT (h != NULL);
4444 value = aarch64_calculate_got_entry_vma (h, globals, info, value,
4446 unresolved_reloc_p);
4447 value = _bfd_aarch64_elf_resolve_relocation (bfd_r_type, place, value,
4452 case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21:
4453 case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC:
4454 case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21:
4455 case BFD_RELOC_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC:
4456 case BFD_RELOC_AARCH64_TLSIE_LD32_GOTTPREL_LO12_NC:
4457 if (globals->root.sgot == NULL)
4458 return bfd_reloc_notsupported;
4460 value = (symbol_got_offset (input_bfd, h, r_symndx)
4461 + globals->root.sgot->output_section->vma
4462 + globals->root.sgot->output_offset);
4464 value = _bfd_aarch64_elf_resolve_relocation (bfd_r_type, place, value,
4466 *unresolved_reloc_p = FALSE;
4469 case BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_HI12:
4470 case BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_LO12:
4471 case BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_LO12_NC:
4472 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0:
4473 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC:
4474 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1:
4475 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1_NC:
4476 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G2:
4477 value = _bfd_aarch64_elf_resolve_relocation (bfd_r_type, place, value,
4478 signed_addend - tpoff_base (info),
4480 *unresolved_reloc_p = FALSE;
4483 case BFD_RELOC_AARCH64_TLSDESC_ADD:
4484 case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12_NC:
4485 case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21:
4486 case BFD_RELOC_AARCH64_TLSDESC_LD32_LO12_NC:
4487 case BFD_RELOC_AARCH64_TLSDESC_LD64_LO12_NC:
4488 case BFD_RELOC_AARCH64_TLSDESC_LDR:
4489 if (globals->root.sgot == NULL)
4490 return bfd_reloc_notsupported;
4491 value = (symbol_tlsdesc_got_offset (input_bfd, h, r_symndx)
4492 + globals->root.sgotplt->output_section->vma
4493 + globals->root.sgotplt->output_offset
4494 + globals->sgotplt_jump_table_size);
4496 value = _bfd_aarch64_elf_resolve_relocation (bfd_r_type, place, value,
4498 *unresolved_reloc_p = FALSE;
4502 return bfd_reloc_notsupported;
4506 *saved_addend = value;
4508 /* Only apply the final relocation in a sequence. */
4510 return bfd_reloc_continue;
4512 return _bfd_aarch64_elf_put_addend (input_bfd, hit_data, bfd_r_type,
4516 /* Handle TLS relaxations. Relaxing is possible for symbols that use
4517 R_AARCH64_TLSDESC_ADR_{PAGE, LD64_LO12_NC, ADD_LO12_NC} during a static
4520 Return bfd_reloc_ok if we're done, bfd_reloc_continue if the caller
4521 is to then call final_link_relocate. Return other values in the
4524 static bfd_reloc_status_type
4525 elfNN_aarch64_tls_relax (struct elf_aarch64_link_hash_table *globals,
4526 bfd *input_bfd, bfd_byte *contents,
4527 Elf_Internal_Rela *rel, struct elf_link_hash_entry *h)
4529 bfd_boolean is_local = h == NULL;
4530 unsigned int r_type = ELFNN_R_TYPE (rel->r_info);
4533 BFD_ASSERT (globals && input_bfd && contents && rel);
4535 switch (elfNN_aarch64_bfd_reloc_from_type (r_type))
4537 case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21:
4538 case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21:
4541 /* GD->LE relaxation:
4542 adrp x0, :tlsgd:var => movz x0, :tprel_g1:var
4544 adrp x0, :tlsdesc:var => movz x0, :tprel_g1:var
4546 bfd_putl32 (0xd2a00000, contents + rel->r_offset);
4547 return bfd_reloc_continue;
4551 /* GD->IE relaxation:
4552 adrp x0, :tlsgd:var => adrp x0, :gottprel:var
4554 adrp x0, :tlsdesc:var => adrp x0, :gottprel:var
4556 return bfd_reloc_continue;
4559 case BFD_RELOC_AARCH64_TLSDESC_LDNN_LO12_NC:
4562 /* GD->LE relaxation:
4563 ldr xd, [x0, #:tlsdesc_lo12:var] => movk x0, :tprel_g0_nc:var
4565 bfd_putl32 (0xf2800000, contents + rel->r_offset);
4566 return bfd_reloc_continue;
4570 /* GD->IE relaxation:
4571 ldr xd, [x0, #:tlsdesc_lo12:var] => ldr x0, [x0, #:gottprel_lo12:var]
4573 insn = bfd_getl32 (contents + rel->r_offset);
4575 bfd_putl32 (insn, contents + rel->r_offset);
4576 return bfd_reloc_continue;
4579 case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC:
4582 /* GD->LE relaxation
4583 add x0, #:tlsgd_lo12:var => movk x0, :tprel_g0_nc:var
4584 bl __tls_get_addr => mrs x1, tpidr_el0
4585 nop => add x0, x1, x0
4588 /* First kill the tls_get_addr reloc on the bl instruction. */
4589 BFD_ASSERT (rel->r_offset + 4 == rel[1].r_offset);
4590 rel[1].r_info = ELFNN_R_INFO (STN_UNDEF, R_AARCH64_NONE);
4592 bfd_putl32 (0xf2800000, contents + rel->r_offset);
4593 bfd_putl32 (0xd53bd041, contents + rel->r_offset + 4);
4594 bfd_putl32 (0x8b000020, contents + rel->r_offset + 8);
4595 return bfd_reloc_continue;
4599 /* GD->IE relaxation
4600 ADD x0, #:tlsgd_lo12:var => ldr x0, [x0, #:gottprel_lo12:var]
4601 BL __tls_get_addr => mrs x1, tpidr_el0
4603 NOP => add x0, x1, x0
4606 BFD_ASSERT (ELFNN_R_TYPE (rel[1].r_info) == AARCH64_R (CALL26));
4608 /* Remove the relocation on the BL instruction. */
4609 rel[1].r_info = ELFNN_R_INFO (STN_UNDEF, R_AARCH64_NONE);
4611 bfd_putl32 (0xf9400000, contents + rel->r_offset);
4613 /* We choose to fixup the BL and NOP instructions using the
4614 offset from the second relocation to allow flexibility in
4615 scheduling instructions between the ADD and BL. */
4616 bfd_putl32 (0xd53bd041, contents + rel[1].r_offset);
4617 bfd_putl32 (0x8b000020, contents + rel[1].r_offset + 4);
4618 return bfd_reloc_continue;
4621 case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12_NC:
4622 case BFD_RELOC_AARCH64_TLSDESC_CALL:
4623 /* GD->IE/LE relaxation:
4624 add x0, x0, #:tlsdesc_lo12:var => nop
4627 bfd_putl32 (INSN_NOP, contents + rel->r_offset);
4628 return bfd_reloc_ok;
4630 case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21:
4631 /* IE->LE relaxation:
4632 adrp xd, :gottprel:var => movz xd, :tprel_g1:var
4636 insn = bfd_getl32 (contents + rel->r_offset);
4637 bfd_putl32 (0xd2a00000 | (insn & 0x1f), contents + rel->r_offset);
4639 return bfd_reloc_continue;
4641 case BFD_RELOC_AARCH64_TLSIE_LDNN_GOTTPREL_LO12_NC:
4642 /* IE->LE relaxation:
4643 ldr xd, [xm, #:gottprel_lo12:var] => movk xd, :tprel_g0_nc:var
4647 insn = bfd_getl32 (contents + rel->r_offset);
4648 bfd_putl32 (0xf2800000 | (insn & 0x1f), contents + rel->r_offset);
4650 return bfd_reloc_continue;
4653 return bfd_reloc_continue;
4656 return bfd_reloc_ok;
4659 /* Relocate an AArch64 ELF section. */
4662 elfNN_aarch64_relocate_section (bfd *output_bfd,
4663 struct bfd_link_info *info,
4665 asection *input_section,
4667 Elf_Internal_Rela *relocs,
4668 Elf_Internal_Sym *local_syms,
4669 asection **local_sections)
4671 Elf_Internal_Shdr *symtab_hdr;
4672 struct elf_link_hash_entry **sym_hashes;
4673 Elf_Internal_Rela *rel;
4674 Elf_Internal_Rela *relend;
4676 struct elf_aarch64_link_hash_table *globals;
4677 bfd_boolean save_addend = FALSE;
4680 globals = elf_aarch64_hash_table (info);
4682 symtab_hdr = &elf_symtab_hdr (input_bfd);
4683 sym_hashes = elf_sym_hashes (input_bfd);
4686 relend = relocs + input_section->reloc_count;
4687 for (; rel < relend; rel++)
4689 unsigned int r_type;
4690 bfd_reloc_code_real_type bfd_r_type;
4691 bfd_reloc_code_real_type relaxed_bfd_r_type;
4692 reloc_howto_type *howto;
4693 unsigned long r_symndx;
4694 Elf_Internal_Sym *sym;
4696 struct elf_link_hash_entry *h;
4698 bfd_reloc_status_type r;
4701 bfd_boolean unresolved_reloc = FALSE;
4702 char *error_message = NULL;
4704 r_symndx = ELFNN_R_SYM (rel->r_info);
4705 r_type = ELFNN_R_TYPE (rel->r_info);
4707 bfd_reloc.howto = elfNN_aarch64_howto_from_type (r_type);
4708 howto = bfd_reloc.howto;
4712 (*_bfd_error_handler)
4713 (_("%B: unrecognized relocation (0x%x) in section `%A'"),
4714 input_bfd, input_section, r_type);
4717 bfd_r_type = elfNN_aarch64_bfd_reloc_from_howto (howto);
4723 if (r_symndx < symtab_hdr->sh_info)
4725 sym = local_syms + r_symndx;
4726 sym_type = ELFNN_ST_TYPE (sym->st_info);
4727 sec = local_sections[r_symndx];
4729 /* An object file might have a reference to a local
4730 undefined symbol. This is a daft object file, but we
4731 should at least do something about it. */
4732 if (r_type != R_AARCH64_NONE && r_type != R_AARCH64_NULL
4733 && bfd_is_und_section (sec)
4734 && ELF_ST_BIND (sym->st_info) != STB_WEAK)
4736 if (!info->callbacks->undefined_symbol
4737 (info, bfd_elf_string_from_elf_section
4738 (input_bfd, symtab_hdr->sh_link, sym->st_name),
4739 input_bfd, input_section, rel->r_offset, TRUE))
4743 relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel);
4745 /* Relocate against local STT_GNU_IFUNC symbol. */
4746 if (!info->relocatable
4747 && ELF_ST_TYPE (sym->st_info) == STT_GNU_IFUNC)
4749 h = elfNN_aarch64_get_local_sym_hash (globals, input_bfd,
4754 /* Set STT_GNU_IFUNC symbol value. */
4755 h->root.u.def.value = sym->st_value;
4756 h->root.u.def.section = sec;
4761 bfd_boolean warned, ignored;
4763 RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel,
4764 r_symndx, symtab_hdr, sym_hashes,
4766 unresolved_reloc, warned, ignored);
4771 if (sec != NULL && discarded_section (sec))
4772 RELOC_AGAINST_DISCARDED_SECTION (info, input_bfd, input_section,
4773 rel, 1, relend, howto, 0, contents);
4775 if (info->relocatable)
4779 name = h->root.root.string;
4782 name = (bfd_elf_string_from_elf_section
4783 (input_bfd, symtab_hdr->sh_link, sym->st_name));
4784 if (name == NULL || *name == '\0')
4785 name = bfd_section_name (input_bfd, sec);
4789 && r_type != R_AARCH64_NONE
4790 && r_type != R_AARCH64_NULL
4792 || h->root.type == bfd_link_hash_defined
4793 || h->root.type == bfd_link_hash_defweak)
4794 && IS_AARCH64_TLS_RELOC (bfd_r_type) != (sym_type == STT_TLS))
4796 (*_bfd_error_handler)
4797 ((sym_type == STT_TLS
4798 ? _("%B(%A+0x%lx): %s used with TLS symbol %s")
4799 : _("%B(%A+0x%lx): %s used with non-TLS symbol %s")),
4801 input_section, (long) rel->r_offset, howto->name, name);
4804 /* We relax only if we can see that there can be a valid transition
4805 from a reloc type to another.
4806 We call elfNN_aarch64_final_link_relocate unless we're completely
4807 done, i.e., the relaxation produced the final output we want. */
4809 relaxed_bfd_r_type = aarch64_tls_transition (input_bfd, info, r_type,
4811 if (relaxed_bfd_r_type != bfd_r_type)
4813 bfd_r_type = relaxed_bfd_r_type;
4814 howto = elfNN_aarch64_howto_from_bfd_reloc (bfd_r_type);
4815 BFD_ASSERT (howto != NULL);
4816 r_type = howto->type;
4817 r = elfNN_aarch64_tls_relax (globals, input_bfd, contents, rel, h);
4818 unresolved_reloc = 0;
4821 r = bfd_reloc_continue;
4823 /* There may be multiple consecutive relocations for the
4824 same offset. In that case we are supposed to treat the
4825 output of each relocation as the addend for the next. */
4826 if (rel + 1 < relend
4827 && rel->r_offset == rel[1].r_offset
4828 && ELFNN_R_TYPE (rel[1].r_info) != R_AARCH64_NONE
4829 && ELFNN_R_TYPE (rel[1].r_info) != R_AARCH64_NULL)
4832 save_addend = FALSE;
4834 if (r == bfd_reloc_continue)
4835 r = elfNN_aarch64_final_link_relocate (howto, input_bfd, output_bfd,
4836 input_section, contents, rel,
4837 relocation, info, sec,
4838 h, &unresolved_reloc,
4839 save_addend, &addend, sym);
4841 switch (elfNN_aarch64_bfd_reloc_from_type (r_type))
4843 case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21:
4844 case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC:
4845 if (! symbol_got_offset_mark_p (input_bfd, h, r_symndx))
4847 bfd_boolean need_relocs = FALSE;
4852 off = symbol_got_offset (input_bfd, h, r_symndx);
4853 indx = h && h->dynindx != -1 ? h->dynindx : 0;
4856 (info->shared || indx != 0) &&
4858 || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
4859 || h->root.type != bfd_link_hash_undefweak);
4861 BFD_ASSERT (globals->root.srelgot != NULL);
4865 Elf_Internal_Rela rela;
4866 rela.r_info = ELFNN_R_INFO (indx, AARCH64_R (TLS_DTPMOD));
4868 rela.r_offset = globals->root.sgot->output_section->vma +
4869 globals->root.sgot->output_offset + off;
4872 loc = globals->root.srelgot->contents;
4873 loc += globals->root.srelgot->reloc_count++
4874 * RELOC_SIZE (htab);
4875 bfd_elfNN_swap_reloca_out (output_bfd, &rela, loc);
4879 bfd_put_NN (output_bfd,
4880 relocation - dtpoff_base (info),
4881 globals->root.sgot->contents + off
4886 /* This TLS symbol is global. We emit a
4887 relocation to fixup the tls offset at load
4890 ELFNN_R_INFO (indx, AARCH64_R (TLS_DTPREL));
4893 (globals->root.sgot->output_section->vma
4894 + globals->root.sgot->output_offset + off
4897 loc = globals->root.srelgot->contents;
4898 loc += globals->root.srelgot->reloc_count++
4899 * RELOC_SIZE (globals);
4900 bfd_elfNN_swap_reloca_out (output_bfd, &rela, loc);
4901 bfd_put_NN (output_bfd, (bfd_vma) 0,
4902 globals->root.sgot->contents + off
4908 bfd_put_NN (output_bfd, (bfd_vma) 1,
4909 globals->root.sgot->contents + off);
4910 bfd_put_NN (output_bfd,
4911 relocation - dtpoff_base (info),
4912 globals->root.sgot->contents + off
4916 symbol_got_offset_mark (input_bfd, h, r_symndx);
4920 case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21:
4921 case BFD_RELOC_AARCH64_TLSIE_LDNN_GOTTPREL_LO12_NC:
4922 if (! symbol_got_offset_mark_p (input_bfd, h, r_symndx))
4924 bfd_boolean need_relocs = FALSE;
4929 off = symbol_got_offset (input_bfd, h, r_symndx);
4931 indx = h && h->dynindx != -1 ? h->dynindx : 0;
4934 (info->shared || indx != 0) &&
4936 || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
4937 || h->root.type != bfd_link_hash_undefweak);
4939 BFD_ASSERT (globals->root.srelgot != NULL);
4943 Elf_Internal_Rela rela;
4946 rela.r_addend = relocation - dtpoff_base (info);
4950 rela.r_info = ELFNN_R_INFO (indx, AARCH64_R (TLS_TPREL));
4951 rela.r_offset = globals->root.sgot->output_section->vma +
4952 globals->root.sgot->output_offset + off;
4954 loc = globals->root.srelgot->contents;
4955 loc += globals->root.srelgot->reloc_count++
4956 * RELOC_SIZE (htab);
4958 bfd_elfNN_swap_reloca_out (output_bfd, &rela, loc);
4960 bfd_put_NN (output_bfd, rela.r_addend,
4961 globals->root.sgot->contents + off);
4964 bfd_put_NN (output_bfd, relocation - tpoff_base (info),
4965 globals->root.sgot->contents + off);
4967 symbol_got_offset_mark (input_bfd, h, r_symndx);
4971 case BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_LO12:
4972 case BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_HI12:
4973 case BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_LO12_NC:
4974 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G2:
4975 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1:
4976 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1_NC:
4977 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0:
4978 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC:
4981 case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12_NC:
4982 case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21:
4983 case BFD_RELOC_AARCH64_TLSDESC_LDNN_LO12_NC:
4984 if (! symbol_tlsdesc_got_offset_mark_p (input_bfd, h, r_symndx))
4986 bfd_boolean need_relocs = FALSE;
4987 int indx = h && h->dynindx != -1 ? h->dynindx : 0;
4988 bfd_vma off = symbol_tlsdesc_got_offset (input_bfd, h, r_symndx);
4990 need_relocs = (h == NULL
4991 || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
4992 || h->root.type != bfd_link_hash_undefweak);
4994 BFD_ASSERT (globals->root.srelgot != NULL);
4995 BFD_ASSERT (globals->root.sgot != NULL);
5000 Elf_Internal_Rela rela;
5001 rela.r_info = ELFNN_R_INFO (indx, AARCH64_R (TLSDESC));
5004 rela.r_offset = (globals->root.sgotplt->output_section->vma
5005 + globals->root.sgotplt->output_offset
5006 + off + globals->sgotplt_jump_table_size);
5009 rela.r_addend = relocation - dtpoff_base (info);
5011 /* Allocate the next available slot in the PLT reloc
5012 section to hold our R_AARCH64_TLSDESC, the next
5013 available slot is determined from reloc_count,
5014 which we step. But note, reloc_count was
5015 artifically moved down while allocating slots for
5016 real PLT relocs such that all of the PLT relocs
5017 will fit above the initial reloc_count and the
5018 extra stuff will fit below. */
5019 loc = globals->root.srelplt->contents;
5020 loc += globals->root.srelplt->reloc_count++
5021 * RELOC_SIZE (globals);
5023 bfd_elfNN_swap_reloca_out (output_bfd, &rela, loc);
5025 bfd_put_NN (output_bfd, (bfd_vma) 0,
5026 globals->root.sgotplt->contents + off +
5027 globals->sgotplt_jump_table_size);
5028 bfd_put_NN (output_bfd, (bfd_vma) 0,
5029 globals->root.sgotplt->contents + off +
5030 globals->sgotplt_jump_table_size +
5034 symbol_tlsdesc_got_offset_mark (input_bfd, h, r_symndx);
5045 /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
5046 because such sections are not SEC_ALLOC and thus ld.so will
5047 not process them. */
5048 if (unresolved_reloc
5049 && !((input_section->flags & SEC_DEBUGGING) != 0
5051 && _bfd_elf_section_offset (output_bfd, info, input_section,
5052 +rel->r_offset) != (bfd_vma) - 1)
5054 (*_bfd_error_handler)
5056 ("%B(%A+0x%lx): unresolvable %s relocation against symbol `%s'"),
5057 input_bfd, input_section, (long) rel->r_offset, howto->name,
5058 h->root.root.string);
5062 if (r != bfd_reloc_ok && r != bfd_reloc_continue)
5066 case bfd_reloc_overflow:
5067 /* If the overflowing reloc was to an undefined symbol,
5068 we have already printed one error message and there
5069 is no point complaining again. */
5071 h->root.type != bfd_link_hash_undefined)
5072 && (!((*info->callbacks->reloc_overflow)
5073 (info, (h ? &h->root : NULL), name, howto->name,
5074 (bfd_vma) 0, input_bfd, input_section,
5079 case bfd_reloc_undefined:
5080 if (!((*info->callbacks->undefined_symbol)
5081 (info, name, input_bfd, input_section,
5082 rel->r_offset, TRUE)))
5086 case bfd_reloc_outofrange:
5087 error_message = _("out of range");
5090 case bfd_reloc_notsupported:
5091 error_message = _("unsupported relocation");
5094 case bfd_reloc_dangerous:
5095 /* error_message should already be set. */
5099 error_message = _("unknown error");
5103 BFD_ASSERT (error_message != NULL);
5104 if (!((*info->callbacks->reloc_dangerous)
5105 (info, error_message, input_bfd, input_section,
5116 /* Set the right machine number. */
5119 elfNN_aarch64_object_p (bfd *abfd)
5122 bfd_default_set_arch_mach (abfd, bfd_arch_aarch64, bfd_mach_aarch64_ilp32);
5124 bfd_default_set_arch_mach (abfd, bfd_arch_aarch64, bfd_mach_aarch64);
5129 /* Function to keep AArch64 specific flags in the ELF header. */
5132 elfNN_aarch64_set_private_flags (bfd *abfd, flagword flags)
5134 if (elf_flags_init (abfd) && elf_elfheader (abfd)->e_flags != flags)
5139 elf_elfheader (abfd)->e_flags = flags;
5140 elf_flags_init (abfd) = TRUE;
5146 /* Merge backend specific data from an object file to the output
5147 object file when linking. */
5150 elfNN_aarch64_merge_private_bfd_data (bfd *ibfd, bfd *obfd)
5154 bfd_boolean flags_compatible = TRUE;
5157 /* Check if we have the same endianess. */
5158 if (!_bfd_generic_verify_endian_match (ibfd, obfd))
5161 if (!is_aarch64_elf (ibfd) || !is_aarch64_elf (obfd))
5164 /* The input BFD must have had its flags initialised. */
5165 /* The following seems bogus to me -- The flags are initialized in
5166 the assembler but I don't think an elf_flags_init field is
5167 written into the object. */
5168 /* BFD_ASSERT (elf_flags_init (ibfd)); */
5170 in_flags = elf_elfheader (ibfd)->e_flags;
5171 out_flags = elf_elfheader (obfd)->e_flags;
5173 if (!elf_flags_init (obfd))
5175 /* If the input is the default architecture and had the default
5176 flags then do not bother setting the flags for the output
5177 architecture, instead allow future merges to do this. If no
5178 future merges ever set these flags then they will retain their
5179 uninitialised values, which surprise surprise, correspond
5180 to the default values. */
5181 if (bfd_get_arch_info (ibfd)->the_default
5182 && elf_elfheader (ibfd)->e_flags == 0)
5185 elf_flags_init (obfd) = TRUE;
5186 elf_elfheader (obfd)->e_flags = in_flags;
5188 if (bfd_get_arch (obfd) == bfd_get_arch (ibfd)
5189 && bfd_get_arch_info (obfd)->the_default)
5190 return bfd_set_arch_mach (obfd, bfd_get_arch (ibfd),
5191 bfd_get_mach (ibfd));
5196 /* Identical flags must be compatible. */
5197 if (in_flags == out_flags)
5200 /* Check to see if the input BFD actually contains any sections. If
5201 not, its flags may not have been initialised either, but it
5202 cannot actually cause any incompatiblity. Do not short-circuit
5203 dynamic objects; their section list may be emptied by
5204 elf_link_add_object_symbols.
5206 Also check to see if there are no code sections in the input.
5207 In this case there is no need to check for code specific flags.
5208 XXX - do we need to worry about floating-point format compatability
5209 in data sections ? */
5210 if (!(ibfd->flags & DYNAMIC))
5212 bfd_boolean null_input_bfd = TRUE;
5213 bfd_boolean only_data_sections = TRUE;
5215 for (sec = ibfd->sections; sec != NULL; sec = sec->next)
5217 if ((bfd_get_section_flags (ibfd, sec)
5218 & (SEC_LOAD | SEC_CODE | SEC_HAS_CONTENTS))
5219 == (SEC_LOAD | SEC_CODE | SEC_HAS_CONTENTS))
5220 only_data_sections = FALSE;
5222 null_input_bfd = FALSE;
5226 if (null_input_bfd || only_data_sections)
5230 return flags_compatible;
5233 /* Display the flags field. */
5236 elfNN_aarch64_print_private_bfd_data (bfd *abfd, void *ptr)
5238 FILE *file = (FILE *) ptr;
5239 unsigned long flags;
5241 BFD_ASSERT (abfd != NULL && ptr != NULL);
5243 /* Print normal ELF private data. */
5244 _bfd_elf_print_private_bfd_data (abfd, ptr);
5246 flags = elf_elfheader (abfd)->e_flags;
5247 /* Ignore init flag - it may not be set, despite the flags field
5248 containing valid data. */
5250 /* xgettext:c-format */
5251 fprintf (file, _("private flags = %lx:"), elf_elfheader (abfd)->e_flags);
5254 fprintf (file, _("<Unrecognised flag bits set>"));
5261 /* Update the got entry reference counts for the section being removed. */
5264 elfNN_aarch64_gc_sweep_hook (bfd *abfd,
5265 struct bfd_link_info *info,
5267 const Elf_Internal_Rela * relocs)
5269 struct elf_aarch64_link_hash_table *htab;
5270 Elf_Internal_Shdr *symtab_hdr;
5271 struct elf_link_hash_entry **sym_hashes;
5272 struct elf_aarch64_local_symbol *locals;
5273 const Elf_Internal_Rela *rel, *relend;
5275 if (info->relocatable)
5278 htab = elf_aarch64_hash_table (info);
5283 elf_section_data (sec)->local_dynrel = NULL;
5285 symtab_hdr = &elf_symtab_hdr (abfd);
5286 sym_hashes = elf_sym_hashes (abfd);
5288 locals = elf_aarch64_locals (abfd);
5290 relend = relocs + sec->reloc_count;
5291 for (rel = relocs; rel < relend; rel++)
5293 unsigned long r_symndx;
5294 unsigned int r_type;
5295 struct elf_link_hash_entry *h = NULL;
5297 r_symndx = ELFNN_R_SYM (rel->r_info);
5299 if (r_symndx >= symtab_hdr->sh_info)
5302 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
5303 while (h->root.type == bfd_link_hash_indirect
5304 || h->root.type == bfd_link_hash_warning)
5305 h = (struct elf_link_hash_entry *) h->root.u.i.link;
5309 Elf_Internal_Sym *isym;
5311 /* A local symbol. */
5312 isym = bfd_sym_from_r_symndx (&htab->sym_cache,
5315 /* Check relocation against local STT_GNU_IFUNC symbol. */
5317 && ELF_ST_TYPE (isym->st_info) == STT_GNU_IFUNC)
5319 h = elfNN_aarch64_get_local_sym_hash (htab, abfd, rel, FALSE);
5327 struct elf_aarch64_link_hash_entry *eh;
5328 struct elf_dyn_relocs **pp;
5329 struct elf_dyn_relocs *p;
5331 eh = (struct elf_aarch64_link_hash_entry *) h;
5333 for (pp = &eh->dyn_relocs; (p = *pp) != NULL; pp = &p->next)
5336 /* Everything must go for SEC. */
5342 r_type = ELFNN_R_TYPE (rel->r_info);
5343 switch (aarch64_tls_transition (abfd,info, r_type, h ,r_symndx))
5345 case BFD_RELOC_AARCH64_ADR_GOT_PAGE:
5346 case BFD_RELOC_AARCH64_GOT_LD_PREL19:
5347 case BFD_RELOC_AARCH64_LD32_GOT_LO12_NC:
5348 case BFD_RELOC_AARCH64_LD64_GOT_LO12_NC:
5349 case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12_NC:
5350 case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21:
5351 case BFD_RELOC_AARCH64_TLSDESC_LD32_LO12_NC:
5352 case BFD_RELOC_AARCH64_TLSDESC_LD64_LO12_NC:
5353 case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC:
5354 case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21:
5355 case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21:
5356 case BFD_RELOC_AARCH64_TLSIE_LD32_GOTTPREL_LO12_NC:
5357 case BFD_RELOC_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC:
5358 case BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_HI12:
5359 case BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_LO12:
5360 case BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_LO12_NC:
5361 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0:
5362 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC:
5363 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1:
5364 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1_NC:
5365 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G2:
5368 if (h->got.refcount > 0)
5369 h->got.refcount -= 1;
5371 if (h->type == STT_GNU_IFUNC)
5373 if (h->plt.refcount > 0)
5374 h->plt.refcount -= 1;
5377 else if (locals != NULL)
5379 if (locals[r_symndx].got_refcount > 0)
5380 locals[r_symndx].got_refcount -= 1;
5384 case BFD_RELOC_AARCH64_CALL26:
5385 case BFD_RELOC_AARCH64_JUMP26:
5386 /* If this is a local symbol then we resolve it
5387 directly without creating a PLT entry. */
5391 if (h->plt.refcount > 0)
5392 h->plt.refcount -= 1;
5395 case BFD_RELOC_AARCH64_MOVW_G0_NC:
5396 case BFD_RELOC_AARCH64_MOVW_G1_NC:
5397 case BFD_RELOC_AARCH64_MOVW_G2_NC:
5398 case BFD_RELOC_AARCH64_MOVW_G3:
5399 case BFD_RELOC_AARCH64_ADR_HI21_NC_PCREL:
5400 case BFD_RELOC_AARCH64_ADR_HI21_PCREL:
5401 case BFD_RELOC_AARCH64_ADR_LO21_PCREL:
5402 case BFD_RELOC_AARCH64_NN:
5403 if (h != NULL && info->executable)
5405 if (h->plt.refcount > 0)
5406 h->plt.refcount -= 1;
5418 /* Adjust a symbol defined by a dynamic object and referenced by a
5419 regular object. The current definition is in some section of the
5420 dynamic object, but we're not including those sections. We have to
5421 change the definition to something the rest of the link can
5425 elfNN_aarch64_adjust_dynamic_symbol (struct bfd_link_info *info,
5426 struct elf_link_hash_entry *h)
5428 struct elf_aarch64_link_hash_table *htab;
5431 /* If this is a function, put it in the procedure linkage table. We
5432 will fill in the contents of the procedure linkage table later,
5433 when we know the address of the .got section. */
5434 if (h->type == STT_FUNC || h->type == STT_GNU_IFUNC || h->needs_plt)
5436 if (h->plt.refcount <= 0
5437 || (h->type != STT_GNU_IFUNC
5438 && (SYMBOL_CALLS_LOCAL (info, h)
5439 || (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
5440 && h->root.type == bfd_link_hash_undefweak))))
5442 /* This case can occur if we saw a CALL26 reloc in
5443 an input file, but the symbol wasn't referred to
5444 by a dynamic object or all references were
5445 garbage collected. In which case we can end up
5447 h->plt.offset = (bfd_vma) - 1;
5454 /* It's possible that we incorrectly decided a .plt reloc was
5455 needed for an R_X86_64_PC32 reloc to a non-function sym in
5456 check_relocs. We can't decide accurately between function and
5457 non-function syms in check-relocs; Objects loaded later in
5458 the link may change h->type. So fix it now. */
5459 h->plt.offset = (bfd_vma) - 1;
5462 /* If this is a weak symbol, and there is a real definition, the
5463 processor independent code will have arranged for us to see the
5464 real definition first, and we can just use the same value. */
5465 if (h->u.weakdef != NULL)
5467 BFD_ASSERT (h->u.weakdef->root.type == bfd_link_hash_defined
5468 || h->u.weakdef->root.type == bfd_link_hash_defweak);
5469 h->root.u.def.section = h->u.weakdef->root.u.def.section;
5470 h->root.u.def.value = h->u.weakdef->root.u.def.value;
5471 if (ELIMINATE_COPY_RELOCS || info->nocopyreloc)
5472 h->non_got_ref = h->u.weakdef->non_got_ref;
5476 /* If we are creating a shared library, we must presume that the
5477 only references to the symbol are via the global offset table.
5478 For such cases we need not do anything here; the relocations will
5479 be handled correctly by relocate_section. */
5483 /* If there are no references to this symbol that do not use the
5484 GOT, we don't need to generate a copy reloc. */
5485 if (!h->non_got_ref)
5488 /* If -z nocopyreloc was given, we won't generate them either. */
5489 if (info->nocopyreloc)
5495 /* We must allocate the symbol in our .dynbss section, which will
5496 become part of the .bss section of the executable. There will be
5497 an entry for this symbol in the .dynsym section. The dynamic
5498 object will contain position independent code, so all references
5499 from the dynamic object to this symbol will go through the global
5500 offset table. The dynamic linker will use the .dynsym entry to
5501 determine the address it must put in the global offset table, so
5502 both the dynamic object and the regular object will refer to the
5503 same memory location for the variable. */
5505 htab = elf_aarch64_hash_table (info);
5507 /* We must generate a R_AARCH64_COPY reloc to tell the dynamic linker
5508 to copy the initial value out of the dynamic object and into the
5509 runtime process image. */
5510 if ((h->root.u.def.section->flags & SEC_ALLOC) != 0 && h->size != 0)
5512 htab->srelbss->size += RELOC_SIZE (htab);
5518 return _bfd_elf_adjust_dynamic_copy (h, s);
5523 elfNN_aarch64_allocate_local_symbols (bfd *abfd, unsigned number)
5525 struct elf_aarch64_local_symbol *locals;
5526 locals = elf_aarch64_locals (abfd);
5529 locals = (struct elf_aarch64_local_symbol *)
5530 bfd_zalloc (abfd, number * sizeof (struct elf_aarch64_local_symbol));
5533 elf_aarch64_locals (abfd) = locals;
5538 /* Create the .got section to hold the global offset table. */
5541 aarch64_elf_create_got_section (bfd *abfd, struct bfd_link_info *info)
5543 const struct elf_backend_data *bed = get_elf_backend_data (abfd);
5546 struct elf_link_hash_entry *h;
5547 struct elf_link_hash_table *htab = elf_hash_table (info);
5549 /* This function may be called more than once. */
5550 s = bfd_get_linker_section (abfd, ".got");
5554 flags = bed->dynamic_sec_flags;
5556 s = bfd_make_section_anyway_with_flags (abfd,
5557 (bed->rela_plts_and_copies_p
5558 ? ".rela.got" : ".rel.got"),
5559 (bed->dynamic_sec_flags
5562 || ! bfd_set_section_alignment (abfd, s, bed->s->log_file_align))
5566 s = bfd_make_section_anyway_with_flags (abfd, ".got", flags);
5568 || !bfd_set_section_alignment (abfd, s, bed->s->log_file_align))
5571 htab->sgot->size += GOT_ENTRY_SIZE;
5573 if (bed->want_got_sym)
5575 /* Define the symbol _GLOBAL_OFFSET_TABLE_ at the start of the .got
5576 (or .got.plt) section. We don't do this in the linker script
5577 because we don't want to define the symbol if we are not creating
5578 a global offset table. */
5579 h = _bfd_elf_define_linkage_sym (abfd, info, s,
5580 "_GLOBAL_OFFSET_TABLE_");
5581 elf_hash_table (info)->hgot = h;
5586 if (bed->want_got_plt)
5588 s = bfd_make_section_anyway_with_flags (abfd, ".got.plt", flags);
5590 || !bfd_set_section_alignment (abfd, s,
5591 bed->s->log_file_align))
5596 /* The first bit of the global offset table is the header. */
5597 s->size += bed->got_header_size;
5602 /* Look through the relocs for a section during the first phase. */
5605 elfNN_aarch64_check_relocs (bfd *abfd, struct bfd_link_info *info,
5606 asection *sec, const Elf_Internal_Rela *relocs)
5608 Elf_Internal_Shdr *symtab_hdr;
5609 struct elf_link_hash_entry **sym_hashes;
5610 const Elf_Internal_Rela *rel;
5611 const Elf_Internal_Rela *rel_end;
5614 struct elf_aarch64_link_hash_table *htab;
5616 if (info->relocatable)
5619 BFD_ASSERT (is_aarch64_elf (abfd));
5621 htab = elf_aarch64_hash_table (info);
5624 symtab_hdr = &elf_symtab_hdr (abfd);
5625 sym_hashes = elf_sym_hashes (abfd);
5627 rel_end = relocs + sec->reloc_count;
5628 for (rel = relocs; rel < rel_end; rel++)
5630 struct elf_link_hash_entry *h;
5631 unsigned long r_symndx;
5632 unsigned int r_type;
5633 bfd_reloc_code_real_type bfd_r_type;
5634 Elf_Internal_Sym *isym;
5636 r_symndx = ELFNN_R_SYM (rel->r_info);
5637 r_type = ELFNN_R_TYPE (rel->r_info);
5639 if (r_symndx >= NUM_SHDR_ENTRIES (symtab_hdr))
5641 (*_bfd_error_handler) (_("%B: bad symbol index: %d"), abfd,
5646 if (r_symndx < symtab_hdr->sh_info)
5648 /* A local symbol. */
5649 isym = bfd_sym_from_r_symndx (&htab->sym_cache,
5654 /* Check relocation against local STT_GNU_IFUNC symbol. */
5655 if (ELF_ST_TYPE (isym->st_info) == STT_GNU_IFUNC)
5657 h = elfNN_aarch64_get_local_sym_hash (htab, abfd, rel,
5662 /* Fake a STT_GNU_IFUNC symbol. */
5663 h->type = STT_GNU_IFUNC;
5666 h->forced_local = 1;
5667 h->root.type = bfd_link_hash_defined;
5674 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
5675 while (h->root.type == bfd_link_hash_indirect
5676 || h->root.type == bfd_link_hash_warning)
5677 h = (struct elf_link_hash_entry *) h->root.u.i.link;
5679 /* PR15323, ref flags aren't set for references in the same
5681 h->root.non_ir_ref = 1;
5684 /* Could be done earlier, if h were already available. */
5685 bfd_r_type = aarch64_tls_transition (abfd, info, r_type, h, r_symndx);
5689 /* Create the ifunc sections for static executables. If we
5690 never see an indirect function symbol nor we are building
5691 a static executable, those sections will be empty and
5692 won't appear in output. */
5698 case BFD_RELOC_AARCH64_NN:
5699 case BFD_RELOC_AARCH64_CALL26:
5700 case BFD_RELOC_AARCH64_JUMP26:
5701 case BFD_RELOC_AARCH64_LD32_GOT_LO12_NC:
5702 case BFD_RELOC_AARCH64_LD64_GOT_LO12_NC:
5703 case BFD_RELOC_AARCH64_ADR_GOT_PAGE:
5704 case BFD_RELOC_AARCH64_GOT_LD_PREL19:
5705 case BFD_RELOC_AARCH64_ADR_HI21_PCREL:
5706 case BFD_RELOC_AARCH64_ADD_LO12:
5707 if (htab->root.dynobj == NULL)
5708 htab->root.dynobj = abfd;
5709 if (!_bfd_elf_create_ifunc_sections (htab->root.dynobj, info))
5714 /* It is referenced by a non-shared object. */
5716 h->root.non_ir_ref = 1;
5721 case BFD_RELOC_AARCH64_NN:
5723 /* We don't need to handle relocs into sections not going into
5724 the "real" output. */
5725 if ((sec->flags & SEC_ALLOC) == 0)
5733 h->plt.refcount += 1;
5734 h->pointer_equality_needed = 1;
5737 /* No need to do anything if we're not creating a shared
5743 struct elf_dyn_relocs *p;
5744 struct elf_dyn_relocs **head;
5746 /* We must copy these reloc types into the output file.
5747 Create a reloc section in dynobj and make room for
5751 if (htab->root.dynobj == NULL)
5752 htab->root.dynobj = abfd;
5754 sreloc = _bfd_elf_make_dynamic_reloc_section
5755 (sec, htab->root.dynobj, LOG_FILE_ALIGN, abfd, /*rela? */ TRUE);
5761 /* If this is a global symbol, we count the number of
5762 relocations we need for this symbol. */
5765 struct elf_aarch64_link_hash_entry *eh;
5766 eh = (struct elf_aarch64_link_hash_entry *) h;
5767 head = &eh->dyn_relocs;
5771 /* Track dynamic relocs needed for local syms too.
5772 We really need local syms available to do this
5778 isym = bfd_sym_from_r_symndx (&htab->sym_cache,
5783 s = bfd_section_from_elf_index (abfd, isym->st_shndx);
5787 /* Beware of type punned pointers vs strict aliasing
5789 vpp = &(elf_section_data (s)->local_dynrel);
5790 head = (struct elf_dyn_relocs **) vpp;
5794 if (p == NULL || p->sec != sec)
5796 bfd_size_type amt = sizeof *p;
5797 p = ((struct elf_dyn_relocs *)
5798 bfd_zalloc (htab->root.dynobj, amt));
5811 /* RR: We probably want to keep a consistency check that
5812 there are no dangling GOT_PAGE relocs. */
5813 case BFD_RELOC_AARCH64_ADR_GOT_PAGE:
5814 case BFD_RELOC_AARCH64_GOT_LD_PREL19:
5815 case BFD_RELOC_AARCH64_LD32_GOT_LO12_NC:
5816 case BFD_RELOC_AARCH64_LD64_GOT_LO12_NC:
5817 case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12_NC:
5818 case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21:
5819 case BFD_RELOC_AARCH64_TLSDESC_LD32_LO12_NC:
5820 case BFD_RELOC_AARCH64_TLSDESC_LD64_LO12_NC:
5821 case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC:
5822 case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21:
5823 case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21:
5824 case BFD_RELOC_AARCH64_TLSIE_LD32_GOTTPREL_LO12_NC:
5825 case BFD_RELOC_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC:
5826 case BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_HI12:
5827 case BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_LO12:
5828 case BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_LO12_NC:
5829 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0:
5830 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC:
5831 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1:
5832 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1_NC:
5833 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G2:
5836 unsigned old_got_type;
5838 got_type = aarch64_reloc_got_type (bfd_r_type);
5842 h->got.refcount += 1;
5843 old_got_type = elf_aarch64_hash_entry (h)->got_type;
5847 struct elf_aarch64_local_symbol *locals;
5849 if (!elfNN_aarch64_allocate_local_symbols
5850 (abfd, symtab_hdr->sh_info))
5853 locals = elf_aarch64_locals (abfd);
5854 BFD_ASSERT (r_symndx < symtab_hdr->sh_info);
5855 locals[r_symndx].got_refcount += 1;
5856 old_got_type = locals[r_symndx].got_type;
5859 /* If a variable is accessed with both general dynamic TLS
5860 methods, two slots may be created. */
5861 if (GOT_TLS_GD_ANY_P (old_got_type) && GOT_TLS_GD_ANY_P (got_type))
5862 got_type |= old_got_type;
5864 /* We will already have issued an error message if there
5865 is a TLS/non-TLS mismatch, based on the symbol type.
5866 So just combine any TLS types needed. */
5867 if (old_got_type != GOT_UNKNOWN && old_got_type != GOT_NORMAL
5868 && got_type != GOT_NORMAL)
5869 got_type |= old_got_type;
5871 /* If the symbol is accessed by both IE and GD methods, we
5872 are able to relax. Turn off the GD flag, without
5873 messing up with any other kind of TLS types that may be
5875 if ((got_type & GOT_TLS_IE) && GOT_TLS_GD_ANY_P (got_type))
5876 got_type &= ~ (GOT_TLSDESC_GD | GOT_TLS_GD);
5878 if (old_got_type != got_type)
5881 elf_aarch64_hash_entry (h)->got_type = got_type;
5884 struct elf_aarch64_local_symbol *locals;
5885 locals = elf_aarch64_locals (abfd);
5886 BFD_ASSERT (r_symndx < symtab_hdr->sh_info);
5887 locals[r_symndx].got_type = got_type;
5891 if (htab->root.dynobj == NULL)
5892 htab->root.dynobj = abfd;
5893 if (! aarch64_elf_create_got_section (htab->root.dynobj, info))
5898 case BFD_RELOC_AARCH64_MOVW_G0_NC:
5899 case BFD_RELOC_AARCH64_MOVW_G1_NC:
5900 case BFD_RELOC_AARCH64_MOVW_G2_NC:
5901 case BFD_RELOC_AARCH64_MOVW_G3:
5904 int howto_index = bfd_r_type - BFD_RELOC_AARCH64_RELOC_START;
5905 (*_bfd_error_handler)
5906 (_("%B: relocation %s against `%s' can not be used when making "
5907 "a shared object; recompile with -fPIC"),
5908 abfd, elfNN_aarch64_howto_table[howto_index].name,
5909 (h) ? h->root.root.string : "a local symbol");
5910 bfd_set_error (bfd_error_bad_value);
5914 case BFD_RELOC_AARCH64_ADR_HI21_NC_PCREL:
5915 case BFD_RELOC_AARCH64_ADR_HI21_PCREL:
5916 case BFD_RELOC_AARCH64_ADR_LO21_PCREL:
5917 if (h != NULL && info->executable)
5919 /* If this reloc is in a read-only section, we might
5920 need a copy reloc. We can't check reliably at this
5921 stage whether the section is read-only, as input
5922 sections have not yet been mapped to output sections.
5923 Tentatively set the flag for now, and correct in
5924 adjust_dynamic_symbol. */
5926 h->plt.refcount += 1;
5927 h->pointer_equality_needed = 1;
5929 /* FIXME:: RR need to handle these in shared libraries
5930 and essentially bomb out as these being non-PIC
5931 relocations in shared libraries. */
5934 case BFD_RELOC_AARCH64_CALL26:
5935 case BFD_RELOC_AARCH64_JUMP26:
5936 /* If this is a local symbol then we resolve it
5937 directly without creating a PLT entry. */
5942 if (h->plt.refcount <= 0)
5943 h->plt.refcount = 1;
5945 h->plt.refcount += 1;
5956 /* Treat mapping symbols as special target symbols. */
5959 elfNN_aarch64_is_target_special_symbol (bfd *abfd ATTRIBUTE_UNUSED,
5962 return bfd_is_aarch64_special_symbol_name (sym->name,
5963 BFD_AARCH64_SPECIAL_SYM_TYPE_ANY);
5966 /* This is a copy of elf_find_function () from elf.c except that
5967 AArch64 mapping symbols are ignored when looking for function names. */
5970 aarch64_elf_find_function (bfd *abfd ATTRIBUTE_UNUSED,
5974 const char **filename_ptr,
5975 const char **functionname_ptr)
5977 const char *filename = NULL;
5978 asymbol *func = NULL;
5979 bfd_vma low_func = 0;
5982 for (p = symbols; *p != NULL; p++)
5986 q = (elf_symbol_type *) * p;
5988 switch (ELF_ST_TYPE (q->internal_elf_sym.st_info))
5993 filename = bfd_asymbol_name (&q->symbol);
5997 /* Skip mapping symbols. */
5998 if ((q->symbol.flags & BSF_LOCAL)
5999 && (bfd_is_aarch64_special_symbol_name
6000 (q->symbol.name, BFD_AARCH64_SPECIAL_SYM_TYPE_ANY)))
6003 if (bfd_get_section (&q->symbol) == section
6004 && q->symbol.value >= low_func && q->symbol.value <= offset)
6006 func = (asymbol *) q;
6007 low_func = q->symbol.value;
6017 *filename_ptr = filename;
6018 if (functionname_ptr)
6019 *functionname_ptr = bfd_asymbol_name (func);
6025 /* Find the nearest line to a particular section and offset, for error
6026 reporting. This code is a duplicate of the code in elf.c, except
6027 that it uses aarch64_elf_find_function. */
6030 elfNN_aarch64_find_nearest_line (bfd *abfd,
6034 const char **filename_ptr,
6035 const char **functionname_ptr,
6036 unsigned int *line_ptr,
6037 unsigned int *discriminator_ptr)
6039 bfd_boolean found = FALSE;
6041 if (_bfd_dwarf2_find_nearest_line (abfd, symbols, NULL, section, offset,
6042 filename_ptr, functionname_ptr,
6043 line_ptr, discriminator_ptr,
6044 dwarf_debug_sections, 0,
6045 &elf_tdata (abfd)->dwarf2_find_line_info))
6047 if (!*functionname_ptr)
6048 aarch64_elf_find_function (abfd, symbols, section, offset,
6049 *filename_ptr ? NULL : filename_ptr,
6055 /* Skip _bfd_dwarf1_find_nearest_line since no known AArch64
6056 toolchain uses DWARF1. */
6058 if (!_bfd_stab_section_find_nearest_line (abfd, symbols, section, offset,
6059 &found, filename_ptr,
6060 functionname_ptr, line_ptr,
6061 &elf_tdata (abfd)->line_info))
6064 if (found && (*functionname_ptr || *line_ptr))
6067 if (symbols == NULL)
6070 if (!aarch64_elf_find_function (abfd, symbols, section, offset,
6071 filename_ptr, functionname_ptr))
6079 elfNN_aarch64_find_inliner_info (bfd *abfd,
6080 const char **filename_ptr,
6081 const char **functionname_ptr,
6082 unsigned int *line_ptr)
6085 found = _bfd_dwarf2_find_inliner_info
6086 (abfd, filename_ptr,
6087 functionname_ptr, line_ptr, &elf_tdata (abfd)->dwarf2_find_line_info);
6093 elfNN_aarch64_post_process_headers (bfd *abfd,
6094 struct bfd_link_info *link_info)
6096 Elf_Internal_Ehdr *i_ehdrp; /* ELF file header, internal form. */
6098 i_ehdrp = elf_elfheader (abfd);
6099 i_ehdrp->e_ident[EI_ABIVERSION] = AARCH64_ELF_ABI_VERSION;
6101 _bfd_elf_post_process_headers (abfd, link_info);
6104 static enum elf_reloc_type_class
6105 elfNN_aarch64_reloc_type_class (const struct bfd_link_info *info ATTRIBUTE_UNUSED,
6106 const asection *rel_sec ATTRIBUTE_UNUSED,
6107 const Elf_Internal_Rela *rela)
6109 switch ((int) ELFNN_R_TYPE (rela->r_info))
6111 case AARCH64_R (RELATIVE):
6112 return reloc_class_relative;
6113 case AARCH64_R (JUMP_SLOT):
6114 return reloc_class_plt;
6115 case AARCH64_R (COPY):
6116 return reloc_class_copy;
6118 return reloc_class_normal;
6122 /* Handle an AArch64 specific section when reading an object file. This is
6123 called when bfd_section_from_shdr finds a section with an unknown
6127 elfNN_aarch64_section_from_shdr (bfd *abfd,
6128 Elf_Internal_Shdr *hdr,
6129 const char *name, int shindex)
6131 /* There ought to be a place to keep ELF backend specific flags, but
6132 at the moment there isn't one. We just keep track of the
6133 sections by their name, instead. Fortunately, the ABI gives
6134 names for all the AArch64 specific sections, so we will probably get
6136 switch (hdr->sh_type)
6138 case SHT_AARCH64_ATTRIBUTES:
6145 if (!_bfd_elf_make_section_from_shdr (abfd, hdr, name, shindex))
6151 /* A structure used to record a list of sections, independently
6152 of the next and prev fields in the asection structure. */
6153 typedef struct section_list
6156 struct section_list *next;
6157 struct section_list *prev;
6161 /* Unfortunately we need to keep a list of sections for which
6162 an _aarch64_elf_section_data structure has been allocated. This
6163 is because it is possible for functions like elfNN_aarch64_write_section
6164 to be called on a section which has had an elf_data_structure
6165 allocated for it (and so the used_by_bfd field is valid) but
6166 for which the AArch64 extended version of this structure - the
6167 _aarch64_elf_section_data structure - has not been allocated. */
6168 static section_list *sections_with_aarch64_elf_section_data = NULL;
6171 record_section_with_aarch64_elf_section_data (asection *sec)
6173 struct section_list *entry;
6175 entry = bfd_malloc (sizeof (*entry));
6179 entry->next = sections_with_aarch64_elf_section_data;
6181 if (entry->next != NULL)
6182 entry->next->prev = entry;
6183 sections_with_aarch64_elf_section_data = entry;
6186 static struct section_list *
6187 find_aarch64_elf_section_entry (asection *sec)
6189 struct section_list *entry;
6190 static struct section_list *last_entry = NULL;
6192 /* This is a short cut for the typical case where the sections are added
6193 to the sections_with_aarch64_elf_section_data list in forward order and
6194 then looked up here in backwards order. This makes a real difference
6195 to the ld-srec/sec64k.exp linker test. */
6196 entry = sections_with_aarch64_elf_section_data;
6197 if (last_entry != NULL)
6199 if (last_entry->sec == sec)
6201 else if (last_entry->next != NULL && last_entry->next->sec == sec)
6202 entry = last_entry->next;
6205 for (; entry; entry = entry->next)
6206 if (entry->sec == sec)
6210 /* Record the entry prior to this one - it is the entry we are
6211 most likely to want to locate next time. Also this way if we
6212 have been called from
6213 unrecord_section_with_aarch64_elf_section_data () we will not
6214 be caching a pointer that is about to be freed. */
6215 last_entry = entry->prev;
6221 unrecord_section_with_aarch64_elf_section_data (asection *sec)
6223 struct section_list *entry;
6225 entry = find_aarch64_elf_section_entry (sec);
6229 if (entry->prev != NULL)
6230 entry->prev->next = entry->next;
6231 if (entry->next != NULL)
6232 entry->next->prev = entry->prev;
6233 if (entry == sections_with_aarch64_elf_section_data)
6234 sections_with_aarch64_elf_section_data = entry->next;
6243 struct bfd_link_info *info;
6246 int (*func) (void *, const char *, Elf_Internal_Sym *,
6247 asection *, struct elf_link_hash_entry *);
6248 } output_arch_syminfo;
6250 enum map_symbol_type
6257 /* Output a single mapping symbol. */
6260 elfNN_aarch64_output_map_sym (output_arch_syminfo *osi,
6261 enum map_symbol_type type, bfd_vma offset)
6263 static const char *names[2] = { "$x", "$d" };
6264 Elf_Internal_Sym sym;
6266 sym.st_value = (osi->sec->output_section->vma
6267 + osi->sec->output_offset + offset);
6270 sym.st_info = ELF_ST_INFO (STB_LOCAL, STT_NOTYPE);
6271 sym.st_shndx = osi->sec_shndx;
6272 return osi->func (osi->finfo, names[type], &sym, osi->sec, NULL) == 1;
6277 /* Output mapping symbols for PLT entries associated with H. */
6280 elfNN_aarch64_output_plt_map (struct elf_link_hash_entry *h, void *inf)
6282 output_arch_syminfo *osi = (output_arch_syminfo *) inf;
6285 if (h->root.type == bfd_link_hash_indirect)
6288 if (h->root.type == bfd_link_hash_warning)
6289 /* When warning symbols are created, they **replace** the "real"
6290 entry in the hash table, thus we never get to see the real
6291 symbol in a hash traversal. So look at it now. */
6292 h = (struct elf_link_hash_entry *) h->root.u.i.link;
6294 if (h->plt.offset == (bfd_vma) - 1)
6297 addr = h->plt.offset;
6300 if (!elfNN_aarch64_output_map_sym (osi, AARCH64_MAP_INSN, addr))
6307 /* Output a single local symbol for a generated stub. */
6310 elfNN_aarch64_output_stub_sym (output_arch_syminfo *osi, const char *name,
6311 bfd_vma offset, bfd_vma size)
6313 Elf_Internal_Sym sym;
6315 sym.st_value = (osi->sec->output_section->vma
6316 + osi->sec->output_offset + offset);
6319 sym.st_info = ELF_ST_INFO (STB_LOCAL, STT_FUNC);
6320 sym.st_shndx = osi->sec_shndx;
6321 return osi->func (osi->finfo, name, &sym, osi->sec, NULL) == 1;
6325 aarch64_map_one_stub (struct bfd_hash_entry *gen_entry, void *in_arg)
6327 struct elf_aarch64_stub_hash_entry *stub_entry;
6331 output_arch_syminfo *osi;
6333 /* Massage our args to the form they really have. */
6334 stub_entry = (struct elf_aarch64_stub_hash_entry *) gen_entry;
6335 osi = (output_arch_syminfo *) in_arg;
6337 stub_sec = stub_entry->stub_sec;
6339 /* Ensure this stub is attached to the current section being
6341 if (stub_sec != osi->sec)
6344 addr = (bfd_vma) stub_entry->stub_offset;
6346 stub_name = stub_entry->output_name;
6348 switch (stub_entry->stub_type)
6350 case aarch64_stub_adrp_branch:
6351 if (!elfNN_aarch64_output_stub_sym (osi, stub_name, addr,
6352 sizeof (aarch64_adrp_branch_stub)))
6354 if (!elfNN_aarch64_output_map_sym (osi, AARCH64_MAP_INSN, addr))
6357 case aarch64_stub_long_branch:
6358 if (!elfNN_aarch64_output_stub_sym
6359 (osi, stub_name, addr, sizeof (aarch64_long_branch_stub)))
6361 if (!elfNN_aarch64_output_map_sym (osi, AARCH64_MAP_INSN, addr))
6363 if (!elfNN_aarch64_output_map_sym (osi, AARCH64_MAP_DATA, addr + 16))
6366 case aarch64_stub_erratum_835769_veneer:
6367 if (!elfNN_aarch64_output_stub_sym (osi, stub_name, addr,
6368 sizeof (aarch64_erratum_835769_stub)))
6370 if (!elfNN_aarch64_output_map_sym (osi, AARCH64_MAP_INSN, addr))
6380 /* Output mapping symbols for linker generated sections. */
6383 elfNN_aarch64_output_arch_local_syms (bfd *output_bfd,
6384 struct bfd_link_info *info,
6386 int (*func) (void *, const char *,
6389 struct elf_link_hash_entry
6392 output_arch_syminfo osi;
6393 struct elf_aarch64_link_hash_table *htab;
6395 htab = elf_aarch64_hash_table (info);
6401 /* Long calls stubs. */
6402 if (htab->stub_bfd && htab->stub_bfd->sections)
6406 for (stub_sec = htab->stub_bfd->sections;
6407 stub_sec != NULL; stub_sec = stub_sec->next)
6409 /* Ignore non-stub sections. */
6410 if (!strstr (stub_sec->name, STUB_SUFFIX))
6415 osi.sec_shndx = _bfd_elf_section_from_bfd_section
6416 (output_bfd, osi.sec->output_section);
6418 bfd_hash_traverse (&htab->stub_hash_table, aarch64_map_one_stub,
6423 /* Finally, output mapping symbols for the PLT. */
6424 if (!htab->root.splt || htab->root.splt->size == 0)
6427 /* For now live without mapping symbols for the plt. */
6428 osi.sec_shndx = _bfd_elf_section_from_bfd_section
6429 (output_bfd, htab->root.splt->output_section);
6430 osi.sec = htab->root.splt;
6432 elf_link_hash_traverse (&htab->root, elfNN_aarch64_output_plt_map,
6439 /* Allocate target specific section data. */
6442 elfNN_aarch64_new_section_hook (bfd *abfd, asection *sec)
6444 if (!sec->used_by_bfd)
6446 _aarch64_elf_section_data *sdata;
6447 bfd_size_type amt = sizeof (*sdata);
6449 sdata = bfd_zalloc (abfd, amt);
6452 sec->used_by_bfd = sdata;
6455 record_section_with_aarch64_elf_section_data (sec);
6457 return _bfd_elf_new_section_hook (abfd, sec);
6462 unrecord_section_via_map_over_sections (bfd *abfd ATTRIBUTE_UNUSED,
6464 void *ignore ATTRIBUTE_UNUSED)
6466 unrecord_section_with_aarch64_elf_section_data (sec);
6470 elfNN_aarch64_close_and_cleanup (bfd *abfd)
6473 bfd_map_over_sections (abfd,
6474 unrecord_section_via_map_over_sections, NULL);
6476 return _bfd_elf_close_and_cleanup (abfd);
6480 elfNN_aarch64_bfd_free_cached_info (bfd *abfd)
6483 bfd_map_over_sections (abfd,
6484 unrecord_section_via_map_over_sections, NULL);
6486 return _bfd_free_cached_info (abfd);
6489 /* Create dynamic sections. This is different from the ARM backend in that
6490 the got, plt, gotplt and their relocation sections are all created in the
6491 standard part of the bfd elf backend. */
6494 elfNN_aarch64_create_dynamic_sections (bfd *dynobj,
6495 struct bfd_link_info *info)
6497 struct elf_aarch64_link_hash_table *htab;
6499 /* We need to create .got section. */
6500 if (!aarch64_elf_create_got_section (dynobj, info))
6503 if (!_bfd_elf_create_dynamic_sections (dynobj, info))
6506 htab = elf_aarch64_hash_table (info);
6507 htab->sdynbss = bfd_get_linker_section (dynobj, ".dynbss");
6509 htab->srelbss = bfd_get_linker_section (dynobj, ".rela.bss");
6511 if (!htab->sdynbss || (!info->shared && !htab->srelbss))
6518 /* Allocate space in .plt, .got and associated reloc sections for
6522 elfNN_aarch64_allocate_dynrelocs (struct elf_link_hash_entry *h, void *inf)
6524 struct bfd_link_info *info;
6525 struct elf_aarch64_link_hash_table *htab;
6526 struct elf_aarch64_link_hash_entry *eh;
6527 struct elf_dyn_relocs *p;
6529 /* An example of a bfd_link_hash_indirect symbol is versioned
6530 symbol. For example: __gxx_personality_v0(bfd_link_hash_indirect)
6531 -> __gxx_personality_v0(bfd_link_hash_defined)
6533 There is no need to process bfd_link_hash_indirect symbols here
6534 because we will also be presented with the concrete instance of
6535 the symbol and elfNN_aarch64_copy_indirect_symbol () will have been
6536 called to copy all relevant data from the generic to the concrete
6539 if (h->root.type == bfd_link_hash_indirect)
6542 if (h->root.type == bfd_link_hash_warning)
6543 h = (struct elf_link_hash_entry *) h->root.u.i.link;
6545 info = (struct bfd_link_info *) inf;
6546 htab = elf_aarch64_hash_table (info);
6548 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle it
6549 here if it is defined and referenced in a non-shared object. */
6550 if (h->type == STT_GNU_IFUNC
6553 else if (htab->root.dynamic_sections_created && h->plt.refcount > 0)
6555 /* Make sure this symbol is output as a dynamic symbol.
6556 Undefined weak syms won't yet be marked as dynamic. */
6557 if (h->dynindx == -1 && !h->forced_local)
6559 if (!bfd_elf_link_record_dynamic_symbol (info, h))
6563 if (info->shared || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h))
6565 asection *s = htab->root.splt;
6567 /* If this is the first .plt entry, make room for the special
6570 s->size += htab->plt_header_size;
6572 h->plt.offset = s->size;
6574 /* If this symbol is not defined in a regular file, and we are
6575 not generating a shared library, then set the symbol to this
6576 location in the .plt. This is required to make function
6577 pointers compare as equal between the normal executable and
6578 the shared library. */
6579 if (!info->shared && !h->def_regular)
6581 h->root.u.def.section = s;
6582 h->root.u.def.value = h->plt.offset;
6585 /* Make room for this entry. For now we only create the
6586 small model PLT entries. We later need to find a way
6587 of relaxing into these from the large model PLT entries. */
6588 s->size += PLT_SMALL_ENTRY_SIZE;
6590 /* We also need to make an entry in the .got.plt section, which
6591 will be placed in the .got section by the linker script. */
6592 htab->root.sgotplt->size += GOT_ENTRY_SIZE;
6594 /* We also need to make an entry in the .rela.plt section. */
6595 htab->root.srelplt->size += RELOC_SIZE (htab);
6597 /* We need to ensure that all GOT entries that serve the PLT
6598 are consecutive with the special GOT slots [0] [1] and
6599 [2]. Any addtional relocations, such as
6600 R_AARCH64_TLSDESC, must be placed after the PLT related
6601 entries. We abuse the reloc_count such that during
6602 sizing we adjust reloc_count to indicate the number of
6603 PLT related reserved entries. In subsequent phases when
6604 filling in the contents of the reloc entries, PLT related
6605 entries are placed by computing their PLT index (0
6606 .. reloc_count). While other none PLT relocs are placed
6607 at the slot indicated by reloc_count and reloc_count is
6610 htab->root.srelplt->reloc_count++;
6614 h->plt.offset = (bfd_vma) - 1;
6620 h->plt.offset = (bfd_vma) - 1;
6624 eh = (struct elf_aarch64_link_hash_entry *) h;
6625 eh->tlsdesc_got_jump_table_offset = (bfd_vma) - 1;
6627 if (h->got.refcount > 0)
6630 unsigned got_type = elf_aarch64_hash_entry (h)->got_type;
6632 h->got.offset = (bfd_vma) - 1;
6634 dyn = htab->root.dynamic_sections_created;
6636 /* Make sure this symbol is output as a dynamic symbol.
6637 Undefined weak syms won't yet be marked as dynamic. */
6638 if (dyn && h->dynindx == -1 && !h->forced_local)
6640 if (!bfd_elf_link_record_dynamic_symbol (info, h))
6644 if (got_type == GOT_UNKNOWN)
6647 else if (got_type == GOT_NORMAL)
6649 h->got.offset = htab->root.sgot->size;
6650 htab->root.sgot->size += GOT_ENTRY_SIZE;
6651 if ((ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
6652 || h->root.type != bfd_link_hash_undefweak)
6654 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, 0, h)))
6656 htab->root.srelgot->size += RELOC_SIZE (htab);
6662 if (got_type & GOT_TLSDESC_GD)
6664 eh->tlsdesc_got_jump_table_offset =
6665 (htab->root.sgotplt->size
6666 - aarch64_compute_jump_table_size (htab));
6667 htab->root.sgotplt->size += GOT_ENTRY_SIZE * 2;
6668 h->got.offset = (bfd_vma) - 2;
6671 if (got_type & GOT_TLS_GD)
6673 h->got.offset = htab->root.sgot->size;
6674 htab->root.sgot->size += GOT_ENTRY_SIZE * 2;
6677 if (got_type & GOT_TLS_IE)
6679 h->got.offset = htab->root.sgot->size;
6680 htab->root.sgot->size += GOT_ENTRY_SIZE;
6683 indx = h && h->dynindx != -1 ? h->dynindx : 0;
6684 if ((ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
6685 || h->root.type != bfd_link_hash_undefweak)
6688 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, 0, h)))
6690 if (got_type & GOT_TLSDESC_GD)
6692 htab->root.srelplt->size += RELOC_SIZE (htab);
6693 /* Note reloc_count not incremented here! We have
6694 already adjusted reloc_count for this relocation
6697 /* TLSDESC PLT is now needed, but not yet determined. */
6698 htab->tlsdesc_plt = (bfd_vma) - 1;
6701 if (got_type & GOT_TLS_GD)
6702 htab->root.srelgot->size += RELOC_SIZE (htab) * 2;
6704 if (got_type & GOT_TLS_IE)
6705 htab->root.srelgot->size += RELOC_SIZE (htab);
6711 h->got.offset = (bfd_vma) - 1;
6714 if (eh->dyn_relocs == NULL)
6717 /* In the shared -Bsymbolic case, discard space allocated for
6718 dynamic pc-relative relocs against symbols which turn out to be
6719 defined in regular objects. For the normal shared case, discard
6720 space for pc-relative relocs that have become local due to symbol
6721 visibility changes. */
6725 /* Relocs that use pc_count are those that appear on a call
6726 insn, or certain REL relocs that can generated via assembly.
6727 We want calls to protected symbols to resolve directly to the
6728 function rather than going via the plt. If people want
6729 function pointer comparisons to work as expected then they
6730 should avoid writing weird assembly. */
6731 if (SYMBOL_CALLS_LOCAL (info, h))
6733 struct elf_dyn_relocs **pp;
6735 for (pp = &eh->dyn_relocs; (p = *pp) != NULL;)
6737 p->count -= p->pc_count;
6746 /* Also discard relocs on undefined weak syms with non-default
6748 if (eh->dyn_relocs != NULL && h->root.type == bfd_link_hash_undefweak)
6750 if (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT)
6751 eh->dyn_relocs = NULL;
6753 /* Make sure undefined weak symbols are output as a dynamic
6755 else if (h->dynindx == -1
6757 && !bfd_elf_link_record_dynamic_symbol (info, h))
6762 else if (ELIMINATE_COPY_RELOCS)
6764 /* For the non-shared case, discard space for relocs against
6765 symbols which turn out to need copy relocs or are not
6771 || (htab->root.dynamic_sections_created
6772 && (h->root.type == bfd_link_hash_undefweak
6773 || h->root.type == bfd_link_hash_undefined))))
6775 /* Make sure this symbol is output as a dynamic symbol.
6776 Undefined weak syms won't yet be marked as dynamic. */
6777 if (h->dynindx == -1
6779 && !bfd_elf_link_record_dynamic_symbol (info, h))
6782 /* If that succeeded, we know we'll be keeping all the
6784 if (h->dynindx != -1)
6788 eh->dyn_relocs = NULL;
6793 /* Finally, allocate space. */
6794 for (p = eh->dyn_relocs; p != NULL; p = p->next)
6798 sreloc = elf_section_data (p->sec)->sreloc;
6800 BFD_ASSERT (sreloc != NULL);
6802 sreloc->size += p->count * RELOC_SIZE (htab);
6808 /* Allocate space in .plt, .got and associated reloc sections for
6809 ifunc dynamic relocs. */
6812 elfNN_aarch64_allocate_ifunc_dynrelocs (struct elf_link_hash_entry *h,
6815 struct bfd_link_info *info;
6816 struct elf_aarch64_link_hash_table *htab;
6817 struct elf_aarch64_link_hash_entry *eh;
6819 /* An example of a bfd_link_hash_indirect symbol is versioned
6820 symbol. For example: __gxx_personality_v0(bfd_link_hash_indirect)
6821 -> __gxx_personality_v0(bfd_link_hash_defined)
6823 There is no need to process bfd_link_hash_indirect symbols here
6824 because we will also be presented with the concrete instance of
6825 the symbol and elfNN_aarch64_copy_indirect_symbol () will have been
6826 called to copy all relevant data from the generic to the concrete
6829 if (h->root.type == bfd_link_hash_indirect)
6832 if (h->root.type == bfd_link_hash_warning)
6833 h = (struct elf_link_hash_entry *) h->root.u.i.link;
6835 info = (struct bfd_link_info *) inf;
6836 htab = elf_aarch64_hash_table (info);
6838 eh = (struct elf_aarch64_link_hash_entry *) h;
6840 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle it
6841 here if it is defined and referenced in a non-shared object. */
6842 if (h->type == STT_GNU_IFUNC
6844 return _bfd_elf_allocate_ifunc_dyn_relocs (info, h,
6846 htab->plt_entry_size,
6847 htab->plt_header_size,
6852 /* Allocate space in .plt, .got and associated reloc sections for
6853 local dynamic relocs. */
6856 elfNN_aarch64_allocate_local_dynrelocs (void **slot, void *inf)
6858 struct elf_link_hash_entry *h
6859 = (struct elf_link_hash_entry *) *slot;
6861 if (h->type != STT_GNU_IFUNC
6865 || h->root.type != bfd_link_hash_defined)
6868 return elfNN_aarch64_allocate_dynrelocs (h, inf);
6871 /* Allocate space in .plt, .got and associated reloc sections for
6872 local ifunc dynamic relocs. */
6875 elfNN_aarch64_allocate_local_ifunc_dynrelocs (void **slot, void *inf)
6877 struct elf_link_hash_entry *h
6878 = (struct elf_link_hash_entry *) *slot;
6880 if (h->type != STT_GNU_IFUNC
6884 || h->root.type != bfd_link_hash_defined)
6887 return elfNN_aarch64_allocate_ifunc_dynrelocs (h, inf);
6890 /* This is the most important function of all . Innocuosly named
6893 elfNN_aarch64_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
6894 struct bfd_link_info *info)
6896 struct elf_aarch64_link_hash_table *htab;
6902 htab = elf_aarch64_hash_table ((info));
6903 dynobj = htab->root.dynobj;
6905 BFD_ASSERT (dynobj != NULL);
6907 if (htab->root.dynamic_sections_created)
6909 if (info->executable)
6911 s = bfd_get_linker_section (dynobj, ".interp");
6914 s->size = sizeof ELF_DYNAMIC_INTERPRETER;
6915 s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
6919 /* Set up .got offsets for local syms, and space for local dynamic
6921 for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link.next)
6923 struct elf_aarch64_local_symbol *locals = NULL;
6924 Elf_Internal_Shdr *symtab_hdr;
6928 if (!is_aarch64_elf (ibfd))
6931 for (s = ibfd->sections; s != NULL; s = s->next)
6933 struct elf_dyn_relocs *p;
6935 for (p = (struct elf_dyn_relocs *)
6936 (elf_section_data (s)->local_dynrel); p != NULL; p = p->next)
6938 if (!bfd_is_abs_section (p->sec)
6939 && bfd_is_abs_section (p->sec->output_section))
6941 /* Input section has been discarded, either because
6942 it is a copy of a linkonce section or due to
6943 linker script /DISCARD/, so we'll be discarding
6946 else if (p->count != 0)
6948 srel = elf_section_data (p->sec)->sreloc;
6949 srel->size += p->count * RELOC_SIZE (htab);
6950 if ((p->sec->output_section->flags & SEC_READONLY) != 0)
6951 info->flags |= DF_TEXTREL;
6956 locals = elf_aarch64_locals (ibfd);
6960 symtab_hdr = &elf_symtab_hdr (ibfd);
6961 srel = htab->root.srelgot;
6962 for (i = 0; i < symtab_hdr->sh_info; i++)
6964 locals[i].got_offset = (bfd_vma) - 1;
6965 locals[i].tlsdesc_got_jump_table_offset = (bfd_vma) - 1;
6966 if (locals[i].got_refcount > 0)
6968 unsigned got_type = locals[i].got_type;
6969 if (got_type & GOT_TLSDESC_GD)
6971 locals[i].tlsdesc_got_jump_table_offset =
6972 (htab->root.sgotplt->size
6973 - aarch64_compute_jump_table_size (htab));
6974 htab->root.sgotplt->size += GOT_ENTRY_SIZE * 2;
6975 locals[i].got_offset = (bfd_vma) - 2;
6978 if (got_type & GOT_TLS_GD)
6980 locals[i].got_offset = htab->root.sgot->size;
6981 htab->root.sgot->size += GOT_ENTRY_SIZE * 2;
6984 if (got_type & GOT_TLS_IE)
6986 locals[i].got_offset = htab->root.sgot->size;
6987 htab->root.sgot->size += GOT_ENTRY_SIZE;
6990 if (got_type == GOT_UNKNOWN)
6994 if (got_type == GOT_NORMAL)
7000 if (got_type & GOT_TLSDESC_GD)
7002 htab->root.srelplt->size += RELOC_SIZE (htab);
7003 /* Note RELOC_COUNT not incremented here! */
7004 htab->tlsdesc_plt = (bfd_vma) - 1;
7007 if (got_type & GOT_TLS_GD)
7008 htab->root.srelgot->size += RELOC_SIZE (htab) * 2;
7010 if (got_type & GOT_TLS_IE)
7011 htab->root.srelgot->size += RELOC_SIZE (htab);
7016 locals[i].got_refcount = (bfd_vma) - 1;
7022 /* Allocate global sym .plt and .got entries, and space for global
7023 sym dynamic relocs. */
7024 elf_link_hash_traverse (&htab->root, elfNN_aarch64_allocate_dynrelocs,
7027 /* Allocate global ifunc sym .plt and .got entries, and space for global
7028 ifunc sym dynamic relocs. */
7029 elf_link_hash_traverse (&htab->root, elfNN_aarch64_allocate_ifunc_dynrelocs,
7032 /* Allocate .plt and .got entries, and space for local symbols. */
7033 htab_traverse (htab->loc_hash_table,
7034 elfNN_aarch64_allocate_local_dynrelocs,
7037 /* Allocate .plt and .got entries, and space for local ifunc symbols. */
7038 htab_traverse (htab->loc_hash_table,
7039 elfNN_aarch64_allocate_local_ifunc_dynrelocs,
7042 /* For every jump slot reserved in the sgotplt, reloc_count is
7043 incremented. However, when we reserve space for TLS descriptors,
7044 it's not incremented, so in order to compute the space reserved
7045 for them, it suffices to multiply the reloc count by the jump
7048 if (htab->root.srelplt)
7049 htab->sgotplt_jump_table_size = aarch64_compute_jump_table_size (htab);
7051 if (htab->tlsdesc_plt)
7053 if (htab->root.splt->size == 0)
7054 htab->root.splt->size += PLT_ENTRY_SIZE;
7056 htab->tlsdesc_plt = htab->root.splt->size;
7057 htab->root.splt->size += PLT_TLSDESC_ENTRY_SIZE;
7059 /* If we're not using lazy TLS relocations, don't generate the
7060 GOT entry required. */
7061 if (!(info->flags & DF_BIND_NOW))
7063 htab->dt_tlsdesc_got = htab->root.sgot->size;
7064 htab->root.sgot->size += GOT_ENTRY_SIZE;
7068 /* Init mapping symbols information to use later to distingush between
7069 code and data while scanning for erratam 835769. */
7070 if (htab->fix_erratum_835769)
7071 for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link.next)
7073 if (!is_aarch64_elf (ibfd))
7075 bfd_elfNN_aarch64_init_maps (ibfd);
7078 /* We now have determined the sizes of the various dynamic sections.
7079 Allocate memory for them. */
7081 for (s = dynobj->sections; s != NULL; s = s->next)
7083 if ((s->flags & SEC_LINKER_CREATED) == 0)
7086 if (s == htab->root.splt
7087 || s == htab->root.sgot
7088 || s == htab->root.sgotplt
7089 || s == htab->root.iplt
7090 || s == htab->root.igotplt || s == htab->sdynbss)
7092 /* Strip this section if we don't need it; see the
7095 else if (CONST_STRNEQ (bfd_get_section_name (dynobj, s), ".rela"))
7097 if (s->size != 0 && s != htab->root.srelplt)
7100 /* We use the reloc_count field as a counter if we need
7101 to copy relocs into the output file. */
7102 if (s != htab->root.srelplt)
7107 /* It's not one of our sections, so don't allocate space. */
7113 /* If we don't need this section, strip it from the
7114 output file. This is mostly to handle .rela.bss and
7115 .rela.plt. We must create both sections in
7116 create_dynamic_sections, because they must be created
7117 before the linker maps input sections to output
7118 sections. The linker does that before
7119 adjust_dynamic_symbol is called, and it is that
7120 function which decides whether anything needs to go
7121 into these sections. */
7123 s->flags |= SEC_EXCLUDE;
7127 if ((s->flags & SEC_HAS_CONTENTS) == 0)
7130 /* Allocate memory for the section contents. We use bfd_zalloc
7131 here in case unused entries are not reclaimed before the
7132 section's contents are written out. This should not happen,
7133 but this way if it does, we get a R_AARCH64_NONE reloc instead
7135 s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->size);
7136 if (s->contents == NULL)
7140 if (htab->root.dynamic_sections_created)
7142 /* Add some entries to the .dynamic section. We fill in the
7143 values later, in elfNN_aarch64_finish_dynamic_sections, but we
7144 must add the entries now so that we get the correct size for
7145 the .dynamic section. The DT_DEBUG entry is filled in by the
7146 dynamic linker and used by the debugger. */
7147 #define add_dynamic_entry(TAG, VAL) \
7148 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
7150 if (info->executable)
7152 if (!add_dynamic_entry (DT_DEBUG, 0))
7156 if (htab->root.splt->size != 0)
7158 if (!add_dynamic_entry (DT_PLTGOT, 0)
7159 || !add_dynamic_entry (DT_PLTRELSZ, 0)
7160 || !add_dynamic_entry (DT_PLTREL, DT_RELA)
7161 || !add_dynamic_entry (DT_JMPREL, 0))
7164 if (htab->tlsdesc_plt
7165 && (!add_dynamic_entry (DT_TLSDESC_PLT, 0)
7166 || !add_dynamic_entry (DT_TLSDESC_GOT, 0)))
7172 if (!add_dynamic_entry (DT_RELA, 0)
7173 || !add_dynamic_entry (DT_RELASZ, 0)
7174 || !add_dynamic_entry (DT_RELAENT, RELOC_SIZE (htab)))
7177 /* If any dynamic relocs apply to a read-only section,
7178 then we need a DT_TEXTREL entry. */
7179 if ((info->flags & DF_TEXTREL) != 0)
7181 if (!add_dynamic_entry (DT_TEXTREL, 0))
7186 #undef add_dynamic_entry
7192 elf_aarch64_update_plt_entry (bfd *output_bfd,
7193 bfd_reloc_code_real_type r_type,
7194 bfd_byte *plt_entry, bfd_vma value)
7196 reloc_howto_type *howto = elfNN_aarch64_howto_from_bfd_reloc (r_type);
7198 _bfd_aarch64_elf_put_addend (output_bfd, plt_entry, r_type, howto, value);
7202 elfNN_aarch64_create_small_pltn_entry (struct elf_link_hash_entry *h,
7203 struct elf_aarch64_link_hash_table
7204 *htab, bfd *output_bfd,
7205 struct bfd_link_info *info)
7207 bfd_byte *plt_entry;
7210 bfd_vma gotplt_entry_address;
7211 bfd_vma plt_entry_address;
7212 Elf_Internal_Rela rela;
7214 asection *plt, *gotplt, *relplt;
7216 /* When building a static executable, use .iplt, .igot.plt and
7217 .rela.iplt sections for STT_GNU_IFUNC symbols. */
7218 if (htab->root.splt != NULL)
7220 plt = htab->root.splt;
7221 gotplt = htab->root.sgotplt;
7222 relplt = htab->root.srelplt;
7226 plt = htab->root.iplt;
7227 gotplt = htab->root.igotplt;
7228 relplt = htab->root.irelplt;
7231 /* Get the index in the procedure linkage table which
7232 corresponds to this symbol. This is the index of this symbol
7233 in all the symbols for which we are making plt entries. The
7234 first entry in the procedure linkage table is reserved.
7236 Get the offset into the .got table of the entry that
7237 corresponds to this function. Each .got entry is GOT_ENTRY_SIZE
7238 bytes. The first three are reserved for the dynamic linker.
7240 For static executables, we don't reserve anything. */
7242 if (plt == htab->root.splt)
7244 plt_index = (h->plt.offset - htab->plt_header_size) / htab->plt_entry_size;
7245 got_offset = (plt_index + 3) * GOT_ENTRY_SIZE;
7249 plt_index = h->plt.offset / htab->plt_entry_size;
7250 got_offset = plt_index * GOT_ENTRY_SIZE;
7253 plt_entry = plt->contents + h->plt.offset;
7254 plt_entry_address = plt->output_section->vma
7255 + plt->output_offset + h->plt.offset;
7256 gotplt_entry_address = gotplt->output_section->vma +
7257 gotplt->output_offset + got_offset;
7259 /* Copy in the boiler-plate for the PLTn entry. */
7260 memcpy (plt_entry, elfNN_aarch64_small_plt_entry, PLT_SMALL_ENTRY_SIZE);
7262 /* Fill in the top 21 bits for this: ADRP x16, PLT_GOT + n * 8.
7263 ADRP: ((PG(S+A)-PG(P)) >> 12) & 0x1fffff */
7264 elf_aarch64_update_plt_entry (output_bfd, BFD_RELOC_AARCH64_ADR_HI21_PCREL,
7266 PG (gotplt_entry_address) -
7267 PG (plt_entry_address));
7269 /* Fill in the lo12 bits for the load from the pltgot. */
7270 elf_aarch64_update_plt_entry (output_bfd, BFD_RELOC_AARCH64_LDSTNN_LO12,
7272 PG_OFFSET (gotplt_entry_address));
7274 /* Fill in the lo12 bits for the add from the pltgot entry. */
7275 elf_aarch64_update_plt_entry (output_bfd, BFD_RELOC_AARCH64_ADD_LO12,
7277 PG_OFFSET (gotplt_entry_address));
7279 /* All the GOTPLT Entries are essentially initialized to PLT0. */
7280 bfd_put_NN (output_bfd,
7281 plt->output_section->vma + plt->output_offset,
7282 gotplt->contents + got_offset);
7284 rela.r_offset = gotplt_entry_address;
7286 if (h->dynindx == -1
7287 || ((info->executable
7288 || ELF_ST_VISIBILITY (h->other) != STV_DEFAULT)
7290 && h->type == STT_GNU_IFUNC))
7292 /* If an STT_GNU_IFUNC symbol is locally defined, generate
7293 R_AARCH64_IRELATIVE instead of R_AARCH64_JUMP_SLOT. */
7294 rela.r_info = ELFNN_R_INFO (0, AARCH64_R (IRELATIVE));
7295 rela.r_addend = (h->root.u.def.value
7296 + h->root.u.def.section->output_section->vma
7297 + h->root.u.def.section->output_offset);
7301 /* Fill in the entry in the .rela.plt section. */
7302 rela.r_info = ELFNN_R_INFO (h->dynindx, AARCH64_R (JUMP_SLOT));
7306 /* Compute the relocation entry to used based on PLT index and do
7307 not adjust reloc_count. The reloc_count has already been adjusted
7308 to account for this entry. */
7309 loc = relplt->contents + plt_index * RELOC_SIZE (htab);
7310 bfd_elfNN_swap_reloca_out (output_bfd, &rela, loc);
7313 /* Size sections even though they're not dynamic. We use it to setup
7314 _TLS_MODULE_BASE_, if needed. */
7317 elfNN_aarch64_always_size_sections (bfd *output_bfd,
7318 struct bfd_link_info *info)
7322 if (info->relocatable)
7325 tls_sec = elf_hash_table (info)->tls_sec;
7329 struct elf_link_hash_entry *tlsbase;
7331 tlsbase = elf_link_hash_lookup (elf_hash_table (info),
7332 "_TLS_MODULE_BASE_", TRUE, TRUE, FALSE);
7336 struct bfd_link_hash_entry *h = NULL;
7337 const struct elf_backend_data *bed =
7338 get_elf_backend_data (output_bfd);
7340 if (!(_bfd_generic_link_add_one_symbol
7341 (info, output_bfd, "_TLS_MODULE_BASE_", BSF_LOCAL,
7342 tls_sec, 0, NULL, FALSE, bed->collect, &h)))
7345 tlsbase->type = STT_TLS;
7346 tlsbase = (struct elf_link_hash_entry *) h;
7347 tlsbase->def_regular = 1;
7348 tlsbase->other = STV_HIDDEN;
7349 (*bed->elf_backend_hide_symbol) (info, tlsbase, TRUE);
7356 /* Finish up dynamic symbol handling. We set the contents of various
7357 dynamic sections here. */
7359 elfNN_aarch64_finish_dynamic_symbol (bfd *output_bfd,
7360 struct bfd_link_info *info,
7361 struct elf_link_hash_entry *h,
7362 Elf_Internal_Sym *sym)
7364 struct elf_aarch64_link_hash_table *htab;
7365 htab = elf_aarch64_hash_table (info);
7367 if (h->plt.offset != (bfd_vma) - 1)
7369 asection *plt, *gotplt, *relplt;
7371 /* This symbol has an entry in the procedure linkage table. Set
7374 /* When building a static executable, use .iplt, .igot.plt and
7375 .rela.iplt sections for STT_GNU_IFUNC symbols. */
7376 if (htab->root.splt != NULL)
7378 plt = htab->root.splt;
7379 gotplt = htab->root.sgotplt;
7380 relplt = htab->root.srelplt;
7384 plt = htab->root.iplt;
7385 gotplt = htab->root.igotplt;
7386 relplt = htab->root.irelplt;
7389 /* This symbol has an entry in the procedure linkage table. Set
7391 if ((h->dynindx == -1
7392 && !((h->forced_local || info->executable)
7394 && h->type == STT_GNU_IFUNC))
7400 elfNN_aarch64_create_small_pltn_entry (h, htab, output_bfd, info);
7401 if (!h->def_regular)
7403 /* Mark the symbol as undefined, rather than as defined in
7404 the .plt section. Leave the value alone. This is a clue
7405 for the dynamic linker, to make function pointer
7406 comparisons work between an application and shared
7408 sym->st_shndx = SHN_UNDEF;
7412 if (h->got.offset != (bfd_vma) - 1
7413 && elf_aarch64_hash_entry (h)->got_type == GOT_NORMAL)
7415 Elf_Internal_Rela rela;
7418 /* This symbol has an entry in the global offset table. Set it
7420 if (htab->root.sgot == NULL || htab->root.srelgot == NULL)
7423 rela.r_offset = (htab->root.sgot->output_section->vma
7424 + htab->root.sgot->output_offset
7425 + (h->got.offset & ~(bfd_vma) 1));
7428 && h->type == STT_GNU_IFUNC)
7432 /* Generate R_AARCH64_GLOB_DAT. */
7439 if (!h->pointer_equality_needed)
7442 /* For non-shared object, we can't use .got.plt, which
7443 contains the real function address if we need pointer
7444 equality. We load the GOT entry with the PLT entry. */
7445 plt = htab->root.splt ? htab->root.splt : htab->root.iplt;
7446 bfd_put_NN (output_bfd, (plt->output_section->vma
7447 + plt->output_offset
7449 htab->root.sgot->contents
7450 + (h->got.offset & ~(bfd_vma) 1));
7454 else if (info->shared && SYMBOL_REFERENCES_LOCAL (info, h))
7456 if (!h->def_regular)
7459 BFD_ASSERT ((h->got.offset & 1) != 0);
7460 rela.r_info = ELFNN_R_INFO (0, AARCH64_R (RELATIVE));
7461 rela.r_addend = (h->root.u.def.value
7462 + h->root.u.def.section->output_section->vma
7463 + h->root.u.def.section->output_offset);
7468 BFD_ASSERT ((h->got.offset & 1) == 0);
7469 bfd_put_NN (output_bfd, (bfd_vma) 0,
7470 htab->root.sgot->contents + h->got.offset);
7471 rela.r_info = ELFNN_R_INFO (h->dynindx, AARCH64_R (GLOB_DAT));
7475 loc = htab->root.srelgot->contents;
7476 loc += htab->root.srelgot->reloc_count++ * RELOC_SIZE (htab);
7477 bfd_elfNN_swap_reloca_out (output_bfd, &rela, loc);
7482 Elf_Internal_Rela rela;
7485 /* This symbol needs a copy reloc. Set it up. */
7487 if (h->dynindx == -1
7488 || (h->root.type != bfd_link_hash_defined
7489 && h->root.type != bfd_link_hash_defweak)
7490 || htab->srelbss == NULL)
7493 rela.r_offset = (h->root.u.def.value
7494 + h->root.u.def.section->output_section->vma
7495 + h->root.u.def.section->output_offset);
7496 rela.r_info = ELFNN_R_INFO (h->dynindx, AARCH64_R (COPY));
7498 loc = htab->srelbss->contents;
7499 loc += htab->srelbss->reloc_count++ * RELOC_SIZE (htab);
7500 bfd_elfNN_swap_reloca_out (output_bfd, &rela, loc);
7503 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. SYM may
7504 be NULL for local symbols. */
7506 && (h == elf_hash_table (info)->hdynamic
7507 || h == elf_hash_table (info)->hgot))
7508 sym->st_shndx = SHN_ABS;
7513 /* Finish up local dynamic symbol handling. We set the contents of
7514 various dynamic sections here. */
7517 elfNN_aarch64_finish_local_dynamic_symbol (void **slot, void *inf)
7519 struct elf_link_hash_entry *h
7520 = (struct elf_link_hash_entry *) *slot;
7521 struct bfd_link_info *info
7522 = (struct bfd_link_info *) inf;
7524 return elfNN_aarch64_finish_dynamic_symbol (info->output_bfd,
7529 elfNN_aarch64_init_small_plt0_entry (bfd *output_bfd ATTRIBUTE_UNUSED,
7530 struct elf_aarch64_link_hash_table
7533 /* Fill in PLT0. Fixme:RR Note this doesn't distinguish between
7534 small and large plts and at the minute just generates
7537 /* PLT0 of the small PLT looks like this in ELF64 -
7538 stp x16, x30, [sp, #-16]! // Save the reloc and lr on stack.
7539 adrp x16, PLT_GOT + 16 // Get the page base of the GOTPLT
7540 ldr x17, [x16, #:lo12:PLT_GOT+16] // Load the address of the
7542 add x16, x16, #:lo12:PLT_GOT+16 // Load the lo12 bits of the
7543 // GOTPLT entry for this.
7545 PLT0 will be slightly different in ELF32 due to different got entry
7548 bfd_vma plt_got_2nd_ent; /* Address of GOT[2]. */
7552 memcpy (htab->root.splt->contents, elfNN_aarch64_small_plt0_entry,
7554 elf_section_data (htab->root.splt->output_section)->this_hdr.sh_entsize =
7557 plt_got_2nd_ent = (htab->root.sgotplt->output_section->vma
7558 + htab->root.sgotplt->output_offset
7559 + GOT_ENTRY_SIZE * 2);
7561 plt_base = htab->root.splt->output_section->vma +
7562 htab->root.splt->output_offset;
7564 /* Fill in the top 21 bits for this: ADRP x16, PLT_GOT + n * 8.
7565 ADRP: ((PG(S+A)-PG(P)) >> 12) & 0x1fffff */
7566 elf_aarch64_update_plt_entry (output_bfd, BFD_RELOC_AARCH64_ADR_HI21_PCREL,
7567 htab->root.splt->contents + 4,
7568 PG (plt_got_2nd_ent) - PG (plt_base + 4));
7570 elf_aarch64_update_plt_entry (output_bfd, BFD_RELOC_AARCH64_LDSTNN_LO12,
7571 htab->root.splt->contents + 8,
7572 PG_OFFSET (plt_got_2nd_ent));
7574 elf_aarch64_update_plt_entry (output_bfd, BFD_RELOC_AARCH64_ADD_LO12,
7575 htab->root.splt->contents + 12,
7576 PG_OFFSET (plt_got_2nd_ent));
7580 elfNN_aarch64_finish_dynamic_sections (bfd *output_bfd,
7581 struct bfd_link_info *info)
7583 struct elf_aarch64_link_hash_table *htab;
7587 htab = elf_aarch64_hash_table (info);
7588 dynobj = htab->root.dynobj;
7589 sdyn = bfd_get_linker_section (dynobj, ".dynamic");
7591 if (htab->root.dynamic_sections_created)
7593 ElfNN_External_Dyn *dyncon, *dynconend;
7595 if (sdyn == NULL || htab->root.sgot == NULL)
7598 dyncon = (ElfNN_External_Dyn *) sdyn->contents;
7599 dynconend = (ElfNN_External_Dyn *) (sdyn->contents + sdyn->size);
7600 for (; dyncon < dynconend; dyncon++)
7602 Elf_Internal_Dyn dyn;
7605 bfd_elfNN_swap_dyn_in (dynobj, dyncon, &dyn);
7613 s = htab->root.sgotplt;
7614 dyn.d_un.d_ptr = s->output_section->vma + s->output_offset;
7618 dyn.d_un.d_ptr = htab->root.srelplt->output_section->vma;
7622 s = htab->root.srelplt;
7623 dyn.d_un.d_val = s->size;
7627 /* The procedure linkage table relocs (DT_JMPREL) should
7628 not be included in the overall relocs (DT_RELA).
7629 Therefore, we override the DT_RELASZ entry here to
7630 make it not include the JMPREL relocs. Since the
7631 linker script arranges for .rela.plt to follow all
7632 other relocation sections, we don't have to worry
7633 about changing the DT_RELA entry. */
7634 if (htab->root.srelplt != NULL)
7636 s = htab->root.srelplt;
7637 dyn.d_un.d_val -= s->size;
7641 case DT_TLSDESC_PLT:
7642 s = htab->root.splt;
7643 dyn.d_un.d_ptr = s->output_section->vma + s->output_offset
7644 + htab->tlsdesc_plt;
7647 case DT_TLSDESC_GOT:
7648 s = htab->root.sgot;
7649 dyn.d_un.d_ptr = s->output_section->vma + s->output_offset
7650 + htab->dt_tlsdesc_got;
7654 bfd_elfNN_swap_dyn_out (output_bfd, &dyn, dyncon);
7659 /* Fill in the special first entry in the procedure linkage table. */
7660 if (htab->root.splt && htab->root.splt->size > 0)
7662 elfNN_aarch64_init_small_plt0_entry (output_bfd, htab);
7664 elf_section_data (htab->root.splt->output_section)->
7665 this_hdr.sh_entsize = htab->plt_entry_size;
7668 if (htab->tlsdesc_plt)
7670 bfd_put_NN (output_bfd, (bfd_vma) 0,
7671 htab->root.sgot->contents + htab->dt_tlsdesc_got);
7673 memcpy (htab->root.splt->contents + htab->tlsdesc_plt,
7674 elfNN_aarch64_tlsdesc_small_plt_entry,
7675 sizeof (elfNN_aarch64_tlsdesc_small_plt_entry));
7678 bfd_vma adrp1_addr =
7679 htab->root.splt->output_section->vma
7680 + htab->root.splt->output_offset + htab->tlsdesc_plt + 4;
7682 bfd_vma adrp2_addr = adrp1_addr + 4;
7685 htab->root.sgot->output_section->vma
7686 + htab->root.sgot->output_offset;
7688 bfd_vma pltgot_addr =
7689 htab->root.sgotplt->output_section->vma
7690 + htab->root.sgotplt->output_offset;
7692 bfd_vma dt_tlsdesc_got = got_addr + htab->dt_tlsdesc_got;
7694 bfd_byte *plt_entry =
7695 htab->root.splt->contents + htab->tlsdesc_plt;
7697 /* adrp x2, DT_TLSDESC_GOT */
7698 elf_aarch64_update_plt_entry (output_bfd,
7699 BFD_RELOC_AARCH64_ADR_HI21_PCREL,
7701 (PG (dt_tlsdesc_got)
7702 - PG (adrp1_addr)));
7705 elf_aarch64_update_plt_entry (output_bfd,
7706 BFD_RELOC_AARCH64_ADR_HI21_PCREL,
7709 - PG (adrp2_addr)));
7711 /* ldr x2, [x2, #0] */
7712 elf_aarch64_update_plt_entry (output_bfd,
7713 BFD_RELOC_AARCH64_LDSTNN_LO12,
7715 PG_OFFSET (dt_tlsdesc_got));
7718 elf_aarch64_update_plt_entry (output_bfd,
7719 BFD_RELOC_AARCH64_ADD_LO12,
7721 PG_OFFSET (pltgot_addr));
7726 if (htab->root.sgotplt)
7728 if (bfd_is_abs_section (htab->root.sgotplt->output_section))
7730 (*_bfd_error_handler)
7731 (_("discarded output section: `%A'"), htab->root.sgotplt);
7735 /* Fill in the first three entries in the global offset table. */
7736 if (htab->root.sgotplt->size > 0)
7738 bfd_put_NN (output_bfd, (bfd_vma) 0, htab->root.sgotplt->contents);
7740 /* Write GOT[1] and GOT[2], needed for the dynamic linker. */
7741 bfd_put_NN (output_bfd,
7743 htab->root.sgotplt->contents + GOT_ENTRY_SIZE);
7744 bfd_put_NN (output_bfd,
7746 htab->root.sgotplt->contents + GOT_ENTRY_SIZE * 2);
7749 if (htab->root.sgot)
7751 if (htab->root.sgot->size > 0)
7754 sdyn ? sdyn->output_section->vma + sdyn->output_offset : 0;
7755 bfd_put_NN (output_bfd, addr, htab->root.sgot->contents);
7759 elf_section_data (htab->root.sgotplt->output_section)->
7760 this_hdr.sh_entsize = GOT_ENTRY_SIZE;
7763 if (htab->root.sgot && htab->root.sgot->size > 0)
7764 elf_section_data (htab->root.sgot->output_section)->this_hdr.sh_entsize
7767 /* Fill PLT and GOT entries for local STT_GNU_IFUNC symbols. */
7768 htab_traverse (htab->loc_hash_table,
7769 elfNN_aarch64_finish_local_dynamic_symbol,
7775 /* Return address for Ith PLT stub in section PLT, for relocation REL
7776 or (bfd_vma) -1 if it should not be included. */
7779 elfNN_aarch64_plt_sym_val (bfd_vma i, const asection *plt,
7780 const arelent *rel ATTRIBUTE_UNUSED)
7782 return plt->vma + PLT_ENTRY_SIZE + i * PLT_SMALL_ENTRY_SIZE;
7786 /* We use this so we can override certain functions
7787 (though currently we don't). */
7789 const struct elf_size_info elfNN_aarch64_size_info =
7791 sizeof (ElfNN_External_Ehdr),
7792 sizeof (ElfNN_External_Phdr),
7793 sizeof (ElfNN_External_Shdr),
7794 sizeof (ElfNN_External_Rel),
7795 sizeof (ElfNN_External_Rela),
7796 sizeof (ElfNN_External_Sym),
7797 sizeof (ElfNN_External_Dyn),
7798 sizeof (Elf_External_Note),
7799 4, /* Hash table entry size. */
7800 1, /* Internal relocs per external relocs. */
7801 ARCH_SIZE, /* Arch size. */
7802 LOG_FILE_ALIGN, /* Log_file_align. */
7803 ELFCLASSNN, EV_CURRENT,
7804 bfd_elfNN_write_out_phdrs,
7805 bfd_elfNN_write_shdrs_and_ehdr,
7806 bfd_elfNN_checksum_contents,
7807 bfd_elfNN_write_relocs,
7808 bfd_elfNN_swap_symbol_in,
7809 bfd_elfNN_swap_symbol_out,
7810 bfd_elfNN_slurp_reloc_table,
7811 bfd_elfNN_slurp_symbol_table,
7812 bfd_elfNN_swap_dyn_in,
7813 bfd_elfNN_swap_dyn_out,
7814 bfd_elfNN_swap_reloc_in,
7815 bfd_elfNN_swap_reloc_out,
7816 bfd_elfNN_swap_reloca_in,
7817 bfd_elfNN_swap_reloca_out
7820 #define ELF_ARCH bfd_arch_aarch64
7821 #define ELF_MACHINE_CODE EM_AARCH64
7822 #define ELF_MAXPAGESIZE 0x10000
7823 #define ELF_MINPAGESIZE 0x1000
7824 #define ELF_COMMONPAGESIZE 0x1000
7826 #define bfd_elfNN_close_and_cleanup \
7827 elfNN_aarch64_close_and_cleanup
7829 #define bfd_elfNN_bfd_free_cached_info \
7830 elfNN_aarch64_bfd_free_cached_info
7832 #define bfd_elfNN_bfd_is_target_special_symbol \
7833 elfNN_aarch64_is_target_special_symbol
7835 #define bfd_elfNN_bfd_link_hash_table_create \
7836 elfNN_aarch64_link_hash_table_create
7838 #define bfd_elfNN_bfd_merge_private_bfd_data \
7839 elfNN_aarch64_merge_private_bfd_data
7841 #define bfd_elfNN_bfd_print_private_bfd_data \
7842 elfNN_aarch64_print_private_bfd_data
7844 #define bfd_elfNN_bfd_reloc_type_lookup \
7845 elfNN_aarch64_reloc_type_lookup
7847 #define bfd_elfNN_bfd_reloc_name_lookup \
7848 elfNN_aarch64_reloc_name_lookup
7850 #define bfd_elfNN_bfd_set_private_flags \
7851 elfNN_aarch64_set_private_flags
7853 #define bfd_elfNN_find_inliner_info \
7854 elfNN_aarch64_find_inliner_info
7856 #define bfd_elfNN_find_nearest_line \
7857 elfNN_aarch64_find_nearest_line
7859 #define bfd_elfNN_mkobject \
7860 elfNN_aarch64_mkobject
7862 #define bfd_elfNN_new_section_hook \
7863 elfNN_aarch64_new_section_hook
7865 #define elf_backend_adjust_dynamic_symbol \
7866 elfNN_aarch64_adjust_dynamic_symbol
7868 #define elf_backend_always_size_sections \
7869 elfNN_aarch64_always_size_sections
7871 #define elf_backend_check_relocs \
7872 elfNN_aarch64_check_relocs
7874 #define elf_backend_copy_indirect_symbol \
7875 elfNN_aarch64_copy_indirect_symbol
7877 /* Create .dynbss, and .rela.bss sections in DYNOBJ, and set up shortcuts
7878 to them in our hash. */
7879 #define elf_backend_create_dynamic_sections \
7880 elfNN_aarch64_create_dynamic_sections
7882 #define elf_backend_init_index_section \
7883 _bfd_elf_init_2_index_sections
7885 #define elf_backend_finish_dynamic_sections \
7886 elfNN_aarch64_finish_dynamic_sections
7888 #define elf_backend_finish_dynamic_symbol \
7889 elfNN_aarch64_finish_dynamic_symbol
7891 #define elf_backend_gc_sweep_hook \
7892 elfNN_aarch64_gc_sweep_hook
7894 #define elf_backend_object_p \
7895 elfNN_aarch64_object_p
7897 #define elf_backend_output_arch_local_syms \
7898 elfNN_aarch64_output_arch_local_syms
7900 #define elf_backend_plt_sym_val \
7901 elfNN_aarch64_plt_sym_val
7903 #define elf_backend_post_process_headers \
7904 elfNN_aarch64_post_process_headers
7906 #define elf_backend_relocate_section \
7907 elfNN_aarch64_relocate_section
7909 #define elf_backend_reloc_type_class \
7910 elfNN_aarch64_reloc_type_class
7912 #define elf_backend_section_from_shdr \
7913 elfNN_aarch64_section_from_shdr
7915 #define elf_backend_size_dynamic_sections \
7916 elfNN_aarch64_size_dynamic_sections
7918 #define elf_backend_size_info \
7919 elfNN_aarch64_size_info
7921 #define elf_backend_write_section \
7922 elfNN_aarch64_write_section
7924 #define elf_backend_can_refcount 1
7925 #define elf_backend_can_gc_sections 1
7926 #define elf_backend_plt_readonly 1
7927 #define elf_backend_want_got_plt 1
7928 #define elf_backend_want_plt_sym 0
7929 #define elf_backend_may_use_rel_p 0
7930 #define elf_backend_may_use_rela_p 1
7931 #define elf_backend_default_use_rela_p 1
7932 #define elf_backend_rela_normal 1
7933 #define elf_backend_got_header_size (GOT_ENTRY_SIZE * 3)
7934 #define elf_backend_default_execstack 0
7936 #undef elf_backend_obj_attrs_section
7937 #define elf_backend_obj_attrs_section ".ARM.attributes"
7939 #include "elfNN-target.h"