1 /* AArch64-specific support for NN-bit ELF.
2 Copyright (C) 2009-2015 Free Software Foundation, Inc.
3 Contributed by ARM Ltd.
5 This file is part of BFD, the Binary File Descriptor library.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; see the file COPYING3. If not,
19 see <http://www.gnu.org/licenses/>. */
21 /* Notes on implementation:
23 Thread Local Store (TLS)
27 The implementation currently supports both traditional TLS and TLS
28 descriptors, but only general dynamic (GD).
30 For traditional TLS the assembler will present us with code
31 fragments of the form:
34 R_AARCH64_TLSGD_ADR_PAGE21(foo)
35 add x0, :tlsgd_lo12:foo
36 R_AARCH64_TLSGD_ADD_LO12_NC(foo)
40 For TLS descriptors the assembler will present us with code
41 fragments of the form:
43 adrp x0, :tlsdesc:foo R_AARCH64_TLSDESC_ADR_PAGE21(foo)
44 ldr x1, [x0, #:tlsdesc_lo12:foo] R_AARCH64_TLSDESC_LD64_LO12(foo)
45 add x0, x0, #:tlsdesc_lo12:foo R_AARCH64_TLSDESC_ADD_LO12(foo)
47 blr x1 R_AARCH64_TLSDESC_CALL(foo)
49 The relocations R_AARCH64_TLSGD_{ADR_PREL21,ADD_LO12_NC} against foo
50 indicate that foo is thread local and should be accessed via the
51 traditional TLS mechanims.
53 The relocations R_AARCH64_TLSDESC_{ADR_PAGE21,LD64_LO12_NC,ADD_LO12_NC}
54 against foo indicate that 'foo' is thread local and should be accessed
55 via a TLS descriptor mechanism.
57 The precise instruction sequence is only relevant from the
58 perspective of linker relaxation which is currently not implemented.
60 The static linker must detect that 'foo' is a TLS object and
61 allocate a double GOT entry. The GOT entry must be created for both
62 global and local TLS symbols. Note that this is different to none
63 TLS local objects which do not need a GOT entry.
65 In the traditional TLS mechanism, the double GOT entry is used to
66 provide the tls_index structure, containing module and offset
67 entries. The static linker places the relocation R_AARCH64_TLS_DTPMOD
68 on the module entry. The loader will subsequently fixup this
69 relocation with the module identity.
71 For global traditional TLS symbols the static linker places an
72 R_AARCH64_TLS_DTPREL relocation on the offset entry. The loader
73 will subsequently fixup the offset. For local TLS symbols the static
74 linker fixes up offset.
76 In the TLS descriptor mechanism the double GOT entry is used to
77 provide the descriptor. The static linker places the relocation
78 R_AARCH64_TLSDESC on the first GOT slot. The loader will
79 subsequently fix this up.
83 The handling of TLS symbols is implemented across a number of
84 different backend functions. The following is a top level view of
85 what processing is performed where.
87 The TLS implementation maintains state information for each TLS
88 symbol. The state information for local and global symbols is kept
89 in different places. Global symbols use generic BFD structures while
90 local symbols use backend specific structures that are allocated and
91 maintained entirely by the backend.
95 elfNN_aarch64_check_relocs()
97 This function is invoked for each relocation.
99 The TLS relocations R_AARCH64_TLSGD_{ADR_PREL21,ADD_LO12_NC} and
100 R_AARCH64_TLSDESC_{ADR_PAGE21,LD64_LO12_NC,ADD_LO12_NC} are
101 spotted. One time creation of local symbol data structures are
102 created when the first local symbol is seen.
104 The reference count for a symbol is incremented. The GOT type for
105 each symbol is marked as general dynamic.
107 elfNN_aarch64_allocate_dynrelocs ()
109 For each global with positive reference count we allocate a double
110 GOT slot. For a traditional TLS symbol we allocate space for two
111 relocation entries on the GOT, for a TLS descriptor symbol we
112 allocate space for one relocation on the slot. Record the GOT offset
115 elfNN_aarch64_size_dynamic_sections ()
117 Iterate all input BFDS, look for in the local symbol data structure
118 constructed earlier for local TLS symbols and allocate them double
119 GOT slots along with space for a single GOT relocation. Update the
120 local symbol structure to record the GOT offset allocated.
122 elfNN_aarch64_relocate_section ()
124 Calls elfNN_aarch64_final_link_relocate ()
126 Emit the relevant TLS relocations against the GOT for each TLS
127 symbol. For local TLS symbols emit the GOT offset directly. The GOT
128 relocations are emitted once the first time a TLS symbol is
129 encountered. The implementation uses the LSB of the GOT offset to
130 flag that the relevant GOT relocations for a symbol have been
131 emitted. All of the TLS code that uses the GOT offset needs to take
132 care to mask out this flag bit before using the offset.
134 elfNN_aarch64_final_link_relocate ()
136 Fixup the R_AARCH64_TLSGD_{ADR_PREL21, ADD_LO12_NC} relocations. */
140 #include "libiberty.h"
142 #include "bfd_stdint.h"
145 #include "objalloc.h"
146 #include "elf/aarch64.h"
147 #include "elfxx-aarch64.h"
152 #define AARCH64_R(NAME) R_AARCH64_ ## NAME
153 #define AARCH64_R_STR(NAME) "R_AARCH64_" #NAME
154 #define HOWTO64(...) HOWTO (__VA_ARGS__)
155 #define HOWTO32(...) EMPTY_HOWTO (0)
156 #define LOG_FILE_ALIGN 3
160 #define AARCH64_R(NAME) R_AARCH64_P32_ ## NAME
161 #define AARCH64_R_STR(NAME) "R_AARCH64_P32_" #NAME
162 #define HOWTO64(...) EMPTY_HOWTO (0)
163 #define HOWTO32(...) HOWTO (__VA_ARGS__)
164 #define LOG_FILE_ALIGN 2
167 #define IS_AARCH64_TLS_RELOC(R_TYPE) \
168 ((R_TYPE) == BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC \
169 || (R_TYPE) == BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21 \
170 || (R_TYPE) == BFD_RELOC_AARCH64_TLSGD_ADR_PREL21 \
171 || (R_TYPE) == BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21 \
172 || (R_TYPE) == BFD_RELOC_AARCH64_TLSIE_LD32_GOTTPREL_LO12_NC \
173 || (R_TYPE) == BFD_RELOC_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC \
174 || (R_TYPE) == BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19 \
175 || (R_TYPE) == BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G0_NC \
176 || (R_TYPE) == BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G1 \
177 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_ADD_DTPREL_LO12 \
178 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_ADD_DTPREL_LO12_NC \
179 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC \
180 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21 \
181 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_ADR_PREL21 \
182 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_HI12 \
183 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_LO12 \
184 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_LO12_NC \
185 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0 \
186 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC \
187 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1 \
188 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1_NC \
189 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G2 \
190 || (R_TYPE) == BFD_RELOC_AARCH64_TLS_DTPMOD \
191 || (R_TYPE) == BFD_RELOC_AARCH64_TLS_DTPREL \
192 || (R_TYPE) == BFD_RELOC_AARCH64_TLS_TPREL \
193 || IS_AARCH64_TLSDESC_RELOC ((R_TYPE)))
195 #define IS_AARCH64_TLS_RELAX_RELOC(R_TYPE) \
196 ((R_TYPE) == BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21 \
197 || (R_TYPE) == BFD_RELOC_AARCH64_TLSGD_ADR_PREL21 \
198 || (R_TYPE) == BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC \
199 || (R_TYPE) == BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21 \
200 || (R_TYPE) == BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19 \
201 || (R_TYPE) == BFD_RELOC_AARCH64_TLSIE_LDNN_GOTTPREL_LO12_NC \
202 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21 \
203 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21 \
204 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_LD_PREL19 \
205 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_LDNN_LO12_NC \
206 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_CALL \
207 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_ADD_LO12_NC)
209 #define IS_AARCH64_TLSDESC_RELOC(R_TYPE) \
210 ((R_TYPE) == BFD_RELOC_AARCH64_TLSDESC \
211 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_ADD \
212 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_ADD_LO12_NC \
213 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21 \
214 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21 \
215 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_CALL \
216 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_LD32_LO12_NC \
217 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_LD64_LO12_NC \
218 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_LDR \
219 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_LD_PREL19 \
220 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_OFF_G0_NC \
221 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_OFF_G1)
223 #define ELIMINATE_COPY_RELOCS 0
225 /* Return size of a relocation entry. HTAB is the bfd's
226 elf_aarch64_link_hash_entry. */
227 #define RELOC_SIZE(HTAB) (sizeof (ElfNN_External_Rela))
229 /* GOT Entry size - 8 bytes in ELF64 and 4 bytes in ELF32. */
230 #define GOT_ENTRY_SIZE (ARCH_SIZE / 8)
231 #define PLT_ENTRY_SIZE (32)
232 #define PLT_SMALL_ENTRY_SIZE (16)
233 #define PLT_TLSDESC_ENTRY_SIZE (32)
235 /* Encoding of the nop instruction */
236 #define INSN_NOP 0xd503201f
238 #define aarch64_compute_jump_table_size(htab) \
239 (((htab)->root.srelplt == NULL) ? 0 \
240 : (htab)->root.srelplt->reloc_count * GOT_ENTRY_SIZE)
242 /* The first entry in a procedure linkage table looks like this
243 if the distance between the PLTGOT and the PLT is < 4GB use
244 these PLT entries. Note that the dynamic linker gets &PLTGOT[2]
245 in x16 and needs to work out PLTGOT[1] by using an address of
246 [x16,#-GOT_ENTRY_SIZE]. */
247 static const bfd_byte elfNN_aarch64_small_plt0_entry[PLT_ENTRY_SIZE] =
249 0xf0, 0x7b, 0xbf, 0xa9, /* stp x16, x30, [sp, #-16]! */
250 0x10, 0x00, 0x00, 0x90, /* adrp x16, (GOT+16) */
252 0x11, 0x0A, 0x40, 0xf9, /* ldr x17, [x16, #PLT_GOT+0x10] */
253 0x10, 0x42, 0x00, 0x91, /* add x16, x16,#PLT_GOT+0x10 */
255 0x11, 0x0A, 0x40, 0xb9, /* ldr w17, [x16, #PLT_GOT+0x8] */
256 0x10, 0x22, 0x00, 0x11, /* add w16, w16,#PLT_GOT+0x8 */
258 0x20, 0x02, 0x1f, 0xd6, /* br x17 */
259 0x1f, 0x20, 0x03, 0xd5, /* nop */
260 0x1f, 0x20, 0x03, 0xd5, /* nop */
261 0x1f, 0x20, 0x03, 0xd5, /* nop */
264 /* Per function entry in a procedure linkage table looks like this
265 if the distance between the PLTGOT and the PLT is < 4GB use
266 these PLT entries. */
267 static const bfd_byte elfNN_aarch64_small_plt_entry[PLT_SMALL_ENTRY_SIZE] =
269 0x10, 0x00, 0x00, 0x90, /* adrp x16, PLTGOT + n * 8 */
271 0x11, 0x02, 0x40, 0xf9, /* ldr x17, [x16, PLTGOT + n * 8] */
272 0x10, 0x02, 0x00, 0x91, /* add x16, x16, :lo12:PLTGOT + n * 8 */
274 0x11, 0x02, 0x40, 0xb9, /* ldr w17, [x16, PLTGOT + n * 4] */
275 0x10, 0x02, 0x00, 0x11, /* add w16, w16, :lo12:PLTGOT + n * 4 */
277 0x20, 0x02, 0x1f, 0xd6, /* br x17. */
280 static const bfd_byte
281 elfNN_aarch64_tlsdesc_small_plt_entry[PLT_TLSDESC_ENTRY_SIZE] =
283 0xe2, 0x0f, 0xbf, 0xa9, /* stp x2, x3, [sp, #-16]! */
284 0x02, 0x00, 0x00, 0x90, /* adrp x2, 0 */
285 0x03, 0x00, 0x00, 0x90, /* adrp x3, 0 */
287 0x42, 0x00, 0x40, 0xf9, /* ldr x2, [x2, #0] */
288 0x63, 0x00, 0x00, 0x91, /* add x3, x3, 0 */
290 0x42, 0x00, 0x40, 0xb9, /* ldr w2, [x2, #0] */
291 0x63, 0x00, 0x00, 0x11, /* add w3, w3, 0 */
293 0x40, 0x00, 0x1f, 0xd6, /* br x2 */
294 0x1f, 0x20, 0x03, 0xd5, /* nop */
295 0x1f, 0x20, 0x03, 0xd5, /* nop */
298 #define elf_info_to_howto elfNN_aarch64_info_to_howto
299 #define elf_info_to_howto_rel elfNN_aarch64_info_to_howto
301 #define AARCH64_ELF_ABI_VERSION 0
303 /* In case we're on a 32-bit machine, construct a 64-bit "-1" value. */
304 #define ALL_ONES (~ (bfd_vma) 0)
306 /* Indexed by the bfd interal reloc enumerators.
307 Therefore, the table needs to be synced with BFD_RELOC_AARCH64_*
310 static reloc_howto_type elfNN_aarch64_howto_table[] =
314 /* Basic data relocations. */
317 HOWTO (R_AARCH64_NULL, /* type */
319 3, /* size (0 = byte, 1 = short, 2 = long) */
321 FALSE, /* pc_relative */
323 complain_overflow_dont, /* complain_on_overflow */
324 bfd_elf_generic_reloc, /* special_function */
325 "R_AARCH64_NULL", /* name */
326 FALSE, /* partial_inplace */
329 FALSE), /* pcrel_offset */
331 HOWTO (R_AARCH64_NONE, /* type */
333 3, /* size (0 = byte, 1 = short, 2 = long) */
335 FALSE, /* pc_relative */
337 complain_overflow_dont, /* complain_on_overflow */
338 bfd_elf_generic_reloc, /* special_function */
339 "R_AARCH64_NONE", /* name */
340 FALSE, /* partial_inplace */
343 FALSE), /* pcrel_offset */
347 HOWTO64 (AARCH64_R (ABS64), /* type */
349 4, /* size (4 = long long) */
351 FALSE, /* pc_relative */
353 complain_overflow_unsigned, /* complain_on_overflow */
354 bfd_elf_generic_reloc, /* special_function */
355 AARCH64_R_STR (ABS64), /* name */
356 FALSE, /* partial_inplace */
357 ALL_ONES, /* src_mask */
358 ALL_ONES, /* dst_mask */
359 FALSE), /* pcrel_offset */
362 HOWTO (AARCH64_R (ABS32), /* type */
364 2, /* size (0 = byte, 1 = short, 2 = long) */
366 FALSE, /* pc_relative */
368 complain_overflow_unsigned, /* complain_on_overflow */
369 bfd_elf_generic_reloc, /* special_function */
370 AARCH64_R_STR (ABS32), /* name */
371 FALSE, /* partial_inplace */
372 0xffffffff, /* src_mask */
373 0xffffffff, /* dst_mask */
374 FALSE), /* pcrel_offset */
377 HOWTO (AARCH64_R (ABS16), /* type */
379 1, /* size (0 = byte, 1 = short, 2 = long) */
381 FALSE, /* pc_relative */
383 complain_overflow_unsigned, /* complain_on_overflow */
384 bfd_elf_generic_reloc, /* special_function */
385 AARCH64_R_STR (ABS16), /* name */
386 FALSE, /* partial_inplace */
387 0xffff, /* src_mask */
388 0xffff, /* dst_mask */
389 FALSE), /* pcrel_offset */
391 /* .xword: (S+A-P) */
392 HOWTO64 (AARCH64_R (PREL64), /* type */
394 4, /* size (4 = long long) */
396 TRUE, /* pc_relative */
398 complain_overflow_signed, /* complain_on_overflow */
399 bfd_elf_generic_reloc, /* special_function */
400 AARCH64_R_STR (PREL64), /* name */
401 FALSE, /* partial_inplace */
402 ALL_ONES, /* src_mask */
403 ALL_ONES, /* dst_mask */
404 TRUE), /* pcrel_offset */
407 HOWTO (AARCH64_R (PREL32), /* type */
409 2, /* size (0 = byte, 1 = short, 2 = long) */
411 TRUE, /* pc_relative */
413 complain_overflow_signed, /* complain_on_overflow */
414 bfd_elf_generic_reloc, /* special_function */
415 AARCH64_R_STR (PREL32), /* name */
416 FALSE, /* partial_inplace */
417 0xffffffff, /* src_mask */
418 0xffffffff, /* dst_mask */
419 TRUE), /* pcrel_offset */
422 HOWTO (AARCH64_R (PREL16), /* type */
424 1, /* size (0 = byte, 1 = short, 2 = long) */
426 TRUE, /* pc_relative */
428 complain_overflow_signed, /* complain_on_overflow */
429 bfd_elf_generic_reloc, /* special_function */
430 AARCH64_R_STR (PREL16), /* name */
431 FALSE, /* partial_inplace */
432 0xffff, /* src_mask */
433 0xffff, /* dst_mask */
434 TRUE), /* pcrel_offset */
436 /* Group relocations to create a 16, 32, 48 or 64 bit
437 unsigned data or abs address inline. */
439 /* MOVZ: ((S+A) >> 0) & 0xffff */
440 HOWTO (AARCH64_R (MOVW_UABS_G0), /* type */
442 2, /* size (0 = byte, 1 = short, 2 = long) */
444 FALSE, /* pc_relative */
446 complain_overflow_unsigned, /* complain_on_overflow */
447 bfd_elf_generic_reloc, /* special_function */
448 AARCH64_R_STR (MOVW_UABS_G0), /* name */
449 FALSE, /* partial_inplace */
450 0xffff, /* src_mask */
451 0xffff, /* dst_mask */
452 FALSE), /* pcrel_offset */
454 /* MOVK: ((S+A) >> 0) & 0xffff [no overflow check] */
455 HOWTO (AARCH64_R (MOVW_UABS_G0_NC), /* type */
457 2, /* size (0 = byte, 1 = short, 2 = long) */
459 FALSE, /* pc_relative */
461 complain_overflow_dont, /* complain_on_overflow */
462 bfd_elf_generic_reloc, /* special_function */
463 AARCH64_R_STR (MOVW_UABS_G0_NC), /* name */
464 FALSE, /* partial_inplace */
465 0xffff, /* src_mask */
466 0xffff, /* dst_mask */
467 FALSE), /* pcrel_offset */
469 /* MOVZ: ((S+A) >> 16) & 0xffff */
470 HOWTO (AARCH64_R (MOVW_UABS_G1), /* type */
472 2, /* size (0 = byte, 1 = short, 2 = long) */
474 FALSE, /* pc_relative */
476 complain_overflow_unsigned, /* complain_on_overflow */
477 bfd_elf_generic_reloc, /* special_function */
478 AARCH64_R_STR (MOVW_UABS_G1), /* name */
479 FALSE, /* partial_inplace */
480 0xffff, /* src_mask */
481 0xffff, /* dst_mask */
482 FALSE), /* pcrel_offset */
484 /* MOVK: ((S+A) >> 16) & 0xffff [no overflow check] */
485 HOWTO64 (AARCH64_R (MOVW_UABS_G1_NC), /* type */
487 2, /* size (0 = byte, 1 = short, 2 = long) */
489 FALSE, /* pc_relative */
491 complain_overflow_dont, /* complain_on_overflow */
492 bfd_elf_generic_reloc, /* special_function */
493 AARCH64_R_STR (MOVW_UABS_G1_NC), /* name */
494 FALSE, /* partial_inplace */
495 0xffff, /* src_mask */
496 0xffff, /* dst_mask */
497 FALSE), /* pcrel_offset */
499 /* MOVZ: ((S+A) >> 32) & 0xffff */
500 HOWTO64 (AARCH64_R (MOVW_UABS_G2), /* type */
502 2, /* size (0 = byte, 1 = short, 2 = long) */
504 FALSE, /* pc_relative */
506 complain_overflow_unsigned, /* complain_on_overflow */
507 bfd_elf_generic_reloc, /* special_function */
508 AARCH64_R_STR (MOVW_UABS_G2), /* name */
509 FALSE, /* partial_inplace */
510 0xffff, /* src_mask */
511 0xffff, /* dst_mask */
512 FALSE), /* pcrel_offset */
514 /* MOVK: ((S+A) >> 32) & 0xffff [no overflow check] */
515 HOWTO64 (AARCH64_R (MOVW_UABS_G2_NC), /* type */
517 2, /* size (0 = byte, 1 = short, 2 = long) */
519 FALSE, /* pc_relative */
521 complain_overflow_dont, /* complain_on_overflow */
522 bfd_elf_generic_reloc, /* special_function */
523 AARCH64_R_STR (MOVW_UABS_G2_NC), /* name */
524 FALSE, /* partial_inplace */
525 0xffff, /* src_mask */
526 0xffff, /* dst_mask */
527 FALSE), /* pcrel_offset */
529 /* MOVZ: ((S+A) >> 48) & 0xffff */
530 HOWTO64 (AARCH64_R (MOVW_UABS_G3), /* type */
532 2, /* size (0 = byte, 1 = short, 2 = long) */
534 FALSE, /* pc_relative */
536 complain_overflow_unsigned, /* complain_on_overflow */
537 bfd_elf_generic_reloc, /* special_function */
538 AARCH64_R_STR (MOVW_UABS_G3), /* name */
539 FALSE, /* partial_inplace */
540 0xffff, /* src_mask */
541 0xffff, /* dst_mask */
542 FALSE), /* pcrel_offset */
544 /* Group relocations to create high part of a 16, 32, 48 or 64 bit
545 signed data or abs address inline. Will change instruction
546 to MOVN or MOVZ depending on sign of calculated value. */
548 /* MOV[ZN]: ((S+A) >> 0) & 0xffff */
549 HOWTO (AARCH64_R (MOVW_SABS_G0), /* type */
551 2, /* size (0 = byte, 1 = short, 2 = long) */
553 FALSE, /* pc_relative */
555 complain_overflow_signed, /* complain_on_overflow */
556 bfd_elf_generic_reloc, /* special_function */
557 AARCH64_R_STR (MOVW_SABS_G0), /* name */
558 FALSE, /* partial_inplace */
559 0xffff, /* src_mask */
560 0xffff, /* dst_mask */
561 FALSE), /* pcrel_offset */
563 /* MOV[ZN]: ((S+A) >> 16) & 0xffff */
564 HOWTO64 (AARCH64_R (MOVW_SABS_G1), /* type */
566 2, /* size (0 = byte, 1 = short, 2 = long) */
568 FALSE, /* pc_relative */
570 complain_overflow_signed, /* complain_on_overflow */
571 bfd_elf_generic_reloc, /* special_function */
572 AARCH64_R_STR (MOVW_SABS_G1), /* name */
573 FALSE, /* partial_inplace */
574 0xffff, /* src_mask */
575 0xffff, /* dst_mask */
576 FALSE), /* pcrel_offset */
578 /* MOV[ZN]: ((S+A) >> 32) & 0xffff */
579 HOWTO64 (AARCH64_R (MOVW_SABS_G2), /* type */
581 2, /* size (0 = byte, 1 = short, 2 = long) */
583 FALSE, /* pc_relative */
585 complain_overflow_signed, /* complain_on_overflow */
586 bfd_elf_generic_reloc, /* special_function */
587 AARCH64_R_STR (MOVW_SABS_G2), /* name */
588 FALSE, /* partial_inplace */
589 0xffff, /* src_mask */
590 0xffff, /* dst_mask */
591 FALSE), /* pcrel_offset */
593 /* Relocations to generate 19, 21 and 33 bit PC-relative load/store
594 addresses: PG(x) is (x & ~0xfff). */
596 /* LD-lit: ((S+A-P) >> 2) & 0x7ffff */
597 HOWTO (AARCH64_R (LD_PREL_LO19), /* type */
599 2, /* size (0 = byte, 1 = short, 2 = long) */
601 TRUE, /* pc_relative */
603 complain_overflow_signed, /* complain_on_overflow */
604 bfd_elf_generic_reloc, /* special_function */
605 AARCH64_R_STR (LD_PREL_LO19), /* name */
606 FALSE, /* partial_inplace */
607 0x7ffff, /* src_mask */
608 0x7ffff, /* dst_mask */
609 TRUE), /* pcrel_offset */
611 /* ADR: (S+A-P) & 0x1fffff */
612 HOWTO (AARCH64_R (ADR_PREL_LO21), /* type */
614 2, /* size (0 = byte, 1 = short, 2 = long) */
616 TRUE, /* pc_relative */
618 complain_overflow_signed, /* complain_on_overflow */
619 bfd_elf_generic_reloc, /* special_function */
620 AARCH64_R_STR (ADR_PREL_LO21), /* name */
621 FALSE, /* partial_inplace */
622 0x1fffff, /* src_mask */
623 0x1fffff, /* dst_mask */
624 TRUE), /* pcrel_offset */
626 /* ADRP: ((PG(S+A)-PG(P)) >> 12) & 0x1fffff */
627 HOWTO (AARCH64_R (ADR_PREL_PG_HI21), /* type */
629 2, /* size (0 = byte, 1 = short, 2 = long) */
631 TRUE, /* pc_relative */
633 complain_overflow_signed, /* complain_on_overflow */
634 bfd_elf_generic_reloc, /* special_function */
635 AARCH64_R_STR (ADR_PREL_PG_HI21), /* name */
636 FALSE, /* partial_inplace */
637 0x1fffff, /* src_mask */
638 0x1fffff, /* dst_mask */
639 TRUE), /* pcrel_offset */
641 /* ADRP: ((PG(S+A)-PG(P)) >> 12) & 0x1fffff [no overflow check] */
642 HOWTO64 (AARCH64_R (ADR_PREL_PG_HI21_NC), /* type */
644 2, /* size (0 = byte, 1 = short, 2 = long) */
646 TRUE, /* pc_relative */
648 complain_overflow_dont, /* complain_on_overflow */
649 bfd_elf_generic_reloc, /* special_function */
650 AARCH64_R_STR (ADR_PREL_PG_HI21_NC), /* name */
651 FALSE, /* partial_inplace */
652 0x1fffff, /* src_mask */
653 0x1fffff, /* dst_mask */
654 TRUE), /* pcrel_offset */
656 /* ADD: (S+A) & 0xfff [no overflow check] */
657 HOWTO (AARCH64_R (ADD_ABS_LO12_NC), /* type */
659 2, /* size (0 = byte, 1 = short, 2 = long) */
661 FALSE, /* pc_relative */
663 complain_overflow_dont, /* complain_on_overflow */
664 bfd_elf_generic_reloc, /* special_function */
665 AARCH64_R_STR (ADD_ABS_LO12_NC), /* name */
666 FALSE, /* partial_inplace */
667 0x3ffc00, /* src_mask */
668 0x3ffc00, /* dst_mask */
669 FALSE), /* pcrel_offset */
671 /* LD/ST8: (S+A) & 0xfff */
672 HOWTO (AARCH64_R (LDST8_ABS_LO12_NC), /* type */
674 2, /* size (0 = byte, 1 = short, 2 = long) */
676 FALSE, /* pc_relative */
678 complain_overflow_dont, /* complain_on_overflow */
679 bfd_elf_generic_reloc, /* special_function */
680 AARCH64_R_STR (LDST8_ABS_LO12_NC), /* name */
681 FALSE, /* partial_inplace */
682 0xfff, /* src_mask */
683 0xfff, /* dst_mask */
684 FALSE), /* pcrel_offset */
686 /* Relocations for control-flow instructions. */
688 /* TBZ/NZ: ((S+A-P) >> 2) & 0x3fff */
689 HOWTO (AARCH64_R (TSTBR14), /* type */
691 2, /* size (0 = byte, 1 = short, 2 = long) */
693 TRUE, /* pc_relative */
695 complain_overflow_signed, /* complain_on_overflow */
696 bfd_elf_generic_reloc, /* special_function */
697 AARCH64_R_STR (TSTBR14), /* name */
698 FALSE, /* partial_inplace */
699 0x3fff, /* src_mask */
700 0x3fff, /* dst_mask */
701 TRUE), /* pcrel_offset */
703 /* B.cond: ((S+A-P) >> 2) & 0x7ffff */
704 HOWTO (AARCH64_R (CONDBR19), /* type */
706 2, /* size (0 = byte, 1 = short, 2 = long) */
708 TRUE, /* pc_relative */
710 complain_overflow_signed, /* complain_on_overflow */
711 bfd_elf_generic_reloc, /* special_function */
712 AARCH64_R_STR (CONDBR19), /* name */
713 FALSE, /* partial_inplace */
714 0x7ffff, /* src_mask */
715 0x7ffff, /* dst_mask */
716 TRUE), /* pcrel_offset */
718 /* B: ((S+A-P) >> 2) & 0x3ffffff */
719 HOWTO (AARCH64_R (JUMP26), /* type */
721 2, /* size (0 = byte, 1 = short, 2 = long) */
723 TRUE, /* pc_relative */
725 complain_overflow_signed, /* complain_on_overflow */
726 bfd_elf_generic_reloc, /* special_function */
727 AARCH64_R_STR (JUMP26), /* name */
728 FALSE, /* partial_inplace */
729 0x3ffffff, /* src_mask */
730 0x3ffffff, /* dst_mask */
731 TRUE), /* pcrel_offset */
733 /* BL: ((S+A-P) >> 2) & 0x3ffffff */
734 HOWTO (AARCH64_R (CALL26), /* type */
736 2, /* size (0 = byte, 1 = short, 2 = long) */
738 TRUE, /* pc_relative */
740 complain_overflow_signed, /* complain_on_overflow */
741 bfd_elf_generic_reloc, /* special_function */
742 AARCH64_R_STR (CALL26), /* name */
743 FALSE, /* partial_inplace */
744 0x3ffffff, /* src_mask */
745 0x3ffffff, /* dst_mask */
746 TRUE), /* pcrel_offset */
748 /* LD/ST16: (S+A) & 0xffe */
749 HOWTO (AARCH64_R (LDST16_ABS_LO12_NC), /* type */
751 2, /* size (0 = byte, 1 = short, 2 = long) */
753 FALSE, /* pc_relative */
755 complain_overflow_dont, /* complain_on_overflow */
756 bfd_elf_generic_reloc, /* special_function */
757 AARCH64_R_STR (LDST16_ABS_LO12_NC), /* name */
758 FALSE, /* partial_inplace */
759 0xffe, /* src_mask */
760 0xffe, /* dst_mask */
761 FALSE), /* pcrel_offset */
763 /* LD/ST32: (S+A) & 0xffc */
764 HOWTO (AARCH64_R (LDST32_ABS_LO12_NC), /* type */
766 2, /* size (0 = byte, 1 = short, 2 = long) */
768 FALSE, /* pc_relative */
770 complain_overflow_dont, /* complain_on_overflow */
771 bfd_elf_generic_reloc, /* special_function */
772 AARCH64_R_STR (LDST32_ABS_LO12_NC), /* name */
773 FALSE, /* partial_inplace */
774 0xffc, /* src_mask */
775 0xffc, /* dst_mask */
776 FALSE), /* pcrel_offset */
778 /* LD/ST64: (S+A) & 0xff8 */
779 HOWTO (AARCH64_R (LDST64_ABS_LO12_NC), /* type */
781 2, /* size (0 = byte, 1 = short, 2 = long) */
783 FALSE, /* pc_relative */
785 complain_overflow_dont, /* complain_on_overflow */
786 bfd_elf_generic_reloc, /* special_function */
787 AARCH64_R_STR (LDST64_ABS_LO12_NC), /* name */
788 FALSE, /* partial_inplace */
789 0xff8, /* src_mask */
790 0xff8, /* dst_mask */
791 FALSE), /* pcrel_offset */
793 /* LD/ST128: (S+A) & 0xff0 */
794 HOWTO (AARCH64_R (LDST128_ABS_LO12_NC), /* type */
796 2, /* size (0 = byte, 1 = short, 2 = long) */
798 FALSE, /* pc_relative */
800 complain_overflow_dont, /* complain_on_overflow */
801 bfd_elf_generic_reloc, /* special_function */
802 AARCH64_R_STR (LDST128_ABS_LO12_NC), /* name */
803 FALSE, /* partial_inplace */
804 0xff0, /* src_mask */
805 0xff0, /* dst_mask */
806 FALSE), /* pcrel_offset */
808 /* Set a load-literal immediate field to bits
809 0x1FFFFC of G(S)-P */
810 HOWTO (AARCH64_R (GOT_LD_PREL19), /* type */
812 2, /* size (0 = byte,1 = short,2 = long) */
814 TRUE, /* pc_relative */
816 complain_overflow_signed, /* complain_on_overflow */
817 bfd_elf_generic_reloc, /* special_function */
818 AARCH64_R_STR (GOT_LD_PREL19), /* name */
819 FALSE, /* partial_inplace */
820 0xffffe0, /* src_mask */
821 0xffffe0, /* dst_mask */
822 TRUE), /* pcrel_offset */
824 /* Get to the page for the GOT entry for the symbol
825 (G(S) - P) using an ADRP instruction. */
826 HOWTO (AARCH64_R (ADR_GOT_PAGE), /* type */
828 2, /* size (0 = byte, 1 = short, 2 = long) */
830 TRUE, /* pc_relative */
832 complain_overflow_dont, /* complain_on_overflow */
833 bfd_elf_generic_reloc, /* special_function */
834 AARCH64_R_STR (ADR_GOT_PAGE), /* name */
835 FALSE, /* partial_inplace */
836 0x1fffff, /* src_mask */
837 0x1fffff, /* dst_mask */
838 TRUE), /* pcrel_offset */
840 /* LD64: GOT offset G(S) & 0xff8 */
841 HOWTO64 (AARCH64_R (LD64_GOT_LO12_NC), /* type */
843 2, /* size (0 = byte, 1 = short, 2 = long) */
845 FALSE, /* pc_relative */
847 complain_overflow_dont, /* complain_on_overflow */
848 bfd_elf_generic_reloc, /* special_function */
849 AARCH64_R_STR (LD64_GOT_LO12_NC), /* name */
850 FALSE, /* partial_inplace */
851 0xff8, /* src_mask */
852 0xff8, /* dst_mask */
853 FALSE), /* pcrel_offset */
855 /* LD32: GOT offset G(S) & 0xffc */
856 HOWTO32 (AARCH64_R (LD32_GOT_LO12_NC), /* type */
858 2, /* size (0 = byte, 1 = short, 2 = long) */
860 FALSE, /* pc_relative */
862 complain_overflow_dont, /* complain_on_overflow */
863 bfd_elf_generic_reloc, /* special_function */
864 AARCH64_R_STR (LD32_GOT_LO12_NC), /* name */
865 FALSE, /* partial_inplace */
866 0xffc, /* src_mask */
867 0xffc, /* dst_mask */
868 FALSE), /* pcrel_offset */
870 /* LD64: GOT offset for the symbol. */
871 HOWTO64 (AARCH64_R (LD64_GOTOFF_LO15), /* type */
873 2, /* size (0 = byte, 1 = short, 2 = long) */
875 FALSE, /* pc_relative */
877 complain_overflow_unsigned, /* complain_on_overflow */
878 bfd_elf_generic_reloc, /* special_function */
879 AARCH64_R_STR (LD64_GOTOFF_LO15), /* name */
880 FALSE, /* partial_inplace */
881 0x7ff8, /* src_mask */
882 0x7ff8, /* dst_mask */
883 FALSE), /* pcrel_offset */
885 /* LD32: GOT offset to the page address of GOT table.
886 (G(S) - PAGE (_GLOBAL_OFFSET_TABLE_)) & 0x5ffc. */
887 HOWTO32 (AARCH64_R (LD32_GOTPAGE_LO14), /* type */
889 2, /* size (0 = byte, 1 = short, 2 = long) */
891 FALSE, /* pc_relative */
893 complain_overflow_unsigned, /* complain_on_overflow */
894 bfd_elf_generic_reloc, /* special_function */
895 AARCH64_R_STR (LD32_GOTPAGE_LO14), /* name */
896 FALSE, /* partial_inplace */
897 0x5ffc, /* src_mask */
898 0x5ffc, /* dst_mask */
899 FALSE), /* pcrel_offset */
901 /* LD64: GOT offset to the page address of GOT table.
902 (G(S) - PAGE (_GLOBAL_OFFSET_TABLE_)) & 0x7ff8. */
903 HOWTO64 (AARCH64_R (LD64_GOTPAGE_LO15), /* type */
905 2, /* size (0 = byte, 1 = short, 2 = long) */
907 FALSE, /* pc_relative */
909 complain_overflow_unsigned, /* complain_on_overflow */
910 bfd_elf_generic_reloc, /* special_function */
911 AARCH64_R_STR (LD64_GOTPAGE_LO15), /* name */
912 FALSE, /* partial_inplace */
913 0x7ff8, /* src_mask */
914 0x7ff8, /* dst_mask */
915 FALSE), /* pcrel_offset */
917 /* Get to the page for the GOT entry for the symbol
918 (G(S) - P) using an ADRP instruction. */
919 HOWTO (AARCH64_R (TLSGD_ADR_PAGE21), /* type */
921 2, /* size (0 = byte, 1 = short, 2 = long) */
923 TRUE, /* pc_relative */
925 complain_overflow_dont, /* complain_on_overflow */
926 bfd_elf_generic_reloc, /* special_function */
927 AARCH64_R_STR (TLSGD_ADR_PAGE21), /* name */
928 FALSE, /* partial_inplace */
929 0x1fffff, /* src_mask */
930 0x1fffff, /* dst_mask */
931 TRUE), /* pcrel_offset */
933 HOWTO (AARCH64_R (TLSGD_ADR_PREL21), /* type */
935 2, /* size (0 = byte, 1 = short, 2 = long) */
937 TRUE, /* pc_relative */
939 complain_overflow_dont, /* complain_on_overflow */
940 bfd_elf_generic_reloc, /* special_function */
941 AARCH64_R_STR (TLSGD_ADR_PREL21), /* name */
942 FALSE, /* partial_inplace */
943 0x1fffff, /* src_mask */
944 0x1fffff, /* dst_mask */
945 TRUE), /* pcrel_offset */
947 /* ADD: GOT offset G(S) & 0xff8 [no overflow check] */
948 HOWTO (AARCH64_R (TLSGD_ADD_LO12_NC), /* type */
950 2, /* size (0 = byte, 1 = short, 2 = long) */
952 FALSE, /* pc_relative */
954 complain_overflow_dont, /* complain_on_overflow */
955 bfd_elf_generic_reloc, /* special_function */
956 AARCH64_R_STR (TLSGD_ADD_LO12_NC), /* name */
957 FALSE, /* partial_inplace */
958 0xfff, /* src_mask */
959 0xfff, /* dst_mask */
960 FALSE), /* pcrel_offset */
962 HOWTO64 (AARCH64_R (TLSIE_MOVW_GOTTPREL_G1), /* type */
964 2, /* size (0 = byte, 1 = short, 2 = long) */
966 FALSE, /* pc_relative */
968 complain_overflow_dont, /* complain_on_overflow */
969 bfd_elf_generic_reloc, /* special_function */
970 AARCH64_R_STR (TLSIE_MOVW_GOTTPREL_G1), /* name */
971 FALSE, /* partial_inplace */
972 0xffff, /* src_mask */
973 0xffff, /* dst_mask */
974 FALSE), /* pcrel_offset */
976 HOWTO64 (AARCH64_R (TLSIE_MOVW_GOTTPREL_G0_NC), /* type */
978 2, /* size (0 = byte, 1 = short, 2 = long) */
980 FALSE, /* pc_relative */
982 complain_overflow_dont, /* complain_on_overflow */
983 bfd_elf_generic_reloc, /* special_function */
984 AARCH64_R_STR (TLSIE_MOVW_GOTTPREL_G0_NC), /* name */
985 FALSE, /* partial_inplace */
986 0xffff, /* src_mask */
987 0xffff, /* dst_mask */
988 FALSE), /* pcrel_offset */
990 HOWTO (AARCH64_R (TLSIE_ADR_GOTTPREL_PAGE21), /* type */
992 2, /* size (0 = byte, 1 = short, 2 = long) */
994 FALSE, /* pc_relative */
996 complain_overflow_dont, /* complain_on_overflow */
997 bfd_elf_generic_reloc, /* special_function */
998 AARCH64_R_STR (TLSIE_ADR_GOTTPREL_PAGE21), /* name */
999 FALSE, /* partial_inplace */
1000 0x1fffff, /* src_mask */
1001 0x1fffff, /* dst_mask */
1002 FALSE), /* pcrel_offset */
1004 HOWTO64 (AARCH64_R (TLSIE_LD64_GOTTPREL_LO12_NC), /* type */
1006 2, /* size (0 = byte, 1 = short, 2 = long) */
1008 FALSE, /* pc_relative */
1010 complain_overflow_dont, /* complain_on_overflow */
1011 bfd_elf_generic_reloc, /* special_function */
1012 AARCH64_R_STR (TLSIE_LD64_GOTTPREL_LO12_NC), /* name */
1013 FALSE, /* partial_inplace */
1014 0xff8, /* src_mask */
1015 0xff8, /* dst_mask */
1016 FALSE), /* pcrel_offset */
1018 HOWTO32 (AARCH64_R (TLSIE_LD32_GOTTPREL_LO12_NC), /* type */
1020 2, /* size (0 = byte, 1 = short, 2 = long) */
1022 FALSE, /* pc_relative */
1024 complain_overflow_dont, /* complain_on_overflow */
1025 bfd_elf_generic_reloc, /* special_function */
1026 AARCH64_R_STR (TLSIE_LD32_GOTTPREL_LO12_NC), /* name */
1027 FALSE, /* partial_inplace */
1028 0xffc, /* src_mask */
1029 0xffc, /* dst_mask */
1030 FALSE), /* pcrel_offset */
1032 HOWTO (AARCH64_R (TLSIE_LD_GOTTPREL_PREL19), /* type */
1034 2, /* size (0 = byte, 1 = short, 2 = long) */
1036 FALSE, /* pc_relative */
1038 complain_overflow_dont, /* complain_on_overflow */
1039 bfd_elf_generic_reloc, /* special_function */
1040 AARCH64_R_STR (TLSIE_LD_GOTTPREL_PREL19), /* name */
1041 FALSE, /* partial_inplace */
1042 0x1ffffc, /* src_mask */
1043 0x1ffffc, /* dst_mask */
1044 FALSE), /* pcrel_offset */
1046 /* ADD: bit[23:12] of byte offset to module TLS base address. */
1047 HOWTO (AARCH64_R (TLSLD_ADD_DTPREL_HI12), /* type */
1048 12, /* rightshift */
1049 2, /* size (0 = byte, 1 = short, 2 = long) */
1051 FALSE, /* pc_relative */
1053 complain_overflow_unsigned, /* complain_on_overflow */
1054 bfd_elf_generic_reloc, /* special_function */
1055 AARCH64_R_STR (TLSLD_ADD_DTPREL_HI12), /* name */
1056 FALSE, /* partial_inplace */
1057 0xfff, /* src_mask */
1058 0xfff, /* dst_mask */
1059 FALSE), /* pcrel_offset */
1061 /* Unsigned 12 bit byte offset to module TLS base address. */
1062 HOWTO (AARCH64_R (TLSLD_ADD_DTPREL_LO12), /* type */
1064 2, /* size (0 = byte, 1 = short, 2 = long) */
1066 FALSE, /* pc_relative */
1068 complain_overflow_unsigned, /* complain_on_overflow */
1069 bfd_elf_generic_reloc, /* special_function */
1070 AARCH64_R_STR (TLSLD_ADD_DTPREL_LO12), /* name */
1071 FALSE, /* partial_inplace */
1072 0xfff, /* src_mask */
1073 0xfff, /* dst_mask */
1074 FALSE), /* pcrel_offset */
1076 /* No overflow check version of BFD_RELOC_AARCH64_TLSLD_ADD_DTPREL_LO12. */
1077 HOWTO (AARCH64_R (TLSLD_ADD_DTPREL_LO12_NC), /* type */
1079 2, /* size (0 = byte, 1 = short, 2 = long) */
1081 FALSE, /* pc_relative */
1083 complain_overflow_dont, /* complain_on_overflow */
1084 bfd_elf_generic_reloc, /* special_function */
1085 AARCH64_R_STR (TLSLD_ADD_DTPREL_LO12_NC), /* name */
1086 FALSE, /* partial_inplace */
1087 0xfff, /* src_mask */
1088 0xfff, /* dst_mask */
1089 FALSE), /* pcrel_offset */
1091 /* ADD: GOT offset G(S) & 0xff8 [no overflow check] */
1092 HOWTO (AARCH64_R (TLSLD_ADD_LO12_NC), /* type */
1094 2, /* size (0 = byte, 1 = short, 2 = long) */
1096 FALSE, /* pc_relative */
1098 complain_overflow_dont, /* complain_on_overflow */
1099 bfd_elf_generic_reloc, /* special_function */
1100 AARCH64_R_STR (TLSLD_ADD_LO12_NC), /* name */
1101 FALSE, /* partial_inplace */
1102 0xfff, /* src_mask */
1103 0xfff, /* dst_mask */
1104 FALSE), /* pcrel_offset */
1106 /* Get to the page for the GOT entry for the symbol
1107 (G(S) - P) using an ADRP instruction. */
1108 HOWTO (AARCH64_R (TLSLD_ADR_PAGE21), /* type */
1109 12, /* rightshift */
1110 2, /* size (0 = byte, 1 = short, 2 = long) */
1112 TRUE, /* pc_relative */
1114 complain_overflow_signed, /* complain_on_overflow */
1115 bfd_elf_generic_reloc, /* special_function */
1116 AARCH64_R_STR (TLSLD_ADR_PAGE21), /* name */
1117 FALSE, /* partial_inplace */
1118 0x1fffff, /* src_mask */
1119 0x1fffff, /* dst_mask */
1120 TRUE), /* pcrel_offset */
1122 HOWTO (AARCH64_R (TLSLD_ADR_PREL21), /* type */
1124 2, /* size (0 = byte, 1 = short, 2 = long) */
1126 TRUE, /* pc_relative */
1128 complain_overflow_signed, /* complain_on_overflow */
1129 bfd_elf_generic_reloc, /* special_function */
1130 AARCH64_R_STR (TLSLD_ADR_PREL21), /* name */
1131 FALSE, /* partial_inplace */
1132 0x1fffff, /* src_mask */
1133 0x1fffff, /* dst_mask */
1134 TRUE), /* pcrel_offset */
1136 /* MOVZ: bit[15:0] of byte offset to module TLS base address. */
1137 HOWTO (AARCH64_R (TLSLD_MOVW_DTPREL_G0), /* type */
1139 2, /* size (0 = byte, 1 = short, 2 = long) */
1141 FALSE, /* pc_relative */
1143 complain_overflow_unsigned, /* complain_on_overflow */
1144 bfd_elf_generic_reloc, /* special_function */
1145 AARCH64_R_STR (TLSLD_MOVW_DTPREL_G0), /* name */
1146 FALSE, /* partial_inplace */
1147 0xffff, /* src_mask */
1148 0xffff, /* dst_mask */
1149 FALSE), /* pcrel_offset */
1151 /* No overflow check version of BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G0. */
1152 HOWTO (AARCH64_R (TLSLD_MOVW_DTPREL_G0_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 (TLSLD_MOVW_DTPREL_G0_NC), /* name */
1161 FALSE, /* partial_inplace */
1162 0xffff, /* src_mask */
1163 0xffff, /* dst_mask */
1164 FALSE), /* pcrel_offset */
1166 /* MOVZ: bit[31:16] of byte offset to module TLS base address. */
1167 HOWTO (AARCH64_R (TLSLD_MOVW_DTPREL_G1), /* type */
1168 16, /* rightshift */
1169 2, /* size (0 = byte, 1 = short, 2 = long) */
1171 FALSE, /* pc_relative */
1173 complain_overflow_unsigned, /* complain_on_overflow */
1174 bfd_elf_generic_reloc, /* special_function */
1175 AARCH64_R_STR (TLSLD_MOVW_DTPREL_G1), /* name */
1176 FALSE, /* partial_inplace */
1177 0xffff, /* src_mask */
1178 0xffff, /* dst_mask */
1179 FALSE), /* pcrel_offset */
1181 /* No overflow check version of BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G1. */
1182 HOWTO64 (AARCH64_R (TLSLD_MOVW_DTPREL_G1_NC), /* type */
1183 16, /* rightshift */
1184 2, /* size (0 = byte, 1 = short, 2 = long) */
1186 FALSE, /* pc_relative */
1188 complain_overflow_dont, /* complain_on_overflow */
1189 bfd_elf_generic_reloc, /* special_function */
1190 AARCH64_R_STR (TLSLD_MOVW_DTPREL_G1_NC), /* name */
1191 FALSE, /* partial_inplace */
1192 0xffff, /* src_mask */
1193 0xffff, /* dst_mask */
1194 FALSE), /* pcrel_offset */
1196 /* MOVZ: bit[47:32] of byte offset to module TLS base address. */
1197 HOWTO64 (AARCH64_R (TLSLD_MOVW_DTPREL_G2), /* type */
1198 32, /* rightshift */
1199 2, /* size (0 = byte, 1 = short, 2 = long) */
1201 FALSE, /* pc_relative */
1203 complain_overflow_unsigned, /* complain_on_overflow */
1204 bfd_elf_generic_reloc, /* special_function */
1205 AARCH64_R_STR (TLSLD_MOVW_DTPREL_G2), /* name */
1206 FALSE, /* partial_inplace */
1207 0xffff, /* src_mask */
1208 0xffff, /* dst_mask */
1209 FALSE), /* pcrel_offset */
1211 HOWTO64 (AARCH64_R (TLSLE_MOVW_TPREL_G2), /* type */
1212 32, /* rightshift */
1213 2, /* size (0 = byte, 1 = short, 2 = long) */
1215 FALSE, /* pc_relative */
1217 complain_overflow_unsigned, /* complain_on_overflow */
1218 bfd_elf_generic_reloc, /* special_function */
1219 AARCH64_R_STR (TLSLE_MOVW_TPREL_G2), /* name */
1220 FALSE, /* partial_inplace */
1221 0xffff, /* src_mask */
1222 0xffff, /* dst_mask */
1223 FALSE), /* pcrel_offset */
1225 HOWTO (AARCH64_R (TLSLE_MOVW_TPREL_G1), /* type */
1226 16, /* rightshift */
1227 2, /* size (0 = byte, 1 = short, 2 = long) */
1229 FALSE, /* pc_relative */
1231 complain_overflow_dont, /* complain_on_overflow */
1232 bfd_elf_generic_reloc, /* special_function */
1233 AARCH64_R_STR (TLSLE_MOVW_TPREL_G1), /* name */
1234 FALSE, /* partial_inplace */
1235 0xffff, /* src_mask */
1236 0xffff, /* dst_mask */
1237 FALSE), /* pcrel_offset */
1239 HOWTO64 (AARCH64_R (TLSLE_MOVW_TPREL_G1_NC), /* type */
1240 16, /* rightshift */
1241 2, /* size (0 = byte, 1 = short, 2 = long) */
1243 FALSE, /* pc_relative */
1245 complain_overflow_dont, /* complain_on_overflow */
1246 bfd_elf_generic_reloc, /* special_function */
1247 AARCH64_R_STR (TLSLE_MOVW_TPREL_G1_NC), /* name */
1248 FALSE, /* partial_inplace */
1249 0xffff, /* src_mask */
1250 0xffff, /* dst_mask */
1251 FALSE), /* pcrel_offset */
1253 HOWTO (AARCH64_R (TLSLE_MOVW_TPREL_G0), /* type */
1255 2, /* size (0 = byte, 1 = short, 2 = long) */
1257 FALSE, /* pc_relative */
1259 complain_overflow_dont, /* complain_on_overflow */
1260 bfd_elf_generic_reloc, /* special_function */
1261 AARCH64_R_STR (TLSLE_MOVW_TPREL_G0), /* name */
1262 FALSE, /* partial_inplace */
1263 0xffff, /* src_mask */
1264 0xffff, /* dst_mask */
1265 FALSE), /* pcrel_offset */
1267 HOWTO (AARCH64_R (TLSLE_MOVW_TPREL_G0_NC), /* type */
1269 2, /* size (0 = byte, 1 = short, 2 = long) */
1271 FALSE, /* pc_relative */
1273 complain_overflow_dont, /* complain_on_overflow */
1274 bfd_elf_generic_reloc, /* special_function */
1275 AARCH64_R_STR (TLSLE_MOVW_TPREL_G0_NC), /* name */
1276 FALSE, /* partial_inplace */
1277 0xffff, /* src_mask */
1278 0xffff, /* dst_mask */
1279 FALSE), /* pcrel_offset */
1281 HOWTO (AARCH64_R (TLSLE_ADD_TPREL_HI12), /* type */
1282 12, /* rightshift */
1283 2, /* size (0 = byte, 1 = short, 2 = long) */
1285 FALSE, /* pc_relative */
1287 complain_overflow_unsigned, /* complain_on_overflow */
1288 bfd_elf_generic_reloc, /* special_function */
1289 AARCH64_R_STR (TLSLE_ADD_TPREL_HI12), /* name */
1290 FALSE, /* partial_inplace */
1291 0xfff, /* src_mask */
1292 0xfff, /* dst_mask */
1293 FALSE), /* pcrel_offset */
1295 HOWTO (AARCH64_R (TLSLE_ADD_TPREL_LO12), /* type */
1297 2, /* size (0 = byte, 1 = short, 2 = long) */
1299 FALSE, /* pc_relative */
1301 complain_overflow_unsigned, /* complain_on_overflow */
1302 bfd_elf_generic_reloc, /* special_function */
1303 AARCH64_R_STR (TLSLE_ADD_TPREL_LO12), /* name */
1304 FALSE, /* partial_inplace */
1305 0xfff, /* src_mask */
1306 0xfff, /* dst_mask */
1307 FALSE), /* pcrel_offset */
1309 HOWTO (AARCH64_R (TLSLE_ADD_TPREL_LO12_NC), /* type */
1311 2, /* size (0 = byte, 1 = short, 2 = long) */
1313 FALSE, /* pc_relative */
1315 complain_overflow_dont, /* complain_on_overflow */
1316 bfd_elf_generic_reloc, /* special_function */
1317 AARCH64_R_STR (TLSLE_ADD_TPREL_LO12_NC), /* name */
1318 FALSE, /* partial_inplace */
1319 0xfff, /* src_mask */
1320 0xfff, /* dst_mask */
1321 FALSE), /* pcrel_offset */
1323 HOWTO (AARCH64_R (TLSDESC_LD_PREL19), /* type */
1325 2, /* size (0 = byte, 1 = short, 2 = long) */
1327 TRUE, /* pc_relative */
1329 complain_overflow_dont, /* complain_on_overflow */
1330 bfd_elf_generic_reloc, /* special_function */
1331 AARCH64_R_STR (TLSDESC_LD_PREL19), /* name */
1332 FALSE, /* partial_inplace */
1333 0x0ffffe0, /* src_mask */
1334 0x0ffffe0, /* dst_mask */
1335 TRUE), /* pcrel_offset */
1337 HOWTO (AARCH64_R (TLSDESC_ADR_PREL21), /* type */
1339 2, /* size (0 = byte, 1 = short, 2 = long) */
1341 TRUE, /* pc_relative */
1343 complain_overflow_dont, /* complain_on_overflow */
1344 bfd_elf_generic_reloc, /* special_function */
1345 AARCH64_R_STR (TLSDESC_ADR_PREL21), /* name */
1346 FALSE, /* partial_inplace */
1347 0x1fffff, /* src_mask */
1348 0x1fffff, /* dst_mask */
1349 TRUE), /* pcrel_offset */
1351 /* Get to the page for the GOT entry for the symbol
1352 (G(S) - P) using an ADRP instruction. */
1353 HOWTO (AARCH64_R (TLSDESC_ADR_PAGE21), /* type */
1354 12, /* rightshift */
1355 2, /* size (0 = byte, 1 = short, 2 = long) */
1357 TRUE, /* pc_relative */
1359 complain_overflow_dont, /* complain_on_overflow */
1360 bfd_elf_generic_reloc, /* special_function */
1361 AARCH64_R_STR (TLSDESC_ADR_PAGE21), /* name */
1362 FALSE, /* partial_inplace */
1363 0x1fffff, /* src_mask */
1364 0x1fffff, /* dst_mask */
1365 TRUE), /* pcrel_offset */
1367 /* LD64: GOT offset G(S) & 0xff8. */
1368 HOWTO64 (AARCH64_R (TLSDESC_LD64_LO12_NC), /* type */
1370 2, /* size (0 = byte, 1 = short, 2 = long) */
1372 FALSE, /* pc_relative */
1374 complain_overflow_dont, /* complain_on_overflow */
1375 bfd_elf_generic_reloc, /* special_function */
1376 AARCH64_R_STR (TLSDESC_LD64_LO12_NC), /* name */
1377 FALSE, /* partial_inplace */
1378 0xff8, /* src_mask */
1379 0xff8, /* dst_mask */
1380 FALSE), /* pcrel_offset */
1382 /* LD32: GOT offset G(S) & 0xffc. */
1383 HOWTO32 (AARCH64_R (TLSDESC_LD32_LO12_NC), /* type */
1385 2, /* size (0 = byte, 1 = short, 2 = long) */
1387 FALSE, /* pc_relative */
1389 complain_overflow_dont, /* complain_on_overflow */
1390 bfd_elf_generic_reloc, /* special_function */
1391 AARCH64_R_STR (TLSDESC_LD32_LO12_NC), /* name */
1392 FALSE, /* partial_inplace */
1393 0xffc, /* src_mask */
1394 0xffc, /* dst_mask */
1395 FALSE), /* pcrel_offset */
1397 /* ADD: GOT offset G(S) & 0xfff. */
1398 HOWTO (AARCH64_R (TLSDESC_ADD_LO12_NC), /* type */
1400 2, /* size (0 = byte, 1 = short, 2 = long) */
1402 FALSE, /* pc_relative */
1404 complain_overflow_dont, /* complain_on_overflow */
1405 bfd_elf_generic_reloc, /* special_function */
1406 AARCH64_R_STR (TLSDESC_ADD_LO12_NC), /* name */
1407 FALSE, /* partial_inplace */
1408 0xfff, /* src_mask */
1409 0xfff, /* dst_mask */
1410 FALSE), /* pcrel_offset */
1412 HOWTO64 (AARCH64_R (TLSDESC_OFF_G1), /* type */
1413 16, /* rightshift */
1414 2, /* size (0 = byte, 1 = short, 2 = long) */
1416 FALSE, /* pc_relative */
1418 complain_overflow_dont, /* complain_on_overflow */
1419 bfd_elf_generic_reloc, /* special_function */
1420 AARCH64_R_STR (TLSDESC_OFF_G1), /* name */
1421 FALSE, /* partial_inplace */
1422 0xffff, /* src_mask */
1423 0xffff, /* dst_mask */
1424 FALSE), /* pcrel_offset */
1426 HOWTO64 (AARCH64_R (TLSDESC_OFF_G0_NC), /* type */
1428 2, /* size (0 = byte, 1 = short, 2 = long) */
1430 FALSE, /* pc_relative */
1432 complain_overflow_dont, /* complain_on_overflow */
1433 bfd_elf_generic_reloc, /* special_function */
1434 AARCH64_R_STR (TLSDESC_OFF_G0_NC), /* name */
1435 FALSE, /* partial_inplace */
1436 0xffff, /* src_mask */
1437 0xffff, /* dst_mask */
1438 FALSE), /* pcrel_offset */
1440 HOWTO64 (AARCH64_R (TLSDESC_LDR), /* type */
1442 2, /* size (0 = byte, 1 = short, 2 = long) */
1444 FALSE, /* pc_relative */
1446 complain_overflow_dont, /* complain_on_overflow */
1447 bfd_elf_generic_reloc, /* special_function */
1448 AARCH64_R_STR (TLSDESC_LDR), /* name */
1449 FALSE, /* partial_inplace */
1452 FALSE), /* pcrel_offset */
1454 HOWTO64 (AARCH64_R (TLSDESC_ADD), /* type */
1456 2, /* size (0 = byte, 1 = short, 2 = long) */
1458 FALSE, /* pc_relative */
1460 complain_overflow_dont, /* complain_on_overflow */
1461 bfd_elf_generic_reloc, /* special_function */
1462 AARCH64_R_STR (TLSDESC_ADD), /* name */
1463 FALSE, /* partial_inplace */
1466 FALSE), /* pcrel_offset */
1468 HOWTO (AARCH64_R (TLSDESC_CALL), /* type */
1470 2, /* size (0 = byte, 1 = short, 2 = long) */
1472 FALSE, /* pc_relative */
1474 complain_overflow_dont, /* complain_on_overflow */
1475 bfd_elf_generic_reloc, /* special_function */
1476 AARCH64_R_STR (TLSDESC_CALL), /* name */
1477 FALSE, /* partial_inplace */
1480 FALSE), /* pcrel_offset */
1482 HOWTO (AARCH64_R (COPY), /* type */
1484 2, /* size (0 = byte, 1 = short, 2 = long) */
1486 FALSE, /* pc_relative */
1488 complain_overflow_bitfield, /* complain_on_overflow */
1489 bfd_elf_generic_reloc, /* special_function */
1490 AARCH64_R_STR (COPY), /* name */
1491 TRUE, /* partial_inplace */
1492 0xffffffff, /* src_mask */
1493 0xffffffff, /* dst_mask */
1494 FALSE), /* pcrel_offset */
1496 HOWTO (AARCH64_R (GLOB_DAT), /* type */
1498 2, /* size (0 = byte, 1 = short, 2 = long) */
1500 FALSE, /* pc_relative */
1502 complain_overflow_bitfield, /* complain_on_overflow */
1503 bfd_elf_generic_reloc, /* special_function */
1504 AARCH64_R_STR (GLOB_DAT), /* name */
1505 TRUE, /* partial_inplace */
1506 0xffffffff, /* src_mask */
1507 0xffffffff, /* dst_mask */
1508 FALSE), /* pcrel_offset */
1510 HOWTO (AARCH64_R (JUMP_SLOT), /* type */
1512 2, /* size (0 = byte, 1 = short, 2 = long) */
1514 FALSE, /* pc_relative */
1516 complain_overflow_bitfield, /* complain_on_overflow */
1517 bfd_elf_generic_reloc, /* special_function */
1518 AARCH64_R_STR (JUMP_SLOT), /* name */
1519 TRUE, /* partial_inplace */
1520 0xffffffff, /* src_mask */
1521 0xffffffff, /* dst_mask */
1522 FALSE), /* pcrel_offset */
1524 HOWTO (AARCH64_R (RELATIVE), /* type */
1526 2, /* size (0 = byte, 1 = short, 2 = long) */
1528 FALSE, /* pc_relative */
1530 complain_overflow_bitfield, /* complain_on_overflow */
1531 bfd_elf_generic_reloc, /* special_function */
1532 AARCH64_R_STR (RELATIVE), /* name */
1533 TRUE, /* partial_inplace */
1534 ALL_ONES, /* src_mask */
1535 ALL_ONES, /* dst_mask */
1536 FALSE), /* pcrel_offset */
1538 HOWTO (AARCH64_R (TLS_DTPMOD), /* type */
1540 2, /* size (0 = byte, 1 = short, 2 = long) */
1542 FALSE, /* pc_relative */
1544 complain_overflow_dont, /* complain_on_overflow */
1545 bfd_elf_generic_reloc, /* special_function */
1547 AARCH64_R_STR (TLS_DTPMOD64), /* name */
1549 AARCH64_R_STR (TLS_DTPMOD), /* name */
1551 FALSE, /* partial_inplace */
1553 ALL_ONES, /* dst_mask */
1554 FALSE), /* pc_reloffset */
1556 HOWTO (AARCH64_R (TLS_DTPREL), /* type */
1558 2, /* size (0 = byte, 1 = short, 2 = long) */
1560 FALSE, /* pc_relative */
1562 complain_overflow_dont, /* complain_on_overflow */
1563 bfd_elf_generic_reloc, /* special_function */
1565 AARCH64_R_STR (TLS_DTPREL64), /* name */
1567 AARCH64_R_STR (TLS_DTPREL), /* name */
1569 FALSE, /* partial_inplace */
1571 ALL_ONES, /* dst_mask */
1572 FALSE), /* pcrel_offset */
1574 HOWTO (AARCH64_R (TLS_TPREL), /* type */
1576 2, /* size (0 = byte, 1 = short, 2 = long) */
1578 FALSE, /* pc_relative */
1580 complain_overflow_dont, /* complain_on_overflow */
1581 bfd_elf_generic_reloc, /* special_function */
1583 AARCH64_R_STR (TLS_TPREL64), /* name */
1585 AARCH64_R_STR (TLS_TPREL), /* name */
1587 FALSE, /* partial_inplace */
1589 ALL_ONES, /* dst_mask */
1590 FALSE), /* pcrel_offset */
1592 HOWTO (AARCH64_R (TLSDESC), /* type */
1594 2, /* size (0 = byte, 1 = short, 2 = long) */
1596 FALSE, /* pc_relative */
1598 complain_overflow_dont, /* complain_on_overflow */
1599 bfd_elf_generic_reloc, /* special_function */
1600 AARCH64_R_STR (TLSDESC), /* name */
1601 FALSE, /* partial_inplace */
1603 ALL_ONES, /* dst_mask */
1604 FALSE), /* pcrel_offset */
1606 HOWTO (AARCH64_R (IRELATIVE), /* type */
1608 2, /* size (0 = byte, 1 = short, 2 = long) */
1610 FALSE, /* pc_relative */
1612 complain_overflow_bitfield, /* complain_on_overflow */
1613 bfd_elf_generic_reloc, /* special_function */
1614 AARCH64_R_STR (IRELATIVE), /* name */
1615 FALSE, /* partial_inplace */
1617 ALL_ONES, /* dst_mask */
1618 FALSE), /* pcrel_offset */
1623 static reloc_howto_type elfNN_aarch64_howto_none =
1624 HOWTO (R_AARCH64_NONE, /* type */
1626 3, /* size (0 = byte, 1 = short, 2 = long) */
1628 FALSE, /* pc_relative */
1630 complain_overflow_dont,/* complain_on_overflow */
1631 bfd_elf_generic_reloc, /* special_function */
1632 "R_AARCH64_NONE", /* name */
1633 FALSE, /* partial_inplace */
1636 FALSE); /* pcrel_offset */
1638 /* Given HOWTO, return the bfd internal relocation enumerator. */
1640 static bfd_reloc_code_real_type
1641 elfNN_aarch64_bfd_reloc_from_howto (reloc_howto_type *howto)
1644 = (int) ARRAY_SIZE (elfNN_aarch64_howto_table);
1645 const ptrdiff_t offset
1646 = howto - elfNN_aarch64_howto_table;
1648 if (offset > 0 && offset < size - 1)
1649 return BFD_RELOC_AARCH64_RELOC_START + offset;
1651 if (howto == &elfNN_aarch64_howto_none)
1652 return BFD_RELOC_AARCH64_NONE;
1654 return BFD_RELOC_AARCH64_RELOC_START;
1657 /* Given R_TYPE, return the bfd internal relocation enumerator. */
1659 static bfd_reloc_code_real_type
1660 elfNN_aarch64_bfd_reloc_from_type (unsigned int r_type)
1662 static bfd_boolean initialized_p = FALSE;
1663 /* Indexed by R_TYPE, values are offsets in the howto_table. */
1664 static unsigned int offsets[R_AARCH64_end];
1666 if (initialized_p == FALSE)
1670 for (i = 1; i < ARRAY_SIZE (elfNN_aarch64_howto_table) - 1; ++i)
1671 if (elfNN_aarch64_howto_table[i].type != 0)
1672 offsets[elfNN_aarch64_howto_table[i].type] = i;
1674 initialized_p = TRUE;
1677 if (r_type == R_AARCH64_NONE || r_type == R_AARCH64_NULL)
1678 return BFD_RELOC_AARCH64_NONE;
1680 /* PR 17512: file: b371e70a. */
1681 if (r_type >= R_AARCH64_end)
1683 _bfd_error_handler (_("Invalid AArch64 reloc number: %d"), r_type);
1684 bfd_set_error (bfd_error_bad_value);
1685 return BFD_RELOC_AARCH64_NONE;
1688 return BFD_RELOC_AARCH64_RELOC_START + offsets[r_type];
1691 struct elf_aarch64_reloc_map
1693 bfd_reloc_code_real_type from;
1694 bfd_reloc_code_real_type to;
1697 /* Map bfd generic reloc to AArch64-specific reloc. */
1698 static const struct elf_aarch64_reloc_map elf_aarch64_reloc_map[] =
1700 {BFD_RELOC_NONE, BFD_RELOC_AARCH64_NONE},
1702 /* Basic data relocations. */
1703 {BFD_RELOC_CTOR, BFD_RELOC_AARCH64_NN},
1704 {BFD_RELOC_64, BFD_RELOC_AARCH64_64},
1705 {BFD_RELOC_32, BFD_RELOC_AARCH64_32},
1706 {BFD_RELOC_16, BFD_RELOC_AARCH64_16},
1707 {BFD_RELOC_64_PCREL, BFD_RELOC_AARCH64_64_PCREL},
1708 {BFD_RELOC_32_PCREL, BFD_RELOC_AARCH64_32_PCREL},
1709 {BFD_RELOC_16_PCREL, BFD_RELOC_AARCH64_16_PCREL},
1712 /* Given the bfd internal relocation enumerator in CODE, return the
1713 corresponding howto entry. */
1715 static reloc_howto_type *
1716 elfNN_aarch64_howto_from_bfd_reloc (bfd_reloc_code_real_type code)
1720 /* Convert bfd generic reloc to AArch64-specific reloc. */
1721 if (code < BFD_RELOC_AARCH64_RELOC_START
1722 || code > BFD_RELOC_AARCH64_RELOC_END)
1723 for (i = 0; i < ARRAY_SIZE (elf_aarch64_reloc_map); i++)
1724 if (elf_aarch64_reloc_map[i].from == code)
1726 code = elf_aarch64_reloc_map[i].to;
1730 if (code > BFD_RELOC_AARCH64_RELOC_START
1731 && code < BFD_RELOC_AARCH64_RELOC_END)
1732 if (elfNN_aarch64_howto_table[code - BFD_RELOC_AARCH64_RELOC_START].type)
1733 return &elfNN_aarch64_howto_table[code - BFD_RELOC_AARCH64_RELOC_START];
1735 if (code == BFD_RELOC_AARCH64_NONE)
1736 return &elfNN_aarch64_howto_none;
1741 static reloc_howto_type *
1742 elfNN_aarch64_howto_from_type (unsigned int r_type)
1744 bfd_reloc_code_real_type val;
1745 reloc_howto_type *howto;
1750 bfd_set_error (bfd_error_bad_value);
1755 if (r_type == R_AARCH64_NONE)
1756 return &elfNN_aarch64_howto_none;
1758 val = elfNN_aarch64_bfd_reloc_from_type (r_type);
1759 howto = elfNN_aarch64_howto_from_bfd_reloc (val);
1764 bfd_set_error (bfd_error_bad_value);
1769 elfNN_aarch64_info_to_howto (bfd *abfd ATTRIBUTE_UNUSED, arelent *bfd_reloc,
1770 Elf_Internal_Rela *elf_reloc)
1772 unsigned int r_type;
1774 r_type = ELFNN_R_TYPE (elf_reloc->r_info);
1775 bfd_reloc->howto = elfNN_aarch64_howto_from_type (r_type);
1778 static reloc_howto_type *
1779 elfNN_aarch64_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED,
1780 bfd_reloc_code_real_type code)
1782 reloc_howto_type *howto = elfNN_aarch64_howto_from_bfd_reloc (code);
1787 bfd_set_error (bfd_error_bad_value);
1791 static reloc_howto_type *
1792 elfNN_aarch64_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED,
1797 for (i = 1; i < ARRAY_SIZE (elfNN_aarch64_howto_table) - 1; ++i)
1798 if (elfNN_aarch64_howto_table[i].name != NULL
1799 && strcasecmp (elfNN_aarch64_howto_table[i].name, r_name) == 0)
1800 return &elfNN_aarch64_howto_table[i];
1805 #define TARGET_LITTLE_SYM aarch64_elfNN_le_vec
1806 #define TARGET_LITTLE_NAME "elfNN-littleaarch64"
1807 #define TARGET_BIG_SYM aarch64_elfNN_be_vec
1808 #define TARGET_BIG_NAME "elfNN-bigaarch64"
1810 /* The linker script knows the section names for placement.
1811 The entry_names are used to do simple name mangling on the stubs.
1812 Given a function name, and its type, the stub can be found. The
1813 name can be changed. The only requirement is the %s be present. */
1814 #define STUB_ENTRY_NAME "__%s_veneer"
1816 /* The name of the dynamic interpreter. This is put in the .interp
1818 #define ELF_DYNAMIC_INTERPRETER "/lib/ld.so.1"
1820 #define AARCH64_MAX_FWD_BRANCH_OFFSET \
1821 (((1 << 25) - 1) << 2)
1822 #define AARCH64_MAX_BWD_BRANCH_OFFSET \
1825 #define AARCH64_MAX_ADRP_IMM ((1 << 20) - 1)
1826 #define AARCH64_MIN_ADRP_IMM (-(1 << 20))
1829 aarch64_valid_for_adrp_p (bfd_vma value, bfd_vma place)
1831 bfd_signed_vma offset = (bfd_signed_vma) (PG (value) - PG (place)) >> 12;
1832 return offset <= AARCH64_MAX_ADRP_IMM && offset >= AARCH64_MIN_ADRP_IMM;
1836 aarch64_valid_branch_p (bfd_vma value, bfd_vma place)
1838 bfd_signed_vma offset = (bfd_signed_vma) (value - place);
1839 return (offset <= AARCH64_MAX_FWD_BRANCH_OFFSET
1840 && offset >= AARCH64_MAX_BWD_BRANCH_OFFSET);
1843 static const uint32_t aarch64_adrp_branch_stub [] =
1845 0x90000010, /* adrp ip0, X */
1846 /* R_AARCH64_ADR_HI21_PCREL(X) */
1847 0x91000210, /* add ip0, ip0, :lo12:X */
1848 /* R_AARCH64_ADD_ABS_LO12_NC(X) */
1849 0xd61f0200, /* br ip0 */
1852 static const uint32_t aarch64_long_branch_stub[] =
1855 0x58000090, /* ldr ip0, 1f */
1857 0x18000090, /* ldr wip0, 1f */
1859 0x10000011, /* adr ip1, #0 */
1860 0x8b110210, /* add ip0, ip0, ip1 */
1861 0xd61f0200, /* br ip0 */
1862 0x00000000, /* 1: .xword or .word
1863 R_AARCH64_PRELNN(X) + 12
1868 static const uint32_t aarch64_erratum_835769_stub[] =
1870 0x00000000, /* Placeholder for multiply accumulate. */
1871 0x14000000, /* b <label> */
1874 static const uint32_t aarch64_erratum_843419_stub[] =
1876 0x00000000, /* Placeholder for LDR instruction. */
1877 0x14000000, /* b <label> */
1880 /* Section name for stubs is the associated section name plus this
1882 #define STUB_SUFFIX ".stub"
1884 enum elf_aarch64_stub_type
1887 aarch64_stub_adrp_branch,
1888 aarch64_stub_long_branch,
1889 aarch64_stub_erratum_835769_veneer,
1890 aarch64_stub_erratum_843419_veneer,
1893 struct elf_aarch64_stub_hash_entry
1895 /* Base hash table entry structure. */
1896 struct bfd_hash_entry root;
1898 /* The stub section. */
1901 /* Offset within stub_sec of the beginning of this stub. */
1902 bfd_vma stub_offset;
1904 /* Given the symbol's value and its section we can determine its final
1905 value when building the stubs (so the stub knows where to jump). */
1906 bfd_vma target_value;
1907 asection *target_section;
1909 enum elf_aarch64_stub_type stub_type;
1911 /* The symbol table entry, if any, that this was derived from. */
1912 struct elf_aarch64_link_hash_entry *h;
1914 /* Destination symbol type */
1915 unsigned char st_type;
1917 /* Where this stub is being called from, or, in the case of combined
1918 stub sections, the first input section in the group. */
1921 /* The name for the local symbol at the start of this stub. The
1922 stub name in the hash table has to be unique; this does not, so
1923 it can be friendlier. */
1926 /* The instruction which caused this stub to be generated (only valid for
1927 erratum 835769 workaround stubs at present). */
1928 uint32_t veneered_insn;
1930 /* In an erratum 843419 workaround stub, the ADRP instruction offset. */
1931 bfd_vma adrp_offset;
1934 /* Used to build a map of a section. This is required for mixed-endian
1937 typedef struct elf_elf_section_map
1942 elf_aarch64_section_map;
1945 typedef struct _aarch64_elf_section_data
1947 struct bfd_elf_section_data elf;
1948 unsigned int mapcount;
1949 unsigned int mapsize;
1950 elf_aarch64_section_map *map;
1952 _aarch64_elf_section_data;
1954 #define elf_aarch64_section_data(sec) \
1955 ((_aarch64_elf_section_data *) elf_section_data (sec))
1957 /* The size of the thread control block which is defined to be two pointers. */
1958 #define TCB_SIZE (ARCH_SIZE/8)*2
1960 struct elf_aarch64_local_symbol
1962 unsigned int got_type;
1963 bfd_signed_vma got_refcount;
1966 /* Offset of the GOTPLT entry reserved for the TLS descriptor. The
1967 offset is from the end of the jump table and reserved entries
1970 The magic value (bfd_vma) -1 indicates that an offset has not be
1972 bfd_vma tlsdesc_got_jump_table_offset;
1975 struct elf_aarch64_obj_tdata
1977 struct elf_obj_tdata root;
1979 /* local symbol descriptors */
1980 struct elf_aarch64_local_symbol *locals;
1982 /* Zero to warn when linking objects with incompatible enum sizes. */
1983 int no_enum_size_warning;
1985 /* Zero to warn when linking objects with incompatible wchar_t sizes. */
1986 int no_wchar_size_warning;
1989 #define elf_aarch64_tdata(bfd) \
1990 ((struct elf_aarch64_obj_tdata *) (bfd)->tdata.any)
1992 #define elf_aarch64_locals(bfd) (elf_aarch64_tdata (bfd)->locals)
1994 #define is_aarch64_elf(bfd) \
1995 (bfd_get_flavour (bfd) == bfd_target_elf_flavour \
1996 && elf_tdata (bfd) != NULL \
1997 && elf_object_id (bfd) == AARCH64_ELF_DATA)
2000 elfNN_aarch64_mkobject (bfd *abfd)
2002 return bfd_elf_allocate_object (abfd, sizeof (struct elf_aarch64_obj_tdata),
2006 #define elf_aarch64_hash_entry(ent) \
2007 ((struct elf_aarch64_link_hash_entry *)(ent))
2009 #define GOT_UNKNOWN 0
2010 #define GOT_NORMAL 1
2011 #define GOT_TLS_GD 2
2012 #define GOT_TLS_IE 4
2013 #define GOT_TLSDESC_GD 8
2015 #define GOT_TLS_GD_ANY_P(type) ((type & GOT_TLS_GD) || (type & GOT_TLSDESC_GD))
2017 /* AArch64 ELF linker hash entry. */
2018 struct elf_aarch64_link_hash_entry
2020 struct elf_link_hash_entry root;
2022 /* Track dynamic relocs copied for this symbol. */
2023 struct elf_dyn_relocs *dyn_relocs;
2025 /* Since PLT entries have variable size, we need to record the
2026 index into .got.plt instead of recomputing it from the PLT
2028 bfd_signed_vma plt_got_offset;
2030 /* Bit mask representing the type of GOT entry(s) if any required by
2032 unsigned int got_type;
2034 /* A pointer to the most recently used stub hash entry against this
2036 struct elf_aarch64_stub_hash_entry *stub_cache;
2038 /* Offset of the GOTPLT entry reserved for the TLS descriptor. The offset
2039 is from the end of the jump table and reserved entries within the PLTGOT.
2041 The magic value (bfd_vma) -1 indicates that an offset has not
2043 bfd_vma tlsdesc_got_jump_table_offset;
2047 elfNN_aarch64_symbol_got_type (struct elf_link_hash_entry *h,
2049 unsigned long r_symndx)
2052 return elf_aarch64_hash_entry (h)->got_type;
2054 if (! elf_aarch64_locals (abfd))
2057 return elf_aarch64_locals (abfd)[r_symndx].got_type;
2060 /* Get the AArch64 elf linker hash table from a link_info structure. */
2061 #define elf_aarch64_hash_table(info) \
2062 ((struct elf_aarch64_link_hash_table *) ((info)->hash))
2064 #define aarch64_stub_hash_lookup(table, string, create, copy) \
2065 ((struct elf_aarch64_stub_hash_entry *) \
2066 bfd_hash_lookup ((table), (string), (create), (copy)))
2068 /* AArch64 ELF linker hash table. */
2069 struct elf_aarch64_link_hash_table
2071 /* The main hash table. */
2072 struct elf_link_hash_table root;
2074 /* Nonzero to force PIC branch veneers. */
2077 /* Fix erratum 835769. */
2078 int fix_erratum_835769;
2080 /* Fix erratum 843419. */
2081 int fix_erratum_843419;
2083 /* Enable ADRP->ADR rewrite for erratum 843419 workaround. */
2084 int fix_erratum_843419_adr;
2086 /* The number of bytes in the initial entry in the PLT. */
2087 bfd_size_type plt_header_size;
2089 /* The number of bytes in the subsequent PLT etries. */
2090 bfd_size_type plt_entry_size;
2092 /* Short-cuts to get to dynamic linker sections. */
2096 /* Small local sym cache. */
2097 struct sym_cache sym_cache;
2099 /* For convenience in allocate_dynrelocs. */
2102 /* The amount of space used by the reserved portion of the sgotplt
2103 section, plus whatever space is used by the jump slots. */
2104 bfd_vma sgotplt_jump_table_size;
2106 /* The stub hash table. */
2107 struct bfd_hash_table stub_hash_table;
2109 /* Linker stub bfd. */
2112 /* Linker call-backs. */
2113 asection *(*add_stub_section) (const char *, asection *);
2114 void (*layout_sections_again) (void);
2116 /* Array to keep track of which stub sections have been created, and
2117 information on stub grouping. */
2120 /* This is the section to which stubs in the group will be
2123 /* The stub section. */
2127 /* Assorted information used by elfNN_aarch64_size_stubs. */
2128 unsigned int bfd_count;
2130 asection **input_list;
2132 /* The offset into splt of the PLT entry for the TLS descriptor
2133 resolver. Special values are 0, if not necessary (or not found
2134 to be necessary yet), and -1 if needed but not determined
2136 bfd_vma tlsdesc_plt;
2138 /* The GOT offset for the lazy trampoline. Communicated to the
2139 loader via DT_TLSDESC_GOT. The magic value (bfd_vma) -1
2140 indicates an offset is not allocated. */
2141 bfd_vma dt_tlsdesc_got;
2143 /* Used by local STT_GNU_IFUNC symbols. */
2144 htab_t loc_hash_table;
2145 void * loc_hash_memory;
2148 /* Create an entry in an AArch64 ELF linker hash table. */
2150 static struct bfd_hash_entry *
2151 elfNN_aarch64_link_hash_newfunc (struct bfd_hash_entry *entry,
2152 struct bfd_hash_table *table,
2155 struct elf_aarch64_link_hash_entry *ret =
2156 (struct elf_aarch64_link_hash_entry *) entry;
2158 /* Allocate the structure if it has not already been allocated by a
2161 ret = bfd_hash_allocate (table,
2162 sizeof (struct elf_aarch64_link_hash_entry));
2164 return (struct bfd_hash_entry *) ret;
2166 /* Call the allocation method of the superclass. */
2167 ret = ((struct elf_aarch64_link_hash_entry *)
2168 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry *) ret,
2172 ret->dyn_relocs = NULL;
2173 ret->got_type = GOT_UNKNOWN;
2174 ret->plt_got_offset = (bfd_vma) - 1;
2175 ret->stub_cache = NULL;
2176 ret->tlsdesc_got_jump_table_offset = (bfd_vma) - 1;
2179 return (struct bfd_hash_entry *) ret;
2182 /* Initialize an entry in the stub hash table. */
2184 static struct bfd_hash_entry *
2185 stub_hash_newfunc (struct bfd_hash_entry *entry,
2186 struct bfd_hash_table *table, const char *string)
2188 /* Allocate the structure if it has not already been allocated by a
2192 entry = bfd_hash_allocate (table,
2194 elf_aarch64_stub_hash_entry));
2199 /* Call the allocation method of the superclass. */
2200 entry = bfd_hash_newfunc (entry, table, string);
2203 struct elf_aarch64_stub_hash_entry *eh;
2205 /* Initialize the local fields. */
2206 eh = (struct elf_aarch64_stub_hash_entry *) entry;
2207 eh->adrp_offset = 0;
2208 eh->stub_sec = NULL;
2209 eh->stub_offset = 0;
2210 eh->target_value = 0;
2211 eh->target_section = NULL;
2212 eh->stub_type = aarch64_stub_none;
2220 /* Compute a hash of a local hash entry. We use elf_link_hash_entry
2221 for local symbol so that we can handle local STT_GNU_IFUNC symbols
2222 as global symbol. We reuse indx and dynstr_index for local symbol
2223 hash since they aren't used by global symbols in this backend. */
2226 elfNN_aarch64_local_htab_hash (const void *ptr)
2228 struct elf_link_hash_entry *h
2229 = (struct elf_link_hash_entry *) ptr;
2230 return ELF_LOCAL_SYMBOL_HASH (h->indx, h->dynstr_index);
2233 /* Compare local hash entries. */
2236 elfNN_aarch64_local_htab_eq (const void *ptr1, const void *ptr2)
2238 struct elf_link_hash_entry *h1
2239 = (struct elf_link_hash_entry *) ptr1;
2240 struct elf_link_hash_entry *h2
2241 = (struct elf_link_hash_entry *) ptr2;
2243 return h1->indx == h2->indx && h1->dynstr_index == h2->dynstr_index;
2246 /* Find and/or create a hash entry for local symbol. */
2248 static struct elf_link_hash_entry *
2249 elfNN_aarch64_get_local_sym_hash (struct elf_aarch64_link_hash_table *htab,
2250 bfd *abfd, const Elf_Internal_Rela *rel,
2253 struct elf_aarch64_link_hash_entry e, *ret;
2254 asection *sec = abfd->sections;
2255 hashval_t h = ELF_LOCAL_SYMBOL_HASH (sec->id,
2256 ELFNN_R_SYM (rel->r_info));
2259 e.root.indx = sec->id;
2260 e.root.dynstr_index = ELFNN_R_SYM (rel->r_info);
2261 slot = htab_find_slot_with_hash (htab->loc_hash_table, &e, h,
2262 create ? INSERT : NO_INSERT);
2269 ret = (struct elf_aarch64_link_hash_entry *) *slot;
2273 ret = (struct elf_aarch64_link_hash_entry *)
2274 objalloc_alloc ((struct objalloc *) htab->loc_hash_memory,
2275 sizeof (struct elf_aarch64_link_hash_entry));
2278 memset (ret, 0, sizeof (*ret));
2279 ret->root.indx = sec->id;
2280 ret->root.dynstr_index = ELFNN_R_SYM (rel->r_info);
2281 ret->root.dynindx = -1;
2287 /* Copy the extra info we tack onto an elf_link_hash_entry. */
2290 elfNN_aarch64_copy_indirect_symbol (struct bfd_link_info *info,
2291 struct elf_link_hash_entry *dir,
2292 struct elf_link_hash_entry *ind)
2294 struct elf_aarch64_link_hash_entry *edir, *eind;
2296 edir = (struct elf_aarch64_link_hash_entry *) dir;
2297 eind = (struct elf_aarch64_link_hash_entry *) ind;
2299 if (eind->dyn_relocs != NULL)
2301 if (edir->dyn_relocs != NULL)
2303 struct elf_dyn_relocs **pp;
2304 struct elf_dyn_relocs *p;
2306 /* Add reloc counts against the indirect sym to the direct sym
2307 list. Merge any entries against the same section. */
2308 for (pp = &eind->dyn_relocs; (p = *pp) != NULL;)
2310 struct elf_dyn_relocs *q;
2312 for (q = edir->dyn_relocs; q != NULL; q = q->next)
2313 if (q->sec == p->sec)
2315 q->pc_count += p->pc_count;
2316 q->count += p->count;
2323 *pp = edir->dyn_relocs;
2326 edir->dyn_relocs = eind->dyn_relocs;
2327 eind->dyn_relocs = NULL;
2330 if (ind->root.type == bfd_link_hash_indirect)
2332 /* Copy over PLT info. */
2333 if (dir->got.refcount <= 0)
2335 edir->got_type = eind->got_type;
2336 eind->got_type = GOT_UNKNOWN;
2340 _bfd_elf_link_hash_copy_indirect (info, dir, ind);
2343 /* Destroy an AArch64 elf linker hash table. */
2346 elfNN_aarch64_link_hash_table_free (bfd *obfd)
2348 struct elf_aarch64_link_hash_table *ret
2349 = (struct elf_aarch64_link_hash_table *) obfd->link.hash;
2351 if (ret->loc_hash_table)
2352 htab_delete (ret->loc_hash_table);
2353 if (ret->loc_hash_memory)
2354 objalloc_free ((struct objalloc *) ret->loc_hash_memory);
2356 bfd_hash_table_free (&ret->stub_hash_table);
2357 _bfd_elf_link_hash_table_free (obfd);
2360 /* Create an AArch64 elf linker hash table. */
2362 static struct bfd_link_hash_table *
2363 elfNN_aarch64_link_hash_table_create (bfd *abfd)
2365 struct elf_aarch64_link_hash_table *ret;
2366 bfd_size_type amt = sizeof (struct elf_aarch64_link_hash_table);
2368 ret = bfd_zmalloc (amt);
2372 if (!_bfd_elf_link_hash_table_init
2373 (&ret->root, abfd, elfNN_aarch64_link_hash_newfunc,
2374 sizeof (struct elf_aarch64_link_hash_entry), AARCH64_ELF_DATA))
2380 ret->plt_header_size = PLT_ENTRY_SIZE;
2381 ret->plt_entry_size = PLT_SMALL_ENTRY_SIZE;
2383 ret->dt_tlsdesc_got = (bfd_vma) - 1;
2385 if (!bfd_hash_table_init (&ret->stub_hash_table, stub_hash_newfunc,
2386 sizeof (struct elf_aarch64_stub_hash_entry)))
2388 _bfd_elf_link_hash_table_free (abfd);
2392 ret->loc_hash_table = htab_try_create (1024,
2393 elfNN_aarch64_local_htab_hash,
2394 elfNN_aarch64_local_htab_eq,
2396 ret->loc_hash_memory = objalloc_create ();
2397 if (!ret->loc_hash_table || !ret->loc_hash_memory)
2399 elfNN_aarch64_link_hash_table_free (abfd);
2402 ret->root.root.hash_table_free = elfNN_aarch64_link_hash_table_free;
2404 return &ret->root.root;
2408 aarch64_relocate (unsigned int r_type, bfd *input_bfd, asection *input_section,
2409 bfd_vma offset, bfd_vma value)
2411 reloc_howto_type *howto;
2414 howto = elfNN_aarch64_howto_from_type (r_type);
2415 place = (input_section->output_section->vma + input_section->output_offset
2418 r_type = elfNN_aarch64_bfd_reloc_from_type (r_type);
2419 value = _bfd_aarch64_elf_resolve_relocation (r_type, place, value, 0, FALSE);
2420 return _bfd_aarch64_elf_put_addend (input_bfd,
2421 input_section->contents + offset, r_type,
2425 static enum elf_aarch64_stub_type
2426 aarch64_select_branch_stub (bfd_vma value, bfd_vma place)
2428 if (aarch64_valid_for_adrp_p (value, place))
2429 return aarch64_stub_adrp_branch;
2430 return aarch64_stub_long_branch;
2433 /* Determine the type of stub needed, if any, for a call. */
2435 static enum elf_aarch64_stub_type
2436 aarch64_type_of_stub (struct bfd_link_info *info,
2437 asection *input_sec,
2438 const Elf_Internal_Rela *rel,
2440 unsigned char st_type,
2441 struct elf_aarch64_link_hash_entry *hash,
2442 bfd_vma destination)
2445 bfd_signed_vma branch_offset;
2446 unsigned int r_type;
2447 struct elf_aarch64_link_hash_table *globals;
2448 enum elf_aarch64_stub_type stub_type = aarch64_stub_none;
2449 bfd_boolean via_plt_p;
2451 if (st_type != STT_FUNC
2452 && (sym_sec != bfd_abs_section_ptr))
2455 globals = elf_aarch64_hash_table (info);
2456 via_plt_p = (globals->root.splt != NULL && hash != NULL
2457 && hash->root.plt.offset != (bfd_vma) - 1);
2458 /* Make sure call to plt stub can fit into the branch range. */
2460 destination = (globals->root.splt->output_section->vma
2461 + globals->root.splt->output_offset
2462 + hash->root.plt.offset);
2464 /* Determine where the call point is. */
2465 location = (input_sec->output_offset
2466 + input_sec->output_section->vma + rel->r_offset);
2468 branch_offset = (bfd_signed_vma) (destination - location);
2470 r_type = ELFNN_R_TYPE (rel->r_info);
2472 /* We don't want to redirect any old unconditional jump in this way,
2473 only one which is being used for a sibcall, where it is
2474 acceptable for the IP0 and IP1 registers to be clobbered. */
2475 if ((r_type == AARCH64_R (CALL26) || r_type == AARCH64_R (JUMP26))
2476 && (branch_offset > AARCH64_MAX_FWD_BRANCH_OFFSET
2477 || branch_offset < AARCH64_MAX_BWD_BRANCH_OFFSET))
2479 stub_type = aarch64_stub_long_branch;
2485 /* Build a name for an entry in the stub hash table. */
2488 elfNN_aarch64_stub_name (const asection *input_section,
2489 const asection *sym_sec,
2490 const struct elf_aarch64_link_hash_entry *hash,
2491 const Elf_Internal_Rela *rel)
2498 len = 8 + 1 + strlen (hash->root.root.root.string) + 1 + 16 + 1;
2499 stub_name = bfd_malloc (len);
2500 if (stub_name != NULL)
2501 snprintf (stub_name, len, "%08x_%s+%" BFD_VMA_FMT "x",
2502 (unsigned int) input_section->id,
2503 hash->root.root.root.string,
2508 len = 8 + 1 + 8 + 1 + 8 + 1 + 16 + 1;
2509 stub_name = bfd_malloc (len);
2510 if (stub_name != NULL)
2511 snprintf (stub_name, len, "%08x_%x:%x+%" BFD_VMA_FMT "x",
2512 (unsigned int) input_section->id,
2513 (unsigned int) sym_sec->id,
2514 (unsigned int) ELFNN_R_SYM (rel->r_info),
2521 /* Look up an entry in the stub hash. Stub entries are cached because
2522 creating the stub name takes a bit of time. */
2524 static struct elf_aarch64_stub_hash_entry *
2525 elfNN_aarch64_get_stub_entry (const asection *input_section,
2526 const asection *sym_sec,
2527 struct elf_link_hash_entry *hash,
2528 const Elf_Internal_Rela *rel,
2529 struct elf_aarch64_link_hash_table *htab)
2531 struct elf_aarch64_stub_hash_entry *stub_entry;
2532 struct elf_aarch64_link_hash_entry *h =
2533 (struct elf_aarch64_link_hash_entry *) hash;
2534 const asection *id_sec;
2536 if ((input_section->flags & SEC_CODE) == 0)
2539 /* If this input section is part of a group of sections sharing one
2540 stub section, then use the id of the first section in the group.
2541 Stub names need to include a section id, as there may well be
2542 more than one stub used to reach say, printf, and we need to
2543 distinguish between them. */
2544 id_sec = htab->stub_group[input_section->id].link_sec;
2546 if (h != NULL && h->stub_cache != NULL
2547 && h->stub_cache->h == h && h->stub_cache->id_sec == id_sec)
2549 stub_entry = h->stub_cache;
2555 stub_name = elfNN_aarch64_stub_name (id_sec, sym_sec, h, rel);
2556 if (stub_name == NULL)
2559 stub_entry = aarch64_stub_hash_lookup (&htab->stub_hash_table,
2560 stub_name, FALSE, FALSE);
2562 h->stub_cache = stub_entry;
2571 /* Create a stub section. */
2574 _bfd_aarch64_create_stub_section (asection *section,
2575 struct elf_aarch64_link_hash_table *htab)
2581 namelen = strlen (section->name);
2582 len = namelen + sizeof (STUB_SUFFIX);
2583 s_name = bfd_alloc (htab->stub_bfd, len);
2587 memcpy (s_name, section->name, namelen);
2588 memcpy (s_name + namelen, STUB_SUFFIX, sizeof (STUB_SUFFIX));
2589 return (*htab->add_stub_section) (s_name, section);
2593 /* Find or create a stub section for a link section.
2595 Fix or create the stub section used to collect stubs attached to
2596 the specified link section. */
2599 _bfd_aarch64_get_stub_for_link_section (asection *link_section,
2600 struct elf_aarch64_link_hash_table *htab)
2602 if (htab->stub_group[link_section->id].stub_sec == NULL)
2603 htab->stub_group[link_section->id].stub_sec
2604 = _bfd_aarch64_create_stub_section (link_section, htab);
2605 return htab->stub_group[link_section->id].stub_sec;
2609 /* Find or create a stub section in the stub group for an input
2613 _bfd_aarch64_create_or_find_stub_sec (asection *section,
2614 struct elf_aarch64_link_hash_table *htab)
2616 asection *link_sec = htab->stub_group[section->id].link_sec;
2617 return _bfd_aarch64_get_stub_for_link_section (link_sec, htab);
2621 /* Add a new stub entry in the stub group associated with an input
2622 section to the stub hash. Not all fields of the new stub entry are
2625 static struct elf_aarch64_stub_hash_entry *
2626 _bfd_aarch64_add_stub_entry_in_group (const char *stub_name,
2628 struct elf_aarch64_link_hash_table *htab)
2632 struct elf_aarch64_stub_hash_entry *stub_entry;
2634 link_sec = htab->stub_group[section->id].link_sec;
2635 stub_sec = _bfd_aarch64_create_or_find_stub_sec (section, htab);
2637 /* Enter this entry into the linker stub hash table. */
2638 stub_entry = aarch64_stub_hash_lookup (&htab->stub_hash_table, stub_name,
2640 if (stub_entry == NULL)
2642 (*_bfd_error_handler) (_("%s: cannot create stub entry %s"),
2643 section->owner, stub_name);
2647 stub_entry->stub_sec = stub_sec;
2648 stub_entry->stub_offset = 0;
2649 stub_entry->id_sec = link_sec;
2654 /* Add a new stub entry in the final stub section to the stub hash.
2655 Not all fields of the new stub entry are initialised. */
2657 static struct elf_aarch64_stub_hash_entry *
2658 _bfd_aarch64_add_stub_entry_after (const char *stub_name,
2659 asection *link_section,
2660 struct elf_aarch64_link_hash_table *htab)
2663 struct elf_aarch64_stub_hash_entry *stub_entry;
2665 stub_sec = _bfd_aarch64_get_stub_for_link_section (link_section, htab);
2666 stub_entry = aarch64_stub_hash_lookup (&htab->stub_hash_table, stub_name,
2668 if (stub_entry == NULL)
2670 (*_bfd_error_handler) (_("cannot create stub entry %s"), stub_name);
2674 stub_entry->stub_sec = stub_sec;
2675 stub_entry->stub_offset = 0;
2676 stub_entry->id_sec = link_section;
2683 aarch64_build_one_stub (struct bfd_hash_entry *gen_entry,
2684 void *in_arg ATTRIBUTE_UNUSED)
2686 struct elf_aarch64_stub_hash_entry *stub_entry;
2691 bfd_vma veneered_insn_loc;
2692 bfd_vma veneer_entry_loc;
2693 bfd_signed_vma branch_offset = 0;
2694 unsigned int template_size;
2695 const uint32_t *template;
2698 /* Massage our args to the form they really have. */
2699 stub_entry = (struct elf_aarch64_stub_hash_entry *) gen_entry;
2701 stub_sec = stub_entry->stub_sec;
2703 /* Make a note of the offset within the stubs for this entry. */
2704 stub_entry->stub_offset = stub_sec->size;
2705 loc = stub_sec->contents + stub_entry->stub_offset;
2707 stub_bfd = stub_sec->owner;
2709 /* This is the address of the stub destination. */
2710 sym_value = (stub_entry->target_value
2711 + stub_entry->target_section->output_offset
2712 + stub_entry->target_section->output_section->vma);
2714 if (stub_entry->stub_type == aarch64_stub_long_branch)
2716 bfd_vma place = (stub_entry->stub_offset + stub_sec->output_section->vma
2717 + stub_sec->output_offset);
2719 /* See if we can relax the stub. */
2720 if (aarch64_valid_for_adrp_p (sym_value, place))
2721 stub_entry->stub_type = aarch64_select_branch_stub (sym_value, place);
2724 switch (stub_entry->stub_type)
2726 case aarch64_stub_adrp_branch:
2727 template = aarch64_adrp_branch_stub;
2728 template_size = sizeof (aarch64_adrp_branch_stub);
2730 case aarch64_stub_long_branch:
2731 template = aarch64_long_branch_stub;
2732 template_size = sizeof (aarch64_long_branch_stub);
2734 case aarch64_stub_erratum_835769_veneer:
2735 template = aarch64_erratum_835769_stub;
2736 template_size = sizeof (aarch64_erratum_835769_stub);
2738 case aarch64_stub_erratum_843419_veneer:
2739 template = aarch64_erratum_843419_stub;
2740 template_size = sizeof (aarch64_erratum_843419_stub);
2746 for (i = 0; i < (template_size / sizeof template[0]); i++)
2748 bfd_putl32 (template[i], loc);
2752 template_size = (template_size + 7) & ~7;
2753 stub_sec->size += template_size;
2755 switch (stub_entry->stub_type)
2757 case aarch64_stub_adrp_branch:
2758 if (aarch64_relocate (AARCH64_R (ADR_PREL_PG_HI21), stub_bfd, stub_sec,
2759 stub_entry->stub_offset, sym_value))
2760 /* The stub would not have been relaxed if the offset was out
2764 if (aarch64_relocate (AARCH64_R (ADD_ABS_LO12_NC), stub_bfd, stub_sec,
2765 stub_entry->stub_offset + 4, sym_value))
2769 case aarch64_stub_long_branch:
2770 /* We want the value relative to the address 12 bytes back from the
2772 if (aarch64_relocate (AARCH64_R (PRELNN), stub_bfd, stub_sec,
2773 stub_entry->stub_offset + 16, sym_value + 12))
2777 case aarch64_stub_erratum_835769_veneer:
2778 veneered_insn_loc = stub_entry->target_section->output_section->vma
2779 + stub_entry->target_section->output_offset
2780 + stub_entry->target_value;
2781 veneer_entry_loc = stub_entry->stub_sec->output_section->vma
2782 + stub_entry->stub_sec->output_offset
2783 + stub_entry->stub_offset;
2784 branch_offset = veneered_insn_loc - veneer_entry_loc;
2785 branch_offset >>= 2;
2786 branch_offset &= 0x3ffffff;
2787 bfd_putl32 (stub_entry->veneered_insn,
2788 stub_sec->contents + stub_entry->stub_offset);
2789 bfd_putl32 (template[1] | branch_offset,
2790 stub_sec->contents + stub_entry->stub_offset + 4);
2793 case aarch64_stub_erratum_843419_veneer:
2794 if (aarch64_relocate (AARCH64_R (JUMP26), stub_bfd, stub_sec,
2795 stub_entry->stub_offset + 4, sym_value + 4))
2806 /* As above, but don't actually build the stub. Just bump offset so
2807 we know stub section sizes. */
2810 aarch64_size_one_stub (struct bfd_hash_entry *gen_entry,
2811 void *in_arg ATTRIBUTE_UNUSED)
2813 struct elf_aarch64_stub_hash_entry *stub_entry;
2816 /* Massage our args to the form they really have. */
2817 stub_entry = (struct elf_aarch64_stub_hash_entry *) gen_entry;
2819 switch (stub_entry->stub_type)
2821 case aarch64_stub_adrp_branch:
2822 size = sizeof (aarch64_adrp_branch_stub);
2824 case aarch64_stub_long_branch:
2825 size = sizeof (aarch64_long_branch_stub);
2827 case aarch64_stub_erratum_835769_veneer:
2828 size = sizeof (aarch64_erratum_835769_stub);
2830 case aarch64_stub_erratum_843419_veneer:
2831 size = sizeof (aarch64_erratum_843419_stub);
2837 size = (size + 7) & ~7;
2838 stub_entry->stub_sec->size += size;
2842 /* External entry points for sizing and building linker stubs. */
2844 /* Set up various things so that we can make a list of input sections
2845 for each output section included in the link. Returns -1 on error,
2846 0 when no stubs will be needed, and 1 on success. */
2849 elfNN_aarch64_setup_section_lists (bfd *output_bfd,
2850 struct bfd_link_info *info)
2853 unsigned int bfd_count;
2854 int top_id, top_index;
2856 asection **input_list, **list;
2858 struct elf_aarch64_link_hash_table *htab =
2859 elf_aarch64_hash_table (info);
2861 if (!is_elf_hash_table (htab))
2864 /* Count the number of input BFDs and find the top input section id. */
2865 for (input_bfd = info->input_bfds, bfd_count = 0, top_id = 0;
2866 input_bfd != NULL; input_bfd = input_bfd->link.next)
2869 for (section = input_bfd->sections;
2870 section != NULL; section = section->next)
2872 if (top_id < section->id)
2873 top_id = section->id;
2876 htab->bfd_count = bfd_count;
2878 amt = sizeof (struct map_stub) * (top_id + 1);
2879 htab->stub_group = bfd_zmalloc (amt);
2880 if (htab->stub_group == NULL)
2883 /* We can't use output_bfd->section_count here to find the top output
2884 section index as some sections may have been removed, and
2885 _bfd_strip_section_from_output doesn't renumber the indices. */
2886 for (section = output_bfd->sections, top_index = 0;
2887 section != NULL; section = section->next)
2889 if (top_index < section->index)
2890 top_index = section->index;
2893 htab->top_index = top_index;
2894 amt = sizeof (asection *) * (top_index + 1);
2895 input_list = bfd_malloc (amt);
2896 htab->input_list = input_list;
2897 if (input_list == NULL)
2900 /* For sections we aren't interested in, mark their entries with a
2901 value we can check later. */
2902 list = input_list + top_index;
2904 *list = bfd_abs_section_ptr;
2905 while (list-- != input_list);
2907 for (section = output_bfd->sections;
2908 section != NULL; section = section->next)
2910 if ((section->flags & SEC_CODE) != 0)
2911 input_list[section->index] = NULL;
2917 /* Used by elfNN_aarch64_next_input_section and group_sections. */
2918 #define PREV_SEC(sec) (htab->stub_group[(sec)->id].link_sec)
2920 /* The linker repeatedly calls this function for each input section,
2921 in the order that input sections are linked into output sections.
2922 Build lists of input sections to determine groupings between which
2923 we may insert linker stubs. */
2926 elfNN_aarch64_next_input_section (struct bfd_link_info *info, asection *isec)
2928 struct elf_aarch64_link_hash_table *htab =
2929 elf_aarch64_hash_table (info);
2931 if (isec->output_section->index <= htab->top_index)
2933 asection **list = htab->input_list + isec->output_section->index;
2935 if (*list != bfd_abs_section_ptr)
2937 /* Steal the link_sec pointer for our list. */
2938 /* This happens to make the list in reverse order,
2939 which is what we want. */
2940 PREV_SEC (isec) = *list;
2946 /* See whether we can group stub sections together. Grouping stub
2947 sections may result in fewer stubs. More importantly, we need to
2948 put all .init* and .fini* stubs at the beginning of the .init or
2949 .fini output sections respectively, because glibc splits the
2950 _init and _fini functions into multiple parts. Putting a stub in
2951 the middle of a function is not a good idea. */
2954 group_sections (struct elf_aarch64_link_hash_table *htab,
2955 bfd_size_type stub_group_size,
2956 bfd_boolean stubs_always_before_branch)
2958 asection **list = htab->input_list + htab->top_index;
2962 asection *tail = *list;
2964 if (tail == bfd_abs_section_ptr)
2967 while (tail != NULL)
2971 bfd_size_type total;
2975 while ((prev = PREV_SEC (curr)) != NULL
2976 && ((total += curr->output_offset - prev->output_offset)
2980 /* OK, the size from the start of CURR to the end is less
2981 than stub_group_size and thus can be handled by one stub
2982 section. (Or the tail section is itself larger than
2983 stub_group_size, in which case we may be toast.)
2984 We should really be keeping track of the total size of
2985 stubs added here, as stubs contribute to the final output
2989 prev = PREV_SEC (tail);
2990 /* Set up this stub group. */
2991 htab->stub_group[tail->id].link_sec = curr;
2993 while (tail != curr && (tail = prev) != NULL);
2995 /* But wait, there's more! Input sections up to stub_group_size
2996 bytes before the stub section can be handled by it too. */
2997 if (!stubs_always_before_branch)
3001 && ((total += tail->output_offset - prev->output_offset)
3005 prev = PREV_SEC (tail);
3006 htab->stub_group[tail->id].link_sec = curr;
3012 while (list-- != htab->input_list);
3014 free (htab->input_list);
3019 #define AARCH64_BITS(x, pos, n) (((x) >> (pos)) & ((1 << (n)) - 1))
3021 #define AARCH64_RT(insn) AARCH64_BITS (insn, 0, 5)
3022 #define AARCH64_RT2(insn) AARCH64_BITS (insn, 10, 5)
3023 #define AARCH64_RA(insn) AARCH64_BITS (insn, 10, 5)
3024 #define AARCH64_RD(insn) AARCH64_BITS (insn, 0, 5)
3025 #define AARCH64_RN(insn) AARCH64_BITS (insn, 5, 5)
3026 #define AARCH64_RM(insn) AARCH64_BITS (insn, 16, 5)
3028 #define AARCH64_MAC(insn) (((insn) & 0xff000000) == 0x9b000000)
3029 #define AARCH64_BIT(insn, n) AARCH64_BITS (insn, n, 1)
3030 #define AARCH64_OP31(insn) AARCH64_BITS (insn, 21, 3)
3031 #define AARCH64_ZR 0x1f
3033 /* All ld/st ops. See C4-182 of the ARM ARM. The encoding space for
3034 LD_PCREL, LDST_RO, LDST_UI and LDST_UIMM cover prefetch ops. */
3036 #define AARCH64_LD(insn) (AARCH64_BIT (insn, 22) == 1)
3037 #define AARCH64_LDST(insn) (((insn) & 0x0a000000) == 0x08000000)
3038 #define AARCH64_LDST_EX(insn) (((insn) & 0x3f000000) == 0x08000000)
3039 #define AARCH64_LDST_PCREL(insn) (((insn) & 0x3b000000) == 0x18000000)
3040 #define AARCH64_LDST_NAP(insn) (((insn) & 0x3b800000) == 0x28000000)
3041 #define AARCH64_LDSTP_PI(insn) (((insn) & 0x3b800000) == 0x28800000)
3042 #define AARCH64_LDSTP_O(insn) (((insn) & 0x3b800000) == 0x29000000)
3043 #define AARCH64_LDSTP_PRE(insn) (((insn) & 0x3b800000) == 0x29800000)
3044 #define AARCH64_LDST_UI(insn) (((insn) & 0x3b200c00) == 0x38000000)
3045 #define AARCH64_LDST_PIIMM(insn) (((insn) & 0x3b200c00) == 0x38000400)
3046 #define AARCH64_LDST_U(insn) (((insn) & 0x3b200c00) == 0x38000800)
3047 #define AARCH64_LDST_PREIMM(insn) (((insn) & 0x3b200c00) == 0x38000c00)
3048 #define AARCH64_LDST_RO(insn) (((insn) & 0x3b200c00) == 0x38200800)
3049 #define AARCH64_LDST_UIMM(insn) (((insn) & 0x3b000000) == 0x39000000)
3050 #define AARCH64_LDST_SIMD_M(insn) (((insn) & 0xbfbf0000) == 0x0c000000)
3051 #define AARCH64_LDST_SIMD_M_PI(insn) (((insn) & 0xbfa00000) == 0x0c800000)
3052 #define AARCH64_LDST_SIMD_S(insn) (((insn) & 0xbf9f0000) == 0x0d000000)
3053 #define AARCH64_LDST_SIMD_S_PI(insn) (((insn) & 0xbf800000) == 0x0d800000)
3055 /* Classify an INSN if it is indeed a load/store.
3057 Return TRUE if INSN is a LD/ST instruction otherwise return FALSE.
3059 For scalar LD/ST instructions PAIR is FALSE, RT is returned and RT2
3062 For LD/ST pair instructions PAIR is TRUE, RT and RT2 are returned.
3067 aarch64_mem_op_p (uint32_t insn, unsigned int *rt, unsigned int *rt2,
3068 bfd_boolean *pair, bfd_boolean *load)
3076 /* Bail out quickly if INSN doesn't fall into the the load-store
3078 if (!AARCH64_LDST (insn))
3083 if (AARCH64_LDST_EX (insn))
3085 *rt = AARCH64_RT (insn);
3087 if (AARCH64_BIT (insn, 21) == 1)
3090 *rt2 = AARCH64_RT2 (insn);
3092 *load = AARCH64_LD (insn);
3095 else if (AARCH64_LDST_NAP (insn)
3096 || AARCH64_LDSTP_PI (insn)
3097 || AARCH64_LDSTP_O (insn)
3098 || AARCH64_LDSTP_PRE (insn))
3101 *rt = AARCH64_RT (insn);
3102 *rt2 = AARCH64_RT2 (insn);
3103 *load = AARCH64_LD (insn);
3106 else if (AARCH64_LDST_PCREL (insn)
3107 || AARCH64_LDST_UI (insn)
3108 || AARCH64_LDST_PIIMM (insn)
3109 || AARCH64_LDST_U (insn)
3110 || AARCH64_LDST_PREIMM (insn)
3111 || AARCH64_LDST_RO (insn)
3112 || AARCH64_LDST_UIMM (insn))
3114 *rt = AARCH64_RT (insn);
3116 if (AARCH64_LDST_PCREL (insn))
3118 opc = AARCH64_BITS (insn, 22, 2);
3119 v = AARCH64_BIT (insn, 26);
3120 opc_v = opc | (v << 2);
3121 *load = (opc_v == 1 || opc_v == 2 || opc_v == 3
3122 || opc_v == 5 || opc_v == 7);
3125 else if (AARCH64_LDST_SIMD_M (insn)
3126 || AARCH64_LDST_SIMD_M_PI (insn))
3128 *rt = AARCH64_RT (insn);
3129 *load = AARCH64_BIT (insn, 22);
3130 opcode = (insn >> 12) & 0xf;
3157 else if (AARCH64_LDST_SIMD_S (insn)
3158 || AARCH64_LDST_SIMD_S_PI (insn))
3160 *rt = AARCH64_RT (insn);
3161 r = (insn >> 21) & 1;
3162 *load = AARCH64_BIT (insn, 22);
3163 opcode = (insn >> 13) & 0x7;
3175 *rt2 = *rt + (r == 0 ? 2 : 3);
3183 *rt2 = *rt + (r == 0 ? 2 : 3);
3195 /* Return TRUE if INSN is multiply-accumulate. */
3198 aarch64_mlxl_p (uint32_t insn)
3200 uint32_t op31 = AARCH64_OP31 (insn);
3202 if (AARCH64_MAC (insn)
3203 && (op31 == 0 || op31 == 1 || op31 == 5)
3204 /* Exclude MUL instructions which are encoded as a multiple accumulate
3206 && AARCH64_RA (insn) != AARCH64_ZR)
3212 /* Some early revisions of the Cortex-A53 have an erratum (835769) whereby
3213 it is possible for a 64-bit multiply-accumulate instruction to generate an
3214 incorrect result. The details are quite complex and hard to
3215 determine statically, since branches in the code may exist in some
3216 circumstances, but all cases end with a memory (load, store, or
3217 prefetch) instruction followed immediately by the multiply-accumulate
3218 operation. We employ a linker patching technique, by moving the potentially
3219 affected multiply-accumulate instruction into a patch region and replacing
3220 the original instruction with a branch to the patch. This function checks
3221 if INSN_1 is the memory operation followed by a multiply-accumulate
3222 operation (INSN_2). Return TRUE if an erratum sequence is found, FALSE
3223 if INSN_1 and INSN_2 are safe. */
3226 aarch64_erratum_sequence (uint32_t insn_1, uint32_t insn_2)
3236 if (aarch64_mlxl_p (insn_2)
3237 && aarch64_mem_op_p (insn_1, &rt, &rt2, &pair, &load))
3239 /* Any SIMD memory op is independent of the subsequent MLA
3240 by definition of the erratum. */
3241 if (AARCH64_BIT (insn_1, 26))
3244 /* If not SIMD, check for integer memory ops and MLA relationship. */
3245 rn = AARCH64_RN (insn_2);
3246 ra = AARCH64_RA (insn_2);
3247 rm = AARCH64_RM (insn_2);
3249 /* If this is a load and there's a true(RAW) dependency, we are safe
3250 and this is not an erratum sequence. */
3252 (rt == rn || rt == rm || rt == ra
3253 || (pair && (rt2 == rn || rt2 == rm || rt2 == ra))))
3256 /* We conservatively put out stubs for all other cases (including
3264 /* Used to order a list of mapping symbols by address. */
3267 elf_aarch64_compare_mapping (const void *a, const void *b)
3269 const elf_aarch64_section_map *amap = (const elf_aarch64_section_map *) a;
3270 const elf_aarch64_section_map *bmap = (const elf_aarch64_section_map *) b;
3272 if (amap->vma > bmap->vma)
3274 else if (amap->vma < bmap->vma)
3276 else if (amap->type > bmap->type)
3277 /* Ensure results do not depend on the host qsort for objects with
3278 multiple mapping symbols at the same address by sorting on type
3281 else if (amap->type < bmap->type)
3289 _bfd_aarch64_erratum_835769_stub_name (unsigned num_fixes)
3291 char *stub_name = (char *) bfd_malloc
3292 (strlen ("__erratum_835769_veneer_") + 16);
3293 sprintf (stub_name,"__erratum_835769_veneer_%d", num_fixes);
3297 /* Scan for Cortex-A53 erratum 835769 sequence.
3299 Return TRUE else FALSE on abnormal termination. */
3302 _bfd_aarch64_erratum_835769_scan (bfd *input_bfd,
3303 struct bfd_link_info *info,
3304 unsigned int *num_fixes_p)
3307 struct elf_aarch64_link_hash_table *htab = elf_aarch64_hash_table (info);
3308 unsigned int num_fixes = *num_fixes_p;
3313 for (section = input_bfd->sections;
3315 section = section->next)
3317 bfd_byte *contents = NULL;
3318 struct _aarch64_elf_section_data *sec_data;
3321 if (elf_section_type (section) != SHT_PROGBITS
3322 || (elf_section_flags (section) & SHF_EXECINSTR) == 0
3323 || (section->flags & SEC_EXCLUDE) != 0
3324 || (section->sec_info_type == SEC_INFO_TYPE_JUST_SYMS)
3325 || (section->output_section == bfd_abs_section_ptr))
3328 if (elf_section_data (section)->this_hdr.contents != NULL)
3329 contents = elf_section_data (section)->this_hdr.contents;
3330 else if (! bfd_malloc_and_get_section (input_bfd, section, &contents))
3333 sec_data = elf_aarch64_section_data (section);
3335 qsort (sec_data->map, sec_data->mapcount,
3336 sizeof (elf_aarch64_section_map), elf_aarch64_compare_mapping);
3338 for (span = 0; span < sec_data->mapcount; span++)
3340 unsigned int span_start = sec_data->map[span].vma;
3341 unsigned int span_end = ((span == sec_data->mapcount - 1)
3342 ? sec_data->map[0].vma + section->size
3343 : sec_data->map[span + 1].vma);
3345 char span_type = sec_data->map[span].type;
3347 if (span_type == 'd')
3350 for (i = span_start; i + 4 < span_end; i += 4)
3352 uint32_t insn_1 = bfd_getl32 (contents + i);
3353 uint32_t insn_2 = bfd_getl32 (contents + i + 4);
3355 if (aarch64_erratum_sequence (insn_1, insn_2))
3357 struct elf_aarch64_stub_hash_entry *stub_entry;
3358 char *stub_name = _bfd_aarch64_erratum_835769_stub_name (num_fixes);
3362 stub_entry = _bfd_aarch64_add_stub_entry_in_group (stub_name,
3368 stub_entry->stub_type = aarch64_stub_erratum_835769_veneer;
3369 stub_entry->target_section = section;
3370 stub_entry->target_value = i + 4;
3371 stub_entry->veneered_insn = insn_2;
3372 stub_entry->output_name = stub_name;
3377 if (elf_section_data (section)->this_hdr.contents == NULL)
3381 *num_fixes_p = num_fixes;
3387 /* Test if instruction INSN is ADRP. */
3390 _bfd_aarch64_adrp_p (uint32_t insn)
3392 return ((insn & 0x9f000000) == 0x90000000);
3396 /* Helper predicate to look for cortex-a53 erratum 843419 sequence 1. */
3399 _bfd_aarch64_erratum_843419_sequence_p (uint32_t insn_1, uint32_t insn_2,
3407 return (aarch64_mem_op_p (insn_2, &rt, &rt2, &pair, &load)
3410 && AARCH64_LDST_UIMM (insn_3)
3411 && AARCH64_RN (insn_3) == AARCH64_RD (insn_1));
3415 /* Test for the presence of Cortex-A53 erratum 843419 instruction sequence.
3417 Return TRUE if section CONTENTS at offset I contains one of the
3418 erratum 843419 sequences, otherwise return FALSE. If a sequence is
3419 seen set P_VENEER_I to the offset of the final LOAD/STORE
3420 instruction in the sequence.
3424 _bfd_aarch64_erratum_843419_p (bfd_byte *contents, bfd_vma vma,
3425 bfd_vma i, bfd_vma span_end,
3426 bfd_vma *p_veneer_i)
3428 uint32_t insn_1 = bfd_getl32 (contents + i);
3430 if (!_bfd_aarch64_adrp_p (insn_1))
3433 if (span_end < i + 12)
3436 uint32_t insn_2 = bfd_getl32 (contents + i + 4);
3437 uint32_t insn_3 = bfd_getl32 (contents + i + 8);
3439 if ((vma & 0xfff) != 0xff8 && (vma & 0xfff) != 0xffc)
3442 if (_bfd_aarch64_erratum_843419_sequence_p (insn_1, insn_2, insn_3))
3444 *p_veneer_i = i + 8;
3448 if (span_end < i + 16)
3451 uint32_t insn_4 = bfd_getl32 (contents + i + 12);
3453 if (_bfd_aarch64_erratum_843419_sequence_p (insn_1, insn_2, insn_4))
3455 *p_veneer_i = i + 12;
3463 /* Resize all stub sections. */
3466 _bfd_aarch64_resize_stubs (struct elf_aarch64_link_hash_table *htab)
3470 /* OK, we've added some stubs. Find out the new size of the
3472 for (section = htab->stub_bfd->sections;
3473 section != NULL; section = section->next)
3475 /* Ignore non-stub sections. */
3476 if (!strstr (section->name, STUB_SUFFIX))
3481 bfd_hash_traverse (&htab->stub_hash_table, aarch64_size_one_stub, htab);
3483 for (section = htab->stub_bfd->sections;
3484 section != NULL; section = section->next)
3486 if (!strstr (section->name, STUB_SUFFIX))
3492 /* Ensure all stub sections have a size which is a multiple of
3493 4096. This is important in order to ensure that the insertion
3494 of stub sections does not in itself move existing code around
3495 in such a way that new errata sequences are created. */
3496 if (htab->fix_erratum_843419)
3498 section->size = BFD_ALIGN (section->size, 0x1000);
3503 /* Construct an erratum 843419 workaround stub name.
3507 _bfd_aarch64_erratum_843419_stub_name (asection *input_section,
3510 const bfd_size_type len = 8 + 4 + 1 + 8 + 1 + 16 + 1;
3511 char *stub_name = bfd_malloc (len);
3513 if (stub_name != NULL)
3514 snprintf (stub_name, len, "e843419@%04x_%08x_%" BFD_VMA_FMT "x",
3515 input_section->owner->id,
3521 /* Build a stub_entry structure describing an 843419 fixup.
3523 The stub_entry constructed is populated with the bit pattern INSN
3524 of the instruction located at OFFSET within input SECTION.
3526 Returns TRUE on success. */
3529 _bfd_aarch64_erratum_843419_fixup (uint32_t insn,
3530 bfd_vma adrp_offset,
3531 bfd_vma ldst_offset,
3533 struct bfd_link_info *info)
3535 struct elf_aarch64_link_hash_table *htab = elf_aarch64_hash_table (info);
3537 struct elf_aarch64_stub_hash_entry *stub_entry;
3539 stub_name = _bfd_aarch64_erratum_843419_stub_name (section, ldst_offset);
3540 stub_entry = aarch64_stub_hash_lookup (&htab->stub_hash_table, stub_name,
3548 /* We always place an 843419 workaround veneer in the stub section
3549 attached to the input section in which an erratum sequence has
3550 been found. This ensures that later in the link process (in
3551 elfNN_aarch64_write_section) when we copy the veneered
3552 instruction from the input section into the stub section the
3553 copied instruction will have had any relocations applied to it.
3554 If we placed workaround veneers in any other stub section then we
3555 could not assume that all relocations have been processed on the
3556 corresponding input section at the point we output the stub
3560 stub_entry = _bfd_aarch64_add_stub_entry_after (stub_name, section, htab);
3561 if (stub_entry == NULL)
3567 stub_entry->adrp_offset = adrp_offset;
3568 stub_entry->target_value = ldst_offset;
3569 stub_entry->target_section = section;
3570 stub_entry->stub_type = aarch64_stub_erratum_843419_veneer;
3571 stub_entry->veneered_insn = insn;
3572 stub_entry->output_name = stub_name;
3578 /* Scan an input section looking for the signature of erratum 843419.
3580 Scans input SECTION in INPUT_BFD looking for erratum 843419
3581 signatures, for each signature found a stub_entry is created
3582 describing the location of the erratum for subsequent fixup.
3584 Return TRUE on successful scan, FALSE on failure to scan.
3588 _bfd_aarch64_erratum_843419_scan (bfd *input_bfd, asection *section,
3589 struct bfd_link_info *info)
3591 struct elf_aarch64_link_hash_table *htab = elf_aarch64_hash_table (info);
3596 if (elf_section_type (section) != SHT_PROGBITS
3597 || (elf_section_flags (section) & SHF_EXECINSTR) == 0
3598 || (section->flags & SEC_EXCLUDE) != 0
3599 || (section->sec_info_type == SEC_INFO_TYPE_JUST_SYMS)
3600 || (section->output_section == bfd_abs_section_ptr))
3605 bfd_byte *contents = NULL;
3606 struct _aarch64_elf_section_data *sec_data;
3609 if (elf_section_data (section)->this_hdr.contents != NULL)
3610 contents = elf_section_data (section)->this_hdr.contents;
3611 else if (! bfd_malloc_and_get_section (input_bfd, section, &contents))
3614 sec_data = elf_aarch64_section_data (section);
3616 qsort (sec_data->map, sec_data->mapcount,
3617 sizeof (elf_aarch64_section_map), elf_aarch64_compare_mapping);
3619 for (span = 0; span < sec_data->mapcount; span++)
3621 unsigned int span_start = sec_data->map[span].vma;
3622 unsigned int span_end = ((span == sec_data->mapcount - 1)
3623 ? sec_data->map[0].vma + section->size
3624 : sec_data->map[span + 1].vma);
3626 char span_type = sec_data->map[span].type;
3628 if (span_type == 'd')
3631 for (i = span_start; i + 8 < span_end; i += 4)
3633 bfd_vma vma = (section->output_section->vma
3634 + section->output_offset
3638 if (_bfd_aarch64_erratum_843419_p
3639 (contents, vma, i, span_end, &veneer_i))
3641 uint32_t insn = bfd_getl32 (contents + veneer_i);
3643 if (!_bfd_aarch64_erratum_843419_fixup (insn, i, veneer_i,
3650 if (elf_section_data (section)->this_hdr.contents == NULL)
3659 /* Determine and set the size of the stub section for a final link.
3661 The basic idea here is to examine all the relocations looking for
3662 PC-relative calls to a target that is unreachable with a "bl"
3666 elfNN_aarch64_size_stubs (bfd *output_bfd,
3668 struct bfd_link_info *info,
3669 bfd_signed_vma group_size,
3670 asection * (*add_stub_section) (const char *,
3672 void (*layout_sections_again) (void))
3674 bfd_size_type stub_group_size;
3675 bfd_boolean stubs_always_before_branch;
3676 bfd_boolean stub_changed = FALSE;
3677 struct elf_aarch64_link_hash_table *htab = elf_aarch64_hash_table (info);
3678 unsigned int num_erratum_835769_fixes = 0;
3680 /* Propagate mach to stub bfd, because it may not have been
3681 finalized when we created stub_bfd. */
3682 bfd_set_arch_mach (stub_bfd, bfd_get_arch (output_bfd),
3683 bfd_get_mach (output_bfd));
3685 /* Stash our params away. */
3686 htab->stub_bfd = stub_bfd;
3687 htab->add_stub_section = add_stub_section;
3688 htab->layout_sections_again = layout_sections_again;
3689 stubs_always_before_branch = group_size < 0;
3691 stub_group_size = -group_size;
3693 stub_group_size = group_size;
3695 if (stub_group_size == 1)
3697 /* Default values. */
3698 /* AArch64 branch range is +-128MB. The value used is 1MB less. */
3699 stub_group_size = 127 * 1024 * 1024;
3702 group_sections (htab, stub_group_size, stubs_always_before_branch);
3704 (*htab->layout_sections_again) ();
3706 if (htab->fix_erratum_835769)
3710 for (input_bfd = info->input_bfds;
3711 input_bfd != NULL; input_bfd = input_bfd->link.next)
3712 if (!_bfd_aarch64_erratum_835769_scan (input_bfd, info,
3713 &num_erratum_835769_fixes))
3716 _bfd_aarch64_resize_stubs (htab);
3717 (*htab->layout_sections_again) ();
3720 if (htab->fix_erratum_843419)
3724 for (input_bfd = info->input_bfds;
3726 input_bfd = input_bfd->link.next)
3730 for (section = input_bfd->sections;
3732 section = section->next)
3733 if (!_bfd_aarch64_erratum_843419_scan (input_bfd, section, info))
3737 _bfd_aarch64_resize_stubs (htab);
3738 (*htab->layout_sections_again) ();
3745 for (input_bfd = info->input_bfds;
3746 input_bfd != NULL; input_bfd = input_bfd->link.next)
3748 Elf_Internal_Shdr *symtab_hdr;
3750 Elf_Internal_Sym *local_syms = NULL;
3752 /* We'll need the symbol table in a second. */
3753 symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
3754 if (symtab_hdr->sh_info == 0)
3757 /* Walk over each section attached to the input bfd. */
3758 for (section = input_bfd->sections;
3759 section != NULL; section = section->next)
3761 Elf_Internal_Rela *internal_relocs, *irelaend, *irela;
3763 /* If there aren't any relocs, then there's nothing more
3765 if ((section->flags & SEC_RELOC) == 0
3766 || section->reloc_count == 0
3767 || (section->flags & SEC_CODE) == 0)
3770 /* If this section is a link-once section that will be
3771 discarded, then don't create any stubs. */
3772 if (section->output_section == NULL
3773 || section->output_section->owner != output_bfd)
3776 /* Get the relocs. */
3778 = _bfd_elf_link_read_relocs (input_bfd, section, NULL,
3779 NULL, info->keep_memory);
3780 if (internal_relocs == NULL)
3781 goto error_ret_free_local;
3783 /* Now examine each relocation. */
3784 irela = internal_relocs;
3785 irelaend = irela + section->reloc_count;
3786 for (; irela < irelaend; irela++)
3788 unsigned int r_type, r_indx;
3789 enum elf_aarch64_stub_type stub_type;
3790 struct elf_aarch64_stub_hash_entry *stub_entry;
3793 bfd_vma destination;
3794 struct elf_aarch64_link_hash_entry *hash;
3795 const char *sym_name;
3797 const asection *id_sec;
3798 unsigned char st_type;
3801 r_type = ELFNN_R_TYPE (irela->r_info);
3802 r_indx = ELFNN_R_SYM (irela->r_info);
3804 if (r_type >= (unsigned int) R_AARCH64_end)
3806 bfd_set_error (bfd_error_bad_value);
3807 error_ret_free_internal:
3808 if (elf_section_data (section)->relocs == NULL)
3809 free (internal_relocs);
3810 goto error_ret_free_local;
3813 /* Only look for stubs on unconditional branch and
3814 branch and link instructions. */
3815 if (r_type != (unsigned int) AARCH64_R (CALL26)
3816 && r_type != (unsigned int) AARCH64_R (JUMP26))
3819 /* Now determine the call target, its name, value,
3826 if (r_indx < symtab_hdr->sh_info)
3828 /* It's a local symbol. */
3829 Elf_Internal_Sym *sym;
3830 Elf_Internal_Shdr *hdr;
3832 if (local_syms == NULL)
3835 = (Elf_Internal_Sym *) symtab_hdr->contents;
3836 if (local_syms == NULL)
3838 = bfd_elf_get_elf_syms (input_bfd, symtab_hdr,
3839 symtab_hdr->sh_info, 0,
3841 if (local_syms == NULL)
3842 goto error_ret_free_internal;
3845 sym = local_syms + r_indx;
3846 hdr = elf_elfsections (input_bfd)[sym->st_shndx];
3847 sym_sec = hdr->bfd_section;
3849 /* This is an undefined symbol. It can never
3853 if (ELF_ST_TYPE (sym->st_info) != STT_SECTION)
3854 sym_value = sym->st_value;
3855 destination = (sym_value + irela->r_addend
3856 + sym_sec->output_offset
3857 + sym_sec->output_section->vma);
3858 st_type = ELF_ST_TYPE (sym->st_info);
3860 = bfd_elf_string_from_elf_section (input_bfd,
3861 symtab_hdr->sh_link,
3868 e_indx = r_indx - symtab_hdr->sh_info;
3869 hash = ((struct elf_aarch64_link_hash_entry *)
3870 elf_sym_hashes (input_bfd)[e_indx]);
3872 while (hash->root.root.type == bfd_link_hash_indirect
3873 || hash->root.root.type == bfd_link_hash_warning)
3874 hash = ((struct elf_aarch64_link_hash_entry *)
3875 hash->root.root.u.i.link);
3877 if (hash->root.root.type == bfd_link_hash_defined
3878 || hash->root.root.type == bfd_link_hash_defweak)
3880 struct elf_aarch64_link_hash_table *globals =
3881 elf_aarch64_hash_table (info);
3882 sym_sec = hash->root.root.u.def.section;
3883 sym_value = hash->root.root.u.def.value;
3884 /* For a destination in a shared library,
3885 use the PLT stub as target address to
3886 decide whether a branch stub is
3888 if (globals->root.splt != NULL && hash != NULL
3889 && hash->root.plt.offset != (bfd_vma) - 1)
3891 sym_sec = globals->root.splt;
3892 sym_value = hash->root.plt.offset;
3893 if (sym_sec->output_section != NULL)
3894 destination = (sym_value
3895 + sym_sec->output_offset
3897 sym_sec->output_section->vma);
3899 else if (sym_sec->output_section != NULL)
3900 destination = (sym_value + irela->r_addend
3901 + sym_sec->output_offset
3902 + sym_sec->output_section->vma);
3904 else if (hash->root.root.type == bfd_link_hash_undefined
3905 || (hash->root.root.type
3906 == bfd_link_hash_undefweak))
3908 /* For a shared library, use the PLT stub as
3909 target address to decide whether a long
3910 branch stub is needed.
3911 For absolute code, they cannot be handled. */
3912 struct elf_aarch64_link_hash_table *globals =
3913 elf_aarch64_hash_table (info);
3915 if (globals->root.splt != NULL && hash != NULL
3916 && hash->root.plt.offset != (bfd_vma) - 1)
3918 sym_sec = globals->root.splt;
3919 sym_value = hash->root.plt.offset;
3920 if (sym_sec->output_section != NULL)
3921 destination = (sym_value
3922 + sym_sec->output_offset
3924 sym_sec->output_section->vma);
3931 bfd_set_error (bfd_error_bad_value);
3932 goto error_ret_free_internal;
3934 st_type = ELF_ST_TYPE (hash->root.type);
3935 sym_name = hash->root.root.root.string;
3938 /* Determine what (if any) linker stub is needed. */
3939 stub_type = aarch64_type_of_stub
3940 (info, section, irela, sym_sec, st_type, hash, destination);
3941 if (stub_type == aarch64_stub_none)
3944 /* Support for grouping stub sections. */
3945 id_sec = htab->stub_group[section->id].link_sec;
3947 /* Get the name of this stub. */
3948 stub_name = elfNN_aarch64_stub_name (id_sec, sym_sec, hash,
3951 goto error_ret_free_internal;
3954 aarch64_stub_hash_lookup (&htab->stub_hash_table,
3955 stub_name, FALSE, FALSE);
3956 if (stub_entry != NULL)
3958 /* The proper stub has already been created. */
3963 stub_entry = _bfd_aarch64_add_stub_entry_in_group
3964 (stub_name, section, htab);
3965 if (stub_entry == NULL)
3968 goto error_ret_free_internal;
3971 stub_entry->target_value = sym_value;
3972 stub_entry->target_section = sym_sec;
3973 stub_entry->stub_type = stub_type;
3974 stub_entry->h = hash;
3975 stub_entry->st_type = st_type;
3977 if (sym_name == NULL)
3978 sym_name = "unnamed";
3979 len = sizeof (STUB_ENTRY_NAME) + strlen (sym_name);
3980 stub_entry->output_name = bfd_alloc (htab->stub_bfd, len);
3981 if (stub_entry->output_name == NULL)
3984 goto error_ret_free_internal;
3987 snprintf (stub_entry->output_name, len, STUB_ENTRY_NAME,
3990 stub_changed = TRUE;
3993 /* We're done with the internal relocs, free them. */
3994 if (elf_section_data (section)->relocs == NULL)
3995 free (internal_relocs);
4002 _bfd_aarch64_resize_stubs (htab);
4004 /* Ask the linker to do its stuff. */
4005 (*htab->layout_sections_again) ();
4006 stub_changed = FALSE;
4011 error_ret_free_local:
4015 /* Build all the stubs associated with the current output file. The
4016 stubs are kept in a hash table attached to the main linker hash
4017 table. We also set up the .plt entries for statically linked PIC
4018 functions here. This function is called via aarch64_elf_finish in the
4022 elfNN_aarch64_build_stubs (struct bfd_link_info *info)
4025 struct bfd_hash_table *table;
4026 struct elf_aarch64_link_hash_table *htab;
4028 htab = elf_aarch64_hash_table (info);
4030 for (stub_sec = htab->stub_bfd->sections;
4031 stub_sec != NULL; stub_sec = stub_sec->next)
4035 /* Ignore non-stub sections. */
4036 if (!strstr (stub_sec->name, STUB_SUFFIX))
4039 /* Allocate memory to hold the linker stubs. */
4040 size = stub_sec->size;
4041 stub_sec->contents = bfd_zalloc (htab->stub_bfd, size);
4042 if (stub_sec->contents == NULL && size != 0)
4046 bfd_putl32 (0x14000000 | (size >> 2), stub_sec->contents);
4047 stub_sec->size += 4;
4050 /* Build the stubs as directed by the stub hash table. */
4051 table = &htab->stub_hash_table;
4052 bfd_hash_traverse (table, aarch64_build_one_stub, info);
4058 /* Add an entry to the code/data map for section SEC. */
4061 elfNN_aarch64_section_map_add (asection *sec, char type, bfd_vma vma)
4063 struct _aarch64_elf_section_data *sec_data =
4064 elf_aarch64_section_data (sec);
4065 unsigned int newidx;
4067 if (sec_data->map == NULL)
4069 sec_data->map = bfd_malloc (sizeof (elf_aarch64_section_map));
4070 sec_data->mapcount = 0;
4071 sec_data->mapsize = 1;
4074 newidx = sec_data->mapcount++;
4076 if (sec_data->mapcount > sec_data->mapsize)
4078 sec_data->mapsize *= 2;
4079 sec_data->map = bfd_realloc_or_free
4080 (sec_data->map, sec_data->mapsize * sizeof (elf_aarch64_section_map));
4085 sec_data->map[newidx].vma = vma;
4086 sec_data->map[newidx].type = type;
4091 /* Initialise maps of insn/data for input BFDs. */
4093 bfd_elfNN_aarch64_init_maps (bfd *abfd)
4095 Elf_Internal_Sym *isymbuf;
4096 Elf_Internal_Shdr *hdr;
4097 unsigned int i, localsyms;
4099 /* Make sure that we are dealing with an AArch64 elf binary. */
4100 if (!is_aarch64_elf (abfd))
4103 if ((abfd->flags & DYNAMIC) != 0)
4106 hdr = &elf_symtab_hdr (abfd);
4107 localsyms = hdr->sh_info;
4109 /* Obtain a buffer full of symbols for this BFD. The hdr->sh_info field
4110 should contain the number of local symbols, which should come before any
4111 global symbols. Mapping symbols are always local. */
4112 isymbuf = bfd_elf_get_elf_syms (abfd, hdr, localsyms, 0, NULL, NULL, NULL);
4114 /* No internal symbols read? Skip this BFD. */
4115 if (isymbuf == NULL)
4118 for (i = 0; i < localsyms; i++)
4120 Elf_Internal_Sym *isym = &isymbuf[i];
4121 asection *sec = bfd_section_from_elf_index (abfd, isym->st_shndx);
4124 if (sec != NULL && ELF_ST_BIND (isym->st_info) == STB_LOCAL)
4126 name = bfd_elf_string_from_elf_section (abfd,
4130 if (bfd_is_aarch64_special_symbol_name
4131 (name, BFD_AARCH64_SPECIAL_SYM_TYPE_MAP))
4132 elfNN_aarch64_section_map_add (sec, name[1], isym->st_value);
4137 /* Set option values needed during linking. */
4139 bfd_elfNN_aarch64_set_options (struct bfd *output_bfd,
4140 struct bfd_link_info *link_info,
4142 int no_wchar_warn, int pic_veneer,
4143 int fix_erratum_835769,
4144 int fix_erratum_843419)
4146 struct elf_aarch64_link_hash_table *globals;
4148 globals = elf_aarch64_hash_table (link_info);
4149 globals->pic_veneer = pic_veneer;
4150 globals->fix_erratum_835769 = fix_erratum_835769;
4151 globals->fix_erratum_843419 = fix_erratum_843419;
4152 globals->fix_erratum_843419_adr = TRUE;
4154 BFD_ASSERT (is_aarch64_elf (output_bfd));
4155 elf_aarch64_tdata (output_bfd)->no_enum_size_warning = no_enum_warn;
4156 elf_aarch64_tdata (output_bfd)->no_wchar_size_warning = no_wchar_warn;
4160 aarch64_calculate_got_entry_vma (struct elf_link_hash_entry *h,
4161 struct elf_aarch64_link_hash_table
4162 *globals, struct bfd_link_info *info,
4163 bfd_vma value, bfd *output_bfd,
4164 bfd_boolean *unresolved_reloc_p)
4166 bfd_vma off = (bfd_vma) - 1;
4167 asection *basegot = globals->root.sgot;
4168 bfd_boolean dyn = globals->root.dynamic_sections_created;
4172 BFD_ASSERT (basegot != NULL);
4173 off = h->got.offset;
4174 BFD_ASSERT (off != (bfd_vma) - 1);
4175 if (!WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, bfd_link_pic (info), h)
4176 || (bfd_link_pic (info)
4177 && SYMBOL_REFERENCES_LOCAL (info, h))
4178 || (ELF_ST_VISIBILITY (h->other)
4179 && h->root.type == bfd_link_hash_undefweak))
4181 /* This is actually a static link, or it is a -Bsymbolic link
4182 and the symbol is defined locally. We must initialize this
4183 entry in the global offset table. Since the offset must
4184 always be a multiple of 8 (4 in the case of ILP32), we use
4185 the least significant bit to record whether we have
4186 initialized it already.
4187 When doing a dynamic link, we create a .rel(a).got relocation
4188 entry to initialize the value. This is done in the
4189 finish_dynamic_symbol routine. */
4194 bfd_put_NN (output_bfd, value, basegot->contents + off);
4199 *unresolved_reloc_p = FALSE;
4201 off = off + basegot->output_section->vma + basegot->output_offset;
4207 /* Change R_TYPE to a more efficient access model where possible,
4208 return the new reloc type. */
4210 static bfd_reloc_code_real_type
4211 aarch64_tls_transition_without_check (bfd_reloc_code_real_type r_type,
4212 struct elf_link_hash_entry *h)
4214 bfd_boolean is_local = h == NULL;
4218 case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21:
4219 case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21:
4221 ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1
4222 : BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21);
4224 case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21:
4226 ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC
4229 case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19:
4231 ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1
4232 : BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19);
4234 case BFD_RELOC_AARCH64_TLSDESC_LDNN_LO12_NC:
4235 case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC:
4237 ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC
4238 : BFD_RELOC_AARCH64_TLSIE_LDNN_GOTTPREL_LO12_NC);
4240 case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21:
4241 return is_local ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1 : r_type;
4243 case BFD_RELOC_AARCH64_TLSIE_LDNN_GOTTPREL_LO12_NC:
4244 return is_local ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC : r_type;
4246 case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19:
4249 case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21:
4251 ? BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_HI12
4252 : BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19);
4254 case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12_NC:
4255 case BFD_RELOC_AARCH64_TLSDESC_CALL:
4256 /* Instructions with these relocations will become NOPs. */
4257 return BFD_RELOC_AARCH64_NONE;
4267 aarch64_reloc_got_type (bfd_reloc_code_real_type r_type)
4271 case BFD_RELOC_AARCH64_ADR_GOT_PAGE:
4272 case BFD_RELOC_AARCH64_GOT_LD_PREL19:
4273 case BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14:
4274 case BFD_RELOC_AARCH64_LD32_GOT_LO12_NC:
4275 case BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15:
4276 case BFD_RELOC_AARCH64_LD64_GOT_LO12_NC:
4279 case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC:
4280 case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21:
4281 case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21:
4282 case BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC:
4283 case BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21:
4284 case BFD_RELOC_AARCH64_TLSLD_ADR_PREL21:
4287 case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12_NC:
4288 case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21:
4289 case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21:
4290 case BFD_RELOC_AARCH64_TLSDESC_CALL:
4291 case BFD_RELOC_AARCH64_TLSDESC_LD32_LO12_NC:
4292 case BFD_RELOC_AARCH64_TLSDESC_LD64_LO12_NC:
4293 case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19:
4294 return GOT_TLSDESC_GD;
4296 case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21:
4297 case BFD_RELOC_AARCH64_TLSIE_LD32_GOTTPREL_LO12_NC:
4298 case BFD_RELOC_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC:
4299 case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19:
4309 aarch64_can_relax_tls (bfd *input_bfd,
4310 struct bfd_link_info *info,
4311 bfd_reloc_code_real_type r_type,
4312 struct elf_link_hash_entry *h,
4313 unsigned long r_symndx)
4315 unsigned int symbol_got_type;
4316 unsigned int reloc_got_type;
4318 if (! IS_AARCH64_TLS_RELAX_RELOC (r_type))
4321 symbol_got_type = elfNN_aarch64_symbol_got_type (h, input_bfd, r_symndx);
4322 reloc_got_type = aarch64_reloc_got_type (r_type);
4324 if (symbol_got_type == GOT_TLS_IE && GOT_TLS_GD_ANY_P (reloc_got_type))
4327 if (bfd_link_pic (info))
4330 if (h && h->root.type == bfd_link_hash_undefweak)
4336 /* Given the relocation code R_TYPE, return the relaxed bfd reloc
4339 static bfd_reloc_code_real_type
4340 aarch64_tls_transition (bfd *input_bfd,
4341 struct bfd_link_info *info,
4342 unsigned int r_type,
4343 struct elf_link_hash_entry *h,
4344 unsigned long r_symndx)
4346 bfd_reloc_code_real_type bfd_r_type
4347 = elfNN_aarch64_bfd_reloc_from_type (r_type);
4349 if (! aarch64_can_relax_tls (input_bfd, info, bfd_r_type, h, r_symndx))
4352 return aarch64_tls_transition_without_check (bfd_r_type, h);
4355 /* Return the base VMA address which should be subtracted from real addresses
4356 when resolving R_AARCH64_TLS_DTPREL relocation. */
4359 dtpoff_base (struct bfd_link_info *info)
4361 /* If tls_sec is NULL, we should have signalled an error already. */
4362 BFD_ASSERT (elf_hash_table (info)->tls_sec != NULL);
4363 return elf_hash_table (info)->tls_sec->vma;
4366 /* Return the base VMA address which should be subtracted from real addresses
4367 when resolving R_AARCH64_TLS_GOTTPREL64 relocations. */
4370 tpoff_base (struct bfd_link_info *info)
4372 struct elf_link_hash_table *htab = elf_hash_table (info);
4374 /* If tls_sec is NULL, we should have signalled an error already. */
4375 BFD_ASSERT (htab->tls_sec != NULL);
4377 bfd_vma base = align_power ((bfd_vma) TCB_SIZE,
4378 htab->tls_sec->alignment_power);
4379 return htab->tls_sec->vma - base;
4383 symbol_got_offset_ref (bfd *input_bfd, struct elf_link_hash_entry *h,
4384 unsigned long r_symndx)
4386 /* Calculate the address of the GOT entry for symbol
4387 referred to in h. */
4389 return &h->got.offset;
4393 struct elf_aarch64_local_symbol *l;
4395 l = elf_aarch64_locals (input_bfd);
4396 return &l[r_symndx].got_offset;
4401 symbol_got_offset_mark (bfd *input_bfd, struct elf_link_hash_entry *h,
4402 unsigned long r_symndx)
4405 p = symbol_got_offset_ref (input_bfd, h, r_symndx);
4410 symbol_got_offset_mark_p (bfd *input_bfd, struct elf_link_hash_entry *h,
4411 unsigned long r_symndx)
4414 value = * symbol_got_offset_ref (input_bfd, h, r_symndx);
4419 symbol_got_offset (bfd *input_bfd, struct elf_link_hash_entry *h,
4420 unsigned long r_symndx)
4423 value = * symbol_got_offset_ref (input_bfd, h, r_symndx);
4429 symbol_tlsdesc_got_offset_ref (bfd *input_bfd, struct elf_link_hash_entry *h,
4430 unsigned long r_symndx)
4432 /* Calculate the address of the GOT entry for symbol
4433 referred to in h. */
4436 struct elf_aarch64_link_hash_entry *eh;
4437 eh = (struct elf_aarch64_link_hash_entry *) h;
4438 return &eh->tlsdesc_got_jump_table_offset;
4443 struct elf_aarch64_local_symbol *l;
4445 l = elf_aarch64_locals (input_bfd);
4446 return &l[r_symndx].tlsdesc_got_jump_table_offset;
4451 symbol_tlsdesc_got_offset_mark (bfd *input_bfd, struct elf_link_hash_entry *h,
4452 unsigned long r_symndx)
4455 p = symbol_tlsdesc_got_offset_ref (input_bfd, h, r_symndx);
4460 symbol_tlsdesc_got_offset_mark_p (bfd *input_bfd,
4461 struct elf_link_hash_entry *h,
4462 unsigned long r_symndx)
4465 value = * symbol_tlsdesc_got_offset_ref (input_bfd, h, r_symndx);
4470 symbol_tlsdesc_got_offset (bfd *input_bfd, struct elf_link_hash_entry *h,
4471 unsigned long r_symndx)
4474 value = * symbol_tlsdesc_got_offset_ref (input_bfd, h, r_symndx);
4479 /* Data for make_branch_to_erratum_835769_stub(). */
4481 struct erratum_835769_branch_to_stub_data
4483 struct bfd_link_info *info;
4484 asection *output_section;
4488 /* Helper to insert branches to erratum 835769 stubs in the right
4489 places for a particular section. */
4492 make_branch_to_erratum_835769_stub (struct bfd_hash_entry *gen_entry,
4495 struct elf_aarch64_stub_hash_entry *stub_entry;
4496 struct erratum_835769_branch_to_stub_data *data;
4498 unsigned long branch_insn = 0;
4499 bfd_vma veneered_insn_loc, veneer_entry_loc;
4500 bfd_signed_vma branch_offset;
4501 unsigned int target;
4504 stub_entry = (struct elf_aarch64_stub_hash_entry *) gen_entry;
4505 data = (struct erratum_835769_branch_to_stub_data *) in_arg;
4507 if (stub_entry->target_section != data->output_section
4508 || stub_entry->stub_type != aarch64_stub_erratum_835769_veneer)
4511 contents = data->contents;
4512 veneered_insn_loc = stub_entry->target_section->output_section->vma
4513 + stub_entry->target_section->output_offset
4514 + stub_entry->target_value;
4515 veneer_entry_loc = stub_entry->stub_sec->output_section->vma
4516 + stub_entry->stub_sec->output_offset
4517 + stub_entry->stub_offset;
4518 branch_offset = veneer_entry_loc - veneered_insn_loc;
4520 abfd = stub_entry->target_section->owner;
4521 if (!aarch64_valid_branch_p (veneer_entry_loc, veneered_insn_loc))
4522 (*_bfd_error_handler)
4523 (_("%B: error: Erratum 835769 stub out "
4524 "of range (input file too large)"), abfd);
4526 target = stub_entry->target_value;
4527 branch_insn = 0x14000000;
4528 branch_offset >>= 2;
4529 branch_offset &= 0x3ffffff;
4530 branch_insn |= branch_offset;
4531 bfd_putl32 (branch_insn, &contents[target]);
4538 _bfd_aarch64_erratum_843419_branch_to_stub (struct bfd_hash_entry *gen_entry,
4541 struct elf_aarch64_stub_hash_entry *stub_entry
4542 = (struct elf_aarch64_stub_hash_entry *) gen_entry;
4543 struct erratum_835769_branch_to_stub_data *data
4544 = (struct erratum_835769_branch_to_stub_data *) in_arg;
4545 struct bfd_link_info *info;
4546 struct elf_aarch64_link_hash_table *htab;
4554 contents = data->contents;
4555 section = data->output_section;
4557 htab = elf_aarch64_hash_table (info);
4559 if (stub_entry->target_section != section
4560 || stub_entry->stub_type != aarch64_stub_erratum_843419_veneer)
4563 insn = bfd_getl32 (contents + stub_entry->target_value);
4565 stub_entry->stub_sec->contents + stub_entry->stub_offset);
4567 place = (section->output_section->vma + section->output_offset
4568 + stub_entry->adrp_offset);
4569 insn = bfd_getl32 (contents + stub_entry->adrp_offset);
4571 if ((insn & AARCH64_ADRP_OP_MASK) != AARCH64_ADRP_OP)
4574 bfd_signed_vma imm =
4575 (_bfd_aarch64_sign_extend
4576 ((bfd_vma) _bfd_aarch64_decode_adrp_imm (insn) << 12, 33)
4579 if (htab->fix_erratum_843419_adr
4580 && (imm >= AARCH64_MIN_ADRP_IMM && imm <= AARCH64_MAX_ADRP_IMM))
4582 insn = (_bfd_aarch64_reencode_adr_imm (AARCH64_ADR_OP, imm)
4583 | AARCH64_RT (insn));
4584 bfd_putl32 (insn, contents + stub_entry->adrp_offset);
4588 bfd_vma veneered_insn_loc;
4589 bfd_vma veneer_entry_loc;
4590 bfd_signed_vma branch_offset;
4591 uint32_t branch_insn;
4593 veneered_insn_loc = stub_entry->target_section->output_section->vma
4594 + stub_entry->target_section->output_offset
4595 + stub_entry->target_value;
4596 veneer_entry_loc = stub_entry->stub_sec->output_section->vma
4597 + stub_entry->stub_sec->output_offset
4598 + stub_entry->stub_offset;
4599 branch_offset = veneer_entry_loc - veneered_insn_loc;
4601 abfd = stub_entry->target_section->owner;
4602 if (!aarch64_valid_branch_p (veneer_entry_loc, veneered_insn_loc))
4603 (*_bfd_error_handler)
4604 (_("%B: error: Erratum 843419 stub out "
4605 "of range (input file too large)"), abfd);
4607 branch_insn = 0x14000000;
4608 branch_offset >>= 2;
4609 branch_offset &= 0x3ffffff;
4610 branch_insn |= branch_offset;
4611 bfd_putl32 (branch_insn, contents + stub_entry->target_value);
4618 elfNN_aarch64_write_section (bfd *output_bfd ATTRIBUTE_UNUSED,
4619 struct bfd_link_info *link_info,
4624 struct elf_aarch64_link_hash_table *globals =
4625 elf_aarch64_hash_table (link_info);
4627 if (globals == NULL)
4630 /* Fix code to point to erratum 835769 stubs. */
4631 if (globals->fix_erratum_835769)
4633 struct erratum_835769_branch_to_stub_data data;
4635 data.info = link_info;
4636 data.output_section = sec;
4637 data.contents = contents;
4638 bfd_hash_traverse (&globals->stub_hash_table,
4639 make_branch_to_erratum_835769_stub, &data);
4642 if (globals->fix_erratum_843419)
4644 struct erratum_835769_branch_to_stub_data data;
4646 data.info = link_info;
4647 data.output_section = sec;
4648 data.contents = contents;
4649 bfd_hash_traverse (&globals->stub_hash_table,
4650 _bfd_aarch64_erratum_843419_branch_to_stub, &data);
4656 /* Perform a relocation as part of a final link. */
4657 static bfd_reloc_status_type
4658 elfNN_aarch64_final_link_relocate (reloc_howto_type *howto,
4661 asection *input_section,
4663 Elf_Internal_Rela *rel,
4665 struct bfd_link_info *info,
4667 struct elf_link_hash_entry *h,
4668 bfd_boolean *unresolved_reloc_p,
4669 bfd_boolean save_addend,
4670 bfd_vma *saved_addend,
4671 Elf_Internal_Sym *sym)
4673 Elf_Internal_Shdr *symtab_hdr;
4674 unsigned int r_type = howto->type;
4675 bfd_reloc_code_real_type bfd_r_type
4676 = elfNN_aarch64_bfd_reloc_from_howto (howto);
4677 bfd_reloc_code_real_type new_bfd_r_type;
4678 unsigned long r_symndx;
4679 bfd_byte *hit_data = contents + rel->r_offset;
4681 bfd_signed_vma signed_addend;
4682 struct elf_aarch64_link_hash_table *globals;
4683 bfd_boolean weak_undef_p;
4686 globals = elf_aarch64_hash_table (info);
4688 symtab_hdr = &elf_symtab_hdr (input_bfd);
4690 BFD_ASSERT (is_aarch64_elf (input_bfd));
4692 r_symndx = ELFNN_R_SYM (rel->r_info);
4694 /* It is possible to have linker relaxations on some TLS access
4695 models. Update our information here. */
4696 new_bfd_r_type = aarch64_tls_transition (input_bfd, info, r_type, h, r_symndx);
4697 if (new_bfd_r_type != bfd_r_type)
4699 bfd_r_type = new_bfd_r_type;
4700 howto = elfNN_aarch64_howto_from_bfd_reloc (bfd_r_type);
4701 BFD_ASSERT (howto != NULL);
4702 r_type = howto->type;
4705 place = input_section->output_section->vma
4706 + input_section->output_offset + rel->r_offset;
4708 /* Get addend, accumulating the addend for consecutive relocs
4709 which refer to the same offset. */
4710 signed_addend = saved_addend ? *saved_addend : 0;
4711 signed_addend += rel->r_addend;
4713 weak_undef_p = (h ? h->root.type == bfd_link_hash_undefweak
4714 : bfd_is_und_section (sym_sec));
4716 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle
4717 it here if it is defined in a non-shared object. */
4719 && h->type == STT_GNU_IFUNC
4726 if ((input_section->flags & SEC_ALLOC) == 0
4727 || h->plt.offset == (bfd_vma) -1)
4730 /* STT_GNU_IFUNC symbol must go through PLT. */
4731 plt = globals->root.splt ? globals->root.splt : globals->root.iplt;
4732 value = (plt->output_section->vma + plt->output_offset + h->plt.offset);
4737 if (h->root.root.string)
4738 name = h->root.root.string;
4740 name = bfd_elf_sym_name (input_bfd, symtab_hdr, sym,
4742 (*_bfd_error_handler)
4743 (_("%B: relocation %s against STT_GNU_IFUNC "
4744 "symbol `%s' isn't handled by %s"), input_bfd,
4745 howto->name, name, __FUNCTION__);
4746 bfd_set_error (bfd_error_bad_value);
4749 case BFD_RELOC_AARCH64_NN:
4750 if (rel->r_addend != 0)
4752 if (h->root.root.string)
4753 name = h->root.root.string;
4755 name = bfd_elf_sym_name (input_bfd, symtab_hdr,
4757 (*_bfd_error_handler)
4758 (_("%B: relocation %s against STT_GNU_IFUNC "
4759 "symbol `%s' has non-zero addend: %d"),
4760 input_bfd, howto->name, name, rel->r_addend);
4761 bfd_set_error (bfd_error_bad_value);
4765 /* Generate dynamic relocation only when there is a
4766 non-GOT reference in a shared object. */
4767 if (bfd_link_pic (info) && h->non_got_ref)
4769 Elf_Internal_Rela outrel;
4772 /* Need a dynamic relocation to get the real function
4774 outrel.r_offset = _bfd_elf_section_offset (output_bfd,
4778 if (outrel.r_offset == (bfd_vma) -1
4779 || outrel.r_offset == (bfd_vma) -2)
4782 outrel.r_offset += (input_section->output_section->vma
4783 + input_section->output_offset);
4785 if (h->dynindx == -1
4787 || bfd_link_executable (info))
4789 /* This symbol is resolved locally. */
4790 outrel.r_info = ELFNN_R_INFO (0, AARCH64_R (IRELATIVE));
4791 outrel.r_addend = (h->root.u.def.value
4792 + h->root.u.def.section->output_section->vma
4793 + h->root.u.def.section->output_offset);
4797 outrel.r_info = ELFNN_R_INFO (h->dynindx, r_type);
4798 outrel.r_addend = 0;
4801 sreloc = globals->root.irelifunc;
4802 elf_append_rela (output_bfd, sreloc, &outrel);
4804 /* If this reloc is against an external symbol, we
4805 do not want to fiddle with the addend. Otherwise,
4806 we need to include the symbol value so that it
4807 becomes an addend for the dynamic reloc. For an
4808 internal symbol, we have updated addend. */
4809 return bfd_reloc_ok;
4812 case BFD_RELOC_AARCH64_CALL26:
4813 case BFD_RELOC_AARCH64_JUMP26:
4814 value = _bfd_aarch64_elf_resolve_relocation (bfd_r_type, place, value,
4817 return _bfd_aarch64_elf_put_addend (input_bfd, hit_data, bfd_r_type,
4819 case BFD_RELOC_AARCH64_ADR_GOT_PAGE:
4820 case BFD_RELOC_AARCH64_GOT_LD_PREL19:
4821 case BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14:
4822 case BFD_RELOC_AARCH64_LD32_GOT_LO12_NC:
4823 case BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15:
4824 case BFD_RELOC_AARCH64_LD64_GOT_LO12_NC:
4825 base_got = globals->root.sgot;
4826 off = h->got.offset;
4828 if (base_got == NULL)
4831 if (off == (bfd_vma) -1)
4835 /* We can't use h->got.offset here to save state, or
4836 even just remember the offset, as finish_dynamic_symbol
4837 would use that as offset into .got. */
4839 if (globals->root.splt != NULL)
4841 plt_index = ((h->plt.offset - globals->plt_header_size) /
4842 globals->plt_entry_size);
4843 off = (plt_index + 3) * GOT_ENTRY_SIZE;
4844 base_got = globals->root.sgotplt;
4848 plt_index = h->plt.offset / globals->plt_entry_size;
4849 off = plt_index * GOT_ENTRY_SIZE;
4850 base_got = globals->root.igotplt;
4853 if (h->dynindx == -1
4857 /* This references the local definition. We must
4858 initialize this entry in the global offset table.
4859 Since the offset must always be a multiple of 8,
4860 we use the least significant bit to record
4861 whether we have initialized it already.
4863 When doing a dynamic link, we create a .rela.got
4864 relocation entry to initialize the value. This
4865 is done in the finish_dynamic_symbol routine. */
4870 bfd_put_NN (output_bfd, value,
4871 base_got->contents + off);
4872 /* Note that this is harmless as -1 | 1 still is -1. */
4876 value = (base_got->output_section->vma
4877 + base_got->output_offset + off);
4880 value = aarch64_calculate_got_entry_vma (h, globals, info,
4882 unresolved_reloc_p);
4883 if (bfd_r_type == BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15
4884 || bfd_r_type == BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14)
4885 addend = (globals->root.sgot->output_section->vma
4886 + globals->root.sgot->output_offset);
4887 value = _bfd_aarch64_elf_resolve_relocation (bfd_r_type, place, value,
4888 addend, weak_undef_p);
4889 return _bfd_aarch64_elf_put_addend (input_bfd, hit_data, bfd_r_type, howto, value);
4890 case BFD_RELOC_AARCH64_ADD_LO12:
4891 case BFD_RELOC_AARCH64_ADR_HI21_PCREL:
4898 case BFD_RELOC_AARCH64_NONE:
4899 case BFD_RELOC_AARCH64_TLSDESC_CALL:
4900 *unresolved_reloc_p = FALSE;
4901 return bfd_reloc_ok;
4903 case BFD_RELOC_AARCH64_NN:
4905 /* When generating a shared object or relocatable executable, these
4906 relocations are copied into the output file to be resolved at
4908 if (((bfd_link_pic (info) == TRUE)
4909 || globals->root.is_relocatable_executable)
4910 && (input_section->flags & SEC_ALLOC)
4912 || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
4913 || h->root.type != bfd_link_hash_undefweak))
4915 Elf_Internal_Rela outrel;
4917 bfd_boolean skip, relocate;
4920 *unresolved_reloc_p = FALSE;
4925 outrel.r_addend = signed_addend;
4927 _bfd_elf_section_offset (output_bfd, info, input_section,
4929 if (outrel.r_offset == (bfd_vma) - 1)
4931 else if (outrel.r_offset == (bfd_vma) - 2)
4937 outrel.r_offset += (input_section->output_section->vma
4938 + input_section->output_offset);
4941 memset (&outrel, 0, sizeof outrel);
4944 && (!bfd_link_pic (info)
4945 || !SYMBOLIC_BIND (info, h)
4946 || !h->def_regular))
4947 outrel.r_info = ELFNN_R_INFO (h->dynindx, r_type);
4952 /* On SVR4-ish systems, the dynamic loader cannot
4953 relocate the text and data segments independently,
4954 so the symbol does not matter. */
4956 outrel.r_info = ELFNN_R_INFO (symbol, AARCH64_R (RELATIVE));
4957 outrel.r_addend += value;
4960 sreloc = elf_section_data (input_section)->sreloc;
4961 if (sreloc == NULL || sreloc->contents == NULL)
4962 return bfd_reloc_notsupported;
4964 loc = sreloc->contents + sreloc->reloc_count++ * RELOC_SIZE (globals);
4965 bfd_elfNN_swap_reloca_out (output_bfd, &outrel, loc);
4967 if (sreloc->reloc_count * RELOC_SIZE (globals) > sreloc->size)
4969 /* Sanity to check that we have previously allocated
4970 sufficient space in the relocation section for the
4971 number of relocations we actually want to emit. */
4975 /* If this reloc is against an external symbol, we do not want to
4976 fiddle with the addend. Otherwise, we need to include the symbol
4977 value so that it becomes an addend for the dynamic reloc. */
4979 return bfd_reloc_ok;
4981 return _bfd_final_link_relocate (howto, input_bfd, input_section,
4982 contents, rel->r_offset, value,
4986 value += signed_addend;
4989 case BFD_RELOC_AARCH64_CALL26:
4990 case BFD_RELOC_AARCH64_JUMP26:
4992 asection *splt = globals->root.splt;
4993 bfd_boolean via_plt_p =
4994 splt != NULL && h != NULL && h->plt.offset != (bfd_vma) - 1;
4996 /* A call to an undefined weak symbol is converted to a jump to
4997 the next instruction unless a PLT entry will be created.
4998 The jump to the next instruction is optimized as a NOP.
4999 Do the same for local undefined symbols. */
5000 if (weak_undef_p && ! via_plt_p)
5002 bfd_putl32 (INSN_NOP, hit_data);
5003 return bfd_reloc_ok;
5006 /* If the call goes through a PLT entry, make sure to
5007 check distance to the right destination address. */
5009 value = (splt->output_section->vma
5010 + splt->output_offset + h->plt.offset);
5012 /* Check if a stub has to be inserted because the destination
5014 struct elf_aarch64_stub_hash_entry *stub_entry = NULL;
5015 if (! aarch64_valid_branch_p (value, place))
5016 /* The target is out of reach, so redirect the branch to
5017 the local stub for this function. */
5018 stub_entry = elfNN_aarch64_get_stub_entry (input_section, sym_sec, h,
5020 if (stub_entry != NULL)
5021 value = (stub_entry->stub_offset
5022 + stub_entry->stub_sec->output_offset
5023 + stub_entry->stub_sec->output_section->vma);
5025 value = _bfd_aarch64_elf_resolve_relocation (bfd_r_type, place, value,
5026 signed_addend, weak_undef_p);
5027 *unresolved_reloc_p = FALSE;
5030 case BFD_RELOC_AARCH64_16_PCREL:
5031 case BFD_RELOC_AARCH64_32_PCREL:
5032 case BFD_RELOC_AARCH64_64_PCREL:
5033 case BFD_RELOC_AARCH64_ADR_HI21_NC_PCREL:
5034 case BFD_RELOC_AARCH64_ADR_HI21_PCREL:
5035 case BFD_RELOC_AARCH64_ADR_LO21_PCREL:
5036 case BFD_RELOC_AARCH64_LD_LO19_PCREL:
5037 if (bfd_link_pic (info)
5038 && (input_section->flags & SEC_ALLOC) != 0
5039 && (input_section->flags & SEC_READONLY) != 0
5043 int howto_index = bfd_r_type - BFD_RELOC_AARCH64_RELOC_START;
5045 (*_bfd_error_handler)
5046 (_("%B: relocation %s against external symbol `%s' can not be used"
5047 " when making a shared object; recompile with -fPIC"),
5048 input_bfd, elfNN_aarch64_howto_table[howto_index].name,
5049 h->root.root.string);
5050 bfd_set_error (bfd_error_bad_value);
5054 case BFD_RELOC_AARCH64_16:
5056 case BFD_RELOC_AARCH64_32:
5058 case BFD_RELOC_AARCH64_ADD_LO12:
5059 case BFD_RELOC_AARCH64_BRANCH19:
5060 case BFD_RELOC_AARCH64_LDST128_LO12:
5061 case BFD_RELOC_AARCH64_LDST16_LO12:
5062 case BFD_RELOC_AARCH64_LDST32_LO12:
5063 case BFD_RELOC_AARCH64_LDST64_LO12:
5064 case BFD_RELOC_AARCH64_LDST8_LO12:
5065 case BFD_RELOC_AARCH64_MOVW_G0:
5066 case BFD_RELOC_AARCH64_MOVW_G0_NC:
5067 case BFD_RELOC_AARCH64_MOVW_G0_S:
5068 case BFD_RELOC_AARCH64_MOVW_G1:
5069 case BFD_RELOC_AARCH64_MOVW_G1_NC:
5070 case BFD_RELOC_AARCH64_MOVW_G1_S:
5071 case BFD_RELOC_AARCH64_MOVW_G2:
5072 case BFD_RELOC_AARCH64_MOVW_G2_NC:
5073 case BFD_RELOC_AARCH64_MOVW_G2_S:
5074 case BFD_RELOC_AARCH64_MOVW_G3:
5075 case BFD_RELOC_AARCH64_TSTBR14:
5076 value = _bfd_aarch64_elf_resolve_relocation (bfd_r_type, place, value,
5077 signed_addend, weak_undef_p);
5080 case BFD_RELOC_AARCH64_ADR_GOT_PAGE:
5081 case BFD_RELOC_AARCH64_GOT_LD_PREL19:
5082 case BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14:
5083 case BFD_RELOC_AARCH64_LD32_GOT_LO12_NC:
5084 case BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15:
5085 case BFD_RELOC_AARCH64_LD64_GOT_LO12_NC:
5086 if (globals->root.sgot == NULL)
5087 BFD_ASSERT (h != NULL);
5092 value = aarch64_calculate_got_entry_vma (h, globals, info, value,
5094 unresolved_reloc_p);
5095 if (bfd_r_type == BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15
5096 || bfd_r_type == BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14)
5097 addend = (globals->root.sgot->output_section->vma
5098 + globals->root.sgot->output_offset);
5099 value = _bfd_aarch64_elf_resolve_relocation (bfd_r_type, place, value,
5100 addend, weak_undef_p);
5105 struct elf_aarch64_local_symbol *locals
5106 = elf_aarch64_locals (input_bfd);
5110 int howto_index = bfd_r_type - BFD_RELOC_AARCH64_RELOC_START;
5111 (*_bfd_error_handler)
5112 (_("%B: Local symbol descriptor table be NULL when applying "
5113 "relocation %s against local symbol"),
5114 input_bfd, elfNN_aarch64_howto_table[howto_index].name);
5118 off = symbol_got_offset (input_bfd, h, r_symndx);
5119 base_got = globals->root.sgot;
5120 bfd_vma got_entry_addr = (base_got->output_section->vma
5121 + base_got->output_offset + off);
5123 if (!symbol_got_offset_mark_p (input_bfd, h, r_symndx))
5125 bfd_put_64 (output_bfd, value, base_got->contents + off);
5127 if (bfd_link_pic (info))
5130 Elf_Internal_Rela outrel;
5132 /* For local symbol, we have done absolute relocation in static
5133 linking stageh. While for share library, we need to update
5134 the content of GOT entry according to the share objects
5135 loading base address. So we need to generate a
5136 R_AARCH64_RELATIVE reloc for dynamic linker. */
5137 s = globals->root.srelgot;
5141 outrel.r_offset = got_entry_addr;
5142 outrel.r_info = ELFNN_R_INFO (0, AARCH64_R (RELATIVE));
5143 outrel.r_addend = value;
5144 elf_append_rela (output_bfd, s, &outrel);
5147 symbol_got_offset_mark (input_bfd, h, r_symndx);
5150 /* Update the relocation value to GOT entry addr as we have transformed
5151 the direct data access into indirect data access through GOT. */
5152 value = got_entry_addr;
5154 if (bfd_r_type == BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15
5155 || bfd_r_type == BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14)
5156 addend = base_got->output_section->vma + base_got->output_offset;
5158 value = _bfd_aarch64_elf_resolve_relocation (bfd_r_type, place, value,
5159 addend, weak_undef_p);
5164 case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC:
5165 case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21:
5166 case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21:
5167 case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21:
5168 case BFD_RELOC_AARCH64_TLSIE_LD32_GOTTPREL_LO12_NC:
5169 case BFD_RELOC_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC:
5170 case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19:
5171 case BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC:
5172 case BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21:
5173 case BFD_RELOC_AARCH64_TLSLD_ADR_PREL21:
5174 if (globals->root.sgot == NULL)
5175 return bfd_reloc_notsupported;
5177 value = (symbol_got_offset (input_bfd, h, r_symndx)
5178 + globals->root.sgot->output_section->vma
5179 + globals->root.sgot->output_offset);
5181 value = _bfd_aarch64_elf_resolve_relocation (bfd_r_type, place, value,
5183 *unresolved_reloc_p = FALSE;
5186 case BFD_RELOC_AARCH64_TLSLD_ADD_DTPREL_LO12:
5187 case BFD_RELOC_AARCH64_TLSLD_ADD_DTPREL_LO12_NC:
5188 value = _bfd_aarch64_elf_resolve_relocation (bfd_r_type, place, value,
5189 signed_addend - dtpoff_base (info),
5193 case BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_HI12:
5194 case BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_LO12:
5195 case BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_LO12_NC:
5196 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0:
5197 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC:
5198 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1:
5199 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1_NC:
5200 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G2:
5201 value = _bfd_aarch64_elf_resolve_relocation (bfd_r_type, place, value,
5202 signed_addend - tpoff_base (info),
5204 *unresolved_reloc_p = FALSE;
5207 case BFD_RELOC_AARCH64_TLSDESC_ADD:
5208 case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12_NC:
5209 case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21:
5210 case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21:
5211 case BFD_RELOC_AARCH64_TLSDESC_LD32_LO12_NC:
5212 case BFD_RELOC_AARCH64_TLSDESC_LD64_LO12_NC:
5213 case BFD_RELOC_AARCH64_TLSDESC_LDR:
5214 case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19:
5215 if (globals->root.sgot == NULL)
5216 return bfd_reloc_notsupported;
5217 value = (symbol_tlsdesc_got_offset (input_bfd, h, r_symndx)
5218 + globals->root.sgotplt->output_section->vma
5219 + globals->root.sgotplt->output_offset
5220 + globals->sgotplt_jump_table_size);
5222 value = _bfd_aarch64_elf_resolve_relocation (bfd_r_type, place, value,
5224 *unresolved_reloc_p = FALSE;
5228 return bfd_reloc_notsupported;
5232 *saved_addend = value;
5234 /* Only apply the final relocation in a sequence. */
5236 return bfd_reloc_continue;
5238 return _bfd_aarch64_elf_put_addend (input_bfd, hit_data, bfd_r_type,
5242 /* Handle TLS relaxations. Relaxing is possible for symbols that use
5243 R_AARCH64_TLSDESC_ADR_{PAGE, LD64_LO12_NC, ADD_LO12_NC} during a static
5246 Return bfd_reloc_ok if we're done, bfd_reloc_continue if the caller
5247 is to then call final_link_relocate. Return other values in the
5250 static bfd_reloc_status_type
5251 elfNN_aarch64_tls_relax (struct elf_aarch64_link_hash_table *globals,
5252 bfd *input_bfd, bfd_byte *contents,
5253 Elf_Internal_Rela *rel, struct elf_link_hash_entry *h)
5255 bfd_boolean is_local = h == NULL;
5256 unsigned int r_type = ELFNN_R_TYPE (rel->r_info);
5259 BFD_ASSERT (globals && input_bfd && contents && rel);
5261 switch (elfNN_aarch64_bfd_reloc_from_type (r_type))
5263 case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21:
5264 case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21:
5267 /* GD->LE relaxation:
5268 adrp x0, :tlsgd:var => movz x0, :tprel_g1:var
5270 adrp x0, :tlsdesc:var => movz x0, :tprel_g1:var
5272 bfd_putl32 (0xd2a00000, contents + rel->r_offset);
5273 return bfd_reloc_continue;
5277 /* GD->IE relaxation:
5278 adrp x0, :tlsgd:var => adrp x0, :gottprel:var
5280 adrp x0, :tlsdesc:var => adrp x0, :gottprel:var
5282 return bfd_reloc_continue;
5285 case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21:
5289 case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19:
5292 /* Tiny TLSDESC->LE relaxation:
5293 ldr x1, :tlsdesc:var => movz x0, #:tprel_g1:var
5294 adr x0, :tlsdesc:var => movk x0, #:tprel_g0_nc:var
5298 BFD_ASSERT (ELFNN_R_TYPE (rel[1].r_info) == AARCH64_R (TLSDESC_ADR_PREL21));
5299 BFD_ASSERT (ELFNN_R_TYPE (rel[2].r_info) == AARCH64_R (TLSDESC_CALL));
5301 rel[1].r_info = ELFNN_R_INFO (ELFNN_R_SYM (rel->r_info),
5302 AARCH64_R (TLSLE_MOVW_TPREL_G0_NC));
5303 rel[2].r_info = ELFNN_R_INFO (STN_UNDEF, R_AARCH64_NONE);
5305 bfd_putl32 (0xd2a00000, contents + rel->r_offset);
5306 bfd_putl32 (0xf2800000, contents + rel->r_offset + 4);
5307 bfd_putl32 (INSN_NOP, contents + rel->r_offset + 8);
5308 return bfd_reloc_continue;
5312 /* Tiny TLSDESC->IE relaxation:
5313 ldr x1, :tlsdesc:var => ldr x0, :gottprel:var
5314 adr x0, :tlsdesc:var => nop
5318 BFD_ASSERT (ELFNN_R_TYPE (rel[1].r_info) == AARCH64_R (TLSDESC_ADR_PREL21));
5319 BFD_ASSERT (ELFNN_R_TYPE (rel[2].r_info) == AARCH64_R (TLSDESC_CALL));
5321 rel[1].r_info = ELFNN_R_INFO (STN_UNDEF, R_AARCH64_NONE);
5322 rel[2].r_info = ELFNN_R_INFO (STN_UNDEF, R_AARCH64_NONE);
5324 bfd_putl32 (0x58000000, contents + rel->r_offset);
5325 bfd_putl32 (INSN_NOP, contents + rel->r_offset + 4);
5326 bfd_putl32 (INSN_NOP, contents + rel->r_offset + 8);
5327 return bfd_reloc_continue;
5330 case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21:
5333 /* Tiny GD->LE relaxation:
5334 adr x0, :tlsgd:var => mrs x1, tpidr_el0
5335 bl __tls_get_addr => add x0, x1, #:tprel_hi12:x, lsl #12
5336 nop => add x0, x0, #:tprel_lo12_nc:x
5339 /* First kill the tls_get_addr reloc on the bl instruction. */
5340 BFD_ASSERT (rel->r_offset + 4 == rel[1].r_offset);
5342 bfd_putl32 (0xd53bd041, contents + rel->r_offset + 0);
5343 bfd_putl32 (0x91400020, contents + rel->r_offset + 4);
5344 bfd_putl32 (0x91000000, contents + rel->r_offset + 8);
5346 rel[1].r_info = ELFNN_R_INFO (ELFNN_R_SYM (rel->r_info),
5347 AARCH64_R (TLSLE_ADD_TPREL_LO12_NC));
5348 rel[1].r_offset = rel->r_offset + 8;
5350 /* Move the current relocation to the second instruction in
5353 rel->r_info = ELFNN_R_INFO (ELFNN_R_SYM (rel->r_info),
5354 AARCH64_R (TLSLE_ADD_TPREL_HI12));
5355 return bfd_reloc_continue;
5359 /* Tiny GD->IE relaxation:
5360 adr x0, :tlsgd:var => ldr x0, :gottprel:var
5361 bl __tls_get_addr => mrs x1, tpidr_el0
5362 nop => add x0, x0, x1
5365 /* First kill the tls_get_addr reloc on the bl instruction. */
5366 BFD_ASSERT (rel->r_offset + 4 == rel[1].r_offset);
5367 rel[1].r_info = ELFNN_R_INFO (STN_UNDEF, R_AARCH64_NONE);
5369 bfd_putl32 (0x58000000, contents + rel->r_offset);
5370 bfd_putl32 (0xd53bd041, contents + rel->r_offset + 4);
5371 bfd_putl32 (0x8b000020, contents + rel->r_offset + 8);
5372 return bfd_reloc_continue;
5375 case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19:
5376 return bfd_reloc_continue;
5378 case BFD_RELOC_AARCH64_TLSDESC_LDNN_LO12_NC:
5381 /* GD->LE relaxation:
5382 ldr xd, [x0, #:tlsdesc_lo12:var] => movk x0, :tprel_g0_nc:var
5384 bfd_putl32 (0xf2800000, contents + rel->r_offset);
5385 return bfd_reloc_continue;
5389 /* GD->IE relaxation:
5390 ldr xd, [x0, #:tlsdesc_lo12:var] => ldr x0, [x0, #:gottprel_lo12:var]
5392 insn = bfd_getl32 (contents + rel->r_offset);
5394 bfd_putl32 (insn, contents + rel->r_offset);
5395 return bfd_reloc_continue;
5398 case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC:
5401 /* GD->LE relaxation
5402 add x0, #:tlsgd_lo12:var => movk x0, :tprel_g0_nc:var
5403 bl __tls_get_addr => mrs x1, tpidr_el0
5404 nop => add x0, x1, x0
5407 /* First kill the tls_get_addr reloc on the bl instruction. */
5408 BFD_ASSERT (rel->r_offset + 4 == rel[1].r_offset);
5409 rel[1].r_info = ELFNN_R_INFO (STN_UNDEF, R_AARCH64_NONE);
5411 bfd_putl32 (0xf2800000, contents + rel->r_offset);
5412 bfd_putl32 (0xd53bd041, contents + rel->r_offset + 4);
5413 bfd_putl32 (0x8b000020, contents + rel->r_offset + 8);
5414 return bfd_reloc_continue;
5418 /* GD->IE relaxation
5419 ADD x0, #:tlsgd_lo12:var => ldr x0, [x0, #:gottprel_lo12:var]
5420 BL __tls_get_addr => mrs x1, tpidr_el0
5422 NOP => add x0, x1, x0
5425 BFD_ASSERT (ELFNN_R_TYPE (rel[1].r_info) == AARCH64_R (CALL26));
5427 /* Remove the relocation on the BL instruction. */
5428 rel[1].r_info = ELFNN_R_INFO (STN_UNDEF, R_AARCH64_NONE);
5430 bfd_putl32 (0xf9400000, contents + rel->r_offset);
5432 /* We choose to fixup the BL and NOP instructions using the
5433 offset from the second relocation to allow flexibility in
5434 scheduling instructions between the ADD and BL. */
5435 bfd_putl32 (0xd53bd041, contents + rel[1].r_offset);
5436 bfd_putl32 (0x8b000020, contents + rel[1].r_offset + 4);
5437 return bfd_reloc_continue;
5440 case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12_NC:
5441 case BFD_RELOC_AARCH64_TLSDESC_CALL:
5442 /* GD->IE/LE relaxation:
5443 add x0, x0, #:tlsdesc_lo12:var => nop
5446 bfd_putl32 (INSN_NOP, contents + rel->r_offset);
5447 return bfd_reloc_ok;
5449 case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21:
5450 /* IE->LE relaxation:
5451 adrp xd, :gottprel:var => movz xd, :tprel_g1:var
5455 insn = bfd_getl32 (contents + rel->r_offset);
5456 bfd_putl32 (0xd2a00000 | (insn & 0x1f), contents + rel->r_offset);
5458 return bfd_reloc_continue;
5460 case BFD_RELOC_AARCH64_TLSIE_LDNN_GOTTPREL_LO12_NC:
5461 /* IE->LE relaxation:
5462 ldr xd, [xm, #:gottprel_lo12:var] => movk xd, :tprel_g0_nc:var
5466 insn = bfd_getl32 (contents + rel->r_offset);
5467 bfd_putl32 (0xf2800000 | (insn & 0x1f), contents + rel->r_offset);
5469 return bfd_reloc_continue;
5472 return bfd_reloc_continue;
5475 return bfd_reloc_ok;
5478 /* Relocate an AArch64 ELF section. */
5481 elfNN_aarch64_relocate_section (bfd *output_bfd,
5482 struct bfd_link_info *info,
5484 asection *input_section,
5486 Elf_Internal_Rela *relocs,
5487 Elf_Internal_Sym *local_syms,
5488 asection **local_sections)
5490 Elf_Internal_Shdr *symtab_hdr;
5491 struct elf_link_hash_entry **sym_hashes;
5492 Elf_Internal_Rela *rel;
5493 Elf_Internal_Rela *relend;
5495 struct elf_aarch64_link_hash_table *globals;
5496 bfd_boolean save_addend = FALSE;
5499 globals = elf_aarch64_hash_table (info);
5501 symtab_hdr = &elf_symtab_hdr (input_bfd);
5502 sym_hashes = elf_sym_hashes (input_bfd);
5505 relend = relocs + input_section->reloc_count;
5506 for (; rel < relend; rel++)
5508 unsigned int r_type;
5509 bfd_reloc_code_real_type bfd_r_type;
5510 bfd_reloc_code_real_type relaxed_bfd_r_type;
5511 reloc_howto_type *howto;
5512 unsigned long r_symndx;
5513 Elf_Internal_Sym *sym;
5515 struct elf_link_hash_entry *h;
5517 bfd_reloc_status_type r;
5520 bfd_boolean unresolved_reloc = FALSE;
5521 char *error_message = NULL;
5523 r_symndx = ELFNN_R_SYM (rel->r_info);
5524 r_type = ELFNN_R_TYPE (rel->r_info);
5526 bfd_reloc.howto = elfNN_aarch64_howto_from_type (r_type);
5527 howto = bfd_reloc.howto;
5531 (*_bfd_error_handler)
5532 (_("%B: unrecognized relocation (0x%x) in section `%A'"),
5533 input_bfd, input_section, r_type);
5536 bfd_r_type = elfNN_aarch64_bfd_reloc_from_howto (howto);
5542 if (r_symndx < symtab_hdr->sh_info)
5544 sym = local_syms + r_symndx;
5545 sym_type = ELFNN_ST_TYPE (sym->st_info);
5546 sec = local_sections[r_symndx];
5548 /* An object file might have a reference to a local
5549 undefined symbol. This is a daft object file, but we
5550 should at least do something about it. */
5551 if (r_type != R_AARCH64_NONE && r_type != R_AARCH64_NULL
5552 && bfd_is_und_section (sec)
5553 && ELF_ST_BIND (sym->st_info) != STB_WEAK)
5555 if (!info->callbacks->undefined_symbol
5556 (info, bfd_elf_string_from_elf_section
5557 (input_bfd, symtab_hdr->sh_link, sym->st_name),
5558 input_bfd, input_section, rel->r_offset, TRUE))
5562 relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel);
5564 /* Relocate against local STT_GNU_IFUNC symbol. */
5565 if (!bfd_link_relocatable (info)
5566 && ELF_ST_TYPE (sym->st_info) == STT_GNU_IFUNC)
5568 h = elfNN_aarch64_get_local_sym_hash (globals, input_bfd,
5573 /* Set STT_GNU_IFUNC symbol value. */
5574 h->root.u.def.value = sym->st_value;
5575 h->root.u.def.section = sec;
5580 bfd_boolean warned, ignored;
5582 RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel,
5583 r_symndx, symtab_hdr, sym_hashes,
5585 unresolved_reloc, warned, ignored);
5590 if (sec != NULL && discarded_section (sec))
5591 RELOC_AGAINST_DISCARDED_SECTION (info, input_bfd, input_section,
5592 rel, 1, relend, howto, 0, contents);
5594 if (bfd_link_relocatable (info))
5598 name = h->root.root.string;
5601 name = (bfd_elf_string_from_elf_section
5602 (input_bfd, symtab_hdr->sh_link, sym->st_name));
5603 if (name == NULL || *name == '\0')
5604 name = bfd_section_name (input_bfd, sec);
5608 && r_type != R_AARCH64_NONE
5609 && r_type != R_AARCH64_NULL
5611 || h->root.type == bfd_link_hash_defined
5612 || h->root.type == bfd_link_hash_defweak)
5613 && IS_AARCH64_TLS_RELOC (bfd_r_type) != (sym_type == STT_TLS))
5615 (*_bfd_error_handler)
5616 ((sym_type == STT_TLS
5617 ? _("%B(%A+0x%lx): %s used with TLS symbol %s")
5618 : _("%B(%A+0x%lx): %s used with non-TLS symbol %s")),
5620 input_section, (long) rel->r_offset, howto->name, name);
5623 /* We relax only if we can see that there can be a valid transition
5624 from a reloc type to another.
5625 We call elfNN_aarch64_final_link_relocate unless we're completely
5626 done, i.e., the relaxation produced the final output we want. */
5628 relaxed_bfd_r_type = aarch64_tls_transition (input_bfd, info, r_type,
5630 if (relaxed_bfd_r_type != bfd_r_type)
5632 bfd_r_type = relaxed_bfd_r_type;
5633 howto = elfNN_aarch64_howto_from_bfd_reloc (bfd_r_type);
5634 BFD_ASSERT (howto != NULL);
5635 r_type = howto->type;
5636 r = elfNN_aarch64_tls_relax (globals, input_bfd, contents, rel, h);
5637 unresolved_reloc = 0;
5640 r = bfd_reloc_continue;
5642 /* There may be multiple consecutive relocations for the
5643 same offset. In that case we are supposed to treat the
5644 output of each relocation as the addend for the next. */
5645 if (rel + 1 < relend
5646 && rel->r_offset == rel[1].r_offset
5647 && ELFNN_R_TYPE (rel[1].r_info) != R_AARCH64_NONE
5648 && ELFNN_R_TYPE (rel[1].r_info) != R_AARCH64_NULL)
5651 save_addend = FALSE;
5653 if (r == bfd_reloc_continue)
5654 r = elfNN_aarch64_final_link_relocate (howto, input_bfd, output_bfd,
5655 input_section, contents, rel,
5656 relocation, info, sec,
5657 h, &unresolved_reloc,
5658 save_addend, &addend, sym);
5660 switch (elfNN_aarch64_bfd_reloc_from_type (r_type))
5662 case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC:
5663 case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21:
5664 case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21:
5665 case BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC:
5666 case BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21:
5667 case BFD_RELOC_AARCH64_TLSLD_ADR_PREL21:
5668 if (! symbol_got_offset_mark_p (input_bfd, h, r_symndx))
5670 bfd_boolean need_relocs = FALSE;
5675 off = symbol_got_offset (input_bfd, h, r_symndx);
5676 indx = h && h->dynindx != -1 ? h->dynindx : 0;
5679 (bfd_link_pic (info) || indx != 0) &&
5681 || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
5682 || h->root.type != bfd_link_hash_undefweak);
5684 BFD_ASSERT (globals->root.srelgot != NULL);
5688 Elf_Internal_Rela rela;
5689 rela.r_info = ELFNN_R_INFO (indx, AARCH64_R (TLS_DTPMOD));
5691 rela.r_offset = globals->root.sgot->output_section->vma +
5692 globals->root.sgot->output_offset + off;
5695 loc = globals->root.srelgot->contents;
5696 loc += globals->root.srelgot->reloc_count++
5697 * RELOC_SIZE (htab);
5698 bfd_elfNN_swap_reloca_out (output_bfd, &rela, loc);
5700 bfd_reloc_code_real_type real_type =
5701 elfNN_aarch64_bfd_reloc_from_type (r_type);
5703 if (real_type == BFD_RELOC_AARCH64_TLSLD_ADR_PREL21
5704 || real_type == BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21
5705 || real_type == BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC)
5707 /* For local dynamic, don't generate DTPREL in any case.
5708 Initialize the DTPREL slot into zero, so we get module
5709 base address when invoke runtime TLS resolver. */
5710 bfd_put_NN (output_bfd, 0,
5711 globals->root.sgot->contents + off
5716 bfd_put_NN (output_bfd,
5717 relocation - dtpoff_base (info),
5718 globals->root.sgot->contents + off
5723 /* This TLS symbol is global. We emit a
5724 relocation to fixup the tls offset at load
5727 ELFNN_R_INFO (indx, AARCH64_R (TLS_DTPREL));
5730 (globals->root.sgot->output_section->vma
5731 + globals->root.sgot->output_offset + off
5734 loc = globals->root.srelgot->contents;
5735 loc += globals->root.srelgot->reloc_count++
5736 * RELOC_SIZE (globals);
5737 bfd_elfNN_swap_reloca_out (output_bfd, &rela, loc);
5738 bfd_put_NN (output_bfd, (bfd_vma) 0,
5739 globals->root.sgot->contents + off
5745 bfd_put_NN (output_bfd, (bfd_vma) 1,
5746 globals->root.sgot->contents + off);
5747 bfd_put_NN (output_bfd,
5748 relocation - dtpoff_base (info),
5749 globals->root.sgot->contents + off
5753 symbol_got_offset_mark (input_bfd, h, r_symndx);
5757 case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21:
5758 case BFD_RELOC_AARCH64_TLSIE_LDNN_GOTTPREL_LO12_NC:
5759 case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19:
5760 if (! symbol_got_offset_mark_p (input_bfd, h, r_symndx))
5762 bfd_boolean need_relocs = FALSE;
5767 off = symbol_got_offset (input_bfd, h, r_symndx);
5769 indx = h && h->dynindx != -1 ? h->dynindx : 0;
5772 (bfd_link_pic (info) || indx != 0) &&
5774 || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
5775 || h->root.type != bfd_link_hash_undefweak);
5777 BFD_ASSERT (globals->root.srelgot != NULL);
5781 Elf_Internal_Rela rela;
5784 rela.r_addend = relocation - dtpoff_base (info);
5788 rela.r_info = ELFNN_R_INFO (indx, AARCH64_R (TLS_TPREL));
5789 rela.r_offset = globals->root.sgot->output_section->vma +
5790 globals->root.sgot->output_offset + off;
5792 loc = globals->root.srelgot->contents;
5793 loc += globals->root.srelgot->reloc_count++
5794 * RELOC_SIZE (htab);
5796 bfd_elfNN_swap_reloca_out (output_bfd, &rela, loc);
5798 bfd_put_NN (output_bfd, rela.r_addend,
5799 globals->root.sgot->contents + off);
5802 bfd_put_NN (output_bfd, relocation - tpoff_base (info),
5803 globals->root.sgot->contents + off);
5805 symbol_got_offset_mark (input_bfd, h, r_symndx);
5809 case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12_NC:
5810 case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21:
5811 case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21:
5812 case BFD_RELOC_AARCH64_TLSDESC_LDNN_LO12_NC:
5813 case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19:
5814 if (! symbol_tlsdesc_got_offset_mark_p (input_bfd, h, r_symndx))
5816 bfd_boolean need_relocs = FALSE;
5817 int indx = h && h->dynindx != -1 ? h->dynindx : 0;
5818 bfd_vma off = symbol_tlsdesc_got_offset (input_bfd, h, r_symndx);
5820 need_relocs = (h == NULL
5821 || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
5822 || h->root.type != bfd_link_hash_undefweak);
5824 BFD_ASSERT (globals->root.srelgot != NULL);
5825 BFD_ASSERT (globals->root.sgot != NULL);
5830 Elf_Internal_Rela rela;
5831 rela.r_info = ELFNN_R_INFO (indx, AARCH64_R (TLSDESC));
5834 rela.r_offset = (globals->root.sgotplt->output_section->vma
5835 + globals->root.sgotplt->output_offset
5836 + off + globals->sgotplt_jump_table_size);
5839 rela.r_addend = relocation - dtpoff_base (info);
5841 /* Allocate the next available slot in the PLT reloc
5842 section to hold our R_AARCH64_TLSDESC, the next
5843 available slot is determined from reloc_count,
5844 which we step. But note, reloc_count was
5845 artifically moved down while allocating slots for
5846 real PLT relocs such that all of the PLT relocs
5847 will fit above the initial reloc_count and the
5848 extra stuff will fit below. */
5849 loc = globals->root.srelplt->contents;
5850 loc += globals->root.srelplt->reloc_count++
5851 * RELOC_SIZE (globals);
5853 bfd_elfNN_swap_reloca_out (output_bfd, &rela, loc);
5855 bfd_put_NN (output_bfd, (bfd_vma) 0,
5856 globals->root.sgotplt->contents + off +
5857 globals->sgotplt_jump_table_size);
5858 bfd_put_NN (output_bfd, (bfd_vma) 0,
5859 globals->root.sgotplt->contents + off +
5860 globals->sgotplt_jump_table_size +
5864 symbol_tlsdesc_got_offset_mark (input_bfd, h, r_symndx);
5875 /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
5876 because such sections are not SEC_ALLOC and thus ld.so will
5877 not process them. */
5878 if (unresolved_reloc
5879 && !((input_section->flags & SEC_DEBUGGING) != 0
5881 && _bfd_elf_section_offset (output_bfd, info, input_section,
5882 +rel->r_offset) != (bfd_vma) - 1)
5884 (*_bfd_error_handler)
5886 ("%B(%A+0x%lx): unresolvable %s relocation against symbol `%s'"),
5887 input_bfd, input_section, (long) rel->r_offset, howto->name,
5888 h->root.root.string);
5892 if (r != bfd_reloc_ok && r != bfd_reloc_continue)
5894 bfd_reloc_code_real_type real_r_type
5895 = elfNN_aarch64_bfd_reloc_from_type (r_type);
5899 case bfd_reloc_overflow:
5900 if (!(*info->callbacks->reloc_overflow)
5901 (info, (h ? &h->root : NULL), name, howto->name, (bfd_vma) 0,
5902 input_bfd, input_section, rel->r_offset))
5904 if (real_r_type == BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15
5905 || real_r_type == BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14)
5907 (*info->callbacks->warning)
5909 _("Too many GOT entries for -fpic, "
5910 "please recompile with -fPIC"),
5911 name, input_bfd, input_section, rel->r_offset);
5916 case bfd_reloc_undefined:
5917 if (!((*info->callbacks->undefined_symbol)
5918 (info, name, input_bfd, input_section,
5919 rel->r_offset, TRUE)))
5923 case bfd_reloc_outofrange:
5924 error_message = _("out of range");
5927 case bfd_reloc_notsupported:
5928 error_message = _("unsupported relocation");
5931 case bfd_reloc_dangerous:
5932 /* error_message should already be set. */
5936 error_message = _("unknown error");
5940 BFD_ASSERT (error_message != NULL);
5941 if (!((*info->callbacks->reloc_dangerous)
5942 (info, error_message, input_bfd, input_section,
5953 /* Set the right machine number. */
5956 elfNN_aarch64_object_p (bfd *abfd)
5959 bfd_default_set_arch_mach (abfd, bfd_arch_aarch64, bfd_mach_aarch64_ilp32);
5961 bfd_default_set_arch_mach (abfd, bfd_arch_aarch64, bfd_mach_aarch64);
5966 /* Function to keep AArch64 specific flags in the ELF header. */
5969 elfNN_aarch64_set_private_flags (bfd *abfd, flagword flags)
5971 if (elf_flags_init (abfd) && elf_elfheader (abfd)->e_flags != flags)
5976 elf_elfheader (abfd)->e_flags = flags;
5977 elf_flags_init (abfd) = TRUE;
5983 /* Merge backend specific data from an object file to the output
5984 object file when linking. */
5987 elfNN_aarch64_merge_private_bfd_data (bfd *ibfd, bfd *obfd)
5991 bfd_boolean flags_compatible = TRUE;
5994 /* Check if we have the same endianess. */
5995 if (!_bfd_generic_verify_endian_match (ibfd, obfd))
5998 if (!is_aarch64_elf (ibfd) || !is_aarch64_elf (obfd))
6001 /* The input BFD must have had its flags initialised. */
6002 /* The following seems bogus to me -- The flags are initialized in
6003 the assembler but I don't think an elf_flags_init field is
6004 written into the object. */
6005 /* BFD_ASSERT (elf_flags_init (ibfd)); */
6007 in_flags = elf_elfheader (ibfd)->e_flags;
6008 out_flags = elf_elfheader (obfd)->e_flags;
6010 if (!elf_flags_init (obfd))
6012 /* If the input is the default architecture and had the default
6013 flags then do not bother setting the flags for the output
6014 architecture, instead allow future merges to do this. If no
6015 future merges ever set these flags then they will retain their
6016 uninitialised values, which surprise surprise, correspond
6017 to the default values. */
6018 if (bfd_get_arch_info (ibfd)->the_default
6019 && elf_elfheader (ibfd)->e_flags == 0)
6022 elf_flags_init (obfd) = TRUE;
6023 elf_elfheader (obfd)->e_flags = in_flags;
6025 if (bfd_get_arch (obfd) == bfd_get_arch (ibfd)
6026 && bfd_get_arch_info (obfd)->the_default)
6027 return bfd_set_arch_mach (obfd, bfd_get_arch (ibfd),
6028 bfd_get_mach (ibfd));
6033 /* Identical flags must be compatible. */
6034 if (in_flags == out_flags)
6037 /* Check to see if the input BFD actually contains any sections. If
6038 not, its flags may not have been initialised either, but it
6039 cannot actually cause any incompatiblity. Do not short-circuit
6040 dynamic objects; their section list may be emptied by
6041 elf_link_add_object_symbols.
6043 Also check to see if there are no code sections in the input.
6044 In this case there is no need to check for code specific flags.
6045 XXX - do we need to worry about floating-point format compatability
6046 in data sections ? */
6047 if (!(ibfd->flags & DYNAMIC))
6049 bfd_boolean null_input_bfd = TRUE;
6050 bfd_boolean only_data_sections = TRUE;
6052 for (sec = ibfd->sections; sec != NULL; sec = sec->next)
6054 if ((bfd_get_section_flags (ibfd, sec)
6055 & (SEC_LOAD | SEC_CODE | SEC_HAS_CONTENTS))
6056 == (SEC_LOAD | SEC_CODE | SEC_HAS_CONTENTS))
6057 only_data_sections = FALSE;
6059 null_input_bfd = FALSE;
6063 if (null_input_bfd || only_data_sections)
6067 return flags_compatible;
6070 /* Display the flags field. */
6073 elfNN_aarch64_print_private_bfd_data (bfd *abfd, void *ptr)
6075 FILE *file = (FILE *) ptr;
6076 unsigned long flags;
6078 BFD_ASSERT (abfd != NULL && ptr != NULL);
6080 /* Print normal ELF private data. */
6081 _bfd_elf_print_private_bfd_data (abfd, ptr);
6083 flags = elf_elfheader (abfd)->e_flags;
6084 /* Ignore init flag - it may not be set, despite the flags field
6085 containing valid data. */
6087 /* xgettext:c-format */
6088 fprintf (file, _("private flags = %lx:"), elf_elfheader (abfd)->e_flags);
6091 fprintf (file, _("<Unrecognised flag bits set>"));
6098 /* Update the got entry reference counts for the section being removed. */
6101 elfNN_aarch64_gc_sweep_hook (bfd *abfd,
6102 struct bfd_link_info *info,
6104 const Elf_Internal_Rela * relocs)
6106 struct elf_aarch64_link_hash_table *htab;
6107 Elf_Internal_Shdr *symtab_hdr;
6108 struct elf_link_hash_entry **sym_hashes;
6109 struct elf_aarch64_local_symbol *locals;
6110 const Elf_Internal_Rela *rel, *relend;
6112 if (bfd_link_relocatable (info))
6115 htab = elf_aarch64_hash_table (info);
6120 elf_section_data (sec)->local_dynrel = NULL;
6122 symtab_hdr = &elf_symtab_hdr (abfd);
6123 sym_hashes = elf_sym_hashes (abfd);
6125 locals = elf_aarch64_locals (abfd);
6127 relend = relocs + sec->reloc_count;
6128 for (rel = relocs; rel < relend; rel++)
6130 unsigned long r_symndx;
6131 unsigned int r_type;
6132 struct elf_link_hash_entry *h = NULL;
6134 r_symndx = ELFNN_R_SYM (rel->r_info);
6136 if (r_symndx >= symtab_hdr->sh_info)
6139 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
6140 while (h->root.type == bfd_link_hash_indirect
6141 || h->root.type == bfd_link_hash_warning)
6142 h = (struct elf_link_hash_entry *) h->root.u.i.link;
6146 Elf_Internal_Sym *isym;
6148 /* A local symbol. */
6149 isym = bfd_sym_from_r_symndx (&htab->sym_cache,
6152 /* Check relocation against local STT_GNU_IFUNC symbol. */
6154 && ELF_ST_TYPE (isym->st_info) == STT_GNU_IFUNC)
6156 h = elfNN_aarch64_get_local_sym_hash (htab, abfd, rel, FALSE);
6164 struct elf_aarch64_link_hash_entry *eh;
6165 struct elf_dyn_relocs **pp;
6166 struct elf_dyn_relocs *p;
6168 eh = (struct elf_aarch64_link_hash_entry *) h;
6170 for (pp = &eh->dyn_relocs; (p = *pp) != NULL; pp = &p->next)
6173 /* Everything must go for SEC. */
6179 r_type = ELFNN_R_TYPE (rel->r_info);
6180 switch (aarch64_tls_transition (abfd,info, r_type, h ,r_symndx))
6182 case BFD_RELOC_AARCH64_ADR_GOT_PAGE:
6183 case BFD_RELOC_AARCH64_GOT_LD_PREL19:
6184 case BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14:
6185 case BFD_RELOC_AARCH64_LD32_GOT_LO12_NC:
6186 case BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15:
6187 case BFD_RELOC_AARCH64_LD64_GOT_LO12_NC:
6188 case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12_NC:
6189 case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21:
6190 case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21:
6191 case BFD_RELOC_AARCH64_TLSDESC_LD32_LO12_NC:
6192 case BFD_RELOC_AARCH64_TLSDESC_LD64_LO12_NC:
6193 case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19:
6194 case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC:
6195 case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21:
6196 case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21:
6197 case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21:
6198 case BFD_RELOC_AARCH64_TLSIE_LD32_GOTTPREL_LO12_NC:
6199 case BFD_RELOC_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC:
6200 case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19:
6201 case BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC:
6202 case BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21:
6203 case BFD_RELOC_AARCH64_TLSLD_ADR_PREL21:
6206 if (h->got.refcount > 0)
6207 h->got.refcount -= 1;
6209 if (h->type == STT_GNU_IFUNC)
6211 if (h->plt.refcount > 0)
6212 h->plt.refcount -= 1;
6215 else if (locals != NULL)
6217 if (locals[r_symndx].got_refcount > 0)
6218 locals[r_symndx].got_refcount -= 1;
6222 case BFD_RELOC_AARCH64_CALL26:
6223 case BFD_RELOC_AARCH64_JUMP26:
6224 /* If this is a local symbol then we resolve it
6225 directly without creating a PLT entry. */
6229 if (h->plt.refcount > 0)
6230 h->plt.refcount -= 1;
6233 case BFD_RELOC_AARCH64_ADR_HI21_NC_PCREL:
6234 case BFD_RELOC_AARCH64_ADR_HI21_PCREL:
6235 case BFD_RELOC_AARCH64_ADR_LO21_PCREL:
6236 case BFD_RELOC_AARCH64_MOVW_G0_NC:
6237 case BFD_RELOC_AARCH64_MOVW_G1_NC:
6238 case BFD_RELOC_AARCH64_MOVW_G2_NC:
6239 case BFD_RELOC_AARCH64_MOVW_G3:
6240 case BFD_RELOC_AARCH64_NN:
6241 if (h != NULL && bfd_link_executable (info))
6243 if (h->plt.refcount > 0)
6244 h->plt.refcount -= 1;
6256 /* Adjust a symbol defined by a dynamic object and referenced by a
6257 regular object. The current definition is in some section of the
6258 dynamic object, but we're not including those sections. We have to
6259 change the definition to something the rest of the link can
6263 elfNN_aarch64_adjust_dynamic_symbol (struct bfd_link_info *info,
6264 struct elf_link_hash_entry *h)
6266 struct elf_aarch64_link_hash_table *htab;
6269 /* If this is a function, put it in the procedure linkage table. We
6270 will fill in the contents of the procedure linkage table later,
6271 when we know the address of the .got section. */
6272 if (h->type == STT_FUNC || h->type == STT_GNU_IFUNC || h->needs_plt)
6274 if (h->plt.refcount <= 0
6275 || (h->type != STT_GNU_IFUNC
6276 && (SYMBOL_CALLS_LOCAL (info, h)
6277 || (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
6278 && h->root.type == bfd_link_hash_undefweak))))
6280 /* This case can occur if we saw a CALL26 reloc in
6281 an input file, but the symbol wasn't referred to
6282 by a dynamic object or all references were
6283 garbage collected. In which case we can end up
6285 h->plt.offset = (bfd_vma) - 1;
6292 /* Otherwise, reset to -1. */
6293 h->plt.offset = (bfd_vma) - 1;
6296 /* If this is a weak symbol, and there is a real definition, the
6297 processor independent code will have arranged for us to see the
6298 real definition first, and we can just use the same value. */
6299 if (h->u.weakdef != NULL)
6301 BFD_ASSERT (h->u.weakdef->root.type == bfd_link_hash_defined
6302 || h->u.weakdef->root.type == bfd_link_hash_defweak);
6303 h->root.u.def.section = h->u.weakdef->root.u.def.section;
6304 h->root.u.def.value = h->u.weakdef->root.u.def.value;
6305 if (ELIMINATE_COPY_RELOCS || info->nocopyreloc)
6306 h->non_got_ref = h->u.weakdef->non_got_ref;
6310 /* If we are creating a shared library, we must presume that the
6311 only references to the symbol are via the global offset table.
6312 For such cases we need not do anything here; the relocations will
6313 be handled correctly by relocate_section. */
6314 if (bfd_link_pic (info))
6317 /* If there are no references to this symbol that do not use the
6318 GOT, we don't need to generate a copy reloc. */
6319 if (!h->non_got_ref)
6322 /* If -z nocopyreloc was given, we won't generate them either. */
6323 if (info->nocopyreloc)
6329 /* We must allocate the symbol in our .dynbss section, which will
6330 become part of the .bss section of the executable. There will be
6331 an entry for this symbol in the .dynsym section. The dynamic
6332 object will contain position independent code, so all references
6333 from the dynamic object to this symbol will go through the global
6334 offset table. The dynamic linker will use the .dynsym entry to
6335 determine the address it must put in the global offset table, so
6336 both the dynamic object and the regular object will refer to the
6337 same memory location for the variable. */
6339 htab = elf_aarch64_hash_table (info);
6341 /* We must generate a R_AARCH64_COPY reloc to tell the dynamic linker
6342 to copy the initial value out of the dynamic object and into the
6343 runtime process image. */
6344 if ((h->root.u.def.section->flags & SEC_ALLOC) != 0 && h->size != 0)
6346 htab->srelbss->size += RELOC_SIZE (htab);
6352 return _bfd_elf_adjust_dynamic_copy (info, h, s);
6357 elfNN_aarch64_allocate_local_symbols (bfd *abfd, unsigned number)
6359 struct elf_aarch64_local_symbol *locals;
6360 locals = elf_aarch64_locals (abfd);
6363 locals = (struct elf_aarch64_local_symbol *)
6364 bfd_zalloc (abfd, number * sizeof (struct elf_aarch64_local_symbol));
6367 elf_aarch64_locals (abfd) = locals;
6372 /* Create the .got section to hold the global offset table. */
6375 aarch64_elf_create_got_section (bfd *abfd, struct bfd_link_info *info)
6377 const struct elf_backend_data *bed = get_elf_backend_data (abfd);
6380 struct elf_link_hash_entry *h;
6381 struct elf_link_hash_table *htab = elf_hash_table (info);
6383 /* This function may be called more than once. */
6384 s = bfd_get_linker_section (abfd, ".got");
6388 flags = bed->dynamic_sec_flags;
6390 s = bfd_make_section_anyway_with_flags (abfd,
6391 (bed->rela_plts_and_copies_p
6392 ? ".rela.got" : ".rel.got"),
6393 (bed->dynamic_sec_flags
6396 || ! bfd_set_section_alignment (abfd, s, bed->s->log_file_align))
6400 s = bfd_make_section_anyway_with_flags (abfd, ".got", flags);
6402 || !bfd_set_section_alignment (abfd, s, bed->s->log_file_align))
6405 htab->sgot->size += GOT_ENTRY_SIZE;
6407 if (bed->want_got_sym)
6409 /* Define the symbol _GLOBAL_OFFSET_TABLE_ at the start of the .got
6410 (or .got.plt) section. We don't do this in the linker script
6411 because we don't want to define the symbol if we are not creating
6412 a global offset table. */
6413 h = _bfd_elf_define_linkage_sym (abfd, info, s,
6414 "_GLOBAL_OFFSET_TABLE_");
6415 elf_hash_table (info)->hgot = h;
6420 if (bed->want_got_plt)
6422 s = bfd_make_section_anyway_with_flags (abfd, ".got.plt", flags);
6424 || !bfd_set_section_alignment (abfd, s,
6425 bed->s->log_file_align))
6430 /* The first bit of the global offset table is the header. */
6431 s->size += bed->got_header_size;
6436 /* Look through the relocs for a section during the first phase. */
6439 elfNN_aarch64_check_relocs (bfd *abfd, struct bfd_link_info *info,
6440 asection *sec, const Elf_Internal_Rela *relocs)
6442 Elf_Internal_Shdr *symtab_hdr;
6443 struct elf_link_hash_entry **sym_hashes;
6444 const Elf_Internal_Rela *rel;
6445 const Elf_Internal_Rela *rel_end;
6448 struct elf_aarch64_link_hash_table *htab;
6450 if (bfd_link_relocatable (info))
6453 BFD_ASSERT (is_aarch64_elf (abfd));
6455 htab = elf_aarch64_hash_table (info);
6458 symtab_hdr = &elf_symtab_hdr (abfd);
6459 sym_hashes = elf_sym_hashes (abfd);
6461 rel_end = relocs + sec->reloc_count;
6462 for (rel = relocs; rel < rel_end; rel++)
6464 struct elf_link_hash_entry *h;
6465 unsigned long r_symndx;
6466 unsigned int r_type;
6467 bfd_reloc_code_real_type bfd_r_type;
6468 Elf_Internal_Sym *isym;
6470 r_symndx = ELFNN_R_SYM (rel->r_info);
6471 r_type = ELFNN_R_TYPE (rel->r_info);
6473 if (r_symndx >= NUM_SHDR_ENTRIES (symtab_hdr))
6475 (*_bfd_error_handler) (_("%B: bad symbol index: %d"), abfd,
6480 if (r_symndx < symtab_hdr->sh_info)
6482 /* A local symbol. */
6483 isym = bfd_sym_from_r_symndx (&htab->sym_cache,
6488 /* Check relocation against local STT_GNU_IFUNC symbol. */
6489 if (ELF_ST_TYPE (isym->st_info) == STT_GNU_IFUNC)
6491 h = elfNN_aarch64_get_local_sym_hash (htab, abfd, rel,
6496 /* Fake a STT_GNU_IFUNC symbol. */
6497 h->type = STT_GNU_IFUNC;
6500 h->forced_local = 1;
6501 h->root.type = bfd_link_hash_defined;
6508 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
6509 while (h->root.type == bfd_link_hash_indirect
6510 || h->root.type == bfd_link_hash_warning)
6511 h = (struct elf_link_hash_entry *) h->root.u.i.link;
6513 /* PR15323, ref flags aren't set for references in the same
6515 h->root.non_ir_ref = 1;
6518 /* Could be done earlier, if h were already available. */
6519 bfd_r_type = aarch64_tls_transition (abfd, info, r_type, h, r_symndx);
6523 /* Create the ifunc sections for static executables. If we
6524 never see an indirect function symbol nor we are building
6525 a static executable, those sections will be empty and
6526 won't appear in output. */
6532 case BFD_RELOC_AARCH64_ADD_LO12:
6533 case BFD_RELOC_AARCH64_ADR_GOT_PAGE:
6534 case BFD_RELOC_AARCH64_ADR_HI21_PCREL:
6535 case BFD_RELOC_AARCH64_CALL26:
6536 case BFD_RELOC_AARCH64_GOT_LD_PREL19:
6537 case BFD_RELOC_AARCH64_JUMP26:
6538 case BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14:
6539 case BFD_RELOC_AARCH64_LD32_GOT_LO12_NC:
6540 case BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15:
6541 case BFD_RELOC_AARCH64_LD64_GOT_LO12_NC:
6542 case BFD_RELOC_AARCH64_NN:
6543 if (htab->root.dynobj == NULL)
6544 htab->root.dynobj = abfd;
6545 if (!_bfd_elf_create_ifunc_sections (htab->root.dynobj, info))
6550 /* It is referenced by a non-shared object. */
6552 h->root.non_ir_ref = 1;
6557 case BFD_RELOC_AARCH64_NN:
6559 /* We don't need to handle relocs into sections not going into
6560 the "real" output. */
6561 if ((sec->flags & SEC_ALLOC) == 0)
6566 if (!bfd_link_pic (info))
6569 h->plt.refcount += 1;
6570 h->pointer_equality_needed = 1;
6573 /* No need to do anything if we're not creating a shared
6575 if (! bfd_link_pic (info))
6579 struct elf_dyn_relocs *p;
6580 struct elf_dyn_relocs **head;
6582 /* We must copy these reloc types into the output file.
6583 Create a reloc section in dynobj and make room for
6587 if (htab->root.dynobj == NULL)
6588 htab->root.dynobj = abfd;
6590 sreloc = _bfd_elf_make_dynamic_reloc_section
6591 (sec, htab->root.dynobj, LOG_FILE_ALIGN, abfd, /*rela? */ TRUE);
6597 /* If this is a global symbol, we count the number of
6598 relocations we need for this symbol. */
6601 struct elf_aarch64_link_hash_entry *eh;
6602 eh = (struct elf_aarch64_link_hash_entry *) h;
6603 head = &eh->dyn_relocs;
6607 /* Track dynamic relocs needed for local syms too.
6608 We really need local syms available to do this
6614 isym = bfd_sym_from_r_symndx (&htab->sym_cache,
6619 s = bfd_section_from_elf_index (abfd, isym->st_shndx);
6623 /* Beware of type punned pointers vs strict aliasing
6625 vpp = &(elf_section_data (s)->local_dynrel);
6626 head = (struct elf_dyn_relocs **) vpp;
6630 if (p == NULL || p->sec != sec)
6632 bfd_size_type amt = sizeof *p;
6633 p = ((struct elf_dyn_relocs *)
6634 bfd_zalloc (htab->root.dynobj, amt));
6647 /* RR: We probably want to keep a consistency check that
6648 there are no dangling GOT_PAGE relocs. */
6649 case BFD_RELOC_AARCH64_ADR_GOT_PAGE:
6650 case BFD_RELOC_AARCH64_GOT_LD_PREL19:
6651 case BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14:
6652 case BFD_RELOC_AARCH64_LD32_GOT_LO12_NC:
6653 case BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15:
6654 case BFD_RELOC_AARCH64_LD64_GOT_LO12_NC:
6655 case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12_NC:
6656 case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21:
6657 case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21:
6658 case BFD_RELOC_AARCH64_TLSDESC_LD32_LO12_NC:
6659 case BFD_RELOC_AARCH64_TLSDESC_LD64_LO12_NC:
6660 case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19:
6661 case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC:
6662 case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21:
6663 case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21:
6664 case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21:
6665 case BFD_RELOC_AARCH64_TLSIE_LD32_GOTTPREL_LO12_NC:
6666 case BFD_RELOC_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC:
6667 case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19:
6668 case BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC:
6669 case BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21:
6670 case BFD_RELOC_AARCH64_TLSLD_ADR_PREL21:
6673 unsigned old_got_type;
6675 got_type = aarch64_reloc_got_type (bfd_r_type);
6679 h->got.refcount += 1;
6680 old_got_type = elf_aarch64_hash_entry (h)->got_type;
6684 struct elf_aarch64_local_symbol *locals;
6686 if (!elfNN_aarch64_allocate_local_symbols
6687 (abfd, symtab_hdr->sh_info))
6690 locals = elf_aarch64_locals (abfd);
6691 BFD_ASSERT (r_symndx < symtab_hdr->sh_info);
6692 locals[r_symndx].got_refcount += 1;
6693 old_got_type = locals[r_symndx].got_type;
6696 /* If a variable is accessed with both general dynamic TLS
6697 methods, two slots may be created. */
6698 if (GOT_TLS_GD_ANY_P (old_got_type) && GOT_TLS_GD_ANY_P (got_type))
6699 got_type |= old_got_type;
6701 /* We will already have issued an error message if there
6702 is a TLS/non-TLS mismatch, based on the symbol type.
6703 So just combine any TLS types needed. */
6704 if (old_got_type != GOT_UNKNOWN && old_got_type != GOT_NORMAL
6705 && got_type != GOT_NORMAL)
6706 got_type |= old_got_type;
6708 /* If the symbol is accessed by both IE and GD methods, we
6709 are able to relax. Turn off the GD flag, without
6710 messing up with any other kind of TLS types that may be
6712 if ((got_type & GOT_TLS_IE) && GOT_TLS_GD_ANY_P (got_type))
6713 got_type &= ~ (GOT_TLSDESC_GD | GOT_TLS_GD);
6715 if (old_got_type != got_type)
6718 elf_aarch64_hash_entry (h)->got_type = got_type;
6721 struct elf_aarch64_local_symbol *locals;
6722 locals = elf_aarch64_locals (abfd);
6723 BFD_ASSERT (r_symndx < symtab_hdr->sh_info);
6724 locals[r_symndx].got_type = got_type;
6728 if (htab->root.dynobj == NULL)
6729 htab->root.dynobj = abfd;
6730 if (! aarch64_elf_create_got_section (htab->root.dynobj, info))
6735 case BFD_RELOC_AARCH64_MOVW_G0_NC:
6736 case BFD_RELOC_AARCH64_MOVW_G1_NC:
6737 case BFD_RELOC_AARCH64_MOVW_G2_NC:
6738 case BFD_RELOC_AARCH64_MOVW_G3:
6739 if (bfd_link_pic (info))
6741 int howto_index = bfd_r_type - BFD_RELOC_AARCH64_RELOC_START;
6742 (*_bfd_error_handler)
6743 (_("%B: relocation %s against `%s' can not be used when making "
6744 "a shared object; recompile with -fPIC"),
6745 abfd, elfNN_aarch64_howto_table[howto_index].name,
6746 (h) ? h->root.root.string : "a local symbol");
6747 bfd_set_error (bfd_error_bad_value);
6751 case BFD_RELOC_AARCH64_ADR_HI21_NC_PCREL:
6752 case BFD_RELOC_AARCH64_ADR_HI21_PCREL:
6753 case BFD_RELOC_AARCH64_ADR_LO21_PCREL:
6754 if (h != NULL && bfd_link_executable (info))
6756 /* If this reloc is in a read-only section, we might
6757 need a copy reloc. We can't check reliably at this
6758 stage whether the section is read-only, as input
6759 sections have not yet been mapped to output sections.
6760 Tentatively set the flag for now, and correct in
6761 adjust_dynamic_symbol. */
6763 h->plt.refcount += 1;
6764 h->pointer_equality_needed = 1;
6766 /* FIXME:: RR need to handle these in shared libraries
6767 and essentially bomb out as these being non-PIC
6768 relocations in shared libraries. */
6771 case BFD_RELOC_AARCH64_CALL26:
6772 case BFD_RELOC_AARCH64_JUMP26:
6773 /* If this is a local symbol then we resolve it
6774 directly without creating a PLT entry. */
6779 if (h->plt.refcount <= 0)
6780 h->plt.refcount = 1;
6782 h->plt.refcount += 1;
6793 /* Treat mapping symbols as special target symbols. */
6796 elfNN_aarch64_is_target_special_symbol (bfd *abfd ATTRIBUTE_UNUSED,
6799 return bfd_is_aarch64_special_symbol_name (sym->name,
6800 BFD_AARCH64_SPECIAL_SYM_TYPE_ANY);
6803 /* This is a copy of elf_find_function () from elf.c except that
6804 AArch64 mapping symbols are ignored when looking for function names. */
6807 aarch64_elf_find_function (bfd *abfd ATTRIBUTE_UNUSED,
6811 const char **filename_ptr,
6812 const char **functionname_ptr)
6814 const char *filename = NULL;
6815 asymbol *func = NULL;
6816 bfd_vma low_func = 0;
6819 for (p = symbols; *p != NULL; p++)
6823 q = (elf_symbol_type *) * p;
6825 switch (ELF_ST_TYPE (q->internal_elf_sym.st_info))
6830 filename = bfd_asymbol_name (&q->symbol);
6834 /* Skip mapping symbols. */
6835 if ((q->symbol.flags & BSF_LOCAL)
6836 && (bfd_is_aarch64_special_symbol_name
6837 (q->symbol.name, BFD_AARCH64_SPECIAL_SYM_TYPE_ANY)))
6840 if (bfd_get_section (&q->symbol) == section
6841 && q->symbol.value >= low_func && q->symbol.value <= offset)
6843 func = (asymbol *) q;
6844 low_func = q->symbol.value;
6854 *filename_ptr = filename;
6855 if (functionname_ptr)
6856 *functionname_ptr = bfd_asymbol_name (func);
6862 /* Find the nearest line to a particular section and offset, for error
6863 reporting. This code is a duplicate of the code in elf.c, except
6864 that it uses aarch64_elf_find_function. */
6867 elfNN_aarch64_find_nearest_line (bfd *abfd,
6871 const char **filename_ptr,
6872 const char **functionname_ptr,
6873 unsigned int *line_ptr,
6874 unsigned int *discriminator_ptr)
6876 bfd_boolean found = FALSE;
6878 if (_bfd_dwarf2_find_nearest_line (abfd, symbols, NULL, section, offset,
6879 filename_ptr, functionname_ptr,
6880 line_ptr, discriminator_ptr,
6881 dwarf_debug_sections, 0,
6882 &elf_tdata (abfd)->dwarf2_find_line_info))
6884 if (!*functionname_ptr)
6885 aarch64_elf_find_function (abfd, symbols, section, offset,
6886 *filename_ptr ? NULL : filename_ptr,
6892 /* Skip _bfd_dwarf1_find_nearest_line since no known AArch64
6893 toolchain uses DWARF1. */
6895 if (!_bfd_stab_section_find_nearest_line (abfd, symbols, section, offset,
6896 &found, filename_ptr,
6897 functionname_ptr, line_ptr,
6898 &elf_tdata (abfd)->line_info))
6901 if (found && (*functionname_ptr || *line_ptr))
6904 if (symbols == NULL)
6907 if (!aarch64_elf_find_function (abfd, symbols, section, offset,
6908 filename_ptr, functionname_ptr))
6916 elfNN_aarch64_find_inliner_info (bfd *abfd,
6917 const char **filename_ptr,
6918 const char **functionname_ptr,
6919 unsigned int *line_ptr)
6922 found = _bfd_dwarf2_find_inliner_info
6923 (abfd, filename_ptr,
6924 functionname_ptr, line_ptr, &elf_tdata (abfd)->dwarf2_find_line_info);
6930 elfNN_aarch64_post_process_headers (bfd *abfd,
6931 struct bfd_link_info *link_info)
6933 Elf_Internal_Ehdr *i_ehdrp; /* ELF file header, internal form. */
6935 i_ehdrp = elf_elfheader (abfd);
6936 i_ehdrp->e_ident[EI_ABIVERSION] = AARCH64_ELF_ABI_VERSION;
6938 _bfd_elf_post_process_headers (abfd, link_info);
6941 static enum elf_reloc_type_class
6942 elfNN_aarch64_reloc_type_class (const struct bfd_link_info *info ATTRIBUTE_UNUSED,
6943 const asection *rel_sec ATTRIBUTE_UNUSED,
6944 const Elf_Internal_Rela *rela)
6946 switch ((int) ELFNN_R_TYPE (rela->r_info))
6948 case AARCH64_R (RELATIVE):
6949 return reloc_class_relative;
6950 case AARCH64_R (JUMP_SLOT):
6951 return reloc_class_plt;
6952 case AARCH64_R (COPY):
6953 return reloc_class_copy;
6955 return reloc_class_normal;
6959 /* Handle an AArch64 specific section when reading an object file. This is
6960 called when bfd_section_from_shdr finds a section with an unknown
6964 elfNN_aarch64_section_from_shdr (bfd *abfd,
6965 Elf_Internal_Shdr *hdr,
6966 const char *name, int shindex)
6968 /* There ought to be a place to keep ELF backend specific flags, but
6969 at the moment there isn't one. We just keep track of the
6970 sections by their name, instead. Fortunately, the ABI gives
6971 names for all the AArch64 specific sections, so we will probably get
6973 switch (hdr->sh_type)
6975 case SHT_AARCH64_ATTRIBUTES:
6982 if (!_bfd_elf_make_section_from_shdr (abfd, hdr, name, shindex))
6988 /* A structure used to record a list of sections, independently
6989 of the next and prev fields in the asection structure. */
6990 typedef struct section_list
6993 struct section_list *next;
6994 struct section_list *prev;
6998 /* Unfortunately we need to keep a list of sections for which
6999 an _aarch64_elf_section_data structure has been allocated. This
7000 is because it is possible for functions like elfNN_aarch64_write_section
7001 to be called on a section which has had an elf_data_structure
7002 allocated for it (and so the used_by_bfd field is valid) but
7003 for which the AArch64 extended version of this structure - the
7004 _aarch64_elf_section_data structure - has not been allocated. */
7005 static section_list *sections_with_aarch64_elf_section_data = NULL;
7008 record_section_with_aarch64_elf_section_data (asection *sec)
7010 struct section_list *entry;
7012 entry = bfd_malloc (sizeof (*entry));
7016 entry->next = sections_with_aarch64_elf_section_data;
7018 if (entry->next != NULL)
7019 entry->next->prev = entry;
7020 sections_with_aarch64_elf_section_data = entry;
7023 static struct section_list *
7024 find_aarch64_elf_section_entry (asection *sec)
7026 struct section_list *entry;
7027 static struct section_list *last_entry = NULL;
7029 /* This is a short cut for the typical case where the sections are added
7030 to the sections_with_aarch64_elf_section_data list in forward order and
7031 then looked up here in backwards order. This makes a real difference
7032 to the ld-srec/sec64k.exp linker test. */
7033 entry = sections_with_aarch64_elf_section_data;
7034 if (last_entry != NULL)
7036 if (last_entry->sec == sec)
7038 else if (last_entry->next != NULL && last_entry->next->sec == sec)
7039 entry = last_entry->next;
7042 for (; entry; entry = entry->next)
7043 if (entry->sec == sec)
7047 /* Record the entry prior to this one - it is the entry we are
7048 most likely to want to locate next time. Also this way if we
7049 have been called from
7050 unrecord_section_with_aarch64_elf_section_data () we will not
7051 be caching a pointer that is about to be freed. */
7052 last_entry = entry->prev;
7058 unrecord_section_with_aarch64_elf_section_data (asection *sec)
7060 struct section_list *entry;
7062 entry = find_aarch64_elf_section_entry (sec);
7066 if (entry->prev != NULL)
7067 entry->prev->next = entry->next;
7068 if (entry->next != NULL)
7069 entry->next->prev = entry->prev;
7070 if (entry == sections_with_aarch64_elf_section_data)
7071 sections_with_aarch64_elf_section_data = entry->next;
7080 struct bfd_link_info *info;
7083 int (*func) (void *, const char *, Elf_Internal_Sym *,
7084 asection *, struct elf_link_hash_entry *);
7085 } output_arch_syminfo;
7087 enum map_symbol_type
7094 /* Output a single mapping symbol. */
7097 elfNN_aarch64_output_map_sym (output_arch_syminfo *osi,
7098 enum map_symbol_type type, bfd_vma offset)
7100 static const char *names[2] = { "$x", "$d" };
7101 Elf_Internal_Sym sym;
7103 sym.st_value = (osi->sec->output_section->vma
7104 + osi->sec->output_offset + offset);
7107 sym.st_info = ELF_ST_INFO (STB_LOCAL, STT_NOTYPE);
7108 sym.st_shndx = osi->sec_shndx;
7109 return osi->func (osi->finfo, names[type], &sym, osi->sec, NULL) == 1;
7114 /* Output mapping symbols for PLT entries associated with H. */
7117 elfNN_aarch64_output_plt_map (struct elf_link_hash_entry *h, void *inf)
7119 output_arch_syminfo *osi = (output_arch_syminfo *) inf;
7122 if (h->root.type == bfd_link_hash_indirect)
7125 if (h->root.type == bfd_link_hash_warning)
7126 /* When warning symbols are created, they **replace** the "real"
7127 entry in the hash table, thus we never get to see the real
7128 symbol in a hash traversal. So look at it now. */
7129 h = (struct elf_link_hash_entry *) h->root.u.i.link;
7131 if (h->plt.offset == (bfd_vma) - 1)
7134 addr = h->plt.offset;
7137 if (!elfNN_aarch64_output_map_sym (osi, AARCH64_MAP_INSN, addr))
7144 /* Output a single local symbol for a generated stub. */
7147 elfNN_aarch64_output_stub_sym (output_arch_syminfo *osi, const char *name,
7148 bfd_vma offset, bfd_vma size)
7150 Elf_Internal_Sym sym;
7152 sym.st_value = (osi->sec->output_section->vma
7153 + osi->sec->output_offset + offset);
7156 sym.st_info = ELF_ST_INFO (STB_LOCAL, STT_FUNC);
7157 sym.st_shndx = osi->sec_shndx;
7158 return osi->func (osi->finfo, name, &sym, osi->sec, NULL) == 1;
7162 aarch64_map_one_stub (struct bfd_hash_entry *gen_entry, void *in_arg)
7164 struct elf_aarch64_stub_hash_entry *stub_entry;
7168 output_arch_syminfo *osi;
7170 /* Massage our args to the form they really have. */
7171 stub_entry = (struct elf_aarch64_stub_hash_entry *) gen_entry;
7172 osi = (output_arch_syminfo *) in_arg;
7174 stub_sec = stub_entry->stub_sec;
7176 /* Ensure this stub is attached to the current section being
7178 if (stub_sec != osi->sec)
7181 addr = (bfd_vma) stub_entry->stub_offset;
7183 stub_name = stub_entry->output_name;
7185 switch (stub_entry->stub_type)
7187 case aarch64_stub_adrp_branch:
7188 if (!elfNN_aarch64_output_stub_sym (osi, stub_name, addr,
7189 sizeof (aarch64_adrp_branch_stub)))
7191 if (!elfNN_aarch64_output_map_sym (osi, AARCH64_MAP_INSN, addr))
7194 case aarch64_stub_long_branch:
7195 if (!elfNN_aarch64_output_stub_sym
7196 (osi, stub_name, addr, sizeof (aarch64_long_branch_stub)))
7198 if (!elfNN_aarch64_output_map_sym (osi, AARCH64_MAP_INSN, addr))
7200 if (!elfNN_aarch64_output_map_sym (osi, AARCH64_MAP_DATA, addr + 16))
7203 case aarch64_stub_erratum_835769_veneer:
7204 if (!elfNN_aarch64_output_stub_sym (osi, stub_name, addr,
7205 sizeof (aarch64_erratum_835769_stub)))
7207 if (!elfNN_aarch64_output_map_sym (osi, AARCH64_MAP_INSN, addr))
7210 case aarch64_stub_erratum_843419_veneer:
7211 if (!elfNN_aarch64_output_stub_sym (osi, stub_name, addr,
7212 sizeof (aarch64_erratum_843419_stub)))
7214 if (!elfNN_aarch64_output_map_sym (osi, AARCH64_MAP_INSN, addr))
7225 /* Output mapping symbols for linker generated sections. */
7228 elfNN_aarch64_output_arch_local_syms (bfd *output_bfd,
7229 struct bfd_link_info *info,
7231 int (*func) (void *, const char *,
7234 struct elf_link_hash_entry
7237 output_arch_syminfo osi;
7238 struct elf_aarch64_link_hash_table *htab;
7240 htab = elf_aarch64_hash_table (info);
7246 /* Long calls stubs. */
7247 if (htab->stub_bfd && htab->stub_bfd->sections)
7251 for (stub_sec = htab->stub_bfd->sections;
7252 stub_sec != NULL; stub_sec = stub_sec->next)
7254 /* Ignore non-stub sections. */
7255 if (!strstr (stub_sec->name, STUB_SUFFIX))
7260 osi.sec_shndx = _bfd_elf_section_from_bfd_section
7261 (output_bfd, osi.sec->output_section);
7263 /* The first instruction in a stub is always a branch. */
7264 if (!elfNN_aarch64_output_map_sym (&osi, AARCH64_MAP_INSN, 0))
7267 bfd_hash_traverse (&htab->stub_hash_table, aarch64_map_one_stub,
7272 /* Finally, output mapping symbols for the PLT. */
7273 if (!htab->root.splt || htab->root.splt->size == 0)
7276 /* For now live without mapping symbols for the plt. */
7277 osi.sec_shndx = _bfd_elf_section_from_bfd_section
7278 (output_bfd, htab->root.splt->output_section);
7279 osi.sec = htab->root.splt;
7281 elf_link_hash_traverse (&htab->root, elfNN_aarch64_output_plt_map,
7288 /* Allocate target specific section data. */
7291 elfNN_aarch64_new_section_hook (bfd *abfd, asection *sec)
7293 if (!sec->used_by_bfd)
7295 _aarch64_elf_section_data *sdata;
7296 bfd_size_type amt = sizeof (*sdata);
7298 sdata = bfd_zalloc (abfd, amt);
7301 sec->used_by_bfd = sdata;
7304 record_section_with_aarch64_elf_section_data (sec);
7306 return _bfd_elf_new_section_hook (abfd, sec);
7311 unrecord_section_via_map_over_sections (bfd *abfd ATTRIBUTE_UNUSED,
7313 void *ignore ATTRIBUTE_UNUSED)
7315 unrecord_section_with_aarch64_elf_section_data (sec);
7319 elfNN_aarch64_close_and_cleanup (bfd *abfd)
7322 bfd_map_over_sections (abfd,
7323 unrecord_section_via_map_over_sections, NULL);
7325 return _bfd_elf_close_and_cleanup (abfd);
7329 elfNN_aarch64_bfd_free_cached_info (bfd *abfd)
7332 bfd_map_over_sections (abfd,
7333 unrecord_section_via_map_over_sections, NULL);
7335 return _bfd_free_cached_info (abfd);
7338 /* Create dynamic sections. This is different from the ARM backend in that
7339 the got, plt, gotplt and their relocation sections are all created in the
7340 standard part of the bfd elf backend. */
7343 elfNN_aarch64_create_dynamic_sections (bfd *dynobj,
7344 struct bfd_link_info *info)
7346 struct elf_aarch64_link_hash_table *htab;
7348 /* We need to create .got section. */
7349 if (!aarch64_elf_create_got_section (dynobj, info))
7352 if (!_bfd_elf_create_dynamic_sections (dynobj, info))
7355 htab = elf_aarch64_hash_table (info);
7356 htab->sdynbss = bfd_get_linker_section (dynobj, ".dynbss");
7357 if (!bfd_link_pic (info))
7358 htab->srelbss = bfd_get_linker_section (dynobj, ".rela.bss");
7360 if (!htab->sdynbss || (!bfd_link_pic (info) && !htab->srelbss))
7367 /* Allocate space in .plt, .got and associated reloc sections for
7371 elfNN_aarch64_allocate_dynrelocs (struct elf_link_hash_entry *h, void *inf)
7373 struct bfd_link_info *info;
7374 struct elf_aarch64_link_hash_table *htab;
7375 struct elf_aarch64_link_hash_entry *eh;
7376 struct elf_dyn_relocs *p;
7378 /* An example of a bfd_link_hash_indirect symbol is versioned
7379 symbol. For example: __gxx_personality_v0(bfd_link_hash_indirect)
7380 -> __gxx_personality_v0(bfd_link_hash_defined)
7382 There is no need to process bfd_link_hash_indirect symbols here
7383 because we will also be presented with the concrete instance of
7384 the symbol and elfNN_aarch64_copy_indirect_symbol () will have been
7385 called to copy all relevant data from the generic to the concrete
7388 if (h->root.type == bfd_link_hash_indirect)
7391 if (h->root.type == bfd_link_hash_warning)
7392 h = (struct elf_link_hash_entry *) h->root.u.i.link;
7394 info = (struct bfd_link_info *) inf;
7395 htab = elf_aarch64_hash_table (info);
7397 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle it
7398 here if it is defined and referenced in a non-shared object. */
7399 if (h->type == STT_GNU_IFUNC
7402 else if (htab->root.dynamic_sections_created && h->plt.refcount > 0)
7404 /* Make sure this symbol is output as a dynamic symbol.
7405 Undefined weak syms won't yet be marked as dynamic. */
7406 if (h->dynindx == -1 && !h->forced_local)
7408 if (!bfd_elf_link_record_dynamic_symbol (info, h))
7412 if (bfd_link_pic (info) || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h))
7414 asection *s = htab->root.splt;
7416 /* If this is the first .plt entry, make room for the special
7419 s->size += htab->plt_header_size;
7421 h->plt.offset = s->size;
7423 /* If this symbol is not defined in a regular file, and we are
7424 not generating a shared library, then set the symbol to this
7425 location in the .plt. This is required to make function
7426 pointers compare as equal between the normal executable and
7427 the shared library. */
7428 if (!bfd_link_pic (info) && !h->def_regular)
7430 h->root.u.def.section = s;
7431 h->root.u.def.value = h->plt.offset;
7434 /* Make room for this entry. For now we only create the
7435 small model PLT entries. We later need to find a way
7436 of relaxing into these from the large model PLT entries. */
7437 s->size += PLT_SMALL_ENTRY_SIZE;
7439 /* We also need to make an entry in the .got.plt section, which
7440 will be placed in the .got section by the linker script. */
7441 htab->root.sgotplt->size += GOT_ENTRY_SIZE;
7443 /* We also need to make an entry in the .rela.plt section. */
7444 htab->root.srelplt->size += RELOC_SIZE (htab);
7446 /* We need to ensure that all GOT entries that serve the PLT
7447 are consecutive with the special GOT slots [0] [1] and
7448 [2]. Any addtional relocations, such as
7449 R_AARCH64_TLSDESC, must be placed after the PLT related
7450 entries. We abuse the reloc_count such that during
7451 sizing we adjust reloc_count to indicate the number of
7452 PLT related reserved entries. In subsequent phases when
7453 filling in the contents of the reloc entries, PLT related
7454 entries are placed by computing their PLT index (0
7455 .. reloc_count). While other none PLT relocs are placed
7456 at the slot indicated by reloc_count and reloc_count is
7459 htab->root.srelplt->reloc_count++;
7463 h->plt.offset = (bfd_vma) - 1;
7469 h->plt.offset = (bfd_vma) - 1;
7473 eh = (struct elf_aarch64_link_hash_entry *) h;
7474 eh->tlsdesc_got_jump_table_offset = (bfd_vma) - 1;
7476 if (h->got.refcount > 0)
7479 unsigned got_type = elf_aarch64_hash_entry (h)->got_type;
7481 h->got.offset = (bfd_vma) - 1;
7483 dyn = htab->root.dynamic_sections_created;
7485 /* Make sure this symbol is output as a dynamic symbol.
7486 Undefined weak syms won't yet be marked as dynamic. */
7487 if (dyn && h->dynindx == -1 && !h->forced_local)
7489 if (!bfd_elf_link_record_dynamic_symbol (info, h))
7493 if (got_type == GOT_UNKNOWN)
7496 else if (got_type == GOT_NORMAL)
7498 h->got.offset = htab->root.sgot->size;
7499 htab->root.sgot->size += GOT_ENTRY_SIZE;
7500 if ((ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
7501 || h->root.type != bfd_link_hash_undefweak)
7502 && (bfd_link_pic (info)
7503 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, 0, h)))
7505 htab->root.srelgot->size += RELOC_SIZE (htab);
7511 if (got_type & GOT_TLSDESC_GD)
7513 eh->tlsdesc_got_jump_table_offset =
7514 (htab->root.sgotplt->size
7515 - aarch64_compute_jump_table_size (htab));
7516 htab->root.sgotplt->size += GOT_ENTRY_SIZE * 2;
7517 h->got.offset = (bfd_vma) - 2;
7520 if (got_type & GOT_TLS_GD)
7522 h->got.offset = htab->root.sgot->size;
7523 htab->root.sgot->size += GOT_ENTRY_SIZE * 2;
7526 if (got_type & GOT_TLS_IE)
7528 h->got.offset = htab->root.sgot->size;
7529 htab->root.sgot->size += GOT_ENTRY_SIZE;
7532 indx = h && h->dynindx != -1 ? h->dynindx : 0;
7533 if ((ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
7534 || h->root.type != bfd_link_hash_undefweak)
7535 && (bfd_link_pic (info)
7537 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, 0, h)))
7539 if (got_type & GOT_TLSDESC_GD)
7541 htab->root.srelplt->size += RELOC_SIZE (htab);
7542 /* Note reloc_count not incremented here! We have
7543 already adjusted reloc_count for this relocation
7546 /* TLSDESC PLT is now needed, but not yet determined. */
7547 htab->tlsdesc_plt = (bfd_vma) - 1;
7550 if (got_type & GOT_TLS_GD)
7551 htab->root.srelgot->size += RELOC_SIZE (htab) * 2;
7553 if (got_type & GOT_TLS_IE)
7554 htab->root.srelgot->size += RELOC_SIZE (htab);
7560 h->got.offset = (bfd_vma) - 1;
7563 if (eh->dyn_relocs == NULL)
7566 /* In the shared -Bsymbolic case, discard space allocated for
7567 dynamic pc-relative relocs against symbols which turn out to be
7568 defined in regular objects. For the normal shared case, discard
7569 space for pc-relative relocs that have become local due to symbol
7570 visibility changes. */
7572 if (bfd_link_pic (info))
7574 /* Relocs that use pc_count are those that appear on a call
7575 insn, or certain REL relocs that can generated via assembly.
7576 We want calls to protected symbols to resolve directly to the
7577 function rather than going via the plt. If people want
7578 function pointer comparisons to work as expected then they
7579 should avoid writing weird assembly. */
7580 if (SYMBOL_CALLS_LOCAL (info, h))
7582 struct elf_dyn_relocs **pp;
7584 for (pp = &eh->dyn_relocs; (p = *pp) != NULL;)
7586 p->count -= p->pc_count;
7595 /* Also discard relocs on undefined weak syms with non-default
7597 if (eh->dyn_relocs != NULL && h->root.type == bfd_link_hash_undefweak)
7599 if (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT)
7600 eh->dyn_relocs = NULL;
7602 /* Make sure undefined weak symbols are output as a dynamic
7604 else if (h->dynindx == -1
7606 && !bfd_elf_link_record_dynamic_symbol (info, h))
7611 else if (ELIMINATE_COPY_RELOCS)
7613 /* For the non-shared case, discard space for relocs against
7614 symbols which turn out to need copy relocs or are not
7620 || (htab->root.dynamic_sections_created
7621 && (h->root.type == bfd_link_hash_undefweak
7622 || h->root.type == bfd_link_hash_undefined))))
7624 /* Make sure this symbol is output as a dynamic symbol.
7625 Undefined weak syms won't yet be marked as dynamic. */
7626 if (h->dynindx == -1
7628 && !bfd_elf_link_record_dynamic_symbol (info, h))
7631 /* If that succeeded, we know we'll be keeping all the
7633 if (h->dynindx != -1)
7637 eh->dyn_relocs = NULL;
7642 /* Finally, allocate space. */
7643 for (p = eh->dyn_relocs; p != NULL; p = p->next)
7647 sreloc = elf_section_data (p->sec)->sreloc;
7649 BFD_ASSERT (sreloc != NULL);
7651 sreloc->size += p->count * RELOC_SIZE (htab);
7657 /* Allocate space in .plt, .got and associated reloc sections for
7658 ifunc dynamic relocs. */
7661 elfNN_aarch64_allocate_ifunc_dynrelocs (struct elf_link_hash_entry *h,
7664 struct bfd_link_info *info;
7665 struct elf_aarch64_link_hash_table *htab;
7666 struct elf_aarch64_link_hash_entry *eh;
7668 /* An example of a bfd_link_hash_indirect symbol is versioned
7669 symbol. For example: __gxx_personality_v0(bfd_link_hash_indirect)
7670 -> __gxx_personality_v0(bfd_link_hash_defined)
7672 There is no need to process bfd_link_hash_indirect symbols here
7673 because we will also be presented with the concrete instance of
7674 the symbol and elfNN_aarch64_copy_indirect_symbol () will have been
7675 called to copy all relevant data from the generic to the concrete
7678 if (h->root.type == bfd_link_hash_indirect)
7681 if (h->root.type == bfd_link_hash_warning)
7682 h = (struct elf_link_hash_entry *) h->root.u.i.link;
7684 info = (struct bfd_link_info *) inf;
7685 htab = elf_aarch64_hash_table (info);
7687 eh = (struct elf_aarch64_link_hash_entry *) h;
7689 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle it
7690 here if it is defined and referenced in a non-shared object. */
7691 if (h->type == STT_GNU_IFUNC
7693 return _bfd_elf_allocate_ifunc_dyn_relocs (info, h,
7695 htab->plt_entry_size,
7696 htab->plt_header_size,
7701 /* Allocate space in .plt, .got and associated reloc sections for
7702 local dynamic relocs. */
7705 elfNN_aarch64_allocate_local_dynrelocs (void **slot, void *inf)
7707 struct elf_link_hash_entry *h
7708 = (struct elf_link_hash_entry *) *slot;
7710 if (h->type != STT_GNU_IFUNC
7714 || h->root.type != bfd_link_hash_defined)
7717 return elfNN_aarch64_allocate_dynrelocs (h, inf);
7720 /* Allocate space in .plt, .got and associated reloc sections for
7721 local ifunc dynamic relocs. */
7724 elfNN_aarch64_allocate_local_ifunc_dynrelocs (void **slot, void *inf)
7726 struct elf_link_hash_entry *h
7727 = (struct elf_link_hash_entry *) *slot;
7729 if (h->type != STT_GNU_IFUNC
7733 || h->root.type != bfd_link_hash_defined)
7736 return elfNN_aarch64_allocate_ifunc_dynrelocs (h, inf);
7739 /* Find any dynamic relocs that apply to read-only sections. */
7742 aarch64_readonly_dynrelocs (struct elf_link_hash_entry * h, void * inf)
7744 struct elf_aarch64_link_hash_entry * eh;
7745 struct elf_dyn_relocs * p;
7747 eh = (struct elf_aarch64_link_hash_entry *) h;
7748 for (p = eh->dyn_relocs; p != NULL; p = p->next)
7750 asection *s = p->sec;
7752 if (s != NULL && (s->flags & SEC_READONLY) != 0)
7754 struct bfd_link_info *info = (struct bfd_link_info *) inf;
7756 info->flags |= DF_TEXTREL;
7758 /* Not an error, just cut short the traversal. */
7765 /* This is the most important function of all . Innocuosly named
7768 elfNN_aarch64_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
7769 struct bfd_link_info *info)
7771 struct elf_aarch64_link_hash_table *htab;
7777 htab = elf_aarch64_hash_table ((info));
7778 dynobj = htab->root.dynobj;
7780 BFD_ASSERT (dynobj != NULL);
7782 if (htab->root.dynamic_sections_created)
7784 if (bfd_link_executable (info))
7786 s = bfd_get_linker_section (dynobj, ".interp");
7789 s->size = sizeof ELF_DYNAMIC_INTERPRETER;
7790 s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
7794 /* Set up .got offsets for local syms, and space for local dynamic
7796 for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link.next)
7798 struct elf_aarch64_local_symbol *locals = NULL;
7799 Elf_Internal_Shdr *symtab_hdr;
7803 if (!is_aarch64_elf (ibfd))
7806 for (s = ibfd->sections; s != NULL; s = s->next)
7808 struct elf_dyn_relocs *p;
7810 for (p = (struct elf_dyn_relocs *)
7811 (elf_section_data (s)->local_dynrel); p != NULL; p = p->next)
7813 if (!bfd_is_abs_section (p->sec)
7814 && bfd_is_abs_section (p->sec->output_section))
7816 /* Input section has been discarded, either because
7817 it is a copy of a linkonce section or due to
7818 linker script /DISCARD/, so we'll be discarding
7821 else if (p->count != 0)
7823 srel = elf_section_data (p->sec)->sreloc;
7824 srel->size += p->count * RELOC_SIZE (htab);
7825 if ((p->sec->output_section->flags & SEC_READONLY) != 0)
7826 info->flags |= DF_TEXTREL;
7831 locals = elf_aarch64_locals (ibfd);
7835 symtab_hdr = &elf_symtab_hdr (ibfd);
7836 srel = htab->root.srelgot;
7837 for (i = 0; i < symtab_hdr->sh_info; i++)
7839 locals[i].got_offset = (bfd_vma) - 1;
7840 locals[i].tlsdesc_got_jump_table_offset = (bfd_vma) - 1;
7841 if (locals[i].got_refcount > 0)
7843 unsigned got_type = locals[i].got_type;
7844 if (got_type & GOT_TLSDESC_GD)
7846 locals[i].tlsdesc_got_jump_table_offset =
7847 (htab->root.sgotplt->size
7848 - aarch64_compute_jump_table_size (htab));
7849 htab->root.sgotplt->size += GOT_ENTRY_SIZE * 2;
7850 locals[i].got_offset = (bfd_vma) - 2;
7853 if (got_type & GOT_TLS_GD)
7855 locals[i].got_offset = htab->root.sgot->size;
7856 htab->root.sgot->size += GOT_ENTRY_SIZE * 2;
7859 if (got_type & GOT_TLS_IE
7860 || got_type & GOT_NORMAL)
7862 locals[i].got_offset = htab->root.sgot->size;
7863 htab->root.sgot->size += GOT_ENTRY_SIZE;
7866 if (got_type == GOT_UNKNOWN)
7870 if (bfd_link_pic (info))
7872 if (got_type & GOT_TLSDESC_GD)
7874 htab->root.srelplt->size += RELOC_SIZE (htab);
7875 /* Note RELOC_COUNT not incremented here! */
7876 htab->tlsdesc_plt = (bfd_vma) - 1;
7879 if (got_type & GOT_TLS_GD)
7880 htab->root.srelgot->size += RELOC_SIZE (htab) * 2;
7882 if (got_type & GOT_TLS_IE
7883 || got_type & GOT_NORMAL)
7884 htab->root.srelgot->size += RELOC_SIZE (htab);
7889 locals[i].got_refcount = (bfd_vma) - 1;
7895 /* Allocate global sym .plt and .got entries, and space for global
7896 sym dynamic relocs. */
7897 elf_link_hash_traverse (&htab->root, elfNN_aarch64_allocate_dynrelocs,
7900 /* Allocate global ifunc sym .plt and .got entries, and space for global
7901 ifunc sym dynamic relocs. */
7902 elf_link_hash_traverse (&htab->root, elfNN_aarch64_allocate_ifunc_dynrelocs,
7905 /* Allocate .plt and .got entries, and space for local symbols. */
7906 htab_traverse (htab->loc_hash_table,
7907 elfNN_aarch64_allocate_local_dynrelocs,
7910 /* Allocate .plt and .got entries, and space for local ifunc symbols. */
7911 htab_traverse (htab->loc_hash_table,
7912 elfNN_aarch64_allocate_local_ifunc_dynrelocs,
7915 /* For every jump slot reserved in the sgotplt, reloc_count is
7916 incremented. However, when we reserve space for TLS descriptors,
7917 it's not incremented, so in order to compute the space reserved
7918 for them, it suffices to multiply the reloc count by the jump
7921 if (htab->root.srelplt)
7922 htab->sgotplt_jump_table_size = aarch64_compute_jump_table_size (htab);
7924 if (htab->tlsdesc_plt)
7926 if (htab->root.splt->size == 0)
7927 htab->root.splt->size += PLT_ENTRY_SIZE;
7929 htab->tlsdesc_plt = htab->root.splt->size;
7930 htab->root.splt->size += PLT_TLSDESC_ENTRY_SIZE;
7932 /* If we're not using lazy TLS relocations, don't generate the
7933 GOT entry required. */
7934 if (!(info->flags & DF_BIND_NOW))
7936 htab->dt_tlsdesc_got = htab->root.sgot->size;
7937 htab->root.sgot->size += GOT_ENTRY_SIZE;
7941 /* Init mapping symbols information to use later to distingush between
7942 code and data while scanning for errata. */
7943 if (htab->fix_erratum_835769 || htab->fix_erratum_843419)
7944 for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link.next)
7946 if (!is_aarch64_elf (ibfd))
7948 bfd_elfNN_aarch64_init_maps (ibfd);
7951 /* We now have determined the sizes of the various dynamic sections.
7952 Allocate memory for them. */
7954 for (s = dynobj->sections; s != NULL; s = s->next)
7956 if ((s->flags & SEC_LINKER_CREATED) == 0)
7959 if (s == htab->root.splt
7960 || s == htab->root.sgot
7961 || s == htab->root.sgotplt
7962 || s == htab->root.iplt
7963 || s == htab->root.igotplt || s == htab->sdynbss)
7965 /* Strip this section if we don't need it; see the
7968 else if (CONST_STRNEQ (bfd_get_section_name (dynobj, s), ".rela"))
7970 if (s->size != 0 && s != htab->root.srelplt)
7973 /* We use the reloc_count field as a counter if we need
7974 to copy relocs into the output file. */
7975 if (s != htab->root.srelplt)
7980 /* It's not one of our sections, so don't allocate space. */
7986 /* If we don't need this section, strip it from the
7987 output file. This is mostly to handle .rela.bss and
7988 .rela.plt. We must create both sections in
7989 create_dynamic_sections, because they must be created
7990 before the linker maps input sections to output
7991 sections. The linker does that before
7992 adjust_dynamic_symbol is called, and it is that
7993 function which decides whether anything needs to go
7994 into these sections. */
7996 s->flags |= SEC_EXCLUDE;
8000 if ((s->flags & SEC_HAS_CONTENTS) == 0)
8003 /* Allocate memory for the section contents. We use bfd_zalloc
8004 here in case unused entries are not reclaimed before the
8005 section's contents are written out. This should not happen,
8006 but this way if it does, we get a R_AARCH64_NONE reloc instead
8008 s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->size);
8009 if (s->contents == NULL)
8013 if (htab->root.dynamic_sections_created)
8015 /* Add some entries to the .dynamic section. We fill in the
8016 values later, in elfNN_aarch64_finish_dynamic_sections, but we
8017 must add the entries now so that we get the correct size for
8018 the .dynamic section. The DT_DEBUG entry is filled in by the
8019 dynamic linker and used by the debugger. */
8020 #define add_dynamic_entry(TAG, VAL) \
8021 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
8023 if (bfd_link_executable (info))
8025 if (!add_dynamic_entry (DT_DEBUG, 0))
8029 if (htab->root.splt->size != 0)
8031 if (!add_dynamic_entry (DT_PLTGOT, 0)
8032 || !add_dynamic_entry (DT_PLTRELSZ, 0)
8033 || !add_dynamic_entry (DT_PLTREL, DT_RELA)
8034 || !add_dynamic_entry (DT_JMPREL, 0))
8037 if (htab->tlsdesc_plt
8038 && (!add_dynamic_entry (DT_TLSDESC_PLT, 0)
8039 || !add_dynamic_entry (DT_TLSDESC_GOT, 0)))
8045 if (!add_dynamic_entry (DT_RELA, 0)
8046 || !add_dynamic_entry (DT_RELASZ, 0)
8047 || !add_dynamic_entry (DT_RELAENT, RELOC_SIZE (htab)))
8050 /* If any dynamic relocs apply to a read-only section,
8051 then we need a DT_TEXTREL entry. */
8052 if ((info->flags & DF_TEXTREL) == 0)
8053 elf_link_hash_traverse (& htab->root, aarch64_readonly_dynrelocs,
8056 if ((info->flags & DF_TEXTREL) != 0)
8058 if (!add_dynamic_entry (DT_TEXTREL, 0))
8063 #undef add_dynamic_entry
8069 elf_aarch64_update_plt_entry (bfd *output_bfd,
8070 bfd_reloc_code_real_type r_type,
8071 bfd_byte *plt_entry, bfd_vma value)
8073 reloc_howto_type *howto = elfNN_aarch64_howto_from_bfd_reloc (r_type);
8075 _bfd_aarch64_elf_put_addend (output_bfd, plt_entry, r_type, howto, value);
8079 elfNN_aarch64_create_small_pltn_entry (struct elf_link_hash_entry *h,
8080 struct elf_aarch64_link_hash_table
8081 *htab, bfd *output_bfd,
8082 struct bfd_link_info *info)
8084 bfd_byte *plt_entry;
8087 bfd_vma gotplt_entry_address;
8088 bfd_vma plt_entry_address;
8089 Elf_Internal_Rela rela;
8091 asection *plt, *gotplt, *relplt;
8093 /* When building a static executable, use .iplt, .igot.plt and
8094 .rela.iplt sections for STT_GNU_IFUNC symbols. */
8095 if (htab->root.splt != NULL)
8097 plt = htab->root.splt;
8098 gotplt = htab->root.sgotplt;
8099 relplt = htab->root.srelplt;
8103 plt = htab->root.iplt;
8104 gotplt = htab->root.igotplt;
8105 relplt = htab->root.irelplt;
8108 /* Get the index in the procedure linkage table which
8109 corresponds to this symbol. This is the index of this symbol
8110 in all the symbols for which we are making plt entries. The
8111 first entry in the procedure linkage table is reserved.
8113 Get the offset into the .got table of the entry that
8114 corresponds to this function. Each .got entry is GOT_ENTRY_SIZE
8115 bytes. The first three are reserved for the dynamic linker.
8117 For static executables, we don't reserve anything. */
8119 if (plt == htab->root.splt)
8121 plt_index = (h->plt.offset - htab->plt_header_size) / htab->plt_entry_size;
8122 got_offset = (plt_index + 3) * GOT_ENTRY_SIZE;
8126 plt_index = h->plt.offset / htab->plt_entry_size;
8127 got_offset = plt_index * GOT_ENTRY_SIZE;
8130 plt_entry = plt->contents + h->plt.offset;
8131 plt_entry_address = plt->output_section->vma
8132 + plt->output_offset + h->plt.offset;
8133 gotplt_entry_address = gotplt->output_section->vma +
8134 gotplt->output_offset + got_offset;
8136 /* Copy in the boiler-plate for the PLTn entry. */
8137 memcpy (plt_entry, elfNN_aarch64_small_plt_entry, PLT_SMALL_ENTRY_SIZE);
8139 /* Fill in the top 21 bits for this: ADRP x16, PLT_GOT + n * 8.
8140 ADRP: ((PG(S+A)-PG(P)) >> 12) & 0x1fffff */
8141 elf_aarch64_update_plt_entry (output_bfd, BFD_RELOC_AARCH64_ADR_HI21_PCREL,
8143 PG (gotplt_entry_address) -
8144 PG (plt_entry_address));
8146 /* Fill in the lo12 bits for the load from the pltgot. */
8147 elf_aarch64_update_plt_entry (output_bfd, BFD_RELOC_AARCH64_LDSTNN_LO12,
8149 PG_OFFSET (gotplt_entry_address));
8151 /* Fill in the lo12 bits for the add from the pltgot entry. */
8152 elf_aarch64_update_plt_entry (output_bfd, BFD_RELOC_AARCH64_ADD_LO12,
8154 PG_OFFSET (gotplt_entry_address));
8156 /* All the GOTPLT Entries are essentially initialized to PLT0. */
8157 bfd_put_NN (output_bfd,
8158 plt->output_section->vma + plt->output_offset,
8159 gotplt->contents + got_offset);
8161 rela.r_offset = gotplt_entry_address;
8163 if (h->dynindx == -1
8164 || ((bfd_link_executable (info)
8165 || ELF_ST_VISIBILITY (h->other) != STV_DEFAULT)
8167 && h->type == STT_GNU_IFUNC))
8169 /* If an STT_GNU_IFUNC symbol is locally defined, generate
8170 R_AARCH64_IRELATIVE instead of R_AARCH64_JUMP_SLOT. */
8171 rela.r_info = ELFNN_R_INFO (0, AARCH64_R (IRELATIVE));
8172 rela.r_addend = (h->root.u.def.value
8173 + h->root.u.def.section->output_section->vma
8174 + h->root.u.def.section->output_offset);
8178 /* Fill in the entry in the .rela.plt section. */
8179 rela.r_info = ELFNN_R_INFO (h->dynindx, AARCH64_R (JUMP_SLOT));
8183 /* Compute the relocation entry to used based on PLT index and do
8184 not adjust reloc_count. The reloc_count has already been adjusted
8185 to account for this entry. */
8186 loc = relplt->contents + plt_index * RELOC_SIZE (htab);
8187 bfd_elfNN_swap_reloca_out (output_bfd, &rela, loc);
8190 /* Size sections even though they're not dynamic. We use it to setup
8191 _TLS_MODULE_BASE_, if needed. */
8194 elfNN_aarch64_always_size_sections (bfd *output_bfd,
8195 struct bfd_link_info *info)
8199 if (bfd_link_relocatable (info))
8202 tls_sec = elf_hash_table (info)->tls_sec;
8206 struct elf_link_hash_entry *tlsbase;
8208 tlsbase = elf_link_hash_lookup (elf_hash_table (info),
8209 "_TLS_MODULE_BASE_", TRUE, TRUE, FALSE);
8213 struct bfd_link_hash_entry *h = NULL;
8214 const struct elf_backend_data *bed =
8215 get_elf_backend_data (output_bfd);
8217 if (!(_bfd_generic_link_add_one_symbol
8218 (info, output_bfd, "_TLS_MODULE_BASE_", BSF_LOCAL,
8219 tls_sec, 0, NULL, FALSE, bed->collect, &h)))
8222 tlsbase->type = STT_TLS;
8223 tlsbase = (struct elf_link_hash_entry *) h;
8224 tlsbase->def_regular = 1;
8225 tlsbase->other = STV_HIDDEN;
8226 (*bed->elf_backend_hide_symbol) (info, tlsbase, TRUE);
8233 /* Finish up dynamic symbol handling. We set the contents of various
8234 dynamic sections here. */
8236 elfNN_aarch64_finish_dynamic_symbol (bfd *output_bfd,
8237 struct bfd_link_info *info,
8238 struct elf_link_hash_entry *h,
8239 Elf_Internal_Sym *sym)
8241 struct elf_aarch64_link_hash_table *htab;
8242 htab = elf_aarch64_hash_table (info);
8244 if (h->plt.offset != (bfd_vma) - 1)
8246 asection *plt, *gotplt, *relplt;
8248 /* This symbol has an entry in the procedure linkage table. Set
8251 /* When building a static executable, use .iplt, .igot.plt and
8252 .rela.iplt sections for STT_GNU_IFUNC symbols. */
8253 if (htab->root.splt != NULL)
8255 plt = htab->root.splt;
8256 gotplt = htab->root.sgotplt;
8257 relplt = htab->root.srelplt;
8261 plt = htab->root.iplt;
8262 gotplt = htab->root.igotplt;
8263 relplt = htab->root.irelplt;
8266 /* This symbol has an entry in the procedure linkage table. Set
8268 if ((h->dynindx == -1
8269 && !((h->forced_local || bfd_link_executable (info))
8271 && h->type == STT_GNU_IFUNC))
8277 elfNN_aarch64_create_small_pltn_entry (h, htab, output_bfd, info);
8278 if (!h->def_regular)
8280 /* Mark the symbol as undefined, rather than as defined in
8281 the .plt section. */
8282 sym->st_shndx = SHN_UNDEF;
8283 /* If the symbol is weak we need to clear the value.
8284 Otherwise, the PLT entry would provide a definition for
8285 the symbol even if the symbol wasn't defined anywhere,
8286 and so the symbol would never be NULL. Leave the value if
8287 there were any relocations where pointer equality matters
8288 (this is a clue for the dynamic linker, to make function
8289 pointer comparisons work between an application and shared
8291 if (!h->ref_regular_nonweak || !h->pointer_equality_needed)
8296 if (h->got.offset != (bfd_vma) - 1
8297 && elf_aarch64_hash_entry (h)->got_type == GOT_NORMAL)
8299 Elf_Internal_Rela rela;
8302 /* This symbol has an entry in the global offset table. Set it
8304 if (htab->root.sgot == NULL || htab->root.srelgot == NULL)
8307 rela.r_offset = (htab->root.sgot->output_section->vma
8308 + htab->root.sgot->output_offset
8309 + (h->got.offset & ~(bfd_vma) 1));
8312 && h->type == STT_GNU_IFUNC)
8314 if (bfd_link_pic (info))
8316 /* Generate R_AARCH64_GLOB_DAT. */
8323 if (!h->pointer_equality_needed)
8326 /* For non-shared object, we can't use .got.plt, which
8327 contains the real function address if we need pointer
8328 equality. We load the GOT entry with the PLT entry. */
8329 plt = htab->root.splt ? htab->root.splt : htab->root.iplt;
8330 bfd_put_NN (output_bfd, (plt->output_section->vma
8331 + plt->output_offset
8333 htab->root.sgot->contents
8334 + (h->got.offset & ~(bfd_vma) 1));
8338 else if (bfd_link_pic (info) && SYMBOL_REFERENCES_LOCAL (info, h))
8340 if (!h->def_regular)
8343 BFD_ASSERT ((h->got.offset & 1) != 0);
8344 rela.r_info = ELFNN_R_INFO (0, AARCH64_R (RELATIVE));
8345 rela.r_addend = (h->root.u.def.value
8346 + h->root.u.def.section->output_section->vma
8347 + h->root.u.def.section->output_offset);
8352 BFD_ASSERT ((h->got.offset & 1) == 0);
8353 bfd_put_NN (output_bfd, (bfd_vma) 0,
8354 htab->root.sgot->contents + h->got.offset);
8355 rela.r_info = ELFNN_R_INFO (h->dynindx, AARCH64_R (GLOB_DAT));
8359 loc = htab->root.srelgot->contents;
8360 loc += htab->root.srelgot->reloc_count++ * RELOC_SIZE (htab);
8361 bfd_elfNN_swap_reloca_out (output_bfd, &rela, loc);
8366 Elf_Internal_Rela rela;
8369 /* This symbol needs a copy reloc. Set it up. */
8371 if (h->dynindx == -1
8372 || (h->root.type != bfd_link_hash_defined
8373 && h->root.type != bfd_link_hash_defweak)
8374 || htab->srelbss == NULL)
8377 rela.r_offset = (h->root.u.def.value
8378 + h->root.u.def.section->output_section->vma
8379 + h->root.u.def.section->output_offset);
8380 rela.r_info = ELFNN_R_INFO (h->dynindx, AARCH64_R (COPY));
8382 loc = htab->srelbss->contents;
8383 loc += htab->srelbss->reloc_count++ * RELOC_SIZE (htab);
8384 bfd_elfNN_swap_reloca_out (output_bfd, &rela, loc);
8387 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. SYM may
8388 be NULL for local symbols. */
8390 && (h == elf_hash_table (info)->hdynamic
8391 || h == elf_hash_table (info)->hgot))
8392 sym->st_shndx = SHN_ABS;
8397 /* Finish up local dynamic symbol handling. We set the contents of
8398 various dynamic sections here. */
8401 elfNN_aarch64_finish_local_dynamic_symbol (void **slot, void *inf)
8403 struct elf_link_hash_entry *h
8404 = (struct elf_link_hash_entry *) *slot;
8405 struct bfd_link_info *info
8406 = (struct bfd_link_info *) inf;
8408 return elfNN_aarch64_finish_dynamic_symbol (info->output_bfd,
8413 elfNN_aarch64_init_small_plt0_entry (bfd *output_bfd ATTRIBUTE_UNUSED,
8414 struct elf_aarch64_link_hash_table
8417 /* Fill in PLT0. Fixme:RR Note this doesn't distinguish between
8418 small and large plts and at the minute just generates
8421 /* PLT0 of the small PLT looks like this in ELF64 -
8422 stp x16, x30, [sp, #-16]! // Save the reloc and lr on stack.
8423 adrp x16, PLT_GOT + 16 // Get the page base of the GOTPLT
8424 ldr x17, [x16, #:lo12:PLT_GOT+16] // Load the address of the
8426 add x16, x16, #:lo12:PLT_GOT+16 // Load the lo12 bits of the
8427 // GOTPLT entry for this.
8429 PLT0 will be slightly different in ELF32 due to different got entry
8432 bfd_vma plt_got_2nd_ent; /* Address of GOT[2]. */
8436 memcpy (htab->root.splt->contents, elfNN_aarch64_small_plt0_entry,
8438 elf_section_data (htab->root.splt->output_section)->this_hdr.sh_entsize =
8441 plt_got_2nd_ent = (htab->root.sgotplt->output_section->vma
8442 + htab->root.sgotplt->output_offset
8443 + GOT_ENTRY_SIZE * 2);
8445 plt_base = htab->root.splt->output_section->vma +
8446 htab->root.splt->output_offset;
8448 /* Fill in the top 21 bits for this: ADRP x16, PLT_GOT + n * 8.
8449 ADRP: ((PG(S+A)-PG(P)) >> 12) & 0x1fffff */
8450 elf_aarch64_update_plt_entry (output_bfd, BFD_RELOC_AARCH64_ADR_HI21_PCREL,
8451 htab->root.splt->contents + 4,
8452 PG (plt_got_2nd_ent) - PG (plt_base + 4));
8454 elf_aarch64_update_plt_entry (output_bfd, BFD_RELOC_AARCH64_LDSTNN_LO12,
8455 htab->root.splt->contents + 8,
8456 PG_OFFSET (plt_got_2nd_ent));
8458 elf_aarch64_update_plt_entry (output_bfd, BFD_RELOC_AARCH64_ADD_LO12,
8459 htab->root.splt->contents + 12,
8460 PG_OFFSET (plt_got_2nd_ent));
8464 elfNN_aarch64_finish_dynamic_sections (bfd *output_bfd,
8465 struct bfd_link_info *info)
8467 struct elf_aarch64_link_hash_table *htab;
8471 htab = elf_aarch64_hash_table (info);
8472 dynobj = htab->root.dynobj;
8473 sdyn = bfd_get_linker_section (dynobj, ".dynamic");
8475 if (htab->root.dynamic_sections_created)
8477 ElfNN_External_Dyn *dyncon, *dynconend;
8479 if (sdyn == NULL || htab->root.sgot == NULL)
8482 dyncon = (ElfNN_External_Dyn *) sdyn->contents;
8483 dynconend = (ElfNN_External_Dyn *) (sdyn->contents + sdyn->size);
8484 for (; dyncon < dynconend; dyncon++)
8486 Elf_Internal_Dyn dyn;
8489 bfd_elfNN_swap_dyn_in (dynobj, dyncon, &dyn);
8497 s = htab->root.sgotplt;
8498 dyn.d_un.d_ptr = s->output_section->vma + s->output_offset;
8502 dyn.d_un.d_ptr = htab->root.srelplt->output_section->vma;
8506 s = htab->root.srelplt;
8507 dyn.d_un.d_val = s->size;
8511 /* The procedure linkage table relocs (DT_JMPREL) should
8512 not be included in the overall relocs (DT_RELA).
8513 Therefore, we override the DT_RELASZ entry here to
8514 make it not include the JMPREL relocs. Since the
8515 linker script arranges for .rela.plt to follow all
8516 other relocation sections, we don't have to worry
8517 about changing the DT_RELA entry. */
8518 if (htab->root.srelplt != NULL)
8520 s = htab->root.srelplt;
8521 dyn.d_un.d_val -= s->size;
8525 case DT_TLSDESC_PLT:
8526 s = htab->root.splt;
8527 dyn.d_un.d_ptr = s->output_section->vma + s->output_offset
8528 + htab->tlsdesc_plt;
8531 case DT_TLSDESC_GOT:
8532 s = htab->root.sgot;
8533 dyn.d_un.d_ptr = s->output_section->vma + s->output_offset
8534 + htab->dt_tlsdesc_got;
8538 bfd_elfNN_swap_dyn_out (output_bfd, &dyn, dyncon);
8543 /* Fill in the special first entry in the procedure linkage table. */
8544 if (htab->root.splt && htab->root.splt->size > 0)
8546 elfNN_aarch64_init_small_plt0_entry (output_bfd, htab);
8548 elf_section_data (htab->root.splt->output_section)->
8549 this_hdr.sh_entsize = htab->plt_entry_size;
8552 if (htab->tlsdesc_plt)
8554 bfd_put_NN (output_bfd, (bfd_vma) 0,
8555 htab->root.sgot->contents + htab->dt_tlsdesc_got);
8557 memcpy (htab->root.splt->contents + htab->tlsdesc_plt,
8558 elfNN_aarch64_tlsdesc_small_plt_entry,
8559 sizeof (elfNN_aarch64_tlsdesc_small_plt_entry));
8562 bfd_vma adrp1_addr =
8563 htab->root.splt->output_section->vma
8564 + htab->root.splt->output_offset + htab->tlsdesc_plt + 4;
8566 bfd_vma adrp2_addr = adrp1_addr + 4;
8569 htab->root.sgot->output_section->vma
8570 + htab->root.sgot->output_offset;
8572 bfd_vma pltgot_addr =
8573 htab->root.sgotplt->output_section->vma
8574 + htab->root.sgotplt->output_offset;
8576 bfd_vma dt_tlsdesc_got = got_addr + htab->dt_tlsdesc_got;
8578 bfd_byte *plt_entry =
8579 htab->root.splt->contents + htab->tlsdesc_plt;
8581 /* adrp x2, DT_TLSDESC_GOT */
8582 elf_aarch64_update_plt_entry (output_bfd,
8583 BFD_RELOC_AARCH64_ADR_HI21_PCREL,
8585 (PG (dt_tlsdesc_got)
8586 - PG (adrp1_addr)));
8589 elf_aarch64_update_plt_entry (output_bfd,
8590 BFD_RELOC_AARCH64_ADR_HI21_PCREL,
8593 - PG (adrp2_addr)));
8595 /* ldr x2, [x2, #0] */
8596 elf_aarch64_update_plt_entry (output_bfd,
8597 BFD_RELOC_AARCH64_LDSTNN_LO12,
8599 PG_OFFSET (dt_tlsdesc_got));
8602 elf_aarch64_update_plt_entry (output_bfd,
8603 BFD_RELOC_AARCH64_ADD_LO12,
8605 PG_OFFSET (pltgot_addr));
8610 if (htab->root.sgotplt)
8612 if (bfd_is_abs_section (htab->root.sgotplt->output_section))
8614 (*_bfd_error_handler)
8615 (_("discarded output section: `%A'"), htab->root.sgotplt);
8619 /* Fill in the first three entries in the global offset table. */
8620 if (htab->root.sgotplt->size > 0)
8622 bfd_put_NN (output_bfd, (bfd_vma) 0, htab->root.sgotplt->contents);
8624 /* Write GOT[1] and GOT[2], needed for the dynamic linker. */
8625 bfd_put_NN (output_bfd,
8627 htab->root.sgotplt->contents + GOT_ENTRY_SIZE);
8628 bfd_put_NN (output_bfd,
8630 htab->root.sgotplt->contents + GOT_ENTRY_SIZE * 2);
8633 if (htab->root.sgot)
8635 if (htab->root.sgot->size > 0)
8638 sdyn ? sdyn->output_section->vma + sdyn->output_offset : 0;
8639 bfd_put_NN (output_bfd, addr, htab->root.sgot->contents);
8643 elf_section_data (htab->root.sgotplt->output_section)->
8644 this_hdr.sh_entsize = GOT_ENTRY_SIZE;
8647 if (htab->root.sgot && htab->root.sgot->size > 0)
8648 elf_section_data (htab->root.sgot->output_section)->this_hdr.sh_entsize
8651 /* Fill PLT and GOT entries for local STT_GNU_IFUNC symbols. */
8652 htab_traverse (htab->loc_hash_table,
8653 elfNN_aarch64_finish_local_dynamic_symbol,
8659 /* Return address for Ith PLT stub in section PLT, for relocation REL
8660 or (bfd_vma) -1 if it should not be included. */
8663 elfNN_aarch64_plt_sym_val (bfd_vma i, const asection *plt,
8664 const arelent *rel ATTRIBUTE_UNUSED)
8666 return plt->vma + PLT_ENTRY_SIZE + i * PLT_SMALL_ENTRY_SIZE;
8670 /* We use this so we can override certain functions
8671 (though currently we don't). */
8673 const struct elf_size_info elfNN_aarch64_size_info =
8675 sizeof (ElfNN_External_Ehdr),
8676 sizeof (ElfNN_External_Phdr),
8677 sizeof (ElfNN_External_Shdr),
8678 sizeof (ElfNN_External_Rel),
8679 sizeof (ElfNN_External_Rela),
8680 sizeof (ElfNN_External_Sym),
8681 sizeof (ElfNN_External_Dyn),
8682 sizeof (Elf_External_Note),
8683 4, /* Hash table entry size. */
8684 1, /* Internal relocs per external relocs. */
8685 ARCH_SIZE, /* Arch size. */
8686 LOG_FILE_ALIGN, /* Log_file_align. */
8687 ELFCLASSNN, EV_CURRENT,
8688 bfd_elfNN_write_out_phdrs,
8689 bfd_elfNN_write_shdrs_and_ehdr,
8690 bfd_elfNN_checksum_contents,
8691 bfd_elfNN_write_relocs,
8692 bfd_elfNN_swap_symbol_in,
8693 bfd_elfNN_swap_symbol_out,
8694 bfd_elfNN_slurp_reloc_table,
8695 bfd_elfNN_slurp_symbol_table,
8696 bfd_elfNN_swap_dyn_in,
8697 bfd_elfNN_swap_dyn_out,
8698 bfd_elfNN_swap_reloc_in,
8699 bfd_elfNN_swap_reloc_out,
8700 bfd_elfNN_swap_reloca_in,
8701 bfd_elfNN_swap_reloca_out
8704 #define ELF_ARCH bfd_arch_aarch64
8705 #define ELF_MACHINE_CODE EM_AARCH64
8706 #define ELF_MAXPAGESIZE 0x10000
8707 #define ELF_MINPAGESIZE 0x1000
8708 #define ELF_COMMONPAGESIZE 0x1000
8710 #define bfd_elfNN_close_and_cleanup \
8711 elfNN_aarch64_close_and_cleanup
8713 #define bfd_elfNN_bfd_free_cached_info \
8714 elfNN_aarch64_bfd_free_cached_info
8716 #define bfd_elfNN_bfd_is_target_special_symbol \
8717 elfNN_aarch64_is_target_special_symbol
8719 #define bfd_elfNN_bfd_link_hash_table_create \
8720 elfNN_aarch64_link_hash_table_create
8722 #define bfd_elfNN_bfd_merge_private_bfd_data \
8723 elfNN_aarch64_merge_private_bfd_data
8725 #define bfd_elfNN_bfd_print_private_bfd_data \
8726 elfNN_aarch64_print_private_bfd_data
8728 #define bfd_elfNN_bfd_reloc_type_lookup \
8729 elfNN_aarch64_reloc_type_lookup
8731 #define bfd_elfNN_bfd_reloc_name_lookup \
8732 elfNN_aarch64_reloc_name_lookup
8734 #define bfd_elfNN_bfd_set_private_flags \
8735 elfNN_aarch64_set_private_flags
8737 #define bfd_elfNN_find_inliner_info \
8738 elfNN_aarch64_find_inliner_info
8740 #define bfd_elfNN_find_nearest_line \
8741 elfNN_aarch64_find_nearest_line
8743 #define bfd_elfNN_mkobject \
8744 elfNN_aarch64_mkobject
8746 #define bfd_elfNN_new_section_hook \
8747 elfNN_aarch64_new_section_hook
8749 #define elf_backend_adjust_dynamic_symbol \
8750 elfNN_aarch64_adjust_dynamic_symbol
8752 #define elf_backend_always_size_sections \
8753 elfNN_aarch64_always_size_sections
8755 #define elf_backend_check_relocs \
8756 elfNN_aarch64_check_relocs
8758 #define elf_backend_copy_indirect_symbol \
8759 elfNN_aarch64_copy_indirect_symbol
8761 /* Create .dynbss, and .rela.bss sections in DYNOBJ, and set up shortcuts
8762 to them in our hash. */
8763 #define elf_backend_create_dynamic_sections \
8764 elfNN_aarch64_create_dynamic_sections
8766 #define elf_backend_init_index_section \
8767 _bfd_elf_init_2_index_sections
8769 #define elf_backend_finish_dynamic_sections \
8770 elfNN_aarch64_finish_dynamic_sections
8772 #define elf_backend_finish_dynamic_symbol \
8773 elfNN_aarch64_finish_dynamic_symbol
8775 #define elf_backend_gc_sweep_hook \
8776 elfNN_aarch64_gc_sweep_hook
8778 #define elf_backend_object_p \
8779 elfNN_aarch64_object_p
8781 #define elf_backend_output_arch_local_syms \
8782 elfNN_aarch64_output_arch_local_syms
8784 #define elf_backend_plt_sym_val \
8785 elfNN_aarch64_plt_sym_val
8787 #define elf_backend_post_process_headers \
8788 elfNN_aarch64_post_process_headers
8790 #define elf_backend_relocate_section \
8791 elfNN_aarch64_relocate_section
8793 #define elf_backend_reloc_type_class \
8794 elfNN_aarch64_reloc_type_class
8796 #define elf_backend_section_from_shdr \
8797 elfNN_aarch64_section_from_shdr
8799 #define elf_backend_size_dynamic_sections \
8800 elfNN_aarch64_size_dynamic_sections
8802 #define elf_backend_size_info \
8803 elfNN_aarch64_size_info
8805 #define elf_backend_write_section \
8806 elfNN_aarch64_write_section
8808 #define elf_backend_can_refcount 1
8809 #define elf_backend_can_gc_sections 1
8810 #define elf_backend_plt_readonly 1
8811 #define elf_backend_want_got_plt 1
8812 #define elf_backend_want_plt_sym 0
8813 #define elf_backend_may_use_rel_p 0
8814 #define elf_backend_may_use_rela_p 1
8815 #define elf_backend_default_use_rela_p 1
8816 #define elf_backend_rela_normal 1
8817 #define elf_backend_got_header_size (GOT_ENTRY_SIZE * 3)
8818 #define elf_backend_default_execstack 0
8819 #define elf_backend_extern_protected_data 1
8821 #undef elf_backend_obj_attrs_section
8822 #define elf_backend_obj_attrs_section ".ARM.attributes"
8824 #include "elfNN-target.h"