1 /* AArch64-specific support for NN-bit ELF.
2 Copyright (C) 2009-2019 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"
144 #include "objalloc.h"
145 #include "elf/aarch64.h"
146 #include "elfxx-aarch64.h"
151 #define AARCH64_R(NAME) R_AARCH64_ ## NAME
152 #define AARCH64_R_STR(NAME) "R_AARCH64_" #NAME
153 #define HOWTO64(...) HOWTO (__VA_ARGS__)
154 #define HOWTO32(...) EMPTY_HOWTO (0)
155 #define LOG_FILE_ALIGN 3
156 #define BFD_RELOC_AARCH64_TLSDESC_LD64_LO12_NC BFD_RELOC_AARCH64_TLSDESC_LD64_LO12
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
165 #define BFD_RELOC_AARCH64_TLSDESC_LD32_LO12 BFD_RELOC_AARCH64_TLSDESC_LD32_LO12_NC
166 #define R_AARCH64_P32_TLSDESC_ADD_LO12 R_AARCH64_P32_TLSDESC_ADD_LO12_NC
169 #define IS_AARCH64_TLS_RELOC(R_TYPE) \
170 ((R_TYPE) == BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC \
171 || (R_TYPE) == BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21 \
172 || (R_TYPE) == BFD_RELOC_AARCH64_TLSGD_ADR_PREL21 \
173 || (R_TYPE) == BFD_RELOC_AARCH64_TLSGD_MOVW_G0_NC \
174 || (R_TYPE) == BFD_RELOC_AARCH64_TLSGD_MOVW_G1 \
175 || (R_TYPE) == BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21 \
176 || (R_TYPE) == BFD_RELOC_AARCH64_TLSIE_LD32_GOTTPREL_LO12_NC \
177 || (R_TYPE) == BFD_RELOC_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC \
178 || (R_TYPE) == BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19 \
179 || (R_TYPE) == BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G0_NC \
180 || (R_TYPE) == BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G1 \
181 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_ADD_DTPREL_HI12 \
182 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_ADD_DTPREL_LO12 \
183 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_ADD_DTPREL_LO12_NC \
184 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC \
185 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21 \
186 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_ADR_PREL21 \
187 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_LDST16_DTPREL_LO12 \
188 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_LDST16_DTPREL_LO12_NC \
189 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_LDST32_DTPREL_LO12 \
190 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_LDST32_DTPREL_LO12_NC \
191 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_LDST64_DTPREL_LO12 \
192 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_LDST64_DTPREL_LO12_NC \
193 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_LDST8_DTPREL_LO12 \
194 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_LDST8_DTPREL_LO12_NC \
195 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G0 \
196 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G0_NC \
197 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G1 \
198 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G1_NC \
199 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G2 \
200 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_HI12 \
201 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_LO12 \
202 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_LO12_NC \
203 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_LDST16_TPREL_LO12 \
204 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_LDST16_TPREL_LO12_NC \
205 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_LDST32_TPREL_LO12 \
206 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_LDST32_TPREL_LO12_NC \
207 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_LDST64_TPREL_LO12 \
208 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_LDST64_TPREL_LO12_NC \
209 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_LDST8_TPREL_LO12 \
210 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_LDST8_TPREL_LO12_NC \
211 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0 \
212 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC \
213 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1 \
214 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1_NC \
215 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G2 \
216 || (R_TYPE) == BFD_RELOC_AARCH64_TLS_DTPMOD \
217 || (R_TYPE) == BFD_RELOC_AARCH64_TLS_DTPREL \
218 || (R_TYPE) == BFD_RELOC_AARCH64_TLS_TPREL \
219 || IS_AARCH64_TLSDESC_RELOC ((R_TYPE)))
221 #define IS_AARCH64_TLS_RELAX_RELOC(R_TYPE) \
222 ((R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_ADD \
223 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_ADD_LO12 \
224 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21 \
225 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21 \
226 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_CALL \
227 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_LD_PREL19 \
228 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_LDNN_LO12_NC \
229 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_LDR \
230 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_OFF_G0_NC \
231 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_OFF_G1 \
232 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_LDR \
233 || (R_TYPE) == BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21 \
234 || (R_TYPE) == BFD_RELOC_AARCH64_TLSGD_ADR_PREL21 \
235 || (R_TYPE) == BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC \
236 || (R_TYPE) == BFD_RELOC_AARCH64_TLSGD_MOVW_G0_NC \
237 || (R_TYPE) == BFD_RELOC_AARCH64_TLSGD_MOVW_G1 \
238 || (R_TYPE) == BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21 \
239 || (R_TYPE) == BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19 \
240 || (R_TYPE) == BFD_RELOC_AARCH64_TLSIE_LDNN_GOTTPREL_LO12_NC \
241 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC \
242 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21 \
243 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_ADR_PREL21)
245 #define IS_AARCH64_TLSDESC_RELOC(R_TYPE) \
246 ((R_TYPE) == BFD_RELOC_AARCH64_TLSDESC \
247 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_ADD \
248 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_ADD_LO12 \
249 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21 \
250 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21 \
251 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_CALL \
252 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_LD32_LO12_NC \
253 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_LD64_LO12 \
254 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_LDR \
255 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_LD_PREL19 \
256 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_OFF_G0_NC \
257 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_OFF_G1)
259 #define ELIMINATE_COPY_RELOCS 1
261 /* Return size of a relocation entry. HTAB is the bfd's
262 elf_aarch64_link_hash_entry. */
263 #define RELOC_SIZE(HTAB) (sizeof (ElfNN_External_Rela))
265 /* GOT Entry size - 8 bytes in ELF64 and 4 bytes in ELF32. */
266 #define GOT_ENTRY_SIZE (ARCH_SIZE / 8)
267 #define PLT_ENTRY_SIZE (32)
268 #define PLT_SMALL_ENTRY_SIZE (16)
269 #define PLT_TLSDESC_ENTRY_SIZE (32)
271 /* Encoding of the nop instruction. */
272 #define INSN_NOP 0xd503201f
274 #define aarch64_compute_jump_table_size(htab) \
275 (((htab)->root.srelplt == NULL) ? 0 \
276 : (htab)->root.srelplt->reloc_count * GOT_ENTRY_SIZE)
278 /* The first entry in a procedure linkage table looks like this
279 if the distance between the PLTGOT and the PLT is < 4GB use
280 these PLT entries. Note that the dynamic linker gets &PLTGOT[2]
281 in x16 and needs to work out PLTGOT[1] by using an address of
282 [x16,#-GOT_ENTRY_SIZE]. */
283 static const bfd_byte elfNN_aarch64_small_plt0_entry
[PLT_ENTRY_SIZE
] =
285 0xf0, 0x7b, 0xbf, 0xa9, /* stp x16, x30, [sp, #-16]! */
286 0x10, 0x00, 0x00, 0x90, /* adrp x16, (GOT+16) */
288 0x11, 0x0A, 0x40, 0xf9, /* ldr x17, [x16, #PLT_GOT+0x10] */
289 0x10, 0x42, 0x00, 0x91, /* add x16, x16,#PLT_GOT+0x10 */
291 0x11, 0x0A, 0x40, 0xb9, /* ldr w17, [x16, #PLT_GOT+0x8] */
292 0x10, 0x22, 0x00, 0x11, /* add w16, w16,#PLT_GOT+0x8 */
294 0x20, 0x02, 0x1f, 0xd6, /* br x17 */
295 0x1f, 0x20, 0x03, 0xd5, /* nop */
296 0x1f, 0x20, 0x03, 0xd5, /* nop */
297 0x1f, 0x20, 0x03, 0xd5, /* nop */
300 /* Per function entry in a procedure linkage table looks like this
301 if the distance between the PLTGOT and the PLT is < 4GB use
302 these PLT entries. */
303 static const bfd_byte elfNN_aarch64_small_plt_entry
[PLT_SMALL_ENTRY_SIZE
] =
305 0x10, 0x00, 0x00, 0x90, /* adrp x16, PLTGOT + n * 8 */
307 0x11, 0x02, 0x40, 0xf9, /* ldr x17, [x16, PLTGOT + n * 8] */
308 0x10, 0x02, 0x00, 0x91, /* add x16, x16, :lo12:PLTGOT + n * 8 */
310 0x11, 0x02, 0x40, 0xb9, /* ldr w17, [x16, PLTGOT + n * 4] */
311 0x10, 0x02, 0x00, 0x11, /* add w16, w16, :lo12:PLTGOT + n * 4 */
313 0x20, 0x02, 0x1f, 0xd6, /* br x17. */
316 static const bfd_byte
317 elfNN_aarch64_tlsdesc_small_plt_entry
[PLT_TLSDESC_ENTRY_SIZE
] =
319 0xe2, 0x0f, 0xbf, 0xa9, /* stp x2, x3, [sp, #-16]! */
320 0x02, 0x00, 0x00, 0x90, /* adrp x2, 0 */
321 0x03, 0x00, 0x00, 0x90, /* adrp x3, 0 */
323 0x42, 0x00, 0x40, 0xf9, /* ldr x2, [x2, #0] */
324 0x63, 0x00, 0x00, 0x91, /* add x3, x3, 0 */
326 0x42, 0x00, 0x40, 0xb9, /* ldr w2, [x2, #0] */
327 0x63, 0x00, 0x00, 0x11, /* add w3, w3, 0 */
329 0x40, 0x00, 0x1f, 0xd6, /* br x2 */
330 0x1f, 0x20, 0x03, 0xd5, /* nop */
331 0x1f, 0x20, 0x03, 0xd5, /* nop */
334 #define elf_info_to_howto elfNN_aarch64_info_to_howto
335 #define elf_info_to_howto_rel elfNN_aarch64_info_to_howto
337 #define AARCH64_ELF_ABI_VERSION 0
339 /* In case we're on a 32-bit machine, construct a 64-bit "-1" value. */
340 #define ALL_ONES (~ (bfd_vma) 0)
342 /* Indexed by the bfd interal reloc enumerators.
343 Therefore, the table needs to be synced with BFD_RELOC_AARCH64_*
346 static reloc_howto_type elfNN_aarch64_howto_table
[] =
350 /* Basic data relocations. */
352 /* Deprecated, but retained for backwards compatibility. */
353 HOWTO64 (R_AARCH64_NULL
, /* type */
355 3, /* size (0 = byte, 1 = short, 2 = long) */
357 FALSE
, /* pc_relative */
359 complain_overflow_dont
, /* complain_on_overflow */
360 bfd_elf_generic_reloc
, /* special_function */
361 "R_AARCH64_NULL", /* name */
362 FALSE
, /* partial_inplace */
365 FALSE
), /* pcrel_offset */
366 HOWTO (R_AARCH64_NONE
, /* type */
368 3, /* size (0 = byte, 1 = short, 2 = long) */
370 FALSE
, /* pc_relative */
372 complain_overflow_dont
, /* complain_on_overflow */
373 bfd_elf_generic_reloc
, /* special_function */
374 "R_AARCH64_NONE", /* name */
375 FALSE
, /* partial_inplace */
378 FALSE
), /* pcrel_offset */
381 HOWTO64 (AARCH64_R (ABS64
), /* type */
383 4, /* size (4 = long long) */
385 FALSE
, /* pc_relative */
387 complain_overflow_unsigned
, /* complain_on_overflow */
388 bfd_elf_generic_reloc
, /* special_function */
389 AARCH64_R_STR (ABS64
), /* name */
390 FALSE
, /* partial_inplace */
391 ALL_ONES
, /* src_mask */
392 ALL_ONES
, /* dst_mask */
393 FALSE
), /* pcrel_offset */
396 HOWTO (AARCH64_R (ABS32
), /* type */
398 2, /* 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 (ABS32
), /* name */
405 FALSE
, /* partial_inplace */
406 0xffffffff, /* src_mask */
407 0xffffffff, /* dst_mask */
408 FALSE
), /* pcrel_offset */
411 HOWTO (AARCH64_R (ABS16
), /* type */
413 1, /* size (0 = byte, 1 = short, 2 = long) */
415 FALSE
, /* pc_relative */
417 complain_overflow_unsigned
, /* complain_on_overflow */
418 bfd_elf_generic_reloc
, /* special_function */
419 AARCH64_R_STR (ABS16
), /* name */
420 FALSE
, /* partial_inplace */
421 0xffff, /* src_mask */
422 0xffff, /* dst_mask */
423 FALSE
), /* pcrel_offset */
425 /* .xword: (S+A-P) */
426 HOWTO64 (AARCH64_R (PREL64
), /* type */
428 4, /* size (4 = long long) */
430 TRUE
, /* pc_relative */
432 complain_overflow_signed
, /* complain_on_overflow */
433 bfd_elf_generic_reloc
, /* special_function */
434 AARCH64_R_STR (PREL64
), /* name */
435 FALSE
, /* partial_inplace */
436 ALL_ONES
, /* src_mask */
437 ALL_ONES
, /* dst_mask */
438 TRUE
), /* pcrel_offset */
441 HOWTO (AARCH64_R (PREL32
), /* type */
443 2, /* 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 (PREL32
), /* name */
450 FALSE
, /* partial_inplace */
451 0xffffffff, /* src_mask */
452 0xffffffff, /* dst_mask */
453 TRUE
), /* pcrel_offset */
456 HOWTO (AARCH64_R (PREL16
), /* type */
458 1, /* size (0 = byte, 1 = short, 2 = long) */
460 TRUE
, /* pc_relative */
462 complain_overflow_signed
, /* complain_on_overflow */
463 bfd_elf_generic_reloc
, /* special_function */
464 AARCH64_R_STR (PREL16
), /* name */
465 FALSE
, /* partial_inplace */
466 0xffff, /* src_mask */
467 0xffff, /* dst_mask */
468 TRUE
), /* pcrel_offset */
470 /* Group relocations to create a 16, 32, 48 or 64 bit
471 unsigned data or abs address inline. */
473 /* MOVZ: ((S+A) >> 0) & 0xffff */
474 HOWTO (AARCH64_R (MOVW_UABS_G0
), /* type */
476 2, /* size (0 = byte, 1 = short, 2 = long) */
478 FALSE
, /* pc_relative */
480 complain_overflow_unsigned
, /* complain_on_overflow */
481 bfd_elf_generic_reloc
, /* special_function */
482 AARCH64_R_STR (MOVW_UABS_G0
), /* name */
483 FALSE
, /* partial_inplace */
484 0xffff, /* src_mask */
485 0xffff, /* dst_mask */
486 FALSE
), /* pcrel_offset */
488 /* MOVK: ((S+A) >> 0) & 0xffff [no overflow check] */
489 HOWTO (AARCH64_R (MOVW_UABS_G0_NC
), /* type */
491 2, /* size (0 = byte, 1 = short, 2 = long) */
493 FALSE
, /* pc_relative */
495 complain_overflow_dont
, /* complain_on_overflow */
496 bfd_elf_generic_reloc
, /* special_function */
497 AARCH64_R_STR (MOVW_UABS_G0_NC
), /* name */
498 FALSE
, /* partial_inplace */
499 0xffff, /* src_mask */
500 0xffff, /* dst_mask */
501 FALSE
), /* pcrel_offset */
503 /* MOVZ: ((S+A) >> 16) & 0xffff */
504 HOWTO (AARCH64_R (MOVW_UABS_G1
), /* type */
506 2, /* size (0 = byte, 1 = short, 2 = long) */
508 FALSE
, /* pc_relative */
510 complain_overflow_unsigned
, /* complain_on_overflow */
511 bfd_elf_generic_reloc
, /* special_function */
512 AARCH64_R_STR (MOVW_UABS_G1
), /* name */
513 FALSE
, /* partial_inplace */
514 0xffff, /* src_mask */
515 0xffff, /* dst_mask */
516 FALSE
), /* pcrel_offset */
518 /* MOVK: ((S+A) >> 16) & 0xffff [no overflow check] */
519 HOWTO64 (AARCH64_R (MOVW_UABS_G1_NC
), /* type */
521 2, /* size (0 = byte, 1 = short, 2 = long) */
523 FALSE
, /* pc_relative */
525 complain_overflow_dont
, /* complain_on_overflow */
526 bfd_elf_generic_reloc
, /* special_function */
527 AARCH64_R_STR (MOVW_UABS_G1_NC
), /* name */
528 FALSE
, /* partial_inplace */
529 0xffff, /* src_mask */
530 0xffff, /* dst_mask */
531 FALSE
), /* pcrel_offset */
533 /* MOVZ: ((S+A) >> 32) & 0xffff */
534 HOWTO64 (AARCH64_R (MOVW_UABS_G2
), /* type */
536 2, /* size (0 = byte, 1 = short, 2 = long) */
538 FALSE
, /* pc_relative */
540 complain_overflow_unsigned
, /* complain_on_overflow */
541 bfd_elf_generic_reloc
, /* special_function */
542 AARCH64_R_STR (MOVW_UABS_G2
), /* name */
543 FALSE
, /* partial_inplace */
544 0xffff, /* src_mask */
545 0xffff, /* dst_mask */
546 FALSE
), /* pcrel_offset */
548 /* MOVK: ((S+A) >> 32) & 0xffff [no overflow check] */
549 HOWTO64 (AARCH64_R (MOVW_UABS_G2_NC
), /* type */
551 2, /* size (0 = byte, 1 = short, 2 = long) */
553 FALSE
, /* pc_relative */
555 complain_overflow_dont
, /* complain_on_overflow */
556 bfd_elf_generic_reloc
, /* special_function */
557 AARCH64_R_STR (MOVW_UABS_G2_NC
), /* name */
558 FALSE
, /* partial_inplace */
559 0xffff, /* src_mask */
560 0xffff, /* dst_mask */
561 FALSE
), /* pcrel_offset */
563 /* MOVZ: ((S+A) >> 48) & 0xffff */
564 HOWTO64 (AARCH64_R (MOVW_UABS_G3
), /* type */
566 2, /* size (0 = byte, 1 = short, 2 = long) */
568 FALSE
, /* pc_relative */
570 complain_overflow_unsigned
, /* complain_on_overflow */
571 bfd_elf_generic_reloc
, /* special_function */
572 AARCH64_R_STR (MOVW_UABS_G3
), /* name */
573 FALSE
, /* partial_inplace */
574 0xffff, /* src_mask */
575 0xffff, /* dst_mask */
576 FALSE
), /* pcrel_offset */
578 /* Group relocations to create high part of a 16, 32, 48 or 64 bit
579 signed data or abs address inline. Will change instruction
580 to MOVN or MOVZ depending on sign of calculated value. */
582 /* MOV[ZN]: ((S+A) >> 0) & 0xffff */
583 HOWTO (AARCH64_R (MOVW_SABS_G0
), /* 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_G0
), /* name */
592 FALSE
, /* partial_inplace */
593 0xffff, /* src_mask */
594 0xffff, /* dst_mask */
595 FALSE
), /* pcrel_offset */
597 /* MOV[ZN]: ((S+A) >> 16) & 0xffff */
598 HOWTO64 (AARCH64_R (MOVW_SABS_G1
), /* 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_G1
), /* name */
607 FALSE
, /* partial_inplace */
608 0xffff, /* src_mask */
609 0xffff, /* dst_mask */
610 FALSE
), /* pcrel_offset */
612 /* MOV[ZN]: ((S+A) >> 32) & 0xffff */
613 HOWTO64 (AARCH64_R (MOVW_SABS_G2
), /* type */
615 2, /* size (0 = byte, 1 = short, 2 = long) */
617 FALSE
, /* pc_relative */
619 complain_overflow_signed
, /* complain_on_overflow */
620 bfd_elf_generic_reloc
, /* special_function */
621 AARCH64_R_STR (MOVW_SABS_G2
), /* name */
622 FALSE
, /* partial_inplace */
623 0xffff, /* src_mask */
624 0xffff, /* dst_mask */
625 FALSE
), /* pcrel_offset */
627 /* Group relocations to create a 16, 32, 48 or 64 bit
628 PC relative address inline. */
630 /* MOV[NZ]: ((S+A-P) >> 0) & 0xffff */
631 HOWTO64 (AARCH64_R (MOVW_PREL_G0
), /* 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 (MOVW_PREL_G0
), /* name */
640 FALSE
, /* partial_inplace */
641 0xffff, /* src_mask */
642 0xffff, /* dst_mask */
643 TRUE
), /* pcrel_offset */
645 /* MOVK: ((S+A-P) >> 0) & 0xffff [no overflow check] */
646 HOWTO64 (AARCH64_R (MOVW_PREL_G0_NC
), /* type */
648 2, /* size (0 = byte, 1 = short, 2 = long) */
650 TRUE
, /* pc_relative */
652 complain_overflow_dont
, /* complain_on_overflow */
653 bfd_elf_generic_reloc
, /* special_function */
654 AARCH64_R_STR (MOVW_PREL_G0_NC
), /* name */
655 FALSE
, /* partial_inplace */
656 0xffff, /* src_mask */
657 0xffff, /* dst_mask */
658 TRUE
), /* pcrel_offset */
660 /* MOV[NZ]: ((S+A-P) >> 16) & 0xffff */
661 HOWTO64 (AARCH64_R (MOVW_PREL_G1
), /* type */
663 2, /* size (0 = byte, 1 = short, 2 = long) */
665 TRUE
, /* pc_relative */
667 complain_overflow_signed
, /* complain_on_overflow */
668 bfd_elf_generic_reloc
, /* special_function */
669 AARCH64_R_STR (MOVW_PREL_G1
), /* name */
670 FALSE
, /* partial_inplace */
671 0xffff, /* src_mask */
672 0xffff, /* dst_mask */
673 TRUE
), /* pcrel_offset */
675 /* MOVK: ((S+A-P) >> 16) & 0xffff [no overflow check] */
676 HOWTO64 (AARCH64_R (MOVW_PREL_G1_NC
), /* type */
678 2, /* size (0 = byte, 1 = short, 2 = long) */
680 TRUE
, /* pc_relative */
682 complain_overflow_dont
, /* complain_on_overflow */
683 bfd_elf_generic_reloc
, /* special_function */
684 AARCH64_R_STR (MOVW_PREL_G1_NC
), /* name */
685 FALSE
, /* partial_inplace */
686 0xffff, /* src_mask */
687 0xffff, /* dst_mask */
688 TRUE
), /* pcrel_offset */
690 /* MOV[NZ]: ((S+A-P) >> 32) & 0xffff */
691 HOWTO64 (AARCH64_R (MOVW_PREL_G2
), /* type */
693 2, /* size (0 = byte, 1 = short, 2 = long) */
695 TRUE
, /* pc_relative */
697 complain_overflow_signed
, /* complain_on_overflow */
698 bfd_elf_generic_reloc
, /* special_function */
699 AARCH64_R_STR (MOVW_PREL_G2
), /* name */
700 FALSE
, /* partial_inplace */
701 0xffff, /* src_mask */
702 0xffff, /* dst_mask */
703 TRUE
), /* pcrel_offset */
705 /* MOVK: ((S+A-P) >> 32) & 0xffff [no overflow check] */
706 HOWTO64 (AARCH64_R (MOVW_PREL_G2_NC
), /* type */
708 2, /* size (0 = byte, 1 = short, 2 = long) */
710 TRUE
, /* pc_relative */
712 complain_overflow_dont
, /* complain_on_overflow */
713 bfd_elf_generic_reloc
, /* special_function */
714 AARCH64_R_STR (MOVW_PREL_G2_NC
), /* name */
715 FALSE
, /* partial_inplace */
716 0xffff, /* src_mask */
717 0xffff, /* dst_mask */
718 TRUE
), /* pcrel_offset */
720 /* MOV[NZ]: ((S+A-P) >> 48) & 0xffff */
721 HOWTO64 (AARCH64_R (MOVW_PREL_G3
), /* type */
723 2, /* size (0 = byte, 1 = short, 2 = long) */
725 TRUE
, /* pc_relative */
727 complain_overflow_dont
, /* complain_on_overflow */
728 bfd_elf_generic_reloc
, /* special_function */
729 AARCH64_R_STR (MOVW_PREL_G3
), /* name */
730 FALSE
, /* partial_inplace */
731 0xffff, /* src_mask */
732 0xffff, /* dst_mask */
733 TRUE
), /* pcrel_offset */
735 /* Relocations to generate 19, 21 and 33 bit PC-relative load/store
736 addresses: PG(x) is (x & ~0xfff). */
738 /* LD-lit: ((S+A-P) >> 2) & 0x7ffff */
739 HOWTO (AARCH64_R (LD_PREL_LO19
), /* type */
741 2, /* size (0 = byte, 1 = short, 2 = long) */
743 TRUE
, /* pc_relative */
745 complain_overflow_signed
, /* complain_on_overflow */
746 bfd_elf_generic_reloc
, /* special_function */
747 AARCH64_R_STR (LD_PREL_LO19
), /* name */
748 FALSE
, /* partial_inplace */
749 0x7ffff, /* src_mask */
750 0x7ffff, /* dst_mask */
751 TRUE
), /* pcrel_offset */
753 /* ADR: (S+A-P) & 0x1fffff */
754 HOWTO (AARCH64_R (ADR_PREL_LO21
), /* type */
756 2, /* size (0 = byte, 1 = short, 2 = long) */
758 TRUE
, /* pc_relative */
760 complain_overflow_signed
, /* complain_on_overflow */
761 bfd_elf_generic_reloc
, /* special_function */
762 AARCH64_R_STR (ADR_PREL_LO21
), /* name */
763 FALSE
, /* partial_inplace */
764 0x1fffff, /* src_mask */
765 0x1fffff, /* dst_mask */
766 TRUE
), /* pcrel_offset */
768 /* ADRP: ((PG(S+A)-PG(P)) >> 12) & 0x1fffff */
769 HOWTO (AARCH64_R (ADR_PREL_PG_HI21
), /* type */
771 2, /* size (0 = byte, 1 = short, 2 = long) */
773 TRUE
, /* pc_relative */
775 complain_overflow_signed
, /* complain_on_overflow */
776 bfd_elf_generic_reloc
, /* special_function */
777 AARCH64_R_STR (ADR_PREL_PG_HI21
), /* name */
778 FALSE
, /* partial_inplace */
779 0x1fffff, /* src_mask */
780 0x1fffff, /* dst_mask */
781 TRUE
), /* pcrel_offset */
783 /* ADRP: ((PG(S+A)-PG(P)) >> 12) & 0x1fffff [no overflow check] */
784 HOWTO64 (AARCH64_R (ADR_PREL_PG_HI21_NC
), /* type */
786 2, /* size (0 = byte, 1 = short, 2 = long) */
788 TRUE
, /* pc_relative */
790 complain_overflow_dont
, /* complain_on_overflow */
791 bfd_elf_generic_reloc
, /* special_function */
792 AARCH64_R_STR (ADR_PREL_PG_HI21_NC
), /* name */
793 FALSE
, /* partial_inplace */
794 0x1fffff, /* src_mask */
795 0x1fffff, /* dst_mask */
796 TRUE
), /* pcrel_offset */
798 /* ADD: (S+A) & 0xfff [no overflow check] */
799 HOWTO (AARCH64_R (ADD_ABS_LO12_NC
), /* type */
801 2, /* size (0 = byte, 1 = short, 2 = long) */
803 FALSE
, /* pc_relative */
805 complain_overflow_dont
, /* complain_on_overflow */
806 bfd_elf_generic_reloc
, /* special_function */
807 AARCH64_R_STR (ADD_ABS_LO12_NC
), /* name */
808 FALSE
, /* partial_inplace */
809 0x3ffc00, /* src_mask */
810 0x3ffc00, /* dst_mask */
811 FALSE
), /* pcrel_offset */
813 /* LD/ST8: (S+A) & 0xfff */
814 HOWTO (AARCH64_R (LDST8_ABS_LO12_NC
), /* type */
816 2, /* size (0 = byte, 1 = short, 2 = long) */
818 FALSE
, /* pc_relative */
820 complain_overflow_dont
, /* complain_on_overflow */
821 bfd_elf_generic_reloc
, /* special_function */
822 AARCH64_R_STR (LDST8_ABS_LO12_NC
), /* name */
823 FALSE
, /* partial_inplace */
824 0xfff, /* src_mask */
825 0xfff, /* dst_mask */
826 FALSE
), /* pcrel_offset */
828 /* Relocations for control-flow instructions. */
830 /* TBZ/NZ: ((S+A-P) >> 2) & 0x3fff */
831 HOWTO (AARCH64_R (TSTBR14
), /* type */
833 2, /* size (0 = byte, 1 = short, 2 = long) */
835 TRUE
, /* pc_relative */
837 complain_overflow_signed
, /* complain_on_overflow */
838 bfd_elf_generic_reloc
, /* special_function */
839 AARCH64_R_STR (TSTBR14
), /* name */
840 FALSE
, /* partial_inplace */
841 0x3fff, /* src_mask */
842 0x3fff, /* dst_mask */
843 TRUE
), /* pcrel_offset */
845 /* B.cond: ((S+A-P) >> 2) & 0x7ffff */
846 HOWTO (AARCH64_R (CONDBR19
), /* type */
848 2, /* size (0 = byte, 1 = short, 2 = long) */
850 TRUE
, /* pc_relative */
852 complain_overflow_signed
, /* complain_on_overflow */
853 bfd_elf_generic_reloc
, /* special_function */
854 AARCH64_R_STR (CONDBR19
), /* name */
855 FALSE
, /* partial_inplace */
856 0x7ffff, /* src_mask */
857 0x7ffff, /* dst_mask */
858 TRUE
), /* pcrel_offset */
860 /* B: ((S+A-P) >> 2) & 0x3ffffff */
861 HOWTO (AARCH64_R (JUMP26
), /* type */
863 2, /* size (0 = byte, 1 = short, 2 = long) */
865 TRUE
, /* pc_relative */
867 complain_overflow_signed
, /* complain_on_overflow */
868 bfd_elf_generic_reloc
, /* special_function */
869 AARCH64_R_STR (JUMP26
), /* name */
870 FALSE
, /* partial_inplace */
871 0x3ffffff, /* src_mask */
872 0x3ffffff, /* dst_mask */
873 TRUE
), /* pcrel_offset */
875 /* BL: ((S+A-P) >> 2) & 0x3ffffff */
876 HOWTO (AARCH64_R (CALL26
), /* type */
878 2, /* size (0 = byte, 1 = short, 2 = long) */
880 TRUE
, /* pc_relative */
882 complain_overflow_signed
, /* complain_on_overflow */
883 bfd_elf_generic_reloc
, /* special_function */
884 AARCH64_R_STR (CALL26
), /* name */
885 FALSE
, /* partial_inplace */
886 0x3ffffff, /* src_mask */
887 0x3ffffff, /* dst_mask */
888 TRUE
), /* pcrel_offset */
890 /* LD/ST16: (S+A) & 0xffe */
891 HOWTO (AARCH64_R (LDST16_ABS_LO12_NC
), /* type */
893 2, /* size (0 = byte, 1 = short, 2 = long) */
895 FALSE
, /* pc_relative */
897 complain_overflow_dont
, /* complain_on_overflow */
898 bfd_elf_generic_reloc
, /* special_function */
899 AARCH64_R_STR (LDST16_ABS_LO12_NC
), /* name */
900 FALSE
, /* partial_inplace */
901 0xffe, /* src_mask */
902 0xffe, /* dst_mask */
903 FALSE
), /* pcrel_offset */
905 /* LD/ST32: (S+A) & 0xffc */
906 HOWTO (AARCH64_R (LDST32_ABS_LO12_NC
), /* type */
908 2, /* size (0 = byte, 1 = short, 2 = long) */
910 FALSE
, /* pc_relative */
912 complain_overflow_dont
, /* complain_on_overflow */
913 bfd_elf_generic_reloc
, /* special_function */
914 AARCH64_R_STR (LDST32_ABS_LO12_NC
), /* name */
915 FALSE
, /* partial_inplace */
916 0xffc, /* src_mask */
917 0xffc, /* dst_mask */
918 FALSE
), /* pcrel_offset */
920 /* LD/ST64: (S+A) & 0xff8 */
921 HOWTO (AARCH64_R (LDST64_ABS_LO12_NC
), /* type */
923 2, /* size (0 = byte, 1 = short, 2 = long) */
925 FALSE
, /* pc_relative */
927 complain_overflow_dont
, /* complain_on_overflow */
928 bfd_elf_generic_reloc
, /* special_function */
929 AARCH64_R_STR (LDST64_ABS_LO12_NC
), /* name */
930 FALSE
, /* partial_inplace */
931 0xff8, /* src_mask */
932 0xff8, /* dst_mask */
933 FALSE
), /* pcrel_offset */
935 /* LD/ST128: (S+A) & 0xff0 */
936 HOWTO (AARCH64_R (LDST128_ABS_LO12_NC
), /* type */
938 2, /* size (0 = byte, 1 = short, 2 = long) */
940 FALSE
, /* pc_relative */
942 complain_overflow_dont
, /* complain_on_overflow */
943 bfd_elf_generic_reloc
, /* special_function */
944 AARCH64_R_STR (LDST128_ABS_LO12_NC
), /* name */
945 FALSE
, /* partial_inplace */
946 0xff0, /* src_mask */
947 0xff0, /* dst_mask */
948 FALSE
), /* pcrel_offset */
950 /* Set a load-literal immediate field to bits
951 0x1FFFFC of G(S)-P */
952 HOWTO (AARCH64_R (GOT_LD_PREL19
), /* type */
954 2, /* size (0 = byte,1 = short,2 = long) */
956 TRUE
, /* pc_relative */
958 complain_overflow_signed
, /* complain_on_overflow */
959 bfd_elf_generic_reloc
, /* special_function */
960 AARCH64_R_STR (GOT_LD_PREL19
), /* name */
961 FALSE
, /* partial_inplace */
962 0xffffe0, /* src_mask */
963 0xffffe0, /* dst_mask */
964 TRUE
), /* 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 (ADR_GOT_PAGE
), /* 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 (ADR_GOT_PAGE
), /* name */
977 FALSE
, /* partial_inplace */
978 0x1fffff, /* src_mask */
979 0x1fffff, /* dst_mask */
980 TRUE
), /* pcrel_offset */
982 /* LD64: GOT offset G(S) & 0xff8 */
983 HOWTO64 (AARCH64_R (LD64_GOT_LO12_NC
), /* type */
985 2, /* size (0 = byte, 1 = short, 2 = long) */
987 FALSE
, /* pc_relative */
989 complain_overflow_dont
, /* complain_on_overflow */
990 bfd_elf_generic_reloc
, /* special_function */
991 AARCH64_R_STR (LD64_GOT_LO12_NC
), /* name */
992 FALSE
, /* partial_inplace */
993 0xff8, /* src_mask */
994 0xff8, /* dst_mask */
995 FALSE
), /* pcrel_offset */
997 /* LD32: GOT offset G(S) & 0xffc */
998 HOWTO32 (AARCH64_R (LD32_GOT_LO12_NC
), /* type */
1000 2, /* size (0 = byte, 1 = short, 2 = long) */
1002 FALSE
, /* pc_relative */
1004 complain_overflow_dont
, /* complain_on_overflow */
1005 bfd_elf_generic_reloc
, /* special_function */
1006 AARCH64_R_STR (LD32_GOT_LO12_NC
), /* name */
1007 FALSE
, /* partial_inplace */
1008 0xffc, /* src_mask */
1009 0xffc, /* dst_mask */
1010 FALSE
), /* pcrel_offset */
1012 /* Lower 16 bits of GOT offset for the symbol. */
1013 HOWTO64 (AARCH64_R (MOVW_GOTOFF_G0_NC
), /* type */
1015 2, /* size (0 = byte, 1 = short, 2 = long) */
1017 FALSE
, /* pc_relative */
1019 complain_overflow_dont
, /* complain_on_overflow */
1020 bfd_elf_generic_reloc
, /* special_function */
1021 AARCH64_R_STR (MOVW_GOTOFF_G0_NC
), /* name */
1022 FALSE
, /* partial_inplace */
1023 0xffff, /* src_mask */
1024 0xffff, /* dst_mask */
1025 FALSE
), /* pcrel_offset */
1027 /* Higher 16 bits of GOT offset for the symbol. */
1028 HOWTO64 (AARCH64_R (MOVW_GOTOFF_G1
), /* type */
1029 16, /* rightshift */
1030 2, /* size (0 = byte, 1 = short, 2 = long) */
1032 FALSE
, /* pc_relative */
1034 complain_overflow_unsigned
, /* complain_on_overflow */
1035 bfd_elf_generic_reloc
, /* special_function */
1036 AARCH64_R_STR (MOVW_GOTOFF_G1
), /* name */
1037 FALSE
, /* partial_inplace */
1038 0xffff, /* src_mask */
1039 0xffff, /* dst_mask */
1040 FALSE
), /* pcrel_offset */
1042 /* LD64: GOT offset for the symbol. */
1043 HOWTO64 (AARCH64_R (LD64_GOTOFF_LO15
), /* type */
1045 2, /* size (0 = byte, 1 = short, 2 = long) */
1047 FALSE
, /* pc_relative */
1049 complain_overflow_unsigned
, /* complain_on_overflow */
1050 bfd_elf_generic_reloc
, /* special_function */
1051 AARCH64_R_STR (LD64_GOTOFF_LO15
), /* name */
1052 FALSE
, /* partial_inplace */
1053 0x7ff8, /* src_mask */
1054 0x7ff8, /* dst_mask */
1055 FALSE
), /* pcrel_offset */
1057 /* LD32: GOT offset to the page address of GOT table.
1058 (G(S) - PAGE (_GLOBAL_OFFSET_TABLE_)) & 0x5ffc. */
1059 HOWTO32 (AARCH64_R (LD32_GOTPAGE_LO14
), /* type */
1061 2, /* size (0 = byte, 1 = short, 2 = long) */
1063 FALSE
, /* pc_relative */
1065 complain_overflow_unsigned
, /* complain_on_overflow */
1066 bfd_elf_generic_reloc
, /* special_function */
1067 AARCH64_R_STR (LD32_GOTPAGE_LO14
), /* name */
1068 FALSE
, /* partial_inplace */
1069 0x5ffc, /* src_mask */
1070 0x5ffc, /* dst_mask */
1071 FALSE
), /* pcrel_offset */
1073 /* LD64: GOT offset to the page address of GOT table.
1074 (G(S) - PAGE (_GLOBAL_OFFSET_TABLE_)) & 0x7ff8. */
1075 HOWTO64 (AARCH64_R (LD64_GOTPAGE_LO15
), /* type */
1077 2, /* size (0 = byte, 1 = short, 2 = long) */
1079 FALSE
, /* pc_relative */
1081 complain_overflow_unsigned
, /* complain_on_overflow */
1082 bfd_elf_generic_reloc
, /* special_function */
1083 AARCH64_R_STR (LD64_GOTPAGE_LO15
), /* name */
1084 FALSE
, /* partial_inplace */
1085 0x7ff8, /* src_mask */
1086 0x7ff8, /* dst_mask */
1087 FALSE
), /* pcrel_offset */
1089 /* Get to the page for the GOT entry for the symbol
1090 (G(S) - P) using an ADRP instruction. */
1091 HOWTO (AARCH64_R (TLSGD_ADR_PAGE21
), /* type */
1092 12, /* rightshift */
1093 2, /* size (0 = byte, 1 = short, 2 = long) */
1095 TRUE
, /* pc_relative */
1097 complain_overflow_dont
, /* complain_on_overflow */
1098 bfd_elf_generic_reloc
, /* special_function */
1099 AARCH64_R_STR (TLSGD_ADR_PAGE21
), /* name */
1100 FALSE
, /* partial_inplace */
1101 0x1fffff, /* src_mask */
1102 0x1fffff, /* dst_mask */
1103 TRUE
), /* pcrel_offset */
1105 HOWTO (AARCH64_R (TLSGD_ADR_PREL21
), /* type */
1107 2, /* size (0 = byte, 1 = short, 2 = long) */
1109 TRUE
, /* pc_relative */
1111 complain_overflow_dont
, /* complain_on_overflow */
1112 bfd_elf_generic_reloc
, /* special_function */
1113 AARCH64_R_STR (TLSGD_ADR_PREL21
), /* name */
1114 FALSE
, /* partial_inplace */
1115 0x1fffff, /* src_mask */
1116 0x1fffff, /* dst_mask */
1117 TRUE
), /* pcrel_offset */
1119 /* ADD: GOT offset G(S) & 0xff8 [no overflow check] */
1120 HOWTO (AARCH64_R (TLSGD_ADD_LO12_NC
), /* type */
1122 2, /* size (0 = byte, 1 = short, 2 = long) */
1124 FALSE
, /* pc_relative */
1126 complain_overflow_dont
, /* complain_on_overflow */
1127 bfd_elf_generic_reloc
, /* special_function */
1128 AARCH64_R_STR (TLSGD_ADD_LO12_NC
), /* name */
1129 FALSE
, /* partial_inplace */
1130 0xfff, /* src_mask */
1131 0xfff, /* dst_mask */
1132 FALSE
), /* pcrel_offset */
1134 /* Lower 16 bits of GOT offset to tls_index. */
1135 HOWTO64 (AARCH64_R (TLSGD_MOVW_G0_NC
), /* type */
1137 2, /* size (0 = byte, 1 = short, 2 = long) */
1139 FALSE
, /* pc_relative */
1141 complain_overflow_dont
, /* complain_on_overflow */
1142 bfd_elf_generic_reloc
, /* special_function */
1143 AARCH64_R_STR (TLSGD_MOVW_G0_NC
), /* name */
1144 FALSE
, /* partial_inplace */
1145 0xffff, /* src_mask */
1146 0xffff, /* dst_mask */
1147 FALSE
), /* pcrel_offset */
1149 /* Higher 16 bits of GOT offset to tls_index. */
1150 HOWTO64 (AARCH64_R (TLSGD_MOVW_G1
), /* type */
1151 16, /* rightshift */
1152 2, /* size (0 = byte, 1 = short, 2 = long) */
1154 FALSE
, /* pc_relative */
1156 complain_overflow_unsigned
, /* complain_on_overflow */
1157 bfd_elf_generic_reloc
, /* special_function */
1158 AARCH64_R_STR (TLSGD_MOVW_G1
), /* name */
1159 FALSE
, /* partial_inplace */
1160 0xffff, /* src_mask */
1161 0xffff, /* dst_mask */
1162 FALSE
), /* pcrel_offset */
1164 HOWTO (AARCH64_R (TLSIE_ADR_GOTTPREL_PAGE21
), /* type */
1165 12, /* rightshift */
1166 2, /* size (0 = byte, 1 = short, 2 = long) */
1168 FALSE
, /* pc_relative */
1170 complain_overflow_dont
, /* complain_on_overflow */
1171 bfd_elf_generic_reloc
, /* special_function */
1172 AARCH64_R_STR (TLSIE_ADR_GOTTPREL_PAGE21
), /* name */
1173 FALSE
, /* partial_inplace */
1174 0x1fffff, /* src_mask */
1175 0x1fffff, /* dst_mask */
1176 FALSE
), /* pcrel_offset */
1178 HOWTO64 (AARCH64_R (TLSIE_LD64_GOTTPREL_LO12_NC
), /* type */
1180 2, /* size (0 = byte, 1 = short, 2 = long) */
1182 FALSE
, /* pc_relative */
1184 complain_overflow_dont
, /* complain_on_overflow */
1185 bfd_elf_generic_reloc
, /* special_function */
1186 AARCH64_R_STR (TLSIE_LD64_GOTTPREL_LO12_NC
), /* name */
1187 FALSE
, /* partial_inplace */
1188 0xff8, /* src_mask */
1189 0xff8, /* dst_mask */
1190 FALSE
), /* pcrel_offset */
1192 HOWTO32 (AARCH64_R (TLSIE_LD32_GOTTPREL_LO12_NC
), /* type */
1194 2, /* size (0 = byte, 1 = short, 2 = long) */
1196 FALSE
, /* pc_relative */
1198 complain_overflow_dont
, /* complain_on_overflow */
1199 bfd_elf_generic_reloc
, /* special_function */
1200 AARCH64_R_STR (TLSIE_LD32_GOTTPREL_LO12_NC
), /* name */
1201 FALSE
, /* partial_inplace */
1202 0xffc, /* src_mask */
1203 0xffc, /* dst_mask */
1204 FALSE
), /* pcrel_offset */
1206 HOWTO (AARCH64_R (TLSIE_LD_GOTTPREL_PREL19
), /* type */
1208 2, /* size (0 = byte, 1 = short, 2 = long) */
1210 FALSE
, /* pc_relative */
1212 complain_overflow_dont
, /* complain_on_overflow */
1213 bfd_elf_generic_reloc
, /* special_function */
1214 AARCH64_R_STR (TLSIE_LD_GOTTPREL_PREL19
), /* name */
1215 FALSE
, /* partial_inplace */
1216 0x1ffffc, /* src_mask */
1217 0x1ffffc, /* dst_mask */
1218 FALSE
), /* pcrel_offset */
1220 HOWTO64 (AARCH64_R (TLSIE_MOVW_GOTTPREL_G0_NC
), /* type */
1222 2, /* size (0 = byte, 1 = short, 2 = long) */
1224 FALSE
, /* pc_relative */
1226 complain_overflow_dont
, /* complain_on_overflow */
1227 bfd_elf_generic_reloc
, /* special_function */
1228 AARCH64_R_STR (TLSIE_MOVW_GOTTPREL_G0_NC
), /* name */
1229 FALSE
, /* partial_inplace */
1230 0xffff, /* src_mask */
1231 0xffff, /* dst_mask */
1232 FALSE
), /* pcrel_offset */
1234 HOWTO64 (AARCH64_R (TLSIE_MOVW_GOTTPREL_G1
), /* type */
1235 16, /* rightshift */
1236 2, /* size (0 = byte, 1 = short, 2 = long) */
1238 FALSE
, /* pc_relative */
1240 complain_overflow_unsigned
, /* complain_on_overflow */
1241 bfd_elf_generic_reloc
, /* special_function */
1242 AARCH64_R_STR (TLSIE_MOVW_GOTTPREL_G1
), /* name */
1243 FALSE
, /* partial_inplace */
1244 0xffff, /* src_mask */
1245 0xffff, /* dst_mask */
1246 FALSE
), /* pcrel_offset */
1248 /* ADD: bit[23:12] of byte offset to module TLS base address. */
1249 HOWTO (AARCH64_R (TLSLD_ADD_DTPREL_HI12
), /* type */
1250 12, /* rightshift */
1251 2, /* size (0 = byte, 1 = short, 2 = long) */
1253 FALSE
, /* pc_relative */
1255 complain_overflow_unsigned
, /* complain_on_overflow */
1256 bfd_elf_generic_reloc
, /* special_function */
1257 AARCH64_R_STR (TLSLD_ADD_DTPREL_HI12
), /* name */
1258 FALSE
, /* partial_inplace */
1259 0xfff, /* src_mask */
1260 0xfff, /* dst_mask */
1261 FALSE
), /* pcrel_offset */
1263 /* Unsigned 12 bit byte offset to module TLS base address. */
1264 HOWTO (AARCH64_R (TLSLD_ADD_DTPREL_LO12
), /* type */
1266 2, /* size (0 = byte, 1 = short, 2 = long) */
1268 FALSE
, /* pc_relative */
1270 complain_overflow_unsigned
, /* complain_on_overflow */
1271 bfd_elf_generic_reloc
, /* special_function */
1272 AARCH64_R_STR (TLSLD_ADD_DTPREL_LO12
), /* name */
1273 FALSE
, /* partial_inplace */
1274 0xfff, /* src_mask */
1275 0xfff, /* dst_mask */
1276 FALSE
), /* pcrel_offset */
1278 /* No overflow check version of BFD_RELOC_AARCH64_TLSLD_ADD_DTPREL_LO12. */
1279 HOWTO (AARCH64_R (TLSLD_ADD_DTPREL_LO12_NC
), /* type */
1281 2, /* size (0 = byte, 1 = short, 2 = long) */
1283 FALSE
, /* pc_relative */
1285 complain_overflow_dont
, /* complain_on_overflow */
1286 bfd_elf_generic_reloc
, /* special_function */
1287 AARCH64_R_STR (TLSLD_ADD_DTPREL_LO12_NC
), /* name */
1288 FALSE
, /* partial_inplace */
1289 0xfff, /* src_mask */
1290 0xfff, /* dst_mask */
1291 FALSE
), /* pcrel_offset */
1293 /* ADD: GOT offset G(S) & 0xff8 [no overflow check] */
1294 HOWTO (AARCH64_R (TLSLD_ADD_LO12_NC
), /* type */
1296 2, /* size (0 = byte, 1 = short, 2 = long) */
1298 FALSE
, /* pc_relative */
1300 complain_overflow_dont
, /* complain_on_overflow */
1301 bfd_elf_generic_reloc
, /* special_function */
1302 AARCH64_R_STR (TLSLD_ADD_LO12_NC
), /* name */
1303 FALSE
, /* partial_inplace */
1304 0xfff, /* src_mask */
1305 0xfff, /* dst_mask */
1306 FALSE
), /* pcrel_offset */
1308 /* Get to the page for the GOT entry for the symbol
1309 (G(S) - P) using an ADRP instruction. */
1310 HOWTO (AARCH64_R (TLSLD_ADR_PAGE21
), /* type */
1311 12, /* rightshift */
1312 2, /* size (0 = byte, 1 = short, 2 = long) */
1314 TRUE
, /* pc_relative */
1316 complain_overflow_signed
, /* complain_on_overflow */
1317 bfd_elf_generic_reloc
, /* special_function */
1318 AARCH64_R_STR (TLSLD_ADR_PAGE21
), /* name */
1319 FALSE
, /* partial_inplace */
1320 0x1fffff, /* src_mask */
1321 0x1fffff, /* dst_mask */
1322 TRUE
), /* pcrel_offset */
1324 HOWTO (AARCH64_R (TLSLD_ADR_PREL21
), /* type */
1326 2, /* size (0 = byte, 1 = short, 2 = long) */
1328 TRUE
, /* pc_relative */
1330 complain_overflow_signed
, /* complain_on_overflow */
1331 bfd_elf_generic_reloc
, /* special_function */
1332 AARCH64_R_STR (TLSLD_ADR_PREL21
), /* name */
1333 FALSE
, /* partial_inplace */
1334 0x1fffff, /* src_mask */
1335 0x1fffff, /* dst_mask */
1336 TRUE
), /* pcrel_offset */
1338 /* LD/ST16: bit[11:1] of byte offset to module TLS base address. */
1339 HOWTO64 (AARCH64_R (TLSLD_LDST16_DTPREL_LO12
), /* type */
1341 2, /* size (0 = byte, 1 = short, 2 = long) */
1343 FALSE
, /* pc_relative */
1345 complain_overflow_unsigned
, /* complain_on_overflow */
1346 bfd_elf_generic_reloc
, /* special_function */
1347 AARCH64_R_STR (TLSLD_LDST16_DTPREL_LO12
), /* name */
1348 FALSE
, /* partial_inplace */
1349 0x1ffc00, /* src_mask */
1350 0x1ffc00, /* dst_mask */
1351 FALSE
), /* pcrel_offset */
1353 /* Same as BFD_RELOC_AARCH64_TLSLD_LDST16_DTPREL_LO12, but no overflow check. */
1354 HOWTO64 (AARCH64_R (TLSLD_LDST16_DTPREL_LO12_NC
), /* type */
1356 2, /* size (0 = byte, 1 = short, 2 = long) */
1358 FALSE
, /* pc_relative */
1360 complain_overflow_dont
, /* complain_on_overflow */
1361 bfd_elf_generic_reloc
, /* special_function */
1362 AARCH64_R_STR (TLSLD_LDST16_DTPREL_LO12_NC
), /* name */
1363 FALSE
, /* partial_inplace */
1364 0x1ffc00, /* src_mask */
1365 0x1ffc00, /* dst_mask */
1366 FALSE
), /* pcrel_offset */
1368 /* LD/ST32: bit[11:2] of byte offset to module TLS base address. */
1369 HOWTO64 (AARCH64_R (TLSLD_LDST32_DTPREL_LO12
), /* type */
1371 2, /* size (0 = byte, 1 = short, 2 = long) */
1373 FALSE
, /* pc_relative */
1375 complain_overflow_unsigned
, /* complain_on_overflow */
1376 bfd_elf_generic_reloc
, /* special_function */
1377 AARCH64_R_STR (TLSLD_LDST32_DTPREL_LO12
), /* name */
1378 FALSE
, /* partial_inplace */
1379 0x3ffc00, /* src_mask */
1380 0x3ffc00, /* dst_mask */
1381 FALSE
), /* pcrel_offset */
1383 /* Same as BFD_RELOC_AARCH64_TLSLD_LDST32_DTPREL_LO12, but no overflow check. */
1384 HOWTO64 (AARCH64_R (TLSLD_LDST32_DTPREL_LO12_NC
), /* type */
1386 2, /* size (0 = byte, 1 = short, 2 = long) */
1388 FALSE
, /* pc_relative */
1390 complain_overflow_dont
, /* complain_on_overflow */
1391 bfd_elf_generic_reloc
, /* special_function */
1392 AARCH64_R_STR (TLSLD_LDST32_DTPREL_LO12_NC
), /* name */
1393 FALSE
, /* partial_inplace */
1394 0xffc00, /* src_mask */
1395 0xffc00, /* dst_mask */
1396 FALSE
), /* pcrel_offset */
1398 /* LD/ST64: bit[11:3] of byte offset to module TLS base address. */
1399 HOWTO64 (AARCH64_R (TLSLD_LDST64_DTPREL_LO12
), /* type */
1401 2, /* size (0 = byte, 1 = short, 2 = long) */
1403 FALSE
, /* pc_relative */
1405 complain_overflow_unsigned
, /* complain_on_overflow */
1406 bfd_elf_generic_reloc
, /* special_function */
1407 AARCH64_R_STR (TLSLD_LDST64_DTPREL_LO12
), /* name */
1408 FALSE
, /* partial_inplace */
1409 0x3ffc00, /* src_mask */
1410 0x3ffc00, /* dst_mask */
1411 FALSE
), /* pcrel_offset */
1413 /* Same as BFD_RELOC_AARCH64_TLSLD_LDST64_DTPREL_LO12, but no overflow check. */
1414 HOWTO64 (AARCH64_R (TLSLD_LDST64_DTPREL_LO12_NC
), /* type */
1416 2, /* size (0 = byte, 1 = short, 2 = long) */
1418 FALSE
, /* pc_relative */
1420 complain_overflow_dont
, /* complain_on_overflow */
1421 bfd_elf_generic_reloc
, /* special_function */
1422 AARCH64_R_STR (TLSLD_LDST64_DTPREL_LO12_NC
), /* name */
1423 FALSE
, /* partial_inplace */
1424 0x7fc00, /* src_mask */
1425 0x7fc00, /* dst_mask */
1426 FALSE
), /* pcrel_offset */
1428 /* LD/ST8: bit[11:0] of byte offset to module TLS base address. */
1429 HOWTO64 (AARCH64_R (TLSLD_LDST8_DTPREL_LO12
), /* type */
1431 2, /* size (0 = byte, 1 = short, 2 = long) */
1433 FALSE
, /* pc_relative */
1435 complain_overflow_unsigned
, /* complain_on_overflow */
1436 bfd_elf_generic_reloc
, /* special_function */
1437 AARCH64_R_STR (TLSLD_LDST8_DTPREL_LO12
), /* name */
1438 FALSE
, /* partial_inplace */
1439 0x3ffc00, /* src_mask */
1440 0x3ffc00, /* dst_mask */
1441 FALSE
), /* pcrel_offset */
1443 /* Same as BFD_RELOC_AARCH64_TLSLD_LDST8_DTPREL_LO12, but no overflow check. */
1444 HOWTO64 (AARCH64_R (TLSLD_LDST8_DTPREL_LO12_NC
), /* type */
1446 2, /* size (0 = byte, 1 = short, 2 = long) */
1448 FALSE
, /* pc_relative */
1450 complain_overflow_dont
, /* complain_on_overflow */
1451 bfd_elf_generic_reloc
, /* special_function */
1452 AARCH64_R_STR (TLSLD_LDST8_DTPREL_LO12_NC
), /* name */
1453 FALSE
, /* partial_inplace */
1454 0x3ffc00, /* src_mask */
1455 0x3ffc00, /* dst_mask */
1456 FALSE
), /* pcrel_offset */
1458 /* MOVZ: bit[15:0] of byte offset to module TLS base address. */
1459 HOWTO (AARCH64_R (TLSLD_MOVW_DTPREL_G0
), /* type */
1461 2, /* size (0 = byte, 1 = short, 2 = long) */
1463 FALSE
, /* pc_relative */
1465 complain_overflow_unsigned
, /* complain_on_overflow */
1466 bfd_elf_generic_reloc
, /* special_function */
1467 AARCH64_R_STR (TLSLD_MOVW_DTPREL_G0
), /* name */
1468 FALSE
, /* partial_inplace */
1469 0xffff, /* src_mask */
1470 0xffff, /* dst_mask */
1471 FALSE
), /* pcrel_offset */
1473 /* No overflow check version of BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G0. */
1474 HOWTO (AARCH64_R (TLSLD_MOVW_DTPREL_G0_NC
), /* type */
1476 2, /* size (0 = byte, 1 = short, 2 = long) */
1478 FALSE
, /* pc_relative */
1480 complain_overflow_dont
, /* complain_on_overflow */
1481 bfd_elf_generic_reloc
, /* special_function */
1482 AARCH64_R_STR (TLSLD_MOVW_DTPREL_G0_NC
), /* name */
1483 FALSE
, /* partial_inplace */
1484 0xffff, /* src_mask */
1485 0xffff, /* dst_mask */
1486 FALSE
), /* pcrel_offset */
1488 /* MOVZ: bit[31:16] of byte offset to module TLS base address. */
1489 HOWTO (AARCH64_R (TLSLD_MOVW_DTPREL_G1
), /* type */
1490 16, /* rightshift */
1491 2, /* size (0 = byte, 1 = short, 2 = long) */
1493 FALSE
, /* pc_relative */
1495 complain_overflow_unsigned
, /* complain_on_overflow */
1496 bfd_elf_generic_reloc
, /* special_function */
1497 AARCH64_R_STR (TLSLD_MOVW_DTPREL_G1
), /* name */
1498 FALSE
, /* partial_inplace */
1499 0xffff, /* src_mask */
1500 0xffff, /* dst_mask */
1501 FALSE
), /* pcrel_offset */
1503 /* No overflow check version of BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G1. */
1504 HOWTO64 (AARCH64_R (TLSLD_MOVW_DTPREL_G1_NC
), /* type */
1505 16, /* rightshift */
1506 2, /* size (0 = byte, 1 = short, 2 = long) */
1508 FALSE
, /* pc_relative */
1510 complain_overflow_dont
, /* complain_on_overflow */
1511 bfd_elf_generic_reloc
, /* special_function */
1512 AARCH64_R_STR (TLSLD_MOVW_DTPREL_G1_NC
), /* name */
1513 FALSE
, /* partial_inplace */
1514 0xffff, /* src_mask */
1515 0xffff, /* dst_mask */
1516 FALSE
), /* pcrel_offset */
1518 /* MOVZ: bit[47:32] of byte offset to module TLS base address. */
1519 HOWTO64 (AARCH64_R (TLSLD_MOVW_DTPREL_G2
), /* type */
1520 32, /* rightshift */
1521 2, /* size (0 = byte, 1 = short, 2 = long) */
1523 FALSE
, /* pc_relative */
1525 complain_overflow_unsigned
, /* complain_on_overflow */
1526 bfd_elf_generic_reloc
, /* special_function */
1527 AARCH64_R_STR (TLSLD_MOVW_DTPREL_G2
), /* name */
1528 FALSE
, /* partial_inplace */
1529 0xffff, /* src_mask */
1530 0xffff, /* dst_mask */
1531 FALSE
), /* pcrel_offset */
1533 HOWTO64 (AARCH64_R (TLSLE_MOVW_TPREL_G2
), /* type */
1534 32, /* rightshift */
1535 2, /* size (0 = byte, 1 = short, 2 = long) */
1537 FALSE
, /* pc_relative */
1539 complain_overflow_unsigned
, /* complain_on_overflow */
1540 bfd_elf_generic_reloc
, /* special_function */
1541 AARCH64_R_STR (TLSLE_MOVW_TPREL_G2
), /* name */
1542 FALSE
, /* partial_inplace */
1543 0xffff, /* src_mask */
1544 0xffff, /* dst_mask */
1545 FALSE
), /* pcrel_offset */
1547 HOWTO (AARCH64_R (TLSLE_MOVW_TPREL_G1
), /* type */
1548 16, /* rightshift */
1549 2, /* size (0 = byte, 1 = short, 2 = long) */
1551 FALSE
, /* pc_relative */
1553 complain_overflow_dont
, /* complain_on_overflow */
1554 bfd_elf_generic_reloc
, /* special_function */
1555 AARCH64_R_STR (TLSLE_MOVW_TPREL_G1
), /* name */
1556 FALSE
, /* partial_inplace */
1557 0xffff, /* src_mask */
1558 0xffff, /* dst_mask */
1559 FALSE
), /* pcrel_offset */
1561 HOWTO64 (AARCH64_R (TLSLE_MOVW_TPREL_G1_NC
), /* type */
1562 16, /* rightshift */
1563 2, /* size (0 = byte, 1 = short, 2 = long) */
1565 FALSE
, /* pc_relative */
1567 complain_overflow_dont
, /* complain_on_overflow */
1568 bfd_elf_generic_reloc
, /* special_function */
1569 AARCH64_R_STR (TLSLE_MOVW_TPREL_G1_NC
), /* name */
1570 FALSE
, /* partial_inplace */
1571 0xffff, /* src_mask */
1572 0xffff, /* dst_mask */
1573 FALSE
), /* pcrel_offset */
1575 HOWTO (AARCH64_R (TLSLE_MOVW_TPREL_G0
), /* type */
1577 2, /* size (0 = byte, 1 = short, 2 = long) */
1579 FALSE
, /* pc_relative */
1581 complain_overflow_dont
, /* complain_on_overflow */
1582 bfd_elf_generic_reloc
, /* special_function */
1583 AARCH64_R_STR (TLSLE_MOVW_TPREL_G0
), /* name */
1584 FALSE
, /* partial_inplace */
1585 0xffff, /* src_mask */
1586 0xffff, /* dst_mask */
1587 FALSE
), /* pcrel_offset */
1589 HOWTO (AARCH64_R (TLSLE_MOVW_TPREL_G0_NC
), /* type */
1591 2, /* size (0 = byte, 1 = short, 2 = long) */
1593 FALSE
, /* pc_relative */
1595 complain_overflow_dont
, /* complain_on_overflow */
1596 bfd_elf_generic_reloc
, /* special_function */
1597 AARCH64_R_STR (TLSLE_MOVW_TPREL_G0_NC
), /* name */
1598 FALSE
, /* partial_inplace */
1599 0xffff, /* src_mask */
1600 0xffff, /* dst_mask */
1601 FALSE
), /* pcrel_offset */
1603 HOWTO (AARCH64_R (TLSLE_ADD_TPREL_HI12
), /* type */
1604 12, /* rightshift */
1605 2, /* size (0 = byte, 1 = short, 2 = long) */
1607 FALSE
, /* pc_relative */
1609 complain_overflow_unsigned
, /* complain_on_overflow */
1610 bfd_elf_generic_reloc
, /* special_function */
1611 AARCH64_R_STR (TLSLE_ADD_TPREL_HI12
), /* name */
1612 FALSE
, /* partial_inplace */
1613 0xfff, /* src_mask */
1614 0xfff, /* dst_mask */
1615 FALSE
), /* pcrel_offset */
1617 HOWTO (AARCH64_R (TLSLE_ADD_TPREL_LO12
), /* type */
1619 2, /* size (0 = byte, 1 = short, 2 = long) */
1621 FALSE
, /* pc_relative */
1623 complain_overflow_unsigned
, /* complain_on_overflow */
1624 bfd_elf_generic_reloc
, /* special_function */
1625 AARCH64_R_STR (TLSLE_ADD_TPREL_LO12
), /* name */
1626 FALSE
, /* partial_inplace */
1627 0xfff, /* src_mask */
1628 0xfff, /* dst_mask */
1629 FALSE
), /* pcrel_offset */
1631 HOWTO (AARCH64_R (TLSLE_ADD_TPREL_LO12_NC
), /* type */
1633 2, /* size (0 = byte, 1 = short, 2 = long) */
1635 FALSE
, /* pc_relative */
1637 complain_overflow_dont
, /* complain_on_overflow */
1638 bfd_elf_generic_reloc
, /* special_function */
1639 AARCH64_R_STR (TLSLE_ADD_TPREL_LO12_NC
), /* name */
1640 FALSE
, /* partial_inplace */
1641 0xfff, /* src_mask */
1642 0xfff, /* dst_mask */
1643 FALSE
), /* pcrel_offset */
1645 /* LD/ST16: bit[11:1] of byte offset to module TLS base address. */
1646 HOWTO (AARCH64_R (TLSLE_LDST16_TPREL_LO12
), /* type */
1648 2, /* size (0 = byte, 1 = short, 2 = long) */
1650 FALSE
, /* pc_relative */
1652 complain_overflow_unsigned
, /* complain_on_overflow */
1653 bfd_elf_generic_reloc
, /* special_function */
1654 AARCH64_R_STR (TLSLE_LDST16_TPREL_LO12
), /* name */
1655 FALSE
, /* partial_inplace */
1656 0x1ffc00, /* src_mask */
1657 0x1ffc00, /* dst_mask */
1658 FALSE
), /* pcrel_offset */
1660 /* Same as BFD_RELOC_AARCH64_TLSLE_LDST16_TPREL_LO12, but no overflow check. */
1661 HOWTO (AARCH64_R (TLSLE_LDST16_TPREL_LO12_NC
), /* type */
1663 2, /* size (0 = byte, 1 = short, 2 = long) */
1665 FALSE
, /* pc_relative */
1667 complain_overflow_dont
, /* complain_on_overflow */
1668 bfd_elf_generic_reloc
, /* special_function */
1669 AARCH64_R_STR (TLSLE_LDST16_TPREL_LO12_NC
), /* name */
1670 FALSE
, /* partial_inplace */
1671 0x1ffc00, /* src_mask */
1672 0x1ffc00, /* dst_mask */
1673 FALSE
), /* pcrel_offset */
1675 /* LD/ST32: bit[11:2] of byte offset to module TLS base address. */
1676 HOWTO (AARCH64_R (TLSLE_LDST32_TPREL_LO12
), /* type */
1678 2, /* size (0 = byte, 1 = short, 2 = long) */
1680 FALSE
, /* pc_relative */
1682 complain_overflow_unsigned
, /* complain_on_overflow */
1683 bfd_elf_generic_reloc
, /* special_function */
1684 AARCH64_R_STR (TLSLE_LDST32_TPREL_LO12
), /* name */
1685 FALSE
, /* partial_inplace */
1686 0xffc00, /* src_mask */
1687 0xffc00, /* dst_mask */
1688 FALSE
), /* pcrel_offset */
1690 /* Same as BFD_RELOC_AARCH64_TLSLE_LDST32_TPREL_LO12, but no overflow check. */
1691 HOWTO (AARCH64_R (TLSLE_LDST32_TPREL_LO12_NC
), /* type */
1693 2, /* size (0 = byte, 1 = short, 2 = long) */
1695 FALSE
, /* pc_relative */
1697 complain_overflow_dont
, /* complain_on_overflow */
1698 bfd_elf_generic_reloc
, /* special_function */
1699 AARCH64_R_STR (TLSLE_LDST32_TPREL_LO12_NC
), /* name */
1700 FALSE
, /* partial_inplace */
1701 0xffc00, /* src_mask */
1702 0xffc00, /* dst_mask */
1703 FALSE
), /* pcrel_offset */
1705 /* LD/ST64: bit[11:3] of byte offset to module TLS base address. */
1706 HOWTO (AARCH64_R (TLSLE_LDST64_TPREL_LO12
), /* type */
1708 2, /* size (0 = byte, 1 = short, 2 = long) */
1710 FALSE
, /* pc_relative */
1712 complain_overflow_unsigned
, /* complain_on_overflow */
1713 bfd_elf_generic_reloc
, /* special_function */
1714 AARCH64_R_STR (TLSLE_LDST64_TPREL_LO12
), /* name */
1715 FALSE
, /* partial_inplace */
1716 0x7fc00, /* src_mask */
1717 0x7fc00, /* dst_mask */
1718 FALSE
), /* pcrel_offset */
1720 /* Same as BFD_RELOC_AARCH64_TLSLE_LDST64_TPREL_LO12, but no overflow check. */
1721 HOWTO (AARCH64_R (TLSLE_LDST64_TPREL_LO12_NC
), /* type */
1723 2, /* size (0 = byte, 1 = short, 2 = long) */
1725 FALSE
, /* pc_relative */
1727 complain_overflow_dont
, /* complain_on_overflow */
1728 bfd_elf_generic_reloc
, /* special_function */
1729 AARCH64_R_STR (TLSLE_LDST64_TPREL_LO12_NC
), /* name */
1730 FALSE
, /* partial_inplace */
1731 0x7fc00, /* src_mask */
1732 0x7fc00, /* dst_mask */
1733 FALSE
), /* pcrel_offset */
1735 /* LD/ST8: bit[11:0] of byte offset to module TLS base address. */
1736 HOWTO (AARCH64_R (TLSLE_LDST8_TPREL_LO12
), /* type */
1738 2, /* size (0 = byte, 1 = short, 2 = long) */
1740 FALSE
, /* pc_relative */
1742 complain_overflow_unsigned
, /* complain_on_overflow */
1743 bfd_elf_generic_reloc
, /* special_function */
1744 AARCH64_R_STR (TLSLE_LDST8_TPREL_LO12
), /* name */
1745 FALSE
, /* partial_inplace */
1746 0x3ffc00, /* src_mask */
1747 0x3ffc00, /* dst_mask */
1748 FALSE
), /* pcrel_offset */
1750 /* Same as BFD_RELOC_AARCH64_TLSLE_LDST8_TPREL_LO12, but no overflow check. */
1751 HOWTO (AARCH64_R (TLSLE_LDST8_TPREL_LO12_NC
), /* type */
1753 2, /* size (0 = byte, 1 = short, 2 = long) */
1755 FALSE
, /* pc_relative */
1757 complain_overflow_dont
, /* complain_on_overflow */
1758 bfd_elf_generic_reloc
, /* special_function */
1759 AARCH64_R_STR (TLSLE_LDST8_TPREL_LO12_NC
), /* name */
1760 FALSE
, /* partial_inplace */
1761 0x3ffc00, /* src_mask */
1762 0x3ffc00, /* dst_mask */
1763 FALSE
), /* pcrel_offset */
1765 HOWTO (AARCH64_R (TLSDESC_LD_PREL19
), /* type */
1767 2, /* size (0 = byte, 1 = short, 2 = long) */
1769 TRUE
, /* pc_relative */
1771 complain_overflow_dont
, /* complain_on_overflow */
1772 bfd_elf_generic_reloc
, /* special_function */
1773 AARCH64_R_STR (TLSDESC_LD_PREL19
), /* name */
1774 FALSE
, /* partial_inplace */
1775 0x0ffffe0, /* src_mask */
1776 0x0ffffe0, /* dst_mask */
1777 TRUE
), /* pcrel_offset */
1779 HOWTO (AARCH64_R (TLSDESC_ADR_PREL21
), /* type */
1781 2, /* size (0 = byte, 1 = short, 2 = long) */
1783 TRUE
, /* pc_relative */
1785 complain_overflow_dont
, /* complain_on_overflow */
1786 bfd_elf_generic_reloc
, /* special_function */
1787 AARCH64_R_STR (TLSDESC_ADR_PREL21
), /* name */
1788 FALSE
, /* partial_inplace */
1789 0x1fffff, /* src_mask */
1790 0x1fffff, /* dst_mask */
1791 TRUE
), /* pcrel_offset */
1793 /* Get to the page for the GOT entry for the symbol
1794 (G(S) - P) using an ADRP instruction. */
1795 HOWTO (AARCH64_R (TLSDESC_ADR_PAGE21
), /* type */
1796 12, /* rightshift */
1797 2, /* size (0 = byte, 1 = short, 2 = long) */
1799 TRUE
, /* pc_relative */
1801 complain_overflow_dont
, /* complain_on_overflow */
1802 bfd_elf_generic_reloc
, /* special_function */
1803 AARCH64_R_STR (TLSDESC_ADR_PAGE21
), /* name */
1804 FALSE
, /* partial_inplace */
1805 0x1fffff, /* src_mask */
1806 0x1fffff, /* dst_mask */
1807 TRUE
), /* pcrel_offset */
1809 /* LD64: GOT offset G(S) & 0xff8. */
1810 HOWTO64 (AARCH64_R (TLSDESC_LD64_LO12
), /* type */
1812 2, /* size (0 = byte, 1 = short, 2 = long) */
1814 FALSE
, /* pc_relative */
1816 complain_overflow_dont
, /* complain_on_overflow */
1817 bfd_elf_generic_reloc
, /* special_function */
1818 AARCH64_R_STR (TLSDESC_LD64_LO12
), /* name */
1819 FALSE
, /* partial_inplace */
1820 0xff8, /* src_mask */
1821 0xff8, /* dst_mask */
1822 FALSE
), /* pcrel_offset */
1824 /* LD32: GOT offset G(S) & 0xffc. */
1825 HOWTO32 (AARCH64_R (TLSDESC_LD32_LO12_NC
), /* type */
1827 2, /* size (0 = byte, 1 = short, 2 = long) */
1829 FALSE
, /* pc_relative */
1831 complain_overflow_dont
, /* complain_on_overflow */
1832 bfd_elf_generic_reloc
, /* special_function */
1833 AARCH64_R_STR (TLSDESC_LD32_LO12_NC
), /* name */
1834 FALSE
, /* partial_inplace */
1835 0xffc, /* src_mask */
1836 0xffc, /* dst_mask */
1837 FALSE
), /* pcrel_offset */
1839 /* ADD: GOT offset G(S) & 0xfff. */
1840 HOWTO (AARCH64_R (TLSDESC_ADD_LO12
), /* type */
1842 2, /* size (0 = byte, 1 = short, 2 = long) */
1844 FALSE
, /* pc_relative */
1846 complain_overflow_dont
,/* complain_on_overflow */
1847 bfd_elf_generic_reloc
, /* special_function */
1848 AARCH64_R_STR (TLSDESC_ADD_LO12
), /* name */
1849 FALSE
, /* partial_inplace */
1850 0xfff, /* src_mask */
1851 0xfff, /* dst_mask */
1852 FALSE
), /* pcrel_offset */
1854 HOWTO64 (AARCH64_R (TLSDESC_OFF_G1
), /* type */
1855 16, /* rightshift */
1856 2, /* size (0 = byte, 1 = short, 2 = long) */
1858 FALSE
, /* pc_relative */
1860 complain_overflow_unsigned
, /* complain_on_overflow */
1861 bfd_elf_generic_reloc
, /* special_function */
1862 AARCH64_R_STR (TLSDESC_OFF_G1
), /* name */
1863 FALSE
, /* partial_inplace */
1864 0xffff, /* src_mask */
1865 0xffff, /* dst_mask */
1866 FALSE
), /* pcrel_offset */
1868 HOWTO64 (AARCH64_R (TLSDESC_OFF_G0_NC
), /* type */
1870 2, /* size (0 = byte, 1 = short, 2 = long) */
1872 FALSE
, /* pc_relative */
1874 complain_overflow_dont
, /* complain_on_overflow */
1875 bfd_elf_generic_reloc
, /* special_function */
1876 AARCH64_R_STR (TLSDESC_OFF_G0_NC
), /* name */
1877 FALSE
, /* partial_inplace */
1878 0xffff, /* src_mask */
1879 0xffff, /* dst_mask */
1880 FALSE
), /* pcrel_offset */
1882 HOWTO64 (AARCH64_R (TLSDESC_LDR
), /* type */
1884 2, /* size (0 = byte, 1 = short, 2 = long) */
1886 FALSE
, /* pc_relative */
1888 complain_overflow_dont
, /* complain_on_overflow */
1889 bfd_elf_generic_reloc
, /* special_function */
1890 AARCH64_R_STR (TLSDESC_LDR
), /* name */
1891 FALSE
, /* partial_inplace */
1894 FALSE
), /* pcrel_offset */
1896 HOWTO64 (AARCH64_R (TLSDESC_ADD
), /* type */
1898 2, /* size (0 = byte, 1 = short, 2 = long) */
1900 FALSE
, /* pc_relative */
1902 complain_overflow_dont
, /* complain_on_overflow */
1903 bfd_elf_generic_reloc
, /* special_function */
1904 AARCH64_R_STR (TLSDESC_ADD
), /* name */
1905 FALSE
, /* partial_inplace */
1908 FALSE
), /* pcrel_offset */
1910 HOWTO (AARCH64_R (TLSDESC_CALL
), /* type */
1912 2, /* size (0 = byte, 1 = short, 2 = long) */
1914 FALSE
, /* pc_relative */
1916 complain_overflow_dont
, /* complain_on_overflow */
1917 bfd_elf_generic_reloc
, /* special_function */
1918 AARCH64_R_STR (TLSDESC_CALL
), /* name */
1919 FALSE
, /* partial_inplace */
1922 FALSE
), /* pcrel_offset */
1924 HOWTO (AARCH64_R (COPY
), /* type */
1926 2, /* size (0 = byte, 1 = short, 2 = long) */
1928 FALSE
, /* pc_relative */
1930 complain_overflow_bitfield
, /* complain_on_overflow */
1931 bfd_elf_generic_reloc
, /* special_function */
1932 AARCH64_R_STR (COPY
), /* name */
1933 TRUE
, /* partial_inplace */
1934 0xffffffff, /* src_mask */
1935 0xffffffff, /* dst_mask */
1936 FALSE
), /* pcrel_offset */
1938 HOWTO (AARCH64_R (GLOB_DAT
), /* type */
1940 2, /* size (0 = byte, 1 = short, 2 = long) */
1942 FALSE
, /* pc_relative */
1944 complain_overflow_bitfield
, /* complain_on_overflow */
1945 bfd_elf_generic_reloc
, /* special_function */
1946 AARCH64_R_STR (GLOB_DAT
), /* name */
1947 TRUE
, /* partial_inplace */
1948 0xffffffff, /* src_mask */
1949 0xffffffff, /* dst_mask */
1950 FALSE
), /* pcrel_offset */
1952 HOWTO (AARCH64_R (JUMP_SLOT
), /* type */
1954 2, /* size (0 = byte, 1 = short, 2 = long) */
1956 FALSE
, /* pc_relative */
1958 complain_overflow_bitfield
, /* complain_on_overflow */
1959 bfd_elf_generic_reloc
, /* special_function */
1960 AARCH64_R_STR (JUMP_SLOT
), /* name */
1961 TRUE
, /* partial_inplace */
1962 0xffffffff, /* src_mask */
1963 0xffffffff, /* dst_mask */
1964 FALSE
), /* pcrel_offset */
1966 HOWTO (AARCH64_R (RELATIVE
), /* type */
1968 2, /* size (0 = byte, 1 = short, 2 = long) */
1970 FALSE
, /* pc_relative */
1972 complain_overflow_bitfield
, /* complain_on_overflow */
1973 bfd_elf_generic_reloc
, /* special_function */
1974 AARCH64_R_STR (RELATIVE
), /* name */
1975 TRUE
, /* partial_inplace */
1976 ALL_ONES
, /* src_mask */
1977 ALL_ONES
, /* dst_mask */
1978 FALSE
), /* pcrel_offset */
1980 HOWTO (AARCH64_R (TLS_DTPMOD
), /* type */
1982 2, /* size (0 = byte, 1 = short, 2 = long) */
1984 FALSE
, /* pc_relative */
1986 complain_overflow_dont
, /* complain_on_overflow */
1987 bfd_elf_generic_reloc
, /* special_function */
1989 AARCH64_R_STR (TLS_DTPMOD64
), /* name */
1991 AARCH64_R_STR (TLS_DTPMOD
), /* name */
1993 FALSE
, /* partial_inplace */
1995 ALL_ONES
, /* dst_mask */
1996 FALSE
), /* pc_reloffset */
1998 HOWTO (AARCH64_R (TLS_DTPREL
), /* type */
2000 2, /* size (0 = byte, 1 = short, 2 = long) */
2002 FALSE
, /* pc_relative */
2004 complain_overflow_dont
, /* complain_on_overflow */
2005 bfd_elf_generic_reloc
, /* special_function */
2007 AARCH64_R_STR (TLS_DTPREL64
), /* name */
2009 AARCH64_R_STR (TLS_DTPREL
), /* name */
2011 FALSE
, /* partial_inplace */
2013 ALL_ONES
, /* dst_mask */
2014 FALSE
), /* pcrel_offset */
2016 HOWTO (AARCH64_R (TLS_TPREL
), /* type */
2018 2, /* size (0 = byte, 1 = short, 2 = long) */
2020 FALSE
, /* pc_relative */
2022 complain_overflow_dont
, /* complain_on_overflow */
2023 bfd_elf_generic_reloc
, /* special_function */
2025 AARCH64_R_STR (TLS_TPREL64
), /* name */
2027 AARCH64_R_STR (TLS_TPREL
), /* name */
2029 FALSE
, /* partial_inplace */
2031 ALL_ONES
, /* dst_mask */
2032 FALSE
), /* pcrel_offset */
2034 HOWTO (AARCH64_R (TLSDESC
), /* type */
2036 2, /* size (0 = byte, 1 = short, 2 = long) */
2038 FALSE
, /* pc_relative */
2040 complain_overflow_dont
, /* complain_on_overflow */
2041 bfd_elf_generic_reloc
, /* special_function */
2042 AARCH64_R_STR (TLSDESC
), /* name */
2043 FALSE
, /* partial_inplace */
2045 ALL_ONES
, /* dst_mask */
2046 FALSE
), /* pcrel_offset */
2048 HOWTO (AARCH64_R (IRELATIVE
), /* type */
2050 2, /* size (0 = byte, 1 = short, 2 = long) */
2052 FALSE
, /* pc_relative */
2054 complain_overflow_bitfield
, /* complain_on_overflow */
2055 bfd_elf_generic_reloc
, /* special_function */
2056 AARCH64_R_STR (IRELATIVE
), /* name */
2057 FALSE
, /* partial_inplace */
2059 ALL_ONES
, /* dst_mask */
2060 FALSE
), /* pcrel_offset */
2065 static reloc_howto_type elfNN_aarch64_howto_none
=
2066 HOWTO (R_AARCH64_NONE
, /* type */
2068 3, /* size (0 = byte, 1 = short, 2 = long) */
2070 FALSE
, /* pc_relative */
2072 complain_overflow_dont
,/* complain_on_overflow */
2073 bfd_elf_generic_reloc
, /* special_function */
2074 "R_AARCH64_NONE", /* name */
2075 FALSE
, /* partial_inplace */
2078 FALSE
); /* pcrel_offset */
2080 /* Given HOWTO, return the bfd internal relocation enumerator. */
2082 static bfd_reloc_code_real_type
2083 elfNN_aarch64_bfd_reloc_from_howto (reloc_howto_type
*howto
)
2086 = (int) ARRAY_SIZE (elfNN_aarch64_howto_table
);
2087 const ptrdiff_t offset
2088 = howto
- elfNN_aarch64_howto_table
;
2090 if (offset
> 0 && offset
< size
- 1)
2091 return BFD_RELOC_AARCH64_RELOC_START
+ offset
;
2093 if (howto
== &elfNN_aarch64_howto_none
)
2094 return BFD_RELOC_AARCH64_NONE
;
2096 return BFD_RELOC_AARCH64_RELOC_START
;
2099 /* Given R_TYPE, return the bfd internal relocation enumerator. */
2101 static bfd_reloc_code_real_type
2102 elfNN_aarch64_bfd_reloc_from_type (bfd
*abfd
, unsigned int r_type
)
2104 static bfd_boolean initialized_p
= FALSE
;
2105 /* Indexed by R_TYPE, values are offsets in the howto_table. */
2106 static unsigned int offsets
[R_AARCH64_end
];
2112 for (i
= 1; i
< ARRAY_SIZE (elfNN_aarch64_howto_table
) - 1; ++i
)
2113 if (elfNN_aarch64_howto_table
[i
].type
!= 0)
2114 offsets
[elfNN_aarch64_howto_table
[i
].type
] = i
;
2116 initialized_p
= TRUE
;
2119 if (r_type
== R_AARCH64_NONE
|| r_type
== R_AARCH64_NULL
)
2120 return BFD_RELOC_AARCH64_NONE
;
2122 /* PR 17512: file: b371e70a. */
2123 if (r_type
>= R_AARCH64_end
)
2125 _bfd_error_handler (_("%pB: unsupported relocation type %#x"),
2127 bfd_set_error (bfd_error_bad_value
);
2128 return BFD_RELOC_AARCH64_NONE
;
2131 return BFD_RELOC_AARCH64_RELOC_START
+ offsets
[r_type
];
2134 struct elf_aarch64_reloc_map
2136 bfd_reloc_code_real_type from
;
2137 bfd_reloc_code_real_type to
;
2140 /* Map bfd generic reloc to AArch64-specific reloc. */
2141 static const struct elf_aarch64_reloc_map elf_aarch64_reloc_map
[] =
2143 {BFD_RELOC_NONE
, BFD_RELOC_AARCH64_NONE
},
2145 /* Basic data relocations. */
2146 {BFD_RELOC_CTOR
, BFD_RELOC_AARCH64_NN
},
2147 {BFD_RELOC_64
, BFD_RELOC_AARCH64_64
},
2148 {BFD_RELOC_32
, BFD_RELOC_AARCH64_32
},
2149 {BFD_RELOC_16
, BFD_RELOC_AARCH64_16
},
2150 {BFD_RELOC_64_PCREL
, BFD_RELOC_AARCH64_64_PCREL
},
2151 {BFD_RELOC_32_PCREL
, BFD_RELOC_AARCH64_32_PCREL
},
2152 {BFD_RELOC_16_PCREL
, BFD_RELOC_AARCH64_16_PCREL
},
2155 /* Given the bfd internal relocation enumerator in CODE, return the
2156 corresponding howto entry. */
2158 static reloc_howto_type
*
2159 elfNN_aarch64_howto_from_bfd_reloc (bfd_reloc_code_real_type code
)
2163 /* Convert bfd generic reloc to AArch64-specific reloc. */
2164 if (code
< BFD_RELOC_AARCH64_RELOC_START
2165 || code
> BFD_RELOC_AARCH64_RELOC_END
)
2166 for (i
= 0; i
< ARRAY_SIZE (elf_aarch64_reloc_map
); i
++)
2167 if (elf_aarch64_reloc_map
[i
].from
== code
)
2169 code
= elf_aarch64_reloc_map
[i
].to
;
2173 if (code
> BFD_RELOC_AARCH64_RELOC_START
2174 && code
< BFD_RELOC_AARCH64_RELOC_END
)
2175 if (elfNN_aarch64_howto_table
[code
- BFD_RELOC_AARCH64_RELOC_START
].type
)
2176 return &elfNN_aarch64_howto_table
[code
- BFD_RELOC_AARCH64_RELOC_START
];
2178 if (code
== BFD_RELOC_AARCH64_NONE
)
2179 return &elfNN_aarch64_howto_none
;
2184 static reloc_howto_type
*
2185 elfNN_aarch64_howto_from_type (bfd
*abfd
, unsigned int r_type
)
2187 bfd_reloc_code_real_type val
;
2188 reloc_howto_type
*howto
;
2193 bfd_set_error (bfd_error_bad_value
);
2198 if (r_type
== R_AARCH64_NONE
)
2199 return &elfNN_aarch64_howto_none
;
2201 val
= elfNN_aarch64_bfd_reloc_from_type (abfd
, r_type
);
2202 howto
= elfNN_aarch64_howto_from_bfd_reloc (val
);
2207 bfd_set_error (bfd_error_bad_value
);
2212 elfNN_aarch64_info_to_howto (bfd
*abfd
, arelent
*bfd_reloc
,
2213 Elf_Internal_Rela
*elf_reloc
)
2215 unsigned int r_type
;
2217 r_type
= ELFNN_R_TYPE (elf_reloc
->r_info
);
2218 bfd_reloc
->howto
= elfNN_aarch64_howto_from_type (abfd
, r_type
);
2220 if (bfd_reloc
->howto
== NULL
)
2222 /* xgettext:c-format */
2223 _bfd_error_handler (_("%pB: unsupported relocation type %#x"), abfd
, r_type
);
2229 static reloc_howto_type
*
2230 elfNN_aarch64_reloc_type_lookup (bfd
*abfd ATTRIBUTE_UNUSED
,
2231 bfd_reloc_code_real_type code
)
2233 reloc_howto_type
*howto
= elfNN_aarch64_howto_from_bfd_reloc (code
);
2238 bfd_set_error (bfd_error_bad_value
);
2242 static reloc_howto_type
*
2243 elfNN_aarch64_reloc_name_lookup (bfd
*abfd ATTRIBUTE_UNUSED
,
2248 for (i
= 1; i
< ARRAY_SIZE (elfNN_aarch64_howto_table
) - 1; ++i
)
2249 if (elfNN_aarch64_howto_table
[i
].name
!= NULL
2250 && strcasecmp (elfNN_aarch64_howto_table
[i
].name
, r_name
) == 0)
2251 return &elfNN_aarch64_howto_table
[i
];
2256 #define TARGET_LITTLE_SYM aarch64_elfNN_le_vec
2257 #define TARGET_LITTLE_NAME "elfNN-littleaarch64"
2258 #define TARGET_BIG_SYM aarch64_elfNN_be_vec
2259 #define TARGET_BIG_NAME "elfNN-bigaarch64"
2261 /* The linker script knows the section names for placement.
2262 The entry_names are used to do simple name mangling on the stubs.
2263 Given a function name, and its type, the stub can be found. The
2264 name can be changed. The only requirement is the %s be present. */
2265 #define STUB_ENTRY_NAME "__%s_veneer"
2267 /* The name of the dynamic interpreter. This is put in the .interp
2269 #define ELF_DYNAMIC_INTERPRETER "/lib/ld.so.1"
2271 #define AARCH64_MAX_FWD_BRANCH_OFFSET \
2272 (((1 << 25) - 1) << 2)
2273 #define AARCH64_MAX_BWD_BRANCH_OFFSET \
2276 #define AARCH64_MAX_ADRP_IMM ((1 << 20) - 1)
2277 #define AARCH64_MIN_ADRP_IMM (-(1 << 20))
2280 aarch64_valid_for_adrp_p (bfd_vma value
, bfd_vma place
)
2282 bfd_signed_vma offset
= (bfd_signed_vma
) (PG (value
) - PG (place
)) >> 12;
2283 return offset
<= AARCH64_MAX_ADRP_IMM
&& offset
>= AARCH64_MIN_ADRP_IMM
;
2287 aarch64_valid_branch_p (bfd_vma value
, bfd_vma place
)
2289 bfd_signed_vma offset
= (bfd_signed_vma
) (value
- place
);
2290 return (offset
<= AARCH64_MAX_FWD_BRANCH_OFFSET
2291 && offset
>= AARCH64_MAX_BWD_BRANCH_OFFSET
);
2294 static const uint32_t aarch64_adrp_branch_stub
[] =
2296 0x90000010, /* adrp ip0, X */
2297 /* R_AARCH64_ADR_HI21_PCREL(X) */
2298 0x91000210, /* add ip0, ip0, :lo12:X */
2299 /* R_AARCH64_ADD_ABS_LO12_NC(X) */
2300 0xd61f0200, /* br ip0 */
2303 static const uint32_t aarch64_long_branch_stub
[] =
2306 0x58000090, /* ldr ip0, 1f */
2308 0x18000090, /* ldr wip0, 1f */
2310 0x10000011, /* adr ip1, #0 */
2311 0x8b110210, /* add ip0, ip0, ip1 */
2312 0xd61f0200, /* br ip0 */
2313 0x00000000, /* 1: .xword or .word
2314 R_AARCH64_PRELNN(X) + 12
2319 static const uint32_t aarch64_erratum_835769_stub
[] =
2321 0x00000000, /* Placeholder for multiply accumulate. */
2322 0x14000000, /* b <label> */
2325 static const uint32_t aarch64_erratum_843419_stub
[] =
2327 0x00000000, /* Placeholder for LDR instruction. */
2328 0x14000000, /* b <label> */
2331 /* Section name for stubs is the associated section name plus this
2333 #define STUB_SUFFIX ".stub"
2335 enum elf_aarch64_stub_type
2338 aarch64_stub_adrp_branch
,
2339 aarch64_stub_long_branch
,
2340 aarch64_stub_erratum_835769_veneer
,
2341 aarch64_stub_erratum_843419_veneer
,
2344 struct elf_aarch64_stub_hash_entry
2346 /* Base hash table entry structure. */
2347 struct bfd_hash_entry root
;
2349 /* The stub section. */
2352 /* Offset within stub_sec of the beginning of this stub. */
2353 bfd_vma stub_offset
;
2355 /* Given the symbol's value and its section we can determine its final
2356 value when building the stubs (so the stub knows where to jump). */
2357 bfd_vma target_value
;
2358 asection
*target_section
;
2360 enum elf_aarch64_stub_type stub_type
;
2362 /* The symbol table entry, if any, that this was derived from. */
2363 struct elf_aarch64_link_hash_entry
*h
;
2365 /* Destination symbol type */
2366 unsigned char st_type
;
2368 /* Where this stub is being called from, or, in the case of combined
2369 stub sections, the first input section in the group. */
2372 /* The name for the local symbol at the start of this stub. The
2373 stub name in the hash table has to be unique; this does not, so
2374 it can be friendlier. */
2377 /* The instruction which caused this stub to be generated (only valid for
2378 erratum 835769 workaround stubs at present). */
2379 uint32_t veneered_insn
;
2381 /* In an erratum 843419 workaround stub, the ADRP instruction offset. */
2382 bfd_vma adrp_offset
;
2385 /* Used to build a map of a section. This is required for mixed-endian
2388 typedef struct elf_elf_section_map
2393 elf_aarch64_section_map
;
2396 typedef struct _aarch64_elf_section_data
2398 struct bfd_elf_section_data elf
;
2399 unsigned int mapcount
;
2400 unsigned int mapsize
;
2401 elf_aarch64_section_map
*map
;
2403 _aarch64_elf_section_data
;
2405 #define elf_aarch64_section_data(sec) \
2406 ((_aarch64_elf_section_data *) elf_section_data (sec))
2408 /* The size of the thread control block which is defined to be two pointers. */
2409 #define TCB_SIZE (ARCH_SIZE/8)*2
2411 struct elf_aarch64_local_symbol
2413 unsigned int got_type
;
2414 bfd_signed_vma got_refcount
;
2417 /* Offset of the GOTPLT entry reserved for the TLS descriptor. The
2418 offset is from the end of the jump table and reserved entries
2421 The magic value (bfd_vma) -1 indicates that an offset has not be
2423 bfd_vma tlsdesc_got_jump_table_offset
;
2426 struct elf_aarch64_obj_tdata
2428 struct elf_obj_tdata root
;
2430 /* local symbol descriptors */
2431 struct elf_aarch64_local_symbol
*locals
;
2433 /* Zero to warn when linking objects with incompatible enum sizes. */
2434 int no_enum_size_warning
;
2436 /* Zero to warn when linking objects with incompatible wchar_t sizes. */
2437 int no_wchar_size_warning
;
2439 /* All GNU_PROPERTY_AARCH64_FEATURE_1_AND properties. */
2440 uint32_t gnu_and_prop
;
2443 #define elf_aarch64_tdata(bfd) \
2444 ((struct elf_aarch64_obj_tdata *) (bfd)->tdata.any)
2446 #define elf_aarch64_locals(bfd) (elf_aarch64_tdata (bfd)->locals)
2448 #define is_aarch64_elf(bfd) \
2449 (bfd_get_flavour (bfd) == bfd_target_elf_flavour \
2450 && elf_tdata (bfd) != NULL \
2451 && elf_object_id (bfd) == AARCH64_ELF_DATA)
2454 elfNN_aarch64_mkobject (bfd
*abfd
)
2456 return bfd_elf_allocate_object (abfd
, sizeof (struct elf_aarch64_obj_tdata
),
2460 #define elf_aarch64_hash_entry(ent) \
2461 ((struct elf_aarch64_link_hash_entry *)(ent))
2463 #define GOT_UNKNOWN 0
2464 #define GOT_NORMAL 1
2465 #define GOT_TLS_GD 2
2466 #define GOT_TLS_IE 4
2467 #define GOT_TLSDESC_GD 8
2469 #define GOT_TLS_GD_ANY_P(type) ((type & GOT_TLS_GD) || (type & GOT_TLSDESC_GD))
2471 /* AArch64 ELF linker hash entry. */
2472 struct elf_aarch64_link_hash_entry
2474 struct elf_link_hash_entry root
;
2476 /* Track dynamic relocs copied for this symbol. */
2477 struct elf_dyn_relocs
*dyn_relocs
;
2479 /* Since PLT entries have variable size, we need to record the
2480 index into .got.plt instead of recomputing it from the PLT
2482 bfd_signed_vma plt_got_offset
;
2484 /* Bit mask representing the type of GOT entry(s) if any required by
2486 unsigned int got_type
;
2488 /* A pointer to the most recently used stub hash entry against this
2490 struct elf_aarch64_stub_hash_entry
*stub_cache
;
2492 /* Offset of the GOTPLT entry reserved for the TLS descriptor. The offset
2493 is from the end of the jump table and reserved entries within the PLTGOT.
2495 The magic value (bfd_vma) -1 indicates that an offset has not
2497 bfd_vma tlsdesc_got_jump_table_offset
;
2501 elfNN_aarch64_symbol_got_type (struct elf_link_hash_entry
*h
,
2503 unsigned long r_symndx
)
2506 return elf_aarch64_hash_entry (h
)->got_type
;
2508 if (! elf_aarch64_locals (abfd
))
2511 return elf_aarch64_locals (abfd
)[r_symndx
].got_type
;
2514 /* Get the AArch64 elf linker hash table from a link_info structure. */
2515 #define elf_aarch64_hash_table(info) \
2516 ((struct elf_aarch64_link_hash_table *) ((info)->hash))
2518 #define aarch64_stub_hash_lookup(table, string, create, copy) \
2519 ((struct elf_aarch64_stub_hash_entry *) \
2520 bfd_hash_lookup ((table), (string), (create), (copy)))
2522 /* AArch64 ELF linker hash table. */
2523 struct elf_aarch64_link_hash_table
2525 /* The main hash table. */
2526 struct elf_link_hash_table root
;
2528 /* Nonzero to force PIC branch veneers. */
2531 /* Fix erratum 835769. */
2532 int fix_erratum_835769
;
2534 /* Fix erratum 843419. */
2535 int fix_erratum_843419
;
2537 /* Enable ADRP->ADR rewrite for erratum 843419 workaround. */
2538 int fix_erratum_843419_adr
;
2540 /* Don't apply link-time values for dynamic relocations. */
2541 int no_apply_dynamic_relocs
;
2543 /* The number of bytes in the initial entry in the PLT. */
2544 bfd_size_type plt_header_size
;
2546 /* The number of bytes in the subsequent PLT etries. */
2547 bfd_size_type plt_entry_size
;
2549 /* Small local sym cache. */
2550 struct sym_cache sym_cache
;
2552 /* For convenience in allocate_dynrelocs. */
2555 /* The amount of space used by the reserved portion of the sgotplt
2556 section, plus whatever space is used by the jump slots. */
2557 bfd_vma sgotplt_jump_table_size
;
2559 /* The stub hash table. */
2560 struct bfd_hash_table stub_hash_table
;
2562 /* Linker stub bfd. */
2565 /* Linker call-backs. */
2566 asection
*(*add_stub_section
) (const char *, asection
*);
2567 void (*layout_sections_again
) (void);
2569 /* Array to keep track of which stub sections have been created, and
2570 information on stub grouping. */
2573 /* This is the section to which stubs in the group will be
2576 /* The stub section. */
2580 /* Assorted information used by elfNN_aarch64_size_stubs. */
2581 unsigned int bfd_count
;
2582 unsigned int top_index
;
2583 asection
**input_list
;
2585 /* The offset into splt of the PLT entry for the TLS descriptor
2586 resolver. Special values are 0, if not necessary (or not found
2587 to be necessary yet), and -1 if needed but not determined
2589 bfd_vma tlsdesc_plt
;
2591 /* The GOT offset for the lazy trampoline. Communicated to the
2592 loader via DT_TLSDESC_GOT. The magic value (bfd_vma) -1
2593 indicates an offset is not allocated. */
2594 bfd_vma dt_tlsdesc_got
;
2596 /* Used by local STT_GNU_IFUNC symbols. */
2597 htab_t loc_hash_table
;
2598 void * loc_hash_memory
;
2601 /* Create an entry in an AArch64 ELF linker hash table. */
2603 static struct bfd_hash_entry
*
2604 elfNN_aarch64_link_hash_newfunc (struct bfd_hash_entry
*entry
,
2605 struct bfd_hash_table
*table
,
2608 struct elf_aarch64_link_hash_entry
*ret
=
2609 (struct elf_aarch64_link_hash_entry
*) entry
;
2611 /* Allocate the structure if it has not already been allocated by a
2614 ret
= bfd_hash_allocate (table
,
2615 sizeof (struct elf_aarch64_link_hash_entry
));
2617 return (struct bfd_hash_entry
*) ret
;
2619 /* Call the allocation method of the superclass. */
2620 ret
= ((struct elf_aarch64_link_hash_entry
*)
2621 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry
*) ret
,
2625 ret
->dyn_relocs
= NULL
;
2626 ret
->got_type
= GOT_UNKNOWN
;
2627 ret
->plt_got_offset
= (bfd_vma
) - 1;
2628 ret
->stub_cache
= NULL
;
2629 ret
->tlsdesc_got_jump_table_offset
= (bfd_vma
) - 1;
2632 return (struct bfd_hash_entry
*) ret
;
2635 /* Initialize an entry in the stub hash table. */
2637 static struct bfd_hash_entry
*
2638 stub_hash_newfunc (struct bfd_hash_entry
*entry
,
2639 struct bfd_hash_table
*table
, const char *string
)
2641 /* Allocate the structure if it has not already been allocated by a
2645 entry
= bfd_hash_allocate (table
,
2647 elf_aarch64_stub_hash_entry
));
2652 /* Call the allocation method of the superclass. */
2653 entry
= bfd_hash_newfunc (entry
, table
, string
);
2656 struct elf_aarch64_stub_hash_entry
*eh
;
2658 /* Initialize the local fields. */
2659 eh
= (struct elf_aarch64_stub_hash_entry
*) entry
;
2660 eh
->adrp_offset
= 0;
2661 eh
->stub_sec
= NULL
;
2662 eh
->stub_offset
= 0;
2663 eh
->target_value
= 0;
2664 eh
->target_section
= NULL
;
2665 eh
->stub_type
= aarch64_stub_none
;
2673 /* Compute a hash of a local hash entry. We use elf_link_hash_entry
2674 for local symbol so that we can handle local STT_GNU_IFUNC symbols
2675 as global symbol. We reuse indx and dynstr_index for local symbol
2676 hash since they aren't used by global symbols in this backend. */
2679 elfNN_aarch64_local_htab_hash (const void *ptr
)
2681 struct elf_link_hash_entry
*h
2682 = (struct elf_link_hash_entry
*) ptr
;
2683 return ELF_LOCAL_SYMBOL_HASH (h
->indx
, h
->dynstr_index
);
2686 /* Compare local hash entries. */
2689 elfNN_aarch64_local_htab_eq (const void *ptr1
, const void *ptr2
)
2691 struct elf_link_hash_entry
*h1
2692 = (struct elf_link_hash_entry
*) ptr1
;
2693 struct elf_link_hash_entry
*h2
2694 = (struct elf_link_hash_entry
*) ptr2
;
2696 return h1
->indx
== h2
->indx
&& h1
->dynstr_index
== h2
->dynstr_index
;
2699 /* Find and/or create a hash entry for local symbol. */
2701 static struct elf_link_hash_entry
*
2702 elfNN_aarch64_get_local_sym_hash (struct elf_aarch64_link_hash_table
*htab
,
2703 bfd
*abfd
, const Elf_Internal_Rela
*rel
,
2706 struct elf_aarch64_link_hash_entry e
, *ret
;
2707 asection
*sec
= abfd
->sections
;
2708 hashval_t h
= ELF_LOCAL_SYMBOL_HASH (sec
->id
,
2709 ELFNN_R_SYM (rel
->r_info
));
2712 e
.root
.indx
= sec
->id
;
2713 e
.root
.dynstr_index
= ELFNN_R_SYM (rel
->r_info
);
2714 slot
= htab_find_slot_with_hash (htab
->loc_hash_table
, &e
, h
,
2715 create
? INSERT
: NO_INSERT
);
2722 ret
= (struct elf_aarch64_link_hash_entry
*) *slot
;
2726 ret
= (struct elf_aarch64_link_hash_entry
*)
2727 objalloc_alloc ((struct objalloc
*) htab
->loc_hash_memory
,
2728 sizeof (struct elf_aarch64_link_hash_entry
));
2731 memset (ret
, 0, sizeof (*ret
));
2732 ret
->root
.indx
= sec
->id
;
2733 ret
->root
.dynstr_index
= ELFNN_R_SYM (rel
->r_info
);
2734 ret
->root
.dynindx
= -1;
2740 /* Copy the extra info we tack onto an elf_link_hash_entry. */
2743 elfNN_aarch64_copy_indirect_symbol (struct bfd_link_info
*info
,
2744 struct elf_link_hash_entry
*dir
,
2745 struct elf_link_hash_entry
*ind
)
2747 struct elf_aarch64_link_hash_entry
*edir
, *eind
;
2749 edir
= (struct elf_aarch64_link_hash_entry
*) dir
;
2750 eind
= (struct elf_aarch64_link_hash_entry
*) ind
;
2752 if (eind
->dyn_relocs
!= NULL
)
2754 if (edir
->dyn_relocs
!= NULL
)
2756 struct elf_dyn_relocs
**pp
;
2757 struct elf_dyn_relocs
*p
;
2759 /* Add reloc counts against the indirect sym to the direct sym
2760 list. Merge any entries against the same section. */
2761 for (pp
= &eind
->dyn_relocs
; (p
= *pp
) != NULL
;)
2763 struct elf_dyn_relocs
*q
;
2765 for (q
= edir
->dyn_relocs
; q
!= NULL
; q
= q
->next
)
2766 if (q
->sec
== p
->sec
)
2768 q
->pc_count
+= p
->pc_count
;
2769 q
->count
+= p
->count
;
2776 *pp
= edir
->dyn_relocs
;
2779 edir
->dyn_relocs
= eind
->dyn_relocs
;
2780 eind
->dyn_relocs
= NULL
;
2783 if (ind
->root
.type
== bfd_link_hash_indirect
)
2785 /* Copy over PLT info. */
2786 if (dir
->got
.refcount
<= 0)
2788 edir
->got_type
= eind
->got_type
;
2789 eind
->got_type
= GOT_UNKNOWN
;
2793 _bfd_elf_link_hash_copy_indirect (info
, dir
, ind
);
2796 /* Destroy an AArch64 elf linker hash table. */
2799 elfNN_aarch64_link_hash_table_free (bfd
*obfd
)
2801 struct elf_aarch64_link_hash_table
*ret
2802 = (struct elf_aarch64_link_hash_table
*) obfd
->link
.hash
;
2804 if (ret
->loc_hash_table
)
2805 htab_delete (ret
->loc_hash_table
);
2806 if (ret
->loc_hash_memory
)
2807 objalloc_free ((struct objalloc
*) ret
->loc_hash_memory
);
2809 bfd_hash_table_free (&ret
->stub_hash_table
);
2810 _bfd_elf_link_hash_table_free (obfd
);
2813 /* Create an AArch64 elf linker hash table. */
2815 static struct bfd_link_hash_table
*
2816 elfNN_aarch64_link_hash_table_create (bfd
*abfd
)
2818 struct elf_aarch64_link_hash_table
*ret
;
2819 bfd_size_type amt
= sizeof (struct elf_aarch64_link_hash_table
);
2821 ret
= bfd_zmalloc (amt
);
2825 if (!_bfd_elf_link_hash_table_init
2826 (&ret
->root
, abfd
, elfNN_aarch64_link_hash_newfunc
,
2827 sizeof (struct elf_aarch64_link_hash_entry
), AARCH64_ELF_DATA
))
2833 ret
->plt_header_size
= PLT_ENTRY_SIZE
;
2834 ret
->plt_entry_size
= PLT_SMALL_ENTRY_SIZE
;
2836 ret
->dt_tlsdesc_got
= (bfd_vma
) - 1;
2838 if (!bfd_hash_table_init (&ret
->stub_hash_table
, stub_hash_newfunc
,
2839 sizeof (struct elf_aarch64_stub_hash_entry
)))
2841 _bfd_elf_link_hash_table_free (abfd
);
2845 ret
->loc_hash_table
= htab_try_create (1024,
2846 elfNN_aarch64_local_htab_hash
,
2847 elfNN_aarch64_local_htab_eq
,
2849 ret
->loc_hash_memory
= objalloc_create ();
2850 if (!ret
->loc_hash_table
|| !ret
->loc_hash_memory
)
2852 elfNN_aarch64_link_hash_table_free (abfd
);
2855 ret
->root
.root
.hash_table_free
= elfNN_aarch64_link_hash_table_free
;
2857 return &ret
->root
.root
;
2860 /* Perform relocation R_TYPE. Returns TRUE upon success, FALSE otherwise. */
2863 aarch64_relocate (unsigned int r_type
, bfd
*input_bfd
, asection
*input_section
,
2864 bfd_vma offset
, bfd_vma value
)
2866 reloc_howto_type
*howto
;
2869 howto
= elfNN_aarch64_howto_from_type (input_bfd
, r_type
);
2870 place
= (input_section
->output_section
->vma
+ input_section
->output_offset
2873 r_type
= elfNN_aarch64_bfd_reloc_from_type (input_bfd
, r_type
);
2874 value
= _bfd_aarch64_elf_resolve_relocation (r_type
, place
, value
, 0, FALSE
);
2875 return _bfd_aarch64_elf_put_addend (input_bfd
,
2876 input_section
->contents
+ offset
, r_type
,
2877 howto
, value
) == bfd_reloc_ok
;
2880 static enum elf_aarch64_stub_type
2881 aarch64_select_branch_stub (bfd_vma value
, bfd_vma place
)
2883 if (aarch64_valid_for_adrp_p (value
, place
))
2884 return aarch64_stub_adrp_branch
;
2885 return aarch64_stub_long_branch
;
2888 /* Determine the type of stub needed, if any, for a call. */
2890 static enum elf_aarch64_stub_type
2891 aarch64_type_of_stub (asection
*input_sec
,
2892 const Elf_Internal_Rela
*rel
,
2894 unsigned char st_type
,
2895 bfd_vma destination
)
2898 bfd_signed_vma branch_offset
;
2899 unsigned int r_type
;
2900 enum elf_aarch64_stub_type stub_type
= aarch64_stub_none
;
2902 if (st_type
!= STT_FUNC
2903 && (sym_sec
== input_sec
))
2906 /* Determine where the call point is. */
2907 location
= (input_sec
->output_offset
2908 + input_sec
->output_section
->vma
+ rel
->r_offset
);
2910 branch_offset
= (bfd_signed_vma
) (destination
- location
);
2912 r_type
= ELFNN_R_TYPE (rel
->r_info
);
2914 /* We don't want to redirect any old unconditional jump in this way,
2915 only one which is being used for a sibcall, where it is
2916 acceptable for the IP0 and IP1 registers to be clobbered. */
2917 if ((r_type
== AARCH64_R (CALL26
) || r_type
== AARCH64_R (JUMP26
))
2918 && (branch_offset
> AARCH64_MAX_FWD_BRANCH_OFFSET
2919 || branch_offset
< AARCH64_MAX_BWD_BRANCH_OFFSET
))
2921 stub_type
= aarch64_stub_long_branch
;
2927 /* Build a name for an entry in the stub hash table. */
2930 elfNN_aarch64_stub_name (const asection
*input_section
,
2931 const asection
*sym_sec
,
2932 const struct elf_aarch64_link_hash_entry
*hash
,
2933 const Elf_Internal_Rela
*rel
)
2940 len
= 8 + 1 + strlen (hash
->root
.root
.root
.string
) + 1 + 16 + 1;
2941 stub_name
= bfd_malloc (len
);
2942 if (stub_name
!= NULL
)
2943 snprintf (stub_name
, len
, "%08x_%s+%" BFD_VMA_FMT
"x",
2944 (unsigned int) input_section
->id
,
2945 hash
->root
.root
.root
.string
,
2950 len
= 8 + 1 + 8 + 1 + 8 + 1 + 16 + 1;
2951 stub_name
= bfd_malloc (len
);
2952 if (stub_name
!= NULL
)
2953 snprintf (stub_name
, len
, "%08x_%x:%x+%" BFD_VMA_FMT
"x",
2954 (unsigned int) input_section
->id
,
2955 (unsigned int) sym_sec
->id
,
2956 (unsigned int) ELFNN_R_SYM (rel
->r_info
),
2963 /* Return TRUE if symbol H should be hashed in the `.gnu.hash' section. For
2964 executable PLT slots where the executable never takes the address of those
2965 functions, the function symbols are not added to the hash table. */
2968 elf_aarch64_hash_symbol (struct elf_link_hash_entry
*h
)
2970 if (h
->plt
.offset
!= (bfd_vma
) -1
2972 && !h
->pointer_equality_needed
)
2975 return _bfd_elf_hash_symbol (h
);
2979 /* Look up an entry in the stub hash. Stub entries are cached because
2980 creating the stub name takes a bit of time. */
2982 static struct elf_aarch64_stub_hash_entry
*
2983 elfNN_aarch64_get_stub_entry (const asection
*input_section
,
2984 const asection
*sym_sec
,
2985 struct elf_link_hash_entry
*hash
,
2986 const Elf_Internal_Rela
*rel
,
2987 struct elf_aarch64_link_hash_table
*htab
)
2989 struct elf_aarch64_stub_hash_entry
*stub_entry
;
2990 struct elf_aarch64_link_hash_entry
*h
=
2991 (struct elf_aarch64_link_hash_entry
*) hash
;
2992 const asection
*id_sec
;
2994 if ((input_section
->flags
& SEC_CODE
) == 0)
2997 /* If this input section is part of a group of sections sharing one
2998 stub section, then use the id of the first section in the group.
2999 Stub names need to include a section id, as there may well be
3000 more than one stub used to reach say, printf, and we need to
3001 distinguish between them. */
3002 id_sec
= htab
->stub_group
[input_section
->id
].link_sec
;
3004 if (h
!= NULL
&& h
->stub_cache
!= NULL
3005 && h
->stub_cache
->h
== h
&& h
->stub_cache
->id_sec
== id_sec
)
3007 stub_entry
= h
->stub_cache
;
3013 stub_name
= elfNN_aarch64_stub_name (id_sec
, sym_sec
, h
, rel
);
3014 if (stub_name
== NULL
)
3017 stub_entry
= aarch64_stub_hash_lookup (&htab
->stub_hash_table
,
3018 stub_name
, FALSE
, FALSE
);
3020 h
->stub_cache
= stub_entry
;
3029 /* Create a stub section. */
3032 _bfd_aarch64_create_stub_section (asection
*section
,
3033 struct elf_aarch64_link_hash_table
*htab
)
3039 namelen
= strlen (section
->name
);
3040 len
= namelen
+ sizeof (STUB_SUFFIX
);
3041 s_name
= bfd_alloc (htab
->stub_bfd
, len
);
3045 memcpy (s_name
, section
->name
, namelen
);
3046 memcpy (s_name
+ namelen
, STUB_SUFFIX
, sizeof (STUB_SUFFIX
));
3047 return (*htab
->add_stub_section
) (s_name
, section
);
3051 /* Find or create a stub section for a link section.
3053 Fix or create the stub section used to collect stubs attached to
3054 the specified link section. */
3057 _bfd_aarch64_get_stub_for_link_section (asection
*link_section
,
3058 struct elf_aarch64_link_hash_table
*htab
)
3060 if (htab
->stub_group
[link_section
->id
].stub_sec
== NULL
)
3061 htab
->stub_group
[link_section
->id
].stub_sec
3062 = _bfd_aarch64_create_stub_section (link_section
, htab
);
3063 return htab
->stub_group
[link_section
->id
].stub_sec
;
3067 /* Find or create a stub section in the stub group for an input
3071 _bfd_aarch64_create_or_find_stub_sec (asection
*section
,
3072 struct elf_aarch64_link_hash_table
*htab
)
3074 asection
*link_sec
= htab
->stub_group
[section
->id
].link_sec
;
3075 return _bfd_aarch64_get_stub_for_link_section (link_sec
, htab
);
3079 /* Add a new stub entry in the stub group associated with an input
3080 section to the stub hash. Not all fields of the new stub entry are
3083 static struct elf_aarch64_stub_hash_entry
*
3084 _bfd_aarch64_add_stub_entry_in_group (const char *stub_name
,
3086 struct elf_aarch64_link_hash_table
*htab
)
3090 struct elf_aarch64_stub_hash_entry
*stub_entry
;
3092 link_sec
= htab
->stub_group
[section
->id
].link_sec
;
3093 stub_sec
= _bfd_aarch64_create_or_find_stub_sec (section
, htab
);
3095 /* Enter this entry into the linker stub hash table. */
3096 stub_entry
= aarch64_stub_hash_lookup (&htab
->stub_hash_table
, stub_name
,
3098 if (stub_entry
== NULL
)
3100 /* xgettext:c-format */
3101 _bfd_error_handler (_("%pB: cannot create stub entry %s"),
3102 section
->owner
, stub_name
);
3106 stub_entry
->stub_sec
= stub_sec
;
3107 stub_entry
->stub_offset
= 0;
3108 stub_entry
->id_sec
= link_sec
;
3113 /* Add a new stub entry in the final stub section to the stub hash.
3114 Not all fields of the new stub entry are initialised. */
3116 static struct elf_aarch64_stub_hash_entry
*
3117 _bfd_aarch64_add_stub_entry_after (const char *stub_name
,
3118 asection
*link_section
,
3119 struct elf_aarch64_link_hash_table
*htab
)
3122 struct elf_aarch64_stub_hash_entry
*stub_entry
;
3124 stub_sec
= _bfd_aarch64_get_stub_for_link_section (link_section
, htab
);
3125 stub_entry
= aarch64_stub_hash_lookup (&htab
->stub_hash_table
, stub_name
,
3127 if (stub_entry
== NULL
)
3129 _bfd_error_handler (_("cannot create stub entry %s"), stub_name
);
3133 stub_entry
->stub_sec
= stub_sec
;
3134 stub_entry
->stub_offset
= 0;
3135 stub_entry
->id_sec
= link_section
;
3142 aarch64_build_one_stub (struct bfd_hash_entry
*gen_entry
,
3143 void *in_arg ATTRIBUTE_UNUSED
)
3145 struct elf_aarch64_stub_hash_entry
*stub_entry
;
3150 bfd_vma veneered_insn_loc
;
3151 bfd_vma veneer_entry_loc
;
3152 bfd_signed_vma branch_offset
= 0;
3153 unsigned int template_size
;
3154 const uint32_t *template;
3157 /* Massage our args to the form they really have. */
3158 stub_entry
= (struct elf_aarch64_stub_hash_entry
*) gen_entry
;
3160 stub_sec
= stub_entry
->stub_sec
;
3162 /* Make a note of the offset within the stubs for this entry. */
3163 stub_entry
->stub_offset
= stub_sec
->size
;
3164 loc
= stub_sec
->contents
+ stub_entry
->stub_offset
;
3166 stub_bfd
= stub_sec
->owner
;
3168 /* This is the address of the stub destination. */
3169 sym_value
= (stub_entry
->target_value
3170 + stub_entry
->target_section
->output_offset
3171 + stub_entry
->target_section
->output_section
->vma
);
3173 if (stub_entry
->stub_type
== aarch64_stub_long_branch
)
3175 bfd_vma place
= (stub_entry
->stub_offset
+ stub_sec
->output_section
->vma
3176 + stub_sec
->output_offset
);
3178 /* See if we can relax the stub. */
3179 if (aarch64_valid_for_adrp_p (sym_value
, place
))
3180 stub_entry
->stub_type
= aarch64_select_branch_stub (sym_value
, place
);
3183 switch (stub_entry
->stub_type
)
3185 case aarch64_stub_adrp_branch
:
3186 template = aarch64_adrp_branch_stub
;
3187 template_size
= sizeof (aarch64_adrp_branch_stub
);
3189 case aarch64_stub_long_branch
:
3190 template = aarch64_long_branch_stub
;
3191 template_size
= sizeof (aarch64_long_branch_stub
);
3193 case aarch64_stub_erratum_835769_veneer
:
3194 template = aarch64_erratum_835769_stub
;
3195 template_size
= sizeof (aarch64_erratum_835769_stub
);
3197 case aarch64_stub_erratum_843419_veneer
:
3198 template = aarch64_erratum_843419_stub
;
3199 template_size
= sizeof (aarch64_erratum_843419_stub
);
3205 for (i
= 0; i
< (template_size
/ sizeof template[0]); i
++)
3207 bfd_putl32 (template[i
], loc
);
3211 template_size
= (template_size
+ 7) & ~7;
3212 stub_sec
->size
+= template_size
;
3214 switch (stub_entry
->stub_type
)
3216 case aarch64_stub_adrp_branch
:
3217 if (!aarch64_relocate (AARCH64_R (ADR_PREL_PG_HI21
), stub_bfd
, stub_sec
,
3218 stub_entry
->stub_offset
, sym_value
))
3219 /* The stub would not have been relaxed if the offset was out
3223 if (!aarch64_relocate (AARCH64_R (ADD_ABS_LO12_NC
), stub_bfd
, stub_sec
,
3224 stub_entry
->stub_offset
+ 4, sym_value
))
3228 case aarch64_stub_long_branch
:
3229 /* We want the value relative to the address 12 bytes back from the
3231 if (!aarch64_relocate (AARCH64_R (PRELNN
), stub_bfd
, stub_sec
,
3232 stub_entry
->stub_offset
+ 16, sym_value
+ 12))
3236 case aarch64_stub_erratum_835769_veneer
:
3237 veneered_insn_loc
= stub_entry
->target_section
->output_section
->vma
3238 + stub_entry
->target_section
->output_offset
3239 + stub_entry
->target_value
;
3240 veneer_entry_loc
= stub_entry
->stub_sec
->output_section
->vma
3241 + stub_entry
->stub_sec
->output_offset
3242 + stub_entry
->stub_offset
;
3243 branch_offset
= veneered_insn_loc
- veneer_entry_loc
;
3244 branch_offset
>>= 2;
3245 branch_offset
&= 0x3ffffff;
3246 bfd_putl32 (stub_entry
->veneered_insn
,
3247 stub_sec
->contents
+ stub_entry
->stub_offset
);
3248 bfd_putl32 (template[1] | branch_offset
,
3249 stub_sec
->contents
+ stub_entry
->stub_offset
+ 4);
3252 case aarch64_stub_erratum_843419_veneer
:
3253 if (!aarch64_relocate (AARCH64_R (JUMP26
), stub_bfd
, stub_sec
,
3254 stub_entry
->stub_offset
+ 4, sym_value
+ 4))
3265 /* As above, but don't actually build the stub. Just bump offset so
3266 we know stub section sizes. */
3269 aarch64_size_one_stub (struct bfd_hash_entry
*gen_entry
,
3270 void *in_arg ATTRIBUTE_UNUSED
)
3272 struct elf_aarch64_stub_hash_entry
*stub_entry
;
3275 /* Massage our args to the form they really have. */
3276 stub_entry
= (struct elf_aarch64_stub_hash_entry
*) gen_entry
;
3278 switch (stub_entry
->stub_type
)
3280 case aarch64_stub_adrp_branch
:
3281 size
= sizeof (aarch64_adrp_branch_stub
);
3283 case aarch64_stub_long_branch
:
3284 size
= sizeof (aarch64_long_branch_stub
);
3286 case aarch64_stub_erratum_835769_veneer
:
3287 size
= sizeof (aarch64_erratum_835769_stub
);
3289 case aarch64_stub_erratum_843419_veneer
:
3290 size
= sizeof (aarch64_erratum_843419_stub
);
3296 size
= (size
+ 7) & ~7;
3297 stub_entry
->stub_sec
->size
+= size
;
3301 /* External entry points for sizing and building linker stubs. */
3303 /* Set up various things so that we can make a list of input sections
3304 for each output section included in the link. Returns -1 on error,
3305 0 when no stubs will be needed, and 1 on success. */
3308 elfNN_aarch64_setup_section_lists (bfd
*output_bfd
,
3309 struct bfd_link_info
*info
)
3312 unsigned int bfd_count
;
3313 unsigned int top_id
, top_index
;
3315 asection
**input_list
, **list
;
3317 struct elf_aarch64_link_hash_table
*htab
=
3318 elf_aarch64_hash_table (info
);
3320 if (!is_elf_hash_table (htab
))
3323 /* Count the number of input BFDs and find the top input section id. */
3324 for (input_bfd
= info
->input_bfds
, bfd_count
= 0, top_id
= 0;
3325 input_bfd
!= NULL
; input_bfd
= input_bfd
->link
.next
)
3328 for (section
= input_bfd
->sections
;
3329 section
!= NULL
; section
= section
->next
)
3331 if (top_id
< section
->id
)
3332 top_id
= section
->id
;
3335 htab
->bfd_count
= bfd_count
;
3337 amt
= sizeof (struct map_stub
) * (top_id
+ 1);
3338 htab
->stub_group
= bfd_zmalloc (amt
);
3339 if (htab
->stub_group
== NULL
)
3342 /* We can't use output_bfd->section_count here to find the top output
3343 section index as some sections may have been removed, and
3344 _bfd_strip_section_from_output doesn't renumber the indices. */
3345 for (section
= output_bfd
->sections
, top_index
= 0;
3346 section
!= NULL
; section
= section
->next
)
3348 if (top_index
< section
->index
)
3349 top_index
= section
->index
;
3352 htab
->top_index
= top_index
;
3353 amt
= sizeof (asection
*) * (top_index
+ 1);
3354 input_list
= bfd_malloc (amt
);
3355 htab
->input_list
= input_list
;
3356 if (input_list
== NULL
)
3359 /* For sections we aren't interested in, mark their entries with a
3360 value we can check later. */
3361 list
= input_list
+ top_index
;
3363 *list
= bfd_abs_section_ptr
;
3364 while (list
-- != input_list
);
3366 for (section
= output_bfd
->sections
;
3367 section
!= NULL
; section
= section
->next
)
3369 if ((section
->flags
& SEC_CODE
) != 0)
3370 input_list
[section
->index
] = NULL
;
3376 /* Used by elfNN_aarch64_next_input_section and group_sections. */
3377 #define PREV_SEC(sec) (htab->stub_group[(sec)->id].link_sec)
3379 /* The linker repeatedly calls this function for each input section,
3380 in the order that input sections are linked into output sections.
3381 Build lists of input sections to determine groupings between which
3382 we may insert linker stubs. */
3385 elfNN_aarch64_next_input_section (struct bfd_link_info
*info
, asection
*isec
)
3387 struct elf_aarch64_link_hash_table
*htab
=
3388 elf_aarch64_hash_table (info
);
3390 if (isec
->output_section
->index
<= htab
->top_index
)
3392 asection
**list
= htab
->input_list
+ isec
->output_section
->index
;
3394 if (*list
!= bfd_abs_section_ptr
)
3396 /* Steal the link_sec pointer for our list. */
3397 /* This happens to make the list in reverse order,
3398 which is what we want. */
3399 PREV_SEC (isec
) = *list
;
3405 /* See whether we can group stub sections together. Grouping stub
3406 sections may result in fewer stubs. More importantly, we need to
3407 put all .init* and .fini* stubs at the beginning of the .init or
3408 .fini output sections respectively, because glibc splits the
3409 _init and _fini functions into multiple parts. Putting a stub in
3410 the middle of a function is not a good idea. */
3413 group_sections (struct elf_aarch64_link_hash_table
*htab
,
3414 bfd_size_type stub_group_size
,
3415 bfd_boolean stubs_always_before_branch
)
3417 asection
**list
= htab
->input_list
+ htab
->top_index
;
3421 asection
*tail
= *list
;
3423 if (tail
== bfd_abs_section_ptr
)
3426 while (tail
!= NULL
)
3430 bfd_size_type total
;
3434 while ((prev
= PREV_SEC (curr
)) != NULL
3435 && ((total
+= curr
->output_offset
- prev
->output_offset
)
3439 /* OK, the size from the start of CURR to the end is less
3440 than stub_group_size and thus can be handled by one stub
3441 section. (Or the tail section is itself larger than
3442 stub_group_size, in which case we may be toast.)
3443 We should really be keeping track of the total size of
3444 stubs added here, as stubs contribute to the final output
3448 prev
= PREV_SEC (tail
);
3449 /* Set up this stub group. */
3450 htab
->stub_group
[tail
->id
].link_sec
= curr
;
3452 while (tail
!= curr
&& (tail
= prev
) != NULL
);
3454 /* But wait, there's more! Input sections up to stub_group_size
3455 bytes before the stub section can be handled by it too. */
3456 if (!stubs_always_before_branch
)
3460 && ((total
+= tail
->output_offset
- prev
->output_offset
)
3464 prev
= PREV_SEC (tail
);
3465 htab
->stub_group
[tail
->id
].link_sec
= curr
;
3471 while (list
-- != htab
->input_list
);
3473 free (htab
->input_list
);
3478 #define AARCH64_BITS(x, pos, n) (((x) >> (pos)) & ((1 << (n)) - 1))
3480 #define AARCH64_RT(insn) AARCH64_BITS (insn, 0, 5)
3481 #define AARCH64_RT2(insn) AARCH64_BITS (insn, 10, 5)
3482 #define AARCH64_RA(insn) AARCH64_BITS (insn, 10, 5)
3483 #define AARCH64_RD(insn) AARCH64_BITS (insn, 0, 5)
3484 #define AARCH64_RN(insn) AARCH64_BITS (insn, 5, 5)
3485 #define AARCH64_RM(insn) AARCH64_BITS (insn, 16, 5)
3487 #define AARCH64_MAC(insn) (((insn) & 0xff000000) == 0x9b000000)
3488 #define AARCH64_BIT(insn, n) AARCH64_BITS (insn, n, 1)
3489 #define AARCH64_OP31(insn) AARCH64_BITS (insn, 21, 3)
3490 #define AARCH64_ZR 0x1f
3492 /* All ld/st ops. See C4-182 of the ARM ARM. The encoding space for
3493 LD_PCREL, LDST_RO, LDST_UI and LDST_UIMM cover prefetch ops. */
3495 #define AARCH64_LD(insn) (AARCH64_BIT (insn, 22) == 1)
3496 #define AARCH64_LDST(insn) (((insn) & 0x0a000000) == 0x08000000)
3497 #define AARCH64_LDST_EX(insn) (((insn) & 0x3f000000) == 0x08000000)
3498 #define AARCH64_LDST_PCREL(insn) (((insn) & 0x3b000000) == 0x18000000)
3499 #define AARCH64_LDST_NAP(insn) (((insn) & 0x3b800000) == 0x28000000)
3500 #define AARCH64_LDSTP_PI(insn) (((insn) & 0x3b800000) == 0x28800000)
3501 #define AARCH64_LDSTP_O(insn) (((insn) & 0x3b800000) == 0x29000000)
3502 #define AARCH64_LDSTP_PRE(insn) (((insn) & 0x3b800000) == 0x29800000)
3503 #define AARCH64_LDST_UI(insn) (((insn) & 0x3b200c00) == 0x38000000)
3504 #define AARCH64_LDST_PIIMM(insn) (((insn) & 0x3b200c00) == 0x38000400)
3505 #define AARCH64_LDST_U(insn) (((insn) & 0x3b200c00) == 0x38000800)
3506 #define AARCH64_LDST_PREIMM(insn) (((insn) & 0x3b200c00) == 0x38000c00)
3507 #define AARCH64_LDST_RO(insn) (((insn) & 0x3b200c00) == 0x38200800)
3508 #define AARCH64_LDST_UIMM(insn) (((insn) & 0x3b000000) == 0x39000000)
3509 #define AARCH64_LDST_SIMD_M(insn) (((insn) & 0xbfbf0000) == 0x0c000000)
3510 #define AARCH64_LDST_SIMD_M_PI(insn) (((insn) & 0xbfa00000) == 0x0c800000)
3511 #define AARCH64_LDST_SIMD_S(insn) (((insn) & 0xbf9f0000) == 0x0d000000)
3512 #define AARCH64_LDST_SIMD_S_PI(insn) (((insn) & 0xbf800000) == 0x0d800000)
3514 /* Classify an INSN if it is indeed a load/store.
3516 Return TRUE if INSN is a LD/ST instruction otherwise return FALSE.
3518 For scalar LD/ST instructions PAIR is FALSE, RT is returned and RT2
3521 For LD/ST pair instructions PAIR is TRUE, RT and RT2 are returned. */
3524 aarch64_mem_op_p (uint32_t insn
, unsigned int *rt
, unsigned int *rt2
,
3525 bfd_boolean
*pair
, bfd_boolean
*load
)
3533 /* Bail out quickly if INSN doesn't fall into the load-store
3535 if (!AARCH64_LDST (insn
))
3540 if (AARCH64_LDST_EX (insn
))
3542 *rt
= AARCH64_RT (insn
);
3544 if (AARCH64_BIT (insn
, 21) == 1)
3547 *rt2
= AARCH64_RT2 (insn
);
3549 *load
= AARCH64_LD (insn
);
3552 else if (AARCH64_LDST_NAP (insn
)
3553 || AARCH64_LDSTP_PI (insn
)
3554 || AARCH64_LDSTP_O (insn
)
3555 || AARCH64_LDSTP_PRE (insn
))
3558 *rt
= AARCH64_RT (insn
);
3559 *rt2
= AARCH64_RT2 (insn
);
3560 *load
= AARCH64_LD (insn
);
3563 else if (AARCH64_LDST_PCREL (insn
)
3564 || AARCH64_LDST_UI (insn
)
3565 || AARCH64_LDST_PIIMM (insn
)
3566 || AARCH64_LDST_U (insn
)
3567 || AARCH64_LDST_PREIMM (insn
)
3568 || AARCH64_LDST_RO (insn
)
3569 || AARCH64_LDST_UIMM (insn
))
3571 *rt
= AARCH64_RT (insn
);
3573 if (AARCH64_LDST_PCREL (insn
))
3575 opc
= AARCH64_BITS (insn
, 22, 2);
3576 v
= AARCH64_BIT (insn
, 26);
3577 opc_v
= opc
| (v
<< 2);
3578 *load
= (opc_v
== 1 || opc_v
== 2 || opc_v
== 3
3579 || opc_v
== 5 || opc_v
== 7);
3582 else if (AARCH64_LDST_SIMD_M (insn
)
3583 || AARCH64_LDST_SIMD_M_PI (insn
))
3585 *rt
= AARCH64_RT (insn
);
3586 *load
= AARCH64_BIT (insn
, 22);
3587 opcode
= (insn
>> 12) & 0xf;
3614 else if (AARCH64_LDST_SIMD_S (insn
)
3615 || AARCH64_LDST_SIMD_S_PI (insn
))
3617 *rt
= AARCH64_RT (insn
);
3618 r
= (insn
>> 21) & 1;
3619 *load
= AARCH64_BIT (insn
, 22);
3620 opcode
= (insn
>> 13) & 0x7;
3632 *rt2
= *rt
+ (r
== 0 ? 2 : 3);
3640 *rt2
= *rt
+ (r
== 0 ? 2 : 3);
3652 /* Return TRUE if INSN is multiply-accumulate. */
3655 aarch64_mlxl_p (uint32_t insn
)
3657 uint32_t op31
= AARCH64_OP31 (insn
);
3659 if (AARCH64_MAC (insn
)
3660 && (op31
== 0 || op31
== 1 || op31
== 5)
3661 /* Exclude MUL instructions which are encoded as a multiple accumulate
3663 && AARCH64_RA (insn
) != AARCH64_ZR
)
3669 /* Some early revisions of the Cortex-A53 have an erratum (835769) whereby
3670 it is possible for a 64-bit multiply-accumulate instruction to generate an
3671 incorrect result. The details are quite complex and hard to
3672 determine statically, since branches in the code may exist in some
3673 circumstances, but all cases end with a memory (load, store, or
3674 prefetch) instruction followed immediately by the multiply-accumulate
3675 operation. We employ a linker patching technique, by moving the potentially
3676 affected multiply-accumulate instruction into a patch region and replacing
3677 the original instruction with a branch to the patch. This function checks
3678 if INSN_1 is the memory operation followed by a multiply-accumulate
3679 operation (INSN_2). Return TRUE if an erratum sequence is found, FALSE
3680 if INSN_1 and INSN_2 are safe. */
3683 aarch64_erratum_sequence (uint32_t insn_1
, uint32_t insn_2
)
3693 if (aarch64_mlxl_p (insn_2
)
3694 && aarch64_mem_op_p (insn_1
, &rt
, &rt2
, &pair
, &load
))
3696 /* Any SIMD memory op is independent of the subsequent MLA
3697 by definition of the erratum. */
3698 if (AARCH64_BIT (insn_1
, 26))
3701 /* If not SIMD, check for integer memory ops and MLA relationship. */
3702 rn
= AARCH64_RN (insn_2
);
3703 ra
= AARCH64_RA (insn_2
);
3704 rm
= AARCH64_RM (insn_2
);
3706 /* If this is a load and there's a true(RAW) dependency, we are safe
3707 and this is not an erratum sequence. */
3709 (rt
== rn
|| rt
== rm
|| rt
== ra
3710 || (pair
&& (rt2
== rn
|| rt2
== rm
|| rt2
== ra
))))
3713 /* We conservatively put out stubs for all other cases (including
3721 /* Used to order a list of mapping symbols by address. */
3724 elf_aarch64_compare_mapping (const void *a
, const void *b
)
3726 const elf_aarch64_section_map
*amap
= (const elf_aarch64_section_map
*) a
;
3727 const elf_aarch64_section_map
*bmap
= (const elf_aarch64_section_map
*) b
;
3729 if (amap
->vma
> bmap
->vma
)
3731 else if (amap
->vma
< bmap
->vma
)
3733 else if (amap
->type
> bmap
->type
)
3734 /* Ensure results do not depend on the host qsort for objects with
3735 multiple mapping symbols at the same address by sorting on type
3738 else if (amap
->type
< bmap
->type
)
3746 _bfd_aarch64_erratum_835769_stub_name (unsigned num_fixes
)
3748 char *stub_name
= (char *) bfd_malloc
3749 (strlen ("__erratum_835769_veneer_") + 16);
3750 if (stub_name
!= NULL
)
3751 sprintf (stub_name
,"__erratum_835769_veneer_%d", num_fixes
);
3755 /* Scan for Cortex-A53 erratum 835769 sequence.
3757 Return TRUE else FALSE on abnormal termination. */
3760 _bfd_aarch64_erratum_835769_scan (bfd
*input_bfd
,
3761 struct bfd_link_info
*info
,
3762 unsigned int *num_fixes_p
)
3765 struct elf_aarch64_link_hash_table
*htab
= elf_aarch64_hash_table (info
);
3766 unsigned int num_fixes
= *num_fixes_p
;
3771 for (section
= input_bfd
->sections
;
3773 section
= section
->next
)
3775 bfd_byte
*contents
= NULL
;
3776 struct _aarch64_elf_section_data
*sec_data
;
3779 if (elf_section_type (section
) != SHT_PROGBITS
3780 || (elf_section_flags (section
) & SHF_EXECINSTR
) == 0
3781 || (section
->flags
& SEC_EXCLUDE
) != 0
3782 || (section
->sec_info_type
== SEC_INFO_TYPE_JUST_SYMS
)
3783 || (section
->output_section
== bfd_abs_section_ptr
))
3786 if (elf_section_data (section
)->this_hdr
.contents
!= NULL
)
3787 contents
= elf_section_data (section
)->this_hdr
.contents
;
3788 else if (! bfd_malloc_and_get_section (input_bfd
, section
, &contents
))
3791 sec_data
= elf_aarch64_section_data (section
);
3793 qsort (sec_data
->map
, sec_data
->mapcount
,
3794 sizeof (elf_aarch64_section_map
), elf_aarch64_compare_mapping
);
3796 for (span
= 0; span
< sec_data
->mapcount
; span
++)
3798 unsigned int span_start
= sec_data
->map
[span
].vma
;
3799 unsigned int span_end
= ((span
== sec_data
->mapcount
- 1)
3800 ? sec_data
->map
[0].vma
+ section
->size
3801 : sec_data
->map
[span
+ 1].vma
);
3803 char span_type
= sec_data
->map
[span
].type
;
3805 if (span_type
== 'd')
3808 for (i
= span_start
; i
+ 4 < span_end
; i
+= 4)
3810 uint32_t insn_1
= bfd_getl32 (contents
+ i
);
3811 uint32_t insn_2
= bfd_getl32 (contents
+ i
+ 4);
3813 if (aarch64_erratum_sequence (insn_1
, insn_2
))
3815 struct elf_aarch64_stub_hash_entry
*stub_entry
;
3816 char *stub_name
= _bfd_aarch64_erratum_835769_stub_name (num_fixes
);
3820 stub_entry
= _bfd_aarch64_add_stub_entry_in_group (stub_name
,
3826 stub_entry
->stub_type
= aarch64_stub_erratum_835769_veneer
;
3827 stub_entry
->target_section
= section
;
3828 stub_entry
->target_value
= i
+ 4;
3829 stub_entry
->veneered_insn
= insn_2
;
3830 stub_entry
->output_name
= stub_name
;
3835 if (elf_section_data (section
)->this_hdr
.contents
== NULL
)
3839 *num_fixes_p
= num_fixes
;
3845 /* Test if instruction INSN is ADRP. */
3848 _bfd_aarch64_adrp_p (uint32_t insn
)
3850 return ((insn
& AARCH64_ADRP_OP_MASK
) == AARCH64_ADRP_OP
);
3854 /* Helper predicate to look for cortex-a53 erratum 843419 sequence 1. */
3857 _bfd_aarch64_erratum_843419_sequence_p (uint32_t insn_1
, uint32_t insn_2
,
3865 return (aarch64_mem_op_p (insn_2
, &rt
, &rt2
, &pair
, &load
)
3868 && AARCH64_LDST_UIMM (insn_3
)
3869 && AARCH64_RN (insn_3
) == AARCH64_RD (insn_1
));
3873 /* Test for the presence of Cortex-A53 erratum 843419 instruction sequence.
3875 Return TRUE if section CONTENTS at offset I contains one of the
3876 erratum 843419 sequences, otherwise return FALSE. If a sequence is
3877 seen set P_VENEER_I to the offset of the final LOAD/STORE
3878 instruction in the sequence.
3882 _bfd_aarch64_erratum_843419_p (bfd_byte
*contents
, bfd_vma vma
,
3883 bfd_vma i
, bfd_vma span_end
,
3884 bfd_vma
*p_veneer_i
)
3886 uint32_t insn_1
= bfd_getl32 (contents
+ i
);
3888 if (!_bfd_aarch64_adrp_p (insn_1
))
3891 if (span_end
< i
+ 12)
3894 uint32_t insn_2
= bfd_getl32 (contents
+ i
+ 4);
3895 uint32_t insn_3
= bfd_getl32 (contents
+ i
+ 8);
3897 if ((vma
& 0xfff) != 0xff8 && (vma
& 0xfff) != 0xffc)
3900 if (_bfd_aarch64_erratum_843419_sequence_p (insn_1
, insn_2
, insn_3
))
3902 *p_veneer_i
= i
+ 8;
3906 if (span_end
< i
+ 16)
3909 uint32_t insn_4
= bfd_getl32 (contents
+ i
+ 12);
3911 if (_bfd_aarch64_erratum_843419_sequence_p (insn_1
, insn_2
, insn_4
))
3913 *p_veneer_i
= i
+ 12;
3921 /* Resize all stub sections. */
3924 _bfd_aarch64_resize_stubs (struct elf_aarch64_link_hash_table
*htab
)
3928 /* OK, we've added some stubs. Find out the new size of the
3930 for (section
= htab
->stub_bfd
->sections
;
3931 section
!= NULL
; section
= section
->next
)
3933 /* Ignore non-stub sections. */
3934 if (!strstr (section
->name
, STUB_SUFFIX
))
3939 bfd_hash_traverse (&htab
->stub_hash_table
, aarch64_size_one_stub
, htab
);
3941 for (section
= htab
->stub_bfd
->sections
;
3942 section
!= NULL
; section
= section
->next
)
3944 if (!strstr (section
->name
, STUB_SUFFIX
))
3947 /* Add space for a branch. Add 8 bytes to keep section 8 byte aligned,
3948 as long branch stubs contain a 64-bit address. */
3952 /* Ensure all stub sections have a size which is a multiple of
3953 4096. This is important in order to ensure that the insertion
3954 of stub sections does not in itself move existing code around
3955 in such a way that new errata sequences are created. */
3956 if (htab
->fix_erratum_843419
)
3958 section
->size
= BFD_ALIGN (section
->size
, 0x1000);
3962 /* Construct an erratum 843419 workaround stub name. */
3965 _bfd_aarch64_erratum_843419_stub_name (asection
*input_section
,
3968 const bfd_size_type len
= 8 + 4 + 1 + 8 + 1 + 16 + 1;
3969 char *stub_name
= bfd_malloc (len
);
3971 if (stub_name
!= NULL
)
3972 snprintf (stub_name
, len
, "e843419@%04x_%08x_%" BFD_VMA_FMT
"x",
3973 input_section
->owner
->id
,
3979 /* Build a stub_entry structure describing an 843419 fixup.
3981 The stub_entry constructed is populated with the bit pattern INSN
3982 of the instruction located at OFFSET within input SECTION.
3984 Returns TRUE on success. */
3987 _bfd_aarch64_erratum_843419_fixup (uint32_t insn
,
3988 bfd_vma adrp_offset
,
3989 bfd_vma ldst_offset
,
3991 struct bfd_link_info
*info
)
3993 struct elf_aarch64_link_hash_table
*htab
= elf_aarch64_hash_table (info
);
3995 struct elf_aarch64_stub_hash_entry
*stub_entry
;
3997 stub_name
= _bfd_aarch64_erratum_843419_stub_name (section
, ldst_offset
);
3998 if (stub_name
== NULL
)
4000 stub_entry
= aarch64_stub_hash_lookup (&htab
->stub_hash_table
, stub_name
,
4008 /* We always place an 843419 workaround veneer in the stub section
4009 attached to the input section in which an erratum sequence has
4010 been found. This ensures that later in the link process (in
4011 elfNN_aarch64_write_section) when we copy the veneered
4012 instruction from the input section into the stub section the
4013 copied instruction will have had any relocations applied to it.
4014 If we placed workaround veneers in any other stub section then we
4015 could not assume that all relocations have been processed on the
4016 corresponding input section at the point we output the stub
4019 stub_entry
= _bfd_aarch64_add_stub_entry_after (stub_name
, section
, htab
);
4020 if (stub_entry
== NULL
)
4026 stub_entry
->adrp_offset
= adrp_offset
;
4027 stub_entry
->target_value
= ldst_offset
;
4028 stub_entry
->target_section
= section
;
4029 stub_entry
->stub_type
= aarch64_stub_erratum_843419_veneer
;
4030 stub_entry
->veneered_insn
= insn
;
4031 stub_entry
->output_name
= stub_name
;
4037 /* Scan an input section looking for the signature of erratum 843419.
4039 Scans input SECTION in INPUT_BFD looking for erratum 843419
4040 signatures, for each signature found a stub_entry is created
4041 describing the location of the erratum for subsequent fixup.
4043 Return TRUE on successful scan, FALSE on failure to scan.
4047 _bfd_aarch64_erratum_843419_scan (bfd
*input_bfd
, asection
*section
,
4048 struct bfd_link_info
*info
)
4050 struct elf_aarch64_link_hash_table
*htab
= elf_aarch64_hash_table (info
);
4055 if (elf_section_type (section
) != SHT_PROGBITS
4056 || (elf_section_flags (section
) & SHF_EXECINSTR
) == 0
4057 || (section
->flags
& SEC_EXCLUDE
) != 0
4058 || (section
->sec_info_type
== SEC_INFO_TYPE_JUST_SYMS
)
4059 || (section
->output_section
== bfd_abs_section_ptr
))
4064 bfd_byte
*contents
= NULL
;
4065 struct _aarch64_elf_section_data
*sec_data
;
4068 if (elf_section_data (section
)->this_hdr
.contents
!= NULL
)
4069 contents
= elf_section_data (section
)->this_hdr
.contents
;
4070 else if (! bfd_malloc_and_get_section (input_bfd
, section
, &contents
))
4073 sec_data
= elf_aarch64_section_data (section
);
4075 qsort (sec_data
->map
, sec_data
->mapcount
,
4076 sizeof (elf_aarch64_section_map
), elf_aarch64_compare_mapping
);
4078 for (span
= 0; span
< sec_data
->mapcount
; span
++)
4080 unsigned int span_start
= sec_data
->map
[span
].vma
;
4081 unsigned int span_end
= ((span
== sec_data
->mapcount
- 1)
4082 ? sec_data
->map
[0].vma
+ section
->size
4083 : sec_data
->map
[span
+ 1].vma
);
4085 char span_type
= sec_data
->map
[span
].type
;
4087 if (span_type
== 'd')
4090 for (i
= span_start
; i
+ 8 < span_end
; i
+= 4)
4092 bfd_vma vma
= (section
->output_section
->vma
4093 + section
->output_offset
4097 if (_bfd_aarch64_erratum_843419_p
4098 (contents
, vma
, i
, span_end
, &veneer_i
))
4100 uint32_t insn
= bfd_getl32 (contents
+ veneer_i
);
4102 if (!_bfd_aarch64_erratum_843419_fixup (insn
, i
, veneer_i
,
4109 if (elf_section_data (section
)->this_hdr
.contents
== NULL
)
4118 /* Determine and set the size of the stub section for a final link.
4120 The basic idea here is to examine all the relocations looking for
4121 PC-relative calls to a target that is unreachable with a "bl"
4125 elfNN_aarch64_size_stubs (bfd
*output_bfd
,
4127 struct bfd_link_info
*info
,
4128 bfd_signed_vma group_size
,
4129 asection
* (*add_stub_section
) (const char *,
4131 void (*layout_sections_again
) (void))
4133 bfd_size_type stub_group_size
;
4134 bfd_boolean stubs_always_before_branch
;
4135 bfd_boolean stub_changed
= FALSE
;
4136 struct elf_aarch64_link_hash_table
*htab
= elf_aarch64_hash_table (info
);
4137 unsigned int num_erratum_835769_fixes
= 0;
4139 /* Propagate mach to stub bfd, because it may not have been
4140 finalized when we created stub_bfd. */
4141 bfd_set_arch_mach (stub_bfd
, bfd_get_arch (output_bfd
),
4142 bfd_get_mach (output_bfd
));
4144 /* Stash our params away. */
4145 htab
->stub_bfd
= stub_bfd
;
4146 htab
->add_stub_section
= add_stub_section
;
4147 htab
->layout_sections_again
= layout_sections_again
;
4148 stubs_always_before_branch
= group_size
< 0;
4150 stub_group_size
= -group_size
;
4152 stub_group_size
= group_size
;
4154 if (stub_group_size
== 1)
4156 /* Default values. */
4157 /* AArch64 branch range is +-128MB. The value used is 1MB less. */
4158 stub_group_size
= 127 * 1024 * 1024;
4161 group_sections (htab
, stub_group_size
, stubs_always_before_branch
);
4163 (*htab
->layout_sections_again
) ();
4165 if (htab
->fix_erratum_835769
)
4169 for (input_bfd
= info
->input_bfds
;
4170 input_bfd
!= NULL
; input_bfd
= input_bfd
->link
.next
)
4171 if (!_bfd_aarch64_erratum_835769_scan (input_bfd
, info
,
4172 &num_erratum_835769_fixes
))
4175 _bfd_aarch64_resize_stubs (htab
);
4176 (*htab
->layout_sections_again
) ();
4179 if (htab
->fix_erratum_843419
)
4183 for (input_bfd
= info
->input_bfds
;
4185 input_bfd
= input_bfd
->link
.next
)
4189 for (section
= input_bfd
->sections
;
4191 section
= section
->next
)
4192 if (!_bfd_aarch64_erratum_843419_scan (input_bfd
, section
, info
))
4196 _bfd_aarch64_resize_stubs (htab
);
4197 (*htab
->layout_sections_again
) ();
4204 for (input_bfd
= info
->input_bfds
;
4205 input_bfd
!= NULL
; input_bfd
= input_bfd
->link
.next
)
4207 Elf_Internal_Shdr
*symtab_hdr
;
4209 Elf_Internal_Sym
*local_syms
= NULL
;
4211 /* We'll need the symbol table in a second. */
4212 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
4213 if (symtab_hdr
->sh_info
== 0)
4216 /* Walk over each section attached to the input bfd. */
4217 for (section
= input_bfd
->sections
;
4218 section
!= NULL
; section
= section
->next
)
4220 Elf_Internal_Rela
*internal_relocs
, *irelaend
, *irela
;
4222 /* If there aren't any relocs, then there's nothing more
4224 if ((section
->flags
& SEC_RELOC
) == 0
4225 || section
->reloc_count
== 0
4226 || (section
->flags
& SEC_CODE
) == 0)
4229 /* If this section is a link-once section that will be
4230 discarded, then don't create any stubs. */
4231 if (section
->output_section
== NULL
4232 || section
->output_section
->owner
!= output_bfd
)
4235 /* Get the relocs. */
4237 = _bfd_elf_link_read_relocs (input_bfd
, section
, NULL
,
4238 NULL
, info
->keep_memory
);
4239 if (internal_relocs
== NULL
)
4240 goto error_ret_free_local
;
4242 /* Now examine each relocation. */
4243 irela
= internal_relocs
;
4244 irelaend
= irela
+ section
->reloc_count
;
4245 for (; irela
< irelaend
; irela
++)
4247 unsigned int r_type
, r_indx
;
4248 enum elf_aarch64_stub_type stub_type
;
4249 struct elf_aarch64_stub_hash_entry
*stub_entry
;
4252 bfd_vma destination
;
4253 struct elf_aarch64_link_hash_entry
*hash
;
4254 const char *sym_name
;
4256 const asection
*id_sec
;
4257 unsigned char st_type
;
4260 r_type
= ELFNN_R_TYPE (irela
->r_info
);
4261 r_indx
= ELFNN_R_SYM (irela
->r_info
);
4263 if (r_type
>= (unsigned int) R_AARCH64_end
)
4265 bfd_set_error (bfd_error_bad_value
);
4266 error_ret_free_internal
:
4267 if (elf_section_data (section
)->relocs
== NULL
)
4268 free (internal_relocs
);
4269 goto error_ret_free_local
;
4272 /* Only look for stubs on unconditional branch and
4273 branch and link instructions. */
4274 if (r_type
!= (unsigned int) AARCH64_R (CALL26
)
4275 && r_type
!= (unsigned int) AARCH64_R (JUMP26
))
4278 /* Now determine the call target, its name, value,
4285 if (r_indx
< symtab_hdr
->sh_info
)
4287 /* It's a local symbol. */
4288 Elf_Internal_Sym
*sym
;
4289 Elf_Internal_Shdr
*hdr
;
4291 if (local_syms
== NULL
)
4294 = (Elf_Internal_Sym
*) symtab_hdr
->contents
;
4295 if (local_syms
== NULL
)
4297 = bfd_elf_get_elf_syms (input_bfd
, symtab_hdr
,
4298 symtab_hdr
->sh_info
, 0,
4300 if (local_syms
== NULL
)
4301 goto error_ret_free_internal
;
4304 sym
= local_syms
+ r_indx
;
4305 hdr
= elf_elfsections (input_bfd
)[sym
->st_shndx
];
4306 sym_sec
= hdr
->bfd_section
;
4308 /* This is an undefined symbol. It can never
4312 if (ELF_ST_TYPE (sym
->st_info
) != STT_SECTION
)
4313 sym_value
= sym
->st_value
;
4314 destination
= (sym_value
+ irela
->r_addend
4315 + sym_sec
->output_offset
4316 + sym_sec
->output_section
->vma
);
4317 st_type
= ELF_ST_TYPE (sym
->st_info
);
4319 = bfd_elf_string_from_elf_section (input_bfd
,
4320 symtab_hdr
->sh_link
,
4327 e_indx
= r_indx
- symtab_hdr
->sh_info
;
4328 hash
= ((struct elf_aarch64_link_hash_entry
*)
4329 elf_sym_hashes (input_bfd
)[e_indx
]);
4331 while (hash
->root
.root
.type
== bfd_link_hash_indirect
4332 || hash
->root
.root
.type
== bfd_link_hash_warning
)
4333 hash
= ((struct elf_aarch64_link_hash_entry
*)
4334 hash
->root
.root
.u
.i
.link
);
4336 if (hash
->root
.root
.type
== bfd_link_hash_defined
4337 || hash
->root
.root
.type
== bfd_link_hash_defweak
)
4339 struct elf_aarch64_link_hash_table
*globals
=
4340 elf_aarch64_hash_table (info
);
4341 sym_sec
= hash
->root
.root
.u
.def
.section
;
4342 sym_value
= hash
->root
.root
.u
.def
.value
;
4343 /* For a destination in a shared library,
4344 use the PLT stub as target address to
4345 decide whether a branch stub is
4347 if (globals
->root
.splt
!= NULL
&& hash
!= NULL
4348 && hash
->root
.plt
.offset
!= (bfd_vma
) - 1)
4350 sym_sec
= globals
->root
.splt
;
4351 sym_value
= hash
->root
.plt
.offset
;
4352 if (sym_sec
->output_section
!= NULL
)
4353 destination
= (sym_value
4354 + sym_sec
->output_offset
4356 sym_sec
->output_section
->vma
);
4358 else if (sym_sec
->output_section
!= NULL
)
4359 destination
= (sym_value
+ irela
->r_addend
4360 + sym_sec
->output_offset
4361 + sym_sec
->output_section
->vma
);
4363 else if (hash
->root
.root
.type
== bfd_link_hash_undefined
4364 || (hash
->root
.root
.type
4365 == bfd_link_hash_undefweak
))
4367 /* For a shared library, use the PLT stub as
4368 target address to decide whether a long
4369 branch stub is needed.
4370 For absolute code, they cannot be handled. */
4371 struct elf_aarch64_link_hash_table
*globals
=
4372 elf_aarch64_hash_table (info
);
4374 if (globals
->root
.splt
!= NULL
&& hash
!= NULL
4375 && hash
->root
.plt
.offset
!= (bfd_vma
) - 1)
4377 sym_sec
= globals
->root
.splt
;
4378 sym_value
= hash
->root
.plt
.offset
;
4379 if (sym_sec
->output_section
!= NULL
)
4380 destination
= (sym_value
4381 + sym_sec
->output_offset
4383 sym_sec
->output_section
->vma
);
4390 bfd_set_error (bfd_error_bad_value
);
4391 goto error_ret_free_internal
;
4393 st_type
= ELF_ST_TYPE (hash
->root
.type
);
4394 sym_name
= hash
->root
.root
.root
.string
;
4397 /* Determine what (if any) linker stub is needed. */
4398 stub_type
= aarch64_type_of_stub (section
, irela
, sym_sec
,
4399 st_type
, destination
);
4400 if (stub_type
== aarch64_stub_none
)
4403 /* Support for grouping stub sections. */
4404 id_sec
= htab
->stub_group
[section
->id
].link_sec
;
4406 /* Get the name of this stub. */
4407 stub_name
= elfNN_aarch64_stub_name (id_sec
, sym_sec
, hash
,
4410 goto error_ret_free_internal
;
4413 aarch64_stub_hash_lookup (&htab
->stub_hash_table
,
4414 stub_name
, FALSE
, FALSE
);
4415 if (stub_entry
!= NULL
)
4417 /* The proper stub has already been created. */
4419 /* Always update this stub's target since it may have
4420 changed after layout. */
4421 stub_entry
->target_value
= sym_value
+ irela
->r_addend
;
4425 stub_entry
= _bfd_aarch64_add_stub_entry_in_group
4426 (stub_name
, section
, htab
);
4427 if (stub_entry
== NULL
)
4430 goto error_ret_free_internal
;
4433 stub_entry
->target_value
= sym_value
+ irela
->r_addend
;
4434 stub_entry
->target_section
= sym_sec
;
4435 stub_entry
->stub_type
= stub_type
;
4436 stub_entry
->h
= hash
;
4437 stub_entry
->st_type
= st_type
;
4439 if (sym_name
== NULL
)
4440 sym_name
= "unnamed";
4441 len
= sizeof (STUB_ENTRY_NAME
) + strlen (sym_name
);
4442 stub_entry
->output_name
= bfd_alloc (htab
->stub_bfd
, len
);
4443 if (stub_entry
->output_name
== NULL
)
4446 goto error_ret_free_internal
;
4449 snprintf (stub_entry
->output_name
, len
, STUB_ENTRY_NAME
,
4452 stub_changed
= TRUE
;
4455 /* We're done with the internal relocs, free them. */
4456 if (elf_section_data (section
)->relocs
== NULL
)
4457 free (internal_relocs
);
4464 _bfd_aarch64_resize_stubs (htab
);
4466 /* Ask the linker to do its stuff. */
4467 (*htab
->layout_sections_again
) ();
4468 stub_changed
= FALSE
;
4473 error_ret_free_local
:
4477 /* Build all the stubs associated with the current output file. The
4478 stubs are kept in a hash table attached to the main linker hash
4479 table. We also set up the .plt entries for statically linked PIC
4480 functions here. This function is called via aarch64_elf_finish in the
4484 elfNN_aarch64_build_stubs (struct bfd_link_info
*info
)
4487 struct bfd_hash_table
*table
;
4488 struct elf_aarch64_link_hash_table
*htab
;
4490 htab
= elf_aarch64_hash_table (info
);
4492 for (stub_sec
= htab
->stub_bfd
->sections
;
4493 stub_sec
!= NULL
; stub_sec
= stub_sec
->next
)
4497 /* Ignore non-stub sections. */
4498 if (!strstr (stub_sec
->name
, STUB_SUFFIX
))
4501 /* Allocate memory to hold the linker stubs. */
4502 size
= stub_sec
->size
;
4503 stub_sec
->contents
= bfd_zalloc (htab
->stub_bfd
, size
);
4504 if (stub_sec
->contents
== NULL
&& size
!= 0)
4508 /* Add a branch around the stub section, and a nop, to keep it 8 byte
4509 aligned, as long branch stubs contain a 64-bit address. */
4510 bfd_putl32 (0x14000000 | (size
>> 2), stub_sec
->contents
);
4511 bfd_putl32 (INSN_NOP
, stub_sec
->contents
+ 4);
4512 stub_sec
->size
+= 8;
4515 /* Build the stubs as directed by the stub hash table. */
4516 table
= &htab
->stub_hash_table
;
4517 bfd_hash_traverse (table
, aarch64_build_one_stub
, info
);
4523 /* Add an entry to the code/data map for section SEC. */
4526 elfNN_aarch64_section_map_add (asection
*sec
, char type
, bfd_vma vma
)
4528 struct _aarch64_elf_section_data
*sec_data
=
4529 elf_aarch64_section_data (sec
);
4530 unsigned int newidx
;
4532 if (sec_data
->map
== NULL
)
4534 sec_data
->map
= bfd_malloc (sizeof (elf_aarch64_section_map
));
4535 sec_data
->mapcount
= 0;
4536 sec_data
->mapsize
= 1;
4539 newidx
= sec_data
->mapcount
++;
4541 if (sec_data
->mapcount
> sec_data
->mapsize
)
4543 sec_data
->mapsize
*= 2;
4544 sec_data
->map
= bfd_realloc_or_free
4545 (sec_data
->map
, sec_data
->mapsize
* sizeof (elf_aarch64_section_map
));
4550 sec_data
->map
[newidx
].vma
= vma
;
4551 sec_data
->map
[newidx
].type
= type
;
4556 /* Initialise maps of insn/data for input BFDs. */
4558 bfd_elfNN_aarch64_init_maps (bfd
*abfd
)
4560 Elf_Internal_Sym
*isymbuf
;
4561 Elf_Internal_Shdr
*hdr
;
4562 unsigned int i
, localsyms
;
4564 /* Make sure that we are dealing with an AArch64 elf binary. */
4565 if (!is_aarch64_elf (abfd
))
4568 if ((abfd
->flags
& DYNAMIC
) != 0)
4571 hdr
= &elf_symtab_hdr (abfd
);
4572 localsyms
= hdr
->sh_info
;
4574 /* Obtain a buffer full of symbols for this BFD. The hdr->sh_info field
4575 should contain the number of local symbols, which should come before any
4576 global symbols. Mapping symbols are always local. */
4577 isymbuf
= bfd_elf_get_elf_syms (abfd
, hdr
, localsyms
, 0, NULL
, NULL
, NULL
);
4579 /* No internal symbols read? Skip this BFD. */
4580 if (isymbuf
== NULL
)
4583 for (i
= 0; i
< localsyms
; i
++)
4585 Elf_Internal_Sym
*isym
= &isymbuf
[i
];
4586 asection
*sec
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
4589 if (sec
!= NULL
&& ELF_ST_BIND (isym
->st_info
) == STB_LOCAL
)
4591 name
= bfd_elf_string_from_elf_section (abfd
,
4595 if (bfd_is_aarch64_special_symbol_name
4596 (name
, BFD_AARCH64_SPECIAL_SYM_TYPE_MAP
))
4597 elfNN_aarch64_section_map_add (sec
, name
[1], isym
->st_value
);
4602 /* Set option values needed during linking. */
4604 bfd_elfNN_aarch64_set_options (struct bfd
*output_bfd
,
4605 struct bfd_link_info
*link_info
,
4607 int no_wchar_warn
, int pic_veneer
,
4608 int fix_erratum_835769
,
4609 int fix_erratum_843419
,
4610 int no_apply_dynamic_relocs
)
4612 struct elf_aarch64_link_hash_table
*globals
;
4614 globals
= elf_aarch64_hash_table (link_info
);
4615 globals
->pic_veneer
= pic_veneer
;
4616 globals
->fix_erratum_835769
= fix_erratum_835769
;
4617 globals
->fix_erratum_843419
= fix_erratum_843419
;
4618 globals
->fix_erratum_843419_adr
= TRUE
;
4619 globals
->no_apply_dynamic_relocs
= no_apply_dynamic_relocs
;
4621 BFD_ASSERT (is_aarch64_elf (output_bfd
));
4622 elf_aarch64_tdata (output_bfd
)->no_enum_size_warning
= no_enum_warn
;
4623 elf_aarch64_tdata (output_bfd
)->no_wchar_size_warning
= no_wchar_warn
;
4627 aarch64_calculate_got_entry_vma (struct elf_link_hash_entry
*h
,
4628 struct elf_aarch64_link_hash_table
4629 *globals
, struct bfd_link_info
*info
,
4630 bfd_vma value
, bfd
*output_bfd
,
4631 bfd_boolean
*unresolved_reloc_p
)
4633 bfd_vma off
= (bfd_vma
) - 1;
4634 asection
*basegot
= globals
->root
.sgot
;
4635 bfd_boolean dyn
= globals
->root
.dynamic_sections_created
;
4639 BFD_ASSERT (basegot
!= NULL
);
4640 off
= h
->got
.offset
;
4641 BFD_ASSERT (off
!= (bfd_vma
) - 1);
4642 if (!WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, bfd_link_pic (info
), h
)
4643 || (bfd_link_pic (info
)
4644 && SYMBOL_REFERENCES_LOCAL (info
, h
))
4645 || (ELF_ST_VISIBILITY (h
->other
)
4646 && h
->root
.type
== bfd_link_hash_undefweak
))
4648 /* This is actually a static link, or it is a -Bsymbolic link
4649 and the symbol is defined locally. We must initialize this
4650 entry in the global offset table. Since the offset must
4651 always be a multiple of 8 (4 in the case of ILP32), we use
4652 the least significant bit to record whether we have
4653 initialized it already.
4654 When doing a dynamic link, we create a .rel(a).got relocation
4655 entry to initialize the value. This is done in the
4656 finish_dynamic_symbol routine. */
4661 bfd_put_NN (output_bfd
, value
, basegot
->contents
+ off
);
4666 *unresolved_reloc_p
= FALSE
;
4668 off
= off
+ basegot
->output_section
->vma
+ basegot
->output_offset
;
4674 /* Change R_TYPE to a more efficient access model where possible,
4675 return the new reloc type. */
4677 static bfd_reloc_code_real_type
4678 aarch64_tls_transition_without_check (bfd_reloc_code_real_type r_type
,
4679 struct elf_link_hash_entry
*h
)
4681 bfd_boolean is_local
= h
== NULL
;
4685 case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21
:
4686 case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21
:
4688 ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1
4689 : BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21
);
4691 case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21
:
4693 ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC
4696 case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19
:
4698 ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1
4699 : BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19
);
4701 case BFD_RELOC_AARCH64_TLSDESC_LDR
:
4703 ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC
4704 : BFD_RELOC_AARCH64_NONE
);
4706 case BFD_RELOC_AARCH64_TLSDESC_OFF_G0_NC
:
4708 ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1_NC
4709 : BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G0_NC
);
4711 case BFD_RELOC_AARCH64_TLSDESC_OFF_G1
:
4713 ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G2
4714 : BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G1
);
4716 case BFD_RELOC_AARCH64_TLSDESC_LDNN_LO12_NC
:
4717 case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC
:
4719 ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC
4720 : BFD_RELOC_AARCH64_TLSIE_LDNN_GOTTPREL_LO12_NC
);
4722 case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21
:
4723 return is_local
? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1
: r_type
;
4725 case BFD_RELOC_AARCH64_TLSIE_LDNN_GOTTPREL_LO12_NC
:
4726 return is_local
? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC
: r_type
;
4728 case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19
:
4731 case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21
:
4733 ? BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_HI12
4734 : BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19
);
4736 case BFD_RELOC_AARCH64_TLSDESC_ADD
:
4737 case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12
:
4738 case BFD_RELOC_AARCH64_TLSDESC_CALL
:
4739 /* Instructions with these relocations will become NOPs. */
4740 return BFD_RELOC_AARCH64_NONE
;
4742 case BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC
:
4743 case BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21
:
4744 case BFD_RELOC_AARCH64_TLSLD_ADR_PREL21
:
4745 return is_local
? BFD_RELOC_AARCH64_NONE
: r_type
;
4748 case BFD_RELOC_AARCH64_TLSGD_MOVW_G0_NC
:
4750 ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1_NC
4751 : BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G0_NC
;
4753 case BFD_RELOC_AARCH64_TLSGD_MOVW_G1
:
4755 ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G2
4756 : BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G1
;
4767 aarch64_reloc_got_type (bfd_reloc_code_real_type r_type
)
4771 case BFD_RELOC_AARCH64_ADR_GOT_PAGE
:
4772 case BFD_RELOC_AARCH64_GOT_LD_PREL19
:
4773 case BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14
:
4774 case BFD_RELOC_AARCH64_LD32_GOT_LO12_NC
:
4775 case BFD_RELOC_AARCH64_LD64_GOTOFF_LO15
:
4776 case BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15
:
4777 case BFD_RELOC_AARCH64_LD64_GOT_LO12_NC
:
4778 case BFD_RELOC_AARCH64_MOVW_GOTOFF_G0_NC
:
4779 case BFD_RELOC_AARCH64_MOVW_GOTOFF_G1
:
4782 case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC
:
4783 case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21
:
4784 case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21
:
4785 case BFD_RELOC_AARCH64_TLSGD_MOVW_G0_NC
:
4786 case BFD_RELOC_AARCH64_TLSGD_MOVW_G1
:
4787 case BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC
:
4788 case BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21
:
4789 case BFD_RELOC_AARCH64_TLSLD_ADR_PREL21
:
4792 case BFD_RELOC_AARCH64_TLSDESC_ADD
:
4793 case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12
:
4794 case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21
:
4795 case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21
:
4796 case BFD_RELOC_AARCH64_TLSDESC_CALL
:
4797 case BFD_RELOC_AARCH64_TLSDESC_LD32_LO12_NC
:
4798 case BFD_RELOC_AARCH64_TLSDESC_LD64_LO12
:
4799 case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19
:
4800 case BFD_RELOC_AARCH64_TLSDESC_LDR
:
4801 case BFD_RELOC_AARCH64_TLSDESC_OFF_G0_NC
:
4802 case BFD_RELOC_AARCH64_TLSDESC_OFF_G1
:
4803 return GOT_TLSDESC_GD
;
4805 case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21
:
4806 case BFD_RELOC_AARCH64_TLSIE_LD32_GOTTPREL_LO12_NC
:
4807 case BFD_RELOC_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC
:
4808 case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19
:
4809 case BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G0_NC
:
4810 case BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G1
:
4820 aarch64_can_relax_tls (bfd
*input_bfd
,
4821 struct bfd_link_info
*info
,
4822 bfd_reloc_code_real_type r_type
,
4823 struct elf_link_hash_entry
*h
,
4824 unsigned long r_symndx
)
4826 unsigned int symbol_got_type
;
4827 unsigned int reloc_got_type
;
4829 if (! IS_AARCH64_TLS_RELAX_RELOC (r_type
))
4832 symbol_got_type
= elfNN_aarch64_symbol_got_type (h
, input_bfd
, r_symndx
);
4833 reloc_got_type
= aarch64_reloc_got_type (r_type
);
4835 if (symbol_got_type
== GOT_TLS_IE
&& GOT_TLS_GD_ANY_P (reloc_got_type
))
4838 if (!bfd_link_executable (info
))
4841 if (h
&& h
->root
.type
== bfd_link_hash_undefweak
)
4847 /* Given the relocation code R_TYPE, return the relaxed bfd reloc
4850 static bfd_reloc_code_real_type
4851 aarch64_tls_transition (bfd
*input_bfd
,
4852 struct bfd_link_info
*info
,
4853 unsigned int r_type
,
4854 struct elf_link_hash_entry
*h
,
4855 unsigned long r_symndx
)
4857 bfd_reloc_code_real_type bfd_r_type
4858 = elfNN_aarch64_bfd_reloc_from_type (input_bfd
, r_type
);
4860 if (! aarch64_can_relax_tls (input_bfd
, info
, bfd_r_type
, h
, r_symndx
))
4863 return aarch64_tls_transition_without_check (bfd_r_type
, h
);
4866 /* Return the base VMA address which should be subtracted from real addresses
4867 when resolving R_AARCH64_TLS_DTPREL relocation. */
4870 dtpoff_base (struct bfd_link_info
*info
)
4872 /* If tls_sec is NULL, we should have signalled an error already. */
4873 BFD_ASSERT (elf_hash_table (info
)->tls_sec
!= NULL
);
4874 return elf_hash_table (info
)->tls_sec
->vma
;
4877 /* Return the base VMA address which should be subtracted from real addresses
4878 when resolving R_AARCH64_TLS_GOTTPREL64 relocations. */
4881 tpoff_base (struct bfd_link_info
*info
)
4883 struct elf_link_hash_table
*htab
= elf_hash_table (info
);
4885 /* If tls_sec is NULL, we should have signalled an error already. */
4886 BFD_ASSERT (htab
->tls_sec
!= NULL
);
4888 bfd_vma base
= align_power ((bfd_vma
) TCB_SIZE
,
4889 htab
->tls_sec
->alignment_power
);
4890 return htab
->tls_sec
->vma
- base
;
4894 symbol_got_offset_ref (bfd
*input_bfd
, struct elf_link_hash_entry
*h
,
4895 unsigned long r_symndx
)
4897 /* Calculate the address of the GOT entry for symbol
4898 referred to in h. */
4900 return &h
->got
.offset
;
4904 struct elf_aarch64_local_symbol
*l
;
4906 l
= elf_aarch64_locals (input_bfd
);
4907 return &l
[r_symndx
].got_offset
;
4912 symbol_got_offset_mark (bfd
*input_bfd
, struct elf_link_hash_entry
*h
,
4913 unsigned long r_symndx
)
4916 p
= symbol_got_offset_ref (input_bfd
, h
, r_symndx
);
4921 symbol_got_offset_mark_p (bfd
*input_bfd
, struct elf_link_hash_entry
*h
,
4922 unsigned long r_symndx
)
4925 value
= * symbol_got_offset_ref (input_bfd
, h
, r_symndx
);
4930 symbol_got_offset (bfd
*input_bfd
, struct elf_link_hash_entry
*h
,
4931 unsigned long r_symndx
)
4934 value
= * symbol_got_offset_ref (input_bfd
, h
, r_symndx
);
4940 symbol_tlsdesc_got_offset_ref (bfd
*input_bfd
, struct elf_link_hash_entry
*h
,
4941 unsigned long r_symndx
)
4943 /* Calculate the address of the GOT entry for symbol
4944 referred to in h. */
4947 struct elf_aarch64_link_hash_entry
*eh
;
4948 eh
= (struct elf_aarch64_link_hash_entry
*) h
;
4949 return &eh
->tlsdesc_got_jump_table_offset
;
4954 struct elf_aarch64_local_symbol
*l
;
4956 l
= elf_aarch64_locals (input_bfd
);
4957 return &l
[r_symndx
].tlsdesc_got_jump_table_offset
;
4962 symbol_tlsdesc_got_offset_mark (bfd
*input_bfd
, struct elf_link_hash_entry
*h
,
4963 unsigned long r_symndx
)
4966 p
= symbol_tlsdesc_got_offset_ref (input_bfd
, h
, r_symndx
);
4971 symbol_tlsdesc_got_offset_mark_p (bfd
*input_bfd
,
4972 struct elf_link_hash_entry
*h
,
4973 unsigned long r_symndx
)
4976 value
= * symbol_tlsdesc_got_offset_ref (input_bfd
, h
, r_symndx
);
4981 symbol_tlsdesc_got_offset (bfd
*input_bfd
, struct elf_link_hash_entry
*h
,
4982 unsigned long r_symndx
)
4985 value
= * symbol_tlsdesc_got_offset_ref (input_bfd
, h
, r_symndx
);
4990 /* Data for make_branch_to_erratum_835769_stub(). */
4992 struct erratum_835769_branch_to_stub_data
4994 struct bfd_link_info
*info
;
4995 asection
*output_section
;
4999 /* Helper to insert branches to erratum 835769 stubs in the right
5000 places for a particular section. */
5003 make_branch_to_erratum_835769_stub (struct bfd_hash_entry
*gen_entry
,
5006 struct elf_aarch64_stub_hash_entry
*stub_entry
;
5007 struct erratum_835769_branch_to_stub_data
*data
;
5009 unsigned long branch_insn
= 0;
5010 bfd_vma veneered_insn_loc
, veneer_entry_loc
;
5011 bfd_signed_vma branch_offset
;
5012 unsigned int target
;
5015 stub_entry
= (struct elf_aarch64_stub_hash_entry
*) gen_entry
;
5016 data
= (struct erratum_835769_branch_to_stub_data
*) in_arg
;
5018 if (stub_entry
->target_section
!= data
->output_section
5019 || stub_entry
->stub_type
!= aarch64_stub_erratum_835769_veneer
)
5022 contents
= data
->contents
;
5023 veneered_insn_loc
= stub_entry
->target_section
->output_section
->vma
5024 + stub_entry
->target_section
->output_offset
5025 + stub_entry
->target_value
;
5026 veneer_entry_loc
= stub_entry
->stub_sec
->output_section
->vma
5027 + stub_entry
->stub_sec
->output_offset
5028 + stub_entry
->stub_offset
;
5029 branch_offset
= veneer_entry_loc
- veneered_insn_loc
;
5031 abfd
= stub_entry
->target_section
->owner
;
5032 if (!aarch64_valid_branch_p (veneer_entry_loc
, veneered_insn_loc
))
5034 (_("%pB: error: erratum 835769 stub out "
5035 "of range (input file too large)"), abfd
);
5037 target
= stub_entry
->target_value
;
5038 branch_insn
= 0x14000000;
5039 branch_offset
>>= 2;
5040 branch_offset
&= 0x3ffffff;
5041 branch_insn
|= branch_offset
;
5042 bfd_putl32 (branch_insn
, &contents
[target
]);
5049 _bfd_aarch64_erratum_843419_branch_to_stub (struct bfd_hash_entry
*gen_entry
,
5052 struct elf_aarch64_stub_hash_entry
*stub_entry
5053 = (struct elf_aarch64_stub_hash_entry
*) gen_entry
;
5054 struct erratum_835769_branch_to_stub_data
*data
5055 = (struct erratum_835769_branch_to_stub_data
*) in_arg
;
5056 struct bfd_link_info
*info
;
5057 struct elf_aarch64_link_hash_table
*htab
;
5065 contents
= data
->contents
;
5066 section
= data
->output_section
;
5068 htab
= elf_aarch64_hash_table (info
);
5070 if (stub_entry
->target_section
!= section
5071 || stub_entry
->stub_type
!= aarch64_stub_erratum_843419_veneer
)
5074 insn
= bfd_getl32 (contents
+ stub_entry
->target_value
);
5076 stub_entry
->stub_sec
->contents
+ stub_entry
->stub_offset
);
5078 place
= (section
->output_section
->vma
+ section
->output_offset
5079 + stub_entry
->adrp_offset
);
5080 insn
= bfd_getl32 (contents
+ stub_entry
->adrp_offset
);
5082 if (!_bfd_aarch64_adrp_p (insn
))
5085 bfd_signed_vma imm
=
5086 (_bfd_aarch64_sign_extend
5087 ((bfd_vma
) _bfd_aarch64_decode_adrp_imm (insn
) << 12, 33)
5090 if (htab
->fix_erratum_843419_adr
5091 && (imm
>= AARCH64_MIN_ADRP_IMM
&& imm
<= AARCH64_MAX_ADRP_IMM
))
5093 insn
= (_bfd_aarch64_reencode_adr_imm (AARCH64_ADR_OP
, imm
)
5094 | AARCH64_RT (insn
));
5095 bfd_putl32 (insn
, contents
+ stub_entry
->adrp_offset
);
5099 bfd_vma veneered_insn_loc
;
5100 bfd_vma veneer_entry_loc
;
5101 bfd_signed_vma branch_offset
;
5102 uint32_t branch_insn
;
5104 veneered_insn_loc
= stub_entry
->target_section
->output_section
->vma
5105 + stub_entry
->target_section
->output_offset
5106 + stub_entry
->target_value
;
5107 veneer_entry_loc
= stub_entry
->stub_sec
->output_section
->vma
5108 + stub_entry
->stub_sec
->output_offset
5109 + stub_entry
->stub_offset
;
5110 branch_offset
= veneer_entry_loc
- veneered_insn_loc
;
5112 abfd
= stub_entry
->target_section
->owner
;
5113 if (!aarch64_valid_branch_p (veneer_entry_loc
, veneered_insn_loc
))
5115 (_("%pB: error: erratum 843419 stub out "
5116 "of range (input file too large)"), abfd
);
5118 branch_insn
= 0x14000000;
5119 branch_offset
>>= 2;
5120 branch_offset
&= 0x3ffffff;
5121 branch_insn
|= branch_offset
;
5122 bfd_putl32 (branch_insn
, contents
+ stub_entry
->target_value
);
5129 elfNN_aarch64_write_section (bfd
*output_bfd ATTRIBUTE_UNUSED
,
5130 struct bfd_link_info
*link_info
,
5135 struct elf_aarch64_link_hash_table
*globals
=
5136 elf_aarch64_hash_table (link_info
);
5138 if (globals
== NULL
)
5141 /* Fix code to point to erratum 835769 stubs. */
5142 if (globals
->fix_erratum_835769
)
5144 struct erratum_835769_branch_to_stub_data data
;
5146 data
.info
= link_info
;
5147 data
.output_section
= sec
;
5148 data
.contents
= contents
;
5149 bfd_hash_traverse (&globals
->stub_hash_table
,
5150 make_branch_to_erratum_835769_stub
, &data
);
5153 if (globals
->fix_erratum_843419
)
5155 struct erratum_835769_branch_to_stub_data data
;
5157 data
.info
= link_info
;
5158 data
.output_section
= sec
;
5159 data
.contents
= contents
;
5160 bfd_hash_traverse (&globals
->stub_hash_table
,
5161 _bfd_aarch64_erratum_843419_branch_to_stub
, &data
);
5167 /* Return TRUE if RELOC is a relocation against the base of GOT table. */
5170 aarch64_relocation_aginst_gp_p (bfd_reloc_code_real_type reloc
)
5172 return (reloc
== BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14
5173 || reloc
== BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15
5174 || reloc
== BFD_RELOC_AARCH64_LD64_GOTOFF_LO15
5175 || reloc
== BFD_RELOC_AARCH64_MOVW_GOTOFF_G0_NC
5176 || reloc
== BFD_RELOC_AARCH64_MOVW_GOTOFF_G1
);
5179 /* Perform a relocation as part of a final link. The input relocation type
5180 should be TLS relaxed. */
5182 static bfd_reloc_status_type
5183 elfNN_aarch64_final_link_relocate (reloc_howto_type
*howto
,
5186 asection
*input_section
,
5188 Elf_Internal_Rela
*rel
,
5190 struct bfd_link_info
*info
,
5192 struct elf_link_hash_entry
*h
,
5193 bfd_boolean
*unresolved_reloc_p
,
5194 bfd_boolean save_addend
,
5195 bfd_vma
*saved_addend
,
5196 Elf_Internal_Sym
*sym
)
5198 Elf_Internal_Shdr
*symtab_hdr
;
5199 unsigned int r_type
= howto
->type
;
5200 bfd_reloc_code_real_type bfd_r_type
5201 = elfNN_aarch64_bfd_reloc_from_howto (howto
);
5202 unsigned long r_symndx
;
5203 bfd_byte
*hit_data
= contents
+ rel
->r_offset
;
5204 bfd_vma place
, off
, got_entry_addr
= 0;
5205 bfd_signed_vma signed_addend
;
5206 struct elf_aarch64_link_hash_table
*globals
;
5207 bfd_boolean weak_undef_p
;
5208 bfd_boolean relative_reloc
;
5210 bfd_vma orig_value
= value
;
5211 bfd_boolean resolved_to_zero
;
5212 bfd_boolean abs_symbol_p
;
5214 globals
= elf_aarch64_hash_table (info
);
5216 symtab_hdr
= &elf_symtab_hdr (input_bfd
);
5218 BFD_ASSERT (is_aarch64_elf (input_bfd
));
5220 r_symndx
= ELFNN_R_SYM (rel
->r_info
);
5222 place
= input_section
->output_section
->vma
5223 + input_section
->output_offset
+ rel
->r_offset
;
5225 /* Get addend, accumulating the addend for consecutive relocs
5226 which refer to the same offset. */
5227 signed_addend
= saved_addend
? *saved_addend
: 0;
5228 signed_addend
+= rel
->r_addend
;
5230 weak_undef_p
= (h
? h
->root
.type
== bfd_link_hash_undefweak
5231 : bfd_is_und_section (sym_sec
));
5232 abs_symbol_p
= h
!= NULL
&& bfd_is_abs_symbol (&h
->root
);
5235 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle
5236 it here if it is defined in a non-shared object. */
5238 && h
->type
== STT_GNU_IFUNC
5245 if ((input_section
->flags
& SEC_ALLOC
) == 0)
5247 /* If this is a SHT_NOTE section without SHF_ALLOC, treat
5248 STT_GNU_IFUNC symbol as STT_FUNC. */
5249 if (elf_section_type (input_section
) == SHT_NOTE
)
5252 /* Dynamic relocs are not propagated for SEC_DEBUGGING
5253 sections because such sections are not SEC_ALLOC and
5254 thus ld.so will not process them. */
5255 if ((input_section
->flags
& SEC_DEBUGGING
) != 0)
5256 return bfd_reloc_ok
;
5258 if (h
->root
.root
.string
)
5259 name
= h
->root
.root
.string
;
5261 name
= bfd_elf_sym_name (input_bfd
, symtab_hdr
, sym
, NULL
);
5263 /* xgettext:c-format */
5264 (_("%pB(%pA+%#" PRIx64
"): "
5265 "unresolvable %s relocation against symbol `%s'"),
5266 input_bfd
, input_section
, (uint64_t) rel
->r_offset
,
5268 bfd_set_error (bfd_error_bad_value
);
5269 return bfd_reloc_notsupported
;
5271 else if (h
->plt
.offset
== (bfd_vma
) -1)
5272 goto bad_ifunc_reloc
;
5274 /* STT_GNU_IFUNC symbol must go through PLT. */
5275 plt
= globals
->root
.splt
? globals
->root
.splt
: globals
->root
.iplt
;
5276 value
= (plt
->output_section
->vma
+ plt
->output_offset
+ h
->plt
.offset
);
5282 if (h
->root
.root
.string
)
5283 name
= h
->root
.root
.string
;
5285 name
= bfd_elf_sym_name (input_bfd
, symtab_hdr
, sym
,
5288 /* xgettext:c-format */
5289 (_("%pB: relocation %s against STT_GNU_IFUNC "
5290 "symbol `%s' isn't handled by %s"), input_bfd
,
5291 howto
->name
, name
, __FUNCTION__
);
5292 bfd_set_error (bfd_error_bad_value
);
5293 return bfd_reloc_notsupported
;
5295 case BFD_RELOC_AARCH64_NN
:
5296 if (rel
->r_addend
!= 0)
5298 if (h
->root
.root
.string
)
5299 name
= h
->root
.root
.string
;
5301 name
= bfd_elf_sym_name (input_bfd
, symtab_hdr
,
5304 /* xgettext:c-format */
5305 (_("%pB: relocation %s against STT_GNU_IFUNC "
5306 "symbol `%s' has non-zero addend: %" PRId64
),
5307 input_bfd
, howto
->name
, name
, (int64_t) rel
->r_addend
);
5308 bfd_set_error (bfd_error_bad_value
);
5309 return bfd_reloc_notsupported
;
5312 /* Generate dynamic relocation only when there is a
5313 non-GOT reference in a shared object. */
5314 if (bfd_link_pic (info
) && h
->non_got_ref
)
5316 Elf_Internal_Rela outrel
;
5319 /* Need a dynamic relocation to get the real function
5321 outrel
.r_offset
= _bfd_elf_section_offset (output_bfd
,
5325 if (outrel
.r_offset
== (bfd_vma
) -1
5326 || outrel
.r_offset
== (bfd_vma
) -2)
5329 outrel
.r_offset
+= (input_section
->output_section
->vma
5330 + input_section
->output_offset
);
5332 if (h
->dynindx
== -1
5334 || bfd_link_executable (info
))
5336 /* This symbol is resolved locally. */
5337 outrel
.r_info
= ELFNN_R_INFO (0, AARCH64_R (IRELATIVE
));
5338 outrel
.r_addend
= (h
->root
.u
.def
.value
5339 + h
->root
.u
.def
.section
->output_section
->vma
5340 + h
->root
.u
.def
.section
->output_offset
);
5344 outrel
.r_info
= ELFNN_R_INFO (h
->dynindx
, r_type
);
5345 outrel
.r_addend
= 0;
5348 sreloc
= globals
->root
.irelifunc
;
5349 elf_append_rela (output_bfd
, sreloc
, &outrel
);
5351 /* If this reloc is against an external symbol, we
5352 do not want to fiddle with the addend. Otherwise,
5353 we need to include the symbol value so that it
5354 becomes an addend for the dynamic reloc. For an
5355 internal symbol, we have updated addend. */
5356 return bfd_reloc_ok
;
5359 case BFD_RELOC_AARCH64_CALL26
:
5360 case BFD_RELOC_AARCH64_JUMP26
:
5361 value
= _bfd_aarch64_elf_resolve_relocation (bfd_r_type
, place
, value
,
5364 return _bfd_aarch64_elf_put_addend (input_bfd
, hit_data
, bfd_r_type
,
5366 case BFD_RELOC_AARCH64_ADR_GOT_PAGE
:
5367 case BFD_RELOC_AARCH64_GOT_LD_PREL19
:
5368 case BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14
:
5369 case BFD_RELOC_AARCH64_LD32_GOT_LO12_NC
:
5370 case BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15
:
5371 case BFD_RELOC_AARCH64_MOVW_GOTOFF_G0_NC
:
5372 case BFD_RELOC_AARCH64_MOVW_GOTOFF_G1
:
5373 case BFD_RELOC_AARCH64_LD64_GOTOFF_LO15
:
5374 case BFD_RELOC_AARCH64_LD64_GOT_LO12_NC
:
5375 base_got
= globals
->root
.sgot
;
5376 off
= h
->got
.offset
;
5378 if (base_got
== NULL
)
5381 if (off
== (bfd_vma
) -1)
5385 /* We can't use h->got.offset here to save state, or
5386 even just remember the offset, as finish_dynamic_symbol
5387 would use that as offset into .got. */
5389 if (globals
->root
.splt
!= NULL
)
5391 plt_index
= ((h
->plt
.offset
- globals
->plt_header_size
) /
5392 globals
->plt_entry_size
);
5393 off
= (plt_index
+ 3) * GOT_ENTRY_SIZE
;
5394 base_got
= globals
->root
.sgotplt
;
5398 plt_index
= h
->plt
.offset
/ globals
->plt_entry_size
;
5399 off
= plt_index
* GOT_ENTRY_SIZE
;
5400 base_got
= globals
->root
.igotplt
;
5403 if (h
->dynindx
== -1
5407 /* This references the local definition. We must
5408 initialize this entry in the global offset table.
5409 Since the offset must always be a multiple of 8,
5410 we use the least significant bit to record
5411 whether we have initialized it already.
5413 When doing a dynamic link, we create a .rela.got
5414 relocation entry to initialize the value. This
5415 is done in the finish_dynamic_symbol routine. */
5420 bfd_put_NN (output_bfd
, value
,
5421 base_got
->contents
+ off
);
5422 /* Note that this is harmless as -1 | 1 still is -1. */
5426 value
= (base_got
->output_section
->vma
5427 + base_got
->output_offset
+ off
);
5430 value
= aarch64_calculate_got_entry_vma (h
, globals
, info
,
5432 unresolved_reloc_p
);
5434 if (aarch64_relocation_aginst_gp_p (bfd_r_type
))
5435 addend
= (globals
->root
.sgot
->output_section
->vma
5436 + globals
->root
.sgot
->output_offset
);
5438 value
= _bfd_aarch64_elf_resolve_relocation (bfd_r_type
, place
, value
,
5439 addend
, weak_undef_p
);
5440 return _bfd_aarch64_elf_put_addend (input_bfd
, hit_data
, bfd_r_type
, howto
, value
);
5441 case BFD_RELOC_AARCH64_ADD_LO12
:
5442 case BFD_RELOC_AARCH64_ADR_HI21_PCREL
:
5448 resolved_to_zero
= (h
!= NULL
5449 && UNDEFWEAK_NO_DYNAMIC_RELOC (info
, h
));
5453 case BFD_RELOC_AARCH64_NONE
:
5454 case BFD_RELOC_AARCH64_TLSDESC_ADD
:
5455 case BFD_RELOC_AARCH64_TLSDESC_CALL
:
5456 case BFD_RELOC_AARCH64_TLSDESC_LDR
:
5457 *unresolved_reloc_p
= FALSE
;
5458 return bfd_reloc_ok
;
5460 case BFD_RELOC_AARCH64_NN
:
5462 /* When generating a shared object or relocatable executable, these
5463 relocations are copied into the output file to be resolved at
5465 if (((bfd_link_pic (info
)
5466 || globals
->root
.is_relocatable_executable
)
5467 && (input_section
->flags
& SEC_ALLOC
)
5469 || (ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
5470 && !resolved_to_zero
)
5471 || h
->root
.type
!= bfd_link_hash_undefweak
))
5472 /* Or we are creating an executable, we may need to keep relocations
5473 for symbols satisfied by a dynamic library if we manage to avoid
5474 copy relocs for the symbol. */
5475 || (ELIMINATE_COPY_RELOCS
5476 && !bfd_link_pic (info
)
5478 && (input_section
->flags
& SEC_ALLOC
)
5483 || h
->root
.type
== bfd_link_hash_undefweak
5484 || h
->root
.type
== bfd_link_hash_undefined
)))
5486 Elf_Internal_Rela outrel
;
5488 bfd_boolean skip
, relocate
;
5491 *unresolved_reloc_p
= FALSE
;
5496 outrel
.r_addend
= signed_addend
;
5498 _bfd_elf_section_offset (output_bfd
, info
, input_section
,
5500 if (outrel
.r_offset
== (bfd_vma
) - 1)
5502 else if (outrel
.r_offset
== (bfd_vma
) - 2)
5507 else if (abs_symbol_p
)
5509 /* Local absolute symbol. */
5510 skip
= (h
->forced_local
|| (h
->dynindx
== -1));
5514 outrel
.r_offset
+= (input_section
->output_section
->vma
5515 + input_section
->output_offset
);
5518 memset (&outrel
, 0, sizeof outrel
);
5521 && (!bfd_link_pic (info
)
5522 || !(bfd_link_pie (info
) || SYMBOLIC_BIND (info
, h
))
5523 || !h
->def_regular
))
5524 outrel
.r_info
= ELFNN_R_INFO (h
->dynindx
, r_type
);
5529 /* On SVR4-ish systems, the dynamic loader cannot
5530 relocate the text and data segments independently,
5531 so the symbol does not matter. */
5533 relocate
= globals
->no_apply_dynamic_relocs
? FALSE
: TRUE
;
5534 outrel
.r_info
= ELFNN_R_INFO (symbol
, AARCH64_R (RELATIVE
));
5535 outrel
.r_addend
+= value
;
5538 sreloc
= elf_section_data (input_section
)->sreloc
;
5539 if (sreloc
== NULL
|| sreloc
->contents
== NULL
)
5540 return bfd_reloc_notsupported
;
5542 loc
= sreloc
->contents
+ sreloc
->reloc_count
++ * RELOC_SIZE (globals
);
5543 bfd_elfNN_swap_reloca_out (output_bfd
, &outrel
, loc
);
5545 if (sreloc
->reloc_count
* RELOC_SIZE (globals
) > sreloc
->size
)
5547 /* Sanity to check that we have previously allocated
5548 sufficient space in the relocation section for the
5549 number of relocations we actually want to emit. */
5553 /* If this reloc is against an external symbol, we do not want to
5554 fiddle with the addend. Otherwise, we need to include the symbol
5555 value so that it becomes an addend for the dynamic reloc. */
5557 return bfd_reloc_ok
;
5559 return _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
5560 contents
, rel
->r_offset
, value
,
5564 value
+= signed_addend
;
5567 case BFD_RELOC_AARCH64_CALL26
:
5568 case BFD_RELOC_AARCH64_JUMP26
:
5570 asection
*splt
= globals
->root
.splt
;
5571 bfd_boolean via_plt_p
=
5572 splt
!= NULL
&& h
!= NULL
&& h
->plt
.offset
!= (bfd_vma
) - 1;
5574 /* A call to an undefined weak symbol is converted to a jump to
5575 the next instruction unless a PLT entry will be created.
5576 The jump to the next instruction is optimized as a NOP.
5577 Do the same for local undefined symbols. */
5578 if (weak_undef_p
&& ! via_plt_p
)
5580 bfd_putl32 (INSN_NOP
, hit_data
);
5581 return bfd_reloc_ok
;
5584 /* If the call goes through a PLT entry, make sure to
5585 check distance to the right destination address. */
5587 value
= (splt
->output_section
->vma
5588 + splt
->output_offset
+ h
->plt
.offset
);
5590 /* Check if a stub has to be inserted because the destination
5592 struct elf_aarch64_stub_hash_entry
*stub_entry
= NULL
;
5594 /* If the branch destination is directed to plt stub, "value" will be
5595 the final destination, otherwise we should plus signed_addend, it may
5596 contain non-zero value, for example call to local function symbol
5597 which are turned into "sec_sym + sec_off", and sec_off is kept in
5599 if (! aarch64_valid_branch_p (via_plt_p
? value
: value
+ signed_addend
,
5601 /* The target is out of reach, so redirect the branch to
5602 the local stub for this function. */
5603 stub_entry
= elfNN_aarch64_get_stub_entry (input_section
, sym_sec
, h
,
5605 if (stub_entry
!= NULL
)
5607 value
= (stub_entry
->stub_offset
5608 + stub_entry
->stub_sec
->output_offset
5609 + stub_entry
->stub_sec
->output_section
->vma
);
5611 /* We have redirected the destination to stub entry address,
5612 so ignore any addend record in the original rela entry. */
5616 value
= _bfd_aarch64_elf_resolve_relocation (bfd_r_type
, place
, value
,
5617 signed_addend
, weak_undef_p
);
5618 *unresolved_reloc_p
= FALSE
;
5621 case BFD_RELOC_AARCH64_16_PCREL
:
5622 case BFD_RELOC_AARCH64_32_PCREL
:
5623 case BFD_RELOC_AARCH64_64_PCREL
:
5624 case BFD_RELOC_AARCH64_ADR_HI21_NC_PCREL
:
5625 case BFD_RELOC_AARCH64_ADR_HI21_PCREL
:
5626 case BFD_RELOC_AARCH64_ADR_LO21_PCREL
:
5627 case BFD_RELOC_AARCH64_LD_LO19_PCREL
:
5628 case BFD_RELOC_AARCH64_MOVW_PREL_G0
:
5629 case BFD_RELOC_AARCH64_MOVW_PREL_G0_NC
:
5630 case BFD_RELOC_AARCH64_MOVW_PREL_G1
:
5631 case BFD_RELOC_AARCH64_MOVW_PREL_G1_NC
:
5632 case BFD_RELOC_AARCH64_MOVW_PREL_G2
:
5633 case BFD_RELOC_AARCH64_MOVW_PREL_G2_NC
:
5634 case BFD_RELOC_AARCH64_MOVW_PREL_G3
:
5635 if (bfd_link_pic (info
)
5636 && (input_section
->flags
& SEC_ALLOC
) != 0
5637 && (input_section
->flags
& SEC_READONLY
) != 0
5638 && !SYMBOL_REFERENCES_LOCAL (info
, h
))
5640 int howto_index
= bfd_r_type
- BFD_RELOC_AARCH64_RELOC_START
;
5643 /* xgettext:c-format */
5644 (_("%pB: relocation %s against symbol `%s' which may bind "
5645 "externally can not be used when making a shared object; "
5646 "recompile with -fPIC"),
5647 input_bfd
, elfNN_aarch64_howto_table
[howto_index
].name
,
5648 h
->root
.root
.string
);
5649 bfd_set_error (bfd_error_bad_value
);
5650 return bfd_reloc_notsupported
;
5654 case BFD_RELOC_AARCH64_16
:
5656 case BFD_RELOC_AARCH64_32
:
5658 case BFD_RELOC_AARCH64_ADD_LO12
:
5659 case BFD_RELOC_AARCH64_BRANCH19
:
5660 case BFD_RELOC_AARCH64_LDST128_LO12
:
5661 case BFD_RELOC_AARCH64_LDST16_LO12
:
5662 case BFD_RELOC_AARCH64_LDST32_LO12
:
5663 case BFD_RELOC_AARCH64_LDST64_LO12
:
5664 case BFD_RELOC_AARCH64_LDST8_LO12
:
5665 case BFD_RELOC_AARCH64_MOVW_G0
:
5666 case BFD_RELOC_AARCH64_MOVW_G0_NC
:
5667 case BFD_RELOC_AARCH64_MOVW_G0_S
:
5668 case BFD_RELOC_AARCH64_MOVW_G1
:
5669 case BFD_RELOC_AARCH64_MOVW_G1_NC
:
5670 case BFD_RELOC_AARCH64_MOVW_G1_S
:
5671 case BFD_RELOC_AARCH64_MOVW_G2
:
5672 case BFD_RELOC_AARCH64_MOVW_G2_NC
:
5673 case BFD_RELOC_AARCH64_MOVW_G2_S
:
5674 case BFD_RELOC_AARCH64_MOVW_G3
:
5675 case BFD_RELOC_AARCH64_TSTBR14
:
5676 value
= _bfd_aarch64_elf_resolve_relocation (bfd_r_type
, place
, value
,
5677 signed_addend
, weak_undef_p
);
5680 case BFD_RELOC_AARCH64_ADR_GOT_PAGE
:
5681 case BFD_RELOC_AARCH64_GOT_LD_PREL19
:
5682 case BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14
:
5683 case BFD_RELOC_AARCH64_LD32_GOT_LO12_NC
:
5684 case BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15
:
5685 case BFD_RELOC_AARCH64_LD64_GOT_LO12_NC
:
5686 case BFD_RELOC_AARCH64_LD64_GOTOFF_LO15
:
5687 case BFD_RELOC_AARCH64_MOVW_GOTOFF_G0_NC
:
5688 case BFD_RELOC_AARCH64_MOVW_GOTOFF_G1
:
5689 if (globals
->root
.sgot
== NULL
)
5690 BFD_ASSERT (h
!= NULL
);
5692 relative_reloc
= FALSE
;
5697 /* If a symbol is not dynamic and is not undefined weak, bind it
5698 locally and generate a RELATIVE relocation under PIC mode.
5700 NOTE: one symbol may be referenced by several relocations, we
5701 should only generate one RELATIVE relocation for that symbol.
5702 Therefore, check GOT offset mark first. */
5703 if (h
->dynindx
== -1
5705 && h
->root
.type
!= bfd_link_hash_undefweak
5706 && bfd_link_pic (info
)
5707 && !symbol_got_offset_mark_p (input_bfd
, h
, r_symndx
))
5708 relative_reloc
= TRUE
;
5710 value
= aarch64_calculate_got_entry_vma (h
, globals
, info
, value
,
5712 unresolved_reloc_p
);
5713 /* Record the GOT entry address which will be used when generating
5714 RELATIVE relocation. */
5716 got_entry_addr
= value
;
5718 if (aarch64_relocation_aginst_gp_p (bfd_r_type
))
5719 addend
= (globals
->root
.sgot
->output_section
->vma
5720 + globals
->root
.sgot
->output_offset
);
5721 value
= _bfd_aarch64_elf_resolve_relocation (bfd_r_type
, place
, value
,
5722 addend
, weak_undef_p
);
5727 struct elf_aarch64_local_symbol
*locals
5728 = elf_aarch64_locals (input_bfd
);
5732 int howto_index
= bfd_r_type
- BFD_RELOC_AARCH64_RELOC_START
;
5734 /* xgettext:c-format */
5735 (_("%pB: local symbol descriptor table be NULL when applying "
5736 "relocation %s against local symbol"),
5737 input_bfd
, elfNN_aarch64_howto_table
[howto_index
].name
);
5741 off
= symbol_got_offset (input_bfd
, h
, r_symndx
);
5742 base_got
= globals
->root
.sgot
;
5743 got_entry_addr
= (base_got
->output_section
->vma
5744 + base_got
->output_offset
+ off
);
5746 if (!symbol_got_offset_mark_p (input_bfd
, h
, r_symndx
))
5748 bfd_put_64 (output_bfd
, value
, base_got
->contents
+ off
);
5750 /* For local symbol, we have done absolute relocation in static
5751 linking stage. While for shared library, we need to update the
5752 content of GOT entry according to the shared object's runtime
5753 base address. So, we need to generate a R_AARCH64_RELATIVE reloc
5754 for dynamic linker. */
5755 if (bfd_link_pic (info
))
5756 relative_reloc
= TRUE
;
5758 symbol_got_offset_mark (input_bfd
, h
, r_symndx
);
5761 /* Update the relocation value to GOT entry addr as we have transformed
5762 the direct data access into indirect data access through GOT. */
5763 value
= got_entry_addr
;
5765 if (aarch64_relocation_aginst_gp_p (bfd_r_type
))
5766 addend
= base_got
->output_section
->vma
+ base_got
->output_offset
;
5768 value
= _bfd_aarch64_elf_resolve_relocation (bfd_r_type
, place
, value
,
5769 addend
, weak_undef_p
);
5775 Elf_Internal_Rela outrel
;
5777 s
= globals
->root
.srelgot
;
5781 outrel
.r_offset
= got_entry_addr
;
5782 outrel
.r_info
= ELFNN_R_INFO (0, AARCH64_R (RELATIVE
));
5783 outrel
.r_addend
= orig_value
;
5784 elf_append_rela (output_bfd
, s
, &outrel
);
5788 case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC
:
5789 case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21
:
5790 case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21
:
5791 case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21
:
5792 case BFD_RELOC_AARCH64_TLSIE_LD32_GOTTPREL_LO12_NC
:
5793 case BFD_RELOC_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC
:
5794 case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19
:
5795 case BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC
:
5796 case BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21
:
5797 case BFD_RELOC_AARCH64_TLSLD_ADR_PREL21
:
5798 if (globals
->root
.sgot
== NULL
)
5799 return bfd_reloc_notsupported
;
5801 value
= (symbol_got_offset (input_bfd
, h
, r_symndx
)
5802 + globals
->root
.sgot
->output_section
->vma
5803 + globals
->root
.sgot
->output_offset
);
5805 value
= _bfd_aarch64_elf_resolve_relocation (bfd_r_type
, place
, value
,
5807 *unresolved_reloc_p
= FALSE
;
5810 case BFD_RELOC_AARCH64_TLSGD_MOVW_G0_NC
:
5811 case BFD_RELOC_AARCH64_TLSGD_MOVW_G1
:
5812 case BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G0_NC
:
5813 case BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G1
:
5814 if (globals
->root
.sgot
== NULL
)
5815 return bfd_reloc_notsupported
;
5817 value
= symbol_got_offset (input_bfd
, h
, r_symndx
);
5818 value
= _bfd_aarch64_elf_resolve_relocation (bfd_r_type
, place
, value
,
5820 *unresolved_reloc_p
= FALSE
;
5823 case BFD_RELOC_AARCH64_TLSLD_ADD_DTPREL_HI12
:
5824 case BFD_RELOC_AARCH64_TLSLD_ADD_DTPREL_LO12
:
5825 case BFD_RELOC_AARCH64_TLSLD_ADD_DTPREL_LO12_NC
:
5826 case BFD_RELOC_AARCH64_TLSLD_LDST16_DTPREL_LO12
:
5827 case BFD_RELOC_AARCH64_TLSLD_LDST16_DTPREL_LO12_NC
:
5828 case BFD_RELOC_AARCH64_TLSLD_LDST32_DTPREL_LO12
:
5829 case BFD_RELOC_AARCH64_TLSLD_LDST32_DTPREL_LO12_NC
:
5830 case BFD_RELOC_AARCH64_TLSLD_LDST64_DTPREL_LO12
:
5831 case BFD_RELOC_AARCH64_TLSLD_LDST64_DTPREL_LO12_NC
:
5832 case BFD_RELOC_AARCH64_TLSLD_LDST8_DTPREL_LO12
:
5833 case BFD_RELOC_AARCH64_TLSLD_LDST8_DTPREL_LO12_NC
:
5834 case BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G0
:
5835 case BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G0_NC
:
5836 case BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G1
:
5837 case BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G1_NC
:
5838 case BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G2
:
5839 value
= _bfd_aarch64_elf_resolve_relocation (bfd_r_type
, place
, value
,
5840 signed_addend
- dtpoff_base (info
),
5844 case BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_HI12
:
5845 case BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_LO12
:
5846 case BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_LO12_NC
:
5847 case BFD_RELOC_AARCH64_TLSLE_LDST16_TPREL_LO12
:
5848 case BFD_RELOC_AARCH64_TLSLE_LDST16_TPREL_LO12_NC
:
5849 case BFD_RELOC_AARCH64_TLSLE_LDST32_TPREL_LO12
:
5850 case BFD_RELOC_AARCH64_TLSLE_LDST32_TPREL_LO12_NC
:
5851 case BFD_RELOC_AARCH64_TLSLE_LDST64_TPREL_LO12
:
5852 case BFD_RELOC_AARCH64_TLSLE_LDST64_TPREL_LO12_NC
:
5853 case BFD_RELOC_AARCH64_TLSLE_LDST8_TPREL_LO12
:
5854 case BFD_RELOC_AARCH64_TLSLE_LDST8_TPREL_LO12_NC
:
5855 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0
:
5856 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC
:
5857 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1
:
5858 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1_NC
:
5859 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G2
:
5860 value
= _bfd_aarch64_elf_resolve_relocation (bfd_r_type
, place
, value
,
5861 signed_addend
- tpoff_base (info
),
5863 *unresolved_reloc_p
= FALSE
;
5866 case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12
:
5867 case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21
:
5868 case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21
:
5869 case BFD_RELOC_AARCH64_TLSDESC_LD32_LO12_NC
:
5870 case BFD_RELOC_AARCH64_TLSDESC_LD64_LO12
:
5871 case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19
:
5872 if (globals
->root
.sgot
== NULL
)
5873 return bfd_reloc_notsupported
;
5874 value
= (symbol_tlsdesc_got_offset (input_bfd
, h
, r_symndx
)
5875 + globals
->root
.sgotplt
->output_section
->vma
5876 + globals
->root
.sgotplt
->output_offset
5877 + globals
->sgotplt_jump_table_size
);
5879 value
= _bfd_aarch64_elf_resolve_relocation (bfd_r_type
, place
, value
,
5881 *unresolved_reloc_p
= FALSE
;
5884 case BFD_RELOC_AARCH64_TLSDESC_OFF_G0_NC
:
5885 case BFD_RELOC_AARCH64_TLSDESC_OFF_G1
:
5886 if (globals
->root
.sgot
== NULL
)
5887 return bfd_reloc_notsupported
;
5889 value
= (symbol_tlsdesc_got_offset (input_bfd
, h
, r_symndx
)
5890 + globals
->root
.sgotplt
->output_section
->vma
5891 + globals
->root
.sgotplt
->output_offset
5892 + globals
->sgotplt_jump_table_size
);
5894 value
-= (globals
->root
.sgot
->output_section
->vma
5895 + globals
->root
.sgot
->output_offset
);
5897 value
= _bfd_aarch64_elf_resolve_relocation (bfd_r_type
, place
, value
,
5899 *unresolved_reloc_p
= FALSE
;
5903 return bfd_reloc_notsupported
;
5907 *saved_addend
= value
;
5909 /* Only apply the final relocation in a sequence. */
5911 return bfd_reloc_continue
;
5913 return _bfd_aarch64_elf_put_addend (input_bfd
, hit_data
, bfd_r_type
,
5917 /* LP64 and ILP32 operates on x- and w-registers respectively.
5918 Next definitions take into account the difference between
5919 corresponding machine codes. R means x-register if the target
5920 arch is LP64, and w-register if the target is ILP32. */
5923 # define add_R0_R0 (0x91000000)
5924 # define add_R0_R0_R1 (0x8b000020)
5925 # define add_R0_R1 (0x91400020)
5926 # define ldr_R0 (0x58000000)
5927 # define ldr_R0_mask(i) (i & 0xffffffe0)
5928 # define ldr_R0_x0 (0xf9400000)
5929 # define ldr_hw_R0 (0xf2a00000)
5930 # define movk_R0 (0xf2800000)
5931 # define movz_R0 (0xd2a00000)
5932 # define movz_hw_R0 (0xd2c00000)
5933 #else /*ARCH_SIZE == 32 */
5934 # define add_R0_R0 (0x11000000)
5935 # define add_R0_R0_R1 (0x0b000020)
5936 # define add_R0_R1 (0x11400020)
5937 # define ldr_R0 (0x18000000)
5938 # define ldr_R0_mask(i) (i & 0xbfffffe0)
5939 # define ldr_R0_x0 (0xb9400000)
5940 # define ldr_hw_R0 (0x72a00000)
5941 # define movk_R0 (0x72800000)
5942 # define movz_R0 (0x52a00000)
5943 # define movz_hw_R0 (0x52c00000)
5946 /* Structure to hold payload for _bfd_aarch64_erratum_843419_clear_stub,
5947 it is used to identify the stub information to reset. */
5949 struct erratum_843419_branch_to_stub_clear_data
5951 bfd_vma adrp_offset
;
5952 asection
*output_section
;
5955 /* Clear the erratum information for GEN_ENTRY if the ADRP_OFFSET and
5956 section inside IN_ARG matches. The clearing is done by setting the
5957 stub_type to none. */
5960 _bfd_aarch64_erratum_843419_clear_stub (struct bfd_hash_entry
*gen_entry
,
5963 struct elf_aarch64_stub_hash_entry
*stub_entry
5964 = (struct elf_aarch64_stub_hash_entry
*) gen_entry
;
5965 struct erratum_843419_branch_to_stub_clear_data
*data
5966 = (struct erratum_843419_branch_to_stub_clear_data
*) in_arg
;
5968 if (stub_entry
->target_section
!= data
->output_section
5969 || stub_entry
->stub_type
!= aarch64_stub_erratum_843419_veneer
5970 || stub_entry
->adrp_offset
!= data
->adrp_offset
)
5973 /* Change the stub type instead of removing the entry, removing from the hash
5974 table would be slower and we have already reserved the memory for the entry
5975 so there wouldn't be much gain. Changing the stub also keeps around a
5976 record of what was there before. */
5977 stub_entry
->stub_type
= aarch64_stub_none
;
5979 /* We're done and there could have been only one matching stub at that
5980 particular offset, so abort further traversal. */
5984 /* TLS Relaxations may relax an adrp sequence that matches the erratum 843419
5985 sequence. In this case the erratum no longer applies and we need to remove
5986 the entry from the pending stub generation. This clears matching adrp insn
5987 at ADRP_OFFSET in INPUT_SECTION in the stub table defined in GLOBALS. */
5990 clear_erratum_843419_entry (struct elf_aarch64_link_hash_table
*globals
,
5991 bfd_vma adrp_offset
, asection
*input_section
)
5993 if (globals
->fix_erratum_843419
)
5995 struct erratum_843419_branch_to_stub_clear_data data
;
5996 data
.adrp_offset
= adrp_offset
;
5997 data
.output_section
= input_section
;
5999 bfd_hash_traverse (&globals
->stub_hash_table
,
6000 _bfd_aarch64_erratum_843419_clear_stub
, &data
);
6004 /* Handle TLS relaxations. Relaxing is possible for symbols that use
6005 R_AARCH64_TLSDESC_ADR_{PAGE, LD64_LO12_NC, ADD_LO12_NC} during a static
6008 Return bfd_reloc_ok if we're done, bfd_reloc_continue if the caller
6009 is to then call final_link_relocate. Return other values in the
6012 static bfd_reloc_status_type
6013 elfNN_aarch64_tls_relax (struct elf_aarch64_link_hash_table
*globals
,
6014 bfd
*input_bfd
, asection
*input_section
,
6015 bfd_byte
*contents
, Elf_Internal_Rela
*rel
,
6016 struct elf_link_hash_entry
*h
)
6018 bfd_boolean is_local
= h
== NULL
;
6019 unsigned int r_type
= ELFNN_R_TYPE (rel
->r_info
);
6022 BFD_ASSERT (globals
&& input_bfd
&& contents
&& rel
);
6024 switch (elfNN_aarch64_bfd_reloc_from_type (input_bfd
, r_type
))
6026 case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21
:
6027 case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21
:
6030 /* GD->LE relaxation:
6031 adrp x0, :tlsgd:var => movz R0, :tprel_g1:var
6033 adrp x0, :tlsdesc:var => movz R0, :tprel_g1:var
6035 Where R is x for LP64, and w for ILP32. */
6036 bfd_putl32 (movz_R0
, contents
+ rel
->r_offset
);
6037 /* We have relaxed the adrp into a mov, we may have to clear any
6038 pending erratum fixes. */
6039 clear_erratum_843419_entry (globals
, rel
->r_offset
, input_section
);
6040 return bfd_reloc_continue
;
6044 /* GD->IE relaxation:
6045 adrp x0, :tlsgd:var => adrp x0, :gottprel:var
6047 adrp x0, :tlsdesc:var => adrp x0, :gottprel:var
6049 return bfd_reloc_continue
;
6052 case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21
:
6056 case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19
:
6059 /* Tiny TLSDESC->LE relaxation:
6060 ldr x1, :tlsdesc:var => movz R0, #:tprel_g1:var
6061 adr x0, :tlsdesc:var => movk R0, #:tprel_g0_nc:var
6065 Where R is x for LP64, and w for ILP32. */
6066 BFD_ASSERT (ELFNN_R_TYPE (rel
[1].r_info
) == AARCH64_R (TLSDESC_ADR_PREL21
));
6067 BFD_ASSERT (ELFNN_R_TYPE (rel
[2].r_info
) == AARCH64_R (TLSDESC_CALL
));
6069 rel
[1].r_info
= ELFNN_R_INFO (ELFNN_R_SYM (rel
->r_info
),
6070 AARCH64_R (TLSLE_MOVW_TPREL_G0_NC
));
6071 rel
[2].r_info
= ELFNN_R_INFO (STN_UNDEF
, R_AARCH64_NONE
);
6073 bfd_putl32 (movz_R0
, contents
+ rel
->r_offset
);
6074 bfd_putl32 (movk_R0
, contents
+ rel
->r_offset
+ 4);
6075 bfd_putl32 (INSN_NOP
, contents
+ rel
->r_offset
+ 8);
6076 return bfd_reloc_continue
;
6080 /* Tiny TLSDESC->IE relaxation:
6081 ldr x1, :tlsdesc:var => ldr x0, :gottprel:var
6082 adr x0, :tlsdesc:var => nop
6086 BFD_ASSERT (ELFNN_R_TYPE (rel
[1].r_info
) == AARCH64_R (TLSDESC_ADR_PREL21
));
6087 BFD_ASSERT (ELFNN_R_TYPE (rel
[2].r_info
) == AARCH64_R (TLSDESC_CALL
));
6089 rel
[1].r_info
= ELFNN_R_INFO (STN_UNDEF
, R_AARCH64_NONE
);
6090 rel
[2].r_info
= ELFNN_R_INFO (STN_UNDEF
, R_AARCH64_NONE
);
6092 bfd_putl32 (ldr_R0
, contents
+ rel
->r_offset
);
6093 bfd_putl32 (INSN_NOP
, contents
+ rel
->r_offset
+ 4);
6094 bfd_putl32 (INSN_NOP
, contents
+ rel
->r_offset
+ 8);
6095 return bfd_reloc_continue
;
6098 case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21
:
6101 /* Tiny GD->LE relaxation:
6102 adr x0, :tlsgd:var => mrs x1, tpidr_el0
6103 bl __tls_get_addr => add R0, R1, #:tprel_hi12:x, lsl #12
6104 nop => add R0, R0, #:tprel_lo12_nc:x
6106 Where R is x for LP64, and x for Ilp32. */
6108 /* First kill the tls_get_addr reloc on the bl instruction. */
6109 BFD_ASSERT (rel
->r_offset
+ 4 == rel
[1].r_offset
);
6111 bfd_putl32 (0xd53bd041, contents
+ rel
->r_offset
+ 0);
6112 bfd_putl32 (add_R0_R1
, contents
+ rel
->r_offset
+ 4);
6113 bfd_putl32 (add_R0_R0
, contents
+ rel
->r_offset
+ 8);
6115 rel
[1].r_info
= ELFNN_R_INFO (ELFNN_R_SYM (rel
->r_info
),
6116 AARCH64_R (TLSLE_ADD_TPREL_LO12_NC
));
6117 rel
[1].r_offset
= rel
->r_offset
+ 8;
6119 /* Move the current relocation to the second instruction in
6122 rel
->r_info
= ELFNN_R_INFO (ELFNN_R_SYM (rel
->r_info
),
6123 AARCH64_R (TLSLE_ADD_TPREL_HI12
));
6124 return bfd_reloc_continue
;
6128 /* Tiny GD->IE relaxation:
6129 adr x0, :tlsgd:var => ldr R0, :gottprel:var
6130 bl __tls_get_addr => mrs x1, tpidr_el0
6131 nop => add R0, R0, R1
6133 Where R is x for LP64, and w for Ilp32. */
6135 /* First kill the tls_get_addr reloc on the bl instruction. */
6136 BFD_ASSERT (rel
->r_offset
+ 4 == rel
[1].r_offset
);
6137 rel
[1].r_info
= ELFNN_R_INFO (STN_UNDEF
, R_AARCH64_NONE
);
6139 bfd_putl32 (ldr_R0
, contents
+ rel
->r_offset
);
6140 bfd_putl32 (0xd53bd041, contents
+ rel
->r_offset
+ 4);
6141 bfd_putl32 (add_R0_R0_R1
, contents
+ rel
->r_offset
+ 8);
6142 return bfd_reloc_continue
;
6146 case BFD_RELOC_AARCH64_TLSGD_MOVW_G1
:
6147 BFD_ASSERT (ELFNN_R_TYPE (rel
[1].r_info
) == AARCH64_R (TLSGD_MOVW_G0_NC
));
6148 BFD_ASSERT (rel
->r_offset
+ 12 == rel
[2].r_offset
);
6149 BFD_ASSERT (ELFNN_R_TYPE (rel
[2].r_info
) == AARCH64_R (CALL26
));
6153 /* Large GD->LE relaxation:
6154 movz x0, #:tlsgd_g1:var => movz x0, #:tprel_g2:var, lsl #32
6155 movk x0, #:tlsgd_g0_nc:var => movk x0, #:tprel_g1_nc:var, lsl #16
6156 add x0, gp, x0 => movk x0, #:tprel_g0_nc:var
6157 bl __tls_get_addr => mrs x1, tpidr_el0
6158 nop => add x0, x0, x1
6160 rel
[2].r_info
= ELFNN_R_INFO (ELFNN_R_SYM (rel
->r_info
),
6161 AARCH64_R (TLSLE_MOVW_TPREL_G0_NC
));
6162 rel
[2].r_offset
= rel
->r_offset
+ 8;
6164 bfd_putl32 (movz_hw_R0
, contents
+ rel
->r_offset
+ 0);
6165 bfd_putl32 (ldr_hw_R0
, contents
+ rel
->r_offset
+ 4);
6166 bfd_putl32 (movk_R0
, contents
+ rel
->r_offset
+ 8);
6167 bfd_putl32 (0xd53bd041, contents
+ rel
->r_offset
+ 12);
6168 bfd_putl32 (add_R0_R0_R1
, contents
+ rel
->r_offset
+ 16);
6172 /* Large GD->IE relaxation:
6173 movz x0, #:tlsgd_g1:var => movz x0, #:gottprel_g1:var, lsl #16
6174 movk x0, #:tlsgd_g0_nc:var => movk x0, #:gottprel_g0_nc:var
6175 add x0, gp, x0 => ldr x0, [gp, x0]
6176 bl __tls_get_addr => mrs x1, tpidr_el0
6177 nop => add x0, x0, x1
6179 rel
[2].r_info
= ELFNN_R_INFO (STN_UNDEF
, R_AARCH64_NONE
);
6180 bfd_putl32 (0xd2a80000, contents
+ rel
->r_offset
+ 0);
6181 bfd_putl32 (ldr_R0
, contents
+ rel
->r_offset
+ 8);
6182 bfd_putl32 (0xd53bd041, contents
+ rel
->r_offset
+ 12);
6183 bfd_putl32 (add_R0_R0_R1
, contents
+ rel
->r_offset
+ 16);
6185 return bfd_reloc_continue
;
6187 case BFD_RELOC_AARCH64_TLSGD_MOVW_G0_NC
:
6188 return bfd_reloc_continue
;
6191 case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19
:
6192 return bfd_reloc_continue
;
6194 case BFD_RELOC_AARCH64_TLSDESC_LDNN_LO12_NC
:
6197 /* GD->LE relaxation:
6198 ldr xd, [x0, #:tlsdesc_lo12:var] => movk x0, :tprel_g0_nc:var
6200 Where R is x for lp64 mode, and w for ILP32 mode. */
6201 bfd_putl32 (movk_R0
, contents
+ rel
->r_offset
);
6202 return bfd_reloc_continue
;
6206 /* GD->IE relaxation:
6207 ldr xd, [x0, #:tlsdesc_lo12:var] => ldr R0, [x0, #:gottprel_lo12:var]
6209 Where R is x for lp64 mode, and w for ILP32 mode. */
6210 insn
= bfd_getl32 (contents
+ rel
->r_offset
);
6211 bfd_putl32 (ldr_R0_mask (insn
), contents
+ rel
->r_offset
);
6212 return bfd_reloc_continue
;
6215 case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC
:
6218 /* GD->LE relaxation
6219 add x0, #:tlsgd_lo12:var => movk R0, :tprel_g0_nc:var
6220 bl __tls_get_addr => mrs x1, tpidr_el0
6221 nop => add R0, R1, R0
6223 Where R is x for lp64 mode, and w for ILP32 mode. */
6225 /* First kill the tls_get_addr reloc on the bl instruction. */
6226 BFD_ASSERT (rel
->r_offset
+ 4 == rel
[1].r_offset
);
6227 rel
[1].r_info
= ELFNN_R_INFO (STN_UNDEF
, R_AARCH64_NONE
);
6229 bfd_putl32 (movk_R0
, contents
+ rel
->r_offset
);
6230 bfd_putl32 (0xd53bd041, contents
+ rel
->r_offset
+ 4);
6231 bfd_putl32 (add_R0_R0_R1
, contents
+ rel
->r_offset
+ 8);
6232 return bfd_reloc_continue
;
6236 /* GD->IE relaxation
6237 ADD x0, #:tlsgd_lo12:var => ldr R0, [x0, #:gottprel_lo12:var]
6238 BL __tls_get_addr => mrs x1, tpidr_el0
6240 NOP => add R0, R1, R0
6242 Where R is x for lp64 mode, and w for ilp32 mode. */
6244 BFD_ASSERT (ELFNN_R_TYPE (rel
[1].r_info
) == AARCH64_R (CALL26
));
6246 /* Remove the relocation on the BL instruction. */
6247 rel
[1].r_info
= ELFNN_R_INFO (STN_UNDEF
, R_AARCH64_NONE
);
6249 /* We choose to fixup the BL and NOP instructions using the
6250 offset from the second relocation to allow flexibility in
6251 scheduling instructions between the ADD and BL. */
6252 bfd_putl32 (ldr_R0_x0
, contents
+ rel
->r_offset
);
6253 bfd_putl32 (0xd53bd041, contents
+ rel
[1].r_offset
);
6254 bfd_putl32 (add_R0_R0_R1
, contents
+ rel
[1].r_offset
+ 4);
6255 return bfd_reloc_continue
;
6258 case BFD_RELOC_AARCH64_TLSDESC_ADD
:
6259 case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12
:
6260 case BFD_RELOC_AARCH64_TLSDESC_CALL
:
6261 /* GD->IE/LE relaxation:
6262 add x0, x0, #:tlsdesc_lo12:var => nop
6265 bfd_putl32 (INSN_NOP
, contents
+ rel
->r_offset
);
6266 return bfd_reloc_ok
;
6268 case BFD_RELOC_AARCH64_TLSDESC_LDR
:
6271 /* GD->LE relaxation:
6272 ldr xd, [gp, xn] => movk R0, #:tprel_g0_nc:var
6274 Where R is x for lp64 mode, and w for ILP32 mode. */
6275 bfd_putl32 (movk_R0
, contents
+ rel
->r_offset
);
6276 return bfd_reloc_continue
;
6280 /* GD->IE relaxation:
6281 ldr xd, [gp, xn] => ldr R0, [gp, xn]
6283 Where R is x for lp64 mode, and w for ILP32 mode. */
6284 insn
= bfd_getl32 (contents
+ rel
->r_offset
);
6285 bfd_putl32 (ldr_R0_mask (insn
), contents
+ rel
->r_offset
);
6286 return bfd_reloc_ok
;
6289 case BFD_RELOC_AARCH64_TLSDESC_OFF_G0_NC
:
6290 /* GD->LE relaxation:
6291 movk xd, #:tlsdesc_off_g0_nc:var => movk R0, #:tprel_g1_nc:var, lsl #16
6293 movk xd, #:tlsdesc_off_g0_nc:var => movk Rd, #:gottprel_g0_nc:var
6295 Where R is x for lp64 mode, and w for ILP32 mode. */
6297 bfd_putl32 (ldr_hw_R0
, contents
+ rel
->r_offset
);
6298 return bfd_reloc_continue
;
6300 case BFD_RELOC_AARCH64_TLSDESC_OFF_G1
:
6303 /* GD->LE relaxation:
6304 movz xd, #:tlsdesc_off_g1:var => movz R0, #:tprel_g2:var, lsl #32
6306 Where R is x for lp64 mode, and w for ILP32 mode. */
6307 bfd_putl32 (movz_hw_R0
, contents
+ rel
->r_offset
);
6308 return bfd_reloc_continue
;
6312 /* GD->IE relaxation:
6313 movz xd, #:tlsdesc_off_g1:var => movz Rd, #:gottprel_g1:var, lsl #16
6315 Where R is x for lp64 mode, and w for ILP32 mode. */
6316 insn
= bfd_getl32 (contents
+ rel
->r_offset
);
6317 bfd_putl32 (movz_R0
| (insn
& 0x1f), contents
+ rel
->r_offset
);
6318 return bfd_reloc_continue
;
6321 case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21
:
6322 /* IE->LE relaxation:
6323 adrp xd, :gottprel:var => movz Rd, :tprel_g1:var
6325 Where R is x for lp64 mode, and w for ILP32 mode. */
6328 insn
= bfd_getl32 (contents
+ rel
->r_offset
);
6329 bfd_putl32 (movz_R0
| (insn
& 0x1f), contents
+ rel
->r_offset
);
6330 /* We have relaxed the adrp into a mov, we may have to clear any
6331 pending erratum fixes. */
6332 clear_erratum_843419_entry (globals
, rel
->r_offset
, input_section
);
6334 return bfd_reloc_continue
;
6336 case BFD_RELOC_AARCH64_TLSIE_LDNN_GOTTPREL_LO12_NC
:
6337 /* IE->LE relaxation:
6338 ldr xd, [xm, #:gottprel_lo12:var] => movk Rd, :tprel_g0_nc:var
6340 Where R is x for lp64 mode, and w for ILP32 mode. */
6343 insn
= bfd_getl32 (contents
+ rel
->r_offset
);
6344 bfd_putl32 (movk_R0
| (insn
& 0x1f), contents
+ rel
->r_offset
);
6346 return bfd_reloc_continue
;
6348 case BFD_RELOC_AARCH64_TLSLD_ADR_PREL21
:
6349 /* LD->LE relaxation (tiny):
6350 adr x0, :tlsldm:x => mrs x0, tpidr_el0
6351 bl __tls_get_addr => add R0, R0, TCB_SIZE
6353 Where R is x for lp64 mode, and w for ilp32 mode. */
6356 BFD_ASSERT (rel
->r_offset
+ 4 == rel
[1].r_offset
);
6357 BFD_ASSERT (ELFNN_R_TYPE (rel
[1].r_info
) == AARCH64_R (CALL26
));
6358 /* No need of CALL26 relocation for tls_get_addr. */
6359 rel
[1].r_info
= ELFNN_R_INFO (STN_UNDEF
, R_AARCH64_NONE
);
6360 bfd_putl32 (0xd53bd040, contents
+ rel
->r_offset
+ 0);
6361 bfd_putl32 (add_R0_R0
| (TCB_SIZE
<< 10),
6362 contents
+ rel
->r_offset
+ 4);
6363 return bfd_reloc_ok
;
6365 return bfd_reloc_continue
;
6367 case BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21
:
6368 /* LD->LE relaxation (small):
6369 adrp x0, :tlsldm:x => mrs x0, tpidr_el0
6373 bfd_putl32 (0xd53bd040, contents
+ rel
->r_offset
);
6374 return bfd_reloc_ok
;
6376 return bfd_reloc_continue
;
6378 case BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC
:
6379 /* LD->LE relaxation (small):
6380 add x0, #:tlsldm_lo12:x => add R0, R0, TCB_SIZE
6381 bl __tls_get_addr => nop
6383 Where R is x for lp64 mode, and w for ilp32 mode. */
6386 BFD_ASSERT (rel
->r_offset
+ 4 == rel
[1].r_offset
);
6387 BFD_ASSERT (ELFNN_R_TYPE (rel
[1].r_info
) == AARCH64_R (CALL26
));
6388 /* No need of CALL26 relocation for tls_get_addr. */
6389 rel
[1].r_info
= ELFNN_R_INFO (STN_UNDEF
, R_AARCH64_NONE
);
6390 bfd_putl32 (add_R0_R0
| (TCB_SIZE
<< 10),
6391 contents
+ rel
->r_offset
+ 0);
6392 bfd_putl32 (INSN_NOP
, contents
+ rel
->r_offset
+ 4);
6393 return bfd_reloc_ok
;
6395 return bfd_reloc_continue
;
6398 return bfd_reloc_continue
;
6401 return bfd_reloc_ok
;
6404 /* Relocate an AArch64 ELF section. */
6407 elfNN_aarch64_relocate_section (bfd
*output_bfd
,
6408 struct bfd_link_info
*info
,
6410 asection
*input_section
,
6412 Elf_Internal_Rela
*relocs
,
6413 Elf_Internal_Sym
*local_syms
,
6414 asection
**local_sections
)
6416 Elf_Internal_Shdr
*symtab_hdr
;
6417 struct elf_link_hash_entry
**sym_hashes
;
6418 Elf_Internal_Rela
*rel
;
6419 Elf_Internal_Rela
*relend
;
6421 struct elf_aarch64_link_hash_table
*globals
;
6422 bfd_boolean save_addend
= FALSE
;
6425 globals
= elf_aarch64_hash_table (info
);
6427 symtab_hdr
= &elf_symtab_hdr (input_bfd
);
6428 sym_hashes
= elf_sym_hashes (input_bfd
);
6431 relend
= relocs
+ input_section
->reloc_count
;
6432 for (; rel
< relend
; rel
++)
6434 unsigned int r_type
;
6435 bfd_reloc_code_real_type bfd_r_type
;
6436 bfd_reloc_code_real_type relaxed_bfd_r_type
;
6437 reloc_howto_type
*howto
;
6438 unsigned long r_symndx
;
6439 Elf_Internal_Sym
*sym
;
6441 struct elf_link_hash_entry
*h
;
6443 bfd_reloc_status_type r
;
6446 bfd_boolean unresolved_reloc
= FALSE
;
6447 char *error_message
= NULL
;
6449 r_symndx
= ELFNN_R_SYM (rel
->r_info
);
6450 r_type
= ELFNN_R_TYPE (rel
->r_info
);
6452 bfd_reloc
.howto
= elfNN_aarch64_howto_from_type (input_bfd
, r_type
);
6453 howto
= bfd_reloc
.howto
;
6456 return _bfd_unrecognized_reloc (input_bfd
, input_section
, r_type
);
6458 bfd_r_type
= elfNN_aarch64_bfd_reloc_from_howto (howto
);
6464 if (r_symndx
< symtab_hdr
->sh_info
)
6466 sym
= local_syms
+ r_symndx
;
6467 sym_type
= ELFNN_ST_TYPE (sym
->st_info
);
6468 sec
= local_sections
[r_symndx
];
6470 /* An object file might have a reference to a local
6471 undefined symbol. This is a daft object file, but we
6472 should at least do something about it. */
6473 if (r_type
!= R_AARCH64_NONE
&& r_type
!= R_AARCH64_NULL
6474 && bfd_is_und_section (sec
)
6475 && ELF_ST_BIND (sym
->st_info
) != STB_WEAK
)
6476 (*info
->callbacks
->undefined_symbol
)
6477 (info
, bfd_elf_string_from_elf_section
6478 (input_bfd
, symtab_hdr
->sh_link
, sym
->st_name
),
6479 input_bfd
, input_section
, rel
->r_offset
, TRUE
);
6481 relocation
= _bfd_elf_rela_local_sym (output_bfd
, sym
, &sec
, rel
);
6483 /* Relocate against local STT_GNU_IFUNC symbol. */
6484 if (!bfd_link_relocatable (info
)
6485 && ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
)
6487 h
= elfNN_aarch64_get_local_sym_hash (globals
, input_bfd
,
6492 /* Set STT_GNU_IFUNC symbol value. */
6493 h
->root
.u
.def
.value
= sym
->st_value
;
6494 h
->root
.u
.def
.section
= sec
;
6499 bfd_boolean warned
, ignored
;
6501 RELOC_FOR_GLOBAL_SYMBOL (info
, input_bfd
, input_section
, rel
,
6502 r_symndx
, symtab_hdr
, sym_hashes
,
6504 unresolved_reloc
, warned
, ignored
);
6509 if (sec
!= NULL
&& discarded_section (sec
))
6510 RELOC_AGAINST_DISCARDED_SECTION (info
, input_bfd
, input_section
,
6511 rel
, 1, relend
, howto
, 0, contents
);
6513 if (bfd_link_relocatable (info
))
6517 name
= h
->root
.root
.string
;
6520 name
= (bfd_elf_string_from_elf_section
6521 (input_bfd
, symtab_hdr
->sh_link
, sym
->st_name
));
6522 if (name
== NULL
|| *name
== '\0')
6523 name
= bfd_section_name (input_bfd
, sec
);
6527 && r_type
!= R_AARCH64_NONE
6528 && r_type
!= R_AARCH64_NULL
6530 || h
->root
.type
== bfd_link_hash_defined
6531 || h
->root
.type
== bfd_link_hash_defweak
)
6532 && IS_AARCH64_TLS_RELOC (bfd_r_type
) != (sym_type
== STT_TLS
))
6535 ((sym_type
== STT_TLS
6536 /* xgettext:c-format */
6537 ? _("%pB(%pA+%#" PRIx64
"): %s used with TLS symbol %s")
6538 /* xgettext:c-format */
6539 : _("%pB(%pA+%#" PRIx64
"): %s used with non-TLS symbol %s")),
6541 input_section
, (uint64_t) rel
->r_offset
, howto
->name
, name
);
6544 /* We relax only if we can see that there can be a valid transition
6545 from a reloc type to another.
6546 We call elfNN_aarch64_final_link_relocate unless we're completely
6547 done, i.e., the relaxation produced the final output we want. */
6549 relaxed_bfd_r_type
= aarch64_tls_transition (input_bfd
, info
, r_type
,
6551 if (relaxed_bfd_r_type
!= bfd_r_type
)
6553 bfd_r_type
= relaxed_bfd_r_type
;
6554 howto
= elfNN_aarch64_howto_from_bfd_reloc (bfd_r_type
);
6555 BFD_ASSERT (howto
!= NULL
);
6556 r_type
= howto
->type
;
6557 r
= elfNN_aarch64_tls_relax (globals
, input_bfd
, input_section
,
6559 unresolved_reloc
= 0;
6562 r
= bfd_reloc_continue
;
6564 /* There may be multiple consecutive relocations for the
6565 same offset. In that case we are supposed to treat the
6566 output of each relocation as the addend for the next. */
6567 if (rel
+ 1 < relend
6568 && rel
->r_offset
== rel
[1].r_offset
6569 && ELFNN_R_TYPE (rel
[1].r_info
) != R_AARCH64_NONE
6570 && ELFNN_R_TYPE (rel
[1].r_info
) != R_AARCH64_NULL
)
6573 save_addend
= FALSE
;
6575 if (r
== bfd_reloc_continue
)
6576 r
= elfNN_aarch64_final_link_relocate (howto
, input_bfd
, output_bfd
,
6577 input_section
, contents
, rel
,
6578 relocation
, info
, sec
,
6579 h
, &unresolved_reloc
,
6580 save_addend
, &addend
, sym
);
6582 switch (elfNN_aarch64_bfd_reloc_from_type (input_bfd
, r_type
))
6584 case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC
:
6585 case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21
:
6586 case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21
:
6587 case BFD_RELOC_AARCH64_TLSGD_MOVW_G0_NC
:
6588 case BFD_RELOC_AARCH64_TLSGD_MOVW_G1
:
6589 case BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC
:
6590 case BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21
:
6591 case BFD_RELOC_AARCH64_TLSLD_ADR_PREL21
:
6592 if (! symbol_got_offset_mark_p (input_bfd
, h
, r_symndx
))
6594 bfd_boolean need_relocs
= FALSE
;
6599 off
= symbol_got_offset (input_bfd
, h
, r_symndx
);
6600 indx
= h
&& h
->dynindx
!= -1 ? h
->dynindx
: 0;
6603 (!bfd_link_executable (info
) || indx
!= 0) &&
6605 || ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
6606 || h
->root
.type
!= bfd_link_hash_undefweak
);
6608 BFD_ASSERT (globals
->root
.srelgot
!= NULL
);
6612 Elf_Internal_Rela rela
;
6613 rela
.r_info
= ELFNN_R_INFO (indx
, AARCH64_R (TLS_DTPMOD
));
6615 rela
.r_offset
= globals
->root
.sgot
->output_section
->vma
+
6616 globals
->root
.sgot
->output_offset
+ off
;
6619 loc
= globals
->root
.srelgot
->contents
;
6620 loc
+= globals
->root
.srelgot
->reloc_count
++
6621 * RELOC_SIZE (htab
);
6622 bfd_elfNN_swap_reloca_out (output_bfd
, &rela
, loc
);
6624 bfd_reloc_code_real_type real_type
=
6625 elfNN_aarch64_bfd_reloc_from_type (input_bfd
, r_type
);
6627 if (real_type
== BFD_RELOC_AARCH64_TLSLD_ADR_PREL21
6628 || real_type
== BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21
6629 || real_type
== BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC
)
6631 /* For local dynamic, don't generate DTPREL in any case.
6632 Initialize the DTPREL slot into zero, so we get module
6633 base address when invoke runtime TLS resolver. */
6634 bfd_put_NN (output_bfd
, 0,
6635 globals
->root
.sgot
->contents
+ off
6640 bfd_put_NN (output_bfd
,
6641 relocation
- dtpoff_base (info
),
6642 globals
->root
.sgot
->contents
+ off
6647 /* This TLS symbol is global. We emit a
6648 relocation to fixup the tls offset at load
6651 ELFNN_R_INFO (indx
, AARCH64_R (TLS_DTPREL
));
6654 (globals
->root
.sgot
->output_section
->vma
6655 + globals
->root
.sgot
->output_offset
+ off
6658 loc
= globals
->root
.srelgot
->contents
;
6659 loc
+= globals
->root
.srelgot
->reloc_count
++
6660 * RELOC_SIZE (globals
);
6661 bfd_elfNN_swap_reloca_out (output_bfd
, &rela
, loc
);
6662 bfd_put_NN (output_bfd
, (bfd_vma
) 0,
6663 globals
->root
.sgot
->contents
+ off
6669 bfd_put_NN (output_bfd
, (bfd_vma
) 1,
6670 globals
->root
.sgot
->contents
+ off
);
6671 bfd_put_NN (output_bfd
,
6672 relocation
- dtpoff_base (info
),
6673 globals
->root
.sgot
->contents
+ off
6677 symbol_got_offset_mark (input_bfd
, h
, r_symndx
);
6681 case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21
:
6682 case BFD_RELOC_AARCH64_TLSIE_LDNN_GOTTPREL_LO12_NC
:
6683 case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19
:
6684 case BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G0_NC
:
6685 case BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G1
:
6686 if (! symbol_got_offset_mark_p (input_bfd
, h
, r_symndx
))
6688 bfd_boolean need_relocs
= FALSE
;
6693 off
= symbol_got_offset (input_bfd
, h
, r_symndx
);
6695 indx
= h
&& h
->dynindx
!= -1 ? h
->dynindx
: 0;
6698 (!bfd_link_executable (info
) || indx
!= 0) &&
6700 || ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
6701 || h
->root
.type
!= bfd_link_hash_undefweak
);
6703 BFD_ASSERT (globals
->root
.srelgot
!= NULL
);
6707 Elf_Internal_Rela rela
;
6710 rela
.r_addend
= relocation
- dtpoff_base (info
);
6714 rela
.r_info
= ELFNN_R_INFO (indx
, AARCH64_R (TLS_TPREL
));
6715 rela
.r_offset
= globals
->root
.sgot
->output_section
->vma
+
6716 globals
->root
.sgot
->output_offset
+ off
;
6718 loc
= globals
->root
.srelgot
->contents
;
6719 loc
+= globals
->root
.srelgot
->reloc_count
++
6720 * RELOC_SIZE (htab
);
6722 bfd_elfNN_swap_reloca_out (output_bfd
, &rela
, loc
);
6724 bfd_put_NN (output_bfd
, rela
.r_addend
,
6725 globals
->root
.sgot
->contents
+ off
);
6728 bfd_put_NN (output_bfd
, relocation
- tpoff_base (info
),
6729 globals
->root
.sgot
->contents
+ off
);
6731 symbol_got_offset_mark (input_bfd
, h
, r_symndx
);
6735 case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12
:
6736 case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21
:
6737 case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21
:
6738 case BFD_RELOC_AARCH64_TLSDESC_LDNN_LO12_NC
:
6739 case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19
:
6740 case BFD_RELOC_AARCH64_TLSDESC_OFF_G0_NC
:
6741 case BFD_RELOC_AARCH64_TLSDESC_OFF_G1
:
6742 if (! symbol_tlsdesc_got_offset_mark_p (input_bfd
, h
, r_symndx
))
6744 bfd_boolean need_relocs
= FALSE
;
6745 int indx
= h
&& h
->dynindx
!= -1 ? h
->dynindx
: 0;
6746 bfd_vma off
= symbol_tlsdesc_got_offset (input_bfd
, h
, r_symndx
);
6748 need_relocs
= (h
== NULL
6749 || ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
6750 || h
->root
.type
!= bfd_link_hash_undefweak
);
6752 BFD_ASSERT (globals
->root
.srelgot
!= NULL
);
6753 BFD_ASSERT (globals
->root
.sgot
!= NULL
);
6758 Elf_Internal_Rela rela
;
6759 rela
.r_info
= ELFNN_R_INFO (indx
, AARCH64_R (TLSDESC
));
6762 rela
.r_offset
= (globals
->root
.sgotplt
->output_section
->vma
6763 + globals
->root
.sgotplt
->output_offset
6764 + off
+ globals
->sgotplt_jump_table_size
);
6767 rela
.r_addend
= relocation
- dtpoff_base (info
);
6769 /* Allocate the next available slot in the PLT reloc
6770 section to hold our R_AARCH64_TLSDESC, the next
6771 available slot is determined from reloc_count,
6772 which we step. But note, reloc_count was
6773 artifically moved down while allocating slots for
6774 real PLT relocs such that all of the PLT relocs
6775 will fit above the initial reloc_count and the
6776 extra stuff will fit below. */
6777 loc
= globals
->root
.srelplt
->contents
;
6778 loc
+= globals
->root
.srelplt
->reloc_count
++
6779 * RELOC_SIZE (globals
);
6781 bfd_elfNN_swap_reloca_out (output_bfd
, &rela
, loc
);
6783 bfd_put_NN (output_bfd
, (bfd_vma
) 0,
6784 globals
->root
.sgotplt
->contents
+ off
+
6785 globals
->sgotplt_jump_table_size
);
6786 bfd_put_NN (output_bfd
, (bfd_vma
) 0,
6787 globals
->root
.sgotplt
->contents
+ off
+
6788 globals
->sgotplt_jump_table_size
+
6792 symbol_tlsdesc_got_offset_mark (input_bfd
, h
, r_symndx
);
6799 /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
6800 because such sections are not SEC_ALLOC and thus ld.so will
6801 not process them. */
6802 if (unresolved_reloc
6803 && !((input_section
->flags
& SEC_DEBUGGING
) != 0
6805 && _bfd_elf_section_offset (output_bfd
, info
, input_section
,
6806 +rel
->r_offset
) != (bfd_vma
) - 1)
6809 /* xgettext:c-format */
6810 (_("%pB(%pA+%#" PRIx64
"): "
6811 "unresolvable %s relocation against symbol `%s'"),
6812 input_bfd
, input_section
, (uint64_t) rel
->r_offset
, howto
->name
,
6813 h
->root
.root
.string
);
6817 if (r
!= bfd_reloc_ok
&& r
!= bfd_reloc_continue
)
6819 bfd_reloc_code_real_type real_r_type
6820 = elfNN_aarch64_bfd_reloc_from_type (input_bfd
, r_type
);
6824 case bfd_reloc_overflow
:
6825 (*info
->callbacks
->reloc_overflow
)
6826 (info
, (h
? &h
->root
: NULL
), name
, howto
->name
, (bfd_vma
) 0,
6827 input_bfd
, input_section
, rel
->r_offset
);
6828 if (real_r_type
== BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15
6829 || real_r_type
== BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14
)
6831 (*info
->callbacks
->warning
)
6833 _("too many GOT entries for -fpic, "
6834 "please recompile with -fPIC"),
6835 name
, input_bfd
, input_section
, rel
->r_offset
);
6838 /* Overflow can occur when a variable is referenced with a type
6839 that has a larger alignment than the type with which it was
6841 file1.c: extern int foo; int a (void) { return foo; }
6842 file2.c: char bar, foo, baz;
6843 If the variable is placed into a data section at an offset
6844 that is incompatible with the larger alignment requirement
6845 overflow will occur. (Strictly speaking this is not overflow
6846 but rather an alignment problem, but the bfd_reloc_ error
6847 enum does not have a value to cover that situation).
6849 Try to catch this situation here and provide a more helpful
6850 error message to the user. */
6851 if (addend
& ((1 << howto
->rightshift
) - 1)
6852 /* FIXME: Are we testing all of the appropriate reloc
6854 && (real_r_type
== BFD_RELOC_AARCH64_LD_LO19_PCREL
6855 || real_r_type
== BFD_RELOC_AARCH64_LDST16_LO12
6856 || real_r_type
== BFD_RELOC_AARCH64_LDST32_LO12
6857 || real_r_type
== BFD_RELOC_AARCH64_LDST64_LO12
6858 || real_r_type
== BFD_RELOC_AARCH64_LDST128_LO12
))
6860 info
->callbacks
->warning
6861 (info
, _("one possible cause of this error is that the \
6862 symbol is being referenced in the indicated code as if it had a larger \
6863 alignment than was declared where it was defined"),
6864 name
, input_bfd
, input_section
, rel
->r_offset
);
6868 case bfd_reloc_undefined
:
6869 (*info
->callbacks
->undefined_symbol
)
6870 (info
, name
, input_bfd
, input_section
, rel
->r_offset
, TRUE
);
6873 case bfd_reloc_outofrange
:
6874 error_message
= _("out of range");
6877 case bfd_reloc_notsupported
:
6878 error_message
= _("unsupported relocation");
6881 case bfd_reloc_dangerous
:
6882 /* error_message should already be set. */
6886 error_message
= _("unknown error");
6890 BFD_ASSERT (error_message
!= NULL
);
6891 (*info
->callbacks
->reloc_dangerous
)
6892 (info
, error_message
, input_bfd
, input_section
, rel
->r_offset
);
6904 /* Set the right machine number. */
6907 elfNN_aarch64_object_p (bfd
*abfd
)
6910 bfd_default_set_arch_mach (abfd
, bfd_arch_aarch64
, bfd_mach_aarch64_ilp32
);
6912 bfd_default_set_arch_mach (abfd
, bfd_arch_aarch64
, bfd_mach_aarch64
);
6917 /* Function to keep AArch64 specific flags in the ELF header. */
6920 elfNN_aarch64_set_private_flags (bfd
*abfd
, flagword flags
)
6922 if (elf_flags_init (abfd
) && elf_elfheader (abfd
)->e_flags
!= flags
)
6927 elf_elfheader (abfd
)->e_flags
= flags
;
6928 elf_flags_init (abfd
) = TRUE
;
6934 /* Merge backend specific data from an object file to the output
6935 object file when linking. */
6938 elfNN_aarch64_merge_private_bfd_data (bfd
*ibfd
, struct bfd_link_info
*info
)
6940 bfd
*obfd
= info
->output_bfd
;
6943 bfd_boolean flags_compatible
= TRUE
;
6946 /* Check if we have the same endianess. */
6947 if (!_bfd_generic_verify_endian_match (ibfd
, info
))
6950 if (!is_aarch64_elf (ibfd
) || !is_aarch64_elf (obfd
))
6953 /* The input BFD must have had its flags initialised. */
6954 /* The following seems bogus to me -- The flags are initialized in
6955 the assembler but I don't think an elf_flags_init field is
6956 written into the object. */
6957 /* BFD_ASSERT (elf_flags_init (ibfd)); */
6959 in_flags
= elf_elfheader (ibfd
)->e_flags
;
6960 out_flags
= elf_elfheader (obfd
)->e_flags
;
6962 if (!elf_flags_init (obfd
))
6964 /* If the input is the default architecture and had the default
6965 flags then do not bother setting the flags for the output
6966 architecture, instead allow future merges to do this. If no
6967 future merges ever set these flags then they will retain their
6968 uninitialised values, which surprise surprise, correspond
6969 to the default values. */
6970 if (bfd_get_arch_info (ibfd
)->the_default
6971 && elf_elfheader (ibfd
)->e_flags
== 0)
6974 elf_flags_init (obfd
) = TRUE
;
6975 elf_elfheader (obfd
)->e_flags
= in_flags
;
6977 if (bfd_get_arch (obfd
) == bfd_get_arch (ibfd
)
6978 && bfd_get_arch_info (obfd
)->the_default
)
6979 return bfd_set_arch_mach (obfd
, bfd_get_arch (ibfd
),
6980 bfd_get_mach (ibfd
));
6985 /* Identical flags must be compatible. */
6986 if (in_flags
== out_flags
)
6989 /* Check to see if the input BFD actually contains any sections. If
6990 not, its flags may not have been initialised either, but it
6991 cannot actually cause any incompatiblity. Do not short-circuit
6992 dynamic objects; their section list may be emptied by
6993 elf_link_add_object_symbols.
6995 Also check to see if there are no code sections in the input.
6996 In this case there is no need to check for code specific flags.
6997 XXX - do we need to worry about floating-point format compatability
6998 in data sections ? */
6999 if (!(ibfd
->flags
& DYNAMIC
))
7001 bfd_boolean null_input_bfd
= TRUE
;
7002 bfd_boolean only_data_sections
= TRUE
;
7004 for (sec
= ibfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
7006 if ((bfd_get_section_flags (ibfd
, sec
)
7007 & (SEC_LOAD
| SEC_CODE
| SEC_HAS_CONTENTS
))
7008 == (SEC_LOAD
| SEC_CODE
| SEC_HAS_CONTENTS
))
7009 only_data_sections
= FALSE
;
7011 null_input_bfd
= FALSE
;
7015 if (null_input_bfd
|| only_data_sections
)
7019 return flags_compatible
;
7022 /* Display the flags field. */
7025 elfNN_aarch64_print_private_bfd_data (bfd
*abfd
, void *ptr
)
7027 FILE *file
= (FILE *) ptr
;
7028 unsigned long flags
;
7030 BFD_ASSERT (abfd
!= NULL
&& ptr
!= NULL
);
7032 /* Print normal ELF private data. */
7033 _bfd_elf_print_private_bfd_data (abfd
, ptr
);
7035 flags
= elf_elfheader (abfd
)->e_flags
;
7036 /* Ignore init flag - it may not be set, despite the flags field
7037 containing valid data. */
7039 /* xgettext:c-format */
7040 fprintf (file
, _("private flags = %lx:"), elf_elfheader (abfd
)->e_flags
);
7043 fprintf (file
, _("<Unrecognised flag bits set>"));
7050 /* Find dynamic relocs for H that apply to read-only sections. */
7053 readonly_dynrelocs (struct elf_link_hash_entry
*h
)
7055 struct elf_dyn_relocs
*p
;
7057 for (p
= elf_aarch64_hash_entry (h
)->dyn_relocs
; p
!= NULL
; p
= p
->next
)
7059 asection
*s
= p
->sec
->output_section
;
7061 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
7067 /* Return true if we need copy relocation against EH. */
7070 need_copy_relocation_p (struct elf_aarch64_link_hash_entry
*eh
)
7072 struct elf_dyn_relocs
*p
;
7075 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
7077 /* If there is any pc-relative reference, we need to keep copy relocation
7078 to avoid propagating the relocation into runtime that current glibc
7079 does not support. */
7083 s
= p
->sec
->output_section
;
7084 /* Need copy relocation if it's against read-only section. */
7085 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
7092 /* Adjust a symbol defined by a dynamic object and referenced by a
7093 regular object. The current definition is in some section of the
7094 dynamic object, but we're not including those sections. We have to
7095 change the definition to something the rest of the link can
7099 elfNN_aarch64_adjust_dynamic_symbol (struct bfd_link_info
*info
,
7100 struct elf_link_hash_entry
*h
)
7102 struct elf_aarch64_link_hash_table
*htab
;
7105 /* If this is a function, put it in the procedure linkage table. We
7106 will fill in the contents of the procedure linkage table later,
7107 when we know the address of the .got section. */
7108 if (h
->type
== STT_FUNC
|| h
->type
== STT_GNU_IFUNC
|| h
->needs_plt
)
7110 if (h
->plt
.refcount
<= 0
7111 || (h
->type
!= STT_GNU_IFUNC
7112 && (SYMBOL_CALLS_LOCAL (info
, h
)
7113 || (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
7114 && h
->root
.type
== bfd_link_hash_undefweak
))))
7116 /* This case can occur if we saw a CALL26 reloc in
7117 an input file, but the symbol wasn't referred to
7118 by a dynamic object or all references were
7119 garbage collected. In which case we can end up
7121 h
->plt
.offset
= (bfd_vma
) - 1;
7128 /* Otherwise, reset to -1. */
7129 h
->plt
.offset
= (bfd_vma
) - 1;
7132 /* If this is a weak symbol, and there is a real definition, the
7133 processor independent code will have arranged for us to see the
7134 real definition first, and we can just use the same value. */
7135 if (h
->is_weakalias
)
7137 struct elf_link_hash_entry
*def
= weakdef (h
);
7138 BFD_ASSERT (def
->root
.type
== bfd_link_hash_defined
);
7139 h
->root
.u
.def
.section
= def
->root
.u
.def
.section
;
7140 h
->root
.u
.def
.value
= def
->root
.u
.def
.value
;
7141 if (ELIMINATE_COPY_RELOCS
|| info
->nocopyreloc
)
7142 h
->non_got_ref
= def
->non_got_ref
;
7146 /* If we are creating a shared library, we must presume that the
7147 only references to the symbol are via the global offset table.
7148 For such cases we need not do anything here; the relocations will
7149 be handled correctly by relocate_section. */
7150 if (bfd_link_pic (info
))
7153 /* If there are no references to this symbol that do not use the
7154 GOT, we don't need to generate a copy reloc. */
7155 if (!h
->non_got_ref
)
7158 /* If -z nocopyreloc was given, we won't generate them either. */
7159 if (info
->nocopyreloc
)
7165 if (ELIMINATE_COPY_RELOCS
)
7167 struct elf_aarch64_link_hash_entry
*eh
;
7168 /* If we don't find any dynamic relocs in read-only sections, then
7169 we'll be keeping the dynamic relocs and avoiding the copy reloc. */
7170 eh
= (struct elf_aarch64_link_hash_entry
*) h
;
7171 if (!need_copy_relocation_p (eh
))
7178 /* We must allocate the symbol in our .dynbss section, which will
7179 become part of the .bss section of the executable. There will be
7180 an entry for this symbol in the .dynsym section. The dynamic
7181 object will contain position independent code, so all references
7182 from the dynamic object to this symbol will go through the global
7183 offset table. The dynamic linker will use the .dynsym entry to
7184 determine the address it must put in the global offset table, so
7185 both the dynamic object and the regular object will refer to the
7186 same memory location for the variable. */
7188 htab
= elf_aarch64_hash_table (info
);
7190 /* We must generate a R_AARCH64_COPY reloc to tell the dynamic linker
7191 to copy the initial value out of the dynamic object and into the
7192 runtime process image. */
7193 if ((h
->root
.u
.def
.section
->flags
& SEC_READONLY
) != 0)
7195 s
= htab
->root
.sdynrelro
;
7196 srel
= htab
->root
.sreldynrelro
;
7200 s
= htab
->root
.sdynbss
;
7201 srel
= htab
->root
.srelbss
;
7203 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0 && h
->size
!= 0)
7205 srel
->size
+= RELOC_SIZE (htab
);
7209 return _bfd_elf_adjust_dynamic_copy (info
, h
, s
);
7214 elfNN_aarch64_allocate_local_symbols (bfd
*abfd
, unsigned number
)
7216 struct elf_aarch64_local_symbol
*locals
;
7217 locals
= elf_aarch64_locals (abfd
);
7220 locals
= (struct elf_aarch64_local_symbol
*)
7221 bfd_zalloc (abfd
, number
* sizeof (struct elf_aarch64_local_symbol
));
7224 elf_aarch64_locals (abfd
) = locals
;
7229 /* Create the .got section to hold the global offset table. */
7232 aarch64_elf_create_got_section (bfd
*abfd
, struct bfd_link_info
*info
)
7234 const struct elf_backend_data
*bed
= get_elf_backend_data (abfd
);
7237 struct elf_link_hash_entry
*h
;
7238 struct elf_link_hash_table
*htab
= elf_hash_table (info
);
7240 /* This function may be called more than once. */
7241 if (htab
->sgot
!= NULL
)
7244 flags
= bed
->dynamic_sec_flags
;
7246 s
= bfd_make_section_anyway_with_flags (abfd
,
7247 (bed
->rela_plts_and_copies_p
7248 ? ".rela.got" : ".rel.got"),
7249 (bed
->dynamic_sec_flags
7252 || ! bfd_set_section_alignment (abfd
, s
, bed
->s
->log_file_align
))
7256 s
= bfd_make_section_anyway_with_flags (abfd
, ".got", flags
);
7258 || !bfd_set_section_alignment (abfd
, s
, bed
->s
->log_file_align
))
7261 htab
->sgot
->size
+= GOT_ENTRY_SIZE
;
7263 if (bed
->want_got_sym
)
7265 /* Define the symbol _GLOBAL_OFFSET_TABLE_ at the start of the .got
7266 (or .got.plt) section. We don't do this in the linker script
7267 because we don't want to define the symbol if we are not creating
7268 a global offset table. */
7269 h
= _bfd_elf_define_linkage_sym (abfd
, info
, s
,
7270 "_GLOBAL_OFFSET_TABLE_");
7271 elf_hash_table (info
)->hgot
= h
;
7276 if (bed
->want_got_plt
)
7278 s
= bfd_make_section_anyway_with_flags (abfd
, ".got.plt", flags
);
7280 || !bfd_set_section_alignment (abfd
, s
,
7281 bed
->s
->log_file_align
))
7286 /* The first bit of the global offset table is the header. */
7287 s
->size
+= bed
->got_header_size
;
7292 /* Look through the relocs for a section during the first phase. */
7295 elfNN_aarch64_check_relocs (bfd
*abfd
, struct bfd_link_info
*info
,
7296 asection
*sec
, const Elf_Internal_Rela
*relocs
)
7298 Elf_Internal_Shdr
*symtab_hdr
;
7299 struct elf_link_hash_entry
**sym_hashes
;
7300 const Elf_Internal_Rela
*rel
;
7301 const Elf_Internal_Rela
*rel_end
;
7304 struct elf_aarch64_link_hash_table
*htab
;
7306 if (bfd_link_relocatable (info
))
7309 BFD_ASSERT (is_aarch64_elf (abfd
));
7311 htab
= elf_aarch64_hash_table (info
);
7314 symtab_hdr
= &elf_symtab_hdr (abfd
);
7315 sym_hashes
= elf_sym_hashes (abfd
);
7317 rel_end
= relocs
+ sec
->reloc_count
;
7318 for (rel
= relocs
; rel
< rel_end
; rel
++)
7320 struct elf_link_hash_entry
*h
;
7321 unsigned int r_symndx
;
7322 unsigned int r_type
;
7323 bfd_reloc_code_real_type bfd_r_type
;
7324 Elf_Internal_Sym
*isym
;
7326 r_symndx
= ELFNN_R_SYM (rel
->r_info
);
7327 r_type
= ELFNN_R_TYPE (rel
->r_info
);
7329 if (r_symndx
>= NUM_SHDR_ENTRIES (symtab_hdr
))
7331 /* xgettext:c-format */
7332 _bfd_error_handler (_("%pB: bad symbol index: %d"), abfd
, r_symndx
);
7336 if (r_symndx
< symtab_hdr
->sh_info
)
7338 /* A local symbol. */
7339 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
7344 /* Check relocation against local STT_GNU_IFUNC symbol. */
7345 if (ELF_ST_TYPE (isym
->st_info
) == STT_GNU_IFUNC
)
7347 h
= elfNN_aarch64_get_local_sym_hash (htab
, abfd
, rel
,
7352 /* Fake a STT_GNU_IFUNC symbol. */
7353 h
->type
= STT_GNU_IFUNC
;
7356 h
->forced_local
= 1;
7357 h
->root
.type
= bfd_link_hash_defined
;
7364 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
7365 while (h
->root
.type
== bfd_link_hash_indirect
7366 || h
->root
.type
== bfd_link_hash_warning
)
7367 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
7370 /* Could be done earlier, if h were already available. */
7371 bfd_r_type
= aarch64_tls_transition (abfd
, info
, r_type
, h
, r_symndx
);
7375 /* If a relocation refers to _GLOBAL_OFFSET_TABLE_, create the .got.
7376 This shows up in particular in an R_AARCH64_PREL64 in large model
7377 when calculating the pc-relative address to .got section which is
7378 used to initialize the gp register. */
7379 if (h
->root
.root
.string
7380 && strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_") == 0)
7382 if (htab
->root
.dynobj
== NULL
)
7383 htab
->root
.dynobj
= abfd
;
7385 if (! aarch64_elf_create_got_section (htab
->root
.dynobj
, info
))
7388 BFD_ASSERT (h
== htab
->root
.hgot
);
7391 /* Create the ifunc sections for static executables. If we
7392 never see an indirect function symbol nor we are building
7393 a static executable, those sections will be empty and
7394 won't appear in output. */
7400 case BFD_RELOC_AARCH64_ADD_LO12
:
7401 case BFD_RELOC_AARCH64_ADR_GOT_PAGE
:
7402 case BFD_RELOC_AARCH64_ADR_HI21_PCREL
:
7403 case BFD_RELOC_AARCH64_CALL26
:
7404 case BFD_RELOC_AARCH64_GOT_LD_PREL19
:
7405 case BFD_RELOC_AARCH64_JUMP26
:
7406 case BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14
:
7407 case BFD_RELOC_AARCH64_LD32_GOT_LO12_NC
:
7408 case BFD_RELOC_AARCH64_LD64_GOTOFF_LO15
:
7409 case BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15
:
7410 case BFD_RELOC_AARCH64_LD64_GOT_LO12_NC
:
7411 case BFD_RELOC_AARCH64_MOVW_GOTOFF_G0_NC
:
7412 case BFD_RELOC_AARCH64_MOVW_GOTOFF_G1
:
7413 case BFD_RELOC_AARCH64_NN
:
7414 if (htab
->root
.dynobj
== NULL
)
7415 htab
->root
.dynobj
= abfd
;
7416 if (!_bfd_elf_create_ifunc_sections (htab
->root
.dynobj
, info
))
7421 /* It is referenced by a non-shared object. */
7427 case BFD_RELOC_AARCH64_16
:
7429 case BFD_RELOC_AARCH64_32
:
7431 if (bfd_link_pic (info
) && (sec
->flags
& SEC_ALLOC
) != 0)
7434 /* This is an absolute symbol. It represents a value instead
7436 && (bfd_is_abs_symbol (&h
->root
)
7437 /* This is an undefined symbol. */
7438 || h
->root
.type
== bfd_link_hash_undefined
))
7441 /* For local symbols, defined global symbols in a non-ABS section,
7442 it is assumed that the value is an address. */
7443 int howto_index
= bfd_r_type
- BFD_RELOC_AARCH64_RELOC_START
;
7445 /* xgettext:c-format */
7446 (_("%pB: relocation %s against `%s' can not be used when making "
7448 abfd
, elfNN_aarch64_howto_table
[howto_index
].name
,
7449 (h
) ? h
->root
.root
.string
: "a local symbol");
7450 bfd_set_error (bfd_error_bad_value
);
7456 case BFD_RELOC_AARCH64_MOVW_G0_NC
:
7457 case BFD_RELOC_AARCH64_MOVW_G1_NC
:
7458 case BFD_RELOC_AARCH64_MOVW_G2_NC
:
7459 case BFD_RELOC_AARCH64_MOVW_G3
:
7460 if (bfd_link_pic (info
))
7462 int howto_index
= bfd_r_type
- BFD_RELOC_AARCH64_RELOC_START
;
7464 /* xgettext:c-format */
7465 (_("%pB: relocation %s against `%s' can not be used when making "
7466 "a shared object; recompile with -fPIC"),
7467 abfd
, elfNN_aarch64_howto_table
[howto_index
].name
,
7468 (h
) ? h
->root
.root
.string
: "a local symbol");
7469 bfd_set_error (bfd_error_bad_value
);
7474 case BFD_RELOC_AARCH64_16_PCREL
:
7475 case BFD_RELOC_AARCH64_32_PCREL
:
7476 case BFD_RELOC_AARCH64_64_PCREL
:
7477 case BFD_RELOC_AARCH64_ADD_LO12
:
7478 case BFD_RELOC_AARCH64_ADR_HI21_NC_PCREL
:
7479 case BFD_RELOC_AARCH64_ADR_HI21_PCREL
:
7480 case BFD_RELOC_AARCH64_ADR_LO21_PCREL
:
7481 case BFD_RELOC_AARCH64_LDST128_LO12
:
7482 case BFD_RELOC_AARCH64_LDST16_LO12
:
7483 case BFD_RELOC_AARCH64_LDST32_LO12
:
7484 case BFD_RELOC_AARCH64_LDST64_LO12
:
7485 case BFD_RELOC_AARCH64_LDST8_LO12
:
7486 case BFD_RELOC_AARCH64_LD_LO19_PCREL
:
7487 if (h
== NULL
|| bfd_link_pic (info
))
7491 case BFD_RELOC_AARCH64_NN
:
7493 /* We don't need to handle relocs into sections not going into
7494 the "real" output. */
7495 if ((sec
->flags
& SEC_ALLOC
) == 0)
7500 if (!bfd_link_pic (info
))
7503 h
->plt
.refcount
+= 1;
7504 h
->pointer_equality_needed
= 1;
7507 /* No need to do anything if we're not creating a shared
7509 if (!(bfd_link_pic (info
)
7510 /* If on the other hand, we are creating an executable, we
7511 may need to keep relocations for symbols satisfied by a
7512 dynamic library if we manage to avoid copy relocs for the
7515 NOTE: Currently, there is no support of copy relocs
7516 elimination on pc-relative relocation types, because there is
7517 no dynamic relocation support for them in glibc. We still
7518 record the dynamic symbol reference for them. This is
7519 because one symbol may be referenced by both absolute
7520 relocation (for example, BFD_RELOC_AARCH64_NN) and
7521 pc-relative relocation. We need full symbol reference
7522 information to make correct decision later in
7523 elfNN_aarch64_adjust_dynamic_symbol. */
7524 || (ELIMINATE_COPY_RELOCS
7525 && !bfd_link_pic (info
)
7527 && (h
->root
.type
== bfd_link_hash_defweak
7528 || !h
->def_regular
))))
7532 struct elf_dyn_relocs
*p
;
7533 struct elf_dyn_relocs
**head
;
7534 int howto_index
= bfd_r_type
- BFD_RELOC_AARCH64_RELOC_START
;
7536 /* We must copy these reloc types into the output file.
7537 Create a reloc section in dynobj and make room for
7541 if (htab
->root
.dynobj
== NULL
)
7542 htab
->root
.dynobj
= abfd
;
7544 sreloc
= _bfd_elf_make_dynamic_reloc_section
7545 (sec
, htab
->root
.dynobj
, LOG_FILE_ALIGN
, abfd
, /*rela? */ TRUE
);
7551 /* If this is a global symbol, we count the number of
7552 relocations we need for this symbol. */
7555 struct elf_aarch64_link_hash_entry
*eh
;
7556 eh
= (struct elf_aarch64_link_hash_entry
*) h
;
7557 head
= &eh
->dyn_relocs
;
7561 /* Track dynamic relocs needed for local syms too.
7562 We really need local syms available to do this
7568 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
7573 s
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
7577 /* Beware of type punned pointers vs strict aliasing
7579 vpp
= &(elf_section_data (s
)->local_dynrel
);
7580 head
= (struct elf_dyn_relocs
**) vpp
;
7584 if (p
== NULL
|| p
->sec
!= sec
)
7586 bfd_size_type amt
= sizeof *p
;
7587 p
= ((struct elf_dyn_relocs
*)
7588 bfd_zalloc (htab
->root
.dynobj
, amt
));
7598 if (elfNN_aarch64_howto_table
[howto_index
].pc_relative
)
7603 /* RR: We probably want to keep a consistency check that
7604 there are no dangling GOT_PAGE relocs. */
7605 case BFD_RELOC_AARCH64_ADR_GOT_PAGE
:
7606 case BFD_RELOC_AARCH64_GOT_LD_PREL19
:
7607 case BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14
:
7608 case BFD_RELOC_AARCH64_LD32_GOT_LO12_NC
:
7609 case BFD_RELOC_AARCH64_LD64_GOTOFF_LO15
:
7610 case BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15
:
7611 case BFD_RELOC_AARCH64_LD64_GOT_LO12_NC
:
7612 case BFD_RELOC_AARCH64_MOVW_GOTOFF_G0_NC
:
7613 case BFD_RELOC_AARCH64_MOVW_GOTOFF_G1
:
7614 case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12
:
7615 case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21
:
7616 case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21
:
7617 case BFD_RELOC_AARCH64_TLSDESC_LD32_LO12_NC
:
7618 case BFD_RELOC_AARCH64_TLSDESC_LD64_LO12
:
7619 case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19
:
7620 case BFD_RELOC_AARCH64_TLSDESC_OFF_G0_NC
:
7621 case BFD_RELOC_AARCH64_TLSDESC_OFF_G1
:
7622 case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC
:
7623 case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21
:
7624 case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21
:
7625 case BFD_RELOC_AARCH64_TLSGD_MOVW_G0_NC
:
7626 case BFD_RELOC_AARCH64_TLSGD_MOVW_G1
:
7627 case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21
:
7628 case BFD_RELOC_AARCH64_TLSIE_LD32_GOTTPREL_LO12_NC
:
7629 case BFD_RELOC_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC
:
7630 case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19
:
7631 case BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G0_NC
:
7632 case BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G1
:
7633 case BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC
:
7634 case BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21
:
7635 case BFD_RELOC_AARCH64_TLSLD_ADR_PREL21
:
7638 unsigned old_got_type
;
7640 got_type
= aarch64_reloc_got_type (bfd_r_type
);
7644 h
->got
.refcount
+= 1;
7645 old_got_type
= elf_aarch64_hash_entry (h
)->got_type
;
7649 struct elf_aarch64_local_symbol
*locals
;
7651 if (!elfNN_aarch64_allocate_local_symbols
7652 (abfd
, symtab_hdr
->sh_info
))
7655 locals
= elf_aarch64_locals (abfd
);
7656 BFD_ASSERT (r_symndx
< symtab_hdr
->sh_info
);
7657 locals
[r_symndx
].got_refcount
+= 1;
7658 old_got_type
= locals
[r_symndx
].got_type
;
7661 /* If a variable is accessed with both general dynamic TLS
7662 methods, two slots may be created. */
7663 if (GOT_TLS_GD_ANY_P (old_got_type
) && GOT_TLS_GD_ANY_P (got_type
))
7664 got_type
|= old_got_type
;
7666 /* We will already have issued an error message if there
7667 is a TLS/non-TLS mismatch, based on the symbol type.
7668 So just combine any TLS types needed. */
7669 if (old_got_type
!= GOT_UNKNOWN
&& old_got_type
!= GOT_NORMAL
7670 && got_type
!= GOT_NORMAL
)
7671 got_type
|= old_got_type
;
7673 /* If the symbol is accessed by both IE and GD methods, we
7674 are able to relax. Turn off the GD flag, without
7675 messing up with any other kind of TLS types that may be
7677 if ((got_type
& GOT_TLS_IE
) && GOT_TLS_GD_ANY_P (got_type
))
7678 got_type
&= ~ (GOT_TLSDESC_GD
| GOT_TLS_GD
);
7680 if (old_got_type
!= got_type
)
7683 elf_aarch64_hash_entry (h
)->got_type
= got_type
;
7686 struct elf_aarch64_local_symbol
*locals
;
7687 locals
= elf_aarch64_locals (abfd
);
7688 BFD_ASSERT (r_symndx
< symtab_hdr
->sh_info
);
7689 locals
[r_symndx
].got_type
= got_type
;
7693 if (htab
->root
.dynobj
== NULL
)
7694 htab
->root
.dynobj
= abfd
;
7695 if (! aarch64_elf_create_got_section (htab
->root
.dynobj
, info
))
7700 case BFD_RELOC_AARCH64_CALL26
:
7701 case BFD_RELOC_AARCH64_JUMP26
:
7702 /* If this is a local symbol then we resolve it
7703 directly without creating a PLT entry. */
7708 if (h
->plt
.refcount
<= 0)
7709 h
->plt
.refcount
= 1;
7711 h
->plt
.refcount
+= 1;
7722 /* Treat mapping symbols as special target symbols. */
7725 elfNN_aarch64_is_target_special_symbol (bfd
*abfd ATTRIBUTE_UNUSED
,
7728 return bfd_is_aarch64_special_symbol_name (sym
->name
,
7729 BFD_AARCH64_SPECIAL_SYM_TYPE_ANY
);
7732 /* This is a copy of elf_find_function () from elf.c except that
7733 AArch64 mapping symbols are ignored when looking for function names. */
7736 aarch64_elf_find_function (bfd
*abfd ATTRIBUTE_UNUSED
,
7740 const char **filename_ptr
,
7741 const char **functionname_ptr
)
7743 const char *filename
= NULL
;
7744 asymbol
*func
= NULL
;
7745 bfd_vma low_func
= 0;
7748 for (p
= symbols
; *p
!= NULL
; p
++)
7752 q
= (elf_symbol_type
*) * p
;
7754 switch (ELF_ST_TYPE (q
->internal_elf_sym
.st_info
))
7759 filename
= bfd_asymbol_name (&q
->symbol
);
7763 /* Skip mapping symbols. */
7764 if ((q
->symbol
.flags
& BSF_LOCAL
)
7765 && (bfd_is_aarch64_special_symbol_name
7766 (q
->symbol
.name
, BFD_AARCH64_SPECIAL_SYM_TYPE_ANY
)))
7769 if (bfd_get_section (&q
->symbol
) == section
7770 && q
->symbol
.value
>= low_func
&& q
->symbol
.value
<= offset
)
7772 func
= (asymbol
*) q
;
7773 low_func
= q
->symbol
.value
;
7783 *filename_ptr
= filename
;
7784 if (functionname_ptr
)
7785 *functionname_ptr
= bfd_asymbol_name (func
);
7791 /* Find the nearest line to a particular section and offset, for error
7792 reporting. This code is a duplicate of the code in elf.c, except
7793 that it uses aarch64_elf_find_function. */
7796 elfNN_aarch64_find_nearest_line (bfd
*abfd
,
7800 const char **filename_ptr
,
7801 const char **functionname_ptr
,
7802 unsigned int *line_ptr
,
7803 unsigned int *discriminator_ptr
)
7805 bfd_boolean found
= FALSE
;
7807 if (_bfd_dwarf2_find_nearest_line (abfd
, symbols
, NULL
, section
, offset
,
7808 filename_ptr
, functionname_ptr
,
7809 line_ptr
, discriminator_ptr
,
7810 dwarf_debug_sections
, 0,
7811 &elf_tdata (abfd
)->dwarf2_find_line_info
))
7813 if (!*functionname_ptr
)
7814 aarch64_elf_find_function (abfd
, symbols
, section
, offset
,
7815 *filename_ptr
? NULL
: filename_ptr
,
7821 /* Skip _bfd_dwarf1_find_nearest_line since no known AArch64
7822 toolchain uses DWARF1. */
7824 if (!_bfd_stab_section_find_nearest_line (abfd
, symbols
, section
, offset
,
7825 &found
, filename_ptr
,
7826 functionname_ptr
, line_ptr
,
7827 &elf_tdata (abfd
)->line_info
))
7830 if (found
&& (*functionname_ptr
|| *line_ptr
))
7833 if (symbols
== NULL
)
7836 if (!aarch64_elf_find_function (abfd
, symbols
, section
, offset
,
7837 filename_ptr
, functionname_ptr
))
7845 elfNN_aarch64_find_inliner_info (bfd
*abfd
,
7846 const char **filename_ptr
,
7847 const char **functionname_ptr
,
7848 unsigned int *line_ptr
)
7851 found
= _bfd_dwarf2_find_inliner_info
7852 (abfd
, filename_ptr
,
7853 functionname_ptr
, line_ptr
, &elf_tdata (abfd
)->dwarf2_find_line_info
);
7859 elfNN_aarch64_post_process_headers (bfd
*abfd
,
7860 struct bfd_link_info
*link_info
)
7862 Elf_Internal_Ehdr
*i_ehdrp
; /* ELF file header, internal form. */
7864 i_ehdrp
= elf_elfheader (abfd
);
7865 i_ehdrp
->e_ident
[EI_ABIVERSION
] = AARCH64_ELF_ABI_VERSION
;
7867 _bfd_elf_post_process_headers (abfd
, link_info
);
7870 static enum elf_reloc_type_class
7871 elfNN_aarch64_reloc_type_class (const struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
7872 const asection
*rel_sec ATTRIBUTE_UNUSED
,
7873 const Elf_Internal_Rela
*rela
)
7875 struct elf_aarch64_link_hash_table
*htab
= elf_aarch64_hash_table (info
);
7877 if (htab
->root
.dynsym
!= NULL
7878 && htab
->root
.dynsym
->contents
!= NULL
)
7880 /* Check relocation against STT_GNU_IFUNC symbol if there are
7882 bfd
*abfd
= info
->output_bfd
;
7883 const struct elf_backend_data
*bed
= get_elf_backend_data (abfd
);
7884 unsigned long r_symndx
= ELFNN_R_SYM (rela
->r_info
);
7885 if (r_symndx
!= STN_UNDEF
)
7887 Elf_Internal_Sym sym
;
7888 if (!bed
->s
->swap_symbol_in (abfd
,
7889 (htab
->root
.dynsym
->contents
7890 + r_symndx
* bed
->s
->sizeof_sym
),
7893 /* xgettext:c-format */
7894 _bfd_error_handler (_("%pB symbol number %lu references"
7895 " nonexistent SHT_SYMTAB_SHNDX section"),
7897 /* Ideally an error class should be returned here. */
7899 else if (ELF_ST_TYPE (sym
.st_info
) == STT_GNU_IFUNC
)
7900 return reloc_class_ifunc
;
7904 switch ((int) ELFNN_R_TYPE (rela
->r_info
))
7906 case AARCH64_R (IRELATIVE
):
7907 return reloc_class_ifunc
;
7908 case AARCH64_R (RELATIVE
):
7909 return reloc_class_relative
;
7910 case AARCH64_R (JUMP_SLOT
):
7911 return reloc_class_plt
;
7912 case AARCH64_R (COPY
):
7913 return reloc_class_copy
;
7915 return reloc_class_normal
;
7919 /* Handle an AArch64 specific section when reading an object file. This is
7920 called when bfd_section_from_shdr finds a section with an unknown
7924 elfNN_aarch64_section_from_shdr (bfd
*abfd
,
7925 Elf_Internal_Shdr
*hdr
,
7926 const char *name
, int shindex
)
7928 /* There ought to be a place to keep ELF backend specific flags, but
7929 at the moment there isn't one. We just keep track of the
7930 sections by their name, instead. Fortunately, the ABI gives
7931 names for all the AArch64 specific sections, so we will probably get
7933 switch (hdr
->sh_type
)
7935 case SHT_AARCH64_ATTRIBUTES
:
7942 if (!_bfd_elf_make_section_from_shdr (abfd
, hdr
, name
, shindex
))
7948 /* A structure used to record a list of sections, independently
7949 of the next and prev fields in the asection structure. */
7950 typedef struct section_list
7953 struct section_list
*next
;
7954 struct section_list
*prev
;
7958 /* Unfortunately we need to keep a list of sections for which
7959 an _aarch64_elf_section_data structure has been allocated. This
7960 is because it is possible for functions like elfNN_aarch64_write_section
7961 to be called on a section which has had an elf_data_structure
7962 allocated for it (and so the used_by_bfd field is valid) but
7963 for which the AArch64 extended version of this structure - the
7964 _aarch64_elf_section_data structure - has not been allocated. */
7965 static section_list
*sections_with_aarch64_elf_section_data
= NULL
;
7968 record_section_with_aarch64_elf_section_data (asection
*sec
)
7970 struct section_list
*entry
;
7972 entry
= bfd_malloc (sizeof (*entry
));
7976 entry
->next
= sections_with_aarch64_elf_section_data
;
7978 if (entry
->next
!= NULL
)
7979 entry
->next
->prev
= entry
;
7980 sections_with_aarch64_elf_section_data
= entry
;
7983 static struct section_list
*
7984 find_aarch64_elf_section_entry (asection
*sec
)
7986 struct section_list
*entry
;
7987 static struct section_list
*last_entry
= NULL
;
7989 /* This is a short cut for the typical case where the sections are added
7990 to the sections_with_aarch64_elf_section_data list in forward order and
7991 then looked up here in backwards order. This makes a real difference
7992 to the ld-srec/sec64k.exp linker test. */
7993 entry
= sections_with_aarch64_elf_section_data
;
7994 if (last_entry
!= NULL
)
7996 if (last_entry
->sec
== sec
)
7998 else if (last_entry
->next
!= NULL
&& last_entry
->next
->sec
== sec
)
7999 entry
= last_entry
->next
;
8002 for (; entry
; entry
= entry
->next
)
8003 if (entry
->sec
== sec
)
8007 /* Record the entry prior to this one - it is the entry we are
8008 most likely to want to locate next time. Also this way if we
8009 have been called from
8010 unrecord_section_with_aarch64_elf_section_data () we will not
8011 be caching a pointer that is about to be freed. */
8012 last_entry
= entry
->prev
;
8018 unrecord_section_with_aarch64_elf_section_data (asection
*sec
)
8020 struct section_list
*entry
;
8022 entry
= find_aarch64_elf_section_entry (sec
);
8026 if (entry
->prev
!= NULL
)
8027 entry
->prev
->next
= entry
->next
;
8028 if (entry
->next
!= NULL
)
8029 entry
->next
->prev
= entry
->prev
;
8030 if (entry
== sections_with_aarch64_elf_section_data
)
8031 sections_with_aarch64_elf_section_data
= entry
->next
;
8040 struct bfd_link_info
*info
;
8043 int (*func
) (void *, const char *, Elf_Internal_Sym
*,
8044 asection
*, struct elf_link_hash_entry
*);
8045 } output_arch_syminfo
;
8047 enum map_symbol_type
8054 /* Output a single mapping symbol. */
8057 elfNN_aarch64_output_map_sym (output_arch_syminfo
*osi
,
8058 enum map_symbol_type type
, bfd_vma offset
)
8060 static const char *names
[2] = { "$x", "$d" };
8061 Elf_Internal_Sym sym
;
8063 sym
.st_value
= (osi
->sec
->output_section
->vma
8064 + osi
->sec
->output_offset
+ offset
);
8067 sym
.st_info
= ELF_ST_INFO (STB_LOCAL
, STT_NOTYPE
);
8068 sym
.st_shndx
= osi
->sec_shndx
;
8069 return osi
->func (osi
->finfo
, names
[type
], &sym
, osi
->sec
, NULL
) == 1;
8072 /* Output a single local symbol for a generated stub. */
8075 elfNN_aarch64_output_stub_sym (output_arch_syminfo
*osi
, const char *name
,
8076 bfd_vma offset
, bfd_vma size
)
8078 Elf_Internal_Sym sym
;
8080 sym
.st_value
= (osi
->sec
->output_section
->vma
8081 + osi
->sec
->output_offset
+ offset
);
8084 sym
.st_info
= ELF_ST_INFO (STB_LOCAL
, STT_FUNC
);
8085 sym
.st_shndx
= osi
->sec_shndx
;
8086 return osi
->func (osi
->finfo
, name
, &sym
, osi
->sec
, NULL
) == 1;
8090 aarch64_map_one_stub (struct bfd_hash_entry
*gen_entry
, void *in_arg
)
8092 struct elf_aarch64_stub_hash_entry
*stub_entry
;
8096 output_arch_syminfo
*osi
;
8098 /* Massage our args to the form they really have. */
8099 stub_entry
= (struct elf_aarch64_stub_hash_entry
*) gen_entry
;
8100 osi
= (output_arch_syminfo
*) in_arg
;
8102 stub_sec
= stub_entry
->stub_sec
;
8104 /* Ensure this stub is attached to the current section being
8106 if (stub_sec
!= osi
->sec
)
8109 addr
= (bfd_vma
) stub_entry
->stub_offset
;
8111 stub_name
= stub_entry
->output_name
;
8113 switch (stub_entry
->stub_type
)
8115 case aarch64_stub_adrp_branch
:
8116 if (!elfNN_aarch64_output_stub_sym (osi
, stub_name
, addr
,
8117 sizeof (aarch64_adrp_branch_stub
)))
8119 if (!elfNN_aarch64_output_map_sym (osi
, AARCH64_MAP_INSN
, addr
))
8122 case aarch64_stub_long_branch
:
8123 if (!elfNN_aarch64_output_stub_sym
8124 (osi
, stub_name
, addr
, sizeof (aarch64_long_branch_stub
)))
8126 if (!elfNN_aarch64_output_map_sym (osi
, AARCH64_MAP_INSN
, addr
))
8128 if (!elfNN_aarch64_output_map_sym (osi
, AARCH64_MAP_DATA
, addr
+ 16))
8131 case aarch64_stub_erratum_835769_veneer
:
8132 if (!elfNN_aarch64_output_stub_sym (osi
, stub_name
, addr
,
8133 sizeof (aarch64_erratum_835769_stub
)))
8135 if (!elfNN_aarch64_output_map_sym (osi
, AARCH64_MAP_INSN
, addr
))
8138 case aarch64_stub_erratum_843419_veneer
:
8139 if (!elfNN_aarch64_output_stub_sym (osi
, stub_name
, addr
,
8140 sizeof (aarch64_erratum_843419_stub
)))
8142 if (!elfNN_aarch64_output_map_sym (osi
, AARCH64_MAP_INSN
, addr
))
8145 case aarch64_stub_none
:
8155 /* Output mapping symbols for linker generated sections. */
8158 elfNN_aarch64_output_arch_local_syms (bfd
*output_bfd
,
8159 struct bfd_link_info
*info
,
8161 int (*func
) (void *, const char *,
8164 struct elf_link_hash_entry
8167 output_arch_syminfo osi
;
8168 struct elf_aarch64_link_hash_table
*htab
;
8170 htab
= elf_aarch64_hash_table (info
);
8176 /* Long calls stubs. */
8177 if (htab
->stub_bfd
&& htab
->stub_bfd
->sections
)
8181 for (stub_sec
= htab
->stub_bfd
->sections
;
8182 stub_sec
!= NULL
; stub_sec
= stub_sec
->next
)
8184 /* Ignore non-stub sections. */
8185 if (!strstr (stub_sec
->name
, STUB_SUFFIX
))
8190 osi
.sec_shndx
= _bfd_elf_section_from_bfd_section
8191 (output_bfd
, osi
.sec
->output_section
);
8193 /* The first instruction in a stub is always a branch. */
8194 if (!elfNN_aarch64_output_map_sym (&osi
, AARCH64_MAP_INSN
, 0))
8197 bfd_hash_traverse (&htab
->stub_hash_table
, aarch64_map_one_stub
,
8202 /* Finally, output mapping symbols for the PLT. */
8203 if (!htab
->root
.splt
|| htab
->root
.splt
->size
== 0)
8206 osi
.sec_shndx
= _bfd_elf_section_from_bfd_section
8207 (output_bfd
, htab
->root
.splt
->output_section
);
8208 osi
.sec
= htab
->root
.splt
;
8210 elfNN_aarch64_output_map_sym (&osi
, AARCH64_MAP_INSN
, 0);
8216 /* Allocate target specific section data. */
8219 elfNN_aarch64_new_section_hook (bfd
*abfd
, asection
*sec
)
8221 if (!sec
->used_by_bfd
)
8223 _aarch64_elf_section_data
*sdata
;
8224 bfd_size_type amt
= sizeof (*sdata
);
8226 sdata
= bfd_zalloc (abfd
, amt
);
8229 sec
->used_by_bfd
= sdata
;
8232 record_section_with_aarch64_elf_section_data (sec
);
8234 return _bfd_elf_new_section_hook (abfd
, sec
);
8239 unrecord_section_via_map_over_sections (bfd
*abfd ATTRIBUTE_UNUSED
,
8241 void *ignore ATTRIBUTE_UNUSED
)
8243 unrecord_section_with_aarch64_elf_section_data (sec
);
8247 elfNN_aarch64_close_and_cleanup (bfd
*abfd
)
8250 bfd_map_over_sections (abfd
,
8251 unrecord_section_via_map_over_sections
, NULL
);
8253 return _bfd_elf_close_and_cleanup (abfd
);
8257 elfNN_aarch64_bfd_free_cached_info (bfd
*abfd
)
8260 bfd_map_over_sections (abfd
,
8261 unrecord_section_via_map_over_sections
, NULL
);
8263 return _bfd_free_cached_info (abfd
);
8266 /* Create dynamic sections. This is different from the ARM backend in that
8267 the got, plt, gotplt and their relocation sections are all created in the
8268 standard part of the bfd elf backend. */
8271 elfNN_aarch64_create_dynamic_sections (bfd
*dynobj
,
8272 struct bfd_link_info
*info
)
8274 /* We need to create .got section. */
8275 if (!aarch64_elf_create_got_section (dynobj
, info
))
8278 return _bfd_elf_create_dynamic_sections (dynobj
, info
);
8282 /* Allocate space in .plt, .got and associated reloc sections for
8286 elfNN_aarch64_allocate_dynrelocs (struct elf_link_hash_entry
*h
, void *inf
)
8288 struct bfd_link_info
*info
;
8289 struct elf_aarch64_link_hash_table
*htab
;
8290 struct elf_aarch64_link_hash_entry
*eh
;
8291 struct elf_dyn_relocs
*p
;
8293 /* An example of a bfd_link_hash_indirect symbol is versioned
8294 symbol. For example: __gxx_personality_v0(bfd_link_hash_indirect)
8295 -> __gxx_personality_v0(bfd_link_hash_defined)
8297 There is no need to process bfd_link_hash_indirect symbols here
8298 because we will also be presented with the concrete instance of
8299 the symbol and elfNN_aarch64_copy_indirect_symbol () will have been
8300 called to copy all relevant data from the generic to the concrete
8302 if (h
->root
.type
== bfd_link_hash_indirect
)
8305 if (h
->root
.type
== bfd_link_hash_warning
)
8306 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
8308 info
= (struct bfd_link_info
*) inf
;
8309 htab
= elf_aarch64_hash_table (info
);
8311 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle it
8312 here if it is defined and referenced in a non-shared object. */
8313 if (h
->type
== STT_GNU_IFUNC
8316 else if (htab
->root
.dynamic_sections_created
&& h
->plt
.refcount
> 0)
8318 /* Make sure this symbol is output as a dynamic symbol.
8319 Undefined weak syms won't yet be marked as dynamic. */
8320 if (h
->dynindx
== -1 && !h
->forced_local
8321 && h
->root
.type
== bfd_link_hash_undefweak
)
8323 if (!bfd_elf_link_record_dynamic_symbol (info
, h
))
8327 if (bfd_link_pic (info
) || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h
))
8329 asection
*s
= htab
->root
.splt
;
8331 /* If this is the first .plt entry, make room for the special
8334 s
->size
+= htab
->plt_header_size
;
8336 h
->plt
.offset
= s
->size
;
8338 /* If this symbol is not defined in a regular file, and we are
8339 not generating a shared library, then set the symbol to this
8340 location in the .plt. This is required to make function
8341 pointers compare as equal between the normal executable and
8342 the shared library. */
8343 if (!bfd_link_pic (info
) && !h
->def_regular
)
8345 h
->root
.u
.def
.section
= s
;
8346 h
->root
.u
.def
.value
= h
->plt
.offset
;
8349 /* Make room for this entry. For now we only create the
8350 small model PLT entries. We later need to find a way
8351 of relaxing into these from the large model PLT entries. */
8352 s
->size
+= PLT_SMALL_ENTRY_SIZE
;
8354 /* We also need to make an entry in the .got.plt section, which
8355 will be placed in the .got section by the linker script. */
8356 htab
->root
.sgotplt
->size
+= GOT_ENTRY_SIZE
;
8358 /* We also need to make an entry in the .rela.plt section. */
8359 htab
->root
.srelplt
->size
+= RELOC_SIZE (htab
);
8361 /* We need to ensure that all GOT entries that serve the PLT
8362 are consecutive with the special GOT slots [0] [1] and
8363 [2]. Any addtional relocations, such as
8364 R_AARCH64_TLSDESC, must be placed after the PLT related
8365 entries. We abuse the reloc_count such that during
8366 sizing we adjust reloc_count to indicate the number of
8367 PLT related reserved entries. In subsequent phases when
8368 filling in the contents of the reloc entries, PLT related
8369 entries are placed by computing their PLT index (0
8370 .. reloc_count). While other none PLT relocs are placed
8371 at the slot indicated by reloc_count and reloc_count is
8374 htab
->root
.srelplt
->reloc_count
++;
8378 h
->plt
.offset
= (bfd_vma
) - 1;
8384 h
->plt
.offset
= (bfd_vma
) - 1;
8388 eh
= (struct elf_aarch64_link_hash_entry
*) h
;
8389 eh
->tlsdesc_got_jump_table_offset
= (bfd_vma
) - 1;
8391 if (h
->got
.refcount
> 0)
8394 unsigned got_type
= elf_aarch64_hash_entry (h
)->got_type
;
8396 h
->got
.offset
= (bfd_vma
) - 1;
8398 dyn
= htab
->root
.dynamic_sections_created
;
8400 /* Make sure this symbol is output as a dynamic symbol.
8401 Undefined weak syms won't yet be marked as dynamic. */
8402 if (dyn
&& h
->dynindx
== -1 && !h
->forced_local
8403 && h
->root
.type
== bfd_link_hash_undefweak
)
8405 if (!bfd_elf_link_record_dynamic_symbol (info
, h
))
8409 if (got_type
== GOT_UNKNOWN
)
8412 else if (got_type
== GOT_NORMAL
)
8414 h
->got
.offset
= htab
->root
.sgot
->size
;
8415 htab
->root
.sgot
->size
+= GOT_ENTRY_SIZE
;
8416 if ((ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
8417 || h
->root
.type
!= bfd_link_hash_undefweak
)
8418 && (bfd_link_pic (info
)
8419 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, 0, h
))
8420 /* Undefined weak symbol in static PIE resolves to 0 without
8421 any dynamic relocations. */
8422 && !UNDEFWEAK_NO_DYNAMIC_RELOC (info
, h
))
8424 htab
->root
.srelgot
->size
+= RELOC_SIZE (htab
);
8430 if (got_type
& GOT_TLSDESC_GD
)
8432 eh
->tlsdesc_got_jump_table_offset
=
8433 (htab
->root
.sgotplt
->size
8434 - aarch64_compute_jump_table_size (htab
));
8435 htab
->root
.sgotplt
->size
+= GOT_ENTRY_SIZE
* 2;
8436 h
->got
.offset
= (bfd_vma
) - 2;
8439 if (got_type
& GOT_TLS_GD
)
8441 h
->got
.offset
= htab
->root
.sgot
->size
;
8442 htab
->root
.sgot
->size
+= GOT_ENTRY_SIZE
* 2;
8445 if (got_type
& GOT_TLS_IE
)
8447 h
->got
.offset
= htab
->root
.sgot
->size
;
8448 htab
->root
.sgot
->size
+= GOT_ENTRY_SIZE
;
8451 indx
= h
&& h
->dynindx
!= -1 ? h
->dynindx
: 0;
8452 if ((ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
8453 || h
->root
.type
!= bfd_link_hash_undefweak
)
8454 && (!bfd_link_executable (info
)
8456 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, 0, h
)))
8458 if (got_type
& GOT_TLSDESC_GD
)
8460 htab
->root
.srelplt
->size
+= RELOC_SIZE (htab
);
8461 /* Note reloc_count not incremented here! We have
8462 already adjusted reloc_count for this relocation
8465 /* TLSDESC PLT is now needed, but not yet determined. */
8466 htab
->tlsdesc_plt
= (bfd_vma
) - 1;
8469 if (got_type
& GOT_TLS_GD
)
8470 htab
->root
.srelgot
->size
+= RELOC_SIZE (htab
) * 2;
8472 if (got_type
& GOT_TLS_IE
)
8473 htab
->root
.srelgot
->size
+= RELOC_SIZE (htab
);
8479 h
->got
.offset
= (bfd_vma
) - 1;
8482 if (eh
->dyn_relocs
== NULL
)
8485 /* In the shared -Bsymbolic case, discard space allocated for
8486 dynamic pc-relative relocs against symbols which turn out to be
8487 defined in regular objects. For the normal shared case, discard
8488 space for pc-relative relocs that have become local due to symbol
8489 visibility changes. */
8491 if (bfd_link_pic (info
))
8493 /* Relocs that use pc_count are those that appear on a call
8494 insn, or certain REL relocs that can generated via assembly.
8495 We want calls to protected symbols to resolve directly to the
8496 function rather than going via the plt. If people want
8497 function pointer comparisons to work as expected then they
8498 should avoid writing weird assembly. */
8499 if (SYMBOL_CALLS_LOCAL (info
, h
))
8501 struct elf_dyn_relocs
**pp
;
8503 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
;)
8505 p
->count
-= p
->pc_count
;
8514 /* Also discard relocs on undefined weak syms with non-default
8516 if (eh
->dyn_relocs
!= NULL
&& h
->root
.type
== bfd_link_hash_undefweak
)
8518 if (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
8519 || UNDEFWEAK_NO_DYNAMIC_RELOC (info
, h
))
8520 eh
->dyn_relocs
= NULL
;
8522 /* Make sure undefined weak symbols are output as a dynamic
8524 else if (h
->dynindx
== -1
8526 && h
->root
.type
== bfd_link_hash_undefweak
8527 && !bfd_elf_link_record_dynamic_symbol (info
, h
))
8532 else if (ELIMINATE_COPY_RELOCS
)
8534 /* For the non-shared case, discard space for relocs against
8535 symbols which turn out to need copy relocs or are not
8541 || (htab
->root
.dynamic_sections_created
8542 && (h
->root
.type
== bfd_link_hash_undefweak
8543 || h
->root
.type
== bfd_link_hash_undefined
))))
8545 /* Make sure this symbol is output as a dynamic symbol.
8546 Undefined weak syms won't yet be marked as dynamic. */
8547 if (h
->dynindx
== -1
8549 && h
->root
.type
== bfd_link_hash_undefweak
8550 && !bfd_elf_link_record_dynamic_symbol (info
, h
))
8553 /* If that succeeded, we know we'll be keeping all the
8555 if (h
->dynindx
!= -1)
8559 eh
->dyn_relocs
= NULL
;
8564 /* Finally, allocate space. */
8565 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
8569 sreloc
= elf_section_data (p
->sec
)->sreloc
;
8571 BFD_ASSERT (sreloc
!= NULL
);
8573 sreloc
->size
+= p
->count
* RELOC_SIZE (htab
);
8579 /* Allocate space in .plt, .got and associated reloc sections for
8580 ifunc dynamic relocs. */
8583 elfNN_aarch64_allocate_ifunc_dynrelocs (struct elf_link_hash_entry
*h
,
8586 struct bfd_link_info
*info
;
8587 struct elf_aarch64_link_hash_table
*htab
;
8588 struct elf_aarch64_link_hash_entry
*eh
;
8590 /* An example of a bfd_link_hash_indirect symbol is versioned
8591 symbol. For example: __gxx_personality_v0(bfd_link_hash_indirect)
8592 -> __gxx_personality_v0(bfd_link_hash_defined)
8594 There is no need to process bfd_link_hash_indirect symbols here
8595 because we will also be presented with the concrete instance of
8596 the symbol and elfNN_aarch64_copy_indirect_symbol () will have been
8597 called to copy all relevant data from the generic to the concrete
8599 if (h
->root
.type
== bfd_link_hash_indirect
)
8602 if (h
->root
.type
== bfd_link_hash_warning
)
8603 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
8605 info
= (struct bfd_link_info
*) inf
;
8606 htab
= elf_aarch64_hash_table (info
);
8608 eh
= (struct elf_aarch64_link_hash_entry
*) h
;
8610 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle it
8611 here if it is defined and referenced in a non-shared object. */
8612 if (h
->type
== STT_GNU_IFUNC
8614 return _bfd_elf_allocate_ifunc_dyn_relocs (info
, h
,
8617 htab
->plt_entry_size
,
8618 htab
->plt_header_size
,
8624 /* Allocate space in .plt, .got and associated reloc sections for
8625 local dynamic relocs. */
8628 elfNN_aarch64_allocate_local_dynrelocs (void **slot
, void *inf
)
8630 struct elf_link_hash_entry
*h
8631 = (struct elf_link_hash_entry
*) *slot
;
8633 if (h
->type
!= STT_GNU_IFUNC
8637 || h
->root
.type
!= bfd_link_hash_defined
)
8640 return elfNN_aarch64_allocate_dynrelocs (h
, inf
);
8643 /* Allocate space in .plt, .got and associated reloc sections for
8644 local ifunc dynamic relocs. */
8647 elfNN_aarch64_allocate_local_ifunc_dynrelocs (void **slot
, void *inf
)
8649 struct elf_link_hash_entry
*h
8650 = (struct elf_link_hash_entry
*) *slot
;
8652 if (h
->type
!= STT_GNU_IFUNC
8656 || h
->root
.type
!= bfd_link_hash_defined
)
8659 return elfNN_aarch64_allocate_ifunc_dynrelocs (h
, inf
);
8662 /* Set DF_TEXTREL if we find any dynamic relocs that apply to
8663 read-only sections. */
8666 maybe_set_textrel (struct elf_link_hash_entry
*h
, void *info_p
)
8670 if (h
->root
.type
== bfd_link_hash_indirect
)
8673 sec
= readonly_dynrelocs (h
);
8676 struct bfd_link_info
*info
= (struct bfd_link_info
*) info_p
;
8678 info
->flags
|= DF_TEXTREL
;
8679 info
->callbacks
->minfo
8680 (_("%pB: dynamic relocation against `%pT' in read-only section `%pA'\n"),
8681 sec
->owner
, h
->root
.root
.string
, sec
);
8683 /* Not an error, just cut short the traversal. */
8689 /* This is the most important function of all . Innocuosly named
8693 elfNN_aarch64_size_dynamic_sections (bfd
*output_bfd ATTRIBUTE_UNUSED
,
8694 struct bfd_link_info
*info
)
8696 struct elf_aarch64_link_hash_table
*htab
;
8702 htab
= elf_aarch64_hash_table ((info
));
8703 dynobj
= htab
->root
.dynobj
;
8705 BFD_ASSERT (dynobj
!= NULL
);
8707 if (htab
->root
.dynamic_sections_created
)
8709 if (bfd_link_executable (info
) && !info
->nointerp
)
8711 s
= bfd_get_linker_section (dynobj
, ".interp");
8714 s
->size
= sizeof ELF_DYNAMIC_INTERPRETER
;
8715 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
8719 /* Set up .got offsets for local syms, and space for local dynamic
8721 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
8723 struct elf_aarch64_local_symbol
*locals
= NULL
;
8724 Elf_Internal_Shdr
*symtab_hdr
;
8728 if (!is_aarch64_elf (ibfd
))
8731 for (s
= ibfd
->sections
; s
!= NULL
; s
= s
->next
)
8733 struct elf_dyn_relocs
*p
;
8735 for (p
= (struct elf_dyn_relocs
*)
8736 (elf_section_data (s
)->local_dynrel
); p
!= NULL
; p
= p
->next
)
8738 if (!bfd_is_abs_section (p
->sec
)
8739 && bfd_is_abs_section (p
->sec
->output_section
))
8741 /* Input section has been discarded, either because
8742 it is a copy of a linkonce section or due to
8743 linker script /DISCARD/, so we'll be discarding
8746 else if (p
->count
!= 0)
8748 srel
= elf_section_data (p
->sec
)->sreloc
;
8749 srel
->size
+= p
->count
* RELOC_SIZE (htab
);
8750 if ((p
->sec
->output_section
->flags
& SEC_READONLY
) != 0)
8751 info
->flags
|= DF_TEXTREL
;
8756 locals
= elf_aarch64_locals (ibfd
);
8760 symtab_hdr
= &elf_symtab_hdr (ibfd
);
8761 srel
= htab
->root
.srelgot
;
8762 for (i
= 0; i
< symtab_hdr
->sh_info
; i
++)
8764 locals
[i
].got_offset
= (bfd_vma
) - 1;
8765 locals
[i
].tlsdesc_got_jump_table_offset
= (bfd_vma
) - 1;
8766 if (locals
[i
].got_refcount
> 0)
8768 unsigned got_type
= locals
[i
].got_type
;
8769 if (got_type
& GOT_TLSDESC_GD
)
8771 locals
[i
].tlsdesc_got_jump_table_offset
=
8772 (htab
->root
.sgotplt
->size
8773 - aarch64_compute_jump_table_size (htab
));
8774 htab
->root
.sgotplt
->size
+= GOT_ENTRY_SIZE
* 2;
8775 locals
[i
].got_offset
= (bfd_vma
) - 2;
8778 if (got_type
& GOT_TLS_GD
)
8780 locals
[i
].got_offset
= htab
->root
.sgot
->size
;
8781 htab
->root
.sgot
->size
+= GOT_ENTRY_SIZE
* 2;
8784 if (got_type
& GOT_TLS_IE
8785 || got_type
& GOT_NORMAL
)
8787 locals
[i
].got_offset
= htab
->root
.sgot
->size
;
8788 htab
->root
.sgot
->size
+= GOT_ENTRY_SIZE
;
8791 if (got_type
== GOT_UNKNOWN
)
8795 if (bfd_link_pic (info
))
8797 if (got_type
& GOT_TLSDESC_GD
)
8799 htab
->root
.srelplt
->size
+= RELOC_SIZE (htab
);
8800 /* Note RELOC_COUNT not incremented here! */
8801 htab
->tlsdesc_plt
= (bfd_vma
) - 1;
8804 if (got_type
& GOT_TLS_GD
)
8805 htab
->root
.srelgot
->size
+= RELOC_SIZE (htab
) * 2;
8807 if (got_type
& GOT_TLS_IE
8808 || got_type
& GOT_NORMAL
)
8809 htab
->root
.srelgot
->size
+= RELOC_SIZE (htab
);
8814 locals
[i
].got_refcount
= (bfd_vma
) - 1;
8820 /* Allocate global sym .plt and .got entries, and space for global
8821 sym dynamic relocs. */
8822 elf_link_hash_traverse (&htab
->root
, elfNN_aarch64_allocate_dynrelocs
,
8825 /* Allocate global ifunc sym .plt and .got entries, and space for global
8826 ifunc sym dynamic relocs. */
8827 elf_link_hash_traverse (&htab
->root
, elfNN_aarch64_allocate_ifunc_dynrelocs
,
8830 /* Allocate .plt and .got entries, and space for local symbols. */
8831 htab_traverse (htab
->loc_hash_table
,
8832 elfNN_aarch64_allocate_local_dynrelocs
,
8835 /* Allocate .plt and .got entries, and space for local ifunc symbols. */
8836 htab_traverse (htab
->loc_hash_table
,
8837 elfNN_aarch64_allocate_local_ifunc_dynrelocs
,
8840 /* For every jump slot reserved in the sgotplt, reloc_count is
8841 incremented. However, when we reserve space for TLS descriptors,
8842 it's not incremented, so in order to compute the space reserved
8843 for them, it suffices to multiply the reloc count by the jump
8846 if (htab
->root
.srelplt
)
8847 htab
->sgotplt_jump_table_size
= aarch64_compute_jump_table_size (htab
);
8849 if (htab
->tlsdesc_plt
)
8851 if (htab
->root
.splt
->size
== 0)
8852 htab
->root
.splt
->size
+= PLT_ENTRY_SIZE
;
8854 htab
->tlsdesc_plt
= htab
->root
.splt
->size
;
8855 htab
->root
.splt
->size
+= PLT_TLSDESC_ENTRY_SIZE
;
8857 /* If we're not using lazy TLS relocations, don't generate the
8858 GOT entry required. */
8859 if (!(info
->flags
& DF_BIND_NOW
))
8861 htab
->dt_tlsdesc_got
= htab
->root
.sgot
->size
;
8862 htab
->root
.sgot
->size
+= GOT_ENTRY_SIZE
;
8866 /* Init mapping symbols information to use later to distingush between
8867 code and data while scanning for errata. */
8868 if (htab
->fix_erratum_835769
|| htab
->fix_erratum_843419
)
8869 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
8871 if (!is_aarch64_elf (ibfd
))
8873 bfd_elfNN_aarch64_init_maps (ibfd
);
8876 /* We now have determined the sizes of the various dynamic sections.
8877 Allocate memory for them. */
8879 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
8881 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
8884 if (s
== htab
->root
.splt
8885 || s
== htab
->root
.sgot
8886 || s
== htab
->root
.sgotplt
8887 || s
== htab
->root
.iplt
8888 || s
== htab
->root
.igotplt
8889 || s
== htab
->root
.sdynbss
8890 || s
== htab
->root
.sdynrelro
)
8892 /* Strip this section if we don't need it; see the
8895 else if (CONST_STRNEQ (bfd_get_section_name (dynobj
, s
), ".rela"))
8897 if (s
->size
!= 0 && s
!= htab
->root
.srelplt
)
8900 /* We use the reloc_count field as a counter if we need
8901 to copy relocs into the output file. */
8902 if (s
!= htab
->root
.srelplt
)
8907 /* It's not one of our sections, so don't allocate space. */
8913 /* If we don't need this section, strip it from the
8914 output file. This is mostly to handle .rela.bss and
8915 .rela.plt. We must create both sections in
8916 create_dynamic_sections, because they must be created
8917 before the linker maps input sections to output
8918 sections. The linker does that before
8919 adjust_dynamic_symbol is called, and it is that
8920 function which decides whether anything needs to go
8921 into these sections. */
8922 s
->flags
|= SEC_EXCLUDE
;
8926 if ((s
->flags
& SEC_HAS_CONTENTS
) == 0)
8929 /* Allocate memory for the section contents. We use bfd_zalloc
8930 here in case unused entries are not reclaimed before the
8931 section's contents are written out. This should not happen,
8932 but this way if it does, we get a R_AARCH64_NONE reloc instead
8934 s
->contents
= (bfd_byte
*) bfd_zalloc (dynobj
, s
->size
);
8935 if (s
->contents
== NULL
)
8939 if (htab
->root
.dynamic_sections_created
)
8941 /* Add some entries to the .dynamic section. We fill in the
8942 values later, in elfNN_aarch64_finish_dynamic_sections, but we
8943 must add the entries now so that we get the correct size for
8944 the .dynamic section. The DT_DEBUG entry is filled in by the
8945 dynamic linker and used by the debugger. */
8946 #define add_dynamic_entry(TAG, VAL) \
8947 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
8949 if (bfd_link_executable (info
))
8951 if (!add_dynamic_entry (DT_DEBUG
, 0))
8955 if (htab
->root
.splt
->size
!= 0)
8957 if (!add_dynamic_entry (DT_PLTGOT
, 0)
8958 || !add_dynamic_entry (DT_PLTRELSZ
, 0)
8959 || !add_dynamic_entry (DT_PLTREL
, DT_RELA
)
8960 || !add_dynamic_entry (DT_JMPREL
, 0))
8963 if (htab
->tlsdesc_plt
8964 && (!add_dynamic_entry (DT_TLSDESC_PLT
, 0)
8965 || !add_dynamic_entry (DT_TLSDESC_GOT
, 0)))
8971 if (!add_dynamic_entry (DT_RELA
, 0)
8972 || !add_dynamic_entry (DT_RELASZ
, 0)
8973 || !add_dynamic_entry (DT_RELAENT
, RELOC_SIZE (htab
)))
8976 /* If any dynamic relocs apply to a read-only section,
8977 then we need a DT_TEXTREL entry. */
8978 if ((info
->flags
& DF_TEXTREL
) == 0)
8979 elf_link_hash_traverse (&htab
->root
, maybe_set_textrel
, info
);
8981 if ((info
->flags
& DF_TEXTREL
) != 0)
8983 if (!add_dynamic_entry (DT_TEXTREL
, 0))
8988 #undef add_dynamic_entry
8994 elf_aarch64_update_plt_entry (bfd
*output_bfd
,
8995 bfd_reloc_code_real_type r_type
,
8996 bfd_byte
*plt_entry
, bfd_vma value
)
8998 reloc_howto_type
*howto
= elfNN_aarch64_howto_from_bfd_reloc (r_type
);
9000 /* FIXME: We should check the return value from this function call. */
9001 (void) _bfd_aarch64_elf_put_addend (output_bfd
, plt_entry
, r_type
, howto
, value
);
9005 elfNN_aarch64_create_small_pltn_entry (struct elf_link_hash_entry
*h
,
9006 struct elf_aarch64_link_hash_table
9007 *htab
, bfd
*output_bfd
,
9008 struct bfd_link_info
*info
)
9010 bfd_byte
*plt_entry
;
9013 bfd_vma gotplt_entry_address
;
9014 bfd_vma plt_entry_address
;
9015 Elf_Internal_Rela rela
;
9017 asection
*plt
, *gotplt
, *relplt
;
9019 /* When building a static executable, use .iplt, .igot.plt and
9020 .rela.iplt sections for STT_GNU_IFUNC symbols. */
9021 if (htab
->root
.splt
!= NULL
)
9023 plt
= htab
->root
.splt
;
9024 gotplt
= htab
->root
.sgotplt
;
9025 relplt
= htab
->root
.srelplt
;
9029 plt
= htab
->root
.iplt
;
9030 gotplt
= htab
->root
.igotplt
;
9031 relplt
= htab
->root
.irelplt
;
9034 /* Get the index in the procedure linkage table which
9035 corresponds to this symbol. This is the index of this symbol
9036 in all the symbols for which we are making plt entries. The
9037 first entry in the procedure linkage table is reserved.
9039 Get the offset into the .got table of the entry that
9040 corresponds to this function. Each .got entry is GOT_ENTRY_SIZE
9041 bytes. The first three are reserved for the dynamic linker.
9043 For static executables, we don't reserve anything. */
9045 if (plt
== htab
->root
.splt
)
9047 plt_index
= (h
->plt
.offset
- htab
->plt_header_size
) / htab
->plt_entry_size
;
9048 got_offset
= (plt_index
+ 3) * GOT_ENTRY_SIZE
;
9052 plt_index
= h
->plt
.offset
/ htab
->plt_entry_size
;
9053 got_offset
= plt_index
* GOT_ENTRY_SIZE
;
9056 plt_entry
= plt
->contents
+ h
->plt
.offset
;
9057 plt_entry_address
= plt
->output_section
->vma
9058 + plt
->output_offset
+ h
->plt
.offset
;
9059 gotplt_entry_address
= gotplt
->output_section
->vma
+
9060 gotplt
->output_offset
+ got_offset
;
9062 /* Copy in the boiler-plate for the PLTn entry. */
9063 memcpy (plt_entry
, elfNN_aarch64_small_plt_entry
, PLT_SMALL_ENTRY_SIZE
);
9065 /* Fill in the top 21 bits for this: ADRP x16, PLT_GOT + n * 8.
9066 ADRP: ((PG(S+A)-PG(P)) >> 12) & 0x1fffff */
9067 elf_aarch64_update_plt_entry (output_bfd
, BFD_RELOC_AARCH64_ADR_HI21_PCREL
,
9069 PG (gotplt_entry_address
) -
9070 PG (plt_entry_address
));
9072 /* Fill in the lo12 bits for the load from the pltgot. */
9073 elf_aarch64_update_plt_entry (output_bfd
, BFD_RELOC_AARCH64_LDSTNN_LO12
,
9075 PG_OFFSET (gotplt_entry_address
));
9077 /* Fill in the lo12 bits for the add from the pltgot entry. */
9078 elf_aarch64_update_plt_entry (output_bfd
, BFD_RELOC_AARCH64_ADD_LO12
,
9080 PG_OFFSET (gotplt_entry_address
));
9082 /* All the GOTPLT Entries are essentially initialized to PLT0. */
9083 bfd_put_NN (output_bfd
,
9084 plt
->output_section
->vma
+ plt
->output_offset
,
9085 gotplt
->contents
+ got_offset
);
9087 rela
.r_offset
= gotplt_entry_address
;
9089 if (h
->dynindx
== -1
9090 || ((bfd_link_executable (info
)
9091 || ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
)
9093 && h
->type
== STT_GNU_IFUNC
))
9095 /* If an STT_GNU_IFUNC symbol is locally defined, generate
9096 R_AARCH64_IRELATIVE instead of R_AARCH64_JUMP_SLOT. */
9097 rela
.r_info
= ELFNN_R_INFO (0, AARCH64_R (IRELATIVE
));
9098 rela
.r_addend
= (h
->root
.u
.def
.value
9099 + h
->root
.u
.def
.section
->output_section
->vma
9100 + h
->root
.u
.def
.section
->output_offset
);
9104 /* Fill in the entry in the .rela.plt section. */
9105 rela
.r_info
= ELFNN_R_INFO (h
->dynindx
, AARCH64_R (JUMP_SLOT
));
9109 /* Compute the relocation entry to used based on PLT index and do
9110 not adjust reloc_count. The reloc_count has already been adjusted
9111 to account for this entry. */
9112 loc
= relplt
->contents
+ plt_index
* RELOC_SIZE (htab
);
9113 bfd_elfNN_swap_reloca_out (output_bfd
, &rela
, loc
);
9116 /* Size sections even though they're not dynamic. We use it to setup
9117 _TLS_MODULE_BASE_, if needed. */
9120 elfNN_aarch64_always_size_sections (bfd
*output_bfd
,
9121 struct bfd_link_info
*info
)
9125 if (bfd_link_relocatable (info
))
9128 tls_sec
= elf_hash_table (info
)->tls_sec
;
9132 struct elf_link_hash_entry
*tlsbase
;
9134 tlsbase
= elf_link_hash_lookup (elf_hash_table (info
),
9135 "_TLS_MODULE_BASE_", TRUE
, TRUE
, FALSE
);
9139 struct bfd_link_hash_entry
*h
= NULL
;
9140 const struct elf_backend_data
*bed
=
9141 get_elf_backend_data (output_bfd
);
9143 if (!(_bfd_generic_link_add_one_symbol
9144 (info
, output_bfd
, "_TLS_MODULE_BASE_", BSF_LOCAL
,
9145 tls_sec
, 0, NULL
, FALSE
, bed
->collect
, &h
)))
9148 tlsbase
->type
= STT_TLS
;
9149 tlsbase
= (struct elf_link_hash_entry
*) h
;
9150 tlsbase
->def_regular
= 1;
9151 tlsbase
->other
= STV_HIDDEN
;
9152 (*bed
->elf_backend_hide_symbol
) (info
, tlsbase
, TRUE
);
9159 /* Finish up dynamic symbol handling. We set the contents of various
9160 dynamic sections here. */
9163 elfNN_aarch64_finish_dynamic_symbol (bfd
*output_bfd
,
9164 struct bfd_link_info
*info
,
9165 struct elf_link_hash_entry
*h
,
9166 Elf_Internal_Sym
*sym
)
9168 struct elf_aarch64_link_hash_table
*htab
;
9169 htab
= elf_aarch64_hash_table (info
);
9171 if (h
->plt
.offset
!= (bfd_vma
) - 1)
9173 asection
*plt
, *gotplt
, *relplt
;
9175 /* This symbol has an entry in the procedure linkage table. Set
9178 /* When building a static executable, use .iplt, .igot.plt and
9179 .rela.iplt sections for STT_GNU_IFUNC symbols. */
9180 if (htab
->root
.splt
!= NULL
)
9182 plt
= htab
->root
.splt
;
9183 gotplt
= htab
->root
.sgotplt
;
9184 relplt
= htab
->root
.srelplt
;
9188 plt
= htab
->root
.iplt
;
9189 gotplt
= htab
->root
.igotplt
;
9190 relplt
= htab
->root
.irelplt
;
9193 /* This symbol has an entry in the procedure linkage table. Set
9195 if ((h
->dynindx
== -1
9196 && !((h
->forced_local
|| bfd_link_executable (info
))
9198 && h
->type
== STT_GNU_IFUNC
))
9204 elfNN_aarch64_create_small_pltn_entry (h
, htab
, output_bfd
, info
);
9205 if (!h
->def_regular
)
9207 /* Mark the symbol as undefined, rather than as defined in
9208 the .plt section. */
9209 sym
->st_shndx
= SHN_UNDEF
;
9210 /* If the symbol is weak we need to clear the value.
9211 Otherwise, the PLT entry would provide a definition for
9212 the symbol even if the symbol wasn't defined anywhere,
9213 and so the symbol would never be NULL. Leave the value if
9214 there were any relocations where pointer equality matters
9215 (this is a clue for the dynamic linker, to make function
9216 pointer comparisons work between an application and shared
9218 if (!h
->ref_regular_nonweak
|| !h
->pointer_equality_needed
)
9223 if (h
->got
.offset
!= (bfd_vma
) - 1
9224 && elf_aarch64_hash_entry (h
)->got_type
== GOT_NORMAL
9225 /* Undefined weak symbol in static PIE resolves to 0 without
9226 any dynamic relocations. */
9227 && !UNDEFWEAK_NO_DYNAMIC_RELOC (info
, h
))
9229 Elf_Internal_Rela rela
;
9232 /* This symbol has an entry in the global offset table. Set it
9234 if (htab
->root
.sgot
== NULL
|| htab
->root
.srelgot
== NULL
)
9237 rela
.r_offset
= (htab
->root
.sgot
->output_section
->vma
9238 + htab
->root
.sgot
->output_offset
9239 + (h
->got
.offset
& ~(bfd_vma
) 1));
9242 && h
->type
== STT_GNU_IFUNC
)
9244 if (bfd_link_pic (info
))
9246 /* Generate R_AARCH64_GLOB_DAT. */
9253 if (!h
->pointer_equality_needed
)
9256 /* For non-shared object, we can't use .got.plt, which
9257 contains the real function address if we need pointer
9258 equality. We load the GOT entry with the PLT entry. */
9259 plt
= htab
->root
.splt
? htab
->root
.splt
: htab
->root
.iplt
;
9260 bfd_put_NN (output_bfd
, (plt
->output_section
->vma
9261 + plt
->output_offset
9263 htab
->root
.sgot
->contents
9264 + (h
->got
.offset
& ~(bfd_vma
) 1));
9268 else if (bfd_link_pic (info
) && SYMBOL_REFERENCES_LOCAL (info
, h
))
9270 if (!(h
->def_regular
|| ELF_COMMON_DEF_P (h
)))
9273 BFD_ASSERT ((h
->got
.offset
& 1) != 0);
9274 rela
.r_info
= ELFNN_R_INFO (0, AARCH64_R (RELATIVE
));
9275 rela
.r_addend
= (h
->root
.u
.def
.value
9276 + h
->root
.u
.def
.section
->output_section
->vma
9277 + h
->root
.u
.def
.section
->output_offset
);
9282 BFD_ASSERT ((h
->got
.offset
& 1) == 0);
9283 bfd_put_NN (output_bfd
, (bfd_vma
) 0,
9284 htab
->root
.sgot
->contents
+ h
->got
.offset
);
9285 rela
.r_info
= ELFNN_R_INFO (h
->dynindx
, AARCH64_R (GLOB_DAT
));
9289 loc
= htab
->root
.srelgot
->contents
;
9290 loc
+= htab
->root
.srelgot
->reloc_count
++ * RELOC_SIZE (htab
);
9291 bfd_elfNN_swap_reloca_out (output_bfd
, &rela
, loc
);
9296 Elf_Internal_Rela rela
;
9300 /* This symbol needs a copy reloc. Set it up. */
9301 if (h
->dynindx
== -1
9302 || (h
->root
.type
!= bfd_link_hash_defined
9303 && h
->root
.type
!= bfd_link_hash_defweak
)
9304 || htab
->root
.srelbss
== NULL
)
9307 rela
.r_offset
= (h
->root
.u
.def
.value
9308 + h
->root
.u
.def
.section
->output_section
->vma
9309 + h
->root
.u
.def
.section
->output_offset
);
9310 rela
.r_info
= ELFNN_R_INFO (h
->dynindx
, AARCH64_R (COPY
));
9312 if (h
->root
.u
.def
.section
== htab
->root
.sdynrelro
)
9313 s
= htab
->root
.sreldynrelro
;
9315 s
= htab
->root
.srelbss
;
9316 loc
= s
->contents
+ s
->reloc_count
++ * RELOC_SIZE (htab
);
9317 bfd_elfNN_swap_reloca_out (output_bfd
, &rela
, loc
);
9320 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. SYM may
9321 be NULL for local symbols. */
9323 && (h
== elf_hash_table (info
)->hdynamic
9324 || h
== elf_hash_table (info
)->hgot
))
9325 sym
->st_shndx
= SHN_ABS
;
9330 /* Finish up local dynamic symbol handling. We set the contents of
9331 various dynamic sections here. */
9334 elfNN_aarch64_finish_local_dynamic_symbol (void **slot
, void *inf
)
9336 struct elf_link_hash_entry
*h
9337 = (struct elf_link_hash_entry
*) *slot
;
9338 struct bfd_link_info
*info
9339 = (struct bfd_link_info
*) inf
;
9341 return elfNN_aarch64_finish_dynamic_symbol (info
->output_bfd
,
9346 elfNN_aarch64_init_small_plt0_entry (bfd
*output_bfd ATTRIBUTE_UNUSED
,
9347 struct elf_aarch64_link_hash_table
9350 /* Fill in PLT0. Fixme:RR Note this doesn't distinguish between
9351 small and large plts and at the minute just generates
9354 /* PLT0 of the small PLT looks like this in ELF64 -
9355 stp x16, x30, [sp, #-16]! // Save the reloc and lr on stack.
9356 adrp x16, PLT_GOT + 16 // Get the page base of the GOTPLT
9357 ldr x17, [x16, #:lo12:PLT_GOT+16] // Load the address of the
9359 add x16, x16, #:lo12:PLT_GOT+16 // Load the lo12 bits of the
9360 // GOTPLT entry for this.
9362 PLT0 will be slightly different in ELF32 due to different got entry
9364 bfd_vma plt_got_2nd_ent
; /* Address of GOT[2]. */
9368 memcpy (htab
->root
.splt
->contents
, elfNN_aarch64_small_plt0_entry
,
9370 elf_section_data (htab
->root
.splt
->output_section
)->this_hdr
.sh_entsize
=
9373 plt_got_2nd_ent
= (htab
->root
.sgotplt
->output_section
->vma
9374 + htab
->root
.sgotplt
->output_offset
9375 + GOT_ENTRY_SIZE
* 2);
9377 plt_base
= htab
->root
.splt
->output_section
->vma
+
9378 htab
->root
.splt
->output_offset
;
9380 /* Fill in the top 21 bits for this: ADRP x16, PLT_GOT + n * 8.
9381 ADRP: ((PG(S+A)-PG(P)) >> 12) & 0x1fffff */
9382 elf_aarch64_update_plt_entry (output_bfd
, BFD_RELOC_AARCH64_ADR_HI21_PCREL
,
9383 htab
->root
.splt
->contents
+ 4,
9384 PG (plt_got_2nd_ent
) - PG (plt_base
+ 4));
9386 elf_aarch64_update_plt_entry (output_bfd
, BFD_RELOC_AARCH64_LDSTNN_LO12
,
9387 htab
->root
.splt
->contents
+ 8,
9388 PG_OFFSET (plt_got_2nd_ent
));
9390 elf_aarch64_update_plt_entry (output_bfd
, BFD_RELOC_AARCH64_ADD_LO12
,
9391 htab
->root
.splt
->contents
+ 12,
9392 PG_OFFSET (plt_got_2nd_ent
));
9396 elfNN_aarch64_finish_dynamic_sections (bfd
*output_bfd
,
9397 struct bfd_link_info
*info
)
9399 struct elf_aarch64_link_hash_table
*htab
;
9403 htab
= elf_aarch64_hash_table (info
);
9404 dynobj
= htab
->root
.dynobj
;
9405 sdyn
= bfd_get_linker_section (dynobj
, ".dynamic");
9407 if (htab
->root
.dynamic_sections_created
)
9409 ElfNN_External_Dyn
*dyncon
, *dynconend
;
9411 if (sdyn
== NULL
|| htab
->root
.sgot
== NULL
)
9414 dyncon
= (ElfNN_External_Dyn
*) sdyn
->contents
;
9415 dynconend
= (ElfNN_External_Dyn
*) (sdyn
->contents
+ sdyn
->size
);
9416 for (; dyncon
< dynconend
; dyncon
++)
9418 Elf_Internal_Dyn dyn
;
9421 bfd_elfNN_swap_dyn_in (dynobj
, dyncon
, &dyn
);
9429 s
= htab
->root
.sgotplt
;
9430 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
9434 s
= htab
->root
.srelplt
;
9435 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
9439 s
= htab
->root
.srelplt
;
9440 dyn
.d_un
.d_val
= s
->size
;
9443 case DT_TLSDESC_PLT
:
9444 s
= htab
->root
.splt
;
9445 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
9446 + htab
->tlsdesc_plt
;
9449 case DT_TLSDESC_GOT
:
9450 s
= htab
->root
.sgot
;
9451 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
9452 + htab
->dt_tlsdesc_got
;
9456 bfd_elfNN_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
9461 /* Fill in the special first entry in the procedure linkage table. */
9462 if (htab
->root
.splt
&& htab
->root
.splt
->size
> 0)
9464 elfNN_aarch64_init_small_plt0_entry (output_bfd
, htab
);
9466 elf_section_data (htab
->root
.splt
->output_section
)->
9467 this_hdr
.sh_entsize
= htab
->plt_entry_size
;
9470 if (htab
->tlsdesc_plt
)
9472 bfd_put_NN (output_bfd
, (bfd_vma
) 0,
9473 htab
->root
.sgot
->contents
+ htab
->dt_tlsdesc_got
);
9475 memcpy (htab
->root
.splt
->contents
+ htab
->tlsdesc_plt
,
9476 elfNN_aarch64_tlsdesc_small_plt_entry
,
9477 sizeof (elfNN_aarch64_tlsdesc_small_plt_entry
));
9480 bfd_vma adrp1_addr
=
9481 htab
->root
.splt
->output_section
->vma
9482 + htab
->root
.splt
->output_offset
+ htab
->tlsdesc_plt
+ 4;
9484 bfd_vma adrp2_addr
= adrp1_addr
+ 4;
9487 htab
->root
.sgot
->output_section
->vma
9488 + htab
->root
.sgot
->output_offset
;
9490 bfd_vma pltgot_addr
=
9491 htab
->root
.sgotplt
->output_section
->vma
9492 + htab
->root
.sgotplt
->output_offset
;
9494 bfd_vma dt_tlsdesc_got
= got_addr
+ htab
->dt_tlsdesc_got
;
9496 bfd_byte
*plt_entry
=
9497 htab
->root
.splt
->contents
+ htab
->tlsdesc_plt
;
9499 /* adrp x2, DT_TLSDESC_GOT */
9500 elf_aarch64_update_plt_entry (output_bfd
,
9501 BFD_RELOC_AARCH64_ADR_HI21_PCREL
,
9503 (PG (dt_tlsdesc_got
)
9504 - PG (adrp1_addr
)));
9507 elf_aarch64_update_plt_entry (output_bfd
,
9508 BFD_RELOC_AARCH64_ADR_HI21_PCREL
,
9511 - PG (adrp2_addr
)));
9513 /* ldr x2, [x2, #0] */
9514 elf_aarch64_update_plt_entry (output_bfd
,
9515 BFD_RELOC_AARCH64_LDSTNN_LO12
,
9517 PG_OFFSET (dt_tlsdesc_got
));
9520 elf_aarch64_update_plt_entry (output_bfd
,
9521 BFD_RELOC_AARCH64_ADD_LO12
,
9523 PG_OFFSET (pltgot_addr
));
9528 if (htab
->root
.sgotplt
)
9530 if (bfd_is_abs_section (htab
->root
.sgotplt
->output_section
))
9533 (_("discarded output section: `%pA'"), htab
->root
.sgotplt
);
9537 /* Fill in the first three entries in the global offset table. */
9538 if (htab
->root
.sgotplt
->size
> 0)
9540 bfd_put_NN (output_bfd
, (bfd_vma
) 0, htab
->root
.sgotplt
->contents
);
9542 /* Write GOT[1] and GOT[2], needed for the dynamic linker. */
9543 bfd_put_NN (output_bfd
,
9545 htab
->root
.sgotplt
->contents
+ GOT_ENTRY_SIZE
);
9546 bfd_put_NN (output_bfd
,
9548 htab
->root
.sgotplt
->contents
+ GOT_ENTRY_SIZE
* 2);
9551 if (htab
->root
.sgot
)
9553 if (htab
->root
.sgot
->size
> 0)
9556 sdyn
? sdyn
->output_section
->vma
+ sdyn
->output_offset
: 0;
9557 bfd_put_NN (output_bfd
, addr
, htab
->root
.sgot
->contents
);
9561 elf_section_data (htab
->root
.sgotplt
->output_section
)->
9562 this_hdr
.sh_entsize
= GOT_ENTRY_SIZE
;
9565 if (htab
->root
.sgot
&& htab
->root
.sgot
->size
> 0)
9566 elf_section_data (htab
->root
.sgot
->output_section
)->this_hdr
.sh_entsize
9569 /* Fill PLT and GOT entries for local STT_GNU_IFUNC symbols. */
9570 htab_traverse (htab
->loc_hash_table
,
9571 elfNN_aarch64_finish_local_dynamic_symbol
,
9577 /* Return address for Ith PLT stub in section PLT, for relocation REL
9578 or (bfd_vma) -1 if it should not be included. */
9581 elfNN_aarch64_plt_sym_val (bfd_vma i
, const asection
*plt
,
9582 const arelent
*rel ATTRIBUTE_UNUSED
)
9584 return plt
->vma
+ PLT_ENTRY_SIZE
+ i
* PLT_SMALL_ENTRY_SIZE
;
9587 /* Returns TRUE if NAME is an AArch64 mapping symbol.
9588 The ARM ELF standard defines $x (for A64 code) and $d (for data).
9589 It also allows a period initiated suffix to be added to the symbol, ie:
9590 "$[adtx]\.[:sym_char]+". */
9593 is_aarch64_mapping_symbol (const char * name
)
9595 return name
!= NULL
/* Paranoia. */
9596 && name
[0] == '$' /* Note: if objcopy --prefix-symbols has been used then
9597 the mapping symbols could have acquired a prefix.
9598 We do not support this here, since such symbols no
9599 longer conform to the ARM ELF ABI. */
9600 && (name
[1] == 'd' || name
[1] == 'x')
9601 && (name
[2] == 0 || name
[2] == '.');
9602 /* FIXME: Strictly speaking the symbol is only a valid mapping symbol if
9603 any characters that follow the period are legal characters for the body
9604 of a symbol's name. For now we just assume that this is the case. */
9607 /* Make sure that mapping symbols in object files are not removed via the
9608 "strip --strip-unneeded" tool. These symbols might needed in order to
9609 correctly generate linked files. Once an object file has been linked,
9610 it should be safe to remove them. */
9613 elfNN_aarch64_backend_symbol_processing (bfd
*abfd
, asymbol
*sym
)
9615 if (((abfd
->flags
& (EXEC_P
| DYNAMIC
)) == 0)
9616 && sym
->section
!= bfd_abs_section_ptr
9617 && is_aarch64_mapping_symbol (sym
->name
))
9618 sym
->flags
|= BSF_KEEP
;
9621 /* Implement elf_backend_setup_gnu_properties for AArch64. It serves as a
9622 wrapper function for _bfd_aarch64_elf_link_setup_gnu_properties to account
9623 for the effect of GNU properties of the output_bfd. */
9625 elfNN_aarch64_link_setup_gnu_properties (struct bfd_link_info
*info
)
9627 uint32_t prop
= elf_aarch64_tdata (info
->output_bfd
)->gnu_and_prop
;
9628 bfd
*pbfd
= _bfd_aarch64_elf_link_setup_gnu_properties (info
, &prop
);
9629 elf_aarch64_tdata (info
->output_bfd
)->gnu_and_prop
= prop
;
9633 /* Implement elf_backend_merge_gnu_properties for AArch64. It serves as a
9634 wrapper function for _bfd_aarch64_elf_merge_gnu_properties to account
9635 for the effect of GNU properties of the output_bfd. */
9637 elfNN_aarch64_merge_gnu_properties (struct bfd_link_info
*info
,
9639 elf_property
*aprop
,
9640 elf_property
*bprop
)
9643 = elf_aarch64_tdata (info
->output_bfd
)->gnu_and_prop
;
9644 return _bfd_aarch64_elf_merge_gnu_properties (info
, abfd
, aprop
,
9648 /* We use this so we can override certain functions
9649 (though currently we don't). */
9651 const struct elf_size_info elfNN_aarch64_size_info
=
9653 sizeof (ElfNN_External_Ehdr
),
9654 sizeof (ElfNN_External_Phdr
),
9655 sizeof (ElfNN_External_Shdr
),
9656 sizeof (ElfNN_External_Rel
),
9657 sizeof (ElfNN_External_Rela
),
9658 sizeof (ElfNN_External_Sym
),
9659 sizeof (ElfNN_External_Dyn
),
9660 sizeof (Elf_External_Note
),
9661 4, /* Hash table entry size. */
9662 1, /* Internal relocs per external relocs. */
9663 ARCH_SIZE
, /* Arch size. */
9664 LOG_FILE_ALIGN
, /* Log_file_align. */
9665 ELFCLASSNN
, EV_CURRENT
,
9666 bfd_elfNN_write_out_phdrs
,
9667 bfd_elfNN_write_shdrs_and_ehdr
,
9668 bfd_elfNN_checksum_contents
,
9669 bfd_elfNN_write_relocs
,
9670 bfd_elfNN_swap_symbol_in
,
9671 bfd_elfNN_swap_symbol_out
,
9672 bfd_elfNN_slurp_reloc_table
,
9673 bfd_elfNN_slurp_symbol_table
,
9674 bfd_elfNN_swap_dyn_in
,
9675 bfd_elfNN_swap_dyn_out
,
9676 bfd_elfNN_swap_reloc_in
,
9677 bfd_elfNN_swap_reloc_out
,
9678 bfd_elfNN_swap_reloca_in
,
9679 bfd_elfNN_swap_reloca_out
9682 #define ELF_ARCH bfd_arch_aarch64
9683 #define ELF_MACHINE_CODE EM_AARCH64
9684 #define ELF_MAXPAGESIZE 0x10000
9685 #define ELF_MINPAGESIZE 0x1000
9686 #define ELF_COMMONPAGESIZE 0x1000
9688 #define bfd_elfNN_close_and_cleanup \
9689 elfNN_aarch64_close_and_cleanup
9691 #define bfd_elfNN_bfd_free_cached_info \
9692 elfNN_aarch64_bfd_free_cached_info
9694 #define bfd_elfNN_bfd_is_target_special_symbol \
9695 elfNN_aarch64_is_target_special_symbol
9697 #define bfd_elfNN_bfd_link_hash_table_create \
9698 elfNN_aarch64_link_hash_table_create
9700 #define bfd_elfNN_bfd_merge_private_bfd_data \
9701 elfNN_aarch64_merge_private_bfd_data
9703 #define bfd_elfNN_bfd_print_private_bfd_data \
9704 elfNN_aarch64_print_private_bfd_data
9706 #define bfd_elfNN_bfd_reloc_type_lookup \
9707 elfNN_aarch64_reloc_type_lookup
9709 #define bfd_elfNN_bfd_reloc_name_lookup \
9710 elfNN_aarch64_reloc_name_lookup
9712 #define bfd_elfNN_bfd_set_private_flags \
9713 elfNN_aarch64_set_private_flags
9715 #define bfd_elfNN_find_inliner_info \
9716 elfNN_aarch64_find_inliner_info
9718 #define bfd_elfNN_find_nearest_line \
9719 elfNN_aarch64_find_nearest_line
9721 #define bfd_elfNN_mkobject \
9722 elfNN_aarch64_mkobject
9724 #define bfd_elfNN_new_section_hook \
9725 elfNN_aarch64_new_section_hook
9727 #define elf_backend_adjust_dynamic_symbol \
9728 elfNN_aarch64_adjust_dynamic_symbol
9730 #define elf_backend_always_size_sections \
9731 elfNN_aarch64_always_size_sections
9733 #define elf_backend_check_relocs \
9734 elfNN_aarch64_check_relocs
9736 #define elf_backend_copy_indirect_symbol \
9737 elfNN_aarch64_copy_indirect_symbol
9739 /* Create .dynbss, and .rela.bss sections in DYNOBJ, and set up shortcuts
9740 to them in our hash. */
9741 #define elf_backend_create_dynamic_sections \
9742 elfNN_aarch64_create_dynamic_sections
9744 #define elf_backend_init_index_section \
9745 _bfd_elf_init_2_index_sections
9747 #define elf_backend_finish_dynamic_sections \
9748 elfNN_aarch64_finish_dynamic_sections
9750 #define elf_backend_finish_dynamic_symbol \
9751 elfNN_aarch64_finish_dynamic_symbol
9753 #define elf_backend_object_p \
9754 elfNN_aarch64_object_p
9756 #define elf_backend_output_arch_local_syms \
9757 elfNN_aarch64_output_arch_local_syms
9759 #define elf_backend_plt_sym_val \
9760 elfNN_aarch64_plt_sym_val
9762 #define elf_backend_post_process_headers \
9763 elfNN_aarch64_post_process_headers
9765 #define elf_backend_relocate_section \
9766 elfNN_aarch64_relocate_section
9768 #define elf_backend_reloc_type_class \
9769 elfNN_aarch64_reloc_type_class
9771 #define elf_backend_section_from_shdr \
9772 elfNN_aarch64_section_from_shdr
9774 #define elf_backend_size_dynamic_sections \
9775 elfNN_aarch64_size_dynamic_sections
9777 #define elf_backend_size_info \
9778 elfNN_aarch64_size_info
9780 #define elf_backend_write_section \
9781 elfNN_aarch64_write_section
9783 #define elf_backend_symbol_processing \
9784 elfNN_aarch64_backend_symbol_processing
9786 #define elf_backend_setup_gnu_properties \
9787 elfNN_aarch64_link_setup_gnu_properties
9789 #define elf_backend_merge_gnu_properties \
9790 elfNN_aarch64_merge_gnu_properties
9792 #define elf_backend_can_refcount 1
9793 #define elf_backend_can_gc_sections 1
9794 #define elf_backend_plt_readonly 1
9795 #define elf_backend_want_got_plt 1
9796 #define elf_backend_want_plt_sym 0
9797 #define elf_backend_want_dynrelro 1
9798 #define elf_backend_may_use_rel_p 0
9799 #define elf_backend_may_use_rela_p 1
9800 #define elf_backend_default_use_rela_p 1
9801 #define elf_backend_rela_normal 1
9802 #define elf_backend_dtrel_excludes_plt 1
9803 #define elf_backend_got_header_size (GOT_ENTRY_SIZE * 3)
9804 #define elf_backend_default_execstack 0
9805 #define elf_backend_extern_protected_data 1
9806 #define elf_backend_hash_symbol elf_aarch64_hash_symbol
9808 #undef elf_backend_obj_attrs_section
9809 #define elf_backend_obj_attrs_section ".ARM.attributes"
9811 #include "elfNN-target.h"
9813 /* CloudABI support. */
9815 #undef TARGET_LITTLE_SYM
9816 #define TARGET_LITTLE_SYM aarch64_elfNN_le_cloudabi_vec
9817 #undef TARGET_LITTLE_NAME
9818 #define TARGET_LITTLE_NAME "elfNN-littleaarch64-cloudabi"
9819 #undef TARGET_BIG_SYM
9820 #define TARGET_BIG_SYM aarch64_elfNN_be_cloudabi_vec
9821 #undef TARGET_BIG_NAME
9822 #define TARGET_BIG_NAME "elfNN-bigaarch64-cloudabi"
9825 #define ELF_OSABI ELFOSABI_CLOUDABI
9828 #define elfNN_bed elfNN_aarch64_cloudabi_bed
9830 #include "elfNN-target.h"