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_TLSIE_ADR_GOTTPREL_PAGE21 \
222 || (R_TYPE) == BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19 \
223 || (R_TYPE) == BFD_RELOC_AARCH64_TLSIE_LDNN_GOTTPREL_LO12_NC \
224 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC \
225 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21 \
226 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_ADR_PREL21)
228 #define IS_AARCH64_TLSDESC_RELOC(R_TYPE) \
229 ((R_TYPE) == BFD_RELOC_AARCH64_TLSDESC \
230 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_ADD \
231 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_ADD_LO12_NC \
232 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21 \
233 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21 \
234 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_CALL \
235 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_LD32_LO12_NC \
236 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_LD64_LO12_NC \
237 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_LDR \
238 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_LD_PREL19 \
239 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_OFF_G0_NC \
240 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_OFF_G1)
242 #define ELIMINATE_COPY_RELOCS 0
244 /* Return size of a relocation entry. HTAB is the bfd's
245 elf_aarch64_link_hash_entry. */
246 #define RELOC_SIZE(HTAB) (sizeof (ElfNN_External_Rela))
248 /* GOT Entry size - 8 bytes in ELF64 and 4 bytes in ELF32. */
249 #define GOT_ENTRY_SIZE (ARCH_SIZE / 8)
250 #define PLT_ENTRY_SIZE (32)
251 #define PLT_SMALL_ENTRY_SIZE (16)
252 #define PLT_TLSDESC_ENTRY_SIZE (32)
254 /* Encoding of the nop instruction */
255 #define INSN_NOP 0xd503201f
257 #define aarch64_compute_jump_table_size(htab) \
258 (((htab)->root.srelplt == NULL) ? 0 \
259 : (htab)->root.srelplt->reloc_count * GOT_ENTRY_SIZE)
261 /* The first entry in a procedure linkage table looks like this
262 if the distance between the PLTGOT and the PLT is < 4GB use
263 these PLT entries. Note that the dynamic linker gets &PLTGOT[2]
264 in x16 and needs to work out PLTGOT[1] by using an address of
265 [x16,#-GOT_ENTRY_SIZE]. */
266 static const bfd_byte elfNN_aarch64_small_plt0_entry
[PLT_ENTRY_SIZE
] =
268 0xf0, 0x7b, 0xbf, 0xa9, /* stp x16, x30, [sp, #-16]! */
269 0x10, 0x00, 0x00, 0x90, /* adrp x16, (GOT+16) */
271 0x11, 0x0A, 0x40, 0xf9, /* ldr x17, [x16, #PLT_GOT+0x10] */
272 0x10, 0x42, 0x00, 0x91, /* add x16, x16,#PLT_GOT+0x10 */
274 0x11, 0x0A, 0x40, 0xb9, /* ldr w17, [x16, #PLT_GOT+0x8] */
275 0x10, 0x22, 0x00, 0x11, /* add w16, w16,#PLT_GOT+0x8 */
277 0x20, 0x02, 0x1f, 0xd6, /* br x17 */
278 0x1f, 0x20, 0x03, 0xd5, /* nop */
279 0x1f, 0x20, 0x03, 0xd5, /* nop */
280 0x1f, 0x20, 0x03, 0xd5, /* nop */
283 /* Per function entry in a procedure linkage table looks like this
284 if the distance between the PLTGOT and the PLT is < 4GB use
285 these PLT entries. */
286 static const bfd_byte elfNN_aarch64_small_plt_entry
[PLT_SMALL_ENTRY_SIZE
] =
288 0x10, 0x00, 0x00, 0x90, /* adrp x16, PLTGOT + n * 8 */
290 0x11, 0x02, 0x40, 0xf9, /* ldr x17, [x16, PLTGOT + n * 8] */
291 0x10, 0x02, 0x00, 0x91, /* add x16, x16, :lo12:PLTGOT + n * 8 */
293 0x11, 0x02, 0x40, 0xb9, /* ldr w17, [x16, PLTGOT + n * 4] */
294 0x10, 0x02, 0x00, 0x11, /* add w16, w16, :lo12:PLTGOT + n * 4 */
296 0x20, 0x02, 0x1f, 0xd6, /* br x17. */
299 static const bfd_byte
300 elfNN_aarch64_tlsdesc_small_plt_entry
[PLT_TLSDESC_ENTRY_SIZE
] =
302 0xe2, 0x0f, 0xbf, 0xa9, /* stp x2, x3, [sp, #-16]! */
303 0x02, 0x00, 0x00, 0x90, /* adrp x2, 0 */
304 0x03, 0x00, 0x00, 0x90, /* adrp x3, 0 */
306 0x42, 0x00, 0x40, 0xf9, /* ldr x2, [x2, #0] */
307 0x63, 0x00, 0x00, 0x91, /* add x3, x3, 0 */
309 0x42, 0x00, 0x40, 0xb9, /* ldr w2, [x2, #0] */
310 0x63, 0x00, 0x00, 0x11, /* add w3, w3, 0 */
312 0x40, 0x00, 0x1f, 0xd6, /* br x2 */
313 0x1f, 0x20, 0x03, 0xd5, /* nop */
314 0x1f, 0x20, 0x03, 0xd5, /* nop */
317 #define elf_info_to_howto elfNN_aarch64_info_to_howto
318 #define elf_info_to_howto_rel elfNN_aarch64_info_to_howto
320 #define AARCH64_ELF_ABI_VERSION 0
322 /* In case we're on a 32-bit machine, construct a 64-bit "-1" value. */
323 #define ALL_ONES (~ (bfd_vma) 0)
325 /* Indexed by the bfd interal reloc enumerators.
326 Therefore, the table needs to be synced with BFD_RELOC_AARCH64_*
329 static reloc_howto_type elfNN_aarch64_howto_table
[] =
333 /* Basic data relocations. */
336 HOWTO (R_AARCH64_NULL
, /* type */
338 3, /* size (0 = byte, 1 = short, 2 = long) */
340 FALSE
, /* pc_relative */
342 complain_overflow_dont
, /* complain_on_overflow */
343 bfd_elf_generic_reloc
, /* special_function */
344 "R_AARCH64_NULL", /* name */
345 FALSE
, /* partial_inplace */
348 FALSE
), /* pcrel_offset */
350 HOWTO (R_AARCH64_NONE
, /* type */
352 3, /* size (0 = byte, 1 = short, 2 = long) */
354 FALSE
, /* pc_relative */
356 complain_overflow_dont
, /* complain_on_overflow */
357 bfd_elf_generic_reloc
, /* special_function */
358 "R_AARCH64_NONE", /* name */
359 FALSE
, /* partial_inplace */
362 FALSE
), /* pcrel_offset */
366 HOWTO64 (AARCH64_R (ABS64
), /* type */
368 4, /* size (4 = long long) */
370 FALSE
, /* pc_relative */
372 complain_overflow_unsigned
, /* complain_on_overflow */
373 bfd_elf_generic_reloc
, /* special_function */
374 AARCH64_R_STR (ABS64
), /* name */
375 FALSE
, /* partial_inplace */
376 ALL_ONES
, /* src_mask */
377 ALL_ONES
, /* dst_mask */
378 FALSE
), /* pcrel_offset */
381 HOWTO (AARCH64_R (ABS32
), /* type */
383 2, /* size (0 = byte, 1 = short, 2 = long) */
385 FALSE
, /* pc_relative */
387 complain_overflow_unsigned
, /* complain_on_overflow */
388 bfd_elf_generic_reloc
, /* special_function */
389 AARCH64_R_STR (ABS32
), /* name */
390 FALSE
, /* partial_inplace */
391 0xffffffff, /* src_mask */
392 0xffffffff, /* dst_mask */
393 FALSE
), /* pcrel_offset */
396 HOWTO (AARCH64_R (ABS16
), /* type */
398 1, /* size (0 = byte, 1 = short, 2 = long) */
400 FALSE
, /* pc_relative */
402 complain_overflow_unsigned
, /* complain_on_overflow */
403 bfd_elf_generic_reloc
, /* special_function */
404 AARCH64_R_STR (ABS16
), /* name */
405 FALSE
, /* partial_inplace */
406 0xffff, /* src_mask */
407 0xffff, /* dst_mask */
408 FALSE
), /* pcrel_offset */
410 /* .xword: (S+A-P) */
411 HOWTO64 (AARCH64_R (PREL64
), /* type */
413 4, /* size (4 = long long) */
415 TRUE
, /* pc_relative */
417 complain_overflow_signed
, /* complain_on_overflow */
418 bfd_elf_generic_reloc
, /* special_function */
419 AARCH64_R_STR (PREL64
), /* name */
420 FALSE
, /* partial_inplace */
421 ALL_ONES
, /* src_mask */
422 ALL_ONES
, /* dst_mask */
423 TRUE
), /* pcrel_offset */
426 HOWTO (AARCH64_R (PREL32
), /* type */
428 2, /* size (0 = byte, 1 = short, 2 = long) */
430 TRUE
, /* pc_relative */
432 complain_overflow_signed
, /* complain_on_overflow */
433 bfd_elf_generic_reloc
, /* special_function */
434 AARCH64_R_STR (PREL32
), /* name */
435 FALSE
, /* partial_inplace */
436 0xffffffff, /* src_mask */
437 0xffffffff, /* dst_mask */
438 TRUE
), /* pcrel_offset */
441 HOWTO (AARCH64_R (PREL16
), /* type */
443 1, /* size (0 = byte, 1 = short, 2 = long) */
445 TRUE
, /* pc_relative */
447 complain_overflow_signed
, /* complain_on_overflow */
448 bfd_elf_generic_reloc
, /* special_function */
449 AARCH64_R_STR (PREL16
), /* name */
450 FALSE
, /* partial_inplace */
451 0xffff, /* src_mask */
452 0xffff, /* dst_mask */
453 TRUE
), /* pcrel_offset */
455 /* Group relocations to create a 16, 32, 48 or 64 bit
456 unsigned data or abs address inline. */
458 /* MOVZ: ((S+A) >> 0) & 0xffff */
459 HOWTO (AARCH64_R (MOVW_UABS_G0
), /* type */
461 2, /* size (0 = byte, 1 = short, 2 = long) */
463 FALSE
, /* pc_relative */
465 complain_overflow_unsigned
, /* complain_on_overflow */
466 bfd_elf_generic_reloc
, /* special_function */
467 AARCH64_R_STR (MOVW_UABS_G0
), /* name */
468 FALSE
, /* partial_inplace */
469 0xffff, /* src_mask */
470 0xffff, /* dst_mask */
471 FALSE
), /* pcrel_offset */
473 /* MOVK: ((S+A) >> 0) & 0xffff [no overflow check] */
474 HOWTO (AARCH64_R (MOVW_UABS_G0_NC
), /* type */
476 2, /* size (0 = byte, 1 = short, 2 = long) */
478 FALSE
, /* pc_relative */
480 complain_overflow_dont
, /* complain_on_overflow */
481 bfd_elf_generic_reloc
, /* special_function */
482 AARCH64_R_STR (MOVW_UABS_G0_NC
), /* name */
483 FALSE
, /* partial_inplace */
484 0xffff, /* src_mask */
485 0xffff, /* dst_mask */
486 FALSE
), /* pcrel_offset */
488 /* MOVZ: ((S+A) >> 16) & 0xffff */
489 HOWTO (AARCH64_R (MOVW_UABS_G1
), /* type */
491 2, /* size (0 = byte, 1 = short, 2 = long) */
493 FALSE
, /* pc_relative */
495 complain_overflow_unsigned
, /* complain_on_overflow */
496 bfd_elf_generic_reloc
, /* special_function */
497 AARCH64_R_STR (MOVW_UABS_G1
), /* name */
498 FALSE
, /* partial_inplace */
499 0xffff, /* src_mask */
500 0xffff, /* dst_mask */
501 FALSE
), /* pcrel_offset */
503 /* MOVK: ((S+A) >> 16) & 0xffff [no overflow check] */
504 HOWTO64 (AARCH64_R (MOVW_UABS_G1_NC
), /* type */
506 2, /* size (0 = byte, 1 = short, 2 = long) */
508 FALSE
, /* pc_relative */
510 complain_overflow_dont
, /* complain_on_overflow */
511 bfd_elf_generic_reloc
, /* special_function */
512 AARCH64_R_STR (MOVW_UABS_G1_NC
), /* name */
513 FALSE
, /* partial_inplace */
514 0xffff, /* src_mask */
515 0xffff, /* dst_mask */
516 FALSE
), /* pcrel_offset */
518 /* MOVZ: ((S+A) >> 32) & 0xffff */
519 HOWTO64 (AARCH64_R (MOVW_UABS_G2
), /* type */
521 2, /* size (0 = byte, 1 = short, 2 = long) */
523 FALSE
, /* pc_relative */
525 complain_overflow_unsigned
, /* complain_on_overflow */
526 bfd_elf_generic_reloc
, /* special_function */
527 AARCH64_R_STR (MOVW_UABS_G2
), /* name */
528 FALSE
, /* partial_inplace */
529 0xffff, /* src_mask */
530 0xffff, /* dst_mask */
531 FALSE
), /* pcrel_offset */
533 /* MOVK: ((S+A) >> 32) & 0xffff [no overflow check] */
534 HOWTO64 (AARCH64_R (MOVW_UABS_G2_NC
), /* type */
536 2, /* size (0 = byte, 1 = short, 2 = long) */
538 FALSE
, /* pc_relative */
540 complain_overflow_dont
, /* complain_on_overflow */
541 bfd_elf_generic_reloc
, /* special_function */
542 AARCH64_R_STR (MOVW_UABS_G2_NC
), /* name */
543 FALSE
, /* partial_inplace */
544 0xffff, /* src_mask */
545 0xffff, /* dst_mask */
546 FALSE
), /* pcrel_offset */
548 /* MOVZ: ((S+A) >> 48) & 0xffff */
549 HOWTO64 (AARCH64_R (MOVW_UABS_G3
), /* type */
551 2, /* size (0 = byte, 1 = short, 2 = long) */
553 FALSE
, /* pc_relative */
555 complain_overflow_unsigned
, /* complain_on_overflow */
556 bfd_elf_generic_reloc
, /* special_function */
557 AARCH64_R_STR (MOVW_UABS_G3
), /* name */
558 FALSE
, /* partial_inplace */
559 0xffff, /* src_mask */
560 0xffff, /* dst_mask */
561 FALSE
), /* pcrel_offset */
563 /* Group relocations to create high part of a 16, 32, 48 or 64 bit
564 signed data or abs address inline. Will change instruction
565 to MOVN or MOVZ depending on sign of calculated value. */
567 /* MOV[ZN]: ((S+A) >> 0) & 0xffff */
568 HOWTO (AARCH64_R (MOVW_SABS_G0
), /* type */
570 2, /* size (0 = byte, 1 = short, 2 = long) */
572 FALSE
, /* pc_relative */
574 complain_overflow_signed
, /* complain_on_overflow */
575 bfd_elf_generic_reloc
, /* special_function */
576 AARCH64_R_STR (MOVW_SABS_G0
), /* name */
577 FALSE
, /* partial_inplace */
578 0xffff, /* src_mask */
579 0xffff, /* dst_mask */
580 FALSE
), /* pcrel_offset */
582 /* MOV[ZN]: ((S+A) >> 16) & 0xffff */
583 HOWTO64 (AARCH64_R (MOVW_SABS_G1
), /* type */
585 2, /* size (0 = byte, 1 = short, 2 = long) */
587 FALSE
, /* pc_relative */
589 complain_overflow_signed
, /* complain_on_overflow */
590 bfd_elf_generic_reloc
, /* special_function */
591 AARCH64_R_STR (MOVW_SABS_G1
), /* name */
592 FALSE
, /* partial_inplace */
593 0xffff, /* src_mask */
594 0xffff, /* dst_mask */
595 FALSE
), /* pcrel_offset */
597 /* MOV[ZN]: ((S+A) >> 32) & 0xffff */
598 HOWTO64 (AARCH64_R (MOVW_SABS_G2
), /* type */
600 2, /* size (0 = byte, 1 = short, 2 = long) */
602 FALSE
, /* pc_relative */
604 complain_overflow_signed
, /* complain_on_overflow */
605 bfd_elf_generic_reloc
, /* special_function */
606 AARCH64_R_STR (MOVW_SABS_G2
), /* name */
607 FALSE
, /* partial_inplace */
608 0xffff, /* src_mask */
609 0xffff, /* dst_mask */
610 FALSE
), /* pcrel_offset */
612 /* Relocations to generate 19, 21 and 33 bit PC-relative load/store
613 addresses: PG(x) is (x & ~0xfff). */
615 /* LD-lit: ((S+A-P) >> 2) & 0x7ffff */
616 HOWTO (AARCH64_R (LD_PREL_LO19
), /* type */
618 2, /* size (0 = byte, 1 = short, 2 = long) */
620 TRUE
, /* pc_relative */
622 complain_overflow_signed
, /* complain_on_overflow */
623 bfd_elf_generic_reloc
, /* special_function */
624 AARCH64_R_STR (LD_PREL_LO19
), /* name */
625 FALSE
, /* partial_inplace */
626 0x7ffff, /* src_mask */
627 0x7ffff, /* dst_mask */
628 TRUE
), /* pcrel_offset */
630 /* ADR: (S+A-P) & 0x1fffff */
631 HOWTO (AARCH64_R (ADR_PREL_LO21
), /* type */
633 2, /* size (0 = byte, 1 = short, 2 = long) */
635 TRUE
, /* pc_relative */
637 complain_overflow_signed
, /* complain_on_overflow */
638 bfd_elf_generic_reloc
, /* special_function */
639 AARCH64_R_STR (ADR_PREL_LO21
), /* name */
640 FALSE
, /* partial_inplace */
641 0x1fffff, /* src_mask */
642 0x1fffff, /* dst_mask */
643 TRUE
), /* pcrel_offset */
645 /* ADRP: ((PG(S+A)-PG(P)) >> 12) & 0x1fffff */
646 HOWTO (AARCH64_R (ADR_PREL_PG_HI21
), /* type */
648 2, /* size (0 = byte, 1 = short, 2 = long) */
650 TRUE
, /* pc_relative */
652 complain_overflow_signed
, /* complain_on_overflow */
653 bfd_elf_generic_reloc
, /* special_function */
654 AARCH64_R_STR (ADR_PREL_PG_HI21
), /* name */
655 FALSE
, /* partial_inplace */
656 0x1fffff, /* src_mask */
657 0x1fffff, /* dst_mask */
658 TRUE
), /* pcrel_offset */
660 /* ADRP: ((PG(S+A)-PG(P)) >> 12) & 0x1fffff [no overflow check] */
661 HOWTO64 (AARCH64_R (ADR_PREL_PG_HI21_NC
), /* type */
663 2, /* size (0 = byte, 1 = short, 2 = long) */
665 TRUE
, /* pc_relative */
667 complain_overflow_dont
, /* complain_on_overflow */
668 bfd_elf_generic_reloc
, /* special_function */
669 AARCH64_R_STR (ADR_PREL_PG_HI21_NC
), /* name */
670 FALSE
, /* partial_inplace */
671 0x1fffff, /* src_mask */
672 0x1fffff, /* dst_mask */
673 TRUE
), /* pcrel_offset */
675 /* ADD: (S+A) & 0xfff [no overflow check] */
676 HOWTO (AARCH64_R (ADD_ABS_LO12_NC
), /* type */
678 2, /* size (0 = byte, 1 = short, 2 = long) */
680 FALSE
, /* pc_relative */
682 complain_overflow_dont
, /* complain_on_overflow */
683 bfd_elf_generic_reloc
, /* special_function */
684 AARCH64_R_STR (ADD_ABS_LO12_NC
), /* name */
685 FALSE
, /* partial_inplace */
686 0x3ffc00, /* src_mask */
687 0x3ffc00, /* dst_mask */
688 FALSE
), /* pcrel_offset */
690 /* LD/ST8: (S+A) & 0xfff */
691 HOWTO (AARCH64_R (LDST8_ABS_LO12_NC
), /* type */
693 2, /* size (0 = byte, 1 = short, 2 = long) */
695 FALSE
, /* pc_relative */
697 complain_overflow_dont
, /* complain_on_overflow */
698 bfd_elf_generic_reloc
, /* special_function */
699 AARCH64_R_STR (LDST8_ABS_LO12_NC
), /* name */
700 FALSE
, /* partial_inplace */
701 0xfff, /* src_mask */
702 0xfff, /* dst_mask */
703 FALSE
), /* pcrel_offset */
705 /* Relocations for control-flow instructions. */
707 /* TBZ/NZ: ((S+A-P) >> 2) & 0x3fff */
708 HOWTO (AARCH64_R (TSTBR14
), /* type */
710 2, /* size (0 = byte, 1 = short, 2 = long) */
712 TRUE
, /* pc_relative */
714 complain_overflow_signed
, /* complain_on_overflow */
715 bfd_elf_generic_reloc
, /* special_function */
716 AARCH64_R_STR (TSTBR14
), /* name */
717 FALSE
, /* partial_inplace */
718 0x3fff, /* src_mask */
719 0x3fff, /* dst_mask */
720 TRUE
), /* pcrel_offset */
722 /* B.cond: ((S+A-P) >> 2) & 0x7ffff */
723 HOWTO (AARCH64_R (CONDBR19
), /* type */
725 2, /* size (0 = byte, 1 = short, 2 = long) */
727 TRUE
, /* pc_relative */
729 complain_overflow_signed
, /* complain_on_overflow */
730 bfd_elf_generic_reloc
, /* special_function */
731 AARCH64_R_STR (CONDBR19
), /* name */
732 FALSE
, /* partial_inplace */
733 0x7ffff, /* src_mask */
734 0x7ffff, /* dst_mask */
735 TRUE
), /* pcrel_offset */
737 /* B: ((S+A-P) >> 2) & 0x3ffffff */
738 HOWTO (AARCH64_R (JUMP26
), /* type */
740 2, /* size (0 = byte, 1 = short, 2 = long) */
742 TRUE
, /* pc_relative */
744 complain_overflow_signed
, /* complain_on_overflow */
745 bfd_elf_generic_reloc
, /* special_function */
746 AARCH64_R_STR (JUMP26
), /* name */
747 FALSE
, /* partial_inplace */
748 0x3ffffff, /* src_mask */
749 0x3ffffff, /* dst_mask */
750 TRUE
), /* pcrel_offset */
752 /* BL: ((S+A-P) >> 2) & 0x3ffffff */
753 HOWTO (AARCH64_R (CALL26
), /* type */
755 2, /* size (0 = byte, 1 = short, 2 = long) */
757 TRUE
, /* pc_relative */
759 complain_overflow_signed
, /* complain_on_overflow */
760 bfd_elf_generic_reloc
, /* special_function */
761 AARCH64_R_STR (CALL26
), /* name */
762 FALSE
, /* partial_inplace */
763 0x3ffffff, /* src_mask */
764 0x3ffffff, /* dst_mask */
765 TRUE
), /* pcrel_offset */
767 /* LD/ST16: (S+A) & 0xffe */
768 HOWTO (AARCH64_R (LDST16_ABS_LO12_NC
), /* type */
770 2, /* size (0 = byte, 1 = short, 2 = long) */
772 FALSE
, /* pc_relative */
774 complain_overflow_dont
, /* complain_on_overflow */
775 bfd_elf_generic_reloc
, /* special_function */
776 AARCH64_R_STR (LDST16_ABS_LO12_NC
), /* name */
777 FALSE
, /* partial_inplace */
778 0xffe, /* src_mask */
779 0xffe, /* dst_mask */
780 FALSE
), /* pcrel_offset */
782 /* LD/ST32: (S+A) & 0xffc */
783 HOWTO (AARCH64_R (LDST32_ABS_LO12_NC
), /* type */
785 2, /* size (0 = byte, 1 = short, 2 = long) */
787 FALSE
, /* pc_relative */
789 complain_overflow_dont
, /* complain_on_overflow */
790 bfd_elf_generic_reloc
, /* special_function */
791 AARCH64_R_STR (LDST32_ABS_LO12_NC
), /* name */
792 FALSE
, /* partial_inplace */
793 0xffc, /* src_mask */
794 0xffc, /* dst_mask */
795 FALSE
), /* pcrel_offset */
797 /* LD/ST64: (S+A) & 0xff8 */
798 HOWTO (AARCH64_R (LDST64_ABS_LO12_NC
), /* type */
800 2, /* size (0 = byte, 1 = short, 2 = long) */
802 FALSE
, /* pc_relative */
804 complain_overflow_dont
, /* complain_on_overflow */
805 bfd_elf_generic_reloc
, /* special_function */
806 AARCH64_R_STR (LDST64_ABS_LO12_NC
), /* name */
807 FALSE
, /* partial_inplace */
808 0xff8, /* src_mask */
809 0xff8, /* dst_mask */
810 FALSE
), /* pcrel_offset */
812 /* LD/ST128: (S+A) & 0xff0 */
813 HOWTO (AARCH64_R (LDST128_ABS_LO12_NC
), /* type */
815 2, /* size (0 = byte, 1 = short, 2 = long) */
817 FALSE
, /* pc_relative */
819 complain_overflow_dont
, /* complain_on_overflow */
820 bfd_elf_generic_reloc
, /* special_function */
821 AARCH64_R_STR (LDST128_ABS_LO12_NC
), /* name */
822 FALSE
, /* partial_inplace */
823 0xff0, /* src_mask */
824 0xff0, /* dst_mask */
825 FALSE
), /* pcrel_offset */
827 /* Set a load-literal immediate field to bits
828 0x1FFFFC of G(S)-P */
829 HOWTO (AARCH64_R (GOT_LD_PREL19
), /* type */
831 2, /* size (0 = byte,1 = short,2 = long) */
833 TRUE
, /* pc_relative */
835 complain_overflow_signed
, /* complain_on_overflow */
836 bfd_elf_generic_reloc
, /* special_function */
837 AARCH64_R_STR (GOT_LD_PREL19
), /* name */
838 FALSE
, /* partial_inplace */
839 0xffffe0, /* src_mask */
840 0xffffe0, /* dst_mask */
841 TRUE
), /* pcrel_offset */
843 /* Get to the page for the GOT entry for the symbol
844 (G(S) - P) using an ADRP instruction. */
845 HOWTO (AARCH64_R (ADR_GOT_PAGE
), /* type */
847 2, /* size (0 = byte, 1 = short, 2 = long) */
849 TRUE
, /* pc_relative */
851 complain_overflow_dont
, /* complain_on_overflow */
852 bfd_elf_generic_reloc
, /* special_function */
853 AARCH64_R_STR (ADR_GOT_PAGE
), /* name */
854 FALSE
, /* partial_inplace */
855 0x1fffff, /* src_mask */
856 0x1fffff, /* dst_mask */
857 TRUE
), /* pcrel_offset */
859 /* LD64: GOT offset G(S) & 0xff8 */
860 HOWTO64 (AARCH64_R (LD64_GOT_LO12_NC
), /* type */
862 2, /* size (0 = byte, 1 = short, 2 = long) */
864 FALSE
, /* pc_relative */
866 complain_overflow_dont
, /* complain_on_overflow */
867 bfd_elf_generic_reloc
, /* special_function */
868 AARCH64_R_STR (LD64_GOT_LO12_NC
), /* name */
869 FALSE
, /* partial_inplace */
870 0xff8, /* src_mask */
871 0xff8, /* dst_mask */
872 FALSE
), /* pcrel_offset */
874 /* LD32: GOT offset G(S) & 0xffc */
875 HOWTO32 (AARCH64_R (LD32_GOT_LO12_NC
), /* type */
877 2, /* size (0 = byte, 1 = short, 2 = long) */
879 FALSE
, /* pc_relative */
881 complain_overflow_dont
, /* complain_on_overflow */
882 bfd_elf_generic_reloc
, /* special_function */
883 AARCH64_R_STR (LD32_GOT_LO12_NC
), /* name */
884 FALSE
, /* partial_inplace */
885 0xffc, /* src_mask */
886 0xffc, /* dst_mask */
887 FALSE
), /* pcrel_offset */
889 /* Lower 16 bits of GOT offset for the symbol. */
890 HOWTO64 (AARCH64_R (MOVW_GOTOFF_G0_NC
), /* type */
892 2, /* size (0 = byte, 1 = short, 2 = long) */
894 FALSE
, /* pc_relative */
896 complain_overflow_dont
, /* complain_on_overflow */
897 bfd_elf_generic_reloc
, /* special_function */
898 AARCH64_R_STR (MOVW_GOTOFF_G0_NC
), /* name */
899 FALSE
, /* partial_inplace */
900 0xffff, /* src_mask */
901 0xffff, /* dst_mask */
902 FALSE
), /* pcrel_offset */
904 /* Higher 16 bits of GOT offset for the symbol. */
905 HOWTO64 (AARCH64_R (MOVW_GOTOFF_G1
), /* type */
907 2, /* size (0 = byte, 1 = short, 2 = long) */
909 FALSE
, /* pc_relative */
911 complain_overflow_unsigned
, /* complain_on_overflow */
912 bfd_elf_generic_reloc
, /* special_function */
913 AARCH64_R_STR (MOVW_GOTOFF_G1
), /* name */
914 FALSE
, /* partial_inplace */
915 0xffff, /* src_mask */
916 0xffff, /* dst_mask */
917 FALSE
), /* pcrel_offset */
919 /* LD64: GOT offset for the symbol. */
920 HOWTO64 (AARCH64_R (LD64_GOTOFF_LO15
), /* type */
922 2, /* size (0 = byte, 1 = short, 2 = long) */
924 FALSE
, /* pc_relative */
926 complain_overflow_unsigned
, /* complain_on_overflow */
927 bfd_elf_generic_reloc
, /* special_function */
928 AARCH64_R_STR (LD64_GOTOFF_LO15
), /* name */
929 FALSE
, /* partial_inplace */
930 0x7ff8, /* src_mask */
931 0x7ff8, /* dst_mask */
932 FALSE
), /* pcrel_offset */
934 /* LD32: GOT offset to the page address of GOT table.
935 (G(S) - PAGE (_GLOBAL_OFFSET_TABLE_)) & 0x5ffc. */
936 HOWTO32 (AARCH64_R (LD32_GOTPAGE_LO14
), /* type */
938 2, /* size (0 = byte, 1 = short, 2 = long) */
940 FALSE
, /* pc_relative */
942 complain_overflow_unsigned
, /* complain_on_overflow */
943 bfd_elf_generic_reloc
, /* special_function */
944 AARCH64_R_STR (LD32_GOTPAGE_LO14
), /* name */
945 FALSE
, /* partial_inplace */
946 0x5ffc, /* src_mask */
947 0x5ffc, /* dst_mask */
948 FALSE
), /* pcrel_offset */
950 /* LD64: GOT offset to the page address of GOT table.
951 (G(S) - PAGE (_GLOBAL_OFFSET_TABLE_)) & 0x7ff8. */
952 HOWTO64 (AARCH64_R (LD64_GOTPAGE_LO15
), /* type */
954 2, /* size (0 = byte, 1 = short, 2 = long) */
956 FALSE
, /* pc_relative */
958 complain_overflow_unsigned
, /* complain_on_overflow */
959 bfd_elf_generic_reloc
, /* special_function */
960 AARCH64_R_STR (LD64_GOTPAGE_LO15
), /* name */
961 FALSE
, /* partial_inplace */
962 0x7ff8, /* src_mask */
963 0x7ff8, /* dst_mask */
964 FALSE
), /* pcrel_offset */
966 /* Get to the page for the GOT entry for the symbol
967 (G(S) - P) using an ADRP instruction. */
968 HOWTO (AARCH64_R (TLSGD_ADR_PAGE21
), /* type */
970 2, /* size (0 = byte, 1 = short, 2 = long) */
972 TRUE
, /* pc_relative */
974 complain_overflow_dont
, /* complain_on_overflow */
975 bfd_elf_generic_reloc
, /* special_function */
976 AARCH64_R_STR (TLSGD_ADR_PAGE21
), /* name */
977 FALSE
, /* partial_inplace */
978 0x1fffff, /* src_mask */
979 0x1fffff, /* dst_mask */
980 TRUE
), /* pcrel_offset */
982 HOWTO (AARCH64_R (TLSGD_ADR_PREL21
), /* type */
984 2, /* size (0 = byte, 1 = short, 2 = long) */
986 TRUE
, /* pc_relative */
988 complain_overflow_dont
, /* complain_on_overflow */
989 bfd_elf_generic_reloc
, /* special_function */
990 AARCH64_R_STR (TLSGD_ADR_PREL21
), /* name */
991 FALSE
, /* partial_inplace */
992 0x1fffff, /* src_mask */
993 0x1fffff, /* dst_mask */
994 TRUE
), /* pcrel_offset */
996 /* ADD: GOT offset G(S) & 0xff8 [no overflow check] */
997 HOWTO (AARCH64_R (TLSGD_ADD_LO12_NC
), /* type */
999 2, /* size (0 = byte, 1 = short, 2 = long) */
1001 FALSE
, /* pc_relative */
1003 complain_overflow_dont
, /* complain_on_overflow */
1004 bfd_elf_generic_reloc
, /* special_function */
1005 AARCH64_R_STR (TLSGD_ADD_LO12_NC
), /* name */
1006 FALSE
, /* partial_inplace */
1007 0xfff, /* src_mask */
1008 0xfff, /* dst_mask */
1009 FALSE
), /* pcrel_offset */
1011 /* Lower 16 bits of GOT offset to tls_index. */
1012 HOWTO64 (AARCH64_R (TLSGD_MOVW_G0_NC
), /* type */
1014 2, /* size (0 = byte, 1 = short, 2 = long) */
1016 FALSE
, /* pc_relative */
1018 complain_overflow_dont
, /* complain_on_overflow */
1019 bfd_elf_generic_reloc
, /* special_function */
1020 AARCH64_R_STR (TLSGD_MOVW_G0_NC
), /* name */
1021 FALSE
, /* partial_inplace */
1022 0xffff, /* src_mask */
1023 0xffff, /* dst_mask */
1024 FALSE
), /* pcrel_offset */
1026 /* Higher 16 bits of GOT offset to tls_index. */
1027 HOWTO64 (AARCH64_R (TLSGD_MOVW_G1
), /* type */
1028 16, /* rightshift */
1029 2, /* size (0 = byte, 1 = short, 2 = long) */
1031 FALSE
, /* pc_relative */
1033 complain_overflow_unsigned
, /* complain_on_overflow */
1034 bfd_elf_generic_reloc
, /* special_function */
1035 AARCH64_R_STR (TLSGD_MOVW_G1
), /* name */
1036 FALSE
, /* partial_inplace */
1037 0xffff, /* src_mask */
1038 0xffff, /* dst_mask */
1039 FALSE
), /* pcrel_offset */
1041 HOWTO (AARCH64_R (TLSIE_ADR_GOTTPREL_PAGE21
), /* type */
1042 12, /* rightshift */
1043 2, /* size (0 = byte, 1 = short, 2 = long) */
1045 FALSE
, /* pc_relative */
1047 complain_overflow_dont
, /* complain_on_overflow */
1048 bfd_elf_generic_reloc
, /* special_function */
1049 AARCH64_R_STR (TLSIE_ADR_GOTTPREL_PAGE21
), /* name */
1050 FALSE
, /* partial_inplace */
1051 0x1fffff, /* src_mask */
1052 0x1fffff, /* dst_mask */
1053 FALSE
), /* pcrel_offset */
1055 HOWTO64 (AARCH64_R (TLSIE_LD64_GOTTPREL_LO12_NC
), /* type */
1057 2, /* size (0 = byte, 1 = short, 2 = long) */
1059 FALSE
, /* pc_relative */
1061 complain_overflow_dont
, /* complain_on_overflow */
1062 bfd_elf_generic_reloc
, /* special_function */
1063 AARCH64_R_STR (TLSIE_LD64_GOTTPREL_LO12_NC
), /* name */
1064 FALSE
, /* partial_inplace */
1065 0xff8, /* src_mask */
1066 0xff8, /* dst_mask */
1067 FALSE
), /* pcrel_offset */
1069 HOWTO32 (AARCH64_R (TLSIE_LD32_GOTTPREL_LO12_NC
), /* type */
1071 2, /* size (0 = byte, 1 = short, 2 = long) */
1073 FALSE
, /* pc_relative */
1075 complain_overflow_dont
, /* complain_on_overflow */
1076 bfd_elf_generic_reloc
, /* special_function */
1077 AARCH64_R_STR (TLSIE_LD32_GOTTPREL_LO12_NC
), /* name */
1078 FALSE
, /* partial_inplace */
1079 0xffc, /* src_mask */
1080 0xffc, /* dst_mask */
1081 FALSE
), /* pcrel_offset */
1083 HOWTO (AARCH64_R (TLSIE_LD_GOTTPREL_PREL19
), /* type */
1085 2, /* size (0 = byte, 1 = short, 2 = long) */
1087 FALSE
, /* pc_relative */
1089 complain_overflow_dont
, /* complain_on_overflow */
1090 bfd_elf_generic_reloc
, /* special_function */
1091 AARCH64_R_STR (TLSIE_LD_GOTTPREL_PREL19
), /* name */
1092 FALSE
, /* partial_inplace */
1093 0x1ffffc, /* src_mask */
1094 0x1ffffc, /* dst_mask */
1095 FALSE
), /* pcrel_offset */
1097 HOWTO64 (AARCH64_R (TLSIE_MOVW_GOTTPREL_G0_NC
), /* type */
1099 2, /* size (0 = byte, 1 = short, 2 = long) */
1101 FALSE
, /* pc_relative */
1103 complain_overflow_dont
, /* complain_on_overflow */
1104 bfd_elf_generic_reloc
, /* special_function */
1105 AARCH64_R_STR (TLSIE_MOVW_GOTTPREL_G0_NC
), /* name */
1106 FALSE
, /* partial_inplace */
1107 0xffff, /* src_mask */
1108 0xffff, /* dst_mask */
1109 FALSE
), /* pcrel_offset */
1111 HOWTO64 (AARCH64_R (TLSIE_MOVW_GOTTPREL_G1
), /* type */
1112 16, /* rightshift */
1113 2, /* size (0 = byte, 1 = short, 2 = long) */
1115 FALSE
, /* pc_relative */
1117 complain_overflow_unsigned
, /* complain_on_overflow */
1118 bfd_elf_generic_reloc
, /* special_function */
1119 AARCH64_R_STR (TLSIE_MOVW_GOTTPREL_G1
), /* name */
1120 FALSE
, /* partial_inplace */
1121 0xffff, /* src_mask */
1122 0xffff, /* dst_mask */
1123 FALSE
), /* pcrel_offset */
1125 /* ADD: bit[23:12] of byte offset to module TLS base address. */
1126 HOWTO (AARCH64_R (TLSLD_ADD_DTPREL_HI12
), /* type */
1127 12, /* rightshift */
1128 2, /* size (0 = byte, 1 = short, 2 = long) */
1130 FALSE
, /* pc_relative */
1132 complain_overflow_unsigned
, /* complain_on_overflow */
1133 bfd_elf_generic_reloc
, /* special_function */
1134 AARCH64_R_STR (TLSLD_ADD_DTPREL_HI12
), /* name */
1135 FALSE
, /* partial_inplace */
1136 0xfff, /* src_mask */
1137 0xfff, /* dst_mask */
1138 FALSE
), /* pcrel_offset */
1140 /* Unsigned 12 bit byte offset to module TLS base address. */
1141 HOWTO (AARCH64_R (TLSLD_ADD_DTPREL_LO12
), /* type */
1143 2, /* size (0 = byte, 1 = short, 2 = long) */
1145 FALSE
, /* pc_relative */
1147 complain_overflow_unsigned
, /* complain_on_overflow */
1148 bfd_elf_generic_reloc
, /* special_function */
1149 AARCH64_R_STR (TLSLD_ADD_DTPREL_LO12
), /* name */
1150 FALSE
, /* partial_inplace */
1151 0xfff, /* src_mask */
1152 0xfff, /* dst_mask */
1153 FALSE
), /* pcrel_offset */
1155 /* No overflow check version of BFD_RELOC_AARCH64_TLSLD_ADD_DTPREL_LO12. */
1156 HOWTO (AARCH64_R (TLSLD_ADD_DTPREL_LO12_NC
), /* type */
1158 2, /* size (0 = byte, 1 = short, 2 = long) */
1160 FALSE
, /* pc_relative */
1162 complain_overflow_dont
, /* complain_on_overflow */
1163 bfd_elf_generic_reloc
, /* special_function */
1164 AARCH64_R_STR (TLSLD_ADD_DTPREL_LO12_NC
), /* name */
1165 FALSE
, /* partial_inplace */
1166 0xfff, /* src_mask */
1167 0xfff, /* dst_mask */
1168 FALSE
), /* pcrel_offset */
1170 /* ADD: GOT offset G(S) & 0xff8 [no overflow check] */
1171 HOWTO (AARCH64_R (TLSLD_ADD_LO12_NC
), /* type */
1173 2, /* size (0 = byte, 1 = short, 2 = long) */
1175 FALSE
, /* pc_relative */
1177 complain_overflow_dont
, /* complain_on_overflow */
1178 bfd_elf_generic_reloc
, /* special_function */
1179 AARCH64_R_STR (TLSLD_ADD_LO12_NC
), /* name */
1180 FALSE
, /* partial_inplace */
1181 0xfff, /* src_mask */
1182 0xfff, /* dst_mask */
1183 FALSE
), /* pcrel_offset */
1185 /* Get to the page for the GOT entry for the symbol
1186 (G(S) - P) using an ADRP instruction. */
1187 HOWTO (AARCH64_R (TLSLD_ADR_PAGE21
), /* type */
1188 12, /* rightshift */
1189 2, /* size (0 = byte, 1 = short, 2 = long) */
1191 TRUE
, /* pc_relative */
1193 complain_overflow_signed
, /* complain_on_overflow */
1194 bfd_elf_generic_reloc
, /* special_function */
1195 AARCH64_R_STR (TLSLD_ADR_PAGE21
), /* name */
1196 FALSE
, /* partial_inplace */
1197 0x1fffff, /* src_mask */
1198 0x1fffff, /* dst_mask */
1199 TRUE
), /* pcrel_offset */
1201 HOWTO (AARCH64_R (TLSLD_ADR_PREL21
), /* type */
1203 2, /* size (0 = byte, 1 = short, 2 = long) */
1205 TRUE
, /* pc_relative */
1207 complain_overflow_signed
, /* complain_on_overflow */
1208 bfd_elf_generic_reloc
, /* special_function */
1209 AARCH64_R_STR (TLSLD_ADR_PREL21
), /* name */
1210 FALSE
, /* partial_inplace */
1211 0x1fffff, /* src_mask */
1212 0x1fffff, /* dst_mask */
1213 TRUE
), /* pcrel_offset */
1215 /* LD/ST16: bit[11:1] of byte offset to module TLS base address. */
1216 HOWTO64 (AARCH64_R (TLSLD_LDST16_DTPREL_LO12
), /* type */
1218 2, /* size (0 = byte, 1 = short, 2 = long) */
1220 FALSE
, /* pc_relative */
1222 complain_overflow_unsigned
, /* complain_on_overflow */
1223 bfd_elf_generic_reloc
, /* special_function */
1224 AARCH64_R_STR (TLSLD_LDST16_DTPREL_LO12
), /* name */
1225 FALSE
, /* partial_inplace */
1226 0x1ffc00, /* src_mask */
1227 0x1ffc00, /* dst_mask */
1228 FALSE
), /* pcrel_offset */
1230 /* Same as BFD_RELOC_AARCH64_TLSLD_LDST16_DTPREL_LO12, but no overflow check. */
1231 HOWTO64 (AARCH64_R (TLSLD_LDST16_DTPREL_LO12_NC
), /* type */
1233 2, /* size (0 = byte, 1 = short, 2 = long) */
1235 FALSE
, /* pc_relative */
1237 complain_overflow_dont
, /* complain_on_overflow */
1238 bfd_elf_generic_reloc
, /* special_function */
1239 AARCH64_R_STR (TLSLD_LDST16_DTPREL_LO12_NC
), /* name */
1240 FALSE
, /* partial_inplace */
1241 0x1ffc00, /* src_mask */
1242 0x1ffc00, /* dst_mask */
1243 FALSE
), /* pcrel_offset */
1245 /* LD/ST32: bit[11:2] of byte offset to module TLS base address. */
1246 HOWTO64 (AARCH64_R (TLSLD_LDST32_DTPREL_LO12
), /* type */
1248 2, /* size (0 = byte, 1 = short, 2 = long) */
1250 FALSE
, /* pc_relative */
1252 complain_overflow_unsigned
, /* complain_on_overflow */
1253 bfd_elf_generic_reloc
, /* special_function */
1254 AARCH64_R_STR (TLSLD_LDST32_DTPREL_LO12
), /* name */
1255 FALSE
, /* partial_inplace */
1256 0x3ffc00, /* src_mask */
1257 0x3ffc00, /* dst_mask */
1258 FALSE
), /* pcrel_offset */
1260 /* Same as BFD_RELOC_AARCH64_TLSLD_LDST32_DTPREL_LO12, but no overflow check. */
1261 HOWTO64 (AARCH64_R (TLSLD_LDST32_DTPREL_LO12_NC
), /* type */
1263 2, /* size (0 = byte, 1 = short, 2 = long) */
1265 FALSE
, /* pc_relative */
1267 complain_overflow_dont
, /* complain_on_overflow */
1268 bfd_elf_generic_reloc
, /* special_function */
1269 AARCH64_R_STR (TLSLD_LDST32_DTPREL_LO12_NC
), /* name */
1270 FALSE
, /* partial_inplace */
1271 0xffc00, /* src_mask */
1272 0xffc00, /* dst_mask */
1273 FALSE
), /* pcrel_offset */
1275 /* LD/ST64: bit[11:3] of byte offset to module TLS base address. */
1276 HOWTO64 (AARCH64_R (TLSLD_LDST64_DTPREL_LO12
), /* type */
1278 2, /* size (0 = byte, 1 = short, 2 = long) */
1280 FALSE
, /* pc_relative */
1282 complain_overflow_unsigned
, /* complain_on_overflow */
1283 bfd_elf_generic_reloc
, /* special_function */
1284 AARCH64_R_STR (TLSLD_LDST64_DTPREL_LO12
), /* name */
1285 FALSE
, /* partial_inplace */
1286 0x3ffc00, /* src_mask */
1287 0x3ffc00, /* dst_mask */
1288 FALSE
), /* pcrel_offset */
1290 /* Same as BFD_RELOC_AARCH64_TLSLD_LDST64_DTPREL_LO12, but no overflow check. */
1291 HOWTO64 (AARCH64_R (TLSLD_LDST64_DTPREL_LO12_NC
), /* type */
1293 2, /* size (0 = byte, 1 = short, 2 = long) */
1295 FALSE
, /* pc_relative */
1297 complain_overflow_dont
, /* complain_on_overflow */
1298 bfd_elf_generic_reloc
, /* special_function */
1299 AARCH64_R_STR (TLSLD_LDST64_DTPREL_LO12_NC
), /* name */
1300 FALSE
, /* partial_inplace */
1301 0x7fc00, /* src_mask */
1302 0x7fc00, /* dst_mask */
1303 FALSE
), /* pcrel_offset */
1305 /* LD/ST8: bit[11:0] of byte offset to module TLS base address. */
1306 HOWTO64 (AARCH64_R (TLSLD_LDST8_DTPREL_LO12
), /* type */
1308 2, /* size (0 = byte, 1 = short, 2 = long) */
1310 FALSE
, /* pc_relative */
1312 complain_overflow_unsigned
, /* complain_on_overflow */
1313 bfd_elf_generic_reloc
, /* special_function */
1314 AARCH64_R_STR (TLSLD_LDST8_DTPREL_LO12
), /* name */
1315 FALSE
, /* partial_inplace */
1316 0x3ffc00, /* src_mask */
1317 0x3ffc00, /* dst_mask */
1318 FALSE
), /* pcrel_offset */
1320 /* Same as BFD_RELOC_AARCH64_TLSLD_LDST8_DTPREL_LO12, but no overflow check. */
1321 HOWTO64 (AARCH64_R (TLSLD_LDST8_DTPREL_LO12_NC
), /* type */
1323 2, /* size (0 = byte, 1 = short, 2 = long) */
1325 FALSE
, /* pc_relative */
1327 complain_overflow_dont
, /* complain_on_overflow */
1328 bfd_elf_generic_reloc
, /* special_function */
1329 AARCH64_R_STR (TLSLD_LDST8_DTPREL_LO12_NC
), /* name */
1330 FALSE
, /* partial_inplace */
1331 0x3ffc00, /* src_mask */
1332 0x3ffc00, /* dst_mask */
1333 FALSE
), /* pcrel_offset */
1335 /* MOVZ: bit[15:0] of byte offset to module TLS base address. */
1336 HOWTO (AARCH64_R (TLSLD_MOVW_DTPREL_G0
), /* type */
1338 2, /* size (0 = byte, 1 = short, 2 = long) */
1340 FALSE
, /* pc_relative */
1342 complain_overflow_unsigned
, /* complain_on_overflow */
1343 bfd_elf_generic_reloc
, /* special_function */
1344 AARCH64_R_STR (TLSLD_MOVW_DTPREL_G0
), /* name */
1345 FALSE
, /* partial_inplace */
1346 0xffff, /* src_mask */
1347 0xffff, /* dst_mask */
1348 FALSE
), /* pcrel_offset */
1350 /* No overflow check version of BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G0. */
1351 HOWTO (AARCH64_R (TLSLD_MOVW_DTPREL_G0_NC
), /* type */
1353 2, /* size (0 = byte, 1 = short, 2 = long) */
1355 FALSE
, /* pc_relative */
1357 complain_overflow_dont
, /* complain_on_overflow */
1358 bfd_elf_generic_reloc
, /* special_function */
1359 AARCH64_R_STR (TLSLD_MOVW_DTPREL_G0_NC
), /* name */
1360 FALSE
, /* partial_inplace */
1361 0xffff, /* src_mask */
1362 0xffff, /* dst_mask */
1363 FALSE
), /* pcrel_offset */
1365 /* MOVZ: bit[31:16] of byte offset to module TLS base address. */
1366 HOWTO (AARCH64_R (TLSLD_MOVW_DTPREL_G1
), /* type */
1367 16, /* rightshift */
1368 2, /* size (0 = byte, 1 = short, 2 = long) */
1370 FALSE
, /* pc_relative */
1372 complain_overflow_unsigned
, /* complain_on_overflow */
1373 bfd_elf_generic_reloc
, /* special_function */
1374 AARCH64_R_STR (TLSLD_MOVW_DTPREL_G1
), /* name */
1375 FALSE
, /* partial_inplace */
1376 0xffff, /* src_mask */
1377 0xffff, /* dst_mask */
1378 FALSE
), /* pcrel_offset */
1380 /* No overflow check version of BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G1. */
1381 HOWTO64 (AARCH64_R (TLSLD_MOVW_DTPREL_G1_NC
), /* type */
1382 16, /* rightshift */
1383 2, /* size (0 = byte, 1 = short, 2 = long) */
1385 FALSE
, /* pc_relative */
1387 complain_overflow_dont
, /* complain_on_overflow */
1388 bfd_elf_generic_reloc
, /* special_function */
1389 AARCH64_R_STR (TLSLD_MOVW_DTPREL_G1_NC
), /* name */
1390 FALSE
, /* partial_inplace */
1391 0xffff, /* src_mask */
1392 0xffff, /* dst_mask */
1393 FALSE
), /* pcrel_offset */
1395 /* MOVZ: bit[47:32] of byte offset to module TLS base address. */
1396 HOWTO64 (AARCH64_R (TLSLD_MOVW_DTPREL_G2
), /* type */
1397 32, /* rightshift */
1398 2, /* size (0 = byte, 1 = short, 2 = long) */
1400 FALSE
, /* pc_relative */
1402 complain_overflow_unsigned
, /* complain_on_overflow */
1403 bfd_elf_generic_reloc
, /* special_function */
1404 AARCH64_R_STR (TLSLD_MOVW_DTPREL_G2
), /* name */
1405 FALSE
, /* partial_inplace */
1406 0xffff, /* src_mask */
1407 0xffff, /* dst_mask */
1408 FALSE
), /* pcrel_offset */
1410 HOWTO64 (AARCH64_R (TLSLE_MOVW_TPREL_G2
), /* type */
1411 32, /* rightshift */
1412 2, /* size (0 = byte, 1 = short, 2 = long) */
1414 FALSE
, /* pc_relative */
1416 complain_overflow_unsigned
, /* complain_on_overflow */
1417 bfd_elf_generic_reloc
, /* special_function */
1418 AARCH64_R_STR (TLSLE_MOVW_TPREL_G2
), /* name */
1419 FALSE
, /* partial_inplace */
1420 0xffff, /* src_mask */
1421 0xffff, /* dst_mask */
1422 FALSE
), /* pcrel_offset */
1424 HOWTO (AARCH64_R (TLSLE_MOVW_TPREL_G1
), /* type */
1425 16, /* rightshift */
1426 2, /* size (0 = byte, 1 = short, 2 = long) */
1428 FALSE
, /* pc_relative */
1430 complain_overflow_dont
, /* complain_on_overflow */
1431 bfd_elf_generic_reloc
, /* special_function */
1432 AARCH64_R_STR (TLSLE_MOVW_TPREL_G1
), /* name */
1433 FALSE
, /* partial_inplace */
1434 0xffff, /* src_mask */
1435 0xffff, /* dst_mask */
1436 FALSE
), /* pcrel_offset */
1438 HOWTO64 (AARCH64_R (TLSLE_MOVW_TPREL_G1_NC
), /* type */
1439 16, /* rightshift */
1440 2, /* size (0 = byte, 1 = short, 2 = long) */
1442 FALSE
, /* pc_relative */
1444 complain_overflow_dont
, /* complain_on_overflow */
1445 bfd_elf_generic_reloc
, /* special_function */
1446 AARCH64_R_STR (TLSLE_MOVW_TPREL_G1_NC
), /* name */
1447 FALSE
, /* partial_inplace */
1448 0xffff, /* src_mask */
1449 0xffff, /* dst_mask */
1450 FALSE
), /* pcrel_offset */
1452 HOWTO (AARCH64_R (TLSLE_MOVW_TPREL_G0
), /* type */
1454 2, /* size (0 = byte, 1 = short, 2 = long) */
1456 FALSE
, /* pc_relative */
1458 complain_overflow_dont
, /* complain_on_overflow */
1459 bfd_elf_generic_reloc
, /* special_function */
1460 AARCH64_R_STR (TLSLE_MOVW_TPREL_G0
), /* name */
1461 FALSE
, /* partial_inplace */
1462 0xffff, /* src_mask */
1463 0xffff, /* dst_mask */
1464 FALSE
), /* pcrel_offset */
1466 HOWTO (AARCH64_R (TLSLE_MOVW_TPREL_G0_NC
), /* type */
1468 2, /* size (0 = byte, 1 = short, 2 = long) */
1470 FALSE
, /* pc_relative */
1472 complain_overflow_dont
, /* complain_on_overflow */
1473 bfd_elf_generic_reloc
, /* special_function */
1474 AARCH64_R_STR (TLSLE_MOVW_TPREL_G0_NC
), /* name */
1475 FALSE
, /* partial_inplace */
1476 0xffff, /* src_mask */
1477 0xffff, /* dst_mask */
1478 FALSE
), /* pcrel_offset */
1480 HOWTO (AARCH64_R (TLSLE_ADD_TPREL_HI12
), /* type */
1481 12, /* rightshift */
1482 2, /* size (0 = byte, 1 = short, 2 = long) */
1484 FALSE
, /* pc_relative */
1486 complain_overflow_unsigned
, /* complain_on_overflow */
1487 bfd_elf_generic_reloc
, /* special_function */
1488 AARCH64_R_STR (TLSLE_ADD_TPREL_HI12
), /* name */
1489 FALSE
, /* partial_inplace */
1490 0xfff, /* src_mask */
1491 0xfff, /* dst_mask */
1492 FALSE
), /* pcrel_offset */
1494 HOWTO (AARCH64_R (TLSLE_ADD_TPREL_LO12
), /* type */
1496 2, /* size (0 = byte, 1 = short, 2 = long) */
1498 FALSE
, /* pc_relative */
1500 complain_overflow_unsigned
, /* complain_on_overflow */
1501 bfd_elf_generic_reloc
, /* special_function */
1502 AARCH64_R_STR (TLSLE_ADD_TPREL_LO12
), /* name */
1503 FALSE
, /* partial_inplace */
1504 0xfff, /* src_mask */
1505 0xfff, /* dst_mask */
1506 FALSE
), /* pcrel_offset */
1508 HOWTO (AARCH64_R (TLSLE_ADD_TPREL_LO12_NC
), /* type */
1510 2, /* size (0 = byte, 1 = short, 2 = long) */
1512 FALSE
, /* pc_relative */
1514 complain_overflow_dont
, /* complain_on_overflow */
1515 bfd_elf_generic_reloc
, /* special_function */
1516 AARCH64_R_STR (TLSLE_ADD_TPREL_LO12_NC
), /* name */
1517 FALSE
, /* partial_inplace */
1518 0xfff, /* src_mask */
1519 0xfff, /* dst_mask */
1520 FALSE
), /* pcrel_offset */
1522 HOWTO (AARCH64_R (TLSDESC_LD_PREL19
), /* type */
1524 2, /* size (0 = byte, 1 = short, 2 = long) */
1526 TRUE
, /* pc_relative */
1528 complain_overflow_dont
, /* complain_on_overflow */
1529 bfd_elf_generic_reloc
, /* special_function */
1530 AARCH64_R_STR (TLSDESC_LD_PREL19
), /* name */
1531 FALSE
, /* partial_inplace */
1532 0x0ffffe0, /* src_mask */
1533 0x0ffffe0, /* dst_mask */
1534 TRUE
), /* pcrel_offset */
1536 HOWTO (AARCH64_R (TLSDESC_ADR_PREL21
), /* type */
1538 2, /* size (0 = byte, 1 = short, 2 = long) */
1540 TRUE
, /* pc_relative */
1542 complain_overflow_dont
, /* complain_on_overflow */
1543 bfd_elf_generic_reloc
, /* special_function */
1544 AARCH64_R_STR (TLSDESC_ADR_PREL21
), /* name */
1545 FALSE
, /* partial_inplace */
1546 0x1fffff, /* src_mask */
1547 0x1fffff, /* dst_mask */
1548 TRUE
), /* pcrel_offset */
1550 /* Get to the page for the GOT entry for the symbol
1551 (G(S) - P) using an ADRP instruction. */
1552 HOWTO (AARCH64_R (TLSDESC_ADR_PAGE21
), /* type */
1553 12, /* rightshift */
1554 2, /* size (0 = byte, 1 = short, 2 = long) */
1556 TRUE
, /* pc_relative */
1558 complain_overflow_dont
, /* complain_on_overflow */
1559 bfd_elf_generic_reloc
, /* special_function */
1560 AARCH64_R_STR (TLSDESC_ADR_PAGE21
), /* name */
1561 FALSE
, /* partial_inplace */
1562 0x1fffff, /* src_mask */
1563 0x1fffff, /* dst_mask */
1564 TRUE
), /* pcrel_offset */
1566 /* LD64: GOT offset G(S) & 0xff8. */
1567 HOWTO64 (AARCH64_R (TLSDESC_LD64_LO12_NC
), /* type */
1569 2, /* size (0 = byte, 1 = short, 2 = long) */
1571 FALSE
, /* pc_relative */
1573 complain_overflow_dont
, /* complain_on_overflow */
1574 bfd_elf_generic_reloc
, /* special_function */
1575 AARCH64_R_STR (TLSDESC_LD64_LO12_NC
), /* name */
1576 FALSE
, /* partial_inplace */
1577 0xff8, /* src_mask */
1578 0xff8, /* dst_mask */
1579 FALSE
), /* pcrel_offset */
1581 /* LD32: GOT offset G(S) & 0xffc. */
1582 HOWTO32 (AARCH64_R (TLSDESC_LD32_LO12_NC
), /* type */
1584 2, /* size (0 = byte, 1 = short, 2 = long) */
1586 FALSE
, /* pc_relative */
1588 complain_overflow_dont
, /* complain_on_overflow */
1589 bfd_elf_generic_reloc
, /* special_function */
1590 AARCH64_R_STR (TLSDESC_LD32_LO12_NC
), /* name */
1591 FALSE
, /* partial_inplace */
1592 0xffc, /* src_mask */
1593 0xffc, /* dst_mask */
1594 FALSE
), /* pcrel_offset */
1596 /* ADD: GOT offset G(S) & 0xfff. */
1597 HOWTO (AARCH64_R (TLSDESC_ADD_LO12_NC
), /* type */
1599 2, /* size (0 = byte, 1 = short, 2 = long) */
1601 FALSE
, /* pc_relative */
1603 complain_overflow_dont
, /* complain_on_overflow */
1604 bfd_elf_generic_reloc
, /* special_function */
1605 AARCH64_R_STR (TLSDESC_ADD_LO12_NC
), /* name */
1606 FALSE
, /* partial_inplace */
1607 0xfff, /* src_mask */
1608 0xfff, /* dst_mask */
1609 FALSE
), /* pcrel_offset */
1611 HOWTO64 (AARCH64_R (TLSDESC_OFF_G1
), /* type */
1612 16, /* rightshift */
1613 2, /* size (0 = byte, 1 = short, 2 = long) */
1615 FALSE
, /* pc_relative */
1617 complain_overflow_dont
, /* complain_on_overflow */
1618 bfd_elf_generic_reloc
, /* special_function */
1619 AARCH64_R_STR (TLSDESC_OFF_G1
), /* name */
1620 FALSE
, /* partial_inplace */
1621 0xffff, /* src_mask */
1622 0xffff, /* dst_mask */
1623 FALSE
), /* pcrel_offset */
1625 HOWTO64 (AARCH64_R (TLSDESC_OFF_G0_NC
), /* type */
1627 2, /* size (0 = byte, 1 = short, 2 = long) */
1629 FALSE
, /* pc_relative */
1631 complain_overflow_dont
, /* complain_on_overflow */
1632 bfd_elf_generic_reloc
, /* special_function */
1633 AARCH64_R_STR (TLSDESC_OFF_G0_NC
), /* name */
1634 FALSE
, /* partial_inplace */
1635 0xffff, /* src_mask */
1636 0xffff, /* dst_mask */
1637 FALSE
), /* pcrel_offset */
1639 HOWTO64 (AARCH64_R (TLSDESC_LDR
), /* type */
1641 2, /* size (0 = byte, 1 = short, 2 = long) */
1643 FALSE
, /* pc_relative */
1645 complain_overflow_dont
, /* complain_on_overflow */
1646 bfd_elf_generic_reloc
, /* special_function */
1647 AARCH64_R_STR (TLSDESC_LDR
), /* name */
1648 FALSE
, /* partial_inplace */
1651 FALSE
), /* pcrel_offset */
1653 HOWTO64 (AARCH64_R (TLSDESC_ADD
), /* type */
1655 2, /* size (0 = byte, 1 = short, 2 = long) */
1657 FALSE
, /* pc_relative */
1659 complain_overflow_dont
, /* complain_on_overflow */
1660 bfd_elf_generic_reloc
, /* special_function */
1661 AARCH64_R_STR (TLSDESC_ADD
), /* name */
1662 FALSE
, /* partial_inplace */
1665 FALSE
), /* pcrel_offset */
1667 HOWTO (AARCH64_R (TLSDESC_CALL
), /* type */
1669 2, /* size (0 = byte, 1 = short, 2 = long) */
1671 FALSE
, /* pc_relative */
1673 complain_overflow_dont
, /* complain_on_overflow */
1674 bfd_elf_generic_reloc
, /* special_function */
1675 AARCH64_R_STR (TLSDESC_CALL
), /* name */
1676 FALSE
, /* partial_inplace */
1679 FALSE
), /* pcrel_offset */
1681 HOWTO (AARCH64_R (COPY
), /* type */
1683 2, /* size (0 = byte, 1 = short, 2 = long) */
1685 FALSE
, /* pc_relative */
1687 complain_overflow_bitfield
, /* complain_on_overflow */
1688 bfd_elf_generic_reloc
, /* special_function */
1689 AARCH64_R_STR (COPY
), /* name */
1690 TRUE
, /* partial_inplace */
1691 0xffffffff, /* src_mask */
1692 0xffffffff, /* dst_mask */
1693 FALSE
), /* pcrel_offset */
1695 HOWTO (AARCH64_R (GLOB_DAT
), /* type */
1697 2, /* size (0 = byte, 1 = short, 2 = long) */
1699 FALSE
, /* pc_relative */
1701 complain_overflow_bitfield
, /* complain_on_overflow */
1702 bfd_elf_generic_reloc
, /* special_function */
1703 AARCH64_R_STR (GLOB_DAT
), /* name */
1704 TRUE
, /* partial_inplace */
1705 0xffffffff, /* src_mask */
1706 0xffffffff, /* dst_mask */
1707 FALSE
), /* pcrel_offset */
1709 HOWTO (AARCH64_R (JUMP_SLOT
), /* type */
1711 2, /* size (0 = byte, 1 = short, 2 = long) */
1713 FALSE
, /* pc_relative */
1715 complain_overflow_bitfield
, /* complain_on_overflow */
1716 bfd_elf_generic_reloc
, /* special_function */
1717 AARCH64_R_STR (JUMP_SLOT
), /* name */
1718 TRUE
, /* partial_inplace */
1719 0xffffffff, /* src_mask */
1720 0xffffffff, /* dst_mask */
1721 FALSE
), /* pcrel_offset */
1723 HOWTO (AARCH64_R (RELATIVE
), /* type */
1725 2, /* size (0 = byte, 1 = short, 2 = long) */
1727 FALSE
, /* pc_relative */
1729 complain_overflow_bitfield
, /* complain_on_overflow */
1730 bfd_elf_generic_reloc
, /* special_function */
1731 AARCH64_R_STR (RELATIVE
), /* name */
1732 TRUE
, /* partial_inplace */
1733 ALL_ONES
, /* src_mask */
1734 ALL_ONES
, /* dst_mask */
1735 FALSE
), /* pcrel_offset */
1737 HOWTO (AARCH64_R (TLS_DTPMOD
), /* type */
1739 2, /* size (0 = byte, 1 = short, 2 = long) */
1741 FALSE
, /* pc_relative */
1743 complain_overflow_dont
, /* complain_on_overflow */
1744 bfd_elf_generic_reloc
, /* special_function */
1746 AARCH64_R_STR (TLS_DTPMOD64
), /* name */
1748 AARCH64_R_STR (TLS_DTPMOD
), /* name */
1750 FALSE
, /* partial_inplace */
1752 ALL_ONES
, /* dst_mask */
1753 FALSE
), /* pc_reloffset */
1755 HOWTO (AARCH64_R (TLS_DTPREL
), /* type */
1757 2, /* size (0 = byte, 1 = short, 2 = long) */
1759 FALSE
, /* pc_relative */
1761 complain_overflow_dont
, /* complain_on_overflow */
1762 bfd_elf_generic_reloc
, /* special_function */
1764 AARCH64_R_STR (TLS_DTPREL64
), /* name */
1766 AARCH64_R_STR (TLS_DTPREL
), /* name */
1768 FALSE
, /* partial_inplace */
1770 ALL_ONES
, /* dst_mask */
1771 FALSE
), /* pcrel_offset */
1773 HOWTO (AARCH64_R (TLS_TPREL
), /* type */
1775 2, /* size (0 = byte, 1 = short, 2 = long) */
1777 FALSE
, /* pc_relative */
1779 complain_overflow_dont
, /* complain_on_overflow */
1780 bfd_elf_generic_reloc
, /* special_function */
1782 AARCH64_R_STR (TLS_TPREL64
), /* name */
1784 AARCH64_R_STR (TLS_TPREL
), /* name */
1786 FALSE
, /* partial_inplace */
1788 ALL_ONES
, /* dst_mask */
1789 FALSE
), /* pcrel_offset */
1791 HOWTO (AARCH64_R (TLSDESC
), /* type */
1793 2, /* size (0 = byte, 1 = short, 2 = long) */
1795 FALSE
, /* pc_relative */
1797 complain_overflow_dont
, /* complain_on_overflow */
1798 bfd_elf_generic_reloc
, /* special_function */
1799 AARCH64_R_STR (TLSDESC
), /* name */
1800 FALSE
, /* partial_inplace */
1802 ALL_ONES
, /* dst_mask */
1803 FALSE
), /* pcrel_offset */
1805 HOWTO (AARCH64_R (IRELATIVE
), /* type */
1807 2, /* size (0 = byte, 1 = short, 2 = long) */
1809 FALSE
, /* pc_relative */
1811 complain_overflow_bitfield
, /* complain_on_overflow */
1812 bfd_elf_generic_reloc
, /* special_function */
1813 AARCH64_R_STR (IRELATIVE
), /* name */
1814 FALSE
, /* partial_inplace */
1816 ALL_ONES
, /* dst_mask */
1817 FALSE
), /* pcrel_offset */
1822 static reloc_howto_type elfNN_aarch64_howto_none
=
1823 HOWTO (R_AARCH64_NONE
, /* type */
1825 3, /* size (0 = byte, 1 = short, 2 = long) */
1827 FALSE
, /* pc_relative */
1829 complain_overflow_dont
,/* complain_on_overflow */
1830 bfd_elf_generic_reloc
, /* special_function */
1831 "R_AARCH64_NONE", /* name */
1832 FALSE
, /* partial_inplace */
1835 FALSE
); /* pcrel_offset */
1837 /* Given HOWTO, return the bfd internal relocation enumerator. */
1839 static bfd_reloc_code_real_type
1840 elfNN_aarch64_bfd_reloc_from_howto (reloc_howto_type
*howto
)
1843 = (int) ARRAY_SIZE (elfNN_aarch64_howto_table
);
1844 const ptrdiff_t offset
1845 = howto
- elfNN_aarch64_howto_table
;
1847 if (offset
> 0 && offset
< size
- 1)
1848 return BFD_RELOC_AARCH64_RELOC_START
+ offset
;
1850 if (howto
== &elfNN_aarch64_howto_none
)
1851 return BFD_RELOC_AARCH64_NONE
;
1853 return BFD_RELOC_AARCH64_RELOC_START
;
1856 /* Given R_TYPE, return the bfd internal relocation enumerator. */
1858 static bfd_reloc_code_real_type
1859 elfNN_aarch64_bfd_reloc_from_type (unsigned int r_type
)
1861 static bfd_boolean initialized_p
= FALSE
;
1862 /* Indexed by R_TYPE, values are offsets in the howto_table. */
1863 static unsigned int offsets
[R_AARCH64_end
];
1865 if (initialized_p
== FALSE
)
1869 for (i
= 1; i
< ARRAY_SIZE (elfNN_aarch64_howto_table
) - 1; ++i
)
1870 if (elfNN_aarch64_howto_table
[i
].type
!= 0)
1871 offsets
[elfNN_aarch64_howto_table
[i
].type
] = i
;
1873 initialized_p
= TRUE
;
1876 if (r_type
== R_AARCH64_NONE
|| r_type
== R_AARCH64_NULL
)
1877 return BFD_RELOC_AARCH64_NONE
;
1879 /* PR 17512: file: b371e70a. */
1880 if (r_type
>= R_AARCH64_end
)
1882 _bfd_error_handler (_("Invalid AArch64 reloc number: %d"), r_type
);
1883 bfd_set_error (bfd_error_bad_value
);
1884 return BFD_RELOC_AARCH64_NONE
;
1887 return BFD_RELOC_AARCH64_RELOC_START
+ offsets
[r_type
];
1890 struct elf_aarch64_reloc_map
1892 bfd_reloc_code_real_type from
;
1893 bfd_reloc_code_real_type to
;
1896 /* Map bfd generic reloc to AArch64-specific reloc. */
1897 static const struct elf_aarch64_reloc_map elf_aarch64_reloc_map
[] =
1899 {BFD_RELOC_NONE
, BFD_RELOC_AARCH64_NONE
},
1901 /* Basic data relocations. */
1902 {BFD_RELOC_CTOR
, BFD_RELOC_AARCH64_NN
},
1903 {BFD_RELOC_64
, BFD_RELOC_AARCH64_64
},
1904 {BFD_RELOC_32
, BFD_RELOC_AARCH64_32
},
1905 {BFD_RELOC_16
, BFD_RELOC_AARCH64_16
},
1906 {BFD_RELOC_64_PCREL
, BFD_RELOC_AARCH64_64_PCREL
},
1907 {BFD_RELOC_32_PCREL
, BFD_RELOC_AARCH64_32_PCREL
},
1908 {BFD_RELOC_16_PCREL
, BFD_RELOC_AARCH64_16_PCREL
},
1911 /* Given the bfd internal relocation enumerator in CODE, return the
1912 corresponding howto entry. */
1914 static reloc_howto_type
*
1915 elfNN_aarch64_howto_from_bfd_reloc (bfd_reloc_code_real_type code
)
1919 /* Convert bfd generic reloc to AArch64-specific reloc. */
1920 if (code
< BFD_RELOC_AARCH64_RELOC_START
1921 || code
> BFD_RELOC_AARCH64_RELOC_END
)
1922 for (i
= 0; i
< ARRAY_SIZE (elf_aarch64_reloc_map
); i
++)
1923 if (elf_aarch64_reloc_map
[i
].from
== code
)
1925 code
= elf_aarch64_reloc_map
[i
].to
;
1929 if (code
> BFD_RELOC_AARCH64_RELOC_START
1930 && code
< BFD_RELOC_AARCH64_RELOC_END
)
1931 if (elfNN_aarch64_howto_table
[code
- BFD_RELOC_AARCH64_RELOC_START
].type
)
1932 return &elfNN_aarch64_howto_table
[code
- BFD_RELOC_AARCH64_RELOC_START
];
1934 if (code
== BFD_RELOC_AARCH64_NONE
)
1935 return &elfNN_aarch64_howto_none
;
1940 static reloc_howto_type
*
1941 elfNN_aarch64_howto_from_type (unsigned int r_type
)
1943 bfd_reloc_code_real_type val
;
1944 reloc_howto_type
*howto
;
1949 bfd_set_error (bfd_error_bad_value
);
1954 if (r_type
== R_AARCH64_NONE
)
1955 return &elfNN_aarch64_howto_none
;
1957 val
= elfNN_aarch64_bfd_reloc_from_type (r_type
);
1958 howto
= elfNN_aarch64_howto_from_bfd_reloc (val
);
1963 bfd_set_error (bfd_error_bad_value
);
1968 elfNN_aarch64_info_to_howto (bfd
*abfd ATTRIBUTE_UNUSED
, arelent
*bfd_reloc
,
1969 Elf_Internal_Rela
*elf_reloc
)
1971 unsigned int r_type
;
1973 r_type
= ELFNN_R_TYPE (elf_reloc
->r_info
);
1974 bfd_reloc
->howto
= elfNN_aarch64_howto_from_type (r_type
);
1977 static reloc_howto_type
*
1978 elfNN_aarch64_reloc_type_lookup (bfd
*abfd ATTRIBUTE_UNUSED
,
1979 bfd_reloc_code_real_type code
)
1981 reloc_howto_type
*howto
= elfNN_aarch64_howto_from_bfd_reloc (code
);
1986 bfd_set_error (bfd_error_bad_value
);
1990 static reloc_howto_type
*
1991 elfNN_aarch64_reloc_name_lookup (bfd
*abfd ATTRIBUTE_UNUSED
,
1996 for (i
= 1; i
< ARRAY_SIZE (elfNN_aarch64_howto_table
) - 1; ++i
)
1997 if (elfNN_aarch64_howto_table
[i
].name
!= NULL
1998 && strcasecmp (elfNN_aarch64_howto_table
[i
].name
, r_name
) == 0)
1999 return &elfNN_aarch64_howto_table
[i
];
2004 #define TARGET_LITTLE_SYM aarch64_elfNN_le_vec
2005 #define TARGET_LITTLE_NAME "elfNN-littleaarch64"
2006 #define TARGET_BIG_SYM aarch64_elfNN_be_vec
2007 #define TARGET_BIG_NAME "elfNN-bigaarch64"
2009 /* The linker script knows the section names for placement.
2010 The entry_names are used to do simple name mangling on the stubs.
2011 Given a function name, and its type, the stub can be found. The
2012 name can be changed. The only requirement is the %s be present. */
2013 #define STUB_ENTRY_NAME "__%s_veneer"
2015 /* The name of the dynamic interpreter. This is put in the .interp
2017 #define ELF_DYNAMIC_INTERPRETER "/lib/ld.so.1"
2019 #define AARCH64_MAX_FWD_BRANCH_OFFSET \
2020 (((1 << 25) - 1) << 2)
2021 #define AARCH64_MAX_BWD_BRANCH_OFFSET \
2024 #define AARCH64_MAX_ADRP_IMM ((1 << 20) - 1)
2025 #define AARCH64_MIN_ADRP_IMM (-(1 << 20))
2028 aarch64_valid_for_adrp_p (bfd_vma value
, bfd_vma place
)
2030 bfd_signed_vma offset
= (bfd_signed_vma
) (PG (value
) - PG (place
)) >> 12;
2031 return offset
<= AARCH64_MAX_ADRP_IMM
&& offset
>= AARCH64_MIN_ADRP_IMM
;
2035 aarch64_valid_branch_p (bfd_vma value
, bfd_vma place
)
2037 bfd_signed_vma offset
= (bfd_signed_vma
) (value
- place
);
2038 return (offset
<= AARCH64_MAX_FWD_BRANCH_OFFSET
2039 && offset
>= AARCH64_MAX_BWD_BRANCH_OFFSET
);
2042 static const uint32_t aarch64_adrp_branch_stub
[] =
2044 0x90000010, /* adrp ip0, X */
2045 /* R_AARCH64_ADR_HI21_PCREL(X) */
2046 0x91000210, /* add ip0, ip0, :lo12:X */
2047 /* R_AARCH64_ADD_ABS_LO12_NC(X) */
2048 0xd61f0200, /* br ip0 */
2051 static const uint32_t aarch64_long_branch_stub
[] =
2054 0x58000090, /* ldr ip0, 1f */
2056 0x18000090, /* ldr wip0, 1f */
2058 0x10000011, /* adr ip1, #0 */
2059 0x8b110210, /* add ip0, ip0, ip1 */
2060 0xd61f0200, /* br ip0 */
2061 0x00000000, /* 1: .xword or .word
2062 R_AARCH64_PRELNN(X) + 12
2067 static const uint32_t aarch64_erratum_835769_stub
[] =
2069 0x00000000, /* Placeholder for multiply accumulate. */
2070 0x14000000, /* b <label> */
2073 static const uint32_t aarch64_erratum_843419_stub
[] =
2075 0x00000000, /* Placeholder for LDR instruction. */
2076 0x14000000, /* b <label> */
2079 /* Section name for stubs is the associated section name plus this
2081 #define STUB_SUFFIX ".stub"
2083 enum elf_aarch64_stub_type
2086 aarch64_stub_adrp_branch
,
2087 aarch64_stub_long_branch
,
2088 aarch64_stub_erratum_835769_veneer
,
2089 aarch64_stub_erratum_843419_veneer
,
2092 struct elf_aarch64_stub_hash_entry
2094 /* Base hash table entry structure. */
2095 struct bfd_hash_entry root
;
2097 /* The stub section. */
2100 /* Offset within stub_sec of the beginning of this stub. */
2101 bfd_vma stub_offset
;
2103 /* Given the symbol's value and its section we can determine its final
2104 value when building the stubs (so the stub knows where to jump). */
2105 bfd_vma target_value
;
2106 asection
*target_section
;
2108 enum elf_aarch64_stub_type stub_type
;
2110 /* The symbol table entry, if any, that this was derived from. */
2111 struct elf_aarch64_link_hash_entry
*h
;
2113 /* Destination symbol type */
2114 unsigned char st_type
;
2116 /* Where this stub is being called from, or, in the case of combined
2117 stub sections, the first input section in the group. */
2120 /* The name for the local symbol at the start of this stub. The
2121 stub name in the hash table has to be unique; this does not, so
2122 it can be friendlier. */
2125 /* The instruction which caused this stub to be generated (only valid for
2126 erratum 835769 workaround stubs at present). */
2127 uint32_t veneered_insn
;
2129 /* In an erratum 843419 workaround stub, the ADRP instruction offset. */
2130 bfd_vma adrp_offset
;
2133 /* Used to build a map of a section. This is required for mixed-endian
2136 typedef struct elf_elf_section_map
2141 elf_aarch64_section_map
;
2144 typedef struct _aarch64_elf_section_data
2146 struct bfd_elf_section_data elf
;
2147 unsigned int mapcount
;
2148 unsigned int mapsize
;
2149 elf_aarch64_section_map
*map
;
2151 _aarch64_elf_section_data
;
2153 #define elf_aarch64_section_data(sec) \
2154 ((_aarch64_elf_section_data *) elf_section_data (sec))
2156 /* The size of the thread control block which is defined to be two pointers. */
2157 #define TCB_SIZE (ARCH_SIZE/8)*2
2159 struct elf_aarch64_local_symbol
2161 unsigned int got_type
;
2162 bfd_signed_vma got_refcount
;
2165 /* Offset of the GOTPLT entry reserved for the TLS descriptor. The
2166 offset is from the end of the jump table and reserved entries
2169 The magic value (bfd_vma) -1 indicates that an offset has not be
2171 bfd_vma tlsdesc_got_jump_table_offset
;
2174 struct elf_aarch64_obj_tdata
2176 struct elf_obj_tdata root
;
2178 /* local symbol descriptors */
2179 struct elf_aarch64_local_symbol
*locals
;
2181 /* Zero to warn when linking objects with incompatible enum sizes. */
2182 int no_enum_size_warning
;
2184 /* Zero to warn when linking objects with incompatible wchar_t sizes. */
2185 int no_wchar_size_warning
;
2188 #define elf_aarch64_tdata(bfd) \
2189 ((struct elf_aarch64_obj_tdata *) (bfd)->tdata.any)
2191 #define elf_aarch64_locals(bfd) (elf_aarch64_tdata (bfd)->locals)
2193 #define is_aarch64_elf(bfd) \
2194 (bfd_get_flavour (bfd) == bfd_target_elf_flavour \
2195 && elf_tdata (bfd) != NULL \
2196 && elf_object_id (bfd) == AARCH64_ELF_DATA)
2199 elfNN_aarch64_mkobject (bfd
*abfd
)
2201 return bfd_elf_allocate_object (abfd
, sizeof (struct elf_aarch64_obj_tdata
),
2205 #define elf_aarch64_hash_entry(ent) \
2206 ((struct elf_aarch64_link_hash_entry *)(ent))
2208 #define GOT_UNKNOWN 0
2209 #define GOT_NORMAL 1
2210 #define GOT_TLS_GD 2
2211 #define GOT_TLS_IE 4
2212 #define GOT_TLSDESC_GD 8
2214 #define GOT_TLS_GD_ANY_P(type) ((type & GOT_TLS_GD) || (type & GOT_TLSDESC_GD))
2216 /* AArch64 ELF linker hash entry. */
2217 struct elf_aarch64_link_hash_entry
2219 struct elf_link_hash_entry root
;
2221 /* Track dynamic relocs copied for this symbol. */
2222 struct elf_dyn_relocs
*dyn_relocs
;
2224 /* Since PLT entries have variable size, we need to record the
2225 index into .got.plt instead of recomputing it from the PLT
2227 bfd_signed_vma plt_got_offset
;
2229 /* Bit mask representing the type of GOT entry(s) if any required by
2231 unsigned int got_type
;
2233 /* A pointer to the most recently used stub hash entry against this
2235 struct elf_aarch64_stub_hash_entry
*stub_cache
;
2237 /* Offset of the GOTPLT entry reserved for the TLS descriptor. The offset
2238 is from the end of the jump table and reserved entries within the PLTGOT.
2240 The magic value (bfd_vma) -1 indicates that an offset has not
2242 bfd_vma tlsdesc_got_jump_table_offset
;
2246 elfNN_aarch64_symbol_got_type (struct elf_link_hash_entry
*h
,
2248 unsigned long r_symndx
)
2251 return elf_aarch64_hash_entry (h
)->got_type
;
2253 if (! elf_aarch64_locals (abfd
))
2256 return elf_aarch64_locals (abfd
)[r_symndx
].got_type
;
2259 /* Get the AArch64 elf linker hash table from a link_info structure. */
2260 #define elf_aarch64_hash_table(info) \
2261 ((struct elf_aarch64_link_hash_table *) ((info)->hash))
2263 #define aarch64_stub_hash_lookup(table, string, create, copy) \
2264 ((struct elf_aarch64_stub_hash_entry *) \
2265 bfd_hash_lookup ((table), (string), (create), (copy)))
2267 /* AArch64 ELF linker hash table. */
2268 struct elf_aarch64_link_hash_table
2270 /* The main hash table. */
2271 struct elf_link_hash_table root
;
2273 /* Nonzero to force PIC branch veneers. */
2276 /* Fix erratum 835769. */
2277 int fix_erratum_835769
;
2279 /* Fix erratum 843419. */
2280 int fix_erratum_843419
;
2282 /* Enable ADRP->ADR rewrite for erratum 843419 workaround. */
2283 int fix_erratum_843419_adr
;
2285 /* The number of bytes in the initial entry in the PLT. */
2286 bfd_size_type plt_header_size
;
2288 /* The number of bytes in the subsequent PLT etries. */
2289 bfd_size_type plt_entry_size
;
2291 /* Short-cuts to get to dynamic linker sections. */
2295 /* Small local sym cache. */
2296 struct sym_cache sym_cache
;
2298 /* For convenience in allocate_dynrelocs. */
2301 /* The amount of space used by the reserved portion of the sgotplt
2302 section, plus whatever space is used by the jump slots. */
2303 bfd_vma sgotplt_jump_table_size
;
2305 /* The stub hash table. */
2306 struct bfd_hash_table stub_hash_table
;
2308 /* Linker stub bfd. */
2311 /* Linker call-backs. */
2312 asection
*(*add_stub_section
) (const char *, asection
*);
2313 void (*layout_sections_again
) (void);
2315 /* Array to keep track of which stub sections have been created, and
2316 information on stub grouping. */
2319 /* This is the section to which stubs in the group will be
2322 /* The stub section. */
2326 /* Assorted information used by elfNN_aarch64_size_stubs. */
2327 unsigned int bfd_count
;
2328 unsigned int top_index
;
2329 asection
**input_list
;
2331 /* The offset into splt of the PLT entry for the TLS descriptor
2332 resolver. Special values are 0, if not necessary (or not found
2333 to be necessary yet), and -1 if needed but not determined
2335 bfd_vma tlsdesc_plt
;
2337 /* The GOT offset for the lazy trampoline. Communicated to the
2338 loader via DT_TLSDESC_GOT. The magic value (bfd_vma) -1
2339 indicates an offset is not allocated. */
2340 bfd_vma dt_tlsdesc_got
;
2342 /* Used by local STT_GNU_IFUNC symbols. */
2343 htab_t loc_hash_table
;
2344 void * loc_hash_memory
;
2347 /* Create an entry in an AArch64 ELF linker hash table. */
2349 static struct bfd_hash_entry
*
2350 elfNN_aarch64_link_hash_newfunc (struct bfd_hash_entry
*entry
,
2351 struct bfd_hash_table
*table
,
2354 struct elf_aarch64_link_hash_entry
*ret
=
2355 (struct elf_aarch64_link_hash_entry
*) entry
;
2357 /* Allocate the structure if it has not already been allocated by a
2360 ret
= bfd_hash_allocate (table
,
2361 sizeof (struct elf_aarch64_link_hash_entry
));
2363 return (struct bfd_hash_entry
*) ret
;
2365 /* Call the allocation method of the superclass. */
2366 ret
= ((struct elf_aarch64_link_hash_entry
*)
2367 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry
*) ret
,
2371 ret
->dyn_relocs
= NULL
;
2372 ret
->got_type
= GOT_UNKNOWN
;
2373 ret
->plt_got_offset
= (bfd_vma
) - 1;
2374 ret
->stub_cache
= NULL
;
2375 ret
->tlsdesc_got_jump_table_offset
= (bfd_vma
) - 1;
2378 return (struct bfd_hash_entry
*) ret
;
2381 /* Initialize an entry in the stub hash table. */
2383 static struct bfd_hash_entry
*
2384 stub_hash_newfunc (struct bfd_hash_entry
*entry
,
2385 struct bfd_hash_table
*table
, const char *string
)
2387 /* Allocate the structure if it has not already been allocated by a
2391 entry
= bfd_hash_allocate (table
,
2393 elf_aarch64_stub_hash_entry
));
2398 /* Call the allocation method of the superclass. */
2399 entry
= bfd_hash_newfunc (entry
, table
, string
);
2402 struct elf_aarch64_stub_hash_entry
*eh
;
2404 /* Initialize the local fields. */
2405 eh
= (struct elf_aarch64_stub_hash_entry
*) entry
;
2406 eh
->adrp_offset
= 0;
2407 eh
->stub_sec
= NULL
;
2408 eh
->stub_offset
= 0;
2409 eh
->target_value
= 0;
2410 eh
->target_section
= NULL
;
2411 eh
->stub_type
= aarch64_stub_none
;
2419 /* Compute a hash of a local hash entry. We use elf_link_hash_entry
2420 for local symbol so that we can handle local STT_GNU_IFUNC symbols
2421 as global symbol. We reuse indx and dynstr_index for local symbol
2422 hash since they aren't used by global symbols in this backend. */
2425 elfNN_aarch64_local_htab_hash (const void *ptr
)
2427 struct elf_link_hash_entry
*h
2428 = (struct elf_link_hash_entry
*) ptr
;
2429 return ELF_LOCAL_SYMBOL_HASH (h
->indx
, h
->dynstr_index
);
2432 /* Compare local hash entries. */
2435 elfNN_aarch64_local_htab_eq (const void *ptr1
, const void *ptr2
)
2437 struct elf_link_hash_entry
*h1
2438 = (struct elf_link_hash_entry
*) ptr1
;
2439 struct elf_link_hash_entry
*h2
2440 = (struct elf_link_hash_entry
*) ptr2
;
2442 return h1
->indx
== h2
->indx
&& h1
->dynstr_index
== h2
->dynstr_index
;
2445 /* Find and/or create a hash entry for local symbol. */
2447 static struct elf_link_hash_entry
*
2448 elfNN_aarch64_get_local_sym_hash (struct elf_aarch64_link_hash_table
*htab
,
2449 bfd
*abfd
, const Elf_Internal_Rela
*rel
,
2452 struct elf_aarch64_link_hash_entry e
, *ret
;
2453 asection
*sec
= abfd
->sections
;
2454 hashval_t h
= ELF_LOCAL_SYMBOL_HASH (sec
->id
,
2455 ELFNN_R_SYM (rel
->r_info
));
2458 e
.root
.indx
= sec
->id
;
2459 e
.root
.dynstr_index
= ELFNN_R_SYM (rel
->r_info
);
2460 slot
= htab_find_slot_with_hash (htab
->loc_hash_table
, &e
, h
,
2461 create
? INSERT
: NO_INSERT
);
2468 ret
= (struct elf_aarch64_link_hash_entry
*) *slot
;
2472 ret
= (struct elf_aarch64_link_hash_entry
*)
2473 objalloc_alloc ((struct objalloc
*) htab
->loc_hash_memory
,
2474 sizeof (struct elf_aarch64_link_hash_entry
));
2477 memset (ret
, 0, sizeof (*ret
));
2478 ret
->root
.indx
= sec
->id
;
2479 ret
->root
.dynstr_index
= ELFNN_R_SYM (rel
->r_info
);
2480 ret
->root
.dynindx
= -1;
2486 /* Copy the extra info we tack onto an elf_link_hash_entry. */
2489 elfNN_aarch64_copy_indirect_symbol (struct bfd_link_info
*info
,
2490 struct elf_link_hash_entry
*dir
,
2491 struct elf_link_hash_entry
*ind
)
2493 struct elf_aarch64_link_hash_entry
*edir
, *eind
;
2495 edir
= (struct elf_aarch64_link_hash_entry
*) dir
;
2496 eind
= (struct elf_aarch64_link_hash_entry
*) ind
;
2498 if (eind
->dyn_relocs
!= NULL
)
2500 if (edir
->dyn_relocs
!= NULL
)
2502 struct elf_dyn_relocs
**pp
;
2503 struct elf_dyn_relocs
*p
;
2505 /* Add reloc counts against the indirect sym to the direct sym
2506 list. Merge any entries against the same section. */
2507 for (pp
= &eind
->dyn_relocs
; (p
= *pp
) != NULL
;)
2509 struct elf_dyn_relocs
*q
;
2511 for (q
= edir
->dyn_relocs
; q
!= NULL
; q
= q
->next
)
2512 if (q
->sec
== p
->sec
)
2514 q
->pc_count
+= p
->pc_count
;
2515 q
->count
+= p
->count
;
2522 *pp
= edir
->dyn_relocs
;
2525 edir
->dyn_relocs
= eind
->dyn_relocs
;
2526 eind
->dyn_relocs
= NULL
;
2529 if (ind
->root
.type
== bfd_link_hash_indirect
)
2531 /* Copy over PLT info. */
2532 if (dir
->got
.refcount
<= 0)
2534 edir
->got_type
= eind
->got_type
;
2535 eind
->got_type
= GOT_UNKNOWN
;
2539 _bfd_elf_link_hash_copy_indirect (info
, dir
, ind
);
2542 /* Destroy an AArch64 elf linker hash table. */
2545 elfNN_aarch64_link_hash_table_free (bfd
*obfd
)
2547 struct elf_aarch64_link_hash_table
*ret
2548 = (struct elf_aarch64_link_hash_table
*) obfd
->link
.hash
;
2550 if (ret
->loc_hash_table
)
2551 htab_delete (ret
->loc_hash_table
);
2552 if (ret
->loc_hash_memory
)
2553 objalloc_free ((struct objalloc
*) ret
->loc_hash_memory
);
2555 bfd_hash_table_free (&ret
->stub_hash_table
);
2556 _bfd_elf_link_hash_table_free (obfd
);
2559 /* Create an AArch64 elf linker hash table. */
2561 static struct bfd_link_hash_table
*
2562 elfNN_aarch64_link_hash_table_create (bfd
*abfd
)
2564 struct elf_aarch64_link_hash_table
*ret
;
2565 bfd_size_type amt
= sizeof (struct elf_aarch64_link_hash_table
);
2567 ret
= bfd_zmalloc (amt
);
2571 if (!_bfd_elf_link_hash_table_init
2572 (&ret
->root
, abfd
, elfNN_aarch64_link_hash_newfunc
,
2573 sizeof (struct elf_aarch64_link_hash_entry
), AARCH64_ELF_DATA
))
2579 ret
->plt_header_size
= PLT_ENTRY_SIZE
;
2580 ret
->plt_entry_size
= PLT_SMALL_ENTRY_SIZE
;
2582 ret
->dt_tlsdesc_got
= (bfd_vma
) - 1;
2584 if (!bfd_hash_table_init (&ret
->stub_hash_table
, stub_hash_newfunc
,
2585 sizeof (struct elf_aarch64_stub_hash_entry
)))
2587 _bfd_elf_link_hash_table_free (abfd
);
2591 ret
->loc_hash_table
= htab_try_create (1024,
2592 elfNN_aarch64_local_htab_hash
,
2593 elfNN_aarch64_local_htab_eq
,
2595 ret
->loc_hash_memory
= objalloc_create ();
2596 if (!ret
->loc_hash_table
|| !ret
->loc_hash_memory
)
2598 elfNN_aarch64_link_hash_table_free (abfd
);
2601 ret
->root
.root
.hash_table_free
= elfNN_aarch64_link_hash_table_free
;
2603 return &ret
->root
.root
;
2607 aarch64_relocate (unsigned int r_type
, bfd
*input_bfd
, asection
*input_section
,
2608 bfd_vma offset
, bfd_vma value
)
2610 reloc_howto_type
*howto
;
2613 howto
= elfNN_aarch64_howto_from_type (r_type
);
2614 place
= (input_section
->output_section
->vma
+ input_section
->output_offset
2617 r_type
= elfNN_aarch64_bfd_reloc_from_type (r_type
);
2618 value
= _bfd_aarch64_elf_resolve_relocation (r_type
, place
, value
, 0, FALSE
);
2619 return _bfd_aarch64_elf_put_addend (input_bfd
,
2620 input_section
->contents
+ offset
, r_type
,
2624 static enum elf_aarch64_stub_type
2625 aarch64_select_branch_stub (bfd_vma value
, bfd_vma place
)
2627 if (aarch64_valid_for_adrp_p (value
, place
))
2628 return aarch64_stub_adrp_branch
;
2629 return aarch64_stub_long_branch
;
2632 /* Determine the type of stub needed, if any, for a call. */
2634 static enum elf_aarch64_stub_type
2635 aarch64_type_of_stub (struct bfd_link_info
*info
,
2636 asection
*input_sec
,
2637 const Elf_Internal_Rela
*rel
,
2639 unsigned char st_type
,
2640 struct elf_aarch64_link_hash_entry
*hash
,
2641 bfd_vma destination
)
2644 bfd_signed_vma branch_offset
;
2645 unsigned int r_type
;
2646 struct elf_aarch64_link_hash_table
*globals
;
2647 enum elf_aarch64_stub_type stub_type
= aarch64_stub_none
;
2648 bfd_boolean via_plt_p
;
2650 if (st_type
!= STT_FUNC
2651 && (sym_sec
!= bfd_abs_section_ptr
))
2654 globals
= elf_aarch64_hash_table (info
);
2655 via_plt_p
= (globals
->root
.splt
!= NULL
&& hash
!= NULL
2656 && hash
->root
.plt
.offset
!= (bfd_vma
) - 1);
2657 /* Make sure call to plt stub can fit into the branch range. */
2659 destination
= (globals
->root
.splt
->output_section
->vma
2660 + globals
->root
.splt
->output_offset
2661 + hash
->root
.plt
.offset
);
2663 /* Determine where the call point is. */
2664 location
= (input_sec
->output_offset
2665 + input_sec
->output_section
->vma
+ rel
->r_offset
);
2667 branch_offset
= (bfd_signed_vma
) (destination
- location
);
2669 r_type
= ELFNN_R_TYPE (rel
->r_info
);
2671 /* We don't want to redirect any old unconditional jump in this way,
2672 only one which is being used for a sibcall, where it is
2673 acceptable for the IP0 and IP1 registers to be clobbered. */
2674 if ((r_type
== AARCH64_R (CALL26
) || r_type
== AARCH64_R (JUMP26
))
2675 && (branch_offset
> AARCH64_MAX_FWD_BRANCH_OFFSET
2676 || branch_offset
< AARCH64_MAX_BWD_BRANCH_OFFSET
))
2678 stub_type
= aarch64_stub_long_branch
;
2684 /* Build a name for an entry in the stub hash table. */
2687 elfNN_aarch64_stub_name (const asection
*input_section
,
2688 const asection
*sym_sec
,
2689 const struct elf_aarch64_link_hash_entry
*hash
,
2690 const Elf_Internal_Rela
*rel
)
2697 len
= 8 + 1 + strlen (hash
->root
.root
.root
.string
) + 1 + 16 + 1;
2698 stub_name
= bfd_malloc (len
);
2699 if (stub_name
!= NULL
)
2700 snprintf (stub_name
, len
, "%08x_%s+%" BFD_VMA_FMT
"x",
2701 (unsigned int) input_section
->id
,
2702 hash
->root
.root
.root
.string
,
2707 len
= 8 + 1 + 8 + 1 + 8 + 1 + 16 + 1;
2708 stub_name
= bfd_malloc (len
);
2709 if (stub_name
!= NULL
)
2710 snprintf (stub_name
, len
, "%08x_%x:%x+%" BFD_VMA_FMT
"x",
2711 (unsigned int) input_section
->id
,
2712 (unsigned int) sym_sec
->id
,
2713 (unsigned int) ELFNN_R_SYM (rel
->r_info
),
2720 /* Look up an entry in the stub hash. Stub entries are cached because
2721 creating the stub name takes a bit of time. */
2723 static struct elf_aarch64_stub_hash_entry
*
2724 elfNN_aarch64_get_stub_entry (const asection
*input_section
,
2725 const asection
*sym_sec
,
2726 struct elf_link_hash_entry
*hash
,
2727 const Elf_Internal_Rela
*rel
,
2728 struct elf_aarch64_link_hash_table
*htab
)
2730 struct elf_aarch64_stub_hash_entry
*stub_entry
;
2731 struct elf_aarch64_link_hash_entry
*h
=
2732 (struct elf_aarch64_link_hash_entry
*) hash
;
2733 const asection
*id_sec
;
2735 if ((input_section
->flags
& SEC_CODE
) == 0)
2738 /* If this input section is part of a group of sections sharing one
2739 stub section, then use the id of the first section in the group.
2740 Stub names need to include a section id, as there may well be
2741 more than one stub used to reach say, printf, and we need to
2742 distinguish between them. */
2743 id_sec
= htab
->stub_group
[input_section
->id
].link_sec
;
2745 if (h
!= NULL
&& h
->stub_cache
!= NULL
2746 && h
->stub_cache
->h
== h
&& h
->stub_cache
->id_sec
== id_sec
)
2748 stub_entry
= h
->stub_cache
;
2754 stub_name
= elfNN_aarch64_stub_name (id_sec
, sym_sec
, h
, rel
);
2755 if (stub_name
== NULL
)
2758 stub_entry
= aarch64_stub_hash_lookup (&htab
->stub_hash_table
,
2759 stub_name
, FALSE
, FALSE
);
2761 h
->stub_cache
= stub_entry
;
2770 /* Create a stub section. */
2773 _bfd_aarch64_create_stub_section (asection
*section
,
2774 struct elf_aarch64_link_hash_table
*htab
)
2780 namelen
= strlen (section
->name
);
2781 len
= namelen
+ sizeof (STUB_SUFFIX
);
2782 s_name
= bfd_alloc (htab
->stub_bfd
, len
);
2786 memcpy (s_name
, section
->name
, namelen
);
2787 memcpy (s_name
+ namelen
, STUB_SUFFIX
, sizeof (STUB_SUFFIX
));
2788 return (*htab
->add_stub_section
) (s_name
, section
);
2792 /* Find or create a stub section for a link section.
2794 Fix or create the stub section used to collect stubs attached to
2795 the specified link section. */
2798 _bfd_aarch64_get_stub_for_link_section (asection
*link_section
,
2799 struct elf_aarch64_link_hash_table
*htab
)
2801 if (htab
->stub_group
[link_section
->id
].stub_sec
== NULL
)
2802 htab
->stub_group
[link_section
->id
].stub_sec
2803 = _bfd_aarch64_create_stub_section (link_section
, htab
);
2804 return htab
->stub_group
[link_section
->id
].stub_sec
;
2808 /* Find or create a stub section in the stub group for an input
2812 _bfd_aarch64_create_or_find_stub_sec (asection
*section
,
2813 struct elf_aarch64_link_hash_table
*htab
)
2815 asection
*link_sec
= htab
->stub_group
[section
->id
].link_sec
;
2816 return _bfd_aarch64_get_stub_for_link_section (link_sec
, htab
);
2820 /* Add a new stub entry in the stub group associated with an input
2821 section to the stub hash. Not all fields of the new stub entry are
2824 static struct elf_aarch64_stub_hash_entry
*
2825 _bfd_aarch64_add_stub_entry_in_group (const char *stub_name
,
2827 struct elf_aarch64_link_hash_table
*htab
)
2831 struct elf_aarch64_stub_hash_entry
*stub_entry
;
2833 link_sec
= htab
->stub_group
[section
->id
].link_sec
;
2834 stub_sec
= _bfd_aarch64_create_or_find_stub_sec (section
, htab
);
2836 /* Enter this entry into the linker stub hash table. */
2837 stub_entry
= aarch64_stub_hash_lookup (&htab
->stub_hash_table
, stub_name
,
2839 if (stub_entry
== NULL
)
2841 (*_bfd_error_handler
) (_("%s: cannot create stub entry %s"),
2842 section
->owner
, stub_name
);
2846 stub_entry
->stub_sec
= stub_sec
;
2847 stub_entry
->stub_offset
= 0;
2848 stub_entry
->id_sec
= link_sec
;
2853 /* Add a new stub entry in the final stub section to the stub hash.
2854 Not all fields of the new stub entry are initialised. */
2856 static struct elf_aarch64_stub_hash_entry
*
2857 _bfd_aarch64_add_stub_entry_after (const char *stub_name
,
2858 asection
*link_section
,
2859 struct elf_aarch64_link_hash_table
*htab
)
2862 struct elf_aarch64_stub_hash_entry
*stub_entry
;
2864 stub_sec
= _bfd_aarch64_get_stub_for_link_section (link_section
, htab
);
2865 stub_entry
= aarch64_stub_hash_lookup (&htab
->stub_hash_table
, stub_name
,
2867 if (stub_entry
== NULL
)
2869 (*_bfd_error_handler
) (_("cannot create stub entry %s"), stub_name
);
2873 stub_entry
->stub_sec
= stub_sec
;
2874 stub_entry
->stub_offset
= 0;
2875 stub_entry
->id_sec
= link_section
;
2882 aarch64_build_one_stub (struct bfd_hash_entry
*gen_entry
,
2883 void *in_arg ATTRIBUTE_UNUSED
)
2885 struct elf_aarch64_stub_hash_entry
*stub_entry
;
2890 bfd_vma veneered_insn_loc
;
2891 bfd_vma veneer_entry_loc
;
2892 bfd_signed_vma branch_offset
= 0;
2893 unsigned int template_size
;
2894 const uint32_t *template;
2897 /* Massage our args to the form they really have. */
2898 stub_entry
= (struct elf_aarch64_stub_hash_entry
*) gen_entry
;
2900 stub_sec
= stub_entry
->stub_sec
;
2902 /* Make a note of the offset within the stubs for this entry. */
2903 stub_entry
->stub_offset
= stub_sec
->size
;
2904 loc
= stub_sec
->contents
+ stub_entry
->stub_offset
;
2906 stub_bfd
= stub_sec
->owner
;
2908 /* This is the address of the stub destination. */
2909 sym_value
= (stub_entry
->target_value
2910 + stub_entry
->target_section
->output_offset
2911 + stub_entry
->target_section
->output_section
->vma
);
2913 if (stub_entry
->stub_type
== aarch64_stub_long_branch
)
2915 bfd_vma place
= (stub_entry
->stub_offset
+ stub_sec
->output_section
->vma
2916 + stub_sec
->output_offset
);
2918 /* See if we can relax the stub. */
2919 if (aarch64_valid_for_adrp_p (sym_value
, place
))
2920 stub_entry
->stub_type
= aarch64_select_branch_stub (sym_value
, place
);
2923 switch (stub_entry
->stub_type
)
2925 case aarch64_stub_adrp_branch
:
2926 template = aarch64_adrp_branch_stub
;
2927 template_size
= sizeof (aarch64_adrp_branch_stub
);
2929 case aarch64_stub_long_branch
:
2930 template = aarch64_long_branch_stub
;
2931 template_size
= sizeof (aarch64_long_branch_stub
);
2933 case aarch64_stub_erratum_835769_veneer
:
2934 template = aarch64_erratum_835769_stub
;
2935 template_size
= sizeof (aarch64_erratum_835769_stub
);
2937 case aarch64_stub_erratum_843419_veneer
:
2938 template = aarch64_erratum_843419_stub
;
2939 template_size
= sizeof (aarch64_erratum_843419_stub
);
2945 for (i
= 0; i
< (template_size
/ sizeof template[0]); i
++)
2947 bfd_putl32 (template[i
], loc
);
2951 template_size
= (template_size
+ 7) & ~7;
2952 stub_sec
->size
+= template_size
;
2954 switch (stub_entry
->stub_type
)
2956 case aarch64_stub_adrp_branch
:
2957 if (aarch64_relocate (AARCH64_R (ADR_PREL_PG_HI21
), stub_bfd
, stub_sec
,
2958 stub_entry
->stub_offset
, sym_value
))
2959 /* The stub would not have been relaxed if the offset was out
2963 if (aarch64_relocate (AARCH64_R (ADD_ABS_LO12_NC
), stub_bfd
, stub_sec
,
2964 stub_entry
->stub_offset
+ 4, sym_value
))
2968 case aarch64_stub_long_branch
:
2969 /* We want the value relative to the address 12 bytes back from the
2971 if (aarch64_relocate (AARCH64_R (PRELNN
), stub_bfd
, stub_sec
,
2972 stub_entry
->stub_offset
+ 16, sym_value
+ 12))
2976 case aarch64_stub_erratum_835769_veneer
:
2977 veneered_insn_loc
= stub_entry
->target_section
->output_section
->vma
2978 + stub_entry
->target_section
->output_offset
2979 + stub_entry
->target_value
;
2980 veneer_entry_loc
= stub_entry
->stub_sec
->output_section
->vma
2981 + stub_entry
->stub_sec
->output_offset
2982 + stub_entry
->stub_offset
;
2983 branch_offset
= veneered_insn_loc
- veneer_entry_loc
;
2984 branch_offset
>>= 2;
2985 branch_offset
&= 0x3ffffff;
2986 bfd_putl32 (stub_entry
->veneered_insn
,
2987 stub_sec
->contents
+ stub_entry
->stub_offset
);
2988 bfd_putl32 (template[1] | branch_offset
,
2989 stub_sec
->contents
+ stub_entry
->stub_offset
+ 4);
2992 case aarch64_stub_erratum_843419_veneer
:
2993 if (aarch64_relocate (AARCH64_R (JUMP26
), stub_bfd
, stub_sec
,
2994 stub_entry
->stub_offset
+ 4, sym_value
+ 4))
3005 /* As above, but don't actually build the stub. Just bump offset so
3006 we know stub section sizes. */
3009 aarch64_size_one_stub (struct bfd_hash_entry
*gen_entry
,
3010 void *in_arg ATTRIBUTE_UNUSED
)
3012 struct elf_aarch64_stub_hash_entry
*stub_entry
;
3015 /* Massage our args to the form they really have. */
3016 stub_entry
= (struct elf_aarch64_stub_hash_entry
*) gen_entry
;
3018 switch (stub_entry
->stub_type
)
3020 case aarch64_stub_adrp_branch
:
3021 size
= sizeof (aarch64_adrp_branch_stub
);
3023 case aarch64_stub_long_branch
:
3024 size
= sizeof (aarch64_long_branch_stub
);
3026 case aarch64_stub_erratum_835769_veneer
:
3027 size
= sizeof (aarch64_erratum_835769_stub
);
3029 case aarch64_stub_erratum_843419_veneer
:
3030 size
= sizeof (aarch64_erratum_843419_stub
);
3036 size
= (size
+ 7) & ~7;
3037 stub_entry
->stub_sec
->size
+= size
;
3041 /* External entry points for sizing and building linker stubs. */
3043 /* Set up various things so that we can make a list of input sections
3044 for each output section included in the link. Returns -1 on error,
3045 0 when no stubs will be needed, and 1 on success. */
3048 elfNN_aarch64_setup_section_lists (bfd
*output_bfd
,
3049 struct bfd_link_info
*info
)
3052 unsigned int bfd_count
;
3053 unsigned int top_id
, top_index
;
3055 asection
**input_list
, **list
;
3057 struct elf_aarch64_link_hash_table
*htab
=
3058 elf_aarch64_hash_table (info
);
3060 if (!is_elf_hash_table (htab
))
3063 /* Count the number of input BFDs and find the top input section id. */
3064 for (input_bfd
= info
->input_bfds
, bfd_count
= 0, top_id
= 0;
3065 input_bfd
!= NULL
; input_bfd
= input_bfd
->link
.next
)
3068 for (section
= input_bfd
->sections
;
3069 section
!= NULL
; section
= section
->next
)
3071 if (top_id
< section
->id
)
3072 top_id
= section
->id
;
3075 htab
->bfd_count
= bfd_count
;
3077 amt
= sizeof (struct map_stub
) * (top_id
+ 1);
3078 htab
->stub_group
= bfd_zmalloc (amt
);
3079 if (htab
->stub_group
== NULL
)
3082 /* We can't use output_bfd->section_count here to find the top output
3083 section index as some sections may have been removed, and
3084 _bfd_strip_section_from_output doesn't renumber the indices. */
3085 for (section
= output_bfd
->sections
, top_index
= 0;
3086 section
!= NULL
; section
= section
->next
)
3088 if (top_index
< section
->index
)
3089 top_index
= section
->index
;
3092 htab
->top_index
= top_index
;
3093 amt
= sizeof (asection
*) * (top_index
+ 1);
3094 input_list
= bfd_malloc (amt
);
3095 htab
->input_list
= input_list
;
3096 if (input_list
== NULL
)
3099 /* For sections we aren't interested in, mark their entries with a
3100 value we can check later. */
3101 list
= input_list
+ top_index
;
3103 *list
= bfd_abs_section_ptr
;
3104 while (list
-- != input_list
);
3106 for (section
= output_bfd
->sections
;
3107 section
!= NULL
; section
= section
->next
)
3109 if ((section
->flags
& SEC_CODE
) != 0)
3110 input_list
[section
->index
] = NULL
;
3116 /* Used by elfNN_aarch64_next_input_section and group_sections. */
3117 #define PREV_SEC(sec) (htab->stub_group[(sec)->id].link_sec)
3119 /* The linker repeatedly calls this function for each input section,
3120 in the order that input sections are linked into output sections.
3121 Build lists of input sections to determine groupings between which
3122 we may insert linker stubs. */
3125 elfNN_aarch64_next_input_section (struct bfd_link_info
*info
, asection
*isec
)
3127 struct elf_aarch64_link_hash_table
*htab
=
3128 elf_aarch64_hash_table (info
);
3130 if (isec
->output_section
->index
<= htab
->top_index
)
3132 asection
**list
= htab
->input_list
+ isec
->output_section
->index
;
3134 if (*list
!= bfd_abs_section_ptr
)
3136 /* Steal the link_sec pointer for our list. */
3137 /* This happens to make the list in reverse order,
3138 which is what we want. */
3139 PREV_SEC (isec
) = *list
;
3145 /* See whether we can group stub sections together. Grouping stub
3146 sections may result in fewer stubs. More importantly, we need to
3147 put all .init* and .fini* stubs at the beginning of the .init or
3148 .fini output sections respectively, because glibc splits the
3149 _init and _fini functions into multiple parts. Putting a stub in
3150 the middle of a function is not a good idea. */
3153 group_sections (struct elf_aarch64_link_hash_table
*htab
,
3154 bfd_size_type stub_group_size
,
3155 bfd_boolean stubs_always_before_branch
)
3157 asection
**list
= htab
->input_list
+ htab
->top_index
;
3161 asection
*tail
= *list
;
3163 if (tail
== bfd_abs_section_ptr
)
3166 while (tail
!= NULL
)
3170 bfd_size_type total
;
3174 while ((prev
= PREV_SEC (curr
)) != NULL
3175 && ((total
+= curr
->output_offset
- prev
->output_offset
)
3179 /* OK, the size from the start of CURR to the end is less
3180 than stub_group_size and thus can be handled by one stub
3181 section. (Or the tail section is itself larger than
3182 stub_group_size, in which case we may be toast.)
3183 We should really be keeping track of the total size of
3184 stubs added here, as stubs contribute to the final output
3188 prev
= PREV_SEC (tail
);
3189 /* Set up this stub group. */
3190 htab
->stub_group
[tail
->id
].link_sec
= curr
;
3192 while (tail
!= curr
&& (tail
= prev
) != NULL
);
3194 /* But wait, there's more! Input sections up to stub_group_size
3195 bytes before the stub section can be handled by it too. */
3196 if (!stubs_always_before_branch
)
3200 && ((total
+= tail
->output_offset
- prev
->output_offset
)
3204 prev
= PREV_SEC (tail
);
3205 htab
->stub_group
[tail
->id
].link_sec
= curr
;
3211 while (list
-- != htab
->input_list
);
3213 free (htab
->input_list
);
3218 #define AARCH64_BITS(x, pos, n) (((x) >> (pos)) & ((1 << (n)) - 1))
3220 #define AARCH64_RT(insn) AARCH64_BITS (insn, 0, 5)
3221 #define AARCH64_RT2(insn) AARCH64_BITS (insn, 10, 5)
3222 #define AARCH64_RA(insn) AARCH64_BITS (insn, 10, 5)
3223 #define AARCH64_RD(insn) AARCH64_BITS (insn, 0, 5)
3224 #define AARCH64_RN(insn) AARCH64_BITS (insn, 5, 5)
3225 #define AARCH64_RM(insn) AARCH64_BITS (insn, 16, 5)
3227 #define AARCH64_MAC(insn) (((insn) & 0xff000000) == 0x9b000000)
3228 #define AARCH64_BIT(insn, n) AARCH64_BITS (insn, n, 1)
3229 #define AARCH64_OP31(insn) AARCH64_BITS (insn, 21, 3)
3230 #define AARCH64_ZR 0x1f
3232 /* All ld/st ops. See C4-182 of the ARM ARM. The encoding space for
3233 LD_PCREL, LDST_RO, LDST_UI and LDST_UIMM cover prefetch ops. */
3235 #define AARCH64_LD(insn) (AARCH64_BIT (insn, 22) == 1)
3236 #define AARCH64_LDST(insn) (((insn) & 0x0a000000) == 0x08000000)
3237 #define AARCH64_LDST_EX(insn) (((insn) & 0x3f000000) == 0x08000000)
3238 #define AARCH64_LDST_PCREL(insn) (((insn) & 0x3b000000) == 0x18000000)
3239 #define AARCH64_LDST_NAP(insn) (((insn) & 0x3b800000) == 0x28000000)
3240 #define AARCH64_LDSTP_PI(insn) (((insn) & 0x3b800000) == 0x28800000)
3241 #define AARCH64_LDSTP_O(insn) (((insn) & 0x3b800000) == 0x29000000)
3242 #define AARCH64_LDSTP_PRE(insn) (((insn) & 0x3b800000) == 0x29800000)
3243 #define AARCH64_LDST_UI(insn) (((insn) & 0x3b200c00) == 0x38000000)
3244 #define AARCH64_LDST_PIIMM(insn) (((insn) & 0x3b200c00) == 0x38000400)
3245 #define AARCH64_LDST_U(insn) (((insn) & 0x3b200c00) == 0x38000800)
3246 #define AARCH64_LDST_PREIMM(insn) (((insn) & 0x3b200c00) == 0x38000c00)
3247 #define AARCH64_LDST_RO(insn) (((insn) & 0x3b200c00) == 0x38200800)
3248 #define AARCH64_LDST_UIMM(insn) (((insn) & 0x3b000000) == 0x39000000)
3249 #define AARCH64_LDST_SIMD_M(insn) (((insn) & 0xbfbf0000) == 0x0c000000)
3250 #define AARCH64_LDST_SIMD_M_PI(insn) (((insn) & 0xbfa00000) == 0x0c800000)
3251 #define AARCH64_LDST_SIMD_S(insn) (((insn) & 0xbf9f0000) == 0x0d000000)
3252 #define AARCH64_LDST_SIMD_S_PI(insn) (((insn) & 0xbf800000) == 0x0d800000)
3254 /* Classify an INSN if it is indeed a load/store.
3256 Return TRUE if INSN is a LD/ST instruction otherwise return FALSE.
3258 For scalar LD/ST instructions PAIR is FALSE, RT is returned and RT2
3261 For LD/ST pair instructions PAIR is TRUE, RT and RT2 are returned.
3266 aarch64_mem_op_p (uint32_t insn
, unsigned int *rt
, unsigned int *rt2
,
3267 bfd_boolean
*pair
, bfd_boolean
*load
)
3275 /* Bail out quickly if INSN doesn't fall into the the load-store
3277 if (!AARCH64_LDST (insn
))
3282 if (AARCH64_LDST_EX (insn
))
3284 *rt
= AARCH64_RT (insn
);
3286 if (AARCH64_BIT (insn
, 21) == 1)
3289 *rt2
= AARCH64_RT2 (insn
);
3291 *load
= AARCH64_LD (insn
);
3294 else if (AARCH64_LDST_NAP (insn
)
3295 || AARCH64_LDSTP_PI (insn
)
3296 || AARCH64_LDSTP_O (insn
)
3297 || AARCH64_LDSTP_PRE (insn
))
3300 *rt
= AARCH64_RT (insn
);
3301 *rt2
= AARCH64_RT2 (insn
);
3302 *load
= AARCH64_LD (insn
);
3305 else if (AARCH64_LDST_PCREL (insn
)
3306 || AARCH64_LDST_UI (insn
)
3307 || AARCH64_LDST_PIIMM (insn
)
3308 || AARCH64_LDST_U (insn
)
3309 || AARCH64_LDST_PREIMM (insn
)
3310 || AARCH64_LDST_RO (insn
)
3311 || AARCH64_LDST_UIMM (insn
))
3313 *rt
= AARCH64_RT (insn
);
3315 if (AARCH64_LDST_PCREL (insn
))
3317 opc
= AARCH64_BITS (insn
, 22, 2);
3318 v
= AARCH64_BIT (insn
, 26);
3319 opc_v
= opc
| (v
<< 2);
3320 *load
= (opc_v
== 1 || opc_v
== 2 || opc_v
== 3
3321 || opc_v
== 5 || opc_v
== 7);
3324 else if (AARCH64_LDST_SIMD_M (insn
)
3325 || AARCH64_LDST_SIMD_M_PI (insn
))
3327 *rt
= AARCH64_RT (insn
);
3328 *load
= AARCH64_BIT (insn
, 22);
3329 opcode
= (insn
>> 12) & 0xf;
3356 else if (AARCH64_LDST_SIMD_S (insn
)
3357 || AARCH64_LDST_SIMD_S_PI (insn
))
3359 *rt
= AARCH64_RT (insn
);
3360 r
= (insn
>> 21) & 1;
3361 *load
= AARCH64_BIT (insn
, 22);
3362 opcode
= (insn
>> 13) & 0x7;
3374 *rt2
= *rt
+ (r
== 0 ? 2 : 3);
3382 *rt2
= *rt
+ (r
== 0 ? 2 : 3);
3394 /* Return TRUE if INSN is multiply-accumulate. */
3397 aarch64_mlxl_p (uint32_t insn
)
3399 uint32_t op31
= AARCH64_OP31 (insn
);
3401 if (AARCH64_MAC (insn
)
3402 && (op31
== 0 || op31
== 1 || op31
== 5)
3403 /* Exclude MUL instructions which are encoded as a multiple accumulate
3405 && AARCH64_RA (insn
) != AARCH64_ZR
)
3411 /* Some early revisions of the Cortex-A53 have an erratum (835769) whereby
3412 it is possible for a 64-bit multiply-accumulate instruction to generate an
3413 incorrect result. The details are quite complex and hard to
3414 determine statically, since branches in the code may exist in some
3415 circumstances, but all cases end with a memory (load, store, or
3416 prefetch) instruction followed immediately by the multiply-accumulate
3417 operation. We employ a linker patching technique, by moving the potentially
3418 affected multiply-accumulate instruction into a patch region and replacing
3419 the original instruction with a branch to the patch. This function checks
3420 if INSN_1 is the memory operation followed by a multiply-accumulate
3421 operation (INSN_2). Return TRUE if an erratum sequence is found, FALSE
3422 if INSN_1 and INSN_2 are safe. */
3425 aarch64_erratum_sequence (uint32_t insn_1
, uint32_t insn_2
)
3435 if (aarch64_mlxl_p (insn_2
)
3436 && aarch64_mem_op_p (insn_1
, &rt
, &rt2
, &pair
, &load
))
3438 /* Any SIMD memory op is independent of the subsequent MLA
3439 by definition of the erratum. */
3440 if (AARCH64_BIT (insn_1
, 26))
3443 /* If not SIMD, check for integer memory ops and MLA relationship. */
3444 rn
= AARCH64_RN (insn_2
);
3445 ra
= AARCH64_RA (insn_2
);
3446 rm
= AARCH64_RM (insn_2
);
3448 /* If this is a load and there's a true(RAW) dependency, we are safe
3449 and this is not an erratum sequence. */
3451 (rt
== rn
|| rt
== rm
|| rt
== ra
3452 || (pair
&& (rt2
== rn
|| rt2
== rm
|| rt2
== ra
))))
3455 /* We conservatively put out stubs for all other cases (including
3463 /* Used to order a list of mapping symbols by address. */
3466 elf_aarch64_compare_mapping (const void *a
, const void *b
)
3468 const elf_aarch64_section_map
*amap
= (const elf_aarch64_section_map
*) a
;
3469 const elf_aarch64_section_map
*bmap
= (const elf_aarch64_section_map
*) b
;
3471 if (amap
->vma
> bmap
->vma
)
3473 else if (amap
->vma
< bmap
->vma
)
3475 else if (amap
->type
> bmap
->type
)
3476 /* Ensure results do not depend on the host qsort for objects with
3477 multiple mapping symbols at the same address by sorting on type
3480 else if (amap
->type
< bmap
->type
)
3488 _bfd_aarch64_erratum_835769_stub_name (unsigned num_fixes
)
3490 char *stub_name
= (char *) bfd_malloc
3491 (strlen ("__erratum_835769_veneer_") + 16);
3492 sprintf (stub_name
,"__erratum_835769_veneer_%d", num_fixes
);
3496 /* Scan for Cortex-A53 erratum 835769 sequence.
3498 Return TRUE else FALSE on abnormal termination. */
3501 _bfd_aarch64_erratum_835769_scan (bfd
*input_bfd
,
3502 struct bfd_link_info
*info
,
3503 unsigned int *num_fixes_p
)
3506 struct elf_aarch64_link_hash_table
*htab
= elf_aarch64_hash_table (info
);
3507 unsigned int num_fixes
= *num_fixes_p
;
3512 for (section
= input_bfd
->sections
;
3514 section
= section
->next
)
3516 bfd_byte
*contents
= NULL
;
3517 struct _aarch64_elf_section_data
*sec_data
;
3520 if (elf_section_type (section
) != SHT_PROGBITS
3521 || (elf_section_flags (section
) & SHF_EXECINSTR
) == 0
3522 || (section
->flags
& SEC_EXCLUDE
) != 0
3523 || (section
->sec_info_type
== SEC_INFO_TYPE_JUST_SYMS
)
3524 || (section
->output_section
== bfd_abs_section_ptr
))
3527 if (elf_section_data (section
)->this_hdr
.contents
!= NULL
)
3528 contents
= elf_section_data (section
)->this_hdr
.contents
;
3529 else if (! bfd_malloc_and_get_section (input_bfd
, section
, &contents
))
3532 sec_data
= elf_aarch64_section_data (section
);
3534 qsort (sec_data
->map
, sec_data
->mapcount
,
3535 sizeof (elf_aarch64_section_map
), elf_aarch64_compare_mapping
);
3537 for (span
= 0; span
< sec_data
->mapcount
; span
++)
3539 unsigned int span_start
= sec_data
->map
[span
].vma
;
3540 unsigned int span_end
= ((span
== sec_data
->mapcount
- 1)
3541 ? sec_data
->map
[0].vma
+ section
->size
3542 : sec_data
->map
[span
+ 1].vma
);
3544 char span_type
= sec_data
->map
[span
].type
;
3546 if (span_type
== 'd')
3549 for (i
= span_start
; i
+ 4 < span_end
; i
+= 4)
3551 uint32_t insn_1
= bfd_getl32 (contents
+ i
);
3552 uint32_t insn_2
= bfd_getl32 (contents
+ i
+ 4);
3554 if (aarch64_erratum_sequence (insn_1
, insn_2
))
3556 struct elf_aarch64_stub_hash_entry
*stub_entry
;
3557 char *stub_name
= _bfd_aarch64_erratum_835769_stub_name (num_fixes
);
3561 stub_entry
= _bfd_aarch64_add_stub_entry_in_group (stub_name
,
3567 stub_entry
->stub_type
= aarch64_stub_erratum_835769_veneer
;
3568 stub_entry
->target_section
= section
;
3569 stub_entry
->target_value
= i
+ 4;
3570 stub_entry
->veneered_insn
= insn_2
;
3571 stub_entry
->output_name
= stub_name
;
3576 if (elf_section_data (section
)->this_hdr
.contents
== NULL
)
3580 *num_fixes_p
= num_fixes
;
3586 /* Test if instruction INSN is ADRP. */
3589 _bfd_aarch64_adrp_p (uint32_t insn
)
3591 return ((insn
& 0x9f000000) == 0x90000000);
3595 /* Helper predicate to look for cortex-a53 erratum 843419 sequence 1. */
3598 _bfd_aarch64_erratum_843419_sequence_p (uint32_t insn_1
, uint32_t insn_2
,
3606 return (aarch64_mem_op_p (insn_2
, &rt
, &rt2
, &pair
, &load
)
3609 && AARCH64_LDST_UIMM (insn_3
)
3610 && AARCH64_RN (insn_3
) == AARCH64_RD (insn_1
));
3614 /* Test for the presence of Cortex-A53 erratum 843419 instruction sequence.
3616 Return TRUE if section CONTENTS at offset I contains one of the
3617 erratum 843419 sequences, otherwise return FALSE. If a sequence is
3618 seen set P_VENEER_I to the offset of the final LOAD/STORE
3619 instruction in the sequence.
3623 _bfd_aarch64_erratum_843419_p (bfd_byte
*contents
, bfd_vma vma
,
3624 bfd_vma i
, bfd_vma span_end
,
3625 bfd_vma
*p_veneer_i
)
3627 uint32_t insn_1
= bfd_getl32 (contents
+ i
);
3629 if (!_bfd_aarch64_adrp_p (insn_1
))
3632 if (span_end
< i
+ 12)
3635 uint32_t insn_2
= bfd_getl32 (contents
+ i
+ 4);
3636 uint32_t insn_3
= bfd_getl32 (contents
+ i
+ 8);
3638 if ((vma
& 0xfff) != 0xff8 && (vma
& 0xfff) != 0xffc)
3641 if (_bfd_aarch64_erratum_843419_sequence_p (insn_1
, insn_2
, insn_3
))
3643 *p_veneer_i
= i
+ 8;
3647 if (span_end
< i
+ 16)
3650 uint32_t insn_4
= bfd_getl32 (contents
+ i
+ 12);
3652 if (_bfd_aarch64_erratum_843419_sequence_p (insn_1
, insn_2
, insn_4
))
3654 *p_veneer_i
= i
+ 12;
3662 /* Resize all stub sections. */
3665 _bfd_aarch64_resize_stubs (struct elf_aarch64_link_hash_table
*htab
)
3669 /* OK, we've added some stubs. Find out the new size of the
3671 for (section
= htab
->stub_bfd
->sections
;
3672 section
!= NULL
; section
= section
->next
)
3674 /* Ignore non-stub sections. */
3675 if (!strstr (section
->name
, STUB_SUFFIX
))
3680 bfd_hash_traverse (&htab
->stub_hash_table
, aarch64_size_one_stub
, htab
);
3682 for (section
= htab
->stub_bfd
->sections
;
3683 section
!= NULL
; section
= section
->next
)
3685 if (!strstr (section
->name
, STUB_SUFFIX
))
3691 /* Ensure all stub sections have a size which is a multiple of
3692 4096. This is important in order to ensure that the insertion
3693 of stub sections does not in itself move existing code around
3694 in such a way that new errata sequences are created. */
3695 if (htab
->fix_erratum_843419
)
3697 section
->size
= BFD_ALIGN (section
->size
, 0x1000);
3702 /* Construct an erratum 843419 workaround stub name.
3706 _bfd_aarch64_erratum_843419_stub_name (asection
*input_section
,
3709 const bfd_size_type len
= 8 + 4 + 1 + 8 + 1 + 16 + 1;
3710 char *stub_name
= bfd_malloc (len
);
3712 if (stub_name
!= NULL
)
3713 snprintf (stub_name
, len
, "e843419@%04x_%08x_%" BFD_VMA_FMT
"x",
3714 input_section
->owner
->id
,
3720 /* Build a stub_entry structure describing an 843419 fixup.
3722 The stub_entry constructed is populated with the bit pattern INSN
3723 of the instruction located at OFFSET within input SECTION.
3725 Returns TRUE on success. */
3728 _bfd_aarch64_erratum_843419_fixup (uint32_t insn
,
3729 bfd_vma adrp_offset
,
3730 bfd_vma ldst_offset
,
3732 struct bfd_link_info
*info
)
3734 struct elf_aarch64_link_hash_table
*htab
= elf_aarch64_hash_table (info
);
3736 struct elf_aarch64_stub_hash_entry
*stub_entry
;
3738 stub_name
= _bfd_aarch64_erratum_843419_stub_name (section
, ldst_offset
);
3739 stub_entry
= aarch64_stub_hash_lookup (&htab
->stub_hash_table
, stub_name
,
3747 /* We always place an 843419 workaround veneer in the stub section
3748 attached to the input section in which an erratum sequence has
3749 been found. This ensures that later in the link process (in
3750 elfNN_aarch64_write_section) when we copy the veneered
3751 instruction from the input section into the stub section the
3752 copied instruction will have had any relocations applied to it.
3753 If we placed workaround veneers in any other stub section then we
3754 could not assume that all relocations have been processed on the
3755 corresponding input section at the point we output the stub
3759 stub_entry
= _bfd_aarch64_add_stub_entry_after (stub_name
, section
, htab
);
3760 if (stub_entry
== NULL
)
3766 stub_entry
->adrp_offset
= adrp_offset
;
3767 stub_entry
->target_value
= ldst_offset
;
3768 stub_entry
->target_section
= section
;
3769 stub_entry
->stub_type
= aarch64_stub_erratum_843419_veneer
;
3770 stub_entry
->veneered_insn
= insn
;
3771 stub_entry
->output_name
= stub_name
;
3777 /* Scan an input section looking for the signature of erratum 843419.
3779 Scans input SECTION in INPUT_BFD looking for erratum 843419
3780 signatures, for each signature found a stub_entry is created
3781 describing the location of the erratum for subsequent fixup.
3783 Return TRUE on successful scan, FALSE on failure to scan.
3787 _bfd_aarch64_erratum_843419_scan (bfd
*input_bfd
, asection
*section
,
3788 struct bfd_link_info
*info
)
3790 struct elf_aarch64_link_hash_table
*htab
= elf_aarch64_hash_table (info
);
3795 if (elf_section_type (section
) != SHT_PROGBITS
3796 || (elf_section_flags (section
) & SHF_EXECINSTR
) == 0
3797 || (section
->flags
& SEC_EXCLUDE
) != 0
3798 || (section
->sec_info_type
== SEC_INFO_TYPE_JUST_SYMS
)
3799 || (section
->output_section
== bfd_abs_section_ptr
))
3804 bfd_byte
*contents
= NULL
;
3805 struct _aarch64_elf_section_data
*sec_data
;
3808 if (elf_section_data (section
)->this_hdr
.contents
!= NULL
)
3809 contents
= elf_section_data (section
)->this_hdr
.contents
;
3810 else if (! bfd_malloc_and_get_section (input_bfd
, section
, &contents
))
3813 sec_data
= elf_aarch64_section_data (section
);
3815 qsort (sec_data
->map
, sec_data
->mapcount
,
3816 sizeof (elf_aarch64_section_map
), elf_aarch64_compare_mapping
);
3818 for (span
= 0; span
< sec_data
->mapcount
; span
++)
3820 unsigned int span_start
= sec_data
->map
[span
].vma
;
3821 unsigned int span_end
= ((span
== sec_data
->mapcount
- 1)
3822 ? sec_data
->map
[0].vma
+ section
->size
3823 : sec_data
->map
[span
+ 1].vma
);
3825 char span_type
= sec_data
->map
[span
].type
;
3827 if (span_type
== 'd')
3830 for (i
= span_start
; i
+ 8 < span_end
; i
+= 4)
3832 bfd_vma vma
= (section
->output_section
->vma
3833 + section
->output_offset
3837 if (_bfd_aarch64_erratum_843419_p
3838 (contents
, vma
, i
, span_end
, &veneer_i
))
3840 uint32_t insn
= bfd_getl32 (contents
+ veneer_i
);
3842 if (!_bfd_aarch64_erratum_843419_fixup (insn
, i
, veneer_i
,
3849 if (elf_section_data (section
)->this_hdr
.contents
== NULL
)
3858 /* Determine and set the size of the stub section for a final link.
3860 The basic idea here is to examine all the relocations looking for
3861 PC-relative calls to a target that is unreachable with a "bl"
3865 elfNN_aarch64_size_stubs (bfd
*output_bfd
,
3867 struct bfd_link_info
*info
,
3868 bfd_signed_vma group_size
,
3869 asection
* (*add_stub_section
) (const char *,
3871 void (*layout_sections_again
) (void))
3873 bfd_size_type stub_group_size
;
3874 bfd_boolean stubs_always_before_branch
;
3875 bfd_boolean stub_changed
= FALSE
;
3876 struct elf_aarch64_link_hash_table
*htab
= elf_aarch64_hash_table (info
);
3877 unsigned int num_erratum_835769_fixes
= 0;
3879 /* Propagate mach to stub bfd, because it may not have been
3880 finalized when we created stub_bfd. */
3881 bfd_set_arch_mach (stub_bfd
, bfd_get_arch (output_bfd
),
3882 bfd_get_mach (output_bfd
));
3884 /* Stash our params away. */
3885 htab
->stub_bfd
= stub_bfd
;
3886 htab
->add_stub_section
= add_stub_section
;
3887 htab
->layout_sections_again
= layout_sections_again
;
3888 stubs_always_before_branch
= group_size
< 0;
3890 stub_group_size
= -group_size
;
3892 stub_group_size
= group_size
;
3894 if (stub_group_size
== 1)
3896 /* Default values. */
3897 /* AArch64 branch range is +-128MB. The value used is 1MB less. */
3898 stub_group_size
= 127 * 1024 * 1024;
3901 group_sections (htab
, stub_group_size
, stubs_always_before_branch
);
3903 (*htab
->layout_sections_again
) ();
3905 if (htab
->fix_erratum_835769
)
3909 for (input_bfd
= info
->input_bfds
;
3910 input_bfd
!= NULL
; input_bfd
= input_bfd
->link
.next
)
3911 if (!_bfd_aarch64_erratum_835769_scan (input_bfd
, info
,
3912 &num_erratum_835769_fixes
))
3915 _bfd_aarch64_resize_stubs (htab
);
3916 (*htab
->layout_sections_again
) ();
3919 if (htab
->fix_erratum_843419
)
3923 for (input_bfd
= info
->input_bfds
;
3925 input_bfd
= input_bfd
->link
.next
)
3929 for (section
= input_bfd
->sections
;
3931 section
= section
->next
)
3932 if (!_bfd_aarch64_erratum_843419_scan (input_bfd
, section
, info
))
3936 _bfd_aarch64_resize_stubs (htab
);
3937 (*htab
->layout_sections_again
) ();
3944 for (input_bfd
= info
->input_bfds
;
3945 input_bfd
!= NULL
; input_bfd
= input_bfd
->link
.next
)
3947 Elf_Internal_Shdr
*symtab_hdr
;
3949 Elf_Internal_Sym
*local_syms
= NULL
;
3951 /* We'll need the symbol table in a second. */
3952 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
3953 if (symtab_hdr
->sh_info
== 0)
3956 /* Walk over each section attached to the input bfd. */
3957 for (section
= input_bfd
->sections
;
3958 section
!= NULL
; section
= section
->next
)
3960 Elf_Internal_Rela
*internal_relocs
, *irelaend
, *irela
;
3962 /* If there aren't any relocs, then there's nothing more
3964 if ((section
->flags
& SEC_RELOC
) == 0
3965 || section
->reloc_count
== 0
3966 || (section
->flags
& SEC_CODE
) == 0)
3969 /* If this section is a link-once section that will be
3970 discarded, then don't create any stubs. */
3971 if (section
->output_section
== NULL
3972 || section
->output_section
->owner
!= output_bfd
)
3975 /* Get the relocs. */
3977 = _bfd_elf_link_read_relocs (input_bfd
, section
, NULL
,
3978 NULL
, info
->keep_memory
);
3979 if (internal_relocs
== NULL
)
3980 goto error_ret_free_local
;
3982 /* Now examine each relocation. */
3983 irela
= internal_relocs
;
3984 irelaend
= irela
+ section
->reloc_count
;
3985 for (; irela
< irelaend
; irela
++)
3987 unsigned int r_type
, r_indx
;
3988 enum elf_aarch64_stub_type stub_type
;
3989 struct elf_aarch64_stub_hash_entry
*stub_entry
;
3992 bfd_vma destination
;
3993 struct elf_aarch64_link_hash_entry
*hash
;
3994 const char *sym_name
;
3996 const asection
*id_sec
;
3997 unsigned char st_type
;
4000 r_type
= ELFNN_R_TYPE (irela
->r_info
);
4001 r_indx
= ELFNN_R_SYM (irela
->r_info
);
4003 if (r_type
>= (unsigned int) R_AARCH64_end
)
4005 bfd_set_error (bfd_error_bad_value
);
4006 error_ret_free_internal
:
4007 if (elf_section_data (section
)->relocs
== NULL
)
4008 free (internal_relocs
);
4009 goto error_ret_free_local
;
4012 /* Only look for stubs on unconditional branch and
4013 branch and link instructions. */
4014 if (r_type
!= (unsigned int) AARCH64_R (CALL26
)
4015 && r_type
!= (unsigned int) AARCH64_R (JUMP26
))
4018 /* Now determine the call target, its name, value,
4025 if (r_indx
< symtab_hdr
->sh_info
)
4027 /* It's a local symbol. */
4028 Elf_Internal_Sym
*sym
;
4029 Elf_Internal_Shdr
*hdr
;
4031 if (local_syms
== NULL
)
4034 = (Elf_Internal_Sym
*) symtab_hdr
->contents
;
4035 if (local_syms
== NULL
)
4037 = bfd_elf_get_elf_syms (input_bfd
, symtab_hdr
,
4038 symtab_hdr
->sh_info
, 0,
4040 if (local_syms
== NULL
)
4041 goto error_ret_free_internal
;
4044 sym
= local_syms
+ r_indx
;
4045 hdr
= elf_elfsections (input_bfd
)[sym
->st_shndx
];
4046 sym_sec
= hdr
->bfd_section
;
4048 /* This is an undefined symbol. It can never
4052 if (ELF_ST_TYPE (sym
->st_info
) != STT_SECTION
)
4053 sym_value
= sym
->st_value
;
4054 destination
= (sym_value
+ irela
->r_addend
4055 + sym_sec
->output_offset
4056 + sym_sec
->output_section
->vma
);
4057 st_type
= ELF_ST_TYPE (sym
->st_info
);
4059 = bfd_elf_string_from_elf_section (input_bfd
,
4060 symtab_hdr
->sh_link
,
4067 e_indx
= r_indx
- symtab_hdr
->sh_info
;
4068 hash
= ((struct elf_aarch64_link_hash_entry
*)
4069 elf_sym_hashes (input_bfd
)[e_indx
]);
4071 while (hash
->root
.root
.type
== bfd_link_hash_indirect
4072 || hash
->root
.root
.type
== bfd_link_hash_warning
)
4073 hash
= ((struct elf_aarch64_link_hash_entry
*)
4074 hash
->root
.root
.u
.i
.link
);
4076 if (hash
->root
.root
.type
== bfd_link_hash_defined
4077 || hash
->root
.root
.type
== bfd_link_hash_defweak
)
4079 struct elf_aarch64_link_hash_table
*globals
=
4080 elf_aarch64_hash_table (info
);
4081 sym_sec
= hash
->root
.root
.u
.def
.section
;
4082 sym_value
= hash
->root
.root
.u
.def
.value
;
4083 /* For a destination in a shared library,
4084 use the PLT stub as target address to
4085 decide whether a branch stub is
4087 if (globals
->root
.splt
!= NULL
&& hash
!= NULL
4088 && hash
->root
.plt
.offset
!= (bfd_vma
) - 1)
4090 sym_sec
= globals
->root
.splt
;
4091 sym_value
= hash
->root
.plt
.offset
;
4092 if (sym_sec
->output_section
!= NULL
)
4093 destination
= (sym_value
4094 + sym_sec
->output_offset
4096 sym_sec
->output_section
->vma
);
4098 else if (sym_sec
->output_section
!= NULL
)
4099 destination
= (sym_value
+ irela
->r_addend
4100 + sym_sec
->output_offset
4101 + sym_sec
->output_section
->vma
);
4103 else if (hash
->root
.root
.type
== bfd_link_hash_undefined
4104 || (hash
->root
.root
.type
4105 == bfd_link_hash_undefweak
))
4107 /* For a shared library, use the PLT stub as
4108 target address to decide whether a long
4109 branch stub is needed.
4110 For absolute code, they cannot be handled. */
4111 struct elf_aarch64_link_hash_table
*globals
=
4112 elf_aarch64_hash_table (info
);
4114 if (globals
->root
.splt
!= NULL
&& hash
!= NULL
4115 && hash
->root
.plt
.offset
!= (bfd_vma
) - 1)
4117 sym_sec
= globals
->root
.splt
;
4118 sym_value
= hash
->root
.plt
.offset
;
4119 if (sym_sec
->output_section
!= NULL
)
4120 destination
= (sym_value
4121 + sym_sec
->output_offset
4123 sym_sec
->output_section
->vma
);
4130 bfd_set_error (bfd_error_bad_value
);
4131 goto error_ret_free_internal
;
4133 st_type
= ELF_ST_TYPE (hash
->root
.type
);
4134 sym_name
= hash
->root
.root
.root
.string
;
4137 /* Determine what (if any) linker stub is needed. */
4138 stub_type
= aarch64_type_of_stub
4139 (info
, section
, irela
, sym_sec
, st_type
, hash
, destination
);
4140 if (stub_type
== aarch64_stub_none
)
4143 /* Support for grouping stub sections. */
4144 id_sec
= htab
->stub_group
[section
->id
].link_sec
;
4146 /* Get the name of this stub. */
4147 stub_name
= elfNN_aarch64_stub_name (id_sec
, sym_sec
, hash
,
4150 goto error_ret_free_internal
;
4153 aarch64_stub_hash_lookup (&htab
->stub_hash_table
,
4154 stub_name
, FALSE
, FALSE
);
4155 if (stub_entry
!= NULL
)
4157 /* The proper stub has already been created. */
4162 stub_entry
= _bfd_aarch64_add_stub_entry_in_group
4163 (stub_name
, section
, htab
);
4164 if (stub_entry
== NULL
)
4167 goto error_ret_free_internal
;
4170 stub_entry
->target_value
= sym_value
;
4171 stub_entry
->target_section
= sym_sec
;
4172 stub_entry
->stub_type
= stub_type
;
4173 stub_entry
->h
= hash
;
4174 stub_entry
->st_type
= st_type
;
4176 if (sym_name
== NULL
)
4177 sym_name
= "unnamed";
4178 len
= sizeof (STUB_ENTRY_NAME
) + strlen (sym_name
);
4179 stub_entry
->output_name
= bfd_alloc (htab
->stub_bfd
, len
);
4180 if (stub_entry
->output_name
== NULL
)
4183 goto error_ret_free_internal
;
4186 snprintf (stub_entry
->output_name
, len
, STUB_ENTRY_NAME
,
4189 stub_changed
= TRUE
;
4192 /* We're done with the internal relocs, free them. */
4193 if (elf_section_data (section
)->relocs
== NULL
)
4194 free (internal_relocs
);
4201 _bfd_aarch64_resize_stubs (htab
);
4203 /* Ask the linker to do its stuff. */
4204 (*htab
->layout_sections_again
) ();
4205 stub_changed
= FALSE
;
4210 error_ret_free_local
:
4214 /* Build all the stubs associated with the current output file. The
4215 stubs are kept in a hash table attached to the main linker hash
4216 table. We also set up the .plt entries for statically linked PIC
4217 functions here. This function is called via aarch64_elf_finish in the
4221 elfNN_aarch64_build_stubs (struct bfd_link_info
*info
)
4224 struct bfd_hash_table
*table
;
4225 struct elf_aarch64_link_hash_table
*htab
;
4227 htab
= elf_aarch64_hash_table (info
);
4229 for (stub_sec
= htab
->stub_bfd
->sections
;
4230 stub_sec
!= NULL
; stub_sec
= stub_sec
->next
)
4234 /* Ignore non-stub sections. */
4235 if (!strstr (stub_sec
->name
, STUB_SUFFIX
))
4238 /* Allocate memory to hold the linker stubs. */
4239 size
= stub_sec
->size
;
4240 stub_sec
->contents
= bfd_zalloc (htab
->stub_bfd
, size
);
4241 if (stub_sec
->contents
== NULL
&& size
!= 0)
4245 bfd_putl32 (0x14000000 | (size
>> 2), stub_sec
->contents
);
4246 stub_sec
->size
+= 4;
4249 /* Build the stubs as directed by the stub hash table. */
4250 table
= &htab
->stub_hash_table
;
4251 bfd_hash_traverse (table
, aarch64_build_one_stub
, info
);
4257 /* Add an entry to the code/data map for section SEC. */
4260 elfNN_aarch64_section_map_add (asection
*sec
, char type
, bfd_vma vma
)
4262 struct _aarch64_elf_section_data
*sec_data
=
4263 elf_aarch64_section_data (sec
);
4264 unsigned int newidx
;
4266 if (sec_data
->map
== NULL
)
4268 sec_data
->map
= bfd_malloc (sizeof (elf_aarch64_section_map
));
4269 sec_data
->mapcount
= 0;
4270 sec_data
->mapsize
= 1;
4273 newidx
= sec_data
->mapcount
++;
4275 if (sec_data
->mapcount
> sec_data
->mapsize
)
4277 sec_data
->mapsize
*= 2;
4278 sec_data
->map
= bfd_realloc_or_free
4279 (sec_data
->map
, sec_data
->mapsize
* sizeof (elf_aarch64_section_map
));
4284 sec_data
->map
[newidx
].vma
= vma
;
4285 sec_data
->map
[newidx
].type
= type
;
4290 /* Initialise maps of insn/data for input BFDs. */
4292 bfd_elfNN_aarch64_init_maps (bfd
*abfd
)
4294 Elf_Internal_Sym
*isymbuf
;
4295 Elf_Internal_Shdr
*hdr
;
4296 unsigned int i
, localsyms
;
4298 /* Make sure that we are dealing with an AArch64 elf binary. */
4299 if (!is_aarch64_elf (abfd
))
4302 if ((abfd
->flags
& DYNAMIC
) != 0)
4305 hdr
= &elf_symtab_hdr (abfd
);
4306 localsyms
= hdr
->sh_info
;
4308 /* Obtain a buffer full of symbols for this BFD. The hdr->sh_info field
4309 should contain the number of local symbols, which should come before any
4310 global symbols. Mapping symbols are always local. */
4311 isymbuf
= bfd_elf_get_elf_syms (abfd
, hdr
, localsyms
, 0, NULL
, NULL
, NULL
);
4313 /* No internal symbols read? Skip this BFD. */
4314 if (isymbuf
== NULL
)
4317 for (i
= 0; i
< localsyms
; i
++)
4319 Elf_Internal_Sym
*isym
= &isymbuf
[i
];
4320 asection
*sec
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
4323 if (sec
!= NULL
&& ELF_ST_BIND (isym
->st_info
) == STB_LOCAL
)
4325 name
= bfd_elf_string_from_elf_section (abfd
,
4329 if (bfd_is_aarch64_special_symbol_name
4330 (name
, BFD_AARCH64_SPECIAL_SYM_TYPE_MAP
))
4331 elfNN_aarch64_section_map_add (sec
, name
[1], isym
->st_value
);
4336 /* Set option values needed during linking. */
4338 bfd_elfNN_aarch64_set_options (struct bfd
*output_bfd
,
4339 struct bfd_link_info
*link_info
,
4341 int no_wchar_warn
, int pic_veneer
,
4342 int fix_erratum_835769
,
4343 int fix_erratum_843419
)
4345 struct elf_aarch64_link_hash_table
*globals
;
4347 globals
= elf_aarch64_hash_table (link_info
);
4348 globals
->pic_veneer
= pic_veneer
;
4349 globals
->fix_erratum_835769
= fix_erratum_835769
;
4350 globals
->fix_erratum_843419
= fix_erratum_843419
;
4351 globals
->fix_erratum_843419_adr
= TRUE
;
4353 BFD_ASSERT (is_aarch64_elf (output_bfd
));
4354 elf_aarch64_tdata (output_bfd
)->no_enum_size_warning
= no_enum_warn
;
4355 elf_aarch64_tdata (output_bfd
)->no_wchar_size_warning
= no_wchar_warn
;
4359 aarch64_calculate_got_entry_vma (struct elf_link_hash_entry
*h
,
4360 struct elf_aarch64_link_hash_table
4361 *globals
, struct bfd_link_info
*info
,
4362 bfd_vma value
, bfd
*output_bfd
,
4363 bfd_boolean
*unresolved_reloc_p
)
4365 bfd_vma off
= (bfd_vma
) - 1;
4366 asection
*basegot
= globals
->root
.sgot
;
4367 bfd_boolean dyn
= globals
->root
.dynamic_sections_created
;
4371 BFD_ASSERT (basegot
!= NULL
);
4372 off
= h
->got
.offset
;
4373 BFD_ASSERT (off
!= (bfd_vma
) - 1);
4374 if (!WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, bfd_link_pic (info
), h
)
4375 || (bfd_link_pic (info
)
4376 && SYMBOL_REFERENCES_LOCAL (info
, h
))
4377 || (ELF_ST_VISIBILITY (h
->other
)
4378 && h
->root
.type
== bfd_link_hash_undefweak
))
4380 /* This is actually a static link, or it is a -Bsymbolic link
4381 and the symbol is defined locally. We must initialize this
4382 entry in the global offset table. Since the offset must
4383 always be a multiple of 8 (4 in the case of ILP32), we use
4384 the least significant bit to record whether we have
4385 initialized it already.
4386 When doing a dynamic link, we create a .rel(a).got relocation
4387 entry to initialize the value. This is done in the
4388 finish_dynamic_symbol routine. */
4393 bfd_put_NN (output_bfd
, value
, basegot
->contents
+ off
);
4398 *unresolved_reloc_p
= FALSE
;
4400 off
= off
+ basegot
->output_section
->vma
+ basegot
->output_offset
;
4406 /* Change R_TYPE to a more efficient access model where possible,
4407 return the new reloc type. */
4409 static bfd_reloc_code_real_type
4410 aarch64_tls_transition_without_check (bfd_reloc_code_real_type r_type
,
4411 struct elf_link_hash_entry
*h
)
4413 bfd_boolean is_local
= h
== NULL
;
4417 case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21
:
4418 case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21
:
4420 ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1
4421 : BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21
);
4423 case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21
:
4425 ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC
4428 case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19
:
4430 ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1
4431 : BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19
);
4433 case BFD_RELOC_AARCH64_TLSDESC_LDNN_LO12_NC
:
4434 case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC
:
4436 ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC
4437 : BFD_RELOC_AARCH64_TLSIE_LDNN_GOTTPREL_LO12_NC
);
4439 case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21
:
4440 return is_local
? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1
: r_type
;
4442 case BFD_RELOC_AARCH64_TLSIE_LDNN_GOTTPREL_LO12_NC
:
4443 return is_local
? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC
: r_type
;
4445 case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19
:
4448 case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21
:
4450 ? BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_HI12
4451 : BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19
);
4453 case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12_NC
:
4454 case BFD_RELOC_AARCH64_TLSDESC_CALL
:
4455 /* Instructions with these relocations will become NOPs. */
4456 return BFD_RELOC_AARCH64_NONE
;
4458 case BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC
:
4459 case BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21
:
4460 case BFD_RELOC_AARCH64_TLSLD_ADR_PREL21
:
4461 return is_local
? BFD_RELOC_AARCH64_NONE
: r_type
;
4471 aarch64_reloc_got_type (bfd_reloc_code_real_type r_type
)
4475 case BFD_RELOC_AARCH64_ADR_GOT_PAGE
:
4476 case BFD_RELOC_AARCH64_GOT_LD_PREL19
:
4477 case BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14
:
4478 case BFD_RELOC_AARCH64_LD32_GOT_LO12_NC
:
4479 case BFD_RELOC_AARCH64_LD64_GOTOFF_LO15
:
4480 case BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15
:
4481 case BFD_RELOC_AARCH64_LD64_GOT_LO12_NC
:
4482 case BFD_RELOC_AARCH64_MOVW_GOTOFF_G0_NC
:
4483 case BFD_RELOC_AARCH64_MOVW_GOTOFF_G1
:
4486 case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC
:
4487 case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21
:
4488 case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21
:
4489 case BFD_RELOC_AARCH64_TLSGD_MOVW_G0_NC
:
4490 case BFD_RELOC_AARCH64_TLSGD_MOVW_G1
:
4491 case BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC
:
4492 case BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21
:
4493 case BFD_RELOC_AARCH64_TLSLD_ADR_PREL21
:
4496 case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12_NC
:
4497 case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21
:
4498 case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21
:
4499 case BFD_RELOC_AARCH64_TLSDESC_CALL
:
4500 case BFD_RELOC_AARCH64_TLSDESC_LD32_LO12_NC
:
4501 case BFD_RELOC_AARCH64_TLSDESC_LD64_LO12_NC
:
4502 case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19
:
4503 return GOT_TLSDESC_GD
;
4505 case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21
:
4506 case BFD_RELOC_AARCH64_TLSIE_LD32_GOTTPREL_LO12_NC
:
4507 case BFD_RELOC_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC
:
4508 case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19
:
4509 case BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G0_NC
:
4510 case BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G1
:
4520 aarch64_can_relax_tls (bfd
*input_bfd
,
4521 struct bfd_link_info
*info
,
4522 bfd_reloc_code_real_type r_type
,
4523 struct elf_link_hash_entry
*h
,
4524 unsigned long r_symndx
)
4526 unsigned int symbol_got_type
;
4527 unsigned int reloc_got_type
;
4529 if (! IS_AARCH64_TLS_RELAX_RELOC (r_type
))
4532 symbol_got_type
= elfNN_aarch64_symbol_got_type (h
, input_bfd
, r_symndx
);
4533 reloc_got_type
= aarch64_reloc_got_type (r_type
);
4535 if (symbol_got_type
== GOT_TLS_IE
&& GOT_TLS_GD_ANY_P (reloc_got_type
))
4538 if (bfd_link_pic (info
))
4541 if (h
&& h
->root
.type
== bfd_link_hash_undefweak
)
4547 /* Given the relocation code R_TYPE, return the relaxed bfd reloc
4550 static bfd_reloc_code_real_type
4551 aarch64_tls_transition (bfd
*input_bfd
,
4552 struct bfd_link_info
*info
,
4553 unsigned int r_type
,
4554 struct elf_link_hash_entry
*h
,
4555 unsigned long r_symndx
)
4557 bfd_reloc_code_real_type bfd_r_type
4558 = elfNN_aarch64_bfd_reloc_from_type (r_type
);
4560 if (! aarch64_can_relax_tls (input_bfd
, info
, bfd_r_type
, h
, r_symndx
))
4563 return aarch64_tls_transition_without_check (bfd_r_type
, h
);
4566 /* Return the base VMA address which should be subtracted from real addresses
4567 when resolving R_AARCH64_TLS_DTPREL relocation. */
4570 dtpoff_base (struct bfd_link_info
*info
)
4572 /* If tls_sec is NULL, we should have signalled an error already. */
4573 BFD_ASSERT (elf_hash_table (info
)->tls_sec
!= NULL
);
4574 return elf_hash_table (info
)->tls_sec
->vma
;
4577 /* Return the base VMA address which should be subtracted from real addresses
4578 when resolving R_AARCH64_TLS_GOTTPREL64 relocations. */
4581 tpoff_base (struct bfd_link_info
*info
)
4583 struct elf_link_hash_table
*htab
= elf_hash_table (info
);
4585 /* If tls_sec is NULL, we should have signalled an error already. */
4586 BFD_ASSERT (htab
->tls_sec
!= NULL
);
4588 bfd_vma base
= align_power ((bfd_vma
) TCB_SIZE
,
4589 htab
->tls_sec
->alignment_power
);
4590 return htab
->tls_sec
->vma
- base
;
4594 symbol_got_offset_ref (bfd
*input_bfd
, struct elf_link_hash_entry
*h
,
4595 unsigned long r_symndx
)
4597 /* Calculate the address of the GOT entry for symbol
4598 referred to in h. */
4600 return &h
->got
.offset
;
4604 struct elf_aarch64_local_symbol
*l
;
4606 l
= elf_aarch64_locals (input_bfd
);
4607 return &l
[r_symndx
].got_offset
;
4612 symbol_got_offset_mark (bfd
*input_bfd
, struct elf_link_hash_entry
*h
,
4613 unsigned long r_symndx
)
4616 p
= symbol_got_offset_ref (input_bfd
, h
, r_symndx
);
4621 symbol_got_offset_mark_p (bfd
*input_bfd
, struct elf_link_hash_entry
*h
,
4622 unsigned long r_symndx
)
4625 value
= * symbol_got_offset_ref (input_bfd
, h
, r_symndx
);
4630 symbol_got_offset (bfd
*input_bfd
, struct elf_link_hash_entry
*h
,
4631 unsigned long r_symndx
)
4634 value
= * symbol_got_offset_ref (input_bfd
, h
, r_symndx
);
4640 symbol_tlsdesc_got_offset_ref (bfd
*input_bfd
, struct elf_link_hash_entry
*h
,
4641 unsigned long r_symndx
)
4643 /* Calculate the address of the GOT entry for symbol
4644 referred to in h. */
4647 struct elf_aarch64_link_hash_entry
*eh
;
4648 eh
= (struct elf_aarch64_link_hash_entry
*) h
;
4649 return &eh
->tlsdesc_got_jump_table_offset
;
4654 struct elf_aarch64_local_symbol
*l
;
4656 l
= elf_aarch64_locals (input_bfd
);
4657 return &l
[r_symndx
].tlsdesc_got_jump_table_offset
;
4662 symbol_tlsdesc_got_offset_mark (bfd
*input_bfd
, struct elf_link_hash_entry
*h
,
4663 unsigned long r_symndx
)
4666 p
= symbol_tlsdesc_got_offset_ref (input_bfd
, h
, r_symndx
);
4671 symbol_tlsdesc_got_offset_mark_p (bfd
*input_bfd
,
4672 struct elf_link_hash_entry
*h
,
4673 unsigned long r_symndx
)
4676 value
= * symbol_tlsdesc_got_offset_ref (input_bfd
, h
, r_symndx
);
4681 symbol_tlsdesc_got_offset (bfd
*input_bfd
, struct elf_link_hash_entry
*h
,
4682 unsigned long r_symndx
)
4685 value
= * symbol_tlsdesc_got_offset_ref (input_bfd
, h
, r_symndx
);
4690 /* Data for make_branch_to_erratum_835769_stub(). */
4692 struct erratum_835769_branch_to_stub_data
4694 struct bfd_link_info
*info
;
4695 asection
*output_section
;
4699 /* Helper to insert branches to erratum 835769 stubs in the right
4700 places for a particular section. */
4703 make_branch_to_erratum_835769_stub (struct bfd_hash_entry
*gen_entry
,
4706 struct elf_aarch64_stub_hash_entry
*stub_entry
;
4707 struct erratum_835769_branch_to_stub_data
*data
;
4709 unsigned long branch_insn
= 0;
4710 bfd_vma veneered_insn_loc
, veneer_entry_loc
;
4711 bfd_signed_vma branch_offset
;
4712 unsigned int target
;
4715 stub_entry
= (struct elf_aarch64_stub_hash_entry
*) gen_entry
;
4716 data
= (struct erratum_835769_branch_to_stub_data
*) in_arg
;
4718 if (stub_entry
->target_section
!= data
->output_section
4719 || stub_entry
->stub_type
!= aarch64_stub_erratum_835769_veneer
)
4722 contents
= data
->contents
;
4723 veneered_insn_loc
= stub_entry
->target_section
->output_section
->vma
4724 + stub_entry
->target_section
->output_offset
4725 + stub_entry
->target_value
;
4726 veneer_entry_loc
= stub_entry
->stub_sec
->output_section
->vma
4727 + stub_entry
->stub_sec
->output_offset
4728 + stub_entry
->stub_offset
;
4729 branch_offset
= veneer_entry_loc
- veneered_insn_loc
;
4731 abfd
= stub_entry
->target_section
->owner
;
4732 if (!aarch64_valid_branch_p (veneer_entry_loc
, veneered_insn_loc
))
4733 (*_bfd_error_handler
)
4734 (_("%B: error: Erratum 835769 stub out "
4735 "of range (input file too large)"), abfd
);
4737 target
= stub_entry
->target_value
;
4738 branch_insn
= 0x14000000;
4739 branch_offset
>>= 2;
4740 branch_offset
&= 0x3ffffff;
4741 branch_insn
|= branch_offset
;
4742 bfd_putl32 (branch_insn
, &contents
[target
]);
4749 _bfd_aarch64_erratum_843419_branch_to_stub (struct bfd_hash_entry
*gen_entry
,
4752 struct elf_aarch64_stub_hash_entry
*stub_entry
4753 = (struct elf_aarch64_stub_hash_entry
*) gen_entry
;
4754 struct erratum_835769_branch_to_stub_data
*data
4755 = (struct erratum_835769_branch_to_stub_data
*) in_arg
;
4756 struct bfd_link_info
*info
;
4757 struct elf_aarch64_link_hash_table
*htab
;
4765 contents
= data
->contents
;
4766 section
= data
->output_section
;
4768 htab
= elf_aarch64_hash_table (info
);
4770 if (stub_entry
->target_section
!= section
4771 || stub_entry
->stub_type
!= aarch64_stub_erratum_843419_veneer
)
4774 insn
= bfd_getl32 (contents
+ stub_entry
->target_value
);
4776 stub_entry
->stub_sec
->contents
+ stub_entry
->stub_offset
);
4778 place
= (section
->output_section
->vma
+ section
->output_offset
4779 + stub_entry
->adrp_offset
);
4780 insn
= bfd_getl32 (contents
+ stub_entry
->adrp_offset
);
4782 if ((insn
& AARCH64_ADRP_OP_MASK
) != AARCH64_ADRP_OP
)
4785 bfd_signed_vma imm
=
4786 (_bfd_aarch64_sign_extend
4787 ((bfd_vma
) _bfd_aarch64_decode_adrp_imm (insn
) << 12, 33)
4790 if (htab
->fix_erratum_843419_adr
4791 && (imm
>= AARCH64_MIN_ADRP_IMM
&& imm
<= AARCH64_MAX_ADRP_IMM
))
4793 insn
= (_bfd_aarch64_reencode_adr_imm (AARCH64_ADR_OP
, imm
)
4794 | AARCH64_RT (insn
));
4795 bfd_putl32 (insn
, contents
+ stub_entry
->adrp_offset
);
4799 bfd_vma veneered_insn_loc
;
4800 bfd_vma veneer_entry_loc
;
4801 bfd_signed_vma branch_offset
;
4802 uint32_t branch_insn
;
4804 veneered_insn_loc
= stub_entry
->target_section
->output_section
->vma
4805 + stub_entry
->target_section
->output_offset
4806 + stub_entry
->target_value
;
4807 veneer_entry_loc
= stub_entry
->stub_sec
->output_section
->vma
4808 + stub_entry
->stub_sec
->output_offset
4809 + stub_entry
->stub_offset
;
4810 branch_offset
= veneer_entry_loc
- veneered_insn_loc
;
4812 abfd
= stub_entry
->target_section
->owner
;
4813 if (!aarch64_valid_branch_p (veneer_entry_loc
, veneered_insn_loc
))
4814 (*_bfd_error_handler
)
4815 (_("%B: error: Erratum 843419 stub out "
4816 "of range (input file too large)"), abfd
);
4818 branch_insn
= 0x14000000;
4819 branch_offset
>>= 2;
4820 branch_offset
&= 0x3ffffff;
4821 branch_insn
|= branch_offset
;
4822 bfd_putl32 (branch_insn
, contents
+ stub_entry
->target_value
);
4829 elfNN_aarch64_write_section (bfd
*output_bfd ATTRIBUTE_UNUSED
,
4830 struct bfd_link_info
*link_info
,
4835 struct elf_aarch64_link_hash_table
*globals
=
4836 elf_aarch64_hash_table (link_info
);
4838 if (globals
== NULL
)
4841 /* Fix code to point to erratum 835769 stubs. */
4842 if (globals
->fix_erratum_835769
)
4844 struct erratum_835769_branch_to_stub_data data
;
4846 data
.info
= link_info
;
4847 data
.output_section
= sec
;
4848 data
.contents
= contents
;
4849 bfd_hash_traverse (&globals
->stub_hash_table
,
4850 make_branch_to_erratum_835769_stub
, &data
);
4853 if (globals
->fix_erratum_843419
)
4855 struct erratum_835769_branch_to_stub_data data
;
4857 data
.info
= link_info
;
4858 data
.output_section
= sec
;
4859 data
.contents
= contents
;
4860 bfd_hash_traverse (&globals
->stub_hash_table
,
4861 _bfd_aarch64_erratum_843419_branch_to_stub
, &data
);
4867 /* Perform a relocation as part of a final link. */
4868 static bfd_reloc_status_type
4869 elfNN_aarch64_final_link_relocate (reloc_howto_type
*howto
,
4872 asection
*input_section
,
4874 Elf_Internal_Rela
*rel
,
4876 struct bfd_link_info
*info
,
4878 struct elf_link_hash_entry
*h
,
4879 bfd_boolean
*unresolved_reloc_p
,
4880 bfd_boolean save_addend
,
4881 bfd_vma
*saved_addend
,
4882 Elf_Internal_Sym
*sym
)
4884 Elf_Internal_Shdr
*symtab_hdr
;
4885 unsigned int r_type
= howto
->type
;
4886 bfd_reloc_code_real_type bfd_r_type
4887 = elfNN_aarch64_bfd_reloc_from_howto (howto
);
4888 bfd_reloc_code_real_type new_bfd_r_type
;
4889 unsigned long r_symndx
;
4890 bfd_byte
*hit_data
= contents
+ rel
->r_offset
;
4892 bfd_signed_vma signed_addend
;
4893 struct elf_aarch64_link_hash_table
*globals
;
4894 bfd_boolean weak_undef_p
;
4897 globals
= elf_aarch64_hash_table (info
);
4899 symtab_hdr
= &elf_symtab_hdr (input_bfd
);
4901 BFD_ASSERT (is_aarch64_elf (input_bfd
));
4903 r_symndx
= ELFNN_R_SYM (rel
->r_info
);
4905 /* It is possible to have linker relaxations on some TLS access
4906 models. Update our information here. */
4907 new_bfd_r_type
= aarch64_tls_transition (input_bfd
, info
, r_type
, h
, r_symndx
);
4908 if (new_bfd_r_type
!= bfd_r_type
)
4910 bfd_r_type
= new_bfd_r_type
;
4911 howto
= elfNN_aarch64_howto_from_bfd_reloc (bfd_r_type
);
4912 BFD_ASSERT (howto
!= NULL
);
4913 r_type
= howto
->type
;
4916 place
= input_section
->output_section
->vma
4917 + input_section
->output_offset
+ rel
->r_offset
;
4919 /* Get addend, accumulating the addend for consecutive relocs
4920 which refer to the same offset. */
4921 signed_addend
= saved_addend
? *saved_addend
: 0;
4922 signed_addend
+= rel
->r_addend
;
4924 weak_undef_p
= (h
? h
->root
.type
== bfd_link_hash_undefweak
4925 : bfd_is_und_section (sym_sec
));
4927 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle
4928 it here if it is defined in a non-shared object. */
4930 && h
->type
== STT_GNU_IFUNC
4937 if ((input_section
->flags
& SEC_ALLOC
) == 0
4938 || h
->plt
.offset
== (bfd_vma
) -1)
4941 /* STT_GNU_IFUNC symbol must go through PLT. */
4942 plt
= globals
->root
.splt
? globals
->root
.splt
: globals
->root
.iplt
;
4943 value
= (plt
->output_section
->vma
+ plt
->output_offset
+ h
->plt
.offset
);
4948 if (h
->root
.root
.string
)
4949 name
= h
->root
.root
.string
;
4951 name
= bfd_elf_sym_name (input_bfd
, symtab_hdr
, sym
,
4953 (*_bfd_error_handler
)
4954 (_("%B: relocation %s against STT_GNU_IFUNC "
4955 "symbol `%s' isn't handled by %s"), input_bfd
,
4956 howto
->name
, name
, __FUNCTION__
);
4957 bfd_set_error (bfd_error_bad_value
);
4960 case BFD_RELOC_AARCH64_NN
:
4961 if (rel
->r_addend
!= 0)
4963 if (h
->root
.root
.string
)
4964 name
= h
->root
.root
.string
;
4966 name
= bfd_elf_sym_name (input_bfd
, symtab_hdr
,
4968 (*_bfd_error_handler
)
4969 (_("%B: relocation %s against STT_GNU_IFUNC "
4970 "symbol `%s' has non-zero addend: %d"),
4971 input_bfd
, howto
->name
, name
, rel
->r_addend
);
4972 bfd_set_error (bfd_error_bad_value
);
4976 /* Generate dynamic relocation only when there is a
4977 non-GOT reference in a shared object. */
4978 if (bfd_link_pic (info
) && h
->non_got_ref
)
4980 Elf_Internal_Rela outrel
;
4983 /* Need a dynamic relocation to get the real function
4985 outrel
.r_offset
= _bfd_elf_section_offset (output_bfd
,
4989 if (outrel
.r_offset
== (bfd_vma
) -1
4990 || outrel
.r_offset
== (bfd_vma
) -2)
4993 outrel
.r_offset
+= (input_section
->output_section
->vma
4994 + input_section
->output_offset
);
4996 if (h
->dynindx
== -1
4998 || bfd_link_executable (info
))
5000 /* This symbol is resolved locally. */
5001 outrel
.r_info
= ELFNN_R_INFO (0, AARCH64_R (IRELATIVE
));
5002 outrel
.r_addend
= (h
->root
.u
.def
.value
5003 + h
->root
.u
.def
.section
->output_section
->vma
5004 + h
->root
.u
.def
.section
->output_offset
);
5008 outrel
.r_info
= ELFNN_R_INFO (h
->dynindx
, r_type
);
5009 outrel
.r_addend
= 0;
5012 sreloc
= globals
->root
.irelifunc
;
5013 elf_append_rela (output_bfd
, sreloc
, &outrel
);
5015 /* If this reloc is against an external symbol, we
5016 do not want to fiddle with the addend. Otherwise,
5017 we need to include the symbol value so that it
5018 becomes an addend for the dynamic reloc. For an
5019 internal symbol, we have updated addend. */
5020 return bfd_reloc_ok
;
5023 case BFD_RELOC_AARCH64_CALL26
:
5024 case BFD_RELOC_AARCH64_JUMP26
:
5025 value
= _bfd_aarch64_elf_resolve_relocation (bfd_r_type
, place
, value
,
5028 return _bfd_aarch64_elf_put_addend (input_bfd
, hit_data
, bfd_r_type
,
5030 case BFD_RELOC_AARCH64_ADR_GOT_PAGE
:
5031 case BFD_RELOC_AARCH64_GOT_LD_PREL19
:
5032 case BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14
:
5033 case BFD_RELOC_AARCH64_LD32_GOT_LO12_NC
:
5034 case BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15
:
5035 case BFD_RELOC_AARCH64_MOVW_GOTOFF_G0_NC
:
5036 case BFD_RELOC_AARCH64_MOVW_GOTOFF_G1
:
5037 case BFD_RELOC_AARCH64_LD64_GOTOFF_LO15
:
5038 case BFD_RELOC_AARCH64_LD64_GOT_LO12_NC
:
5039 base_got
= globals
->root
.sgot
;
5040 off
= h
->got
.offset
;
5042 if (base_got
== NULL
)
5045 if (off
== (bfd_vma
) -1)
5049 /* We can't use h->got.offset here to save state, or
5050 even just remember the offset, as finish_dynamic_symbol
5051 would use that as offset into .got. */
5053 if (globals
->root
.splt
!= NULL
)
5055 plt_index
= ((h
->plt
.offset
- globals
->plt_header_size
) /
5056 globals
->plt_entry_size
);
5057 off
= (plt_index
+ 3) * GOT_ENTRY_SIZE
;
5058 base_got
= globals
->root
.sgotplt
;
5062 plt_index
= h
->plt
.offset
/ globals
->plt_entry_size
;
5063 off
= plt_index
* GOT_ENTRY_SIZE
;
5064 base_got
= globals
->root
.igotplt
;
5067 if (h
->dynindx
== -1
5071 /* This references the local definition. We must
5072 initialize this entry in the global offset table.
5073 Since the offset must always be a multiple of 8,
5074 we use the least significant bit to record
5075 whether we have initialized it already.
5077 When doing a dynamic link, we create a .rela.got
5078 relocation entry to initialize the value. This
5079 is done in the finish_dynamic_symbol routine. */
5084 bfd_put_NN (output_bfd
, value
,
5085 base_got
->contents
+ off
);
5086 /* Note that this is harmless as -1 | 1 still is -1. */
5090 value
= (base_got
->output_section
->vma
5091 + base_got
->output_offset
+ off
);
5094 value
= aarch64_calculate_got_entry_vma (h
, globals
, info
,
5096 unresolved_reloc_p
);
5100 case BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14
:
5101 case BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15
:
5102 addend
= (globals
->root
.sgot
->output_section
->vma
5103 + globals
->root
.sgot
->output_offset
);
5105 case BFD_RELOC_AARCH64_MOVW_GOTOFF_G0_NC
:
5106 case BFD_RELOC_AARCH64_MOVW_GOTOFF_G1
:
5107 case BFD_RELOC_AARCH64_LD64_GOTOFF_LO15
:
5108 value
= (value
- globals
->root
.sgot
->output_section
->vma
5109 - globals
->root
.sgot
->output_offset
);
5114 value
= _bfd_aarch64_elf_resolve_relocation (bfd_r_type
, place
, value
,
5115 addend
, weak_undef_p
);
5116 return _bfd_aarch64_elf_put_addend (input_bfd
, hit_data
, bfd_r_type
, howto
, value
);
5117 case BFD_RELOC_AARCH64_ADD_LO12
:
5118 case BFD_RELOC_AARCH64_ADR_HI21_PCREL
:
5125 case BFD_RELOC_AARCH64_NONE
:
5126 case BFD_RELOC_AARCH64_TLSDESC_CALL
:
5127 *unresolved_reloc_p
= FALSE
;
5128 return bfd_reloc_ok
;
5130 case BFD_RELOC_AARCH64_NN
:
5132 /* When generating a shared object or relocatable executable, these
5133 relocations are copied into the output file to be resolved at
5135 if (((bfd_link_pic (info
) == TRUE
)
5136 || globals
->root
.is_relocatable_executable
)
5137 && (input_section
->flags
& SEC_ALLOC
)
5139 || ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
5140 || h
->root
.type
!= bfd_link_hash_undefweak
))
5142 Elf_Internal_Rela outrel
;
5144 bfd_boolean skip
, relocate
;
5147 *unresolved_reloc_p
= FALSE
;
5152 outrel
.r_addend
= signed_addend
;
5154 _bfd_elf_section_offset (output_bfd
, info
, input_section
,
5156 if (outrel
.r_offset
== (bfd_vma
) - 1)
5158 else if (outrel
.r_offset
== (bfd_vma
) - 2)
5164 outrel
.r_offset
+= (input_section
->output_section
->vma
5165 + input_section
->output_offset
);
5168 memset (&outrel
, 0, sizeof outrel
);
5171 && (!bfd_link_pic (info
)
5172 || !SYMBOLIC_BIND (info
, h
)
5173 || !h
->def_regular
))
5174 outrel
.r_info
= ELFNN_R_INFO (h
->dynindx
, r_type
);
5179 /* On SVR4-ish systems, the dynamic loader cannot
5180 relocate the text and data segments independently,
5181 so the symbol does not matter. */
5183 outrel
.r_info
= ELFNN_R_INFO (symbol
, AARCH64_R (RELATIVE
));
5184 outrel
.r_addend
+= value
;
5187 sreloc
= elf_section_data (input_section
)->sreloc
;
5188 if (sreloc
== NULL
|| sreloc
->contents
== NULL
)
5189 return bfd_reloc_notsupported
;
5191 loc
= sreloc
->contents
+ sreloc
->reloc_count
++ * RELOC_SIZE (globals
);
5192 bfd_elfNN_swap_reloca_out (output_bfd
, &outrel
, loc
);
5194 if (sreloc
->reloc_count
* RELOC_SIZE (globals
) > sreloc
->size
)
5196 /* Sanity to check that we have previously allocated
5197 sufficient space in the relocation section for the
5198 number of relocations we actually want to emit. */
5202 /* If this reloc is against an external symbol, we do not want to
5203 fiddle with the addend. Otherwise, we need to include the symbol
5204 value so that it becomes an addend for the dynamic reloc. */
5206 return bfd_reloc_ok
;
5208 return _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
5209 contents
, rel
->r_offset
, value
,
5213 value
+= signed_addend
;
5216 case BFD_RELOC_AARCH64_CALL26
:
5217 case BFD_RELOC_AARCH64_JUMP26
:
5219 asection
*splt
= globals
->root
.splt
;
5220 bfd_boolean via_plt_p
=
5221 splt
!= NULL
&& h
!= NULL
&& h
->plt
.offset
!= (bfd_vma
) - 1;
5223 /* A call to an undefined weak symbol is converted to a jump to
5224 the next instruction unless a PLT entry will be created.
5225 The jump to the next instruction is optimized as a NOP.
5226 Do the same for local undefined symbols. */
5227 if (weak_undef_p
&& ! via_plt_p
)
5229 bfd_putl32 (INSN_NOP
, hit_data
);
5230 return bfd_reloc_ok
;
5233 /* If the call goes through a PLT entry, make sure to
5234 check distance to the right destination address. */
5236 value
= (splt
->output_section
->vma
5237 + splt
->output_offset
+ h
->plt
.offset
);
5239 /* Check if a stub has to be inserted because the destination
5241 struct elf_aarch64_stub_hash_entry
*stub_entry
= NULL
;
5242 if (! aarch64_valid_branch_p (value
, place
))
5243 /* The target is out of reach, so redirect the branch to
5244 the local stub for this function. */
5245 stub_entry
= elfNN_aarch64_get_stub_entry (input_section
, sym_sec
, h
,
5247 if (stub_entry
!= NULL
)
5248 value
= (stub_entry
->stub_offset
5249 + stub_entry
->stub_sec
->output_offset
5250 + stub_entry
->stub_sec
->output_section
->vma
);
5252 value
= _bfd_aarch64_elf_resolve_relocation (bfd_r_type
, place
, value
,
5253 signed_addend
, weak_undef_p
);
5254 *unresolved_reloc_p
= FALSE
;
5257 case BFD_RELOC_AARCH64_16_PCREL
:
5258 case BFD_RELOC_AARCH64_32_PCREL
:
5259 case BFD_RELOC_AARCH64_64_PCREL
:
5260 case BFD_RELOC_AARCH64_ADR_HI21_NC_PCREL
:
5261 case BFD_RELOC_AARCH64_ADR_HI21_PCREL
:
5262 case BFD_RELOC_AARCH64_ADR_LO21_PCREL
:
5263 case BFD_RELOC_AARCH64_LD_LO19_PCREL
:
5264 if (bfd_link_pic (info
)
5265 && (input_section
->flags
& SEC_ALLOC
) != 0
5266 && (input_section
->flags
& SEC_READONLY
) != 0
5270 int howto_index
= bfd_r_type
- BFD_RELOC_AARCH64_RELOC_START
;
5272 (*_bfd_error_handler
)
5273 (_("%B: relocation %s against external symbol `%s' can not be used"
5274 " when making a shared object; recompile with -fPIC"),
5275 input_bfd
, elfNN_aarch64_howto_table
[howto_index
].name
,
5276 h
->root
.root
.string
);
5277 bfd_set_error (bfd_error_bad_value
);
5281 case BFD_RELOC_AARCH64_16
:
5283 case BFD_RELOC_AARCH64_32
:
5285 case BFD_RELOC_AARCH64_ADD_LO12
:
5286 case BFD_RELOC_AARCH64_BRANCH19
:
5287 case BFD_RELOC_AARCH64_LDST128_LO12
:
5288 case BFD_RELOC_AARCH64_LDST16_LO12
:
5289 case BFD_RELOC_AARCH64_LDST32_LO12
:
5290 case BFD_RELOC_AARCH64_LDST64_LO12
:
5291 case BFD_RELOC_AARCH64_LDST8_LO12
:
5292 case BFD_RELOC_AARCH64_MOVW_G0
:
5293 case BFD_RELOC_AARCH64_MOVW_G0_NC
:
5294 case BFD_RELOC_AARCH64_MOVW_G0_S
:
5295 case BFD_RELOC_AARCH64_MOVW_G1
:
5296 case BFD_RELOC_AARCH64_MOVW_G1_NC
:
5297 case BFD_RELOC_AARCH64_MOVW_G1_S
:
5298 case BFD_RELOC_AARCH64_MOVW_G2
:
5299 case BFD_RELOC_AARCH64_MOVW_G2_NC
:
5300 case BFD_RELOC_AARCH64_MOVW_G2_S
:
5301 case BFD_RELOC_AARCH64_MOVW_G3
:
5302 case BFD_RELOC_AARCH64_TSTBR14
:
5303 value
= _bfd_aarch64_elf_resolve_relocation (bfd_r_type
, place
, value
,
5304 signed_addend
, weak_undef_p
);
5307 case BFD_RELOC_AARCH64_ADR_GOT_PAGE
:
5308 case BFD_RELOC_AARCH64_GOT_LD_PREL19
:
5309 case BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14
:
5310 case BFD_RELOC_AARCH64_LD32_GOT_LO12_NC
:
5311 case BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15
:
5312 case BFD_RELOC_AARCH64_LD64_GOT_LO12_NC
:
5313 if (globals
->root
.sgot
== NULL
)
5314 BFD_ASSERT (h
!= NULL
);
5319 value
= aarch64_calculate_got_entry_vma (h
, globals
, info
, value
,
5321 unresolved_reloc_p
);
5322 if (bfd_r_type
== BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15
5323 || bfd_r_type
== BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14
)
5324 addend
= (globals
->root
.sgot
->output_section
->vma
5325 + globals
->root
.sgot
->output_offset
);
5326 value
= _bfd_aarch64_elf_resolve_relocation (bfd_r_type
, place
, value
,
5327 addend
, weak_undef_p
);
5332 struct elf_aarch64_local_symbol
*locals
5333 = elf_aarch64_locals (input_bfd
);
5337 int howto_index
= bfd_r_type
- BFD_RELOC_AARCH64_RELOC_START
;
5338 (*_bfd_error_handler
)
5339 (_("%B: Local symbol descriptor table be NULL when applying "
5340 "relocation %s against local symbol"),
5341 input_bfd
, elfNN_aarch64_howto_table
[howto_index
].name
);
5345 off
= symbol_got_offset (input_bfd
, h
, r_symndx
);
5346 base_got
= globals
->root
.sgot
;
5347 bfd_vma got_entry_addr
= (base_got
->output_section
->vma
5348 + base_got
->output_offset
+ off
);
5350 if (!symbol_got_offset_mark_p (input_bfd
, h
, r_symndx
))
5352 bfd_put_64 (output_bfd
, value
, base_got
->contents
+ off
);
5354 if (bfd_link_pic (info
))
5357 Elf_Internal_Rela outrel
;
5359 /* For local symbol, we have done absolute relocation in static
5360 linking stageh. While for share library, we need to update
5361 the content of GOT entry according to the share objects
5362 loading base address. So we need to generate a
5363 R_AARCH64_RELATIVE reloc for dynamic linker. */
5364 s
= globals
->root
.srelgot
;
5368 outrel
.r_offset
= got_entry_addr
;
5369 outrel
.r_info
= ELFNN_R_INFO (0, AARCH64_R (RELATIVE
));
5370 outrel
.r_addend
= value
;
5371 elf_append_rela (output_bfd
, s
, &outrel
);
5374 symbol_got_offset_mark (input_bfd
, h
, r_symndx
);
5377 /* Update the relocation value to GOT entry addr as we have transformed
5378 the direct data access into indirect data access through GOT. */
5379 value
= got_entry_addr
;
5381 if (bfd_r_type
== BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15
5382 || bfd_r_type
== BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14
)
5383 addend
= base_got
->output_section
->vma
+ base_got
->output_offset
;
5385 value
= _bfd_aarch64_elf_resolve_relocation (bfd_r_type
, place
, value
,
5386 addend
, weak_undef_p
);
5391 case BFD_RELOC_AARCH64_LD64_GOTOFF_LO15
:
5392 case BFD_RELOC_AARCH64_MOVW_GOTOFF_G0_NC
:
5393 case BFD_RELOC_AARCH64_MOVW_GOTOFF_G1
:
5395 value
= aarch64_calculate_got_entry_vma (h
, globals
, info
, value
,
5397 unresolved_reloc_p
);
5400 struct elf_aarch64_local_symbol
*locals
5401 = elf_aarch64_locals (input_bfd
);
5405 int howto_index
= bfd_r_type
- BFD_RELOC_AARCH64_RELOC_START
;
5406 (*_bfd_error_handler
)
5407 (_("%B: Local symbol descriptor table be NULL when applying "
5408 "relocation %s against local symbol"),
5409 input_bfd
, elfNN_aarch64_howto_table
[howto_index
].name
);
5413 off
= symbol_got_offset (input_bfd
, h
, r_symndx
);
5414 base_got
= globals
->root
.sgot
;
5415 if (base_got
== NULL
)
5418 bfd_vma got_entry_addr
= (base_got
->output_section
->vma
5419 + base_got
->output_offset
+ off
);
5421 if (!symbol_got_offset_mark_p (input_bfd
, h
, r_symndx
))
5423 bfd_put_64 (output_bfd
, value
, base_got
->contents
+ off
);
5425 if (bfd_link_pic (info
))
5428 Elf_Internal_Rela outrel
;
5430 /* For local symbol, we have done absolute relocation in static
5431 linking stage. While for share library, we need to update
5432 the content of GOT entry according to the share objects
5433 loading base address. So we need to generate a
5434 R_AARCH64_RELATIVE reloc for dynamic linker. */
5435 s
= globals
->root
.srelgot
;
5439 outrel
.r_offset
= got_entry_addr
;
5440 outrel
.r_info
= ELFNN_R_INFO (0, AARCH64_R (RELATIVE
));
5441 outrel
.r_addend
= value
;
5442 elf_append_rela (output_bfd
, s
, &outrel
);
5445 symbol_got_offset_mark (input_bfd
, h
, r_symndx
);
5449 /* Update the relocation value to GOT entry addr as we have transformed
5450 the direct data access into indirect data access through GOT. */
5451 value
= symbol_got_offset (input_bfd
, h
, r_symndx
);
5452 value
= _bfd_aarch64_elf_resolve_relocation (bfd_r_type
, place
, value
,
5454 *unresolved_reloc_p
= FALSE
;
5457 case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC
:
5458 case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21
:
5459 case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21
:
5460 case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21
:
5461 case BFD_RELOC_AARCH64_TLSIE_LD32_GOTTPREL_LO12_NC
:
5462 case BFD_RELOC_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC
:
5463 case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19
:
5464 case BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC
:
5465 case BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21
:
5466 case BFD_RELOC_AARCH64_TLSLD_ADR_PREL21
:
5467 if (globals
->root
.sgot
== NULL
)
5468 return bfd_reloc_notsupported
;
5470 value
= (symbol_got_offset (input_bfd
, h
, r_symndx
)
5471 + globals
->root
.sgot
->output_section
->vma
5472 + globals
->root
.sgot
->output_offset
);
5474 value
= _bfd_aarch64_elf_resolve_relocation (bfd_r_type
, place
, value
,
5476 *unresolved_reloc_p
= FALSE
;
5479 case BFD_RELOC_AARCH64_TLSGD_MOVW_G0_NC
:
5480 case BFD_RELOC_AARCH64_TLSGD_MOVW_G1
:
5481 case BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G0_NC
:
5482 case BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G1
:
5483 if (globals
->root
.sgot
== NULL
)
5484 return bfd_reloc_notsupported
;
5486 value
= symbol_got_offset (input_bfd
, h
, r_symndx
);
5487 value
= _bfd_aarch64_elf_resolve_relocation (bfd_r_type
, place
, value
,
5489 *unresolved_reloc_p
= FALSE
;
5492 case BFD_RELOC_AARCH64_TLSLD_ADD_DTPREL_HI12
:
5493 case BFD_RELOC_AARCH64_TLSLD_ADD_DTPREL_LO12
:
5494 case BFD_RELOC_AARCH64_TLSLD_ADD_DTPREL_LO12_NC
:
5495 case BFD_RELOC_AARCH64_TLSLD_LDST16_DTPREL_LO12
:
5496 case BFD_RELOC_AARCH64_TLSLD_LDST16_DTPREL_LO12_NC
:
5497 case BFD_RELOC_AARCH64_TLSLD_LDST32_DTPREL_LO12
:
5498 case BFD_RELOC_AARCH64_TLSLD_LDST32_DTPREL_LO12_NC
:
5499 case BFD_RELOC_AARCH64_TLSLD_LDST64_DTPREL_LO12
:
5500 case BFD_RELOC_AARCH64_TLSLD_LDST64_DTPREL_LO12_NC
:
5501 case BFD_RELOC_AARCH64_TLSLD_LDST8_DTPREL_LO12
:
5502 case BFD_RELOC_AARCH64_TLSLD_LDST8_DTPREL_LO12_NC
:
5503 case BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G0
:
5504 case BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G0_NC
:
5505 case BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G1
:
5506 case BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G1_NC
:
5507 case BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G2
:
5508 value
= _bfd_aarch64_elf_resolve_relocation (bfd_r_type
, place
, value
,
5509 signed_addend
- dtpoff_base (info
),
5513 case BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_HI12
:
5514 case BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_LO12
:
5515 case BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_LO12_NC
:
5516 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0
:
5517 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC
:
5518 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1
:
5519 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1_NC
:
5520 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G2
:
5521 value
= _bfd_aarch64_elf_resolve_relocation (bfd_r_type
, place
, value
,
5522 signed_addend
- tpoff_base (info
),
5524 *unresolved_reloc_p
= FALSE
;
5527 case BFD_RELOC_AARCH64_TLSDESC_ADD
:
5528 case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12_NC
:
5529 case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21
:
5530 case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21
:
5531 case BFD_RELOC_AARCH64_TLSDESC_LD32_LO12_NC
:
5532 case BFD_RELOC_AARCH64_TLSDESC_LD64_LO12_NC
:
5533 case BFD_RELOC_AARCH64_TLSDESC_LDR
:
5534 case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19
:
5535 if (globals
->root
.sgot
== NULL
)
5536 return bfd_reloc_notsupported
;
5537 value
= (symbol_tlsdesc_got_offset (input_bfd
, h
, r_symndx
)
5538 + globals
->root
.sgotplt
->output_section
->vma
5539 + globals
->root
.sgotplt
->output_offset
5540 + globals
->sgotplt_jump_table_size
);
5542 value
= _bfd_aarch64_elf_resolve_relocation (bfd_r_type
, place
, value
,
5544 *unresolved_reloc_p
= FALSE
;
5548 return bfd_reloc_notsupported
;
5552 *saved_addend
= value
;
5554 /* Only apply the final relocation in a sequence. */
5556 return bfd_reloc_continue
;
5558 return _bfd_aarch64_elf_put_addend (input_bfd
, hit_data
, bfd_r_type
,
5562 /* Handle TLS relaxations. Relaxing is possible for symbols that use
5563 R_AARCH64_TLSDESC_ADR_{PAGE, LD64_LO12_NC, ADD_LO12_NC} during a static
5566 Return bfd_reloc_ok if we're done, bfd_reloc_continue if the caller
5567 is to then call final_link_relocate. Return other values in the
5570 static bfd_reloc_status_type
5571 elfNN_aarch64_tls_relax (struct elf_aarch64_link_hash_table
*globals
,
5572 bfd
*input_bfd
, bfd_byte
*contents
,
5573 Elf_Internal_Rela
*rel
, struct elf_link_hash_entry
*h
)
5575 bfd_boolean is_local
= h
== NULL
;
5576 unsigned int r_type
= ELFNN_R_TYPE (rel
->r_info
);
5579 BFD_ASSERT (globals
&& input_bfd
&& contents
&& rel
);
5581 switch (elfNN_aarch64_bfd_reloc_from_type (r_type
))
5583 case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21
:
5584 case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21
:
5587 /* GD->LE relaxation:
5588 adrp x0, :tlsgd:var => movz x0, :tprel_g1:var
5590 adrp x0, :tlsdesc:var => movz x0, :tprel_g1:var
5592 bfd_putl32 (0xd2a00000, contents
+ rel
->r_offset
);
5593 return bfd_reloc_continue
;
5597 /* GD->IE relaxation:
5598 adrp x0, :tlsgd:var => adrp x0, :gottprel:var
5600 adrp x0, :tlsdesc:var => adrp x0, :gottprel:var
5602 return bfd_reloc_continue
;
5605 case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21
:
5609 case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19
:
5612 /* Tiny TLSDESC->LE relaxation:
5613 ldr x1, :tlsdesc:var => movz x0, #:tprel_g1:var
5614 adr x0, :tlsdesc:var => movk x0, #:tprel_g0_nc:var
5618 BFD_ASSERT (ELFNN_R_TYPE (rel
[1].r_info
) == AARCH64_R (TLSDESC_ADR_PREL21
));
5619 BFD_ASSERT (ELFNN_R_TYPE (rel
[2].r_info
) == AARCH64_R (TLSDESC_CALL
));
5621 rel
[1].r_info
= ELFNN_R_INFO (ELFNN_R_SYM (rel
->r_info
),
5622 AARCH64_R (TLSLE_MOVW_TPREL_G0_NC
));
5623 rel
[2].r_info
= ELFNN_R_INFO (STN_UNDEF
, R_AARCH64_NONE
);
5625 bfd_putl32 (0xd2a00000, contents
+ rel
->r_offset
);
5626 bfd_putl32 (0xf2800000, contents
+ rel
->r_offset
+ 4);
5627 bfd_putl32 (INSN_NOP
, contents
+ rel
->r_offset
+ 8);
5628 return bfd_reloc_continue
;
5632 /* Tiny TLSDESC->IE relaxation:
5633 ldr x1, :tlsdesc:var => ldr x0, :gottprel:var
5634 adr x0, :tlsdesc:var => nop
5638 BFD_ASSERT (ELFNN_R_TYPE (rel
[1].r_info
) == AARCH64_R (TLSDESC_ADR_PREL21
));
5639 BFD_ASSERT (ELFNN_R_TYPE (rel
[2].r_info
) == AARCH64_R (TLSDESC_CALL
));
5641 rel
[1].r_info
= ELFNN_R_INFO (STN_UNDEF
, R_AARCH64_NONE
);
5642 rel
[2].r_info
= ELFNN_R_INFO (STN_UNDEF
, R_AARCH64_NONE
);
5644 bfd_putl32 (0x58000000, contents
+ rel
->r_offset
);
5645 bfd_putl32 (INSN_NOP
, contents
+ rel
->r_offset
+ 4);
5646 bfd_putl32 (INSN_NOP
, contents
+ rel
->r_offset
+ 8);
5647 return bfd_reloc_continue
;
5650 case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21
:
5653 /* Tiny GD->LE relaxation:
5654 adr x0, :tlsgd:var => mrs x1, tpidr_el0
5655 bl __tls_get_addr => add x0, x1, #:tprel_hi12:x, lsl #12
5656 nop => add x0, x0, #:tprel_lo12_nc:x
5659 /* First kill the tls_get_addr reloc on the bl instruction. */
5660 BFD_ASSERT (rel
->r_offset
+ 4 == rel
[1].r_offset
);
5662 bfd_putl32 (0xd53bd041, contents
+ rel
->r_offset
+ 0);
5663 bfd_putl32 (0x91400020, contents
+ rel
->r_offset
+ 4);
5664 bfd_putl32 (0x91000000, contents
+ rel
->r_offset
+ 8);
5666 rel
[1].r_info
= ELFNN_R_INFO (ELFNN_R_SYM (rel
->r_info
),
5667 AARCH64_R (TLSLE_ADD_TPREL_LO12_NC
));
5668 rel
[1].r_offset
= rel
->r_offset
+ 8;
5670 /* Move the current relocation to the second instruction in
5673 rel
->r_info
= ELFNN_R_INFO (ELFNN_R_SYM (rel
->r_info
),
5674 AARCH64_R (TLSLE_ADD_TPREL_HI12
));
5675 return bfd_reloc_continue
;
5679 /* Tiny GD->IE relaxation:
5680 adr x0, :tlsgd:var => ldr x0, :gottprel:var
5681 bl __tls_get_addr => mrs x1, tpidr_el0
5682 nop => add x0, x0, x1
5685 /* First kill the tls_get_addr reloc on the bl instruction. */
5686 BFD_ASSERT (rel
->r_offset
+ 4 == rel
[1].r_offset
);
5687 rel
[1].r_info
= ELFNN_R_INFO (STN_UNDEF
, R_AARCH64_NONE
);
5689 bfd_putl32 (0x58000000, contents
+ rel
->r_offset
);
5690 bfd_putl32 (0xd53bd041, contents
+ rel
->r_offset
+ 4);
5691 bfd_putl32 (0x8b000020, contents
+ rel
->r_offset
+ 8);
5692 return bfd_reloc_continue
;
5695 case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19
:
5696 return bfd_reloc_continue
;
5698 case BFD_RELOC_AARCH64_TLSDESC_LDNN_LO12_NC
:
5701 /* GD->LE relaxation:
5702 ldr xd, [x0, #:tlsdesc_lo12:var] => movk x0, :tprel_g0_nc:var
5704 bfd_putl32 (0xf2800000, contents
+ rel
->r_offset
);
5705 return bfd_reloc_continue
;
5709 /* GD->IE relaxation:
5710 ldr xd, [x0, #:tlsdesc_lo12:var] => ldr x0, [x0, #:gottprel_lo12:var]
5712 insn
= bfd_getl32 (contents
+ rel
->r_offset
);
5714 bfd_putl32 (insn
, contents
+ rel
->r_offset
);
5715 return bfd_reloc_continue
;
5718 case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC
:
5721 /* GD->LE relaxation
5722 add x0, #:tlsgd_lo12:var => movk x0, :tprel_g0_nc:var
5723 bl __tls_get_addr => mrs x1, tpidr_el0
5724 nop => add x0, x1, x0
5727 /* First kill the tls_get_addr reloc on the bl instruction. */
5728 BFD_ASSERT (rel
->r_offset
+ 4 == rel
[1].r_offset
);
5729 rel
[1].r_info
= ELFNN_R_INFO (STN_UNDEF
, R_AARCH64_NONE
);
5731 bfd_putl32 (0xf2800000, contents
+ rel
->r_offset
);
5732 bfd_putl32 (0xd53bd041, contents
+ rel
->r_offset
+ 4);
5733 bfd_putl32 (0x8b000020, contents
+ rel
->r_offset
+ 8);
5734 return bfd_reloc_continue
;
5738 /* GD->IE relaxation
5739 ADD x0, #:tlsgd_lo12:var => ldr x0, [x0, #:gottprel_lo12:var]
5740 BL __tls_get_addr => mrs x1, tpidr_el0
5742 NOP => add x0, x1, x0
5745 BFD_ASSERT (ELFNN_R_TYPE (rel
[1].r_info
) == AARCH64_R (CALL26
));
5747 /* Remove the relocation on the BL instruction. */
5748 rel
[1].r_info
= ELFNN_R_INFO (STN_UNDEF
, R_AARCH64_NONE
);
5750 bfd_putl32 (0xf9400000, contents
+ rel
->r_offset
);
5752 /* We choose to fixup the BL and NOP instructions using the
5753 offset from the second relocation to allow flexibility in
5754 scheduling instructions between the ADD and BL. */
5755 bfd_putl32 (0xd53bd041, contents
+ rel
[1].r_offset
);
5756 bfd_putl32 (0x8b000020, contents
+ rel
[1].r_offset
+ 4);
5757 return bfd_reloc_continue
;
5760 case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12_NC
:
5761 case BFD_RELOC_AARCH64_TLSDESC_CALL
:
5762 /* GD->IE/LE relaxation:
5763 add x0, x0, #:tlsdesc_lo12:var => nop
5766 bfd_putl32 (INSN_NOP
, contents
+ rel
->r_offset
);
5767 return bfd_reloc_ok
;
5769 case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21
:
5770 /* IE->LE relaxation:
5771 adrp xd, :gottprel:var => movz xd, :tprel_g1:var
5775 insn
= bfd_getl32 (contents
+ rel
->r_offset
);
5776 bfd_putl32 (0xd2a00000 | (insn
& 0x1f), contents
+ rel
->r_offset
);
5778 return bfd_reloc_continue
;
5780 case BFD_RELOC_AARCH64_TLSIE_LDNN_GOTTPREL_LO12_NC
:
5781 /* IE->LE relaxation:
5782 ldr xd, [xm, #:gottprel_lo12:var] => movk xd, :tprel_g0_nc:var
5786 insn
= bfd_getl32 (contents
+ rel
->r_offset
);
5787 bfd_putl32 (0xf2800000 | (insn
& 0x1f), contents
+ rel
->r_offset
);
5789 return bfd_reloc_continue
;
5791 case BFD_RELOC_AARCH64_TLSLD_ADR_PREL21
:
5792 /* LD->LE relaxation (tiny):
5793 adr x0, :tlsldm:x => mrs x0, tpidr_el0
5794 bl __tls_get_addr => add x0, x0, TCB_SIZE
5798 BFD_ASSERT (rel
->r_offset
+ 4 == rel
[1].r_offset
);
5799 BFD_ASSERT (ELFNN_R_TYPE (rel
[1].r_info
) == AARCH64_R (CALL26
));
5800 /* No need of CALL26 relocation for tls_get_addr. */
5801 rel
[1].r_info
= ELFNN_R_INFO (STN_UNDEF
, R_AARCH64_NONE
);
5802 bfd_putl32 (0xd53bd040, contents
+ rel
->r_offset
+ 0);
5803 bfd_putl32 (0x91004000, contents
+ rel
->r_offset
+ 4);
5804 return bfd_reloc_ok
;
5806 return bfd_reloc_continue
;
5808 case BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21
:
5809 /* LD->LE relaxation (small):
5810 adrp x0, :tlsldm:x => mrs x0, tpidr_el0
5814 bfd_putl32 (0xd53bd040, contents
+ rel
->r_offset
);
5815 return bfd_reloc_ok
;
5817 return bfd_reloc_continue
;
5819 case BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC
:
5820 /* LD->LE relaxation (small):
5821 add x0, #:tlsldm_lo12:x => add x0, x0, TCB_SIZE
5822 bl __tls_get_addr => nop
5826 BFD_ASSERT (rel
->r_offset
+ 4 == rel
[1].r_offset
);
5827 BFD_ASSERT (ELFNN_R_TYPE (rel
[1].r_info
) == AARCH64_R (CALL26
));
5828 /* No need of CALL26 relocation for tls_get_addr. */
5829 rel
[1].r_info
= ELFNN_R_INFO (STN_UNDEF
, R_AARCH64_NONE
);
5830 bfd_putl32 (0x91004000, contents
+ rel
->r_offset
+ 0);
5831 bfd_putl32 (0xd503201f, contents
+ rel
->r_offset
+ 4);
5832 return bfd_reloc_ok
;
5834 return bfd_reloc_continue
;
5837 return bfd_reloc_continue
;
5840 return bfd_reloc_ok
;
5843 /* Relocate an AArch64 ELF section. */
5846 elfNN_aarch64_relocate_section (bfd
*output_bfd
,
5847 struct bfd_link_info
*info
,
5849 asection
*input_section
,
5851 Elf_Internal_Rela
*relocs
,
5852 Elf_Internal_Sym
*local_syms
,
5853 asection
**local_sections
)
5855 Elf_Internal_Shdr
*symtab_hdr
;
5856 struct elf_link_hash_entry
**sym_hashes
;
5857 Elf_Internal_Rela
*rel
;
5858 Elf_Internal_Rela
*relend
;
5860 struct elf_aarch64_link_hash_table
*globals
;
5861 bfd_boolean save_addend
= FALSE
;
5864 globals
= elf_aarch64_hash_table (info
);
5866 symtab_hdr
= &elf_symtab_hdr (input_bfd
);
5867 sym_hashes
= elf_sym_hashes (input_bfd
);
5870 relend
= relocs
+ input_section
->reloc_count
;
5871 for (; rel
< relend
; rel
++)
5873 unsigned int r_type
;
5874 bfd_reloc_code_real_type bfd_r_type
;
5875 bfd_reloc_code_real_type relaxed_bfd_r_type
;
5876 reloc_howto_type
*howto
;
5877 unsigned long r_symndx
;
5878 Elf_Internal_Sym
*sym
;
5880 struct elf_link_hash_entry
*h
;
5882 bfd_reloc_status_type r
;
5885 bfd_boolean unresolved_reloc
= FALSE
;
5886 char *error_message
= NULL
;
5888 r_symndx
= ELFNN_R_SYM (rel
->r_info
);
5889 r_type
= ELFNN_R_TYPE (rel
->r_info
);
5891 bfd_reloc
.howto
= elfNN_aarch64_howto_from_type (r_type
);
5892 howto
= bfd_reloc
.howto
;
5896 (*_bfd_error_handler
)
5897 (_("%B: unrecognized relocation (0x%x) in section `%A'"),
5898 input_bfd
, input_section
, r_type
);
5901 bfd_r_type
= elfNN_aarch64_bfd_reloc_from_howto (howto
);
5907 if (r_symndx
< symtab_hdr
->sh_info
)
5909 sym
= local_syms
+ r_symndx
;
5910 sym_type
= ELFNN_ST_TYPE (sym
->st_info
);
5911 sec
= local_sections
[r_symndx
];
5913 /* An object file might have a reference to a local
5914 undefined symbol. This is a daft object file, but we
5915 should at least do something about it. */
5916 if (r_type
!= R_AARCH64_NONE
&& r_type
!= R_AARCH64_NULL
5917 && bfd_is_und_section (sec
)
5918 && ELF_ST_BIND (sym
->st_info
) != STB_WEAK
)
5920 if (!info
->callbacks
->undefined_symbol
5921 (info
, bfd_elf_string_from_elf_section
5922 (input_bfd
, symtab_hdr
->sh_link
, sym
->st_name
),
5923 input_bfd
, input_section
, rel
->r_offset
, TRUE
))
5927 relocation
= _bfd_elf_rela_local_sym (output_bfd
, sym
, &sec
, rel
);
5929 /* Relocate against local STT_GNU_IFUNC symbol. */
5930 if (!bfd_link_relocatable (info
)
5931 && ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
)
5933 h
= elfNN_aarch64_get_local_sym_hash (globals
, input_bfd
,
5938 /* Set STT_GNU_IFUNC symbol value. */
5939 h
->root
.u
.def
.value
= sym
->st_value
;
5940 h
->root
.u
.def
.section
= sec
;
5945 bfd_boolean warned
, ignored
;
5947 RELOC_FOR_GLOBAL_SYMBOL (info
, input_bfd
, input_section
, rel
,
5948 r_symndx
, symtab_hdr
, sym_hashes
,
5950 unresolved_reloc
, warned
, ignored
);
5955 if (sec
!= NULL
&& discarded_section (sec
))
5956 RELOC_AGAINST_DISCARDED_SECTION (info
, input_bfd
, input_section
,
5957 rel
, 1, relend
, howto
, 0, contents
);
5959 if (bfd_link_relocatable (info
))
5963 name
= h
->root
.root
.string
;
5966 name
= (bfd_elf_string_from_elf_section
5967 (input_bfd
, symtab_hdr
->sh_link
, sym
->st_name
));
5968 if (name
== NULL
|| *name
== '\0')
5969 name
= bfd_section_name (input_bfd
, sec
);
5973 && r_type
!= R_AARCH64_NONE
5974 && r_type
!= R_AARCH64_NULL
5976 || h
->root
.type
== bfd_link_hash_defined
5977 || h
->root
.type
== bfd_link_hash_defweak
)
5978 && IS_AARCH64_TLS_RELOC (bfd_r_type
) != (sym_type
== STT_TLS
))
5980 (*_bfd_error_handler
)
5981 ((sym_type
== STT_TLS
5982 ? _("%B(%A+0x%lx): %s used with TLS symbol %s")
5983 : _("%B(%A+0x%lx): %s used with non-TLS symbol %s")),
5985 input_section
, (long) rel
->r_offset
, howto
->name
, name
);
5988 /* We relax only if we can see that there can be a valid transition
5989 from a reloc type to another.
5990 We call elfNN_aarch64_final_link_relocate unless we're completely
5991 done, i.e., the relaxation produced the final output we want. */
5993 relaxed_bfd_r_type
= aarch64_tls_transition (input_bfd
, info
, r_type
,
5995 if (relaxed_bfd_r_type
!= bfd_r_type
)
5997 bfd_r_type
= relaxed_bfd_r_type
;
5998 howto
= elfNN_aarch64_howto_from_bfd_reloc (bfd_r_type
);
5999 BFD_ASSERT (howto
!= NULL
);
6000 r_type
= howto
->type
;
6001 r
= elfNN_aarch64_tls_relax (globals
, input_bfd
, contents
, rel
, h
);
6002 unresolved_reloc
= 0;
6005 r
= bfd_reloc_continue
;
6007 /* There may be multiple consecutive relocations for the
6008 same offset. In that case we are supposed to treat the
6009 output of each relocation as the addend for the next. */
6010 if (rel
+ 1 < relend
6011 && rel
->r_offset
== rel
[1].r_offset
6012 && ELFNN_R_TYPE (rel
[1].r_info
) != R_AARCH64_NONE
6013 && ELFNN_R_TYPE (rel
[1].r_info
) != R_AARCH64_NULL
)
6016 save_addend
= FALSE
;
6018 if (r
== bfd_reloc_continue
)
6019 r
= elfNN_aarch64_final_link_relocate (howto
, input_bfd
, output_bfd
,
6020 input_section
, contents
, rel
,
6021 relocation
, info
, sec
,
6022 h
, &unresolved_reloc
,
6023 save_addend
, &addend
, sym
);
6025 switch (elfNN_aarch64_bfd_reloc_from_type (r_type
))
6027 case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC
:
6028 case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21
:
6029 case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21
:
6030 case BFD_RELOC_AARCH64_TLSGD_MOVW_G0_NC
:
6031 case BFD_RELOC_AARCH64_TLSGD_MOVW_G1
:
6032 case BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC
:
6033 case BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21
:
6034 case BFD_RELOC_AARCH64_TLSLD_ADR_PREL21
:
6035 if (! symbol_got_offset_mark_p (input_bfd
, h
, r_symndx
))
6037 bfd_boolean need_relocs
= FALSE
;
6042 off
= symbol_got_offset (input_bfd
, h
, r_symndx
);
6043 indx
= h
&& h
->dynindx
!= -1 ? h
->dynindx
: 0;
6046 (bfd_link_pic (info
) || indx
!= 0) &&
6048 || ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
6049 || h
->root
.type
!= bfd_link_hash_undefweak
);
6051 BFD_ASSERT (globals
->root
.srelgot
!= NULL
);
6055 Elf_Internal_Rela rela
;
6056 rela
.r_info
= ELFNN_R_INFO (indx
, AARCH64_R (TLS_DTPMOD
));
6058 rela
.r_offset
= globals
->root
.sgot
->output_section
->vma
+
6059 globals
->root
.sgot
->output_offset
+ off
;
6062 loc
= globals
->root
.srelgot
->contents
;
6063 loc
+= globals
->root
.srelgot
->reloc_count
++
6064 * RELOC_SIZE (htab
);
6065 bfd_elfNN_swap_reloca_out (output_bfd
, &rela
, loc
);
6067 bfd_reloc_code_real_type real_type
=
6068 elfNN_aarch64_bfd_reloc_from_type (r_type
);
6070 if (real_type
== BFD_RELOC_AARCH64_TLSLD_ADR_PREL21
6071 || real_type
== BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21
6072 || real_type
== BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC
)
6074 /* For local dynamic, don't generate DTPREL in any case.
6075 Initialize the DTPREL slot into zero, so we get module
6076 base address when invoke runtime TLS resolver. */
6077 bfd_put_NN (output_bfd
, 0,
6078 globals
->root
.sgot
->contents
+ off
6083 bfd_put_NN (output_bfd
,
6084 relocation
- dtpoff_base (info
),
6085 globals
->root
.sgot
->contents
+ off
6090 /* This TLS symbol is global. We emit a
6091 relocation to fixup the tls offset at load
6094 ELFNN_R_INFO (indx
, AARCH64_R (TLS_DTPREL
));
6097 (globals
->root
.sgot
->output_section
->vma
6098 + globals
->root
.sgot
->output_offset
+ off
6101 loc
= globals
->root
.srelgot
->contents
;
6102 loc
+= globals
->root
.srelgot
->reloc_count
++
6103 * RELOC_SIZE (globals
);
6104 bfd_elfNN_swap_reloca_out (output_bfd
, &rela
, loc
);
6105 bfd_put_NN (output_bfd
, (bfd_vma
) 0,
6106 globals
->root
.sgot
->contents
+ off
6112 bfd_put_NN (output_bfd
, (bfd_vma
) 1,
6113 globals
->root
.sgot
->contents
+ off
);
6114 bfd_put_NN (output_bfd
,
6115 relocation
- dtpoff_base (info
),
6116 globals
->root
.sgot
->contents
+ off
6120 symbol_got_offset_mark (input_bfd
, h
, r_symndx
);
6124 case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21
:
6125 case BFD_RELOC_AARCH64_TLSIE_LDNN_GOTTPREL_LO12_NC
:
6126 case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19
:
6127 case BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G0_NC
:
6128 case BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G1
:
6129 if (! symbol_got_offset_mark_p (input_bfd
, h
, r_symndx
))
6131 bfd_boolean need_relocs
= FALSE
;
6136 off
= symbol_got_offset (input_bfd
, h
, r_symndx
);
6138 indx
= h
&& h
->dynindx
!= -1 ? h
->dynindx
: 0;
6141 (bfd_link_pic (info
) || indx
!= 0) &&
6143 || ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
6144 || h
->root
.type
!= bfd_link_hash_undefweak
);
6146 BFD_ASSERT (globals
->root
.srelgot
!= NULL
);
6150 Elf_Internal_Rela rela
;
6153 rela
.r_addend
= relocation
- dtpoff_base (info
);
6157 rela
.r_info
= ELFNN_R_INFO (indx
, AARCH64_R (TLS_TPREL
));
6158 rela
.r_offset
= globals
->root
.sgot
->output_section
->vma
+
6159 globals
->root
.sgot
->output_offset
+ off
;
6161 loc
= globals
->root
.srelgot
->contents
;
6162 loc
+= globals
->root
.srelgot
->reloc_count
++
6163 * RELOC_SIZE (htab
);
6165 bfd_elfNN_swap_reloca_out (output_bfd
, &rela
, loc
);
6167 bfd_put_NN (output_bfd
, rela
.r_addend
,
6168 globals
->root
.sgot
->contents
+ off
);
6171 bfd_put_NN (output_bfd
, relocation
- tpoff_base (info
),
6172 globals
->root
.sgot
->contents
+ off
);
6174 symbol_got_offset_mark (input_bfd
, h
, r_symndx
);
6178 case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12_NC
:
6179 case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21
:
6180 case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21
:
6181 case BFD_RELOC_AARCH64_TLSDESC_LDNN_LO12_NC
:
6182 case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19
:
6183 if (! symbol_tlsdesc_got_offset_mark_p (input_bfd
, h
, r_symndx
))
6185 bfd_boolean need_relocs
= FALSE
;
6186 int indx
= h
&& h
->dynindx
!= -1 ? h
->dynindx
: 0;
6187 bfd_vma off
= symbol_tlsdesc_got_offset (input_bfd
, h
, r_symndx
);
6189 need_relocs
= (h
== NULL
6190 || ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
6191 || h
->root
.type
!= bfd_link_hash_undefweak
);
6193 BFD_ASSERT (globals
->root
.srelgot
!= NULL
);
6194 BFD_ASSERT (globals
->root
.sgot
!= NULL
);
6199 Elf_Internal_Rela rela
;
6200 rela
.r_info
= ELFNN_R_INFO (indx
, AARCH64_R (TLSDESC
));
6203 rela
.r_offset
= (globals
->root
.sgotplt
->output_section
->vma
6204 + globals
->root
.sgotplt
->output_offset
6205 + off
+ globals
->sgotplt_jump_table_size
);
6208 rela
.r_addend
= relocation
- dtpoff_base (info
);
6210 /* Allocate the next available slot in the PLT reloc
6211 section to hold our R_AARCH64_TLSDESC, the next
6212 available slot is determined from reloc_count,
6213 which we step. But note, reloc_count was
6214 artifically moved down while allocating slots for
6215 real PLT relocs such that all of the PLT relocs
6216 will fit above the initial reloc_count and the
6217 extra stuff will fit below. */
6218 loc
= globals
->root
.srelplt
->contents
;
6219 loc
+= globals
->root
.srelplt
->reloc_count
++
6220 * RELOC_SIZE (globals
);
6222 bfd_elfNN_swap_reloca_out (output_bfd
, &rela
, loc
);
6224 bfd_put_NN (output_bfd
, (bfd_vma
) 0,
6225 globals
->root
.sgotplt
->contents
+ off
+
6226 globals
->sgotplt_jump_table_size
);
6227 bfd_put_NN (output_bfd
, (bfd_vma
) 0,
6228 globals
->root
.sgotplt
->contents
+ off
+
6229 globals
->sgotplt_jump_table_size
+
6233 symbol_tlsdesc_got_offset_mark (input_bfd
, h
, r_symndx
);
6244 /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
6245 because such sections are not SEC_ALLOC and thus ld.so will
6246 not process them. */
6247 if (unresolved_reloc
6248 && !((input_section
->flags
& SEC_DEBUGGING
) != 0
6250 && _bfd_elf_section_offset (output_bfd
, info
, input_section
,
6251 +rel
->r_offset
) != (bfd_vma
) - 1)
6253 (*_bfd_error_handler
)
6255 ("%B(%A+0x%lx): unresolvable %s relocation against symbol `%s'"),
6256 input_bfd
, input_section
, (long) rel
->r_offset
, howto
->name
,
6257 h
->root
.root
.string
);
6261 if (r
!= bfd_reloc_ok
&& r
!= bfd_reloc_continue
)
6263 bfd_reloc_code_real_type real_r_type
6264 = elfNN_aarch64_bfd_reloc_from_type (r_type
);
6268 case bfd_reloc_overflow
:
6269 if (!(*info
->callbacks
->reloc_overflow
)
6270 (info
, (h
? &h
->root
: NULL
), name
, howto
->name
, (bfd_vma
) 0,
6271 input_bfd
, input_section
, rel
->r_offset
))
6273 if (real_r_type
== BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15
6274 || real_r_type
== BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14
)
6276 (*info
->callbacks
->warning
)
6278 _("Too many GOT entries for -fpic, "
6279 "please recompile with -fPIC"),
6280 name
, input_bfd
, input_section
, rel
->r_offset
);
6285 case bfd_reloc_undefined
:
6286 if (!((*info
->callbacks
->undefined_symbol
)
6287 (info
, name
, input_bfd
, input_section
,
6288 rel
->r_offset
, TRUE
)))
6292 case bfd_reloc_outofrange
:
6293 error_message
= _("out of range");
6296 case bfd_reloc_notsupported
:
6297 error_message
= _("unsupported relocation");
6300 case bfd_reloc_dangerous
:
6301 /* error_message should already be set. */
6305 error_message
= _("unknown error");
6309 BFD_ASSERT (error_message
!= NULL
);
6310 if (!((*info
->callbacks
->reloc_dangerous
)
6311 (info
, error_message
, input_bfd
, input_section
,
6322 /* Set the right machine number. */
6325 elfNN_aarch64_object_p (bfd
*abfd
)
6328 bfd_default_set_arch_mach (abfd
, bfd_arch_aarch64
, bfd_mach_aarch64_ilp32
);
6330 bfd_default_set_arch_mach (abfd
, bfd_arch_aarch64
, bfd_mach_aarch64
);
6335 /* Function to keep AArch64 specific flags in the ELF header. */
6338 elfNN_aarch64_set_private_flags (bfd
*abfd
, flagword flags
)
6340 if (elf_flags_init (abfd
) && elf_elfheader (abfd
)->e_flags
!= flags
)
6345 elf_elfheader (abfd
)->e_flags
= flags
;
6346 elf_flags_init (abfd
) = TRUE
;
6352 /* Merge backend specific data from an object file to the output
6353 object file when linking. */
6356 elfNN_aarch64_merge_private_bfd_data (bfd
*ibfd
, bfd
*obfd
)
6360 bfd_boolean flags_compatible
= TRUE
;
6363 /* Check if we have the same endianess. */
6364 if (!_bfd_generic_verify_endian_match (ibfd
, obfd
))
6367 if (!is_aarch64_elf (ibfd
) || !is_aarch64_elf (obfd
))
6370 /* The input BFD must have had its flags initialised. */
6371 /* The following seems bogus to me -- The flags are initialized in
6372 the assembler but I don't think an elf_flags_init field is
6373 written into the object. */
6374 /* BFD_ASSERT (elf_flags_init (ibfd)); */
6376 in_flags
= elf_elfheader (ibfd
)->e_flags
;
6377 out_flags
= elf_elfheader (obfd
)->e_flags
;
6379 if (!elf_flags_init (obfd
))
6381 /* If the input is the default architecture and had the default
6382 flags then do not bother setting the flags for the output
6383 architecture, instead allow future merges to do this. If no
6384 future merges ever set these flags then they will retain their
6385 uninitialised values, which surprise surprise, correspond
6386 to the default values. */
6387 if (bfd_get_arch_info (ibfd
)->the_default
6388 && elf_elfheader (ibfd
)->e_flags
== 0)
6391 elf_flags_init (obfd
) = TRUE
;
6392 elf_elfheader (obfd
)->e_flags
= in_flags
;
6394 if (bfd_get_arch (obfd
) == bfd_get_arch (ibfd
)
6395 && bfd_get_arch_info (obfd
)->the_default
)
6396 return bfd_set_arch_mach (obfd
, bfd_get_arch (ibfd
),
6397 bfd_get_mach (ibfd
));
6402 /* Identical flags must be compatible. */
6403 if (in_flags
== out_flags
)
6406 /* Check to see if the input BFD actually contains any sections. If
6407 not, its flags may not have been initialised either, but it
6408 cannot actually cause any incompatiblity. Do not short-circuit
6409 dynamic objects; their section list may be emptied by
6410 elf_link_add_object_symbols.
6412 Also check to see if there are no code sections in the input.
6413 In this case there is no need to check for code specific flags.
6414 XXX - do we need to worry about floating-point format compatability
6415 in data sections ? */
6416 if (!(ibfd
->flags
& DYNAMIC
))
6418 bfd_boolean null_input_bfd
= TRUE
;
6419 bfd_boolean only_data_sections
= TRUE
;
6421 for (sec
= ibfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
6423 if ((bfd_get_section_flags (ibfd
, sec
)
6424 & (SEC_LOAD
| SEC_CODE
| SEC_HAS_CONTENTS
))
6425 == (SEC_LOAD
| SEC_CODE
| SEC_HAS_CONTENTS
))
6426 only_data_sections
= FALSE
;
6428 null_input_bfd
= FALSE
;
6432 if (null_input_bfd
|| only_data_sections
)
6436 return flags_compatible
;
6439 /* Display the flags field. */
6442 elfNN_aarch64_print_private_bfd_data (bfd
*abfd
, void *ptr
)
6444 FILE *file
= (FILE *) ptr
;
6445 unsigned long flags
;
6447 BFD_ASSERT (abfd
!= NULL
&& ptr
!= NULL
);
6449 /* Print normal ELF private data. */
6450 _bfd_elf_print_private_bfd_data (abfd
, ptr
);
6452 flags
= elf_elfheader (abfd
)->e_flags
;
6453 /* Ignore init flag - it may not be set, despite the flags field
6454 containing valid data. */
6456 /* xgettext:c-format */
6457 fprintf (file
, _("private flags = %lx:"), elf_elfheader (abfd
)->e_flags
);
6460 fprintf (file
, _("<Unrecognised flag bits set>"));
6467 /* Update the got entry reference counts for the section being removed. */
6470 elfNN_aarch64_gc_sweep_hook (bfd
*abfd
,
6471 struct bfd_link_info
*info
,
6473 const Elf_Internal_Rela
* relocs
)
6475 struct elf_aarch64_link_hash_table
*htab
;
6476 Elf_Internal_Shdr
*symtab_hdr
;
6477 struct elf_link_hash_entry
**sym_hashes
;
6478 struct elf_aarch64_local_symbol
*locals
;
6479 const Elf_Internal_Rela
*rel
, *relend
;
6481 if (bfd_link_relocatable (info
))
6484 htab
= elf_aarch64_hash_table (info
);
6489 elf_section_data (sec
)->local_dynrel
= NULL
;
6491 symtab_hdr
= &elf_symtab_hdr (abfd
);
6492 sym_hashes
= elf_sym_hashes (abfd
);
6494 locals
= elf_aarch64_locals (abfd
);
6496 relend
= relocs
+ sec
->reloc_count
;
6497 for (rel
= relocs
; rel
< relend
; rel
++)
6499 unsigned long r_symndx
;
6500 unsigned int r_type
;
6501 struct elf_link_hash_entry
*h
= NULL
;
6503 r_symndx
= ELFNN_R_SYM (rel
->r_info
);
6505 if (r_symndx
>= symtab_hdr
->sh_info
)
6508 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
6509 while (h
->root
.type
== bfd_link_hash_indirect
6510 || h
->root
.type
== bfd_link_hash_warning
)
6511 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
6515 Elf_Internal_Sym
*isym
;
6517 /* A local symbol. */
6518 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
6521 /* Check relocation against local STT_GNU_IFUNC symbol. */
6523 && ELF_ST_TYPE (isym
->st_info
) == STT_GNU_IFUNC
)
6525 h
= elfNN_aarch64_get_local_sym_hash (htab
, abfd
, rel
, FALSE
);
6533 struct elf_aarch64_link_hash_entry
*eh
;
6534 struct elf_dyn_relocs
**pp
;
6535 struct elf_dyn_relocs
*p
;
6537 eh
= (struct elf_aarch64_link_hash_entry
*) h
;
6539 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; pp
= &p
->next
)
6542 /* Everything must go for SEC. */
6548 r_type
= ELFNN_R_TYPE (rel
->r_info
);
6549 switch (aarch64_tls_transition (abfd
,info
, r_type
, h
,r_symndx
))
6551 case BFD_RELOC_AARCH64_ADR_GOT_PAGE
:
6552 case BFD_RELOC_AARCH64_GOT_LD_PREL19
:
6553 case BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14
:
6554 case BFD_RELOC_AARCH64_LD32_GOT_LO12_NC
:
6555 case BFD_RELOC_AARCH64_LD64_GOTOFF_LO15
:
6556 case BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15
:
6557 case BFD_RELOC_AARCH64_LD64_GOT_LO12_NC
:
6558 case BFD_RELOC_AARCH64_MOVW_GOTOFF_G0_NC
:
6559 case BFD_RELOC_AARCH64_MOVW_GOTOFF_G1
:
6560 case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12_NC
:
6561 case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21
:
6562 case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21
:
6563 case BFD_RELOC_AARCH64_TLSDESC_LD32_LO12_NC
:
6564 case BFD_RELOC_AARCH64_TLSDESC_LD64_LO12_NC
:
6565 case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19
:
6566 case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC
:
6567 case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21
:
6568 case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21
:
6569 case BFD_RELOC_AARCH64_TLSGD_MOVW_G0_NC
:
6570 case BFD_RELOC_AARCH64_TLSGD_MOVW_G1
:
6571 case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21
:
6572 case BFD_RELOC_AARCH64_TLSIE_LD32_GOTTPREL_LO12_NC
:
6573 case BFD_RELOC_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC
:
6574 case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19
:
6575 case BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G0_NC
:
6576 case BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G1
:
6577 case BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC
:
6578 case BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21
:
6579 case BFD_RELOC_AARCH64_TLSLD_ADR_PREL21
:
6582 if (h
->got
.refcount
> 0)
6583 h
->got
.refcount
-= 1;
6585 if (h
->type
== STT_GNU_IFUNC
)
6587 if (h
->plt
.refcount
> 0)
6588 h
->plt
.refcount
-= 1;
6591 else if (locals
!= NULL
)
6593 if (locals
[r_symndx
].got_refcount
> 0)
6594 locals
[r_symndx
].got_refcount
-= 1;
6598 case BFD_RELOC_AARCH64_CALL26
:
6599 case BFD_RELOC_AARCH64_JUMP26
:
6600 /* If this is a local symbol then we resolve it
6601 directly without creating a PLT entry. */
6605 if (h
->plt
.refcount
> 0)
6606 h
->plt
.refcount
-= 1;
6609 case BFD_RELOC_AARCH64_ADR_HI21_NC_PCREL
:
6610 case BFD_RELOC_AARCH64_ADR_HI21_PCREL
:
6611 case BFD_RELOC_AARCH64_ADR_LO21_PCREL
:
6612 case BFD_RELOC_AARCH64_MOVW_G0_NC
:
6613 case BFD_RELOC_AARCH64_MOVW_G1_NC
:
6614 case BFD_RELOC_AARCH64_MOVW_G2_NC
:
6615 case BFD_RELOC_AARCH64_MOVW_G3
:
6616 case BFD_RELOC_AARCH64_NN
:
6617 if (h
!= NULL
&& bfd_link_executable (info
))
6619 if (h
->plt
.refcount
> 0)
6620 h
->plt
.refcount
-= 1;
6632 /* Adjust a symbol defined by a dynamic object and referenced by a
6633 regular object. The current definition is in some section of the
6634 dynamic object, but we're not including those sections. We have to
6635 change the definition to something the rest of the link can
6639 elfNN_aarch64_adjust_dynamic_symbol (struct bfd_link_info
*info
,
6640 struct elf_link_hash_entry
*h
)
6642 struct elf_aarch64_link_hash_table
*htab
;
6645 /* If this is a function, put it in the procedure linkage table. We
6646 will fill in the contents of the procedure linkage table later,
6647 when we know the address of the .got section. */
6648 if (h
->type
== STT_FUNC
|| h
->type
== STT_GNU_IFUNC
|| h
->needs_plt
)
6650 if (h
->plt
.refcount
<= 0
6651 || (h
->type
!= STT_GNU_IFUNC
6652 && (SYMBOL_CALLS_LOCAL (info
, h
)
6653 || (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
6654 && h
->root
.type
== bfd_link_hash_undefweak
))))
6656 /* This case can occur if we saw a CALL26 reloc in
6657 an input file, but the symbol wasn't referred to
6658 by a dynamic object or all references were
6659 garbage collected. In which case we can end up
6661 h
->plt
.offset
= (bfd_vma
) - 1;
6668 /* Otherwise, reset to -1. */
6669 h
->plt
.offset
= (bfd_vma
) - 1;
6672 /* If this is a weak symbol, and there is a real definition, the
6673 processor independent code will have arranged for us to see the
6674 real definition first, and we can just use the same value. */
6675 if (h
->u
.weakdef
!= NULL
)
6677 BFD_ASSERT (h
->u
.weakdef
->root
.type
== bfd_link_hash_defined
6678 || h
->u
.weakdef
->root
.type
== bfd_link_hash_defweak
);
6679 h
->root
.u
.def
.section
= h
->u
.weakdef
->root
.u
.def
.section
;
6680 h
->root
.u
.def
.value
= h
->u
.weakdef
->root
.u
.def
.value
;
6681 if (ELIMINATE_COPY_RELOCS
|| info
->nocopyreloc
)
6682 h
->non_got_ref
= h
->u
.weakdef
->non_got_ref
;
6686 /* If we are creating a shared library, we must presume that the
6687 only references to the symbol are via the global offset table.
6688 For such cases we need not do anything here; the relocations will
6689 be handled correctly by relocate_section. */
6690 if (bfd_link_pic (info
))
6693 /* If there are no references to this symbol that do not use the
6694 GOT, we don't need to generate a copy reloc. */
6695 if (!h
->non_got_ref
)
6698 /* If -z nocopyreloc was given, we won't generate them either. */
6699 if (info
->nocopyreloc
)
6705 /* We must allocate the symbol in our .dynbss section, which will
6706 become part of the .bss section of the executable. There will be
6707 an entry for this symbol in the .dynsym section. The dynamic
6708 object will contain position independent code, so all references
6709 from the dynamic object to this symbol will go through the global
6710 offset table. The dynamic linker will use the .dynsym entry to
6711 determine the address it must put in the global offset table, so
6712 both the dynamic object and the regular object will refer to the
6713 same memory location for the variable. */
6715 htab
= elf_aarch64_hash_table (info
);
6717 /* We must generate a R_AARCH64_COPY reloc to tell the dynamic linker
6718 to copy the initial value out of the dynamic object and into the
6719 runtime process image. */
6720 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0 && h
->size
!= 0)
6722 htab
->srelbss
->size
+= RELOC_SIZE (htab
);
6728 return _bfd_elf_adjust_dynamic_copy (info
, h
, s
);
6733 elfNN_aarch64_allocate_local_symbols (bfd
*abfd
, unsigned number
)
6735 struct elf_aarch64_local_symbol
*locals
;
6736 locals
= elf_aarch64_locals (abfd
);
6739 locals
= (struct elf_aarch64_local_symbol
*)
6740 bfd_zalloc (abfd
, number
* sizeof (struct elf_aarch64_local_symbol
));
6743 elf_aarch64_locals (abfd
) = locals
;
6748 /* Create the .got section to hold the global offset table. */
6751 aarch64_elf_create_got_section (bfd
*abfd
, struct bfd_link_info
*info
)
6753 const struct elf_backend_data
*bed
= get_elf_backend_data (abfd
);
6756 struct elf_link_hash_entry
*h
;
6757 struct elf_link_hash_table
*htab
= elf_hash_table (info
);
6759 /* This function may be called more than once. */
6760 s
= bfd_get_linker_section (abfd
, ".got");
6764 flags
= bed
->dynamic_sec_flags
;
6766 s
= bfd_make_section_anyway_with_flags (abfd
,
6767 (bed
->rela_plts_and_copies_p
6768 ? ".rela.got" : ".rel.got"),
6769 (bed
->dynamic_sec_flags
6772 || ! bfd_set_section_alignment (abfd
, s
, bed
->s
->log_file_align
))
6776 s
= bfd_make_section_anyway_with_flags (abfd
, ".got", flags
);
6778 || !bfd_set_section_alignment (abfd
, s
, bed
->s
->log_file_align
))
6781 htab
->sgot
->size
+= GOT_ENTRY_SIZE
;
6783 if (bed
->want_got_sym
)
6785 /* Define the symbol _GLOBAL_OFFSET_TABLE_ at the start of the .got
6786 (or .got.plt) section. We don't do this in the linker script
6787 because we don't want to define the symbol if we are not creating
6788 a global offset table. */
6789 h
= _bfd_elf_define_linkage_sym (abfd
, info
, s
,
6790 "_GLOBAL_OFFSET_TABLE_");
6791 elf_hash_table (info
)->hgot
= h
;
6796 if (bed
->want_got_plt
)
6798 s
= bfd_make_section_anyway_with_flags (abfd
, ".got.plt", flags
);
6800 || !bfd_set_section_alignment (abfd
, s
,
6801 bed
->s
->log_file_align
))
6806 /* The first bit of the global offset table is the header. */
6807 s
->size
+= bed
->got_header_size
;
6812 /* Look through the relocs for a section during the first phase. */
6815 elfNN_aarch64_check_relocs (bfd
*abfd
, struct bfd_link_info
*info
,
6816 asection
*sec
, const Elf_Internal_Rela
*relocs
)
6818 Elf_Internal_Shdr
*symtab_hdr
;
6819 struct elf_link_hash_entry
**sym_hashes
;
6820 const Elf_Internal_Rela
*rel
;
6821 const Elf_Internal_Rela
*rel_end
;
6824 struct elf_aarch64_link_hash_table
*htab
;
6826 if (bfd_link_relocatable (info
))
6829 BFD_ASSERT (is_aarch64_elf (abfd
));
6831 htab
= elf_aarch64_hash_table (info
);
6834 symtab_hdr
= &elf_symtab_hdr (abfd
);
6835 sym_hashes
= elf_sym_hashes (abfd
);
6837 rel_end
= relocs
+ sec
->reloc_count
;
6838 for (rel
= relocs
; rel
< rel_end
; rel
++)
6840 struct elf_link_hash_entry
*h
;
6841 unsigned long r_symndx
;
6842 unsigned int r_type
;
6843 bfd_reloc_code_real_type bfd_r_type
;
6844 Elf_Internal_Sym
*isym
;
6846 r_symndx
= ELFNN_R_SYM (rel
->r_info
);
6847 r_type
= ELFNN_R_TYPE (rel
->r_info
);
6849 if (r_symndx
>= NUM_SHDR_ENTRIES (symtab_hdr
))
6851 (*_bfd_error_handler
) (_("%B: bad symbol index: %d"), abfd
,
6856 if (r_symndx
< symtab_hdr
->sh_info
)
6858 /* A local symbol. */
6859 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
6864 /* Check relocation against local STT_GNU_IFUNC symbol. */
6865 if (ELF_ST_TYPE (isym
->st_info
) == STT_GNU_IFUNC
)
6867 h
= elfNN_aarch64_get_local_sym_hash (htab
, abfd
, rel
,
6872 /* Fake a STT_GNU_IFUNC symbol. */
6873 h
->type
= STT_GNU_IFUNC
;
6876 h
->forced_local
= 1;
6877 h
->root
.type
= bfd_link_hash_defined
;
6884 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
6885 while (h
->root
.type
== bfd_link_hash_indirect
6886 || h
->root
.type
== bfd_link_hash_warning
)
6887 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
6889 /* PR15323, ref flags aren't set for references in the same
6891 h
->root
.non_ir_ref
= 1;
6894 /* Could be done earlier, if h were already available. */
6895 bfd_r_type
= aarch64_tls_transition (abfd
, info
, r_type
, h
, r_symndx
);
6899 /* Create the ifunc sections for static executables. If we
6900 never see an indirect function symbol nor we are building
6901 a static executable, those sections will be empty and
6902 won't appear in output. */
6908 case BFD_RELOC_AARCH64_ADD_LO12
:
6909 case BFD_RELOC_AARCH64_ADR_GOT_PAGE
:
6910 case BFD_RELOC_AARCH64_ADR_HI21_PCREL
:
6911 case BFD_RELOC_AARCH64_CALL26
:
6912 case BFD_RELOC_AARCH64_GOT_LD_PREL19
:
6913 case BFD_RELOC_AARCH64_JUMP26
:
6914 case BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14
:
6915 case BFD_RELOC_AARCH64_LD32_GOT_LO12_NC
:
6916 case BFD_RELOC_AARCH64_LD64_GOTOFF_LO15
:
6917 case BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15
:
6918 case BFD_RELOC_AARCH64_LD64_GOT_LO12_NC
:
6919 case BFD_RELOC_AARCH64_MOVW_GOTOFF_G0_NC
:
6920 case BFD_RELOC_AARCH64_MOVW_GOTOFF_G1
:
6921 case BFD_RELOC_AARCH64_NN
:
6922 if (htab
->root
.dynobj
== NULL
)
6923 htab
->root
.dynobj
= abfd
;
6924 if (!_bfd_elf_create_ifunc_sections (htab
->root
.dynobj
, info
))
6929 /* It is referenced by a non-shared object. */
6931 h
->root
.non_ir_ref
= 1;
6936 case BFD_RELOC_AARCH64_NN
:
6938 /* We don't need to handle relocs into sections not going into
6939 the "real" output. */
6940 if ((sec
->flags
& SEC_ALLOC
) == 0)
6945 if (!bfd_link_pic (info
))
6948 h
->plt
.refcount
+= 1;
6949 h
->pointer_equality_needed
= 1;
6952 /* No need to do anything if we're not creating a shared
6954 if (! bfd_link_pic (info
))
6958 struct elf_dyn_relocs
*p
;
6959 struct elf_dyn_relocs
**head
;
6961 /* We must copy these reloc types into the output file.
6962 Create a reloc section in dynobj and make room for
6966 if (htab
->root
.dynobj
== NULL
)
6967 htab
->root
.dynobj
= abfd
;
6969 sreloc
= _bfd_elf_make_dynamic_reloc_section
6970 (sec
, htab
->root
.dynobj
, LOG_FILE_ALIGN
, abfd
, /*rela? */ TRUE
);
6976 /* If this is a global symbol, we count the number of
6977 relocations we need for this symbol. */
6980 struct elf_aarch64_link_hash_entry
*eh
;
6981 eh
= (struct elf_aarch64_link_hash_entry
*) h
;
6982 head
= &eh
->dyn_relocs
;
6986 /* Track dynamic relocs needed for local syms too.
6987 We really need local syms available to do this
6993 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
6998 s
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
7002 /* Beware of type punned pointers vs strict aliasing
7004 vpp
= &(elf_section_data (s
)->local_dynrel
);
7005 head
= (struct elf_dyn_relocs
**) vpp
;
7009 if (p
== NULL
|| p
->sec
!= sec
)
7011 bfd_size_type amt
= sizeof *p
;
7012 p
= ((struct elf_dyn_relocs
*)
7013 bfd_zalloc (htab
->root
.dynobj
, amt
));
7026 /* RR: We probably want to keep a consistency check that
7027 there are no dangling GOT_PAGE relocs. */
7028 case BFD_RELOC_AARCH64_ADR_GOT_PAGE
:
7029 case BFD_RELOC_AARCH64_GOT_LD_PREL19
:
7030 case BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14
:
7031 case BFD_RELOC_AARCH64_LD32_GOT_LO12_NC
:
7032 case BFD_RELOC_AARCH64_LD64_GOTOFF_LO15
:
7033 case BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15
:
7034 case BFD_RELOC_AARCH64_LD64_GOT_LO12_NC
:
7035 case BFD_RELOC_AARCH64_MOVW_GOTOFF_G0_NC
:
7036 case BFD_RELOC_AARCH64_MOVW_GOTOFF_G1
:
7037 case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12_NC
:
7038 case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21
:
7039 case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21
:
7040 case BFD_RELOC_AARCH64_TLSDESC_LD32_LO12_NC
:
7041 case BFD_RELOC_AARCH64_TLSDESC_LD64_LO12_NC
:
7042 case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19
:
7043 case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC
:
7044 case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21
:
7045 case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21
:
7046 case BFD_RELOC_AARCH64_TLSGD_MOVW_G0_NC
:
7047 case BFD_RELOC_AARCH64_TLSGD_MOVW_G1
:
7048 case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21
:
7049 case BFD_RELOC_AARCH64_TLSIE_LD32_GOTTPREL_LO12_NC
:
7050 case BFD_RELOC_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC
:
7051 case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19
:
7052 case BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G0_NC
:
7053 case BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G1
:
7054 case BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC
:
7055 case BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21
:
7056 case BFD_RELOC_AARCH64_TLSLD_ADR_PREL21
:
7057 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1
:
7058 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1_NC
:
7059 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G2
:
7062 unsigned old_got_type
;
7064 got_type
= aarch64_reloc_got_type (bfd_r_type
);
7068 h
->got
.refcount
+= 1;
7069 old_got_type
= elf_aarch64_hash_entry (h
)->got_type
;
7073 struct elf_aarch64_local_symbol
*locals
;
7075 if (!elfNN_aarch64_allocate_local_symbols
7076 (abfd
, symtab_hdr
->sh_info
))
7079 locals
= elf_aarch64_locals (abfd
);
7080 BFD_ASSERT (r_symndx
< symtab_hdr
->sh_info
);
7081 locals
[r_symndx
].got_refcount
+= 1;
7082 old_got_type
= locals
[r_symndx
].got_type
;
7085 /* If a variable is accessed with both general dynamic TLS
7086 methods, two slots may be created. */
7087 if (GOT_TLS_GD_ANY_P (old_got_type
) && GOT_TLS_GD_ANY_P (got_type
))
7088 got_type
|= old_got_type
;
7090 /* We will already have issued an error message if there
7091 is a TLS/non-TLS mismatch, based on the symbol type.
7092 So just combine any TLS types needed. */
7093 if (old_got_type
!= GOT_UNKNOWN
&& old_got_type
!= GOT_NORMAL
7094 && got_type
!= GOT_NORMAL
)
7095 got_type
|= old_got_type
;
7097 /* If the symbol is accessed by both IE and GD methods, we
7098 are able to relax. Turn off the GD flag, without
7099 messing up with any other kind of TLS types that may be
7101 if ((got_type
& GOT_TLS_IE
) && GOT_TLS_GD_ANY_P (got_type
))
7102 got_type
&= ~ (GOT_TLSDESC_GD
| GOT_TLS_GD
);
7104 if (old_got_type
!= got_type
)
7107 elf_aarch64_hash_entry (h
)->got_type
= got_type
;
7110 struct elf_aarch64_local_symbol
*locals
;
7111 locals
= elf_aarch64_locals (abfd
);
7112 BFD_ASSERT (r_symndx
< symtab_hdr
->sh_info
);
7113 locals
[r_symndx
].got_type
= got_type
;
7117 if (htab
->root
.dynobj
== NULL
)
7118 htab
->root
.dynobj
= abfd
;
7119 if (! aarch64_elf_create_got_section (htab
->root
.dynobj
, info
))
7124 case BFD_RELOC_AARCH64_MOVW_G0_NC
:
7125 case BFD_RELOC_AARCH64_MOVW_G1_NC
:
7126 case BFD_RELOC_AARCH64_MOVW_G2_NC
:
7127 case BFD_RELOC_AARCH64_MOVW_G3
:
7128 if (bfd_link_pic (info
))
7130 int howto_index
= bfd_r_type
- BFD_RELOC_AARCH64_RELOC_START
;
7131 (*_bfd_error_handler
)
7132 (_("%B: relocation %s against `%s' can not be used when making "
7133 "a shared object; recompile with -fPIC"),
7134 abfd
, elfNN_aarch64_howto_table
[howto_index
].name
,
7135 (h
) ? h
->root
.root
.string
: "a local symbol");
7136 bfd_set_error (bfd_error_bad_value
);
7140 case BFD_RELOC_AARCH64_ADR_HI21_NC_PCREL
:
7141 case BFD_RELOC_AARCH64_ADR_HI21_PCREL
:
7142 case BFD_RELOC_AARCH64_ADR_LO21_PCREL
:
7143 if (h
!= NULL
&& bfd_link_executable (info
))
7145 /* If this reloc is in a read-only section, we might
7146 need a copy reloc. We can't check reliably at this
7147 stage whether the section is read-only, as input
7148 sections have not yet been mapped to output sections.
7149 Tentatively set the flag for now, and correct in
7150 adjust_dynamic_symbol. */
7152 h
->plt
.refcount
+= 1;
7153 h
->pointer_equality_needed
= 1;
7155 /* FIXME:: RR need to handle these in shared libraries
7156 and essentially bomb out as these being non-PIC
7157 relocations in shared libraries. */
7160 case BFD_RELOC_AARCH64_CALL26
:
7161 case BFD_RELOC_AARCH64_JUMP26
:
7162 /* If this is a local symbol then we resolve it
7163 directly without creating a PLT entry. */
7168 if (h
->plt
.refcount
<= 0)
7169 h
->plt
.refcount
= 1;
7171 h
->plt
.refcount
+= 1;
7182 /* Treat mapping symbols as special target symbols. */
7185 elfNN_aarch64_is_target_special_symbol (bfd
*abfd ATTRIBUTE_UNUSED
,
7188 return bfd_is_aarch64_special_symbol_name (sym
->name
,
7189 BFD_AARCH64_SPECIAL_SYM_TYPE_ANY
);
7192 /* This is a copy of elf_find_function () from elf.c except that
7193 AArch64 mapping symbols are ignored when looking for function names. */
7196 aarch64_elf_find_function (bfd
*abfd ATTRIBUTE_UNUSED
,
7200 const char **filename_ptr
,
7201 const char **functionname_ptr
)
7203 const char *filename
= NULL
;
7204 asymbol
*func
= NULL
;
7205 bfd_vma low_func
= 0;
7208 for (p
= symbols
; *p
!= NULL
; p
++)
7212 q
= (elf_symbol_type
*) * p
;
7214 switch (ELF_ST_TYPE (q
->internal_elf_sym
.st_info
))
7219 filename
= bfd_asymbol_name (&q
->symbol
);
7223 /* Skip mapping symbols. */
7224 if ((q
->symbol
.flags
& BSF_LOCAL
)
7225 && (bfd_is_aarch64_special_symbol_name
7226 (q
->symbol
.name
, BFD_AARCH64_SPECIAL_SYM_TYPE_ANY
)))
7229 if (bfd_get_section (&q
->symbol
) == section
7230 && q
->symbol
.value
>= low_func
&& q
->symbol
.value
<= offset
)
7232 func
= (asymbol
*) q
;
7233 low_func
= q
->symbol
.value
;
7243 *filename_ptr
= filename
;
7244 if (functionname_ptr
)
7245 *functionname_ptr
= bfd_asymbol_name (func
);
7251 /* Find the nearest line to a particular section and offset, for error
7252 reporting. This code is a duplicate of the code in elf.c, except
7253 that it uses aarch64_elf_find_function. */
7256 elfNN_aarch64_find_nearest_line (bfd
*abfd
,
7260 const char **filename_ptr
,
7261 const char **functionname_ptr
,
7262 unsigned int *line_ptr
,
7263 unsigned int *discriminator_ptr
)
7265 bfd_boolean found
= FALSE
;
7267 if (_bfd_dwarf2_find_nearest_line (abfd
, symbols
, NULL
, section
, offset
,
7268 filename_ptr
, functionname_ptr
,
7269 line_ptr
, discriminator_ptr
,
7270 dwarf_debug_sections
, 0,
7271 &elf_tdata (abfd
)->dwarf2_find_line_info
))
7273 if (!*functionname_ptr
)
7274 aarch64_elf_find_function (abfd
, symbols
, section
, offset
,
7275 *filename_ptr
? NULL
: filename_ptr
,
7281 /* Skip _bfd_dwarf1_find_nearest_line since no known AArch64
7282 toolchain uses DWARF1. */
7284 if (!_bfd_stab_section_find_nearest_line (abfd
, symbols
, section
, offset
,
7285 &found
, filename_ptr
,
7286 functionname_ptr
, line_ptr
,
7287 &elf_tdata (abfd
)->line_info
))
7290 if (found
&& (*functionname_ptr
|| *line_ptr
))
7293 if (symbols
== NULL
)
7296 if (!aarch64_elf_find_function (abfd
, symbols
, section
, offset
,
7297 filename_ptr
, functionname_ptr
))
7305 elfNN_aarch64_find_inliner_info (bfd
*abfd
,
7306 const char **filename_ptr
,
7307 const char **functionname_ptr
,
7308 unsigned int *line_ptr
)
7311 found
= _bfd_dwarf2_find_inliner_info
7312 (abfd
, filename_ptr
,
7313 functionname_ptr
, line_ptr
, &elf_tdata (abfd
)->dwarf2_find_line_info
);
7319 elfNN_aarch64_post_process_headers (bfd
*abfd
,
7320 struct bfd_link_info
*link_info
)
7322 Elf_Internal_Ehdr
*i_ehdrp
; /* ELF file header, internal form. */
7324 i_ehdrp
= elf_elfheader (abfd
);
7325 i_ehdrp
->e_ident
[EI_ABIVERSION
] = AARCH64_ELF_ABI_VERSION
;
7327 _bfd_elf_post_process_headers (abfd
, link_info
);
7330 static enum elf_reloc_type_class
7331 elfNN_aarch64_reloc_type_class (const struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
7332 const asection
*rel_sec ATTRIBUTE_UNUSED
,
7333 const Elf_Internal_Rela
*rela
)
7335 switch ((int) ELFNN_R_TYPE (rela
->r_info
))
7337 case AARCH64_R (RELATIVE
):
7338 return reloc_class_relative
;
7339 case AARCH64_R (JUMP_SLOT
):
7340 return reloc_class_plt
;
7341 case AARCH64_R (COPY
):
7342 return reloc_class_copy
;
7344 return reloc_class_normal
;
7348 /* Handle an AArch64 specific section when reading an object file. This is
7349 called when bfd_section_from_shdr finds a section with an unknown
7353 elfNN_aarch64_section_from_shdr (bfd
*abfd
,
7354 Elf_Internal_Shdr
*hdr
,
7355 const char *name
, int shindex
)
7357 /* There ought to be a place to keep ELF backend specific flags, but
7358 at the moment there isn't one. We just keep track of the
7359 sections by their name, instead. Fortunately, the ABI gives
7360 names for all the AArch64 specific sections, so we will probably get
7362 switch (hdr
->sh_type
)
7364 case SHT_AARCH64_ATTRIBUTES
:
7371 if (!_bfd_elf_make_section_from_shdr (abfd
, hdr
, name
, shindex
))
7377 /* A structure used to record a list of sections, independently
7378 of the next and prev fields in the asection structure. */
7379 typedef struct section_list
7382 struct section_list
*next
;
7383 struct section_list
*prev
;
7387 /* Unfortunately we need to keep a list of sections for which
7388 an _aarch64_elf_section_data structure has been allocated. This
7389 is because it is possible for functions like elfNN_aarch64_write_section
7390 to be called on a section which has had an elf_data_structure
7391 allocated for it (and so the used_by_bfd field is valid) but
7392 for which the AArch64 extended version of this structure - the
7393 _aarch64_elf_section_data structure - has not been allocated. */
7394 static section_list
*sections_with_aarch64_elf_section_data
= NULL
;
7397 record_section_with_aarch64_elf_section_data (asection
*sec
)
7399 struct section_list
*entry
;
7401 entry
= bfd_malloc (sizeof (*entry
));
7405 entry
->next
= sections_with_aarch64_elf_section_data
;
7407 if (entry
->next
!= NULL
)
7408 entry
->next
->prev
= entry
;
7409 sections_with_aarch64_elf_section_data
= entry
;
7412 static struct section_list
*
7413 find_aarch64_elf_section_entry (asection
*sec
)
7415 struct section_list
*entry
;
7416 static struct section_list
*last_entry
= NULL
;
7418 /* This is a short cut for the typical case where the sections are added
7419 to the sections_with_aarch64_elf_section_data list in forward order and
7420 then looked up here in backwards order. This makes a real difference
7421 to the ld-srec/sec64k.exp linker test. */
7422 entry
= sections_with_aarch64_elf_section_data
;
7423 if (last_entry
!= NULL
)
7425 if (last_entry
->sec
== sec
)
7427 else if (last_entry
->next
!= NULL
&& last_entry
->next
->sec
== sec
)
7428 entry
= last_entry
->next
;
7431 for (; entry
; entry
= entry
->next
)
7432 if (entry
->sec
== sec
)
7436 /* Record the entry prior to this one - it is the entry we are
7437 most likely to want to locate next time. Also this way if we
7438 have been called from
7439 unrecord_section_with_aarch64_elf_section_data () we will not
7440 be caching a pointer that is about to be freed. */
7441 last_entry
= entry
->prev
;
7447 unrecord_section_with_aarch64_elf_section_data (asection
*sec
)
7449 struct section_list
*entry
;
7451 entry
= find_aarch64_elf_section_entry (sec
);
7455 if (entry
->prev
!= NULL
)
7456 entry
->prev
->next
= entry
->next
;
7457 if (entry
->next
!= NULL
)
7458 entry
->next
->prev
= entry
->prev
;
7459 if (entry
== sections_with_aarch64_elf_section_data
)
7460 sections_with_aarch64_elf_section_data
= entry
->next
;
7469 struct bfd_link_info
*info
;
7472 int (*func
) (void *, const char *, Elf_Internal_Sym
*,
7473 asection
*, struct elf_link_hash_entry
*);
7474 } output_arch_syminfo
;
7476 enum map_symbol_type
7483 /* Output a single mapping symbol. */
7486 elfNN_aarch64_output_map_sym (output_arch_syminfo
*osi
,
7487 enum map_symbol_type type
, bfd_vma offset
)
7489 static const char *names
[2] = { "$x", "$d" };
7490 Elf_Internal_Sym sym
;
7492 sym
.st_value
= (osi
->sec
->output_section
->vma
7493 + osi
->sec
->output_offset
+ offset
);
7496 sym
.st_info
= ELF_ST_INFO (STB_LOCAL
, STT_NOTYPE
);
7497 sym
.st_shndx
= osi
->sec_shndx
;
7498 return osi
->func (osi
->finfo
, names
[type
], &sym
, osi
->sec
, NULL
) == 1;
7501 /* Output a single local symbol for a generated stub. */
7504 elfNN_aarch64_output_stub_sym (output_arch_syminfo
*osi
, const char *name
,
7505 bfd_vma offset
, bfd_vma size
)
7507 Elf_Internal_Sym sym
;
7509 sym
.st_value
= (osi
->sec
->output_section
->vma
7510 + osi
->sec
->output_offset
+ offset
);
7513 sym
.st_info
= ELF_ST_INFO (STB_LOCAL
, STT_FUNC
);
7514 sym
.st_shndx
= osi
->sec_shndx
;
7515 return osi
->func (osi
->finfo
, name
, &sym
, osi
->sec
, NULL
) == 1;
7519 aarch64_map_one_stub (struct bfd_hash_entry
*gen_entry
, void *in_arg
)
7521 struct elf_aarch64_stub_hash_entry
*stub_entry
;
7525 output_arch_syminfo
*osi
;
7527 /* Massage our args to the form they really have. */
7528 stub_entry
= (struct elf_aarch64_stub_hash_entry
*) gen_entry
;
7529 osi
= (output_arch_syminfo
*) in_arg
;
7531 stub_sec
= stub_entry
->stub_sec
;
7533 /* Ensure this stub is attached to the current section being
7535 if (stub_sec
!= osi
->sec
)
7538 addr
= (bfd_vma
) stub_entry
->stub_offset
;
7540 stub_name
= stub_entry
->output_name
;
7542 switch (stub_entry
->stub_type
)
7544 case aarch64_stub_adrp_branch
:
7545 if (!elfNN_aarch64_output_stub_sym (osi
, stub_name
, addr
,
7546 sizeof (aarch64_adrp_branch_stub
)))
7548 if (!elfNN_aarch64_output_map_sym (osi
, AARCH64_MAP_INSN
, addr
))
7551 case aarch64_stub_long_branch
:
7552 if (!elfNN_aarch64_output_stub_sym
7553 (osi
, stub_name
, addr
, sizeof (aarch64_long_branch_stub
)))
7555 if (!elfNN_aarch64_output_map_sym (osi
, AARCH64_MAP_INSN
, addr
))
7557 if (!elfNN_aarch64_output_map_sym (osi
, AARCH64_MAP_DATA
, addr
+ 16))
7560 case aarch64_stub_erratum_835769_veneer
:
7561 if (!elfNN_aarch64_output_stub_sym (osi
, stub_name
, addr
,
7562 sizeof (aarch64_erratum_835769_stub
)))
7564 if (!elfNN_aarch64_output_map_sym (osi
, AARCH64_MAP_INSN
, addr
))
7567 case aarch64_stub_erratum_843419_veneer
:
7568 if (!elfNN_aarch64_output_stub_sym (osi
, stub_name
, addr
,
7569 sizeof (aarch64_erratum_843419_stub
)))
7571 if (!elfNN_aarch64_output_map_sym (osi
, AARCH64_MAP_INSN
, addr
))
7582 /* Output mapping symbols for linker generated sections. */
7585 elfNN_aarch64_output_arch_local_syms (bfd
*output_bfd
,
7586 struct bfd_link_info
*info
,
7588 int (*func
) (void *, const char *,
7591 struct elf_link_hash_entry
7594 output_arch_syminfo osi
;
7595 struct elf_aarch64_link_hash_table
*htab
;
7597 htab
= elf_aarch64_hash_table (info
);
7603 /* Long calls stubs. */
7604 if (htab
->stub_bfd
&& htab
->stub_bfd
->sections
)
7608 for (stub_sec
= htab
->stub_bfd
->sections
;
7609 stub_sec
!= NULL
; stub_sec
= stub_sec
->next
)
7611 /* Ignore non-stub sections. */
7612 if (!strstr (stub_sec
->name
, STUB_SUFFIX
))
7617 osi
.sec_shndx
= _bfd_elf_section_from_bfd_section
7618 (output_bfd
, osi
.sec
->output_section
);
7620 /* The first instruction in a stub is always a branch. */
7621 if (!elfNN_aarch64_output_map_sym (&osi
, AARCH64_MAP_INSN
, 0))
7624 bfd_hash_traverse (&htab
->stub_hash_table
, aarch64_map_one_stub
,
7629 /* Finally, output mapping symbols for the PLT. */
7630 if (!htab
->root
.splt
|| htab
->root
.splt
->size
== 0)
7633 osi
.sec_shndx
= _bfd_elf_section_from_bfd_section
7634 (output_bfd
, htab
->root
.splt
->output_section
);
7635 osi
.sec
= htab
->root
.splt
;
7637 elfNN_aarch64_output_map_sym (&osi
, AARCH64_MAP_INSN
, 0);
7643 /* Allocate target specific section data. */
7646 elfNN_aarch64_new_section_hook (bfd
*abfd
, asection
*sec
)
7648 if (!sec
->used_by_bfd
)
7650 _aarch64_elf_section_data
*sdata
;
7651 bfd_size_type amt
= sizeof (*sdata
);
7653 sdata
= bfd_zalloc (abfd
, amt
);
7656 sec
->used_by_bfd
= sdata
;
7659 record_section_with_aarch64_elf_section_data (sec
);
7661 return _bfd_elf_new_section_hook (abfd
, sec
);
7666 unrecord_section_via_map_over_sections (bfd
*abfd ATTRIBUTE_UNUSED
,
7668 void *ignore ATTRIBUTE_UNUSED
)
7670 unrecord_section_with_aarch64_elf_section_data (sec
);
7674 elfNN_aarch64_close_and_cleanup (bfd
*abfd
)
7677 bfd_map_over_sections (abfd
,
7678 unrecord_section_via_map_over_sections
, NULL
);
7680 return _bfd_elf_close_and_cleanup (abfd
);
7684 elfNN_aarch64_bfd_free_cached_info (bfd
*abfd
)
7687 bfd_map_over_sections (abfd
,
7688 unrecord_section_via_map_over_sections
, NULL
);
7690 return _bfd_free_cached_info (abfd
);
7693 /* Create dynamic sections. This is different from the ARM backend in that
7694 the got, plt, gotplt and their relocation sections are all created in the
7695 standard part of the bfd elf backend. */
7698 elfNN_aarch64_create_dynamic_sections (bfd
*dynobj
,
7699 struct bfd_link_info
*info
)
7701 struct elf_aarch64_link_hash_table
*htab
;
7703 /* We need to create .got section. */
7704 if (!aarch64_elf_create_got_section (dynobj
, info
))
7707 if (!_bfd_elf_create_dynamic_sections (dynobj
, info
))
7710 htab
= elf_aarch64_hash_table (info
);
7711 htab
->sdynbss
= bfd_get_linker_section (dynobj
, ".dynbss");
7712 if (!bfd_link_pic (info
))
7713 htab
->srelbss
= bfd_get_linker_section (dynobj
, ".rela.bss");
7715 if (!htab
->sdynbss
|| (!bfd_link_pic (info
) && !htab
->srelbss
))
7722 /* Allocate space in .plt, .got and associated reloc sections for
7726 elfNN_aarch64_allocate_dynrelocs (struct elf_link_hash_entry
*h
, void *inf
)
7728 struct bfd_link_info
*info
;
7729 struct elf_aarch64_link_hash_table
*htab
;
7730 struct elf_aarch64_link_hash_entry
*eh
;
7731 struct elf_dyn_relocs
*p
;
7733 /* An example of a bfd_link_hash_indirect symbol is versioned
7734 symbol. For example: __gxx_personality_v0(bfd_link_hash_indirect)
7735 -> __gxx_personality_v0(bfd_link_hash_defined)
7737 There is no need to process bfd_link_hash_indirect symbols here
7738 because we will also be presented with the concrete instance of
7739 the symbol and elfNN_aarch64_copy_indirect_symbol () will have been
7740 called to copy all relevant data from the generic to the concrete
7743 if (h
->root
.type
== bfd_link_hash_indirect
)
7746 if (h
->root
.type
== bfd_link_hash_warning
)
7747 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
7749 info
= (struct bfd_link_info
*) inf
;
7750 htab
= elf_aarch64_hash_table (info
);
7752 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle it
7753 here if it is defined and referenced in a non-shared object. */
7754 if (h
->type
== STT_GNU_IFUNC
7757 else if (htab
->root
.dynamic_sections_created
&& h
->plt
.refcount
> 0)
7759 /* Make sure this symbol is output as a dynamic symbol.
7760 Undefined weak syms won't yet be marked as dynamic. */
7761 if (h
->dynindx
== -1 && !h
->forced_local
)
7763 if (!bfd_elf_link_record_dynamic_symbol (info
, h
))
7767 if (bfd_link_pic (info
) || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h
))
7769 asection
*s
= htab
->root
.splt
;
7771 /* If this is the first .plt entry, make room for the special
7774 s
->size
+= htab
->plt_header_size
;
7776 h
->plt
.offset
= s
->size
;
7778 /* If this symbol is not defined in a regular file, and we are
7779 not generating a shared library, then set the symbol to this
7780 location in the .plt. This is required to make function
7781 pointers compare as equal between the normal executable and
7782 the shared library. */
7783 if (!bfd_link_pic (info
) && !h
->def_regular
)
7785 h
->root
.u
.def
.section
= s
;
7786 h
->root
.u
.def
.value
= h
->plt
.offset
;
7789 /* Make room for this entry. For now we only create the
7790 small model PLT entries. We later need to find a way
7791 of relaxing into these from the large model PLT entries. */
7792 s
->size
+= PLT_SMALL_ENTRY_SIZE
;
7794 /* We also need to make an entry in the .got.plt section, which
7795 will be placed in the .got section by the linker script. */
7796 htab
->root
.sgotplt
->size
+= GOT_ENTRY_SIZE
;
7798 /* We also need to make an entry in the .rela.plt section. */
7799 htab
->root
.srelplt
->size
+= RELOC_SIZE (htab
);
7801 /* We need to ensure that all GOT entries that serve the PLT
7802 are consecutive with the special GOT slots [0] [1] and
7803 [2]. Any addtional relocations, such as
7804 R_AARCH64_TLSDESC, must be placed after the PLT related
7805 entries. We abuse the reloc_count such that during
7806 sizing we adjust reloc_count to indicate the number of
7807 PLT related reserved entries. In subsequent phases when
7808 filling in the contents of the reloc entries, PLT related
7809 entries are placed by computing their PLT index (0
7810 .. reloc_count). While other none PLT relocs are placed
7811 at the slot indicated by reloc_count and reloc_count is
7814 htab
->root
.srelplt
->reloc_count
++;
7818 h
->plt
.offset
= (bfd_vma
) - 1;
7824 h
->plt
.offset
= (bfd_vma
) - 1;
7828 eh
= (struct elf_aarch64_link_hash_entry
*) h
;
7829 eh
->tlsdesc_got_jump_table_offset
= (bfd_vma
) - 1;
7831 if (h
->got
.refcount
> 0)
7834 unsigned got_type
= elf_aarch64_hash_entry (h
)->got_type
;
7836 h
->got
.offset
= (bfd_vma
) - 1;
7838 dyn
= htab
->root
.dynamic_sections_created
;
7840 /* Make sure this symbol is output as a dynamic symbol.
7841 Undefined weak syms won't yet be marked as dynamic. */
7842 if (dyn
&& h
->dynindx
== -1 && !h
->forced_local
)
7844 if (!bfd_elf_link_record_dynamic_symbol (info
, h
))
7848 if (got_type
== GOT_UNKNOWN
)
7851 else if (got_type
== GOT_NORMAL
)
7853 h
->got
.offset
= htab
->root
.sgot
->size
;
7854 htab
->root
.sgot
->size
+= GOT_ENTRY_SIZE
;
7855 if ((ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
7856 || h
->root
.type
!= bfd_link_hash_undefweak
)
7857 && (bfd_link_pic (info
)
7858 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, 0, h
)))
7860 htab
->root
.srelgot
->size
+= RELOC_SIZE (htab
);
7866 if (got_type
& GOT_TLSDESC_GD
)
7868 eh
->tlsdesc_got_jump_table_offset
=
7869 (htab
->root
.sgotplt
->size
7870 - aarch64_compute_jump_table_size (htab
));
7871 htab
->root
.sgotplt
->size
+= GOT_ENTRY_SIZE
* 2;
7872 h
->got
.offset
= (bfd_vma
) - 2;
7875 if (got_type
& GOT_TLS_GD
)
7877 h
->got
.offset
= htab
->root
.sgot
->size
;
7878 htab
->root
.sgot
->size
+= GOT_ENTRY_SIZE
* 2;
7881 if (got_type
& GOT_TLS_IE
)
7883 h
->got
.offset
= htab
->root
.sgot
->size
;
7884 htab
->root
.sgot
->size
+= GOT_ENTRY_SIZE
;
7887 indx
= h
&& h
->dynindx
!= -1 ? h
->dynindx
: 0;
7888 if ((ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
7889 || h
->root
.type
!= bfd_link_hash_undefweak
)
7890 && (bfd_link_pic (info
)
7892 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, 0, h
)))
7894 if (got_type
& GOT_TLSDESC_GD
)
7896 htab
->root
.srelplt
->size
+= RELOC_SIZE (htab
);
7897 /* Note reloc_count not incremented here! We have
7898 already adjusted reloc_count for this relocation
7901 /* TLSDESC PLT is now needed, but not yet determined. */
7902 htab
->tlsdesc_plt
= (bfd_vma
) - 1;
7905 if (got_type
& GOT_TLS_GD
)
7906 htab
->root
.srelgot
->size
+= RELOC_SIZE (htab
) * 2;
7908 if (got_type
& GOT_TLS_IE
)
7909 htab
->root
.srelgot
->size
+= RELOC_SIZE (htab
);
7915 h
->got
.offset
= (bfd_vma
) - 1;
7918 if (eh
->dyn_relocs
== NULL
)
7921 /* In the shared -Bsymbolic case, discard space allocated for
7922 dynamic pc-relative relocs against symbols which turn out to be
7923 defined in regular objects. For the normal shared case, discard
7924 space for pc-relative relocs that have become local due to symbol
7925 visibility changes. */
7927 if (bfd_link_pic (info
))
7929 /* Relocs that use pc_count are those that appear on a call
7930 insn, or certain REL relocs that can generated via assembly.
7931 We want calls to protected symbols to resolve directly to the
7932 function rather than going via the plt. If people want
7933 function pointer comparisons to work as expected then they
7934 should avoid writing weird assembly. */
7935 if (SYMBOL_CALLS_LOCAL (info
, h
))
7937 struct elf_dyn_relocs
**pp
;
7939 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
;)
7941 p
->count
-= p
->pc_count
;
7950 /* Also discard relocs on undefined weak syms with non-default
7952 if (eh
->dyn_relocs
!= NULL
&& h
->root
.type
== bfd_link_hash_undefweak
)
7954 if (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
)
7955 eh
->dyn_relocs
= NULL
;
7957 /* Make sure undefined weak symbols are output as a dynamic
7959 else if (h
->dynindx
== -1
7961 && !bfd_elf_link_record_dynamic_symbol (info
, h
))
7966 else if (ELIMINATE_COPY_RELOCS
)
7968 /* For the non-shared case, discard space for relocs against
7969 symbols which turn out to need copy relocs or are not
7975 || (htab
->root
.dynamic_sections_created
7976 && (h
->root
.type
== bfd_link_hash_undefweak
7977 || h
->root
.type
== bfd_link_hash_undefined
))))
7979 /* Make sure this symbol is output as a dynamic symbol.
7980 Undefined weak syms won't yet be marked as dynamic. */
7981 if (h
->dynindx
== -1
7983 && !bfd_elf_link_record_dynamic_symbol (info
, h
))
7986 /* If that succeeded, we know we'll be keeping all the
7988 if (h
->dynindx
!= -1)
7992 eh
->dyn_relocs
= NULL
;
7997 /* Finally, allocate space. */
7998 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
8002 sreloc
= elf_section_data (p
->sec
)->sreloc
;
8004 BFD_ASSERT (sreloc
!= NULL
);
8006 sreloc
->size
+= p
->count
* RELOC_SIZE (htab
);
8012 /* Allocate space in .plt, .got and associated reloc sections for
8013 ifunc dynamic relocs. */
8016 elfNN_aarch64_allocate_ifunc_dynrelocs (struct elf_link_hash_entry
*h
,
8019 struct bfd_link_info
*info
;
8020 struct elf_aarch64_link_hash_table
*htab
;
8021 struct elf_aarch64_link_hash_entry
*eh
;
8023 /* An example of a bfd_link_hash_indirect symbol is versioned
8024 symbol. For example: __gxx_personality_v0(bfd_link_hash_indirect)
8025 -> __gxx_personality_v0(bfd_link_hash_defined)
8027 There is no need to process bfd_link_hash_indirect symbols here
8028 because we will also be presented with the concrete instance of
8029 the symbol and elfNN_aarch64_copy_indirect_symbol () will have been
8030 called to copy all relevant data from the generic to the concrete
8033 if (h
->root
.type
== bfd_link_hash_indirect
)
8036 if (h
->root
.type
== bfd_link_hash_warning
)
8037 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
8039 info
= (struct bfd_link_info
*) inf
;
8040 htab
= elf_aarch64_hash_table (info
);
8042 eh
= (struct elf_aarch64_link_hash_entry
*) h
;
8044 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle it
8045 here if it is defined and referenced in a non-shared object. */
8046 if (h
->type
== STT_GNU_IFUNC
8048 return _bfd_elf_allocate_ifunc_dyn_relocs (info
, h
,
8050 htab
->plt_entry_size
,
8051 htab
->plt_header_size
,
8056 /* Allocate space in .plt, .got and associated reloc sections for
8057 local dynamic relocs. */
8060 elfNN_aarch64_allocate_local_dynrelocs (void **slot
, void *inf
)
8062 struct elf_link_hash_entry
*h
8063 = (struct elf_link_hash_entry
*) *slot
;
8065 if (h
->type
!= STT_GNU_IFUNC
8069 || h
->root
.type
!= bfd_link_hash_defined
)
8072 return elfNN_aarch64_allocate_dynrelocs (h
, inf
);
8075 /* Allocate space in .plt, .got and associated reloc sections for
8076 local ifunc dynamic relocs. */
8079 elfNN_aarch64_allocate_local_ifunc_dynrelocs (void **slot
, void *inf
)
8081 struct elf_link_hash_entry
*h
8082 = (struct elf_link_hash_entry
*) *slot
;
8084 if (h
->type
!= STT_GNU_IFUNC
8088 || h
->root
.type
!= bfd_link_hash_defined
)
8091 return elfNN_aarch64_allocate_ifunc_dynrelocs (h
, inf
);
8094 /* Find any dynamic relocs that apply to read-only sections. */
8097 aarch64_readonly_dynrelocs (struct elf_link_hash_entry
* h
, void * inf
)
8099 struct elf_aarch64_link_hash_entry
* eh
;
8100 struct elf_dyn_relocs
* p
;
8102 eh
= (struct elf_aarch64_link_hash_entry
*) h
;
8103 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
8105 asection
*s
= p
->sec
;
8107 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
8109 struct bfd_link_info
*info
= (struct bfd_link_info
*) inf
;
8111 info
->flags
|= DF_TEXTREL
;
8113 /* Not an error, just cut short the traversal. */
8120 /* This is the most important function of all . Innocuosly named
8123 elfNN_aarch64_size_dynamic_sections (bfd
*output_bfd ATTRIBUTE_UNUSED
,
8124 struct bfd_link_info
*info
)
8126 struct elf_aarch64_link_hash_table
*htab
;
8132 htab
= elf_aarch64_hash_table ((info
));
8133 dynobj
= htab
->root
.dynobj
;
8135 BFD_ASSERT (dynobj
!= NULL
);
8137 if (htab
->root
.dynamic_sections_created
)
8139 if (bfd_link_executable (info
) && !info
->nointerp
)
8141 s
= bfd_get_linker_section (dynobj
, ".interp");
8144 s
->size
= sizeof ELF_DYNAMIC_INTERPRETER
;
8145 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
8149 /* Set up .got offsets for local syms, and space for local dynamic
8151 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
8153 struct elf_aarch64_local_symbol
*locals
= NULL
;
8154 Elf_Internal_Shdr
*symtab_hdr
;
8158 if (!is_aarch64_elf (ibfd
))
8161 for (s
= ibfd
->sections
; s
!= NULL
; s
= s
->next
)
8163 struct elf_dyn_relocs
*p
;
8165 for (p
= (struct elf_dyn_relocs
*)
8166 (elf_section_data (s
)->local_dynrel
); p
!= NULL
; p
= p
->next
)
8168 if (!bfd_is_abs_section (p
->sec
)
8169 && bfd_is_abs_section (p
->sec
->output_section
))
8171 /* Input section has been discarded, either because
8172 it is a copy of a linkonce section or due to
8173 linker script /DISCARD/, so we'll be discarding
8176 else if (p
->count
!= 0)
8178 srel
= elf_section_data (p
->sec
)->sreloc
;
8179 srel
->size
+= p
->count
* RELOC_SIZE (htab
);
8180 if ((p
->sec
->output_section
->flags
& SEC_READONLY
) != 0)
8181 info
->flags
|= DF_TEXTREL
;
8186 locals
= elf_aarch64_locals (ibfd
);
8190 symtab_hdr
= &elf_symtab_hdr (ibfd
);
8191 srel
= htab
->root
.srelgot
;
8192 for (i
= 0; i
< symtab_hdr
->sh_info
; i
++)
8194 locals
[i
].got_offset
= (bfd_vma
) - 1;
8195 locals
[i
].tlsdesc_got_jump_table_offset
= (bfd_vma
) - 1;
8196 if (locals
[i
].got_refcount
> 0)
8198 unsigned got_type
= locals
[i
].got_type
;
8199 if (got_type
& GOT_TLSDESC_GD
)
8201 locals
[i
].tlsdesc_got_jump_table_offset
=
8202 (htab
->root
.sgotplt
->size
8203 - aarch64_compute_jump_table_size (htab
));
8204 htab
->root
.sgotplt
->size
+= GOT_ENTRY_SIZE
* 2;
8205 locals
[i
].got_offset
= (bfd_vma
) - 2;
8208 if (got_type
& GOT_TLS_GD
)
8210 locals
[i
].got_offset
= htab
->root
.sgot
->size
;
8211 htab
->root
.sgot
->size
+= GOT_ENTRY_SIZE
* 2;
8214 if (got_type
& GOT_TLS_IE
8215 || got_type
& GOT_NORMAL
)
8217 locals
[i
].got_offset
= htab
->root
.sgot
->size
;
8218 htab
->root
.sgot
->size
+= GOT_ENTRY_SIZE
;
8221 if (got_type
== GOT_UNKNOWN
)
8225 if (bfd_link_pic (info
))
8227 if (got_type
& GOT_TLSDESC_GD
)
8229 htab
->root
.srelplt
->size
+= RELOC_SIZE (htab
);
8230 /* Note RELOC_COUNT not incremented here! */
8231 htab
->tlsdesc_plt
= (bfd_vma
) - 1;
8234 if (got_type
& GOT_TLS_GD
)
8235 htab
->root
.srelgot
->size
+= RELOC_SIZE (htab
) * 2;
8237 if (got_type
& GOT_TLS_IE
8238 || got_type
& GOT_NORMAL
)
8239 htab
->root
.srelgot
->size
+= RELOC_SIZE (htab
);
8244 locals
[i
].got_refcount
= (bfd_vma
) - 1;
8250 /* Allocate global sym .plt and .got entries, and space for global
8251 sym dynamic relocs. */
8252 elf_link_hash_traverse (&htab
->root
, elfNN_aarch64_allocate_dynrelocs
,
8255 /* Allocate global ifunc sym .plt and .got entries, and space for global
8256 ifunc sym dynamic relocs. */
8257 elf_link_hash_traverse (&htab
->root
, elfNN_aarch64_allocate_ifunc_dynrelocs
,
8260 /* Allocate .plt and .got entries, and space for local symbols. */
8261 htab_traverse (htab
->loc_hash_table
,
8262 elfNN_aarch64_allocate_local_dynrelocs
,
8265 /* Allocate .plt and .got entries, and space for local ifunc symbols. */
8266 htab_traverse (htab
->loc_hash_table
,
8267 elfNN_aarch64_allocate_local_ifunc_dynrelocs
,
8270 /* For every jump slot reserved in the sgotplt, reloc_count is
8271 incremented. However, when we reserve space for TLS descriptors,
8272 it's not incremented, so in order to compute the space reserved
8273 for them, it suffices to multiply the reloc count by the jump
8276 if (htab
->root
.srelplt
)
8277 htab
->sgotplt_jump_table_size
= aarch64_compute_jump_table_size (htab
);
8279 if (htab
->tlsdesc_plt
)
8281 if (htab
->root
.splt
->size
== 0)
8282 htab
->root
.splt
->size
+= PLT_ENTRY_SIZE
;
8284 htab
->tlsdesc_plt
= htab
->root
.splt
->size
;
8285 htab
->root
.splt
->size
+= PLT_TLSDESC_ENTRY_SIZE
;
8287 /* If we're not using lazy TLS relocations, don't generate the
8288 GOT entry required. */
8289 if (!(info
->flags
& DF_BIND_NOW
))
8291 htab
->dt_tlsdesc_got
= htab
->root
.sgot
->size
;
8292 htab
->root
.sgot
->size
+= GOT_ENTRY_SIZE
;
8296 /* Init mapping symbols information to use later to distingush between
8297 code and data while scanning for errata. */
8298 if (htab
->fix_erratum_835769
|| htab
->fix_erratum_843419
)
8299 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
8301 if (!is_aarch64_elf (ibfd
))
8303 bfd_elfNN_aarch64_init_maps (ibfd
);
8306 /* We now have determined the sizes of the various dynamic sections.
8307 Allocate memory for them. */
8309 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
8311 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
8314 if (s
== htab
->root
.splt
8315 || s
== htab
->root
.sgot
8316 || s
== htab
->root
.sgotplt
8317 || s
== htab
->root
.iplt
8318 || s
== htab
->root
.igotplt
|| s
== htab
->sdynbss
)
8320 /* Strip this section if we don't need it; see the
8323 else if (CONST_STRNEQ (bfd_get_section_name (dynobj
, s
), ".rela"))
8325 if (s
->size
!= 0 && s
!= htab
->root
.srelplt
)
8328 /* We use the reloc_count field as a counter if we need
8329 to copy relocs into the output file. */
8330 if (s
!= htab
->root
.srelplt
)
8335 /* It's not one of our sections, so don't allocate space. */
8341 /* If we don't need this section, strip it from the
8342 output file. This is mostly to handle .rela.bss and
8343 .rela.plt. We must create both sections in
8344 create_dynamic_sections, because they must be created
8345 before the linker maps input sections to output
8346 sections. The linker does that before
8347 adjust_dynamic_symbol is called, and it is that
8348 function which decides whether anything needs to go
8349 into these sections. */
8351 s
->flags
|= SEC_EXCLUDE
;
8355 if ((s
->flags
& SEC_HAS_CONTENTS
) == 0)
8358 /* Allocate memory for the section contents. We use bfd_zalloc
8359 here in case unused entries are not reclaimed before the
8360 section's contents are written out. This should not happen,
8361 but this way if it does, we get a R_AARCH64_NONE reloc instead
8363 s
->contents
= (bfd_byte
*) bfd_zalloc (dynobj
, s
->size
);
8364 if (s
->contents
== NULL
)
8368 if (htab
->root
.dynamic_sections_created
)
8370 /* Add some entries to the .dynamic section. We fill in the
8371 values later, in elfNN_aarch64_finish_dynamic_sections, but we
8372 must add the entries now so that we get the correct size for
8373 the .dynamic section. The DT_DEBUG entry is filled in by the
8374 dynamic linker and used by the debugger. */
8375 #define add_dynamic_entry(TAG, VAL) \
8376 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
8378 if (bfd_link_executable (info
))
8380 if (!add_dynamic_entry (DT_DEBUG
, 0))
8384 if (htab
->root
.splt
->size
!= 0)
8386 if (!add_dynamic_entry (DT_PLTGOT
, 0)
8387 || !add_dynamic_entry (DT_PLTRELSZ
, 0)
8388 || !add_dynamic_entry (DT_PLTREL
, DT_RELA
)
8389 || !add_dynamic_entry (DT_JMPREL
, 0))
8392 if (htab
->tlsdesc_plt
8393 && (!add_dynamic_entry (DT_TLSDESC_PLT
, 0)
8394 || !add_dynamic_entry (DT_TLSDESC_GOT
, 0)))
8400 if (!add_dynamic_entry (DT_RELA
, 0)
8401 || !add_dynamic_entry (DT_RELASZ
, 0)
8402 || !add_dynamic_entry (DT_RELAENT
, RELOC_SIZE (htab
)))
8405 /* If any dynamic relocs apply to a read-only section,
8406 then we need a DT_TEXTREL entry. */
8407 if ((info
->flags
& DF_TEXTREL
) == 0)
8408 elf_link_hash_traverse (& htab
->root
, aarch64_readonly_dynrelocs
,
8411 if ((info
->flags
& DF_TEXTREL
) != 0)
8413 if (!add_dynamic_entry (DT_TEXTREL
, 0))
8418 #undef add_dynamic_entry
8424 elf_aarch64_update_plt_entry (bfd
*output_bfd
,
8425 bfd_reloc_code_real_type r_type
,
8426 bfd_byte
*plt_entry
, bfd_vma value
)
8428 reloc_howto_type
*howto
= elfNN_aarch64_howto_from_bfd_reloc (r_type
);
8430 _bfd_aarch64_elf_put_addend (output_bfd
, plt_entry
, r_type
, howto
, value
);
8434 elfNN_aarch64_create_small_pltn_entry (struct elf_link_hash_entry
*h
,
8435 struct elf_aarch64_link_hash_table
8436 *htab
, bfd
*output_bfd
,
8437 struct bfd_link_info
*info
)
8439 bfd_byte
*plt_entry
;
8442 bfd_vma gotplt_entry_address
;
8443 bfd_vma plt_entry_address
;
8444 Elf_Internal_Rela rela
;
8446 asection
*plt
, *gotplt
, *relplt
;
8448 /* When building a static executable, use .iplt, .igot.plt and
8449 .rela.iplt sections for STT_GNU_IFUNC symbols. */
8450 if (htab
->root
.splt
!= NULL
)
8452 plt
= htab
->root
.splt
;
8453 gotplt
= htab
->root
.sgotplt
;
8454 relplt
= htab
->root
.srelplt
;
8458 plt
= htab
->root
.iplt
;
8459 gotplt
= htab
->root
.igotplt
;
8460 relplt
= htab
->root
.irelplt
;
8463 /* Get the index in the procedure linkage table which
8464 corresponds to this symbol. This is the index of this symbol
8465 in all the symbols for which we are making plt entries. The
8466 first entry in the procedure linkage table is reserved.
8468 Get the offset into the .got table of the entry that
8469 corresponds to this function. Each .got entry is GOT_ENTRY_SIZE
8470 bytes. The first three are reserved for the dynamic linker.
8472 For static executables, we don't reserve anything. */
8474 if (plt
== htab
->root
.splt
)
8476 plt_index
= (h
->plt
.offset
- htab
->plt_header_size
) / htab
->plt_entry_size
;
8477 got_offset
= (plt_index
+ 3) * GOT_ENTRY_SIZE
;
8481 plt_index
= h
->plt
.offset
/ htab
->plt_entry_size
;
8482 got_offset
= plt_index
* GOT_ENTRY_SIZE
;
8485 plt_entry
= plt
->contents
+ h
->plt
.offset
;
8486 plt_entry_address
= plt
->output_section
->vma
8487 + plt
->output_offset
+ h
->plt
.offset
;
8488 gotplt_entry_address
= gotplt
->output_section
->vma
+
8489 gotplt
->output_offset
+ got_offset
;
8491 /* Copy in the boiler-plate for the PLTn entry. */
8492 memcpy (plt_entry
, elfNN_aarch64_small_plt_entry
, PLT_SMALL_ENTRY_SIZE
);
8494 /* Fill in the top 21 bits for this: ADRP x16, PLT_GOT + n * 8.
8495 ADRP: ((PG(S+A)-PG(P)) >> 12) & 0x1fffff */
8496 elf_aarch64_update_plt_entry (output_bfd
, BFD_RELOC_AARCH64_ADR_HI21_PCREL
,
8498 PG (gotplt_entry_address
) -
8499 PG (plt_entry_address
));
8501 /* Fill in the lo12 bits for the load from the pltgot. */
8502 elf_aarch64_update_plt_entry (output_bfd
, BFD_RELOC_AARCH64_LDSTNN_LO12
,
8504 PG_OFFSET (gotplt_entry_address
));
8506 /* Fill in the lo12 bits for the add from the pltgot entry. */
8507 elf_aarch64_update_plt_entry (output_bfd
, BFD_RELOC_AARCH64_ADD_LO12
,
8509 PG_OFFSET (gotplt_entry_address
));
8511 /* All the GOTPLT Entries are essentially initialized to PLT0. */
8512 bfd_put_NN (output_bfd
,
8513 plt
->output_section
->vma
+ plt
->output_offset
,
8514 gotplt
->contents
+ got_offset
);
8516 rela
.r_offset
= gotplt_entry_address
;
8518 if (h
->dynindx
== -1
8519 || ((bfd_link_executable (info
)
8520 || ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
)
8522 && h
->type
== STT_GNU_IFUNC
))
8524 /* If an STT_GNU_IFUNC symbol is locally defined, generate
8525 R_AARCH64_IRELATIVE instead of R_AARCH64_JUMP_SLOT. */
8526 rela
.r_info
= ELFNN_R_INFO (0, AARCH64_R (IRELATIVE
));
8527 rela
.r_addend
= (h
->root
.u
.def
.value
8528 + h
->root
.u
.def
.section
->output_section
->vma
8529 + h
->root
.u
.def
.section
->output_offset
);
8533 /* Fill in the entry in the .rela.plt section. */
8534 rela
.r_info
= ELFNN_R_INFO (h
->dynindx
, AARCH64_R (JUMP_SLOT
));
8538 /* Compute the relocation entry to used based on PLT index and do
8539 not adjust reloc_count. The reloc_count has already been adjusted
8540 to account for this entry. */
8541 loc
= relplt
->contents
+ plt_index
* RELOC_SIZE (htab
);
8542 bfd_elfNN_swap_reloca_out (output_bfd
, &rela
, loc
);
8545 /* Size sections even though they're not dynamic. We use it to setup
8546 _TLS_MODULE_BASE_, if needed. */
8549 elfNN_aarch64_always_size_sections (bfd
*output_bfd
,
8550 struct bfd_link_info
*info
)
8554 if (bfd_link_relocatable (info
))
8557 tls_sec
= elf_hash_table (info
)->tls_sec
;
8561 struct elf_link_hash_entry
*tlsbase
;
8563 tlsbase
= elf_link_hash_lookup (elf_hash_table (info
),
8564 "_TLS_MODULE_BASE_", TRUE
, TRUE
, FALSE
);
8568 struct bfd_link_hash_entry
*h
= NULL
;
8569 const struct elf_backend_data
*bed
=
8570 get_elf_backend_data (output_bfd
);
8572 if (!(_bfd_generic_link_add_one_symbol
8573 (info
, output_bfd
, "_TLS_MODULE_BASE_", BSF_LOCAL
,
8574 tls_sec
, 0, NULL
, FALSE
, bed
->collect
, &h
)))
8577 tlsbase
->type
= STT_TLS
;
8578 tlsbase
= (struct elf_link_hash_entry
*) h
;
8579 tlsbase
->def_regular
= 1;
8580 tlsbase
->other
= STV_HIDDEN
;
8581 (*bed
->elf_backend_hide_symbol
) (info
, tlsbase
, TRUE
);
8588 /* Finish up dynamic symbol handling. We set the contents of various
8589 dynamic sections here. */
8591 elfNN_aarch64_finish_dynamic_symbol (bfd
*output_bfd
,
8592 struct bfd_link_info
*info
,
8593 struct elf_link_hash_entry
*h
,
8594 Elf_Internal_Sym
*sym
)
8596 struct elf_aarch64_link_hash_table
*htab
;
8597 htab
= elf_aarch64_hash_table (info
);
8599 if (h
->plt
.offset
!= (bfd_vma
) - 1)
8601 asection
*plt
, *gotplt
, *relplt
;
8603 /* This symbol has an entry in the procedure linkage table. Set
8606 /* When building a static executable, use .iplt, .igot.plt and
8607 .rela.iplt sections for STT_GNU_IFUNC symbols. */
8608 if (htab
->root
.splt
!= NULL
)
8610 plt
= htab
->root
.splt
;
8611 gotplt
= htab
->root
.sgotplt
;
8612 relplt
= htab
->root
.srelplt
;
8616 plt
= htab
->root
.iplt
;
8617 gotplt
= htab
->root
.igotplt
;
8618 relplt
= htab
->root
.irelplt
;
8621 /* This symbol has an entry in the procedure linkage table. Set
8623 if ((h
->dynindx
== -1
8624 && !((h
->forced_local
|| bfd_link_executable (info
))
8626 && h
->type
== STT_GNU_IFUNC
))
8632 elfNN_aarch64_create_small_pltn_entry (h
, htab
, output_bfd
, info
);
8633 if (!h
->def_regular
)
8635 /* Mark the symbol as undefined, rather than as defined in
8636 the .plt section. */
8637 sym
->st_shndx
= SHN_UNDEF
;
8638 /* If the symbol is weak we need to clear the value.
8639 Otherwise, the PLT entry would provide a definition for
8640 the symbol even if the symbol wasn't defined anywhere,
8641 and so the symbol would never be NULL. Leave the value if
8642 there were any relocations where pointer equality matters
8643 (this is a clue for the dynamic linker, to make function
8644 pointer comparisons work between an application and shared
8646 if (!h
->ref_regular_nonweak
|| !h
->pointer_equality_needed
)
8651 if (h
->got
.offset
!= (bfd_vma
) - 1
8652 && elf_aarch64_hash_entry (h
)->got_type
== GOT_NORMAL
)
8654 Elf_Internal_Rela rela
;
8657 /* This symbol has an entry in the global offset table. Set it
8659 if (htab
->root
.sgot
== NULL
|| htab
->root
.srelgot
== NULL
)
8662 rela
.r_offset
= (htab
->root
.sgot
->output_section
->vma
8663 + htab
->root
.sgot
->output_offset
8664 + (h
->got
.offset
& ~(bfd_vma
) 1));
8667 && h
->type
== STT_GNU_IFUNC
)
8669 if (bfd_link_pic (info
))
8671 /* Generate R_AARCH64_GLOB_DAT. */
8678 if (!h
->pointer_equality_needed
)
8681 /* For non-shared object, we can't use .got.plt, which
8682 contains the real function address if we need pointer
8683 equality. We load the GOT entry with the PLT entry. */
8684 plt
= htab
->root
.splt
? htab
->root
.splt
: htab
->root
.iplt
;
8685 bfd_put_NN (output_bfd
, (plt
->output_section
->vma
8686 + plt
->output_offset
8688 htab
->root
.sgot
->contents
8689 + (h
->got
.offset
& ~(bfd_vma
) 1));
8693 else if (bfd_link_pic (info
) && SYMBOL_REFERENCES_LOCAL (info
, h
))
8695 if (!h
->def_regular
)
8698 BFD_ASSERT ((h
->got
.offset
& 1) != 0);
8699 rela
.r_info
= ELFNN_R_INFO (0, AARCH64_R (RELATIVE
));
8700 rela
.r_addend
= (h
->root
.u
.def
.value
8701 + h
->root
.u
.def
.section
->output_section
->vma
8702 + h
->root
.u
.def
.section
->output_offset
);
8707 BFD_ASSERT ((h
->got
.offset
& 1) == 0);
8708 bfd_put_NN (output_bfd
, (bfd_vma
) 0,
8709 htab
->root
.sgot
->contents
+ h
->got
.offset
);
8710 rela
.r_info
= ELFNN_R_INFO (h
->dynindx
, AARCH64_R (GLOB_DAT
));
8714 loc
= htab
->root
.srelgot
->contents
;
8715 loc
+= htab
->root
.srelgot
->reloc_count
++ * RELOC_SIZE (htab
);
8716 bfd_elfNN_swap_reloca_out (output_bfd
, &rela
, loc
);
8721 Elf_Internal_Rela rela
;
8724 /* This symbol needs a copy reloc. Set it up. */
8726 if (h
->dynindx
== -1
8727 || (h
->root
.type
!= bfd_link_hash_defined
8728 && h
->root
.type
!= bfd_link_hash_defweak
)
8729 || htab
->srelbss
== NULL
)
8732 rela
.r_offset
= (h
->root
.u
.def
.value
8733 + h
->root
.u
.def
.section
->output_section
->vma
8734 + h
->root
.u
.def
.section
->output_offset
);
8735 rela
.r_info
= ELFNN_R_INFO (h
->dynindx
, AARCH64_R (COPY
));
8737 loc
= htab
->srelbss
->contents
;
8738 loc
+= htab
->srelbss
->reloc_count
++ * RELOC_SIZE (htab
);
8739 bfd_elfNN_swap_reloca_out (output_bfd
, &rela
, loc
);
8742 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. SYM may
8743 be NULL for local symbols. */
8745 && (h
== elf_hash_table (info
)->hdynamic
8746 || h
== elf_hash_table (info
)->hgot
))
8747 sym
->st_shndx
= SHN_ABS
;
8752 /* Finish up local dynamic symbol handling. We set the contents of
8753 various dynamic sections here. */
8756 elfNN_aarch64_finish_local_dynamic_symbol (void **slot
, void *inf
)
8758 struct elf_link_hash_entry
*h
8759 = (struct elf_link_hash_entry
*) *slot
;
8760 struct bfd_link_info
*info
8761 = (struct bfd_link_info
*) inf
;
8763 return elfNN_aarch64_finish_dynamic_symbol (info
->output_bfd
,
8768 elfNN_aarch64_init_small_plt0_entry (bfd
*output_bfd ATTRIBUTE_UNUSED
,
8769 struct elf_aarch64_link_hash_table
8772 /* Fill in PLT0. Fixme:RR Note this doesn't distinguish between
8773 small and large plts and at the minute just generates
8776 /* PLT0 of the small PLT looks like this in ELF64 -
8777 stp x16, x30, [sp, #-16]! // Save the reloc and lr on stack.
8778 adrp x16, PLT_GOT + 16 // Get the page base of the GOTPLT
8779 ldr x17, [x16, #:lo12:PLT_GOT+16] // Load the address of the
8781 add x16, x16, #:lo12:PLT_GOT+16 // Load the lo12 bits of the
8782 // GOTPLT entry for this.
8784 PLT0 will be slightly different in ELF32 due to different got entry
8787 bfd_vma plt_got_2nd_ent
; /* Address of GOT[2]. */
8791 memcpy (htab
->root
.splt
->contents
, elfNN_aarch64_small_plt0_entry
,
8793 elf_section_data (htab
->root
.splt
->output_section
)->this_hdr
.sh_entsize
=
8796 plt_got_2nd_ent
= (htab
->root
.sgotplt
->output_section
->vma
8797 + htab
->root
.sgotplt
->output_offset
8798 + GOT_ENTRY_SIZE
* 2);
8800 plt_base
= htab
->root
.splt
->output_section
->vma
+
8801 htab
->root
.splt
->output_offset
;
8803 /* Fill in the top 21 bits for this: ADRP x16, PLT_GOT + n * 8.
8804 ADRP: ((PG(S+A)-PG(P)) >> 12) & 0x1fffff */
8805 elf_aarch64_update_plt_entry (output_bfd
, BFD_RELOC_AARCH64_ADR_HI21_PCREL
,
8806 htab
->root
.splt
->contents
+ 4,
8807 PG (plt_got_2nd_ent
) - PG (plt_base
+ 4));
8809 elf_aarch64_update_plt_entry (output_bfd
, BFD_RELOC_AARCH64_LDSTNN_LO12
,
8810 htab
->root
.splt
->contents
+ 8,
8811 PG_OFFSET (plt_got_2nd_ent
));
8813 elf_aarch64_update_plt_entry (output_bfd
, BFD_RELOC_AARCH64_ADD_LO12
,
8814 htab
->root
.splt
->contents
+ 12,
8815 PG_OFFSET (plt_got_2nd_ent
));
8819 elfNN_aarch64_finish_dynamic_sections (bfd
*output_bfd
,
8820 struct bfd_link_info
*info
)
8822 struct elf_aarch64_link_hash_table
*htab
;
8826 htab
= elf_aarch64_hash_table (info
);
8827 dynobj
= htab
->root
.dynobj
;
8828 sdyn
= bfd_get_linker_section (dynobj
, ".dynamic");
8830 if (htab
->root
.dynamic_sections_created
)
8832 ElfNN_External_Dyn
*dyncon
, *dynconend
;
8834 if (sdyn
== NULL
|| htab
->root
.sgot
== NULL
)
8837 dyncon
= (ElfNN_External_Dyn
*) sdyn
->contents
;
8838 dynconend
= (ElfNN_External_Dyn
*) (sdyn
->contents
+ sdyn
->size
);
8839 for (; dyncon
< dynconend
; dyncon
++)
8841 Elf_Internal_Dyn dyn
;
8844 bfd_elfNN_swap_dyn_in (dynobj
, dyncon
, &dyn
);
8852 s
= htab
->root
.sgotplt
;
8853 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
8857 dyn
.d_un
.d_ptr
= htab
->root
.srelplt
->output_section
->vma
;
8861 s
= htab
->root
.srelplt
;
8862 dyn
.d_un
.d_val
= s
->size
;
8866 /* The procedure linkage table relocs (DT_JMPREL) should
8867 not be included in the overall relocs (DT_RELA).
8868 Therefore, we override the DT_RELASZ entry here to
8869 make it not include the JMPREL relocs. Since the
8870 linker script arranges for .rela.plt to follow all
8871 other relocation sections, we don't have to worry
8872 about changing the DT_RELA entry. */
8873 if (htab
->root
.srelplt
!= NULL
)
8875 s
= htab
->root
.srelplt
;
8876 dyn
.d_un
.d_val
-= s
->size
;
8880 case DT_TLSDESC_PLT
:
8881 s
= htab
->root
.splt
;
8882 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
8883 + htab
->tlsdesc_plt
;
8886 case DT_TLSDESC_GOT
:
8887 s
= htab
->root
.sgot
;
8888 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
8889 + htab
->dt_tlsdesc_got
;
8893 bfd_elfNN_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
8898 /* Fill in the special first entry in the procedure linkage table. */
8899 if (htab
->root
.splt
&& htab
->root
.splt
->size
> 0)
8901 elfNN_aarch64_init_small_plt0_entry (output_bfd
, htab
);
8903 elf_section_data (htab
->root
.splt
->output_section
)->
8904 this_hdr
.sh_entsize
= htab
->plt_entry_size
;
8907 if (htab
->tlsdesc_plt
)
8909 bfd_put_NN (output_bfd
, (bfd_vma
) 0,
8910 htab
->root
.sgot
->contents
+ htab
->dt_tlsdesc_got
);
8912 memcpy (htab
->root
.splt
->contents
+ htab
->tlsdesc_plt
,
8913 elfNN_aarch64_tlsdesc_small_plt_entry
,
8914 sizeof (elfNN_aarch64_tlsdesc_small_plt_entry
));
8917 bfd_vma adrp1_addr
=
8918 htab
->root
.splt
->output_section
->vma
8919 + htab
->root
.splt
->output_offset
+ htab
->tlsdesc_plt
+ 4;
8921 bfd_vma adrp2_addr
= adrp1_addr
+ 4;
8924 htab
->root
.sgot
->output_section
->vma
8925 + htab
->root
.sgot
->output_offset
;
8927 bfd_vma pltgot_addr
=
8928 htab
->root
.sgotplt
->output_section
->vma
8929 + htab
->root
.sgotplt
->output_offset
;
8931 bfd_vma dt_tlsdesc_got
= got_addr
+ htab
->dt_tlsdesc_got
;
8933 bfd_byte
*plt_entry
=
8934 htab
->root
.splt
->contents
+ htab
->tlsdesc_plt
;
8936 /* adrp x2, DT_TLSDESC_GOT */
8937 elf_aarch64_update_plt_entry (output_bfd
,
8938 BFD_RELOC_AARCH64_ADR_HI21_PCREL
,
8940 (PG (dt_tlsdesc_got
)
8941 - PG (adrp1_addr
)));
8944 elf_aarch64_update_plt_entry (output_bfd
,
8945 BFD_RELOC_AARCH64_ADR_HI21_PCREL
,
8948 - PG (adrp2_addr
)));
8950 /* ldr x2, [x2, #0] */
8951 elf_aarch64_update_plt_entry (output_bfd
,
8952 BFD_RELOC_AARCH64_LDSTNN_LO12
,
8954 PG_OFFSET (dt_tlsdesc_got
));
8957 elf_aarch64_update_plt_entry (output_bfd
,
8958 BFD_RELOC_AARCH64_ADD_LO12
,
8960 PG_OFFSET (pltgot_addr
));
8965 if (htab
->root
.sgotplt
)
8967 if (bfd_is_abs_section (htab
->root
.sgotplt
->output_section
))
8969 (*_bfd_error_handler
)
8970 (_("discarded output section: `%A'"), htab
->root
.sgotplt
);
8974 /* Fill in the first three entries in the global offset table. */
8975 if (htab
->root
.sgotplt
->size
> 0)
8977 bfd_put_NN (output_bfd
, (bfd_vma
) 0, htab
->root
.sgotplt
->contents
);
8979 /* Write GOT[1] and GOT[2], needed for the dynamic linker. */
8980 bfd_put_NN (output_bfd
,
8982 htab
->root
.sgotplt
->contents
+ GOT_ENTRY_SIZE
);
8983 bfd_put_NN (output_bfd
,
8985 htab
->root
.sgotplt
->contents
+ GOT_ENTRY_SIZE
* 2);
8988 if (htab
->root
.sgot
)
8990 if (htab
->root
.sgot
->size
> 0)
8993 sdyn
? sdyn
->output_section
->vma
+ sdyn
->output_offset
: 0;
8994 bfd_put_NN (output_bfd
, addr
, htab
->root
.sgot
->contents
);
8998 elf_section_data (htab
->root
.sgotplt
->output_section
)->
8999 this_hdr
.sh_entsize
= GOT_ENTRY_SIZE
;
9002 if (htab
->root
.sgot
&& htab
->root
.sgot
->size
> 0)
9003 elf_section_data (htab
->root
.sgot
->output_section
)->this_hdr
.sh_entsize
9006 /* Fill PLT and GOT entries for local STT_GNU_IFUNC symbols. */
9007 htab_traverse (htab
->loc_hash_table
,
9008 elfNN_aarch64_finish_local_dynamic_symbol
,
9014 /* Return address for Ith PLT stub in section PLT, for relocation REL
9015 or (bfd_vma) -1 if it should not be included. */
9018 elfNN_aarch64_plt_sym_val (bfd_vma i
, const asection
*plt
,
9019 const arelent
*rel ATTRIBUTE_UNUSED
)
9021 return plt
->vma
+ PLT_ENTRY_SIZE
+ i
* PLT_SMALL_ENTRY_SIZE
;
9025 /* We use this so we can override certain functions
9026 (though currently we don't). */
9028 const struct elf_size_info elfNN_aarch64_size_info
=
9030 sizeof (ElfNN_External_Ehdr
),
9031 sizeof (ElfNN_External_Phdr
),
9032 sizeof (ElfNN_External_Shdr
),
9033 sizeof (ElfNN_External_Rel
),
9034 sizeof (ElfNN_External_Rela
),
9035 sizeof (ElfNN_External_Sym
),
9036 sizeof (ElfNN_External_Dyn
),
9037 sizeof (Elf_External_Note
),
9038 4, /* Hash table entry size. */
9039 1, /* Internal relocs per external relocs. */
9040 ARCH_SIZE
, /* Arch size. */
9041 LOG_FILE_ALIGN
, /* Log_file_align. */
9042 ELFCLASSNN
, EV_CURRENT
,
9043 bfd_elfNN_write_out_phdrs
,
9044 bfd_elfNN_write_shdrs_and_ehdr
,
9045 bfd_elfNN_checksum_contents
,
9046 bfd_elfNN_write_relocs
,
9047 bfd_elfNN_swap_symbol_in
,
9048 bfd_elfNN_swap_symbol_out
,
9049 bfd_elfNN_slurp_reloc_table
,
9050 bfd_elfNN_slurp_symbol_table
,
9051 bfd_elfNN_swap_dyn_in
,
9052 bfd_elfNN_swap_dyn_out
,
9053 bfd_elfNN_swap_reloc_in
,
9054 bfd_elfNN_swap_reloc_out
,
9055 bfd_elfNN_swap_reloca_in
,
9056 bfd_elfNN_swap_reloca_out
9059 #define ELF_ARCH bfd_arch_aarch64
9060 #define ELF_MACHINE_CODE EM_AARCH64
9061 #define ELF_MAXPAGESIZE 0x10000
9062 #define ELF_MINPAGESIZE 0x1000
9063 #define ELF_COMMONPAGESIZE 0x1000
9065 #define bfd_elfNN_close_and_cleanup \
9066 elfNN_aarch64_close_and_cleanup
9068 #define bfd_elfNN_bfd_free_cached_info \
9069 elfNN_aarch64_bfd_free_cached_info
9071 #define bfd_elfNN_bfd_is_target_special_symbol \
9072 elfNN_aarch64_is_target_special_symbol
9074 #define bfd_elfNN_bfd_link_hash_table_create \
9075 elfNN_aarch64_link_hash_table_create
9077 #define bfd_elfNN_bfd_merge_private_bfd_data \
9078 elfNN_aarch64_merge_private_bfd_data
9080 #define bfd_elfNN_bfd_print_private_bfd_data \
9081 elfNN_aarch64_print_private_bfd_data
9083 #define bfd_elfNN_bfd_reloc_type_lookup \
9084 elfNN_aarch64_reloc_type_lookup
9086 #define bfd_elfNN_bfd_reloc_name_lookup \
9087 elfNN_aarch64_reloc_name_lookup
9089 #define bfd_elfNN_bfd_set_private_flags \
9090 elfNN_aarch64_set_private_flags
9092 #define bfd_elfNN_find_inliner_info \
9093 elfNN_aarch64_find_inliner_info
9095 #define bfd_elfNN_find_nearest_line \
9096 elfNN_aarch64_find_nearest_line
9098 #define bfd_elfNN_mkobject \
9099 elfNN_aarch64_mkobject
9101 #define bfd_elfNN_new_section_hook \
9102 elfNN_aarch64_new_section_hook
9104 #define elf_backend_adjust_dynamic_symbol \
9105 elfNN_aarch64_adjust_dynamic_symbol
9107 #define elf_backend_always_size_sections \
9108 elfNN_aarch64_always_size_sections
9110 #define elf_backend_check_relocs \
9111 elfNN_aarch64_check_relocs
9113 #define elf_backend_copy_indirect_symbol \
9114 elfNN_aarch64_copy_indirect_symbol
9116 /* Create .dynbss, and .rela.bss sections in DYNOBJ, and set up shortcuts
9117 to them in our hash. */
9118 #define elf_backend_create_dynamic_sections \
9119 elfNN_aarch64_create_dynamic_sections
9121 #define elf_backend_init_index_section \
9122 _bfd_elf_init_2_index_sections
9124 #define elf_backend_finish_dynamic_sections \
9125 elfNN_aarch64_finish_dynamic_sections
9127 #define elf_backend_finish_dynamic_symbol \
9128 elfNN_aarch64_finish_dynamic_symbol
9130 #define elf_backend_gc_sweep_hook \
9131 elfNN_aarch64_gc_sweep_hook
9133 #define elf_backend_object_p \
9134 elfNN_aarch64_object_p
9136 #define elf_backend_output_arch_local_syms \
9137 elfNN_aarch64_output_arch_local_syms
9139 #define elf_backend_plt_sym_val \
9140 elfNN_aarch64_plt_sym_val
9142 #define elf_backend_post_process_headers \
9143 elfNN_aarch64_post_process_headers
9145 #define elf_backend_relocate_section \
9146 elfNN_aarch64_relocate_section
9148 #define elf_backend_reloc_type_class \
9149 elfNN_aarch64_reloc_type_class
9151 #define elf_backend_section_from_shdr \
9152 elfNN_aarch64_section_from_shdr
9154 #define elf_backend_size_dynamic_sections \
9155 elfNN_aarch64_size_dynamic_sections
9157 #define elf_backend_size_info \
9158 elfNN_aarch64_size_info
9160 #define elf_backend_write_section \
9161 elfNN_aarch64_write_section
9163 #define elf_backend_can_refcount 1
9164 #define elf_backend_can_gc_sections 1
9165 #define elf_backend_plt_readonly 1
9166 #define elf_backend_want_got_plt 1
9167 #define elf_backend_want_plt_sym 0
9168 #define elf_backend_may_use_rel_p 0
9169 #define elf_backend_may_use_rela_p 1
9170 #define elf_backend_default_use_rela_p 1
9171 #define elf_backend_rela_normal 1
9172 #define elf_backend_got_header_size (GOT_ENTRY_SIZE * 3)
9173 #define elf_backend_default_execstack 0
9174 #define elf_backend_extern_protected_data 1
9176 #undef elf_backend_obj_attrs_section
9177 #define elf_backend_obj_attrs_section ".ARM.attributes"
9179 #include "elfNN-target.h"