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 for the symbol. */
852 HOWTO64 (AARCH64_R (LD64_GOTOFF_LO15
), /* type */
854 2, /* size (0 = byte, 1 = short, 2 = long) */
856 FALSE
, /* pc_relative */
858 complain_overflow_unsigned
, /* complain_on_overflow */
859 bfd_elf_generic_reloc
, /* special_function */
860 AARCH64_R_STR (LD64_GOTOFF_LO15
), /* name */
861 FALSE
, /* partial_inplace */
862 0x7ff8, /* src_mask */
863 0x7ff8, /* dst_mask */
864 FALSE
), /* pcrel_offset */
866 /* LD32: GOT offset to the page address of GOT table.
867 (G(S) - PAGE (_GLOBAL_OFFSET_TABLE_)) & 0x5ffc. */
868 HOWTO32 (AARCH64_R (LD32_GOTPAGE_LO14
), /* type */
870 2, /* size (0 = byte, 1 = short, 2 = long) */
872 FALSE
, /* pc_relative */
874 complain_overflow_unsigned
, /* complain_on_overflow */
875 bfd_elf_generic_reloc
, /* special_function */
876 AARCH64_R_STR (LD32_GOTPAGE_LO14
), /* name */
877 FALSE
, /* partial_inplace */
878 0x5ffc, /* src_mask */
879 0x5ffc, /* dst_mask */
880 FALSE
), /* pcrel_offset */
882 /* LD64: GOT offset to the page address of GOT table.
883 (G(S) - PAGE (_GLOBAL_OFFSET_TABLE_)) & 0x7ff8. */
884 HOWTO64 (AARCH64_R (LD64_GOTPAGE_LO15
), /* type */
886 2, /* size (0 = byte, 1 = short, 2 = long) */
888 FALSE
, /* pc_relative */
890 complain_overflow_unsigned
, /* complain_on_overflow */
891 bfd_elf_generic_reloc
, /* special_function */
892 AARCH64_R_STR (LD64_GOTPAGE_LO15
), /* name */
893 FALSE
, /* partial_inplace */
894 0x7ff8, /* src_mask */
895 0x7ff8, /* dst_mask */
896 FALSE
), /* pcrel_offset */
898 /* Get to the page for the GOT entry for the symbol
899 (G(S) - P) using an ADRP instruction. */
900 HOWTO (AARCH64_R (TLSGD_ADR_PAGE21
), /* type */
902 2, /* size (0 = byte, 1 = short, 2 = long) */
904 TRUE
, /* pc_relative */
906 complain_overflow_dont
, /* complain_on_overflow */
907 bfd_elf_generic_reloc
, /* special_function */
908 AARCH64_R_STR (TLSGD_ADR_PAGE21
), /* name */
909 FALSE
, /* partial_inplace */
910 0x1fffff, /* src_mask */
911 0x1fffff, /* dst_mask */
912 TRUE
), /* pcrel_offset */
914 HOWTO (AARCH64_R (TLSGD_ADR_PREL21
), /* type */
916 2, /* size (0 = byte, 1 = short, 2 = long) */
918 TRUE
, /* pc_relative */
920 complain_overflow_dont
, /* complain_on_overflow */
921 bfd_elf_generic_reloc
, /* special_function */
922 AARCH64_R_STR (TLSGD_ADR_PREL21
), /* name */
923 FALSE
, /* partial_inplace */
924 0x1fffff, /* src_mask */
925 0x1fffff, /* dst_mask */
926 TRUE
), /* pcrel_offset */
928 /* ADD: GOT offset G(S) & 0xff8 [no overflow check] */
929 HOWTO (AARCH64_R (TLSGD_ADD_LO12_NC
), /* type */
931 2, /* size (0 = byte, 1 = short, 2 = long) */
933 FALSE
, /* pc_relative */
935 complain_overflow_dont
, /* complain_on_overflow */
936 bfd_elf_generic_reloc
, /* special_function */
937 AARCH64_R_STR (TLSGD_ADD_LO12_NC
), /* name */
938 FALSE
, /* partial_inplace */
939 0xfff, /* src_mask */
940 0xfff, /* dst_mask */
941 FALSE
), /* pcrel_offset */
943 HOWTO64 (AARCH64_R (TLSIE_MOVW_GOTTPREL_G1
), /* type */
945 2, /* size (0 = byte, 1 = short, 2 = long) */
947 FALSE
, /* pc_relative */
949 complain_overflow_dont
, /* complain_on_overflow */
950 bfd_elf_generic_reloc
, /* special_function */
951 AARCH64_R_STR (TLSIE_MOVW_GOTTPREL_G1
), /* name */
952 FALSE
, /* partial_inplace */
953 0xffff, /* src_mask */
954 0xffff, /* dst_mask */
955 FALSE
), /* pcrel_offset */
957 HOWTO64 (AARCH64_R (TLSIE_MOVW_GOTTPREL_G0_NC
), /* type */
959 2, /* size (0 = byte, 1 = short, 2 = long) */
961 FALSE
, /* pc_relative */
963 complain_overflow_dont
, /* complain_on_overflow */
964 bfd_elf_generic_reloc
, /* special_function */
965 AARCH64_R_STR (TLSIE_MOVW_GOTTPREL_G0_NC
), /* name */
966 FALSE
, /* partial_inplace */
967 0xffff, /* src_mask */
968 0xffff, /* dst_mask */
969 FALSE
), /* pcrel_offset */
971 HOWTO (AARCH64_R (TLSIE_ADR_GOTTPREL_PAGE21
), /* type */
973 2, /* size (0 = byte, 1 = short, 2 = long) */
975 FALSE
, /* pc_relative */
977 complain_overflow_dont
, /* complain_on_overflow */
978 bfd_elf_generic_reloc
, /* special_function */
979 AARCH64_R_STR (TLSIE_ADR_GOTTPREL_PAGE21
), /* name */
980 FALSE
, /* partial_inplace */
981 0x1fffff, /* src_mask */
982 0x1fffff, /* dst_mask */
983 FALSE
), /* pcrel_offset */
985 HOWTO64 (AARCH64_R (TLSIE_LD64_GOTTPREL_LO12_NC
), /* type */
987 2, /* size (0 = byte, 1 = short, 2 = long) */
989 FALSE
, /* pc_relative */
991 complain_overflow_dont
, /* complain_on_overflow */
992 bfd_elf_generic_reloc
, /* special_function */
993 AARCH64_R_STR (TLSIE_LD64_GOTTPREL_LO12_NC
), /* name */
994 FALSE
, /* partial_inplace */
995 0xff8, /* src_mask */
996 0xff8, /* dst_mask */
997 FALSE
), /* pcrel_offset */
999 HOWTO32 (AARCH64_R (TLSIE_LD32_GOTTPREL_LO12_NC
), /* type */
1001 2, /* size (0 = byte, 1 = short, 2 = long) */
1003 FALSE
, /* pc_relative */
1005 complain_overflow_dont
, /* complain_on_overflow */
1006 bfd_elf_generic_reloc
, /* special_function */
1007 AARCH64_R_STR (TLSIE_LD32_GOTTPREL_LO12_NC
), /* name */
1008 FALSE
, /* partial_inplace */
1009 0xffc, /* src_mask */
1010 0xffc, /* dst_mask */
1011 FALSE
), /* pcrel_offset */
1013 HOWTO (AARCH64_R (TLSIE_LD_GOTTPREL_PREL19
), /* type */
1015 2, /* size (0 = byte, 1 = short, 2 = long) */
1017 FALSE
, /* pc_relative */
1019 complain_overflow_dont
, /* complain_on_overflow */
1020 bfd_elf_generic_reloc
, /* special_function */
1021 AARCH64_R_STR (TLSIE_LD_GOTTPREL_PREL19
), /* name */
1022 FALSE
, /* partial_inplace */
1023 0x1ffffc, /* src_mask */
1024 0x1ffffc, /* dst_mask */
1025 FALSE
), /* pcrel_offset */
1027 HOWTO64 (AARCH64_R (TLSLE_MOVW_TPREL_G2
), /* type */
1028 32, /* rightshift */
1029 2, /* size (0 = byte, 1 = short, 2 = long) */
1031 FALSE
, /* pc_relative */
1033 complain_overflow_unsigned
, /* complain_on_overflow */
1034 bfd_elf_generic_reloc
, /* special_function */
1035 AARCH64_R_STR (TLSLE_MOVW_TPREL_G2
), /* name */
1036 FALSE
, /* partial_inplace */
1037 0xffff, /* src_mask */
1038 0xffff, /* dst_mask */
1039 FALSE
), /* pcrel_offset */
1041 HOWTO (AARCH64_R (TLSLE_MOVW_TPREL_G1
), /* type */
1042 16, /* rightshift */
1043 2, /* size (0 = byte, 1 = short, 2 = long) */
1045 FALSE
, /* pc_relative */
1047 complain_overflow_dont
, /* complain_on_overflow */
1048 bfd_elf_generic_reloc
, /* special_function */
1049 AARCH64_R_STR (TLSLE_MOVW_TPREL_G1
), /* name */
1050 FALSE
, /* partial_inplace */
1051 0xffff, /* src_mask */
1052 0xffff, /* dst_mask */
1053 FALSE
), /* pcrel_offset */
1055 HOWTO64 (AARCH64_R (TLSLE_MOVW_TPREL_G1_NC
), /* type */
1056 16, /* rightshift */
1057 2, /* size (0 = byte, 1 = short, 2 = long) */
1059 FALSE
, /* pc_relative */
1061 complain_overflow_dont
, /* complain_on_overflow */
1062 bfd_elf_generic_reloc
, /* special_function */
1063 AARCH64_R_STR (TLSLE_MOVW_TPREL_G1_NC
), /* name */
1064 FALSE
, /* partial_inplace */
1065 0xffff, /* src_mask */
1066 0xffff, /* dst_mask */
1067 FALSE
), /* pcrel_offset */
1069 HOWTO (AARCH64_R (TLSLE_MOVW_TPREL_G0
), /* type */
1071 2, /* size (0 = byte, 1 = short, 2 = long) */
1073 FALSE
, /* pc_relative */
1075 complain_overflow_dont
, /* complain_on_overflow */
1076 bfd_elf_generic_reloc
, /* special_function */
1077 AARCH64_R_STR (TLSLE_MOVW_TPREL_G0
), /* name */
1078 FALSE
, /* partial_inplace */
1079 0xffff, /* src_mask */
1080 0xffff, /* dst_mask */
1081 FALSE
), /* pcrel_offset */
1083 HOWTO (AARCH64_R (TLSLE_MOVW_TPREL_G0_NC
), /* type */
1085 2, /* size (0 = byte, 1 = short, 2 = long) */
1087 FALSE
, /* pc_relative */
1089 complain_overflow_dont
, /* complain_on_overflow */
1090 bfd_elf_generic_reloc
, /* special_function */
1091 AARCH64_R_STR (TLSLE_MOVW_TPREL_G0_NC
), /* name */
1092 FALSE
, /* partial_inplace */
1093 0xffff, /* src_mask */
1094 0xffff, /* dst_mask */
1095 FALSE
), /* pcrel_offset */
1097 HOWTO (AARCH64_R (TLSLE_ADD_TPREL_HI12
), /* type */
1098 12, /* rightshift */
1099 2, /* size (0 = byte, 1 = short, 2 = long) */
1101 FALSE
, /* pc_relative */
1103 complain_overflow_unsigned
, /* complain_on_overflow */
1104 bfd_elf_generic_reloc
, /* special_function */
1105 AARCH64_R_STR (TLSLE_ADD_TPREL_HI12
), /* name */
1106 FALSE
, /* partial_inplace */
1107 0xfff, /* src_mask */
1108 0xfff, /* dst_mask */
1109 FALSE
), /* pcrel_offset */
1111 HOWTO (AARCH64_R (TLSLE_ADD_TPREL_LO12
), /* type */
1113 2, /* size (0 = byte, 1 = short, 2 = long) */
1115 FALSE
, /* pc_relative */
1117 complain_overflow_unsigned
, /* complain_on_overflow */
1118 bfd_elf_generic_reloc
, /* special_function */
1119 AARCH64_R_STR (TLSLE_ADD_TPREL_LO12
), /* name */
1120 FALSE
, /* partial_inplace */
1121 0xfff, /* src_mask */
1122 0xfff, /* dst_mask */
1123 FALSE
), /* pcrel_offset */
1125 HOWTO (AARCH64_R (TLSLE_ADD_TPREL_LO12_NC
), /* type */
1127 2, /* size (0 = byte, 1 = short, 2 = long) */
1129 FALSE
, /* pc_relative */
1131 complain_overflow_dont
, /* complain_on_overflow */
1132 bfd_elf_generic_reloc
, /* special_function */
1133 AARCH64_R_STR (TLSLE_ADD_TPREL_LO12_NC
), /* name */
1134 FALSE
, /* partial_inplace */
1135 0xfff, /* src_mask */
1136 0xfff, /* dst_mask */
1137 FALSE
), /* pcrel_offset */
1139 HOWTO (AARCH64_R (TLSDESC_LD_PREL19
), /* type */
1141 2, /* size (0 = byte, 1 = short, 2 = long) */
1143 TRUE
, /* pc_relative */
1145 complain_overflow_dont
, /* complain_on_overflow */
1146 bfd_elf_generic_reloc
, /* special_function */
1147 AARCH64_R_STR (TLSDESC_LD_PREL19
), /* name */
1148 FALSE
, /* partial_inplace */
1149 0x0ffffe0, /* src_mask */
1150 0x0ffffe0, /* dst_mask */
1151 TRUE
), /* pcrel_offset */
1153 HOWTO (AARCH64_R (TLSDESC_ADR_PREL21
), /* type */
1155 2, /* size (0 = byte, 1 = short, 2 = long) */
1157 TRUE
, /* pc_relative */
1159 complain_overflow_dont
, /* complain_on_overflow */
1160 bfd_elf_generic_reloc
, /* special_function */
1161 AARCH64_R_STR (TLSDESC_ADR_PREL21
), /* name */
1162 FALSE
, /* partial_inplace */
1163 0x1fffff, /* src_mask */
1164 0x1fffff, /* dst_mask */
1165 TRUE
), /* pcrel_offset */
1167 /* Get to the page for the GOT entry for the symbol
1168 (G(S) - P) using an ADRP instruction. */
1169 HOWTO (AARCH64_R (TLSDESC_ADR_PAGE21
), /* type */
1170 12, /* rightshift */
1171 2, /* size (0 = byte, 1 = short, 2 = long) */
1173 TRUE
, /* pc_relative */
1175 complain_overflow_dont
, /* complain_on_overflow */
1176 bfd_elf_generic_reloc
, /* special_function */
1177 AARCH64_R_STR (TLSDESC_ADR_PAGE21
), /* name */
1178 FALSE
, /* partial_inplace */
1179 0x1fffff, /* src_mask */
1180 0x1fffff, /* dst_mask */
1181 TRUE
), /* pcrel_offset */
1183 /* LD64: GOT offset G(S) & 0xff8. */
1184 HOWTO64 (AARCH64_R (TLSDESC_LD64_LO12_NC
), /* type */
1186 2, /* size (0 = byte, 1 = short, 2 = long) */
1188 FALSE
, /* pc_relative */
1190 complain_overflow_dont
, /* complain_on_overflow */
1191 bfd_elf_generic_reloc
, /* special_function */
1192 AARCH64_R_STR (TLSDESC_LD64_LO12_NC
), /* name */
1193 FALSE
, /* partial_inplace */
1194 0xff8, /* src_mask */
1195 0xff8, /* dst_mask */
1196 FALSE
), /* pcrel_offset */
1198 /* LD32: GOT offset G(S) & 0xffc. */
1199 HOWTO32 (AARCH64_R (TLSDESC_LD32_LO12_NC
), /* type */
1201 2, /* size (0 = byte, 1 = short, 2 = long) */
1203 FALSE
, /* pc_relative */
1205 complain_overflow_dont
, /* complain_on_overflow */
1206 bfd_elf_generic_reloc
, /* special_function */
1207 AARCH64_R_STR (TLSDESC_LD32_LO12_NC
), /* name */
1208 FALSE
, /* partial_inplace */
1209 0xffc, /* src_mask */
1210 0xffc, /* dst_mask */
1211 FALSE
), /* pcrel_offset */
1213 /* ADD: GOT offset G(S) & 0xfff. */
1214 HOWTO (AARCH64_R (TLSDESC_ADD_LO12_NC
), /* type */
1216 2, /* size (0 = byte, 1 = short, 2 = long) */
1218 FALSE
, /* pc_relative */
1220 complain_overflow_dont
, /* complain_on_overflow */
1221 bfd_elf_generic_reloc
, /* special_function */
1222 AARCH64_R_STR (TLSDESC_ADD_LO12_NC
), /* name */
1223 FALSE
, /* partial_inplace */
1224 0xfff, /* src_mask */
1225 0xfff, /* dst_mask */
1226 FALSE
), /* pcrel_offset */
1228 HOWTO64 (AARCH64_R (TLSDESC_OFF_G1
), /* type */
1229 16, /* rightshift */
1230 2, /* size (0 = byte, 1 = short, 2 = long) */
1232 FALSE
, /* pc_relative */
1234 complain_overflow_dont
, /* complain_on_overflow */
1235 bfd_elf_generic_reloc
, /* special_function */
1236 AARCH64_R_STR (TLSDESC_OFF_G1
), /* name */
1237 FALSE
, /* partial_inplace */
1238 0xffff, /* src_mask */
1239 0xffff, /* dst_mask */
1240 FALSE
), /* pcrel_offset */
1242 HOWTO64 (AARCH64_R (TLSDESC_OFF_G0_NC
), /* type */
1244 2, /* size (0 = byte, 1 = short, 2 = long) */
1246 FALSE
, /* pc_relative */
1248 complain_overflow_dont
, /* complain_on_overflow */
1249 bfd_elf_generic_reloc
, /* special_function */
1250 AARCH64_R_STR (TLSDESC_OFF_G0_NC
), /* name */
1251 FALSE
, /* partial_inplace */
1252 0xffff, /* src_mask */
1253 0xffff, /* dst_mask */
1254 FALSE
), /* pcrel_offset */
1256 HOWTO64 (AARCH64_R (TLSDESC_LDR
), /* type */
1258 2, /* size (0 = byte, 1 = short, 2 = long) */
1260 FALSE
, /* pc_relative */
1262 complain_overflow_dont
, /* complain_on_overflow */
1263 bfd_elf_generic_reloc
, /* special_function */
1264 AARCH64_R_STR (TLSDESC_LDR
), /* name */
1265 FALSE
, /* partial_inplace */
1268 FALSE
), /* pcrel_offset */
1270 HOWTO64 (AARCH64_R (TLSDESC_ADD
), /* type */
1272 2, /* size (0 = byte, 1 = short, 2 = long) */
1274 FALSE
, /* pc_relative */
1276 complain_overflow_dont
, /* complain_on_overflow */
1277 bfd_elf_generic_reloc
, /* special_function */
1278 AARCH64_R_STR (TLSDESC_ADD
), /* name */
1279 FALSE
, /* partial_inplace */
1282 FALSE
), /* pcrel_offset */
1284 HOWTO (AARCH64_R (TLSDESC_CALL
), /* type */
1286 2, /* size (0 = byte, 1 = short, 2 = long) */
1288 FALSE
, /* pc_relative */
1290 complain_overflow_dont
, /* complain_on_overflow */
1291 bfd_elf_generic_reloc
, /* special_function */
1292 AARCH64_R_STR (TLSDESC_CALL
), /* name */
1293 FALSE
, /* partial_inplace */
1296 FALSE
), /* pcrel_offset */
1298 HOWTO (AARCH64_R (COPY
), /* type */
1300 2, /* size (0 = byte, 1 = short, 2 = long) */
1302 FALSE
, /* pc_relative */
1304 complain_overflow_bitfield
, /* complain_on_overflow */
1305 bfd_elf_generic_reloc
, /* special_function */
1306 AARCH64_R_STR (COPY
), /* name */
1307 TRUE
, /* partial_inplace */
1308 0xffffffff, /* src_mask */
1309 0xffffffff, /* dst_mask */
1310 FALSE
), /* pcrel_offset */
1312 HOWTO (AARCH64_R (GLOB_DAT
), /* type */
1314 2, /* size (0 = byte, 1 = short, 2 = long) */
1316 FALSE
, /* pc_relative */
1318 complain_overflow_bitfield
, /* complain_on_overflow */
1319 bfd_elf_generic_reloc
, /* special_function */
1320 AARCH64_R_STR (GLOB_DAT
), /* name */
1321 TRUE
, /* partial_inplace */
1322 0xffffffff, /* src_mask */
1323 0xffffffff, /* dst_mask */
1324 FALSE
), /* pcrel_offset */
1326 HOWTO (AARCH64_R (JUMP_SLOT
), /* type */
1328 2, /* size (0 = byte, 1 = short, 2 = long) */
1330 FALSE
, /* pc_relative */
1332 complain_overflow_bitfield
, /* complain_on_overflow */
1333 bfd_elf_generic_reloc
, /* special_function */
1334 AARCH64_R_STR (JUMP_SLOT
), /* name */
1335 TRUE
, /* partial_inplace */
1336 0xffffffff, /* src_mask */
1337 0xffffffff, /* dst_mask */
1338 FALSE
), /* pcrel_offset */
1340 HOWTO (AARCH64_R (RELATIVE
), /* type */
1342 2, /* size (0 = byte, 1 = short, 2 = long) */
1344 FALSE
, /* pc_relative */
1346 complain_overflow_bitfield
, /* complain_on_overflow */
1347 bfd_elf_generic_reloc
, /* special_function */
1348 AARCH64_R_STR (RELATIVE
), /* name */
1349 TRUE
, /* partial_inplace */
1350 ALL_ONES
, /* src_mask */
1351 ALL_ONES
, /* dst_mask */
1352 FALSE
), /* pcrel_offset */
1354 HOWTO (AARCH64_R (TLS_DTPMOD
), /* type */
1356 2, /* size (0 = byte, 1 = short, 2 = long) */
1358 FALSE
, /* pc_relative */
1360 complain_overflow_dont
, /* complain_on_overflow */
1361 bfd_elf_generic_reloc
, /* special_function */
1363 AARCH64_R_STR (TLS_DTPMOD64
), /* name */
1365 AARCH64_R_STR (TLS_DTPMOD
), /* name */
1367 FALSE
, /* partial_inplace */
1369 ALL_ONES
, /* dst_mask */
1370 FALSE
), /* pc_reloffset */
1372 HOWTO (AARCH64_R (TLS_DTPREL
), /* type */
1374 2, /* size (0 = byte, 1 = short, 2 = long) */
1376 FALSE
, /* pc_relative */
1378 complain_overflow_dont
, /* complain_on_overflow */
1379 bfd_elf_generic_reloc
, /* special_function */
1381 AARCH64_R_STR (TLS_DTPREL64
), /* name */
1383 AARCH64_R_STR (TLS_DTPREL
), /* name */
1385 FALSE
, /* partial_inplace */
1387 ALL_ONES
, /* dst_mask */
1388 FALSE
), /* pcrel_offset */
1390 HOWTO (AARCH64_R (TLS_TPREL
), /* type */
1392 2, /* size (0 = byte, 1 = short, 2 = long) */
1394 FALSE
, /* pc_relative */
1396 complain_overflow_dont
, /* complain_on_overflow */
1397 bfd_elf_generic_reloc
, /* special_function */
1399 AARCH64_R_STR (TLS_TPREL64
), /* name */
1401 AARCH64_R_STR (TLS_TPREL
), /* name */
1403 FALSE
, /* partial_inplace */
1405 ALL_ONES
, /* dst_mask */
1406 FALSE
), /* pcrel_offset */
1408 HOWTO (AARCH64_R (TLSDESC
), /* type */
1410 2, /* size (0 = byte, 1 = short, 2 = long) */
1412 FALSE
, /* pc_relative */
1414 complain_overflow_dont
, /* complain_on_overflow */
1415 bfd_elf_generic_reloc
, /* special_function */
1416 AARCH64_R_STR (TLSDESC
), /* name */
1417 FALSE
, /* partial_inplace */
1419 ALL_ONES
, /* dst_mask */
1420 FALSE
), /* pcrel_offset */
1422 HOWTO (AARCH64_R (IRELATIVE
), /* type */
1424 2, /* size (0 = byte, 1 = short, 2 = long) */
1426 FALSE
, /* pc_relative */
1428 complain_overflow_bitfield
, /* complain_on_overflow */
1429 bfd_elf_generic_reloc
, /* special_function */
1430 AARCH64_R_STR (IRELATIVE
), /* name */
1431 FALSE
, /* partial_inplace */
1433 ALL_ONES
, /* dst_mask */
1434 FALSE
), /* pcrel_offset */
1439 static reloc_howto_type elfNN_aarch64_howto_none
=
1440 HOWTO (R_AARCH64_NONE
, /* type */
1442 3, /* size (0 = byte, 1 = short, 2 = long) */
1444 FALSE
, /* pc_relative */
1446 complain_overflow_dont
,/* complain_on_overflow */
1447 bfd_elf_generic_reloc
, /* special_function */
1448 "R_AARCH64_NONE", /* name */
1449 FALSE
, /* partial_inplace */
1452 FALSE
); /* pcrel_offset */
1454 /* Given HOWTO, return the bfd internal relocation enumerator. */
1456 static bfd_reloc_code_real_type
1457 elfNN_aarch64_bfd_reloc_from_howto (reloc_howto_type
*howto
)
1460 = (int) ARRAY_SIZE (elfNN_aarch64_howto_table
);
1461 const ptrdiff_t offset
1462 = howto
- elfNN_aarch64_howto_table
;
1464 if (offset
> 0 && offset
< size
- 1)
1465 return BFD_RELOC_AARCH64_RELOC_START
+ offset
;
1467 if (howto
== &elfNN_aarch64_howto_none
)
1468 return BFD_RELOC_AARCH64_NONE
;
1470 return BFD_RELOC_AARCH64_RELOC_START
;
1473 /* Given R_TYPE, return the bfd internal relocation enumerator. */
1475 static bfd_reloc_code_real_type
1476 elfNN_aarch64_bfd_reloc_from_type (unsigned int r_type
)
1478 static bfd_boolean initialized_p
= FALSE
;
1479 /* Indexed by R_TYPE, values are offsets in the howto_table. */
1480 static unsigned int offsets
[R_AARCH64_end
];
1482 if (initialized_p
== FALSE
)
1486 for (i
= 1; i
< ARRAY_SIZE (elfNN_aarch64_howto_table
) - 1; ++i
)
1487 if (elfNN_aarch64_howto_table
[i
].type
!= 0)
1488 offsets
[elfNN_aarch64_howto_table
[i
].type
] = i
;
1490 initialized_p
= TRUE
;
1493 if (r_type
== R_AARCH64_NONE
|| r_type
== R_AARCH64_NULL
)
1494 return BFD_RELOC_AARCH64_NONE
;
1496 /* PR 17512: file: b371e70a. */
1497 if (r_type
>= R_AARCH64_end
)
1499 _bfd_error_handler (_("Invalid AArch64 reloc number: %d"), r_type
);
1500 bfd_set_error (bfd_error_bad_value
);
1501 return BFD_RELOC_AARCH64_NONE
;
1504 return BFD_RELOC_AARCH64_RELOC_START
+ offsets
[r_type
];
1507 struct elf_aarch64_reloc_map
1509 bfd_reloc_code_real_type from
;
1510 bfd_reloc_code_real_type to
;
1513 /* Map bfd generic reloc to AArch64-specific reloc. */
1514 static const struct elf_aarch64_reloc_map elf_aarch64_reloc_map
[] =
1516 {BFD_RELOC_NONE
, BFD_RELOC_AARCH64_NONE
},
1518 /* Basic data relocations. */
1519 {BFD_RELOC_CTOR
, BFD_RELOC_AARCH64_NN
},
1520 {BFD_RELOC_64
, BFD_RELOC_AARCH64_64
},
1521 {BFD_RELOC_32
, BFD_RELOC_AARCH64_32
},
1522 {BFD_RELOC_16
, BFD_RELOC_AARCH64_16
},
1523 {BFD_RELOC_64_PCREL
, BFD_RELOC_AARCH64_64_PCREL
},
1524 {BFD_RELOC_32_PCREL
, BFD_RELOC_AARCH64_32_PCREL
},
1525 {BFD_RELOC_16_PCREL
, BFD_RELOC_AARCH64_16_PCREL
},
1528 /* Given the bfd internal relocation enumerator in CODE, return the
1529 corresponding howto entry. */
1531 static reloc_howto_type
*
1532 elfNN_aarch64_howto_from_bfd_reloc (bfd_reloc_code_real_type code
)
1536 /* Convert bfd generic reloc to AArch64-specific reloc. */
1537 if (code
< BFD_RELOC_AARCH64_RELOC_START
1538 || code
> BFD_RELOC_AARCH64_RELOC_END
)
1539 for (i
= 0; i
< ARRAY_SIZE (elf_aarch64_reloc_map
); i
++)
1540 if (elf_aarch64_reloc_map
[i
].from
== code
)
1542 code
= elf_aarch64_reloc_map
[i
].to
;
1546 if (code
> BFD_RELOC_AARCH64_RELOC_START
1547 && code
< BFD_RELOC_AARCH64_RELOC_END
)
1548 if (elfNN_aarch64_howto_table
[code
- BFD_RELOC_AARCH64_RELOC_START
].type
)
1549 return &elfNN_aarch64_howto_table
[code
- BFD_RELOC_AARCH64_RELOC_START
];
1551 if (code
== BFD_RELOC_AARCH64_NONE
)
1552 return &elfNN_aarch64_howto_none
;
1557 static reloc_howto_type
*
1558 elfNN_aarch64_howto_from_type (unsigned int r_type
)
1560 bfd_reloc_code_real_type val
;
1561 reloc_howto_type
*howto
;
1566 bfd_set_error (bfd_error_bad_value
);
1571 if (r_type
== R_AARCH64_NONE
)
1572 return &elfNN_aarch64_howto_none
;
1574 val
= elfNN_aarch64_bfd_reloc_from_type (r_type
);
1575 howto
= elfNN_aarch64_howto_from_bfd_reloc (val
);
1580 bfd_set_error (bfd_error_bad_value
);
1585 elfNN_aarch64_info_to_howto (bfd
*abfd ATTRIBUTE_UNUSED
, arelent
*bfd_reloc
,
1586 Elf_Internal_Rela
*elf_reloc
)
1588 unsigned int r_type
;
1590 r_type
= ELFNN_R_TYPE (elf_reloc
->r_info
);
1591 bfd_reloc
->howto
= elfNN_aarch64_howto_from_type (r_type
);
1594 static reloc_howto_type
*
1595 elfNN_aarch64_reloc_type_lookup (bfd
*abfd ATTRIBUTE_UNUSED
,
1596 bfd_reloc_code_real_type code
)
1598 reloc_howto_type
*howto
= elfNN_aarch64_howto_from_bfd_reloc (code
);
1603 bfd_set_error (bfd_error_bad_value
);
1607 static reloc_howto_type
*
1608 elfNN_aarch64_reloc_name_lookup (bfd
*abfd ATTRIBUTE_UNUSED
,
1613 for (i
= 1; i
< ARRAY_SIZE (elfNN_aarch64_howto_table
) - 1; ++i
)
1614 if (elfNN_aarch64_howto_table
[i
].name
!= NULL
1615 && strcasecmp (elfNN_aarch64_howto_table
[i
].name
, r_name
) == 0)
1616 return &elfNN_aarch64_howto_table
[i
];
1621 #define TARGET_LITTLE_SYM aarch64_elfNN_le_vec
1622 #define TARGET_LITTLE_NAME "elfNN-littleaarch64"
1623 #define TARGET_BIG_SYM aarch64_elfNN_be_vec
1624 #define TARGET_BIG_NAME "elfNN-bigaarch64"
1626 /* The linker script knows the section names for placement.
1627 The entry_names are used to do simple name mangling on the stubs.
1628 Given a function name, and its type, the stub can be found. The
1629 name can be changed. The only requirement is the %s be present. */
1630 #define STUB_ENTRY_NAME "__%s_veneer"
1632 /* The name of the dynamic interpreter. This is put in the .interp
1634 #define ELF_DYNAMIC_INTERPRETER "/lib/ld.so.1"
1636 #define AARCH64_MAX_FWD_BRANCH_OFFSET \
1637 (((1 << 25) - 1) << 2)
1638 #define AARCH64_MAX_BWD_BRANCH_OFFSET \
1641 #define AARCH64_MAX_ADRP_IMM ((1 << 20) - 1)
1642 #define AARCH64_MIN_ADRP_IMM (-(1 << 20))
1645 aarch64_valid_for_adrp_p (bfd_vma value
, bfd_vma place
)
1647 bfd_signed_vma offset
= (bfd_signed_vma
) (PG (value
) - PG (place
)) >> 12;
1648 return offset
<= AARCH64_MAX_ADRP_IMM
&& offset
>= AARCH64_MIN_ADRP_IMM
;
1652 aarch64_valid_branch_p (bfd_vma value
, bfd_vma place
)
1654 bfd_signed_vma offset
= (bfd_signed_vma
) (value
- place
);
1655 return (offset
<= AARCH64_MAX_FWD_BRANCH_OFFSET
1656 && offset
>= AARCH64_MAX_BWD_BRANCH_OFFSET
);
1659 static const uint32_t aarch64_adrp_branch_stub
[] =
1661 0x90000010, /* adrp ip0, X */
1662 /* R_AARCH64_ADR_HI21_PCREL(X) */
1663 0x91000210, /* add ip0, ip0, :lo12:X */
1664 /* R_AARCH64_ADD_ABS_LO12_NC(X) */
1665 0xd61f0200, /* br ip0 */
1668 static const uint32_t aarch64_long_branch_stub
[] =
1671 0x58000090, /* ldr ip0, 1f */
1673 0x18000090, /* ldr wip0, 1f */
1675 0x10000011, /* adr ip1, #0 */
1676 0x8b110210, /* add ip0, ip0, ip1 */
1677 0xd61f0200, /* br ip0 */
1678 0x00000000, /* 1: .xword or .word
1679 R_AARCH64_PRELNN(X) + 12
1684 static const uint32_t aarch64_erratum_835769_stub
[] =
1686 0x00000000, /* Placeholder for multiply accumulate. */
1687 0x14000000, /* b <label> */
1690 static const uint32_t aarch64_erratum_843419_stub
[] =
1692 0x00000000, /* Placeholder for LDR instruction. */
1693 0x14000000, /* b <label> */
1696 /* Section name for stubs is the associated section name plus this
1698 #define STUB_SUFFIX ".stub"
1700 enum elf_aarch64_stub_type
1703 aarch64_stub_adrp_branch
,
1704 aarch64_stub_long_branch
,
1705 aarch64_stub_erratum_835769_veneer
,
1706 aarch64_stub_erratum_843419_veneer
,
1709 struct elf_aarch64_stub_hash_entry
1711 /* Base hash table entry structure. */
1712 struct bfd_hash_entry root
;
1714 /* The stub section. */
1717 /* Offset within stub_sec of the beginning of this stub. */
1718 bfd_vma stub_offset
;
1720 /* Given the symbol's value and its section we can determine its final
1721 value when building the stubs (so the stub knows where to jump). */
1722 bfd_vma target_value
;
1723 asection
*target_section
;
1725 enum elf_aarch64_stub_type stub_type
;
1727 /* The symbol table entry, if any, that this was derived from. */
1728 struct elf_aarch64_link_hash_entry
*h
;
1730 /* Destination symbol type */
1731 unsigned char st_type
;
1733 /* Where this stub is being called from, or, in the case of combined
1734 stub sections, the first input section in the group. */
1737 /* The name for the local symbol at the start of this stub. The
1738 stub name in the hash table has to be unique; this does not, so
1739 it can be friendlier. */
1742 /* The instruction which caused this stub to be generated (only valid for
1743 erratum 835769 workaround stubs at present). */
1744 uint32_t veneered_insn
;
1746 /* In an erratum 843419 workaround stub, the ADRP instruction offset. */
1747 bfd_vma adrp_offset
;
1750 /* Used to build a map of a section. This is required for mixed-endian
1753 typedef struct elf_elf_section_map
1758 elf_aarch64_section_map
;
1761 typedef struct _aarch64_elf_section_data
1763 struct bfd_elf_section_data elf
;
1764 unsigned int mapcount
;
1765 unsigned int mapsize
;
1766 elf_aarch64_section_map
*map
;
1768 _aarch64_elf_section_data
;
1770 #define elf_aarch64_section_data(sec) \
1771 ((_aarch64_elf_section_data *) elf_section_data (sec))
1773 /* The size of the thread control block which is defined to be two pointers. */
1774 #define TCB_SIZE (ARCH_SIZE/8)*2
1776 struct elf_aarch64_local_symbol
1778 unsigned int got_type
;
1779 bfd_signed_vma got_refcount
;
1782 /* Offset of the GOTPLT entry reserved for the TLS descriptor. The
1783 offset is from the end of the jump table and reserved entries
1786 The magic value (bfd_vma) -1 indicates that an offset has not be
1788 bfd_vma tlsdesc_got_jump_table_offset
;
1791 struct elf_aarch64_obj_tdata
1793 struct elf_obj_tdata root
;
1795 /* local symbol descriptors */
1796 struct elf_aarch64_local_symbol
*locals
;
1798 /* Zero to warn when linking objects with incompatible enum sizes. */
1799 int no_enum_size_warning
;
1801 /* Zero to warn when linking objects with incompatible wchar_t sizes. */
1802 int no_wchar_size_warning
;
1805 #define elf_aarch64_tdata(bfd) \
1806 ((struct elf_aarch64_obj_tdata *) (bfd)->tdata.any)
1808 #define elf_aarch64_locals(bfd) (elf_aarch64_tdata (bfd)->locals)
1810 #define is_aarch64_elf(bfd) \
1811 (bfd_get_flavour (bfd) == bfd_target_elf_flavour \
1812 && elf_tdata (bfd) != NULL \
1813 && elf_object_id (bfd) == AARCH64_ELF_DATA)
1816 elfNN_aarch64_mkobject (bfd
*abfd
)
1818 return bfd_elf_allocate_object (abfd
, sizeof (struct elf_aarch64_obj_tdata
),
1822 #define elf_aarch64_hash_entry(ent) \
1823 ((struct elf_aarch64_link_hash_entry *)(ent))
1825 #define GOT_UNKNOWN 0
1826 #define GOT_NORMAL 1
1827 #define GOT_TLS_GD 2
1828 #define GOT_TLS_IE 4
1829 #define GOT_TLSDESC_GD 8
1831 #define GOT_TLS_GD_ANY_P(type) ((type & GOT_TLS_GD) || (type & GOT_TLSDESC_GD))
1833 /* AArch64 ELF linker hash entry. */
1834 struct elf_aarch64_link_hash_entry
1836 struct elf_link_hash_entry root
;
1838 /* Track dynamic relocs copied for this symbol. */
1839 struct elf_dyn_relocs
*dyn_relocs
;
1841 /* Since PLT entries have variable size, we need to record the
1842 index into .got.plt instead of recomputing it from the PLT
1844 bfd_signed_vma plt_got_offset
;
1846 /* Bit mask representing the type of GOT entry(s) if any required by
1848 unsigned int got_type
;
1850 /* A pointer to the most recently used stub hash entry against this
1852 struct elf_aarch64_stub_hash_entry
*stub_cache
;
1854 /* Offset of the GOTPLT entry reserved for the TLS descriptor. The offset
1855 is from the end of the jump table and reserved entries within the PLTGOT.
1857 The magic value (bfd_vma) -1 indicates that an offset has not
1859 bfd_vma tlsdesc_got_jump_table_offset
;
1863 elfNN_aarch64_symbol_got_type (struct elf_link_hash_entry
*h
,
1865 unsigned long r_symndx
)
1868 return elf_aarch64_hash_entry (h
)->got_type
;
1870 if (! elf_aarch64_locals (abfd
))
1873 return elf_aarch64_locals (abfd
)[r_symndx
].got_type
;
1876 /* Get the AArch64 elf linker hash table from a link_info structure. */
1877 #define elf_aarch64_hash_table(info) \
1878 ((struct elf_aarch64_link_hash_table *) ((info)->hash))
1880 #define aarch64_stub_hash_lookup(table, string, create, copy) \
1881 ((struct elf_aarch64_stub_hash_entry *) \
1882 bfd_hash_lookup ((table), (string), (create), (copy)))
1884 /* AArch64 ELF linker hash table. */
1885 struct elf_aarch64_link_hash_table
1887 /* The main hash table. */
1888 struct elf_link_hash_table root
;
1890 /* Nonzero to force PIC branch veneers. */
1893 /* Fix erratum 835769. */
1894 int fix_erratum_835769
;
1896 /* Fix erratum 843419. */
1897 int fix_erratum_843419
;
1899 /* Enable ADRP->ADR rewrite for erratum 843419 workaround. */
1900 int fix_erratum_843419_adr
;
1902 /* The number of bytes in the initial entry in the PLT. */
1903 bfd_size_type plt_header_size
;
1905 /* The number of bytes in the subsequent PLT etries. */
1906 bfd_size_type plt_entry_size
;
1908 /* Short-cuts to get to dynamic linker sections. */
1912 /* Small local sym cache. */
1913 struct sym_cache sym_cache
;
1915 /* For convenience in allocate_dynrelocs. */
1918 /* The amount of space used by the reserved portion of the sgotplt
1919 section, plus whatever space is used by the jump slots. */
1920 bfd_vma sgotplt_jump_table_size
;
1922 /* The stub hash table. */
1923 struct bfd_hash_table stub_hash_table
;
1925 /* Linker stub bfd. */
1928 /* Linker call-backs. */
1929 asection
*(*add_stub_section
) (const char *, asection
*);
1930 void (*layout_sections_again
) (void);
1932 /* Array to keep track of which stub sections have been created, and
1933 information on stub grouping. */
1936 /* This is the section to which stubs in the group will be
1939 /* The stub section. */
1943 /* Assorted information used by elfNN_aarch64_size_stubs. */
1944 unsigned int bfd_count
;
1946 asection
**input_list
;
1948 /* The offset into splt of the PLT entry for the TLS descriptor
1949 resolver. Special values are 0, if not necessary (or not found
1950 to be necessary yet), and -1 if needed but not determined
1952 bfd_vma tlsdesc_plt
;
1954 /* The GOT offset for the lazy trampoline. Communicated to the
1955 loader via DT_TLSDESC_GOT. The magic value (bfd_vma) -1
1956 indicates an offset is not allocated. */
1957 bfd_vma dt_tlsdesc_got
;
1959 /* Used by local STT_GNU_IFUNC symbols. */
1960 htab_t loc_hash_table
;
1961 void * loc_hash_memory
;
1964 /* Create an entry in an AArch64 ELF linker hash table. */
1966 static struct bfd_hash_entry
*
1967 elfNN_aarch64_link_hash_newfunc (struct bfd_hash_entry
*entry
,
1968 struct bfd_hash_table
*table
,
1971 struct elf_aarch64_link_hash_entry
*ret
=
1972 (struct elf_aarch64_link_hash_entry
*) entry
;
1974 /* Allocate the structure if it has not already been allocated by a
1977 ret
= bfd_hash_allocate (table
,
1978 sizeof (struct elf_aarch64_link_hash_entry
));
1980 return (struct bfd_hash_entry
*) ret
;
1982 /* Call the allocation method of the superclass. */
1983 ret
= ((struct elf_aarch64_link_hash_entry
*)
1984 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry
*) ret
,
1988 ret
->dyn_relocs
= NULL
;
1989 ret
->got_type
= GOT_UNKNOWN
;
1990 ret
->plt_got_offset
= (bfd_vma
) - 1;
1991 ret
->stub_cache
= NULL
;
1992 ret
->tlsdesc_got_jump_table_offset
= (bfd_vma
) - 1;
1995 return (struct bfd_hash_entry
*) ret
;
1998 /* Initialize an entry in the stub hash table. */
2000 static struct bfd_hash_entry
*
2001 stub_hash_newfunc (struct bfd_hash_entry
*entry
,
2002 struct bfd_hash_table
*table
, const char *string
)
2004 /* Allocate the structure if it has not already been allocated by a
2008 entry
= bfd_hash_allocate (table
,
2010 elf_aarch64_stub_hash_entry
));
2015 /* Call the allocation method of the superclass. */
2016 entry
= bfd_hash_newfunc (entry
, table
, string
);
2019 struct elf_aarch64_stub_hash_entry
*eh
;
2021 /* Initialize the local fields. */
2022 eh
= (struct elf_aarch64_stub_hash_entry
*) entry
;
2023 eh
->adrp_offset
= 0;
2024 eh
->stub_sec
= NULL
;
2025 eh
->stub_offset
= 0;
2026 eh
->target_value
= 0;
2027 eh
->target_section
= NULL
;
2028 eh
->stub_type
= aarch64_stub_none
;
2036 /* Compute a hash of a local hash entry. We use elf_link_hash_entry
2037 for local symbol so that we can handle local STT_GNU_IFUNC symbols
2038 as global symbol. We reuse indx and dynstr_index for local symbol
2039 hash since they aren't used by global symbols in this backend. */
2042 elfNN_aarch64_local_htab_hash (const void *ptr
)
2044 struct elf_link_hash_entry
*h
2045 = (struct elf_link_hash_entry
*) ptr
;
2046 return ELF_LOCAL_SYMBOL_HASH (h
->indx
, h
->dynstr_index
);
2049 /* Compare local hash entries. */
2052 elfNN_aarch64_local_htab_eq (const void *ptr1
, const void *ptr2
)
2054 struct elf_link_hash_entry
*h1
2055 = (struct elf_link_hash_entry
*) ptr1
;
2056 struct elf_link_hash_entry
*h2
2057 = (struct elf_link_hash_entry
*) ptr2
;
2059 return h1
->indx
== h2
->indx
&& h1
->dynstr_index
== h2
->dynstr_index
;
2062 /* Find and/or create a hash entry for local symbol. */
2064 static struct elf_link_hash_entry
*
2065 elfNN_aarch64_get_local_sym_hash (struct elf_aarch64_link_hash_table
*htab
,
2066 bfd
*abfd
, const Elf_Internal_Rela
*rel
,
2069 struct elf_aarch64_link_hash_entry e
, *ret
;
2070 asection
*sec
= abfd
->sections
;
2071 hashval_t h
= ELF_LOCAL_SYMBOL_HASH (sec
->id
,
2072 ELFNN_R_SYM (rel
->r_info
));
2075 e
.root
.indx
= sec
->id
;
2076 e
.root
.dynstr_index
= ELFNN_R_SYM (rel
->r_info
);
2077 slot
= htab_find_slot_with_hash (htab
->loc_hash_table
, &e
, h
,
2078 create
? INSERT
: NO_INSERT
);
2085 ret
= (struct elf_aarch64_link_hash_entry
*) *slot
;
2089 ret
= (struct elf_aarch64_link_hash_entry
*)
2090 objalloc_alloc ((struct objalloc
*) htab
->loc_hash_memory
,
2091 sizeof (struct elf_aarch64_link_hash_entry
));
2094 memset (ret
, 0, sizeof (*ret
));
2095 ret
->root
.indx
= sec
->id
;
2096 ret
->root
.dynstr_index
= ELFNN_R_SYM (rel
->r_info
);
2097 ret
->root
.dynindx
= -1;
2103 /* Copy the extra info we tack onto an elf_link_hash_entry. */
2106 elfNN_aarch64_copy_indirect_symbol (struct bfd_link_info
*info
,
2107 struct elf_link_hash_entry
*dir
,
2108 struct elf_link_hash_entry
*ind
)
2110 struct elf_aarch64_link_hash_entry
*edir
, *eind
;
2112 edir
= (struct elf_aarch64_link_hash_entry
*) dir
;
2113 eind
= (struct elf_aarch64_link_hash_entry
*) ind
;
2115 if (eind
->dyn_relocs
!= NULL
)
2117 if (edir
->dyn_relocs
!= NULL
)
2119 struct elf_dyn_relocs
**pp
;
2120 struct elf_dyn_relocs
*p
;
2122 /* Add reloc counts against the indirect sym to the direct sym
2123 list. Merge any entries against the same section. */
2124 for (pp
= &eind
->dyn_relocs
; (p
= *pp
) != NULL
;)
2126 struct elf_dyn_relocs
*q
;
2128 for (q
= edir
->dyn_relocs
; q
!= NULL
; q
= q
->next
)
2129 if (q
->sec
== p
->sec
)
2131 q
->pc_count
+= p
->pc_count
;
2132 q
->count
+= p
->count
;
2139 *pp
= edir
->dyn_relocs
;
2142 edir
->dyn_relocs
= eind
->dyn_relocs
;
2143 eind
->dyn_relocs
= NULL
;
2146 if (ind
->root
.type
== bfd_link_hash_indirect
)
2148 /* Copy over PLT info. */
2149 if (dir
->got
.refcount
<= 0)
2151 edir
->got_type
= eind
->got_type
;
2152 eind
->got_type
= GOT_UNKNOWN
;
2156 _bfd_elf_link_hash_copy_indirect (info
, dir
, ind
);
2159 /* Destroy an AArch64 elf linker hash table. */
2162 elfNN_aarch64_link_hash_table_free (bfd
*obfd
)
2164 struct elf_aarch64_link_hash_table
*ret
2165 = (struct elf_aarch64_link_hash_table
*) obfd
->link
.hash
;
2167 if (ret
->loc_hash_table
)
2168 htab_delete (ret
->loc_hash_table
);
2169 if (ret
->loc_hash_memory
)
2170 objalloc_free ((struct objalloc
*) ret
->loc_hash_memory
);
2172 bfd_hash_table_free (&ret
->stub_hash_table
);
2173 _bfd_elf_link_hash_table_free (obfd
);
2176 /* Create an AArch64 elf linker hash table. */
2178 static struct bfd_link_hash_table
*
2179 elfNN_aarch64_link_hash_table_create (bfd
*abfd
)
2181 struct elf_aarch64_link_hash_table
*ret
;
2182 bfd_size_type amt
= sizeof (struct elf_aarch64_link_hash_table
);
2184 ret
= bfd_zmalloc (amt
);
2188 if (!_bfd_elf_link_hash_table_init
2189 (&ret
->root
, abfd
, elfNN_aarch64_link_hash_newfunc
,
2190 sizeof (struct elf_aarch64_link_hash_entry
), AARCH64_ELF_DATA
))
2196 ret
->plt_header_size
= PLT_ENTRY_SIZE
;
2197 ret
->plt_entry_size
= PLT_SMALL_ENTRY_SIZE
;
2199 ret
->dt_tlsdesc_got
= (bfd_vma
) - 1;
2201 if (!bfd_hash_table_init (&ret
->stub_hash_table
, stub_hash_newfunc
,
2202 sizeof (struct elf_aarch64_stub_hash_entry
)))
2204 _bfd_elf_link_hash_table_free (abfd
);
2208 ret
->loc_hash_table
= htab_try_create (1024,
2209 elfNN_aarch64_local_htab_hash
,
2210 elfNN_aarch64_local_htab_eq
,
2212 ret
->loc_hash_memory
= objalloc_create ();
2213 if (!ret
->loc_hash_table
|| !ret
->loc_hash_memory
)
2215 elfNN_aarch64_link_hash_table_free (abfd
);
2218 ret
->root
.root
.hash_table_free
= elfNN_aarch64_link_hash_table_free
;
2220 return &ret
->root
.root
;
2224 aarch64_relocate (unsigned int r_type
, bfd
*input_bfd
, asection
*input_section
,
2225 bfd_vma offset
, bfd_vma value
)
2227 reloc_howto_type
*howto
;
2230 howto
= elfNN_aarch64_howto_from_type (r_type
);
2231 place
= (input_section
->output_section
->vma
+ input_section
->output_offset
2234 r_type
= elfNN_aarch64_bfd_reloc_from_type (r_type
);
2235 value
= _bfd_aarch64_elf_resolve_relocation (r_type
, place
, value
, 0, FALSE
);
2236 return _bfd_aarch64_elf_put_addend (input_bfd
,
2237 input_section
->contents
+ offset
, r_type
,
2241 static enum elf_aarch64_stub_type
2242 aarch64_select_branch_stub (bfd_vma value
, bfd_vma place
)
2244 if (aarch64_valid_for_adrp_p (value
, place
))
2245 return aarch64_stub_adrp_branch
;
2246 return aarch64_stub_long_branch
;
2249 /* Determine the type of stub needed, if any, for a call. */
2251 static enum elf_aarch64_stub_type
2252 aarch64_type_of_stub (struct bfd_link_info
*info
,
2253 asection
*input_sec
,
2254 const Elf_Internal_Rela
*rel
,
2255 unsigned char st_type
,
2256 struct elf_aarch64_link_hash_entry
*hash
,
2257 bfd_vma destination
)
2260 bfd_signed_vma branch_offset
;
2261 unsigned int r_type
;
2262 struct elf_aarch64_link_hash_table
*globals
;
2263 enum elf_aarch64_stub_type stub_type
= aarch64_stub_none
;
2264 bfd_boolean via_plt_p
;
2266 if (st_type
!= STT_FUNC
)
2269 globals
= elf_aarch64_hash_table (info
);
2270 via_plt_p
= (globals
->root
.splt
!= NULL
&& hash
!= NULL
2271 && hash
->root
.plt
.offset
!= (bfd_vma
) - 1);
2276 /* Determine where the call point is. */
2277 location
= (input_sec
->output_offset
2278 + input_sec
->output_section
->vma
+ rel
->r_offset
);
2280 branch_offset
= (bfd_signed_vma
) (destination
- location
);
2282 r_type
= ELFNN_R_TYPE (rel
->r_info
);
2284 /* We don't want to redirect any old unconditional jump in this way,
2285 only one which is being used for a sibcall, where it is
2286 acceptable for the IP0 and IP1 registers to be clobbered. */
2287 if ((r_type
== AARCH64_R (CALL26
) || r_type
== AARCH64_R (JUMP26
))
2288 && (branch_offset
> AARCH64_MAX_FWD_BRANCH_OFFSET
2289 || branch_offset
< AARCH64_MAX_BWD_BRANCH_OFFSET
))
2291 stub_type
= aarch64_stub_long_branch
;
2297 /* Build a name for an entry in the stub hash table. */
2300 elfNN_aarch64_stub_name (const asection
*input_section
,
2301 const asection
*sym_sec
,
2302 const struct elf_aarch64_link_hash_entry
*hash
,
2303 const Elf_Internal_Rela
*rel
)
2310 len
= 8 + 1 + strlen (hash
->root
.root
.root
.string
) + 1 + 16 + 1;
2311 stub_name
= bfd_malloc (len
);
2312 if (stub_name
!= NULL
)
2313 snprintf (stub_name
, len
, "%08x_%s+%" BFD_VMA_FMT
"x",
2314 (unsigned int) input_section
->id
,
2315 hash
->root
.root
.root
.string
,
2320 len
= 8 + 1 + 8 + 1 + 8 + 1 + 16 + 1;
2321 stub_name
= bfd_malloc (len
);
2322 if (stub_name
!= NULL
)
2323 snprintf (stub_name
, len
, "%08x_%x:%x+%" BFD_VMA_FMT
"x",
2324 (unsigned int) input_section
->id
,
2325 (unsigned int) sym_sec
->id
,
2326 (unsigned int) ELFNN_R_SYM (rel
->r_info
),
2333 /* Look up an entry in the stub hash. Stub entries are cached because
2334 creating the stub name takes a bit of time. */
2336 static struct elf_aarch64_stub_hash_entry
*
2337 elfNN_aarch64_get_stub_entry (const asection
*input_section
,
2338 const asection
*sym_sec
,
2339 struct elf_link_hash_entry
*hash
,
2340 const Elf_Internal_Rela
*rel
,
2341 struct elf_aarch64_link_hash_table
*htab
)
2343 struct elf_aarch64_stub_hash_entry
*stub_entry
;
2344 struct elf_aarch64_link_hash_entry
*h
=
2345 (struct elf_aarch64_link_hash_entry
*) hash
;
2346 const asection
*id_sec
;
2348 if ((input_section
->flags
& SEC_CODE
) == 0)
2351 /* If this input section is part of a group of sections sharing one
2352 stub section, then use the id of the first section in the group.
2353 Stub names need to include a section id, as there may well be
2354 more than one stub used to reach say, printf, and we need to
2355 distinguish between them. */
2356 id_sec
= htab
->stub_group
[input_section
->id
].link_sec
;
2358 if (h
!= NULL
&& h
->stub_cache
!= NULL
2359 && h
->stub_cache
->h
== h
&& h
->stub_cache
->id_sec
== id_sec
)
2361 stub_entry
= h
->stub_cache
;
2367 stub_name
= elfNN_aarch64_stub_name (id_sec
, sym_sec
, h
, rel
);
2368 if (stub_name
== NULL
)
2371 stub_entry
= aarch64_stub_hash_lookup (&htab
->stub_hash_table
,
2372 stub_name
, FALSE
, FALSE
);
2374 h
->stub_cache
= stub_entry
;
2383 /* Create a stub section. */
2386 _bfd_aarch64_create_stub_section (asection
*section
,
2387 struct elf_aarch64_link_hash_table
*htab
)
2393 namelen
= strlen (section
->name
);
2394 len
= namelen
+ sizeof (STUB_SUFFIX
);
2395 s_name
= bfd_alloc (htab
->stub_bfd
, len
);
2399 memcpy (s_name
, section
->name
, namelen
);
2400 memcpy (s_name
+ namelen
, STUB_SUFFIX
, sizeof (STUB_SUFFIX
));
2401 return (*htab
->add_stub_section
) (s_name
, section
);
2405 /* Find or create a stub section for a link section.
2407 Fix or create the stub section used to collect stubs attached to
2408 the specified link section. */
2411 _bfd_aarch64_get_stub_for_link_section (asection
*link_section
,
2412 struct elf_aarch64_link_hash_table
*htab
)
2414 if (htab
->stub_group
[link_section
->id
].stub_sec
== NULL
)
2415 htab
->stub_group
[link_section
->id
].stub_sec
2416 = _bfd_aarch64_create_stub_section (link_section
, htab
);
2417 return htab
->stub_group
[link_section
->id
].stub_sec
;
2421 /* Find or create a stub section in the stub group for an input
2425 _bfd_aarch64_create_or_find_stub_sec (asection
*section
,
2426 struct elf_aarch64_link_hash_table
*htab
)
2428 asection
*link_sec
= htab
->stub_group
[section
->id
].link_sec
;
2429 return _bfd_aarch64_get_stub_for_link_section (link_sec
, htab
);
2433 /* Add a new stub entry in the stub group associated with an input
2434 section to the stub hash. Not all fields of the new stub entry are
2437 static struct elf_aarch64_stub_hash_entry
*
2438 _bfd_aarch64_add_stub_entry_in_group (const char *stub_name
,
2440 struct elf_aarch64_link_hash_table
*htab
)
2444 struct elf_aarch64_stub_hash_entry
*stub_entry
;
2446 link_sec
= htab
->stub_group
[section
->id
].link_sec
;
2447 stub_sec
= _bfd_aarch64_create_or_find_stub_sec (section
, htab
);
2449 /* Enter this entry into the linker stub hash table. */
2450 stub_entry
= aarch64_stub_hash_lookup (&htab
->stub_hash_table
, stub_name
,
2452 if (stub_entry
== NULL
)
2454 (*_bfd_error_handler
) (_("%s: cannot create stub entry %s"),
2455 section
->owner
, stub_name
);
2459 stub_entry
->stub_sec
= stub_sec
;
2460 stub_entry
->stub_offset
= 0;
2461 stub_entry
->id_sec
= link_sec
;
2466 /* Add a new stub entry in the final stub section to the stub hash.
2467 Not all fields of the new stub entry are initialised. */
2469 static struct elf_aarch64_stub_hash_entry
*
2470 _bfd_aarch64_add_stub_entry_after (const char *stub_name
,
2471 asection
*link_section
,
2472 struct elf_aarch64_link_hash_table
*htab
)
2475 struct elf_aarch64_stub_hash_entry
*stub_entry
;
2477 stub_sec
= _bfd_aarch64_get_stub_for_link_section (link_section
, htab
);
2478 stub_entry
= aarch64_stub_hash_lookup (&htab
->stub_hash_table
, stub_name
,
2480 if (stub_entry
== NULL
)
2482 (*_bfd_error_handler
) (_("cannot create stub entry %s"), stub_name
);
2486 stub_entry
->stub_sec
= stub_sec
;
2487 stub_entry
->stub_offset
= 0;
2488 stub_entry
->id_sec
= link_section
;
2495 aarch64_build_one_stub (struct bfd_hash_entry
*gen_entry
,
2496 void *in_arg ATTRIBUTE_UNUSED
)
2498 struct elf_aarch64_stub_hash_entry
*stub_entry
;
2503 bfd_vma veneered_insn_loc
;
2504 bfd_vma veneer_entry_loc
;
2505 bfd_signed_vma branch_offset
= 0;
2506 unsigned int template_size
;
2507 const uint32_t *template;
2510 /* Massage our args to the form they really have. */
2511 stub_entry
= (struct elf_aarch64_stub_hash_entry
*) gen_entry
;
2513 stub_sec
= stub_entry
->stub_sec
;
2515 /* Make a note of the offset within the stubs for this entry. */
2516 stub_entry
->stub_offset
= stub_sec
->size
;
2517 loc
= stub_sec
->contents
+ stub_entry
->stub_offset
;
2519 stub_bfd
= stub_sec
->owner
;
2521 /* This is the address of the stub destination. */
2522 sym_value
= (stub_entry
->target_value
2523 + stub_entry
->target_section
->output_offset
2524 + stub_entry
->target_section
->output_section
->vma
);
2526 if (stub_entry
->stub_type
== aarch64_stub_long_branch
)
2528 bfd_vma place
= (stub_entry
->stub_offset
+ stub_sec
->output_section
->vma
2529 + stub_sec
->output_offset
);
2531 /* See if we can relax the stub. */
2532 if (aarch64_valid_for_adrp_p (sym_value
, place
))
2533 stub_entry
->stub_type
= aarch64_select_branch_stub (sym_value
, place
);
2536 switch (stub_entry
->stub_type
)
2538 case aarch64_stub_adrp_branch
:
2539 template = aarch64_adrp_branch_stub
;
2540 template_size
= sizeof (aarch64_adrp_branch_stub
);
2542 case aarch64_stub_long_branch
:
2543 template = aarch64_long_branch_stub
;
2544 template_size
= sizeof (aarch64_long_branch_stub
);
2546 case aarch64_stub_erratum_835769_veneer
:
2547 template = aarch64_erratum_835769_stub
;
2548 template_size
= sizeof (aarch64_erratum_835769_stub
);
2550 case aarch64_stub_erratum_843419_veneer
:
2551 template = aarch64_erratum_843419_stub
;
2552 template_size
= sizeof (aarch64_erratum_843419_stub
);
2558 for (i
= 0; i
< (template_size
/ sizeof template[0]); i
++)
2560 bfd_putl32 (template[i
], loc
);
2564 template_size
= (template_size
+ 7) & ~7;
2565 stub_sec
->size
+= template_size
;
2567 switch (stub_entry
->stub_type
)
2569 case aarch64_stub_adrp_branch
:
2570 if (aarch64_relocate (AARCH64_R (ADR_PREL_PG_HI21
), stub_bfd
, stub_sec
,
2571 stub_entry
->stub_offset
, sym_value
))
2572 /* The stub would not have been relaxed if the offset was out
2576 if (aarch64_relocate (AARCH64_R (ADD_ABS_LO12_NC
), stub_bfd
, stub_sec
,
2577 stub_entry
->stub_offset
+ 4, sym_value
))
2581 case aarch64_stub_long_branch
:
2582 /* We want the value relative to the address 12 bytes back from the
2584 if (aarch64_relocate (AARCH64_R (PRELNN
), stub_bfd
, stub_sec
,
2585 stub_entry
->stub_offset
+ 16, sym_value
+ 12))
2589 case aarch64_stub_erratum_835769_veneer
:
2590 veneered_insn_loc
= stub_entry
->target_section
->output_section
->vma
2591 + stub_entry
->target_section
->output_offset
2592 + stub_entry
->target_value
;
2593 veneer_entry_loc
= stub_entry
->stub_sec
->output_section
->vma
2594 + stub_entry
->stub_sec
->output_offset
2595 + stub_entry
->stub_offset
;
2596 branch_offset
= veneered_insn_loc
- veneer_entry_loc
;
2597 branch_offset
>>= 2;
2598 branch_offset
&= 0x3ffffff;
2599 bfd_putl32 (stub_entry
->veneered_insn
,
2600 stub_sec
->contents
+ stub_entry
->stub_offset
);
2601 bfd_putl32 (template[1] | branch_offset
,
2602 stub_sec
->contents
+ stub_entry
->stub_offset
+ 4);
2605 case aarch64_stub_erratum_843419_veneer
:
2606 if (aarch64_relocate (AARCH64_R (JUMP26
), stub_bfd
, stub_sec
,
2607 stub_entry
->stub_offset
+ 4, sym_value
+ 4))
2618 /* As above, but don't actually build the stub. Just bump offset so
2619 we know stub section sizes. */
2622 aarch64_size_one_stub (struct bfd_hash_entry
*gen_entry
,
2623 void *in_arg ATTRIBUTE_UNUSED
)
2625 struct elf_aarch64_stub_hash_entry
*stub_entry
;
2628 /* Massage our args to the form they really have. */
2629 stub_entry
= (struct elf_aarch64_stub_hash_entry
*) gen_entry
;
2631 switch (stub_entry
->stub_type
)
2633 case aarch64_stub_adrp_branch
:
2634 size
= sizeof (aarch64_adrp_branch_stub
);
2636 case aarch64_stub_long_branch
:
2637 size
= sizeof (aarch64_long_branch_stub
);
2639 case aarch64_stub_erratum_835769_veneer
:
2640 size
= sizeof (aarch64_erratum_835769_stub
);
2642 case aarch64_stub_erratum_843419_veneer
:
2643 size
= sizeof (aarch64_erratum_843419_stub
);
2649 size
= (size
+ 7) & ~7;
2650 stub_entry
->stub_sec
->size
+= size
;
2654 /* External entry points for sizing and building linker stubs. */
2656 /* Set up various things so that we can make a list of input sections
2657 for each output section included in the link. Returns -1 on error,
2658 0 when no stubs will be needed, and 1 on success. */
2661 elfNN_aarch64_setup_section_lists (bfd
*output_bfd
,
2662 struct bfd_link_info
*info
)
2665 unsigned int bfd_count
;
2666 int top_id
, top_index
;
2668 asection
**input_list
, **list
;
2670 struct elf_aarch64_link_hash_table
*htab
=
2671 elf_aarch64_hash_table (info
);
2673 if (!is_elf_hash_table (htab
))
2676 /* Count the number of input BFDs and find the top input section id. */
2677 for (input_bfd
= info
->input_bfds
, bfd_count
= 0, top_id
= 0;
2678 input_bfd
!= NULL
; input_bfd
= input_bfd
->link
.next
)
2681 for (section
= input_bfd
->sections
;
2682 section
!= NULL
; section
= section
->next
)
2684 if (top_id
< section
->id
)
2685 top_id
= section
->id
;
2688 htab
->bfd_count
= bfd_count
;
2690 amt
= sizeof (struct map_stub
) * (top_id
+ 1);
2691 htab
->stub_group
= bfd_zmalloc (amt
);
2692 if (htab
->stub_group
== NULL
)
2695 /* We can't use output_bfd->section_count here to find the top output
2696 section index as some sections may have been removed, and
2697 _bfd_strip_section_from_output doesn't renumber the indices. */
2698 for (section
= output_bfd
->sections
, top_index
= 0;
2699 section
!= NULL
; section
= section
->next
)
2701 if (top_index
< section
->index
)
2702 top_index
= section
->index
;
2705 htab
->top_index
= top_index
;
2706 amt
= sizeof (asection
*) * (top_index
+ 1);
2707 input_list
= bfd_malloc (amt
);
2708 htab
->input_list
= input_list
;
2709 if (input_list
== NULL
)
2712 /* For sections we aren't interested in, mark their entries with a
2713 value we can check later. */
2714 list
= input_list
+ top_index
;
2716 *list
= bfd_abs_section_ptr
;
2717 while (list
-- != input_list
);
2719 for (section
= output_bfd
->sections
;
2720 section
!= NULL
; section
= section
->next
)
2722 if ((section
->flags
& SEC_CODE
) != 0)
2723 input_list
[section
->index
] = NULL
;
2729 /* Used by elfNN_aarch64_next_input_section and group_sections. */
2730 #define PREV_SEC(sec) (htab->stub_group[(sec)->id].link_sec)
2732 /* The linker repeatedly calls this function for each input section,
2733 in the order that input sections are linked into output sections.
2734 Build lists of input sections to determine groupings between which
2735 we may insert linker stubs. */
2738 elfNN_aarch64_next_input_section (struct bfd_link_info
*info
, asection
*isec
)
2740 struct elf_aarch64_link_hash_table
*htab
=
2741 elf_aarch64_hash_table (info
);
2743 if (isec
->output_section
->index
<= htab
->top_index
)
2745 asection
**list
= htab
->input_list
+ isec
->output_section
->index
;
2747 if (*list
!= bfd_abs_section_ptr
)
2749 /* Steal the link_sec pointer for our list. */
2750 /* This happens to make the list in reverse order,
2751 which is what we want. */
2752 PREV_SEC (isec
) = *list
;
2758 /* See whether we can group stub sections together. Grouping stub
2759 sections may result in fewer stubs. More importantly, we need to
2760 put all .init* and .fini* stubs at the beginning of the .init or
2761 .fini output sections respectively, because glibc splits the
2762 _init and _fini functions into multiple parts. Putting a stub in
2763 the middle of a function is not a good idea. */
2766 group_sections (struct elf_aarch64_link_hash_table
*htab
,
2767 bfd_size_type stub_group_size
,
2768 bfd_boolean stubs_always_before_branch
)
2770 asection
**list
= htab
->input_list
+ htab
->top_index
;
2774 asection
*tail
= *list
;
2776 if (tail
== bfd_abs_section_ptr
)
2779 while (tail
!= NULL
)
2783 bfd_size_type total
;
2787 while ((prev
= PREV_SEC (curr
)) != NULL
2788 && ((total
+= curr
->output_offset
- prev
->output_offset
)
2792 /* OK, the size from the start of CURR to the end is less
2793 than stub_group_size and thus can be handled by one stub
2794 section. (Or the tail section is itself larger than
2795 stub_group_size, in which case we may be toast.)
2796 We should really be keeping track of the total size of
2797 stubs added here, as stubs contribute to the final output
2801 prev
= PREV_SEC (tail
);
2802 /* Set up this stub group. */
2803 htab
->stub_group
[tail
->id
].link_sec
= curr
;
2805 while (tail
!= curr
&& (tail
= prev
) != NULL
);
2807 /* But wait, there's more! Input sections up to stub_group_size
2808 bytes before the stub section can be handled by it too. */
2809 if (!stubs_always_before_branch
)
2813 && ((total
+= tail
->output_offset
- prev
->output_offset
)
2817 prev
= PREV_SEC (tail
);
2818 htab
->stub_group
[tail
->id
].link_sec
= curr
;
2824 while (list
-- != htab
->input_list
);
2826 free (htab
->input_list
);
2831 #define AARCH64_BITS(x, pos, n) (((x) >> (pos)) & ((1 << (n)) - 1))
2833 #define AARCH64_RT(insn) AARCH64_BITS (insn, 0, 5)
2834 #define AARCH64_RT2(insn) AARCH64_BITS (insn, 10, 5)
2835 #define AARCH64_RA(insn) AARCH64_BITS (insn, 10, 5)
2836 #define AARCH64_RD(insn) AARCH64_BITS (insn, 0, 5)
2837 #define AARCH64_RN(insn) AARCH64_BITS (insn, 5, 5)
2838 #define AARCH64_RM(insn) AARCH64_BITS (insn, 16, 5)
2840 #define AARCH64_MAC(insn) (((insn) & 0xff000000) == 0x9b000000)
2841 #define AARCH64_BIT(insn, n) AARCH64_BITS (insn, n, 1)
2842 #define AARCH64_OP31(insn) AARCH64_BITS (insn, 21, 3)
2843 #define AARCH64_ZR 0x1f
2845 /* All ld/st ops. See C4-182 of the ARM ARM. The encoding space for
2846 LD_PCREL, LDST_RO, LDST_UI and LDST_UIMM cover prefetch ops. */
2848 #define AARCH64_LD(insn) (AARCH64_BIT (insn, 22) == 1)
2849 #define AARCH64_LDST(insn) (((insn) & 0x0a000000) == 0x08000000)
2850 #define AARCH64_LDST_EX(insn) (((insn) & 0x3f000000) == 0x08000000)
2851 #define AARCH64_LDST_PCREL(insn) (((insn) & 0x3b000000) == 0x18000000)
2852 #define AARCH64_LDST_NAP(insn) (((insn) & 0x3b800000) == 0x28000000)
2853 #define AARCH64_LDSTP_PI(insn) (((insn) & 0x3b800000) == 0x28800000)
2854 #define AARCH64_LDSTP_O(insn) (((insn) & 0x3b800000) == 0x29000000)
2855 #define AARCH64_LDSTP_PRE(insn) (((insn) & 0x3b800000) == 0x29800000)
2856 #define AARCH64_LDST_UI(insn) (((insn) & 0x3b200c00) == 0x38000000)
2857 #define AARCH64_LDST_PIIMM(insn) (((insn) & 0x3b200c00) == 0x38000400)
2858 #define AARCH64_LDST_U(insn) (((insn) & 0x3b200c00) == 0x38000800)
2859 #define AARCH64_LDST_PREIMM(insn) (((insn) & 0x3b200c00) == 0x38000c00)
2860 #define AARCH64_LDST_RO(insn) (((insn) & 0x3b200c00) == 0x38200800)
2861 #define AARCH64_LDST_UIMM(insn) (((insn) & 0x3b000000) == 0x39000000)
2862 #define AARCH64_LDST_SIMD_M(insn) (((insn) & 0xbfbf0000) == 0x0c000000)
2863 #define AARCH64_LDST_SIMD_M_PI(insn) (((insn) & 0xbfa00000) == 0x0c800000)
2864 #define AARCH64_LDST_SIMD_S(insn) (((insn) & 0xbf9f0000) == 0x0d000000)
2865 #define AARCH64_LDST_SIMD_S_PI(insn) (((insn) & 0xbf800000) == 0x0d800000)
2867 /* Classify an INSN if it is indeed a load/store.
2869 Return TRUE if INSN is a LD/ST instruction otherwise return FALSE.
2871 For scalar LD/ST instructions PAIR is FALSE, RT is returned and RT2
2874 For LD/ST pair instructions PAIR is TRUE, RT and RT2 are returned.
2879 aarch64_mem_op_p (uint32_t insn
, unsigned int *rt
, unsigned int *rt2
,
2880 bfd_boolean
*pair
, bfd_boolean
*load
)
2888 /* Bail out quickly if INSN doesn't fall into the the load-store
2890 if (!AARCH64_LDST (insn
))
2895 if (AARCH64_LDST_EX (insn
))
2897 *rt
= AARCH64_RT (insn
);
2899 if (AARCH64_BIT (insn
, 21) == 1)
2902 *rt2
= AARCH64_RT2 (insn
);
2904 *load
= AARCH64_LD (insn
);
2907 else if (AARCH64_LDST_NAP (insn
)
2908 || AARCH64_LDSTP_PI (insn
)
2909 || AARCH64_LDSTP_O (insn
)
2910 || AARCH64_LDSTP_PRE (insn
))
2913 *rt
= AARCH64_RT (insn
);
2914 *rt2
= AARCH64_RT2 (insn
);
2915 *load
= AARCH64_LD (insn
);
2918 else if (AARCH64_LDST_PCREL (insn
)
2919 || AARCH64_LDST_UI (insn
)
2920 || AARCH64_LDST_PIIMM (insn
)
2921 || AARCH64_LDST_U (insn
)
2922 || AARCH64_LDST_PREIMM (insn
)
2923 || AARCH64_LDST_RO (insn
)
2924 || AARCH64_LDST_UIMM (insn
))
2926 *rt
= AARCH64_RT (insn
);
2928 if (AARCH64_LDST_PCREL (insn
))
2930 opc
= AARCH64_BITS (insn
, 22, 2);
2931 v
= AARCH64_BIT (insn
, 26);
2932 opc_v
= opc
| (v
<< 2);
2933 *load
= (opc_v
== 1 || opc_v
== 2 || opc_v
== 3
2934 || opc_v
== 5 || opc_v
== 7);
2937 else if (AARCH64_LDST_SIMD_M (insn
)
2938 || AARCH64_LDST_SIMD_M_PI (insn
))
2940 *rt
= AARCH64_RT (insn
);
2941 *load
= AARCH64_BIT (insn
, 22);
2942 opcode
= (insn
>> 12) & 0xf;
2969 else if (AARCH64_LDST_SIMD_S (insn
)
2970 || AARCH64_LDST_SIMD_S_PI (insn
))
2972 *rt
= AARCH64_RT (insn
);
2973 r
= (insn
>> 21) & 1;
2974 *load
= AARCH64_BIT (insn
, 22);
2975 opcode
= (insn
>> 13) & 0x7;
2987 *rt2
= *rt
+ (r
== 0 ? 2 : 3);
2995 *rt2
= *rt
+ (r
== 0 ? 2 : 3);
3007 /* Return TRUE if INSN is multiply-accumulate. */
3010 aarch64_mlxl_p (uint32_t insn
)
3012 uint32_t op31
= AARCH64_OP31 (insn
);
3014 if (AARCH64_MAC (insn
)
3015 && (op31
== 0 || op31
== 1 || op31
== 5)
3016 /* Exclude MUL instructions which are encoded as a multiple accumulate
3018 && AARCH64_RA (insn
) != AARCH64_ZR
)
3024 /* Some early revisions of the Cortex-A53 have an erratum (835769) whereby
3025 it is possible for a 64-bit multiply-accumulate instruction to generate an
3026 incorrect result. The details are quite complex and hard to
3027 determine statically, since branches in the code may exist in some
3028 circumstances, but all cases end with a memory (load, store, or
3029 prefetch) instruction followed immediately by the multiply-accumulate
3030 operation. We employ a linker patching technique, by moving the potentially
3031 affected multiply-accumulate instruction into a patch region and replacing
3032 the original instruction with a branch to the patch. This function checks
3033 if INSN_1 is the memory operation followed by a multiply-accumulate
3034 operation (INSN_2). Return TRUE if an erratum sequence is found, FALSE
3035 if INSN_1 and INSN_2 are safe. */
3038 aarch64_erratum_sequence (uint32_t insn_1
, uint32_t insn_2
)
3048 if (aarch64_mlxl_p (insn_2
)
3049 && aarch64_mem_op_p (insn_1
, &rt
, &rt2
, &pair
, &load
))
3051 /* Any SIMD memory op is independent of the subsequent MLA
3052 by definition of the erratum. */
3053 if (AARCH64_BIT (insn_1
, 26))
3056 /* If not SIMD, check for integer memory ops and MLA relationship. */
3057 rn
= AARCH64_RN (insn_2
);
3058 ra
= AARCH64_RA (insn_2
);
3059 rm
= AARCH64_RM (insn_2
);
3061 /* If this is a load and there's a true(RAW) dependency, we are safe
3062 and this is not an erratum sequence. */
3064 (rt
== rn
|| rt
== rm
|| rt
== ra
3065 || (pair
&& (rt2
== rn
|| rt2
== rm
|| rt2
== ra
))))
3068 /* We conservatively put out stubs for all other cases (including
3076 /* Used to order a list of mapping symbols by address. */
3079 elf_aarch64_compare_mapping (const void *a
, const void *b
)
3081 const elf_aarch64_section_map
*amap
= (const elf_aarch64_section_map
*) a
;
3082 const elf_aarch64_section_map
*bmap
= (const elf_aarch64_section_map
*) b
;
3084 if (amap
->vma
> bmap
->vma
)
3086 else if (amap
->vma
< bmap
->vma
)
3088 else if (amap
->type
> bmap
->type
)
3089 /* Ensure results do not depend on the host qsort for objects with
3090 multiple mapping symbols at the same address by sorting on type
3093 else if (amap
->type
< bmap
->type
)
3101 _bfd_aarch64_erratum_835769_stub_name (unsigned num_fixes
)
3103 char *stub_name
= (char *) bfd_malloc
3104 (strlen ("__erratum_835769_veneer_") + 16);
3105 sprintf (stub_name
,"__erratum_835769_veneer_%d", num_fixes
);
3109 /* Scan for Cortex-A53 erratum 835769 sequence.
3111 Return TRUE else FALSE on abnormal termination. */
3114 _bfd_aarch64_erratum_835769_scan (bfd
*input_bfd
,
3115 struct bfd_link_info
*info
,
3116 unsigned int *num_fixes_p
)
3119 struct elf_aarch64_link_hash_table
*htab
= elf_aarch64_hash_table (info
);
3120 unsigned int num_fixes
= *num_fixes_p
;
3125 for (section
= input_bfd
->sections
;
3127 section
= section
->next
)
3129 bfd_byte
*contents
= NULL
;
3130 struct _aarch64_elf_section_data
*sec_data
;
3133 if (elf_section_type (section
) != SHT_PROGBITS
3134 || (elf_section_flags (section
) & SHF_EXECINSTR
) == 0
3135 || (section
->flags
& SEC_EXCLUDE
) != 0
3136 || (section
->sec_info_type
== SEC_INFO_TYPE_JUST_SYMS
)
3137 || (section
->output_section
== bfd_abs_section_ptr
))
3140 if (elf_section_data (section
)->this_hdr
.contents
!= NULL
)
3141 contents
= elf_section_data (section
)->this_hdr
.contents
;
3142 else if (! bfd_malloc_and_get_section (input_bfd
, section
, &contents
))
3145 sec_data
= elf_aarch64_section_data (section
);
3147 qsort (sec_data
->map
, sec_data
->mapcount
,
3148 sizeof (elf_aarch64_section_map
), elf_aarch64_compare_mapping
);
3150 for (span
= 0; span
< sec_data
->mapcount
; span
++)
3152 unsigned int span_start
= sec_data
->map
[span
].vma
;
3153 unsigned int span_end
= ((span
== sec_data
->mapcount
- 1)
3154 ? sec_data
->map
[0].vma
+ section
->size
3155 : sec_data
->map
[span
+ 1].vma
);
3157 char span_type
= sec_data
->map
[span
].type
;
3159 if (span_type
== 'd')
3162 for (i
= span_start
; i
+ 4 < span_end
; i
+= 4)
3164 uint32_t insn_1
= bfd_getl32 (contents
+ i
);
3165 uint32_t insn_2
= bfd_getl32 (contents
+ i
+ 4);
3167 if (aarch64_erratum_sequence (insn_1
, insn_2
))
3169 struct elf_aarch64_stub_hash_entry
*stub_entry
;
3170 char *stub_name
= _bfd_aarch64_erratum_835769_stub_name (num_fixes
);
3174 stub_entry
= _bfd_aarch64_add_stub_entry_in_group (stub_name
,
3180 stub_entry
->stub_type
= aarch64_stub_erratum_835769_veneer
;
3181 stub_entry
->target_section
= section
;
3182 stub_entry
->target_value
= i
+ 4;
3183 stub_entry
->veneered_insn
= insn_2
;
3184 stub_entry
->output_name
= stub_name
;
3189 if (elf_section_data (section
)->this_hdr
.contents
== NULL
)
3193 *num_fixes_p
= num_fixes
;
3199 /* Test if instruction INSN is ADRP. */
3202 _bfd_aarch64_adrp_p (uint32_t insn
)
3204 return ((insn
& 0x9f000000) == 0x90000000);
3208 /* Helper predicate to look for cortex-a53 erratum 843419 sequence 1. */
3211 _bfd_aarch64_erratum_843419_sequence_p (uint32_t insn_1
, uint32_t insn_2
,
3219 return (aarch64_mem_op_p (insn_2
, &rt
, &rt2
, &pair
, &load
)
3222 && AARCH64_LDST_UIMM (insn_3
)
3223 && AARCH64_RN (insn_3
) == AARCH64_RD (insn_1
));
3227 /* Test for the presence of Cortex-A53 erratum 843419 instruction sequence.
3229 Return TRUE if section CONTENTS at offset I contains one of the
3230 erratum 843419 sequences, otherwise return FALSE. If a sequence is
3231 seen set P_VENEER_I to the offset of the final LOAD/STORE
3232 instruction in the sequence.
3236 _bfd_aarch64_erratum_843419_p (bfd_byte
*contents
, bfd_vma vma
,
3237 bfd_vma i
, bfd_vma span_end
,
3238 bfd_vma
*p_veneer_i
)
3240 uint32_t insn_1
= bfd_getl32 (contents
+ i
);
3242 if (!_bfd_aarch64_adrp_p (insn_1
))
3245 if (span_end
< i
+ 12)
3248 uint32_t insn_2
= bfd_getl32 (contents
+ i
+ 4);
3249 uint32_t insn_3
= bfd_getl32 (contents
+ i
+ 8);
3251 if ((vma
& 0xfff) != 0xff8 && (vma
& 0xfff) != 0xffc)
3254 if (_bfd_aarch64_erratum_843419_sequence_p (insn_1
, insn_2
, insn_3
))
3256 *p_veneer_i
= i
+ 8;
3260 if (span_end
< i
+ 16)
3263 uint32_t insn_4
= bfd_getl32 (contents
+ i
+ 12);
3265 if (_bfd_aarch64_erratum_843419_sequence_p (insn_1
, insn_2
, insn_4
))
3267 *p_veneer_i
= i
+ 12;
3275 /* Resize all stub sections. */
3278 _bfd_aarch64_resize_stubs (struct elf_aarch64_link_hash_table
*htab
)
3282 /* OK, we've added some stubs. Find out the new size of the
3284 for (section
= htab
->stub_bfd
->sections
;
3285 section
!= NULL
; section
= section
->next
)
3287 /* Ignore non-stub sections. */
3288 if (!strstr (section
->name
, STUB_SUFFIX
))
3293 bfd_hash_traverse (&htab
->stub_hash_table
, aarch64_size_one_stub
, htab
);
3295 for (section
= htab
->stub_bfd
->sections
;
3296 section
!= NULL
; section
= section
->next
)
3298 if (!strstr (section
->name
, STUB_SUFFIX
))
3304 /* Ensure all stub sections have a size which is a multiple of
3305 4096. This is important in order to ensure that the insertion
3306 of stub sections does not in itself move existing code around
3307 in such a way that new errata sequences are created. */
3308 if (htab
->fix_erratum_843419
)
3310 section
->size
= BFD_ALIGN (section
->size
, 0x1000);
3315 /* Construct an erratum 843419 workaround stub name.
3319 _bfd_aarch64_erratum_843419_stub_name (asection
*input_section
,
3322 const bfd_size_type len
= 8 + 4 + 1 + 8 + 1 + 16 + 1;
3323 char *stub_name
= bfd_malloc (len
);
3325 if (stub_name
!= NULL
)
3326 snprintf (stub_name
, len
, "e843419@%04x_%08x_%" BFD_VMA_FMT
"x",
3327 input_section
->owner
->id
,
3333 /* Build a stub_entry structure describing an 843419 fixup.
3335 The stub_entry constructed is populated with the bit pattern INSN
3336 of the instruction located at OFFSET within input SECTION.
3338 Returns TRUE on success. */
3341 _bfd_aarch64_erratum_843419_fixup (uint32_t insn
,
3342 bfd_vma adrp_offset
,
3343 bfd_vma ldst_offset
,
3345 struct bfd_link_info
*info
)
3347 struct elf_aarch64_link_hash_table
*htab
= elf_aarch64_hash_table (info
);
3349 struct elf_aarch64_stub_hash_entry
*stub_entry
;
3351 stub_name
= _bfd_aarch64_erratum_843419_stub_name (section
, ldst_offset
);
3352 stub_entry
= aarch64_stub_hash_lookup (&htab
->stub_hash_table
, stub_name
,
3360 /* We always place an 843419 workaround veneer in the stub section
3361 attached to the input section in which an erratum sequence has
3362 been found. This ensures that later in the link process (in
3363 elfNN_aarch64_write_section) when we copy the veneered
3364 instruction from the input section into the stub section the
3365 copied instruction will have had any relocations applied to it.
3366 If we placed workaround veneers in any other stub section then we
3367 could not assume that all relocations have been processed on the
3368 corresponding input section at the point we output the stub
3372 stub_entry
= _bfd_aarch64_add_stub_entry_after (stub_name
, section
, htab
);
3373 if (stub_entry
== NULL
)
3379 stub_entry
->adrp_offset
= adrp_offset
;
3380 stub_entry
->target_value
= ldst_offset
;
3381 stub_entry
->target_section
= section
;
3382 stub_entry
->stub_type
= aarch64_stub_erratum_843419_veneer
;
3383 stub_entry
->veneered_insn
= insn
;
3384 stub_entry
->output_name
= stub_name
;
3390 /* Scan an input section looking for the signature of erratum 843419.
3392 Scans input SECTION in INPUT_BFD looking for erratum 843419
3393 signatures, for each signature found a stub_entry is created
3394 describing the location of the erratum for subsequent fixup.
3396 Return TRUE on successful scan, FALSE on failure to scan.
3400 _bfd_aarch64_erratum_843419_scan (bfd
*input_bfd
, asection
*section
,
3401 struct bfd_link_info
*info
)
3403 struct elf_aarch64_link_hash_table
*htab
= elf_aarch64_hash_table (info
);
3408 if (elf_section_type (section
) != SHT_PROGBITS
3409 || (elf_section_flags (section
) & SHF_EXECINSTR
) == 0
3410 || (section
->flags
& SEC_EXCLUDE
) != 0
3411 || (section
->sec_info_type
== SEC_INFO_TYPE_JUST_SYMS
)
3412 || (section
->output_section
== bfd_abs_section_ptr
))
3417 bfd_byte
*contents
= NULL
;
3418 struct _aarch64_elf_section_data
*sec_data
;
3421 if (elf_section_data (section
)->this_hdr
.contents
!= NULL
)
3422 contents
= elf_section_data (section
)->this_hdr
.contents
;
3423 else if (! bfd_malloc_and_get_section (input_bfd
, section
, &contents
))
3426 sec_data
= elf_aarch64_section_data (section
);
3428 qsort (sec_data
->map
, sec_data
->mapcount
,
3429 sizeof (elf_aarch64_section_map
), elf_aarch64_compare_mapping
);
3431 for (span
= 0; span
< sec_data
->mapcount
; span
++)
3433 unsigned int span_start
= sec_data
->map
[span
].vma
;
3434 unsigned int span_end
= ((span
== sec_data
->mapcount
- 1)
3435 ? sec_data
->map
[0].vma
+ section
->size
3436 : sec_data
->map
[span
+ 1].vma
);
3438 char span_type
= sec_data
->map
[span
].type
;
3440 if (span_type
== 'd')
3443 for (i
= span_start
; i
+ 8 < span_end
; i
+= 4)
3445 bfd_vma vma
= (section
->output_section
->vma
3446 + section
->output_offset
3450 if (_bfd_aarch64_erratum_843419_p
3451 (contents
, vma
, i
, span_end
, &veneer_i
))
3453 uint32_t insn
= bfd_getl32 (contents
+ veneer_i
);
3455 if (!_bfd_aarch64_erratum_843419_fixup (insn
, i
, veneer_i
,
3462 if (elf_section_data (section
)->this_hdr
.contents
== NULL
)
3471 /* Determine and set the size of the stub section for a final link.
3473 The basic idea here is to examine all the relocations looking for
3474 PC-relative calls to a target that is unreachable with a "bl"
3478 elfNN_aarch64_size_stubs (bfd
*output_bfd
,
3480 struct bfd_link_info
*info
,
3481 bfd_signed_vma group_size
,
3482 asection
* (*add_stub_section
) (const char *,
3484 void (*layout_sections_again
) (void))
3486 bfd_size_type stub_group_size
;
3487 bfd_boolean stubs_always_before_branch
;
3488 bfd_boolean stub_changed
= FALSE
;
3489 struct elf_aarch64_link_hash_table
*htab
= elf_aarch64_hash_table (info
);
3490 unsigned int num_erratum_835769_fixes
= 0;
3492 /* Propagate mach to stub bfd, because it may not have been
3493 finalized when we created stub_bfd. */
3494 bfd_set_arch_mach (stub_bfd
, bfd_get_arch (output_bfd
),
3495 bfd_get_mach (output_bfd
));
3497 /* Stash our params away. */
3498 htab
->stub_bfd
= stub_bfd
;
3499 htab
->add_stub_section
= add_stub_section
;
3500 htab
->layout_sections_again
= layout_sections_again
;
3501 stubs_always_before_branch
= group_size
< 0;
3503 stub_group_size
= -group_size
;
3505 stub_group_size
= group_size
;
3507 if (stub_group_size
== 1)
3509 /* Default values. */
3510 /* AArch64 branch range is +-128MB. The value used is 1MB less. */
3511 stub_group_size
= 127 * 1024 * 1024;
3514 group_sections (htab
, stub_group_size
, stubs_always_before_branch
);
3516 (*htab
->layout_sections_again
) ();
3518 if (htab
->fix_erratum_835769
)
3522 for (input_bfd
= info
->input_bfds
;
3523 input_bfd
!= NULL
; input_bfd
= input_bfd
->link
.next
)
3524 if (!_bfd_aarch64_erratum_835769_scan (input_bfd
, info
,
3525 &num_erratum_835769_fixes
))
3528 _bfd_aarch64_resize_stubs (htab
);
3529 (*htab
->layout_sections_again
) ();
3532 if (htab
->fix_erratum_843419
)
3536 for (input_bfd
= info
->input_bfds
;
3538 input_bfd
= input_bfd
->link
.next
)
3542 for (section
= input_bfd
->sections
;
3544 section
= section
->next
)
3545 if (!_bfd_aarch64_erratum_843419_scan (input_bfd
, section
, info
))
3549 _bfd_aarch64_resize_stubs (htab
);
3550 (*htab
->layout_sections_again
) ();
3557 for (input_bfd
= info
->input_bfds
;
3558 input_bfd
!= NULL
; input_bfd
= input_bfd
->link
.next
)
3560 Elf_Internal_Shdr
*symtab_hdr
;
3562 Elf_Internal_Sym
*local_syms
= NULL
;
3564 /* We'll need the symbol table in a second. */
3565 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
3566 if (symtab_hdr
->sh_info
== 0)
3569 /* Walk over each section attached to the input bfd. */
3570 for (section
= input_bfd
->sections
;
3571 section
!= NULL
; section
= section
->next
)
3573 Elf_Internal_Rela
*internal_relocs
, *irelaend
, *irela
;
3575 /* If there aren't any relocs, then there's nothing more
3577 if ((section
->flags
& SEC_RELOC
) == 0
3578 || section
->reloc_count
== 0
3579 || (section
->flags
& SEC_CODE
) == 0)
3582 /* If this section is a link-once section that will be
3583 discarded, then don't create any stubs. */
3584 if (section
->output_section
== NULL
3585 || section
->output_section
->owner
!= output_bfd
)
3588 /* Get the relocs. */
3590 = _bfd_elf_link_read_relocs (input_bfd
, section
, NULL
,
3591 NULL
, info
->keep_memory
);
3592 if (internal_relocs
== NULL
)
3593 goto error_ret_free_local
;
3595 /* Now examine each relocation. */
3596 irela
= internal_relocs
;
3597 irelaend
= irela
+ section
->reloc_count
;
3598 for (; irela
< irelaend
; irela
++)
3600 unsigned int r_type
, r_indx
;
3601 enum elf_aarch64_stub_type stub_type
;
3602 struct elf_aarch64_stub_hash_entry
*stub_entry
;
3605 bfd_vma destination
;
3606 struct elf_aarch64_link_hash_entry
*hash
;
3607 const char *sym_name
;
3609 const asection
*id_sec
;
3610 unsigned char st_type
;
3613 r_type
= ELFNN_R_TYPE (irela
->r_info
);
3614 r_indx
= ELFNN_R_SYM (irela
->r_info
);
3616 if (r_type
>= (unsigned int) R_AARCH64_end
)
3618 bfd_set_error (bfd_error_bad_value
);
3619 error_ret_free_internal
:
3620 if (elf_section_data (section
)->relocs
== NULL
)
3621 free (internal_relocs
);
3622 goto error_ret_free_local
;
3625 /* Only look for stubs on unconditional branch and
3626 branch and link instructions. */
3627 if (r_type
!= (unsigned int) AARCH64_R (CALL26
)
3628 && r_type
!= (unsigned int) AARCH64_R (JUMP26
))
3631 /* Now determine the call target, its name, value,
3638 if (r_indx
< symtab_hdr
->sh_info
)
3640 /* It's a local symbol. */
3641 Elf_Internal_Sym
*sym
;
3642 Elf_Internal_Shdr
*hdr
;
3644 if (local_syms
== NULL
)
3647 = (Elf_Internal_Sym
*) symtab_hdr
->contents
;
3648 if (local_syms
== NULL
)
3650 = bfd_elf_get_elf_syms (input_bfd
, symtab_hdr
,
3651 symtab_hdr
->sh_info
, 0,
3653 if (local_syms
== NULL
)
3654 goto error_ret_free_internal
;
3657 sym
= local_syms
+ r_indx
;
3658 hdr
= elf_elfsections (input_bfd
)[sym
->st_shndx
];
3659 sym_sec
= hdr
->bfd_section
;
3661 /* This is an undefined symbol. It can never
3665 if (ELF_ST_TYPE (sym
->st_info
) != STT_SECTION
)
3666 sym_value
= sym
->st_value
;
3667 destination
= (sym_value
+ irela
->r_addend
3668 + sym_sec
->output_offset
3669 + sym_sec
->output_section
->vma
);
3670 st_type
= ELF_ST_TYPE (sym
->st_info
);
3672 = bfd_elf_string_from_elf_section (input_bfd
,
3673 symtab_hdr
->sh_link
,
3680 e_indx
= r_indx
- symtab_hdr
->sh_info
;
3681 hash
= ((struct elf_aarch64_link_hash_entry
*)
3682 elf_sym_hashes (input_bfd
)[e_indx
]);
3684 while (hash
->root
.root
.type
== bfd_link_hash_indirect
3685 || hash
->root
.root
.type
== bfd_link_hash_warning
)
3686 hash
= ((struct elf_aarch64_link_hash_entry
*)
3687 hash
->root
.root
.u
.i
.link
);
3689 if (hash
->root
.root
.type
== bfd_link_hash_defined
3690 || hash
->root
.root
.type
== bfd_link_hash_defweak
)
3692 struct elf_aarch64_link_hash_table
*globals
=
3693 elf_aarch64_hash_table (info
);
3694 sym_sec
= hash
->root
.root
.u
.def
.section
;
3695 sym_value
= hash
->root
.root
.u
.def
.value
;
3696 /* For a destination in a shared library,
3697 use the PLT stub as target address to
3698 decide whether a branch stub is
3700 if (globals
->root
.splt
!= NULL
&& hash
!= NULL
3701 && hash
->root
.plt
.offset
!= (bfd_vma
) - 1)
3703 sym_sec
= globals
->root
.splt
;
3704 sym_value
= hash
->root
.plt
.offset
;
3705 if (sym_sec
->output_section
!= NULL
)
3706 destination
= (sym_value
3707 + sym_sec
->output_offset
3709 sym_sec
->output_section
->vma
);
3711 else if (sym_sec
->output_section
!= NULL
)
3712 destination
= (sym_value
+ irela
->r_addend
3713 + sym_sec
->output_offset
3714 + sym_sec
->output_section
->vma
);
3716 else if (hash
->root
.root
.type
== bfd_link_hash_undefined
3717 || (hash
->root
.root
.type
3718 == bfd_link_hash_undefweak
))
3720 /* For a shared library, use the PLT stub as
3721 target address to decide whether a long
3722 branch stub is needed.
3723 For absolute code, they cannot be handled. */
3724 struct elf_aarch64_link_hash_table
*globals
=
3725 elf_aarch64_hash_table (info
);
3727 if (globals
->root
.splt
!= NULL
&& hash
!= NULL
3728 && hash
->root
.plt
.offset
!= (bfd_vma
) - 1)
3730 sym_sec
= globals
->root
.splt
;
3731 sym_value
= hash
->root
.plt
.offset
;
3732 if (sym_sec
->output_section
!= NULL
)
3733 destination
= (sym_value
3734 + sym_sec
->output_offset
3736 sym_sec
->output_section
->vma
);
3743 bfd_set_error (bfd_error_bad_value
);
3744 goto error_ret_free_internal
;
3746 st_type
= ELF_ST_TYPE (hash
->root
.type
);
3747 sym_name
= hash
->root
.root
.root
.string
;
3750 /* Determine what (if any) linker stub is needed. */
3751 stub_type
= aarch64_type_of_stub
3752 (info
, section
, irela
, st_type
, hash
, destination
);
3753 if (stub_type
== aarch64_stub_none
)
3756 /* Support for grouping stub sections. */
3757 id_sec
= htab
->stub_group
[section
->id
].link_sec
;
3759 /* Get the name of this stub. */
3760 stub_name
= elfNN_aarch64_stub_name (id_sec
, sym_sec
, hash
,
3763 goto error_ret_free_internal
;
3766 aarch64_stub_hash_lookup (&htab
->stub_hash_table
,
3767 stub_name
, FALSE
, FALSE
);
3768 if (stub_entry
!= NULL
)
3770 /* The proper stub has already been created. */
3775 stub_entry
= _bfd_aarch64_add_stub_entry_in_group
3776 (stub_name
, section
, htab
);
3777 if (stub_entry
== NULL
)
3780 goto error_ret_free_internal
;
3783 stub_entry
->target_value
= sym_value
;
3784 stub_entry
->target_section
= sym_sec
;
3785 stub_entry
->stub_type
= stub_type
;
3786 stub_entry
->h
= hash
;
3787 stub_entry
->st_type
= st_type
;
3789 if (sym_name
== NULL
)
3790 sym_name
= "unnamed";
3791 len
= sizeof (STUB_ENTRY_NAME
) + strlen (sym_name
);
3792 stub_entry
->output_name
= bfd_alloc (htab
->stub_bfd
, len
);
3793 if (stub_entry
->output_name
== NULL
)
3796 goto error_ret_free_internal
;
3799 snprintf (stub_entry
->output_name
, len
, STUB_ENTRY_NAME
,
3802 stub_changed
= TRUE
;
3805 /* We're done with the internal relocs, free them. */
3806 if (elf_section_data (section
)->relocs
== NULL
)
3807 free (internal_relocs
);
3814 _bfd_aarch64_resize_stubs (htab
);
3816 /* Ask the linker to do its stuff. */
3817 (*htab
->layout_sections_again
) ();
3818 stub_changed
= FALSE
;
3823 error_ret_free_local
:
3827 /* Build all the stubs associated with the current output file. The
3828 stubs are kept in a hash table attached to the main linker hash
3829 table. We also set up the .plt entries for statically linked PIC
3830 functions here. This function is called via aarch64_elf_finish in the
3834 elfNN_aarch64_build_stubs (struct bfd_link_info
*info
)
3837 struct bfd_hash_table
*table
;
3838 struct elf_aarch64_link_hash_table
*htab
;
3840 htab
= elf_aarch64_hash_table (info
);
3842 for (stub_sec
= htab
->stub_bfd
->sections
;
3843 stub_sec
!= NULL
; stub_sec
= stub_sec
->next
)
3847 /* Ignore non-stub sections. */
3848 if (!strstr (stub_sec
->name
, STUB_SUFFIX
))
3851 /* Allocate memory to hold the linker stubs. */
3852 size
= stub_sec
->size
;
3853 stub_sec
->contents
= bfd_zalloc (htab
->stub_bfd
, size
);
3854 if (stub_sec
->contents
== NULL
&& size
!= 0)
3858 bfd_putl32 (0x14000000 | (size
>> 2), stub_sec
->contents
);
3859 stub_sec
->size
+= 4;
3862 /* Build the stubs as directed by the stub hash table. */
3863 table
= &htab
->stub_hash_table
;
3864 bfd_hash_traverse (table
, aarch64_build_one_stub
, info
);
3870 /* Add an entry to the code/data map for section SEC. */
3873 elfNN_aarch64_section_map_add (asection
*sec
, char type
, bfd_vma vma
)
3875 struct _aarch64_elf_section_data
*sec_data
=
3876 elf_aarch64_section_data (sec
);
3877 unsigned int newidx
;
3879 if (sec_data
->map
== NULL
)
3881 sec_data
->map
= bfd_malloc (sizeof (elf_aarch64_section_map
));
3882 sec_data
->mapcount
= 0;
3883 sec_data
->mapsize
= 1;
3886 newidx
= sec_data
->mapcount
++;
3888 if (sec_data
->mapcount
> sec_data
->mapsize
)
3890 sec_data
->mapsize
*= 2;
3891 sec_data
->map
= bfd_realloc_or_free
3892 (sec_data
->map
, sec_data
->mapsize
* sizeof (elf_aarch64_section_map
));
3897 sec_data
->map
[newidx
].vma
= vma
;
3898 sec_data
->map
[newidx
].type
= type
;
3903 /* Initialise maps of insn/data for input BFDs. */
3905 bfd_elfNN_aarch64_init_maps (bfd
*abfd
)
3907 Elf_Internal_Sym
*isymbuf
;
3908 Elf_Internal_Shdr
*hdr
;
3909 unsigned int i
, localsyms
;
3911 /* Make sure that we are dealing with an AArch64 elf binary. */
3912 if (!is_aarch64_elf (abfd
))
3915 if ((abfd
->flags
& DYNAMIC
) != 0)
3918 hdr
= &elf_symtab_hdr (abfd
);
3919 localsyms
= hdr
->sh_info
;
3921 /* Obtain a buffer full of symbols for this BFD. The hdr->sh_info field
3922 should contain the number of local symbols, which should come before any
3923 global symbols. Mapping symbols are always local. */
3924 isymbuf
= bfd_elf_get_elf_syms (abfd
, hdr
, localsyms
, 0, NULL
, NULL
, NULL
);
3926 /* No internal symbols read? Skip this BFD. */
3927 if (isymbuf
== NULL
)
3930 for (i
= 0; i
< localsyms
; i
++)
3932 Elf_Internal_Sym
*isym
= &isymbuf
[i
];
3933 asection
*sec
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
3936 if (sec
!= NULL
&& ELF_ST_BIND (isym
->st_info
) == STB_LOCAL
)
3938 name
= bfd_elf_string_from_elf_section (abfd
,
3942 if (bfd_is_aarch64_special_symbol_name
3943 (name
, BFD_AARCH64_SPECIAL_SYM_TYPE_MAP
))
3944 elfNN_aarch64_section_map_add (sec
, name
[1], isym
->st_value
);
3949 /* Set option values needed during linking. */
3951 bfd_elfNN_aarch64_set_options (struct bfd
*output_bfd
,
3952 struct bfd_link_info
*link_info
,
3954 int no_wchar_warn
, int pic_veneer
,
3955 int fix_erratum_835769
,
3956 int fix_erratum_843419
)
3958 struct elf_aarch64_link_hash_table
*globals
;
3960 globals
= elf_aarch64_hash_table (link_info
);
3961 globals
->pic_veneer
= pic_veneer
;
3962 globals
->fix_erratum_835769
= fix_erratum_835769
;
3963 globals
->fix_erratum_843419
= fix_erratum_843419
;
3964 globals
->fix_erratum_843419_adr
= TRUE
;
3966 BFD_ASSERT (is_aarch64_elf (output_bfd
));
3967 elf_aarch64_tdata (output_bfd
)->no_enum_size_warning
= no_enum_warn
;
3968 elf_aarch64_tdata (output_bfd
)->no_wchar_size_warning
= no_wchar_warn
;
3972 aarch64_calculate_got_entry_vma (struct elf_link_hash_entry
*h
,
3973 struct elf_aarch64_link_hash_table
3974 *globals
, struct bfd_link_info
*info
,
3975 bfd_vma value
, bfd
*output_bfd
,
3976 bfd_boolean
*unresolved_reloc_p
)
3978 bfd_vma off
= (bfd_vma
) - 1;
3979 asection
*basegot
= globals
->root
.sgot
;
3980 bfd_boolean dyn
= globals
->root
.dynamic_sections_created
;
3984 BFD_ASSERT (basegot
!= NULL
);
3985 off
= h
->got
.offset
;
3986 BFD_ASSERT (off
!= (bfd_vma
) - 1);
3987 if (!WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, info
->shared
, h
)
3989 && SYMBOL_REFERENCES_LOCAL (info
, h
))
3990 || (ELF_ST_VISIBILITY (h
->other
)
3991 && h
->root
.type
== bfd_link_hash_undefweak
))
3993 /* This is actually a static link, or it is a -Bsymbolic link
3994 and the symbol is defined locally. We must initialize this
3995 entry in the global offset table. Since the offset must
3996 always be a multiple of 8 (4 in the case of ILP32), we use
3997 the least significant bit to record whether we have
3998 initialized it already.
3999 When doing a dynamic link, we create a .rel(a).got relocation
4000 entry to initialize the value. This is done in the
4001 finish_dynamic_symbol routine. */
4006 bfd_put_NN (output_bfd
, value
, basegot
->contents
+ off
);
4011 *unresolved_reloc_p
= FALSE
;
4013 off
= off
+ basegot
->output_section
->vma
+ basegot
->output_offset
;
4019 /* Change R_TYPE to a more efficient access model where possible,
4020 return the new reloc type. */
4022 static bfd_reloc_code_real_type
4023 aarch64_tls_transition_without_check (bfd_reloc_code_real_type r_type
,
4024 struct elf_link_hash_entry
*h
)
4026 bfd_boolean is_local
= h
== NULL
;
4030 case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21
:
4031 case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21
:
4033 ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1
4034 : BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21
);
4036 case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21
:
4038 ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC
4041 case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19
:
4043 ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1
4044 : BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19
);
4046 case BFD_RELOC_AARCH64_TLSDESC_LDNN_LO12_NC
:
4047 case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC
:
4049 ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC
4050 : BFD_RELOC_AARCH64_TLSIE_LDNN_GOTTPREL_LO12_NC
);
4052 case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21
:
4053 return is_local
? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1
: r_type
;
4055 case BFD_RELOC_AARCH64_TLSIE_LDNN_GOTTPREL_LO12_NC
:
4056 return is_local
? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC
: r_type
;
4058 case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19
:
4061 case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21
:
4063 ? BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_HI12
4064 : BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19
);
4066 case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12_NC
:
4067 case BFD_RELOC_AARCH64_TLSDESC_CALL
:
4068 /* Instructions with these relocations will become NOPs. */
4069 return BFD_RELOC_AARCH64_NONE
;
4079 aarch64_reloc_got_type (bfd_reloc_code_real_type r_type
)
4083 case BFD_RELOC_AARCH64_ADR_GOT_PAGE
:
4084 case BFD_RELOC_AARCH64_GOT_LD_PREL19
:
4085 case BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14
:
4086 case BFD_RELOC_AARCH64_LD32_GOT_LO12_NC
:
4087 case BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15
:
4088 case BFD_RELOC_AARCH64_LD64_GOT_LO12_NC
:
4091 case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC
:
4092 case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21
:
4093 case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21
:
4096 case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12_NC
:
4097 case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21
:
4098 case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21
:
4099 case BFD_RELOC_AARCH64_TLSDESC_CALL
:
4100 case BFD_RELOC_AARCH64_TLSDESC_LD32_LO12_NC
:
4101 case BFD_RELOC_AARCH64_TLSDESC_LD64_LO12_NC
:
4102 case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19
:
4103 return GOT_TLSDESC_GD
;
4105 case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21
:
4106 case BFD_RELOC_AARCH64_TLSIE_LD32_GOTTPREL_LO12_NC
:
4107 case BFD_RELOC_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC
:
4108 case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19
:
4111 case BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_HI12
:
4112 case BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_LO12
:
4113 case BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_LO12_NC
:
4114 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0
:
4115 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC
:
4116 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1
:
4117 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1_NC
:
4118 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G2
:
4128 aarch64_can_relax_tls (bfd
*input_bfd
,
4129 struct bfd_link_info
*info
,
4130 bfd_reloc_code_real_type r_type
,
4131 struct elf_link_hash_entry
*h
,
4132 unsigned long r_symndx
)
4134 unsigned int symbol_got_type
;
4135 unsigned int reloc_got_type
;
4137 if (! IS_AARCH64_TLS_RELOC (r_type
))
4140 symbol_got_type
= elfNN_aarch64_symbol_got_type (h
, input_bfd
, r_symndx
);
4141 reloc_got_type
= aarch64_reloc_got_type (r_type
);
4143 if (symbol_got_type
== GOT_TLS_IE
&& GOT_TLS_GD_ANY_P (reloc_got_type
))
4149 if (h
&& h
->root
.type
== bfd_link_hash_undefweak
)
4155 /* Given the relocation code R_TYPE, return the relaxed bfd reloc
4158 static bfd_reloc_code_real_type
4159 aarch64_tls_transition (bfd
*input_bfd
,
4160 struct bfd_link_info
*info
,
4161 unsigned int r_type
,
4162 struct elf_link_hash_entry
*h
,
4163 unsigned long r_symndx
)
4165 bfd_reloc_code_real_type bfd_r_type
4166 = elfNN_aarch64_bfd_reloc_from_type (r_type
);
4168 if (! aarch64_can_relax_tls (input_bfd
, info
, bfd_r_type
, h
, r_symndx
))
4171 return aarch64_tls_transition_without_check (bfd_r_type
, h
);
4174 /* Return the base VMA address which should be subtracted from real addresses
4175 when resolving R_AARCH64_TLS_DTPREL relocation. */
4178 dtpoff_base (struct bfd_link_info
*info
)
4180 /* If tls_sec is NULL, we should have signalled an error already. */
4181 BFD_ASSERT (elf_hash_table (info
)->tls_sec
!= NULL
);
4182 return elf_hash_table (info
)->tls_sec
->vma
;
4185 /* Return the base VMA address which should be subtracted from real addresses
4186 when resolving R_AARCH64_TLS_GOTTPREL64 relocations. */
4189 tpoff_base (struct bfd_link_info
*info
)
4191 struct elf_link_hash_table
*htab
= elf_hash_table (info
);
4193 /* If tls_sec is NULL, we should have signalled an error already. */
4194 BFD_ASSERT (htab
->tls_sec
!= NULL
);
4196 bfd_vma base
= align_power ((bfd_vma
) TCB_SIZE
,
4197 htab
->tls_sec
->alignment_power
);
4198 return htab
->tls_sec
->vma
- base
;
4202 symbol_got_offset_ref (bfd
*input_bfd
, struct elf_link_hash_entry
*h
,
4203 unsigned long r_symndx
)
4205 /* Calculate the address of the GOT entry for symbol
4206 referred to in h. */
4208 return &h
->got
.offset
;
4212 struct elf_aarch64_local_symbol
*l
;
4214 l
= elf_aarch64_locals (input_bfd
);
4215 return &l
[r_symndx
].got_offset
;
4220 symbol_got_offset_mark (bfd
*input_bfd
, struct elf_link_hash_entry
*h
,
4221 unsigned long r_symndx
)
4224 p
= symbol_got_offset_ref (input_bfd
, h
, r_symndx
);
4229 symbol_got_offset_mark_p (bfd
*input_bfd
, struct elf_link_hash_entry
*h
,
4230 unsigned long r_symndx
)
4233 value
= * symbol_got_offset_ref (input_bfd
, h
, r_symndx
);
4238 symbol_got_offset (bfd
*input_bfd
, struct elf_link_hash_entry
*h
,
4239 unsigned long r_symndx
)
4242 value
= * symbol_got_offset_ref (input_bfd
, h
, r_symndx
);
4248 symbol_tlsdesc_got_offset_ref (bfd
*input_bfd
, struct elf_link_hash_entry
*h
,
4249 unsigned long r_symndx
)
4251 /* Calculate the address of the GOT entry for symbol
4252 referred to in h. */
4255 struct elf_aarch64_link_hash_entry
*eh
;
4256 eh
= (struct elf_aarch64_link_hash_entry
*) h
;
4257 return &eh
->tlsdesc_got_jump_table_offset
;
4262 struct elf_aarch64_local_symbol
*l
;
4264 l
= elf_aarch64_locals (input_bfd
);
4265 return &l
[r_symndx
].tlsdesc_got_jump_table_offset
;
4270 symbol_tlsdesc_got_offset_mark (bfd
*input_bfd
, struct elf_link_hash_entry
*h
,
4271 unsigned long r_symndx
)
4274 p
= symbol_tlsdesc_got_offset_ref (input_bfd
, h
, r_symndx
);
4279 symbol_tlsdesc_got_offset_mark_p (bfd
*input_bfd
,
4280 struct elf_link_hash_entry
*h
,
4281 unsigned long r_symndx
)
4284 value
= * symbol_tlsdesc_got_offset_ref (input_bfd
, h
, r_symndx
);
4289 symbol_tlsdesc_got_offset (bfd
*input_bfd
, struct elf_link_hash_entry
*h
,
4290 unsigned long r_symndx
)
4293 value
= * symbol_tlsdesc_got_offset_ref (input_bfd
, h
, r_symndx
);
4298 /* Data for make_branch_to_erratum_835769_stub(). */
4300 struct erratum_835769_branch_to_stub_data
4302 struct bfd_link_info
*info
;
4303 asection
*output_section
;
4307 /* Helper to insert branches to erratum 835769 stubs in the right
4308 places for a particular section. */
4311 make_branch_to_erratum_835769_stub (struct bfd_hash_entry
*gen_entry
,
4314 struct elf_aarch64_stub_hash_entry
*stub_entry
;
4315 struct erratum_835769_branch_to_stub_data
*data
;
4317 unsigned long branch_insn
= 0;
4318 bfd_vma veneered_insn_loc
, veneer_entry_loc
;
4319 bfd_signed_vma branch_offset
;
4320 unsigned int target
;
4323 stub_entry
= (struct elf_aarch64_stub_hash_entry
*) gen_entry
;
4324 data
= (struct erratum_835769_branch_to_stub_data
*) in_arg
;
4326 if (stub_entry
->target_section
!= data
->output_section
4327 || stub_entry
->stub_type
!= aarch64_stub_erratum_835769_veneer
)
4330 contents
= data
->contents
;
4331 veneered_insn_loc
= stub_entry
->target_section
->output_section
->vma
4332 + stub_entry
->target_section
->output_offset
4333 + stub_entry
->target_value
;
4334 veneer_entry_loc
= stub_entry
->stub_sec
->output_section
->vma
4335 + stub_entry
->stub_sec
->output_offset
4336 + stub_entry
->stub_offset
;
4337 branch_offset
= veneer_entry_loc
- veneered_insn_loc
;
4339 abfd
= stub_entry
->target_section
->owner
;
4340 if (!aarch64_valid_branch_p (veneer_entry_loc
, veneered_insn_loc
))
4341 (*_bfd_error_handler
)
4342 (_("%B: error: Erratum 835769 stub out "
4343 "of range (input file too large)"), abfd
);
4345 target
= stub_entry
->target_value
;
4346 branch_insn
= 0x14000000;
4347 branch_offset
>>= 2;
4348 branch_offset
&= 0x3ffffff;
4349 branch_insn
|= branch_offset
;
4350 bfd_putl32 (branch_insn
, &contents
[target
]);
4357 _bfd_aarch64_erratum_843419_branch_to_stub (struct bfd_hash_entry
*gen_entry
,
4360 struct elf_aarch64_stub_hash_entry
*stub_entry
4361 = (struct elf_aarch64_stub_hash_entry
*) gen_entry
;
4362 struct erratum_835769_branch_to_stub_data
*data
4363 = (struct erratum_835769_branch_to_stub_data
*) in_arg
;
4364 struct bfd_link_info
*info
;
4365 struct elf_aarch64_link_hash_table
*htab
;
4373 contents
= data
->contents
;
4374 section
= data
->output_section
;
4376 htab
= elf_aarch64_hash_table (info
);
4378 if (stub_entry
->target_section
!= section
4379 || stub_entry
->stub_type
!= aarch64_stub_erratum_843419_veneer
)
4382 insn
= bfd_getl32 (contents
+ stub_entry
->target_value
);
4384 stub_entry
->stub_sec
->contents
+ stub_entry
->stub_offset
);
4386 place
= (section
->output_section
->vma
+ section
->output_offset
4387 + stub_entry
->adrp_offset
);
4388 insn
= bfd_getl32 (contents
+ stub_entry
->adrp_offset
);
4390 if ((insn
& AARCH64_ADRP_OP_MASK
) != AARCH64_ADRP_OP
)
4393 bfd_signed_vma imm
=
4394 (_bfd_aarch64_sign_extend
4395 ((bfd_vma
) _bfd_aarch64_decode_adrp_imm (insn
) << 12, 33)
4398 if (htab
->fix_erratum_843419_adr
4399 && (imm
>= AARCH64_MIN_ADRP_IMM
&& imm
<= AARCH64_MAX_ADRP_IMM
))
4401 insn
= (_bfd_aarch64_reencode_adr_imm (AARCH64_ADR_OP
, imm
)
4402 | AARCH64_RT (insn
));
4403 bfd_putl32 (insn
, contents
+ stub_entry
->adrp_offset
);
4407 bfd_vma veneered_insn_loc
;
4408 bfd_vma veneer_entry_loc
;
4409 bfd_signed_vma branch_offset
;
4410 uint32_t branch_insn
;
4412 veneered_insn_loc
= stub_entry
->target_section
->output_section
->vma
4413 + stub_entry
->target_section
->output_offset
4414 + stub_entry
->target_value
;
4415 veneer_entry_loc
= stub_entry
->stub_sec
->output_section
->vma
4416 + stub_entry
->stub_sec
->output_offset
4417 + stub_entry
->stub_offset
;
4418 branch_offset
= veneer_entry_loc
- veneered_insn_loc
;
4420 abfd
= stub_entry
->target_section
->owner
;
4421 if (!aarch64_valid_branch_p (veneer_entry_loc
, veneered_insn_loc
))
4422 (*_bfd_error_handler
)
4423 (_("%B: error: Erratum 843419 stub out "
4424 "of range (input file too large)"), abfd
);
4426 branch_insn
= 0x14000000;
4427 branch_offset
>>= 2;
4428 branch_offset
&= 0x3ffffff;
4429 branch_insn
|= branch_offset
;
4430 bfd_putl32 (branch_insn
, contents
+ stub_entry
->target_value
);
4437 elfNN_aarch64_write_section (bfd
*output_bfd ATTRIBUTE_UNUSED
,
4438 struct bfd_link_info
*link_info
,
4443 struct elf_aarch64_link_hash_table
*globals
=
4444 elf_aarch64_hash_table (link_info
);
4446 if (globals
== NULL
)
4449 /* Fix code to point to erratum 835769 stubs. */
4450 if (globals
->fix_erratum_835769
)
4452 struct erratum_835769_branch_to_stub_data data
;
4454 data
.info
= link_info
;
4455 data
.output_section
= sec
;
4456 data
.contents
= contents
;
4457 bfd_hash_traverse (&globals
->stub_hash_table
,
4458 make_branch_to_erratum_835769_stub
, &data
);
4461 if (globals
->fix_erratum_843419
)
4463 struct erratum_835769_branch_to_stub_data data
;
4465 data
.info
= link_info
;
4466 data
.output_section
= sec
;
4467 data
.contents
= contents
;
4468 bfd_hash_traverse (&globals
->stub_hash_table
,
4469 _bfd_aarch64_erratum_843419_branch_to_stub
, &data
);
4475 /* Perform a relocation as part of a final link. */
4476 static bfd_reloc_status_type
4477 elfNN_aarch64_final_link_relocate (reloc_howto_type
*howto
,
4480 asection
*input_section
,
4482 Elf_Internal_Rela
*rel
,
4484 struct bfd_link_info
*info
,
4486 struct elf_link_hash_entry
*h
,
4487 bfd_boolean
*unresolved_reloc_p
,
4488 bfd_boolean save_addend
,
4489 bfd_vma
*saved_addend
,
4490 Elf_Internal_Sym
*sym
)
4492 Elf_Internal_Shdr
*symtab_hdr
;
4493 unsigned int r_type
= howto
->type
;
4494 bfd_reloc_code_real_type bfd_r_type
4495 = elfNN_aarch64_bfd_reloc_from_howto (howto
);
4496 bfd_reloc_code_real_type new_bfd_r_type
;
4497 unsigned long r_symndx
;
4498 bfd_byte
*hit_data
= contents
+ rel
->r_offset
;
4500 bfd_signed_vma signed_addend
;
4501 struct elf_aarch64_link_hash_table
*globals
;
4502 bfd_boolean weak_undef_p
;
4505 globals
= elf_aarch64_hash_table (info
);
4507 symtab_hdr
= &elf_symtab_hdr (input_bfd
);
4509 BFD_ASSERT (is_aarch64_elf (input_bfd
));
4511 r_symndx
= ELFNN_R_SYM (rel
->r_info
);
4513 /* It is possible to have linker relaxations on some TLS access
4514 models. Update our information here. */
4515 new_bfd_r_type
= aarch64_tls_transition (input_bfd
, info
, r_type
, h
, r_symndx
);
4516 if (new_bfd_r_type
!= bfd_r_type
)
4518 bfd_r_type
= new_bfd_r_type
;
4519 howto
= elfNN_aarch64_howto_from_bfd_reloc (bfd_r_type
);
4520 BFD_ASSERT (howto
!= NULL
);
4521 r_type
= howto
->type
;
4524 place
= input_section
->output_section
->vma
4525 + input_section
->output_offset
+ rel
->r_offset
;
4527 /* Get addend, accumulating the addend for consecutive relocs
4528 which refer to the same offset. */
4529 signed_addend
= saved_addend
? *saved_addend
: 0;
4530 signed_addend
+= rel
->r_addend
;
4532 weak_undef_p
= (h
? h
->root
.type
== bfd_link_hash_undefweak
4533 : bfd_is_und_section (sym_sec
));
4535 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle
4536 it here if it is defined in a non-shared object. */
4538 && h
->type
== STT_GNU_IFUNC
4545 if ((input_section
->flags
& SEC_ALLOC
) == 0
4546 || h
->plt
.offset
== (bfd_vma
) -1)
4549 /* STT_GNU_IFUNC symbol must go through PLT. */
4550 plt
= globals
->root
.splt
? globals
->root
.splt
: globals
->root
.iplt
;
4551 value
= (plt
->output_section
->vma
+ plt
->output_offset
+ h
->plt
.offset
);
4556 if (h
->root
.root
.string
)
4557 name
= h
->root
.root
.string
;
4559 name
= bfd_elf_sym_name (input_bfd
, symtab_hdr
, sym
,
4561 (*_bfd_error_handler
)
4562 (_("%B: relocation %s against STT_GNU_IFUNC "
4563 "symbol `%s' isn't handled by %s"), input_bfd
,
4564 howto
->name
, name
, __FUNCTION__
);
4565 bfd_set_error (bfd_error_bad_value
);
4568 case BFD_RELOC_AARCH64_NN
:
4569 if (rel
->r_addend
!= 0)
4571 if (h
->root
.root
.string
)
4572 name
= h
->root
.root
.string
;
4574 name
= bfd_elf_sym_name (input_bfd
, symtab_hdr
,
4576 (*_bfd_error_handler
)
4577 (_("%B: relocation %s against STT_GNU_IFUNC "
4578 "symbol `%s' has non-zero addend: %d"),
4579 input_bfd
, howto
->name
, name
, rel
->r_addend
);
4580 bfd_set_error (bfd_error_bad_value
);
4584 /* Generate dynamic relocation only when there is a
4585 non-GOT reference in a shared object. */
4586 if (info
->shared
&& h
->non_got_ref
)
4588 Elf_Internal_Rela outrel
;
4591 /* Need a dynamic relocation to get the real function
4593 outrel
.r_offset
= _bfd_elf_section_offset (output_bfd
,
4597 if (outrel
.r_offset
== (bfd_vma
) -1
4598 || outrel
.r_offset
== (bfd_vma
) -2)
4601 outrel
.r_offset
+= (input_section
->output_section
->vma
4602 + input_section
->output_offset
);
4604 if (h
->dynindx
== -1
4606 || info
->executable
)
4608 /* This symbol is resolved locally. */
4609 outrel
.r_info
= ELFNN_R_INFO (0, AARCH64_R (IRELATIVE
));
4610 outrel
.r_addend
= (h
->root
.u
.def
.value
4611 + h
->root
.u
.def
.section
->output_section
->vma
4612 + h
->root
.u
.def
.section
->output_offset
);
4616 outrel
.r_info
= ELFNN_R_INFO (h
->dynindx
, r_type
);
4617 outrel
.r_addend
= 0;
4620 sreloc
= globals
->root
.irelifunc
;
4621 elf_append_rela (output_bfd
, sreloc
, &outrel
);
4623 /* If this reloc is against an external symbol, we
4624 do not want to fiddle with the addend. Otherwise,
4625 we need to include the symbol value so that it
4626 becomes an addend for the dynamic reloc. For an
4627 internal symbol, we have updated addend. */
4628 return bfd_reloc_ok
;
4631 case BFD_RELOC_AARCH64_CALL26
:
4632 case BFD_RELOC_AARCH64_JUMP26
:
4633 value
= _bfd_aarch64_elf_resolve_relocation (bfd_r_type
, place
, value
,
4636 return _bfd_aarch64_elf_put_addend (input_bfd
, hit_data
, bfd_r_type
,
4638 case BFD_RELOC_AARCH64_ADR_GOT_PAGE
:
4639 case BFD_RELOC_AARCH64_GOT_LD_PREL19
:
4640 case BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14
:
4641 case BFD_RELOC_AARCH64_LD32_GOT_LO12_NC
:
4642 case BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15
:
4643 case BFD_RELOC_AARCH64_LD64_GOT_LO12_NC
:
4644 base_got
= globals
->root
.sgot
;
4645 off
= h
->got
.offset
;
4647 if (base_got
== NULL
)
4650 if (off
== (bfd_vma
) -1)
4654 /* We can't use h->got.offset here to save state, or
4655 even just remember the offset, as finish_dynamic_symbol
4656 would use that as offset into .got. */
4658 if (globals
->root
.splt
!= NULL
)
4660 plt_index
= ((h
->plt
.offset
- globals
->plt_header_size
) /
4661 globals
->plt_entry_size
);
4662 off
= (plt_index
+ 3) * GOT_ENTRY_SIZE
;
4663 base_got
= globals
->root
.sgotplt
;
4667 plt_index
= h
->plt
.offset
/ globals
->plt_entry_size
;
4668 off
= plt_index
* GOT_ENTRY_SIZE
;
4669 base_got
= globals
->root
.igotplt
;
4672 if (h
->dynindx
== -1
4676 /* This references the local definition. We must
4677 initialize this entry in the global offset table.
4678 Since the offset must always be a multiple of 8,
4679 we use the least significant bit to record
4680 whether we have initialized it already.
4682 When doing a dynamic link, we create a .rela.got
4683 relocation entry to initialize the value. This
4684 is done in the finish_dynamic_symbol routine. */
4689 bfd_put_NN (output_bfd
, value
,
4690 base_got
->contents
+ off
);
4691 /* Note that this is harmless as -1 | 1 still is -1. */
4695 value
= (base_got
->output_section
->vma
4696 + base_got
->output_offset
+ off
);
4699 value
= aarch64_calculate_got_entry_vma (h
, globals
, info
,
4701 unresolved_reloc_p
);
4702 if (bfd_r_type
== BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15
4703 || bfd_r_type
== BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14
)
4704 addend
= (globals
->root
.sgot
->output_section
->vma
4705 + globals
->root
.sgot
->output_offset
);
4706 value
= _bfd_aarch64_elf_resolve_relocation (bfd_r_type
, place
, value
,
4707 addend
, weak_undef_p
);
4708 return _bfd_aarch64_elf_put_addend (input_bfd
, hit_data
, bfd_r_type
, howto
, value
);
4709 case BFD_RELOC_AARCH64_ADD_LO12
:
4710 case BFD_RELOC_AARCH64_ADR_HI21_PCREL
:
4717 case BFD_RELOC_AARCH64_NONE
:
4718 case BFD_RELOC_AARCH64_TLSDESC_CALL
:
4719 *unresolved_reloc_p
= FALSE
;
4720 return bfd_reloc_ok
;
4722 case BFD_RELOC_AARCH64_NN
:
4724 /* When generating a shared object or relocatable executable, these
4725 relocations are copied into the output file to be resolved at
4727 if (((info
->shared
== TRUE
) || globals
->root
.is_relocatable_executable
)
4728 && (input_section
->flags
& SEC_ALLOC
)
4730 || ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
4731 || h
->root
.type
!= bfd_link_hash_undefweak
))
4733 Elf_Internal_Rela outrel
;
4735 bfd_boolean skip
, relocate
;
4738 *unresolved_reloc_p
= FALSE
;
4743 outrel
.r_addend
= signed_addend
;
4745 _bfd_elf_section_offset (output_bfd
, info
, input_section
,
4747 if (outrel
.r_offset
== (bfd_vma
) - 1)
4749 else if (outrel
.r_offset
== (bfd_vma
) - 2)
4755 outrel
.r_offset
+= (input_section
->output_section
->vma
4756 + input_section
->output_offset
);
4759 memset (&outrel
, 0, sizeof outrel
);
4762 && (!info
->shared
|| !SYMBOLIC_BIND (info
, h
) || !h
->def_regular
))
4763 outrel
.r_info
= ELFNN_R_INFO (h
->dynindx
, r_type
);
4768 /* On SVR4-ish systems, the dynamic loader cannot
4769 relocate the text and data segments independently,
4770 so the symbol does not matter. */
4772 outrel
.r_info
= ELFNN_R_INFO (symbol
, AARCH64_R (RELATIVE
));
4773 outrel
.r_addend
+= value
;
4776 sreloc
= elf_section_data (input_section
)->sreloc
;
4777 if (sreloc
== NULL
|| sreloc
->contents
== NULL
)
4778 return bfd_reloc_notsupported
;
4780 loc
= sreloc
->contents
+ sreloc
->reloc_count
++ * RELOC_SIZE (globals
);
4781 bfd_elfNN_swap_reloca_out (output_bfd
, &outrel
, loc
);
4783 if (sreloc
->reloc_count
* RELOC_SIZE (globals
) > sreloc
->size
)
4785 /* Sanity to check that we have previously allocated
4786 sufficient space in the relocation section for the
4787 number of relocations we actually want to emit. */
4791 /* If this reloc is against an external symbol, we do not want to
4792 fiddle with the addend. Otherwise, we need to include the symbol
4793 value so that it becomes an addend for the dynamic reloc. */
4795 return bfd_reloc_ok
;
4797 return _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
4798 contents
, rel
->r_offset
, value
,
4802 value
+= signed_addend
;
4805 case BFD_RELOC_AARCH64_CALL26
:
4806 case BFD_RELOC_AARCH64_JUMP26
:
4808 asection
*splt
= globals
->root
.splt
;
4809 bfd_boolean via_plt_p
=
4810 splt
!= NULL
&& h
!= NULL
&& h
->plt
.offset
!= (bfd_vma
) - 1;
4812 /* A call to an undefined weak symbol is converted to a jump to
4813 the next instruction unless a PLT entry will be created.
4814 The jump to the next instruction is optimized as a NOP.
4815 Do the same for local undefined symbols. */
4816 if (weak_undef_p
&& ! via_plt_p
)
4818 bfd_putl32 (INSN_NOP
, hit_data
);
4819 return bfd_reloc_ok
;
4822 /* If the call goes through a PLT entry, make sure to
4823 check distance to the right destination address. */
4826 value
= (splt
->output_section
->vma
4827 + splt
->output_offset
+ h
->plt
.offset
);
4828 *unresolved_reloc_p
= FALSE
;
4831 /* If the target symbol is global and marked as a function the
4832 relocation applies a function call or a tail call. In this
4833 situation we can veneer out of range branches. The veneers
4834 use IP0 and IP1 hence cannot be used arbitrary out of range
4835 branches that occur within the body of a function. */
4836 if (h
&& h
->type
== STT_FUNC
)
4838 /* Check if a stub has to be inserted because the destination
4840 if (! aarch64_valid_branch_p (value
, place
))
4842 /* The target is out of reach, so redirect the branch to
4843 the local stub for this function. */
4844 struct elf_aarch64_stub_hash_entry
*stub_entry
;
4845 stub_entry
= elfNN_aarch64_get_stub_entry (input_section
,
4848 if (stub_entry
!= NULL
)
4849 value
= (stub_entry
->stub_offset
4850 + stub_entry
->stub_sec
->output_offset
4851 + stub_entry
->stub_sec
->output_section
->vma
);
4855 value
= _bfd_aarch64_elf_resolve_relocation (bfd_r_type
, place
, value
,
4856 signed_addend
, weak_undef_p
);
4859 case BFD_RELOC_AARCH64_16_PCREL
:
4860 case BFD_RELOC_AARCH64_32_PCREL
:
4861 case BFD_RELOC_AARCH64_64_PCREL
:
4862 case BFD_RELOC_AARCH64_ADR_HI21_NC_PCREL
:
4863 case BFD_RELOC_AARCH64_ADR_HI21_PCREL
:
4864 case BFD_RELOC_AARCH64_ADR_LO21_PCREL
:
4865 case BFD_RELOC_AARCH64_LD_LO19_PCREL
:
4867 && (input_section
->flags
& SEC_ALLOC
) != 0
4868 && (input_section
->flags
& SEC_READONLY
) != 0
4872 int howto_index
= bfd_r_type
- BFD_RELOC_AARCH64_RELOC_START
;
4874 (*_bfd_error_handler
)
4875 (_("%B: relocation %s against external symbol `%s' can not be used"
4876 " when making a shared object; recompile with -fPIC"),
4877 input_bfd
, elfNN_aarch64_howto_table
[howto_index
].name
,
4878 h
->root
.root
.string
);
4879 bfd_set_error (bfd_error_bad_value
);
4883 case BFD_RELOC_AARCH64_16
:
4885 case BFD_RELOC_AARCH64_32
:
4887 case BFD_RELOC_AARCH64_ADD_LO12
:
4888 case BFD_RELOC_AARCH64_BRANCH19
:
4889 case BFD_RELOC_AARCH64_LDST128_LO12
:
4890 case BFD_RELOC_AARCH64_LDST16_LO12
:
4891 case BFD_RELOC_AARCH64_LDST32_LO12
:
4892 case BFD_RELOC_AARCH64_LDST64_LO12
:
4893 case BFD_RELOC_AARCH64_LDST8_LO12
:
4894 case BFD_RELOC_AARCH64_MOVW_G0
:
4895 case BFD_RELOC_AARCH64_MOVW_G0_NC
:
4896 case BFD_RELOC_AARCH64_MOVW_G0_S
:
4897 case BFD_RELOC_AARCH64_MOVW_G1
:
4898 case BFD_RELOC_AARCH64_MOVW_G1_NC
:
4899 case BFD_RELOC_AARCH64_MOVW_G1_S
:
4900 case BFD_RELOC_AARCH64_MOVW_G2
:
4901 case BFD_RELOC_AARCH64_MOVW_G2_NC
:
4902 case BFD_RELOC_AARCH64_MOVW_G2_S
:
4903 case BFD_RELOC_AARCH64_MOVW_G3
:
4904 case BFD_RELOC_AARCH64_TSTBR14
:
4905 value
= _bfd_aarch64_elf_resolve_relocation (bfd_r_type
, place
, value
,
4906 signed_addend
, weak_undef_p
);
4909 case BFD_RELOC_AARCH64_ADR_GOT_PAGE
:
4910 case BFD_RELOC_AARCH64_GOT_LD_PREL19
:
4911 case BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14
:
4912 case BFD_RELOC_AARCH64_LD32_GOT_LO12_NC
:
4913 case BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15
:
4914 case BFD_RELOC_AARCH64_LD64_GOT_LO12_NC
:
4915 if (globals
->root
.sgot
== NULL
)
4916 BFD_ASSERT (h
!= NULL
);
4921 value
= aarch64_calculate_got_entry_vma (h
, globals
, info
, value
,
4923 unresolved_reloc_p
);
4924 if (bfd_r_type
== BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15
4925 || bfd_r_type
== BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14
)
4926 addend
= (globals
->root
.sgot
->output_section
->vma
4927 + globals
->root
.sgot
->output_offset
);
4928 value
= _bfd_aarch64_elf_resolve_relocation (bfd_r_type
, place
, value
,
4929 addend
, weak_undef_p
);
4934 struct elf_aarch64_local_symbol
*locals
4935 = elf_aarch64_locals (input_bfd
);
4939 int howto_index
= bfd_r_type
- BFD_RELOC_AARCH64_RELOC_START
;
4940 (*_bfd_error_handler
)
4941 (_("%B: Local symbol descriptor table be NULL when applying "
4942 "relocation %s against local symbol"),
4943 input_bfd
, elfNN_aarch64_howto_table
[howto_index
].name
);
4947 off
= symbol_got_offset (input_bfd
, h
, r_symndx
);
4948 base_got
= globals
->root
.sgot
;
4949 bfd_vma got_entry_addr
= (base_got
->output_section
->vma
4950 + base_got
->output_offset
+ off
);
4952 if (!symbol_got_offset_mark_p (input_bfd
, h
, r_symndx
))
4954 bfd_put_64 (output_bfd
, value
, base_got
->contents
+ off
);
4959 Elf_Internal_Rela outrel
;
4961 /* For local symbol, we have done absolute relocation in static
4962 linking stageh. While for share library, we need to update
4963 the content of GOT entry according to the share objects
4964 loading base address. So we need to generate a
4965 R_AARCH64_RELATIVE reloc for dynamic linker. */
4966 s
= globals
->root
.srelgot
;
4970 outrel
.r_offset
= got_entry_addr
;
4971 outrel
.r_info
= ELFNN_R_INFO (0, AARCH64_R (RELATIVE
));
4972 outrel
.r_addend
= value
;
4973 elf_append_rela (output_bfd
, s
, &outrel
);
4976 symbol_got_offset_mark (input_bfd
, h
, r_symndx
);
4979 /* Update the relocation value to GOT entry addr as we have transformed
4980 the direct data access into indirect data access through GOT. */
4981 value
= got_entry_addr
;
4983 if (bfd_r_type
== BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15
4984 || bfd_r_type
== BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14
)
4985 addend
= base_got
->output_section
->vma
+ base_got
->output_offset
;
4987 value
= _bfd_aarch64_elf_resolve_relocation (bfd_r_type
, place
, value
,
4988 addend
, weak_undef_p
);
4993 case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC
:
4994 case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21
:
4995 case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21
:
4996 case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21
:
4997 case BFD_RELOC_AARCH64_TLSIE_LD32_GOTTPREL_LO12_NC
:
4998 case BFD_RELOC_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC
:
4999 case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19
:
5000 if (globals
->root
.sgot
== NULL
)
5001 return bfd_reloc_notsupported
;
5003 value
= (symbol_got_offset (input_bfd
, h
, r_symndx
)
5004 + globals
->root
.sgot
->output_section
->vma
5005 + globals
->root
.sgot
->output_offset
);
5007 value
= _bfd_aarch64_elf_resolve_relocation (bfd_r_type
, place
, value
,
5009 *unresolved_reloc_p
= FALSE
;
5012 case BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_HI12
:
5013 case BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_LO12
:
5014 case BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_LO12_NC
:
5015 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0
:
5016 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC
:
5017 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1
:
5018 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1_NC
:
5019 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G2
:
5020 value
= _bfd_aarch64_elf_resolve_relocation (bfd_r_type
, place
, value
,
5021 signed_addend
- tpoff_base (info
),
5023 *unresolved_reloc_p
= FALSE
;
5026 case BFD_RELOC_AARCH64_TLSDESC_ADD
:
5027 case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12_NC
:
5028 case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21
:
5029 case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21
:
5030 case BFD_RELOC_AARCH64_TLSDESC_LD32_LO12_NC
:
5031 case BFD_RELOC_AARCH64_TLSDESC_LD64_LO12_NC
:
5032 case BFD_RELOC_AARCH64_TLSDESC_LDR
:
5033 case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19
:
5034 if (globals
->root
.sgot
== NULL
)
5035 return bfd_reloc_notsupported
;
5036 value
= (symbol_tlsdesc_got_offset (input_bfd
, h
, r_symndx
)
5037 + globals
->root
.sgotplt
->output_section
->vma
5038 + globals
->root
.sgotplt
->output_offset
5039 + globals
->sgotplt_jump_table_size
);
5041 value
= _bfd_aarch64_elf_resolve_relocation (bfd_r_type
, place
, value
,
5043 *unresolved_reloc_p
= FALSE
;
5047 return bfd_reloc_notsupported
;
5051 *saved_addend
= value
;
5053 /* Only apply the final relocation in a sequence. */
5055 return bfd_reloc_continue
;
5057 return _bfd_aarch64_elf_put_addend (input_bfd
, hit_data
, bfd_r_type
,
5061 /* Handle TLS relaxations. Relaxing is possible for symbols that use
5062 R_AARCH64_TLSDESC_ADR_{PAGE, LD64_LO12_NC, ADD_LO12_NC} during a static
5065 Return bfd_reloc_ok if we're done, bfd_reloc_continue if the caller
5066 is to then call final_link_relocate. Return other values in the
5069 static bfd_reloc_status_type
5070 elfNN_aarch64_tls_relax (struct elf_aarch64_link_hash_table
*globals
,
5071 bfd
*input_bfd
, bfd_byte
*contents
,
5072 Elf_Internal_Rela
*rel
, struct elf_link_hash_entry
*h
)
5074 bfd_boolean is_local
= h
== NULL
;
5075 unsigned int r_type
= ELFNN_R_TYPE (rel
->r_info
);
5078 BFD_ASSERT (globals
&& input_bfd
&& contents
&& rel
);
5080 switch (elfNN_aarch64_bfd_reloc_from_type (r_type
))
5082 case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21
:
5083 case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21
:
5086 /* GD->LE relaxation:
5087 adrp x0, :tlsgd:var => movz x0, :tprel_g1:var
5089 adrp x0, :tlsdesc:var => movz x0, :tprel_g1:var
5091 bfd_putl32 (0xd2a00000, contents
+ rel
->r_offset
);
5092 return bfd_reloc_continue
;
5096 /* GD->IE relaxation:
5097 adrp x0, :tlsgd:var => adrp x0, :gottprel:var
5099 adrp x0, :tlsdesc:var => adrp x0, :gottprel:var
5101 return bfd_reloc_continue
;
5104 case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21
:
5108 case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19
:
5111 /* Tiny TLSDESC->LE relaxation:
5112 ldr x1, :tlsdesc:var => movz x0, #:tprel_g1:var
5113 adr x0, :tlsdesc:var => movk x0, #:tprel_g0_nc:var
5117 BFD_ASSERT (ELFNN_R_TYPE (rel
[1].r_info
) == AARCH64_R (TLSDESC_ADR_PREL21
));
5118 BFD_ASSERT (ELFNN_R_TYPE (rel
[2].r_info
) == AARCH64_R (TLSDESC_CALL
));
5120 rel
[1].r_info
= ELFNN_R_INFO (ELFNN_R_SYM (rel
->r_info
),
5121 AARCH64_R (TLSLE_MOVW_TPREL_G0_NC
));
5122 rel
[2].r_info
= ELFNN_R_INFO (STN_UNDEF
, R_AARCH64_NONE
);
5124 bfd_putl32 (0xd2a00000, contents
+ rel
->r_offset
);
5125 bfd_putl32 (0xf2800000, contents
+ rel
->r_offset
+ 4);
5126 bfd_putl32 (INSN_NOP
, contents
+ rel
->r_offset
+ 8);
5127 return bfd_reloc_continue
;
5131 /* Tiny TLSDESC->IE relaxation:
5132 ldr x1, :tlsdesc:var => ldr x0, :gottprel:var
5133 adr x0, :tlsdesc:var => nop
5137 BFD_ASSERT (ELFNN_R_TYPE (rel
[1].r_info
) == AARCH64_R (TLSDESC_ADR_PREL21
));
5138 BFD_ASSERT (ELFNN_R_TYPE (rel
[2].r_info
) == AARCH64_R (TLSDESC_CALL
));
5140 rel
[1].r_info
= ELFNN_R_INFO (STN_UNDEF
, R_AARCH64_NONE
);
5141 rel
[2].r_info
= ELFNN_R_INFO (STN_UNDEF
, R_AARCH64_NONE
);
5143 bfd_putl32 (0x58000000, contents
+ rel
->r_offset
);
5144 bfd_putl32 (INSN_NOP
, contents
+ rel
->r_offset
+ 4);
5145 bfd_putl32 (INSN_NOP
, contents
+ rel
->r_offset
+ 8);
5146 return bfd_reloc_continue
;
5149 case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21
:
5152 /* Tiny GD->LE relaxation:
5153 adr x0, :tlsgd:var => mrs x1, tpidr_el0
5154 bl __tls_get_addr => add x0, x1, #:tprel_hi12:x, lsl #12
5155 nop => add x0, x0, #:tprel_lo12_nc:x
5158 /* First kill the tls_get_addr reloc on the bl instruction. */
5159 BFD_ASSERT (rel
->r_offset
+ 4 == rel
[1].r_offset
);
5161 bfd_putl32 (0xd53bd041, contents
+ rel
->r_offset
+ 0);
5162 bfd_putl32 (0x91400020, contents
+ rel
->r_offset
+ 4);
5163 bfd_putl32 (0x91000000, contents
+ rel
->r_offset
+ 8);
5165 rel
[1].r_info
= ELFNN_R_INFO (ELFNN_R_SYM (rel
->r_info
),
5166 AARCH64_R (TLSLE_ADD_TPREL_LO12_NC
));
5167 rel
[1].r_offset
= rel
->r_offset
+ 8;
5169 /* Move the current relocation to the second instruction in
5172 rel
->r_info
= ELFNN_R_INFO (ELFNN_R_SYM (rel
->r_info
),
5173 AARCH64_R (TLSLE_ADD_TPREL_HI12
));
5174 return bfd_reloc_continue
;
5178 /* Tiny GD->IE relaxation:
5179 adr x0, :tlsgd:var => ldr x0, :gottprel:var
5180 bl __tls_get_addr => mrs x1, tpidr_el0
5181 nop => add x0, x0, x1
5184 /* First kill the tls_get_addr reloc on the bl instruction. */
5185 BFD_ASSERT (rel
->r_offset
+ 4 == rel
[1].r_offset
);
5186 rel
[1].r_info
= ELFNN_R_INFO (STN_UNDEF
, R_AARCH64_NONE
);
5188 bfd_putl32 (0x58000000, contents
+ rel
->r_offset
);
5189 bfd_putl32 (0xd53bd041, contents
+ rel
->r_offset
+ 4);
5190 bfd_putl32 (0x8b000020, contents
+ rel
->r_offset
+ 8);
5191 return bfd_reloc_continue
;
5194 case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19
:
5195 return bfd_reloc_continue
;
5197 case BFD_RELOC_AARCH64_TLSDESC_LDNN_LO12_NC
:
5200 /* GD->LE relaxation:
5201 ldr xd, [x0, #:tlsdesc_lo12:var] => movk x0, :tprel_g0_nc:var
5203 bfd_putl32 (0xf2800000, contents
+ rel
->r_offset
);
5204 return bfd_reloc_continue
;
5208 /* GD->IE relaxation:
5209 ldr xd, [x0, #:tlsdesc_lo12:var] => ldr x0, [x0, #:gottprel_lo12:var]
5211 insn
= bfd_getl32 (contents
+ rel
->r_offset
);
5213 bfd_putl32 (insn
, contents
+ rel
->r_offset
);
5214 return bfd_reloc_continue
;
5217 case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC
:
5220 /* GD->LE relaxation
5221 add x0, #:tlsgd_lo12:var => movk x0, :tprel_g0_nc:var
5222 bl __tls_get_addr => mrs x1, tpidr_el0
5223 nop => add x0, x1, x0
5226 /* First kill the tls_get_addr reloc on the bl instruction. */
5227 BFD_ASSERT (rel
->r_offset
+ 4 == rel
[1].r_offset
);
5228 rel
[1].r_info
= ELFNN_R_INFO (STN_UNDEF
, R_AARCH64_NONE
);
5230 bfd_putl32 (0xf2800000, contents
+ rel
->r_offset
);
5231 bfd_putl32 (0xd53bd041, contents
+ rel
->r_offset
+ 4);
5232 bfd_putl32 (0x8b000020, contents
+ rel
->r_offset
+ 8);
5233 return bfd_reloc_continue
;
5237 /* GD->IE relaxation
5238 ADD x0, #:tlsgd_lo12:var => ldr x0, [x0, #:gottprel_lo12:var]
5239 BL __tls_get_addr => mrs x1, tpidr_el0
5241 NOP => add x0, x1, x0
5244 BFD_ASSERT (ELFNN_R_TYPE (rel
[1].r_info
) == AARCH64_R (CALL26
));
5246 /* Remove the relocation on the BL instruction. */
5247 rel
[1].r_info
= ELFNN_R_INFO (STN_UNDEF
, R_AARCH64_NONE
);
5249 bfd_putl32 (0xf9400000, contents
+ rel
->r_offset
);
5251 /* We choose to fixup the BL and NOP instructions using the
5252 offset from the second relocation to allow flexibility in
5253 scheduling instructions between the ADD and BL. */
5254 bfd_putl32 (0xd53bd041, contents
+ rel
[1].r_offset
);
5255 bfd_putl32 (0x8b000020, contents
+ rel
[1].r_offset
+ 4);
5256 return bfd_reloc_continue
;
5259 case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12_NC
:
5260 case BFD_RELOC_AARCH64_TLSDESC_CALL
:
5261 /* GD->IE/LE relaxation:
5262 add x0, x0, #:tlsdesc_lo12:var => nop
5265 bfd_putl32 (INSN_NOP
, contents
+ rel
->r_offset
);
5266 return bfd_reloc_ok
;
5268 case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21
:
5269 /* IE->LE relaxation:
5270 adrp xd, :gottprel:var => movz xd, :tprel_g1:var
5274 insn
= bfd_getl32 (contents
+ rel
->r_offset
);
5275 bfd_putl32 (0xd2a00000 | (insn
& 0x1f), contents
+ rel
->r_offset
);
5277 return bfd_reloc_continue
;
5279 case BFD_RELOC_AARCH64_TLSIE_LDNN_GOTTPREL_LO12_NC
:
5280 /* IE->LE relaxation:
5281 ldr xd, [xm, #:gottprel_lo12:var] => movk xd, :tprel_g0_nc:var
5285 insn
= bfd_getl32 (contents
+ rel
->r_offset
);
5286 bfd_putl32 (0xf2800000 | (insn
& 0x1f), contents
+ rel
->r_offset
);
5288 return bfd_reloc_continue
;
5291 return bfd_reloc_continue
;
5294 return bfd_reloc_ok
;
5297 /* Relocate an AArch64 ELF section. */
5300 elfNN_aarch64_relocate_section (bfd
*output_bfd
,
5301 struct bfd_link_info
*info
,
5303 asection
*input_section
,
5305 Elf_Internal_Rela
*relocs
,
5306 Elf_Internal_Sym
*local_syms
,
5307 asection
**local_sections
)
5309 Elf_Internal_Shdr
*symtab_hdr
;
5310 struct elf_link_hash_entry
**sym_hashes
;
5311 Elf_Internal_Rela
*rel
;
5312 Elf_Internal_Rela
*relend
;
5314 struct elf_aarch64_link_hash_table
*globals
;
5315 bfd_boolean save_addend
= FALSE
;
5318 globals
= elf_aarch64_hash_table (info
);
5320 symtab_hdr
= &elf_symtab_hdr (input_bfd
);
5321 sym_hashes
= elf_sym_hashes (input_bfd
);
5324 relend
= relocs
+ input_section
->reloc_count
;
5325 for (; rel
< relend
; rel
++)
5327 unsigned int r_type
;
5328 bfd_reloc_code_real_type bfd_r_type
;
5329 bfd_reloc_code_real_type relaxed_bfd_r_type
;
5330 reloc_howto_type
*howto
;
5331 unsigned long r_symndx
;
5332 Elf_Internal_Sym
*sym
;
5334 struct elf_link_hash_entry
*h
;
5336 bfd_reloc_status_type r
;
5339 bfd_boolean unresolved_reloc
= FALSE
;
5340 char *error_message
= NULL
;
5342 r_symndx
= ELFNN_R_SYM (rel
->r_info
);
5343 r_type
= ELFNN_R_TYPE (rel
->r_info
);
5345 bfd_reloc
.howto
= elfNN_aarch64_howto_from_type (r_type
);
5346 howto
= bfd_reloc
.howto
;
5350 (*_bfd_error_handler
)
5351 (_("%B: unrecognized relocation (0x%x) in section `%A'"),
5352 input_bfd
, input_section
, r_type
);
5355 bfd_r_type
= elfNN_aarch64_bfd_reloc_from_howto (howto
);
5361 if (r_symndx
< symtab_hdr
->sh_info
)
5363 sym
= local_syms
+ r_symndx
;
5364 sym_type
= ELFNN_ST_TYPE (sym
->st_info
);
5365 sec
= local_sections
[r_symndx
];
5367 /* An object file might have a reference to a local
5368 undefined symbol. This is a daft object file, but we
5369 should at least do something about it. */
5370 if (r_type
!= R_AARCH64_NONE
&& r_type
!= R_AARCH64_NULL
5371 && bfd_is_und_section (sec
)
5372 && ELF_ST_BIND (sym
->st_info
) != STB_WEAK
)
5374 if (!info
->callbacks
->undefined_symbol
5375 (info
, bfd_elf_string_from_elf_section
5376 (input_bfd
, symtab_hdr
->sh_link
, sym
->st_name
),
5377 input_bfd
, input_section
, rel
->r_offset
, TRUE
))
5381 relocation
= _bfd_elf_rela_local_sym (output_bfd
, sym
, &sec
, rel
);
5383 /* Relocate against local STT_GNU_IFUNC symbol. */
5384 if (!info
->relocatable
5385 && ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
)
5387 h
= elfNN_aarch64_get_local_sym_hash (globals
, input_bfd
,
5392 /* Set STT_GNU_IFUNC symbol value. */
5393 h
->root
.u
.def
.value
= sym
->st_value
;
5394 h
->root
.u
.def
.section
= sec
;
5399 bfd_boolean warned
, ignored
;
5401 RELOC_FOR_GLOBAL_SYMBOL (info
, input_bfd
, input_section
, rel
,
5402 r_symndx
, symtab_hdr
, sym_hashes
,
5404 unresolved_reloc
, warned
, ignored
);
5409 if (sec
!= NULL
&& discarded_section (sec
))
5410 RELOC_AGAINST_DISCARDED_SECTION (info
, input_bfd
, input_section
,
5411 rel
, 1, relend
, howto
, 0, contents
);
5413 if (info
->relocatable
)
5417 name
= h
->root
.root
.string
;
5420 name
= (bfd_elf_string_from_elf_section
5421 (input_bfd
, symtab_hdr
->sh_link
, sym
->st_name
));
5422 if (name
== NULL
|| *name
== '\0')
5423 name
= bfd_section_name (input_bfd
, sec
);
5427 && r_type
!= R_AARCH64_NONE
5428 && r_type
!= R_AARCH64_NULL
5430 || h
->root
.type
== bfd_link_hash_defined
5431 || h
->root
.type
== bfd_link_hash_defweak
)
5432 && IS_AARCH64_TLS_RELOC (bfd_r_type
) != (sym_type
== STT_TLS
))
5434 (*_bfd_error_handler
)
5435 ((sym_type
== STT_TLS
5436 ? _("%B(%A+0x%lx): %s used with TLS symbol %s")
5437 : _("%B(%A+0x%lx): %s used with non-TLS symbol %s")),
5439 input_section
, (long) rel
->r_offset
, howto
->name
, name
);
5442 /* We relax only if we can see that there can be a valid transition
5443 from a reloc type to another.
5444 We call elfNN_aarch64_final_link_relocate unless we're completely
5445 done, i.e., the relaxation produced the final output we want. */
5447 relaxed_bfd_r_type
= aarch64_tls_transition (input_bfd
, info
, r_type
,
5449 if (relaxed_bfd_r_type
!= bfd_r_type
)
5451 bfd_r_type
= relaxed_bfd_r_type
;
5452 howto
= elfNN_aarch64_howto_from_bfd_reloc (bfd_r_type
);
5453 BFD_ASSERT (howto
!= NULL
);
5454 r_type
= howto
->type
;
5455 r
= elfNN_aarch64_tls_relax (globals
, input_bfd
, contents
, rel
, h
);
5456 unresolved_reloc
= 0;
5459 r
= bfd_reloc_continue
;
5461 /* There may be multiple consecutive relocations for the
5462 same offset. In that case we are supposed to treat the
5463 output of each relocation as the addend for the next. */
5464 if (rel
+ 1 < relend
5465 && rel
->r_offset
== rel
[1].r_offset
5466 && ELFNN_R_TYPE (rel
[1].r_info
) != R_AARCH64_NONE
5467 && ELFNN_R_TYPE (rel
[1].r_info
) != R_AARCH64_NULL
)
5470 save_addend
= FALSE
;
5472 if (r
== bfd_reloc_continue
)
5473 r
= elfNN_aarch64_final_link_relocate (howto
, input_bfd
, output_bfd
,
5474 input_section
, contents
, rel
,
5475 relocation
, info
, sec
,
5476 h
, &unresolved_reloc
,
5477 save_addend
, &addend
, sym
);
5479 switch (elfNN_aarch64_bfd_reloc_from_type (r_type
))
5481 case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC
:
5482 case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21
:
5483 case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21
:
5484 if (! symbol_got_offset_mark_p (input_bfd
, h
, r_symndx
))
5486 bfd_boolean need_relocs
= FALSE
;
5491 off
= symbol_got_offset (input_bfd
, h
, r_symndx
);
5492 indx
= h
&& h
->dynindx
!= -1 ? h
->dynindx
: 0;
5495 (info
->shared
|| indx
!= 0) &&
5497 || ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
5498 || h
->root
.type
!= bfd_link_hash_undefweak
);
5500 BFD_ASSERT (globals
->root
.srelgot
!= NULL
);
5504 Elf_Internal_Rela rela
;
5505 rela
.r_info
= ELFNN_R_INFO (indx
, AARCH64_R (TLS_DTPMOD
));
5507 rela
.r_offset
= globals
->root
.sgot
->output_section
->vma
+
5508 globals
->root
.sgot
->output_offset
+ off
;
5511 loc
= globals
->root
.srelgot
->contents
;
5512 loc
+= globals
->root
.srelgot
->reloc_count
++
5513 * RELOC_SIZE (htab
);
5514 bfd_elfNN_swap_reloca_out (output_bfd
, &rela
, loc
);
5518 bfd_put_NN (output_bfd
,
5519 relocation
- dtpoff_base (info
),
5520 globals
->root
.sgot
->contents
+ off
5525 /* This TLS symbol is global. We emit a
5526 relocation to fixup the tls offset at load
5529 ELFNN_R_INFO (indx
, AARCH64_R (TLS_DTPREL
));
5532 (globals
->root
.sgot
->output_section
->vma
5533 + globals
->root
.sgot
->output_offset
+ off
5536 loc
= globals
->root
.srelgot
->contents
;
5537 loc
+= globals
->root
.srelgot
->reloc_count
++
5538 * RELOC_SIZE (globals
);
5539 bfd_elfNN_swap_reloca_out (output_bfd
, &rela
, loc
);
5540 bfd_put_NN (output_bfd
, (bfd_vma
) 0,
5541 globals
->root
.sgot
->contents
+ off
5547 bfd_put_NN (output_bfd
, (bfd_vma
) 1,
5548 globals
->root
.sgot
->contents
+ off
);
5549 bfd_put_NN (output_bfd
,
5550 relocation
- dtpoff_base (info
),
5551 globals
->root
.sgot
->contents
+ off
5555 symbol_got_offset_mark (input_bfd
, h
, r_symndx
);
5559 case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21
:
5560 case BFD_RELOC_AARCH64_TLSIE_LDNN_GOTTPREL_LO12_NC
:
5561 case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19
:
5562 if (! symbol_got_offset_mark_p (input_bfd
, h
, r_symndx
))
5564 bfd_boolean need_relocs
= FALSE
;
5569 off
= symbol_got_offset (input_bfd
, h
, r_symndx
);
5571 indx
= h
&& h
->dynindx
!= -1 ? h
->dynindx
: 0;
5574 (info
->shared
|| indx
!= 0) &&
5576 || ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
5577 || h
->root
.type
!= bfd_link_hash_undefweak
);
5579 BFD_ASSERT (globals
->root
.srelgot
!= NULL
);
5583 Elf_Internal_Rela rela
;
5586 rela
.r_addend
= relocation
- dtpoff_base (info
);
5590 rela
.r_info
= ELFNN_R_INFO (indx
, AARCH64_R (TLS_TPREL
));
5591 rela
.r_offset
= globals
->root
.sgot
->output_section
->vma
+
5592 globals
->root
.sgot
->output_offset
+ off
;
5594 loc
= globals
->root
.srelgot
->contents
;
5595 loc
+= globals
->root
.srelgot
->reloc_count
++
5596 * RELOC_SIZE (htab
);
5598 bfd_elfNN_swap_reloca_out (output_bfd
, &rela
, loc
);
5600 bfd_put_NN (output_bfd
, rela
.r_addend
,
5601 globals
->root
.sgot
->contents
+ off
);
5604 bfd_put_NN (output_bfd
, relocation
- tpoff_base (info
),
5605 globals
->root
.sgot
->contents
+ off
);
5607 symbol_got_offset_mark (input_bfd
, h
, r_symndx
);
5611 case BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_HI12
:
5612 case BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_LO12
:
5613 case BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_LO12_NC
:
5614 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0
:
5615 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC
:
5616 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1
:
5617 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1_NC
:
5618 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G2
:
5621 case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12_NC
:
5622 case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21
:
5623 case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21
:
5624 case BFD_RELOC_AARCH64_TLSDESC_LDNN_LO12_NC
:
5625 case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19
:
5626 if (! symbol_tlsdesc_got_offset_mark_p (input_bfd
, h
, r_symndx
))
5628 bfd_boolean need_relocs
= FALSE
;
5629 int indx
= h
&& h
->dynindx
!= -1 ? h
->dynindx
: 0;
5630 bfd_vma off
= symbol_tlsdesc_got_offset (input_bfd
, h
, r_symndx
);
5632 need_relocs
= (h
== NULL
5633 || ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
5634 || h
->root
.type
!= bfd_link_hash_undefweak
);
5636 BFD_ASSERT (globals
->root
.srelgot
!= NULL
);
5637 BFD_ASSERT (globals
->root
.sgot
!= NULL
);
5642 Elf_Internal_Rela rela
;
5643 rela
.r_info
= ELFNN_R_INFO (indx
, AARCH64_R (TLSDESC
));
5646 rela
.r_offset
= (globals
->root
.sgotplt
->output_section
->vma
5647 + globals
->root
.sgotplt
->output_offset
5648 + off
+ globals
->sgotplt_jump_table_size
);
5651 rela
.r_addend
= relocation
- dtpoff_base (info
);
5653 /* Allocate the next available slot in the PLT reloc
5654 section to hold our R_AARCH64_TLSDESC, the next
5655 available slot is determined from reloc_count,
5656 which we step. But note, reloc_count was
5657 artifically moved down while allocating slots for
5658 real PLT relocs such that all of the PLT relocs
5659 will fit above the initial reloc_count and the
5660 extra stuff will fit below. */
5661 loc
= globals
->root
.srelplt
->contents
;
5662 loc
+= globals
->root
.srelplt
->reloc_count
++
5663 * RELOC_SIZE (globals
);
5665 bfd_elfNN_swap_reloca_out (output_bfd
, &rela
, loc
);
5667 bfd_put_NN (output_bfd
, (bfd_vma
) 0,
5668 globals
->root
.sgotplt
->contents
+ off
+
5669 globals
->sgotplt_jump_table_size
);
5670 bfd_put_NN (output_bfd
, (bfd_vma
) 0,
5671 globals
->root
.sgotplt
->contents
+ off
+
5672 globals
->sgotplt_jump_table_size
+
5676 symbol_tlsdesc_got_offset_mark (input_bfd
, h
, r_symndx
);
5687 /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
5688 because such sections are not SEC_ALLOC and thus ld.so will
5689 not process them. */
5690 if (unresolved_reloc
5691 && !((input_section
->flags
& SEC_DEBUGGING
) != 0
5693 && _bfd_elf_section_offset (output_bfd
, info
, input_section
,
5694 +rel
->r_offset
) != (bfd_vma
) - 1)
5696 (*_bfd_error_handler
)
5698 ("%B(%A+0x%lx): unresolvable %s relocation against symbol `%s'"),
5699 input_bfd
, input_section
, (long) rel
->r_offset
, howto
->name
,
5700 h
->root
.root
.string
);
5704 if (r
!= bfd_reloc_ok
&& r
!= bfd_reloc_continue
)
5708 case bfd_reloc_overflow
:
5709 if (!(*info
->callbacks
->reloc_overflow
)
5710 (info
, (h
? &h
->root
: NULL
), name
, howto
->name
, (bfd_vma
) 0,
5711 input_bfd
, input_section
, rel
->r_offset
))
5715 case bfd_reloc_undefined
:
5716 if (!((*info
->callbacks
->undefined_symbol
)
5717 (info
, name
, input_bfd
, input_section
,
5718 rel
->r_offset
, TRUE
)))
5722 case bfd_reloc_outofrange
:
5723 error_message
= _("out of range");
5726 case bfd_reloc_notsupported
:
5727 error_message
= _("unsupported relocation");
5730 case bfd_reloc_dangerous
:
5731 /* error_message should already be set. */
5735 error_message
= _("unknown error");
5739 BFD_ASSERT (error_message
!= NULL
);
5740 if (!((*info
->callbacks
->reloc_dangerous
)
5741 (info
, error_message
, input_bfd
, input_section
,
5752 /* Set the right machine number. */
5755 elfNN_aarch64_object_p (bfd
*abfd
)
5758 bfd_default_set_arch_mach (abfd
, bfd_arch_aarch64
, bfd_mach_aarch64_ilp32
);
5760 bfd_default_set_arch_mach (abfd
, bfd_arch_aarch64
, bfd_mach_aarch64
);
5765 /* Function to keep AArch64 specific flags in the ELF header. */
5768 elfNN_aarch64_set_private_flags (bfd
*abfd
, flagword flags
)
5770 if (elf_flags_init (abfd
) && elf_elfheader (abfd
)->e_flags
!= flags
)
5775 elf_elfheader (abfd
)->e_flags
= flags
;
5776 elf_flags_init (abfd
) = TRUE
;
5782 /* Merge backend specific data from an object file to the output
5783 object file when linking. */
5786 elfNN_aarch64_merge_private_bfd_data (bfd
*ibfd
, bfd
*obfd
)
5790 bfd_boolean flags_compatible
= TRUE
;
5793 /* Check if we have the same endianess. */
5794 if (!_bfd_generic_verify_endian_match (ibfd
, obfd
))
5797 if (!is_aarch64_elf (ibfd
) || !is_aarch64_elf (obfd
))
5800 /* The input BFD must have had its flags initialised. */
5801 /* The following seems bogus to me -- The flags are initialized in
5802 the assembler but I don't think an elf_flags_init field is
5803 written into the object. */
5804 /* BFD_ASSERT (elf_flags_init (ibfd)); */
5806 in_flags
= elf_elfheader (ibfd
)->e_flags
;
5807 out_flags
= elf_elfheader (obfd
)->e_flags
;
5809 if (!elf_flags_init (obfd
))
5811 /* If the input is the default architecture and had the default
5812 flags then do not bother setting the flags for the output
5813 architecture, instead allow future merges to do this. If no
5814 future merges ever set these flags then they will retain their
5815 uninitialised values, which surprise surprise, correspond
5816 to the default values. */
5817 if (bfd_get_arch_info (ibfd
)->the_default
5818 && elf_elfheader (ibfd
)->e_flags
== 0)
5821 elf_flags_init (obfd
) = TRUE
;
5822 elf_elfheader (obfd
)->e_flags
= in_flags
;
5824 if (bfd_get_arch (obfd
) == bfd_get_arch (ibfd
)
5825 && bfd_get_arch_info (obfd
)->the_default
)
5826 return bfd_set_arch_mach (obfd
, bfd_get_arch (ibfd
),
5827 bfd_get_mach (ibfd
));
5832 /* Identical flags must be compatible. */
5833 if (in_flags
== out_flags
)
5836 /* Check to see if the input BFD actually contains any sections. If
5837 not, its flags may not have been initialised either, but it
5838 cannot actually cause any incompatiblity. Do not short-circuit
5839 dynamic objects; their section list may be emptied by
5840 elf_link_add_object_symbols.
5842 Also check to see if there are no code sections in the input.
5843 In this case there is no need to check for code specific flags.
5844 XXX - do we need to worry about floating-point format compatability
5845 in data sections ? */
5846 if (!(ibfd
->flags
& DYNAMIC
))
5848 bfd_boolean null_input_bfd
= TRUE
;
5849 bfd_boolean only_data_sections
= TRUE
;
5851 for (sec
= ibfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
5853 if ((bfd_get_section_flags (ibfd
, sec
)
5854 & (SEC_LOAD
| SEC_CODE
| SEC_HAS_CONTENTS
))
5855 == (SEC_LOAD
| SEC_CODE
| SEC_HAS_CONTENTS
))
5856 only_data_sections
= FALSE
;
5858 null_input_bfd
= FALSE
;
5862 if (null_input_bfd
|| only_data_sections
)
5866 return flags_compatible
;
5869 /* Display the flags field. */
5872 elfNN_aarch64_print_private_bfd_data (bfd
*abfd
, void *ptr
)
5874 FILE *file
= (FILE *) ptr
;
5875 unsigned long flags
;
5877 BFD_ASSERT (abfd
!= NULL
&& ptr
!= NULL
);
5879 /* Print normal ELF private data. */
5880 _bfd_elf_print_private_bfd_data (abfd
, ptr
);
5882 flags
= elf_elfheader (abfd
)->e_flags
;
5883 /* Ignore init flag - it may not be set, despite the flags field
5884 containing valid data. */
5886 /* xgettext:c-format */
5887 fprintf (file
, _("private flags = %lx:"), elf_elfheader (abfd
)->e_flags
);
5890 fprintf (file
, _("<Unrecognised flag bits set>"));
5897 /* Update the got entry reference counts for the section being removed. */
5900 elfNN_aarch64_gc_sweep_hook (bfd
*abfd
,
5901 struct bfd_link_info
*info
,
5903 const Elf_Internal_Rela
* relocs
)
5905 struct elf_aarch64_link_hash_table
*htab
;
5906 Elf_Internal_Shdr
*symtab_hdr
;
5907 struct elf_link_hash_entry
**sym_hashes
;
5908 struct elf_aarch64_local_symbol
*locals
;
5909 const Elf_Internal_Rela
*rel
, *relend
;
5911 if (info
->relocatable
)
5914 htab
= elf_aarch64_hash_table (info
);
5919 elf_section_data (sec
)->local_dynrel
= NULL
;
5921 symtab_hdr
= &elf_symtab_hdr (abfd
);
5922 sym_hashes
= elf_sym_hashes (abfd
);
5924 locals
= elf_aarch64_locals (abfd
);
5926 relend
= relocs
+ sec
->reloc_count
;
5927 for (rel
= relocs
; rel
< relend
; rel
++)
5929 unsigned long r_symndx
;
5930 unsigned int r_type
;
5931 struct elf_link_hash_entry
*h
= NULL
;
5933 r_symndx
= ELFNN_R_SYM (rel
->r_info
);
5935 if (r_symndx
>= symtab_hdr
->sh_info
)
5938 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
5939 while (h
->root
.type
== bfd_link_hash_indirect
5940 || h
->root
.type
== bfd_link_hash_warning
)
5941 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
5945 Elf_Internal_Sym
*isym
;
5947 /* A local symbol. */
5948 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
5951 /* Check relocation against local STT_GNU_IFUNC symbol. */
5953 && ELF_ST_TYPE (isym
->st_info
) == STT_GNU_IFUNC
)
5955 h
= elfNN_aarch64_get_local_sym_hash (htab
, abfd
, rel
, FALSE
);
5963 struct elf_aarch64_link_hash_entry
*eh
;
5964 struct elf_dyn_relocs
**pp
;
5965 struct elf_dyn_relocs
*p
;
5967 eh
= (struct elf_aarch64_link_hash_entry
*) h
;
5969 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; pp
= &p
->next
)
5972 /* Everything must go for SEC. */
5978 r_type
= ELFNN_R_TYPE (rel
->r_info
);
5979 switch (aarch64_tls_transition (abfd
,info
, r_type
, h
,r_symndx
))
5981 case BFD_RELOC_AARCH64_ADR_GOT_PAGE
:
5982 case BFD_RELOC_AARCH64_GOT_LD_PREL19
:
5983 case BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14
:
5984 case BFD_RELOC_AARCH64_LD32_GOT_LO12_NC
:
5985 case BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15
:
5986 case BFD_RELOC_AARCH64_LD64_GOT_LO12_NC
:
5987 case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12_NC
:
5988 case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21
:
5989 case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21
:
5990 case BFD_RELOC_AARCH64_TLSDESC_LD32_LO12_NC
:
5991 case BFD_RELOC_AARCH64_TLSDESC_LD64_LO12_NC
:
5992 case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19
:
5993 case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC
:
5994 case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21
:
5995 case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21
:
5996 case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21
:
5997 case BFD_RELOC_AARCH64_TLSIE_LD32_GOTTPREL_LO12_NC
:
5998 case BFD_RELOC_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC
:
5999 case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19
:
6000 case BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_HI12
:
6001 case BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_LO12
:
6002 case BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_LO12_NC
:
6003 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0
:
6004 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC
:
6005 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1
:
6006 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1_NC
:
6007 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G2
:
6010 if (h
->got
.refcount
> 0)
6011 h
->got
.refcount
-= 1;
6013 if (h
->type
== STT_GNU_IFUNC
)
6015 if (h
->plt
.refcount
> 0)
6016 h
->plt
.refcount
-= 1;
6019 else if (locals
!= NULL
)
6021 if (locals
[r_symndx
].got_refcount
> 0)
6022 locals
[r_symndx
].got_refcount
-= 1;
6026 case BFD_RELOC_AARCH64_CALL26
:
6027 case BFD_RELOC_AARCH64_JUMP26
:
6028 /* If this is a local symbol then we resolve it
6029 directly without creating a PLT entry. */
6033 if (h
->plt
.refcount
> 0)
6034 h
->plt
.refcount
-= 1;
6037 case BFD_RELOC_AARCH64_ADR_HI21_NC_PCREL
:
6038 case BFD_RELOC_AARCH64_ADR_HI21_PCREL
:
6039 case BFD_RELOC_AARCH64_ADR_LO21_PCREL
:
6040 case BFD_RELOC_AARCH64_MOVW_G0_NC
:
6041 case BFD_RELOC_AARCH64_MOVW_G1_NC
:
6042 case BFD_RELOC_AARCH64_MOVW_G2_NC
:
6043 case BFD_RELOC_AARCH64_MOVW_G3
:
6044 case BFD_RELOC_AARCH64_NN
:
6045 if (h
!= NULL
&& info
->executable
)
6047 if (h
->plt
.refcount
> 0)
6048 h
->plt
.refcount
-= 1;
6060 /* Adjust a symbol defined by a dynamic object and referenced by a
6061 regular object. The current definition is in some section of the
6062 dynamic object, but we're not including those sections. We have to
6063 change the definition to something the rest of the link can
6067 elfNN_aarch64_adjust_dynamic_symbol (struct bfd_link_info
*info
,
6068 struct elf_link_hash_entry
*h
)
6070 struct elf_aarch64_link_hash_table
*htab
;
6073 /* If this is a function, put it in the procedure linkage table. We
6074 will fill in the contents of the procedure linkage table later,
6075 when we know the address of the .got section. */
6076 if (h
->type
== STT_FUNC
|| h
->type
== STT_GNU_IFUNC
|| h
->needs_plt
)
6078 if (h
->plt
.refcount
<= 0
6079 || (h
->type
!= STT_GNU_IFUNC
6080 && (SYMBOL_CALLS_LOCAL (info
, h
)
6081 || (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
6082 && h
->root
.type
== bfd_link_hash_undefweak
))))
6084 /* This case can occur if we saw a CALL26 reloc in
6085 an input file, but the symbol wasn't referred to
6086 by a dynamic object or all references were
6087 garbage collected. In which case we can end up
6089 h
->plt
.offset
= (bfd_vma
) - 1;
6096 /* Otherwise, reset to -1. */
6097 h
->plt
.offset
= (bfd_vma
) - 1;
6100 /* If this is a weak symbol, and there is a real definition, the
6101 processor independent code will have arranged for us to see the
6102 real definition first, and we can just use the same value. */
6103 if (h
->u
.weakdef
!= NULL
)
6105 BFD_ASSERT (h
->u
.weakdef
->root
.type
== bfd_link_hash_defined
6106 || h
->u
.weakdef
->root
.type
== bfd_link_hash_defweak
);
6107 h
->root
.u
.def
.section
= h
->u
.weakdef
->root
.u
.def
.section
;
6108 h
->root
.u
.def
.value
= h
->u
.weakdef
->root
.u
.def
.value
;
6109 if (ELIMINATE_COPY_RELOCS
|| info
->nocopyreloc
)
6110 h
->non_got_ref
= h
->u
.weakdef
->non_got_ref
;
6114 /* If we are creating a shared library, we must presume that the
6115 only references to the symbol are via the global offset table.
6116 For such cases we need not do anything here; the relocations will
6117 be handled correctly by relocate_section. */
6121 /* If there are no references to this symbol that do not use the
6122 GOT, we don't need to generate a copy reloc. */
6123 if (!h
->non_got_ref
)
6126 /* If -z nocopyreloc was given, we won't generate them either. */
6127 if (info
->nocopyreloc
)
6133 /* We must allocate the symbol in our .dynbss section, which will
6134 become part of the .bss section of the executable. There will be
6135 an entry for this symbol in the .dynsym section. The dynamic
6136 object will contain position independent code, so all references
6137 from the dynamic object to this symbol will go through the global
6138 offset table. The dynamic linker will use the .dynsym entry to
6139 determine the address it must put in the global offset table, so
6140 both the dynamic object and the regular object will refer to the
6141 same memory location for the variable. */
6143 htab
= elf_aarch64_hash_table (info
);
6145 /* We must generate a R_AARCH64_COPY reloc to tell the dynamic linker
6146 to copy the initial value out of the dynamic object and into the
6147 runtime process image. */
6148 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0 && h
->size
!= 0)
6150 htab
->srelbss
->size
+= RELOC_SIZE (htab
);
6156 return _bfd_elf_adjust_dynamic_copy (info
, h
, s
);
6161 elfNN_aarch64_allocate_local_symbols (bfd
*abfd
, unsigned number
)
6163 struct elf_aarch64_local_symbol
*locals
;
6164 locals
= elf_aarch64_locals (abfd
);
6167 locals
= (struct elf_aarch64_local_symbol
*)
6168 bfd_zalloc (abfd
, number
* sizeof (struct elf_aarch64_local_symbol
));
6171 elf_aarch64_locals (abfd
) = locals
;
6176 /* Create the .got section to hold the global offset table. */
6179 aarch64_elf_create_got_section (bfd
*abfd
, struct bfd_link_info
*info
)
6181 const struct elf_backend_data
*bed
= get_elf_backend_data (abfd
);
6184 struct elf_link_hash_entry
*h
;
6185 struct elf_link_hash_table
*htab
= elf_hash_table (info
);
6187 /* This function may be called more than once. */
6188 s
= bfd_get_linker_section (abfd
, ".got");
6192 flags
= bed
->dynamic_sec_flags
;
6194 s
= bfd_make_section_anyway_with_flags (abfd
,
6195 (bed
->rela_plts_and_copies_p
6196 ? ".rela.got" : ".rel.got"),
6197 (bed
->dynamic_sec_flags
6200 || ! bfd_set_section_alignment (abfd
, s
, bed
->s
->log_file_align
))
6204 s
= bfd_make_section_anyway_with_flags (abfd
, ".got", flags
);
6206 || !bfd_set_section_alignment (abfd
, s
, bed
->s
->log_file_align
))
6209 htab
->sgot
->size
+= GOT_ENTRY_SIZE
;
6211 if (bed
->want_got_sym
)
6213 /* Define the symbol _GLOBAL_OFFSET_TABLE_ at the start of the .got
6214 (or .got.plt) section. We don't do this in the linker script
6215 because we don't want to define the symbol if we are not creating
6216 a global offset table. */
6217 h
= _bfd_elf_define_linkage_sym (abfd
, info
, s
,
6218 "_GLOBAL_OFFSET_TABLE_");
6219 elf_hash_table (info
)->hgot
= h
;
6224 if (bed
->want_got_plt
)
6226 s
= bfd_make_section_anyway_with_flags (abfd
, ".got.plt", flags
);
6228 || !bfd_set_section_alignment (abfd
, s
,
6229 bed
->s
->log_file_align
))
6234 /* The first bit of the global offset table is the header. */
6235 s
->size
+= bed
->got_header_size
;
6240 /* Look through the relocs for a section during the first phase. */
6243 elfNN_aarch64_check_relocs (bfd
*abfd
, struct bfd_link_info
*info
,
6244 asection
*sec
, const Elf_Internal_Rela
*relocs
)
6246 Elf_Internal_Shdr
*symtab_hdr
;
6247 struct elf_link_hash_entry
**sym_hashes
;
6248 const Elf_Internal_Rela
*rel
;
6249 const Elf_Internal_Rela
*rel_end
;
6252 struct elf_aarch64_link_hash_table
*htab
;
6254 if (info
->relocatable
)
6257 BFD_ASSERT (is_aarch64_elf (abfd
));
6259 htab
= elf_aarch64_hash_table (info
);
6262 symtab_hdr
= &elf_symtab_hdr (abfd
);
6263 sym_hashes
= elf_sym_hashes (abfd
);
6265 rel_end
= relocs
+ sec
->reloc_count
;
6266 for (rel
= relocs
; rel
< rel_end
; rel
++)
6268 struct elf_link_hash_entry
*h
;
6269 unsigned long r_symndx
;
6270 unsigned int r_type
;
6271 bfd_reloc_code_real_type bfd_r_type
;
6272 Elf_Internal_Sym
*isym
;
6274 r_symndx
= ELFNN_R_SYM (rel
->r_info
);
6275 r_type
= ELFNN_R_TYPE (rel
->r_info
);
6277 if (r_symndx
>= NUM_SHDR_ENTRIES (symtab_hdr
))
6279 (*_bfd_error_handler
) (_("%B: bad symbol index: %d"), abfd
,
6284 if (r_symndx
< symtab_hdr
->sh_info
)
6286 /* A local symbol. */
6287 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
6292 /* Check relocation against local STT_GNU_IFUNC symbol. */
6293 if (ELF_ST_TYPE (isym
->st_info
) == STT_GNU_IFUNC
)
6295 h
= elfNN_aarch64_get_local_sym_hash (htab
, abfd
, rel
,
6300 /* Fake a STT_GNU_IFUNC symbol. */
6301 h
->type
= STT_GNU_IFUNC
;
6304 h
->forced_local
= 1;
6305 h
->root
.type
= bfd_link_hash_defined
;
6312 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
6313 while (h
->root
.type
== bfd_link_hash_indirect
6314 || h
->root
.type
== bfd_link_hash_warning
)
6315 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
6317 /* PR15323, ref flags aren't set for references in the same
6319 h
->root
.non_ir_ref
= 1;
6322 /* Could be done earlier, if h were already available. */
6323 bfd_r_type
= aarch64_tls_transition (abfd
, info
, r_type
, h
, r_symndx
);
6327 /* Create the ifunc sections for static executables. If we
6328 never see an indirect function symbol nor we are building
6329 a static executable, those sections will be empty and
6330 won't appear in output. */
6336 case BFD_RELOC_AARCH64_ADD_LO12
:
6337 case BFD_RELOC_AARCH64_ADR_GOT_PAGE
:
6338 case BFD_RELOC_AARCH64_ADR_HI21_PCREL
:
6339 case BFD_RELOC_AARCH64_CALL26
:
6340 case BFD_RELOC_AARCH64_GOT_LD_PREL19
:
6341 case BFD_RELOC_AARCH64_JUMP26
:
6342 case BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14
:
6343 case BFD_RELOC_AARCH64_LD32_GOT_LO12_NC
:
6344 case BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15
:
6345 case BFD_RELOC_AARCH64_LD64_GOT_LO12_NC
:
6346 case BFD_RELOC_AARCH64_NN
:
6347 if (htab
->root
.dynobj
== NULL
)
6348 htab
->root
.dynobj
= abfd
;
6349 if (!_bfd_elf_create_ifunc_sections (htab
->root
.dynobj
, info
))
6354 /* It is referenced by a non-shared object. */
6356 h
->root
.non_ir_ref
= 1;
6361 case BFD_RELOC_AARCH64_NN
:
6363 /* We don't need to handle relocs into sections not going into
6364 the "real" output. */
6365 if ((sec
->flags
& SEC_ALLOC
) == 0)
6373 h
->plt
.refcount
+= 1;
6374 h
->pointer_equality_needed
= 1;
6377 /* No need to do anything if we're not creating a shared
6383 struct elf_dyn_relocs
*p
;
6384 struct elf_dyn_relocs
**head
;
6386 /* We must copy these reloc types into the output file.
6387 Create a reloc section in dynobj and make room for
6391 if (htab
->root
.dynobj
== NULL
)
6392 htab
->root
.dynobj
= abfd
;
6394 sreloc
= _bfd_elf_make_dynamic_reloc_section
6395 (sec
, htab
->root
.dynobj
, LOG_FILE_ALIGN
, abfd
, /*rela? */ TRUE
);
6401 /* If this is a global symbol, we count the number of
6402 relocations we need for this symbol. */
6405 struct elf_aarch64_link_hash_entry
*eh
;
6406 eh
= (struct elf_aarch64_link_hash_entry
*) h
;
6407 head
= &eh
->dyn_relocs
;
6411 /* Track dynamic relocs needed for local syms too.
6412 We really need local syms available to do this
6418 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
6423 s
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
6427 /* Beware of type punned pointers vs strict aliasing
6429 vpp
= &(elf_section_data (s
)->local_dynrel
);
6430 head
= (struct elf_dyn_relocs
**) vpp
;
6434 if (p
== NULL
|| p
->sec
!= sec
)
6436 bfd_size_type amt
= sizeof *p
;
6437 p
= ((struct elf_dyn_relocs
*)
6438 bfd_zalloc (htab
->root
.dynobj
, amt
));
6451 /* RR: We probably want to keep a consistency check that
6452 there are no dangling GOT_PAGE relocs. */
6453 case BFD_RELOC_AARCH64_ADR_GOT_PAGE
:
6454 case BFD_RELOC_AARCH64_GOT_LD_PREL19
:
6455 case BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14
:
6456 case BFD_RELOC_AARCH64_LD32_GOT_LO12_NC
:
6457 case BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15
:
6458 case BFD_RELOC_AARCH64_LD64_GOT_LO12_NC
:
6459 case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12_NC
:
6460 case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21
:
6461 case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21
:
6462 case BFD_RELOC_AARCH64_TLSDESC_LD32_LO12_NC
:
6463 case BFD_RELOC_AARCH64_TLSDESC_LD64_LO12_NC
:
6464 case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19
:
6465 case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC
:
6466 case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21
:
6467 case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21
:
6468 case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21
:
6469 case BFD_RELOC_AARCH64_TLSIE_LD32_GOTTPREL_LO12_NC
:
6470 case BFD_RELOC_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC
:
6471 case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19
:
6472 case BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_HI12
:
6473 case BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_LO12
:
6474 case BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_LO12_NC
:
6475 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0
:
6476 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC
:
6477 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1
:
6478 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1_NC
:
6479 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G2
:
6482 unsigned old_got_type
;
6484 got_type
= aarch64_reloc_got_type (bfd_r_type
);
6488 h
->got
.refcount
+= 1;
6489 old_got_type
= elf_aarch64_hash_entry (h
)->got_type
;
6493 struct elf_aarch64_local_symbol
*locals
;
6495 if (!elfNN_aarch64_allocate_local_symbols
6496 (abfd
, symtab_hdr
->sh_info
))
6499 locals
= elf_aarch64_locals (abfd
);
6500 BFD_ASSERT (r_symndx
< symtab_hdr
->sh_info
);
6501 locals
[r_symndx
].got_refcount
+= 1;
6502 old_got_type
= locals
[r_symndx
].got_type
;
6505 /* If a variable is accessed with both general dynamic TLS
6506 methods, two slots may be created. */
6507 if (GOT_TLS_GD_ANY_P (old_got_type
) && GOT_TLS_GD_ANY_P (got_type
))
6508 got_type
|= old_got_type
;
6510 /* We will already have issued an error message if there
6511 is a TLS/non-TLS mismatch, based on the symbol type.
6512 So just combine any TLS types needed. */
6513 if (old_got_type
!= GOT_UNKNOWN
&& old_got_type
!= GOT_NORMAL
6514 && got_type
!= GOT_NORMAL
)
6515 got_type
|= old_got_type
;
6517 /* If the symbol is accessed by both IE and GD methods, we
6518 are able to relax. Turn off the GD flag, without
6519 messing up with any other kind of TLS types that may be
6521 if ((got_type
& GOT_TLS_IE
) && GOT_TLS_GD_ANY_P (got_type
))
6522 got_type
&= ~ (GOT_TLSDESC_GD
| GOT_TLS_GD
);
6524 if (old_got_type
!= got_type
)
6527 elf_aarch64_hash_entry (h
)->got_type
= got_type
;
6530 struct elf_aarch64_local_symbol
*locals
;
6531 locals
= elf_aarch64_locals (abfd
);
6532 BFD_ASSERT (r_symndx
< symtab_hdr
->sh_info
);
6533 locals
[r_symndx
].got_type
= got_type
;
6537 if (htab
->root
.dynobj
== NULL
)
6538 htab
->root
.dynobj
= abfd
;
6539 if (! aarch64_elf_create_got_section (htab
->root
.dynobj
, info
))
6544 case BFD_RELOC_AARCH64_MOVW_G0_NC
:
6545 case BFD_RELOC_AARCH64_MOVW_G1_NC
:
6546 case BFD_RELOC_AARCH64_MOVW_G2_NC
:
6547 case BFD_RELOC_AARCH64_MOVW_G3
:
6550 int howto_index
= bfd_r_type
- BFD_RELOC_AARCH64_RELOC_START
;
6551 (*_bfd_error_handler
)
6552 (_("%B: relocation %s against `%s' can not be used when making "
6553 "a shared object; recompile with -fPIC"),
6554 abfd
, elfNN_aarch64_howto_table
[howto_index
].name
,
6555 (h
) ? h
->root
.root
.string
: "a local symbol");
6556 bfd_set_error (bfd_error_bad_value
);
6560 case BFD_RELOC_AARCH64_ADR_HI21_NC_PCREL
:
6561 case BFD_RELOC_AARCH64_ADR_HI21_PCREL
:
6562 case BFD_RELOC_AARCH64_ADR_LO21_PCREL
:
6563 if (h
!= NULL
&& info
->executable
)
6565 /* If this reloc is in a read-only section, we might
6566 need a copy reloc. We can't check reliably at this
6567 stage whether the section is read-only, as input
6568 sections have not yet been mapped to output sections.
6569 Tentatively set the flag for now, and correct in
6570 adjust_dynamic_symbol. */
6572 h
->plt
.refcount
+= 1;
6573 h
->pointer_equality_needed
= 1;
6575 /* FIXME:: RR need to handle these in shared libraries
6576 and essentially bomb out as these being non-PIC
6577 relocations in shared libraries. */
6580 case BFD_RELOC_AARCH64_CALL26
:
6581 case BFD_RELOC_AARCH64_JUMP26
:
6582 /* If this is a local symbol then we resolve it
6583 directly without creating a PLT entry. */
6588 if (h
->plt
.refcount
<= 0)
6589 h
->plt
.refcount
= 1;
6591 h
->plt
.refcount
+= 1;
6602 /* Treat mapping symbols as special target symbols. */
6605 elfNN_aarch64_is_target_special_symbol (bfd
*abfd ATTRIBUTE_UNUSED
,
6608 return bfd_is_aarch64_special_symbol_name (sym
->name
,
6609 BFD_AARCH64_SPECIAL_SYM_TYPE_ANY
);
6612 /* This is a copy of elf_find_function () from elf.c except that
6613 AArch64 mapping symbols are ignored when looking for function names. */
6616 aarch64_elf_find_function (bfd
*abfd ATTRIBUTE_UNUSED
,
6620 const char **filename_ptr
,
6621 const char **functionname_ptr
)
6623 const char *filename
= NULL
;
6624 asymbol
*func
= NULL
;
6625 bfd_vma low_func
= 0;
6628 for (p
= symbols
; *p
!= NULL
; p
++)
6632 q
= (elf_symbol_type
*) * p
;
6634 switch (ELF_ST_TYPE (q
->internal_elf_sym
.st_info
))
6639 filename
= bfd_asymbol_name (&q
->symbol
);
6643 /* Skip mapping symbols. */
6644 if ((q
->symbol
.flags
& BSF_LOCAL
)
6645 && (bfd_is_aarch64_special_symbol_name
6646 (q
->symbol
.name
, BFD_AARCH64_SPECIAL_SYM_TYPE_ANY
)))
6649 if (bfd_get_section (&q
->symbol
) == section
6650 && q
->symbol
.value
>= low_func
&& q
->symbol
.value
<= offset
)
6652 func
= (asymbol
*) q
;
6653 low_func
= q
->symbol
.value
;
6663 *filename_ptr
= filename
;
6664 if (functionname_ptr
)
6665 *functionname_ptr
= bfd_asymbol_name (func
);
6671 /* Find the nearest line to a particular section and offset, for error
6672 reporting. This code is a duplicate of the code in elf.c, except
6673 that it uses aarch64_elf_find_function. */
6676 elfNN_aarch64_find_nearest_line (bfd
*abfd
,
6680 const char **filename_ptr
,
6681 const char **functionname_ptr
,
6682 unsigned int *line_ptr
,
6683 unsigned int *discriminator_ptr
)
6685 bfd_boolean found
= FALSE
;
6687 if (_bfd_dwarf2_find_nearest_line (abfd
, symbols
, NULL
, section
, offset
,
6688 filename_ptr
, functionname_ptr
,
6689 line_ptr
, discriminator_ptr
,
6690 dwarf_debug_sections
, 0,
6691 &elf_tdata (abfd
)->dwarf2_find_line_info
))
6693 if (!*functionname_ptr
)
6694 aarch64_elf_find_function (abfd
, symbols
, section
, offset
,
6695 *filename_ptr
? NULL
: filename_ptr
,
6701 /* Skip _bfd_dwarf1_find_nearest_line since no known AArch64
6702 toolchain uses DWARF1. */
6704 if (!_bfd_stab_section_find_nearest_line (abfd
, symbols
, section
, offset
,
6705 &found
, filename_ptr
,
6706 functionname_ptr
, line_ptr
,
6707 &elf_tdata (abfd
)->line_info
))
6710 if (found
&& (*functionname_ptr
|| *line_ptr
))
6713 if (symbols
== NULL
)
6716 if (!aarch64_elf_find_function (abfd
, symbols
, section
, offset
,
6717 filename_ptr
, functionname_ptr
))
6725 elfNN_aarch64_find_inliner_info (bfd
*abfd
,
6726 const char **filename_ptr
,
6727 const char **functionname_ptr
,
6728 unsigned int *line_ptr
)
6731 found
= _bfd_dwarf2_find_inliner_info
6732 (abfd
, filename_ptr
,
6733 functionname_ptr
, line_ptr
, &elf_tdata (abfd
)->dwarf2_find_line_info
);
6739 elfNN_aarch64_post_process_headers (bfd
*abfd
,
6740 struct bfd_link_info
*link_info
)
6742 Elf_Internal_Ehdr
*i_ehdrp
; /* ELF file header, internal form. */
6744 i_ehdrp
= elf_elfheader (abfd
);
6745 i_ehdrp
->e_ident
[EI_ABIVERSION
] = AARCH64_ELF_ABI_VERSION
;
6747 _bfd_elf_post_process_headers (abfd
, link_info
);
6750 static enum elf_reloc_type_class
6751 elfNN_aarch64_reloc_type_class (const struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
6752 const asection
*rel_sec ATTRIBUTE_UNUSED
,
6753 const Elf_Internal_Rela
*rela
)
6755 switch ((int) ELFNN_R_TYPE (rela
->r_info
))
6757 case AARCH64_R (RELATIVE
):
6758 return reloc_class_relative
;
6759 case AARCH64_R (JUMP_SLOT
):
6760 return reloc_class_plt
;
6761 case AARCH64_R (COPY
):
6762 return reloc_class_copy
;
6764 return reloc_class_normal
;
6768 /* Handle an AArch64 specific section when reading an object file. This is
6769 called when bfd_section_from_shdr finds a section with an unknown
6773 elfNN_aarch64_section_from_shdr (bfd
*abfd
,
6774 Elf_Internal_Shdr
*hdr
,
6775 const char *name
, int shindex
)
6777 /* There ought to be a place to keep ELF backend specific flags, but
6778 at the moment there isn't one. We just keep track of the
6779 sections by their name, instead. Fortunately, the ABI gives
6780 names for all the AArch64 specific sections, so we will probably get
6782 switch (hdr
->sh_type
)
6784 case SHT_AARCH64_ATTRIBUTES
:
6791 if (!_bfd_elf_make_section_from_shdr (abfd
, hdr
, name
, shindex
))
6797 /* A structure used to record a list of sections, independently
6798 of the next and prev fields in the asection structure. */
6799 typedef struct section_list
6802 struct section_list
*next
;
6803 struct section_list
*prev
;
6807 /* Unfortunately we need to keep a list of sections for which
6808 an _aarch64_elf_section_data structure has been allocated. This
6809 is because it is possible for functions like elfNN_aarch64_write_section
6810 to be called on a section which has had an elf_data_structure
6811 allocated for it (and so the used_by_bfd field is valid) but
6812 for which the AArch64 extended version of this structure - the
6813 _aarch64_elf_section_data structure - has not been allocated. */
6814 static section_list
*sections_with_aarch64_elf_section_data
= NULL
;
6817 record_section_with_aarch64_elf_section_data (asection
*sec
)
6819 struct section_list
*entry
;
6821 entry
= bfd_malloc (sizeof (*entry
));
6825 entry
->next
= sections_with_aarch64_elf_section_data
;
6827 if (entry
->next
!= NULL
)
6828 entry
->next
->prev
= entry
;
6829 sections_with_aarch64_elf_section_data
= entry
;
6832 static struct section_list
*
6833 find_aarch64_elf_section_entry (asection
*sec
)
6835 struct section_list
*entry
;
6836 static struct section_list
*last_entry
= NULL
;
6838 /* This is a short cut for the typical case where the sections are added
6839 to the sections_with_aarch64_elf_section_data list in forward order and
6840 then looked up here in backwards order. This makes a real difference
6841 to the ld-srec/sec64k.exp linker test. */
6842 entry
= sections_with_aarch64_elf_section_data
;
6843 if (last_entry
!= NULL
)
6845 if (last_entry
->sec
== sec
)
6847 else if (last_entry
->next
!= NULL
&& last_entry
->next
->sec
== sec
)
6848 entry
= last_entry
->next
;
6851 for (; entry
; entry
= entry
->next
)
6852 if (entry
->sec
== sec
)
6856 /* Record the entry prior to this one - it is the entry we are
6857 most likely to want to locate next time. Also this way if we
6858 have been called from
6859 unrecord_section_with_aarch64_elf_section_data () we will not
6860 be caching a pointer that is about to be freed. */
6861 last_entry
= entry
->prev
;
6867 unrecord_section_with_aarch64_elf_section_data (asection
*sec
)
6869 struct section_list
*entry
;
6871 entry
= find_aarch64_elf_section_entry (sec
);
6875 if (entry
->prev
!= NULL
)
6876 entry
->prev
->next
= entry
->next
;
6877 if (entry
->next
!= NULL
)
6878 entry
->next
->prev
= entry
->prev
;
6879 if (entry
== sections_with_aarch64_elf_section_data
)
6880 sections_with_aarch64_elf_section_data
= entry
->next
;
6889 struct bfd_link_info
*info
;
6892 int (*func
) (void *, const char *, Elf_Internal_Sym
*,
6893 asection
*, struct elf_link_hash_entry
*);
6894 } output_arch_syminfo
;
6896 enum map_symbol_type
6903 /* Output a single mapping symbol. */
6906 elfNN_aarch64_output_map_sym (output_arch_syminfo
*osi
,
6907 enum map_symbol_type type
, bfd_vma offset
)
6909 static const char *names
[2] = { "$x", "$d" };
6910 Elf_Internal_Sym sym
;
6912 sym
.st_value
= (osi
->sec
->output_section
->vma
6913 + osi
->sec
->output_offset
+ offset
);
6916 sym
.st_info
= ELF_ST_INFO (STB_LOCAL
, STT_NOTYPE
);
6917 sym
.st_shndx
= osi
->sec_shndx
;
6918 return osi
->func (osi
->finfo
, names
[type
], &sym
, osi
->sec
, NULL
) == 1;
6923 /* Output mapping symbols for PLT entries associated with H. */
6926 elfNN_aarch64_output_plt_map (struct elf_link_hash_entry
*h
, void *inf
)
6928 output_arch_syminfo
*osi
= (output_arch_syminfo
*) inf
;
6931 if (h
->root
.type
== bfd_link_hash_indirect
)
6934 if (h
->root
.type
== bfd_link_hash_warning
)
6935 /* When warning symbols are created, they **replace** the "real"
6936 entry in the hash table, thus we never get to see the real
6937 symbol in a hash traversal. So look at it now. */
6938 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
6940 if (h
->plt
.offset
== (bfd_vma
) - 1)
6943 addr
= h
->plt
.offset
;
6946 if (!elfNN_aarch64_output_map_sym (osi
, AARCH64_MAP_INSN
, addr
))
6953 /* Output a single local symbol for a generated stub. */
6956 elfNN_aarch64_output_stub_sym (output_arch_syminfo
*osi
, const char *name
,
6957 bfd_vma offset
, bfd_vma size
)
6959 Elf_Internal_Sym sym
;
6961 sym
.st_value
= (osi
->sec
->output_section
->vma
6962 + osi
->sec
->output_offset
+ offset
);
6965 sym
.st_info
= ELF_ST_INFO (STB_LOCAL
, STT_FUNC
);
6966 sym
.st_shndx
= osi
->sec_shndx
;
6967 return osi
->func (osi
->finfo
, name
, &sym
, osi
->sec
, NULL
) == 1;
6971 aarch64_map_one_stub (struct bfd_hash_entry
*gen_entry
, void *in_arg
)
6973 struct elf_aarch64_stub_hash_entry
*stub_entry
;
6977 output_arch_syminfo
*osi
;
6979 /* Massage our args to the form they really have. */
6980 stub_entry
= (struct elf_aarch64_stub_hash_entry
*) gen_entry
;
6981 osi
= (output_arch_syminfo
*) in_arg
;
6983 stub_sec
= stub_entry
->stub_sec
;
6985 /* Ensure this stub is attached to the current section being
6987 if (stub_sec
!= osi
->sec
)
6990 addr
= (bfd_vma
) stub_entry
->stub_offset
;
6992 stub_name
= stub_entry
->output_name
;
6994 switch (stub_entry
->stub_type
)
6996 case aarch64_stub_adrp_branch
:
6997 if (!elfNN_aarch64_output_stub_sym (osi
, stub_name
, addr
,
6998 sizeof (aarch64_adrp_branch_stub
)))
7000 if (!elfNN_aarch64_output_map_sym (osi
, AARCH64_MAP_INSN
, addr
))
7003 case aarch64_stub_long_branch
:
7004 if (!elfNN_aarch64_output_stub_sym
7005 (osi
, stub_name
, addr
, sizeof (aarch64_long_branch_stub
)))
7007 if (!elfNN_aarch64_output_map_sym (osi
, AARCH64_MAP_INSN
, addr
))
7009 if (!elfNN_aarch64_output_map_sym (osi
, AARCH64_MAP_DATA
, addr
+ 16))
7012 case aarch64_stub_erratum_835769_veneer
:
7013 if (!elfNN_aarch64_output_stub_sym (osi
, stub_name
, addr
,
7014 sizeof (aarch64_erratum_835769_stub
)))
7016 if (!elfNN_aarch64_output_map_sym (osi
, AARCH64_MAP_INSN
, addr
))
7019 case aarch64_stub_erratum_843419_veneer
:
7020 if (!elfNN_aarch64_output_stub_sym (osi
, stub_name
, addr
,
7021 sizeof (aarch64_erratum_843419_stub
)))
7023 if (!elfNN_aarch64_output_map_sym (osi
, AARCH64_MAP_INSN
, addr
))
7034 /* Output mapping symbols for linker generated sections. */
7037 elfNN_aarch64_output_arch_local_syms (bfd
*output_bfd
,
7038 struct bfd_link_info
*info
,
7040 int (*func
) (void *, const char *,
7043 struct elf_link_hash_entry
7046 output_arch_syminfo osi
;
7047 struct elf_aarch64_link_hash_table
*htab
;
7049 htab
= elf_aarch64_hash_table (info
);
7055 /* Long calls stubs. */
7056 if (htab
->stub_bfd
&& htab
->stub_bfd
->sections
)
7060 for (stub_sec
= htab
->stub_bfd
->sections
;
7061 stub_sec
!= NULL
; stub_sec
= stub_sec
->next
)
7063 /* Ignore non-stub sections. */
7064 if (!strstr (stub_sec
->name
, STUB_SUFFIX
))
7069 osi
.sec_shndx
= _bfd_elf_section_from_bfd_section
7070 (output_bfd
, osi
.sec
->output_section
);
7072 /* The first instruction in a stub is always a branch. */
7073 if (!elfNN_aarch64_output_map_sym (&osi
, AARCH64_MAP_INSN
, 0))
7076 bfd_hash_traverse (&htab
->stub_hash_table
, aarch64_map_one_stub
,
7081 /* Finally, output mapping symbols for the PLT. */
7082 if (!htab
->root
.splt
|| htab
->root
.splt
->size
== 0)
7085 /* For now live without mapping symbols for the plt. */
7086 osi
.sec_shndx
= _bfd_elf_section_from_bfd_section
7087 (output_bfd
, htab
->root
.splt
->output_section
);
7088 osi
.sec
= htab
->root
.splt
;
7090 elf_link_hash_traverse (&htab
->root
, elfNN_aarch64_output_plt_map
,
7097 /* Allocate target specific section data. */
7100 elfNN_aarch64_new_section_hook (bfd
*abfd
, asection
*sec
)
7102 if (!sec
->used_by_bfd
)
7104 _aarch64_elf_section_data
*sdata
;
7105 bfd_size_type amt
= sizeof (*sdata
);
7107 sdata
= bfd_zalloc (abfd
, amt
);
7110 sec
->used_by_bfd
= sdata
;
7113 record_section_with_aarch64_elf_section_data (sec
);
7115 return _bfd_elf_new_section_hook (abfd
, sec
);
7120 unrecord_section_via_map_over_sections (bfd
*abfd ATTRIBUTE_UNUSED
,
7122 void *ignore ATTRIBUTE_UNUSED
)
7124 unrecord_section_with_aarch64_elf_section_data (sec
);
7128 elfNN_aarch64_close_and_cleanup (bfd
*abfd
)
7131 bfd_map_over_sections (abfd
,
7132 unrecord_section_via_map_over_sections
, NULL
);
7134 return _bfd_elf_close_and_cleanup (abfd
);
7138 elfNN_aarch64_bfd_free_cached_info (bfd
*abfd
)
7141 bfd_map_over_sections (abfd
,
7142 unrecord_section_via_map_over_sections
, NULL
);
7144 return _bfd_free_cached_info (abfd
);
7147 /* Create dynamic sections. This is different from the ARM backend in that
7148 the got, plt, gotplt and their relocation sections are all created in the
7149 standard part of the bfd elf backend. */
7152 elfNN_aarch64_create_dynamic_sections (bfd
*dynobj
,
7153 struct bfd_link_info
*info
)
7155 struct elf_aarch64_link_hash_table
*htab
;
7157 /* We need to create .got section. */
7158 if (!aarch64_elf_create_got_section (dynobj
, info
))
7161 if (!_bfd_elf_create_dynamic_sections (dynobj
, info
))
7164 htab
= elf_aarch64_hash_table (info
);
7165 htab
->sdynbss
= bfd_get_linker_section (dynobj
, ".dynbss");
7167 htab
->srelbss
= bfd_get_linker_section (dynobj
, ".rela.bss");
7169 if (!htab
->sdynbss
|| (!info
->shared
&& !htab
->srelbss
))
7176 /* Allocate space in .plt, .got and associated reloc sections for
7180 elfNN_aarch64_allocate_dynrelocs (struct elf_link_hash_entry
*h
, void *inf
)
7182 struct bfd_link_info
*info
;
7183 struct elf_aarch64_link_hash_table
*htab
;
7184 struct elf_aarch64_link_hash_entry
*eh
;
7185 struct elf_dyn_relocs
*p
;
7187 /* An example of a bfd_link_hash_indirect symbol is versioned
7188 symbol. For example: __gxx_personality_v0(bfd_link_hash_indirect)
7189 -> __gxx_personality_v0(bfd_link_hash_defined)
7191 There is no need to process bfd_link_hash_indirect symbols here
7192 because we will also be presented with the concrete instance of
7193 the symbol and elfNN_aarch64_copy_indirect_symbol () will have been
7194 called to copy all relevant data from the generic to the concrete
7197 if (h
->root
.type
== bfd_link_hash_indirect
)
7200 if (h
->root
.type
== bfd_link_hash_warning
)
7201 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
7203 info
= (struct bfd_link_info
*) inf
;
7204 htab
= elf_aarch64_hash_table (info
);
7206 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle it
7207 here if it is defined and referenced in a non-shared object. */
7208 if (h
->type
== STT_GNU_IFUNC
7211 else if (htab
->root
.dynamic_sections_created
&& h
->plt
.refcount
> 0)
7213 /* Make sure this symbol is output as a dynamic symbol.
7214 Undefined weak syms won't yet be marked as dynamic. */
7215 if (h
->dynindx
== -1 && !h
->forced_local
)
7217 if (!bfd_elf_link_record_dynamic_symbol (info
, h
))
7221 if (info
->shared
|| WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h
))
7223 asection
*s
= htab
->root
.splt
;
7225 /* If this is the first .plt entry, make room for the special
7228 s
->size
+= htab
->plt_header_size
;
7230 h
->plt
.offset
= s
->size
;
7232 /* If this symbol is not defined in a regular file, and we are
7233 not generating a shared library, then set the symbol to this
7234 location in the .plt. This is required to make function
7235 pointers compare as equal between the normal executable and
7236 the shared library. */
7237 if (!info
->shared
&& !h
->def_regular
)
7239 h
->root
.u
.def
.section
= s
;
7240 h
->root
.u
.def
.value
= h
->plt
.offset
;
7243 /* Make room for this entry. For now we only create the
7244 small model PLT entries. We later need to find a way
7245 of relaxing into these from the large model PLT entries. */
7246 s
->size
+= PLT_SMALL_ENTRY_SIZE
;
7248 /* We also need to make an entry in the .got.plt section, which
7249 will be placed in the .got section by the linker script. */
7250 htab
->root
.sgotplt
->size
+= GOT_ENTRY_SIZE
;
7252 /* We also need to make an entry in the .rela.plt section. */
7253 htab
->root
.srelplt
->size
+= RELOC_SIZE (htab
);
7255 /* We need to ensure that all GOT entries that serve the PLT
7256 are consecutive with the special GOT slots [0] [1] and
7257 [2]. Any addtional relocations, such as
7258 R_AARCH64_TLSDESC, must be placed after the PLT related
7259 entries. We abuse the reloc_count such that during
7260 sizing we adjust reloc_count to indicate the number of
7261 PLT related reserved entries. In subsequent phases when
7262 filling in the contents of the reloc entries, PLT related
7263 entries are placed by computing their PLT index (0
7264 .. reloc_count). While other none PLT relocs are placed
7265 at the slot indicated by reloc_count and reloc_count is
7268 htab
->root
.srelplt
->reloc_count
++;
7272 h
->plt
.offset
= (bfd_vma
) - 1;
7278 h
->plt
.offset
= (bfd_vma
) - 1;
7282 eh
= (struct elf_aarch64_link_hash_entry
*) h
;
7283 eh
->tlsdesc_got_jump_table_offset
= (bfd_vma
) - 1;
7285 if (h
->got
.refcount
> 0)
7288 unsigned got_type
= elf_aarch64_hash_entry (h
)->got_type
;
7290 h
->got
.offset
= (bfd_vma
) - 1;
7292 dyn
= htab
->root
.dynamic_sections_created
;
7294 /* Make sure this symbol is output as a dynamic symbol.
7295 Undefined weak syms won't yet be marked as dynamic. */
7296 if (dyn
&& h
->dynindx
== -1 && !h
->forced_local
)
7298 if (!bfd_elf_link_record_dynamic_symbol (info
, h
))
7302 if (got_type
== GOT_UNKNOWN
)
7305 else if (got_type
== GOT_NORMAL
)
7307 h
->got
.offset
= htab
->root
.sgot
->size
;
7308 htab
->root
.sgot
->size
+= GOT_ENTRY_SIZE
;
7309 if ((ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
7310 || h
->root
.type
!= bfd_link_hash_undefweak
)
7312 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, 0, h
)))
7314 htab
->root
.srelgot
->size
+= RELOC_SIZE (htab
);
7320 if (got_type
& GOT_TLSDESC_GD
)
7322 eh
->tlsdesc_got_jump_table_offset
=
7323 (htab
->root
.sgotplt
->size
7324 - aarch64_compute_jump_table_size (htab
));
7325 htab
->root
.sgotplt
->size
+= GOT_ENTRY_SIZE
* 2;
7326 h
->got
.offset
= (bfd_vma
) - 2;
7329 if (got_type
& GOT_TLS_GD
)
7331 h
->got
.offset
= htab
->root
.sgot
->size
;
7332 htab
->root
.sgot
->size
+= GOT_ENTRY_SIZE
* 2;
7335 if (got_type
& GOT_TLS_IE
)
7337 h
->got
.offset
= htab
->root
.sgot
->size
;
7338 htab
->root
.sgot
->size
+= GOT_ENTRY_SIZE
;
7341 indx
= h
&& h
->dynindx
!= -1 ? h
->dynindx
: 0;
7342 if ((ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
7343 || h
->root
.type
!= bfd_link_hash_undefweak
)
7346 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, 0, h
)))
7348 if (got_type
& GOT_TLSDESC_GD
)
7350 htab
->root
.srelplt
->size
+= RELOC_SIZE (htab
);
7351 /* Note reloc_count not incremented here! We have
7352 already adjusted reloc_count for this relocation
7355 /* TLSDESC PLT is now needed, but not yet determined. */
7356 htab
->tlsdesc_plt
= (bfd_vma
) - 1;
7359 if (got_type
& GOT_TLS_GD
)
7360 htab
->root
.srelgot
->size
+= RELOC_SIZE (htab
) * 2;
7362 if (got_type
& GOT_TLS_IE
)
7363 htab
->root
.srelgot
->size
+= RELOC_SIZE (htab
);
7369 h
->got
.offset
= (bfd_vma
) - 1;
7372 if (eh
->dyn_relocs
== NULL
)
7375 /* In the shared -Bsymbolic case, discard space allocated for
7376 dynamic pc-relative relocs against symbols which turn out to be
7377 defined in regular objects. For the normal shared case, discard
7378 space for pc-relative relocs that have become local due to symbol
7379 visibility changes. */
7383 /* Relocs that use pc_count are those that appear on a call
7384 insn, or certain REL relocs that can generated via assembly.
7385 We want calls to protected symbols to resolve directly to the
7386 function rather than going via the plt. If people want
7387 function pointer comparisons to work as expected then they
7388 should avoid writing weird assembly. */
7389 if (SYMBOL_CALLS_LOCAL (info
, h
))
7391 struct elf_dyn_relocs
**pp
;
7393 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
;)
7395 p
->count
-= p
->pc_count
;
7404 /* Also discard relocs on undefined weak syms with non-default
7406 if (eh
->dyn_relocs
!= NULL
&& h
->root
.type
== bfd_link_hash_undefweak
)
7408 if (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
)
7409 eh
->dyn_relocs
= NULL
;
7411 /* Make sure undefined weak symbols are output as a dynamic
7413 else if (h
->dynindx
== -1
7415 && !bfd_elf_link_record_dynamic_symbol (info
, h
))
7420 else if (ELIMINATE_COPY_RELOCS
)
7422 /* For the non-shared case, discard space for relocs against
7423 symbols which turn out to need copy relocs or are not
7429 || (htab
->root
.dynamic_sections_created
7430 && (h
->root
.type
== bfd_link_hash_undefweak
7431 || h
->root
.type
== bfd_link_hash_undefined
))))
7433 /* Make sure this symbol is output as a dynamic symbol.
7434 Undefined weak syms won't yet be marked as dynamic. */
7435 if (h
->dynindx
== -1
7437 && !bfd_elf_link_record_dynamic_symbol (info
, h
))
7440 /* If that succeeded, we know we'll be keeping all the
7442 if (h
->dynindx
!= -1)
7446 eh
->dyn_relocs
= NULL
;
7451 /* Finally, allocate space. */
7452 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
7456 sreloc
= elf_section_data (p
->sec
)->sreloc
;
7458 BFD_ASSERT (sreloc
!= NULL
);
7460 sreloc
->size
+= p
->count
* RELOC_SIZE (htab
);
7466 /* Allocate space in .plt, .got and associated reloc sections for
7467 ifunc dynamic relocs. */
7470 elfNN_aarch64_allocate_ifunc_dynrelocs (struct elf_link_hash_entry
*h
,
7473 struct bfd_link_info
*info
;
7474 struct elf_aarch64_link_hash_table
*htab
;
7475 struct elf_aarch64_link_hash_entry
*eh
;
7477 /* An example of a bfd_link_hash_indirect symbol is versioned
7478 symbol. For example: __gxx_personality_v0(bfd_link_hash_indirect)
7479 -> __gxx_personality_v0(bfd_link_hash_defined)
7481 There is no need to process bfd_link_hash_indirect symbols here
7482 because we will also be presented with the concrete instance of
7483 the symbol and elfNN_aarch64_copy_indirect_symbol () will have been
7484 called to copy all relevant data from the generic to the concrete
7487 if (h
->root
.type
== bfd_link_hash_indirect
)
7490 if (h
->root
.type
== bfd_link_hash_warning
)
7491 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
7493 info
= (struct bfd_link_info
*) inf
;
7494 htab
= elf_aarch64_hash_table (info
);
7496 eh
= (struct elf_aarch64_link_hash_entry
*) h
;
7498 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle it
7499 here if it is defined and referenced in a non-shared object. */
7500 if (h
->type
== STT_GNU_IFUNC
7502 return _bfd_elf_allocate_ifunc_dyn_relocs (info
, h
,
7504 htab
->plt_entry_size
,
7505 htab
->plt_header_size
,
7510 /* Allocate space in .plt, .got and associated reloc sections for
7511 local dynamic relocs. */
7514 elfNN_aarch64_allocate_local_dynrelocs (void **slot
, void *inf
)
7516 struct elf_link_hash_entry
*h
7517 = (struct elf_link_hash_entry
*) *slot
;
7519 if (h
->type
!= STT_GNU_IFUNC
7523 || h
->root
.type
!= bfd_link_hash_defined
)
7526 return elfNN_aarch64_allocate_dynrelocs (h
, inf
);
7529 /* Allocate space in .plt, .got and associated reloc sections for
7530 local ifunc dynamic relocs. */
7533 elfNN_aarch64_allocate_local_ifunc_dynrelocs (void **slot
, void *inf
)
7535 struct elf_link_hash_entry
*h
7536 = (struct elf_link_hash_entry
*) *slot
;
7538 if (h
->type
!= STT_GNU_IFUNC
7542 || h
->root
.type
!= bfd_link_hash_defined
)
7545 return elfNN_aarch64_allocate_ifunc_dynrelocs (h
, inf
);
7548 /* Find any dynamic relocs that apply to read-only sections. */
7551 aarch64_readonly_dynrelocs (struct elf_link_hash_entry
* h
, void * inf
)
7553 struct elf_aarch64_link_hash_entry
* eh
;
7554 struct elf_dyn_relocs
* p
;
7556 eh
= (struct elf_aarch64_link_hash_entry
*) h
;
7557 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
7559 asection
*s
= p
->sec
;
7561 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
7563 struct bfd_link_info
*info
= (struct bfd_link_info
*) inf
;
7565 info
->flags
|= DF_TEXTREL
;
7567 /* Not an error, just cut short the traversal. */
7574 /* This is the most important function of all . Innocuosly named
7577 elfNN_aarch64_size_dynamic_sections (bfd
*output_bfd ATTRIBUTE_UNUSED
,
7578 struct bfd_link_info
*info
)
7580 struct elf_aarch64_link_hash_table
*htab
;
7586 htab
= elf_aarch64_hash_table ((info
));
7587 dynobj
= htab
->root
.dynobj
;
7589 BFD_ASSERT (dynobj
!= NULL
);
7591 if (htab
->root
.dynamic_sections_created
)
7593 if (info
->executable
)
7595 s
= bfd_get_linker_section (dynobj
, ".interp");
7598 s
->size
= sizeof ELF_DYNAMIC_INTERPRETER
;
7599 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
7603 /* Set up .got offsets for local syms, and space for local dynamic
7605 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
7607 struct elf_aarch64_local_symbol
*locals
= NULL
;
7608 Elf_Internal_Shdr
*symtab_hdr
;
7612 if (!is_aarch64_elf (ibfd
))
7615 for (s
= ibfd
->sections
; s
!= NULL
; s
= s
->next
)
7617 struct elf_dyn_relocs
*p
;
7619 for (p
= (struct elf_dyn_relocs
*)
7620 (elf_section_data (s
)->local_dynrel
); p
!= NULL
; p
= p
->next
)
7622 if (!bfd_is_abs_section (p
->sec
)
7623 && bfd_is_abs_section (p
->sec
->output_section
))
7625 /* Input section has been discarded, either because
7626 it is a copy of a linkonce section or due to
7627 linker script /DISCARD/, so we'll be discarding
7630 else if (p
->count
!= 0)
7632 srel
= elf_section_data (p
->sec
)->sreloc
;
7633 srel
->size
+= p
->count
* RELOC_SIZE (htab
);
7634 if ((p
->sec
->output_section
->flags
& SEC_READONLY
) != 0)
7635 info
->flags
|= DF_TEXTREL
;
7640 locals
= elf_aarch64_locals (ibfd
);
7644 symtab_hdr
= &elf_symtab_hdr (ibfd
);
7645 srel
= htab
->root
.srelgot
;
7646 for (i
= 0; i
< symtab_hdr
->sh_info
; i
++)
7648 locals
[i
].got_offset
= (bfd_vma
) - 1;
7649 locals
[i
].tlsdesc_got_jump_table_offset
= (bfd_vma
) - 1;
7650 if (locals
[i
].got_refcount
> 0)
7652 unsigned got_type
= locals
[i
].got_type
;
7653 if (got_type
& GOT_TLSDESC_GD
)
7655 locals
[i
].tlsdesc_got_jump_table_offset
=
7656 (htab
->root
.sgotplt
->size
7657 - aarch64_compute_jump_table_size (htab
));
7658 htab
->root
.sgotplt
->size
+= GOT_ENTRY_SIZE
* 2;
7659 locals
[i
].got_offset
= (bfd_vma
) - 2;
7662 if (got_type
& GOT_TLS_GD
)
7664 locals
[i
].got_offset
= htab
->root
.sgot
->size
;
7665 htab
->root
.sgot
->size
+= GOT_ENTRY_SIZE
* 2;
7668 if (got_type
& GOT_TLS_IE
7669 || got_type
& GOT_NORMAL
)
7671 locals
[i
].got_offset
= htab
->root
.sgot
->size
;
7672 htab
->root
.sgot
->size
+= GOT_ENTRY_SIZE
;
7675 if (got_type
== GOT_UNKNOWN
)
7681 if (got_type
& GOT_TLSDESC_GD
)
7683 htab
->root
.srelplt
->size
+= RELOC_SIZE (htab
);
7684 /* Note RELOC_COUNT not incremented here! */
7685 htab
->tlsdesc_plt
= (bfd_vma
) - 1;
7688 if (got_type
& GOT_TLS_GD
)
7689 htab
->root
.srelgot
->size
+= RELOC_SIZE (htab
) * 2;
7691 if (got_type
& GOT_TLS_IE
7692 || got_type
& GOT_NORMAL
)
7693 htab
->root
.srelgot
->size
+= RELOC_SIZE (htab
);
7698 locals
[i
].got_refcount
= (bfd_vma
) - 1;
7704 /* Allocate global sym .plt and .got entries, and space for global
7705 sym dynamic relocs. */
7706 elf_link_hash_traverse (&htab
->root
, elfNN_aarch64_allocate_dynrelocs
,
7709 /* Allocate global ifunc sym .plt and .got entries, and space for global
7710 ifunc sym dynamic relocs. */
7711 elf_link_hash_traverse (&htab
->root
, elfNN_aarch64_allocate_ifunc_dynrelocs
,
7714 /* Allocate .plt and .got entries, and space for local symbols. */
7715 htab_traverse (htab
->loc_hash_table
,
7716 elfNN_aarch64_allocate_local_dynrelocs
,
7719 /* Allocate .plt and .got entries, and space for local ifunc symbols. */
7720 htab_traverse (htab
->loc_hash_table
,
7721 elfNN_aarch64_allocate_local_ifunc_dynrelocs
,
7724 /* For every jump slot reserved in the sgotplt, reloc_count is
7725 incremented. However, when we reserve space for TLS descriptors,
7726 it's not incremented, so in order to compute the space reserved
7727 for them, it suffices to multiply the reloc count by the jump
7730 if (htab
->root
.srelplt
)
7731 htab
->sgotplt_jump_table_size
= aarch64_compute_jump_table_size (htab
);
7733 if (htab
->tlsdesc_plt
)
7735 if (htab
->root
.splt
->size
== 0)
7736 htab
->root
.splt
->size
+= PLT_ENTRY_SIZE
;
7738 htab
->tlsdesc_plt
= htab
->root
.splt
->size
;
7739 htab
->root
.splt
->size
+= PLT_TLSDESC_ENTRY_SIZE
;
7741 /* If we're not using lazy TLS relocations, don't generate the
7742 GOT entry required. */
7743 if (!(info
->flags
& DF_BIND_NOW
))
7745 htab
->dt_tlsdesc_got
= htab
->root
.sgot
->size
;
7746 htab
->root
.sgot
->size
+= GOT_ENTRY_SIZE
;
7750 /* Init mapping symbols information to use later to distingush between
7751 code and data while scanning for errata. */
7752 if (htab
->fix_erratum_835769
|| htab
->fix_erratum_843419
)
7753 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
7755 if (!is_aarch64_elf (ibfd
))
7757 bfd_elfNN_aarch64_init_maps (ibfd
);
7760 /* We now have determined the sizes of the various dynamic sections.
7761 Allocate memory for them. */
7763 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
7765 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
7768 if (s
== htab
->root
.splt
7769 || s
== htab
->root
.sgot
7770 || s
== htab
->root
.sgotplt
7771 || s
== htab
->root
.iplt
7772 || s
== htab
->root
.igotplt
|| s
== htab
->sdynbss
)
7774 /* Strip this section if we don't need it; see the
7777 else if (CONST_STRNEQ (bfd_get_section_name (dynobj
, s
), ".rela"))
7779 if (s
->size
!= 0 && s
!= htab
->root
.srelplt
)
7782 /* We use the reloc_count field as a counter if we need
7783 to copy relocs into the output file. */
7784 if (s
!= htab
->root
.srelplt
)
7789 /* It's not one of our sections, so don't allocate space. */
7795 /* If we don't need this section, strip it from the
7796 output file. This is mostly to handle .rela.bss and
7797 .rela.plt. We must create both sections in
7798 create_dynamic_sections, because they must be created
7799 before the linker maps input sections to output
7800 sections. The linker does that before
7801 adjust_dynamic_symbol is called, and it is that
7802 function which decides whether anything needs to go
7803 into these sections. */
7805 s
->flags
|= SEC_EXCLUDE
;
7809 if ((s
->flags
& SEC_HAS_CONTENTS
) == 0)
7812 /* Allocate memory for the section contents. We use bfd_zalloc
7813 here in case unused entries are not reclaimed before the
7814 section's contents are written out. This should not happen,
7815 but this way if it does, we get a R_AARCH64_NONE reloc instead
7817 s
->contents
= (bfd_byte
*) bfd_zalloc (dynobj
, s
->size
);
7818 if (s
->contents
== NULL
)
7822 if (htab
->root
.dynamic_sections_created
)
7824 /* Add some entries to the .dynamic section. We fill in the
7825 values later, in elfNN_aarch64_finish_dynamic_sections, but we
7826 must add the entries now so that we get the correct size for
7827 the .dynamic section. The DT_DEBUG entry is filled in by the
7828 dynamic linker and used by the debugger. */
7829 #define add_dynamic_entry(TAG, VAL) \
7830 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
7832 if (info
->executable
)
7834 if (!add_dynamic_entry (DT_DEBUG
, 0))
7838 if (htab
->root
.splt
->size
!= 0)
7840 if (!add_dynamic_entry (DT_PLTGOT
, 0)
7841 || !add_dynamic_entry (DT_PLTRELSZ
, 0)
7842 || !add_dynamic_entry (DT_PLTREL
, DT_RELA
)
7843 || !add_dynamic_entry (DT_JMPREL
, 0))
7846 if (htab
->tlsdesc_plt
7847 && (!add_dynamic_entry (DT_TLSDESC_PLT
, 0)
7848 || !add_dynamic_entry (DT_TLSDESC_GOT
, 0)))
7854 if (!add_dynamic_entry (DT_RELA
, 0)
7855 || !add_dynamic_entry (DT_RELASZ
, 0)
7856 || !add_dynamic_entry (DT_RELAENT
, RELOC_SIZE (htab
)))
7859 /* If any dynamic relocs apply to a read-only section,
7860 then we need a DT_TEXTREL entry. */
7861 if ((info
->flags
& DF_TEXTREL
) == 0)
7862 elf_link_hash_traverse (& htab
->root
, aarch64_readonly_dynrelocs
,
7865 if ((info
->flags
& DF_TEXTREL
) != 0)
7867 if (!add_dynamic_entry (DT_TEXTREL
, 0))
7872 #undef add_dynamic_entry
7878 elf_aarch64_update_plt_entry (bfd
*output_bfd
,
7879 bfd_reloc_code_real_type r_type
,
7880 bfd_byte
*plt_entry
, bfd_vma value
)
7882 reloc_howto_type
*howto
= elfNN_aarch64_howto_from_bfd_reloc (r_type
);
7884 _bfd_aarch64_elf_put_addend (output_bfd
, plt_entry
, r_type
, howto
, value
);
7888 elfNN_aarch64_create_small_pltn_entry (struct elf_link_hash_entry
*h
,
7889 struct elf_aarch64_link_hash_table
7890 *htab
, bfd
*output_bfd
,
7891 struct bfd_link_info
*info
)
7893 bfd_byte
*plt_entry
;
7896 bfd_vma gotplt_entry_address
;
7897 bfd_vma plt_entry_address
;
7898 Elf_Internal_Rela rela
;
7900 asection
*plt
, *gotplt
, *relplt
;
7902 /* When building a static executable, use .iplt, .igot.plt and
7903 .rela.iplt sections for STT_GNU_IFUNC symbols. */
7904 if (htab
->root
.splt
!= NULL
)
7906 plt
= htab
->root
.splt
;
7907 gotplt
= htab
->root
.sgotplt
;
7908 relplt
= htab
->root
.srelplt
;
7912 plt
= htab
->root
.iplt
;
7913 gotplt
= htab
->root
.igotplt
;
7914 relplt
= htab
->root
.irelplt
;
7917 /* Get the index in the procedure linkage table which
7918 corresponds to this symbol. This is the index of this symbol
7919 in all the symbols for which we are making plt entries. The
7920 first entry in the procedure linkage table is reserved.
7922 Get the offset into the .got table of the entry that
7923 corresponds to this function. Each .got entry is GOT_ENTRY_SIZE
7924 bytes. The first three are reserved for the dynamic linker.
7926 For static executables, we don't reserve anything. */
7928 if (plt
== htab
->root
.splt
)
7930 plt_index
= (h
->plt
.offset
- htab
->plt_header_size
) / htab
->plt_entry_size
;
7931 got_offset
= (plt_index
+ 3) * GOT_ENTRY_SIZE
;
7935 plt_index
= h
->plt
.offset
/ htab
->plt_entry_size
;
7936 got_offset
= plt_index
* GOT_ENTRY_SIZE
;
7939 plt_entry
= plt
->contents
+ h
->plt
.offset
;
7940 plt_entry_address
= plt
->output_section
->vma
7941 + plt
->output_offset
+ h
->plt
.offset
;
7942 gotplt_entry_address
= gotplt
->output_section
->vma
+
7943 gotplt
->output_offset
+ got_offset
;
7945 /* Copy in the boiler-plate for the PLTn entry. */
7946 memcpy (plt_entry
, elfNN_aarch64_small_plt_entry
, PLT_SMALL_ENTRY_SIZE
);
7948 /* Fill in the top 21 bits for this: ADRP x16, PLT_GOT + n * 8.
7949 ADRP: ((PG(S+A)-PG(P)) >> 12) & 0x1fffff */
7950 elf_aarch64_update_plt_entry (output_bfd
, BFD_RELOC_AARCH64_ADR_HI21_PCREL
,
7952 PG (gotplt_entry_address
) -
7953 PG (plt_entry_address
));
7955 /* Fill in the lo12 bits for the load from the pltgot. */
7956 elf_aarch64_update_plt_entry (output_bfd
, BFD_RELOC_AARCH64_LDSTNN_LO12
,
7958 PG_OFFSET (gotplt_entry_address
));
7960 /* Fill in the lo12 bits for the add from the pltgot entry. */
7961 elf_aarch64_update_plt_entry (output_bfd
, BFD_RELOC_AARCH64_ADD_LO12
,
7963 PG_OFFSET (gotplt_entry_address
));
7965 /* All the GOTPLT Entries are essentially initialized to PLT0. */
7966 bfd_put_NN (output_bfd
,
7967 plt
->output_section
->vma
+ plt
->output_offset
,
7968 gotplt
->contents
+ got_offset
);
7970 rela
.r_offset
= gotplt_entry_address
;
7972 if (h
->dynindx
== -1
7973 || ((info
->executable
7974 || ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
)
7976 && h
->type
== STT_GNU_IFUNC
))
7978 /* If an STT_GNU_IFUNC symbol is locally defined, generate
7979 R_AARCH64_IRELATIVE instead of R_AARCH64_JUMP_SLOT. */
7980 rela
.r_info
= ELFNN_R_INFO (0, AARCH64_R (IRELATIVE
));
7981 rela
.r_addend
= (h
->root
.u
.def
.value
7982 + h
->root
.u
.def
.section
->output_section
->vma
7983 + h
->root
.u
.def
.section
->output_offset
);
7987 /* Fill in the entry in the .rela.plt section. */
7988 rela
.r_info
= ELFNN_R_INFO (h
->dynindx
, AARCH64_R (JUMP_SLOT
));
7992 /* Compute the relocation entry to used based on PLT index and do
7993 not adjust reloc_count. The reloc_count has already been adjusted
7994 to account for this entry. */
7995 loc
= relplt
->contents
+ plt_index
* RELOC_SIZE (htab
);
7996 bfd_elfNN_swap_reloca_out (output_bfd
, &rela
, loc
);
7999 /* Size sections even though they're not dynamic. We use it to setup
8000 _TLS_MODULE_BASE_, if needed. */
8003 elfNN_aarch64_always_size_sections (bfd
*output_bfd
,
8004 struct bfd_link_info
*info
)
8008 if (info
->relocatable
)
8011 tls_sec
= elf_hash_table (info
)->tls_sec
;
8015 struct elf_link_hash_entry
*tlsbase
;
8017 tlsbase
= elf_link_hash_lookup (elf_hash_table (info
),
8018 "_TLS_MODULE_BASE_", TRUE
, TRUE
, FALSE
);
8022 struct bfd_link_hash_entry
*h
= NULL
;
8023 const struct elf_backend_data
*bed
=
8024 get_elf_backend_data (output_bfd
);
8026 if (!(_bfd_generic_link_add_one_symbol
8027 (info
, output_bfd
, "_TLS_MODULE_BASE_", BSF_LOCAL
,
8028 tls_sec
, 0, NULL
, FALSE
, bed
->collect
, &h
)))
8031 tlsbase
->type
= STT_TLS
;
8032 tlsbase
= (struct elf_link_hash_entry
*) h
;
8033 tlsbase
->def_regular
= 1;
8034 tlsbase
->other
= STV_HIDDEN
;
8035 (*bed
->elf_backend_hide_symbol
) (info
, tlsbase
, TRUE
);
8042 /* Finish up dynamic symbol handling. We set the contents of various
8043 dynamic sections here. */
8045 elfNN_aarch64_finish_dynamic_symbol (bfd
*output_bfd
,
8046 struct bfd_link_info
*info
,
8047 struct elf_link_hash_entry
*h
,
8048 Elf_Internal_Sym
*sym
)
8050 struct elf_aarch64_link_hash_table
*htab
;
8051 htab
= elf_aarch64_hash_table (info
);
8053 if (h
->plt
.offset
!= (bfd_vma
) - 1)
8055 asection
*plt
, *gotplt
, *relplt
;
8057 /* This symbol has an entry in the procedure linkage table. Set
8060 /* When building a static executable, use .iplt, .igot.plt and
8061 .rela.iplt sections for STT_GNU_IFUNC symbols. */
8062 if (htab
->root
.splt
!= NULL
)
8064 plt
= htab
->root
.splt
;
8065 gotplt
= htab
->root
.sgotplt
;
8066 relplt
= htab
->root
.srelplt
;
8070 plt
= htab
->root
.iplt
;
8071 gotplt
= htab
->root
.igotplt
;
8072 relplt
= htab
->root
.irelplt
;
8075 /* This symbol has an entry in the procedure linkage table. Set
8077 if ((h
->dynindx
== -1
8078 && !((h
->forced_local
|| info
->executable
)
8080 && h
->type
== STT_GNU_IFUNC
))
8086 elfNN_aarch64_create_small_pltn_entry (h
, htab
, output_bfd
, info
);
8087 if (!h
->def_regular
)
8089 /* Mark the symbol as undefined, rather than as defined in
8090 the .plt section. */
8091 sym
->st_shndx
= SHN_UNDEF
;
8092 /* If the symbol is weak we need to clear the value.
8093 Otherwise, the PLT entry would provide a definition for
8094 the symbol even if the symbol wasn't defined anywhere,
8095 and so the symbol would never be NULL. Leave the value if
8096 there were any relocations where pointer equality matters
8097 (this is a clue for the dynamic linker, to make function
8098 pointer comparisons work between an application and shared
8100 if (!h
->ref_regular_nonweak
|| !h
->pointer_equality_needed
)
8105 if (h
->got
.offset
!= (bfd_vma
) - 1
8106 && elf_aarch64_hash_entry (h
)->got_type
== GOT_NORMAL
)
8108 Elf_Internal_Rela rela
;
8111 /* This symbol has an entry in the global offset table. Set it
8113 if (htab
->root
.sgot
== NULL
|| htab
->root
.srelgot
== NULL
)
8116 rela
.r_offset
= (htab
->root
.sgot
->output_section
->vma
8117 + htab
->root
.sgot
->output_offset
8118 + (h
->got
.offset
& ~(bfd_vma
) 1));
8121 && h
->type
== STT_GNU_IFUNC
)
8125 /* Generate R_AARCH64_GLOB_DAT. */
8132 if (!h
->pointer_equality_needed
)
8135 /* For non-shared object, we can't use .got.plt, which
8136 contains the real function address if we need pointer
8137 equality. We load the GOT entry with the PLT entry. */
8138 plt
= htab
->root
.splt
? htab
->root
.splt
: htab
->root
.iplt
;
8139 bfd_put_NN (output_bfd
, (plt
->output_section
->vma
8140 + plt
->output_offset
8142 htab
->root
.sgot
->contents
8143 + (h
->got
.offset
& ~(bfd_vma
) 1));
8147 else if (info
->shared
&& SYMBOL_REFERENCES_LOCAL (info
, h
))
8149 if (!h
->def_regular
)
8152 BFD_ASSERT ((h
->got
.offset
& 1) != 0);
8153 rela
.r_info
= ELFNN_R_INFO (0, AARCH64_R (RELATIVE
));
8154 rela
.r_addend
= (h
->root
.u
.def
.value
8155 + h
->root
.u
.def
.section
->output_section
->vma
8156 + h
->root
.u
.def
.section
->output_offset
);
8161 BFD_ASSERT ((h
->got
.offset
& 1) == 0);
8162 bfd_put_NN (output_bfd
, (bfd_vma
) 0,
8163 htab
->root
.sgot
->contents
+ h
->got
.offset
);
8164 rela
.r_info
= ELFNN_R_INFO (h
->dynindx
, AARCH64_R (GLOB_DAT
));
8168 loc
= htab
->root
.srelgot
->contents
;
8169 loc
+= htab
->root
.srelgot
->reloc_count
++ * RELOC_SIZE (htab
);
8170 bfd_elfNN_swap_reloca_out (output_bfd
, &rela
, loc
);
8175 Elf_Internal_Rela rela
;
8178 /* This symbol needs a copy reloc. Set it up. */
8180 if (h
->dynindx
== -1
8181 || (h
->root
.type
!= bfd_link_hash_defined
8182 && h
->root
.type
!= bfd_link_hash_defweak
)
8183 || htab
->srelbss
== NULL
)
8186 rela
.r_offset
= (h
->root
.u
.def
.value
8187 + h
->root
.u
.def
.section
->output_section
->vma
8188 + h
->root
.u
.def
.section
->output_offset
);
8189 rela
.r_info
= ELFNN_R_INFO (h
->dynindx
, AARCH64_R (COPY
));
8191 loc
= htab
->srelbss
->contents
;
8192 loc
+= htab
->srelbss
->reloc_count
++ * RELOC_SIZE (htab
);
8193 bfd_elfNN_swap_reloca_out (output_bfd
, &rela
, loc
);
8196 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. SYM may
8197 be NULL for local symbols. */
8199 && (h
== elf_hash_table (info
)->hdynamic
8200 || h
== elf_hash_table (info
)->hgot
))
8201 sym
->st_shndx
= SHN_ABS
;
8206 /* Finish up local dynamic symbol handling. We set the contents of
8207 various dynamic sections here. */
8210 elfNN_aarch64_finish_local_dynamic_symbol (void **slot
, void *inf
)
8212 struct elf_link_hash_entry
*h
8213 = (struct elf_link_hash_entry
*) *slot
;
8214 struct bfd_link_info
*info
8215 = (struct bfd_link_info
*) inf
;
8217 return elfNN_aarch64_finish_dynamic_symbol (info
->output_bfd
,
8222 elfNN_aarch64_init_small_plt0_entry (bfd
*output_bfd ATTRIBUTE_UNUSED
,
8223 struct elf_aarch64_link_hash_table
8226 /* Fill in PLT0. Fixme:RR Note this doesn't distinguish between
8227 small and large plts and at the minute just generates
8230 /* PLT0 of the small PLT looks like this in ELF64 -
8231 stp x16, x30, [sp, #-16]! // Save the reloc and lr on stack.
8232 adrp x16, PLT_GOT + 16 // Get the page base of the GOTPLT
8233 ldr x17, [x16, #:lo12:PLT_GOT+16] // Load the address of the
8235 add x16, x16, #:lo12:PLT_GOT+16 // Load the lo12 bits of the
8236 // GOTPLT entry for this.
8238 PLT0 will be slightly different in ELF32 due to different got entry
8241 bfd_vma plt_got_2nd_ent
; /* Address of GOT[2]. */
8245 memcpy (htab
->root
.splt
->contents
, elfNN_aarch64_small_plt0_entry
,
8247 elf_section_data (htab
->root
.splt
->output_section
)->this_hdr
.sh_entsize
=
8250 plt_got_2nd_ent
= (htab
->root
.sgotplt
->output_section
->vma
8251 + htab
->root
.sgotplt
->output_offset
8252 + GOT_ENTRY_SIZE
* 2);
8254 plt_base
= htab
->root
.splt
->output_section
->vma
+
8255 htab
->root
.splt
->output_offset
;
8257 /* Fill in the top 21 bits for this: ADRP x16, PLT_GOT + n * 8.
8258 ADRP: ((PG(S+A)-PG(P)) >> 12) & 0x1fffff */
8259 elf_aarch64_update_plt_entry (output_bfd
, BFD_RELOC_AARCH64_ADR_HI21_PCREL
,
8260 htab
->root
.splt
->contents
+ 4,
8261 PG (plt_got_2nd_ent
) - PG (plt_base
+ 4));
8263 elf_aarch64_update_plt_entry (output_bfd
, BFD_RELOC_AARCH64_LDSTNN_LO12
,
8264 htab
->root
.splt
->contents
+ 8,
8265 PG_OFFSET (plt_got_2nd_ent
));
8267 elf_aarch64_update_plt_entry (output_bfd
, BFD_RELOC_AARCH64_ADD_LO12
,
8268 htab
->root
.splt
->contents
+ 12,
8269 PG_OFFSET (plt_got_2nd_ent
));
8273 elfNN_aarch64_finish_dynamic_sections (bfd
*output_bfd
,
8274 struct bfd_link_info
*info
)
8276 struct elf_aarch64_link_hash_table
*htab
;
8280 htab
= elf_aarch64_hash_table (info
);
8281 dynobj
= htab
->root
.dynobj
;
8282 sdyn
= bfd_get_linker_section (dynobj
, ".dynamic");
8284 if (htab
->root
.dynamic_sections_created
)
8286 ElfNN_External_Dyn
*dyncon
, *dynconend
;
8288 if (sdyn
== NULL
|| htab
->root
.sgot
== NULL
)
8291 dyncon
= (ElfNN_External_Dyn
*) sdyn
->contents
;
8292 dynconend
= (ElfNN_External_Dyn
*) (sdyn
->contents
+ sdyn
->size
);
8293 for (; dyncon
< dynconend
; dyncon
++)
8295 Elf_Internal_Dyn dyn
;
8298 bfd_elfNN_swap_dyn_in (dynobj
, dyncon
, &dyn
);
8306 s
= htab
->root
.sgotplt
;
8307 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
8311 dyn
.d_un
.d_ptr
= htab
->root
.srelplt
->output_section
->vma
;
8315 s
= htab
->root
.srelplt
;
8316 dyn
.d_un
.d_val
= s
->size
;
8320 /* The procedure linkage table relocs (DT_JMPREL) should
8321 not be included in the overall relocs (DT_RELA).
8322 Therefore, we override the DT_RELASZ entry here to
8323 make it not include the JMPREL relocs. Since the
8324 linker script arranges for .rela.plt to follow all
8325 other relocation sections, we don't have to worry
8326 about changing the DT_RELA entry. */
8327 if (htab
->root
.srelplt
!= NULL
)
8329 s
= htab
->root
.srelplt
;
8330 dyn
.d_un
.d_val
-= s
->size
;
8334 case DT_TLSDESC_PLT
:
8335 s
= htab
->root
.splt
;
8336 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
8337 + htab
->tlsdesc_plt
;
8340 case DT_TLSDESC_GOT
:
8341 s
= htab
->root
.sgot
;
8342 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
8343 + htab
->dt_tlsdesc_got
;
8347 bfd_elfNN_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
8352 /* Fill in the special first entry in the procedure linkage table. */
8353 if (htab
->root
.splt
&& htab
->root
.splt
->size
> 0)
8355 elfNN_aarch64_init_small_plt0_entry (output_bfd
, htab
);
8357 elf_section_data (htab
->root
.splt
->output_section
)->
8358 this_hdr
.sh_entsize
= htab
->plt_entry_size
;
8361 if (htab
->tlsdesc_plt
)
8363 bfd_put_NN (output_bfd
, (bfd_vma
) 0,
8364 htab
->root
.sgot
->contents
+ htab
->dt_tlsdesc_got
);
8366 memcpy (htab
->root
.splt
->contents
+ htab
->tlsdesc_plt
,
8367 elfNN_aarch64_tlsdesc_small_plt_entry
,
8368 sizeof (elfNN_aarch64_tlsdesc_small_plt_entry
));
8371 bfd_vma adrp1_addr
=
8372 htab
->root
.splt
->output_section
->vma
8373 + htab
->root
.splt
->output_offset
+ htab
->tlsdesc_plt
+ 4;
8375 bfd_vma adrp2_addr
= adrp1_addr
+ 4;
8378 htab
->root
.sgot
->output_section
->vma
8379 + htab
->root
.sgot
->output_offset
;
8381 bfd_vma pltgot_addr
=
8382 htab
->root
.sgotplt
->output_section
->vma
8383 + htab
->root
.sgotplt
->output_offset
;
8385 bfd_vma dt_tlsdesc_got
= got_addr
+ htab
->dt_tlsdesc_got
;
8387 bfd_byte
*plt_entry
=
8388 htab
->root
.splt
->contents
+ htab
->tlsdesc_plt
;
8390 /* adrp x2, DT_TLSDESC_GOT */
8391 elf_aarch64_update_plt_entry (output_bfd
,
8392 BFD_RELOC_AARCH64_ADR_HI21_PCREL
,
8394 (PG (dt_tlsdesc_got
)
8395 - PG (adrp1_addr
)));
8398 elf_aarch64_update_plt_entry (output_bfd
,
8399 BFD_RELOC_AARCH64_ADR_HI21_PCREL
,
8402 - PG (adrp2_addr
)));
8404 /* ldr x2, [x2, #0] */
8405 elf_aarch64_update_plt_entry (output_bfd
,
8406 BFD_RELOC_AARCH64_LDSTNN_LO12
,
8408 PG_OFFSET (dt_tlsdesc_got
));
8411 elf_aarch64_update_plt_entry (output_bfd
,
8412 BFD_RELOC_AARCH64_ADD_LO12
,
8414 PG_OFFSET (pltgot_addr
));
8419 if (htab
->root
.sgotplt
)
8421 if (bfd_is_abs_section (htab
->root
.sgotplt
->output_section
))
8423 (*_bfd_error_handler
)
8424 (_("discarded output section: `%A'"), htab
->root
.sgotplt
);
8428 /* Fill in the first three entries in the global offset table. */
8429 if (htab
->root
.sgotplt
->size
> 0)
8431 bfd_put_NN (output_bfd
, (bfd_vma
) 0, htab
->root
.sgotplt
->contents
);
8433 /* Write GOT[1] and GOT[2], needed for the dynamic linker. */
8434 bfd_put_NN (output_bfd
,
8436 htab
->root
.sgotplt
->contents
+ GOT_ENTRY_SIZE
);
8437 bfd_put_NN (output_bfd
,
8439 htab
->root
.sgotplt
->contents
+ GOT_ENTRY_SIZE
* 2);
8442 if (htab
->root
.sgot
)
8444 if (htab
->root
.sgot
->size
> 0)
8447 sdyn
? sdyn
->output_section
->vma
+ sdyn
->output_offset
: 0;
8448 bfd_put_NN (output_bfd
, addr
, htab
->root
.sgot
->contents
);
8452 elf_section_data (htab
->root
.sgotplt
->output_section
)->
8453 this_hdr
.sh_entsize
= GOT_ENTRY_SIZE
;
8456 if (htab
->root
.sgot
&& htab
->root
.sgot
->size
> 0)
8457 elf_section_data (htab
->root
.sgot
->output_section
)->this_hdr
.sh_entsize
8460 /* Fill PLT and GOT entries for local STT_GNU_IFUNC symbols. */
8461 htab_traverse (htab
->loc_hash_table
,
8462 elfNN_aarch64_finish_local_dynamic_symbol
,
8468 /* Return address for Ith PLT stub in section PLT, for relocation REL
8469 or (bfd_vma) -1 if it should not be included. */
8472 elfNN_aarch64_plt_sym_val (bfd_vma i
, const asection
*plt
,
8473 const arelent
*rel ATTRIBUTE_UNUSED
)
8475 return plt
->vma
+ PLT_ENTRY_SIZE
+ i
* PLT_SMALL_ENTRY_SIZE
;
8479 /* We use this so we can override certain functions
8480 (though currently we don't). */
8482 const struct elf_size_info elfNN_aarch64_size_info
=
8484 sizeof (ElfNN_External_Ehdr
),
8485 sizeof (ElfNN_External_Phdr
),
8486 sizeof (ElfNN_External_Shdr
),
8487 sizeof (ElfNN_External_Rel
),
8488 sizeof (ElfNN_External_Rela
),
8489 sizeof (ElfNN_External_Sym
),
8490 sizeof (ElfNN_External_Dyn
),
8491 sizeof (Elf_External_Note
),
8492 4, /* Hash table entry size. */
8493 1, /* Internal relocs per external relocs. */
8494 ARCH_SIZE
, /* Arch size. */
8495 LOG_FILE_ALIGN
, /* Log_file_align. */
8496 ELFCLASSNN
, EV_CURRENT
,
8497 bfd_elfNN_write_out_phdrs
,
8498 bfd_elfNN_write_shdrs_and_ehdr
,
8499 bfd_elfNN_checksum_contents
,
8500 bfd_elfNN_write_relocs
,
8501 bfd_elfNN_swap_symbol_in
,
8502 bfd_elfNN_swap_symbol_out
,
8503 bfd_elfNN_slurp_reloc_table
,
8504 bfd_elfNN_slurp_symbol_table
,
8505 bfd_elfNN_swap_dyn_in
,
8506 bfd_elfNN_swap_dyn_out
,
8507 bfd_elfNN_swap_reloc_in
,
8508 bfd_elfNN_swap_reloc_out
,
8509 bfd_elfNN_swap_reloca_in
,
8510 bfd_elfNN_swap_reloca_out
8513 #define ELF_ARCH bfd_arch_aarch64
8514 #define ELF_MACHINE_CODE EM_AARCH64
8515 #define ELF_MAXPAGESIZE 0x10000
8516 #define ELF_MINPAGESIZE 0x1000
8517 #define ELF_COMMONPAGESIZE 0x1000
8519 #define bfd_elfNN_close_and_cleanup \
8520 elfNN_aarch64_close_and_cleanup
8522 #define bfd_elfNN_bfd_free_cached_info \
8523 elfNN_aarch64_bfd_free_cached_info
8525 #define bfd_elfNN_bfd_is_target_special_symbol \
8526 elfNN_aarch64_is_target_special_symbol
8528 #define bfd_elfNN_bfd_link_hash_table_create \
8529 elfNN_aarch64_link_hash_table_create
8531 #define bfd_elfNN_bfd_merge_private_bfd_data \
8532 elfNN_aarch64_merge_private_bfd_data
8534 #define bfd_elfNN_bfd_print_private_bfd_data \
8535 elfNN_aarch64_print_private_bfd_data
8537 #define bfd_elfNN_bfd_reloc_type_lookup \
8538 elfNN_aarch64_reloc_type_lookup
8540 #define bfd_elfNN_bfd_reloc_name_lookup \
8541 elfNN_aarch64_reloc_name_lookup
8543 #define bfd_elfNN_bfd_set_private_flags \
8544 elfNN_aarch64_set_private_flags
8546 #define bfd_elfNN_find_inliner_info \
8547 elfNN_aarch64_find_inliner_info
8549 #define bfd_elfNN_find_nearest_line \
8550 elfNN_aarch64_find_nearest_line
8552 #define bfd_elfNN_mkobject \
8553 elfNN_aarch64_mkobject
8555 #define bfd_elfNN_new_section_hook \
8556 elfNN_aarch64_new_section_hook
8558 #define elf_backend_adjust_dynamic_symbol \
8559 elfNN_aarch64_adjust_dynamic_symbol
8561 #define elf_backend_always_size_sections \
8562 elfNN_aarch64_always_size_sections
8564 #define elf_backend_check_relocs \
8565 elfNN_aarch64_check_relocs
8567 #define elf_backend_copy_indirect_symbol \
8568 elfNN_aarch64_copy_indirect_symbol
8570 /* Create .dynbss, and .rela.bss sections in DYNOBJ, and set up shortcuts
8571 to them in our hash. */
8572 #define elf_backend_create_dynamic_sections \
8573 elfNN_aarch64_create_dynamic_sections
8575 #define elf_backend_init_index_section \
8576 _bfd_elf_init_2_index_sections
8578 #define elf_backend_finish_dynamic_sections \
8579 elfNN_aarch64_finish_dynamic_sections
8581 #define elf_backend_finish_dynamic_symbol \
8582 elfNN_aarch64_finish_dynamic_symbol
8584 #define elf_backend_gc_sweep_hook \
8585 elfNN_aarch64_gc_sweep_hook
8587 #define elf_backend_object_p \
8588 elfNN_aarch64_object_p
8590 #define elf_backend_output_arch_local_syms \
8591 elfNN_aarch64_output_arch_local_syms
8593 #define elf_backend_plt_sym_val \
8594 elfNN_aarch64_plt_sym_val
8596 #define elf_backend_post_process_headers \
8597 elfNN_aarch64_post_process_headers
8599 #define elf_backend_relocate_section \
8600 elfNN_aarch64_relocate_section
8602 #define elf_backend_reloc_type_class \
8603 elfNN_aarch64_reloc_type_class
8605 #define elf_backend_section_from_shdr \
8606 elfNN_aarch64_section_from_shdr
8608 #define elf_backend_size_dynamic_sections \
8609 elfNN_aarch64_size_dynamic_sections
8611 #define elf_backend_size_info \
8612 elfNN_aarch64_size_info
8614 #define elf_backend_write_section \
8615 elfNN_aarch64_write_section
8617 #define elf_backend_can_refcount 1
8618 #define elf_backend_can_gc_sections 1
8619 #define elf_backend_plt_readonly 1
8620 #define elf_backend_want_got_plt 1
8621 #define elf_backend_want_plt_sym 0
8622 #define elf_backend_may_use_rel_p 0
8623 #define elf_backend_may_use_rela_p 1
8624 #define elf_backend_default_use_rela_p 1
8625 #define elf_backend_rela_normal 1
8626 #define elf_backend_got_header_size (GOT_ENTRY_SIZE * 3)
8627 #define elf_backend_default_execstack 0
8629 #undef elf_backend_obj_attrs_section
8630 #define elf_backend_obj_attrs_section ".ARM.attributes"
8632 #include "elfNN-target.h"