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_TLSGD_MOVW_G1 \
172 || (R_TYPE) == BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21 \
173 || (R_TYPE) == BFD_RELOC_AARCH64_TLSIE_LD32_GOTTPREL_LO12_NC \
174 || (R_TYPE) == BFD_RELOC_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC \
175 || (R_TYPE) == BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19 \
176 || (R_TYPE) == BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G0_NC \
177 || (R_TYPE) == BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G1 \
178 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_ADD_DTPREL_HI12 \
179 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_ADD_DTPREL_LO12 \
180 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_ADD_DTPREL_LO12_NC \
181 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC \
182 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21 \
183 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_ADR_PREL21 \
184 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_LDST16_DTPREL_LO12 \
185 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_LDST16_DTPREL_LO12_NC \
186 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_LDST32_DTPREL_LO12 \
187 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_LDST32_DTPREL_LO12_NC \
188 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_LDST64_DTPREL_LO12 \
189 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_LDST64_DTPREL_LO12_NC \
190 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_LDST8_DTPREL_LO12 \
191 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_LDST8_DTPREL_LO12_NC \
192 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G0 \
193 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G0_NC \
194 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G1 \
195 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G1_NC \
196 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G2 \
197 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_HI12 \
198 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_LO12 \
199 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_LO12_NC \
200 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0 \
201 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC \
202 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1 \
203 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1_NC \
204 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G2 \
205 || (R_TYPE) == BFD_RELOC_AARCH64_TLS_DTPMOD \
206 || (R_TYPE) == BFD_RELOC_AARCH64_TLS_DTPREL \
207 || (R_TYPE) == BFD_RELOC_AARCH64_TLS_TPREL \
208 || IS_AARCH64_TLSDESC_RELOC ((R_TYPE)))
210 #define IS_AARCH64_TLS_RELAX_RELOC(R_TYPE) \
211 ((R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_ADD_LO12_NC \
212 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21 \
213 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21 \
214 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_CALL \
215 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_LD_PREL19 \
216 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_LDNN_LO12_NC \
217 || (R_TYPE) == BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21 \
218 || (R_TYPE) == BFD_RELOC_AARCH64_TLSGD_ADR_PREL21 \
219 || (R_TYPE) == BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC \
220 || (R_TYPE) == BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21 \
221 || (R_TYPE) == BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19 \
222 || (R_TYPE) == BFD_RELOC_AARCH64_TLSIE_LDNN_GOTTPREL_LO12_NC \
223 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC \
224 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21 \
225 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_ADR_PREL21)
227 #define IS_AARCH64_TLSDESC_RELOC(R_TYPE) \
228 ((R_TYPE) == BFD_RELOC_AARCH64_TLSDESC \
229 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_ADD \
230 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_ADD_LO12_NC \
231 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21 \
232 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21 \
233 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_CALL \
234 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_LD32_LO12_NC \
235 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_LD64_LO12_NC \
236 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_LDR \
237 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_LD_PREL19 \
238 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_OFF_G0_NC \
239 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_OFF_G1)
241 #define ELIMINATE_COPY_RELOCS 0
243 /* Return size of a relocation entry. HTAB is the bfd's
244 elf_aarch64_link_hash_entry. */
245 #define RELOC_SIZE(HTAB) (sizeof (ElfNN_External_Rela))
247 /* GOT Entry size - 8 bytes in ELF64 and 4 bytes in ELF32. */
248 #define GOT_ENTRY_SIZE (ARCH_SIZE / 8)
249 #define PLT_ENTRY_SIZE (32)
250 #define PLT_SMALL_ENTRY_SIZE (16)
251 #define PLT_TLSDESC_ENTRY_SIZE (32)
253 /* Encoding of the nop instruction */
254 #define INSN_NOP 0xd503201f
256 #define aarch64_compute_jump_table_size(htab) \
257 (((htab)->root.srelplt == NULL) ? 0 \
258 : (htab)->root.srelplt->reloc_count * GOT_ENTRY_SIZE)
260 /* The first entry in a procedure linkage table looks like this
261 if the distance between the PLTGOT and the PLT is < 4GB use
262 these PLT entries. Note that the dynamic linker gets &PLTGOT[2]
263 in x16 and needs to work out PLTGOT[1] by using an address of
264 [x16,#-GOT_ENTRY_SIZE]. */
265 static const bfd_byte elfNN_aarch64_small_plt0_entry
[PLT_ENTRY_SIZE
] =
267 0xf0, 0x7b, 0xbf, 0xa9, /* stp x16, x30, [sp, #-16]! */
268 0x10, 0x00, 0x00, 0x90, /* adrp x16, (GOT+16) */
270 0x11, 0x0A, 0x40, 0xf9, /* ldr x17, [x16, #PLT_GOT+0x10] */
271 0x10, 0x42, 0x00, 0x91, /* add x16, x16,#PLT_GOT+0x10 */
273 0x11, 0x0A, 0x40, 0xb9, /* ldr w17, [x16, #PLT_GOT+0x8] */
274 0x10, 0x22, 0x00, 0x11, /* add w16, w16,#PLT_GOT+0x8 */
276 0x20, 0x02, 0x1f, 0xd6, /* br x17 */
277 0x1f, 0x20, 0x03, 0xd5, /* nop */
278 0x1f, 0x20, 0x03, 0xd5, /* nop */
279 0x1f, 0x20, 0x03, 0xd5, /* nop */
282 /* Per function entry in a procedure linkage table looks like this
283 if the distance between the PLTGOT and the PLT is < 4GB use
284 these PLT entries. */
285 static const bfd_byte elfNN_aarch64_small_plt_entry
[PLT_SMALL_ENTRY_SIZE
] =
287 0x10, 0x00, 0x00, 0x90, /* adrp x16, PLTGOT + n * 8 */
289 0x11, 0x02, 0x40, 0xf9, /* ldr x17, [x16, PLTGOT + n * 8] */
290 0x10, 0x02, 0x00, 0x91, /* add x16, x16, :lo12:PLTGOT + n * 8 */
292 0x11, 0x02, 0x40, 0xb9, /* ldr w17, [x16, PLTGOT + n * 4] */
293 0x10, 0x02, 0x00, 0x11, /* add w16, w16, :lo12:PLTGOT + n * 4 */
295 0x20, 0x02, 0x1f, 0xd6, /* br x17. */
298 static const bfd_byte
299 elfNN_aarch64_tlsdesc_small_plt_entry
[PLT_TLSDESC_ENTRY_SIZE
] =
301 0xe2, 0x0f, 0xbf, 0xa9, /* stp x2, x3, [sp, #-16]! */
302 0x02, 0x00, 0x00, 0x90, /* adrp x2, 0 */
303 0x03, 0x00, 0x00, 0x90, /* adrp x3, 0 */
305 0x42, 0x00, 0x40, 0xf9, /* ldr x2, [x2, #0] */
306 0x63, 0x00, 0x00, 0x91, /* add x3, x3, 0 */
308 0x42, 0x00, 0x40, 0xb9, /* ldr w2, [x2, #0] */
309 0x63, 0x00, 0x00, 0x11, /* add w3, w3, 0 */
311 0x40, 0x00, 0x1f, 0xd6, /* br x2 */
312 0x1f, 0x20, 0x03, 0xd5, /* nop */
313 0x1f, 0x20, 0x03, 0xd5, /* nop */
316 #define elf_info_to_howto elfNN_aarch64_info_to_howto
317 #define elf_info_to_howto_rel elfNN_aarch64_info_to_howto
319 #define AARCH64_ELF_ABI_VERSION 0
321 /* In case we're on a 32-bit machine, construct a 64-bit "-1" value. */
322 #define ALL_ONES (~ (bfd_vma) 0)
324 /* Indexed by the bfd interal reloc enumerators.
325 Therefore, the table needs to be synced with BFD_RELOC_AARCH64_*
328 static reloc_howto_type elfNN_aarch64_howto_table
[] =
332 /* Basic data relocations. */
335 HOWTO (R_AARCH64_NULL
, /* type */
337 3, /* size (0 = byte, 1 = short, 2 = long) */
339 FALSE
, /* pc_relative */
341 complain_overflow_dont
, /* complain_on_overflow */
342 bfd_elf_generic_reloc
, /* special_function */
343 "R_AARCH64_NULL", /* name */
344 FALSE
, /* partial_inplace */
347 FALSE
), /* pcrel_offset */
349 HOWTO (R_AARCH64_NONE
, /* type */
351 3, /* size (0 = byte, 1 = short, 2 = long) */
353 FALSE
, /* pc_relative */
355 complain_overflow_dont
, /* complain_on_overflow */
356 bfd_elf_generic_reloc
, /* special_function */
357 "R_AARCH64_NONE", /* name */
358 FALSE
, /* partial_inplace */
361 FALSE
), /* pcrel_offset */
365 HOWTO64 (AARCH64_R (ABS64
), /* type */
367 4, /* size (4 = long long) */
369 FALSE
, /* pc_relative */
371 complain_overflow_unsigned
, /* complain_on_overflow */
372 bfd_elf_generic_reloc
, /* special_function */
373 AARCH64_R_STR (ABS64
), /* name */
374 FALSE
, /* partial_inplace */
375 ALL_ONES
, /* src_mask */
376 ALL_ONES
, /* dst_mask */
377 FALSE
), /* pcrel_offset */
380 HOWTO (AARCH64_R (ABS32
), /* type */
382 2, /* size (0 = byte, 1 = short, 2 = long) */
384 FALSE
, /* pc_relative */
386 complain_overflow_unsigned
, /* complain_on_overflow */
387 bfd_elf_generic_reloc
, /* special_function */
388 AARCH64_R_STR (ABS32
), /* name */
389 FALSE
, /* partial_inplace */
390 0xffffffff, /* src_mask */
391 0xffffffff, /* dst_mask */
392 FALSE
), /* pcrel_offset */
395 HOWTO (AARCH64_R (ABS16
), /* type */
397 1, /* size (0 = byte, 1 = short, 2 = long) */
399 FALSE
, /* pc_relative */
401 complain_overflow_unsigned
, /* complain_on_overflow */
402 bfd_elf_generic_reloc
, /* special_function */
403 AARCH64_R_STR (ABS16
), /* name */
404 FALSE
, /* partial_inplace */
405 0xffff, /* src_mask */
406 0xffff, /* dst_mask */
407 FALSE
), /* pcrel_offset */
409 /* .xword: (S+A-P) */
410 HOWTO64 (AARCH64_R (PREL64
), /* type */
412 4, /* size (4 = long long) */
414 TRUE
, /* pc_relative */
416 complain_overflow_signed
, /* complain_on_overflow */
417 bfd_elf_generic_reloc
, /* special_function */
418 AARCH64_R_STR (PREL64
), /* name */
419 FALSE
, /* partial_inplace */
420 ALL_ONES
, /* src_mask */
421 ALL_ONES
, /* dst_mask */
422 TRUE
), /* pcrel_offset */
425 HOWTO (AARCH64_R (PREL32
), /* type */
427 2, /* size (0 = byte, 1 = short, 2 = long) */
429 TRUE
, /* pc_relative */
431 complain_overflow_signed
, /* complain_on_overflow */
432 bfd_elf_generic_reloc
, /* special_function */
433 AARCH64_R_STR (PREL32
), /* name */
434 FALSE
, /* partial_inplace */
435 0xffffffff, /* src_mask */
436 0xffffffff, /* dst_mask */
437 TRUE
), /* pcrel_offset */
440 HOWTO (AARCH64_R (PREL16
), /* type */
442 1, /* size (0 = byte, 1 = short, 2 = long) */
444 TRUE
, /* pc_relative */
446 complain_overflow_signed
, /* complain_on_overflow */
447 bfd_elf_generic_reloc
, /* special_function */
448 AARCH64_R_STR (PREL16
), /* name */
449 FALSE
, /* partial_inplace */
450 0xffff, /* src_mask */
451 0xffff, /* dst_mask */
452 TRUE
), /* pcrel_offset */
454 /* Group relocations to create a 16, 32, 48 or 64 bit
455 unsigned data or abs address inline. */
457 /* MOVZ: ((S+A) >> 0) & 0xffff */
458 HOWTO (AARCH64_R (MOVW_UABS_G0
), /* type */
460 2, /* size (0 = byte, 1 = short, 2 = long) */
462 FALSE
, /* pc_relative */
464 complain_overflow_unsigned
, /* complain_on_overflow */
465 bfd_elf_generic_reloc
, /* special_function */
466 AARCH64_R_STR (MOVW_UABS_G0
), /* name */
467 FALSE
, /* partial_inplace */
468 0xffff, /* src_mask */
469 0xffff, /* dst_mask */
470 FALSE
), /* pcrel_offset */
472 /* MOVK: ((S+A) >> 0) & 0xffff [no overflow check] */
473 HOWTO (AARCH64_R (MOVW_UABS_G0_NC
), /* type */
475 2, /* size (0 = byte, 1 = short, 2 = long) */
477 FALSE
, /* pc_relative */
479 complain_overflow_dont
, /* complain_on_overflow */
480 bfd_elf_generic_reloc
, /* special_function */
481 AARCH64_R_STR (MOVW_UABS_G0_NC
), /* name */
482 FALSE
, /* partial_inplace */
483 0xffff, /* src_mask */
484 0xffff, /* dst_mask */
485 FALSE
), /* pcrel_offset */
487 /* MOVZ: ((S+A) >> 16) & 0xffff */
488 HOWTO (AARCH64_R (MOVW_UABS_G1
), /* type */
490 2, /* size (0 = byte, 1 = short, 2 = long) */
492 FALSE
, /* pc_relative */
494 complain_overflow_unsigned
, /* complain_on_overflow */
495 bfd_elf_generic_reloc
, /* special_function */
496 AARCH64_R_STR (MOVW_UABS_G1
), /* name */
497 FALSE
, /* partial_inplace */
498 0xffff, /* src_mask */
499 0xffff, /* dst_mask */
500 FALSE
), /* pcrel_offset */
502 /* MOVK: ((S+A) >> 16) & 0xffff [no overflow check] */
503 HOWTO64 (AARCH64_R (MOVW_UABS_G1_NC
), /* type */
505 2, /* size (0 = byte, 1 = short, 2 = long) */
507 FALSE
, /* pc_relative */
509 complain_overflow_dont
, /* complain_on_overflow */
510 bfd_elf_generic_reloc
, /* special_function */
511 AARCH64_R_STR (MOVW_UABS_G1_NC
), /* name */
512 FALSE
, /* partial_inplace */
513 0xffff, /* src_mask */
514 0xffff, /* dst_mask */
515 FALSE
), /* pcrel_offset */
517 /* MOVZ: ((S+A) >> 32) & 0xffff */
518 HOWTO64 (AARCH64_R (MOVW_UABS_G2
), /* type */
520 2, /* size (0 = byte, 1 = short, 2 = long) */
522 FALSE
, /* pc_relative */
524 complain_overflow_unsigned
, /* complain_on_overflow */
525 bfd_elf_generic_reloc
, /* special_function */
526 AARCH64_R_STR (MOVW_UABS_G2
), /* name */
527 FALSE
, /* partial_inplace */
528 0xffff, /* src_mask */
529 0xffff, /* dst_mask */
530 FALSE
), /* pcrel_offset */
532 /* MOVK: ((S+A) >> 32) & 0xffff [no overflow check] */
533 HOWTO64 (AARCH64_R (MOVW_UABS_G2_NC
), /* type */
535 2, /* size (0 = byte, 1 = short, 2 = long) */
537 FALSE
, /* pc_relative */
539 complain_overflow_dont
, /* complain_on_overflow */
540 bfd_elf_generic_reloc
, /* special_function */
541 AARCH64_R_STR (MOVW_UABS_G2_NC
), /* name */
542 FALSE
, /* partial_inplace */
543 0xffff, /* src_mask */
544 0xffff, /* dst_mask */
545 FALSE
), /* pcrel_offset */
547 /* MOVZ: ((S+A) >> 48) & 0xffff */
548 HOWTO64 (AARCH64_R (MOVW_UABS_G3
), /* type */
550 2, /* size (0 = byte, 1 = short, 2 = long) */
552 FALSE
, /* pc_relative */
554 complain_overflow_unsigned
, /* complain_on_overflow */
555 bfd_elf_generic_reloc
, /* special_function */
556 AARCH64_R_STR (MOVW_UABS_G3
), /* name */
557 FALSE
, /* partial_inplace */
558 0xffff, /* src_mask */
559 0xffff, /* dst_mask */
560 FALSE
), /* pcrel_offset */
562 /* Group relocations to create high part of a 16, 32, 48 or 64 bit
563 signed data or abs address inline. Will change instruction
564 to MOVN or MOVZ depending on sign of calculated value. */
566 /* MOV[ZN]: ((S+A) >> 0) & 0xffff */
567 HOWTO (AARCH64_R (MOVW_SABS_G0
), /* type */
569 2, /* size (0 = byte, 1 = short, 2 = long) */
571 FALSE
, /* pc_relative */
573 complain_overflow_signed
, /* complain_on_overflow */
574 bfd_elf_generic_reloc
, /* special_function */
575 AARCH64_R_STR (MOVW_SABS_G0
), /* name */
576 FALSE
, /* partial_inplace */
577 0xffff, /* src_mask */
578 0xffff, /* dst_mask */
579 FALSE
), /* pcrel_offset */
581 /* MOV[ZN]: ((S+A) >> 16) & 0xffff */
582 HOWTO64 (AARCH64_R (MOVW_SABS_G1
), /* type */
584 2, /* size (0 = byte, 1 = short, 2 = long) */
586 FALSE
, /* pc_relative */
588 complain_overflow_signed
, /* complain_on_overflow */
589 bfd_elf_generic_reloc
, /* special_function */
590 AARCH64_R_STR (MOVW_SABS_G1
), /* name */
591 FALSE
, /* partial_inplace */
592 0xffff, /* src_mask */
593 0xffff, /* dst_mask */
594 FALSE
), /* pcrel_offset */
596 /* MOV[ZN]: ((S+A) >> 32) & 0xffff */
597 HOWTO64 (AARCH64_R (MOVW_SABS_G2
), /* type */
599 2, /* size (0 = byte, 1 = short, 2 = long) */
601 FALSE
, /* pc_relative */
603 complain_overflow_signed
, /* complain_on_overflow */
604 bfd_elf_generic_reloc
, /* special_function */
605 AARCH64_R_STR (MOVW_SABS_G2
), /* name */
606 FALSE
, /* partial_inplace */
607 0xffff, /* src_mask */
608 0xffff, /* dst_mask */
609 FALSE
), /* pcrel_offset */
611 /* Relocations to generate 19, 21 and 33 bit PC-relative load/store
612 addresses: PG(x) is (x & ~0xfff). */
614 /* LD-lit: ((S+A-P) >> 2) & 0x7ffff */
615 HOWTO (AARCH64_R (LD_PREL_LO19
), /* type */
617 2, /* size (0 = byte, 1 = short, 2 = long) */
619 TRUE
, /* pc_relative */
621 complain_overflow_signed
, /* complain_on_overflow */
622 bfd_elf_generic_reloc
, /* special_function */
623 AARCH64_R_STR (LD_PREL_LO19
), /* name */
624 FALSE
, /* partial_inplace */
625 0x7ffff, /* src_mask */
626 0x7ffff, /* dst_mask */
627 TRUE
), /* pcrel_offset */
629 /* ADR: (S+A-P) & 0x1fffff */
630 HOWTO (AARCH64_R (ADR_PREL_LO21
), /* type */
632 2, /* size (0 = byte, 1 = short, 2 = long) */
634 TRUE
, /* pc_relative */
636 complain_overflow_signed
, /* complain_on_overflow */
637 bfd_elf_generic_reloc
, /* special_function */
638 AARCH64_R_STR (ADR_PREL_LO21
), /* name */
639 FALSE
, /* partial_inplace */
640 0x1fffff, /* src_mask */
641 0x1fffff, /* dst_mask */
642 TRUE
), /* pcrel_offset */
644 /* ADRP: ((PG(S+A)-PG(P)) >> 12) & 0x1fffff */
645 HOWTO (AARCH64_R (ADR_PREL_PG_HI21
), /* type */
647 2, /* size (0 = byte, 1 = short, 2 = long) */
649 TRUE
, /* pc_relative */
651 complain_overflow_signed
, /* complain_on_overflow */
652 bfd_elf_generic_reloc
, /* special_function */
653 AARCH64_R_STR (ADR_PREL_PG_HI21
), /* name */
654 FALSE
, /* partial_inplace */
655 0x1fffff, /* src_mask */
656 0x1fffff, /* dst_mask */
657 TRUE
), /* pcrel_offset */
659 /* ADRP: ((PG(S+A)-PG(P)) >> 12) & 0x1fffff [no overflow check] */
660 HOWTO64 (AARCH64_R (ADR_PREL_PG_HI21_NC
), /* type */
662 2, /* size (0 = byte, 1 = short, 2 = long) */
664 TRUE
, /* pc_relative */
666 complain_overflow_dont
, /* complain_on_overflow */
667 bfd_elf_generic_reloc
, /* special_function */
668 AARCH64_R_STR (ADR_PREL_PG_HI21_NC
), /* name */
669 FALSE
, /* partial_inplace */
670 0x1fffff, /* src_mask */
671 0x1fffff, /* dst_mask */
672 TRUE
), /* pcrel_offset */
674 /* ADD: (S+A) & 0xfff [no overflow check] */
675 HOWTO (AARCH64_R (ADD_ABS_LO12_NC
), /* type */
677 2, /* size (0 = byte, 1 = short, 2 = long) */
679 FALSE
, /* pc_relative */
681 complain_overflow_dont
, /* complain_on_overflow */
682 bfd_elf_generic_reloc
, /* special_function */
683 AARCH64_R_STR (ADD_ABS_LO12_NC
), /* name */
684 FALSE
, /* partial_inplace */
685 0x3ffc00, /* src_mask */
686 0x3ffc00, /* dst_mask */
687 FALSE
), /* pcrel_offset */
689 /* LD/ST8: (S+A) & 0xfff */
690 HOWTO (AARCH64_R (LDST8_ABS_LO12_NC
), /* type */
692 2, /* size (0 = byte, 1 = short, 2 = long) */
694 FALSE
, /* pc_relative */
696 complain_overflow_dont
, /* complain_on_overflow */
697 bfd_elf_generic_reloc
, /* special_function */
698 AARCH64_R_STR (LDST8_ABS_LO12_NC
), /* name */
699 FALSE
, /* partial_inplace */
700 0xfff, /* src_mask */
701 0xfff, /* dst_mask */
702 FALSE
), /* pcrel_offset */
704 /* Relocations for control-flow instructions. */
706 /* TBZ/NZ: ((S+A-P) >> 2) & 0x3fff */
707 HOWTO (AARCH64_R (TSTBR14
), /* type */
709 2, /* size (0 = byte, 1 = short, 2 = long) */
711 TRUE
, /* pc_relative */
713 complain_overflow_signed
, /* complain_on_overflow */
714 bfd_elf_generic_reloc
, /* special_function */
715 AARCH64_R_STR (TSTBR14
), /* name */
716 FALSE
, /* partial_inplace */
717 0x3fff, /* src_mask */
718 0x3fff, /* dst_mask */
719 TRUE
), /* pcrel_offset */
721 /* B.cond: ((S+A-P) >> 2) & 0x7ffff */
722 HOWTO (AARCH64_R (CONDBR19
), /* type */
724 2, /* size (0 = byte, 1 = short, 2 = long) */
726 TRUE
, /* pc_relative */
728 complain_overflow_signed
, /* complain_on_overflow */
729 bfd_elf_generic_reloc
, /* special_function */
730 AARCH64_R_STR (CONDBR19
), /* name */
731 FALSE
, /* partial_inplace */
732 0x7ffff, /* src_mask */
733 0x7ffff, /* dst_mask */
734 TRUE
), /* pcrel_offset */
736 /* B: ((S+A-P) >> 2) & 0x3ffffff */
737 HOWTO (AARCH64_R (JUMP26
), /* type */
739 2, /* size (0 = byte, 1 = short, 2 = long) */
741 TRUE
, /* pc_relative */
743 complain_overflow_signed
, /* complain_on_overflow */
744 bfd_elf_generic_reloc
, /* special_function */
745 AARCH64_R_STR (JUMP26
), /* name */
746 FALSE
, /* partial_inplace */
747 0x3ffffff, /* src_mask */
748 0x3ffffff, /* dst_mask */
749 TRUE
), /* pcrel_offset */
751 /* BL: ((S+A-P) >> 2) & 0x3ffffff */
752 HOWTO (AARCH64_R (CALL26
), /* type */
754 2, /* size (0 = byte, 1 = short, 2 = long) */
756 TRUE
, /* pc_relative */
758 complain_overflow_signed
, /* complain_on_overflow */
759 bfd_elf_generic_reloc
, /* special_function */
760 AARCH64_R_STR (CALL26
), /* name */
761 FALSE
, /* partial_inplace */
762 0x3ffffff, /* src_mask */
763 0x3ffffff, /* dst_mask */
764 TRUE
), /* pcrel_offset */
766 /* LD/ST16: (S+A) & 0xffe */
767 HOWTO (AARCH64_R (LDST16_ABS_LO12_NC
), /* type */
769 2, /* size (0 = byte, 1 = short, 2 = long) */
771 FALSE
, /* pc_relative */
773 complain_overflow_dont
, /* complain_on_overflow */
774 bfd_elf_generic_reloc
, /* special_function */
775 AARCH64_R_STR (LDST16_ABS_LO12_NC
), /* name */
776 FALSE
, /* partial_inplace */
777 0xffe, /* src_mask */
778 0xffe, /* dst_mask */
779 FALSE
), /* pcrel_offset */
781 /* LD/ST32: (S+A) & 0xffc */
782 HOWTO (AARCH64_R (LDST32_ABS_LO12_NC
), /* type */
784 2, /* size (0 = byte, 1 = short, 2 = long) */
786 FALSE
, /* pc_relative */
788 complain_overflow_dont
, /* complain_on_overflow */
789 bfd_elf_generic_reloc
, /* special_function */
790 AARCH64_R_STR (LDST32_ABS_LO12_NC
), /* name */
791 FALSE
, /* partial_inplace */
792 0xffc, /* src_mask */
793 0xffc, /* dst_mask */
794 FALSE
), /* pcrel_offset */
796 /* LD/ST64: (S+A) & 0xff8 */
797 HOWTO (AARCH64_R (LDST64_ABS_LO12_NC
), /* type */
799 2, /* size (0 = byte, 1 = short, 2 = long) */
801 FALSE
, /* pc_relative */
803 complain_overflow_dont
, /* complain_on_overflow */
804 bfd_elf_generic_reloc
, /* special_function */
805 AARCH64_R_STR (LDST64_ABS_LO12_NC
), /* name */
806 FALSE
, /* partial_inplace */
807 0xff8, /* src_mask */
808 0xff8, /* dst_mask */
809 FALSE
), /* pcrel_offset */
811 /* LD/ST128: (S+A) & 0xff0 */
812 HOWTO (AARCH64_R (LDST128_ABS_LO12_NC
), /* type */
814 2, /* size (0 = byte, 1 = short, 2 = long) */
816 FALSE
, /* pc_relative */
818 complain_overflow_dont
, /* complain_on_overflow */
819 bfd_elf_generic_reloc
, /* special_function */
820 AARCH64_R_STR (LDST128_ABS_LO12_NC
), /* name */
821 FALSE
, /* partial_inplace */
822 0xff0, /* src_mask */
823 0xff0, /* dst_mask */
824 FALSE
), /* pcrel_offset */
826 /* Set a load-literal immediate field to bits
827 0x1FFFFC of G(S)-P */
828 HOWTO (AARCH64_R (GOT_LD_PREL19
), /* type */
830 2, /* size (0 = byte,1 = short,2 = long) */
832 TRUE
, /* pc_relative */
834 complain_overflow_signed
, /* complain_on_overflow */
835 bfd_elf_generic_reloc
, /* special_function */
836 AARCH64_R_STR (GOT_LD_PREL19
), /* name */
837 FALSE
, /* partial_inplace */
838 0xffffe0, /* src_mask */
839 0xffffe0, /* dst_mask */
840 TRUE
), /* pcrel_offset */
842 /* Get to the page for the GOT entry for the symbol
843 (G(S) - P) using an ADRP instruction. */
844 HOWTO (AARCH64_R (ADR_GOT_PAGE
), /* type */
846 2, /* size (0 = byte, 1 = short, 2 = long) */
848 TRUE
, /* pc_relative */
850 complain_overflow_dont
, /* complain_on_overflow */
851 bfd_elf_generic_reloc
, /* special_function */
852 AARCH64_R_STR (ADR_GOT_PAGE
), /* name */
853 FALSE
, /* partial_inplace */
854 0x1fffff, /* src_mask */
855 0x1fffff, /* dst_mask */
856 TRUE
), /* pcrel_offset */
858 /* LD64: GOT offset G(S) & 0xff8 */
859 HOWTO64 (AARCH64_R (LD64_GOT_LO12_NC
), /* type */
861 2, /* size (0 = byte, 1 = short, 2 = long) */
863 FALSE
, /* pc_relative */
865 complain_overflow_dont
, /* complain_on_overflow */
866 bfd_elf_generic_reloc
, /* special_function */
867 AARCH64_R_STR (LD64_GOT_LO12_NC
), /* name */
868 FALSE
, /* partial_inplace */
869 0xff8, /* src_mask */
870 0xff8, /* dst_mask */
871 FALSE
), /* pcrel_offset */
873 /* LD32: GOT offset G(S) & 0xffc */
874 HOWTO32 (AARCH64_R (LD32_GOT_LO12_NC
), /* type */
876 2, /* size (0 = byte, 1 = short, 2 = long) */
878 FALSE
, /* pc_relative */
880 complain_overflow_dont
, /* complain_on_overflow */
881 bfd_elf_generic_reloc
, /* special_function */
882 AARCH64_R_STR (LD32_GOT_LO12_NC
), /* name */
883 FALSE
, /* partial_inplace */
884 0xffc, /* src_mask */
885 0xffc, /* dst_mask */
886 FALSE
), /* pcrel_offset */
888 /* Lower 16 bits of GOT offset for the symbol. */
889 HOWTO64 (AARCH64_R (MOVW_GOTOFF_G0_NC
), /* type */
891 2, /* size (0 = byte, 1 = short, 2 = long) */
893 FALSE
, /* pc_relative */
895 complain_overflow_dont
, /* complain_on_overflow */
896 bfd_elf_generic_reloc
, /* special_function */
897 AARCH64_R_STR (MOVW_GOTOFF_G0_NC
), /* name */
898 FALSE
, /* partial_inplace */
899 0xffff, /* src_mask */
900 0xffff, /* dst_mask */
901 FALSE
), /* pcrel_offset */
903 /* Higher 16 bits of GOT offset for the symbol. */
904 HOWTO64 (AARCH64_R (MOVW_GOTOFF_G1
), /* type */
906 2, /* size (0 = byte, 1 = short, 2 = long) */
908 FALSE
, /* pc_relative */
910 complain_overflow_unsigned
, /* complain_on_overflow */
911 bfd_elf_generic_reloc
, /* special_function */
912 AARCH64_R_STR (MOVW_GOTOFF_G1
), /* name */
913 FALSE
, /* partial_inplace */
914 0xffff, /* src_mask */
915 0xffff, /* dst_mask */
916 FALSE
), /* pcrel_offset */
918 /* LD64: GOT offset for the symbol. */
919 HOWTO64 (AARCH64_R (LD64_GOTOFF_LO15
), /* type */
921 2, /* size (0 = byte, 1 = short, 2 = long) */
923 FALSE
, /* pc_relative */
925 complain_overflow_unsigned
, /* complain_on_overflow */
926 bfd_elf_generic_reloc
, /* special_function */
927 AARCH64_R_STR (LD64_GOTOFF_LO15
), /* name */
928 FALSE
, /* partial_inplace */
929 0x7ff8, /* src_mask */
930 0x7ff8, /* dst_mask */
931 FALSE
), /* pcrel_offset */
933 /* LD32: GOT offset to the page address of GOT table.
934 (G(S) - PAGE (_GLOBAL_OFFSET_TABLE_)) & 0x5ffc. */
935 HOWTO32 (AARCH64_R (LD32_GOTPAGE_LO14
), /* type */
937 2, /* size (0 = byte, 1 = short, 2 = long) */
939 FALSE
, /* pc_relative */
941 complain_overflow_unsigned
, /* complain_on_overflow */
942 bfd_elf_generic_reloc
, /* special_function */
943 AARCH64_R_STR (LD32_GOTPAGE_LO14
), /* name */
944 FALSE
, /* partial_inplace */
945 0x5ffc, /* src_mask */
946 0x5ffc, /* dst_mask */
947 FALSE
), /* pcrel_offset */
949 /* LD64: GOT offset to the page address of GOT table.
950 (G(S) - PAGE (_GLOBAL_OFFSET_TABLE_)) & 0x7ff8. */
951 HOWTO64 (AARCH64_R (LD64_GOTPAGE_LO15
), /* type */
953 2, /* size (0 = byte, 1 = short, 2 = long) */
955 FALSE
, /* pc_relative */
957 complain_overflow_unsigned
, /* complain_on_overflow */
958 bfd_elf_generic_reloc
, /* special_function */
959 AARCH64_R_STR (LD64_GOTPAGE_LO15
), /* name */
960 FALSE
, /* partial_inplace */
961 0x7ff8, /* src_mask */
962 0x7ff8, /* dst_mask */
963 FALSE
), /* pcrel_offset */
965 /* Get to the page for the GOT entry for the symbol
966 (G(S) - P) using an ADRP instruction. */
967 HOWTO (AARCH64_R (TLSGD_ADR_PAGE21
), /* type */
969 2, /* size (0 = byte, 1 = short, 2 = long) */
971 TRUE
, /* pc_relative */
973 complain_overflow_dont
, /* complain_on_overflow */
974 bfd_elf_generic_reloc
, /* special_function */
975 AARCH64_R_STR (TLSGD_ADR_PAGE21
), /* name */
976 FALSE
, /* partial_inplace */
977 0x1fffff, /* src_mask */
978 0x1fffff, /* dst_mask */
979 TRUE
), /* pcrel_offset */
981 HOWTO (AARCH64_R (TLSGD_ADR_PREL21
), /* type */
983 2, /* size (0 = byte, 1 = short, 2 = long) */
985 TRUE
, /* pc_relative */
987 complain_overflow_dont
, /* complain_on_overflow */
988 bfd_elf_generic_reloc
, /* special_function */
989 AARCH64_R_STR (TLSGD_ADR_PREL21
), /* name */
990 FALSE
, /* partial_inplace */
991 0x1fffff, /* src_mask */
992 0x1fffff, /* dst_mask */
993 TRUE
), /* pcrel_offset */
995 /* ADD: GOT offset G(S) & 0xff8 [no overflow check] */
996 HOWTO (AARCH64_R (TLSGD_ADD_LO12_NC
), /* type */
998 2, /* size (0 = byte, 1 = short, 2 = long) */
1000 FALSE
, /* pc_relative */
1002 complain_overflow_dont
, /* complain_on_overflow */
1003 bfd_elf_generic_reloc
, /* special_function */
1004 AARCH64_R_STR (TLSGD_ADD_LO12_NC
), /* name */
1005 FALSE
, /* partial_inplace */
1006 0xfff, /* src_mask */
1007 0xfff, /* dst_mask */
1008 FALSE
), /* pcrel_offset */
1010 /* Higher 16 bits of GOT offset to tls_index. */
1011 HOWTO64 (AARCH64_R (TLSGD_MOVW_G1
), /* type */
1012 16, /* rightshift */
1013 2, /* size (0 = byte, 1 = short, 2 = long) */
1015 FALSE
, /* pc_relative */
1017 complain_overflow_unsigned
, /* complain_on_overflow */
1018 bfd_elf_generic_reloc
, /* special_function */
1019 AARCH64_R_STR (TLSGD_MOVW_G1
), /* name */
1020 FALSE
, /* partial_inplace */
1021 0xffff, /* src_mask */
1022 0xffff, /* dst_mask */
1023 FALSE
), /* pcrel_offset */
1025 HOWTO64 (AARCH64_R (TLSIE_MOVW_GOTTPREL_G1
), /* type */
1026 16, /* rightshift */
1027 2, /* size (0 = byte, 1 = short, 2 = long) */
1029 FALSE
, /* pc_relative */
1031 complain_overflow_dont
, /* complain_on_overflow */
1032 bfd_elf_generic_reloc
, /* special_function */
1033 AARCH64_R_STR (TLSIE_MOVW_GOTTPREL_G1
), /* name */
1034 FALSE
, /* partial_inplace */
1035 0xffff, /* src_mask */
1036 0xffff, /* dst_mask */
1037 FALSE
), /* pcrel_offset */
1039 HOWTO64 (AARCH64_R (TLSIE_MOVW_GOTTPREL_G0_NC
), /* type */
1041 2, /* size (0 = byte, 1 = short, 2 = long) */
1043 FALSE
, /* pc_relative */
1045 complain_overflow_dont
, /* complain_on_overflow */
1046 bfd_elf_generic_reloc
, /* special_function */
1047 AARCH64_R_STR (TLSIE_MOVW_GOTTPREL_G0_NC
), /* name */
1048 FALSE
, /* partial_inplace */
1049 0xffff, /* src_mask */
1050 0xffff, /* dst_mask */
1051 FALSE
), /* pcrel_offset */
1053 HOWTO (AARCH64_R (TLSIE_ADR_GOTTPREL_PAGE21
), /* type */
1054 12, /* rightshift */
1055 2, /* size (0 = byte, 1 = short, 2 = long) */
1057 FALSE
, /* pc_relative */
1059 complain_overflow_dont
, /* complain_on_overflow */
1060 bfd_elf_generic_reloc
, /* special_function */
1061 AARCH64_R_STR (TLSIE_ADR_GOTTPREL_PAGE21
), /* name */
1062 FALSE
, /* partial_inplace */
1063 0x1fffff, /* src_mask */
1064 0x1fffff, /* dst_mask */
1065 FALSE
), /* pcrel_offset */
1067 HOWTO64 (AARCH64_R (TLSIE_LD64_GOTTPREL_LO12_NC
), /* type */
1069 2, /* size (0 = byte, 1 = short, 2 = long) */
1071 FALSE
, /* pc_relative */
1073 complain_overflow_dont
, /* complain_on_overflow */
1074 bfd_elf_generic_reloc
, /* special_function */
1075 AARCH64_R_STR (TLSIE_LD64_GOTTPREL_LO12_NC
), /* name */
1076 FALSE
, /* partial_inplace */
1077 0xff8, /* src_mask */
1078 0xff8, /* dst_mask */
1079 FALSE
), /* pcrel_offset */
1081 HOWTO32 (AARCH64_R (TLSIE_LD32_GOTTPREL_LO12_NC
), /* type */
1083 2, /* size (0 = byte, 1 = short, 2 = long) */
1085 FALSE
, /* pc_relative */
1087 complain_overflow_dont
, /* complain_on_overflow */
1088 bfd_elf_generic_reloc
, /* special_function */
1089 AARCH64_R_STR (TLSIE_LD32_GOTTPREL_LO12_NC
), /* name */
1090 FALSE
, /* partial_inplace */
1091 0xffc, /* src_mask */
1092 0xffc, /* dst_mask */
1093 FALSE
), /* pcrel_offset */
1095 HOWTO (AARCH64_R (TLSIE_LD_GOTTPREL_PREL19
), /* type */
1097 2, /* size (0 = byte, 1 = short, 2 = long) */
1099 FALSE
, /* pc_relative */
1101 complain_overflow_dont
, /* complain_on_overflow */
1102 bfd_elf_generic_reloc
, /* special_function */
1103 AARCH64_R_STR (TLSIE_LD_GOTTPREL_PREL19
), /* name */
1104 FALSE
, /* partial_inplace */
1105 0x1ffffc, /* src_mask */
1106 0x1ffffc, /* dst_mask */
1107 FALSE
), /* pcrel_offset */
1109 /* ADD: bit[23:12] of byte offset to module TLS base address. */
1110 HOWTO (AARCH64_R (TLSLD_ADD_DTPREL_HI12
), /* type */
1111 12, /* rightshift */
1112 2, /* size (0 = byte, 1 = short, 2 = long) */
1114 FALSE
, /* pc_relative */
1116 complain_overflow_unsigned
, /* complain_on_overflow */
1117 bfd_elf_generic_reloc
, /* special_function */
1118 AARCH64_R_STR (TLSLD_ADD_DTPREL_HI12
), /* name */
1119 FALSE
, /* partial_inplace */
1120 0xfff, /* src_mask */
1121 0xfff, /* dst_mask */
1122 FALSE
), /* pcrel_offset */
1124 /* Unsigned 12 bit byte offset to module TLS base address. */
1125 HOWTO (AARCH64_R (TLSLD_ADD_DTPREL_LO12
), /* type */
1127 2, /* size (0 = byte, 1 = short, 2 = long) */
1129 FALSE
, /* pc_relative */
1131 complain_overflow_unsigned
, /* complain_on_overflow */
1132 bfd_elf_generic_reloc
, /* special_function */
1133 AARCH64_R_STR (TLSLD_ADD_DTPREL_LO12
), /* name */
1134 FALSE
, /* partial_inplace */
1135 0xfff, /* src_mask */
1136 0xfff, /* dst_mask */
1137 FALSE
), /* pcrel_offset */
1139 /* No overflow check version of BFD_RELOC_AARCH64_TLSLD_ADD_DTPREL_LO12. */
1140 HOWTO (AARCH64_R (TLSLD_ADD_DTPREL_LO12_NC
), /* type */
1142 2, /* size (0 = byte, 1 = short, 2 = long) */
1144 FALSE
, /* pc_relative */
1146 complain_overflow_dont
, /* complain_on_overflow */
1147 bfd_elf_generic_reloc
, /* special_function */
1148 AARCH64_R_STR (TLSLD_ADD_DTPREL_LO12_NC
), /* name */
1149 FALSE
, /* partial_inplace */
1150 0xfff, /* src_mask */
1151 0xfff, /* dst_mask */
1152 FALSE
), /* pcrel_offset */
1154 /* ADD: GOT offset G(S) & 0xff8 [no overflow check] */
1155 HOWTO (AARCH64_R (TLSLD_ADD_LO12_NC
), /* type */
1157 2, /* size (0 = byte, 1 = short, 2 = long) */
1159 FALSE
, /* pc_relative */
1161 complain_overflow_dont
, /* complain_on_overflow */
1162 bfd_elf_generic_reloc
, /* special_function */
1163 AARCH64_R_STR (TLSLD_ADD_LO12_NC
), /* name */
1164 FALSE
, /* partial_inplace */
1165 0xfff, /* src_mask */
1166 0xfff, /* dst_mask */
1167 FALSE
), /* pcrel_offset */
1169 /* Get to the page for the GOT entry for the symbol
1170 (G(S) - P) using an ADRP instruction. */
1171 HOWTO (AARCH64_R (TLSLD_ADR_PAGE21
), /* type */
1172 12, /* rightshift */
1173 2, /* size (0 = byte, 1 = short, 2 = long) */
1175 TRUE
, /* pc_relative */
1177 complain_overflow_signed
, /* complain_on_overflow */
1178 bfd_elf_generic_reloc
, /* special_function */
1179 AARCH64_R_STR (TLSLD_ADR_PAGE21
), /* name */
1180 FALSE
, /* partial_inplace */
1181 0x1fffff, /* src_mask */
1182 0x1fffff, /* dst_mask */
1183 TRUE
), /* pcrel_offset */
1185 HOWTO (AARCH64_R (TLSLD_ADR_PREL21
), /* type */
1187 2, /* size (0 = byte, 1 = short, 2 = long) */
1189 TRUE
, /* pc_relative */
1191 complain_overflow_signed
, /* complain_on_overflow */
1192 bfd_elf_generic_reloc
, /* special_function */
1193 AARCH64_R_STR (TLSLD_ADR_PREL21
), /* name */
1194 FALSE
, /* partial_inplace */
1195 0x1fffff, /* src_mask */
1196 0x1fffff, /* dst_mask */
1197 TRUE
), /* pcrel_offset */
1199 /* LD/ST16: bit[11:1] of byte offset to module TLS base address. */
1200 HOWTO64 (AARCH64_R (TLSLD_LDST16_DTPREL_LO12
), /* type */
1202 2, /* size (0 = byte, 1 = short, 2 = long) */
1204 FALSE
, /* pc_relative */
1206 complain_overflow_unsigned
, /* complain_on_overflow */
1207 bfd_elf_generic_reloc
, /* special_function */
1208 AARCH64_R_STR (TLSLD_LDST16_DTPREL_LO12
), /* name */
1209 FALSE
, /* partial_inplace */
1210 0x1ffc00, /* src_mask */
1211 0x1ffc00, /* dst_mask */
1212 FALSE
), /* pcrel_offset */
1214 /* Same as BFD_RELOC_AARCH64_TLSLD_LDST16_DTPREL_LO12, but no overflow check. */
1215 HOWTO64 (AARCH64_R (TLSLD_LDST16_DTPREL_LO12_NC
), /* type */
1217 2, /* size (0 = byte, 1 = short, 2 = long) */
1219 FALSE
, /* pc_relative */
1221 complain_overflow_dont
, /* complain_on_overflow */
1222 bfd_elf_generic_reloc
, /* special_function */
1223 AARCH64_R_STR (TLSLD_LDST16_DTPREL_LO12_NC
), /* name */
1224 FALSE
, /* partial_inplace */
1225 0x1ffc00, /* src_mask */
1226 0x1ffc00, /* dst_mask */
1227 FALSE
), /* pcrel_offset */
1229 /* LD/ST32: bit[11:2] of byte offset to module TLS base address. */
1230 HOWTO64 (AARCH64_R (TLSLD_LDST32_DTPREL_LO12
), /* type */
1232 2, /* size (0 = byte, 1 = short, 2 = long) */
1234 FALSE
, /* pc_relative */
1236 complain_overflow_unsigned
, /* complain_on_overflow */
1237 bfd_elf_generic_reloc
, /* special_function */
1238 AARCH64_R_STR (TLSLD_LDST32_DTPREL_LO12
), /* name */
1239 FALSE
, /* partial_inplace */
1240 0x3ffc00, /* src_mask */
1241 0x3ffc00, /* dst_mask */
1242 FALSE
), /* pcrel_offset */
1244 /* Same as BFD_RELOC_AARCH64_TLSLD_LDST32_DTPREL_LO12, but no overflow check. */
1245 HOWTO64 (AARCH64_R (TLSLD_LDST32_DTPREL_LO12_NC
), /* type */
1247 2, /* size (0 = byte, 1 = short, 2 = long) */
1249 FALSE
, /* pc_relative */
1251 complain_overflow_dont
, /* complain_on_overflow */
1252 bfd_elf_generic_reloc
, /* special_function */
1253 AARCH64_R_STR (TLSLD_LDST32_DTPREL_LO12_NC
), /* name */
1254 FALSE
, /* partial_inplace */
1255 0xffc00, /* src_mask */
1256 0xffc00, /* dst_mask */
1257 FALSE
), /* pcrel_offset */
1259 /* LD/ST64: bit[11:3] of byte offset to module TLS base address. */
1260 HOWTO64 (AARCH64_R (TLSLD_LDST64_DTPREL_LO12
), /* type */
1262 2, /* size (0 = byte, 1 = short, 2 = long) */
1264 FALSE
, /* pc_relative */
1266 complain_overflow_unsigned
, /* complain_on_overflow */
1267 bfd_elf_generic_reloc
, /* special_function */
1268 AARCH64_R_STR (TLSLD_LDST64_DTPREL_LO12
), /* name */
1269 FALSE
, /* partial_inplace */
1270 0x3ffc00, /* src_mask */
1271 0x3ffc00, /* dst_mask */
1272 FALSE
), /* pcrel_offset */
1274 /* Same as BFD_RELOC_AARCH64_TLSLD_LDST64_DTPREL_LO12, but no overflow check. */
1275 HOWTO64 (AARCH64_R (TLSLD_LDST64_DTPREL_LO12_NC
), /* type */
1277 2, /* size (0 = byte, 1 = short, 2 = long) */
1279 FALSE
, /* pc_relative */
1281 complain_overflow_dont
, /* complain_on_overflow */
1282 bfd_elf_generic_reloc
, /* special_function */
1283 AARCH64_R_STR (TLSLD_LDST64_DTPREL_LO12_NC
), /* name */
1284 FALSE
, /* partial_inplace */
1285 0x7fc00, /* src_mask */
1286 0x7fc00, /* dst_mask */
1287 FALSE
), /* pcrel_offset */
1289 /* LD/ST8: bit[11:0] of byte offset to module TLS base address. */
1290 HOWTO64 (AARCH64_R (TLSLD_LDST8_DTPREL_LO12
), /* type */
1292 2, /* size (0 = byte, 1 = short, 2 = long) */
1294 FALSE
, /* pc_relative */
1296 complain_overflow_unsigned
, /* complain_on_overflow */
1297 bfd_elf_generic_reloc
, /* special_function */
1298 AARCH64_R_STR (TLSLD_LDST8_DTPREL_LO12
), /* name */
1299 FALSE
, /* partial_inplace */
1300 0x3ffc00, /* src_mask */
1301 0x3ffc00, /* dst_mask */
1302 FALSE
), /* pcrel_offset */
1304 /* Same as BFD_RELOC_AARCH64_TLSLD_LDST8_DTPREL_LO12, but no overflow check. */
1305 HOWTO64 (AARCH64_R (TLSLD_LDST8_DTPREL_LO12_NC
), /* type */
1307 2, /* size (0 = byte, 1 = short, 2 = long) */
1309 FALSE
, /* pc_relative */
1311 complain_overflow_dont
, /* complain_on_overflow */
1312 bfd_elf_generic_reloc
, /* special_function */
1313 AARCH64_R_STR (TLSLD_LDST8_DTPREL_LO12_NC
), /* name */
1314 FALSE
, /* partial_inplace */
1315 0x3ffc00, /* src_mask */
1316 0x3ffc00, /* dst_mask */
1317 FALSE
), /* pcrel_offset */
1319 /* MOVZ: bit[15:0] of byte offset to module TLS base address. */
1320 HOWTO (AARCH64_R (TLSLD_MOVW_DTPREL_G0
), /* type */
1322 2, /* size (0 = byte, 1 = short, 2 = long) */
1324 FALSE
, /* pc_relative */
1326 complain_overflow_unsigned
, /* complain_on_overflow */
1327 bfd_elf_generic_reloc
, /* special_function */
1328 AARCH64_R_STR (TLSLD_MOVW_DTPREL_G0
), /* name */
1329 FALSE
, /* partial_inplace */
1330 0xffff, /* src_mask */
1331 0xffff, /* dst_mask */
1332 FALSE
), /* pcrel_offset */
1334 /* No overflow check version of BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G0. */
1335 HOWTO (AARCH64_R (TLSLD_MOVW_DTPREL_G0_NC
), /* type */
1337 2, /* size (0 = byte, 1 = short, 2 = long) */
1339 FALSE
, /* pc_relative */
1341 complain_overflow_dont
, /* complain_on_overflow */
1342 bfd_elf_generic_reloc
, /* special_function */
1343 AARCH64_R_STR (TLSLD_MOVW_DTPREL_G0_NC
), /* name */
1344 FALSE
, /* partial_inplace */
1345 0xffff, /* src_mask */
1346 0xffff, /* dst_mask */
1347 FALSE
), /* pcrel_offset */
1349 /* MOVZ: bit[31:16] of byte offset to module TLS base address. */
1350 HOWTO (AARCH64_R (TLSLD_MOVW_DTPREL_G1
), /* type */
1351 16, /* rightshift */
1352 2, /* size (0 = byte, 1 = short, 2 = long) */
1354 FALSE
, /* pc_relative */
1356 complain_overflow_unsigned
, /* complain_on_overflow */
1357 bfd_elf_generic_reloc
, /* special_function */
1358 AARCH64_R_STR (TLSLD_MOVW_DTPREL_G1
), /* name */
1359 FALSE
, /* partial_inplace */
1360 0xffff, /* src_mask */
1361 0xffff, /* dst_mask */
1362 FALSE
), /* pcrel_offset */
1364 /* No overflow check version of BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G1. */
1365 HOWTO64 (AARCH64_R (TLSLD_MOVW_DTPREL_G1_NC
), /* type */
1366 16, /* rightshift */
1367 2, /* size (0 = byte, 1 = short, 2 = long) */
1369 FALSE
, /* pc_relative */
1371 complain_overflow_dont
, /* complain_on_overflow */
1372 bfd_elf_generic_reloc
, /* special_function */
1373 AARCH64_R_STR (TLSLD_MOVW_DTPREL_G1_NC
), /* name */
1374 FALSE
, /* partial_inplace */
1375 0xffff, /* src_mask */
1376 0xffff, /* dst_mask */
1377 FALSE
), /* pcrel_offset */
1379 /* MOVZ: bit[47:32] of byte offset to module TLS base address. */
1380 HOWTO64 (AARCH64_R (TLSLD_MOVW_DTPREL_G2
), /* type */
1381 32, /* rightshift */
1382 2, /* size (0 = byte, 1 = short, 2 = long) */
1384 FALSE
, /* pc_relative */
1386 complain_overflow_unsigned
, /* complain_on_overflow */
1387 bfd_elf_generic_reloc
, /* special_function */
1388 AARCH64_R_STR (TLSLD_MOVW_DTPREL_G2
), /* name */
1389 FALSE
, /* partial_inplace */
1390 0xffff, /* src_mask */
1391 0xffff, /* dst_mask */
1392 FALSE
), /* pcrel_offset */
1394 HOWTO64 (AARCH64_R (TLSLE_MOVW_TPREL_G2
), /* type */
1395 32, /* rightshift */
1396 2, /* size (0 = byte, 1 = short, 2 = long) */
1398 FALSE
, /* pc_relative */
1400 complain_overflow_unsigned
, /* complain_on_overflow */
1401 bfd_elf_generic_reloc
, /* special_function */
1402 AARCH64_R_STR (TLSLE_MOVW_TPREL_G2
), /* name */
1403 FALSE
, /* partial_inplace */
1404 0xffff, /* src_mask */
1405 0xffff, /* dst_mask */
1406 FALSE
), /* pcrel_offset */
1408 HOWTO (AARCH64_R (TLSLE_MOVW_TPREL_G1
), /* type */
1409 16, /* rightshift */
1410 2, /* size (0 = byte, 1 = short, 2 = long) */
1412 FALSE
, /* pc_relative */
1414 complain_overflow_dont
, /* complain_on_overflow */
1415 bfd_elf_generic_reloc
, /* special_function */
1416 AARCH64_R_STR (TLSLE_MOVW_TPREL_G1
), /* name */
1417 FALSE
, /* partial_inplace */
1418 0xffff, /* src_mask */
1419 0xffff, /* dst_mask */
1420 FALSE
), /* pcrel_offset */
1422 HOWTO64 (AARCH64_R (TLSLE_MOVW_TPREL_G1_NC
), /* type */
1423 16, /* rightshift */
1424 2, /* size (0 = byte, 1 = short, 2 = long) */
1426 FALSE
, /* pc_relative */
1428 complain_overflow_dont
, /* complain_on_overflow */
1429 bfd_elf_generic_reloc
, /* special_function */
1430 AARCH64_R_STR (TLSLE_MOVW_TPREL_G1_NC
), /* name */
1431 FALSE
, /* partial_inplace */
1432 0xffff, /* src_mask */
1433 0xffff, /* dst_mask */
1434 FALSE
), /* pcrel_offset */
1436 HOWTO (AARCH64_R (TLSLE_MOVW_TPREL_G0
), /* type */
1438 2, /* size (0 = byte, 1 = short, 2 = long) */
1440 FALSE
, /* pc_relative */
1442 complain_overflow_dont
, /* complain_on_overflow */
1443 bfd_elf_generic_reloc
, /* special_function */
1444 AARCH64_R_STR (TLSLE_MOVW_TPREL_G0
), /* name */
1445 FALSE
, /* partial_inplace */
1446 0xffff, /* src_mask */
1447 0xffff, /* dst_mask */
1448 FALSE
), /* pcrel_offset */
1450 HOWTO (AARCH64_R (TLSLE_MOVW_TPREL_G0_NC
), /* type */
1452 2, /* size (0 = byte, 1 = short, 2 = long) */
1454 FALSE
, /* pc_relative */
1456 complain_overflow_dont
, /* complain_on_overflow */
1457 bfd_elf_generic_reloc
, /* special_function */
1458 AARCH64_R_STR (TLSLE_MOVW_TPREL_G0_NC
), /* name */
1459 FALSE
, /* partial_inplace */
1460 0xffff, /* src_mask */
1461 0xffff, /* dst_mask */
1462 FALSE
), /* pcrel_offset */
1464 HOWTO (AARCH64_R (TLSLE_ADD_TPREL_HI12
), /* type */
1465 12, /* rightshift */
1466 2, /* size (0 = byte, 1 = short, 2 = long) */
1468 FALSE
, /* pc_relative */
1470 complain_overflow_unsigned
, /* complain_on_overflow */
1471 bfd_elf_generic_reloc
, /* special_function */
1472 AARCH64_R_STR (TLSLE_ADD_TPREL_HI12
), /* name */
1473 FALSE
, /* partial_inplace */
1474 0xfff, /* src_mask */
1475 0xfff, /* dst_mask */
1476 FALSE
), /* pcrel_offset */
1478 HOWTO (AARCH64_R (TLSLE_ADD_TPREL_LO12
), /* type */
1480 2, /* size (0 = byte, 1 = short, 2 = long) */
1482 FALSE
, /* pc_relative */
1484 complain_overflow_unsigned
, /* complain_on_overflow */
1485 bfd_elf_generic_reloc
, /* special_function */
1486 AARCH64_R_STR (TLSLE_ADD_TPREL_LO12
), /* name */
1487 FALSE
, /* partial_inplace */
1488 0xfff, /* src_mask */
1489 0xfff, /* dst_mask */
1490 FALSE
), /* pcrel_offset */
1492 HOWTO (AARCH64_R (TLSLE_ADD_TPREL_LO12_NC
), /* type */
1494 2, /* size (0 = byte, 1 = short, 2 = long) */
1496 FALSE
, /* pc_relative */
1498 complain_overflow_dont
, /* complain_on_overflow */
1499 bfd_elf_generic_reloc
, /* special_function */
1500 AARCH64_R_STR (TLSLE_ADD_TPREL_LO12_NC
), /* name */
1501 FALSE
, /* partial_inplace */
1502 0xfff, /* src_mask */
1503 0xfff, /* dst_mask */
1504 FALSE
), /* pcrel_offset */
1506 HOWTO (AARCH64_R (TLSDESC_LD_PREL19
), /* type */
1508 2, /* size (0 = byte, 1 = short, 2 = long) */
1510 TRUE
, /* pc_relative */
1512 complain_overflow_dont
, /* complain_on_overflow */
1513 bfd_elf_generic_reloc
, /* special_function */
1514 AARCH64_R_STR (TLSDESC_LD_PREL19
), /* name */
1515 FALSE
, /* partial_inplace */
1516 0x0ffffe0, /* src_mask */
1517 0x0ffffe0, /* dst_mask */
1518 TRUE
), /* pcrel_offset */
1520 HOWTO (AARCH64_R (TLSDESC_ADR_PREL21
), /* type */
1522 2, /* size (0 = byte, 1 = short, 2 = long) */
1524 TRUE
, /* pc_relative */
1526 complain_overflow_dont
, /* complain_on_overflow */
1527 bfd_elf_generic_reloc
, /* special_function */
1528 AARCH64_R_STR (TLSDESC_ADR_PREL21
), /* name */
1529 FALSE
, /* partial_inplace */
1530 0x1fffff, /* src_mask */
1531 0x1fffff, /* dst_mask */
1532 TRUE
), /* pcrel_offset */
1534 /* Get to the page for the GOT entry for the symbol
1535 (G(S) - P) using an ADRP instruction. */
1536 HOWTO (AARCH64_R (TLSDESC_ADR_PAGE21
), /* type */
1537 12, /* rightshift */
1538 2, /* size (0 = byte, 1 = short, 2 = long) */
1540 TRUE
, /* pc_relative */
1542 complain_overflow_dont
, /* complain_on_overflow */
1543 bfd_elf_generic_reloc
, /* special_function */
1544 AARCH64_R_STR (TLSDESC_ADR_PAGE21
), /* name */
1545 FALSE
, /* partial_inplace */
1546 0x1fffff, /* src_mask */
1547 0x1fffff, /* dst_mask */
1548 TRUE
), /* pcrel_offset */
1550 /* LD64: GOT offset G(S) & 0xff8. */
1551 HOWTO64 (AARCH64_R (TLSDESC_LD64_LO12_NC
), /* type */
1553 2, /* size (0 = byte, 1 = short, 2 = long) */
1555 FALSE
, /* pc_relative */
1557 complain_overflow_dont
, /* complain_on_overflow */
1558 bfd_elf_generic_reloc
, /* special_function */
1559 AARCH64_R_STR (TLSDESC_LD64_LO12_NC
), /* name */
1560 FALSE
, /* partial_inplace */
1561 0xff8, /* src_mask */
1562 0xff8, /* dst_mask */
1563 FALSE
), /* pcrel_offset */
1565 /* LD32: GOT offset G(S) & 0xffc. */
1566 HOWTO32 (AARCH64_R (TLSDESC_LD32_LO12_NC
), /* type */
1568 2, /* size (0 = byte, 1 = short, 2 = long) */
1570 FALSE
, /* pc_relative */
1572 complain_overflow_dont
, /* complain_on_overflow */
1573 bfd_elf_generic_reloc
, /* special_function */
1574 AARCH64_R_STR (TLSDESC_LD32_LO12_NC
), /* name */
1575 FALSE
, /* partial_inplace */
1576 0xffc, /* src_mask */
1577 0xffc, /* dst_mask */
1578 FALSE
), /* pcrel_offset */
1580 /* ADD: GOT offset G(S) & 0xfff. */
1581 HOWTO (AARCH64_R (TLSDESC_ADD_LO12_NC
), /* type */
1583 2, /* size (0 = byte, 1 = short, 2 = long) */
1585 FALSE
, /* pc_relative */
1587 complain_overflow_dont
, /* complain_on_overflow */
1588 bfd_elf_generic_reloc
, /* special_function */
1589 AARCH64_R_STR (TLSDESC_ADD_LO12_NC
), /* name */
1590 FALSE
, /* partial_inplace */
1591 0xfff, /* src_mask */
1592 0xfff, /* dst_mask */
1593 FALSE
), /* pcrel_offset */
1595 HOWTO64 (AARCH64_R (TLSDESC_OFF_G1
), /* type */
1596 16, /* rightshift */
1597 2, /* size (0 = byte, 1 = short, 2 = long) */
1599 FALSE
, /* pc_relative */
1601 complain_overflow_dont
, /* complain_on_overflow */
1602 bfd_elf_generic_reloc
, /* special_function */
1603 AARCH64_R_STR (TLSDESC_OFF_G1
), /* name */
1604 FALSE
, /* partial_inplace */
1605 0xffff, /* src_mask */
1606 0xffff, /* dst_mask */
1607 FALSE
), /* pcrel_offset */
1609 HOWTO64 (AARCH64_R (TLSDESC_OFF_G0_NC
), /* type */
1611 2, /* size (0 = byte, 1 = short, 2 = long) */
1613 FALSE
, /* pc_relative */
1615 complain_overflow_dont
, /* complain_on_overflow */
1616 bfd_elf_generic_reloc
, /* special_function */
1617 AARCH64_R_STR (TLSDESC_OFF_G0_NC
), /* name */
1618 FALSE
, /* partial_inplace */
1619 0xffff, /* src_mask */
1620 0xffff, /* dst_mask */
1621 FALSE
), /* pcrel_offset */
1623 HOWTO64 (AARCH64_R (TLSDESC_LDR
), /* type */
1625 2, /* size (0 = byte, 1 = short, 2 = long) */
1627 FALSE
, /* pc_relative */
1629 complain_overflow_dont
, /* complain_on_overflow */
1630 bfd_elf_generic_reloc
, /* special_function */
1631 AARCH64_R_STR (TLSDESC_LDR
), /* name */
1632 FALSE
, /* partial_inplace */
1635 FALSE
), /* pcrel_offset */
1637 HOWTO64 (AARCH64_R (TLSDESC_ADD
), /* type */
1639 2, /* size (0 = byte, 1 = short, 2 = long) */
1641 FALSE
, /* pc_relative */
1643 complain_overflow_dont
, /* complain_on_overflow */
1644 bfd_elf_generic_reloc
, /* special_function */
1645 AARCH64_R_STR (TLSDESC_ADD
), /* name */
1646 FALSE
, /* partial_inplace */
1649 FALSE
), /* pcrel_offset */
1651 HOWTO (AARCH64_R (TLSDESC_CALL
), /* type */
1653 2, /* size (0 = byte, 1 = short, 2 = long) */
1655 FALSE
, /* pc_relative */
1657 complain_overflow_dont
, /* complain_on_overflow */
1658 bfd_elf_generic_reloc
, /* special_function */
1659 AARCH64_R_STR (TLSDESC_CALL
), /* name */
1660 FALSE
, /* partial_inplace */
1663 FALSE
), /* pcrel_offset */
1665 HOWTO (AARCH64_R (COPY
), /* type */
1667 2, /* size (0 = byte, 1 = short, 2 = long) */
1669 FALSE
, /* pc_relative */
1671 complain_overflow_bitfield
, /* complain_on_overflow */
1672 bfd_elf_generic_reloc
, /* special_function */
1673 AARCH64_R_STR (COPY
), /* name */
1674 TRUE
, /* partial_inplace */
1675 0xffffffff, /* src_mask */
1676 0xffffffff, /* dst_mask */
1677 FALSE
), /* pcrel_offset */
1679 HOWTO (AARCH64_R (GLOB_DAT
), /* type */
1681 2, /* size (0 = byte, 1 = short, 2 = long) */
1683 FALSE
, /* pc_relative */
1685 complain_overflow_bitfield
, /* complain_on_overflow */
1686 bfd_elf_generic_reloc
, /* special_function */
1687 AARCH64_R_STR (GLOB_DAT
), /* name */
1688 TRUE
, /* partial_inplace */
1689 0xffffffff, /* src_mask */
1690 0xffffffff, /* dst_mask */
1691 FALSE
), /* pcrel_offset */
1693 HOWTO (AARCH64_R (JUMP_SLOT
), /* type */
1695 2, /* size (0 = byte, 1 = short, 2 = long) */
1697 FALSE
, /* pc_relative */
1699 complain_overflow_bitfield
, /* complain_on_overflow */
1700 bfd_elf_generic_reloc
, /* special_function */
1701 AARCH64_R_STR (JUMP_SLOT
), /* name */
1702 TRUE
, /* partial_inplace */
1703 0xffffffff, /* src_mask */
1704 0xffffffff, /* dst_mask */
1705 FALSE
), /* pcrel_offset */
1707 HOWTO (AARCH64_R (RELATIVE
), /* type */
1709 2, /* size (0 = byte, 1 = short, 2 = long) */
1711 FALSE
, /* pc_relative */
1713 complain_overflow_bitfield
, /* complain_on_overflow */
1714 bfd_elf_generic_reloc
, /* special_function */
1715 AARCH64_R_STR (RELATIVE
), /* name */
1716 TRUE
, /* partial_inplace */
1717 ALL_ONES
, /* src_mask */
1718 ALL_ONES
, /* dst_mask */
1719 FALSE
), /* pcrel_offset */
1721 HOWTO (AARCH64_R (TLS_DTPMOD
), /* type */
1723 2, /* size (0 = byte, 1 = short, 2 = long) */
1725 FALSE
, /* pc_relative */
1727 complain_overflow_dont
, /* complain_on_overflow */
1728 bfd_elf_generic_reloc
, /* special_function */
1730 AARCH64_R_STR (TLS_DTPMOD64
), /* name */
1732 AARCH64_R_STR (TLS_DTPMOD
), /* name */
1734 FALSE
, /* partial_inplace */
1736 ALL_ONES
, /* dst_mask */
1737 FALSE
), /* pc_reloffset */
1739 HOWTO (AARCH64_R (TLS_DTPREL
), /* type */
1741 2, /* size (0 = byte, 1 = short, 2 = long) */
1743 FALSE
, /* pc_relative */
1745 complain_overflow_dont
, /* complain_on_overflow */
1746 bfd_elf_generic_reloc
, /* special_function */
1748 AARCH64_R_STR (TLS_DTPREL64
), /* name */
1750 AARCH64_R_STR (TLS_DTPREL
), /* name */
1752 FALSE
, /* partial_inplace */
1754 ALL_ONES
, /* dst_mask */
1755 FALSE
), /* pcrel_offset */
1757 HOWTO (AARCH64_R (TLS_TPREL
), /* type */
1759 2, /* size (0 = byte, 1 = short, 2 = long) */
1761 FALSE
, /* pc_relative */
1763 complain_overflow_dont
, /* complain_on_overflow */
1764 bfd_elf_generic_reloc
, /* special_function */
1766 AARCH64_R_STR (TLS_TPREL64
), /* name */
1768 AARCH64_R_STR (TLS_TPREL
), /* name */
1770 FALSE
, /* partial_inplace */
1772 ALL_ONES
, /* dst_mask */
1773 FALSE
), /* pcrel_offset */
1775 HOWTO (AARCH64_R (TLSDESC
), /* type */
1777 2, /* size (0 = byte, 1 = short, 2 = long) */
1779 FALSE
, /* pc_relative */
1781 complain_overflow_dont
, /* complain_on_overflow */
1782 bfd_elf_generic_reloc
, /* special_function */
1783 AARCH64_R_STR (TLSDESC
), /* name */
1784 FALSE
, /* partial_inplace */
1786 ALL_ONES
, /* dst_mask */
1787 FALSE
), /* pcrel_offset */
1789 HOWTO (AARCH64_R (IRELATIVE
), /* type */
1791 2, /* size (0 = byte, 1 = short, 2 = long) */
1793 FALSE
, /* pc_relative */
1795 complain_overflow_bitfield
, /* complain_on_overflow */
1796 bfd_elf_generic_reloc
, /* special_function */
1797 AARCH64_R_STR (IRELATIVE
), /* name */
1798 FALSE
, /* partial_inplace */
1800 ALL_ONES
, /* dst_mask */
1801 FALSE
), /* pcrel_offset */
1806 static reloc_howto_type elfNN_aarch64_howto_none
=
1807 HOWTO (R_AARCH64_NONE
, /* type */
1809 3, /* size (0 = byte, 1 = short, 2 = long) */
1811 FALSE
, /* pc_relative */
1813 complain_overflow_dont
,/* complain_on_overflow */
1814 bfd_elf_generic_reloc
, /* special_function */
1815 "R_AARCH64_NONE", /* name */
1816 FALSE
, /* partial_inplace */
1819 FALSE
); /* pcrel_offset */
1821 /* Given HOWTO, return the bfd internal relocation enumerator. */
1823 static bfd_reloc_code_real_type
1824 elfNN_aarch64_bfd_reloc_from_howto (reloc_howto_type
*howto
)
1827 = (int) ARRAY_SIZE (elfNN_aarch64_howto_table
);
1828 const ptrdiff_t offset
1829 = howto
- elfNN_aarch64_howto_table
;
1831 if (offset
> 0 && offset
< size
- 1)
1832 return BFD_RELOC_AARCH64_RELOC_START
+ offset
;
1834 if (howto
== &elfNN_aarch64_howto_none
)
1835 return BFD_RELOC_AARCH64_NONE
;
1837 return BFD_RELOC_AARCH64_RELOC_START
;
1840 /* Given R_TYPE, return the bfd internal relocation enumerator. */
1842 static bfd_reloc_code_real_type
1843 elfNN_aarch64_bfd_reloc_from_type (unsigned int r_type
)
1845 static bfd_boolean initialized_p
= FALSE
;
1846 /* Indexed by R_TYPE, values are offsets in the howto_table. */
1847 static unsigned int offsets
[R_AARCH64_end
];
1849 if (initialized_p
== FALSE
)
1853 for (i
= 1; i
< ARRAY_SIZE (elfNN_aarch64_howto_table
) - 1; ++i
)
1854 if (elfNN_aarch64_howto_table
[i
].type
!= 0)
1855 offsets
[elfNN_aarch64_howto_table
[i
].type
] = i
;
1857 initialized_p
= TRUE
;
1860 if (r_type
== R_AARCH64_NONE
|| r_type
== R_AARCH64_NULL
)
1861 return BFD_RELOC_AARCH64_NONE
;
1863 /* PR 17512: file: b371e70a. */
1864 if (r_type
>= R_AARCH64_end
)
1866 _bfd_error_handler (_("Invalid AArch64 reloc number: %d"), r_type
);
1867 bfd_set_error (bfd_error_bad_value
);
1868 return BFD_RELOC_AARCH64_NONE
;
1871 return BFD_RELOC_AARCH64_RELOC_START
+ offsets
[r_type
];
1874 struct elf_aarch64_reloc_map
1876 bfd_reloc_code_real_type from
;
1877 bfd_reloc_code_real_type to
;
1880 /* Map bfd generic reloc to AArch64-specific reloc. */
1881 static const struct elf_aarch64_reloc_map elf_aarch64_reloc_map
[] =
1883 {BFD_RELOC_NONE
, BFD_RELOC_AARCH64_NONE
},
1885 /* Basic data relocations. */
1886 {BFD_RELOC_CTOR
, BFD_RELOC_AARCH64_NN
},
1887 {BFD_RELOC_64
, BFD_RELOC_AARCH64_64
},
1888 {BFD_RELOC_32
, BFD_RELOC_AARCH64_32
},
1889 {BFD_RELOC_16
, BFD_RELOC_AARCH64_16
},
1890 {BFD_RELOC_64_PCREL
, BFD_RELOC_AARCH64_64_PCREL
},
1891 {BFD_RELOC_32_PCREL
, BFD_RELOC_AARCH64_32_PCREL
},
1892 {BFD_RELOC_16_PCREL
, BFD_RELOC_AARCH64_16_PCREL
},
1895 /* Given the bfd internal relocation enumerator in CODE, return the
1896 corresponding howto entry. */
1898 static reloc_howto_type
*
1899 elfNN_aarch64_howto_from_bfd_reloc (bfd_reloc_code_real_type code
)
1903 /* Convert bfd generic reloc to AArch64-specific reloc. */
1904 if (code
< BFD_RELOC_AARCH64_RELOC_START
1905 || code
> BFD_RELOC_AARCH64_RELOC_END
)
1906 for (i
= 0; i
< ARRAY_SIZE (elf_aarch64_reloc_map
); i
++)
1907 if (elf_aarch64_reloc_map
[i
].from
== code
)
1909 code
= elf_aarch64_reloc_map
[i
].to
;
1913 if (code
> BFD_RELOC_AARCH64_RELOC_START
1914 && code
< BFD_RELOC_AARCH64_RELOC_END
)
1915 if (elfNN_aarch64_howto_table
[code
- BFD_RELOC_AARCH64_RELOC_START
].type
)
1916 return &elfNN_aarch64_howto_table
[code
- BFD_RELOC_AARCH64_RELOC_START
];
1918 if (code
== BFD_RELOC_AARCH64_NONE
)
1919 return &elfNN_aarch64_howto_none
;
1924 static reloc_howto_type
*
1925 elfNN_aarch64_howto_from_type (unsigned int r_type
)
1927 bfd_reloc_code_real_type val
;
1928 reloc_howto_type
*howto
;
1933 bfd_set_error (bfd_error_bad_value
);
1938 if (r_type
== R_AARCH64_NONE
)
1939 return &elfNN_aarch64_howto_none
;
1941 val
= elfNN_aarch64_bfd_reloc_from_type (r_type
);
1942 howto
= elfNN_aarch64_howto_from_bfd_reloc (val
);
1947 bfd_set_error (bfd_error_bad_value
);
1952 elfNN_aarch64_info_to_howto (bfd
*abfd ATTRIBUTE_UNUSED
, arelent
*bfd_reloc
,
1953 Elf_Internal_Rela
*elf_reloc
)
1955 unsigned int r_type
;
1957 r_type
= ELFNN_R_TYPE (elf_reloc
->r_info
);
1958 bfd_reloc
->howto
= elfNN_aarch64_howto_from_type (r_type
);
1961 static reloc_howto_type
*
1962 elfNN_aarch64_reloc_type_lookup (bfd
*abfd ATTRIBUTE_UNUSED
,
1963 bfd_reloc_code_real_type code
)
1965 reloc_howto_type
*howto
= elfNN_aarch64_howto_from_bfd_reloc (code
);
1970 bfd_set_error (bfd_error_bad_value
);
1974 static reloc_howto_type
*
1975 elfNN_aarch64_reloc_name_lookup (bfd
*abfd ATTRIBUTE_UNUSED
,
1980 for (i
= 1; i
< ARRAY_SIZE (elfNN_aarch64_howto_table
) - 1; ++i
)
1981 if (elfNN_aarch64_howto_table
[i
].name
!= NULL
1982 && strcasecmp (elfNN_aarch64_howto_table
[i
].name
, r_name
) == 0)
1983 return &elfNN_aarch64_howto_table
[i
];
1988 #define TARGET_LITTLE_SYM aarch64_elfNN_le_vec
1989 #define TARGET_LITTLE_NAME "elfNN-littleaarch64"
1990 #define TARGET_BIG_SYM aarch64_elfNN_be_vec
1991 #define TARGET_BIG_NAME "elfNN-bigaarch64"
1993 /* The linker script knows the section names for placement.
1994 The entry_names are used to do simple name mangling on the stubs.
1995 Given a function name, and its type, the stub can be found. The
1996 name can be changed. The only requirement is the %s be present. */
1997 #define STUB_ENTRY_NAME "__%s_veneer"
1999 /* The name of the dynamic interpreter. This is put in the .interp
2001 #define ELF_DYNAMIC_INTERPRETER "/lib/ld.so.1"
2003 #define AARCH64_MAX_FWD_BRANCH_OFFSET \
2004 (((1 << 25) - 1) << 2)
2005 #define AARCH64_MAX_BWD_BRANCH_OFFSET \
2008 #define AARCH64_MAX_ADRP_IMM ((1 << 20) - 1)
2009 #define AARCH64_MIN_ADRP_IMM (-(1 << 20))
2012 aarch64_valid_for_adrp_p (bfd_vma value
, bfd_vma place
)
2014 bfd_signed_vma offset
= (bfd_signed_vma
) (PG (value
) - PG (place
)) >> 12;
2015 return offset
<= AARCH64_MAX_ADRP_IMM
&& offset
>= AARCH64_MIN_ADRP_IMM
;
2019 aarch64_valid_branch_p (bfd_vma value
, bfd_vma place
)
2021 bfd_signed_vma offset
= (bfd_signed_vma
) (value
- place
);
2022 return (offset
<= AARCH64_MAX_FWD_BRANCH_OFFSET
2023 && offset
>= AARCH64_MAX_BWD_BRANCH_OFFSET
);
2026 static const uint32_t aarch64_adrp_branch_stub
[] =
2028 0x90000010, /* adrp ip0, X */
2029 /* R_AARCH64_ADR_HI21_PCREL(X) */
2030 0x91000210, /* add ip0, ip0, :lo12:X */
2031 /* R_AARCH64_ADD_ABS_LO12_NC(X) */
2032 0xd61f0200, /* br ip0 */
2035 static const uint32_t aarch64_long_branch_stub
[] =
2038 0x58000090, /* ldr ip0, 1f */
2040 0x18000090, /* ldr wip0, 1f */
2042 0x10000011, /* adr ip1, #0 */
2043 0x8b110210, /* add ip0, ip0, ip1 */
2044 0xd61f0200, /* br ip0 */
2045 0x00000000, /* 1: .xword or .word
2046 R_AARCH64_PRELNN(X) + 12
2051 static const uint32_t aarch64_erratum_835769_stub
[] =
2053 0x00000000, /* Placeholder for multiply accumulate. */
2054 0x14000000, /* b <label> */
2057 static const uint32_t aarch64_erratum_843419_stub
[] =
2059 0x00000000, /* Placeholder for LDR instruction. */
2060 0x14000000, /* b <label> */
2063 /* Section name for stubs is the associated section name plus this
2065 #define STUB_SUFFIX ".stub"
2067 enum elf_aarch64_stub_type
2070 aarch64_stub_adrp_branch
,
2071 aarch64_stub_long_branch
,
2072 aarch64_stub_erratum_835769_veneer
,
2073 aarch64_stub_erratum_843419_veneer
,
2076 struct elf_aarch64_stub_hash_entry
2078 /* Base hash table entry structure. */
2079 struct bfd_hash_entry root
;
2081 /* The stub section. */
2084 /* Offset within stub_sec of the beginning of this stub. */
2085 bfd_vma stub_offset
;
2087 /* Given the symbol's value and its section we can determine its final
2088 value when building the stubs (so the stub knows where to jump). */
2089 bfd_vma target_value
;
2090 asection
*target_section
;
2092 enum elf_aarch64_stub_type stub_type
;
2094 /* The symbol table entry, if any, that this was derived from. */
2095 struct elf_aarch64_link_hash_entry
*h
;
2097 /* Destination symbol type */
2098 unsigned char st_type
;
2100 /* Where this stub is being called from, or, in the case of combined
2101 stub sections, the first input section in the group. */
2104 /* The name for the local symbol at the start of this stub. The
2105 stub name in the hash table has to be unique; this does not, so
2106 it can be friendlier. */
2109 /* The instruction which caused this stub to be generated (only valid for
2110 erratum 835769 workaround stubs at present). */
2111 uint32_t veneered_insn
;
2113 /* In an erratum 843419 workaround stub, the ADRP instruction offset. */
2114 bfd_vma adrp_offset
;
2117 /* Used to build a map of a section. This is required for mixed-endian
2120 typedef struct elf_elf_section_map
2125 elf_aarch64_section_map
;
2128 typedef struct _aarch64_elf_section_data
2130 struct bfd_elf_section_data elf
;
2131 unsigned int mapcount
;
2132 unsigned int mapsize
;
2133 elf_aarch64_section_map
*map
;
2135 _aarch64_elf_section_data
;
2137 #define elf_aarch64_section_data(sec) \
2138 ((_aarch64_elf_section_data *) elf_section_data (sec))
2140 /* The size of the thread control block which is defined to be two pointers. */
2141 #define TCB_SIZE (ARCH_SIZE/8)*2
2143 struct elf_aarch64_local_symbol
2145 unsigned int got_type
;
2146 bfd_signed_vma got_refcount
;
2149 /* Offset of the GOTPLT entry reserved for the TLS descriptor. The
2150 offset is from the end of the jump table and reserved entries
2153 The magic value (bfd_vma) -1 indicates that an offset has not be
2155 bfd_vma tlsdesc_got_jump_table_offset
;
2158 struct elf_aarch64_obj_tdata
2160 struct elf_obj_tdata root
;
2162 /* local symbol descriptors */
2163 struct elf_aarch64_local_symbol
*locals
;
2165 /* Zero to warn when linking objects with incompatible enum sizes. */
2166 int no_enum_size_warning
;
2168 /* Zero to warn when linking objects with incompatible wchar_t sizes. */
2169 int no_wchar_size_warning
;
2172 #define elf_aarch64_tdata(bfd) \
2173 ((struct elf_aarch64_obj_tdata *) (bfd)->tdata.any)
2175 #define elf_aarch64_locals(bfd) (elf_aarch64_tdata (bfd)->locals)
2177 #define is_aarch64_elf(bfd) \
2178 (bfd_get_flavour (bfd) == bfd_target_elf_flavour \
2179 && elf_tdata (bfd) != NULL \
2180 && elf_object_id (bfd) == AARCH64_ELF_DATA)
2183 elfNN_aarch64_mkobject (bfd
*abfd
)
2185 return bfd_elf_allocate_object (abfd
, sizeof (struct elf_aarch64_obj_tdata
),
2189 #define elf_aarch64_hash_entry(ent) \
2190 ((struct elf_aarch64_link_hash_entry *)(ent))
2192 #define GOT_UNKNOWN 0
2193 #define GOT_NORMAL 1
2194 #define GOT_TLS_GD 2
2195 #define GOT_TLS_IE 4
2196 #define GOT_TLSDESC_GD 8
2198 #define GOT_TLS_GD_ANY_P(type) ((type & GOT_TLS_GD) || (type & GOT_TLSDESC_GD))
2200 /* AArch64 ELF linker hash entry. */
2201 struct elf_aarch64_link_hash_entry
2203 struct elf_link_hash_entry root
;
2205 /* Track dynamic relocs copied for this symbol. */
2206 struct elf_dyn_relocs
*dyn_relocs
;
2208 /* Since PLT entries have variable size, we need to record the
2209 index into .got.plt instead of recomputing it from the PLT
2211 bfd_signed_vma plt_got_offset
;
2213 /* Bit mask representing the type of GOT entry(s) if any required by
2215 unsigned int got_type
;
2217 /* A pointer to the most recently used stub hash entry against this
2219 struct elf_aarch64_stub_hash_entry
*stub_cache
;
2221 /* Offset of the GOTPLT entry reserved for the TLS descriptor. The offset
2222 is from the end of the jump table and reserved entries within the PLTGOT.
2224 The magic value (bfd_vma) -1 indicates that an offset has not
2226 bfd_vma tlsdesc_got_jump_table_offset
;
2230 elfNN_aarch64_symbol_got_type (struct elf_link_hash_entry
*h
,
2232 unsigned long r_symndx
)
2235 return elf_aarch64_hash_entry (h
)->got_type
;
2237 if (! elf_aarch64_locals (abfd
))
2240 return elf_aarch64_locals (abfd
)[r_symndx
].got_type
;
2243 /* Get the AArch64 elf linker hash table from a link_info structure. */
2244 #define elf_aarch64_hash_table(info) \
2245 ((struct elf_aarch64_link_hash_table *) ((info)->hash))
2247 #define aarch64_stub_hash_lookup(table, string, create, copy) \
2248 ((struct elf_aarch64_stub_hash_entry *) \
2249 bfd_hash_lookup ((table), (string), (create), (copy)))
2251 /* AArch64 ELF linker hash table. */
2252 struct elf_aarch64_link_hash_table
2254 /* The main hash table. */
2255 struct elf_link_hash_table root
;
2257 /* Nonzero to force PIC branch veneers. */
2260 /* Fix erratum 835769. */
2261 int fix_erratum_835769
;
2263 /* Fix erratum 843419. */
2264 int fix_erratum_843419
;
2266 /* Enable ADRP->ADR rewrite for erratum 843419 workaround. */
2267 int fix_erratum_843419_adr
;
2269 /* The number of bytes in the initial entry in the PLT. */
2270 bfd_size_type plt_header_size
;
2272 /* The number of bytes in the subsequent PLT etries. */
2273 bfd_size_type plt_entry_size
;
2275 /* Short-cuts to get to dynamic linker sections. */
2279 /* Small local sym cache. */
2280 struct sym_cache sym_cache
;
2282 /* For convenience in allocate_dynrelocs. */
2285 /* The amount of space used by the reserved portion of the sgotplt
2286 section, plus whatever space is used by the jump slots. */
2287 bfd_vma sgotplt_jump_table_size
;
2289 /* The stub hash table. */
2290 struct bfd_hash_table stub_hash_table
;
2292 /* Linker stub bfd. */
2295 /* Linker call-backs. */
2296 asection
*(*add_stub_section
) (const char *, asection
*);
2297 void (*layout_sections_again
) (void);
2299 /* Array to keep track of which stub sections have been created, and
2300 information on stub grouping. */
2303 /* This is the section to which stubs in the group will be
2306 /* The stub section. */
2310 /* Assorted information used by elfNN_aarch64_size_stubs. */
2311 unsigned int bfd_count
;
2312 unsigned int top_index
;
2313 asection
**input_list
;
2315 /* The offset into splt of the PLT entry for the TLS descriptor
2316 resolver. Special values are 0, if not necessary (or not found
2317 to be necessary yet), and -1 if needed but not determined
2319 bfd_vma tlsdesc_plt
;
2321 /* The GOT offset for the lazy trampoline. Communicated to the
2322 loader via DT_TLSDESC_GOT. The magic value (bfd_vma) -1
2323 indicates an offset is not allocated. */
2324 bfd_vma dt_tlsdesc_got
;
2326 /* Used by local STT_GNU_IFUNC symbols. */
2327 htab_t loc_hash_table
;
2328 void * loc_hash_memory
;
2331 /* Create an entry in an AArch64 ELF linker hash table. */
2333 static struct bfd_hash_entry
*
2334 elfNN_aarch64_link_hash_newfunc (struct bfd_hash_entry
*entry
,
2335 struct bfd_hash_table
*table
,
2338 struct elf_aarch64_link_hash_entry
*ret
=
2339 (struct elf_aarch64_link_hash_entry
*) entry
;
2341 /* Allocate the structure if it has not already been allocated by a
2344 ret
= bfd_hash_allocate (table
,
2345 sizeof (struct elf_aarch64_link_hash_entry
));
2347 return (struct bfd_hash_entry
*) ret
;
2349 /* Call the allocation method of the superclass. */
2350 ret
= ((struct elf_aarch64_link_hash_entry
*)
2351 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry
*) ret
,
2355 ret
->dyn_relocs
= NULL
;
2356 ret
->got_type
= GOT_UNKNOWN
;
2357 ret
->plt_got_offset
= (bfd_vma
) - 1;
2358 ret
->stub_cache
= NULL
;
2359 ret
->tlsdesc_got_jump_table_offset
= (bfd_vma
) - 1;
2362 return (struct bfd_hash_entry
*) ret
;
2365 /* Initialize an entry in the stub hash table. */
2367 static struct bfd_hash_entry
*
2368 stub_hash_newfunc (struct bfd_hash_entry
*entry
,
2369 struct bfd_hash_table
*table
, const char *string
)
2371 /* Allocate the structure if it has not already been allocated by a
2375 entry
= bfd_hash_allocate (table
,
2377 elf_aarch64_stub_hash_entry
));
2382 /* Call the allocation method of the superclass. */
2383 entry
= bfd_hash_newfunc (entry
, table
, string
);
2386 struct elf_aarch64_stub_hash_entry
*eh
;
2388 /* Initialize the local fields. */
2389 eh
= (struct elf_aarch64_stub_hash_entry
*) entry
;
2390 eh
->adrp_offset
= 0;
2391 eh
->stub_sec
= NULL
;
2392 eh
->stub_offset
= 0;
2393 eh
->target_value
= 0;
2394 eh
->target_section
= NULL
;
2395 eh
->stub_type
= aarch64_stub_none
;
2403 /* Compute a hash of a local hash entry. We use elf_link_hash_entry
2404 for local symbol so that we can handle local STT_GNU_IFUNC symbols
2405 as global symbol. We reuse indx and dynstr_index for local symbol
2406 hash since they aren't used by global symbols in this backend. */
2409 elfNN_aarch64_local_htab_hash (const void *ptr
)
2411 struct elf_link_hash_entry
*h
2412 = (struct elf_link_hash_entry
*) ptr
;
2413 return ELF_LOCAL_SYMBOL_HASH (h
->indx
, h
->dynstr_index
);
2416 /* Compare local hash entries. */
2419 elfNN_aarch64_local_htab_eq (const void *ptr1
, const void *ptr2
)
2421 struct elf_link_hash_entry
*h1
2422 = (struct elf_link_hash_entry
*) ptr1
;
2423 struct elf_link_hash_entry
*h2
2424 = (struct elf_link_hash_entry
*) ptr2
;
2426 return h1
->indx
== h2
->indx
&& h1
->dynstr_index
== h2
->dynstr_index
;
2429 /* Find and/or create a hash entry for local symbol. */
2431 static struct elf_link_hash_entry
*
2432 elfNN_aarch64_get_local_sym_hash (struct elf_aarch64_link_hash_table
*htab
,
2433 bfd
*abfd
, const Elf_Internal_Rela
*rel
,
2436 struct elf_aarch64_link_hash_entry e
, *ret
;
2437 asection
*sec
= abfd
->sections
;
2438 hashval_t h
= ELF_LOCAL_SYMBOL_HASH (sec
->id
,
2439 ELFNN_R_SYM (rel
->r_info
));
2442 e
.root
.indx
= sec
->id
;
2443 e
.root
.dynstr_index
= ELFNN_R_SYM (rel
->r_info
);
2444 slot
= htab_find_slot_with_hash (htab
->loc_hash_table
, &e
, h
,
2445 create
? INSERT
: NO_INSERT
);
2452 ret
= (struct elf_aarch64_link_hash_entry
*) *slot
;
2456 ret
= (struct elf_aarch64_link_hash_entry
*)
2457 objalloc_alloc ((struct objalloc
*) htab
->loc_hash_memory
,
2458 sizeof (struct elf_aarch64_link_hash_entry
));
2461 memset (ret
, 0, sizeof (*ret
));
2462 ret
->root
.indx
= sec
->id
;
2463 ret
->root
.dynstr_index
= ELFNN_R_SYM (rel
->r_info
);
2464 ret
->root
.dynindx
= -1;
2470 /* Copy the extra info we tack onto an elf_link_hash_entry. */
2473 elfNN_aarch64_copy_indirect_symbol (struct bfd_link_info
*info
,
2474 struct elf_link_hash_entry
*dir
,
2475 struct elf_link_hash_entry
*ind
)
2477 struct elf_aarch64_link_hash_entry
*edir
, *eind
;
2479 edir
= (struct elf_aarch64_link_hash_entry
*) dir
;
2480 eind
= (struct elf_aarch64_link_hash_entry
*) ind
;
2482 if (eind
->dyn_relocs
!= NULL
)
2484 if (edir
->dyn_relocs
!= NULL
)
2486 struct elf_dyn_relocs
**pp
;
2487 struct elf_dyn_relocs
*p
;
2489 /* Add reloc counts against the indirect sym to the direct sym
2490 list. Merge any entries against the same section. */
2491 for (pp
= &eind
->dyn_relocs
; (p
= *pp
) != NULL
;)
2493 struct elf_dyn_relocs
*q
;
2495 for (q
= edir
->dyn_relocs
; q
!= NULL
; q
= q
->next
)
2496 if (q
->sec
== p
->sec
)
2498 q
->pc_count
+= p
->pc_count
;
2499 q
->count
+= p
->count
;
2506 *pp
= edir
->dyn_relocs
;
2509 edir
->dyn_relocs
= eind
->dyn_relocs
;
2510 eind
->dyn_relocs
= NULL
;
2513 if (ind
->root
.type
== bfd_link_hash_indirect
)
2515 /* Copy over PLT info. */
2516 if (dir
->got
.refcount
<= 0)
2518 edir
->got_type
= eind
->got_type
;
2519 eind
->got_type
= GOT_UNKNOWN
;
2523 _bfd_elf_link_hash_copy_indirect (info
, dir
, ind
);
2526 /* Destroy an AArch64 elf linker hash table. */
2529 elfNN_aarch64_link_hash_table_free (bfd
*obfd
)
2531 struct elf_aarch64_link_hash_table
*ret
2532 = (struct elf_aarch64_link_hash_table
*) obfd
->link
.hash
;
2534 if (ret
->loc_hash_table
)
2535 htab_delete (ret
->loc_hash_table
);
2536 if (ret
->loc_hash_memory
)
2537 objalloc_free ((struct objalloc
*) ret
->loc_hash_memory
);
2539 bfd_hash_table_free (&ret
->stub_hash_table
);
2540 _bfd_elf_link_hash_table_free (obfd
);
2543 /* Create an AArch64 elf linker hash table. */
2545 static struct bfd_link_hash_table
*
2546 elfNN_aarch64_link_hash_table_create (bfd
*abfd
)
2548 struct elf_aarch64_link_hash_table
*ret
;
2549 bfd_size_type amt
= sizeof (struct elf_aarch64_link_hash_table
);
2551 ret
= bfd_zmalloc (amt
);
2555 if (!_bfd_elf_link_hash_table_init
2556 (&ret
->root
, abfd
, elfNN_aarch64_link_hash_newfunc
,
2557 sizeof (struct elf_aarch64_link_hash_entry
), AARCH64_ELF_DATA
))
2563 ret
->plt_header_size
= PLT_ENTRY_SIZE
;
2564 ret
->plt_entry_size
= PLT_SMALL_ENTRY_SIZE
;
2566 ret
->dt_tlsdesc_got
= (bfd_vma
) - 1;
2568 if (!bfd_hash_table_init (&ret
->stub_hash_table
, stub_hash_newfunc
,
2569 sizeof (struct elf_aarch64_stub_hash_entry
)))
2571 _bfd_elf_link_hash_table_free (abfd
);
2575 ret
->loc_hash_table
= htab_try_create (1024,
2576 elfNN_aarch64_local_htab_hash
,
2577 elfNN_aarch64_local_htab_eq
,
2579 ret
->loc_hash_memory
= objalloc_create ();
2580 if (!ret
->loc_hash_table
|| !ret
->loc_hash_memory
)
2582 elfNN_aarch64_link_hash_table_free (abfd
);
2585 ret
->root
.root
.hash_table_free
= elfNN_aarch64_link_hash_table_free
;
2587 return &ret
->root
.root
;
2591 aarch64_relocate (unsigned int r_type
, bfd
*input_bfd
, asection
*input_section
,
2592 bfd_vma offset
, bfd_vma value
)
2594 reloc_howto_type
*howto
;
2597 howto
= elfNN_aarch64_howto_from_type (r_type
);
2598 place
= (input_section
->output_section
->vma
+ input_section
->output_offset
2601 r_type
= elfNN_aarch64_bfd_reloc_from_type (r_type
);
2602 value
= _bfd_aarch64_elf_resolve_relocation (r_type
, place
, value
, 0, FALSE
);
2603 return _bfd_aarch64_elf_put_addend (input_bfd
,
2604 input_section
->contents
+ offset
, r_type
,
2608 static enum elf_aarch64_stub_type
2609 aarch64_select_branch_stub (bfd_vma value
, bfd_vma place
)
2611 if (aarch64_valid_for_adrp_p (value
, place
))
2612 return aarch64_stub_adrp_branch
;
2613 return aarch64_stub_long_branch
;
2616 /* Determine the type of stub needed, if any, for a call. */
2618 static enum elf_aarch64_stub_type
2619 aarch64_type_of_stub (struct bfd_link_info
*info
,
2620 asection
*input_sec
,
2621 const Elf_Internal_Rela
*rel
,
2623 unsigned char st_type
,
2624 struct elf_aarch64_link_hash_entry
*hash
,
2625 bfd_vma destination
)
2628 bfd_signed_vma branch_offset
;
2629 unsigned int r_type
;
2630 struct elf_aarch64_link_hash_table
*globals
;
2631 enum elf_aarch64_stub_type stub_type
= aarch64_stub_none
;
2632 bfd_boolean via_plt_p
;
2634 if (st_type
!= STT_FUNC
2635 && (sym_sec
!= bfd_abs_section_ptr
))
2638 globals
= elf_aarch64_hash_table (info
);
2639 via_plt_p
= (globals
->root
.splt
!= NULL
&& hash
!= NULL
2640 && hash
->root
.plt
.offset
!= (bfd_vma
) - 1);
2641 /* Make sure call to plt stub can fit into the branch range. */
2643 destination
= (globals
->root
.splt
->output_section
->vma
2644 + globals
->root
.splt
->output_offset
2645 + hash
->root
.plt
.offset
);
2647 /* Determine where the call point is. */
2648 location
= (input_sec
->output_offset
2649 + input_sec
->output_section
->vma
+ rel
->r_offset
);
2651 branch_offset
= (bfd_signed_vma
) (destination
- location
);
2653 r_type
= ELFNN_R_TYPE (rel
->r_info
);
2655 /* We don't want to redirect any old unconditional jump in this way,
2656 only one which is being used for a sibcall, where it is
2657 acceptable for the IP0 and IP1 registers to be clobbered. */
2658 if ((r_type
== AARCH64_R (CALL26
) || r_type
== AARCH64_R (JUMP26
))
2659 && (branch_offset
> AARCH64_MAX_FWD_BRANCH_OFFSET
2660 || branch_offset
< AARCH64_MAX_BWD_BRANCH_OFFSET
))
2662 stub_type
= aarch64_stub_long_branch
;
2668 /* Build a name for an entry in the stub hash table. */
2671 elfNN_aarch64_stub_name (const asection
*input_section
,
2672 const asection
*sym_sec
,
2673 const struct elf_aarch64_link_hash_entry
*hash
,
2674 const Elf_Internal_Rela
*rel
)
2681 len
= 8 + 1 + strlen (hash
->root
.root
.root
.string
) + 1 + 16 + 1;
2682 stub_name
= bfd_malloc (len
);
2683 if (stub_name
!= NULL
)
2684 snprintf (stub_name
, len
, "%08x_%s+%" BFD_VMA_FMT
"x",
2685 (unsigned int) input_section
->id
,
2686 hash
->root
.root
.root
.string
,
2691 len
= 8 + 1 + 8 + 1 + 8 + 1 + 16 + 1;
2692 stub_name
= bfd_malloc (len
);
2693 if (stub_name
!= NULL
)
2694 snprintf (stub_name
, len
, "%08x_%x:%x+%" BFD_VMA_FMT
"x",
2695 (unsigned int) input_section
->id
,
2696 (unsigned int) sym_sec
->id
,
2697 (unsigned int) ELFNN_R_SYM (rel
->r_info
),
2704 /* Look up an entry in the stub hash. Stub entries are cached because
2705 creating the stub name takes a bit of time. */
2707 static struct elf_aarch64_stub_hash_entry
*
2708 elfNN_aarch64_get_stub_entry (const asection
*input_section
,
2709 const asection
*sym_sec
,
2710 struct elf_link_hash_entry
*hash
,
2711 const Elf_Internal_Rela
*rel
,
2712 struct elf_aarch64_link_hash_table
*htab
)
2714 struct elf_aarch64_stub_hash_entry
*stub_entry
;
2715 struct elf_aarch64_link_hash_entry
*h
=
2716 (struct elf_aarch64_link_hash_entry
*) hash
;
2717 const asection
*id_sec
;
2719 if ((input_section
->flags
& SEC_CODE
) == 0)
2722 /* If this input section is part of a group of sections sharing one
2723 stub section, then use the id of the first section in the group.
2724 Stub names need to include a section id, as there may well be
2725 more than one stub used to reach say, printf, and we need to
2726 distinguish between them. */
2727 id_sec
= htab
->stub_group
[input_section
->id
].link_sec
;
2729 if (h
!= NULL
&& h
->stub_cache
!= NULL
2730 && h
->stub_cache
->h
== h
&& h
->stub_cache
->id_sec
== id_sec
)
2732 stub_entry
= h
->stub_cache
;
2738 stub_name
= elfNN_aarch64_stub_name (id_sec
, sym_sec
, h
, rel
);
2739 if (stub_name
== NULL
)
2742 stub_entry
= aarch64_stub_hash_lookup (&htab
->stub_hash_table
,
2743 stub_name
, FALSE
, FALSE
);
2745 h
->stub_cache
= stub_entry
;
2754 /* Create a stub section. */
2757 _bfd_aarch64_create_stub_section (asection
*section
,
2758 struct elf_aarch64_link_hash_table
*htab
)
2764 namelen
= strlen (section
->name
);
2765 len
= namelen
+ sizeof (STUB_SUFFIX
);
2766 s_name
= bfd_alloc (htab
->stub_bfd
, len
);
2770 memcpy (s_name
, section
->name
, namelen
);
2771 memcpy (s_name
+ namelen
, STUB_SUFFIX
, sizeof (STUB_SUFFIX
));
2772 return (*htab
->add_stub_section
) (s_name
, section
);
2776 /* Find or create a stub section for a link section.
2778 Fix or create the stub section used to collect stubs attached to
2779 the specified link section. */
2782 _bfd_aarch64_get_stub_for_link_section (asection
*link_section
,
2783 struct elf_aarch64_link_hash_table
*htab
)
2785 if (htab
->stub_group
[link_section
->id
].stub_sec
== NULL
)
2786 htab
->stub_group
[link_section
->id
].stub_sec
2787 = _bfd_aarch64_create_stub_section (link_section
, htab
);
2788 return htab
->stub_group
[link_section
->id
].stub_sec
;
2792 /* Find or create a stub section in the stub group for an input
2796 _bfd_aarch64_create_or_find_stub_sec (asection
*section
,
2797 struct elf_aarch64_link_hash_table
*htab
)
2799 asection
*link_sec
= htab
->stub_group
[section
->id
].link_sec
;
2800 return _bfd_aarch64_get_stub_for_link_section (link_sec
, htab
);
2804 /* Add a new stub entry in the stub group associated with an input
2805 section to the stub hash. Not all fields of the new stub entry are
2808 static struct elf_aarch64_stub_hash_entry
*
2809 _bfd_aarch64_add_stub_entry_in_group (const char *stub_name
,
2811 struct elf_aarch64_link_hash_table
*htab
)
2815 struct elf_aarch64_stub_hash_entry
*stub_entry
;
2817 link_sec
= htab
->stub_group
[section
->id
].link_sec
;
2818 stub_sec
= _bfd_aarch64_create_or_find_stub_sec (section
, htab
);
2820 /* Enter this entry into the linker stub hash table. */
2821 stub_entry
= aarch64_stub_hash_lookup (&htab
->stub_hash_table
, stub_name
,
2823 if (stub_entry
== NULL
)
2825 (*_bfd_error_handler
) (_("%s: cannot create stub entry %s"),
2826 section
->owner
, stub_name
);
2830 stub_entry
->stub_sec
= stub_sec
;
2831 stub_entry
->stub_offset
= 0;
2832 stub_entry
->id_sec
= link_sec
;
2837 /* Add a new stub entry in the final stub section to the stub hash.
2838 Not all fields of the new stub entry are initialised. */
2840 static struct elf_aarch64_stub_hash_entry
*
2841 _bfd_aarch64_add_stub_entry_after (const char *stub_name
,
2842 asection
*link_section
,
2843 struct elf_aarch64_link_hash_table
*htab
)
2846 struct elf_aarch64_stub_hash_entry
*stub_entry
;
2848 stub_sec
= _bfd_aarch64_get_stub_for_link_section (link_section
, htab
);
2849 stub_entry
= aarch64_stub_hash_lookup (&htab
->stub_hash_table
, stub_name
,
2851 if (stub_entry
== NULL
)
2853 (*_bfd_error_handler
) (_("cannot create stub entry %s"), stub_name
);
2857 stub_entry
->stub_sec
= stub_sec
;
2858 stub_entry
->stub_offset
= 0;
2859 stub_entry
->id_sec
= link_section
;
2866 aarch64_build_one_stub (struct bfd_hash_entry
*gen_entry
,
2867 void *in_arg ATTRIBUTE_UNUSED
)
2869 struct elf_aarch64_stub_hash_entry
*stub_entry
;
2874 bfd_vma veneered_insn_loc
;
2875 bfd_vma veneer_entry_loc
;
2876 bfd_signed_vma branch_offset
= 0;
2877 unsigned int template_size
;
2878 const uint32_t *template;
2881 /* Massage our args to the form they really have. */
2882 stub_entry
= (struct elf_aarch64_stub_hash_entry
*) gen_entry
;
2884 stub_sec
= stub_entry
->stub_sec
;
2886 /* Make a note of the offset within the stubs for this entry. */
2887 stub_entry
->stub_offset
= stub_sec
->size
;
2888 loc
= stub_sec
->contents
+ stub_entry
->stub_offset
;
2890 stub_bfd
= stub_sec
->owner
;
2892 /* This is the address of the stub destination. */
2893 sym_value
= (stub_entry
->target_value
2894 + stub_entry
->target_section
->output_offset
2895 + stub_entry
->target_section
->output_section
->vma
);
2897 if (stub_entry
->stub_type
== aarch64_stub_long_branch
)
2899 bfd_vma place
= (stub_entry
->stub_offset
+ stub_sec
->output_section
->vma
2900 + stub_sec
->output_offset
);
2902 /* See if we can relax the stub. */
2903 if (aarch64_valid_for_adrp_p (sym_value
, place
))
2904 stub_entry
->stub_type
= aarch64_select_branch_stub (sym_value
, place
);
2907 switch (stub_entry
->stub_type
)
2909 case aarch64_stub_adrp_branch
:
2910 template = aarch64_adrp_branch_stub
;
2911 template_size
= sizeof (aarch64_adrp_branch_stub
);
2913 case aarch64_stub_long_branch
:
2914 template = aarch64_long_branch_stub
;
2915 template_size
= sizeof (aarch64_long_branch_stub
);
2917 case aarch64_stub_erratum_835769_veneer
:
2918 template = aarch64_erratum_835769_stub
;
2919 template_size
= sizeof (aarch64_erratum_835769_stub
);
2921 case aarch64_stub_erratum_843419_veneer
:
2922 template = aarch64_erratum_843419_stub
;
2923 template_size
= sizeof (aarch64_erratum_843419_stub
);
2929 for (i
= 0; i
< (template_size
/ sizeof template[0]); i
++)
2931 bfd_putl32 (template[i
], loc
);
2935 template_size
= (template_size
+ 7) & ~7;
2936 stub_sec
->size
+= template_size
;
2938 switch (stub_entry
->stub_type
)
2940 case aarch64_stub_adrp_branch
:
2941 if (aarch64_relocate (AARCH64_R (ADR_PREL_PG_HI21
), stub_bfd
, stub_sec
,
2942 stub_entry
->stub_offset
, sym_value
))
2943 /* The stub would not have been relaxed if the offset was out
2947 if (aarch64_relocate (AARCH64_R (ADD_ABS_LO12_NC
), stub_bfd
, stub_sec
,
2948 stub_entry
->stub_offset
+ 4, sym_value
))
2952 case aarch64_stub_long_branch
:
2953 /* We want the value relative to the address 12 bytes back from the
2955 if (aarch64_relocate (AARCH64_R (PRELNN
), stub_bfd
, stub_sec
,
2956 stub_entry
->stub_offset
+ 16, sym_value
+ 12))
2960 case aarch64_stub_erratum_835769_veneer
:
2961 veneered_insn_loc
= stub_entry
->target_section
->output_section
->vma
2962 + stub_entry
->target_section
->output_offset
2963 + stub_entry
->target_value
;
2964 veneer_entry_loc
= stub_entry
->stub_sec
->output_section
->vma
2965 + stub_entry
->stub_sec
->output_offset
2966 + stub_entry
->stub_offset
;
2967 branch_offset
= veneered_insn_loc
- veneer_entry_loc
;
2968 branch_offset
>>= 2;
2969 branch_offset
&= 0x3ffffff;
2970 bfd_putl32 (stub_entry
->veneered_insn
,
2971 stub_sec
->contents
+ stub_entry
->stub_offset
);
2972 bfd_putl32 (template[1] | branch_offset
,
2973 stub_sec
->contents
+ stub_entry
->stub_offset
+ 4);
2976 case aarch64_stub_erratum_843419_veneer
:
2977 if (aarch64_relocate (AARCH64_R (JUMP26
), stub_bfd
, stub_sec
,
2978 stub_entry
->stub_offset
+ 4, sym_value
+ 4))
2989 /* As above, but don't actually build the stub. Just bump offset so
2990 we know stub section sizes. */
2993 aarch64_size_one_stub (struct bfd_hash_entry
*gen_entry
,
2994 void *in_arg ATTRIBUTE_UNUSED
)
2996 struct elf_aarch64_stub_hash_entry
*stub_entry
;
2999 /* Massage our args to the form they really have. */
3000 stub_entry
= (struct elf_aarch64_stub_hash_entry
*) gen_entry
;
3002 switch (stub_entry
->stub_type
)
3004 case aarch64_stub_adrp_branch
:
3005 size
= sizeof (aarch64_adrp_branch_stub
);
3007 case aarch64_stub_long_branch
:
3008 size
= sizeof (aarch64_long_branch_stub
);
3010 case aarch64_stub_erratum_835769_veneer
:
3011 size
= sizeof (aarch64_erratum_835769_stub
);
3013 case aarch64_stub_erratum_843419_veneer
:
3014 size
= sizeof (aarch64_erratum_843419_stub
);
3020 size
= (size
+ 7) & ~7;
3021 stub_entry
->stub_sec
->size
+= size
;
3025 /* External entry points for sizing and building linker stubs. */
3027 /* Set up various things so that we can make a list of input sections
3028 for each output section included in the link. Returns -1 on error,
3029 0 when no stubs will be needed, and 1 on success. */
3032 elfNN_aarch64_setup_section_lists (bfd
*output_bfd
,
3033 struct bfd_link_info
*info
)
3036 unsigned int bfd_count
;
3037 unsigned int top_id
, top_index
;
3039 asection
**input_list
, **list
;
3041 struct elf_aarch64_link_hash_table
*htab
=
3042 elf_aarch64_hash_table (info
);
3044 if (!is_elf_hash_table (htab
))
3047 /* Count the number of input BFDs and find the top input section id. */
3048 for (input_bfd
= info
->input_bfds
, bfd_count
= 0, top_id
= 0;
3049 input_bfd
!= NULL
; input_bfd
= input_bfd
->link
.next
)
3052 for (section
= input_bfd
->sections
;
3053 section
!= NULL
; section
= section
->next
)
3055 if (top_id
< section
->id
)
3056 top_id
= section
->id
;
3059 htab
->bfd_count
= bfd_count
;
3061 amt
= sizeof (struct map_stub
) * (top_id
+ 1);
3062 htab
->stub_group
= bfd_zmalloc (amt
);
3063 if (htab
->stub_group
== NULL
)
3066 /* We can't use output_bfd->section_count here to find the top output
3067 section index as some sections may have been removed, and
3068 _bfd_strip_section_from_output doesn't renumber the indices. */
3069 for (section
= output_bfd
->sections
, top_index
= 0;
3070 section
!= NULL
; section
= section
->next
)
3072 if (top_index
< section
->index
)
3073 top_index
= section
->index
;
3076 htab
->top_index
= top_index
;
3077 amt
= sizeof (asection
*) * (top_index
+ 1);
3078 input_list
= bfd_malloc (amt
);
3079 htab
->input_list
= input_list
;
3080 if (input_list
== NULL
)
3083 /* For sections we aren't interested in, mark their entries with a
3084 value we can check later. */
3085 list
= input_list
+ top_index
;
3087 *list
= bfd_abs_section_ptr
;
3088 while (list
-- != input_list
);
3090 for (section
= output_bfd
->sections
;
3091 section
!= NULL
; section
= section
->next
)
3093 if ((section
->flags
& SEC_CODE
) != 0)
3094 input_list
[section
->index
] = NULL
;
3100 /* Used by elfNN_aarch64_next_input_section and group_sections. */
3101 #define PREV_SEC(sec) (htab->stub_group[(sec)->id].link_sec)
3103 /* The linker repeatedly calls this function for each input section,
3104 in the order that input sections are linked into output sections.
3105 Build lists of input sections to determine groupings between which
3106 we may insert linker stubs. */
3109 elfNN_aarch64_next_input_section (struct bfd_link_info
*info
, asection
*isec
)
3111 struct elf_aarch64_link_hash_table
*htab
=
3112 elf_aarch64_hash_table (info
);
3114 if (isec
->output_section
->index
<= htab
->top_index
)
3116 asection
**list
= htab
->input_list
+ isec
->output_section
->index
;
3118 if (*list
!= bfd_abs_section_ptr
)
3120 /* Steal the link_sec pointer for our list. */
3121 /* This happens to make the list in reverse order,
3122 which is what we want. */
3123 PREV_SEC (isec
) = *list
;
3129 /* See whether we can group stub sections together. Grouping stub
3130 sections may result in fewer stubs. More importantly, we need to
3131 put all .init* and .fini* stubs at the beginning of the .init or
3132 .fini output sections respectively, because glibc splits the
3133 _init and _fini functions into multiple parts. Putting a stub in
3134 the middle of a function is not a good idea. */
3137 group_sections (struct elf_aarch64_link_hash_table
*htab
,
3138 bfd_size_type stub_group_size
,
3139 bfd_boolean stubs_always_before_branch
)
3141 asection
**list
= htab
->input_list
+ htab
->top_index
;
3145 asection
*tail
= *list
;
3147 if (tail
== bfd_abs_section_ptr
)
3150 while (tail
!= NULL
)
3154 bfd_size_type total
;
3158 while ((prev
= PREV_SEC (curr
)) != NULL
3159 && ((total
+= curr
->output_offset
- prev
->output_offset
)
3163 /* OK, the size from the start of CURR to the end is less
3164 than stub_group_size and thus can be handled by one stub
3165 section. (Or the tail section is itself larger than
3166 stub_group_size, in which case we may be toast.)
3167 We should really be keeping track of the total size of
3168 stubs added here, as stubs contribute to the final output
3172 prev
= PREV_SEC (tail
);
3173 /* Set up this stub group. */
3174 htab
->stub_group
[tail
->id
].link_sec
= curr
;
3176 while (tail
!= curr
&& (tail
= prev
) != NULL
);
3178 /* But wait, there's more! Input sections up to stub_group_size
3179 bytes before the stub section can be handled by it too. */
3180 if (!stubs_always_before_branch
)
3184 && ((total
+= tail
->output_offset
- prev
->output_offset
)
3188 prev
= PREV_SEC (tail
);
3189 htab
->stub_group
[tail
->id
].link_sec
= curr
;
3195 while (list
-- != htab
->input_list
);
3197 free (htab
->input_list
);
3202 #define AARCH64_BITS(x, pos, n) (((x) >> (pos)) & ((1 << (n)) - 1))
3204 #define AARCH64_RT(insn) AARCH64_BITS (insn, 0, 5)
3205 #define AARCH64_RT2(insn) AARCH64_BITS (insn, 10, 5)
3206 #define AARCH64_RA(insn) AARCH64_BITS (insn, 10, 5)
3207 #define AARCH64_RD(insn) AARCH64_BITS (insn, 0, 5)
3208 #define AARCH64_RN(insn) AARCH64_BITS (insn, 5, 5)
3209 #define AARCH64_RM(insn) AARCH64_BITS (insn, 16, 5)
3211 #define AARCH64_MAC(insn) (((insn) & 0xff000000) == 0x9b000000)
3212 #define AARCH64_BIT(insn, n) AARCH64_BITS (insn, n, 1)
3213 #define AARCH64_OP31(insn) AARCH64_BITS (insn, 21, 3)
3214 #define AARCH64_ZR 0x1f
3216 /* All ld/st ops. See C4-182 of the ARM ARM. The encoding space for
3217 LD_PCREL, LDST_RO, LDST_UI and LDST_UIMM cover prefetch ops. */
3219 #define AARCH64_LD(insn) (AARCH64_BIT (insn, 22) == 1)
3220 #define AARCH64_LDST(insn) (((insn) & 0x0a000000) == 0x08000000)
3221 #define AARCH64_LDST_EX(insn) (((insn) & 0x3f000000) == 0x08000000)
3222 #define AARCH64_LDST_PCREL(insn) (((insn) & 0x3b000000) == 0x18000000)
3223 #define AARCH64_LDST_NAP(insn) (((insn) & 0x3b800000) == 0x28000000)
3224 #define AARCH64_LDSTP_PI(insn) (((insn) & 0x3b800000) == 0x28800000)
3225 #define AARCH64_LDSTP_O(insn) (((insn) & 0x3b800000) == 0x29000000)
3226 #define AARCH64_LDSTP_PRE(insn) (((insn) & 0x3b800000) == 0x29800000)
3227 #define AARCH64_LDST_UI(insn) (((insn) & 0x3b200c00) == 0x38000000)
3228 #define AARCH64_LDST_PIIMM(insn) (((insn) & 0x3b200c00) == 0x38000400)
3229 #define AARCH64_LDST_U(insn) (((insn) & 0x3b200c00) == 0x38000800)
3230 #define AARCH64_LDST_PREIMM(insn) (((insn) & 0x3b200c00) == 0x38000c00)
3231 #define AARCH64_LDST_RO(insn) (((insn) & 0x3b200c00) == 0x38200800)
3232 #define AARCH64_LDST_UIMM(insn) (((insn) & 0x3b000000) == 0x39000000)
3233 #define AARCH64_LDST_SIMD_M(insn) (((insn) & 0xbfbf0000) == 0x0c000000)
3234 #define AARCH64_LDST_SIMD_M_PI(insn) (((insn) & 0xbfa00000) == 0x0c800000)
3235 #define AARCH64_LDST_SIMD_S(insn) (((insn) & 0xbf9f0000) == 0x0d000000)
3236 #define AARCH64_LDST_SIMD_S_PI(insn) (((insn) & 0xbf800000) == 0x0d800000)
3238 /* Classify an INSN if it is indeed a load/store.
3240 Return TRUE if INSN is a LD/ST instruction otherwise return FALSE.
3242 For scalar LD/ST instructions PAIR is FALSE, RT is returned and RT2
3245 For LD/ST pair instructions PAIR is TRUE, RT and RT2 are returned.
3250 aarch64_mem_op_p (uint32_t insn
, unsigned int *rt
, unsigned int *rt2
,
3251 bfd_boolean
*pair
, bfd_boolean
*load
)
3259 /* Bail out quickly if INSN doesn't fall into the the load-store
3261 if (!AARCH64_LDST (insn
))
3266 if (AARCH64_LDST_EX (insn
))
3268 *rt
= AARCH64_RT (insn
);
3270 if (AARCH64_BIT (insn
, 21) == 1)
3273 *rt2
= AARCH64_RT2 (insn
);
3275 *load
= AARCH64_LD (insn
);
3278 else if (AARCH64_LDST_NAP (insn
)
3279 || AARCH64_LDSTP_PI (insn
)
3280 || AARCH64_LDSTP_O (insn
)
3281 || AARCH64_LDSTP_PRE (insn
))
3284 *rt
= AARCH64_RT (insn
);
3285 *rt2
= AARCH64_RT2 (insn
);
3286 *load
= AARCH64_LD (insn
);
3289 else if (AARCH64_LDST_PCREL (insn
)
3290 || AARCH64_LDST_UI (insn
)
3291 || AARCH64_LDST_PIIMM (insn
)
3292 || AARCH64_LDST_U (insn
)
3293 || AARCH64_LDST_PREIMM (insn
)
3294 || AARCH64_LDST_RO (insn
)
3295 || AARCH64_LDST_UIMM (insn
))
3297 *rt
= AARCH64_RT (insn
);
3299 if (AARCH64_LDST_PCREL (insn
))
3301 opc
= AARCH64_BITS (insn
, 22, 2);
3302 v
= AARCH64_BIT (insn
, 26);
3303 opc_v
= opc
| (v
<< 2);
3304 *load
= (opc_v
== 1 || opc_v
== 2 || opc_v
== 3
3305 || opc_v
== 5 || opc_v
== 7);
3308 else if (AARCH64_LDST_SIMD_M (insn
)
3309 || AARCH64_LDST_SIMD_M_PI (insn
))
3311 *rt
= AARCH64_RT (insn
);
3312 *load
= AARCH64_BIT (insn
, 22);
3313 opcode
= (insn
>> 12) & 0xf;
3340 else if (AARCH64_LDST_SIMD_S (insn
)
3341 || AARCH64_LDST_SIMD_S_PI (insn
))
3343 *rt
= AARCH64_RT (insn
);
3344 r
= (insn
>> 21) & 1;
3345 *load
= AARCH64_BIT (insn
, 22);
3346 opcode
= (insn
>> 13) & 0x7;
3358 *rt2
= *rt
+ (r
== 0 ? 2 : 3);
3366 *rt2
= *rt
+ (r
== 0 ? 2 : 3);
3378 /* Return TRUE if INSN is multiply-accumulate. */
3381 aarch64_mlxl_p (uint32_t insn
)
3383 uint32_t op31
= AARCH64_OP31 (insn
);
3385 if (AARCH64_MAC (insn
)
3386 && (op31
== 0 || op31
== 1 || op31
== 5)
3387 /* Exclude MUL instructions which are encoded as a multiple accumulate
3389 && AARCH64_RA (insn
) != AARCH64_ZR
)
3395 /* Some early revisions of the Cortex-A53 have an erratum (835769) whereby
3396 it is possible for a 64-bit multiply-accumulate instruction to generate an
3397 incorrect result. The details are quite complex and hard to
3398 determine statically, since branches in the code may exist in some
3399 circumstances, but all cases end with a memory (load, store, or
3400 prefetch) instruction followed immediately by the multiply-accumulate
3401 operation. We employ a linker patching technique, by moving the potentially
3402 affected multiply-accumulate instruction into a patch region and replacing
3403 the original instruction with a branch to the patch. This function checks
3404 if INSN_1 is the memory operation followed by a multiply-accumulate
3405 operation (INSN_2). Return TRUE if an erratum sequence is found, FALSE
3406 if INSN_1 and INSN_2 are safe. */
3409 aarch64_erratum_sequence (uint32_t insn_1
, uint32_t insn_2
)
3419 if (aarch64_mlxl_p (insn_2
)
3420 && aarch64_mem_op_p (insn_1
, &rt
, &rt2
, &pair
, &load
))
3422 /* Any SIMD memory op is independent of the subsequent MLA
3423 by definition of the erratum. */
3424 if (AARCH64_BIT (insn_1
, 26))
3427 /* If not SIMD, check for integer memory ops and MLA relationship. */
3428 rn
= AARCH64_RN (insn_2
);
3429 ra
= AARCH64_RA (insn_2
);
3430 rm
= AARCH64_RM (insn_2
);
3432 /* If this is a load and there's a true(RAW) dependency, we are safe
3433 and this is not an erratum sequence. */
3435 (rt
== rn
|| rt
== rm
|| rt
== ra
3436 || (pair
&& (rt2
== rn
|| rt2
== rm
|| rt2
== ra
))))
3439 /* We conservatively put out stubs for all other cases (including
3447 /* Used to order a list of mapping symbols by address. */
3450 elf_aarch64_compare_mapping (const void *a
, const void *b
)
3452 const elf_aarch64_section_map
*amap
= (const elf_aarch64_section_map
*) a
;
3453 const elf_aarch64_section_map
*bmap
= (const elf_aarch64_section_map
*) b
;
3455 if (amap
->vma
> bmap
->vma
)
3457 else if (amap
->vma
< bmap
->vma
)
3459 else if (amap
->type
> bmap
->type
)
3460 /* Ensure results do not depend on the host qsort for objects with
3461 multiple mapping symbols at the same address by sorting on type
3464 else if (amap
->type
< bmap
->type
)
3472 _bfd_aarch64_erratum_835769_stub_name (unsigned num_fixes
)
3474 char *stub_name
= (char *) bfd_malloc
3475 (strlen ("__erratum_835769_veneer_") + 16);
3476 sprintf (stub_name
,"__erratum_835769_veneer_%d", num_fixes
);
3480 /* Scan for Cortex-A53 erratum 835769 sequence.
3482 Return TRUE else FALSE on abnormal termination. */
3485 _bfd_aarch64_erratum_835769_scan (bfd
*input_bfd
,
3486 struct bfd_link_info
*info
,
3487 unsigned int *num_fixes_p
)
3490 struct elf_aarch64_link_hash_table
*htab
= elf_aarch64_hash_table (info
);
3491 unsigned int num_fixes
= *num_fixes_p
;
3496 for (section
= input_bfd
->sections
;
3498 section
= section
->next
)
3500 bfd_byte
*contents
= NULL
;
3501 struct _aarch64_elf_section_data
*sec_data
;
3504 if (elf_section_type (section
) != SHT_PROGBITS
3505 || (elf_section_flags (section
) & SHF_EXECINSTR
) == 0
3506 || (section
->flags
& SEC_EXCLUDE
) != 0
3507 || (section
->sec_info_type
== SEC_INFO_TYPE_JUST_SYMS
)
3508 || (section
->output_section
== bfd_abs_section_ptr
))
3511 if (elf_section_data (section
)->this_hdr
.contents
!= NULL
)
3512 contents
= elf_section_data (section
)->this_hdr
.contents
;
3513 else if (! bfd_malloc_and_get_section (input_bfd
, section
, &contents
))
3516 sec_data
= elf_aarch64_section_data (section
);
3518 qsort (sec_data
->map
, sec_data
->mapcount
,
3519 sizeof (elf_aarch64_section_map
), elf_aarch64_compare_mapping
);
3521 for (span
= 0; span
< sec_data
->mapcount
; span
++)
3523 unsigned int span_start
= sec_data
->map
[span
].vma
;
3524 unsigned int span_end
= ((span
== sec_data
->mapcount
- 1)
3525 ? sec_data
->map
[0].vma
+ section
->size
3526 : sec_data
->map
[span
+ 1].vma
);
3528 char span_type
= sec_data
->map
[span
].type
;
3530 if (span_type
== 'd')
3533 for (i
= span_start
; i
+ 4 < span_end
; i
+= 4)
3535 uint32_t insn_1
= bfd_getl32 (contents
+ i
);
3536 uint32_t insn_2
= bfd_getl32 (contents
+ i
+ 4);
3538 if (aarch64_erratum_sequence (insn_1
, insn_2
))
3540 struct elf_aarch64_stub_hash_entry
*stub_entry
;
3541 char *stub_name
= _bfd_aarch64_erratum_835769_stub_name (num_fixes
);
3545 stub_entry
= _bfd_aarch64_add_stub_entry_in_group (stub_name
,
3551 stub_entry
->stub_type
= aarch64_stub_erratum_835769_veneer
;
3552 stub_entry
->target_section
= section
;
3553 stub_entry
->target_value
= i
+ 4;
3554 stub_entry
->veneered_insn
= insn_2
;
3555 stub_entry
->output_name
= stub_name
;
3560 if (elf_section_data (section
)->this_hdr
.contents
== NULL
)
3564 *num_fixes_p
= num_fixes
;
3570 /* Test if instruction INSN is ADRP. */
3573 _bfd_aarch64_adrp_p (uint32_t insn
)
3575 return ((insn
& 0x9f000000) == 0x90000000);
3579 /* Helper predicate to look for cortex-a53 erratum 843419 sequence 1. */
3582 _bfd_aarch64_erratum_843419_sequence_p (uint32_t insn_1
, uint32_t insn_2
,
3590 return (aarch64_mem_op_p (insn_2
, &rt
, &rt2
, &pair
, &load
)
3593 && AARCH64_LDST_UIMM (insn_3
)
3594 && AARCH64_RN (insn_3
) == AARCH64_RD (insn_1
));
3598 /* Test for the presence of Cortex-A53 erratum 843419 instruction sequence.
3600 Return TRUE if section CONTENTS at offset I contains one of the
3601 erratum 843419 sequences, otherwise return FALSE. If a sequence is
3602 seen set P_VENEER_I to the offset of the final LOAD/STORE
3603 instruction in the sequence.
3607 _bfd_aarch64_erratum_843419_p (bfd_byte
*contents
, bfd_vma vma
,
3608 bfd_vma i
, bfd_vma span_end
,
3609 bfd_vma
*p_veneer_i
)
3611 uint32_t insn_1
= bfd_getl32 (contents
+ i
);
3613 if (!_bfd_aarch64_adrp_p (insn_1
))
3616 if (span_end
< i
+ 12)
3619 uint32_t insn_2
= bfd_getl32 (contents
+ i
+ 4);
3620 uint32_t insn_3
= bfd_getl32 (contents
+ i
+ 8);
3622 if ((vma
& 0xfff) != 0xff8 && (vma
& 0xfff) != 0xffc)
3625 if (_bfd_aarch64_erratum_843419_sequence_p (insn_1
, insn_2
, insn_3
))
3627 *p_veneer_i
= i
+ 8;
3631 if (span_end
< i
+ 16)
3634 uint32_t insn_4
= bfd_getl32 (contents
+ i
+ 12);
3636 if (_bfd_aarch64_erratum_843419_sequence_p (insn_1
, insn_2
, insn_4
))
3638 *p_veneer_i
= i
+ 12;
3646 /* Resize all stub sections. */
3649 _bfd_aarch64_resize_stubs (struct elf_aarch64_link_hash_table
*htab
)
3653 /* OK, we've added some stubs. Find out the new size of the
3655 for (section
= htab
->stub_bfd
->sections
;
3656 section
!= NULL
; section
= section
->next
)
3658 /* Ignore non-stub sections. */
3659 if (!strstr (section
->name
, STUB_SUFFIX
))
3664 bfd_hash_traverse (&htab
->stub_hash_table
, aarch64_size_one_stub
, htab
);
3666 for (section
= htab
->stub_bfd
->sections
;
3667 section
!= NULL
; section
= section
->next
)
3669 if (!strstr (section
->name
, STUB_SUFFIX
))
3675 /* Ensure all stub sections have a size which is a multiple of
3676 4096. This is important in order to ensure that the insertion
3677 of stub sections does not in itself move existing code around
3678 in such a way that new errata sequences are created. */
3679 if (htab
->fix_erratum_843419
)
3681 section
->size
= BFD_ALIGN (section
->size
, 0x1000);
3686 /* Construct an erratum 843419 workaround stub name.
3690 _bfd_aarch64_erratum_843419_stub_name (asection
*input_section
,
3693 const bfd_size_type len
= 8 + 4 + 1 + 8 + 1 + 16 + 1;
3694 char *stub_name
= bfd_malloc (len
);
3696 if (stub_name
!= NULL
)
3697 snprintf (stub_name
, len
, "e843419@%04x_%08x_%" BFD_VMA_FMT
"x",
3698 input_section
->owner
->id
,
3704 /* Build a stub_entry structure describing an 843419 fixup.
3706 The stub_entry constructed is populated with the bit pattern INSN
3707 of the instruction located at OFFSET within input SECTION.
3709 Returns TRUE on success. */
3712 _bfd_aarch64_erratum_843419_fixup (uint32_t insn
,
3713 bfd_vma adrp_offset
,
3714 bfd_vma ldst_offset
,
3716 struct bfd_link_info
*info
)
3718 struct elf_aarch64_link_hash_table
*htab
= elf_aarch64_hash_table (info
);
3720 struct elf_aarch64_stub_hash_entry
*stub_entry
;
3722 stub_name
= _bfd_aarch64_erratum_843419_stub_name (section
, ldst_offset
);
3723 stub_entry
= aarch64_stub_hash_lookup (&htab
->stub_hash_table
, stub_name
,
3731 /* We always place an 843419 workaround veneer in the stub section
3732 attached to the input section in which an erratum sequence has
3733 been found. This ensures that later in the link process (in
3734 elfNN_aarch64_write_section) when we copy the veneered
3735 instruction from the input section into the stub section the
3736 copied instruction will have had any relocations applied to it.
3737 If we placed workaround veneers in any other stub section then we
3738 could not assume that all relocations have been processed on the
3739 corresponding input section at the point we output the stub
3743 stub_entry
= _bfd_aarch64_add_stub_entry_after (stub_name
, section
, htab
);
3744 if (stub_entry
== NULL
)
3750 stub_entry
->adrp_offset
= adrp_offset
;
3751 stub_entry
->target_value
= ldst_offset
;
3752 stub_entry
->target_section
= section
;
3753 stub_entry
->stub_type
= aarch64_stub_erratum_843419_veneer
;
3754 stub_entry
->veneered_insn
= insn
;
3755 stub_entry
->output_name
= stub_name
;
3761 /* Scan an input section looking for the signature of erratum 843419.
3763 Scans input SECTION in INPUT_BFD looking for erratum 843419
3764 signatures, for each signature found a stub_entry is created
3765 describing the location of the erratum for subsequent fixup.
3767 Return TRUE on successful scan, FALSE on failure to scan.
3771 _bfd_aarch64_erratum_843419_scan (bfd
*input_bfd
, asection
*section
,
3772 struct bfd_link_info
*info
)
3774 struct elf_aarch64_link_hash_table
*htab
= elf_aarch64_hash_table (info
);
3779 if (elf_section_type (section
) != SHT_PROGBITS
3780 || (elf_section_flags (section
) & SHF_EXECINSTR
) == 0
3781 || (section
->flags
& SEC_EXCLUDE
) != 0
3782 || (section
->sec_info_type
== SEC_INFO_TYPE_JUST_SYMS
)
3783 || (section
->output_section
== bfd_abs_section_ptr
))
3788 bfd_byte
*contents
= NULL
;
3789 struct _aarch64_elf_section_data
*sec_data
;
3792 if (elf_section_data (section
)->this_hdr
.contents
!= NULL
)
3793 contents
= elf_section_data (section
)->this_hdr
.contents
;
3794 else if (! bfd_malloc_and_get_section (input_bfd
, section
, &contents
))
3797 sec_data
= elf_aarch64_section_data (section
);
3799 qsort (sec_data
->map
, sec_data
->mapcount
,
3800 sizeof (elf_aarch64_section_map
), elf_aarch64_compare_mapping
);
3802 for (span
= 0; span
< sec_data
->mapcount
; span
++)
3804 unsigned int span_start
= sec_data
->map
[span
].vma
;
3805 unsigned int span_end
= ((span
== sec_data
->mapcount
- 1)
3806 ? sec_data
->map
[0].vma
+ section
->size
3807 : sec_data
->map
[span
+ 1].vma
);
3809 char span_type
= sec_data
->map
[span
].type
;
3811 if (span_type
== 'd')
3814 for (i
= span_start
; i
+ 8 < span_end
; i
+= 4)
3816 bfd_vma vma
= (section
->output_section
->vma
3817 + section
->output_offset
3821 if (_bfd_aarch64_erratum_843419_p
3822 (contents
, vma
, i
, span_end
, &veneer_i
))
3824 uint32_t insn
= bfd_getl32 (contents
+ veneer_i
);
3826 if (!_bfd_aarch64_erratum_843419_fixup (insn
, i
, veneer_i
,
3833 if (elf_section_data (section
)->this_hdr
.contents
== NULL
)
3842 /* Determine and set the size of the stub section for a final link.
3844 The basic idea here is to examine all the relocations looking for
3845 PC-relative calls to a target that is unreachable with a "bl"
3849 elfNN_aarch64_size_stubs (bfd
*output_bfd
,
3851 struct bfd_link_info
*info
,
3852 bfd_signed_vma group_size
,
3853 asection
* (*add_stub_section
) (const char *,
3855 void (*layout_sections_again
) (void))
3857 bfd_size_type stub_group_size
;
3858 bfd_boolean stubs_always_before_branch
;
3859 bfd_boolean stub_changed
= FALSE
;
3860 struct elf_aarch64_link_hash_table
*htab
= elf_aarch64_hash_table (info
);
3861 unsigned int num_erratum_835769_fixes
= 0;
3863 /* Propagate mach to stub bfd, because it may not have been
3864 finalized when we created stub_bfd. */
3865 bfd_set_arch_mach (stub_bfd
, bfd_get_arch (output_bfd
),
3866 bfd_get_mach (output_bfd
));
3868 /* Stash our params away. */
3869 htab
->stub_bfd
= stub_bfd
;
3870 htab
->add_stub_section
= add_stub_section
;
3871 htab
->layout_sections_again
= layout_sections_again
;
3872 stubs_always_before_branch
= group_size
< 0;
3874 stub_group_size
= -group_size
;
3876 stub_group_size
= group_size
;
3878 if (stub_group_size
== 1)
3880 /* Default values. */
3881 /* AArch64 branch range is +-128MB. The value used is 1MB less. */
3882 stub_group_size
= 127 * 1024 * 1024;
3885 group_sections (htab
, stub_group_size
, stubs_always_before_branch
);
3887 (*htab
->layout_sections_again
) ();
3889 if (htab
->fix_erratum_835769
)
3893 for (input_bfd
= info
->input_bfds
;
3894 input_bfd
!= NULL
; input_bfd
= input_bfd
->link
.next
)
3895 if (!_bfd_aarch64_erratum_835769_scan (input_bfd
, info
,
3896 &num_erratum_835769_fixes
))
3899 _bfd_aarch64_resize_stubs (htab
);
3900 (*htab
->layout_sections_again
) ();
3903 if (htab
->fix_erratum_843419
)
3907 for (input_bfd
= info
->input_bfds
;
3909 input_bfd
= input_bfd
->link
.next
)
3913 for (section
= input_bfd
->sections
;
3915 section
= section
->next
)
3916 if (!_bfd_aarch64_erratum_843419_scan (input_bfd
, section
, info
))
3920 _bfd_aarch64_resize_stubs (htab
);
3921 (*htab
->layout_sections_again
) ();
3928 for (input_bfd
= info
->input_bfds
;
3929 input_bfd
!= NULL
; input_bfd
= input_bfd
->link
.next
)
3931 Elf_Internal_Shdr
*symtab_hdr
;
3933 Elf_Internal_Sym
*local_syms
= NULL
;
3935 /* We'll need the symbol table in a second. */
3936 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
3937 if (symtab_hdr
->sh_info
== 0)
3940 /* Walk over each section attached to the input bfd. */
3941 for (section
= input_bfd
->sections
;
3942 section
!= NULL
; section
= section
->next
)
3944 Elf_Internal_Rela
*internal_relocs
, *irelaend
, *irela
;
3946 /* If there aren't any relocs, then there's nothing more
3948 if ((section
->flags
& SEC_RELOC
) == 0
3949 || section
->reloc_count
== 0
3950 || (section
->flags
& SEC_CODE
) == 0)
3953 /* If this section is a link-once section that will be
3954 discarded, then don't create any stubs. */
3955 if (section
->output_section
== NULL
3956 || section
->output_section
->owner
!= output_bfd
)
3959 /* Get the relocs. */
3961 = _bfd_elf_link_read_relocs (input_bfd
, section
, NULL
,
3962 NULL
, info
->keep_memory
);
3963 if (internal_relocs
== NULL
)
3964 goto error_ret_free_local
;
3966 /* Now examine each relocation. */
3967 irela
= internal_relocs
;
3968 irelaend
= irela
+ section
->reloc_count
;
3969 for (; irela
< irelaend
; irela
++)
3971 unsigned int r_type
, r_indx
;
3972 enum elf_aarch64_stub_type stub_type
;
3973 struct elf_aarch64_stub_hash_entry
*stub_entry
;
3976 bfd_vma destination
;
3977 struct elf_aarch64_link_hash_entry
*hash
;
3978 const char *sym_name
;
3980 const asection
*id_sec
;
3981 unsigned char st_type
;
3984 r_type
= ELFNN_R_TYPE (irela
->r_info
);
3985 r_indx
= ELFNN_R_SYM (irela
->r_info
);
3987 if (r_type
>= (unsigned int) R_AARCH64_end
)
3989 bfd_set_error (bfd_error_bad_value
);
3990 error_ret_free_internal
:
3991 if (elf_section_data (section
)->relocs
== NULL
)
3992 free (internal_relocs
);
3993 goto error_ret_free_local
;
3996 /* Only look for stubs on unconditional branch and
3997 branch and link instructions. */
3998 if (r_type
!= (unsigned int) AARCH64_R (CALL26
)
3999 && r_type
!= (unsigned int) AARCH64_R (JUMP26
))
4002 /* Now determine the call target, its name, value,
4009 if (r_indx
< symtab_hdr
->sh_info
)
4011 /* It's a local symbol. */
4012 Elf_Internal_Sym
*sym
;
4013 Elf_Internal_Shdr
*hdr
;
4015 if (local_syms
== NULL
)
4018 = (Elf_Internal_Sym
*) symtab_hdr
->contents
;
4019 if (local_syms
== NULL
)
4021 = bfd_elf_get_elf_syms (input_bfd
, symtab_hdr
,
4022 symtab_hdr
->sh_info
, 0,
4024 if (local_syms
== NULL
)
4025 goto error_ret_free_internal
;
4028 sym
= local_syms
+ r_indx
;
4029 hdr
= elf_elfsections (input_bfd
)[sym
->st_shndx
];
4030 sym_sec
= hdr
->bfd_section
;
4032 /* This is an undefined symbol. It can never
4036 if (ELF_ST_TYPE (sym
->st_info
) != STT_SECTION
)
4037 sym_value
= sym
->st_value
;
4038 destination
= (sym_value
+ irela
->r_addend
4039 + sym_sec
->output_offset
4040 + sym_sec
->output_section
->vma
);
4041 st_type
= ELF_ST_TYPE (sym
->st_info
);
4043 = bfd_elf_string_from_elf_section (input_bfd
,
4044 symtab_hdr
->sh_link
,
4051 e_indx
= r_indx
- symtab_hdr
->sh_info
;
4052 hash
= ((struct elf_aarch64_link_hash_entry
*)
4053 elf_sym_hashes (input_bfd
)[e_indx
]);
4055 while (hash
->root
.root
.type
== bfd_link_hash_indirect
4056 || hash
->root
.root
.type
== bfd_link_hash_warning
)
4057 hash
= ((struct elf_aarch64_link_hash_entry
*)
4058 hash
->root
.root
.u
.i
.link
);
4060 if (hash
->root
.root
.type
== bfd_link_hash_defined
4061 || hash
->root
.root
.type
== bfd_link_hash_defweak
)
4063 struct elf_aarch64_link_hash_table
*globals
=
4064 elf_aarch64_hash_table (info
);
4065 sym_sec
= hash
->root
.root
.u
.def
.section
;
4066 sym_value
= hash
->root
.root
.u
.def
.value
;
4067 /* For a destination in a shared library,
4068 use the PLT stub as target address to
4069 decide whether a branch stub is
4071 if (globals
->root
.splt
!= NULL
&& hash
!= NULL
4072 && hash
->root
.plt
.offset
!= (bfd_vma
) - 1)
4074 sym_sec
= globals
->root
.splt
;
4075 sym_value
= hash
->root
.plt
.offset
;
4076 if (sym_sec
->output_section
!= NULL
)
4077 destination
= (sym_value
4078 + sym_sec
->output_offset
4080 sym_sec
->output_section
->vma
);
4082 else if (sym_sec
->output_section
!= NULL
)
4083 destination
= (sym_value
+ irela
->r_addend
4084 + sym_sec
->output_offset
4085 + sym_sec
->output_section
->vma
);
4087 else if (hash
->root
.root
.type
== bfd_link_hash_undefined
4088 || (hash
->root
.root
.type
4089 == bfd_link_hash_undefweak
))
4091 /* For a shared library, use the PLT stub as
4092 target address to decide whether a long
4093 branch stub is needed.
4094 For absolute code, they cannot be handled. */
4095 struct elf_aarch64_link_hash_table
*globals
=
4096 elf_aarch64_hash_table (info
);
4098 if (globals
->root
.splt
!= NULL
&& hash
!= NULL
4099 && hash
->root
.plt
.offset
!= (bfd_vma
) - 1)
4101 sym_sec
= globals
->root
.splt
;
4102 sym_value
= hash
->root
.plt
.offset
;
4103 if (sym_sec
->output_section
!= NULL
)
4104 destination
= (sym_value
4105 + sym_sec
->output_offset
4107 sym_sec
->output_section
->vma
);
4114 bfd_set_error (bfd_error_bad_value
);
4115 goto error_ret_free_internal
;
4117 st_type
= ELF_ST_TYPE (hash
->root
.type
);
4118 sym_name
= hash
->root
.root
.root
.string
;
4121 /* Determine what (if any) linker stub is needed. */
4122 stub_type
= aarch64_type_of_stub
4123 (info
, section
, irela
, sym_sec
, st_type
, hash
, destination
);
4124 if (stub_type
== aarch64_stub_none
)
4127 /* Support for grouping stub sections. */
4128 id_sec
= htab
->stub_group
[section
->id
].link_sec
;
4130 /* Get the name of this stub. */
4131 stub_name
= elfNN_aarch64_stub_name (id_sec
, sym_sec
, hash
,
4134 goto error_ret_free_internal
;
4137 aarch64_stub_hash_lookup (&htab
->stub_hash_table
,
4138 stub_name
, FALSE
, FALSE
);
4139 if (stub_entry
!= NULL
)
4141 /* The proper stub has already been created. */
4146 stub_entry
= _bfd_aarch64_add_stub_entry_in_group
4147 (stub_name
, section
, htab
);
4148 if (stub_entry
== NULL
)
4151 goto error_ret_free_internal
;
4154 stub_entry
->target_value
= sym_value
;
4155 stub_entry
->target_section
= sym_sec
;
4156 stub_entry
->stub_type
= stub_type
;
4157 stub_entry
->h
= hash
;
4158 stub_entry
->st_type
= st_type
;
4160 if (sym_name
== NULL
)
4161 sym_name
= "unnamed";
4162 len
= sizeof (STUB_ENTRY_NAME
) + strlen (sym_name
);
4163 stub_entry
->output_name
= bfd_alloc (htab
->stub_bfd
, len
);
4164 if (stub_entry
->output_name
== NULL
)
4167 goto error_ret_free_internal
;
4170 snprintf (stub_entry
->output_name
, len
, STUB_ENTRY_NAME
,
4173 stub_changed
= TRUE
;
4176 /* We're done with the internal relocs, free them. */
4177 if (elf_section_data (section
)->relocs
== NULL
)
4178 free (internal_relocs
);
4185 _bfd_aarch64_resize_stubs (htab
);
4187 /* Ask the linker to do its stuff. */
4188 (*htab
->layout_sections_again
) ();
4189 stub_changed
= FALSE
;
4194 error_ret_free_local
:
4198 /* Build all the stubs associated with the current output file. The
4199 stubs are kept in a hash table attached to the main linker hash
4200 table. We also set up the .plt entries for statically linked PIC
4201 functions here. This function is called via aarch64_elf_finish in the
4205 elfNN_aarch64_build_stubs (struct bfd_link_info
*info
)
4208 struct bfd_hash_table
*table
;
4209 struct elf_aarch64_link_hash_table
*htab
;
4211 htab
= elf_aarch64_hash_table (info
);
4213 for (stub_sec
= htab
->stub_bfd
->sections
;
4214 stub_sec
!= NULL
; stub_sec
= stub_sec
->next
)
4218 /* Ignore non-stub sections. */
4219 if (!strstr (stub_sec
->name
, STUB_SUFFIX
))
4222 /* Allocate memory to hold the linker stubs. */
4223 size
= stub_sec
->size
;
4224 stub_sec
->contents
= bfd_zalloc (htab
->stub_bfd
, size
);
4225 if (stub_sec
->contents
== NULL
&& size
!= 0)
4229 bfd_putl32 (0x14000000 | (size
>> 2), stub_sec
->contents
);
4230 stub_sec
->size
+= 4;
4233 /* Build the stubs as directed by the stub hash table. */
4234 table
= &htab
->stub_hash_table
;
4235 bfd_hash_traverse (table
, aarch64_build_one_stub
, info
);
4241 /* Add an entry to the code/data map for section SEC. */
4244 elfNN_aarch64_section_map_add (asection
*sec
, char type
, bfd_vma vma
)
4246 struct _aarch64_elf_section_data
*sec_data
=
4247 elf_aarch64_section_data (sec
);
4248 unsigned int newidx
;
4250 if (sec_data
->map
== NULL
)
4252 sec_data
->map
= bfd_malloc (sizeof (elf_aarch64_section_map
));
4253 sec_data
->mapcount
= 0;
4254 sec_data
->mapsize
= 1;
4257 newidx
= sec_data
->mapcount
++;
4259 if (sec_data
->mapcount
> sec_data
->mapsize
)
4261 sec_data
->mapsize
*= 2;
4262 sec_data
->map
= bfd_realloc_or_free
4263 (sec_data
->map
, sec_data
->mapsize
* sizeof (elf_aarch64_section_map
));
4268 sec_data
->map
[newidx
].vma
= vma
;
4269 sec_data
->map
[newidx
].type
= type
;
4274 /* Initialise maps of insn/data for input BFDs. */
4276 bfd_elfNN_aarch64_init_maps (bfd
*abfd
)
4278 Elf_Internal_Sym
*isymbuf
;
4279 Elf_Internal_Shdr
*hdr
;
4280 unsigned int i
, localsyms
;
4282 /* Make sure that we are dealing with an AArch64 elf binary. */
4283 if (!is_aarch64_elf (abfd
))
4286 if ((abfd
->flags
& DYNAMIC
) != 0)
4289 hdr
= &elf_symtab_hdr (abfd
);
4290 localsyms
= hdr
->sh_info
;
4292 /* Obtain a buffer full of symbols for this BFD. The hdr->sh_info field
4293 should contain the number of local symbols, which should come before any
4294 global symbols. Mapping symbols are always local. */
4295 isymbuf
= bfd_elf_get_elf_syms (abfd
, hdr
, localsyms
, 0, NULL
, NULL
, NULL
);
4297 /* No internal symbols read? Skip this BFD. */
4298 if (isymbuf
== NULL
)
4301 for (i
= 0; i
< localsyms
; i
++)
4303 Elf_Internal_Sym
*isym
= &isymbuf
[i
];
4304 asection
*sec
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
4307 if (sec
!= NULL
&& ELF_ST_BIND (isym
->st_info
) == STB_LOCAL
)
4309 name
= bfd_elf_string_from_elf_section (abfd
,
4313 if (bfd_is_aarch64_special_symbol_name
4314 (name
, BFD_AARCH64_SPECIAL_SYM_TYPE_MAP
))
4315 elfNN_aarch64_section_map_add (sec
, name
[1], isym
->st_value
);
4320 /* Set option values needed during linking. */
4322 bfd_elfNN_aarch64_set_options (struct bfd
*output_bfd
,
4323 struct bfd_link_info
*link_info
,
4325 int no_wchar_warn
, int pic_veneer
,
4326 int fix_erratum_835769
,
4327 int fix_erratum_843419
)
4329 struct elf_aarch64_link_hash_table
*globals
;
4331 globals
= elf_aarch64_hash_table (link_info
);
4332 globals
->pic_veneer
= pic_veneer
;
4333 globals
->fix_erratum_835769
= fix_erratum_835769
;
4334 globals
->fix_erratum_843419
= fix_erratum_843419
;
4335 globals
->fix_erratum_843419_adr
= TRUE
;
4337 BFD_ASSERT (is_aarch64_elf (output_bfd
));
4338 elf_aarch64_tdata (output_bfd
)->no_enum_size_warning
= no_enum_warn
;
4339 elf_aarch64_tdata (output_bfd
)->no_wchar_size_warning
= no_wchar_warn
;
4343 aarch64_calculate_got_entry_vma (struct elf_link_hash_entry
*h
,
4344 struct elf_aarch64_link_hash_table
4345 *globals
, struct bfd_link_info
*info
,
4346 bfd_vma value
, bfd
*output_bfd
,
4347 bfd_boolean
*unresolved_reloc_p
)
4349 bfd_vma off
= (bfd_vma
) - 1;
4350 asection
*basegot
= globals
->root
.sgot
;
4351 bfd_boolean dyn
= globals
->root
.dynamic_sections_created
;
4355 BFD_ASSERT (basegot
!= NULL
);
4356 off
= h
->got
.offset
;
4357 BFD_ASSERT (off
!= (bfd_vma
) - 1);
4358 if (!WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, bfd_link_pic (info
), h
)
4359 || (bfd_link_pic (info
)
4360 && SYMBOL_REFERENCES_LOCAL (info
, h
))
4361 || (ELF_ST_VISIBILITY (h
->other
)
4362 && h
->root
.type
== bfd_link_hash_undefweak
))
4364 /* This is actually a static link, or it is a -Bsymbolic link
4365 and the symbol is defined locally. We must initialize this
4366 entry in the global offset table. Since the offset must
4367 always be a multiple of 8 (4 in the case of ILP32), we use
4368 the least significant bit to record whether we have
4369 initialized it already.
4370 When doing a dynamic link, we create a .rel(a).got relocation
4371 entry to initialize the value. This is done in the
4372 finish_dynamic_symbol routine. */
4377 bfd_put_NN (output_bfd
, value
, basegot
->contents
+ off
);
4382 *unresolved_reloc_p
= FALSE
;
4384 off
= off
+ basegot
->output_section
->vma
+ basegot
->output_offset
;
4390 /* Change R_TYPE to a more efficient access model where possible,
4391 return the new reloc type. */
4393 static bfd_reloc_code_real_type
4394 aarch64_tls_transition_without_check (bfd_reloc_code_real_type r_type
,
4395 struct elf_link_hash_entry
*h
)
4397 bfd_boolean is_local
= h
== NULL
;
4401 case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21
:
4402 case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21
:
4404 ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1
4405 : BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21
);
4407 case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21
:
4409 ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC
4412 case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19
:
4414 ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1
4415 : BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19
);
4417 case BFD_RELOC_AARCH64_TLSDESC_LDNN_LO12_NC
:
4418 case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC
:
4420 ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC
4421 : BFD_RELOC_AARCH64_TLSIE_LDNN_GOTTPREL_LO12_NC
);
4423 case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21
:
4424 return is_local
? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1
: r_type
;
4426 case BFD_RELOC_AARCH64_TLSIE_LDNN_GOTTPREL_LO12_NC
:
4427 return is_local
? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC
: r_type
;
4429 case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19
:
4432 case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21
:
4434 ? BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_HI12
4435 : BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19
);
4437 case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12_NC
:
4438 case BFD_RELOC_AARCH64_TLSDESC_CALL
:
4439 /* Instructions with these relocations will become NOPs. */
4440 return BFD_RELOC_AARCH64_NONE
;
4442 case BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC
:
4443 case BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21
:
4444 case BFD_RELOC_AARCH64_TLSLD_ADR_PREL21
:
4445 return is_local
? BFD_RELOC_AARCH64_NONE
: r_type
;
4455 aarch64_reloc_got_type (bfd_reloc_code_real_type r_type
)
4459 case BFD_RELOC_AARCH64_ADR_GOT_PAGE
:
4460 case BFD_RELOC_AARCH64_GOT_LD_PREL19
:
4461 case BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14
:
4462 case BFD_RELOC_AARCH64_LD32_GOT_LO12_NC
:
4463 case BFD_RELOC_AARCH64_LD64_GOTOFF_LO15
:
4464 case BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15
:
4465 case BFD_RELOC_AARCH64_LD64_GOT_LO12_NC
:
4466 case BFD_RELOC_AARCH64_MOVW_GOTOFF_G0_NC
:
4467 case BFD_RELOC_AARCH64_MOVW_GOTOFF_G1
:
4470 case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC
:
4471 case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21
:
4472 case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21
:
4473 case BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC
:
4474 case BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21
:
4475 case BFD_RELOC_AARCH64_TLSLD_ADR_PREL21
:
4478 case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12_NC
:
4479 case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21
:
4480 case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21
:
4481 case BFD_RELOC_AARCH64_TLSDESC_CALL
:
4482 case BFD_RELOC_AARCH64_TLSDESC_LD32_LO12_NC
:
4483 case BFD_RELOC_AARCH64_TLSDESC_LD64_LO12_NC
:
4484 case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19
:
4485 return GOT_TLSDESC_GD
;
4487 case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21
:
4488 case BFD_RELOC_AARCH64_TLSIE_LD32_GOTTPREL_LO12_NC
:
4489 case BFD_RELOC_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC
:
4490 case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19
:
4500 aarch64_can_relax_tls (bfd
*input_bfd
,
4501 struct bfd_link_info
*info
,
4502 bfd_reloc_code_real_type r_type
,
4503 struct elf_link_hash_entry
*h
,
4504 unsigned long r_symndx
)
4506 unsigned int symbol_got_type
;
4507 unsigned int reloc_got_type
;
4509 if (! IS_AARCH64_TLS_RELAX_RELOC (r_type
))
4512 symbol_got_type
= elfNN_aarch64_symbol_got_type (h
, input_bfd
, r_symndx
);
4513 reloc_got_type
= aarch64_reloc_got_type (r_type
);
4515 if (symbol_got_type
== GOT_TLS_IE
&& GOT_TLS_GD_ANY_P (reloc_got_type
))
4518 if (bfd_link_pic (info
))
4521 if (h
&& h
->root
.type
== bfd_link_hash_undefweak
)
4527 /* Given the relocation code R_TYPE, return the relaxed bfd reloc
4530 static bfd_reloc_code_real_type
4531 aarch64_tls_transition (bfd
*input_bfd
,
4532 struct bfd_link_info
*info
,
4533 unsigned int r_type
,
4534 struct elf_link_hash_entry
*h
,
4535 unsigned long r_symndx
)
4537 bfd_reloc_code_real_type bfd_r_type
4538 = elfNN_aarch64_bfd_reloc_from_type (r_type
);
4540 if (! aarch64_can_relax_tls (input_bfd
, info
, bfd_r_type
, h
, r_symndx
))
4543 return aarch64_tls_transition_without_check (bfd_r_type
, h
);
4546 /* Return the base VMA address which should be subtracted from real addresses
4547 when resolving R_AARCH64_TLS_DTPREL relocation. */
4550 dtpoff_base (struct bfd_link_info
*info
)
4552 /* If tls_sec is NULL, we should have signalled an error already. */
4553 BFD_ASSERT (elf_hash_table (info
)->tls_sec
!= NULL
);
4554 return elf_hash_table (info
)->tls_sec
->vma
;
4557 /* Return the base VMA address which should be subtracted from real addresses
4558 when resolving R_AARCH64_TLS_GOTTPREL64 relocations. */
4561 tpoff_base (struct bfd_link_info
*info
)
4563 struct elf_link_hash_table
*htab
= elf_hash_table (info
);
4565 /* If tls_sec is NULL, we should have signalled an error already. */
4566 BFD_ASSERT (htab
->tls_sec
!= NULL
);
4568 bfd_vma base
= align_power ((bfd_vma
) TCB_SIZE
,
4569 htab
->tls_sec
->alignment_power
);
4570 return htab
->tls_sec
->vma
- base
;
4574 symbol_got_offset_ref (bfd
*input_bfd
, struct elf_link_hash_entry
*h
,
4575 unsigned long r_symndx
)
4577 /* Calculate the address of the GOT entry for symbol
4578 referred to in h. */
4580 return &h
->got
.offset
;
4584 struct elf_aarch64_local_symbol
*l
;
4586 l
= elf_aarch64_locals (input_bfd
);
4587 return &l
[r_symndx
].got_offset
;
4592 symbol_got_offset_mark (bfd
*input_bfd
, struct elf_link_hash_entry
*h
,
4593 unsigned long r_symndx
)
4596 p
= symbol_got_offset_ref (input_bfd
, h
, r_symndx
);
4601 symbol_got_offset_mark_p (bfd
*input_bfd
, struct elf_link_hash_entry
*h
,
4602 unsigned long r_symndx
)
4605 value
= * symbol_got_offset_ref (input_bfd
, h
, r_symndx
);
4610 symbol_got_offset (bfd
*input_bfd
, struct elf_link_hash_entry
*h
,
4611 unsigned long r_symndx
)
4614 value
= * symbol_got_offset_ref (input_bfd
, h
, r_symndx
);
4620 symbol_tlsdesc_got_offset_ref (bfd
*input_bfd
, struct elf_link_hash_entry
*h
,
4621 unsigned long r_symndx
)
4623 /* Calculate the address of the GOT entry for symbol
4624 referred to in h. */
4627 struct elf_aarch64_link_hash_entry
*eh
;
4628 eh
= (struct elf_aarch64_link_hash_entry
*) h
;
4629 return &eh
->tlsdesc_got_jump_table_offset
;
4634 struct elf_aarch64_local_symbol
*l
;
4636 l
= elf_aarch64_locals (input_bfd
);
4637 return &l
[r_symndx
].tlsdesc_got_jump_table_offset
;
4642 symbol_tlsdesc_got_offset_mark (bfd
*input_bfd
, struct elf_link_hash_entry
*h
,
4643 unsigned long r_symndx
)
4646 p
= symbol_tlsdesc_got_offset_ref (input_bfd
, h
, r_symndx
);
4651 symbol_tlsdesc_got_offset_mark_p (bfd
*input_bfd
,
4652 struct elf_link_hash_entry
*h
,
4653 unsigned long r_symndx
)
4656 value
= * symbol_tlsdesc_got_offset_ref (input_bfd
, h
, r_symndx
);
4661 symbol_tlsdesc_got_offset (bfd
*input_bfd
, struct elf_link_hash_entry
*h
,
4662 unsigned long r_symndx
)
4665 value
= * symbol_tlsdesc_got_offset_ref (input_bfd
, h
, r_symndx
);
4670 /* Data for make_branch_to_erratum_835769_stub(). */
4672 struct erratum_835769_branch_to_stub_data
4674 struct bfd_link_info
*info
;
4675 asection
*output_section
;
4679 /* Helper to insert branches to erratum 835769 stubs in the right
4680 places for a particular section. */
4683 make_branch_to_erratum_835769_stub (struct bfd_hash_entry
*gen_entry
,
4686 struct elf_aarch64_stub_hash_entry
*stub_entry
;
4687 struct erratum_835769_branch_to_stub_data
*data
;
4689 unsigned long branch_insn
= 0;
4690 bfd_vma veneered_insn_loc
, veneer_entry_loc
;
4691 bfd_signed_vma branch_offset
;
4692 unsigned int target
;
4695 stub_entry
= (struct elf_aarch64_stub_hash_entry
*) gen_entry
;
4696 data
= (struct erratum_835769_branch_to_stub_data
*) in_arg
;
4698 if (stub_entry
->target_section
!= data
->output_section
4699 || stub_entry
->stub_type
!= aarch64_stub_erratum_835769_veneer
)
4702 contents
= data
->contents
;
4703 veneered_insn_loc
= stub_entry
->target_section
->output_section
->vma
4704 + stub_entry
->target_section
->output_offset
4705 + stub_entry
->target_value
;
4706 veneer_entry_loc
= stub_entry
->stub_sec
->output_section
->vma
4707 + stub_entry
->stub_sec
->output_offset
4708 + stub_entry
->stub_offset
;
4709 branch_offset
= veneer_entry_loc
- veneered_insn_loc
;
4711 abfd
= stub_entry
->target_section
->owner
;
4712 if (!aarch64_valid_branch_p (veneer_entry_loc
, veneered_insn_loc
))
4713 (*_bfd_error_handler
)
4714 (_("%B: error: Erratum 835769 stub out "
4715 "of range (input file too large)"), abfd
);
4717 target
= stub_entry
->target_value
;
4718 branch_insn
= 0x14000000;
4719 branch_offset
>>= 2;
4720 branch_offset
&= 0x3ffffff;
4721 branch_insn
|= branch_offset
;
4722 bfd_putl32 (branch_insn
, &contents
[target
]);
4729 _bfd_aarch64_erratum_843419_branch_to_stub (struct bfd_hash_entry
*gen_entry
,
4732 struct elf_aarch64_stub_hash_entry
*stub_entry
4733 = (struct elf_aarch64_stub_hash_entry
*) gen_entry
;
4734 struct erratum_835769_branch_to_stub_data
*data
4735 = (struct erratum_835769_branch_to_stub_data
*) in_arg
;
4736 struct bfd_link_info
*info
;
4737 struct elf_aarch64_link_hash_table
*htab
;
4745 contents
= data
->contents
;
4746 section
= data
->output_section
;
4748 htab
= elf_aarch64_hash_table (info
);
4750 if (stub_entry
->target_section
!= section
4751 || stub_entry
->stub_type
!= aarch64_stub_erratum_843419_veneer
)
4754 insn
= bfd_getl32 (contents
+ stub_entry
->target_value
);
4756 stub_entry
->stub_sec
->contents
+ stub_entry
->stub_offset
);
4758 place
= (section
->output_section
->vma
+ section
->output_offset
4759 + stub_entry
->adrp_offset
);
4760 insn
= bfd_getl32 (contents
+ stub_entry
->adrp_offset
);
4762 if ((insn
& AARCH64_ADRP_OP_MASK
) != AARCH64_ADRP_OP
)
4765 bfd_signed_vma imm
=
4766 (_bfd_aarch64_sign_extend
4767 ((bfd_vma
) _bfd_aarch64_decode_adrp_imm (insn
) << 12, 33)
4770 if (htab
->fix_erratum_843419_adr
4771 && (imm
>= AARCH64_MIN_ADRP_IMM
&& imm
<= AARCH64_MAX_ADRP_IMM
))
4773 insn
= (_bfd_aarch64_reencode_adr_imm (AARCH64_ADR_OP
, imm
)
4774 | AARCH64_RT (insn
));
4775 bfd_putl32 (insn
, contents
+ stub_entry
->adrp_offset
);
4779 bfd_vma veneered_insn_loc
;
4780 bfd_vma veneer_entry_loc
;
4781 bfd_signed_vma branch_offset
;
4782 uint32_t branch_insn
;
4784 veneered_insn_loc
= stub_entry
->target_section
->output_section
->vma
4785 + stub_entry
->target_section
->output_offset
4786 + stub_entry
->target_value
;
4787 veneer_entry_loc
= stub_entry
->stub_sec
->output_section
->vma
4788 + stub_entry
->stub_sec
->output_offset
4789 + stub_entry
->stub_offset
;
4790 branch_offset
= veneer_entry_loc
- veneered_insn_loc
;
4792 abfd
= stub_entry
->target_section
->owner
;
4793 if (!aarch64_valid_branch_p (veneer_entry_loc
, veneered_insn_loc
))
4794 (*_bfd_error_handler
)
4795 (_("%B: error: Erratum 843419 stub out "
4796 "of range (input file too large)"), abfd
);
4798 branch_insn
= 0x14000000;
4799 branch_offset
>>= 2;
4800 branch_offset
&= 0x3ffffff;
4801 branch_insn
|= branch_offset
;
4802 bfd_putl32 (branch_insn
, contents
+ stub_entry
->target_value
);
4809 elfNN_aarch64_write_section (bfd
*output_bfd ATTRIBUTE_UNUSED
,
4810 struct bfd_link_info
*link_info
,
4815 struct elf_aarch64_link_hash_table
*globals
=
4816 elf_aarch64_hash_table (link_info
);
4818 if (globals
== NULL
)
4821 /* Fix code to point to erratum 835769 stubs. */
4822 if (globals
->fix_erratum_835769
)
4824 struct erratum_835769_branch_to_stub_data data
;
4826 data
.info
= link_info
;
4827 data
.output_section
= sec
;
4828 data
.contents
= contents
;
4829 bfd_hash_traverse (&globals
->stub_hash_table
,
4830 make_branch_to_erratum_835769_stub
, &data
);
4833 if (globals
->fix_erratum_843419
)
4835 struct erratum_835769_branch_to_stub_data data
;
4837 data
.info
= link_info
;
4838 data
.output_section
= sec
;
4839 data
.contents
= contents
;
4840 bfd_hash_traverse (&globals
->stub_hash_table
,
4841 _bfd_aarch64_erratum_843419_branch_to_stub
, &data
);
4847 /* Perform a relocation as part of a final link. */
4848 static bfd_reloc_status_type
4849 elfNN_aarch64_final_link_relocate (reloc_howto_type
*howto
,
4852 asection
*input_section
,
4854 Elf_Internal_Rela
*rel
,
4856 struct bfd_link_info
*info
,
4858 struct elf_link_hash_entry
*h
,
4859 bfd_boolean
*unresolved_reloc_p
,
4860 bfd_boolean save_addend
,
4861 bfd_vma
*saved_addend
,
4862 Elf_Internal_Sym
*sym
)
4864 Elf_Internal_Shdr
*symtab_hdr
;
4865 unsigned int r_type
= howto
->type
;
4866 bfd_reloc_code_real_type bfd_r_type
4867 = elfNN_aarch64_bfd_reloc_from_howto (howto
);
4868 bfd_reloc_code_real_type new_bfd_r_type
;
4869 unsigned long r_symndx
;
4870 bfd_byte
*hit_data
= contents
+ rel
->r_offset
;
4872 bfd_signed_vma signed_addend
;
4873 struct elf_aarch64_link_hash_table
*globals
;
4874 bfd_boolean weak_undef_p
;
4877 globals
= elf_aarch64_hash_table (info
);
4879 symtab_hdr
= &elf_symtab_hdr (input_bfd
);
4881 BFD_ASSERT (is_aarch64_elf (input_bfd
));
4883 r_symndx
= ELFNN_R_SYM (rel
->r_info
);
4885 /* It is possible to have linker relaxations on some TLS access
4886 models. Update our information here. */
4887 new_bfd_r_type
= aarch64_tls_transition (input_bfd
, info
, r_type
, h
, r_symndx
);
4888 if (new_bfd_r_type
!= bfd_r_type
)
4890 bfd_r_type
= new_bfd_r_type
;
4891 howto
= elfNN_aarch64_howto_from_bfd_reloc (bfd_r_type
);
4892 BFD_ASSERT (howto
!= NULL
);
4893 r_type
= howto
->type
;
4896 place
= input_section
->output_section
->vma
4897 + input_section
->output_offset
+ rel
->r_offset
;
4899 /* Get addend, accumulating the addend for consecutive relocs
4900 which refer to the same offset. */
4901 signed_addend
= saved_addend
? *saved_addend
: 0;
4902 signed_addend
+= rel
->r_addend
;
4904 weak_undef_p
= (h
? h
->root
.type
== bfd_link_hash_undefweak
4905 : bfd_is_und_section (sym_sec
));
4907 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle
4908 it here if it is defined in a non-shared object. */
4910 && h
->type
== STT_GNU_IFUNC
4917 if ((input_section
->flags
& SEC_ALLOC
) == 0
4918 || h
->plt
.offset
== (bfd_vma
) -1)
4921 /* STT_GNU_IFUNC symbol must go through PLT. */
4922 plt
= globals
->root
.splt
? globals
->root
.splt
: globals
->root
.iplt
;
4923 value
= (plt
->output_section
->vma
+ plt
->output_offset
+ h
->plt
.offset
);
4928 if (h
->root
.root
.string
)
4929 name
= h
->root
.root
.string
;
4931 name
= bfd_elf_sym_name (input_bfd
, symtab_hdr
, sym
,
4933 (*_bfd_error_handler
)
4934 (_("%B: relocation %s against STT_GNU_IFUNC "
4935 "symbol `%s' isn't handled by %s"), input_bfd
,
4936 howto
->name
, name
, __FUNCTION__
);
4937 bfd_set_error (bfd_error_bad_value
);
4940 case BFD_RELOC_AARCH64_NN
:
4941 if (rel
->r_addend
!= 0)
4943 if (h
->root
.root
.string
)
4944 name
= h
->root
.root
.string
;
4946 name
= bfd_elf_sym_name (input_bfd
, symtab_hdr
,
4948 (*_bfd_error_handler
)
4949 (_("%B: relocation %s against STT_GNU_IFUNC "
4950 "symbol `%s' has non-zero addend: %d"),
4951 input_bfd
, howto
->name
, name
, rel
->r_addend
);
4952 bfd_set_error (bfd_error_bad_value
);
4956 /* Generate dynamic relocation only when there is a
4957 non-GOT reference in a shared object. */
4958 if (bfd_link_pic (info
) && h
->non_got_ref
)
4960 Elf_Internal_Rela outrel
;
4963 /* Need a dynamic relocation to get the real function
4965 outrel
.r_offset
= _bfd_elf_section_offset (output_bfd
,
4969 if (outrel
.r_offset
== (bfd_vma
) -1
4970 || outrel
.r_offset
== (bfd_vma
) -2)
4973 outrel
.r_offset
+= (input_section
->output_section
->vma
4974 + input_section
->output_offset
);
4976 if (h
->dynindx
== -1
4978 || bfd_link_executable (info
))
4980 /* This symbol is resolved locally. */
4981 outrel
.r_info
= ELFNN_R_INFO (0, AARCH64_R (IRELATIVE
));
4982 outrel
.r_addend
= (h
->root
.u
.def
.value
4983 + h
->root
.u
.def
.section
->output_section
->vma
4984 + h
->root
.u
.def
.section
->output_offset
);
4988 outrel
.r_info
= ELFNN_R_INFO (h
->dynindx
, r_type
);
4989 outrel
.r_addend
= 0;
4992 sreloc
= globals
->root
.irelifunc
;
4993 elf_append_rela (output_bfd
, sreloc
, &outrel
);
4995 /* If this reloc is against an external symbol, we
4996 do not want to fiddle with the addend. Otherwise,
4997 we need to include the symbol value so that it
4998 becomes an addend for the dynamic reloc. For an
4999 internal symbol, we have updated addend. */
5000 return bfd_reloc_ok
;
5003 case BFD_RELOC_AARCH64_CALL26
:
5004 case BFD_RELOC_AARCH64_JUMP26
:
5005 value
= _bfd_aarch64_elf_resolve_relocation (bfd_r_type
, place
, value
,
5008 return _bfd_aarch64_elf_put_addend (input_bfd
, hit_data
, bfd_r_type
,
5010 case BFD_RELOC_AARCH64_ADR_GOT_PAGE
:
5011 case BFD_RELOC_AARCH64_GOT_LD_PREL19
:
5012 case BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14
:
5013 case BFD_RELOC_AARCH64_LD32_GOT_LO12_NC
:
5014 case BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15
:
5015 case BFD_RELOC_AARCH64_MOVW_GOTOFF_G0_NC
:
5016 case BFD_RELOC_AARCH64_MOVW_GOTOFF_G1
:
5017 case BFD_RELOC_AARCH64_LD64_GOTOFF_LO15
:
5018 case BFD_RELOC_AARCH64_LD64_GOT_LO12_NC
:
5019 base_got
= globals
->root
.sgot
;
5020 off
= h
->got
.offset
;
5022 if (base_got
== NULL
)
5025 if (off
== (bfd_vma
) -1)
5029 /* We can't use h->got.offset here to save state, or
5030 even just remember the offset, as finish_dynamic_symbol
5031 would use that as offset into .got. */
5033 if (globals
->root
.splt
!= NULL
)
5035 plt_index
= ((h
->plt
.offset
- globals
->plt_header_size
) /
5036 globals
->plt_entry_size
);
5037 off
= (plt_index
+ 3) * GOT_ENTRY_SIZE
;
5038 base_got
= globals
->root
.sgotplt
;
5042 plt_index
= h
->plt
.offset
/ globals
->plt_entry_size
;
5043 off
= plt_index
* GOT_ENTRY_SIZE
;
5044 base_got
= globals
->root
.igotplt
;
5047 if (h
->dynindx
== -1
5051 /* This references the local definition. We must
5052 initialize this entry in the global offset table.
5053 Since the offset must always be a multiple of 8,
5054 we use the least significant bit to record
5055 whether we have initialized it already.
5057 When doing a dynamic link, we create a .rela.got
5058 relocation entry to initialize the value. This
5059 is done in the finish_dynamic_symbol routine. */
5064 bfd_put_NN (output_bfd
, value
,
5065 base_got
->contents
+ off
);
5066 /* Note that this is harmless as -1 | 1 still is -1. */
5070 value
= (base_got
->output_section
->vma
5071 + base_got
->output_offset
+ off
);
5074 value
= aarch64_calculate_got_entry_vma (h
, globals
, info
,
5076 unresolved_reloc_p
);
5080 case BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14
:
5081 case BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15
:
5082 addend
= (globals
->root
.sgot
->output_section
->vma
5083 + globals
->root
.sgot
->output_offset
);
5085 case BFD_RELOC_AARCH64_MOVW_GOTOFF_G0_NC
:
5086 case BFD_RELOC_AARCH64_MOVW_GOTOFF_G1
:
5087 case BFD_RELOC_AARCH64_LD64_GOTOFF_LO15
:
5088 value
= (value
- globals
->root
.sgot
->output_section
->vma
5089 - globals
->root
.sgot
->output_offset
);
5094 value
= _bfd_aarch64_elf_resolve_relocation (bfd_r_type
, place
, value
,
5095 addend
, weak_undef_p
);
5096 return _bfd_aarch64_elf_put_addend (input_bfd
, hit_data
, bfd_r_type
, howto
, value
);
5097 case BFD_RELOC_AARCH64_ADD_LO12
:
5098 case BFD_RELOC_AARCH64_ADR_HI21_PCREL
:
5105 case BFD_RELOC_AARCH64_NONE
:
5106 case BFD_RELOC_AARCH64_TLSDESC_CALL
:
5107 *unresolved_reloc_p
= FALSE
;
5108 return bfd_reloc_ok
;
5110 case BFD_RELOC_AARCH64_NN
:
5112 /* When generating a shared object or relocatable executable, these
5113 relocations are copied into the output file to be resolved at
5115 if (((bfd_link_pic (info
) == TRUE
)
5116 || globals
->root
.is_relocatable_executable
)
5117 && (input_section
->flags
& SEC_ALLOC
)
5119 || ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
5120 || h
->root
.type
!= bfd_link_hash_undefweak
))
5122 Elf_Internal_Rela outrel
;
5124 bfd_boolean skip
, relocate
;
5127 *unresolved_reloc_p
= FALSE
;
5132 outrel
.r_addend
= signed_addend
;
5134 _bfd_elf_section_offset (output_bfd
, info
, input_section
,
5136 if (outrel
.r_offset
== (bfd_vma
) - 1)
5138 else if (outrel
.r_offset
== (bfd_vma
) - 2)
5144 outrel
.r_offset
+= (input_section
->output_section
->vma
5145 + input_section
->output_offset
);
5148 memset (&outrel
, 0, sizeof outrel
);
5151 && (!bfd_link_pic (info
)
5152 || !SYMBOLIC_BIND (info
, h
)
5153 || !h
->def_regular
))
5154 outrel
.r_info
= ELFNN_R_INFO (h
->dynindx
, r_type
);
5159 /* On SVR4-ish systems, the dynamic loader cannot
5160 relocate the text and data segments independently,
5161 so the symbol does not matter. */
5163 outrel
.r_info
= ELFNN_R_INFO (symbol
, AARCH64_R (RELATIVE
));
5164 outrel
.r_addend
+= value
;
5167 sreloc
= elf_section_data (input_section
)->sreloc
;
5168 if (sreloc
== NULL
|| sreloc
->contents
== NULL
)
5169 return bfd_reloc_notsupported
;
5171 loc
= sreloc
->contents
+ sreloc
->reloc_count
++ * RELOC_SIZE (globals
);
5172 bfd_elfNN_swap_reloca_out (output_bfd
, &outrel
, loc
);
5174 if (sreloc
->reloc_count
* RELOC_SIZE (globals
) > sreloc
->size
)
5176 /* Sanity to check that we have previously allocated
5177 sufficient space in the relocation section for the
5178 number of relocations we actually want to emit. */
5182 /* If this reloc is against an external symbol, we do not want to
5183 fiddle with the addend. Otherwise, we need to include the symbol
5184 value so that it becomes an addend for the dynamic reloc. */
5186 return bfd_reloc_ok
;
5188 return _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
5189 contents
, rel
->r_offset
, value
,
5193 value
+= signed_addend
;
5196 case BFD_RELOC_AARCH64_CALL26
:
5197 case BFD_RELOC_AARCH64_JUMP26
:
5199 asection
*splt
= globals
->root
.splt
;
5200 bfd_boolean via_plt_p
=
5201 splt
!= NULL
&& h
!= NULL
&& h
->plt
.offset
!= (bfd_vma
) - 1;
5203 /* A call to an undefined weak symbol is converted to a jump to
5204 the next instruction unless a PLT entry will be created.
5205 The jump to the next instruction is optimized as a NOP.
5206 Do the same for local undefined symbols. */
5207 if (weak_undef_p
&& ! via_plt_p
)
5209 bfd_putl32 (INSN_NOP
, hit_data
);
5210 return bfd_reloc_ok
;
5213 /* If the call goes through a PLT entry, make sure to
5214 check distance to the right destination address. */
5216 value
= (splt
->output_section
->vma
5217 + splt
->output_offset
+ h
->plt
.offset
);
5219 /* Check if a stub has to be inserted because the destination
5221 struct elf_aarch64_stub_hash_entry
*stub_entry
= NULL
;
5222 if (! aarch64_valid_branch_p (value
, place
))
5223 /* The target is out of reach, so redirect the branch to
5224 the local stub for this function. */
5225 stub_entry
= elfNN_aarch64_get_stub_entry (input_section
, sym_sec
, h
,
5227 if (stub_entry
!= NULL
)
5228 value
= (stub_entry
->stub_offset
5229 + stub_entry
->stub_sec
->output_offset
5230 + stub_entry
->stub_sec
->output_section
->vma
);
5232 value
= _bfd_aarch64_elf_resolve_relocation (bfd_r_type
, place
, value
,
5233 signed_addend
, weak_undef_p
);
5234 *unresolved_reloc_p
= FALSE
;
5237 case BFD_RELOC_AARCH64_16_PCREL
:
5238 case BFD_RELOC_AARCH64_32_PCREL
:
5239 case BFD_RELOC_AARCH64_64_PCREL
:
5240 case BFD_RELOC_AARCH64_ADR_HI21_NC_PCREL
:
5241 case BFD_RELOC_AARCH64_ADR_HI21_PCREL
:
5242 case BFD_RELOC_AARCH64_ADR_LO21_PCREL
:
5243 case BFD_RELOC_AARCH64_LD_LO19_PCREL
:
5244 if (bfd_link_pic (info
)
5245 && (input_section
->flags
& SEC_ALLOC
) != 0
5246 && (input_section
->flags
& SEC_READONLY
) != 0
5250 int howto_index
= bfd_r_type
- BFD_RELOC_AARCH64_RELOC_START
;
5252 (*_bfd_error_handler
)
5253 (_("%B: relocation %s against external symbol `%s' can not be used"
5254 " when making a shared object; recompile with -fPIC"),
5255 input_bfd
, elfNN_aarch64_howto_table
[howto_index
].name
,
5256 h
->root
.root
.string
);
5257 bfd_set_error (bfd_error_bad_value
);
5261 case BFD_RELOC_AARCH64_16
:
5263 case BFD_RELOC_AARCH64_32
:
5265 case BFD_RELOC_AARCH64_ADD_LO12
:
5266 case BFD_RELOC_AARCH64_BRANCH19
:
5267 case BFD_RELOC_AARCH64_LDST128_LO12
:
5268 case BFD_RELOC_AARCH64_LDST16_LO12
:
5269 case BFD_RELOC_AARCH64_LDST32_LO12
:
5270 case BFD_RELOC_AARCH64_LDST64_LO12
:
5271 case BFD_RELOC_AARCH64_LDST8_LO12
:
5272 case BFD_RELOC_AARCH64_MOVW_G0
:
5273 case BFD_RELOC_AARCH64_MOVW_G0_NC
:
5274 case BFD_RELOC_AARCH64_MOVW_G0_S
:
5275 case BFD_RELOC_AARCH64_MOVW_G1
:
5276 case BFD_RELOC_AARCH64_MOVW_G1_NC
:
5277 case BFD_RELOC_AARCH64_MOVW_G1_S
:
5278 case BFD_RELOC_AARCH64_MOVW_G2
:
5279 case BFD_RELOC_AARCH64_MOVW_G2_NC
:
5280 case BFD_RELOC_AARCH64_MOVW_G2_S
:
5281 case BFD_RELOC_AARCH64_MOVW_G3
:
5282 case BFD_RELOC_AARCH64_TSTBR14
:
5283 value
= _bfd_aarch64_elf_resolve_relocation (bfd_r_type
, place
, value
,
5284 signed_addend
, weak_undef_p
);
5287 case BFD_RELOC_AARCH64_ADR_GOT_PAGE
:
5288 case BFD_RELOC_AARCH64_GOT_LD_PREL19
:
5289 case BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14
:
5290 case BFD_RELOC_AARCH64_LD32_GOT_LO12_NC
:
5291 case BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15
:
5292 case BFD_RELOC_AARCH64_LD64_GOT_LO12_NC
:
5293 if (globals
->root
.sgot
== NULL
)
5294 BFD_ASSERT (h
!= NULL
);
5299 value
= aarch64_calculate_got_entry_vma (h
, globals
, info
, value
,
5301 unresolved_reloc_p
);
5302 if (bfd_r_type
== BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15
5303 || bfd_r_type
== BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14
)
5304 addend
= (globals
->root
.sgot
->output_section
->vma
5305 + globals
->root
.sgot
->output_offset
);
5306 value
= _bfd_aarch64_elf_resolve_relocation (bfd_r_type
, place
, value
,
5307 addend
, weak_undef_p
);
5312 struct elf_aarch64_local_symbol
*locals
5313 = elf_aarch64_locals (input_bfd
);
5317 int howto_index
= bfd_r_type
- BFD_RELOC_AARCH64_RELOC_START
;
5318 (*_bfd_error_handler
)
5319 (_("%B: Local symbol descriptor table be NULL when applying "
5320 "relocation %s against local symbol"),
5321 input_bfd
, elfNN_aarch64_howto_table
[howto_index
].name
);
5325 off
= symbol_got_offset (input_bfd
, h
, r_symndx
);
5326 base_got
= globals
->root
.sgot
;
5327 bfd_vma got_entry_addr
= (base_got
->output_section
->vma
5328 + base_got
->output_offset
+ off
);
5330 if (!symbol_got_offset_mark_p (input_bfd
, h
, r_symndx
))
5332 bfd_put_64 (output_bfd
, value
, base_got
->contents
+ off
);
5334 if (bfd_link_pic (info
))
5337 Elf_Internal_Rela outrel
;
5339 /* For local symbol, we have done absolute relocation in static
5340 linking stageh. While for share library, we need to update
5341 the content of GOT entry according to the share objects
5342 loading base address. So we need to generate a
5343 R_AARCH64_RELATIVE reloc for dynamic linker. */
5344 s
= globals
->root
.srelgot
;
5348 outrel
.r_offset
= got_entry_addr
;
5349 outrel
.r_info
= ELFNN_R_INFO (0, AARCH64_R (RELATIVE
));
5350 outrel
.r_addend
= value
;
5351 elf_append_rela (output_bfd
, s
, &outrel
);
5354 symbol_got_offset_mark (input_bfd
, h
, r_symndx
);
5357 /* Update the relocation value to GOT entry addr as we have transformed
5358 the direct data access into indirect data access through GOT. */
5359 value
= got_entry_addr
;
5361 if (bfd_r_type
== BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15
5362 || bfd_r_type
== BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14
)
5363 addend
= base_got
->output_section
->vma
+ base_got
->output_offset
;
5365 value
= _bfd_aarch64_elf_resolve_relocation (bfd_r_type
, place
, value
,
5366 addend
, weak_undef_p
);
5371 case BFD_RELOC_AARCH64_LD64_GOTOFF_LO15
:
5372 case BFD_RELOC_AARCH64_MOVW_GOTOFF_G0_NC
:
5373 case BFD_RELOC_AARCH64_MOVW_GOTOFF_G1
:
5375 value
= aarch64_calculate_got_entry_vma (h
, globals
, info
, value
,
5377 unresolved_reloc_p
);
5380 struct elf_aarch64_local_symbol
*locals
5381 = elf_aarch64_locals (input_bfd
);
5385 int howto_index
= bfd_r_type
- BFD_RELOC_AARCH64_RELOC_START
;
5386 (*_bfd_error_handler
)
5387 (_("%B: Local symbol descriptor table be NULL when applying "
5388 "relocation %s against local symbol"),
5389 input_bfd
, elfNN_aarch64_howto_table
[howto_index
].name
);
5393 off
= symbol_got_offset (input_bfd
, h
, r_symndx
);
5394 base_got
= globals
->root
.sgot
;
5395 if (base_got
== NULL
)
5398 bfd_vma got_entry_addr
= (base_got
->output_section
->vma
5399 + base_got
->output_offset
+ off
);
5401 if (!symbol_got_offset_mark_p (input_bfd
, h
, r_symndx
))
5403 bfd_put_64 (output_bfd
, value
, base_got
->contents
+ off
);
5405 if (bfd_link_pic (info
))
5408 Elf_Internal_Rela outrel
;
5410 /* For local symbol, we have done absolute relocation in static
5411 linking stage. While for share library, we need to update
5412 the content of GOT entry according to the share objects
5413 loading base address. So we need to generate a
5414 R_AARCH64_RELATIVE reloc for dynamic linker. */
5415 s
= globals
->root
.srelgot
;
5419 outrel
.r_offset
= got_entry_addr
;
5420 outrel
.r_info
= ELFNN_R_INFO (0, AARCH64_R (RELATIVE
));
5421 outrel
.r_addend
= value
;
5422 elf_append_rela (output_bfd
, s
, &outrel
);
5425 symbol_got_offset_mark (input_bfd
, h
, r_symndx
);
5429 /* Update the relocation value to GOT entry addr as we have transformed
5430 the direct data access into indirect data access through GOT. */
5431 value
= symbol_got_offset (input_bfd
, h
, r_symndx
);
5432 value
= _bfd_aarch64_elf_resolve_relocation (bfd_r_type
, place
, value
,
5434 *unresolved_reloc_p
= FALSE
;
5437 case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC
:
5438 case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21
:
5439 case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21
:
5440 case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21
:
5441 case BFD_RELOC_AARCH64_TLSIE_LD32_GOTTPREL_LO12_NC
:
5442 case BFD_RELOC_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC
:
5443 case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19
:
5444 case BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC
:
5445 case BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21
:
5446 case BFD_RELOC_AARCH64_TLSLD_ADR_PREL21
:
5447 if (globals
->root
.sgot
== NULL
)
5448 return bfd_reloc_notsupported
;
5450 value
= (symbol_got_offset (input_bfd
, h
, r_symndx
)
5451 + globals
->root
.sgot
->output_section
->vma
5452 + globals
->root
.sgot
->output_offset
);
5454 value
= _bfd_aarch64_elf_resolve_relocation (bfd_r_type
, place
, value
,
5456 *unresolved_reloc_p
= FALSE
;
5459 case BFD_RELOC_AARCH64_TLSLD_ADD_DTPREL_HI12
:
5460 case BFD_RELOC_AARCH64_TLSLD_ADD_DTPREL_LO12
:
5461 case BFD_RELOC_AARCH64_TLSLD_ADD_DTPREL_LO12_NC
:
5462 case BFD_RELOC_AARCH64_TLSLD_LDST16_DTPREL_LO12
:
5463 case BFD_RELOC_AARCH64_TLSLD_LDST16_DTPREL_LO12_NC
:
5464 case BFD_RELOC_AARCH64_TLSLD_LDST32_DTPREL_LO12
:
5465 case BFD_RELOC_AARCH64_TLSLD_LDST32_DTPREL_LO12_NC
:
5466 case BFD_RELOC_AARCH64_TLSLD_LDST64_DTPREL_LO12
:
5467 case BFD_RELOC_AARCH64_TLSLD_LDST64_DTPREL_LO12_NC
:
5468 case BFD_RELOC_AARCH64_TLSLD_LDST8_DTPREL_LO12
:
5469 case BFD_RELOC_AARCH64_TLSLD_LDST8_DTPREL_LO12_NC
:
5470 case BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G0
:
5471 case BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G0_NC
:
5472 case BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G1
:
5473 case BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G1_NC
:
5474 case BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G2
:
5475 value
= _bfd_aarch64_elf_resolve_relocation (bfd_r_type
, place
, value
,
5476 signed_addend
- dtpoff_base (info
),
5480 case BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_HI12
:
5481 case BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_LO12
:
5482 case BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_LO12_NC
:
5483 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0
:
5484 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC
:
5485 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1
:
5486 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1_NC
:
5487 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G2
:
5488 value
= _bfd_aarch64_elf_resolve_relocation (bfd_r_type
, place
, value
,
5489 signed_addend
- tpoff_base (info
),
5491 *unresolved_reloc_p
= FALSE
;
5494 case BFD_RELOC_AARCH64_TLSDESC_ADD
:
5495 case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12_NC
:
5496 case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21
:
5497 case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21
:
5498 case BFD_RELOC_AARCH64_TLSDESC_LD32_LO12_NC
:
5499 case BFD_RELOC_AARCH64_TLSDESC_LD64_LO12_NC
:
5500 case BFD_RELOC_AARCH64_TLSDESC_LDR
:
5501 case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19
:
5502 if (globals
->root
.sgot
== NULL
)
5503 return bfd_reloc_notsupported
;
5504 value
= (symbol_tlsdesc_got_offset (input_bfd
, h
, r_symndx
)
5505 + globals
->root
.sgotplt
->output_section
->vma
5506 + globals
->root
.sgotplt
->output_offset
5507 + globals
->sgotplt_jump_table_size
);
5509 value
= _bfd_aarch64_elf_resolve_relocation (bfd_r_type
, place
, value
,
5511 *unresolved_reloc_p
= FALSE
;
5515 return bfd_reloc_notsupported
;
5519 *saved_addend
= value
;
5521 /* Only apply the final relocation in a sequence. */
5523 return bfd_reloc_continue
;
5525 return _bfd_aarch64_elf_put_addend (input_bfd
, hit_data
, bfd_r_type
,
5529 /* Handle TLS relaxations. Relaxing is possible for symbols that use
5530 R_AARCH64_TLSDESC_ADR_{PAGE, LD64_LO12_NC, ADD_LO12_NC} during a static
5533 Return bfd_reloc_ok if we're done, bfd_reloc_continue if the caller
5534 is to then call final_link_relocate. Return other values in the
5537 static bfd_reloc_status_type
5538 elfNN_aarch64_tls_relax (struct elf_aarch64_link_hash_table
*globals
,
5539 bfd
*input_bfd
, bfd_byte
*contents
,
5540 Elf_Internal_Rela
*rel
, struct elf_link_hash_entry
*h
)
5542 bfd_boolean is_local
= h
== NULL
;
5543 unsigned int r_type
= ELFNN_R_TYPE (rel
->r_info
);
5546 BFD_ASSERT (globals
&& input_bfd
&& contents
&& rel
);
5548 switch (elfNN_aarch64_bfd_reloc_from_type (r_type
))
5550 case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21
:
5551 case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21
:
5554 /* GD->LE relaxation:
5555 adrp x0, :tlsgd:var => movz x0, :tprel_g1:var
5557 adrp x0, :tlsdesc:var => movz x0, :tprel_g1:var
5559 bfd_putl32 (0xd2a00000, contents
+ rel
->r_offset
);
5560 return bfd_reloc_continue
;
5564 /* GD->IE relaxation:
5565 adrp x0, :tlsgd:var => adrp x0, :gottprel:var
5567 adrp x0, :tlsdesc:var => adrp x0, :gottprel:var
5569 return bfd_reloc_continue
;
5572 case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21
:
5576 case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19
:
5579 /* Tiny TLSDESC->LE relaxation:
5580 ldr x1, :tlsdesc:var => movz x0, #:tprel_g1:var
5581 adr x0, :tlsdesc:var => movk x0, #:tprel_g0_nc:var
5585 BFD_ASSERT (ELFNN_R_TYPE (rel
[1].r_info
) == AARCH64_R (TLSDESC_ADR_PREL21
));
5586 BFD_ASSERT (ELFNN_R_TYPE (rel
[2].r_info
) == AARCH64_R (TLSDESC_CALL
));
5588 rel
[1].r_info
= ELFNN_R_INFO (ELFNN_R_SYM (rel
->r_info
),
5589 AARCH64_R (TLSLE_MOVW_TPREL_G0_NC
));
5590 rel
[2].r_info
= ELFNN_R_INFO (STN_UNDEF
, R_AARCH64_NONE
);
5592 bfd_putl32 (0xd2a00000, contents
+ rel
->r_offset
);
5593 bfd_putl32 (0xf2800000, contents
+ rel
->r_offset
+ 4);
5594 bfd_putl32 (INSN_NOP
, contents
+ rel
->r_offset
+ 8);
5595 return bfd_reloc_continue
;
5599 /* Tiny TLSDESC->IE relaxation:
5600 ldr x1, :tlsdesc:var => ldr x0, :gottprel:var
5601 adr x0, :tlsdesc:var => nop
5605 BFD_ASSERT (ELFNN_R_TYPE (rel
[1].r_info
) == AARCH64_R (TLSDESC_ADR_PREL21
));
5606 BFD_ASSERT (ELFNN_R_TYPE (rel
[2].r_info
) == AARCH64_R (TLSDESC_CALL
));
5608 rel
[1].r_info
= ELFNN_R_INFO (STN_UNDEF
, R_AARCH64_NONE
);
5609 rel
[2].r_info
= ELFNN_R_INFO (STN_UNDEF
, R_AARCH64_NONE
);
5611 bfd_putl32 (0x58000000, contents
+ rel
->r_offset
);
5612 bfd_putl32 (INSN_NOP
, contents
+ rel
->r_offset
+ 4);
5613 bfd_putl32 (INSN_NOP
, contents
+ rel
->r_offset
+ 8);
5614 return bfd_reloc_continue
;
5617 case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21
:
5620 /* Tiny GD->LE relaxation:
5621 adr x0, :tlsgd:var => mrs x1, tpidr_el0
5622 bl __tls_get_addr => add x0, x1, #:tprel_hi12:x, lsl #12
5623 nop => add x0, x0, #:tprel_lo12_nc:x
5626 /* First kill the tls_get_addr reloc on the bl instruction. */
5627 BFD_ASSERT (rel
->r_offset
+ 4 == rel
[1].r_offset
);
5629 bfd_putl32 (0xd53bd041, contents
+ rel
->r_offset
+ 0);
5630 bfd_putl32 (0x91400020, contents
+ rel
->r_offset
+ 4);
5631 bfd_putl32 (0x91000000, contents
+ rel
->r_offset
+ 8);
5633 rel
[1].r_info
= ELFNN_R_INFO (ELFNN_R_SYM (rel
->r_info
),
5634 AARCH64_R (TLSLE_ADD_TPREL_LO12_NC
));
5635 rel
[1].r_offset
= rel
->r_offset
+ 8;
5637 /* Move the current relocation to the second instruction in
5640 rel
->r_info
= ELFNN_R_INFO (ELFNN_R_SYM (rel
->r_info
),
5641 AARCH64_R (TLSLE_ADD_TPREL_HI12
));
5642 return bfd_reloc_continue
;
5646 /* Tiny GD->IE relaxation:
5647 adr x0, :tlsgd:var => ldr x0, :gottprel:var
5648 bl __tls_get_addr => mrs x1, tpidr_el0
5649 nop => add x0, x0, x1
5652 /* First kill the tls_get_addr reloc on the bl instruction. */
5653 BFD_ASSERT (rel
->r_offset
+ 4 == rel
[1].r_offset
);
5654 rel
[1].r_info
= ELFNN_R_INFO (STN_UNDEF
, R_AARCH64_NONE
);
5656 bfd_putl32 (0x58000000, contents
+ rel
->r_offset
);
5657 bfd_putl32 (0xd53bd041, contents
+ rel
->r_offset
+ 4);
5658 bfd_putl32 (0x8b000020, contents
+ rel
->r_offset
+ 8);
5659 return bfd_reloc_continue
;
5662 case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19
:
5663 return bfd_reloc_continue
;
5665 case BFD_RELOC_AARCH64_TLSDESC_LDNN_LO12_NC
:
5668 /* GD->LE relaxation:
5669 ldr xd, [x0, #:tlsdesc_lo12:var] => movk x0, :tprel_g0_nc:var
5671 bfd_putl32 (0xf2800000, contents
+ rel
->r_offset
);
5672 return bfd_reloc_continue
;
5676 /* GD->IE relaxation:
5677 ldr xd, [x0, #:tlsdesc_lo12:var] => ldr x0, [x0, #:gottprel_lo12:var]
5679 insn
= bfd_getl32 (contents
+ rel
->r_offset
);
5681 bfd_putl32 (insn
, contents
+ rel
->r_offset
);
5682 return bfd_reloc_continue
;
5685 case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC
:
5688 /* GD->LE relaxation
5689 add x0, #:tlsgd_lo12:var => movk x0, :tprel_g0_nc:var
5690 bl __tls_get_addr => mrs x1, tpidr_el0
5691 nop => add x0, x1, x0
5694 /* First kill the tls_get_addr reloc on the bl instruction. */
5695 BFD_ASSERT (rel
->r_offset
+ 4 == rel
[1].r_offset
);
5696 rel
[1].r_info
= ELFNN_R_INFO (STN_UNDEF
, R_AARCH64_NONE
);
5698 bfd_putl32 (0xf2800000, contents
+ rel
->r_offset
);
5699 bfd_putl32 (0xd53bd041, contents
+ rel
->r_offset
+ 4);
5700 bfd_putl32 (0x8b000020, contents
+ rel
->r_offset
+ 8);
5701 return bfd_reloc_continue
;
5705 /* GD->IE relaxation
5706 ADD x0, #:tlsgd_lo12:var => ldr x0, [x0, #:gottprel_lo12:var]
5707 BL __tls_get_addr => mrs x1, tpidr_el0
5709 NOP => add x0, x1, x0
5712 BFD_ASSERT (ELFNN_R_TYPE (rel
[1].r_info
) == AARCH64_R (CALL26
));
5714 /* Remove the relocation on the BL instruction. */
5715 rel
[1].r_info
= ELFNN_R_INFO (STN_UNDEF
, R_AARCH64_NONE
);
5717 bfd_putl32 (0xf9400000, contents
+ rel
->r_offset
);
5719 /* We choose to fixup the BL and NOP instructions using the
5720 offset from the second relocation to allow flexibility in
5721 scheduling instructions between the ADD and BL. */
5722 bfd_putl32 (0xd53bd041, contents
+ rel
[1].r_offset
);
5723 bfd_putl32 (0x8b000020, contents
+ rel
[1].r_offset
+ 4);
5724 return bfd_reloc_continue
;
5727 case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12_NC
:
5728 case BFD_RELOC_AARCH64_TLSDESC_CALL
:
5729 /* GD->IE/LE relaxation:
5730 add x0, x0, #:tlsdesc_lo12:var => nop
5733 bfd_putl32 (INSN_NOP
, contents
+ rel
->r_offset
);
5734 return bfd_reloc_ok
;
5736 case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21
:
5737 /* IE->LE relaxation:
5738 adrp xd, :gottprel:var => movz xd, :tprel_g1:var
5742 insn
= bfd_getl32 (contents
+ rel
->r_offset
);
5743 bfd_putl32 (0xd2a00000 | (insn
& 0x1f), contents
+ rel
->r_offset
);
5745 return bfd_reloc_continue
;
5747 case BFD_RELOC_AARCH64_TLSIE_LDNN_GOTTPREL_LO12_NC
:
5748 /* IE->LE relaxation:
5749 ldr xd, [xm, #:gottprel_lo12:var] => movk xd, :tprel_g0_nc:var
5753 insn
= bfd_getl32 (contents
+ rel
->r_offset
);
5754 bfd_putl32 (0xf2800000 | (insn
& 0x1f), contents
+ rel
->r_offset
);
5756 return bfd_reloc_continue
;
5758 case BFD_RELOC_AARCH64_TLSLD_ADR_PREL21
:
5759 /* LD->LE relaxation (tiny):
5760 adr x0, :tlsldm:x => mrs x0, tpidr_el0
5761 bl __tls_get_addr => add x0, x0, TCB_SIZE
5765 BFD_ASSERT (rel
->r_offset
+ 4 == rel
[1].r_offset
);
5766 BFD_ASSERT (ELFNN_R_TYPE (rel
[1].r_info
) == AARCH64_R (CALL26
));
5767 /* No need of CALL26 relocation for tls_get_addr. */
5768 rel
[1].r_info
= ELFNN_R_INFO (STN_UNDEF
, R_AARCH64_NONE
);
5769 bfd_putl32 (0xd53bd040, contents
+ rel
->r_offset
+ 0);
5770 bfd_putl32 (0x91004000, contents
+ rel
->r_offset
+ 4);
5771 return bfd_reloc_ok
;
5773 return bfd_reloc_continue
;
5775 case BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21
:
5776 /* LD->LE relaxation (small):
5777 adrp x0, :tlsldm:x => mrs x0, tpidr_el0
5781 bfd_putl32 (0xd53bd040, contents
+ rel
->r_offset
);
5782 return bfd_reloc_ok
;
5784 return bfd_reloc_continue
;
5786 case BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC
:
5787 /* LD->LE relaxation (small):
5788 add x0, #:tlsldm_lo12:x => add x0, x0, TCB_SIZE
5789 bl __tls_get_addr => nop
5793 BFD_ASSERT (rel
->r_offset
+ 4 == rel
[1].r_offset
);
5794 BFD_ASSERT (ELFNN_R_TYPE (rel
[1].r_info
) == AARCH64_R (CALL26
));
5795 /* No need of CALL26 relocation for tls_get_addr. */
5796 rel
[1].r_info
= ELFNN_R_INFO (STN_UNDEF
, R_AARCH64_NONE
);
5797 bfd_putl32 (0x91004000, contents
+ rel
->r_offset
+ 0);
5798 bfd_putl32 (0xd503201f, contents
+ rel
->r_offset
+ 4);
5799 return bfd_reloc_ok
;
5801 return bfd_reloc_continue
;
5804 return bfd_reloc_continue
;
5807 return bfd_reloc_ok
;
5810 /* Relocate an AArch64 ELF section. */
5813 elfNN_aarch64_relocate_section (bfd
*output_bfd
,
5814 struct bfd_link_info
*info
,
5816 asection
*input_section
,
5818 Elf_Internal_Rela
*relocs
,
5819 Elf_Internal_Sym
*local_syms
,
5820 asection
**local_sections
)
5822 Elf_Internal_Shdr
*symtab_hdr
;
5823 struct elf_link_hash_entry
**sym_hashes
;
5824 Elf_Internal_Rela
*rel
;
5825 Elf_Internal_Rela
*relend
;
5827 struct elf_aarch64_link_hash_table
*globals
;
5828 bfd_boolean save_addend
= FALSE
;
5831 globals
= elf_aarch64_hash_table (info
);
5833 symtab_hdr
= &elf_symtab_hdr (input_bfd
);
5834 sym_hashes
= elf_sym_hashes (input_bfd
);
5837 relend
= relocs
+ input_section
->reloc_count
;
5838 for (; rel
< relend
; rel
++)
5840 unsigned int r_type
;
5841 bfd_reloc_code_real_type bfd_r_type
;
5842 bfd_reloc_code_real_type relaxed_bfd_r_type
;
5843 reloc_howto_type
*howto
;
5844 unsigned long r_symndx
;
5845 Elf_Internal_Sym
*sym
;
5847 struct elf_link_hash_entry
*h
;
5849 bfd_reloc_status_type r
;
5852 bfd_boolean unresolved_reloc
= FALSE
;
5853 char *error_message
= NULL
;
5855 r_symndx
= ELFNN_R_SYM (rel
->r_info
);
5856 r_type
= ELFNN_R_TYPE (rel
->r_info
);
5858 bfd_reloc
.howto
= elfNN_aarch64_howto_from_type (r_type
);
5859 howto
= bfd_reloc
.howto
;
5863 (*_bfd_error_handler
)
5864 (_("%B: unrecognized relocation (0x%x) in section `%A'"),
5865 input_bfd
, input_section
, r_type
);
5868 bfd_r_type
= elfNN_aarch64_bfd_reloc_from_howto (howto
);
5874 if (r_symndx
< symtab_hdr
->sh_info
)
5876 sym
= local_syms
+ r_symndx
;
5877 sym_type
= ELFNN_ST_TYPE (sym
->st_info
);
5878 sec
= local_sections
[r_symndx
];
5880 /* An object file might have a reference to a local
5881 undefined symbol. This is a daft object file, but we
5882 should at least do something about it. */
5883 if (r_type
!= R_AARCH64_NONE
&& r_type
!= R_AARCH64_NULL
5884 && bfd_is_und_section (sec
)
5885 && ELF_ST_BIND (sym
->st_info
) != STB_WEAK
)
5887 if (!info
->callbacks
->undefined_symbol
5888 (info
, bfd_elf_string_from_elf_section
5889 (input_bfd
, symtab_hdr
->sh_link
, sym
->st_name
),
5890 input_bfd
, input_section
, rel
->r_offset
, TRUE
))
5894 relocation
= _bfd_elf_rela_local_sym (output_bfd
, sym
, &sec
, rel
);
5896 /* Relocate against local STT_GNU_IFUNC symbol. */
5897 if (!bfd_link_relocatable (info
)
5898 && ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
)
5900 h
= elfNN_aarch64_get_local_sym_hash (globals
, input_bfd
,
5905 /* Set STT_GNU_IFUNC symbol value. */
5906 h
->root
.u
.def
.value
= sym
->st_value
;
5907 h
->root
.u
.def
.section
= sec
;
5912 bfd_boolean warned
, ignored
;
5914 RELOC_FOR_GLOBAL_SYMBOL (info
, input_bfd
, input_section
, rel
,
5915 r_symndx
, symtab_hdr
, sym_hashes
,
5917 unresolved_reloc
, warned
, ignored
);
5922 if (sec
!= NULL
&& discarded_section (sec
))
5923 RELOC_AGAINST_DISCARDED_SECTION (info
, input_bfd
, input_section
,
5924 rel
, 1, relend
, howto
, 0, contents
);
5926 if (bfd_link_relocatable (info
))
5930 name
= h
->root
.root
.string
;
5933 name
= (bfd_elf_string_from_elf_section
5934 (input_bfd
, symtab_hdr
->sh_link
, sym
->st_name
));
5935 if (name
== NULL
|| *name
== '\0')
5936 name
= bfd_section_name (input_bfd
, sec
);
5940 && r_type
!= R_AARCH64_NONE
5941 && r_type
!= R_AARCH64_NULL
5943 || h
->root
.type
== bfd_link_hash_defined
5944 || h
->root
.type
== bfd_link_hash_defweak
)
5945 && IS_AARCH64_TLS_RELOC (bfd_r_type
) != (sym_type
== STT_TLS
))
5947 (*_bfd_error_handler
)
5948 ((sym_type
== STT_TLS
5949 ? _("%B(%A+0x%lx): %s used with TLS symbol %s")
5950 : _("%B(%A+0x%lx): %s used with non-TLS symbol %s")),
5952 input_section
, (long) rel
->r_offset
, howto
->name
, name
);
5955 /* We relax only if we can see that there can be a valid transition
5956 from a reloc type to another.
5957 We call elfNN_aarch64_final_link_relocate unless we're completely
5958 done, i.e., the relaxation produced the final output we want. */
5960 relaxed_bfd_r_type
= aarch64_tls_transition (input_bfd
, info
, r_type
,
5962 if (relaxed_bfd_r_type
!= bfd_r_type
)
5964 bfd_r_type
= relaxed_bfd_r_type
;
5965 howto
= elfNN_aarch64_howto_from_bfd_reloc (bfd_r_type
);
5966 BFD_ASSERT (howto
!= NULL
);
5967 r_type
= howto
->type
;
5968 r
= elfNN_aarch64_tls_relax (globals
, input_bfd
, contents
, rel
, h
);
5969 unresolved_reloc
= 0;
5972 r
= bfd_reloc_continue
;
5974 /* There may be multiple consecutive relocations for the
5975 same offset. In that case we are supposed to treat the
5976 output of each relocation as the addend for the next. */
5977 if (rel
+ 1 < relend
5978 && rel
->r_offset
== rel
[1].r_offset
5979 && ELFNN_R_TYPE (rel
[1].r_info
) != R_AARCH64_NONE
5980 && ELFNN_R_TYPE (rel
[1].r_info
) != R_AARCH64_NULL
)
5983 save_addend
= FALSE
;
5985 if (r
== bfd_reloc_continue
)
5986 r
= elfNN_aarch64_final_link_relocate (howto
, input_bfd
, output_bfd
,
5987 input_section
, contents
, rel
,
5988 relocation
, info
, sec
,
5989 h
, &unresolved_reloc
,
5990 save_addend
, &addend
, sym
);
5992 switch (elfNN_aarch64_bfd_reloc_from_type (r_type
))
5994 case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC
:
5995 case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21
:
5996 case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21
:
5997 case BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC
:
5998 case BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21
:
5999 case BFD_RELOC_AARCH64_TLSLD_ADR_PREL21
:
6000 if (! symbol_got_offset_mark_p (input_bfd
, h
, r_symndx
))
6002 bfd_boolean need_relocs
= FALSE
;
6007 off
= symbol_got_offset (input_bfd
, h
, r_symndx
);
6008 indx
= h
&& h
->dynindx
!= -1 ? h
->dynindx
: 0;
6011 (bfd_link_pic (info
) || indx
!= 0) &&
6013 || ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
6014 || h
->root
.type
!= bfd_link_hash_undefweak
);
6016 BFD_ASSERT (globals
->root
.srelgot
!= NULL
);
6020 Elf_Internal_Rela rela
;
6021 rela
.r_info
= ELFNN_R_INFO (indx
, AARCH64_R (TLS_DTPMOD
));
6023 rela
.r_offset
= globals
->root
.sgot
->output_section
->vma
+
6024 globals
->root
.sgot
->output_offset
+ off
;
6027 loc
= globals
->root
.srelgot
->contents
;
6028 loc
+= globals
->root
.srelgot
->reloc_count
++
6029 * RELOC_SIZE (htab
);
6030 bfd_elfNN_swap_reloca_out (output_bfd
, &rela
, loc
);
6032 bfd_reloc_code_real_type real_type
=
6033 elfNN_aarch64_bfd_reloc_from_type (r_type
);
6035 if (real_type
== BFD_RELOC_AARCH64_TLSLD_ADR_PREL21
6036 || real_type
== BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21
6037 || real_type
== BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC
)
6039 /* For local dynamic, don't generate DTPREL in any case.
6040 Initialize the DTPREL slot into zero, so we get module
6041 base address when invoke runtime TLS resolver. */
6042 bfd_put_NN (output_bfd
, 0,
6043 globals
->root
.sgot
->contents
+ off
6048 bfd_put_NN (output_bfd
,
6049 relocation
- dtpoff_base (info
),
6050 globals
->root
.sgot
->contents
+ off
6055 /* This TLS symbol is global. We emit a
6056 relocation to fixup the tls offset at load
6059 ELFNN_R_INFO (indx
, AARCH64_R (TLS_DTPREL
));
6062 (globals
->root
.sgot
->output_section
->vma
6063 + globals
->root
.sgot
->output_offset
+ off
6066 loc
= globals
->root
.srelgot
->contents
;
6067 loc
+= globals
->root
.srelgot
->reloc_count
++
6068 * RELOC_SIZE (globals
);
6069 bfd_elfNN_swap_reloca_out (output_bfd
, &rela
, loc
);
6070 bfd_put_NN (output_bfd
, (bfd_vma
) 0,
6071 globals
->root
.sgot
->contents
+ off
6077 bfd_put_NN (output_bfd
, (bfd_vma
) 1,
6078 globals
->root
.sgot
->contents
+ off
);
6079 bfd_put_NN (output_bfd
,
6080 relocation
- dtpoff_base (info
),
6081 globals
->root
.sgot
->contents
+ off
6085 symbol_got_offset_mark (input_bfd
, h
, r_symndx
);
6089 case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21
:
6090 case BFD_RELOC_AARCH64_TLSIE_LDNN_GOTTPREL_LO12_NC
:
6091 case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19
:
6092 if (! symbol_got_offset_mark_p (input_bfd
, h
, r_symndx
))
6094 bfd_boolean need_relocs
= FALSE
;
6099 off
= symbol_got_offset (input_bfd
, h
, r_symndx
);
6101 indx
= h
&& h
->dynindx
!= -1 ? h
->dynindx
: 0;
6104 (bfd_link_pic (info
) || indx
!= 0) &&
6106 || ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
6107 || h
->root
.type
!= bfd_link_hash_undefweak
);
6109 BFD_ASSERT (globals
->root
.srelgot
!= NULL
);
6113 Elf_Internal_Rela rela
;
6116 rela
.r_addend
= relocation
- dtpoff_base (info
);
6120 rela
.r_info
= ELFNN_R_INFO (indx
, AARCH64_R (TLS_TPREL
));
6121 rela
.r_offset
= globals
->root
.sgot
->output_section
->vma
+
6122 globals
->root
.sgot
->output_offset
+ off
;
6124 loc
= globals
->root
.srelgot
->contents
;
6125 loc
+= globals
->root
.srelgot
->reloc_count
++
6126 * RELOC_SIZE (htab
);
6128 bfd_elfNN_swap_reloca_out (output_bfd
, &rela
, loc
);
6130 bfd_put_NN (output_bfd
, rela
.r_addend
,
6131 globals
->root
.sgot
->contents
+ off
);
6134 bfd_put_NN (output_bfd
, relocation
- tpoff_base (info
),
6135 globals
->root
.sgot
->contents
+ off
);
6137 symbol_got_offset_mark (input_bfd
, h
, r_symndx
);
6141 case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12_NC
:
6142 case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21
:
6143 case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21
:
6144 case BFD_RELOC_AARCH64_TLSDESC_LDNN_LO12_NC
:
6145 case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19
:
6146 if (! symbol_tlsdesc_got_offset_mark_p (input_bfd
, h
, r_symndx
))
6148 bfd_boolean need_relocs
= FALSE
;
6149 int indx
= h
&& h
->dynindx
!= -1 ? h
->dynindx
: 0;
6150 bfd_vma off
= symbol_tlsdesc_got_offset (input_bfd
, h
, r_symndx
);
6152 need_relocs
= (h
== NULL
6153 || ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
6154 || h
->root
.type
!= bfd_link_hash_undefweak
);
6156 BFD_ASSERT (globals
->root
.srelgot
!= NULL
);
6157 BFD_ASSERT (globals
->root
.sgot
!= NULL
);
6162 Elf_Internal_Rela rela
;
6163 rela
.r_info
= ELFNN_R_INFO (indx
, AARCH64_R (TLSDESC
));
6166 rela
.r_offset
= (globals
->root
.sgotplt
->output_section
->vma
6167 + globals
->root
.sgotplt
->output_offset
6168 + off
+ globals
->sgotplt_jump_table_size
);
6171 rela
.r_addend
= relocation
- dtpoff_base (info
);
6173 /* Allocate the next available slot in the PLT reloc
6174 section to hold our R_AARCH64_TLSDESC, the next
6175 available slot is determined from reloc_count,
6176 which we step. But note, reloc_count was
6177 artifically moved down while allocating slots for
6178 real PLT relocs such that all of the PLT relocs
6179 will fit above the initial reloc_count and the
6180 extra stuff will fit below. */
6181 loc
= globals
->root
.srelplt
->contents
;
6182 loc
+= globals
->root
.srelplt
->reloc_count
++
6183 * RELOC_SIZE (globals
);
6185 bfd_elfNN_swap_reloca_out (output_bfd
, &rela
, loc
);
6187 bfd_put_NN (output_bfd
, (bfd_vma
) 0,
6188 globals
->root
.sgotplt
->contents
+ off
+
6189 globals
->sgotplt_jump_table_size
);
6190 bfd_put_NN (output_bfd
, (bfd_vma
) 0,
6191 globals
->root
.sgotplt
->contents
+ off
+
6192 globals
->sgotplt_jump_table_size
+
6196 symbol_tlsdesc_got_offset_mark (input_bfd
, h
, r_symndx
);
6207 /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
6208 because such sections are not SEC_ALLOC and thus ld.so will
6209 not process them. */
6210 if (unresolved_reloc
6211 && !((input_section
->flags
& SEC_DEBUGGING
) != 0
6213 && _bfd_elf_section_offset (output_bfd
, info
, input_section
,
6214 +rel
->r_offset
) != (bfd_vma
) - 1)
6216 (*_bfd_error_handler
)
6218 ("%B(%A+0x%lx): unresolvable %s relocation against symbol `%s'"),
6219 input_bfd
, input_section
, (long) rel
->r_offset
, howto
->name
,
6220 h
->root
.root
.string
);
6224 if (r
!= bfd_reloc_ok
&& r
!= bfd_reloc_continue
)
6226 bfd_reloc_code_real_type real_r_type
6227 = elfNN_aarch64_bfd_reloc_from_type (r_type
);
6231 case bfd_reloc_overflow
:
6232 if (!(*info
->callbacks
->reloc_overflow
)
6233 (info
, (h
? &h
->root
: NULL
), name
, howto
->name
, (bfd_vma
) 0,
6234 input_bfd
, input_section
, rel
->r_offset
))
6236 if (real_r_type
== BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15
6237 || real_r_type
== BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14
)
6239 (*info
->callbacks
->warning
)
6241 _("Too many GOT entries for -fpic, "
6242 "please recompile with -fPIC"),
6243 name
, input_bfd
, input_section
, rel
->r_offset
);
6248 case bfd_reloc_undefined
:
6249 if (!((*info
->callbacks
->undefined_symbol
)
6250 (info
, name
, input_bfd
, input_section
,
6251 rel
->r_offset
, TRUE
)))
6255 case bfd_reloc_outofrange
:
6256 error_message
= _("out of range");
6259 case bfd_reloc_notsupported
:
6260 error_message
= _("unsupported relocation");
6263 case bfd_reloc_dangerous
:
6264 /* error_message should already be set. */
6268 error_message
= _("unknown error");
6272 BFD_ASSERT (error_message
!= NULL
);
6273 if (!((*info
->callbacks
->reloc_dangerous
)
6274 (info
, error_message
, input_bfd
, input_section
,
6285 /* Set the right machine number. */
6288 elfNN_aarch64_object_p (bfd
*abfd
)
6291 bfd_default_set_arch_mach (abfd
, bfd_arch_aarch64
, bfd_mach_aarch64_ilp32
);
6293 bfd_default_set_arch_mach (abfd
, bfd_arch_aarch64
, bfd_mach_aarch64
);
6298 /* Function to keep AArch64 specific flags in the ELF header. */
6301 elfNN_aarch64_set_private_flags (bfd
*abfd
, flagword flags
)
6303 if (elf_flags_init (abfd
) && elf_elfheader (abfd
)->e_flags
!= flags
)
6308 elf_elfheader (abfd
)->e_flags
= flags
;
6309 elf_flags_init (abfd
) = TRUE
;
6315 /* Merge backend specific data from an object file to the output
6316 object file when linking. */
6319 elfNN_aarch64_merge_private_bfd_data (bfd
*ibfd
, bfd
*obfd
)
6323 bfd_boolean flags_compatible
= TRUE
;
6326 /* Check if we have the same endianess. */
6327 if (!_bfd_generic_verify_endian_match (ibfd
, obfd
))
6330 if (!is_aarch64_elf (ibfd
) || !is_aarch64_elf (obfd
))
6333 /* The input BFD must have had its flags initialised. */
6334 /* The following seems bogus to me -- The flags are initialized in
6335 the assembler but I don't think an elf_flags_init field is
6336 written into the object. */
6337 /* BFD_ASSERT (elf_flags_init (ibfd)); */
6339 in_flags
= elf_elfheader (ibfd
)->e_flags
;
6340 out_flags
= elf_elfheader (obfd
)->e_flags
;
6342 if (!elf_flags_init (obfd
))
6344 /* If the input is the default architecture and had the default
6345 flags then do not bother setting the flags for the output
6346 architecture, instead allow future merges to do this. If no
6347 future merges ever set these flags then they will retain their
6348 uninitialised values, which surprise surprise, correspond
6349 to the default values. */
6350 if (bfd_get_arch_info (ibfd
)->the_default
6351 && elf_elfheader (ibfd
)->e_flags
== 0)
6354 elf_flags_init (obfd
) = TRUE
;
6355 elf_elfheader (obfd
)->e_flags
= in_flags
;
6357 if (bfd_get_arch (obfd
) == bfd_get_arch (ibfd
)
6358 && bfd_get_arch_info (obfd
)->the_default
)
6359 return bfd_set_arch_mach (obfd
, bfd_get_arch (ibfd
),
6360 bfd_get_mach (ibfd
));
6365 /* Identical flags must be compatible. */
6366 if (in_flags
== out_flags
)
6369 /* Check to see if the input BFD actually contains any sections. If
6370 not, its flags may not have been initialised either, but it
6371 cannot actually cause any incompatiblity. Do not short-circuit
6372 dynamic objects; their section list may be emptied by
6373 elf_link_add_object_symbols.
6375 Also check to see if there are no code sections in the input.
6376 In this case there is no need to check for code specific flags.
6377 XXX - do we need to worry about floating-point format compatability
6378 in data sections ? */
6379 if (!(ibfd
->flags
& DYNAMIC
))
6381 bfd_boolean null_input_bfd
= TRUE
;
6382 bfd_boolean only_data_sections
= TRUE
;
6384 for (sec
= ibfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
6386 if ((bfd_get_section_flags (ibfd
, sec
)
6387 & (SEC_LOAD
| SEC_CODE
| SEC_HAS_CONTENTS
))
6388 == (SEC_LOAD
| SEC_CODE
| SEC_HAS_CONTENTS
))
6389 only_data_sections
= FALSE
;
6391 null_input_bfd
= FALSE
;
6395 if (null_input_bfd
|| only_data_sections
)
6399 return flags_compatible
;
6402 /* Display the flags field. */
6405 elfNN_aarch64_print_private_bfd_data (bfd
*abfd
, void *ptr
)
6407 FILE *file
= (FILE *) ptr
;
6408 unsigned long flags
;
6410 BFD_ASSERT (abfd
!= NULL
&& ptr
!= NULL
);
6412 /* Print normal ELF private data. */
6413 _bfd_elf_print_private_bfd_data (abfd
, ptr
);
6415 flags
= elf_elfheader (abfd
)->e_flags
;
6416 /* Ignore init flag - it may not be set, despite the flags field
6417 containing valid data. */
6419 /* xgettext:c-format */
6420 fprintf (file
, _("private flags = %lx:"), elf_elfheader (abfd
)->e_flags
);
6423 fprintf (file
, _("<Unrecognised flag bits set>"));
6430 /* Update the got entry reference counts for the section being removed. */
6433 elfNN_aarch64_gc_sweep_hook (bfd
*abfd
,
6434 struct bfd_link_info
*info
,
6436 const Elf_Internal_Rela
* relocs
)
6438 struct elf_aarch64_link_hash_table
*htab
;
6439 Elf_Internal_Shdr
*symtab_hdr
;
6440 struct elf_link_hash_entry
**sym_hashes
;
6441 struct elf_aarch64_local_symbol
*locals
;
6442 const Elf_Internal_Rela
*rel
, *relend
;
6444 if (bfd_link_relocatable (info
))
6447 htab
= elf_aarch64_hash_table (info
);
6452 elf_section_data (sec
)->local_dynrel
= NULL
;
6454 symtab_hdr
= &elf_symtab_hdr (abfd
);
6455 sym_hashes
= elf_sym_hashes (abfd
);
6457 locals
= elf_aarch64_locals (abfd
);
6459 relend
= relocs
+ sec
->reloc_count
;
6460 for (rel
= relocs
; rel
< relend
; rel
++)
6462 unsigned long r_symndx
;
6463 unsigned int r_type
;
6464 struct elf_link_hash_entry
*h
= NULL
;
6466 r_symndx
= ELFNN_R_SYM (rel
->r_info
);
6468 if (r_symndx
>= symtab_hdr
->sh_info
)
6471 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
6472 while (h
->root
.type
== bfd_link_hash_indirect
6473 || h
->root
.type
== bfd_link_hash_warning
)
6474 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
6478 Elf_Internal_Sym
*isym
;
6480 /* A local symbol. */
6481 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
6484 /* Check relocation against local STT_GNU_IFUNC symbol. */
6486 && ELF_ST_TYPE (isym
->st_info
) == STT_GNU_IFUNC
)
6488 h
= elfNN_aarch64_get_local_sym_hash (htab
, abfd
, rel
, FALSE
);
6496 struct elf_aarch64_link_hash_entry
*eh
;
6497 struct elf_dyn_relocs
**pp
;
6498 struct elf_dyn_relocs
*p
;
6500 eh
= (struct elf_aarch64_link_hash_entry
*) h
;
6502 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; pp
= &p
->next
)
6505 /* Everything must go for SEC. */
6511 r_type
= ELFNN_R_TYPE (rel
->r_info
);
6512 switch (aarch64_tls_transition (abfd
,info
, r_type
, h
,r_symndx
))
6514 case BFD_RELOC_AARCH64_ADR_GOT_PAGE
:
6515 case BFD_RELOC_AARCH64_GOT_LD_PREL19
:
6516 case BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14
:
6517 case BFD_RELOC_AARCH64_LD32_GOT_LO12_NC
:
6518 case BFD_RELOC_AARCH64_LD64_GOTOFF_LO15
:
6519 case BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15
:
6520 case BFD_RELOC_AARCH64_LD64_GOT_LO12_NC
:
6521 case BFD_RELOC_AARCH64_MOVW_GOTOFF_G0_NC
:
6522 case BFD_RELOC_AARCH64_MOVW_GOTOFF_G1
:
6523 case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12_NC
:
6524 case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21
:
6525 case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21
:
6526 case BFD_RELOC_AARCH64_TLSDESC_LD32_LO12_NC
:
6527 case BFD_RELOC_AARCH64_TLSDESC_LD64_LO12_NC
:
6528 case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19
:
6529 case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC
:
6530 case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21
:
6531 case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21
:
6532 case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21
:
6533 case BFD_RELOC_AARCH64_TLSIE_LD32_GOTTPREL_LO12_NC
:
6534 case BFD_RELOC_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC
:
6535 case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19
:
6536 case BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC
:
6537 case BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21
:
6538 case BFD_RELOC_AARCH64_TLSLD_ADR_PREL21
:
6541 if (h
->got
.refcount
> 0)
6542 h
->got
.refcount
-= 1;
6544 if (h
->type
== STT_GNU_IFUNC
)
6546 if (h
->plt
.refcount
> 0)
6547 h
->plt
.refcount
-= 1;
6550 else if (locals
!= NULL
)
6552 if (locals
[r_symndx
].got_refcount
> 0)
6553 locals
[r_symndx
].got_refcount
-= 1;
6557 case BFD_RELOC_AARCH64_CALL26
:
6558 case BFD_RELOC_AARCH64_JUMP26
:
6559 /* If this is a local symbol then we resolve it
6560 directly without creating a PLT entry. */
6564 if (h
->plt
.refcount
> 0)
6565 h
->plt
.refcount
-= 1;
6568 case BFD_RELOC_AARCH64_ADR_HI21_NC_PCREL
:
6569 case BFD_RELOC_AARCH64_ADR_HI21_PCREL
:
6570 case BFD_RELOC_AARCH64_ADR_LO21_PCREL
:
6571 case BFD_RELOC_AARCH64_MOVW_G0_NC
:
6572 case BFD_RELOC_AARCH64_MOVW_G1_NC
:
6573 case BFD_RELOC_AARCH64_MOVW_G2_NC
:
6574 case BFD_RELOC_AARCH64_MOVW_G3
:
6575 case BFD_RELOC_AARCH64_NN
:
6576 if (h
!= NULL
&& bfd_link_executable (info
))
6578 if (h
->plt
.refcount
> 0)
6579 h
->plt
.refcount
-= 1;
6591 /* Adjust a symbol defined by a dynamic object and referenced by a
6592 regular object. The current definition is in some section of the
6593 dynamic object, but we're not including those sections. We have to
6594 change the definition to something the rest of the link can
6598 elfNN_aarch64_adjust_dynamic_symbol (struct bfd_link_info
*info
,
6599 struct elf_link_hash_entry
*h
)
6601 struct elf_aarch64_link_hash_table
*htab
;
6604 /* If this is a function, put it in the procedure linkage table. We
6605 will fill in the contents of the procedure linkage table later,
6606 when we know the address of the .got section. */
6607 if (h
->type
== STT_FUNC
|| h
->type
== STT_GNU_IFUNC
|| h
->needs_plt
)
6609 if (h
->plt
.refcount
<= 0
6610 || (h
->type
!= STT_GNU_IFUNC
6611 && (SYMBOL_CALLS_LOCAL (info
, h
)
6612 || (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
6613 && h
->root
.type
== bfd_link_hash_undefweak
))))
6615 /* This case can occur if we saw a CALL26 reloc in
6616 an input file, but the symbol wasn't referred to
6617 by a dynamic object or all references were
6618 garbage collected. In which case we can end up
6620 h
->plt
.offset
= (bfd_vma
) - 1;
6627 /* Otherwise, reset to -1. */
6628 h
->plt
.offset
= (bfd_vma
) - 1;
6631 /* If this is a weak symbol, and there is a real definition, the
6632 processor independent code will have arranged for us to see the
6633 real definition first, and we can just use the same value. */
6634 if (h
->u
.weakdef
!= NULL
)
6636 BFD_ASSERT (h
->u
.weakdef
->root
.type
== bfd_link_hash_defined
6637 || h
->u
.weakdef
->root
.type
== bfd_link_hash_defweak
);
6638 h
->root
.u
.def
.section
= h
->u
.weakdef
->root
.u
.def
.section
;
6639 h
->root
.u
.def
.value
= h
->u
.weakdef
->root
.u
.def
.value
;
6640 if (ELIMINATE_COPY_RELOCS
|| info
->nocopyreloc
)
6641 h
->non_got_ref
= h
->u
.weakdef
->non_got_ref
;
6645 /* If we are creating a shared library, we must presume that the
6646 only references to the symbol are via the global offset table.
6647 For such cases we need not do anything here; the relocations will
6648 be handled correctly by relocate_section. */
6649 if (bfd_link_pic (info
))
6652 /* If there are no references to this symbol that do not use the
6653 GOT, we don't need to generate a copy reloc. */
6654 if (!h
->non_got_ref
)
6657 /* If -z nocopyreloc was given, we won't generate them either. */
6658 if (info
->nocopyreloc
)
6664 /* We must allocate the symbol in our .dynbss section, which will
6665 become part of the .bss section of the executable. There will be
6666 an entry for this symbol in the .dynsym section. The dynamic
6667 object will contain position independent code, so all references
6668 from the dynamic object to this symbol will go through the global
6669 offset table. The dynamic linker will use the .dynsym entry to
6670 determine the address it must put in the global offset table, so
6671 both the dynamic object and the regular object will refer to the
6672 same memory location for the variable. */
6674 htab
= elf_aarch64_hash_table (info
);
6676 /* We must generate a R_AARCH64_COPY reloc to tell the dynamic linker
6677 to copy the initial value out of the dynamic object and into the
6678 runtime process image. */
6679 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0 && h
->size
!= 0)
6681 htab
->srelbss
->size
+= RELOC_SIZE (htab
);
6687 return _bfd_elf_adjust_dynamic_copy (info
, h
, s
);
6692 elfNN_aarch64_allocate_local_symbols (bfd
*abfd
, unsigned number
)
6694 struct elf_aarch64_local_symbol
*locals
;
6695 locals
= elf_aarch64_locals (abfd
);
6698 locals
= (struct elf_aarch64_local_symbol
*)
6699 bfd_zalloc (abfd
, number
* sizeof (struct elf_aarch64_local_symbol
));
6702 elf_aarch64_locals (abfd
) = locals
;
6707 /* Create the .got section to hold the global offset table. */
6710 aarch64_elf_create_got_section (bfd
*abfd
, struct bfd_link_info
*info
)
6712 const struct elf_backend_data
*bed
= get_elf_backend_data (abfd
);
6715 struct elf_link_hash_entry
*h
;
6716 struct elf_link_hash_table
*htab
= elf_hash_table (info
);
6718 /* This function may be called more than once. */
6719 s
= bfd_get_linker_section (abfd
, ".got");
6723 flags
= bed
->dynamic_sec_flags
;
6725 s
= bfd_make_section_anyway_with_flags (abfd
,
6726 (bed
->rela_plts_and_copies_p
6727 ? ".rela.got" : ".rel.got"),
6728 (bed
->dynamic_sec_flags
6731 || ! bfd_set_section_alignment (abfd
, s
, bed
->s
->log_file_align
))
6735 s
= bfd_make_section_anyway_with_flags (abfd
, ".got", flags
);
6737 || !bfd_set_section_alignment (abfd
, s
, bed
->s
->log_file_align
))
6740 htab
->sgot
->size
+= GOT_ENTRY_SIZE
;
6742 if (bed
->want_got_sym
)
6744 /* Define the symbol _GLOBAL_OFFSET_TABLE_ at the start of the .got
6745 (or .got.plt) section. We don't do this in the linker script
6746 because we don't want to define the symbol if we are not creating
6747 a global offset table. */
6748 h
= _bfd_elf_define_linkage_sym (abfd
, info
, s
,
6749 "_GLOBAL_OFFSET_TABLE_");
6750 elf_hash_table (info
)->hgot
= h
;
6755 if (bed
->want_got_plt
)
6757 s
= bfd_make_section_anyway_with_flags (abfd
, ".got.plt", flags
);
6759 || !bfd_set_section_alignment (abfd
, s
,
6760 bed
->s
->log_file_align
))
6765 /* The first bit of the global offset table is the header. */
6766 s
->size
+= bed
->got_header_size
;
6771 /* Look through the relocs for a section during the first phase. */
6774 elfNN_aarch64_check_relocs (bfd
*abfd
, struct bfd_link_info
*info
,
6775 asection
*sec
, const Elf_Internal_Rela
*relocs
)
6777 Elf_Internal_Shdr
*symtab_hdr
;
6778 struct elf_link_hash_entry
**sym_hashes
;
6779 const Elf_Internal_Rela
*rel
;
6780 const Elf_Internal_Rela
*rel_end
;
6783 struct elf_aarch64_link_hash_table
*htab
;
6785 if (bfd_link_relocatable (info
))
6788 BFD_ASSERT (is_aarch64_elf (abfd
));
6790 htab
= elf_aarch64_hash_table (info
);
6793 symtab_hdr
= &elf_symtab_hdr (abfd
);
6794 sym_hashes
= elf_sym_hashes (abfd
);
6796 rel_end
= relocs
+ sec
->reloc_count
;
6797 for (rel
= relocs
; rel
< rel_end
; rel
++)
6799 struct elf_link_hash_entry
*h
;
6800 unsigned long r_symndx
;
6801 unsigned int r_type
;
6802 bfd_reloc_code_real_type bfd_r_type
;
6803 Elf_Internal_Sym
*isym
;
6805 r_symndx
= ELFNN_R_SYM (rel
->r_info
);
6806 r_type
= ELFNN_R_TYPE (rel
->r_info
);
6808 if (r_symndx
>= NUM_SHDR_ENTRIES (symtab_hdr
))
6810 (*_bfd_error_handler
) (_("%B: bad symbol index: %d"), abfd
,
6815 if (r_symndx
< symtab_hdr
->sh_info
)
6817 /* A local symbol. */
6818 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
6823 /* Check relocation against local STT_GNU_IFUNC symbol. */
6824 if (ELF_ST_TYPE (isym
->st_info
) == STT_GNU_IFUNC
)
6826 h
= elfNN_aarch64_get_local_sym_hash (htab
, abfd
, rel
,
6831 /* Fake a STT_GNU_IFUNC symbol. */
6832 h
->type
= STT_GNU_IFUNC
;
6835 h
->forced_local
= 1;
6836 h
->root
.type
= bfd_link_hash_defined
;
6843 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
6844 while (h
->root
.type
== bfd_link_hash_indirect
6845 || h
->root
.type
== bfd_link_hash_warning
)
6846 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
6848 /* PR15323, ref flags aren't set for references in the same
6850 h
->root
.non_ir_ref
= 1;
6853 /* Could be done earlier, if h were already available. */
6854 bfd_r_type
= aarch64_tls_transition (abfd
, info
, r_type
, h
, r_symndx
);
6858 /* Create the ifunc sections for static executables. If we
6859 never see an indirect function symbol nor we are building
6860 a static executable, those sections will be empty and
6861 won't appear in output. */
6867 case BFD_RELOC_AARCH64_ADD_LO12
:
6868 case BFD_RELOC_AARCH64_ADR_GOT_PAGE
:
6869 case BFD_RELOC_AARCH64_ADR_HI21_PCREL
:
6870 case BFD_RELOC_AARCH64_CALL26
:
6871 case BFD_RELOC_AARCH64_GOT_LD_PREL19
:
6872 case BFD_RELOC_AARCH64_JUMP26
:
6873 case BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14
:
6874 case BFD_RELOC_AARCH64_LD32_GOT_LO12_NC
:
6875 case BFD_RELOC_AARCH64_LD64_GOTOFF_LO15
:
6876 case BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15
:
6877 case BFD_RELOC_AARCH64_LD64_GOT_LO12_NC
:
6878 case BFD_RELOC_AARCH64_MOVW_GOTOFF_G0_NC
:
6879 case BFD_RELOC_AARCH64_MOVW_GOTOFF_G1
:
6880 case BFD_RELOC_AARCH64_NN
:
6881 if (htab
->root
.dynobj
== NULL
)
6882 htab
->root
.dynobj
= abfd
;
6883 if (!_bfd_elf_create_ifunc_sections (htab
->root
.dynobj
, info
))
6888 /* It is referenced by a non-shared object. */
6890 h
->root
.non_ir_ref
= 1;
6895 case BFD_RELOC_AARCH64_NN
:
6897 /* We don't need to handle relocs into sections not going into
6898 the "real" output. */
6899 if ((sec
->flags
& SEC_ALLOC
) == 0)
6904 if (!bfd_link_pic (info
))
6907 h
->plt
.refcount
+= 1;
6908 h
->pointer_equality_needed
= 1;
6911 /* No need to do anything if we're not creating a shared
6913 if (! bfd_link_pic (info
))
6917 struct elf_dyn_relocs
*p
;
6918 struct elf_dyn_relocs
**head
;
6920 /* We must copy these reloc types into the output file.
6921 Create a reloc section in dynobj and make room for
6925 if (htab
->root
.dynobj
== NULL
)
6926 htab
->root
.dynobj
= abfd
;
6928 sreloc
= _bfd_elf_make_dynamic_reloc_section
6929 (sec
, htab
->root
.dynobj
, LOG_FILE_ALIGN
, abfd
, /*rela? */ TRUE
);
6935 /* If this is a global symbol, we count the number of
6936 relocations we need for this symbol. */
6939 struct elf_aarch64_link_hash_entry
*eh
;
6940 eh
= (struct elf_aarch64_link_hash_entry
*) h
;
6941 head
= &eh
->dyn_relocs
;
6945 /* Track dynamic relocs needed for local syms too.
6946 We really need local syms available to do this
6952 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
6957 s
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
6961 /* Beware of type punned pointers vs strict aliasing
6963 vpp
= &(elf_section_data (s
)->local_dynrel
);
6964 head
= (struct elf_dyn_relocs
**) vpp
;
6968 if (p
== NULL
|| p
->sec
!= sec
)
6970 bfd_size_type amt
= sizeof *p
;
6971 p
= ((struct elf_dyn_relocs
*)
6972 bfd_zalloc (htab
->root
.dynobj
, amt
));
6985 /* RR: We probably want to keep a consistency check that
6986 there are no dangling GOT_PAGE relocs. */
6987 case BFD_RELOC_AARCH64_ADR_GOT_PAGE
:
6988 case BFD_RELOC_AARCH64_GOT_LD_PREL19
:
6989 case BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14
:
6990 case BFD_RELOC_AARCH64_LD32_GOT_LO12_NC
:
6991 case BFD_RELOC_AARCH64_LD64_GOTOFF_LO15
:
6992 case BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15
:
6993 case BFD_RELOC_AARCH64_LD64_GOT_LO12_NC
:
6994 case BFD_RELOC_AARCH64_MOVW_GOTOFF_G0_NC
:
6995 case BFD_RELOC_AARCH64_MOVW_GOTOFF_G1
:
6996 case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12_NC
:
6997 case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21
:
6998 case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21
:
6999 case BFD_RELOC_AARCH64_TLSDESC_LD32_LO12_NC
:
7000 case BFD_RELOC_AARCH64_TLSDESC_LD64_LO12_NC
:
7001 case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19
:
7002 case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC
:
7003 case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21
:
7004 case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21
:
7005 case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21
:
7006 case BFD_RELOC_AARCH64_TLSIE_LD32_GOTTPREL_LO12_NC
:
7007 case BFD_RELOC_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC
:
7008 case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19
:
7009 case BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC
:
7010 case BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21
:
7011 case BFD_RELOC_AARCH64_TLSLD_ADR_PREL21
:
7014 unsigned old_got_type
;
7016 got_type
= aarch64_reloc_got_type (bfd_r_type
);
7020 h
->got
.refcount
+= 1;
7021 old_got_type
= elf_aarch64_hash_entry (h
)->got_type
;
7025 struct elf_aarch64_local_symbol
*locals
;
7027 if (!elfNN_aarch64_allocate_local_symbols
7028 (abfd
, symtab_hdr
->sh_info
))
7031 locals
= elf_aarch64_locals (abfd
);
7032 BFD_ASSERT (r_symndx
< symtab_hdr
->sh_info
);
7033 locals
[r_symndx
].got_refcount
+= 1;
7034 old_got_type
= locals
[r_symndx
].got_type
;
7037 /* If a variable is accessed with both general dynamic TLS
7038 methods, two slots may be created. */
7039 if (GOT_TLS_GD_ANY_P (old_got_type
) && GOT_TLS_GD_ANY_P (got_type
))
7040 got_type
|= old_got_type
;
7042 /* We will already have issued an error message if there
7043 is a TLS/non-TLS mismatch, based on the symbol type.
7044 So just combine any TLS types needed. */
7045 if (old_got_type
!= GOT_UNKNOWN
&& old_got_type
!= GOT_NORMAL
7046 && got_type
!= GOT_NORMAL
)
7047 got_type
|= old_got_type
;
7049 /* If the symbol is accessed by both IE and GD methods, we
7050 are able to relax. Turn off the GD flag, without
7051 messing up with any other kind of TLS types that may be
7053 if ((got_type
& GOT_TLS_IE
) && GOT_TLS_GD_ANY_P (got_type
))
7054 got_type
&= ~ (GOT_TLSDESC_GD
| GOT_TLS_GD
);
7056 if (old_got_type
!= got_type
)
7059 elf_aarch64_hash_entry (h
)->got_type
= got_type
;
7062 struct elf_aarch64_local_symbol
*locals
;
7063 locals
= elf_aarch64_locals (abfd
);
7064 BFD_ASSERT (r_symndx
< symtab_hdr
->sh_info
);
7065 locals
[r_symndx
].got_type
= got_type
;
7069 if (htab
->root
.dynobj
== NULL
)
7070 htab
->root
.dynobj
= abfd
;
7071 if (! aarch64_elf_create_got_section (htab
->root
.dynobj
, info
))
7076 case BFD_RELOC_AARCH64_MOVW_G0_NC
:
7077 case BFD_RELOC_AARCH64_MOVW_G1_NC
:
7078 case BFD_RELOC_AARCH64_MOVW_G2_NC
:
7079 case BFD_RELOC_AARCH64_MOVW_G3
:
7080 if (bfd_link_pic (info
))
7082 int howto_index
= bfd_r_type
- BFD_RELOC_AARCH64_RELOC_START
;
7083 (*_bfd_error_handler
)
7084 (_("%B: relocation %s against `%s' can not be used when making "
7085 "a shared object; recompile with -fPIC"),
7086 abfd
, elfNN_aarch64_howto_table
[howto_index
].name
,
7087 (h
) ? h
->root
.root
.string
: "a local symbol");
7088 bfd_set_error (bfd_error_bad_value
);
7092 case BFD_RELOC_AARCH64_ADR_HI21_NC_PCREL
:
7093 case BFD_RELOC_AARCH64_ADR_HI21_PCREL
:
7094 case BFD_RELOC_AARCH64_ADR_LO21_PCREL
:
7095 if (h
!= NULL
&& bfd_link_executable (info
))
7097 /* If this reloc is in a read-only section, we might
7098 need a copy reloc. We can't check reliably at this
7099 stage whether the section is read-only, as input
7100 sections have not yet been mapped to output sections.
7101 Tentatively set the flag for now, and correct in
7102 adjust_dynamic_symbol. */
7104 h
->plt
.refcount
+= 1;
7105 h
->pointer_equality_needed
= 1;
7107 /* FIXME:: RR need to handle these in shared libraries
7108 and essentially bomb out as these being non-PIC
7109 relocations in shared libraries. */
7112 case BFD_RELOC_AARCH64_CALL26
:
7113 case BFD_RELOC_AARCH64_JUMP26
:
7114 /* If this is a local symbol then we resolve it
7115 directly without creating a PLT entry. */
7120 if (h
->plt
.refcount
<= 0)
7121 h
->plt
.refcount
= 1;
7123 h
->plt
.refcount
+= 1;
7134 /* Treat mapping symbols as special target symbols. */
7137 elfNN_aarch64_is_target_special_symbol (bfd
*abfd ATTRIBUTE_UNUSED
,
7140 return bfd_is_aarch64_special_symbol_name (sym
->name
,
7141 BFD_AARCH64_SPECIAL_SYM_TYPE_ANY
);
7144 /* This is a copy of elf_find_function () from elf.c except that
7145 AArch64 mapping symbols are ignored when looking for function names. */
7148 aarch64_elf_find_function (bfd
*abfd ATTRIBUTE_UNUSED
,
7152 const char **filename_ptr
,
7153 const char **functionname_ptr
)
7155 const char *filename
= NULL
;
7156 asymbol
*func
= NULL
;
7157 bfd_vma low_func
= 0;
7160 for (p
= symbols
; *p
!= NULL
; p
++)
7164 q
= (elf_symbol_type
*) * p
;
7166 switch (ELF_ST_TYPE (q
->internal_elf_sym
.st_info
))
7171 filename
= bfd_asymbol_name (&q
->symbol
);
7175 /* Skip mapping symbols. */
7176 if ((q
->symbol
.flags
& BSF_LOCAL
)
7177 && (bfd_is_aarch64_special_symbol_name
7178 (q
->symbol
.name
, BFD_AARCH64_SPECIAL_SYM_TYPE_ANY
)))
7181 if (bfd_get_section (&q
->symbol
) == section
7182 && q
->symbol
.value
>= low_func
&& q
->symbol
.value
<= offset
)
7184 func
= (asymbol
*) q
;
7185 low_func
= q
->symbol
.value
;
7195 *filename_ptr
= filename
;
7196 if (functionname_ptr
)
7197 *functionname_ptr
= bfd_asymbol_name (func
);
7203 /* Find the nearest line to a particular section and offset, for error
7204 reporting. This code is a duplicate of the code in elf.c, except
7205 that it uses aarch64_elf_find_function. */
7208 elfNN_aarch64_find_nearest_line (bfd
*abfd
,
7212 const char **filename_ptr
,
7213 const char **functionname_ptr
,
7214 unsigned int *line_ptr
,
7215 unsigned int *discriminator_ptr
)
7217 bfd_boolean found
= FALSE
;
7219 if (_bfd_dwarf2_find_nearest_line (abfd
, symbols
, NULL
, section
, offset
,
7220 filename_ptr
, functionname_ptr
,
7221 line_ptr
, discriminator_ptr
,
7222 dwarf_debug_sections
, 0,
7223 &elf_tdata (abfd
)->dwarf2_find_line_info
))
7225 if (!*functionname_ptr
)
7226 aarch64_elf_find_function (abfd
, symbols
, section
, offset
,
7227 *filename_ptr
? NULL
: filename_ptr
,
7233 /* Skip _bfd_dwarf1_find_nearest_line since no known AArch64
7234 toolchain uses DWARF1. */
7236 if (!_bfd_stab_section_find_nearest_line (abfd
, symbols
, section
, offset
,
7237 &found
, filename_ptr
,
7238 functionname_ptr
, line_ptr
,
7239 &elf_tdata (abfd
)->line_info
))
7242 if (found
&& (*functionname_ptr
|| *line_ptr
))
7245 if (symbols
== NULL
)
7248 if (!aarch64_elf_find_function (abfd
, symbols
, section
, offset
,
7249 filename_ptr
, functionname_ptr
))
7257 elfNN_aarch64_find_inliner_info (bfd
*abfd
,
7258 const char **filename_ptr
,
7259 const char **functionname_ptr
,
7260 unsigned int *line_ptr
)
7263 found
= _bfd_dwarf2_find_inliner_info
7264 (abfd
, filename_ptr
,
7265 functionname_ptr
, line_ptr
, &elf_tdata (abfd
)->dwarf2_find_line_info
);
7271 elfNN_aarch64_post_process_headers (bfd
*abfd
,
7272 struct bfd_link_info
*link_info
)
7274 Elf_Internal_Ehdr
*i_ehdrp
; /* ELF file header, internal form. */
7276 i_ehdrp
= elf_elfheader (abfd
);
7277 i_ehdrp
->e_ident
[EI_ABIVERSION
] = AARCH64_ELF_ABI_VERSION
;
7279 _bfd_elf_post_process_headers (abfd
, link_info
);
7282 static enum elf_reloc_type_class
7283 elfNN_aarch64_reloc_type_class (const struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
7284 const asection
*rel_sec ATTRIBUTE_UNUSED
,
7285 const Elf_Internal_Rela
*rela
)
7287 switch ((int) ELFNN_R_TYPE (rela
->r_info
))
7289 case AARCH64_R (RELATIVE
):
7290 return reloc_class_relative
;
7291 case AARCH64_R (JUMP_SLOT
):
7292 return reloc_class_plt
;
7293 case AARCH64_R (COPY
):
7294 return reloc_class_copy
;
7296 return reloc_class_normal
;
7300 /* Handle an AArch64 specific section when reading an object file. This is
7301 called when bfd_section_from_shdr finds a section with an unknown
7305 elfNN_aarch64_section_from_shdr (bfd
*abfd
,
7306 Elf_Internal_Shdr
*hdr
,
7307 const char *name
, int shindex
)
7309 /* There ought to be a place to keep ELF backend specific flags, but
7310 at the moment there isn't one. We just keep track of the
7311 sections by their name, instead. Fortunately, the ABI gives
7312 names for all the AArch64 specific sections, so we will probably get
7314 switch (hdr
->sh_type
)
7316 case SHT_AARCH64_ATTRIBUTES
:
7323 if (!_bfd_elf_make_section_from_shdr (abfd
, hdr
, name
, shindex
))
7329 /* A structure used to record a list of sections, independently
7330 of the next and prev fields in the asection structure. */
7331 typedef struct section_list
7334 struct section_list
*next
;
7335 struct section_list
*prev
;
7339 /* Unfortunately we need to keep a list of sections for which
7340 an _aarch64_elf_section_data structure has been allocated. This
7341 is because it is possible for functions like elfNN_aarch64_write_section
7342 to be called on a section which has had an elf_data_structure
7343 allocated for it (and so the used_by_bfd field is valid) but
7344 for which the AArch64 extended version of this structure - the
7345 _aarch64_elf_section_data structure - has not been allocated. */
7346 static section_list
*sections_with_aarch64_elf_section_data
= NULL
;
7349 record_section_with_aarch64_elf_section_data (asection
*sec
)
7351 struct section_list
*entry
;
7353 entry
= bfd_malloc (sizeof (*entry
));
7357 entry
->next
= sections_with_aarch64_elf_section_data
;
7359 if (entry
->next
!= NULL
)
7360 entry
->next
->prev
= entry
;
7361 sections_with_aarch64_elf_section_data
= entry
;
7364 static struct section_list
*
7365 find_aarch64_elf_section_entry (asection
*sec
)
7367 struct section_list
*entry
;
7368 static struct section_list
*last_entry
= NULL
;
7370 /* This is a short cut for the typical case where the sections are added
7371 to the sections_with_aarch64_elf_section_data list in forward order and
7372 then looked up here in backwards order. This makes a real difference
7373 to the ld-srec/sec64k.exp linker test. */
7374 entry
= sections_with_aarch64_elf_section_data
;
7375 if (last_entry
!= NULL
)
7377 if (last_entry
->sec
== sec
)
7379 else if (last_entry
->next
!= NULL
&& last_entry
->next
->sec
== sec
)
7380 entry
= last_entry
->next
;
7383 for (; entry
; entry
= entry
->next
)
7384 if (entry
->sec
== sec
)
7388 /* Record the entry prior to this one - it is the entry we are
7389 most likely to want to locate next time. Also this way if we
7390 have been called from
7391 unrecord_section_with_aarch64_elf_section_data () we will not
7392 be caching a pointer that is about to be freed. */
7393 last_entry
= entry
->prev
;
7399 unrecord_section_with_aarch64_elf_section_data (asection
*sec
)
7401 struct section_list
*entry
;
7403 entry
= find_aarch64_elf_section_entry (sec
);
7407 if (entry
->prev
!= NULL
)
7408 entry
->prev
->next
= entry
->next
;
7409 if (entry
->next
!= NULL
)
7410 entry
->next
->prev
= entry
->prev
;
7411 if (entry
== sections_with_aarch64_elf_section_data
)
7412 sections_with_aarch64_elf_section_data
= entry
->next
;
7421 struct bfd_link_info
*info
;
7424 int (*func
) (void *, const char *, Elf_Internal_Sym
*,
7425 asection
*, struct elf_link_hash_entry
*);
7426 } output_arch_syminfo
;
7428 enum map_symbol_type
7435 /* Output a single mapping symbol. */
7438 elfNN_aarch64_output_map_sym (output_arch_syminfo
*osi
,
7439 enum map_symbol_type type
, bfd_vma offset
)
7441 static const char *names
[2] = { "$x", "$d" };
7442 Elf_Internal_Sym sym
;
7444 sym
.st_value
= (osi
->sec
->output_section
->vma
7445 + osi
->sec
->output_offset
+ offset
);
7448 sym
.st_info
= ELF_ST_INFO (STB_LOCAL
, STT_NOTYPE
);
7449 sym
.st_shndx
= osi
->sec_shndx
;
7450 return osi
->func (osi
->finfo
, names
[type
], &sym
, osi
->sec
, NULL
) == 1;
7453 /* Output a single local symbol for a generated stub. */
7456 elfNN_aarch64_output_stub_sym (output_arch_syminfo
*osi
, const char *name
,
7457 bfd_vma offset
, bfd_vma size
)
7459 Elf_Internal_Sym sym
;
7461 sym
.st_value
= (osi
->sec
->output_section
->vma
7462 + osi
->sec
->output_offset
+ offset
);
7465 sym
.st_info
= ELF_ST_INFO (STB_LOCAL
, STT_FUNC
);
7466 sym
.st_shndx
= osi
->sec_shndx
;
7467 return osi
->func (osi
->finfo
, name
, &sym
, osi
->sec
, NULL
) == 1;
7471 aarch64_map_one_stub (struct bfd_hash_entry
*gen_entry
, void *in_arg
)
7473 struct elf_aarch64_stub_hash_entry
*stub_entry
;
7477 output_arch_syminfo
*osi
;
7479 /* Massage our args to the form they really have. */
7480 stub_entry
= (struct elf_aarch64_stub_hash_entry
*) gen_entry
;
7481 osi
= (output_arch_syminfo
*) in_arg
;
7483 stub_sec
= stub_entry
->stub_sec
;
7485 /* Ensure this stub is attached to the current section being
7487 if (stub_sec
!= osi
->sec
)
7490 addr
= (bfd_vma
) stub_entry
->stub_offset
;
7492 stub_name
= stub_entry
->output_name
;
7494 switch (stub_entry
->stub_type
)
7496 case aarch64_stub_adrp_branch
:
7497 if (!elfNN_aarch64_output_stub_sym (osi
, stub_name
, addr
,
7498 sizeof (aarch64_adrp_branch_stub
)))
7500 if (!elfNN_aarch64_output_map_sym (osi
, AARCH64_MAP_INSN
, addr
))
7503 case aarch64_stub_long_branch
:
7504 if (!elfNN_aarch64_output_stub_sym
7505 (osi
, stub_name
, addr
, sizeof (aarch64_long_branch_stub
)))
7507 if (!elfNN_aarch64_output_map_sym (osi
, AARCH64_MAP_INSN
, addr
))
7509 if (!elfNN_aarch64_output_map_sym (osi
, AARCH64_MAP_DATA
, addr
+ 16))
7512 case aarch64_stub_erratum_835769_veneer
:
7513 if (!elfNN_aarch64_output_stub_sym (osi
, stub_name
, addr
,
7514 sizeof (aarch64_erratum_835769_stub
)))
7516 if (!elfNN_aarch64_output_map_sym (osi
, AARCH64_MAP_INSN
, addr
))
7519 case aarch64_stub_erratum_843419_veneer
:
7520 if (!elfNN_aarch64_output_stub_sym (osi
, stub_name
, addr
,
7521 sizeof (aarch64_erratum_843419_stub
)))
7523 if (!elfNN_aarch64_output_map_sym (osi
, AARCH64_MAP_INSN
, addr
))
7534 /* Output mapping symbols for linker generated sections. */
7537 elfNN_aarch64_output_arch_local_syms (bfd
*output_bfd
,
7538 struct bfd_link_info
*info
,
7540 int (*func
) (void *, const char *,
7543 struct elf_link_hash_entry
7546 output_arch_syminfo osi
;
7547 struct elf_aarch64_link_hash_table
*htab
;
7549 htab
= elf_aarch64_hash_table (info
);
7555 /* Long calls stubs. */
7556 if (htab
->stub_bfd
&& htab
->stub_bfd
->sections
)
7560 for (stub_sec
= htab
->stub_bfd
->sections
;
7561 stub_sec
!= NULL
; stub_sec
= stub_sec
->next
)
7563 /* Ignore non-stub sections. */
7564 if (!strstr (stub_sec
->name
, STUB_SUFFIX
))
7569 osi
.sec_shndx
= _bfd_elf_section_from_bfd_section
7570 (output_bfd
, osi
.sec
->output_section
);
7572 /* The first instruction in a stub is always a branch. */
7573 if (!elfNN_aarch64_output_map_sym (&osi
, AARCH64_MAP_INSN
, 0))
7576 bfd_hash_traverse (&htab
->stub_hash_table
, aarch64_map_one_stub
,
7581 /* Finally, output mapping symbols for the PLT. */
7582 if (!htab
->root
.splt
|| htab
->root
.splt
->size
== 0)
7585 osi
.sec_shndx
= _bfd_elf_section_from_bfd_section
7586 (output_bfd
, htab
->root
.splt
->output_section
);
7587 osi
.sec
= htab
->root
.splt
;
7589 elfNN_aarch64_output_map_sym (&osi
, AARCH64_MAP_INSN
, 0);
7595 /* Allocate target specific section data. */
7598 elfNN_aarch64_new_section_hook (bfd
*abfd
, asection
*sec
)
7600 if (!sec
->used_by_bfd
)
7602 _aarch64_elf_section_data
*sdata
;
7603 bfd_size_type amt
= sizeof (*sdata
);
7605 sdata
= bfd_zalloc (abfd
, amt
);
7608 sec
->used_by_bfd
= sdata
;
7611 record_section_with_aarch64_elf_section_data (sec
);
7613 return _bfd_elf_new_section_hook (abfd
, sec
);
7618 unrecord_section_via_map_over_sections (bfd
*abfd ATTRIBUTE_UNUSED
,
7620 void *ignore ATTRIBUTE_UNUSED
)
7622 unrecord_section_with_aarch64_elf_section_data (sec
);
7626 elfNN_aarch64_close_and_cleanup (bfd
*abfd
)
7629 bfd_map_over_sections (abfd
,
7630 unrecord_section_via_map_over_sections
, NULL
);
7632 return _bfd_elf_close_and_cleanup (abfd
);
7636 elfNN_aarch64_bfd_free_cached_info (bfd
*abfd
)
7639 bfd_map_over_sections (abfd
,
7640 unrecord_section_via_map_over_sections
, NULL
);
7642 return _bfd_free_cached_info (abfd
);
7645 /* Create dynamic sections. This is different from the ARM backend in that
7646 the got, plt, gotplt and their relocation sections are all created in the
7647 standard part of the bfd elf backend. */
7650 elfNN_aarch64_create_dynamic_sections (bfd
*dynobj
,
7651 struct bfd_link_info
*info
)
7653 struct elf_aarch64_link_hash_table
*htab
;
7655 /* We need to create .got section. */
7656 if (!aarch64_elf_create_got_section (dynobj
, info
))
7659 if (!_bfd_elf_create_dynamic_sections (dynobj
, info
))
7662 htab
= elf_aarch64_hash_table (info
);
7663 htab
->sdynbss
= bfd_get_linker_section (dynobj
, ".dynbss");
7664 if (!bfd_link_pic (info
))
7665 htab
->srelbss
= bfd_get_linker_section (dynobj
, ".rela.bss");
7667 if (!htab
->sdynbss
|| (!bfd_link_pic (info
) && !htab
->srelbss
))
7674 /* Allocate space in .plt, .got and associated reloc sections for
7678 elfNN_aarch64_allocate_dynrelocs (struct elf_link_hash_entry
*h
, void *inf
)
7680 struct bfd_link_info
*info
;
7681 struct elf_aarch64_link_hash_table
*htab
;
7682 struct elf_aarch64_link_hash_entry
*eh
;
7683 struct elf_dyn_relocs
*p
;
7685 /* An example of a bfd_link_hash_indirect symbol is versioned
7686 symbol. For example: __gxx_personality_v0(bfd_link_hash_indirect)
7687 -> __gxx_personality_v0(bfd_link_hash_defined)
7689 There is no need to process bfd_link_hash_indirect symbols here
7690 because we will also be presented with the concrete instance of
7691 the symbol and elfNN_aarch64_copy_indirect_symbol () will have been
7692 called to copy all relevant data from the generic to the concrete
7695 if (h
->root
.type
== bfd_link_hash_indirect
)
7698 if (h
->root
.type
== bfd_link_hash_warning
)
7699 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
7701 info
= (struct bfd_link_info
*) inf
;
7702 htab
= elf_aarch64_hash_table (info
);
7704 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle it
7705 here if it is defined and referenced in a non-shared object. */
7706 if (h
->type
== STT_GNU_IFUNC
7709 else if (htab
->root
.dynamic_sections_created
&& h
->plt
.refcount
> 0)
7711 /* Make sure this symbol is output as a dynamic symbol.
7712 Undefined weak syms won't yet be marked as dynamic. */
7713 if (h
->dynindx
== -1 && !h
->forced_local
)
7715 if (!bfd_elf_link_record_dynamic_symbol (info
, h
))
7719 if (bfd_link_pic (info
) || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h
))
7721 asection
*s
= htab
->root
.splt
;
7723 /* If this is the first .plt entry, make room for the special
7726 s
->size
+= htab
->plt_header_size
;
7728 h
->plt
.offset
= s
->size
;
7730 /* If this symbol is not defined in a regular file, and we are
7731 not generating a shared library, then set the symbol to this
7732 location in the .plt. This is required to make function
7733 pointers compare as equal between the normal executable and
7734 the shared library. */
7735 if (!bfd_link_pic (info
) && !h
->def_regular
)
7737 h
->root
.u
.def
.section
= s
;
7738 h
->root
.u
.def
.value
= h
->plt
.offset
;
7741 /* Make room for this entry. For now we only create the
7742 small model PLT entries. We later need to find a way
7743 of relaxing into these from the large model PLT entries. */
7744 s
->size
+= PLT_SMALL_ENTRY_SIZE
;
7746 /* We also need to make an entry in the .got.plt section, which
7747 will be placed in the .got section by the linker script. */
7748 htab
->root
.sgotplt
->size
+= GOT_ENTRY_SIZE
;
7750 /* We also need to make an entry in the .rela.plt section. */
7751 htab
->root
.srelplt
->size
+= RELOC_SIZE (htab
);
7753 /* We need to ensure that all GOT entries that serve the PLT
7754 are consecutive with the special GOT slots [0] [1] and
7755 [2]. Any addtional relocations, such as
7756 R_AARCH64_TLSDESC, must be placed after the PLT related
7757 entries. We abuse the reloc_count such that during
7758 sizing we adjust reloc_count to indicate the number of
7759 PLT related reserved entries. In subsequent phases when
7760 filling in the contents of the reloc entries, PLT related
7761 entries are placed by computing their PLT index (0
7762 .. reloc_count). While other none PLT relocs are placed
7763 at the slot indicated by reloc_count and reloc_count is
7766 htab
->root
.srelplt
->reloc_count
++;
7770 h
->plt
.offset
= (bfd_vma
) - 1;
7776 h
->plt
.offset
= (bfd_vma
) - 1;
7780 eh
= (struct elf_aarch64_link_hash_entry
*) h
;
7781 eh
->tlsdesc_got_jump_table_offset
= (bfd_vma
) - 1;
7783 if (h
->got
.refcount
> 0)
7786 unsigned got_type
= elf_aarch64_hash_entry (h
)->got_type
;
7788 h
->got
.offset
= (bfd_vma
) - 1;
7790 dyn
= htab
->root
.dynamic_sections_created
;
7792 /* Make sure this symbol is output as a dynamic symbol.
7793 Undefined weak syms won't yet be marked as dynamic. */
7794 if (dyn
&& h
->dynindx
== -1 && !h
->forced_local
)
7796 if (!bfd_elf_link_record_dynamic_symbol (info
, h
))
7800 if (got_type
== GOT_UNKNOWN
)
7803 else if (got_type
== GOT_NORMAL
)
7805 h
->got
.offset
= htab
->root
.sgot
->size
;
7806 htab
->root
.sgot
->size
+= GOT_ENTRY_SIZE
;
7807 if ((ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
7808 || h
->root
.type
!= bfd_link_hash_undefweak
)
7809 && (bfd_link_pic (info
)
7810 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, 0, h
)))
7812 htab
->root
.srelgot
->size
+= RELOC_SIZE (htab
);
7818 if (got_type
& GOT_TLSDESC_GD
)
7820 eh
->tlsdesc_got_jump_table_offset
=
7821 (htab
->root
.sgotplt
->size
7822 - aarch64_compute_jump_table_size (htab
));
7823 htab
->root
.sgotplt
->size
+= GOT_ENTRY_SIZE
* 2;
7824 h
->got
.offset
= (bfd_vma
) - 2;
7827 if (got_type
& GOT_TLS_GD
)
7829 h
->got
.offset
= htab
->root
.sgot
->size
;
7830 htab
->root
.sgot
->size
+= GOT_ENTRY_SIZE
* 2;
7833 if (got_type
& GOT_TLS_IE
)
7835 h
->got
.offset
= htab
->root
.sgot
->size
;
7836 htab
->root
.sgot
->size
+= GOT_ENTRY_SIZE
;
7839 indx
= h
&& h
->dynindx
!= -1 ? h
->dynindx
: 0;
7840 if ((ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
7841 || h
->root
.type
!= bfd_link_hash_undefweak
)
7842 && (bfd_link_pic (info
)
7844 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, 0, h
)))
7846 if (got_type
& GOT_TLSDESC_GD
)
7848 htab
->root
.srelplt
->size
+= RELOC_SIZE (htab
);
7849 /* Note reloc_count not incremented here! We have
7850 already adjusted reloc_count for this relocation
7853 /* TLSDESC PLT is now needed, but not yet determined. */
7854 htab
->tlsdesc_plt
= (bfd_vma
) - 1;
7857 if (got_type
& GOT_TLS_GD
)
7858 htab
->root
.srelgot
->size
+= RELOC_SIZE (htab
) * 2;
7860 if (got_type
& GOT_TLS_IE
)
7861 htab
->root
.srelgot
->size
+= RELOC_SIZE (htab
);
7867 h
->got
.offset
= (bfd_vma
) - 1;
7870 if (eh
->dyn_relocs
== NULL
)
7873 /* In the shared -Bsymbolic case, discard space allocated for
7874 dynamic pc-relative relocs against symbols which turn out to be
7875 defined in regular objects. For the normal shared case, discard
7876 space for pc-relative relocs that have become local due to symbol
7877 visibility changes. */
7879 if (bfd_link_pic (info
))
7881 /* Relocs that use pc_count are those that appear on a call
7882 insn, or certain REL relocs that can generated via assembly.
7883 We want calls to protected symbols to resolve directly to the
7884 function rather than going via the plt. If people want
7885 function pointer comparisons to work as expected then they
7886 should avoid writing weird assembly. */
7887 if (SYMBOL_CALLS_LOCAL (info
, h
))
7889 struct elf_dyn_relocs
**pp
;
7891 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
;)
7893 p
->count
-= p
->pc_count
;
7902 /* Also discard relocs on undefined weak syms with non-default
7904 if (eh
->dyn_relocs
!= NULL
&& h
->root
.type
== bfd_link_hash_undefweak
)
7906 if (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
)
7907 eh
->dyn_relocs
= NULL
;
7909 /* Make sure undefined weak symbols are output as a dynamic
7911 else if (h
->dynindx
== -1
7913 && !bfd_elf_link_record_dynamic_symbol (info
, h
))
7918 else if (ELIMINATE_COPY_RELOCS
)
7920 /* For the non-shared case, discard space for relocs against
7921 symbols which turn out to need copy relocs or are not
7927 || (htab
->root
.dynamic_sections_created
7928 && (h
->root
.type
== bfd_link_hash_undefweak
7929 || h
->root
.type
== bfd_link_hash_undefined
))))
7931 /* Make sure this symbol is output as a dynamic symbol.
7932 Undefined weak syms won't yet be marked as dynamic. */
7933 if (h
->dynindx
== -1
7935 && !bfd_elf_link_record_dynamic_symbol (info
, h
))
7938 /* If that succeeded, we know we'll be keeping all the
7940 if (h
->dynindx
!= -1)
7944 eh
->dyn_relocs
= NULL
;
7949 /* Finally, allocate space. */
7950 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
7954 sreloc
= elf_section_data (p
->sec
)->sreloc
;
7956 BFD_ASSERT (sreloc
!= NULL
);
7958 sreloc
->size
+= p
->count
* RELOC_SIZE (htab
);
7964 /* Allocate space in .plt, .got and associated reloc sections for
7965 ifunc dynamic relocs. */
7968 elfNN_aarch64_allocate_ifunc_dynrelocs (struct elf_link_hash_entry
*h
,
7971 struct bfd_link_info
*info
;
7972 struct elf_aarch64_link_hash_table
*htab
;
7973 struct elf_aarch64_link_hash_entry
*eh
;
7975 /* An example of a bfd_link_hash_indirect symbol is versioned
7976 symbol. For example: __gxx_personality_v0(bfd_link_hash_indirect)
7977 -> __gxx_personality_v0(bfd_link_hash_defined)
7979 There is no need to process bfd_link_hash_indirect symbols here
7980 because we will also be presented with the concrete instance of
7981 the symbol and elfNN_aarch64_copy_indirect_symbol () will have been
7982 called to copy all relevant data from the generic to the concrete
7985 if (h
->root
.type
== bfd_link_hash_indirect
)
7988 if (h
->root
.type
== bfd_link_hash_warning
)
7989 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
7991 info
= (struct bfd_link_info
*) inf
;
7992 htab
= elf_aarch64_hash_table (info
);
7994 eh
= (struct elf_aarch64_link_hash_entry
*) h
;
7996 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle it
7997 here if it is defined and referenced in a non-shared object. */
7998 if (h
->type
== STT_GNU_IFUNC
8000 return _bfd_elf_allocate_ifunc_dyn_relocs (info
, h
,
8002 htab
->plt_entry_size
,
8003 htab
->plt_header_size
,
8008 /* Allocate space in .plt, .got and associated reloc sections for
8009 local dynamic relocs. */
8012 elfNN_aarch64_allocate_local_dynrelocs (void **slot
, void *inf
)
8014 struct elf_link_hash_entry
*h
8015 = (struct elf_link_hash_entry
*) *slot
;
8017 if (h
->type
!= STT_GNU_IFUNC
8021 || h
->root
.type
!= bfd_link_hash_defined
)
8024 return elfNN_aarch64_allocate_dynrelocs (h
, inf
);
8027 /* Allocate space in .plt, .got and associated reloc sections for
8028 local ifunc dynamic relocs. */
8031 elfNN_aarch64_allocate_local_ifunc_dynrelocs (void **slot
, void *inf
)
8033 struct elf_link_hash_entry
*h
8034 = (struct elf_link_hash_entry
*) *slot
;
8036 if (h
->type
!= STT_GNU_IFUNC
8040 || h
->root
.type
!= bfd_link_hash_defined
)
8043 return elfNN_aarch64_allocate_ifunc_dynrelocs (h
, inf
);
8046 /* Find any dynamic relocs that apply to read-only sections. */
8049 aarch64_readonly_dynrelocs (struct elf_link_hash_entry
* h
, void * inf
)
8051 struct elf_aarch64_link_hash_entry
* eh
;
8052 struct elf_dyn_relocs
* p
;
8054 eh
= (struct elf_aarch64_link_hash_entry
*) h
;
8055 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
8057 asection
*s
= p
->sec
;
8059 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
8061 struct bfd_link_info
*info
= (struct bfd_link_info
*) inf
;
8063 info
->flags
|= DF_TEXTREL
;
8065 /* Not an error, just cut short the traversal. */
8072 /* This is the most important function of all . Innocuosly named
8075 elfNN_aarch64_size_dynamic_sections (bfd
*output_bfd ATTRIBUTE_UNUSED
,
8076 struct bfd_link_info
*info
)
8078 struct elf_aarch64_link_hash_table
*htab
;
8084 htab
= elf_aarch64_hash_table ((info
));
8085 dynobj
= htab
->root
.dynobj
;
8087 BFD_ASSERT (dynobj
!= NULL
);
8089 if (htab
->root
.dynamic_sections_created
)
8091 if (bfd_link_executable (info
) && !info
->nointerp
)
8093 s
= bfd_get_linker_section (dynobj
, ".interp");
8096 s
->size
= sizeof ELF_DYNAMIC_INTERPRETER
;
8097 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
8101 /* Set up .got offsets for local syms, and space for local dynamic
8103 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
8105 struct elf_aarch64_local_symbol
*locals
= NULL
;
8106 Elf_Internal_Shdr
*symtab_hdr
;
8110 if (!is_aarch64_elf (ibfd
))
8113 for (s
= ibfd
->sections
; s
!= NULL
; s
= s
->next
)
8115 struct elf_dyn_relocs
*p
;
8117 for (p
= (struct elf_dyn_relocs
*)
8118 (elf_section_data (s
)->local_dynrel
); p
!= NULL
; p
= p
->next
)
8120 if (!bfd_is_abs_section (p
->sec
)
8121 && bfd_is_abs_section (p
->sec
->output_section
))
8123 /* Input section has been discarded, either because
8124 it is a copy of a linkonce section or due to
8125 linker script /DISCARD/, so we'll be discarding
8128 else if (p
->count
!= 0)
8130 srel
= elf_section_data (p
->sec
)->sreloc
;
8131 srel
->size
+= p
->count
* RELOC_SIZE (htab
);
8132 if ((p
->sec
->output_section
->flags
& SEC_READONLY
) != 0)
8133 info
->flags
|= DF_TEXTREL
;
8138 locals
= elf_aarch64_locals (ibfd
);
8142 symtab_hdr
= &elf_symtab_hdr (ibfd
);
8143 srel
= htab
->root
.srelgot
;
8144 for (i
= 0; i
< symtab_hdr
->sh_info
; i
++)
8146 locals
[i
].got_offset
= (bfd_vma
) - 1;
8147 locals
[i
].tlsdesc_got_jump_table_offset
= (bfd_vma
) - 1;
8148 if (locals
[i
].got_refcount
> 0)
8150 unsigned got_type
= locals
[i
].got_type
;
8151 if (got_type
& GOT_TLSDESC_GD
)
8153 locals
[i
].tlsdesc_got_jump_table_offset
=
8154 (htab
->root
.sgotplt
->size
8155 - aarch64_compute_jump_table_size (htab
));
8156 htab
->root
.sgotplt
->size
+= GOT_ENTRY_SIZE
* 2;
8157 locals
[i
].got_offset
= (bfd_vma
) - 2;
8160 if (got_type
& GOT_TLS_GD
)
8162 locals
[i
].got_offset
= htab
->root
.sgot
->size
;
8163 htab
->root
.sgot
->size
+= GOT_ENTRY_SIZE
* 2;
8166 if (got_type
& GOT_TLS_IE
8167 || got_type
& GOT_NORMAL
)
8169 locals
[i
].got_offset
= htab
->root
.sgot
->size
;
8170 htab
->root
.sgot
->size
+= GOT_ENTRY_SIZE
;
8173 if (got_type
== GOT_UNKNOWN
)
8177 if (bfd_link_pic (info
))
8179 if (got_type
& GOT_TLSDESC_GD
)
8181 htab
->root
.srelplt
->size
+= RELOC_SIZE (htab
);
8182 /* Note RELOC_COUNT not incremented here! */
8183 htab
->tlsdesc_plt
= (bfd_vma
) - 1;
8186 if (got_type
& GOT_TLS_GD
)
8187 htab
->root
.srelgot
->size
+= RELOC_SIZE (htab
) * 2;
8189 if (got_type
& GOT_TLS_IE
8190 || got_type
& GOT_NORMAL
)
8191 htab
->root
.srelgot
->size
+= RELOC_SIZE (htab
);
8196 locals
[i
].got_refcount
= (bfd_vma
) - 1;
8202 /* Allocate global sym .plt and .got entries, and space for global
8203 sym dynamic relocs. */
8204 elf_link_hash_traverse (&htab
->root
, elfNN_aarch64_allocate_dynrelocs
,
8207 /* Allocate global ifunc sym .plt and .got entries, and space for global
8208 ifunc sym dynamic relocs. */
8209 elf_link_hash_traverse (&htab
->root
, elfNN_aarch64_allocate_ifunc_dynrelocs
,
8212 /* Allocate .plt and .got entries, and space for local symbols. */
8213 htab_traverse (htab
->loc_hash_table
,
8214 elfNN_aarch64_allocate_local_dynrelocs
,
8217 /* Allocate .plt and .got entries, and space for local ifunc symbols. */
8218 htab_traverse (htab
->loc_hash_table
,
8219 elfNN_aarch64_allocate_local_ifunc_dynrelocs
,
8222 /* For every jump slot reserved in the sgotplt, reloc_count is
8223 incremented. However, when we reserve space for TLS descriptors,
8224 it's not incremented, so in order to compute the space reserved
8225 for them, it suffices to multiply the reloc count by the jump
8228 if (htab
->root
.srelplt
)
8229 htab
->sgotplt_jump_table_size
= aarch64_compute_jump_table_size (htab
);
8231 if (htab
->tlsdesc_plt
)
8233 if (htab
->root
.splt
->size
== 0)
8234 htab
->root
.splt
->size
+= PLT_ENTRY_SIZE
;
8236 htab
->tlsdesc_plt
= htab
->root
.splt
->size
;
8237 htab
->root
.splt
->size
+= PLT_TLSDESC_ENTRY_SIZE
;
8239 /* If we're not using lazy TLS relocations, don't generate the
8240 GOT entry required. */
8241 if (!(info
->flags
& DF_BIND_NOW
))
8243 htab
->dt_tlsdesc_got
= htab
->root
.sgot
->size
;
8244 htab
->root
.sgot
->size
+= GOT_ENTRY_SIZE
;
8248 /* Init mapping symbols information to use later to distingush between
8249 code and data while scanning for errata. */
8250 if (htab
->fix_erratum_835769
|| htab
->fix_erratum_843419
)
8251 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
8253 if (!is_aarch64_elf (ibfd
))
8255 bfd_elfNN_aarch64_init_maps (ibfd
);
8258 /* We now have determined the sizes of the various dynamic sections.
8259 Allocate memory for them. */
8261 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
8263 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
8266 if (s
== htab
->root
.splt
8267 || s
== htab
->root
.sgot
8268 || s
== htab
->root
.sgotplt
8269 || s
== htab
->root
.iplt
8270 || s
== htab
->root
.igotplt
|| s
== htab
->sdynbss
)
8272 /* Strip this section if we don't need it; see the
8275 else if (CONST_STRNEQ (bfd_get_section_name (dynobj
, s
), ".rela"))
8277 if (s
->size
!= 0 && s
!= htab
->root
.srelplt
)
8280 /* We use the reloc_count field as a counter if we need
8281 to copy relocs into the output file. */
8282 if (s
!= htab
->root
.srelplt
)
8287 /* It's not one of our sections, so don't allocate space. */
8293 /* If we don't need this section, strip it from the
8294 output file. This is mostly to handle .rela.bss and
8295 .rela.plt. We must create both sections in
8296 create_dynamic_sections, because they must be created
8297 before the linker maps input sections to output
8298 sections. The linker does that before
8299 adjust_dynamic_symbol is called, and it is that
8300 function which decides whether anything needs to go
8301 into these sections. */
8303 s
->flags
|= SEC_EXCLUDE
;
8307 if ((s
->flags
& SEC_HAS_CONTENTS
) == 0)
8310 /* Allocate memory for the section contents. We use bfd_zalloc
8311 here in case unused entries are not reclaimed before the
8312 section's contents are written out. This should not happen,
8313 but this way if it does, we get a R_AARCH64_NONE reloc instead
8315 s
->contents
= (bfd_byte
*) bfd_zalloc (dynobj
, s
->size
);
8316 if (s
->contents
== NULL
)
8320 if (htab
->root
.dynamic_sections_created
)
8322 /* Add some entries to the .dynamic section. We fill in the
8323 values later, in elfNN_aarch64_finish_dynamic_sections, but we
8324 must add the entries now so that we get the correct size for
8325 the .dynamic section. The DT_DEBUG entry is filled in by the
8326 dynamic linker and used by the debugger. */
8327 #define add_dynamic_entry(TAG, VAL) \
8328 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
8330 if (bfd_link_executable (info
))
8332 if (!add_dynamic_entry (DT_DEBUG
, 0))
8336 if (htab
->root
.splt
->size
!= 0)
8338 if (!add_dynamic_entry (DT_PLTGOT
, 0)
8339 || !add_dynamic_entry (DT_PLTRELSZ
, 0)
8340 || !add_dynamic_entry (DT_PLTREL
, DT_RELA
)
8341 || !add_dynamic_entry (DT_JMPREL
, 0))
8344 if (htab
->tlsdesc_plt
8345 && (!add_dynamic_entry (DT_TLSDESC_PLT
, 0)
8346 || !add_dynamic_entry (DT_TLSDESC_GOT
, 0)))
8352 if (!add_dynamic_entry (DT_RELA
, 0)
8353 || !add_dynamic_entry (DT_RELASZ
, 0)
8354 || !add_dynamic_entry (DT_RELAENT
, RELOC_SIZE (htab
)))
8357 /* If any dynamic relocs apply to a read-only section,
8358 then we need a DT_TEXTREL entry. */
8359 if ((info
->flags
& DF_TEXTREL
) == 0)
8360 elf_link_hash_traverse (& htab
->root
, aarch64_readonly_dynrelocs
,
8363 if ((info
->flags
& DF_TEXTREL
) != 0)
8365 if (!add_dynamic_entry (DT_TEXTREL
, 0))
8370 #undef add_dynamic_entry
8376 elf_aarch64_update_plt_entry (bfd
*output_bfd
,
8377 bfd_reloc_code_real_type r_type
,
8378 bfd_byte
*plt_entry
, bfd_vma value
)
8380 reloc_howto_type
*howto
= elfNN_aarch64_howto_from_bfd_reloc (r_type
);
8382 _bfd_aarch64_elf_put_addend (output_bfd
, plt_entry
, r_type
, howto
, value
);
8386 elfNN_aarch64_create_small_pltn_entry (struct elf_link_hash_entry
*h
,
8387 struct elf_aarch64_link_hash_table
8388 *htab
, bfd
*output_bfd
,
8389 struct bfd_link_info
*info
)
8391 bfd_byte
*plt_entry
;
8394 bfd_vma gotplt_entry_address
;
8395 bfd_vma plt_entry_address
;
8396 Elf_Internal_Rela rela
;
8398 asection
*plt
, *gotplt
, *relplt
;
8400 /* When building a static executable, use .iplt, .igot.plt and
8401 .rela.iplt sections for STT_GNU_IFUNC symbols. */
8402 if (htab
->root
.splt
!= NULL
)
8404 plt
= htab
->root
.splt
;
8405 gotplt
= htab
->root
.sgotplt
;
8406 relplt
= htab
->root
.srelplt
;
8410 plt
= htab
->root
.iplt
;
8411 gotplt
= htab
->root
.igotplt
;
8412 relplt
= htab
->root
.irelplt
;
8415 /* Get the index in the procedure linkage table which
8416 corresponds to this symbol. This is the index of this symbol
8417 in all the symbols for which we are making plt entries. The
8418 first entry in the procedure linkage table is reserved.
8420 Get the offset into the .got table of the entry that
8421 corresponds to this function. Each .got entry is GOT_ENTRY_SIZE
8422 bytes. The first three are reserved for the dynamic linker.
8424 For static executables, we don't reserve anything. */
8426 if (plt
== htab
->root
.splt
)
8428 plt_index
= (h
->plt
.offset
- htab
->plt_header_size
) / htab
->plt_entry_size
;
8429 got_offset
= (plt_index
+ 3) * GOT_ENTRY_SIZE
;
8433 plt_index
= h
->plt
.offset
/ htab
->plt_entry_size
;
8434 got_offset
= plt_index
* GOT_ENTRY_SIZE
;
8437 plt_entry
= plt
->contents
+ h
->plt
.offset
;
8438 plt_entry_address
= plt
->output_section
->vma
8439 + plt
->output_offset
+ h
->plt
.offset
;
8440 gotplt_entry_address
= gotplt
->output_section
->vma
+
8441 gotplt
->output_offset
+ got_offset
;
8443 /* Copy in the boiler-plate for the PLTn entry. */
8444 memcpy (plt_entry
, elfNN_aarch64_small_plt_entry
, PLT_SMALL_ENTRY_SIZE
);
8446 /* Fill in the top 21 bits for this: ADRP x16, PLT_GOT + n * 8.
8447 ADRP: ((PG(S+A)-PG(P)) >> 12) & 0x1fffff */
8448 elf_aarch64_update_plt_entry (output_bfd
, BFD_RELOC_AARCH64_ADR_HI21_PCREL
,
8450 PG (gotplt_entry_address
) -
8451 PG (plt_entry_address
));
8453 /* Fill in the lo12 bits for the load from the pltgot. */
8454 elf_aarch64_update_plt_entry (output_bfd
, BFD_RELOC_AARCH64_LDSTNN_LO12
,
8456 PG_OFFSET (gotplt_entry_address
));
8458 /* Fill in the lo12 bits for the add from the pltgot entry. */
8459 elf_aarch64_update_plt_entry (output_bfd
, BFD_RELOC_AARCH64_ADD_LO12
,
8461 PG_OFFSET (gotplt_entry_address
));
8463 /* All the GOTPLT Entries are essentially initialized to PLT0. */
8464 bfd_put_NN (output_bfd
,
8465 plt
->output_section
->vma
+ plt
->output_offset
,
8466 gotplt
->contents
+ got_offset
);
8468 rela
.r_offset
= gotplt_entry_address
;
8470 if (h
->dynindx
== -1
8471 || ((bfd_link_executable (info
)
8472 || ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
)
8474 && h
->type
== STT_GNU_IFUNC
))
8476 /* If an STT_GNU_IFUNC symbol is locally defined, generate
8477 R_AARCH64_IRELATIVE instead of R_AARCH64_JUMP_SLOT. */
8478 rela
.r_info
= ELFNN_R_INFO (0, AARCH64_R (IRELATIVE
));
8479 rela
.r_addend
= (h
->root
.u
.def
.value
8480 + h
->root
.u
.def
.section
->output_section
->vma
8481 + h
->root
.u
.def
.section
->output_offset
);
8485 /* Fill in the entry in the .rela.plt section. */
8486 rela
.r_info
= ELFNN_R_INFO (h
->dynindx
, AARCH64_R (JUMP_SLOT
));
8490 /* Compute the relocation entry to used based on PLT index and do
8491 not adjust reloc_count. The reloc_count has already been adjusted
8492 to account for this entry. */
8493 loc
= relplt
->contents
+ plt_index
* RELOC_SIZE (htab
);
8494 bfd_elfNN_swap_reloca_out (output_bfd
, &rela
, loc
);
8497 /* Size sections even though they're not dynamic. We use it to setup
8498 _TLS_MODULE_BASE_, if needed. */
8501 elfNN_aarch64_always_size_sections (bfd
*output_bfd
,
8502 struct bfd_link_info
*info
)
8506 if (bfd_link_relocatable (info
))
8509 tls_sec
= elf_hash_table (info
)->tls_sec
;
8513 struct elf_link_hash_entry
*tlsbase
;
8515 tlsbase
= elf_link_hash_lookup (elf_hash_table (info
),
8516 "_TLS_MODULE_BASE_", TRUE
, TRUE
, FALSE
);
8520 struct bfd_link_hash_entry
*h
= NULL
;
8521 const struct elf_backend_data
*bed
=
8522 get_elf_backend_data (output_bfd
);
8524 if (!(_bfd_generic_link_add_one_symbol
8525 (info
, output_bfd
, "_TLS_MODULE_BASE_", BSF_LOCAL
,
8526 tls_sec
, 0, NULL
, FALSE
, bed
->collect
, &h
)))
8529 tlsbase
->type
= STT_TLS
;
8530 tlsbase
= (struct elf_link_hash_entry
*) h
;
8531 tlsbase
->def_regular
= 1;
8532 tlsbase
->other
= STV_HIDDEN
;
8533 (*bed
->elf_backend_hide_symbol
) (info
, tlsbase
, TRUE
);
8540 /* Finish up dynamic symbol handling. We set the contents of various
8541 dynamic sections here. */
8543 elfNN_aarch64_finish_dynamic_symbol (bfd
*output_bfd
,
8544 struct bfd_link_info
*info
,
8545 struct elf_link_hash_entry
*h
,
8546 Elf_Internal_Sym
*sym
)
8548 struct elf_aarch64_link_hash_table
*htab
;
8549 htab
= elf_aarch64_hash_table (info
);
8551 if (h
->plt
.offset
!= (bfd_vma
) - 1)
8553 asection
*plt
, *gotplt
, *relplt
;
8555 /* This symbol has an entry in the procedure linkage table. Set
8558 /* When building a static executable, use .iplt, .igot.plt and
8559 .rela.iplt sections for STT_GNU_IFUNC symbols. */
8560 if (htab
->root
.splt
!= NULL
)
8562 plt
= htab
->root
.splt
;
8563 gotplt
= htab
->root
.sgotplt
;
8564 relplt
= htab
->root
.srelplt
;
8568 plt
= htab
->root
.iplt
;
8569 gotplt
= htab
->root
.igotplt
;
8570 relplt
= htab
->root
.irelplt
;
8573 /* This symbol has an entry in the procedure linkage table. Set
8575 if ((h
->dynindx
== -1
8576 && !((h
->forced_local
|| bfd_link_executable (info
))
8578 && h
->type
== STT_GNU_IFUNC
))
8584 elfNN_aarch64_create_small_pltn_entry (h
, htab
, output_bfd
, info
);
8585 if (!h
->def_regular
)
8587 /* Mark the symbol as undefined, rather than as defined in
8588 the .plt section. */
8589 sym
->st_shndx
= SHN_UNDEF
;
8590 /* If the symbol is weak we need to clear the value.
8591 Otherwise, the PLT entry would provide a definition for
8592 the symbol even if the symbol wasn't defined anywhere,
8593 and so the symbol would never be NULL. Leave the value if
8594 there were any relocations where pointer equality matters
8595 (this is a clue for the dynamic linker, to make function
8596 pointer comparisons work between an application and shared
8598 if (!h
->ref_regular_nonweak
|| !h
->pointer_equality_needed
)
8603 if (h
->got
.offset
!= (bfd_vma
) - 1
8604 && elf_aarch64_hash_entry (h
)->got_type
== GOT_NORMAL
)
8606 Elf_Internal_Rela rela
;
8609 /* This symbol has an entry in the global offset table. Set it
8611 if (htab
->root
.sgot
== NULL
|| htab
->root
.srelgot
== NULL
)
8614 rela
.r_offset
= (htab
->root
.sgot
->output_section
->vma
8615 + htab
->root
.sgot
->output_offset
8616 + (h
->got
.offset
& ~(bfd_vma
) 1));
8619 && h
->type
== STT_GNU_IFUNC
)
8621 if (bfd_link_pic (info
))
8623 /* Generate R_AARCH64_GLOB_DAT. */
8630 if (!h
->pointer_equality_needed
)
8633 /* For non-shared object, we can't use .got.plt, which
8634 contains the real function address if we need pointer
8635 equality. We load the GOT entry with the PLT entry. */
8636 plt
= htab
->root
.splt
? htab
->root
.splt
: htab
->root
.iplt
;
8637 bfd_put_NN (output_bfd
, (plt
->output_section
->vma
8638 + plt
->output_offset
8640 htab
->root
.sgot
->contents
8641 + (h
->got
.offset
& ~(bfd_vma
) 1));
8645 else if (bfd_link_pic (info
) && SYMBOL_REFERENCES_LOCAL (info
, h
))
8647 if (!h
->def_regular
)
8650 BFD_ASSERT ((h
->got
.offset
& 1) != 0);
8651 rela
.r_info
= ELFNN_R_INFO (0, AARCH64_R (RELATIVE
));
8652 rela
.r_addend
= (h
->root
.u
.def
.value
8653 + h
->root
.u
.def
.section
->output_section
->vma
8654 + h
->root
.u
.def
.section
->output_offset
);
8659 BFD_ASSERT ((h
->got
.offset
& 1) == 0);
8660 bfd_put_NN (output_bfd
, (bfd_vma
) 0,
8661 htab
->root
.sgot
->contents
+ h
->got
.offset
);
8662 rela
.r_info
= ELFNN_R_INFO (h
->dynindx
, AARCH64_R (GLOB_DAT
));
8666 loc
= htab
->root
.srelgot
->contents
;
8667 loc
+= htab
->root
.srelgot
->reloc_count
++ * RELOC_SIZE (htab
);
8668 bfd_elfNN_swap_reloca_out (output_bfd
, &rela
, loc
);
8673 Elf_Internal_Rela rela
;
8676 /* This symbol needs a copy reloc. Set it up. */
8678 if (h
->dynindx
== -1
8679 || (h
->root
.type
!= bfd_link_hash_defined
8680 && h
->root
.type
!= bfd_link_hash_defweak
)
8681 || htab
->srelbss
== NULL
)
8684 rela
.r_offset
= (h
->root
.u
.def
.value
8685 + h
->root
.u
.def
.section
->output_section
->vma
8686 + h
->root
.u
.def
.section
->output_offset
);
8687 rela
.r_info
= ELFNN_R_INFO (h
->dynindx
, AARCH64_R (COPY
));
8689 loc
= htab
->srelbss
->contents
;
8690 loc
+= htab
->srelbss
->reloc_count
++ * RELOC_SIZE (htab
);
8691 bfd_elfNN_swap_reloca_out (output_bfd
, &rela
, loc
);
8694 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. SYM may
8695 be NULL for local symbols. */
8697 && (h
== elf_hash_table (info
)->hdynamic
8698 || h
== elf_hash_table (info
)->hgot
))
8699 sym
->st_shndx
= SHN_ABS
;
8704 /* Finish up local dynamic symbol handling. We set the contents of
8705 various dynamic sections here. */
8708 elfNN_aarch64_finish_local_dynamic_symbol (void **slot
, void *inf
)
8710 struct elf_link_hash_entry
*h
8711 = (struct elf_link_hash_entry
*) *slot
;
8712 struct bfd_link_info
*info
8713 = (struct bfd_link_info
*) inf
;
8715 return elfNN_aarch64_finish_dynamic_symbol (info
->output_bfd
,
8720 elfNN_aarch64_init_small_plt0_entry (bfd
*output_bfd ATTRIBUTE_UNUSED
,
8721 struct elf_aarch64_link_hash_table
8724 /* Fill in PLT0. Fixme:RR Note this doesn't distinguish between
8725 small and large plts and at the minute just generates
8728 /* PLT0 of the small PLT looks like this in ELF64 -
8729 stp x16, x30, [sp, #-16]! // Save the reloc and lr on stack.
8730 adrp x16, PLT_GOT + 16 // Get the page base of the GOTPLT
8731 ldr x17, [x16, #:lo12:PLT_GOT+16] // Load the address of the
8733 add x16, x16, #:lo12:PLT_GOT+16 // Load the lo12 bits of the
8734 // GOTPLT entry for this.
8736 PLT0 will be slightly different in ELF32 due to different got entry
8739 bfd_vma plt_got_2nd_ent
; /* Address of GOT[2]. */
8743 memcpy (htab
->root
.splt
->contents
, elfNN_aarch64_small_plt0_entry
,
8745 elf_section_data (htab
->root
.splt
->output_section
)->this_hdr
.sh_entsize
=
8748 plt_got_2nd_ent
= (htab
->root
.sgotplt
->output_section
->vma
8749 + htab
->root
.sgotplt
->output_offset
8750 + GOT_ENTRY_SIZE
* 2);
8752 plt_base
= htab
->root
.splt
->output_section
->vma
+
8753 htab
->root
.splt
->output_offset
;
8755 /* Fill in the top 21 bits for this: ADRP x16, PLT_GOT + n * 8.
8756 ADRP: ((PG(S+A)-PG(P)) >> 12) & 0x1fffff */
8757 elf_aarch64_update_plt_entry (output_bfd
, BFD_RELOC_AARCH64_ADR_HI21_PCREL
,
8758 htab
->root
.splt
->contents
+ 4,
8759 PG (plt_got_2nd_ent
) - PG (plt_base
+ 4));
8761 elf_aarch64_update_plt_entry (output_bfd
, BFD_RELOC_AARCH64_LDSTNN_LO12
,
8762 htab
->root
.splt
->contents
+ 8,
8763 PG_OFFSET (plt_got_2nd_ent
));
8765 elf_aarch64_update_plt_entry (output_bfd
, BFD_RELOC_AARCH64_ADD_LO12
,
8766 htab
->root
.splt
->contents
+ 12,
8767 PG_OFFSET (plt_got_2nd_ent
));
8771 elfNN_aarch64_finish_dynamic_sections (bfd
*output_bfd
,
8772 struct bfd_link_info
*info
)
8774 struct elf_aarch64_link_hash_table
*htab
;
8778 htab
= elf_aarch64_hash_table (info
);
8779 dynobj
= htab
->root
.dynobj
;
8780 sdyn
= bfd_get_linker_section (dynobj
, ".dynamic");
8782 if (htab
->root
.dynamic_sections_created
)
8784 ElfNN_External_Dyn
*dyncon
, *dynconend
;
8786 if (sdyn
== NULL
|| htab
->root
.sgot
== NULL
)
8789 dyncon
= (ElfNN_External_Dyn
*) sdyn
->contents
;
8790 dynconend
= (ElfNN_External_Dyn
*) (sdyn
->contents
+ sdyn
->size
);
8791 for (; dyncon
< dynconend
; dyncon
++)
8793 Elf_Internal_Dyn dyn
;
8796 bfd_elfNN_swap_dyn_in (dynobj
, dyncon
, &dyn
);
8804 s
= htab
->root
.sgotplt
;
8805 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
8809 dyn
.d_un
.d_ptr
= htab
->root
.srelplt
->output_section
->vma
;
8813 s
= htab
->root
.srelplt
;
8814 dyn
.d_un
.d_val
= s
->size
;
8818 /* The procedure linkage table relocs (DT_JMPREL) should
8819 not be included in the overall relocs (DT_RELA).
8820 Therefore, we override the DT_RELASZ entry here to
8821 make it not include the JMPREL relocs. Since the
8822 linker script arranges for .rela.plt to follow all
8823 other relocation sections, we don't have to worry
8824 about changing the DT_RELA entry. */
8825 if (htab
->root
.srelplt
!= NULL
)
8827 s
= htab
->root
.srelplt
;
8828 dyn
.d_un
.d_val
-= s
->size
;
8832 case DT_TLSDESC_PLT
:
8833 s
= htab
->root
.splt
;
8834 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
8835 + htab
->tlsdesc_plt
;
8838 case DT_TLSDESC_GOT
:
8839 s
= htab
->root
.sgot
;
8840 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
8841 + htab
->dt_tlsdesc_got
;
8845 bfd_elfNN_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
8850 /* Fill in the special first entry in the procedure linkage table. */
8851 if (htab
->root
.splt
&& htab
->root
.splt
->size
> 0)
8853 elfNN_aarch64_init_small_plt0_entry (output_bfd
, htab
);
8855 elf_section_data (htab
->root
.splt
->output_section
)->
8856 this_hdr
.sh_entsize
= htab
->plt_entry_size
;
8859 if (htab
->tlsdesc_plt
)
8861 bfd_put_NN (output_bfd
, (bfd_vma
) 0,
8862 htab
->root
.sgot
->contents
+ htab
->dt_tlsdesc_got
);
8864 memcpy (htab
->root
.splt
->contents
+ htab
->tlsdesc_plt
,
8865 elfNN_aarch64_tlsdesc_small_plt_entry
,
8866 sizeof (elfNN_aarch64_tlsdesc_small_plt_entry
));
8869 bfd_vma adrp1_addr
=
8870 htab
->root
.splt
->output_section
->vma
8871 + htab
->root
.splt
->output_offset
+ htab
->tlsdesc_plt
+ 4;
8873 bfd_vma adrp2_addr
= adrp1_addr
+ 4;
8876 htab
->root
.sgot
->output_section
->vma
8877 + htab
->root
.sgot
->output_offset
;
8879 bfd_vma pltgot_addr
=
8880 htab
->root
.sgotplt
->output_section
->vma
8881 + htab
->root
.sgotplt
->output_offset
;
8883 bfd_vma dt_tlsdesc_got
= got_addr
+ htab
->dt_tlsdesc_got
;
8885 bfd_byte
*plt_entry
=
8886 htab
->root
.splt
->contents
+ htab
->tlsdesc_plt
;
8888 /* adrp x2, DT_TLSDESC_GOT */
8889 elf_aarch64_update_plt_entry (output_bfd
,
8890 BFD_RELOC_AARCH64_ADR_HI21_PCREL
,
8892 (PG (dt_tlsdesc_got
)
8893 - PG (adrp1_addr
)));
8896 elf_aarch64_update_plt_entry (output_bfd
,
8897 BFD_RELOC_AARCH64_ADR_HI21_PCREL
,
8900 - PG (adrp2_addr
)));
8902 /* ldr x2, [x2, #0] */
8903 elf_aarch64_update_plt_entry (output_bfd
,
8904 BFD_RELOC_AARCH64_LDSTNN_LO12
,
8906 PG_OFFSET (dt_tlsdesc_got
));
8909 elf_aarch64_update_plt_entry (output_bfd
,
8910 BFD_RELOC_AARCH64_ADD_LO12
,
8912 PG_OFFSET (pltgot_addr
));
8917 if (htab
->root
.sgotplt
)
8919 if (bfd_is_abs_section (htab
->root
.sgotplt
->output_section
))
8921 (*_bfd_error_handler
)
8922 (_("discarded output section: `%A'"), htab
->root
.sgotplt
);
8926 /* Fill in the first three entries in the global offset table. */
8927 if (htab
->root
.sgotplt
->size
> 0)
8929 bfd_put_NN (output_bfd
, (bfd_vma
) 0, htab
->root
.sgotplt
->contents
);
8931 /* Write GOT[1] and GOT[2], needed for the dynamic linker. */
8932 bfd_put_NN (output_bfd
,
8934 htab
->root
.sgotplt
->contents
+ GOT_ENTRY_SIZE
);
8935 bfd_put_NN (output_bfd
,
8937 htab
->root
.sgotplt
->contents
+ GOT_ENTRY_SIZE
* 2);
8940 if (htab
->root
.sgot
)
8942 if (htab
->root
.sgot
->size
> 0)
8945 sdyn
? sdyn
->output_section
->vma
+ sdyn
->output_offset
: 0;
8946 bfd_put_NN (output_bfd
, addr
, htab
->root
.sgot
->contents
);
8950 elf_section_data (htab
->root
.sgotplt
->output_section
)->
8951 this_hdr
.sh_entsize
= GOT_ENTRY_SIZE
;
8954 if (htab
->root
.sgot
&& htab
->root
.sgot
->size
> 0)
8955 elf_section_data (htab
->root
.sgot
->output_section
)->this_hdr
.sh_entsize
8958 /* Fill PLT and GOT entries for local STT_GNU_IFUNC symbols. */
8959 htab_traverse (htab
->loc_hash_table
,
8960 elfNN_aarch64_finish_local_dynamic_symbol
,
8966 /* Return address for Ith PLT stub in section PLT, for relocation REL
8967 or (bfd_vma) -1 if it should not be included. */
8970 elfNN_aarch64_plt_sym_val (bfd_vma i
, const asection
*plt
,
8971 const arelent
*rel ATTRIBUTE_UNUSED
)
8973 return plt
->vma
+ PLT_ENTRY_SIZE
+ i
* PLT_SMALL_ENTRY_SIZE
;
8977 /* We use this so we can override certain functions
8978 (though currently we don't). */
8980 const struct elf_size_info elfNN_aarch64_size_info
=
8982 sizeof (ElfNN_External_Ehdr
),
8983 sizeof (ElfNN_External_Phdr
),
8984 sizeof (ElfNN_External_Shdr
),
8985 sizeof (ElfNN_External_Rel
),
8986 sizeof (ElfNN_External_Rela
),
8987 sizeof (ElfNN_External_Sym
),
8988 sizeof (ElfNN_External_Dyn
),
8989 sizeof (Elf_External_Note
),
8990 4, /* Hash table entry size. */
8991 1, /* Internal relocs per external relocs. */
8992 ARCH_SIZE
, /* Arch size. */
8993 LOG_FILE_ALIGN
, /* Log_file_align. */
8994 ELFCLASSNN
, EV_CURRENT
,
8995 bfd_elfNN_write_out_phdrs
,
8996 bfd_elfNN_write_shdrs_and_ehdr
,
8997 bfd_elfNN_checksum_contents
,
8998 bfd_elfNN_write_relocs
,
8999 bfd_elfNN_swap_symbol_in
,
9000 bfd_elfNN_swap_symbol_out
,
9001 bfd_elfNN_slurp_reloc_table
,
9002 bfd_elfNN_slurp_symbol_table
,
9003 bfd_elfNN_swap_dyn_in
,
9004 bfd_elfNN_swap_dyn_out
,
9005 bfd_elfNN_swap_reloc_in
,
9006 bfd_elfNN_swap_reloc_out
,
9007 bfd_elfNN_swap_reloca_in
,
9008 bfd_elfNN_swap_reloca_out
9011 #define ELF_ARCH bfd_arch_aarch64
9012 #define ELF_MACHINE_CODE EM_AARCH64
9013 #define ELF_MAXPAGESIZE 0x10000
9014 #define ELF_MINPAGESIZE 0x1000
9015 #define ELF_COMMONPAGESIZE 0x1000
9017 #define bfd_elfNN_close_and_cleanup \
9018 elfNN_aarch64_close_and_cleanup
9020 #define bfd_elfNN_bfd_free_cached_info \
9021 elfNN_aarch64_bfd_free_cached_info
9023 #define bfd_elfNN_bfd_is_target_special_symbol \
9024 elfNN_aarch64_is_target_special_symbol
9026 #define bfd_elfNN_bfd_link_hash_table_create \
9027 elfNN_aarch64_link_hash_table_create
9029 #define bfd_elfNN_bfd_merge_private_bfd_data \
9030 elfNN_aarch64_merge_private_bfd_data
9032 #define bfd_elfNN_bfd_print_private_bfd_data \
9033 elfNN_aarch64_print_private_bfd_data
9035 #define bfd_elfNN_bfd_reloc_type_lookup \
9036 elfNN_aarch64_reloc_type_lookup
9038 #define bfd_elfNN_bfd_reloc_name_lookup \
9039 elfNN_aarch64_reloc_name_lookup
9041 #define bfd_elfNN_bfd_set_private_flags \
9042 elfNN_aarch64_set_private_flags
9044 #define bfd_elfNN_find_inliner_info \
9045 elfNN_aarch64_find_inliner_info
9047 #define bfd_elfNN_find_nearest_line \
9048 elfNN_aarch64_find_nearest_line
9050 #define bfd_elfNN_mkobject \
9051 elfNN_aarch64_mkobject
9053 #define bfd_elfNN_new_section_hook \
9054 elfNN_aarch64_new_section_hook
9056 #define elf_backend_adjust_dynamic_symbol \
9057 elfNN_aarch64_adjust_dynamic_symbol
9059 #define elf_backend_always_size_sections \
9060 elfNN_aarch64_always_size_sections
9062 #define elf_backend_check_relocs \
9063 elfNN_aarch64_check_relocs
9065 #define elf_backend_copy_indirect_symbol \
9066 elfNN_aarch64_copy_indirect_symbol
9068 /* Create .dynbss, and .rela.bss sections in DYNOBJ, and set up shortcuts
9069 to them in our hash. */
9070 #define elf_backend_create_dynamic_sections \
9071 elfNN_aarch64_create_dynamic_sections
9073 #define elf_backend_init_index_section \
9074 _bfd_elf_init_2_index_sections
9076 #define elf_backend_finish_dynamic_sections \
9077 elfNN_aarch64_finish_dynamic_sections
9079 #define elf_backend_finish_dynamic_symbol \
9080 elfNN_aarch64_finish_dynamic_symbol
9082 #define elf_backend_gc_sweep_hook \
9083 elfNN_aarch64_gc_sweep_hook
9085 #define elf_backend_object_p \
9086 elfNN_aarch64_object_p
9088 #define elf_backend_output_arch_local_syms \
9089 elfNN_aarch64_output_arch_local_syms
9091 #define elf_backend_plt_sym_val \
9092 elfNN_aarch64_plt_sym_val
9094 #define elf_backend_post_process_headers \
9095 elfNN_aarch64_post_process_headers
9097 #define elf_backend_relocate_section \
9098 elfNN_aarch64_relocate_section
9100 #define elf_backend_reloc_type_class \
9101 elfNN_aarch64_reloc_type_class
9103 #define elf_backend_section_from_shdr \
9104 elfNN_aarch64_section_from_shdr
9106 #define elf_backend_size_dynamic_sections \
9107 elfNN_aarch64_size_dynamic_sections
9109 #define elf_backend_size_info \
9110 elfNN_aarch64_size_info
9112 #define elf_backend_write_section \
9113 elfNN_aarch64_write_section
9115 #define elf_backend_can_refcount 1
9116 #define elf_backend_can_gc_sections 1
9117 #define elf_backend_plt_readonly 1
9118 #define elf_backend_want_got_plt 1
9119 #define elf_backend_want_plt_sym 0
9120 #define elf_backend_may_use_rel_p 0
9121 #define elf_backend_may_use_rela_p 1
9122 #define elf_backend_default_use_rela_p 1
9123 #define elf_backend_rela_normal 1
9124 #define elf_backend_got_header_size (GOT_ENTRY_SIZE * 3)
9125 #define elf_backend_default_execstack 0
9126 #define elf_backend_extern_protected_data 1
9128 #undef elf_backend_obj_attrs_section
9129 #define elf_backend_obj_attrs_section ".ARM.attributes"
9131 #include "elfNN-target.h"