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_HI12 \
178 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_ADD_DTPREL_LO12 \
179 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_ADD_DTPREL_LO12_NC \
180 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC \
181 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21 \
182 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_ADR_PREL21 \
183 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G0 \
184 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G0_NC \
185 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G1 \
186 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G1_NC \
187 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G2 \
188 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_HI12 \
189 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_LO12 \
190 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_LO12_NC \
191 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0 \
192 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC \
193 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1 \
194 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1_NC \
195 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G2 \
196 || (R_TYPE) == BFD_RELOC_AARCH64_TLS_DTPMOD \
197 || (R_TYPE) == BFD_RELOC_AARCH64_TLS_DTPREL \
198 || (R_TYPE) == BFD_RELOC_AARCH64_TLS_TPREL \
199 || IS_AARCH64_TLSDESC_RELOC ((R_TYPE)))
201 #define IS_AARCH64_TLS_RELAX_RELOC(R_TYPE) \
202 ((R_TYPE) == BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21 \
203 || (R_TYPE) == BFD_RELOC_AARCH64_TLSGD_ADR_PREL21 \
204 || (R_TYPE) == BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC \
205 || (R_TYPE) == BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21 \
206 || (R_TYPE) == BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19 \
207 || (R_TYPE) == BFD_RELOC_AARCH64_TLSIE_LDNN_GOTTPREL_LO12_NC \
208 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21 \
209 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21 \
210 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_LD_PREL19 \
211 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_LDNN_LO12_NC \
212 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_CALL \
213 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_ADD_LO12_NC)
215 #define IS_AARCH64_TLSDESC_RELOC(R_TYPE) \
216 ((R_TYPE) == BFD_RELOC_AARCH64_TLSDESC \
217 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_ADD \
218 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_ADD_LO12_NC \
219 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21 \
220 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21 \
221 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_CALL \
222 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_LD32_LO12_NC \
223 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_LD64_LO12_NC \
224 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_LDR \
225 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_LD_PREL19 \
226 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_OFF_G0_NC \
227 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_OFF_G1)
229 #define ELIMINATE_COPY_RELOCS 0
231 /* Return size of a relocation entry. HTAB is the bfd's
232 elf_aarch64_link_hash_entry. */
233 #define RELOC_SIZE(HTAB) (sizeof (ElfNN_External_Rela))
235 /* GOT Entry size - 8 bytes in ELF64 and 4 bytes in ELF32. */
236 #define GOT_ENTRY_SIZE (ARCH_SIZE / 8)
237 #define PLT_ENTRY_SIZE (32)
238 #define PLT_SMALL_ENTRY_SIZE (16)
239 #define PLT_TLSDESC_ENTRY_SIZE (32)
241 /* Encoding of the nop instruction */
242 #define INSN_NOP 0xd503201f
244 #define aarch64_compute_jump_table_size(htab) \
245 (((htab)->root.srelplt == NULL) ? 0 \
246 : (htab)->root.srelplt->reloc_count * GOT_ENTRY_SIZE)
248 /* The first entry in a procedure linkage table looks like this
249 if the distance between the PLTGOT and the PLT is < 4GB use
250 these PLT entries. Note that the dynamic linker gets &PLTGOT[2]
251 in x16 and needs to work out PLTGOT[1] by using an address of
252 [x16,#-GOT_ENTRY_SIZE]. */
253 static const bfd_byte elfNN_aarch64_small_plt0_entry[PLT_ENTRY_SIZE] =
255 0xf0, 0x7b, 0xbf, 0xa9, /* stp x16, x30, [sp, #-16]! */
256 0x10, 0x00, 0x00, 0x90, /* adrp x16, (GOT+16) */
258 0x11, 0x0A, 0x40, 0xf9, /* ldr x17, [x16, #PLT_GOT+0x10] */
259 0x10, 0x42, 0x00, 0x91, /* add x16, x16,#PLT_GOT+0x10 */
261 0x11, 0x0A, 0x40, 0xb9, /* ldr w17, [x16, #PLT_GOT+0x8] */
262 0x10, 0x22, 0x00, 0x11, /* add w16, w16,#PLT_GOT+0x8 */
264 0x20, 0x02, 0x1f, 0xd6, /* br x17 */
265 0x1f, 0x20, 0x03, 0xd5, /* nop */
266 0x1f, 0x20, 0x03, 0xd5, /* nop */
267 0x1f, 0x20, 0x03, 0xd5, /* nop */
270 /* Per function entry in a procedure linkage table looks like this
271 if the distance between the PLTGOT and the PLT is < 4GB use
272 these PLT entries. */
273 static const bfd_byte elfNN_aarch64_small_plt_entry[PLT_SMALL_ENTRY_SIZE] =
275 0x10, 0x00, 0x00, 0x90, /* adrp x16, PLTGOT + n * 8 */
277 0x11, 0x02, 0x40, 0xf9, /* ldr x17, [x16, PLTGOT + n * 8] */
278 0x10, 0x02, 0x00, 0x91, /* add x16, x16, :lo12:PLTGOT + n * 8 */
280 0x11, 0x02, 0x40, 0xb9, /* ldr w17, [x16, PLTGOT + n * 4] */
281 0x10, 0x02, 0x00, 0x11, /* add w16, w16, :lo12:PLTGOT + n * 4 */
283 0x20, 0x02, 0x1f, 0xd6, /* br x17. */
286 static const bfd_byte
287 elfNN_aarch64_tlsdesc_small_plt_entry[PLT_TLSDESC_ENTRY_SIZE] =
289 0xe2, 0x0f, 0xbf, 0xa9, /* stp x2, x3, [sp, #-16]! */
290 0x02, 0x00, 0x00, 0x90, /* adrp x2, 0 */
291 0x03, 0x00, 0x00, 0x90, /* adrp x3, 0 */
293 0x42, 0x00, 0x40, 0xf9, /* ldr x2, [x2, #0] */
294 0x63, 0x00, 0x00, 0x91, /* add x3, x3, 0 */
296 0x42, 0x00, 0x40, 0xb9, /* ldr w2, [x2, #0] */
297 0x63, 0x00, 0x00, 0x11, /* add w3, w3, 0 */
299 0x40, 0x00, 0x1f, 0xd6, /* br x2 */
300 0x1f, 0x20, 0x03, 0xd5, /* nop */
301 0x1f, 0x20, 0x03, 0xd5, /* nop */
304 #define elf_info_to_howto elfNN_aarch64_info_to_howto
305 #define elf_info_to_howto_rel elfNN_aarch64_info_to_howto
307 #define AARCH64_ELF_ABI_VERSION 0
309 /* In case we're on a 32-bit machine, construct a 64-bit "-1" value. */
310 #define ALL_ONES (~ (bfd_vma) 0)
312 /* Indexed by the bfd interal reloc enumerators.
313 Therefore, the table needs to be synced with BFD_RELOC_AARCH64_*
316 static reloc_howto_type elfNN_aarch64_howto_table[] =
320 /* Basic data relocations. */
323 HOWTO (R_AARCH64_NULL, /* type */
325 3, /* size (0 = byte, 1 = short, 2 = long) */
327 FALSE, /* pc_relative */
329 complain_overflow_dont, /* complain_on_overflow */
330 bfd_elf_generic_reloc, /* special_function */
331 "R_AARCH64_NULL", /* name */
332 FALSE, /* partial_inplace */
335 FALSE), /* pcrel_offset */
337 HOWTO (R_AARCH64_NONE, /* type */
339 3, /* size (0 = byte, 1 = short, 2 = long) */
341 FALSE, /* pc_relative */
343 complain_overflow_dont, /* complain_on_overflow */
344 bfd_elf_generic_reloc, /* special_function */
345 "R_AARCH64_NONE", /* name */
346 FALSE, /* partial_inplace */
349 FALSE), /* pcrel_offset */
353 HOWTO64 (AARCH64_R (ABS64), /* type */
355 4, /* size (4 = long long) */
357 FALSE, /* pc_relative */
359 complain_overflow_unsigned, /* complain_on_overflow */
360 bfd_elf_generic_reloc, /* special_function */
361 AARCH64_R_STR (ABS64), /* name */
362 FALSE, /* partial_inplace */
363 ALL_ONES, /* src_mask */
364 ALL_ONES, /* dst_mask */
365 FALSE), /* pcrel_offset */
368 HOWTO (AARCH64_R (ABS32), /* type */
370 2, /* size (0 = byte, 1 = short, 2 = long) */
372 FALSE, /* pc_relative */
374 complain_overflow_unsigned, /* complain_on_overflow */
375 bfd_elf_generic_reloc, /* special_function */
376 AARCH64_R_STR (ABS32), /* name */
377 FALSE, /* partial_inplace */
378 0xffffffff, /* src_mask */
379 0xffffffff, /* dst_mask */
380 FALSE), /* pcrel_offset */
383 HOWTO (AARCH64_R (ABS16), /* type */
385 1, /* size (0 = byte, 1 = short, 2 = long) */
387 FALSE, /* pc_relative */
389 complain_overflow_unsigned, /* complain_on_overflow */
390 bfd_elf_generic_reloc, /* special_function */
391 AARCH64_R_STR (ABS16), /* name */
392 FALSE, /* partial_inplace */
393 0xffff, /* src_mask */
394 0xffff, /* dst_mask */
395 FALSE), /* pcrel_offset */
397 /* .xword: (S+A-P) */
398 HOWTO64 (AARCH64_R (PREL64), /* type */
400 4, /* size (4 = long long) */
402 TRUE, /* pc_relative */
404 complain_overflow_signed, /* complain_on_overflow */
405 bfd_elf_generic_reloc, /* special_function */
406 AARCH64_R_STR (PREL64), /* name */
407 FALSE, /* partial_inplace */
408 ALL_ONES, /* src_mask */
409 ALL_ONES, /* dst_mask */
410 TRUE), /* pcrel_offset */
413 HOWTO (AARCH64_R (PREL32), /* type */
415 2, /* size (0 = byte, 1 = short, 2 = long) */
417 TRUE, /* pc_relative */
419 complain_overflow_signed, /* complain_on_overflow */
420 bfd_elf_generic_reloc, /* special_function */
421 AARCH64_R_STR (PREL32), /* name */
422 FALSE, /* partial_inplace */
423 0xffffffff, /* src_mask */
424 0xffffffff, /* dst_mask */
425 TRUE), /* pcrel_offset */
428 HOWTO (AARCH64_R (PREL16), /* type */
430 1, /* size (0 = byte, 1 = short, 2 = long) */
432 TRUE, /* pc_relative */
434 complain_overflow_signed, /* complain_on_overflow */
435 bfd_elf_generic_reloc, /* special_function */
436 AARCH64_R_STR (PREL16), /* name */
437 FALSE, /* partial_inplace */
438 0xffff, /* src_mask */
439 0xffff, /* dst_mask */
440 TRUE), /* pcrel_offset */
442 /* Group relocations to create a 16, 32, 48 or 64 bit
443 unsigned data or abs address inline. */
445 /* MOVZ: ((S+A) >> 0) & 0xffff */
446 HOWTO (AARCH64_R (MOVW_UABS_G0), /* type */
448 2, /* size (0 = byte, 1 = short, 2 = long) */
450 FALSE, /* pc_relative */
452 complain_overflow_unsigned, /* complain_on_overflow */
453 bfd_elf_generic_reloc, /* special_function */
454 AARCH64_R_STR (MOVW_UABS_G0), /* name */
455 FALSE, /* partial_inplace */
456 0xffff, /* src_mask */
457 0xffff, /* dst_mask */
458 FALSE), /* pcrel_offset */
460 /* MOVK: ((S+A) >> 0) & 0xffff [no overflow check] */
461 HOWTO (AARCH64_R (MOVW_UABS_G0_NC), /* type */
463 2, /* size (0 = byte, 1 = short, 2 = long) */
465 FALSE, /* pc_relative */
467 complain_overflow_dont, /* complain_on_overflow */
468 bfd_elf_generic_reloc, /* special_function */
469 AARCH64_R_STR (MOVW_UABS_G0_NC), /* name */
470 FALSE, /* partial_inplace */
471 0xffff, /* src_mask */
472 0xffff, /* dst_mask */
473 FALSE), /* pcrel_offset */
475 /* MOVZ: ((S+A) >> 16) & 0xffff */
476 HOWTO (AARCH64_R (MOVW_UABS_G1), /* type */
478 2, /* size (0 = byte, 1 = short, 2 = long) */
480 FALSE, /* pc_relative */
482 complain_overflow_unsigned, /* complain_on_overflow */
483 bfd_elf_generic_reloc, /* special_function */
484 AARCH64_R_STR (MOVW_UABS_G1), /* name */
485 FALSE, /* partial_inplace */
486 0xffff, /* src_mask */
487 0xffff, /* dst_mask */
488 FALSE), /* pcrel_offset */
490 /* MOVK: ((S+A) >> 16) & 0xffff [no overflow check] */
491 HOWTO64 (AARCH64_R (MOVW_UABS_G1_NC), /* type */
493 2, /* size (0 = byte, 1 = short, 2 = long) */
495 FALSE, /* pc_relative */
497 complain_overflow_dont, /* complain_on_overflow */
498 bfd_elf_generic_reloc, /* special_function */
499 AARCH64_R_STR (MOVW_UABS_G1_NC), /* name */
500 FALSE, /* partial_inplace */
501 0xffff, /* src_mask */
502 0xffff, /* dst_mask */
503 FALSE), /* pcrel_offset */
505 /* MOVZ: ((S+A) >> 32) & 0xffff */
506 HOWTO64 (AARCH64_R (MOVW_UABS_G2), /* type */
508 2, /* size (0 = byte, 1 = short, 2 = long) */
510 FALSE, /* pc_relative */
512 complain_overflow_unsigned, /* complain_on_overflow */
513 bfd_elf_generic_reloc, /* special_function */
514 AARCH64_R_STR (MOVW_UABS_G2), /* name */
515 FALSE, /* partial_inplace */
516 0xffff, /* src_mask */
517 0xffff, /* dst_mask */
518 FALSE), /* pcrel_offset */
520 /* MOVK: ((S+A) >> 32) & 0xffff [no overflow check] */
521 HOWTO64 (AARCH64_R (MOVW_UABS_G2_NC), /* type */
523 2, /* size (0 = byte, 1 = short, 2 = long) */
525 FALSE, /* pc_relative */
527 complain_overflow_dont, /* complain_on_overflow */
528 bfd_elf_generic_reloc, /* special_function */
529 AARCH64_R_STR (MOVW_UABS_G2_NC), /* name */
530 FALSE, /* partial_inplace */
531 0xffff, /* src_mask */
532 0xffff, /* dst_mask */
533 FALSE), /* pcrel_offset */
535 /* MOVZ: ((S+A) >> 48) & 0xffff */
536 HOWTO64 (AARCH64_R (MOVW_UABS_G3), /* type */
538 2, /* size (0 = byte, 1 = short, 2 = long) */
540 FALSE, /* pc_relative */
542 complain_overflow_unsigned, /* complain_on_overflow */
543 bfd_elf_generic_reloc, /* special_function */
544 AARCH64_R_STR (MOVW_UABS_G3), /* name */
545 FALSE, /* partial_inplace */
546 0xffff, /* src_mask */
547 0xffff, /* dst_mask */
548 FALSE), /* pcrel_offset */
550 /* Group relocations to create high part of a 16, 32, 48 or 64 bit
551 signed data or abs address inline. Will change instruction
552 to MOVN or MOVZ depending on sign of calculated value. */
554 /* MOV[ZN]: ((S+A) >> 0) & 0xffff */
555 HOWTO (AARCH64_R (MOVW_SABS_G0), /* type */
557 2, /* size (0 = byte, 1 = short, 2 = long) */
559 FALSE, /* pc_relative */
561 complain_overflow_signed, /* complain_on_overflow */
562 bfd_elf_generic_reloc, /* special_function */
563 AARCH64_R_STR (MOVW_SABS_G0), /* name */
564 FALSE, /* partial_inplace */
565 0xffff, /* src_mask */
566 0xffff, /* dst_mask */
567 FALSE), /* pcrel_offset */
569 /* MOV[ZN]: ((S+A) >> 16) & 0xffff */
570 HOWTO64 (AARCH64_R (MOVW_SABS_G1), /* type */
572 2, /* size (0 = byte, 1 = short, 2 = long) */
574 FALSE, /* pc_relative */
576 complain_overflow_signed, /* complain_on_overflow */
577 bfd_elf_generic_reloc, /* special_function */
578 AARCH64_R_STR (MOVW_SABS_G1), /* name */
579 FALSE, /* partial_inplace */
580 0xffff, /* src_mask */
581 0xffff, /* dst_mask */
582 FALSE), /* pcrel_offset */
584 /* MOV[ZN]: ((S+A) >> 32) & 0xffff */
585 HOWTO64 (AARCH64_R (MOVW_SABS_G2), /* type */
587 2, /* size (0 = byte, 1 = short, 2 = long) */
589 FALSE, /* pc_relative */
591 complain_overflow_signed, /* complain_on_overflow */
592 bfd_elf_generic_reloc, /* special_function */
593 AARCH64_R_STR (MOVW_SABS_G2), /* name */
594 FALSE, /* partial_inplace */
595 0xffff, /* src_mask */
596 0xffff, /* dst_mask */
597 FALSE), /* pcrel_offset */
599 /* Relocations to generate 19, 21 and 33 bit PC-relative load/store
600 addresses: PG(x) is (x & ~0xfff). */
602 /* LD-lit: ((S+A-P) >> 2) & 0x7ffff */
603 HOWTO (AARCH64_R (LD_PREL_LO19), /* type */
605 2, /* size (0 = byte, 1 = short, 2 = long) */
607 TRUE, /* pc_relative */
609 complain_overflow_signed, /* complain_on_overflow */
610 bfd_elf_generic_reloc, /* special_function */
611 AARCH64_R_STR (LD_PREL_LO19), /* name */
612 FALSE, /* partial_inplace */
613 0x7ffff, /* src_mask */
614 0x7ffff, /* dst_mask */
615 TRUE), /* pcrel_offset */
617 /* ADR: (S+A-P) & 0x1fffff */
618 HOWTO (AARCH64_R (ADR_PREL_LO21), /* type */
620 2, /* size (0 = byte, 1 = short, 2 = long) */
622 TRUE, /* pc_relative */
624 complain_overflow_signed, /* complain_on_overflow */
625 bfd_elf_generic_reloc, /* special_function */
626 AARCH64_R_STR (ADR_PREL_LO21), /* name */
627 FALSE, /* partial_inplace */
628 0x1fffff, /* src_mask */
629 0x1fffff, /* dst_mask */
630 TRUE), /* pcrel_offset */
632 /* ADRP: ((PG(S+A)-PG(P)) >> 12) & 0x1fffff */
633 HOWTO (AARCH64_R (ADR_PREL_PG_HI21), /* type */
635 2, /* size (0 = byte, 1 = short, 2 = long) */
637 TRUE, /* pc_relative */
639 complain_overflow_signed, /* complain_on_overflow */
640 bfd_elf_generic_reloc, /* special_function */
641 AARCH64_R_STR (ADR_PREL_PG_HI21), /* name */
642 FALSE, /* partial_inplace */
643 0x1fffff, /* src_mask */
644 0x1fffff, /* dst_mask */
645 TRUE), /* pcrel_offset */
647 /* ADRP: ((PG(S+A)-PG(P)) >> 12) & 0x1fffff [no overflow check] */
648 HOWTO64 (AARCH64_R (ADR_PREL_PG_HI21_NC), /* type */
650 2, /* size (0 = byte, 1 = short, 2 = long) */
652 TRUE, /* pc_relative */
654 complain_overflow_dont, /* complain_on_overflow */
655 bfd_elf_generic_reloc, /* special_function */
656 AARCH64_R_STR (ADR_PREL_PG_HI21_NC), /* name */
657 FALSE, /* partial_inplace */
658 0x1fffff, /* src_mask */
659 0x1fffff, /* dst_mask */
660 TRUE), /* pcrel_offset */
662 /* ADD: (S+A) & 0xfff [no overflow check] */
663 HOWTO (AARCH64_R (ADD_ABS_LO12_NC), /* type */
665 2, /* size (0 = byte, 1 = short, 2 = long) */
667 FALSE, /* pc_relative */
669 complain_overflow_dont, /* complain_on_overflow */
670 bfd_elf_generic_reloc, /* special_function */
671 AARCH64_R_STR (ADD_ABS_LO12_NC), /* name */
672 FALSE, /* partial_inplace */
673 0x3ffc00, /* src_mask */
674 0x3ffc00, /* dst_mask */
675 FALSE), /* pcrel_offset */
677 /* LD/ST8: (S+A) & 0xfff */
678 HOWTO (AARCH64_R (LDST8_ABS_LO12_NC), /* type */
680 2, /* size (0 = byte, 1 = short, 2 = long) */
682 FALSE, /* pc_relative */
684 complain_overflow_dont, /* complain_on_overflow */
685 bfd_elf_generic_reloc, /* special_function */
686 AARCH64_R_STR (LDST8_ABS_LO12_NC), /* name */
687 FALSE, /* partial_inplace */
688 0xfff, /* src_mask */
689 0xfff, /* dst_mask */
690 FALSE), /* pcrel_offset */
692 /* Relocations for control-flow instructions. */
694 /* TBZ/NZ: ((S+A-P) >> 2) & 0x3fff */
695 HOWTO (AARCH64_R (TSTBR14), /* type */
697 2, /* size (0 = byte, 1 = short, 2 = long) */
699 TRUE, /* pc_relative */
701 complain_overflow_signed, /* complain_on_overflow */
702 bfd_elf_generic_reloc, /* special_function */
703 AARCH64_R_STR (TSTBR14), /* name */
704 FALSE, /* partial_inplace */
705 0x3fff, /* src_mask */
706 0x3fff, /* dst_mask */
707 TRUE), /* pcrel_offset */
709 /* B.cond: ((S+A-P) >> 2) & 0x7ffff */
710 HOWTO (AARCH64_R (CONDBR19), /* type */
712 2, /* size (0 = byte, 1 = short, 2 = long) */
714 TRUE, /* pc_relative */
716 complain_overflow_signed, /* complain_on_overflow */
717 bfd_elf_generic_reloc, /* special_function */
718 AARCH64_R_STR (CONDBR19), /* name */
719 FALSE, /* partial_inplace */
720 0x7ffff, /* src_mask */
721 0x7ffff, /* dst_mask */
722 TRUE), /* pcrel_offset */
724 /* B: ((S+A-P) >> 2) & 0x3ffffff */
725 HOWTO (AARCH64_R (JUMP26), /* type */
727 2, /* size (0 = byte, 1 = short, 2 = long) */
729 TRUE, /* pc_relative */
731 complain_overflow_signed, /* complain_on_overflow */
732 bfd_elf_generic_reloc, /* special_function */
733 AARCH64_R_STR (JUMP26), /* name */
734 FALSE, /* partial_inplace */
735 0x3ffffff, /* src_mask */
736 0x3ffffff, /* dst_mask */
737 TRUE), /* pcrel_offset */
739 /* BL: ((S+A-P) >> 2) & 0x3ffffff */
740 HOWTO (AARCH64_R (CALL26), /* type */
742 2, /* size (0 = byte, 1 = short, 2 = long) */
744 TRUE, /* pc_relative */
746 complain_overflow_signed, /* complain_on_overflow */
747 bfd_elf_generic_reloc, /* special_function */
748 AARCH64_R_STR (CALL26), /* name */
749 FALSE, /* partial_inplace */
750 0x3ffffff, /* src_mask */
751 0x3ffffff, /* dst_mask */
752 TRUE), /* pcrel_offset */
754 /* LD/ST16: (S+A) & 0xffe */
755 HOWTO (AARCH64_R (LDST16_ABS_LO12_NC), /* type */
757 2, /* size (0 = byte, 1 = short, 2 = long) */
759 FALSE, /* pc_relative */
761 complain_overflow_dont, /* complain_on_overflow */
762 bfd_elf_generic_reloc, /* special_function */
763 AARCH64_R_STR (LDST16_ABS_LO12_NC), /* name */
764 FALSE, /* partial_inplace */
765 0xffe, /* src_mask */
766 0xffe, /* dst_mask */
767 FALSE), /* pcrel_offset */
769 /* LD/ST32: (S+A) & 0xffc */
770 HOWTO (AARCH64_R (LDST32_ABS_LO12_NC), /* type */
772 2, /* size (0 = byte, 1 = short, 2 = long) */
774 FALSE, /* pc_relative */
776 complain_overflow_dont, /* complain_on_overflow */
777 bfd_elf_generic_reloc, /* special_function */
778 AARCH64_R_STR (LDST32_ABS_LO12_NC), /* name */
779 FALSE, /* partial_inplace */
780 0xffc, /* src_mask */
781 0xffc, /* dst_mask */
782 FALSE), /* pcrel_offset */
784 /* LD/ST64: (S+A) & 0xff8 */
785 HOWTO (AARCH64_R (LDST64_ABS_LO12_NC), /* type */
787 2, /* size (0 = byte, 1 = short, 2 = long) */
789 FALSE, /* pc_relative */
791 complain_overflow_dont, /* complain_on_overflow */
792 bfd_elf_generic_reloc, /* special_function */
793 AARCH64_R_STR (LDST64_ABS_LO12_NC), /* name */
794 FALSE, /* partial_inplace */
795 0xff8, /* src_mask */
796 0xff8, /* dst_mask */
797 FALSE), /* pcrel_offset */
799 /* LD/ST128: (S+A) & 0xff0 */
800 HOWTO (AARCH64_R (LDST128_ABS_LO12_NC), /* type */
802 2, /* size (0 = byte, 1 = short, 2 = long) */
804 FALSE, /* pc_relative */
806 complain_overflow_dont, /* complain_on_overflow */
807 bfd_elf_generic_reloc, /* special_function */
808 AARCH64_R_STR (LDST128_ABS_LO12_NC), /* name */
809 FALSE, /* partial_inplace */
810 0xff0, /* src_mask */
811 0xff0, /* dst_mask */
812 FALSE), /* pcrel_offset */
814 /* Set a load-literal immediate field to bits
815 0x1FFFFC of G(S)-P */
816 HOWTO (AARCH64_R (GOT_LD_PREL19), /* type */
818 2, /* size (0 = byte,1 = short,2 = long) */
820 TRUE, /* pc_relative */
822 complain_overflow_signed, /* complain_on_overflow */
823 bfd_elf_generic_reloc, /* special_function */
824 AARCH64_R_STR (GOT_LD_PREL19), /* name */
825 FALSE, /* partial_inplace */
826 0xffffe0, /* src_mask */
827 0xffffe0, /* dst_mask */
828 TRUE), /* pcrel_offset */
830 /* Get to the page for the GOT entry for the symbol
831 (G(S) - P) using an ADRP instruction. */
832 HOWTO (AARCH64_R (ADR_GOT_PAGE), /* type */
834 2, /* size (0 = byte, 1 = short, 2 = long) */
836 TRUE, /* pc_relative */
838 complain_overflow_dont, /* complain_on_overflow */
839 bfd_elf_generic_reloc, /* special_function */
840 AARCH64_R_STR (ADR_GOT_PAGE), /* name */
841 FALSE, /* partial_inplace */
842 0x1fffff, /* src_mask */
843 0x1fffff, /* dst_mask */
844 TRUE), /* pcrel_offset */
846 /* LD64: GOT offset G(S) & 0xff8 */
847 HOWTO64 (AARCH64_R (LD64_GOT_LO12_NC), /* type */
849 2, /* size (0 = byte, 1 = short, 2 = long) */
851 FALSE, /* pc_relative */
853 complain_overflow_dont, /* complain_on_overflow */
854 bfd_elf_generic_reloc, /* special_function */
855 AARCH64_R_STR (LD64_GOT_LO12_NC), /* name */
856 FALSE, /* partial_inplace */
857 0xff8, /* src_mask */
858 0xff8, /* dst_mask */
859 FALSE), /* pcrel_offset */
861 /* LD32: GOT offset G(S) & 0xffc */
862 HOWTO32 (AARCH64_R (LD32_GOT_LO12_NC), /* type */
864 2, /* size (0 = byte, 1 = short, 2 = long) */
866 FALSE, /* pc_relative */
868 complain_overflow_dont, /* complain_on_overflow */
869 bfd_elf_generic_reloc, /* special_function */
870 AARCH64_R_STR (LD32_GOT_LO12_NC), /* name */
871 FALSE, /* partial_inplace */
872 0xffc, /* src_mask */
873 0xffc, /* dst_mask */
874 FALSE), /* pcrel_offset */
876 /* LD64: GOT offset for the symbol. */
877 HOWTO64 (AARCH64_R (LD64_GOTOFF_LO15), /* type */
879 2, /* size (0 = byte, 1 = short, 2 = long) */
881 FALSE, /* pc_relative */
883 complain_overflow_unsigned, /* complain_on_overflow */
884 bfd_elf_generic_reloc, /* special_function */
885 AARCH64_R_STR (LD64_GOTOFF_LO15), /* name */
886 FALSE, /* partial_inplace */
887 0x7ff8, /* src_mask */
888 0x7ff8, /* dst_mask */
889 FALSE), /* pcrel_offset */
891 /* LD32: GOT offset to the page address of GOT table.
892 (G(S) - PAGE (_GLOBAL_OFFSET_TABLE_)) & 0x5ffc. */
893 HOWTO32 (AARCH64_R (LD32_GOTPAGE_LO14), /* type */
895 2, /* size (0 = byte, 1 = short, 2 = long) */
897 FALSE, /* pc_relative */
899 complain_overflow_unsigned, /* complain_on_overflow */
900 bfd_elf_generic_reloc, /* special_function */
901 AARCH64_R_STR (LD32_GOTPAGE_LO14), /* name */
902 FALSE, /* partial_inplace */
903 0x5ffc, /* src_mask */
904 0x5ffc, /* dst_mask */
905 FALSE), /* pcrel_offset */
907 /* LD64: GOT offset to the page address of GOT table.
908 (G(S) - PAGE (_GLOBAL_OFFSET_TABLE_)) & 0x7ff8. */
909 HOWTO64 (AARCH64_R (LD64_GOTPAGE_LO15), /* type */
911 2, /* size (0 = byte, 1 = short, 2 = long) */
913 FALSE, /* pc_relative */
915 complain_overflow_unsigned, /* complain_on_overflow */
916 bfd_elf_generic_reloc, /* special_function */
917 AARCH64_R_STR (LD64_GOTPAGE_LO15), /* name */
918 FALSE, /* partial_inplace */
919 0x7ff8, /* src_mask */
920 0x7ff8, /* dst_mask */
921 FALSE), /* pcrel_offset */
923 /* Get to the page for the GOT entry for the symbol
924 (G(S) - P) using an ADRP instruction. */
925 HOWTO (AARCH64_R (TLSGD_ADR_PAGE21), /* type */
927 2, /* size (0 = byte, 1 = short, 2 = long) */
929 TRUE, /* pc_relative */
931 complain_overflow_dont, /* complain_on_overflow */
932 bfd_elf_generic_reloc, /* special_function */
933 AARCH64_R_STR (TLSGD_ADR_PAGE21), /* name */
934 FALSE, /* partial_inplace */
935 0x1fffff, /* src_mask */
936 0x1fffff, /* dst_mask */
937 TRUE), /* pcrel_offset */
939 HOWTO (AARCH64_R (TLSGD_ADR_PREL21), /* type */
941 2, /* size (0 = byte, 1 = short, 2 = long) */
943 TRUE, /* pc_relative */
945 complain_overflow_dont, /* complain_on_overflow */
946 bfd_elf_generic_reloc, /* special_function */
947 AARCH64_R_STR (TLSGD_ADR_PREL21), /* name */
948 FALSE, /* partial_inplace */
949 0x1fffff, /* src_mask */
950 0x1fffff, /* dst_mask */
951 TRUE), /* pcrel_offset */
953 /* ADD: GOT offset G(S) & 0xff8 [no overflow check] */
954 HOWTO (AARCH64_R (TLSGD_ADD_LO12_NC), /* type */
956 2, /* size (0 = byte, 1 = short, 2 = long) */
958 FALSE, /* pc_relative */
960 complain_overflow_dont, /* complain_on_overflow */
961 bfd_elf_generic_reloc, /* special_function */
962 AARCH64_R_STR (TLSGD_ADD_LO12_NC), /* name */
963 FALSE, /* partial_inplace */
964 0xfff, /* src_mask */
965 0xfff, /* dst_mask */
966 FALSE), /* pcrel_offset */
968 HOWTO64 (AARCH64_R (TLSIE_MOVW_GOTTPREL_G1), /* type */
970 2, /* size (0 = byte, 1 = short, 2 = long) */
972 FALSE, /* pc_relative */
974 complain_overflow_dont, /* complain_on_overflow */
975 bfd_elf_generic_reloc, /* special_function */
976 AARCH64_R_STR (TLSIE_MOVW_GOTTPREL_G1), /* name */
977 FALSE, /* partial_inplace */
978 0xffff, /* src_mask */
979 0xffff, /* dst_mask */
980 FALSE), /* pcrel_offset */
982 HOWTO64 (AARCH64_R (TLSIE_MOVW_GOTTPREL_G0_NC), /* type */
984 2, /* size (0 = byte, 1 = short, 2 = long) */
986 FALSE, /* pc_relative */
988 complain_overflow_dont, /* complain_on_overflow */
989 bfd_elf_generic_reloc, /* special_function */
990 AARCH64_R_STR (TLSIE_MOVW_GOTTPREL_G0_NC), /* name */
991 FALSE, /* partial_inplace */
992 0xffff, /* src_mask */
993 0xffff, /* dst_mask */
994 FALSE), /* pcrel_offset */
996 HOWTO (AARCH64_R (TLSIE_ADR_GOTTPREL_PAGE21), /* type */
998 2, /* size (0 = byte, 1 = short, 2 = long) */
1000 FALSE, /* pc_relative */
1002 complain_overflow_dont, /* complain_on_overflow */
1003 bfd_elf_generic_reloc, /* special_function */
1004 AARCH64_R_STR (TLSIE_ADR_GOTTPREL_PAGE21), /* name */
1005 FALSE, /* partial_inplace */
1006 0x1fffff, /* src_mask */
1007 0x1fffff, /* dst_mask */
1008 FALSE), /* pcrel_offset */
1010 HOWTO64 (AARCH64_R (TLSIE_LD64_GOTTPREL_LO12_NC), /* type */
1012 2, /* size (0 = byte, 1 = short, 2 = long) */
1014 FALSE, /* pc_relative */
1016 complain_overflow_dont, /* complain_on_overflow */
1017 bfd_elf_generic_reloc, /* special_function */
1018 AARCH64_R_STR (TLSIE_LD64_GOTTPREL_LO12_NC), /* name */
1019 FALSE, /* partial_inplace */
1020 0xff8, /* src_mask */
1021 0xff8, /* dst_mask */
1022 FALSE), /* pcrel_offset */
1024 HOWTO32 (AARCH64_R (TLSIE_LD32_GOTTPREL_LO12_NC), /* type */
1026 2, /* size (0 = byte, 1 = short, 2 = long) */
1028 FALSE, /* pc_relative */
1030 complain_overflow_dont, /* complain_on_overflow */
1031 bfd_elf_generic_reloc, /* special_function */
1032 AARCH64_R_STR (TLSIE_LD32_GOTTPREL_LO12_NC), /* name */
1033 FALSE, /* partial_inplace */
1034 0xffc, /* src_mask */
1035 0xffc, /* dst_mask */
1036 FALSE), /* pcrel_offset */
1038 HOWTO (AARCH64_R (TLSIE_LD_GOTTPREL_PREL19), /* type */
1040 2, /* size (0 = byte, 1 = short, 2 = long) */
1042 FALSE, /* pc_relative */
1044 complain_overflow_dont, /* complain_on_overflow */
1045 bfd_elf_generic_reloc, /* special_function */
1046 AARCH64_R_STR (TLSIE_LD_GOTTPREL_PREL19), /* name */
1047 FALSE, /* partial_inplace */
1048 0x1ffffc, /* src_mask */
1049 0x1ffffc, /* dst_mask */
1050 FALSE), /* pcrel_offset */
1052 /* ADD: bit[23:12] of byte offset to module TLS base address. */
1053 HOWTO (AARCH64_R (TLSLD_ADD_DTPREL_HI12), /* type */
1054 12, /* rightshift */
1055 2, /* size (0 = byte, 1 = short, 2 = long) */
1057 FALSE, /* pc_relative */
1059 complain_overflow_unsigned, /* complain_on_overflow */
1060 bfd_elf_generic_reloc, /* special_function */
1061 AARCH64_R_STR (TLSLD_ADD_DTPREL_HI12), /* name */
1062 FALSE, /* partial_inplace */
1063 0xfff, /* src_mask */
1064 0xfff, /* dst_mask */
1065 FALSE), /* pcrel_offset */
1067 /* Unsigned 12 bit byte offset to module TLS base address. */
1068 HOWTO (AARCH64_R (TLSLD_ADD_DTPREL_LO12), /* type */
1070 2, /* size (0 = byte, 1 = short, 2 = long) */
1072 FALSE, /* pc_relative */
1074 complain_overflow_unsigned, /* complain_on_overflow */
1075 bfd_elf_generic_reloc, /* special_function */
1076 AARCH64_R_STR (TLSLD_ADD_DTPREL_LO12), /* name */
1077 FALSE, /* partial_inplace */
1078 0xfff, /* src_mask */
1079 0xfff, /* dst_mask */
1080 FALSE), /* pcrel_offset */
1082 /* No overflow check version of BFD_RELOC_AARCH64_TLSLD_ADD_DTPREL_LO12. */
1083 HOWTO (AARCH64_R (TLSLD_ADD_DTPREL_LO12_NC), /* type */
1085 2, /* size (0 = byte, 1 = short, 2 = long) */
1087 FALSE, /* pc_relative */
1089 complain_overflow_dont, /* complain_on_overflow */
1090 bfd_elf_generic_reloc, /* special_function */
1091 AARCH64_R_STR (TLSLD_ADD_DTPREL_LO12_NC), /* name */
1092 FALSE, /* partial_inplace */
1093 0xfff, /* src_mask */
1094 0xfff, /* dst_mask */
1095 FALSE), /* pcrel_offset */
1097 /* ADD: GOT offset G(S) & 0xff8 [no overflow check] */
1098 HOWTO (AARCH64_R (TLSLD_ADD_LO12_NC), /* type */
1100 2, /* size (0 = byte, 1 = short, 2 = long) */
1102 FALSE, /* pc_relative */
1104 complain_overflow_dont, /* complain_on_overflow */
1105 bfd_elf_generic_reloc, /* special_function */
1106 AARCH64_R_STR (TLSLD_ADD_LO12_NC), /* name */
1107 FALSE, /* partial_inplace */
1108 0xfff, /* src_mask */
1109 0xfff, /* dst_mask */
1110 FALSE), /* pcrel_offset */
1112 /* Get to the page for the GOT entry for the symbol
1113 (G(S) - P) using an ADRP instruction. */
1114 HOWTO (AARCH64_R (TLSLD_ADR_PAGE21), /* type */
1115 12, /* rightshift */
1116 2, /* size (0 = byte, 1 = short, 2 = long) */
1118 TRUE, /* pc_relative */
1120 complain_overflow_signed, /* complain_on_overflow */
1121 bfd_elf_generic_reloc, /* special_function */
1122 AARCH64_R_STR (TLSLD_ADR_PAGE21), /* name */
1123 FALSE, /* partial_inplace */
1124 0x1fffff, /* src_mask */
1125 0x1fffff, /* dst_mask */
1126 TRUE), /* pcrel_offset */
1128 HOWTO (AARCH64_R (TLSLD_ADR_PREL21), /* type */
1130 2, /* size (0 = byte, 1 = short, 2 = long) */
1132 TRUE, /* pc_relative */
1134 complain_overflow_signed, /* complain_on_overflow */
1135 bfd_elf_generic_reloc, /* special_function */
1136 AARCH64_R_STR (TLSLD_ADR_PREL21), /* name */
1137 FALSE, /* partial_inplace */
1138 0x1fffff, /* src_mask */
1139 0x1fffff, /* dst_mask */
1140 TRUE), /* pcrel_offset */
1142 /* MOVZ: bit[15:0] of byte offset to module TLS base address. */
1143 HOWTO (AARCH64_R (TLSLD_MOVW_DTPREL_G0), /* type */
1145 2, /* size (0 = byte, 1 = short, 2 = long) */
1147 FALSE, /* pc_relative */
1149 complain_overflow_unsigned, /* complain_on_overflow */
1150 bfd_elf_generic_reloc, /* special_function */
1151 AARCH64_R_STR (TLSLD_MOVW_DTPREL_G0), /* name */
1152 FALSE, /* partial_inplace */
1153 0xffff, /* src_mask */
1154 0xffff, /* dst_mask */
1155 FALSE), /* pcrel_offset */
1157 /* No overflow check version of BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G0. */
1158 HOWTO (AARCH64_R (TLSLD_MOVW_DTPREL_G0_NC), /* type */
1160 2, /* size (0 = byte, 1 = short, 2 = long) */
1162 FALSE, /* pc_relative */
1164 complain_overflow_dont, /* complain_on_overflow */
1165 bfd_elf_generic_reloc, /* special_function */
1166 AARCH64_R_STR (TLSLD_MOVW_DTPREL_G0_NC), /* name */
1167 FALSE, /* partial_inplace */
1168 0xffff, /* src_mask */
1169 0xffff, /* dst_mask */
1170 FALSE), /* pcrel_offset */
1172 /* MOVZ: bit[31:16] of byte offset to module TLS base address. */
1173 HOWTO (AARCH64_R (TLSLD_MOVW_DTPREL_G1), /* type */
1174 16, /* rightshift */
1175 2, /* size (0 = byte, 1 = short, 2 = long) */
1177 FALSE, /* pc_relative */
1179 complain_overflow_unsigned, /* complain_on_overflow */
1180 bfd_elf_generic_reloc, /* special_function */
1181 AARCH64_R_STR (TLSLD_MOVW_DTPREL_G1), /* name */
1182 FALSE, /* partial_inplace */
1183 0xffff, /* src_mask */
1184 0xffff, /* dst_mask */
1185 FALSE), /* pcrel_offset */
1187 /* No overflow check version of BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G1. */
1188 HOWTO64 (AARCH64_R (TLSLD_MOVW_DTPREL_G1_NC), /* type */
1189 16, /* rightshift */
1190 2, /* size (0 = byte, 1 = short, 2 = long) */
1192 FALSE, /* pc_relative */
1194 complain_overflow_dont, /* complain_on_overflow */
1195 bfd_elf_generic_reloc, /* special_function */
1196 AARCH64_R_STR (TLSLD_MOVW_DTPREL_G1_NC), /* name */
1197 FALSE, /* partial_inplace */
1198 0xffff, /* src_mask */
1199 0xffff, /* dst_mask */
1200 FALSE), /* pcrel_offset */
1202 /* MOVZ: bit[47:32] of byte offset to module TLS base address. */
1203 HOWTO64 (AARCH64_R (TLSLD_MOVW_DTPREL_G2), /* type */
1204 32, /* rightshift */
1205 2, /* size (0 = byte, 1 = short, 2 = long) */
1207 FALSE, /* pc_relative */
1209 complain_overflow_unsigned, /* complain_on_overflow */
1210 bfd_elf_generic_reloc, /* special_function */
1211 AARCH64_R_STR (TLSLD_MOVW_DTPREL_G2), /* name */
1212 FALSE, /* partial_inplace */
1213 0xffff, /* src_mask */
1214 0xffff, /* dst_mask */
1215 FALSE), /* pcrel_offset */
1217 HOWTO64 (AARCH64_R (TLSLE_MOVW_TPREL_G2), /* type */
1218 32, /* rightshift */
1219 2, /* size (0 = byte, 1 = short, 2 = long) */
1221 FALSE, /* pc_relative */
1223 complain_overflow_unsigned, /* complain_on_overflow */
1224 bfd_elf_generic_reloc, /* special_function */
1225 AARCH64_R_STR (TLSLE_MOVW_TPREL_G2), /* name */
1226 FALSE, /* partial_inplace */
1227 0xffff, /* src_mask */
1228 0xffff, /* dst_mask */
1229 FALSE), /* pcrel_offset */
1231 HOWTO (AARCH64_R (TLSLE_MOVW_TPREL_G1), /* type */
1232 16, /* rightshift */
1233 2, /* size (0 = byte, 1 = short, 2 = long) */
1235 FALSE, /* pc_relative */
1237 complain_overflow_dont, /* complain_on_overflow */
1238 bfd_elf_generic_reloc, /* special_function */
1239 AARCH64_R_STR (TLSLE_MOVW_TPREL_G1), /* name */
1240 FALSE, /* partial_inplace */
1241 0xffff, /* src_mask */
1242 0xffff, /* dst_mask */
1243 FALSE), /* pcrel_offset */
1245 HOWTO64 (AARCH64_R (TLSLE_MOVW_TPREL_G1_NC), /* type */
1246 16, /* rightshift */
1247 2, /* size (0 = byte, 1 = short, 2 = long) */
1249 FALSE, /* pc_relative */
1251 complain_overflow_dont, /* complain_on_overflow */
1252 bfd_elf_generic_reloc, /* special_function */
1253 AARCH64_R_STR (TLSLE_MOVW_TPREL_G1_NC), /* name */
1254 FALSE, /* partial_inplace */
1255 0xffff, /* src_mask */
1256 0xffff, /* dst_mask */
1257 FALSE), /* pcrel_offset */
1259 HOWTO (AARCH64_R (TLSLE_MOVW_TPREL_G0), /* type */
1261 2, /* size (0 = byte, 1 = short, 2 = long) */
1263 FALSE, /* pc_relative */
1265 complain_overflow_dont, /* complain_on_overflow */
1266 bfd_elf_generic_reloc, /* special_function */
1267 AARCH64_R_STR (TLSLE_MOVW_TPREL_G0), /* name */
1268 FALSE, /* partial_inplace */
1269 0xffff, /* src_mask */
1270 0xffff, /* dst_mask */
1271 FALSE), /* pcrel_offset */
1273 HOWTO (AARCH64_R (TLSLE_MOVW_TPREL_G0_NC), /* type */
1275 2, /* size (0 = byte, 1 = short, 2 = long) */
1277 FALSE, /* pc_relative */
1279 complain_overflow_dont, /* complain_on_overflow */
1280 bfd_elf_generic_reloc, /* special_function */
1281 AARCH64_R_STR (TLSLE_MOVW_TPREL_G0_NC), /* name */
1282 FALSE, /* partial_inplace */
1283 0xffff, /* src_mask */
1284 0xffff, /* dst_mask */
1285 FALSE), /* pcrel_offset */
1287 HOWTO (AARCH64_R (TLSLE_ADD_TPREL_HI12), /* type */
1288 12, /* rightshift */
1289 2, /* size (0 = byte, 1 = short, 2 = long) */
1291 FALSE, /* pc_relative */
1293 complain_overflow_unsigned, /* complain_on_overflow */
1294 bfd_elf_generic_reloc, /* special_function */
1295 AARCH64_R_STR (TLSLE_ADD_TPREL_HI12), /* name */
1296 FALSE, /* partial_inplace */
1297 0xfff, /* src_mask */
1298 0xfff, /* dst_mask */
1299 FALSE), /* pcrel_offset */
1301 HOWTO (AARCH64_R (TLSLE_ADD_TPREL_LO12), /* type */
1303 2, /* size (0 = byte, 1 = short, 2 = long) */
1305 FALSE, /* pc_relative */
1307 complain_overflow_unsigned, /* complain_on_overflow */
1308 bfd_elf_generic_reloc, /* special_function */
1309 AARCH64_R_STR (TLSLE_ADD_TPREL_LO12), /* name */
1310 FALSE, /* partial_inplace */
1311 0xfff, /* src_mask */
1312 0xfff, /* dst_mask */
1313 FALSE), /* pcrel_offset */
1315 HOWTO (AARCH64_R (TLSLE_ADD_TPREL_LO12_NC), /* type */
1317 2, /* size (0 = byte, 1 = short, 2 = long) */
1319 FALSE, /* pc_relative */
1321 complain_overflow_dont, /* complain_on_overflow */
1322 bfd_elf_generic_reloc, /* special_function */
1323 AARCH64_R_STR (TLSLE_ADD_TPREL_LO12_NC), /* name */
1324 FALSE, /* partial_inplace */
1325 0xfff, /* src_mask */
1326 0xfff, /* dst_mask */
1327 FALSE), /* pcrel_offset */
1329 HOWTO (AARCH64_R (TLSDESC_LD_PREL19), /* type */
1331 2, /* size (0 = byte, 1 = short, 2 = long) */
1333 TRUE, /* pc_relative */
1335 complain_overflow_dont, /* complain_on_overflow */
1336 bfd_elf_generic_reloc, /* special_function */
1337 AARCH64_R_STR (TLSDESC_LD_PREL19), /* name */
1338 FALSE, /* partial_inplace */
1339 0x0ffffe0, /* src_mask */
1340 0x0ffffe0, /* dst_mask */
1341 TRUE), /* pcrel_offset */
1343 HOWTO (AARCH64_R (TLSDESC_ADR_PREL21), /* type */
1345 2, /* size (0 = byte, 1 = short, 2 = long) */
1347 TRUE, /* pc_relative */
1349 complain_overflow_dont, /* complain_on_overflow */
1350 bfd_elf_generic_reloc, /* special_function */
1351 AARCH64_R_STR (TLSDESC_ADR_PREL21), /* name */
1352 FALSE, /* partial_inplace */
1353 0x1fffff, /* src_mask */
1354 0x1fffff, /* dst_mask */
1355 TRUE), /* pcrel_offset */
1357 /* Get to the page for the GOT entry for the symbol
1358 (G(S) - P) using an ADRP instruction. */
1359 HOWTO (AARCH64_R (TLSDESC_ADR_PAGE21), /* type */
1360 12, /* rightshift */
1361 2, /* size (0 = byte, 1 = short, 2 = long) */
1363 TRUE, /* pc_relative */
1365 complain_overflow_dont, /* complain_on_overflow */
1366 bfd_elf_generic_reloc, /* special_function */
1367 AARCH64_R_STR (TLSDESC_ADR_PAGE21), /* name */
1368 FALSE, /* partial_inplace */
1369 0x1fffff, /* src_mask */
1370 0x1fffff, /* dst_mask */
1371 TRUE), /* pcrel_offset */
1373 /* LD64: GOT offset G(S) & 0xff8. */
1374 HOWTO64 (AARCH64_R (TLSDESC_LD64_LO12_NC), /* type */
1376 2, /* size (0 = byte, 1 = short, 2 = long) */
1378 FALSE, /* pc_relative */
1380 complain_overflow_dont, /* complain_on_overflow */
1381 bfd_elf_generic_reloc, /* special_function */
1382 AARCH64_R_STR (TLSDESC_LD64_LO12_NC), /* name */
1383 FALSE, /* partial_inplace */
1384 0xff8, /* src_mask */
1385 0xff8, /* dst_mask */
1386 FALSE), /* pcrel_offset */
1388 /* LD32: GOT offset G(S) & 0xffc. */
1389 HOWTO32 (AARCH64_R (TLSDESC_LD32_LO12_NC), /* type */
1391 2, /* size (0 = byte, 1 = short, 2 = long) */
1393 FALSE, /* pc_relative */
1395 complain_overflow_dont, /* complain_on_overflow */
1396 bfd_elf_generic_reloc, /* special_function */
1397 AARCH64_R_STR (TLSDESC_LD32_LO12_NC), /* name */
1398 FALSE, /* partial_inplace */
1399 0xffc, /* src_mask */
1400 0xffc, /* dst_mask */
1401 FALSE), /* pcrel_offset */
1403 /* ADD: GOT offset G(S) & 0xfff. */
1404 HOWTO (AARCH64_R (TLSDESC_ADD_LO12_NC), /* type */
1406 2, /* size (0 = byte, 1 = short, 2 = long) */
1408 FALSE, /* pc_relative */
1410 complain_overflow_dont, /* complain_on_overflow */
1411 bfd_elf_generic_reloc, /* special_function */
1412 AARCH64_R_STR (TLSDESC_ADD_LO12_NC), /* name */
1413 FALSE, /* partial_inplace */
1414 0xfff, /* src_mask */
1415 0xfff, /* dst_mask */
1416 FALSE), /* pcrel_offset */
1418 HOWTO64 (AARCH64_R (TLSDESC_OFF_G1), /* type */
1419 16, /* rightshift */
1420 2, /* size (0 = byte, 1 = short, 2 = long) */
1422 FALSE, /* pc_relative */
1424 complain_overflow_dont, /* complain_on_overflow */
1425 bfd_elf_generic_reloc, /* special_function */
1426 AARCH64_R_STR (TLSDESC_OFF_G1), /* name */
1427 FALSE, /* partial_inplace */
1428 0xffff, /* src_mask */
1429 0xffff, /* dst_mask */
1430 FALSE), /* pcrel_offset */
1432 HOWTO64 (AARCH64_R (TLSDESC_OFF_G0_NC), /* type */
1434 2, /* size (0 = byte, 1 = short, 2 = long) */
1436 FALSE, /* pc_relative */
1438 complain_overflow_dont, /* complain_on_overflow */
1439 bfd_elf_generic_reloc, /* special_function */
1440 AARCH64_R_STR (TLSDESC_OFF_G0_NC), /* name */
1441 FALSE, /* partial_inplace */
1442 0xffff, /* src_mask */
1443 0xffff, /* dst_mask */
1444 FALSE), /* pcrel_offset */
1446 HOWTO64 (AARCH64_R (TLSDESC_LDR), /* type */
1448 2, /* size (0 = byte, 1 = short, 2 = long) */
1450 FALSE, /* pc_relative */
1452 complain_overflow_dont, /* complain_on_overflow */
1453 bfd_elf_generic_reloc, /* special_function */
1454 AARCH64_R_STR (TLSDESC_LDR), /* name */
1455 FALSE, /* partial_inplace */
1458 FALSE), /* pcrel_offset */
1460 HOWTO64 (AARCH64_R (TLSDESC_ADD), /* type */
1462 2, /* size (0 = byte, 1 = short, 2 = long) */
1464 FALSE, /* pc_relative */
1466 complain_overflow_dont, /* complain_on_overflow */
1467 bfd_elf_generic_reloc, /* special_function */
1468 AARCH64_R_STR (TLSDESC_ADD), /* name */
1469 FALSE, /* partial_inplace */
1472 FALSE), /* pcrel_offset */
1474 HOWTO (AARCH64_R (TLSDESC_CALL), /* type */
1476 2, /* size (0 = byte, 1 = short, 2 = long) */
1478 FALSE, /* pc_relative */
1480 complain_overflow_dont, /* complain_on_overflow */
1481 bfd_elf_generic_reloc, /* special_function */
1482 AARCH64_R_STR (TLSDESC_CALL), /* name */
1483 FALSE, /* partial_inplace */
1486 FALSE), /* pcrel_offset */
1488 HOWTO (AARCH64_R (COPY), /* type */
1490 2, /* size (0 = byte, 1 = short, 2 = long) */
1492 FALSE, /* pc_relative */
1494 complain_overflow_bitfield, /* complain_on_overflow */
1495 bfd_elf_generic_reloc, /* special_function */
1496 AARCH64_R_STR (COPY), /* name */
1497 TRUE, /* partial_inplace */
1498 0xffffffff, /* src_mask */
1499 0xffffffff, /* dst_mask */
1500 FALSE), /* pcrel_offset */
1502 HOWTO (AARCH64_R (GLOB_DAT), /* type */
1504 2, /* size (0 = byte, 1 = short, 2 = long) */
1506 FALSE, /* pc_relative */
1508 complain_overflow_bitfield, /* complain_on_overflow */
1509 bfd_elf_generic_reloc, /* special_function */
1510 AARCH64_R_STR (GLOB_DAT), /* name */
1511 TRUE, /* partial_inplace */
1512 0xffffffff, /* src_mask */
1513 0xffffffff, /* dst_mask */
1514 FALSE), /* pcrel_offset */
1516 HOWTO (AARCH64_R (JUMP_SLOT), /* type */
1518 2, /* size (0 = byte, 1 = short, 2 = long) */
1520 FALSE, /* pc_relative */
1522 complain_overflow_bitfield, /* complain_on_overflow */
1523 bfd_elf_generic_reloc, /* special_function */
1524 AARCH64_R_STR (JUMP_SLOT), /* name */
1525 TRUE, /* partial_inplace */
1526 0xffffffff, /* src_mask */
1527 0xffffffff, /* dst_mask */
1528 FALSE), /* pcrel_offset */
1530 HOWTO (AARCH64_R (RELATIVE), /* type */
1532 2, /* size (0 = byte, 1 = short, 2 = long) */
1534 FALSE, /* pc_relative */
1536 complain_overflow_bitfield, /* complain_on_overflow */
1537 bfd_elf_generic_reloc, /* special_function */
1538 AARCH64_R_STR (RELATIVE), /* name */
1539 TRUE, /* partial_inplace */
1540 ALL_ONES, /* src_mask */
1541 ALL_ONES, /* dst_mask */
1542 FALSE), /* pcrel_offset */
1544 HOWTO (AARCH64_R (TLS_DTPMOD), /* type */
1546 2, /* size (0 = byte, 1 = short, 2 = long) */
1548 FALSE, /* pc_relative */
1550 complain_overflow_dont, /* complain_on_overflow */
1551 bfd_elf_generic_reloc, /* special_function */
1553 AARCH64_R_STR (TLS_DTPMOD64), /* name */
1555 AARCH64_R_STR (TLS_DTPMOD), /* name */
1557 FALSE, /* partial_inplace */
1559 ALL_ONES, /* dst_mask */
1560 FALSE), /* pc_reloffset */
1562 HOWTO (AARCH64_R (TLS_DTPREL), /* type */
1564 2, /* size (0 = byte, 1 = short, 2 = long) */
1566 FALSE, /* pc_relative */
1568 complain_overflow_dont, /* complain_on_overflow */
1569 bfd_elf_generic_reloc, /* special_function */
1571 AARCH64_R_STR (TLS_DTPREL64), /* name */
1573 AARCH64_R_STR (TLS_DTPREL), /* name */
1575 FALSE, /* partial_inplace */
1577 ALL_ONES, /* dst_mask */
1578 FALSE), /* pcrel_offset */
1580 HOWTO (AARCH64_R (TLS_TPREL), /* type */
1582 2, /* size (0 = byte, 1 = short, 2 = long) */
1584 FALSE, /* pc_relative */
1586 complain_overflow_dont, /* complain_on_overflow */
1587 bfd_elf_generic_reloc, /* special_function */
1589 AARCH64_R_STR (TLS_TPREL64), /* name */
1591 AARCH64_R_STR (TLS_TPREL), /* name */
1593 FALSE, /* partial_inplace */
1595 ALL_ONES, /* dst_mask */
1596 FALSE), /* pcrel_offset */
1598 HOWTO (AARCH64_R (TLSDESC), /* type */
1600 2, /* size (0 = byte, 1 = short, 2 = long) */
1602 FALSE, /* pc_relative */
1604 complain_overflow_dont, /* complain_on_overflow */
1605 bfd_elf_generic_reloc, /* special_function */
1606 AARCH64_R_STR (TLSDESC), /* name */
1607 FALSE, /* partial_inplace */
1609 ALL_ONES, /* dst_mask */
1610 FALSE), /* pcrel_offset */
1612 HOWTO (AARCH64_R (IRELATIVE), /* type */
1614 2, /* size (0 = byte, 1 = short, 2 = long) */
1616 FALSE, /* pc_relative */
1618 complain_overflow_bitfield, /* complain_on_overflow */
1619 bfd_elf_generic_reloc, /* special_function */
1620 AARCH64_R_STR (IRELATIVE), /* name */
1621 FALSE, /* partial_inplace */
1623 ALL_ONES, /* dst_mask */
1624 FALSE), /* pcrel_offset */
1629 static reloc_howto_type elfNN_aarch64_howto_none =
1630 HOWTO (R_AARCH64_NONE, /* type */
1632 3, /* size (0 = byte, 1 = short, 2 = long) */
1634 FALSE, /* pc_relative */
1636 complain_overflow_dont,/* complain_on_overflow */
1637 bfd_elf_generic_reloc, /* special_function */
1638 "R_AARCH64_NONE", /* name */
1639 FALSE, /* partial_inplace */
1642 FALSE); /* pcrel_offset */
1644 /* Given HOWTO, return the bfd internal relocation enumerator. */
1646 static bfd_reloc_code_real_type
1647 elfNN_aarch64_bfd_reloc_from_howto (reloc_howto_type *howto)
1650 = (int) ARRAY_SIZE (elfNN_aarch64_howto_table);
1651 const ptrdiff_t offset
1652 = howto - elfNN_aarch64_howto_table;
1654 if (offset > 0 && offset < size - 1)
1655 return BFD_RELOC_AARCH64_RELOC_START + offset;
1657 if (howto == &elfNN_aarch64_howto_none)
1658 return BFD_RELOC_AARCH64_NONE;
1660 return BFD_RELOC_AARCH64_RELOC_START;
1663 /* Given R_TYPE, return the bfd internal relocation enumerator. */
1665 static bfd_reloc_code_real_type
1666 elfNN_aarch64_bfd_reloc_from_type (unsigned int r_type)
1668 static bfd_boolean initialized_p = FALSE;
1669 /* Indexed by R_TYPE, values are offsets in the howto_table. */
1670 static unsigned int offsets[R_AARCH64_end];
1672 if (initialized_p == FALSE)
1676 for (i = 1; i < ARRAY_SIZE (elfNN_aarch64_howto_table) - 1; ++i)
1677 if (elfNN_aarch64_howto_table[i].type != 0)
1678 offsets[elfNN_aarch64_howto_table[i].type] = i;
1680 initialized_p = TRUE;
1683 if (r_type == R_AARCH64_NONE || r_type == R_AARCH64_NULL)
1684 return BFD_RELOC_AARCH64_NONE;
1686 /* PR 17512: file: b371e70a. */
1687 if (r_type >= R_AARCH64_end)
1689 _bfd_error_handler (_("Invalid AArch64 reloc number: %d"), r_type);
1690 bfd_set_error (bfd_error_bad_value);
1691 return BFD_RELOC_AARCH64_NONE;
1694 return BFD_RELOC_AARCH64_RELOC_START + offsets[r_type];
1697 struct elf_aarch64_reloc_map
1699 bfd_reloc_code_real_type from;
1700 bfd_reloc_code_real_type to;
1703 /* Map bfd generic reloc to AArch64-specific reloc. */
1704 static const struct elf_aarch64_reloc_map elf_aarch64_reloc_map[] =
1706 {BFD_RELOC_NONE, BFD_RELOC_AARCH64_NONE},
1708 /* Basic data relocations. */
1709 {BFD_RELOC_CTOR, BFD_RELOC_AARCH64_NN},
1710 {BFD_RELOC_64, BFD_RELOC_AARCH64_64},
1711 {BFD_RELOC_32, BFD_RELOC_AARCH64_32},
1712 {BFD_RELOC_16, BFD_RELOC_AARCH64_16},
1713 {BFD_RELOC_64_PCREL, BFD_RELOC_AARCH64_64_PCREL},
1714 {BFD_RELOC_32_PCREL, BFD_RELOC_AARCH64_32_PCREL},
1715 {BFD_RELOC_16_PCREL, BFD_RELOC_AARCH64_16_PCREL},
1718 /* Given the bfd internal relocation enumerator in CODE, return the
1719 corresponding howto entry. */
1721 static reloc_howto_type *
1722 elfNN_aarch64_howto_from_bfd_reloc (bfd_reloc_code_real_type code)
1726 /* Convert bfd generic reloc to AArch64-specific reloc. */
1727 if (code < BFD_RELOC_AARCH64_RELOC_START
1728 || code > BFD_RELOC_AARCH64_RELOC_END)
1729 for (i = 0; i < ARRAY_SIZE (elf_aarch64_reloc_map); i++)
1730 if (elf_aarch64_reloc_map[i].from == code)
1732 code = elf_aarch64_reloc_map[i].to;
1736 if (code > BFD_RELOC_AARCH64_RELOC_START
1737 && code < BFD_RELOC_AARCH64_RELOC_END)
1738 if (elfNN_aarch64_howto_table[code - BFD_RELOC_AARCH64_RELOC_START].type)
1739 return &elfNN_aarch64_howto_table[code - BFD_RELOC_AARCH64_RELOC_START];
1741 if (code == BFD_RELOC_AARCH64_NONE)
1742 return &elfNN_aarch64_howto_none;
1747 static reloc_howto_type *
1748 elfNN_aarch64_howto_from_type (unsigned int r_type)
1750 bfd_reloc_code_real_type val;
1751 reloc_howto_type *howto;
1756 bfd_set_error (bfd_error_bad_value);
1761 if (r_type == R_AARCH64_NONE)
1762 return &elfNN_aarch64_howto_none;
1764 val = elfNN_aarch64_bfd_reloc_from_type (r_type);
1765 howto = elfNN_aarch64_howto_from_bfd_reloc (val);
1770 bfd_set_error (bfd_error_bad_value);
1775 elfNN_aarch64_info_to_howto (bfd *abfd ATTRIBUTE_UNUSED, arelent *bfd_reloc,
1776 Elf_Internal_Rela *elf_reloc)
1778 unsigned int r_type;
1780 r_type = ELFNN_R_TYPE (elf_reloc->r_info);
1781 bfd_reloc->howto = elfNN_aarch64_howto_from_type (r_type);
1784 static reloc_howto_type *
1785 elfNN_aarch64_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED,
1786 bfd_reloc_code_real_type code)
1788 reloc_howto_type *howto = elfNN_aarch64_howto_from_bfd_reloc (code);
1793 bfd_set_error (bfd_error_bad_value);
1797 static reloc_howto_type *
1798 elfNN_aarch64_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED,
1803 for (i = 1; i < ARRAY_SIZE (elfNN_aarch64_howto_table) - 1; ++i)
1804 if (elfNN_aarch64_howto_table[i].name != NULL
1805 && strcasecmp (elfNN_aarch64_howto_table[i].name, r_name) == 0)
1806 return &elfNN_aarch64_howto_table[i];
1811 #define TARGET_LITTLE_SYM aarch64_elfNN_le_vec
1812 #define TARGET_LITTLE_NAME "elfNN-littleaarch64"
1813 #define TARGET_BIG_SYM aarch64_elfNN_be_vec
1814 #define TARGET_BIG_NAME "elfNN-bigaarch64"
1816 /* The linker script knows the section names for placement.
1817 The entry_names are used to do simple name mangling on the stubs.
1818 Given a function name, and its type, the stub can be found. The
1819 name can be changed. The only requirement is the %s be present. */
1820 #define STUB_ENTRY_NAME "__%s_veneer"
1822 /* The name of the dynamic interpreter. This is put in the .interp
1824 #define ELF_DYNAMIC_INTERPRETER "/lib/ld.so.1"
1826 #define AARCH64_MAX_FWD_BRANCH_OFFSET \
1827 (((1 << 25) - 1) << 2)
1828 #define AARCH64_MAX_BWD_BRANCH_OFFSET \
1831 #define AARCH64_MAX_ADRP_IMM ((1 << 20) - 1)
1832 #define AARCH64_MIN_ADRP_IMM (-(1 << 20))
1835 aarch64_valid_for_adrp_p (bfd_vma value, bfd_vma place)
1837 bfd_signed_vma offset = (bfd_signed_vma) (PG (value) - PG (place)) >> 12;
1838 return offset <= AARCH64_MAX_ADRP_IMM && offset >= AARCH64_MIN_ADRP_IMM;
1842 aarch64_valid_branch_p (bfd_vma value, bfd_vma place)
1844 bfd_signed_vma offset = (bfd_signed_vma) (value - place);
1845 return (offset <= AARCH64_MAX_FWD_BRANCH_OFFSET
1846 && offset >= AARCH64_MAX_BWD_BRANCH_OFFSET);
1849 static const uint32_t aarch64_adrp_branch_stub [] =
1851 0x90000010, /* adrp ip0, X */
1852 /* R_AARCH64_ADR_HI21_PCREL(X) */
1853 0x91000210, /* add ip0, ip0, :lo12:X */
1854 /* R_AARCH64_ADD_ABS_LO12_NC(X) */
1855 0xd61f0200, /* br ip0 */
1858 static const uint32_t aarch64_long_branch_stub[] =
1861 0x58000090, /* ldr ip0, 1f */
1863 0x18000090, /* ldr wip0, 1f */
1865 0x10000011, /* adr ip1, #0 */
1866 0x8b110210, /* add ip0, ip0, ip1 */
1867 0xd61f0200, /* br ip0 */
1868 0x00000000, /* 1: .xword or .word
1869 R_AARCH64_PRELNN(X) + 12
1874 static const uint32_t aarch64_erratum_835769_stub[] =
1876 0x00000000, /* Placeholder for multiply accumulate. */
1877 0x14000000, /* b <label> */
1880 static const uint32_t aarch64_erratum_843419_stub[] =
1882 0x00000000, /* Placeholder for LDR instruction. */
1883 0x14000000, /* b <label> */
1886 /* Section name for stubs is the associated section name plus this
1888 #define STUB_SUFFIX ".stub"
1890 enum elf_aarch64_stub_type
1893 aarch64_stub_adrp_branch,
1894 aarch64_stub_long_branch,
1895 aarch64_stub_erratum_835769_veneer,
1896 aarch64_stub_erratum_843419_veneer,
1899 struct elf_aarch64_stub_hash_entry
1901 /* Base hash table entry structure. */
1902 struct bfd_hash_entry root;
1904 /* The stub section. */
1907 /* Offset within stub_sec of the beginning of this stub. */
1908 bfd_vma stub_offset;
1910 /* Given the symbol's value and its section we can determine its final
1911 value when building the stubs (so the stub knows where to jump). */
1912 bfd_vma target_value;
1913 asection *target_section;
1915 enum elf_aarch64_stub_type stub_type;
1917 /* The symbol table entry, if any, that this was derived from. */
1918 struct elf_aarch64_link_hash_entry *h;
1920 /* Destination symbol type */
1921 unsigned char st_type;
1923 /* Where this stub is being called from, or, in the case of combined
1924 stub sections, the first input section in the group. */
1927 /* The name for the local symbol at the start of this stub. The
1928 stub name in the hash table has to be unique; this does not, so
1929 it can be friendlier. */
1932 /* The instruction which caused this stub to be generated (only valid for
1933 erratum 835769 workaround stubs at present). */
1934 uint32_t veneered_insn;
1936 /* In an erratum 843419 workaround stub, the ADRP instruction offset. */
1937 bfd_vma adrp_offset;
1940 /* Used to build a map of a section. This is required for mixed-endian
1943 typedef struct elf_elf_section_map
1948 elf_aarch64_section_map;
1951 typedef struct _aarch64_elf_section_data
1953 struct bfd_elf_section_data elf;
1954 unsigned int mapcount;
1955 unsigned int mapsize;
1956 elf_aarch64_section_map *map;
1958 _aarch64_elf_section_data;
1960 #define elf_aarch64_section_data(sec) \
1961 ((_aarch64_elf_section_data *) elf_section_data (sec))
1963 /* The size of the thread control block which is defined to be two pointers. */
1964 #define TCB_SIZE (ARCH_SIZE/8)*2
1966 struct elf_aarch64_local_symbol
1968 unsigned int got_type;
1969 bfd_signed_vma got_refcount;
1972 /* Offset of the GOTPLT entry reserved for the TLS descriptor. The
1973 offset is from the end of the jump table and reserved entries
1976 The magic value (bfd_vma) -1 indicates that an offset has not be
1978 bfd_vma tlsdesc_got_jump_table_offset;
1981 struct elf_aarch64_obj_tdata
1983 struct elf_obj_tdata root;
1985 /* local symbol descriptors */
1986 struct elf_aarch64_local_symbol *locals;
1988 /* Zero to warn when linking objects with incompatible enum sizes. */
1989 int no_enum_size_warning;
1991 /* Zero to warn when linking objects with incompatible wchar_t sizes. */
1992 int no_wchar_size_warning;
1995 #define elf_aarch64_tdata(bfd) \
1996 ((struct elf_aarch64_obj_tdata *) (bfd)->tdata.any)
1998 #define elf_aarch64_locals(bfd) (elf_aarch64_tdata (bfd)->locals)
2000 #define is_aarch64_elf(bfd) \
2001 (bfd_get_flavour (bfd) == bfd_target_elf_flavour \
2002 && elf_tdata (bfd) != NULL \
2003 && elf_object_id (bfd) == AARCH64_ELF_DATA)
2006 elfNN_aarch64_mkobject (bfd *abfd)
2008 return bfd_elf_allocate_object (abfd, sizeof (struct elf_aarch64_obj_tdata),
2012 #define elf_aarch64_hash_entry(ent) \
2013 ((struct elf_aarch64_link_hash_entry *)(ent))
2015 #define GOT_UNKNOWN 0
2016 #define GOT_NORMAL 1
2017 #define GOT_TLS_GD 2
2018 #define GOT_TLS_IE 4
2019 #define GOT_TLSDESC_GD 8
2021 #define GOT_TLS_GD_ANY_P(type) ((type & GOT_TLS_GD) || (type & GOT_TLSDESC_GD))
2023 /* AArch64 ELF linker hash entry. */
2024 struct elf_aarch64_link_hash_entry
2026 struct elf_link_hash_entry root;
2028 /* Track dynamic relocs copied for this symbol. */
2029 struct elf_dyn_relocs *dyn_relocs;
2031 /* Since PLT entries have variable size, we need to record the
2032 index into .got.plt instead of recomputing it from the PLT
2034 bfd_signed_vma plt_got_offset;
2036 /* Bit mask representing the type of GOT entry(s) if any required by
2038 unsigned int got_type;
2040 /* A pointer to the most recently used stub hash entry against this
2042 struct elf_aarch64_stub_hash_entry *stub_cache;
2044 /* Offset of the GOTPLT entry reserved for the TLS descriptor. The offset
2045 is from the end of the jump table and reserved entries within the PLTGOT.
2047 The magic value (bfd_vma) -1 indicates that an offset has not
2049 bfd_vma tlsdesc_got_jump_table_offset;
2053 elfNN_aarch64_symbol_got_type (struct elf_link_hash_entry *h,
2055 unsigned long r_symndx)
2058 return elf_aarch64_hash_entry (h)->got_type;
2060 if (! elf_aarch64_locals (abfd))
2063 return elf_aarch64_locals (abfd)[r_symndx].got_type;
2066 /* Get the AArch64 elf linker hash table from a link_info structure. */
2067 #define elf_aarch64_hash_table(info) \
2068 ((struct elf_aarch64_link_hash_table *) ((info)->hash))
2070 #define aarch64_stub_hash_lookup(table, string, create, copy) \
2071 ((struct elf_aarch64_stub_hash_entry *) \
2072 bfd_hash_lookup ((table), (string), (create), (copy)))
2074 /* AArch64 ELF linker hash table. */
2075 struct elf_aarch64_link_hash_table
2077 /* The main hash table. */
2078 struct elf_link_hash_table root;
2080 /* Nonzero to force PIC branch veneers. */
2083 /* Fix erratum 835769. */
2084 int fix_erratum_835769;
2086 /* Fix erratum 843419. */
2087 int fix_erratum_843419;
2089 /* Enable ADRP->ADR rewrite for erratum 843419 workaround. */
2090 int fix_erratum_843419_adr;
2092 /* The number of bytes in the initial entry in the PLT. */
2093 bfd_size_type plt_header_size;
2095 /* The number of bytes in the subsequent PLT etries. */
2096 bfd_size_type plt_entry_size;
2098 /* Short-cuts to get to dynamic linker sections. */
2102 /* Small local sym cache. */
2103 struct sym_cache sym_cache;
2105 /* For convenience in allocate_dynrelocs. */
2108 /* The amount of space used by the reserved portion of the sgotplt
2109 section, plus whatever space is used by the jump slots. */
2110 bfd_vma sgotplt_jump_table_size;
2112 /* The stub hash table. */
2113 struct bfd_hash_table stub_hash_table;
2115 /* Linker stub bfd. */
2118 /* Linker call-backs. */
2119 asection *(*add_stub_section) (const char *, asection *);
2120 void (*layout_sections_again) (void);
2122 /* Array to keep track of which stub sections have been created, and
2123 information on stub grouping. */
2126 /* This is the section to which stubs in the group will be
2129 /* The stub section. */
2133 /* Assorted information used by elfNN_aarch64_size_stubs. */
2134 unsigned int bfd_count;
2136 asection **input_list;
2138 /* The offset into splt of the PLT entry for the TLS descriptor
2139 resolver. Special values are 0, if not necessary (or not found
2140 to be necessary yet), and -1 if needed but not determined
2142 bfd_vma tlsdesc_plt;
2144 /* The GOT offset for the lazy trampoline. Communicated to the
2145 loader via DT_TLSDESC_GOT. The magic value (bfd_vma) -1
2146 indicates an offset is not allocated. */
2147 bfd_vma dt_tlsdesc_got;
2149 /* Used by local STT_GNU_IFUNC symbols. */
2150 htab_t loc_hash_table;
2151 void * loc_hash_memory;
2154 /* Create an entry in an AArch64 ELF linker hash table. */
2156 static struct bfd_hash_entry *
2157 elfNN_aarch64_link_hash_newfunc (struct bfd_hash_entry *entry,
2158 struct bfd_hash_table *table,
2161 struct elf_aarch64_link_hash_entry *ret =
2162 (struct elf_aarch64_link_hash_entry *) entry;
2164 /* Allocate the structure if it has not already been allocated by a
2167 ret = bfd_hash_allocate (table,
2168 sizeof (struct elf_aarch64_link_hash_entry));
2170 return (struct bfd_hash_entry *) ret;
2172 /* Call the allocation method of the superclass. */
2173 ret = ((struct elf_aarch64_link_hash_entry *)
2174 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry *) ret,
2178 ret->dyn_relocs = NULL;
2179 ret->got_type = GOT_UNKNOWN;
2180 ret->plt_got_offset = (bfd_vma) - 1;
2181 ret->stub_cache = NULL;
2182 ret->tlsdesc_got_jump_table_offset = (bfd_vma) - 1;
2185 return (struct bfd_hash_entry *) ret;
2188 /* Initialize an entry in the stub hash table. */
2190 static struct bfd_hash_entry *
2191 stub_hash_newfunc (struct bfd_hash_entry *entry,
2192 struct bfd_hash_table *table, const char *string)
2194 /* Allocate the structure if it has not already been allocated by a
2198 entry = bfd_hash_allocate (table,
2200 elf_aarch64_stub_hash_entry));
2205 /* Call the allocation method of the superclass. */
2206 entry = bfd_hash_newfunc (entry, table, string);
2209 struct elf_aarch64_stub_hash_entry *eh;
2211 /* Initialize the local fields. */
2212 eh = (struct elf_aarch64_stub_hash_entry *) entry;
2213 eh->adrp_offset = 0;
2214 eh->stub_sec = NULL;
2215 eh->stub_offset = 0;
2216 eh->target_value = 0;
2217 eh->target_section = NULL;
2218 eh->stub_type = aarch64_stub_none;
2226 /* Compute a hash of a local hash entry. We use elf_link_hash_entry
2227 for local symbol so that we can handle local STT_GNU_IFUNC symbols
2228 as global symbol. We reuse indx and dynstr_index for local symbol
2229 hash since they aren't used by global symbols in this backend. */
2232 elfNN_aarch64_local_htab_hash (const void *ptr)
2234 struct elf_link_hash_entry *h
2235 = (struct elf_link_hash_entry *) ptr;
2236 return ELF_LOCAL_SYMBOL_HASH (h->indx, h->dynstr_index);
2239 /* Compare local hash entries. */
2242 elfNN_aarch64_local_htab_eq (const void *ptr1, const void *ptr2)
2244 struct elf_link_hash_entry *h1
2245 = (struct elf_link_hash_entry *) ptr1;
2246 struct elf_link_hash_entry *h2
2247 = (struct elf_link_hash_entry *) ptr2;
2249 return h1->indx == h2->indx && h1->dynstr_index == h2->dynstr_index;
2252 /* Find and/or create a hash entry for local symbol. */
2254 static struct elf_link_hash_entry *
2255 elfNN_aarch64_get_local_sym_hash (struct elf_aarch64_link_hash_table *htab,
2256 bfd *abfd, const Elf_Internal_Rela *rel,
2259 struct elf_aarch64_link_hash_entry e, *ret;
2260 asection *sec = abfd->sections;
2261 hashval_t h = ELF_LOCAL_SYMBOL_HASH (sec->id,
2262 ELFNN_R_SYM (rel->r_info));
2265 e.root.indx = sec->id;
2266 e.root.dynstr_index = ELFNN_R_SYM (rel->r_info);
2267 slot = htab_find_slot_with_hash (htab->loc_hash_table, &e, h,
2268 create ? INSERT : NO_INSERT);
2275 ret = (struct elf_aarch64_link_hash_entry *) *slot;
2279 ret = (struct elf_aarch64_link_hash_entry *)
2280 objalloc_alloc ((struct objalloc *) htab->loc_hash_memory,
2281 sizeof (struct elf_aarch64_link_hash_entry));
2284 memset (ret, 0, sizeof (*ret));
2285 ret->root.indx = sec->id;
2286 ret->root.dynstr_index = ELFNN_R_SYM (rel->r_info);
2287 ret->root.dynindx = -1;
2293 /* Copy the extra info we tack onto an elf_link_hash_entry. */
2296 elfNN_aarch64_copy_indirect_symbol (struct bfd_link_info *info,
2297 struct elf_link_hash_entry *dir,
2298 struct elf_link_hash_entry *ind)
2300 struct elf_aarch64_link_hash_entry *edir, *eind;
2302 edir = (struct elf_aarch64_link_hash_entry *) dir;
2303 eind = (struct elf_aarch64_link_hash_entry *) ind;
2305 if (eind->dyn_relocs != NULL)
2307 if (edir->dyn_relocs != NULL)
2309 struct elf_dyn_relocs **pp;
2310 struct elf_dyn_relocs *p;
2312 /* Add reloc counts against the indirect sym to the direct sym
2313 list. Merge any entries against the same section. */
2314 for (pp = &eind->dyn_relocs; (p = *pp) != NULL;)
2316 struct elf_dyn_relocs *q;
2318 for (q = edir->dyn_relocs; q != NULL; q = q->next)
2319 if (q->sec == p->sec)
2321 q->pc_count += p->pc_count;
2322 q->count += p->count;
2329 *pp = edir->dyn_relocs;
2332 edir->dyn_relocs = eind->dyn_relocs;
2333 eind->dyn_relocs = NULL;
2336 if (ind->root.type == bfd_link_hash_indirect)
2338 /* Copy over PLT info. */
2339 if (dir->got.refcount <= 0)
2341 edir->got_type = eind->got_type;
2342 eind->got_type = GOT_UNKNOWN;
2346 _bfd_elf_link_hash_copy_indirect (info, dir, ind);
2349 /* Destroy an AArch64 elf linker hash table. */
2352 elfNN_aarch64_link_hash_table_free (bfd *obfd)
2354 struct elf_aarch64_link_hash_table *ret
2355 = (struct elf_aarch64_link_hash_table *) obfd->link.hash;
2357 if (ret->loc_hash_table)
2358 htab_delete (ret->loc_hash_table);
2359 if (ret->loc_hash_memory)
2360 objalloc_free ((struct objalloc *) ret->loc_hash_memory);
2362 bfd_hash_table_free (&ret->stub_hash_table);
2363 _bfd_elf_link_hash_table_free (obfd);
2366 /* Create an AArch64 elf linker hash table. */
2368 static struct bfd_link_hash_table *
2369 elfNN_aarch64_link_hash_table_create (bfd *abfd)
2371 struct elf_aarch64_link_hash_table *ret;
2372 bfd_size_type amt = sizeof (struct elf_aarch64_link_hash_table);
2374 ret = bfd_zmalloc (amt);
2378 if (!_bfd_elf_link_hash_table_init
2379 (&ret->root, abfd, elfNN_aarch64_link_hash_newfunc,
2380 sizeof (struct elf_aarch64_link_hash_entry), AARCH64_ELF_DATA))
2386 ret->plt_header_size = PLT_ENTRY_SIZE;
2387 ret->plt_entry_size = PLT_SMALL_ENTRY_SIZE;
2389 ret->dt_tlsdesc_got = (bfd_vma) - 1;
2391 if (!bfd_hash_table_init (&ret->stub_hash_table, stub_hash_newfunc,
2392 sizeof (struct elf_aarch64_stub_hash_entry)))
2394 _bfd_elf_link_hash_table_free (abfd);
2398 ret->loc_hash_table = htab_try_create (1024,
2399 elfNN_aarch64_local_htab_hash,
2400 elfNN_aarch64_local_htab_eq,
2402 ret->loc_hash_memory = objalloc_create ();
2403 if (!ret->loc_hash_table || !ret->loc_hash_memory)
2405 elfNN_aarch64_link_hash_table_free (abfd);
2408 ret->root.root.hash_table_free = elfNN_aarch64_link_hash_table_free;
2410 return &ret->root.root;
2414 aarch64_relocate (unsigned int r_type, bfd *input_bfd, asection *input_section,
2415 bfd_vma offset, bfd_vma value)
2417 reloc_howto_type *howto;
2420 howto = elfNN_aarch64_howto_from_type (r_type);
2421 place = (input_section->output_section->vma + input_section->output_offset
2424 r_type = elfNN_aarch64_bfd_reloc_from_type (r_type);
2425 value = _bfd_aarch64_elf_resolve_relocation (r_type, place, value, 0, FALSE);
2426 return _bfd_aarch64_elf_put_addend (input_bfd,
2427 input_section->contents + offset, r_type,
2431 static enum elf_aarch64_stub_type
2432 aarch64_select_branch_stub (bfd_vma value, bfd_vma place)
2434 if (aarch64_valid_for_adrp_p (value, place))
2435 return aarch64_stub_adrp_branch;
2436 return aarch64_stub_long_branch;
2439 /* Determine the type of stub needed, if any, for a call. */
2441 static enum elf_aarch64_stub_type
2442 aarch64_type_of_stub (struct bfd_link_info *info,
2443 asection *input_sec,
2444 const Elf_Internal_Rela *rel,
2446 unsigned char st_type,
2447 struct elf_aarch64_link_hash_entry *hash,
2448 bfd_vma destination)
2451 bfd_signed_vma branch_offset;
2452 unsigned int r_type;
2453 struct elf_aarch64_link_hash_table *globals;
2454 enum elf_aarch64_stub_type stub_type = aarch64_stub_none;
2455 bfd_boolean via_plt_p;
2457 if (st_type != STT_FUNC
2458 && (sym_sec != bfd_abs_section_ptr))
2461 globals = elf_aarch64_hash_table (info);
2462 via_plt_p = (globals->root.splt != NULL && hash != NULL
2463 && hash->root.plt.offset != (bfd_vma) - 1);
2464 /* Make sure call to plt stub can fit into the branch range. */
2466 destination = (globals->root.splt->output_section->vma
2467 + globals->root.splt->output_offset
2468 + hash->root.plt.offset);
2470 /* Determine where the call point is. */
2471 location = (input_sec->output_offset
2472 + input_sec->output_section->vma + rel->r_offset);
2474 branch_offset = (bfd_signed_vma) (destination - location);
2476 r_type = ELFNN_R_TYPE (rel->r_info);
2478 /* We don't want to redirect any old unconditional jump in this way,
2479 only one which is being used for a sibcall, where it is
2480 acceptable for the IP0 and IP1 registers to be clobbered. */
2481 if ((r_type == AARCH64_R (CALL26) || r_type == AARCH64_R (JUMP26))
2482 && (branch_offset > AARCH64_MAX_FWD_BRANCH_OFFSET
2483 || branch_offset < AARCH64_MAX_BWD_BRANCH_OFFSET))
2485 stub_type = aarch64_stub_long_branch;
2491 /* Build a name for an entry in the stub hash table. */
2494 elfNN_aarch64_stub_name (const asection *input_section,
2495 const asection *sym_sec,
2496 const struct elf_aarch64_link_hash_entry *hash,
2497 const Elf_Internal_Rela *rel)
2504 len = 8 + 1 + strlen (hash->root.root.root.string) + 1 + 16 + 1;
2505 stub_name = bfd_malloc (len);
2506 if (stub_name != NULL)
2507 snprintf (stub_name, len, "%08x_%s+%" BFD_VMA_FMT "x",
2508 (unsigned int) input_section->id,
2509 hash->root.root.root.string,
2514 len = 8 + 1 + 8 + 1 + 8 + 1 + 16 + 1;
2515 stub_name = bfd_malloc (len);
2516 if (stub_name != NULL)
2517 snprintf (stub_name, len, "%08x_%x:%x+%" BFD_VMA_FMT "x",
2518 (unsigned int) input_section->id,
2519 (unsigned int) sym_sec->id,
2520 (unsigned int) ELFNN_R_SYM (rel->r_info),
2527 /* Look up an entry in the stub hash. Stub entries are cached because
2528 creating the stub name takes a bit of time. */
2530 static struct elf_aarch64_stub_hash_entry *
2531 elfNN_aarch64_get_stub_entry (const asection *input_section,
2532 const asection *sym_sec,
2533 struct elf_link_hash_entry *hash,
2534 const Elf_Internal_Rela *rel,
2535 struct elf_aarch64_link_hash_table *htab)
2537 struct elf_aarch64_stub_hash_entry *stub_entry;
2538 struct elf_aarch64_link_hash_entry *h =
2539 (struct elf_aarch64_link_hash_entry *) hash;
2540 const asection *id_sec;
2542 if ((input_section->flags & SEC_CODE) == 0)
2545 /* If this input section is part of a group of sections sharing one
2546 stub section, then use the id of the first section in the group.
2547 Stub names need to include a section id, as there may well be
2548 more than one stub used to reach say, printf, and we need to
2549 distinguish between them. */
2550 id_sec = htab->stub_group[input_section->id].link_sec;
2552 if (h != NULL && h->stub_cache != NULL
2553 && h->stub_cache->h == h && h->stub_cache->id_sec == id_sec)
2555 stub_entry = h->stub_cache;
2561 stub_name = elfNN_aarch64_stub_name (id_sec, sym_sec, h, rel);
2562 if (stub_name == NULL)
2565 stub_entry = aarch64_stub_hash_lookup (&htab->stub_hash_table,
2566 stub_name, FALSE, FALSE);
2568 h->stub_cache = stub_entry;
2577 /* Create a stub section. */
2580 _bfd_aarch64_create_stub_section (asection *section,
2581 struct elf_aarch64_link_hash_table *htab)
2587 namelen = strlen (section->name);
2588 len = namelen + sizeof (STUB_SUFFIX);
2589 s_name = bfd_alloc (htab->stub_bfd, len);
2593 memcpy (s_name, section->name, namelen);
2594 memcpy (s_name + namelen, STUB_SUFFIX, sizeof (STUB_SUFFIX));
2595 return (*htab->add_stub_section) (s_name, section);
2599 /* Find or create a stub section for a link section.
2601 Fix or create the stub section used to collect stubs attached to
2602 the specified link section. */
2605 _bfd_aarch64_get_stub_for_link_section (asection *link_section,
2606 struct elf_aarch64_link_hash_table *htab)
2608 if (htab->stub_group[link_section->id].stub_sec == NULL)
2609 htab->stub_group[link_section->id].stub_sec
2610 = _bfd_aarch64_create_stub_section (link_section, htab);
2611 return htab->stub_group[link_section->id].stub_sec;
2615 /* Find or create a stub section in the stub group for an input
2619 _bfd_aarch64_create_or_find_stub_sec (asection *section,
2620 struct elf_aarch64_link_hash_table *htab)
2622 asection *link_sec = htab->stub_group[section->id].link_sec;
2623 return _bfd_aarch64_get_stub_for_link_section (link_sec, htab);
2627 /* Add a new stub entry in the stub group associated with an input
2628 section to the stub hash. Not all fields of the new stub entry are
2631 static struct elf_aarch64_stub_hash_entry *
2632 _bfd_aarch64_add_stub_entry_in_group (const char *stub_name,
2634 struct elf_aarch64_link_hash_table *htab)
2638 struct elf_aarch64_stub_hash_entry *stub_entry;
2640 link_sec = htab->stub_group[section->id].link_sec;
2641 stub_sec = _bfd_aarch64_create_or_find_stub_sec (section, htab);
2643 /* Enter this entry into the linker stub hash table. */
2644 stub_entry = aarch64_stub_hash_lookup (&htab->stub_hash_table, stub_name,
2646 if (stub_entry == NULL)
2648 (*_bfd_error_handler) (_("%s: cannot create stub entry %s"),
2649 section->owner, stub_name);
2653 stub_entry->stub_sec = stub_sec;
2654 stub_entry->stub_offset = 0;
2655 stub_entry->id_sec = link_sec;
2660 /* Add a new stub entry in the final stub section to the stub hash.
2661 Not all fields of the new stub entry are initialised. */
2663 static struct elf_aarch64_stub_hash_entry *
2664 _bfd_aarch64_add_stub_entry_after (const char *stub_name,
2665 asection *link_section,
2666 struct elf_aarch64_link_hash_table *htab)
2669 struct elf_aarch64_stub_hash_entry *stub_entry;
2671 stub_sec = _bfd_aarch64_get_stub_for_link_section (link_section, htab);
2672 stub_entry = aarch64_stub_hash_lookup (&htab->stub_hash_table, stub_name,
2674 if (stub_entry == NULL)
2676 (*_bfd_error_handler) (_("cannot create stub entry %s"), stub_name);
2680 stub_entry->stub_sec = stub_sec;
2681 stub_entry->stub_offset = 0;
2682 stub_entry->id_sec = link_section;
2689 aarch64_build_one_stub (struct bfd_hash_entry *gen_entry,
2690 void *in_arg ATTRIBUTE_UNUSED)
2692 struct elf_aarch64_stub_hash_entry *stub_entry;
2697 bfd_vma veneered_insn_loc;
2698 bfd_vma veneer_entry_loc;
2699 bfd_signed_vma branch_offset = 0;
2700 unsigned int template_size;
2701 const uint32_t *template;
2704 /* Massage our args to the form they really have. */
2705 stub_entry = (struct elf_aarch64_stub_hash_entry *) gen_entry;
2707 stub_sec = stub_entry->stub_sec;
2709 /* Make a note of the offset within the stubs for this entry. */
2710 stub_entry->stub_offset = stub_sec->size;
2711 loc = stub_sec->contents + stub_entry->stub_offset;
2713 stub_bfd = stub_sec->owner;
2715 /* This is the address of the stub destination. */
2716 sym_value = (stub_entry->target_value
2717 + stub_entry->target_section->output_offset
2718 + stub_entry->target_section->output_section->vma);
2720 if (stub_entry->stub_type == aarch64_stub_long_branch)
2722 bfd_vma place = (stub_entry->stub_offset + stub_sec->output_section->vma
2723 + stub_sec->output_offset);
2725 /* See if we can relax the stub. */
2726 if (aarch64_valid_for_adrp_p (sym_value, place))
2727 stub_entry->stub_type = aarch64_select_branch_stub (sym_value, place);
2730 switch (stub_entry->stub_type)
2732 case aarch64_stub_adrp_branch:
2733 template = aarch64_adrp_branch_stub;
2734 template_size = sizeof (aarch64_adrp_branch_stub);
2736 case aarch64_stub_long_branch:
2737 template = aarch64_long_branch_stub;
2738 template_size = sizeof (aarch64_long_branch_stub);
2740 case aarch64_stub_erratum_835769_veneer:
2741 template = aarch64_erratum_835769_stub;
2742 template_size = sizeof (aarch64_erratum_835769_stub);
2744 case aarch64_stub_erratum_843419_veneer:
2745 template = aarch64_erratum_843419_stub;
2746 template_size = sizeof (aarch64_erratum_843419_stub);
2752 for (i = 0; i < (template_size / sizeof template[0]); i++)
2754 bfd_putl32 (template[i], loc);
2758 template_size = (template_size + 7) & ~7;
2759 stub_sec->size += template_size;
2761 switch (stub_entry->stub_type)
2763 case aarch64_stub_adrp_branch:
2764 if (aarch64_relocate (AARCH64_R (ADR_PREL_PG_HI21), stub_bfd, stub_sec,
2765 stub_entry->stub_offset, sym_value))
2766 /* The stub would not have been relaxed if the offset was out
2770 if (aarch64_relocate (AARCH64_R (ADD_ABS_LO12_NC), stub_bfd, stub_sec,
2771 stub_entry->stub_offset + 4, sym_value))
2775 case aarch64_stub_long_branch:
2776 /* We want the value relative to the address 12 bytes back from the
2778 if (aarch64_relocate (AARCH64_R (PRELNN), stub_bfd, stub_sec,
2779 stub_entry->stub_offset + 16, sym_value + 12))
2783 case aarch64_stub_erratum_835769_veneer:
2784 veneered_insn_loc = stub_entry->target_section->output_section->vma
2785 + stub_entry->target_section->output_offset
2786 + stub_entry->target_value;
2787 veneer_entry_loc = stub_entry->stub_sec->output_section->vma
2788 + stub_entry->stub_sec->output_offset
2789 + stub_entry->stub_offset;
2790 branch_offset = veneered_insn_loc - veneer_entry_loc;
2791 branch_offset >>= 2;
2792 branch_offset &= 0x3ffffff;
2793 bfd_putl32 (stub_entry->veneered_insn,
2794 stub_sec->contents + stub_entry->stub_offset);
2795 bfd_putl32 (template[1] | branch_offset,
2796 stub_sec->contents + stub_entry->stub_offset + 4);
2799 case aarch64_stub_erratum_843419_veneer:
2800 if (aarch64_relocate (AARCH64_R (JUMP26), stub_bfd, stub_sec,
2801 stub_entry->stub_offset + 4, sym_value + 4))
2812 /* As above, but don't actually build the stub. Just bump offset so
2813 we know stub section sizes. */
2816 aarch64_size_one_stub (struct bfd_hash_entry *gen_entry,
2817 void *in_arg ATTRIBUTE_UNUSED)
2819 struct elf_aarch64_stub_hash_entry *stub_entry;
2822 /* Massage our args to the form they really have. */
2823 stub_entry = (struct elf_aarch64_stub_hash_entry *) gen_entry;
2825 switch (stub_entry->stub_type)
2827 case aarch64_stub_adrp_branch:
2828 size = sizeof (aarch64_adrp_branch_stub);
2830 case aarch64_stub_long_branch:
2831 size = sizeof (aarch64_long_branch_stub);
2833 case aarch64_stub_erratum_835769_veneer:
2834 size = sizeof (aarch64_erratum_835769_stub);
2836 case aarch64_stub_erratum_843419_veneer:
2837 size = sizeof (aarch64_erratum_843419_stub);
2843 size = (size + 7) & ~7;
2844 stub_entry->stub_sec->size += size;
2848 /* External entry points for sizing and building linker stubs. */
2850 /* Set up various things so that we can make a list of input sections
2851 for each output section included in the link. Returns -1 on error,
2852 0 when no stubs will be needed, and 1 on success. */
2855 elfNN_aarch64_setup_section_lists (bfd *output_bfd,
2856 struct bfd_link_info *info)
2859 unsigned int bfd_count;
2860 int top_id, top_index;
2862 asection **input_list, **list;
2864 struct elf_aarch64_link_hash_table *htab =
2865 elf_aarch64_hash_table (info);
2867 if (!is_elf_hash_table (htab))
2870 /* Count the number of input BFDs and find the top input section id. */
2871 for (input_bfd = info->input_bfds, bfd_count = 0, top_id = 0;
2872 input_bfd != NULL; input_bfd = input_bfd->link.next)
2875 for (section = input_bfd->sections;
2876 section != NULL; section = section->next)
2878 if (top_id < section->id)
2879 top_id = section->id;
2882 htab->bfd_count = bfd_count;
2884 amt = sizeof (struct map_stub) * (top_id + 1);
2885 htab->stub_group = bfd_zmalloc (amt);
2886 if (htab->stub_group == NULL)
2889 /* We can't use output_bfd->section_count here to find the top output
2890 section index as some sections may have been removed, and
2891 _bfd_strip_section_from_output doesn't renumber the indices. */
2892 for (section = output_bfd->sections, top_index = 0;
2893 section != NULL; section = section->next)
2895 if (top_index < section->index)
2896 top_index = section->index;
2899 htab->top_index = top_index;
2900 amt = sizeof (asection *) * (top_index + 1);
2901 input_list = bfd_malloc (amt);
2902 htab->input_list = input_list;
2903 if (input_list == NULL)
2906 /* For sections we aren't interested in, mark their entries with a
2907 value we can check later. */
2908 list = input_list + top_index;
2910 *list = bfd_abs_section_ptr;
2911 while (list-- != input_list);
2913 for (section = output_bfd->sections;
2914 section != NULL; section = section->next)
2916 if ((section->flags & SEC_CODE) != 0)
2917 input_list[section->index] = NULL;
2923 /* Used by elfNN_aarch64_next_input_section and group_sections. */
2924 #define PREV_SEC(sec) (htab->stub_group[(sec)->id].link_sec)
2926 /* The linker repeatedly calls this function for each input section,
2927 in the order that input sections are linked into output sections.
2928 Build lists of input sections to determine groupings between which
2929 we may insert linker stubs. */
2932 elfNN_aarch64_next_input_section (struct bfd_link_info *info, asection *isec)
2934 struct elf_aarch64_link_hash_table *htab =
2935 elf_aarch64_hash_table (info);
2937 if (isec->output_section->index <= htab->top_index)
2939 asection **list = htab->input_list + isec->output_section->index;
2941 if (*list != bfd_abs_section_ptr)
2943 /* Steal the link_sec pointer for our list. */
2944 /* This happens to make the list in reverse order,
2945 which is what we want. */
2946 PREV_SEC (isec) = *list;
2952 /* See whether we can group stub sections together. Grouping stub
2953 sections may result in fewer stubs. More importantly, we need to
2954 put all .init* and .fini* stubs at the beginning of the .init or
2955 .fini output sections respectively, because glibc splits the
2956 _init and _fini functions into multiple parts. Putting a stub in
2957 the middle of a function is not a good idea. */
2960 group_sections (struct elf_aarch64_link_hash_table *htab,
2961 bfd_size_type stub_group_size,
2962 bfd_boolean stubs_always_before_branch)
2964 asection **list = htab->input_list + htab->top_index;
2968 asection *tail = *list;
2970 if (tail == bfd_abs_section_ptr)
2973 while (tail != NULL)
2977 bfd_size_type total;
2981 while ((prev = PREV_SEC (curr)) != NULL
2982 && ((total += curr->output_offset - prev->output_offset)
2986 /* OK, the size from the start of CURR to the end is less
2987 than stub_group_size and thus can be handled by one stub
2988 section. (Or the tail section is itself larger than
2989 stub_group_size, in which case we may be toast.)
2990 We should really be keeping track of the total size of
2991 stubs added here, as stubs contribute to the final output
2995 prev = PREV_SEC (tail);
2996 /* Set up this stub group. */
2997 htab->stub_group[tail->id].link_sec = curr;
2999 while (tail != curr && (tail = prev) != NULL);
3001 /* But wait, there's more! Input sections up to stub_group_size
3002 bytes before the stub section can be handled by it too. */
3003 if (!stubs_always_before_branch)
3007 && ((total += tail->output_offset - prev->output_offset)
3011 prev = PREV_SEC (tail);
3012 htab->stub_group[tail->id].link_sec = curr;
3018 while (list-- != htab->input_list);
3020 free (htab->input_list);
3025 #define AARCH64_BITS(x, pos, n) (((x) >> (pos)) & ((1 << (n)) - 1))
3027 #define AARCH64_RT(insn) AARCH64_BITS (insn, 0, 5)
3028 #define AARCH64_RT2(insn) AARCH64_BITS (insn, 10, 5)
3029 #define AARCH64_RA(insn) AARCH64_BITS (insn, 10, 5)
3030 #define AARCH64_RD(insn) AARCH64_BITS (insn, 0, 5)
3031 #define AARCH64_RN(insn) AARCH64_BITS (insn, 5, 5)
3032 #define AARCH64_RM(insn) AARCH64_BITS (insn, 16, 5)
3034 #define AARCH64_MAC(insn) (((insn) & 0xff000000) == 0x9b000000)
3035 #define AARCH64_BIT(insn, n) AARCH64_BITS (insn, n, 1)
3036 #define AARCH64_OP31(insn) AARCH64_BITS (insn, 21, 3)
3037 #define AARCH64_ZR 0x1f
3039 /* All ld/st ops. See C4-182 of the ARM ARM. The encoding space for
3040 LD_PCREL, LDST_RO, LDST_UI and LDST_UIMM cover prefetch ops. */
3042 #define AARCH64_LD(insn) (AARCH64_BIT (insn, 22) == 1)
3043 #define AARCH64_LDST(insn) (((insn) & 0x0a000000) == 0x08000000)
3044 #define AARCH64_LDST_EX(insn) (((insn) & 0x3f000000) == 0x08000000)
3045 #define AARCH64_LDST_PCREL(insn) (((insn) & 0x3b000000) == 0x18000000)
3046 #define AARCH64_LDST_NAP(insn) (((insn) & 0x3b800000) == 0x28000000)
3047 #define AARCH64_LDSTP_PI(insn) (((insn) & 0x3b800000) == 0x28800000)
3048 #define AARCH64_LDSTP_O(insn) (((insn) & 0x3b800000) == 0x29000000)
3049 #define AARCH64_LDSTP_PRE(insn) (((insn) & 0x3b800000) == 0x29800000)
3050 #define AARCH64_LDST_UI(insn) (((insn) & 0x3b200c00) == 0x38000000)
3051 #define AARCH64_LDST_PIIMM(insn) (((insn) & 0x3b200c00) == 0x38000400)
3052 #define AARCH64_LDST_U(insn) (((insn) & 0x3b200c00) == 0x38000800)
3053 #define AARCH64_LDST_PREIMM(insn) (((insn) & 0x3b200c00) == 0x38000c00)
3054 #define AARCH64_LDST_RO(insn) (((insn) & 0x3b200c00) == 0x38200800)
3055 #define AARCH64_LDST_UIMM(insn) (((insn) & 0x3b000000) == 0x39000000)
3056 #define AARCH64_LDST_SIMD_M(insn) (((insn) & 0xbfbf0000) == 0x0c000000)
3057 #define AARCH64_LDST_SIMD_M_PI(insn) (((insn) & 0xbfa00000) == 0x0c800000)
3058 #define AARCH64_LDST_SIMD_S(insn) (((insn) & 0xbf9f0000) == 0x0d000000)
3059 #define AARCH64_LDST_SIMD_S_PI(insn) (((insn) & 0xbf800000) == 0x0d800000)
3061 /* Classify an INSN if it is indeed a load/store.
3063 Return TRUE if INSN is a LD/ST instruction otherwise return FALSE.
3065 For scalar LD/ST instructions PAIR is FALSE, RT is returned and RT2
3068 For LD/ST pair instructions PAIR is TRUE, RT and RT2 are returned.
3073 aarch64_mem_op_p (uint32_t insn, unsigned int *rt, unsigned int *rt2,
3074 bfd_boolean *pair, bfd_boolean *load)
3082 /* Bail out quickly if INSN doesn't fall into the the load-store
3084 if (!AARCH64_LDST (insn))
3089 if (AARCH64_LDST_EX (insn))
3091 *rt = AARCH64_RT (insn);
3093 if (AARCH64_BIT (insn, 21) == 1)
3096 *rt2 = AARCH64_RT2 (insn);
3098 *load = AARCH64_LD (insn);
3101 else if (AARCH64_LDST_NAP (insn)
3102 || AARCH64_LDSTP_PI (insn)
3103 || AARCH64_LDSTP_O (insn)
3104 || AARCH64_LDSTP_PRE (insn))
3107 *rt = AARCH64_RT (insn);
3108 *rt2 = AARCH64_RT2 (insn);
3109 *load = AARCH64_LD (insn);
3112 else if (AARCH64_LDST_PCREL (insn)
3113 || AARCH64_LDST_UI (insn)
3114 || AARCH64_LDST_PIIMM (insn)
3115 || AARCH64_LDST_U (insn)
3116 || AARCH64_LDST_PREIMM (insn)
3117 || AARCH64_LDST_RO (insn)
3118 || AARCH64_LDST_UIMM (insn))
3120 *rt = AARCH64_RT (insn);
3122 if (AARCH64_LDST_PCREL (insn))
3124 opc = AARCH64_BITS (insn, 22, 2);
3125 v = AARCH64_BIT (insn, 26);
3126 opc_v = opc | (v << 2);
3127 *load = (opc_v == 1 || opc_v == 2 || opc_v == 3
3128 || opc_v == 5 || opc_v == 7);
3131 else if (AARCH64_LDST_SIMD_M (insn)
3132 || AARCH64_LDST_SIMD_M_PI (insn))
3134 *rt = AARCH64_RT (insn);
3135 *load = AARCH64_BIT (insn, 22);
3136 opcode = (insn >> 12) & 0xf;
3163 else if (AARCH64_LDST_SIMD_S (insn)
3164 || AARCH64_LDST_SIMD_S_PI (insn))
3166 *rt = AARCH64_RT (insn);
3167 r = (insn >> 21) & 1;
3168 *load = AARCH64_BIT (insn, 22);
3169 opcode = (insn >> 13) & 0x7;
3181 *rt2 = *rt + (r == 0 ? 2 : 3);
3189 *rt2 = *rt + (r == 0 ? 2 : 3);
3201 /* Return TRUE if INSN is multiply-accumulate. */
3204 aarch64_mlxl_p (uint32_t insn)
3206 uint32_t op31 = AARCH64_OP31 (insn);
3208 if (AARCH64_MAC (insn)
3209 && (op31 == 0 || op31 == 1 || op31 == 5)
3210 /* Exclude MUL instructions which are encoded as a multiple accumulate
3212 && AARCH64_RA (insn) != AARCH64_ZR)
3218 /* Some early revisions of the Cortex-A53 have an erratum (835769) whereby
3219 it is possible for a 64-bit multiply-accumulate instruction to generate an
3220 incorrect result. The details are quite complex and hard to
3221 determine statically, since branches in the code may exist in some
3222 circumstances, but all cases end with a memory (load, store, or
3223 prefetch) instruction followed immediately by the multiply-accumulate
3224 operation. We employ a linker patching technique, by moving the potentially
3225 affected multiply-accumulate instruction into a patch region and replacing
3226 the original instruction with a branch to the patch. This function checks
3227 if INSN_1 is the memory operation followed by a multiply-accumulate
3228 operation (INSN_2). Return TRUE if an erratum sequence is found, FALSE
3229 if INSN_1 and INSN_2 are safe. */
3232 aarch64_erratum_sequence (uint32_t insn_1, uint32_t insn_2)
3242 if (aarch64_mlxl_p (insn_2)
3243 && aarch64_mem_op_p (insn_1, &rt, &rt2, &pair, &load))
3245 /* Any SIMD memory op is independent of the subsequent MLA
3246 by definition of the erratum. */
3247 if (AARCH64_BIT (insn_1, 26))
3250 /* If not SIMD, check for integer memory ops and MLA relationship. */
3251 rn = AARCH64_RN (insn_2);
3252 ra = AARCH64_RA (insn_2);
3253 rm = AARCH64_RM (insn_2);
3255 /* If this is a load and there's a true(RAW) dependency, we are safe
3256 and this is not an erratum sequence. */
3258 (rt == rn || rt == rm || rt == ra
3259 || (pair && (rt2 == rn || rt2 == rm || rt2 == ra))))
3262 /* We conservatively put out stubs for all other cases (including
3270 /* Used to order a list of mapping symbols by address. */
3273 elf_aarch64_compare_mapping (const void *a, const void *b)
3275 const elf_aarch64_section_map *amap = (const elf_aarch64_section_map *) a;
3276 const elf_aarch64_section_map *bmap = (const elf_aarch64_section_map *) b;
3278 if (amap->vma > bmap->vma)
3280 else if (amap->vma < bmap->vma)
3282 else if (amap->type > bmap->type)
3283 /* Ensure results do not depend on the host qsort for objects with
3284 multiple mapping symbols at the same address by sorting on type
3287 else if (amap->type < bmap->type)
3295 _bfd_aarch64_erratum_835769_stub_name (unsigned num_fixes)
3297 char *stub_name = (char *) bfd_malloc
3298 (strlen ("__erratum_835769_veneer_") + 16);
3299 sprintf (stub_name,"__erratum_835769_veneer_%d", num_fixes);
3303 /* Scan for Cortex-A53 erratum 835769 sequence.
3305 Return TRUE else FALSE on abnormal termination. */
3308 _bfd_aarch64_erratum_835769_scan (bfd *input_bfd,
3309 struct bfd_link_info *info,
3310 unsigned int *num_fixes_p)
3313 struct elf_aarch64_link_hash_table *htab = elf_aarch64_hash_table (info);
3314 unsigned int num_fixes = *num_fixes_p;
3319 for (section = input_bfd->sections;
3321 section = section->next)
3323 bfd_byte *contents = NULL;
3324 struct _aarch64_elf_section_data *sec_data;
3327 if (elf_section_type (section) != SHT_PROGBITS
3328 || (elf_section_flags (section) & SHF_EXECINSTR) == 0
3329 || (section->flags & SEC_EXCLUDE) != 0
3330 || (section->sec_info_type == SEC_INFO_TYPE_JUST_SYMS)
3331 || (section->output_section == bfd_abs_section_ptr))
3334 if (elf_section_data (section)->this_hdr.contents != NULL)
3335 contents = elf_section_data (section)->this_hdr.contents;
3336 else if (! bfd_malloc_and_get_section (input_bfd, section, &contents))
3339 sec_data = elf_aarch64_section_data (section);
3341 qsort (sec_data->map, sec_data->mapcount,
3342 sizeof (elf_aarch64_section_map), elf_aarch64_compare_mapping);
3344 for (span = 0; span < sec_data->mapcount; span++)
3346 unsigned int span_start = sec_data->map[span].vma;
3347 unsigned int span_end = ((span == sec_data->mapcount - 1)
3348 ? sec_data->map[0].vma + section->size
3349 : sec_data->map[span + 1].vma);
3351 char span_type = sec_data->map[span].type;
3353 if (span_type == 'd')
3356 for (i = span_start; i + 4 < span_end; i += 4)
3358 uint32_t insn_1 = bfd_getl32 (contents + i);
3359 uint32_t insn_2 = bfd_getl32 (contents + i + 4);
3361 if (aarch64_erratum_sequence (insn_1, insn_2))
3363 struct elf_aarch64_stub_hash_entry *stub_entry;
3364 char *stub_name = _bfd_aarch64_erratum_835769_stub_name (num_fixes);
3368 stub_entry = _bfd_aarch64_add_stub_entry_in_group (stub_name,
3374 stub_entry->stub_type = aarch64_stub_erratum_835769_veneer;
3375 stub_entry->target_section = section;
3376 stub_entry->target_value = i + 4;
3377 stub_entry->veneered_insn = insn_2;
3378 stub_entry->output_name = stub_name;
3383 if (elf_section_data (section)->this_hdr.contents == NULL)
3387 *num_fixes_p = num_fixes;
3393 /* Test if instruction INSN is ADRP. */
3396 _bfd_aarch64_adrp_p (uint32_t insn)
3398 return ((insn & 0x9f000000) == 0x90000000);
3402 /* Helper predicate to look for cortex-a53 erratum 843419 sequence 1. */
3405 _bfd_aarch64_erratum_843419_sequence_p (uint32_t insn_1, uint32_t insn_2,
3413 return (aarch64_mem_op_p (insn_2, &rt, &rt2, &pair, &load)
3416 && AARCH64_LDST_UIMM (insn_3)
3417 && AARCH64_RN (insn_3) == AARCH64_RD (insn_1));
3421 /* Test for the presence of Cortex-A53 erratum 843419 instruction sequence.
3423 Return TRUE if section CONTENTS at offset I contains one of the
3424 erratum 843419 sequences, otherwise return FALSE. If a sequence is
3425 seen set P_VENEER_I to the offset of the final LOAD/STORE
3426 instruction in the sequence.
3430 _bfd_aarch64_erratum_843419_p (bfd_byte *contents, bfd_vma vma,
3431 bfd_vma i, bfd_vma span_end,
3432 bfd_vma *p_veneer_i)
3434 uint32_t insn_1 = bfd_getl32 (contents + i);
3436 if (!_bfd_aarch64_adrp_p (insn_1))
3439 if (span_end < i + 12)
3442 uint32_t insn_2 = bfd_getl32 (contents + i + 4);
3443 uint32_t insn_3 = bfd_getl32 (contents + i + 8);
3445 if ((vma & 0xfff) != 0xff8 && (vma & 0xfff) != 0xffc)
3448 if (_bfd_aarch64_erratum_843419_sequence_p (insn_1, insn_2, insn_3))
3450 *p_veneer_i = i + 8;
3454 if (span_end < i + 16)
3457 uint32_t insn_4 = bfd_getl32 (contents + i + 12);
3459 if (_bfd_aarch64_erratum_843419_sequence_p (insn_1, insn_2, insn_4))
3461 *p_veneer_i = i + 12;
3469 /* Resize all stub sections. */
3472 _bfd_aarch64_resize_stubs (struct elf_aarch64_link_hash_table *htab)
3476 /* OK, we've added some stubs. Find out the new size of the
3478 for (section = htab->stub_bfd->sections;
3479 section != NULL; section = section->next)
3481 /* Ignore non-stub sections. */
3482 if (!strstr (section->name, STUB_SUFFIX))
3487 bfd_hash_traverse (&htab->stub_hash_table, aarch64_size_one_stub, htab);
3489 for (section = htab->stub_bfd->sections;
3490 section != NULL; section = section->next)
3492 if (!strstr (section->name, STUB_SUFFIX))
3498 /* Ensure all stub sections have a size which is a multiple of
3499 4096. This is important in order to ensure that the insertion
3500 of stub sections does not in itself move existing code around
3501 in such a way that new errata sequences are created. */
3502 if (htab->fix_erratum_843419)
3504 section->size = BFD_ALIGN (section->size, 0x1000);
3509 /* Construct an erratum 843419 workaround stub name.
3513 _bfd_aarch64_erratum_843419_stub_name (asection *input_section,
3516 const bfd_size_type len = 8 + 4 + 1 + 8 + 1 + 16 + 1;
3517 char *stub_name = bfd_malloc (len);
3519 if (stub_name != NULL)
3520 snprintf (stub_name, len, "e843419@%04x_%08x_%" BFD_VMA_FMT "x",
3521 input_section->owner->id,
3527 /* Build a stub_entry structure describing an 843419 fixup.
3529 The stub_entry constructed is populated with the bit pattern INSN
3530 of the instruction located at OFFSET within input SECTION.
3532 Returns TRUE on success. */
3535 _bfd_aarch64_erratum_843419_fixup (uint32_t insn,
3536 bfd_vma adrp_offset,
3537 bfd_vma ldst_offset,
3539 struct bfd_link_info *info)
3541 struct elf_aarch64_link_hash_table *htab = elf_aarch64_hash_table (info);
3543 struct elf_aarch64_stub_hash_entry *stub_entry;
3545 stub_name = _bfd_aarch64_erratum_843419_stub_name (section, ldst_offset);
3546 stub_entry = aarch64_stub_hash_lookup (&htab->stub_hash_table, stub_name,
3554 /* We always place an 843419 workaround veneer in the stub section
3555 attached to the input section in which an erratum sequence has
3556 been found. This ensures that later in the link process (in
3557 elfNN_aarch64_write_section) when we copy the veneered
3558 instruction from the input section into the stub section the
3559 copied instruction will have had any relocations applied to it.
3560 If we placed workaround veneers in any other stub section then we
3561 could not assume that all relocations have been processed on the
3562 corresponding input section at the point we output the stub
3566 stub_entry = _bfd_aarch64_add_stub_entry_after (stub_name, section, htab);
3567 if (stub_entry == NULL)
3573 stub_entry->adrp_offset = adrp_offset;
3574 stub_entry->target_value = ldst_offset;
3575 stub_entry->target_section = section;
3576 stub_entry->stub_type = aarch64_stub_erratum_843419_veneer;
3577 stub_entry->veneered_insn = insn;
3578 stub_entry->output_name = stub_name;
3584 /* Scan an input section looking for the signature of erratum 843419.
3586 Scans input SECTION in INPUT_BFD looking for erratum 843419
3587 signatures, for each signature found a stub_entry is created
3588 describing the location of the erratum for subsequent fixup.
3590 Return TRUE on successful scan, FALSE on failure to scan.
3594 _bfd_aarch64_erratum_843419_scan (bfd *input_bfd, asection *section,
3595 struct bfd_link_info *info)
3597 struct elf_aarch64_link_hash_table *htab = elf_aarch64_hash_table (info);
3602 if (elf_section_type (section) != SHT_PROGBITS
3603 || (elf_section_flags (section) & SHF_EXECINSTR) == 0
3604 || (section->flags & SEC_EXCLUDE) != 0
3605 || (section->sec_info_type == SEC_INFO_TYPE_JUST_SYMS)
3606 || (section->output_section == bfd_abs_section_ptr))
3611 bfd_byte *contents = NULL;
3612 struct _aarch64_elf_section_data *sec_data;
3615 if (elf_section_data (section)->this_hdr.contents != NULL)
3616 contents = elf_section_data (section)->this_hdr.contents;
3617 else if (! bfd_malloc_and_get_section (input_bfd, section, &contents))
3620 sec_data = elf_aarch64_section_data (section);
3622 qsort (sec_data->map, sec_data->mapcount,
3623 sizeof (elf_aarch64_section_map), elf_aarch64_compare_mapping);
3625 for (span = 0; span < sec_data->mapcount; span++)
3627 unsigned int span_start = sec_data->map[span].vma;
3628 unsigned int span_end = ((span == sec_data->mapcount - 1)
3629 ? sec_data->map[0].vma + section->size
3630 : sec_data->map[span + 1].vma);
3632 char span_type = sec_data->map[span].type;
3634 if (span_type == 'd')
3637 for (i = span_start; i + 8 < span_end; i += 4)
3639 bfd_vma vma = (section->output_section->vma
3640 + section->output_offset
3644 if (_bfd_aarch64_erratum_843419_p
3645 (contents, vma, i, span_end, &veneer_i))
3647 uint32_t insn = bfd_getl32 (contents + veneer_i);
3649 if (!_bfd_aarch64_erratum_843419_fixup (insn, i, veneer_i,
3656 if (elf_section_data (section)->this_hdr.contents == NULL)
3665 /* Determine and set the size of the stub section for a final link.
3667 The basic idea here is to examine all the relocations looking for
3668 PC-relative calls to a target that is unreachable with a "bl"
3672 elfNN_aarch64_size_stubs (bfd *output_bfd,
3674 struct bfd_link_info *info,
3675 bfd_signed_vma group_size,
3676 asection * (*add_stub_section) (const char *,
3678 void (*layout_sections_again) (void))
3680 bfd_size_type stub_group_size;
3681 bfd_boolean stubs_always_before_branch;
3682 bfd_boolean stub_changed = FALSE;
3683 struct elf_aarch64_link_hash_table *htab = elf_aarch64_hash_table (info);
3684 unsigned int num_erratum_835769_fixes = 0;
3686 /* Propagate mach to stub bfd, because it may not have been
3687 finalized when we created stub_bfd. */
3688 bfd_set_arch_mach (stub_bfd, bfd_get_arch (output_bfd),
3689 bfd_get_mach (output_bfd));
3691 /* Stash our params away. */
3692 htab->stub_bfd = stub_bfd;
3693 htab->add_stub_section = add_stub_section;
3694 htab->layout_sections_again = layout_sections_again;
3695 stubs_always_before_branch = group_size < 0;
3697 stub_group_size = -group_size;
3699 stub_group_size = group_size;
3701 if (stub_group_size == 1)
3703 /* Default values. */
3704 /* AArch64 branch range is +-128MB. The value used is 1MB less. */
3705 stub_group_size = 127 * 1024 * 1024;
3708 group_sections (htab, stub_group_size, stubs_always_before_branch);
3710 (*htab->layout_sections_again) ();
3712 if (htab->fix_erratum_835769)
3716 for (input_bfd = info->input_bfds;
3717 input_bfd != NULL; input_bfd = input_bfd->link.next)
3718 if (!_bfd_aarch64_erratum_835769_scan (input_bfd, info,
3719 &num_erratum_835769_fixes))
3722 _bfd_aarch64_resize_stubs (htab);
3723 (*htab->layout_sections_again) ();
3726 if (htab->fix_erratum_843419)
3730 for (input_bfd = info->input_bfds;
3732 input_bfd = input_bfd->link.next)
3736 for (section = input_bfd->sections;
3738 section = section->next)
3739 if (!_bfd_aarch64_erratum_843419_scan (input_bfd, section, info))
3743 _bfd_aarch64_resize_stubs (htab);
3744 (*htab->layout_sections_again) ();
3751 for (input_bfd = info->input_bfds;
3752 input_bfd != NULL; input_bfd = input_bfd->link.next)
3754 Elf_Internal_Shdr *symtab_hdr;
3756 Elf_Internal_Sym *local_syms = NULL;
3758 /* We'll need the symbol table in a second. */
3759 symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
3760 if (symtab_hdr->sh_info == 0)
3763 /* Walk over each section attached to the input bfd. */
3764 for (section = input_bfd->sections;
3765 section != NULL; section = section->next)
3767 Elf_Internal_Rela *internal_relocs, *irelaend, *irela;
3769 /* If there aren't any relocs, then there's nothing more
3771 if ((section->flags & SEC_RELOC) == 0
3772 || section->reloc_count == 0
3773 || (section->flags & SEC_CODE) == 0)
3776 /* If this section is a link-once section that will be
3777 discarded, then don't create any stubs. */
3778 if (section->output_section == NULL
3779 || section->output_section->owner != output_bfd)
3782 /* Get the relocs. */
3784 = _bfd_elf_link_read_relocs (input_bfd, section, NULL,
3785 NULL, info->keep_memory);
3786 if (internal_relocs == NULL)
3787 goto error_ret_free_local;
3789 /* Now examine each relocation. */
3790 irela = internal_relocs;
3791 irelaend = irela + section->reloc_count;
3792 for (; irela < irelaend; irela++)
3794 unsigned int r_type, r_indx;
3795 enum elf_aarch64_stub_type stub_type;
3796 struct elf_aarch64_stub_hash_entry *stub_entry;
3799 bfd_vma destination;
3800 struct elf_aarch64_link_hash_entry *hash;
3801 const char *sym_name;
3803 const asection *id_sec;
3804 unsigned char st_type;
3807 r_type = ELFNN_R_TYPE (irela->r_info);
3808 r_indx = ELFNN_R_SYM (irela->r_info);
3810 if (r_type >= (unsigned int) R_AARCH64_end)
3812 bfd_set_error (bfd_error_bad_value);
3813 error_ret_free_internal:
3814 if (elf_section_data (section)->relocs == NULL)
3815 free (internal_relocs);
3816 goto error_ret_free_local;
3819 /* Only look for stubs on unconditional branch and
3820 branch and link instructions. */
3821 if (r_type != (unsigned int) AARCH64_R (CALL26)
3822 && r_type != (unsigned int) AARCH64_R (JUMP26))
3825 /* Now determine the call target, its name, value,
3832 if (r_indx < symtab_hdr->sh_info)
3834 /* It's a local symbol. */
3835 Elf_Internal_Sym *sym;
3836 Elf_Internal_Shdr *hdr;
3838 if (local_syms == NULL)
3841 = (Elf_Internal_Sym *) symtab_hdr->contents;
3842 if (local_syms == NULL)
3844 = bfd_elf_get_elf_syms (input_bfd, symtab_hdr,
3845 symtab_hdr->sh_info, 0,
3847 if (local_syms == NULL)
3848 goto error_ret_free_internal;
3851 sym = local_syms + r_indx;
3852 hdr = elf_elfsections (input_bfd)[sym->st_shndx];
3853 sym_sec = hdr->bfd_section;
3855 /* This is an undefined symbol. It can never
3859 if (ELF_ST_TYPE (sym->st_info) != STT_SECTION)
3860 sym_value = sym->st_value;
3861 destination = (sym_value + irela->r_addend
3862 + sym_sec->output_offset
3863 + sym_sec->output_section->vma);
3864 st_type = ELF_ST_TYPE (sym->st_info);
3866 = bfd_elf_string_from_elf_section (input_bfd,
3867 symtab_hdr->sh_link,
3874 e_indx = r_indx - symtab_hdr->sh_info;
3875 hash = ((struct elf_aarch64_link_hash_entry *)
3876 elf_sym_hashes (input_bfd)[e_indx]);
3878 while (hash->root.root.type == bfd_link_hash_indirect
3879 || hash->root.root.type == bfd_link_hash_warning)
3880 hash = ((struct elf_aarch64_link_hash_entry *)
3881 hash->root.root.u.i.link);
3883 if (hash->root.root.type == bfd_link_hash_defined
3884 || hash->root.root.type == bfd_link_hash_defweak)
3886 struct elf_aarch64_link_hash_table *globals =
3887 elf_aarch64_hash_table (info);
3888 sym_sec = hash->root.root.u.def.section;
3889 sym_value = hash->root.root.u.def.value;
3890 /* For a destination in a shared library,
3891 use the PLT stub as target address to
3892 decide whether a branch stub is
3894 if (globals->root.splt != NULL && hash != NULL
3895 && hash->root.plt.offset != (bfd_vma) - 1)
3897 sym_sec = globals->root.splt;
3898 sym_value = hash->root.plt.offset;
3899 if (sym_sec->output_section != NULL)
3900 destination = (sym_value
3901 + sym_sec->output_offset
3903 sym_sec->output_section->vma);
3905 else if (sym_sec->output_section != NULL)
3906 destination = (sym_value + irela->r_addend
3907 + sym_sec->output_offset
3908 + sym_sec->output_section->vma);
3910 else if (hash->root.root.type == bfd_link_hash_undefined
3911 || (hash->root.root.type
3912 == bfd_link_hash_undefweak))
3914 /* For a shared library, use the PLT stub as
3915 target address to decide whether a long
3916 branch stub is needed.
3917 For absolute code, they cannot be handled. */
3918 struct elf_aarch64_link_hash_table *globals =
3919 elf_aarch64_hash_table (info);
3921 if (globals->root.splt != NULL && hash != NULL
3922 && hash->root.plt.offset != (bfd_vma) - 1)
3924 sym_sec = globals->root.splt;
3925 sym_value = hash->root.plt.offset;
3926 if (sym_sec->output_section != NULL)
3927 destination = (sym_value
3928 + sym_sec->output_offset
3930 sym_sec->output_section->vma);
3937 bfd_set_error (bfd_error_bad_value);
3938 goto error_ret_free_internal;
3940 st_type = ELF_ST_TYPE (hash->root.type);
3941 sym_name = hash->root.root.root.string;
3944 /* Determine what (if any) linker stub is needed. */
3945 stub_type = aarch64_type_of_stub
3946 (info, section, irela, sym_sec, st_type, hash, destination);
3947 if (stub_type == aarch64_stub_none)
3950 /* Support for grouping stub sections. */
3951 id_sec = htab->stub_group[section->id].link_sec;
3953 /* Get the name of this stub. */
3954 stub_name = elfNN_aarch64_stub_name (id_sec, sym_sec, hash,
3957 goto error_ret_free_internal;
3960 aarch64_stub_hash_lookup (&htab->stub_hash_table,
3961 stub_name, FALSE, FALSE);
3962 if (stub_entry != NULL)
3964 /* The proper stub has already been created. */
3969 stub_entry = _bfd_aarch64_add_stub_entry_in_group
3970 (stub_name, section, htab);
3971 if (stub_entry == NULL)
3974 goto error_ret_free_internal;
3977 stub_entry->target_value = sym_value;
3978 stub_entry->target_section = sym_sec;
3979 stub_entry->stub_type = stub_type;
3980 stub_entry->h = hash;
3981 stub_entry->st_type = st_type;
3983 if (sym_name == NULL)
3984 sym_name = "unnamed";
3985 len = sizeof (STUB_ENTRY_NAME) + strlen (sym_name);
3986 stub_entry->output_name = bfd_alloc (htab->stub_bfd, len);
3987 if (stub_entry->output_name == NULL)
3990 goto error_ret_free_internal;
3993 snprintf (stub_entry->output_name, len, STUB_ENTRY_NAME,
3996 stub_changed = TRUE;
3999 /* We're done with the internal relocs, free them. */
4000 if (elf_section_data (section)->relocs == NULL)
4001 free (internal_relocs);
4008 _bfd_aarch64_resize_stubs (htab);
4010 /* Ask the linker to do its stuff. */
4011 (*htab->layout_sections_again) ();
4012 stub_changed = FALSE;
4017 error_ret_free_local:
4021 /* Build all the stubs associated with the current output file. The
4022 stubs are kept in a hash table attached to the main linker hash
4023 table. We also set up the .plt entries for statically linked PIC
4024 functions here. This function is called via aarch64_elf_finish in the
4028 elfNN_aarch64_build_stubs (struct bfd_link_info *info)
4031 struct bfd_hash_table *table;
4032 struct elf_aarch64_link_hash_table *htab;
4034 htab = elf_aarch64_hash_table (info);
4036 for (stub_sec = htab->stub_bfd->sections;
4037 stub_sec != NULL; stub_sec = stub_sec->next)
4041 /* Ignore non-stub sections. */
4042 if (!strstr (stub_sec->name, STUB_SUFFIX))
4045 /* Allocate memory to hold the linker stubs. */
4046 size = stub_sec->size;
4047 stub_sec->contents = bfd_zalloc (htab->stub_bfd, size);
4048 if (stub_sec->contents == NULL && size != 0)
4052 bfd_putl32 (0x14000000 | (size >> 2), stub_sec->contents);
4053 stub_sec->size += 4;
4056 /* Build the stubs as directed by the stub hash table. */
4057 table = &htab->stub_hash_table;
4058 bfd_hash_traverse (table, aarch64_build_one_stub, info);
4064 /* Add an entry to the code/data map for section SEC. */
4067 elfNN_aarch64_section_map_add (asection *sec, char type, bfd_vma vma)
4069 struct _aarch64_elf_section_data *sec_data =
4070 elf_aarch64_section_data (sec);
4071 unsigned int newidx;
4073 if (sec_data->map == NULL)
4075 sec_data->map = bfd_malloc (sizeof (elf_aarch64_section_map));
4076 sec_data->mapcount = 0;
4077 sec_data->mapsize = 1;
4080 newidx = sec_data->mapcount++;
4082 if (sec_data->mapcount > sec_data->mapsize)
4084 sec_data->mapsize *= 2;
4085 sec_data->map = bfd_realloc_or_free
4086 (sec_data->map, sec_data->mapsize * sizeof (elf_aarch64_section_map));
4091 sec_data->map[newidx].vma = vma;
4092 sec_data->map[newidx].type = type;
4097 /* Initialise maps of insn/data for input BFDs. */
4099 bfd_elfNN_aarch64_init_maps (bfd *abfd)
4101 Elf_Internal_Sym *isymbuf;
4102 Elf_Internal_Shdr *hdr;
4103 unsigned int i, localsyms;
4105 /* Make sure that we are dealing with an AArch64 elf binary. */
4106 if (!is_aarch64_elf (abfd))
4109 if ((abfd->flags & DYNAMIC) != 0)
4112 hdr = &elf_symtab_hdr (abfd);
4113 localsyms = hdr->sh_info;
4115 /* Obtain a buffer full of symbols for this BFD. The hdr->sh_info field
4116 should contain the number of local symbols, which should come before any
4117 global symbols. Mapping symbols are always local. */
4118 isymbuf = bfd_elf_get_elf_syms (abfd, hdr, localsyms, 0, NULL, NULL, NULL);
4120 /* No internal symbols read? Skip this BFD. */
4121 if (isymbuf == NULL)
4124 for (i = 0; i < localsyms; i++)
4126 Elf_Internal_Sym *isym = &isymbuf[i];
4127 asection *sec = bfd_section_from_elf_index (abfd, isym->st_shndx);
4130 if (sec != NULL && ELF_ST_BIND (isym->st_info) == STB_LOCAL)
4132 name = bfd_elf_string_from_elf_section (abfd,
4136 if (bfd_is_aarch64_special_symbol_name
4137 (name, BFD_AARCH64_SPECIAL_SYM_TYPE_MAP))
4138 elfNN_aarch64_section_map_add (sec, name[1], isym->st_value);
4143 /* Set option values needed during linking. */
4145 bfd_elfNN_aarch64_set_options (struct bfd *output_bfd,
4146 struct bfd_link_info *link_info,
4148 int no_wchar_warn, int pic_veneer,
4149 int fix_erratum_835769,
4150 int fix_erratum_843419)
4152 struct elf_aarch64_link_hash_table *globals;
4154 globals = elf_aarch64_hash_table (link_info);
4155 globals->pic_veneer = pic_veneer;
4156 globals->fix_erratum_835769 = fix_erratum_835769;
4157 globals->fix_erratum_843419 = fix_erratum_843419;
4158 globals->fix_erratum_843419_adr = TRUE;
4160 BFD_ASSERT (is_aarch64_elf (output_bfd));
4161 elf_aarch64_tdata (output_bfd)->no_enum_size_warning = no_enum_warn;
4162 elf_aarch64_tdata (output_bfd)->no_wchar_size_warning = no_wchar_warn;
4166 aarch64_calculate_got_entry_vma (struct elf_link_hash_entry *h,
4167 struct elf_aarch64_link_hash_table
4168 *globals, struct bfd_link_info *info,
4169 bfd_vma value, bfd *output_bfd,
4170 bfd_boolean *unresolved_reloc_p)
4172 bfd_vma off = (bfd_vma) - 1;
4173 asection *basegot = globals->root.sgot;
4174 bfd_boolean dyn = globals->root.dynamic_sections_created;
4178 BFD_ASSERT (basegot != NULL);
4179 off = h->got.offset;
4180 BFD_ASSERT (off != (bfd_vma) - 1);
4181 if (!WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, bfd_link_pic (info), h)
4182 || (bfd_link_pic (info)
4183 && SYMBOL_REFERENCES_LOCAL (info, h))
4184 || (ELF_ST_VISIBILITY (h->other)
4185 && h->root.type == bfd_link_hash_undefweak))
4187 /* This is actually a static link, or it is a -Bsymbolic link
4188 and the symbol is defined locally. We must initialize this
4189 entry in the global offset table. Since the offset must
4190 always be a multiple of 8 (4 in the case of ILP32), we use
4191 the least significant bit to record whether we have
4192 initialized it already.
4193 When doing a dynamic link, we create a .rel(a).got relocation
4194 entry to initialize the value. This is done in the
4195 finish_dynamic_symbol routine. */
4200 bfd_put_NN (output_bfd, value, basegot->contents + off);
4205 *unresolved_reloc_p = FALSE;
4207 off = off + basegot->output_section->vma + basegot->output_offset;
4213 /* Change R_TYPE to a more efficient access model where possible,
4214 return the new reloc type. */
4216 static bfd_reloc_code_real_type
4217 aarch64_tls_transition_without_check (bfd_reloc_code_real_type r_type,
4218 struct elf_link_hash_entry *h)
4220 bfd_boolean is_local = h == NULL;
4224 case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21:
4225 case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21:
4227 ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1
4228 : BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21);
4230 case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21:
4232 ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC
4235 case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19:
4237 ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1
4238 : BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19);
4240 case BFD_RELOC_AARCH64_TLSDESC_LDNN_LO12_NC:
4241 case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC:
4243 ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC
4244 : BFD_RELOC_AARCH64_TLSIE_LDNN_GOTTPREL_LO12_NC);
4246 case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21:
4247 return is_local ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1 : r_type;
4249 case BFD_RELOC_AARCH64_TLSIE_LDNN_GOTTPREL_LO12_NC:
4250 return is_local ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC : r_type;
4252 case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19:
4255 case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21:
4257 ? BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_HI12
4258 : BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19);
4260 case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12_NC:
4261 case BFD_RELOC_AARCH64_TLSDESC_CALL:
4262 /* Instructions with these relocations will become NOPs. */
4263 return BFD_RELOC_AARCH64_NONE;
4273 aarch64_reloc_got_type (bfd_reloc_code_real_type r_type)
4277 case BFD_RELOC_AARCH64_ADR_GOT_PAGE:
4278 case BFD_RELOC_AARCH64_GOT_LD_PREL19:
4279 case BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14:
4280 case BFD_RELOC_AARCH64_LD32_GOT_LO12_NC:
4281 case BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15:
4282 case BFD_RELOC_AARCH64_LD64_GOT_LO12_NC:
4285 case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC:
4286 case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21:
4287 case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21:
4288 case BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC:
4289 case BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21:
4290 case BFD_RELOC_AARCH64_TLSLD_ADR_PREL21:
4293 case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12_NC:
4294 case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21:
4295 case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21:
4296 case BFD_RELOC_AARCH64_TLSDESC_CALL:
4297 case BFD_RELOC_AARCH64_TLSDESC_LD32_LO12_NC:
4298 case BFD_RELOC_AARCH64_TLSDESC_LD64_LO12_NC:
4299 case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19:
4300 return GOT_TLSDESC_GD;
4302 case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21:
4303 case BFD_RELOC_AARCH64_TLSIE_LD32_GOTTPREL_LO12_NC:
4304 case BFD_RELOC_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC:
4305 case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19:
4315 aarch64_can_relax_tls (bfd *input_bfd,
4316 struct bfd_link_info *info,
4317 bfd_reloc_code_real_type r_type,
4318 struct elf_link_hash_entry *h,
4319 unsigned long r_symndx)
4321 unsigned int symbol_got_type;
4322 unsigned int reloc_got_type;
4324 if (! IS_AARCH64_TLS_RELAX_RELOC (r_type))
4327 symbol_got_type = elfNN_aarch64_symbol_got_type (h, input_bfd, r_symndx);
4328 reloc_got_type = aarch64_reloc_got_type (r_type);
4330 if (symbol_got_type == GOT_TLS_IE && GOT_TLS_GD_ANY_P (reloc_got_type))
4333 if (bfd_link_pic (info))
4336 if (h && h->root.type == bfd_link_hash_undefweak)
4342 /* Given the relocation code R_TYPE, return the relaxed bfd reloc
4345 static bfd_reloc_code_real_type
4346 aarch64_tls_transition (bfd *input_bfd,
4347 struct bfd_link_info *info,
4348 unsigned int r_type,
4349 struct elf_link_hash_entry *h,
4350 unsigned long r_symndx)
4352 bfd_reloc_code_real_type bfd_r_type
4353 = elfNN_aarch64_bfd_reloc_from_type (r_type);
4355 if (! aarch64_can_relax_tls (input_bfd, info, bfd_r_type, h, r_symndx))
4358 return aarch64_tls_transition_without_check (bfd_r_type, h);
4361 /* Return the base VMA address which should be subtracted from real addresses
4362 when resolving R_AARCH64_TLS_DTPREL relocation. */
4365 dtpoff_base (struct bfd_link_info *info)
4367 /* If tls_sec is NULL, we should have signalled an error already. */
4368 BFD_ASSERT (elf_hash_table (info)->tls_sec != NULL);
4369 return elf_hash_table (info)->tls_sec->vma;
4372 /* Return the base VMA address which should be subtracted from real addresses
4373 when resolving R_AARCH64_TLS_GOTTPREL64 relocations. */
4376 tpoff_base (struct bfd_link_info *info)
4378 struct elf_link_hash_table *htab = elf_hash_table (info);
4380 /* If tls_sec is NULL, we should have signalled an error already. */
4381 BFD_ASSERT (htab->tls_sec != NULL);
4383 bfd_vma base = align_power ((bfd_vma) TCB_SIZE,
4384 htab->tls_sec->alignment_power);
4385 return htab->tls_sec->vma - base;
4389 symbol_got_offset_ref (bfd *input_bfd, struct elf_link_hash_entry *h,
4390 unsigned long r_symndx)
4392 /* Calculate the address of the GOT entry for symbol
4393 referred to in h. */
4395 return &h->got.offset;
4399 struct elf_aarch64_local_symbol *l;
4401 l = elf_aarch64_locals (input_bfd);
4402 return &l[r_symndx].got_offset;
4407 symbol_got_offset_mark (bfd *input_bfd, struct elf_link_hash_entry *h,
4408 unsigned long r_symndx)
4411 p = symbol_got_offset_ref (input_bfd, h, r_symndx);
4416 symbol_got_offset_mark_p (bfd *input_bfd, struct elf_link_hash_entry *h,
4417 unsigned long r_symndx)
4420 value = * symbol_got_offset_ref (input_bfd, h, r_symndx);
4425 symbol_got_offset (bfd *input_bfd, struct elf_link_hash_entry *h,
4426 unsigned long r_symndx)
4429 value = * symbol_got_offset_ref (input_bfd, h, r_symndx);
4435 symbol_tlsdesc_got_offset_ref (bfd *input_bfd, struct elf_link_hash_entry *h,
4436 unsigned long r_symndx)
4438 /* Calculate the address of the GOT entry for symbol
4439 referred to in h. */
4442 struct elf_aarch64_link_hash_entry *eh;
4443 eh = (struct elf_aarch64_link_hash_entry *) h;
4444 return &eh->tlsdesc_got_jump_table_offset;
4449 struct elf_aarch64_local_symbol *l;
4451 l = elf_aarch64_locals (input_bfd);
4452 return &l[r_symndx].tlsdesc_got_jump_table_offset;
4457 symbol_tlsdesc_got_offset_mark (bfd *input_bfd, struct elf_link_hash_entry *h,
4458 unsigned long r_symndx)
4461 p = symbol_tlsdesc_got_offset_ref (input_bfd, h, r_symndx);
4466 symbol_tlsdesc_got_offset_mark_p (bfd *input_bfd,
4467 struct elf_link_hash_entry *h,
4468 unsigned long r_symndx)
4471 value = * symbol_tlsdesc_got_offset_ref (input_bfd, h, r_symndx);
4476 symbol_tlsdesc_got_offset (bfd *input_bfd, struct elf_link_hash_entry *h,
4477 unsigned long r_symndx)
4480 value = * symbol_tlsdesc_got_offset_ref (input_bfd, h, r_symndx);
4485 /* Data for make_branch_to_erratum_835769_stub(). */
4487 struct erratum_835769_branch_to_stub_data
4489 struct bfd_link_info *info;
4490 asection *output_section;
4494 /* Helper to insert branches to erratum 835769 stubs in the right
4495 places for a particular section. */
4498 make_branch_to_erratum_835769_stub (struct bfd_hash_entry *gen_entry,
4501 struct elf_aarch64_stub_hash_entry *stub_entry;
4502 struct erratum_835769_branch_to_stub_data *data;
4504 unsigned long branch_insn = 0;
4505 bfd_vma veneered_insn_loc, veneer_entry_loc;
4506 bfd_signed_vma branch_offset;
4507 unsigned int target;
4510 stub_entry = (struct elf_aarch64_stub_hash_entry *) gen_entry;
4511 data = (struct erratum_835769_branch_to_stub_data *) in_arg;
4513 if (stub_entry->target_section != data->output_section
4514 || stub_entry->stub_type != aarch64_stub_erratum_835769_veneer)
4517 contents = data->contents;
4518 veneered_insn_loc = stub_entry->target_section->output_section->vma
4519 + stub_entry->target_section->output_offset
4520 + stub_entry->target_value;
4521 veneer_entry_loc = stub_entry->stub_sec->output_section->vma
4522 + stub_entry->stub_sec->output_offset
4523 + stub_entry->stub_offset;
4524 branch_offset = veneer_entry_loc - veneered_insn_loc;
4526 abfd = stub_entry->target_section->owner;
4527 if (!aarch64_valid_branch_p (veneer_entry_loc, veneered_insn_loc))
4528 (*_bfd_error_handler)
4529 (_("%B: error: Erratum 835769 stub out "
4530 "of range (input file too large)"), abfd);
4532 target = stub_entry->target_value;
4533 branch_insn = 0x14000000;
4534 branch_offset >>= 2;
4535 branch_offset &= 0x3ffffff;
4536 branch_insn |= branch_offset;
4537 bfd_putl32 (branch_insn, &contents[target]);
4544 _bfd_aarch64_erratum_843419_branch_to_stub (struct bfd_hash_entry *gen_entry,
4547 struct elf_aarch64_stub_hash_entry *stub_entry
4548 = (struct elf_aarch64_stub_hash_entry *) gen_entry;
4549 struct erratum_835769_branch_to_stub_data *data
4550 = (struct erratum_835769_branch_to_stub_data *) in_arg;
4551 struct bfd_link_info *info;
4552 struct elf_aarch64_link_hash_table *htab;
4560 contents = data->contents;
4561 section = data->output_section;
4563 htab = elf_aarch64_hash_table (info);
4565 if (stub_entry->target_section != section
4566 || stub_entry->stub_type != aarch64_stub_erratum_843419_veneer)
4569 insn = bfd_getl32 (contents + stub_entry->target_value);
4571 stub_entry->stub_sec->contents + stub_entry->stub_offset);
4573 place = (section->output_section->vma + section->output_offset
4574 + stub_entry->adrp_offset);
4575 insn = bfd_getl32 (contents + stub_entry->adrp_offset);
4577 if ((insn & AARCH64_ADRP_OP_MASK) != AARCH64_ADRP_OP)
4580 bfd_signed_vma imm =
4581 (_bfd_aarch64_sign_extend
4582 ((bfd_vma) _bfd_aarch64_decode_adrp_imm (insn) << 12, 33)
4585 if (htab->fix_erratum_843419_adr
4586 && (imm >= AARCH64_MIN_ADRP_IMM && imm <= AARCH64_MAX_ADRP_IMM))
4588 insn = (_bfd_aarch64_reencode_adr_imm (AARCH64_ADR_OP, imm)
4589 | AARCH64_RT (insn));
4590 bfd_putl32 (insn, contents + stub_entry->adrp_offset);
4594 bfd_vma veneered_insn_loc;
4595 bfd_vma veneer_entry_loc;
4596 bfd_signed_vma branch_offset;
4597 uint32_t branch_insn;
4599 veneered_insn_loc = stub_entry->target_section->output_section->vma
4600 + stub_entry->target_section->output_offset
4601 + stub_entry->target_value;
4602 veneer_entry_loc = stub_entry->stub_sec->output_section->vma
4603 + stub_entry->stub_sec->output_offset
4604 + stub_entry->stub_offset;
4605 branch_offset = veneer_entry_loc - veneered_insn_loc;
4607 abfd = stub_entry->target_section->owner;
4608 if (!aarch64_valid_branch_p (veneer_entry_loc, veneered_insn_loc))
4609 (*_bfd_error_handler)
4610 (_("%B: error: Erratum 843419 stub out "
4611 "of range (input file too large)"), abfd);
4613 branch_insn = 0x14000000;
4614 branch_offset >>= 2;
4615 branch_offset &= 0x3ffffff;
4616 branch_insn |= branch_offset;
4617 bfd_putl32 (branch_insn, contents + stub_entry->target_value);
4624 elfNN_aarch64_write_section (bfd *output_bfd ATTRIBUTE_UNUSED,
4625 struct bfd_link_info *link_info,
4630 struct elf_aarch64_link_hash_table *globals =
4631 elf_aarch64_hash_table (link_info);
4633 if (globals == NULL)
4636 /* Fix code to point to erratum 835769 stubs. */
4637 if (globals->fix_erratum_835769)
4639 struct erratum_835769_branch_to_stub_data data;
4641 data.info = link_info;
4642 data.output_section = sec;
4643 data.contents = contents;
4644 bfd_hash_traverse (&globals->stub_hash_table,
4645 make_branch_to_erratum_835769_stub, &data);
4648 if (globals->fix_erratum_843419)
4650 struct erratum_835769_branch_to_stub_data data;
4652 data.info = link_info;
4653 data.output_section = sec;
4654 data.contents = contents;
4655 bfd_hash_traverse (&globals->stub_hash_table,
4656 _bfd_aarch64_erratum_843419_branch_to_stub, &data);
4662 /* Perform a relocation as part of a final link. */
4663 static bfd_reloc_status_type
4664 elfNN_aarch64_final_link_relocate (reloc_howto_type *howto,
4667 asection *input_section,
4669 Elf_Internal_Rela *rel,
4671 struct bfd_link_info *info,
4673 struct elf_link_hash_entry *h,
4674 bfd_boolean *unresolved_reloc_p,
4675 bfd_boolean save_addend,
4676 bfd_vma *saved_addend,
4677 Elf_Internal_Sym *sym)
4679 Elf_Internal_Shdr *symtab_hdr;
4680 unsigned int r_type = howto->type;
4681 bfd_reloc_code_real_type bfd_r_type
4682 = elfNN_aarch64_bfd_reloc_from_howto (howto);
4683 bfd_reloc_code_real_type new_bfd_r_type;
4684 unsigned long r_symndx;
4685 bfd_byte *hit_data = contents + rel->r_offset;
4687 bfd_signed_vma signed_addend;
4688 struct elf_aarch64_link_hash_table *globals;
4689 bfd_boolean weak_undef_p;
4692 globals = elf_aarch64_hash_table (info);
4694 symtab_hdr = &elf_symtab_hdr (input_bfd);
4696 BFD_ASSERT (is_aarch64_elf (input_bfd));
4698 r_symndx = ELFNN_R_SYM (rel->r_info);
4700 /* It is possible to have linker relaxations on some TLS access
4701 models. Update our information here. */
4702 new_bfd_r_type = aarch64_tls_transition (input_bfd, info, r_type, h, r_symndx);
4703 if (new_bfd_r_type != bfd_r_type)
4705 bfd_r_type = new_bfd_r_type;
4706 howto = elfNN_aarch64_howto_from_bfd_reloc (bfd_r_type);
4707 BFD_ASSERT (howto != NULL);
4708 r_type = howto->type;
4711 place = input_section->output_section->vma
4712 + input_section->output_offset + rel->r_offset;
4714 /* Get addend, accumulating the addend for consecutive relocs
4715 which refer to the same offset. */
4716 signed_addend = saved_addend ? *saved_addend : 0;
4717 signed_addend += rel->r_addend;
4719 weak_undef_p = (h ? h->root.type == bfd_link_hash_undefweak
4720 : bfd_is_und_section (sym_sec));
4722 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle
4723 it here if it is defined in a non-shared object. */
4725 && h->type == STT_GNU_IFUNC
4732 if ((input_section->flags & SEC_ALLOC) == 0
4733 || h->plt.offset == (bfd_vma) -1)
4736 /* STT_GNU_IFUNC symbol must go through PLT. */
4737 plt = globals->root.splt ? globals->root.splt : globals->root.iplt;
4738 value = (plt->output_section->vma + plt->output_offset + h->plt.offset);
4743 if (h->root.root.string)
4744 name = h->root.root.string;
4746 name = bfd_elf_sym_name (input_bfd, symtab_hdr, sym,
4748 (*_bfd_error_handler)
4749 (_("%B: relocation %s against STT_GNU_IFUNC "
4750 "symbol `%s' isn't handled by %s"), input_bfd,
4751 howto->name, name, __FUNCTION__);
4752 bfd_set_error (bfd_error_bad_value);
4755 case BFD_RELOC_AARCH64_NN:
4756 if (rel->r_addend != 0)
4758 if (h->root.root.string)
4759 name = h->root.root.string;
4761 name = bfd_elf_sym_name (input_bfd, symtab_hdr,
4763 (*_bfd_error_handler)
4764 (_("%B: relocation %s against STT_GNU_IFUNC "
4765 "symbol `%s' has non-zero addend: %d"),
4766 input_bfd, howto->name, name, rel->r_addend);
4767 bfd_set_error (bfd_error_bad_value);
4771 /* Generate dynamic relocation only when there is a
4772 non-GOT reference in a shared object. */
4773 if (bfd_link_pic (info) && h->non_got_ref)
4775 Elf_Internal_Rela outrel;
4778 /* Need a dynamic relocation to get the real function
4780 outrel.r_offset = _bfd_elf_section_offset (output_bfd,
4784 if (outrel.r_offset == (bfd_vma) -1
4785 || outrel.r_offset == (bfd_vma) -2)
4788 outrel.r_offset += (input_section->output_section->vma
4789 + input_section->output_offset);
4791 if (h->dynindx == -1
4793 || bfd_link_executable (info))
4795 /* This symbol is resolved locally. */
4796 outrel.r_info = ELFNN_R_INFO (0, AARCH64_R (IRELATIVE));
4797 outrel.r_addend = (h->root.u.def.value
4798 + h->root.u.def.section->output_section->vma
4799 + h->root.u.def.section->output_offset);
4803 outrel.r_info = ELFNN_R_INFO (h->dynindx, r_type);
4804 outrel.r_addend = 0;
4807 sreloc = globals->root.irelifunc;
4808 elf_append_rela (output_bfd, sreloc, &outrel);
4810 /* If this reloc is against an external symbol, we
4811 do not want to fiddle with the addend. Otherwise,
4812 we need to include the symbol value so that it
4813 becomes an addend for the dynamic reloc. For an
4814 internal symbol, we have updated addend. */
4815 return bfd_reloc_ok;
4818 case BFD_RELOC_AARCH64_CALL26:
4819 case BFD_RELOC_AARCH64_JUMP26:
4820 value = _bfd_aarch64_elf_resolve_relocation (bfd_r_type, place, value,
4823 return _bfd_aarch64_elf_put_addend (input_bfd, hit_data, bfd_r_type,
4825 case BFD_RELOC_AARCH64_ADR_GOT_PAGE:
4826 case BFD_RELOC_AARCH64_GOT_LD_PREL19:
4827 case BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14:
4828 case BFD_RELOC_AARCH64_LD32_GOT_LO12_NC:
4829 case BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15:
4830 case BFD_RELOC_AARCH64_LD64_GOT_LO12_NC:
4831 base_got = globals->root.sgot;
4832 off = h->got.offset;
4834 if (base_got == NULL)
4837 if (off == (bfd_vma) -1)
4841 /* We can't use h->got.offset here to save state, or
4842 even just remember the offset, as finish_dynamic_symbol
4843 would use that as offset into .got. */
4845 if (globals->root.splt != NULL)
4847 plt_index = ((h->plt.offset - globals->plt_header_size) /
4848 globals->plt_entry_size);
4849 off = (plt_index + 3) * GOT_ENTRY_SIZE;
4850 base_got = globals->root.sgotplt;
4854 plt_index = h->plt.offset / globals->plt_entry_size;
4855 off = plt_index * GOT_ENTRY_SIZE;
4856 base_got = globals->root.igotplt;
4859 if (h->dynindx == -1
4863 /* This references the local definition. We must
4864 initialize this entry in the global offset table.
4865 Since the offset must always be a multiple of 8,
4866 we use the least significant bit to record
4867 whether we have initialized it already.
4869 When doing a dynamic link, we create a .rela.got
4870 relocation entry to initialize the value. This
4871 is done in the finish_dynamic_symbol routine. */
4876 bfd_put_NN (output_bfd, value,
4877 base_got->contents + off);
4878 /* Note that this is harmless as -1 | 1 still is -1. */
4882 value = (base_got->output_section->vma
4883 + base_got->output_offset + off);
4886 value = aarch64_calculate_got_entry_vma (h, globals, info,
4888 unresolved_reloc_p);
4889 if (bfd_r_type == BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15
4890 || bfd_r_type == BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14)
4891 addend = (globals->root.sgot->output_section->vma
4892 + globals->root.sgot->output_offset);
4893 value = _bfd_aarch64_elf_resolve_relocation (bfd_r_type, place, value,
4894 addend, weak_undef_p);
4895 return _bfd_aarch64_elf_put_addend (input_bfd, hit_data, bfd_r_type, howto, value);
4896 case BFD_RELOC_AARCH64_ADD_LO12:
4897 case BFD_RELOC_AARCH64_ADR_HI21_PCREL:
4904 case BFD_RELOC_AARCH64_NONE:
4905 case BFD_RELOC_AARCH64_TLSDESC_CALL:
4906 *unresolved_reloc_p = FALSE;
4907 return bfd_reloc_ok;
4909 case BFD_RELOC_AARCH64_NN:
4911 /* When generating a shared object or relocatable executable, these
4912 relocations are copied into the output file to be resolved at
4914 if (((bfd_link_pic (info) == TRUE)
4915 || globals->root.is_relocatable_executable)
4916 && (input_section->flags & SEC_ALLOC)
4918 || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
4919 || h->root.type != bfd_link_hash_undefweak))
4921 Elf_Internal_Rela outrel;
4923 bfd_boolean skip, relocate;
4926 *unresolved_reloc_p = FALSE;
4931 outrel.r_addend = signed_addend;
4933 _bfd_elf_section_offset (output_bfd, info, input_section,
4935 if (outrel.r_offset == (bfd_vma) - 1)
4937 else if (outrel.r_offset == (bfd_vma) - 2)
4943 outrel.r_offset += (input_section->output_section->vma
4944 + input_section->output_offset);
4947 memset (&outrel, 0, sizeof outrel);
4950 && (!bfd_link_pic (info)
4951 || !SYMBOLIC_BIND (info, h)
4952 || !h->def_regular))
4953 outrel.r_info = ELFNN_R_INFO (h->dynindx, r_type);
4958 /* On SVR4-ish systems, the dynamic loader cannot
4959 relocate the text and data segments independently,
4960 so the symbol does not matter. */
4962 outrel.r_info = ELFNN_R_INFO (symbol, AARCH64_R (RELATIVE));
4963 outrel.r_addend += value;
4966 sreloc = elf_section_data (input_section)->sreloc;
4967 if (sreloc == NULL || sreloc->contents == NULL)
4968 return bfd_reloc_notsupported;
4970 loc = sreloc->contents + sreloc->reloc_count++ * RELOC_SIZE (globals);
4971 bfd_elfNN_swap_reloca_out (output_bfd, &outrel, loc);
4973 if (sreloc->reloc_count * RELOC_SIZE (globals) > sreloc->size)
4975 /* Sanity to check that we have previously allocated
4976 sufficient space in the relocation section for the
4977 number of relocations we actually want to emit. */
4981 /* If this reloc is against an external symbol, we do not want to
4982 fiddle with the addend. Otherwise, we need to include the symbol
4983 value so that it becomes an addend for the dynamic reloc. */
4985 return bfd_reloc_ok;
4987 return _bfd_final_link_relocate (howto, input_bfd, input_section,
4988 contents, rel->r_offset, value,
4992 value += signed_addend;
4995 case BFD_RELOC_AARCH64_CALL26:
4996 case BFD_RELOC_AARCH64_JUMP26:
4998 asection *splt = globals->root.splt;
4999 bfd_boolean via_plt_p =
5000 splt != NULL && h != NULL && h->plt.offset != (bfd_vma) - 1;
5002 /* A call to an undefined weak symbol is converted to a jump to
5003 the next instruction unless a PLT entry will be created.
5004 The jump to the next instruction is optimized as a NOP.
5005 Do the same for local undefined symbols. */
5006 if (weak_undef_p && ! via_plt_p)
5008 bfd_putl32 (INSN_NOP, hit_data);
5009 return bfd_reloc_ok;
5012 /* If the call goes through a PLT entry, make sure to
5013 check distance to the right destination address. */
5015 value = (splt->output_section->vma
5016 + splt->output_offset + h->plt.offset);
5018 /* Check if a stub has to be inserted because the destination
5020 struct elf_aarch64_stub_hash_entry *stub_entry = NULL;
5021 if (! aarch64_valid_branch_p (value, place))
5022 /* The target is out of reach, so redirect the branch to
5023 the local stub for this function. */
5024 stub_entry = elfNN_aarch64_get_stub_entry (input_section, sym_sec, h,
5026 if (stub_entry != NULL)
5027 value = (stub_entry->stub_offset
5028 + stub_entry->stub_sec->output_offset
5029 + stub_entry->stub_sec->output_section->vma);
5031 value = _bfd_aarch64_elf_resolve_relocation (bfd_r_type, place, value,
5032 signed_addend, weak_undef_p);
5033 *unresolved_reloc_p = FALSE;
5036 case BFD_RELOC_AARCH64_16_PCREL:
5037 case BFD_RELOC_AARCH64_32_PCREL:
5038 case BFD_RELOC_AARCH64_64_PCREL:
5039 case BFD_RELOC_AARCH64_ADR_HI21_NC_PCREL:
5040 case BFD_RELOC_AARCH64_ADR_HI21_PCREL:
5041 case BFD_RELOC_AARCH64_ADR_LO21_PCREL:
5042 case BFD_RELOC_AARCH64_LD_LO19_PCREL:
5043 if (bfd_link_pic (info)
5044 && (input_section->flags & SEC_ALLOC) != 0
5045 && (input_section->flags & SEC_READONLY) != 0
5049 int howto_index = bfd_r_type - BFD_RELOC_AARCH64_RELOC_START;
5051 (*_bfd_error_handler)
5052 (_("%B: relocation %s against external symbol `%s' can not be used"
5053 " when making a shared object; recompile with -fPIC"),
5054 input_bfd, elfNN_aarch64_howto_table[howto_index].name,
5055 h->root.root.string);
5056 bfd_set_error (bfd_error_bad_value);
5060 case BFD_RELOC_AARCH64_16:
5062 case BFD_RELOC_AARCH64_32:
5064 case BFD_RELOC_AARCH64_ADD_LO12:
5065 case BFD_RELOC_AARCH64_BRANCH19:
5066 case BFD_RELOC_AARCH64_LDST128_LO12:
5067 case BFD_RELOC_AARCH64_LDST16_LO12:
5068 case BFD_RELOC_AARCH64_LDST32_LO12:
5069 case BFD_RELOC_AARCH64_LDST64_LO12:
5070 case BFD_RELOC_AARCH64_LDST8_LO12:
5071 case BFD_RELOC_AARCH64_MOVW_G0:
5072 case BFD_RELOC_AARCH64_MOVW_G0_NC:
5073 case BFD_RELOC_AARCH64_MOVW_G0_S:
5074 case BFD_RELOC_AARCH64_MOVW_G1:
5075 case BFD_RELOC_AARCH64_MOVW_G1_NC:
5076 case BFD_RELOC_AARCH64_MOVW_G1_S:
5077 case BFD_RELOC_AARCH64_MOVW_G2:
5078 case BFD_RELOC_AARCH64_MOVW_G2_NC:
5079 case BFD_RELOC_AARCH64_MOVW_G2_S:
5080 case BFD_RELOC_AARCH64_MOVW_G3:
5081 case BFD_RELOC_AARCH64_TSTBR14:
5082 value = _bfd_aarch64_elf_resolve_relocation (bfd_r_type, place, value,
5083 signed_addend, weak_undef_p);
5086 case BFD_RELOC_AARCH64_ADR_GOT_PAGE:
5087 case BFD_RELOC_AARCH64_GOT_LD_PREL19:
5088 case BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14:
5089 case BFD_RELOC_AARCH64_LD32_GOT_LO12_NC:
5090 case BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15:
5091 case BFD_RELOC_AARCH64_LD64_GOT_LO12_NC:
5092 if (globals->root.sgot == NULL)
5093 BFD_ASSERT (h != NULL);
5098 value = aarch64_calculate_got_entry_vma (h, globals, info, value,
5100 unresolved_reloc_p);
5101 if (bfd_r_type == BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15
5102 || bfd_r_type == BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14)
5103 addend = (globals->root.sgot->output_section->vma
5104 + globals->root.sgot->output_offset);
5105 value = _bfd_aarch64_elf_resolve_relocation (bfd_r_type, place, value,
5106 addend, weak_undef_p);
5111 struct elf_aarch64_local_symbol *locals
5112 = elf_aarch64_locals (input_bfd);
5116 int howto_index = bfd_r_type - BFD_RELOC_AARCH64_RELOC_START;
5117 (*_bfd_error_handler)
5118 (_("%B: Local symbol descriptor table be NULL when applying "
5119 "relocation %s against local symbol"),
5120 input_bfd, elfNN_aarch64_howto_table[howto_index].name);
5124 off = symbol_got_offset (input_bfd, h, r_symndx);
5125 base_got = globals->root.sgot;
5126 bfd_vma got_entry_addr = (base_got->output_section->vma
5127 + base_got->output_offset + off);
5129 if (!symbol_got_offset_mark_p (input_bfd, h, r_symndx))
5131 bfd_put_64 (output_bfd, value, base_got->contents + off);
5133 if (bfd_link_pic (info))
5136 Elf_Internal_Rela outrel;
5138 /* For local symbol, we have done absolute relocation in static
5139 linking stageh. While for share library, we need to update
5140 the content of GOT entry according to the share objects
5141 loading base address. So we need to generate a
5142 R_AARCH64_RELATIVE reloc for dynamic linker. */
5143 s = globals->root.srelgot;
5147 outrel.r_offset = got_entry_addr;
5148 outrel.r_info = ELFNN_R_INFO (0, AARCH64_R (RELATIVE));
5149 outrel.r_addend = value;
5150 elf_append_rela (output_bfd, s, &outrel);
5153 symbol_got_offset_mark (input_bfd, h, r_symndx);
5156 /* Update the relocation value to GOT entry addr as we have transformed
5157 the direct data access into indirect data access through GOT. */
5158 value = got_entry_addr;
5160 if (bfd_r_type == BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15
5161 || bfd_r_type == BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14)
5162 addend = base_got->output_section->vma + base_got->output_offset;
5164 value = _bfd_aarch64_elf_resolve_relocation (bfd_r_type, place, value,
5165 addend, weak_undef_p);
5170 case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC:
5171 case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21:
5172 case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21:
5173 case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21:
5174 case BFD_RELOC_AARCH64_TLSIE_LD32_GOTTPREL_LO12_NC:
5175 case BFD_RELOC_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC:
5176 case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19:
5177 case BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC:
5178 case BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21:
5179 case BFD_RELOC_AARCH64_TLSLD_ADR_PREL21:
5180 if (globals->root.sgot == NULL)
5181 return bfd_reloc_notsupported;
5183 value = (symbol_got_offset (input_bfd, h, r_symndx)
5184 + globals->root.sgot->output_section->vma
5185 + globals->root.sgot->output_offset);
5187 value = _bfd_aarch64_elf_resolve_relocation (bfd_r_type, place, value,
5189 *unresolved_reloc_p = FALSE;
5192 case BFD_RELOC_AARCH64_TLSLD_ADD_DTPREL_HI12:
5193 case BFD_RELOC_AARCH64_TLSLD_ADD_DTPREL_LO12:
5194 case BFD_RELOC_AARCH64_TLSLD_ADD_DTPREL_LO12_NC:
5195 case BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G0:
5196 case BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G0_NC:
5197 case BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G1:
5198 case BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G1_NC:
5199 case BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G2:
5200 value = _bfd_aarch64_elf_resolve_relocation (bfd_r_type, place, value,
5201 signed_addend - dtpoff_base (info),
5205 case BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_HI12:
5206 case BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_LO12:
5207 case BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_LO12_NC:
5208 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0:
5209 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC:
5210 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1:
5211 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1_NC:
5212 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G2:
5213 value = _bfd_aarch64_elf_resolve_relocation (bfd_r_type, place, value,
5214 signed_addend - tpoff_base (info),
5216 *unresolved_reloc_p = FALSE;
5219 case BFD_RELOC_AARCH64_TLSDESC_ADD:
5220 case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12_NC:
5221 case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21:
5222 case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21:
5223 case BFD_RELOC_AARCH64_TLSDESC_LD32_LO12_NC:
5224 case BFD_RELOC_AARCH64_TLSDESC_LD64_LO12_NC:
5225 case BFD_RELOC_AARCH64_TLSDESC_LDR:
5226 case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19:
5227 if (globals->root.sgot == NULL)
5228 return bfd_reloc_notsupported;
5229 value = (symbol_tlsdesc_got_offset (input_bfd, h, r_symndx)
5230 + globals->root.sgotplt->output_section->vma
5231 + globals->root.sgotplt->output_offset
5232 + globals->sgotplt_jump_table_size);
5234 value = _bfd_aarch64_elf_resolve_relocation (bfd_r_type, place, value,
5236 *unresolved_reloc_p = FALSE;
5240 return bfd_reloc_notsupported;
5244 *saved_addend = value;
5246 /* Only apply the final relocation in a sequence. */
5248 return bfd_reloc_continue;
5250 return _bfd_aarch64_elf_put_addend (input_bfd, hit_data, bfd_r_type,
5254 /* Handle TLS relaxations. Relaxing is possible for symbols that use
5255 R_AARCH64_TLSDESC_ADR_{PAGE, LD64_LO12_NC, ADD_LO12_NC} during a static
5258 Return bfd_reloc_ok if we're done, bfd_reloc_continue if the caller
5259 is to then call final_link_relocate. Return other values in the
5262 static bfd_reloc_status_type
5263 elfNN_aarch64_tls_relax (struct elf_aarch64_link_hash_table *globals,
5264 bfd *input_bfd, bfd_byte *contents,
5265 Elf_Internal_Rela *rel, struct elf_link_hash_entry *h)
5267 bfd_boolean is_local = h == NULL;
5268 unsigned int r_type = ELFNN_R_TYPE (rel->r_info);
5271 BFD_ASSERT (globals && input_bfd && contents && rel);
5273 switch (elfNN_aarch64_bfd_reloc_from_type (r_type))
5275 case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21:
5276 case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21:
5279 /* GD->LE relaxation:
5280 adrp x0, :tlsgd:var => movz x0, :tprel_g1:var
5282 adrp x0, :tlsdesc:var => movz x0, :tprel_g1:var
5284 bfd_putl32 (0xd2a00000, contents + rel->r_offset);
5285 return bfd_reloc_continue;
5289 /* GD->IE relaxation:
5290 adrp x0, :tlsgd:var => adrp x0, :gottprel:var
5292 adrp x0, :tlsdesc:var => adrp x0, :gottprel:var
5294 return bfd_reloc_continue;
5297 case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21:
5301 case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19:
5304 /* Tiny TLSDESC->LE relaxation:
5305 ldr x1, :tlsdesc:var => movz x0, #:tprel_g1:var
5306 adr x0, :tlsdesc:var => movk x0, #:tprel_g0_nc:var
5310 BFD_ASSERT (ELFNN_R_TYPE (rel[1].r_info) == AARCH64_R (TLSDESC_ADR_PREL21));
5311 BFD_ASSERT (ELFNN_R_TYPE (rel[2].r_info) == AARCH64_R (TLSDESC_CALL));
5313 rel[1].r_info = ELFNN_R_INFO (ELFNN_R_SYM (rel->r_info),
5314 AARCH64_R (TLSLE_MOVW_TPREL_G0_NC));
5315 rel[2].r_info = ELFNN_R_INFO (STN_UNDEF, R_AARCH64_NONE);
5317 bfd_putl32 (0xd2a00000, contents + rel->r_offset);
5318 bfd_putl32 (0xf2800000, contents + rel->r_offset + 4);
5319 bfd_putl32 (INSN_NOP, contents + rel->r_offset + 8);
5320 return bfd_reloc_continue;
5324 /* Tiny TLSDESC->IE relaxation:
5325 ldr x1, :tlsdesc:var => ldr x0, :gottprel:var
5326 adr x0, :tlsdesc:var => nop
5330 BFD_ASSERT (ELFNN_R_TYPE (rel[1].r_info) == AARCH64_R (TLSDESC_ADR_PREL21));
5331 BFD_ASSERT (ELFNN_R_TYPE (rel[2].r_info) == AARCH64_R (TLSDESC_CALL));
5333 rel[1].r_info = ELFNN_R_INFO (STN_UNDEF, R_AARCH64_NONE);
5334 rel[2].r_info = ELFNN_R_INFO (STN_UNDEF, R_AARCH64_NONE);
5336 bfd_putl32 (0x58000000, contents + rel->r_offset);
5337 bfd_putl32 (INSN_NOP, contents + rel->r_offset + 4);
5338 bfd_putl32 (INSN_NOP, contents + rel->r_offset + 8);
5339 return bfd_reloc_continue;
5342 case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21:
5345 /* Tiny GD->LE relaxation:
5346 adr x0, :tlsgd:var => mrs x1, tpidr_el0
5347 bl __tls_get_addr => add x0, x1, #:tprel_hi12:x, lsl #12
5348 nop => add x0, x0, #:tprel_lo12_nc:x
5351 /* First kill the tls_get_addr reloc on the bl instruction. */
5352 BFD_ASSERT (rel->r_offset + 4 == rel[1].r_offset);
5354 bfd_putl32 (0xd53bd041, contents + rel->r_offset + 0);
5355 bfd_putl32 (0x91400020, contents + rel->r_offset + 4);
5356 bfd_putl32 (0x91000000, contents + rel->r_offset + 8);
5358 rel[1].r_info = ELFNN_R_INFO (ELFNN_R_SYM (rel->r_info),
5359 AARCH64_R (TLSLE_ADD_TPREL_LO12_NC));
5360 rel[1].r_offset = rel->r_offset + 8;
5362 /* Move the current relocation to the second instruction in
5365 rel->r_info = ELFNN_R_INFO (ELFNN_R_SYM (rel->r_info),
5366 AARCH64_R (TLSLE_ADD_TPREL_HI12));
5367 return bfd_reloc_continue;
5371 /* Tiny GD->IE relaxation:
5372 adr x0, :tlsgd:var => ldr x0, :gottprel:var
5373 bl __tls_get_addr => mrs x1, tpidr_el0
5374 nop => add x0, x0, x1
5377 /* First kill the tls_get_addr reloc on the bl instruction. */
5378 BFD_ASSERT (rel->r_offset + 4 == rel[1].r_offset);
5379 rel[1].r_info = ELFNN_R_INFO (STN_UNDEF, R_AARCH64_NONE);
5381 bfd_putl32 (0x58000000, contents + rel->r_offset);
5382 bfd_putl32 (0xd53bd041, contents + rel->r_offset + 4);
5383 bfd_putl32 (0x8b000020, contents + rel->r_offset + 8);
5384 return bfd_reloc_continue;
5387 case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19:
5388 return bfd_reloc_continue;
5390 case BFD_RELOC_AARCH64_TLSDESC_LDNN_LO12_NC:
5393 /* GD->LE relaxation:
5394 ldr xd, [x0, #:tlsdesc_lo12:var] => movk x0, :tprel_g0_nc:var
5396 bfd_putl32 (0xf2800000, contents + rel->r_offset);
5397 return bfd_reloc_continue;
5401 /* GD->IE relaxation:
5402 ldr xd, [x0, #:tlsdesc_lo12:var] => ldr x0, [x0, #:gottprel_lo12:var]
5404 insn = bfd_getl32 (contents + rel->r_offset);
5406 bfd_putl32 (insn, contents + rel->r_offset);
5407 return bfd_reloc_continue;
5410 case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC:
5413 /* GD->LE relaxation
5414 add x0, #:tlsgd_lo12:var => movk x0, :tprel_g0_nc:var
5415 bl __tls_get_addr => mrs x1, tpidr_el0
5416 nop => add x0, x1, x0
5419 /* First kill the tls_get_addr reloc on the bl instruction. */
5420 BFD_ASSERT (rel->r_offset + 4 == rel[1].r_offset);
5421 rel[1].r_info = ELFNN_R_INFO (STN_UNDEF, R_AARCH64_NONE);
5423 bfd_putl32 (0xf2800000, contents + rel->r_offset);
5424 bfd_putl32 (0xd53bd041, contents + rel->r_offset + 4);
5425 bfd_putl32 (0x8b000020, contents + rel->r_offset + 8);
5426 return bfd_reloc_continue;
5430 /* GD->IE relaxation
5431 ADD x0, #:tlsgd_lo12:var => ldr x0, [x0, #:gottprel_lo12:var]
5432 BL __tls_get_addr => mrs x1, tpidr_el0
5434 NOP => add x0, x1, x0
5437 BFD_ASSERT (ELFNN_R_TYPE (rel[1].r_info) == AARCH64_R (CALL26));
5439 /* Remove the relocation on the BL instruction. */
5440 rel[1].r_info = ELFNN_R_INFO (STN_UNDEF, R_AARCH64_NONE);
5442 bfd_putl32 (0xf9400000, contents + rel->r_offset);
5444 /* We choose to fixup the BL and NOP instructions using the
5445 offset from the second relocation to allow flexibility in
5446 scheduling instructions between the ADD and BL. */
5447 bfd_putl32 (0xd53bd041, contents + rel[1].r_offset);
5448 bfd_putl32 (0x8b000020, contents + rel[1].r_offset + 4);
5449 return bfd_reloc_continue;
5452 case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12_NC:
5453 case BFD_RELOC_AARCH64_TLSDESC_CALL:
5454 /* GD->IE/LE relaxation:
5455 add x0, x0, #:tlsdesc_lo12:var => nop
5458 bfd_putl32 (INSN_NOP, contents + rel->r_offset);
5459 return bfd_reloc_ok;
5461 case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21:
5462 /* IE->LE relaxation:
5463 adrp xd, :gottprel:var => movz xd, :tprel_g1:var
5467 insn = bfd_getl32 (contents + rel->r_offset);
5468 bfd_putl32 (0xd2a00000 | (insn & 0x1f), contents + rel->r_offset);
5470 return bfd_reloc_continue;
5472 case BFD_RELOC_AARCH64_TLSIE_LDNN_GOTTPREL_LO12_NC:
5473 /* IE->LE relaxation:
5474 ldr xd, [xm, #:gottprel_lo12:var] => movk xd, :tprel_g0_nc:var
5478 insn = bfd_getl32 (contents + rel->r_offset);
5479 bfd_putl32 (0xf2800000 | (insn & 0x1f), contents + rel->r_offset);
5481 return bfd_reloc_continue;
5484 return bfd_reloc_continue;
5487 return bfd_reloc_ok;
5490 /* Relocate an AArch64 ELF section. */
5493 elfNN_aarch64_relocate_section (bfd *output_bfd,
5494 struct bfd_link_info *info,
5496 asection *input_section,
5498 Elf_Internal_Rela *relocs,
5499 Elf_Internal_Sym *local_syms,
5500 asection **local_sections)
5502 Elf_Internal_Shdr *symtab_hdr;
5503 struct elf_link_hash_entry **sym_hashes;
5504 Elf_Internal_Rela *rel;
5505 Elf_Internal_Rela *relend;
5507 struct elf_aarch64_link_hash_table *globals;
5508 bfd_boolean save_addend = FALSE;
5511 globals = elf_aarch64_hash_table (info);
5513 symtab_hdr = &elf_symtab_hdr (input_bfd);
5514 sym_hashes = elf_sym_hashes (input_bfd);
5517 relend = relocs + input_section->reloc_count;
5518 for (; rel < relend; rel++)
5520 unsigned int r_type;
5521 bfd_reloc_code_real_type bfd_r_type;
5522 bfd_reloc_code_real_type relaxed_bfd_r_type;
5523 reloc_howto_type *howto;
5524 unsigned long r_symndx;
5525 Elf_Internal_Sym *sym;
5527 struct elf_link_hash_entry *h;
5529 bfd_reloc_status_type r;
5532 bfd_boolean unresolved_reloc = FALSE;
5533 char *error_message = NULL;
5535 r_symndx = ELFNN_R_SYM (rel->r_info);
5536 r_type = ELFNN_R_TYPE (rel->r_info);
5538 bfd_reloc.howto = elfNN_aarch64_howto_from_type (r_type);
5539 howto = bfd_reloc.howto;
5543 (*_bfd_error_handler)
5544 (_("%B: unrecognized relocation (0x%x) in section `%A'"),
5545 input_bfd, input_section, r_type);
5548 bfd_r_type = elfNN_aarch64_bfd_reloc_from_howto (howto);
5554 if (r_symndx < symtab_hdr->sh_info)
5556 sym = local_syms + r_symndx;
5557 sym_type = ELFNN_ST_TYPE (sym->st_info);
5558 sec = local_sections[r_symndx];
5560 /* An object file might have a reference to a local
5561 undefined symbol. This is a daft object file, but we
5562 should at least do something about it. */
5563 if (r_type != R_AARCH64_NONE && r_type != R_AARCH64_NULL
5564 && bfd_is_und_section (sec)
5565 && ELF_ST_BIND (sym->st_info) != STB_WEAK)
5567 if (!info->callbacks->undefined_symbol
5568 (info, bfd_elf_string_from_elf_section
5569 (input_bfd, symtab_hdr->sh_link, sym->st_name),
5570 input_bfd, input_section, rel->r_offset, TRUE))
5574 relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel);
5576 /* Relocate against local STT_GNU_IFUNC symbol. */
5577 if (!bfd_link_relocatable (info)
5578 && ELF_ST_TYPE (sym->st_info) == STT_GNU_IFUNC)
5580 h = elfNN_aarch64_get_local_sym_hash (globals, input_bfd,
5585 /* Set STT_GNU_IFUNC symbol value. */
5586 h->root.u.def.value = sym->st_value;
5587 h->root.u.def.section = sec;
5592 bfd_boolean warned, ignored;
5594 RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel,
5595 r_symndx, symtab_hdr, sym_hashes,
5597 unresolved_reloc, warned, ignored);
5602 if (sec != NULL && discarded_section (sec))
5603 RELOC_AGAINST_DISCARDED_SECTION (info, input_bfd, input_section,
5604 rel, 1, relend, howto, 0, contents);
5606 if (bfd_link_relocatable (info))
5610 name = h->root.root.string;
5613 name = (bfd_elf_string_from_elf_section
5614 (input_bfd, symtab_hdr->sh_link, sym->st_name));
5615 if (name == NULL || *name == '\0')
5616 name = bfd_section_name (input_bfd, sec);
5620 && r_type != R_AARCH64_NONE
5621 && r_type != R_AARCH64_NULL
5623 || h->root.type == bfd_link_hash_defined
5624 || h->root.type == bfd_link_hash_defweak)
5625 && IS_AARCH64_TLS_RELOC (bfd_r_type) != (sym_type == STT_TLS))
5627 (*_bfd_error_handler)
5628 ((sym_type == STT_TLS
5629 ? _("%B(%A+0x%lx): %s used with TLS symbol %s")
5630 : _("%B(%A+0x%lx): %s used with non-TLS symbol %s")),
5632 input_section, (long) rel->r_offset, howto->name, name);
5635 /* We relax only if we can see that there can be a valid transition
5636 from a reloc type to another.
5637 We call elfNN_aarch64_final_link_relocate unless we're completely
5638 done, i.e., the relaxation produced the final output we want. */
5640 relaxed_bfd_r_type = aarch64_tls_transition (input_bfd, info, r_type,
5642 if (relaxed_bfd_r_type != bfd_r_type)
5644 bfd_r_type = relaxed_bfd_r_type;
5645 howto = elfNN_aarch64_howto_from_bfd_reloc (bfd_r_type);
5646 BFD_ASSERT (howto != NULL);
5647 r_type = howto->type;
5648 r = elfNN_aarch64_tls_relax (globals, input_bfd, contents, rel, h);
5649 unresolved_reloc = 0;
5652 r = bfd_reloc_continue;
5654 /* There may be multiple consecutive relocations for the
5655 same offset. In that case we are supposed to treat the
5656 output of each relocation as the addend for the next. */
5657 if (rel + 1 < relend
5658 && rel->r_offset == rel[1].r_offset
5659 && ELFNN_R_TYPE (rel[1].r_info) != R_AARCH64_NONE
5660 && ELFNN_R_TYPE (rel[1].r_info) != R_AARCH64_NULL)
5663 save_addend = FALSE;
5665 if (r == bfd_reloc_continue)
5666 r = elfNN_aarch64_final_link_relocate (howto, input_bfd, output_bfd,
5667 input_section, contents, rel,
5668 relocation, info, sec,
5669 h, &unresolved_reloc,
5670 save_addend, &addend, sym);
5672 switch (elfNN_aarch64_bfd_reloc_from_type (r_type))
5674 case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC:
5675 case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21:
5676 case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21:
5677 case BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC:
5678 case BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21:
5679 case BFD_RELOC_AARCH64_TLSLD_ADR_PREL21:
5680 if (! symbol_got_offset_mark_p (input_bfd, h, r_symndx))
5682 bfd_boolean need_relocs = FALSE;
5687 off = symbol_got_offset (input_bfd, h, r_symndx);
5688 indx = h && h->dynindx != -1 ? h->dynindx : 0;
5691 (bfd_link_pic (info) || indx != 0) &&
5693 || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
5694 || h->root.type != bfd_link_hash_undefweak);
5696 BFD_ASSERT (globals->root.srelgot != NULL);
5700 Elf_Internal_Rela rela;
5701 rela.r_info = ELFNN_R_INFO (indx, AARCH64_R (TLS_DTPMOD));
5703 rela.r_offset = globals->root.sgot->output_section->vma +
5704 globals->root.sgot->output_offset + off;
5707 loc = globals->root.srelgot->contents;
5708 loc += globals->root.srelgot->reloc_count++
5709 * RELOC_SIZE (htab);
5710 bfd_elfNN_swap_reloca_out (output_bfd, &rela, loc);
5712 bfd_reloc_code_real_type real_type =
5713 elfNN_aarch64_bfd_reloc_from_type (r_type);
5715 if (real_type == BFD_RELOC_AARCH64_TLSLD_ADR_PREL21
5716 || real_type == BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21
5717 || real_type == BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC)
5719 /* For local dynamic, don't generate DTPREL in any case.
5720 Initialize the DTPREL slot into zero, so we get module
5721 base address when invoke runtime TLS resolver. */
5722 bfd_put_NN (output_bfd, 0,
5723 globals->root.sgot->contents + off
5728 bfd_put_NN (output_bfd,
5729 relocation - dtpoff_base (info),
5730 globals->root.sgot->contents + off
5735 /* This TLS symbol is global. We emit a
5736 relocation to fixup the tls offset at load
5739 ELFNN_R_INFO (indx, AARCH64_R (TLS_DTPREL));
5742 (globals->root.sgot->output_section->vma
5743 + globals->root.sgot->output_offset + off
5746 loc = globals->root.srelgot->contents;
5747 loc += globals->root.srelgot->reloc_count++
5748 * RELOC_SIZE (globals);
5749 bfd_elfNN_swap_reloca_out (output_bfd, &rela, loc);
5750 bfd_put_NN (output_bfd, (bfd_vma) 0,
5751 globals->root.sgot->contents + off
5757 bfd_put_NN (output_bfd, (bfd_vma) 1,
5758 globals->root.sgot->contents + off);
5759 bfd_put_NN (output_bfd,
5760 relocation - dtpoff_base (info),
5761 globals->root.sgot->contents + off
5765 symbol_got_offset_mark (input_bfd, h, r_symndx);
5769 case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21:
5770 case BFD_RELOC_AARCH64_TLSIE_LDNN_GOTTPREL_LO12_NC:
5771 case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19:
5772 if (! symbol_got_offset_mark_p (input_bfd, h, r_symndx))
5774 bfd_boolean need_relocs = FALSE;
5779 off = symbol_got_offset (input_bfd, h, r_symndx);
5781 indx = h && h->dynindx != -1 ? h->dynindx : 0;
5784 (bfd_link_pic (info) || indx != 0) &&
5786 || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
5787 || h->root.type != bfd_link_hash_undefweak);
5789 BFD_ASSERT (globals->root.srelgot != NULL);
5793 Elf_Internal_Rela rela;
5796 rela.r_addend = relocation - dtpoff_base (info);
5800 rela.r_info = ELFNN_R_INFO (indx, AARCH64_R (TLS_TPREL));
5801 rela.r_offset = globals->root.sgot->output_section->vma +
5802 globals->root.sgot->output_offset + off;
5804 loc = globals->root.srelgot->contents;
5805 loc += globals->root.srelgot->reloc_count++
5806 * RELOC_SIZE (htab);
5808 bfd_elfNN_swap_reloca_out (output_bfd, &rela, loc);
5810 bfd_put_NN (output_bfd, rela.r_addend,
5811 globals->root.sgot->contents + off);
5814 bfd_put_NN (output_bfd, relocation - tpoff_base (info),
5815 globals->root.sgot->contents + off);
5817 symbol_got_offset_mark (input_bfd, h, r_symndx);
5821 case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12_NC:
5822 case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21:
5823 case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21:
5824 case BFD_RELOC_AARCH64_TLSDESC_LDNN_LO12_NC:
5825 case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19:
5826 if (! symbol_tlsdesc_got_offset_mark_p (input_bfd, h, r_symndx))
5828 bfd_boolean need_relocs = FALSE;
5829 int indx = h && h->dynindx != -1 ? h->dynindx : 0;
5830 bfd_vma off = symbol_tlsdesc_got_offset (input_bfd, h, r_symndx);
5832 need_relocs = (h == NULL
5833 || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
5834 || h->root.type != bfd_link_hash_undefweak);
5836 BFD_ASSERT (globals->root.srelgot != NULL);
5837 BFD_ASSERT (globals->root.sgot != NULL);
5842 Elf_Internal_Rela rela;
5843 rela.r_info = ELFNN_R_INFO (indx, AARCH64_R (TLSDESC));
5846 rela.r_offset = (globals->root.sgotplt->output_section->vma
5847 + globals->root.sgotplt->output_offset
5848 + off + globals->sgotplt_jump_table_size);
5851 rela.r_addend = relocation - dtpoff_base (info);
5853 /* Allocate the next available slot in the PLT reloc
5854 section to hold our R_AARCH64_TLSDESC, the next
5855 available slot is determined from reloc_count,
5856 which we step. But note, reloc_count was
5857 artifically moved down while allocating slots for
5858 real PLT relocs such that all of the PLT relocs
5859 will fit above the initial reloc_count and the
5860 extra stuff will fit below. */
5861 loc = globals->root.srelplt->contents;
5862 loc += globals->root.srelplt->reloc_count++
5863 * RELOC_SIZE (globals);
5865 bfd_elfNN_swap_reloca_out (output_bfd, &rela, loc);
5867 bfd_put_NN (output_bfd, (bfd_vma) 0,
5868 globals->root.sgotplt->contents + off +
5869 globals->sgotplt_jump_table_size);
5870 bfd_put_NN (output_bfd, (bfd_vma) 0,
5871 globals->root.sgotplt->contents + off +
5872 globals->sgotplt_jump_table_size +
5876 symbol_tlsdesc_got_offset_mark (input_bfd, h, r_symndx);
5887 /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
5888 because such sections are not SEC_ALLOC and thus ld.so will
5889 not process them. */
5890 if (unresolved_reloc
5891 && !((input_section->flags & SEC_DEBUGGING) != 0
5893 && _bfd_elf_section_offset (output_bfd, info, input_section,
5894 +rel->r_offset) != (bfd_vma) - 1)
5896 (*_bfd_error_handler)
5898 ("%B(%A+0x%lx): unresolvable %s relocation against symbol `%s'"),
5899 input_bfd, input_section, (long) rel->r_offset, howto->name,
5900 h->root.root.string);
5904 if (r != bfd_reloc_ok && r != bfd_reloc_continue)
5906 bfd_reloc_code_real_type real_r_type
5907 = elfNN_aarch64_bfd_reloc_from_type (r_type);
5911 case bfd_reloc_overflow:
5912 if (!(*info->callbacks->reloc_overflow)
5913 (info, (h ? &h->root : NULL), name, howto->name, (bfd_vma) 0,
5914 input_bfd, input_section, rel->r_offset))
5916 if (real_r_type == BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15
5917 || real_r_type == BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14)
5919 (*info->callbacks->warning)
5921 _("Too many GOT entries for -fpic, "
5922 "please recompile with -fPIC"),
5923 name, input_bfd, input_section, rel->r_offset);
5928 case bfd_reloc_undefined:
5929 if (!((*info->callbacks->undefined_symbol)
5930 (info, name, input_bfd, input_section,
5931 rel->r_offset, TRUE)))
5935 case bfd_reloc_outofrange:
5936 error_message = _("out of range");
5939 case bfd_reloc_notsupported:
5940 error_message = _("unsupported relocation");
5943 case bfd_reloc_dangerous:
5944 /* error_message should already be set. */
5948 error_message = _("unknown error");
5952 BFD_ASSERT (error_message != NULL);
5953 if (!((*info->callbacks->reloc_dangerous)
5954 (info, error_message, input_bfd, input_section,
5965 /* Set the right machine number. */
5968 elfNN_aarch64_object_p (bfd *abfd)
5971 bfd_default_set_arch_mach (abfd, bfd_arch_aarch64, bfd_mach_aarch64_ilp32);
5973 bfd_default_set_arch_mach (abfd, bfd_arch_aarch64, bfd_mach_aarch64);
5978 /* Function to keep AArch64 specific flags in the ELF header. */
5981 elfNN_aarch64_set_private_flags (bfd *abfd, flagword flags)
5983 if (elf_flags_init (abfd) && elf_elfheader (abfd)->e_flags != flags)
5988 elf_elfheader (abfd)->e_flags = flags;
5989 elf_flags_init (abfd) = TRUE;
5995 /* Merge backend specific data from an object file to the output
5996 object file when linking. */
5999 elfNN_aarch64_merge_private_bfd_data (bfd *ibfd, bfd *obfd)
6003 bfd_boolean flags_compatible = TRUE;
6006 /* Check if we have the same endianess. */
6007 if (!_bfd_generic_verify_endian_match (ibfd, obfd))
6010 if (!is_aarch64_elf (ibfd) || !is_aarch64_elf (obfd))
6013 /* The input BFD must have had its flags initialised. */
6014 /* The following seems bogus to me -- The flags are initialized in
6015 the assembler but I don't think an elf_flags_init field is
6016 written into the object. */
6017 /* BFD_ASSERT (elf_flags_init (ibfd)); */
6019 in_flags = elf_elfheader (ibfd)->e_flags;
6020 out_flags = elf_elfheader (obfd)->e_flags;
6022 if (!elf_flags_init (obfd))
6024 /* If the input is the default architecture and had the default
6025 flags then do not bother setting the flags for the output
6026 architecture, instead allow future merges to do this. If no
6027 future merges ever set these flags then they will retain their
6028 uninitialised values, which surprise surprise, correspond
6029 to the default values. */
6030 if (bfd_get_arch_info (ibfd)->the_default
6031 && elf_elfheader (ibfd)->e_flags == 0)
6034 elf_flags_init (obfd) = TRUE;
6035 elf_elfheader (obfd)->e_flags = in_flags;
6037 if (bfd_get_arch (obfd) == bfd_get_arch (ibfd)
6038 && bfd_get_arch_info (obfd)->the_default)
6039 return bfd_set_arch_mach (obfd, bfd_get_arch (ibfd),
6040 bfd_get_mach (ibfd));
6045 /* Identical flags must be compatible. */
6046 if (in_flags == out_flags)
6049 /* Check to see if the input BFD actually contains any sections. If
6050 not, its flags may not have been initialised either, but it
6051 cannot actually cause any incompatiblity. Do not short-circuit
6052 dynamic objects; their section list may be emptied by
6053 elf_link_add_object_symbols.
6055 Also check to see if there are no code sections in the input.
6056 In this case there is no need to check for code specific flags.
6057 XXX - do we need to worry about floating-point format compatability
6058 in data sections ? */
6059 if (!(ibfd->flags & DYNAMIC))
6061 bfd_boolean null_input_bfd = TRUE;
6062 bfd_boolean only_data_sections = TRUE;
6064 for (sec = ibfd->sections; sec != NULL; sec = sec->next)
6066 if ((bfd_get_section_flags (ibfd, sec)
6067 & (SEC_LOAD | SEC_CODE | SEC_HAS_CONTENTS))
6068 == (SEC_LOAD | SEC_CODE | SEC_HAS_CONTENTS))
6069 only_data_sections = FALSE;
6071 null_input_bfd = FALSE;
6075 if (null_input_bfd || only_data_sections)
6079 return flags_compatible;
6082 /* Display the flags field. */
6085 elfNN_aarch64_print_private_bfd_data (bfd *abfd, void *ptr)
6087 FILE *file = (FILE *) ptr;
6088 unsigned long flags;
6090 BFD_ASSERT (abfd != NULL && ptr != NULL);
6092 /* Print normal ELF private data. */
6093 _bfd_elf_print_private_bfd_data (abfd, ptr);
6095 flags = elf_elfheader (abfd)->e_flags;
6096 /* Ignore init flag - it may not be set, despite the flags field
6097 containing valid data. */
6099 /* xgettext:c-format */
6100 fprintf (file, _("private flags = %lx:"), elf_elfheader (abfd)->e_flags);
6103 fprintf (file, _("<Unrecognised flag bits set>"));
6110 /* Update the got entry reference counts for the section being removed. */
6113 elfNN_aarch64_gc_sweep_hook (bfd *abfd,
6114 struct bfd_link_info *info,
6116 const Elf_Internal_Rela * relocs)
6118 struct elf_aarch64_link_hash_table *htab;
6119 Elf_Internal_Shdr *symtab_hdr;
6120 struct elf_link_hash_entry **sym_hashes;
6121 struct elf_aarch64_local_symbol *locals;
6122 const Elf_Internal_Rela *rel, *relend;
6124 if (bfd_link_relocatable (info))
6127 htab = elf_aarch64_hash_table (info);
6132 elf_section_data (sec)->local_dynrel = NULL;
6134 symtab_hdr = &elf_symtab_hdr (abfd);
6135 sym_hashes = elf_sym_hashes (abfd);
6137 locals = elf_aarch64_locals (abfd);
6139 relend = relocs + sec->reloc_count;
6140 for (rel = relocs; rel < relend; rel++)
6142 unsigned long r_symndx;
6143 unsigned int r_type;
6144 struct elf_link_hash_entry *h = NULL;
6146 r_symndx = ELFNN_R_SYM (rel->r_info);
6148 if (r_symndx >= symtab_hdr->sh_info)
6151 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
6152 while (h->root.type == bfd_link_hash_indirect
6153 || h->root.type == bfd_link_hash_warning)
6154 h = (struct elf_link_hash_entry *) h->root.u.i.link;
6158 Elf_Internal_Sym *isym;
6160 /* A local symbol. */
6161 isym = bfd_sym_from_r_symndx (&htab->sym_cache,
6164 /* Check relocation against local STT_GNU_IFUNC symbol. */
6166 && ELF_ST_TYPE (isym->st_info) == STT_GNU_IFUNC)
6168 h = elfNN_aarch64_get_local_sym_hash (htab, abfd, rel, FALSE);
6176 struct elf_aarch64_link_hash_entry *eh;
6177 struct elf_dyn_relocs **pp;
6178 struct elf_dyn_relocs *p;
6180 eh = (struct elf_aarch64_link_hash_entry *) h;
6182 for (pp = &eh->dyn_relocs; (p = *pp) != NULL; pp = &p->next)
6185 /* Everything must go for SEC. */
6191 r_type = ELFNN_R_TYPE (rel->r_info);
6192 switch (aarch64_tls_transition (abfd,info, r_type, h ,r_symndx))
6194 case BFD_RELOC_AARCH64_ADR_GOT_PAGE:
6195 case BFD_RELOC_AARCH64_GOT_LD_PREL19:
6196 case BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14:
6197 case BFD_RELOC_AARCH64_LD32_GOT_LO12_NC:
6198 case BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15:
6199 case BFD_RELOC_AARCH64_LD64_GOT_LO12_NC:
6200 case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12_NC:
6201 case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21:
6202 case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21:
6203 case BFD_RELOC_AARCH64_TLSDESC_LD32_LO12_NC:
6204 case BFD_RELOC_AARCH64_TLSDESC_LD64_LO12_NC:
6205 case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19:
6206 case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC:
6207 case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21:
6208 case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21:
6209 case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21:
6210 case BFD_RELOC_AARCH64_TLSIE_LD32_GOTTPREL_LO12_NC:
6211 case BFD_RELOC_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC:
6212 case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19:
6213 case BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC:
6214 case BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21:
6215 case BFD_RELOC_AARCH64_TLSLD_ADR_PREL21:
6218 if (h->got.refcount > 0)
6219 h->got.refcount -= 1;
6221 if (h->type == STT_GNU_IFUNC)
6223 if (h->plt.refcount > 0)
6224 h->plt.refcount -= 1;
6227 else if (locals != NULL)
6229 if (locals[r_symndx].got_refcount > 0)
6230 locals[r_symndx].got_refcount -= 1;
6234 case BFD_RELOC_AARCH64_CALL26:
6235 case BFD_RELOC_AARCH64_JUMP26:
6236 /* If this is a local symbol then we resolve it
6237 directly without creating a PLT entry. */
6241 if (h->plt.refcount > 0)
6242 h->plt.refcount -= 1;
6245 case BFD_RELOC_AARCH64_ADR_HI21_NC_PCREL:
6246 case BFD_RELOC_AARCH64_ADR_HI21_PCREL:
6247 case BFD_RELOC_AARCH64_ADR_LO21_PCREL:
6248 case BFD_RELOC_AARCH64_MOVW_G0_NC:
6249 case BFD_RELOC_AARCH64_MOVW_G1_NC:
6250 case BFD_RELOC_AARCH64_MOVW_G2_NC:
6251 case BFD_RELOC_AARCH64_MOVW_G3:
6252 case BFD_RELOC_AARCH64_NN:
6253 if (h != NULL && bfd_link_executable (info))
6255 if (h->plt.refcount > 0)
6256 h->plt.refcount -= 1;
6268 /* Adjust a symbol defined by a dynamic object and referenced by a
6269 regular object. The current definition is in some section of the
6270 dynamic object, but we're not including those sections. We have to
6271 change the definition to something the rest of the link can
6275 elfNN_aarch64_adjust_dynamic_symbol (struct bfd_link_info *info,
6276 struct elf_link_hash_entry *h)
6278 struct elf_aarch64_link_hash_table *htab;
6281 /* If this is a function, put it in the procedure linkage table. We
6282 will fill in the contents of the procedure linkage table later,
6283 when we know the address of the .got section. */
6284 if (h->type == STT_FUNC || h->type == STT_GNU_IFUNC || h->needs_plt)
6286 if (h->plt.refcount <= 0
6287 || (h->type != STT_GNU_IFUNC
6288 && (SYMBOL_CALLS_LOCAL (info, h)
6289 || (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
6290 && h->root.type == bfd_link_hash_undefweak))))
6292 /* This case can occur if we saw a CALL26 reloc in
6293 an input file, but the symbol wasn't referred to
6294 by a dynamic object or all references were
6295 garbage collected. In which case we can end up
6297 h->plt.offset = (bfd_vma) - 1;
6304 /* Otherwise, reset to -1. */
6305 h->plt.offset = (bfd_vma) - 1;
6308 /* If this is a weak symbol, and there is a real definition, the
6309 processor independent code will have arranged for us to see the
6310 real definition first, and we can just use the same value. */
6311 if (h->u.weakdef != NULL)
6313 BFD_ASSERT (h->u.weakdef->root.type == bfd_link_hash_defined
6314 || h->u.weakdef->root.type == bfd_link_hash_defweak);
6315 h->root.u.def.section = h->u.weakdef->root.u.def.section;
6316 h->root.u.def.value = h->u.weakdef->root.u.def.value;
6317 if (ELIMINATE_COPY_RELOCS || info->nocopyreloc)
6318 h->non_got_ref = h->u.weakdef->non_got_ref;
6322 /* If we are creating a shared library, we must presume that the
6323 only references to the symbol are via the global offset table.
6324 For such cases we need not do anything here; the relocations will
6325 be handled correctly by relocate_section. */
6326 if (bfd_link_pic (info))
6329 /* If there are no references to this symbol that do not use the
6330 GOT, we don't need to generate a copy reloc. */
6331 if (!h->non_got_ref)
6334 /* If -z nocopyreloc was given, we won't generate them either. */
6335 if (info->nocopyreloc)
6341 /* We must allocate the symbol in our .dynbss section, which will
6342 become part of the .bss section of the executable. There will be
6343 an entry for this symbol in the .dynsym section. The dynamic
6344 object will contain position independent code, so all references
6345 from the dynamic object to this symbol will go through the global
6346 offset table. The dynamic linker will use the .dynsym entry to
6347 determine the address it must put in the global offset table, so
6348 both the dynamic object and the regular object will refer to the
6349 same memory location for the variable. */
6351 htab = elf_aarch64_hash_table (info);
6353 /* We must generate a R_AARCH64_COPY reloc to tell the dynamic linker
6354 to copy the initial value out of the dynamic object and into the
6355 runtime process image. */
6356 if ((h->root.u.def.section->flags & SEC_ALLOC) != 0 && h->size != 0)
6358 htab->srelbss->size += RELOC_SIZE (htab);
6364 return _bfd_elf_adjust_dynamic_copy (info, h, s);
6369 elfNN_aarch64_allocate_local_symbols (bfd *abfd, unsigned number)
6371 struct elf_aarch64_local_symbol *locals;
6372 locals = elf_aarch64_locals (abfd);
6375 locals = (struct elf_aarch64_local_symbol *)
6376 bfd_zalloc (abfd, number * sizeof (struct elf_aarch64_local_symbol));
6379 elf_aarch64_locals (abfd) = locals;
6384 /* Create the .got section to hold the global offset table. */
6387 aarch64_elf_create_got_section (bfd *abfd, struct bfd_link_info *info)
6389 const struct elf_backend_data *bed = get_elf_backend_data (abfd);
6392 struct elf_link_hash_entry *h;
6393 struct elf_link_hash_table *htab = elf_hash_table (info);
6395 /* This function may be called more than once. */
6396 s = bfd_get_linker_section (abfd, ".got");
6400 flags = bed->dynamic_sec_flags;
6402 s = bfd_make_section_anyway_with_flags (abfd,
6403 (bed->rela_plts_and_copies_p
6404 ? ".rela.got" : ".rel.got"),
6405 (bed->dynamic_sec_flags
6408 || ! bfd_set_section_alignment (abfd, s, bed->s->log_file_align))
6412 s = bfd_make_section_anyway_with_flags (abfd, ".got", flags);
6414 || !bfd_set_section_alignment (abfd, s, bed->s->log_file_align))
6417 htab->sgot->size += GOT_ENTRY_SIZE;
6419 if (bed->want_got_sym)
6421 /* Define the symbol _GLOBAL_OFFSET_TABLE_ at the start of the .got
6422 (or .got.plt) section. We don't do this in the linker script
6423 because we don't want to define the symbol if we are not creating
6424 a global offset table. */
6425 h = _bfd_elf_define_linkage_sym (abfd, info, s,
6426 "_GLOBAL_OFFSET_TABLE_");
6427 elf_hash_table (info)->hgot = h;
6432 if (bed->want_got_plt)
6434 s = bfd_make_section_anyway_with_flags (abfd, ".got.plt", flags);
6436 || !bfd_set_section_alignment (abfd, s,
6437 bed->s->log_file_align))
6442 /* The first bit of the global offset table is the header. */
6443 s->size += bed->got_header_size;
6448 /* Look through the relocs for a section during the first phase. */
6451 elfNN_aarch64_check_relocs (bfd *abfd, struct bfd_link_info *info,
6452 asection *sec, const Elf_Internal_Rela *relocs)
6454 Elf_Internal_Shdr *symtab_hdr;
6455 struct elf_link_hash_entry **sym_hashes;
6456 const Elf_Internal_Rela *rel;
6457 const Elf_Internal_Rela *rel_end;
6460 struct elf_aarch64_link_hash_table *htab;
6462 if (bfd_link_relocatable (info))
6465 BFD_ASSERT (is_aarch64_elf (abfd));
6467 htab = elf_aarch64_hash_table (info);
6470 symtab_hdr = &elf_symtab_hdr (abfd);
6471 sym_hashes = elf_sym_hashes (abfd);
6473 rel_end = relocs + sec->reloc_count;
6474 for (rel = relocs; rel < rel_end; rel++)
6476 struct elf_link_hash_entry *h;
6477 unsigned long r_symndx;
6478 unsigned int r_type;
6479 bfd_reloc_code_real_type bfd_r_type;
6480 Elf_Internal_Sym *isym;
6482 r_symndx = ELFNN_R_SYM (rel->r_info);
6483 r_type = ELFNN_R_TYPE (rel->r_info);
6485 if (r_symndx >= NUM_SHDR_ENTRIES (symtab_hdr))
6487 (*_bfd_error_handler) (_("%B: bad symbol index: %d"), abfd,
6492 if (r_symndx < symtab_hdr->sh_info)
6494 /* A local symbol. */
6495 isym = bfd_sym_from_r_symndx (&htab->sym_cache,
6500 /* Check relocation against local STT_GNU_IFUNC symbol. */
6501 if (ELF_ST_TYPE (isym->st_info) == STT_GNU_IFUNC)
6503 h = elfNN_aarch64_get_local_sym_hash (htab, abfd, rel,
6508 /* Fake a STT_GNU_IFUNC symbol. */
6509 h->type = STT_GNU_IFUNC;
6512 h->forced_local = 1;
6513 h->root.type = bfd_link_hash_defined;
6520 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
6521 while (h->root.type == bfd_link_hash_indirect
6522 || h->root.type == bfd_link_hash_warning)
6523 h = (struct elf_link_hash_entry *) h->root.u.i.link;
6525 /* PR15323, ref flags aren't set for references in the same
6527 h->root.non_ir_ref = 1;
6530 /* Could be done earlier, if h were already available. */
6531 bfd_r_type = aarch64_tls_transition (abfd, info, r_type, h, r_symndx);
6535 /* Create the ifunc sections for static executables. If we
6536 never see an indirect function symbol nor we are building
6537 a static executable, those sections will be empty and
6538 won't appear in output. */
6544 case BFD_RELOC_AARCH64_ADD_LO12:
6545 case BFD_RELOC_AARCH64_ADR_GOT_PAGE:
6546 case BFD_RELOC_AARCH64_ADR_HI21_PCREL:
6547 case BFD_RELOC_AARCH64_CALL26:
6548 case BFD_RELOC_AARCH64_GOT_LD_PREL19:
6549 case BFD_RELOC_AARCH64_JUMP26:
6550 case BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14:
6551 case BFD_RELOC_AARCH64_LD32_GOT_LO12_NC:
6552 case BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15:
6553 case BFD_RELOC_AARCH64_LD64_GOT_LO12_NC:
6554 case BFD_RELOC_AARCH64_NN:
6555 if (htab->root.dynobj == NULL)
6556 htab->root.dynobj = abfd;
6557 if (!_bfd_elf_create_ifunc_sections (htab->root.dynobj, info))
6562 /* It is referenced by a non-shared object. */
6564 h->root.non_ir_ref = 1;
6569 case BFD_RELOC_AARCH64_NN:
6571 /* We don't need to handle relocs into sections not going into
6572 the "real" output. */
6573 if ((sec->flags & SEC_ALLOC) == 0)
6578 if (!bfd_link_pic (info))
6581 h->plt.refcount += 1;
6582 h->pointer_equality_needed = 1;
6585 /* No need to do anything if we're not creating a shared
6587 if (! bfd_link_pic (info))
6591 struct elf_dyn_relocs *p;
6592 struct elf_dyn_relocs **head;
6594 /* We must copy these reloc types into the output file.
6595 Create a reloc section in dynobj and make room for
6599 if (htab->root.dynobj == NULL)
6600 htab->root.dynobj = abfd;
6602 sreloc = _bfd_elf_make_dynamic_reloc_section
6603 (sec, htab->root.dynobj, LOG_FILE_ALIGN, abfd, /*rela? */ TRUE);
6609 /* If this is a global symbol, we count the number of
6610 relocations we need for this symbol. */
6613 struct elf_aarch64_link_hash_entry *eh;
6614 eh = (struct elf_aarch64_link_hash_entry *) h;
6615 head = &eh->dyn_relocs;
6619 /* Track dynamic relocs needed for local syms too.
6620 We really need local syms available to do this
6626 isym = bfd_sym_from_r_symndx (&htab->sym_cache,
6631 s = bfd_section_from_elf_index (abfd, isym->st_shndx);
6635 /* Beware of type punned pointers vs strict aliasing
6637 vpp = &(elf_section_data (s)->local_dynrel);
6638 head = (struct elf_dyn_relocs **) vpp;
6642 if (p == NULL || p->sec != sec)
6644 bfd_size_type amt = sizeof *p;
6645 p = ((struct elf_dyn_relocs *)
6646 bfd_zalloc (htab->root.dynobj, amt));
6659 /* RR: We probably want to keep a consistency check that
6660 there are no dangling GOT_PAGE relocs. */
6661 case BFD_RELOC_AARCH64_ADR_GOT_PAGE:
6662 case BFD_RELOC_AARCH64_GOT_LD_PREL19:
6663 case BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14:
6664 case BFD_RELOC_AARCH64_LD32_GOT_LO12_NC:
6665 case BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15:
6666 case BFD_RELOC_AARCH64_LD64_GOT_LO12_NC:
6667 case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12_NC:
6668 case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21:
6669 case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21:
6670 case BFD_RELOC_AARCH64_TLSDESC_LD32_LO12_NC:
6671 case BFD_RELOC_AARCH64_TLSDESC_LD64_LO12_NC:
6672 case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19:
6673 case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC:
6674 case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21:
6675 case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21:
6676 case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21:
6677 case BFD_RELOC_AARCH64_TLSIE_LD32_GOTTPREL_LO12_NC:
6678 case BFD_RELOC_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC:
6679 case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19:
6680 case BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC:
6681 case BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21:
6682 case BFD_RELOC_AARCH64_TLSLD_ADR_PREL21:
6685 unsigned old_got_type;
6687 got_type = aarch64_reloc_got_type (bfd_r_type);
6691 h->got.refcount += 1;
6692 old_got_type = elf_aarch64_hash_entry (h)->got_type;
6696 struct elf_aarch64_local_symbol *locals;
6698 if (!elfNN_aarch64_allocate_local_symbols
6699 (abfd, symtab_hdr->sh_info))
6702 locals = elf_aarch64_locals (abfd);
6703 BFD_ASSERT (r_symndx < symtab_hdr->sh_info);
6704 locals[r_symndx].got_refcount += 1;
6705 old_got_type = locals[r_symndx].got_type;
6708 /* If a variable is accessed with both general dynamic TLS
6709 methods, two slots may be created. */
6710 if (GOT_TLS_GD_ANY_P (old_got_type) && GOT_TLS_GD_ANY_P (got_type))
6711 got_type |= old_got_type;
6713 /* We will already have issued an error message if there
6714 is a TLS/non-TLS mismatch, based on the symbol type.
6715 So just combine any TLS types needed. */
6716 if (old_got_type != GOT_UNKNOWN && old_got_type != GOT_NORMAL
6717 && got_type != GOT_NORMAL)
6718 got_type |= old_got_type;
6720 /* If the symbol is accessed by both IE and GD methods, we
6721 are able to relax. Turn off the GD flag, without
6722 messing up with any other kind of TLS types that may be
6724 if ((got_type & GOT_TLS_IE) && GOT_TLS_GD_ANY_P (got_type))
6725 got_type &= ~ (GOT_TLSDESC_GD | GOT_TLS_GD);
6727 if (old_got_type != got_type)
6730 elf_aarch64_hash_entry (h)->got_type = got_type;
6733 struct elf_aarch64_local_symbol *locals;
6734 locals = elf_aarch64_locals (abfd);
6735 BFD_ASSERT (r_symndx < symtab_hdr->sh_info);
6736 locals[r_symndx].got_type = got_type;
6740 if (htab->root.dynobj == NULL)
6741 htab->root.dynobj = abfd;
6742 if (! aarch64_elf_create_got_section (htab->root.dynobj, info))
6747 case BFD_RELOC_AARCH64_MOVW_G0_NC:
6748 case BFD_RELOC_AARCH64_MOVW_G1_NC:
6749 case BFD_RELOC_AARCH64_MOVW_G2_NC:
6750 case BFD_RELOC_AARCH64_MOVW_G3:
6751 if (bfd_link_pic (info))
6753 int howto_index = bfd_r_type - BFD_RELOC_AARCH64_RELOC_START;
6754 (*_bfd_error_handler)
6755 (_("%B: relocation %s against `%s' can not be used when making "
6756 "a shared object; recompile with -fPIC"),
6757 abfd, elfNN_aarch64_howto_table[howto_index].name,
6758 (h) ? h->root.root.string : "a local symbol");
6759 bfd_set_error (bfd_error_bad_value);
6763 case BFD_RELOC_AARCH64_ADR_HI21_NC_PCREL:
6764 case BFD_RELOC_AARCH64_ADR_HI21_PCREL:
6765 case BFD_RELOC_AARCH64_ADR_LO21_PCREL:
6766 if (h != NULL && bfd_link_executable (info))
6768 /* If this reloc is in a read-only section, we might
6769 need a copy reloc. We can't check reliably at this
6770 stage whether the section is read-only, as input
6771 sections have not yet been mapped to output sections.
6772 Tentatively set the flag for now, and correct in
6773 adjust_dynamic_symbol. */
6775 h->plt.refcount += 1;
6776 h->pointer_equality_needed = 1;
6778 /* FIXME:: RR need to handle these in shared libraries
6779 and essentially bomb out as these being non-PIC
6780 relocations in shared libraries. */
6783 case BFD_RELOC_AARCH64_CALL26:
6784 case BFD_RELOC_AARCH64_JUMP26:
6785 /* If this is a local symbol then we resolve it
6786 directly without creating a PLT entry. */
6791 if (h->plt.refcount <= 0)
6792 h->plt.refcount = 1;
6794 h->plt.refcount += 1;
6805 /* Treat mapping symbols as special target symbols. */
6808 elfNN_aarch64_is_target_special_symbol (bfd *abfd ATTRIBUTE_UNUSED,
6811 return bfd_is_aarch64_special_symbol_name (sym->name,
6812 BFD_AARCH64_SPECIAL_SYM_TYPE_ANY);
6815 /* This is a copy of elf_find_function () from elf.c except that
6816 AArch64 mapping symbols are ignored when looking for function names. */
6819 aarch64_elf_find_function (bfd *abfd ATTRIBUTE_UNUSED,
6823 const char **filename_ptr,
6824 const char **functionname_ptr)
6826 const char *filename = NULL;
6827 asymbol *func = NULL;
6828 bfd_vma low_func = 0;
6831 for (p = symbols; *p != NULL; p++)
6835 q = (elf_symbol_type *) * p;
6837 switch (ELF_ST_TYPE (q->internal_elf_sym.st_info))
6842 filename = bfd_asymbol_name (&q->symbol);
6846 /* Skip mapping symbols. */
6847 if ((q->symbol.flags & BSF_LOCAL)
6848 && (bfd_is_aarch64_special_symbol_name
6849 (q->symbol.name, BFD_AARCH64_SPECIAL_SYM_TYPE_ANY)))
6852 if (bfd_get_section (&q->symbol) == section
6853 && q->symbol.value >= low_func && q->symbol.value <= offset)
6855 func = (asymbol *) q;
6856 low_func = q->symbol.value;
6866 *filename_ptr = filename;
6867 if (functionname_ptr)
6868 *functionname_ptr = bfd_asymbol_name (func);
6874 /* Find the nearest line to a particular section and offset, for error
6875 reporting. This code is a duplicate of the code in elf.c, except
6876 that it uses aarch64_elf_find_function. */
6879 elfNN_aarch64_find_nearest_line (bfd *abfd,
6883 const char **filename_ptr,
6884 const char **functionname_ptr,
6885 unsigned int *line_ptr,
6886 unsigned int *discriminator_ptr)
6888 bfd_boolean found = FALSE;
6890 if (_bfd_dwarf2_find_nearest_line (abfd, symbols, NULL, section, offset,
6891 filename_ptr, functionname_ptr,
6892 line_ptr, discriminator_ptr,
6893 dwarf_debug_sections, 0,
6894 &elf_tdata (abfd)->dwarf2_find_line_info))
6896 if (!*functionname_ptr)
6897 aarch64_elf_find_function (abfd, symbols, section, offset,
6898 *filename_ptr ? NULL : filename_ptr,
6904 /* Skip _bfd_dwarf1_find_nearest_line since no known AArch64
6905 toolchain uses DWARF1. */
6907 if (!_bfd_stab_section_find_nearest_line (abfd, symbols, section, offset,
6908 &found, filename_ptr,
6909 functionname_ptr, line_ptr,
6910 &elf_tdata (abfd)->line_info))
6913 if (found && (*functionname_ptr || *line_ptr))
6916 if (symbols == NULL)
6919 if (!aarch64_elf_find_function (abfd, symbols, section, offset,
6920 filename_ptr, functionname_ptr))
6928 elfNN_aarch64_find_inliner_info (bfd *abfd,
6929 const char **filename_ptr,
6930 const char **functionname_ptr,
6931 unsigned int *line_ptr)
6934 found = _bfd_dwarf2_find_inliner_info
6935 (abfd, filename_ptr,
6936 functionname_ptr, line_ptr, &elf_tdata (abfd)->dwarf2_find_line_info);
6942 elfNN_aarch64_post_process_headers (bfd *abfd,
6943 struct bfd_link_info *link_info)
6945 Elf_Internal_Ehdr *i_ehdrp; /* ELF file header, internal form. */
6947 i_ehdrp = elf_elfheader (abfd);
6948 i_ehdrp->e_ident[EI_ABIVERSION] = AARCH64_ELF_ABI_VERSION;
6950 _bfd_elf_post_process_headers (abfd, link_info);
6953 static enum elf_reloc_type_class
6954 elfNN_aarch64_reloc_type_class (const struct bfd_link_info *info ATTRIBUTE_UNUSED,
6955 const asection *rel_sec ATTRIBUTE_UNUSED,
6956 const Elf_Internal_Rela *rela)
6958 switch ((int) ELFNN_R_TYPE (rela->r_info))
6960 case AARCH64_R (RELATIVE):
6961 return reloc_class_relative;
6962 case AARCH64_R (JUMP_SLOT):
6963 return reloc_class_plt;
6964 case AARCH64_R (COPY):
6965 return reloc_class_copy;
6967 return reloc_class_normal;
6971 /* Handle an AArch64 specific section when reading an object file. This is
6972 called when bfd_section_from_shdr finds a section with an unknown
6976 elfNN_aarch64_section_from_shdr (bfd *abfd,
6977 Elf_Internal_Shdr *hdr,
6978 const char *name, int shindex)
6980 /* There ought to be a place to keep ELF backend specific flags, but
6981 at the moment there isn't one. We just keep track of the
6982 sections by their name, instead. Fortunately, the ABI gives
6983 names for all the AArch64 specific sections, so we will probably get
6985 switch (hdr->sh_type)
6987 case SHT_AARCH64_ATTRIBUTES:
6994 if (!_bfd_elf_make_section_from_shdr (abfd, hdr, name, shindex))
7000 /* A structure used to record a list of sections, independently
7001 of the next and prev fields in the asection structure. */
7002 typedef struct section_list
7005 struct section_list *next;
7006 struct section_list *prev;
7010 /* Unfortunately we need to keep a list of sections for which
7011 an _aarch64_elf_section_data structure has been allocated. This
7012 is because it is possible for functions like elfNN_aarch64_write_section
7013 to be called on a section which has had an elf_data_structure
7014 allocated for it (and so the used_by_bfd field is valid) but
7015 for which the AArch64 extended version of this structure - the
7016 _aarch64_elf_section_data structure - has not been allocated. */
7017 static section_list *sections_with_aarch64_elf_section_data = NULL;
7020 record_section_with_aarch64_elf_section_data (asection *sec)
7022 struct section_list *entry;
7024 entry = bfd_malloc (sizeof (*entry));
7028 entry->next = sections_with_aarch64_elf_section_data;
7030 if (entry->next != NULL)
7031 entry->next->prev = entry;
7032 sections_with_aarch64_elf_section_data = entry;
7035 static struct section_list *
7036 find_aarch64_elf_section_entry (asection *sec)
7038 struct section_list *entry;
7039 static struct section_list *last_entry = NULL;
7041 /* This is a short cut for the typical case where the sections are added
7042 to the sections_with_aarch64_elf_section_data list in forward order and
7043 then looked up here in backwards order. This makes a real difference
7044 to the ld-srec/sec64k.exp linker test. */
7045 entry = sections_with_aarch64_elf_section_data;
7046 if (last_entry != NULL)
7048 if (last_entry->sec == sec)
7050 else if (last_entry->next != NULL && last_entry->next->sec == sec)
7051 entry = last_entry->next;
7054 for (; entry; entry = entry->next)
7055 if (entry->sec == sec)
7059 /* Record the entry prior to this one - it is the entry we are
7060 most likely to want to locate next time. Also this way if we
7061 have been called from
7062 unrecord_section_with_aarch64_elf_section_data () we will not
7063 be caching a pointer that is about to be freed. */
7064 last_entry = entry->prev;
7070 unrecord_section_with_aarch64_elf_section_data (asection *sec)
7072 struct section_list *entry;
7074 entry = find_aarch64_elf_section_entry (sec);
7078 if (entry->prev != NULL)
7079 entry->prev->next = entry->next;
7080 if (entry->next != NULL)
7081 entry->next->prev = entry->prev;
7082 if (entry == sections_with_aarch64_elf_section_data)
7083 sections_with_aarch64_elf_section_data = entry->next;
7092 struct bfd_link_info *info;
7095 int (*func) (void *, const char *, Elf_Internal_Sym *,
7096 asection *, struct elf_link_hash_entry *);
7097 } output_arch_syminfo;
7099 enum map_symbol_type
7106 /* Output a single mapping symbol. */
7109 elfNN_aarch64_output_map_sym (output_arch_syminfo *osi,
7110 enum map_symbol_type type, bfd_vma offset)
7112 static const char *names[2] = { "$x", "$d" };
7113 Elf_Internal_Sym sym;
7115 sym.st_value = (osi->sec->output_section->vma
7116 + osi->sec->output_offset + offset);
7119 sym.st_info = ELF_ST_INFO (STB_LOCAL, STT_NOTYPE);
7120 sym.st_shndx = osi->sec_shndx;
7121 return osi->func (osi->finfo, names[type], &sym, osi->sec, NULL) == 1;
7126 /* Output mapping symbols for PLT entries associated with H. */
7129 elfNN_aarch64_output_plt_map (struct elf_link_hash_entry *h, void *inf)
7131 output_arch_syminfo *osi = (output_arch_syminfo *) inf;
7134 if (h->root.type == bfd_link_hash_indirect)
7137 if (h->root.type == bfd_link_hash_warning)
7138 /* When warning symbols are created, they **replace** the "real"
7139 entry in the hash table, thus we never get to see the real
7140 symbol in a hash traversal. So look at it now. */
7141 h = (struct elf_link_hash_entry *) h->root.u.i.link;
7143 if (h->plt.offset == (bfd_vma) - 1)
7146 addr = h->plt.offset;
7149 if (!elfNN_aarch64_output_map_sym (osi, AARCH64_MAP_INSN, addr))
7156 /* Output a single local symbol for a generated stub. */
7159 elfNN_aarch64_output_stub_sym (output_arch_syminfo *osi, const char *name,
7160 bfd_vma offset, bfd_vma size)
7162 Elf_Internal_Sym sym;
7164 sym.st_value = (osi->sec->output_section->vma
7165 + osi->sec->output_offset + offset);
7168 sym.st_info = ELF_ST_INFO (STB_LOCAL, STT_FUNC);
7169 sym.st_shndx = osi->sec_shndx;
7170 return osi->func (osi->finfo, name, &sym, osi->sec, NULL) == 1;
7174 aarch64_map_one_stub (struct bfd_hash_entry *gen_entry, void *in_arg)
7176 struct elf_aarch64_stub_hash_entry *stub_entry;
7180 output_arch_syminfo *osi;
7182 /* Massage our args to the form they really have. */
7183 stub_entry = (struct elf_aarch64_stub_hash_entry *) gen_entry;
7184 osi = (output_arch_syminfo *) in_arg;
7186 stub_sec = stub_entry->stub_sec;
7188 /* Ensure this stub is attached to the current section being
7190 if (stub_sec != osi->sec)
7193 addr = (bfd_vma) stub_entry->stub_offset;
7195 stub_name = stub_entry->output_name;
7197 switch (stub_entry->stub_type)
7199 case aarch64_stub_adrp_branch:
7200 if (!elfNN_aarch64_output_stub_sym (osi, stub_name, addr,
7201 sizeof (aarch64_adrp_branch_stub)))
7203 if (!elfNN_aarch64_output_map_sym (osi, AARCH64_MAP_INSN, addr))
7206 case aarch64_stub_long_branch:
7207 if (!elfNN_aarch64_output_stub_sym
7208 (osi, stub_name, addr, sizeof (aarch64_long_branch_stub)))
7210 if (!elfNN_aarch64_output_map_sym (osi, AARCH64_MAP_INSN, addr))
7212 if (!elfNN_aarch64_output_map_sym (osi, AARCH64_MAP_DATA, addr + 16))
7215 case aarch64_stub_erratum_835769_veneer:
7216 if (!elfNN_aarch64_output_stub_sym (osi, stub_name, addr,
7217 sizeof (aarch64_erratum_835769_stub)))
7219 if (!elfNN_aarch64_output_map_sym (osi, AARCH64_MAP_INSN, addr))
7222 case aarch64_stub_erratum_843419_veneer:
7223 if (!elfNN_aarch64_output_stub_sym (osi, stub_name, addr,
7224 sizeof (aarch64_erratum_843419_stub)))
7226 if (!elfNN_aarch64_output_map_sym (osi, AARCH64_MAP_INSN, addr))
7237 /* Output mapping symbols for linker generated sections. */
7240 elfNN_aarch64_output_arch_local_syms (bfd *output_bfd,
7241 struct bfd_link_info *info,
7243 int (*func) (void *, const char *,
7246 struct elf_link_hash_entry
7249 output_arch_syminfo osi;
7250 struct elf_aarch64_link_hash_table *htab;
7252 htab = elf_aarch64_hash_table (info);
7258 /* Long calls stubs. */
7259 if (htab->stub_bfd && htab->stub_bfd->sections)
7263 for (stub_sec = htab->stub_bfd->sections;
7264 stub_sec != NULL; stub_sec = stub_sec->next)
7266 /* Ignore non-stub sections. */
7267 if (!strstr (stub_sec->name, STUB_SUFFIX))
7272 osi.sec_shndx = _bfd_elf_section_from_bfd_section
7273 (output_bfd, osi.sec->output_section);
7275 /* The first instruction in a stub is always a branch. */
7276 if (!elfNN_aarch64_output_map_sym (&osi, AARCH64_MAP_INSN, 0))
7279 bfd_hash_traverse (&htab->stub_hash_table, aarch64_map_one_stub,
7284 /* Finally, output mapping symbols for the PLT. */
7285 if (!htab->root.splt || htab->root.splt->size == 0)
7288 /* For now live without mapping symbols for the plt. */
7289 osi.sec_shndx = _bfd_elf_section_from_bfd_section
7290 (output_bfd, htab->root.splt->output_section);
7291 osi.sec = htab->root.splt;
7293 elf_link_hash_traverse (&htab->root, elfNN_aarch64_output_plt_map,
7300 /* Allocate target specific section data. */
7303 elfNN_aarch64_new_section_hook (bfd *abfd, asection *sec)
7305 if (!sec->used_by_bfd)
7307 _aarch64_elf_section_data *sdata;
7308 bfd_size_type amt = sizeof (*sdata);
7310 sdata = bfd_zalloc (abfd, amt);
7313 sec->used_by_bfd = sdata;
7316 record_section_with_aarch64_elf_section_data (sec);
7318 return _bfd_elf_new_section_hook (abfd, sec);
7323 unrecord_section_via_map_over_sections (bfd *abfd ATTRIBUTE_UNUSED,
7325 void *ignore ATTRIBUTE_UNUSED)
7327 unrecord_section_with_aarch64_elf_section_data (sec);
7331 elfNN_aarch64_close_and_cleanup (bfd *abfd)
7334 bfd_map_over_sections (abfd,
7335 unrecord_section_via_map_over_sections, NULL);
7337 return _bfd_elf_close_and_cleanup (abfd);
7341 elfNN_aarch64_bfd_free_cached_info (bfd *abfd)
7344 bfd_map_over_sections (abfd,
7345 unrecord_section_via_map_over_sections, NULL);
7347 return _bfd_free_cached_info (abfd);
7350 /* Create dynamic sections. This is different from the ARM backend in that
7351 the got, plt, gotplt and their relocation sections are all created in the
7352 standard part of the bfd elf backend. */
7355 elfNN_aarch64_create_dynamic_sections (bfd *dynobj,
7356 struct bfd_link_info *info)
7358 struct elf_aarch64_link_hash_table *htab;
7360 /* We need to create .got section. */
7361 if (!aarch64_elf_create_got_section (dynobj, info))
7364 if (!_bfd_elf_create_dynamic_sections (dynobj, info))
7367 htab = elf_aarch64_hash_table (info);
7368 htab->sdynbss = bfd_get_linker_section (dynobj, ".dynbss");
7369 if (!bfd_link_pic (info))
7370 htab->srelbss = bfd_get_linker_section (dynobj, ".rela.bss");
7372 if (!htab->sdynbss || (!bfd_link_pic (info) && !htab->srelbss))
7379 /* Allocate space in .plt, .got and associated reloc sections for
7383 elfNN_aarch64_allocate_dynrelocs (struct elf_link_hash_entry *h, void *inf)
7385 struct bfd_link_info *info;
7386 struct elf_aarch64_link_hash_table *htab;
7387 struct elf_aarch64_link_hash_entry *eh;
7388 struct elf_dyn_relocs *p;
7390 /* An example of a bfd_link_hash_indirect symbol is versioned
7391 symbol. For example: __gxx_personality_v0(bfd_link_hash_indirect)
7392 -> __gxx_personality_v0(bfd_link_hash_defined)
7394 There is no need to process bfd_link_hash_indirect symbols here
7395 because we will also be presented with the concrete instance of
7396 the symbol and elfNN_aarch64_copy_indirect_symbol () will have been
7397 called to copy all relevant data from the generic to the concrete
7400 if (h->root.type == bfd_link_hash_indirect)
7403 if (h->root.type == bfd_link_hash_warning)
7404 h = (struct elf_link_hash_entry *) h->root.u.i.link;
7406 info = (struct bfd_link_info *) inf;
7407 htab = elf_aarch64_hash_table (info);
7409 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle it
7410 here if it is defined and referenced in a non-shared object. */
7411 if (h->type == STT_GNU_IFUNC
7414 else if (htab->root.dynamic_sections_created && h->plt.refcount > 0)
7416 /* Make sure this symbol is output as a dynamic symbol.
7417 Undefined weak syms won't yet be marked as dynamic. */
7418 if (h->dynindx == -1 && !h->forced_local)
7420 if (!bfd_elf_link_record_dynamic_symbol (info, h))
7424 if (bfd_link_pic (info) || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h))
7426 asection *s = htab->root.splt;
7428 /* If this is the first .plt entry, make room for the special
7431 s->size += htab->plt_header_size;
7433 h->plt.offset = s->size;
7435 /* If this symbol is not defined in a regular file, and we are
7436 not generating a shared library, then set the symbol to this
7437 location in the .plt. This is required to make function
7438 pointers compare as equal between the normal executable and
7439 the shared library. */
7440 if (!bfd_link_pic (info) && !h->def_regular)
7442 h->root.u.def.section = s;
7443 h->root.u.def.value = h->plt.offset;
7446 /* Make room for this entry. For now we only create the
7447 small model PLT entries. We later need to find a way
7448 of relaxing into these from the large model PLT entries. */
7449 s->size += PLT_SMALL_ENTRY_SIZE;
7451 /* We also need to make an entry in the .got.plt section, which
7452 will be placed in the .got section by the linker script. */
7453 htab->root.sgotplt->size += GOT_ENTRY_SIZE;
7455 /* We also need to make an entry in the .rela.plt section. */
7456 htab->root.srelplt->size += RELOC_SIZE (htab);
7458 /* We need to ensure that all GOT entries that serve the PLT
7459 are consecutive with the special GOT slots [0] [1] and
7460 [2]. Any addtional relocations, such as
7461 R_AARCH64_TLSDESC, must be placed after the PLT related
7462 entries. We abuse the reloc_count such that during
7463 sizing we adjust reloc_count to indicate the number of
7464 PLT related reserved entries. In subsequent phases when
7465 filling in the contents of the reloc entries, PLT related
7466 entries are placed by computing their PLT index (0
7467 .. reloc_count). While other none PLT relocs are placed
7468 at the slot indicated by reloc_count and reloc_count is
7471 htab->root.srelplt->reloc_count++;
7475 h->plt.offset = (bfd_vma) - 1;
7481 h->plt.offset = (bfd_vma) - 1;
7485 eh = (struct elf_aarch64_link_hash_entry *) h;
7486 eh->tlsdesc_got_jump_table_offset = (bfd_vma) - 1;
7488 if (h->got.refcount > 0)
7491 unsigned got_type = elf_aarch64_hash_entry (h)->got_type;
7493 h->got.offset = (bfd_vma) - 1;
7495 dyn = htab->root.dynamic_sections_created;
7497 /* Make sure this symbol is output as a dynamic symbol.
7498 Undefined weak syms won't yet be marked as dynamic. */
7499 if (dyn && h->dynindx == -1 && !h->forced_local)
7501 if (!bfd_elf_link_record_dynamic_symbol (info, h))
7505 if (got_type == GOT_UNKNOWN)
7508 else if (got_type == GOT_NORMAL)
7510 h->got.offset = htab->root.sgot->size;
7511 htab->root.sgot->size += GOT_ENTRY_SIZE;
7512 if ((ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
7513 || h->root.type != bfd_link_hash_undefweak)
7514 && (bfd_link_pic (info)
7515 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, 0, h)))
7517 htab->root.srelgot->size += RELOC_SIZE (htab);
7523 if (got_type & GOT_TLSDESC_GD)
7525 eh->tlsdesc_got_jump_table_offset =
7526 (htab->root.sgotplt->size
7527 - aarch64_compute_jump_table_size (htab));
7528 htab->root.sgotplt->size += GOT_ENTRY_SIZE * 2;
7529 h->got.offset = (bfd_vma) - 2;
7532 if (got_type & GOT_TLS_GD)
7534 h->got.offset = htab->root.sgot->size;
7535 htab->root.sgot->size += GOT_ENTRY_SIZE * 2;
7538 if (got_type & GOT_TLS_IE)
7540 h->got.offset = htab->root.sgot->size;
7541 htab->root.sgot->size += GOT_ENTRY_SIZE;
7544 indx = h && h->dynindx != -1 ? h->dynindx : 0;
7545 if ((ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
7546 || h->root.type != bfd_link_hash_undefweak)
7547 && (bfd_link_pic (info)
7549 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, 0, h)))
7551 if (got_type & GOT_TLSDESC_GD)
7553 htab->root.srelplt->size += RELOC_SIZE (htab);
7554 /* Note reloc_count not incremented here! We have
7555 already adjusted reloc_count for this relocation
7558 /* TLSDESC PLT is now needed, but not yet determined. */
7559 htab->tlsdesc_plt = (bfd_vma) - 1;
7562 if (got_type & GOT_TLS_GD)
7563 htab->root.srelgot->size += RELOC_SIZE (htab) * 2;
7565 if (got_type & GOT_TLS_IE)
7566 htab->root.srelgot->size += RELOC_SIZE (htab);
7572 h->got.offset = (bfd_vma) - 1;
7575 if (eh->dyn_relocs == NULL)
7578 /* In the shared -Bsymbolic case, discard space allocated for
7579 dynamic pc-relative relocs against symbols which turn out to be
7580 defined in regular objects. For the normal shared case, discard
7581 space for pc-relative relocs that have become local due to symbol
7582 visibility changes. */
7584 if (bfd_link_pic (info))
7586 /* Relocs that use pc_count are those that appear on a call
7587 insn, or certain REL relocs that can generated via assembly.
7588 We want calls to protected symbols to resolve directly to the
7589 function rather than going via the plt. If people want
7590 function pointer comparisons to work as expected then they
7591 should avoid writing weird assembly. */
7592 if (SYMBOL_CALLS_LOCAL (info, h))
7594 struct elf_dyn_relocs **pp;
7596 for (pp = &eh->dyn_relocs; (p = *pp) != NULL;)
7598 p->count -= p->pc_count;
7607 /* Also discard relocs on undefined weak syms with non-default
7609 if (eh->dyn_relocs != NULL && h->root.type == bfd_link_hash_undefweak)
7611 if (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT)
7612 eh->dyn_relocs = NULL;
7614 /* Make sure undefined weak symbols are output as a dynamic
7616 else if (h->dynindx == -1
7618 && !bfd_elf_link_record_dynamic_symbol (info, h))
7623 else if (ELIMINATE_COPY_RELOCS)
7625 /* For the non-shared case, discard space for relocs against
7626 symbols which turn out to need copy relocs or are not
7632 || (htab->root.dynamic_sections_created
7633 && (h->root.type == bfd_link_hash_undefweak
7634 || h->root.type == bfd_link_hash_undefined))))
7636 /* Make sure this symbol is output as a dynamic symbol.
7637 Undefined weak syms won't yet be marked as dynamic. */
7638 if (h->dynindx == -1
7640 && !bfd_elf_link_record_dynamic_symbol (info, h))
7643 /* If that succeeded, we know we'll be keeping all the
7645 if (h->dynindx != -1)
7649 eh->dyn_relocs = NULL;
7654 /* Finally, allocate space. */
7655 for (p = eh->dyn_relocs; p != NULL; p = p->next)
7659 sreloc = elf_section_data (p->sec)->sreloc;
7661 BFD_ASSERT (sreloc != NULL);
7663 sreloc->size += p->count * RELOC_SIZE (htab);
7669 /* Allocate space in .plt, .got and associated reloc sections for
7670 ifunc dynamic relocs. */
7673 elfNN_aarch64_allocate_ifunc_dynrelocs (struct elf_link_hash_entry *h,
7676 struct bfd_link_info *info;
7677 struct elf_aarch64_link_hash_table *htab;
7678 struct elf_aarch64_link_hash_entry *eh;
7680 /* An example of a bfd_link_hash_indirect symbol is versioned
7681 symbol. For example: __gxx_personality_v0(bfd_link_hash_indirect)
7682 -> __gxx_personality_v0(bfd_link_hash_defined)
7684 There is no need to process bfd_link_hash_indirect symbols here
7685 because we will also be presented with the concrete instance of
7686 the symbol and elfNN_aarch64_copy_indirect_symbol () will have been
7687 called to copy all relevant data from the generic to the concrete
7690 if (h->root.type == bfd_link_hash_indirect)
7693 if (h->root.type == bfd_link_hash_warning)
7694 h = (struct elf_link_hash_entry *) h->root.u.i.link;
7696 info = (struct bfd_link_info *) inf;
7697 htab = elf_aarch64_hash_table (info);
7699 eh = (struct elf_aarch64_link_hash_entry *) h;
7701 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle it
7702 here if it is defined and referenced in a non-shared object. */
7703 if (h->type == STT_GNU_IFUNC
7705 return _bfd_elf_allocate_ifunc_dyn_relocs (info, h,
7707 htab->plt_entry_size,
7708 htab->plt_header_size,
7713 /* Allocate space in .plt, .got and associated reloc sections for
7714 local dynamic relocs. */
7717 elfNN_aarch64_allocate_local_dynrelocs (void **slot, void *inf)
7719 struct elf_link_hash_entry *h
7720 = (struct elf_link_hash_entry *) *slot;
7722 if (h->type != STT_GNU_IFUNC
7726 || h->root.type != bfd_link_hash_defined)
7729 return elfNN_aarch64_allocate_dynrelocs (h, inf);
7732 /* Allocate space in .plt, .got and associated reloc sections for
7733 local ifunc dynamic relocs. */
7736 elfNN_aarch64_allocate_local_ifunc_dynrelocs (void **slot, void *inf)
7738 struct elf_link_hash_entry *h
7739 = (struct elf_link_hash_entry *) *slot;
7741 if (h->type != STT_GNU_IFUNC
7745 || h->root.type != bfd_link_hash_defined)
7748 return elfNN_aarch64_allocate_ifunc_dynrelocs (h, inf);
7751 /* Find any dynamic relocs that apply to read-only sections. */
7754 aarch64_readonly_dynrelocs (struct elf_link_hash_entry * h, void * inf)
7756 struct elf_aarch64_link_hash_entry * eh;
7757 struct elf_dyn_relocs * p;
7759 eh = (struct elf_aarch64_link_hash_entry *) h;
7760 for (p = eh->dyn_relocs; p != NULL; p = p->next)
7762 asection *s = p->sec;
7764 if (s != NULL && (s->flags & SEC_READONLY) != 0)
7766 struct bfd_link_info *info = (struct bfd_link_info *) inf;
7768 info->flags |= DF_TEXTREL;
7770 /* Not an error, just cut short the traversal. */
7777 /* This is the most important function of all . Innocuosly named
7780 elfNN_aarch64_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
7781 struct bfd_link_info *info)
7783 struct elf_aarch64_link_hash_table *htab;
7789 htab = elf_aarch64_hash_table ((info));
7790 dynobj = htab->root.dynobj;
7792 BFD_ASSERT (dynobj != NULL);
7794 if (htab->root.dynamic_sections_created)
7796 if (bfd_link_executable (info))
7798 s = bfd_get_linker_section (dynobj, ".interp");
7801 s->size = sizeof ELF_DYNAMIC_INTERPRETER;
7802 s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
7806 /* Set up .got offsets for local syms, and space for local dynamic
7808 for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link.next)
7810 struct elf_aarch64_local_symbol *locals = NULL;
7811 Elf_Internal_Shdr *symtab_hdr;
7815 if (!is_aarch64_elf (ibfd))
7818 for (s = ibfd->sections; s != NULL; s = s->next)
7820 struct elf_dyn_relocs *p;
7822 for (p = (struct elf_dyn_relocs *)
7823 (elf_section_data (s)->local_dynrel); p != NULL; p = p->next)
7825 if (!bfd_is_abs_section (p->sec)
7826 && bfd_is_abs_section (p->sec->output_section))
7828 /* Input section has been discarded, either because
7829 it is a copy of a linkonce section or due to
7830 linker script /DISCARD/, so we'll be discarding
7833 else if (p->count != 0)
7835 srel = elf_section_data (p->sec)->sreloc;
7836 srel->size += p->count * RELOC_SIZE (htab);
7837 if ((p->sec->output_section->flags & SEC_READONLY) != 0)
7838 info->flags |= DF_TEXTREL;
7843 locals = elf_aarch64_locals (ibfd);
7847 symtab_hdr = &elf_symtab_hdr (ibfd);
7848 srel = htab->root.srelgot;
7849 for (i = 0; i < symtab_hdr->sh_info; i++)
7851 locals[i].got_offset = (bfd_vma) - 1;
7852 locals[i].tlsdesc_got_jump_table_offset = (bfd_vma) - 1;
7853 if (locals[i].got_refcount > 0)
7855 unsigned got_type = locals[i].got_type;
7856 if (got_type & GOT_TLSDESC_GD)
7858 locals[i].tlsdesc_got_jump_table_offset =
7859 (htab->root.sgotplt->size
7860 - aarch64_compute_jump_table_size (htab));
7861 htab->root.sgotplt->size += GOT_ENTRY_SIZE * 2;
7862 locals[i].got_offset = (bfd_vma) - 2;
7865 if (got_type & GOT_TLS_GD)
7867 locals[i].got_offset = htab->root.sgot->size;
7868 htab->root.sgot->size += GOT_ENTRY_SIZE * 2;
7871 if (got_type & GOT_TLS_IE
7872 || got_type & GOT_NORMAL)
7874 locals[i].got_offset = htab->root.sgot->size;
7875 htab->root.sgot->size += GOT_ENTRY_SIZE;
7878 if (got_type == GOT_UNKNOWN)
7882 if (bfd_link_pic (info))
7884 if (got_type & GOT_TLSDESC_GD)
7886 htab->root.srelplt->size += RELOC_SIZE (htab);
7887 /* Note RELOC_COUNT not incremented here! */
7888 htab->tlsdesc_plt = (bfd_vma) - 1;
7891 if (got_type & GOT_TLS_GD)
7892 htab->root.srelgot->size += RELOC_SIZE (htab) * 2;
7894 if (got_type & GOT_TLS_IE
7895 || got_type & GOT_NORMAL)
7896 htab->root.srelgot->size += RELOC_SIZE (htab);
7901 locals[i].got_refcount = (bfd_vma) - 1;
7907 /* Allocate global sym .plt and .got entries, and space for global
7908 sym dynamic relocs. */
7909 elf_link_hash_traverse (&htab->root, elfNN_aarch64_allocate_dynrelocs,
7912 /* Allocate global ifunc sym .plt and .got entries, and space for global
7913 ifunc sym dynamic relocs. */
7914 elf_link_hash_traverse (&htab->root, elfNN_aarch64_allocate_ifunc_dynrelocs,
7917 /* Allocate .plt and .got entries, and space for local symbols. */
7918 htab_traverse (htab->loc_hash_table,
7919 elfNN_aarch64_allocate_local_dynrelocs,
7922 /* Allocate .plt and .got entries, and space for local ifunc symbols. */
7923 htab_traverse (htab->loc_hash_table,
7924 elfNN_aarch64_allocate_local_ifunc_dynrelocs,
7927 /* For every jump slot reserved in the sgotplt, reloc_count is
7928 incremented. However, when we reserve space for TLS descriptors,
7929 it's not incremented, so in order to compute the space reserved
7930 for them, it suffices to multiply the reloc count by the jump
7933 if (htab->root.srelplt)
7934 htab->sgotplt_jump_table_size = aarch64_compute_jump_table_size (htab);
7936 if (htab->tlsdesc_plt)
7938 if (htab->root.splt->size == 0)
7939 htab->root.splt->size += PLT_ENTRY_SIZE;
7941 htab->tlsdesc_plt = htab->root.splt->size;
7942 htab->root.splt->size += PLT_TLSDESC_ENTRY_SIZE;
7944 /* If we're not using lazy TLS relocations, don't generate the
7945 GOT entry required. */
7946 if (!(info->flags & DF_BIND_NOW))
7948 htab->dt_tlsdesc_got = htab->root.sgot->size;
7949 htab->root.sgot->size += GOT_ENTRY_SIZE;
7953 /* Init mapping symbols information to use later to distingush between
7954 code and data while scanning for errata. */
7955 if (htab->fix_erratum_835769 || htab->fix_erratum_843419)
7956 for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link.next)
7958 if (!is_aarch64_elf (ibfd))
7960 bfd_elfNN_aarch64_init_maps (ibfd);
7963 /* We now have determined the sizes of the various dynamic sections.
7964 Allocate memory for them. */
7966 for (s = dynobj->sections; s != NULL; s = s->next)
7968 if ((s->flags & SEC_LINKER_CREATED) == 0)
7971 if (s == htab->root.splt
7972 || s == htab->root.sgot
7973 || s == htab->root.sgotplt
7974 || s == htab->root.iplt
7975 || s == htab->root.igotplt || s == htab->sdynbss)
7977 /* Strip this section if we don't need it; see the
7980 else if (CONST_STRNEQ (bfd_get_section_name (dynobj, s), ".rela"))
7982 if (s->size != 0 && s != htab->root.srelplt)
7985 /* We use the reloc_count field as a counter if we need
7986 to copy relocs into the output file. */
7987 if (s != htab->root.srelplt)
7992 /* It's not one of our sections, so don't allocate space. */
7998 /* If we don't need this section, strip it from the
7999 output file. This is mostly to handle .rela.bss and
8000 .rela.plt. We must create both sections in
8001 create_dynamic_sections, because they must be created
8002 before the linker maps input sections to output
8003 sections. The linker does that before
8004 adjust_dynamic_symbol is called, and it is that
8005 function which decides whether anything needs to go
8006 into these sections. */
8008 s->flags |= SEC_EXCLUDE;
8012 if ((s->flags & SEC_HAS_CONTENTS) == 0)
8015 /* Allocate memory for the section contents. We use bfd_zalloc
8016 here in case unused entries are not reclaimed before the
8017 section's contents are written out. This should not happen,
8018 but this way if it does, we get a R_AARCH64_NONE reloc instead
8020 s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->size);
8021 if (s->contents == NULL)
8025 if (htab->root.dynamic_sections_created)
8027 /* Add some entries to the .dynamic section. We fill in the
8028 values later, in elfNN_aarch64_finish_dynamic_sections, but we
8029 must add the entries now so that we get the correct size for
8030 the .dynamic section. The DT_DEBUG entry is filled in by the
8031 dynamic linker and used by the debugger. */
8032 #define add_dynamic_entry(TAG, VAL) \
8033 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
8035 if (bfd_link_executable (info))
8037 if (!add_dynamic_entry (DT_DEBUG, 0))
8041 if (htab->root.splt->size != 0)
8043 if (!add_dynamic_entry (DT_PLTGOT, 0)
8044 || !add_dynamic_entry (DT_PLTRELSZ, 0)
8045 || !add_dynamic_entry (DT_PLTREL, DT_RELA)
8046 || !add_dynamic_entry (DT_JMPREL, 0))
8049 if (htab->tlsdesc_plt
8050 && (!add_dynamic_entry (DT_TLSDESC_PLT, 0)
8051 || !add_dynamic_entry (DT_TLSDESC_GOT, 0)))
8057 if (!add_dynamic_entry (DT_RELA, 0)
8058 || !add_dynamic_entry (DT_RELASZ, 0)
8059 || !add_dynamic_entry (DT_RELAENT, RELOC_SIZE (htab)))
8062 /* If any dynamic relocs apply to a read-only section,
8063 then we need a DT_TEXTREL entry. */
8064 if ((info->flags & DF_TEXTREL) == 0)
8065 elf_link_hash_traverse (& htab->root, aarch64_readonly_dynrelocs,
8068 if ((info->flags & DF_TEXTREL) != 0)
8070 if (!add_dynamic_entry (DT_TEXTREL, 0))
8075 #undef add_dynamic_entry
8081 elf_aarch64_update_plt_entry (bfd *output_bfd,
8082 bfd_reloc_code_real_type r_type,
8083 bfd_byte *plt_entry, bfd_vma value)
8085 reloc_howto_type *howto = elfNN_aarch64_howto_from_bfd_reloc (r_type);
8087 _bfd_aarch64_elf_put_addend (output_bfd, plt_entry, r_type, howto, value);
8091 elfNN_aarch64_create_small_pltn_entry (struct elf_link_hash_entry *h,
8092 struct elf_aarch64_link_hash_table
8093 *htab, bfd *output_bfd,
8094 struct bfd_link_info *info)
8096 bfd_byte *plt_entry;
8099 bfd_vma gotplt_entry_address;
8100 bfd_vma plt_entry_address;
8101 Elf_Internal_Rela rela;
8103 asection *plt, *gotplt, *relplt;
8105 /* When building a static executable, use .iplt, .igot.plt and
8106 .rela.iplt sections for STT_GNU_IFUNC symbols. */
8107 if (htab->root.splt != NULL)
8109 plt = htab->root.splt;
8110 gotplt = htab->root.sgotplt;
8111 relplt = htab->root.srelplt;
8115 plt = htab->root.iplt;
8116 gotplt = htab->root.igotplt;
8117 relplt = htab->root.irelplt;
8120 /* Get the index in the procedure linkage table which
8121 corresponds to this symbol. This is the index of this symbol
8122 in all the symbols for which we are making plt entries. The
8123 first entry in the procedure linkage table is reserved.
8125 Get the offset into the .got table of the entry that
8126 corresponds to this function. Each .got entry is GOT_ENTRY_SIZE
8127 bytes. The first three are reserved for the dynamic linker.
8129 For static executables, we don't reserve anything. */
8131 if (plt == htab->root.splt)
8133 plt_index = (h->plt.offset - htab->plt_header_size) / htab->plt_entry_size;
8134 got_offset = (plt_index + 3) * GOT_ENTRY_SIZE;
8138 plt_index = h->plt.offset / htab->plt_entry_size;
8139 got_offset = plt_index * GOT_ENTRY_SIZE;
8142 plt_entry = plt->contents + h->plt.offset;
8143 plt_entry_address = plt->output_section->vma
8144 + plt->output_offset + h->plt.offset;
8145 gotplt_entry_address = gotplt->output_section->vma +
8146 gotplt->output_offset + got_offset;
8148 /* Copy in the boiler-plate for the PLTn entry. */
8149 memcpy (plt_entry, elfNN_aarch64_small_plt_entry, PLT_SMALL_ENTRY_SIZE);
8151 /* Fill in the top 21 bits for this: ADRP x16, PLT_GOT + n * 8.
8152 ADRP: ((PG(S+A)-PG(P)) >> 12) & 0x1fffff */
8153 elf_aarch64_update_plt_entry (output_bfd, BFD_RELOC_AARCH64_ADR_HI21_PCREL,
8155 PG (gotplt_entry_address) -
8156 PG (plt_entry_address));
8158 /* Fill in the lo12 bits for the load from the pltgot. */
8159 elf_aarch64_update_plt_entry (output_bfd, BFD_RELOC_AARCH64_LDSTNN_LO12,
8161 PG_OFFSET (gotplt_entry_address));
8163 /* Fill in the lo12 bits for the add from the pltgot entry. */
8164 elf_aarch64_update_plt_entry (output_bfd, BFD_RELOC_AARCH64_ADD_LO12,
8166 PG_OFFSET (gotplt_entry_address));
8168 /* All the GOTPLT Entries are essentially initialized to PLT0. */
8169 bfd_put_NN (output_bfd,
8170 plt->output_section->vma + plt->output_offset,
8171 gotplt->contents + got_offset);
8173 rela.r_offset = gotplt_entry_address;
8175 if (h->dynindx == -1
8176 || ((bfd_link_executable (info)
8177 || ELF_ST_VISIBILITY (h->other) != STV_DEFAULT)
8179 && h->type == STT_GNU_IFUNC))
8181 /* If an STT_GNU_IFUNC symbol is locally defined, generate
8182 R_AARCH64_IRELATIVE instead of R_AARCH64_JUMP_SLOT. */
8183 rela.r_info = ELFNN_R_INFO (0, AARCH64_R (IRELATIVE));
8184 rela.r_addend = (h->root.u.def.value
8185 + h->root.u.def.section->output_section->vma
8186 + h->root.u.def.section->output_offset);
8190 /* Fill in the entry in the .rela.plt section. */
8191 rela.r_info = ELFNN_R_INFO (h->dynindx, AARCH64_R (JUMP_SLOT));
8195 /* Compute the relocation entry to used based on PLT index and do
8196 not adjust reloc_count. The reloc_count has already been adjusted
8197 to account for this entry. */
8198 loc = relplt->contents + plt_index * RELOC_SIZE (htab);
8199 bfd_elfNN_swap_reloca_out (output_bfd, &rela, loc);
8202 /* Size sections even though they're not dynamic. We use it to setup
8203 _TLS_MODULE_BASE_, if needed. */
8206 elfNN_aarch64_always_size_sections (bfd *output_bfd,
8207 struct bfd_link_info *info)
8211 if (bfd_link_relocatable (info))
8214 tls_sec = elf_hash_table (info)->tls_sec;
8218 struct elf_link_hash_entry *tlsbase;
8220 tlsbase = elf_link_hash_lookup (elf_hash_table (info),
8221 "_TLS_MODULE_BASE_", TRUE, TRUE, FALSE);
8225 struct bfd_link_hash_entry *h = NULL;
8226 const struct elf_backend_data *bed =
8227 get_elf_backend_data (output_bfd);
8229 if (!(_bfd_generic_link_add_one_symbol
8230 (info, output_bfd, "_TLS_MODULE_BASE_", BSF_LOCAL,
8231 tls_sec, 0, NULL, FALSE, bed->collect, &h)))
8234 tlsbase->type = STT_TLS;
8235 tlsbase = (struct elf_link_hash_entry *) h;
8236 tlsbase->def_regular = 1;
8237 tlsbase->other = STV_HIDDEN;
8238 (*bed->elf_backend_hide_symbol) (info, tlsbase, TRUE);
8245 /* Finish up dynamic symbol handling. We set the contents of various
8246 dynamic sections here. */
8248 elfNN_aarch64_finish_dynamic_symbol (bfd *output_bfd,
8249 struct bfd_link_info *info,
8250 struct elf_link_hash_entry *h,
8251 Elf_Internal_Sym *sym)
8253 struct elf_aarch64_link_hash_table *htab;
8254 htab = elf_aarch64_hash_table (info);
8256 if (h->plt.offset != (bfd_vma) - 1)
8258 asection *plt, *gotplt, *relplt;
8260 /* This symbol has an entry in the procedure linkage table. Set
8263 /* When building a static executable, use .iplt, .igot.plt and
8264 .rela.iplt sections for STT_GNU_IFUNC symbols. */
8265 if (htab->root.splt != NULL)
8267 plt = htab->root.splt;
8268 gotplt = htab->root.sgotplt;
8269 relplt = htab->root.srelplt;
8273 plt = htab->root.iplt;
8274 gotplt = htab->root.igotplt;
8275 relplt = htab->root.irelplt;
8278 /* This symbol has an entry in the procedure linkage table. Set
8280 if ((h->dynindx == -1
8281 && !((h->forced_local || bfd_link_executable (info))
8283 && h->type == STT_GNU_IFUNC))
8289 elfNN_aarch64_create_small_pltn_entry (h, htab, output_bfd, info);
8290 if (!h->def_regular)
8292 /* Mark the symbol as undefined, rather than as defined in
8293 the .plt section. */
8294 sym->st_shndx = SHN_UNDEF;
8295 /* If the symbol is weak we need to clear the value.
8296 Otherwise, the PLT entry would provide a definition for
8297 the symbol even if the symbol wasn't defined anywhere,
8298 and so the symbol would never be NULL. Leave the value if
8299 there were any relocations where pointer equality matters
8300 (this is a clue for the dynamic linker, to make function
8301 pointer comparisons work between an application and shared
8303 if (!h->ref_regular_nonweak || !h->pointer_equality_needed)
8308 if (h->got.offset != (bfd_vma) - 1
8309 && elf_aarch64_hash_entry (h)->got_type == GOT_NORMAL)
8311 Elf_Internal_Rela rela;
8314 /* This symbol has an entry in the global offset table. Set it
8316 if (htab->root.sgot == NULL || htab->root.srelgot == NULL)
8319 rela.r_offset = (htab->root.sgot->output_section->vma
8320 + htab->root.sgot->output_offset
8321 + (h->got.offset & ~(bfd_vma) 1));
8324 && h->type == STT_GNU_IFUNC)
8326 if (bfd_link_pic (info))
8328 /* Generate R_AARCH64_GLOB_DAT. */
8335 if (!h->pointer_equality_needed)
8338 /* For non-shared object, we can't use .got.plt, which
8339 contains the real function address if we need pointer
8340 equality. We load the GOT entry with the PLT entry. */
8341 plt = htab->root.splt ? htab->root.splt : htab->root.iplt;
8342 bfd_put_NN (output_bfd, (plt->output_section->vma
8343 + plt->output_offset
8345 htab->root.sgot->contents
8346 + (h->got.offset & ~(bfd_vma) 1));
8350 else if (bfd_link_pic (info) && SYMBOL_REFERENCES_LOCAL (info, h))
8352 if (!h->def_regular)
8355 BFD_ASSERT ((h->got.offset & 1) != 0);
8356 rela.r_info = ELFNN_R_INFO (0, AARCH64_R (RELATIVE));
8357 rela.r_addend = (h->root.u.def.value
8358 + h->root.u.def.section->output_section->vma
8359 + h->root.u.def.section->output_offset);
8364 BFD_ASSERT ((h->got.offset & 1) == 0);
8365 bfd_put_NN (output_bfd, (bfd_vma) 0,
8366 htab->root.sgot->contents + h->got.offset);
8367 rela.r_info = ELFNN_R_INFO (h->dynindx, AARCH64_R (GLOB_DAT));
8371 loc = htab->root.srelgot->contents;
8372 loc += htab->root.srelgot->reloc_count++ * RELOC_SIZE (htab);
8373 bfd_elfNN_swap_reloca_out (output_bfd, &rela, loc);
8378 Elf_Internal_Rela rela;
8381 /* This symbol needs a copy reloc. Set it up. */
8383 if (h->dynindx == -1
8384 || (h->root.type != bfd_link_hash_defined
8385 && h->root.type != bfd_link_hash_defweak)
8386 || htab->srelbss == NULL)
8389 rela.r_offset = (h->root.u.def.value
8390 + h->root.u.def.section->output_section->vma
8391 + h->root.u.def.section->output_offset);
8392 rela.r_info = ELFNN_R_INFO (h->dynindx, AARCH64_R (COPY));
8394 loc = htab->srelbss->contents;
8395 loc += htab->srelbss->reloc_count++ * RELOC_SIZE (htab);
8396 bfd_elfNN_swap_reloca_out (output_bfd, &rela, loc);
8399 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. SYM may
8400 be NULL for local symbols. */
8402 && (h == elf_hash_table (info)->hdynamic
8403 || h == elf_hash_table (info)->hgot))
8404 sym->st_shndx = SHN_ABS;
8409 /* Finish up local dynamic symbol handling. We set the contents of
8410 various dynamic sections here. */
8413 elfNN_aarch64_finish_local_dynamic_symbol (void **slot, void *inf)
8415 struct elf_link_hash_entry *h
8416 = (struct elf_link_hash_entry *) *slot;
8417 struct bfd_link_info *info
8418 = (struct bfd_link_info *) inf;
8420 return elfNN_aarch64_finish_dynamic_symbol (info->output_bfd,
8425 elfNN_aarch64_init_small_plt0_entry (bfd *output_bfd ATTRIBUTE_UNUSED,
8426 struct elf_aarch64_link_hash_table
8429 /* Fill in PLT0. Fixme:RR Note this doesn't distinguish between
8430 small and large plts and at the minute just generates
8433 /* PLT0 of the small PLT looks like this in ELF64 -
8434 stp x16, x30, [sp, #-16]! // Save the reloc and lr on stack.
8435 adrp x16, PLT_GOT + 16 // Get the page base of the GOTPLT
8436 ldr x17, [x16, #:lo12:PLT_GOT+16] // Load the address of the
8438 add x16, x16, #:lo12:PLT_GOT+16 // Load the lo12 bits of the
8439 // GOTPLT entry for this.
8441 PLT0 will be slightly different in ELF32 due to different got entry
8444 bfd_vma plt_got_2nd_ent; /* Address of GOT[2]. */
8448 memcpy (htab->root.splt->contents, elfNN_aarch64_small_plt0_entry,
8450 elf_section_data (htab->root.splt->output_section)->this_hdr.sh_entsize =
8453 plt_got_2nd_ent = (htab->root.sgotplt->output_section->vma
8454 + htab->root.sgotplt->output_offset
8455 + GOT_ENTRY_SIZE * 2);
8457 plt_base = htab->root.splt->output_section->vma +
8458 htab->root.splt->output_offset;
8460 /* Fill in the top 21 bits for this: ADRP x16, PLT_GOT + n * 8.
8461 ADRP: ((PG(S+A)-PG(P)) >> 12) & 0x1fffff */
8462 elf_aarch64_update_plt_entry (output_bfd, BFD_RELOC_AARCH64_ADR_HI21_PCREL,
8463 htab->root.splt->contents + 4,
8464 PG (plt_got_2nd_ent) - PG (plt_base + 4));
8466 elf_aarch64_update_plt_entry (output_bfd, BFD_RELOC_AARCH64_LDSTNN_LO12,
8467 htab->root.splt->contents + 8,
8468 PG_OFFSET (plt_got_2nd_ent));
8470 elf_aarch64_update_plt_entry (output_bfd, BFD_RELOC_AARCH64_ADD_LO12,
8471 htab->root.splt->contents + 12,
8472 PG_OFFSET (plt_got_2nd_ent));
8476 elfNN_aarch64_finish_dynamic_sections (bfd *output_bfd,
8477 struct bfd_link_info *info)
8479 struct elf_aarch64_link_hash_table *htab;
8483 htab = elf_aarch64_hash_table (info);
8484 dynobj = htab->root.dynobj;
8485 sdyn = bfd_get_linker_section (dynobj, ".dynamic");
8487 if (htab->root.dynamic_sections_created)
8489 ElfNN_External_Dyn *dyncon, *dynconend;
8491 if (sdyn == NULL || htab->root.sgot == NULL)
8494 dyncon = (ElfNN_External_Dyn *) sdyn->contents;
8495 dynconend = (ElfNN_External_Dyn *) (sdyn->contents + sdyn->size);
8496 for (; dyncon < dynconend; dyncon++)
8498 Elf_Internal_Dyn dyn;
8501 bfd_elfNN_swap_dyn_in (dynobj, dyncon, &dyn);
8509 s = htab->root.sgotplt;
8510 dyn.d_un.d_ptr = s->output_section->vma + s->output_offset;
8514 dyn.d_un.d_ptr = htab->root.srelplt->output_section->vma;
8518 s = htab->root.srelplt;
8519 dyn.d_un.d_val = s->size;
8523 /* The procedure linkage table relocs (DT_JMPREL) should
8524 not be included in the overall relocs (DT_RELA).
8525 Therefore, we override the DT_RELASZ entry here to
8526 make it not include the JMPREL relocs. Since the
8527 linker script arranges for .rela.plt to follow all
8528 other relocation sections, we don't have to worry
8529 about changing the DT_RELA entry. */
8530 if (htab->root.srelplt != NULL)
8532 s = htab->root.srelplt;
8533 dyn.d_un.d_val -= s->size;
8537 case DT_TLSDESC_PLT:
8538 s = htab->root.splt;
8539 dyn.d_un.d_ptr = s->output_section->vma + s->output_offset
8540 + htab->tlsdesc_plt;
8543 case DT_TLSDESC_GOT:
8544 s = htab->root.sgot;
8545 dyn.d_un.d_ptr = s->output_section->vma + s->output_offset
8546 + htab->dt_tlsdesc_got;
8550 bfd_elfNN_swap_dyn_out (output_bfd, &dyn, dyncon);
8555 /* Fill in the special first entry in the procedure linkage table. */
8556 if (htab->root.splt && htab->root.splt->size > 0)
8558 elfNN_aarch64_init_small_plt0_entry (output_bfd, htab);
8560 elf_section_data (htab->root.splt->output_section)->
8561 this_hdr.sh_entsize = htab->plt_entry_size;
8564 if (htab->tlsdesc_plt)
8566 bfd_put_NN (output_bfd, (bfd_vma) 0,
8567 htab->root.sgot->contents + htab->dt_tlsdesc_got);
8569 memcpy (htab->root.splt->contents + htab->tlsdesc_plt,
8570 elfNN_aarch64_tlsdesc_small_plt_entry,
8571 sizeof (elfNN_aarch64_tlsdesc_small_plt_entry));
8574 bfd_vma adrp1_addr =
8575 htab->root.splt->output_section->vma
8576 + htab->root.splt->output_offset + htab->tlsdesc_plt + 4;
8578 bfd_vma adrp2_addr = adrp1_addr + 4;
8581 htab->root.sgot->output_section->vma
8582 + htab->root.sgot->output_offset;
8584 bfd_vma pltgot_addr =
8585 htab->root.sgotplt->output_section->vma
8586 + htab->root.sgotplt->output_offset;
8588 bfd_vma dt_tlsdesc_got = got_addr + htab->dt_tlsdesc_got;
8590 bfd_byte *plt_entry =
8591 htab->root.splt->contents + htab->tlsdesc_plt;
8593 /* adrp x2, DT_TLSDESC_GOT */
8594 elf_aarch64_update_plt_entry (output_bfd,
8595 BFD_RELOC_AARCH64_ADR_HI21_PCREL,
8597 (PG (dt_tlsdesc_got)
8598 - PG (adrp1_addr)));
8601 elf_aarch64_update_plt_entry (output_bfd,
8602 BFD_RELOC_AARCH64_ADR_HI21_PCREL,
8605 - PG (adrp2_addr)));
8607 /* ldr x2, [x2, #0] */
8608 elf_aarch64_update_plt_entry (output_bfd,
8609 BFD_RELOC_AARCH64_LDSTNN_LO12,
8611 PG_OFFSET (dt_tlsdesc_got));
8614 elf_aarch64_update_plt_entry (output_bfd,
8615 BFD_RELOC_AARCH64_ADD_LO12,
8617 PG_OFFSET (pltgot_addr));
8622 if (htab->root.sgotplt)
8624 if (bfd_is_abs_section (htab->root.sgotplt->output_section))
8626 (*_bfd_error_handler)
8627 (_("discarded output section: `%A'"), htab->root.sgotplt);
8631 /* Fill in the first three entries in the global offset table. */
8632 if (htab->root.sgotplt->size > 0)
8634 bfd_put_NN (output_bfd, (bfd_vma) 0, htab->root.sgotplt->contents);
8636 /* Write GOT[1] and GOT[2], needed for the dynamic linker. */
8637 bfd_put_NN (output_bfd,
8639 htab->root.sgotplt->contents + GOT_ENTRY_SIZE);
8640 bfd_put_NN (output_bfd,
8642 htab->root.sgotplt->contents + GOT_ENTRY_SIZE * 2);
8645 if (htab->root.sgot)
8647 if (htab->root.sgot->size > 0)
8650 sdyn ? sdyn->output_section->vma + sdyn->output_offset : 0;
8651 bfd_put_NN (output_bfd, addr, htab->root.sgot->contents);
8655 elf_section_data (htab->root.sgotplt->output_section)->
8656 this_hdr.sh_entsize = GOT_ENTRY_SIZE;
8659 if (htab->root.sgot && htab->root.sgot->size > 0)
8660 elf_section_data (htab->root.sgot->output_section)->this_hdr.sh_entsize
8663 /* Fill PLT and GOT entries for local STT_GNU_IFUNC symbols. */
8664 htab_traverse (htab->loc_hash_table,
8665 elfNN_aarch64_finish_local_dynamic_symbol,
8671 /* Return address for Ith PLT stub in section PLT, for relocation REL
8672 or (bfd_vma) -1 if it should not be included. */
8675 elfNN_aarch64_plt_sym_val (bfd_vma i, const asection *plt,
8676 const arelent *rel ATTRIBUTE_UNUSED)
8678 return plt->vma + PLT_ENTRY_SIZE + i * PLT_SMALL_ENTRY_SIZE;
8682 /* We use this so we can override certain functions
8683 (though currently we don't). */
8685 const struct elf_size_info elfNN_aarch64_size_info =
8687 sizeof (ElfNN_External_Ehdr),
8688 sizeof (ElfNN_External_Phdr),
8689 sizeof (ElfNN_External_Shdr),
8690 sizeof (ElfNN_External_Rel),
8691 sizeof (ElfNN_External_Rela),
8692 sizeof (ElfNN_External_Sym),
8693 sizeof (ElfNN_External_Dyn),
8694 sizeof (Elf_External_Note),
8695 4, /* Hash table entry size. */
8696 1, /* Internal relocs per external relocs. */
8697 ARCH_SIZE, /* Arch size. */
8698 LOG_FILE_ALIGN, /* Log_file_align. */
8699 ELFCLASSNN, EV_CURRENT,
8700 bfd_elfNN_write_out_phdrs,
8701 bfd_elfNN_write_shdrs_and_ehdr,
8702 bfd_elfNN_checksum_contents,
8703 bfd_elfNN_write_relocs,
8704 bfd_elfNN_swap_symbol_in,
8705 bfd_elfNN_swap_symbol_out,
8706 bfd_elfNN_slurp_reloc_table,
8707 bfd_elfNN_slurp_symbol_table,
8708 bfd_elfNN_swap_dyn_in,
8709 bfd_elfNN_swap_dyn_out,
8710 bfd_elfNN_swap_reloc_in,
8711 bfd_elfNN_swap_reloc_out,
8712 bfd_elfNN_swap_reloca_in,
8713 bfd_elfNN_swap_reloca_out
8716 #define ELF_ARCH bfd_arch_aarch64
8717 #define ELF_MACHINE_CODE EM_AARCH64
8718 #define ELF_MAXPAGESIZE 0x10000
8719 #define ELF_MINPAGESIZE 0x1000
8720 #define ELF_COMMONPAGESIZE 0x1000
8722 #define bfd_elfNN_close_and_cleanup \
8723 elfNN_aarch64_close_and_cleanup
8725 #define bfd_elfNN_bfd_free_cached_info \
8726 elfNN_aarch64_bfd_free_cached_info
8728 #define bfd_elfNN_bfd_is_target_special_symbol \
8729 elfNN_aarch64_is_target_special_symbol
8731 #define bfd_elfNN_bfd_link_hash_table_create \
8732 elfNN_aarch64_link_hash_table_create
8734 #define bfd_elfNN_bfd_merge_private_bfd_data \
8735 elfNN_aarch64_merge_private_bfd_data
8737 #define bfd_elfNN_bfd_print_private_bfd_data \
8738 elfNN_aarch64_print_private_bfd_data
8740 #define bfd_elfNN_bfd_reloc_type_lookup \
8741 elfNN_aarch64_reloc_type_lookup
8743 #define bfd_elfNN_bfd_reloc_name_lookup \
8744 elfNN_aarch64_reloc_name_lookup
8746 #define bfd_elfNN_bfd_set_private_flags \
8747 elfNN_aarch64_set_private_flags
8749 #define bfd_elfNN_find_inliner_info \
8750 elfNN_aarch64_find_inliner_info
8752 #define bfd_elfNN_find_nearest_line \
8753 elfNN_aarch64_find_nearest_line
8755 #define bfd_elfNN_mkobject \
8756 elfNN_aarch64_mkobject
8758 #define bfd_elfNN_new_section_hook \
8759 elfNN_aarch64_new_section_hook
8761 #define elf_backend_adjust_dynamic_symbol \
8762 elfNN_aarch64_adjust_dynamic_symbol
8764 #define elf_backend_always_size_sections \
8765 elfNN_aarch64_always_size_sections
8767 #define elf_backend_check_relocs \
8768 elfNN_aarch64_check_relocs
8770 #define elf_backend_copy_indirect_symbol \
8771 elfNN_aarch64_copy_indirect_symbol
8773 /* Create .dynbss, and .rela.bss sections in DYNOBJ, and set up shortcuts
8774 to them in our hash. */
8775 #define elf_backend_create_dynamic_sections \
8776 elfNN_aarch64_create_dynamic_sections
8778 #define elf_backend_init_index_section \
8779 _bfd_elf_init_2_index_sections
8781 #define elf_backend_finish_dynamic_sections \
8782 elfNN_aarch64_finish_dynamic_sections
8784 #define elf_backend_finish_dynamic_symbol \
8785 elfNN_aarch64_finish_dynamic_symbol
8787 #define elf_backend_gc_sweep_hook \
8788 elfNN_aarch64_gc_sweep_hook
8790 #define elf_backend_object_p \
8791 elfNN_aarch64_object_p
8793 #define elf_backend_output_arch_local_syms \
8794 elfNN_aarch64_output_arch_local_syms
8796 #define elf_backend_plt_sym_val \
8797 elfNN_aarch64_plt_sym_val
8799 #define elf_backend_post_process_headers \
8800 elfNN_aarch64_post_process_headers
8802 #define elf_backend_relocate_section \
8803 elfNN_aarch64_relocate_section
8805 #define elf_backend_reloc_type_class \
8806 elfNN_aarch64_reloc_type_class
8808 #define elf_backend_section_from_shdr \
8809 elfNN_aarch64_section_from_shdr
8811 #define elf_backend_size_dynamic_sections \
8812 elfNN_aarch64_size_dynamic_sections
8814 #define elf_backend_size_info \
8815 elfNN_aarch64_size_info
8817 #define elf_backend_write_section \
8818 elfNN_aarch64_write_section
8820 #define elf_backend_can_refcount 1
8821 #define elf_backend_can_gc_sections 1
8822 #define elf_backend_plt_readonly 1
8823 #define elf_backend_want_got_plt 1
8824 #define elf_backend_want_plt_sym 0
8825 #define elf_backend_may_use_rel_p 0
8826 #define elf_backend_may_use_rela_p 1
8827 #define elf_backend_default_use_rela_p 1
8828 #define elf_backend_rela_normal 1
8829 #define elf_backend_got_header_size (GOT_ENTRY_SIZE * 3)
8830 #define elf_backend_default_execstack 0
8831 #define elf_backend_extern_protected_data 1
8833 #undef elf_backend_obj_attrs_section
8834 #define elf_backend_obj_attrs_section ".ARM.attributes"
8836 #include "elfNN-target.h"