1 /* AArch64-specific support for NN-bit ELF.
2 Copyright (C) 2009-2015 Free Software Foundation, Inc.
3 Contributed by ARM Ltd.
5 This file is part of BFD, the Binary File Descriptor library.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; see the file COPYING3. If not,
19 see <http://www.gnu.org/licenses/>. */
21 /* Notes on implementation:
23 Thread Local Store (TLS)
27 The implementation currently supports both traditional TLS and TLS
28 descriptors, but only general dynamic (GD).
30 For traditional TLS the assembler will present us with code
31 fragments of the form:
34 R_AARCH64_TLSGD_ADR_PAGE21(foo)
35 add x0, :tlsgd_lo12:foo
36 R_AARCH64_TLSGD_ADD_LO12_NC(foo)
40 For TLS descriptors the assembler will present us with code
41 fragments of the form:
43 adrp x0, :tlsdesc:foo R_AARCH64_TLSDESC_ADR_PAGE21(foo)
44 ldr x1, [x0, #:tlsdesc_lo12:foo] R_AARCH64_TLSDESC_LD64_LO12(foo)
45 add x0, x0, #:tlsdesc_lo12:foo R_AARCH64_TLSDESC_ADD_LO12(foo)
47 blr x1 R_AARCH64_TLSDESC_CALL(foo)
49 The relocations R_AARCH64_TLSGD_{ADR_PREL21,ADD_LO12_NC} against foo
50 indicate that foo is thread local and should be accessed via the
51 traditional TLS mechanims.
53 The relocations R_AARCH64_TLSDESC_{ADR_PAGE21,LD64_LO12_NC,ADD_LO12_NC}
54 against foo indicate that 'foo' is thread local and should be accessed
55 via a TLS descriptor mechanism.
57 The precise instruction sequence is only relevant from the
58 perspective of linker relaxation which is currently not implemented.
60 The static linker must detect that 'foo' is a TLS object and
61 allocate a double GOT entry. The GOT entry must be created for both
62 global and local TLS symbols. Note that this is different to none
63 TLS local objects which do not need a GOT entry.
65 In the traditional TLS mechanism, the double GOT entry is used to
66 provide the tls_index structure, containing module and offset
67 entries. The static linker places the relocation R_AARCH64_TLS_DTPMOD
68 on the module entry. The loader will subsequently fixup this
69 relocation with the module identity.
71 For global traditional TLS symbols the static linker places an
72 R_AARCH64_TLS_DTPREL relocation on the offset entry. The loader
73 will subsequently fixup the offset. For local TLS symbols the static
74 linker fixes up offset.
76 In the TLS descriptor mechanism the double GOT entry is used to
77 provide the descriptor. The static linker places the relocation
78 R_AARCH64_TLSDESC on the first GOT slot. The loader will
79 subsequently fix this up.
83 The handling of TLS symbols is implemented across a number of
84 different backend functions. The following is a top level view of
85 what processing is performed where.
87 The TLS implementation maintains state information for each TLS
88 symbol. The state information for local and global symbols is kept
89 in different places. Global symbols use generic BFD structures while
90 local symbols use backend specific structures that are allocated and
91 maintained entirely by the backend.
95 elfNN_aarch64_check_relocs()
97 This function is invoked for each relocation.
99 The TLS relocations R_AARCH64_TLSGD_{ADR_PREL21,ADD_LO12_NC} and
100 R_AARCH64_TLSDESC_{ADR_PAGE21,LD64_LO12_NC,ADD_LO12_NC} are
101 spotted. One time creation of local symbol data structures are
102 created when the first local symbol is seen.
104 The reference count for a symbol is incremented. The GOT type for
105 each symbol is marked as general dynamic.
107 elfNN_aarch64_allocate_dynrelocs ()
109 For each global with positive reference count we allocate a double
110 GOT slot. For a traditional TLS symbol we allocate space for two
111 relocation entries on the GOT, for a TLS descriptor symbol we
112 allocate space for one relocation on the slot. Record the GOT offset
115 elfNN_aarch64_size_dynamic_sections ()
117 Iterate all input BFDS, look for in the local symbol data structure
118 constructed earlier for local TLS symbols and allocate them double
119 GOT slots along with space for a single GOT relocation. Update the
120 local symbol structure to record the GOT offset allocated.
122 elfNN_aarch64_relocate_section ()
124 Calls elfNN_aarch64_final_link_relocate ()
126 Emit the relevant TLS relocations against the GOT for each TLS
127 symbol. For local TLS symbols emit the GOT offset directly. The GOT
128 relocations are emitted once the first time a TLS symbol is
129 encountered. The implementation uses the LSB of the GOT offset to
130 flag that the relevant GOT relocations for a symbol have been
131 emitted. All of the TLS code that uses the GOT offset needs to take
132 care to mask out this flag bit before using the offset.
134 elfNN_aarch64_final_link_relocate ()
136 Fixup the R_AARCH64_TLSGD_{ADR_PREL21, ADD_LO12_NC} relocations. */
140 #include "libiberty.h"
142 #include "bfd_stdint.h"
145 #include "objalloc.h"
146 #include "elf/aarch64.h"
147 #include "elfxx-aarch64.h"
152 #define AARCH64_R(NAME) R_AARCH64_ ## NAME
153 #define AARCH64_R_STR(NAME) "R_AARCH64_" #NAME
154 #define HOWTO64(...) HOWTO (__VA_ARGS__)
155 #define HOWTO32(...) EMPTY_HOWTO (0)
156 #define LOG_FILE_ALIGN 3
160 #define AARCH64_R(NAME) R_AARCH64_P32_ ## NAME
161 #define AARCH64_R_STR(NAME) "R_AARCH64_P32_" #NAME
162 #define HOWTO64(...) EMPTY_HOWTO (0)
163 #define HOWTO32(...) HOWTO (__VA_ARGS__)
164 #define LOG_FILE_ALIGN 2
167 #define IS_AARCH64_TLS_RELOC(R_TYPE) \
168 ((R_TYPE) == BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC \
169 || (R_TYPE) == BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21 \
170 || (R_TYPE) == BFD_RELOC_AARCH64_TLSGD_ADR_PREL21 \
171 || (R_TYPE) == BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21 \
172 || (R_TYPE) == BFD_RELOC_AARCH64_TLSIE_LD32_GOTTPREL_LO12_NC \
173 || (R_TYPE) == BFD_RELOC_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC \
174 || (R_TYPE) == BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19 \
175 || (R_TYPE) == BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G0_NC \
176 || (R_TYPE) == BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G1 \
177 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_ADD_DTPREL_HI12 \
178 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_ADD_DTPREL_LO12 \
179 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_ADD_DTPREL_LO12_NC \
180 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC \
181 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21 \
182 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_ADR_PREL21 \
183 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_LDST16_DTPREL_LO12 \
184 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_LDST16_DTPREL_LO12_NC \
185 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_LDST32_DTPREL_LO12 \
186 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_LDST32_DTPREL_LO12_NC \
187 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_LDST64_DTPREL_LO12 \
188 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_LDST64_DTPREL_LO12_NC \
189 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_LDST8_DTPREL_LO12 \
190 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_LDST8_DTPREL_LO12_NC \
191 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G0 \
192 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G0_NC \
193 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G1 \
194 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G1_NC \
195 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G2 \
196 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_HI12 \
197 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_LO12 \
198 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_LO12_NC \
199 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0 \
200 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC \
201 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1 \
202 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1_NC \
203 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G2 \
204 || (R_TYPE) == BFD_RELOC_AARCH64_TLS_DTPMOD \
205 || (R_TYPE) == BFD_RELOC_AARCH64_TLS_DTPREL \
206 || (R_TYPE) == BFD_RELOC_AARCH64_TLS_TPREL \
207 || IS_AARCH64_TLSDESC_RELOC ((R_TYPE)))
209 #define IS_AARCH64_TLS_RELAX_RELOC(R_TYPE) \
210 ((R_TYPE) == BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21 \
211 || (R_TYPE) == BFD_RELOC_AARCH64_TLSGD_ADR_PREL21 \
212 || (R_TYPE) == BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC \
213 || (R_TYPE) == BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21 \
214 || (R_TYPE) == BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19 \
215 || (R_TYPE) == BFD_RELOC_AARCH64_TLSIE_LDNN_GOTTPREL_LO12_NC \
216 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21 \
217 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21 \
218 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_LD_PREL19 \
219 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_LDNN_LO12_NC \
220 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_CALL \
221 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_ADD_LO12_NC)
223 #define IS_AARCH64_TLSDESC_RELOC(R_TYPE) \
224 ((R_TYPE) == BFD_RELOC_AARCH64_TLSDESC \
225 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_ADD \
226 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_ADD_LO12_NC \
227 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21 \
228 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21 \
229 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_CALL \
230 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_LD32_LO12_NC \
231 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_LD64_LO12_NC \
232 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_LDR \
233 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_LD_PREL19 \
234 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_OFF_G0_NC \
235 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_OFF_G1)
237 #define ELIMINATE_COPY_RELOCS 0
239 /* Return size of a relocation entry. HTAB is the bfd's
240 elf_aarch64_link_hash_entry. */
241 #define RELOC_SIZE(HTAB) (sizeof (ElfNN_External_Rela))
243 /* GOT Entry size - 8 bytes in ELF64 and 4 bytes in ELF32. */
244 #define GOT_ENTRY_SIZE (ARCH_SIZE / 8)
245 #define PLT_ENTRY_SIZE (32)
246 #define PLT_SMALL_ENTRY_SIZE (16)
247 #define PLT_TLSDESC_ENTRY_SIZE (32)
249 /* Encoding of the nop instruction */
250 #define INSN_NOP 0xd503201f
252 #define aarch64_compute_jump_table_size(htab) \
253 (((htab)->root.srelplt == NULL) ? 0 \
254 : (htab)->root.srelplt->reloc_count * GOT_ENTRY_SIZE)
256 /* The first entry in a procedure linkage table looks like this
257 if the distance between the PLTGOT and the PLT is < 4GB use
258 these PLT entries. Note that the dynamic linker gets &PLTGOT[2]
259 in x16 and needs to work out PLTGOT[1] by using an address of
260 [x16,#-GOT_ENTRY_SIZE]. */
261 static const bfd_byte elfNN_aarch64_small_plt0_entry
[PLT_ENTRY_SIZE
] =
263 0xf0, 0x7b, 0xbf, 0xa9, /* stp x16, x30, [sp, #-16]! */
264 0x10, 0x00, 0x00, 0x90, /* adrp x16, (GOT+16) */
266 0x11, 0x0A, 0x40, 0xf9, /* ldr x17, [x16, #PLT_GOT+0x10] */
267 0x10, 0x42, 0x00, 0x91, /* add x16, x16,#PLT_GOT+0x10 */
269 0x11, 0x0A, 0x40, 0xb9, /* ldr w17, [x16, #PLT_GOT+0x8] */
270 0x10, 0x22, 0x00, 0x11, /* add w16, w16,#PLT_GOT+0x8 */
272 0x20, 0x02, 0x1f, 0xd6, /* br x17 */
273 0x1f, 0x20, 0x03, 0xd5, /* nop */
274 0x1f, 0x20, 0x03, 0xd5, /* nop */
275 0x1f, 0x20, 0x03, 0xd5, /* nop */
278 /* Per function entry in a procedure linkage table looks like this
279 if the distance between the PLTGOT and the PLT is < 4GB use
280 these PLT entries. */
281 static const bfd_byte elfNN_aarch64_small_plt_entry
[PLT_SMALL_ENTRY_SIZE
] =
283 0x10, 0x00, 0x00, 0x90, /* adrp x16, PLTGOT + n * 8 */
285 0x11, 0x02, 0x40, 0xf9, /* ldr x17, [x16, PLTGOT + n * 8] */
286 0x10, 0x02, 0x00, 0x91, /* add x16, x16, :lo12:PLTGOT + n * 8 */
288 0x11, 0x02, 0x40, 0xb9, /* ldr w17, [x16, PLTGOT + n * 4] */
289 0x10, 0x02, 0x00, 0x11, /* add w16, w16, :lo12:PLTGOT + n * 4 */
291 0x20, 0x02, 0x1f, 0xd6, /* br x17. */
294 static const bfd_byte
295 elfNN_aarch64_tlsdesc_small_plt_entry
[PLT_TLSDESC_ENTRY_SIZE
] =
297 0xe2, 0x0f, 0xbf, 0xa9, /* stp x2, x3, [sp, #-16]! */
298 0x02, 0x00, 0x00, 0x90, /* adrp x2, 0 */
299 0x03, 0x00, 0x00, 0x90, /* adrp x3, 0 */
301 0x42, 0x00, 0x40, 0xf9, /* ldr x2, [x2, #0] */
302 0x63, 0x00, 0x00, 0x91, /* add x3, x3, 0 */
304 0x42, 0x00, 0x40, 0xb9, /* ldr w2, [x2, #0] */
305 0x63, 0x00, 0x00, 0x11, /* add w3, w3, 0 */
307 0x40, 0x00, 0x1f, 0xd6, /* br x2 */
308 0x1f, 0x20, 0x03, 0xd5, /* nop */
309 0x1f, 0x20, 0x03, 0xd5, /* nop */
312 #define elf_info_to_howto elfNN_aarch64_info_to_howto
313 #define elf_info_to_howto_rel elfNN_aarch64_info_to_howto
315 #define AARCH64_ELF_ABI_VERSION 0
317 /* In case we're on a 32-bit machine, construct a 64-bit "-1" value. */
318 #define ALL_ONES (~ (bfd_vma) 0)
320 /* Indexed by the bfd interal reloc enumerators.
321 Therefore, the table needs to be synced with BFD_RELOC_AARCH64_*
324 static reloc_howto_type elfNN_aarch64_howto_table
[] =
328 /* Basic data relocations. */
331 HOWTO (R_AARCH64_NULL
, /* type */
333 3, /* size (0 = byte, 1 = short, 2 = long) */
335 FALSE
, /* pc_relative */
337 complain_overflow_dont
, /* complain_on_overflow */
338 bfd_elf_generic_reloc
, /* special_function */
339 "R_AARCH64_NULL", /* name */
340 FALSE
, /* partial_inplace */
343 FALSE
), /* pcrel_offset */
345 HOWTO (R_AARCH64_NONE
, /* type */
347 3, /* size (0 = byte, 1 = short, 2 = long) */
349 FALSE
, /* pc_relative */
351 complain_overflow_dont
, /* complain_on_overflow */
352 bfd_elf_generic_reloc
, /* special_function */
353 "R_AARCH64_NONE", /* name */
354 FALSE
, /* partial_inplace */
357 FALSE
), /* pcrel_offset */
361 HOWTO64 (AARCH64_R (ABS64
), /* type */
363 4, /* size (4 = long long) */
365 FALSE
, /* pc_relative */
367 complain_overflow_unsigned
, /* complain_on_overflow */
368 bfd_elf_generic_reloc
, /* special_function */
369 AARCH64_R_STR (ABS64
), /* name */
370 FALSE
, /* partial_inplace */
371 ALL_ONES
, /* src_mask */
372 ALL_ONES
, /* dst_mask */
373 FALSE
), /* pcrel_offset */
376 HOWTO (AARCH64_R (ABS32
), /* type */
378 2, /* size (0 = byte, 1 = short, 2 = long) */
380 FALSE
, /* pc_relative */
382 complain_overflow_unsigned
, /* complain_on_overflow */
383 bfd_elf_generic_reloc
, /* special_function */
384 AARCH64_R_STR (ABS32
), /* name */
385 FALSE
, /* partial_inplace */
386 0xffffffff, /* src_mask */
387 0xffffffff, /* dst_mask */
388 FALSE
), /* pcrel_offset */
391 HOWTO (AARCH64_R (ABS16
), /* type */
393 1, /* size (0 = byte, 1 = short, 2 = long) */
395 FALSE
, /* pc_relative */
397 complain_overflow_unsigned
, /* complain_on_overflow */
398 bfd_elf_generic_reloc
, /* special_function */
399 AARCH64_R_STR (ABS16
), /* name */
400 FALSE
, /* partial_inplace */
401 0xffff, /* src_mask */
402 0xffff, /* dst_mask */
403 FALSE
), /* pcrel_offset */
405 /* .xword: (S+A-P) */
406 HOWTO64 (AARCH64_R (PREL64
), /* type */
408 4, /* size (4 = long long) */
410 TRUE
, /* pc_relative */
412 complain_overflow_signed
, /* complain_on_overflow */
413 bfd_elf_generic_reloc
, /* special_function */
414 AARCH64_R_STR (PREL64
), /* name */
415 FALSE
, /* partial_inplace */
416 ALL_ONES
, /* src_mask */
417 ALL_ONES
, /* dst_mask */
418 TRUE
), /* pcrel_offset */
421 HOWTO (AARCH64_R (PREL32
), /* type */
423 2, /* size (0 = byte, 1 = short, 2 = long) */
425 TRUE
, /* pc_relative */
427 complain_overflow_signed
, /* complain_on_overflow */
428 bfd_elf_generic_reloc
, /* special_function */
429 AARCH64_R_STR (PREL32
), /* name */
430 FALSE
, /* partial_inplace */
431 0xffffffff, /* src_mask */
432 0xffffffff, /* dst_mask */
433 TRUE
), /* pcrel_offset */
436 HOWTO (AARCH64_R (PREL16
), /* type */
438 1, /* size (0 = byte, 1 = short, 2 = long) */
440 TRUE
, /* pc_relative */
442 complain_overflow_signed
, /* complain_on_overflow */
443 bfd_elf_generic_reloc
, /* special_function */
444 AARCH64_R_STR (PREL16
), /* name */
445 FALSE
, /* partial_inplace */
446 0xffff, /* src_mask */
447 0xffff, /* dst_mask */
448 TRUE
), /* pcrel_offset */
450 /* Group relocations to create a 16, 32, 48 or 64 bit
451 unsigned data or abs address inline. */
453 /* MOVZ: ((S+A) >> 0) & 0xffff */
454 HOWTO (AARCH64_R (MOVW_UABS_G0
), /* type */
456 2, /* size (0 = byte, 1 = short, 2 = long) */
458 FALSE
, /* pc_relative */
460 complain_overflow_unsigned
, /* complain_on_overflow */
461 bfd_elf_generic_reloc
, /* special_function */
462 AARCH64_R_STR (MOVW_UABS_G0
), /* name */
463 FALSE
, /* partial_inplace */
464 0xffff, /* src_mask */
465 0xffff, /* dst_mask */
466 FALSE
), /* pcrel_offset */
468 /* MOVK: ((S+A) >> 0) & 0xffff [no overflow check] */
469 HOWTO (AARCH64_R (MOVW_UABS_G0_NC
), /* type */
471 2, /* size (0 = byte, 1 = short, 2 = long) */
473 FALSE
, /* pc_relative */
475 complain_overflow_dont
, /* complain_on_overflow */
476 bfd_elf_generic_reloc
, /* special_function */
477 AARCH64_R_STR (MOVW_UABS_G0_NC
), /* name */
478 FALSE
, /* partial_inplace */
479 0xffff, /* src_mask */
480 0xffff, /* dst_mask */
481 FALSE
), /* pcrel_offset */
483 /* MOVZ: ((S+A) >> 16) & 0xffff */
484 HOWTO (AARCH64_R (MOVW_UABS_G1
), /* type */
486 2, /* size (0 = byte, 1 = short, 2 = long) */
488 FALSE
, /* pc_relative */
490 complain_overflow_unsigned
, /* complain_on_overflow */
491 bfd_elf_generic_reloc
, /* special_function */
492 AARCH64_R_STR (MOVW_UABS_G1
), /* name */
493 FALSE
, /* partial_inplace */
494 0xffff, /* src_mask */
495 0xffff, /* dst_mask */
496 FALSE
), /* pcrel_offset */
498 /* MOVK: ((S+A) >> 16) & 0xffff [no overflow check] */
499 HOWTO64 (AARCH64_R (MOVW_UABS_G1_NC
), /* type */
501 2, /* size (0 = byte, 1 = short, 2 = long) */
503 FALSE
, /* pc_relative */
505 complain_overflow_dont
, /* complain_on_overflow */
506 bfd_elf_generic_reloc
, /* special_function */
507 AARCH64_R_STR (MOVW_UABS_G1_NC
), /* name */
508 FALSE
, /* partial_inplace */
509 0xffff, /* src_mask */
510 0xffff, /* dst_mask */
511 FALSE
), /* pcrel_offset */
513 /* MOVZ: ((S+A) >> 32) & 0xffff */
514 HOWTO64 (AARCH64_R (MOVW_UABS_G2
), /* type */
516 2, /* size (0 = byte, 1 = short, 2 = long) */
518 FALSE
, /* pc_relative */
520 complain_overflow_unsigned
, /* complain_on_overflow */
521 bfd_elf_generic_reloc
, /* special_function */
522 AARCH64_R_STR (MOVW_UABS_G2
), /* name */
523 FALSE
, /* partial_inplace */
524 0xffff, /* src_mask */
525 0xffff, /* dst_mask */
526 FALSE
), /* pcrel_offset */
528 /* MOVK: ((S+A) >> 32) & 0xffff [no overflow check] */
529 HOWTO64 (AARCH64_R (MOVW_UABS_G2_NC
), /* type */
531 2, /* size (0 = byte, 1 = short, 2 = long) */
533 FALSE
, /* pc_relative */
535 complain_overflow_dont
, /* complain_on_overflow */
536 bfd_elf_generic_reloc
, /* special_function */
537 AARCH64_R_STR (MOVW_UABS_G2_NC
), /* name */
538 FALSE
, /* partial_inplace */
539 0xffff, /* src_mask */
540 0xffff, /* dst_mask */
541 FALSE
), /* pcrel_offset */
543 /* MOVZ: ((S+A) >> 48) & 0xffff */
544 HOWTO64 (AARCH64_R (MOVW_UABS_G3
), /* type */
546 2, /* size (0 = byte, 1 = short, 2 = long) */
548 FALSE
, /* pc_relative */
550 complain_overflow_unsigned
, /* complain_on_overflow */
551 bfd_elf_generic_reloc
, /* special_function */
552 AARCH64_R_STR (MOVW_UABS_G3
), /* name */
553 FALSE
, /* partial_inplace */
554 0xffff, /* src_mask */
555 0xffff, /* dst_mask */
556 FALSE
), /* pcrel_offset */
558 /* Group relocations to create high part of a 16, 32, 48 or 64 bit
559 signed data or abs address inline. Will change instruction
560 to MOVN or MOVZ depending on sign of calculated value. */
562 /* MOV[ZN]: ((S+A) >> 0) & 0xffff */
563 HOWTO (AARCH64_R (MOVW_SABS_G0
), /* type */
565 2, /* size (0 = byte, 1 = short, 2 = long) */
567 FALSE
, /* pc_relative */
569 complain_overflow_signed
, /* complain_on_overflow */
570 bfd_elf_generic_reloc
, /* special_function */
571 AARCH64_R_STR (MOVW_SABS_G0
), /* name */
572 FALSE
, /* partial_inplace */
573 0xffff, /* src_mask */
574 0xffff, /* dst_mask */
575 FALSE
), /* pcrel_offset */
577 /* MOV[ZN]: ((S+A) >> 16) & 0xffff */
578 HOWTO64 (AARCH64_R (MOVW_SABS_G1
), /* type */
580 2, /* size (0 = byte, 1 = short, 2 = long) */
582 FALSE
, /* pc_relative */
584 complain_overflow_signed
, /* complain_on_overflow */
585 bfd_elf_generic_reloc
, /* special_function */
586 AARCH64_R_STR (MOVW_SABS_G1
), /* name */
587 FALSE
, /* partial_inplace */
588 0xffff, /* src_mask */
589 0xffff, /* dst_mask */
590 FALSE
), /* pcrel_offset */
592 /* MOV[ZN]: ((S+A) >> 32) & 0xffff */
593 HOWTO64 (AARCH64_R (MOVW_SABS_G2
), /* type */
595 2, /* size (0 = byte, 1 = short, 2 = long) */
597 FALSE
, /* pc_relative */
599 complain_overflow_signed
, /* complain_on_overflow */
600 bfd_elf_generic_reloc
, /* special_function */
601 AARCH64_R_STR (MOVW_SABS_G2
), /* name */
602 FALSE
, /* partial_inplace */
603 0xffff, /* src_mask */
604 0xffff, /* dst_mask */
605 FALSE
), /* pcrel_offset */
607 /* Relocations to generate 19, 21 and 33 bit PC-relative load/store
608 addresses: PG(x) is (x & ~0xfff). */
610 /* LD-lit: ((S+A-P) >> 2) & 0x7ffff */
611 HOWTO (AARCH64_R (LD_PREL_LO19
), /* type */
613 2, /* size (0 = byte, 1 = short, 2 = long) */
615 TRUE
, /* pc_relative */
617 complain_overflow_signed
, /* complain_on_overflow */
618 bfd_elf_generic_reloc
, /* special_function */
619 AARCH64_R_STR (LD_PREL_LO19
), /* name */
620 FALSE
, /* partial_inplace */
621 0x7ffff, /* src_mask */
622 0x7ffff, /* dst_mask */
623 TRUE
), /* pcrel_offset */
625 /* ADR: (S+A-P) & 0x1fffff */
626 HOWTO (AARCH64_R (ADR_PREL_LO21
), /* type */
628 2, /* size (0 = byte, 1 = short, 2 = long) */
630 TRUE
, /* pc_relative */
632 complain_overflow_signed
, /* complain_on_overflow */
633 bfd_elf_generic_reloc
, /* special_function */
634 AARCH64_R_STR (ADR_PREL_LO21
), /* name */
635 FALSE
, /* partial_inplace */
636 0x1fffff, /* src_mask */
637 0x1fffff, /* dst_mask */
638 TRUE
), /* pcrel_offset */
640 /* ADRP: ((PG(S+A)-PG(P)) >> 12) & 0x1fffff */
641 HOWTO (AARCH64_R (ADR_PREL_PG_HI21
), /* type */
643 2, /* size (0 = byte, 1 = short, 2 = long) */
645 TRUE
, /* pc_relative */
647 complain_overflow_signed
, /* complain_on_overflow */
648 bfd_elf_generic_reloc
, /* special_function */
649 AARCH64_R_STR (ADR_PREL_PG_HI21
), /* name */
650 FALSE
, /* partial_inplace */
651 0x1fffff, /* src_mask */
652 0x1fffff, /* dst_mask */
653 TRUE
), /* pcrel_offset */
655 /* ADRP: ((PG(S+A)-PG(P)) >> 12) & 0x1fffff [no overflow check] */
656 HOWTO64 (AARCH64_R (ADR_PREL_PG_HI21_NC
), /* type */
658 2, /* size (0 = byte, 1 = short, 2 = long) */
660 TRUE
, /* pc_relative */
662 complain_overflow_dont
, /* complain_on_overflow */
663 bfd_elf_generic_reloc
, /* special_function */
664 AARCH64_R_STR (ADR_PREL_PG_HI21_NC
), /* name */
665 FALSE
, /* partial_inplace */
666 0x1fffff, /* src_mask */
667 0x1fffff, /* dst_mask */
668 TRUE
), /* pcrel_offset */
670 /* ADD: (S+A) & 0xfff [no overflow check] */
671 HOWTO (AARCH64_R (ADD_ABS_LO12_NC
), /* type */
673 2, /* size (0 = byte, 1 = short, 2 = long) */
675 FALSE
, /* pc_relative */
677 complain_overflow_dont
, /* complain_on_overflow */
678 bfd_elf_generic_reloc
, /* special_function */
679 AARCH64_R_STR (ADD_ABS_LO12_NC
), /* name */
680 FALSE
, /* partial_inplace */
681 0x3ffc00, /* src_mask */
682 0x3ffc00, /* dst_mask */
683 FALSE
), /* pcrel_offset */
685 /* LD/ST8: (S+A) & 0xfff */
686 HOWTO (AARCH64_R (LDST8_ABS_LO12_NC
), /* type */
688 2, /* size (0 = byte, 1 = short, 2 = long) */
690 FALSE
, /* pc_relative */
692 complain_overflow_dont
, /* complain_on_overflow */
693 bfd_elf_generic_reloc
, /* special_function */
694 AARCH64_R_STR (LDST8_ABS_LO12_NC
), /* name */
695 FALSE
, /* partial_inplace */
696 0xfff, /* src_mask */
697 0xfff, /* dst_mask */
698 FALSE
), /* pcrel_offset */
700 /* Relocations for control-flow instructions. */
702 /* TBZ/NZ: ((S+A-P) >> 2) & 0x3fff */
703 HOWTO (AARCH64_R (TSTBR14
), /* type */
705 2, /* size (0 = byte, 1 = short, 2 = long) */
707 TRUE
, /* pc_relative */
709 complain_overflow_signed
, /* complain_on_overflow */
710 bfd_elf_generic_reloc
, /* special_function */
711 AARCH64_R_STR (TSTBR14
), /* name */
712 FALSE
, /* partial_inplace */
713 0x3fff, /* src_mask */
714 0x3fff, /* dst_mask */
715 TRUE
), /* pcrel_offset */
717 /* B.cond: ((S+A-P) >> 2) & 0x7ffff */
718 HOWTO (AARCH64_R (CONDBR19
), /* type */
720 2, /* size (0 = byte, 1 = short, 2 = long) */
722 TRUE
, /* pc_relative */
724 complain_overflow_signed
, /* complain_on_overflow */
725 bfd_elf_generic_reloc
, /* special_function */
726 AARCH64_R_STR (CONDBR19
), /* name */
727 FALSE
, /* partial_inplace */
728 0x7ffff, /* src_mask */
729 0x7ffff, /* dst_mask */
730 TRUE
), /* pcrel_offset */
732 /* B: ((S+A-P) >> 2) & 0x3ffffff */
733 HOWTO (AARCH64_R (JUMP26
), /* type */
735 2, /* size (0 = byte, 1 = short, 2 = long) */
737 TRUE
, /* pc_relative */
739 complain_overflow_signed
, /* complain_on_overflow */
740 bfd_elf_generic_reloc
, /* special_function */
741 AARCH64_R_STR (JUMP26
), /* name */
742 FALSE
, /* partial_inplace */
743 0x3ffffff, /* src_mask */
744 0x3ffffff, /* dst_mask */
745 TRUE
), /* pcrel_offset */
747 /* BL: ((S+A-P) >> 2) & 0x3ffffff */
748 HOWTO (AARCH64_R (CALL26
), /* type */
750 2, /* size (0 = byte, 1 = short, 2 = long) */
752 TRUE
, /* pc_relative */
754 complain_overflow_signed
, /* complain_on_overflow */
755 bfd_elf_generic_reloc
, /* special_function */
756 AARCH64_R_STR (CALL26
), /* name */
757 FALSE
, /* partial_inplace */
758 0x3ffffff, /* src_mask */
759 0x3ffffff, /* dst_mask */
760 TRUE
), /* pcrel_offset */
762 /* LD/ST16: (S+A) & 0xffe */
763 HOWTO (AARCH64_R (LDST16_ABS_LO12_NC
), /* type */
765 2, /* size (0 = byte, 1 = short, 2 = long) */
767 FALSE
, /* pc_relative */
769 complain_overflow_dont
, /* complain_on_overflow */
770 bfd_elf_generic_reloc
, /* special_function */
771 AARCH64_R_STR (LDST16_ABS_LO12_NC
), /* name */
772 FALSE
, /* partial_inplace */
773 0xffe, /* src_mask */
774 0xffe, /* dst_mask */
775 FALSE
), /* pcrel_offset */
777 /* LD/ST32: (S+A) & 0xffc */
778 HOWTO (AARCH64_R (LDST32_ABS_LO12_NC
), /* type */
780 2, /* size (0 = byte, 1 = short, 2 = long) */
782 FALSE
, /* pc_relative */
784 complain_overflow_dont
, /* complain_on_overflow */
785 bfd_elf_generic_reloc
, /* special_function */
786 AARCH64_R_STR (LDST32_ABS_LO12_NC
), /* name */
787 FALSE
, /* partial_inplace */
788 0xffc, /* src_mask */
789 0xffc, /* dst_mask */
790 FALSE
), /* pcrel_offset */
792 /* LD/ST64: (S+A) & 0xff8 */
793 HOWTO (AARCH64_R (LDST64_ABS_LO12_NC
), /* type */
795 2, /* size (0 = byte, 1 = short, 2 = long) */
797 FALSE
, /* pc_relative */
799 complain_overflow_dont
, /* complain_on_overflow */
800 bfd_elf_generic_reloc
, /* special_function */
801 AARCH64_R_STR (LDST64_ABS_LO12_NC
), /* name */
802 FALSE
, /* partial_inplace */
803 0xff8, /* src_mask */
804 0xff8, /* dst_mask */
805 FALSE
), /* pcrel_offset */
807 /* LD/ST128: (S+A) & 0xff0 */
808 HOWTO (AARCH64_R (LDST128_ABS_LO12_NC
), /* type */
810 2, /* size (0 = byte, 1 = short, 2 = long) */
812 FALSE
, /* pc_relative */
814 complain_overflow_dont
, /* complain_on_overflow */
815 bfd_elf_generic_reloc
, /* special_function */
816 AARCH64_R_STR (LDST128_ABS_LO12_NC
), /* name */
817 FALSE
, /* partial_inplace */
818 0xff0, /* src_mask */
819 0xff0, /* dst_mask */
820 FALSE
), /* pcrel_offset */
822 /* Set a load-literal immediate field to bits
823 0x1FFFFC of G(S)-P */
824 HOWTO (AARCH64_R (GOT_LD_PREL19
), /* type */
826 2, /* size (0 = byte,1 = short,2 = long) */
828 TRUE
, /* pc_relative */
830 complain_overflow_signed
, /* complain_on_overflow */
831 bfd_elf_generic_reloc
, /* special_function */
832 AARCH64_R_STR (GOT_LD_PREL19
), /* name */
833 FALSE
, /* partial_inplace */
834 0xffffe0, /* src_mask */
835 0xffffe0, /* dst_mask */
836 TRUE
), /* pcrel_offset */
838 /* Get to the page for the GOT entry for the symbol
839 (G(S) - P) using an ADRP instruction. */
840 HOWTO (AARCH64_R (ADR_GOT_PAGE
), /* type */
842 2, /* size (0 = byte, 1 = short, 2 = long) */
844 TRUE
, /* pc_relative */
846 complain_overflow_dont
, /* complain_on_overflow */
847 bfd_elf_generic_reloc
, /* special_function */
848 AARCH64_R_STR (ADR_GOT_PAGE
), /* name */
849 FALSE
, /* partial_inplace */
850 0x1fffff, /* src_mask */
851 0x1fffff, /* dst_mask */
852 TRUE
), /* pcrel_offset */
854 /* LD64: GOT offset G(S) & 0xff8 */
855 HOWTO64 (AARCH64_R (LD64_GOT_LO12_NC
), /* type */
857 2, /* size (0 = byte, 1 = short, 2 = long) */
859 FALSE
, /* pc_relative */
861 complain_overflow_dont
, /* complain_on_overflow */
862 bfd_elf_generic_reloc
, /* special_function */
863 AARCH64_R_STR (LD64_GOT_LO12_NC
), /* name */
864 FALSE
, /* partial_inplace */
865 0xff8, /* src_mask */
866 0xff8, /* dst_mask */
867 FALSE
), /* pcrel_offset */
869 /* LD32: GOT offset G(S) & 0xffc */
870 HOWTO32 (AARCH64_R (LD32_GOT_LO12_NC
), /* type */
872 2, /* size (0 = byte, 1 = short, 2 = long) */
874 FALSE
, /* pc_relative */
876 complain_overflow_dont
, /* complain_on_overflow */
877 bfd_elf_generic_reloc
, /* special_function */
878 AARCH64_R_STR (LD32_GOT_LO12_NC
), /* name */
879 FALSE
, /* partial_inplace */
880 0xffc, /* src_mask */
881 0xffc, /* dst_mask */
882 FALSE
), /* pcrel_offset */
884 /* LD64: GOT offset for the symbol. */
885 HOWTO64 (AARCH64_R (LD64_GOTOFF_LO15
), /* type */
887 2, /* size (0 = byte, 1 = short, 2 = long) */
889 FALSE
, /* pc_relative */
891 complain_overflow_unsigned
, /* complain_on_overflow */
892 bfd_elf_generic_reloc
, /* special_function */
893 AARCH64_R_STR (LD64_GOTOFF_LO15
), /* name */
894 FALSE
, /* partial_inplace */
895 0x7ff8, /* src_mask */
896 0x7ff8, /* dst_mask */
897 FALSE
), /* pcrel_offset */
899 /* LD32: GOT offset to the page address of GOT table.
900 (G(S) - PAGE (_GLOBAL_OFFSET_TABLE_)) & 0x5ffc. */
901 HOWTO32 (AARCH64_R (LD32_GOTPAGE_LO14
), /* type */
903 2, /* size (0 = byte, 1 = short, 2 = long) */
905 FALSE
, /* pc_relative */
907 complain_overflow_unsigned
, /* complain_on_overflow */
908 bfd_elf_generic_reloc
, /* special_function */
909 AARCH64_R_STR (LD32_GOTPAGE_LO14
), /* name */
910 FALSE
, /* partial_inplace */
911 0x5ffc, /* src_mask */
912 0x5ffc, /* dst_mask */
913 FALSE
), /* pcrel_offset */
915 /* LD64: GOT offset to the page address of GOT table.
916 (G(S) - PAGE (_GLOBAL_OFFSET_TABLE_)) & 0x7ff8. */
917 HOWTO64 (AARCH64_R (LD64_GOTPAGE_LO15
), /* type */
919 2, /* size (0 = byte, 1 = short, 2 = long) */
921 FALSE
, /* pc_relative */
923 complain_overflow_unsigned
, /* complain_on_overflow */
924 bfd_elf_generic_reloc
, /* special_function */
925 AARCH64_R_STR (LD64_GOTPAGE_LO15
), /* name */
926 FALSE
, /* partial_inplace */
927 0x7ff8, /* src_mask */
928 0x7ff8, /* dst_mask */
929 FALSE
), /* pcrel_offset */
931 /* Get to the page for the GOT entry for the symbol
932 (G(S) - P) using an ADRP instruction. */
933 HOWTO (AARCH64_R (TLSGD_ADR_PAGE21
), /* type */
935 2, /* size (0 = byte, 1 = short, 2 = long) */
937 TRUE
, /* pc_relative */
939 complain_overflow_dont
, /* complain_on_overflow */
940 bfd_elf_generic_reloc
, /* special_function */
941 AARCH64_R_STR (TLSGD_ADR_PAGE21
), /* name */
942 FALSE
, /* partial_inplace */
943 0x1fffff, /* src_mask */
944 0x1fffff, /* dst_mask */
945 TRUE
), /* pcrel_offset */
947 HOWTO (AARCH64_R (TLSGD_ADR_PREL21
), /* type */
949 2, /* size (0 = byte, 1 = short, 2 = long) */
951 TRUE
, /* pc_relative */
953 complain_overflow_dont
, /* complain_on_overflow */
954 bfd_elf_generic_reloc
, /* special_function */
955 AARCH64_R_STR (TLSGD_ADR_PREL21
), /* name */
956 FALSE
, /* partial_inplace */
957 0x1fffff, /* src_mask */
958 0x1fffff, /* dst_mask */
959 TRUE
), /* pcrel_offset */
961 /* ADD: GOT offset G(S) & 0xff8 [no overflow check] */
962 HOWTO (AARCH64_R (TLSGD_ADD_LO12_NC
), /* type */
964 2, /* size (0 = byte, 1 = short, 2 = long) */
966 FALSE
, /* pc_relative */
968 complain_overflow_dont
, /* complain_on_overflow */
969 bfd_elf_generic_reloc
, /* special_function */
970 AARCH64_R_STR (TLSGD_ADD_LO12_NC
), /* name */
971 FALSE
, /* partial_inplace */
972 0xfff, /* src_mask */
973 0xfff, /* dst_mask */
974 FALSE
), /* pcrel_offset */
976 HOWTO64 (AARCH64_R (TLSIE_MOVW_GOTTPREL_G1
), /* type */
978 2, /* size (0 = byte, 1 = short, 2 = long) */
980 FALSE
, /* pc_relative */
982 complain_overflow_dont
, /* complain_on_overflow */
983 bfd_elf_generic_reloc
, /* special_function */
984 AARCH64_R_STR (TLSIE_MOVW_GOTTPREL_G1
), /* name */
985 FALSE
, /* partial_inplace */
986 0xffff, /* src_mask */
987 0xffff, /* dst_mask */
988 FALSE
), /* pcrel_offset */
990 HOWTO64 (AARCH64_R (TLSIE_MOVW_GOTTPREL_G0_NC
), /* type */
992 2, /* size (0 = byte, 1 = short, 2 = long) */
994 FALSE
, /* pc_relative */
996 complain_overflow_dont
, /* complain_on_overflow */
997 bfd_elf_generic_reloc
, /* special_function */
998 AARCH64_R_STR (TLSIE_MOVW_GOTTPREL_G0_NC
), /* name */
999 FALSE
, /* partial_inplace */
1000 0xffff, /* src_mask */
1001 0xffff, /* dst_mask */
1002 FALSE
), /* pcrel_offset */
1004 HOWTO (AARCH64_R (TLSIE_ADR_GOTTPREL_PAGE21
), /* type */
1005 12, /* rightshift */
1006 2, /* size (0 = byte, 1 = short, 2 = long) */
1008 FALSE
, /* pc_relative */
1010 complain_overflow_dont
, /* complain_on_overflow */
1011 bfd_elf_generic_reloc
, /* special_function */
1012 AARCH64_R_STR (TLSIE_ADR_GOTTPREL_PAGE21
), /* name */
1013 FALSE
, /* partial_inplace */
1014 0x1fffff, /* src_mask */
1015 0x1fffff, /* dst_mask */
1016 FALSE
), /* pcrel_offset */
1018 HOWTO64 (AARCH64_R (TLSIE_LD64_GOTTPREL_LO12_NC
), /* type */
1020 2, /* size (0 = byte, 1 = short, 2 = long) */
1022 FALSE
, /* pc_relative */
1024 complain_overflow_dont
, /* complain_on_overflow */
1025 bfd_elf_generic_reloc
, /* special_function */
1026 AARCH64_R_STR (TLSIE_LD64_GOTTPREL_LO12_NC
), /* name */
1027 FALSE
, /* partial_inplace */
1028 0xff8, /* src_mask */
1029 0xff8, /* dst_mask */
1030 FALSE
), /* pcrel_offset */
1032 HOWTO32 (AARCH64_R (TLSIE_LD32_GOTTPREL_LO12_NC
), /* type */
1034 2, /* size (0 = byte, 1 = short, 2 = long) */
1036 FALSE
, /* pc_relative */
1038 complain_overflow_dont
, /* complain_on_overflow */
1039 bfd_elf_generic_reloc
, /* special_function */
1040 AARCH64_R_STR (TLSIE_LD32_GOTTPREL_LO12_NC
), /* name */
1041 FALSE
, /* partial_inplace */
1042 0xffc, /* src_mask */
1043 0xffc, /* dst_mask */
1044 FALSE
), /* pcrel_offset */
1046 HOWTO (AARCH64_R (TLSIE_LD_GOTTPREL_PREL19
), /* type */
1048 2, /* size (0 = byte, 1 = short, 2 = long) */
1050 FALSE
, /* pc_relative */
1052 complain_overflow_dont
, /* complain_on_overflow */
1053 bfd_elf_generic_reloc
, /* special_function */
1054 AARCH64_R_STR (TLSIE_LD_GOTTPREL_PREL19
), /* name */
1055 FALSE
, /* partial_inplace */
1056 0x1ffffc, /* src_mask */
1057 0x1ffffc, /* dst_mask */
1058 FALSE
), /* pcrel_offset */
1060 /* ADD: bit[23:12] of byte offset to module TLS base address. */
1061 HOWTO (AARCH64_R (TLSLD_ADD_DTPREL_HI12
), /* type */
1062 12, /* rightshift */
1063 2, /* size (0 = byte, 1 = short, 2 = long) */
1065 FALSE
, /* pc_relative */
1067 complain_overflow_unsigned
, /* complain_on_overflow */
1068 bfd_elf_generic_reloc
, /* special_function */
1069 AARCH64_R_STR (TLSLD_ADD_DTPREL_HI12
), /* name */
1070 FALSE
, /* partial_inplace */
1071 0xfff, /* src_mask */
1072 0xfff, /* dst_mask */
1073 FALSE
), /* pcrel_offset */
1075 /* Unsigned 12 bit byte offset to module TLS base address. */
1076 HOWTO (AARCH64_R (TLSLD_ADD_DTPREL_LO12
), /* type */
1078 2, /* size (0 = byte, 1 = short, 2 = long) */
1080 FALSE
, /* pc_relative */
1082 complain_overflow_unsigned
, /* complain_on_overflow */
1083 bfd_elf_generic_reloc
, /* special_function */
1084 AARCH64_R_STR (TLSLD_ADD_DTPREL_LO12
), /* name */
1085 FALSE
, /* partial_inplace */
1086 0xfff, /* src_mask */
1087 0xfff, /* dst_mask */
1088 FALSE
), /* pcrel_offset */
1090 /* No overflow check version of BFD_RELOC_AARCH64_TLSLD_ADD_DTPREL_LO12. */
1091 HOWTO (AARCH64_R (TLSLD_ADD_DTPREL_LO12_NC
), /* type */
1093 2, /* size (0 = byte, 1 = short, 2 = long) */
1095 FALSE
, /* pc_relative */
1097 complain_overflow_dont
, /* complain_on_overflow */
1098 bfd_elf_generic_reloc
, /* special_function */
1099 AARCH64_R_STR (TLSLD_ADD_DTPREL_LO12_NC
), /* name */
1100 FALSE
, /* partial_inplace */
1101 0xfff, /* src_mask */
1102 0xfff, /* dst_mask */
1103 FALSE
), /* pcrel_offset */
1105 /* ADD: GOT offset G(S) & 0xff8 [no overflow check] */
1106 HOWTO (AARCH64_R (TLSLD_ADD_LO12_NC
), /* type */
1108 2, /* size (0 = byte, 1 = short, 2 = long) */
1110 FALSE
, /* pc_relative */
1112 complain_overflow_dont
, /* complain_on_overflow */
1113 bfd_elf_generic_reloc
, /* special_function */
1114 AARCH64_R_STR (TLSLD_ADD_LO12_NC
), /* name */
1115 FALSE
, /* partial_inplace */
1116 0xfff, /* src_mask */
1117 0xfff, /* dst_mask */
1118 FALSE
), /* pcrel_offset */
1120 /* Get to the page for the GOT entry for the symbol
1121 (G(S) - P) using an ADRP instruction. */
1122 HOWTO (AARCH64_R (TLSLD_ADR_PAGE21
), /* type */
1123 12, /* rightshift */
1124 2, /* size (0 = byte, 1 = short, 2 = long) */
1126 TRUE
, /* pc_relative */
1128 complain_overflow_signed
, /* complain_on_overflow */
1129 bfd_elf_generic_reloc
, /* special_function */
1130 AARCH64_R_STR (TLSLD_ADR_PAGE21
), /* name */
1131 FALSE
, /* partial_inplace */
1132 0x1fffff, /* src_mask */
1133 0x1fffff, /* dst_mask */
1134 TRUE
), /* pcrel_offset */
1136 HOWTO (AARCH64_R (TLSLD_ADR_PREL21
), /* type */
1138 2, /* size (0 = byte, 1 = short, 2 = long) */
1140 TRUE
, /* pc_relative */
1142 complain_overflow_signed
, /* complain_on_overflow */
1143 bfd_elf_generic_reloc
, /* special_function */
1144 AARCH64_R_STR (TLSLD_ADR_PREL21
), /* name */
1145 FALSE
, /* partial_inplace */
1146 0x1fffff, /* src_mask */
1147 0x1fffff, /* dst_mask */
1148 TRUE
), /* pcrel_offset */
1150 /* LD/ST16: bit[11:1] of byte offset to module TLS base address. */
1151 HOWTO64 (AARCH64_R (TLSLD_LDST16_DTPREL_LO12
), /* type */
1153 2, /* size (0 = byte, 1 = short, 2 = long) */
1155 FALSE
, /* pc_relative */
1157 complain_overflow_unsigned
, /* complain_on_overflow */
1158 bfd_elf_generic_reloc
, /* special_function */
1159 AARCH64_R_STR (TLSLD_LDST16_DTPREL_LO12
), /* name */
1160 FALSE
, /* partial_inplace */
1161 0x1ffc00, /* src_mask */
1162 0x1ffc00, /* dst_mask */
1163 FALSE
), /* pcrel_offset */
1165 /* Same as BFD_RELOC_AARCH64_TLSLD_LDST16_DTPREL_LO12, but no overflow check. */
1166 HOWTO64 (AARCH64_R (TLSLD_LDST16_DTPREL_LO12_NC
), /* type */
1168 2, /* size (0 = byte, 1 = short, 2 = long) */
1170 FALSE
, /* pc_relative */
1172 complain_overflow_dont
, /* complain_on_overflow */
1173 bfd_elf_generic_reloc
, /* special_function */
1174 AARCH64_R_STR (TLSLD_LDST16_DTPREL_LO12_NC
), /* name */
1175 FALSE
, /* partial_inplace */
1176 0x1ffc00, /* src_mask */
1177 0x1ffc00, /* dst_mask */
1178 FALSE
), /* pcrel_offset */
1180 /* LD/ST32: bit[11:2] of byte offset to module TLS base address. */
1181 HOWTO64 (AARCH64_R (TLSLD_LDST32_DTPREL_LO12
), /* type */
1183 2, /* size (0 = byte, 1 = short, 2 = long) */
1185 FALSE
, /* pc_relative */
1187 complain_overflow_unsigned
, /* complain_on_overflow */
1188 bfd_elf_generic_reloc
, /* special_function */
1189 AARCH64_R_STR (TLSLD_LDST32_DTPREL_LO12
), /* name */
1190 FALSE
, /* partial_inplace */
1191 0x3ffc00, /* src_mask */
1192 0x3ffc00, /* dst_mask */
1193 FALSE
), /* pcrel_offset */
1195 /* Same as BFD_RELOC_AARCH64_TLSLD_LDST32_DTPREL_LO12, but no overflow check. */
1196 HOWTO64 (AARCH64_R (TLSLD_LDST32_DTPREL_LO12_NC
), /* type */
1198 2, /* size (0 = byte, 1 = short, 2 = long) */
1200 FALSE
, /* pc_relative */
1202 complain_overflow_dont
, /* complain_on_overflow */
1203 bfd_elf_generic_reloc
, /* special_function */
1204 AARCH64_R_STR (TLSLD_LDST32_DTPREL_LO12_NC
), /* name */
1205 FALSE
, /* partial_inplace */
1206 0xffc00, /* src_mask */
1207 0xffc00, /* dst_mask */
1208 FALSE
), /* pcrel_offset */
1210 /* LD/ST64: bit[11:3] of byte offset to module TLS base address. */
1211 HOWTO64 (AARCH64_R (TLSLD_LDST64_DTPREL_LO12
), /* type */
1213 2, /* size (0 = byte, 1 = short, 2 = long) */
1215 FALSE
, /* pc_relative */
1217 complain_overflow_unsigned
, /* complain_on_overflow */
1218 bfd_elf_generic_reloc
, /* special_function */
1219 AARCH64_R_STR (TLSLD_LDST64_DTPREL_LO12
), /* name */
1220 FALSE
, /* partial_inplace */
1221 0x3ffc00, /* src_mask */
1222 0x3ffc00, /* dst_mask */
1223 FALSE
), /* pcrel_offset */
1225 /* Same as BFD_RELOC_AARCH64_TLSLD_LDST64_DTPREL_LO12, but no overflow check. */
1226 HOWTO64 (AARCH64_R (TLSLD_LDST64_DTPREL_LO12_NC
), /* type */
1228 2, /* size (0 = byte, 1 = short, 2 = long) */
1230 FALSE
, /* pc_relative */
1232 complain_overflow_dont
, /* complain_on_overflow */
1233 bfd_elf_generic_reloc
, /* special_function */
1234 AARCH64_R_STR (TLSLD_LDST64_DTPREL_LO12_NC
), /* name */
1235 FALSE
, /* partial_inplace */
1236 0x7fc00, /* src_mask */
1237 0x7fc00, /* dst_mask */
1238 FALSE
), /* pcrel_offset */
1240 /* LD/ST8: bit[11:0] of byte offset to module TLS base address. */
1241 HOWTO64 (AARCH64_R (TLSLD_LDST8_DTPREL_LO12
), /* type */
1243 2, /* size (0 = byte, 1 = short, 2 = long) */
1245 FALSE
, /* pc_relative */
1247 complain_overflow_unsigned
, /* complain_on_overflow */
1248 bfd_elf_generic_reloc
, /* special_function */
1249 AARCH64_R_STR (TLSLD_LDST8_DTPREL_LO12
), /* name */
1250 FALSE
, /* partial_inplace */
1251 0x3ffc00, /* src_mask */
1252 0x3ffc00, /* dst_mask */
1253 FALSE
), /* pcrel_offset */
1255 /* Same as BFD_RELOC_AARCH64_TLSLD_LDST8_DTPREL_LO12, but no overflow check. */
1256 HOWTO64 (AARCH64_R (TLSLD_LDST8_DTPREL_LO12_NC
), /* 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 (TLSLD_LDST8_DTPREL_LO12_NC
), /* name */
1265 FALSE
, /* partial_inplace */
1266 0x3ffc00, /* src_mask */
1267 0x3ffc00, /* dst_mask */
1268 FALSE
), /* pcrel_offset */
1270 /* MOVZ: bit[15:0] of byte offset to module TLS base address. */
1271 HOWTO (AARCH64_R (TLSLD_MOVW_DTPREL_G0
), /* type */
1273 2, /* size (0 = byte, 1 = short, 2 = long) */
1275 FALSE
, /* pc_relative */
1277 complain_overflow_unsigned
, /* complain_on_overflow */
1278 bfd_elf_generic_reloc
, /* special_function */
1279 AARCH64_R_STR (TLSLD_MOVW_DTPREL_G0
), /* name */
1280 FALSE
, /* partial_inplace */
1281 0xffff, /* src_mask */
1282 0xffff, /* dst_mask */
1283 FALSE
), /* pcrel_offset */
1285 /* No overflow check version of BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G0. */
1286 HOWTO (AARCH64_R (TLSLD_MOVW_DTPREL_G0_NC
), /* type */
1288 2, /* size (0 = byte, 1 = short, 2 = long) */
1290 FALSE
, /* pc_relative */
1292 complain_overflow_dont
, /* complain_on_overflow */
1293 bfd_elf_generic_reloc
, /* special_function */
1294 AARCH64_R_STR (TLSLD_MOVW_DTPREL_G0_NC
), /* name */
1295 FALSE
, /* partial_inplace */
1296 0xffff, /* src_mask */
1297 0xffff, /* dst_mask */
1298 FALSE
), /* pcrel_offset */
1300 /* MOVZ: bit[31:16] of byte offset to module TLS base address. */
1301 HOWTO (AARCH64_R (TLSLD_MOVW_DTPREL_G1
), /* type */
1302 16, /* rightshift */
1303 2, /* size (0 = byte, 1 = short, 2 = long) */
1305 FALSE
, /* pc_relative */
1307 complain_overflow_unsigned
, /* complain_on_overflow */
1308 bfd_elf_generic_reloc
, /* special_function */
1309 AARCH64_R_STR (TLSLD_MOVW_DTPREL_G1
), /* name */
1310 FALSE
, /* partial_inplace */
1311 0xffff, /* src_mask */
1312 0xffff, /* dst_mask */
1313 FALSE
), /* pcrel_offset */
1315 /* No overflow check version of BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G1. */
1316 HOWTO64 (AARCH64_R (TLSLD_MOVW_DTPREL_G1_NC
), /* type */
1317 16, /* rightshift */
1318 2, /* size (0 = byte, 1 = short, 2 = long) */
1320 FALSE
, /* pc_relative */
1322 complain_overflow_dont
, /* complain_on_overflow */
1323 bfd_elf_generic_reloc
, /* special_function */
1324 AARCH64_R_STR (TLSLD_MOVW_DTPREL_G1_NC
), /* name */
1325 FALSE
, /* partial_inplace */
1326 0xffff, /* src_mask */
1327 0xffff, /* dst_mask */
1328 FALSE
), /* pcrel_offset */
1330 /* MOVZ: bit[47:32] of byte offset to module TLS base address. */
1331 HOWTO64 (AARCH64_R (TLSLD_MOVW_DTPREL_G2
), /* type */
1332 32, /* rightshift */
1333 2, /* size (0 = byte, 1 = short, 2 = long) */
1335 FALSE
, /* pc_relative */
1337 complain_overflow_unsigned
, /* complain_on_overflow */
1338 bfd_elf_generic_reloc
, /* special_function */
1339 AARCH64_R_STR (TLSLD_MOVW_DTPREL_G2
), /* name */
1340 FALSE
, /* partial_inplace */
1341 0xffff, /* src_mask */
1342 0xffff, /* dst_mask */
1343 FALSE
), /* pcrel_offset */
1345 HOWTO64 (AARCH64_R (TLSLE_MOVW_TPREL_G2
), /* type */
1346 32, /* rightshift */
1347 2, /* size (0 = byte, 1 = short, 2 = long) */
1349 FALSE
, /* pc_relative */
1351 complain_overflow_unsigned
, /* complain_on_overflow */
1352 bfd_elf_generic_reloc
, /* special_function */
1353 AARCH64_R_STR (TLSLE_MOVW_TPREL_G2
), /* name */
1354 FALSE
, /* partial_inplace */
1355 0xffff, /* src_mask */
1356 0xffff, /* dst_mask */
1357 FALSE
), /* pcrel_offset */
1359 HOWTO (AARCH64_R (TLSLE_MOVW_TPREL_G1
), /* type */
1360 16, /* rightshift */
1361 2, /* size (0 = byte, 1 = short, 2 = long) */
1363 FALSE
, /* pc_relative */
1365 complain_overflow_dont
, /* complain_on_overflow */
1366 bfd_elf_generic_reloc
, /* special_function */
1367 AARCH64_R_STR (TLSLE_MOVW_TPREL_G1
), /* name */
1368 FALSE
, /* partial_inplace */
1369 0xffff, /* src_mask */
1370 0xffff, /* dst_mask */
1371 FALSE
), /* pcrel_offset */
1373 HOWTO64 (AARCH64_R (TLSLE_MOVW_TPREL_G1_NC
), /* type */
1374 16, /* rightshift */
1375 2, /* size (0 = byte, 1 = short, 2 = long) */
1377 FALSE
, /* pc_relative */
1379 complain_overflow_dont
, /* complain_on_overflow */
1380 bfd_elf_generic_reloc
, /* special_function */
1381 AARCH64_R_STR (TLSLE_MOVW_TPREL_G1_NC
), /* name */
1382 FALSE
, /* partial_inplace */
1383 0xffff, /* src_mask */
1384 0xffff, /* dst_mask */
1385 FALSE
), /* pcrel_offset */
1387 HOWTO (AARCH64_R (TLSLE_MOVW_TPREL_G0
), /* type */
1389 2, /* size (0 = byte, 1 = short, 2 = long) */
1391 FALSE
, /* pc_relative */
1393 complain_overflow_dont
, /* complain_on_overflow */
1394 bfd_elf_generic_reloc
, /* special_function */
1395 AARCH64_R_STR (TLSLE_MOVW_TPREL_G0
), /* name */
1396 FALSE
, /* partial_inplace */
1397 0xffff, /* src_mask */
1398 0xffff, /* dst_mask */
1399 FALSE
), /* pcrel_offset */
1401 HOWTO (AARCH64_R (TLSLE_MOVW_TPREL_G0_NC
), /* type */
1403 2, /* size (0 = byte, 1 = short, 2 = long) */
1405 FALSE
, /* pc_relative */
1407 complain_overflow_dont
, /* complain_on_overflow */
1408 bfd_elf_generic_reloc
, /* special_function */
1409 AARCH64_R_STR (TLSLE_MOVW_TPREL_G0_NC
), /* name */
1410 FALSE
, /* partial_inplace */
1411 0xffff, /* src_mask */
1412 0xffff, /* dst_mask */
1413 FALSE
), /* pcrel_offset */
1415 HOWTO (AARCH64_R (TLSLE_ADD_TPREL_HI12
), /* type */
1416 12, /* rightshift */
1417 2, /* size (0 = byte, 1 = short, 2 = long) */
1419 FALSE
, /* pc_relative */
1421 complain_overflow_unsigned
, /* complain_on_overflow */
1422 bfd_elf_generic_reloc
, /* special_function */
1423 AARCH64_R_STR (TLSLE_ADD_TPREL_HI12
), /* name */
1424 FALSE
, /* partial_inplace */
1425 0xfff, /* src_mask */
1426 0xfff, /* dst_mask */
1427 FALSE
), /* pcrel_offset */
1429 HOWTO (AARCH64_R (TLSLE_ADD_TPREL_LO12
), /* type */
1431 2, /* size (0 = byte, 1 = short, 2 = long) */
1433 FALSE
, /* pc_relative */
1435 complain_overflow_unsigned
, /* complain_on_overflow */
1436 bfd_elf_generic_reloc
, /* special_function */
1437 AARCH64_R_STR (TLSLE_ADD_TPREL_LO12
), /* name */
1438 FALSE
, /* partial_inplace */
1439 0xfff, /* src_mask */
1440 0xfff, /* dst_mask */
1441 FALSE
), /* pcrel_offset */
1443 HOWTO (AARCH64_R (TLSLE_ADD_TPREL_LO12_NC
), /* type */
1445 2, /* size (0 = byte, 1 = short, 2 = long) */
1447 FALSE
, /* pc_relative */
1449 complain_overflow_dont
, /* complain_on_overflow */
1450 bfd_elf_generic_reloc
, /* special_function */
1451 AARCH64_R_STR (TLSLE_ADD_TPREL_LO12_NC
), /* name */
1452 FALSE
, /* partial_inplace */
1453 0xfff, /* src_mask */
1454 0xfff, /* dst_mask */
1455 FALSE
), /* pcrel_offset */
1457 HOWTO (AARCH64_R (TLSDESC_LD_PREL19
), /* type */
1459 2, /* size (0 = byte, 1 = short, 2 = long) */
1461 TRUE
, /* pc_relative */
1463 complain_overflow_dont
, /* complain_on_overflow */
1464 bfd_elf_generic_reloc
, /* special_function */
1465 AARCH64_R_STR (TLSDESC_LD_PREL19
), /* name */
1466 FALSE
, /* partial_inplace */
1467 0x0ffffe0, /* src_mask */
1468 0x0ffffe0, /* dst_mask */
1469 TRUE
), /* pcrel_offset */
1471 HOWTO (AARCH64_R (TLSDESC_ADR_PREL21
), /* type */
1473 2, /* size (0 = byte, 1 = short, 2 = long) */
1475 TRUE
, /* pc_relative */
1477 complain_overflow_dont
, /* complain_on_overflow */
1478 bfd_elf_generic_reloc
, /* special_function */
1479 AARCH64_R_STR (TLSDESC_ADR_PREL21
), /* name */
1480 FALSE
, /* partial_inplace */
1481 0x1fffff, /* src_mask */
1482 0x1fffff, /* dst_mask */
1483 TRUE
), /* pcrel_offset */
1485 /* Get to the page for the GOT entry for the symbol
1486 (G(S) - P) using an ADRP instruction. */
1487 HOWTO (AARCH64_R (TLSDESC_ADR_PAGE21
), /* type */
1488 12, /* rightshift */
1489 2, /* size (0 = byte, 1 = short, 2 = long) */
1491 TRUE
, /* pc_relative */
1493 complain_overflow_dont
, /* complain_on_overflow */
1494 bfd_elf_generic_reloc
, /* special_function */
1495 AARCH64_R_STR (TLSDESC_ADR_PAGE21
), /* name */
1496 FALSE
, /* partial_inplace */
1497 0x1fffff, /* src_mask */
1498 0x1fffff, /* dst_mask */
1499 TRUE
), /* pcrel_offset */
1501 /* LD64: GOT offset G(S) & 0xff8. */
1502 HOWTO64 (AARCH64_R (TLSDESC_LD64_LO12_NC
), /* type */
1504 2, /* size (0 = byte, 1 = short, 2 = long) */
1506 FALSE
, /* pc_relative */
1508 complain_overflow_dont
, /* complain_on_overflow */
1509 bfd_elf_generic_reloc
, /* special_function */
1510 AARCH64_R_STR (TLSDESC_LD64_LO12_NC
), /* name */
1511 FALSE
, /* partial_inplace */
1512 0xff8, /* src_mask */
1513 0xff8, /* dst_mask */
1514 FALSE
), /* pcrel_offset */
1516 /* LD32: GOT offset G(S) & 0xffc. */
1517 HOWTO32 (AARCH64_R (TLSDESC_LD32_LO12_NC
), /* type */
1519 2, /* size (0 = byte, 1 = short, 2 = long) */
1521 FALSE
, /* pc_relative */
1523 complain_overflow_dont
, /* complain_on_overflow */
1524 bfd_elf_generic_reloc
, /* special_function */
1525 AARCH64_R_STR (TLSDESC_LD32_LO12_NC
), /* name */
1526 FALSE
, /* partial_inplace */
1527 0xffc, /* src_mask */
1528 0xffc, /* dst_mask */
1529 FALSE
), /* pcrel_offset */
1531 /* ADD: GOT offset G(S) & 0xfff. */
1532 HOWTO (AARCH64_R (TLSDESC_ADD_LO12_NC
), /* type */
1534 2, /* size (0 = byte, 1 = short, 2 = long) */
1536 FALSE
, /* pc_relative */
1538 complain_overflow_dont
, /* complain_on_overflow */
1539 bfd_elf_generic_reloc
, /* special_function */
1540 AARCH64_R_STR (TLSDESC_ADD_LO12_NC
), /* name */
1541 FALSE
, /* partial_inplace */
1542 0xfff, /* src_mask */
1543 0xfff, /* dst_mask */
1544 FALSE
), /* pcrel_offset */
1546 HOWTO64 (AARCH64_R (TLSDESC_OFF_G1
), /* type */
1547 16, /* rightshift */
1548 2, /* size (0 = byte, 1 = short, 2 = long) */
1550 FALSE
, /* pc_relative */
1552 complain_overflow_dont
, /* complain_on_overflow */
1553 bfd_elf_generic_reloc
, /* special_function */
1554 AARCH64_R_STR (TLSDESC_OFF_G1
), /* name */
1555 FALSE
, /* partial_inplace */
1556 0xffff, /* src_mask */
1557 0xffff, /* dst_mask */
1558 FALSE
), /* pcrel_offset */
1560 HOWTO64 (AARCH64_R (TLSDESC_OFF_G0_NC
), /* type */
1562 2, /* size (0 = byte, 1 = short, 2 = long) */
1564 FALSE
, /* pc_relative */
1566 complain_overflow_dont
, /* complain_on_overflow */
1567 bfd_elf_generic_reloc
, /* special_function */
1568 AARCH64_R_STR (TLSDESC_OFF_G0_NC
), /* name */
1569 FALSE
, /* partial_inplace */
1570 0xffff, /* src_mask */
1571 0xffff, /* dst_mask */
1572 FALSE
), /* pcrel_offset */
1574 HOWTO64 (AARCH64_R (TLSDESC_LDR
), /* type */
1576 2, /* size (0 = byte, 1 = short, 2 = long) */
1578 FALSE
, /* pc_relative */
1580 complain_overflow_dont
, /* complain_on_overflow */
1581 bfd_elf_generic_reloc
, /* special_function */
1582 AARCH64_R_STR (TLSDESC_LDR
), /* name */
1583 FALSE
, /* partial_inplace */
1586 FALSE
), /* pcrel_offset */
1588 HOWTO64 (AARCH64_R (TLSDESC_ADD
), /* type */
1590 2, /* size (0 = byte, 1 = short, 2 = long) */
1592 FALSE
, /* pc_relative */
1594 complain_overflow_dont
, /* complain_on_overflow */
1595 bfd_elf_generic_reloc
, /* special_function */
1596 AARCH64_R_STR (TLSDESC_ADD
), /* name */
1597 FALSE
, /* partial_inplace */
1600 FALSE
), /* pcrel_offset */
1602 HOWTO (AARCH64_R (TLSDESC_CALL
), /* type */
1604 2, /* size (0 = byte, 1 = short, 2 = long) */
1606 FALSE
, /* pc_relative */
1608 complain_overflow_dont
, /* complain_on_overflow */
1609 bfd_elf_generic_reloc
, /* special_function */
1610 AARCH64_R_STR (TLSDESC_CALL
), /* name */
1611 FALSE
, /* partial_inplace */
1614 FALSE
), /* pcrel_offset */
1616 HOWTO (AARCH64_R (COPY
), /* type */
1618 2, /* size (0 = byte, 1 = short, 2 = long) */
1620 FALSE
, /* pc_relative */
1622 complain_overflow_bitfield
, /* complain_on_overflow */
1623 bfd_elf_generic_reloc
, /* special_function */
1624 AARCH64_R_STR (COPY
), /* name */
1625 TRUE
, /* partial_inplace */
1626 0xffffffff, /* src_mask */
1627 0xffffffff, /* dst_mask */
1628 FALSE
), /* pcrel_offset */
1630 HOWTO (AARCH64_R (GLOB_DAT
), /* type */
1632 2, /* size (0 = byte, 1 = short, 2 = long) */
1634 FALSE
, /* pc_relative */
1636 complain_overflow_bitfield
, /* complain_on_overflow */
1637 bfd_elf_generic_reloc
, /* special_function */
1638 AARCH64_R_STR (GLOB_DAT
), /* name */
1639 TRUE
, /* partial_inplace */
1640 0xffffffff, /* src_mask */
1641 0xffffffff, /* dst_mask */
1642 FALSE
), /* pcrel_offset */
1644 HOWTO (AARCH64_R (JUMP_SLOT
), /* type */
1646 2, /* size (0 = byte, 1 = short, 2 = long) */
1648 FALSE
, /* pc_relative */
1650 complain_overflow_bitfield
, /* complain_on_overflow */
1651 bfd_elf_generic_reloc
, /* special_function */
1652 AARCH64_R_STR (JUMP_SLOT
), /* name */
1653 TRUE
, /* partial_inplace */
1654 0xffffffff, /* src_mask */
1655 0xffffffff, /* dst_mask */
1656 FALSE
), /* pcrel_offset */
1658 HOWTO (AARCH64_R (RELATIVE
), /* type */
1660 2, /* size (0 = byte, 1 = short, 2 = long) */
1662 FALSE
, /* pc_relative */
1664 complain_overflow_bitfield
, /* complain_on_overflow */
1665 bfd_elf_generic_reloc
, /* special_function */
1666 AARCH64_R_STR (RELATIVE
), /* name */
1667 TRUE
, /* partial_inplace */
1668 ALL_ONES
, /* src_mask */
1669 ALL_ONES
, /* dst_mask */
1670 FALSE
), /* pcrel_offset */
1672 HOWTO (AARCH64_R (TLS_DTPMOD
), /* type */
1674 2, /* size (0 = byte, 1 = short, 2 = long) */
1676 FALSE
, /* pc_relative */
1678 complain_overflow_dont
, /* complain_on_overflow */
1679 bfd_elf_generic_reloc
, /* special_function */
1681 AARCH64_R_STR (TLS_DTPMOD64
), /* name */
1683 AARCH64_R_STR (TLS_DTPMOD
), /* name */
1685 FALSE
, /* partial_inplace */
1687 ALL_ONES
, /* dst_mask */
1688 FALSE
), /* pc_reloffset */
1690 HOWTO (AARCH64_R (TLS_DTPREL
), /* type */
1692 2, /* size (0 = byte, 1 = short, 2 = long) */
1694 FALSE
, /* pc_relative */
1696 complain_overflow_dont
, /* complain_on_overflow */
1697 bfd_elf_generic_reloc
, /* special_function */
1699 AARCH64_R_STR (TLS_DTPREL64
), /* name */
1701 AARCH64_R_STR (TLS_DTPREL
), /* name */
1703 FALSE
, /* partial_inplace */
1705 ALL_ONES
, /* dst_mask */
1706 FALSE
), /* pcrel_offset */
1708 HOWTO (AARCH64_R (TLS_TPREL
), /* type */
1710 2, /* size (0 = byte, 1 = short, 2 = long) */
1712 FALSE
, /* pc_relative */
1714 complain_overflow_dont
, /* complain_on_overflow */
1715 bfd_elf_generic_reloc
, /* special_function */
1717 AARCH64_R_STR (TLS_TPREL64
), /* name */
1719 AARCH64_R_STR (TLS_TPREL
), /* name */
1721 FALSE
, /* partial_inplace */
1723 ALL_ONES
, /* dst_mask */
1724 FALSE
), /* pcrel_offset */
1726 HOWTO (AARCH64_R (TLSDESC
), /* type */
1728 2, /* size (0 = byte, 1 = short, 2 = long) */
1730 FALSE
, /* pc_relative */
1732 complain_overflow_dont
, /* complain_on_overflow */
1733 bfd_elf_generic_reloc
, /* special_function */
1734 AARCH64_R_STR (TLSDESC
), /* name */
1735 FALSE
, /* partial_inplace */
1737 ALL_ONES
, /* dst_mask */
1738 FALSE
), /* pcrel_offset */
1740 HOWTO (AARCH64_R (IRELATIVE
), /* type */
1742 2, /* size (0 = byte, 1 = short, 2 = long) */
1744 FALSE
, /* pc_relative */
1746 complain_overflow_bitfield
, /* complain_on_overflow */
1747 bfd_elf_generic_reloc
, /* special_function */
1748 AARCH64_R_STR (IRELATIVE
), /* name */
1749 FALSE
, /* partial_inplace */
1751 ALL_ONES
, /* dst_mask */
1752 FALSE
), /* pcrel_offset */
1757 static reloc_howto_type elfNN_aarch64_howto_none
=
1758 HOWTO (R_AARCH64_NONE
, /* type */
1760 3, /* size (0 = byte, 1 = short, 2 = long) */
1762 FALSE
, /* pc_relative */
1764 complain_overflow_dont
,/* complain_on_overflow */
1765 bfd_elf_generic_reloc
, /* special_function */
1766 "R_AARCH64_NONE", /* name */
1767 FALSE
, /* partial_inplace */
1770 FALSE
); /* pcrel_offset */
1772 /* Given HOWTO, return the bfd internal relocation enumerator. */
1774 static bfd_reloc_code_real_type
1775 elfNN_aarch64_bfd_reloc_from_howto (reloc_howto_type
*howto
)
1778 = (int) ARRAY_SIZE (elfNN_aarch64_howto_table
);
1779 const ptrdiff_t offset
1780 = howto
- elfNN_aarch64_howto_table
;
1782 if (offset
> 0 && offset
< size
- 1)
1783 return BFD_RELOC_AARCH64_RELOC_START
+ offset
;
1785 if (howto
== &elfNN_aarch64_howto_none
)
1786 return BFD_RELOC_AARCH64_NONE
;
1788 return BFD_RELOC_AARCH64_RELOC_START
;
1791 /* Given R_TYPE, return the bfd internal relocation enumerator. */
1793 static bfd_reloc_code_real_type
1794 elfNN_aarch64_bfd_reloc_from_type (unsigned int r_type
)
1796 static bfd_boolean initialized_p
= FALSE
;
1797 /* Indexed by R_TYPE, values are offsets in the howto_table. */
1798 static unsigned int offsets
[R_AARCH64_end
];
1800 if (initialized_p
== FALSE
)
1804 for (i
= 1; i
< ARRAY_SIZE (elfNN_aarch64_howto_table
) - 1; ++i
)
1805 if (elfNN_aarch64_howto_table
[i
].type
!= 0)
1806 offsets
[elfNN_aarch64_howto_table
[i
].type
] = i
;
1808 initialized_p
= TRUE
;
1811 if (r_type
== R_AARCH64_NONE
|| r_type
== R_AARCH64_NULL
)
1812 return BFD_RELOC_AARCH64_NONE
;
1814 /* PR 17512: file: b371e70a. */
1815 if (r_type
>= R_AARCH64_end
)
1817 _bfd_error_handler (_("Invalid AArch64 reloc number: %d"), r_type
);
1818 bfd_set_error (bfd_error_bad_value
);
1819 return BFD_RELOC_AARCH64_NONE
;
1822 return BFD_RELOC_AARCH64_RELOC_START
+ offsets
[r_type
];
1825 struct elf_aarch64_reloc_map
1827 bfd_reloc_code_real_type from
;
1828 bfd_reloc_code_real_type to
;
1831 /* Map bfd generic reloc to AArch64-specific reloc. */
1832 static const struct elf_aarch64_reloc_map elf_aarch64_reloc_map
[] =
1834 {BFD_RELOC_NONE
, BFD_RELOC_AARCH64_NONE
},
1836 /* Basic data relocations. */
1837 {BFD_RELOC_CTOR
, BFD_RELOC_AARCH64_NN
},
1838 {BFD_RELOC_64
, BFD_RELOC_AARCH64_64
},
1839 {BFD_RELOC_32
, BFD_RELOC_AARCH64_32
},
1840 {BFD_RELOC_16
, BFD_RELOC_AARCH64_16
},
1841 {BFD_RELOC_64_PCREL
, BFD_RELOC_AARCH64_64_PCREL
},
1842 {BFD_RELOC_32_PCREL
, BFD_RELOC_AARCH64_32_PCREL
},
1843 {BFD_RELOC_16_PCREL
, BFD_RELOC_AARCH64_16_PCREL
},
1846 /* Given the bfd internal relocation enumerator in CODE, return the
1847 corresponding howto entry. */
1849 static reloc_howto_type
*
1850 elfNN_aarch64_howto_from_bfd_reloc (bfd_reloc_code_real_type code
)
1854 /* Convert bfd generic reloc to AArch64-specific reloc. */
1855 if (code
< BFD_RELOC_AARCH64_RELOC_START
1856 || code
> BFD_RELOC_AARCH64_RELOC_END
)
1857 for (i
= 0; i
< ARRAY_SIZE (elf_aarch64_reloc_map
); i
++)
1858 if (elf_aarch64_reloc_map
[i
].from
== code
)
1860 code
= elf_aarch64_reloc_map
[i
].to
;
1864 if (code
> BFD_RELOC_AARCH64_RELOC_START
1865 && code
< BFD_RELOC_AARCH64_RELOC_END
)
1866 if (elfNN_aarch64_howto_table
[code
- BFD_RELOC_AARCH64_RELOC_START
].type
)
1867 return &elfNN_aarch64_howto_table
[code
- BFD_RELOC_AARCH64_RELOC_START
];
1869 if (code
== BFD_RELOC_AARCH64_NONE
)
1870 return &elfNN_aarch64_howto_none
;
1875 static reloc_howto_type
*
1876 elfNN_aarch64_howto_from_type (unsigned int r_type
)
1878 bfd_reloc_code_real_type val
;
1879 reloc_howto_type
*howto
;
1884 bfd_set_error (bfd_error_bad_value
);
1889 if (r_type
== R_AARCH64_NONE
)
1890 return &elfNN_aarch64_howto_none
;
1892 val
= elfNN_aarch64_bfd_reloc_from_type (r_type
);
1893 howto
= elfNN_aarch64_howto_from_bfd_reloc (val
);
1898 bfd_set_error (bfd_error_bad_value
);
1903 elfNN_aarch64_info_to_howto (bfd
*abfd ATTRIBUTE_UNUSED
, arelent
*bfd_reloc
,
1904 Elf_Internal_Rela
*elf_reloc
)
1906 unsigned int r_type
;
1908 r_type
= ELFNN_R_TYPE (elf_reloc
->r_info
);
1909 bfd_reloc
->howto
= elfNN_aarch64_howto_from_type (r_type
);
1912 static reloc_howto_type
*
1913 elfNN_aarch64_reloc_type_lookup (bfd
*abfd ATTRIBUTE_UNUSED
,
1914 bfd_reloc_code_real_type code
)
1916 reloc_howto_type
*howto
= elfNN_aarch64_howto_from_bfd_reloc (code
);
1921 bfd_set_error (bfd_error_bad_value
);
1925 static reloc_howto_type
*
1926 elfNN_aarch64_reloc_name_lookup (bfd
*abfd ATTRIBUTE_UNUSED
,
1931 for (i
= 1; i
< ARRAY_SIZE (elfNN_aarch64_howto_table
) - 1; ++i
)
1932 if (elfNN_aarch64_howto_table
[i
].name
!= NULL
1933 && strcasecmp (elfNN_aarch64_howto_table
[i
].name
, r_name
) == 0)
1934 return &elfNN_aarch64_howto_table
[i
];
1939 #define TARGET_LITTLE_SYM aarch64_elfNN_le_vec
1940 #define TARGET_LITTLE_NAME "elfNN-littleaarch64"
1941 #define TARGET_BIG_SYM aarch64_elfNN_be_vec
1942 #define TARGET_BIG_NAME "elfNN-bigaarch64"
1944 /* The linker script knows the section names for placement.
1945 The entry_names are used to do simple name mangling on the stubs.
1946 Given a function name, and its type, the stub can be found. The
1947 name can be changed. The only requirement is the %s be present. */
1948 #define STUB_ENTRY_NAME "__%s_veneer"
1950 /* The name of the dynamic interpreter. This is put in the .interp
1952 #define ELF_DYNAMIC_INTERPRETER "/lib/ld.so.1"
1954 #define AARCH64_MAX_FWD_BRANCH_OFFSET \
1955 (((1 << 25) - 1) << 2)
1956 #define AARCH64_MAX_BWD_BRANCH_OFFSET \
1959 #define AARCH64_MAX_ADRP_IMM ((1 << 20) - 1)
1960 #define AARCH64_MIN_ADRP_IMM (-(1 << 20))
1963 aarch64_valid_for_adrp_p (bfd_vma value
, bfd_vma place
)
1965 bfd_signed_vma offset
= (bfd_signed_vma
) (PG (value
) - PG (place
)) >> 12;
1966 return offset
<= AARCH64_MAX_ADRP_IMM
&& offset
>= AARCH64_MIN_ADRP_IMM
;
1970 aarch64_valid_branch_p (bfd_vma value
, bfd_vma place
)
1972 bfd_signed_vma offset
= (bfd_signed_vma
) (value
- place
);
1973 return (offset
<= AARCH64_MAX_FWD_BRANCH_OFFSET
1974 && offset
>= AARCH64_MAX_BWD_BRANCH_OFFSET
);
1977 static const uint32_t aarch64_adrp_branch_stub
[] =
1979 0x90000010, /* adrp ip0, X */
1980 /* R_AARCH64_ADR_HI21_PCREL(X) */
1981 0x91000210, /* add ip0, ip0, :lo12:X */
1982 /* R_AARCH64_ADD_ABS_LO12_NC(X) */
1983 0xd61f0200, /* br ip0 */
1986 static const uint32_t aarch64_long_branch_stub
[] =
1989 0x58000090, /* ldr ip0, 1f */
1991 0x18000090, /* ldr wip0, 1f */
1993 0x10000011, /* adr ip1, #0 */
1994 0x8b110210, /* add ip0, ip0, ip1 */
1995 0xd61f0200, /* br ip0 */
1996 0x00000000, /* 1: .xword or .word
1997 R_AARCH64_PRELNN(X) + 12
2002 static const uint32_t aarch64_erratum_835769_stub
[] =
2004 0x00000000, /* Placeholder for multiply accumulate. */
2005 0x14000000, /* b <label> */
2008 static const uint32_t aarch64_erratum_843419_stub
[] =
2010 0x00000000, /* Placeholder for LDR instruction. */
2011 0x14000000, /* b <label> */
2014 /* Section name for stubs is the associated section name plus this
2016 #define STUB_SUFFIX ".stub"
2018 enum elf_aarch64_stub_type
2021 aarch64_stub_adrp_branch
,
2022 aarch64_stub_long_branch
,
2023 aarch64_stub_erratum_835769_veneer
,
2024 aarch64_stub_erratum_843419_veneer
,
2027 struct elf_aarch64_stub_hash_entry
2029 /* Base hash table entry structure. */
2030 struct bfd_hash_entry root
;
2032 /* The stub section. */
2035 /* Offset within stub_sec of the beginning of this stub. */
2036 bfd_vma stub_offset
;
2038 /* Given the symbol's value and its section we can determine its final
2039 value when building the stubs (so the stub knows where to jump). */
2040 bfd_vma target_value
;
2041 asection
*target_section
;
2043 enum elf_aarch64_stub_type stub_type
;
2045 /* The symbol table entry, if any, that this was derived from. */
2046 struct elf_aarch64_link_hash_entry
*h
;
2048 /* Destination symbol type */
2049 unsigned char st_type
;
2051 /* Where this stub is being called from, or, in the case of combined
2052 stub sections, the first input section in the group. */
2055 /* The name for the local symbol at the start of this stub. The
2056 stub name in the hash table has to be unique; this does not, so
2057 it can be friendlier. */
2060 /* The instruction which caused this stub to be generated (only valid for
2061 erratum 835769 workaround stubs at present). */
2062 uint32_t veneered_insn
;
2064 /* In an erratum 843419 workaround stub, the ADRP instruction offset. */
2065 bfd_vma adrp_offset
;
2068 /* Used to build a map of a section. This is required for mixed-endian
2071 typedef struct elf_elf_section_map
2076 elf_aarch64_section_map
;
2079 typedef struct _aarch64_elf_section_data
2081 struct bfd_elf_section_data elf
;
2082 unsigned int mapcount
;
2083 unsigned int mapsize
;
2084 elf_aarch64_section_map
*map
;
2086 _aarch64_elf_section_data
;
2088 #define elf_aarch64_section_data(sec) \
2089 ((_aarch64_elf_section_data *) elf_section_data (sec))
2091 /* The size of the thread control block which is defined to be two pointers. */
2092 #define TCB_SIZE (ARCH_SIZE/8)*2
2094 struct elf_aarch64_local_symbol
2096 unsigned int got_type
;
2097 bfd_signed_vma got_refcount
;
2100 /* Offset of the GOTPLT entry reserved for the TLS descriptor. The
2101 offset is from the end of the jump table and reserved entries
2104 The magic value (bfd_vma) -1 indicates that an offset has not be
2106 bfd_vma tlsdesc_got_jump_table_offset
;
2109 struct elf_aarch64_obj_tdata
2111 struct elf_obj_tdata root
;
2113 /* local symbol descriptors */
2114 struct elf_aarch64_local_symbol
*locals
;
2116 /* Zero to warn when linking objects with incompatible enum sizes. */
2117 int no_enum_size_warning
;
2119 /* Zero to warn when linking objects with incompatible wchar_t sizes. */
2120 int no_wchar_size_warning
;
2123 #define elf_aarch64_tdata(bfd) \
2124 ((struct elf_aarch64_obj_tdata *) (bfd)->tdata.any)
2126 #define elf_aarch64_locals(bfd) (elf_aarch64_tdata (bfd)->locals)
2128 #define is_aarch64_elf(bfd) \
2129 (bfd_get_flavour (bfd) == bfd_target_elf_flavour \
2130 && elf_tdata (bfd) != NULL \
2131 && elf_object_id (bfd) == AARCH64_ELF_DATA)
2134 elfNN_aarch64_mkobject (bfd
*abfd
)
2136 return bfd_elf_allocate_object (abfd
, sizeof (struct elf_aarch64_obj_tdata
),
2140 #define elf_aarch64_hash_entry(ent) \
2141 ((struct elf_aarch64_link_hash_entry *)(ent))
2143 #define GOT_UNKNOWN 0
2144 #define GOT_NORMAL 1
2145 #define GOT_TLS_GD 2
2146 #define GOT_TLS_IE 4
2147 #define GOT_TLSDESC_GD 8
2149 #define GOT_TLS_GD_ANY_P(type) ((type & GOT_TLS_GD) || (type & GOT_TLSDESC_GD))
2151 /* AArch64 ELF linker hash entry. */
2152 struct elf_aarch64_link_hash_entry
2154 struct elf_link_hash_entry root
;
2156 /* Track dynamic relocs copied for this symbol. */
2157 struct elf_dyn_relocs
*dyn_relocs
;
2159 /* Since PLT entries have variable size, we need to record the
2160 index into .got.plt instead of recomputing it from the PLT
2162 bfd_signed_vma plt_got_offset
;
2164 /* Bit mask representing the type of GOT entry(s) if any required by
2166 unsigned int got_type
;
2168 /* A pointer to the most recently used stub hash entry against this
2170 struct elf_aarch64_stub_hash_entry
*stub_cache
;
2172 /* Offset of the GOTPLT entry reserved for the TLS descriptor. The offset
2173 is from the end of the jump table and reserved entries within the PLTGOT.
2175 The magic value (bfd_vma) -1 indicates that an offset has not
2177 bfd_vma tlsdesc_got_jump_table_offset
;
2181 elfNN_aarch64_symbol_got_type (struct elf_link_hash_entry
*h
,
2183 unsigned long r_symndx
)
2186 return elf_aarch64_hash_entry (h
)->got_type
;
2188 if (! elf_aarch64_locals (abfd
))
2191 return elf_aarch64_locals (abfd
)[r_symndx
].got_type
;
2194 /* Get the AArch64 elf linker hash table from a link_info structure. */
2195 #define elf_aarch64_hash_table(info) \
2196 ((struct elf_aarch64_link_hash_table *) ((info)->hash))
2198 #define aarch64_stub_hash_lookup(table, string, create, copy) \
2199 ((struct elf_aarch64_stub_hash_entry *) \
2200 bfd_hash_lookup ((table), (string), (create), (copy)))
2202 /* AArch64 ELF linker hash table. */
2203 struct elf_aarch64_link_hash_table
2205 /* The main hash table. */
2206 struct elf_link_hash_table root
;
2208 /* Nonzero to force PIC branch veneers. */
2211 /* Fix erratum 835769. */
2212 int fix_erratum_835769
;
2214 /* Fix erratum 843419. */
2215 int fix_erratum_843419
;
2217 /* Enable ADRP->ADR rewrite for erratum 843419 workaround. */
2218 int fix_erratum_843419_adr
;
2220 /* The number of bytes in the initial entry in the PLT. */
2221 bfd_size_type plt_header_size
;
2223 /* The number of bytes in the subsequent PLT etries. */
2224 bfd_size_type plt_entry_size
;
2226 /* Short-cuts to get to dynamic linker sections. */
2230 /* Small local sym cache. */
2231 struct sym_cache sym_cache
;
2233 /* For convenience in allocate_dynrelocs. */
2236 /* The amount of space used by the reserved portion of the sgotplt
2237 section, plus whatever space is used by the jump slots. */
2238 bfd_vma sgotplt_jump_table_size
;
2240 /* The stub hash table. */
2241 struct bfd_hash_table stub_hash_table
;
2243 /* Linker stub bfd. */
2246 /* Linker call-backs. */
2247 asection
*(*add_stub_section
) (const char *, asection
*);
2248 void (*layout_sections_again
) (void);
2250 /* Array to keep track of which stub sections have been created, and
2251 information on stub grouping. */
2254 /* This is the section to which stubs in the group will be
2257 /* The stub section. */
2261 /* Assorted information used by elfNN_aarch64_size_stubs. */
2262 unsigned int bfd_count
;
2263 unsigned int top_index
;
2264 asection
**input_list
;
2266 /* The offset into splt of the PLT entry for the TLS descriptor
2267 resolver. Special values are 0, if not necessary (or not found
2268 to be necessary yet), and -1 if needed but not determined
2270 bfd_vma tlsdesc_plt
;
2272 /* The GOT offset for the lazy trampoline. Communicated to the
2273 loader via DT_TLSDESC_GOT. The magic value (bfd_vma) -1
2274 indicates an offset is not allocated. */
2275 bfd_vma dt_tlsdesc_got
;
2277 /* Used by local STT_GNU_IFUNC symbols. */
2278 htab_t loc_hash_table
;
2279 void * loc_hash_memory
;
2282 /* Create an entry in an AArch64 ELF linker hash table. */
2284 static struct bfd_hash_entry
*
2285 elfNN_aarch64_link_hash_newfunc (struct bfd_hash_entry
*entry
,
2286 struct bfd_hash_table
*table
,
2289 struct elf_aarch64_link_hash_entry
*ret
=
2290 (struct elf_aarch64_link_hash_entry
*) entry
;
2292 /* Allocate the structure if it has not already been allocated by a
2295 ret
= bfd_hash_allocate (table
,
2296 sizeof (struct elf_aarch64_link_hash_entry
));
2298 return (struct bfd_hash_entry
*) ret
;
2300 /* Call the allocation method of the superclass. */
2301 ret
= ((struct elf_aarch64_link_hash_entry
*)
2302 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry
*) ret
,
2306 ret
->dyn_relocs
= NULL
;
2307 ret
->got_type
= GOT_UNKNOWN
;
2308 ret
->plt_got_offset
= (bfd_vma
) - 1;
2309 ret
->stub_cache
= NULL
;
2310 ret
->tlsdesc_got_jump_table_offset
= (bfd_vma
) - 1;
2313 return (struct bfd_hash_entry
*) ret
;
2316 /* Initialize an entry in the stub hash table. */
2318 static struct bfd_hash_entry
*
2319 stub_hash_newfunc (struct bfd_hash_entry
*entry
,
2320 struct bfd_hash_table
*table
, const char *string
)
2322 /* Allocate the structure if it has not already been allocated by a
2326 entry
= bfd_hash_allocate (table
,
2328 elf_aarch64_stub_hash_entry
));
2333 /* Call the allocation method of the superclass. */
2334 entry
= bfd_hash_newfunc (entry
, table
, string
);
2337 struct elf_aarch64_stub_hash_entry
*eh
;
2339 /* Initialize the local fields. */
2340 eh
= (struct elf_aarch64_stub_hash_entry
*) entry
;
2341 eh
->adrp_offset
= 0;
2342 eh
->stub_sec
= NULL
;
2343 eh
->stub_offset
= 0;
2344 eh
->target_value
= 0;
2345 eh
->target_section
= NULL
;
2346 eh
->stub_type
= aarch64_stub_none
;
2354 /* Compute a hash of a local hash entry. We use elf_link_hash_entry
2355 for local symbol so that we can handle local STT_GNU_IFUNC symbols
2356 as global symbol. We reuse indx and dynstr_index for local symbol
2357 hash since they aren't used by global symbols in this backend. */
2360 elfNN_aarch64_local_htab_hash (const void *ptr
)
2362 struct elf_link_hash_entry
*h
2363 = (struct elf_link_hash_entry
*) ptr
;
2364 return ELF_LOCAL_SYMBOL_HASH (h
->indx
, h
->dynstr_index
);
2367 /* Compare local hash entries. */
2370 elfNN_aarch64_local_htab_eq (const void *ptr1
, const void *ptr2
)
2372 struct elf_link_hash_entry
*h1
2373 = (struct elf_link_hash_entry
*) ptr1
;
2374 struct elf_link_hash_entry
*h2
2375 = (struct elf_link_hash_entry
*) ptr2
;
2377 return h1
->indx
== h2
->indx
&& h1
->dynstr_index
== h2
->dynstr_index
;
2380 /* Find and/or create a hash entry for local symbol. */
2382 static struct elf_link_hash_entry
*
2383 elfNN_aarch64_get_local_sym_hash (struct elf_aarch64_link_hash_table
*htab
,
2384 bfd
*abfd
, const Elf_Internal_Rela
*rel
,
2387 struct elf_aarch64_link_hash_entry e
, *ret
;
2388 asection
*sec
= abfd
->sections
;
2389 hashval_t h
= ELF_LOCAL_SYMBOL_HASH (sec
->id
,
2390 ELFNN_R_SYM (rel
->r_info
));
2393 e
.root
.indx
= sec
->id
;
2394 e
.root
.dynstr_index
= ELFNN_R_SYM (rel
->r_info
);
2395 slot
= htab_find_slot_with_hash (htab
->loc_hash_table
, &e
, h
,
2396 create
? INSERT
: NO_INSERT
);
2403 ret
= (struct elf_aarch64_link_hash_entry
*) *slot
;
2407 ret
= (struct elf_aarch64_link_hash_entry
*)
2408 objalloc_alloc ((struct objalloc
*) htab
->loc_hash_memory
,
2409 sizeof (struct elf_aarch64_link_hash_entry
));
2412 memset (ret
, 0, sizeof (*ret
));
2413 ret
->root
.indx
= sec
->id
;
2414 ret
->root
.dynstr_index
= ELFNN_R_SYM (rel
->r_info
);
2415 ret
->root
.dynindx
= -1;
2421 /* Copy the extra info we tack onto an elf_link_hash_entry. */
2424 elfNN_aarch64_copy_indirect_symbol (struct bfd_link_info
*info
,
2425 struct elf_link_hash_entry
*dir
,
2426 struct elf_link_hash_entry
*ind
)
2428 struct elf_aarch64_link_hash_entry
*edir
, *eind
;
2430 edir
= (struct elf_aarch64_link_hash_entry
*) dir
;
2431 eind
= (struct elf_aarch64_link_hash_entry
*) ind
;
2433 if (eind
->dyn_relocs
!= NULL
)
2435 if (edir
->dyn_relocs
!= NULL
)
2437 struct elf_dyn_relocs
**pp
;
2438 struct elf_dyn_relocs
*p
;
2440 /* Add reloc counts against the indirect sym to the direct sym
2441 list. Merge any entries against the same section. */
2442 for (pp
= &eind
->dyn_relocs
; (p
= *pp
) != NULL
;)
2444 struct elf_dyn_relocs
*q
;
2446 for (q
= edir
->dyn_relocs
; q
!= NULL
; q
= q
->next
)
2447 if (q
->sec
== p
->sec
)
2449 q
->pc_count
+= p
->pc_count
;
2450 q
->count
+= p
->count
;
2457 *pp
= edir
->dyn_relocs
;
2460 edir
->dyn_relocs
= eind
->dyn_relocs
;
2461 eind
->dyn_relocs
= NULL
;
2464 if (ind
->root
.type
== bfd_link_hash_indirect
)
2466 /* Copy over PLT info. */
2467 if (dir
->got
.refcount
<= 0)
2469 edir
->got_type
= eind
->got_type
;
2470 eind
->got_type
= GOT_UNKNOWN
;
2474 _bfd_elf_link_hash_copy_indirect (info
, dir
, ind
);
2477 /* Destroy an AArch64 elf linker hash table. */
2480 elfNN_aarch64_link_hash_table_free (bfd
*obfd
)
2482 struct elf_aarch64_link_hash_table
*ret
2483 = (struct elf_aarch64_link_hash_table
*) obfd
->link
.hash
;
2485 if (ret
->loc_hash_table
)
2486 htab_delete (ret
->loc_hash_table
);
2487 if (ret
->loc_hash_memory
)
2488 objalloc_free ((struct objalloc
*) ret
->loc_hash_memory
);
2490 bfd_hash_table_free (&ret
->stub_hash_table
);
2491 _bfd_elf_link_hash_table_free (obfd
);
2494 /* Create an AArch64 elf linker hash table. */
2496 static struct bfd_link_hash_table
*
2497 elfNN_aarch64_link_hash_table_create (bfd
*abfd
)
2499 struct elf_aarch64_link_hash_table
*ret
;
2500 bfd_size_type amt
= sizeof (struct elf_aarch64_link_hash_table
);
2502 ret
= bfd_zmalloc (amt
);
2506 if (!_bfd_elf_link_hash_table_init
2507 (&ret
->root
, abfd
, elfNN_aarch64_link_hash_newfunc
,
2508 sizeof (struct elf_aarch64_link_hash_entry
), AARCH64_ELF_DATA
))
2514 ret
->plt_header_size
= PLT_ENTRY_SIZE
;
2515 ret
->plt_entry_size
= PLT_SMALL_ENTRY_SIZE
;
2517 ret
->dt_tlsdesc_got
= (bfd_vma
) - 1;
2519 if (!bfd_hash_table_init (&ret
->stub_hash_table
, stub_hash_newfunc
,
2520 sizeof (struct elf_aarch64_stub_hash_entry
)))
2522 _bfd_elf_link_hash_table_free (abfd
);
2526 ret
->loc_hash_table
= htab_try_create (1024,
2527 elfNN_aarch64_local_htab_hash
,
2528 elfNN_aarch64_local_htab_eq
,
2530 ret
->loc_hash_memory
= objalloc_create ();
2531 if (!ret
->loc_hash_table
|| !ret
->loc_hash_memory
)
2533 elfNN_aarch64_link_hash_table_free (abfd
);
2536 ret
->root
.root
.hash_table_free
= elfNN_aarch64_link_hash_table_free
;
2538 return &ret
->root
.root
;
2542 aarch64_relocate (unsigned int r_type
, bfd
*input_bfd
, asection
*input_section
,
2543 bfd_vma offset
, bfd_vma value
)
2545 reloc_howto_type
*howto
;
2548 howto
= elfNN_aarch64_howto_from_type (r_type
);
2549 place
= (input_section
->output_section
->vma
+ input_section
->output_offset
2552 r_type
= elfNN_aarch64_bfd_reloc_from_type (r_type
);
2553 value
= _bfd_aarch64_elf_resolve_relocation (r_type
, place
, value
, 0, FALSE
);
2554 return _bfd_aarch64_elf_put_addend (input_bfd
,
2555 input_section
->contents
+ offset
, r_type
,
2559 static enum elf_aarch64_stub_type
2560 aarch64_select_branch_stub (bfd_vma value
, bfd_vma place
)
2562 if (aarch64_valid_for_adrp_p (value
, place
))
2563 return aarch64_stub_adrp_branch
;
2564 return aarch64_stub_long_branch
;
2567 /* Determine the type of stub needed, if any, for a call. */
2569 static enum elf_aarch64_stub_type
2570 aarch64_type_of_stub (struct bfd_link_info
*info
,
2571 asection
*input_sec
,
2572 const Elf_Internal_Rela
*rel
,
2574 unsigned char st_type
,
2575 struct elf_aarch64_link_hash_entry
*hash
,
2576 bfd_vma destination
)
2579 bfd_signed_vma branch_offset
;
2580 unsigned int r_type
;
2581 struct elf_aarch64_link_hash_table
*globals
;
2582 enum elf_aarch64_stub_type stub_type
= aarch64_stub_none
;
2583 bfd_boolean via_plt_p
;
2585 if (st_type
!= STT_FUNC
2586 && (sym_sec
!= bfd_abs_section_ptr
))
2589 globals
= elf_aarch64_hash_table (info
);
2590 via_plt_p
= (globals
->root
.splt
!= NULL
&& hash
!= NULL
2591 && hash
->root
.plt
.offset
!= (bfd_vma
) - 1);
2592 /* Make sure call to plt stub can fit into the branch range. */
2594 destination
= (globals
->root
.splt
->output_section
->vma
2595 + globals
->root
.splt
->output_offset
2596 + hash
->root
.plt
.offset
);
2598 /* Determine where the call point is. */
2599 location
= (input_sec
->output_offset
2600 + input_sec
->output_section
->vma
+ rel
->r_offset
);
2602 branch_offset
= (bfd_signed_vma
) (destination
- location
);
2604 r_type
= ELFNN_R_TYPE (rel
->r_info
);
2606 /* We don't want to redirect any old unconditional jump in this way,
2607 only one which is being used for a sibcall, where it is
2608 acceptable for the IP0 and IP1 registers to be clobbered. */
2609 if ((r_type
== AARCH64_R (CALL26
) || r_type
== AARCH64_R (JUMP26
))
2610 && (branch_offset
> AARCH64_MAX_FWD_BRANCH_OFFSET
2611 || branch_offset
< AARCH64_MAX_BWD_BRANCH_OFFSET
))
2613 stub_type
= aarch64_stub_long_branch
;
2619 /* Build a name for an entry in the stub hash table. */
2622 elfNN_aarch64_stub_name (const asection
*input_section
,
2623 const asection
*sym_sec
,
2624 const struct elf_aarch64_link_hash_entry
*hash
,
2625 const Elf_Internal_Rela
*rel
)
2632 len
= 8 + 1 + strlen (hash
->root
.root
.root
.string
) + 1 + 16 + 1;
2633 stub_name
= bfd_malloc (len
);
2634 if (stub_name
!= NULL
)
2635 snprintf (stub_name
, len
, "%08x_%s+%" BFD_VMA_FMT
"x",
2636 (unsigned int) input_section
->id
,
2637 hash
->root
.root
.root
.string
,
2642 len
= 8 + 1 + 8 + 1 + 8 + 1 + 16 + 1;
2643 stub_name
= bfd_malloc (len
);
2644 if (stub_name
!= NULL
)
2645 snprintf (stub_name
, len
, "%08x_%x:%x+%" BFD_VMA_FMT
"x",
2646 (unsigned int) input_section
->id
,
2647 (unsigned int) sym_sec
->id
,
2648 (unsigned int) ELFNN_R_SYM (rel
->r_info
),
2655 /* Look up an entry in the stub hash. Stub entries are cached because
2656 creating the stub name takes a bit of time. */
2658 static struct elf_aarch64_stub_hash_entry
*
2659 elfNN_aarch64_get_stub_entry (const asection
*input_section
,
2660 const asection
*sym_sec
,
2661 struct elf_link_hash_entry
*hash
,
2662 const Elf_Internal_Rela
*rel
,
2663 struct elf_aarch64_link_hash_table
*htab
)
2665 struct elf_aarch64_stub_hash_entry
*stub_entry
;
2666 struct elf_aarch64_link_hash_entry
*h
=
2667 (struct elf_aarch64_link_hash_entry
*) hash
;
2668 const asection
*id_sec
;
2670 if ((input_section
->flags
& SEC_CODE
) == 0)
2673 /* If this input section is part of a group of sections sharing one
2674 stub section, then use the id of the first section in the group.
2675 Stub names need to include a section id, as there may well be
2676 more than one stub used to reach say, printf, and we need to
2677 distinguish between them. */
2678 id_sec
= htab
->stub_group
[input_section
->id
].link_sec
;
2680 if (h
!= NULL
&& h
->stub_cache
!= NULL
2681 && h
->stub_cache
->h
== h
&& h
->stub_cache
->id_sec
== id_sec
)
2683 stub_entry
= h
->stub_cache
;
2689 stub_name
= elfNN_aarch64_stub_name (id_sec
, sym_sec
, h
, rel
);
2690 if (stub_name
== NULL
)
2693 stub_entry
= aarch64_stub_hash_lookup (&htab
->stub_hash_table
,
2694 stub_name
, FALSE
, FALSE
);
2696 h
->stub_cache
= stub_entry
;
2705 /* Create a stub section. */
2708 _bfd_aarch64_create_stub_section (asection
*section
,
2709 struct elf_aarch64_link_hash_table
*htab
)
2715 namelen
= strlen (section
->name
);
2716 len
= namelen
+ sizeof (STUB_SUFFIX
);
2717 s_name
= bfd_alloc (htab
->stub_bfd
, len
);
2721 memcpy (s_name
, section
->name
, namelen
);
2722 memcpy (s_name
+ namelen
, STUB_SUFFIX
, sizeof (STUB_SUFFIX
));
2723 return (*htab
->add_stub_section
) (s_name
, section
);
2727 /* Find or create a stub section for a link section.
2729 Fix or create the stub section used to collect stubs attached to
2730 the specified link section. */
2733 _bfd_aarch64_get_stub_for_link_section (asection
*link_section
,
2734 struct elf_aarch64_link_hash_table
*htab
)
2736 if (htab
->stub_group
[link_section
->id
].stub_sec
== NULL
)
2737 htab
->stub_group
[link_section
->id
].stub_sec
2738 = _bfd_aarch64_create_stub_section (link_section
, htab
);
2739 return htab
->stub_group
[link_section
->id
].stub_sec
;
2743 /* Find or create a stub section in the stub group for an input
2747 _bfd_aarch64_create_or_find_stub_sec (asection
*section
,
2748 struct elf_aarch64_link_hash_table
*htab
)
2750 asection
*link_sec
= htab
->stub_group
[section
->id
].link_sec
;
2751 return _bfd_aarch64_get_stub_for_link_section (link_sec
, htab
);
2755 /* Add a new stub entry in the stub group associated with an input
2756 section to the stub hash. Not all fields of the new stub entry are
2759 static struct elf_aarch64_stub_hash_entry
*
2760 _bfd_aarch64_add_stub_entry_in_group (const char *stub_name
,
2762 struct elf_aarch64_link_hash_table
*htab
)
2766 struct elf_aarch64_stub_hash_entry
*stub_entry
;
2768 link_sec
= htab
->stub_group
[section
->id
].link_sec
;
2769 stub_sec
= _bfd_aarch64_create_or_find_stub_sec (section
, htab
);
2771 /* Enter this entry into the linker stub hash table. */
2772 stub_entry
= aarch64_stub_hash_lookup (&htab
->stub_hash_table
, stub_name
,
2774 if (stub_entry
== NULL
)
2776 (*_bfd_error_handler
) (_("%s: cannot create stub entry %s"),
2777 section
->owner
, stub_name
);
2781 stub_entry
->stub_sec
= stub_sec
;
2782 stub_entry
->stub_offset
= 0;
2783 stub_entry
->id_sec
= link_sec
;
2788 /* Add a new stub entry in the final stub section to the stub hash.
2789 Not all fields of the new stub entry are initialised. */
2791 static struct elf_aarch64_stub_hash_entry
*
2792 _bfd_aarch64_add_stub_entry_after (const char *stub_name
,
2793 asection
*link_section
,
2794 struct elf_aarch64_link_hash_table
*htab
)
2797 struct elf_aarch64_stub_hash_entry
*stub_entry
;
2799 stub_sec
= _bfd_aarch64_get_stub_for_link_section (link_section
, htab
);
2800 stub_entry
= aarch64_stub_hash_lookup (&htab
->stub_hash_table
, stub_name
,
2802 if (stub_entry
== NULL
)
2804 (*_bfd_error_handler
) (_("cannot create stub entry %s"), stub_name
);
2808 stub_entry
->stub_sec
= stub_sec
;
2809 stub_entry
->stub_offset
= 0;
2810 stub_entry
->id_sec
= link_section
;
2817 aarch64_build_one_stub (struct bfd_hash_entry
*gen_entry
,
2818 void *in_arg ATTRIBUTE_UNUSED
)
2820 struct elf_aarch64_stub_hash_entry
*stub_entry
;
2825 bfd_vma veneered_insn_loc
;
2826 bfd_vma veneer_entry_loc
;
2827 bfd_signed_vma branch_offset
= 0;
2828 unsigned int template_size
;
2829 const uint32_t *template;
2832 /* Massage our args to the form they really have. */
2833 stub_entry
= (struct elf_aarch64_stub_hash_entry
*) gen_entry
;
2835 stub_sec
= stub_entry
->stub_sec
;
2837 /* Make a note of the offset within the stubs for this entry. */
2838 stub_entry
->stub_offset
= stub_sec
->size
;
2839 loc
= stub_sec
->contents
+ stub_entry
->stub_offset
;
2841 stub_bfd
= stub_sec
->owner
;
2843 /* This is the address of the stub destination. */
2844 sym_value
= (stub_entry
->target_value
2845 + stub_entry
->target_section
->output_offset
2846 + stub_entry
->target_section
->output_section
->vma
);
2848 if (stub_entry
->stub_type
== aarch64_stub_long_branch
)
2850 bfd_vma place
= (stub_entry
->stub_offset
+ stub_sec
->output_section
->vma
2851 + stub_sec
->output_offset
);
2853 /* See if we can relax the stub. */
2854 if (aarch64_valid_for_adrp_p (sym_value
, place
))
2855 stub_entry
->stub_type
= aarch64_select_branch_stub (sym_value
, place
);
2858 switch (stub_entry
->stub_type
)
2860 case aarch64_stub_adrp_branch
:
2861 template = aarch64_adrp_branch_stub
;
2862 template_size
= sizeof (aarch64_adrp_branch_stub
);
2864 case aarch64_stub_long_branch
:
2865 template = aarch64_long_branch_stub
;
2866 template_size
= sizeof (aarch64_long_branch_stub
);
2868 case aarch64_stub_erratum_835769_veneer
:
2869 template = aarch64_erratum_835769_stub
;
2870 template_size
= sizeof (aarch64_erratum_835769_stub
);
2872 case aarch64_stub_erratum_843419_veneer
:
2873 template = aarch64_erratum_843419_stub
;
2874 template_size
= sizeof (aarch64_erratum_843419_stub
);
2880 for (i
= 0; i
< (template_size
/ sizeof template[0]); i
++)
2882 bfd_putl32 (template[i
], loc
);
2886 template_size
= (template_size
+ 7) & ~7;
2887 stub_sec
->size
+= template_size
;
2889 switch (stub_entry
->stub_type
)
2891 case aarch64_stub_adrp_branch
:
2892 if (aarch64_relocate (AARCH64_R (ADR_PREL_PG_HI21
), stub_bfd
, stub_sec
,
2893 stub_entry
->stub_offset
, sym_value
))
2894 /* The stub would not have been relaxed if the offset was out
2898 if (aarch64_relocate (AARCH64_R (ADD_ABS_LO12_NC
), stub_bfd
, stub_sec
,
2899 stub_entry
->stub_offset
+ 4, sym_value
))
2903 case aarch64_stub_long_branch
:
2904 /* We want the value relative to the address 12 bytes back from the
2906 if (aarch64_relocate (AARCH64_R (PRELNN
), stub_bfd
, stub_sec
,
2907 stub_entry
->stub_offset
+ 16, sym_value
+ 12))
2911 case aarch64_stub_erratum_835769_veneer
:
2912 veneered_insn_loc
= stub_entry
->target_section
->output_section
->vma
2913 + stub_entry
->target_section
->output_offset
2914 + stub_entry
->target_value
;
2915 veneer_entry_loc
= stub_entry
->stub_sec
->output_section
->vma
2916 + stub_entry
->stub_sec
->output_offset
2917 + stub_entry
->stub_offset
;
2918 branch_offset
= veneered_insn_loc
- veneer_entry_loc
;
2919 branch_offset
>>= 2;
2920 branch_offset
&= 0x3ffffff;
2921 bfd_putl32 (stub_entry
->veneered_insn
,
2922 stub_sec
->contents
+ stub_entry
->stub_offset
);
2923 bfd_putl32 (template[1] | branch_offset
,
2924 stub_sec
->contents
+ stub_entry
->stub_offset
+ 4);
2927 case aarch64_stub_erratum_843419_veneer
:
2928 if (aarch64_relocate (AARCH64_R (JUMP26
), stub_bfd
, stub_sec
,
2929 stub_entry
->stub_offset
+ 4, sym_value
+ 4))
2940 /* As above, but don't actually build the stub. Just bump offset so
2941 we know stub section sizes. */
2944 aarch64_size_one_stub (struct bfd_hash_entry
*gen_entry
,
2945 void *in_arg ATTRIBUTE_UNUSED
)
2947 struct elf_aarch64_stub_hash_entry
*stub_entry
;
2950 /* Massage our args to the form they really have. */
2951 stub_entry
= (struct elf_aarch64_stub_hash_entry
*) gen_entry
;
2953 switch (stub_entry
->stub_type
)
2955 case aarch64_stub_adrp_branch
:
2956 size
= sizeof (aarch64_adrp_branch_stub
);
2958 case aarch64_stub_long_branch
:
2959 size
= sizeof (aarch64_long_branch_stub
);
2961 case aarch64_stub_erratum_835769_veneer
:
2962 size
= sizeof (aarch64_erratum_835769_stub
);
2964 case aarch64_stub_erratum_843419_veneer
:
2965 size
= sizeof (aarch64_erratum_843419_stub
);
2971 size
= (size
+ 7) & ~7;
2972 stub_entry
->stub_sec
->size
+= size
;
2976 /* External entry points for sizing and building linker stubs. */
2978 /* Set up various things so that we can make a list of input sections
2979 for each output section included in the link. Returns -1 on error,
2980 0 when no stubs will be needed, and 1 on success. */
2983 elfNN_aarch64_setup_section_lists (bfd
*output_bfd
,
2984 struct bfd_link_info
*info
)
2987 unsigned int bfd_count
;
2988 unsigned int top_id
, top_index
;
2990 asection
**input_list
, **list
;
2992 struct elf_aarch64_link_hash_table
*htab
=
2993 elf_aarch64_hash_table (info
);
2995 if (!is_elf_hash_table (htab
))
2998 /* Count the number of input BFDs and find the top input section id. */
2999 for (input_bfd
= info
->input_bfds
, bfd_count
= 0, top_id
= 0;
3000 input_bfd
!= NULL
; input_bfd
= input_bfd
->link
.next
)
3003 for (section
= input_bfd
->sections
;
3004 section
!= NULL
; section
= section
->next
)
3006 if (top_id
< section
->id
)
3007 top_id
= section
->id
;
3010 htab
->bfd_count
= bfd_count
;
3012 amt
= sizeof (struct map_stub
) * (top_id
+ 1);
3013 htab
->stub_group
= bfd_zmalloc (amt
);
3014 if (htab
->stub_group
== NULL
)
3017 /* We can't use output_bfd->section_count here to find the top output
3018 section index as some sections may have been removed, and
3019 _bfd_strip_section_from_output doesn't renumber the indices. */
3020 for (section
= output_bfd
->sections
, top_index
= 0;
3021 section
!= NULL
; section
= section
->next
)
3023 if (top_index
< section
->index
)
3024 top_index
= section
->index
;
3027 htab
->top_index
= top_index
;
3028 amt
= sizeof (asection
*) * (top_index
+ 1);
3029 input_list
= bfd_malloc (amt
);
3030 htab
->input_list
= input_list
;
3031 if (input_list
== NULL
)
3034 /* For sections we aren't interested in, mark their entries with a
3035 value we can check later. */
3036 list
= input_list
+ top_index
;
3038 *list
= bfd_abs_section_ptr
;
3039 while (list
-- != input_list
);
3041 for (section
= output_bfd
->sections
;
3042 section
!= NULL
; section
= section
->next
)
3044 if ((section
->flags
& SEC_CODE
) != 0)
3045 input_list
[section
->index
] = NULL
;
3051 /* Used by elfNN_aarch64_next_input_section and group_sections. */
3052 #define PREV_SEC(sec) (htab->stub_group[(sec)->id].link_sec)
3054 /* The linker repeatedly calls this function for each input section,
3055 in the order that input sections are linked into output sections.
3056 Build lists of input sections to determine groupings between which
3057 we may insert linker stubs. */
3060 elfNN_aarch64_next_input_section (struct bfd_link_info
*info
, asection
*isec
)
3062 struct elf_aarch64_link_hash_table
*htab
=
3063 elf_aarch64_hash_table (info
);
3065 if (isec
->output_section
->index
<= htab
->top_index
)
3067 asection
**list
= htab
->input_list
+ isec
->output_section
->index
;
3069 if (*list
!= bfd_abs_section_ptr
)
3071 /* Steal the link_sec pointer for our list. */
3072 /* This happens to make the list in reverse order,
3073 which is what we want. */
3074 PREV_SEC (isec
) = *list
;
3080 /* See whether we can group stub sections together. Grouping stub
3081 sections may result in fewer stubs. More importantly, we need to
3082 put all .init* and .fini* stubs at the beginning of the .init or
3083 .fini output sections respectively, because glibc splits the
3084 _init and _fini functions into multiple parts. Putting a stub in
3085 the middle of a function is not a good idea. */
3088 group_sections (struct elf_aarch64_link_hash_table
*htab
,
3089 bfd_size_type stub_group_size
,
3090 bfd_boolean stubs_always_before_branch
)
3092 asection
**list
= htab
->input_list
+ htab
->top_index
;
3096 asection
*tail
= *list
;
3098 if (tail
== bfd_abs_section_ptr
)
3101 while (tail
!= NULL
)
3105 bfd_size_type total
;
3109 while ((prev
= PREV_SEC (curr
)) != NULL
3110 && ((total
+= curr
->output_offset
- prev
->output_offset
)
3114 /* OK, the size from the start of CURR to the end is less
3115 than stub_group_size and thus can be handled by one stub
3116 section. (Or the tail section is itself larger than
3117 stub_group_size, in which case we may be toast.)
3118 We should really be keeping track of the total size of
3119 stubs added here, as stubs contribute to the final output
3123 prev
= PREV_SEC (tail
);
3124 /* Set up this stub group. */
3125 htab
->stub_group
[tail
->id
].link_sec
= curr
;
3127 while (tail
!= curr
&& (tail
= prev
) != NULL
);
3129 /* But wait, there's more! Input sections up to stub_group_size
3130 bytes before the stub section can be handled by it too. */
3131 if (!stubs_always_before_branch
)
3135 && ((total
+= tail
->output_offset
- prev
->output_offset
)
3139 prev
= PREV_SEC (tail
);
3140 htab
->stub_group
[tail
->id
].link_sec
= curr
;
3146 while (list
-- != htab
->input_list
);
3148 free (htab
->input_list
);
3153 #define AARCH64_BITS(x, pos, n) (((x) >> (pos)) & ((1 << (n)) - 1))
3155 #define AARCH64_RT(insn) AARCH64_BITS (insn, 0, 5)
3156 #define AARCH64_RT2(insn) AARCH64_BITS (insn, 10, 5)
3157 #define AARCH64_RA(insn) AARCH64_BITS (insn, 10, 5)
3158 #define AARCH64_RD(insn) AARCH64_BITS (insn, 0, 5)
3159 #define AARCH64_RN(insn) AARCH64_BITS (insn, 5, 5)
3160 #define AARCH64_RM(insn) AARCH64_BITS (insn, 16, 5)
3162 #define AARCH64_MAC(insn) (((insn) & 0xff000000) == 0x9b000000)
3163 #define AARCH64_BIT(insn, n) AARCH64_BITS (insn, n, 1)
3164 #define AARCH64_OP31(insn) AARCH64_BITS (insn, 21, 3)
3165 #define AARCH64_ZR 0x1f
3167 /* All ld/st ops. See C4-182 of the ARM ARM. The encoding space for
3168 LD_PCREL, LDST_RO, LDST_UI and LDST_UIMM cover prefetch ops. */
3170 #define AARCH64_LD(insn) (AARCH64_BIT (insn, 22) == 1)
3171 #define AARCH64_LDST(insn) (((insn) & 0x0a000000) == 0x08000000)
3172 #define AARCH64_LDST_EX(insn) (((insn) & 0x3f000000) == 0x08000000)
3173 #define AARCH64_LDST_PCREL(insn) (((insn) & 0x3b000000) == 0x18000000)
3174 #define AARCH64_LDST_NAP(insn) (((insn) & 0x3b800000) == 0x28000000)
3175 #define AARCH64_LDSTP_PI(insn) (((insn) & 0x3b800000) == 0x28800000)
3176 #define AARCH64_LDSTP_O(insn) (((insn) & 0x3b800000) == 0x29000000)
3177 #define AARCH64_LDSTP_PRE(insn) (((insn) & 0x3b800000) == 0x29800000)
3178 #define AARCH64_LDST_UI(insn) (((insn) & 0x3b200c00) == 0x38000000)
3179 #define AARCH64_LDST_PIIMM(insn) (((insn) & 0x3b200c00) == 0x38000400)
3180 #define AARCH64_LDST_U(insn) (((insn) & 0x3b200c00) == 0x38000800)
3181 #define AARCH64_LDST_PREIMM(insn) (((insn) & 0x3b200c00) == 0x38000c00)
3182 #define AARCH64_LDST_RO(insn) (((insn) & 0x3b200c00) == 0x38200800)
3183 #define AARCH64_LDST_UIMM(insn) (((insn) & 0x3b000000) == 0x39000000)
3184 #define AARCH64_LDST_SIMD_M(insn) (((insn) & 0xbfbf0000) == 0x0c000000)
3185 #define AARCH64_LDST_SIMD_M_PI(insn) (((insn) & 0xbfa00000) == 0x0c800000)
3186 #define AARCH64_LDST_SIMD_S(insn) (((insn) & 0xbf9f0000) == 0x0d000000)
3187 #define AARCH64_LDST_SIMD_S_PI(insn) (((insn) & 0xbf800000) == 0x0d800000)
3189 /* Classify an INSN if it is indeed a load/store.
3191 Return TRUE if INSN is a LD/ST instruction otherwise return FALSE.
3193 For scalar LD/ST instructions PAIR is FALSE, RT is returned and RT2
3196 For LD/ST pair instructions PAIR is TRUE, RT and RT2 are returned.
3201 aarch64_mem_op_p (uint32_t insn
, unsigned int *rt
, unsigned int *rt2
,
3202 bfd_boolean
*pair
, bfd_boolean
*load
)
3210 /* Bail out quickly if INSN doesn't fall into the the load-store
3212 if (!AARCH64_LDST (insn
))
3217 if (AARCH64_LDST_EX (insn
))
3219 *rt
= AARCH64_RT (insn
);
3221 if (AARCH64_BIT (insn
, 21) == 1)
3224 *rt2
= AARCH64_RT2 (insn
);
3226 *load
= AARCH64_LD (insn
);
3229 else if (AARCH64_LDST_NAP (insn
)
3230 || AARCH64_LDSTP_PI (insn
)
3231 || AARCH64_LDSTP_O (insn
)
3232 || AARCH64_LDSTP_PRE (insn
))
3235 *rt
= AARCH64_RT (insn
);
3236 *rt2
= AARCH64_RT2 (insn
);
3237 *load
= AARCH64_LD (insn
);
3240 else if (AARCH64_LDST_PCREL (insn
)
3241 || AARCH64_LDST_UI (insn
)
3242 || AARCH64_LDST_PIIMM (insn
)
3243 || AARCH64_LDST_U (insn
)
3244 || AARCH64_LDST_PREIMM (insn
)
3245 || AARCH64_LDST_RO (insn
)
3246 || AARCH64_LDST_UIMM (insn
))
3248 *rt
= AARCH64_RT (insn
);
3250 if (AARCH64_LDST_PCREL (insn
))
3252 opc
= AARCH64_BITS (insn
, 22, 2);
3253 v
= AARCH64_BIT (insn
, 26);
3254 opc_v
= opc
| (v
<< 2);
3255 *load
= (opc_v
== 1 || opc_v
== 2 || opc_v
== 3
3256 || opc_v
== 5 || opc_v
== 7);
3259 else if (AARCH64_LDST_SIMD_M (insn
)
3260 || AARCH64_LDST_SIMD_M_PI (insn
))
3262 *rt
= AARCH64_RT (insn
);
3263 *load
= AARCH64_BIT (insn
, 22);
3264 opcode
= (insn
>> 12) & 0xf;
3291 else if (AARCH64_LDST_SIMD_S (insn
)
3292 || AARCH64_LDST_SIMD_S_PI (insn
))
3294 *rt
= AARCH64_RT (insn
);
3295 r
= (insn
>> 21) & 1;
3296 *load
= AARCH64_BIT (insn
, 22);
3297 opcode
= (insn
>> 13) & 0x7;
3309 *rt2
= *rt
+ (r
== 0 ? 2 : 3);
3317 *rt2
= *rt
+ (r
== 0 ? 2 : 3);
3329 /* Return TRUE if INSN is multiply-accumulate. */
3332 aarch64_mlxl_p (uint32_t insn
)
3334 uint32_t op31
= AARCH64_OP31 (insn
);
3336 if (AARCH64_MAC (insn
)
3337 && (op31
== 0 || op31
== 1 || op31
== 5)
3338 /* Exclude MUL instructions which are encoded as a multiple accumulate
3340 && AARCH64_RA (insn
) != AARCH64_ZR
)
3346 /* Some early revisions of the Cortex-A53 have an erratum (835769) whereby
3347 it is possible for a 64-bit multiply-accumulate instruction to generate an
3348 incorrect result. The details are quite complex and hard to
3349 determine statically, since branches in the code may exist in some
3350 circumstances, but all cases end with a memory (load, store, or
3351 prefetch) instruction followed immediately by the multiply-accumulate
3352 operation. We employ a linker patching technique, by moving the potentially
3353 affected multiply-accumulate instruction into a patch region and replacing
3354 the original instruction with a branch to the patch. This function checks
3355 if INSN_1 is the memory operation followed by a multiply-accumulate
3356 operation (INSN_2). Return TRUE if an erratum sequence is found, FALSE
3357 if INSN_1 and INSN_2 are safe. */
3360 aarch64_erratum_sequence (uint32_t insn_1
, uint32_t insn_2
)
3370 if (aarch64_mlxl_p (insn_2
)
3371 && aarch64_mem_op_p (insn_1
, &rt
, &rt2
, &pair
, &load
))
3373 /* Any SIMD memory op is independent of the subsequent MLA
3374 by definition of the erratum. */
3375 if (AARCH64_BIT (insn_1
, 26))
3378 /* If not SIMD, check for integer memory ops and MLA relationship. */
3379 rn
= AARCH64_RN (insn_2
);
3380 ra
= AARCH64_RA (insn_2
);
3381 rm
= AARCH64_RM (insn_2
);
3383 /* If this is a load and there's a true(RAW) dependency, we are safe
3384 and this is not an erratum sequence. */
3386 (rt
== rn
|| rt
== rm
|| rt
== ra
3387 || (pair
&& (rt2
== rn
|| rt2
== rm
|| rt2
== ra
))))
3390 /* We conservatively put out stubs for all other cases (including
3398 /* Used to order a list of mapping symbols by address. */
3401 elf_aarch64_compare_mapping (const void *a
, const void *b
)
3403 const elf_aarch64_section_map
*amap
= (const elf_aarch64_section_map
*) a
;
3404 const elf_aarch64_section_map
*bmap
= (const elf_aarch64_section_map
*) b
;
3406 if (amap
->vma
> bmap
->vma
)
3408 else if (amap
->vma
< bmap
->vma
)
3410 else if (amap
->type
> bmap
->type
)
3411 /* Ensure results do not depend on the host qsort for objects with
3412 multiple mapping symbols at the same address by sorting on type
3415 else if (amap
->type
< bmap
->type
)
3423 _bfd_aarch64_erratum_835769_stub_name (unsigned num_fixes
)
3425 char *stub_name
= (char *) bfd_malloc
3426 (strlen ("__erratum_835769_veneer_") + 16);
3427 sprintf (stub_name
,"__erratum_835769_veneer_%d", num_fixes
);
3431 /* Scan for Cortex-A53 erratum 835769 sequence.
3433 Return TRUE else FALSE on abnormal termination. */
3436 _bfd_aarch64_erratum_835769_scan (bfd
*input_bfd
,
3437 struct bfd_link_info
*info
,
3438 unsigned int *num_fixes_p
)
3441 struct elf_aarch64_link_hash_table
*htab
= elf_aarch64_hash_table (info
);
3442 unsigned int num_fixes
= *num_fixes_p
;
3447 for (section
= input_bfd
->sections
;
3449 section
= section
->next
)
3451 bfd_byte
*contents
= NULL
;
3452 struct _aarch64_elf_section_data
*sec_data
;
3455 if (elf_section_type (section
) != SHT_PROGBITS
3456 || (elf_section_flags (section
) & SHF_EXECINSTR
) == 0
3457 || (section
->flags
& SEC_EXCLUDE
) != 0
3458 || (section
->sec_info_type
== SEC_INFO_TYPE_JUST_SYMS
)
3459 || (section
->output_section
== bfd_abs_section_ptr
))
3462 if (elf_section_data (section
)->this_hdr
.contents
!= NULL
)
3463 contents
= elf_section_data (section
)->this_hdr
.contents
;
3464 else if (! bfd_malloc_and_get_section (input_bfd
, section
, &contents
))
3467 sec_data
= elf_aarch64_section_data (section
);
3469 qsort (sec_data
->map
, sec_data
->mapcount
,
3470 sizeof (elf_aarch64_section_map
), elf_aarch64_compare_mapping
);
3472 for (span
= 0; span
< sec_data
->mapcount
; span
++)
3474 unsigned int span_start
= sec_data
->map
[span
].vma
;
3475 unsigned int span_end
= ((span
== sec_data
->mapcount
- 1)
3476 ? sec_data
->map
[0].vma
+ section
->size
3477 : sec_data
->map
[span
+ 1].vma
);
3479 char span_type
= sec_data
->map
[span
].type
;
3481 if (span_type
== 'd')
3484 for (i
= span_start
; i
+ 4 < span_end
; i
+= 4)
3486 uint32_t insn_1
= bfd_getl32 (contents
+ i
);
3487 uint32_t insn_2
= bfd_getl32 (contents
+ i
+ 4);
3489 if (aarch64_erratum_sequence (insn_1
, insn_2
))
3491 struct elf_aarch64_stub_hash_entry
*stub_entry
;
3492 char *stub_name
= _bfd_aarch64_erratum_835769_stub_name (num_fixes
);
3496 stub_entry
= _bfd_aarch64_add_stub_entry_in_group (stub_name
,
3502 stub_entry
->stub_type
= aarch64_stub_erratum_835769_veneer
;
3503 stub_entry
->target_section
= section
;
3504 stub_entry
->target_value
= i
+ 4;
3505 stub_entry
->veneered_insn
= insn_2
;
3506 stub_entry
->output_name
= stub_name
;
3511 if (elf_section_data (section
)->this_hdr
.contents
== NULL
)
3515 *num_fixes_p
= num_fixes
;
3521 /* Test if instruction INSN is ADRP. */
3524 _bfd_aarch64_adrp_p (uint32_t insn
)
3526 return ((insn
& 0x9f000000) == 0x90000000);
3530 /* Helper predicate to look for cortex-a53 erratum 843419 sequence 1. */
3533 _bfd_aarch64_erratum_843419_sequence_p (uint32_t insn_1
, uint32_t insn_2
,
3541 return (aarch64_mem_op_p (insn_2
, &rt
, &rt2
, &pair
, &load
)
3544 && AARCH64_LDST_UIMM (insn_3
)
3545 && AARCH64_RN (insn_3
) == AARCH64_RD (insn_1
));
3549 /* Test for the presence of Cortex-A53 erratum 843419 instruction sequence.
3551 Return TRUE if section CONTENTS at offset I contains one of the
3552 erratum 843419 sequences, otherwise return FALSE. If a sequence is
3553 seen set P_VENEER_I to the offset of the final LOAD/STORE
3554 instruction in the sequence.
3558 _bfd_aarch64_erratum_843419_p (bfd_byte
*contents
, bfd_vma vma
,
3559 bfd_vma i
, bfd_vma span_end
,
3560 bfd_vma
*p_veneer_i
)
3562 uint32_t insn_1
= bfd_getl32 (contents
+ i
);
3564 if (!_bfd_aarch64_adrp_p (insn_1
))
3567 if (span_end
< i
+ 12)
3570 uint32_t insn_2
= bfd_getl32 (contents
+ i
+ 4);
3571 uint32_t insn_3
= bfd_getl32 (contents
+ i
+ 8);
3573 if ((vma
& 0xfff) != 0xff8 && (vma
& 0xfff) != 0xffc)
3576 if (_bfd_aarch64_erratum_843419_sequence_p (insn_1
, insn_2
, insn_3
))
3578 *p_veneer_i
= i
+ 8;
3582 if (span_end
< i
+ 16)
3585 uint32_t insn_4
= bfd_getl32 (contents
+ i
+ 12);
3587 if (_bfd_aarch64_erratum_843419_sequence_p (insn_1
, insn_2
, insn_4
))
3589 *p_veneer_i
= i
+ 12;
3597 /* Resize all stub sections. */
3600 _bfd_aarch64_resize_stubs (struct elf_aarch64_link_hash_table
*htab
)
3604 /* OK, we've added some stubs. Find out the new size of the
3606 for (section
= htab
->stub_bfd
->sections
;
3607 section
!= NULL
; section
= section
->next
)
3609 /* Ignore non-stub sections. */
3610 if (!strstr (section
->name
, STUB_SUFFIX
))
3615 bfd_hash_traverse (&htab
->stub_hash_table
, aarch64_size_one_stub
, htab
);
3617 for (section
= htab
->stub_bfd
->sections
;
3618 section
!= NULL
; section
= section
->next
)
3620 if (!strstr (section
->name
, STUB_SUFFIX
))
3626 /* Ensure all stub sections have a size which is a multiple of
3627 4096. This is important in order to ensure that the insertion
3628 of stub sections does not in itself move existing code around
3629 in such a way that new errata sequences are created. */
3630 if (htab
->fix_erratum_843419
)
3632 section
->size
= BFD_ALIGN (section
->size
, 0x1000);
3637 /* Construct an erratum 843419 workaround stub name.
3641 _bfd_aarch64_erratum_843419_stub_name (asection
*input_section
,
3644 const bfd_size_type len
= 8 + 4 + 1 + 8 + 1 + 16 + 1;
3645 char *stub_name
= bfd_malloc (len
);
3647 if (stub_name
!= NULL
)
3648 snprintf (stub_name
, len
, "e843419@%04x_%08x_%" BFD_VMA_FMT
"x",
3649 input_section
->owner
->id
,
3655 /* Build a stub_entry structure describing an 843419 fixup.
3657 The stub_entry constructed is populated with the bit pattern INSN
3658 of the instruction located at OFFSET within input SECTION.
3660 Returns TRUE on success. */
3663 _bfd_aarch64_erratum_843419_fixup (uint32_t insn
,
3664 bfd_vma adrp_offset
,
3665 bfd_vma ldst_offset
,
3667 struct bfd_link_info
*info
)
3669 struct elf_aarch64_link_hash_table
*htab
= elf_aarch64_hash_table (info
);
3671 struct elf_aarch64_stub_hash_entry
*stub_entry
;
3673 stub_name
= _bfd_aarch64_erratum_843419_stub_name (section
, ldst_offset
);
3674 stub_entry
= aarch64_stub_hash_lookup (&htab
->stub_hash_table
, stub_name
,
3682 /* We always place an 843419 workaround veneer in the stub section
3683 attached to the input section in which an erratum sequence has
3684 been found. This ensures that later in the link process (in
3685 elfNN_aarch64_write_section) when we copy the veneered
3686 instruction from the input section into the stub section the
3687 copied instruction will have had any relocations applied to it.
3688 If we placed workaround veneers in any other stub section then we
3689 could not assume that all relocations have been processed on the
3690 corresponding input section at the point we output the stub
3694 stub_entry
= _bfd_aarch64_add_stub_entry_after (stub_name
, section
, htab
);
3695 if (stub_entry
== NULL
)
3701 stub_entry
->adrp_offset
= adrp_offset
;
3702 stub_entry
->target_value
= ldst_offset
;
3703 stub_entry
->target_section
= section
;
3704 stub_entry
->stub_type
= aarch64_stub_erratum_843419_veneer
;
3705 stub_entry
->veneered_insn
= insn
;
3706 stub_entry
->output_name
= stub_name
;
3712 /* Scan an input section looking for the signature of erratum 843419.
3714 Scans input SECTION in INPUT_BFD looking for erratum 843419
3715 signatures, for each signature found a stub_entry is created
3716 describing the location of the erratum for subsequent fixup.
3718 Return TRUE on successful scan, FALSE on failure to scan.
3722 _bfd_aarch64_erratum_843419_scan (bfd
*input_bfd
, asection
*section
,
3723 struct bfd_link_info
*info
)
3725 struct elf_aarch64_link_hash_table
*htab
= elf_aarch64_hash_table (info
);
3730 if (elf_section_type (section
) != SHT_PROGBITS
3731 || (elf_section_flags (section
) & SHF_EXECINSTR
) == 0
3732 || (section
->flags
& SEC_EXCLUDE
) != 0
3733 || (section
->sec_info_type
== SEC_INFO_TYPE_JUST_SYMS
)
3734 || (section
->output_section
== bfd_abs_section_ptr
))
3739 bfd_byte
*contents
= NULL
;
3740 struct _aarch64_elf_section_data
*sec_data
;
3743 if (elf_section_data (section
)->this_hdr
.contents
!= NULL
)
3744 contents
= elf_section_data (section
)->this_hdr
.contents
;
3745 else if (! bfd_malloc_and_get_section (input_bfd
, section
, &contents
))
3748 sec_data
= elf_aarch64_section_data (section
);
3750 qsort (sec_data
->map
, sec_data
->mapcount
,
3751 sizeof (elf_aarch64_section_map
), elf_aarch64_compare_mapping
);
3753 for (span
= 0; span
< sec_data
->mapcount
; span
++)
3755 unsigned int span_start
= sec_data
->map
[span
].vma
;
3756 unsigned int span_end
= ((span
== sec_data
->mapcount
- 1)
3757 ? sec_data
->map
[0].vma
+ section
->size
3758 : sec_data
->map
[span
+ 1].vma
);
3760 char span_type
= sec_data
->map
[span
].type
;
3762 if (span_type
== 'd')
3765 for (i
= span_start
; i
+ 8 < span_end
; i
+= 4)
3767 bfd_vma vma
= (section
->output_section
->vma
3768 + section
->output_offset
3772 if (_bfd_aarch64_erratum_843419_p
3773 (contents
, vma
, i
, span_end
, &veneer_i
))
3775 uint32_t insn
= bfd_getl32 (contents
+ veneer_i
);
3777 if (!_bfd_aarch64_erratum_843419_fixup (insn
, i
, veneer_i
,
3784 if (elf_section_data (section
)->this_hdr
.contents
== NULL
)
3793 /* Determine and set the size of the stub section for a final link.
3795 The basic idea here is to examine all the relocations looking for
3796 PC-relative calls to a target that is unreachable with a "bl"
3800 elfNN_aarch64_size_stubs (bfd
*output_bfd
,
3802 struct bfd_link_info
*info
,
3803 bfd_signed_vma group_size
,
3804 asection
* (*add_stub_section
) (const char *,
3806 void (*layout_sections_again
) (void))
3808 bfd_size_type stub_group_size
;
3809 bfd_boolean stubs_always_before_branch
;
3810 bfd_boolean stub_changed
= FALSE
;
3811 struct elf_aarch64_link_hash_table
*htab
= elf_aarch64_hash_table (info
);
3812 unsigned int num_erratum_835769_fixes
= 0;
3814 /* Propagate mach to stub bfd, because it may not have been
3815 finalized when we created stub_bfd. */
3816 bfd_set_arch_mach (stub_bfd
, bfd_get_arch (output_bfd
),
3817 bfd_get_mach (output_bfd
));
3819 /* Stash our params away. */
3820 htab
->stub_bfd
= stub_bfd
;
3821 htab
->add_stub_section
= add_stub_section
;
3822 htab
->layout_sections_again
= layout_sections_again
;
3823 stubs_always_before_branch
= group_size
< 0;
3825 stub_group_size
= -group_size
;
3827 stub_group_size
= group_size
;
3829 if (stub_group_size
== 1)
3831 /* Default values. */
3832 /* AArch64 branch range is +-128MB. The value used is 1MB less. */
3833 stub_group_size
= 127 * 1024 * 1024;
3836 group_sections (htab
, stub_group_size
, stubs_always_before_branch
);
3838 (*htab
->layout_sections_again
) ();
3840 if (htab
->fix_erratum_835769
)
3844 for (input_bfd
= info
->input_bfds
;
3845 input_bfd
!= NULL
; input_bfd
= input_bfd
->link
.next
)
3846 if (!_bfd_aarch64_erratum_835769_scan (input_bfd
, info
,
3847 &num_erratum_835769_fixes
))
3850 _bfd_aarch64_resize_stubs (htab
);
3851 (*htab
->layout_sections_again
) ();
3854 if (htab
->fix_erratum_843419
)
3858 for (input_bfd
= info
->input_bfds
;
3860 input_bfd
= input_bfd
->link
.next
)
3864 for (section
= input_bfd
->sections
;
3866 section
= section
->next
)
3867 if (!_bfd_aarch64_erratum_843419_scan (input_bfd
, section
, info
))
3871 _bfd_aarch64_resize_stubs (htab
);
3872 (*htab
->layout_sections_again
) ();
3879 for (input_bfd
= info
->input_bfds
;
3880 input_bfd
!= NULL
; input_bfd
= input_bfd
->link
.next
)
3882 Elf_Internal_Shdr
*symtab_hdr
;
3884 Elf_Internal_Sym
*local_syms
= NULL
;
3886 /* We'll need the symbol table in a second. */
3887 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
3888 if (symtab_hdr
->sh_info
== 0)
3891 /* Walk over each section attached to the input bfd. */
3892 for (section
= input_bfd
->sections
;
3893 section
!= NULL
; section
= section
->next
)
3895 Elf_Internal_Rela
*internal_relocs
, *irelaend
, *irela
;
3897 /* If there aren't any relocs, then there's nothing more
3899 if ((section
->flags
& SEC_RELOC
) == 0
3900 || section
->reloc_count
== 0
3901 || (section
->flags
& SEC_CODE
) == 0)
3904 /* If this section is a link-once section that will be
3905 discarded, then don't create any stubs. */
3906 if (section
->output_section
== NULL
3907 || section
->output_section
->owner
!= output_bfd
)
3910 /* Get the relocs. */
3912 = _bfd_elf_link_read_relocs (input_bfd
, section
, NULL
,
3913 NULL
, info
->keep_memory
);
3914 if (internal_relocs
== NULL
)
3915 goto error_ret_free_local
;
3917 /* Now examine each relocation. */
3918 irela
= internal_relocs
;
3919 irelaend
= irela
+ section
->reloc_count
;
3920 for (; irela
< irelaend
; irela
++)
3922 unsigned int r_type
, r_indx
;
3923 enum elf_aarch64_stub_type stub_type
;
3924 struct elf_aarch64_stub_hash_entry
*stub_entry
;
3927 bfd_vma destination
;
3928 struct elf_aarch64_link_hash_entry
*hash
;
3929 const char *sym_name
;
3931 const asection
*id_sec
;
3932 unsigned char st_type
;
3935 r_type
= ELFNN_R_TYPE (irela
->r_info
);
3936 r_indx
= ELFNN_R_SYM (irela
->r_info
);
3938 if (r_type
>= (unsigned int) R_AARCH64_end
)
3940 bfd_set_error (bfd_error_bad_value
);
3941 error_ret_free_internal
:
3942 if (elf_section_data (section
)->relocs
== NULL
)
3943 free (internal_relocs
);
3944 goto error_ret_free_local
;
3947 /* Only look for stubs on unconditional branch and
3948 branch and link instructions. */
3949 if (r_type
!= (unsigned int) AARCH64_R (CALL26
)
3950 && r_type
!= (unsigned int) AARCH64_R (JUMP26
))
3953 /* Now determine the call target, its name, value,
3960 if (r_indx
< symtab_hdr
->sh_info
)
3962 /* It's a local symbol. */
3963 Elf_Internal_Sym
*sym
;
3964 Elf_Internal_Shdr
*hdr
;
3966 if (local_syms
== NULL
)
3969 = (Elf_Internal_Sym
*) symtab_hdr
->contents
;
3970 if (local_syms
== NULL
)
3972 = bfd_elf_get_elf_syms (input_bfd
, symtab_hdr
,
3973 symtab_hdr
->sh_info
, 0,
3975 if (local_syms
== NULL
)
3976 goto error_ret_free_internal
;
3979 sym
= local_syms
+ r_indx
;
3980 hdr
= elf_elfsections (input_bfd
)[sym
->st_shndx
];
3981 sym_sec
= hdr
->bfd_section
;
3983 /* This is an undefined symbol. It can never
3987 if (ELF_ST_TYPE (sym
->st_info
) != STT_SECTION
)
3988 sym_value
= sym
->st_value
;
3989 destination
= (sym_value
+ irela
->r_addend
3990 + sym_sec
->output_offset
3991 + sym_sec
->output_section
->vma
);
3992 st_type
= ELF_ST_TYPE (sym
->st_info
);
3994 = bfd_elf_string_from_elf_section (input_bfd
,
3995 symtab_hdr
->sh_link
,
4002 e_indx
= r_indx
- symtab_hdr
->sh_info
;
4003 hash
= ((struct elf_aarch64_link_hash_entry
*)
4004 elf_sym_hashes (input_bfd
)[e_indx
]);
4006 while (hash
->root
.root
.type
== bfd_link_hash_indirect
4007 || hash
->root
.root
.type
== bfd_link_hash_warning
)
4008 hash
= ((struct elf_aarch64_link_hash_entry
*)
4009 hash
->root
.root
.u
.i
.link
);
4011 if (hash
->root
.root
.type
== bfd_link_hash_defined
4012 || hash
->root
.root
.type
== bfd_link_hash_defweak
)
4014 struct elf_aarch64_link_hash_table
*globals
=
4015 elf_aarch64_hash_table (info
);
4016 sym_sec
= hash
->root
.root
.u
.def
.section
;
4017 sym_value
= hash
->root
.root
.u
.def
.value
;
4018 /* For a destination in a shared library,
4019 use the PLT stub as target address to
4020 decide whether a branch stub is
4022 if (globals
->root
.splt
!= NULL
&& hash
!= NULL
4023 && hash
->root
.plt
.offset
!= (bfd_vma
) - 1)
4025 sym_sec
= globals
->root
.splt
;
4026 sym_value
= hash
->root
.plt
.offset
;
4027 if (sym_sec
->output_section
!= NULL
)
4028 destination
= (sym_value
4029 + sym_sec
->output_offset
4031 sym_sec
->output_section
->vma
);
4033 else if (sym_sec
->output_section
!= NULL
)
4034 destination
= (sym_value
+ irela
->r_addend
4035 + sym_sec
->output_offset
4036 + sym_sec
->output_section
->vma
);
4038 else if (hash
->root
.root
.type
== bfd_link_hash_undefined
4039 || (hash
->root
.root
.type
4040 == bfd_link_hash_undefweak
))
4042 /* For a shared library, use the PLT stub as
4043 target address to decide whether a long
4044 branch stub is needed.
4045 For absolute code, they cannot be handled. */
4046 struct elf_aarch64_link_hash_table
*globals
=
4047 elf_aarch64_hash_table (info
);
4049 if (globals
->root
.splt
!= NULL
&& hash
!= NULL
4050 && hash
->root
.plt
.offset
!= (bfd_vma
) - 1)
4052 sym_sec
= globals
->root
.splt
;
4053 sym_value
= hash
->root
.plt
.offset
;
4054 if (sym_sec
->output_section
!= NULL
)
4055 destination
= (sym_value
4056 + sym_sec
->output_offset
4058 sym_sec
->output_section
->vma
);
4065 bfd_set_error (bfd_error_bad_value
);
4066 goto error_ret_free_internal
;
4068 st_type
= ELF_ST_TYPE (hash
->root
.type
);
4069 sym_name
= hash
->root
.root
.root
.string
;
4072 /* Determine what (if any) linker stub is needed. */
4073 stub_type
= aarch64_type_of_stub
4074 (info
, section
, irela
, sym_sec
, st_type
, hash
, destination
);
4075 if (stub_type
== aarch64_stub_none
)
4078 /* Support for grouping stub sections. */
4079 id_sec
= htab
->stub_group
[section
->id
].link_sec
;
4081 /* Get the name of this stub. */
4082 stub_name
= elfNN_aarch64_stub_name (id_sec
, sym_sec
, hash
,
4085 goto error_ret_free_internal
;
4088 aarch64_stub_hash_lookup (&htab
->stub_hash_table
,
4089 stub_name
, FALSE
, FALSE
);
4090 if (stub_entry
!= NULL
)
4092 /* The proper stub has already been created. */
4097 stub_entry
= _bfd_aarch64_add_stub_entry_in_group
4098 (stub_name
, section
, htab
);
4099 if (stub_entry
== NULL
)
4102 goto error_ret_free_internal
;
4105 stub_entry
->target_value
= sym_value
;
4106 stub_entry
->target_section
= sym_sec
;
4107 stub_entry
->stub_type
= stub_type
;
4108 stub_entry
->h
= hash
;
4109 stub_entry
->st_type
= st_type
;
4111 if (sym_name
== NULL
)
4112 sym_name
= "unnamed";
4113 len
= sizeof (STUB_ENTRY_NAME
) + strlen (sym_name
);
4114 stub_entry
->output_name
= bfd_alloc (htab
->stub_bfd
, len
);
4115 if (stub_entry
->output_name
== NULL
)
4118 goto error_ret_free_internal
;
4121 snprintf (stub_entry
->output_name
, len
, STUB_ENTRY_NAME
,
4124 stub_changed
= TRUE
;
4127 /* We're done with the internal relocs, free them. */
4128 if (elf_section_data (section
)->relocs
== NULL
)
4129 free (internal_relocs
);
4136 _bfd_aarch64_resize_stubs (htab
);
4138 /* Ask the linker to do its stuff. */
4139 (*htab
->layout_sections_again
) ();
4140 stub_changed
= FALSE
;
4145 error_ret_free_local
:
4149 /* Build all the stubs associated with the current output file. The
4150 stubs are kept in a hash table attached to the main linker hash
4151 table. We also set up the .plt entries for statically linked PIC
4152 functions here. This function is called via aarch64_elf_finish in the
4156 elfNN_aarch64_build_stubs (struct bfd_link_info
*info
)
4159 struct bfd_hash_table
*table
;
4160 struct elf_aarch64_link_hash_table
*htab
;
4162 htab
= elf_aarch64_hash_table (info
);
4164 for (stub_sec
= htab
->stub_bfd
->sections
;
4165 stub_sec
!= NULL
; stub_sec
= stub_sec
->next
)
4169 /* Ignore non-stub sections. */
4170 if (!strstr (stub_sec
->name
, STUB_SUFFIX
))
4173 /* Allocate memory to hold the linker stubs. */
4174 size
= stub_sec
->size
;
4175 stub_sec
->contents
= bfd_zalloc (htab
->stub_bfd
, size
);
4176 if (stub_sec
->contents
== NULL
&& size
!= 0)
4180 bfd_putl32 (0x14000000 | (size
>> 2), stub_sec
->contents
);
4181 stub_sec
->size
+= 4;
4184 /* Build the stubs as directed by the stub hash table. */
4185 table
= &htab
->stub_hash_table
;
4186 bfd_hash_traverse (table
, aarch64_build_one_stub
, info
);
4192 /* Add an entry to the code/data map for section SEC. */
4195 elfNN_aarch64_section_map_add (asection
*sec
, char type
, bfd_vma vma
)
4197 struct _aarch64_elf_section_data
*sec_data
=
4198 elf_aarch64_section_data (sec
);
4199 unsigned int newidx
;
4201 if (sec_data
->map
== NULL
)
4203 sec_data
->map
= bfd_malloc (sizeof (elf_aarch64_section_map
));
4204 sec_data
->mapcount
= 0;
4205 sec_data
->mapsize
= 1;
4208 newidx
= sec_data
->mapcount
++;
4210 if (sec_data
->mapcount
> sec_data
->mapsize
)
4212 sec_data
->mapsize
*= 2;
4213 sec_data
->map
= bfd_realloc_or_free
4214 (sec_data
->map
, sec_data
->mapsize
* sizeof (elf_aarch64_section_map
));
4219 sec_data
->map
[newidx
].vma
= vma
;
4220 sec_data
->map
[newidx
].type
= type
;
4225 /* Initialise maps of insn/data for input BFDs. */
4227 bfd_elfNN_aarch64_init_maps (bfd
*abfd
)
4229 Elf_Internal_Sym
*isymbuf
;
4230 Elf_Internal_Shdr
*hdr
;
4231 unsigned int i
, localsyms
;
4233 /* Make sure that we are dealing with an AArch64 elf binary. */
4234 if (!is_aarch64_elf (abfd
))
4237 if ((abfd
->flags
& DYNAMIC
) != 0)
4240 hdr
= &elf_symtab_hdr (abfd
);
4241 localsyms
= hdr
->sh_info
;
4243 /* Obtain a buffer full of symbols for this BFD. The hdr->sh_info field
4244 should contain the number of local symbols, which should come before any
4245 global symbols. Mapping symbols are always local. */
4246 isymbuf
= bfd_elf_get_elf_syms (abfd
, hdr
, localsyms
, 0, NULL
, NULL
, NULL
);
4248 /* No internal symbols read? Skip this BFD. */
4249 if (isymbuf
== NULL
)
4252 for (i
= 0; i
< localsyms
; i
++)
4254 Elf_Internal_Sym
*isym
= &isymbuf
[i
];
4255 asection
*sec
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
4258 if (sec
!= NULL
&& ELF_ST_BIND (isym
->st_info
) == STB_LOCAL
)
4260 name
= bfd_elf_string_from_elf_section (abfd
,
4264 if (bfd_is_aarch64_special_symbol_name
4265 (name
, BFD_AARCH64_SPECIAL_SYM_TYPE_MAP
))
4266 elfNN_aarch64_section_map_add (sec
, name
[1], isym
->st_value
);
4271 /* Set option values needed during linking. */
4273 bfd_elfNN_aarch64_set_options (struct bfd
*output_bfd
,
4274 struct bfd_link_info
*link_info
,
4276 int no_wchar_warn
, int pic_veneer
,
4277 int fix_erratum_835769
,
4278 int fix_erratum_843419
)
4280 struct elf_aarch64_link_hash_table
*globals
;
4282 globals
= elf_aarch64_hash_table (link_info
);
4283 globals
->pic_veneer
= pic_veneer
;
4284 globals
->fix_erratum_835769
= fix_erratum_835769
;
4285 globals
->fix_erratum_843419
= fix_erratum_843419
;
4286 globals
->fix_erratum_843419_adr
= TRUE
;
4288 BFD_ASSERT (is_aarch64_elf (output_bfd
));
4289 elf_aarch64_tdata (output_bfd
)->no_enum_size_warning
= no_enum_warn
;
4290 elf_aarch64_tdata (output_bfd
)->no_wchar_size_warning
= no_wchar_warn
;
4294 aarch64_calculate_got_entry_vma (struct elf_link_hash_entry
*h
,
4295 struct elf_aarch64_link_hash_table
4296 *globals
, struct bfd_link_info
*info
,
4297 bfd_vma value
, bfd
*output_bfd
,
4298 bfd_boolean
*unresolved_reloc_p
)
4300 bfd_vma off
= (bfd_vma
) - 1;
4301 asection
*basegot
= globals
->root
.sgot
;
4302 bfd_boolean dyn
= globals
->root
.dynamic_sections_created
;
4306 BFD_ASSERT (basegot
!= NULL
);
4307 off
= h
->got
.offset
;
4308 BFD_ASSERT (off
!= (bfd_vma
) - 1);
4309 if (!WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, bfd_link_pic (info
), h
)
4310 || (bfd_link_pic (info
)
4311 && SYMBOL_REFERENCES_LOCAL (info
, h
))
4312 || (ELF_ST_VISIBILITY (h
->other
)
4313 && h
->root
.type
== bfd_link_hash_undefweak
))
4315 /* This is actually a static link, or it is a -Bsymbolic link
4316 and the symbol is defined locally. We must initialize this
4317 entry in the global offset table. Since the offset must
4318 always be a multiple of 8 (4 in the case of ILP32), we use
4319 the least significant bit to record whether we have
4320 initialized it already.
4321 When doing a dynamic link, we create a .rel(a).got relocation
4322 entry to initialize the value. This is done in the
4323 finish_dynamic_symbol routine. */
4328 bfd_put_NN (output_bfd
, value
, basegot
->contents
+ off
);
4333 *unresolved_reloc_p
= FALSE
;
4335 off
= off
+ basegot
->output_section
->vma
+ basegot
->output_offset
;
4341 /* Change R_TYPE to a more efficient access model where possible,
4342 return the new reloc type. */
4344 static bfd_reloc_code_real_type
4345 aarch64_tls_transition_without_check (bfd_reloc_code_real_type r_type
,
4346 struct elf_link_hash_entry
*h
)
4348 bfd_boolean is_local
= h
== NULL
;
4352 case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21
:
4353 case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21
:
4355 ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1
4356 : BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21
);
4358 case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21
:
4360 ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC
4363 case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19
:
4365 ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1
4366 : BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19
);
4368 case BFD_RELOC_AARCH64_TLSDESC_LDNN_LO12_NC
:
4369 case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC
:
4371 ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC
4372 : BFD_RELOC_AARCH64_TLSIE_LDNN_GOTTPREL_LO12_NC
);
4374 case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21
:
4375 return is_local
? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1
: r_type
;
4377 case BFD_RELOC_AARCH64_TLSIE_LDNN_GOTTPREL_LO12_NC
:
4378 return is_local
? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC
: r_type
;
4380 case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19
:
4383 case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21
:
4385 ? BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_HI12
4386 : BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19
);
4388 case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12_NC
:
4389 case BFD_RELOC_AARCH64_TLSDESC_CALL
:
4390 /* Instructions with these relocations will become NOPs. */
4391 return BFD_RELOC_AARCH64_NONE
;
4401 aarch64_reloc_got_type (bfd_reloc_code_real_type r_type
)
4405 case BFD_RELOC_AARCH64_ADR_GOT_PAGE
:
4406 case BFD_RELOC_AARCH64_GOT_LD_PREL19
:
4407 case BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14
:
4408 case BFD_RELOC_AARCH64_LD32_GOT_LO12_NC
:
4409 case BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15
:
4410 case BFD_RELOC_AARCH64_LD64_GOT_LO12_NC
:
4413 case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC
:
4414 case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21
:
4415 case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21
:
4416 case BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC
:
4417 case BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21
:
4418 case BFD_RELOC_AARCH64_TLSLD_ADR_PREL21
:
4421 case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12_NC
:
4422 case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21
:
4423 case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21
:
4424 case BFD_RELOC_AARCH64_TLSDESC_CALL
:
4425 case BFD_RELOC_AARCH64_TLSDESC_LD32_LO12_NC
:
4426 case BFD_RELOC_AARCH64_TLSDESC_LD64_LO12_NC
:
4427 case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19
:
4428 return GOT_TLSDESC_GD
;
4430 case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21
:
4431 case BFD_RELOC_AARCH64_TLSIE_LD32_GOTTPREL_LO12_NC
:
4432 case BFD_RELOC_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC
:
4433 case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19
:
4443 aarch64_can_relax_tls (bfd
*input_bfd
,
4444 struct bfd_link_info
*info
,
4445 bfd_reloc_code_real_type r_type
,
4446 struct elf_link_hash_entry
*h
,
4447 unsigned long r_symndx
)
4449 unsigned int symbol_got_type
;
4450 unsigned int reloc_got_type
;
4452 if (! IS_AARCH64_TLS_RELAX_RELOC (r_type
))
4455 symbol_got_type
= elfNN_aarch64_symbol_got_type (h
, input_bfd
, r_symndx
);
4456 reloc_got_type
= aarch64_reloc_got_type (r_type
);
4458 if (symbol_got_type
== GOT_TLS_IE
&& GOT_TLS_GD_ANY_P (reloc_got_type
))
4461 if (bfd_link_pic (info
))
4464 if (h
&& h
->root
.type
== bfd_link_hash_undefweak
)
4470 /* Given the relocation code R_TYPE, return the relaxed bfd reloc
4473 static bfd_reloc_code_real_type
4474 aarch64_tls_transition (bfd
*input_bfd
,
4475 struct bfd_link_info
*info
,
4476 unsigned int r_type
,
4477 struct elf_link_hash_entry
*h
,
4478 unsigned long r_symndx
)
4480 bfd_reloc_code_real_type bfd_r_type
4481 = elfNN_aarch64_bfd_reloc_from_type (r_type
);
4483 if (! aarch64_can_relax_tls (input_bfd
, info
, bfd_r_type
, h
, r_symndx
))
4486 return aarch64_tls_transition_without_check (bfd_r_type
, h
);
4489 /* Return the base VMA address which should be subtracted from real addresses
4490 when resolving R_AARCH64_TLS_DTPREL relocation. */
4493 dtpoff_base (struct bfd_link_info
*info
)
4495 /* If tls_sec is NULL, we should have signalled an error already. */
4496 BFD_ASSERT (elf_hash_table (info
)->tls_sec
!= NULL
);
4497 return elf_hash_table (info
)->tls_sec
->vma
;
4500 /* Return the base VMA address which should be subtracted from real addresses
4501 when resolving R_AARCH64_TLS_GOTTPREL64 relocations. */
4504 tpoff_base (struct bfd_link_info
*info
)
4506 struct elf_link_hash_table
*htab
= elf_hash_table (info
);
4508 /* If tls_sec is NULL, we should have signalled an error already. */
4509 BFD_ASSERT (htab
->tls_sec
!= NULL
);
4511 bfd_vma base
= align_power ((bfd_vma
) TCB_SIZE
,
4512 htab
->tls_sec
->alignment_power
);
4513 return htab
->tls_sec
->vma
- base
;
4517 symbol_got_offset_ref (bfd
*input_bfd
, struct elf_link_hash_entry
*h
,
4518 unsigned long r_symndx
)
4520 /* Calculate the address of the GOT entry for symbol
4521 referred to in h. */
4523 return &h
->got
.offset
;
4527 struct elf_aarch64_local_symbol
*l
;
4529 l
= elf_aarch64_locals (input_bfd
);
4530 return &l
[r_symndx
].got_offset
;
4535 symbol_got_offset_mark (bfd
*input_bfd
, struct elf_link_hash_entry
*h
,
4536 unsigned long r_symndx
)
4539 p
= symbol_got_offset_ref (input_bfd
, h
, r_symndx
);
4544 symbol_got_offset_mark_p (bfd
*input_bfd
, struct elf_link_hash_entry
*h
,
4545 unsigned long r_symndx
)
4548 value
= * symbol_got_offset_ref (input_bfd
, h
, r_symndx
);
4553 symbol_got_offset (bfd
*input_bfd
, struct elf_link_hash_entry
*h
,
4554 unsigned long r_symndx
)
4557 value
= * symbol_got_offset_ref (input_bfd
, h
, r_symndx
);
4563 symbol_tlsdesc_got_offset_ref (bfd
*input_bfd
, struct elf_link_hash_entry
*h
,
4564 unsigned long r_symndx
)
4566 /* Calculate the address of the GOT entry for symbol
4567 referred to in h. */
4570 struct elf_aarch64_link_hash_entry
*eh
;
4571 eh
= (struct elf_aarch64_link_hash_entry
*) h
;
4572 return &eh
->tlsdesc_got_jump_table_offset
;
4577 struct elf_aarch64_local_symbol
*l
;
4579 l
= elf_aarch64_locals (input_bfd
);
4580 return &l
[r_symndx
].tlsdesc_got_jump_table_offset
;
4585 symbol_tlsdesc_got_offset_mark (bfd
*input_bfd
, struct elf_link_hash_entry
*h
,
4586 unsigned long r_symndx
)
4589 p
= symbol_tlsdesc_got_offset_ref (input_bfd
, h
, r_symndx
);
4594 symbol_tlsdesc_got_offset_mark_p (bfd
*input_bfd
,
4595 struct elf_link_hash_entry
*h
,
4596 unsigned long r_symndx
)
4599 value
= * symbol_tlsdesc_got_offset_ref (input_bfd
, h
, r_symndx
);
4604 symbol_tlsdesc_got_offset (bfd
*input_bfd
, struct elf_link_hash_entry
*h
,
4605 unsigned long r_symndx
)
4608 value
= * symbol_tlsdesc_got_offset_ref (input_bfd
, h
, r_symndx
);
4613 /* Data for make_branch_to_erratum_835769_stub(). */
4615 struct erratum_835769_branch_to_stub_data
4617 struct bfd_link_info
*info
;
4618 asection
*output_section
;
4622 /* Helper to insert branches to erratum 835769 stubs in the right
4623 places for a particular section. */
4626 make_branch_to_erratum_835769_stub (struct bfd_hash_entry
*gen_entry
,
4629 struct elf_aarch64_stub_hash_entry
*stub_entry
;
4630 struct erratum_835769_branch_to_stub_data
*data
;
4632 unsigned long branch_insn
= 0;
4633 bfd_vma veneered_insn_loc
, veneer_entry_loc
;
4634 bfd_signed_vma branch_offset
;
4635 unsigned int target
;
4638 stub_entry
= (struct elf_aarch64_stub_hash_entry
*) gen_entry
;
4639 data
= (struct erratum_835769_branch_to_stub_data
*) in_arg
;
4641 if (stub_entry
->target_section
!= data
->output_section
4642 || stub_entry
->stub_type
!= aarch64_stub_erratum_835769_veneer
)
4645 contents
= data
->contents
;
4646 veneered_insn_loc
= stub_entry
->target_section
->output_section
->vma
4647 + stub_entry
->target_section
->output_offset
4648 + stub_entry
->target_value
;
4649 veneer_entry_loc
= stub_entry
->stub_sec
->output_section
->vma
4650 + stub_entry
->stub_sec
->output_offset
4651 + stub_entry
->stub_offset
;
4652 branch_offset
= veneer_entry_loc
- veneered_insn_loc
;
4654 abfd
= stub_entry
->target_section
->owner
;
4655 if (!aarch64_valid_branch_p (veneer_entry_loc
, veneered_insn_loc
))
4656 (*_bfd_error_handler
)
4657 (_("%B: error: Erratum 835769 stub out "
4658 "of range (input file too large)"), abfd
);
4660 target
= stub_entry
->target_value
;
4661 branch_insn
= 0x14000000;
4662 branch_offset
>>= 2;
4663 branch_offset
&= 0x3ffffff;
4664 branch_insn
|= branch_offset
;
4665 bfd_putl32 (branch_insn
, &contents
[target
]);
4672 _bfd_aarch64_erratum_843419_branch_to_stub (struct bfd_hash_entry
*gen_entry
,
4675 struct elf_aarch64_stub_hash_entry
*stub_entry
4676 = (struct elf_aarch64_stub_hash_entry
*) gen_entry
;
4677 struct erratum_835769_branch_to_stub_data
*data
4678 = (struct erratum_835769_branch_to_stub_data
*) in_arg
;
4679 struct bfd_link_info
*info
;
4680 struct elf_aarch64_link_hash_table
*htab
;
4688 contents
= data
->contents
;
4689 section
= data
->output_section
;
4691 htab
= elf_aarch64_hash_table (info
);
4693 if (stub_entry
->target_section
!= section
4694 || stub_entry
->stub_type
!= aarch64_stub_erratum_843419_veneer
)
4697 insn
= bfd_getl32 (contents
+ stub_entry
->target_value
);
4699 stub_entry
->stub_sec
->contents
+ stub_entry
->stub_offset
);
4701 place
= (section
->output_section
->vma
+ section
->output_offset
4702 + stub_entry
->adrp_offset
);
4703 insn
= bfd_getl32 (contents
+ stub_entry
->adrp_offset
);
4705 if ((insn
& AARCH64_ADRP_OP_MASK
) != AARCH64_ADRP_OP
)
4708 bfd_signed_vma imm
=
4709 (_bfd_aarch64_sign_extend
4710 ((bfd_vma
) _bfd_aarch64_decode_adrp_imm (insn
) << 12, 33)
4713 if (htab
->fix_erratum_843419_adr
4714 && (imm
>= AARCH64_MIN_ADRP_IMM
&& imm
<= AARCH64_MAX_ADRP_IMM
))
4716 insn
= (_bfd_aarch64_reencode_adr_imm (AARCH64_ADR_OP
, imm
)
4717 | AARCH64_RT (insn
));
4718 bfd_putl32 (insn
, contents
+ stub_entry
->adrp_offset
);
4722 bfd_vma veneered_insn_loc
;
4723 bfd_vma veneer_entry_loc
;
4724 bfd_signed_vma branch_offset
;
4725 uint32_t branch_insn
;
4727 veneered_insn_loc
= stub_entry
->target_section
->output_section
->vma
4728 + stub_entry
->target_section
->output_offset
4729 + stub_entry
->target_value
;
4730 veneer_entry_loc
= stub_entry
->stub_sec
->output_section
->vma
4731 + stub_entry
->stub_sec
->output_offset
4732 + stub_entry
->stub_offset
;
4733 branch_offset
= veneer_entry_loc
- veneered_insn_loc
;
4735 abfd
= stub_entry
->target_section
->owner
;
4736 if (!aarch64_valid_branch_p (veneer_entry_loc
, veneered_insn_loc
))
4737 (*_bfd_error_handler
)
4738 (_("%B: error: Erratum 843419 stub out "
4739 "of range (input file too large)"), abfd
);
4741 branch_insn
= 0x14000000;
4742 branch_offset
>>= 2;
4743 branch_offset
&= 0x3ffffff;
4744 branch_insn
|= branch_offset
;
4745 bfd_putl32 (branch_insn
, contents
+ stub_entry
->target_value
);
4752 elfNN_aarch64_write_section (bfd
*output_bfd ATTRIBUTE_UNUSED
,
4753 struct bfd_link_info
*link_info
,
4758 struct elf_aarch64_link_hash_table
*globals
=
4759 elf_aarch64_hash_table (link_info
);
4761 if (globals
== NULL
)
4764 /* Fix code to point to erratum 835769 stubs. */
4765 if (globals
->fix_erratum_835769
)
4767 struct erratum_835769_branch_to_stub_data data
;
4769 data
.info
= link_info
;
4770 data
.output_section
= sec
;
4771 data
.contents
= contents
;
4772 bfd_hash_traverse (&globals
->stub_hash_table
,
4773 make_branch_to_erratum_835769_stub
, &data
);
4776 if (globals
->fix_erratum_843419
)
4778 struct erratum_835769_branch_to_stub_data data
;
4780 data
.info
= link_info
;
4781 data
.output_section
= sec
;
4782 data
.contents
= contents
;
4783 bfd_hash_traverse (&globals
->stub_hash_table
,
4784 _bfd_aarch64_erratum_843419_branch_to_stub
, &data
);
4790 /* Perform a relocation as part of a final link. */
4791 static bfd_reloc_status_type
4792 elfNN_aarch64_final_link_relocate (reloc_howto_type
*howto
,
4795 asection
*input_section
,
4797 Elf_Internal_Rela
*rel
,
4799 struct bfd_link_info
*info
,
4801 struct elf_link_hash_entry
*h
,
4802 bfd_boolean
*unresolved_reloc_p
,
4803 bfd_boolean save_addend
,
4804 bfd_vma
*saved_addend
,
4805 Elf_Internal_Sym
*sym
)
4807 Elf_Internal_Shdr
*symtab_hdr
;
4808 unsigned int r_type
= howto
->type
;
4809 bfd_reloc_code_real_type bfd_r_type
4810 = elfNN_aarch64_bfd_reloc_from_howto (howto
);
4811 bfd_reloc_code_real_type new_bfd_r_type
;
4812 unsigned long r_symndx
;
4813 bfd_byte
*hit_data
= contents
+ rel
->r_offset
;
4815 bfd_signed_vma signed_addend
;
4816 struct elf_aarch64_link_hash_table
*globals
;
4817 bfd_boolean weak_undef_p
;
4820 globals
= elf_aarch64_hash_table (info
);
4822 symtab_hdr
= &elf_symtab_hdr (input_bfd
);
4824 BFD_ASSERT (is_aarch64_elf (input_bfd
));
4826 r_symndx
= ELFNN_R_SYM (rel
->r_info
);
4828 /* It is possible to have linker relaxations on some TLS access
4829 models. Update our information here. */
4830 new_bfd_r_type
= aarch64_tls_transition (input_bfd
, info
, r_type
, h
, r_symndx
);
4831 if (new_bfd_r_type
!= bfd_r_type
)
4833 bfd_r_type
= new_bfd_r_type
;
4834 howto
= elfNN_aarch64_howto_from_bfd_reloc (bfd_r_type
);
4835 BFD_ASSERT (howto
!= NULL
);
4836 r_type
= howto
->type
;
4839 place
= input_section
->output_section
->vma
4840 + input_section
->output_offset
+ rel
->r_offset
;
4842 /* Get addend, accumulating the addend for consecutive relocs
4843 which refer to the same offset. */
4844 signed_addend
= saved_addend
? *saved_addend
: 0;
4845 signed_addend
+= rel
->r_addend
;
4847 weak_undef_p
= (h
? h
->root
.type
== bfd_link_hash_undefweak
4848 : bfd_is_und_section (sym_sec
));
4850 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle
4851 it here if it is defined in a non-shared object. */
4853 && h
->type
== STT_GNU_IFUNC
4860 if ((input_section
->flags
& SEC_ALLOC
) == 0
4861 || h
->plt
.offset
== (bfd_vma
) -1)
4864 /* STT_GNU_IFUNC symbol must go through PLT. */
4865 plt
= globals
->root
.splt
? globals
->root
.splt
: globals
->root
.iplt
;
4866 value
= (plt
->output_section
->vma
+ plt
->output_offset
+ h
->plt
.offset
);
4871 if (h
->root
.root
.string
)
4872 name
= h
->root
.root
.string
;
4874 name
= bfd_elf_sym_name (input_bfd
, symtab_hdr
, sym
,
4876 (*_bfd_error_handler
)
4877 (_("%B: relocation %s against STT_GNU_IFUNC "
4878 "symbol `%s' isn't handled by %s"), input_bfd
,
4879 howto
->name
, name
, __FUNCTION__
);
4880 bfd_set_error (bfd_error_bad_value
);
4883 case BFD_RELOC_AARCH64_NN
:
4884 if (rel
->r_addend
!= 0)
4886 if (h
->root
.root
.string
)
4887 name
= h
->root
.root
.string
;
4889 name
= bfd_elf_sym_name (input_bfd
, symtab_hdr
,
4891 (*_bfd_error_handler
)
4892 (_("%B: relocation %s against STT_GNU_IFUNC "
4893 "symbol `%s' has non-zero addend: %d"),
4894 input_bfd
, howto
->name
, name
, rel
->r_addend
);
4895 bfd_set_error (bfd_error_bad_value
);
4899 /* Generate dynamic relocation only when there is a
4900 non-GOT reference in a shared object. */
4901 if (bfd_link_pic (info
) && h
->non_got_ref
)
4903 Elf_Internal_Rela outrel
;
4906 /* Need a dynamic relocation to get the real function
4908 outrel
.r_offset
= _bfd_elf_section_offset (output_bfd
,
4912 if (outrel
.r_offset
== (bfd_vma
) -1
4913 || outrel
.r_offset
== (bfd_vma
) -2)
4916 outrel
.r_offset
+= (input_section
->output_section
->vma
4917 + input_section
->output_offset
);
4919 if (h
->dynindx
== -1
4921 || bfd_link_executable (info
))
4923 /* This symbol is resolved locally. */
4924 outrel
.r_info
= ELFNN_R_INFO (0, AARCH64_R (IRELATIVE
));
4925 outrel
.r_addend
= (h
->root
.u
.def
.value
4926 + h
->root
.u
.def
.section
->output_section
->vma
4927 + h
->root
.u
.def
.section
->output_offset
);
4931 outrel
.r_info
= ELFNN_R_INFO (h
->dynindx
, r_type
);
4932 outrel
.r_addend
= 0;
4935 sreloc
= globals
->root
.irelifunc
;
4936 elf_append_rela (output_bfd
, sreloc
, &outrel
);
4938 /* If this reloc is against an external symbol, we
4939 do not want to fiddle with the addend. Otherwise,
4940 we need to include the symbol value so that it
4941 becomes an addend for the dynamic reloc. For an
4942 internal symbol, we have updated addend. */
4943 return bfd_reloc_ok
;
4946 case BFD_RELOC_AARCH64_CALL26
:
4947 case BFD_RELOC_AARCH64_JUMP26
:
4948 value
= _bfd_aarch64_elf_resolve_relocation (bfd_r_type
, place
, value
,
4951 return _bfd_aarch64_elf_put_addend (input_bfd
, hit_data
, bfd_r_type
,
4953 case BFD_RELOC_AARCH64_ADR_GOT_PAGE
:
4954 case BFD_RELOC_AARCH64_GOT_LD_PREL19
:
4955 case BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14
:
4956 case BFD_RELOC_AARCH64_LD32_GOT_LO12_NC
:
4957 case BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15
:
4958 case BFD_RELOC_AARCH64_LD64_GOT_LO12_NC
:
4959 base_got
= globals
->root
.sgot
;
4960 off
= h
->got
.offset
;
4962 if (base_got
== NULL
)
4965 if (off
== (bfd_vma
) -1)
4969 /* We can't use h->got.offset here to save state, or
4970 even just remember the offset, as finish_dynamic_symbol
4971 would use that as offset into .got. */
4973 if (globals
->root
.splt
!= NULL
)
4975 plt_index
= ((h
->plt
.offset
- globals
->plt_header_size
) /
4976 globals
->plt_entry_size
);
4977 off
= (plt_index
+ 3) * GOT_ENTRY_SIZE
;
4978 base_got
= globals
->root
.sgotplt
;
4982 plt_index
= h
->plt
.offset
/ globals
->plt_entry_size
;
4983 off
= plt_index
* GOT_ENTRY_SIZE
;
4984 base_got
= globals
->root
.igotplt
;
4987 if (h
->dynindx
== -1
4991 /* This references the local definition. We must
4992 initialize this entry in the global offset table.
4993 Since the offset must always be a multiple of 8,
4994 we use the least significant bit to record
4995 whether we have initialized it already.
4997 When doing a dynamic link, we create a .rela.got
4998 relocation entry to initialize the value. This
4999 is done in the finish_dynamic_symbol routine. */
5004 bfd_put_NN (output_bfd
, value
,
5005 base_got
->contents
+ off
);
5006 /* Note that this is harmless as -1 | 1 still is -1. */
5010 value
= (base_got
->output_section
->vma
5011 + base_got
->output_offset
+ off
);
5014 value
= aarch64_calculate_got_entry_vma (h
, globals
, info
,
5016 unresolved_reloc_p
);
5017 if (bfd_r_type
== BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15
5018 || bfd_r_type
== BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14
)
5019 addend
= (globals
->root
.sgot
->output_section
->vma
5020 + globals
->root
.sgot
->output_offset
);
5021 value
= _bfd_aarch64_elf_resolve_relocation (bfd_r_type
, place
, value
,
5022 addend
, weak_undef_p
);
5023 return _bfd_aarch64_elf_put_addend (input_bfd
, hit_data
, bfd_r_type
, howto
, value
);
5024 case BFD_RELOC_AARCH64_ADD_LO12
:
5025 case BFD_RELOC_AARCH64_ADR_HI21_PCREL
:
5032 case BFD_RELOC_AARCH64_NONE
:
5033 case BFD_RELOC_AARCH64_TLSDESC_CALL
:
5034 *unresolved_reloc_p
= FALSE
;
5035 return bfd_reloc_ok
;
5037 case BFD_RELOC_AARCH64_NN
:
5039 /* When generating a shared object or relocatable executable, these
5040 relocations are copied into the output file to be resolved at
5042 if (((bfd_link_pic (info
) == TRUE
)
5043 || globals
->root
.is_relocatable_executable
)
5044 && (input_section
->flags
& SEC_ALLOC
)
5046 || ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
5047 || h
->root
.type
!= bfd_link_hash_undefweak
))
5049 Elf_Internal_Rela outrel
;
5051 bfd_boolean skip
, relocate
;
5054 *unresolved_reloc_p
= FALSE
;
5059 outrel
.r_addend
= signed_addend
;
5061 _bfd_elf_section_offset (output_bfd
, info
, input_section
,
5063 if (outrel
.r_offset
== (bfd_vma
) - 1)
5065 else if (outrel
.r_offset
== (bfd_vma
) - 2)
5071 outrel
.r_offset
+= (input_section
->output_section
->vma
5072 + input_section
->output_offset
);
5075 memset (&outrel
, 0, sizeof outrel
);
5078 && (!bfd_link_pic (info
)
5079 || !SYMBOLIC_BIND (info
, h
)
5080 || !h
->def_regular
))
5081 outrel
.r_info
= ELFNN_R_INFO (h
->dynindx
, r_type
);
5086 /* On SVR4-ish systems, the dynamic loader cannot
5087 relocate the text and data segments independently,
5088 so the symbol does not matter. */
5090 outrel
.r_info
= ELFNN_R_INFO (symbol
, AARCH64_R (RELATIVE
));
5091 outrel
.r_addend
+= value
;
5094 sreloc
= elf_section_data (input_section
)->sreloc
;
5095 if (sreloc
== NULL
|| sreloc
->contents
== NULL
)
5096 return bfd_reloc_notsupported
;
5098 loc
= sreloc
->contents
+ sreloc
->reloc_count
++ * RELOC_SIZE (globals
);
5099 bfd_elfNN_swap_reloca_out (output_bfd
, &outrel
, loc
);
5101 if (sreloc
->reloc_count
* RELOC_SIZE (globals
) > sreloc
->size
)
5103 /* Sanity to check that we have previously allocated
5104 sufficient space in the relocation section for the
5105 number of relocations we actually want to emit. */
5109 /* If this reloc is against an external symbol, we do not want to
5110 fiddle with the addend. Otherwise, we need to include the symbol
5111 value so that it becomes an addend for the dynamic reloc. */
5113 return bfd_reloc_ok
;
5115 return _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
5116 contents
, rel
->r_offset
, value
,
5120 value
+= signed_addend
;
5123 case BFD_RELOC_AARCH64_CALL26
:
5124 case BFD_RELOC_AARCH64_JUMP26
:
5126 asection
*splt
= globals
->root
.splt
;
5127 bfd_boolean via_plt_p
=
5128 splt
!= NULL
&& h
!= NULL
&& h
->plt
.offset
!= (bfd_vma
) - 1;
5130 /* A call to an undefined weak symbol is converted to a jump to
5131 the next instruction unless a PLT entry will be created.
5132 The jump to the next instruction is optimized as a NOP.
5133 Do the same for local undefined symbols. */
5134 if (weak_undef_p
&& ! via_plt_p
)
5136 bfd_putl32 (INSN_NOP
, hit_data
);
5137 return bfd_reloc_ok
;
5140 /* If the call goes through a PLT entry, make sure to
5141 check distance to the right destination address. */
5143 value
= (splt
->output_section
->vma
5144 + splt
->output_offset
+ h
->plt
.offset
);
5146 /* Check if a stub has to be inserted because the destination
5148 struct elf_aarch64_stub_hash_entry
*stub_entry
= NULL
;
5149 if (! aarch64_valid_branch_p (value
, place
))
5150 /* The target is out of reach, so redirect the branch to
5151 the local stub for this function. */
5152 stub_entry
= elfNN_aarch64_get_stub_entry (input_section
, sym_sec
, h
,
5154 if (stub_entry
!= NULL
)
5155 value
= (stub_entry
->stub_offset
5156 + stub_entry
->stub_sec
->output_offset
5157 + stub_entry
->stub_sec
->output_section
->vma
);
5159 value
= _bfd_aarch64_elf_resolve_relocation (bfd_r_type
, place
, value
,
5160 signed_addend
, weak_undef_p
);
5161 *unresolved_reloc_p
= FALSE
;
5164 case BFD_RELOC_AARCH64_16_PCREL
:
5165 case BFD_RELOC_AARCH64_32_PCREL
:
5166 case BFD_RELOC_AARCH64_64_PCREL
:
5167 case BFD_RELOC_AARCH64_ADR_HI21_NC_PCREL
:
5168 case BFD_RELOC_AARCH64_ADR_HI21_PCREL
:
5169 case BFD_RELOC_AARCH64_ADR_LO21_PCREL
:
5170 case BFD_RELOC_AARCH64_LD_LO19_PCREL
:
5171 if (bfd_link_pic (info
)
5172 && (input_section
->flags
& SEC_ALLOC
) != 0
5173 && (input_section
->flags
& SEC_READONLY
) != 0
5177 int howto_index
= bfd_r_type
- BFD_RELOC_AARCH64_RELOC_START
;
5179 (*_bfd_error_handler
)
5180 (_("%B: relocation %s against external symbol `%s' can not be used"
5181 " when making a shared object; recompile with -fPIC"),
5182 input_bfd
, elfNN_aarch64_howto_table
[howto_index
].name
,
5183 h
->root
.root
.string
);
5184 bfd_set_error (bfd_error_bad_value
);
5188 case BFD_RELOC_AARCH64_16
:
5190 case BFD_RELOC_AARCH64_32
:
5192 case BFD_RELOC_AARCH64_ADD_LO12
:
5193 case BFD_RELOC_AARCH64_BRANCH19
:
5194 case BFD_RELOC_AARCH64_LDST128_LO12
:
5195 case BFD_RELOC_AARCH64_LDST16_LO12
:
5196 case BFD_RELOC_AARCH64_LDST32_LO12
:
5197 case BFD_RELOC_AARCH64_LDST64_LO12
:
5198 case BFD_RELOC_AARCH64_LDST8_LO12
:
5199 case BFD_RELOC_AARCH64_MOVW_G0
:
5200 case BFD_RELOC_AARCH64_MOVW_G0_NC
:
5201 case BFD_RELOC_AARCH64_MOVW_G0_S
:
5202 case BFD_RELOC_AARCH64_MOVW_G1
:
5203 case BFD_RELOC_AARCH64_MOVW_G1_NC
:
5204 case BFD_RELOC_AARCH64_MOVW_G1_S
:
5205 case BFD_RELOC_AARCH64_MOVW_G2
:
5206 case BFD_RELOC_AARCH64_MOVW_G2_NC
:
5207 case BFD_RELOC_AARCH64_MOVW_G2_S
:
5208 case BFD_RELOC_AARCH64_MOVW_G3
:
5209 case BFD_RELOC_AARCH64_TSTBR14
:
5210 value
= _bfd_aarch64_elf_resolve_relocation (bfd_r_type
, place
, value
,
5211 signed_addend
, weak_undef_p
);
5214 case BFD_RELOC_AARCH64_ADR_GOT_PAGE
:
5215 case BFD_RELOC_AARCH64_GOT_LD_PREL19
:
5216 case BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14
:
5217 case BFD_RELOC_AARCH64_LD32_GOT_LO12_NC
:
5218 case BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15
:
5219 case BFD_RELOC_AARCH64_LD64_GOT_LO12_NC
:
5220 if (globals
->root
.sgot
== NULL
)
5221 BFD_ASSERT (h
!= NULL
);
5226 value
= aarch64_calculate_got_entry_vma (h
, globals
, info
, value
,
5228 unresolved_reloc_p
);
5229 if (bfd_r_type
== BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15
5230 || bfd_r_type
== BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14
)
5231 addend
= (globals
->root
.sgot
->output_section
->vma
5232 + globals
->root
.sgot
->output_offset
);
5233 value
= _bfd_aarch64_elf_resolve_relocation (bfd_r_type
, place
, value
,
5234 addend
, weak_undef_p
);
5239 struct elf_aarch64_local_symbol
*locals
5240 = elf_aarch64_locals (input_bfd
);
5244 int howto_index
= bfd_r_type
- BFD_RELOC_AARCH64_RELOC_START
;
5245 (*_bfd_error_handler
)
5246 (_("%B: Local symbol descriptor table be NULL when applying "
5247 "relocation %s against local symbol"),
5248 input_bfd
, elfNN_aarch64_howto_table
[howto_index
].name
);
5252 off
= symbol_got_offset (input_bfd
, h
, r_symndx
);
5253 base_got
= globals
->root
.sgot
;
5254 bfd_vma got_entry_addr
= (base_got
->output_section
->vma
5255 + base_got
->output_offset
+ off
);
5257 if (!symbol_got_offset_mark_p (input_bfd
, h
, r_symndx
))
5259 bfd_put_64 (output_bfd
, value
, base_got
->contents
+ off
);
5261 if (bfd_link_pic (info
))
5264 Elf_Internal_Rela outrel
;
5266 /* For local symbol, we have done absolute relocation in static
5267 linking stageh. While for share library, we need to update
5268 the content of GOT entry according to the share objects
5269 loading base address. So we need to generate a
5270 R_AARCH64_RELATIVE reloc for dynamic linker. */
5271 s
= globals
->root
.srelgot
;
5275 outrel
.r_offset
= got_entry_addr
;
5276 outrel
.r_info
= ELFNN_R_INFO (0, AARCH64_R (RELATIVE
));
5277 outrel
.r_addend
= value
;
5278 elf_append_rela (output_bfd
, s
, &outrel
);
5281 symbol_got_offset_mark (input_bfd
, h
, r_symndx
);
5284 /* Update the relocation value to GOT entry addr as we have transformed
5285 the direct data access into indirect data access through GOT. */
5286 value
= got_entry_addr
;
5288 if (bfd_r_type
== BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15
5289 || bfd_r_type
== BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14
)
5290 addend
= base_got
->output_section
->vma
+ base_got
->output_offset
;
5292 value
= _bfd_aarch64_elf_resolve_relocation (bfd_r_type
, place
, value
,
5293 addend
, weak_undef_p
);
5298 case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC
:
5299 case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21
:
5300 case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21
:
5301 case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21
:
5302 case BFD_RELOC_AARCH64_TLSIE_LD32_GOTTPREL_LO12_NC
:
5303 case BFD_RELOC_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC
:
5304 case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19
:
5305 case BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC
:
5306 case BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21
:
5307 case BFD_RELOC_AARCH64_TLSLD_ADR_PREL21
:
5308 if (globals
->root
.sgot
== NULL
)
5309 return bfd_reloc_notsupported
;
5311 value
= (symbol_got_offset (input_bfd
, h
, r_symndx
)
5312 + globals
->root
.sgot
->output_section
->vma
5313 + globals
->root
.sgot
->output_offset
);
5315 value
= _bfd_aarch64_elf_resolve_relocation (bfd_r_type
, place
, value
,
5317 *unresolved_reloc_p
= FALSE
;
5320 case BFD_RELOC_AARCH64_TLSLD_ADD_DTPREL_HI12
:
5321 case BFD_RELOC_AARCH64_TLSLD_ADD_DTPREL_LO12
:
5322 case BFD_RELOC_AARCH64_TLSLD_ADD_DTPREL_LO12_NC
:
5323 case BFD_RELOC_AARCH64_TLSLD_LDST16_DTPREL_LO12
:
5324 case BFD_RELOC_AARCH64_TLSLD_LDST16_DTPREL_LO12_NC
:
5325 case BFD_RELOC_AARCH64_TLSLD_LDST32_DTPREL_LO12
:
5326 case BFD_RELOC_AARCH64_TLSLD_LDST32_DTPREL_LO12_NC
:
5327 case BFD_RELOC_AARCH64_TLSLD_LDST64_DTPREL_LO12
:
5328 case BFD_RELOC_AARCH64_TLSLD_LDST64_DTPREL_LO12_NC
:
5329 case BFD_RELOC_AARCH64_TLSLD_LDST8_DTPREL_LO12
:
5330 case BFD_RELOC_AARCH64_TLSLD_LDST8_DTPREL_LO12_NC
:
5331 case BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G0
:
5332 case BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G0_NC
:
5333 case BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G1
:
5334 case BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G1_NC
:
5335 case BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G2
:
5336 value
= _bfd_aarch64_elf_resolve_relocation (bfd_r_type
, place
, value
,
5337 signed_addend
- dtpoff_base (info
),
5341 case BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_HI12
:
5342 case BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_LO12
:
5343 case BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_LO12_NC
:
5344 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0
:
5345 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC
:
5346 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1
:
5347 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1_NC
:
5348 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G2
:
5349 value
= _bfd_aarch64_elf_resolve_relocation (bfd_r_type
, place
, value
,
5350 signed_addend
- tpoff_base (info
),
5352 *unresolved_reloc_p
= FALSE
;
5355 case BFD_RELOC_AARCH64_TLSDESC_ADD
:
5356 case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12_NC
:
5357 case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21
:
5358 case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21
:
5359 case BFD_RELOC_AARCH64_TLSDESC_LD32_LO12_NC
:
5360 case BFD_RELOC_AARCH64_TLSDESC_LD64_LO12_NC
:
5361 case BFD_RELOC_AARCH64_TLSDESC_LDR
:
5362 case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19
:
5363 if (globals
->root
.sgot
== NULL
)
5364 return bfd_reloc_notsupported
;
5365 value
= (symbol_tlsdesc_got_offset (input_bfd
, h
, r_symndx
)
5366 + globals
->root
.sgotplt
->output_section
->vma
5367 + globals
->root
.sgotplt
->output_offset
5368 + globals
->sgotplt_jump_table_size
);
5370 value
= _bfd_aarch64_elf_resolve_relocation (bfd_r_type
, place
, value
,
5372 *unresolved_reloc_p
= FALSE
;
5376 return bfd_reloc_notsupported
;
5380 *saved_addend
= value
;
5382 /* Only apply the final relocation in a sequence. */
5384 return bfd_reloc_continue
;
5386 return _bfd_aarch64_elf_put_addend (input_bfd
, hit_data
, bfd_r_type
,
5390 /* Handle TLS relaxations. Relaxing is possible for symbols that use
5391 R_AARCH64_TLSDESC_ADR_{PAGE, LD64_LO12_NC, ADD_LO12_NC} during a static
5394 Return bfd_reloc_ok if we're done, bfd_reloc_continue if the caller
5395 is to then call final_link_relocate. Return other values in the
5398 static bfd_reloc_status_type
5399 elfNN_aarch64_tls_relax (struct elf_aarch64_link_hash_table
*globals
,
5400 bfd
*input_bfd
, bfd_byte
*contents
,
5401 Elf_Internal_Rela
*rel
, struct elf_link_hash_entry
*h
)
5403 bfd_boolean is_local
= h
== NULL
;
5404 unsigned int r_type
= ELFNN_R_TYPE (rel
->r_info
);
5407 BFD_ASSERT (globals
&& input_bfd
&& contents
&& rel
);
5409 switch (elfNN_aarch64_bfd_reloc_from_type (r_type
))
5411 case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21
:
5412 case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21
:
5415 /* GD->LE relaxation:
5416 adrp x0, :tlsgd:var => movz x0, :tprel_g1:var
5418 adrp x0, :tlsdesc:var => movz x0, :tprel_g1:var
5420 bfd_putl32 (0xd2a00000, contents
+ rel
->r_offset
);
5421 return bfd_reloc_continue
;
5425 /* GD->IE relaxation:
5426 adrp x0, :tlsgd:var => adrp x0, :gottprel:var
5428 adrp x0, :tlsdesc:var => adrp x0, :gottprel:var
5430 return bfd_reloc_continue
;
5433 case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21
:
5437 case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19
:
5440 /* Tiny TLSDESC->LE relaxation:
5441 ldr x1, :tlsdesc:var => movz x0, #:tprel_g1:var
5442 adr x0, :tlsdesc:var => movk x0, #:tprel_g0_nc:var
5446 BFD_ASSERT (ELFNN_R_TYPE (rel
[1].r_info
) == AARCH64_R (TLSDESC_ADR_PREL21
));
5447 BFD_ASSERT (ELFNN_R_TYPE (rel
[2].r_info
) == AARCH64_R (TLSDESC_CALL
));
5449 rel
[1].r_info
= ELFNN_R_INFO (ELFNN_R_SYM (rel
->r_info
),
5450 AARCH64_R (TLSLE_MOVW_TPREL_G0_NC
));
5451 rel
[2].r_info
= ELFNN_R_INFO (STN_UNDEF
, R_AARCH64_NONE
);
5453 bfd_putl32 (0xd2a00000, contents
+ rel
->r_offset
);
5454 bfd_putl32 (0xf2800000, contents
+ rel
->r_offset
+ 4);
5455 bfd_putl32 (INSN_NOP
, contents
+ rel
->r_offset
+ 8);
5456 return bfd_reloc_continue
;
5460 /* Tiny TLSDESC->IE relaxation:
5461 ldr x1, :tlsdesc:var => ldr x0, :gottprel:var
5462 adr x0, :tlsdesc:var => nop
5466 BFD_ASSERT (ELFNN_R_TYPE (rel
[1].r_info
) == AARCH64_R (TLSDESC_ADR_PREL21
));
5467 BFD_ASSERT (ELFNN_R_TYPE (rel
[2].r_info
) == AARCH64_R (TLSDESC_CALL
));
5469 rel
[1].r_info
= ELFNN_R_INFO (STN_UNDEF
, R_AARCH64_NONE
);
5470 rel
[2].r_info
= ELFNN_R_INFO (STN_UNDEF
, R_AARCH64_NONE
);
5472 bfd_putl32 (0x58000000, contents
+ rel
->r_offset
);
5473 bfd_putl32 (INSN_NOP
, contents
+ rel
->r_offset
+ 4);
5474 bfd_putl32 (INSN_NOP
, contents
+ rel
->r_offset
+ 8);
5475 return bfd_reloc_continue
;
5478 case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21
:
5481 /* Tiny GD->LE relaxation:
5482 adr x0, :tlsgd:var => mrs x1, tpidr_el0
5483 bl __tls_get_addr => add x0, x1, #:tprel_hi12:x, lsl #12
5484 nop => add x0, x0, #:tprel_lo12_nc:x
5487 /* First kill the tls_get_addr reloc on the bl instruction. */
5488 BFD_ASSERT (rel
->r_offset
+ 4 == rel
[1].r_offset
);
5490 bfd_putl32 (0xd53bd041, contents
+ rel
->r_offset
+ 0);
5491 bfd_putl32 (0x91400020, contents
+ rel
->r_offset
+ 4);
5492 bfd_putl32 (0x91000000, contents
+ rel
->r_offset
+ 8);
5494 rel
[1].r_info
= ELFNN_R_INFO (ELFNN_R_SYM (rel
->r_info
),
5495 AARCH64_R (TLSLE_ADD_TPREL_LO12_NC
));
5496 rel
[1].r_offset
= rel
->r_offset
+ 8;
5498 /* Move the current relocation to the second instruction in
5501 rel
->r_info
= ELFNN_R_INFO (ELFNN_R_SYM (rel
->r_info
),
5502 AARCH64_R (TLSLE_ADD_TPREL_HI12
));
5503 return bfd_reloc_continue
;
5507 /* Tiny GD->IE relaxation:
5508 adr x0, :tlsgd:var => ldr x0, :gottprel:var
5509 bl __tls_get_addr => mrs x1, tpidr_el0
5510 nop => add x0, x0, x1
5513 /* First kill the tls_get_addr reloc on the bl instruction. */
5514 BFD_ASSERT (rel
->r_offset
+ 4 == rel
[1].r_offset
);
5515 rel
[1].r_info
= ELFNN_R_INFO (STN_UNDEF
, R_AARCH64_NONE
);
5517 bfd_putl32 (0x58000000, contents
+ rel
->r_offset
);
5518 bfd_putl32 (0xd53bd041, contents
+ rel
->r_offset
+ 4);
5519 bfd_putl32 (0x8b000020, contents
+ rel
->r_offset
+ 8);
5520 return bfd_reloc_continue
;
5523 case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19
:
5524 return bfd_reloc_continue
;
5526 case BFD_RELOC_AARCH64_TLSDESC_LDNN_LO12_NC
:
5529 /* GD->LE relaxation:
5530 ldr xd, [x0, #:tlsdesc_lo12:var] => movk x0, :tprel_g0_nc:var
5532 bfd_putl32 (0xf2800000, contents
+ rel
->r_offset
);
5533 return bfd_reloc_continue
;
5537 /* GD->IE relaxation:
5538 ldr xd, [x0, #:tlsdesc_lo12:var] => ldr x0, [x0, #:gottprel_lo12:var]
5540 insn
= bfd_getl32 (contents
+ rel
->r_offset
);
5542 bfd_putl32 (insn
, contents
+ rel
->r_offset
);
5543 return bfd_reloc_continue
;
5546 case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC
:
5549 /* GD->LE relaxation
5550 add x0, #:tlsgd_lo12:var => movk x0, :tprel_g0_nc:var
5551 bl __tls_get_addr => mrs x1, tpidr_el0
5552 nop => add x0, x1, x0
5555 /* First kill the tls_get_addr reloc on the bl instruction. */
5556 BFD_ASSERT (rel
->r_offset
+ 4 == rel
[1].r_offset
);
5557 rel
[1].r_info
= ELFNN_R_INFO (STN_UNDEF
, R_AARCH64_NONE
);
5559 bfd_putl32 (0xf2800000, contents
+ rel
->r_offset
);
5560 bfd_putl32 (0xd53bd041, contents
+ rel
->r_offset
+ 4);
5561 bfd_putl32 (0x8b000020, contents
+ rel
->r_offset
+ 8);
5562 return bfd_reloc_continue
;
5566 /* GD->IE relaxation
5567 ADD x0, #:tlsgd_lo12:var => ldr x0, [x0, #:gottprel_lo12:var]
5568 BL __tls_get_addr => mrs x1, tpidr_el0
5570 NOP => add x0, x1, x0
5573 BFD_ASSERT (ELFNN_R_TYPE (rel
[1].r_info
) == AARCH64_R (CALL26
));
5575 /* Remove the relocation on the BL instruction. */
5576 rel
[1].r_info
= ELFNN_R_INFO (STN_UNDEF
, R_AARCH64_NONE
);
5578 bfd_putl32 (0xf9400000, contents
+ rel
->r_offset
);
5580 /* We choose to fixup the BL and NOP instructions using the
5581 offset from the second relocation to allow flexibility in
5582 scheduling instructions between the ADD and BL. */
5583 bfd_putl32 (0xd53bd041, contents
+ rel
[1].r_offset
);
5584 bfd_putl32 (0x8b000020, contents
+ rel
[1].r_offset
+ 4);
5585 return bfd_reloc_continue
;
5588 case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12_NC
:
5589 case BFD_RELOC_AARCH64_TLSDESC_CALL
:
5590 /* GD->IE/LE relaxation:
5591 add x0, x0, #:tlsdesc_lo12:var => nop
5594 bfd_putl32 (INSN_NOP
, contents
+ rel
->r_offset
);
5595 return bfd_reloc_ok
;
5597 case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21
:
5598 /* IE->LE relaxation:
5599 adrp xd, :gottprel:var => movz xd, :tprel_g1:var
5603 insn
= bfd_getl32 (contents
+ rel
->r_offset
);
5604 bfd_putl32 (0xd2a00000 | (insn
& 0x1f), contents
+ rel
->r_offset
);
5606 return bfd_reloc_continue
;
5608 case BFD_RELOC_AARCH64_TLSIE_LDNN_GOTTPREL_LO12_NC
:
5609 /* IE->LE relaxation:
5610 ldr xd, [xm, #:gottprel_lo12:var] => movk xd, :tprel_g0_nc:var
5614 insn
= bfd_getl32 (contents
+ rel
->r_offset
);
5615 bfd_putl32 (0xf2800000 | (insn
& 0x1f), contents
+ rel
->r_offset
);
5617 return bfd_reloc_continue
;
5620 return bfd_reloc_continue
;
5623 return bfd_reloc_ok
;
5626 /* Relocate an AArch64 ELF section. */
5629 elfNN_aarch64_relocate_section (bfd
*output_bfd
,
5630 struct bfd_link_info
*info
,
5632 asection
*input_section
,
5634 Elf_Internal_Rela
*relocs
,
5635 Elf_Internal_Sym
*local_syms
,
5636 asection
**local_sections
)
5638 Elf_Internal_Shdr
*symtab_hdr
;
5639 struct elf_link_hash_entry
**sym_hashes
;
5640 Elf_Internal_Rela
*rel
;
5641 Elf_Internal_Rela
*relend
;
5643 struct elf_aarch64_link_hash_table
*globals
;
5644 bfd_boolean save_addend
= FALSE
;
5647 globals
= elf_aarch64_hash_table (info
);
5649 symtab_hdr
= &elf_symtab_hdr (input_bfd
);
5650 sym_hashes
= elf_sym_hashes (input_bfd
);
5653 relend
= relocs
+ input_section
->reloc_count
;
5654 for (; rel
< relend
; rel
++)
5656 unsigned int r_type
;
5657 bfd_reloc_code_real_type bfd_r_type
;
5658 bfd_reloc_code_real_type relaxed_bfd_r_type
;
5659 reloc_howto_type
*howto
;
5660 unsigned long r_symndx
;
5661 Elf_Internal_Sym
*sym
;
5663 struct elf_link_hash_entry
*h
;
5665 bfd_reloc_status_type r
;
5668 bfd_boolean unresolved_reloc
= FALSE
;
5669 char *error_message
= NULL
;
5671 r_symndx
= ELFNN_R_SYM (rel
->r_info
);
5672 r_type
= ELFNN_R_TYPE (rel
->r_info
);
5674 bfd_reloc
.howto
= elfNN_aarch64_howto_from_type (r_type
);
5675 howto
= bfd_reloc
.howto
;
5679 (*_bfd_error_handler
)
5680 (_("%B: unrecognized relocation (0x%x) in section `%A'"),
5681 input_bfd
, input_section
, r_type
);
5684 bfd_r_type
= elfNN_aarch64_bfd_reloc_from_howto (howto
);
5690 if (r_symndx
< symtab_hdr
->sh_info
)
5692 sym
= local_syms
+ r_symndx
;
5693 sym_type
= ELFNN_ST_TYPE (sym
->st_info
);
5694 sec
= local_sections
[r_symndx
];
5696 /* An object file might have a reference to a local
5697 undefined symbol. This is a daft object file, but we
5698 should at least do something about it. */
5699 if (r_type
!= R_AARCH64_NONE
&& r_type
!= R_AARCH64_NULL
5700 && bfd_is_und_section (sec
)
5701 && ELF_ST_BIND (sym
->st_info
) != STB_WEAK
)
5703 if (!info
->callbacks
->undefined_symbol
5704 (info
, bfd_elf_string_from_elf_section
5705 (input_bfd
, symtab_hdr
->sh_link
, sym
->st_name
),
5706 input_bfd
, input_section
, rel
->r_offset
, TRUE
))
5710 relocation
= _bfd_elf_rela_local_sym (output_bfd
, sym
, &sec
, rel
);
5712 /* Relocate against local STT_GNU_IFUNC symbol. */
5713 if (!bfd_link_relocatable (info
)
5714 && ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
)
5716 h
= elfNN_aarch64_get_local_sym_hash (globals
, input_bfd
,
5721 /* Set STT_GNU_IFUNC symbol value. */
5722 h
->root
.u
.def
.value
= sym
->st_value
;
5723 h
->root
.u
.def
.section
= sec
;
5728 bfd_boolean warned
, ignored
;
5730 RELOC_FOR_GLOBAL_SYMBOL (info
, input_bfd
, input_section
, rel
,
5731 r_symndx
, symtab_hdr
, sym_hashes
,
5733 unresolved_reloc
, warned
, ignored
);
5738 if (sec
!= NULL
&& discarded_section (sec
))
5739 RELOC_AGAINST_DISCARDED_SECTION (info
, input_bfd
, input_section
,
5740 rel
, 1, relend
, howto
, 0, contents
);
5742 if (bfd_link_relocatable (info
))
5746 name
= h
->root
.root
.string
;
5749 name
= (bfd_elf_string_from_elf_section
5750 (input_bfd
, symtab_hdr
->sh_link
, sym
->st_name
));
5751 if (name
== NULL
|| *name
== '\0')
5752 name
= bfd_section_name (input_bfd
, sec
);
5756 && r_type
!= R_AARCH64_NONE
5757 && r_type
!= R_AARCH64_NULL
5759 || h
->root
.type
== bfd_link_hash_defined
5760 || h
->root
.type
== bfd_link_hash_defweak
)
5761 && IS_AARCH64_TLS_RELOC (bfd_r_type
) != (sym_type
== STT_TLS
))
5763 (*_bfd_error_handler
)
5764 ((sym_type
== STT_TLS
5765 ? _("%B(%A+0x%lx): %s used with TLS symbol %s")
5766 : _("%B(%A+0x%lx): %s used with non-TLS symbol %s")),
5768 input_section
, (long) rel
->r_offset
, howto
->name
, name
);
5771 /* We relax only if we can see that there can be a valid transition
5772 from a reloc type to another.
5773 We call elfNN_aarch64_final_link_relocate unless we're completely
5774 done, i.e., the relaxation produced the final output we want. */
5776 relaxed_bfd_r_type
= aarch64_tls_transition (input_bfd
, info
, r_type
,
5778 if (relaxed_bfd_r_type
!= bfd_r_type
)
5780 bfd_r_type
= relaxed_bfd_r_type
;
5781 howto
= elfNN_aarch64_howto_from_bfd_reloc (bfd_r_type
);
5782 BFD_ASSERT (howto
!= NULL
);
5783 r_type
= howto
->type
;
5784 r
= elfNN_aarch64_tls_relax (globals
, input_bfd
, contents
, rel
, h
);
5785 unresolved_reloc
= 0;
5788 r
= bfd_reloc_continue
;
5790 /* There may be multiple consecutive relocations for the
5791 same offset. In that case we are supposed to treat the
5792 output of each relocation as the addend for the next. */
5793 if (rel
+ 1 < relend
5794 && rel
->r_offset
== rel
[1].r_offset
5795 && ELFNN_R_TYPE (rel
[1].r_info
) != R_AARCH64_NONE
5796 && ELFNN_R_TYPE (rel
[1].r_info
) != R_AARCH64_NULL
)
5799 save_addend
= FALSE
;
5801 if (r
== bfd_reloc_continue
)
5802 r
= elfNN_aarch64_final_link_relocate (howto
, input_bfd
, output_bfd
,
5803 input_section
, contents
, rel
,
5804 relocation
, info
, sec
,
5805 h
, &unresolved_reloc
,
5806 save_addend
, &addend
, sym
);
5808 switch (elfNN_aarch64_bfd_reloc_from_type (r_type
))
5810 case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC
:
5811 case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21
:
5812 case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21
:
5813 case BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC
:
5814 case BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21
:
5815 case BFD_RELOC_AARCH64_TLSLD_ADR_PREL21
:
5816 if (! symbol_got_offset_mark_p (input_bfd
, h
, r_symndx
))
5818 bfd_boolean need_relocs
= FALSE
;
5823 off
= symbol_got_offset (input_bfd
, h
, r_symndx
);
5824 indx
= h
&& h
->dynindx
!= -1 ? h
->dynindx
: 0;
5827 (bfd_link_pic (info
) || indx
!= 0) &&
5829 || ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
5830 || h
->root
.type
!= bfd_link_hash_undefweak
);
5832 BFD_ASSERT (globals
->root
.srelgot
!= NULL
);
5836 Elf_Internal_Rela rela
;
5837 rela
.r_info
= ELFNN_R_INFO (indx
, AARCH64_R (TLS_DTPMOD
));
5839 rela
.r_offset
= globals
->root
.sgot
->output_section
->vma
+
5840 globals
->root
.sgot
->output_offset
+ off
;
5843 loc
= globals
->root
.srelgot
->contents
;
5844 loc
+= globals
->root
.srelgot
->reloc_count
++
5845 * RELOC_SIZE (htab
);
5846 bfd_elfNN_swap_reloca_out (output_bfd
, &rela
, loc
);
5848 bfd_reloc_code_real_type real_type
=
5849 elfNN_aarch64_bfd_reloc_from_type (r_type
);
5851 if (real_type
== BFD_RELOC_AARCH64_TLSLD_ADR_PREL21
5852 || real_type
== BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21
5853 || real_type
== BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC
)
5855 /* For local dynamic, don't generate DTPREL in any case.
5856 Initialize the DTPREL slot into zero, so we get module
5857 base address when invoke runtime TLS resolver. */
5858 bfd_put_NN (output_bfd
, 0,
5859 globals
->root
.sgot
->contents
+ off
5864 bfd_put_NN (output_bfd
,
5865 relocation
- dtpoff_base (info
),
5866 globals
->root
.sgot
->contents
+ off
5871 /* This TLS symbol is global. We emit a
5872 relocation to fixup the tls offset at load
5875 ELFNN_R_INFO (indx
, AARCH64_R (TLS_DTPREL
));
5878 (globals
->root
.sgot
->output_section
->vma
5879 + globals
->root
.sgot
->output_offset
+ off
5882 loc
= globals
->root
.srelgot
->contents
;
5883 loc
+= globals
->root
.srelgot
->reloc_count
++
5884 * RELOC_SIZE (globals
);
5885 bfd_elfNN_swap_reloca_out (output_bfd
, &rela
, loc
);
5886 bfd_put_NN (output_bfd
, (bfd_vma
) 0,
5887 globals
->root
.sgot
->contents
+ off
5893 bfd_put_NN (output_bfd
, (bfd_vma
) 1,
5894 globals
->root
.sgot
->contents
+ off
);
5895 bfd_put_NN (output_bfd
,
5896 relocation
- dtpoff_base (info
),
5897 globals
->root
.sgot
->contents
+ off
5901 symbol_got_offset_mark (input_bfd
, h
, r_symndx
);
5905 case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21
:
5906 case BFD_RELOC_AARCH64_TLSIE_LDNN_GOTTPREL_LO12_NC
:
5907 case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19
:
5908 if (! symbol_got_offset_mark_p (input_bfd
, h
, r_symndx
))
5910 bfd_boolean need_relocs
= FALSE
;
5915 off
= symbol_got_offset (input_bfd
, h
, r_symndx
);
5917 indx
= h
&& h
->dynindx
!= -1 ? h
->dynindx
: 0;
5920 (bfd_link_pic (info
) || indx
!= 0) &&
5922 || ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
5923 || h
->root
.type
!= bfd_link_hash_undefweak
);
5925 BFD_ASSERT (globals
->root
.srelgot
!= NULL
);
5929 Elf_Internal_Rela rela
;
5932 rela
.r_addend
= relocation
- dtpoff_base (info
);
5936 rela
.r_info
= ELFNN_R_INFO (indx
, AARCH64_R (TLS_TPREL
));
5937 rela
.r_offset
= globals
->root
.sgot
->output_section
->vma
+
5938 globals
->root
.sgot
->output_offset
+ off
;
5940 loc
= globals
->root
.srelgot
->contents
;
5941 loc
+= globals
->root
.srelgot
->reloc_count
++
5942 * RELOC_SIZE (htab
);
5944 bfd_elfNN_swap_reloca_out (output_bfd
, &rela
, loc
);
5946 bfd_put_NN (output_bfd
, rela
.r_addend
,
5947 globals
->root
.sgot
->contents
+ off
);
5950 bfd_put_NN (output_bfd
, relocation
- tpoff_base (info
),
5951 globals
->root
.sgot
->contents
+ off
);
5953 symbol_got_offset_mark (input_bfd
, h
, r_symndx
);
5957 case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12_NC
:
5958 case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21
:
5959 case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21
:
5960 case BFD_RELOC_AARCH64_TLSDESC_LDNN_LO12_NC
:
5961 case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19
:
5962 if (! symbol_tlsdesc_got_offset_mark_p (input_bfd
, h
, r_symndx
))
5964 bfd_boolean need_relocs
= FALSE
;
5965 int indx
= h
&& h
->dynindx
!= -1 ? h
->dynindx
: 0;
5966 bfd_vma off
= symbol_tlsdesc_got_offset (input_bfd
, h
, r_symndx
);
5968 need_relocs
= (h
== NULL
5969 || ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
5970 || h
->root
.type
!= bfd_link_hash_undefweak
);
5972 BFD_ASSERT (globals
->root
.srelgot
!= NULL
);
5973 BFD_ASSERT (globals
->root
.sgot
!= NULL
);
5978 Elf_Internal_Rela rela
;
5979 rela
.r_info
= ELFNN_R_INFO (indx
, AARCH64_R (TLSDESC
));
5982 rela
.r_offset
= (globals
->root
.sgotplt
->output_section
->vma
5983 + globals
->root
.sgotplt
->output_offset
5984 + off
+ globals
->sgotplt_jump_table_size
);
5987 rela
.r_addend
= relocation
- dtpoff_base (info
);
5989 /* Allocate the next available slot in the PLT reloc
5990 section to hold our R_AARCH64_TLSDESC, the next
5991 available slot is determined from reloc_count,
5992 which we step. But note, reloc_count was
5993 artifically moved down while allocating slots for
5994 real PLT relocs such that all of the PLT relocs
5995 will fit above the initial reloc_count and the
5996 extra stuff will fit below. */
5997 loc
= globals
->root
.srelplt
->contents
;
5998 loc
+= globals
->root
.srelplt
->reloc_count
++
5999 * RELOC_SIZE (globals
);
6001 bfd_elfNN_swap_reloca_out (output_bfd
, &rela
, loc
);
6003 bfd_put_NN (output_bfd
, (bfd_vma
) 0,
6004 globals
->root
.sgotplt
->contents
+ off
+
6005 globals
->sgotplt_jump_table_size
);
6006 bfd_put_NN (output_bfd
, (bfd_vma
) 0,
6007 globals
->root
.sgotplt
->contents
+ off
+
6008 globals
->sgotplt_jump_table_size
+
6012 symbol_tlsdesc_got_offset_mark (input_bfd
, h
, r_symndx
);
6023 /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
6024 because such sections are not SEC_ALLOC and thus ld.so will
6025 not process them. */
6026 if (unresolved_reloc
6027 && !((input_section
->flags
& SEC_DEBUGGING
) != 0
6029 && _bfd_elf_section_offset (output_bfd
, info
, input_section
,
6030 +rel
->r_offset
) != (bfd_vma
) - 1)
6032 (*_bfd_error_handler
)
6034 ("%B(%A+0x%lx): unresolvable %s relocation against symbol `%s'"),
6035 input_bfd
, input_section
, (long) rel
->r_offset
, howto
->name
,
6036 h
->root
.root
.string
);
6040 if (r
!= bfd_reloc_ok
&& r
!= bfd_reloc_continue
)
6042 bfd_reloc_code_real_type real_r_type
6043 = elfNN_aarch64_bfd_reloc_from_type (r_type
);
6047 case bfd_reloc_overflow
:
6048 if (!(*info
->callbacks
->reloc_overflow
)
6049 (info
, (h
? &h
->root
: NULL
), name
, howto
->name
, (bfd_vma
) 0,
6050 input_bfd
, input_section
, rel
->r_offset
))
6052 if (real_r_type
== BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15
6053 || real_r_type
== BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14
)
6055 (*info
->callbacks
->warning
)
6057 _("Too many GOT entries for -fpic, "
6058 "please recompile with -fPIC"),
6059 name
, input_bfd
, input_section
, rel
->r_offset
);
6064 case bfd_reloc_undefined
:
6065 if (!((*info
->callbacks
->undefined_symbol
)
6066 (info
, name
, input_bfd
, input_section
,
6067 rel
->r_offset
, TRUE
)))
6071 case bfd_reloc_outofrange
:
6072 error_message
= _("out of range");
6075 case bfd_reloc_notsupported
:
6076 error_message
= _("unsupported relocation");
6079 case bfd_reloc_dangerous
:
6080 /* error_message should already be set. */
6084 error_message
= _("unknown error");
6088 BFD_ASSERT (error_message
!= NULL
);
6089 if (!((*info
->callbacks
->reloc_dangerous
)
6090 (info
, error_message
, input_bfd
, input_section
,
6101 /* Set the right machine number. */
6104 elfNN_aarch64_object_p (bfd
*abfd
)
6107 bfd_default_set_arch_mach (abfd
, bfd_arch_aarch64
, bfd_mach_aarch64_ilp32
);
6109 bfd_default_set_arch_mach (abfd
, bfd_arch_aarch64
, bfd_mach_aarch64
);
6114 /* Function to keep AArch64 specific flags in the ELF header. */
6117 elfNN_aarch64_set_private_flags (bfd
*abfd
, flagword flags
)
6119 if (elf_flags_init (abfd
) && elf_elfheader (abfd
)->e_flags
!= flags
)
6124 elf_elfheader (abfd
)->e_flags
= flags
;
6125 elf_flags_init (abfd
) = TRUE
;
6131 /* Merge backend specific data from an object file to the output
6132 object file when linking. */
6135 elfNN_aarch64_merge_private_bfd_data (bfd
*ibfd
, bfd
*obfd
)
6139 bfd_boolean flags_compatible
= TRUE
;
6142 /* Check if we have the same endianess. */
6143 if (!_bfd_generic_verify_endian_match (ibfd
, obfd
))
6146 if (!is_aarch64_elf (ibfd
) || !is_aarch64_elf (obfd
))
6149 /* The input BFD must have had its flags initialised. */
6150 /* The following seems bogus to me -- The flags are initialized in
6151 the assembler but I don't think an elf_flags_init field is
6152 written into the object. */
6153 /* BFD_ASSERT (elf_flags_init (ibfd)); */
6155 in_flags
= elf_elfheader (ibfd
)->e_flags
;
6156 out_flags
= elf_elfheader (obfd
)->e_flags
;
6158 if (!elf_flags_init (obfd
))
6160 /* If the input is the default architecture and had the default
6161 flags then do not bother setting the flags for the output
6162 architecture, instead allow future merges to do this. If no
6163 future merges ever set these flags then they will retain their
6164 uninitialised values, which surprise surprise, correspond
6165 to the default values. */
6166 if (bfd_get_arch_info (ibfd
)->the_default
6167 && elf_elfheader (ibfd
)->e_flags
== 0)
6170 elf_flags_init (obfd
) = TRUE
;
6171 elf_elfheader (obfd
)->e_flags
= in_flags
;
6173 if (bfd_get_arch (obfd
) == bfd_get_arch (ibfd
)
6174 && bfd_get_arch_info (obfd
)->the_default
)
6175 return bfd_set_arch_mach (obfd
, bfd_get_arch (ibfd
),
6176 bfd_get_mach (ibfd
));
6181 /* Identical flags must be compatible. */
6182 if (in_flags
== out_flags
)
6185 /* Check to see if the input BFD actually contains any sections. If
6186 not, its flags may not have been initialised either, but it
6187 cannot actually cause any incompatiblity. Do not short-circuit
6188 dynamic objects; their section list may be emptied by
6189 elf_link_add_object_symbols.
6191 Also check to see if there are no code sections in the input.
6192 In this case there is no need to check for code specific flags.
6193 XXX - do we need to worry about floating-point format compatability
6194 in data sections ? */
6195 if (!(ibfd
->flags
& DYNAMIC
))
6197 bfd_boolean null_input_bfd
= TRUE
;
6198 bfd_boolean only_data_sections
= TRUE
;
6200 for (sec
= ibfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
6202 if ((bfd_get_section_flags (ibfd
, sec
)
6203 & (SEC_LOAD
| SEC_CODE
| SEC_HAS_CONTENTS
))
6204 == (SEC_LOAD
| SEC_CODE
| SEC_HAS_CONTENTS
))
6205 only_data_sections
= FALSE
;
6207 null_input_bfd
= FALSE
;
6211 if (null_input_bfd
|| only_data_sections
)
6215 return flags_compatible
;
6218 /* Display the flags field. */
6221 elfNN_aarch64_print_private_bfd_data (bfd
*abfd
, void *ptr
)
6223 FILE *file
= (FILE *) ptr
;
6224 unsigned long flags
;
6226 BFD_ASSERT (abfd
!= NULL
&& ptr
!= NULL
);
6228 /* Print normal ELF private data. */
6229 _bfd_elf_print_private_bfd_data (abfd
, ptr
);
6231 flags
= elf_elfheader (abfd
)->e_flags
;
6232 /* Ignore init flag - it may not be set, despite the flags field
6233 containing valid data. */
6235 /* xgettext:c-format */
6236 fprintf (file
, _("private flags = %lx:"), elf_elfheader (abfd
)->e_flags
);
6239 fprintf (file
, _("<Unrecognised flag bits set>"));
6246 /* Update the got entry reference counts for the section being removed. */
6249 elfNN_aarch64_gc_sweep_hook (bfd
*abfd
,
6250 struct bfd_link_info
*info
,
6252 const Elf_Internal_Rela
* relocs
)
6254 struct elf_aarch64_link_hash_table
*htab
;
6255 Elf_Internal_Shdr
*symtab_hdr
;
6256 struct elf_link_hash_entry
**sym_hashes
;
6257 struct elf_aarch64_local_symbol
*locals
;
6258 const Elf_Internal_Rela
*rel
, *relend
;
6260 if (bfd_link_relocatable (info
))
6263 htab
= elf_aarch64_hash_table (info
);
6268 elf_section_data (sec
)->local_dynrel
= NULL
;
6270 symtab_hdr
= &elf_symtab_hdr (abfd
);
6271 sym_hashes
= elf_sym_hashes (abfd
);
6273 locals
= elf_aarch64_locals (abfd
);
6275 relend
= relocs
+ sec
->reloc_count
;
6276 for (rel
= relocs
; rel
< relend
; rel
++)
6278 unsigned long r_symndx
;
6279 unsigned int r_type
;
6280 struct elf_link_hash_entry
*h
= NULL
;
6282 r_symndx
= ELFNN_R_SYM (rel
->r_info
);
6284 if (r_symndx
>= symtab_hdr
->sh_info
)
6287 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
6288 while (h
->root
.type
== bfd_link_hash_indirect
6289 || h
->root
.type
== bfd_link_hash_warning
)
6290 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
6294 Elf_Internal_Sym
*isym
;
6296 /* A local symbol. */
6297 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
6300 /* Check relocation against local STT_GNU_IFUNC symbol. */
6302 && ELF_ST_TYPE (isym
->st_info
) == STT_GNU_IFUNC
)
6304 h
= elfNN_aarch64_get_local_sym_hash (htab
, abfd
, rel
, FALSE
);
6312 struct elf_aarch64_link_hash_entry
*eh
;
6313 struct elf_dyn_relocs
**pp
;
6314 struct elf_dyn_relocs
*p
;
6316 eh
= (struct elf_aarch64_link_hash_entry
*) h
;
6318 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; pp
= &p
->next
)
6321 /* Everything must go for SEC. */
6327 r_type
= ELFNN_R_TYPE (rel
->r_info
);
6328 switch (aarch64_tls_transition (abfd
,info
, r_type
, h
,r_symndx
))
6330 case BFD_RELOC_AARCH64_ADR_GOT_PAGE
:
6331 case BFD_RELOC_AARCH64_GOT_LD_PREL19
:
6332 case BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14
:
6333 case BFD_RELOC_AARCH64_LD32_GOT_LO12_NC
:
6334 case BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15
:
6335 case BFD_RELOC_AARCH64_LD64_GOT_LO12_NC
:
6336 case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12_NC
:
6337 case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21
:
6338 case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21
:
6339 case BFD_RELOC_AARCH64_TLSDESC_LD32_LO12_NC
:
6340 case BFD_RELOC_AARCH64_TLSDESC_LD64_LO12_NC
:
6341 case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19
:
6342 case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC
:
6343 case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21
:
6344 case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21
:
6345 case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21
:
6346 case BFD_RELOC_AARCH64_TLSIE_LD32_GOTTPREL_LO12_NC
:
6347 case BFD_RELOC_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC
:
6348 case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19
:
6349 case BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC
:
6350 case BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21
:
6351 case BFD_RELOC_AARCH64_TLSLD_ADR_PREL21
:
6354 if (h
->got
.refcount
> 0)
6355 h
->got
.refcount
-= 1;
6357 if (h
->type
== STT_GNU_IFUNC
)
6359 if (h
->plt
.refcount
> 0)
6360 h
->plt
.refcount
-= 1;
6363 else if (locals
!= NULL
)
6365 if (locals
[r_symndx
].got_refcount
> 0)
6366 locals
[r_symndx
].got_refcount
-= 1;
6370 case BFD_RELOC_AARCH64_CALL26
:
6371 case BFD_RELOC_AARCH64_JUMP26
:
6372 /* If this is a local symbol then we resolve it
6373 directly without creating a PLT entry. */
6377 if (h
->plt
.refcount
> 0)
6378 h
->plt
.refcount
-= 1;
6381 case BFD_RELOC_AARCH64_ADR_HI21_NC_PCREL
:
6382 case BFD_RELOC_AARCH64_ADR_HI21_PCREL
:
6383 case BFD_RELOC_AARCH64_ADR_LO21_PCREL
:
6384 case BFD_RELOC_AARCH64_MOVW_G0_NC
:
6385 case BFD_RELOC_AARCH64_MOVW_G1_NC
:
6386 case BFD_RELOC_AARCH64_MOVW_G2_NC
:
6387 case BFD_RELOC_AARCH64_MOVW_G3
:
6388 case BFD_RELOC_AARCH64_NN
:
6389 if (h
!= NULL
&& bfd_link_executable (info
))
6391 if (h
->plt
.refcount
> 0)
6392 h
->plt
.refcount
-= 1;
6404 /* Adjust a symbol defined by a dynamic object and referenced by a
6405 regular object. The current definition is in some section of the
6406 dynamic object, but we're not including those sections. We have to
6407 change the definition to something the rest of the link can
6411 elfNN_aarch64_adjust_dynamic_symbol (struct bfd_link_info
*info
,
6412 struct elf_link_hash_entry
*h
)
6414 struct elf_aarch64_link_hash_table
*htab
;
6417 /* If this is a function, put it in the procedure linkage table. We
6418 will fill in the contents of the procedure linkage table later,
6419 when we know the address of the .got section. */
6420 if (h
->type
== STT_FUNC
|| h
->type
== STT_GNU_IFUNC
|| h
->needs_plt
)
6422 if (h
->plt
.refcount
<= 0
6423 || (h
->type
!= STT_GNU_IFUNC
6424 && (SYMBOL_CALLS_LOCAL (info
, h
)
6425 || (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
6426 && h
->root
.type
== bfd_link_hash_undefweak
))))
6428 /* This case can occur if we saw a CALL26 reloc in
6429 an input file, but the symbol wasn't referred to
6430 by a dynamic object or all references were
6431 garbage collected. In which case we can end up
6433 h
->plt
.offset
= (bfd_vma
) - 1;
6440 /* Otherwise, reset to -1. */
6441 h
->plt
.offset
= (bfd_vma
) - 1;
6444 /* If this is a weak symbol, and there is a real definition, the
6445 processor independent code will have arranged for us to see the
6446 real definition first, and we can just use the same value. */
6447 if (h
->u
.weakdef
!= NULL
)
6449 BFD_ASSERT (h
->u
.weakdef
->root
.type
== bfd_link_hash_defined
6450 || h
->u
.weakdef
->root
.type
== bfd_link_hash_defweak
);
6451 h
->root
.u
.def
.section
= h
->u
.weakdef
->root
.u
.def
.section
;
6452 h
->root
.u
.def
.value
= h
->u
.weakdef
->root
.u
.def
.value
;
6453 if (ELIMINATE_COPY_RELOCS
|| info
->nocopyreloc
)
6454 h
->non_got_ref
= h
->u
.weakdef
->non_got_ref
;
6458 /* If we are creating a shared library, we must presume that the
6459 only references to the symbol are via the global offset table.
6460 For such cases we need not do anything here; the relocations will
6461 be handled correctly by relocate_section. */
6462 if (bfd_link_pic (info
))
6465 /* If there are no references to this symbol that do not use the
6466 GOT, we don't need to generate a copy reloc. */
6467 if (!h
->non_got_ref
)
6470 /* If -z nocopyreloc was given, we won't generate them either. */
6471 if (info
->nocopyreloc
)
6477 /* We must allocate the symbol in our .dynbss section, which will
6478 become part of the .bss section of the executable. There will be
6479 an entry for this symbol in the .dynsym section. The dynamic
6480 object will contain position independent code, so all references
6481 from the dynamic object to this symbol will go through the global
6482 offset table. The dynamic linker will use the .dynsym entry to
6483 determine the address it must put in the global offset table, so
6484 both the dynamic object and the regular object will refer to the
6485 same memory location for the variable. */
6487 htab
= elf_aarch64_hash_table (info
);
6489 /* We must generate a R_AARCH64_COPY reloc to tell the dynamic linker
6490 to copy the initial value out of the dynamic object and into the
6491 runtime process image. */
6492 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0 && h
->size
!= 0)
6494 htab
->srelbss
->size
+= RELOC_SIZE (htab
);
6500 return _bfd_elf_adjust_dynamic_copy (info
, h
, s
);
6505 elfNN_aarch64_allocate_local_symbols (bfd
*abfd
, unsigned number
)
6507 struct elf_aarch64_local_symbol
*locals
;
6508 locals
= elf_aarch64_locals (abfd
);
6511 locals
= (struct elf_aarch64_local_symbol
*)
6512 bfd_zalloc (abfd
, number
* sizeof (struct elf_aarch64_local_symbol
));
6515 elf_aarch64_locals (abfd
) = locals
;
6520 /* Create the .got section to hold the global offset table. */
6523 aarch64_elf_create_got_section (bfd
*abfd
, struct bfd_link_info
*info
)
6525 const struct elf_backend_data
*bed
= get_elf_backend_data (abfd
);
6528 struct elf_link_hash_entry
*h
;
6529 struct elf_link_hash_table
*htab
= elf_hash_table (info
);
6531 /* This function may be called more than once. */
6532 s
= bfd_get_linker_section (abfd
, ".got");
6536 flags
= bed
->dynamic_sec_flags
;
6538 s
= bfd_make_section_anyway_with_flags (abfd
,
6539 (bed
->rela_plts_and_copies_p
6540 ? ".rela.got" : ".rel.got"),
6541 (bed
->dynamic_sec_flags
6544 || ! bfd_set_section_alignment (abfd
, s
, bed
->s
->log_file_align
))
6548 s
= bfd_make_section_anyway_with_flags (abfd
, ".got", flags
);
6550 || !bfd_set_section_alignment (abfd
, s
, bed
->s
->log_file_align
))
6553 htab
->sgot
->size
+= GOT_ENTRY_SIZE
;
6555 if (bed
->want_got_sym
)
6557 /* Define the symbol _GLOBAL_OFFSET_TABLE_ at the start of the .got
6558 (or .got.plt) section. We don't do this in the linker script
6559 because we don't want to define the symbol if we are not creating
6560 a global offset table. */
6561 h
= _bfd_elf_define_linkage_sym (abfd
, info
, s
,
6562 "_GLOBAL_OFFSET_TABLE_");
6563 elf_hash_table (info
)->hgot
= h
;
6568 if (bed
->want_got_plt
)
6570 s
= bfd_make_section_anyway_with_flags (abfd
, ".got.plt", flags
);
6572 || !bfd_set_section_alignment (abfd
, s
,
6573 bed
->s
->log_file_align
))
6578 /* The first bit of the global offset table is the header. */
6579 s
->size
+= bed
->got_header_size
;
6584 /* Look through the relocs for a section during the first phase. */
6587 elfNN_aarch64_check_relocs (bfd
*abfd
, struct bfd_link_info
*info
,
6588 asection
*sec
, const Elf_Internal_Rela
*relocs
)
6590 Elf_Internal_Shdr
*symtab_hdr
;
6591 struct elf_link_hash_entry
**sym_hashes
;
6592 const Elf_Internal_Rela
*rel
;
6593 const Elf_Internal_Rela
*rel_end
;
6596 struct elf_aarch64_link_hash_table
*htab
;
6598 if (bfd_link_relocatable (info
))
6601 BFD_ASSERT (is_aarch64_elf (abfd
));
6603 htab
= elf_aarch64_hash_table (info
);
6606 symtab_hdr
= &elf_symtab_hdr (abfd
);
6607 sym_hashes
= elf_sym_hashes (abfd
);
6609 rel_end
= relocs
+ sec
->reloc_count
;
6610 for (rel
= relocs
; rel
< rel_end
; rel
++)
6612 struct elf_link_hash_entry
*h
;
6613 unsigned long r_symndx
;
6614 unsigned int r_type
;
6615 bfd_reloc_code_real_type bfd_r_type
;
6616 Elf_Internal_Sym
*isym
;
6618 r_symndx
= ELFNN_R_SYM (rel
->r_info
);
6619 r_type
= ELFNN_R_TYPE (rel
->r_info
);
6621 if (r_symndx
>= NUM_SHDR_ENTRIES (symtab_hdr
))
6623 (*_bfd_error_handler
) (_("%B: bad symbol index: %d"), abfd
,
6628 if (r_symndx
< symtab_hdr
->sh_info
)
6630 /* A local symbol. */
6631 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
6636 /* Check relocation against local STT_GNU_IFUNC symbol. */
6637 if (ELF_ST_TYPE (isym
->st_info
) == STT_GNU_IFUNC
)
6639 h
= elfNN_aarch64_get_local_sym_hash (htab
, abfd
, rel
,
6644 /* Fake a STT_GNU_IFUNC symbol. */
6645 h
->type
= STT_GNU_IFUNC
;
6648 h
->forced_local
= 1;
6649 h
->root
.type
= bfd_link_hash_defined
;
6656 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
6657 while (h
->root
.type
== bfd_link_hash_indirect
6658 || h
->root
.type
== bfd_link_hash_warning
)
6659 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
6661 /* PR15323, ref flags aren't set for references in the same
6663 h
->root
.non_ir_ref
= 1;
6666 /* Could be done earlier, if h were already available. */
6667 bfd_r_type
= aarch64_tls_transition (abfd
, info
, r_type
, h
, r_symndx
);
6671 /* Create the ifunc sections for static executables. If we
6672 never see an indirect function symbol nor we are building
6673 a static executable, those sections will be empty and
6674 won't appear in output. */
6680 case BFD_RELOC_AARCH64_ADD_LO12
:
6681 case BFD_RELOC_AARCH64_ADR_GOT_PAGE
:
6682 case BFD_RELOC_AARCH64_ADR_HI21_PCREL
:
6683 case BFD_RELOC_AARCH64_CALL26
:
6684 case BFD_RELOC_AARCH64_GOT_LD_PREL19
:
6685 case BFD_RELOC_AARCH64_JUMP26
:
6686 case BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14
:
6687 case BFD_RELOC_AARCH64_LD32_GOT_LO12_NC
:
6688 case BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15
:
6689 case BFD_RELOC_AARCH64_LD64_GOT_LO12_NC
:
6690 case BFD_RELOC_AARCH64_NN
:
6691 if (htab
->root
.dynobj
== NULL
)
6692 htab
->root
.dynobj
= abfd
;
6693 if (!_bfd_elf_create_ifunc_sections (htab
->root
.dynobj
, info
))
6698 /* It is referenced by a non-shared object. */
6700 h
->root
.non_ir_ref
= 1;
6705 case BFD_RELOC_AARCH64_NN
:
6707 /* We don't need to handle relocs into sections not going into
6708 the "real" output. */
6709 if ((sec
->flags
& SEC_ALLOC
) == 0)
6714 if (!bfd_link_pic (info
))
6717 h
->plt
.refcount
+= 1;
6718 h
->pointer_equality_needed
= 1;
6721 /* No need to do anything if we're not creating a shared
6723 if (! bfd_link_pic (info
))
6727 struct elf_dyn_relocs
*p
;
6728 struct elf_dyn_relocs
**head
;
6730 /* We must copy these reloc types into the output file.
6731 Create a reloc section in dynobj and make room for
6735 if (htab
->root
.dynobj
== NULL
)
6736 htab
->root
.dynobj
= abfd
;
6738 sreloc
= _bfd_elf_make_dynamic_reloc_section
6739 (sec
, htab
->root
.dynobj
, LOG_FILE_ALIGN
, abfd
, /*rela? */ TRUE
);
6745 /* If this is a global symbol, we count the number of
6746 relocations we need for this symbol. */
6749 struct elf_aarch64_link_hash_entry
*eh
;
6750 eh
= (struct elf_aarch64_link_hash_entry
*) h
;
6751 head
= &eh
->dyn_relocs
;
6755 /* Track dynamic relocs needed for local syms too.
6756 We really need local syms available to do this
6762 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
6767 s
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
6771 /* Beware of type punned pointers vs strict aliasing
6773 vpp
= &(elf_section_data (s
)->local_dynrel
);
6774 head
= (struct elf_dyn_relocs
**) vpp
;
6778 if (p
== NULL
|| p
->sec
!= sec
)
6780 bfd_size_type amt
= sizeof *p
;
6781 p
= ((struct elf_dyn_relocs
*)
6782 bfd_zalloc (htab
->root
.dynobj
, amt
));
6795 /* RR: We probably want to keep a consistency check that
6796 there are no dangling GOT_PAGE relocs. */
6797 case BFD_RELOC_AARCH64_ADR_GOT_PAGE
:
6798 case BFD_RELOC_AARCH64_GOT_LD_PREL19
:
6799 case BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14
:
6800 case BFD_RELOC_AARCH64_LD32_GOT_LO12_NC
:
6801 case BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15
:
6802 case BFD_RELOC_AARCH64_LD64_GOT_LO12_NC
:
6803 case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12_NC
:
6804 case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21
:
6805 case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21
:
6806 case BFD_RELOC_AARCH64_TLSDESC_LD32_LO12_NC
:
6807 case BFD_RELOC_AARCH64_TLSDESC_LD64_LO12_NC
:
6808 case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19
:
6809 case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC
:
6810 case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21
:
6811 case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21
:
6812 case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21
:
6813 case BFD_RELOC_AARCH64_TLSIE_LD32_GOTTPREL_LO12_NC
:
6814 case BFD_RELOC_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC
:
6815 case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19
:
6816 case BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC
:
6817 case BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21
:
6818 case BFD_RELOC_AARCH64_TLSLD_ADR_PREL21
:
6821 unsigned old_got_type
;
6823 got_type
= aarch64_reloc_got_type (bfd_r_type
);
6827 h
->got
.refcount
+= 1;
6828 old_got_type
= elf_aarch64_hash_entry (h
)->got_type
;
6832 struct elf_aarch64_local_symbol
*locals
;
6834 if (!elfNN_aarch64_allocate_local_symbols
6835 (abfd
, symtab_hdr
->sh_info
))
6838 locals
= elf_aarch64_locals (abfd
);
6839 BFD_ASSERT (r_symndx
< symtab_hdr
->sh_info
);
6840 locals
[r_symndx
].got_refcount
+= 1;
6841 old_got_type
= locals
[r_symndx
].got_type
;
6844 /* If a variable is accessed with both general dynamic TLS
6845 methods, two slots may be created. */
6846 if (GOT_TLS_GD_ANY_P (old_got_type
) && GOT_TLS_GD_ANY_P (got_type
))
6847 got_type
|= old_got_type
;
6849 /* We will already have issued an error message if there
6850 is a TLS/non-TLS mismatch, based on the symbol type.
6851 So just combine any TLS types needed. */
6852 if (old_got_type
!= GOT_UNKNOWN
&& old_got_type
!= GOT_NORMAL
6853 && got_type
!= GOT_NORMAL
)
6854 got_type
|= old_got_type
;
6856 /* If the symbol is accessed by both IE and GD methods, we
6857 are able to relax. Turn off the GD flag, without
6858 messing up with any other kind of TLS types that may be
6860 if ((got_type
& GOT_TLS_IE
) && GOT_TLS_GD_ANY_P (got_type
))
6861 got_type
&= ~ (GOT_TLSDESC_GD
| GOT_TLS_GD
);
6863 if (old_got_type
!= got_type
)
6866 elf_aarch64_hash_entry (h
)->got_type
= got_type
;
6869 struct elf_aarch64_local_symbol
*locals
;
6870 locals
= elf_aarch64_locals (abfd
);
6871 BFD_ASSERT (r_symndx
< symtab_hdr
->sh_info
);
6872 locals
[r_symndx
].got_type
= got_type
;
6876 if (htab
->root
.dynobj
== NULL
)
6877 htab
->root
.dynobj
= abfd
;
6878 if (! aarch64_elf_create_got_section (htab
->root
.dynobj
, info
))
6883 case BFD_RELOC_AARCH64_MOVW_G0_NC
:
6884 case BFD_RELOC_AARCH64_MOVW_G1_NC
:
6885 case BFD_RELOC_AARCH64_MOVW_G2_NC
:
6886 case BFD_RELOC_AARCH64_MOVW_G3
:
6887 if (bfd_link_pic (info
))
6889 int howto_index
= bfd_r_type
- BFD_RELOC_AARCH64_RELOC_START
;
6890 (*_bfd_error_handler
)
6891 (_("%B: relocation %s against `%s' can not be used when making "
6892 "a shared object; recompile with -fPIC"),
6893 abfd
, elfNN_aarch64_howto_table
[howto_index
].name
,
6894 (h
) ? h
->root
.root
.string
: "a local symbol");
6895 bfd_set_error (bfd_error_bad_value
);
6899 case BFD_RELOC_AARCH64_ADR_HI21_NC_PCREL
:
6900 case BFD_RELOC_AARCH64_ADR_HI21_PCREL
:
6901 case BFD_RELOC_AARCH64_ADR_LO21_PCREL
:
6902 if (h
!= NULL
&& bfd_link_executable (info
))
6904 /* If this reloc is in a read-only section, we might
6905 need a copy reloc. We can't check reliably at this
6906 stage whether the section is read-only, as input
6907 sections have not yet been mapped to output sections.
6908 Tentatively set the flag for now, and correct in
6909 adjust_dynamic_symbol. */
6911 h
->plt
.refcount
+= 1;
6912 h
->pointer_equality_needed
= 1;
6914 /* FIXME:: RR need to handle these in shared libraries
6915 and essentially bomb out as these being non-PIC
6916 relocations in shared libraries. */
6919 case BFD_RELOC_AARCH64_CALL26
:
6920 case BFD_RELOC_AARCH64_JUMP26
:
6921 /* If this is a local symbol then we resolve it
6922 directly without creating a PLT entry. */
6927 if (h
->plt
.refcount
<= 0)
6928 h
->plt
.refcount
= 1;
6930 h
->plt
.refcount
+= 1;
6941 /* Treat mapping symbols as special target symbols. */
6944 elfNN_aarch64_is_target_special_symbol (bfd
*abfd ATTRIBUTE_UNUSED
,
6947 return bfd_is_aarch64_special_symbol_name (sym
->name
,
6948 BFD_AARCH64_SPECIAL_SYM_TYPE_ANY
);
6951 /* This is a copy of elf_find_function () from elf.c except that
6952 AArch64 mapping symbols are ignored when looking for function names. */
6955 aarch64_elf_find_function (bfd
*abfd ATTRIBUTE_UNUSED
,
6959 const char **filename_ptr
,
6960 const char **functionname_ptr
)
6962 const char *filename
= NULL
;
6963 asymbol
*func
= NULL
;
6964 bfd_vma low_func
= 0;
6967 for (p
= symbols
; *p
!= NULL
; p
++)
6971 q
= (elf_symbol_type
*) * p
;
6973 switch (ELF_ST_TYPE (q
->internal_elf_sym
.st_info
))
6978 filename
= bfd_asymbol_name (&q
->symbol
);
6982 /* Skip mapping symbols. */
6983 if ((q
->symbol
.flags
& BSF_LOCAL
)
6984 && (bfd_is_aarch64_special_symbol_name
6985 (q
->symbol
.name
, BFD_AARCH64_SPECIAL_SYM_TYPE_ANY
)))
6988 if (bfd_get_section (&q
->symbol
) == section
6989 && q
->symbol
.value
>= low_func
&& q
->symbol
.value
<= offset
)
6991 func
= (asymbol
*) q
;
6992 low_func
= q
->symbol
.value
;
7002 *filename_ptr
= filename
;
7003 if (functionname_ptr
)
7004 *functionname_ptr
= bfd_asymbol_name (func
);
7010 /* Find the nearest line to a particular section and offset, for error
7011 reporting. This code is a duplicate of the code in elf.c, except
7012 that it uses aarch64_elf_find_function. */
7015 elfNN_aarch64_find_nearest_line (bfd
*abfd
,
7019 const char **filename_ptr
,
7020 const char **functionname_ptr
,
7021 unsigned int *line_ptr
,
7022 unsigned int *discriminator_ptr
)
7024 bfd_boolean found
= FALSE
;
7026 if (_bfd_dwarf2_find_nearest_line (abfd
, symbols
, NULL
, section
, offset
,
7027 filename_ptr
, functionname_ptr
,
7028 line_ptr
, discriminator_ptr
,
7029 dwarf_debug_sections
, 0,
7030 &elf_tdata (abfd
)->dwarf2_find_line_info
))
7032 if (!*functionname_ptr
)
7033 aarch64_elf_find_function (abfd
, symbols
, section
, offset
,
7034 *filename_ptr
? NULL
: filename_ptr
,
7040 /* Skip _bfd_dwarf1_find_nearest_line since no known AArch64
7041 toolchain uses DWARF1. */
7043 if (!_bfd_stab_section_find_nearest_line (abfd
, symbols
, section
, offset
,
7044 &found
, filename_ptr
,
7045 functionname_ptr
, line_ptr
,
7046 &elf_tdata (abfd
)->line_info
))
7049 if (found
&& (*functionname_ptr
|| *line_ptr
))
7052 if (symbols
== NULL
)
7055 if (!aarch64_elf_find_function (abfd
, symbols
, section
, offset
,
7056 filename_ptr
, functionname_ptr
))
7064 elfNN_aarch64_find_inliner_info (bfd
*abfd
,
7065 const char **filename_ptr
,
7066 const char **functionname_ptr
,
7067 unsigned int *line_ptr
)
7070 found
= _bfd_dwarf2_find_inliner_info
7071 (abfd
, filename_ptr
,
7072 functionname_ptr
, line_ptr
, &elf_tdata (abfd
)->dwarf2_find_line_info
);
7078 elfNN_aarch64_post_process_headers (bfd
*abfd
,
7079 struct bfd_link_info
*link_info
)
7081 Elf_Internal_Ehdr
*i_ehdrp
; /* ELF file header, internal form. */
7083 i_ehdrp
= elf_elfheader (abfd
);
7084 i_ehdrp
->e_ident
[EI_ABIVERSION
] = AARCH64_ELF_ABI_VERSION
;
7086 _bfd_elf_post_process_headers (abfd
, link_info
);
7089 static enum elf_reloc_type_class
7090 elfNN_aarch64_reloc_type_class (const struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
7091 const asection
*rel_sec ATTRIBUTE_UNUSED
,
7092 const Elf_Internal_Rela
*rela
)
7094 switch ((int) ELFNN_R_TYPE (rela
->r_info
))
7096 case AARCH64_R (RELATIVE
):
7097 return reloc_class_relative
;
7098 case AARCH64_R (JUMP_SLOT
):
7099 return reloc_class_plt
;
7100 case AARCH64_R (COPY
):
7101 return reloc_class_copy
;
7103 return reloc_class_normal
;
7107 /* Handle an AArch64 specific section when reading an object file. This is
7108 called when bfd_section_from_shdr finds a section with an unknown
7112 elfNN_aarch64_section_from_shdr (bfd
*abfd
,
7113 Elf_Internal_Shdr
*hdr
,
7114 const char *name
, int shindex
)
7116 /* There ought to be a place to keep ELF backend specific flags, but
7117 at the moment there isn't one. We just keep track of the
7118 sections by their name, instead. Fortunately, the ABI gives
7119 names for all the AArch64 specific sections, so we will probably get
7121 switch (hdr
->sh_type
)
7123 case SHT_AARCH64_ATTRIBUTES
:
7130 if (!_bfd_elf_make_section_from_shdr (abfd
, hdr
, name
, shindex
))
7136 /* A structure used to record a list of sections, independently
7137 of the next and prev fields in the asection structure. */
7138 typedef struct section_list
7141 struct section_list
*next
;
7142 struct section_list
*prev
;
7146 /* Unfortunately we need to keep a list of sections for which
7147 an _aarch64_elf_section_data structure has been allocated. This
7148 is because it is possible for functions like elfNN_aarch64_write_section
7149 to be called on a section which has had an elf_data_structure
7150 allocated for it (and so the used_by_bfd field is valid) but
7151 for which the AArch64 extended version of this structure - the
7152 _aarch64_elf_section_data structure - has not been allocated. */
7153 static section_list
*sections_with_aarch64_elf_section_data
= NULL
;
7156 record_section_with_aarch64_elf_section_data (asection
*sec
)
7158 struct section_list
*entry
;
7160 entry
= bfd_malloc (sizeof (*entry
));
7164 entry
->next
= sections_with_aarch64_elf_section_data
;
7166 if (entry
->next
!= NULL
)
7167 entry
->next
->prev
= entry
;
7168 sections_with_aarch64_elf_section_data
= entry
;
7171 static struct section_list
*
7172 find_aarch64_elf_section_entry (asection
*sec
)
7174 struct section_list
*entry
;
7175 static struct section_list
*last_entry
= NULL
;
7177 /* This is a short cut for the typical case where the sections are added
7178 to the sections_with_aarch64_elf_section_data list in forward order and
7179 then looked up here in backwards order. This makes a real difference
7180 to the ld-srec/sec64k.exp linker test. */
7181 entry
= sections_with_aarch64_elf_section_data
;
7182 if (last_entry
!= NULL
)
7184 if (last_entry
->sec
== sec
)
7186 else if (last_entry
->next
!= NULL
&& last_entry
->next
->sec
== sec
)
7187 entry
= last_entry
->next
;
7190 for (; entry
; entry
= entry
->next
)
7191 if (entry
->sec
== sec
)
7195 /* Record the entry prior to this one - it is the entry we are
7196 most likely to want to locate next time. Also this way if we
7197 have been called from
7198 unrecord_section_with_aarch64_elf_section_data () we will not
7199 be caching a pointer that is about to be freed. */
7200 last_entry
= entry
->prev
;
7206 unrecord_section_with_aarch64_elf_section_data (asection
*sec
)
7208 struct section_list
*entry
;
7210 entry
= find_aarch64_elf_section_entry (sec
);
7214 if (entry
->prev
!= NULL
)
7215 entry
->prev
->next
= entry
->next
;
7216 if (entry
->next
!= NULL
)
7217 entry
->next
->prev
= entry
->prev
;
7218 if (entry
== sections_with_aarch64_elf_section_data
)
7219 sections_with_aarch64_elf_section_data
= entry
->next
;
7228 struct bfd_link_info
*info
;
7231 int (*func
) (void *, const char *, Elf_Internal_Sym
*,
7232 asection
*, struct elf_link_hash_entry
*);
7233 } output_arch_syminfo
;
7235 enum map_symbol_type
7242 /* Output a single mapping symbol. */
7245 elfNN_aarch64_output_map_sym (output_arch_syminfo
*osi
,
7246 enum map_symbol_type type
, bfd_vma offset
)
7248 static const char *names
[2] = { "$x", "$d" };
7249 Elf_Internal_Sym sym
;
7251 sym
.st_value
= (osi
->sec
->output_section
->vma
7252 + osi
->sec
->output_offset
+ offset
);
7255 sym
.st_info
= ELF_ST_INFO (STB_LOCAL
, STT_NOTYPE
);
7256 sym
.st_shndx
= osi
->sec_shndx
;
7257 return osi
->func (osi
->finfo
, names
[type
], &sym
, osi
->sec
, NULL
) == 1;
7262 /* Output mapping symbols for PLT entries associated with H. */
7265 elfNN_aarch64_output_plt_map (struct elf_link_hash_entry
*h
, void *inf
)
7267 output_arch_syminfo
*osi
= (output_arch_syminfo
*) inf
;
7270 if (h
->root
.type
== bfd_link_hash_indirect
)
7273 if (h
->root
.type
== bfd_link_hash_warning
)
7274 /* When warning symbols are created, they **replace** the "real"
7275 entry in the hash table, thus we never get to see the real
7276 symbol in a hash traversal. So look at it now. */
7277 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
7279 if (h
->plt
.offset
== (bfd_vma
) - 1)
7282 addr
= h
->plt
.offset
;
7285 if (!elfNN_aarch64_output_map_sym (osi
, AARCH64_MAP_INSN
, addr
))
7292 /* Output a single local symbol for a generated stub. */
7295 elfNN_aarch64_output_stub_sym (output_arch_syminfo
*osi
, const char *name
,
7296 bfd_vma offset
, bfd_vma size
)
7298 Elf_Internal_Sym sym
;
7300 sym
.st_value
= (osi
->sec
->output_section
->vma
7301 + osi
->sec
->output_offset
+ offset
);
7304 sym
.st_info
= ELF_ST_INFO (STB_LOCAL
, STT_FUNC
);
7305 sym
.st_shndx
= osi
->sec_shndx
;
7306 return osi
->func (osi
->finfo
, name
, &sym
, osi
->sec
, NULL
) == 1;
7310 aarch64_map_one_stub (struct bfd_hash_entry
*gen_entry
, void *in_arg
)
7312 struct elf_aarch64_stub_hash_entry
*stub_entry
;
7316 output_arch_syminfo
*osi
;
7318 /* Massage our args to the form they really have. */
7319 stub_entry
= (struct elf_aarch64_stub_hash_entry
*) gen_entry
;
7320 osi
= (output_arch_syminfo
*) in_arg
;
7322 stub_sec
= stub_entry
->stub_sec
;
7324 /* Ensure this stub is attached to the current section being
7326 if (stub_sec
!= osi
->sec
)
7329 addr
= (bfd_vma
) stub_entry
->stub_offset
;
7331 stub_name
= stub_entry
->output_name
;
7333 switch (stub_entry
->stub_type
)
7335 case aarch64_stub_adrp_branch
:
7336 if (!elfNN_aarch64_output_stub_sym (osi
, stub_name
, addr
,
7337 sizeof (aarch64_adrp_branch_stub
)))
7339 if (!elfNN_aarch64_output_map_sym (osi
, AARCH64_MAP_INSN
, addr
))
7342 case aarch64_stub_long_branch
:
7343 if (!elfNN_aarch64_output_stub_sym
7344 (osi
, stub_name
, addr
, sizeof (aarch64_long_branch_stub
)))
7346 if (!elfNN_aarch64_output_map_sym (osi
, AARCH64_MAP_INSN
, addr
))
7348 if (!elfNN_aarch64_output_map_sym (osi
, AARCH64_MAP_DATA
, addr
+ 16))
7351 case aarch64_stub_erratum_835769_veneer
:
7352 if (!elfNN_aarch64_output_stub_sym (osi
, stub_name
, addr
,
7353 sizeof (aarch64_erratum_835769_stub
)))
7355 if (!elfNN_aarch64_output_map_sym (osi
, AARCH64_MAP_INSN
, addr
))
7358 case aarch64_stub_erratum_843419_veneer
:
7359 if (!elfNN_aarch64_output_stub_sym (osi
, stub_name
, addr
,
7360 sizeof (aarch64_erratum_843419_stub
)))
7362 if (!elfNN_aarch64_output_map_sym (osi
, AARCH64_MAP_INSN
, addr
))
7373 /* Output mapping symbols for linker generated sections. */
7376 elfNN_aarch64_output_arch_local_syms (bfd
*output_bfd
,
7377 struct bfd_link_info
*info
,
7379 int (*func
) (void *, const char *,
7382 struct elf_link_hash_entry
7385 output_arch_syminfo osi
;
7386 struct elf_aarch64_link_hash_table
*htab
;
7388 htab
= elf_aarch64_hash_table (info
);
7394 /* Long calls stubs. */
7395 if (htab
->stub_bfd
&& htab
->stub_bfd
->sections
)
7399 for (stub_sec
= htab
->stub_bfd
->sections
;
7400 stub_sec
!= NULL
; stub_sec
= stub_sec
->next
)
7402 /* Ignore non-stub sections. */
7403 if (!strstr (stub_sec
->name
, STUB_SUFFIX
))
7408 osi
.sec_shndx
= _bfd_elf_section_from_bfd_section
7409 (output_bfd
, osi
.sec
->output_section
);
7411 /* The first instruction in a stub is always a branch. */
7412 if (!elfNN_aarch64_output_map_sym (&osi
, AARCH64_MAP_INSN
, 0))
7415 bfd_hash_traverse (&htab
->stub_hash_table
, aarch64_map_one_stub
,
7420 /* Finally, output mapping symbols for the PLT. */
7421 if (!htab
->root
.splt
|| htab
->root
.splt
->size
== 0)
7424 /* For now live without mapping symbols for the plt. */
7425 osi
.sec_shndx
= _bfd_elf_section_from_bfd_section
7426 (output_bfd
, htab
->root
.splt
->output_section
);
7427 osi
.sec
= htab
->root
.splt
;
7429 elf_link_hash_traverse (&htab
->root
, elfNN_aarch64_output_plt_map
,
7436 /* Allocate target specific section data. */
7439 elfNN_aarch64_new_section_hook (bfd
*abfd
, asection
*sec
)
7441 if (!sec
->used_by_bfd
)
7443 _aarch64_elf_section_data
*sdata
;
7444 bfd_size_type amt
= sizeof (*sdata
);
7446 sdata
= bfd_zalloc (abfd
, amt
);
7449 sec
->used_by_bfd
= sdata
;
7452 record_section_with_aarch64_elf_section_data (sec
);
7454 return _bfd_elf_new_section_hook (abfd
, sec
);
7459 unrecord_section_via_map_over_sections (bfd
*abfd ATTRIBUTE_UNUSED
,
7461 void *ignore ATTRIBUTE_UNUSED
)
7463 unrecord_section_with_aarch64_elf_section_data (sec
);
7467 elfNN_aarch64_close_and_cleanup (bfd
*abfd
)
7470 bfd_map_over_sections (abfd
,
7471 unrecord_section_via_map_over_sections
, NULL
);
7473 return _bfd_elf_close_and_cleanup (abfd
);
7477 elfNN_aarch64_bfd_free_cached_info (bfd
*abfd
)
7480 bfd_map_over_sections (abfd
,
7481 unrecord_section_via_map_over_sections
, NULL
);
7483 return _bfd_free_cached_info (abfd
);
7486 /* Create dynamic sections. This is different from the ARM backend in that
7487 the got, plt, gotplt and their relocation sections are all created in the
7488 standard part of the bfd elf backend. */
7491 elfNN_aarch64_create_dynamic_sections (bfd
*dynobj
,
7492 struct bfd_link_info
*info
)
7494 struct elf_aarch64_link_hash_table
*htab
;
7496 /* We need to create .got section. */
7497 if (!aarch64_elf_create_got_section (dynobj
, info
))
7500 if (!_bfd_elf_create_dynamic_sections (dynobj
, info
))
7503 htab
= elf_aarch64_hash_table (info
);
7504 htab
->sdynbss
= bfd_get_linker_section (dynobj
, ".dynbss");
7505 if (!bfd_link_pic (info
))
7506 htab
->srelbss
= bfd_get_linker_section (dynobj
, ".rela.bss");
7508 if (!htab
->sdynbss
|| (!bfd_link_pic (info
) && !htab
->srelbss
))
7515 /* Allocate space in .plt, .got and associated reloc sections for
7519 elfNN_aarch64_allocate_dynrelocs (struct elf_link_hash_entry
*h
, void *inf
)
7521 struct bfd_link_info
*info
;
7522 struct elf_aarch64_link_hash_table
*htab
;
7523 struct elf_aarch64_link_hash_entry
*eh
;
7524 struct elf_dyn_relocs
*p
;
7526 /* An example of a bfd_link_hash_indirect symbol is versioned
7527 symbol. For example: __gxx_personality_v0(bfd_link_hash_indirect)
7528 -> __gxx_personality_v0(bfd_link_hash_defined)
7530 There is no need to process bfd_link_hash_indirect symbols here
7531 because we will also be presented with the concrete instance of
7532 the symbol and elfNN_aarch64_copy_indirect_symbol () will have been
7533 called to copy all relevant data from the generic to the concrete
7536 if (h
->root
.type
== bfd_link_hash_indirect
)
7539 if (h
->root
.type
== bfd_link_hash_warning
)
7540 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
7542 info
= (struct bfd_link_info
*) inf
;
7543 htab
= elf_aarch64_hash_table (info
);
7545 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle it
7546 here if it is defined and referenced in a non-shared object. */
7547 if (h
->type
== STT_GNU_IFUNC
7550 else if (htab
->root
.dynamic_sections_created
&& h
->plt
.refcount
> 0)
7552 /* Make sure this symbol is output as a dynamic symbol.
7553 Undefined weak syms won't yet be marked as dynamic. */
7554 if (h
->dynindx
== -1 && !h
->forced_local
)
7556 if (!bfd_elf_link_record_dynamic_symbol (info
, h
))
7560 if (bfd_link_pic (info
) || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h
))
7562 asection
*s
= htab
->root
.splt
;
7564 /* If this is the first .plt entry, make room for the special
7567 s
->size
+= htab
->plt_header_size
;
7569 h
->plt
.offset
= s
->size
;
7571 /* If this symbol is not defined in a regular file, and we are
7572 not generating a shared library, then set the symbol to this
7573 location in the .plt. This is required to make function
7574 pointers compare as equal between the normal executable and
7575 the shared library. */
7576 if (!bfd_link_pic (info
) && !h
->def_regular
)
7578 h
->root
.u
.def
.section
= s
;
7579 h
->root
.u
.def
.value
= h
->plt
.offset
;
7582 /* Make room for this entry. For now we only create the
7583 small model PLT entries. We later need to find a way
7584 of relaxing into these from the large model PLT entries. */
7585 s
->size
+= PLT_SMALL_ENTRY_SIZE
;
7587 /* We also need to make an entry in the .got.plt section, which
7588 will be placed in the .got section by the linker script. */
7589 htab
->root
.sgotplt
->size
+= GOT_ENTRY_SIZE
;
7591 /* We also need to make an entry in the .rela.plt section. */
7592 htab
->root
.srelplt
->size
+= RELOC_SIZE (htab
);
7594 /* We need to ensure that all GOT entries that serve the PLT
7595 are consecutive with the special GOT slots [0] [1] and
7596 [2]. Any addtional relocations, such as
7597 R_AARCH64_TLSDESC, must be placed after the PLT related
7598 entries. We abuse the reloc_count such that during
7599 sizing we adjust reloc_count to indicate the number of
7600 PLT related reserved entries. In subsequent phases when
7601 filling in the contents of the reloc entries, PLT related
7602 entries are placed by computing their PLT index (0
7603 .. reloc_count). While other none PLT relocs are placed
7604 at the slot indicated by reloc_count and reloc_count is
7607 htab
->root
.srelplt
->reloc_count
++;
7611 h
->plt
.offset
= (bfd_vma
) - 1;
7617 h
->plt
.offset
= (bfd_vma
) - 1;
7621 eh
= (struct elf_aarch64_link_hash_entry
*) h
;
7622 eh
->tlsdesc_got_jump_table_offset
= (bfd_vma
) - 1;
7624 if (h
->got
.refcount
> 0)
7627 unsigned got_type
= elf_aarch64_hash_entry (h
)->got_type
;
7629 h
->got
.offset
= (bfd_vma
) - 1;
7631 dyn
= htab
->root
.dynamic_sections_created
;
7633 /* Make sure this symbol is output as a dynamic symbol.
7634 Undefined weak syms won't yet be marked as dynamic. */
7635 if (dyn
&& h
->dynindx
== -1 && !h
->forced_local
)
7637 if (!bfd_elf_link_record_dynamic_symbol (info
, h
))
7641 if (got_type
== GOT_UNKNOWN
)
7644 else if (got_type
== GOT_NORMAL
)
7646 h
->got
.offset
= htab
->root
.sgot
->size
;
7647 htab
->root
.sgot
->size
+= GOT_ENTRY_SIZE
;
7648 if ((ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
7649 || h
->root
.type
!= bfd_link_hash_undefweak
)
7650 && (bfd_link_pic (info
)
7651 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, 0, h
)))
7653 htab
->root
.srelgot
->size
+= RELOC_SIZE (htab
);
7659 if (got_type
& GOT_TLSDESC_GD
)
7661 eh
->tlsdesc_got_jump_table_offset
=
7662 (htab
->root
.sgotplt
->size
7663 - aarch64_compute_jump_table_size (htab
));
7664 htab
->root
.sgotplt
->size
+= GOT_ENTRY_SIZE
* 2;
7665 h
->got
.offset
= (bfd_vma
) - 2;
7668 if (got_type
& GOT_TLS_GD
)
7670 h
->got
.offset
= htab
->root
.sgot
->size
;
7671 htab
->root
.sgot
->size
+= GOT_ENTRY_SIZE
* 2;
7674 if (got_type
& GOT_TLS_IE
)
7676 h
->got
.offset
= htab
->root
.sgot
->size
;
7677 htab
->root
.sgot
->size
+= GOT_ENTRY_SIZE
;
7680 indx
= h
&& h
->dynindx
!= -1 ? h
->dynindx
: 0;
7681 if ((ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
7682 || h
->root
.type
!= bfd_link_hash_undefweak
)
7683 && (bfd_link_pic (info
)
7685 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, 0, h
)))
7687 if (got_type
& GOT_TLSDESC_GD
)
7689 htab
->root
.srelplt
->size
+= RELOC_SIZE (htab
);
7690 /* Note reloc_count not incremented here! We have
7691 already adjusted reloc_count for this relocation
7694 /* TLSDESC PLT is now needed, but not yet determined. */
7695 htab
->tlsdesc_plt
= (bfd_vma
) - 1;
7698 if (got_type
& GOT_TLS_GD
)
7699 htab
->root
.srelgot
->size
+= RELOC_SIZE (htab
) * 2;
7701 if (got_type
& GOT_TLS_IE
)
7702 htab
->root
.srelgot
->size
+= RELOC_SIZE (htab
);
7708 h
->got
.offset
= (bfd_vma
) - 1;
7711 if (eh
->dyn_relocs
== NULL
)
7714 /* In the shared -Bsymbolic case, discard space allocated for
7715 dynamic pc-relative relocs against symbols which turn out to be
7716 defined in regular objects. For the normal shared case, discard
7717 space for pc-relative relocs that have become local due to symbol
7718 visibility changes. */
7720 if (bfd_link_pic (info
))
7722 /* Relocs that use pc_count are those that appear on a call
7723 insn, or certain REL relocs that can generated via assembly.
7724 We want calls to protected symbols to resolve directly to the
7725 function rather than going via the plt. If people want
7726 function pointer comparisons to work as expected then they
7727 should avoid writing weird assembly. */
7728 if (SYMBOL_CALLS_LOCAL (info
, h
))
7730 struct elf_dyn_relocs
**pp
;
7732 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
;)
7734 p
->count
-= p
->pc_count
;
7743 /* Also discard relocs on undefined weak syms with non-default
7745 if (eh
->dyn_relocs
!= NULL
&& h
->root
.type
== bfd_link_hash_undefweak
)
7747 if (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
)
7748 eh
->dyn_relocs
= NULL
;
7750 /* Make sure undefined weak symbols are output as a dynamic
7752 else if (h
->dynindx
== -1
7754 && !bfd_elf_link_record_dynamic_symbol (info
, h
))
7759 else if (ELIMINATE_COPY_RELOCS
)
7761 /* For the non-shared case, discard space for relocs against
7762 symbols which turn out to need copy relocs or are not
7768 || (htab
->root
.dynamic_sections_created
7769 && (h
->root
.type
== bfd_link_hash_undefweak
7770 || h
->root
.type
== bfd_link_hash_undefined
))))
7772 /* Make sure this symbol is output as a dynamic symbol.
7773 Undefined weak syms won't yet be marked as dynamic. */
7774 if (h
->dynindx
== -1
7776 && !bfd_elf_link_record_dynamic_symbol (info
, h
))
7779 /* If that succeeded, we know we'll be keeping all the
7781 if (h
->dynindx
!= -1)
7785 eh
->dyn_relocs
= NULL
;
7790 /* Finally, allocate space. */
7791 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
7795 sreloc
= elf_section_data (p
->sec
)->sreloc
;
7797 BFD_ASSERT (sreloc
!= NULL
);
7799 sreloc
->size
+= p
->count
* RELOC_SIZE (htab
);
7805 /* Allocate space in .plt, .got and associated reloc sections for
7806 ifunc dynamic relocs. */
7809 elfNN_aarch64_allocate_ifunc_dynrelocs (struct elf_link_hash_entry
*h
,
7812 struct bfd_link_info
*info
;
7813 struct elf_aarch64_link_hash_table
*htab
;
7814 struct elf_aarch64_link_hash_entry
*eh
;
7816 /* An example of a bfd_link_hash_indirect symbol is versioned
7817 symbol. For example: __gxx_personality_v0(bfd_link_hash_indirect)
7818 -> __gxx_personality_v0(bfd_link_hash_defined)
7820 There is no need to process bfd_link_hash_indirect symbols here
7821 because we will also be presented with the concrete instance of
7822 the symbol and elfNN_aarch64_copy_indirect_symbol () will have been
7823 called to copy all relevant data from the generic to the concrete
7826 if (h
->root
.type
== bfd_link_hash_indirect
)
7829 if (h
->root
.type
== bfd_link_hash_warning
)
7830 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
7832 info
= (struct bfd_link_info
*) inf
;
7833 htab
= elf_aarch64_hash_table (info
);
7835 eh
= (struct elf_aarch64_link_hash_entry
*) h
;
7837 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle it
7838 here if it is defined and referenced in a non-shared object. */
7839 if (h
->type
== STT_GNU_IFUNC
7841 return _bfd_elf_allocate_ifunc_dyn_relocs (info
, h
,
7843 htab
->plt_entry_size
,
7844 htab
->plt_header_size
,
7849 /* Allocate space in .plt, .got and associated reloc sections for
7850 local dynamic relocs. */
7853 elfNN_aarch64_allocate_local_dynrelocs (void **slot
, void *inf
)
7855 struct elf_link_hash_entry
*h
7856 = (struct elf_link_hash_entry
*) *slot
;
7858 if (h
->type
!= STT_GNU_IFUNC
7862 || h
->root
.type
!= bfd_link_hash_defined
)
7865 return elfNN_aarch64_allocate_dynrelocs (h
, inf
);
7868 /* Allocate space in .plt, .got and associated reloc sections for
7869 local ifunc dynamic relocs. */
7872 elfNN_aarch64_allocate_local_ifunc_dynrelocs (void **slot
, void *inf
)
7874 struct elf_link_hash_entry
*h
7875 = (struct elf_link_hash_entry
*) *slot
;
7877 if (h
->type
!= STT_GNU_IFUNC
7881 || h
->root
.type
!= bfd_link_hash_defined
)
7884 return elfNN_aarch64_allocate_ifunc_dynrelocs (h
, inf
);
7887 /* Find any dynamic relocs that apply to read-only sections. */
7890 aarch64_readonly_dynrelocs (struct elf_link_hash_entry
* h
, void * inf
)
7892 struct elf_aarch64_link_hash_entry
* eh
;
7893 struct elf_dyn_relocs
* p
;
7895 eh
= (struct elf_aarch64_link_hash_entry
*) h
;
7896 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
7898 asection
*s
= p
->sec
;
7900 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
7902 struct bfd_link_info
*info
= (struct bfd_link_info
*) inf
;
7904 info
->flags
|= DF_TEXTREL
;
7906 /* Not an error, just cut short the traversal. */
7913 /* This is the most important function of all . Innocuosly named
7916 elfNN_aarch64_size_dynamic_sections (bfd
*output_bfd ATTRIBUTE_UNUSED
,
7917 struct bfd_link_info
*info
)
7919 struct elf_aarch64_link_hash_table
*htab
;
7925 htab
= elf_aarch64_hash_table ((info
));
7926 dynobj
= htab
->root
.dynobj
;
7928 BFD_ASSERT (dynobj
!= NULL
);
7930 if (htab
->root
.dynamic_sections_created
)
7932 if (bfd_link_executable (info
))
7934 s
= bfd_get_linker_section (dynobj
, ".interp");
7937 s
->size
= sizeof ELF_DYNAMIC_INTERPRETER
;
7938 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
7942 /* Set up .got offsets for local syms, and space for local dynamic
7944 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
7946 struct elf_aarch64_local_symbol
*locals
= NULL
;
7947 Elf_Internal_Shdr
*symtab_hdr
;
7951 if (!is_aarch64_elf (ibfd
))
7954 for (s
= ibfd
->sections
; s
!= NULL
; s
= s
->next
)
7956 struct elf_dyn_relocs
*p
;
7958 for (p
= (struct elf_dyn_relocs
*)
7959 (elf_section_data (s
)->local_dynrel
); p
!= NULL
; p
= p
->next
)
7961 if (!bfd_is_abs_section (p
->sec
)
7962 && bfd_is_abs_section (p
->sec
->output_section
))
7964 /* Input section has been discarded, either because
7965 it is a copy of a linkonce section or due to
7966 linker script /DISCARD/, so we'll be discarding
7969 else if (p
->count
!= 0)
7971 srel
= elf_section_data (p
->sec
)->sreloc
;
7972 srel
->size
+= p
->count
* RELOC_SIZE (htab
);
7973 if ((p
->sec
->output_section
->flags
& SEC_READONLY
) != 0)
7974 info
->flags
|= DF_TEXTREL
;
7979 locals
= elf_aarch64_locals (ibfd
);
7983 symtab_hdr
= &elf_symtab_hdr (ibfd
);
7984 srel
= htab
->root
.srelgot
;
7985 for (i
= 0; i
< symtab_hdr
->sh_info
; i
++)
7987 locals
[i
].got_offset
= (bfd_vma
) - 1;
7988 locals
[i
].tlsdesc_got_jump_table_offset
= (bfd_vma
) - 1;
7989 if (locals
[i
].got_refcount
> 0)
7991 unsigned got_type
= locals
[i
].got_type
;
7992 if (got_type
& GOT_TLSDESC_GD
)
7994 locals
[i
].tlsdesc_got_jump_table_offset
=
7995 (htab
->root
.sgotplt
->size
7996 - aarch64_compute_jump_table_size (htab
));
7997 htab
->root
.sgotplt
->size
+= GOT_ENTRY_SIZE
* 2;
7998 locals
[i
].got_offset
= (bfd_vma
) - 2;
8001 if (got_type
& GOT_TLS_GD
)
8003 locals
[i
].got_offset
= htab
->root
.sgot
->size
;
8004 htab
->root
.sgot
->size
+= GOT_ENTRY_SIZE
* 2;
8007 if (got_type
& GOT_TLS_IE
8008 || got_type
& GOT_NORMAL
)
8010 locals
[i
].got_offset
= htab
->root
.sgot
->size
;
8011 htab
->root
.sgot
->size
+= GOT_ENTRY_SIZE
;
8014 if (got_type
== GOT_UNKNOWN
)
8018 if (bfd_link_pic (info
))
8020 if (got_type
& GOT_TLSDESC_GD
)
8022 htab
->root
.srelplt
->size
+= RELOC_SIZE (htab
);
8023 /* Note RELOC_COUNT not incremented here! */
8024 htab
->tlsdesc_plt
= (bfd_vma
) - 1;
8027 if (got_type
& GOT_TLS_GD
)
8028 htab
->root
.srelgot
->size
+= RELOC_SIZE (htab
) * 2;
8030 if (got_type
& GOT_TLS_IE
8031 || got_type
& GOT_NORMAL
)
8032 htab
->root
.srelgot
->size
+= RELOC_SIZE (htab
);
8037 locals
[i
].got_refcount
= (bfd_vma
) - 1;
8043 /* Allocate global sym .plt and .got entries, and space for global
8044 sym dynamic relocs. */
8045 elf_link_hash_traverse (&htab
->root
, elfNN_aarch64_allocate_dynrelocs
,
8048 /* Allocate global ifunc sym .plt and .got entries, and space for global
8049 ifunc sym dynamic relocs. */
8050 elf_link_hash_traverse (&htab
->root
, elfNN_aarch64_allocate_ifunc_dynrelocs
,
8053 /* Allocate .plt and .got entries, and space for local symbols. */
8054 htab_traverse (htab
->loc_hash_table
,
8055 elfNN_aarch64_allocate_local_dynrelocs
,
8058 /* Allocate .plt and .got entries, and space for local ifunc symbols. */
8059 htab_traverse (htab
->loc_hash_table
,
8060 elfNN_aarch64_allocate_local_ifunc_dynrelocs
,
8063 /* For every jump slot reserved in the sgotplt, reloc_count is
8064 incremented. However, when we reserve space for TLS descriptors,
8065 it's not incremented, so in order to compute the space reserved
8066 for them, it suffices to multiply the reloc count by the jump
8069 if (htab
->root
.srelplt
)
8070 htab
->sgotplt_jump_table_size
= aarch64_compute_jump_table_size (htab
);
8072 if (htab
->tlsdesc_plt
)
8074 if (htab
->root
.splt
->size
== 0)
8075 htab
->root
.splt
->size
+= PLT_ENTRY_SIZE
;
8077 htab
->tlsdesc_plt
= htab
->root
.splt
->size
;
8078 htab
->root
.splt
->size
+= PLT_TLSDESC_ENTRY_SIZE
;
8080 /* If we're not using lazy TLS relocations, don't generate the
8081 GOT entry required. */
8082 if (!(info
->flags
& DF_BIND_NOW
))
8084 htab
->dt_tlsdesc_got
= htab
->root
.sgot
->size
;
8085 htab
->root
.sgot
->size
+= GOT_ENTRY_SIZE
;
8089 /* Init mapping symbols information to use later to distingush between
8090 code and data while scanning for errata. */
8091 if (htab
->fix_erratum_835769
|| htab
->fix_erratum_843419
)
8092 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
8094 if (!is_aarch64_elf (ibfd
))
8096 bfd_elfNN_aarch64_init_maps (ibfd
);
8099 /* We now have determined the sizes of the various dynamic sections.
8100 Allocate memory for them. */
8102 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
8104 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
8107 if (s
== htab
->root
.splt
8108 || s
== htab
->root
.sgot
8109 || s
== htab
->root
.sgotplt
8110 || s
== htab
->root
.iplt
8111 || s
== htab
->root
.igotplt
|| s
== htab
->sdynbss
)
8113 /* Strip this section if we don't need it; see the
8116 else if (CONST_STRNEQ (bfd_get_section_name (dynobj
, s
), ".rela"))
8118 if (s
->size
!= 0 && s
!= htab
->root
.srelplt
)
8121 /* We use the reloc_count field as a counter if we need
8122 to copy relocs into the output file. */
8123 if (s
!= htab
->root
.srelplt
)
8128 /* It's not one of our sections, so don't allocate space. */
8134 /* If we don't need this section, strip it from the
8135 output file. This is mostly to handle .rela.bss and
8136 .rela.plt. We must create both sections in
8137 create_dynamic_sections, because they must be created
8138 before the linker maps input sections to output
8139 sections. The linker does that before
8140 adjust_dynamic_symbol is called, and it is that
8141 function which decides whether anything needs to go
8142 into these sections. */
8144 s
->flags
|= SEC_EXCLUDE
;
8148 if ((s
->flags
& SEC_HAS_CONTENTS
) == 0)
8151 /* Allocate memory for the section contents. We use bfd_zalloc
8152 here in case unused entries are not reclaimed before the
8153 section's contents are written out. This should not happen,
8154 but this way if it does, we get a R_AARCH64_NONE reloc instead
8156 s
->contents
= (bfd_byte
*) bfd_zalloc (dynobj
, s
->size
);
8157 if (s
->contents
== NULL
)
8161 if (htab
->root
.dynamic_sections_created
)
8163 /* Add some entries to the .dynamic section. We fill in the
8164 values later, in elfNN_aarch64_finish_dynamic_sections, but we
8165 must add the entries now so that we get the correct size for
8166 the .dynamic section. The DT_DEBUG entry is filled in by the
8167 dynamic linker and used by the debugger. */
8168 #define add_dynamic_entry(TAG, VAL) \
8169 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
8171 if (bfd_link_executable (info
))
8173 if (!add_dynamic_entry (DT_DEBUG
, 0))
8177 if (htab
->root
.splt
->size
!= 0)
8179 if (!add_dynamic_entry (DT_PLTGOT
, 0)
8180 || !add_dynamic_entry (DT_PLTRELSZ
, 0)
8181 || !add_dynamic_entry (DT_PLTREL
, DT_RELA
)
8182 || !add_dynamic_entry (DT_JMPREL
, 0))
8185 if (htab
->tlsdesc_plt
8186 && (!add_dynamic_entry (DT_TLSDESC_PLT
, 0)
8187 || !add_dynamic_entry (DT_TLSDESC_GOT
, 0)))
8193 if (!add_dynamic_entry (DT_RELA
, 0)
8194 || !add_dynamic_entry (DT_RELASZ
, 0)
8195 || !add_dynamic_entry (DT_RELAENT
, RELOC_SIZE (htab
)))
8198 /* If any dynamic relocs apply to a read-only section,
8199 then we need a DT_TEXTREL entry. */
8200 if ((info
->flags
& DF_TEXTREL
) == 0)
8201 elf_link_hash_traverse (& htab
->root
, aarch64_readonly_dynrelocs
,
8204 if ((info
->flags
& DF_TEXTREL
) != 0)
8206 if (!add_dynamic_entry (DT_TEXTREL
, 0))
8211 #undef add_dynamic_entry
8217 elf_aarch64_update_plt_entry (bfd
*output_bfd
,
8218 bfd_reloc_code_real_type r_type
,
8219 bfd_byte
*plt_entry
, bfd_vma value
)
8221 reloc_howto_type
*howto
= elfNN_aarch64_howto_from_bfd_reloc (r_type
);
8223 _bfd_aarch64_elf_put_addend (output_bfd
, plt_entry
, r_type
, howto
, value
);
8227 elfNN_aarch64_create_small_pltn_entry (struct elf_link_hash_entry
*h
,
8228 struct elf_aarch64_link_hash_table
8229 *htab
, bfd
*output_bfd
,
8230 struct bfd_link_info
*info
)
8232 bfd_byte
*plt_entry
;
8235 bfd_vma gotplt_entry_address
;
8236 bfd_vma plt_entry_address
;
8237 Elf_Internal_Rela rela
;
8239 asection
*plt
, *gotplt
, *relplt
;
8241 /* When building a static executable, use .iplt, .igot.plt and
8242 .rela.iplt sections for STT_GNU_IFUNC symbols. */
8243 if (htab
->root
.splt
!= NULL
)
8245 plt
= htab
->root
.splt
;
8246 gotplt
= htab
->root
.sgotplt
;
8247 relplt
= htab
->root
.srelplt
;
8251 plt
= htab
->root
.iplt
;
8252 gotplt
= htab
->root
.igotplt
;
8253 relplt
= htab
->root
.irelplt
;
8256 /* Get the index in the procedure linkage table which
8257 corresponds to this symbol. This is the index of this symbol
8258 in all the symbols for which we are making plt entries. The
8259 first entry in the procedure linkage table is reserved.
8261 Get the offset into the .got table of the entry that
8262 corresponds to this function. Each .got entry is GOT_ENTRY_SIZE
8263 bytes. The first three are reserved for the dynamic linker.
8265 For static executables, we don't reserve anything. */
8267 if (plt
== htab
->root
.splt
)
8269 plt_index
= (h
->plt
.offset
- htab
->plt_header_size
) / htab
->plt_entry_size
;
8270 got_offset
= (plt_index
+ 3) * GOT_ENTRY_SIZE
;
8274 plt_index
= h
->plt
.offset
/ htab
->plt_entry_size
;
8275 got_offset
= plt_index
* GOT_ENTRY_SIZE
;
8278 plt_entry
= plt
->contents
+ h
->plt
.offset
;
8279 plt_entry_address
= plt
->output_section
->vma
8280 + plt
->output_offset
+ h
->plt
.offset
;
8281 gotplt_entry_address
= gotplt
->output_section
->vma
+
8282 gotplt
->output_offset
+ got_offset
;
8284 /* Copy in the boiler-plate for the PLTn entry. */
8285 memcpy (plt_entry
, elfNN_aarch64_small_plt_entry
, PLT_SMALL_ENTRY_SIZE
);
8287 /* Fill in the top 21 bits for this: ADRP x16, PLT_GOT + n * 8.
8288 ADRP: ((PG(S+A)-PG(P)) >> 12) & 0x1fffff */
8289 elf_aarch64_update_plt_entry (output_bfd
, BFD_RELOC_AARCH64_ADR_HI21_PCREL
,
8291 PG (gotplt_entry_address
) -
8292 PG (plt_entry_address
));
8294 /* Fill in the lo12 bits for the load from the pltgot. */
8295 elf_aarch64_update_plt_entry (output_bfd
, BFD_RELOC_AARCH64_LDSTNN_LO12
,
8297 PG_OFFSET (gotplt_entry_address
));
8299 /* Fill in the lo12 bits for the add from the pltgot entry. */
8300 elf_aarch64_update_plt_entry (output_bfd
, BFD_RELOC_AARCH64_ADD_LO12
,
8302 PG_OFFSET (gotplt_entry_address
));
8304 /* All the GOTPLT Entries are essentially initialized to PLT0. */
8305 bfd_put_NN (output_bfd
,
8306 plt
->output_section
->vma
+ plt
->output_offset
,
8307 gotplt
->contents
+ got_offset
);
8309 rela
.r_offset
= gotplt_entry_address
;
8311 if (h
->dynindx
== -1
8312 || ((bfd_link_executable (info
)
8313 || ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
)
8315 && h
->type
== STT_GNU_IFUNC
))
8317 /* If an STT_GNU_IFUNC symbol is locally defined, generate
8318 R_AARCH64_IRELATIVE instead of R_AARCH64_JUMP_SLOT. */
8319 rela
.r_info
= ELFNN_R_INFO (0, AARCH64_R (IRELATIVE
));
8320 rela
.r_addend
= (h
->root
.u
.def
.value
8321 + h
->root
.u
.def
.section
->output_section
->vma
8322 + h
->root
.u
.def
.section
->output_offset
);
8326 /* Fill in the entry in the .rela.plt section. */
8327 rela
.r_info
= ELFNN_R_INFO (h
->dynindx
, AARCH64_R (JUMP_SLOT
));
8331 /* Compute the relocation entry to used based on PLT index and do
8332 not adjust reloc_count. The reloc_count has already been adjusted
8333 to account for this entry. */
8334 loc
= relplt
->contents
+ plt_index
* RELOC_SIZE (htab
);
8335 bfd_elfNN_swap_reloca_out (output_bfd
, &rela
, loc
);
8338 /* Size sections even though they're not dynamic. We use it to setup
8339 _TLS_MODULE_BASE_, if needed. */
8342 elfNN_aarch64_always_size_sections (bfd
*output_bfd
,
8343 struct bfd_link_info
*info
)
8347 if (bfd_link_relocatable (info
))
8350 tls_sec
= elf_hash_table (info
)->tls_sec
;
8354 struct elf_link_hash_entry
*tlsbase
;
8356 tlsbase
= elf_link_hash_lookup (elf_hash_table (info
),
8357 "_TLS_MODULE_BASE_", TRUE
, TRUE
, FALSE
);
8361 struct bfd_link_hash_entry
*h
= NULL
;
8362 const struct elf_backend_data
*bed
=
8363 get_elf_backend_data (output_bfd
);
8365 if (!(_bfd_generic_link_add_one_symbol
8366 (info
, output_bfd
, "_TLS_MODULE_BASE_", BSF_LOCAL
,
8367 tls_sec
, 0, NULL
, FALSE
, bed
->collect
, &h
)))
8370 tlsbase
->type
= STT_TLS
;
8371 tlsbase
= (struct elf_link_hash_entry
*) h
;
8372 tlsbase
->def_regular
= 1;
8373 tlsbase
->other
= STV_HIDDEN
;
8374 (*bed
->elf_backend_hide_symbol
) (info
, tlsbase
, TRUE
);
8381 /* Finish up dynamic symbol handling. We set the contents of various
8382 dynamic sections here. */
8384 elfNN_aarch64_finish_dynamic_symbol (bfd
*output_bfd
,
8385 struct bfd_link_info
*info
,
8386 struct elf_link_hash_entry
*h
,
8387 Elf_Internal_Sym
*sym
)
8389 struct elf_aarch64_link_hash_table
*htab
;
8390 htab
= elf_aarch64_hash_table (info
);
8392 if (h
->plt
.offset
!= (bfd_vma
) - 1)
8394 asection
*plt
, *gotplt
, *relplt
;
8396 /* This symbol has an entry in the procedure linkage table. Set
8399 /* When building a static executable, use .iplt, .igot.plt and
8400 .rela.iplt sections for STT_GNU_IFUNC symbols. */
8401 if (htab
->root
.splt
!= NULL
)
8403 plt
= htab
->root
.splt
;
8404 gotplt
= htab
->root
.sgotplt
;
8405 relplt
= htab
->root
.srelplt
;
8409 plt
= htab
->root
.iplt
;
8410 gotplt
= htab
->root
.igotplt
;
8411 relplt
= htab
->root
.irelplt
;
8414 /* This symbol has an entry in the procedure linkage table. Set
8416 if ((h
->dynindx
== -1
8417 && !((h
->forced_local
|| bfd_link_executable (info
))
8419 && h
->type
== STT_GNU_IFUNC
))
8425 elfNN_aarch64_create_small_pltn_entry (h
, htab
, output_bfd
, info
);
8426 if (!h
->def_regular
)
8428 /* Mark the symbol as undefined, rather than as defined in
8429 the .plt section. */
8430 sym
->st_shndx
= SHN_UNDEF
;
8431 /* If the symbol is weak we need to clear the value.
8432 Otherwise, the PLT entry would provide a definition for
8433 the symbol even if the symbol wasn't defined anywhere,
8434 and so the symbol would never be NULL. Leave the value if
8435 there were any relocations where pointer equality matters
8436 (this is a clue for the dynamic linker, to make function
8437 pointer comparisons work between an application and shared
8439 if (!h
->ref_regular_nonweak
|| !h
->pointer_equality_needed
)
8444 if (h
->got
.offset
!= (bfd_vma
) - 1
8445 && elf_aarch64_hash_entry (h
)->got_type
== GOT_NORMAL
)
8447 Elf_Internal_Rela rela
;
8450 /* This symbol has an entry in the global offset table. Set it
8452 if (htab
->root
.sgot
== NULL
|| htab
->root
.srelgot
== NULL
)
8455 rela
.r_offset
= (htab
->root
.sgot
->output_section
->vma
8456 + htab
->root
.sgot
->output_offset
8457 + (h
->got
.offset
& ~(bfd_vma
) 1));
8460 && h
->type
== STT_GNU_IFUNC
)
8462 if (bfd_link_pic (info
))
8464 /* Generate R_AARCH64_GLOB_DAT. */
8471 if (!h
->pointer_equality_needed
)
8474 /* For non-shared object, we can't use .got.plt, which
8475 contains the real function address if we need pointer
8476 equality. We load the GOT entry with the PLT entry. */
8477 plt
= htab
->root
.splt
? htab
->root
.splt
: htab
->root
.iplt
;
8478 bfd_put_NN (output_bfd
, (plt
->output_section
->vma
8479 + plt
->output_offset
8481 htab
->root
.sgot
->contents
8482 + (h
->got
.offset
& ~(bfd_vma
) 1));
8486 else if (bfd_link_pic (info
) && SYMBOL_REFERENCES_LOCAL (info
, h
))
8488 if (!h
->def_regular
)
8491 BFD_ASSERT ((h
->got
.offset
& 1) != 0);
8492 rela
.r_info
= ELFNN_R_INFO (0, AARCH64_R (RELATIVE
));
8493 rela
.r_addend
= (h
->root
.u
.def
.value
8494 + h
->root
.u
.def
.section
->output_section
->vma
8495 + h
->root
.u
.def
.section
->output_offset
);
8500 BFD_ASSERT ((h
->got
.offset
& 1) == 0);
8501 bfd_put_NN (output_bfd
, (bfd_vma
) 0,
8502 htab
->root
.sgot
->contents
+ h
->got
.offset
);
8503 rela
.r_info
= ELFNN_R_INFO (h
->dynindx
, AARCH64_R (GLOB_DAT
));
8507 loc
= htab
->root
.srelgot
->contents
;
8508 loc
+= htab
->root
.srelgot
->reloc_count
++ * RELOC_SIZE (htab
);
8509 bfd_elfNN_swap_reloca_out (output_bfd
, &rela
, loc
);
8514 Elf_Internal_Rela rela
;
8517 /* This symbol needs a copy reloc. Set it up. */
8519 if (h
->dynindx
== -1
8520 || (h
->root
.type
!= bfd_link_hash_defined
8521 && h
->root
.type
!= bfd_link_hash_defweak
)
8522 || htab
->srelbss
== NULL
)
8525 rela
.r_offset
= (h
->root
.u
.def
.value
8526 + h
->root
.u
.def
.section
->output_section
->vma
8527 + h
->root
.u
.def
.section
->output_offset
);
8528 rela
.r_info
= ELFNN_R_INFO (h
->dynindx
, AARCH64_R (COPY
));
8530 loc
= htab
->srelbss
->contents
;
8531 loc
+= htab
->srelbss
->reloc_count
++ * RELOC_SIZE (htab
);
8532 bfd_elfNN_swap_reloca_out (output_bfd
, &rela
, loc
);
8535 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. SYM may
8536 be NULL for local symbols. */
8538 && (h
== elf_hash_table (info
)->hdynamic
8539 || h
== elf_hash_table (info
)->hgot
))
8540 sym
->st_shndx
= SHN_ABS
;
8545 /* Finish up local dynamic symbol handling. We set the contents of
8546 various dynamic sections here. */
8549 elfNN_aarch64_finish_local_dynamic_symbol (void **slot
, void *inf
)
8551 struct elf_link_hash_entry
*h
8552 = (struct elf_link_hash_entry
*) *slot
;
8553 struct bfd_link_info
*info
8554 = (struct bfd_link_info
*) inf
;
8556 return elfNN_aarch64_finish_dynamic_symbol (info
->output_bfd
,
8561 elfNN_aarch64_init_small_plt0_entry (bfd
*output_bfd ATTRIBUTE_UNUSED
,
8562 struct elf_aarch64_link_hash_table
8565 /* Fill in PLT0. Fixme:RR Note this doesn't distinguish between
8566 small and large plts and at the minute just generates
8569 /* PLT0 of the small PLT looks like this in ELF64 -
8570 stp x16, x30, [sp, #-16]! // Save the reloc and lr on stack.
8571 adrp x16, PLT_GOT + 16 // Get the page base of the GOTPLT
8572 ldr x17, [x16, #:lo12:PLT_GOT+16] // Load the address of the
8574 add x16, x16, #:lo12:PLT_GOT+16 // Load the lo12 bits of the
8575 // GOTPLT entry for this.
8577 PLT0 will be slightly different in ELF32 due to different got entry
8580 bfd_vma plt_got_2nd_ent
; /* Address of GOT[2]. */
8584 memcpy (htab
->root
.splt
->contents
, elfNN_aarch64_small_plt0_entry
,
8586 elf_section_data (htab
->root
.splt
->output_section
)->this_hdr
.sh_entsize
=
8589 plt_got_2nd_ent
= (htab
->root
.sgotplt
->output_section
->vma
8590 + htab
->root
.sgotplt
->output_offset
8591 + GOT_ENTRY_SIZE
* 2);
8593 plt_base
= htab
->root
.splt
->output_section
->vma
+
8594 htab
->root
.splt
->output_offset
;
8596 /* Fill in the top 21 bits for this: ADRP x16, PLT_GOT + n * 8.
8597 ADRP: ((PG(S+A)-PG(P)) >> 12) & 0x1fffff */
8598 elf_aarch64_update_plt_entry (output_bfd
, BFD_RELOC_AARCH64_ADR_HI21_PCREL
,
8599 htab
->root
.splt
->contents
+ 4,
8600 PG (plt_got_2nd_ent
) - PG (plt_base
+ 4));
8602 elf_aarch64_update_plt_entry (output_bfd
, BFD_RELOC_AARCH64_LDSTNN_LO12
,
8603 htab
->root
.splt
->contents
+ 8,
8604 PG_OFFSET (plt_got_2nd_ent
));
8606 elf_aarch64_update_plt_entry (output_bfd
, BFD_RELOC_AARCH64_ADD_LO12
,
8607 htab
->root
.splt
->contents
+ 12,
8608 PG_OFFSET (plt_got_2nd_ent
));
8612 elfNN_aarch64_finish_dynamic_sections (bfd
*output_bfd
,
8613 struct bfd_link_info
*info
)
8615 struct elf_aarch64_link_hash_table
*htab
;
8619 htab
= elf_aarch64_hash_table (info
);
8620 dynobj
= htab
->root
.dynobj
;
8621 sdyn
= bfd_get_linker_section (dynobj
, ".dynamic");
8623 if (htab
->root
.dynamic_sections_created
)
8625 ElfNN_External_Dyn
*dyncon
, *dynconend
;
8627 if (sdyn
== NULL
|| htab
->root
.sgot
== NULL
)
8630 dyncon
= (ElfNN_External_Dyn
*) sdyn
->contents
;
8631 dynconend
= (ElfNN_External_Dyn
*) (sdyn
->contents
+ sdyn
->size
);
8632 for (; dyncon
< dynconend
; dyncon
++)
8634 Elf_Internal_Dyn dyn
;
8637 bfd_elfNN_swap_dyn_in (dynobj
, dyncon
, &dyn
);
8645 s
= htab
->root
.sgotplt
;
8646 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
8650 dyn
.d_un
.d_ptr
= htab
->root
.srelplt
->output_section
->vma
;
8654 s
= htab
->root
.srelplt
;
8655 dyn
.d_un
.d_val
= s
->size
;
8659 /* The procedure linkage table relocs (DT_JMPREL) should
8660 not be included in the overall relocs (DT_RELA).
8661 Therefore, we override the DT_RELASZ entry here to
8662 make it not include the JMPREL relocs. Since the
8663 linker script arranges for .rela.plt to follow all
8664 other relocation sections, we don't have to worry
8665 about changing the DT_RELA entry. */
8666 if (htab
->root
.srelplt
!= NULL
)
8668 s
= htab
->root
.srelplt
;
8669 dyn
.d_un
.d_val
-= s
->size
;
8673 case DT_TLSDESC_PLT
:
8674 s
= htab
->root
.splt
;
8675 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
8676 + htab
->tlsdesc_plt
;
8679 case DT_TLSDESC_GOT
:
8680 s
= htab
->root
.sgot
;
8681 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
8682 + htab
->dt_tlsdesc_got
;
8686 bfd_elfNN_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
8691 /* Fill in the special first entry in the procedure linkage table. */
8692 if (htab
->root
.splt
&& htab
->root
.splt
->size
> 0)
8694 elfNN_aarch64_init_small_plt0_entry (output_bfd
, htab
);
8696 elf_section_data (htab
->root
.splt
->output_section
)->
8697 this_hdr
.sh_entsize
= htab
->plt_entry_size
;
8700 if (htab
->tlsdesc_plt
)
8702 bfd_put_NN (output_bfd
, (bfd_vma
) 0,
8703 htab
->root
.sgot
->contents
+ htab
->dt_tlsdesc_got
);
8705 memcpy (htab
->root
.splt
->contents
+ htab
->tlsdesc_plt
,
8706 elfNN_aarch64_tlsdesc_small_plt_entry
,
8707 sizeof (elfNN_aarch64_tlsdesc_small_plt_entry
));
8710 bfd_vma adrp1_addr
=
8711 htab
->root
.splt
->output_section
->vma
8712 + htab
->root
.splt
->output_offset
+ htab
->tlsdesc_plt
+ 4;
8714 bfd_vma adrp2_addr
= adrp1_addr
+ 4;
8717 htab
->root
.sgot
->output_section
->vma
8718 + htab
->root
.sgot
->output_offset
;
8720 bfd_vma pltgot_addr
=
8721 htab
->root
.sgotplt
->output_section
->vma
8722 + htab
->root
.sgotplt
->output_offset
;
8724 bfd_vma dt_tlsdesc_got
= got_addr
+ htab
->dt_tlsdesc_got
;
8726 bfd_byte
*plt_entry
=
8727 htab
->root
.splt
->contents
+ htab
->tlsdesc_plt
;
8729 /* adrp x2, DT_TLSDESC_GOT */
8730 elf_aarch64_update_plt_entry (output_bfd
,
8731 BFD_RELOC_AARCH64_ADR_HI21_PCREL
,
8733 (PG (dt_tlsdesc_got
)
8734 - PG (adrp1_addr
)));
8737 elf_aarch64_update_plt_entry (output_bfd
,
8738 BFD_RELOC_AARCH64_ADR_HI21_PCREL
,
8741 - PG (adrp2_addr
)));
8743 /* ldr x2, [x2, #0] */
8744 elf_aarch64_update_plt_entry (output_bfd
,
8745 BFD_RELOC_AARCH64_LDSTNN_LO12
,
8747 PG_OFFSET (dt_tlsdesc_got
));
8750 elf_aarch64_update_plt_entry (output_bfd
,
8751 BFD_RELOC_AARCH64_ADD_LO12
,
8753 PG_OFFSET (pltgot_addr
));
8758 if (htab
->root
.sgotplt
)
8760 if (bfd_is_abs_section (htab
->root
.sgotplt
->output_section
))
8762 (*_bfd_error_handler
)
8763 (_("discarded output section: `%A'"), htab
->root
.sgotplt
);
8767 /* Fill in the first three entries in the global offset table. */
8768 if (htab
->root
.sgotplt
->size
> 0)
8770 bfd_put_NN (output_bfd
, (bfd_vma
) 0, htab
->root
.sgotplt
->contents
);
8772 /* Write GOT[1] and GOT[2], needed for the dynamic linker. */
8773 bfd_put_NN (output_bfd
,
8775 htab
->root
.sgotplt
->contents
+ GOT_ENTRY_SIZE
);
8776 bfd_put_NN (output_bfd
,
8778 htab
->root
.sgotplt
->contents
+ GOT_ENTRY_SIZE
* 2);
8781 if (htab
->root
.sgot
)
8783 if (htab
->root
.sgot
->size
> 0)
8786 sdyn
? sdyn
->output_section
->vma
+ sdyn
->output_offset
: 0;
8787 bfd_put_NN (output_bfd
, addr
, htab
->root
.sgot
->contents
);
8791 elf_section_data (htab
->root
.sgotplt
->output_section
)->
8792 this_hdr
.sh_entsize
= GOT_ENTRY_SIZE
;
8795 if (htab
->root
.sgot
&& htab
->root
.sgot
->size
> 0)
8796 elf_section_data (htab
->root
.sgot
->output_section
)->this_hdr
.sh_entsize
8799 /* Fill PLT and GOT entries for local STT_GNU_IFUNC symbols. */
8800 htab_traverse (htab
->loc_hash_table
,
8801 elfNN_aarch64_finish_local_dynamic_symbol
,
8807 /* Return address for Ith PLT stub in section PLT, for relocation REL
8808 or (bfd_vma) -1 if it should not be included. */
8811 elfNN_aarch64_plt_sym_val (bfd_vma i
, const asection
*plt
,
8812 const arelent
*rel ATTRIBUTE_UNUSED
)
8814 return plt
->vma
+ PLT_ENTRY_SIZE
+ i
* PLT_SMALL_ENTRY_SIZE
;
8818 /* We use this so we can override certain functions
8819 (though currently we don't). */
8821 const struct elf_size_info elfNN_aarch64_size_info
=
8823 sizeof (ElfNN_External_Ehdr
),
8824 sizeof (ElfNN_External_Phdr
),
8825 sizeof (ElfNN_External_Shdr
),
8826 sizeof (ElfNN_External_Rel
),
8827 sizeof (ElfNN_External_Rela
),
8828 sizeof (ElfNN_External_Sym
),
8829 sizeof (ElfNN_External_Dyn
),
8830 sizeof (Elf_External_Note
),
8831 4, /* Hash table entry size. */
8832 1, /* Internal relocs per external relocs. */
8833 ARCH_SIZE
, /* Arch size. */
8834 LOG_FILE_ALIGN
, /* Log_file_align. */
8835 ELFCLASSNN
, EV_CURRENT
,
8836 bfd_elfNN_write_out_phdrs
,
8837 bfd_elfNN_write_shdrs_and_ehdr
,
8838 bfd_elfNN_checksum_contents
,
8839 bfd_elfNN_write_relocs
,
8840 bfd_elfNN_swap_symbol_in
,
8841 bfd_elfNN_swap_symbol_out
,
8842 bfd_elfNN_slurp_reloc_table
,
8843 bfd_elfNN_slurp_symbol_table
,
8844 bfd_elfNN_swap_dyn_in
,
8845 bfd_elfNN_swap_dyn_out
,
8846 bfd_elfNN_swap_reloc_in
,
8847 bfd_elfNN_swap_reloc_out
,
8848 bfd_elfNN_swap_reloca_in
,
8849 bfd_elfNN_swap_reloca_out
8852 #define ELF_ARCH bfd_arch_aarch64
8853 #define ELF_MACHINE_CODE EM_AARCH64
8854 #define ELF_MAXPAGESIZE 0x10000
8855 #define ELF_MINPAGESIZE 0x1000
8856 #define ELF_COMMONPAGESIZE 0x1000
8858 #define bfd_elfNN_close_and_cleanup \
8859 elfNN_aarch64_close_and_cleanup
8861 #define bfd_elfNN_bfd_free_cached_info \
8862 elfNN_aarch64_bfd_free_cached_info
8864 #define bfd_elfNN_bfd_is_target_special_symbol \
8865 elfNN_aarch64_is_target_special_symbol
8867 #define bfd_elfNN_bfd_link_hash_table_create \
8868 elfNN_aarch64_link_hash_table_create
8870 #define bfd_elfNN_bfd_merge_private_bfd_data \
8871 elfNN_aarch64_merge_private_bfd_data
8873 #define bfd_elfNN_bfd_print_private_bfd_data \
8874 elfNN_aarch64_print_private_bfd_data
8876 #define bfd_elfNN_bfd_reloc_type_lookup \
8877 elfNN_aarch64_reloc_type_lookup
8879 #define bfd_elfNN_bfd_reloc_name_lookup \
8880 elfNN_aarch64_reloc_name_lookup
8882 #define bfd_elfNN_bfd_set_private_flags \
8883 elfNN_aarch64_set_private_flags
8885 #define bfd_elfNN_find_inliner_info \
8886 elfNN_aarch64_find_inliner_info
8888 #define bfd_elfNN_find_nearest_line \
8889 elfNN_aarch64_find_nearest_line
8891 #define bfd_elfNN_mkobject \
8892 elfNN_aarch64_mkobject
8894 #define bfd_elfNN_new_section_hook \
8895 elfNN_aarch64_new_section_hook
8897 #define elf_backend_adjust_dynamic_symbol \
8898 elfNN_aarch64_adjust_dynamic_symbol
8900 #define elf_backend_always_size_sections \
8901 elfNN_aarch64_always_size_sections
8903 #define elf_backend_check_relocs \
8904 elfNN_aarch64_check_relocs
8906 #define elf_backend_copy_indirect_symbol \
8907 elfNN_aarch64_copy_indirect_symbol
8909 /* Create .dynbss, and .rela.bss sections in DYNOBJ, and set up shortcuts
8910 to them in our hash. */
8911 #define elf_backend_create_dynamic_sections \
8912 elfNN_aarch64_create_dynamic_sections
8914 #define elf_backend_init_index_section \
8915 _bfd_elf_init_2_index_sections
8917 #define elf_backend_finish_dynamic_sections \
8918 elfNN_aarch64_finish_dynamic_sections
8920 #define elf_backend_finish_dynamic_symbol \
8921 elfNN_aarch64_finish_dynamic_symbol
8923 #define elf_backend_gc_sweep_hook \
8924 elfNN_aarch64_gc_sweep_hook
8926 #define elf_backend_object_p \
8927 elfNN_aarch64_object_p
8929 #define elf_backend_output_arch_local_syms \
8930 elfNN_aarch64_output_arch_local_syms
8932 #define elf_backend_plt_sym_val \
8933 elfNN_aarch64_plt_sym_val
8935 #define elf_backend_post_process_headers \
8936 elfNN_aarch64_post_process_headers
8938 #define elf_backend_relocate_section \
8939 elfNN_aarch64_relocate_section
8941 #define elf_backend_reloc_type_class \
8942 elfNN_aarch64_reloc_type_class
8944 #define elf_backend_section_from_shdr \
8945 elfNN_aarch64_section_from_shdr
8947 #define elf_backend_size_dynamic_sections \
8948 elfNN_aarch64_size_dynamic_sections
8950 #define elf_backend_size_info \
8951 elfNN_aarch64_size_info
8953 #define elf_backend_write_section \
8954 elfNN_aarch64_write_section
8956 #define elf_backend_can_refcount 1
8957 #define elf_backend_can_gc_sections 1
8958 #define elf_backend_plt_readonly 1
8959 #define elf_backend_want_got_plt 1
8960 #define elf_backend_want_plt_sym 0
8961 #define elf_backend_may_use_rel_p 0
8962 #define elf_backend_may_use_rela_p 1
8963 #define elf_backend_default_use_rela_p 1
8964 #define elf_backend_rela_normal 1
8965 #define elf_backend_got_header_size (GOT_ENTRY_SIZE * 3)
8966 #define elf_backend_default_execstack 0
8967 #define elf_backend_extern_protected_data 1
8969 #undef elf_backend_obj_attrs_section
8970 #define elf_backend_obj_attrs_section ".ARM.attributes"
8972 #include "elfNN-target.h"