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 /* LD64: GOT offset to the page address of GOT table.
852 (G(S) - PAGE (_GLOBAL_OFFSET_TABLE_)) & 0x7ff8. */
853 HOWTO64 (AARCH64_R (LD64_GOTPAGE_LO15
), /* type */
855 2, /* size (0 = byte, 1 = short, 2 = long) */
857 FALSE
, /* pc_relative */
859 complain_overflow_unsigned
, /* complain_on_overflow */
860 bfd_elf_generic_reloc
, /* special_function */
861 AARCH64_R_STR (LD64_GOTPAGE_LO15
), /* name */
862 FALSE
, /* partial_inplace */
863 0x7ff8, /* src_mask */
864 0x7ff8, /* dst_mask */
865 FALSE
), /* pcrel_offset */
867 /* Get to the page for the GOT entry for the symbol
868 (G(S) - P) using an ADRP instruction. */
869 HOWTO (AARCH64_R (TLSGD_ADR_PAGE21
), /* type */
871 2, /* size (0 = byte, 1 = short, 2 = long) */
873 TRUE
, /* pc_relative */
875 complain_overflow_dont
, /* complain_on_overflow */
876 bfd_elf_generic_reloc
, /* special_function */
877 AARCH64_R_STR (TLSGD_ADR_PAGE21
), /* name */
878 FALSE
, /* partial_inplace */
879 0x1fffff, /* src_mask */
880 0x1fffff, /* dst_mask */
881 TRUE
), /* pcrel_offset */
883 HOWTO (AARCH64_R (TLSGD_ADR_PREL21
), /* type */
885 2, /* size (0 = byte, 1 = short, 2 = long) */
887 TRUE
, /* pc_relative */
889 complain_overflow_dont
, /* complain_on_overflow */
890 bfd_elf_generic_reloc
, /* special_function */
891 AARCH64_R_STR (TLSGD_ADR_PREL21
), /* name */
892 FALSE
, /* partial_inplace */
893 0x1fffff, /* src_mask */
894 0x1fffff, /* dst_mask */
895 TRUE
), /* pcrel_offset */
897 /* ADD: GOT offset G(S) & 0xff8 [no overflow check] */
898 HOWTO (AARCH64_R (TLSGD_ADD_LO12_NC
), /* type */
900 2, /* size (0 = byte, 1 = short, 2 = long) */
902 FALSE
, /* pc_relative */
904 complain_overflow_dont
, /* complain_on_overflow */
905 bfd_elf_generic_reloc
, /* special_function */
906 AARCH64_R_STR (TLSGD_ADD_LO12_NC
), /* name */
907 FALSE
, /* partial_inplace */
908 0xfff, /* src_mask */
909 0xfff, /* dst_mask */
910 FALSE
), /* pcrel_offset */
912 HOWTO64 (AARCH64_R (TLSIE_MOVW_GOTTPREL_G1
), /* type */
914 2, /* size (0 = byte, 1 = short, 2 = long) */
916 FALSE
, /* pc_relative */
918 complain_overflow_dont
, /* complain_on_overflow */
919 bfd_elf_generic_reloc
, /* special_function */
920 AARCH64_R_STR (TLSIE_MOVW_GOTTPREL_G1
), /* name */
921 FALSE
, /* partial_inplace */
922 0xffff, /* src_mask */
923 0xffff, /* dst_mask */
924 FALSE
), /* pcrel_offset */
926 HOWTO64 (AARCH64_R (TLSIE_MOVW_GOTTPREL_G0_NC
), /* type */
928 2, /* size (0 = byte, 1 = short, 2 = long) */
930 FALSE
, /* pc_relative */
932 complain_overflow_dont
, /* complain_on_overflow */
933 bfd_elf_generic_reloc
, /* special_function */
934 AARCH64_R_STR (TLSIE_MOVW_GOTTPREL_G0_NC
), /* name */
935 FALSE
, /* partial_inplace */
936 0xffff, /* src_mask */
937 0xffff, /* dst_mask */
938 FALSE
), /* pcrel_offset */
940 HOWTO (AARCH64_R (TLSIE_ADR_GOTTPREL_PAGE21
), /* type */
942 2, /* size (0 = byte, 1 = short, 2 = long) */
944 FALSE
, /* pc_relative */
946 complain_overflow_dont
, /* complain_on_overflow */
947 bfd_elf_generic_reloc
, /* special_function */
948 AARCH64_R_STR (TLSIE_ADR_GOTTPREL_PAGE21
), /* name */
949 FALSE
, /* partial_inplace */
950 0x1fffff, /* src_mask */
951 0x1fffff, /* dst_mask */
952 FALSE
), /* pcrel_offset */
954 HOWTO64 (AARCH64_R (TLSIE_LD64_GOTTPREL_LO12_NC
), /* type */
956 2, /* size (0 = byte, 1 = short, 2 = long) */
958 FALSE
, /* pc_relative */
960 complain_overflow_dont
, /* complain_on_overflow */
961 bfd_elf_generic_reloc
, /* special_function */
962 AARCH64_R_STR (TLSIE_LD64_GOTTPREL_LO12_NC
), /* name */
963 FALSE
, /* partial_inplace */
964 0xff8, /* src_mask */
965 0xff8, /* dst_mask */
966 FALSE
), /* pcrel_offset */
968 HOWTO32 (AARCH64_R (TLSIE_LD32_GOTTPREL_LO12_NC
), /* type */
970 2, /* size (0 = byte, 1 = short, 2 = long) */
972 FALSE
, /* pc_relative */
974 complain_overflow_dont
, /* complain_on_overflow */
975 bfd_elf_generic_reloc
, /* special_function */
976 AARCH64_R_STR (TLSIE_LD32_GOTTPREL_LO12_NC
), /* name */
977 FALSE
, /* partial_inplace */
978 0xffc, /* src_mask */
979 0xffc, /* dst_mask */
980 FALSE
), /* pcrel_offset */
982 HOWTO (AARCH64_R (TLSIE_LD_GOTTPREL_PREL19
), /* type */
984 2, /* size (0 = byte, 1 = short, 2 = long) */
986 FALSE
, /* pc_relative */
988 complain_overflow_dont
, /* complain_on_overflow */
989 bfd_elf_generic_reloc
, /* special_function */
990 AARCH64_R_STR (TLSIE_LD_GOTTPREL_PREL19
), /* name */
991 FALSE
, /* partial_inplace */
992 0x1ffffc, /* src_mask */
993 0x1ffffc, /* dst_mask */
994 FALSE
), /* pcrel_offset */
996 HOWTO64 (AARCH64_R (TLSLE_MOVW_TPREL_G2
), /* type */
998 2, /* size (0 = byte, 1 = short, 2 = long) */
1000 FALSE
, /* pc_relative */
1002 complain_overflow_unsigned
, /* complain_on_overflow */
1003 bfd_elf_generic_reloc
, /* special_function */
1004 AARCH64_R_STR (TLSLE_MOVW_TPREL_G2
), /* name */
1005 FALSE
, /* partial_inplace */
1006 0xffff, /* src_mask */
1007 0xffff, /* dst_mask */
1008 FALSE
), /* pcrel_offset */
1010 HOWTO (AARCH64_R (TLSLE_MOVW_TPREL_G1
), /* type */
1011 16, /* rightshift */
1012 2, /* size (0 = byte, 1 = short, 2 = long) */
1014 FALSE
, /* pc_relative */
1016 complain_overflow_dont
, /* complain_on_overflow */
1017 bfd_elf_generic_reloc
, /* special_function */
1018 AARCH64_R_STR (TLSLE_MOVW_TPREL_G1
), /* name */
1019 FALSE
, /* partial_inplace */
1020 0xffff, /* src_mask */
1021 0xffff, /* dst_mask */
1022 FALSE
), /* pcrel_offset */
1024 HOWTO64 (AARCH64_R (TLSLE_MOVW_TPREL_G1_NC
), /* type */
1025 16, /* rightshift */
1026 2, /* size (0 = byte, 1 = short, 2 = long) */
1028 FALSE
, /* pc_relative */
1030 complain_overflow_dont
, /* complain_on_overflow */
1031 bfd_elf_generic_reloc
, /* special_function */
1032 AARCH64_R_STR (TLSLE_MOVW_TPREL_G1_NC
), /* name */
1033 FALSE
, /* partial_inplace */
1034 0xffff, /* src_mask */
1035 0xffff, /* dst_mask */
1036 FALSE
), /* pcrel_offset */
1038 HOWTO (AARCH64_R (TLSLE_MOVW_TPREL_G0
), /* type */
1040 2, /* size (0 = byte, 1 = short, 2 = long) */
1042 FALSE
, /* pc_relative */
1044 complain_overflow_dont
, /* complain_on_overflow */
1045 bfd_elf_generic_reloc
, /* special_function */
1046 AARCH64_R_STR (TLSLE_MOVW_TPREL_G0
), /* name */
1047 FALSE
, /* partial_inplace */
1048 0xffff, /* src_mask */
1049 0xffff, /* dst_mask */
1050 FALSE
), /* pcrel_offset */
1052 HOWTO (AARCH64_R (TLSLE_MOVW_TPREL_G0_NC
), /* type */
1054 2, /* size (0 = byte, 1 = short, 2 = long) */
1056 FALSE
, /* pc_relative */
1058 complain_overflow_dont
, /* complain_on_overflow */
1059 bfd_elf_generic_reloc
, /* special_function */
1060 AARCH64_R_STR (TLSLE_MOVW_TPREL_G0_NC
), /* name */
1061 FALSE
, /* partial_inplace */
1062 0xffff, /* src_mask */
1063 0xffff, /* dst_mask */
1064 FALSE
), /* pcrel_offset */
1066 HOWTO (AARCH64_R (TLSLE_ADD_TPREL_HI12
), /* type */
1067 12, /* rightshift */
1068 2, /* size (0 = byte, 1 = short, 2 = long) */
1070 FALSE
, /* pc_relative */
1072 complain_overflow_unsigned
, /* complain_on_overflow */
1073 bfd_elf_generic_reloc
, /* special_function */
1074 AARCH64_R_STR (TLSLE_ADD_TPREL_HI12
), /* name */
1075 FALSE
, /* partial_inplace */
1076 0xfff, /* src_mask */
1077 0xfff, /* dst_mask */
1078 FALSE
), /* pcrel_offset */
1080 HOWTO (AARCH64_R (TLSLE_ADD_TPREL_LO12
), /* type */
1082 2, /* size (0 = byte, 1 = short, 2 = long) */
1084 FALSE
, /* pc_relative */
1086 complain_overflow_unsigned
, /* complain_on_overflow */
1087 bfd_elf_generic_reloc
, /* special_function */
1088 AARCH64_R_STR (TLSLE_ADD_TPREL_LO12
), /* name */
1089 FALSE
, /* partial_inplace */
1090 0xfff, /* src_mask */
1091 0xfff, /* dst_mask */
1092 FALSE
), /* pcrel_offset */
1094 HOWTO (AARCH64_R (TLSLE_ADD_TPREL_LO12_NC
), /* type */
1096 2, /* size (0 = byte, 1 = short, 2 = long) */
1098 FALSE
, /* pc_relative */
1100 complain_overflow_dont
, /* complain_on_overflow */
1101 bfd_elf_generic_reloc
, /* special_function */
1102 AARCH64_R_STR (TLSLE_ADD_TPREL_LO12_NC
), /* name */
1103 FALSE
, /* partial_inplace */
1104 0xfff, /* src_mask */
1105 0xfff, /* dst_mask */
1106 FALSE
), /* pcrel_offset */
1108 HOWTO (AARCH64_R (TLSDESC_LD_PREL19
), /* type */
1110 2, /* size (0 = byte, 1 = short, 2 = long) */
1112 TRUE
, /* pc_relative */
1114 complain_overflow_dont
, /* complain_on_overflow */
1115 bfd_elf_generic_reloc
, /* special_function */
1116 AARCH64_R_STR (TLSDESC_LD_PREL19
), /* name */
1117 FALSE
, /* partial_inplace */
1118 0x0ffffe0, /* src_mask */
1119 0x0ffffe0, /* dst_mask */
1120 TRUE
), /* pcrel_offset */
1122 HOWTO (AARCH64_R (TLSDESC_ADR_PREL21
), /* type */
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_PREL21
), /* name */
1131 FALSE
, /* partial_inplace */
1132 0x1fffff, /* src_mask */
1133 0x1fffff, /* dst_mask */
1134 TRUE
), /* pcrel_offset */
1136 /* Get to the page for the GOT entry for the symbol
1137 (G(S) - P) using an ADRP instruction. */
1138 HOWTO (AARCH64_R (TLSDESC_ADR_PAGE21
), /* type */
1139 12, /* rightshift */
1140 2, /* size (0 = byte, 1 = short, 2 = long) */
1142 TRUE
, /* pc_relative */
1144 complain_overflow_dont
, /* complain_on_overflow */
1145 bfd_elf_generic_reloc
, /* special_function */
1146 AARCH64_R_STR (TLSDESC_ADR_PAGE21
), /* name */
1147 FALSE
, /* partial_inplace */
1148 0x1fffff, /* src_mask */
1149 0x1fffff, /* dst_mask */
1150 TRUE
), /* pcrel_offset */
1152 /* LD64: GOT offset G(S) & 0xff8. */
1153 HOWTO64 (AARCH64_R (TLSDESC_LD64_LO12_NC
), /* type */
1155 2, /* size (0 = byte, 1 = short, 2 = long) */
1157 FALSE
, /* pc_relative */
1159 complain_overflow_dont
, /* complain_on_overflow */
1160 bfd_elf_generic_reloc
, /* special_function */
1161 AARCH64_R_STR (TLSDESC_LD64_LO12_NC
), /* name */
1162 FALSE
, /* partial_inplace */
1163 0xff8, /* src_mask */
1164 0xff8, /* dst_mask */
1165 FALSE
), /* pcrel_offset */
1167 /* LD32: GOT offset G(S) & 0xffc. */
1168 HOWTO32 (AARCH64_R (TLSDESC_LD32_LO12_NC
), /* type */
1170 2, /* size (0 = byte, 1 = short, 2 = long) */
1172 FALSE
, /* pc_relative */
1174 complain_overflow_dont
, /* complain_on_overflow */
1175 bfd_elf_generic_reloc
, /* special_function */
1176 AARCH64_R_STR (TLSDESC_LD32_LO12_NC
), /* name */
1177 FALSE
, /* partial_inplace */
1178 0xffc, /* src_mask */
1179 0xffc, /* dst_mask */
1180 FALSE
), /* pcrel_offset */
1182 /* ADD: GOT offset G(S) & 0xfff. */
1183 HOWTO (AARCH64_R (TLSDESC_ADD_LO12_NC
), /* type */
1185 2, /* size (0 = byte, 1 = short, 2 = long) */
1187 FALSE
, /* pc_relative */
1189 complain_overflow_dont
, /* complain_on_overflow */
1190 bfd_elf_generic_reloc
, /* special_function */
1191 AARCH64_R_STR (TLSDESC_ADD_LO12_NC
), /* name */
1192 FALSE
, /* partial_inplace */
1193 0xfff, /* src_mask */
1194 0xfff, /* dst_mask */
1195 FALSE
), /* pcrel_offset */
1197 HOWTO64 (AARCH64_R (TLSDESC_OFF_G1
), /* type */
1198 16, /* rightshift */
1199 2, /* size (0 = byte, 1 = short, 2 = long) */
1201 FALSE
, /* pc_relative */
1203 complain_overflow_dont
, /* complain_on_overflow */
1204 bfd_elf_generic_reloc
, /* special_function */
1205 AARCH64_R_STR (TLSDESC_OFF_G1
), /* name */
1206 FALSE
, /* partial_inplace */
1207 0xffff, /* src_mask */
1208 0xffff, /* dst_mask */
1209 FALSE
), /* pcrel_offset */
1211 HOWTO64 (AARCH64_R (TLSDESC_OFF_G0_NC
), /* type */
1213 2, /* size (0 = byte, 1 = short, 2 = long) */
1215 FALSE
, /* pc_relative */
1217 complain_overflow_dont
, /* complain_on_overflow */
1218 bfd_elf_generic_reloc
, /* special_function */
1219 AARCH64_R_STR (TLSDESC_OFF_G0_NC
), /* name */
1220 FALSE
, /* partial_inplace */
1221 0xffff, /* src_mask */
1222 0xffff, /* dst_mask */
1223 FALSE
), /* pcrel_offset */
1225 HOWTO64 (AARCH64_R (TLSDESC_LDR
), /* type */
1227 2, /* size (0 = byte, 1 = short, 2 = long) */
1229 FALSE
, /* pc_relative */
1231 complain_overflow_dont
, /* complain_on_overflow */
1232 bfd_elf_generic_reloc
, /* special_function */
1233 AARCH64_R_STR (TLSDESC_LDR
), /* name */
1234 FALSE
, /* partial_inplace */
1237 FALSE
), /* pcrel_offset */
1239 HOWTO64 (AARCH64_R (TLSDESC_ADD
), /* type */
1241 2, /* size (0 = byte, 1 = short, 2 = long) */
1243 FALSE
, /* pc_relative */
1245 complain_overflow_dont
, /* complain_on_overflow */
1246 bfd_elf_generic_reloc
, /* special_function */
1247 AARCH64_R_STR (TLSDESC_ADD
), /* name */
1248 FALSE
, /* partial_inplace */
1251 FALSE
), /* pcrel_offset */
1253 HOWTO (AARCH64_R (TLSDESC_CALL
), /* type */
1255 2, /* size (0 = byte, 1 = short, 2 = long) */
1257 FALSE
, /* pc_relative */
1259 complain_overflow_dont
, /* complain_on_overflow */
1260 bfd_elf_generic_reloc
, /* special_function */
1261 AARCH64_R_STR (TLSDESC_CALL
), /* name */
1262 FALSE
, /* partial_inplace */
1265 FALSE
), /* pcrel_offset */
1267 HOWTO (AARCH64_R (COPY
), /* type */
1269 2, /* size (0 = byte, 1 = short, 2 = long) */
1271 FALSE
, /* pc_relative */
1273 complain_overflow_bitfield
, /* complain_on_overflow */
1274 bfd_elf_generic_reloc
, /* special_function */
1275 AARCH64_R_STR (COPY
), /* name */
1276 TRUE
, /* partial_inplace */
1277 0xffffffff, /* src_mask */
1278 0xffffffff, /* dst_mask */
1279 FALSE
), /* pcrel_offset */
1281 HOWTO (AARCH64_R (GLOB_DAT
), /* type */
1283 2, /* size (0 = byte, 1 = short, 2 = long) */
1285 FALSE
, /* pc_relative */
1287 complain_overflow_bitfield
, /* complain_on_overflow */
1288 bfd_elf_generic_reloc
, /* special_function */
1289 AARCH64_R_STR (GLOB_DAT
), /* name */
1290 TRUE
, /* partial_inplace */
1291 0xffffffff, /* src_mask */
1292 0xffffffff, /* dst_mask */
1293 FALSE
), /* pcrel_offset */
1295 HOWTO (AARCH64_R (JUMP_SLOT
), /* type */
1297 2, /* size (0 = byte, 1 = short, 2 = long) */
1299 FALSE
, /* pc_relative */
1301 complain_overflow_bitfield
, /* complain_on_overflow */
1302 bfd_elf_generic_reloc
, /* special_function */
1303 AARCH64_R_STR (JUMP_SLOT
), /* name */
1304 TRUE
, /* partial_inplace */
1305 0xffffffff, /* src_mask */
1306 0xffffffff, /* dst_mask */
1307 FALSE
), /* pcrel_offset */
1309 HOWTO (AARCH64_R (RELATIVE
), /* type */
1311 2, /* size (0 = byte, 1 = short, 2 = long) */
1313 FALSE
, /* pc_relative */
1315 complain_overflow_bitfield
, /* complain_on_overflow */
1316 bfd_elf_generic_reloc
, /* special_function */
1317 AARCH64_R_STR (RELATIVE
), /* name */
1318 TRUE
, /* partial_inplace */
1319 ALL_ONES
, /* src_mask */
1320 ALL_ONES
, /* dst_mask */
1321 FALSE
), /* pcrel_offset */
1323 HOWTO (AARCH64_R (TLS_DTPMOD
), /* type */
1325 2, /* size (0 = byte, 1 = short, 2 = long) */
1327 FALSE
, /* pc_relative */
1329 complain_overflow_dont
, /* complain_on_overflow */
1330 bfd_elf_generic_reloc
, /* special_function */
1332 AARCH64_R_STR (TLS_DTPMOD64
), /* name */
1334 AARCH64_R_STR (TLS_DTPMOD
), /* name */
1336 FALSE
, /* partial_inplace */
1338 ALL_ONES
, /* dst_mask */
1339 FALSE
), /* pc_reloffset */
1341 HOWTO (AARCH64_R (TLS_DTPREL
), /* type */
1343 2, /* size (0 = byte, 1 = short, 2 = long) */
1345 FALSE
, /* pc_relative */
1347 complain_overflow_dont
, /* complain_on_overflow */
1348 bfd_elf_generic_reloc
, /* special_function */
1350 AARCH64_R_STR (TLS_DTPREL64
), /* name */
1352 AARCH64_R_STR (TLS_DTPREL
), /* name */
1354 FALSE
, /* partial_inplace */
1356 ALL_ONES
, /* dst_mask */
1357 FALSE
), /* pcrel_offset */
1359 HOWTO (AARCH64_R (TLS_TPREL
), /* type */
1361 2, /* size (0 = byte, 1 = short, 2 = long) */
1363 FALSE
, /* pc_relative */
1365 complain_overflow_dont
, /* complain_on_overflow */
1366 bfd_elf_generic_reloc
, /* special_function */
1368 AARCH64_R_STR (TLS_TPREL64
), /* name */
1370 AARCH64_R_STR (TLS_TPREL
), /* name */
1372 FALSE
, /* partial_inplace */
1374 ALL_ONES
, /* dst_mask */
1375 FALSE
), /* pcrel_offset */
1377 HOWTO (AARCH64_R (TLSDESC
), /* type */
1379 2, /* size (0 = byte, 1 = short, 2 = long) */
1381 FALSE
, /* pc_relative */
1383 complain_overflow_dont
, /* complain_on_overflow */
1384 bfd_elf_generic_reloc
, /* special_function */
1385 AARCH64_R_STR (TLSDESC
), /* name */
1386 FALSE
, /* partial_inplace */
1388 ALL_ONES
, /* dst_mask */
1389 FALSE
), /* pcrel_offset */
1391 HOWTO (AARCH64_R (IRELATIVE
), /* type */
1393 2, /* size (0 = byte, 1 = short, 2 = long) */
1395 FALSE
, /* pc_relative */
1397 complain_overflow_bitfield
, /* complain_on_overflow */
1398 bfd_elf_generic_reloc
, /* special_function */
1399 AARCH64_R_STR (IRELATIVE
), /* name */
1400 FALSE
, /* partial_inplace */
1402 ALL_ONES
, /* dst_mask */
1403 FALSE
), /* pcrel_offset */
1408 static reloc_howto_type elfNN_aarch64_howto_none
=
1409 HOWTO (R_AARCH64_NONE
, /* type */
1411 3, /* size (0 = byte, 1 = short, 2 = long) */
1413 FALSE
, /* pc_relative */
1415 complain_overflow_dont
,/* complain_on_overflow */
1416 bfd_elf_generic_reloc
, /* special_function */
1417 "R_AARCH64_NONE", /* name */
1418 FALSE
, /* partial_inplace */
1421 FALSE
); /* pcrel_offset */
1423 /* Given HOWTO, return the bfd internal relocation enumerator. */
1425 static bfd_reloc_code_real_type
1426 elfNN_aarch64_bfd_reloc_from_howto (reloc_howto_type
*howto
)
1429 = (int) ARRAY_SIZE (elfNN_aarch64_howto_table
);
1430 const ptrdiff_t offset
1431 = howto
- elfNN_aarch64_howto_table
;
1433 if (offset
> 0 && offset
< size
- 1)
1434 return BFD_RELOC_AARCH64_RELOC_START
+ offset
;
1436 if (howto
== &elfNN_aarch64_howto_none
)
1437 return BFD_RELOC_AARCH64_NONE
;
1439 return BFD_RELOC_AARCH64_RELOC_START
;
1442 /* Given R_TYPE, return the bfd internal relocation enumerator. */
1444 static bfd_reloc_code_real_type
1445 elfNN_aarch64_bfd_reloc_from_type (unsigned int r_type
)
1447 static bfd_boolean initialized_p
= FALSE
;
1448 /* Indexed by R_TYPE, values are offsets in the howto_table. */
1449 static unsigned int offsets
[R_AARCH64_end
];
1451 if (initialized_p
== FALSE
)
1455 for (i
= 1; i
< ARRAY_SIZE (elfNN_aarch64_howto_table
) - 1; ++i
)
1456 if (elfNN_aarch64_howto_table
[i
].type
!= 0)
1457 offsets
[elfNN_aarch64_howto_table
[i
].type
] = i
;
1459 initialized_p
= TRUE
;
1462 if (r_type
== R_AARCH64_NONE
|| r_type
== R_AARCH64_NULL
)
1463 return BFD_RELOC_AARCH64_NONE
;
1465 /* PR 17512: file: b371e70a. */
1466 if (r_type
>= R_AARCH64_end
)
1468 _bfd_error_handler (_("Invalid AArch64 reloc number: %d"), r_type
);
1469 bfd_set_error (bfd_error_bad_value
);
1470 return BFD_RELOC_AARCH64_NONE
;
1473 return BFD_RELOC_AARCH64_RELOC_START
+ offsets
[r_type
];
1476 struct elf_aarch64_reloc_map
1478 bfd_reloc_code_real_type from
;
1479 bfd_reloc_code_real_type to
;
1482 /* Map bfd generic reloc to AArch64-specific reloc. */
1483 static const struct elf_aarch64_reloc_map elf_aarch64_reloc_map
[] =
1485 {BFD_RELOC_NONE
, BFD_RELOC_AARCH64_NONE
},
1487 /* Basic data relocations. */
1488 {BFD_RELOC_CTOR
, BFD_RELOC_AARCH64_NN
},
1489 {BFD_RELOC_64
, BFD_RELOC_AARCH64_64
},
1490 {BFD_RELOC_32
, BFD_RELOC_AARCH64_32
},
1491 {BFD_RELOC_16
, BFD_RELOC_AARCH64_16
},
1492 {BFD_RELOC_64_PCREL
, BFD_RELOC_AARCH64_64_PCREL
},
1493 {BFD_RELOC_32_PCREL
, BFD_RELOC_AARCH64_32_PCREL
},
1494 {BFD_RELOC_16_PCREL
, BFD_RELOC_AARCH64_16_PCREL
},
1497 /* Given the bfd internal relocation enumerator in CODE, return the
1498 corresponding howto entry. */
1500 static reloc_howto_type
*
1501 elfNN_aarch64_howto_from_bfd_reloc (bfd_reloc_code_real_type code
)
1505 /* Convert bfd generic reloc to AArch64-specific reloc. */
1506 if (code
< BFD_RELOC_AARCH64_RELOC_START
1507 || code
> BFD_RELOC_AARCH64_RELOC_END
)
1508 for (i
= 0; i
< ARRAY_SIZE (elf_aarch64_reloc_map
); i
++)
1509 if (elf_aarch64_reloc_map
[i
].from
== code
)
1511 code
= elf_aarch64_reloc_map
[i
].to
;
1515 if (code
> BFD_RELOC_AARCH64_RELOC_START
1516 && code
< BFD_RELOC_AARCH64_RELOC_END
)
1517 if (elfNN_aarch64_howto_table
[code
- BFD_RELOC_AARCH64_RELOC_START
].type
)
1518 return &elfNN_aarch64_howto_table
[code
- BFD_RELOC_AARCH64_RELOC_START
];
1520 if (code
== BFD_RELOC_AARCH64_NONE
)
1521 return &elfNN_aarch64_howto_none
;
1526 static reloc_howto_type
*
1527 elfNN_aarch64_howto_from_type (unsigned int r_type
)
1529 bfd_reloc_code_real_type val
;
1530 reloc_howto_type
*howto
;
1535 bfd_set_error (bfd_error_bad_value
);
1540 if (r_type
== R_AARCH64_NONE
)
1541 return &elfNN_aarch64_howto_none
;
1543 val
= elfNN_aarch64_bfd_reloc_from_type (r_type
);
1544 howto
= elfNN_aarch64_howto_from_bfd_reloc (val
);
1549 bfd_set_error (bfd_error_bad_value
);
1554 elfNN_aarch64_info_to_howto (bfd
*abfd ATTRIBUTE_UNUSED
, arelent
*bfd_reloc
,
1555 Elf_Internal_Rela
*elf_reloc
)
1557 unsigned int r_type
;
1559 r_type
= ELFNN_R_TYPE (elf_reloc
->r_info
);
1560 bfd_reloc
->howto
= elfNN_aarch64_howto_from_type (r_type
);
1563 static reloc_howto_type
*
1564 elfNN_aarch64_reloc_type_lookup (bfd
*abfd ATTRIBUTE_UNUSED
,
1565 bfd_reloc_code_real_type code
)
1567 reloc_howto_type
*howto
= elfNN_aarch64_howto_from_bfd_reloc (code
);
1572 bfd_set_error (bfd_error_bad_value
);
1576 static reloc_howto_type
*
1577 elfNN_aarch64_reloc_name_lookup (bfd
*abfd ATTRIBUTE_UNUSED
,
1582 for (i
= 1; i
< ARRAY_SIZE (elfNN_aarch64_howto_table
) - 1; ++i
)
1583 if (elfNN_aarch64_howto_table
[i
].name
!= NULL
1584 && strcasecmp (elfNN_aarch64_howto_table
[i
].name
, r_name
) == 0)
1585 return &elfNN_aarch64_howto_table
[i
];
1590 #define TARGET_LITTLE_SYM aarch64_elfNN_le_vec
1591 #define TARGET_LITTLE_NAME "elfNN-littleaarch64"
1592 #define TARGET_BIG_SYM aarch64_elfNN_be_vec
1593 #define TARGET_BIG_NAME "elfNN-bigaarch64"
1595 /* The linker script knows the section names for placement.
1596 The entry_names are used to do simple name mangling on the stubs.
1597 Given a function name, and its type, the stub can be found. The
1598 name can be changed. The only requirement is the %s be present. */
1599 #define STUB_ENTRY_NAME "__%s_veneer"
1601 /* The name of the dynamic interpreter. This is put in the .interp
1603 #define ELF_DYNAMIC_INTERPRETER "/lib/ld.so.1"
1605 #define AARCH64_MAX_FWD_BRANCH_OFFSET \
1606 (((1 << 25) - 1) << 2)
1607 #define AARCH64_MAX_BWD_BRANCH_OFFSET \
1610 #define AARCH64_MAX_ADRP_IMM ((1 << 20) - 1)
1611 #define AARCH64_MIN_ADRP_IMM (-(1 << 20))
1614 aarch64_valid_for_adrp_p (bfd_vma value
, bfd_vma place
)
1616 bfd_signed_vma offset
= (bfd_signed_vma
) (PG (value
) - PG (place
)) >> 12;
1617 return offset
<= AARCH64_MAX_ADRP_IMM
&& offset
>= AARCH64_MIN_ADRP_IMM
;
1621 aarch64_valid_branch_p (bfd_vma value
, bfd_vma place
)
1623 bfd_signed_vma offset
= (bfd_signed_vma
) (value
- place
);
1624 return (offset
<= AARCH64_MAX_FWD_BRANCH_OFFSET
1625 && offset
>= AARCH64_MAX_BWD_BRANCH_OFFSET
);
1628 static const uint32_t aarch64_adrp_branch_stub
[] =
1630 0x90000010, /* adrp ip0, X */
1631 /* R_AARCH64_ADR_HI21_PCREL(X) */
1632 0x91000210, /* add ip0, ip0, :lo12:X */
1633 /* R_AARCH64_ADD_ABS_LO12_NC(X) */
1634 0xd61f0200, /* br ip0 */
1637 static const uint32_t aarch64_long_branch_stub
[] =
1640 0x58000090, /* ldr ip0, 1f */
1642 0x18000090, /* ldr wip0, 1f */
1644 0x10000011, /* adr ip1, #0 */
1645 0x8b110210, /* add ip0, ip0, ip1 */
1646 0xd61f0200, /* br ip0 */
1647 0x00000000, /* 1: .xword or .word
1648 R_AARCH64_PRELNN(X) + 12
1653 static const uint32_t aarch64_erratum_835769_stub
[] =
1655 0x00000000, /* Placeholder for multiply accumulate. */
1656 0x14000000, /* b <label> */
1659 static const uint32_t aarch64_erratum_843419_stub
[] =
1661 0x00000000, /* Placeholder for LDR instruction. */
1662 0x14000000, /* b <label> */
1665 /* Section name for stubs is the associated section name plus this
1667 #define STUB_SUFFIX ".stub"
1669 enum elf_aarch64_stub_type
1672 aarch64_stub_adrp_branch
,
1673 aarch64_stub_long_branch
,
1674 aarch64_stub_erratum_835769_veneer
,
1675 aarch64_stub_erratum_843419_veneer
,
1678 struct elf_aarch64_stub_hash_entry
1680 /* Base hash table entry structure. */
1681 struct bfd_hash_entry root
;
1683 /* The stub section. */
1686 /* Offset within stub_sec of the beginning of this stub. */
1687 bfd_vma stub_offset
;
1689 /* Given the symbol's value and its section we can determine its final
1690 value when building the stubs (so the stub knows where to jump). */
1691 bfd_vma target_value
;
1692 asection
*target_section
;
1694 enum elf_aarch64_stub_type stub_type
;
1696 /* The symbol table entry, if any, that this was derived from. */
1697 struct elf_aarch64_link_hash_entry
*h
;
1699 /* Destination symbol type */
1700 unsigned char st_type
;
1702 /* Where this stub is being called from, or, in the case of combined
1703 stub sections, the first input section in the group. */
1706 /* The name for the local symbol at the start of this stub. The
1707 stub name in the hash table has to be unique; this does not, so
1708 it can be friendlier. */
1711 /* The instruction which caused this stub to be generated (only valid for
1712 erratum 835769 workaround stubs at present). */
1713 uint32_t veneered_insn
;
1715 /* In an erratum 843419 workaround stub, the ADRP instruction offset. */
1716 bfd_vma adrp_offset
;
1719 /* Used to build a map of a section. This is required for mixed-endian
1722 typedef struct elf_elf_section_map
1727 elf_aarch64_section_map
;
1730 typedef struct _aarch64_elf_section_data
1732 struct bfd_elf_section_data elf
;
1733 unsigned int mapcount
;
1734 unsigned int mapsize
;
1735 elf_aarch64_section_map
*map
;
1737 _aarch64_elf_section_data
;
1739 #define elf_aarch64_section_data(sec) \
1740 ((_aarch64_elf_section_data *) elf_section_data (sec))
1742 /* The size of the thread control block which is defined to be two pointers. */
1743 #define TCB_SIZE (ARCH_SIZE/8)*2
1745 struct elf_aarch64_local_symbol
1747 unsigned int got_type
;
1748 bfd_signed_vma got_refcount
;
1751 /* Offset of the GOTPLT entry reserved for the TLS descriptor. The
1752 offset is from the end of the jump table and reserved entries
1755 The magic value (bfd_vma) -1 indicates that an offset has not be
1757 bfd_vma tlsdesc_got_jump_table_offset
;
1760 struct elf_aarch64_obj_tdata
1762 struct elf_obj_tdata root
;
1764 /* local symbol descriptors */
1765 struct elf_aarch64_local_symbol
*locals
;
1767 /* Zero to warn when linking objects with incompatible enum sizes. */
1768 int no_enum_size_warning
;
1770 /* Zero to warn when linking objects with incompatible wchar_t sizes. */
1771 int no_wchar_size_warning
;
1774 #define elf_aarch64_tdata(bfd) \
1775 ((struct elf_aarch64_obj_tdata *) (bfd)->tdata.any)
1777 #define elf_aarch64_locals(bfd) (elf_aarch64_tdata (bfd)->locals)
1779 #define is_aarch64_elf(bfd) \
1780 (bfd_get_flavour (bfd) == bfd_target_elf_flavour \
1781 && elf_tdata (bfd) != NULL \
1782 && elf_object_id (bfd) == AARCH64_ELF_DATA)
1785 elfNN_aarch64_mkobject (bfd
*abfd
)
1787 return bfd_elf_allocate_object (abfd
, sizeof (struct elf_aarch64_obj_tdata
),
1791 #define elf_aarch64_hash_entry(ent) \
1792 ((struct elf_aarch64_link_hash_entry *)(ent))
1794 #define GOT_UNKNOWN 0
1795 #define GOT_NORMAL 1
1796 #define GOT_TLS_GD 2
1797 #define GOT_TLS_IE 4
1798 #define GOT_TLSDESC_GD 8
1800 #define GOT_TLS_GD_ANY_P(type) ((type & GOT_TLS_GD) || (type & GOT_TLSDESC_GD))
1802 /* AArch64 ELF linker hash entry. */
1803 struct elf_aarch64_link_hash_entry
1805 struct elf_link_hash_entry root
;
1807 /* Track dynamic relocs copied for this symbol. */
1808 struct elf_dyn_relocs
*dyn_relocs
;
1810 /* Since PLT entries have variable size, we need to record the
1811 index into .got.plt instead of recomputing it from the PLT
1813 bfd_signed_vma plt_got_offset
;
1815 /* Bit mask representing the type of GOT entry(s) if any required by
1817 unsigned int got_type
;
1819 /* A pointer to the most recently used stub hash entry against this
1821 struct elf_aarch64_stub_hash_entry
*stub_cache
;
1823 /* Offset of the GOTPLT entry reserved for the TLS descriptor. The offset
1824 is from the end of the jump table and reserved entries within the PLTGOT.
1826 The magic value (bfd_vma) -1 indicates that an offset has not
1828 bfd_vma tlsdesc_got_jump_table_offset
;
1832 elfNN_aarch64_symbol_got_type (struct elf_link_hash_entry
*h
,
1834 unsigned long r_symndx
)
1837 return elf_aarch64_hash_entry (h
)->got_type
;
1839 if (! elf_aarch64_locals (abfd
))
1842 return elf_aarch64_locals (abfd
)[r_symndx
].got_type
;
1845 /* Get the AArch64 elf linker hash table from a link_info structure. */
1846 #define elf_aarch64_hash_table(info) \
1847 ((struct elf_aarch64_link_hash_table *) ((info)->hash))
1849 #define aarch64_stub_hash_lookup(table, string, create, copy) \
1850 ((struct elf_aarch64_stub_hash_entry *) \
1851 bfd_hash_lookup ((table), (string), (create), (copy)))
1853 /* AArch64 ELF linker hash table. */
1854 struct elf_aarch64_link_hash_table
1856 /* The main hash table. */
1857 struct elf_link_hash_table root
;
1859 /* Nonzero to force PIC branch veneers. */
1862 /* Fix erratum 835769. */
1863 int fix_erratum_835769
;
1865 /* Fix erratum 843419. */
1866 int fix_erratum_843419
;
1868 /* Enable ADRP->ADR rewrite for erratum 843419 workaround. */
1869 int fix_erratum_843419_adr
;
1871 /* The number of bytes in the initial entry in the PLT. */
1872 bfd_size_type plt_header_size
;
1874 /* The number of bytes in the subsequent PLT etries. */
1875 bfd_size_type plt_entry_size
;
1877 /* Short-cuts to get to dynamic linker sections. */
1881 /* Small local sym cache. */
1882 struct sym_cache sym_cache
;
1884 /* For convenience in allocate_dynrelocs. */
1887 /* The amount of space used by the reserved portion of the sgotplt
1888 section, plus whatever space is used by the jump slots. */
1889 bfd_vma sgotplt_jump_table_size
;
1891 /* The stub hash table. */
1892 struct bfd_hash_table stub_hash_table
;
1894 /* Linker stub bfd. */
1897 /* Linker call-backs. */
1898 asection
*(*add_stub_section
) (const char *, asection
*);
1899 void (*layout_sections_again
) (void);
1901 /* Array to keep track of which stub sections have been created, and
1902 information on stub grouping. */
1905 /* This is the section to which stubs in the group will be
1908 /* The stub section. */
1912 /* Assorted information used by elfNN_aarch64_size_stubs. */
1913 unsigned int bfd_count
;
1915 asection
**input_list
;
1917 /* The offset into splt of the PLT entry for the TLS descriptor
1918 resolver. Special values are 0, if not necessary (or not found
1919 to be necessary yet), and -1 if needed but not determined
1921 bfd_vma tlsdesc_plt
;
1923 /* The GOT offset for the lazy trampoline. Communicated to the
1924 loader via DT_TLSDESC_GOT. The magic value (bfd_vma) -1
1925 indicates an offset is not allocated. */
1926 bfd_vma dt_tlsdesc_got
;
1928 /* Used by local STT_GNU_IFUNC symbols. */
1929 htab_t loc_hash_table
;
1930 void * loc_hash_memory
;
1933 /* Create an entry in an AArch64 ELF linker hash table. */
1935 static struct bfd_hash_entry
*
1936 elfNN_aarch64_link_hash_newfunc (struct bfd_hash_entry
*entry
,
1937 struct bfd_hash_table
*table
,
1940 struct elf_aarch64_link_hash_entry
*ret
=
1941 (struct elf_aarch64_link_hash_entry
*) entry
;
1943 /* Allocate the structure if it has not already been allocated by a
1946 ret
= bfd_hash_allocate (table
,
1947 sizeof (struct elf_aarch64_link_hash_entry
));
1949 return (struct bfd_hash_entry
*) ret
;
1951 /* Call the allocation method of the superclass. */
1952 ret
= ((struct elf_aarch64_link_hash_entry
*)
1953 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry
*) ret
,
1957 ret
->dyn_relocs
= NULL
;
1958 ret
->got_type
= GOT_UNKNOWN
;
1959 ret
->plt_got_offset
= (bfd_vma
) - 1;
1960 ret
->stub_cache
= NULL
;
1961 ret
->tlsdesc_got_jump_table_offset
= (bfd_vma
) - 1;
1964 return (struct bfd_hash_entry
*) ret
;
1967 /* Initialize an entry in the stub hash table. */
1969 static struct bfd_hash_entry
*
1970 stub_hash_newfunc (struct bfd_hash_entry
*entry
,
1971 struct bfd_hash_table
*table
, const char *string
)
1973 /* Allocate the structure if it has not already been allocated by a
1977 entry
= bfd_hash_allocate (table
,
1979 elf_aarch64_stub_hash_entry
));
1984 /* Call the allocation method of the superclass. */
1985 entry
= bfd_hash_newfunc (entry
, table
, string
);
1988 struct elf_aarch64_stub_hash_entry
*eh
;
1990 /* Initialize the local fields. */
1991 eh
= (struct elf_aarch64_stub_hash_entry
*) entry
;
1992 eh
->adrp_offset
= 0;
1993 eh
->stub_sec
= NULL
;
1994 eh
->stub_offset
= 0;
1995 eh
->target_value
= 0;
1996 eh
->target_section
= NULL
;
1997 eh
->stub_type
= aarch64_stub_none
;
2005 /* Compute a hash of a local hash entry. We use elf_link_hash_entry
2006 for local symbol so that we can handle local STT_GNU_IFUNC symbols
2007 as global symbol. We reuse indx and dynstr_index for local symbol
2008 hash since they aren't used by global symbols in this backend. */
2011 elfNN_aarch64_local_htab_hash (const void *ptr
)
2013 struct elf_link_hash_entry
*h
2014 = (struct elf_link_hash_entry
*) ptr
;
2015 return ELF_LOCAL_SYMBOL_HASH (h
->indx
, h
->dynstr_index
);
2018 /* Compare local hash entries. */
2021 elfNN_aarch64_local_htab_eq (const void *ptr1
, const void *ptr2
)
2023 struct elf_link_hash_entry
*h1
2024 = (struct elf_link_hash_entry
*) ptr1
;
2025 struct elf_link_hash_entry
*h2
2026 = (struct elf_link_hash_entry
*) ptr2
;
2028 return h1
->indx
== h2
->indx
&& h1
->dynstr_index
== h2
->dynstr_index
;
2031 /* Find and/or create a hash entry for local symbol. */
2033 static struct elf_link_hash_entry
*
2034 elfNN_aarch64_get_local_sym_hash (struct elf_aarch64_link_hash_table
*htab
,
2035 bfd
*abfd
, const Elf_Internal_Rela
*rel
,
2038 struct elf_aarch64_link_hash_entry e
, *ret
;
2039 asection
*sec
= abfd
->sections
;
2040 hashval_t h
= ELF_LOCAL_SYMBOL_HASH (sec
->id
,
2041 ELFNN_R_SYM (rel
->r_info
));
2044 e
.root
.indx
= sec
->id
;
2045 e
.root
.dynstr_index
= ELFNN_R_SYM (rel
->r_info
);
2046 slot
= htab_find_slot_with_hash (htab
->loc_hash_table
, &e
, h
,
2047 create
? INSERT
: NO_INSERT
);
2054 ret
= (struct elf_aarch64_link_hash_entry
*) *slot
;
2058 ret
= (struct elf_aarch64_link_hash_entry
*)
2059 objalloc_alloc ((struct objalloc
*) htab
->loc_hash_memory
,
2060 sizeof (struct elf_aarch64_link_hash_entry
));
2063 memset (ret
, 0, sizeof (*ret
));
2064 ret
->root
.indx
= sec
->id
;
2065 ret
->root
.dynstr_index
= ELFNN_R_SYM (rel
->r_info
);
2066 ret
->root
.dynindx
= -1;
2072 /* Copy the extra info we tack onto an elf_link_hash_entry. */
2075 elfNN_aarch64_copy_indirect_symbol (struct bfd_link_info
*info
,
2076 struct elf_link_hash_entry
*dir
,
2077 struct elf_link_hash_entry
*ind
)
2079 struct elf_aarch64_link_hash_entry
*edir
, *eind
;
2081 edir
= (struct elf_aarch64_link_hash_entry
*) dir
;
2082 eind
= (struct elf_aarch64_link_hash_entry
*) ind
;
2084 if (eind
->dyn_relocs
!= NULL
)
2086 if (edir
->dyn_relocs
!= NULL
)
2088 struct elf_dyn_relocs
**pp
;
2089 struct elf_dyn_relocs
*p
;
2091 /* Add reloc counts against the indirect sym to the direct sym
2092 list. Merge any entries against the same section. */
2093 for (pp
= &eind
->dyn_relocs
; (p
= *pp
) != NULL
;)
2095 struct elf_dyn_relocs
*q
;
2097 for (q
= edir
->dyn_relocs
; q
!= NULL
; q
= q
->next
)
2098 if (q
->sec
== p
->sec
)
2100 q
->pc_count
+= p
->pc_count
;
2101 q
->count
+= p
->count
;
2108 *pp
= edir
->dyn_relocs
;
2111 edir
->dyn_relocs
= eind
->dyn_relocs
;
2112 eind
->dyn_relocs
= NULL
;
2115 if (ind
->root
.type
== bfd_link_hash_indirect
)
2117 /* Copy over PLT info. */
2118 if (dir
->got
.refcount
<= 0)
2120 edir
->got_type
= eind
->got_type
;
2121 eind
->got_type
= GOT_UNKNOWN
;
2125 _bfd_elf_link_hash_copy_indirect (info
, dir
, ind
);
2128 /* Destroy an AArch64 elf linker hash table. */
2131 elfNN_aarch64_link_hash_table_free (bfd
*obfd
)
2133 struct elf_aarch64_link_hash_table
*ret
2134 = (struct elf_aarch64_link_hash_table
*) obfd
->link
.hash
;
2136 if (ret
->loc_hash_table
)
2137 htab_delete (ret
->loc_hash_table
);
2138 if (ret
->loc_hash_memory
)
2139 objalloc_free ((struct objalloc
*) ret
->loc_hash_memory
);
2141 bfd_hash_table_free (&ret
->stub_hash_table
);
2142 _bfd_elf_link_hash_table_free (obfd
);
2145 /* Create an AArch64 elf linker hash table. */
2147 static struct bfd_link_hash_table
*
2148 elfNN_aarch64_link_hash_table_create (bfd
*abfd
)
2150 struct elf_aarch64_link_hash_table
*ret
;
2151 bfd_size_type amt
= sizeof (struct elf_aarch64_link_hash_table
);
2153 ret
= bfd_zmalloc (amt
);
2157 if (!_bfd_elf_link_hash_table_init
2158 (&ret
->root
, abfd
, elfNN_aarch64_link_hash_newfunc
,
2159 sizeof (struct elf_aarch64_link_hash_entry
), AARCH64_ELF_DATA
))
2165 ret
->plt_header_size
= PLT_ENTRY_SIZE
;
2166 ret
->plt_entry_size
= PLT_SMALL_ENTRY_SIZE
;
2168 ret
->dt_tlsdesc_got
= (bfd_vma
) - 1;
2170 if (!bfd_hash_table_init (&ret
->stub_hash_table
, stub_hash_newfunc
,
2171 sizeof (struct elf_aarch64_stub_hash_entry
)))
2173 _bfd_elf_link_hash_table_free (abfd
);
2177 ret
->loc_hash_table
= htab_try_create (1024,
2178 elfNN_aarch64_local_htab_hash
,
2179 elfNN_aarch64_local_htab_eq
,
2181 ret
->loc_hash_memory
= objalloc_create ();
2182 if (!ret
->loc_hash_table
|| !ret
->loc_hash_memory
)
2184 elfNN_aarch64_link_hash_table_free (abfd
);
2187 ret
->root
.root
.hash_table_free
= elfNN_aarch64_link_hash_table_free
;
2189 return &ret
->root
.root
;
2193 aarch64_relocate (unsigned int r_type
, bfd
*input_bfd
, asection
*input_section
,
2194 bfd_vma offset
, bfd_vma value
)
2196 reloc_howto_type
*howto
;
2199 howto
= elfNN_aarch64_howto_from_type (r_type
);
2200 place
= (input_section
->output_section
->vma
+ input_section
->output_offset
2203 r_type
= elfNN_aarch64_bfd_reloc_from_type (r_type
);
2204 value
= _bfd_aarch64_elf_resolve_relocation (r_type
, place
, value
, 0, FALSE
);
2205 return _bfd_aarch64_elf_put_addend (input_bfd
,
2206 input_section
->contents
+ offset
, r_type
,
2210 static enum elf_aarch64_stub_type
2211 aarch64_select_branch_stub (bfd_vma value
, bfd_vma place
)
2213 if (aarch64_valid_for_adrp_p (value
, place
))
2214 return aarch64_stub_adrp_branch
;
2215 return aarch64_stub_long_branch
;
2218 /* Determine the type of stub needed, if any, for a call. */
2220 static enum elf_aarch64_stub_type
2221 aarch64_type_of_stub (struct bfd_link_info
*info
,
2222 asection
*input_sec
,
2223 const Elf_Internal_Rela
*rel
,
2224 unsigned char st_type
,
2225 struct elf_aarch64_link_hash_entry
*hash
,
2226 bfd_vma destination
)
2229 bfd_signed_vma branch_offset
;
2230 unsigned int r_type
;
2231 struct elf_aarch64_link_hash_table
*globals
;
2232 enum elf_aarch64_stub_type stub_type
= aarch64_stub_none
;
2233 bfd_boolean via_plt_p
;
2235 if (st_type
!= STT_FUNC
)
2238 globals
= elf_aarch64_hash_table (info
);
2239 via_plt_p
= (globals
->root
.splt
!= NULL
&& hash
!= NULL
2240 && hash
->root
.plt
.offset
!= (bfd_vma
) - 1);
2245 /* Determine where the call point is. */
2246 location
= (input_sec
->output_offset
2247 + input_sec
->output_section
->vma
+ rel
->r_offset
);
2249 branch_offset
= (bfd_signed_vma
) (destination
- location
);
2251 r_type
= ELFNN_R_TYPE (rel
->r_info
);
2253 /* We don't want to redirect any old unconditional jump in this way,
2254 only one which is being used for a sibcall, where it is
2255 acceptable for the IP0 and IP1 registers to be clobbered. */
2256 if ((r_type
== AARCH64_R (CALL26
) || r_type
== AARCH64_R (JUMP26
))
2257 && (branch_offset
> AARCH64_MAX_FWD_BRANCH_OFFSET
2258 || branch_offset
< AARCH64_MAX_BWD_BRANCH_OFFSET
))
2260 stub_type
= aarch64_stub_long_branch
;
2266 /* Build a name for an entry in the stub hash table. */
2269 elfNN_aarch64_stub_name (const asection
*input_section
,
2270 const asection
*sym_sec
,
2271 const struct elf_aarch64_link_hash_entry
*hash
,
2272 const Elf_Internal_Rela
*rel
)
2279 len
= 8 + 1 + strlen (hash
->root
.root
.root
.string
) + 1 + 16 + 1;
2280 stub_name
= bfd_malloc (len
);
2281 if (stub_name
!= NULL
)
2282 snprintf (stub_name
, len
, "%08x_%s+%" BFD_VMA_FMT
"x",
2283 (unsigned int) input_section
->id
,
2284 hash
->root
.root
.root
.string
,
2289 len
= 8 + 1 + 8 + 1 + 8 + 1 + 16 + 1;
2290 stub_name
= bfd_malloc (len
);
2291 if (stub_name
!= NULL
)
2292 snprintf (stub_name
, len
, "%08x_%x:%x+%" BFD_VMA_FMT
"x",
2293 (unsigned int) input_section
->id
,
2294 (unsigned int) sym_sec
->id
,
2295 (unsigned int) ELFNN_R_SYM (rel
->r_info
),
2302 /* Look up an entry in the stub hash. Stub entries are cached because
2303 creating the stub name takes a bit of time. */
2305 static struct elf_aarch64_stub_hash_entry
*
2306 elfNN_aarch64_get_stub_entry (const asection
*input_section
,
2307 const asection
*sym_sec
,
2308 struct elf_link_hash_entry
*hash
,
2309 const Elf_Internal_Rela
*rel
,
2310 struct elf_aarch64_link_hash_table
*htab
)
2312 struct elf_aarch64_stub_hash_entry
*stub_entry
;
2313 struct elf_aarch64_link_hash_entry
*h
=
2314 (struct elf_aarch64_link_hash_entry
*) hash
;
2315 const asection
*id_sec
;
2317 if ((input_section
->flags
& SEC_CODE
) == 0)
2320 /* If this input section is part of a group of sections sharing one
2321 stub section, then use the id of the first section in the group.
2322 Stub names need to include a section id, as there may well be
2323 more than one stub used to reach say, printf, and we need to
2324 distinguish between them. */
2325 id_sec
= htab
->stub_group
[input_section
->id
].link_sec
;
2327 if (h
!= NULL
&& h
->stub_cache
!= NULL
2328 && h
->stub_cache
->h
== h
&& h
->stub_cache
->id_sec
== id_sec
)
2330 stub_entry
= h
->stub_cache
;
2336 stub_name
= elfNN_aarch64_stub_name (id_sec
, sym_sec
, h
, rel
);
2337 if (stub_name
== NULL
)
2340 stub_entry
= aarch64_stub_hash_lookup (&htab
->stub_hash_table
,
2341 stub_name
, FALSE
, FALSE
);
2343 h
->stub_cache
= stub_entry
;
2352 /* Create a stub section. */
2355 _bfd_aarch64_create_stub_section (asection
*section
,
2356 struct elf_aarch64_link_hash_table
*htab
)
2362 namelen
= strlen (section
->name
);
2363 len
= namelen
+ sizeof (STUB_SUFFIX
);
2364 s_name
= bfd_alloc (htab
->stub_bfd
, len
);
2368 memcpy (s_name
, section
->name
, namelen
);
2369 memcpy (s_name
+ namelen
, STUB_SUFFIX
, sizeof (STUB_SUFFIX
));
2370 return (*htab
->add_stub_section
) (s_name
, section
);
2374 /* Find or create a stub section for a link section.
2376 Fix or create the stub section used to collect stubs attached to
2377 the specified link section. */
2380 _bfd_aarch64_get_stub_for_link_section (asection
*link_section
,
2381 struct elf_aarch64_link_hash_table
*htab
)
2383 if (htab
->stub_group
[link_section
->id
].stub_sec
== NULL
)
2384 htab
->stub_group
[link_section
->id
].stub_sec
2385 = _bfd_aarch64_create_stub_section (link_section
, htab
);
2386 return htab
->stub_group
[link_section
->id
].stub_sec
;
2390 /* Find or create a stub section in the stub group for an input
2394 _bfd_aarch64_create_or_find_stub_sec (asection
*section
,
2395 struct elf_aarch64_link_hash_table
*htab
)
2397 asection
*link_sec
= htab
->stub_group
[section
->id
].link_sec
;
2398 return _bfd_aarch64_get_stub_for_link_section (link_sec
, htab
);
2402 /* Add a new stub entry in the stub group associated with an input
2403 section to the stub hash. Not all fields of the new stub entry are
2406 static struct elf_aarch64_stub_hash_entry
*
2407 _bfd_aarch64_add_stub_entry_in_group (const char *stub_name
,
2409 struct elf_aarch64_link_hash_table
*htab
)
2413 struct elf_aarch64_stub_hash_entry
*stub_entry
;
2415 link_sec
= htab
->stub_group
[section
->id
].link_sec
;
2416 stub_sec
= _bfd_aarch64_create_or_find_stub_sec (section
, htab
);
2418 /* Enter this entry into the linker stub hash table. */
2419 stub_entry
= aarch64_stub_hash_lookup (&htab
->stub_hash_table
, stub_name
,
2421 if (stub_entry
== NULL
)
2423 (*_bfd_error_handler
) (_("%s: cannot create stub entry %s"),
2424 section
->owner
, stub_name
);
2428 stub_entry
->stub_sec
= stub_sec
;
2429 stub_entry
->stub_offset
= 0;
2430 stub_entry
->id_sec
= link_sec
;
2435 /* Add a new stub entry in the final stub section to the stub hash.
2436 Not all fields of the new stub entry are initialised. */
2438 static struct elf_aarch64_stub_hash_entry
*
2439 _bfd_aarch64_add_stub_entry_after (const char *stub_name
,
2440 asection
*link_section
,
2441 struct elf_aarch64_link_hash_table
*htab
)
2444 struct elf_aarch64_stub_hash_entry
*stub_entry
;
2446 stub_sec
= _bfd_aarch64_get_stub_for_link_section (link_section
, htab
);
2447 stub_entry
= aarch64_stub_hash_lookup (&htab
->stub_hash_table
, stub_name
,
2449 if (stub_entry
== NULL
)
2451 (*_bfd_error_handler
) (_("cannot create stub entry %s"), stub_name
);
2455 stub_entry
->stub_sec
= stub_sec
;
2456 stub_entry
->stub_offset
= 0;
2457 stub_entry
->id_sec
= link_section
;
2464 aarch64_build_one_stub (struct bfd_hash_entry
*gen_entry
,
2465 void *in_arg ATTRIBUTE_UNUSED
)
2467 struct elf_aarch64_stub_hash_entry
*stub_entry
;
2472 bfd_vma veneered_insn_loc
;
2473 bfd_vma veneer_entry_loc
;
2474 bfd_signed_vma branch_offset
= 0;
2475 unsigned int template_size
;
2476 const uint32_t *template;
2479 /* Massage our args to the form they really have. */
2480 stub_entry
= (struct elf_aarch64_stub_hash_entry
*) gen_entry
;
2482 stub_sec
= stub_entry
->stub_sec
;
2484 /* Make a note of the offset within the stubs for this entry. */
2485 stub_entry
->stub_offset
= stub_sec
->size
;
2486 loc
= stub_sec
->contents
+ stub_entry
->stub_offset
;
2488 stub_bfd
= stub_sec
->owner
;
2490 /* This is the address of the stub destination. */
2491 sym_value
= (stub_entry
->target_value
2492 + stub_entry
->target_section
->output_offset
2493 + stub_entry
->target_section
->output_section
->vma
);
2495 if (stub_entry
->stub_type
== aarch64_stub_long_branch
)
2497 bfd_vma place
= (stub_entry
->stub_offset
+ stub_sec
->output_section
->vma
2498 + stub_sec
->output_offset
);
2500 /* See if we can relax the stub. */
2501 if (aarch64_valid_for_adrp_p (sym_value
, place
))
2502 stub_entry
->stub_type
= aarch64_select_branch_stub (sym_value
, place
);
2505 switch (stub_entry
->stub_type
)
2507 case aarch64_stub_adrp_branch
:
2508 template = aarch64_adrp_branch_stub
;
2509 template_size
= sizeof (aarch64_adrp_branch_stub
);
2511 case aarch64_stub_long_branch
:
2512 template = aarch64_long_branch_stub
;
2513 template_size
= sizeof (aarch64_long_branch_stub
);
2515 case aarch64_stub_erratum_835769_veneer
:
2516 template = aarch64_erratum_835769_stub
;
2517 template_size
= sizeof (aarch64_erratum_835769_stub
);
2519 case aarch64_stub_erratum_843419_veneer
:
2520 template = aarch64_erratum_843419_stub
;
2521 template_size
= sizeof (aarch64_erratum_843419_stub
);
2527 for (i
= 0; i
< (template_size
/ sizeof template[0]); i
++)
2529 bfd_putl32 (template[i
], loc
);
2533 template_size
= (template_size
+ 7) & ~7;
2534 stub_sec
->size
+= template_size
;
2536 switch (stub_entry
->stub_type
)
2538 case aarch64_stub_adrp_branch
:
2539 if (aarch64_relocate (AARCH64_R (ADR_PREL_PG_HI21
), stub_bfd
, stub_sec
,
2540 stub_entry
->stub_offset
, sym_value
))
2541 /* The stub would not have been relaxed if the offset was out
2545 if (aarch64_relocate (AARCH64_R (ADD_ABS_LO12_NC
), stub_bfd
, stub_sec
,
2546 stub_entry
->stub_offset
+ 4, sym_value
))
2550 case aarch64_stub_long_branch
:
2551 /* We want the value relative to the address 12 bytes back from the
2553 if (aarch64_relocate (AARCH64_R (PRELNN
), stub_bfd
, stub_sec
,
2554 stub_entry
->stub_offset
+ 16, sym_value
+ 12))
2558 case aarch64_stub_erratum_835769_veneer
:
2559 veneered_insn_loc
= stub_entry
->target_section
->output_section
->vma
2560 + stub_entry
->target_section
->output_offset
2561 + stub_entry
->target_value
;
2562 veneer_entry_loc
= stub_entry
->stub_sec
->output_section
->vma
2563 + stub_entry
->stub_sec
->output_offset
2564 + stub_entry
->stub_offset
;
2565 branch_offset
= veneered_insn_loc
- veneer_entry_loc
;
2566 branch_offset
>>= 2;
2567 branch_offset
&= 0x3ffffff;
2568 bfd_putl32 (stub_entry
->veneered_insn
,
2569 stub_sec
->contents
+ stub_entry
->stub_offset
);
2570 bfd_putl32 (template[1] | branch_offset
,
2571 stub_sec
->contents
+ stub_entry
->stub_offset
+ 4);
2574 case aarch64_stub_erratum_843419_veneer
:
2575 if (aarch64_relocate (AARCH64_R (JUMP26
), stub_bfd
, stub_sec
,
2576 stub_entry
->stub_offset
+ 4, sym_value
+ 4))
2587 /* As above, but don't actually build the stub. Just bump offset so
2588 we know stub section sizes. */
2591 aarch64_size_one_stub (struct bfd_hash_entry
*gen_entry
,
2592 void *in_arg ATTRIBUTE_UNUSED
)
2594 struct elf_aarch64_stub_hash_entry
*stub_entry
;
2597 /* Massage our args to the form they really have. */
2598 stub_entry
= (struct elf_aarch64_stub_hash_entry
*) gen_entry
;
2600 switch (stub_entry
->stub_type
)
2602 case aarch64_stub_adrp_branch
:
2603 size
= sizeof (aarch64_adrp_branch_stub
);
2605 case aarch64_stub_long_branch
:
2606 size
= sizeof (aarch64_long_branch_stub
);
2608 case aarch64_stub_erratum_835769_veneer
:
2609 size
= sizeof (aarch64_erratum_835769_stub
);
2611 case aarch64_stub_erratum_843419_veneer
:
2612 size
= sizeof (aarch64_erratum_843419_stub
);
2618 size
= (size
+ 7) & ~7;
2619 stub_entry
->stub_sec
->size
+= size
;
2623 /* External entry points for sizing and building linker stubs. */
2625 /* Set up various things so that we can make a list of input sections
2626 for each output section included in the link. Returns -1 on error,
2627 0 when no stubs will be needed, and 1 on success. */
2630 elfNN_aarch64_setup_section_lists (bfd
*output_bfd
,
2631 struct bfd_link_info
*info
)
2634 unsigned int bfd_count
;
2635 int top_id
, top_index
;
2637 asection
**input_list
, **list
;
2639 struct elf_aarch64_link_hash_table
*htab
=
2640 elf_aarch64_hash_table (info
);
2642 if (!is_elf_hash_table (htab
))
2645 /* Count the number of input BFDs and find the top input section id. */
2646 for (input_bfd
= info
->input_bfds
, bfd_count
= 0, top_id
= 0;
2647 input_bfd
!= NULL
; input_bfd
= input_bfd
->link
.next
)
2650 for (section
= input_bfd
->sections
;
2651 section
!= NULL
; section
= section
->next
)
2653 if (top_id
< section
->id
)
2654 top_id
= section
->id
;
2657 htab
->bfd_count
= bfd_count
;
2659 amt
= sizeof (struct map_stub
) * (top_id
+ 1);
2660 htab
->stub_group
= bfd_zmalloc (amt
);
2661 if (htab
->stub_group
== NULL
)
2664 /* We can't use output_bfd->section_count here to find the top output
2665 section index as some sections may have been removed, and
2666 _bfd_strip_section_from_output doesn't renumber the indices. */
2667 for (section
= output_bfd
->sections
, top_index
= 0;
2668 section
!= NULL
; section
= section
->next
)
2670 if (top_index
< section
->index
)
2671 top_index
= section
->index
;
2674 htab
->top_index
= top_index
;
2675 amt
= sizeof (asection
*) * (top_index
+ 1);
2676 input_list
= bfd_malloc (amt
);
2677 htab
->input_list
= input_list
;
2678 if (input_list
== NULL
)
2681 /* For sections we aren't interested in, mark their entries with a
2682 value we can check later. */
2683 list
= input_list
+ top_index
;
2685 *list
= bfd_abs_section_ptr
;
2686 while (list
-- != input_list
);
2688 for (section
= output_bfd
->sections
;
2689 section
!= NULL
; section
= section
->next
)
2691 if ((section
->flags
& SEC_CODE
) != 0)
2692 input_list
[section
->index
] = NULL
;
2698 /* Used by elfNN_aarch64_next_input_section and group_sections. */
2699 #define PREV_SEC(sec) (htab->stub_group[(sec)->id].link_sec)
2701 /* The linker repeatedly calls this function for each input section,
2702 in the order that input sections are linked into output sections.
2703 Build lists of input sections to determine groupings between which
2704 we may insert linker stubs. */
2707 elfNN_aarch64_next_input_section (struct bfd_link_info
*info
, asection
*isec
)
2709 struct elf_aarch64_link_hash_table
*htab
=
2710 elf_aarch64_hash_table (info
);
2712 if (isec
->output_section
->index
<= htab
->top_index
)
2714 asection
**list
= htab
->input_list
+ isec
->output_section
->index
;
2716 if (*list
!= bfd_abs_section_ptr
)
2718 /* Steal the link_sec pointer for our list. */
2719 /* This happens to make the list in reverse order,
2720 which is what we want. */
2721 PREV_SEC (isec
) = *list
;
2727 /* See whether we can group stub sections together. Grouping stub
2728 sections may result in fewer stubs. More importantly, we need to
2729 put all .init* and .fini* stubs at the beginning of the .init or
2730 .fini output sections respectively, because glibc splits the
2731 _init and _fini functions into multiple parts. Putting a stub in
2732 the middle of a function is not a good idea. */
2735 group_sections (struct elf_aarch64_link_hash_table
*htab
,
2736 bfd_size_type stub_group_size
,
2737 bfd_boolean stubs_always_before_branch
)
2739 asection
**list
= htab
->input_list
+ htab
->top_index
;
2743 asection
*tail
= *list
;
2745 if (tail
== bfd_abs_section_ptr
)
2748 while (tail
!= NULL
)
2752 bfd_size_type total
;
2756 while ((prev
= PREV_SEC (curr
)) != NULL
2757 && ((total
+= curr
->output_offset
- prev
->output_offset
)
2761 /* OK, the size from the start of CURR to the end is less
2762 than stub_group_size and thus can be handled by one stub
2763 section. (Or the tail section is itself larger than
2764 stub_group_size, in which case we may be toast.)
2765 We should really be keeping track of the total size of
2766 stubs added here, as stubs contribute to the final output
2770 prev
= PREV_SEC (tail
);
2771 /* Set up this stub group. */
2772 htab
->stub_group
[tail
->id
].link_sec
= curr
;
2774 while (tail
!= curr
&& (tail
= prev
) != NULL
);
2776 /* But wait, there's more! Input sections up to stub_group_size
2777 bytes before the stub section can be handled by it too. */
2778 if (!stubs_always_before_branch
)
2782 && ((total
+= tail
->output_offset
- prev
->output_offset
)
2786 prev
= PREV_SEC (tail
);
2787 htab
->stub_group
[tail
->id
].link_sec
= curr
;
2793 while (list
-- != htab
->input_list
);
2795 free (htab
->input_list
);
2800 #define AARCH64_BITS(x, pos, n) (((x) >> (pos)) & ((1 << (n)) - 1))
2802 #define AARCH64_RT(insn) AARCH64_BITS (insn, 0, 5)
2803 #define AARCH64_RT2(insn) AARCH64_BITS (insn, 10, 5)
2804 #define AARCH64_RA(insn) AARCH64_BITS (insn, 10, 5)
2805 #define AARCH64_RD(insn) AARCH64_BITS (insn, 0, 5)
2806 #define AARCH64_RN(insn) AARCH64_BITS (insn, 5, 5)
2807 #define AARCH64_RM(insn) AARCH64_BITS (insn, 16, 5)
2809 #define AARCH64_MAC(insn) (((insn) & 0xff000000) == 0x9b000000)
2810 #define AARCH64_BIT(insn, n) AARCH64_BITS (insn, n, 1)
2811 #define AARCH64_OP31(insn) AARCH64_BITS (insn, 21, 3)
2812 #define AARCH64_ZR 0x1f
2814 /* All ld/st ops. See C4-182 of the ARM ARM. The encoding space for
2815 LD_PCREL, LDST_RO, LDST_UI and LDST_UIMM cover prefetch ops. */
2817 #define AARCH64_LD(insn) (AARCH64_BIT (insn, 22) == 1)
2818 #define AARCH64_LDST(insn) (((insn) & 0x0a000000) == 0x08000000)
2819 #define AARCH64_LDST_EX(insn) (((insn) & 0x3f000000) == 0x08000000)
2820 #define AARCH64_LDST_PCREL(insn) (((insn) & 0x3b000000) == 0x18000000)
2821 #define AARCH64_LDST_NAP(insn) (((insn) & 0x3b800000) == 0x28000000)
2822 #define AARCH64_LDSTP_PI(insn) (((insn) & 0x3b800000) == 0x28800000)
2823 #define AARCH64_LDSTP_O(insn) (((insn) & 0x3b800000) == 0x29000000)
2824 #define AARCH64_LDSTP_PRE(insn) (((insn) & 0x3b800000) == 0x29800000)
2825 #define AARCH64_LDST_UI(insn) (((insn) & 0x3b200c00) == 0x38000000)
2826 #define AARCH64_LDST_PIIMM(insn) (((insn) & 0x3b200c00) == 0x38000400)
2827 #define AARCH64_LDST_U(insn) (((insn) & 0x3b200c00) == 0x38000800)
2828 #define AARCH64_LDST_PREIMM(insn) (((insn) & 0x3b200c00) == 0x38000c00)
2829 #define AARCH64_LDST_RO(insn) (((insn) & 0x3b200c00) == 0x38200800)
2830 #define AARCH64_LDST_UIMM(insn) (((insn) & 0x3b000000) == 0x39000000)
2831 #define AARCH64_LDST_SIMD_M(insn) (((insn) & 0xbfbf0000) == 0x0c000000)
2832 #define AARCH64_LDST_SIMD_M_PI(insn) (((insn) & 0xbfa00000) == 0x0c800000)
2833 #define AARCH64_LDST_SIMD_S(insn) (((insn) & 0xbf9f0000) == 0x0d000000)
2834 #define AARCH64_LDST_SIMD_S_PI(insn) (((insn) & 0xbf800000) == 0x0d800000)
2836 /* Classify an INSN if it is indeed a load/store.
2838 Return TRUE if INSN is a LD/ST instruction otherwise return FALSE.
2840 For scalar LD/ST instructions PAIR is FALSE, RT is returned and RT2
2843 For LD/ST pair instructions PAIR is TRUE, RT and RT2 are returned.
2848 aarch64_mem_op_p (uint32_t insn
, unsigned int *rt
, unsigned int *rt2
,
2849 bfd_boolean
*pair
, bfd_boolean
*load
)
2857 /* Bail out quickly if INSN doesn't fall into the the load-store
2859 if (!AARCH64_LDST (insn
))
2864 if (AARCH64_LDST_EX (insn
))
2866 *rt
= AARCH64_RT (insn
);
2868 if (AARCH64_BIT (insn
, 21) == 1)
2871 *rt2
= AARCH64_RT2 (insn
);
2873 *load
= AARCH64_LD (insn
);
2876 else if (AARCH64_LDST_NAP (insn
)
2877 || AARCH64_LDSTP_PI (insn
)
2878 || AARCH64_LDSTP_O (insn
)
2879 || AARCH64_LDSTP_PRE (insn
))
2882 *rt
= AARCH64_RT (insn
);
2883 *rt2
= AARCH64_RT2 (insn
);
2884 *load
= AARCH64_LD (insn
);
2887 else if (AARCH64_LDST_PCREL (insn
)
2888 || AARCH64_LDST_UI (insn
)
2889 || AARCH64_LDST_PIIMM (insn
)
2890 || AARCH64_LDST_U (insn
)
2891 || AARCH64_LDST_PREIMM (insn
)
2892 || AARCH64_LDST_RO (insn
)
2893 || AARCH64_LDST_UIMM (insn
))
2895 *rt
= AARCH64_RT (insn
);
2897 if (AARCH64_LDST_PCREL (insn
))
2899 opc
= AARCH64_BITS (insn
, 22, 2);
2900 v
= AARCH64_BIT (insn
, 26);
2901 opc_v
= opc
| (v
<< 2);
2902 *load
= (opc_v
== 1 || opc_v
== 2 || opc_v
== 3
2903 || opc_v
== 5 || opc_v
== 7);
2906 else if (AARCH64_LDST_SIMD_M (insn
)
2907 || AARCH64_LDST_SIMD_M_PI (insn
))
2909 *rt
= AARCH64_RT (insn
);
2910 *load
= AARCH64_BIT (insn
, 22);
2911 opcode
= (insn
>> 12) & 0xf;
2938 else if (AARCH64_LDST_SIMD_S (insn
)
2939 || AARCH64_LDST_SIMD_S_PI (insn
))
2941 *rt
= AARCH64_RT (insn
);
2942 r
= (insn
>> 21) & 1;
2943 *load
= AARCH64_BIT (insn
, 22);
2944 opcode
= (insn
>> 13) & 0x7;
2956 *rt2
= *rt
+ (r
== 0 ? 2 : 3);
2964 *rt2
= *rt
+ (r
== 0 ? 2 : 3);
2976 /* Return TRUE if INSN is multiply-accumulate. */
2979 aarch64_mlxl_p (uint32_t insn
)
2981 uint32_t op31
= AARCH64_OP31 (insn
);
2983 if (AARCH64_MAC (insn
)
2984 && (op31
== 0 || op31
== 1 || op31
== 5)
2985 /* Exclude MUL instructions which are encoded as a multiple accumulate
2987 && AARCH64_RA (insn
) != AARCH64_ZR
)
2993 /* Some early revisions of the Cortex-A53 have an erratum (835769) whereby
2994 it is possible for a 64-bit multiply-accumulate instruction to generate an
2995 incorrect result. The details are quite complex and hard to
2996 determine statically, since branches in the code may exist in some
2997 circumstances, but all cases end with a memory (load, store, or
2998 prefetch) instruction followed immediately by the multiply-accumulate
2999 operation. We employ a linker patching technique, by moving the potentially
3000 affected multiply-accumulate instruction into a patch region and replacing
3001 the original instruction with a branch to the patch. This function checks
3002 if INSN_1 is the memory operation followed by a multiply-accumulate
3003 operation (INSN_2). Return TRUE if an erratum sequence is found, FALSE
3004 if INSN_1 and INSN_2 are safe. */
3007 aarch64_erratum_sequence (uint32_t insn_1
, uint32_t insn_2
)
3017 if (aarch64_mlxl_p (insn_2
)
3018 && aarch64_mem_op_p (insn_1
, &rt
, &rt2
, &pair
, &load
))
3020 /* Any SIMD memory op is independent of the subsequent MLA
3021 by definition of the erratum. */
3022 if (AARCH64_BIT (insn_1
, 26))
3025 /* If not SIMD, check for integer memory ops and MLA relationship. */
3026 rn
= AARCH64_RN (insn_2
);
3027 ra
= AARCH64_RA (insn_2
);
3028 rm
= AARCH64_RM (insn_2
);
3030 /* If this is a load and there's a true(RAW) dependency, we are safe
3031 and this is not an erratum sequence. */
3033 (rt
== rn
|| rt
== rm
|| rt
== ra
3034 || (pair
&& (rt2
== rn
|| rt2
== rm
|| rt2
== ra
))))
3037 /* We conservatively put out stubs for all other cases (including
3045 /* Used to order a list of mapping symbols by address. */
3048 elf_aarch64_compare_mapping (const void *a
, const void *b
)
3050 const elf_aarch64_section_map
*amap
= (const elf_aarch64_section_map
*) a
;
3051 const elf_aarch64_section_map
*bmap
= (const elf_aarch64_section_map
*) b
;
3053 if (amap
->vma
> bmap
->vma
)
3055 else if (amap
->vma
< bmap
->vma
)
3057 else if (amap
->type
> bmap
->type
)
3058 /* Ensure results do not depend on the host qsort for objects with
3059 multiple mapping symbols at the same address by sorting on type
3062 else if (amap
->type
< bmap
->type
)
3070 _bfd_aarch64_erratum_835769_stub_name (unsigned num_fixes
)
3072 char *stub_name
= (char *) bfd_malloc
3073 (strlen ("__erratum_835769_veneer_") + 16);
3074 sprintf (stub_name
,"__erratum_835769_veneer_%d", num_fixes
);
3078 /* Scan for Cortex-A53 erratum 835769 sequence.
3080 Return TRUE else FALSE on abnormal termination. */
3083 _bfd_aarch64_erratum_835769_scan (bfd
*input_bfd
,
3084 struct bfd_link_info
*info
,
3085 unsigned int *num_fixes_p
)
3088 struct elf_aarch64_link_hash_table
*htab
= elf_aarch64_hash_table (info
);
3089 unsigned int num_fixes
= *num_fixes_p
;
3094 for (section
= input_bfd
->sections
;
3096 section
= section
->next
)
3098 bfd_byte
*contents
= NULL
;
3099 struct _aarch64_elf_section_data
*sec_data
;
3102 if (elf_section_type (section
) != SHT_PROGBITS
3103 || (elf_section_flags (section
) & SHF_EXECINSTR
) == 0
3104 || (section
->flags
& SEC_EXCLUDE
) != 0
3105 || (section
->sec_info_type
== SEC_INFO_TYPE_JUST_SYMS
)
3106 || (section
->output_section
== bfd_abs_section_ptr
))
3109 if (elf_section_data (section
)->this_hdr
.contents
!= NULL
)
3110 contents
= elf_section_data (section
)->this_hdr
.contents
;
3111 else if (! bfd_malloc_and_get_section (input_bfd
, section
, &contents
))
3114 sec_data
= elf_aarch64_section_data (section
);
3116 qsort (sec_data
->map
, sec_data
->mapcount
,
3117 sizeof (elf_aarch64_section_map
), elf_aarch64_compare_mapping
);
3119 for (span
= 0; span
< sec_data
->mapcount
; span
++)
3121 unsigned int span_start
= sec_data
->map
[span
].vma
;
3122 unsigned int span_end
= ((span
== sec_data
->mapcount
- 1)
3123 ? sec_data
->map
[0].vma
+ section
->size
3124 : sec_data
->map
[span
+ 1].vma
);
3126 char span_type
= sec_data
->map
[span
].type
;
3128 if (span_type
== 'd')
3131 for (i
= span_start
; i
+ 4 < span_end
; i
+= 4)
3133 uint32_t insn_1
= bfd_getl32 (contents
+ i
);
3134 uint32_t insn_2
= bfd_getl32 (contents
+ i
+ 4);
3136 if (aarch64_erratum_sequence (insn_1
, insn_2
))
3138 struct elf_aarch64_stub_hash_entry
*stub_entry
;
3139 char *stub_name
= _bfd_aarch64_erratum_835769_stub_name (num_fixes
);
3143 stub_entry
= _bfd_aarch64_add_stub_entry_in_group (stub_name
,
3149 stub_entry
->stub_type
= aarch64_stub_erratum_835769_veneer
;
3150 stub_entry
->target_section
= section
;
3151 stub_entry
->target_value
= i
+ 4;
3152 stub_entry
->veneered_insn
= insn_2
;
3153 stub_entry
->output_name
= stub_name
;
3158 if (elf_section_data (section
)->this_hdr
.contents
== NULL
)
3162 *num_fixes_p
= num_fixes
;
3168 /* Test if instruction INSN is ADRP. */
3171 _bfd_aarch64_adrp_p (uint32_t insn
)
3173 return ((insn
& 0x9f000000) == 0x90000000);
3177 /* Helper predicate to look for cortex-a53 erratum 843419 sequence 1. */
3180 _bfd_aarch64_erratum_843419_sequence_p (uint32_t insn_1
, uint32_t insn_2
,
3188 return (aarch64_mem_op_p (insn_2
, &rt
, &rt2
, &pair
, &load
)
3191 && AARCH64_LDST_UIMM (insn_3
)
3192 && AARCH64_RN (insn_3
) == AARCH64_RD (insn_1
));
3196 /* Test for the presence of Cortex-A53 erratum 843419 instruction sequence.
3198 Return TRUE if section CONTENTS at offset I contains one of the
3199 erratum 843419 sequences, otherwise return FALSE. If a sequence is
3200 seen set P_VENEER_I to the offset of the final LOAD/STORE
3201 instruction in the sequence.
3205 _bfd_aarch64_erratum_843419_p (bfd_byte
*contents
, bfd_vma vma
,
3206 bfd_vma i
, bfd_vma span_end
,
3207 bfd_vma
*p_veneer_i
)
3209 uint32_t insn_1
= bfd_getl32 (contents
+ i
);
3211 if (!_bfd_aarch64_adrp_p (insn_1
))
3214 if (span_end
< i
+ 12)
3217 uint32_t insn_2
= bfd_getl32 (contents
+ i
+ 4);
3218 uint32_t insn_3
= bfd_getl32 (contents
+ i
+ 8);
3220 if ((vma
& 0xfff) != 0xff8 && (vma
& 0xfff) != 0xffc)
3223 if (_bfd_aarch64_erratum_843419_sequence_p (insn_1
, insn_2
, insn_3
))
3225 *p_veneer_i
= i
+ 8;
3229 if (span_end
< i
+ 16)
3232 uint32_t insn_4
= bfd_getl32 (contents
+ i
+ 12);
3234 if (_bfd_aarch64_erratum_843419_sequence_p (insn_1
, insn_2
, insn_4
))
3236 *p_veneer_i
= i
+ 12;
3244 /* Resize all stub sections. */
3247 _bfd_aarch64_resize_stubs (struct elf_aarch64_link_hash_table
*htab
)
3251 /* OK, we've added some stubs. Find out the new size of the
3253 for (section
= htab
->stub_bfd
->sections
;
3254 section
!= NULL
; section
= section
->next
)
3256 /* Ignore non-stub sections. */
3257 if (!strstr (section
->name
, STUB_SUFFIX
))
3262 bfd_hash_traverse (&htab
->stub_hash_table
, aarch64_size_one_stub
, htab
);
3264 for (section
= htab
->stub_bfd
->sections
;
3265 section
!= NULL
; section
= section
->next
)
3267 if (!strstr (section
->name
, STUB_SUFFIX
))
3273 /* Ensure all stub sections have a size which is a multiple of
3274 4096. This is important in order to ensure that the insertion
3275 of stub sections does not in itself move existing code around
3276 in such a way that new errata sequences are created. */
3277 if (htab
->fix_erratum_843419
)
3279 section
->size
= BFD_ALIGN (section
->size
, 0x1000);
3284 /* Construct an erratum 843419 workaround stub name.
3288 _bfd_aarch64_erratum_843419_stub_name (asection
*input_section
,
3291 const bfd_size_type len
= 8 + 4 + 1 + 8 + 1 + 16 + 1;
3292 char *stub_name
= bfd_malloc (len
);
3294 if (stub_name
!= NULL
)
3295 snprintf (stub_name
, len
, "e843419@%04x_%08x_%" BFD_VMA_FMT
"x",
3296 input_section
->owner
->id
,
3302 /* Build a stub_entry structure describing an 843419 fixup.
3304 The stub_entry constructed is populated with the bit pattern INSN
3305 of the instruction located at OFFSET within input SECTION.
3307 Returns TRUE on success. */
3310 _bfd_aarch64_erratum_843419_fixup (uint32_t insn
,
3311 bfd_vma adrp_offset
,
3312 bfd_vma ldst_offset
,
3314 struct bfd_link_info
*info
)
3316 struct elf_aarch64_link_hash_table
*htab
= elf_aarch64_hash_table (info
);
3318 struct elf_aarch64_stub_hash_entry
*stub_entry
;
3320 stub_name
= _bfd_aarch64_erratum_843419_stub_name (section
, ldst_offset
);
3321 stub_entry
= aarch64_stub_hash_lookup (&htab
->stub_hash_table
, stub_name
,
3329 /* We always place an 843419 workaround veneer in the stub section
3330 attached to the input section in which an erratum sequence has
3331 been found. This ensures that later in the link process (in
3332 elfNN_aarch64_write_section) when we copy the veneered
3333 instruction from the input section into the stub section the
3334 copied instruction will have had any relocations applied to it.
3335 If we placed workaround veneers in any other stub section then we
3336 could not assume that all relocations have been processed on the
3337 corresponding input section at the point we output the stub
3341 stub_entry
= _bfd_aarch64_add_stub_entry_after (stub_name
, section
, htab
);
3342 if (stub_entry
== NULL
)
3348 stub_entry
->adrp_offset
= adrp_offset
;
3349 stub_entry
->target_value
= ldst_offset
;
3350 stub_entry
->target_section
= section
;
3351 stub_entry
->stub_type
= aarch64_stub_erratum_843419_veneer
;
3352 stub_entry
->veneered_insn
= insn
;
3353 stub_entry
->output_name
= stub_name
;
3359 /* Scan an input section looking for the signature of erratum 843419.
3361 Scans input SECTION in INPUT_BFD looking for erratum 843419
3362 signatures, for each signature found a stub_entry is created
3363 describing the location of the erratum for subsequent fixup.
3365 Return TRUE on successful scan, FALSE on failure to scan.
3369 _bfd_aarch64_erratum_843419_scan (bfd
*input_bfd
, asection
*section
,
3370 struct bfd_link_info
*info
)
3372 struct elf_aarch64_link_hash_table
*htab
= elf_aarch64_hash_table (info
);
3377 if (elf_section_type (section
) != SHT_PROGBITS
3378 || (elf_section_flags (section
) & SHF_EXECINSTR
) == 0
3379 || (section
->flags
& SEC_EXCLUDE
) != 0
3380 || (section
->sec_info_type
== SEC_INFO_TYPE_JUST_SYMS
)
3381 || (section
->output_section
== bfd_abs_section_ptr
))
3386 bfd_byte
*contents
= NULL
;
3387 struct _aarch64_elf_section_data
*sec_data
;
3390 if (elf_section_data (section
)->this_hdr
.contents
!= NULL
)
3391 contents
= elf_section_data (section
)->this_hdr
.contents
;
3392 else if (! bfd_malloc_and_get_section (input_bfd
, section
, &contents
))
3395 sec_data
= elf_aarch64_section_data (section
);
3397 qsort (sec_data
->map
, sec_data
->mapcount
,
3398 sizeof (elf_aarch64_section_map
), elf_aarch64_compare_mapping
);
3400 for (span
= 0; span
< sec_data
->mapcount
; span
++)
3402 unsigned int span_start
= sec_data
->map
[span
].vma
;
3403 unsigned int span_end
= ((span
== sec_data
->mapcount
- 1)
3404 ? sec_data
->map
[0].vma
+ section
->size
3405 : sec_data
->map
[span
+ 1].vma
);
3407 char span_type
= sec_data
->map
[span
].type
;
3409 if (span_type
== 'd')
3412 for (i
= span_start
; i
+ 8 < span_end
; i
+= 4)
3414 bfd_vma vma
= (section
->output_section
->vma
3415 + section
->output_offset
3419 if (_bfd_aarch64_erratum_843419_p
3420 (contents
, vma
, i
, span_end
, &veneer_i
))
3422 uint32_t insn
= bfd_getl32 (contents
+ veneer_i
);
3424 if (!_bfd_aarch64_erratum_843419_fixup (insn
, i
, veneer_i
,
3431 if (elf_section_data (section
)->this_hdr
.contents
== NULL
)
3440 /* Determine and set the size of the stub section for a final link.
3442 The basic idea here is to examine all the relocations looking for
3443 PC-relative calls to a target that is unreachable with a "bl"
3447 elfNN_aarch64_size_stubs (bfd
*output_bfd
,
3449 struct bfd_link_info
*info
,
3450 bfd_signed_vma group_size
,
3451 asection
* (*add_stub_section
) (const char *,
3453 void (*layout_sections_again
) (void))
3455 bfd_size_type stub_group_size
;
3456 bfd_boolean stubs_always_before_branch
;
3457 bfd_boolean stub_changed
= FALSE
;
3458 struct elf_aarch64_link_hash_table
*htab
= elf_aarch64_hash_table (info
);
3459 unsigned int num_erratum_835769_fixes
= 0;
3461 /* Propagate mach to stub bfd, because it may not have been
3462 finalized when we created stub_bfd. */
3463 bfd_set_arch_mach (stub_bfd
, bfd_get_arch (output_bfd
),
3464 bfd_get_mach (output_bfd
));
3466 /* Stash our params away. */
3467 htab
->stub_bfd
= stub_bfd
;
3468 htab
->add_stub_section
= add_stub_section
;
3469 htab
->layout_sections_again
= layout_sections_again
;
3470 stubs_always_before_branch
= group_size
< 0;
3472 stub_group_size
= -group_size
;
3474 stub_group_size
= group_size
;
3476 if (stub_group_size
== 1)
3478 /* Default values. */
3479 /* AArch64 branch range is +-128MB. The value used is 1MB less. */
3480 stub_group_size
= 127 * 1024 * 1024;
3483 group_sections (htab
, stub_group_size
, stubs_always_before_branch
);
3485 (*htab
->layout_sections_again
) ();
3487 if (htab
->fix_erratum_835769
)
3491 for (input_bfd
= info
->input_bfds
;
3492 input_bfd
!= NULL
; input_bfd
= input_bfd
->link
.next
)
3493 if (!_bfd_aarch64_erratum_835769_scan (input_bfd
, info
,
3494 &num_erratum_835769_fixes
))
3497 _bfd_aarch64_resize_stubs (htab
);
3498 (*htab
->layout_sections_again
) ();
3501 if (htab
->fix_erratum_843419
)
3505 for (input_bfd
= info
->input_bfds
;
3507 input_bfd
= input_bfd
->link
.next
)
3511 for (section
= input_bfd
->sections
;
3513 section
= section
->next
)
3514 if (!_bfd_aarch64_erratum_843419_scan (input_bfd
, section
, info
))
3518 _bfd_aarch64_resize_stubs (htab
);
3519 (*htab
->layout_sections_again
) ();
3526 for (input_bfd
= info
->input_bfds
;
3527 input_bfd
!= NULL
; input_bfd
= input_bfd
->link
.next
)
3529 Elf_Internal_Shdr
*symtab_hdr
;
3531 Elf_Internal_Sym
*local_syms
= NULL
;
3533 /* We'll need the symbol table in a second. */
3534 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
3535 if (symtab_hdr
->sh_info
== 0)
3538 /* Walk over each section attached to the input bfd. */
3539 for (section
= input_bfd
->sections
;
3540 section
!= NULL
; section
= section
->next
)
3542 Elf_Internal_Rela
*internal_relocs
, *irelaend
, *irela
;
3544 /* If there aren't any relocs, then there's nothing more
3546 if ((section
->flags
& SEC_RELOC
) == 0
3547 || section
->reloc_count
== 0
3548 || (section
->flags
& SEC_CODE
) == 0)
3551 /* If this section is a link-once section that will be
3552 discarded, then don't create any stubs. */
3553 if (section
->output_section
== NULL
3554 || section
->output_section
->owner
!= output_bfd
)
3557 /* Get the relocs. */
3559 = _bfd_elf_link_read_relocs (input_bfd
, section
, NULL
,
3560 NULL
, info
->keep_memory
);
3561 if (internal_relocs
== NULL
)
3562 goto error_ret_free_local
;
3564 /* Now examine each relocation. */
3565 irela
= internal_relocs
;
3566 irelaend
= irela
+ section
->reloc_count
;
3567 for (; irela
< irelaend
; irela
++)
3569 unsigned int r_type
, r_indx
;
3570 enum elf_aarch64_stub_type stub_type
;
3571 struct elf_aarch64_stub_hash_entry
*stub_entry
;
3574 bfd_vma destination
;
3575 struct elf_aarch64_link_hash_entry
*hash
;
3576 const char *sym_name
;
3578 const asection
*id_sec
;
3579 unsigned char st_type
;
3582 r_type
= ELFNN_R_TYPE (irela
->r_info
);
3583 r_indx
= ELFNN_R_SYM (irela
->r_info
);
3585 if (r_type
>= (unsigned int) R_AARCH64_end
)
3587 bfd_set_error (bfd_error_bad_value
);
3588 error_ret_free_internal
:
3589 if (elf_section_data (section
)->relocs
== NULL
)
3590 free (internal_relocs
);
3591 goto error_ret_free_local
;
3594 /* Only look for stubs on unconditional branch and
3595 branch and link instructions. */
3596 if (r_type
!= (unsigned int) AARCH64_R (CALL26
)
3597 && r_type
!= (unsigned int) AARCH64_R (JUMP26
))
3600 /* Now determine the call target, its name, value,
3607 if (r_indx
< symtab_hdr
->sh_info
)
3609 /* It's a local symbol. */
3610 Elf_Internal_Sym
*sym
;
3611 Elf_Internal_Shdr
*hdr
;
3613 if (local_syms
== NULL
)
3616 = (Elf_Internal_Sym
*) symtab_hdr
->contents
;
3617 if (local_syms
== NULL
)
3619 = bfd_elf_get_elf_syms (input_bfd
, symtab_hdr
,
3620 symtab_hdr
->sh_info
, 0,
3622 if (local_syms
== NULL
)
3623 goto error_ret_free_internal
;
3626 sym
= local_syms
+ r_indx
;
3627 hdr
= elf_elfsections (input_bfd
)[sym
->st_shndx
];
3628 sym_sec
= hdr
->bfd_section
;
3630 /* This is an undefined symbol. It can never
3634 if (ELF_ST_TYPE (sym
->st_info
) != STT_SECTION
)
3635 sym_value
= sym
->st_value
;
3636 destination
= (sym_value
+ irela
->r_addend
3637 + sym_sec
->output_offset
3638 + sym_sec
->output_section
->vma
);
3639 st_type
= ELF_ST_TYPE (sym
->st_info
);
3641 = bfd_elf_string_from_elf_section (input_bfd
,
3642 symtab_hdr
->sh_link
,
3649 e_indx
= r_indx
- symtab_hdr
->sh_info
;
3650 hash
= ((struct elf_aarch64_link_hash_entry
*)
3651 elf_sym_hashes (input_bfd
)[e_indx
]);
3653 while (hash
->root
.root
.type
== bfd_link_hash_indirect
3654 || hash
->root
.root
.type
== bfd_link_hash_warning
)
3655 hash
= ((struct elf_aarch64_link_hash_entry
*)
3656 hash
->root
.root
.u
.i
.link
);
3658 if (hash
->root
.root
.type
== bfd_link_hash_defined
3659 || hash
->root
.root
.type
== bfd_link_hash_defweak
)
3661 struct elf_aarch64_link_hash_table
*globals
=
3662 elf_aarch64_hash_table (info
);
3663 sym_sec
= hash
->root
.root
.u
.def
.section
;
3664 sym_value
= hash
->root
.root
.u
.def
.value
;
3665 /* For a destination in a shared library,
3666 use the PLT stub as target address to
3667 decide whether a branch stub is
3669 if (globals
->root
.splt
!= NULL
&& hash
!= NULL
3670 && hash
->root
.plt
.offset
!= (bfd_vma
) - 1)
3672 sym_sec
= globals
->root
.splt
;
3673 sym_value
= hash
->root
.plt
.offset
;
3674 if (sym_sec
->output_section
!= NULL
)
3675 destination
= (sym_value
3676 + sym_sec
->output_offset
3678 sym_sec
->output_section
->vma
);
3680 else if (sym_sec
->output_section
!= NULL
)
3681 destination
= (sym_value
+ irela
->r_addend
3682 + sym_sec
->output_offset
3683 + sym_sec
->output_section
->vma
);
3685 else if (hash
->root
.root
.type
== bfd_link_hash_undefined
3686 || (hash
->root
.root
.type
3687 == bfd_link_hash_undefweak
))
3689 /* For a shared library, use the PLT stub as
3690 target address to decide whether a long
3691 branch stub is needed.
3692 For absolute code, they cannot be handled. */
3693 struct elf_aarch64_link_hash_table
*globals
=
3694 elf_aarch64_hash_table (info
);
3696 if (globals
->root
.splt
!= NULL
&& hash
!= NULL
3697 && hash
->root
.plt
.offset
!= (bfd_vma
) - 1)
3699 sym_sec
= globals
->root
.splt
;
3700 sym_value
= hash
->root
.plt
.offset
;
3701 if (sym_sec
->output_section
!= NULL
)
3702 destination
= (sym_value
3703 + sym_sec
->output_offset
3705 sym_sec
->output_section
->vma
);
3712 bfd_set_error (bfd_error_bad_value
);
3713 goto error_ret_free_internal
;
3715 st_type
= ELF_ST_TYPE (hash
->root
.type
);
3716 sym_name
= hash
->root
.root
.root
.string
;
3719 /* Determine what (if any) linker stub is needed. */
3720 stub_type
= aarch64_type_of_stub
3721 (info
, section
, irela
, st_type
, hash
, destination
);
3722 if (stub_type
== aarch64_stub_none
)
3725 /* Support for grouping stub sections. */
3726 id_sec
= htab
->stub_group
[section
->id
].link_sec
;
3728 /* Get the name of this stub. */
3729 stub_name
= elfNN_aarch64_stub_name (id_sec
, sym_sec
, hash
,
3732 goto error_ret_free_internal
;
3735 aarch64_stub_hash_lookup (&htab
->stub_hash_table
,
3736 stub_name
, FALSE
, FALSE
);
3737 if (stub_entry
!= NULL
)
3739 /* The proper stub has already been created. */
3744 stub_entry
= _bfd_aarch64_add_stub_entry_in_group
3745 (stub_name
, section
, htab
);
3746 if (stub_entry
== NULL
)
3749 goto error_ret_free_internal
;
3752 stub_entry
->target_value
= sym_value
;
3753 stub_entry
->target_section
= sym_sec
;
3754 stub_entry
->stub_type
= stub_type
;
3755 stub_entry
->h
= hash
;
3756 stub_entry
->st_type
= st_type
;
3758 if (sym_name
== NULL
)
3759 sym_name
= "unnamed";
3760 len
= sizeof (STUB_ENTRY_NAME
) + strlen (sym_name
);
3761 stub_entry
->output_name
= bfd_alloc (htab
->stub_bfd
, len
);
3762 if (stub_entry
->output_name
== NULL
)
3765 goto error_ret_free_internal
;
3768 snprintf (stub_entry
->output_name
, len
, STUB_ENTRY_NAME
,
3771 stub_changed
= TRUE
;
3774 /* We're done with the internal relocs, free them. */
3775 if (elf_section_data (section
)->relocs
== NULL
)
3776 free (internal_relocs
);
3783 _bfd_aarch64_resize_stubs (htab
);
3785 /* Ask the linker to do its stuff. */
3786 (*htab
->layout_sections_again
) ();
3787 stub_changed
= FALSE
;
3792 error_ret_free_local
:
3796 /* Build all the stubs associated with the current output file. The
3797 stubs are kept in a hash table attached to the main linker hash
3798 table. We also set up the .plt entries for statically linked PIC
3799 functions here. This function is called via aarch64_elf_finish in the
3803 elfNN_aarch64_build_stubs (struct bfd_link_info
*info
)
3806 struct bfd_hash_table
*table
;
3807 struct elf_aarch64_link_hash_table
*htab
;
3809 htab
= elf_aarch64_hash_table (info
);
3811 for (stub_sec
= htab
->stub_bfd
->sections
;
3812 stub_sec
!= NULL
; stub_sec
= stub_sec
->next
)
3816 /* Ignore non-stub sections. */
3817 if (!strstr (stub_sec
->name
, STUB_SUFFIX
))
3820 /* Allocate memory to hold the linker stubs. */
3821 size
= stub_sec
->size
;
3822 stub_sec
->contents
= bfd_zalloc (htab
->stub_bfd
, size
);
3823 if (stub_sec
->contents
== NULL
&& size
!= 0)
3827 bfd_putl32 (0x14000000 | (size
>> 2), stub_sec
->contents
);
3828 stub_sec
->size
+= 4;
3831 /* Build the stubs as directed by the stub hash table. */
3832 table
= &htab
->stub_hash_table
;
3833 bfd_hash_traverse (table
, aarch64_build_one_stub
, info
);
3839 /* Add an entry to the code/data map for section SEC. */
3842 elfNN_aarch64_section_map_add (asection
*sec
, char type
, bfd_vma vma
)
3844 struct _aarch64_elf_section_data
*sec_data
=
3845 elf_aarch64_section_data (sec
);
3846 unsigned int newidx
;
3848 if (sec_data
->map
== NULL
)
3850 sec_data
->map
= bfd_malloc (sizeof (elf_aarch64_section_map
));
3851 sec_data
->mapcount
= 0;
3852 sec_data
->mapsize
= 1;
3855 newidx
= sec_data
->mapcount
++;
3857 if (sec_data
->mapcount
> sec_data
->mapsize
)
3859 sec_data
->mapsize
*= 2;
3860 sec_data
->map
= bfd_realloc_or_free
3861 (sec_data
->map
, sec_data
->mapsize
* sizeof (elf_aarch64_section_map
));
3866 sec_data
->map
[newidx
].vma
= vma
;
3867 sec_data
->map
[newidx
].type
= type
;
3872 /* Initialise maps of insn/data for input BFDs. */
3874 bfd_elfNN_aarch64_init_maps (bfd
*abfd
)
3876 Elf_Internal_Sym
*isymbuf
;
3877 Elf_Internal_Shdr
*hdr
;
3878 unsigned int i
, localsyms
;
3880 /* Make sure that we are dealing with an AArch64 elf binary. */
3881 if (!is_aarch64_elf (abfd
))
3884 if ((abfd
->flags
& DYNAMIC
) != 0)
3887 hdr
= &elf_symtab_hdr (abfd
);
3888 localsyms
= hdr
->sh_info
;
3890 /* Obtain a buffer full of symbols for this BFD. The hdr->sh_info field
3891 should contain the number of local symbols, which should come before any
3892 global symbols. Mapping symbols are always local. */
3893 isymbuf
= bfd_elf_get_elf_syms (abfd
, hdr
, localsyms
, 0, NULL
, NULL
, NULL
);
3895 /* No internal symbols read? Skip this BFD. */
3896 if (isymbuf
== NULL
)
3899 for (i
= 0; i
< localsyms
; i
++)
3901 Elf_Internal_Sym
*isym
= &isymbuf
[i
];
3902 asection
*sec
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
3905 if (sec
!= NULL
&& ELF_ST_BIND (isym
->st_info
) == STB_LOCAL
)
3907 name
= bfd_elf_string_from_elf_section (abfd
,
3911 if (bfd_is_aarch64_special_symbol_name
3912 (name
, BFD_AARCH64_SPECIAL_SYM_TYPE_MAP
))
3913 elfNN_aarch64_section_map_add (sec
, name
[1], isym
->st_value
);
3918 /* Set option values needed during linking. */
3920 bfd_elfNN_aarch64_set_options (struct bfd
*output_bfd
,
3921 struct bfd_link_info
*link_info
,
3923 int no_wchar_warn
, int pic_veneer
,
3924 int fix_erratum_835769
,
3925 int fix_erratum_843419
)
3927 struct elf_aarch64_link_hash_table
*globals
;
3929 globals
= elf_aarch64_hash_table (link_info
);
3930 globals
->pic_veneer
= pic_veneer
;
3931 globals
->fix_erratum_835769
= fix_erratum_835769
;
3932 globals
->fix_erratum_843419
= fix_erratum_843419
;
3933 globals
->fix_erratum_843419_adr
= TRUE
;
3935 BFD_ASSERT (is_aarch64_elf (output_bfd
));
3936 elf_aarch64_tdata (output_bfd
)->no_enum_size_warning
= no_enum_warn
;
3937 elf_aarch64_tdata (output_bfd
)->no_wchar_size_warning
= no_wchar_warn
;
3941 aarch64_calculate_got_entry_vma (struct elf_link_hash_entry
*h
,
3942 struct elf_aarch64_link_hash_table
3943 *globals
, struct bfd_link_info
*info
,
3944 bfd_vma value
, bfd
*output_bfd
,
3945 bfd_boolean
*unresolved_reloc_p
)
3947 bfd_vma off
= (bfd_vma
) - 1;
3948 asection
*basegot
= globals
->root
.sgot
;
3949 bfd_boolean dyn
= globals
->root
.dynamic_sections_created
;
3953 BFD_ASSERT (basegot
!= NULL
);
3954 off
= h
->got
.offset
;
3955 BFD_ASSERT (off
!= (bfd_vma
) - 1);
3956 if (!WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, info
->shared
, h
)
3958 && SYMBOL_REFERENCES_LOCAL (info
, h
))
3959 || (ELF_ST_VISIBILITY (h
->other
)
3960 && h
->root
.type
== bfd_link_hash_undefweak
))
3962 /* This is actually a static link, or it is a -Bsymbolic link
3963 and the symbol is defined locally. We must initialize this
3964 entry in the global offset table. Since the offset must
3965 always be a multiple of 8 (4 in the case of ILP32), we use
3966 the least significant bit to record whether we have
3967 initialized it already.
3968 When doing a dynamic link, we create a .rel(a).got relocation
3969 entry to initialize the value. This is done in the
3970 finish_dynamic_symbol routine. */
3975 bfd_put_NN (output_bfd
, value
, basegot
->contents
+ off
);
3980 *unresolved_reloc_p
= FALSE
;
3982 off
= off
+ basegot
->output_section
->vma
+ basegot
->output_offset
;
3988 /* Change R_TYPE to a more efficient access model where possible,
3989 return the new reloc type. */
3991 static bfd_reloc_code_real_type
3992 aarch64_tls_transition_without_check (bfd_reloc_code_real_type r_type
,
3993 struct elf_link_hash_entry
*h
)
3995 bfd_boolean is_local
= h
== NULL
;
3999 case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21
:
4000 case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21
:
4002 ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1
4003 : BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21
);
4005 case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21
:
4007 ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC
4010 case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19
:
4012 ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1
4013 : BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19
);
4015 case BFD_RELOC_AARCH64_TLSDESC_LDNN_LO12_NC
:
4016 case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC
:
4018 ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC
4019 : BFD_RELOC_AARCH64_TLSIE_LDNN_GOTTPREL_LO12_NC
);
4021 case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21
:
4022 return is_local
? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1
: r_type
;
4024 case BFD_RELOC_AARCH64_TLSIE_LDNN_GOTTPREL_LO12_NC
:
4025 return is_local
? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC
: r_type
;
4027 case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19
:
4030 case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21
:
4032 ? BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_HI12
4033 : BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19
);
4035 case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12_NC
:
4036 case BFD_RELOC_AARCH64_TLSDESC_CALL
:
4037 /* Instructions with these relocations will become NOPs. */
4038 return BFD_RELOC_AARCH64_NONE
;
4048 aarch64_reloc_got_type (bfd_reloc_code_real_type r_type
)
4052 case BFD_RELOC_AARCH64_ADR_GOT_PAGE
:
4053 case BFD_RELOC_AARCH64_GOT_LD_PREL19
:
4054 case BFD_RELOC_AARCH64_LD32_GOT_LO12_NC
:
4055 case BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15
:
4056 case BFD_RELOC_AARCH64_LD64_GOT_LO12_NC
:
4059 case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC
:
4060 case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21
:
4061 case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21
:
4064 case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12_NC
:
4065 case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21
:
4066 case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21
:
4067 case BFD_RELOC_AARCH64_TLSDESC_CALL
:
4068 case BFD_RELOC_AARCH64_TLSDESC_LD32_LO12_NC
:
4069 case BFD_RELOC_AARCH64_TLSDESC_LD64_LO12_NC
:
4070 case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19
:
4071 return GOT_TLSDESC_GD
;
4073 case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21
:
4074 case BFD_RELOC_AARCH64_TLSIE_LD32_GOTTPREL_LO12_NC
:
4075 case BFD_RELOC_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC
:
4076 case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19
:
4079 case BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_HI12
:
4080 case BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_LO12
:
4081 case BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_LO12_NC
:
4082 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0
:
4083 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC
:
4084 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1
:
4085 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1_NC
:
4086 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G2
:
4096 aarch64_can_relax_tls (bfd
*input_bfd
,
4097 struct bfd_link_info
*info
,
4098 bfd_reloc_code_real_type r_type
,
4099 struct elf_link_hash_entry
*h
,
4100 unsigned long r_symndx
)
4102 unsigned int symbol_got_type
;
4103 unsigned int reloc_got_type
;
4105 if (! IS_AARCH64_TLS_RELOC (r_type
))
4108 symbol_got_type
= elfNN_aarch64_symbol_got_type (h
, input_bfd
, r_symndx
);
4109 reloc_got_type
= aarch64_reloc_got_type (r_type
);
4111 if (symbol_got_type
== GOT_TLS_IE
&& GOT_TLS_GD_ANY_P (reloc_got_type
))
4117 if (h
&& h
->root
.type
== bfd_link_hash_undefweak
)
4123 /* Given the relocation code R_TYPE, return the relaxed bfd reloc
4126 static bfd_reloc_code_real_type
4127 aarch64_tls_transition (bfd
*input_bfd
,
4128 struct bfd_link_info
*info
,
4129 unsigned int r_type
,
4130 struct elf_link_hash_entry
*h
,
4131 unsigned long r_symndx
)
4133 bfd_reloc_code_real_type bfd_r_type
4134 = elfNN_aarch64_bfd_reloc_from_type (r_type
);
4136 if (! aarch64_can_relax_tls (input_bfd
, info
, bfd_r_type
, h
, r_symndx
))
4139 return aarch64_tls_transition_without_check (bfd_r_type
, h
);
4142 /* Return the base VMA address which should be subtracted from real addresses
4143 when resolving R_AARCH64_TLS_DTPREL relocation. */
4146 dtpoff_base (struct bfd_link_info
*info
)
4148 /* If tls_sec is NULL, we should have signalled an error already. */
4149 BFD_ASSERT (elf_hash_table (info
)->tls_sec
!= NULL
);
4150 return elf_hash_table (info
)->tls_sec
->vma
;
4153 /* Return the base VMA address which should be subtracted from real addresses
4154 when resolving R_AARCH64_TLS_GOTTPREL64 relocations. */
4157 tpoff_base (struct bfd_link_info
*info
)
4159 struct elf_link_hash_table
*htab
= elf_hash_table (info
);
4161 /* If tls_sec is NULL, we should have signalled an error already. */
4162 BFD_ASSERT (htab
->tls_sec
!= NULL
);
4164 bfd_vma base
= align_power ((bfd_vma
) TCB_SIZE
,
4165 htab
->tls_sec
->alignment_power
);
4166 return htab
->tls_sec
->vma
- base
;
4170 symbol_got_offset_ref (bfd
*input_bfd
, struct elf_link_hash_entry
*h
,
4171 unsigned long r_symndx
)
4173 /* Calculate the address of the GOT entry for symbol
4174 referred to in h. */
4176 return &h
->got
.offset
;
4180 struct elf_aarch64_local_symbol
*l
;
4182 l
= elf_aarch64_locals (input_bfd
);
4183 return &l
[r_symndx
].got_offset
;
4188 symbol_got_offset_mark (bfd
*input_bfd
, struct elf_link_hash_entry
*h
,
4189 unsigned long r_symndx
)
4192 p
= symbol_got_offset_ref (input_bfd
, h
, r_symndx
);
4197 symbol_got_offset_mark_p (bfd
*input_bfd
, struct elf_link_hash_entry
*h
,
4198 unsigned long r_symndx
)
4201 value
= * symbol_got_offset_ref (input_bfd
, h
, r_symndx
);
4206 symbol_got_offset (bfd
*input_bfd
, struct elf_link_hash_entry
*h
,
4207 unsigned long r_symndx
)
4210 value
= * symbol_got_offset_ref (input_bfd
, h
, r_symndx
);
4216 symbol_tlsdesc_got_offset_ref (bfd
*input_bfd
, struct elf_link_hash_entry
*h
,
4217 unsigned long r_symndx
)
4219 /* Calculate the address of the GOT entry for symbol
4220 referred to in h. */
4223 struct elf_aarch64_link_hash_entry
*eh
;
4224 eh
= (struct elf_aarch64_link_hash_entry
*) h
;
4225 return &eh
->tlsdesc_got_jump_table_offset
;
4230 struct elf_aarch64_local_symbol
*l
;
4232 l
= elf_aarch64_locals (input_bfd
);
4233 return &l
[r_symndx
].tlsdesc_got_jump_table_offset
;
4238 symbol_tlsdesc_got_offset_mark (bfd
*input_bfd
, struct elf_link_hash_entry
*h
,
4239 unsigned long r_symndx
)
4242 p
= symbol_tlsdesc_got_offset_ref (input_bfd
, h
, r_symndx
);
4247 symbol_tlsdesc_got_offset_mark_p (bfd
*input_bfd
,
4248 struct elf_link_hash_entry
*h
,
4249 unsigned long r_symndx
)
4252 value
= * symbol_tlsdesc_got_offset_ref (input_bfd
, h
, r_symndx
);
4257 symbol_tlsdesc_got_offset (bfd
*input_bfd
, struct elf_link_hash_entry
*h
,
4258 unsigned long r_symndx
)
4261 value
= * symbol_tlsdesc_got_offset_ref (input_bfd
, h
, r_symndx
);
4266 /* Data for make_branch_to_erratum_835769_stub(). */
4268 struct erratum_835769_branch_to_stub_data
4270 struct bfd_link_info
*info
;
4271 asection
*output_section
;
4275 /* Helper to insert branches to erratum 835769 stubs in the right
4276 places for a particular section. */
4279 make_branch_to_erratum_835769_stub (struct bfd_hash_entry
*gen_entry
,
4282 struct elf_aarch64_stub_hash_entry
*stub_entry
;
4283 struct erratum_835769_branch_to_stub_data
*data
;
4285 unsigned long branch_insn
= 0;
4286 bfd_vma veneered_insn_loc
, veneer_entry_loc
;
4287 bfd_signed_vma branch_offset
;
4288 unsigned int target
;
4291 stub_entry
= (struct elf_aarch64_stub_hash_entry
*) gen_entry
;
4292 data
= (struct erratum_835769_branch_to_stub_data
*) in_arg
;
4294 if (stub_entry
->target_section
!= data
->output_section
4295 || stub_entry
->stub_type
!= aarch64_stub_erratum_835769_veneer
)
4298 contents
= data
->contents
;
4299 veneered_insn_loc
= stub_entry
->target_section
->output_section
->vma
4300 + stub_entry
->target_section
->output_offset
4301 + stub_entry
->target_value
;
4302 veneer_entry_loc
= stub_entry
->stub_sec
->output_section
->vma
4303 + stub_entry
->stub_sec
->output_offset
4304 + stub_entry
->stub_offset
;
4305 branch_offset
= veneer_entry_loc
- veneered_insn_loc
;
4307 abfd
= stub_entry
->target_section
->owner
;
4308 if (!aarch64_valid_branch_p (veneer_entry_loc
, veneered_insn_loc
))
4309 (*_bfd_error_handler
)
4310 (_("%B: error: Erratum 835769 stub out "
4311 "of range (input file too large)"), abfd
);
4313 target
= stub_entry
->target_value
;
4314 branch_insn
= 0x14000000;
4315 branch_offset
>>= 2;
4316 branch_offset
&= 0x3ffffff;
4317 branch_insn
|= branch_offset
;
4318 bfd_putl32 (branch_insn
, &contents
[target
]);
4325 _bfd_aarch64_erratum_843419_branch_to_stub (struct bfd_hash_entry
*gen_entry
,
4328 struct elf_aarch64_stub_hash_entry
*stub_entry
4329 = (struct elf_aarch64_stub_hash_entry
*) gen_entry
;
4330 struct erratum_835769_branch_to_stub_data
*data
4331 = (struct erratum_835769_branch_to_stub_data
*) in_arg
;
4332 struct bfd_link_info
*info
;
4333 struct elf_aarch64_link_hash_table
*htab
;
4341 contents
= data
->contents
;
4342 section
= data
->output_section
;
4344 htab
= elf_aarch64_hash_table (info
);
4346 if (stub_entry
->target_section
!= section
4347 || stub_entry
->stub_type
!= aarch64_stub_erratum_843419_veneer
)
4350 insn
= bfd_getl32 (contents
+ stub_entry
->target_value
);
4352 stub_entry
->stub_sec
->contents
+ stub_entry
->stub_offset
);
4354 place
= (section
->output_section
->vma
+ section
->output_offset
4355 + stub_entry
->adrp_offset
);
4356 insn
= bfd_getl32 (contents
+ stub_entry
->adrp_offset
);
4358 if ((insn
& AARCH64_ADRP_OP_MASK
) != AARCH64_ADRP_OP
)
4361 bfd_signed_vma imm
=
4362 (_bfd_aarch64_sign_extend
4363 ((bfd_vma
) _bfd_aarch64_decode_adrp_imm (insn
) << 12, 33)
4366 if (htab
->fix_erratum_843419_adr
4367 && (imm
>= AARCH64_MIN_ADRP_IMM
&& imm
<= AARCH64_MAX_ADRP_IMM
))
4369 insn
= (_bfd_aarch64_reencode_adr_imm (AARCH64_ADR_OP
, imm
)
4370 | AARCH64_RT (insn
));
4371 bfd_putl32 (insn
, contents
+ stub_entry
->adrp_offset
);
4375 bfd_vma veneered_insn_loc
;
4376 bfd_vma veneer_entry_loc
;
4377 bfd_signed_vma branch_offset
;
4378 uint32_t branch_insn
;
4380 veneered_insn_loc
= stub_entry
->target_section
->output_section
->vma
4381 + stub_entry
->target_section
->output_offset
4382 + stub_entry
->target_value
;
4383 veneer_entry_loc
= stub_entry
->stub_sec
->output_section
->vma
4384 + stub_entry
->stub_sec
->output_offset
4385 + stub_entry
->stub_offset
;
4386 branch_offset
= veneer_entry_loc
- veneered_insn_loc
;
4388 abfd
= stub_entry
->target_section
->owner
;
4389 if (!aarch64_valid_branch_p (veneer_entry_loc
, veneered_insn_loc
))
4390 (*_bfd_error_handler
)
4391 (_("%B: error: Erratum 843419 stub out "
4392 "of range (input file too large)"), abfd
);
4394 branch_insn
= 0x14000000;
4395 branch_offset
>>= 2;
4396 branch_offset
&= 0x3ffffff;
4397 branch_insn
|= branch_offset
;
4398 bfd_putl32 (branch_insn
, contents
+ stub_entry
->target_value
);
4405 elfNN_aarch64_write_section (bfd
*output_bfd ATTRIBUTE_UNUSED
,
4406 struct bfd_link_info
*link_info
,
4411 struct elf_aarch64_link_hash_table
*globals
=
4412 elf_aarch64_hash_table (link_info
);
4414 if (globals
== NULL
)
4417 /* Fix code to point to erratum 835769 stubs. */
4418 if (globals
->fix_erratum_835769
)
4420 struct erratum_835769_branch_to_stub_data data
;
4422 data
.info
= link_info
;
4423 data
.output_section
= sec
;
4424 data
.contents
= contents
;
4425 bfd_hash_traverse (&globals
->stub_hash_table
,
4426 make_branch_to_erratum_835769_stub
, &data
);
4429 if (globals
->fix_erratum_843419
)
4431 struct erratum_835769_branch_to_stub_data data
;
4433 data
.info
= link_info
;
4434 data
.output_section
= sec
;
4435 data
.contents
= contents
;
4436 bfd_hash_traverse (&globals
->stub_hash_table
,
4437 _bfd_aarch64_erratum_843419_branch_to_stub
, &data
);
4443 /* Perform a relocation as part of a final link. */
4444 static bfd_reloc_status_type
4445 elfNN_aarch64_final_link_relocate (reloc_howto_type
*howto
,
4448 asection
*input_section
,
4450 Elf_Internal_Rela
*rel
,
4452 struct bfd_link_info
*info
,
4454 struct elf_link_hash_entry
*h
,
4455 bfd_boolean
*unresolved_reloc_p
,
4456 bfd_boolean save_addend
,
4457 bfd_vma
*saved_addend
,
4458 Elf_Internal_Sym
*sym
)
4460 Elf_Internal_Shdr
*symtab_hdr
;
4461 unsigned int r_type
= howto
->type
;
4462 bfd_reloc_code_real_type bfd_r_type
4463 = elfNN_aarch64_bfd_reloc_from_howto (howto
);
4464 bfd_reloc_code_real_type new_bfd_r_type
;
4465 unsigned long r_symndx
;
4466 bfd_byte
*hit_data
= contents
+ rel
->r_offset
;
4468 bfd_signed_vma signed_addend
;
4469 struct elf_aarch64_link_hash_table
*globals
;
4470 bfd_boolean weak_undef_p
;
4473 globals
= elf_aarch64_hash_table (info
);
4475 symtab_hdr
= &elf_symtab_hdr (input_bfd
);
4477 BFD_ASSERT (is_aarch64_elf (input_bfd
));
4479 r_symndx
= ELFNN_R_SYM (rel
->r_info
);
4481 /* It is possible to have linker relaxations on some TLS access
4482 models. Update our information here. */
4483 new_bfd_r_type
= aarch64_tls_transition (input_bfd
, info
, r_type
, h
, r_symndx
);
4484 if (new_bfd_r_type
!= bfd_r_type
)
4486 bfd_r_type
= new_bfd_r_type
;
4487 howto
= elfNN_aarch64_howto_from_bfd_reloc (bfd_r_type
);
4488 BFD_ASSERT (howto
!= NULL
);
4489 r_type
= howto
->type
;
4492 place
= input_section
->output_section
->vma
4493 + input_section
->output_offset
+ rel
->r_offset
;
4495 /* Get addend, accumulating the addend for consecutive relocs
4496 which refer to the same offset. */
4497 signed_addend
= saved_addend
? *saved_addend
: 0;
4498 signed_addend
+= rel
->r_addend
;
4500 weak_undef_p
= (h
? h
->root
.type
== bfd_link_hash_undefweak
4501 : bfd_is_und_section (sym_sec
));
4503 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle
4504 it here if it is defined in a non-shared object. */
4506 && h
->type
== STT_GNU_IFUNC
4513 if ((input_section
->flags
& SEC_ALLOC
) == 0
4514 || h
->plt
.offset
== (bfd_vma
) -1)
4517 /* STT_GNU_IFUNC symbol must go through PLT. */
4518 plt
= globals
->root
.splt
? globals
->root
.splt
: globals
->root
.iplt
;
4519 value
= (plt
->output_section
->vma
+ plt
->output_offset
+ h
->plt
.offset
);
4524 if (h
->root
.root
.string
)
4525 name
= h
->root
.root
.string
;
4527 name
= bfd_elf_sym_name (input_bfd
, symtab_hdr
, sym
,
4529 (*_bfd_error_handler
)
4530 (_("%B: relocation %s against STT_GNU_IFUNC "
4531 "symbol `%s' isn't handled by %s"), input_bfd
,
4532 howto
->name
, name
, __FUNCTION__
);
4533 bfd_set_error (bfd_error_bad_value
);
4536 case BFD_RELOC_AARCH64_NN
:
4537 if (rel
->r_addend
!= 0)
4539 if (h
->root
.root
.string
)
4540 name
= h
->root
.root
.string
;
4542 name
= bfd_elf_sym_name (input_bfd
, symtab_hdr
,
4544 (*_bfd_error_handler
)
4545 (_("%B: relocation %s against STT_GNU_IFUNC "
4546 "symbol `%s' has non-zero addend: %d"),
4547 input_bfd
, howto
->name
, name
, rel
->r_addend
);
4548 bfd_set_error (bfd_error_bad_value
);
4552 /* Generate dynamic relocation only when there is a
4553 non-GOT reference in a shared object. */
4554 if (info
->shared
&& h
->non_got_ref
)
4556 Elf_Internal_Rela outrel
;
4559 /* Need a dynamic relocation to get the real function
4561 outrel
.r_offset
= _bfd_elf_section_offset (output_bfd
,
4565 if (outrel
.r_offset
== (bfd_vma
) -1
4566 || outrel
.r_offset
== (bfd_vma
) -2)
4569 outrel
.r_offset
+= (input_section
->output_section
->vma
4570 + input_section
->output_offset
);
4572 if (h
->dynindx
== -1
4574 || info
->executable
)
4576 /* This symbol is resolved locally. */
4577 outrel
.r_info
= ELFNN_R_INFO (0, AARCH64_R (IRELATIVE
));
4578 outrel
.r_addend
= (h
->root
.u
.def
.value
4579 + h
->root
.u
.def
.section
->output_section
->vma
4580 + h
->root
.u
.def
.section
->output_offset
);
4584 outrel
.r_info
= ELFNN_R_INFO (h
->dynindx
, r_type
);
4585 outrel
.r_addend
= 0;
4588 sreloc
= globals
->root
.irelifunc
;
4589 elf_append_rela (output_bfd
, sreloc
, &outrel
);
4591 /* If this reloc is against an external symbol, we
4592 do not want to fiddle with the addend. Otherwise,
4593 we need to include the symbol value so that it
4594 becomes an addend for the dynamic reloc. For an
4595 internal symbol, we have updated addend. */
4596 return bfd_reloc_ok
;
4599 case BFD_RELOC_AARCH64_CALL26
:
4600 case BFD_RELOC_AARCH64_JUMP26
:
4601 value
= _bfd_aarch64_elf_resolve_relocation (bfd_r_type
, place
, value
,
4604 return _bfd_aarch64_elf_put_addend (input_bfd
, hit_data
, bfd_r_type
,
4606 case BFD_RELOC_AARCH64_ADR_GOT_PAGE
:
4607 case BFD_RELOC_AARCH64_GOT_LD_PREL19
:
4608 case BFD_RELOC_AARCH64_LD32_GOT_LO12_NC
:
4609 case BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15
:
4610 case BFD_RELOC_AARCH64_LD64_GOT_LO12_NC
:
4611 base_got
= globals
->root
.sgot
;
4612 off
= h
->got
.offset
;
4614 if (base_got
== NULL
)
4617 if (off
== (bfd_vma
) -1)
4621 /* We can't use h->got.offset here to save state, or
4622 even just remember the offset, as finish_dynamic_symbol
4623 would use that as offset into .got. */
4625 if (globals
->root
.splt
!= NULL
)
4627 plt_index
= ((h
->plt
.offset
- globals
->plt_header_size
) /
4628 globals
->plt_entry_size
);
4629 off
= (plt_index
+ 3) * GOT_ENTRY_SIZE
;
4630 base_got
= globals
->root
.sgotplt
;
4634 plt_index
= h
->plt
.offset
/ globals
->plt_entry_size
;
4635 off
= plt_index
* GOT_ENTRY_SIZE
;
4636 base_got
= globals
->root
.igotplt
;
4639 if (h
->dynindx
== -1
4643 /* This references the local definition. We must
4644 initialize this entry in the global offset table.
4645 Since the offset must always be a multiple of 8,
4646 we use the least significant bit to record
4647 whether we have initialized it already.
4649 When doing a dynamic link, we create a .rela.got
4650 relocation entry to initialize the value. This
4651 is done in the finish_dynamic_symbol routine. */
4656 bfd_put_NN (output_bfd
, value
,
4657 base_got
->contents
+ off
);
4658 /* Note that this is harmless as -1 | 1 still is -1. */
4662 value
= (base_got
->output_section
->vma
4663 + base_got
->output_offset
+ off
);
4666 value
= aarch64_calculate_got_entry_vma (h
, globals
, info
,
4668 unresolved_reloc_p
);
4669 if (bfd_r_type
== BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15
)
4670 addend
= (globals
->root
.sgot
->output_section
->vma
4671 + globals
->root
.sgot
->output_offset
);
4672 value
= _bfd_aarch64_elf_resolve_relocation (bfd_r_type
, place
, value
,
4673 addend
, weak_undef_p
);
4674 return _bfd_aarch64_elf_put_addend (input_bfd
, hit_data
, bfd_r_type
, howto
, value
);
4675 case BFD_RELOC_AARCH64_ADD_LO12
:
4676 case BFD_RELOC_AARCH64_ADR_HI21_PCREL
:
4683 case BFD_RELOC_AARCH64_NONE
:
4684 case BFD_RELOC_AARCH64_TLSDESC_CALL
:
4685 *unresolved_reloc_p
= FALSE
;
4686 return bfd_reloc_ok
;
4688 case BFD_RELOC_AARCH64_NN
:
4690 /* When generating a shared object or relocatable executable, these
4691 relocations are copied into the output file to be resolved at
4693 if (((info
->shared
== TRUE
) || globals
->root
.is_relocatable_executable
)
4694 && (input_section
->flags
& SEC_ALLOC
)
4696 || ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
4697 || h
->root
.type
!= bfd_link_hash_undefweak
))
4699 Elf_Internal_Rela outrel
;
4701 bfd_boolean skip
, relocate
;
4704 *unresolved_reloc_p
= FALSE
;
4709 outrel
.r_addend
= signed_addend
;
4711 _bfd_elf_section_offset (output_bfd
, info
, input_section
,
4713 if (outrel
.r_offset
== (bfd_vma
) - 1)
4715 else if (outrel
.r_offset
== (bfd_vma
) - 2)
4721 outrel
.r_offset
+= (input_section
->output_section
->vma
4722 + input_section
->output_offset
);
4725 memset (&outrel
, 0, sizeof outrel
);
4728 && (!info
->shared
|| !SYMBOLIC_BIND (info
, h
) || !h
->def_regular
))
4729 outrel
.r_info
= ELFNN_R_INFO (h
->dynindx
, r_type
);
4734 /* On SVR4-ish systems, the dynamic loader cannot
4735 relocate the text and data segments independently,
4736 so the symbol does not matter. */
4738 outrel
.r_info
= ELFNN_R_INFO (symbol
, AARCH64_R (RELATIVE
));
4739 outrel
.r_addend
+= value
;
4742 sreloc
= elf_section_data (input_section
)->sreloc
;
4743 if (sreloc
== NULL
|| sreloc
->contents
== NULL
)
4744 return bfd_reloc_notsupported
;
4746 loc
= sreloc
->contents
+ sreloc
->reloc_count
++ * RELOC_SIZE (globals
);
4747 bfd_elfNN_swap_reloca_out (output_bfd
, &outrel
, loc
);
4749 if (sreloc
->reloc_count
* RELOC_SIZE (globals
) > sreloc
->size
)
4751 /* Sanity to check that we have previously allocated
4752 sufficient space in the relocation section for the
4753 number of relocations we actually want to emit. */
4757 /* If this reloc is against an external symbol, we do not want to
4758 fiddle with the addend. Otherwise, we need to include the symbol
4759 value so that it becomes an addend for the dynamic reloc. */
4761 return bfd_reloc_ok
;
4763 return _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
4764 contents
, rel
->r_offset
, value
,
4768 value
+= signed_addend
;
4771 case BFD_RELOC_AARCH64_CALL26
:
4772 case BFD_RELOC_AARCH64_JUMP26
:
4774 asection
*splt
= globals
->root
.splt
;
4775 bfd_boolean via_plt_p
=
4776 splt
!= NULL
&& h
!= NULL
&& h
->plt
.offset
!= (bfd_vma
) - 1;
4778 /* A call to an undefined weak symbol is converted to a jump to
4779 the next instruction unless a PLT entry will be created.
4780 The jump to the next instruction is optimized as a NOP.
4781 Do the same for local undefined symbols. */
4782 if (weak_undef_p
&& ! via_plt_p
)
4784 bfd_putl32 (INSN_NOP
, hit_data
);
4785 return bfd_reloc_ok
;
4788 /* If the call goes through a PLT entry, make sure to
4789 check distance to the right destination address. */
4792 value
= (splt
->output_section
->vma
4793 + splt
->output_offset
+ h
->plt
.offset
);
4794 *unresolved_reloc_p
= FALSE
;
4797 /* If the target symbol is global and marked as a function the
4798 relocation applies a function call or a tail call. In this
4799 situation we can veneer out of range branches. The veneers
4800 use IP0 and IP1 hence cannot be used arbitrary out of range
4801 branches that occur within the body of a function. */
4802 if (h
&& h
->type
== STT_FUNC
)
4804 /* Check if a stub has to be inserted because the destination
4806 if (! aarch64_valid_branch_p (value
, place
))
4808 /* The target is out of reach, so redirect the branch to
4809 the local stub for this function. */
4810 struct elf_aarch64_stub_hash_entry
*stub_entry
;
4811 stub_entry
= elfNN_aarch64_get_stub_entry (input_section
,
4814 if (stub_entry
!= NULL
)
4815 value
= (stub_entry
->stub_offset
4816 + stub_entry
->stub_sec
->output_offset
4817 + stub_entry
->stub_sec
->output_section
->vma
);
4821 value
= _bfd_aarch64_elf_resolve_relocation (bfd_r_type
, place
, value
,
4822 signed_addend
, weak_undef_p
);
4825 case BFD_RELOC_AARCH64_16_PCREL
:
4826 case BFD_RELOC_AARCH64_32_PCREL
:
4827 case BFD_RELOC_AARCH64_64_PCREL
:
4828 case BFD_RELOC_AARCH64_ADR_HI21_NC_PCREL
:
4829 case BFD_RELOC_AARCH64_ADR_HI21_PCREL
:
4830 case BFD_RELOC_AARCH64_ADR_LO21_PCREL
:
4831 case BFD_RELOC_AARCH64_LD_LO19_PCREL
:
4833 && (input_section
->flags
& SEC_ALLOC
) != 0
4834 && (input_section
->flags
& SEC_READONLY
) != 0
4838 int howto_index
= bfd_r_type
- BFD_RELOC_AARCH64_RELOC_START
;
4840 (*_bfd_error_handler
)
4841 (_("%B: relocation %s against external symbol `%s' can not be used"
4842 " when making a shared object; recompile with -fPIC"),
4843 input_bfd
, elfNN_aarch64_howto_table
[howto_index
].name
,
4844 h
->root
.root
.string
);
4845 bfd_set_error (bfd_error_bad_value
);
4849 case BFD_RELOC_AARCH64_16
:
4851 case BFD_RELOC_AARCH64_32
:
4853 case BFD_RELOC_AARCH64_ADD_LO12
:
4854 case BFD_RELOC_AARCH64_BRANCH19
:
4855 case BFD_RELOC_AARCH64_LDST128_LO12
:
4856 case BFD_RELOC_AARCH64_LDST16_LO12
:
4857 case BFD_RELOC_AARCH64_LDST32_LO12
:
4858 case BFD_RELOC_AARCH64_LDST64_LO12
:
4859 case BFD_RELOC_AARCH64_LDST8_LO12
:
4860 case BFD_RELOC_AARCH64_MOVW_G0
:
4861 case BFD_RELOC_AARCH64_MOVW_G0_NC
:
4862 case BFD_RELOC_AARCH64_MOVW_G0_S
:
4863 case BFD_RELOC_AARCH64_MOVW_G1
:
4864 case BFD_RELOC_AARCH64_MOVW_G1_NC
:
4865 case BFD_RELOC_AARCH64_MOVW_G1_S
:
4866 case BFD_RELOC_AARCH64_MOVW_G2
:
4867 case BFD_RELOC_AARCH64_MOVW_G2_NC
:
4868 case BFD_RELOC_AARCH64_MOVW_G2_S
:
4869 case BFD_RELOC_AARCH64_MOVW_G3
:
4870 case BFD_RELOC_AARCH64_TSTBR14
:
4871 value
= _bfd_aarch64_elf_resolve_relocation (bfd_r_type
, place
, value
,
4872 signed_addend
, weak_undef_p
);
4875 case BFD_RELOC_AARCH64_ADR_GOT_PAGE
:
4876 case BFD_RELOC_AARCH64_GOT_LD_PREL19
:
4877 case BFD_RELOC_AARCH64_LD32_GOT_LO12_NC
:
4878 case BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15
:
4879 case BFD_RELOC_AARCH64_LD64_GOT_LO12_NC
:
4880 if (globals
->root
.sgot
== NULL
)
4881 BFD_ASSERT (h
!= NULL
);
4886 value
= aarch64_calculate_got_entry_vma (h
, globals
, info
, value
,
4888 unresolved_reloc_p
);
4889 if (bfd_r_type
== BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15
)
4890 addend
= (globals
->root
.sgot
->output_section
->vma
4891 + globals
->root
.sgot
->output_offset
);
4892 value
= _bfd_aarch64_elf_resolve_relocation (bfd_r_type
, place
, value
,
4893 addend
, weak_undef_p
);
4898 struct elf_aarch64_local_symbol
*locals
4899 = elf_aarch64_locals (input_bfd
);
4903 int howto_index
= bfd_r_type
- BFD_RELOC_AARCH64_RELOC_START
;
4904 (*_bfd_error_handler
)
4905 (_("%B: Local symbol descriptor table be NULL when applying "
4906 "relocation %s against local symbol"),
4907 input_bfd
, elfNN_aarch64_howto_table
[howto_index
].name
);
4911 off
= symbol_got_offset (input_bfd
, h
, r_symndx
);
4912 base_got
= globals
->root
.sgot
;
4913 bfd_vma got_entry_addr
= (base_got
->output_section
->vma
4914 + base_got
->output_offset
+ off
);
4916 if (!symbol_got_offset_mark_p (input_bfd
, h
, r_symndx
))
4918 bfd_put_64 (output_bfd
, value
, base_got
->contents
+ off
);
4923 Elf_Internal_Rela outrel
;
4925 /* For local symbol, we have done absolute relocation in static
4926 linking stageh. While for share library, we need to update
4927 the content of GOT entry according to the share objects
4928 loading base address. So we need to generate a
4929 R_AARCH64_RELATIVE reloc for dynamic linker. */
4930 s
= globals
->root
.srelgot
;
4934 outrel
.r_offset
= got_entry_addr
;
4935 outrel
.r_info
= ELFNN_R_INFO (0, AARCH64_R (RELATIVE
));
4936 outrel
.r_addend
= value
;
4937 elf_append_rela (output_bfd
, s
, &outrel
);
4940 symbol_got_offset_mark (input_bfd
, h
, r_symndx
);
4943 /* Update the relocation value to GOT entry addr as we have transformed
4944 the direct data access into indirect data access through GOT. */
4945 value
= got_entry_addr
;
4947 if (bfd_r_type
== BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15
)
4948 addend
= base_got
->output_section
->vma
+ base_got
->output_offset
;
4950 value
= _bfd_aarch64_elf_resolve_relocation (bfd_r_type
, place
, value
,
4951 addend
, weak_undef_p
);
4956 case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC
:
4957 case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21
:
4958 case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21
:
4959 case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21
:
4960 case BFD_RELOC_AARCH64_TLSIE_LD32_GOTTPREL_LO12_NC
:
4961 case BFD_RELOC_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC
:
4962 case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19
:
4963 if (globals
->root
.sgot
== NULL
)
4964 return bfd_reloc_notsupported
;
4966 value
= (symbol_got_offset (input_bfd
, h
, r_symndx
)
4967 + globals
->root
.sgot
->output_section
->vma
4968 + globals
->root
.sgot
->output_offset
);
4970 value
= _bfd_aarch64_elf_resolve_relocation (bfd_r_type
, place
, value
,
4972 *unresolved_reloc_p
= FALSE
;
4975 case BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_HI12
:
4976 case BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_LO12
:
4977 case BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_LO12_NC
:
4978 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0
:
4979 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC
:
4980 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1
:
4981 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1_NC
:
4982 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G2
:
4983 value
= _bfd_aarch64_elf_resolve_relocation (bfd_r_type
, place
, value
,
4984 signed_addend
- tpoff_base (info
),
4986 *unresolved_reloc_p
= FALSE
;
4989 case BFD_RELOC_AARCH64_TLSDESC_ADD
:
4990 case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12_NC
:
4991 case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21
:
4992 case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21
:
4993 case BFD_RELOC_AARCH64_TLSDESC_LD32_LO12_NC
:
4994 case BFD_RELOC_AARCH64_TLSDESC_LD64_LO12_NC
:
4995 case BFD_RELOC_AARCH64_TLSDESC_LDR
:
4996 case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19
:
4997 if (globals
->root
.sgot
== NULL
)
4998 return bfd_reloc_notsupported
;
4999 value
= (symbol_tlsdesc_got_offset (input_bfd
, h
, r_symndx
)
5000 + globals
->root
.sgotplt
->output_section
->vma
5001 + globals
->root
.sgotplt
->output_offset
5002 + globals
->sgotplt_jump_table_size
);
5004 value
= _bfd_aarch64_elf_resolve_relocation (bfd_r_type
, place
, value
,
5006 *unresolved_reloc_p
= FALSE
;
5010 return bfd_reloc_notsupported
;
5014 *saved_addend
= value
;
5016 /* Only apply the final relocation in a sequence. */
5018 return bfd_reloc_continue
;
5020 return _bfd_aarch64_elf_put_addend (input_bfd
, hit_data
, bfd_r_type
,
5024 /* Handle TLS relaxations. Relaxing is possible for symbols that use
5025 R_AARCH64_TLSDESC_ADR_{PAGE, LD64_LO12_NC, ADD_LO12_NC} during a static
5028 Return bfd_reloc_ok if we're done, bfd_reloc_continue if the caller
5029 is to then call final_link_relocate. Return other values in the
5032 static bfd_reloc_status_type
5033 elfNN_aarch64_tls_relax (struct elf_aarch64_link_hash_table
*globals
,
5034 bfd
*input_bfd
, bfd_byte
*contents
,
5035 Elf_Internal_Rela
*rel
, struct elf_link_hash_entry
*h
)
5037 bfd_boolean is_local
= h
== NULL
;
5038 unsigned int r_type
= ELFNN_R_TYPE (rel
->r_info
);
5041 BFD_ASSERT (globals
&& input_bfd
&& contents
&& rel
);
5043 switch (elfNN_aarch64_bfd_reloc_from_type (r_type
))
5045 case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21
:
5046 case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21
:
5049 /* GD->LE relaxation:
5050 adrp x0, :tlsgd:var => movz x0, :tprel_g1:var
5052 adrp x0, :tlsdesc:var => movz x0, :tprel_g1:var
5054 bfd_putl32 (0xd2a00000, contents
+ rel
->r_offset
);
5055 return bfd_reloc_continue
;
5059 /* GD->IE relaxation:
5060 adrp x0, :tlsgd:var => adrp x0, :gottprel:var
5062 adrp x0, :tlsdesc:var => adrp x0, :gottprel:var
5064 return bfd_reloc_continue
;
5067 case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21
:
5071 case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19
:
5074 /* Tiny TLSDESC->LE relaxation:
5075 ldr x1, :tlsdesc:var => movz x0, #:tprel_g1:var
5076 adr x0, :tlsdesc:var => movk x0, #:tprel_g0_nc:var
5080 BFD_ASSERT (ELFNN_R_TYPE (rel
[1].r_info
) == AARCH64_R (TLSDESC_ADR_PREL21
));
5081 BFD_ASSERT (ELFNN_R_TYPE (rel
[2].r_info
) == AARCH64_R (TLSDESC_CALL
));
5083 rel
[1].r_info
= ELFNN_R_INFO (ELFNN_R_SYM (rel
->r_info
),
5084 AARCH64_R (TLSLE_MOVW_TPREL_G0_NC
));
5085 rel
[2].r_info
= ELFNN_R_INFO (STN_UNDEF
, R_AARCH64_NONE
);
5087 bfd_putl32 (0xd2a00000, contents
+ rel
->r_offset
);
5088 bfd_putl32 (0xf2800000, contents
+ rel
->r_offset
+ 4);
5089 bfd_putl32 (INSN_NOP
, contents
+ rel
->r_offset
+ 8);
5090 return bfd_reloc_continue
;
5094 /* Tiny TLSDESC->IE relaxation:
5095 ldr x1, :tlsdesc:var => ldr x0, :gottprel:var
5096 adr x0, :tlsdesc:var => nop
5100 BFD_ASSERT (ELFNN_R_TYPE (rel
[1].r_info
) == AARCH64_R (TLSDESC_ADR_PREL21
));
5101 BFD_ASSERT (ELFNN_R_TYPE (rel
[2].r_info
) == AARCH64_R (TLSDESC_CALL
));
5103 rel
[1].r_info
= ELFNN_R_INFO (STN_UNDEF
, R_AARCH64_NONE
);
5104 rel
[2].r_info
= ELFNN_R_INFO (STN_UNDEF
, R_AARCH64_NONE
);
5106 bfd_putl32 (0x58000000, contents
+ rel
->r_offset
);
5107 bfd_putl32 (INSN_NOP
, contents
+ rel
->r_offset
+ 4);
5108 bfd_putl32 (INSN_NOP
, contents
+ rel
->r_offset
+ 8);
5109 return bfd_reloc_continue
;
5112 case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21
:
5115 /* Tiny GD->LE relaxation:
5116 adr x0, :tlsgd:var => mrs x1, tpidr_el0
5117 bl __tls_get_addr => add x0, x1, #:tprel_hi12:x, lsl #12
5118 nop => add x0, x0, #:tprel_lo12_nc:x
5121 /* First kill the tls_get_addr reloc on the bl instruction. */
5122 BFD_ASSERT (rel
->r_offset
+ 4 == rel
[1].r_offset
);
5124 bfd_putl32 (0xd53bd041, contents
+ rel
->r_offset
+ 0);
5125 bfd_putl32 (0x91400020, contents
+ rel
->r_offset
+ 4);
5126 bfd_putl32 (0x91000000, contents
+ rel
->r_offset
+ 8);
5128 rel
[1].r_info
= ELFNN_R_INFO (ELFNN_R_SYM (rel
->r_info
),
5129 AARCH64_R (TLSLE_ADD_TPREL_LO12_NC
));
5130 rel
[1].r_offset
= rel
->r_offset
+ 8;
5132 /* Move the current relocation to the second instruction in
5135 rel
->r_info
= ELFNN_R_INFO (ELFNN_R_SYM (rel
->r_info
),
5136 AARCH64_R (TLSLE_ADD_TPREL_HI12
));
5137 return bfd_reloc_continue
;
5141 /* Tiny GD->IE relaxation:
5142 adr x0, :tlsgd:var => ldr x0, :gottprel:var
5143 bl __tls_get_addr => mrs x1, tpidr_el0
5144 nop => add x0, x0, x1
5147 /* First kill the tls_get_addr reloc on the bl instruction. */
5148 BFD_ASSERT (rel
->r_offset
+ 4 == rel
[1].r_offset
);
5149 rel
[1].r_info
= ELFNN_R_INFO (STN_UNDEF
, R_AARCH64_NONE
);
5151 bfd_putl32 (0x58000000, contents
+ rel
->r_offset
);
5152 bfd_putl32 (0xd53bd041, contents
+ rel
->r_offset
+ 4);
5153 bfd_putl32 (0x8b000020, contents
+ rel
->r_offset
+ 8);
5154 return bfd_reloc_continue
;
5157 case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19
:
5158 return bfd_reloc_continue
;
5160 case BFD_RELOC_AARCH64_TLSDESC_LDNN_LO12_NC
:
5163 /* GD->LE relaxation:
5164 ldr xd, [x0, #:tlsdesc_lo12:var] => movk x0, :tprel_g0_nc:var
5166 bfd_putl32 (0xf2800000, contents
+ rel
->r_offset
);
5167 return bfd_reloc_continue
;
5171 /* GD->IE relaxation:
5172 ldr xd, [x0, #:tlsdesc_lo12:var] => ldr x0, [x0, #:gottprel_lo12:var]
5174 insn
= bfd_getl32 (contents
+ rel
->r_offset
);
5176 bfd_putl32 (insn
, contents
+ rel
->r_offset
);
5177 return bfd_reloc_continue
;
5180 case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC
:
5183 /* GD->LE relaxation
5184 add x0, #:tlsgd_lo12:var => movk x0, :tprel_g0_nc:var
5185 bl __tls_get_addr => mrs x1, tpidr_el0
5186 nop => add x0, x1, x0
5189 /* First kill the tls_get_addr reloc on the bl instruction. */
5190 BFD_ASSERT (rel
->r_offset
+ 4 == rel
[1].r_offset
);
5191 rel
[1].r_info
= ELFNN_R_INFO (STN_UNDEF
, R_AARCH64_NONE
);
5193 bfd_putl32 (0xf2800000, contents
+ rel
->r_offset
);
5194 bfd_putl32 (0xd53bd041, contents
+ rel
->r_offset
+ 4);
5195 bfd_putl32 (0x8b000020, contents
+ rel
->r_offset
+ 8);
5196 return bfd_reloc_continue
;
5200 /* GD->IE relaxation
5201 ADD x0, #:tlsgd_lo12:var => ldr x0, [x0, #:gottprel_lo12:var]
5202 BL __tls_get_addr => mrs x1, tpidr_el0
5204 NOP => add x0, x1, x0
5207 BFD_ASSERT (ELFNN_R_TYPE (rel
[1].r_info
) == AARCH64_R (CALL26
));
5209 /* Remove the relocation on the BL instruction. */
5210 rel
[1].r_info
= ELFNN_R_INFO (STN_UNDEF
, R_AARCH64_NONE
);
5212 bfd_putl32 (0xf9400000, contents
+ rel
->r_offset
);
5214 /* We choose to fixup the BL and NOP instructions using the
5215 offset from the second relocation to allow flexibility in
5216 scheduling instructions between the ADD and BL. */
5217 bfd_putl32 (0xd53bd041, contents
+ rel
[1].r_offset
);
5218 bfd_putl32 (0x8b000020, contents
+ rel
[1].r_offset
+ 4);
5219 return bfd_reloc_continue
;
5222 case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12_NC
:
5223 case BFD_RELOC_AARCH64_TLSDESC_CALL
:
5224 /* GD->IE/LE relaxation:
5225 add x0, x0, #:tlsdesc_lo12:var => nop
5228 bfd_putl32 (INSN_NOP
, contents
+ rel
->r_offset
);
5229 return bfd_reloc_ok
;
5231 case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21
:
5232 /* IE->LE relaxation:
5233 adrp xd, :gottprel:var => movz xd, :tprel_g1:var
5237 insn
= bfd_getl32 (contents
+ rel
->r_offset
);
5238 bfd_putl32 (0xd2a00000 | (insn
& 0x1f), contents
+ rel
->r_offset
);
5240 return bfd_reloc_continue
;
5242 case BFD_RELOC_AARCH64_TLSIE_LDNN_GOTTPREL_LO12_NC
:
5243 /* IE->LE relaxation:
5244 ldr xd, [xm, #:gottprel_lo12:var] => movk xd, :tprel_g0_nc:var
5248 insn
= bfd_getl32 (contents
+ rel
->r_offset
);
5249 bfd_putl32 (0xf2800000 | (insn
& 0x1f), contents
+ rel
->r_offset
);
5251 return bfd_reloc_continue
;
5254 return bfd_reloc_continue
;
5257 return bfd_reloc_ok
;
5260 /* Relocate an AArch64 ELF section. */
5263 elfNN_aarch64_relocate_section (bfd
*output_bfd
,
5264 struct bfd_link_info
*info
,
5266 asection
*input_section
,
5268 Elf_Internal_Rela
*relocs
,
5269 Elf_Internal_Sym
*local_syms
,
5270 asection
**local_sections
)
5272 Elf_Internal_Shdr
*symtab_hdr
;
5273 struct elf_link_hash_entry
**sym_hashes
;
5274 Elf_Internal_Rela
*rel
;
5275 Elf_Internal_Rela
*relend
;
5277 struct elf_aarch64_link_hash_table
*globals
;
5278 bfd_boolean save_addend
= FALSE
;
5281 globals
= elf_aarch64_hash_table (info
);
5283 symtab_hdr
= &elf_symtab_hdr (input_bfd
);
5284 sym_hashes
= elf_sym_hashes (input_bfd
);
5287 relend
= relocs
+ input_section
->reloc_count
;
5288 for (; rel
< relend
; rel
++)
5290 unsigned int r_type
;
5291 bfd_reloc_code_real_type bfd_r_type
;
5292 bfd_reloc_code_real_type relaxed_bfd_r_type
;
5293 reloc_howto_type
*howto
;
5294 unsigned long r_symndx
;
5295 Elf_Internal_Sym
*sym
;
5297 struct elf_link_hash_entry
*h
;
5299 bfd_reloc_status_type r
;
5302 bfd_boolean unresolved_reloc
= FALSE
;
5303 char *error_message
= NULL
;
5305 r_symndx
= ELFNN_R_SYM (rel
->r_info
);
5306 r_type
= ELFNN_R_TYPE (rel
->r_info
);
5308 bfd_reloc
.howto
= elfNN_aarch64_howto_from_type (r_type
);
5309 howto
= bfd_reloc
.howto
;
5313 (*_bfd_error_handler
)
5314 (_("%B: unrecognized relocation (0x%x) in section `%A'"),
5315 input_bfd
, input_section
, r_type
);
5318 bfd_r_type
= elfNN_aarch64_bfd_reloc_from_howto (howto
);
5324 if (r_symndx
< symtab_hdr
->sh_info
)
5326 sym
= local_syms
+ r_symndx
;
5327 sym_type
= ELFNN_ST_TYPE (sym
->st_info
);
5328 sec
= local_sections
[r_symndx
];
5330 /* An object file might have a reference to a local
5331 undefined symbol. This is a daft object file, but we
5332 should at least do something about it. */
5333 if (r_type
!= R_AARCH64_NONE
&& r_type
!= R_AARCH64_NULL
5334 && bfd_is_und_section (sec
)
5335 && ELF_ST_BIND (sym
->st_info
) != STB_WEAK
)
5337 if (!info
->callbacks
->undefined_symbol
5338 (info
, bfd_elf_string_from_elf_section
5339 (input_bfd
, symtab_hdr
->sh_link
, sym
->st_name
),
5340 input_bfd
, input_section
, rel
->r_offset
, TRUE
))
5344 relocation
= _bfd_elf_rela_local_sym (output_bfd
, sym
, &sec
, rel
);
5346 /* Relocate against local STT_GNU_IFUNC symbol. */
5347 if (!info
->relocatable
5348 && ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
)
5350 h
= elfNN_aarch64_get_local_sym_hash (globals
, input_bfd
,
5355 /* Set STT_GNU_IFUNC symbol value. */
5356 h
->root
.u
.def
.value
= sym
->st_value
;
5357 h
->root
.u
.def
.section
= sec
;
5362 bfd_boolean warned
, ignored
;
5364 RELOC_FOR_GLOBAL_SYMBOL (info
, input_bfd
, input_section
, rel
,
5365 r_symndx
, symtab_hdr
, sym_hashes
,
5367 unresolved_reloc
, warned
, ignored
);
5372 if (sec
!= NULL
&& discarded_section (sec
))
5373 RELOC_AGAINST_DISCARDED_SECTION (info
, input_bfd
, input_section
,
5374 rel
, 1, relend
, howto
, 0, contents
);
5376 if (info
->relocatable
)
5380 name
= h
->root
.root
.string
;
5383 name
= (bfd_elf_string_from_elf_section
5384 (input_bfd
, symtab_hdr
->sh_link
, sym
->st_name
));
5385 if (name
== NULL
|| *name
== '\0')
5386 name
= bfd_section_name (input_bfd
, sec
);
5390 && r_type
!= R_AARCH64_NONE
5391 && r_type
!= R_AARCH64_NULL
5393 || h
->root
.type
== bfd_link_hash_defined
5394 || h
->root
.type
== bfd_link_hash_defweak
)
5395 && IS_AARCH64_TLS_RELOC (bfd_r_type
) != (sym_type
== STT_TLS
))
5397 (*_bfd_error_handler
)
5398 ((sym_type
== STT_TLS
5399 ? _("%B(%A+0x%lx): %s used with TLS symbol %s")
5400 : _("%B(%A+0x%lx): %s used with non-TLS symbol %s")),
5402 input_section
, (long) rel
->r_offset
, howto
->name
, name
);
5405 /* We relax only if we can see that there can be a valid transition
5406 from a reloc type to another.
5407 We call elfNN_aarch64_final_link_relocate unless we're completely
5408 done, i.e., the relaxation produced the final output we want. */
5410 relaxed_bfd_r_type
= aarch64_tls_transition (input_bfd
, info
, r_type
,
5412 if (relaxed_bfd_r_type
!= bfd_r_type
)
5414 bfd_r_type
= relaxed_bfd_r_type
;
5415 howto
= elfNN_aarch64_howto_from_bfd_reloc (bfd_r_type
);
5416 BFD_ASSERT (howto
!= NULL
);
5417 r_type
= howto
->type
;
5418 r
= elfNN_aarch64_tls_relax (globals
, input_bfd
, contents
, rel
, h
);
5419 unresolved_reloc
= 0;
5422 r
= bfd_reloc_continue
;
5424 /* There may be multiple consecutive relocations for the
5425 same offset. In that case we are supposed to treat the
5426 output of each relocation as the addend for the next. */
5427 if (rel
+ 1 < relend
5428 && rel
->r_offset
== rel
[1].r_offset
5429 && ELFNN_R_TYPE (rel
[1].r_info
) != R_AARCH64_NONE
5430 && ELFNN_R_TYPE (rel
[1].r_info
) != R_AARCH64_NULL
)
5433 save_addend
= FALSE
;
5435 if (r
== bfd_reloc_continue
)
5436 r
= elfNN_aarch64_final_link_relocate (howto
, input_bfd
, output_bfd
,
5437 input_section
, contents
, rel
,
5438 relocation
, info
, sec
,
5439 h
, &unresolved_reloc
,
5440 save_addend
, &addend
, sym
);
5442 switch (elfNN_aarch64_bfd_reloc_from_type (r_type
))
5444 case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC
:
5445 case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21
:
5446 case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21
:
5447 if (! symbol_got_offset_mark_p (input_bfd
, h
, r_symndx
))
5449 bfd_boolean need_relocs
= FALSE
;
5454 off
= symbol_got_offset (input_bfd
, h
, r_symndx
);
5455 indx
= h
&& h
->dynindx
!= -1 ? h
->dynindx
: 0;
5458 (info
->shared
|| indx
!= 0) &&
5460 || ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
5461 || h
->root
.type
!= bfd_link_hash_undefweak
);
5463 BFD_ASSERT (globals
->root
.srelgot
!= NULL
);
5467 Elf_Internal_Rela rela
;
5468 rela
.r_info
= ELFNN_R_INFO (indx
, AARCH64_R (TLS_DTPMOD
));
5470 rela
.r_offset
= globals
->root
.sgot
->output_section
->vma
+
5471 globals
->root
.sgot
->output_offset
+ off
;
5474 loc
= globals
->root
.srelgot
->contents
;
5475 loc
+= globals
->root
.srelgot
->reloc_count
++
5476 * RELOC_SIZE (htab
);
5477 bfd_elfNN_swap_reloca_out (output_bfd
, &rela
, loc
);
5481 bfd_put_NN (output_bfd
,
5482 relocation
- dtpoff_base (info
),
5483 globals
->root
.sgot
->contents
+ off
5488 /* This TLS symbol is global. We emit a
5489 relocation to fixup the tls offset at load
5492 ELFNN_R_INFO (indx
, AARCH64_R (TLS_DTPREL
));
5495 (globals
->root
.sgot
->output_section
->vma
5496 + globals
->root
.sgot
->output_offset
+ off
5499 loc
= globals
->root
.srelgot
->contents
;
5500 loc
+= globals
->root
.srelgot
->reloc_count
++
5501 * RELOC_SIZE (globals
);
5502 bfd_elfNN_swap_reloca_out (output_bfd
, &rela
, loc
);
5503 bfd_put_NN (output_bfd
, (bfd_vma
) 0,
5504 globals
->root
.sgot
->contents
+ off
5510 bfd_put_NN (output_bfd
, (bfd_vma
) 1,
5511 globals
->root
.sgot
->contents
+ off
);
5512 bfd_put_NN (output_bfd
,
5513 relocation
- dtpoff_base (info
),
5514 globals
->root
.sgot
->contents
+ off
5518 symbol_got_offset_mark (input_bfd
, h
, r_symndx
);
5522 case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21
:
5523 case BFD_RELOC_AARCH64_TLSIE_LDNN_GOTTPREL_LO12_NC
:
5524 case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19
:
5525 if (! symbol_got_offset_mark_p (input_bfd
, h
, r_symndx
))
5527 bfd_boolean need_relocs
= FALSE
;
5532 off
= symbol_got_offset (input_bfd
, h
, r_symndx
);
5534 indx
= h
&& h
->dynindx
!= -1 ? h
->dynindx
: 0;
5537 (info
->shared
|| indx
!= 0) &&
5539 || ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
5540 || h
->root
.type
!= bfd_link_hash_undefweak
);
5542 BFD_ASSERT (globals
->root
.srelgot
!= NULL
);
5546 Elf_Internal_Rela rela
;
5549 rela
.r_addend
= relocation
- dtpoff_base (info
);
5553 rela
.r_info
= ELFNN_R_INFO (indx
, AARCH64_R (TLS_TPREL
));
5554 rela
.r_offset
= globals
->root
.sgot
->output_section
->vma
+
5555 globals
->root
.sgot
->output_offset
+ off
;
5557 loc
= globals
->root
.srelgot
->contents
;
5558 loc
+= globals
->root
.srelgot
->reloc_count
++
5559 * RELOC_SIZE (htab
);
5561 bfd_elfNN_swap_reloca_out (output_bfd
, &rela
, loc
);
5563 bfd_put_NN (output_bfd
, rela
.r_addend
,
5564 globals
->root
.sgot
->contents
+ off
);
5567 bfd_put_NN (output_bfd
, relocation
- tpoff_base (info
),
5568 globals
->root
.sgot
->contents
+ off
);
5570 symbol_got_offset_mark (input_bfd
, h
, r_symndx
);
5574 case BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_HI12
:
5575 case BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_LO12
:
5576 case BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_LO12_NC
:
5577 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0
:
5578 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC
:
5579 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1
:
5580 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1_NC
:
5581 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G2
:
5584 case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12_NC
:
5585 case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21
:
5586 case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21
:
5587 case BFD_RELOC_AARCH64_TLSDESC_LDNN_LO12_NC
:
5588 case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19
:
5589 if (! symbol_tlsdesc_got_offset_mark_p (input_bfd
, h
, r_symndx
))
5591 bfd_boolean need_relocs
= FALSE
;
5592 int indx
= h
&& h
->dynindx
!= -1 ? h
->dynindx
: 0;
5593 bfd_vma off
= symbol_tlsdesc_got_offset (input_bfd
, h
, r_symndx
);
5595 need_relocs
= (h
== NULL
5596 || ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
5597 || h
->root
.type
!= bfd_link_hash_undefweak
);
5599 BFD_ASSERT (globals
->root
.srelgot
!= NULL
);
5600 BFD_ASSERT (globals
->root
.sgot
!= NULL
);
5605 Elf_Internal_Rela rela
;
5606 rela
.r_info
= ELFNN_R_INFO (indx
, AARCH64_R (TLSDESC
));
5609 rela
.r_offset
= (globals
->root
.sgotplt
->output_section
->vma
5610 + globals
->root
.sgotplt
->output_offset
5611 + off
+ globals
->sgotplt_jump_table_size
);
5614 rela
.r_addend
= relocation
- dtpoff_base (info
);
5616 /* Allocate the next available slot in the PLT reloc
5617 section to hold our R_AARCH64_TLSDESC, the next
5618 available slot is determined from reloc_count,
5619 which we step. But note, reloc_count was
5620 artifically moved down while allocating slots for
5621 real PLT relocs such that all of the PLT relocs
5622 will fit above the initial reloc_count and the
5623 extra stuff will fit below. */
5624 loc
= globals
->root
.srelplt
->contents
;
5625 loc
+= globals
->root
.srelplt
->reloc_count
++
5626 * RELOC_SIZE (globals
);
5628 bfd_elfNN_swap_reloca_out (output_bfd
, &rela
, loc
);
5630 bfd_put_NN (output_bfd
, (bfd_vma
) 0,
5631 globals
->root
.sgotplt
->contents
+ off
+
5632 globals
->sgotplt_jump_table_size
);
5633 bfd_put_NN (output_bfd
, (bfd_vma
) 0,
5634 globals
->root
.sgotplt
->contents
+ off
+
5635 globals
->sgotplt_jump_table_size
+
5639 symbol_tlsdesc_got_offset_mark (input_bfd
, h
, r_symndx
);
5650 /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
5651 because such sections are not SEC_ALLOC and thus ld.so will
5652 not process them. */
5653 if (unresolved_reloc
5654 && !((input_section
->flags
& SEC_DEBUGGING
) != 0
5656 && _bfd_elf_section_offset (output_bfd
, info
, input_section
,
5657 +rel
->r_offset
) != (bfd_vma
) - 1)
5659 (*_bfd_error_handler
)
5661 ("%B(%A+0x%lx): unresolvable %s relocation against symbol `%s'"),
5662 input_bfd
, input_section
, (long) rel
->r_offset
, howto
->name
,
5663 h
->root
.root
.string
);
5667 if (r
!= bfd_reloc_ok
&& r
!= bfd_reloc_continue
)
5671 case bfd_reloc_overflow
:
5672 if (!(*info
->callbacks
->reloc_overflow
)
5673 (info
, (h
? &h
->root
: NULL
), name
, howto
->name
, (bfd_vma
) 0,
5674 input_bfd
, input_section
, rel
->r_offset
))
5678 case bfd_reloc_undefined
:
5679 if (!((*info
->callbacks
->undefined_symbol
)
5680 (info
, name
, input_bfd
, input_section
,
5681 rel
->r_offset
, TRUE
)))
5685 case bfd_reloc_outofrange
:
5686 error_message
= _("out of range");
5689 case bfd_reloc_notsupported
:
5690 error_message
= _("unsupported relocation");
5693 case bfd_reloc_dangerous
:
5694 /* error_message should already be set. */
5698 error_message
= _("unknown error");
5702 BFD_ASSERT (error_message
!= NULL
);
5703 if (!((*info
->callbacks
->reloc_dangerous
)
5704 (info
, error_message
, input_bfd
, input_section
,
5715 /* Set the right machine number. */
5718 elfNN_aarch64_object_p (bfd
*abfd
)
5721 bfd_default_set_arch_mach (abfd
, bfd_arch_aarch64
, bfd_mach_aarch64_ilp32
);
5723 bfd_default_set_arch_mach (abfd
, bfd_arch_aarch64
, bfd_mach_aarch64
);
5728 /* Function to keep AArch64 specific flags in the ELF header. */
5731 elfNN_aarch64_set_private_flags (bfd
*abfd
, flagword flags
)
5733 if (elf_flags_init (abfd
) && elf_elfheader (abfd
)->e_flags
!= flags
)
5738 elf_elfheader (abfd
)->e_flags
= flags
;
5739 elf_flags_init (abfd
) = TRUE
;
5745 /* Merge backend specific data from an object file to the output
5746 object file when linking. */
5749 elfNN_aarch64_merge_private_bfd_data (bfd
*ibfd
, bfd
*obfd
)
5753 bfd_boolean flags_compatible
= TRUE
;
5756 /* Check if we have the same endianess. */
5757 if (!_bfd_generic_verify_endian_match (ibfd
, obfd
))
5760 if (!is_aarch64_elf (ibfd
) || !is_aarch64_elf (obfd
))
5763 /* The input BFD must have had its flags initialised. */
5764 /* The following seems bogus to me -- The flags are initialized in
5765 the assembler but I don't think an elf_flags_init field is
5766 written into the object. */
5767 /* BFD_ASSERT (elf_flags_init (ibfd)); */
5769 in_flags
= elf_elfheader (ibfd
)->e_flags
;
5770 out_flags
= elf_elfheader (obfd
)->e_flags
;
5772 if (!elf_flags_init (obfd
))
5774 /* If the input is the default architecture and had the default
5775 flags then do not bother setting the flags for the output
5776 architecture, instead allow future merges to do this. If no
5777 future merges ever set these flags then they will retain their
5778 uninitialised values, which surprise surprise, correspond
5779 to the default values. */
5780 if (bfd_get_arch_info (ibfd
)->the_default
5781 && elf_elfheader (ibfd
)->e_flags
== 0)
5784 elf_flags_init (obfd
) = TRUE
;
5785 elf_elfheader (obfd
)->e_flags
= in_flags
;
5787 if (bfd_get_arch (obfd
) == bfd_get_arch (ibfd
)
5788 && bfd_get_arch_info (obfd
)->the_default
)
5789 return bfd_set_arch_mach (obfd
, bfd_get_arch (ibfd
),
5790 bfd_get_mach (ibfd
));
5795 /* Identical flags must be compatible. */
5796 if (in_flags
== out_flags
)
5799 /* Check to see if the input BFD actually contains any sections. If
5800 not, its flags may not have been initialised either, but it
5801 cannot actually cause any incompatiblity. Do not short-circuit
5802 dynamic objects; their section list may be emptied by
5803 elf_link_add_object_symbols.
5805 Also check to see if there are no code sections in the input.
5806 In this case there is no need to check for code specific flags.
5807 XXX - do we need to worry about floating-point format compatability
5808 in data sections ? */
5809 if (!(ibfd
->flags
& DYNAMIC
))
5811 bfd_boolean null_input_bfd
= TRUE
;
5812 bfd_boolean only_data_sections
= TRUE
;
5814 for (sec
= ibfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
5816 if ((bfd_get_section_flags (ibfd
, sec
)
5817 & (SEC_LOAD
| SEC_CODE
| SEC_HAS_CONTENTS
))
5818 == (SEC_LOAD
| SEC_CODE
| SEC_HAS_CONTENTS
))
5819 only_data_sections
= FALSE
;
5821 null_input_bfd
= FALSE
;
5825 if (null_input_bfd
|| only_data_sections
)
5829 return flags_compatible
;
5832 /* Display the flags field. */
5835 elfNN_aarch64_print_private_bfd_data (bfd
*abfd
, void *ptr
)
5837 FILE *file
= (FILE *) ptr
;
5838 unsigned long flags
;
5840 BFD_ASSERT (abfd
!= NULL
&& ptr
!= NULL
);
5842 /* Print normal ELF private data. */
5843 _bfd_elf_print_private_bfd_data (abfd
, ptr
);
5845 flags
= elf_elfheader (abfd
)->e_flags
;
5846 /* Ignore init flag - it may not be set, despite the flags field
5847 containing valid data. */
5849 /* xgettext:c-format */
5850 fprintf (file
, _("private flags = %lx:"), elf_elfheader (abfd
)->e_flags
);
5853 fprintf (file
, _("<Unrecognised flag bits set>"));
5860 /* Update the got entry reference counts for the section being removed. */
5863 elfNN_aarch64_gc_sweep_hook (bfd
*abfd
,
5864 struct bfd_link_info
*info
,
5866 const Elf_Internal_Rela
* relocs
)
5868 struct elf_aarch64_link_hash_table
*htab
;
5869 Elf_Internal_Shdr
*symtab_hdr
;
5870 struct elf_link_hash_entry
**sym_hashes
;
5871 struct elf_aarch64_local_symbol
*locals
;
5872 const Elf_Internal_Rela
*rel
, *relend
;
5874 if (info
->relocatable
)
5877 htab
= elf_aarch64_hash_table (info
);
5882 elf_section_data (sec
)->local_dynrel
= NULL
;
5884 symtab_hdr
= &elf_symtab_hdr (abfd
);
5885 sym_hashes
= elf_sym_hashes (abfd
);
5887 locals
= elf_aarch64_locals (abfd
);
5889 relend
= relocs
+ sec
->reloc_count
;
5890 for (rel
= relocs
; rel
< relend
; rel
++)
5892 unsigned long r_symndx
;
5893 unsigned int r_type
;
5894 struct elf_link_hash_entry
*h
= NULL
;
5896 r_symndx
= ELFNN_R_SYM (rel
->r_info
);
5898 if (r_symndx
>= symtab_hdr
->sh_info
)
5901 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
5902 while (h
->root
.type
== bfd_link_hash_indirect
5903 || h
->root
.type
== bfd_link_hash_warning
)
5904 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
5908 Elf_Internal_Sym
*isym
;
5910 /* A local symbol. */
5911 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
5914 /* Check relocation against local STT_GNU_IFUNC symbol. */
5916 && ELF_ST_TYPE (isym
->st_info
) == STT_GNU_IFUNC
)
5918 h
= elfNN_aarch64_get_local_sym_hash (htab
, abfd
, rel
, FALSE
);
5926 struct elf_aarch64_link_hash_entry
*eh
;
5927 struct elf_dyn_relocs
**pp
;
5928 struct elf_dyn_relocs
*p
;
5930 eh
= (struct elf_aarch64_link_hash_entry
*) h
;
5932 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; pp
= &p
->next
)
5935 /* Everything must go for SEC. */
5941 r_type
= ELFNN_R_TYPE (rel
->r_info
);
5942 switch (aarch64_tls_transition (abfd
,info
, r_type
, h
,r_symndx
))
5944 case BFD_RELOC_AARCH64_ADR_GOT_PAGE
:
5945 case BFD_RELOC_AARCH64_GOT_LD_PREL19
:
5946 case BFD_RELOC_AARCH64_LD32_GOT_LO12_NC
:
5947 case BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15
:
5948 case BFD_RELOC_AARCH64_LD64_GOT_LO12_NC
:
5949 case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12_NC
:
5950 case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21
:
5951 case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21
:
5952 case BFD_RELOC_AARCH64_TLSDESC_LD32_LO12_NC
:
5953 case BFD_RELOC_AARCH64_TLSDESC_LD64_LO12_NC
:
5954 case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19
:
5955 case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC
:
5956 case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21
:
5957 case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21
:
5958 case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21
:
5959 case BFD_RELOC_AARCH64_TLSIE_LD32_GOTTPREL_LO12_NC
:
5960 case BFD_RELOC_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC
:
5961 case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19
:
5962 case BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_HI12
:
5963 case BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_LO12
:
5964 case BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_LO12_NC
:
5965 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0
:
5966 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC
:
5967 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1
:
5968 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1_NC
:
5969 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G2
:
5972 if (h
->got
.refcount
> 0)
5973 h
->got
.refcount
-= 1;
5975 if (h
->type
== STT_GNU_IFUNC
)
5977 if (h
->plt
.refcount
> 0)
5978 h
->plt
.refcount
-= 1;
5981 else if (locals
!= NULL
)
5983 if (locals
[r_symndx
].got_refcount
> 0)
5984 locals
[r_symndx
].got_refcount
-= 1;
5988 case BFD_RELOC_AARCH64_CALL26
:
5989 case BFD_RELOC_AARCH64_JUMP26
:
5990 /* If this is a local symbol then we resolve it
5991 directly without creating a PLT entry. */
5995 if (h
->plt
.refcount
> 0)
5996 h
->plt
.refcount
-= 1;
5999 case BFD_RELOC_AARCH64_ADR_HI21_NC_PCREL
:
6000 case BFD_RELOC_AARCH64_ADR_HI21_PCREL
:
6001 case BFD_RELOC_AARCH64_ADR_LO21_PCREL
:
6002 case BFD_RELOC_AARCH64_MOVW_G0_NC
:
6003 case BFD_RELOC_AARCH64_MOVW_G1_NC
:
6004 case BFD_RELOC_AARCH64_MOVW_G2_NC
:
6005 case BFD_RELOC_AARCH64_MOVW_G3
:
6006 case BFD_RELOC_AARCH64_NN
:
6007 if (h
!= NULL
&& info
->executable
)
6009 if (h
->plt
.refcount
> 0)
6010 h
->plt
.refcount
-= 1;
6022 /* Adjust a symbol defined by a dynamic object and referenced by a
6023 regular object. The current definition is in some section of the
6024 dynamic object, but we're not including those sections. We have to
6025 change the definition to something the rest of the link can
6029 elfNN_aarch64_adjust_dynamic_symbol (struct bfd_link_info
*info
,
6030 struct elf_link_hash_entry
*h
)
6032 struct elf_aarch64_link_hash_table
*htab
;
6035 /* If this is a function, put it in the procedure linkage table. We
6036 will fill in the contents of the procedure linkage table later,
6037 when we know the address of the .got section. */
6038 if (h
->type
== STT_FUNC
|| h
->type
== STT_GNU_IFUNC
|| h
->needs_plt
)
6040 if (h
->plt
.refcount
<= 0
6041 || (h
->type
!= STT_GNU_IFUNC
6042 && (SYMBOL_CALLS_LOCAL (info
, h
)
6043 || (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
6044 && h
->root
.type
== bfd_link_hash_undefweak
))))
6046 /* This case can occur if we saw a CALL26 reloc in
6047 an input file, but the symbol wasn't referred to
6048 by a dynamic object or all references were
6049 garbage collected. In which case we can end up
6051 h
->plt
.offset
= (bfd_vma
) - 1;
6058 /* Otherwise, reset to -1. */
6059 h
->plt
.offset
= (bfd_vma
) - 1;
6062 /* If this is a weak symbol, and there is a real definition, the
6063 processor independent code will have arranged for us to see the
6064 real definition first, and we can just use the same value. */
6065 if (h
->u
.weakdef
!= NULL
)
6067 BFD_ASSERT (h
->u
.weakdef
->root
.type
== bfd_link_hash_defined
6068 || h
->u
.weakdef
->root
.type
== bfd_link_hash_defweak
);
6069 h
->root
.u
.def
.section
= h
->u
.weakdef
->root
.u
.def
.section
;
6070 h
->root
.u
.def
.value
= h
->u
.weakdef
->root
.u
.def
.value
;
6071 if (ELIMINATE_COPY_RELOCS
|| info
->nocopyreloc
)
6072 h
->non_got_ref
= h
->u
.weakdef
->non_got_ref
;
6076 /* If we are creating a shared library, we must presume that the
6077 only references to the symbol are via the global offset table.
6078 For such cases we need not do anything here; the relocations will
6079 be handled correctly by relocate_section. */
6083 /* If there are no references to this symbol that do not use the
6084 GOT, we don't need to generate a copy reloc. */
6085 if (!h
->non_got_ref
)
6088 /* If -z nocopyreloc was given, we won't generate them either. */
6089 if (info
->nocopyreloc
)
6095 /* We must allocate the symbol in our .dynbss section, which will
6096 become part of the .bss section of the executable. There will be
6097 an entry for this symbol in the .dynsym section. The dynamic
6098 object will contain position independent code, so all references
6099 from the dynamic object to this symbol will go through the global
6100 offset table. The dynamic linker will use the .dynsym entry to
6101 determine the address it must put in the global offset table, so
6102 both the dynamic object and the regular object will refer to the
6103 same memory location for the variable. */
6105 htab
= elf_aarch64_hash_table (info
);
6107 /* We must generate a R_AARCH64_COPY reloc to tell the dynamic linker
6108 to copy the initial value out of the dynamic object and into the
6109 runtime process image. */
6110 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0 && h
->size
!= 0)
6112 htab
->srelbss
->size
+= RELOC_SIZE (htab
);
6118 return _bfd_elf_adjust_dynamic_copy (info
, h
, s
);
6123 elfNN_aarch64_allocate_local_symbols (bfd
*abfd
, unsigned number
)
6125 struct elf_aarch64_local_symbol
*locals
;
6126 locals
= elf_aarch64_locals (abfd
);
6129 locals
= (struct elf_aarch64_local_symbol
*)
6130 bfd_zalloc (abfd
, number
* sizeof (struct elf_aarch64_local_symbol
));
6133 elf_aarch64_locals (abfd
) = locals
;
6138 /* Create the .got section to hold the global offset table. */
6141 aarch64_elf_create_got_section (bfd
*abfd
, struct bfd_link_info
*info
)
6143 const struct elf_backend_data
*bed
= get_elf_backend_data (abfd
);
6146 struct elf_link_hash_entry
*h
;
6147 struct elf_link_hash_table
*htab
= elf_hash_table (info
);
6149 /* This function may be called more than once. */
6150 s
= bfd_get_linker_section (abfd
, ".got");
6154 flags
= bed
->dynamic_sec_flags
;
6156 s
= bfd_make_section_anyway_with_flags (abfd
,
6157 (bed
->rela_plts_and_copies_p
6158 ? ".rela.got" : ".rel.got"),
6159 (bed
->dynamic_sec_flags
6162 || ! bfd_set_section_alignment (abfd
, s
, bed
->s
->log_file_align
))
6166 s
= bfd_make_section_anyway_with_flags (abfd
, ".got", flags
);
6168 || !bfd_set_section_alignment (abfd
, s
, bed
->s
->log_file_align
))
6171 htab
->sgot
->size
+= GOT_ENTRY_SIZE
;
6173 if (bed
->want_got_sym
)
6175 /* Define the symbol _GLOBAL_OFFSET_TABLE_ at the start of the .got
6176 (or .got.plt) section. We don't do this in the linker script
6177 because we don't want to define the symbol if we are not creating
6178 a global offset table. */
6179 h
= _bfd_elf_define_linkage_sym (abfd
, info
, s
,
6180 "_GLOBAL_OFFSET_TABLE_");
6181 elf_hash_table (info
)->hgot
= h
;
6186 if (bed
->want_got_plt
)
6188 s
= bfd_make_section_anyway_with_flags (abfd
, ".got.plt", flags
);
6190 || !bfd_set_section_alignment (abfd
, s
,
6191 bed
->s
->log_file_align
))
6196 /* The first bit of the global offset table is the header. */
6197 s
->size
+= bed
->got_header_size
;
6202 /* Look through the relocs for a section during the first phase. */
6205 elfNN_aarch64_check_relocs (bfd
*abfd
, struct bfd_link_info
*info
,
6206 asection
*sec
, const Elf_Internal_Rela
*relocs
)
6208 Elf_Internal_Shdr
*symtab_hdr
;
6209 struct elf_link_hash_entry
**sym_hashes
;
6210 const Elf_Internal_Rela
*rel
;
6211 const Elf_Internal_Rela
*rel_end
;
6214 struct elf_aarch64_link_hash_table
*htab
;
6216 if (info
->relocatable
)
6219 BFD_ASSERT (is_aarch64_elf (abfd
));
6221 htab
= elf_aarch64_hash_table (info
);
6224 symtab_hdr
= &elf_symtab_hdr (abfd
);
6225 sym_hashes
= elf_sym_hashes (abfd
);
6227 rel_end
= relocs
+ sec
->reloc_count
;
6228 for (rel
= relocs
; rel
< rel_end
; rel
++)
6230 struct elf_link_hash_entry
*h
;
6231 unsigned long r_symndx
;
6232 unsigned int r_type
;
6233 bfd_reloc_code_real_type bfd_r_type
;
6234 Elf_Internal_Sym
*isym
;
6236 r_symndx
= ELFNN_R_SYM (rel
->r_info
);
6237 r_type
= ELFNN_R_TYPE (rel
->r_info
);
6239 if (r_symndx
>= NUM_SHDR_ENTRIES (symtab_hdr
))
6241 (*_bfd_error_handler
) (_("%B: bad symbol index: %d"), abfd
,
6246 if (r_symndx
< symtab_hdr
->sh_info
)
6248 /* A local symbol. */
6249 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
6254 /* Check relocation against local STT_GNU_IFUNC symbol. */
6255 if (ELF_ST_TYPE (isym
->st_info
) == STT_GNU_IFUNC
)
6257 h
= elfNN_aarch64_get_local_sym_hash (htab
, abfd
, rel
,
6262 /* Fake a STT_GNU_IFUNC symbol. */
6263 h
->type
= STT_GNU_IFUNC
;
6266 h
->forced_local
= 1;
6267 h
->root
.type
= bfd_link_hash_defined
;
6274 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
6275 while (h
->root
.type
== bfd_link_hash_indirect
6276 || h
->root
.type
== bfd_link_hash_warning
)
6277 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
6279 /* PR15323, ref flags aren't set for references in the same
6281 h
->root
.non_ir_ref
= 1;
6284 /* Could be done earlier, if h were already available. */
6285 bfd_r_type
= aarch64_tls_transition (abfd
, info
, r_type
, h
, r_symndx
);
6289 /* Create the ifunc sections for static executables. If we
6290 never see an indirect function symbol nor we are building
6291 a static executable, those sections will be empty and
6292 won't appear in output. */
6298 case BFD_RELOC_AARCH64_ADD_LO12
:
6299 case BFD_RELOC_AARCH64_ADR_GOT_PAGE
:
6300 case BFD_RELOC_AARCH64_ADR_HI21_PCREL
:
6301 case BFD_RELOC_AARCH64_CALL26
:
6302 case BFD_RELOC_AARCH64_GOT_LD_PREL19
:
6303 case BFD_RELOC_AARCH64_JUMP26
:
6304 case BFD_RELOC_AARCH64_LD32_GOT_LO12_NC
:
6305 case BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15
:
6306 case BFD_RELOC_AARCH64_LD64_GOT_LO12_NC
:
6307 case BFD_RELOC_AARCH64_NN
:
6308 if (htab
->root
.dynobj
== NULL
)
6309 htab
->root
.dynobj
= abfd
;
6310 if (!_bfd_elf_create_ifunc_sections (htab
->root
.dynobj
, info
))
6315 /* It is referenced by a non-shared object. */
6317 h
->root
.non_ir_ref
= 1;
6322 case BFD_RELOC_AARCH64_NN
:
6324 /* We don't need to handle relocs into sections not going into
6325 the "real" output. */
6326 if ((sec
->flags
& SEC_ALLOC
) == 0)
6334 h
->plt
.refcount
+= 1;
6335 h
->pointer_equality_needed
= 1;
6338 /* No need to do anything if we're not creating a shared
6344 struct elf_dyn_relocs
*p
;
6345 struct elf_dyn_relocs
**head
;
6347 /* We must copy these reloc types into the output file.
6348 Create a reloc section in dynobj and make room for
6352 if (htab
->root
.dynobj
== NULL
)
6353 htab
->root
.dynobj
= abfd
;
6355 sreloc
= _bfd_elf_make_dynamic_reloc_section
6356 (sec
, htab
->root
.dynobj
, LOG_FILE_ALIGN
, abfd
, /*rela? */ TRUE
);
6362 /* If this is a global symbol, we count the number of
6363 relocations we need for this symbol. */
6366 struct elf_aarch64_link_hash_entry
*eh
;
6367 eh
= (struct elf_aarch64_link_hash_entry
*) h
;
6368 head
= &eh
->dyn_relocs
;
6372 /* Track dynamic relocs needed for local syms too.
6373 We really need local syms available to do this
6379 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
6384 s
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
6388 /* Beware of type punned pointers vs strict aliasing
6390 vpp
= &(elf_section_data (s
)->local_dynrel
);
6391 head
= (struct elf_dyn_relocs
**) vpp
;
6395 if (p
== NULL
|| p
->sec
!= sec
)
6397 bfd_size_type amt
= sizeof *p
;
6398 p
= ((struct elf_dyn_relocs
*)
6399 bfd_zalloc (htab
->root
.dynobj
, amt
));
6412 /* RR: We probably want to keep a consistency check that
6413 there are no dangling GOT_PAGE relocs. */
6414 case BFD_RELOC_AARCH64_ADR_GOT_PAGE
:
6415 case BFD_RELOC_AARCH64_GOT_LD_PREL19
:
6416 case BFD_RELOC_AARCH64_LD32_GOT_LO12_NC
:
6417 case BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15
:
6418 case BFD_RELOC_AARCH64_LD64_GOT_LO12_NC
:
6419 case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12_NC
:
6420 case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21
:
6421 case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21
:
6422 case BFD_RELOC_AARCH64_TLSDESC_LD32_LO12_NC
:
6423 case BFD_RELOC_AARCH64_TLSDESC_LD64_LO12_NC
:
6424 case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19
:
6425 case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC
:
6426 case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21
:
6427 case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21
:
6428 case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21
:
6429 case BFD_RELOC_AARCH64_TLSIE_LD32_GOTTPREL_LO12_NC
:
6430 case BFD_RELOC_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC
:
6431 case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19
:
6432 case BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_HI12
:
6433 case BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_LO12
:
6434 case BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_LO12_NC
:
6435 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0
:
6436 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC
:
6437 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1
:
6438 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1_NC
:
6439 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G2
:
6442 unsigned old_got_type
;
6444 got_type
= aarch64_reloc_got_type (bfd_r_type
);
6448 h
->got
.refcount
+= 1;
6449 old_got_type
= elf_aarch64_hash_entry (h
)->got_type
;
6453 struct elf_aarch64_local_symbol
*locals
;
6455 if (!elfNN_aarch64_allocate_local_symbols
6456 (abfd
, symtab_hdr
->sh_info
))
6459 locals
= elf_aarch64_locals (abfd
);
6460 BFD_ASSERT (r_symndx
< symtab_hdr
->sh_info
);
6461 locals
[r_symndx
].got_refcount
+= 1;
6462 old_got_type
= locals
[r_symndx
].got_type
;
6465 /* If a variable is accessed with both general dynamic TLS
6466 methods, two slots may be created. */
6467 if (GOT_TLS_GD_ANY_P (old_got_type
) && GOT_TLS_GD_ANY_P (got_type
))
6468 got_type
|= old_got_type
;
6470 /* We will already have issued an error message if there
6471 is a TLS/non-TLS mismatch, based on the symbol type.
6472 So just combine any TLS types needed. */
6473 if (old_got_type
!= GOT_UNKNOWN
&& old_got_type
!= GOT_NORMAL
6474 && got_type
!= GOT_NORMAL
)
6475 got_type
|= old_got_type
;
6477 /* If the symbol is accessed by both IE and GD methods, we
6478 are able to relax. Turn off the GD flag, without
6479 messing up with any other kind of TLS types that may be
6481 if ((got_type
& GOT_TLS_IE
) && GOT_TLS_GD_ANY_P (got_type
))
6482 got_type
&= ~ (GOT_TLSDESC_GD
| GOT_TLS_GD
);
6484 if (old_got_type
!= got_type
)
6487 elf_aarch64_hash_entry (h
)->got_type
= got_type
;
6490 struct elf_aarch64_local_symbol
*locals
;
6491 locals
= elf_aarch64_locals (abfd
);
6492 BFD_ASSERT (r_symndx
< symtab_hdr
->sh_info
);
6493 locals
[r_symndx
].got_type
= got_type
;
6497 if (htab
->root
.dynobj
== NULL
)
6498 htab
->root
.dynobj
= abfd
;
6499 if (! aarch64_elf_create_got_section (htab
->root
.dynobj
, info
))
6504 case BFD_RELOC_AARCH64_MOVW_G0_NC
:
6505 case BFD_RELOC_AARCH64_MOVW_G1_NC
:
6506 case BFD_RELOC_AARCH64_MOVW_G2_NC
:
6507 case BFD_RELOC_AARCH64_MOVW_G3
:
6510 int howto_index
= bfd_r_type
- BFD_RELOC_AARCH64_RELOC_START
;
6511 (*_bfd_error_handler
)
6512 (_("%B: relocation %s against `%s' can not be used when making "
6513 "a shared object; recompile with -fPIC"),
6514 abfd
, elfNN_aarch64_howto_table
[howto_index
].name
,
6515 (h
) ? h
->root
.root
.string
: "a local symbol");
6516 bfd_set_error (bfd_error_bad_value
);
6520 case BFD_RELOC_AARCH64_ADR_HI21_NC_PCREL
:
6521 case BFD_RELOC_AARCH64_ADR_HI21_PCREL
:
6522 case BFD_RELOC_AARCH64_ADR_LO21_PCREL
:
6523 if (h
!= NULL
&& info
->executable
)
6525 /* If this reloc is in a read-only section, we might
6526 need a copy reloc. We can't check reliably at this
6527 stage whether the section is read-only, as input
6528 sections have not yet been mapped to output sections.
6529 Tentatively set the flag for now, and correct in
6530 adjust_dynamic_symbol. */
6532 h
->plt
.refcount
+= 1;
6533 h
->pointer_equality_needed
= 1;
6535 /* FIXME:: RR need to handle these in shared libraries
6536 and essentially bomb out as these being non-PIC
6537 relocations in shared libraries. */
6540 case BFD_RELOC_AARCH64_CALL26
:
6541 case BFD_RELOC_AARCH64_JUMP26
:
6542 /* If this is a local symbol then we resolve it
6543 directly without creating a PLT entry. */
6548 if (h
->plt
.refcount
<= 0)
6549 h
->plt
.refcount
= 1;
6551 h
->plt
.refcount
+= 1;
6562 /* Treat mapping symbols as special target symbols. */
6565 elfNN_aarch64_is_target_special_symbol (bfd
*abfd ATTRIBUTE_UNUSED
,
6568 return bfd_is_aarch64_special_symbol_name (sym
->name
,
6569 BFD_AARCH64_SPECIAL_SYM_TYPE_ANY
);
6572 /* This is a copy of elf_find_function () from elf.c except that
6573 AArch64 mapping symbols are ignored when looking for function names. */
6576 aarch64_elf_find_function (bfd
*abfd ATTRIBUTE_UNUSED
,
6580 const char **filename_ptr
,
6581 const char **functionname_ptr
)
6583 const char *filename
= NULL
;
6584 asymbol
*func
= NULL
;
6585 bfd_vma low_func
= 0;
6588 for (p
= symbols
; *p
!= NULL
; p
++)
6592 q
= (elf_symbol_type
*) * p
;
6594 switch (ELF_ST_TYPE (q
->internal_elf_sym
.st_info
))
6599 filename
= bfd_asymbol_name (&q
->symbol
);
6603 /* Skip mapping symbols. */
6604 if ((q
->symbol
.flags
& BSF_LOCAL
)
6605 && (bfd_is_aarch64_special_symbol_name
6606 (q
->symbol
.name
, BFD_AARCH64_SPECIAL_SYM_TYPE_ANY
)))
6609 if (bfd_get_section (&q
->symbol
) == section
6610 && q
->symbol
.value
>= low_func
&& q
->symbol
.value
<= offset
)
6612 func
= (asymbol
*) q
;
6613 low_func
= q
->symbol
.value
;
6623 *filename_ptr
= filename
;
6624 if (functionname_ptr
)
6625 *functionname_ptr
= bfd_asymbol_name (func
);
6631 /* Find the nearest line to a particular section and offset, for error
6632 reporting. This code is a duplicate of the code in elf.c, except
6633 that it uses aarch64_elf_find_function. */
6636 elfNN_aarch64_find_nearest_line (bfd
*abfd
,
6640 const char **filename_ptr
,
6641 const char **functionname_ptr
,
6642 unsigned int *line_ptr
,
6643 unsigned int *discriminator_ptr
)
6645 bfd_boolean found
= FALSE
;
6647 if (_bfd_dwarf2_find_nearest_line (abfd
, symbols
, NULL
, section
, offset
,
6648 filename_ptr
, functionname_ptr
,
6649 line_ptr
, discriminator_ptr
,
6650 dwarf_debug_sections
, 0,
6651 &elf_tdata (abfd
)->dwarf2_find_line_info
))
6653 if (!*functionname_ptr
)
6654 aarch64_elf_find_function (abfd
, symbols
, section
, offset
,
6655 *filename_ptr
? NULL
: filename_ptr
,
6661 /* Skip _bfd_dwarf1_find_nearest_line since no known AArch64
6662 toolchain uses DWARF1. */
6664 if (!_bfd_stab_section_find_nearest_line (abfd
, symbols
, section
, offset
,
6665 &found
, filename_ptr
,
6666 functionname_ptr
, line_ptr
,
6667 &elf_tdata (abfd
)->line_info
))
6670 if (found
&& (*functionname_ptr
|| *line_ptr
))
6673 if (symbols
== NULL
)
6676 if (!aarch64_elf_find_function (abfd
, symbols
, section
, offset
,
6677 filename_ptr
, functionname_ptr
))
6685 elfNN_aarch64_find_inliner_info (bfd
*abfd
,
6686 const char **filename_ptr
,
6687 const char **functionname_ptr
,
6688 unsigned int *line_ptr
)
6691 found
= _bfd_dwarf2_find_inliner_info
6692 (abfd
, filename_ptr
,
6693 functionname_ptr
, line_ptr
, &elf_tdata (abfd
)->dwarf2_find_line_info
);
6699 elfNN_aarch64_post_process_headers (bfd
*abfd
,
6700 struct bfd_link_info
*link_info
)
6702 Elf_Internal_Ehdr
*i_ehdrp
; /* ELF file header, internal form. */
6704 i_ehdrp
= elf_elfheader (abfd
);
6705 i_ehdrp
->e_ident
[EI_ABIVERSION
] = AARCH64_ELF_ABI_VERSION
;
6707 _bfd_elf_post_process_headers (abfd
, link_info
);
6710 static enum elf_reloc_type_class
6711 elfNN_aarch64_reloc_type_class (const struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
6712 const asection
*rel_sec ATTRIBUTE_UNUSED
,
6713 const Elf_Internal_Rela
*rela
)
6715 switch ((int) ELFNN_R_TYPE (rela
->r_info
))
6717 case AARCH64_R (RELATIVE
):
6718 return reloc_class_relative
;
6719 case AARCH64_R (JUMP_SLOT
):
6720 return reloc_class_plt
;
6721 case AARCH64_R (COPY
):
6722 return reloc_class_copy
;
6724 return reloc_class_normal
;
6728 /* Handle an AArch64 specific section when reading an object file. This is
6729 called when bfd_section_from_shdr finds a section with an unknown
6733 elfNN_aarch64_section_from_shdr (bfd
*abfd
,
6734 Elf_Internal_Shdr
*hdr
,
6735 const char *name
, int shindex
)
6737 /* There ought to be a place to keep ELF backend specific flags, but
6738 at the moment there isn't one. We just keep track of the
6739 sections by their name, instead. Fortunately, the ABI gives
6740 names for all the AArch64 specific sections, so we will probably get
6742 switch (hdr
->sh_type
)
6744 case SHT_AARCH64_ATTRIBUTES
:
6751 if (!_bfd_elf_make_section_from_shdr (abfd
, hdr
, name
, shindex
))
6757 /* A structure used to record a list of sections, independently
6758 of the next and prev fields in the asection structure. */
6759 typedef struct section_list
6762 struct section_list
*next
;
6763 struct section_list
*prev
;
6767 /* Unfortunately we need to keep a list of sections for which
6768 an _aarch64_elf_section_data structure has been allocated. This
6769 is because it is possible for functions like elfNN_aarch64_write_section
6770 to be called on a section which has had an elf_data_structure
6771 allocated for it (and so the used_by_bfd field is valid) but
6772 for which the AArch64 extended version of this structure - the
6773 _aarch64_elf_section_data structure - has not been allocated. */
6774 static section_list
*sections_with_aarch64_elf_section_data
= NULL
;
6777 record_section_with_aarch64_elf_section_data (asection
*sec
)
6779 struct section_list
*entry
;
6781 entry
= bfd_malloc (sizeof (*entry
));
6785 entry
->next
= sections_with_aarch64_elf_section_data
;
6787 if (entry
->next
!= NULL
)
6788 entry
->next
->prev
= entry
;
6789 sections_with_aarch64_elf_section_data
= entry
;
6792 static struct section_list
*
6793 find_aarch64_elf_section_entry (asection
*sec
)
6795 struct section_list
*entry
;
6796 static struct section_list
*last_entry
= NULL
;
6798 /* This is a short cut for the typical case where the sections are added
6799 to the sections_with_aarch64_elf_section_data list in forward order and
6800 then looked up here in backwards order. This makes a real difference
6801 to the ld-srec/sec64k.exp linker test. */
6802 entry
= sections_with_aarch64_elf_section_data
;
6803 if (last_entry
!= NULL
)
6805 if (last_entry
->sec
== sec
)
6807 else if (last_entry
->next
!= NULL
&& last_entry
->next
->sec
== sec
)
6808 entry
= last_entry
->next
;
6811 for (; entry
; entry
= entry
->next
)
6812 if (entry
->sec
== sec
)
6816 /* Record the entry prior to this one - it is the entry we are
6817 most likely to want to locate next time. Also this way if we
6818 have been called from
6819 unrecord_section_with_aarch64_elf_section_data () we will not
6820 be caching a pointer that is about to be freed. */
6821 last_entry
= entry
->prev
;
6827 unrecord_section_with_aarch64_elf_section_data (asection
*sec
)
6829 struct section_list
*entry
;
6831 entry
= find_aarch64_elf_section_entry (sec
);
6835 if (entry
->prev
!= NULL
)
6836 entry
->prev
->next
= entry
->next
;
6837 if (entry
->next
!= NULL
)
6838 entry
->next
->prev
= entry
->prev
;
6839 if (entry
== sections_with_aarch64_elf_section_data
)
6840 sections_with_aarch64_elf_section_data
= entry
->next
;
6849 struct bfd_link_info
*info
;
6852 int (*func
) (void *, const char *, Elf_Internal_Sym
*,
6853 asection
*, struct elf_link_hash_entry
*);
6854 } output_arch_syminfo
;
6856 enum map_symbol_type
6863 /* Output a single mapping symbol. */
6866 elfNN_aarch64_output_map_sym (output_arch_syminfo
*osi
,
6867 enum map_symbol_type type
, bfd_vma offset
)
6869 static const char *names
[2] = { "$x", "$d" };
6870 Elf_Internal_Sym sym
;
6872 sym
.st_value
= (osi
->sec
->output_section
->vma
6873 + osi
->sec
->output_offset
+ offset
);
6876 sym
.st_info
= ELF_ST_INFO (STB_LOCAL
, STT_NOTYPE
);
6877 sym
.st_shndx
= osi
->sec_shndx
;
6878 return osi
->func (osi
->finfo
, names
[type
], &sym
, osi
->sec
, NULL
) == 1;
6883 /* Output mapping symbols for PLT entries associated with H. */
6886 elfNN_aarch64_output_plt_map (struct elf_link_hash_entry
*h
, void *inf
)
6888 output_arch_syminfo
*osi
= (output_arch_syminfo
*) inf
;
6891 if (h
->root
.type
== bfd_link_hash_indirect
)
6894 if (h
->root
.type
== bfd_link_hash_warning
)
6895 /* When warning symbols are created, they **replace** the "real"
6896 entry in the hash table, thus we never get to see the real
6897 symbol in a hash traversal. So look at it now. */
6898 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
6900 if (h
->plt
.offset
== (bfd_vma
) - 1)
6903 addr
= h
->plt
.offset
;
6906 if (!elfNN_aarch64_output_map_sym (osi
, AARCH64_MAP_INSN
, addr
))
6913 /* Output a single local symbol for a generated stub. */
6916 elfNN_aarch64_output_stub_sym (output_arch_syminfo
*osi
, const char *name
,
6917 bfd_vma offset
, bfd_vma size
)
6919 Elf_Internal_Sym sym
;
6921 sym
.st_value
= (osi
->sec
->output_section
->vma
6922 + osi
->sec
->output_offset
+ offset
);
6925 sym
.st_info
= ELF_ST_INFO (STB_LOCAL
, STT_FUNC
);
6926 sym
.st_shndx
= osi
->sec_shndx
;
6927 return osi
->func (osi
->finfo
, name
, &sym
, osi
->sec
, NULL
) == 1;
6931 aarch64_map_one_stub (struct bfd_hash_entry
*gen_entry
, void *in_arg
)
6933 struct elf_aarch64_stub_hash_entry
*stub_entry
;
6937 output_arch_syminfo
*osi
;
6939 /* Massage our args to the form they really have. */
6940 stub_entry
= (struct elf_aarch64_stub_hash_entry
*) gen_entry
;
6941 osi
= (output_arch_syminfo
*) in_arg
;
6943 stub_sec
= stub_entry
->stub_sec
;
6945 /* Ensure this stub is attached to the current section being
6947 if (stub_sec
!= osi
->sec
)
6950 addr
= (bfd_vma
) stub_entry
->stub_offset
;
6952 stub_name
= stub_entry
->output_name
;
6954 switch (stub_entry
->stub_type
)
6956 case aarch64_stub_adrp_branch
:
6957 if (!elfNN_aarch64_output_stub_sym (osi
, stub_name
, addr
,
6958 sizeof (aarch64_adrp_branch_stub
)))
6960 if (!elfNN_aarch64_output_map_sym (osi
, AARCH64_MAP_INSN
, addr
))
6963 case aarch64_stub_long_branch
:
6964 if (!elfNN_aarch64_output_stub_sym
6965 (osi
, stub_name
, addr
, sizeof (aarch64_long_branch_stub
)))
6967 if (!elfNN_aarch64_output_map_sym (osi
, AARCH64_MAP_INSN
, addr
))
6969 if (!elfNN_aarch64_output_map_sym (osi
, AARCH64_MAP_DATA
, addr
+ 16))
6972 case aarch64_stub_erratum_835769_veneer
:
6973 if (!elfNN_aarch64_output_stub_sym (osi
, stub_name
, addr
,
6974 sizeof (aarch64_erratum_835769_stub
)))
6976 if (!elfNN_aarch64_output_map_sym (osi
, AARCH64_MAP_INSN
, addr
))
6979 case aarch64_stub_erratum_843419_veneer
:
6980 if (!elfNN_aarch64_output_stub_sym (osi
, stub_name
, addr
,
6981 sizeof (aarch64_erratum_843419_stub
)))
6983 if (!elfNN_aarch64_output_map_sym (osi
, AARCH64_MAP_INSN
, addr
))
6994 /* Output mapping symbols for linker generated sections. */
6997 elfNN_aarch64_output_arch_local_syms (bfd
*output_bfd
,
6998 struct bfd_link_info
*info
,
7000 int (*func
) (void *, const char *,
7003 struct elf_link_hash_entry
7006 output_arch_syminfo osi
;
7007 struct elf_aarch64_link_hash_table
*htab
;
7009 htab
= elf_aarch64_hash_table (info
);
7015 /* Long calls stubs. */
7016 if (htab
->stub_bfd
&& htab
->stub_bfd
->sections
)
7020 for (stub_sec
= htab
->stub_bfd
->sections
;
7021 stub_sec
!= NULL
; stub_sec
= stub_sec
->next
)
7023 /* Ignore non-stub sections. */
7024 if (!strstr (stub_sec
->name
, STUB_SUFFIX
))
7029 osi
.sec_shndx
= _bfd_elf_section_from_bfd_section
7030 (output_bfd
, osi
.sec
->output_section
);
7032 /* The first instruction in a stub is always a branch. */
7033 if (!elfNN_aarch64_output_map_sym (&osi
, AARCH64_MAP_INSN
, 0))
7036 bfd_hash_traverse (&htab
->stub_hash_table
, aarch64_map_one_stub
,
7041 /* Finally, output mapping symbols for the PLT. */
7042 if (!htab
->root
.splt
|| htab
->root
.splt
->size
== 0)
7045 /* For now live without mapping symbols for the plt. */
7046 osi
.sec_shndx
= _bfd_elf_section_from_bfd_section
7047 (output_bfd
, htab
->root
.splt
->output_section
);
7048 osi
.sec
= htab
->root
.splt
;
7050 elf_link_hash_traverse (&htab
->root
, elfNN_aarch64_output_plt_map
,
7057 /* Allocate target specific section data. */
7060 elfNN_aarch64_new_section_hook (bfd
*abfd
, asection
*sec
)
7062 if (!sec
->used_by_bfd
)
7064 _aarch64_elf_section_data
*sdata
;
7065 bfd_size_type amt
= sizeof (*sdata
);
7067 sdata
= bfd_zalloc (abfd
, amt
);
7070 sec
->used_by_bfd
= sdata
;
7073 record_section_with_aarch64_elf_section_data (sec
);
7075 return _bfd_elf_new_section_hook (abfd
, sec
);
7080 unrecord_section_via_map_over_sections (bfd
*abfd ATTRIBUTE_UNUSED
,
7082 void *ignore ATTRIBUTE_UNUSED
)
7084 unrecord_section_with_aarch64_elf_section_data (sec
);
7088 elfNN_aarch64_close_and_cleanup (bfd
*abfd
)
7091 bfd_map_over_sections (abfd
,
7092 unrecord_section_via_map_over_sections
, NULL
);
7094 return _bfd_elf_close_and_cleanup (abfd
);
7098 elfNN_aarch64_bfd_free_cached_info (bfd
*abfd
)
7101 bfd_map_over_sections (abfd
,
7102 unrecord_section_via_map_over_sections
, NULL
);
7104 return _bfd_free_cached_info (abfd
);
7107 /* Create dynamic sections. This is different from the ARM backend in that
7108 the got, plt, gotplt and their relocation sections are all created in the
7109 standard part of the bfd elf backend. */
7112 elfNN_aarch64_create_dynamic_sections (bfd
*dynobj
,
7113 struct bfd_link_info
*info
)
7115 struct elf_aarch64_link_hash_table
*htab
;
7117 /* We need to create .got section. */
7118 if (!aarch64_elf_create_got_section (dynobj
, info
))
7121 if (!_bfd_elf_create_dynamic_sections (dynobj
, info
))
7124 htab
= elf_aarch64_hash_table (info
);
7125 htab
->sdynbss
= bfd_get_linker_section (dynobj
, ".dynbss");
7127 htab
->srelbss
= bfd_get_linker_section (dynobj
, ".rela.bss");
7129 if (!htab
->sdynbss
|| (!info
->shared
&& !htab
->srelbss
))
7136 /* Allocate space in .plt, .got and associated reloc sections for
7140 elfNN_aarch64_allocate_dynrelocs (struct elf_link_hash_entry
*h
, void *inf
)
7142 struct bfd_link_info
*info
;
7143 struct elf_aarch64_link_hash_table
*htab
;
7144 struct elf_aarch64_link_hash_entry
*eh
;
7145 struct elf_dyn_relocs
*p
;
7147 /* An example of a bfd_link_hash_indirect symbol is versioned
7148 symbol. For example: __gxx_personality_v0(bfd_link_hash_indirect)
7149 -> __gxx_personality_v0(bfd_link_hash_defined)
7151 There is no need to process bfd_link_hash_indirect symbols here
7152 because we will also be presented with the concrete instance of
7153 the symbol and elfNN_aarch64_copy_indirect_symbol () will have been
7154 called to copy all relevant data from the generic to the concrete
7157 if (h
->root
.type
== bfd_link_hash_indirect
)
7160 if (h
->root
.type
== bfd_link_hash_warning
)
7161 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
7163 info
= (struct bfd_link_info
*) inf
;
7164 htab
= elf_aarch64_hash_table (info
);
7166 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle it
7167 here if it is defined and referenced in a non-shared object. */
7168 if (h
->type
== STT_GNU_IFUNC
7171 else if (htab
->root
.dynamic_sections_created
&& h
->plt
.refcount
> 0)
7173 /* Make sure this symbol is output as a dynamic symbol.
7174 Undefined weak syms won't yet be marked as dynamic. */
7175 if (h
->dynindx
== -1 && !h
->forced_local
)
7177 if (!bfd_elf_link_record_dynamic_symbol (info
, h
))
7181 if (info
->shared
|| WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h
))
7183 asection
*s
= htab
->root
.splt
;
7185 /* If this is the first .plt entry, make room for the special
7188 s
->size
+= htab
->plt_header_size
;
7190 h
->plt
.offset
= s
->size
;
7192 /* If this symbol is not defined in a regular file, and we are
7193 not generating a shared library, then set the symbol to this
7194 location in the .plt. This is required to make function
7195 pointers compare as equal between the normal executable and
7196 the shared library. */
7197 if (!info
->shared
&& !h
->def_regular
)
7199 h
->root
.u
.def
.section
= s
;
7200 h
->root
.u
.def
.value
= h
->plt
.offset
;
7203 /* Make room for this entry. For now we only create the
7204 small model PLT entries. We later need to find a way
7205 of relaxing into these from the large model PLT entries. */
7206 s
->size
+= PLT_SMALL_ENTRY_SIZE
;
7208 /* We also need to make an entry in the .got.plt section, which
7209 will be placed in the .got section by the linker script. */
7210 htab
->root
.sgotplt
->size
+= GOT_ENTRY_SIZE
;
7212 /* We also need to make an entry in the .rela.plt section. */
7213 htab
->root
.srelplt
->size
+= RELOC_SIZE (htab
);
7215 /* We need to ensure that all GOT entries that serve the PLT
7216 are consecutive with the special GOT slots [0] [1] and
7217 [2]. Any addtional relocations, such as
7218 R_AARCH64_TLSDESC, must be placed after the PLT related
7219 entries. We abuse the reloc_count such that during
7220 sizing we adjust reloc_count to indicate the number of
7221 PLT related reserved entries. In subsequent phases when
7222 filling in the contents of the reloc entries, PLT related
7223 entries are placed by computing their PLT index (0
7224 .. reloc_count). While other none PLT relocs are placed
7225 at the slot indicated by reloc_count and reloc_count is
7228 htab
->root
.srelplt
->reloc_count
++;
7232 h
->plt
.offset
= (bfd_vma
) - 1;
7238 h
->plt
.offset
= (bfd_vma
) - 1;
7242 eh
= (struct elf_aarch64_link_hash_entry
*) h
;
7243 eh
->tlsdesc_got_jump_table_offset
= (bfd_vma
) - 1;
7245 if (h
->got
.refcount
> 0)
7248 unsigned got_type
= elf_aarch64_hash_entry (h
)->got_type
;
7250 h
->got
.offset
= (bfd_vma
) - 1;
7252 dyn
= htab
->root
.dynamic_sections_created
;
7254 /* Make sure this symbol is output as a dynamic symbol.
7255 Undefined weak syms won't yet be marked as dynamic. */
7256 if (dyn
&& h
->dynindx
== -1 && !h
->forced_local
)
7258 if (!bfd_elf_link_record_dynamic_symbol (info
, h
))
7262 if (got_type
== GOT_UNKNOWN
)
7265 else if (got_type
== GOT_NORMAL
)
7267 h
->got
.offset
= htab
->root
.sgot
->size
;
7268 htab
->root
.sgot
->size
+= GOT_ENTRY_SIZE
;
7269 if ((ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
7270 || h
->root
.type
!= bfd_link_hash_undefweak
)
7272 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, 0, h
)))
7274 htab
->root
.srelgot
->size
+= RELOC_SIZE (htab
);
7280 if (got_type
& GOT_TLSDESC_GD
)
7282 eh
->tlsdesc_got_jump_table_offset
=
7283 (htab
->root
.sgotplt
->size
7284 - aarch64_compute_jump_table_size (htab
));
7285 htab
->root
.sgotplt
->size
+= GOT_ENTRY_SIZE
* 2;
7286 h
->got
.offset
= (bfd_vma
) - 2;
7289 if (got_type
& GOT_TLS_GD
)
7291 h
->got
.offset
= htab
->root
.sgot
->size
;
7292 htab
->root
.sgot
->size
+= GOT_ENTRY_SIZE
* 2;
7295 if (got_type
& GOT_TLS_IE
)
7297 h
->got
.offset
= htab
->root
.sgot
->size
;
7298 htab
->root
.sgot
->size
+= GOT_ENTRY_SIZE
;
7301 indx
= h
&& h
->dynindx
!= -1 ? h
->dynindx
: 0;
7302 if ((ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
7303 || h
->root
.type
!= bfd_link_hash_undefweak
)
7306 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, 0, h
)))
7308 if (got_type
& GOT_TLSDESC_GD
)
7310 htab
->root
.srelplt
->size
+= RELOC_SIZE (htab
);
7311 /* Note reloc_count not incremented here! We have
7312 already adjusted reloc_count for this relocation
7315 /* TLSDESC PLT is now needed, but not yet determined. */
7316 htab
->tlsdesc_plt
= (bfd_vma
) - 1;
7319 if (got_type
& GOT_TLS_GD
)
7320 htab
->root
.srelgot
->size
+= RELOC_SIZE (htab
) * 2;
7322 if (got_type
& GOT_TLS_IE
)
7323 htab
->root
.srelgot
->size
+= RELOC_SIZE (htab
);
7329 h
->got
.offset
= (bfd_vma
) - 1;
7332 if (eh
->dyn_relocs
== NULL
)
7335 /* In the shared -Bsymbolic case, discard space allocated for
7336 dynamic pc-relative relocs against symbols which turn out to be
7337 defined in regular objects. For the normal shared case, discard
7338 space for pc-relative relocs that have become local due to symbol
7339 visibility changes. */
7343 /* Relocs that use pc_count are those that appear on a call
7344 insn, or certain REL relocs that can generated via assembly.
7345 We want calls to protected symbols to resolve directly to the
7346 function rather than going via the plt. If people want
7347 function pointer comparisons to work as expected then they
7348 should avoid writing weird assembly. */
7349 if (SYMBOL_CALLS_LOCAL (info
, h
))
7351 struct elf_dyn_relocs
**pp
;
7353 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
;)
7355 p
->count
-= p
->pc_count
;
7364 /* Also discard relocs on undefined weak syms with non-default
7366 if (eh
->dyn_relocs
!= NULL
&& h
->root
.type
== bfd_link_hash_undefweak
)
7368 if (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
)
7369 eh
->dyn_relocs
= NULL
;
7371 /* Make sure undefined weak symbols are output as a dynamic
7373 else if (h
->dynindx
== -1
7375 && !bfd_elf_link_record_dynamic_symbol (info
, h
))
7380 else if (ELIMINATE_COPY_RELOCS
)
7382 /* For the non-shared case, discard space for relocs against
7383 symbols which turn out to need copy relocs or are not
7389 || (htab
->root
.dynamic_sections_created
7390 && (h
->root
.type
== bfd_link_hash_undefweak
7391 || h
->root
.type
== bfd_link_hash_undefined
))))
7393 /* Make sure this symbol is output as a dynamic symbol.
7394 Undefined weak syms won't yet be marked as dynamic. */
7395 if (h
->dynindx
== -1
7397 && !bfd_elf_link_record_dynamic_symbol (info
, h
))
7400 /* If that succeeded, we know we'll be keeping all the
7402 if (h
->dynindx
!= -1)
7406 eh
->dyn_relocs
= NULL
;
7411 /* Finally, allocate space. */
7412 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
7416 sreloc
= elf_section_data (p
->sec
)->sreloc
;
7418 BFD_ASSERT (sreloc
!= NULL
);
7420 sreloc
->size
+= p
->count
* RELOC_SIZE (htab
);
7426 /* Allocate space in .plt, .got and associated reloc sections for
7427 ifunc dynamic relocs. */
7430 elfNN_aarch64_allocate_ifunc_dynrelocs (struct elf_link_hash_entry
*h
,
7433 struct bfd_link_info
*info
;
7434 struct elf_aarch64_link_hash_table
*htab
;
7435 struct elf_aarch64_link_hash_entry
*eh
;
7437 /* An example of a bfd_link_hash_indirect symbol is versioned
7438 symbol. For example: __gxx_personality_v0(bfd_link_hash_indirect)
7439 -> __gxx_personality_v0(bfd_link_hash_defined)
7441 There is no need to process bfd_link_hash_indirect symbols here
7442 because we will also be presented with the concrete instance of
7443 the symbol and elfNN_aarch64_copy_indirect_symbol () will have been
7444 called to copy all relevant data from the generic to the concrete
7447 if (h
->root
.type
== bfd_link_hash_indirect
)
7450 if (h
->root
.type
== bfd_link_hash_warning
)
7451 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
7453 info
= (struct bfd_link_info
*) inf
;
7454 htab
= elf_aarch64_hash_table (info
);
7456 eh
= (struct elf_aarch64_link_hash_entry
*) h
;
7458 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle it
7459 here if it is defined and referenced in a non-shared object. */
7460 if (h
->type
== STT_GNU_IFUNC
7462 return _bfd_elf_allocate_ifunc_dyn_relocs (info
, h
,
7464 htab
->plt_entry_size
,
7465 htab
->plt_header_size
,
7470 /* Allocate space in .plt, .got and associated reloc sections for
7471 local dynamic relocs. */
7474 elfNN_aarch64_allocate_local_dynrelocs (void **slot
, void *inf
)
7476 struct elf_link_hash_entry
*h
7477 = (struct elf_link_hash_entry
*) *slot
;
7479 if (h
->type
!= STT_GNU_IFUNC
7483 || h
->root
.type
!= bfd_link_hash_defined
)
7486 return elfNN_aarch64_allocate_dynrelocs (h
, inf
);
7489 /* Allocate space in .plt, .got and associated reloc sections for
7490 local ifunc dynamic relocs. */
7493 elfNN_aarch64_allocate_local_ifunc_dynrelocs (void **slot
, void *inf
)
7495 struct elf_link_hash_entry
*h
7496 = (struct elf_link_hash_entry
*) *slot
;
7498 if (h
->type
!= STT_GNU_IFUNC
7502 || h
->root
.type
!= bfd_link_hash_defined
)
7505 return elfNN_aarch64_allocate_ifunc_dynrelocs (h
, inf
);
7508 /* This is the most important function of all . Innocuosly named
7511 elfNN_aarch64_size_dynamic_sections (bfd
*output_bfd ATTRIBUTE_UNUSED
,
7512 struct bfd_link_info
*info
)
7514 struct elf_aarch64_link_hash_table
*htab
;
7520 htab
= elf_aarch64_hash_table ((info
));
7521 dynobj
= htab
->root
.dynobj
;
7523 BFD_ASSERT (dynobj
!= NULL
);
7525 if (htab
->root
.dynamic_sections_created
)
7527 if (info
->executable
)
7529 s
= bfd_get_linker_section (dynobj
, ".interp");
7532 s
->size
= sizeof ELF_DYNAMIC_INTERPRETER
;
7533 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
7537 /* Set up .got offsets for local syms, and space for local dynamic
7539 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
7541 struct elf_aarch64_local_symbol
*locals
= NULL
;
7542 Elf_Internal_Shdr
*symtab_hdr
;
7546 if (!is_aarch64_elf (ibfd
))
7549 for (s
= ibfd
->sections
; s
!= NULL
; s
= s
->next
)
7551 struct elf_dyn_relocs
*p
;
7553 for (p
= (struct elf_dyn_relocs
*)
7554 (elf_section_data (s
)->local_dynrel
); p
!= NULL
; p
= p
->next
)
7556 if (!bfd_is_abs_section (p
->sec
)
7557 && bfd_is_abs_section (p
->sec
->output_section
))
7559 /* Input section has been discarded, either because
7560 it is a copy of a linkonce section or due to
7561 linker script /DISCARD/, so we'll be discarding
7564 else if (p
->count
!= 0)
7566 srel
= elf_section_data (p
->sec
)->sreloc
;
7567 srel
->size
+= p
->count
* RELOC_SIZE (htab
);
7568 if ((p
->sec
->output_section
->flags
& SEC_READONLY
) != 0)
7569 info
->flags
|= DF_TEXTREL
;
7574 locals
= elf_aarch64_locals (ibfd
);
7578 symtab_hdr
= &elf_symtab_hdr (ibfd
);
7579 srel
= htab
->root
.srelgot
;
7580 for (i
= 0; i
< symtab_hdr
->sh_info
; i
++)
7582 locals
[i
].got_offset
= (bfd_vma
) - 1;
7583 locals
[i
].tlsdesc_got_jump_table_offset
= (bfd_vma
) - 1;
7584 if (locals
[i
].got_refcount
> 0)
7586 unsigned got_type
= locals
[i
].got_type
;
7587 if (got_type
& GOT_TLSDESC_GD
)
7589 locals
[i
].tlsdesc_got_jump_table_offset
=
7590 (htab
->root
.sgotplt
->size
7591 - aarch64_compute_jump_table_size (htab
));
7592 htab
->root
.sgotplt
->size
+= GOT_ENTRY_SIZE
* 2;
7593 locals
[i
].got_offset
= (bfd_vma
) - 2;
7596 if (got_type
& GOT_TLS_GD
)
7598 locals
[i
].got_offset
= htab
->root
.sgot
->size
;
7599 htab
->root
.sgot
->size
+= GOT_ENTRY_SIZE
* 2;
7602 if (got_type
& GOT_TLS_IE
7603 || got_type
& GOT_NORMAL
)
7605 locals
[i
].got_offset
= htab
->root
.sgot
->size
;
7606 htab
->root
.sgot
->size
+= GOT_ENTRY_SIZE
;
7609 if (got_type
== GOT_UNKNOWN
)
7615 if (got_type
& GOT_TLSDESC_GD
)
7617 htab
->root
.srelplt
->size
+= RELOC_SIZE (htab
);
7618 /* Note RELOC_COUNT not incremented here! */
7619 htab
->tlsdesc_plt
= (bfd_vma
) - 1;
7622 if (got_type
& GOT_TLS_GD
)
7623 htab
->root
.srelgot
->size
+= RELOC_SIZE (htab
) * 2;
7625 if (got_type
& GOT_TLS_IE
7626 || got_type
& GOT_NORMAL
)
7627 htab
->root
.srelgot
->size
+= RELOC_SIZE (htab
);
7632 locals
[i
].got_refcount
= (bfd_vma
) - 1;
7638 /* Allocate global sym .plt and .got entries, and space for global
7639 sym dynamic relocs. */
7640 elf_link_hash_traverse (&htab
->root
, elfNN_aarch64_allocate_dynrelocs
,
7643 /* Allocate global ifunc sym .plt and .got entries, and space for global
7644 ifunc sym dynamic relocs. */
7645 elf_link_hash_traverse (&htab
->root
, elfNN_aarch64_allocate_ifunc_dynrelocs
,
7648 /* Allocate .plt and .got entries, and space for local symbols. */
7649 htab_traverse (htab
->loc_hash_table
,
7650 elfNN_aarch64_allocate_local_dynrelocs
,
7653 /* Allocate .plt and .got entries, and space for local ifunc symbols. */
7654 htab_traverse (htab
->loc_hash_table
,
7655 elfNN_aarch64_allocate_local_ifunc_dynrelocs
,
7658 /* For every jump slot reserved in the sgotplt, reloc_count is
7659 incremented. However, when we reserve space for TLS descriptors,
7660 it's not incremented, so in order to compute the space reserved
7661 for them, it suffices to multiply the reloc count by the jump
7664 if (htab
->root
.srelplt
)
7665 htab
->sgotplt_jump_table_size
= aarch64_compute_jump_table_size (htab
);
7667 if (htab
->tlsdesc_plt
)
7669 if (htab
->root
.splt
->size
== 0)
7670 htab
->root
.splt
->size
+= PLT_ENTRY_SIZE
;
7672 htab
->tlsdesc_plt
= htab
->root
.splt
->size
;
7673 htab
->root
.splt
->size
+= PLT_TLSDESC_ENTRY_SIZE
;
7675 /* If we're not using lazy TLS relocations, don't generate the
7676 GOT entry required. */
7677 if (!(info
->flags
& DF_BIND_NOW
))
7679 htab
->dt_tlsdesc_got
= htab
->root
.sgot
->size
;
7680 htab
->root
.sgot
->size
+= GOT_ENTRY_SIZE
;
7684 /* Init mapping symbols information to use later to distingush between
7685 code and data while scanning for errata. */
7686 if (htab
->fix_erratum_835769
|| htab
->fix_erratum_843419
)
7687 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
7689 if (!is_aarch64_elf (ibfd
))
7691 bfd_elfNN_aarch64_init_maps (ibfd
);
7694 /* We now have determined the sizes of the various dynamic sections.
7695 Allocate memory for them. */
7697 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
7699 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
7702 if (s
== htab
->root
.splt
7703 || s
== htab
->root
.sgot
7704 || s
== htab
->root
.sgotplt
7705 || s
== htab
->root
.iplt
7706 || s
== htab
->root
.igotplt
|| s
== htab
->sdynbss
)
7708 /* Strip this section if we don't need it; see the
7711 else if (CONST_STRNEQ (bfd_get_section_name (dynobj
, s
), ".rela"))
7713 if (s
->size
!= 0 && s
!= htab
->root
.srelplt
)
7716 /* We use the reloc_count field as a counter if we need
7717 to copy relocs into the output file. */
7718 if (s
!= htab
->root
.srelplt
)
7723 /* It's not one of our sections, so don't allocate space. */
7729 /* If we don't need this section, strip it from the
7730 output file. This is mostly to handle .rela.bss and
7731 .rela.plt. We must create both sections in
7732 create_dynamic_sections, because they must be created
7733 before the linker maps input sections to output
7734 sections. The linker does that before
7735 adjust_dynamic_symbol is called, and it is that
7736 function which decides whether anything needs to go
7737 into these sections. */
7739 s
->flags
|= SEC_EXCLUDE
;
7743 if ((s
->flags
& SEC_HAS_CONTENTS
) == 0)
7746 /* Allocate memory for the section contents. We use bfd_zalloc
7747 here in case unused entries are not reclaimed before the
7748 section's contents are written out. This should not happen,
7749 but this way if it does, we get a R_AARCH64_NONE reloc instead
7751 s
->contents
= (bfd_byte
*) bfd_zalloc (dynobj
, s
->size
);
7752 if (s
->contents
== NULL
)
7756 if (htab
->root
.dynamic_sections_created
)
7758 /* Add some entries to the .dynamic section. We fill in the
7759 values later, in elfNN_aarch64_finish_dynamic_sections, but we
7760 must add the entries now so that we get the correct size for
7761 the .dynamic section. The DT_DEBUG entry is filled in by the
7762 dynamic linker and used by the debugger. */
7763 #define add_dynamic_entry(TAG, VAL) \
7764 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
7766 if (info
->executable
)
7768 if (!add_dynamic_entry (DT_DEBUG
, 0))
7772 if (htab
->root
.splt
->size
!= 0)
7774 if (!add_dynamic_entry (DT_PLTGOT
, 0)
7775 || !add_dynamic_entry (DT_PLTRELSZ
, 0)
7776 || !add_dynamic_entry (DT_PLTREL
, DT_RELA
)
7777 || !add_dynamic_entry (DT_JMPREL
, 0))
7780 if (htab
->tlsdesc_plt
7781 && (!add_dynamic_entry (DT_TLSDESC_PLT
, 0)
7782 || !add_dynamic_entry (DT_TLSDESC_GOT
, 0)))
7788 if (!add_dynamic_entry (DT_RELA
, 0)
7789 || !add_dynamic_entry (DT_RELASZ
, 0)
7790 || !add_dynamic_entry (DT_RELAENT
, RELOC_SIZE (htab
)))
7793 /* If any dynamic relocs apply to a read-only section,
7794 then we need a DT_TEXTREL entry. */
7795 if ((info
->flags
& DF_TEXTREL
) != 0)
7797 if (!add_dynamic_entry (DT_TEXTREL
, 0))
7802 #undef add_dynamic_entry
7808 elf_aarch64_update_plt_entry (bfd
*output_bfd
,
7809 bfd_reloc_code_real_type r_type
,
7810 bfd_byte
*plt_entry
, bfd_vma value
)
7812 reloc_howto_type
*howto
= elfNN_aarch64_howto_from_bfd_reloc (r_type
);
7814 _bfd_aarch64_elf_put_addend (output_bfd
, plt_entry
, r_type
, howto
, value
);
7818 elfNN_aarch64_create_small_pltn_entry (struct elf_link_hash_entry
*h
,
7819 struct elf_aarch64_link_hash_table
7820 *htab
, bfd
*output_bfd
,
7821 struct bfd_link_info
*info
)
7823 bfd_byte
*plt_entry
;
7826 bfd_vma gotplt_entry_address
;
7827 bfd_vma plt_entry_address
;
7828 Elf_Internal_Rela rela
;
7830 asection
*plt
, *gotplt
, *relplt
;
7832 /* When building a static executable, use .iplt, .igot.plt and
7833 .rela.iplt sections for STT_GNU_IFUNC symbols. */
7834 if (htab
->root
.splt
!= NULL
)
7836 plt
= htab
->root
.splt
;
7837 gotplt
= htab
->root
.sgotplt
;
7838 relplt
= htab
->root
.srelplt
;
7842 plt
= htab
->root
.iplt
;
7843 gotplt
= htab
->root
.igotplt
;
7844 relplt
= htab
->root
.irelplt
;
7847 /* Get the index in the procedure linkage table which
7848 corresponds to this symbol. This is the index of this symbol
7849 in all the symbols for which we are making plt entries. The
7850 first entry in the procedure linkage table is reserved.
7852 Get the offset into the .got table of the entry that
7853 corresponds to this function. Each .got entry is GOT_ENTRY_SIZE
7854 bytes. The first three are reserved for the dynamic linker.
7856 For static executables, we don't reserve anything. */
7858 if (plt
== htab
->root
.splt
)
7860 plt_index
= (h
->plt
.offset
- htab
->plt_header_size
) / htab
->plt_entry_size
;
7861 got_offset
= (plt_index
+ 3) * GOT_ENTRY_SIZE
;
7865 plt_index
= h
->plt
.offset
/ htab
->plt_entry_size
;
7866 got_offset
= plt_index
* GOT_ENTRY_SIZE
;
7869 plt_entry
= plt
->contents
+ h
->plt
.offset
;
7870 plt_entry_address
= plt
->output_section
->vma
7871 + plt
->output_offset
+ h
->plt
.offset
;
7872 gotplt_entry_address
= gotplt
->output_section
->vma
+
7873 gotplt
->output_offset
+ got_offset
;
7875 /* Copy in the boiler-plate for the PLTn entry. */
7876 memcpy (plt_entry
, elfNN_aarch64_small_plt_entry
, PLT_SMALL_ENTRY_SIZE
);
7878 /* Fill in the top 21 bits for this: ADRP x16, PLT_GOT + n * 8.
7879 ADRP: ((PG(S+A)-PG(P)) >> 12) & 0x1fffff */
7880 elf_aarch64_update_plt_entry (output_bfd
, BFD_RELOC_AARCH64_ADR_HI21_PCREL
,
7882 PG (gotplt_entry_address
) -
7883 PG (plt_entry_address
));
7885 /* Fill in the lo12 bits for the load from the pltgot. */
7886 elf_aarch64_update_plt_entry (output_bfd
, BFD_RELOC_AARCH64_LDSTNN_LO12
,
7888 PG_OFFSET (gotplt_entry_address
));
7890 /* Fill in the lo12 bits for the add from the pltgot entry. */
7891 elf_aarch64_update_plt_entry (output_bfd
, BFD_RELOC_AARCH64_ADD_LO12
,
7893 PG_OFFSET (gotplt_entry_address
));
7895 /* All the GOTPLT Entries are essentially initialized to PLT0. */
7896 bfd_put_NN (output_bfd
,
7897 plt
->output_section
->vma
+ plt
->output_offset
,
7898 gotplt
->contents
+ got_offset
);
7900 rela
.r_offset
= gotplt_entry_address
;
7902 if (h
->dynindx
== -1
7903 || ((info
->executable
7904 || ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
)
7906 && h
->type
== STT_GNU_IFUNC
))
7908 /* If an STT_GNU_IFUNC symbol is locally defined, generate
7909 R_AARCH64_IRELATIVE instead of R_AARCH64_JUMP_SLOT. */
7910 rela
.r_info
= ELFNN_R_INFO (0, AARCH64_R (IRELATIVE
));
7911 rela
.r_addend
= (h
->root
.u
.def
.value
7912 + h
->root
.u
.def
.section
->output_section
->vma
7913 + h
->root
.u
.def
.section
->output_offset
);
7917 /* Fill in the entry in the .rela.plt section. */
7918 rela
.r_info
= ELFNN_R_INFO (h
->dynindx
, AARCH64_R (JUMP_SLOT
));
7922 /* Compute the relocation entry to used based on PLT index and do
7923 not adjust reloc_count. The reloc_count has already been adjusted
7924 to account for this entry. */
7925 loc
= relplt
->contents
+ plt_index
* RELOC_SIZE (htab
);
7926 bfd_elfNN_swap_reloca_out (output_bfd
, &rela
, loc
);
7929 /* Size sections even though they're not dynamic. We use it to setup
7930 _TLS_MODULE_BASE_, if needed. */
7933 elfNN_aarch64_always_size_sections (bfd
*output_bfd
,
7934 struct bfd_link_info
*info
)
7938 if (info
->relocatable
)
7941 tls_sec
= elf_hash_table (info
)->tls_sec
;
7945 struct elf_link_hash_entry
*tlsbase
;
7947 tlsbase
= elf_link_hash_lookup (elf_hash_table (info
),
7948 "_TLS_MODULE_BASE_", TRUE
, TRUE
, FALSE
);
7952 struct bfd_link_hash_entry
*h
= NULL
;
7953 const struct elf_backend_data
*bed
=
7954 get_elf_backend_data (output_bfd
);
7956 if (!(_bfd_generic_link_add_one_symbol
7957 (info
, output_bfd
, "_TLS_MODULE_BASE_", BSF_LOCAL
,
7958 tls_sec
, 0, NULL
, FALSE
, bed
->collect
, &h
)))
7961 tlsbase
->type
= STT_TLS
;
7962 tlsbase
= (struct elf_link_hash_entry
*) h
;
7963 tlsbase
->def_regular
= 1;
7964 tlsbase
->other
= STV_HIDDEN
;
7965 (*bed
->elf_backend_hide_symbol
) (info
, tlsbase
, TRUE
);
7972 /* Finish up dynamic symbol handling. We set the contents of various
7973 dynamic sections here. */
7975 elfNN_aarch64_finish_dynamic_symbol (bfd
*output_bfd
,
7976 struct bfd_link_info
*info
,
7977 struct elf_link_hash_entry
*h
,
7978 Elf_Internal_Sym
*sym
)
7980 struct elf_aarch64_link_hash_table
*htab
;
7981 htab
= elf_aarch64_hash_table (info
);
7983 if (h
->plt
.offset
!= (bfd_vma
) - 1)
7985 asection
*plt
, *gotplt
, *relplt
;
7987 /* This symbol has an entry in the procedure linkage table. Set
7990 /* When building a static executable, use .iplt, .igot.plt and
7991 .rela.iplt sections for STT_GNU_IFUNC symbols. */
7992 if (htab
->root
.splt
!= NULL
)
7994 plt
= htab
->root
.splt
;
7995 gotplt
= htab
->root
.sgotplt
;
7996 relplt
= htab
->root
.srelplt
;
8000 plt
= htab
->root
.iplt
;
8001 gotplt
= htab
->root
.igotplt
;
8002 relplt
= htab
->root
.irelplt
;
8005 /* This symbol has an entry in the procedure linkage table. Set
8007 if ((h
->dynindx
== -1
8008 && !((h
->forced_local
|| info
->executable
)
8010 && h
->type
== STT_GNU_IFUNC
))
8016 elfNN_aarch64_create_small_pltn_entry (h
, htab
, output_bfd
, info
);
8017 if (!h
->def_regular
)
8019 /* Mark the symbol as undefined, rather than as defined in
8020 the .plt section. */
8021 sym
->st_shndx
= SHN_UNDEF
;
8022 /* If the symbol is weak we need to clear the value.
8023 Otherwise, the PLT entry would provide a definition for
8024 the symbol even if the symbol wasn't defined anywhere,
8025 and so the symbol would never be NULL. Leave the value if
8026 there were any relocations where pointer equality matters
8027 (this is a clue for the dynamic linker, to make function
8028 pointer comparisons work between an application and shared
8030 if (!h
->ref_regular_nonweak
|| !h
->pointer_equality_needed
)
8035 if (h
->got
.offset
!= (bfd_vma
) - 1
8036 && elf_aarch64_hash_entry (h
)->got_type
== GOT_NORMAL
)
8038 Elf_Internal_Rela rela
;
8041 /* This symbol has an entry in the global offset table. Set it
8043 if (htab
->root
.sgot
== NULL
|| htab
->root
.srelgot
== NULL
)
8046 rela
.r_offset
= (htab
->root
.sgot
->output_section
->vma
8047 + htab
->root
.sgot
->output_offset
8048 + (h
->got
.offset
& ~(bfd_vma
) 1));
8051 && h
->type
== STT_GNU_IFUNC
)
8055 /* Generate R_AARCH64_GLOB_DAT. */
8062 if (!h
->pointer_equality_needed
)
8065 /* For non-shared object, we can't use .got.plt, which
8066 contains the real function address if we need pointer
8067 equality. We load the GOT entry with the PLT entry. */
8068 plt
= htab
->root
.splt
? htab
->root
.splt
: htab
->root
.iplt
;
8069 bfd_put_NN (output_bfd
, (plt
->output_section
->vma
8070 + plt
->output_offset
8072 htab
->root
.sgot
->contents
8073 + (h
->got
.offset
& ~(bfd_vma
) 1));
8077 else if (info
->shared
&& SYMBOL_REFERENCES_LOCAL (info
, h
))
8079 if (!h
->def_regular
)
8082 BFD_ASSERT ((h
->got
.offset
& 1) != 0);
8083 rela
.r_info
= ELFNN_R_INFO (0, AARCH64_R (RELATIVE
));
8084 rela
.r_addend
= (h
->root
.u
.def
.value
8085 + h
->root
.u
.def
.section
->output_section
->vma
8086 + h
->root
.u
.def
.section
->output_offset
);
8091 BFD_ASSERT ((h
->got
.offset
& 1) == 0);
8092 bfd_put_NN (output_bfd
, (bfd_vma
) 0,
8093 htab
->root
.sgot
->contents
+ h
->got
.offset
);
8094 rela
.r_info
= ELFNN_R_INFO (h
->dynindx
, AARCH64_R (GLOB_DAT
));
8098 loc
= htab
->root
.srelgot
->contents
;
8099 loc
+= htab
->root
.srelgot
->reloc_count
++ * RELOC_SIZE (htab
);
8100 bfd_elfNN_swap_reloca_out (output_bfd
, &rela
, loc
);
8105 Elf_Internal_Rela rela
;
8108 /* This symbol needs a copy reloc. Set it up. */
8110 if (h
->dynindx
== -1
8111 || (h
->root
.type
!= bfd_link_hash_defined
8112 && h
->root
.type
!= bfd_link_hash_defweak
)
8113 || htab
->srelbss
== NULL
)
8116 rela
.r_offset
= (h
->root
.u
.def
.value
8117 + h
->root
.u
.def
.section
->output_section
->vma
8118 + h
->root
.u
.def
.section
->output_offset
);
8119 rela
.r_info
= ELFNN_R_INFO (h
->dynindx
, AARCH64_R (COPY
));
8121 loc
= htab
->srelbss
->contents
;
8122 loc
+= htab
->srelbss
->reloc_count
++ * RELOC_SIZE (htab
);
8123 bfd_elfNN_swap_reloca_out (output_bfd
, &rela
, loc
);
8126 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. SYM may
8127 be NULL for local symbols. */
8129 && (h
== elf_hash_table (info
)->hdynamic
8130 || h
== elf_hash_table (info
)->hgot
))
8131 sym
->st_shndx
= SHN_ABS
;
8136 /* Finish up local dynamic symbol handling. We set the contents of
8137 various dynamic sections here. */
8140 elfNN_aarch64_finish_local_dynamic_symbol (void **slot
, void *inf
)
8142 struct elf_link_hash_entry
*h
8143 = (struct elf_link_hash_entry
*) *slot
;
8144 struct bfd_link_info
*info
8145 = (struct bfd_link_info
*) inf
;
8147 return elfNN_aarch64_finish_dynamic_symbol (info
->output_bfd
,
8152 elfNN_aarch64_init_small_plt0_entry (bfd
*output_bfd ATTRIBUTE_UNUSED
,
8153 struct elf_aarch64_link_hash_table
8156 /* Fill in PLT0. Fixme:RR Note this doesn't distinguish between
8157 small and large plts and at the minute just generates
8160 /* PLT0 of the small PLT looks like this in ELF64 -
8161 stp x16, x30, [sp, #-16]! // Save the reloc and lr on stack.
8162 adrp x16, PLT_GOT + 16 // Get the page base of the GOTPLT
8163 ldr x17, [x16, #:lo12:PLT_GOT+16] // Load the address of the
8165 add x16, x16, #:lo12:PLT_GOT+16 // Load the lo12 bits of the
8166 // GOTPLT entry for this.
8168 PLT0 will be slightly different in ELF32 due to different got entry
8171 bfd_vma plt_got_2nd_ent
; /* Address of GOT[2]. */
8175 memcpy (htab
->root
.splt
->contents
, elfNN_aarch64_small_plt0_entry
,
8177 elf_section_data (htab
->root
.splt
->output_section
)->this_hdr
.sh_entsize
=
8180 plt_got_2nd_ent
= (htab
->root
.sgotplt
->output_section
->vma
8181 + htab
->root
.sgotplt
->output_offset
8182 + GOT_ENTRY_SIZE
* 2);
8184 plt_base
= htab
->root
.splt
->output_section
->vma
+
8185 htab
->root
.splt
->output_offset
;
8187 /* Fill in the top 21 bits for this: ADRP x16, PLT_GOT + n * 8.
8188 ADRP: ((PG(S+A)-PG(P)) >> 12) & 0x1fffff */
8189 elf_aarch64_update_plt_entry (output_bfd
, BFD_RELOC_AARCH64_ADR_HI21_PCREL
,
8190 htab
->root
.splt
->contents
+ 4,
8191 PG (plt_got_2nd_ent
) - PG (plt_base
+ 4));
8193 elf_aarch64_update_plt_entry (output_bfd
, BFD_RELOC_AARCH64_LDSTNN_LO12
,
8194 htab
->root
.splt
->contents
+ 8,
8195 PG_OFFSET (plt_got_2nd_ent
));
8197 elf_aarch64_update_plt_entry (output_bfd
, BFD_RELOC_AARCH64_ADD_LO12
,
8198 htab
->root
.splt
->contents
+ 12,
8199 PG_OFFSET (plt_got_2nd_ent
));
8203 elfNN_aarch64_finish_dynamic_sections (bfd
*output_bfd
,
8204 struct bfd_link_info
*info
)
8206 struct elf_aarch64_link_hash_table
*htab
;
8210 htab
= elf_aarch64_hash_table (info
);
8211 dynobj
= htab
->root
.dynobj
;
8212 sdyn
= bfd_get_linker_section (dynobj
, ".dynamic");
8214 if (htab
->root
.dynamic_sections_created
)
8216 ElfNN_External_Dyn
*dyncon
, *dynconend
;
8218 if (sdyn
== NULL
|| htab
->root
.sgot
== NULL
)
8221 dyncon
= (ElfNN_External_Dyn
*) sdyn
->contents
;
8222 dynconend
= (ElfNN_External_Dyn
*) (sdyn
->contents
+ sdyn
->size
);
8223 for (; dyncon
< dynconend
; dyncon
++)
8225 Elf_Internal_Dyn dyn
;
8228 bfd_elfNN_swap_dyn_in (dynobj
, dyncon
, &dyn
);
8236 s
= htab
->root
.sgotplt
;
8237 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
8241 dyn
.d_un
.d_ptr
= htab
->root
.srelplt
->output_section
->vma
;
8245 s
= htab
->root
.srelplt
;
8246 dyn
.d_un
.d_val
= s
->size
;
8250 /* The procedure linkage table relocs (DT_JMPREL) should
8251 not be included in the overall relocs (DT_RELA).
8252 Therefore, we override the DT_RELASZ entry here to
8253 make it not include the JMPREL relocs. Since the
8254 linker script arranges for .rela.plt to follow all
8255 other relocation sections, we don't have to worry
8256 about changing the DT_RELA entry. */
8257 if (htab
->root
.srelplt
!= NULL
)
8259 s
= htab
->root
.srelplt
;
8260 dyn
.d_un
.d_val
-= s
->size
;
8264 case DT_TLSDESC_PLT
:
8265 s
= htab
->root
.splt
;
8266 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
8267 + htab
->tlsdesc_plt
;
8270 case DT_TLSDESC_GOT
:
8271 s
= htab
->root
.sgot
;
8272 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
8273 + htab
->dt_tlsdesc_got
;
8277 bfd_elfNN_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
8282 /* Fill in the special first entry in the procedure linkage table. */
8283 if (htab
->root
.splt
&& htab
->root
.splt
->size
> 0)
8285 elfNN_aarch64_init_small_plt0_entry (output_bfd
, htab
);
8287 elf_section_data (htab
->root
.splt
->output_section
)->
8288 this_hdr
.sh_entsize
= htab
->plt_entry_size
;
8291 if (htab
->tlsdesc_plt
)
8293 bfd_put_NN (output_bfd
, (bfd_vma
) 0,
8294 htab
->root
.sgot
->contents
+ htab
->dt_tlsdesc_got
);
8296 memcpy (htab
->root
.splt
->contents
+ htab
->tlsdesc_plt
,
8297 elfNN_aarch64_tlsdesc_small_plt_entry
,
8298 sizeof (elfNN_aarch64_tlsdesc_small_plt_entry
));
8301 bfd_vma adrp1_addr
=
8302 htab
->root
.splt
->output_section
->vma
8303 + htab
->root
.splt
->output_offset
+ htab
->tlsdesc_plt
+ 4;
8305 bfd_vma adrp2_addr
= adrp1_addr
+ 4;
8308 htab
->root
.sgot
->output_section
->vma
8309 + htab
->root
.sgot
->output_offset
;
8311 bfd_vma pltgot_addr
=
8312 htab
->root
.sgotplt
->output_section
->vma
8313 + htab
->root
.sgotplt
->output_offset
;
8315 bfd_vma dt_tlsdesc_got
= got_addr
+ htab
->dt_tlsdesc_got
;
8317 bfd_byte
*plt_entry
=
8318 htab
->root
.splt
->contents
+ htab
->tlsdesc_plt
;
8320 /* adrp x2, DT_TLSDESC_GOT */
8321 elf_aarch64_update_plt_entry (output_bfd
,
8322 BFD_RELOC_AARCH64_ADR_HI21_PCREL
,
8324 (PG (dt_tlsdesc_got
)
8325 - PG (adrp1_addr
)));
8328 elf_aarch64_update_plt_entry (output_bfd
,
8329 BFD_RELOC_AARCH64_ADR_HI21_PCREL
,
8332 - PG (adrp2_addr
)));
8334 /* ldr x2, [x2, #0] */
8335 elf_aarch64_update_plt_entry (output_bfd
,
8336 BFD_RELOC_AARCH64_LDSTNN_LO12
,
8338 PG_OFFSET (dt_tlsdesc_got
));
8341 elf_aarch64_update_plt_entry (output_bfd
,
8342 BFD_RELOC_AARCH64_ADD_LO12
,
8344 PG_OFFSET (pltgot_addr
));
8349 if (htab
->root
.sgotplt
)
8351 if (bfd_is_abs_section (htab
->root
.sgotplt
->output_section
))
8353 (*_bfd_error_handler
)
8354 (_("discarded output section: `%A'"), htab
->root
.sgotplt
);
8358 /* Fill in the first three entries in the global offset table. */
8359 if (htab
->root
.sgotplt
->size
> 0)
8361 bfd_put_NN (output_bfd
, (bfd_vma
) 0, htab
->root
.sgotplt
->contents
);
8363 /* Write GOT[1] and GOT[2], needed for the dynamic linker. */
8364 bfd_put_NN (output_bfd
,
8366 htab
->root
.sgotplt
->contents
+ GOT_ENTRY_SIZE
);
8367 bfd_put_NN (output_bfd
,
8369 htab
->root
.sgotplt
->contents
+ GOT_ENTRY_SIZE
* 2);
8372 if (htab
->root
.sgot
)
8374 if (htab
->root
.sgot
->size
> 0)
8377 sdyn
? sdyn
->output_section
->vma
+ sdyn
->output_offset
: 0;
8378 bfd_put_NN (output_bfd
, addr
, htab
->root
.sgot
->contents
);
8382 elf_section_data (htab
->root
.sgotplt
->output_section
)->
8383 this_hdr
.sh_entsize
= GOT_ENTRY_SIZE
;
8386 if (htab
->root
.sgot
&& htab
->root
.sgot
->size
> 0)
8387 elf_section_data (htab
->root
.sgot
->output_section
)->this_hdr
.sh_entsize
8390 /* Fill PLT and GOT entries for local STT_GNU_IFUNC symbols. */
8391 htab_traverse (htab
->loc_hash_table
,
8392 elfNN_aarch64_finish_local_dynamic_symbol
,
8398 /* Return address for Ith PLT stub in section PLT, for relocation REL
8399 or (bfd_vma) -1 if it should not be included. */
8402 elfNN_aarch64_plt_sym_val (bfd_vma i
, const asection
*plt
,
8403 const arelent
*rel ATTRIBUTE_UNUSED
)
8405 return plt
->vma
+ PLT_ENTRY_SIZE
+ i
* PLT_SMALL_ENTRY_SIZE
;
8409 /* We use this so we can override certain functions
8410 (though currently we don't). */
8412 const struct elf_size_info elfNN_aarch64_size_info
=
8414 sizeof (ElfNN_External_Ehdr
),
8415 sizeof (ElfNN_External_Phdr
),
8416 sizeof (ElfNN_External_Shdr
),
8417 sizeof (ElfNN_External_Rel
),
8418 sizeof (ElfNN_External_Rela
),
8419 sizeof (ElfNN_External_Sym
),
8420 sizeof (ElfNN_External_Dyn
),
8421 sizeof (Elf_External_Note
),
8422 4, /* Hash table entry size. */
8423 1, /* Internal relocs per external relocs. */
8424 ARCH_SIZE
, /* Arch size. */
8425 LOG_FILE_ALIGN
, /* Log_file_align. */
8426 ELFCLASSNN
, EV_CURRENT
,
8427 bfd_elfNN_write_out_phdrs
,
8428 bfd_elfNN_write_shdrs_and_ehdr
,
8429 bfd_elfNN_checksum_contents
,
8430 bfd_elfNN_write_relocs
,
8431 bfd_elfNN_swap_symbol_in
,
8432 bfd_elfNN_swap_symbol_out
,
8433 bfd_elfNN_slurp_reloc_table
,
8434 bfd_elfNN_slurp_symbol_table
,
8435 bfd_elfNN_swap_dyn_in
,
8436 bfd_elfNN_swap_dyn_out
,
8437 bfd_elfNN_swap_reloc_in
,
8438 bfd_elfNN_swap_reloc_out
,
8439 bfd_elfNN_swap_reloca_in
,
8440 bfd_elfNN_swap_reloca_out
8443 #define ELF_ARCH bfd_arch_aarch64
8444 #define ELF_MACHINE_CODE EM_AARCH64
8445 #define ELF_MAXPAGESIZE 0x10000
8446 #define ELF_MINPAGESIZE 0x1000
8447 #define ELF_COMMONPAGESIZE 0x1000
8449 #define bfd_elfNN_close_and_cleanup \
8450 elfNN_aarch64_close_and_cleanup
8452 #define bfd_elfNN_bfd_free_cached_info \
8453 elfNN_aarch64_bfd_free_cached_info
8455 #define bfd_elfNN_bfd_is_target_special_symbol \
8456 elfNN_aarch64_is_target_special_symbol
8458 #define bfd_elfNN_bfd_link_hash_table_create \
8459 elfNN_aarch64_link_hash_table_create
8461 #define bfd_elfNN_bfd_merge_private_bfd_data \
8462 elfNN_aarch64_merge_private_bfd_data
8464 #define bfd_elfNN_bfd_print_private_bfd_data \
8465 elfNN_aarch64_print_private_bfd_data
8467 #define bfd_elfNN_bfd_reloc_type_lookup \
8468 elfNN_aarch64_reloc_type_lookup
8470 #define bfd_elfNN_bfd_reloc_name_lookup \
8471 elfNN_aarch64_reloc_name_lookup
8473 #define bfd_elfNN_bfd_set_private_flags \
8474 elfNN_aarch64_set_private_flags
8476 #define bfd_elfNN_find_inliner_info \
8477 elfNN_aarch64_find_inliner_info
8479 #define bfd_elfNN_find_nearest_line \
8480 elfNN_aarch64_find_nearest_line
8482 #define bfd_elfNN_mkobject \
8483 elfNN_aarch64_mkobject
8485 #define bfd_elfNN_new_section_hook \
8486 elfNN_aarch64_new_section_hook
8488 #define elf_backend_adjust_dynamic_symbol \
8489 elfNN_aarch64_adjust_dynamic_symbol
8491 #define elf_backend_always_size_sections \
8492 elfNN_aarch64_always_size_sections
8494 #define elf_backend_check_relocs \
8495 elfNN_aarch64_check_relocs
8497 #define elf_backend_copy_indirect_symbol \
8498 elfNN_aarch64_copy_indirect_symbol
8500 /* Create .dynbss, and .rela.bss sections in DYNOBJ, and set up shortcuts
8501 to them in our hash. */
8502 #define elf_backend_create_dynamic_sections \
8503 elfNN_aarch64_create_dynamic_sections
8505 #define elf_backend_init_index_section \
8506 _bfd_elf_init_2_index_sections
8508 #define elf_backend_finish_dynamic_sections \
8509 elfNN_aarch64_finish_dynamic_sections
8511 #define elf_backend_finish_dynamic_symbol \
8512 elfNN_aarch64_finish_dynamic_symbol
8514 #define elf_backend_gc_sweep_hook \
8515 elfNN_aarch64_gc_sweep_hook
8517 #define elf_backend_object_p \
8518 elfNN_aarch64_object_p
8520 #define elf_backend_output_arch_local_syms \
8521 elfNN_aarch64_output_arch_local_syms
8523 #define elf_backend_plt_sym_val \
8524 elfNN_aarch64_plt_sym_val
8526 #define elf_backend_post_process_headers \
8527 elfNN_aarch64_post_process_headers
8529 #define elf_backend_relocate_section \
8530 elfNN_aarch64_relocate_section
8532 #define elf_backend_reloc_type_class \
8533 elfNN_aarch64_reloc_type_class
8535 #define elf_backend_section_from_shdr \
8536 elfNN_aarch64_section_from_shdr
8538 #define elf_backend_size_dynamic_sections \
8539 elfNN_aarch64_size_dynamic_sections
8541 #define elf_backend_size_info \
8542 elfNN_aarch64_size_info
8544 #define elf_backend_write_section \
8545 elfNN_aarch64_write_section
8547 #define elf_backend_can_refcount 1
8548 #define elf_backend_can_gc_sections 1
8549 #define elf_backend_plt_readonly 1
8550 #define elf_backend_want_got_plt 1
8551 #define elf_backend_want_plt_sym 0
8552 #define elf_backend_may_use_rel_p 0
8553 #define elf_backend_may_use_rela_p 1
8554 #define elf_backend_default_use_rela_p 1
8555 #define elf_backend_rela_normal 1
8556 #define elf_backend_got_header_size (GOT_ENTRY_SIZE * 3)
8557 #define elf_backend_default_execstack 0
8559 #undef elf_backend_obj_attrs_section
8560 #define elf_backend_obj_attrs_section ".ARM.attributes"
8562 #include "elfNN-target.h"