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_ADR_PAGE21 \
169 || (R_TYPE) == BFD_RELOC_AARCH64_TLSGD_ADR_PREL21 \
170 || (R_TYPE) == BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC \
171 || (R_TYPE) == BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G1 \
172 || (R_TYPE) == BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G0_NC \
173 || (R_TYPE) == BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21 \
174 || (R_TYPE) == BFD_RELOC_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC \
175 || (R_TYPE) == BFD_RELOC_AARCH64_TLSIE_LD32_GOTTPREL_LO12_NC \
176 || (R_TYPE) == BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19 \
177 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_LO12 \
178 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_HI12 \
179 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_LO12_NC \
180 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G2 \
181 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1 \
182 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1_NC \
183 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0 \
184 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC \
185 || (R_TYPE) == BFD_RELOC_AARCH64_TLS_DTPMOD \
186 || (R_TYPE) == BFD_RELOC_AARCH64_TLS_DTPREL \
187 || (R_TYPE) == BFD_RELOC_AARCH64_TLS_TPREL \
188 || IS_AARCH64_TLSDESC_RELOC ((R_TYPE)))
190 #define IS_AARCH64_TLSDESC_RELOC(R_TYPE) \
191 ((R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_LD_PREL19 \
192 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21 \
193 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21 \
194 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_ADD_LO12_NC \
195 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_LD64_LO12_NC \
196 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_LD32_LO12_NC \
197 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_OFF_G1 \
198 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_OFF_G0_NC \
199 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_LDR \
200 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_ADD \
201 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_CALL \
202 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC)
204 #define ELIMINATE_COPY_RELOCS 0
206 /* Return size of a relocation entry. HTAB is the bfd's
207 elf_aarch64_link_hash_entry. */
208 #define RELOC_SIZE(HTAB) (sizeof (ElfNN_External_Rela))
210 /* GOT Entry size - 8 bytes in ELF64 and 4 bytes in ELF32. */
211 #define GOT_ENTRY_SIZE (ARCH_SIZE / 8)
212 #define PLT_ENTRY_SIZE (32)
213 #define PLT_SMALL_ENTRY_SIZE (16)
214 #define PLT_TLSDESC_ENTRY_SIZE (32)
216 /* Encoding of the nop instruction */
217 #define INSN_NOP 0xd503201f
219 #define aarch64_compute_jump_table_size(htab) \
220 (((htab)->root.srelplt == NULL) ? 0 \
221 : (htab)->root.srelplt->reloc_count * GOT_ENTRY_SIZE)
223 /* The first entry in a procedure linkage table looks like this
224 if the distance between the PLTGOT and the PLT is < 4GB use
225 these PLT entries. Note that the dynamic linker gets &PLTGOT[2]
226 in x16 and needs to work out PLTGOT[1] by using an address of
227 [x16,#-GOT_ENTRY_SIZE]. */
228 static const bfd_byte elfNN_aarch64_small_plt0_entry
[PLT_ENTRY_SIZE
] =
230 0xf0, 0x7b, 0xbf, 0xa9, /* stp x16, x30, [sp, #-16]! */
231 0x10, 0x00, 0x00, 0x90, /* adrp x16, (GOT+16) */
233 0x11, 0x0A, 0x40, 0xf9, /* ldr x17, [x16, #PLT_GOT+0x10] */
234 0x10, 0x42, 0x00, 0x91, /* add x16, x16,#PLT_GOT+0x10 */
236 0x11, 0x0A, 0x40, 0xb9, /* ldr w17, [x16, #PLT_GOT+0x8] */
237 0x10, 0x22, 0x00, 0x11, /* add w16, w16,#PLT_GOT+0x8 */
239 0x20, 0x02, 0x1f, 0xd6, /* br x17 */
240 0x1f, 0x20, 0x03, 0xd5, /* nop */
241 0x1f, 0x20, 0x03, 0xd5, /* nop */
242 0x1f, 0x20, 0x03, 0xd5, /* nop */
245 /* Per function entry in a procedure linkage table looks like this
246 if the distance between the PLTGOT and the PLT is < 4GB use
247 these PLT entries. */
248 static const bfd_byte elfNN_aarch64_small_plt_entry
[PLT_SMALL_ENTRY_SIZE
] =
250 0x10, 0x00, 0x00, 0x90, /* adrp x16, PLTGOT + n * 8 */
252 0x11, 0x02, 0x40, 0xf9, /* ldr x17, [x16, PLTGOT + n * 8] */
253 0x10, 0x02, 0x00, 0x91, /* add x16, x16, :lo12:PLTGOT + n * 8 */
255 0x11, 0x02, 0x40, 0xb9, /* ldr w17, [x16, PLTGOT + n * 4] */
256 0x10, 0x02, 0x00, 0x11, /* add w16, w16, :lo12:PLTGOT + n * 4 */
258 0x20, 0x02, 0x1f, 0xd6, /* br x17. */
261 static const bfd_byte
262 elfNN_aarch64_tlsdesc_small_plt_entry
[PLT_TLSDESC_ENTRY_SIZE
] =
264 0xe2, 0x0f, 0xbf, 0xa9, /* stp x2, x3, [sp, #-16]! */
265 0x02, 0x00, 0x00, 0x90, /* adrp x2, 0 */
266 0x03, 0x00, 0x00, 0x90, /* adrp x3, 0 */
268 0x42, 0x00, 0x40, 0xf9, /* ldr x2, [x2, #0] */
269 0x63, 0x00, 0x00, 0x91, /* add x3, x3, 0 */
271 0x42, 0x00, 0x40, 0xb9, /* ldr w2, [x2, #0] */
272 0x63, 0x00, 0x00, 0x11, /* add w3, w3, 0 */
274 0x40, 0x00, 0x1f, 0xd6, /* br x2 */
275 0x1f, 0x20, 0x03, 0xd5, /* nop */
276 0x1f, 0x20, 0x03, 0xd5, /* nop */
279 #define elf_info_to_howto elfNN_aarch64_info_to_howto
280 #define elf_info_to_howto_rel elfNN_aarch64_info_to_howto
282 #define AARCH64_ELF_ABI_VERSION 0
284 /* In case we're on a 32-bit machine, construct a 64-bit "-1" value. */
285 #define ALL_ONES (~ (bfd_vma) 0)
287 /* Indexed by the bfd interal reloc enumerators.
288 Therefore, the table needs to be synced with BFD_RELOC_AARCH64_*
291 static reloc_howto_type elfNN_aarch64_howto_table
[] =
295 /* Basic data relocations. */
298 HOWTO (R_AARCH64_NULL
, /* type */
300 3, /* size (0 = byte, 1 = short, 2 = long) */
302 FALSE
, /* pc_relative */
304 complain_overflow_dont
, /* complain_on_overflow */
305 bfd_elf_generic_reloc
, /* special_function */
306 "R_AARCH64_NULL", /* name */
307 FALSE
, /* partial_inplace */
310 FALSE
), /* pcrel_offset */
312 HOWTO (R_AARCH64_NONE
, /* type */
314 3, /* size (0 = byte, 1 = short, 2 = long) */
316 FALSE
, /* pc_relative */
318 complain_overflow_dont
, /* complain_on_overflow */
319 bfd_elf_generic_reloc
, /* special_function */
320 "R_AARCH64_NONE", /* name */
321 FALSE
, /* partial_inplace */
324 FALSE
), /* pcrel_offset */
328 HOWTO64 (AARCH64_R (ABS64
), /* type */
330 4, /* size (4 = long long) */
332 FALSE
, /* pc_relative */
334 complain_overflow_unsigned
, /* complain_on_overflow */
335 bfd_elf_generic_reloc
, /* special_function */
336 AARCH64_R_STR (ABS64
), /* name */
337 FALSE
, /* partial_inplace */
338 ALL_ONES
, /* src_mask */
339 ALL_ONES
, /* dst_mask */
340 FALSE
), /* pcrel_offset */
343 HOWTO (AARCH64_R (ABS32
), /* type */
345 2, /* size (0 = byte, 1 = short, 2 = long) */
347 FALSE
, /* pc_relative */
349 complain_overflow_unsigned
, /* complain_on_overflow */
350 bfd_elf_generic_reloc
, /* special_function */
351 AARCH64_R_STR (ABS32
), /* name */
352 FALSE
, /* partial_inplace */
353 0xffffffff, /* src_mask */
354 0xffffffff, /* dst_mask */
355 FALSE
), /* pcrel_offset */
358 HOWTO (AARCH64_R (ABS16
), /* type */
360 1, /* size (0 = byte, 1 = short, 2 = long) */
362 FALSE
, /* pc_relative */
364 complain_overflow_unsigned
, /* complain_on_overflow */
365 bfd_elf_generic_reloc
, /* special_function */
366 AARCH64_R_STR (ABS16
), /* name */
367 FALSE
, /* partial_inplace */
368 0xffff, /* src_mask */
369 0xffff, /* dst_mask */
370 FALSE
), /* pcrel_offset */
372 /* .xword: (S+A-P) */
373 HOWTO64 (AARCH64_R (PREL64
), /* type */
375 4, /* size (4 = long long) */
377 TRUE
, /* pc_relative */
379 complain_overflow_signed
, /* complain_on_overflow */
380 bfd_elf_generic_reloc
, /* special_function */
381 AARCH64_R_STR (PREL64
), /* name */
382 FALSE
, /* partial_inplace */
383 ALL_ONES
, /* src_mask */
384 ALL_ONES
, /* dst_mask */
385 TRUE
), /* pcrel_offset */
388 HOWTO (AARCH64_R (PREL32
), /* type */
390 2, /* size (0 = byte, 1 = short, 2 = long) */
392 TRUE
, /* pc_relative */
394 complain_overflow_signed
, /* complain_on_overflow */
395 bfd_elf_generic_reloc
, /* special_function */
396 AARCH64_R_STR (PREL32
), /* name */
397 FALSE
, /* partial_inplace */
398 0xffffffff, /* src_mask */
399 0xffffffff, /* dst_mask */
400 TRUE
), /* pcrel_offset */
403 HOWTO (AARCH64_R (PREL16
), /* type */
405 1, /* size (0 = byte, 1 = short, 2 = long) */
407 TRUE
, /* pc_relative */
409 complain_overflow_signed
, /* complain_on_overflow */
410 bfd_elf_generic_reloc
, /* special_function */
411 AARCH64_R_STR (PREL16
), /* name */
412 FALSE
, /* partial_inplace */
413 0xffff, /* src_mask */
414 0xffff, /* dst_mask */
415 TRUE
), /* pcrel_offset */
417 /* Group relocations to create a 16, 32, 48 or 64 bit
418 unsigned data or abs address inline. */
420 /* MOVZ: ((S+A) >> 0) & 0xffff */
421 HOWTO (AARCH64_R (MOVW_UABS_G0
), /* type */
423 2, /* size (0 = byte, 1 = short, 2 = long) */
425 FALSE
, /* pc_relative */
427 complain_overflow_unsigned
, /* complain_on_overflow */
428 bfd_elf_generic_reloc
, /* special_function */
429 AARCH64_R_STR (MOVW_UABS_G0
), /* name */
430 FALSE
, /* partial_inplace */
431 0xffff, /* src_mask */
432 0xffff, /* dst_mask */
433 FALSE
), /* pcrel_offset */
435 /* MOVK: ((S+A) >> 0) & 0xffff [no overflow check] */
436 HOWTO (AARCH64_R (MOVW_UABS_G0_NC
), /* type */
438 2, /* size (0 = byte, 1 = short, 2 = long) */
440 FALSE
, /* pc_relative */
442 complain_overflow_dont
, /* complain_on_overflow */
443 bfd_elf_generic_reloc
, /* special_function */
444 AARCH64_R_STR (MOVW_UABS_G0_NC
), /* name */
445 FALSE
, /* partial_inplace */
446 0xffff, /* src_mask */
447 0xffff, /* dst_mask */
448 FALSE
), /* pcrel_offset */
450 /* MOVZ: ((S+A) >> 16) & 0xffff */
451 HOWTO (AARCH64_R (MOVW_UABS_G1
), /* type */
453 2, /* size (0 = byte, 1 = short, 2 = long) */
455 FALSE
, /* pc_relative */
457 complain_overflow_unsigned
, /* complain_on_overflow */
458 bfd_elf_generic_reloc
, /* special_function */
459 AARCH64_R_STR (MOVW_UABS_G1
), /* name */
460 FALSE
, /* partial_inplace */
461 0xffff, /* src_mask */
462 0xffff, /* dst_mask */
463 FALSE
), /* pcrel_offset */
465 /* MOVK: ((S+A) >> 16) & 0xffff [no overflow check] */
466 HOWTO64 (AARCH64_R (MOVW_UABS_G1_NC
), /* type */
468 2, /* size (0 = byte, 1 = short, 2 = long) */
470 FALSE
, /* pc_relative */
472 complain_overflow_dont
, /* complain_on_overflow */
473 bfd_elf_generic_reloc
, /* special_function */
474 AARCH64_R_STR (MOVW_UABS_G1_NC
), /* name */
475 FALSE
, /* partial_inplace */
476 0xffff, /* src_mask */
477 0xffff, /* dst_mask */
478 FALSE
), /* pcrel_offset */
480 /* MOVZ: ((S+A) >> 32) & 0xffff */
481 HOWTO64 (AARCH64_R (MOVW_UABS_G2
), /* type */
483 2, /* size (0 = byte, 1 = short, 2 = long) */
485 FALSE
, /* pc_relative */
487 complain_overflow_unsigned
, /* complain_on_overflow */
488 bfd_elf_generic_reloc
, /* special_function */
489 AARCH64_R_STR (MOVW_UABS_G2
), /* name */
490 FALSE
, /* partial_inplace */
491 0xffff, /* src_mask */
492 0xffff, /* dst_mask */
493 FALSE
), /* pcrel_offset */
495 /* MOVK: ((S+A) >> 32) & 0xffff [no overflow check] */
496 HOWTO64 (AARCH64_R (MOVW_UABS_G2_NC
), /* type */
498 2, /* size (0 = byte, 1 = short, 2 = long) */
500 FALSE
, /* pc_relative */
502 complain_overflow_dont
, /* complain_on_overflow */
503 bfd_elf_generic_reloc
, /* special_function */
504 AARCH64_R_STR (MOVW_UABS_G2_NC
), /* name */
505 FALSE
, /* partial_inplace */
506 0xffff, /* src_mask */
507 0xffff, /* dst_mask */
508 FALSE
), /* pcrel_offset */
510 /* MOVZ: ((S+A) >> 48) & 0xffff */
511 HOWTO64 (AARCH64_R (MOVW_UABS_G3
), /* type */
513 2, /* size (0 = byte, 1 = short, 2 = long) */
515 FALSE
, /* pc_relative */
517 complain_overflow_unsigned
, /* complain_on_overflow */
518 bfd_elf_generic_reloc
, /* special_function */
519 AARCH64_R_STR (MOVW_UABS_G3
), /* name */
520 FALSE
, /* partial_inplace */
521 0xffff, /* src_mask */
522 0xffff, /* dst_mask */
523 FALSE
), /* pcrel_offset */
525 /* Group relocations to create high part of a 16, 32, 48 or 64 bit
526 signed data or abs address inline. Will change instruction
527 to MOVN or MOVZ depending on sign of calculated value. */
529 /* MOV[ZN]: ((S+A) >> 0) & 0xffff */
530 HOWTO (AARCH64_R (MOVW_SABS_G0
), /* type */
532 2, /* size (0 = byte, 1 = short, 2 = long) */
534 FALSE
, /* pc_relative */
536 complain_overflow_signed
, /* complain_on_overflow */
537 bfd_elf_generic_reloc
, /* special_function */
538 AARCH64_R_STR (MOVW_SABS_G0
), /* name */
539 FALSE
, /* partial_inplace */
540 0xffff, /* src_mask */
541 0xffff, /* dst_mask */
542 FALSE
), /* pcrel_offset */
544 /* MOV[ZN]: ((S+A) >> 16) & 0xffff */
545 HOWTO64 (AARCH64_R (MOVW_SABS_G1
), /* type */
547 2, /* size (0 = byte, 1 = short, 2 = long) */
549 FALSE
, /* pc_relative */
551 complain_overflow_signed
, /* complain_on_overflow */
552 bfd_elf_generic_reloc
, /* special_function */
553 AARCH64_R_STR (MOVW_SABS_G1
), /* name */
554 FALSE
, /* partial_inplace */
555 0xffff, /* src_mask */
556 0xffff, /* dst_mask */
557 FALSE
), /* pcrel_offset */
559 /* MOV[ZN]: ((S+A) >> 32) & 0xffff */
560 HOWTO64 (AARCH64_R (MOVW_SABS_G2
), /* type */
562 2, /* size (0 = byte, 1 = short, 2 = long) */
564 FALSE
, /* pc_relative */
566 complain_overflow_signed
, /* complain_on_overflow */
567 bfd_elf_generic_reloc
, /* special_function */
568 AARCH64_R_STR (MOVW_SABS_G2
), /* name */
569 FALSE
, /* partial_inplace */
570 0xffff, /* src_mask */
571 0xffff, /* dst_mask */
572 FALSE
), /* pcrel_offset */
574 /* Relocations to generate 19, 21 and 33 bit PC-relative load/store
575 addresses: PG(x) is (x & ~0xfff). */
577 /* LD-lit: ((S+A-P) >> 2) & 0x7ffff */
578 HOWTO (AARCH64_R (LD_PREL_LO19
), /* type */
580 2, /* size (0 = byte, 1 = short, 2 = long) */
582 TRUE
, /* pc_relative */
584 complain_overflow_signed
, /* complain_on_overflow */
585 bfd_elf_generic_reloc
, /* special_function */
586 AARCH64_R_STR (LD_PREL_LO19
), /* name */
587 FALSE
, /* partial_inplace */
588 0x7ffff, /* src_mask */
589 0x7ffff, /* dst_mask */
590 TRUE
), /* pcrel_offset */
592 /* ADR: (S+A-P) & 0x1fffff */
593 HOWTO (AARCH64_R (ADR_PREL_LO21
), /* type */
595 2, /* size (0 = byte, 1 = short, 2 = long) */
597 TRUE
, /* pc_relative */
599 complain_overflow_signed
, /* complain_on_overflow */
600 bfd_elf_generic_reloc
, /* special_function */
601 AARCH64_R_STR (ADR_PREL_LO21
), /* name */
602 FALSE
, /* partial_inplace */
603 0x1fffff, /* src_mask */
604 0x1fffff, /* dst_mask */
605 TRUE
), /* pcrel_offset */
607 /* ADRP: ((PG(S+A)-PG(P)) >> 12) & 0x1fffff */
608 HOWTO (AARCH64_R (ADR_PREL_PG_HI21
), /* type */
610 2, /* size (0 = byte, 1 = short, 2 = long) */
612 TRUE
, /* pc_relative */
614 complain_overflow_signed
, /* complain_on_overflow */
615 bfd_elf_generic_reloc
, /* special_function */
616 AARCH64_R_STR (ADR_PREL_PG_HI21
), /* name */
617 FALSE
, /* partial_inplace */
618 0x1fffff, /* src_mask */
619 0x1fffff, /* dst_mask */
620 TRUE
), /* pcrel_offset */
622 /* ADRP: ((PG(S+A)-PG(P)) >> 12) & 0x1fffff [no overflow check] */
623 HOWTO64 (AARCH64_R (ADR_PREL_PG_HI21_NC
), /* type */
625 2, /* size (0 = byte, 1 = short, 2 = long) */
627 TRUE
, /* pc_relative */
629 complain_overflow_dont
, /* complain_on_overflow */
630 bfd_elf_generic_reloc
, /* special_function */
631 AARCH64_R_STR (ADR_PREL_PG_HI21_NC
), /* name */
632 FALSE
, /* partial_inplace */
633 0x1fffff, /* src_mask */
634 0x1fffff, /* dst_mask */
635 TRUE
), /* pcrel_offset */
637 /* ADD: (S+A) & 0xfff [no overflow check] */
638 HOWTO (AARCH64_R (ADD_ABS_LO12_NC
), /* type */
640 2, /* size (0 = byte, 1 = short, 2 = long) */
642 FALSE
, /* pc_relative */
644 complain_overflow_dont
, /* complain_on_overflow */
645 bfd_elf_generic_reloc
, /* special_function */
646 AARCH64_R_STR (ADD_ABS_LO12_NC
), /* name */
647 FALSE
, /* partial_inplace */
648 0x3ffc00, /* src_mask */
649 0x3ffc00, /* dst_mask */
650 FALSE
), /* pcrel_offset */
652 /* LD/ST8: (S+A) & 0xfff */
653 HOWTO (AARCH64_R (LDST8_ABS_LO12_NC
), /* type */
655 2, /* size (0 = byte, 1 = short, 2 = long) */
657 FALSE
, /* pc_relative */
659 complain_overflow_dont
, /* complain_on_overflow */
660 bfd_elf_generic_reloc
, /* special_function */
661 AARCH64_R_STR (LDST8_ABS_LO12_NC
), /* name */
662 FALSE
, /* partial_inplace */
663 0xfff, /* src_mask */
664 0xfff, /* dst_mask */
665 FALSE
), /* pcrel_offset */
667 /* Relocations for control-flow instructions. */
669 /* TBZ/NZ: ((S+A-P) >> 2) & 0x3fff */
670 HOWTO (AARCH64_R (TSTBR14
), /* type */
672 2, /* size (0 = byte, 1 = short, 2 = long) */
674 TRUE
, /* pc_relative */
676 complain_overflow_signed
, /* complain_on_overflow */
677 bfd_elf_generic_reloc
, /* special_function */
678 AARCH64_R_STR (TSTBR14
), /* name */
679 FALSE
, /* partial_inplace */
680 0x3fff, /* src_mask */
681 0x3fff, /* dst_mask */
682 TRUE
), /* pcrel_offset */
684 /* B.cond: ((S+A-P) >> 2) & 0x7ffff */
685 HOWTO (AARCH64_R (CONDBR19
), /* type */
687 2, /* size (0 = byte, 1 = short, 2 = long) */
689 TRUE
, /* pc_relative */
691 complain_overflow_signed
, /* complain_on_overflow */
692 bfd_elf_generic_reloc
, /* special_function */
693 AARCH64_R_STR (CONDBR19
), /* name */
694 FALSE
, /* partial_inplace */
695 0x7ffff, /* src_mask */
696 0x7ffff, /* dst_mask */
697 TRUE
), /* pcrel_offset */
699 /* B: ((S+A-P) >> 2) & 0x3ffffff */
700 HOWTO (AARCH64_R (JUMP26
), /* type */
702 2, /* size (0 = byte, 1 = short, 2 = long) */
704 TRUE
, /* pc_relative */
706 complain_overflow_signed
, /* complain_on_overflow */
707 bfd_elf_generic_reloc
, /* special_function */
708 AARCH64_R_STR (JUMP26
), /* name */
709 FALSE
, /* partial_inplace */
710 0x3ffffff, /* src_mask */
711 0x3ffffff, /* dst_mask */
712 TRUE
), /* pcrel_offset */
714 /* BL: ((S+A-P) >> 2) & 0x3ffffff */
715 HOWTO (AARCH64_R (CALL26
), /* type */
717 2, /* size (0 = byte, 1 = short, 2 = long) */
719 TRUE
, /* pc_relative */
721 complain_overflow_signed
, /* complain_on_overflow */
722 bfd_elf_generic_reloc
, /* special_function */
723 AARCH64_R_STR (CALL26
), /* name */
724 FALSE
, /* partial_inplace */
725 0x3ffffff, /* src_mask */
726 0x3ffffff, /* dst_mask */
727 TRUE
), /* pcrel_offset */
729 /* LD/ST16: (S+A) & 0xffe */
730 HOWTO (AARCH64_R (LDST16_ABS_LO12_NC
), /* type */
732 2, /* size (0 = byte, 1 = short, 2 = long) */
734 FALSE
, /* pc_relative */
736 complain_overflow_dont
, /* complain_on_overflow */
737 bfd_elf_generic_reloc
, /* special_function */
738 AARCH64_R_STR (LDST16_ABS_LO12_NC
), /* name */
739 FALSE
, /* partial_inplace */
740 0xffe, /* src_mask */
741 0xffe, /* dst_mask */
742 FALSE
), /* pcrel_offset */
744 /* LD/ST32: (S+A) & 0xffc */
745 HOWTO (AARCH64_R (LDST32_ABS_LO12_NC
), /* type */
747 2, /* size (0 = byte, 1 = short, 2 = long) */
749 FALSE
, /* pc_relative */
751 complain_overflow_dont
, /* complain_on_overflow */
752 bfd_elf_generic_reloc
, /* special_function */
753 AARCH64_R_STR (LDST32_ABS_LO12_NC
), /* name */
754 FALSE
, /* partial_inplace */
755 0xffc, /* src_mask */
756 0xffc, /* dst_mask */
757 FALSE
), /* pcrel_offset */
759 /* LD/ST64: (S+A) & 0xff8 */
760 HOWTO (AARCH64_R (LDST64_ABS_LO12_NC
), /* type */
762 2, /* size (0 = byte, 1 = short, 2 = long) */
764 FALSE
, /* pc_relative */
766 complain_overflow_dont
, /* complain_on_overflow */
767 bfd_elf_generic_reloc
, /* special_function */
768 AARCH64_R_STR (LDST64_ABS_LO12_NC
), /* name */
769 FALSE
, /* partial_inplace */
770 0xff8, /* src_mask */
771 0xff8, /* dst_mask */
772 FALSE
), /* pcrel_offset */
774 /* LD/ST128: (S+A) & 0xff0 */
775 HOWTO (AARCH64_R (LDST128_ABS_LO12_NC
), /* type */
777 2, /* size (0 = byte, 1 = short, 2 = long) */
779 FALSE
, /* pc_relative */
781 complain_overflow_dont
, /* complain_on_overflow */
782 bfd_elf_generic_reloc
, /* special_function */
783 AARCH64_R_STR (LDST128_ABS_LO12_NC
), /* name */
784 FALSE
, /* partial_inplace */
785 0xff0, /* src_mask */
786 0xff0, /* dst_mask */
787 FALSE
), /* pcrel_offset */
789 /* Set a load-literal immediate field to bits
790 0x1FFFFC of G(S)-P */
791 HOWTO (AARCH64_R (GOT_LD_PREL19
), /* type */
793 2, /* size (0 = byte,1 = short,2 = long) */
795 TRUE
, /* pc_relative */
797 complain_overflow_signed
, /* complain_on_overflow */
798 bfd_elf_generic_reloc
, /* special_function */
799 AARCH64_R_STR (GOT_LD_PREL19
), /* name */
800 FALSE
, /* partial_inplace */
801 0xffffe0, /* src_mask */
802 0xffffe0, /* dst_mask */
803 TRUE
), /* pcrel_offset */
805 /* Get to the page for the GOT entry for the symbol
806 (G(S) - P) using an ADRP instruction. */
807 HOWTO (AARCH64_R (ADR_GOT_PAGE
), /* type */
809 2, /* size (0 = byte, 1 = short, 2 = long) */
811 TRUE
, /* pc_relative */
813 complain_overflow_dont
, /* complain_on_overflow */
814 bfd_elf_generic_reloc
, /* special_function */
815 AARCH64_R_STR (ADR_GOT_PAGE
), /* name */
816 FALSE
, /* partial_inplace */
817 0x1fffff, /* src_mask */
818 0x1fffff, /* dst_mask */
819 TRUE
), /* pcrel_offset */
821 /* LD64: GOT offset G(S) & 0xff8 */
822 HOWTO64 (AARCH64_R (LD64_GOT_LO12_NC
), /* type */
824 2, /* size (0 = byte, 1 = short, 2 = long) */
826 FALSE
, /* pc_relative */
828 complain_overflow_dont
, /* complain_on_overflow */
829 bfd_elf_generic_reloc
, /* special_function */
830 AARCH64_R_STR (LD64_GOT_LO12_NC
), /* name */
831 FALSE
, /* partial_inplace */
832 0xff8, /* src_mask */
833 0xff8, /* dst_mask */
834 FALSE
), /* pcrel_offset */
836 /* LD32: GOT offset G(S) & 0xffc */
837 HOWTO32 (AARCH64_R (LD32_GOT_LO12_NC
), /* type */
839 2, /* size (0 = byte, 1 = short, 2 = long) */
841 FALSE
, /* pc_relative */
843 complain_overflow_dont
, /* complain_on_overflow */
844 bfd_elf_generic_reloc
, /* special_function */
845 AARCH64_R_STR (LD32_GOT_LO12_NC
), /* name */
846 FALSE
, /* partial_inplace */
847 0xffc, /* src_mask */
848 0xffc, /* dst_mask */
849 FALSE
), /* pcrel_offset */
851 /* Get to the page for the GOT entry for the symbol
852 (G(S) - P) using an ADRP instruction. */
853 HOWTO (AARCH64_R (TLSGD_ADR_PAGE21
), /* type */
855 2, /* size (0 = byte, 1 = short, 2 = long) */
857 TRUE
, /* pc_relative */
859 complain_overflow_dont
, /* complain_on_overflow */
860 bfd_elf_generic_reloc
, /* special_function */
861 AARCH64_R_STR (TLSGD_ADR_PAGE21
), /* name */
862 FALSE
, /* partial_inplace */
863 0x1fffff, /* src_mask */
864 0x1fffff, /* dst_mask */
865 TRUE
), /* pcrel_offset */
867 HOWTO (AARCH64_R (TLSGD_ADR_PREL21
), /* type */
869 2, /* size (0 = byte, 1 = short, 2 = long) */
871 TRUE
, /* pc_relative */
873 complain_overflow_dont
, /* complain_on_overflow */
874 bfd_elf_generic_reloc
, /* special_function */
875 AARCH64_R_STR (TLSGD_ADR_PREL21
), /* name */
876 FALSE
, /* partial_inplace */
877 0x1fffff, /* src_mask */
878 0x1fffff, /* dst_mask */
879 TRUE
), /* pcrel_offset */
881 /* ADD: GOT offset G(S) & 0xff8 [no overflow check] */
882 HOWTO (AARCH64_R (TLSGD_ADD_LO12_NC
), /* type */
884 2, /* size (0 = byte, 1 = short, 2 = long) */
886 FALSE
, /* pc_relative */
888 complain_overflow_dont
, /* complain_on_overflow */
889 bfd_elf_generic_reloc
, /* special_function */
890 AARCH64_R_STR (TLSGD_ADD_LO12_NC
), /* name */
891 FALSE
, /* partial_inplace */
892 0xfff, /* src_mask */
893 0xfff, /* dst_mask */
894 FALSE
), /* pcrel_offset */
896 HOWTO64 (AARCH64_R (TLSIE_MOVW_GOTTPREL_G1
), /* type */
898 2, /* size (0 = byte, 1 = short, 2 = long) */
900 FALSE
, /* pc_relative */
902 complain_overflow_dont
, /* complain_on_overflow */
903 bfd_elf_generic_reloc
, /* special_function */
904 AARCH64_R_STR (TLSIE_MOVW_GOTTPREL_G1
), /* name */
905 FALSE
, /* partial_inplace */
906 0xffff, /* src_mask */
907 0xffff, /* dst_mask */
908 FALSE
), /* pcrel_offset */
910 HOWTO64 (AARCH64_R (TLSIE_MOVW_GOTTPREL_G0_NC
), /* type */
912 2, /* size (0 = byte, 1 = short, 2 = long) */
914 FALSE
, /* pc_relative */
916 complain_overflow_dont
, /* complain_on_overflow */
917 bfd_elf_generic_reloc
, /* special_function */
918 AARCH64_R_STR (TLSIE_MOVW_GOTTPREL_G0_NC
), /* name */
919 FALSE
, /* partial_inplace */
920 0xffff, /* src_mask */
921 0xffff, /* dst_mask */
922 FALSE
), /* pcrel_offset */
924 HOWTO (AARCH64_R (TLSIE_ADR_GOTTPREL_PAGE21
), /* type */
926 2, /* size (0 = byte, 1 = short, 2 = long) */
928 FALSE
, /* pc_relative */
930 complain_overflow_dont
, /* complain_on_overflow */
931 bfd_elf_generic_reloc
, /* special_function */
932 AARCH64_R_STR (TLSIE_ADR_GOTTPREL_PAGE21
), /* name */
933 FALSE
, /* partial_inplace */
934 0x1fffff, /* src_mask */
935 0x1fffff, /* dst_mask */
936 FALSE
), /* pcrel_offset */
938 HOWTO64 (AARCH64_R (TLSIE_LD64_GOTTPREL_LO12_NC
), /* type */
940 2, /* size (0 = byte, 1 = short, 2 = long) */
942 FALSE
, /* pc_relative */
944 complain_overflow_dont
, /* complain_on_overflow */
945 bfd_elf_generic_reloc
, /* special_function */
946 AARCH64_R_STR (TLSIE_LD64_GOTTPREL_LO12_NC
), /* name */
947 FALSE
, /* partial_inplace */
948 0xff8, /* src_mask */
949 0xff8, /* dst_mask */
950 FALSE
), /* pcrel_offset */
952 HOWTO32 (AARCH64_R (TLSIE_LD32_GOTTPREL_LO12_NC
), /* type */
954 2, /* size (0 = byte, 1 = short, 2 = long) */
956 FALSE
, /* pc_relative */
958 complain_overflow_dont
, /* complain_on_overflow */
959 bfd_elf_generic_reloc
, /* special_function */
960 AARCH64_R_STR (TLSIE_LD32_GOTTPREL_LO12_NC
), /* name */
961 FALSE
, /* partial_inplace */
962 0xffc, /* src_mask */
963 0xffc, /* dst_mask */
964 FALSE
), /* pcrel_offset */
966 HOWTO (AARCH64_R (TLSIE_LD_GOTTPREL_PREL19
), /* type */
968 2, /* size (0 = byte, 1 = short, 2 = long) */
970 FALSE
, /* pc_relative */
972 complain_overflow_dont
, /* complain_on_overflow */
973 bfd_elf_generic_reloc
, /* special_function */
974 AARCH64_R_STR (TLSIE_LD_GOTTPREL_PREL19
), /* name */
975 FALSE
, /* partial_inplace */
976 0x1ffffc, /* src_mask */
977 0x1ffffc, /* dst_mask */
978 FALSE
), /* pcrel_offset */
980 HOWTO64 (AARCH64_R (TLSLE_MOVW_TPREL_G2
), /* type */
982 2, /* size (0 = byte, 1 = short, 2 = long) */
984 FALSE
, /* pc_relative */
986 complain_overflow_unsigned
, /* complain_on_overflow */
987 bfd_elf_generic_reloc
, /* special_function */
988 AARCH64_R_STR (TLSLE_MOVW_TPREL_G2
), /* name */
989 FALSE
, /* partial_inplace */
990 0xffff, /* src_mask */
991 0xffff, /* dst_mask */
992 FALSE
), /* pcrel_offset */
994 HOWTO (AARCH64_R (TLSLE_MOVW_TPREL_G1
), /* type */
996 2, /* size (0 = byte, 1 = short, 2 = long) */
998 FALSE
, /* pc_relative */
1000 complain_overflow_dont
, /* complain_on_overflow */
1001 bfd_elf_generic_reloc
, /* special_function */
1002 AARCH64_R_STR (TLSLE_MOVW_TPREL_G1
), /* name */
1003 FALSE
, /* partial_inplace */
1004 0xffff, /* src_mask */
1005 0xffff, /* dst_mask */
1006 FALSE
), /* pcrel_offset */
1008 HOWTO64 (AARCH64_R (TLSLE_MOVW_TPREL_G1_NC
), /* type */
1009 16, /* rightshift */
1010 2, /* size (0 = byte, 1 = short, 2 = long) */
1012 FALSE
, /* pc_relative */
1014 complain_overflow_dont
, /* complain_on_overflow */
1015 bfd_elf_generic_reloc
, /* special_function */
1016 AARCH64_R_STR (TLSLE_MOVW_TPREL_G1_NC
), /* name */
1017 FALSE
, /* partial_inplace */
1018 0xffff, /* src_mask */
1019 0xffff, /* dst_mask */
1020 FALSE
), /* pcrel_offset */
1022 HOWTO (AARCH64_R (TLSLE_MOVW_TPREL_G0
), /* type */
1024 2, /* size (0 = byte, 1 = short, 2 = long) */
1026 FALSE
, /* pc_relative */
1028 complain_overflow_dont
, /* complain_on_overflow */
1029 bfd_elf_generic_reloc
, /* special_function */
1030 AARCH64_R_STR (TLSLE_MOVW_TPREL_G0
), /* name */
1031 FALSE
, /* partial_inplace */
1032 0xffff, /* src_mask */
1033 0xffff, /* dst_mask */
1034 FALSE
), /* pcrel_offset */
1036 HOWTO (AARCH64_R (TLSLE_MOVW_TPREL_G0_NC
), /* type */
1038 2, /* size (0 = byte, 1 = short, 2 = long) */
1040 FALSE
, /* pc_relative */
1042 complain_overflow_dont
, /* complain_on_overflow */
1043 bfd_elf_generic_reloc
, /* special_function */
1044 AARCH64_R_STR (TLSLE_MOVW_TPREL_G0_NC
), /* name */
1045 FALSE
, /* partial_inplace */
1046 0xffff, /* src_mask */
1047 0xffff, /* dst_mask */
1048 FALSE
), /* pcrel_offset */
1050 HOWTO (AARCH64_R (TLSLE_ADD_TPREL_HI12
), /* type */
1051 12, /* rightshift */
1052 2, /* size (0 = byte, 1 = short, 2 = long) */
1054 FALSE
, /* pc_relative */
1056 complain_overflow_unsigned
, /* complain_on_overflow */
1057 bfd_elf_generic_reloc
, /* special_function */
1058 AARCH64_R_STR (TLSLE_ADD_TPREL_HI12
), /* name */
1059 FALSE
, /* partial_inplace */
1060 0xfff, /* src_mask */
1061 0xfff, /* dst_mask */
1062 FALSE
), /* pcrel_offset */
1064 HOWTO (AARCH64_R (TLSLE_ADD_TPREL_LO12
), /* type */
1066 2, /* size (0 = byte, 1 = short, 2 = long) */
1068 FALSE
, /* pc_relative */
1070 complain_overflow_dont
, /* complain_on_overflow */
1071 bfd_elf_generic_reloc
, /* special_function */
1072 AARCH64_R_STR (TLSLE_ADD_TPREL_LO12
), /* name */
1073 FALSE
, /* partial_inplace */
1074 0xfff, /* src_mask */
1075 0xfff, /* dst_mask */
1076 FALSE
), /* pcrel_offset */
1078 HOWTO (AARCH64_R (TLSLE_ADD_TPREL_LO12_NC
), /* type */
1080 2, /* size (0 = byte, 1 = short, 2 = long) */
1082 FALSE
, /* pc_relative */
1084 complain_overflow_dont
, /* complain_on_overflow */
1085 bfd_elf_generic_reloc
, /* special_function */
1086 AARCH64_R_STR (TLSLE_ADD_TPREL_LO12_NC
), /* name */
1087 FALSE
, /* partial_inplace */
1088 0xfff, /* src_mask */
1089 0xfff, /* dst_mask */
1090 FALSE
), /* pcrel_offset */
1092 HOWTO (AARCH64_R (TLSDESC_LD_PREL19
), /* type */
1094 2, /* size (0 = byte, 1 = short, 2 = long) */
1096 TRUE
, /* pc_relative */
1098 complain_overflow_dont
, /* complain_on_overflow */
1099 bfd_elf_generic_reloc
, /* special_function */
1100 AARCH64_R_STR (TLSDESC_LD_PREL19
), /* name */
1101 FALSE
, /* partial_inplace */
1102 0x0ffffe0, /* src_mask */
1103 0x0ffffe0, /* dst_mask */
1104 TRUE
), /* pcrel_offset */
1106 HOWTO (AARCH64_R (TLSDESC_ADR_PREL21
), /* type */
1108 2, /* size (0 = byte, 1 = short, 2 = long) */
1110 TRUE
, /* pc_relative */
1112 complain_overflow_dont
, /* complain_on_overflow */
1113 bfd_elf_generic_reloc
, /* special_function */
1114 AARCH64_R_STR (TLSDESC_ADR_PREL21
), /* name */
1115 FALSE
, /* partial_inplace */
1116 0x1fffff, /* src_mask */
1117 0x1fffff, /* dst_mask */
1118 TRUE
), /* pcrel_offset */
1120 /* Get to the page for the GOT entry for the symbol
1121 (G(S) - P) using an ADRP instruction. */
1122 HOWTO (AARCH64_R (TLSDESC_ADR_PAGE21
), /* type */
1123 12, /* rightshift */
1124 2, /* size (0 = byte, 1 = short, 2 = long) */
1126 TRUE
, /* pc_relative */
1128 complain_overflow_dont
, /* complain_on_overflow */
1129 bfd_elf_generic_reloc
, /* special_function */
1130 AARCH64_R_STR (TLSDESC_ADR_PAGE21
), /* name */
1131 FALSE
, /* partial_inplace */
1132 0x1fffff, /* src_mask */
1133 0x1fffff, /* dst_mask */
1134 TRUE
), /* pcrel_offset */
1136 /* LD64: GOT offset G(S) & 0xff8. */
1137 HOWTO64 (AARCH64_R (TLSDESC_LD64_LO12_NC
), /* type */
1139 2, /* size (0 = byte, 1 = short, 2 = long) */
1141 FALSE
, /* pc_relative */
1143 complain_overflow_dont
, /* complain_on_overflow */
1144 bfd_elf_generic_reloc
, /* special_function */
1145 AARCH64_R_STR (TLSDESC_LD64_LO12_NC
), /* name */
1146 FALSE
, /* partial_inplace */
1147 0xff8, /* src_mask */
1148 0xff8, /* dst_mask */
1149 FALSE
), /* pcrel_offset */
1151 /* LD32: GOT offset G(S) & 0xffc. */
1152 HOWTO32 (AARCH64_R (TLSDESC_LD32_LO12_NC
), /* type */
1154 2, /* size (0 = byte, 1 = short, 2 = long) */
1156 FALSE
, /* pc_relative */
1158 complain_overflow_dont
, /* complain_on_overflow */
1159 bfd_elf_generic_reloc
, /* special_function */
1160 AARCH64_R_STR (TLSDESC_LD32_LO12_NC
), /* name */
1161 FALSE
, /* partial_inplace */
1162 0xffc, /* src_mask */
1163 0xffc, /* dst_mask */
1164 FALSE
), /* pcrel_offset */
1166 /* ADD: GOT offset G(S) & 0xfff. */
1167 HOWTO (AARCH64_R (TLSDESC_ADD_LO12_NC
), /* type */
1169 2, /* size (0 = byte, 1 = short, 2 = long) */
1171 FALSE
, /* pc_relative */
1173 complain_overflow_dont
, /* complain_on_overflow */
1174 bfd_elf_generic_reloc
, /* special_function */
1175 AARCH64_R_STR (TLSDESC_ADD_LO12_NC
), /* name */
1176 FALSE
, /* partial_inplace */
1177 0xfff, /* src_mask */
1178 0xfff, /* dst_mask */
1179 FALSE
), /* pcrel_offset */
1181 HOWTO64 (AARCH64_R (TLSDESC_OFF_G1
), /* type */
1182 16, /* rightshift */
1183 2, /* size (0 = byte, 1 = short, 2 = long) */
1185 FALSE
, /* pc_relative */
1187 complain_overflow_dont
, /* complain_on_overflow */
1188 bfd_elf_generic_reloc
, /* special_function */
1189 AARCH64_R_STR (TLSDESC_OFF_G1
), /* name */
1190 FALSE
, /* partial_inplace */
1191 0xffff, /* src_mask */
1192 0xffff, /* dst_mask */
1193 FALSE
), /* pcrel_offset */
1195 HOWTO64 (AARCH64_R (TLSDESC_OFF_G0_NC
), /* type */
1197 2, /* size (0 = byte, 1 = short, 2 = long) */
1199 FALSE
, /* pc_relative */
1201 complain_overflow_dont
, /* complain_on_overflow */
1202 bfd_elf_generic_reloc
, /* special_function */
1203 AARCH64_R_STR (TLSDESC_OFF_G0_NC
), /* name */
1204 FALSE
, /* partial_inplace */
1205 0xffff, /* src_mask */
1206 0xffff, /* dst_mask */
1207 FALSE
), /* pcrel_offset */
1209 HOWTO64 (AARCH64_R (TLSDESC_LDR
), /* type */
1211 2, /* size (0 = byte, 1 = short, 2 = long) */
1213 FALSE
, /* pc_relative */
1215 complain_overflow_dont
, /* complain_on_overflow */
1216 bfd_elf_generic_reloc
, /* special_function */
1217 AARCH64_R_STR (TLSDESC_LDR
), /* name */
1218 FALSE
, /* partial_inplace */
1221 FALSE
), /* pcrel_offset */
1223 HOWTO64 (AARCH64_R (TLSDESC_ADD
), /* type */
1225 2, /* size (0 = byte, 1 = short, 2 = long) */
1227 FALSE
, /* pc_relative */
1229 complain_overflow_dont
, /* complain_on_overflow */
1230 bfd_elf_generic_reloc
, /* special_function */
1231 AARCH64_R_STR (TLSDESC_ADD
), /* name */
1232 FALSE
, /* partial_inplace */
1235 FALSE
), /* pcrel_offset */
1237 HOWTO (AARCH64_R (TLSDESC_CALL
), /* type */
1239 2, /* size (0 = byte, 1 = short, 2 = long) */
1241 FALSE
, /* pc_relative */
1243 complain_overflow_dont
, /* complain_on_overflow */
1244 bfd_elf_generic_reloc
, /* special_function */
1245 AARCH64_R_STR (TLSDESC_CALL
), /* name */
1246 FALSE
, /* partial_inplace */
1249 FALSE
), /* pcrel_offset */
1251 HOWTO (AARCH64_R (COPY
), /* type */
1253 2, /* size (0 = byte, 1 = short, 2 = long) */
1255 FALSE
, /* pc_relative */
1257 complain_overflow_bitfield
, /* complain_on_overflow */
1258 bfd_elf_generic_reloc
, /* special_function */
1259 AARCH64_R_STR (COPY
), /* name */
1260 TRUE
, /* partial_inplace */
1261 0xffffffff, /* src_mask */
1262 0xffffffff, /* dst_mask */
1263 FALSE
), /* pcrel_offset */
1265 HOWTO (AARCH64_R (GLOB_DAT
), /* type */
1267 2, /* size (0 = byte, 1 = short, 2 = long) */
1269 FALSE
, /* pc_relative */
1271 complain_overflow_bitfield
, /* complain_on_overflow */
1272 bfd_elf_generic_reloc
, /* special_function */
1273 AARCH64_R_STR (GLOB_DAT
), /* name */
1274 TRUE
, /* partial_inplace */
1275 0xffffffff, /* src_mask */
1276 0xffffffff, /* dst_mask */
1277 FALSE
), /* pcrel_offset */
1279 HOWTO (AARCH64_R (JUMP_SLOT
), /* type */
1281 2, /* size (0 = byte, 1 = short, 2 = long) */
1283 FALSE
, /* pc_relative */
1285 complain_overflow_bitfield
, /* complain_on_overflow */
1286 bfd_elf_generic_reloc
, /* special_function */
1287 AARCH64_R_STR (JUMP_SLOT
), /* name */
1288 TRUE
, /* partial_inplace */
1289 0xffffffff, /* src_mask */
1290 0xffffffff, /* dst_mask */
1291 FALSE
), /* pcrel_offset */
1293 HOWTO (AARCH64_R (RELATIVE
), /* type */
1295 2, /* size (0 = byte, 1 = short, 2 = long) */
1297 FALSE
, /* pc_relative */
1299 complain_overflow_bitfield
, /* complain_on_overflow */
1300 bfd_elf_generic_reloc
, /* special_function */
1301 AARCH64_R_STR (RELATIVE
), /* name */
1302 TRUE
, /* partial_inplace */
1303 ALL_ONES
, /* src_mask */
1304 ALL_ONES
, /* dst_mask */
1305 FALSE
), /* pcrel_offset */
1307 HOWTO (AARCH64_R (TLS_DTPMOD
), /* type */
1309 2, /* size (0 = byte, 1 = short, 2 = long) */
1311 FALSE
, /* pc_relative */
1313 complain_overflow_dont
, /* complain_on_overflow */
1314 bfd_elf_generic_reloc
, /* special_function */
1316 AARCH64_R_STR (TLS_DTPMOD64
), /* name */
1318 AARCH64_R_STR (TLS_DTPMOD
), /* name */
1320 FALSE
, /* partial_inplace */
1322 ALL_ONES
, /* dst_mask */
1323 FALSE
), /* pc_reloffset */
1325 HOWTO (AARCH64_R (TLS_DTPREL
), /* type */
1327 2, /* size (0 = byte, 1 = short, 2 = long) */
1329 FALSE
, /* pc_relative */
1331 complain_overflow_dont
, /* complain_on_overflow */
1332 bfd_elf_generic_reloc
, /* special_function */
1334 AARCH64_R_STR (TLS_DTPREL64
), /* name */
1336 AARCH64_R_STR (TLS_DTPREL
), /* name */
1338 FALSE
, /* partial_inplace */
1340 ALL_ONES
, /* dst_mask */
1341 FALSE
), /* pcrel_offset */
1343 HOWTO (AARCH64_R (TLS_TPREL
), /* type */
1345 2, /* size (0 = byte, 1 = short, 2 = long) */
1347 FALSE
, /* pc_relative */
1349 complain_overflow_dont
, /* complain_on_overflow */
1350 bfd_elf_generic_reloc
, /* special_function */
1352 AARCH64_R_STR (TLS_TPREL64
), /* name */
1354 AARCH64_R_STR (TLS_TPREL
), /* name */
1356 FALSE
, /* partial_inplace */
1358 ALL_ONES
, /* dst_mask */
1359 FALSE
), /* pcrel_offset */
1361 HOWTO (AARCH64_R (TLSDESC
), /* type */
1363 2, /* size (0 = byte, 1 = short, 2 = long) */
1365 FALSE
, /* pc_relative */
1367 complain_overflow_dont
, /* complain_on_overflow */
1368 bfd_elf_generic_reloc
, /* special_function */
1369 AARCH64_R_STR (TLSDESC
), /* name */
1370 FALSE
, /* partial_inplace */
1372 ALL_ONES
, /* dst_mask */
1373 FALSE
), /* pcrel_offset */
1375 HOWTO (AARCH64_R (IRELATIVE
), /* type */
1377 2, /* size (0 = byte, 1 = short, 2 = long) */
1379 FALSE
, /* pc_relative */
1381 complain_overflow_bitfield
, /* complain_on_overflow */
1382 bfd_elf_generic_reloc
, /* special_function */
1383 AARCH64_R_STR (IRELATIVE
), /* name */
1384 FALSE
, /* partial_inplace */
1386 ALL_ONES
, /* dst_mask */
1387 FALSE
), /* pcrel_offset */
1392 static reloc_howto_type elfNN_aarch64_howto_none
=
1393 HOWTO (R_AARCH64_NONE
, /* type */
1395 3, /* size (0 = byte, 1 = short, 2 = long) */
1397 FALSE
, /* pc_relative */
1399 complain_overflow_dont
,/* complain_on_overflow */
1400 bfd_elf_generic_reloc
, /* special_function */
1401 "R_AARCH64_NONE", /* name */
1402 FALSE
, /* partial_inplace */
1405 FALSE
); /* pcrel_offset */
1407 /* Given HOWTO, return the bfd internal relocation enumerator. */
1409 static bfd_reloc_code_real_type
1410 elfNN_aarch64_bfd_reloc_from_howto (reloc_howto_type
*howto
)
1413 = (int) ARRAY_SIZE (elfNN_aarch64_howto_table
);
1414 const ptrdiff_t offset
1415 = howto
- elfNN_aarch64_howto_table
;
1417 if (offset
> 0 && offset
< size
- 1)
1418 return BFD_RELOC_AARCH64_RELOC_START
+ offset
;
1420 if (howto
== &elfNN_aarch64_howto_none
)
1421 return BFD_RELOC_AARCH64_NONE
;
1423 return BFD_RELOC_AARCH64_RELOC_START
;
1426 /* Given R_TYPE, return the bfd internal relocation enumerator. */
1428 static bfd_reloc_code_real_type
1429 elfNN_aarch64_bfd_reloc_from_type (unsigned int r_type
)
1431 static bfd_boolean initialized_p
= FALSE
;
1432 /* Indexed by R_TYPE, values are offsets in the howto_table. */
1433 static unsigned int offsets
[R_AARCH64_end
];
1435 if (initialized_p
== FALSE
)
1439 for (i
= 1; i
< ARRAY_SIZE (elfNN_aarch64_howto_table
) - 1; ++i
)
1440 if (elfNN_aarch64_howto_table
[i
].type
!= 0)
1441 offsets
[elfNN_aarch64_howto_table
[i
].type
] = i
;
1443 initialized_p
= TRUE
;
1446 if (r_type
== R_AARCH64_NONE
|| r_type
== R_AARCH64_NULL
)
1447 return BFD_RELOC_AARCH64_NONE
;
1449 /* PR 17512: file: b371e70a. */
1450 if (r_type
>= R_AARCH64_end
)
1452 _bfd_error_handler (_("Invalid AArch64 reloc number: %d"), r_type
);
1453 bfd_set_error (bfd_error_bad_value
);
1454 return BFD_RELOC_AARCH64_NONE
;
1457 return BFD_RELOC_AARCH64_RELOC_START
+ offsets
[r_type
];
1460 struct elf_aarch64_reloc_map
1462 bfd_reloc_code_real_type from
;
1463 bfd_reloc_code_real_type to
;
1466 /* Map bfd generic reloc to AArch64-specific reloc. */
1467 static const struct elf_aarch64_reloc_map elf_aarch64_reloc_map
[] =
1469 {BFD_RELOC_NONE
, BFD_RELOC_AARCH64_NONE
},
1471 /* Basic data relocations. */
1472 {BFD_RELOC_CTOR
, BFD_RELOC_AARCH64_NN
},
1473 {BFD_RELOC_64
, BFD_RELOC_AARCH64_64
},
1474 {BFD_RELOC_32
, BFD_RELOC_AARCH64_32
},
1475 {BFD_RELOC_16
, BFD_RELOC_AARCH64_16
},
1476 {BFD_RELOC_64_PCREL
, BFD_RELOC_AARCH64_64_PCREL
},
1477 {BFD_RELOC_32_PCREL
, BFD_RELOC_AARCH64_32_PCREL
},
1478 {BFD_RELOC_16_PCREL
, BFD_RELOC_AARCH64_16_PCREL
},
1481 /* Given the bfd internal relocation enumerator in CODE, return the
1482 corresponding howto entry. */
1484 static reloc_howto_type
*
1485 elfNN_aarch64_howto_from_bfd_reloc (bfd_reloc_code_real_type code
)
1489 /* Convert bfd generic reloc to AArch64-specific reloc. */
1490 if (code
< BFD_RELOC_AARCH64_RELOC_START
1491 || code
> BFD_RELOC_AARCH64_RELOC_END
)
1492 for (i
= 0; i
< ARRAY_SIZE (elf_aarch64_reloc_map
); i
++)
1493 if (elf_aarch64_reloc_map
[i
].from
== code
)
1495 code
= elf_aarch64_reloc_map
[i
].to
;
1499 if (code
> BFD_RELOC_AARCH64_RELOC_START
1500 && code
< BFD_RELOC_AARCH64_RELOC_END
)
1501 if (elfNN_aarch64_howto_table
[code
- BFD_RELOC_AARCH64_RELOC_START
].type
)
1502 return &elfNN_aarch64_howto_table
[code
- BFD_RELOC_AARCH64_RELOC_START
];
1504 if (code
== BFD_RELOC_AARCH64_NONE
)
1505 return &elfNN_aarch64_howto_none
;
1510 static reloc_howto_type
*
1511 elfNN_aarch64_howto_from_type (unsigned int r_type
)
1513 bfd_reloc_code_real_type val
;
1514 reloc_howto_type
*howto
;
1519 bfd_set_error (bfd_error_bad_value
);
1524 if (r_type
== R_AARCH64_NONE
)
1525 return &elfNN_aarch64_howto_none
;
1527 val
= elfNN_aarch64_bfd_reloc_from_type (r_type
);
1528 howto
= elfNN_aarch64_howto_from_bfd_reloc (val
);
1533 bfd_set_error (bfd_error_bad_value
);
1538 elfNN_aarch64_info_to_howto (bfd
*abfd ATTRIBUTE_UNUSED
, arelent
*bfd_reloc
,
1539 Elf_Internal_Rela
*elf_reloc
)
1541 unsigned int r_type
;
1543 r_type
= ELFNN_R_TYPE (elf_reloc
->r_info
);
1544 bfd_reloc
->howto
= elfNN_aarch64_howto_from_type (r_type
);
1547 static reloc_howto_type
*
1548 elfNN_aarch64_reloc_type_lookup (bfd
*abfd ATTRIBUTE_UNUSED
,
1549 bfd_reloc_code_real_type code
)
1551 reloc_howto_type
*howto
= elfNN_aarch64_howto_from_bfd_reloc (code
);
1556 bfd_set_error (bfd_error_bad_value
);
1560 static reloc_howto_type
*
1561 elfNN_aarch64_reloc_name_lookup (bfd
*abfd ATTRIBUTE_UNUSED
,
1566 for (i
= 1; i
< ARRAY_SIZE (elfNN_aarch64_howto_table
) - 1; ++i
)
1567 if (elfNN_aarch64_howto_table
[i
].name
!= NULL
1568 && strcasecmp (elfNN_aarch64_howto_table
[i
].name
, r_name
) == 0)
1569 return &elfNN_aarch64_howto_table
[i
];
1574 #define TARGET_LITTLE_SYM aarch64_elfNN_le_vec
1575 #define TARGET_LITTLE_NAME "elfNN-littleaarch64"
1576 #define TARGET_BIG_SYM aarch64_elfNN_be_vec
1577 #define TARGET_BIG_NAME "elfNN-bigaarch64"
1579 /* The linker script knows the section names for placement.
1580 The entry_names are used to do simple name mangling on the stubs.
1581 Given a function name, and its type, the stub can be found. The
1582 name can be changed. The only requirement is the %s be present. */
1583 #define STUB_ENTRY_NAME "__%s_veneer"
1585 /* The name of the dynamic interpreter. This is put in the .interp
1587 #define ELF_DYNAMIC_INTERPRETER "/lib/ld.so.1"
1589 #define AARCH64_MAX_FWD_BRANCH_OFFSET \
1590 (((1 << 25) - 1) << 2)
1591 #define AARCH64_MAX_BWD_BRANCH_OFFSET \
1594 #define AARCH64_MAX_ADRP_IMM ((1 << 20) - 1)
1595 #define AARCH64_MIN_ADRP_IMM (-(1 << 20))
1598 aarch64_valid_for_adrp_p (bfd_vma value
, bfd_vma place
)
1600 bfd_signed_vma offset
= (bfd_signed_vma
) (PG (value
) - PG (place
)) >> 12;
1601 return offset
<= AARCH64_MAX_ADRP_IMM
&& offset
>= AARCH64_MIN_ADRP_IMM
;
1605 aarch64_valid_branch_p (bfd_vma value
, bfd_vma place
)
1607 bfd_signed_vma offset
= (bfd_signed_vma
) (value
- place
);
1608 return (offset
<= AARCH64_MAX_FWD_BRANCH_OFFSET
1609 && offset
>= AARCH64_MAX_BWD_BRANCH_OFFSET
);
1612 static const uint32_t aarch64_adrp_branch_stub
[] =
1614 0x90000010, /* adrp ip0, X */
1615 /* R_AARCH64_ADR_HI21_PCREL(X) */
1616 0x91000210, /* add ip0, ip0, :lo12:X */
1617 /* R_AARCH64_ADD_ABS_LO12_NC(X) */
1618 0xd61f0200, /* br ip0 */
1621 static const uint32_t aarch64_long_branch_stub
[] =
1624 0x58000090, /* ldr ip0, 1f */
1626 0x18000090, /* ldr wip0, 1f */
1628 0x10000011, /* adr ip1, #0 */
1629 0x8b110210, /* add ip0, ip0, ip1 */
1630 0xd61f0200, /* br ip0 */
1631 0x00000000, /* 1: .xword or .word
1632 R_AARCH64_PRELNN(X) + 12
1637 static const uint32_t aarch64_erratum_835769_stub
[] =
1639 0x00000000, /* Placeholder for multiply accumulate. */
1640 0x14000000, /* b <label> */
1643 static const uint32_t aarch64_erratum_843419_stub
[] =
1645 0x00000000, /* Placeholder for LDR instruction. */
1646 0x14000000, /* b <label> */
1649 /* Section name for stubs is the associated section name plus this
1651 #define STUB_SUFFIX ".stub"
1653 enum elf_aarch64_stub_type
1656 aarch64_stub_adrp_branch
,
1657 aarch64_stub_long_branch
,
1658 aarch64_stub_erratum_835769_veneer
,
1659 aarch64_stub_erratum_843419_veneer
,
1662 struct elf_aarch64_stub_hash_entry
1664 /* Base hash table entry structure. */
1665 struct bfd_hash_entry root
;
1667 /* The stub section. */
1670 /* Offset within stub_sec of the beginning of this stub. */
1671 bfd_vma stub_offset
;
1673 /* Given the symbol's value and its section we can determine its final
1674 value when building the stubs (so the stub knows where to jump). */
1675 bfd_vma target_value
;
1676 asection
*target_section
;
1678 enum elf_aarch64_stub_type stub_type
;
1680 /* The symbol table entry, if any, that this was derived from. */
1681 struct elf_aarch64_link_hash_entry
*h
;
1683 /* Destination symbol type */
1684 unsigned char st_type
;
1686 /* Where this stub is being called from, or, in the case of combined
1687 stub sections, the first input section in the group. */
1690 /* The name for the local symbol at the start of this stub. The
1691 stub name in the hash table has to be unique; this does not, so
1692 it can be friendlier. */
1695 /* The instruction which caused this stub to be generated (only valid for
1696 erratum 835769 workaround stubs at present). */
1697 uint32_t veneered_insn
;
1699 /* In an erratum 843419 workaround stub, the ADRP instruction offset. */
1700 bfd_vma adrp_offset
;
1703 /* Used to build a map of a section. This is required for mixed-endian
1706 typedef struct elf_elf_section_map
1711 elf_aarch64_section_map
;
1714 typedef struct _aarch64_elf_section_data
1716 struct bfd_elf_section_data elf
;
1717 unsigned int mapcount
;
1718 unsigned int mapsize
;
1719 elf_aarch64_section_map
*map
;
1721 _aarch64_elf_section_data
;
1723 #define elf_aarch64_section_data(sec) \
1724 ((_aarch64_elf_section_data *) elf_section_data (sec))
1726 /* The size of the thread control block which is defined to be two pointers. */
1727 #define TCB_SIZE (ARCH_SIZE/8)*2
1729 struct elf_aarch64_local_symbol
1731 unsigned int got_type
;
1732 bfd_signed_vma got_refcount
;
1735 /* Offset of the GOTPLT entry reserved for the TLS descriptor. The
1736 offset is from the end of the jump table and reserved entries
1739 The magic value (bfd_vma) -1 indicates that an offset has not be
1741 bfd_vma tlsdesc_got_jump_table_offset
;
1744 struct elf_aarch64_obj_tdata
1746 struct elf_obj_tdata root
;
1748 /* local symbol descriptors */
1749 struct elf_aarch64_local_symbol
*locals
;
1751 /* Zero to warn when linking objects with incompatible enum sizes. */
1752 int no_enum_size_warning
;
1754 /* Zero to warn when linking objects with incompatible wchar_t sizes. */
1755 int no_wchar_size_warning
;
1758 #define elf_aarch64_tdata(bfd) \
1759 ((struct elf_aarch64_obj_tdata *) (bfd)->tdata.any)
1761 #define elf_aarch64_locals(bfd) (elf_aarch64_tdata (bfd)->locals)
1763 #define is_aarch64_elf(bfd) \
1764 (bfd_get_flavour (bfd) == bfd_target_elf_flavour \
1765 && elf_tdata (bfd) != NULL \
1766 && elf_object_id (bfd) == AARCH64_ELF_DATA)
1769 elfNN_aarch64_mkobject (bfd
*abfd
)
1771 return bfd_elf_allocate_object (abfd
, sizeof (struct elf_aarch64_obj_tdata
),
1775 #define elf_aarch64_hash_entry(ent) \
1776 ((struct elf_aarch64_link_hash_entry *)(ent))
1778 #define GOT_UNKNOWN 0
1779 #define GOT_NORMAL 1
1780 #define GOT_TLS_GD 2
1781 #define GOT_TLS_IE 4
1782 #define GOT_TLSDESC_GD 8
1784 #define GOT_TLS_GD_ANY_P(type) ((type & GOT_TLS_GD) || (type & GOT_TLSDESC_GD))
1786 /* AArch64 ELF linker hash entry. */
1787 struct elf_aarch64_link_hash_entry
1789 struct elf_link_hash_entry root
;
1791 /* Track dynamic relocs copied for this symbol. */
1792 struct elf_dyn_relocs
*dyn_relocs
;
1794 /* Since PLT entries have variable size, we need to record the
1795 index into .got.plt instead of recomputing it from the PLT
1797 bfd_signed_vma plt_got_offset
;
1799 /* Bit mask representing the type of GOT entry(s) if any required by
1801 unsigned int got_type
;
1803 /* A pointer to the most recently used stub hash entry against this
1805 struct elf_aarch64_stub_hash_entry
*stub_cache
;
1807 /* Offset of the GOTPLT entry reserved for the TLS descriptor. The offset
1808 is from the end of the jump table and reserved entries within the PLTGOT.
1810 The magic value (bfd_vma) -1 indicates that an offset has not
1812 bfd_vma tlsdesc_got_jump_table_offset
;
1816 elfNN_aarch64_symbol_got_type (struct elf_link_hash_entry
*h
,
1818 unsigned long r_symndx
)
1821 return elf_aarch64_hash_entry (h
)->got_type
;
1823 if (! elf_aarch64_locals (abfd
))
1826 return elf_aarch64_locals (abfd
)[r_symndx
].got_type
;
1829 /* Get the AArch64 elf linker hash table from a link_info structure. */
1830 #define elf_aarch64_hash_table(info) \
1831 ((struct elf_aarch64_link_hash_table *) ((info)->hash))
1833 #define aarch64_stub_hash_lookup(table, string, create, copy) \
1834 ((struct elf_aarch64_stub_hash_entry *) \
1835 bfd_hash_lookup ((table), (string), (create), (copy)))
1837 /* AArch64 ELF linker hash table. */
1838 struct elf_aarch64_link_hash_table
1840 /* The main hash table. */
1841 struct elf_link_hash_table root
;
1843 /* Nonzero to force PIC branch veneers. */
1846 /* Fix erratum 835769. */
1847 int fix_erratum_835769
;
1849 /* Fix erratum 843419. */
1850 int fix_erratum_843419
;
1852 /* Enable ADRP->ADR rewrite for erratum 843419 workaround. */
1853 int fix_erratum_843419_adr
;
1855 /* The number of bytes in the initial entry in the PLT. */
1856 bfd_size_type plt_header_size
;
1858 /* The number of bytes in the subsequent PLT etries. */
1859 bfd_size_type plt_entry_size
;
1861 /* Short-cuts to get to dynamic linker sections. */
1865 /* Small local sym cache. */
1866 struct sym_cache sym_cache
;
1868 /* For convenience in allocate_dynrelocs. */
1871 /* The amount of space used by the reserved portion of the sgotplt
1872 section, plus whatever space is used by the jump slots. */
1873 bfd_vma sgotplt_jump_table_size
;
1875 /* The stub hash table. */
1876 struct bfd_hash_table stub_hash_table
;
1878 /* Linker stub bfd. */
1881 /* Linker call-backs. */
1882 asection
*(*add_stub_section
) (const char *, asection
*);
1883 void (*layout_sections_again
) (void);
1885 /* Array to keep track of which stub sections have been created, and
1886 information on stub grouping. */
1889 /* This is the section to which stubs in the group will be
1892 /* The stub section. */
1896 /* Assorted information used by elfNN_aarch64_size_stubs. */
1897 unsigned int bfd_count
;
1899 asection
**input_list
;
1901 /* The offset into splt of the PLT entry for the TLS descriptor
1902 resolver. Special values are 0, if not necessary (or not found
1903 to be necessary yet), and -1 if needed but not determined
1905 bfd_vma tlsdesc_plt
;
1907 /* The GOT offset for the lazy trampoline. Communicated to the
1908 loader via DT_TLSDESC_GOT. The magic value (bfd_vma) -1
1909 indicates an offset is not allocated. */
1910 bfd_vma dt_tlsdesc_got
;
1912 /* Used by local STT_GNU_IFUNC symbols. */
1913 htab_t loc_hash_table
;
1914 void * loc_hash_memory
;
1917 /* Create an entry in an AArch64 ELF linker hash table. */
1919 static struct bfd_hash_entry
*
1920 elfNN_aarch64_link_hash_newfunc (struct bfd_hash_entry
*entry
,
1921 struct bfd_hash_table
*table
,
1924 struct elf_aarch64_link_hash_entry
*ret
=
1925 (struct elf_aarch64_link_hash_entry
*) entry
;
1927 /* Allocate the structure if it has not already been allocated by a
1930 ret
= bfd_hash_allocate (table
,
1931 sizeof (struct elf_aarch64_link_hash_entry
));
1933 return (struct bfd_hash_entry
*) ret
;
1935 /* Call the allocation method of the superclass. */
1936 ret
= ((struct elf_aarch64_link_hash_entry
*)
1937 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry
*) ret
,
1941 ret
->dyn_relocs
= NULL
;
1942 ret
->got_type
= GOT_UNKNOWN
;
1943 ret
->plt_got_offset
= (bfd_vma
) - 1;
1944 ret
->stub_cache
= NULL
;
1945 ret
->tlsdesc_got_jump_table_offset
= (bfd_vma
) - 1;
1948 return (struct bfd_hash_entry
*) ret
;
1951 /* Initialize an entry in the stub hash table. */
1953 static struct bfd_hash_entry
*
1954 stub_hash_newfunc (struct bfd_hash_entry
*entry
,
1955 struct bfd_hash_table
*table
, const char *string
)
1957 /* Allocate the structure if it has not already been allocated by a
1961 entry
= bfd_hash_allocate (table
,
1963 elf_aarch64_stub_hash_entry
));
1968 /* Call the allocation method of the superclass. */
1969 entry
= bfd_hash_newfunc (entry
, table
, string
);
1972 struct elf_aarch64_stub_hash_entry
*eh
;
1974 /* Initialize the local fields. */
1975 eh
= (struct elf_aarch64_stub_hash_entry
*) entry
;
1976 eh
->adrp_offset
= 0;
1977 eh
->stub_sec
= NULL
;
1978 eh
->stub_offset
= 0;
1979 eh
->target_value
= 0;
1980 eh
->target_section
= NULL
;
1981 eh
->stub_type
= aarch64_stub_none
;
1989 /* Compute a hash of a local hash entry. We use elf_link_hash_entry
1990 for local symbol so that we can handle local STT_GNU_IFUNC symbols
1991 as global symbol. We reuse indx and dynstr_index for local symbol
1992 hash since they aren't used by global symbols in this backend. */
1995 elfNN_aarch64_local_htab_hash (const void *ptr
)
1997 struct elf_link_hash_entry
*h
1998 = (struct elf_link_hash_entry
*) ptr
;
1999 return ELF_LOCAL_SYMBOL_HASH (h
->indx
, h
->dynstr_index
);
2002 /* Compare local hash entries. */
2005 elfNN_aarch64_local_htab_eq (const void *ptr1
, const void *ptr2
)
2007 struct elf_link_hash_entry
*h1
2008 = (struct elf_link_hash_entry
*) ptr1
;
2009 struct elf_link_hash_entry
*h2
2010 = (struct elf_link_hash_entry
*) ptr2
;
2012 return h1
->indx
== h2
->indx
&& h1
->dynstr_index
== h2
->dynstr_index
;
2015 /* Find and/or create a hash entry for local symbol. */
2017 static struct elf_link_hash_entry
*
2018 elfNN_aarch64_get_local_sym_hash (struct elf_aarch64_link_hash_table
*htab
,
2019 bfd
*abfd
, const Elf_Internal_Rela
*rel
,
2022 struct elf_aarch64_link_hash_entry e
, *ret
;
2023 asection
*sec
= abfd
->sections
;
2024 hashval_t h
= ELF_LOCAL_SYMBOL_HASH (sec
->id
,
2025 ELFNN_R_SYM (rel
->r_info
));
2028 e
.root
.indx
= sec
->id
;
2029 e
.root
.dynstr_index
= ELFNN_R_SYM (rel
->r_info
);
2030 slot
= htab_find_slot_with_hash (htab
->loc_hash_table
, &e
, h
,
2031 create
? INSERT
: NO_INSERT
);
2038 ret
= (struct elf_aarch64_link_hash_entry
*) *slot
;
2042 ret
= (struct elf_aarch64_link_hash_entry
*)
2043 objalloc_alloc ((struct objalloc
*) htab
->loc_hash_memory
,
2044 sizeof (struct elf_aarch64_link_hash_entry
));
2047 memset (ret
, 0, sizeof (*ret
));
2048 ret
->root
.indx
= sec
->id
;
2049 ret
->root
.dynstr_index
= ELFNN_R_SYM (rel
->r_info
);
2050 ret
->root
.dynindx
= -1;
2056 /* Copy the extra info we tack onto an elf_link_hash_entry. */
2059 elfNN_aarch64_copy_indirect_symbol (struct bfd_link_info
*info
,
2060 struct elf_link_hash_entry
*dir
,
2061 struct elf_link_hash_entry
*ind
)
2063 struct elf_aarch64_link_hash_entry
*edir
, *eind
;
2065 edir
= (struct elf_aarch64_link_hash_entry
*) dir
;
2066 eind
= (struct elf_aarch64_link_hash_entry
*) ind
;
2068 if (eind
->dyn_relocs
!= NULL
)
2070 if (edir
->dyn_relocs
!= NULL
)
2072 struct elf_dyn_relocs
**pp
;
2073 struct elf_dyn_relocs
*p
;
2075 /* Add reloc counts against the indirect sym to the direct sym
2076 list. Merge any entries against the same section. */
2077 for (pp
= &eind
->dyn_relocs
; (p
= *pp
) != NULL
;)
2079 struct elf_dyn_relocs
*q
;
2081 for (q
= edir
->dyn_relocs
; q
!= NULL
; q
= q
->next
)
2082 if (q
->sec
== p
->sec
)
2084 q
->pc_count
+= p
->pc_count
;
2085 q
->count
+= p
->count
;
2092 *pp
= edir
->dyn_relocs
;
2095 edir
->dyn_relocs
= eind
->dyn_relocs
;
2096 eind
->dyn_relocs
= NULL
;
2099 if (ind
->root
.type
== bfd_link_hash_indirect
)
2101 /* Copy over PLT info. */
2102 if (dir
->got
.refcount
<= 0)
2104 edir
->got_type
= eind
->got_type
;
2105 eind
->got_type
= GOT_UNKNOWN
;
2109 _bfd_elf_link_hash_copy_indirect (info
, dir
, ind
);
2112 /* Destroy an AArch64 elf linker hash table. */
2115 elfNN_aarch64_link_hash_table_free (bfd
*obfd
)
2117 struct elf_aarch64_link_hash_table
*ret
2118 = (struct elf_aarch64_link_hash_table
*) obfd
->link
.hash
;
2120 if (ret
->loc_hash_table
)
2121 htab_delete (ret
->loc_hash_table
);
2122 if (ret
->loc_hash_memory
)
2123 objalloc_free ((struct objalloc
*) ret
->loc_hash_memory
);
2125 bfd_hash_table_free (&ret
->stub_hash_table
);
2126 _bfd_elf_link_hash_table_free (obfd
);
2129 /* Create an AArch64 elf linker hash table. */
2131 static struct bfd_link_hash_table
*
2132 elfNN_aarch64_link_hash_table_create (bfd
*abfd
)
2134 struct elf_aarch64_link_hash_table
*ret
;
2135 bfd_size_type amt
= sizeof (struct elf_aarch64_link_hash_table
);
2137 ret
= bfd_zmalloc (amt
);
2141 if (!_bfd_elf_link_hash_table_init
2142 (&ret
->root
, abfd
, elfNN_aarch64_link_hash_newfunc
,
2143 sizeof (struct elf_aarch64_link_hash_entry
), AARCH64_ELF_DATA
))
2149 ret
->plt_header_size
= PLT_ENTRY_SIZE
;
2150 ret
->plt_entry_size
= PLT_SMALL_ENTRY_SIZE
;
2152 ret
->dt_tlsdesc_got
= (bfd_vma
) - 1;
2154 if (!bfd_hash_table_init (&ret
->stub_hash_table
, stub_hash_newfunc
,
2155 sizeof (struct elf_aarch64_stub_hash_entry
)))
2157 _bfd_elf_link_hash_table_free (abfd
);
2161 ret
->loc_hash_table
= htab_try_create (1024,
2162 elfNN_aarch64_local_htab_hash
,
2163 elfNN_aarch64_local_htab_eq
,
2165 ret
->loc_hash_memory
= objalloc_create ();
2166 if (!ret
->loc_hash_table
|| !ret
->loc_hash_memory
)
2168 elfNN_aarch64_link_hash_table_free (abfd
);
2171 ret
->root
.root
.hash_table_free
= elfNN_aarch64_link_hash_table_free
;
2173 return &ret
->root
.root
;
2177 aarch64_relocate (unsigned int r_type
, bfd
*input_bfd
, asection
*input_section
,
2178 bfd_vma offset
, bfd_vma value
)
2180 reloc_howto_type
*howto
;
2183 howto
= elfNN_aarch64_howto_from_type (r_type
);
2184 place
= (input_section
->output_section
->vma
+ input_section
->output_offset
2187 r_type
= elfNN_aarch64_bfd_reloc_from_type (r_type
);
2188 value
= _bfd_aarch64_elf_resolve_relocation (r_type
, place
, value
, 0, FALSE
);
2189 return _bfd_aarch64_elf_put_addend (input_bfd
,
2190 input_section
->contents
+ offset
, r_type
,
2194 static enum elf_aarch64_stub_type
2195 aarch64_select_branch_stub (bfd_vma value
, bfd_vma place
)
2197 if (aarch64_valid_for_adrp_p (value
, place
))
2198 return aarch64_stub_adrp_branch
;
2199 return aarch64_stub_long_branch
;
2202 /* Determine the type of stub needed, if any, for a call. */
2204 static enum elf_aarch64_stub_type
2205 aarch64_type_of_stub (struct bfd_link_info
*info
,
2206 asection
*input_sec
,
2207 const Elf_Internal_Rela
*rel
,
2208 unsigned char st_type
,
2209 struct elf_aarch64_link_hash_entry
*hash
,
2210 bfd_vma destination
)
2213 bfd_signed_vma branch_offset
;
2214 unsigned int r_type
;
2215 struct elf_aarch64_link_hash_table
*globals
;
2216 enum elf_aarch64_stub_type stub_type
= aarch64_stub_none
;
2217 bfd_boolean via_plt_p
;
2219 if (st_type
!= STT_FUNC
)
2222 globals
= elf_aarch64_hash_table (info
);
2223 via_plt_p
= (globals
->root
.splt
!= NULL
&& hash
!= NULL
2224 && hash
->root
.plt
.offset
!= (bfd_vma
) - 1);
2229 /* Determine where the call point is. */
2230 location
= (input_sec
->output_offset
2231 + input_sec
->output_section
->vma
+ rel
->r_offset
);
2233 branch_offset
= (bfd_signed_vma
) (destination
- location
);
2235 r_type
= ELFNN_R_TYPE (rel
->r_info
);
2237 /* We don't want to redirect any old unconditional jump in this way,
2238 only one which is being used for a sibcall, where it is
2239 acceptable for the IP0 and IP1 registers to be clobbered. */
2240 if ((r_type
== AARCH64_R (CALL26
) || r_type
== AARCH64_R (JUMP26
))
2241 && (branch_offset
> AARCH64_MAX_FWD_BRANCH_OFFSET
2242 || branch_offset
< AARCH64_MAX_BWD_BRANCH_OFFSET
))
2244 stub_type
= aarch64_stub_long_branch
;
2250 /* Build a name for an entry in the stub hash table. */
2253 elfNN_aarch64_stub_name (const asection
*input_section
,
2254 const asection
*sym_sec
,
2255 const struct elf_aarch64_link_hash_entry
*hash
,
2256 const Elf_Internal_Rela
*rel
)
2263 len
= 8 + 1 + strlen (hash
->root
.root
.root
.string
) + 1 + 16 + 1;
2264 stub_name
= bfd_malloc (len
);
2265 if (stub_name
!= NULL
)
2266 snprintf (stub_name
, len
, "%08x_%s+%" BFD_VMA_FMT
"x",
2267 (unsigned int) input_section
->id
,
2268 hash
->root
.root
.root
.string
,
2273 len
= 8 + 1 + 8 + 1 + 8 + 1 + 16 + 1;
2274 stub_name
= bfd_malloc (len
);
2275 if (stub_name
!= NULL
)
2276 snprintf (stub_name
, len
, "%08x_%x:%x+%" BFD_VMA_FMT
"x",
2277 (unsigned int) input_section
->id
,
2278 (unsigned int) sym_sec
->id
,
2279 (unsigned int) ELFNN_R_SYM (rel
->r_info
),
2286 /* Look up an entry in the stub hash. Stub entries are cached because
2287 creating the stub name takes a bit of time. */
2289 static struct elf_aarch64_stub_hash_entry
*
2290 elfNN_aarch64_get_stub_entry (const asection
*input_section
,
2291 const asection
*sym_sec
,
2292 struct elf_link_hash_entry
*hash
,
2293 const Elf_Internal_Rela
*rel
,
2294 struct elf_aarch64_link_hash_table
*htab
)
2296 struct elf_aarch64_stub_hash_entry
*stub_entry
;
2297 struct elf_aarch64_link_hash_entry
*h
=
2298 (struct elf_aarch64_link_hash_entry
*) hash
;
2299 const asection
*id_sec
;
2301 if ((input_section
->flags
& SEC_CODE
) == 0)
2304 /* If this input section is part of a group of sections sharing one
2305 stub section, then use the id of the first section in the group.
2306 Stub names need to include a section id, as there may well be
2307 more than one stub used to reach say, printf, and we need to
2308 distinguish between them. */
2309 id_sec
= htab
->stub_group
[input_section
->id
].link_sec
;
2311 if (h
!= NULL
&& h
->stub_cache
!= NULL
2312 && h
->stub_cache
->h
== h
&& h
->stub_cache
->id_sec
== id_sec
)
2314 stub_entry
= h
->stub_cache
;
2320 stub_name
= elfNN_aarch64_stub_name (id_sec
, sym_sec
, h
, rel
);
2321 if (stub_name
== NULL
)
2324 stub_entry
= aarch64_stub_hash_lookup (&htab
->stub_hash_table
,
2325 stub_name
, FALSE
, FALSE
);
2327 h
->stub_cache
= stub_entry
;
2336 /* Create a stub section. */
2339 _bfd_aarch64_create_stub_section (asection
*section
,
2340 struct elf_aarch64_link_hash_table
*htab
)
2346 namelen
= strlen (section
->name
);
2347 len
= namelen
+ sizeof (STUB_SUFFIX
);
2348 s_name
= bfd_alloc (htab
->stub_bfd
, len
);
2352 memcpy (s_name
, section
->name
, namelen
);
2353 memcpy (s_name
+ namelen
, STUB_SUFFIX
, sizeof (STUB_SUFFIX
));
2354 return (*htab
->add_stub_section
) (s_name
, section
);
2358 /* Find or create a stub section for a link section.
2360 Fix or create the stub section used to collect stubs attached to
2361 the specified link section. */
2364 _bfd_aarch64_get_stub_for_link_section (asection
*link_section
,
2365 struct elf_aarch64_link_hash_table
*htab
)
2367 if (htab
->stub_group
[link_section
->id
].stub_sec
== NULL
)
2368 htab
->stub_group
[link_section
->id
].stub_sec
2369 = _bfd_aarch64_create_stub_section (link_section
, htab
);
2370 return htab
->stub_group
[link_section
->id
].stub_sec
;
2374 /* Find or create a stub section in the stub group for an input
2378 _bfd_aarch64_create_or_find_stub_sec (asection
*section
,
2379 struct elf_aarch64_link_hash_table
*htab
)
2381 asection
*link_sec
= htab
->stub_group
[section
->id
].link_sec
;
2382 return _bfd_aarch64_get_stub_for_link_section (link_sec
, htab
);
2386 /* Add a new stub entry in the stub group associated with an input
2387 section to the stub hash. Not all fields of the new stub entry are
2390 static struct elf_aarch64_stub_hash_entry
*
2391 _bfd_aarch64_add_stub_entry_in_group (const char *stub_name
,
2393 struct elf_aarch64_link_hash_table
*htab
)
2397 struct elf_aarch64_stub_hash_entry
*stub_entry
;
2399 link_sec
= htab
->stub_group
[section
->id
].link_sec
;
2400 stub_sec
= _bfd_aarch64_create_or_find_stub_sec (section
, htab
);
2402 /* Enter this entry into the linker stub hash table. */
2403 stub_entry
= aarch64_stub_hash_lookup (&htab
->stub_hash_table
, stub_name
,
2405 if (stub_entry
== NULL
)
2407 (*_bfd_error_handler
) (_("%s: cannot create stub entry %s"),
2408 section
->owner
, stub_name
);
2412 stub_entry
->stub_sec
= stub_sec
;
2413 stub_entry
->stub_offset
= 0;
2414 stub_entry
->id_sec
= link_sec
;
2419 /* Add a new stub entry in the final stub section to the stub hash.
2420 Not all fields of the new stub entry are initialised. */
2422 static struct elf_aarch64_stub_hash_entry
*
2423 _bfd_aarch64_add_stub_entry_after (const char *stub_name
,
2424 asection
*link_section
,
2425 struct elf_aarch64_link_hash_table
*htab
)
2428 struct elf_aarch64_stub_hash_entry
*stub_entry
;
2430 stub_sec
= _bfd_aarch64_get_stub_for_link_section (link_section
, htab
);
2431 stub_entry
= aarch64_stub_hash_lookup (&htab
->stub_hash_table
, stub_name
,
2433 if (stub_entry
== NULL
)
2435 (*_bfd_error_handler
) (_("cannot create stub entry %s"), stub_name
);
2439 stub_entry
->stub_sec
= stub_sec
;
2440 stub_entry
->stub_offset
= 0;
2441 stub_entry
->id_sec
= link_section
;
2448 aarch64_build_one_stub (struct bfd_hash_entry
*gen_entry
,
2449 void *in_arg ATTRIBUTE_UNUSED
)
2451 struct elf_aarch64_stub_hash_entry
*stub_entry
;
2456 bfd_vma veneered_insn_loc
;
2457 bfd_vma veneer_entry_loc
;
2458 bfd_signed_vma branch_offset
= 0;
2459 unsigned int template_size
;
2460 const uint32_t *template;
2463 /* Massage our args to the form they really have. */
2464 stub_entry
= (struct elf_aarch64_stub_hash_entry
*) gen_entry
;
2466 stub_sec
= stub_entry
->stub_sec
;
2468 /* Make a note of the offset within the stubs for this entry. */
2469 stub_entry
->stub_offset
= stub_sec
->size
;
2470 loc
= stub_sec
->contents
+ stub_entry
->stub_offset
;
2472 stub_bfd
= stub_sec
->owner
;
2474 /* This is the address of the stub destination. */
2475 sym_value
= (stub_entry
->target_value
2476 + stub_entry
->target_section
->output_offset
2477 + stub_entry
->target_section
->output_section
->vma
);
2479 if (stub_entry
->stub_type
== aarch64_stub_long_branch
)
2481 bfd_vma place
= (stub_entry
->stub_offset
+ stub_sec
->output_section
->vma
2482 + stub_sec
->output_offset
);
2484 /* See if we can relax the stub. */
2485 if (aarch64_valid_for_adrp_p (sym_value
, place
))
2486 stub_entry
->stub_type
= aarch64_select_branch_stub (sym_value
, place
);
2489 switch (stub_entry
->stub_type
)
2491 case aarch64_stub_adrp_branch
:
2492 template = aarch64_adrp_branch_stub
;
2493 template_size
= sizeof (aarch64_adrp_branch_stub
);
2495 case aarch64_stub_long_branch
:
2496 template = aarch64_long_branch_stub
;
2497 template_size
= sizeof (aarch64_long_branch_stub
);
2499 case aarch64_stub_erratum_835769_veneer
:
2500 template = aarch64_erratum_835769_stub
;
2501 template_size
= sizeof (aarch64_erratum_835769_stub
);
2503 case aarch64_stub_erratum_843419_veneer
:
2504 template = aarch64_erratum_843419_stub
;
2505 template_size
= sizeof (aarch64_erratum_843419_stub
);
2511 for (i
= 0; i
< (template_size
/ sizeof template[0]); i
++)
2513 bfd_putl32 (template[i
], loc
);
2517 template_size
= (template_size
+ 7) & ~7;
2518 stub_sec
->size
+= template_size
;
2520 switch (stub_entry
->stub_type
)
2522 case aarch64_stub_adrp_branch
:
2523 if (aarch64_relocate (AARCH64_R (ADR_PREL_PG_HI21
), stub_bfd
, stub_sec
,
2524 stub_entry
->stub_offset
, sym_value
))
2525 /* The stub would not have been relaxed if the offset was out
2529 if (aarch64_relocate (AARCH64_R (ADD_ABS_LO12_NC
), stub_bfd
, stub_sec
,
2530 stub_entry
->stub_offset
+ 4, sym_value
))
2534 case aarch64_stub_long_branch
:
2535 /* We want the value relative to the address 12 bytes back from the
2537 if (aarch64_relocate (AARCH64_R (PRELNN
), stub_bfd
, stub_sec
,
2538 stub_entry
->stub_offset
+ 16, sym_value
+ 12))
2542 case aarch64_stub_erratum_835769_veneer
:
2543 veneered_insn_loc
= stub_entry
->target_section
->output_section
->vma
2544 + stub_entry
->target_section
->output_offset
2545 + stub_entry
->target_value
;
2546 veneer_entry_loc
= stub_entry
->stub_sec
->output_section
->vma
2547 + stub_entry
->stub_sec
->output_offset
2548 + stub_entry
->stub_offset
;
2549 branch_offset
= veneered_insn_loc
- veneer_entry_loc
;
2550 branch_offset
>>= 2;
2551 branch_offset
&= 0x3ffffff;
2552 bfd_putl32 (stub_entry
->veneered_insn
,
2553 stub_sec
->contents
+ stub_entry
->stub_offset
);
2554 bfd_putl32 (template[1] | branch_offset
,
2555 stub_sec
->contents
+ stub_entry
->stub_offset
+ 4);
2558 case aarch64_stub_erratum_843419_veneer
:
2559 if (aarch64_relocate (AARCH64_R (JUMP26
), stub_bfd
, stub_sec
,
2560 stub_entry
->stub_offset
+ 4, sym_value
+ 4))
2571 /* As above, but don't actually build the stub. Just bump offset so
2572 we know stub section sizes. */
2575 aarch64_size_one_stub (struct bfd_hash_entry
*gen_entry
,
2576 void *in_arg ATTRIBUTE_UNUSED
)
2578 struct elf_aarch64_stub_hash_entry
*stub_entry
;
2581 /* Massage our args to the form they really have. */
2582 stub_entry
= (struct elf_aarch64_stub_hash_entry
*) gen_entry
;
2584 switch (stub_entry
->stub_type
)
2586 case aarch64_stub_adrp_branch
:
2587 size
= sizeof (aarch64_adrp_branch_stub
);
2589 case aarch64_stub_long_branch
:
2590 size
= sizeof (aarch64_long_branch_stub
);
2592 case aarch64_stub_erratum_835769_veneer
:
2593 size
= sizeof (aarch64_erratum_835769_stub
);
2595 case aarch64_stub_erratum_843419_veneer
:
2596 size
= sizeof (aarch64_erratum_843419_stub
);
2602 size
= (size
+ 7) & ~7;
2603 stub_entry
->stub_sec
->size
+= size
;
2607 /* External entry points for sizing and building linker stubs. */
2609 /* Set up various things so that we can make a list of input sections
2610 for each output section included in the link. Returns -1 on error,
2611 0 when no stubs will be needed, and 1 on success. */
2614 elfNN_aarch64_setup_section_lists (bfd
*output_bfd
,
2615 struct bfd_link_info
*info
)
2618 unsigned int bfd_count
;
2619 int top_id
, top_index
;
2621 asection
**input_list
, **list
;
2623 struct elf_aarch64_link_hash_table
*htab
=
2624 elf_aarch64_hash_table (info
);
2626 if (!is_elf_hash_table (htab
))
2629 /* Count the number of input BFDs and find the top input section id. */
2630 for (input_bfd
= info
->input_bfds
, bfd_count
= 0, top_id
= 0;
2631 input_bfd
!= NULL
; input_bfd
= input_bfd
->link
.next
)
2634 for (section
= input_bfd
->sections
;
2635 section
!= NULL
; section
= section
->next
)
2637 if (top_id
< section
->id
)
2638 top_id
= section
->id
;
2641 htab
->bfd_count
= bfd_count
;
2643 amt
= sizeof (struct map_stub
) * (top_id
+ 1);
2644 htab
->stub_group
= bfd_zmalloc (amt
);
2645 if (htab
->stub_group
== NULL
)
2648 /* We can't use output_bfd->section_count here to find the top output
2649 section index as some sections may have been removed, and
2650 _bfd_strip_section_from_output doesn't renumber the indices. */
2651 for (section
= output_bfd
->sections
, top_index
= 0;
2652 section
!= NULL
; section
= section
->next
)
2654 if (top_index
< section
->index
)
2655 top_index
= section
->index
;
2658 htab
->top_index
= top_index
;
2659 amt
= sizeof (asection
*) * (top_index
+ 1);
2660 input_list
= bfd_malloc (amt
);
2661 htab
->input_list
= input_list
;
2662 if (input_list
== NULL
)
2665 /* For sections we aren't interested in, mark their entries with a
2666 value we can check later. */
2667 list
= input_list
+ top_index
;
2669 *list
= bfd_abs_section_ptr
;
2670 while (list
-- != input_list
);
2672 for (section
= output_bfd
->sections
;
2673 section
!= NULL
; section
= section
->next
)
2675 if ((section
->flags
& SEC_CODE
) != 0)
2676 input_list
[section
->index
] = NULL
;
2682 /* Used by elfNN_aarch64_next_input_section and group_sections. */
2683 #define PREV_SEC(sec) (htab->stub_group[(sec)->id].link_sec)
2685 /* The linker repeatedly calls this function for each input section,
2686 in the order that input sections are linked into output sections.
2687 Build lists of input sections to determine groupings between which
2688 we may insert linker stubs. */
2691 elfNN_aarch64_next_input_section (struct bfd_link_info
*info
, asection
*isec
)
2693 struct elf_aarch64_link_hash_table
*htab
=
2694 elf_aarch64_hash_table (info
);
2696 if (isec
->output_section
->index
<= htab
->top_index
)
2698 asection
**list
= htab
->input_list
+ isec
->output_section
->index
;
2700 if (*list
!= bfd_abs_section_ptr
)
2702 /* Steal the link_sec pointer for our list. */
2703 /* This happens to make the list in reverse order,
2704 which is what we want. */
2705 PREV_SEC (isec
) = *list
;
2711 /* See whether we can group stub sections together. Grouping stub
2712 sections may result in fewer stubs. More importantly, we need to
2713 put all .init* and .fini* stubs at the beginning of the .init or
2714 .fini output sections respectively, because glibc splits the
2715 _init and _fini functions into multiple parts. Putting a stub in
2716 the middle of a function is not a good idea. */
2719 group_sections (struct elf_aarch64_link_hash_table
*htab
,
2720 bfd_size_type stub_group_size
,
2721 bfd_boolean stubs_always_before_branch
)
2723 asection
**list
= htab
->input_list
+ htab
->top_index
;
2727 asection
*tail
= *list
;
2729 if (tail
== bfd_abs_section_ptr
)
2732 while (tail
!= NULL
)
2736 bfd_size_type total
;
2740 while ((prev
= PREV_SEC (curr
)) != NULL
2741 && ((total
+= curr
->output_offset
- prev
->output_offset
)
2745 /* OK, the size from the start of CURR to the end is less
2746 than stub_group_size and thus can be handled by one stub
2747 section. (Or the tail section is itself larger than
2748 stub_group_size, in which case we may be toast.)
2749 We should really be keeping track of the total size of
2750 stubs added here, as stubs contribute to the final output
2754 prev
= PREV_SEC (tail
);
2755 /* Set up this stub group. */
2756 htab
->stub_group
[tail
->id
].link_sec
= curr
;
2758 while (tail
!= curr
&& (tail
= prev
) != NULL
);
2760 /* But wait, there's more! Input sections up to stub_group_size
2761 bytes before the stub section can be handled by it too. */
2762 if (!stubs_always_before_branch
)
2766 && ((total
+= tail
->output_offset
- prev
->output_offset
)
2770 prev
= PREV_SEC (tail
);
2771 htab
->stub_group
[tail
->id
].link_sec
= curr
;
2777 while (list
-- != htab
->input_list
);
2779 free (htab
->input_list
);
2784 #define AARCH64_BITS(x, pos, n) (((x) >> (pos)) & ((1 << (n)) - 1))
2786 #define AARCH64_RT(insn) AARCH64_BITS (insn, 0, 5)
2787 #define AARCH64_RT2(insn) AARCH64_BITS (insn, 10, 5)
2788 #define AARCH64_RA(insn) AARCH64_BITS (insn, 10, 5)
2789 #define AARCH64_RD(insn) AARCH64_BITS (insn, 0, 5)
2790 #define AARCH64_RN(insn) AARCH64_BITS (insn, 5, 5)
2791 #define AARCH64_RM(insn) AARCH64_BITS (insn, 16, 5)
2793 #define AARCH64_MAC(insn) (((insn) & 0xff000000) == 0x9b000000)
2794 #define AARCH64_BIT(insn, n) AARCH64_BITS (insn, n, 1)
2795 #define AARCH64_OP31(insn) AARCH64_BITS (insn, 21, 3)
2796 #define AARCH64_ZR 0x1f
2798 /* All ld/st ops. See C4-182 of the ARM ARM. The encoding space for
2799 LD_PCREL, LDST_RO, LDST_UI and LDST_UIMM cover prefetch ops. */
2801 #define AARCH64_LD(insn) (AARCH64_BIT (insn, 22) == 1)
2802 #define AARCH64_LDST(insn) (((insn) & 0x0a000000) == 0x08000000)
2803 #define AARCH64_LDST_EX(insn) (((insn) & 0x3f000000) == 0x08000000)
2804 #define AARCH64_LDST_PCREL(insn) (((insn) & 0x3b000000) == 0x18000000)
2805 #define AARCH64_LDST_NAP(insn) (((insn) & 0x3b800000) == 0x28000000)
2806 #define AARCH64_LDSTP_PI(insn) (((insn) & 0x3b800000) == 0x28800000)
2807 #define AARCH64_LDSTP_O(insn) (((insn) & 0x3b800000) == 0x29000000)
2808 #define AARCH64_LDSTP_PRE(insn) (((insn) & 0x3b800000) == 0x29800000)
2809 #define AARCH64_LDST_UI(insn) (((insn) & 0x3b200c00) == 0x38000000)
2810 #define AARCH64_LDST_PIIMM(insn) (((insn) & 0x3b200c00) == 0x38000400)
2811 #define AARCH64_LDST_U(insn) (((insn) & 0x3b200c00) == 0x38000800)
2812 #define AARCH64_LDST_PREIMM(insn) (((insn) & 0x3b200c00) == 0x38000c00)
2813 #define AARCH64_LDST_RO(insn) (((insn) & 0x3b200c00) == 0x38200800)
2814 #define AARCH64_LDST_UIMM(insn) (((insn) & 0x3b000000) == 0x39000000)
2815 #define AARCH64_LDST_SIMD_M(insn) (((insn) & 0xbfbf0000) == 0x0c000000)
2816 #define AARCH64_LDST_SIMD_M_PI(insn) (((insn) & 0xbfa00000) == 0x0c800000)
2817 #define AARCH64_LDST_SIMD_S(insn) (((insn) & 0xbf9f0000) == 0x0d000000)
2818 #define AARCH64_LDST_SIMD_S_PI(insn) (((insn) & 0xbf800000) == 0x0d800000)
2820 /* Classify an INSN if it is indeed a load/store.
2822 Return TRUE if INSN is a LD/ST instruction otherwise return FALSE.
2824 For scalar LD/ST instructions PAIR is FALSE, RT is returned and RT2
2827 For LD/ST pair instructions PAIR is TRUE, RT and RT2 are returned.
2832 aarch64_mem_op_p (uint32_t insn
, unsigned int *rt
, unsigned int *rt2
,
2833 bfd_boolean
*pair
, bfd_boolean
*load
)
2841 /* Bail out quickly if INSN doesn't fall into the the load-store
2843 if (!AARCH64_LDST (insn
))
2848 if (AARCH64_LDST_EX (insn
))
2850 *rt
= AARCH64_RT (insn
);
2852 if (AARCH64_BIT (insn
, 21) == 1)
2855 *rt2
= AARCH64_RT2 (insn
);
2857 *load
= AARCH64_LD (insn
);
2860 else if (AARCH64_LDST_NAP (insn
)
2861 || AARCH64_LDSTP_PI (insn
)
2862 || AARCH64_LDSTP_O (insn
)
2863 || AARCH64_LDSTP_PRE (insn
))
2866 *rt
= AARCH64_RT (insn
);
2867 *rt2
= AARCH64_RT2 (insn
);
2868 *load
= AARCH64_LD (insn
);
2871 else if (AARCH64_LDST_PCREL (insn
)
2872 || AARCH64_LDST_UI (insn
)
2873 || AARCH64_LDST_PIIMM (insn
)
2874 || AARCH64_LDST_U (insn
)
2875 || AARCH64_LDST_PREIMM (insn
)
2876 || AARCH64_LDST_RO (insn
)
2877 || AARCH64_LDST_UIMM (insn
))
2879 *rt
= AARCH64_RT (insn
);
2881 if (AARCH64_LDST_PCREL (insn
))
2883 opc
= AARCH64_BITS (insn
, 22, 2);
2884 v
= AARCH64_BIT (insn
, 26);
2885 opc_v
= opc
| (v
<< 2);
2886 *load
= (opc_v
== 1 || opc_v
== 2 || opc_v
== 3
2887 || opc_v
== 5 || opc_v
== 7);
2890 else if (AARCH64_LDST_SIMD_M (insn
)
2891 || AARCH64_LDST_SIMD_M_PI (insn
))
2893 *rt
= AARCH64_RT (insn
);
2894 *load
= AARCH64_BIT (insn
, 22);
2895 opcode
= (insn
>> 12) & 0xf;
2922 else if (AARCH64_LDST_SIMD_S (insn
)
2923 || AARCH64_LDST_SIMD_S_PI (insn
))
2925 *rt
= AARCH64_RT (insn
);
2926 r
= (insn
>> 21) & 1;
2927 *load
= AARCH64_BIT (insn
, 22);
2928 opcode
= (insn
>> 13) & 0x7;
2940 *rt2
= *rt
+ (r
== 0 ? 2 : 3);
2948 *rt2
= *rt
+ (r
== 0 ? 2 : 3);
2960 /* Return TRUE if INSN is multiply-accumulate. */
2963 aarch64_mlxl_p (uint32_t insn
)
2965 uint32_t op31
= AARCH64_OP31 (insn
);
2967 if (AARCH64_MAC (insn
)
2968 && (op31
== 0 || op31
== 1 || op31
== 5)
2969 /* Exclude MUL instructions which are encoded as a multiple accumulate
2971 && AARCH64_RA (insn
) != AARCH64_ZR
)
2977 /* Some early revisions of the Cortex-A53 have an erratum (835769) whereby
2978 it is possible for a 64-bit multiply-accumulate instruction to generate an
2979 incorrect result. The details are quite complex and hard to
2980 determine statically, since branches in the code may exist in some
2981 circumstances, but all cases end with a memory (load, store, or
2982 prefetch) instruction followed immediately by the multiply-accumulate
2983 operation. We employ a linker patching technique, by moving the potentially
2984 affected multiply-accumulate instruction into a patch region and replacing
2985 the original instruction with a branch to the patch. This function checks
2986 if INSN_1 is the memory operation followed by a multiply-accumulate
2987 operation (INSN_2). Return TRUE if an erratum sequence is found, FALSE
2988 if INSN_1 and INSN_2 are safe. */
2991 aarch64_erratum_sequence (uint32_t insn_1
, uint32_t insn_2
)
3001 if (aarch64_mlxl_p (insn_2
)
3002 && aarch64_mem_op_p (insn_1
, &rt
, &rt2
, &pair
, &load
))
3004 /* Any SIMD memory op is independent of the subsequent MLA
3005 by definition of the erratum. */
3006 if (AARCH64_BIT (insn_1
, 26))
3009 /* If not SIMD, check for integer memory ops and MLA relationship. */
3010 rn
= AARCH64_RN (insn_2
);
3011 ra
= AARCH64_RA (insn_2
);
3012 rm
= AARCH64_RM (insn_2
);
3014 /* If this is a load and there's a true(RAW) dependency, we are safe
3015 and this is not an erratum sequence. */
3017 (rt
== rn
|| rt
== rm
|| rt
== ra
3018 || (pair
&& (rt2
== rn
|| rt2
== rm
|| rt2
== ra
))))
3021 /* We conservatively put out stubs for all other cases (including
3029 /* Used to order a list of mapping symbols by address. */
3032 elf_aarch64_compare_mapping (const void *a
, const void *b
)
3034 const elf_aarch64_section_map
*amap
= (const elf_aarch64_section_map
*) a
;
3035 const elf_aarch64_section_map
*bmap
= (const elf_aarch64_section_map
*) b
;
3037 if (amap
->vma
> bmap
->vma
)
3039 else if (amap
->vma
< bmap
->vma
)
3041 else if (amap
->type
> bmap
->type
)
3042 /* Ensure results do not depend on the host qsort for objects with
3043 multiple mapping symbols at the same address by sorting on type
3046 else if (amap
->type
< bmap
->type
)
3054 _bfd_aarch64_erratum_835769_stub_name (unsigned num_fixes
)
3056 char *stub_name
= (char *) bfd_malloc
3057 (strlen ("__erratum_835769_veneer_") + 16);
3058 sprintf (stub_name
,"__erratum_835769_veneer_%d", num_fixes
);
3062 /* Scan for Cortex-A53 erratum 835769 sequence.
3064 Return TRUE else FALSE on abnormal termination. */
3067 _bfd_aarch64_erratum_835769_scan (bfd
*input_bfd
,
3068 struct bfd_link_info
*info
,
3069 unsigned int *num_fixes_p
)
3072 struct elf_aarch64_link_hash_table
*htab
= elf_aarch64_hash_table (info
);
3073 unsigned int num_fixes
= *num_fixes_p
;
3078 for (section
= input_bfd
->sections
;
3080 section
= section
->next
)
3082 bfd_byte
*contents
= NULL
;
3083 struct _aarch64_elf_section_data
*sec_data
;
3086 if (elf_section_type (section
) != SHT_PROGBITS
3087 || (elf_section_flags (section
) & SHF_EXECINSTR
) == 0
3088 || (section
->flags
& SEC_EXCLUDE
) != 0
3089 || (section
->sec_info_type
== SEC_INFO_TYPE_JUST_SYMS
)
3090 || (section
->output_section
== bfd_abs_section_ptr
))
3093 if (elf_section_data (section
)->this_hdr
.contents
!= NULL
)
3094 contents
= elf_section_data (section
)->this_hdr
.contents
;
3095 else if (! bfd_malloc_and_get_section (input_bfd
, section
, &contents
))
3098 sec_data
= elf_aarch64_section_data (section
);
3100 qsort (sec_data
->map
, sec_data
->mapcount
,
3101 sizeof (elf_aarch64_section_map
), elf_aarch64_compare_mapping
);
3103 for (span
= 0; span
< sec_data
->mapcount
; span
++)
3105 unsigned int span_start
= sec_data
->map
[span
].vma
;
3106 unsigned int span_end
= ((span
== sec_data
->mapcount
- 1)
3107 ? sec_data
->map
[0].vma
+ section
->size
3108 : sec_data
->map
[span
+ 1].vma
);
3110 char span_type
= sec_data
->map
[span
].type
;
3112 if (span_type
== 'd')
3115 for (i
= span_start
; i
+ 4 < span_end
; i
+= 4)
3117 uint32_t insn_1
= bfd_getl32 (contents
+ i
);
3118 uint32_t insn_2
= bfd_getl32 (contents
+ i
+ 4);
3120 if (aarch64_erratum_sequence (insn_1
, insn_2
))
3122 struct elf_aarch64_stub_hash_entry
*stub_entry
;
3123 char *stub_name
= _bfd_aarch64_erratum_835769_stub_name (num_fixes
);
3127 stub_entry
= _bfd_aarch64_add_stub_entry_in_group (stub_name
,
3133 stub_entry
->stub_type
= aarch64_stub_erratum_835769_veneer
;
3134 stub_entry
->target_section
= section
;
3135 stub_entry
->target_value
= i
+ 4;
3136 stub_entry
->veneered_insn
= insn_2
;
3137 stub_entry
->output_name
= stub_name
;
3142 if (elf_section_data (section
)->this_hdr
.contents
== NULL
)
3146 *num_fixes_p
= num_fixes
;
3152 /* Test if instruction INSN is ADRP. */
3155 _bfd_aarch64_adrp_p (uint32_t insn
)
3157 return ((insn
& 0x9f000000) == 0x90000000);
3161 /* Helper predicate to look for cortex-a53 erratum 843419 sequence 1. */
3164 _bfd_aarch64_erratum_843419_sequence_p (uint32_t insn_1
, uint32_t insn_2
,
3172 return (aarch64_mem_op_p (insn_2
, &rt
, &rt2
, &pair
, &load
)
3175 && AARCH64_LDST_UIMM (insn_3
)
3176 && AARCH64_RN (insn_3
) == AARCH64_RD (insn_1
));
3180 /* Test for the presence of Cortex-A53 erratum 843419 instruction sequence.
3182 Return TRUE if section CONTENTS at offset I contains one of the
3183 erratum 843419 sequences, otherwise return FALSE. If a sequence is
3184 seen set P_VENEER_I to the offset of the final LOAD/STORE
3185 instruction in the sequence.
3189 _bfd_aarch64_erratum_843419_p (bfd_byte
*contents
, bfd_vma vma
,
3190 bfd_vma i
, bfd_vma span_end
,
3191 bfd_vma
*p_veneer_i
)
3193 uint32_t insn_1
= bfd_getl32 (contents
+ i
);
3195 if (!_bfd_aarch64_adrp_p (insn_1
))
3198 if (span_end
< i
+ 12)
3201 uint32_t insn_2
= bfd_getl32 (contents
+ i
+ 4);
3202 uint32_t insn_3
= bfd_getl32 (contents
+ i
+ 8);
3204 if ((vma
& 0xfff) != 0xff8 && (vma
& 0xfff) != 0xffc)
3207 if (_bfd_aarch64_erratum_843419_sequence_p (insn_1
, insn_2
, insn_3
))
3209 *p_veneer_i
= i
+ 8;
3213 if (span_end
< i
+ 16)
3216 uint32_t insn_4
= bfd_getl32 (contents
+ i
+ 12);
3218 if (_bfd_aarch64_erratum_843419_sequence_p (insn_1
, insn_2
, insn_4
))
3220 *p_veneer_i
= i
+ 12;
3228 /* Resize all stub sections. */
3231 _bfd_aarch64_resize_stubs (struct elf_aarch64_link_hash_table
*htab
)
3235 /* OK, we've added some stubs. Find out the new size of the
3237 for (section
= htab
->stub_bfd
->sections
;
3238 section
!= NULL
; section
= section
->next
)
3240 /* Ignore non-stub sections. */
3241 if (!strstr (section
->name
, STUB_SUFFIX
))
3246 bfd_hash_traverse (&htab
->stub_hash_table
, aarch64_size_one_stub
, htab
);
3248 for (section
= htab
->stub_bfd
->sections
;
3249 section
!= NULL
; section
= section
->next
)
3251 if (!strstr (section
->name
, STUB_SUFFIX
))
3257 /* Ensure all stub sections have a size which is a multiple of
3258 4096. This is important in order to ensure that the insertion
3259 of stub sections does not in itself move existing code around
3260 in such a way that new errata sequences are created. */
3261 if (htab
->fix_erratum_843419
)
3263 section
->size
= BFD_ALIGN (section
->size
, 0x1000);
3268 /* Construct an erratum 843419 workaround stub name.
3272 _bfd_aarch64_erratum_843419_stub_name (asection
*input_section
,
3275 const bfd_size_type len
= 8 + 4 + 1 + 8 + 1 + 16 + 1;
3276 char *stub_name
= bfd_malloc (len
);
3278 if (stub_name
!= NULL
)
3279 snprintf (stub_name
, len
, "e843419@%04x_%08x_%" BFD_VMA_FMT
"x",
3280 input_section
->owner
->id
,
3286 /* Build a stub_entry structure describing an 843419 fixup.
3288 The stub_entry constructed is populated with the bit pattern INSN
3289 of the instruction located at OFFSET within input SECTION.
3291 Returns TRUE on success. */
3294 _bfd_aarch64_erratum_843419_fixup (uint32_t insn
,
3295 bfd_vma adrp_offset
,
3296 bfd_vma ldst_offset
,
3298 struct bfd_link_info
*info
)
3300 struct elf_aarch64_link_hash_table
*htab
= elf_aarch64_hash_table (info
);
3302 struct elf_aarch64_stub_hash_entry
*stub_entry
;
3304 stub_name
= _bfd_aarch64_erratum_843419_stub_name (section
, ldst_offset
);
3305 stub_entry
= aarch64_stub_hash_lookup (&htab
->stub_hash_table
, stub_name
,
3313 /* We always place an 843419 workaround veneer in the stub section
3314 attached to the input section in which an erratum sequence has
3315 been found. This ensures that later in the link process (in
3316 elfNN_aarch64_write_section) when we copy the veneered
3317 instruction from the input section into the stub section the
3318 copied instruction will have had any relocations applied to it.
3319 If we placed workaround veneers in any other stub section then we
3320 could not assume that all relocations have been processed on the
3321 corresponding input section at the point we output the stub
3325 stub_entry
= _bfd_aarch64_add_stub_entry_after (stub_name
, section
, htab
);
3326 if (stub_entry
== NULL
)
3332 stub_entry
->adrp_offset
= adrp_offset
;
3333 stub_entry
->target_value
= ldst_offset
;
3334 stub_entry
->target_section
= section
;
3335 stub_entry
->stub_type
= aarch64_stub_erratum_843419_veneer
;
3336 stub_entry
->veneered_insn
= insn
;
3337 stub_entry
->output_name
= stub_name
;
3343 /* Scan an input section looking for the signature of erratum 843419.
3345 Scans input SECTION in INPUT_BFD looking for erratum 843419
3346 signatures, for each signature found a stub_entry is created
3347 describing the location of the erratum for subsequent fixup.
3349 Return TRUE on successful scan, FALSE on failure to scan.
3353 _bfd_aarch64_erratum_843419_scan (bfd
*input_bfd
, asection
*section
,
3354 struct bfd_link_info
*info
)
3356 struct elf_aarch64_link_hash_table
*htab
= elf_aarch64_hash_table (info
);
3361 if (elf_section_type (section
) != SHT_PROGBITS
3362 || (elf_section_flags (section
) & SHF_EXECINSTR
) == 0
3363 || (section
->flags
& SEC_EXCLUDE
) != 0
3364 || (section
->sec_info_type
== SEC_INFO_TYPE_JUST_SYMS
)
3365 || (section
->output_section
== bfd_abs_section_ptr
))
3370 bfd_byte
*contents
= NULL
;
3371 struct _aarch64_elf_section_data
*sec_data
;
3374 if (elf_section_data (section
)->this_hdr
.contents
!= NULL
)
3375 contents
= elf_section_data (section
)->this_hdr
.contents
;
3376 else if (! bfd_malloc_and_get_section (input_bfd
, section
, &contents
))
3379 sec_data
= elf_aarch64_section_data (section
);
3381 qsort (sec_data
->map
, sec_data
->mapcount
,
3382 sizeof (elf_aarch64_section_map
), elf_aarch64_compare_mapping
);
3384 for (span
= 0; span
< sec_data
->mapcount
; span
++)
3386 unsigned int span_start
= sec_data
->map
[span
].vma
;
3387 unsigned int span_end
= ((span
== sec_data
->mapcount
- 1)
3388 ? sec_data
->map
[0].vma
+ section
->size
3389 : sec_data
->map
[span
+ 1].vma
);
3391 char span_type
= sec_data
->map
[span
].type
;
3393 if (span_type
== 'd')
3396 for (i
= span_start
; i
+ 8 < span_end
; i
+= 4)
3398 bfd_vma vma
= (section
->output_section
->vma
3399 + section
->output_offset
3403 if (_bfd_aarch64_erratum_843419_p
3404 (contents
, vma
, i
, span_end
, &veneer_i
))
3406 uint32_t insn
= bfd_getl32 (contents
+ veneer_i
);
3408 if (!_bfd_aarch64_erratum_843419_fixup (insn
, i
, veneer_i
,
3415 if (elf_section_data (section
)->this_hdr
.contents
== NULL
)
3424 /* Determine and set the size of the stub section for a final link.
3426 The basic idea here is to examine all the relocations looking for
3427 PC-relative calls to a target that is unreachable with a "bl"
3431 elfNN_aarch64_size_stubs (bfd
*output_bfd
,
3433 struct bfd_link_info
*info
,
3434 bfd_signed_vma group_size
,
3435 asection
* (*add_stub_section
) (const char *,
3437 void (*layout_sections_again
) (void))
3439 bfd_size_type stub_group_size
;
3440 bfd_boolean stubs_always_before_branch
;
3441 bfd_boolean stub_changed
= FALSE
;
3442 struct elf_aarch64_link_hash_table
*htab
= elf_aarch64_hash_table (info
);
3443 unsigned int num_erratum_835769_fixes
= 0;
3445 /* Propagate mach to stub bfd, because it may not have been
3446 finalized when we created stub_bfd. */
3447 bfd_set_arch_mach (stub_bfd
, bfd_get_arch (output_bfd
),
3448 bfd_get_mach (output_bfd
));
3450 /* Stash our params away. */
3451 htab
->stub_bfd
= stub_bfd
;
3452 htab
->add_stub_section
= add_stub_section
;
3453 htab
->layout_sections_again
= layout_sections_again
;
3454 stubs_always_before_branch
= group_size
< 0;
3456 stub_group_size
= -group_size
;
3458 stub_group_size
= group_size
;
3460 if (stub_group_size
== 1)
3462 /* Default values. */
3463 /* AArch64 branch range is +-128MB. The value used is 1MB less. */
3464 stub_group_size
= 127 * 1024 * 1024;
3467 group_sections (htab
, stub_group_size
, stubs_always_before_branch
);
3469 (*htab
->layout_sections_again
) ();
3471 if (htab
->fix_erratum_835769
)
3475 for (input_bfd
= info
->input_bfds
;
3476 input_bfd
!= NULL
; input_bfd
= input_bfd
->link
.next
)
3477 if (!_bfd_aarch64_erratum_835769_scan (input_bfd
, info
,
3478 &num_erratum_835769_fixes
))
3481 _bfd_aarch64_resize_stubs (htab
);
3482 (*htab
->layout_sections_again
) ();
3485 if (htab
->fix_erratum_843419
)
3489 for (input_bfd
= info
->input_bfds
;
3491 input_bfd
= input_bfd
->link
.next
)
3495 for (section
= input_bfd
->sections
;
3497 section
= section
->next
)
3498 if (!_bfd_aarch64_erratum_843419_scan (input_bfd
, section
, info
))
3502 _bfd_aarch64_resize_stubs (htab
);
3503 (*htab
->layout_sections_again
) ();
3510 for (input_bfd
= info
->input_bfds
;
3511 input_bfd
!= NULL
; input_bfd
= input_bfd
->link
.next
)
3513 Elf_Internal_Shdr
*symtab_hdr
;
3515 Elf_Internal_Sym
*local_syms
= NULL
;
3517 /* We'll need the symbol table in a second. */
3518 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
3519 if (symtab_hdr
->sh_info
== 0)
3522 /* Walk over each section attached to the input bfd. */
3523 for (section
= input_bfd
->sections
;
3524 section
!= NULL
; section
= section
->next
)
3526 Elf_Internal_Rela
*internal_relocs
, *irelaend
, *irela
;
3528 /* If there aren't any relocs, then there's nothing more
3530 if ((section
->flags
& SEC_RELOC
) == 0
3531 || section
->reloc_count
== 0
3532 || (section
->flags
& SEC_CODE
) == 0)
3535 /* If this section is a link-once section that will be
3536 discarded, then don't create any stubs. */
3537 if (section
->output_section
== NULL
3538 || section
->output_section
->owner
!= output_bfd
)
3541 /* Get the relocs. */
3543 = _bfd_elf_link_read_relocs (input_bfd
, section
, NULL
,
3544 NULL
, info
->keep_memory
);
3545 if (internal_relocs
== NULL
)
3546 goto error_ret_free_local
;
3548 /* Now examine each relocation. */
3549 irela
= internal_relocs
;
3550 irelaend
= irela
+ section
->reloc_count
;
3551 for (; irela
< irelaend
; irela
++)
3553 unsigned int r_type
, r_indx
;
3554 enum elf_aarch64_stub_type stub_type
;
3555 struct elf_aarch64_stub_hash_entry
*stub_entry
;
3558 bfd_vma destination
;
3559 struct elf_aarch64_link_hash_entry
*hash
;
3560 const char *sym_name
;
3562 const asection
*id_sec
;
3563 unsigned char st_type
;
3566 r_type
= ELFNN_R_TYPE (irela
->r_info
);
3567 r_indx
= ELFNN_R_SYM (irela
->r_info
);
3569 if (r_type
>= (unsigned int) R_AARCH64_end
)
3571 bfd_set_error (bfd_error_bad_value
);
3572 error_ret_free_internal
:
3573 if (elf_section_data (section
)->relocs
== NULL
)
3574 free (internal_relocs
);
3575 goto error_ret_free_local
;
3578 /* Only look for stubs on unconditional branch and
3579 branch and link instructions. */
3580 if (r_type
!= (unsigned int) AARCH64_R (CALL26
)
3581 && r_type
!= (unsigned int) AARCH64_R (JUMP26
))
3584 /* Now determine the call target, its name, value,
3591 if (r_indx
< symtab_hdr
->sh_info
)
3593 /* It's a local symbol. */
3594 Elf_Internal_Sym
*sym
;
3595 Elf_Internal_Shdr
*hdr
;
3597 if (local_syms
== NULL
)
3600 = (Elf_Internal_Sym
*) symtab_hdr
->contents
;
3601 if (local_syms
== NULL
)
3603 = bfd_elf_get_elf_syms (input_bfd
, symtab_hdr
,
3604 symtab_hdr
->sh_info
, 0,
3606 if (local_syms
== NULL
)
3607 goto error_ret_free_internal
;
3610 sym
= local_syms
+ r_indx
;
3611 hdr
= elf_elfsections (input_bfd
)[sym
->st_shndx
];
3612 sym_sec
= hdr
->bfd_section
;
3614 /* This is an undefined symbol. It can never
3618 if (ELF_ST_TYPE (sym
->st_info
) != STT_SECTION
)
3619 sym_value
= sym
->st_value
;
3620 destination
= (sym_value
+ irela
->r_addend
3621 + sym_sec
->output_offset
3622 + sym_sec
->output_section
->vma
);
3623 st_type
= ELF_ST_TYPE (sym
->st_info
);
3625 = bfd_elf_string_from_elf_section (input_bfd
,
3626 symtab_hdr
->sh_link
,
3633 e_indx
= r_indx
- symtab_hdr
->sh_info
;
3634 hash
= ((struct elf_aarch64_link_hash_entry
*)
3635 elf_sym_hashes (input_bfd
)[e_indx
]);
3637 while (hash
->root
.root
.type
== bfd_link_hash_indirect
3638 || hash
->root
.root
.type
== bfd_link_hash_warning
)
3639 hash
= ((struct elf_aarch64_link_hash_entry
*)
3640 hash
->root
.root
.u
.i
.link
);
3642 if (hash
->root
.root
.type
== bfd_link_hash_defined
3643 || hash
->root
.root
.type
== bfd_link_hash_defweak
)
3645 struct elf_aarch64_link_hash_table
*globals
=
3646 elf_aarch64_hash_table (info
);
3647 sym_sec
= hash
->root
.root
.u
.def
.section
;
3648 sym_value
= hash
->root
.root
.u
.def
.value
;
3649 /* For a destination in a shared library,
3650 use the PLT stub as target address to
3651 decide whether a branch stub is
3653 if (globals
->root
.splt
!= NULL
&& hash
!= NULL
3654 && hash
->root
.plt
.offset
!= (bfd_vma
) - 1)
3656 sym_sec
= globals
->root
.splt
;
3657 sym_value
= hash
->root
.plt
.offset
;
3658 if (sym_sec
->output_section
!= NULL
)
3659 destination
= (sym_value
3660 + sym_sec
->output_offset
3662 sym_sec
->output_section
->vma
);
3664 else if (sym_sec
->output_section
!= NULL
)
3665 destination
= (sym_value
+ irela
->r_addend
3666 + sym_sec
->output_offset
3667 + sym_sec
->output_section
->vma
);
3669 else if (hash
->root
.root
.type
== bfd_link_hash_undefined
3670 || (hash
->root
.root
.type
3671 == bfd_link_hash_undefweak
))
3673 /* For a shared library, use the PLT stub as
3674 target address to decide whether a long
3675 branch stub is needed.
3676 For absolute code, they cannot be handled. */
3677 struct elf_aarch64_link_hash_table
*globals
=
3678 elf_aarch64_hash_table (info
);
3680 if (globals
->root
.splt
!= NULL
&& hash
!= NULL
3681 && hash
->root
.plt
.offset
!= (bfd_vma
) - 1)
3683 sym_sec
= globals
->root
.splt
;
3684 sym_value
= hash
->root
.plt
.offset
;
3685 if (sym_sec
->output_section
!= NULL
)
3686 destination
= (sym_value
3687 + sym_sec
->output_offset
3689 sym_sec
->output_section
->vma
);
3696 bfd_set_error (bfd_error_bad_value
);
3697 goto error_ret_free_internal
;
3699 st_type
= ELF_ST_TYPE (hash
->root
.type
);
3700 sym_name
= hash
->root
.root
.root
.string
;
3703 /* Determine what (if any) linker stub is needed. */
3704 stub_type
= aarch64_type_of_stub
3705 (info
, section
, irela
, st_type
, hash
, destination
);
3706 if (stub_type
== aarch64_stub_none
)
3709 /* Support for grouping stub sections. */
3710 id_sec
= htab
->stub_group
[section
->id
].link_sec
;
3712 /* Get the name of this stub. */
3713 stub_name
= elfNN_aarch64_stub_name (id_sec
, sym_sec
, hash
,
3716 goto error_ret_free_internal
;
3719 aarch64_stub_hash_lookup (&htab
->stub_hash_table
,
3720 stub_name
, FALSE
, FALSE
);
3721 if (stub_entry
!= NULL
)
3723 /* The proper stub has already been created. */
3728 stub_entry
= _bfd_aarch64_add_stub_entry_in_group
3729 (stub_name
, section
, htab
);
3730 if (stub_entry
== NULL
)
3733 goto error_ret_free_internal
;
3736 stub_entry
->target_value
= sym_value
;
3737 stub_entry
->target_section
= sym_sec
;
3738 stub_entry
->stub_type
= stub_type
;
3739 stub_entry
->h
= hash
;
3740 stub_entry
->st_type
= st_type
;
3742 if (sym_name
== NULL
)
3743 sym_name
= "unnamed";
3744 len
= sizeof (STUB_ENTRY_NAME
) + strlen (sym_name
);
3745 stub_entry
->output_name
= bfd_alloc (htab
->stub_bfd
, len
);
3746 if (stub_entry
->output_name
== NULL
)
3749 goto error_ret_free_internal
;
3752 snprintf (stub_entry
->output_name
, len
, STUB_ENTRY_NAME
,
3755 stub_changed
= TRUE
;
3758 /* We're done with the internal relocs, free them. */
3759 if (elf_section_data (section
)->relocs
== NULL
)
3760 free (internal_relocs
);
3767 _bfd_aarch64_resize_stubs (htab
);
3769 /* Ask the linker to do its stuff. */
3770 (*htab
->layout_sections_again
) ();
3771 stub_changed
= FALSE
;
3776 error_ret_free_local
:
3780 /* Build all the stubs associated with the current output file. The
3781 stubs are kept in a hash table attached to the main linker hash
3782 table. We also set up the .plt entries for statically linked PIC
3783 functions here. This function is called via aarch64_elf_finish in the
3787 elfNN_aarch64_build_stubs (struct bfd_link_info
*info
)
3790 struct bfd_hash_table
*table
;
3791 struct elf_aarch64_link_hash_table
*htab
;
3793 htab
= elf_aarch64_hash_table (info
);
3795 for (stub_sec
= htab
->stub_bfd
->sections
;
3796 stub_sec
!= NULL
; stub_sec
= stub_sec
->next
)
3800 /* Ignore non-stub sections. */
3801 if (!strstr (stub_sec
->name
, STUB_SUFFIX
))
3804 /* Allocate memory to hold the linker stubs. */
3805 size
= stub_sec
->size
;
3806 stub_sec
->contents
= bfd_zalloc (htab
->stub_bfd
, size
);
3807 if (stub_sec
->contents
== NULL
&& size
!= 0)
3811 bfd_putl32 (0x14000000 | (size
>> 2), stub_sec
->contents
);
3812 stub_sec
->size
+= 4;
3815 /* Build the stubs as directed by the stub hash table. */
3816 table
= &htab
->stub_hash_table
;
3817 bfd_hash_traverse (table
, aarch64_build_one_stub
, info
);
3823 /* Add an entry to the code/data map for section SEC. */
3826 elfNN_aarch64_section_map_add (asection
*sec
, char type
, bfd_vma vma
)
3828 struct _aarch64_elf_section_data
*sec_data
=
3829 elf_aarch64_section_data (sec
);
3830 unsigned int newidx
;
3832 if (sec_data
->map
== NULL
)
3834 sec_data
->map
= bfd_malloc (sizeof (elf_aarch64_section_map
));
3835 sec_data
->mapcount
= 0;
3836 sec_data
->mapsize
= 1;
3839 newidx
= sec_data
->mapcount
++;
3841 if (sec_data
->mapcount
> sec_data
->mapsize
)
3843 sec_data
->mapsize
*= 2;
3844 sec_data
->map
= bfd_realloc_or_free
3845 (sec_data
->map
, sec_data
->mapsize
* sizeof (elf_aarch64_section_map
));
3850 sec_data
->map
[newidx
].vma
= vma
;
3851 sec_data
->map
[newidx
].type
= type
;
3856 /* Initialise maps of insn/data for input BFDs. */
3858 bfd_elfNN_aarch64_init_maps (bfd
*abfd
)
3860 Elf_Internal_Sym
*isymbuf
;
3861 Elf_Internal_Shdr
*hdr
;
3862 unsigned int i
, localsyms
;
3864 /* Make sure that we are dealing with an AArch64 elf binary. */
3865 if (!is_aarch64_elf (abfd
))
3868 if ((abfd
->flags
& DYNAMIC
) != 0)
3871 hdr
= &elf_symtab_hdr (abfd
);
3872 localsyms
= hdr
->sh_info
;
3874 /* Obtain a buffer full of symbols for this BFD. The hdr->sh_info field
3875 should contain the number of local symbols, which should come before any
3876 global symbols. Mapping symbols are always local. */
3877 isymbuf
= bfd_elf_get_elf_syms (abfd
, hdr
, localsyms
, 0, NULL
, NULL
, NULL
);
3879 /* No internal symbols read? Skip this BFD. */
3880 if (isymbuf
== NULL
)
3883 for (i
= 0; i
< localsyms
; i
++)
3885 Elf_Internal_Sym
*isym
= &isymbuf
[i
];
3886 asection
*sec
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
3889 if (sec
!= NULL
&& ELF_ST_BIND (isym
->st_info
) == STB_LOCAL
)
3891 name
= bfd_elf_string_from_elf_section (abfd
,
3895 if (bfd_is_aarch64_special_symbol_name
3896 (name
, BFD_AARCH64_SPECIAL_SYM_TYPE_MAP
))
3897 elfNN_aarch64_section_map_add (sec
, name
[1], isym
->st_value
);
3902 /* Set option values needed during linking. */
3904 bfd_elfNN_aarch64_set_options (struct bfd
*output_bfd
,
3905 struct bfd_link_info
*link_info
,
3907 int no_wchar_warn
, int pic_veneer
,
3908 int fix_erratum_835769
,
3909 int fix_erratum_843419
)
3911 struct elf_aarch64_link_hash_table
*globals
;
3913 globals
= elf_aarch64_hash_table (link_info
);
3914 globals
->pic_veneer
= pic_veneer
;
3915 globals
->fix_erratum_835769
= fix_erratum_835769
;
3916 globals
->fix_erratum_843419
= fix_erratum_843419
;
3917 globals
->fix_erratum_843419_adr
= TRUE
;
3919 BFD_ASSERT (is_aarch64_elf (output_bfd
));
3920 elf_aarch64_tdata (output_bfd
)->no_enum_size_warning
= no_enum_warn
;
3921 elf_aarch64_tdata (output_bfd
)->no_wchar_size_warning
= no_wchar_warn
;
3925 aarch64_calculate_got_entry_vma (struct elf_link_hash_entry
*h
,
3926 struct elf_aarch64_link_hash_table
3927 *globals
, struct bfd_link_info
*info
,
3928 bfd_vma value
, bfd
*output_bfd
,
3929 bfd_boolean
*unresolved_reloc_p
)
3931 bfd_vma off
= (bfd_vma
) - 1;
3932 asection
*basegot
= globals
->root
.sgot
;
3933 bfd_boolean dyn
= globals
->root
.dynamic_sections_created
;
3937 BFD_ASSERT (basegot
!= NULL
);
3938 off
= h
->got
.offset
;
3939 BFD_ASSERT (off
!= (bfd_vma
) - 1);
3940 if (!WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, info
->shared
, h
)
3942 && SYMBOL_REFERENCES_LOCAL (info
, h
))
3943 || (ELF_ST_VISIBILITY (h
->other
)
3944 && h
->root
.type
== bfd_link_hash_undefweak
))
3946 /* This is actually a static link, or it is a -Bsymbolic link
3947 and the symbol is defined locally. We must initialize this
3948 entry in the global offset table. Since the offset must
3949 always be a multiple of 8 (4 in the case of ILP32), we use
3950 the least significant bit to record whether we have
3951 initialized it already.
3952 When doing a dynamic link, we create a .rel(a).got relocation
3953 entry to initialize the value. This is done in the
3954 finish_dynamic_symbol routine. */
3959 bfd_put_NN (output_bfd
, value
, basegot
->contents
+ off
);
3964 *unresolved_reloc_p
= FALSE
;
3966 off
= off
+ basegot
->output_section
->vma
+ basegot
->output_offset
;
3972 /* Change R_TYPE to a more efficient access model where possible,
3973 return the new reloc type. */
3975 static bfd_reloc_code_real_type
3976 aarch64_tls_transition_without_check (bfd_reloc_code_real_type r_type
,
3977 struct elf_link_hash_entry
*h
)
3979 bfd_boolean is_local
= h
== NULL
;
3983 case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21
:
3984 case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21
:
3986 ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1
3987 : BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21
);
3989 case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21
:
3991 ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC
3994 case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19
:
3996 ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1
3997 : BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19
);
3999 case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC
:
4000 case BFD_RELOC_AARCH64_TLSDESC_LDNN_LO12_NC
:
4002 ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC
4003 : BFD_RELOC_AARCH64_TLSIE_LDNN_GOTTPREL_LO12_NC
);
4005 case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21
:
4006 return is_local
? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1
: r_type
;
4008 case BFD_RELOC_AARCH64_TLSIE_LDNN_GOTTPREL_LO12_NC
:
4009 return is_local
? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC
: r_type
;
4011 case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19
:
4014 case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21
:
4016 ? BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_HI12
4017 : BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19
);
4019 case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12_NC
:
4020 case BFD_RELOC_AARCH64_TLSDESC_CALL
:
4021 /* Instructions with these relocations will become NOPs. */
4022 return BFD_RELOC_AARCH64_NONE
;
4032 aarch64_reloc_got_type (bfd_reloc_code_real_type r_type
)
4036 case BFD_RELOC_AARCH64_LD64_GOT_LO12_NC
:
4037 case BFD_RELOC_AARCH64_LD32_GOT_LO12_NC
:
4038 case BFD_RELOC_AARCH64_ADR_GOT_PAGE
:
4039 case BFD_RELOC_AARCH64_GOT_LD_PREL19
:
4042 case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21
:
4043 case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21
:
4044 case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC
:
4047 case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12_NC
:
4048 case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21
:
4049 case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21
:
4050 case BFD_RELOC_AARCH64_TLSDESC_CALL
:
4051 case BFD_RELOC_AARCH64_TLSDESC_LD64_LO12_NC
:
4052 case BFD_RELOC_AARCH64_TLSDESC_LD32_LO12_NC
:
4053 case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19
:
4054 return GOT_TLSDESC_GD
;
4056 case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21
:
4057 case BFD_RELOC_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC
:
4058 case BFD_RELOC_AARCH64_TLSIE_LD32_GOTTPREL_LO12_NC
:
4059 case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19
:
4062 case BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_HI12
:
4063 case BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_LO12
:
4064 case BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_LO12_NC
:
4065 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0
:
4066 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC
:
4067 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1
:
4068 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1_NC
:
4069 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G2
:
4079 aarch64_can_relax_tls (bfd
*input_bfd
,
4080 struct bfd_link_info
*info
,
4081 bfd_reloc_code_real_type r_type
,
4082 struct elf_link_hash_entry
*h
,
4083 unsigned long r_symndx
)
4085 unsigned int symbol_got_type
;
4086 unsigned int reloc_got_type
;
4088 if (! IS_AARCH64_TLS_RELOC (r_type
))
4091 symbol_got_type
= elfNN_aarch64_symbol_got_type (h
, input_bfd
, r_symndx
);
4092 reloc_got_type
= aarch64_reloc_got_type (r_type
);
4094 if (symbol_got_type
== GOT_TLS_IE
&& GOT_TLS_GD_ANY_P (reloc_got_type
))
4100 if (h
&& h
->root
.type
== bfd_link_hash_undefweak
)
4106 /* Given the relocation code R_TYPE, return the relaxed bfd reloc
4109 static bfd_reloc_code_real_type
4110 aarch64_tls_transition (bfd
*input_bfd
,
4111 struct bfd_link_info
*info
,
4112 unsigned int r_type
,
4113 struct elf_link_hash_entry
*h
,
4114 unsigned long r_symndx
)
4116 bfd_reloc_code_real_type bfd_r_type
4117 = elfNN_aarch64_bfd_reloc_from_type (r_type
);
4119 if (! aarch64_can_relax_tls (input_bfd
, info
, bfd_r_type
, h
, r_symndx
))
4122 return aarch64_tls_transition_without_check (bfd_r_type
, h
);
4125 /* Return the base VMA address which should be subtracted from real addresses
4126 when resolving R_AARCH64_TLS_DTPREL relocation. */
4129 dtpoff_base (struct bfd_link_info
*info
)
4131 /* If tls_sec is NULL, we should have signalled an error already. */
4132 BFD_ASSERT (elf_hash_table (info
)->tls_sec
!= NULL
);
4133 return elf_hash_table (info
)->tls_sec
->vma
;
4136 /* Return the base VMA address which should be subtracted from real addresses
4137 when resolving R_AARCH64_TLS_GOTTPREL64 relocations. */
4140 tpoff_base (struct bfd_link_info
*info
)
4142 struct elf_link_hash_table
*htab
= elf_hash_table (info
);
4144 /* If tls_sec is NULL, we should have signalled an error already. */
4145 BFD_ASSERT (htab
->tls_sec
!= NULL
);
4147 bfd_vma base
= align_power ((bfd_vma
) TCB_SIZE
,
4148 htab
->tls_sec
->alignment_power
);
4149 return htab
->tls_sec
->vma
- base
;
4153 symbol_got_offset_ref (bfd
*input_bfd
, struct elf_link_hash_entry
*h
,
4154 unsigned long r_symndx
)
4156 /* Calculate the address of the GOT entry for symbol
4157 referred to in h. */
4159 return &h
->got
.offset
;
4163 struct elf_aarch64_local_symbol
*l
;
4165 l
= elf_aarch64_locals (input_bfd
);
4166 return &l
[r_symndx
].got_offset
;
4171 symbol_got_offset_mark (bfd
*input_bfd
, struct elf_link_hash_entry
*h
,
4172 unsigned long r_symndx
)
4175 p
= symbol_got_offset_ref (input_bfd
, h
, r_symndx
);
4180 symbol_got_offset_mark_p (bfd
*input_bfd
, struct elf_link_hash_entry
*h
,
4181 unsigned long r_symndx
)
4184 value
= * symbol_got_offset_ref (input_bfd
, h
, r_symndx
);
4189 symbol_got_offset (bfd
*input_bfd
, struct elf_link_hash_entry
*h
,
4190 unsigned long r_symndx
)
4193 value
= * symbol_got_offset_ref (input_bfd
, h
, r_symndx
);
4199 symbol_tlsdesc_got_offset_ref (bfd
*input_bfd
, struct elf_link_hash_entry
*h
,
4200 unsigned long r_symndx
)
4202 /* Calculate the address of the GOT entry for symbol
4203 referred to in h. */
4206 struct elf_aarch64_link_hash_entry
*eh
;
4207 eh
= (struct elf_aarch64_link_hash_entry
*) h
;
4208 return &eh
->tlsdesc_got_jump_table_offset
;
4213 struct elf_aarch64_local_symbol
*l
;
4215 l
= elf_aarch64_locals (input_bfd
);
4216 return &l
[r_symndx
].tlsdesc_got_jump_table_offset
;
4221 symbol_tlsdesc_got_offset_mark (bfd
*input_bfd
, struct elf_link_hash_entry
*h
,
4222 unsigned long r_symndx
)
4225 p
= symbol_tlsdesc_got_offset_ref (input_bfd
, h
, r_symndx
);
4230 symbol_tlsdesc_got_offset_mark_p (bfd
*input_bfd
,
4231 struct elf_link_hash_entry
*h
,
4232 unsigned long r_symndx
)
4235 value
= * symbol_tlsdesc_got_offset_ref (input_bfd
, h
, r_symndx
);
4240 symbol_tlsdesc_got_offset (bfd
*input_bfd
, struct elf_link_hash_entry
*h
,
4241 unsigned long r_symndx
)
4244 value
= * symbol_tlsdesc_got_offset_ref (input_bfd
, h
, r_symndx
);
4249 /* Data for make_branch_to_erratum_835769_stub(). */
4251 struct erratum_835769_branch_to_stub_data
4253 struct bfd_link_info
*info
;
4254 asection
*output_section
;
4258 /* Helper to insert branches to erratum 835769 stubs in the right
4259 places for a particular section. */
4262 make_branch_to_erratum_835769_stub (struct bfd_hash_entry
*gen_entry
,
4265 struct elf_aarch64_stub_hash_entry
*stub_entry
;
4266 struct erratum_835769_branch_to_stub_data
*data
;
4268 unsigned long branch_insn
= 0;
4269 bfd_vma veneered_insn_loc
, veneer_entry_loc
;
4270 bfd_signed_vma branch_offset
;
4271 unsigned int target
;
4274 stub_entry
= (struct elf_aarch64_stub_hash_entry
*) gen_entry
;
4275 data
= (struct erratum_835769_branch_to_stub_data
*) in_arg
;
4277 if (stub_entry
->target_section
!= data
->output_section
4278 || stub_entry
->stub_type
!= aarch64_stub_erratum_835769_veneer
)
4281 contents
= data
->contents
;
4282 veneered_insn_loc
= stub_entry
->target_section
->output_section
->vma
4283 + stub_entry
->target_section
->output_offset
4284 + stub_entry
->target_value
;
4285 veneer_entry_loc
= stub_entry
->stub_sec
->output_section
->vma
4286 + stub_entry
->stub_sec
->output_offset
4287 + stub_entry
->stub_offset
;
4288 branch_offset
= veneer_entry_loc
- veneered_insn_loc
;
4290 abfd
= stub_entry
->target_section
->owner
;
4291 if (!aarch64_valid_branch_p (veneer_entry_loc
, veneered_insn_loc
))
4292 (*_bfd_error_handler
)
4293 (_("%B: error: Erratum 835769 stub out "
4294 "of range (input file too large)"), abfd
);
4296 target
= stub_entry
->target_value
;
4297 branch_insn
= 0x14000000;
4298 branch_offset
>>= 2;
4299 branch_offset
&= 0x3ffffff;
4300 branch_insn
|= branch_offset
;
4301 bfd_putl32 (branch_insn
, &contents
[target
]);
4308 _bfd_aarch64_erratum_843419_branch_to_stub (struct bfd_hash_entry
*gen_entry
,
4311 struct elf_aarch64_stub_hash_entry
*stub_entry
4312 = (struct elf_aarch64_stub_hash_entry
*) gen_entry
;
4313 struct erratum_835769_branch_to_stub_data
*data
4314 = (struct erratum_835769_branch_to_stub_data
*) in_arg
;
4315 struct bfd_link_info
*info
;
4316 struct elf_aarch64_link_hash_table
*htab
;
4324 contents
= data
->contents
;
4325 section
= data
->output_section
;
4327 htab
= elf_aarch64_hash_table (info
);
4329 if (stub_entry
->target_section
!= section
4330 || stub_entry
->stub_type
!= aarch64_stub_erratum_843419_veneer
)
4333 insn
= bfd_getl32 (contents
+ stub_entry
->target_value
);
4335 stub_entry
->stub_sec
->contents
+ stub_entry
->stub_offset
);
4337 place
= (section
->output_section
->vma
+ section
->output_offset
4338 + stub_entry
->adrp_offset
);
4339 insn
= bfd_getl32 (contents
+ stub_entry
->adrp_offset
);
4341 if ((insn
& AARCH64_ADRP_OP_MASK
) != AARCH64_ADRP_OP
)
4344 bfd_signed_vma imm
=
4345 (_bfd_aarch64_sign_extend
4346 ((bfd_vma
) _bfd_aarch64_decode_adrp_imm (insn
) << 12, 33)
4349 if (htab
->fix_erratum_843419_adr
4350 && (imm
>= AARCH64_MIN_ADRP_IMM
&& imm
<= AARCH64_MAX_ADRP_IMM
))
4352 insn
= (_bfd_aarch64_reencode_adr_imm (AARCH64_ADR_OP
, imm
)
4353 | AARCH64_RT (insn
));
4354 bfd_putl32 (insn
, contents
+ stub_entry
->adrp_offset
);
4358 bfd_vma veneered_insn_loc
;
4359 bfd_vma veneer_entry_loc
;
4360 bfd_signed_vma branch_offset
;
4361 uint32_t branch_insn
;
4363 veneered_insn_loc
= stub_entry
->target_section
->output_section
->vma
4364 + stub_entry
->target_section
->output_offset
4365 + stub_entry
->target_value
;
4366 veneer_entry_loc
= stub_entry
->stub_sec
->output_section
->vma
4367 + stub_entry
->stub_sec
->output_offset
4368 + stub_entry
->stub_offset
;
4369 branch_offset
= veneer_entry_loc
- veneered_insn_loc
;
4371 abfd
= stub_entry
->target_section
->owner
;
4372 if (!aarch64_valid_branch_p (veneer_entry_loc
, veneered_insn_loc
))
4373 (*_bfd_error_handler
)
4374 (_("%B: error: Erratum 843419 stub out "
4375 "of range (input file too large)"), abfd
);
4377 branch_insn
= 0x14000000;
4378 branch_offset
>>= 2;
4379 branch_offset
&= 0x3ffffff;
4380 branch_insn
|= branch_offset
;
4381 bfd_putl32 (branch_insn
, contents
+ stub_entry
->target_value
);
4388 elfNN_aarch64_write_section (bfd
*output_bfd ATTRIBUTE_UNUSED
,
4389 struct bfd_link_info
*link_info
,
4394 struct elf_aarch64_link_hash_table
*globals
=
4395 elf_aarch64_hash_table (link_info
);
4397 if (globals
== NULL
)
4400 /* Fix code to point to erratum 835769 stubs. */
4401 if (globals
->fix_erratum_835769
)
4403 struct erratum_835769_branch_to_stub_data data
;
4405 data
.info
= link_info
;
4406 data
.output_section
= sec
;
4407 data
.contents
= contents
;
4408 bfd_hash_traverse (&globals
->stub_hash_table
,
4409 make_branch_to_erratum_835769_stub
, &data
);
4412 if (globals
->fix_erratum_843419
)
4414 struct erratum_835769_branch_to_stub_data data
;
4416 data
.info
= link_info
;
4417 data
.output_section
= sec
;
4418 data
.contents
= contents
;
4419 bfd_hash_traverse (&globals
->stub_hash_table
,
4420 _bfd_aarch64_erratum_843419_branch_to_stub
, &data
);
4426 /* Perform a relocation as part of a final link. */
4427 static bfd_reloc_status_type
4428 elfNN_aarch64_final_link_relocate (reloc_howto_type
*howto
,
4431 asection
*input_section
,
4433 Elf_Internal_Rela
*rel
,
4435 struct bfd_link_info
*info
,
4437 struct elf_link_hash_entry
*h
,
4438 bfd_boolean
*unresolved_reloc_p
,
4439 bfd_boolean save_addend
,
4440 bfd_vma
*saved_addend
,
4441 Elf_Internal_Sym
*sym
)
4443 Elf_Internal_Shdr
*symtab_hdr
;
4444 unsigned int r_type
= howto
->type
;
4445 bfd_reloc_code_real_type bfd_r_type
4446 = elfNN_aarch64_bfd_reloc_from_howto (howto
);
4447 bfd_reloc_code_real_type new_bfd_r_type
;
4448 unsigned long r_symndx
;
4449 bfd_byte
*hit_data
= contents
+ rel
->r_offset
;
4451 bfd_signed_vma signed_addend
;
4452 struct elf_aarch64_link_hash_table
*globals
;
4453 bfd_boolean weak_undef_p
;
4455 globals
= elf_aarch64_hash_table (info
);
4457 symtab_hdr
= &elf_symtab_hdr (input_bfd
);
4459 BFD_ASSERT (is_aarch64_elf (input_bfd
));
4461 r_symndx
= ELFNN_R_SYM (rel
->r_info
);
4463 /* It is possible to have linker relaxations on some TLS access
4464 models. Update our information here. */
4465 new_bfd_r_type
= aarch64_tls_transition (input_bfd
, info
, r_type
, h
, r_symndx
);
4466 if (new_bfd_r_type
!= bfd_r_type
)
4468 bfd_r_type
= new_bfd_r_type
;
4469 howto
= elfNN_aarch64_howto_from_bfd_reloc (bfd_r_type
);
4470 BFD_ASSERT (howto
!= NULL
);
4471 r_type
= howto
->type
;
4474 place
= input_section
->output_section
->vma
4475 + input_section
->output_offset
+ rel
->r_offset
;
4477 /* Get addend, accumulating the addend for consecutive relocs
4478 which refer to the same offset. */
4479 signed_addend
= saved_addend
? *saved_addend
: 0;
4480 signed_addend
+= rel
->r_addend
;
4482 weak_undef_p
= (h
? h
->root
.type
== bfd_link_hash_undefweak
4483 : bfd_is_und_section (sym_sec
));
4485 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle
4486 it here if it is defined in a non-shared object. */
4488 && h
->type
== STT_GNU_IFUNC
4496 if ((input_section
->flags
& SEC_ALLOC
) == 0
4497 || h
->plt
.offset
== (bfd_vma
) -1)
4500 /* STT_GNU_IFUNC symbol must go through PLT. */
4501 plt
= globals
->root
.splt
? globals
->root
.splt
: globals
->root
.iplt
;
4502 value
= (plt
->output_section
->vma
+ plt
->output_offset
+ h
->plt
.offset
);
4507 if (h
->root
.root
.string
)
4508 name
= h
->root
.root
.string
;
4510 name
= bfd_elf_sym_name (input_bfd
, symtab_hdr
, sym
,
4512 (*_bfd_error_handler
)
4513 (_("%B: relocation %s against STT_GNU_IFUNC "
4514 "symbol `%s' isn't handled by %s"), input_bfd
,
4515 howto
->name
, name
, __FUNCTION__
);
4516 bfd_set_error (bfd_error_bad_value
);
4519 case BFD_RELOC_AARCH64_NN
:
4520 if (rel
->r_addend
!= 0)
4522 if (h
->root
.root
.string
)
4523 name
= h
->root
.root
.string
;
4525 name
= bfd_elf_sym_name (input_bfd
, symtab_hdr
,
4527 (*_bfd_error_handler
)
4528 (_("%B: relocation %s against STT_GNU_IFUNC "
4529 "symbol `%s' has non-zero addend: %d"),
4530 input_bfd
, howto
->name
, name
, rel
->r_addend
);
4531 bfd_set_error (bfd_error_bad_value
);
4535 /* Generate dynamic relocation only when there is a
4536 non-GOT reference in a shared object. */
4537 if (info
->shared
&& h
->non_got_ref
)
4539 Elf_Internal_Rela outrel
;
4542 /* Need a dynamic relocation to get the real function
4544 outrel
.r_offset
= _bfd_elf_section_offset (output_bfd
,
4548 if (outrel
.r_offset
== (bfd_vma
) -1
4549 || outrel
.r_offset
== (bfd_vma
) -2)
4552 outrel
.r_offset
+= (input_section
->output_section
->vma
4553 + input_section
->output_offset
);
4555 if (h
->dynindx
== -1
4557 || info
->executable
)
4559 /* This symbol is resolved locally. */
4560 outrel
.r_info
= ELFNN_R_INFO (0, AARCH64_R (IRELATIVE
));
4561 outrel
.r_addend
= (h
->root
.u
.def
.value
4562 + h
->root
.u
.def
.section
->output_section
->vma
4563 + h
->root
.u
.def
.section
->output_offset
);
4567 outrel
.r_info
= ELFNN_R_INFO (h
->dynindx
, r_type
);
4568 outrel
.r_addend
= 0;
4571 sreloc
= globals
->root
.irelifunc
;
4572 elf_append_rela (output_bfd
, sreloc
, &outrel
);
4574 /* If this reloc is against an external symbol, we
4575 do not want to fiddle with the addend. Otherwise,
4576 we need to include the symbol value so that it
4577 becomes an addend for the dynamic reloc. For an
4578 internal symbol, we have updated addend. */
4579 return bfd_reloc_ok
;
4582 case BFD_RELOC_AARCH64_JUMP26
:
4583 case BFD_RELOC_AARCH64_CALL26
:
4584 value
= _bfd_aarch64_elf_resolve_relocation (bfd_r_type
, place
, value
,
4587 return _bfd_aarch64_elf_put_addend (input_bfd
, hit_data
, bfd_r_type
,
4589 case BFD_RELOC_AARCH64_LD64_GOT_LO12_NC
:
4590 case BFD_RELOC_AARCH64_LD32_GOT_LO12_NC
:
4591 case BFD_RELOC_AARCH64_ADR_GOT_PAGE
:
4592 case BFD_RELOC_AARCH64_GOT_LD_PREL19
:
4593 base_got
= globals
->root
.sgot
;
4594 off
= h
->got
.offset
;
4596 if (base_got
== NULL
)
4599 if (off
== (bfd_vma
) -1)
4603 /* We can't use h->got.offset here to save state, or
4604 even just remember the offset, as finish_dynamic_symbol
4605 would use that as offset into .got. */
4607 if (globals
->root
.splt
!= NULL
)
4609 plt_index
= ((h
->plt
.offset
- globals
->plt_header_size
) /
4610 globals
->plt_entry_size
);
4611 off
= (plt_index
+ 3) * GOT_ENTRY_SIZE
;
4612 base_got
= globals
->root
.sgotplt
;
4616 plt_index
= h
->plt
.offset
/ globals
->plt_entry_size
;
4617 off
= plt_index
* GOT_ENTRY_SIZE
;
4618 base_got
= globals
->root
.igotplt
;
4621 if (h
->dynindx
== -1
4625 /* This references the local definition. We must
4626 initialize this entry in the global offset table.
4627 Since the offset must always be a multiple of 8,
4628 we use the least significant bit to record
4629 whether we have initialized it already.
4631 When doing a dynamic link, we create a .rela.got
4632 relocation entry to initialize the value. This
4633 is done in the finish_dynamic_symbol routine. */
4638 bfd_put_NN (output_bfd
, value
,
4639 base_got
->contents
+ off
);
4640 /* Note that this is harmless as -1 | 1 still is -1. */
4644 value
= (base_got
->output_section
->vma
4645 + base_got
->output_offset
+ off
);
4648 value
= aarch64_calculate_got_entry_vma (h
, globals
, info
,
4650 unresolved_reloc_p
);
4651 value
= _bfd_aarch64_elf_resolve_relocation (bfd_r_type
, place
, value
,
4653 return _bfd_aarch64_elf_put_addend (input_bfd
, hit_data
, bfd_r_type
, howto
, value
);
4654 case BFD_RELOC_AARCH64_ADR_HI21_PCREL
:
4655 case BFD_RELOC_AARCH64_ADD_LO12
:
4662 case BFD_RELOC_AARCH64_NONE
:
4663 case BFD_RELOC_AARCH64_TLSDESC_CALL
:
4664 *unresolved_reloc_p
= FALSE
;
4665 return bfd_reloc_ok
;
4667 case BFD_RELOC_AARCH64_NN
:
4669 /* When generating a shared object or relocatable executable, these
4670 relocations are copied into the output file to be resolved at
4672 if (((info
->shared
== TRUE
) || globals
->root
.is_relocatable_executable
)
4673 && (input_section
->flags
& SEC_ALLOC
)
4675 || ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
4676 || h
->root
.type
!= bfd_link_hash_undefweak
))
4678 Elf_Internal_Rela outrel
;
4680 bfd_boolean skip
, relocate
;
4683 *unresolved_reloc_p
= FALSE
;
4688 outrel
.r_addend
= signed_addend
;
4690 _bfd_elf_section_offset (output_bfd
, info
, input_section
,
4692 if (outrel
.r_offset
== (bfd_vma
) - 1)
4694 else if (outrel
.r_offset
== (bfd_vma
) - 2)
4700 outrel
.r_offset
+= (input_section
->output_section
->vma
4701 + input_section
->output_offset
);
4704 memset (&outrel
, 0, sizeof outrel
);
4707 && (!info
->shared
|| !SYMBOLIC_BIND (info
, h
) || !h
->def_regular
))
4708 outrel
.r_info
= ELFNN_R_INFO (h
->dynindx
, r_type
);
4713 /* On SVR4-ish systems, the dynamic loader cannot
4714 relocate the text and data segments independently,
4715 so the symbol does not matter. */
4717 outrel
.r_info
= ELFNN_R_INFO (symbol
, AARCH64_R (RELATIVE
));
4718 outrel
.r_addend
+= value
;
4721 sreloc
= elf_section_data (input_section
)->sreloc
;
4722 if (sreloc
== NULL
|| sreloc
->contents
== NULL
)
4723 return bfd_reloc_notsupported
;
4725 loc
= sreloc
->contents
+ sreloc
->reloc_count
++ * RELOC_SIZE (globals
);
4726 bfd_elfNN_swap_reloca_out (output_bfd
, &outrel
, loc
);
4728 if (sreloc
->reloc_count
* RELOC_SIZE (globals
) > sreloc
->size
)
4730 /* Sanity to check that we have previously allocated
4731 sufficient space in the relocation section for the
4732 number of relocations we actually want to emit. */
4736 /* If this reloc is against an external symbol, we do not want to
4737 fiddle with the addend. Otherwise, we need to include the symbol
4738 value so that it becomes an addend for the dynamic reloc. */
4740 return bfd_reloc_ok
;
4742 return _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
4743 contents
, rel
->r_offset
, value
,
4747 value
+= signed_addend
;
4750 case BFD_RELOC_AARCH64_JUMP26
:
4751 case BFD_RELOC_AARCH64_CALL26
:
4753 asection
*splt
= globals
->root
.splt
;
4754 bfd_boolean via_plt_p
=
4755 splt
!= NULL
&& h
!= NULL
&& h
->plt
.offset
!= (bfd_vma
) - 1;
4757 /* A call to an undefined weak symbol is converted to a jump to
4758 the next instruction unless a PLT entry will be created.
4759 The jump to the next instruction is optimized as a NOP.
4760 Do the same for local undefined symbols. */
4761 if (weak_undef_p
&& ! via_plt_p
)
4763 bfd_putl32 (INSN_NOP
, hit_data
);
4764 return bfd_reloc_ok
;
4767 /* If the call goes through a PLT entry, make sure to
4768 check distance to the right destination address. */
4771 value
= (splt
->output_section
->vma
4772 + splt
->output_offset
+ h
->plt
.offset
);
4773 *unresolved_reloc_p
= FALSE
;
4776 /* If the target symbol is global and marked as a function the
4777 relocation applies a function call or a tail call. In this
4778 situation we can veneer out of range branches. The veneers
4779 use IP0 and IP1 hence cannot be used arbitrary out of range
4780 branches that occur within the body of a function. */
4781 if (h
&& h
->type
== STT_FUNC
)
4783 /* Check if a stub has to be inserted because the destination
4785 if (! aarch64_valid_branch_p (value
, place
))
4787 /* The target is out of reach, so redirect the branch to
4788 the local stub for this function. */
4789 struct elf_aarch64_stub_hash_entry
*stub_entry
;
4790 stub_entry
= elfNN_aarch64_get_stub_entry (input_section
,
4793 if (stub_entry
!= NULL
)
4794 value
= (stub_entry
->stub_offset
4795 + stub_entry
->stub_sec
->output_offset
4796 + stub_entry
->stub_sec
->output_section
->vma
);
4800 value
= _bfd_aarch64_elf_resolve_relocation (bfd_r_type
, place
, value
,
4801 signed_addend
, weak_undef_p
);
4804 case BFD_RELOC_AARCH64_16
:
4806 case BFD_RELOC_AARCH64_32
:
4808 case BFD_RELOC_AARCH64_ADD_LO12
:
4809 case BFD_RELOC_AARCH64_ADR_LO21_PCREL
:
4810 case BFD_RELOC_AARCH64_ADR_HI21_PCREL
:
4811 case BFD_RELOC_AARCH64_ADR_HI21_NC_PCREL
:
4812 case BFD_RELOC_AARCH64_BRANCH19
:
4813 case BFD_RELOC_AARCH64_LD_LO19_PCREL
:
4814 case BFD_RELOC_AARCH64_LDST8_LO12
:
4815 case BFD_RELOC_AARCH64_LDST16_LO12
:
4816 case BFD_RELOC_AARCH64_LDST32_LO12
:
4817 case BFD_RELOC_AARCH64_LDST64_LO12
:
4818 case BFD_RELOC_AARCH64_LDST128_LO12
:
4819 case BFD_RELOC_AARCH64_MOVW_G0_S
:
4820 case BFD_RELOC_AARCH64_MOVW_G1_S
:
4821 case BFD_RELOC_AARCH64_MOVW_G2_S
:
4822 case BFD_RELOC_AARCH64_MOVW_G0
:
4823 case BFD_RELOC_AARCH64_MOVW_G0_NC
:
4824 case BFD_RELOC_AARCH64_MOVW_G1
:
4825 case BFD_RELOC_AARCH64_MOVW_G1_NC
:
4826 case BFD_RELOC_AARCH64_MOVW_G2
:
4827 case BFD_RELOC_AARCH64_MOVW_G2_NC
:
4828 case BFD_RELOC_AARCH64_MOVW_G3
:
4829 case BFD_RELOC_AARCH64_16_PCREL
:
4830 case BFD_RELOC_AARCH64_32_PCREL
:
4831 case BFD_RELOC_AARCH64_64_PCREL
:
4832 case BFD_RELOC_AARCH64_TSTBR14
:
4833 value
= _bfd_aarch64_elf_resolve_relocation (bfd_r_type
, place
, value
,
4834 signed_addend
, weak_undef_p
);
4837 case BFD_RELOC_AARCH64_LD64_GOT_LO12_NC
:
4838 case BFD_RELOC_AARCH64_LD32_GOT_LO12_NC
:
4839 case BFD_RELOC_AARCH64_ADR_GOT_PAGE
:
4840 case BFD_RELOC_AARCH64_GOT_LD_PREL19
:
4841 if (globals
->root
.sgot
== NULL
)
4842 BFD_ASSERT (h
!= NULL
);
4846 value
= aarch64_calculate_got_entry_vma (h
, globals
, info
, value
,
4848 unresolved_reloc_p
);
4849 value
= _bfd_aarch64_elf_resolve_relocation (bfd_r_type
, place
, value
,
4854 case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21
:
4855 case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21
:
4856 case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC
:
4857 case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21
:
4858 case BFD_RELOC_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC
:
4859 case BFD_RELOC_AARCH64_TLSIE_LD32_GOTTPREL_LO12_NC
:
4860 case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19
:
4861 if (globals
->root
.sgot
== NULL
)
4862 return bfd_reloc_notsupported
;
4864 value
= (symbol_got_offset (input_bfd
, h
, r_symndx
)
4865 + globals
->root
.sgot
->output_section
->vma
4866 + globals
->root
.sgot
->output_offset
);
4868 value
= _bfd_aarch64_elf_resolve_relocation (bfd_r_type
, place
, value
,
4870 *unresolved_reloc_p
= FALSE
;
4873 case BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_HI12
:
4874 case BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_LO12
:
4875 case BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_LO12_NC
:
4876 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0
:
4877 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC
:
4878 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1
:
4879 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1_NC
:
4880 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G2
:
4881 value
= _bfd_aarch64_elf_resolve_relocation (bfd_r_type
, place
, value
,
4882 signed_addend
- tpoff_base (info
),
4884 *unresolved_reloc_p
= FALSE
;
4887 case BFD_RELOC_AARCH64_TLSDESC_ADD
:
4888 case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12_NC
:
4889 case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21
:
4890 case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21
:
4891 case BFD_RELOC_AARCH64_TLSDESC_LD32_LO12_NC
:
4892 case BFD_RELOC_AARCH64_TLSDESC_LD64_LO12_NC
:
4893 case BFD_RELOC_AARCH64_TLSDESC_LDR
:
4894 case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19
:
4895 if (globals
->root
.sgot
== NULL
)
4896 return bfd_reloc_notsupported
;
4897 value
= (symbol_tlsdesc_got_offset (input_bfd
, h
, r_symndx
)
4898 + globals
->root
.sgotplt
->output_section
->vma
4899 + globals
->root
.sgotplt
->output_offset
4900 + globals
->sgotplt_jump_table_size
);
4902 value
= _bfd_aarch64_elf_resolve_relocation (bfd_r_type
, place
, value
,
4904 *unresolved_reloc_p
= FALSE
;
4908 return bfd_reloc_notsupported
;
4912 *saved_addend
= value
;
4914 /* Only apply the final relocation in a sequence. */
4916 return bfd_reloc_continue
;
4918 return _bfd_aarch64_elf_put_addend (input_bfd
, hit_data
, bfd_r_type
,
4922 /* Handle TLS relaxations. Relaxing is possible for symbols that use
4923 R_AARCH64_TLSDESC_ADR_{PAGE, LD64_LO12_NC, ADD_LO12_NC} during a static
4926 Return bfd_reloc_ok if we're done, bfd_reloc_continue if the caller
4927 is to then call final_link_relocate. Return other values in the
4930 static bfd_reloc_status_type
4931 elfNN_aarch64_tls_relax (struct elf_aarch64_link_hash_table
*globals
,
4932 bfd
*input_bfd
, bfd_byte
*contents
,
4933 Elf_Internal_Rela
*rel
, struct elf_link_hash_entry
*h
)
4935 bfd_boolean is_local
= h
== NULL
;
4936 unsigned int r_type
= ELFNN_R_TYPE (rel
->r_info
);
4939 BFD_ASSERT (globals
&& input_bfd
&& contents
&& rel
);
4941 switch (elfNN_aarch64_bfd_reloc_from_type (r_type
))
4943 case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21
:
4944 case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21
:
4947 /* GD->LE relaxation:
4948 adrp x0, :tlsgd:var => movz x0, :tprel_g1:var
4950 adrp x0, :tlsdesc:var => movz x0, :tprel_g1:var
4952 bfd_putl32 (0xd2a00000, contents
+ rel
->r_offset
);
4953 return bfd_reloc_continue
;
4957 /* GD->IE relaxation:
4958 adrp x0, :tlsgd:var => adrp x0, :gottprel:var
4960 adrp x0, :tlsdesc:var => adrp x0, :gottprel:var
4962 return bfd_reloc_continue
;
4965 case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21
:
4969 case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19
:
4972 /* Tiny TLSDESC->LE relaxation:
4973 ldr x1, :tlsdesc:var => movz x0, #:tprel_g1:var
4974 adr x0, :tlsdesc:var => movk x0, #:tprel_g0_nc:var
4978 BFD_ASSERT (ELFNN_R_TYPE (rel
[1].r_info
) == AARCH64_R (TLSDESC_ADR_PREL21
));
4979 BFD_ASSERT (ELFNN_R_TYPE (rel
[2].r_info
) == AARCH64_R (TLSDESC_CALL
));
4981 rel
[1].r_info
= ELFNN_R_INFO (ELFNN_R_SYM (rel
->r_info
),
4982 AARCH64_R (TLSLE_MOVW_TPREL_G0_NC
));
4983 rel
[2].r_info
= ELFNN_R_INFO (STN_UNDEF
, R_AARCH64_NONE
);
4985 bfd_putl32 (0xd2a00000, contents
+ rel
->r_offset
);
4986 bfd_putl32 (0xf2800000, contents
+ rel
->r_offset
+ 4);
4987 bfd_putl32 (INSN_NOP
, contents
+ rel
->r_offset
+ 8);
4988 return bfd_reloc_continue
;
4992 /* Tiny TLSDESC->IE relaxation:
4993 ldr x1, :tlsdesc:var => ldr x0, :gottprel:var
4994 adr x0, :tlsdesc:var => nop
4998 BFD_ASSERT (ELFNN_R_TYPE (rel
[1].r_info
) == AARCH64_R (TLSDESC_ADR_PREL21
));
4999 BFD_ASSERT (ELFNN_R_TYPE (rel
[2].r_info
) == AARCH64_R (TLSDESC_CALL
));
5001 rel
[1].r_info
= ELFNN_R_INFO (STN_UNDEF
, R_AARCH64_NONE
);
5002 rel
[2].r_info
= ELFNN_R_INFO (STN_UNDEF
, R_AARCH64_NONE
);
5004 bfd_putl32 (0x58000000, contents
+ rel
->r_offset
);
5005 bfd_putl32 (INSN_NOP
, contents
+ rel
->r_offset
+ 4);
5006 bfd_putl32 (INSN_NOP
, contents
+ rel
->r_offset
+ 8);
5007 return bfd_reloc_continue
;
5010 case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21
:
5013 /* Tiny GD->LE relaxation:
5014 adr x0, :tlsgd:var => mrs x1, tpidr_el0
5015 bl __tls_get_addr => add x0, x1, #:tprel_hi12:x, lsl #12
5016 nop => add x0, x0, #:tprel_lo12_nc:x
5019 /* First kill the tls_get_addr reloc on the bl instruction. */
5020 BFD_ASSERT (rel
->r_offset
+ 4 == rel
[1].r_offset
);
5022 bfd_putl32 (0xd53bd041, contents
+ rel
->r_offset
+ 0);
5023 bfd_putl32 (0x91400020, contents
+ rel
->r_offset
+ 4);
5024 bfd_putl32 (0x91000000, contents
+ rel
->r_offset
+ 8);
5026 rel
[1].r_info
= ELFNN_R_INFO (ELFNN_R_SYM (rel
->r_info
),
5027 AARCH64_R (TLSLE_ADD_TPREL_LO12_NC
));
5028 rel
[1].r_offset
= rel
->r_offset
+ 8;
5030 /* Move the current relocation to the second instruction in
5033 rel
->r_info
= ELFNN_R_INFO (ELFNN_R_SYM (rel
->r_info
),
5034 AARCH64_R (TLSLE_ADD_TPREL_HI12
));
5035 return bfd_reloc_continue
;
5039 /* Tiny GD->IE relaxation:
5040 adr x0, :tlsgd:var => ldr x0, :gottprel:var
5041 bl __tls_get_addr => mrs x1, tpidr_el0
5042 nop => add x0, x0, x1
5045 /* First kill the tls_get_addr reloc on the bl instruction. */
5046 BFD_ASSERT (rel
->r_offset
+ 4 == rel
[1].r_offset
);
5047 rel
[1].r_info
= ELFNN_R_INFO (STN_UNDEF
, R_AARCH64_NONE
);
5049 bfd_putl32 (0x58000000, contents
+ rel
->r_offset
);
5050 bfd_putl32 (0xd53bd041, contents
+ rel
->r_offset
+ 4);
5051 bfd_putl32 (0x8b000020, contents
+ rel
->r_offset
+ 8);
5052 return bfd_reloc_continue
;
5055 case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19
:
5056 return bfd_reloc_continue
;
5058 case BFD_RELOC_AARCH64_TLSDESC_LDNN_LO12_NC
:
5061 /* GD->LE relaxation:
5062 ldr xd, [x0, #:tlsdesc_lo12:var] => movk x0, :tprel_g0_nc:var
5064 bfd_putl32 (0xf2800000, contents
+ rel
->r_offset
);
5065 return bfd_reloc_continue
;
5069 /* GD->IE relaxation:
5070 ldr xd, [x0, #:tlsdesc_lo12:var] => ldr x0, [x0, #:gottprel_lo12:var]
5072 insn
= bfd_getl32 (contents
+ rel
->r_offset
);
5074 bfd_putl32 (insn
, contents
+ rel
->r_offset
);
5075 return bfd_reloc_continue
;
5078 case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC
:
5081 /* GD->LE relaxation
5082 add x0, #:tlsgd_lo12:var => movk x0, :tprel_g0_nc:var
5083 bl __tls_get_addr => mrs x1, tpidr_el0
5084 nop => add x0, x1, x0
5087 /* First kill the tls_get_addr reloc on the bl instruction. */
5088 BFD_ASSERT (rel
->r_offset
+ 4 == rel
[1].r_offset
);
5089 rel
[1].r_info
= ELFNN_R_INFO (STN_UNDEF
, R_AARCH64_NONE
);
5091 bfd_putl32 (0xf2800000, contents
+ rel
->r_offset
);
5092 bfd_putl32 (0xd53bd041, contents
+ rel
->r_offset
+ 4);
5093 bfd_putl32 (0x8b000020, contents
+ rel
->r_offset
+ 8);
5094 return bfd_reloc_continue
;
5098 /* GD->IE relaxation
5099 ADD x0, #:tlsgd_lo12:var => ldr x0, [x0, #:gottprel_lo12:var]
5100 BL __tls_get_addr => mrs x1, tpidr_el0
5102 NOP => add x0, x1, x0
5105 BFD_ASSERT (ELFNN_R_TYPE (rel
[1].r_info
) == AARCH64_R (CALL26
));
5107 /* Remove the relocation on the BL instruction. */
5108 rel
[1].r_info
= ELFNN_R_INFO (STN_UNDEF
, R_AARCH64_NONE
);
5110 bfd_putl32 (0xf9400000, contents
+ rel
->r_offset
);
5112 /* We choose to fixup the BL and NOP instructions using the
5113 offset from the second relocation to allow flexibility in
5114 scheduling instructions between the ADD and BL. */
5115 bfd_putl32 (0xd53bd041, contents
+ rel
[1].r_offset
);
5116 bfd_putl32 (0x8b000020, contents
+ rel
[1].r_offset
+ 4);
5117 return bfd_reloc_continue
;
5120 case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12_NC
:
5121 case BFD_RELOC_AARCH64_TLSDESC_CALL
:
5122 /* GD->IE/LE relaxation:
5123 add x0, x0, #:tlsdesc_lo12:var => nop
5126 bfd_putl32 (INSN_NOP
, contents
+ rel
->r_offset
);
5127 return bfd_reloc_ok
;
5129 case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21
:
5130 /* IE->LE relaxation:
5131 adrp xd, :gottprel:var => movz xd, :tprel_g1:var
5135 insn
= bfd_getl32 (contents
+ rel
->r_offset
);
5136 bfd_putl32 (0xd2a00000 | (insn
& 0x1f), contents
+ rel
->r_offset
);
5138 return bfd_reloc_continue
;
5140 case BFD_RELOC_AARCH64_TLSIE_LDNN_GOTTPREL_LO12_NC
:
5141 /* IE->LE relaxation:
5142 ldr xd, [xm, #:gottprel_lo12:var] => movk xd, :tprel_g0_nc:var
5146 insn
= bfd_getl32 (contents
+ rel
->r_offset
);
5147 bfd_putl32 (0xf2800000 | (insn
& 0x1f), contents
+ rel
->r_offset
);
5149 return bfd_reloc_continue
;
5152 return bfd_reloc_continue
;
5155 return bfd_reloc_ok
;
5158 /* Relocate an AArch64 ELF section. */
5161 elfNN_aarch64_relocate_section (bfd
*output_bfd
,
5162 struct bfd_link_info
*info
,
5164 asection
*input_section
,
5166 Elf_Internal_Rela
*relocs
,
5167 Elf_Internal_Sym
*local_syms
,
5168 asection
**local_sections
)
5170 Elf_Internal_Shdr
*symtab_hdr
;
5171 struct elf_link_hash_entry
**sym_hashes
;
5172 Elf_Internal_Rela
*rel
;
5173 Elf_Internal_Rela
*relend
;
5175 struct elf_aarch64_link_hash_table
*globals
;
5176 bfd_boolean save_addend
= FALSE
;
5179 globals
= elf_aarch64_hash_table (info
);
5181 symtab_hdr
= &elf_symtab_hdr (input_bfd
);
5182 sym_hashes
= elf_sym_hashes (input_bfd
);
5185 relend
= relocs
+ input_section
->reloc_count
;
5186 for (; rel
< relend
; rel
++)
5188 unsigned int r_type
;
5189 bfd_reloc_code_real_type bfd_r_type
;
5190 bfd_reloc_code_real_type relaxed_bfd_r_type
;
5191 reloc_howto_type
*howto
;
5192 unsigned long r_symndx
;
5193 Elf_Internal_Sym
*sym
;
5195 struct elf_link_hash_entry
*h
;
5197 bfd_reloc_status_type r
;
5200 bfd_boolean unresolved_reloc
= FALSE
;
5201 char *error_message
= NULL
;
5203 r_symndx
= ELFNN_R_SYM (rel
->r_info
);
5204 r_type
= ELFNN_R_TYPE (rel
->r_info
);
5206 bfd_reloc
.howto
= elfNN_aarch64_howto_from_type (r_type
);
5207 howto
= bfd_reloc
.howto
;
5211 (*_bfd_error_handler
)
5212 (_("%B: unrecognized relocation (0x%x) in section `%A'"),
5213 input_bfd
, input_section
, r_type
);
5216 bfd_r_type
= elfNN_aarch64_bfd_reloc_from_howto (howto
);
5222 if (r_symndx
< symtab_hdr
->sh_info
)
5224 sym
= local_syms
+ r_symndx
;
5225 sym_type
= ELFNN_ST_TYPE (sym
->st_info
);
5226 sec
= local_sections
[r_symndx
];
5228 /* An object file might have a reference to a local
5229 undefined symbol. This is a daft object file, but we
5230 should at least do something about it. */
5231 if (r_type
!= R_AARCH64_NONE
&& r_type
!= R_AARCH64_NULL
5232 && bfd_is_und_section (sec
)
5233 && ELF_ST_BIND (sym
->st_info
) != STB_WEAK
)
5235 if (!info
->callbacks
->undefined_symbol
5236 (info
, bfd_elf_string_from_elf_section
5237 (input_bfd
, symtab_hdr
->sh_link
, sym
->st_name
),
5238 input_bfd
, input_section
, rel
->r_offset
, TRUE
))
5242 relocation
= _bfd_elf_rela_local_sym (output_bfd
, sym
, &sec
, rel
);
5244 /* Relocate against local STT_GNU_IFUNC symbol. */
5245 if (!info
->relocatable
5246 && ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
)
5248 h
= elfNN_aarch64_get_local_sym_hash (globals
, input_bfd
,
5253 /* Set STT_GNU_IFUNC symbol value. */
5254 h
->root
.u
.def
.value
= sym
->st_value
;
5255 h
->root
.u
.def
.section
= sec
;
5260 bfd_boolean warned
, ignored
;
5262 RELOC_FOR_GLOBAL_SYMBOL (info
, input_bfd
, input_section
, rel
,
5263 r_symndx
, symtab_hdr
, sym_hashes
,
5265 unresolved_reloc
, warned
, ignored
);
5270 if (sec
!= NULL
&& discarded_section (sec
))
5271 RELOC_AGAINST_DISCARDED_SECTION (info
, input_bfd
, input_section
,
5272 rel
, 1, relend
, howto
, 0, contents
);
5274 if (info
->relocatable
)
5278 name
= h
->root
.root
.string
;
5281 name
= (bfd_elf_string_from_elf_section
5282 (input_bfd
, symtab_hdr
->sh_link
, sym
->st_name
));
5283 if (name
== NULL
|| *name
== '\0')
5284 name
= bfd_section_name (input_bfd
, sec
);
5288 && r_type
!= R_AARCH64_NONE
5289 && r_type
!= R_AARCH64_NULL
5291 || h
->root
.type
== bfd_link_hash_defined
5292 || h
->root
.type
== bfd_link_hash_defweak
)
5293 && IS_AARCH64_TLS_RELOC (bfd_r_type
) != (sym_type
== STT_TLS
))
5295 (*_bfd_error_handler
)
5296 ((sym_type
== STT_TLS
5297 ? _("%B(%A+0x%lx): %s used with TLS symbol %s")
5298 : _("%B(%A+0x%lx): %s used with non-TLS symbol %s")),
5300 input_section
, (long) rel
->r_offset
, howto
->name
, name
);
5303 /* We relax only if we can see that there can be a valid transition
5304 from a reloc type to another.
5305 We call elfNN_aarch64_final_link_relocate unless we're completely
5306 done, i.e., the relaxation produced the final output we want. */
5308 relaxed_bfd_r_type
= aarch64_tls_transition (input_bfd
, info
, r_type
,
5310 if (relaxed_bfd_r_type
!= bfd_r_type
)
5312 bfd_r_type
= relaxed_bfd_r_type
;
5313 howto
= elfNN_aarch64_howto_from_bfd_reloc (bfd_r_type
);
5314 BFD_ASSERT (howto
!= NULL
);
5315 r_type
= howto
->type
;
5316 r
= elfNN_aarch64_tls_relax (globals
, input_bfd
, contents
, rel
, h
);
5317 unresolved_reloc
= 0;
5320 r
= bfd_reloc_continue
;
5322 /* There may be multiple consecutive relocations for the
5323 same offset. In that case we are supposed to treat the
5324 output of each relocation as the addend for the next. */
5325 if (rel
+ 1 < relend
5326 && rel
->r_offset
== rel
[1].r_offset
5327 && ELFNN_R_TYPE (rel
[1].r_info
) != R_AARCH64_NONE
5328 && ELFNN_R_TYPE (rel
[1].r_info
) != R_AARCH64_NULL
)
5331 save_addend
= FALSE
;
5333 if (r
== bfd_reloc_continue
)
5334 r
= elfNN_aarch64_final_link_relocate (howto
, input_bfd
, output_bfd
,
5335 input_section
, contents
, rel
,
5336 relocation
, info
, sec
,
5337 h
, &unresolved_reloc
,
5338 save_addend
, &addend
, sym
);
5340 switch (elfNN_aarch64_bfd_reloc_from_type (r_type
))
5342 case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21
:
5343 case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21
:
5344 case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC
:
5345 if (! symbol_got_offset_mark_p (input_bfd
, h
, r_symndx
))
5347 bfd_boolean need_relocs
= FALSE
;
5352 off
= symbol_got_offset (input_bfd
, h
, r_symndx
);
5353 indx
= h
&& h
->dynindx
!= -1 ? h
->dynindx
: 0;
5356 (info
->shared
|| indx
!= 0) &&
5358 || ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
5359 || h
->root
.type
!= bfd_link_hash_undefweak
);
5361 BFD_ASSERT (globals
->root
.srelgot
!= NULL
);
5365 Elf_Internal_Rela rela
;
5366 rela
.r_info
= ELFNN_R_INFO (indx
, AARCH64_R (TLS_DTPMOD
));
5368 rela
.r_offset
= globals
->root
.sgot
->output_section
->vma
+
5369 globals
->root
.sgot
->output_offset
+ off
;
5372 loc
= globals
->root
.srelgot
->contents
;
5373 loc
+= globals
->root
.srelgot
->reloc_count
++
5374 * RELOC_SIZE (htab
);
5375 bfd_elfNN_swap_reloca_out (output_bfd
, &rela
, loc
);
5379 bfd_put_NN (output_bfd
,
5380 relocation
- dtpoff_base (info
),
5381 globals
->root
.sgot
->contents
+ off
5386 /* This TLS symbol is global. We emit a
5387 relocation to fixup the tls offset at load
5390 ELFNN_R_INFO (indx
, AARCH64_R (TLS_DTPREL
));
5393 (globals
->root
.sgot
->output_section
->vma
5394 + globals
->root
.sgot
->output_offset
+ off
5397 loc
= globals
->root
.srelgot
->contents
;
5398 loc
+= globals
->root
.srelgot
->reloc_count
++
5399 * RELOC_SIZE (globals
);
5400 bfd_elfNN_swap_reloca_out (output_bfd
, &rela
, loc
);
5401 bfd_put_NN (output_bfd
, (bfd_vma
) 0,
5402 globals
->root
.sgot
->contents
+ off
5408 bfd_put_NN (output_bfd
, (bfd_vma
) 1,
5409 globals
->root
.sgot
->contents
+ off
);
5410 bfd_put_NN (output_bfd
,
5411 relocation
- dtpoff_base (info
),
5412 globals
->root
.sgot
->contents
+ off
5416 symbol_got_offset_mark (input_bfd
, h
, r_symndx
);
5420 case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21
:
5421 case BFD_RELOC_AARCH64_TLSIE_LDNN_GOTTPREL_LO12_NC
:
5422 case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19
:
5423 if (! symbol_got_offset_mark_p (input_bfd
, h
, r_symndx
))
5425 bfd_boolean need_relocs
= FALSE
;
5430 off
= symbol_got_offset (input_bfd
, h
, r_symndx
);
5432 indx
= h
&& h
->dynindx
!= -1 ? h
->dynindx
: 0;
5435 (info
->shared
|| indx
!= 0) &&
5437 || ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
5438 || h
->root
.type
!= bfd_link_hash_undefweak
);
5440 BFD_ASSERT (globals
->root
.srelgot
!= NULL
);
5444 Elf_Internal_Rela rela
;
5447 rela
.r_addend
= relocation
- dtpoff_base (info
);
5451 rela
.r_info
= ELFNN_R_INFO (indx
, AARCH64_R (TLS_TPREL
));
5452 rela
.r_offset
= globals
->root
.sgot
->output_section
->vma
+
5453 globals
->root
.sgot
->output_offset
+ off
;
5455 loc
= globals
->root
.srelgot
->contents
;
5456 loc
+= globals
->root
.srelgot
->reloc_count
++
5457 * RELOC_SIZE (htab
);
5459 bfd_elfNN_swap_reloca_out (output_bfd
, &rela
, loc
);
5461 bfd_put_NN (output_bfd
, rela
.r_addend
,
5462 globals
->root
.sgot
->contents
+ off
);
5465 bfd_put_NN (output_bfd
, relocation
- tpoff_base (info
),
5466 globals
->root
.sgot
->contents
+ off
);
5468 symbol_got_offset_mark (input_bfd
, h
, r_symndx
);
5472 case BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_LO12
:
5473 case BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_HI12
:
5474 case BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_LO12_NC
:
5475 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G2
:
5476 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1
:
5477 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1_NC
:
5478 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0
:
5479 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC
:
5482 case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12_NC
:
5483 case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21
:
5484 case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21
:
5485 case BFD_RELOC_AARCH64_TLSDESC_LDNN_LO12_NC
:
5486 case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19
:
5487 if (! symbol_tlsdesc_got_offset_mark_p (input_bfd
, h
, r_symndx
))
5489 bfd_boolean need_relocs
= FALSE
;
5490 int indx
= h
&& h
->dynindx
!= -1 ? h
->dynindx
: 0;
5491 bfd_vma off
= symbol_tlsdesc_got_offset (input_bfd
, h
, r_symndx
);
5493 need_relocs
= (h
== NULL
5494 || ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
5495 || h
->root
.type
!= bfd_link_hash_undefweak
);
5497 BFD_ASSERT (globals
->root
.srelgot
!= NULL
);
5498 BFD_ASSERT (globals
->root
.sgot
!= NULL
);
5503 Elf_Internal_Rela rela
;
5504 rela
.r_info
= ELFNN_R_INFO (indx
, AARCH64_R (TLSDESC
));
5507 rela
.r_offset
= (globals
->root
.sgotplt
->output_section
->vma
5508 + globals
->root
.sgotplt
->output_offset
5509 + off
+ globals
->sgotplt_jump_table_size
);
5512 rela
.r_addend
= relocation
- dtpoff_base (info
);
5514 /* Allocate the next available slot in the PLT reloc
5515 section to hold our R_AARCH64_TLSDESC, the next
5516 available slot is determined from reloc_count,
5517 which we step. But note, reloc_count was
5518 artifically moved down while allocating slots for
5519 real PLT relocs such that all of the PLT relocs
5520 will fit above the initial reloc_count and the
5521 extra stuff will fit below. */
5522 loc
= globals
->root
.srelplt
->contents
;
5523 loc
+= globals
->root
.srelplt
->reloc_count
++
5524 * RELOC_SIZE (globals
);
5526 bfd_elfNN_swap_reloca_out (output_bfd
, &rela
, loc
);
5528 bfd_put_NN (output_bfd
, (bfd_vma
) 0,
5529 globals
->root
.sgotplt
->contents
+ off
+
5530 globals
->sgotplt_jump_table_size
);
5531 bfd_put_NN (output_bfd
, (bfd_vma
) 0,
5532 globals
->root
.sgotplt
->contents
+ off
+
5533 globals
->sgotplt_jump_table_size
+
5537 symbol_tlsdesc_got_offset_mark (input_bfd
, h
, r_symndx
);
5548 /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
5549 because such sections are not SEC_ALLOC and thus ld.so will
5550 not process them. */
5551 if (unresolved_reloc
5552 && !((input_section
->flags
& SEC_DEBUGGING
) != 0
5554 && _bfd_elf_section_offset (output_bfd
, info
, input_section
,
5555 +rel
->r_offset
) != (bfd_vma
) - 1)
5557 (*_bfd_error_handler
)
5559 ("%B(%A+0x%lx): unresolvable %s relocation against symbol `%s'"),
5560 input_bfd
, input_section
, (long) rel
->r_offset
, howto
->name
,
5561 h
->root
.root
.string
);
5565 if (r
!= bfd_reloc_ok
&& r
!= bfd_reloc_continue
)
5569 case bfd_reloc_overflow
:
5570 /* If the overflowing reloc was to an undefined symbol,
5571 we have already printed one error message and there
5572 is no point complaining again. */
5574 h
->root
.type
!= bfd_link_hash_undefined
)
5575 && (!((*info
->callbacks
->reloc_overflow
)
5576 (info
, (h
? &h
->root
: NULL
), name
, howto
->name
,
5577 (bfd_vma
) 0, input_bfd
, input_section
,
5582 case bfd_reloc_undefined
:
5583 if (!((*info
->callbacks
->undefined_symbol
)
5584 (info
, name
, input_bfd
, input_section
,
5585 rel
->r_offset
, TRUE
)))
5589 case bfd_reloc_outofrange
:
5590 error_message
= _("out of range");
5593 case bfd_reloc_notsupported
:
5594 error_message
= _("unsupported relocation");
5597 case bfd_reloc_dangerous
:
5598 /* error_message should already be set. */
5602 error_message
= _("unknown error");
5606 BFD_ASSERT (error_message
!= NULL
);
5607 if (!((*info
->callbacks
->reloc_dangerous
)
5608 (info
, error_message
, input_bfd
, input_section
,
5619 /* Set the right machine number. */
5622 elfNN_aarch64_object_p (bfd
*abfd
)
5625 bfd_default_set_arch_mach (abfd
, bfd_arch_aarch64
, bfd_mach_aarch64_ilp32
);
5627 bfd_default_set_arch_mach (abfd
, bfd_arch_aarch64
, bfd_mach_aarch64
);
5632 /* Function to keep AArch64 specific flags in the ELF header. */
5635 elfNN_aarch64_set_private_flags (bfd
*abfd
, flagword flags
)
5637 if (elf_flags_init (abfd
) && elf_elfheader (abfd
)->e_flags
!= flags
)
5642 elf_elfheader (abfd
)->e_flags
= flags
;
5643 elf_flags_init (abfd
) = TRUE
;
5649 /* Merge backend specific data from an object file to the output
5650 object file when linking. */
5653 elfNN_aarch64_merge_private_bfd_data (bfd
*ibfd
, bfd
*obfd
)
5657 bfd_boolean flags_compatible
= TRUE
;
5660 /* Check if we have the same endianess. */
5661 if (!_bfd_generic_verify_endian_match (ibfd
, obfd
))
5664 if (!is_aarch64_elf (ibfd
) || !is_aarch64_elf (obfd
))
5667 /* The input BFD must have had its flags initialised. */
5668 /* The following seems bogus to me -- The flags are initialized in
5669 the assembler but I don't think an elf_flags_init field is
5670 written into the object. */
5671 /* BFD_ASSERT (elf_flags_init (ibfd)); */
5673 in_flags
= elf_elfheader (ibfd
)->e_flags
;
5674 out_flags
= elf_elfheader (obfd
)->e_flags
;
5676 if (!elf_flags_init (obfd
))
5678 /* If the input is the default architecture and had the default
5679 flags then do not bother setting the flags for the output
5680 architecture, instead allow future merges to do this. If no
5681 future merges ever set these flags then they will retain their
5682 uninitialised values, which surprise surprise, correspond
5683 to the default values. */
5684 if (bfd_get_arch_info (ibfd
)->the_default
5685 && elf_elfheader (ibfd
)->e_flags
== 0)
5688 elf_flags_init (obfd
) = TRUE
;
5689 elf_elfheader (obfd
)->e_flags
= in_flags
;
5691 if (bfd_get_arch (obfd
) == bfd_get_arch (ibfd
)
5692 && bfd_get_arch_info (obfd
)->the_default
)
5693 return bfd_set_arch_mach (obfd
, bfd_get_arch (ibfd
),
5694 bfd_get_mach (ibfd
));
5699 /* Identical flags must be compatible. */
5700 if (in_flags
== out_flags
)
5703 /* Check to see if the input BFD actually contains any sections. If
5704 not, its flags may not have been initialised either, but it
5705 cannot actually cause any incompatiblity. Do not short-circuit
5706 dynamic objects; their section list may be emptied by
5707 elf_link_add_object_symbols.
5709 Also check to see if there are no code sections in the input.
5710 In this case there is no need to check for code specific flags.
5711 XXX - do we need to worry about floating-point format compatability
5712 in data sections ? */
5713 if (!(ibfd
->flags
& DYNAMIC
))
5715 bfd_boolean null_input_bfd
= TRUE
;
5716 bfd_boolean only_data_sections
= TRUE
;
5718 for (sec
= ibfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
5720 if ((bfd_get_section_flags (ibfd
, sec
)
5721 & (SEC_LOAD
| SEC_CODE
| SEC_HAS_CONTENTS
))
5722 == (SEC_LOAD
| SEC_CODE
| SEC_HAS_CONTENTS
))
5723 only_data_sections
= FALSE
;
5725 null_input_bfd
= FALSE
;
5729 if (null_input_bfd
|| only_data_sections
)
5733 return flags_compatible
;
5736 /* Display the flags field. */
5739 elfNN_aarch64_print_private_bfd_data (bfd
*abfd
, void *ptr
)
5741 FILE *file
= (FILE *) ptr
;
5742 unsigned long flags
;
5744 BFD_ASSERT (abfd
!= NULL
&& ptr
!= NULL
);
5746 /* Print normal ELF private data. */
5747 _bfd_elf_print_private_bfd_data (abfd
, ptr
);
5749 flags
= elf_elfheader (abfd
)->e_flags
;
5750 /* Ignore init flag - it may not be set, despite the flags field
5751 containing valid data. */
5753 /* xgettext:c-format */
5754 fprintf (file
, _("private flags = %lx:"), elf_elfheader (abfd
)->e_flags
);
5757 fprintf (file
, _("<Unrecognised flag bits set>"));
5764 /* Update the got entry reference counts for the section being removed. */
5767 elfNN_aarch64_gc_sweep_hook (bfd
*abfd
,
5768 struct bfd_link_info
*info
,
5770 const Elf_Internal_Rela
* relocs
)
5772 struct elf_aarch64_link_hash_table
*htab
;
5773 Elf_Internal_Shdr
*symtab_hdr
;
5774 struct elf_link_hash_entry
**sym_hashes
;
5775 struct elf_aarch64_local_symbol
*locals
;
5776 const Elf_Internal_Rela
*rel
, *relend
;
5778 if (info
->relocatable
)
5781 htab
= elf_aarch64_hash_table (info
);
5786 elf_section_data (sec
)->local_dynrel
= NULL
;
5788 symtab_hdr
= &elf_symtab_hdr (abfd
);
5789 sym_hashes
= elf_sym_hashes (abfd
);
5791 locals
= elf_aarch64_locals (abfd
);
5793 relend
= relocs
+ sec
->reloc_count
;
5794 for (rel
= relocs
; rel
< relend
; rel
++)
5796 unsigned long r_symndx
;
5797 unsigned int r_type
;
5798 struct elf_link_hash_entry
*h
= NULL
;
5800 r_symndx
= ELFNN_R_SYM (rel
->r_info
);
5802 if (r_symndx
>= symtab_hdr
->sh_info
)
5805 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
5806 while (h
->root
.type
== bfd_link_hash_indirect
5807 || h
->root
.type
== bfd_link_hash_warning
)
5808 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
5812 Elf_Internal_Sym
*isym
;
5814 /* A local symbol. */
5815 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
5818 /* Check relocation against local STT_GNU_IFUNC symbol. */
5820 && ELF_ST_TYPE (isym
->st_info
) == STT_GNU_IFUNC
)
5822 h
= elfNN_aarch64_get_local_sym_hash (htab
, abfd
, rel
, FALSE
);
5830 struct elf_aarch64_link_hash_entry
*eh
;
5831 struct elf_dyn_relocs
**pp
;
5832 struct elf_dyn_relocs
*p
;
5834 eh
= (struct elf_aarch64_link_hash_entry
*) h
;
5836 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; pp
= &p
->next
)
5839 /* Everything must go for SEC. */
5845 r_type
= ELFNN_R_TYPE (rel
->r_info
);
5846 switch (aarch64_tls_transition (abfd
,info
, r_type
, h
,r_symndx
))
5848 case BFD_RELOC_AARCH64_ADR_GOT_PAGE
:
5849 case BFD_RELOC_AARCH64_GOT_LD_PREL19
:
5850 case BFD_RELOC_AARCH64_LD32_GOT_LO12_NC
:
5851 case BFD_RELOC_AARCH64_LD64_GOT_LO12_NC
:
5852 case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12_NC
:
5853 case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21
:
5854 case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21
:
5855 case BFD_RELOC_AARCH64_TLSDESC_LD32_LO12_NC
:
5856 case BFD_RELOC_AARCH64_TLSDESC_LD64_LO12_NC
:
5857 case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19
:
5858 case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC
:
5859 case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21
:
5860 case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21
:
5861 case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21
:
5862 case BFD_RELOC_AARCH64_TLSIE_LD32_GOTTPREL_LO12_NC
:
5863 case BFD_RELOC_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC
:
5864 case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19
:
5865 case BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_HI12
:
5866 case BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_LO12
:
5867 case BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_LO12_NC
:
5868 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0
:
5869 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC
:
5870 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1
:
5871 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1_NC
:
5872 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G2
:
5875 if (h
->got
.refcount
> 0)
5876 h
->got
.refcount
-= 1;
5878 if (h
->type
== STT_GNU_IFUNC
)
5880 if (h
->plt
.refcount
> 0)
5881 h
->plt
.refcount
-= 1;
5884 else if (locals
!= NULL
)
5886 if (locals
[r_symndx
].got_refcount
> 0)
5887 locals
[r_symndx
].got_refcount
-= 1;
5891 case BFD_RELOC_AARCH64_CALL26
:
5892 case BFD_RELOC_AARCH64_JUMP26
:
5893 /* If this is a local symbol then we resolve it
5894 directly without creating a PLT entry. */
5898 if (h
->plt
.refcount
> 0)
5899 h
->plt
.refcount
-= 1;
5902 case BFD_RELOC_AARCH64_MOVW_G0_NC
:
5903 case BFD_RELOC_AARCH64_MOVW_G1_NC
:
5904 case BFD_RELOC_AARCH64_MOVW_G2_NC
:
5905 case BFD_RELOC_AARCH64_MOVW_G3
:
5906 case BFD_RELOC_AARCH64_ADR_HI21_NC_PCREL
:
5907 case BFD_RELOC_AARCH64_ADR_HI21_PCREL
:
5908 case BFD_RELOC_AARCH64_ADR_LO21_PCREL
:
5909 case BFD_RELOC_AARCH64_NN
:
5910 if (h
!= NULL
&& info
->executable
)
5912 if (h
->plt
.refcount
> 0)
5913 h
->plt
.refcount
-= 1;
5925 /* Adjust a symbol defined by a dynamic object and referenced by a
5926 regular object. The current definition is in some section of the
5927 dynamic object, but we're not including those sections. We have to
5928 change the definition to something the rest of the link can
5932 elfNN_aarch64_adjust_dynamic_symbol (struct bfd_link_info
*info
,
5933 struct elf_link_hash_entry
*h
)
5935 struct elf_aarch64_link_hash_table
*htab
;
5938 /* If this is a function, put it in the procedure linkage table. We
5939 will fill in the contents of the procedure linkage table later,
5940 when we know the address of the .got section. */
5941 if (h
->type
== STT_FUNC
|| h
->type
== STT_GNU_IFUNC
|| h
->needs_plt
)
5943 if (h
->plt
.refcount
<= 0
5944 || (h
->type
!= STT_GNU_IFUNC
5945 && (SYMBOL_CALLS_LOCAL (info
, h
)
5946 || (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
5947 && h
->root
.type
== bfd_link_hash_undefweak
))))
5949 /* This case can occur if we saw a CALL26 reloc in
5950 an input file, but the symbol wasn't referred to
5951 by a dynamic object or all references were
5952 garbage collected. In which case we can end up
5954 h
->plt
.offset
= (bfd_vma
) - 1;
5961 /* It's possible that we incorrectly decided a .plt reloc was
5962 needed for an R_X86_64_PC32 reloc to a non-function sym in
5963 check_relocs. We can't decide accurately between function and
5964 non-function syms in check-relocs; Objects loaded later in
5965 the link may change h->type. So fix it now. */
5966 h
->plt
.offset
= (bfd_vma
) - 1;
5969 /* If this is a weak symbol, and there is a real definition, the
5970 processor independent code will have arranged for us to see the
5971 real definition first, and we can just use the same value. */
5972 if (h
->u
.weakdef
!= NULL
)
5974 BFD_ASSERT (h
->u
.weakdef
->root
.type
== bfd_link_hash_defined
5975 || h
->u
.weakdef
->root
.type
== bfd_link_hash_defweak
);
5976 h
->root
.u
.def
.section
= h
->u
.weakdef
->root
.u
.def
.section
;
5977 h
->root
.u
.def
.value
= h
->u
.weakdef
->root
.u
.def
.value
;
5978 if (ELIMINATE_COPY_RELOCS
|| info
->nocopyreloc
)
5979 h
->non_got_ref
= h
->u
.weakdef
->non_got_ref
;
5983 /* If we are creating a shared library, we must presume that the
5984 only references to the symbol are via the global offset table.
5985 For such cases we need not do anything here; the relocations will
5986 be handled correctly by relocate_section. */
5990 /* If there are no references to this symbol that do not use the
5991 GOT, we don't need to generate a copy reloc. */
5992 if (!h
->non_got_ref
)
5995 /* If -z nocopyreloc was given, we won't generate them either. */
5996 if (info
->nocopyreloc
)
6002 /* We must allocate the symbol in our .dynbss section, which will
6003 become part of the .bss section of the executable. There will be
6004 an entry for this symbol in the .dynsym section. The dynamic
6005 object will contain position independent code, so all references
6006 from the dynamic object to this symbol will go through the global
6007 offset table. The dynamic linker will use the .dynsym entry to
6008 determine the address it must put in the global offset table, so
6009 both the dynamic object and the regular object will refer to the
6010 same memory location for the variable. */
6012 htab
= elf_aarch64_hash_table (info
);
6014 /* We must generate a R_AARCH64_COPY reloc to tell the dynamic linker
6015 to copy the initial value out of the dynamic object and into the
6016 runtime process image. */
6017 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0 && h
->size
!= 0)
6019 htab
->srelbss
->size
+= RELOC_SIZE (htab
);
6025 return _bfd_elf_adjust_dynamic_copy (info
, h
, s
);
6030 elfNN_aarch64_allocate_local_symbols (bfd
*abfd
, unsigned number
)
6032 struct elf_aarch64_local_symbol
*locals
;
6033 locals
= elf_aarch64_locals (abfd
);
6036 locals
= (struct elf_aarch64_local_symbol
*)
6037 bfd_zalloc (abfd
, number
* sizeof (struct elf_aarch64_local_symbol
));
6040 elf_aarch64_locals (abfd
) = locals
;
6045 /* Create the .got section to hold the global offset table. */
6048 aarch64_elf_create_got_section (bfd
*abfd
, struct bfd_link_info
*info
)
6050 const struct elf_backend_data
*bed
= get_elf_backend_data (abfd
);
6053 struct elf_link_hash_entry
*h
;
6054 struct elf_link_hash_table
*htab
= elf_hash_table (info
);
6056 /* This function may be called more than once. */
6057 s
= bfd_get_linker_section (abfd
, ".got");
6061 flags
= bed
->dynamic_sec_flags
;
6063 s
= bfd_make_section_anyway_with_flags (abfd
,
6064 (bed
->rela_plts_and_copies_p
6065 ? ".rela.got" : ".rel.got"),
6066 (bed
->dynamic_sec_flags
6069 || ! bfd_set_section_alignment (abfd
, s
, bed
->s
->log_file_align
))
6073 s
= bfd_make_section_anyway_with_flags (abfd
, ".got", flags
);
6075 || !bfd_set_section_alignment (abfd
, s
, bed
->s
->log_file_align
))
6078 htab
->sgot
->size
+= GOT_ENTRY_SIZE
;
6080 if (bed
->want_got_sym
)
6082 /* Define the symbol _GLOBAL_OFFSET_TABLE_ at the start of the .got
6083 (or .got.plt) section. We don't do this in the linker script
6084 because we don't want to define the symbol if we are not creating
6085 a global offset table. */
6086 h
= _bfd_elf_define_linkage_sym (abfd
, info
, s
,
6087 "_GLOBAL_OFFSET_TABLE_");
6088 elf_hash_table (info
)->hgot
= h
;
6093 if (bed
->want_got_plt
)
6095 s
= bfd_make_section_anyway_with_flags (abfd
, ".got.plt", flags
);
6097 || !bfd_set_section_alignment (abfd
, s
,
6098 bed
->s
->log_file_align
))
6103 /* The first bit of the global offset table is the header. */
6104 s
->size
+= bed
->got_header_size
;
6109 /* Look through the relocs for a section during the first phase. */
6112 elfNN_aarch64_check_relocs (bfd
*abfd
, struct bfd_link_info
*info
,
6113 asection
*sec
, const Elf_Internal_Rela
*relocs
)
6115 Elf_Internal_Shdr
*symtab_hdr
;
6116 struct elf_link_hash_entry
**sym_hashes
;
6117 const Elf_Internal_Rela
*rel
;
6118 const Elf_Internal_Rela
*rel_end
;
6121 struct elf_aarch64_link_hash_table
*htab
;
6123 if (info
->relocatable
)
6126 BFD_ASSERT (is_aarch64_elf (abfd
));
6128 htab
= elf_aarch64_hash_table (info
);
6131 symtab_hdr
= &elf_symtab_hdr (abfd
);
6132 sym_hashes
= elf_sym_hashes (abfd
);
6134 rel_end
= relocs
+ sec
->reloc_count
;
6135 for (rel
= relocs
; rel
< rel_end
; rel
++)
6137 struct elf_link_hash_entry
*h
;
6138 unsigned long r_symndx
;
6139 unsigned int r_type
;
6140 bfd_reloc_code_real_type bfd_r_type
;
6141 Elf_Internal_Sym
*isym
;
6143 r_symndx
= ELFNN_R_SYM (rel
->r_info
);
6144 r_type
= ELFNN_R_TYPE (rel
->r_info
);
6146 if (r_symndx
>= NUM_SHDR_ENTRIES (symtab_hdr
))
6148 (*_bfd_error_handler
) (_("%B: bad symbol index: %d"), abfd
,
6153 if (r_symndx
< symtab_hdr
->sh_info
)
6155 /* A local symbol. */
6156 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
6161 /* Check relocation against local STT_GNU_IFUNC symbol. */
6162 if (ELF_ST_TYPE (isym
->st_info
) == STT_GNU_IFUNC
)
6164 h
= elfNN_aarch64_get_local_sym_hash (htab
, abfd
, rel
,
6169 /* Fake a STT_GNU_IFUNC symbol. */
6170 h
->type
= STT_GNU_IFUNC
;
6173 h
->forced_local
= 1;
6174 h
->root
.type
= bfd_link_hash_defined
;
6181 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
6182 while (h
->root
.type
== bfd_link_hash_indirect
6183 || h
->root
.type
== bfd_link_hash_warning
)
6184 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
6186 /* PR15323, ref flags aren't set for references in the same
6188 h
->root
.non_ir_ref
= 1;
6191 /* Could be done earlier, if h were already available. */
6192 bfd_r_type
= aarch64_tls_transition (abfd
, info
, r_type
, h
, r_symndx
);
6196 /* Create the ifunc sections for static executables. If we
6197 never see an indirect function symbol nor we are building
6198 a static executable, those sections will be empty and
6199 won't appear in output. */
6205 case BFD_RELOC_AARCH64_NN
:
6206 case BFD_RELOC_AARCH64_CALL26
:
6207 case BFD_RELOC_AARCH64_JUMP26
:
6208 case BFD_RELOC_AARCH64_LD32_GOT_LO12_NC
:
6209 case BFD_RELOC_AARCH64_LD64_GOT_LO12_NC
:
6210 case BFD_RELOC_AARCH64_ADR_GOT_PAGE
:
6211 case BFD_RELOC_AARCH64_GOT_LD_PREL19
:
6212 case BFD_RELOC_AARCH64_ADR_HI21_PCREL
:
6213 case BFD_RELOC_AARCH64_ADD_LO12
:
6214 if (htab
->root
.dynobj
== NULL
)
6215 htab
->root
.dynobj
= abfd
;
6216 if (!_bfd_elf_create_ifunc_sections (htab
->root
.dynobj
, info
))
6221 /* It is referenced by a non-shared object. */
6223 h
->root
.non_ir_ref
= 1;
6228 case BFD_RELOC_AARCH64_NN
:
6230 /* We don't need to handle relocs into sections not going into
6231 the "real" output. */
6232 if ((sec
->flags
& SEC_ALLOC
) == 0)
6240 h
->plt
.refcount
+= 1;
6241 h
->pointer_equality_needed
= 1;
6244 /* No need to do anything if we're not creating a shared
6250 struct elf_dyn_relocs
*p
;
6251 struct elf_dyn_relocs
**head
;
6253 /* We must copy these reloc types into the output file.
6254 Create a reloc section in dynobj and make room for
6258 if (htab
->root
.dynobj
== NULL
)
6259 htab
->root
.dynobj
= abfd
;
6261 sreloc
= _bfd_elf_make_dynamic_reloc_section
6262 (sec
, htab
->root
.dynobj
, LOG_FILE_ALIGN
, abfd
, /*rela? */ TRUE
);
6268 /* If this is a global symbol, we count the number of
6269 relocations we need for this symbol. */
6272 struct elf_aarch64_link_hash_entry
*eh
;
6273 eh
= (struct elf_aarch64_link_hash_entry
*) h
;
6274 head
= &eh
->dyn_relocs
;
6278 /* Track dynamic relocs needed for local syms too.
6279 We really need local syms available to do this
6285 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
6290 s
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
6294 /* Beware of type punned pointers vs strict aliasing
6296 vpp
= &(elf_section_data (s
)->local_dynrel
);
6297 head
= (struct elf_dyn_relocs
**) vpp
;
6301 if (p
== NULL
|| p
->sec
!= sec
)
6303 bfd_size_type amt
= sizeof *p
;
6304 p
= ((struct elf_dyn_relocs
*)
6305 bfd_zalloc (htab
->root
.dynobj
, amt
));
6318 /* RR: We probably want to keep a consistency check that
6319 there are no dangling GOT_PAGE relocs. */
6320 case BFD_RELOC_AARCH64_ADR_GOT_PAGE
:
6321 case BFD_RELOC_AARCH64_GOT_LD_PREL19
:
6322 case BFD_RELOC_AARCH64_LD32_GOT_LO12_NC
:
6323 case BFD_RELOC_AARCH64_LD64_GOT_LO12_NC
:
6324 case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12_NC
:
6325 case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21
:
6326 case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21
:
6327 case BFD_RELOC_AARCH64_TLSDESC_LD32_LO12_NC
:
6328 case BFD_RELOC_AARCH64_TLSDESC_LD64_LO12_NC
:
6329 case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19
:
6330 case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC
:
6331 case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21
:
6332 case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21
:
6333 case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21
:
6334 case BFD_RELOC_AARCH64_TLSIE_LD32_GOTTPREL_LO12_NC
:
6335 case BFD_RELOC_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC
:
6336 case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19
:
6337 case BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_HI12
:
6338 case BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_LO12
:
6339 case BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_LO12_NC
:
6340 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0
:
6341 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC
:
6342 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1
:
6343 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1_NC
:
6344 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G2
:
6347 unsigned old_got_type
;
6349 got_type
= aarch64_reloc_got_type (bfd_r_type
);
6353 h
->got
.refcount
+= 1;
6354 old_got_type
= elf_aarch64_hash_entry (h
)->got_type
;
6358 struct elf_aarch64_local_symbol
*locals
;
6360 if (!elfNN_aarch64_allocate_local_symbols
6361 (abfd
, symtab_hdr
->sh_info
))
6364 locals
= elf_aarch64_locals (abfd
);
6365 BFD_ASSERT (r_symndx
< symtab_hdr
->sh_info
);
6366 locals
[r_symndx
].got_refcount
+= 1;
6367 old_got_type
= locals
[r_symndx
].got_type
;
6370 /* If a variable is accessed with both general dynamic TLS
6371 methods, two slots may be created. */
6372 if (GOT_TLS_GD_ANY_P (old_got_type
) && GOT_TLS_GD_ANY_P (got_type
))
6373 got_type
|= old_got_type
;
6375 /* We will already have issued an error message if there
6376 is a TLS/non-TLS mismatch, based on the symbol type.
6377 So just combine any TLS types needed. */
6378 if (old_got_type
!= GOT_UNKNOWN
&& old_got_type
!= GOT_NORMAL
6379 && got_type
!= GOT_NORMAL
)
6380 got_type
|= old_got_type
;
6382 /* If the symbol is accessed by both IE and GD methods, we
6383 are able to relax. Turn off the GD flag, without
6384 messing up with any other kind of TLS types that may be
6386 if ((got_type
& GOT_TLS_IE
) && GOT_TLS_GD_ANY_P (got_type
))
6387 got_type
&= ~ (GOT_TLSDESC_GD
| GOT_TLS_GD
);
6389 if (old_got_type
!= got_type
)
6392 elf_aarch64_hash_entry (h
)->got_type
= got_type
;
6395 struct elf_aarch64_local_symbol
*locals
;
6396 locals
= elf_aarch64_locals (abfd
);
6397 BFD_ASSERT (r_symndx
< symtab_hdr
->sh_info
);
6398 locals
[r_symndx
].got_type
= got_type
;
6402 if (htab
->root
.dynobj
== NULL
)
6403 htab
->root
.dynobj
= abfd
;
6404 if (! aarch64_elf_create_got_section (htab
->root
.dynobj
, info
))
6409 case BFD_RELOC_AARCH64_MOVW_G0_NC
:
6410 case BFD_RELOC_AARCH64_MOVW_G1_NC
:
6411 case BFD_RELOC_AARCH64_MOVW_G2_NC
:
6412 case BFD_RELOC_AARCH64_MOVW_G3
:
6415 int howto_index
= bfd_r_type
- BFD_RELOC_AARCH64_RELOC_START
;
6416 (*_bfd_error_handler
)
6417 (_("%B: relocation %s against `%s' can not be used when making "
6418 "a shared object; recompile with -fPIC"),
6419 abfd
, elfNN_aarch64_howto_table
[howto_index
].name
,
6420 (h
) ? h
->root
.root
.string
: "a local symbol");
6421 bfd_set_error (bfd_error_bad_value
);
6425 case BFD_RELOC_AARCH64_ADR_HI21_NC_PCREL
:
6426 case BFD_RELOC_AARCH64_ADR_HI21_PCREL
:
6427 case BFD_RELOC_AARCH64_ADR_LO21_PCREL
:
6428 if (h
!= NULL
&& info
->executable
)
6430 /* If this reloc is in a read-only section, we might
6431 need a copy reloc. We can't check reliably at this
6432 stage whether the section is read-only, as input
6433 sections have not yet been mapped to output sections.
6434 Tentatively set the flag for now, and correct in
6435 adjust_dynamic_symbol. */
6437 h
->plt
.refcount
+= 1;
6438 h
->pointer_equality_needed
= 1;
6440 /* FIXME:: RR need to handle these in shared libraries
6441 and essentially bomb out as these being non-PIC
6442 relocations in shared libraries. */
6445 case BFD_RELOC_AARCH64_CALL26
:
6446 case BFD_RELOC_AARCH64_JUMP26
:
6447 /* If this is a local symbol then we resolve it
6448 directly without creating a PLT entry. */
6453 if (h
->plt
.refcount
<= 0)
6454 h
->plt
.refcount
= 1;
6456 h
->plt
.refcount
+= 1;
6467 /* Treat mapping symbols as special target symbols. */
6470 elfNN_aarch64_is_target_special_symbol (bfd
*abfd ATTRIBUTE_UNUSED
,
6473 return bfd_is_aarch64_special_symbol_name (sym
->name
,
6474 BFD_AARCH64_SPECIAL_SYM_TYPE_ANY
);
6477 /* This is a copy of elf_find_function () from elf.c except that
6478 AArch64 mapping symbols are ignored when looking for function names. */
6481 aarch64_elf_find_function (bfd
*abfd ATTRIBUTE_UNUSED
,
6485 const char **filename_ptr
,
6486 const char **functionname_ptr
)
6488 const char *filename
= NULL
;
6489 asymbol
*func
= NULL
;
6490 bfd_vma low_func
= 0;
6493 for (p
= symbols
; *p
!= NULL
; p
++)
6497 q
= (elf_symbol_type
*) * p
;
6499 switch (ELF_ST_TYPE (q
->internal_elf_sym
.st_info
))
6504 filename
= bfd_asymbol_name (&q
->symbol
);
6508 /* Skip mapping symbols. */
6509 if ((q
->symbol
.flags
& BSF_LOCAL
)
6510 && (bfd_is_aarch64_special_symbol_name
6511 (q
->symbol
.name
, BFD_AARCH64_SPECIAL_SYM_TYPE_ANY
)))
6514 if (bfd_get_section (&q
->symbol
) == section
6515 && q
->symbol
.value
>= low_func
&& q
->symbol
.value
<= offset
)
6517 func
= (asymbol
*) q
;
6518 low_func
= q
->symbol
.value
;
6528 *filename_ptr
= filename
;
6529 if (functionname_ptr
)
6530 *functionname_ptr
= bfd_asymbol_name (func
);
6536 /* Find the nearest line to a particular section and offset, for error
6537 reporting. This code is a duplicate of the code in elf.c, except
6538 that it uses aarch64_elf_find_function. */
6541 elfNN_aarch64_find_nearest_line (bfd
*abfd
,
6545 const char **filename_ptr
,
6546 const char **functionname_ptr
,
6547 unsigned int *line_ptr
,
6548 unsigned int *discriminator_ptr
)
6550 bfd_boolean found
= FALSE
;
6552 if (_bfd_dwarf2_find_nearest_line (abfd
, symbols
, NULL
, section
, offset
,
6553 filename_ptr
, functionname_ptr
,
6554 line_ptr
, discriminator_ptr
,
6555 dwarf_debug_sections
, 0,
6556 &elf_tdata (abfd
)->dwarf2_find_line_info
))
6558 if (!*functionname_ptr
)
6559 aarch64_elf_find_function (abfd
, symbols
, section
, offset
,
6560 *filename_ptr
? NULL
: filename_ptr
,
6566 /* Skip _bfd_dwarf1_find_nearest_line since no known AArch64
6567 toolchain uses DWARF1. */
6569 if (!_bfd_stab_section_find_nearest_line (abfd
, symbols
, section
, offset
,
6570 &found
, filename_ptr
,
6571 functionname_ptr
, line_ptr
,
6572 &elf_tdata (abfd
)->line_info
))
6575 if (found
&& (*functionname_ptr
|| *line_ptr
))
6578 if (symbols
== NULL
)
6581 if (!aarch64_elf_find_function (abfd
, symbols
, section
, offset
,
6582 filename_ptr
, functionname_ptr
))
6590 elfNN_aarch64_find_inliner_info (bfd
*abfd
,
6591 const char **filename_ptr
,
6592 const char **functionname_ptr
,
6593 unsigned int *line_ptr
)
6596 found
= _bfd_dwarf2_find_inliner_info
6597 (abfd
, filename_ptr
,
6598 functionname_ptr
, line_ptr
, &elf_tdata (abfd
)->dwarf2_find_line_info
);
6604 elfNN_aarch64_post_process_headers (bfd
*abfd
,
6605 struct bfd_link_info
*link_info
)
6607 Elf_Internal_Ehdr
*i_ehdrp
; /* ELF file header, internal form. */
6609 i_ehdrp
= elf_elfheader (abfd
);
6610 i_ehdrp
->e_ident
[EI_ABIVERSION
] = AARCH64_ELF_ABI_VERSION
;
6612 _bfd_elf_post_process_headers (abfd
, link_info
);
6615 static enum elf_reloc_type_class
6616 elfNN_aarch64_reloc_type_class (const struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
6617 const asection
*rel_sec ATTRIBUTE_UNUSED
,
6618 const Elf_Internal_Rela
*rela
)
6620 switch ((int) ELFNN_R_TYPE (rela
->r_info
))
6622 case AARCH64_R (RELATIVE
):
6623 return reloc_class_relative
;
6624 case AARCH64_R (JUMP_SLOT
):
6625 return reloc_class_plt
;
6626 case AARCH64_R (COPY
):
6627 return reloc_class_copy
;
6629 return reloc_class_normal
;
6633 /* Handle an AArch64 specific section when reading an object file. This is
6634 called when bfd_section_from_shdr finds a section with an unknown
6638 elfNN_aarch64_section_from_shdr (bfd
*abfd
,
6639 Elf_Internal_Shdr
*hdr
,
6640 const char *name
, int shindex
)
6642 /* There ought to be a place to keep ELF backend specific flags, but
6643 at the moment there isn't one. We just keep track of the
6644 sections by their name, instead. Fortunately, the ABI gives
6645 names for all the AArch64 specific sections, so we will probably get
6647 switch (hdr
->sh_type
)
6649 case SHT_AARCH64_ATTRIBUTES
:
6656 if (!_bfd_elf_make_section_from_shdr (abfd
, hdr
, name
, shindex
))
6662 /* A structure used to record a list of sections, independently
6663 of the next and prev fields in the asection structure. */
6664 typedef struct section_list
6667 struct section_list
*next
;
6668 struct section_list
*prev
;
6672 /* Unfortunately we need to keep a list of sections for which
6673 an _aarch64_elf_section_data structure has been allocated. This
6674 is because it is possible for functions like elfNN_aarch64_write_section
6675 to be called on a section which has had an elf_data_structure
6676 allocated for it (and so the used_by_bfd field is valid) but
6677 for which the AArch64 extended version of this structure - the
6678 _aarch64_elf_section_data structure - has not been allocated. */
6679 static section_list
*sections_with_aarch64_elf_section_data
= NULL
;
6682 record_section_with_aarch64_elf_section_data (asection
*sec
)
6684 struct section_list
*entry
;
6686 entry
= bfd_malloc (sizeof (*entry
));
6690 entry
->next
= sections_with_aarch64_elf_section_data
;
6692 if (entry
->next
!= NULL
)
6693 entry
->next
->prev
= entry
;
6694 sections_with_aarch64_elf_section_data
= entry
;
6697 static struct section_list
*
6698 find_aarch64_elf_section_entry (asection
*sec
)
6700 struct section_list
*entry
;
6701 static struct section_list
*last_entry
= NULL
;
6703 /* This is a short cut for the typical case where the sections are added
6704 to the sections_with_aarch64_elf_section_data list in forward order and
6705 then looked up here in backwards order. This makes a real difference
6706 to the ld-srec/sec64k.exp linker test. */
6707 entry
= sections_with_aarch64_elf_section_data
;
6708 if (last_entry
!= NULL
)
6710 if (last_entry
->sec
== sec
)
6712 else if (last_entry
->next
!= NULL
&& last_entry
->next
->sec
== sec
)
6713 entry
= last_entry
->next
;
6716 for (; entry
; entry
= entry
->next
)
6717 if (entry
->sec
== sec
)
6721 /* Record the entry prior to this one - it is the entry we are
6722 most likely to want to locate next time. Also this way if we
6723 have been called from
6724 unrecord_section_with_aarch64_elf_section_data () we will not
6725 be caching a pointer that is about to be freed. */
6726 last_entry
= entry
->prev
;
6732 unrecord_section_with_aarch64_elf_section_data (asection
*sec
)
6734 struct section_list
*entry
;
6736 entry
= find_aarch64_elf_section_entry (sec
);
6740 if (entry
->prev
!= NULL
)
6741 entry
->prev
->next
= entry
->next
;
6742 if (entry
->next
!= NULL
)
6743 entry
->next
->prev
= entry
->prev
;
6744 if (entry
== sections_with_aarch64_elf_section_data
)
6745 sections_with_aarch64_elf_section_data
= entry
->next
;
6754 struct bfd_link_info
*info
;
6757 int (*func
) (void *, const char *, Elf_Internal_Sym
*,
6758 asection
*, struct elf_link_hash_entry
*);
6759 } output_arch_syminfo
;
6761 enum map_symbol_type
6768 /* Output a single mapping symbol. */
6771 elfNN_aarch64_output_map_sym (output_arch_syminfo
*osi
,
6772 enum map_symbol_type type
, bfd_vma offset
)
6774 static const char *names
[2] = { "$x", "$d" };
6775 Elf_Internal_Sym sym
;
6777 sym
.st_value
= (osi
->sec
->output_section
->vma
6778 + osi
->sec
->output_offset
+ offset
);
6781 sym
.st_info
= ELF_ST_INFO (STB_LOCAL
, STT_NOTYPE
);
6782 sym
.st_shndx
= osi
->sec_shndx
;
6783 return osi
->func (osi
->finfo
, names
[type
], &sym
, osi
->sec
, NULL
) == 1;
6788 /* Output mapping symbols for PLT entries associated with H. */
6791 elfNN_aarch64_output_plt_map (struct elf_link_hash_entry
*h
, void *inf
)
6793 output_arch_syminfo
*osi
= (output_arch_syminfo
*) inf
;
6796 if (h
->root
.type
== bfd_link_hash_indirect
)
6799 if (h
->root
.type
== bfd_link_hash_warning
)
6800 /* When warning symbols are created, they **replace** the "real"
6801 entry in the hash table, thus we never get to see the real
6802 symbol in a hash traversal. So look at it now. */
6803 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
6805 if (h
->plt
.offset
== (bfd_vma
) - 1)
6808 addr
= h
->plt
.offset
;
6811 if (!elfNN_aarch64_output_map_sym (osi
, AARCH64_MAP_INSN
, addr
))
6818 /* Output a single local symbol for a generated stub. */
6821 elfNN_aarch64_output_stub_sym (output_arch_syminfo
*osi
, const char *name
,
6822 bfd_vma offset
, bfd_vma size
)
6824 Elf_Internal_Sym sym
;
6826 sym
.st_value
= (osi
->sec
->output_section
->vma
6827 + osi
->sec
->output_offset
+ offset
);
6830 sym
.st_info
= ELF_ST_INFO (STB_LOCAL
, STT_FUNC
);
6831 sym
.st_shndx
= osi
->sec_shndx
;
6832 return osi
->func (osi
->finfo
, name
, &sym
, osi
->sec
, NULL
) == 1;
6836 aarch64_map_one_stub (struct bfd_hash_entry
*gen_entry
, void *in_arg
)
6838 struct elf_aarch64_stub_hash_entry
*stub_entry
;
6842 output_arch_syminfo
*osi
;
6844 /* Massage our args to the form they really have. */
6845 stub_entry
= (struct elf_aarch64_stub_hash_entry
*) gen_entry
;
6846 osi
= (output_arch_syminfo
*) in_arg
;
6848 stub_sec
= stub_entry
->stub_sec
;
6850 /* Ensure this stub is attached to the current section being
6852 if (stub_sec
!= osi
->sec
)
6855 addr
= (bfd_vma
) stub_entry
->stub_offset
;
6857 stub_name
= stub_entry
->output_name
;
6859 switch (stub_entry
->stub_type
)
6861 case aarch64_stub_adrp_branch
:
6862 if (!elfNN_aarch64_output_stub_sym (osi
, stub_name
, addr
,
6863 sizeof (aarch64_adrp_branch_stub
)))
6865 if (!elfNN_aarch64_output_map_sym (osi
, AARCH64_MAP_INSN
, addr
))
6868 case aarch64_stub_long_branch
:
6869 if (!elfNN_aarch64_output_stub_sym
6870 (osi
, stub_name
, addr
, sizeof (aarch64_long_branch_stub
)))
6872 if (!elfNN_aarch64_output_map_sym (osi
, AARCH64_MAP_INSN
, addr
))
6874 if (!elfNN_aarch64_output_map_sym (osi
, AARCH64_MAP_DATA
, addr
+ 16))
6877 case aarch64_stub_erratum_835769_veneer
:
6878 if (!elfNN_aarch64_output_stub_sym (osi
, stub_name
, addr
,
6879 sizeof (aarch64_erratum_835769_stub
)))
6881 if (!elfNN_aarch64_output_map_sym (osi
, AARCH64_MAP_INSN
, addr
))
6884 case aarch64_stub_erratum_843419_veneer
:
6885 if (!elfNN_aarch64_output_stub_sym (osi
, stub_name
, addr
,
6886 sizeof (aarch64_erratum_843419_stub
)))
6888 if (!elfNN_aarch64_output_map_sym (osi
, AARCH64_MAP_INSN
, addr
))
6899 /* Output mapping symbols for linker generated sections. */
6902 elfNN_aarch64_output_arch_local_syms (bfd
*output_bfd
,
6903 struct bfd_link_info
*info
,
6905 int (*func
) (void *, const char *,
6908 struct elf_link_hash_entry
6911 output_arch_syminfo osi
;
6912 struct elf_aarch64_link_hash_table
*htab
;
6914 htab
= elf_aarch64_hash_table (info
);
6920 /* Long calls stubs. */
6921 if (htab
->stub_bfd
&& htab
->stub_bfd
->sections
)
6925 for (stub_sec
= htab
->stub_bfd
->sections
;
6926 stub_sec
!= NULL
; stub_sec
= stub_sec
->next
)
6928 /* Ignore non-stub sections. */
6929 if (!strstr (stub_sec
->name
, STUB_SUFFIX
))
6934 osi
.sec_shndx
= _bfd_elf_section_from_bfd_section
6935 (output_bfd
, osi
.sec
->output_section
);
6937 /* The first instruction in a stub is always a branch. */
6938 if (!elfNN_aarch64_output_map_sym (&osi
, AARCH64_MAP_INSN
, 0))
6941 bfd_hash_traverse (&htab
->stub_hash_table
, aarch64_map_one_stub
,
6946 /* Finally, output mapping symbols for the PLT. */
6947 if (!htab
->root
.splt
|| htab
->root
.splt
->size
== 0)
6950 /* For now live without mapping symbols for the plt. */
6951 osi
.sec_shndx
= _bfd_elf_section_from_bfd_section
6952 (output_bfd
, htab
->root
.splt
->output_section
);
6953 osi
.sec
= htab
->root
.splt
;
6955 elf_link_hash_traverse (&htab
->root
, elfNN_aarch64_output_plt_map
,
6962 /* Allocate target specific section data. */
6965 elfNN_aarch64_new_section_hook (bfd
*abfd
, asection
*sec
)
6967 if (!sec
->used_by_bfd
)
6969 _aarch64_elf_section_data
*sdata
;
6970 bfd_size_type amt
= sizeof (*sdata
);
6972 sdata
= bfd_zalloc (abfd
, amt
);
6975 sec
->used_by_bfd
= sdata
;
6978 record_section_with_aarch64_elf_section_data (sec
);
6980 return _bfd_elf_new_section_hook (abfd
, sec
);
6985 unrecord_section_via_map_over_sections (bfd
*abfd ATTRIBUTE_UNUSED
,
6987 void *ignore ATTRIBUTE_UNUSED
)
6989 unrecord_section_with_aarch64_elf_section_data (sec
);
6993 elfNN_aarch64_close_and_cleanup (bfd
*abfd
)
6996 bfd_map_over_sections (abfd
,
6997 unrecord_section_via_map_over_sections
, NULL
);
6999 return _bfd_elf_close_and_cleanup (abfd
);
7003 elfNN_aarch64_bfd_free_cached_info (bfd
*abfd
)
7006 bfd_map_over_sections (abfd
,
7007 unrecord_section_via_map_over_sections
, NULL
);
7009 return _bfd_free_cached_info (abfd
);
7012 /* Create dynamic sections. This is different from the ARM backend in that
7013 the got, plt, gotplt and their relocation sections are all created in the
7014 standard part of the bfd elf backend. */
7017 elfNN_aarch64_create_dynamic_sections (bfd
*dynobj
,
7018 struct bfd_link_info
*info
)
7020 struct elf_aarch64_link_hash_table
*htab
;
7022 /* We need to create .got section. */
7023 if (!aarch64_elf_create_got_section (dynobj
, info
))
7026 if (!_bfd_elf_create_dynamic_sections (dynobj
, info
))
7029 htab
= elf_aarch64_hash_table (info
);
7030 htab
->sdynbss
= bfd_get_linker_section (dynobj
, ".dynbss");
7032 htab
->srelbss
= bfd_get_linker_section (dynobj
, ".rela.bss");
7034 if (!htab
->sdynbss
|| (!info
->shared
&& !htab
->srelbss
))
7041 /* Allocate space in .plt, .got and associated reloc sections for
7045 elfNN_aarch64_allocate_dynrelocs (struct elf_link_hash_entry
*h
, void *inf
)
7047 struct bfd_link_info
*info
;
7048 struct elf_aarch64_link_hash_table
*htab
;
7049 struct elf_aarch64_link_hash_entry
*eh
;
7050 struct elf_dyn_relocs
*p
;
7052 /* An example of a bfd_link_hash_indirect symbol is versioned
7053 symbol. For example: __gxx_personality_v0(bfd_link_hash_indirect)
7054 -> __gxx_personality_v0(bfd_link_hash_defined)
7056 There is no need to process bfd_link_hash_indirect symbols here
7057 because we will also be presented with the concrete instance of
7058 the symbol and elfNN_aarch64_copy_indirect_symbol () will have been
7059 called to copy all relevant data from the generic to the concrete
7062 if (h
->root
.type
== bfd_link_hash_indirect
)
7065 if (h
->root
.type
== bfd_link_hash_warning
)
7066 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
7068 info
= (struct bfd_link_info
*) inf
;
7069 htab
= elf_aarch64_hash_table (info
);
7071 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle it
7072 here if it is defined and referenced in a non-shared object. */
7073 if (h
->type
== STT_GNU_IFUNC
7076 else if (htab
->root
.dynamic_sections_created
&& h
->plt
.refcount
> 0)
7078 /* Make sure this symbol is output as a dynamic symbol.
7079 Undefined weak syms won't yet be marked as dynamic. */
7080 if (h
->dynindx
== -1 && !h
->forced_local
)
7082 if (!bfd_elf_link_record_dynamic_symbol (info
, h
))
7086 if (info
->shared
|| WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h
))
7088 asection
*s
= htab
->root
.splt
;
7090 /* If this is the first .plt entry, make room for the special
7093 s
->size
+= htab
->plt_header_size
;
7095 h
->plt
.offset
= s
->size
;
7097 /* If this symbol is not defined in a regular file, and we are
7098 not generating a shared library, then set the symbol to this
7099 location in the .plt. This is required to make function
7100 pointers compare as equal between the normal executable and
7101 the shared library. */
7102 if (!info
->shared
&& !h
->def_regular
)
7104 h
->root
.u
.def
.section
= s
;
7105 h
->root
.u
.def
.value
= h
->plt
.offset
;
7108 /* Make room for this entry. For now we only create the
7109 small model PLT entries. We later need to find a way
7110 of relaxing into these from the large model PLT entries. */
7111 s
->size
+= PLT_SMALL_ENTRY_SIZE
;
7113 /* We also need to make an entry in the .got.plt section, which
7114 will be placed in the .got section by the linker script. */
7115 htab
->root
.sgotplt
->size
+= GOT_ENTRY_SIZE
;
7117 /* We also need to make an entry in the .rela.plt section. */
7118 htab
->root
.srelplt
->size
+= RELOC_SIZE (htab
);
7120 /* We need to ensure that all GOT entries that serve the PLT
7121 are consecutive with the special GOT slots [0] [1] and
7122 [2]. Any addtional relocations, such as
7123 R_AARCH64_TLSDESC, must be placed after the PLT related
7124 entries. We abuse the reloc_count such that during
7125 sizing we adjust reloc_count to indicate the number of
7126 PLT related reserved entries. In subsequent phases when
7127 filling in the contents of the reloc entries, PLT related
7128 entries are placed by computing their PLT index (0
7129 .. reloc_count). While other none PLT relocs are placed
7130 at the slot indicated by reloc_count and reloc_count is
7133 htab
->root
.srelplt
->reloc_count
++;
7137 h
->plt
.offset
= (bfd_vma
) - 1;
7143 h
->plt
.offset
= (bfd_vma
) - 1;
7147 eh
= (struct elf_aarch64_link_hash_entry
*) h
;
7148 eh
->tlsdesc_got_jump_table_offset
= (bfd_vma
) - 1;
7150 if (h
->got
.refcount
> 0)
7153 unsigned got_type
= elf_aarch64_hash_entry (h
)->got_type
;
7155 h
->got
.offset
= (bfd_vma
) - 1;
7157 dyn
= htab
->root
.dynamic_sections_created
;
7159 /* Make sure this symbol is output as a dynamic symbol.
7160 Undefined weak syms won't yet be marked as dynamic. */
7161 if (dyn
&& h
->dynindx
== -1 && !h
->forced_local
)
7163 if (!bfd_elf_link_record_dynamic_symbol (info
, h
))
7167 if (got_type
== GOT_UNKNOWN
)
7170 else if (got_type
== GOT_NORMAL
)
7172 h
->got
.offset
= htab
->root
.sgot
->size
;
7173 htab
->root
.sgot
->size
+= GOT_ENTRY_SIZE
;
7174 if ((ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
7175 || h
->root
.type
!= bfd_link_hash_undefweak
)
7177 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, 0, h
)))
7179 htab
->root
.srelgot
->size
+= RELOC_SIZE (htab
);
7185 if (got_type
& GOT_TLSDESC_GD
)
7187 eh
->tlsdesc_got_jump_table_offset
=
7188 (htab
->root
.sgotplt
->size
7189 - aarch64_compute_jump_table_size (htab
));
7190 htab
->root
.sgotplt
->size
+= GOT_ENTRY_SIZE
* 2;
7191 h
->got
.offset
= (bfd_vma
) - 2;
7194 if (got_type
& GOT_TLS_GD
)
7196 h
->got
.offset
= htab
->root
.sgot
->size
;
7197 htab
->root
.sgot
->size
+= GOT_ENTRY_SIZE
* 2;
7200 if (got_type
& GOT_TLS_IE
)
7202 h
->got
.offset
= htab
->root
.sgot
->size
;
7203 htab
->root
.sgot
->size
+= GOT_ENTRY_SIZE
;
7206 indx
= h
&& h
->dynindx
!= -1 ? h
->dynindx
: 0;
7207 if ((ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
7208 || h
->root
.type
!= bfd_link_hash_undefweak
)
7211 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, 0, h
)))
7213 if (got_type
& GOT_TLSDESC_GD
)
7215 htab
->root
.srelplt
->size
+= RELOC_SIZE (htab
);
7216 /* Note reloc_count not incremented here! We have
7217 already adjusted reloc_count for this relocation
7220 /* TLSDESC PLT is now needed, but not yet determined. */
7221 htab
->tlsdesc_plt
= (bfd_vma
) - 1;
7224 if (got_type
& GOT_TLS_GD
)
7225 htab
->root
.srelgot
->size
+= RELOC_SIZE (htab
) * 2;
7227 if (got_type
& GOT_TLS_IE
)
7228 htab
->root
.srelgot
->size
+= RELOC_SIZE (htab
);
7234 h
->got
.offset
= (bfd_vma
) - 1;
7237 if (eh
->dyn_relocs
== NULL
)
7240 /* In the shared -Bsymbolic case, discard space allocated for
7241 dynamic pc-relative relocs against symbols which turn out to be
7242 defined in regular objects. For the normal shared case, discard
7243 space for pc-relative relocs that have become local due to symbol
7244 visibility changes. */
7248 /* Relocs that use pc_count are those that appear on a call
7249 insn, or certain REL relocs that can generated via assembly.
7250 We want calls to protected symbols to resolve directly to the
7251 function rather than going via the plt. If people want
7252 function pointer comparisons to work as expected then they
7253 should avoid writing weird assembly. */
7254 if (SYMBOL_CALLS_LOCAL (info
, h
))
7256 struct elf_dyn_relocs
**pp
;
7258 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
;)
7260 p
->count
-= p
->pc_count
;
7269 /* Also discard relocs on undefined weak syms with non-default
7271 if (eh
->dyn_relocs
!= NULL
&& h
->root
.type
== bfd_link_hash_undefweak
)
7273 if (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
)
7274 eh
->dyn_relocs
= NULL
;
7276 /* Make sure undefined weak symbols are output as a dynamic
7278 else if (h
->dynindx
== -1
7280 && !bfd_elf_link_record_dynamic_symbol (info
, h
))
7285 else if (ELIMINATE_COPY_RELOCS
)
7287 /* For the non-shared case, discard space for relocs against
7288 symbols which turn out to need copy relocs or are not
7294 || (htab
->root
.dynamic_sections_created
7295 && (h
->root
.type
== bfd_link_hash_undefweak
7296 || h
->root
.type
== bfd_link_hash_undefined
))))
7298 /* Make sure this symbol is output as a dynamic symbol.
7299 Undefined weak syms won't yet be marked as dynamic. */
7300 if (h
->dynindx
== -1
7302 && !bfd_elf_link_record_dynamic_symbol (info
, h
))
7305 /* If that succeeded, we know we'll be keeping all the
7307 if (h
->dynindx
!= -1)
7311 eh
->dyn_relocs
= NULL
;
7316 /* Finally, allocate space. */
7317 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
7321 sreloc
= elf_section_data (p
->sec
)->sreloc
;
7323 BFD_ASSERT (sreloc
!= NULL
);
7325 sreloc
->size
+= p
->count
* RELOC_SIZE (htab
);
7331 /* Allocate space in .plt, .got and associated reloc sections for
7332 ifunc dynamic relocs. */
7335 elfNN_aarch64_allocate_ifunc_dynrelocs (struct elf_link_hash_entry
*h
,
7338 struct bfd_link_info
*info
;
7339 struct elf_aarch64_link_hash_table
*htab
;
7340 struct elf_aarch64_link_hash_entry
*eh
;
7342 /* An example of a bfd_link_hash_indirect symbol is versioned
7343 symbol. For example: __gxx_personality_v0(bfd_link_hash_indirect)
7344 -> __gxx_personality_v0(bfd_link_hash_defined)
7346 There is no need to process bfd_link_hash_indirect symbols here
7347 because we will also be presented with the concrete instance of
7348 the symbol and elfNN_aarch64_copy_indirect_symbol () will have been
7349 called to copy all relevant data from the generic to the concrete
7352 if (h
->root
.type
== bfd_link_hash_indirect
)
7355 if (h
->root
.type
== bfd_link_hash_warning
)
7356 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
7358 info
= (struct bfd_link_info
*) inf
;
7359 htab
= elf_aarch64_hash_table (info
);
7361 eh
= (struct elf_aarch64_link_hash_entry
*) h
;
7363 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle it
7364 here if it is defined and referenced in a non-shared object. */
7365 if (h
->type
== STT_GNU_IFUNC
7367 return _bfd_elf_allocate_ifunc_dyn_relocs (info
, h
,
7369 htab
->plt_entry_size
,
7370 htab
->plt_header_size
,
7375 /* Allocate space in .plt, .got and associated reloc sections for
7376 local dynamic relocs. */
7379 elfNN_aarch64_allocate_local_dynrelocs (void **slot
, void *inf
)
7381 struct elf_link_hash_entry
*h
7382 = (struct elf_link_hash_entry
*) *slot
;
7384 if (h
->type
!= STT_GNU_IFUNC
7388 || h
->root
.type
!= bfd_link_hash_defined
)
7391 return elfNN_aarch64_allocate_dynrelocs (h
, inf
);
7394 /* Allocate space in .plt, .got and associated reloc sections for
7395 local ifunc dynamic relocs. */
7398 elfNN_aarch64_allocate_local_ifunc_dynrelocs (void **slot
, void *inf
)
7400 struct elf_link_hash_entry
*h
7401 = (struct elf_link_hash_entry
*) *slot
;
7403 if (h
->type
!= STT_GNU_IFUNC
7407 || h
->root
.type
!= bfd_link_hash_defined
)
7410 return elfNN_aarch64_allocate_ifunc_dynrelocs (h
, inf
);
7413 /* This is the most important function of all . Innocuosly named
7416 elfNN_aarch64_size_dynamic_sections (bfd
*output_bfd ATTRIBUTE_UNUSED
,
7417 struct bfd_link_info
*info
)
7419 struct elf_aarch64_link_hash_table
*htab
;
7425 htab
= elf_aarch64_hash_table ((info
));
7426 dynobj
= htab
->root
.dynobj
;
7428 BFD_ASSERT (dynobj
!= NULL
);
7430 if (htab
->root
.dynamic_sections_created
)
7432 if (info
->executable
)
7434 s
= bfd_get_linker_section (dynobj
, ".interp");
7437 s
->size
= sizeof ELF_DYNAMIC_INTERPRETER
;
7438 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
7442 /* Set up .got offsets for local syms, and space for local dynamic
7444 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
7446 struct elf_aarch64_local_symbol
*locals
= NULL
;
7447 Elf_Internal_Shdr
*symtab_hdr
;
7451 if (!is_aarch64_elf (ibfd
))
7454 for (s
= ibfd
->sections
; s
!= NULL
; s
= s
->next
)
7456 struct elf_dyn_relocs
*p
;
7458 for (p
= (struct elf_dyn_relocs
*)
7459 (elf_section_data (s
)->local_dynrel
); p
!= NULL
; p
= p
->next
)
7461 if (!bfd_is_abs_section (p
->sec
)
7462 && bfd_is_abs_section (p
->sec
->output_section
))
7464 /* Input section has been discarded, either because
7465 it is a copy of a linkonce section or due to
7466 linker script /DISCARD/, so we'll be discarding
7469 else if (p
->count
!= 0)
7471 srel
= elf_section_data (p
->sec
)->sreloc
;
7472 srel
->size
+= p
->count
* RELOC_SIZE (htab
);
7473 if ((p
->sec
->output_section
->flags
& SEC_READONLY
) != 0)
7474 info
->flags
|= DF_TEXTREL
;
7479 locals
= elf_aarch64_locals (ibfd
);
7483 symtab_hdr
= &elf_symtab_hdr (ibfd
);
7484 srel
= htab
->root
.srelgot
;
7485 for (i
= 0; i
< symtab_hdr
->sh_info
; i
++)
7487 locals
[i
].got_offset
= (bfd_vma
) - 1;
7488 locals
[i
].tlsdesc_got_jump_table_offset
= (bfd_vma
) - 1;
7489 if (locals
[i
].got_refcount
> 0)
7491 unsigned got_type
= locals
[i
].got_type
;
7492 if (got_type
& GOT_TLSDESC_GD
)
7494 locals
[i
].tlsdesc_got_jump_table_offset
=
7495 (htab
->root
.sgotplt
->size
7496 - aarch64_compute_jump_table_size (htab
));
7497 htab
->root
.sgotplt
->size
+= GOT_ENTRY_SIZE
* 2;
7498 locals
[i
].got_offset
= (bfd_vma
) - 2;
7501 if (got_type
& GOT_TLS_GD
)
7503 locals
[i
].got_offset
= htab
->root
.sgot
->size
;
7504 htab
->root
.sgot
->size
+= GOT_ENTRY_SIZE
* 2;
7507 if (got_type
& GOT_TLS_IE
)
7509 locals
[i
].got_offset
= htab
->root
.sgot
->size
;
7510 htab
->root
.sgot
->size
+= GOT_ENTRY_SIZE
;
7513 if (got_type
== GOT_UNKNOWN
)
7517 if (got_type
== GOT_NORMAL
)
7523 if (got_type
& GOT_TLSDESC_GD
)
7525 htab
->root
.srelplt
->size
+= RELOC_SIZE (htab
);
7526 /* Note RELOC_COUNT not incremented here! */
7527 htab
->tlsdesc_plt
= (bfd_vma
) - 1;
7530 if (got_type
& GOT_TLS_GD
)
7531 htab
->root
.srelgot
->size
+= RELOC_SIZE (htab
) * 2;
7533 if (got_type
& GOT_TLS_IE
)
7534 htab
->root
.srelgot
->size
+= RELOC_SIZE (htab
);
7539 locals
[i
].got_refcount
= (bfd_vma
) - 1;
7545 /* Allocate global sym .plt and .got entries, and space for global
7546 sym dynamic relocs. */
7547 elf_link_hash_traverse (&htab
->root
, elfNN_aarch64_allocate_dynrelocs
,
7550 /* Allocate global ifunc sym .plt and .got entries, and space for global
7551 ifunc sym dynamic relocs. */
7552 elf_link_hash_traverse (&htab
->root
, elfNN_aarch64_allocate_ifunc_dynrelocs
,
7555 /* Allocate .plt and .got entries, and space for local symbols. */
7556 htab_traverse (htab
->loc_hash_table
,
7557 elfNN_aarch64_allocate_local_dynrelocs
,
7560 /* Allocate .plt and .got entries, and space for local ifunc symbols. */
7561 htab_traverse (htab
->loc_hash_table
,
7562 elfNN_aarch64_allocate_local_ifunc_dynrelocs
,
7565 /* For every jump slot reserved in the sgotplt, reloc_count is
7566 incremented. However, when we reserve space for TLS descriptors,
7567 it's not incremented, so in order to compute the space reserved
7568 for them, it suffices to multiply the reloc count by the jump
7571 if (htab
->root
.srelplt
)
7572 htab
->sgotplt_jump_table_size
= aarch64_compute_jump_table_size (htab
);
7574 if (htab
->tlsdesc_plt
)
7576 if (htab
->root
.splt
->size
== 0)
7577 htab
->root
.splt
->size
+= PLT_ENTRY_SIZE
;
7579 htab
->tlsdesc_plt
= htab
->root
.splt
->size
;
7580 htab
->root
.splt
->size
+= PLT_TLSDESC_ENTRY_SIZE
;
7582 /* If we're not using lazy TLS relocations, don't generate the
7583 GOT entry required. */
7584 if (!(info
->flags
& DF_BIND_NOW
))
7586 htab
->dt_tlsdesc_got
= htab
->root
.sgot
->size
;
7587 htab
->root
.sgot
->size
+= GOT_ENTRY_SIZE
;
7591 /* Init mapping symbols information to use later to distingush between
7592 code and data while scanning for errata. */
7593 if (htab
->fix_erratum_835769
|| htab
->fix_erratum_843419
)
7594 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
7596 if (!is_aarch64_elf (ibfd
))
7598 bfd_elfNN_aarch64_init_maps (ibfd
);
7601 /* We now have determined the sizes of the various dynamic sections.
7602 Allocate memory for them. */
7604 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
7606 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
7609 if (s
== htab
->root
.splt
7610 || s
== htab
->root
.sgot
7611 || s
== htab
->root
.sgotplt
7612 || s
== htab
->root
.iplt
7613 || s
== htab
->root
.igotplt
|| s
== htab
->sdynbss
)
7615 /* Strip this section if we don't need it; see the
7618 else if (CONST_STRNEQ (bfd_get_section_name (dynobj
, s
), ".rela"))
7620 if (s
->size
!= 0 && s
!= htab
->root
.srelplt
)
7623 /* We use the reloc_count field as a counter if we need
7624 to copy relocs into the output file. */
7625 if (s
!= htab
->root
.srelplt
)
7630 /* It's not one of our sections, so don't allocate space. */
7636 /* If we don't need this section, strip it from the
7637 output file. This is mostly to handle .rela.bss and
7638 .rela.plt. We must create both sections in
7639 create_dynamic_sections, because they must be created
7640 before the linker maps input sections to output
7641 sections. The linker does that before
7642 adjust_dynamic_symbol is called, and it is that
7643 function which decides whether anything needs to go
7644 into these sections. */
7646 s
->flags
|= SEC_EXCLUDE
;
7650 if ((s
->flags
& SEC_HAS_CONTENTS
) == 0)
7653 /* Allocate memory for the section contents. We use bfd_zalloc
7654 here in case unused entries are not reclaimed before the
7655 section's contents are written out. This should not happen,
7656 but this way if it does, we get a R_AARCH64_NONE reloc instead
7658 s
->contents
= (bfd_byte
*) bfd_zalloc (dynobj
, s
->size
);
7659 if (s
->contents
== NULL
)
7663 if (htab
->root
.dynamic_sections_created
)
7665 /* Add some entries to the .dynamic section. We fill in the
7666 values later, in elfNN_aarch64_finish_dynamic_sections, but we
7667 must add the entries now so that we get the correct size for
7668 the .dynamic section. The DT_DEBUG entry is filled in by the
7669 dynamic linker and used by the debugger. */
7670 #define add_dynamic_entry(TAG, VAL) \
7671 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
7673 if (info
->executable
)
7675 if (!add_dynamic_entry (DT_DEBUG
, 0))
7679 if (htab
->root
.splt
->size
!= 0)
7681 if (!add_dynamic_entry (DT_PLTGOT
, 0)
7682 || !add_dynamic_entry (DT_PLTRELSZ
, 0)
7683 || !add_dynamic_entry (DT_PLTREL
, DT_RELA
)
7684 || !add_dynamic_entry (DT_JMPREL
, 0))
7687 if (htab
->tlsdesc_plt
7688 && (!add_dynamic_entry (DT_TLSDESC_PLT
, 0)
7689 || !add_dynamic_entry (DT_TLSDESC_GOT
, 0)))
7695 if (!add_dynamic_entry (DT_RELA
, 0)
7696 || !add_dynamic_entry (DT_RELASZ
, 0)
7697 || !add_dynamic_entry (DT_RELAENT
, RELOC_SIZE (htab
)))
7700 /* If any dynamic relocs apply to a read-only section,
7701 then we need a DT_TEXTREL entry. */
7702 if ((info
->flags
& DF_TEXTREL
) != 0)
7704 if (!add_dynamic_entry (DT_TEXTREL
, 0))
7709 #undef add_dynamic_entry
7715 elf_aarch64_update_plt_entry (bfd
*output_bfd
,
7716 bfd_reloc_code_real_type r_type
,
7717 bfd_byte
*plt_entry
, bfd_vma value
)
7719 reloc_howto_type
*howto
= elfNN_aarch64_howto_from_bfd_reloc (r_type
);
7721 _bfd_aarch64_elf_put_addend (output_bfd
, plt_entry
, r_type
, howto
, value
);
7725 elfNN_aarch64_create_small_pltn_entry (struct elf_link_hash_entry
*h
,
7726 struct elf_aarch64_link_hash_table
7727 *htab
, bfd
*output_bfd
,
7728 struct bfd_link_info
*info
)
7730 bfd_byte
*plt_entry
;
7733 bfd_vma gotplt_entry_address
;
7734 bfd_vma plt_entry_address
;
7735 Elf_Internal_Rela rela
;
7737 asection
*plt
, *gotplt
, *relplt
;
7739 /* When building a static executable, use .iplt, .igot.plt and
7740 .rela.iplt sections for STT_GNU_IFUNC symbols. */
7741 if (htab
->root
.splt
!= NULL
)
7743 plt
= htab
->root
.splt
;
7744 gotplt
= htab
->root
.sgotplt
;
7745 relplt
= htab
->root
.srelplt
;
7749 plt
= htab
->root
.iplt
;
7750 gotplt
= htab
->root
.igotplt
;
7751 relplt
= htab
->root
.irelplt
;
7754 /* Get the index in the procedure linkage table which
7755 corresponds to this symbol. This is the index of this symbol
7756 in all the symbols for which we are making plt entries. The
7757 first entry in the procedure linkage table is reserved.
7759 Get the offset into the .got table of the entry that
7760 corresponds to this function. Each .got entry is GOT_ENTRY_SIZE
7761 bytes. The first three are reserved for the dynamic linker.
7763 For static executables, we don't reserve anything. */
7765 if (plt
== htab
->root
.splt
)
7767 plt_index
= (h
->plt
.offset
- htab
->plt_header_size
) / htab
->plt_entry_size
;
7768 got_offset
= (plt_index
+ 3) * GOT_ENTRY_SIZE
;
7772 plt_index
= h
->plt
.offset
/ htab
->plt_entry_size
;
7773 got_offset
= plt_index
* GOT_ENTRY_SIZE
;
7776 plt_entry
= plt
->contents
+ h
->plt
.offset
;
7777 plt_entry_address
= plt
->output_section
->vma
7778 + plt
->output_offset
+ h
->plt
.offset
;
7779 gotplt_entry_address
= gotplt
->output_section
->vma
+
7780 gotplt
->output_offset
+ got_offset
;
7782 /* Copy in the boiler-plate for the PLTn entry. */
7783 memcpy (plt_entry
, elfNN_aarch64_small_plt_entry
, PLT_SMALL_ENTRY_SIZE
);
7785 /* Fill in the top 21 bits for this: ADRP x16, PLT_GOT + n * 8.
7786 ADRP: ((PG(S+A)-PG(P)) >> 12) & 0x1fffff */
7787 elf_aarch64_update_plt_entry (output_bfd
, BFD_RELOC_AARCH64_ADR_HI21_PCREL
,
7789 PG (gotplt_entry_address
) -
7790 PG (plt_entry_address
));
7792 /* Fill in the lo12 bits for the load from the pltgot. */
7793 elf_aarch64_update_plt_entry (output_bfd
, BFD_RELOC_AARCH64_LDSTNN_LO12
,
7795 PG_OFFSET (gotplt_entry_address
));
7797 /* Fill in the lo12 bits for the add from the pltgot entry. */
7798 elf_aarch64_update_plt_entry (output_bfd
, BFD_RELOC_AARCH64_ADD_LO12
,
7800 PG_OFFSET (gotplt_entry_address
));
7802 /* All the GOTPLT Entries are essentially initialized to PLT0. */
7803 bfd_put_NN (output_bfd
,
7804 plt
->output_section
->vma
+ plt
->output_offset
,
7805 gotplt
->contents
+ got_offset
);
7807 rela
.r_offset
= gotplt_entry_address
;
7809 if (h
->dynindx
== -1
7810 || ((info
->executable
7811 || ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
)
7813 && h
->type
== STT_GNU_IFUNC
))
7815 /* If an STT_GNU_IFUNC symbol is locally defined, generate
7816 R_AARCH64_IRELATIVE instead of R_AARCH64_JUMP_SLOT. */
7817 rela
.r_info
= ELFNN_R_INFO (0, AARCH64_R (IRELATIVE
));
7818 rela
.r_addend
= (h
->root
.u
.def
.value
7819 + h
->root
.u
.def
.section
->output_section
->vma
7820 + h
->root
.u
.def
.section
->output_offset
);
7824 /* Fill in the entry in the .rela.plt section. */
7825 rela
.r_info
= ELFNN_R_INFO (h
->dynindx
, AARCH64_R (JUMP_SLOT
));
7829 /* Compute the relocation entry to used based on PLT index and do
7830 not adjust reloc_count. The reloc_count has already been adjusted
7831 to account for this entry. */
7832 loc
= relplt
->contents
+ plt_index
* RELOC_SIZE (htab
);
7833 bfd_elfNN_swap_reloca_out (output_bfd
, &rela
, loc
);
7836 /* Size sections even though they're not dynamic. We use it to setup
7837 _TLS_MODULE_BASE_, if needed. */
7840 elfNN_aarch64_always_size_sections (bfd
*output_bfd
,
7841 struct bfd_link_info
*info
)
7845 if (info
->relocatable
)
7848 tls_sec
= elf_hash_table (info
)->tls_sec
;
7852 struct elf_link_hash_entry
*tlsbase
;
7854 tlsbase
= elf_link_hash_lookup (elf_hash_table (info
),
7855 "_TLS_MODULE_BASE_", TRUE
, TRUE
, FALSE
);
7859 struct bfd_link_hash_entry
*h
= NULL
;
7860 const struct elf_backend_data
*bed
=
7861 get_elf_backend_data (output_bfd
);
7863 if (!(_bfd_generic_link_add_one_symbol
7864 (info
, output_bfd
, "_TLS_MODULE_BASE_", BSF_LOCAL
,
7865 tls_sec
, 0, NULL
, FALSE
, bed
->collect
, &h
)))
7868 tlsbase
->type
= STT_TLS
;
7869 tlsbase
= (struct elf_link_hash_entry
*) h
;
7870 tlsbase
->def_regular
= 1;
7871 tlsbase
->other
= STV_HIDDEN
;
7872 (*bed
->elf_backend_hide_symbol
) (info
, tlsbase
, TRUE
);
7879 /* Finish up dynamic symbol handling. We set the contents of various
7880 dynamic sections here. */
7882 elfNN_aarch64_finish_dynamic_symbol (bfd
*output_bfd
,
7883 struct bfd_link_info
*info
,
7884 struct elf_link_hash_entry
*h
,
7885 Elf_Internal_Sym
*sym
)
7887 struct elf_aarch64_link_hash_table
*htab
;
7888 htab
= elf_aarch64_hash_table (info
);
7890 if (h
->plt
.offset
!= (bfd_vma
) - 1)
7892 asection
*plt
, *gotplt
, *relplt
;
7894 /* This symbol has an entry in the procedure linkage table. Set
7897 /* When building a static executable, use .iplt, .igot.plt and
7898 .rela.iplt sections for STT_GNU_IFUNC symbols. */
7899 if (htab
->root
.splt
!= NULL
)
7901 plt
= htab
->root
.splt
;
7902 gotplt
= htab
->root
.sgotplt
;
7903 relplt
= htab
->root
.srelplt
;
7907 plt
= htab
->root
.iplt
;
7908 gotplt
= htab
->root
.igotplt
;
7909 relplt
= htab
->root
.irelplt
;
7912 /* This symbol has an entry in the procedure linkage table. Set
7914 if ((h
->dynindx
== -1
7915 && !((h
->forced_local
|| info
->executable
)
7917 && h
->type
== STT_GNU_IFUNC
))
7923 elfNN_aarch64_create_small_pltn_entry (h
, htab
, output_bfd
, info
);
7924 if (!h
->def_regular
)
7926 /* Mark the symbol as undefined, rather than as defined in
7927 the .plt section. */
7928 sym
->st_shndx
= SHN_UNDEF
;
7929 /* If the symbol is weak we need to clear the value.
7930 Otherwise, the PLT entry would provide a definition for
7931 the symbol even if the symbol wasn't defined anywhere,
7932 and so the symbol would never be NULL. Leave the value if
7933 there were any relocations where pointer equality matters
7934 (this is a clue for the dynamic linker, to make function
7935 pointer comparisons work between an application and shared
7937 if (!h
->ref_regular_nonweak
|| !h
->pointer_equality_needed
)
7942 if (h
->got
.offset
!= (bfd_vma
) - 1
7943 && elf_aarch64_hash_entry (h
)->got_type
== GOT_NORMAL
)
7945 Elf_Internal_Rela rela
;
7948 /* This symbol has an entry in the global offset table. Set it
7950 if (htab
->root
.sgot
== NULL
|| htab
->root
.srelgot
== NULL
)
7953 rela
.r_offset
= (htab
->root
.sgot
->output_section
->vma
7954 + htab
->root
.sgot
->output_offset
7955 + (h
->got
.offset
& ~(bfd_vma
) 1));
7958 && h
->type
== STT_GNU_IFUNC
)
7962 /* Generate R_AARCH64_GLOB_DAT. */
7969 if (!h
->pointer_equality_needed
)
7972 /* For non-shared object, we can't use .got.plt, which
7973 contains the real function address if we need pointer
7974 equality. We load the GOT entry with the PLT entry. */
7975 plt
= htab
->root
.splt
? htab
->root
.splt
: htab
->root
.iplt
;
7976 bfd_put_NN (output_bfd
, (plt
->output_section
->vma
7977 + plt
->output_offset
7979 htab
->root
.sgot
->contents
7980 + (h
->got
.offset
& ~(bfd_vma
) 1));
7984 else if (info
->shared
&& SYMBOL_REFERENCES_LOCAL (info
, h
))
7986 if (!h
->def_regular
)
7989 BFD_ASSERT ((h
->got
.offset
& 1) != 0);
7990 rela
.r_info
= ELFNN_R_INFO (0, AARCH64_R (RELATIVE
));
7991 rela
.r_addend
= (h
->root
.u
.def
.value
7992 + h
->root
.u
.def
.section
->output_section
->vma
7993 + h
->root
.u
.def
.section
->output_offset
);
7998 BFD_ASSERT ((h
->got
.offset
& 1) == 0);
7999 bfd_put_NN (output_bfd
, (bfd_vma
) 0,
8000 htab
->root
.sgot
->contents
+ h
->got
.offset
);
8001 rela
.r_info
= ELFNN_R_INFO (h
->dynindx
, AARCH64_R (GLOB_DAT
));
8005 loc
= htab
->root
.srelgot
->contents
;
8006 loc
+= htab
->root
.srelgot
->reloc_count
++ * RELOC_SIZE (htab
);
8007 bfd_elfNN_swap_reloca_out (output_bfd
, &rela
, loc
);
8012 Elf_Internal_Rela rela
;
8015 /* This symbol needs a copy reloc. Set it up. */
8017 if (h
->dynindx
== -1
8018 || (h
->root
.type
!= bfd_link_hash_defined
8019 && h
->root
.type
!= bfd_link_hash_defweak
)
8020 || htab
->srelbss
== NULL
)
8023 rela
.r_offset
= (h
->root
.u
.def
.value
8024 + h
->root
.u
.def
.section
->output_section
->vma
8025 + h
->root
.u
.def
.section
->output_offset
);
8026 rela
.r_info
= ELFNN_R_INFO (h
->dynindx
, AARCH64_R (COPY
));
8028 loc
= htab
->srelbss
->contents
;
8029 loc
+= htab
->srelbss
->reloc_count
++ * RELOC_SIZE (htab
);
8030 bfd_elfNN_swap_reloca_out (output_bfd
, &rela
, loc
);
8033 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. SYM may
8034 be NULL for local symbols. */
8036 && (h
== elf_hash_table (info
)->hdynamic
8037 || h
== elf_hash_table (info
)->hgot
))
8038 sym
->st_shndx
= SHN_ABS
;
8043 /* Finish up local dynamic symbol handling. We set the contents of
8044 various dynamic sections here. */
8047 elfNN_aarch64_finish_local_dynamic_symbol (void **slot
, void *inf
)
8049 struct elf_link_hash_entry
*h
8050 = (struct elf_link_hash_entry
*) *slot
;
8051 struct bfd_link_info
*info
8052 = (struct bfd_link_info
*) inf
;
8054 return elfNN_aarch64_finish_dynamic_symbol (info
->output_bfd
,
8059 elfNN_aarch64_init_small_plt0_entry (bfd
*output_bfd ATTRIBUTE_UNUSED
,
8060 struct elf_aarch64_link_hash_table
8063 /* Fill in PLT0. Fixme:RR Note this doesn't distinguish between
8064 small and large plts and at the minute just generates
8067 /* PLT0 of the small PLT looks like this in ELF64 -
8068 stp x16, x30, [sp, #-16]! // Save the reloc and lr on stack.
8069 adrp x16, PLT_GOT + 16 // Get the page base of the GOTPLT
8070 ldr x17, [x16, #:lo12:PLT_GOT+16] // Load the address of the
8072 add x16, x16, #:lo12:PLT_GOT+16 // Load the lo12 bits of the
8073 // GOTPLT entry for this.
8075 PLT0 will be slightly different in ELF32 due to different got entry
8078 bfd_vma plt_got_2nd_ent
; /* Address of GOT[2]. */
8082 memcpy (htab
->root
.splt
->contents
, elfNN_aarch64_small_plt0_entry
,
8084 elf_section_data (htab
->root
.splt
->output_section
)->this_hdr
.sh_entsize
=
8087 plt_got_2nd_ent
= (htab
->root
.sgotplt
->output_section
->vma
8088 + htab
->root
.sgotplt
->output_offset
8089 + GOT_ENTRY_SIZE
* 2);
8091 plt_base
= htab
->root
.splt
->output_section
->vma
+
8092 htab
->root
.splt
->output_offset
;
8094 /* Fill in the top 21 bits for this: ADRP x16, PLT_GOT + n * 8.
8095 ADRP: ((PG(S+A)-PG(P)) >> 12) & 0x1fffff */
8096 elf_aarch64_update_plt_entry (output_bfd
, BFD_RELOC_AARCH64_ADR_HI21_PCREL
,
8097 htab
->root
.splt
->contents
+ 4,
8098 PG (plt_got_2nd_ent
) - PG (plt_base
+ 4));
8100 elf_aarch64_update_plt_entry (output_bfd
, BFD_RELOC_AARCH64_LDSTNN_LO12
,
8101 htab
->root
.splt
->contents
+ 8,
8102 PG_OFFSET (plt_got_2nd_ent
));
8104 elf_aarch64_update_plt_entry (output_bfd
, BFD_RELOC_AARCH64_ADD_LO12
,
8105 htab
->root
.splt
->contents
+ 12,
8106 PG_OFFSET (plt_got_2nd_ent
));
8110 elfNN_aarch64_finish_dynamic_sections (bfd
*output_bfd
,
8111 struct bfd_link_info
*info
)
8113 struct elf_aarch64_link_hash_table
*htab
;
8117 htab
= elf_aarch64_hash_table (info
);
8118 dynobj
= htab
->root
.dynobj
;
8119 sdyn
= bfd_get_linker_section (dynobj
, ".dynamic");
8121 if (htab
->root
.dynamic_sections_created
)
8123 ElfNN_External_Dyn
*dyncon
, *dynconend
;
8125 if (sdyn
== NULL
|| htab
->root
.sgot
== NULL
)
8128 dyncon
= (ElfNN_External_Dyn
*) sdyn
->contents
;
8129 dynconend
= (ElfNN_External_Dyn
*) (sdyn
->contents
+ sdyn
->size
);
8130 for (; dyncon
< dynconend
; dyncon
++)
8132 Elf_Internal_Dyn dyn
;
8135 bfd_elfNN_swap_dyn_in (dynobj
, dyncon
, &dyn
);
8143 s
= htab
->root
.sgotplt
;
8144 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
8148 dyn
.d_un
.d_ptr
= htab
->root
.srelplt
->output_section
->vma
;
8152 s
= htab
->root
.srelplt
;
8153 dyn
.d_un
.d_val
= s
->size
;
8157 /* The procedure linkage table relocs (DT_JMPREL) should
8158 not be included in the overall relocs (DT_RELA).
8159 Therefore, we override the DT_RELASZ entry here to
8160 make it not include the JMPREL relocs. Since the
8161 linker script arranges for .rela.plt to follow all
8162 other relocation sections, we don't have to worry
8163 about changing the DT_RELA entry. */
8164 if (htab
->root
.srelplt
!= NULL
)
8166 s
= htab
->root
.srelplt
;
8167 dyn
.d_un
.d_val
-= s
->size
;
8171 case DT_TLSDESC_PLT
:
8172 s
= htab
->root
.splt
;
8173 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
8174 + htab
->tlsdesc_plt
;
8177 case DT_TLSDESC_GOT
:
8178 s
= htab
->root
.sgot
;
8179 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
8180 + htab
->dt_tlsdesc_got
;
8184 bfd_elfNN_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
8189 /* Fill in the special first entry in the procedure linkage table. */
8190 if (htab
->root
.splt
&& htab
->root
.splt
->size
> 0)
8192 elfNN_aarch64_init_small_plt0_entry (output_bfd
, htab
);
8194 elf_section_data (htab
->root
.splt
->output_section
)->
8195 this_hdr
.sh_entsize
= htab
->plt_entry_size
;
8198 if (htab
->tlsdesc_plt
)
8200 bfd_put_NN (output_bfd
, (bfd_vma
) 0,
8201 htab
->root
.sgot
->contents
+ htab
->dt_tlsdesc_got
);
8203 memcpy (htab
->root
.splt
->contents
+ htab
->tlsdesc_plt
,
8204 elfNN_aarch64_tlsdesc_small_plt_entry
,
8205 sizeof (elfNN_aarch64_tlsdesc_small_plt_entry
));
8208 bfd_vma adrp1_addr
=
8209 htab
->root
.splt
->output_section
->vma
8210 + htab
->root
.splt
->output_offset
+ htab
->tlsdesc_plt
+ 4;
8212 bfd_vma adrp2_addr
= adrp1_addr
+ 4;
8215 htab
->root
.sgot
->output_section
->vma
8216 + htab
->root
.sgot
->output_offset
;
8218 bfd_vma pltgot_addr
=
8219 htab
->root
.sgotplt
->output_section
->vma
8220 + htab
->root
.sgotplt
->output_offset
;
8222 bfd_vma dt_tlsdesc_got
= got_addr
+ htab
->dt_tlsdesc_got
;
8224 bfd_byte
*plt_entry
=
8225 htab
->root
.splt
->contents
+ htab
->tlsdesc_plt
;
8227 /* adrp x2, DT_TLSDESC_GOT */
8228 elf_aarch64_update_plt_entry (output_bfd
,
8229 BFD_RELOC_AARCH64_ADR_HI21_PCREL
,
8231 (PG (dt_tlsdesc_got
)
8232 - PG (adrp1_addr
)));
8235 elf_aarch64_update_plt_entry (output_bfd
,
8236 BFD_RELOC_AARCH64_ADR_HI21_PCREL
,
8239 - PG (adrp2_addr
)));
8241 /* ldr x2, [x2, #0] */
8242 elf_aarch64_update_plt_entry (output_bfd
,
8243 BFD_RELOC_AARCH64_LDSTNN_LO12
,
8245 PG_OFFSET (dt_tlsdesc_got
));
8248 elf_aarch64_update_plt_entry (output_bfd
,
8249 BFD_RELOC_AARCH64_ADD_LO12
,
8251 PG_OFFSET (pltgot_addr
));
8256 if (htab
->root
.sgotplt
)
8258 if (bfd_is_abs_section (htab
->root
.sgotplt
->output_section
))
8260 (*_bfd_error_handler
)
8261 (_("discarded output section: `%A'"), htab
->root
.sgotplt
);
8265 /* Fill in the first three entries in the global offset table. */
8266 if (htab
->root
.sgotplt
->size
> 0)
8268 bfd_put_NN (output_bfd
, (bfd_vma
) 0, htab
->root
.sgotplt
->contents
);
8270 /* Write GOT[1] and GOT[2], needed for the dynamic linker. */
8271 bfd_put_NN (output_bfd
,
8273 htab
->root
.sgotplt
->contents
+ GOT_ENTRY_SIZE
);
8274 bfd_put_NN (output_bfd
,
8276 htab
->root
.sgotplt
->contents
+ GOT_ENTRY_SIZE
* 2);
8279 if (htab
->root
.sgot
)
8281 if (htab
->root
.sgot
->size
> 0)
8284 sdyn
? sdyn
->output_section
->vma
+ sdyn
->output_offset
: 0;
8285 bfd_put_NN (output_bfd
, addr
, htab
->root
.sgot
->contents
);
8289 elf_section_data (htab
->root
.sgotplt
->output_section
)->
8290 this_hdr
.sh_entsize
= GOT_ENTRY_SIZE
;
8293 if (htab
->root
.sgot
&& htab
->root
.sgot
->size
> 0)
8294 elf_section_data (htab
->root
.sgot
->output_section
)->this_hdr
.sh_entsize
8297 /* Fill PLT and GOT entries for local STT_GNU_IFUNC symbols. */
8298 htab_traverse (htab
->loc_hash_table
,
8299 elfNN_aarch64_finish_local_dynamic_symbol
,
8305 /* Return address for Ith PLT stub in section PLT, for relocation REL
8306 or (bfd_vma) -1 if it should not be included. */
8309 elfNN_aarch64_plt_sym_val (bfd_vma i
, const asection
*plt
,
8310 const arelent
*rel ATTRIBUTE_UNUSED
)
8312 return plt
->vma
+ PLT_ENTRY_SIZE
+ i
* PLT_SMALL_ENTRY_SIZE
;
8316 /* We use this so we can override certain functions
8317 (though currently we don't). */
8319 const struct elf_size_info elfNN_aarch64_size_info
=
8321 sizeof (ElfNN_External_Ehdr
),
8322 sizeof (ElfNN_External_Phdr
),
8323 sizeof (ElfNN_External_Shdr
),
8324 sizeof (ElfNN_External_Rel
),
8325 sizeof (ElfNN_External_Rela
),
8326 sizeof (ElfNN_External_Sym
),
8327 sizeof (ElfNN_External_Dyn
),
8328 sizeof (Elf_External_Note
),
8329 4, /* Hash table entry size. */
8330 1, /* Internal relocs per external relocs. */
8331 ARCH_SIZE
, /* Arch size. */
8332 LOG_FILE_ALIGN
, /* Log_file_align. */
8333 ELFCLASSNN
, EV_CURRENT
,
8334 bfd_elfNN_write_out_phdrs
,
8335 bfd_elfNN_write_shdrs_and_ehdr
,
8336 bfd_elfNN_checksum_contents
,
8337 bfd_elfNN_write_relocs
,
8338 bfd_elfNN_swap_symbol_in
,
8339 bfd_elfNN_swap_symbol_out
,
8340 bfd_elfNN_slurp_reloc_table
,
8341 bfd_elfNN_slurp_symbol_table
,
8342 bfd_elfNN_swap_dyn_in
,
8343 bfd_elfNN_swap_dyn_out
,
8344 bfd_elfNN_swap_reloc_in
,
8345 bfd_elfNN_swap_reloc_out
,
8346 bfd_elfNN_swap_reloca_in
,
8347 bfd_elfNN_swap_reloca_out
8350 #define ELF_ARCH bfd_arch_aarch64
8351 #define ELF_MACHINE_CODE EM_AARCH64
8352 #define ELF_MAXPAGESIZE 0x10000
8353 #define ELF_MINPAGESIZE 0x1000
8354 #define ELF_COMMONPAGESIZE 0x1000
8356 #define bfd_elfNN_close_and_cleanup \
8357 elfNN_aarch64_close_and_cleanup
8359 #define bfd_elfNN_bfd_free_cached_info \
8360 elfNN_aarch64_bfd_free_cached_info
8362 #define bfd_elfNN_bfd_is_target_special_symbol \
8363 elfNN_aarch64_is_target_special_symbol
8365 #define bfd_elfNN_bfd_link_hash_table_create \
8366 elfNN_aarch64_link_hash_table_create
8368 #define bfd_elfNN_bfd_merge_private_bfd_data \
8369 elfNN_aarch64_merge_private_bfd_data
8371 #define bfd_elfNN_bfd_print_private_bfd_data \
8372 elfNN_aarch64_print_private_bfd_data
8374 #define bfd_elfNN_bfd_reloc_type_lookup \
8375 elfNN_aarch64_reloc_type_lookup
8377 #define bfd_elfNN_bfd_reloc_name_lookup \
8378 elfNN_aarch64_reloc_name_lookup
8380 #define bfd_elfNN_bfd_set_private_flags \
8381 elfNN_aarch64_set_private_flags
8383 #define bfd_elfNN_find_inliner_info \
8384 elfNN_aarch64_find_inliner_info
8386 #define bfd_elfNN_find_nearest_line \
8387 elfNN_aarch64_find_nearest_line
8389 #define bfd_elfNN_mkobject \
8390 elfNN_aarch64_mkobject
8392 #define bfd_elfNN_new_section_hook \
8393 elfNN_aarch64_new_section_hook
8395 #define elf_backend_adjust_dynamic_symbol \
8396 elfNN_aarch64_adjust_dynamic_symbol
8398 #define elf_backend_always_size_sections \
8399 elfNN_aarch64_always_size_sections
8401 #define elf_backend_check_relocs \
8402 elfNN_aarch64_check_relocs
8404 #define elf_backend_copy_indirect_symbol \
8405 elfNN_aarch64_copy_indirect_symbol
8407 /* Create .dynbss, and .rela.bss sections in DYNOBJ, and set up shortcuts
8408 to them in our hash. */
8409 #define elf_backend_create_dynamic_sections \
8410 elfNN_aarch64_create_dynamic_sections
8412 #define elf_backend_init_index_section \
8413 _bfd_elf_init_2_index_sections
8415 #define elf_backend_finish_dynamic_sections \
8416 elfNN_aarch64_finish_dynamic_sections
8418 #define elf_backend_finish_dynamic_symbol \
8419 elfNN_aarch64_finish_dynamic_symbol
8421 #define elf_backend_gc_sweep_hook \
8422 elfNN_aarch64_gc_sweep_hook
8424 #define elf_backend_object_p \
8425 elfNN_aarch64_object_p
8427 #define elf_backend_output_arch_local_syms \
8428 elfNN_aarch64_output_arch_local_syms
8430 #define elf_backend_plt_sym_val \
8431 elfNN_aarch64_plt_sym_val
8433 #define elf_backend_post_process_headers \
8434 elfNN_aarch64_post_process_headers
8436 #define elf_backend_relocate_section \
8437 elfNN_aarch64_relocate_section
8439 #define elf_backend_reloc_type_class \
8440 elfNN_aarch64_reloc_type_class
8442 #define elf_backend_section_from_shdr \
8443 elfNN_aarch64_section_from_shdr
8445 #define elf_backend_size_dynamic_sections \
8446 elfNN_aarch64_size_dynamic_sections
8448 #define elf_backend_size_info \
8449 elfNN_aarch64_size_info
8451 #define elf_backend_write_section \
8452 elfNN_aarch64_write_section
8454 #define elf_backend_can_refcount 1
8455 #define elf_backend_can_gc_sections 1
8456 #define elf_backend_plt_readonly 1
8457 #define elf_backend_want_got_plt 1
8458 #define elf_backend_want_plt_sym 0
8459 #define elf_backend_may_use_rel_p 0
8460 #define elf_backend_may_use_rela_p 1
8461 #define elf_backend_default_use_rela_p 1
8462 #define elf_backend_rela_normal 1
8463 #define elf_backend_got_header_size (GOT_ENTRY_SIZE * 3)
8464 #define elf_backend_default_execstack 0
8466 #undef elf_backend_obj_attrs_section
8467 #define elf_backend_obj_attrs_section ".ARM.attributes"
8469 #include "elfNN-target.h"