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_G0_NC \
172 || (R_TYPE) == BFD_RELOC_AARCH64_TLSGD_MOVW_G1 \
173 || (R_TYPE) == BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21 \
174 || (R_TYPE) == BFD_RELOC_AARCH64_TLSIE_LD32_GOTTPREL_LO12_NC \
175 || (R_TYPE) == BFD_RELOC_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC \
176 || (R_TYPE) == BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19 \
177 || (R_TYPE) == BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G0_NC \
178 || (R_TYPE) == BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G1 \
179 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_ADD_DTPREL_HI12 \
180 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_ADD_DTPREL_LO12 \
181 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_ADD_DTPREL_LO12_NC \
182 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC \
183 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21 \
184 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_ADR_PREL21 \
185 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_LDST16_DTPREL_LO12 \
186 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_LDST16_DTPREL_LO12_NC \
187 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_LDST32_DTPREL_LO12 \
188 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_LDST32_DTPREL_LO12_NC \
189 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_LDST64_DTPREL_LO12 \
190 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_LDST64_DTPREL_LO12_NC \
191 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_LDST8_DTPREL_LO12 \
192 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_LDST8_DTPREL_LO12_NC \
193 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G0 \
194 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G0_NC \
195 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G1 \
196 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G1_NC \
197 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G2 \
198 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_HI12 \
199 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_LO12 \
200 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_LO12_NC \
201 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0 \
202 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC \
203 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1 \
204 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1_NC \
205 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G2 \
206 || (R_TYPE) == BFD_RELOC_AARCH64_TLS_DTPMOD \
207 || (R_TYPE) == BFD_RELOC_AARCH64_TLS_DTPREL \
208 || (R_TYPE) == BFD_RELOC_AARCH64_TLS_TPREL \
209 || IS_AARCH64_TLSDESC_RELOC ((R_TYPE)))
211 #define IS_AARCH64_TLS_RELAX_RELOC(R_TYPE) \
212 ((R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_ADD_LO12_NC \
213 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21 \
214 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21 \
215 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_CALL \
216 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_LD_PREL19 \
217 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_LDNN_LO12_NC \
218 || (R_TYPE) == BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21 \
219 || (R_TYPE) == BFD_RELOC_AARCH64_TLSGD_ADR_PREL21 \
220 || (R_TYPE) == BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC \
221 || (R_TYPE) == BFD_RELOC_AARCH64_TLSGD_MOVW_G0_NC \
222 || (R_TYPE) == BFD_RELOC_AARCH64_TLSGD_MOVW_G1 \
223 || (R_TYPE) == BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21 \
224 || (R_TYPE) == BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19 \
225 || (R_TYPE) == BFD_RELOC_AARCH64_TLSIE_LDNN_GOTTPREL_LO12_NC \
226 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC \
227 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21 \
228 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_ADR_PREL21)
230 #define IS_AARCH64_TLSDESC_RELOC(R_TYPE) \
231 ((R_TYPE) == BFD_RELOC_AARCH64_TLSDESC \
232 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_ADD \
233 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_ADD_LO12_NC \
234 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21 \
235 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21 \
236 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_CALL \
237 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_LD32_LO12_NC \
238 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_LD64_LO12_NC \
239 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_LDR \
240 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_LD_PREL19 \
241 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_OFF_G0_NC \
242 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_OFF_G1)
244 #define ELIMINATE_COPY_RELOCS 0
246 /* Return size of a relocation entry. HTAB is the bfd's
247 elf_aarch64_link_hash_entry. */
248 #define RELOC_SIZE(HTAB) (sizeof (ElfNN_External_Rela))
250 /* GOT Entry size - 8 bytes in ELF64 and 4 bytes in ELF32. */
251 #define GOT_ENTRY_SIZE (ARCH_SIZE / 8)
252 #define PLT_ENTRY_SIZE (32)
253 #define PLT_SMALL_ENTRY_SIZE (16)
254 #define PLT_TLSDESC_ENTRY_SIZE (32)
256 /* Encoding of the nop instruction */
257 #define INSN_NOP 0xd503201f
259 #define aarch64_compute_jump_table_size(htab) \
260 (((htab)->root.srelplt == NULL) ? 0 \
261 : (htab)->root.srelplt->reloc_count * GOT_ENTRY_SIZE)
263 /* The first entry in a procedure linkage table looks like this
264 if the distance between the PLTGOT and the PLT is < 4GB use
265 these PLT entries. Note that the dynamic linker gets &PLTGOT[2]
266 in x16 and needs to work out PLTGOT[1] by using an address of
267 [x16,#-GOT_ENTRY_SIZE]. */
268 static const bfd_byte elfNN_aarch64_small_plt0_entry
[PLT_ENTRY_SIZE
] =
270 0xf0, 0x7b, 0xbf, 0xa9, /* stp x16, x30, [sp, #-16]! */
271 0x10, 0x00, 0x00, 0x90, /* adrp x16, (GOT+16) */
273 0x11, 0x0A, 0x40, 0xf9, /* ldr x17, [x16, #PLT_GOT+0x10] */
274 0x10, 0x42, 0x00, 0x91, /* add x16, x16,#PLT_GOT+0x10 */
276 0x11, 0x0A, 0x40, 0xb9, /* ldr w17, [x16, #PLT_GOT+0x8] */
277 0x10, 0x22, 0x00, 0x11, /* add w16, w16,#PLT_GOT+0x8 */
279 0x20, 0x02, 0x1f, 0xd6, /* br x17 */
280 0x1f, 0x20, 0x03, 0xd5, /* nop */
281 0x1f, 0x20, 0x03, 0xd5, /* nop */
282 0x1f, 0x20, 0x03, 0xd5, /* nop */
285 /* Per function entry in a procedure linkage table looks like this
286 if the distance between the PLTGOT and the PLT is < 4GB use
287 these PLT entries. */
288 static const bfd_byte elfNN_aarch64_small_plt_entry
[PLT_SMALL_ENTRY_SIZE
] =
290 0x10, 0x00, 0x00, 0x90, /* adrp x16, PLTGOT + n * 8 */
292 0x11, 0x02, 0x40, 0xf9, /* ldr x17, [x16, PLTGOT + n * 8] */
293 0x10, 0x02, 0x00, 0x91, /* add x16, x16, :lo12:PLTGOT + n * 8 */
295 0x11, 0x02, 0x40, 0xb9, /* ldr w17, [x16, PLTGOT + n * 4] */
296 0x10, 0x02, 0x00, 0x11, /* add w16, w16, :lo12:PLTGOT + n * 4 */
298 0x20, 0x02, 0x1f, 0xd6, /* br x17. */
301 static const bfd_byte
302 elfNN_aarch64_tlsdesc_small_plt_entry
[PLT_TLSDESC_ENTRY_SIZE
] =
304 0xe2, 0x0f, 0xbf, 0xa9, /* stp x2, x3, [sp, #-16]! */
305 0x02, 0x00, 0x00, 0x90, /* adrp x2, 0 */
306 0x03, 0x00, 0x00, 0x90, /* adrp x3, 0 */
308 0x42, 0x00, 0x40, 0xf9, /* ldr x2, [x2, #0] */
309 0x63, 0x00, 0x00, 0x91, /* add x3, x3, 0 */
311 0x42, 0x00, 0x40, 0xb9, /* ldr w2, [x2, #0] */
312 0x63, 0x00, 0x00, 0x11, /* add w3, w3, 0 */
314 0x40, 0x00, 0x1f, 0xd6, /* br x2 */
315 0x1f, 0x20, 0x03, 0xd5, /* nop */
316 0x1f, 0x20, 0x03, 0xd5, /* nop */
319 #define elf_info_to_howto elfNN_aarch64_info_to_howto
320 #define elf_info_to_howto_rel elfNN_aarch64_info_to_howto
322 #define AARCH64_ELF_ABI_VERSION 0
324 /* In case we're on a 32-bit machine, construct a 64-bit "-1" value. */
325 #define ALL_ONES (~ (bfd_vma) 0)
327 /* Indexed by the bfd interal reloc enumerators.
328 Therefore, the table needs to be synced with BFD_RELOC_AARCH64_*
331 static reloc_howto_type elfNN_aarch64_howto_table
[] =
335 /* Basic data relocations. */
338 HOWTO (R_AARCH64_NULL
, /* type */
340 3, /* size (0 = byte, 1 = short, 2 = long) */
342 FALSE
, /* pc_relative */
344 complain_overflow_dont
, /* complain_on_overflow */
345 bfd_elf_generic_reloc
, /* special_function */
346 "R_AARCH64_NULL", /* name */
347 FALSE
, /* partial_inplace */
350 FALSE
), /* pcrel_offset */
352 HOWTO (R_AARCH64_NONE
, /* type */
354 3, /* size (0 = byte, 1 = short, 2 = long) */
356 FALSE
, /* pc_relative */
358 complain_overflow_dont
, /* complain_on_overflow */
359 bfd_elf_generic_reloc
, /* special_function */
360 "R_AARCH64_NONE", /* name */
361 FALSE
, /* partial_inplace */
364 FALSE
), /* pcrel_offset */
368 HOWTO64 (AARCH64_R (ABS64
), /* type */
370 4, /* size (4 = long long) */
372 FALSE
, /* pc_relative */
374 complain_overflow_unsigned
, /* complain_on_overflow */
375 bfd_elf_generic_reloc
, /* special_function */
376 AARCH64_R_STR (ABS64
), /* name */
377 FALSE
, /* partial_inplace */
378 ALL_ONES
, /* src_mask */
379 ALL_ONES
, /* dst_mask */
380 FALSE
), /* pcrel_offset */
383 HOWTO (AARCH64_R (ABS32
), /* type */
385 2, /* size (0 = byte, 1 = short, 2 = long) */
387 FALSE
, /* pc_relative */
389 complain_overflow_unsigned
, /* complain_on_overflow */
390 bfd_elf_generic_reloc
, /* special_function */
391 AARCH64_R_STR (ABS32
), /* name */
392 FALSE
, /* partial_inplace */
393 0xffffffff, /* src_mask */
394 0xffffffff, /* dst_mask */
395 FALSE
), /* pcrel_offset */
398 HOWTO (AARCH64_R (ABS16
), /* type */
400 1, /* size (0 = byte, 1 = short, 2 = long) */
402 FALSE
, /* pc_relative */
404 complain_overflow_unsigned
, /* complain_on_overflow */
405 bfd_elf_generic_reloc
, /* special_function */
406 AARCH64_R_STR (ABS16
), /* name */
407 FALSE
, /* partial_inplace */
408 0xffff, /* src_mask */
409 0xffff, /* dst_mask */
410 FALSE
), /* pcrel_offset */
412 /* .xword: (S+A-P) */
413 HOWTO64 (AARCH64_R (PREL64
), /* type */
415 4, /* size (4 = long long) */
417 TRUE
, /* pc_relative */
419 complain_overflow_signed
, /* complain_on_overflow */
420 bfd_elf_generic_reloc
, /* special_function */
421 AARCH64_R_STR (PREL64
), /* name */
422 FALSE
, /* partial_inplace */
423 ALL_ONES
, /* src_mask */
424 ALL_ONES
, /* dst_mask */
425 TRUE
), /* pcrel_offset */
428 HOWTO (AARCH64_R (PREL32
), /* type */
430 2, /* size (0 = byte, 1 = short, 2 = long) */
432 TRUE
, /* pc_relative */
434 complain_overflow_signed
, /* complain_on_overflow */
435 bfd_elf_generic_reloc
, /* special_function */
436 AARCH64_R_STR (PREL32
), /* name */
437 FALSE
, /* partial_inplace */
438 0xffffffff, /* src_mask */
439 0xffffffff, /* dst_mask */
440 TRUE
), /* pcrel_offset */
443 HOWTO (AARCH64_R (PREL16
), /* type */
445 1, /* size (0 = byte, 1 = short, 2 = long) */
447 TRUE
, /* pc_relative */
449 complain_overflow_signed
, /* complain_on_overflow */
450 bfd_elf_generic_reloc
, /* special_function */
451 AARCH64_R_STR (PREL16
), /* name */
452 FALSE
, /* partial_inplace */
453 0xffff, /* src_mask */
454 0xffff, /* dst_mask */
455 TRUE
), /* pcrel_offset */
457 /* Group relocations to create a 16, 32, 48 or 64 bit
458 unsigned data or abs address inline. */
460 /* MOVZ: ((S+A) >> 0) & 0xffff */
461 HOWTO (AARCH64_R (MOVW_UABS_G0
), /* type */
463 2, /* size (0 = byte, 1 = short, 2 = long) */
465 FALSE
, /* pc_relative */
467 complain_overflow_unsigned
, /* complain_on_overflow */
468 bfd_elf_generic_reloc
, /* special_function */
469 AARCH64_R_STR (MOVW_UABS_G0
), /* name */
470 FALSE
, /* partial_inplace */
471 0xffff, /* src_mask */
472 0xffff, /* dst_mask */
473 FALSE
), /* pcrel_offset */
475 /* MOVK: ((S+A) >> 0) & 0xffff [no overflow check] */
476 HOWTO (AARCH64_R (MOVW_UABS_G0_NC
), /* type */
478 2, /* size (0 = byte, 1 = short, 2 = long) */
480 FALSE
, /* pc_relative */
482 complain_overflow_dont
, /* complain_on_overflow */
483 bfd_elf_generic_reloc
, /* special_function */
484 AARCH64_R_STR (MOVW_UABS_G0_NC
), /* name */
485 FALSE
, /* partial_inplace */
486 0xffff, /* src_mask */
487 0xffff, /* dst_mask */
488 FALSE
), /* pcrel_offset */
490 /* MOVZ: ((S+A) >> 16) & 0xffff */
491 HOWTO (AARCH64_R (MOVW_UABS_G1
), /* type */
493 2, /* size (0 = byte, 1 = short, 2 = long) */
495 FALSE
, /* pc_relative */
497 complain_overflow_unsigned
, /* complain_on_overflow */
498 bfd_elf_generic_reloc
, /* special_function */
499 AARCH64_R_STR (MOVW_UABS_G1
), /* name */
500 FALSE
, /* partial_inplace */
501 0xffff, /* src_mask */
502 0xffff, /* dst_mask */
503 FALSE
), /* pcrel_offset */
505 /* MOVK: ((S+A) >> 16) & 0xffff [no overflow check] */
506 HOWTO64 (AARCH64_R (MOVW_UABS_G1_NC
), /* type */
508 2, /* size (0 = byte, 1 = short, 2 = long) */
510 FALSE
, /* pc_relative */
512 complain_overflow_dont
, /* complain_on_overflow */
513 bfd_elf_generic_reloc
, /* special_function */
514 AARCH64_R_STR (MOVW_UABS_G1_NC
), /* name */
515 FALSE
, /* partial_inplace */
516 0xffff, /* src_mask */
517 0xffff, /* dst_mask */
518 FALSE
), /* pcrel_offset */
520 /* MOVZ: ((S+A) >> 32) & 0xffff */
521 HOWTO64 (AARCH64_R (MOVW_UABS_G2
), /* type */
523 2, /* size (0 = byte, 1 = short, 2 = long) */
525 FALSE
, /* pc_relative */
527 complain_overflow_unsigned
, /* complain_on_overflow */
528 bfd_elf_generic_reloc
, /* special_function */
529 AARCH64_R_STR (MOVW_UABS_G2
), /* name */
530 FALSE
, /* partial_inplace */
531 0xffff, /* src_mask */
532 0xffff, /* dst_mask */
533 FALSE
), /* pcrel_offset */
535 /* MOVK: ((S+A) >> 32) & 0xffff [no overflow check] */
536 HOWTO64 (AARCH64_R (MOVW_UABS_G2_NC
), /* type */
538 2, /* size (0 = byte, 1 = short, 2 = long) */
540 FALSE
, /* pc_relative */
542 complain_overflow_dont
, /* complain_on_overflow */
543 bfd_elf_generic_reloc
, /* special_function */
544 AARCH64_R_STR (MOVW_UABS_G2_NC
), /* name */
545 FALSE
, /* partial_inplace */
546 0xffff, /* src_mask */
547 0xffff, /* dst_mask */
548 FALSE
), /* pcrel_offset */
550 /* MOVZ: ((S+A) >> 48) & 0xffff */
551 HOWTO64 (AARCH64_R (MOVW_UABS_G3
), /* type */
553 2, /* size (0 = byte, 1 = short, 2 = long) */
555 FALSE
, /* pc_relative */
557 complain_overflow_unsigned
, /* complain_on_overflow */
558 bfd_elf_generic_reloc
, /* special_function */
559 AARCH64_R_STR (MOVW_UABS_G3
), /* name */
560 FALSE
, /* partial_inplace */
561 0xffff, /* src_mask */
562 0xffff, /* dst_mask */
563 FALSE
), /* pcrel_offset */
565 /* Group relocations to create high part of a 16, 32, 48 or 64 bit
566 signed data or abs address inline. Will change instruction
567 to MOVN or MOVZ depending on sign of calculated value. */
569 /* MOV[ZN]: ((S+A) >> 0) & 0xffff */
570 HOWTO (AARCH64_R (MOVW_SABS_G0
), /* type */
572 2, /* size (0 = byte, 1 = short, 2 = long) */
574 FALSE
, /* pc_relative */
576 complain_overflow_signed
, /* complain_on_overflow */
577 bfd_elf_generic_reloc
, /* special_function */
578 AARCH64_R_STR (MOVW_SABS_G0
), /* name */
579 FALSE
, /* partial_inplace */
580 0xffff, /* src_mask */
581 0xffff, /* dst_mask */
582 FALSE
), /* pcrel_offset */
584 /* MOV[ZN]: ((S+A) >> 16) & 0xffff */
585 HOWTO64 (AARCH64_R (MOVW_SABS_G1
), /* type */
587 2, /* size (0 = byte, 1 = short, 2 = long) */
589 FALSE
, /* pc_relative */
591 complain_overflow_signed
, /* complain_on_overflow */
592 bfd_elf_generic_reloc
, /* special_function */
593 AARCH64_R_STR (MOVW_SABS_G1
), /* name */
594 FALSE
, /* partial_inplace */
595 0xffff, /* src_mask */
596 0xffff, /* dst_mask */
597 FALSE
), /* pcrel_offset */
599 /* MOV[ZN]: ((S+A) >> 32) & 0xffff */
600 HOWTO64 (AARCH64_R (MOVW_SABS_G2
), /* type */
602 2, /* size (0 = byte, 1 = short, 2 = long) */
604 FALSE
, /* pc_relative */
606 complain_overflow_signed
, /* complain_on_overflow */
607 bfd_elf_generic_reloc
, /* special_function */
608 AARCH64_R_STR (MOVW_SABS_G2
), /* name */
609 FALSE
, /* partial_inplace */
610 0xffff, /* src_mask */
611 0xffff, /* dst_mask */
612 FALSE
), /* pcrel_offset */
614 /* Relocations to generate 19, 21 and 33 bit PC-relative load/store
615 addresses: PG(x) is (x & ~0xfff). */
617 /* LD-lit: ((S+A-P) >> 2) & 0x7ffff */
618 HOWTO (AARCH64_R (LD_PREL_LO19
), /* type */
620 2, /* size (0 = byte, 1 = short, 2 = long) */
622 TRUE
, /* pc_relative */
624 complain_overflow_signed
, /* complain_on_overflow */
625 bfd_elf_generic_reloc
, /* special_function */
626 AARCH64_R_STR (LD_PREL_LO19
), /* name */
627 FALSE
, /* partial_inplace */
628 0x7ffff, /* src_mask */
629 0x7ffff, /* dst_mask */
630 TRUE
), /* pcrel_offset */
632 /* ADR: (S+A-P) & 0x1fffff */
633 HOWTO (AARCH64_R (ADR_PREL_LO21
), /* type */
635 2, /* size (0 = byte, 1 = short, 2 = long) */
637 TRUE
, /* pc_relative */
639 complain_overflow_signed
, /* complain_on_overflow */
640 bfd_elf_generic_reloc
, /* special_function */
641 AARCH64_R_STR (ADR_PREL_LO21
), /* name */
642 FALSE
, /* partial_inplace */
643 0x1fffff, /* src_mask */
644 0x1fffff, /* dst_mask */
645 TRUE
), /* pcrel_offset */
647 /* ADRP: ((PG(S+A)-PG(P)) >> 12) & 0x1fffff */
648 HOWTO (AARCH64_R (ADR_PREL_PG_HI21
), /* type */
650 2, /* size (0 = byte, 1 = short, 2 = long) */
652 TRUE
, /* pc_relative */
654 complain_overflow_signed
, /* complain_on_overflow */
655 bfd_elf_generic_reloc
, /* special_function */
656 AARCH64_R_STR (ADR_PREL_PG_HI21
), /* name */
657 FALSE
, /* partial_inplace */
658 0x1fffff, /* src_mask */
659 0x1fffff, /* dst_mask */
660 TRUE
), /* pcrel_offset */
662 /* ADRP: ((PG(S+A)-PG(P)) >> 12) & 0x1fffff [no overflow check] */
663 HOWTO64 (AARCH64_R (ADR_PREL_PG_HI21_NC
), /* type */
665 2, /* size (0 = byte, 1 = short, 2 = long) */
667 TRUE
, /* pc_relative */
669 complain_overflow_dont
, /* complain_on_overflow */
670 bfd_elf_generic_reloc
, /* special_function */
671 AARCH64_R_STR (ADR_PREL_PG_HI21_NC
), /* name */
672 FALSE
, /* partial_inplace */
673 0x1fffff, /* src_mask */
674 0x1fffff, /* dst_mask */
675 TRUE
), /* pcrel_offset */
677 /* ADD: (S+A) & 0xfff [no overflow check] */
678 HOWTO (AARCH64_R (ADD_ABS_LO12_NC
), /* type */
680 2, /* size (0 = byte, 1 = short, 2 = long) */
682 FALSE
, /* pc_relative */
684 complain_overflow_dont
, /* complain_on_overflow */
685 bfd_elf_generic_reloc
, /* special_function */
686 AARCH64_R_STR (ADD_ABS_LO12_NC
), /* name */
687 FALSE
, /* partial_inplace */
688 0x3ffc00, /* src_mask */
689 0x3ffc00, /* dst_mask */
690 FALSE
), /* pcrel_offset */
692 /* LD/ST8: (S+A) & 0xfff */
693 HOWTO (AARCH64_R (LDST8_ABS_LO12_NC
), /* type */
695 2, /* size (0 = byte, 1 = short, 2 = long) */
697 FALSE
, /* pc_relative */
699 complain_overflow_dont
, /* complain_on_overflow */
700 bfd_elf_generic_reloc
, /* special_function */
701 AARCH64_R_STR (LDST8_ABS_LO12_NC
), /* name */
702 FALSE
, /* partial_inplace */
703 0xfff, /* src_mask */
704 0xfff, /* dst_mask */
705 FALSE
), /* pcrel_offset */
707 /* Relocations for control-flow instructions. */
709 /* TBZ/NZ: ((S+A-P) >> 2) & 0x3fff */
710 HOWTO (AARCH64_R (TSTBR14
), /* type */
712 2, /* size (0 = byte, 1 = short, 2 = long) */
714 TRUE
, /* pc_relative */
716 complain_overflow_signed
, /* complain_on_overflow */
717 bfd_elf_generic_reloc
, /* special_function */
718 AARCH64_R_STR (TSTBR14
), /* name */
719 FALSE
, /* partial_inplace */
720 0x3fff, /* src_mask */
721 0x3fff, /* dst_mask */
722 TRUE
), /* pcrel_offset */
724 /* B.cond: ((S+A-P) >> 2) & 0x7ffff */
725 HOWTO (AARCH64_R (CONDBR19
), /* type */
727 2, /* size (0 = byte, 1 = short, 2 = long) */
729 TRUE
, /* pc_relative */
731 complain_overflow_signed
, /* complain_on_overflow */
732 bfd_elf_generic_reloc
, /* special_function */
733 AARCH64_R_STR (CONDBR19
), /* name */
734 FALSE
, /* partial_inplace */
735 0x7ffff, /* src_mask */
736 0x7ffff, /* dst_mask */
737 TRUE
), /* pcrel_offset */
739 /* B: ((S+A-P) >> 2) & 0x3ffffff */
740 HOWTO (AARCH64_R (JUMP26
), /* type */
742 2, /* size (0 = byte, 1 = short, 2 = long) */
744 TRUE
, /* pc_relative */
746 complain_overflow_signed
, /* complain_on_overflow */
747 bfd_elf_generic_reloc
, /* special_function */
748 AARCH64_R_STR (JUMP26
), /* name */
749 FALSE
, /* partial_inplace */
750 0x3ffffff, /* src_mask */
751 0x3ffffff, /* dst_mask */
752 TRUE
), /* pcrel_offset */
754 /* BL: ((S+A-P) >> 2) & 0x3ffffff */
755 HOWTO (AARCH64_R (CALL26
), /* type */
757 2, /* size (0 = byte, 1 = short, 2 = long) */
759 TRUE
, /* pc_relative */
761 complain_overflow_signed
, /* complain_on_overflow */
762 bfd_elf_generic_reloc
, /* special_function */
763 AARCH64_R_STR (CALL26
), /* name */
764 FALSE
, /* partial_inplace */
765 0x3ffffff, /* src_mask */
766 0x3ffffff, /* dst_mask */
767 TRUE
), /* pcrel_offset */
769 /* LD/ST16: (S+A) & 0xffe */
770 HOWTO (AARCH64_R (LDST16_ABS_LO12_NC
), /* type */
772 2, /* size (0 = byte, 1 = short, 2 = long) */
774 FALSE
, /* pc_relative */
776 complain_overflow_dont
, /* complain_on_overflow */
777 bfd_elf_generic_reloc
, /* special_function */
778 AARCH64_R_STR (LDST16_ABS_LO12_NC
), /* name */
779 FALSE
, /* partial_inplace */
780 0xffe, /* src_mask */
781 0xffe, /* dst_mask */
782 FALSE
), /* pcrel_offset */
784 /* LD/ST32: (S+A) & 0xffc */
785 HOWTO (AARCH64_R (LDST32_ABS_LO12_NC
), /* type */
787 2, /* size (0 = byte, 1 = short, 2 = long) */
789 FALSE
, /* pc_relative */
791 complain_overflow_dont
, /* complain_on_overflow */
792 bfd_elf_generic_reloc
, /* special_function */
793 AARCH64_R_STR (LDST32_ABS_LO12_NC
), /* name */
794 FALSE
, /* partial_inplace */
795 0xffc, /* src_mask */
796 0xffc, /* dst_mask */
797 FALSE
), /* pcrel_offset */
799 /* LD/ST64: (S+A) & 0xff8 */
800 HOWTO (AARCH64_R (LDST64_ABS_LO12_NC
), /* type */
802 2, /* size (0 = byte, 1 = short, 2 = long) */
804 FALSE
, /* pc_relative */
806 complain_overflow_dont
, /* complain_on_overflow */
807 bfd_elf_generic_reloc
, /* special_function */
808 AARCH64_R_STR (LDST64_ABS_LO12_NC
), /* name */
809 FALSE
, /* partial_inplace */
810 0xff8, /* src_mask */
811 0xff8, /* dst_mask */
812 FALSE
), /* pcrel_offset */
814 /* LD/ST128: (S+A) & 0xff0 */
815 HOWTO (AARCH64_R (LDST128_ABS_LO12_NC
), /* type */
817 2, /* size (0 = byte, 1 = short, 2 = long) */
819 FALSE
, /* pc_relative */
821 complain_overflow_dont
, /* complain_on_overflow */
822 bfd_elf_generic_reloc
, /* special_function */
823 AARCH64_R_STR (LDST128_ABS_LO12_NC
), /* name */
824 FALSE
, /* partial_inplace */
825 0xff0, /* src_mask */
826 0xff0, /* dst_mask */
827 FALSE
), /* pcrel_offset */
829 /* Set a load-literal immediate field to bits
830 0x1FFFFC of G(S)-P */
831 HOWTO (AARCH64_R (GOT_LD_PREL19
), /* type */
833 2, /* size (0 = byte,1 = short,2 = long) */
835 TRUE
, /* pc_relative */
837 complain_overflow_signed
, /* complain_on_overflow */
838 bfd_elf_generic_reloc
, /* special_function */
839 AARCH64_R_STR (GOT_LD_PREL19
), /* name */
840 FALSE
, /* partial_inplace */
841 0xffffe0, /* src_mask */
842 0xffffe0, /* dst_mask */
843 TRUE
), /* pcrel_offset */
845 /* Get to the page for the GOT entry for the symbol
846 (G(S) - P) using an ADRP instruction. */
847 HOWTO (AARCH64_R (ADR_GOT_PAGE
), /* type */
849 2, /* size (0 = byte, 1 = short, 2 = long) */
851 TRUE
, /* pc_relative */
853 complain_overflow_dont
, /* complain_on_overflow */
854 bfd_elf_generic_reloc
, /* special_function */
855 AARCH64_R_STR (ADR_GOT_PAGE
), /* name */
856 FALSE
, /* partial_inplace */
857 0x1fffff, /* src_mask */
858 0x1fffff, /* dst_mask */
859 TRUE
), /* pcrel_offset */
861 /* LD64: GOT offset G(S) & 0xff8 */
862 HOWTO64 (AARCH64_R (LD64_GOT_LO12_NC
), /* type */
864 2, /* size (0 = byte, 1 = short, 2 = long) */
866 FALSE
, /* pc_relative */
868 complain_overflow_dont
, /* complain_on_overflow */
869 bfd_elf_generic_reloc
, /* special_function */
870 AARCH64_R_STR (LD64_GOT_LO12_NC
), /* name */
871 FALSE
, /* partial_inplace */
872 0xff8, /* src_mask */
873 0xff8, /* dst_mask */
874 FALSE
), /* pcrel_offset */
876 /* LD32: GOT offset G(S) & 0xffc */
877 HOWTO32 (AARCH64_R (LD32_GOT_LO12_NC
), /* type */
879 2, /* size (0 = byte, 1 = short, 2 = long) */
881 FALSE
, /* pc_relative */
883 complain_overflow_dont
, /* complain_on_overflow */
884 bfd_elf_generic_reloc
, /* special_function */
885 AARCH64_R_STR (LD32_GOT_LO12_NC
), /* name */
886 FALSE
, /* partial_inplace */
887 0xffc, /* src_mask */
888 0xffc, /* dst_mask */
889 FALSE
), /* pcrel_offset */
891 /* Lower 16 bits of GOT offset for the symbol. */
892 HOWTO64 (AARCH64_R (MOVW_GOTOFF_G0_NC
), /* type */
894 2, /* size (0 = byte, 1 = short, 2 = long) */
896 FALSE
, /* pc_relative */
898 complain_overflow_dont
, /* complain_on_overflow */
899 bfd_elf_generic_reloc
, /* special_function */
900 AARCH64_R_STR (MOVW_GOTOFF_G0_NC
), /* name */
901 FALSE
, /* partial_inplace */
902 0xffff, /* src_mask */
903 0xffff, /* dst_mask */
904 FALSE
), /* pcrel_offset */
906 /* Higher 16 bits of GOT offset for the symbol. */
907 HOWTO64 (AARCH64_R (MOVW_GOTOFF_G1
), /* type */
909 2, /* size (0 = byte, 1 = short, 2 = long) */
911 FALSE
, /* pc_relative */
913 complain_overflow_unsigned
, /* complain_on_overflow */
914 bfd_elf_generic_reloc
, /* special_function */
915 AARCH64_R_STR (MOVW_GOTOFF_G1
), /* name */
916 FALSE
, /* partial_inplace */
917 0xffff, /* src_mask */
918 0xffff, /* dst_mask */
919 FALSE
), /* pcrel_offset */
921 /* LD64: GOT offset for the symbol. */
922 HOWTO64 (AARCH64_R (LD64_GOTOFF_LO15
), /* type */
924 2, /* size (0 = byte, 1 = short, 2 = long) */
926 FALSE
, /* pc_relative */
928 complain_overflow_unsigned
, /* complain_on_overflow */
929 bfd_elf_generic_reloc
, /* special_function */
930 AARCH64_R_STR (LD64_GOTOFF_LO15
), /* name */
931 FALSE
, /* partial_inplace */
932 0x7ff8, /* src_mask */
933 0x7ff8, /* dst_mask */
934 FALSE
), /* pcrel_offset */
936 /* LD32: GOT offset to the page address of GOT table.
937 (G(S) - PAGE (_GLOBAL_OFFSET_TABLE_)) & 0x5ffc. */
938 HOWTO32 (AARCH64_R (LD32_GOTPAGE_LO14
), /* type */
940 2, /* size (0 = byte, 1 = short, 2 = long) */
942 FALSE
, /* pc_relative */
944 complain_overflow_unsigned
, /* complain_on_overflow */
945 bfd_elf_generic_reloc
, /* special_function */
946 AARCH64_R_STR (LD32_GOTPAGE_LO14
), /* name */
947 FALSE
, /* partial_inplace */
948 0x5ffc, /* src_mask */
949 0x5ffc, /* dst_mask */
950 FALSE
), /* pcrel_offset */
952 /* LD64: GOT offset to the page address of GOT table.
953 (G(S) - PAGE (_GLOBAL_OFFSET_TABLE_)) & 0x7ff8. */
954 HOWTO64 (AARCH64_R (LD64_GOTPAGE_LO15
), /* type */
956 2, /* size (0 = byte, 1 = short, 2 = long) */
958 FALSE
, /* pc_relative */
960 complain_overflow_unsigned
, /* complain_on_overflow */
961 bfd_elf_generic_reloc
, /* special_function */
962 AARCH64_R_STR (LD64_GOTPAGE_LO15
), /* name */
963 FALSE
, /* partial_inplace */
964 0x7ff8, /* src_mask */
965 0x7ff8, /* dst_mask */
966 FALSE
), /* pcrel_offset */
968 /* Get to the page for the GOT entry for the symbol
969 (G(S) - P) using an ADRP instruction. */
970 HOWTO (AARCH64_R (TLSGD_ADR_PAGE21
), /* type */
972 2, /* size (0 = byte, 1 = short, 2 = long) */
974 TRUE
, /* pc_relative */
976 complain_overflow_dont
, /* complain_on_overflow */
977 bfd_elf_generic_reloc
, /* special_function */
978 AARCH64_R_STR (TLSGD_ADR_PAGE21
), /* name */
979 FALSE
, /* partial_inplace */
980 0x1fffff, /* src_mask */
981 0x1fffff, /* dst_mask */
982 TRUE
), /* pcrel_offset */
984 HOWTO (AARCH64_R (TLSGD_ADR_PREL21
), /* type */
986 2, /* size (0 = byte, 1 = short, 2 = long) */
988 TRUE
, /* pc_relative */
990 complain_overflow_dont
, /* complain_on_overflow */
991 bfd_elf_generic_reloc
, /* special_function */
992 AARCH64_R_STR (TLSGD_ADR_PREL21
), /* name */
993 FALSE
, /* partial_inplace */
994 0x1fffff, /* src_mask */
995 0x1fffff, /* dst_mask */
996 TRUE
), /* pcrel_offset */
998 /* ADD: GOT offset G(S) & 0xff8 [no overflow check] */
999 HOWTO (AARCH64_R (TLSGD_ADD_LO12_NC
), /* type */
1001 2, /* size (0 = byte, 1 = short, 2 = long) */
1003 FALSE
, /* pc_relative */
1005 complain_overflow_dont
, /* complain_on_overflow */
1006 bfd_elf_generic_reloc
, /* special_function */
1007 AARCH64_R_STR (TLSGD_ADD_LO12_NC
), /* name */
1008 FALSE
, /* partial_inplace */
1009 0xfff, /* src_mask */
1010 0xfff, /* dst_mask */
1011 FALSE
), /* pcrel_offset */
1013 /* Lower 16 bits of GOT offset to tls_index. */
1014 HOWTO64 (AARCH64_R (TLSGD_MOVW_G0_NC
), /* type */
1016 2, /* size (0 = byte, 1 = short, 2 = long) */
1018 FALSE
, /* pc_relative */
1020 complain_overflow_dont
, /* complain_on_overflow */
1021 bfd_elf_generic_reloc
, /* special_function */
1022 AARCH64_R_STR (TLSGD_MOVW_G0_NC
), /* name */
1023 FALSE
, /* partial_inplace */
1024 0xffff, /* src_mask */
1025 0xffff, /* dst_mask */
1026 FALSE
), /* pcrel_offset */
1028 /* Higher 16 bits of GOT offset to tls_index. */
1029 HOWTO64 (AARCH64_R (TLSGD_MOVW_G1
), /* type */
1030 16, /* rightshift */
1031 2, /* size (0 = byte, 1 = short, 2 = long) */
1033 FALSE
, /* pc_relative */
1035 complain_overflow_unsigned
, /* complain_on_overflow */
1036 bfd_elf_generic_reloc
, /* special_function */
1037 AARCH64_R_STR (TLSGD_MOVW_G1
), /* name */
1038 FALSE
, /* partial_inplace */
1039 0xffff, /* src_mask */
1040 0xffff, /* dst_mask */
1041 FALSE
), /* pcrel_offset */
1043 HOWTO (AARCH64_R (TLSIE_ADR_GOTTPREL_PAGE21
), /* type */
1044 12, /* rightshift */
1045 2, /* size (0 = byte, 1 = short, 2 = long) */
1047 FALSE
, /* pc_relative */
1049 complain_overflow_dont
, /* complain_on_overflow */
1050 bfd_elf_generic_reloc
, /* special_function */
1051 AARCH64_R_STR (TLSIE_ADR_GOTTPREL_PAGE21
), /* name */
1052 FALSE
, /* partial_inplace */
1053 0x1fffff, /* src_mask */
1054 0x1fffff, /* dst_mask */
1055 FALSE
), /* pcrel_offset */
1057 HOWTO64 (AARCH64_R (TLSIE_LD64_GOTTPREL_LO12_NC
), /* type */
1059 2, /* size (0 = byte, 1 = short, 2 = long) */
1061 FALSE
, /* pc_relative */
1063 complain_overflow_dont
, /* complain_on_overflow */
1064 bfd_elf_generic_reloc
, /* special_function */
1065 AARCH64_R_STR (TLSIE_LD64_GOTTPREL_LO12_NC
), /* name */
1066 FALSE
, /* partial_inplace */
1067 0xff8, /* src_mask */
1068 0xff8, /* dst_mask */
1069 FALSE
), /* pcrel_offset */
1071 HOWTO32 (AARCH64_R (TLSIE_LD32_GOTTPREL_LO12_NC
), /* type */
1073 2, /* size (0 = byte, 1 = short, 2 = long) */
1075 FALSE
, /* pc_relative */
1077 complain_overflow_dont
, /* complain_on_overflow */
1078 bfd_elf_generic_reloc
, /* special_function */
1079 AARCH64_R_STR (TLSIE_LD32_GOTTPREL_LO12_NC
), /* name */
1080 FALSE
, /* partial_inplace */
1081 0xffc, /* src_mask */
1082 0xffc, /* dst_mask */
1083 FALSE
), /* pcrel_offset */
1085 HOWTO (AARCH64_R (TLSIE_LD_GOTTPREL_PREL19
), /* type */
1087 2, /* size (0 = byte, 1 = short, 2 = long) */
1089 FALSE
, /* pc_relative */
1091 complain_overflow_dont
, /* complain_on_overflow */
1092 bfd_elf_generic_reloc
, /* special_function */
1093 AARCH64_R_STR (TLSIE_LD_GOTTPREL_PREL19
), /* name */
1094 FALSE
, /* partial_inplace */
1095 0x1ffffc, /* src_mask */
1096 0x1ffffc, /* dst_mask */
1097 FALSE
), /* pcrel_offset */
1099 HOWTO64 (AARCH64_R (TLSIE_MOVW_GOTTPREL_G0_NC
), /* type */
1101 2, /* size (0 = byte, 1 = short, 2 = long) */
1103 FALSE
, /* pc_relative */
1105 complain_overflow_dont
, /* complain_on_overflow */
1106 bfd_elf_generic_reloc
, /* special_function */
1107 AARCH64_R_STR (TLSIE_MOVW_GOTTPREL_G0_NC
), /* name */
1108 FALSE
, /* partial_inplace */
1109 0xffff, /* src_mask */
1110 0xffff, /* dst_mask */
1111 FALSE
), /* pcrel_offset */
1113 HOWTO64 (AARCH64_R (TLSIE_MOVW_GOTTPREL_G1
), /* type */
1114 16, /* rightshift */
1115 2, /* size (0 = byte, 1 = short, 2 = long) */
1117 FALSE
, /* pc_relative */
1119 complain_overflow_unsigned
, /* complain_on_overflow */
1120 bfd_elf_generic_reloc
, /* special_function */
1121 AARCH64_R_STR (TLSIE_MOVW_GOTTPREL_G1
), /* name */
1122 FALSE
, /* partial_inplace */
1123 0xffff, /* src_mask */
1124 0xffff, /* dst_mask */
1125 FALSE
), /* pcrel_offset */
1127 /* ADD: bit[23:12] of byte offset to module TLS base address. */
1128 HOWTO (AARCH64_R (TLSLD_ADD_DTPREL_HI12
), /* type */
1129 12, /* rightshift */
1130 2, /* size (0 = byte, 1 = short, 2 = long) */
1132 FALSE
, /* pc_relative */
1134 complain_overflow_unsigned
, /* complain_on_overflow */
1135 bfd_elf_generic_reloc
, /* special_function */
1136 AARCH64_R_STR (TLSLD_ADD_DTPREL_HI12
), /* name */
1137 FALSE
, /* partial_inplace */
1138 0xfff, /* src_mask */
1139 0xfff, /* dst_mask */
1140 FALSE
), /* pcrel_offset */
1142 /* Unsigned 12 bit byte offset to module TLS base address. */
1143 HOWTO (AARCH64_R (TLSLD_ADD_DTPREL_LO12
), /* type */
1145 2, /* size (0 = byte, 1 = short, 2 = long) */
1147 FALSE
, /* pc_relative */
1149 complain_overflow_unsigned
, /* complain_on_overflow */
1150 bfd_elf_generic_reloc
, /* special_function */
1151 AARCH64_R_STR (TLSLD_ADD_DTPREL_LO12
), /* name */
1152 FALSE
, /* partial_inplace */
1153 0xfff, /* src_mask */
1154 0xfff, /* dst_mask */
1155 FALSE
), /* pcrel_offset */
1157 /* No overflow check version of BFD_RELOC_AARCH64_TLSLD_ADD_DTPREL_LO12. */
1158 HOWTO (AARCH64_R (TLSLD_ADD_DTPREL_LO12_NC
), /* type */
1160 2, /* size (0 = byte, 1 = short, 2 = long) */
1162 FALSE
, /* pc_relative */
1164 complain_overflow_dont
, /* complain_on_overflow */
1165 bfd_elf_generic_reloc
, /* special_function */
1166 AARCH64_R_STR (TLSLD_ADD_DTPREL_LO12_NC
), /* name */
1167 FALSE
, /* partial_inplace */
1168 0xfff, /* src_mask */
1169 0xfff, /* dst_mask */
1170 FALSE
), /* pcrel_offset */
1172 /* ADD: GOT offset G(S) & 0xff8 [no overflow check] */
1173 HOWTO (AARCH64_R (TLSLD_ADD_LO12_NC
), /* type */
1175 2, /* size (0 = byte, 1 = short, 2 = long) */
1177 FALSE
, /* pc_relative */
1179 complain_overflow_dont
, /* complain_on_overflow */
1180 bfd_elf_generic_reloc
, /* special_function */
1181 AARCH64_R_STR (TLSLD_ADD_LO12_NC
), /* name */
1182 FALSE
, /* partial_inplace */
1183 0xfff, /* src_mask */
1184 0xfff, /* dst_mask */
1185 FALSE
), /* pcrel_offset */
1187 /* Get to the page for the GOT entry for the symbol
1188 (G(S) - P) using an ADRP instruction. */
1189 HOWTO (AARCH64_R (TLSLD_ADR_PAGE21
), /* type */
1190 12, /* rightshift */
1191 2, /* size (0 = byte, 1 = short, 2 = long) */
1193 TRUE
, /* pc_relative */
1195 complain_overflow_signed
, /* complain_on_overflow */
1196 bfd_elf_generic_reloc
, /* special_function */
1197 AARCH64_R_STR (TLSLD_ADR_PAGE21
), /* name */
1198 FALSE
, /* partial_inplace */
1199 0x1fffff, /* src_mask */
1200 0x1fffff, /* dst_mask */
1201 TRUE
), /* pcrel_offset */
1203 HOWTO (AARCH64_R (TLSLD_ADR_PREL21
), /* type */
1205 2, /* size (0 = byte, 1 = short, 2 = long) */
1207 TRUE
, /* pc_relative */
1209 complain_overflow_signed
, /* complain_on_overflow */
1210 bfd_elf_generic_reloc
, /* special_function */
1211 AARCH64_R_STR (TLSLD_ADR_PREL21
), /* name */
1212 FALSE
, /* partial_inplace */
1213 0x1fffff, /* src_mask */
1214 0x1fffff, /* dst_mask */
1215 TRUE
), /* pcrel_offset */
1217 /* LD/ST16: bit[11:1] of byte offset to module TLS base address. */
1218 HOWTO64 (AARCH64_R (TLSLD_LDST16_DTPREL_LO12
), /* type */
1220 2, /* size (0 = byte, 1 = short, 2 = long) */
1222 FALSE
, /* pc_relative */
1224 complain_overflow_unsigned
, /* complain_on_overflow */
1225 bfd_elf_generic_reloc
, /* special_function */
1226 AARCH64_R_STR (TLSLD_LDST16_DTPREL_LO12
), /* name */
1227 FALSE
, /* partial_inplace */
1228 0x1ffc00, /* src_mask */
1229 0x1ffc00, /* dst_mask */
1230 FALSE
), /* pcrel_offset */
1232 /* Same as BFD_RELOC_AARCH64_TLSLD_LDST16_DTPREL_LO12, but no overflow check. */
1233 HOWTO64 (AARCH64_R (TLSLD_LDST16_DTPREL_LO12_NC
), /* type */
1235 2, /* size (0 = byte, 1 = short, 2 = long) */
1237 FALSE
, /* pc_relative */
1239 complain_overflow_dont
, /* complain_on_overflow */
1240 bfd_elf_generic_reloc
, /* special_function */
1241 AARCH64_R_STR (TLSLD_LDST16_DTPREL_LO12_NC
), /* name */
1242 FALSE
, /* partial_inplace */
1243 0x1ffc00, /* src_mask */
1244 0x1ffc00, /* dst_mask */
1245 FALSE
), /* pcrel_offset */
1247 /* LD/ST32: bit[11:2] of byte offset to module TLS base address. */
1248 HOWTO64 (AARCH64_R (TLSLD_LDST32_DTPREL_LO12
), /* type */
1250 2, /* size (0 = byte, 1 = short, 2 = long) */
1252 FALSE
, /* pc_relative */
1254 complain_overflow_unsigned
, /* complain_on_overflow */
1255 bfd_elf_generic_reloc
, /* special_function */
1256 AARCH64_R_STR (TLSLD_LDST32_DTPREL_LO12
), /* name */
1257 FALSE
, /* partial_inplace */
1258 0x3ffc00, /* src_mask */
1259 0x3ffc00, /* dst_mask */
1260 FALSE
), /* pcrel_offset */
1262 /* Same as BFD_RELOC_AARCH64_TLSLD_LDST32_DTPREL_LO12, but no overflow check. */
1263 HOWTO64 (AARCH64_R (TLSLD_LDST32_DTPREL_LO12_NC
), /* type */
1265 2, /* size (0 = byte, 1 = short, 2 = long) */
1267 FALSE
, /* pc_relative */
1269 complain_overflow_dont
, /* complain_on_overflow */
1270 bfd_elf_generic_reloc
, /* special_function */
1271 AARCH64_R_STR (TLSLD_LDST32_DTPREL_LO12_NC
), /* name */
1272 FALSE
, /* partial_inplace */
1273 0xffc00, /* src_mask */
1274 0xffc00, /* dst_mask */
1275 FALSE
), /* pcrel_offset */
1277 /* LD/ST64: bit[11:3] of byte offset to module TLS base address. */
1278 HOWTO64 (AARCH64_R (TLSLD_LDST64_DTPREL_LO12
), /* type */
1280 2, /* size (0 = byte, 1 = short, 2 = long) */
1282 FALSE
, /* pc_relative */
1284 complain_overflow_unsigned
, /* complain_on_overflow */
1285 bfd_elf_generic_reloc
, /* special_function */
1286 AARCH64_R_STR (TLSLD_LDST64_DTPREL_LO12
), /* name */
1287 FALSE
, /* partial_inplace */
1288 0x3ffc00, /* src_mask */
1289 0x3ffc00, /* dst_mask */
1290 FALSE
), /* pcrel_offset */
1292 /* Same as BFD_RELOC_AARCH64_TLSLD_LDST64_DTPREL_LO12, but no overflow check. */
1293 HOWTO64 (AARCH64_R (TLSLD_LDST64_DTPREL_LO12_NC
), /* type */
1295 2, /* size (0 = byte, 1 = short, 2 = long) */
1297 FALSE
, /* pc_relative */
1299 complain_overflow_dont
, /* complain_on_overflow */
1300 bfd_elf_generic_reloc
, /* special_function */
1301 AARCH64_R_STR (TLSLD_LDST64_DTPREL_LO12_NC
), /* name */
1302 FALSE
, /* partial_inplace */
1303 0x7fc00, /* src_mask */
1304 0x7fc00, /* dst_mask */
1305 FALSE
), /* pcrel_offset */
1307 /* LD/ST8: bit[11:0] of byte offset to module TLS base address. */
1308 HOWTO64 (AARCH64_R (TLSLD_LDST8_DTPREL_LO12
), /* type */
1310 2, /* size (0 = byte, 1 = short, 2 = long) */
1312 FALSE
, /* pc_relative */
1314 complain_overflow_unsigned
, /* complain_on_overflow */
1315 bfd_elf_generic_reloc
, /* special_function */
1316 AARCH64_R_STR (TLSLD_LDST8_DTPREL_LO12
), /* name */
1317 FALSE
, /* partial_inplace */
1318 0x3ffc00, /* src_mask */
1319 0x3ffc00, /* dst_mask */
1320 FALSE
), /* pcrel_offset */
1322 /* Same as BFD_RELOC_AARCH64_TLSLD_LDST8_DTPREL_LO12, but no overflow check. */
1323 HOWTO64 (AARCH64_R (TLSLD_LDST8_DTPREL_LO12_NC
), /* type */
1325 2, /* size (0 = byte, 1 = short, 2 = long) */
1327 FALSE
, /* pc_relative */
1329 complain_overflow_dont
, /* complain_on_overflow */
1330 bfd_elf_generic_reloc
, /* special_function */
1331 AARCH64_R_STR (TLSLD_LDST8_DTPREL_LO12_NC
), /* name */
1332 FALSE
, /* partial_inplace */
1333 0x3ffc00, /* src_mask */
1334 0x3ffc00, /* dst_mask */
1335 FALSE
), /* pcrel_offset */
1337 /* MOVZ: bit[15:0] of byte offset to module TLS base address. */
1338 HOWTO (AARCH64_R (TLSLD_MOVW_DTPREL_G0
), /* type */
1340 2, /* size (0 = byte, 1 = short, 2 = long) */
1342 FALSE
, /* pc_relative */
1344 complain_overflow_unsigned
, /* complain_on_overflow */
1345 bfd_elf_generic_reloc
, /* special_function */
1346 AARCH64_R_STR (TLSLD_MOVW_DTPREL_G0
), /* name */
1347 FALSE
, /* partial_inplace */
1348 0xffff, /* src_mask */
1349 0xffff, /* dst_mask */
1350 FALSE
), /* pcrel_offset */
1352 /* No overflow check version of BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G0. */
1353 HOWTO (AARCH64_R (TLSLD_MOVW_DTPREL_G0_NC
), /* type */
1355 2, /* size (0 = byte, 1 = short, 2 = long) */
1357 FALSE
, /* pc_relative */
1359 complain_overflow_dont
, /* complain_on_overflow */
1360 bfd_elf_generic_reloc
, /* special_function */
1361 AARCH64_R_STR (TLSLD_MOVW_DTPREL_G0_NC
), /* name */
1362 FALSE
, /* partial_inplace */
1363 0xffff, /* src_mask */
1364 0xffff, /* dst_mask */
1365 FALSE
), /* pcrel_offset */
1367 /* MOVZ: bit[31:16] of byte offset to module TLS base address. */
1368 HOWTO (AARCH64_R (TLSLD_MOVW_DTPREL_G1
), /* type */
1369 16, /* rightshift */
1370 2, /* size (0 = byte, 1 = short, 2 = long) */
1372 FALSE
, /* pc_relative */
1374 complain_overflow_unsigned
, /* complain_on_overflow */
1375 bfd_elf_generic_reloc
, /* special_function */
1376 AARCH64_R_STR (TLSLD_MOVW_DTPREL_G1
), /* name */
1377 FALSE
, /* partial_inplace */
1378 0xffff, /* src_mask */
1379 0xffff, /* dst_mask */
1380 FALSE
), /* pcrel_offset */
1382 /* No overflow check version of BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G1. */
1383 HOWTO64 (AARCH64_R (TLSLD_MOVW_DTPREL_G1_NC
), /* type */
1384 16, /* rightshift */
1385 2, /* size (0 = byte, 1 = short, 2 = long) */
1387 FALSE
, /* pc_relative */
1389 complain_overflow_dont
, /* complain_on_overflow */
1390 bfd_elf_generic_reloc
, /* special_function */
1391 AARCH64_R_STR (TLSLD_MOVW_DTPREL_G1_NC
), /* name */
1392 FALSE
, /* partial_inplace */
1393 0xffff, /* src_mask */
1394 0xffff, /* dst_mask */
1395 FALSE
), /* pcrel_offset */
1397 /* MOVZ: bit[47:32] of byte offset to module TLS base address. */
1398 HOWTO64 (AARCH64_R (TLSLD_MOVW_DTPREL_G2
), /* type */
1399 32, /* rightshift */
1400 2, /* size (0 = byte, 1 = short, 2 = long) */
1402 FALSE
, /* pc_relative */
1404 complain_overflow_unsigned
, /* complain_on_overflow */
1405 bfd_elf_generic_reloc
, /* special_function */
1406 AARCH64_R_STR (TLSLD_MOVW_DTPREL_G2
), /* name */
1407 FALSE
, /* partial_inplace */
1408 0xffff, /* src_mask */
1409 0xffff, /* dst_mask */
1410 FALSE
), /* pcrel_offset */
1412 HOWTO64 (AARCH64_R (TLSLE_MOVW_TPREL_G2
), /* type */
1413 32, /* rightshift */
1414 2, /* size (0 = byte, 1 = short, 2 = long) */
1416 FALSE
, /* pc_relative */
1418 complain_overflow_unsigned
, /* complain_on_overflow */
1419 bfd_elf_generic_reloc
, /* special_function */
1420 AARCH64_R_STR (TLSLE_MOVW_TPREL_G2
), /* name */
1421 FALSE
, /* partial_inplace */
1422 0xffff, /* src_mask */
1423 0xffff, /* dst_mask */
1424 FALSE
), /* pcrel_offset */
1426 HOWTO (AARCH64_R (TLSLE_MOVW_TPREL_G1
), /* type */
1427 16, /* rightshift */
1428 2, /* size (0 = byte, 1 = short, 2 = long) */
1430 FALSE
, /* pc_relative */
1432 complain_overflow_dont
, /* complain_on_overflow */
1433 bfd_elf_generic_reloc
, /* special_function */
1434 AARCH64_R_STR (TLSLE_MOVW_TPREL_G1
), /* name */
1435 FALSE
, /* partial_inplace */
1436 0xffff, /* src_mask */
1437 0xffff, /* dst_mask */
1438 FALSE
), /* pcrel_offset */
1440 HOWTO64 (AARCH64_R (TLSLE_MOVW_TPREL_G1_NC
), /* type */
1441 16, /* rightshift */
1442 2, /* size (0 = byte, 1 = short, 2 = long) */
1444 FALSE
, /* pc_relative */
1446 complain_overflow_dont
, /* complain_on_overflow */
1447 bfd_elf_generic_reloc
, /* special_function */
1448 AARCH64_R_STR (TLSLE_MOVW_TPREL_G1_NC
), /* name */
1449 FALSE
, /* partial_inplace */
1450 0xffff, /* src_mask */
1451 0xffff, /* dst_mask */
1452 FALSE
), /* pcrel_offset */
1454 HOWTO (AARCH64_R (TLSLE_MOVW_TPREL_G0
), /* type */
1456 2, /* size (0 = byte, 1 = short, 2 = long) */
1458 FALSE
, /* pc_relative */
1460 complain_overflow_dont
, /* complain_on_overflow */
1461 bfd_elf_generic_reloc
, /* special_function */
1462 AARCH64_R_STR (TLSLE_MOVW_TPREL_G0
), /* name */
1463 FALSE
, /* partial_inplace */
1464 0xffff, /* src_mask */
1465 0xffff, /* dst_mask */
1466 FALSE
), /* pcrel_offset */
1468 HOWTO (AARCH64_R (TLSLE_MOVW_TPREL_G0_NC
), /* type */
1470 2, /* size (0 = byte, 1 = short, 2 = long) */
1472 FALSE
, /* pc_relative */
1474 complain_overflow_dont
, /* complain_on_overflow */
1475 bfd_elf_generic_reloc
, /* special_function */
1476 AARCH64_R_STR (TLSLE_MOVW_TPREL_G0_NC
), /* name */
1477 FALSE
, /* partial_inplace */
1478 0xffff, /* src_mask */
1479 0xffff, /* dst_mask */
1480 FALSE
), /* pcrel_offset */
1482 HOWTO (AARCH64_R (TLSLE_ADD_TPREL_HI12
), /* type */
1483 12, /* rightshift */
1484 2, /* size (0 = byte, 1 = short, 2 = long) */
1486 FALSE
, /* pc_relative */
1488 complain_overflow_unsigned
, /* complain_on_overflow */
1489 bfd_elf_generic_reloc
, /* special_function */
1490 AARCH64_R_STR (TLSLE_ADD_TPREL_HI12
), /* name */
1491 FALSE
, /* partial_inplace */
1492 0xfff, /* src_mask */
1493 0xfff, /* dst_mask */
1494 FALSE
), /* pcrel_offset */
1496 HOWTO (AARCH64_R (TLSLE_ADD_TPREL_LO12
), /* type */
1498 2, /* size (0 = byte, 1 = short, 2 = long) */
1500 FALSE
, /* pc_relative */
1502 complain_overflow_unsigned
, /* complain_on_overflow */
1503 bfd_elf_generic_reloc
, /* special_function */
1504 AARCH64_R_STR (TLSLE_ADD_TPREL_LO12
), /* name */
1505 FALSE
, /* partial_inplace */
1506 0xfff, /* src_mask */
1507 0xfff, /* dst_mask */
1508 FALSE
), /* pcrel_offset */
1510 HOWTO (AARCH64_R (TLSLE_ADD_TPREL_LO12_NC
), /* type */
1512 2, /* size (0 = byte, 1 = short, 2 = long) */
1514 FALSE
, /* pc_relative */
1516 complain_overflow_dont
, /* complain_on_overflow */
1517 bfd_elf_generic_reloc
, /* special_function */
1518 AARCH64_R_STR (TLSLE_ADD_TPREL_LO12_NC
), /* name */
1519 FALSE
, /* partial_inplace */
1520 0xfff, /* src_mask */
1521 0xfff, /* dst_mask */
1522 FALSE
), /* pcrel_offset */
1524 HOWTO (AARCH64_R (TLSDESC_LD_PREL19
), /* type */
1526 2, /* size (0 = byte, 1 = short, 2 = long) */
1528 TRUE
, /* pc_relative */
1530 complain_overflow_dont
, /* complain_on_overflow */
1531 bfd_elf_generic_reloc
, /* special_function */
1532 AARCH64_R_STR (TLSDESC_LD_PREL19
), /* name */
1533 FALSE
, /* partial_inplace */
1534 0x0ffffe0, /* src_mask */
1535 0x0ffffe0, /* dst_mask */
1536 TRUE
), /* pcrel_offset */
1538 HOWTO (AARCH64_R (TLSDESC_ADR_PREL21
), /* type */
1540 2, /* size (0 = byte, 1 = short, 2 = long) */
1542 TRUE
, /* pc_relative */
1544 complain_overflow_dont
, /* complain_on_overflow */
1545 bfd_elf_generic_reloc
, /* special_function */
1546 AARCH64_R_STR (TLSDESC_ADR_PREL21
), /* name */
1547 FALSE
, /* partial_inplace */
1548 0x1fffff, /* src_mask */
1549 0x1fffff, /* dst_mask */
1550 TRUE
), /* pcrel_offset */
1552 /* Get to the page for the GOT entry for the symbol
1553 (G(S) - P) using an ADRP instruction. */
1554 HOWTO (AARCH64_R (TLSDESC_ADR_PAGE21
), /* type */
1555 12, /* rightshift */
1556 2, /* size (0 = byte, 1 = short, 2 = long) */
1558 TRUE
, /* pc_relative */
1560 complain_overflow_dont
, /* complain_on_overflow */
1561 bfd_elf_generic_reloc
, /* special_function */
1562 AARCH64_R_STR (TLSDESC_ADR_PAGE21
), /* name */
1563 FALSE
, /* partial_inplace */
1564 0x1fffff, /* src_mask */
1565 0x1fffff, /* dst_mask */
1566 TRUE
), /* pcrel_offset */
1568 /* LD64: GOT offset G(S) & 0xff8. */
1569 HOWTO64 (AARCH64_R (TLSDESC_LD64_LO12_NC
), /* type */
1571 2, /* size (0 = byte, 1 = short, 2 = long) */
1573 FALSE
, /* pc_relative */
1575 complain_overflow_dont
, /* complain_on_overflow */
1576 bfd_elf_generic_reloc
, /* special_function */
1577 AARCH64_R_STR (TLSDESC_LD64_LO12_NC
), /* name */
1578 FALSE
, /* partial_inplace */
1579 0xff8, /* src_mask */
1580 0xff8, /* dst_mask */
1581 FALSE
), /* pcrel_offset */
1583 /* LD32: GOT offset G(S) & 0xffc. */
1584 HOWTO32 (AARCH64_R (TLSDESC_LD32_LO12_NC
), /* type */
1586 2, /* size (0 = byte, 1 = short, 2 = long) */
1588 FALSE
, /* pc_relative */
1590 complain_overflow_dont
, /* complain_on_overflow */
1591 bfd_elf_generic_reloc
, /* special_function */
1592 AARCH64_R_STR (TLSDESC_LD32_LO12_NC
), /* name */
1593 FALSE
, /* partial_inplace */
1594 0xffc, /* src_mask */
1595 0xffc, /* dst_mask */
1596 FALSE
), /* pcrel_offset */
1598 /* ADD: GOT offset G(S) & 0xfff. */
1599 HOWTO (AARCH64_R (TLSDESC_ADD_LO12_NC
), /* type */
1601 2, /* size (0 = byte, 1 = short, 2 = long) */
1603 FALSE
, /* pc_relative */
1605 complain_overflow_dont
, /* complain_on_overflow */
1606 bfd_elf_generic_reloc
, /* special_function */
1607 AARCH64_R_STR (TLSDESC_ADD_LO12_NC
), /* name */
1608 FALSE
, /* partial_inplace */
1609 0xfff, /* src_mask */
1610 0xfff, /* dst_mask */
1611 FALSE
), /* pcrel_offset */
1613 HOWTO64 (AARCH64_R (TLSDESC_OFF_G1
), /* type */
1614 16, /* rightshift */
1615 2, /* size (0 = byte, 1 = short, 2 = long) */
1617 FALSE
, /* pc_relative */
1619 complain_overflow_dont
, /* complain_on_overflow */
1620 bfd_elf_generic_reloc
, /* special_function */
1621 AARCH64_R_STR (TLSDESC_OFF_G1
), /* name */
1622 FALSE
, /* partial_inplace */
1623 0xffff, /* src_mask */
1624 0xffff, /* dst_mask */
1625 FALSE
), /* pcrel_offset */
1627 HOWTO64 (AARCH64_R (TLSDESC_OFF_G0_NC
), /* type */
1629 2, /* size (0 = byte, 1 = short, 2 = long) */
1631 FALSE
, /* pc_relative */
1633 complain_overflow_dont
, /* complain_on_overflow */
1634 bfd_elf_generic_reloc
, /* special_function */
1635 AARCH64_R_STR (TLSDESC_OFF_G0_NC
), /* name */
1636 FALSE
, /* partial_inplace */
1637 0xffff, /* src_mask */
1638 0xffff, /* dst_mask */
1639 FALSE
), /* pcrel_offset */
1641 HOWTO64 (AARCH64_R (TLSDESC_LDR
), /* type */
1643 2, /* size (0 = byte, 1 = short, 2 = long) */
1645 FALSE
, /* pc_relative */
1647 complain_overflow_dont
, /* complain_on_overflow */
1648 bfd_elf_generic_reloc
, /* special_function */
1649 AARCH64_R_STR (TLSDESC_LDR
), /* name */
1650 FALSE
, /* partial_inplace */
1653 FALSE
), /* pcrel_offset */
1655 HOWTO64 (AARCH64_R (TLSDESC_ADD
), /* type */
1657 2, /* size (0 = byte, 1 = short, 2 = long) */
1659 FALSE
, /* pc_relative */
1661 complain_overflow_dont
, /* complain_on_overflow */
1662 bfd_elf_generic_reloc
, /* special_function */
1663 AARCH64_R_STR (TLSDESC_ADD
), /* name */
1664 FALSE
, /* partial_inplace */
1667 FALSE
), /* pcrel_offset */
1669 HOWTO (AARCH64_R (TLSDESC_CALL
), /* type */
1671 2, /* size (0 = byte, 1 = short, 2 = long) */
1673 FALSE
, /* pc_relative */
1675 complain_overflow_dont
, /* complain_on_overflow */
1676 bfd_elf_generic_reloc
, /* special_function */
1677 AARCH64_R_STR (TLSDESC_CALL
), /* name */
1678 FALSE
, /* partial_inplace */
1681 FALSE
), /* pcrel_offset */
1683 HOWTO (AARCH64_R (COPY
), /* type */
1685 2, /* size (0 = byte, 1 = short, 2 = long) */
1687 FALSE
, /* pc_relative */
1689 complain_overflow_bitfield
, /* complain_on_overflow */
1690 bfd_elf_generic_reloc
, /* special_function */
1691 AARCH64_R_STR (COPY
), /* name */
1692 TRUE
, /* partial_inplace */
1693 0xffffffff, /* src_mask */
1694 0xffffffff, /* dst_mask */
1695 FALSE
), /* pcrel_offset */
1697 HOWTO (AARCH64_R (GLOB_DAT
), /* type */
1699 2, /* size (0 = byte, 1 = short, 2 = long) */
1701 FALSE
, /* pc_relative */
1703 complain_overflow_bitfield
, /* complain_on_overflow */
1704 bfd_elf_generic_reloc
, /* special_function */
1705 AARCH64_R_STR (GLOB_DAT
), /* name */
1706 TRUE
, /* partial_inplace */
1707 0xffffffff, /* src_mask */
1708 0xffffffff, /* dst_mask */
1709 FALSE
), /* pcrel_offset */
1711 HOWTO (AARCH64_R (JUMP_SLOT
), /* type */
1713 2, /* size (0 = byte, 1 = short, 2 = long) */
1715 FALSE
, /* pc_relative */
1717 complain_overflow_bitfield
, /* complain_on_overflow */
1718 bfd_elf_generic_reloc
, /* special_function */
1719 AARCH64_R_STR (JUMP_SLOT
), /* name */
1720 TRUE
, /* partial_inplace */
1721 0xffffffff, /* src_mask */
1722 0xffffffff, /* dst_mask */
1723 FALSE
), /* pcrel_offset */
1725 HOWTO (AARCH64_R (RELATIVE
), /* type */
1727 2, /* size (0 = byte, 1 = short, 2 = long) */
1729 FALSE
, /* pc_relative */
1731 complain_overflow_bitfield
, /* complain_on_overflow */
1732 bfd_elf_generic_reloc
, /* special_function */
1733 AARCH64_R_STR (RELATIVE
), /* name */
1734 TRUE
, /* partial_inplace */
1735 ALL_ONES
, /* src_mask */
1736 ALL_ONES
, /* dst_mask */
1737 FALSE
), /* pcrel_offset */
1739 HOWTO (AARCH64_R (TLS_DTPMOD
), /* 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_DTPMOD64
), /* name */
1750 AARCH64_R_STR (TLS_DTPMOD
), /* name */
1752 FALSE
, /* partial_inplace */
1754 ALL_ONES
, /* dst_mask */
1755 FALSE
), /* pc_reloffset */
1757 HOWTO (AARCH64_R (TLS_DTPREL
), /* 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_DTPREL64
), /* name */
1768 AARCH64_R_STR (TLS_DTPREL
), /* name */
1770 FALSE
, /* partial_inplace */
1772 ALL_ONES
, /* dst_mask */
1773 FALSE
), /* pcrel_offset */
1775 HOWTO (AARCH64_R (TLS_TPREL
), /* 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 */
1784 AARCH64_R_STR (TLS_TPREL64
), /* name */
1786 AARCH64_R_STR (TLS_TPREL
), /* name */
1788 FALSE
, /* partial_inplace */
1790 ALL_ONES
, /* dst_mask */
1791 FALSE
), /* pcrel_offset */
1793 HOWTO (AARCH64_R (TLSDESC
), /* type */
1795 2, /* size (0 = byte, 1 = short, 2 = long) */
1797 FALSE
, /* pc_relative */
1799 complain_overflow_dont
, /* complain_on_overflow */
1800 bfd_elf_generic_reloc
, /* special_function */
1801 AARCH64_R_STR (TLSDESC
), /* name */
1802 FALSE
, /* partial_inplace */
1804 ALL_ONES
, /* dst_mask */
1805 FALSE
), /* pcrel_offset */
1807 HOWTO (AARCH64_R (IRELATIVE
), /* type */
1809 2, /* size (0 = byte, 1 = short, 2 = long) */
1811 FALSE
, /* pc_relative */
1813 complain_overflow_bitfield
, /* complain_on_overflow */
1814 bfd_elf_generic_reloc
, /* special_function */
1815 AARCH64_R_STR (IRELATIVE
), /* name */
1816 FALSE
, /* partial_inplace */
1818 ALL_ONES
, /* dst_mask */
1819 FALSE
), /* pcrel_offset */
1824 static reloc_howto_type elfNN_aarch64_howto_none
=
1825 HOWTO (R_AARCH64_NONE
, /* type */
1827 3, /* size (0 = byte, 1 = short, 2 = long) */
1829 FALSE
, /* pc_relative */
1831 complain_overflow_dont
,/* complain_on_overflow */
1832 bfd_elf_generic_reloc
, /* special_function */
1833 "R_AARCH64_NONE", /* name */
1834 FALSE
, /* partial_inplace */
1837 FALSE
); /* pcrel_offset */
1839 /* Given HOWTO, return the bfd internal relocation enumerator. */
1841 static bfd_reloc_code_real_type
1842 elfNN_aarch64_bfd_reloc_from_howto (reloc_howto_type
*howto
)
1845 = (int) ARRAY_SIZE (elfNN_aarch64_howto_table
);
1846 const ptrdiff_t offset
1847 = howto
- elfNN_aarch64_howto_table
;
1849 if (offset
> 0 && offset
< size
- 1)
1850 return BFD_RELOC_AARCH64_RELOC_START
+ offset
;
1852 if (howto
== &elfNN_aarch64_howto_none
)
1853 return BFD_RELOC_AARCH64_NONE
;
1855 return BFD_RELOC_AARCH64_RELOC_START
;
1858 /* Given R_TYPE, return the bfd internal relocation enumerator. */
1860 static bfd_reloc_code_real_type
1861 elfNN_aarch64_bfd_reloc_from_type (unsigned int r_type
)
1863 static bfd_boolean initialized_p
= FALSE
;
1864 /* Indexed by R_TYPE, values are offsets in the howto_table. */
1865 static unsigned int offsets
[R_AARCH64_end
];
1867 if (initialized_p
== FALSE
)
1871 for (i
= 1; i
< ARRAY_SIZE (elfNN_aarch64_howto_table
) - 1; ++i
)
1872 if (elfNN_aarch64_howto_table
[i
].type
!= 0)
1873 offsets
[elfNN_aarch64_howto_table
[i
].type
] = i
;
1875 initialized_p
= TRUE
;
1878 if (r_type
== R_AARCH64_NONE
|| r_type
== R_AARCH64_NULL
)
1879 return BFD_RELOC_AARCH64_NONE
;
1881 /* PR 17512: file: b371e70a. */
1882 if (r_type
>= R_AARCH64_end
)
1884 _bfd_error_handler (_("Invalid AArch64 reloc number: %d"), r_type
);
1885 bfd_set_error (bfd_error_bad_value
);
1886 return BFD_RELOC_AARCH64_NONE
;
1889 return BFD_RELOC_AARCH64_RELOC_START
+ offsets
[r_type
];
1892 struct elf_aarch64_reloc_map
1894 bfd_reloc_code_real_type from
;
1895 bfd_reloc_code_real_type to
;
1898 /* Map bfd generic reloc to AArch64-specific reloc. */
1899 static const struct elf_aarch64_reloc_map elf_aarch64_reloc_map
[] =
1901 {BFD_RELOC_NONE
, BFD_RELOC_AARCH64_NONE
},
1903 /* Basic data relocations. */
1904 {BFD_RELOC_CTOR
, BFD_RELOC_AARCH64_NN
},
1905 {BFD_RELOC_64
, BFD_RELOC_AARCH64_64
},
1906 {BFD_RELOC_32
, BFD_RELOC_AARCH64_32
},
1907 {BFD_RELOC_16
, BFD_RELOC_AARCH64_16
},
1908 {BFD_RELOC_64_PCREL
, BFD_RELOC_AARCH64_64_PCREL
},
1909 {BFD_RELOC_32_PCREL
, BFD_RELOC_AARCH64_32_PCREL
},
1910 {BFD_RELOC_16_PCREL
, BFD_RELOC_AARCH64_16_PCREL
},
1913 /* Given the bfd internal relocation enumerator in CODE, return the
1914 corresponding howto entry. */
1916 static reloc_howto_type
*
1917 elfNN_aarch64_howto_from_bfd_reloc (bfd_reloc_code_real_type code
)
1921 /* Convert bfd generic reloc to AArch64-specific reloc. */
1922 if (code
< BFD_RELOC_AARCH64_RELOC_START
1923 || code
> BFD_RELOC_AARCH64_RELOC_END
)
1924 for (i
= 0; i
< ARRAY_SIZE (elf_aarch64_reloc_map
); i
++)
1925 if (elf_aarch64_reloc_map
[i
].from
== code
)
1927 code
= elf_aarch64_reloc_map
[i
].to
;
1931 if (code
> BFD_RELOC_AARCH64_RELOC_START
1932 && code
< BFD_RELOC_AARCH64_RELOC_END
)
1933 if (elfNN_aarch64_howto_table
[code
- BFD_RELOC_AARCH64_RELOC_START
].type
)
1934 return &elfNN_aarch64_howto_table
[code
- BFD_RELOC_AARCH64_RELOC_START
];
1936 if (code
== BFD_RELOC_AARCH64_NONE
)
1937 return &elfNN_aarch64_howto_none
;
1942 static reloc_howto_type
*
1943 elfNN_aarch64_howto_from_type (unsigned int r_type
)
1945 bfd_reloc_code_real_type val
;
1946 reloc_howto_type
*howto
;
1951 bfd_set_error (bfd_error_bad_value
);
1956 if (r_type
== R_AARCH64_NONE
)
1957 return &elfNN_aarch64_howto_none
;
1959 val
= elfNN_aarch64_bfd_reloc_from_type (r_type
);
1960 howto
= elfNN_aarch64_howto_from_bfd_reloc (val
);
1965 bfd_set_error (bfd_error_bad_value
);
1970 elfNN_aarch64_info_to_howto (bfd
*abfd ATTRIBUTE_UNUSED
, arelent
*bfd_reloc
,
1971 Elf_Internal_Rela
*elf_reloc
)
1973 unsigned int r_type
;
1975 r_type
= ELFNN_R_TYPE (elf_reloc
->r_info
);
1976 bfd_reloc
->howto
= elfNN_aarch64_howto_from_type (r_type
);
1979 static reloc_howto_type
*
1980 elfNN_aarch64_reloc_type_lookup (bfd
*abfd ATTRIBUTE_UNUSED
,
1981 bfd_reloc_code_real_type code
)
1983 reloc_howto_type
*howto
= elfNN_aarch64_howto_from_bfd_reloc (code
);
1988 bfd_set_error (bfd_error_bad_value
);
1992 static reloc_howto_type
*
1993 elfNN_aarch64_reloc_name_lookup (bfd
*abfd ATTRIBUTE_UNUSED
,
1998 for (i
= 1; i
< ARRAY_SIZE (elfNN_aarch64_howto_table
) - 1; ++i
)
1999 if (elfNN_aarch64_howto_table
[i
].name
!= NULL
2000 && strcasecmp (elfNN_aarch64_howto_table
[i
].name
, r_name
) == 0)
2001 return &elfNN_aarch64_howto_table
[i
];
2006 #define TARGET_LITTLE_SYM aarch64_elfNN_le_vec
2007 #define TARGET_LITTLE_NAME "elfNN-littleaarch64"
2008 #define TARGET_BIG_SYM aarch64_elfNN_be_vec
2009 #define TARGET_BIG_NAME "elfNN-bigaarch64"
2011 /* The linker script knows the section names for placement.
2012 The entry_names are used to do simple name mangling on the stubs.
2013 Given a function name, and its type, the stub can be found. The
2014 name can be changed. The only requirement is the %s be present. */
2015 #define STUB_ENTRY_NAME "__%s_veneer"
2017 /* The name of the dynamic interpreter. This is put in the .interp
2019 #define ELF_DYNAMIC_INTERPRETER "/lib/ld.so.1"
2021 #define AARCH64_MAX_FWD_BRANCH_OFFSET \
2022 (((1 << 25) - 1) << 2)
2023 #define AARCH64_MAX_BWD_BRANCH_OFFSET \
2026 #define AARCH64_MAX_ADRP_IMM ((1 << 20) - 1)
2027 #define AARCH64_MIN_ADRP_IMM (-(1 << 20))
2030 aarch64_valid_for_adrp_p (bfd_vma value
, bfd_vma place
)
2032 bfd_signed_vma offset
= (bfd_signed_vma
) (PG (value
) - PG (place
)) >> 12;
2033 return offset
<= AARCH64_MAX_ADRP_IMM
&& offset
>= AARCH64_MIN_ADRP_IMM
;
2037 aarch64_valid_branch_p (bfd_vma value
, bfd_vma place
)
2039 bfd_signed_vma offset
= (bfd_signed_vma
) (value
- place
);
2040 return (offset
<= AARCH64_MAX_FWD_BRANCH_OFFSET
2041 && offset
>= AARCH64_MAX_BWD_BRANCH_OFFSET
);
2044 static const uint32_t aarch64_adrp_branch_stub
[] =
2046 0x90000010, /* adrp ip0, X */
2047 /* R_AARCH64_ADR_HI21_PCREL(X) */
2048 0x91000210, /* add ip0, ip0, :lo12:X */
2049 /* R_AARCH64_ADD_ABS_LO12_NC(X) */
2050 0xd61f0200, /* br ip0 */
2053 static const uint32_t aarch64_long_branch_stub
[] =
2056 0x58000090, /* ldr ip0, 1f */
2058 0x18000090, /* ldr wip0, 1f */
2060 0x10000011, /* adr ip1, #0 */
2061 0x8b110210, /* add ip0, ip0, ip1 */
2062 0xd61f0200, /* br ip0 */
2063 0x00000000, /* 1: .xword or .word
2064 R_AARCH64_PRELNN(X) + 12
2069 static const uint32_t aarch64_erratum_835769_stub
[] =
2071 0x00000000, /* Placeholder for multiply accumulate. */
2072 0x14000000, /* b <label> */
2075 static const uint32_t aarch64_erratum_843419_stub
[] =
2077 0x00000000, /* Placeholder for LDR instruction. */
2078 0x14000000, /* b <label> */
2081 /* Section name for stubs is the associated section name plus this
2083 #define STUB_SUFFIX ".stub"
2085 enum elf_aarch64_stub_type
2088 aarch64_stub_adrp_branch
,
2089 aarch64_stub_long_branch
,
2090 aarch64_stub_erratum_835769_veneer
,
2091 aarch64_stub_erratum_843419_veneer
,
2094 struct elf_aarch64_stub_hash_entry
2096 /* Base hash table entry structure. */
2097 struct bfd_hash_entry root
;
2099 /* The stub section. */
2102 /* Offset within stub_sec of the beginning of this stub. */
2103 bfd_vma stub_offset
;
2105 /* Given the symbol's value and its section we can determine its final
2106 value when building the stubs (so the stub knows where to jump). */
2107 bfd_vma target_value
;
2108 asection
*target_section
;
2110 enum elf_aarch64_stub_type stub_type
;
2112 /* The symbol table entry, if any, that this was derived from. */
2113 struct elf_aarch64_link_hash_entry
*h
;
2115 /* Destination symbol type */
2116 unsigned char st_type
;
2118 /* Where this stub is being called from, or, in the case of combined
2119 stub sections, the first input section in the group. */
2122 /* The name for the local symbol at the start of this stub. The
2123 stub name in the hash table has to be unique; this does not, so
2124 it can be friendlier. */
2127 /* The instruction which caused this stub to be generated (only valid for
2128 erratum 835769 workaround stubs at present). */
2129 uint32_t veneered_insn
;
2131 /* In an erratum 843419 workaround stub, the ADRP instruction offset. */
2132 bfd_vma adrp_offset
;
2135 /* Used to build a map of a section. This is required for mixed-endian
2138 typedef struct elf_elf_section_map
2143 elf_aarch64_section_map
;
2146 typedef struct _aarch64_elf_section_data
2148 struct bfd_elf_section_data elf
;
2149 unsigned int mapcount
;
2150 unsigned int mapsize
;
2151 elf_aarch64_section_map
*map
;
2153 _aarch64_elf_section_data
;
2155 #define elf_aarch64_section_data(sec) \
2156 ((_aarch64_elf_section_data *) elf_section_data (sec))
2158 /* The size of the thread control block which is defined to be two pointers. */
2159 #define TCB_SIZE (ARCH_SIZE/8)*2
2161 struct elf_aarch64_local_symbol
2163 unsigned int got_type
;
2164 bfd_signed_vma got_refcount
;
2167 /* Offset of the GOTPLT entry reserved for the TLS descriptor. The
2168 offset is from the end of the jump table and reserved entries
2171 The magic value (bfd_vma) -1 indicates that an offset has not be
2173 bfd_vma tlsdesc_got_jump_table_offset
;
2176 struct elf_aarch64_obj_tdata
2178 struct elf_obj_tdata root
;
2180 /* local symbol descriptors */
2181 struct elf_aarch64_local_symbol
*locals
;
2183 /* Zero to warn when linking objects with incompatible enum sizes. */
2184 int no_enum_size_warning
;
2186 /* Zero to warn when linking objects with incompatible wchar_t sizes. */
2187 int no_wchar_size_warning
;
2190 #define elf_aarch64_tdata(bfd) \
2191 ((struct elf_aarch64_obj_tdata *) (bfd)->tdata.any)
2193 #define elf_aarch64_locals(bfd) (elf_aarch64_tdata (bfd)->locals)
2195 #define is_aarch64_elf(bfd) \
2196 (bfd_get_flavour (bfd) == bfd_target_elf_flavour \
2197 && elf_tdata (bfd) != NULL \
2198 && elf_object_id (bfd) == AARCH64_ELF_DATA)
2201 elfNN_aarch64_mkobject (bfd
*abfd
)
2203 return bfd_elf_allocate_object (abfd
, sizeof (struct elf_aarch64_obj_tdata
),
2207 #define elf_aarch64_hash_entry(ent) \
2208 ((struct elf_aarch64_link_hash_entry *)(ent))
2210 #define GOT_UNKNOWN 0
2211 #define GOT_NORMAL 1
2212 #define GOT_TLS_GD 2
2213 #define GOT_TLS_IE 4
2214 #define GOT_TLSDESC_GD 8
2216 #define GOT_TLS_GD_ANY_P(type) ((type & GOT_TLS_GD) || (type & GOT_TLSDESC_GD))
2218 /* AArch64 ELF linker hash entry. */
2219 struct elf_aarch64_link_hash_entry
2221 struct elf_link_hash_entry root
;
2223 /* Track dynamic relocs copied for this symbol. */
2224 struct elf_dyn_relocs
*dyn_relocs
;
2226 /* Since PLT entries have variable size, we need to record the
2227 index into .got.plt instead of recomputing it from the PLT
2229 bfd_signed_vma plt_got_offset
;
2231 /* Bit mask representing the type of GOT entry(s) if any required by
2233 unsigned int got_type
;
2235 /* A pointer to the most recently used stub hash entry against this
2237 struct elf_aarch64_stub_hash_entry
*stub_cache
;
2239 /* Offset of the GOTPLT entry reserved for the TLS descriptor. The offset
2240 is from the end of the jump table and reserved entries within the PLTGOT.
2242 The magic value (bfd_vma) -1 indicates that an offset has not
2244 bfd_vma tlsdesc_got_jump_table_offset
;
2248 elfNN_aarch64_symbol_got_type (struct elf_link_hash_entry
*h
,
2250 unsigned long r_symndx
)
2253 return elf_aarch64_hash_entry (h
)->got_type
;
2255 if (! elf_aarch64_locals (abfd
))
2258 return elf_aarch64_locals (abfd
)[r_symndx
].got_type
;
2261 /* Get the AArch64 elf linker hash table from a link_info structure. */
2262 #define elf_aarch64_hash_table(info) \
2263 ((struct elf_aarch64_link_hash_table *) ((info)->hash))
2265 #define aarch64_stub_hash_lookup(table, string, create, copy) \
2266 ((struct elf_aarch64_stub_hash_entry *) \
2267 bfd_hash_lookup ((table), (string), (create), (copy)))
2269 /* AArch64 ELF linker hash table. */
2270 struct elf_aarch64_link_hash_table
2272 /* The main hash table. */
2273 struct elf_link_hash_table root
;
2275 /* Nonzero to force PIC branch veneers. */
2278 /* Fix erratum 835769. */
2279 int fix_erratum_835769
;
2281 /* Fix erratum 843419. */
2282 int fix_erratum_843419
;
2284 /* Enable ADRP->ADR rewrite for erratum 843419 workaround. */
2285 int fix_erratum_843419_adr
;
2287 /* The number of bytes in the initial entry in the PLT. */
2288 bfd_size_type plt_header_size
;
2290 /* The number of bytes in the subsequent PLT etries. */
2291 bfd_size_type plt_entry_size
;
2293 /* Short-cuts to get to dynamic linker sections. */
2297 /* Small local sym cache. */
2298 struct sym_cache sym_cache
;
2300 /* For convenience in allocate_dynrelocs. */
2303 /* The amount of space used by the reserved portion of the sgotplt
2304 section, plus whatever space is used by the jump slots. */
2305 bfd_vma sgotplt_jump_table_size
;
2307 /* The stub hash table. */
2308 struct bfd_hash_table stub_hash_table
;
2310 /* Linker stub bfd. */
2313 /* Linker call-backs. */
2314 asection
*(*add_stub_section
) (const char *, asection
*);
2315 void (*layout_sections_again
) (void);
2317 /* Array to keep track of which stub sections have been created, and
2318 information on stub grouping. */
2321 /* This is the section to which stubs in the group will be
2324 /* The stub section. */
2328 /* Assorted information used by elfNN_aarch64_size_stubs. */
2329 unsigned int bfd_count
;
2330 unsigned int top_index
;
2331 asection
**input_list
;
2333 /* The offset into splt of the PLT entry for the TLS descriptor
2334 resolver. Special values are 0, if not necessary (or not found
2335 to be necessary yet), and -1 if needed but not determined
2337 bfd_vma tlsdesc_plt
;
2339 /* The GOT offset for the lazy trampoline. Communicated to the
2340 loader via DT_TLSDESC_GOT. The magic value (bfd_vma) -1
2341 indicates an offset is not allocated. */
2342 bfd_vma dt_tlsdesc_got
;
2344 /* Used by local STT_GNU_IFUNC symbols. */
2345 htab_t loc_hash_table
;
2346 void * loc_hash_memory
;
2349 /* Create an entry in an AArch64 ELF linker hash table. */
2351 static struct bfd_hash_entry
*
2352 elfNN_aarch64_link_hash_newfunc (struct bfd_hash_entry
*entry
,
2353 struct bfd_hash_table
*table
,
2356 struct elf_aarch64_link_hash_entry
*ret
=
2357 (struct elf_aarch64_link_hash_entry
*) entry
;
2359 /* Allocate the structure if it has not already been allocated by a
2362 ret
= bfd_hash_allocate (table
,
2363 sizeof (struct elf_aarch64_link_hash_entry
));
2365 return (struct bfd_hash_entry
*) ret
;
2367 /* Call the allocation method of the superclass. */
2368 ret
= ((struct elf_aarch64_link_hash_entry
*)
2369 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry
*) ret
,
2373 ret
->dyn_relocs
= NULL
;
2374 ret
->got_type
= GOT_UNKNOWN
;
2375 ret
->plt_got_offset
= (bfd_vma
) - 1;
2376 ret
->stub_cache
= NULL
;
2377 ret
->tlsdesc_got_jump_table_offset
= (bfd_vma
) - 1;
2380 return (struct bfd_hash_entry
*) ret
;
2383 /* Initialize an entry in the stub hash table. */
2385 static struct bfd_hash_entry
*
2386 stub_hash_newfunc (struct bfd_hash_entry
*entry
,
2387 struct bfd_hash_table
*table
, const char *string
)
2389 /* Allocate the structure if it has not already been allocated by a
2393 entry
= bfd_hash_allocate (table
,
2395 elf_aarch64_stub_hash_entry
));
2400 /* Call the allocation method of the superclass. */
2401 entry
= bfd_hash_newfunc (entry
, table
, string
);
2404 struct elf_aarch64_stub_hash_entry
*eh
;
2406 /* Initialize the local fields. */
2407 eh
= (struct elf_aarch64_stub_hash_entry
*) entry
;
2408 eh
->adrp_offset
= 0;
2409 eh
->stub_sec
= NULL
;
2410 eh
->stub_offset
= 0;
2411 eh
->target_value
= 0;
2412 eh
->target_section
= NULL
;
2413 eh
->stub_type
= aarch64_stub_none
;
2421 /* Compute a hash of a local hash entry. We use elf_link_hash_entry
2422 for local symbol so that we can handle local STT_GNU_IFUNC symbols
2423 as global symbol. We reuse indx and dynstr_index for local symbol
2424 hash since they aren't used by global symbols in this backend. */
2427 elfNN_aarch64_local_htab_hash (const void *ptr
)
2429 struct elf_link_hash_entry
*h
2430 = (struct elf_link_hash_entry
*) ptr
;
2431 return ELF_LOCAL_SYMBOL_HASH (h
->indx
, h
->dynstr_index
);
2434 /* Compare local hash entries. */
2437 elfNN_aarch64_local_htab_eq (const void *ptr1
, const void *ptr2
)
2439 struct elf_link_hash_entry
*h1
2440 = (struct elf_link_hash_entry
*) ptr1
;
2441 struct elf_link_hash_entry
*h2
2442 = (struct elf_link_hash_entry
*) ptr2
;
2444 return h1
->indx
== h2
->indx
&& h1
->dynstr_index
== h2
->dynstr_index
;
2447 /* Find and/or create a hash entry for local symbol. */
2449 static struct elf_link_hash_entry
*
2450 elfNN_aarch64_get_local_sym_hash (struct elf_aarch64_link_hash_table
*htab
,
2451 bfd
*abfd
, const Elf_Internal_Rela
*rel
,
2454 struct elf_aarch64_link_hash_entry e
, *ret
;
2455 asection
*sec
= abfd
->sections
;
2456 hashval_t h
= ELF_LOCAL_SYMBOL_HASH (sec
->id
,
2457 ELFNN_R_SYM (rel
->r_info
));
2460 e
.root
.indx
= sec
->id
;
2461 e
.root
.dynstr_index
= ELFNN_R_SYM (rel
->r_info
);
2462 slot
= htab_find_slot_with_hash (htab
->loc_hash_table
, &e
, h
,
2463 create
? INSERT
: NO_INSERT
);
2470 ret
= (struct elf_aarch64_link_hash_entry
*) *slot
;
2474 ret
= (struct elf_aarch64_link_hash_entry
*)
2475 objalloc_alloc ((struct objalloc
*) htab
->loc_hash_memory
,
2476 sizeof (struct elf_aarch64_link_hash_entry
));
2479 memset (ret
, 0, sizeof (*ret
));
2480 ret
->root
.indx
= sec
->id
;
2481 ret
->root
.dynstr_index
= ELFNN_R_SYM (rel
->r_info
);
2482 ret
->root
.dynindx
= -1;
2488 /* Copy the extra info we tack onto an elf_link_hash_entry. */
2491 elfNN_aarch64_copy_indirect_symbol (struct bfd_link_info
*info
,
2492 struct elf_link_hash_entry
*dir
,
2493 struct elf_link_hash_entry
*ind
)
2495 struct elf_aarch64_link_hash_entry
*edir
, *eind
;
2497 edir
= (struct elf_aarch64_link_hash_entry
*) dir
;
2498 eind
= (struct elf_aarch64_link_hash_entry
*) ind
;
2500 if (eind
->dyn_relocs
!= NULL
)
2502 if (edir
->dyn_relocs
!= NULL
)
2504 struct elf_dyn_relocs
**pp
;
2505 struct elf_dyn_relocs
*p
;
2507 /* Add reloc counts against the indirect sym to the direct sym
2508 list. Merge any entries against the same section. */
2509 for (pp
= &eind
->dyn_relocs
; (p
= *pp
) != NULL
;)
2511 struct elf_dyn_relocs
*q
;
2513 for (q
= edir
->dyn_relocs
; q
!= NULL
; q
= q
->next
)
2514 if (q
->sec
== p
->sec
)
2516 q
->pc_count
+= p
->pc_count
;
2517 q
->count
+= p
->count
;
2524 *pp
= edir
->dyn_relocs
;
2527 edir
->dyn_relocs
= eind
->dyn_relocs
;
2528 eind
->dyn_relocs
= NULL
;
2531 if (ind
->root
.type
== bfd_link_hash_indirect
)
2533 /* Copy over PLT info. */
2534 if (dir
->got
.refcount
<= 0)
2536 edir
->got_type
= eind
->got_type
;
2537 eind
->got_type
= GOT_UNKNOWN
;
2541 _bfd_elf_link_hash_copy_indirect (info
, dir
, ind
);
2544 /* Destroy an AArch64 elf linker hash table. */
2547 elfNN_aarch64_link_hash_table_free (bfd
*obfd
)
2549 struct elf_aarch64_link_hash_table
*ret
2550 = (struct elf_aarch64_link_hash_table
*) obfd
->link
.hash
;
2552 if (ret
->loc_hash_table
)
2553 htab_delete (ret
->loc_hash_table
);
2554 if (ret
->loc_hash_memory
)
2555 objalloc_free ((struct objalloc
*) ret
->loc_hash_memory
);
2557 bfd_hash_table_free (&ret
->stub_hash_table
);
2558 _bfd_elf_link_hash_table_free (obfd
);
2561 /* Create an AArch64 elf linker hash table. */
2563 static struct bfd_link_hash_table
*
2564 elfNN_aarch64_link_hash_table_create (bfd
*abfd
)
2566 struct elf_aarch64_link_hash_table
*ret
;
2567 bfd_size_type amt
= sizeof (struct elf_aarch64_link_hash_table
);
2569 ret
= bfd_zmalloc (amt
);
2573 if (!_bfd_elf_link_hash_table_init
2574 (&ret
->root
, abfd
, elfNN_aarch64_link_hash_newfunc
,
2575 sizeof (struct elf_aarch64_link_hash_entry
), AARCH64_ELF_DATA
))
2581 ret
->plt_header_size
= PLT_ENTRY_SIZE
;
2582 ret
->plt_entry_size
= PLT_SMALL_ENTRY_SIZE
;
2584 ret
->dt_tlsdesc_got
= (bfd_vma
) - 1;
2586 if (!bfd_hash_table_init (&ret
->stub_hash_table
, stub_hash_newfunc
,
2587 sizeof (struct elf_aarch64_stub_hash_entry
)))
2589 _bfd_elf_link_hash_table_free (abfd
);
2593 ret
->loc_hash_table
= htab_try_create (1024,
2594 elfNN_aarch64_local_htab_hash
,
2595 elfNN_aarch64_local_htab_eq
,
2597 ret
->loc_hash_memory
= objalloc_create ();
2598 if (!ret
->loc_hash_table
|| !ret
->loc_hash_memory
)
2600 elfNN_aarch64_link_hash_table_free (abfd
);
2603 ret
->root
.root
.hash_table_free
= elfNN_aarch64_link_hash_table_free
;
2605 return &ret
->root
.root
;
2609 aarch64_relocate (unsigned int r_type
, bfd
*input_bfd
, asection
*input_section
,
2610 bfd_vma offset
, bfd_vma value
)
2612 reloc_howto_type
*howto
;
2615 howto
= elfNN_aarch64_howto_from_type (r_type
);
2616 place
= (input_section
->output_section
->vma
+ input_section
->output_offset
2619 r_type
= elfNN_aarch64_bfd_reloc_from_type (r_type
);
2620 value
= _bfd_aarch64_elf_resolve_relocation (r_type
, place
, value
, 0, FALSE
);
2621 return _bfd_aarch64_elf_put_addend (input_bfd
,
2622 input_section
->contents
+ offset
, r_type
,
2626 static enum elf_aarch64_stub_type
2627 aarch64_select_branch_stub (bfd_vma value
, bfd_vma place
)
2629 if (aarch64_valid_for_adrp_p (value
, place
))
2630 return aarch64_stub_adrp_branch
;
2631 return aarch64_stub_long_branch
;
2634 /* Determine the type of stub needed, if any, for a call. */
2636 static enum elf_aarch64_stub_type
2637 aarch64_type_of_stub (struct bfd_link_info
*info
,
2638 asection
*input_sec
,
2639 const Elf_Internal_Rela
*rel
,
2641 unsigned char st_type
,
2642 struct elf_aarch64_link_hash_entry
*hash
,
2643 bfd_vma destination
)
2646 bfd_signed_vma branch_offset
;
2647 unsigned int r_type
;
2648 struct elf_aarch64_link_hash_table
*globals
;
2649 enum elf_aarch64_stub_type stub_type
= aarch64_stub_none
;
2650 bfd_boolean via_plt_p
;
2652 if (st_type
!= STT_FUNC
2653 && (sym_sec
!= bfd_abs_section_ptr
))
2656 globals
= elf_aarch64_hash_table (info
);
2657 via_plt_p
= (globals
->root
.splt
!= NULL
&& hash
!= NULL
2658 && hash
->root
.plt
.offset
!= (bfd_vma
) - 1);
2659 /* Make sure call to plt stub can fit into the branch range. */
2661 destination
= (globals
->root
.splt
->output_section
->vma
2662 + globals
->root
.splt
->output_offset
2663 + hash
->root
.plt
.offset
);
2665 /* Determine where the call point is. */
2666 location
= (input_sec
->output_offset
2667 + input_sec
->output_section
->vma
+ rel
->r_offset
);
2669 branch_offset
= (bfd_signed_vma
) (destination
- location
);
2671 r_type
= ELFNN_R_TYPE (rel
->r_info
);
2673 /* We don't want to redirect any old unconditional jump in this way,
2674 only one which is being used for a sibcall, where it is
2675 acceptable for the IP0 and IP1 registers to be clobbered. */
2676 if ((r_type
== AARCH64_R (CALL26
) || r_type
== AARCH64_R (JUMP26
))
2677 && (branch_offset
> AARCH64_MAX_FWD_BRANCH_OFFSET
2678 || branch_offset
< AARCH64_MAX_BWD_BRANCH_OFFSET
))
2680 stub_type
= aarch64_stub_long_branch
;
2686 /* Build a name for an entry in the stub hash table. */
2689 elfNN_aarch64_stub_name (const asection
*input_section
,
2690 const asection
*sym_sec
,
2691 const struct elf_aarch64_link_hash_entry
*hash
,
2692 const Elf_Internal_Rela
*rel
)
2699 len
= 8 + 1 + strlen (hash
->root
.root
.root
.string
) + 1 + 16 + 1;
2700 stub_name
= bfd_malloc (len
);
2701 if (stub_name
!= NULL
)
2702 snprintf (stub_name
, len
, "%08x_%s+%" BFD_VMA_FMT
"x",
2703 (unsigned int) input_section
->id
,
2704 hash
->root
.root
.root
.string
,
2709 len
= 8 + 1 + 8 + 1 + 8 + 1 + 16 + 1;
2710 stub_name
= bfd_malloc (len
);
2711 if (stub_name
!= NULL
)
2712 snprintf (stub_name
, len
, "%08x_%x:%x+%" BFD_VMA_FMT
"x",
2713 (unsigned int) input_section
->id
,
2714 (unsigned int) sym_sec
->id
,
2715 (unsigned int) ELFNN_R_SYM (rel
->r_info
),
2722 /* Look up an entry in the stub hash. Stub entries are cached because
2723 creating the stub name takes a bit of time. */
2725 static struct elf_aarch64_stub_hash_entry
*
2726 elfNN_aarch64_get_stub_entry (const asection
*input_section
,
2727 const asection
*sym_sec
,
2728 struct elf_link_hash_entry
*hash
,
2729 const Elf_Internal_Rela
*rel
,
2730 struct elf_aarch64_link_hash_table
*htab
)
2732 struct elf_aarch64_stub_hash_entry
*stub_entry
;
2733 struct elf_aarch64_link_hash_entry
*h
=
2734 (struct elf_aarch64_link_hash_entry
*) hash
;
2735 const asection
*id_sec
;
2737 if ((input_section
->flags
& SEC_CODE
) == 0)
2740 /* If this input section is part of a group of sections sharing one
2741 stub section, then use the id of the first section in the group.
2742 Stub names need to include a section id, as there may well be
2743 more than one stub used to reach say, printf, and we need to
2744 distinguish between them. */
2745 id_sec
= htab
->stub_group
[input_section
->id
].link_sec
;
2747 if (h
!= NULL
&& h
->stub_cache
!= NULL
2748 && h
->stub_cache
->h
== h
&& h
->stub_cache
->id_sec
== id_sec
)
2750 stub_entry
= h
->stub_cache
;
2756 stub_name
= elfNN_aarch64_stub_name (id_sec
, sym_sec
, h
, rel
);
2757 if (stub_name
== NULL
)
2760 stub_entry
= aarch64_stub_hash_lookup (&htab
->stub_hash_table
,
2761 stub_name
, FALSE
, FALSE
);
2763 h
->stub_cache
= stub_entry
;
2772 /* Create a stub section. */
2775 _bfd_aarch64_create_stub_section (asection
*section
,
2776 struct elf_aarch64_link_hash_table
*htab
)
2782 namelen
= strlen (section
->name
);
2783 len
= namelen
+ sizeof (STUB_SUFFIX
);
2784 s_name
= bfd_alloc (htab
->stub_bfd
, len
);
2788 memcpy (s_name
, section
->name
, namelen
);
2789 memcpy (s_name
+ namelen
, STUB_SUFFIX
, sizeof (STUB_SUFFIX
));
2790 return (*htab
->add_stub_section
) (s_name
, section
);
2794 /* Find or create a stub section for a link section.
2796 Fix or create the stub section used to collect stubs attached to
2797 the specified link section. */
2800 _bfd_aarch64_get_stub_for_link_section (asection
*link_section
,
2801 struct elf_aarch64_link_hash_table
*htab
)
2803 if (htab
->stub_group
[link_section
->id
].stub_sec
== NULL
)
2804 htab
->stub_group
[link_section
->id
].stub_sec
2805 = _bfd_aarch64_create_stub_section (link_section
, htab
);
2806 return htab
->stub_group
[link_section
->id
].stub_sec
;
2810 /* Find or create a stub section in the stub group for an input
2814 _bfd_aarch64_create_or_find_stub_sec (asection
*section
,
2815 struct elf_aarch64_link_hash_table
*htab
)
2817 asection
*link_sec
= htab
->stub_group
[section
->id
].link_sec
;
2818 return _bfd_aarch64_get_stub_for_link_section (link_sec
, htab
);
2822 /* Add a new stub entry in the stub group associated with an input
2823 section to the stub hash. Not all fields of the new stub entry are
2826 static struct elf_aarch64_stub_hash_entry
*
2827 _bfd_aarch64_add_stub_entry_in_group (const char *stub_name
,
2829 struct elf_aarch64_link_hash_table
*htab
)
2833 struct elf_aarch64_stub_hash_entry
*stub_entry
;
2835 link_sec
= htab
->stub_group
[section
->id
].link_sec
;
2836 stub_sec
= _bfd_aarch64_create_or_find_stub_sec (section
, htab
);
2838 /* Enter this entry into the linker stub hash table. */
2839 stub_entry
= aarch64_stub_hash_lookup (&htab
->stub_hash_table
, stub_name
,
2841 if (stub_entry
== NULL
)
2843 (*_bfd_error_handler
) (_("%s: cannot create stub entry %s"),
2844 section
->owner
, stub_name
);
2848 stub_entry
->stub_sec
= stub_sec
;
2849 stub_entry
->stub_offset
= 0;
2850 stub_entry
->id_sec
= link_sec
;
2855 /* Add a new stub entry in the final stub section to the stub hash.
2856 Not all fields of the new stub entry are initialised. */
2858 static struct elf_aarch64_stub_hash_entry
*
2859 _bfd_aarch64_add_stub_entry_after (const char *stub_name
,
2860 asection
*link_section
,
2861 struct elf_aarch64_link_hash_table
*htab
)
2864 struct elf_aarch64_stub_hash_entry
*stub_entry
;
2866 stub_sec
= _bfd_aarch64_get_stub_for_link_section (link_section
, htab
);
2867 stub_entry
= aarch64_stub_hash_lookup (&htab
->stub_hash_table
, stub_name
,
2869 if (stub_entry
== NULL
)
2871 (*_bfd_error_handler
) (_("cannot create stub entry %s"), stub_name
);
2875 stub_entry
->stub_sec
= stub_sec
;
2876 stub_entry
->stub_offset
= 0;
2877 stub_entry
->id_sec
= link_section
;
2884 aarch64_build_one_stub (struct bfd_hash_entry
*gen_entry
,
2885 void *in_arg ATTRIBUTE_UNUSED
)
2887 struct elf_aarch64_stub_hash_entry
*stub_entry
;
2892 bfd_vma veneered_insn_loc
;
2893 bfd_vma veneer_entry_loc
;
2894 bfd_signed_vma branch_offset
= 0;
2895 unsigned int template_size
;
2896 const uint32_t *template;
2899 /* Massage our args to the form they really have. */
2900 stub_entry
= (struct elf_aarch64_stub_hash_entry
*) gen_entry
;
2902 stub_sec
= stub_entry
->stub_sec
;
2904 /* Make a note of the offset within the stubs for this entry. */
2905 stub_entry
->stub_offset
= stub_sec
->size
;
2906 loc
= stub_sec
->contents
+ stub_entry
->stub_offset
;
2908 stub_bfd
= stub_sec
->owner
;
2910 /* This is the address of the stub destination. */
2911 sym_value
= (stub_entry
->target_value
2912 + stub_entry
->target_section
->output_offset
2913 + stub_entry
->target_section
->output_section
->vma
);
2915 if (stub_entry
->stub_type
== aarch64_stub_long_branch
)
2917 bfd_vma place
= (stub_entry
->stub_offset
+ stub_sec
->output_section
->vma
2918 + stub_sec
->output_offset
);
2920 /* See if we can relax the stub. */
2921 if (aarch64_valid_for_adrp_p (sym_value
, place
))
2922 stub_entry
->stub_type
= aarch64_select_branch_stub (sym_value
, place
);
2925 switch (stub_entry
->stub_type
)
2927 case aarch64_stub_adrp_branch
:
2928 template = aarch64_adrp_branch_stub
;
2929 template_size
= sizeof (aarch64_adrp_branch_stub
);
2931 case aarch64_stub_long_branch
:
2932 template = aarch64_long_branch_stub
;
2933 template_size
= sizeof (aarch64_long_branch_stub
);
2935 case aarch64_stub_erratum_835769_veneer
:
2936 template = aarch64_erratum_835769_stub
;
2937 template_size
= sizeof (aarch64_erratum_835769_stub
);
2939 case aarch64_stub_erratum_843419_veneer
:
2940 template = aarch64_erratum_843419_stub
;
2941 template_size
= sizeof (aarch64_erratum_843419_stub
);
2947 for (i
= 0; i
< (template_size
/ sizeof template[0]); i
++)
2949 bfd_putl32 (template[i
], loc
);
2953 template_size
= (template_size
+ 7) & ~7;
2954 stub_sec
->size
+= template_size
;
2956 switch (stub_entry
->stub_type
)
2958 case aarch64_stub_adrp_branch
:
2959 if (aarch64_relocate (AARCH64_R (ADR_PREL_PG_HI21
), stub_bfd
, stub_sec
,
2960 stub_entry
->stub_offset
, sym_value
))
2961 /* The stub would not have been relaxed if the offset was out
2965 if (aarch64_relocate (AARCH64_R (ADD_ABS_LO12_NC
), stub_bfd
, stub_sec
,
2966 stub_entry
->stub_offset
+ 4, sym_value
))
2970 case aarch64_stub_long_branch
:
2971 /* We want the value relative to the address 12 bytes back from the
2973 if (aarch64_relocate (AARCH64_R (PRELNN
), stub_bfd
, stub_sec
,
2974 stub_entry
->stub_offset
+ 16, sym_value
+ 12))
2978 case aarch64_stub_erratum_835769_veneer
:
2979 veneered_insn_loc
= stub_entry
->target_section
->output_section
->vma
2980 + stub_entry
->target_section
->output_offset
2981 + stub_entry
->target_value
;
2982 veneer_entry_loc
= stub_entry
->stub_sec
->output_section
->vma
2983 + stub_entry
->stub_sec
->output_offset
2984 + stub_entry
->stub_offset
;
2985 branch_offset
= veneered_insn_loc
- veneer_entry_loc
;
2986 branch_offset
>>= 2;
2987 branch_offset
&= 0x3ffffff;
2988 bfd_putl32 (stub_entry
->veneered_insn
,
2989 stub_sec
->contents
+ stub_entry
->stub_offset
);
2990 bfd_putl32 (template[1] | branch_offset
,
2991 stub_sec
->contents
+ stub_entry
->stub_offset
+ 4);
2994 case aarch64_stub_erratum_843419_veneer
:
2995 if (aarch64_relocate (AARCH64_R (JUMP26
), stub_bfd
, stub_sec
,
2996 stub_entry
->stub_offset
+ 4, sym_value
+ 4))
3007 /* As above, but don't actually build the stub. Just bump offset so
3008 we know stub section sizes. */
3011 aarch64_size_one_stub (struct bfd_hash_entry
*gen_entry
,
3012 void *in_arg ATTRIBUTE_UNUSED
)
3014 struct elf_aarch64_stub_hash_entry
*stub_entry
;
3017 /* Massage our args to the form they really have. */
3018 stub_entry
= (struct elf_aarch64_stub_hash_entry
*) gen_entry
;
3020 switch (stub_entry
->stub_type
)
3022 case aarch64_stub_adrp_branch
:
3023 size
= sizeof (aarch64_adrp_branch_stub
);
3025 case aarch64_stub_long_branch
:
3026 size
= sizeof (aarch64_long_branch_stub
);
3028 case aarch64_stub_erratum_835769_veneer
:
3029 size
= sizeof (aarch64_erratum_835769_stub
);
3031 case aarch64_stub_erratum_843419_veneer
:
3032 size
= sizeof (aarch64_erratum_843419_stub
);
3038 size
= (size
+ 7) & ~7;
3039 stub_entry
->stub_sec
->size
+= size
;
3043 /* External entry points for sizing and building linker stubs. */
3045 /* Set up various things so that we can make a list of input sections
3046 for each output section included in the link. Returns -1 on error,
3047 0 when no stubs will be needed, and 1 on success. */
3050 elfNN_aarch64_setup_section_lists (bfd
*output_bfd
,
3051 struct bfd_link_info
*info
)
3054 unsigned int bfd_count
;
3055 unsigned int top_id
, top_index
;
3057 asection
**input_list
, **list
;
3059 struct elf_aarch64_link_hash_table
*htab
=
3060 elf_aarch64_hash_table (info
);
3062 if (!is_elf_hash_table (htab
))
3065 /* Count the number of input BFDs and find the top input section id. */
3066 for (input_bfd
= info
->input_bfds
, bfd_count
= 0, top_id
= 0;
3067 input_bfd
!= NULL
; input_bfd
= input_bfd
->link
.next
)
3070 for (section
= input_bfd
->sections
;
3071 section
!= NULL
; section
= section
->next
)
3073 if (top_id
< section
->id
)
3074 top_id
= section
->id
;
3077 htab
->bfd_count
= bfd_count
;
3079 amt
= sizeof (struct map_stub
) * (top_id
+ 1);
3080 htab
->stub_group
= bfd_zmalloc (amt
);
3081 if (htab
->stub_group
== NULL
)
3084 /* We can't use output_bfd->section_count here to find the top output
3085 section index as some sections may have been removed, and
3086 _bfd_strip_section_from_output doesn't renumber the indices. */
3087 for (section
= output_bfd
->sections
, top_index
= 0;
3088 section
!= NULL
; section
= section
->next
)
3090 if (top_index
< section
->index
)
3091 top_index
= section
->index
;
3094 htab
->top_index
= top_index
;
3095 amt
= sizeof (asection
*) * (top_index
+ 1);
3096 input_list
= bfd_malloc (amt
);
3097 htab
->input_list
= input_list
;
3098 if (input_list
== NULL
)
3101 /* For sections we aren't interested in, mark their entries with a
3102 value we can check later. */
3103 list
= input_list
+ top_index
;
3105 *list
= bfd_abs_section_ptr
;
3106 while (list
-- != input_list
);
3108 for (section
= output_bfd
->sections
;
3109 section
!= NULL
; section
= section
->next
)
3111 if ((section
->flags
& SEC_CODE
) != 0)
3112 input_list
[section
->index
] = NULL
;
3118 /* Used by elfNN_aarch64_next_input_section and group_sections. */
3119 #define PREV_SEC(sec) (htab->stub_group[(sec)->id].link_sec)
3121 /* The linker repeatedly calls this function for each input section,
3122 in the order that input sections are linked into output sections.
3123 Build lists of input sections to determine groupings between which
3124 we may insert linker stubs. */
3127 elfNN_aarch64_next_input_section (struct bfd_link_info
*info
, asection
*isec
)
3129 struct elf_aarch64_link_hash_table
*htab
=
3130 elf_aarch64_hash_table (info
);
3132 if (isec
->output_section
->index
<= htab
->top_index
)
3134 asection
**list
= htab
->input_list
+ isec
->output_section
->index
;
3136 if (*list
!= bfd_abs_section_ptr
)
3138 /* Steal the link_sec pointer for our list. */
3139 /* This happens to make the list in reverse order,
3140 which is what we want. */
3141 PREV_SEC (isec
) = *list
;
3147 /* See whether we can group stub sections together. Grouping stub
3148 sections may result in fewer stubs. More importantly, we need to
3149 put all .init* and .fini* stubs at the beginning of the .init or
3150 .fini output sections respectively, because glibc splits the
3151 _init and _fini functions into multiple parts. Putting a stub in
3152 the middle of a function is not a good idea. */
3155 group_sections (struct elf_aarch64_link_hash_table
*htab
,
3156 bfd_size_type stub_group_size
,
3157 bfd_boolean stubs_always_before_branch
)
3159 asection
**list
= htab
->input_list
+ htab
->top_index
;
3163 asection
*tail
= *list
;
3165 if (tail
== bfd_abs_section_ptr
)
3168 while (tail
!= NULL
)
3172 bfd_size_type total
;
3176 while ((prev
= PREV_SEC (curr
)) != NULL
3177 && ((total
+= curr
->output_offset
- prev
->output_offset
)
3181 /* OK, the size from the start of CURR to the end is less
3182 than stub_group_size and thus can be handled by one stub
3183 section. (Or the tail section is itself larger than
3184 stub_group_size, in which case we may be toast.)
3185 We should really be keeping track of the total size of
3186 stubs added here, as stubs contribute to the final output
3190 prev
= PREV_SEC (tail
);
3191 /* Set up this stub group. */
3192 htab
->stub_group
[tail
->id
].link_sec
= curr
;
3194 while (tail
!= curr
&& (tail
= prev
) != NULL
);
3196 /* But wait, there's more! Input sections up to stub_group_size
3197 bytes before the stub section can be handled by it too. */
3198 if (!stubs_always_before_branch
)
3202 && ((total
+= tail
->output_offset
- prev
->output_offset
)
3206 prev
= PREV_SEC (tail
);
3207 htab
->stub_group
[tail
->id
].link_sec
= curr
;
3213 while (list
-- != htab
->input_list
);
3215 free (htab
->input_list
);
3220 #define AARCH64_BITS(x, pos, n) (((x) >> (pos)) & ((1 << (n)) - 1))
3222 #define AARCH64_RT(insn) AARCH64_BITS (insn, 0, 5)
3223 #define AARCH64_RT2(insn) AARCH64_BITS (insn, 10, 5)
3224 #define AARCH64_RA(insn) AARCH64_BITS (insn, 10, 5)
3225 #define AARCH64_RD(insn) AARCH64_BITS (insn, 0, 5)
3226 #define AARCH64_RN(insn) AARCH64_BITS (insn, 5, 5)
3227 #define AARCH64_RM(insn) AARCH64_BITS (insn, 16, 5)
3229 #define AARCH64_MAC(insn) (((insn) & 0xff000000) == 0x9b000000)
3230 #define AARCH64_BIT(insn, n) AARCH64_BITS (insn, n, 1)
3231 #define AARCH64_OP31(insn) AARCH64_BITS (insn, 21, 3)
3232 #define AARCH64_ZR 0x1f
3234 /* All ld/st ops. See C4-182 of the ARM ARM. The encoding space for
3235 LD_PCREL, LDST_RO, LDST_UI and LDST_UIMM cover prefetch ops. */
3237 #define AARCH64_LD(insn) (AARCH64_BIT (insn, 22) == 1)
3238 #define AARCH64_LDST(insn) (((insn) & 0x0a000000) == 0x08000000)
3239 #define AARCH64_LDST_EX(insn) (((insn) & 0x3f000000) == 0x08000000)
3240 #define AARCH64_LDST_PCREL(insn) (((insn) & 0x3b000000) == 0x18000000)
3241 #define AARCH64_LDST_NAP(insn) (((insn) & 0x3b800000) == 0x28000000)
3242 #define AARCH64_LDSTP_PI(insn) (((insn) & 0x3b800000) == 0x28800000)
3243 #define AARCH64_LDSTP_O(insn) (((insn) & 0x3b800000) == 0x29000000)
3244 #define AARCH64_LDSTP_PRE(insn) (((insn) & 0x3b800000) == 0x29800000)
3245 #define AARCH64_LDST_UI(insn) (((insn) & 0x3b200c00) == 0x38000000)
3246 #define AARCH64_LDST_PIIMM(insn) (((insn) & 0x3b200c00) == 0x38000400)
3247 #define AARCH64_LDST_U(insn) (((insn) & 0x3b200c00) == 0x38000800)
3248 #define AARCH64_LDST_PREIMM(insn) (((insn) & 0x3b200c00) == 0x38000c00)
3249 #define AARCH64_LDST_RO(insn) (((insn) & 0x3b200c00) == 0x38200800)
3250 #define AARCH64_LDST_UIMM(insn) (((insn) & 0x3b000000) == 0x39000000)
3251 #define AARCH64_LDST_SIMD_M(insn) (((insn) & 0xbfbf0000) == 0x0c000000)
3252 #define AARCH64_LDST_SIMD_M_PI(insn) (((insn) & 0xbfa00000) == 0x0c800000)
3253 #define AARCH64_LDST_SIMD_S(insn) (((insn) & 0xbf9f0000) == 0x0d000000)
3254 #define AARCH64_LDST_SIMD_S_PI(insn) (((insn) & 0xbf800000) == 0x0d800000)
3256 /* Classify an INSN if it is indeed a load/store.
3258 Return TRUE if INSN is a LD/ST instruction otherwise return FALSE.
3260 For scalar LD/ST instructions PAIR is FALSE, RT is returned and RT2
3263 For LD/ST pair instructions PAIR is TRUE, RT and RT2 are returned.
3268 aarch64_mem_op_p (uint32_t insn
, unsigned int *rt
, unsigned int *rt2
,
3269 bfd_boolean
*pair
, bfd_boolean
*load
)
3277 /* Bail out quickly if INSN doesn't fall into the the load-store
3279 if (!AARCH64_LDST (insn
))
3284 if (AARCH64_LDST_EX (insn
))
3286 *rt
= AARCH64_RT (insn
);
3288 if (AARCH64_BIT (insn
, 21) == 1)
3291 *rt2
= AARCH64_RT2 (insn
);
3293 *load
= AARCH64_LD (insn
);
3296 else if (AARCH64_LDST_NAP (insn
)
3297 || AARCH64_LDSTP_PI (insn
)
3298 || AARCH64_LDSTP_O (insn
)
3299 || AARCH64_LDSTP_PRE (insn
))
3302 *rt
= AARCH64_RT (insn
);
3303 *rt2
= AARCH64_RT2 (insn
);
3304 *load
= AARCH64_LD (insn
);
3307 else if (AARCH64_LDST_PCREL (insn
)
3308 || AARCH64_LDST_UI (insn
)
3309 || AARCH64_LDST_PIIMM (insn
)
3310 || AARCH64_LDST_U (insn
)
3311 || AARCH64_LDST_PREIMM (insn
)
3312 || AARCH64_LDST_RO (insn
)
3313 || AARCH64_LDST_UIMM (insn
))
3315 *rt
= AARCH64_RT (insn
);
3317 if (AARCH64_LDST_PCREL (insn
))
3319 opc
= AARCH64_BITS (insn
, 22, 2);
3320 v
= AARCH64_BIT (insn
, 26);
3321 opc_v
= opc
| (v
<< 2);
3322 *load
= (opc_v
== 1 || opc_v
== 2 || opc_v
== 3
3323 || opc_v
== 5 || opc_v
== 7);
3326 else if (AARCH64_LDST_SIMD_M (insn
)
3327 || AARCH64_LDST_SIMD_M_PI (insn
))
3329 *rt
= AARCH64_RT (insn
);
3330 *load
= AARCH64_BIT (insn
, 22);
3331 opcode
= (insn
>> 12) & 0xf;
3358 else if (AARCH64_LDST_SIMD_S (insn
)
3359 || AARCH64_LDST_SIMD_S_PI (insn
))
3361 *rt
= AARCH64_RT (insn
);
3362 r
= (insn
>> 21) & 1;
3363 *load
= AARCH64_BIT (insn
, 22);
3364 opcode
= (insn
>> 13) & 0x7;
3376 *rt2
= *rt
+ (r
== 0 ? 2 : 3);
3384 *rt2
= *rt
+ (r
== 0 ? 2 : 3);
3396 /* Return TRUE if INSN is multiply-accumulate. */
3399 aarch64_mlxl_p (uint32_t insn
)
3401 uint32_t op31
= AARCH64_OP31 (insn
);
3403 if (AARCH64_MAC (insn
)
3404 && (op31
== 0 || op31
== 1 || op31
== 5)
3405 /* Exclude MUL instructions which are encoded as a multiple accumulate
3407 && AARCH64_RA (insn
) != AARCH64_ZR
)
3413 /* Some early revisions of the Cortex-A53 have an erratum (835769) whereby
3414 it is possible for a 64-bit multiply-accumulate instruction to generate an
3415 incorrect result. The details are quite complex and hard to
3416 determine statically, since branches in the code may exist in some
3417 circumstances, but all cases end with a memory (load, store, or
3418 prefetch) instruction followed immediately by the multiply-accumulate
3419 operation. We employ a linker patching technique, by moving the potentially
3420 affected multiply-accumulate instruction into a patch region and replacing
3421 the original instruction with a branch to the patch. This function checks
3422 if INSN_1 is the memory operation followed by a multiply-accumulate
3423 operation (INSN_2). Return TRUE if an erratum sequence is found, FALSE
3424 if INSN_1 and INSN_2 are safe. */
3427 aarch64_erratum_sequence (uint32_t insn_1
, uint32_t insn_2
)
3437 if (aarch64_mlxl_p (insn_2
)
3438 && aarch64_mem_op_p (insn_1
, &rt
, &rt2
, &pair
, &load
))
3440 /* Any SIMD memory op is independent of the subsequent MLA
3441 by definition of the erratum. */
3442 if (AARCH64_BIT (insn_1
, 26))
3445 /* If not SIMD, check for integer memory ops and MLA relationship. */
3446 rn
= AARCH64_RN (insn_2
);
3447 ra
= AARCH64_RA (insn_2
);
3448 rm
= AARCH64_RM (insn_2
);
3450 /* If this is a load and there's a true(RAW) dependency, we are safe
3451 and this is not an erratum sequence. */
3453 (rt
== rn
|| rt
== rm
|| rt
== ra
3454 || (pair
&& (rt2
== rn
|| rt2
== rm
|| rt2
== ra
))))
3457 /* We conservatively put out stubs for all other cases (including
3465 /* Used to order a list of mapping symbols by address. */
3468 elf_aarch64_compare_mapping (const void *a
, const void *b
)
3470 const elf_aarch64_section_map
*amap
= (const elf_aarch64_section_map
*) a
;
3471 const elf_aarch64_section_map
*bmap
= (const elf_aarch64_section_map
*) b
;
3473 if (amap
->vma
> bmap
->vma
)
3475 else if (amap
->vma
< bmap
->vma
)
3477 else if (amap
->type
> bmap
->type
)
3478 /* Ensure results do not depend on the host qsort for objects with
3479 multiple mapping symbols at the same address by sorting on type
3482 else if (amap
->type
< bmap
->type
)
3490 _bfd_aarch64_erratum_835769_stub_name (unsigned num_fixes
)
3492 char *stub_name
= (char *) bfd_malloc
3493 (strlen ("__erratum_835769_veneer_") + 16);
3494 sprintf (stub_name
,"__erratum_835769_veneer_%d", num_fixes
);
3498 /* Scan for Cortex-A53 erratum 835769 sequence.
3500 Return TRUE else FALSE on abnormal termination. */
3503 _bfd_aarch64_erratum_835769_scan (bfd
*input_bfd
,
3504 struct bfd_link_info
*info
,
3505 unsigned int *num_fixes_p
)
3508 struct elf_aarch64_link_hash_table
*htab
= elf_aarch64_hash_table (info
);
3509 unsigned int num_fixes
= *num_fixes_p
;
3514 for (section
= input_bfd
->sections
;
3516 section
= section
->next
)
3518 bfd_byte
*contents
= NULL
;
3519 struct _aarch64_elf_section_data
*sec_data
;
3522 if (elf_section_type (section
) != SHT_PROGBITS
3523 || (elf_section_flags (section
) & SHF_EXECINSTR
) == 0
3524 || (section
->flags
& SEC_EXCLUDE
) != 0
3525 || (section
->sec_info_type
== SEC_INFO_TYPE_JUST_SYMS
)
3526 || (section
->output_section
== bfd_abs_section_ptr
))
3529 if (elf_section_data (section
)->this_hdr
.contents
!= NULL
)
3530 contents
= elf_section_data (section
)->this_hdr
.contents
;
3531 else if (! bfd_malloc_and_get_section (input_bfd
, section
, &contents
))
3534 sec_data
= elf_aarch64_section_data (section
);
3536 qsort (sec_data
->map
, sec_data
->mapcount
,
3537 sizeof (elf_aarch64_section_map
), elf_aarch64_compare_mapping
);
3539 for (span
= 0; span
< sec_data
->mapcount
; span
++)
3541 unsigned int span_start
= sec_data
->map
[span
].vma
;
3542 unsigned int span_end
= ((span
== sec_data
->mapcount
- 1)
3543 ? sec_data
->map
[0].vma
+ section
->size
3544 : sec_data
->map
[span
+ 1].vma
);
3546 char span_type
= sec_data
->map
[span
].type
;
3548 if (span_type
== 'd')
3551 for (i
= span_start
; i
+ 4 < span_end
; i
+= 4)
3553 uint32_t insn_1
= bfd_getl32 (contents
+ i
);
3554 uint32_t insn_2
= bfd_getl32 (contents
+ i
+ 4);
3556 if (aarch64_erratum_sequence (insn_1
, insn_2
))
3558 struct elf_aarch64_stub_hash_entry
*stub_entry
;
3559 char *stub_name
= _bfd_aarch64_erratum_835769_stub_name (num_fixes
);
3563 stub_entry
= _bfd_aarch64_add_stub_entry_in_group (stub_name
,
3569 stub_entry
->stub_type
= aarch64_stub_erratum_835769_veneer
;
3570 stub_entry
->target_section
= section
;
3571 stub_entry
->target_value
= i
+ 4;
3572 stub_entry
->veneered_insn
= insn_2
;
3573 stub_entry
->output_name
= stub_name
;
3578 if (elf_section_data (section
)->this_hdr
.contents
== NULL
)
3582 *num_fixes_p
= num_fixes
;
3588 /* Test if instruction INSN is ADRP. */
3591 _bfd_aarch64_adrp_p (uint32_t insn
)
3593 return ((insn
& 0x9f000000) == 0x90000000);
3597 /* Helper predicate to look for cortex-a53 erratum 843419 sequence 1. */
3600 _bfd_aarch64_erratum_843419_sequence_p (uint32_t insn_1
, uint32_t insn_2
,
3608 return (aarch64_mem_op_p (insn_2
, &rt
, &rt2
, &pair
, &load
)
3611 && AARCH64_LDST_UIMM (insn_3
)
3612 && AARCH64_RN (insn_3
) == AARCH64_RD (insn_1
));
3616 /* Test for the presence of Cortex-A53 erratum 843419 instruction sequence.
3618 Return TRUE if section CONTENTS at offset I contains one of the
3619 erratum 843419 sequences, otherwise return FALSE. If a sequence is
3620 seen set P_VENEER_I to the offset of the final LOAD/STORE
3621 instruction in the sequence.
3625 _bfd_aarch64_erratum_843419_p (bfd_byte
*contents
, bfd_vma vma
,
3626 bfd_vma i
, bfd_vma span_end
,
3627 bfd_vma
*p_veneer_i
)
3629 uint32_t insn_1
= bfd_getl32 (contents
+ i
);
3631 if (!_bfd_aarch64_adrp_p (insn_1
))
3634 if (span_end
< i
+ 12)
3637 uint32_t insn_2
= bfd_getl32 (contents
+ i
+ 4);
3638 uint32_t insn_3
= bfd_getl32 (contents
+ i
+ 8);
3640 if ((vma
& 0xfff) != 0xff8 && (vma
& 0xfff) != 0xffc)
3643 if (_bfd_aarch64_erratum_843419_sequence_p (insn_1
, insn_2
, insn_3
))
3645 *p_veneer_i
= i
+ 8;
3649 if (span_end
< i
+ 16)
3652 uint32_t insn_4
= bfd_getl32 (contents
+ i
+ 12);
3654 if (_bfd_aarch64_erratum_843419_sequence_p (insn_1
, insn_2
, insn_4
))
3656 *p_veneer_i
= i
+ 12;
3664 /* Resize all stub sections. */
3667 _bfd_aarch64_resize_stubs (struct elf_aarch64_link_hash_table
*htab
)
3671 /* OK, we've added some stubs. Find out the new size of the
3673 for (section
= htab
->stub_bfd
->sections
;
3674 section
!= NULL
; section
= section
->next
)
3676 /* Ignore non-stub sections. */
3677 if (!strstr (section
->name
, STUB_SUFFIX
))
3682 bfd_hash_traverse (&htab
->stub_hash_table
, aarch64_size_one_stub
, htab
);
3684 for (section
= htab
->stub_bfd
->sections
;
3685 section
!= NULL
; section
= section
->next
)
3687 if (!strstr (section
->name
, STUB_SUFFIX
))
3693 /* Ensure all stub sections have a size which is a multiple of
3694 4096. This is important in order to ensure that the insertion
3695 of stub sections does not in itself move existing code around
3696 in such a way that new errata sequences are created. */
3697 if (htab
->fix_erratum_843419
)
3699 section
->size
= BFD_ALIGN (section
->size
, 0x1000);
3704 /* Construct an erratum 843419 workaround stub name.
3708 _bfd_aarch64_erratum_843419_stub_name (asection
*input_section
,
3711 const bfd_size_type len
= 8 + 4 + 1 + 8 + 1 + 16 + 1;
3712 char *stub_name
= bfd_malloc (len
);
3714 if (stub_name
!= NULL
)
3715 snprintf (stub_name
, len
, "e843419@%04x_%08x_%" BFD_VMA_FMT
"x",
3716 input_section
->owner
->id
,
3722 /* Build a stub_entry structure describing an 843419 fixup.
3724 The stub_entry constructed is populated with the bit pattern INSN
3725 of the instruction located at OFFSET within input SECTION.
3727 Returns TRUE on success. */
3730 _bfd_aarch64_erratum_843419_fixup (uint32_t insn
,
3731 bfd_vma adrp_offset
,
3732 bfd_vma ldst_offset
,
3734 struct bfd_link_info
*info
)
3736 struct elf_aarch64_link_hash_table
*htab
= elf_aarch64_hash_table (info
);
3738 struct elf_aarch64_stub_hash_entry
*stub_entry
;
3740 stub_name
= _bfd_aarch64_erratum_843419_stub_name (section
, ldst_offset
);
3741 stub_entry
= aarch64_stub_hash_lookup (&htab
->stub_hash_table
, stub_name
,
3749 /* We always place an 843419 workaround veneer in the stub section
3750 attached to the input section in which an erratum sequence has
3751 been found. This ensures that later in the link process (in
3752 elfNN_aarch64_write_section) when we copy the veneered
3753 instruction from the input section into the stub section the
3754 copied instruction will have had any relocations applied to it.
3755 If we placed workaround veneers in any other stub section then we
3756 could not assume that all relocations have been processed on the
3757 corresponding input section at the point we output the stub
3761 stub_entry
= _bfd_aarch64_add_stub_entry_after (stub_name
, section
, htab
);
3762 if (stub_entry
== NULL
)
3768 stub_entry
->adrp_offset
= adrp_offset
;
3769 stub_entry
->target_value
= ldst_offset
;
3770 stub_entry
->target_section
= section
;
3771 stub_entry
->stub_type
= aarch64_stub_erratum_843419_veneer
;
3772 stub_entry
->veneered_insn
= insn
;
3773 stub_entry
->output_name
= stub_name
;
3779 /* Scan an input section looking for the signature of erratum 843419.
3781 Scans input SECTION in INPUT_BFD looking for erratum 843419
3782 signatures, for each signature found a stub_entry is created
3783 describing the location of the erratum for subsequent fixup.
3785 Return TRUE on successful scan, FALSE on failure to scan.
3789 _bfd_aarch64_erratum_843419_scan (bfd
*input_bfd
, asection
*section
,
3790 struct bfd_link_info
*info
)
3792 struct elf_aarch64_link_hash_table
*htab
= elf_aarch64_hash_table (info
);
3797 if (elf_section_type (section
) != SHT_PROGBITS
3798 || (elf_section_flags (section
) & SHF_EXECINSTR
) == 0
3799 || (section
->flags
& SEC_EXCLUDE
) != 0
3800 || (section
->sec_info_type
== SEC_INFO_TYPE_JUST_SYMS
)
3801 || (section
->output_section
== bfd_abs_section_ptr
))
3806 bfd_byte
*contents
= NULL
;
3807 struct _aarch64_elf_section_data
*sec_data
;
3810 if (elf_section_data (section
)->this_hdr
.contents
!= NULL
)
3811 contents
= elf_section_data (section
)->this_hdr
.contents
;
3812 else if (! bfd_malloc_and_get_section (input_bfd
, section
, &contents
))
3815 sec_data
= elf_aarch64_section_data (section
);
3817 qsort (sec_data
->map
, sec_data
->mapcount
,
3818 sizeof (elf_aarch64_section_map
), elf_aarch64_compare_mapping
);
3820 for (span
= 0; span
< sec_data
->mapcount
; span
++)
3822 unsigned int span_start
= sec_data
->map
[span
].vma
;
3823 unsigned int span_end
= ((span
== sec_data
->mapcount
- 1)
3824 ? sec_data
->map
[0].vma
+ section
->size
3825 : sec_data
->map
[span
+ 1].vma
);
3827 char span_type
= sec_data
->map
[span
].type
;
3829 if (span_type
== 'd')
3832 for (i
= span_start
; i
+ 8 < span_end
; i
+= 4)
3834 bfd_vma vma
= (section
->output_section
->vma
3835 + section
->output_offset
3839 if (_bfd_aarch64_erratum_843419_p
3840 (contents
, vma
, i
, span_end
, &veneer_i
))
3842 uint32_t insn
= bfd_getl32 (contents
+ veneer_i
);
3844 if (!_bfd_aarch64_erratum_843419_fixup (insn
, i
, veneer_i
,
3851 if (elf_section_data (section
)->this_hdr
.contents
== NULL
)
3860 /* Determine and set the size of the stub section for a final link.
3862 The basic idea here is to examine all the relocations looking for
3863 PC-relative calls to a target that is unreachable with a "bl"
3867 elfNN_aarch64_size_stubs (bfd
*output_bfd
,
3869 struct bfd_link_info
*info
,
3870 bfd_signed_vma group_size
,
3871 asection
* (*add_stub_section
) (const char *,
3873 void (*layout_sections_again
) (void))
3875 bfd_size_type stub_group_size
;
3876 bfd_boolean stubs_always_before_branch
;
3877 bfd_boolean stub_changed
= FALSE
;
3878 struct elf_aarch64_link_hash_table
*htab
= elf_aarch64_hash_table (info
);
3879 unsigned int num_erratum_835769_fixes
= 0;
3881 /* Propagate mach to stub bfd, because it may not have been
3882 finalized when we created stub_bfd. */
3883 bfd_set_arch_mach (stub_bfd
, bfd_get_arch (output_bfd
),
3884 bfd_get_mach (output_bfd
));
3886 /* Stash our params away. */
3887 htab
->stub_bfd
= stub_bfd
;
3888 htab
->add_stub_section
= add_stub_section
;
3889 htab
->layout_sections_again
= layout_sections_again
;
3890 stubs_always_before_branch
= group_size
< 0;
3892 stub_group_size
= -group_size
;
3894 stub_group_size
= group_size
;
3896 if (stub_group_size
== 1)
3898 /* Default values. */
3899 /* AArch64 branch range is +-128MB. The value used is 1MB less. */
3900 stub_group_size
= 127 * 1024 * 1024;
3903 group_sections (htab
, stub_group_size
, stubs_always_before_branch
);
3905 (*htab
->layout_sections_again
) ();
3907 if (htab
->fix_erratum_835769
)
3911 for (input_bfd
= info
->input_bfds
;
3912 input_bfd
!= NULL
; input_bfd
= input_bfd
->link
.next
)
3913 if (!_bfd_aarch64_erratum_835769_scan (input_bfd
, info
,
3914 &num_erratum_835769_fixes
))
3917 _bfd_aarch64_resize_stubs (htab
);
3918 (*htab
->layout_sections_again
) ();
3921 if (htab
->fix_erratum_843419
)
3925 for (input_bfd
= info
->input_bfds
;
3927 input_bfd
= input_bfd
->link
.next
)
3931 for (section
= input_bfd
->sections
;
3933 section
= section
->next
)
3934 if (!_bfd_aarch64_erratum_843419_scan (input_bfd
, section
, info
))
3938 _bfd_aarch64_resize_stubs (htab
);
3939 (*htab
->layout_sections_again
) ();
3946 for (input_bfd
= info
->input_bfds
;
3947 input_bfd
!= NULL
; input_bfd
= input_bfd
->link
.next
)
3949 Elf_Internal_Shdr
*symtab_hdr
;
3951 Elf_Internal_Sym
*local_syms
= NULL
;
3953 /* We'll need the symbol table in a second. */
3954 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
3955 if (symtab_hdr
->sh_info
== 0)
3958 /* Walk over each section attached to the input bfd. */
3959 for (section
= input_bfd
->sections
;
3960 section
!= NULL
; section
= section
->next
)
3962 Elf_Internal_Rela
*internal_relocs
, *irelaend
, *irela
;
3964 /* If there aren't any relocs, then there's nothing more
3966 if ((section
->flags
& SEC_RELOC
) == 0
3967 || section
->reloc_count
== 0
3968 || (section
->flags
& SEC_CODE
) == 0)
3971 /* If this section is a link-once section that will be
3972 discarded, then don't create any stubs. */
3973 if (section
->output_section
== NULL
3974 || section
->output_section
->owner
!= output_bfd
)
3977 /* Get the relocs. */
3979 = _bfd_elf_link_read_relocs (input_bfd
, section
, NULL
,
3980 NULL
, info
->keep_memory
);
3981 if (internal_relocs
== NULL
)
3982 goto error_ret_free_local
;
3984 /* Now examine each relocation. */
3985 irela
= internal_relocs
;
3986 irelaend
= irela
+ section
->reloc_count
;
3987 for (; irela
< irelaend
; irela
++)
3989 unsigned int r_type
, r_indx
;
3990 enum elf_aarch64_stub_type stub_type
;
3991 struct elf_aarch64_stub_hash_entry
*stub_entry
;
3994 bfd_vma destination
;
3995 struct elf_aarch64_link_hash_entry
*hash
;
3996 const char *sym_name
;
3998 const asection
*id_sec
;
3999 unsigned char st_type
;
4002 r_type
= ELFNN_R_TYPE (irela
->r_info
);
4003 r_indx
= ELFNN_R_SYM (irela
->r_info
);
4005 if (r_type
>= (unsigned int) R_AARCH64_end
)
4007 bfd_set_error (bfd_error_bad_value
);
4008 error_ret_free_internal
:
4009 if (elf_section_data (section
)->relocs
== NULL
)
4010 free (internal_relocs
);
4011 goto error_ret_free_local
;
4014 /* Only look for stubs on unconditional branch and
4015 branch and link instructions. */
4016 if (r_type
!= (unsigned int) AARCH64_R (CALL26
)
4017 && r_type
!= (unsigned int) AARCH64_R (JUMP26
))
4020 /* Now determine the call target, its name, value,
4027 if (r_indx
< symtab_hdr
->sh_info
)
4029 /* It's a local symbol. */
4030 Elf_Internal_Sym
*sym
;
4031 Elf_Internal_Shdr
*hdr
;
4033 if (local_syms
== NULL
)
4036 = (Elf_Internal_Sym
*) symtab_hdr
->contents
;
4037 if (local_syms
== NULL
)
4039 = bfd_elf_get_elf_syms (input_bfd
, symtab_hdr
,
4040 symtab_hdr
->sh_info
, 0,
4042 if (local_syms
== NULL
)
4043 goto error_ret_free_internal
;
4046 sym
= local_syms
+ r_indx
;
4047 hdr
= elf_elfsections (input_bfd
)[sym
->st_shndx
];
4048 sym_sec
= hdr
->bfd_section
;
4050 /* This is an undefined symbol. It can never
4054 if (ELF_ST_TYPE (sym
->st_info
) != STT_SECTION
)
4055 sym_value
= sym
->st_value
;
4056 destination
= (sym_value
+ irela
->r_addend
4057 + sym_sec
->output_offset
4058 + sym_sec
->output_section
->vma
);
4059 st_type
= ELF_ST_TYPE (sym
->st_info
);
4061 = bfd_elf_string_from_elf_section (input_bfd
,
4062 symtab_hdr
->sh_link
,
4069 e_indx
= r_indx
- symtab_hdr
->sh_info
;
4070 hash
= ((struct elf_aarch64_link_hash_entry
*)
4071 elf_sym_hashes (input_bfd
)[e_indx
]);
4073 while (hash
->root
.root
.type
== bfd_link_hash_indirect
4074 || hash
->root
.root
.type
== bfd_link_hash_warning
)
4075 hash
= ((struct elf_aarch64_link_hash_entry
*)
4076 hash
->root
.root
.u
.i
.link
);
4078 if (hash
->root
.root
.type
== bfd_link_hash_defined
4079 || hash
->root
.root
.type
== bfd_link_hash_defweak
)
4081 struct elf_aarch64_link_hash_table
*globals
=
4082 elf_aarch64_hash_table (info
);
4083 sym_sec
= hash
->root
.root
.u
.def
.section
;
4084 sym_value
= hash
->root
.root
.u
.def
.value
;
4085 /* For a destination in a shared library,
4086 use the PLT stub as target address to
4087 decide whether a branch stub is
4089 if (globals
->root
.splt
!= NULL
&& hash
!= NULL
4090 && hash
->root
.plt
.offset
!= (bfd_vma
) - 1)
4092 sym_sec
= globals
->root
.splt
;
4093 sym_value
= hash
->root
.plt
.offset
;
4094 if (sym_sec
->output_section
!= NULL
)
4095 destination
= (sym_value
4096 + sym_sec
->output_offset
4098 sym_sec
->output_section
->vma
);
4100 else if (sym_sec
->output_section
!= NULL
)
4101 destination
= (sym_value
+ irela
->r_addend
4102 + sym_sec
->output_offset
4103 + sym_sec
->output_section
->vma
);
4105 else if (hash
->root
.root
.type
== bfd_link_hash_undefined
4106 || (hash
->root
.root
.type
4107 == bfd_link_hash_undefweak
))
4109 /* For a shared library, use the PLT stub as
4110 target address to decide whether a long
4111 branch stub is needed.
4112 For absolute code, they cannot be handled. */
4113 struct elf_aarch64_link_hash_table
*globals
=
4114 elf_aarch64_hash_table (info
);
4116 if (globals
->root
.splt
!= NULL
&& hash
!= NULL
4117 && hash
->root
.plt
.offset
!= (bfd_vma
) - 1)
4119 sym_sec
= globals
->root
.splt
;
4120 sym_value
= hash
->root
.plt
.offset
;
4121 if (sym_sec
->output_section
!= NULL
)
4122 destination
= (sym_value
4123 + sym_sec
->output_offset
4125 sym_sec
->output_section
->vma
);
4132 bfd_set_error (bfd_error_bad_value
);
4133 goto error_ret_free_internal
;
4135 st_type
= ELF_ST_TYPE (hash
->root
.type
);
4136 sym_name
= hash
->root
.root
.root
.string
;
4139 /* Determine what (if any) linker stub is needed. */
4140 stub_type
= aarch64_type_of_stub
4141 (info
, section
, irela
, sym_sec
, st_type
, hash
, destination
);
4142 if (stub_type
== aarch64_stub_none
)
4145 /* Support for grouping stub sections. */
4146 id_sec
= htab
->stub_group
[section
->id
].link_sec
;
4148 /* Get the name of this stub. */
4149 stub_name
= elfNN_aarch64_stub_name (id_sec
, sym_sec
, hash
,
4152 goto error_ret_free_internal
;
4155 aarch64_stub_hash_lookup (&htab
->stub_hash_table
,
4156 stub_name
, FALSE
, FALSE
);
4157 if (stub_entry
!= NULL
)
4159 /* The proper stub has already been created. */
4164 stub_entry
= _bfd_aarch64_add_stub_entry_in_group
4165 (stub_name
, section
, htab
);
4166 if (stub_entry
== NULL
)
4169 goto error_ret_free_internal
;
4172 stub_entry
->target_value
= sym_value
;
4173 stub_entry
->target_section
= sym_sec
;
4174 stub_entry
->stub_type
= stub_type
;
4175 stub_entry
->h
= hash
;
4176 stub_entry
->st_type
= st_type
;
4178 if (sym_name
== NULL
)
4179 sym_name
= "unnamed";
4180 len
= sizeof (STUB_ENTRY_NAME
) + strlen (sym_name
);
4181 stub_entry
->output_name
= bfd_alloc (htab
->stub_bfd
, len
);
4182 if (stub_entry
->output_name
== NULL
)
4185 goto error_ret_free_internal
;
4188 snprintf (stub_entry
->output_name
, len
, STUB_ENTRY_NAME
,
4191 stub_changed
= TRUE
;
4194 /* We're done with the internal relocs, free them. */
4195 if (elf_section_data (section
)->relocs
== NULL
)
4196 free (internal_relocs
);
4203 _bfd_aarch64_resize_stubs (htab
);
4205 /* Ask the linker to do its stuff. */
4206 (*htab
->layout_sections_again
) ();
4207 stub_changed
= FALSE
;
4212 error_ret_free_local
:
4216 /* Build all the stubs associated with the current output file. The
4217 stubs are kept in a hash table attached to the main linker hash
4218 table. We also set up the .plt entries for statically linked PIC
4219 functions here. This function is called via aarch64_elf_finish in the
4223 elfNN_aarch64_build_stubs (struct bfd_link_info
*info
)
4226 struct bfd_hash_table
*table
;
4227 struct elf_aarch64_link_hash_table
*htab
;
4229 htab
= elf_aarch64_hash_table (info
);
4231 for (stub_sec
= htab
->stub_bfd
->sections
;
4232 stub_sec
!= NULL
; stub_sec
= stub_sec
->next
)
4236 /* Ignore non-stub sections. */
4237 if (!strstr (stub_sec
->name
, STUB_SUFFIX
))
4240 /* Allocate memory to hold the linker stubs. */
4241 size
= stub_sec
->size
;
4242 stub_sec
->contents
= bfd_zalloc (htab
->stub_bfd
, size
);
4243 if (stub_sec
->contents
== NULL
&& size
!= 0)
4247 bfd_putl32 (0x14000000 | (size
>> 2), stub_sec
->contents
);
4248 stub_sec
->size
+= 4;
4251 /* Build the stubs as directed by the stub hash table. */
4252 table
= &htab
->stub_hash_table
;
4253 bfd_hash_traverse (table
, aarch64_build_one_stub
, info
);
4259 /* Add an entry to the code/data map for section SEC. */
4262 elfNN_aarch64_section_map_add (asection
*sec
, char type
, bfd_vma vma
)
4264 struct _aarch64_elf_section_data
*sec_data
=
4265 elf_aarch64_section_data (sec
);
4266 unsigned int newidx
;
4268 if (sec_data
->map
== NULL
)
4270 sec_data
->map
= bfd_malloc (sizeof (elf_aarch64_section_map
));
4271 sec_data
->mapcount
= 0;
4272 sec_data
->mapsize
= 1;
4275 newidx
= sec_data
->mapcount
++;
4277 if (sec_data
->mapcount
> sec_data
->mapsize
)
4279 sec_data
->mapsize
*= 2;
4280 sec_data
->map
= bfd_realloc_or_free
4281 (sec_data
->map
, sec_data
->mapsize
* sizeof (elf_aarch64_section_map
));
4286 sec_data
->map
[newidx
].vma
= vma
;
4287 sec_data
->map
[newidx
].type
= type
;
4292 /* Initialise maps of insn/data for input BFDs. */
4294 bfd_elfNN_aarch64_init_maps (bfd
*abfd
)
4296 Elf_Internal_Sym
*isymbuf
;
4297 Elf_Internal_Shdr
*hdr
;
4298 unsigned int i
, localsyms
;
4300 /* Make sure that we are dealing with an AArch64 elf binary. */
4301 if (!is_aarch64_elf (abfd
))
4304 if ((abfd
->flags
& DYNAMIC
) != 0)
4307 hdr
= &elf_symtab_hdr (abfd
);
4308 localsyms
= hdr
->sh_info
;
4310 /* Obtain a buffer full of symbols for this BFD. The hdr->sh_info field
4311 should contain the number of local symbols, which should come before any
4312 global symbols. Mapping symbols are always local. */
4313 isymbuf
= bfd_elf_get_elf_syms (abfd
, hdr
, localsyms
, 0, NULL
, NULL
, NULL
);
4315 /* No internal symbols read? Skip this BFD. */
4316 if (isymbuf
== NULL
)
4319 for (i
= 0; i
< localsyms
; i
++)
4321 Elf_Internal_Sym
*isym
= &isymbuf
[i
];
4322 asection
*sec
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
4325 if (sec
!= NULL
&& ELF_ST_BIND (isym
->st_info
) == STB_LOCAL
)
4327 name
= bfd_elf_string_from_elf_section (abfd
,
4331 if (bfd_is_aarch64_special_symbol_name
4332 (name
, BFD_AARCH64_SPECIAL_SYM_TYPE_MAP
))
4333 elfNN_aarch64_section_map_add (sec
, name
[1], isym
->st_value
);
4338 /* Set option values needed during linking. */
4340 bfd_elfNN_aarch64_set_options (struct bfd
*output_bfd
,
4341 struct bfd_link_info
*link_info
,
4343 int no_wchar_warn
, int pic_veneer
,
4344 int fix_erratum_835769
,
4345 int fix_erratum_843419
)
4347 struct elf_aarch64_link_hash_table
*globals
;
4349 globals
= elf_aarch64_hash_table (link_info
);
4350 globals
->pic_veneer
= pic_veneer
;
4351 globals
->fix_erratum_835769
= fix_erratum_835769
;
4352 globals
->fix_erratum_843419
= fix_erratum_843419
;
4353 globals
->fix_erratum_843419_adr
= TRUE
;
4355 BFD_ASSERT (is_aarch64_elf (output_bfd
));
4356 elf_aarch64_tdata (output_bfd
)->no_enum_size_warning
= no_enum_warn
;
4357 elf_aarch64_tdata (output_bfd
)->no_wchar_size_warning
= no_wchar_warn
;
4361 aarch64_calculate_got_entry_vma (struct elf_link_hash_entry
*h
,
4362 struct elf_aarch64_link_hash_table
4363 *globals
, struct bfd_link_info
*info
,
4364 bfd_vma value
, bfd
*output_bfd
,
4365 bfd_boolean
*unresolved_reloc_p
)
4367 bfd_vma off
= (bfd_vma
) - 1;
4368 asection
*basegot
= globals
->root
.sgot
;
4369 bfd_boolean dyn
= globals
->root
.dynamic_sections_created
;
4373 BFD_ASSERT (basegot
!= NULL
);
4374 off
= h
->got
.offset
;
4375 BFD_ASSERT (off
!= (bfd_vma
) - 1);
4376 if (!WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, bfd_link_pic (info
), h
)
4377 || (bfd_link_pic (info
)
4378 && SYMBOL_REFERENCES_LOCAL (info
, h
))
4379 || (ELF_ST_VISIBILITY (h
->other
)
4380 && h
->root
.type
== bfd_link_hash_undefweak
))
4382 /* This is actually a static link, or it is a -Bsymbolic link
4383 and the symbol is defined locally. We must initialize this
4384 entry in the global offset table. Since the offset must
4385 always be a multiple of 8 (4 in the case of ILP32), we use
4386 the least significant bit to record whether we have
4387 initialized it already.
4388 When doing a dynamic link, we create a .rel(a).got relocation
4389 entry to initialize the value. This is done in the
4390 finish_dynamic_symbol routine. */
4395 bfd_put_NN (output_bfd
, value
, basegot
->contents
+ off
);
4400 *unresolved_reloc_p
= FALSE
;
4402 off
= off
+ basegot
->output_section
->vma
+ basegot
->output_offset
;
4408 /* Change R_TYPE to a more efficient access model where possible,
4409 return the new reloc type. */
4411 static bfd_reloc_code_real_type
4412 aarch64_tls_transition_without_check (bfd_reloc_code_real_type r_type
,
4413 struct elf_link_hash_entry
*h
)
4415 bfd_boolean is_local
= h
== NULL
;
4419 case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21
:
4420 case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21
:
4422 ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1
4423 : BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21
);
4425 case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21
:
4427 ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC
4430 case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19
:
4432 ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1
4433 : BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19
);
4435 case BFD_RELOC_AARCH64_TLSDESC_LDNN_LO12_NC
:
4436 case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC
:
4438 ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC
4439 : BFD_RELOC_AARCH64_TLSIE_LDNN_GOTTPREL_LO12_NC
);
4441 case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21
:
4442 return is_local
? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1
: r_type
;
4444 case BFD_RELOC_AARCH64_TLSIE_LDNN_GOTTPREL_LO12_NC
:
4445 return is_local
? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC
: r_type
;
4447 case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19
:
4450 case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21
:
4452 ? BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_HI12
4453 : BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19
);
4455 case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12_NC
:
4456 case BFD_RELOC_AARCH64_TLSDESC_CALL
:
4457 /* Instructions with these relocations will become NOPs. */
4458 return BFD_RELOC_AARCH64_NONE
;
4460 case BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC
:
4461 case BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21
:
4462 case BFD_RELOC_AARCH64_TLSLD_ADR_PREL21
:
4463 return is_local
? BFD_RELOC_AARCH64_NONE
: r_type
;
4466 case BFD_RELOC_AARCH64_TLSGD_MOVW_G0_NC
:
4468 ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1_NC
4469 : BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G0_NC
;
4471 case BFD_RELOC_AARCH64_TLSGD_MOVW_G1
:
4473 ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G2
4474 : BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G1
;
4485 aarch64_reloc_got_type (bfd_reloc_code_real_type r_type
)
4489 case BFD_RELOC_AARCH64_ADR_GOT_PAGE
:
4490 case BFD_RELOC_AARCH64_GOT_LD_PREL19
:
4491 case BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14
:
4492 case BFD_RELOC_AARCH64_LD32_GOT_LO12_NC
:
4493 case BFD_RELOC_AARCH64_LD64_GOTOFF_LO15
:
4494 case BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15
:
4495 case BFD_RELOC_AARCH64_LD64_GOT_LO12_NC
:
4496 case BFD_RELOC_AARCH64_MOVW_GOTOFF_G0_NC
:
4497 case BFD_RELOC_AARCH64_MOVW_GOTOFF_G1
:
4500 case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC
:
4501 case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21
:
4502 case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21
:
4503 case BFD_RELOC_AARCH64_TLSGD_MOVW_G0_NC
:
4504 case BFD_RELOC_AARCH64_TLSGD_MOVW_G1
:
4505 case BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC
:
4506 case BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21
:
4507 case BFD_RELOC_AARCH64_TLSLD_ADR_PREL21
:
4510 case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12_NC
:
4511 case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21
:
4512 case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21
:
4513 case BFD_RELOC_AARCH64_TLSDESC_CALL
:
4514 case BFD_RELOC_AARCH64_TLSDESC_LD32_LO12_NC
:
4515 case BFD_RELOC_AARCH64_TLSDESC_LD64_LO12_NC
:
4516 case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19
:
4517 return GOT_TLSDESC_GD
;
4519 case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21
:
4520 case BFD_RELOC_AARCH64_TLSIE_LD32_GOTTPREL_LO12_NC
:
4521 case BFD_RELOC_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC
:
4522 case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19
:
4523 case BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G0_NC
:
4524 case BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G1
:
4534 aarch64_can_relax_tls (bfd
*input_bfd
,
4535 struct bfd_link_info
*info
,
4536 bfd_reloc_code_real_type r_type
,
4537 struct elf_link_hash_entry
*h
,
4538 unsigned long r_symndx
)
4540 unsigned int symbol_got_type
;
4541 unsigned int reloc_got_type
;
4543 if (! IS_AARCH64_TLS_RELAX_RELOC (r_type
))
4546 symbol_got_type
= elfNN_aarch64_symbol_got_type (h
, input_bfd
, r_symndx
);
4547 reloc_got_type
= aarch64_reloc_got_type (r_type
);
4549 if (symbol_got_type
== GOT_TLS_IE
&& GOT_TLS_GD_ANY_P (reloc_got_type
))
4552 if (bfd_link_pic (info
))
4555 if (h
&& h
->root
.type
== bfd_link_hash_undefweak
)
4561 /* Given the relocation code R_TYPE, return the relaxed bfd reloc
4564 static bfd_reloc_code_real_type
4565 aarch64_tls_transition (bfd
*input_bfd
,
4566 struct bfd_link_info
*info
,
4567 unsigned int r_type
,
4568 struct elf_link_hash_entry
*h
,
4569 unsigned long r_symndx
)
4571 bfd_reloc_code_real_type bfd_r_type
4572 = elfNN_aarch64_bfd_reloc_from_type (r_type
);
4574 if (! aarch64_can_relax_tls (input_bfd
, info
, bfd_r_type
, h
, r_symndx
))
4577 return aarch64_tls_transition_without_check (bfd_r_type
, h
);
4580 /* Return the base VMA address which should be subtracted from real addresses
4581 when resolving R_AARCH64_TLS_DTPREL relocation. */
4584 dtpoff_base (struct bfd_link_info
*info
)
4586 /* If tls_sec is NULL, we should have signalled an error already. */
4587 BFD_ASSERT (elf_hash_table (info
)->tls_sec
!= NULL
);
4588 return elf_hash_table (info
)->tls_sec
->vma
;
4591 /* Return the base VMA address which should be subtracted from real addresses
4592 when resolving R_AARCH64_TLS_GOTTPREL64 relocations. */
4595 tpoff_base (struct bfd_link_info
*info
)
4597 struct elf_link_hash_table
*htab
= elf_hash_table (info
);
4599 /* If tls_sec is NULL, we should have signalled an error already. */
4600 BFD_ASSERT (htab
->tls_sec
!= NULL
);
4602 bfd_vma base
= align_power ((bfd_vma
) TCB_SIZE
,
4603 htab
->tls_sec
->alignment_power
);
4604 return htab
->tls_sec
->vma
- base
;
4608 symbol_got_offset_ref (bfd
*input_bfd
, struct elf_link_hash_entry
*h
,
4609 unsigned long r_symndx
)
4611 /* Calculate the address of the GOT entry for symbol
4612 referred to in h. */
4614 return &h
->got
.offset
;
4618 struct elf_aarch64_local_symbol
*l
;
4620 l
= elf_aarch64_locals (input_bfd
);
4621 return &l
[r_symndx
].got_offset
;
4626 symbol_got_offset_mark (bfd
*input_bfd
, struct elf_link_hash_entry
*h
,
4627 unsigned long r_symndx
)
4630 p
= symbol_got_offset_ref (input_bfd
, h
, r_symndx
);
4635 symbol_got_offset_mark_p (bfd
*input_bfd
, struct elf_link_hash_entry
*h
,
4636 unsigned long r_symndx
)
4639 value
= * symbol_got_offset_ref (input_bfd
, h
, r_symndx
);
4644 symbol_got_offset (bfd
*input_bfd
, struct elf_link_hash_entry
*h
,
4645 unsigned long r_symndx
)
4648 value
= * symbol_got_offset_ref (input_bfd
, h
, r_symndx
);
4654 symbol_tlsdesc_got_offset_ref (bfd
*input_bfd
, struct elf_link_hash_entry
*h
,
4655 unsigned long r_symndx
)
4657 /* Calculate the address of the GOT entry for symbol
4658 referred to in h. */
4661 struct elf_aarch64_link_hash_entry
*eh
;
4662 eh
= (struct elf_aarch64_link_hash_entry
*) h
;
4663 return &eh
->tlsdesc_got_jump_table_offset
;
4668 struct elf_aarch64_local_symbol
*l
;
4670 l
= elf_aarch64_locals (input_bfd
);
4671 return &l
[r_symndx
].tlsdesc_got_jump_table_offset
;
4676 symbol_tlsdesc_got_offset_mark (bfd
*input_bfd
, struct elf_link_hash_entry
*h
,
4677 unsigned long r_symndx
)
4680 p
= symbol_tlsdesc_got_offset_ref (input_bfd
, h
, r_symndx
);
4685 symbol_tlsdesc_got_offset_mark_p (bfd
*input_bfd
,
4686 struct elf_link_hash_entry
*h
,
4687 unsigned long r_symndx
)
4690 value
= * symbol_tlsdesc_got_offset_ref (input_bfd
, h
, r_symndx
);
4695 symbol_tlsdesc_got_offset (bfd
*input_bfd
, struct elf_link_hash_entry
*h
,
4696 unsigned long r_symndx
)
4699 value
= * symbol_tlsdesc_got_offset_ref (input_bfd
, h
, r_symndx
);
4704 /* Data for make_branch_to_erratum_835769_stub(). */
4706 struct erratum_835769_branch_to_stub_data
4708 struct bfd_link_info
*info
;
4709 asection
*output_section
;
4713 /* Helper to insert branches to erratum 835769 stubs in the right
4714 places for a particular section. */
4717 make_branch_to_erratum_835769_stub (struct bfd_hash_entry
*gen_entry
,
4720 struct elf_aarch64_stub_hash_entry
*stub_entry
;
4721 struct erratum_835769_branch_to_stub_data
*data
;
4723 unsigned long branch_insn
= 0;
4724 bfd_vma veneered_insn_loc
, veneer_entry_loc
;
4725 bfd_signed_vma branch_offset
;
4726 unsigned int target
;
4729 stub_entry
= (struct elf_aarch64_stub_hash_entry
*) gen_entry
;
4730 data
= (struct erratum_835769_branch_to_stub_data
*) in_arg
;
4732 if (stub_entry
->target_section
!= data
->output_section
4733 || stub_entry
->stub_type
!= aarch64_stub_erratum_835769_veneer
)
4736 contents
= data
->contents
;
4737 veneered_insn_loc
= stub_entry
->target_section
->output_section
->vma
4738 + stub_entry
->target_section
->output_offset
4739 + stub_entry
->target_value
;
4740 veneer_entry_loc
= stub_entry
->stub_sec
->output_section
->vma
4741 + stub_entry
->stub_sec
->output_offset
4742 + stub_entry
->stub_offset
;
4743 branch_offset
= veneer_entry_loc
- veneered_insn_loc
;
4745 abfd
= stub_entry
->target_section
->owner
;
4746 if (!aarch64_valid_branch_p (veneer_entry_loc
, veneered_insn_loc
))
4747 (*_bfd_error_handler
)
4748 (_("%B: error: Erratum 835769 stub out "
4749 "of range (input file too large)"), abfd
);
4751 target
= stub_entry
->target_value
;
4752 branch_insn
= 0x14000000;
4753 branch_offset
>>= 2;
4754 branch_offset
&= 0x3ffffff;
4755 branch_insn
|= branch_offset
;
4756 bfd_putl32 (branch_insn
, &contents
[target
]);
4763 _bfd_aarch64_erratum_843419_branch_to_stub (struct bfd_hash_entry
*gen_entry
,
4766 struct elf_aarch64_stub_hash_entry
*stub_entry
4767 = (struct elf_aarch64_stub_hash_entry
*) gen_entry
;
4768 struct erratum_835769_branch_to_stub_data
*data
4769 = (struct erratum_835769_branch_to_stub_data
*) in_arg
;
4770 struct bfd_link_info
*info
;
4771 struct elf_aarch64_link_hash_table
*htab
;
4779 contents
= data
->contents
;
4780 section
= data
->output_section
;
4782 htab
= elf_aarch64_hash_table (info
);
4784 if (stub_entry
->target_section
!= section
4785 || stub_entry
->stub_type
!= aarch64_stub_erratum_843419_veneer
)
4788 insn
= bfd_getl32 (contents
+ stub_entry
->target_value
);
4790 stub_entry
->stub_sec
->contents
+ stub_entry
->stub_offset
);
4792 place
= (section
->output_section
->vma
+ section
->output_offset
4793 + stub_entry
->adrp_offset
);
4794 insn
= bfd_getl32 (contents
+ stub_entry
->adrp_offset
);
4796 if ((insn
& AARCH64_ADRP_OP_MASK
) != AARCH64_ADRP_OP
)
4799 bfd_signed_vma imm
=
4800 (_bfd_aarch64_sign_extend
4801 ((bfd_vma
) _bfd_aarch64_decode_adrp_imm (insn
) << 12, 33)
4804 if (htab
->fix_erratum_843419_adr
4805 && (imm
>= AARCH64_MIN_ADRP_IMM
&& imm
<= AARCH64_MAX_ADRP_IMM
))
4807 insn
= (_bfd_aarch64_reencode_adr_imm (AARCH64_ADR_OP
, imm
)
4808 | AARCH64_RT (insn
));
4809 bfd_putl32 (insn
, contents
+ stub_entry
->adrp_offset
);
4813 bfd_vma veneered_insn_loc
;
4814 bfd_vma veneer_entry_loc
;
4815 bfd_signed_vma branch_offset
;
4816 uint32_t branch_insn
;
4818 veneered_insn_loc
= stub_entry
->target_section
->output_section
->vma
4819 + stub_entry
->target_section
->output_offset
4820 + stub_entry
->target_value
;
4821 veneer_entry_loc
= stub_entry
->stub_sec
->output_section
->vma
4822 + stub_entry
->stub_sec
->output_offset
4823 + stub_entry
->stub_offset
;
4824 branch_offset
= veneer_entry_loc
- veneered_insn_loc
;
4826 abfd
= stub_entry
->target_section
->owner
;
4827 if (!aarch64_valid_branch_p (veneer_entry_loc
, veneered_insn_loc
))
4828 (*_bfd_error_handler
)
4829 (_("%B: error: Erratum 843419 stub out "
4830 "of range (input file too large)"), abfd
);
4832 branch_insn
= 0x14000000;
4833 branch_offset
>>= 2;
4834 branch_offset
&= 0x3ffffff;
4835 branch_insn
|= branch_offset
;
4836 bfd_putl32 (branch_insn
, contents
+ stub_entry
->target_value
);
4843 elfNN_aarch64_write_section (bfd
*output_bfd ATTRIBUTE_UNUSED
,
4844 struct bfd_link_info
*link_info
,
4849 struct elf_aarch64_link_hash_table
*globals
=
4850 elf_aarch64_hash_table (link_info
);
4852 if (globals
== NULL
)
4855 /* Fix code to point to erratum 835769 stubs. */
4856 if (globals
->fix_erratum_835769
)
4858 struct erratum_835769_branch_to_stub_data data
;
4860 data
.info
= link_info
;
4861 data
.output_section
= sec
;
4862 data
.contents
= contents
;
4863 bfd_hash_traverse (&globals
->stub_hash_table
,
4864 make_branch_to_erratum_835769_stub
, &data
);
4867 if (globals
->fix_erratum_843419
)
4869 struct erratum_835769_branch_to_stub_data data
;
4871 data
.info
= link_info
;
4872 data
.output_section
= sec
;
4873 data
.contents
= contents
;
4874 bfd_hash_traverse (&globals
->stub_hash_table
,
4875 _bfd_aarch64_erratum_843419_branch_to_stub
, &data
);
4881 /* Perform a relocation as part of a final link. */
4882 static bfd_reloc_status_type
4883 elfNN_aarch64_final_link_relocate (reloc_howto_type
*howto
,
4886 asection
*input_section
,
4888 Elf_Internal_Rela
*rel
,
4890 struct bfd_link_info
*info
,
4892 struct elf_link_hash_entry
*h
,
4893 bfd_boolean
*unresolved_reloc_p
,
4894 bfd_boolean save_addend
,
4895 bfd_vma
*saved_addend
,
4896 Elf_Internal_Sym
*sym
)
4898 Elf_Internal_Shdr
*symtab_hdr
;
4899 unsigned int r_type
= howto
->type
;
4900 bfd_reloc_code_real_type bfd_r_type
4901 = elfNN_aarch64_bfd_reloc_from_howto (howto
);
4902 bfd_reloc_code_real_type new_bfd_r_type
;
4903 unsigned long r_symndx
;
4904 bfd_byte
*hit_data
= contents
+ rel
->r_offset
;
4906 bfd_signed_vma signed_addend
;
4907 struct elf_aarch64_link_hash_table
*globals
;
4908 bfd_boolean weak_undef_p
;
4911 globals
= elf_aarch64_hash_table (info
);
4913 symtab_hdr
= &elf_symtab_hdr (input_bfd
);
4915 BFD_ASSERT (is_aarch64_elf (input_bfd
));
4917 r_symndx
= ELFNN_R_SYM (rel
->r_info
);
4919 /* It is possible to have linker relaxations on some TLS access
4920 models. Update our information here. */
4921 new_bfd_r_type
= aarch64_tls_transition (input_bfd
, info
, r_type
, h
, r_symndx
);
4922 if (new_bfd_r_type
!= bfd_r_type
)
4924 bfd_r_type
= new_bfd_r_type
;
4925 howto
= elfNN_aarch64_howto_from_bfd_reloc (bfd_r_type
);
4926 BFD_ASSERT (howto
!= NULL
);
4927 r_type
= howto
->type
;
4930 place
= input_section
->output_section
->vma
4931 + input_section
->output_offset
+ rel
->r_offset
;
4933 /* Get addend, accumulating the addend for consecutive relocs
4934 which refer to the same offset. */
4935 signed_addend
= saved_addend
? *saved_addend
: 0;
4936 signed_addend
+= rel
->r_addend
;
4938 weak_undef_p
= (h
? h
->root
.type
== bfd_link_hash_undefweak
4939 : bfd_is_und_section (sym_sec
));
4941 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle
4942 it here if it is defined in a non-shared object. */
4944 && h
->type
== STT_GNU_IFUNC
4951 if ((input_section
->flags
& SEC_ALLOC
) == 0
4952 || h
->plt
.offset
== (bfd_vma
) -1)
4955 /* STT_GNU_IFUNC symbol must go through PLT. */
4956 plt
= globals
->root
.splt
? globals
->root
.splt
: globals
->root
.iplt
;
4957 value
= (plt
->output_section
->vma
+ plt
->output_offset
+ h
->plt
.offset
);
4962 if (h
->root
.root
.string
)
4963 name
= h
->root
.root
.string
;
4965 name
= bfd_elf_sym_name (input_bfd
, symtab_hdr
, sym
,
4967 (*_bfd_error_handler
)
4968 (_("%B: relocation %s against STT_GNU_IFUNC "
4969 "symbol `%s' isn't handled by %s"), input_bfd
,
4970 howto
->name
, name
, __FUNCTION__
);
4971 bfd_set_error (bfd_error_bad_value
);
4974 case BFD_RELOC_AARCH64_NN
:
4975 if (rel
->r_addend
!= 0)
4977 if (h
->root
.root
.string
)
4978 name
= h
->root
.root
.string
;
4980 name
= bfd_elf_sym_name (input_bfd
, symtab_hdr
,
4982 (*_bfd_error_handler
)
4983 (_("%B: relocation %s against STT_GNU_IFUNC "
4984 "symbol `%s' has non-zero addend: %d"),
4985 input_bfd
, howto
->name
, name
, rel
->r_addend
);
4986 bfd_set_error (bfd_error_bad_value
);
4990 /* Generate dynamic relocation only when there is a
4991 non-GOT reference in a shared object. */
4992 if (bfd_link_pic (info
) && h
->non_got_ref
)
4994 Elf_Internal_Rela outrel
;
4997 /* Need a dynamic relocation to get the real function
4999 outrel
.r_offset
= _bfd_elf_section_offset (output_bfd
,
5003 if (outrel
.r_offset
== (bfd_vma
) -1
5004 || outrel
.r_offset
== (bfd_vma
) -2)
5007 outrel
.r_offset
+= (input_section
->output_section
->vma
5008 + input_section
->output_offset
);
5010 if (h
->dynindx
== -1
5012 || bfd_link_executable (info
))
5014 /* This symbol is resolved locally. */
5015 outrel
.r_info
= ELFNN_R_INFO (0, AARCH64_R (IRELATIVE
));
5016 outrel
.r_addend
= (h
->root
.u
.def
.value
5017 + h
->root
.u
.def
.section
->output_section
->vma
5018 + h
->root
.u
.def
.section
->output_offset
);
5022 outrel
.r_info
= ELFNN_R_INFO (h
->dynindx
, r_type
);
5023 outrel
.r_addend
= 0;
5026 sreloc
= globals
->root
.irelifunc
;
5027 elf_append_rela (output_bfd
, sreloc
, &outrel
);
5029 /* If this reloc is against an external symbol, we
5030 do not want to fiddle with the addend. Otherwise,
5031 we need to include the symbol value so that it
5032 becomes an addend for the dynamic reloc. For an
5033 internal symbol, we have updated addend. */
5034 return bfd_reloc_ok
;
5037 case BFD_RELOC_AARCH64_CALL26
:
5038 case BFD_RELOC_AARCH64_JUMP26
:
5039 value
= _bfd_aarch64_elf_resolve_relocation (bfd_r_type
, place
, value
,
5042 return _bfd_aarch64_elf_put_addend (input_bfd
, hit_data
, bfd_r_type
,
5044 case BFD_RELOC_AARCH64_ADR_GOT_PAGE
:
5045 case BFD_RELOC_AARCH64_GOT_LD_PREL19
:
5046 case BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14
:
5047 case BFD_RELOC_AARCH64_LD32_GOT_LO12_NC
:
5048 case BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15
:
5049 case BFD_RELOC_AARCH64_MOVW_GOTOFF_G0_NC
:
5050 case BFD_RELOC_AARCH64_MOVW_GOTOFF_G1
:
5051 case BFD_RELOC_AARCH64_LD64_GOTOFF_LO15
:
5052 case BFD_RELOC_AARCH64_LD64_GOT_LO12_NC
:
5053 base_got
= globals
->root
.sgot
;
5054 off
= h
->got
.offset
;
5056 if (base_got
== NULL
)
5059 if (off
== (bfd_vma
) -1)
5063 /* We can't use h->got.offset here to save state, or
5064 even just remember the offset, as finish_dynamic_symbol
5065 would use that as offset into .got. */
5067 if (globals
->root
.splt
!= NULL
)
5069 plt_index
= ((h
->plt
.offset
- globals
->plt_header_size
) /
5070 globals
->plt_entry_size
);
5071 off
= (plt_index
+ 3) * GOT_ENTRY_SIZE
;
5072 base_got
= globals
->root
.sgotplt
;
5076 plt_index
= h
->plt
.offset
/ globals
->plt_entry_size
;
5077 off
= plt_index
* GOT_ENTRY_SIZE
;
5078 base_got
= globals
->root
.igotplt
;
5081 if (h
->dynindx
== -1
5085 /* This references the local definition. We must
5086 initialize this entry in the global offset table.
5087 Since the offset must always be a multiple of 8,
5088 we use the least significant bit to record
5089 whether we have initialized it already.
5091 When doing a dynamic link, we create a .rela.got
5092 relocation entry to initialize the value. This
5093 is done in the finish_dynamic_symbol routine. */
5098 bfd_put_NN (output_bfd
, value
,
5099 base_got
->contents
+ off
);
5100 /* Note that this is harmless as -1 | 1 still is -1. */
5104 value
= (base_got
->output_section
->vma
5105 + base_got
->output_offset
+ off
);
5108 value
= aarch64_calculate_got_entry_vma (h
, globals
, info
,
5110 unresolved_reloc_p
);
5114 case BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14
:
5115 case BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15
:
5116 addend
= (globals
->root
.sgot
->output_section
->vma
5117 + globals
->root
.sgot
->output_offset
);
5119 case BFD_RELOC_AARCH64_MOVW_GOTOFF_G0_NC
:
5120 case BFD_RELOC_AARCH64_MOVW_GOTOFF_G1
:
5121 case BFD_RELOC_AARCH64_LD64_GOTOFF_LO15
:
5122 value
= (value
- globals
->root
.sgot
->output_section
->vma
5123 - globals
->root
.sgot
->output_offset
);
5128 value
= _bfd_aarch64_elf_resolve_relocation (bfd_r_type
, place
, value
,
5129 addend
, weak_undef_p
);
5130 return _bfd_aarch64_elf_put_addend (input_bfd
, hit_data
, bfd_r_type
, howto
, value
);
5131 case BFD_RELOC_AARCH64_ADD_LO12
:
5132 case BFD_RELOC_AARCH64_ADR_HI21_PCREL
:
5139 case BFD_RELOC_AARCH64_NONE
:
5140 case BFD_RELOC_AARCH64_TLSDESC_CALL
:
5141 *unresolved_reloc_p
= FALSE
;
5142 return bfd_reloc_ok
;
5144 case BFD_RELOC_AARCH64_NN
:
5146 /* When generating a shared object or relocatable executable, these
5147 relocations are copied into the output file to be resolved at
5149 if (((bfd_link_pic (info
) == TRUE
)
5150 || globals
->root
.is_relocatable_executable
)
5151 && (input_section
->flags
& SEC_ALLOC
)
5153 || ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
5154 || h
->root
.type
!= bfd_link_hash_undefweak
))
5156 Elf_Internal_Rela outrel
;
5158 bfd_boolean skip
, relocate
;
5161 *unresolved_reloc_p
= FALSE
;
5166 outrel
.r_addend
= signed_addend
;
5168 _bfd_elf_section_offset (output_bfd
, info
, input_section
,
5170 if (outrel
.r_offset
== (bfd_vma
) - 1)
5172 else if (outrel
.r_offset
== (bfd_vma
) - 2)
5178 outrel
.r_offset
+= (input_section
->output_section
->vma
5179 + input_section
->output_offset
);
5182 memset (&outrel
, 0, sizeof outrel
);
5185 && (!bfd_link_pic (info
)
5186 || !SYMBOLIC_BIND (info
, h
)
5187 || !h
->def_regular
))
5188 outrel
.r_info
= ELFNN_R_INFO (h
->dynindx
, r_type
);
5193 /* On SVR4-ish systems, the dynamic loader cannot
5194 relocate the text and data segments independently,
5195 so the symbol does not matter. */
5197 outrel
.r_info
= ELFNN_R_INFO (symbol
, AARCH64_R (RELATIVE
));
5198 outrel
.r_addend
+= value
;
5201 sreloc
= elf_section_data (input_section
)->sreloc
;
5202 if (sreloc
== NULL
|| sreloc
->contents
== NULL
)
5203 return bfd_reloc_notsupported
;
5205 loc
= sreloc
->contents
+ sreloc
->reloc_count
++ * RELOC_SIZE (globals
);
5206 bfd_elfNN_swap_reloca_out (output_bfd
, &outrel
, loc
);
5208 if (sreloc
->reloc_count
* RELOC_SIZE (globals
) > sreloc
->size
)
5210 /* Sanity to check that we have previously allocated
5211 sufficient space in the relocation section for the
5212 number of relocations we actually want to emit. */
5216 /* If this reloc is against an external symbol, we do not want to
5217 fiddle with the addend. Otherwise, we need to include the symbol
5218 value so that it becomes an addend for the dynamic reloc. */
5220 return bfd_reloc_ok
;
5222 return _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
5223 contents
, rel
->r_offset
, value
,
5227 value
+= signed_addend
;
5230 case BFD_RELOC_AARCH64_CALL26
:
5231 case BFD_RELOC_AARCH64_JUMP26
:
5233 asection
*splt
= globals
->root
.splt
;
5234 bfd_boolean via_plt_p
=
5235 splt
!= NULL
&& h
!= NULL
&& h
->plt
.offset
!= (bfd_vma
) - 1;
5237 /* A call to an undefined weak symbol is converted to a jump to
5238 the next instruction unless a PLT entry will be created.
5239 The jump to the next instruction is optimized as a NOP.
5240 Do the same for local undefined symbols. */
5241 if (weak_undef_p
&& ! via_plt_p
)
5243 bfd_putl32 (INSN_NOP
, hit_data
);
5244 return bfd_reloc_ok
;
5247 /* If the call goes through a PLT entry, make sure to
5248 check distance to the right destination address. */
5250 value
= (splt
->output_section
->vma
5251 + splt
->output_offset
+ h
->plt
.offset
);
5253 /* Check if a stub has to be inserted because the destination
5255 struct elf_aarch64_stub_hash_entry
*stub_entry
= NULL
;
5256 if (! aarch64_valid_branch_p (value
, place
))
5257 /* The target is out of reach, so redirect the branch to
5258 the local stub for this function. */
5259 stub_entry
= elfNN_aarch64_get_stub_entry (input_section
, sym_sec
, h
,
5261 if (stub_entry
!= NULL
)
5262 value
= (stub_entry
->stub_offset
5263 + stub_entry
->stub_sec
->output_offset
5264 + stub_entry
->stub_sec
->output_section
->vma
);
5266 value
= _bfd_aarch64_elf_resolve_relocation (bfd_r_type
, place
, value
,
5267 signed_addend
, weak_undef_p
);
5268 *unresolved_reloc_p
= FALSE
;
5271 case BFD_RELOC_AARCH64_16_PCREL
:
5272 case BFD_RELOC_AARCH64_32_PCREL
:
5273 case BFD_RELOC_AARCH64_64_PCREL
:
5274 case BFD_RELOC_AARCH64_ADR_HI21_NC_PCREL
:
5275 case BFD_RELOC_AARCH64_ADR_HI21_PCREL
:
5276 case BFD_RELOC_AARCH64_ADR_LO21_PCREL
:
5277 case BFD_RELOC_AARCH64_LD_LO19_PCREL
:
5278 if (bfd_link_pic (info
)
5279 && (input_section
->flags
& SEC_ALLOC
) != 0
5280 && (input_section
->flags
& SEC_READONLY
) != 0
5284 int howto_index
= bfd_r_type
- BFD_RELOC_AARCH64_RELOC_START
;
5286 (*_bfd_error_handler
)
5287 (_("%B: relocation %s against external symbol `%s' can not be used"
5288 " when making a shared object; recompile with -fPIC"),
5289 input_bfd
, elfNN_aarch64_howto_table
[howto_index
].name
,
5290 h
->root
.root
.string
);
5291 bfd_set_error (bfd_error_bad_value
);
5295 case BFD_RELOC_AARCH64_16
:
5297 case BFD_RELOC_AARCH64_32
:
5299 case BFD_RELOC_AARCH64_ADD_LO12
:
5300 case BFD_RELOC_AARCH64_BRANCH19
:
5301 case BFD_RELOC_AARCH64_LDST128_LO12
:
5302 case BFD_RELOC_AARCH64_LDST16_LO12
:
5303 case BFD_RELOC_AARCH64_LDST32_LO12
:
5304 case BFD_RELOC_AARCH64_LDST64_LO12
:
5305 case BFD_RELOC_AARCH64_LDST8_LO12
:
5306 case BFD_RELOC_AARCH64_MOVW_G0
:
5307 case BFD_RELOC_AARCH64_MOVW_G0_NC
:
5308 case BFD_RELOC_AARCH64_MOVW_G0_S
:
5309 case BFD_RELOC_AARCH64_MOVW_G1
:
5310 case BFD_RELOC_AARCH64_MOVW_G1_NC
:
5311 case BFD_RELOC_AARCH64_MOVW_G1_S
:
5312 case BFD_RELOC_AARCH64_MOVW_G2
:
5313 case BFD_RELOC_AARCH64_MOVW_G2_NC
:
5314 case BFD_RELOC_AARCH64_MOVW_G2_S
:
5315 case BFD_RELOC_AARCH64_MOVW_G3
:
5316 case BFD_RELOC_AARCH64_TSTBR14
:
5317 value
= _bfd_aarch64_elf_resolve_relocation (bfd_r_type
, place
, value
,
5318 signed_addend
, weak_undef_p
);
5321 case BFD_RELOC_AARCH64_ADR_GOT_PAGE
:
5322 case BFD_RELOC_AARCH64_GOT_LD_PREL19
:
5323 case BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14
:
5324 case BFD_RELOC_AARCH64_LD32_GOT_LO12_NC
:
5325 case BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15
:
5326 case BFD_RELOC_AARCH64_LD64_GOT_LO12_NC
:
5327 if (globals
->root
.sgot
== NULL
)
5328 BFD_ASSERT (h
!= NULL
);
5333 value
= aarch64_calculate_got_entry_vma (h
, globals
, info
, value
,
5335 unresolved_reloc_p
);
5336 if (bfd_r_type
== BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15
5337 || bfd_r_type
== BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14
)
5338 addend
= (globals
->root
.sgot
->output_section
->vma
5339 + globals
->root
.sgot
->output_offset
);
5340 value
= _bfd_aarch64_elf_resolve_relocation (bfd_r_type
, place
, value
,
5341 addend
, weak_undef_p
);
5346 struct elf_aarch64_local_symbol
*locals
5347 = elf_aarch64_locals (input_bfd
);
5351 int howto_index
= bfd_r_type
- BFD_RELOC_AARCH64_RELOC_START
;
5352 (*_bfd_error_handler
)
5353 (_("%B: Local symbol descriptor table be NULL when applying "
5354 "relocation %s against local symbol"),
5355 input_bfd
, elfNN_aarch64_howto_table
[howto_index
].name
);
5359 off
= symbol_got_offset (input_bfd
, h
, r_symndx
);
5360 base_got
= globals
->root
.sgot
;
5361 bfd_vma got_entry_addr
= (base_got
->output_section
->vma
5362 + base_got
->output_offset
+ off
);
5364 if (!symbol_got_offset_mark_p (input_bfd
, h
, r_symndx
))
5366 bfd_put_64 (output_bfd
, value
, base_got
->contents
+ off
);
5368 if (bfd_link_pic (info
))
5371 Elf_Internal_Rela outrel
;
5373 /* For local symbol, we have done absolute relocation in static
5374 linking stageh. While for share library, we need to update
5375 the content of GOT entry according to the share objects
5376 loading base address. So we need to generate a
5377 R_AARCH64_RELATIVE reloc for dynamic linker. */
5378 s
= globals
->root
.srelgot
;
5382 outrel
.r_offset
= got_entry_addr
;
5383 outrel
.r_info
= ELFNN_R_INFO (0, AARCH64_R (RELATIVE
));
5384 outrel
.r_addend
= value
;
5385 elf_append_rela (output_bfd
, s
, &outrel
);
5388 symbol_got_offset_mark (input_bfd
, h
, r_symndx
);
5391 /* Update the relocation value to GOT entry addr as we have transformed
5392 the direct data access into indirect data access through GOT. */
5393 value
= got_entry_addr
;
5395 if (bfd_r_type
== BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15
5396 || bfd_r_type
== BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14
)
5397 addend
= base_got
->output_section
->vma
+ base_got
->output_offset
;
5399 value
= _bfd_aarch64_elf_resolve_relocation (bfd_r_type
, place
, value
,
5400 addend
, weak_undef_p
);
5405 case BFD_RELOC_AARCH64_LD64_GOTOFF_LO15
:
5406 case BFD_RELOC_AARCH64_MOVW_GOTOFF_G0_NC
:
5407 case BFD_RELOC_AARCH64_MOVW_GOTOFF_G1
:
5409 value
= aarch64_calculate_got_entry_vma (h
, globals
, info
, value
,
5411 unresolved_reloc_p
);
5414 struct elf_aarch64_local_symbol
*locals
5415 = elf_aarch64_locals (input_bfd
);
5419 int howto_index
= bfd_r_type
- BFD_RELOC_AARCH64_RELOC_START
;
5420 (*_bfd_error_handler
)
5421 (_("%B: Local symbol descriptor table be NULL when applying "
5422 "relocation %s against local symbol"),
5423 input_bfd
, elfNN_aarch64_howto_table
[howto_index
].name
);
5427 off
= symbol_got_offset (input_bfd
, h
, r_symndx
);
5428 base_got
= globals
->root
.sgot
;
5429 if (base_got
== NULL
)
5432 bfd_vma got_entry_addr
= (base_got
->output_section
->vma
5433 + base_got
->output_offset
+ off
);
5435 if (!symbol_got_offset_mark_p (input_bfd
, h
, r_symndx
))
5437 bfd_put_64 (output_bfd
, value
, base_got
->contents
+ off
);
5439 if (bfd_link_pic (info
))
5442 Elf_Internal_Rela outrel
;
5444 /* For local symbol, we have done absolute relocation in static
5445 linking stage. While for share library, we need to update
5446 the content of GOT entry according to the share objects
5447 loading base address. So we need to generate a
5448 R_AARCH64_RELATIVE reloc for dynamic linker. */
5449 s
= globals
->root
.srelgot
;
5453 outrel
.r_offset
= got_entry_addr
;
5454 outrel
.r_info
= ELFNN_R_INFO (0, AARCH64_R (RELATIVE
));
5455 outrel
.r_addend
= value
;
5456 elf_append_rela (output_bfd
, s
, &outrel
);
5459 symbol_got_offset_mark (input_bfd
, h
, r_symndx
);
5463 /* Update the relocation value to GOT entry addr as we have transformed
5464 the direct data access into indirect data access through GOT. */
5465 value
= symbol_got_offset (input_bfd
, h
, r_symndx
);
5466 value
= _bfd_aarch64_elf_resolve_relocation (bfd_r_type
, place
, value
,
5468 *unresolved_reloc_p
= FALSE
;
5471 case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC
:
5472 case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21
:
5473 case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21
:
5474 case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21
:
5475 case BFD_RELOC_AARCH64_TLSIE_LD32_GOTTPREL_LO12_NC
:
5476 case BFD_RELOC_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC
:
5477 case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19
:
5478 case BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC
:
5479 case BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21
:
5480 case BFD_RELOC_AARCH64_TLSLD_ADR_PREL21
:
5481 if (globals
->root
.sgot
== NULL
)
5482 return bfd_reloc_notsupported
;
5484 value
= (symbol_got_offset (input_bfd
, h
, r_symndx
)
5485 + globals
->root
.sgot
->output_section
->vma
5486 + globals
->root
.sgot
->output_offset
);
5488 value
= _bfd_aarch64_elf_resolve_relocation (bfd_r_type
, place
, value
,
5490 *unresolved_reloc_p
= FALSE
;
5493 case BFD_RELOC_AARCH64_TLSGD_MOVW_G0_NC
:
5494 case BFD_RELOC_AARCH64_TLSGD_MOVW_G1
:
5495 case BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G0_NC
:
5496 case BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G1
:
5497 if (globals
->root
.sgot
== NULL
)
5498 return bfd_reloc_notsupported
;
5500 value
= symbol_got_offset (input_bfd
, h
, r_symndx
);
5501 value
= _bfd_aarch64_elf_resolve_relocation (bfd_r_type
, place
, value
,
5503 *unresolved_reloc_p
= FALSE
;
5506 case BFD_RELOC_AARCH64_TLSLD_ADD_DTPREL_HI12
:
5507 case BFD_RELOC_AARCH64_TLSLD_ADD_DTPREL_LO12
:
5508 case BFD_RELOC_AARCH64_TLSLD_ADD_DTPREL_LO12_NC
:
5509 case BFD_RELOC_AARCH64_TLSLD_LDST16_DTPREL_LO12
:
5510 case BFD_RELOC_AARCH64_TLSLD_LDST16_DTPREL_LO12_NC
:
5511 case BFD_RELOC_AARCH64_TLSLD_LDST32_DTPREL_LO12
:
5512 case BFD_RELOC_AARCH64_TLSLD_LDST32_DTPREL_LO12_NC
:
5513 case BFD_RELOC_AARCH64_TLSLD_LDST64_DTPREL_LO12
:
5514 case BFD_RELOC_AARCH64_TLSLD_LDST64_DTPREL_LO12_NC
:
5515 case BFD_RELOC_AARCH64_TLSLD_LDST8_DTPREL_LO12
:
5516 case BFD_RELOC_AARCH64_TLSLD_LDST8_DTPREL_LO12_NC
:
5517 case BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G0
:
5518 case BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G0_NC
:
5519 case BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G1
:
5520 case BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G1_NC
:
5521 case BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G2
:
5522 value
= _bfd_aarch64_elf_resolve_relocation (bfd_r_type
, place
, value
,
5523 signed_addend
- dtpoff_base (info
),
5527 case BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_HI12
:
5528 case BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_LO12
:
5529 case BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_LO12_NC
:
5530 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0
:
5531 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC
:
5532 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1
:
5533 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1_NC
:
5534 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G2
:
5535 value
= _bfd_aarch64_elf_resolve_relocation (bfd_r_type
, place
, value
,
5536 signed_addend
- tpoff_base (info
),
5538 *unresolved_reloc_p
= FALSE
;
5541 case BFD_RELOC_AARCH64_TLSDESC_ADD
:
5542 case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12_NC
:
5543 case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21
:
5544 case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21
:
5545 case BFD_RELOC_AARCH64_TLSDESC_LD32_LO12_NC
:
5546 case BFD_RELOC_AARCH64_TLSDESC_LD64_LO12_NC
:
5547 case BFD_RELOC_AARCH64_TLSDESC_LDR
:
5548 case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19
:
5549 if (globals
->root
.sgot
== NULL
)
5550 return bfd_reloc_notsupported
;
5551 value
= (symbol_tlsdesc_got_offset (input_bfd
, h
, r_symndx
)
5552 + globals
->root
.sgotplt
->output_section
->vma
5553 + globals
->root
.sgotplt
->output_offset
5554 + globals
->sgotplt_jump_table_size
);
5556 value
= _bfd_aarch64_elf_resolve_relocation (bfd_r_type
, place
, value
,
5558 *unresolved_reloc_p
= FALSE
;
5562 return bfd_reloc_notsupported
;
5566 *saved_addend
= value
;
5568 /* Only apply the final relocation in a sequence. */
5570 return bfd_reloc_continue
;
5572 return _bfd_aarch64_elf_put_addend (input_bfd
, hit_data
, bfd_r_type
,
5576 /* Handle TLS relaxations. Relaxing is possible for symbols that use
5577 R_AARCH64_TLSDESC_ADR_{PAGE, LD64_LO12_NC, ADD_LO12_NC} during a static
5580 Return bfd_reloc_ok if we're done, bfd_reloc_continue if the caller
5581 is to then call final_link_relocate. Return other values in the
5584 static bfd_reloc_status_type
5585 elfNN_aarch64_tls_relax (struct elf_aarch64_link_hash_table
*globals
,
5586 bfd
*input_bfd
, bfd_byte
*contents
,
5587 Elf_Internal_Rela
*rel
, struct elf_link_hash_entry
*h
)
5589 bfd_boolean is_local
= h
== NULL
;
5590 unsigned int r_type
= ELFNN_R_TYPE (rel
->r_info
);
5593 BFD_ASSERT (globals
&& input_bfd
&& contents
&& rel
);
5595 switch (elfNN_aarch64_bfd_reloc_from_type (r_type
))
5597 case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21
:
5598 case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21
:
5601 /* GD->LE relaxation:
5602 adrp x0, :tlsgd:var => movz x0, :tprel_g1:var
5604 adrp x0, :tlsdesc:var => movz x0, :tprel_g1:var
5606 bfd_putl32 (0xd2a00000, contents
+ rel
->r_offset
);
5607 return bfd_reloc_continue
;
5611 /* GD->IE relaxation:
5612 adrp x0, :tlsgd:var => adrp x0, :gottprel:var
5614 adrp x0, :tlsdesc:var => adrp x0, :gottprel:var
5616 return bfd_reloc_continue
;
5619 case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21
:
5623 case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19
:
5626 /* Tiny TLSDESC->LE relaxation:
5627 ldr x1, :tlsdesc:var => movz x0, #:tprel_g1:var
5628 adr x0, :tlsdesc:var => movk x0, #:tprel_g0_nc:var
5632 BFD_ASSERT (ELFNN_R_TYPE (rel
[1].r_info
) == AARCH64_R (TLSDESC_ADR_PREL21
));
5633 BFD_ASSERT (ELFNN_R_TYPE (rel
[2].r_info
) == AARCH64_R (TLSDESC_CALL
));
5635 rel
[1].r_info
= ELFNN_R_INFO (ELFNN_R_SYM (rel
->r_info
),
5636 AARCH64_R (TLSLE_MOVW_TPREL_G0_NC
));
5637 rel
[2].r_info
= ELFNN_R_INFO (STN_UNDEF
, R_AARCH64_NONE
);
5639 bfd_putl32 (0xd2a00000, contents
+ rel
->r_offset
);
5640 bfd_putl32 (0xf2800000, contents
+ rel
->r_offset
+ 4);
5641 bfd_putl32 (INSN_NOP
, contents
+ rel
->r_offset
+ 8);
5642 return bfd_reloc_continue
;
5646 /* Tiny TLSDESC->IE relaxation:
5647 ldr x1, :tlsdesc:var => ldr x0, :gottprel:var
5648 adr x0, :tlsdesc:var => nop
5652 BFD_ASSERT (ELFNN_R_TYPE (rel
[1].r_info
) == AARCH64_R (TLSDESC_ADR_PREL21
));
5653 BFD_ASSERT (ELFNN_R_TYPE (rel
[2].r_info
) == AARCH64_R (TLSDESC_CALL
));
5655 rel
[1].r_info
= ELFNN_R_INFO (STN_UNDEF
, R_AARCH64_NONE
);
5656 rel
[2].r_info
= ELFNN_R_INFO (STN_UNDEF
, R_AARCH64_NONE
);
5658 bfd_putl32 (0x58000000, contents
+ rel
->r_offset
);
5659 bfd_putl32 (INSN_NOP
, contents
+ rel
->r_offset
+ 4);
5660 bfd_putl32 (INSN_NOP
, contents
+ rel
->r_offset
+ 8);
5661 return bfd_reloc_continue
;
5664 case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21
:
5667 /* Tiny GD->LE relaxation:
5668 adr x0, :tlsgd:var => mrs x1, tpidr_el0
5669 bl __tls_get_addr => add x0, x1, #:tprel_hi12:x, lsl #12
5670 nop => add x0, x0, #:tprel_lo12_nc:x
5673 /* First kill the tls_get_addr reloc on the bl instruction. */
5674 BFD_ASSERT (rel
->r_offset
+ 4 == rel
[1].r_offset
);
5676 bfd_putl32 (0xd53bd041, contents
+ rel
->r_offset
+ 0);
5677 bfd_putl32 (0x91400020, contents
+ rel
->r_offset
+ 4);
5678 bfd_putl32 (0x91000000, contents
+ rel
->r_offset
+ 8);
5680 rel
[1].r_info
= ELFNN_R_INFO (ELFNN_R_SYM (rel
->r_info
),
5681 AARCH64_R (TLSLE_ADD_TPREL_LO12_NC
));
5682 rel
[1].r_offset
= rel
->r_offset
+ 8;
5684 /* Move the current relocation to the second instruction in
5687 rel
->r_info
= ELFNN_R_INFO (ELFNN_R_SYM (rel
->r_info
),
5688 AARCH64_R (TLSLE_ADD_TPREL_HI12
));
5689 return bfd_reloc_continue
;
5693 /* Tiny GD->IE relaxation:
5694 adr x0, :tlsgd:var => ldr x0, :gottprel:var
5695 bl __tls_get_addr => mrs x1, tpidr_el0
5696 nop => add x0, x0, x1
5699 /* First kill the tls_get_addr reloc on the bl instruction. */
5700 BFD_ASSERT (rel
->r_offset
+ 4 == rel
[1].r_offset
);
5701 rel
[1].r_info
= ELFNN_R_INFO (STN_UNDEF
, R_AARCH64_NONE
);
5703 bfd_putl32 (0x58000000, contents
+ rel
->r_offset
);
5704 bfd_putl32 (0xd53bd041, contents
+ rel
->r_offset
+ 4);
5705 bfd_putl32 (0x8b000020, contents
+ rel
->r_offset
+ 8);
5706 return bfd_reloc_continue
;
5710 case BFD_RELOC_AARCH64_TLSGD_MOVW_G1
:
5711 BFD_ASSERT (ELFNN_R_TYPE (rel
[1].r_info
) == AARCH64_R (TLSGD_MOVW_G0_NC
));
5712 BFD_ASSERT (rel
->r_offset
+ 12 == rel
[2].r_offset
);
5713 BFD_ASSERT (ELFNN_R_TYPE (rel
[2].r_info
) == AARCH64_R (CALL26
));
5717 /* Large GD->LE relaxation:
5718 movz x0, #:tlsgd_g1:var => movz x0, #:tprel_g2:var, lsl #32
5719 movk x0, #:tlsgd_g0_nc:var => movk x0, #:tprel_g1_nc:var, lsl #16
5720 add x0, gp, x0 => movk x0, #:tprel_g0_nc:var
5721 bl __tls_get_addr => mrs x1, tpidr_el0
5722 nop => add x0, x0, x1
5724 rel
[2].r_info
= ELFNN_R_INFO (ELFNN_R_SYM (rel
->r_info
),
5725 AARCH64_R (TLSLE_MOVW_TPREL_G0_NC
));
5726 rel
[2].r_offset
= rel
->r_offset
+ 8;
5728 bfd_putl32 (0xd2c00000, contents
+ rel
->r_offset
+ 0);
5729 bfd_putl32 (0xf2a00000, contents
+ rel
->r_offset
+ 4);
5730 bfd_putl32 (0xf2800000, contents
+ rel
->r_offset
+ 8);
5731 bfd_putl32 (0xd53bd041, contents
+ rel
->r_offset
+ 12);
5732 bfd_putl32 (0x8b000020, contents
+ rel
->r_offset
+ 16);
5736 /* Large GD->IE relaxation:
5737 movz x0, #:tlsgd_g1:var => movz x0, #:gottprel_g1:var, lsl #16
5738 movk x0, #:tlsgd_g0_nc:var => movk x0, #:gottprel_g0_nc:var
5739 add x0, gp, x0 => ldr x0, [gp, x0]
5740 bl __tls_get_addr => mrs x1, tpidr_el0
5741 nop => add x0, x0, x1
5743 rel
[2].r_info
= ELFNN_R_INFO (STN_UNDEF
, R_AARCH64_NONE
);
5744 bfd_putl32 (0xd2a80000, contents
+ rel
->r_offset
+ 0);
5745 bfd_putl32 (0x58000000, contents
+ rel
->r_offset
+ 8);
5746 bfd_putl32 (0xd53bd041, contents
+ rel
->r_offset
+ 12);
5747 bfd_putl32 (0x8b000020, contents
+ rel
->r_offset
+ 16);
5749 return bfd_reloc_continue
;
5751 case BFD_RELOC_AARCH64_TLSGD_MOVW_G0_NC
:
5752 return bfd_reloc_continue
;
5755 case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19
:
5756 return bfd_reloc_continue
;
5758 case BFD_RELOC_AARCH64_TLSDESC_LDNN_LO12_NC
:
5761 /* GD->LE relaxation:
5762 ldr xd, [x0, #:tlsdesc_lo12:var] => movk x0, :tprel_g0_nc:var
5764 bfd_putl32 (0xf2800000, contents
+ rel
->r_offset
);
5765 return bfd_reloc_continue
;
5769 /* GD->IE relaxation:
5770 ldr xd, [x0, #:tlsdesc_lo12:var] => ldr x0, [x0, #:gottprel_lo12:var]
5772 insn
= bfd_getl32 (contents
+ rel
->r_offset
);
5774 bfd_putl32 (insn
, contents
+ rel
->r_offset
);
5775 return bfd_reloc_continue
;
5778 case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC
:
5781 /* GD->LE relaxation
5782 add x0, #:tlsgd_lo12:var => movk x0, :tprel_g0_nc:var
5783 bl __tls_get_addr => mrs x1, tpidr_el0
5784 nop => add x0, x1, x0
5787 /* First kill the tls_get_addr reloc on the bl instruction. */
5788 BFD_ASSERT (rel
->r_offset
+ 4 == rel
[1].r_offset
);
5789 rel
[1].r_info
= ELFNN_R_INFO (STN_UNDEF
, R_AARCH64_NONE
);
5791 bfd_putl32 (0xf2800000, contents
+ rel
->r_offset
);
5792 bfd_putl32 (0xd53bd041, contents
+ rel
->r_offset
+ 4);
5793 bfd_putl32 (0x8b000020, contents
+ rel
->r_offset
+ 8);
5794 return bfd_reloc_continue
;
5798 /* GD->IE relaxation
5799 ADD x0, #:tlsgd_lo12:var => ldr x0, [x0, #:gottprel_lo12:var]
5800 BL __tls_get_addr => mrs x1, tpidr_el0
5802 NOP => add x0, x1, x0
5805 BFD_ASSERT (ELFNN_R_TYPE (rel
[1].r_info
) == AARCH64_R (CALL26
));
5807 /* Remove the relocation on the BL instruction. */
5808 rel
[1].r_info
= ELFNN_R_INFO (STN_UNDEF
, R_AARCH64_NONE
);
5810 bfd_putl32 (0xf9400000, contents
+ rel
->r_offset
);
5812 /* We choose to fixup the BL and NOP instructions using the
5813 offset from the second relocation to allow flexibility in
5814 scheduling instructions between the ADD and BL. */
5815 bfd_putl32 (0xd53bd041, contents
+ rel
[1].r_offset
);
5816 bfd_putl32 (0x8b000020, contents
+ rel
[1].r_offset
+ 4);
5817 return bfd_reloc_continue
;
5820 case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12_NC
:
5821 case BFD_RELOC_AARCH64_TLSDESC_CALL
:
5822 /* GD->IE/LE relaxation:
5823 add x0, x0, #:tlsdesc_lo12:var => nop
5826 bfd_putl32 (INSN_NOP
, contents
+ rel
->r_offset
);
5827 return bfd_reloc_ok
;
5829 case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21
:
5830 /* IE->LE relaxation:
5831 adrp xd, :gottprel:var => movz xd, :tprel_g1:var
5835 insn
= bfd_getl32 (contents
+ rel
->r_offset
);
5836 bfd_putl32 (0xd2a00000 | (insn
& 0x1f), contents
+ rel
->r_offset
);
5838 return bfd_reloc_continue
;
5840 case BFD_RELOC_AARCH64_TLSIE_LDNN_GOTTPREL_LO12_NC
:
5841 /* IE->LE relaxation:
5842 ldr xd, [xm, #:gottprel_lo12:var] => movk xd, :tprel_g0_nc:var
5846 insn
= bfd_getl32 (contents
+ rel
->r_offset
);
5847 bfd_putl32 (0xf2800000 | (insn
& 0x1f), contents
+ rel
->r_offset
);
5849 return bfd_reloc_continue
;
5851 case BFD_RELOC_AARCH64_TLSLD_ADR_PREL21
:
5852 /* LD->LE relaxation (tiny):
5853 adr x0, :tlsldm:x => mrs x0, tpidr_el0
5854 bl __tls_get_addr => add x0, x0, TCB_SIZE
5858 BFD_ASSERT (rel
->r_offset
+ 4 == rel
[1].r_offset
);
5859 BFD_ASSERT (ELFNN_R_TYPE (rel
[1].r_info
) == AARCH64_R (CALL26
));
5860 /* No need of CALL26 relocation for tls_get_addr. */
5861 rel
[1].r_info
= ELFNN_R_INFO (STN_UNDEF
, R_AARCH64_NONE
);
5862 bfd_putl32 (0xd53bd040, contents
+ rel
->r_offset
+ 0);
5863 bfd_putl32 (0x91004000, contents
+ rel
->r_offset
+ 4);
5864 return bfd_reloc_ok
;
5866 return bfd_reloc_continue
;
5868 case BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21
:
5869 /* LD->LE relaxation (small):
5870 adrp x0, :tlsldm:x => mrs x0, tpidr_el0
5874 bfd_putl32 (0xd53bd040, contents
+ rel
->r_offset
);
5875 return bfd_reloc_ok
;
5877 return bfd_reloc_continue
;
5879 case BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC
:
5880 /* LD->LE relaxation (small):
5881 add x0, #:tlsldm_lo12:x => add x0, x0, TCB_SIZE
5882 bl __tls_get_addr => nop
5886 BFD_ASSERT (rel
->r_offset
+ 4 == rel
[1].r_offset
);
5887 BFD_ASSERT (ELFNN_R_TYPE (rel
[1].r_info
) == AARCH64_R (CALL26
));
5888 /* No need of CALL26 relocation for tls_get_addr. */
5889 rel
[1].r_info
= ELFNN_R_INFO (STN_UNDEF
, R_AARCH64_NONE
);
5890 bfd_putl32 (0x91004000, contents
+ rel
->r_offset
+ 0);
5891 bfd_putl32 (0xd503201f, contents
+ rel
->r_offset
+ 4);
5892 return bfd_reloc_ok
;
5894 return bfd_reloc_continue
;
5897 return bfd_reloc_continue
;
5900 return bfd_reloc_ok
;
5903 /* Relocate an AArch64 ELF section. */
5906 elfNN_aarch64_relocate_section (bfd
*output_bfd
,
5907 struct bfd_link_info
*info
,
5909 asection
*input_section
,
5911 Elf_Internal_Rela
*relocs
,
5912 Elf_Internal_Sym
*local_syms
,
5913 asection
**local_sections
)
5915 Elf_Internal_Shdr
*symtab_hdr
;
5916 struct elf_link_hash_entry
**sym_hashes
;
5917 Elf_Internal_Rela
*rel
;
5918 Elf_Internal_Rela
*relend
;
5920 struct elf_aarch64_link_hash_table
*globals
;
5921 bfd_boolean save_addend
= FALSE
;
5924 globals
= elf_aarch64_hash_table (info
);
5926 symtab_hdr
= &elf_symtab_hdr (input_bfd
);
5927 sym_hashes
= elf_sym_hashes (input_bfd
);
5930 relend
= relocs
+ input_section
->reloc_count
;
5931 for (; rel
< relend
; rel
++)
5933 unsigned int r_type
;
5934 bfd_reloc_code_real_type bfd_r_type
;
5935 bfd_reloc_code_real_type relaxed_bfd_r_type
;
5936 reloc_howto_type
*howto
;
5937 unsigned long r_symndx
;
5938 Elf_Internal_Sym
*sym
;
5940 struct elf_link_hash_entry
*h
;
5942 bfd_reloc_status_type r
;
5945 bfd_boolean unresolved_reloc
= FALSE
;
5946 char *error_message
= NULL
;
5948 r_symndx
= ELFNN_R_SYM (rel
->r_info
);
5949 r_type
= ELFNN_R_TYPE (rel
->r_info
);
5951 bfd_reloc
.howto
= elfNN_aarch64_howto_from_type (r_type
);
5952 howto
= bfd_reloc
.howto
;
5956 (*_bfd_error_handler
)
5957 (_("%B: unrecognized relocation (0x%x) in section `%A'"),
5958 input_bfd
, input_section
, r_type
);
5961 bfd_r_type
= elfNN_aarch64_bfd_reloc_from_howto (howto
);
5967 if (r_symndx
< symtab_hdr
->sh_info
)
5969 sym
= local_syms
+ r_symndx
;
5970 sym_type
= ELFNN_ST_TYPE (sym
->st_info
);
5971 sec
= local_sections
[r_symndx
];
5973 /* An object file might have a reference to a local
5974 undefined symbol. This is a daft object file, but we
5975 should at least do something about it. */
5976 if (r_type
!= R_AARCH64_NONE
&& r_type
!= R_AARCH64_NULL
5977 && bfd_is_und_section (sec
)
5978 && ELF_ST_BIND (sym
->st_info
) != STB_WEAK
)
5980 if (!info
->callbacks
->undefined_symbol
5981 (info
, bfd_elf_string_from_elf_section
5982 (input_bfd
, symtab_hdr
->sh_link
, sym
->st_name
),
5983 input_bfd
, input_section
, rel
->r_offset
, TRUE
))
5987 relocation
= _bfd_elf_rela_local_sym (output_bfd
, sym
, &sec
, rel
);
5989 /* Relocate against local STT_GNU_IFUNC symbol. */
5990 if (!bfd_link_relocatable (info
)
5991 && ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
)
5993 h
= elfNN_aarch64_get_local_sym_hash (globals
, input_bfd
,
5998 /* Set STT_GNU_IFUNC symbol value. */
5999 h
->root
.u
.def
.value
= sym
->st_value
;
6000 h
->root
.u
.def
.section
= sec
;
6005 bfd_boolean warned
, ignored
;
6007 RELOC_FOR_GLOBAL_SYMBOL (info
, input_bfd
, input_section
, rel
,
6008 r_symndx
, symtab_hdr
, sym_hashes
,
6010 unresolved_reloc
, warned
, ignored
);
6015 if (sec
!= NULL
&& discarded_section (sec
))
6016 RELOC_AGAINST_DISCARDED_SECTION (info
, input_bfd
, input_section
,
6017 rel
, 1, relend
, howto
, 0, contents
);
6019 if (bfd_link_relocatable (info
))
6023 name
= h
->root
.root
.string
;
6026 name
= (bfd_elf_string_from_elf_section
6027 (input_bfd
, symtab_hdr
->sh_link
, sym
->st_name
));
6028 if (name
== NULL
|| *name
== '\0')
6029 name
= bfd_section_name (input_bfd
, sec
);
6033 && r_type
!= R_AARCH64_NONE
6034 && r_type
!= R_AARCH64_NULL
6036 || h
->root
.type
== bfd_link_hash_defined
6037 || h
->root
.type
== bfd_link_hash_defweak
)
6038 && IS_AARCH64_TLS_RELOC (bfd_r_type
) != (sym_type
== STT_TLS
))
6040 (*_bfd_error_handler
)
6041 ((sym_type
== STT_TLS
6042 ? _("%B(%A+0x%lx): %s used with TLS symbol %s")
6043 : _("%B(%A+0x%lx): %s used with non-TLS symbol %s")),
6045 input_section
, (long) rel
->r_offset
, howto
->name
, name
);
6048 /* We relax only if we can see that there can be a valid transition
6049 from a reloc type to another.
6050 We call elfNN_aarch64_final_link_relocate unless we're completely
6051 done, i.e., the relaxation produced the final output we want. */
6053 relaxed_bfd_r_type
= aarch64_tls_transition (input_bfd
, info
, r_type
,
6055 if (relaxed_bfd_r_type
!= bfd_r_type
)
6057 bfd_r_type
= relaxed_bfd_r_type
;
6058 howto
= elfNN_aarch64_howto_from_bfd_reloc (bfd_r_type
);
6059 BFD_ASSERT (howto
!= NULL
);
6060 r_type
= howto
->type
;
6061 r
= elfNN_aarch64_tls_relax (globals
, input_bfd
, contents
, rel
, h
);
6062 unresolved_reloc
= 0;
6065 r
= bfd_reloc_continue
;
6067 /* There may be multiple consecutive relocations for the
6068 same offset. In that case we are supposed to treat the
6069 output of each relocation as the addend for the next. */
6070 if (rel
+ 1 < relend
6071 && rel
->r_offset
== rel
[1].r_offset
6072 && ELFNN_R_TYPE (rel
[1].r_info
) != R_AARCH64_NONE
6073 && ELFNN_R_TYPE (rel
[1].r_info
) != R_AARCH64_NULL
)
6076 save_addend
= FALSE
;
6078 if (r
== bfd_reloc_continue
)
6079 r
= elfNN_aarch64_final_link_relocate (howto
, input_bfd
, output_bfd
,
6080 input_section
, contents
, rel
,
6081 relocation
, info
, sec
,
6082 h
, &unresolved_reloc
,
6083 save_addend
, &addend
, sym
);
6085 switch (elfNN_aarch64_bfd_reloc_from_type (r_type
))
6087 case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC
:
6088 case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21
:
6089 case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21
:
6090 case BFD_RELOC_AARCH64_TLSGD_MOVW_G0_NC
:
6091 case BFD_RELOC_AARCH64_TLSGD_MOVW_G1
:
6092 case BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC
:
6093 case BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21
:
6094 case BFD_RELOC_AARCH64_TLSLD_ADR_PREL21
:
6095 if (! symbol_got_offset_mark_p (input_bfd
, h
, r_symndx
))
6097 bfd_boolean need_relocs
= FALSE
;
6102 off
= symbol_got_offset (input_bfd
, h
, r_symndx
);
6103 indx
= h
&& h
->dynindx
!= -1 ? h
->dynindx
: 0;
6106 (bfd_link_pic (info
) || indx
!= 0) &&
6108 || ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
6109 || h
->root
.type
!= bfd_link_hash_undefweak
);
6111 BFD_ASSERT (globals
->root
.srelgot
!= NULL
);
6115 Elf_Internal_Rela rela
;
6116 rela
.r_info
= ELFNN_R_INFO (indx
, AARCH64_R (TLS_DTPMOD
));
6118 rela
.r_offset
= globals
->root
.sgot
->output_section
->vma
+
6119 globals
->root
.sgot
->output_offset
+ off
;
6122 loc
= globals
->root
.srelgot
->contents
;
6123 loc
+= globals
->root
.srelgot
->reloc_count
++
6124 * RELOC_SIZE (htab
);
6125 bfd_elfNN_swap_reloca_out (output_bfd
, &rela
, loc
);
6127 bfd_reloc_code_real_type real_type
=
6128 elfNN_aarch64_bfd_reloc_from_type (r_type
);
6130 if (real_type
== BFD_RELOC_AARCH64_TLSLD_ADR_PREL21
6131 || real_type
== BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21
6132 || real_type
== BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC
)
6134 /* For local dynamic, don't generate DTPREL in any case.
6135 Initialize the DTPREL slot into zero, so we get module
6136 base address when invoke runtime TLS resolver. */
6137 bfd_put_NN (output_bfd
, 0,
6138 globals
->root
.sgot
->contents
+ off
6143 bfd_put_NN (output_bfd
,
6144 relocation
- dtpoff_base (info
),
6145 globals
->root
.sgot
->contents
+ off
6150 /* This TLS symbol is global. We emit a
6151 relocation to fixup the tls offset at load
6154 ELFNN_R_INFO (indx
, AARCH64_R (TLS_DTPREL
));
6157 (globals
->root
.sgot
->output_section
->vma
6158 + globals
->root
.sgot
->output_offset
+ off
6161 loc
= globals
->root
.srelgot
->contents
;
6162 loc
+= globals
->root
.srelgot
->reloc_count
++
6163 * RELOC_SIZE (globals
);
6164 bfd_elfNN_swap_reloca_out (output_bfd
, &rela
, loc
);
6165 bfd_put_NN (output_bfd
, (bfd_vma
) 0,
6166 globals
->root
.sgot
->contents
+ off
6172 bfd_put_NN (output_bfd
, (bfd_vma
) 1,
6173 globals
->root
.sgot
->contents
+ off
);
6174 bfd_put_NN (output_bfd
,
6175 relocation
- dtpoff_base (info
),
6176 globals
->root
.sgot
->contents
+ off
6180 symbol_got_offset_mark (input_bfd
, h
, r_symndx
);
6184 case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21
:
6185 case BFD_RELOC_AARCH64_TLSIE_LDNN_GOTTPREL_LO12_NC
:
6186 case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19
:
6187 case BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G0_NC
:
6188 case BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G1
:
6189 if (! symbol_got_offset_mark_p (input_bfd
, h
, r_symndx
))
6191 bfd_boolean need_relocs
= FALSE
;
6196 off
= symbol_got_offset (input_bfd
, h
, r_symndx
);
6198 indx
= h
&& h
->dynindx
!= -1 ? h
->dynindx
: 0;
6201 (bfd_link_pic (info
) || indx
!= 0) &&
6203 || ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
6204 || h
->root
.type
!= bfd_link_hash_undefweak
);
6206 BFD_ASSERT (globals
->root
.srelgot
!= NULL
);
6210 Elf_Internal_Rela rela
;
6213 rela
.r_addend
= relocation
- dtpoff_base (info
);
6217 rela
.r_info
= ELFNN_R_INFO (indx
, AARCH64_R (TLS_TPREL
));
6218 rela
.r_offset
= globals
->root
.sgot
->output_section
->vma
+
6219 globals
->root
.sgot
->output_offset
+ off
;
6221 loc
= globals
->root
.srelgot
->contents
;
6222 loc
+= globals
->root
.srelgot
->reloc_count
++
6223 * RELOC_SIZE (htab
);
6225 bfd_elfNN_swap_reloca_out (output_bfd
, &rela
, loc
);
6227 bfd_put_NN (output_bfd
, rela
.r_addend
,
6228 globals
->root
.sgot
->contents
+ off
);
6231 bfd_put_NN (output_bfd
, relocation
- tpoff_base (info
),
6232 globals
->root
.sgot
->contents
+ off
);
6234 symbol_got_offset_mark (input_bfd
, h
, r_symndx
);
6238 case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12_NC
:
6239 case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21
:
6240 case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21
:
6241 case BFD_RELOC_AARCH64_TLSDESC_LDNN_LO12_NC
:
6242 case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19
:
6243 if (! symbol_tlsdesc_got_offset_mark_p (input_bfd
, h
, r_symndx
))
6245 bfd_boolean need_relocs
= FALSE
;
6246 int indx
= h
&& h
->dynindx
!= -1 ? h
->dynindx
: 0;
6247 bfd_vma off
= symbol_tlsdesc_got_offset (input_bfd
, h
, r_symndx
);
6249 need_relocs
= (h
== NULL
6250 || ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
6251 || h
->root
.type
!= bfd_link_hash_undefweak
);
6253 BFD_ASSERT (globals
->root
.srelgot
!= NULL
);
6254 BFD_ASSERT (globals
->root
.sgot
!= NULL
);
6259 Elf_Internal_Rela rela
;
6260 rela
.r_info
= ELFNN_R_INFO (indx
, AARCH64_R (TLSDESC
));
6263 rela
.r_offset
= (globals
->root
.sgotplt
->output_section
->vma
6264 + globals
->root
.sgotplt
->output_offset
6265 + off
+ globals
->sgotplt_jump_table_size
);
6268 rela
.r_addend
= relocation
- dtpoff_base (info
);
6270 /* Allocate the next available slot in the PLT reloc
6271 section to hold our R_AARCH64_TLSDESC, the next
6272 available slot is determined from reloc_count,
6273 which we step. But note, reloc_count was
6274 artifically moved down while allocating slots for
6275 real PLT relocs such that all of the PLT relocs
6276 will fit above the initial reloc_count and the
6277 extra stuff will fit below. */
6278 loc
= globals
->root
.srelplt
->contents
;
6279 loc
+= globals
->root
.srelplt
->reloc_count
++
6280 * RELOC_SIZE (globals
);
6282 bfd_elfNN_swap_reloca_out (output_bfd
, &rela
, loc
);
6284 bfd_put_NN (output_bfd
, (bfd_vma
) 0,
6285 globals
->root
.sgotplt
->contents
+ off
+
6286 globals
->sgotplt_jump_table_size
);
6287 bfd_put_NN (output_bfd
, (bfd_vma
) 0,
6288 globals
->root
.sgotplt
->contents
+ off
+
6289 globals
->sgotplt_jump_table_size
+
6293 symbol_tlsdesc_got_offset_mark (input_bfd
, h
, r_symndx
);
6304 /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
6305 because such sections are not SEC_ALLOC and thus ld.so will
6306 not process them. */
6307 if (unresolved_reloc
6308 && !((input_section
->flags
& SEC_DEBUGGING
) != 0
6310 && _bfd_elf_section_offset (output_bfd
, info
, input_section
,
6311 +rel
->r_offset
) != (bfd_vma
) - 1)
6313 (*_bfd_error_handler
)
6315 ("%B(%A+0x%lx): unresolvable %s relocation against symbol `%s'"),
6316 input_bfd
, input_section
, (long) rel
->r_offset
, howto
->name
,
6317 h
->root
.root
.string
);
6321 if (r
!= bfd_reloc_ok
&& r
!= bfd_reloc_continue
)
6323 bfd_reloc_code_real_type real_r_type
6324 = elfNN_aarch64_bfd_reloc_from_type (r_type
);
6328 case bfd_reloc_overflow
:
6329 if (!(*info
->callbacks
->reloc_overflow
)
6330 (info
, (h
? &h
->root
: NULL
), name
, howto
->name
, (bfd_vma
) 0,
6331 input_bfd
, input_section
, rel
->r_offset
))
6333 if (real_r_type
== BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15
6334 || real_r_type
== BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14
)
6336 (*info
->callbacks
->warning
)
6338 _("Too many GOT entries for -fpic, "
6339 "please recompile with -fPIC"),
6340 name
, input_bfd
, input_section
, rel
->r_offset
);
6345 case bfd_reloc_undefined
:
6346 if (!((*info
->callbacks
->undefined_symbol
)
6347 (info
, name
, input_bfd
, input_section
,
6348 rel
->r_offset
, TRUE
)))
6352 case bfd_reloc_outofrange
:
6353 error_message
= _("out of range");
6356 case bfd_reloc_notsupported
:
6357 error_message
= _("unsupported relocation");
6360 case bfd_reloc_dangerous
:
6361 /* error_message should already be set. */
6365 error_message
= _("unknown error");
6369 BFD_ASSERT (error_message
!= NULL
);
6370 if (!((*info
->callbacks
->reloc_dangerous
)
6371 (info
, error_message
, input_bfd
, input_section
,
6382 /* Set the right machine number. */
6385 elfNN_aarch64_object_p (bfd
*abfd
)
6388 bfd_default_set_arch_mach (abfd
, bfd_arch_aarch64
, bfd_mach_aarch64_ilp32
);
6390 bfd_default_set_arch_mach (abfd
, bfd_arch_aarch64
, bfd_mach_aarch64
);
6395 /* Function to keep AArch64 specific flags in the ELF header. */
6398 elfNN_aarch64_set_private_flags (bfd
*abfd
, flagword flags
)
6400 if (elf_flags_init (abfd
) && elf_elfheader (abfd
)->e_flags
!= flags
)
6405 elf_elfheader (abfd
)->e_flags
= flags
;
6406 elf_flags_init (abfd
) = TRUE
;
6412 /* Merge backend specific data from an object file to the output
6413 object file when linking. */
6416 elfNN_aarch64_merge_private_bfd_data (bfd
*ibfd
, bfd
*obfd
)
6420 bfd_boolean flags_compatible
= TRUE
;
6423 /* Check if we have the same endianess. */
6424 if (!_bfd_generic_verify_endian_match (ibfd
, obfd
))
6427 if (!is_aarch64_elf (ibfd
) || !is_aarch64_elf (obfd
))
6430 /* The input BFD must have had its flags initialised. */
6431 /* The following seems bogus to me -- The flags are initialized in
6432 the assembler but I don't think an elf_flags_init field is
6433 written into the object. */
6434 /* BFD_ASSERT (elf_flags_init (ibfd)); */
6436 in_flags
= elf_elfheader (ibfd
)->e_flags
;
6437 out_flags
= elf_elfheader (obfd
)->e_flags
;
6439 if (!elf_flags_init (obfd
))
6441 /* If the input is the default architecture and had the default
6442 flags then do not bother setting the flags for the output
6443 architecture, instead allow future merges to do this. If no
6444 future merges ever set these flags then they will retain their
6445 uninitialised values, which surprise surprise, correspond
6446 to the default values. */
6447 if (bfd_get_arch_info (ibfd
)->the_default
6448 && elf_elfheader (ibfd
)->e_flags
== 0)
6451 elf_flags_init (obfd
) = TRUE
;
6452 elf_elfheader (obfd
)->e_flags
= in_flags
;
6454 if (bfd_get_arch (obfd
) == bfd_get_arch (ibfd
)
6455 && bfd_get_arch_info (obfd
)->the_default
)
6456 return bfd_set_arch_mach (obfd
, bfd_get_arch (ibfd
),
6457 bfd_get_mach (ibfd
));
6462 /* Identical flags must be compatible. */
6463 if (in_flags
== out_flags
)
6466 /* Check to see if the input BFD actually contains any sections. If
6467 not, its flags may not have been initialised either, but it
6468 cannot actually cause any incompatiblity. Do not short-circuit
6469 dynamic objects; their section list may be emptied by
6470 elf_link_add_object_symbols.
6472 Also check to see if there are no code sections in the input.
6473 In this case there is no need to check for code specific flags.
6474 XXX - do we need to worry about floating-point format compatability
6475 in data sections ? */
6476 if (!(ibfd
->flags
& DYNAMIC
))
6478 bfd_boolean null_input_bfd
= TRUE
;
6479 bfd_boolean only_data_sections
= TRUE
;
6481 for (sec
= ibfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
6483 if ((bfd_get_section_flags (ibfd
, sec
)
6484 & (SEC_LOAD
| SEC_CODE
| SEC_HAS_CONTENTS
))
6485 == (SEC_LOAD
| SEC_CODE
| SEC_HAS_CONTENTS
))
6486 only_data_sections
= FALSE
;
6488 null_input_bfd
= FALSE
;
6492 if (null_input_bfd
|| only_data_sections
)
6496 return flags_compatible
;
6499 /* Display the flags field. */
6502 elfNN_aarch64_print_private_bfd_data (bfd
*abfd
, void *ptr
)
6504 FILE *file
= (FILE *) ptr
;
6505 unsigned long flags
;
6507 BFD_ASSERT (abfd
!= NULL
&& ptr
!= NULL
);
6509 /* Print normal ELF private data. */
6510 _bfd_elf_print_private_bfd_data (abfd
, ptr
);
6512 flags
= elf_elfheader (abfd
)->e_flags
;
6513 /* Ignore init flag - it may not be set, despite the flags field
6514 containing valid data. */
6516 /* xgettext:c-format */
6517 fprintf (file
, _("private flags = %lx:"), elf_elfheader (abfd
)->e_flags
);
6520 fprintf (file
, _("<Unrecognised flag bits set>"));
6527 /* Update the got entry reference counts for the section being removed. */
6530 elfNN_aarch64_gc_sweep_hook (bfd
*abfd
,
6531 struct bfd_link_info
*info
,
6533 const Elf_Internal_Rela
* relocs
)
6535 struct elf_aarch64_link_hash_table
*htab
;
6536 Elf_Internal_Shdr
*symtab_hdr
;
6537 struct elf_link_hash_entry
**sym_hashes
;
6538 struct elf_aarch64_local_symbol
*locals
;
6539 const Elf_Internal_Rela
*rel
, *relend
;
6541 if (bfd_link_relocatable (info
))
6544 htab
= elf_aarch64_hash_table (info
);
6549 elf_section_data (sec
)->local_dynrel
= NULL
;
6551 symtab_hdr
= &elf_symtab_hdr (abfd
);
6552 sym_hashes
= elf_sym_hashes (abfd
);
6554 locals
= elf_aarch64_locals (abfd
);
6556 relend
= relocs
+ sec
->reloc_count
;
6557 for (rel
= relocs
; rel
< relend
; rel
++)
6559 unsigned long r_symndx
;
6560 unsigned int r_type
;
6561 struct elf_link_hash_entry
*h
= NULL
;
6563 r_symndx
= ELFNN_R_SYM (rel
->r_info
);
6565 if (r_symndx
>= symtab_hdr
->sh_info
)
6568 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
6569 while (h
->root
.type
== bfd_link_hash_indirect
6570 || h
->root
.type
== bfd_link_hash_warning
)
6571 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
6575 Elf_Internal_Sym
*isym
;
6577 /* A local symbol. */
6578 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
6581 /* Check relocation against local STT_GNU_IFUNC symbol. */
6583 && ELF_ST_TYPE (isym
->st_info
) == STT_GNU_IFUNC
)
6585 h
= elfNN_aarch64_get_local_sym_hash (htab
, abfd
, rel
, FALSE
);
6593 struct elf_aarch64_link_hash_entry
*eh
;
6594 struct elf_dyn_relocs
**pp
;
6595 struct elf_dyn_relocs
*p
;
6597 eh
= (struct elf_aarch64_link_hash_entry
*) h
;
6599 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; pp
= &p
->next
)
6602 /* Everything must go for SEC. */
6608 r_type
= ELFNN_R_TYPE (rel
->r_info
);
6609 switch (aarch64_tls_transition (abfd
,info
, r_type
, h
,r_symndx
))
6611 case BFD_RELOC_AARCH64_ADR_GOT_PAGE
:
6612 case BFD_RELOC_AARCH64_GOT_LD_PREL19
:
6613 case BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14
:
6614 case BFD_RELOC_AARCH64_LD32_GOT_LO12_NC
:
6615 case BFD_RELOC_AARCH64_LD64_GOTOFF_LO15
:
6616 case BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15
:
6617 case BFD_RELOC_AARCH64_LD64_GOT_LO12_NC
:
6618 case BFD_RELOC_AARCH64_MOVW_GOTOFF_G0_NC
:
6619 case BFD_RELOC_AARCH64_MOVW_GOTOFF_G1
:
6620 case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12_NC
:
6621 case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21
:
6622 case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21
:
6623 case BFD_RELOC_AARCH64_TLSDESC_LD32_LO12_NC
:
6624 case BFD_RELOC_AARCH64_TLSDESC_LD64_LO12_NC
:
6625 case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19
:
6626 case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC
:
6627 case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21
:
6628 case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21
:
6629 case BFD_RELOC_AARCH64_TLSGD_MOVW_G0_NC
:
6630 case BFD_RELOC_AARCH64_TLSGD_MOVW_G1
:
6631 case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21
:
6632 case BFD_RELOC_AARCH64_TLSIE_LD32_GOTTPREL_LO12_NC
:
6633 case BFD_RELOC_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC
:
6634 case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19
:
6635 case BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G0_NC
:
6636 case BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G1
:
6637 case BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC
:
6638 case BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21
:
6639 case BFD_RELOC_AARCH64_TLSLD_ADR_PREL21
:
6642 if (h
->got
.refcount
> 0)
6643 h
->got
.refcount
-= 1;
6645 if (h
->type
== STT_GNU_IFUNC
)
6647 if (h
->plt
.refcount
> 0)
6648 h
->plt
.refcount
-= 1;
6651 else if (locals
!= NULL
)
6653 if (locals
[r_symndx
].got_refcount
> 0)
6654 locals
[r_symndx
].got_refcount
-= 1;
6658 case BFD_RELOC_AARCH64_CALL26
:
6659 case BFD_RELOC_AARCH64_JUMP26
:
6660 /* If this is a local symbol then we resolve it
6661 directly without creating a PLT entry. */
6665 if (h
->plt
.refcount
> 0)
6666 h
->plt
.refcount
-= 1;
6669 case BFD_RELOC_AARCH64_ADR_HI21_NC_PCREL
:
6670 case BFD_RELOC_AARCH64_ADR_HI21_PCREL
:
6671 case BFD_RELOC_AARCH64_ADR_LO21_PCREL
:
6672 case BFD_RELOC_AARCH64_MOVW_G0_NC
:
6673 case BFD_RELOC_AARCH64_MOVW_G1_NC
:
6674 case BFD_RELOC_AARCH64_MOVW_G2_NC
:
6675 case BFD_RELOC_AARCH64_MOVW_G3
:
6676 case BFD_RELOC_AARCH64_NN
:
6677 if (h
!= NULL
&& bfd_link_executable (info
))
6679 if (h
->plt
.refcount
> 0)
6680 h
->plt
.refcount
-= 1;
6692 /* Adjust a symbol defined by a dynamic object and referenced by a
6693 regular object. The current definition is in some section of the
6694 dynamic object, but we're not including those sections. We have to
6695 change the definition to something the rest of the link can
6699 elfNN_aarch64_adjust_dynamic_symbol (struct bfd_link_info
*info
,
6700 struct elf_link_hash_entry
*h
)
6702 struct elf_aarch64_link_hash_table
*htab
;
6705 /* If this is a function, put it in the procedure linkage table. We
6706 will fill in the contents of the procedure linkage table later,
6707 when we know the address of the .got section. */
6708 if (h
->type
== STT_FUNC
|| h
->type
== STT_GNU_IFUNC
|| h
->needs_plt
)
6710 if (h
->plt
.refcount
<= 0
6711 || (h
->type
!= STT_GNU_IFUNC
6712 && (SYMBOL_CALLS_LOCAL (info
, h
)
6713 || (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
6714 && h
->root
.type
== bfd_link_hash_undefweak
))))
6716 /* This case can occur if we saw a CALL26 reloc in
6717 an input file, but the symbol wasn't referred to
6718 by a dynamic object or all references were
6719 garbage collected. In which case we can end up
6721 h
->plt
.offset
= (bfd_vma
) - 1;
6728 /* Otherwise, reset to -1. */
6729 h
->plt
.offset
= (bfd_vma
) - 1;
6732 /* If this is a weak symbol, and there is a real definition, the
6733 processor independent code will have arranged for us to see the
6734 real definition first, and we can just use the same value. */
6735 if (h
->u
.weakdef
!= NULL
)
6737 BFD_ASSERT (h
->u
.weakdef
->root
.type
== bfd_link_hash_defined
6738 || h
->u
.weakdef
->root
.type
== bfd_link_hash_defweak
);
6739 h
->root
.u
.def
.section
= h
->u
.weakdef
->root
.u
.def
.section
;
6740 h
->root
.u
.def
.value
= h
->u
.weakdef
->root
.u
.def
.value
;
6741 if (ELIMINATE_COPY_RELOCS
|| info
->nocopyreloc
)
6742 h
->non_got_ref
= h
->u
.weakdef
->non_got_ref
;
6746 /* If we are creating a shared library, we must presume that the
6747 only references to the symbol are via the global offset table.
6748 For such cases we need not do anything here; the relocations will
6749 be handled correctly by relocate_section. */
6750 if (bfd_link_pic (info
))
6753 /* If there are no references to this symbol that do not use the
6754 GOT, we don't need to generate a copy reloc. */
6755 if (!h
->non_got_ref
)
6758 /* If -z nocopyreloc was given, we won't generate them either. */
6759 if (info
->nocopyreloc
)
6765 /* We must allocate the symbol in our .dynbss section, which will
6766 become part of the .bss section of the executable. There will be
6767 an entry for this symbol in the .dynsym section. The dynamic
6768 object will contain position independent code, so all references
6769 from the dynamic object to this symbol will go through the global
6770 offset table. The dynamic linker will use the .dynsym entry to
6771 determine the address it must put in the global offset table, so
6772 both the dynamic object and the regular object will refer to the
6773 same memory location for the variable. */
6775 htab
= elf_aarch64_hash_table (info
);
6777 /* We must generate a R_AARCH64_COPY reloc to tell the dynamic linker
6778 to copy the initial value out of the dynamic object and into the
6779 runtime process image. */
6780 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0 && h
->size
!= 0)
6782 htab
->srelbss
->size
+= RELOC_SIZE (htab
);
6788 return _bfd_elf_adjust_dynamic_copy (info
, h
, s
);
6793 elfNN_aarch64_allocate_local_symbols (bfd
*abfd
, unsigned number
)
6795 struct elf_aarch64_local_symbol
*locals
;
6796 locals
= elf_aarch64_locals (abfd
);
6799 locals
= (struct elf_aarch64_local_symbol
*)
6800 bfd_zalloc (abfd
, number
* sizeof (struct elf_aarch64_local_symbol
));
6803 elf_aarch64_locals (abfd
) = locals
;
6808 /* Create the .got section to hold the global offset table. */
6811 aarch64_elf_create_got_section (bfd
*abfd
, struct bfd_link_info
*info
)
6813 const struct elf_backend_data
*bed
= get_elf_backend_data (abfd
);
6816 struct elf_link_hash_entry
*h
;
6817 struct elf_link_hash_table
*htab
= elf_hash_table (info
);
6819 /* This function may be called more than once. */
6820 s
= bfd_get_linker_section (abfd
, ".got");
6824 flags
= bed
->dynamic_sec_flags
;
6826 s
= bfd_make_section_anyway_with_flags (abfd
,
6827 (bed
->rela_plts_and_copies_p
6828 ? ".rela.got" : ".rel.got"),
6829 (bed
->dynamic_sec_flags
6832 || ! bfd_set_section_alignment (abfd
, s
, bed
->s
->log_file_align
))
6836 s
= bfd_make_section_anyway_with_flags (abfd
, ".got", flags
);
6838 || !bfd_set_section_alignment (abfd
, s
, bed
->s
->log_file_align
))
6841 htab
->sgot
->size
+= GOT_ENTRY_SIZE
;
6843 if (bed
->want_got_sym
)
6845 /* Define the symbol _GLOBAL_OFFSET_TABLE_ at the start of the .got
6846 (or .got.plt) section. We don't do this in the linker script
6847 because we don't want to define the symbol if we are not creating
6848 a global offset table. */
6849 h
= _bfd_elf_define_linkage_sym (abfd
, info
, s
,
6850 "_GLOBAL_OFFSET_TABLE_");
6851 elf_hash_table (info
)->hgot
= h
;
6856 if (bed
->want_got_plt
)
6858 s
= bfd_make_section_anyway_with_flags (abfd
, ".got.plt", flags
);
6860 || !bfd_set_section_alignment (abfd
, s
,
6861 bed
->s
->log_file_align
))
6866 /* The first bit of the global offset table is the header. */
6867 s
->size
+= bed
->got_header_size
;
6872 /* Look through the relocs for a section during the first phase. */
6875 elfNN_aarch64_check_relocs (bfd
*abfd
, struct bfd_link_info
*info
,
6876 asection
*sec
, const Elf_Internal_Rela
*relocs
)
6878 Elf_Internal_Shdr
*symtab_hdr
;
6879 struct elf_link_hash_entry
**sym_hashes
;
6880 const Elf_Internal_Rela
*rel
;
6881 const Elf_Internal_Rela
*rel_end
;
6884 struct elf_aarch64_link_hash_table
*htab
;
6886 if (bfd_link_relocatable (info
))
6889 BFD_ASSERT (is_aarch64_elf (abfd
));
6891 htab
= elf_aarch64_hash_table (info
);
6894 symtab_hdr
= &elf_symtab_hdr (abfd
);
6895 sym_hashes
= elf_sym_hashes (abfd
);
6897 rel_end
= relocs
+ sec
->reloc_count
;
6898 for (rel
= relocs
; rel
< rel_end
; rel
++)
6900 struct elf_link_hash_entry
*h
;
6901 unsigned long r_symndx
;
6902 unsigned int r_type
;
6903 bfd_reloc_code_real_type bfd_r_type
;
6904 Elf_Internal_Sym
*isym
;
6906 r_symndx
= ELFNN_R_SYM (rel
->r_info
);
6907 r_type
= ELFNN_R_TYPE (rel
->r_info
);
6909 if (r_symndx
>= NUM_SHDR_ENTRIES (symtab_hdr
))
6911 (*_bfd_error_handler
) (_("%B: bad symbol index: %d"), abfd
,
6916 if (r_symndx
< symtab_hdr
->sh_info
)
6918 /* A local symbol. */
6919 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
6924 /* Check relocation against local STT_GNU_IFUNC symbol. */
6925 if (ELF_ST_TYPE (isym
->st_info
) == STT_GNU_IFUNC
)
6927 h
= elfNN_aarch64_get_local_sym_hash (htab
, abfd
, rel
,
6932 /* Fake a STT_GNU_IFUNC symbol. */
6933 h
->type
= STT_GNU_IFUNC
;
6936 h
->forced_local
= 1;
6937 h
->root
.type
= bfd_link_hash_defined
;
6944 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
6945 while (h
->root
.type
== bfd_link_hash_indirect
6946 || h
->root
.type
== bfd_link_hash_warning
)
6947 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
6949 /* PR15323, ref flags aren't set for references in the same
6951 h
->root
.non_ir_ref
= 1;
6954 /* Could be done earlier, if h were already available. */
6955 bfd_r_type
= aarch64_tls_transition (abfd
, info
, r_type
, h
, r_symndx
);
6959 /* Create the ifunc sections for static executables. If we
6960 never see an indirect function symbol nor we are building
6961 a static executable, those sections will be empty and
6962 won't appear in output. */
6968 case BFD_RELOC_AARCH64_ADD_LO12
:
6969 case BFD_RELOC_AARCH64_ADR_GOT_PAGE
:
6970 case BFD_RELOC_AARCH64_ADR_HI21_PCREL
:
6971 case BFD_RELOC_AARCH64_CALL26
:
6972 case BFD_RELOC_AARCH64_GOT_LD_PREL19
:
6973 case BFD_RELOC_AARCH64_JUMP26
:
6974 case BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14
:
6975 case BFD_RELOC_AARCH64_LD32_GOT_LO12_NC
:
6976 case BFD_RELOC_AARCH64_LD64_GOTOFF_LO15
:
6977 case BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15
:
6978 case BFD_RELOC_AARCH64_LD64_GOT_LO12_NC
:
6979 case BFD_RELOC_AARCH64_MOVW_GOTOFF_G0_NC
:
6980 case BFD_RELOC_AARCH64_MOVW_GOTOFF_G1
:
6981 case BFD_RELOC_AARCH64_NN
:
6982 if (htab
->root
.dynobj
== NULL
)
6983 htab
->root
.dynobj
= abfd
;
6984 if (!_bfd_elf_create_ifunc_sections (htab
->root
.dynobj
, info
))
6989 /* It is referenced by a non-shared object. */
6991 h
->root
.non_ir_ref
= 1;
6996 case BFD_RELOC_AARCH64_NN
:
6998 /* We don't need to handle relocs into sections not going into
6999 the "real" output. */
7000 if ((sec
->flags
& SEC_ALLOC
) == 0)
7005 if (!bfd_link_pic (info
))
7008 h
->plt
.refcount
+= 1;
7009 h
->pointer_equality_needed
= 1;
7012 /* No need to do anything if we're not creating a shared
7014 if (! bfd_link_pic (info
))
7018 struct elf_dyn_relocs
*p
;
7019 struct elf_dyn_relocs
**head
;
7021 /* We must copy these reloc types into the output file.
7022 Create a reloc section in dynobj and make room for
7026 if (htab
->root
.dynobj
== NULL
)
7027 htab
->root
.dynobj
= abfd
;
7029 sreloc
= _bfd_elf_make_dynamic_reloc_section
7030 (sec
, htab
->root
.dynobj
, LOG_FILE_ALIGN
, abfd
, /*rela? */ TRUE
);
7036 /* If this is a global symbol, we count the number of
7037 relocations we need for this symbol. */
7040 struct elf_aarch64_link_hash_entry
*eh
;
7041 eh
= (struct elf_aarch64_link_hash_entry
*) h
;
7042 head
= &eh
->dyn_relocs
;
7046 /* Track dynamic relocs needed for local syms too.
7047 We really need local syms available to do this
7053 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
7058 s
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
7062 /* Beware of type punned pointers vs strict aliasing
7064 vpp
= &(elf_section_data (s
)->local_dynrel
);
7065 head
= (struct elf_dyn_relocs
**) vpp
;
7069 if (p
== NULL
|| p
->sec
!= sec
)
7071 bfd_size_type amt
= sizeof *p
;
7072 p
= ((struct elf_dyn_relocs
*)
7073 bfd_zalloc (htab
->root
.dynobj
, amt
));
7086 /* RR: We probably want to keep a consistency check that
7087 there are no dangling GOT_PAGE relocs. */
7088 case BFD_RELOC_AARCH64_ADR_GOT_PAGE
:
7089 case BFD_RELOC_AARCH64_GOT_LD_PREL19
:
7090 case BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14
:
7091 case BFD_RELOC_AARCH64_LD32_GOT_LO12_NC
:
7092 case BFD_RELOC_AARCH64_LD64_GOTOFF_LO15
:
7093 case BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15
:
7094 case BFD_RELOC_AARCH64_LD64_GOT_LO12_NC
:
7095 case BFD_RELOC_AARCH64_MOVW_GOTOFF_G0_NC
:
7096 case BFD_RELOC_AARCH64_MOVW_GOTOFF_G1
:
7097 case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12_NC
:
7098 case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21
:
7099 case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21
:
7100 case BFD_RELOC_AARCH64_TLSDESC_LD32_LO12_NC
:
7101 case BFD_RELOC_AARCH64_TLSDESC_LD64_LO12_NC
:
7102 case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19
:
7103 case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC
:
7104 case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21
:
7105 case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21
:
7106 case BFD_RELOC_AARCH64_TLSGD_MOVW_G0_NC
:
7107 case BFD_RELOC_AARCH64_TLSGD_MOVW_G1
:
7108 case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21
:
7109 case BFD_RELOC_AARCH64_TLSIE_LD32_GOTTPREL_LO12_NC
:
7110 case BFD_RELOC_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC
:
7111 case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19
:
7112 case BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G0_NC
:
7113 case BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G1
:
7114 case BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC
:
7115 case BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21
:
7116 case BFD_RELOC_AARCH64_TLSLD_ADR_PREL21
:
7117 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1
:
7118 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1_NC
:
7119 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G2
:
7122 unsigned old_got_type
;
7124 got_type
= aarch64_reloc_got_type (bfd_r_type
);
7128 h
->got
.refcount
+= 1;
7129 old_got_type
= elf_aarch64_hash_entry (h
)->got_type
;
7133 struct elf_aarch64_local_symbol
*locals
;
7135 if (!elfNN_aarch64_allocate_local_symbols
7136 (abfd
, symtab_hdr
->sh_info
))
7139 locals
= elf_aarch64_locals (abfd
);
7140 BFD_ASSERT (r_symndx
< symtab_hdr
->sh_info
);
7141 locals
[r_symndx
].got_refcount
+= 1;
7142 old_got_type
= locals
[r_symndx
].got_type
;
7145 /* If a variable is accessed with both general dynamic TLS
7146 methods, two slots may be created. */
7147 if (GOT_TLS_GD_ANY_P (old_got_type
) && GOT_TLS_GD_ANY_P (got_type
))
7148 got_type
|= old_got_type
;
7150 /* We will already have issued an error message if there
7151 is a TLS/non-TLS mismatch, based on the symbol type.
7152 So just combine any TLS types needed. */
7153 if (old_got_type
!= GOT_UNKNOWN
&& old_got_type
!= GOT_NORMAL
7154 && got_type
!= GOT_NORMAL
)
7155 got_type
|= old_got_type
;
7157 /* If the symbol is accessed by both IE and GD methods, we
7158 are able to relax. Turn off the GD flag, without
7159 messing up with any other kind of TLS types that may be
7161 if ((got_type
& GOT_TLS_IE
) && GOT_TLS_GD_ANY_P (got_type
))
7162 got_type
&= ~ (GOT_TLSDESC_GD
| GOT_TLS_GD
);
7164 if (old_got_type
!= got_type
)
7167 elf_aarch64_hash_entry (h
)->got_type
= got_type
;
7170 struct elf_aarch64_local_symbol
*locals
;
7171 locals
= elf_aarch64_locals (abfd
);
7172 BFD_ASSERT (r_symndx
< symtab_hdr
->sh_info
);
7173 locals
[r_symndx
].got_type
= got_type
;
7177 if (htab
->root
.dynobj
== NULL
)
7178 htab
->root
.dynobj
= abfd
;
7179 if (! aarch64_elf_create_got_section (htab
->root
.dynobj
, info
))
7184 case BFD_RELOC_AARCH64_MOVW_G0_NC
:
7185 case BFD_RELOC_AARCH64_MOVW_G1_NC
:
7186 case BFD_RELOC_AARCH64_MOVW_G2_NC
:
7187 case BFD_RELOC_AARCH64_MOVW_G3
:
7188 if (bfd_link_pic (info
))
7190 int howto_index
= bfd_r_type
- BFD_RELOC_AARCH64_RELOC_START
;
7191 (*_bfd_error_handler
)
7192 (_("%B: relocation %s against `%s' can not be used when making "
7193 "a shared object; recompile with -fPIC"),
7194 abfd
, elfNN_aarch64_howto_table
[howto_index
].name
,
7195 (h
) ? h
->root
.root
.string
: "a local symbol");
7196 bfd_set_error (bfd_error_bad_value
);
7200 case BFD_RELOC_AARCH64_ADR_HI21_NC_PCREL
:
7201 case BFD_RELOC_AARCH64_ADR_HI21_PCREL
:
7202 case BFD_RELOC_AARCH64_ADR_LO21_PCREL
:
7203 if (h
!= NULL
&& bfd_link_executable (info
))
7205 /* If this reloc is in a read-only section, we might
7206 need a copy reloc. We can't check reliably at this
7207 stage whether the section is read-only, as input
7208 sections have not yet been mapped to output sections.
7209 Tentatively set the flag for now, and correct in
7210 adjust_dynamic_symbol. */
7212 h
->plt
.refcount
+= 1;
7213 h
->pointer_equality_needed
= 1;
7215 /* FIXME:: RR need to handle these in shared libraries
7216 and essentially bomb out as these being non-PIC
7217 relocations in shared libraries. */
7220 case BFD_RELOC_AARCH64_CALL26
:
7221 case BFD_RELOC_AARCH64_JUMP26
:
7222 /* If this is a local symbol then we resolve it
7223 directly without creating a PLT entry. */
7228 if (h
->plt
.refcount
<= 0)
7229 h
->plt
.refcount
= 1;
7231 h
->plt
.refcount
+= 1;
7242 /* Treat mapping symbols as special target symbols. */
7245 elfNN_aarch64_is_target_special_symbol (bfd
*abfd ATTRIBUTE_UNUSED
,
7248 return bfd_is_aarch64_special_symbol_name (sym
->name
,
7249 BFD_AARCH64_SPECIAL_SYM_TYPE_ANY
);
7252 /* This is a copy of elf_find_function () from elf.c except that
7253 AArch64 mapping symbols are ignored when looking for function names. */
7256 aarch64_elf_find_function (bfd
*abfd ATTRIBUTE_UNUSED
,
7260 const char **filename_ptr
,
7261 const char **functionname_ptr
)
7263 const char *filename
= NULL
;
7264 asymbol
*func
= NULL
;
7265 bfd_vma low_func
= 0;
7268 for (p
= symbols
; *p
!= NULL
; p
++)
7272 q
= (elf_symbol_type
*) * p
;
7274 switch (ELF_ST_TYPE (q
->internal_elf_sym
.st_info
))
7279 filename
= bfd_asymbol_name (&q
->symbol
);
7283 /* Skip mapping symbols. */
7284 if ((q
->symbol
.flags
& BSF_LOCAL
)
7285 && (bfd_is_aarch64_special_symbol_name
7286 (q
->symbol
.name
, BFD_AARCH64_SPECIAL_SYM_TYPE_ANY
)))
7289 if (bfd_get_section (&q
->symbol
) == section
7290 && q
->symbol
.value
>= low_func
&& q
->symbol
.value
<= offset
)
7292 func
= (asymbol
*) q
;
7293 low_func
= q
->symbol
.value
;
7303 *filename_ptr
= filename
;
7304 if (functionname_ptr
)
7305 *functionname_ptr
= bfd_asymbol_name (func
);
7311 /* Find the nearest line to a particular section and offset, for error
7312 reporting. This code is a duplicate of the code in elf.c, except
7313 that it uses aarch64_elf_find_function. */
7316 elfNN_aarch64_find_nearest_line (bfd
*abfd
,
7320 const char **filename_ptr
,
7321 const char **functionname_ptr
,
7322 unsigned int *line_ptr
,
7323 unsigned int *discriminator_ptr
)
7325 bfd_boolean found
= FALSE
;
7327 if (_bfd_dwarf2_find_nearest_line (abfd
, symbols
, NULL
, section
, offset
,
7328 filename_ptr
, functionname_ptr
,
7329 line_ptr
, discriminator_ptr
,
7330 dwarf_debug_sections
, 0,
7331 &elf_tdata (abfd
)->dwarf2_find_line_info
))
7333 if (!*functionname_ptr
)
7334 aarch64_elf_find_function (abfd
, symbols
, section
, offset
,
7335 *filename_ptr
? NULL
: filename_ptr
,
7341 /* Skip _bfd_dwarf1_find_nearest_line since no known AArch64
7342 toolchain uses DWARF1. */
7344 if (!_bfd_stab_section_find_nearest_line (abfd
, symbols
, section
, offset
,
7345 &found
, filename_ptr
,
7346 functionname_ptr
, line_ptr
,
7347 &elf_tdata (abfd
)->line_info
))
7350 if (found
&& (*functionname_ptr
|| *line_ptr
))
7353 if (symbols
== NULL
)
7356 if (!aarch64_elf_find_function (abfd
, symbols
, section
, offset
,
7357 filename_ptr
, functionname_ptr
))
7365 elfNN_aarch64_find_inliner_info (bfd
*abfd
,
7366 const char **filename_ptr
,
7367 const char **functionname_ptr
,
7368 unsigned int *line_ptr
)
7371 found
= _bfd_dwarf2_find_inliner_info
7372 (abfd
, filename_ptr
,
7373 functionname_ptr
, line_ptr
, &elf_tdata (abfd
)->dwarf2_find_line_info
);
7379 elfNN_aarch64_post_process_headers (bfd
*abfd
,
7380 struct bfd_link_info
*link_info
)
7382 Elf_Internal_Ehdr
*i_ehdrp
; /* ELF file header, internal form. */
7384 i_ehdrp
= elf_elfheader (abfd
);
7385 i_ehdrp
->e_ident
[EI_ABIVERSION
] = AARCH64_ELF_ABI_VERSION
;
7387 _bfd_elf_post_process_headers (abfd
, link_info
);
7390 static enum elf_reloc_type_class
7391 elfNN_aarch64_reloc_type_class (const struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
7392 const asection
*rel_sec ATTRIBUTE_UNUSED
,
7393 const Elf_Internal_Rela
*rela
)
7395 switch ((int) ELFNN_R_TYPE (rela
->r_info
))
7397 case AARCH64_R (RELATIVE
):
7398 return reloc_class_relative
;
7399 case AARCH64_R (JUMP_SLOT
):
7400 return reloc_class_plt
;
7401 case AARCH64_R (COPY
):
7402 return reloc_class_copy
;
7404 return reloc_class_normal
;
7408 /* Handle an AArch64 specific section when reading an object file. This is
7409 called when bfd_section_from_shdr finds a section with an unknown
7413 elfNN_aarch64_section_from_shdr (bfd
*abfd
,
7414 Elf_Internal_Shdr
*hdr
,
7415 const char *name
, int shindex
)
7417 /* There ought to be a place to keep ELF backend specific flags, but
7418 at the moment there isn't one. We just keep track of the
7419 sections by their name, instead. Fortunately, the ABI gives
7420 names for all the AArch64 specific sections, so we will probably get
7422 switch (hdr
->sh_type
)
7424 case SHT_AARCH64_ATTRIBUTES
:
7431 if (!_bfd_elf_make_section_from_shdr (abfd
, hdr
, name
, shindex
))
7437 /* A structure used to record a list of sections, independently
7438 of the next and prev fields in the asection structure. */
7439 typedef struct section_list
7442 struct section_list
*next
;
7443 struct section_list
*prev
;
7447 /* Unfortunately we need to keep a list of sections for which
7448 an _aarch64_elf_section_data structure has been allocated. This
7449 is because it is possible for functions like elfNN_aarch64_write_section
7450 to be called on a section which has had an elf_data_structure
7451 allocated for it (and so the used_by_bfd field is valid) but
7452 for which the AArch64 extended version of this structure - the
7453 _aarch64_elf_section_data structure - has not been allocated. */
7454 static section_list
*sections_with_aarch64_elf_section_data
= NULL
;
7457 record_section_with_aarch64_elf_section_data (asection
*sec
)
7459 struct section_list
*entry
;
7461 entry
= bfd_malloc (sizeof (*entry
));
7465 entry
->next
= sections_with_aarch64_elf_section_data
;
7467 if (entry
->next
!= NULL
)
7468 entry
->next
->prev
= entry
;
7469 sections_with_aarch64_elf_section_data
= entry
;
7472 static struct section_list
*
7473 find_aarch64_elf_section_entry (asection
*sec
)
7475 struct section_list
*entry
;
7476 static struct section_list
*last_entry
= NULL
;
7478 /* This is a short cut for the typical case where the sections are added
7479 to the sections_with_aarch64_elf_section_data list in forward order and
7480 then looked up here in backwards order. This makes a real difference
7481 to the ld-srec/sec64k.exp linker test. */
7482 entry
= sections_with_aarch64_elf_section_data
;
7483 if (last_entry
!= NULL
)
7485 if (last_entry
->sec
== sec
)
7487 else if (last_entry
->next
!= NULL
&& last_entry
->next
->sec
== sec
)
7488 entry
= last_entry
->next
;
7491 for (; entry
; entry
= entry
->next
)
7492 if (entry
->sec
== sec
)
7496 /* Record the entry prior to this one - it is the entry we are
7497 most likely to want to locate next time. Also this way if we
7498 have been called from
7499 unrecord_section_with_aarch64_elf_section_data () we will not
7500 be caching a pointer that is about to be freed. */
7501 last_entry
= entry
->prev
;
7507 unrecord_section_with_aarch64_elf_section_data (asection
*sec
)
7509 struct section_list
*entry
;
7511 entry
= find_aarch64_elf_section_entry (sec
);
7515 if (entry
->prev
!= NULL
)
7516 entry
->prev
->next
= entry
->next
;
7517 if (entry
->next
!= NULL
)
7518 entry
->next
->prev
= entry
->prev
;
7519 if (entry
== sections_with_aarch64_elf_section_data
)
7520 sections_with_aarch64_elf_section_data
= entry
->next
;
7529 struct bfd_link_info
*info
;
7532 int (*func
) (void *, const char *, Elf_Internal_Sym
*,
7533 asection
*, struct elf_link_hash_entry
*);
7534 } output_arch_syminfo
;
7536 enum map_symbol_type
7543 /* Output a single mapping symbol. */
7546 elfNN_aarch64_output_map_sym (output_arch_syminfo
*osi
,
7547 enum map_symbol_type type
, bfd_vma offset
)
7549 static const char *names
[2] = { "$x", "$d" };
7550 Elf_Internal_Sym sym
;
7552 sym
.st_value
= (osi
->sec
->output_section
->vma
7553 + osi
->sec
->output_offset
+ offset
);
7556 sym
.st_info
= ELF_ST_INFO (STB_LOCAL
, STT_NOTYPE
);
7557 sym
.st_shndx
= osi
->sec_shndx
;
7558 return osi
->func (osi
->finfo
, names
[type
], &sym
, osi
->sec
, NULL
) == 1;
7561 /* Output a single local symbol for a generated stub. */
7564 elfNN_aarch64_output_stub_sym (output_arch_syminfo
*osi
, const char *name
,
7565 bfd_vma offset
, bfd_vma size
)
7567 Elf_Internal_Sym sym
;
7569 sym
.st_value
= (osi
->sec
->output_section
->vma
7570 + osi
->sec
->output_offset
+ offset
);
7573 sym
.st_info
= ELF_ST_INFO (STB_LOCAL
, STT_FUNC
);
7574 sym
.st_shndx
= osi
->sec_shndx
;
7575 return osi
->func (osi
->finfo
, name
, &sym
, osi
->sec
, NULL
) == 1;
7579 aarch64_map_one_stub (struct bfd_hash_entry
*gen_entry
, void *in_arg
)
7581 struct elf_aarch64_stub_hash_entry
*stub_entry
;
7585 output_arch_syminfo
*osi
;
7587 /* Massage our args to the form they really have. */
7588 stub_entry
= (struct elf_aarch64_stub_hash_entry
*) gen_entry
;
7589 osi
= (output_arch_syminfo
*) in_arg
;
7591 stub_sec
= stub_entry
->stub_sec
;
7593 /* Ensure this stub is attached to the current section being
7595 if (stub_sec
!= osi
->sec
)
7598 addr
= (bfd_vma
) stub_entry
->stub_offset
;
7600 stub_name
= stub_entry
->output_name
;
7602 switch (stub_entry
->stub_type
)
7604 case aarch64_stub_adrp_branch
:
7605 if (!elfNN_aarch64_output_stub_sym (osi
, stub_name
, addr
,
7606 sizeof (aarch64_adrp_branch_stub
)))
7608 if (!elfNN_aarch64_output_map_sym (osi
, AARCH64_MAP_INSN
, addr
))
7611 case aarch64_stub_long_branch
:
7612 if (!elfNN_aarch64_output_stub_sym
7613 (osi
, stub_name
, addr
, sizeof (aarch64_long_branch_stub
)))
7615 if (!elfNN_aarch64_output_map_sym (osi
, AARCH64_MAP_INSN
, addr
))
7617 if (!elfNN_aarch64_output_map_sym (osi
, AARCH64_MAP_DATA
, addr
+ 16))
7620 case aarch64_stub_erratum_835769_veneer
:
7621 if (!elfNN_aarch64_output_stub_sym (osi
, stub_name
, addr
,
7622 sizeof (aarch64_erratum_835769_stub
)))
7624 if (!elfNN_aarch64_output_map_sym (osi
, AARCH64_MAP_INSN
, addr
))
7627 case aarch64_stub_erratum_843419_veneer
:
7628 if (!elfNN_aarch64_output_stub_sym (osi
, stub_name
, addr
,
7629 sizeof (aarch64_erratum_843419_stub
)))
7631 if (!elfNN_aarch64_output_map_sym (osi
, AARCH64_MAP_INSN
, addr
))
7642 /* Output mapping symbols for linker generated sections. */
7645 elfNN_aarch64_output_arch_local_syms (bfd
*output_bfd
,
7646 struct bfd_link_info
*info
,
7648 int (*func
) (void *, const char *,
7651 struct elf_link_hash_entry
7654 output_arch_syminfo osi
;
7655 struct elf_aarch64_link_hash_table
*htab
;
7657 htab
= elf_aarch64_hash_table (info
);
7663 /* Long calls stubs. */
7664 if (htab
->stub_bfd
&& htab
->stub_bfd
->sections
)
7668 for (stub_sec
= htab
->stub_bfd
->sections
;
7669 stub_sec
!= NULL
; stub_sec
= stub_sec
->next
)
7671 /* Ignore non-stub sections. */
7672 if (!strstr (stub_sec
->name
, STUB_SUFFIX
))
7677 osi
.sec_shndx
= _bfd_elf_section_from_bfd_section
7678 (output_bfd
, osi
.sec
->output_section
);
7680 /* The first instruction in a stub is always a branch. */
7681 if (!elfNN_aarch64_output_map_sym (&osi
, AARCH64_MAP_INSN
, 0))
7684 bfd_hash_traverse (&htab
->stub_hash_table
, aarch64_map_one_stub
,
7689 /* Finally, output mapping symbols for the PLT. */
7690 if (!htab
->root
.splt
|| htab
->root
.splt
->size
== 0)
7693 osi
.sec_shndx
= _bfd_elf_section_from_bfd_section
7694 (output_bfd
, htab
->root
.splt
->output_section
);
7695 osi
.sec
= htab
->root
.splt
;
7697 elfNN_aarch64_output_map_sym (&osi
, AARCH64_MAP_INSN
, 0);
7703 /* Allocate target specific section data. */
7706 elfNN_aarch64_new_section_hook (bfd
*abfd
, asection
*sec
)
7708 if (!sec
->used_by_bfd
)
7710 _aarch64_elf_section_data
*sdata
;
7711 bfd_size_type amt
= sizeof (*sdata
);
7713 sdata
= bfd_zalloc (abfd
, amt
);
7716 sec
->used_by_bfd
= sdata
;
7719 record_section_with_aarch64_elf_section_data (sec
);
7721 return _bfd_elf_new_section_hook (abfd
, sec
);
7726 unrecord_section_via_map_over_sections (bfd
*abfd ATTRIBUTE_UNUSED
,
7728 void *ignore ATTRIBUTE_UNUSED
)
7730 unrecord_section_with_aarch64_elf_section_data (sec
);
7734 elfNN_aarch64_close_and_cleanup (bfd
*abfd
)
7737 bfd_map_over_sections (abfd
,
7738 unrecord_section_via_map_over_sections
, NULL
);
7740 return _bfd_elf_close_and_cleanup (abfd
);
7744 elfNN_aarch64_bfd_free_cached_info (bfd
*abfd
)
7747 bfd_map_over_sections (abfd
,
7748 unrecord_section_via_map_over_sections
, NULL
);
7750 return _bfd_free_cached_info (abfd
);
7753 /* Create dynamic sections. This is different from the ARM backend in that
7754 the got, plt, gotplt and their relocation sections are all created in the
7755 standard part of the bfd elf backend. */
7758 elfNN_aarch64_create_dynamic_sections (bfd
*dynobj
,
7759 struct bfd_link_info
*info
)
7761 struct elf_aarch64_link_hash_table
*htab
;
7763 /* We need to create .got section. */
7764 if (!aarch64_elf_create_got_section (dynobj
, info
))
7767 if (!_bfd_elf_create_dynamic_sections (dynobj
, info
))
7770 htab
= elf_aarch64_hash_table (info
);
7771 htab
->sdynbss
= bfd_get_linker_section (dynobj
, ".dynbss");
7772 if (!bfd_link_pic (info
))
7773 htab
->srelbss
= bfd_get_linker_section (dynobj
, ".rela.bss");
7775 if (!htab
->sdynbss
|| (!bfd_link_pic (info
) && !htab
->srelbss
))
7782 /* Allocate space in .plt, .got and associated reloc sections for
7786 elfNN_aarch64_allocate_dynrelocs (struct elf_link_hash_entry
*h
, void *inf
)
7788 struct bfd_link_info
*info
;
7789 struct elf_aarch64_link_hash_table
*htab
;
7790 struct elf_aarch64_link_hash_entry
*eh
;
7791 struct elf_dyn_relocs
*p
;
7793 /* An example of a bfd_link_hash_indirect symbol is versioned
7794 symbol. For example: __gxx_personality_v0(bfd_link_hash_indirect)
7795 -> __gxx_personality_v0(bfd_link_hash_defined)
7797 There is no need to process bfd_link_hash_indirect symbols here
7798 because we will also be presented with the concrete instance of
7799 the symbol and elfNN_aarch64_copy_indirect_symbol () will have been
7800 called to copy all relevant data from the generic to the concrete
7803 if (h
->root
.type
== bfd_link_hash_indirect
)
7806 if (h
->root
.type
== bfd_link_hash_warning
)
7807 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
7809 info
= (struct bfd_link_info
*) inf
;
7810 htab
= elf_aarch64_hash_table (info
);
7812 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle it
7813 here if it is defined and referenced in a non-shared object. */
7814 if (h
->type
== STT_GNU_IFUNC
7817 else if (htab
->root
.dynamic_sections_created
&& h
->plt
.refcount
> 0)
7819 /* Make sure this symbol is output as a dynamic symbol.
7820 Undefined weak syms won't yet be marked as dynamic. */
7821 if (h
->dynindx
== -1 && !h
->forced_local
)
7823 if (!bfd_elf_link_record_dynamic_symbol (info
, h
))
7827 if (bfd_link_pic (info
) || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h
))
7829 asection
*s
= htab
->root
.splt
;
7831 /* If this is the first .plt entry, make room for the special
7834 s
->size
+= htab
->plt_header_size
;
7836 h
->plt
.offset
= s
->size
;
7838 /* If this symbol is not defined in a regular file, and we are
7839 not generating a shared library, then set the symbol to this
7840 location in the .plt. This is required to make function
7841 pointers compare as equal between the normal executable and
7842 the shared library. */
7843 if (!bfd_link_pic (info
) && !h
->def_regular
)
7845 h
->root
.u
.def
.section
= s
;
7846 h
->root
.u
.def
.value
= h
->plt
.offset
;
7849 /* Make room for this entry. For now we only create the
7850 small model PLT entries. We later need to find a way
7851 of relaxing into these from the large model PLT entries. */
7852 s
->size
+= PLT_SMALL_ENTRY_SIZE
;
7854 /* We also need to make an entry in the .got.plt section, which
7855 will be placed in the .got section by the linker script. */
7856 htab
->root
.sgotplt
->size
+= GOT_ENTRY_SIZE
;
7858 /* We also need to make an entry in the .rela.plt section. */
7859 htab
->root
.srelplt
->size
+= RELOC_SIZE (htab
);
7861 /* We need to ensure that all GOT entries that serve the PLT
7862 are consecutive with the special GOT slots [0] [1] and
7863 [2]. Any addtional relocations, such as
7864 R_AARCH64_TLSDESC, must be placed after the PLT related
7865 entries. We abuse the reloc_count such that during
7866 sizing we adjust reloc_count to indicate the number of
7867 PLT related reserved entries. In subsequent phases when
7868 filling in the contents of the reloc entries, PLT related
7869 entries are placed by computing their PLT index (0
7870 .. reloc_count). While other none PLT relocs are placed
7871 at the slot indicated by reloc_count and reloc_count is
7874 htab
->root
.srelplt
->reloc_count
++;
7878 h
->plt
.offset
= (bfd_vma
) - 1;
7884 h
->plt
.offset
= (bfd_vma
) - 1;
7888 eh
= (struct elf_aarch64_link_hash_entry
*) h
;
7889 eh
->tlsdesc_got_jump_table_offset
= (bfd_vma
) - 1;
7891 if (h
->got
.refcount
> 0)
7894 unsigned got_type
= elf_aarch64_hash_entry (h
)->got_type
;
7896 h
->got
.offset
= (bfd_vma
) - 1;
7898 dyn
= htab
->root
.dynamic_sections_created
;
7900 /* Make sure this symbol is output as a dynamic symbol.
7901 Undefined weak syms won't yet be marked as dynamic. */
7902 if (dyn
&& h
->dynindx
== -1 && !h
->forced_local
)
7904 if (!bfd_elf_link_record_dynamic_symbol (info
, h
))
7908 if (got_type
== GOT_UNKNOWN
)
7911 else if (got_type
== GOT_NORMAL
)
7913 h
->got
.offset
= htab
->root
.sgot
->size
;
7914 htab
->root
.sgot
->size
+= GOT_ENTRY_SIZE
;
7915 if ((ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
7916 || h
->root
.type
!= bfd_link_hash_undefweak
)
7917 && (bfd_link_pic (info
)
7918 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, 0, h
)))
7920 htab
->root
.srelgot
->size
+= RELOC_SIZE (htab
);
7926 if (got_type
& GOT_TLSDESC_GD
)
7928 eh
->tlsdesc_got_jump_table_offset
=
7929 (htab
->root
.sgotplt
->size
7930 - aarch64_compute_jump_table_size (htab
));
7931 htab
->root
.sgotplt
->size
+= GOT_ENTRY_SIZE
* 2;
7932 h
->got
.offset
= (bfd_vma
) - 2;
7935 if (got_type
& GOT_TLS_GD
)
7937 h
->got
.offset
= htab
->root
.sgot
->size
;
7938 htab
->root
.sgot
->size
+= GOT_ENTRY_SIZE
* 2;
7941 if (got_type
& GOT_TLS_IE
)
7943 h
->got
.offset
= htab
->root
.sgot
->size
;
7944 htab
->root
.sgot
->size
+= GOT_ENTRY_SIZE
;
7947 indx
= h
&& h
->dynindx
!= -1 ? h
->dynindx
: 0;
7948 if ((ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
7949 || h
->root
.type
!= bfd_link_hash_undefweak
)
7950 && (bfd_link_pic (info
)
7952 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, 0, h
)))
7954 if (got_type
& GOT_TLSDESC_GD
)
7956 htab
->root
.srelplt
->size
+= RELOC_SIZE (htab
);
7957 /* Note reloc_count not incremented here! We have
7958 already adjusted reloc_count for this relocation
7961 /* TLSDESC PLT is now needed, but not yet determined. */
7962 htab
->tlsdesc_plt
= (bfd_vma
) - 1;
7965 if (got_type
& GOT_TLS_GD
)
7966 htab
->root
.srelgot
->size
+= RELOC_SIZE (htab
) * 2;
7968 if (got_type
& GOT_TLS_IE
)
7969 htab
->root
.srelgot
->size
+= RELOC_SIZE (htab
);
7975 h
->got
.offset
= (bfd_vma
) - 1;
7978 if (eh
->dyn_relocs
== NULL
)
7981 /* In the shared -Bsymbolic case, discard space allocated for
7982 dynamic pc-relative relocs against symbols which turn out to be
7983 defined in regular objects. For the normal shared case, discard
7984 space for pc-relative relocs that have become local due to symbol
7985 visibility changes. */
7987 if (bfd_link_pic (info
))
7989 /* Relocs that use pc_count are those that appear on a call
7990 insn, or certain REL relocs that can generated via assembly.
7991 We want calls to protected symbols to resolve directly to the
7992 function rather than going via the plt. If people want
7993 function pointer comparisons to work as expected then they
7994 should avoid writing weird assembly. */
7995 if (SYMBOL_CALLS_LOCAL (info
, h
))
7997 struct elf_dyn_relocs
**pp
;
7999 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
;)
8001 p
->count
-= p
->pc_count
;
8010 /* Also discard relocs on undefined weak syms with non-default
8012 if (eh
->dyn_relocs
!= NULL
&& h
->root
.type
== bfd_link_hash_undefweak
)
8014 if (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
)
8015 eh
->dyn_relocs
= NULL
;
8017 /* Make sure undefined weak symbols are output as a dynamic
8019 else if (h
->dynindx
== -1
8021 && !bfd_elf_link_record_dynamic_symbol (info
, h
))
8026 else if (ELIMINATE_COPY_RELOCS
)
8028 /* For the non-shared case, discard space for relocs against
8029 symbols which turn out to need copy relocs or are not
8035 || (htab
->root
.dynamic_sections_created
8036 && (h
->root
.type
== bfd_link_hash_undefweak
8037 || h
->root
.type
== bfd_link_hash_undefined
))))
8039 /* Make sure this symbol is output as a dynamic symbol.
8040 Undefined weak syms won't yet be marked as dynamic. */
8041 if (h
->dynindx
== -1
8043 && !bfd_elf_link_record_dynamic_symbol (info
, h
))
8046 /* If that succeeded, we know we'll be keeping all the
8048 if (h
->dynindx
!= -1)
8052 eh
->dyn_relocs
= NULL
;
8057 /* Finally, allocate space. */
8058 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
8062 sreloc
= elf_section_data (p
->sec
)->sreloc
;
8064 BFD_ASSERT (sreloc
!= NULL
);
8066 sreloc
->size
+= p
->count
* RELOC_SIZE (htab
);
8072 /* Allocate space in .plt, .got and associated reloc sections for
8073 ifunc dynamic relocs. */
8076 elfNN_aarch64_allocate_ifunc_dynrelocs (struct elf_link_hash_entry
*h
,
8079 struct bfd_link_info
*info
;
8080 struct elf_aarch64_link_hash_table
*htab
;
8081 struct elf_aarch64_link_hash_entry
*eh
;
8083 /* An example of a bfd_link_hash_indirect symbol is versioned
8084 symbol. For example: __gxx_personality_v0(bfd_link_hash_indirect)
8085 -> __gxx_personality_v0(bfd_link_hash_defined)
8087 There is no need to process bfd_link_hash_indirect symbols here
8088 because we will also be presented with the concrete instance of
8089 the symbol and elfNN_aarch64_copy_indirect_symbol () will have been
8090 called to copy all relevant data from the generic to the concrete
8093 if (h
->root
.type
== bfd_link_hash_indirect
)
8096 if (h
->root
.type
== bfd_link_hash_warning
)
8097 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
8099 info
= (struct bfd_link_info
*) inf
;
8100 htab
= elf_aarch64_hash_table (info
);
8102 eh
= (struct elf_aarch64_link_hash_entry
*) h
;
8104 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle it
8105 here if it is defined and referenced in a non-shared object. */
8106 if (h
->type
== STT_GNU_IFUNC
8108 return _bfd_elf_allocate_ifunc_dyn_relocs (info
, h
,
8110 htab
->plt_entry_size
,
8111 htab
->plt_header_size
,
8116 /* Allocate space in .plt, .got and associated reloc sections for
8117 local dynamic relocs. */
8120 elfNN_aarch64_allocate_local_dynrelocs (void **slot
, void *inf
)
8122 struct elf_link_hash_entry
*h
8123 = (struct elf_link_hash_entry
*) *slot
;
8125 if (h
->type
!= STT_GNU_IFUNC
8129 || h
->root
.type
!= bfd_link_hash_defined
)
8132 return elfNN_aarch64_allocate_dynrelocs (h
, inf
);
8135 /* Allocate space in .plt, .got and associated reloc sections for
8136 local ifunc dynamic relocs. */
8139 elfNN_aarch64_allocate_local_ifunc_dynrelocs (void **slot
, void *inf
)
8141 struct elf_link_hash_entry
*h
8142 = (struct elf_link_hash_entry
*) *slot
;
8144 if (h
->type
!= STT_GNU_IFUNC
8148 || h
->root
.type
!= bfd_link_hash_defined
)
8151 return elfNN_aarch64_allocate_ifunc_dynrelocs (h
, inf
);
8154 /* Find any dynamic relocs that apply to read-only sections. */
8157 aarch64_readonly_dynrelocs (struct elf_link_hash_entry
* h
, void * inf
)
8159 struct elf_aarch64_link_hash_entry
* eh
;
8160 struct elf_dyn_relocs
* p
;
8162 eh
= (struct elf_aarch64_link_hash_entry
*) h
;
8163 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
8165 asection
*s
= p
->sec
;
8167 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
8169 struct bfd_link_info
*info
= (struct bfd_link_info
*) inf
;
8171 info
->flags
|= DF_TEXTREL
;
8173 /* Not an error, just cut short the traversal. */
8180 /* This is the most important function of all . Innocuosly named
8183 elfNN_aarch64_size_dynamic_sections (bfd
*output_bfd ATTRIBUTE_UNUSED
,
8184 struct bfd_link_info
*info
)
8186 struct elf_aarch64_link_hash_table
*htab
;
8192 htab
= elf_aarch64_hash_table ((info
));
8193 dynobj
= htab
->root
.dynobj
;
8195 BFD_ASSERT (dynobj
!= NULL
);
8197 if (htab
->root
.dynamic_sections_created
)
8199 if (bfd_link_executable (info
) && !info
->nointerp
)
8201 s
= bfd_get_linker_section (dynobj
, ".interp");
8204 s
->size
= sizeof ELF_DYNAMIC_INTERPRETER
;
8205 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
8209 /* Set up .got offsets for local syms, and space for local dynamic
8211 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
8213 struct elf_aarch64_local_symbol
*locals
= NULL
;
8214 Elf_Internal_Shdr
*symtab_hdr
;
8218 if (!is_aarch64_elf (ibfd
))
8221 for (s
= ibfd
->sections
; s
!= NULL
; s
= s
->next
)
8223 struct elf_dyn_relocs
*p
;
8225 for (p
= (struct elf_dyn_relocs
*)
8226 (elf_section_data (s
)->local_dynrel
); p
!= NULL
; p
= p
->next
)
8228 if (!bfd_is_abs_section (p
->sec
)
8229 && bfd_is_abs_section (p
->sec
->output_section
))
8231 /* Input section has been discarded, either because
8232 it is a copy of a linkonce section or due to
8233 linker script /DISCARD/, so we'll be discarding
8236 else if (p
->count
!= 0)
8238 srel
= elf_section_data (p
->sec
)->sreloc
;
8239 srel
->size
+= p
->count
* RELOC_SIZE (htab
);
8240 if ((p
->sec
->output_section
->flags
& SEC_READONLY
) != 0)
8241 info
->flags
|= DF_TEXTREL
;
8246 locals
= elf_aarch64_locals (ibfd
);
8250 symtab_hdr
= &elf_symtab_hdr (ibfd
);
8251 srel
= htab
->root
.srelgot
;
8252 for (i
= 0; i
< symtab_hdr
->sh_info
; i
++)
8254 locals
[i
].got_offset
= (bfd_vma
) - 1;
8255 locals
[i
].tlsdesc_got_jump_table_offset
= (bfd_vma
) - 1;
8256 if (locals
[i
].got_refcount
> 0)
8258 unsigned got_type
= locals
[i
].got_type
;
8259 if (got_type
& GOT_TLSDESC_GD
)
8261 locals
[i
].tlsdesc_got_jump_table_offset
=
8262 (htab
->root
.sgotplt
->size
8263 - aarch64_compute_jump_table_size (htab
));
8264 htab
->root
.sgotplt
->size
+= GOT_ENTRY_SIZE
* 2;
8265 locals
[i
].got_offset
= (bfd_vma
) - 2;
8268 if (got_type
& GOT_TLS_GD
)
8270 locals
[i
].got_offset
= htab
->root
.sgot
->size
;
8271 htab
->root
.sgot
->size
+= GOT_ENTRY_SIZE
* 2;
8274 if (got_type
& GOT_TLS_IE
8275 || got_type
& GOT_NORMAL
)
8277 locals
[i
].got_offset
= htab
->root
.sgot
->size
;
8278 htab
->root
.sgot
->size
+= GOT_ENTRY_SIZE
;
8281 if (got_type
== GOT_UNKNOWN
)
8285 if (bfd_link_pic (info
))
8287 if (got_type
& GOT_TLSDESC_GD
)
8289 htab
->root
.srelplt
->size
+= RELOC_SIZE (htab
);
8290 /* Note RELOC_COUNT not incremented here! */
8291 htab
->tlsdesc_plt
= (bfd_vma
) - 1;
8294 if (got_type
& GOT_TLS_GD
)
8295 htab
->root
.srelgot
->size
+= RELOC_SIZE (htab
) * 2;
8297 if (got_type
& GOT_TLS_IE
8298 || got_type
& GOT_NORMAL
)
8299 htab
->root
.srelgot
->size
+= RELOC_SIZE (htab
);
8304 locals
[i
].got_refcount
= (bfd_vma
) - 1;
8310 /* Allocate global sym .plt and .got entries, and space for global
8311 sym dynamic relocs. */
8312 elf_link_hash_traverse (&htab
->root
, elfNN_aarch64_allocate_dynrelocs
,
8315 /* Allocate global ifunc sym .plt and .got entries, and space for global
8316 ifunc sym dynamic relocs. */
8317 elf_link_hash_traverse (&htab
->root
, elfNN_aarch64_allocate_ifunc_dynrelocs
,
8320 /* Allocate .plt and .got entries, and space for local symbols. */
8321 htab_traverse (htab
->loc_hash_table
,
8322 elfNN_aarch64_allocate_local_dynrelocs
,
8325 /* Allocate .plt and .got entries, and space for local ifunc symbols. */
8326 htab_traverse (htab
->loc_hash_table
,
8327 elfNN_aarch64_allocate_local_ifunc_dynrelocs
,
8330 /* For every jump slot reserved in the sgotplt, reloc_count is
8331 incremented. However, when we reserve space for TLS descriptors,
8332 it's not incremented, so in order to compute the space reserved
8333 for them, it suffices to multiply the reloc count by the jump
8336 if (htab
->root
.srelplt
)
8337 htab
->sgotplt_jump_table_size
= aarch64_compute_jump_table_size (htab
);
8339 if (htab
->tlsdesc_plt
)
8341 if (htab
->root
.splt
->size
== 0)
8342 htab
->root
.splt
->size
+= PLT_ENTRY_SIZE
;
8344 htab
->tlsdesc_plt
= htab
->root
.splt
->size
;
8345 htab
->root
.splt
->size
+= PLT_TLSDESC_ENTRY_SIZE
;
8347 /* If we're not using lazy TLS relocations, don't generate the
8348 GOT entry required. */
8349 if (!(info
->flags
& DF_BIND_NOW
))
8351 htab
->dt_tlsdesc_got
= htab
->root
.sgot
->size
;
8352 htab
->root
.sgot
->size
+= GOT_ENTRY_SIZE
;
8356 /* Init mapping symbols information to use later to distingush between
8357 code and data while scanning for errata. */
8358 if (htab
->fix_erratum_835769
|| htab
->fix_erratum_843419
)
8359 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
8361 if (!is_aarch64_elf (ibfd
))
8363 bfd_elfNN_aarch64_init_maps (ibfd
);
8366 /* We now have determined the sizes of the various dynamic sections.
8367 Allocate memory for them. */
8369 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
8371 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
8374 if (s
== htab
->root
.splt
8375 || s
== htab
->root
.sgot
8376 || s
== htab
->root
.sgotplt
8377 || s
== htab
->root
.iplt
8378 || s
== htab
->root
.igotplt
|| s
== htab
->sdynbss
)
8380 /* Strip this section if we don't need it; see the
8383 else if (CONST_STRNEQ (bfd_get_section_name (dynobj
, s
), ".rela"))
8385 if (s
->size
!= 0 && s
!= htab
->root
.srelplt
)
8388 /* We use the reloc_count field as a counter if we need
8389 to copy relocs into the output file. */
8390 if (s
!= htab
->root
.srelplt
)
8395 /* It's not one of our sections, so don't allocate space. */
8401 /* If we don't need this section, strip it from the
8402 output file. This is mostly to handle .rela.bss and
8403 .rela.plt. We must create both sections in
8404 create_dynamic_sections, because they must be created
8405 before the linker maps input sections to output
8406 sections. The linker does that before
8407 adjust_dynamic_symbol is called, and it is that
8408 function which decides whether anything needs to go
8409 into these sections. */
8411 s
->flags
|= SEC_EXCLUDE
;
8415 if ((s
->flags
& SEC_HAS_CONTENTS
) == 0)
8418 /* Allocate memory for the section contents. We use bfd_zalloc
8419 here in case unused entries are not reclaimed before the
8420 section's contents are written out. This should not happen,
8421 but this way if it does, we get a R_AARCH64_NONE reloc instead
8423 s
->contents
= (bfd_byte
*) bfd_zalloc (dynobj
, s
->size
);
8424 if (s
->contents
== NULL
)
8428 if (htab
->root
.dynamic_sections_created
)
8430 /* Add some entries to the .dynamic section. We fill in the
8431 values later, in elfNN_aarch64_finish_dynamic_sections, but we
8432 must add the entries now so that we get the correct size for
8433 the .dynamic section. The DT_DEBUG entry is filled in by the
8434 dynamic linker and used by the debugger. */
8435 #define add_dynamic_entry(TAG, VAL) \
8436 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
8438 if (bfd_link_executable (info
))
8440 if (!add_dynamic_entry (DT_DEBUG
, 0))
8444 if (htab
->root
.splt
->size
!= 0)
8446 if (!add_dynamic_entry (DT_PLTGOT
, 0)
8447 || !add_dynamic_entry (DT_PLTRELSZ
, 0)
8448 || !add_dynamic_entry (DT_PLTREL
, DT_RELA
)
8449 || !add_dynamic_entry (DT_JMPREL
, 0))
8452 if (htab
->tlsdesc_plt
8453 && (!add_dynamic_entry (DT_TLSDESC_PLT
, 0)
8454 || !add_dynamic_entry (DT_TLSDESC_GOT
, 0)))
8460 if (!add_dynamic_entry (DT_RELA
, 0)
8461 || !add_dynamic_entry (DT_RELASZ
, 0)
8462 || !add_dynamic_entry (DT_RELAENT
, RELOC_SIZE (htab
)))
8465 /* If any dynamic relocs apply to a read-only section,
8466 then we need a DT_TEXTREL entry. */
8467 if ((info
->flags
& DF_TEXTREL
) == 0)
8468 elf_link_hash_traverse (& htab
->root
, aarch64_readonly_dynrelocs
,
8471 if ((info
->flags
& DF_TEXTREL
) != 0)
8473 if (!add_dynamic_entry (DT_TEXTREL
, 0))
8478 #undef add_dynamic_entry
8484 elf_aarch64_update_plt_entry (bfd
*output_bfd
,
8485 bfd_reloc_code_real_type r_type
,
8486 bfd_byte
*plt_entry
, bfd_vma value
)
8488 reloc_howto_type
*howto
= elfNN_aarch64_howto_from_bfd_reloc (r_type
);
8490 _bfd_aarch64_elf_put_addend (output_bfd
, plt_entry
, r_type
, howto
, value
);
8494 elfNN_aarch64_create_small_pltn_entry (struct elf_link_hash_entry
*h
,
8495 struct elf_aarch64_link_hash_table
8496 *htab
, bfd
*output_bfd
,
8497 struct bfd_link_info
*info
)
8499 bfd_byte
*plt_entry
;
8502 bfd_vma gotplt_entry_address
;
8503 bfd_vma plt_entry_address
;
8504 Elf_Internal_Rela rela
;
8506 asection
*plt
, *gotplt
, *relplt
;
8508 /* When building a static executable, use .iplt, .igot.plt and
8509 .rela.iplt sections for STT_GNU_IFUNC symbols. */
8510 if (htab
->root
.splt
!= NULL
)
8512 plt
= htab
->root
.splt
;
8513 gotplt
= htab
->root
.sgotplt
;
8514 relplt
= htab
->root
.srelplt
;
8518 plt
= htab
->root
.iplt
;
8519 gotplt
= htab
->root
.igotplt
;
8520 relplt
= htab
->root
.irelplt
;
8523 /* Get the index in the procedure linkage table which
8524 corresponds to this symbol. This is the index of this symbol
8525 in all the symbols for which we are making plt entries. The
8526 first entry in the procedure linkage table is reserved.
8528 Get the offset into the .got table of the entry that
8529 corresponds to this function. Each .got entry is GOT_ENTRY_SIZE
8530 bytes. The first three are reserved for the dynamic linker.
8532 For static executables, we don't reserve anything. */
8534 if (plt
== htab
->root
.splt
)
8536 plt_index
= (h
->plt
.offset
- htab
->plt_header_size
) / htab
->plt_entry_size
;
8537 got_offset
= (plt_index
+ 3) * GOT_ENTRY_SIZE
;
8541 plt_index
= h
->plt
.offset
/ htab
->plt_entry_size
;
8542 got_offset
= plt_index
* GOT_ENTRY_SIZE
;
8545 plt_entry
= plt
->contents
+ h
->plt
.offset
;
8546 plt_entry_address
= plt
->output_section
->vma
8547 + plt
->output_offset
+ h
->plt
.offset
;
8548 gotplt_entry_address
= gotplt
->output_section
->vma
+
8549 gotplt
->output_offset
+ got_offset
;
8551 /* Copy in the boiler-plate for the PLTn entry. */
8552 memcpy (plt_entry
, elfNN_aarch64_small_plt_entry
, PLT_SMALL_ENTRY_SIZE
);
8554 /* Fill in the top 21 bits for this: ADRP x16, PLT_GOT + n * 8.
8555 ADRP: ((PG(S+A)-PG(P)) >> 12) & 0x1fffff */
8556 elf_aarch64_update_plt_entry (output_bfd
, BFD_RELOC_AARCH64_ADR_HI21_PCREL
,
8558 PG (gotplt_entry_address
) -
8559 PG (plt_entry_address
));
8561 /* Fill in the lo12 bits for the load from the pltgot. */
8562 elf_aarch64_update_plt_entry (output_bfd
, BFD_RELOC_AARCH64_LDSTNN_LO12
,
8564 PG_OFFSET (gotplt_entry_address
));
8566 /* Fill in the lo12 bits for the add from the pltgot entry. */
8567 elf_aarch64_update_plt_entry (output_bfd
, BFD_RELOC_AARCH64_ADD_LO12
,
8569 PG_OFFSET (gotplt_entry_address
));
8571 /* All the GOTPLT Entries are essentially initialized to PLT0. */
8572 bfd_put_NN (output_bfd
,
8573 plt
->output_section
->vma
+ plt
->output_offset
,
8574 gotplt
->contents
+ got_offset
);
8576 rela
.r_offset
= gotplt_entry_address
;
8578 if (h
->dynindx
== -1
8579 || ((bfd_link_executable (info
)
8580 || ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
)
8582 && h
->type
== STT_GNU_IFUNC
))
8584 /* If an STT_GNU_IFUNC symbol is locally defined, generate
8585 R_AARCH64_IRELATIVE instead of R_AARCH64_JUMP_SLOT. */
8586 rela
.r_info
= ELFNN_R_INFO (0, AARCH64_R (IRELATIVE
));
8587 rela
.r_addend
= (h
->root
.u
.def
.value
8588 + h
->root
.u
.def
.section
->output_section
->vma
8589 + h
->root
.u
.def
.section
->output_offset
);
8593 /* Fill in the entry in the .rela.plt section. */
8594 rela
.r_info
= ELFNN_R_INFO (h
->dynindx
, AARCH64_R (JUMP_SLOT
));
8598 /* Compute the relocation entry to used based on PLT index and do
8599 not adjust reloc_count. The reloc_count has already been adjusted
8600 to account for this entry. */
8601 loc
= relplt
->contents
+ plt_index
* RELOC_SIZE (htab
);
8602 bfd_elfNN_swap_reloca_out (output_bfd
, &rela
, loc
);
8605 /* Size sections even though they're not dynamic. We use it to setup
8606 _TLS_MODULE_BASE_, if needed. */
8609 elfNN_aarch64_always_size_sections (bfd
*output_bfd
,
8610 struct bfd_link_info
*info
)
8614 if (bfd_link_relocatable (info
))
8617 tls_sec
= elf_hash_table (info
)->tls_sec
;
8621 struct elf_link_hash_entry
*tlsbase
;
8623 tlsbase
= elf_link_hash_lookup (elf_hash_table (info
),
8624 "_TLS_MODULE_BASE_", TRUE
, TRUE
, FALSE
);
8628 struct bfd_link_hash_entry
*h
= NULL
;
8629 const struct elf_backend_data
*bed
=
8630 get_elf_backend_data (output_bfd
);
8632 if (!(_bfd_generic_link_add_one_symbol
8633 (info
, output_bfd
, "_TLS_MODULE_BASE_", BSF_LOCAL
,
8634 tls_sec
, 0, NULL
, FALSE
, bed
->collect
, &h
)))
8637 tlsbase
->type
= STT_TLS
;
8638 tlsbase
= (struct elf_link_hash_entry
*) h
;
8639 tlsbase
->def_regular
= 1;
8640 tlsbase
->other
= STV_HIDDEN
;
8641 (*bed
->elf_backend_hide_symbol
) (info
, tlsbase
, TRUE
);
8648 /* Finish up dynamic symbol handling. We set the contents of various
8649 dynamic sections here. */
8651 elfNN_aarch64_finish_dynamic_symbol (bfd
*output_bfd
,
8652 struct bfd_link_info
*info
,
8653 struct elf_link_hash_entry
*h
,
8654 Elf_Internal_Sym
*sym
)
8656 struct elf_aarch64_link_hash_table
*htab
;
8657 htab
= elf_aarch64_hash_table (info
);
8659 if (h
->plt
.offset
!= (bfd_vma
) - 1)
8661 asection
*plt
, *gotplt
, *relplt
;
8663 /* This symbol has an entry in the procedure linkage table. Set
8666 /* When building a static executable, use .iplt, .igot.plt and
8667 .rela.iplt sections for STT_GNU_IFUNC symbols. */
8668 if (htab
->root
.splt
!= NULL
)
8670 plt
= htab
->root
.splt
;
8671 gotplt
= htab
->root
.sgotplt
;
8672 relplt
= htab
->root
.srelplt
;
8676 plt
= htab
->root
.iplt
;
8677 gotplt
= htab
->root
.igotplt
;
8678 relplt
= htab
->root
.irelplt
;
8681 /* This symbol has an entry in the procedure linkage table. Set
8683 if ((h
->dynindx
== -1
8684 && !((h
->forced_local
|| bfd_link_executable (info
))
8686 && h
->type
== STT_GNU_IFUNC
))
8692 elfNN_aarch64_create_small_pltn_entry (h
, htab
, output_bfd
, info
);
8693 if (!h
->def_regular
)
8695 /* Mark the symbol as undefined, rather than as defined in
8696 the .plt section. */
8697 sym
->st_shndx
= SHN_UNDEF
;
8698 /* If the symbol is weak we need to clear the value.
8699 Otherwise, the PLT entry would provide a definition for
8700 the symbol even if the symbol wasn't defined anywhere,
8701 and so the symbol would never be NULL. Leave the value if
8702 there were any relocations where pointer equality matters
8703 (this is a clue for the dynamic linker, to make function
8704 pointer comparisons work between an application and shared
8706 if (!h
->ref_regular_nonweak
|| !h
->pointer_equality_needed
)
8711 if (h
->got
.offset
!= (bfd_vma
) - 1
8712 && elf_aarch64_hash_entry (h
)->got_type
== GOT_NORMAL
)
8714 Elf_Internal_Rela rela
;
8717 /* This symbol has an entry in the global offset table. Set it
8719 if (htab
->root
.sgot
== NULL
|| htab
->root
.srelgot
== NULL
)
8722 rela
.r_offset
= (htab
->root
.sgot
->output_section
->vma
8723 + htab
->root
.sgot
->output_offset
8724 + (h
->got
.offset
& ~(bfd_vma
) 1));
8727 && h
->type
== STT_GNU_IFUNC
)
8729 if (bfd_link_pic (info
))
8731 /* Generate R_AARCH64_GLOB_DAT. */
8738 if (!h
->pointer_equality_needed
)
8741 /* For non-shared object, we can't use .got.plt, which
8742 contains the real function address if we need pointer
8743 equality. We load the GOT entry with the PLT entry. */
8744 plt
= htab
->root
.splt
? htab
->root
.splt
: htab
->root
.iplt
;
8745 bfd_put_NN (output_bfd
, (plt
->output_section
->vma
8746 + plt
->output_offset
8748 htab
->root
.sgot
->contents
8749 + (h
->got
.offset
& ~(bfd_vma
) 1));
8753 else if (bfd_link_pic (info
) && SYMBOL_REFERENCES_LOCAL (info
, h
))
8755 if (!h
->def_regular
)
8758 BFD_ASSERT ((h
->got
.offset
& 1) != 0);
8759 rela
.r_info
= ELFNN_R_INFO (0, AARCH64_R (RELATIVE
));
8760 rela
.r_addend
= (h
->root
.u
.def
.value
8761 + h
->root
.u
.def
.section
->output_section
->vma
8762 + h
->root
.u
.def
.section
->output_offset
);
8767 BFD_ASSERT ((h
->got
.offset
& 1) == 0);
8768 bfd_put_NN (output_bfd
, (bfd_vma
) 0,
8769 htab
->root
.sgot
->contents
+ h
->got
.offset
);
8770 rela
.r_info
= ELFNN_R_INFO (h
->dynindx
, AARCH64_R (GLOB_DAT
));
8774 loc
= htab
->root
.srelgot
->contents
;
8775 loc
+= htab
->root
.srelgot
->reloc_count
++ * RELOC_SIZE (htab
);
8776 bfd_elfNN_swap_reloca_out (output_bfd
, &rela
, loc
);
8781 Elf_Internal_Rela rela
;
8784 /* This symbol needs a copy reloc. Set it up. */
8786 if (h
->dynindx
== -1
8787 || (h
->root
.type
!= bfd_link_hash_defined
8788 && h
->root
.type
!= bfd_link_hash_defweak
)
8789 || htab
->srelbss
== NULL
)
8792 rela
.r_offset
= (h
->root
.u
.def
.value
8793 + h
->root
.u
.def
.section
->output_section
->vma
8794 + h
->root
.u
.def
.section
->output_offset
);
8795 rela
.r_info
= ELFNN_R_INFO (h
->dynindx
, AARCH64_R (COPY
));
8797 loc
= htab
->srelbss
->contents
;
8798 loc
+= htab
->srelbss
->reloc_count
++ * RELOC_SIZE (htab
);
8799 bfd_elfNN_swap_reloca_out (output_bfd
, &rela
, loc
);
8802 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. SYM may
8803 be NULL for local symbols. */
8805 && (h
== elf_hash_table (info
)->hdynamic
8806 || h
== elf_hash_table (info
)->hgot
))
8807 sym
->st_shndx
= SHN_ABS
;
8812 /* Finish up local dynamic symbol handling. We set the contents of
8813 various dynamic sections here. */
8816 elfNN_aarch64_finish_local_dynamic_symbol (void **slot
, void *inf
)
8818 struct elf_link_hash_entry
*h
8819 = (struct elf_link_hash_entry
*) *slot
;
8820 struct bfd_link_info
*info
8821 = (struct bfd_link_info
*) inf
;
8823 return elfNN_aarch64_finish_dynamic_symbol (info
->output_bfd
,
8828 elfNN_aarch64_init_small_plt0_entry (bfd
*output_bfd ATTRIBUTE_UNUSED
,
8829 struct elf_aarch64_link_hash_table
8832 /* Fill in PLT0. Fixme:RR Note this doesn't distinguish between
8833 small and large plts and at the minute just generates
8836 /* PLT0 of the small PLT looks like this in ELF64 -
8837 stp x16, x30, [sp, #-16]! // Save the reloc and lr on stack.
8838 adrp x16, PLT_GOT + 16 // Get the page base of the GOTPLT
8839 ldr x17, [x16, #:lo12:PLT_GOT+16] // Load the address of the
8841 add x16, x16, #:lo12:PLT_GOT+16 // Load the lo12 bits of the
8842 // GOTPLT entry for this.
8844 PLT0 will be slightly different in ELF32 due to different got entry
8847 bfd_vma plt_got_2nd_ent
; /* Address of GOT[2]. */
8851 memcpy (htab
->root
.splt
->contents
, elfNN_aarch64_small_plt0_entry
,
8853 elf_section_data (htab
->root
.splt
->output_section
)->this_hdr
.sh_entsize
=
8856 plt_got_2nd_ent
= (htab
->root
.sgotplt
->output_section
->vma
8857 + htab
->root
.sgotplt
->output_offset
8858 + GOT_ENTRY_SIZE
* 2);
8860 plt_base
= htab
->root
.splt
->output_section
->vma
+
8861 htab
->root
.splt
->output_offset
;
8863 /* Fill in the top 21 bits for this: ADRP x16, PLT_GOT + n * 8.
8864 ADRP: ((PG(S+A)-PG(P)) >> 12) & 0x1fffff */
8865 elf_aarch64_update_plt_entry (output_bfd
, BFD_RELOC_AARCH64_ADR_HI21_PCREL
,
8866 htab
->root
.splt
->contents
+ 4,
8867 PG (plt_got_2nd_ent
) - PG (plt_base
+ 4));
8869 elf_aarch64_update_plt_entry (output_bfd
, BFD_RELOC_AARCH64_LDSTNN_LO12
,
8870 htab
->root
.splt
->contents
+ 8,
8871 PG_OFFSET (plt_got_2nd_ent
));
8873 elf_aarch64_update_plt_entry (output_bfd
, BFD_RELOC_AARCH64_ADD_LO12
,
8874 htab
->root
.splt
->contents
+ 12,
8875 PG_OFFSET (plt_got_2nd_ent
));
8879 elfNN_aarch64_finish_dynamic_sections (bfd
*output_bfd
,
8880 struct bfd_link_info
*info
)
8882 struct elf_aarch64_link_hash_table
*htab
;
8886 htab
= elf_aarch64_hash_table (info
);
8887 dynobj
= htab
->root
.dynobj
;
8888 sdyn
= bfd_get_linker_section (dynobj
, ".dynamic");
8890 if (htab
->root
.dynamic_sections_created
)
8892 ElfNN_External_Dyn
*dyncon
, *dynconend
;
8894 if (sdyn
== NULL
|| htab
->root
.sgot
== NULL
)
8897 dyncon
= (ElfNN_External_Dyn
*) sdyn
->contents
;
8898 dynconend
= (ElfNN_External_Dyn
*) (sdyn
->contents
+ sdyn
->size
);
8899 for (; dyncon
< dynconend
; dyncon
++)
8901 Elf_Internal_Dyn dyn
;
8904 bfd_elfNN_swap_dyn_in (dynobj
, dyncon
, &dyn
);
8912 s
= htab
->root
.sgotplt
;
8913 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
8917 dyn
.d_un
.d_ptr
= htab
->root
.srelplt
->output_section
->vma
;
8921 s
= htab
->root
.srelplt
;
8922 dyn
.d_un
.d_val
= s
->size
;
8926 /* The procedure linkage table relocs (DT_JMPREL) should
8927 not be included in the overall relocs (DT_RELA).
8928 Therefore, we override the DT_RELASZ entry here to
8929 make it not include the JMPREL relocs. Since the
8930 linker script arranges for .rela.plt to follow all
8931 other relocation sections, we don't have to worry
8932 about changing the DT_RELA entry. */
8933 if (htab
->root
.srelplt
!= NULL
)
8935 s
= htab
->root
.srelplt
;
8936 dyn
.d_un
.d_val
-= s
->size
;
8940 case DT_TLSDESC_PLT
:
8941 s
= htab
->root
.splt
;
8942 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
8943 + htab
->tlsdesc_plt
;
8946 case DT_TLSDESC_GOT
:
8947 s
= htab
->root
.sgot
;
8948 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
8949 + htab
->dt_tlsdesc_got
;
8953 bfd_elfNN_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
8958 /* Fill in the special first entry in the procedure linkage table. */
8959 if (htab
->root
.splt
&& htab
->root
.splt
->size
> 0)
8961 elfNN_aarch64_init_small_plt0_entry (output_bfd
, htab
);
8963 elf_section_data (htab
->root
.splt
->output_section
)->
8964 this_hdr
.sh_entsize
= htab
->plt_entry_size
;
8967 if (htab
->tlsdesc_plt
)
8969 bfd_put_NN (output_bfd
, (bfd_vma
) 0,
8970 htab
->root
.sgot
->contents
+ htab
->dt_tlsdesc_got
);
8972 memcpy (htab
->root
.splt
->contents
+ htab
->tlsdesc_plt
,
8973 elfNN_aarch64_tlsdesc_small_plt_entry
,
8974 sizeof (elfNN_aarch64_tlsdesc_small_plt_entry
));
8977 bfd_vma adrp1_addr
=
8978 htab
->root
.splt
->output_section
->vma
8979 + htab
->root
.splt
->output_offset
+ htab
->tlsdesc_plt
+ 4;
8981 bfd_vma adrp2_addr
= adrp1_addr
+ 4;
8984 htab
->root
.sgot
->output_section
->vma
8985 + htab
->root
.sgot
->output_offset
;
8987 bfd_vma pltgot_addr
=
8988 htab
->root
.sgotplt
->output_section
->vma
8989 + htab
->root
.sgotplt
->output_offset
;
8991 bfd_vma dt_tlsdesc_got
= got_addr
+ htab
->dt_tlsdesc_got
;
8993 bfd_byte
*plt_entry
=
8994 htab
->root
.splt
->contents
+ htab
->tlsdesc_plt
;
8996 /* adrp x2, DT_TLSDESC_GOT */
8997 elf_aarch64_update_plt_entry (output_bfd
,
8998 BFD_RELOC_AARCH64_ADR_HI21_PCREL
,
9000 (PG (dt_tlsdesc_got
)
9001 - PG (adrp1_addr
)));
9004 elf_aarch64_update_plt_entry (output_bfd
,
9005 BFD_RELOC_AARCH64_ADR_HI21_PCREL
,
9008 - PG (adrp2_addr
)));
9010 /* ldr x2, [x2, #0] */
9011 elf_aarch64_update_plt_entry (output_bfd
,
9012 BFD_RELOC_AARCH64_LDSTNN_LO12
,
9014 PG_OFFSET (dt_tlsdesc_got
));
9017 elf_aarch64_update_plt_entry (output_bfd
,
9018 BFD_RELOC_AARCH64_ADD_LO12
,
9020 PG_OFFSET (pltgot_addr
));
9025 if (htab
->root
.sgotplt
)
9027 if (bfd_is_abs_section (htab
->root
.sgotplt
->output_section
))
9029 (*_bfd_error_handler
)
9030 (_("discarded output section: `%A'"), htab
->root
.sgotplt
);
9034 /* Fill in the first three entries in the global offset table. */
9035 if (htab
->root
.sgotplt
->size
> 0)
9037 bfd_put_NN (output_bfd
, (bfd_vma
) 0, htab
->root
.sgotplt
->contents
);
9039 /* Write GOT[1] and GOT[2], needed for the dynamic linker. */
9040 bfd_put_NN (output_bfd
,
9042 htab
->root
.sgotplt
->contents
+ GOT_ENTRY_SIZE
);
9043 bfd_put_NN (output_bfd
,
9045 htab
->root
.sgotplt
->contents
+ GOT_ENTRY_SIZE
* 2);
9048 if (htab
->root
.sgot
)
9050 if (htab
->root
.sgot
->size
> 0)
9053 sdyn
? sdyn
->output_section
->vma
+ sdyn
->output_offset
: 0;
9054 bfd_put_NN (output_bfd
, addr
, htab
->root
.sgot
->contents
);
9058 elf_section_data (htab
->root
.sgotplt
->output_section
)->
9059 this_hdr
.sh_entsize
= GOT_ENTRY_SIZE
;
9062 if (htab
->root
.sgot
&& htab
->root
.sgot
->size
> 0)
9063 elf_section_data (htab
->root
.sgot
->output_section
)->this_hdr
.sh_entsize
9066 /* Fill PLT and GOT entries for local STT_GNU_IFUNC symbols. */
9067 htab_traverse (htab
->loc_hash_table
,
9068 elfNN_aarch64_finish_local_dynamic_symbol
,
9074 /* Return address for Ith PLT stub in section PLT, for relocation REL
9075 or (bfd_vma) -1 if it should not be included. */
9078 elfNN_aarch64_plt_sym_val (bfd_vma i
, const asection
*plt
,
9079 const arelent
*rel ATTRIBUTE_UNUSED
)
9081 return plt
->vma
+ PLT_ENTRY_SIZE
+ i
* PLT_SMALL_ENTRY_SIZE
;
9085 /* We use this so we can override certain functions
9086 (though currently we don't). */
9088 const struct elf_size_info elfNN_aarch64_size_info
=
9090 sizeof (ElfNN_External_Ehdr
),
9091 sizeof (ElfNN_External_Phdr
),
9092 sizeof (ElfNN_External_Shdr
),
9093 sizeof (ElfNN_External_Rel
),
9094 sizeof (ElfNN_External_Rela
),
9095 sizeof (ElfNN_External_Sym
),
9096 sizeof (ElfNN_External_Dyn
),
9097 sizeof (Elf_External_Note
),
9098 4, /* Hash table entry size. */
9099 1, /* Internal relocs per external relocs. */
9100 ARCH_SIZE
, /* Arch size. */
9101 LOG_FILE_ALIGN
, /* Log_file_align. */
9102 ELFCLASSNN
, EV_CURRENT
,
9103 bfd_elfNN_write_out_phdrs
,
9104 bfd_elfNN_write_shdrs_and_ehdr
,
9105 bfd_elfNN_checksum_contents
,
9106 bfd_elfNN_write_relocs
,
9107 bfd_elfNN_swap_symbol_in
,
9108 bfd_elfNN_swap_symbol_out
,
9109 bfd_elfNN_slurp_reloc_table
,
9110 bfd_elfNN_slurp_symbol_table
,
9111 bfd_elfNN_swap_dyn_in
,
9112 bfd_elfNN_swap_dyn_out
,
9113 bfd_elfNN_swap_reloc_in
,
9114 bfd_elfNN_swap_reloc_out
,
9115 bfd_elfNN_swap_reloca_in
,
9116 bfd_elfNN_swap_reloca_out
9119 #define ELF_ARCH bfd_arch_aarch64
9120 #define ELF_MACHINE_CODE EM_AARCH64
9121 #define ELF_MAXPAGESIZE 0x10000
9122 #define ELF_MINPAGESIZE 0x1000
9123 #define ELF_COMMONPAGESIZE 0x1000
9125 #define bfd_elfNN_close_and_cleanup \
9126 elfNN_aarch64_close_and_cleanup
9128 #define bfd_elfNN_bfd_free_cached_info \
9129 elfNN_aarch64_bfd_free_cached_info
9131 #define bfd_elfNN_bfd_is_target_special_symbol \
9132 elfNN_aarch64_is_target_special_symbol
9134 #define bfd_elfNN_bfd_link_hash_table_create \
9135 elfNN_aarch64_link_hash_table_create
9137 #define bfd_elfNN_bfd_merge_private_bfd_data \
9138 elfNN_aarch64_merge_private_bfd_data
9140 #define bfd_elfNN_bfd_print_private_bfd_data \
9141 elfNN_aarch64_print_private_bfd_data
9143 #define bfd_elfNN_bfd_reloc_type_lookup \
9144 elfNN_aarch64_reloc_type_lookup
9146 #define bfd_elfNN_bfd_reloc_name_lookup \
9147 elfNN_aarch64_reloc_name_lookup
9149 #define bfd_elfNN_bfd_set_private_flags \
9150 elfNN_aarch64_set_private_flags
9152 #define bfd_elfNN_find_inliner_info \
9153 elfNN_aarch64_find_inliner_info
9155 #define bfd_elfNN_find_nearest_line \
9156 elfNN_aarch64_find_nearest_line
9158 #define bfd_elfNN_mkobject \
9159 elfNN_aarch64_mkobject
9161 #define bfd_elfNN_new_section_hook \
9162 elfNN_aarch64_new_section_hook
9164 #define elf_backend_adjust_dynamic_symbol \
9165 elfNN_aarch64_adjust_dynamic_symbol
9167 #define elf_backend_always_size_sections \
9168 elfNN_aarch64_always_size_sections
9170 #define elf_backend_check_relocs \
9171 elfNN_aarch64_check_relocs
9173 #define elf_backend_copy_indirect_symbol \
9174 elfNN_aarch64_copy_indirect_symbol
9176 /* Create .dynbss, and .rela.bss sections in DYNOBJ, and set up shortcuts
9177 to them in our hash. */
9178 #define elf_backend_create_dynamic_sections \
9179 elfNN_aarch64_create_dynamic_sections
9181 #define elf_backend_init_index_section \
9182 _bfd_elf_init_2_index_sections
9184 #define elf_backend_finish_dynamic_sections \
9185 elfNN_aarch64_finish_dynamic_sections
9187 #define elf_backend_finish_dynamic_symbol \
9188 elfNN_aarch64_finish_dynamic_symbol
9190 #define elf_backend_gc_sweep_hook \
9191 elfNN_aarch64_gc_sweep_hook
9193 #define elf_backend_object_p \
9194 elfNN_aarch64_object_p
9196 #define elf_backend_output_arch_local_syms \
9197 elfNN_aarch64_output_arch_local_syms
9199 #define elf_backend_plt_sym_val \
9200 elfNN_aarch64_plt_sym_val
9202 #define elf_backend_post_process_headers \
9203 elfNN_aarch64_post_process_headers
9205 #define elf_backend_relocate_section \
9206 elfNN_aarch64_relocate_section
9208 #define elf_backend_reloc_type_class \
9209 elfNN_aarch64_reloc_type_class
9211 #define elf_backend_section_from_shdr \
9212 elfNN_aarch64_section_from_shdr
9214 #define elf_backend_size_dynamic_sections \
9215 elfNN_aarch64_size_dynamic_sections
9217 #define elf_backend_size_info \
9218 elfNN_aarch64_size_info
9220 #define elf_backend_write_section \
9221 elfNN_aarch64_write_section
9223 #define elf_backend_can_refcount 1
9224 #define elf_backend_can_gc_sections 1
9225 #define elf_backend_plt_readonly 1
9226 #define elf_backend_want_got_plt 1
9227 #define elf_backend_want_plt_sym 0
9228 #define elf_backend_may_use_rel_p 0
9229 #define elf_backend_may_use_rela_p 1
9230 #define elf_backend_default_use_rela_p 1
9231 #define elf_backend_rela_normal 1
9232 #define elf_backend_got_header_size (GOT_ENTRY_SIZE * 3)
9233 #define elf_backend_default_execstack 0
9234 #define elf_backend_extern_protected_data 1
9236 #undef elf_backend_obj_attrs_section
9237 #define elf_backend_obj_attrs_section ".ARM.attributes"
9239 #include "elfNN-target.h"