1 /* AArch64-specific support for NN-bit ELF.
2 Copyright (C) 2009-2017 Free Software Foundation, Inc.
3 Contributed by ARM Ltd.
5 This file is part of BFD, the Binary File Descriptor library.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; see the file COPYING3. If not,
19 see <http://www.gnu.org/licenses/>. */
21 /* Notes on implementation:
23 Thread Local Store (TLS)
27 The implementation currently supports both traditional TLS and TLS
28 descriptors, but only general dynamic (GD).
30 For traditional TLS the assembler will present us with code
31 fragments of the form:
34 R_AARCH64_TLSGD_ADR_PAGE21(foo)
35 add x0, :tlsgd_lo12:foo
36 R_AARCH64_TLSGD_ADD_LO12_NC(foo)
40 For TLS descriptors the assembler will present us with code
41 fragments of the form:
43 adrp x0, :tlsdesc:foo R_AARCH64_TLSDESC_ADR_PAGE21(foo)
44 ldr x1, [x0, #:tlsdesc_lo12:foo] R_AARCH64_TLSDESC_LD64_LO12(foo)
45 add x0, x0, #:tlsdesc_lo12:foo R_AARCH64_TLSDESC_ADD_LO12(foo)
47 blr x1 R_AARCH64_TLSDESC_CALL(foo)
49 The relocations R_AARCH64_TLSGD_{ADR_PREL21,ADD_LO12_NC} against foo
50 indicate that foo is thread local and should be accessed via the
51 traditional TLS mechanims.
53 The relocations R_AARCH64_TLSDESC_{ADR_PAGE21,LD64_LO12_NC,ADD_LO12_NC}
54 against foo indicate that 'foo' is thread local and should be accessed
55 via a TLS descriptor mechanism.
57 The precise instruction sequence is only relevant from the
58 perspective of linker relaxation which is currently not implemented.
60 The static linker must detect that 'foo' is a TLS object and
61 allocate a double GOT entry. The GOT entry must be created for both
62 global and local TLS symbols. Note that this is different to none
63 TLS local objects which do not need a GOT entry.
65 In the traditional TLS mechanism, the double GOT entry is used to
66 provide the tls_index structure, containing module and offset
67 entries. The static linker places the relocation R_AARCH64_TLS_DTPMOD
68 on the module entry. The loader will subsequently fixup this
69 relocation with the module identity.
71 For global traditional TLS symbols the static linker places an
72 R_AARCH64_TLS_DTPREL relocation on the offset entry. The loader
73 will subsequently fixup the offset. For local TLS symbols the static
74 linker fixes up offset.
76 In the TLS descriptor mechanism the double GOT entry is used to
77 provide the descriptor. The static linker places the relocation
78 R_AARCH64_TLSDESC on the first GOT slot. The loader will
79 subsequently fix this up.
83 The handling of TLS symbols is implemented across a number of
84 different backend functions. The following is a top level view of
85 what processing is performed where.
87 The TLS implementation maintains state information for each TLS
88 symbol. The state information for local and global symbols is kept
89 in different places. Global symbols use generic BFD structures while
90 local symbols use backend specific structures that are allocated and
91 maintained entirely by the backend.
95 elfNN_aarch64_check_relocs()
97 This function is invoked for each relocation.
99 The TLS relocations R_AARCH64_TLSGD_{ADR_PREL21,ADD_LO12_NC} and
100 R_AARCH64_TLSDESC_{ADR_PAGE21,LD64_LO12_NC,ADD_LO12_NC} are
101 spotted. One time creation of local symbol data structures are
102 created when the first local symbol is seen.
104 The reference count for a symbol is incremented. The GOT type for
105 each symbol is marked as general dynamic.
107 elfNN_aarch64_allocate_dynrelocs ()
109 For each global with positive reference count we allocate a double
110 GOT slot. For a traditional TLS symbol we allocate space for two
111 relocation entries on the GOT, for a TLS descriptor symbol we
112 allocate space for one relocation on the slot. Record the GOT offset
115 elfNN_aarch64_size_dynamic_sections ()
117 Iterate all input BFDS, look for in the local symbol data structure
118 constructed earlier for local TLS symbols and allocate them double
119 GOT slots along with space for a single GOT relocation. Update the
120 local symbol structure to record the GOT offset allocated.
122 elfNN_aarch64_relocate_section ()
124 Calls elfNN_aarch64_final_link_relocate ()
126 Emit the relevant TLS relocations against the GOT for each TLS
127 symbol. For local TLS symbols emit the GOT offset directly. The GOT
128 relocations are emitted once the first time a TLS symbol is
129 encountered. The implementation uses the LSB of the GOT offset to
130 flag that the relevant GOT relocations for a symbol have been
131 emitted. All of the TLS code that uses the GOT offset needs to take
132 care to mask out this flag bit before using the offset.
134 elfNN_aarch64_final_link_relocate ()
136 Fixup the R_AARCH64_TLSGD_{ADR_PREL21, ADD_LO12_NC} relocations. */
140 #include "libiberty.h"
142 #include "bfd_stdint.h"
145 #include "objalloc.h"
146 #include "elf/aarch64.h"
147 #include "elfxx-aarch64.h"
152 #define AARCH64_R(NAME) R_AARCH64_ ## NAME
153 #define AARCH64_R_STR(NAME) "R_AARCH64_" #NAME
154 #define HOWTO64(...) HOWTO (__VA_ARGS__)
155 #define HOWTO32(...) EMPTY_HOWTO (0)
156 #define LOG_FILE_ALIGN 3
160 #define AARCH64_R(NAME) R_AARCH64_P32_ ## NAME
161 #define AARCH64_R_STR(NAME) "R_AARCH64_P32_" #NAME
162 #define HOWTO64(...) EMPTY_HOWTO (0)
163 #define HOWTO32(...) HOWTO (__VA_ARGS__)
164 #define LOG_FILE_ALIGN 2
167 #define IS_AARCH64_TLS_RELOC(R_TYPE) \
168 ((R_TYPE) == BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC \
169 || (R_TYPE) == BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21 \
170 || (R_TYPE) == BFD_RELOC_AARCH64_TLSGD_ADR_PREL21 \
171 || (R_TYPE) == BFD_RELOC_AARCH64_TLSGD_MOVW_G0_NC \
172 || (R_TYPE) == BFD_RELOC_AARCH64_TLSGD_MOVW_G1 \
173 || (R_TYPE) == BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21 \
174 || (R_TYPE) == BFD_RELOC_AARCH64_TLSIE_LD32_GOTTPREL_LO12_NC \
175 || (R_TYPE) == BFD_RELOC_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC \
176 || (R_TYPE) == BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19 \
177 || (R_TYPE) == BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G0_NC \
178 || (R_TYPE) == BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G1 \
179 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_ADD_DTPREL_HI12 \
180 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_ADD_DTPREL_LO12 \
181 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_ADD_DTPREL_LO12_NC \
182 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC \
183 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21 \
184 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_ADR_PREL21 \
185 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_LDST16_DTPREL_LO12 \
186 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_LDST16_DTPREL_LO12_NC \
187 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_LDST32_DTPREL_LO12 \
188 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_LDST32_DTPREL_LO12_NC \
189 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_LDST64_DTPREL_LO12 \
190 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_LDST64_DTPREL_LO12_NC \
191 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_LDST8_DTPREL_LO12 \
192 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_LDST8_DTPREL_LO12_NC \
193 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G0 \
194 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G0_NC \
195 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G1 \
196 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G1_NC \
197 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G2 \
198 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_HI12 \
199 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_LO12 \
200 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_LO12_NC \
201 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0 \
202 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC \
203 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1 \
204 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1_NC \
205 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G2 \
206 || (R_TYPE) == BFD_RELOC_AARCH64_TLS_DTPMOD \
207 || (R_TYPE) == BFD_RELOC_AARCH64_TLS_DTPREL \
208 || (R_TYPE) == BFD_RELOC_AARCH64_TLS_TPREL \
209 || IS_AARCH64_TLSDESC_RELOC ((R_TYPE)))
211 #define IS_AARCH64_TLS_RELAX_RELOC(R_TYPE) \
212 ((R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_ADD \
213 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_ADD_LO12_NC \
214 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21 \
215 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21 \
216 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_CALL \
217 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_LD_PREL19 \
218 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_LDNN_LO12_NC \
219 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_LDR \
220 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_OFF_G0_NC \
221 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_OFF_G1 \
222 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_LDR \
223 || (R_TYPE) == BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21 \
224 || (R_TYPE) == BFD_RELOC_AARCH64_TLSGD_ADR_PREL21 \
225 || (R_TYPE) == BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC \
226 || (R_TYPE) == BFD_RELOC_AARCH64_TLSGD_MOVW_G0_NC \
227 || (R_TYPE) == BFD_RELOC_AARCH64_TLSGD_MOVW_G1 \
228 || (R_TYPE) == BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21 \
229 || (R_TYPE) == BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19 \
230 || (R_TYPE) == BFD_RELOC_AARCH64_TLSIE_LDNN_GOTTPREL_LO12_NC \
231 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC \
232 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21 \
233 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_ADR_PREL21)
235 #define IS_AARCH64_TLSDESC_RELOC(R_TYPE) \
236 ((R_TYPE) == BFD_RELOC_AARCH64_TLSDESC \
237 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_ADD \
238 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_ADD_LO12_NC \
239 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21 \
240 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21 \
241 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_CALL \
242 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_LD32_LO12_NC \
243 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_LD64_LO12_NC \
244 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_LDR \
245 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_LD_PREL19 \
246 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_OFF_G0_NC \
247 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_OFF_G1)
249 #define ELIMINATE_COPY_RELOCS 0
251 /* Return size of a relocation entry. HTAB is the bfd's
252 elf_aarch64_link_hash_entry. */
253 #define RELOC_SIZE(HTAB) (sizeof (ElfNN_External_Rela))
255 /* GOT Entry size - 8 bytes in ELF64 and 4 bytes in ELF32. */
256 #define GOT_ENTRY_SIZE (ARCH_SIZE / 8)
257 #define PLT_ENTRY_SIZE (32)
258 #define PLT_SMALL_ENTRY_SIZE (16)
259 #define PLT_TLSDESC_ENTRY_SIZE (32)
261 /* Encoding of the nop instruction */
262 #define INSN_NOP 0xd503201f
264 #define aarch64_compute_jump_table_size(htab) \
265 (((htab)->root.srelplt == NULL) ? 0 \
266 : (htab)->root.srelplt->reloc_count * GOT_ENTRY_SIZE)
268 /* The first entry in a procedure linkage table looks like this
269 if the distance between the PLTGOT and the PLT is < 4GB use
270 these PLT entries. Note that the dynamic linker gets &PLTGOT[2]
271 in x16 and needs to work out PLTGOT[1] by using an address of
272 [x16,#-GOT_ENTRY_SIZE]. */
273 static const bfd_byte elfNN_aarch64_small_plt0_entry
[PLT_ENTRY_SIZE
] =
275 0xf0, 0x7b, 0xbf, 0xa9, /* stp x16, x30, [sp, #-16]! */
276 0x10, 0x00, 0x00, 0x90, /* adrp x16, (GOT+16) */
278 0x11, 0x0A, 0x40, 0xf9, /* ldr x17, [x16, #PLT_GOT+0x10] */
279 0x10, 0x42, 0x00, 0x91, /* add x16, x16,#PLT_GOT+0x10 */
281 0x11, 0x0A, 0x40, 0xb9, /* ldr w17, [x16, #PLT_GOT+0x8] */
282 0x10, 0x22, 0x00, 0x11, /* add w16, w16,#PLT_GOT+0x8 */
284 0x20, 0x02, 0x1f, 0xd6, /* br x17 */
285 0x1f, 0x20, 0x03, 0xd5, /* nop */
286 0x1f, 0x20, 0x03, 0xd5, /* nop */
287 0x1f, 0x20, 0x03, 0xd5, /* nop */
290 /* Per function entry in a procedure linkage table looks like this
291 if the distance between the PLTGOT and the PLT is < 4GB use
292 these PLT entries. */
293 static const bfd_byte elfNN_aarch64_small_plt_entry
[PLT_SMALL_ENTRY_SIZE
] =
295 0x10, 0x00, 0x00, 0x90, /* adrp x16, PLTGOT + n * 8 */
297 0x11, 0x02, 0x40, 0xf9, /* ldr x17, [x16, PLTGOT + n * 8] */
298 0x10, 0x02, 0x00, 0x91, /* add x16, x16, :lo12:PLTGOT + n * 8 */
300 0x11, 0x02, 0x40, 0xb9, /* ldr w17, [x16, PLTGOT + n * 4] */
301 0x10, 0x02, 0x00, 0x11, /* add w16, w16, :lo12:PLTGOT + n * 4 */
303 0x20, 0x02, 0x1f, 0xd6, /* br x17. */
306 static const bfd_byte
307 elfNN_aarch64_tlsdesc_small_plt_entry
[PLT_TLSDESC_ENTRY_SIZE
] =
309 0xe2, 0x0f, 0xbf, 0xa9, /* stp x2, x3, [sp, #-16]! */
310 0x02, 0x00, 0x00, 0x90, /* adrp x2, 0 */
311 0x03, 0x00, 0x00, 0x90, /* adrp x3, 0 */
313 0x42, 0x00, 0x40, 0xf9, /* ldr x2, [x2, #0] */
314 0x63, 0x00, 0x00, 0x91, /* add x3, x3, 0 */
316 0x42, 0x00, 0x40, 0xb9, /* ldr w2, [x2, #0] */
317 0x63, 0x00, 0x00, 0x11, /* add w3, w3, 0 */
319 0x40, 0x00, 0x1f, 0xd6, /* br x2 */
320 0x1f, 0x20, 0x03, 0xd5, /* nop */
321 0x1f, 0x20, 0x03, 0xd5, /* nop */
324 #define elf_info_to_howto elfNN_aarch64_info_to_howto
325 #define elf_info_to_howto_rel elfNN_aarch64_info_to_howto
327 #define AARCH64_ELF_ABI_VERSION 0
329 /* In case we're on a 32-bit machine, construct a 64-bit "-1" value. */
330 #define ALL_ONES (~ (bfd_vma) 0)
332 /* Indexed by the bfd interal reloc enumerators.
333 Therefore, the table needs to be synced with BFD_RELOC_AARCH64_*
336 static reloc_howto_type elfNN_aarch64_howto_table
[] =
340 /* Basic data relocations. */
342 /* Deprecated, but retained for backwards compatibility. */
343 HOWTO64 (R_AARCH64_NULL
, /* type */
345 3, /* size (0 = byte, 1 = short, 2 = long) */
347 FALSE
, /* pc_relative */
349 complain_overflow_dont
, /* complain_on_overflow */
350 bfd_elf_generic_reloc
, /* special_function */
351 "R_AARCH64_NULL", /* name */
352 FALSE
, /* partial_inplace */
355 FALSE
), /* pcrel_offset */
356 HOWTO (R_AARCH64_NONE
, /* type */
358 3, /* size (0 = byte, 1 = short, 2 = long) */
360 FALSE
, /* pc_relative */
362 complain_overflow_dont
, /* complain_on_overflow */
363 bfd_elf_generic_reloc
, /* special_function */
364 "R_AARCH64_NONE", /* name */
365 FALSE
, /* partial_inplace */
368 FALSE
), /* pcrel_offset */
371 HOWTO64 (AARCH64_R (ABS64
), /* type */
373 4, /* size (4 = long long) */
375 FALSE
, /* pc_relative */
377 complain_overflow_unsigned
, /* complain_on_overflow */
378 bfd_elf_generic_reloc
, /* special_function */
379 AARCH64_R_STR (ABS64
), /* name */
380 FALSE
, /* partial_inplace */
381 ALL_ONES
, /* src_mask */
382 ALL_ONES
, /* dst_mask */
383 FALSE
), /* pcrel_offset */
386 HOWTO (AARCH64_R (ABS32
), /* type */
388 2, /* size (0 = byte, 1 = short, 2 = long) */
390 FALSE
, /* pc_relative */
392 complain_overflow_unsigned
, /* complain_on_overflow */
393 bfd_elf_generic_reloc
, /* special_function */
394 AARCH64_R_STR (ABS32
), /* name */
395 FALSE
, /* partial_inplace */
396 0xffffffff, /* src_mask */
397 0xffffffff, /* dst_mask */
398 FALSE
), /* pcrel_offset */
401 HOWTO (AARCH64_R (ABS16
), /* type */
403 1, /* size (0 = byte, 1 = short, 2 = long) */
405 FALSE
, /* pc_relative */
407 complain_overflow_unsigned
, /* complain_on_overflow */
408 bfd_elf_generic_reloc
, /* special_function */
409 AARCH64_R_STR (ABS16
), /* name */
410 FALSE
, /* partial_inplace */
411 0xffff, /* src_mask */
412 0xffff, /* dst_mask */
413 FALSE
), /* pcrel_offset */
415 /* .xword: (S+A-P) */
416 HOWTO64 (AARCH64_R (PREL64
), /* type */
418 4, /* size (4 = long long) */
420 TRUE
, /* pc_relative */
422 complain_overflow_signed
, /* complain_on_overflow */
423 bfd_elf_generic_reloc
, /* special_function */
424 AARCH64_R_STR (PREL64
), /* name */
425 FALSE
, /* partial_inplace */
426 ALL_ONES
, /* src_mask */
427 ALL_ONES
, /* dst_mask */
428 TRUE
), /* pcrel_offset */
431 HOWTO (AARCH64_R (PREL32
), /* type */
433 2, /* size (0 = byte, 1 = short, 2 = long) */
435 TRUE
, /* pc_relative */
437 complain_overflow_signed
, /* complain_on_overflow */
438 bfd_elf_generic_reloc
, /* special_function */
439 AARCH64_R_STR (PREL32
), /* name */
440 FALSE
, /* partial_inplace */
441 0xffffffff, /* src_mask */
442 0xffffffff, /* dst_mask */
443 TRUE
), /* pcrel_offset */
446 HOWTO (AARCH64_R (PREL16
), /* type */
448 1, /* size (0 = byte, 1 = short, 2 = long) */
450 TRUE
, /* pc_relative */
452 complain_overflow_signed
, /* complain_on_overflow */
453 bfd_elf_generic_reloc
, /* special_function */
454 AARCH64_R_STR (PREL16
), /* name */
455 FALSE
, /* partial_inplace */
456 0xffff, /* src_mask */
457 0xffff, /* dst_mask */
458 TRUE
), /* pcrel_offset */
460 /* Group relocations to create a 16, 32, 48 or 64 bit
461 unsigned data or abs address inline. */
463 /* MOVZ: ((S+A) >> 0) & 0xffff */
464 HOWTO (AARCH64_R (MOVW_UABS_G0
), /* type */
466 2, /* size (0 = byte, 1 = short, 2 = long) */
468 FALSE
, /* pc_relative */
470 complain_overflow_unsigned
, /* complain_on_overflow */
471 bfd_elf_generic_reloc
, /* special_function */
472 AARCH64_R_STR (MOVW_UABS_G0
), /* name */
473 FALSE
, /* partial_inplace */
474 0xffff, /* src_mask */
475 0xffff, /* dst_mask */
476 FALSE
), /* pcrel_offset */
478 /* MOVK: ((S+A) >> 0) & 0xffff [no overflow check] */
479 HOWTO (AARCH64_R (MOVW_UABS_G0_NC
), /* type */
481 2, /* size (0 = byte, 1 = short, 2 = long) */
483 FALSE
, /* pc_relative */
485 complain_overflow_dont
, /* complain_on_overflow */
486 bfd_elf_generic_reloc
, /* special_function */
487 AARCH64_R_STR (MOVW_UABS_G0_NC
), /* name */
488 FALSE
, /* partial_inplace */
489 0xffff, /* src_mask */
490 0xffff, /* dst_mask */
491 FALSE
), /* pcrel_offset */
493 /* MOVZ: ((S+A) >> 16) & 0xffff */
494 HOWTO (AARCH64_R (MOVW_UABS_G1
), /* type */
496 2, /* size (0 = byte, 1 = short, 2 = long) */
498 FALSE
, /* pc_relative */
500 complain_overflow_unsigned
, /* complain_on_overflow */
501 bfd_elf_generic_reloc
, /* special_function */
502 AARCH64_R_STR (MOVW_UABS_G1
), /* name */
503 FALSE
, /* partial_inplace */
504 0xffff, /* src_mask */
505 0xffff, /* dst_mask */
506 FALSE
), /* pcrel_offset */
508 /* MOVK: ((S+A) >> 16) & 0xffff [no overflow check] */
509 HOWTO64 (AARCH64_R (MOVW_UABS_G1_NC
), /* type */
511 2, /* size (0 = byte, 1 = short, 2 = long) */
513 FALSE
, /* pc_relative */
515 complain_overflow_dont
, /* complain_on_overflow */
516 bfd_elf_generic_reloc
, /* special_function */
517 AARCH64_R_STR (MOVW_UABS_G1_NC
), /* name */
518 FALSE
, /* partial_inplace */
519 0xffff, /* src_mask */
520 0xffff, /* dst_mask */
521 FALSE
), /* pcrel_offset */
523 /* MOVZ: ((S+A) >> 32) & 0xffff */
524 HOWTO64 (AARCH64_R (MOVW_UABS_G2
), /* type */
526 2, /* size (0 = byte, 1 = short, 2 = long) */
528 FALSE
, /* pc_relative */
530 complain_overflow_unsigned
, /* complain_on_overflow */
531 bfd_elf_generic_reloc
, /* special_function */
532 AARCH64_R_STR (MOVW_UABS_G2
), /* name */
533 FALSE
, /* partial_inplace */
534 0xffff, /* src_mask */
535 0xffff, /* dst_mask */
536 FALSE
), /* pcrel_offset */
538 /* MOVK: ((S+A) >> 32) & 0xffff [no overflow check] */
539 HOWTO64 (AARCH64_R (MOVW_UABS_G2_NC
), /* type */
541 2, /* size (0 = byte, 1 = short, 2 = long) */
543 FALSE
, /* pc_relative */
545 complain_overflow_dont
, /* complain_on_overflow */
546 bfd_elf_generic_reloc
, /* special_function */
547 AARCH64_R_STR (MOVW_UABS_G2_NC
), /* name */
548 FALSE
, /* partial_inplace */
549 0xffff, /* src_mask */
550 0xffff, /* dst_mask */
551 FALSE
), /* pcrel_offset */
553 /* MOVZ: ((S+A) >> 48) & 0xffff */
554 HOWTO64 (AARCH64_R (MOVW_UABS_G3
), /* type */
556 2, /* size (0 = byte, 1 = short, 2 = long) */
558 FALSE
, /* pc_relative */
560 complain_overflow_unsigned
, /* complain_on_overflow */
561 bfd_elf_generic_reloc
, /* special_function */
562 AARCH64_R_STR (MOVW_UABS_G3
), /* name */
563 FALSE
, /* partial_inplace */
564 0xffff, /* src_mask */
565 0xffff, /* dst_mask */
566 FALSE
), /* pcrel_offset */
568 /* Group relocations to create high part of a 16, 32, 48 or 64 bit
569 signed data or abs address inline. Will change instruction
570 to MOVN or MOVZ depending on sign of calculated value. */
572 /* MOV[ZN]: ((S+A) >> 0) & 0xffff */
573 HOWTO (AARCH64_R (MOVW_SABS_G0
), /* type */
575 2, /* size (0 = byte, 1 = short, 2 = long) */
577 FALSE
, /* pc_relative */
579 complain_overflow_signed
, /* complain_on_overflow */
580 bfd_elf_generic_reloc
, /* special_function */
581 AARCH64_R_STR (MOVW_SABS_G0
), /* name */
582 FALSE
, /* partial_inplace */
583 0xffff, /* src_mask */
584 0xffff, /* dst_mask */
585 FALSE
), /* pcrel_offset */
587 /* MOV[ZN]: ((S+A) >> 16) & 0xffff */
588 HOWTO64 (AARCH64_R (MOVW_SABS_G1
), /* type */
590 2, /* size (0 = byte, 1 = short, 2 = long) */
592 FALSE
, /* pc_relative */
594 complain_overflow_signed
, /* complain_on_overflow */
595 bfd_elf_generic_reloc
, /* special_function */
596 AARCH64_R_STR (MOVW_SABS_G1
), /* name */
597 FALSE
, /* partial_inplace */
598 0xffff, /* src_mask */
599 0xffff, /* dst_mask */
600 FALSE
), /* pcrel_offset */
602 /* MOV[ZN]: ((S+A) >> 32) & 0xffff */
603 HOWTO64 (AARCH64_R (MOVW_SABS_G2
), /* type */
605 2, /* size (0 = byte, 1 = short, 2 = long) */
607 FALSE
, /* pc_relative */
609 complain_overflow_signed
, /* complain_on_overflow */
610 bfd_elf_generic_reloc
, /* special_function */
611 AARCH64_R_STR (MOVW_SABS_G2
), /* name */
612 FALSE
, /* partial_inplace */
613 0xffff, /* src_mask */
614 0xffff, /* dst_mask */
615 FALSE
), /* pcrel_offset */
617 /* Relocations to generate 19, 21 and 33 bit PC-relative load/store
618 addresses: PG(x) is (x & ~0xfff). */
620 /* LD-lit: ((S+A-P) >> 2) & 0x7ffff */
621 HOWTO (AARCH64_R (LD_PREL_LO19
), /* type */
623 2, /* size (0 = byte, 1 = short, 2 = long) */
625 TRUE
, /* pc_relative */
627 complain_overflow_signed
, /* complain_on_overflow */
628 bfd_elf_generic_reloc
, /* special_function */
629 AARCH64_R_STR (LD_PREL_LO19
), /* name */
630 FALSE
, /* partial_inplace */
631 0x7ffff, /* src_mask */
632 0x7ffff, /* dst_mask */
633 TRUE
), /* pcrel_offset */
635 /* ADR: (S+A-P) & 0x1fffff */
636 HOWTO (AARCH64_R (ADR_PREL_LO21
), /* type */
638 2, /* size (0 = byte, 1 = short, 2 = long) */
640 TRUE
, /* pc_relative */
642 complain_overflow_signed
, /* complain_on_overflow */
643 bfd_elf_generic_reloc
, /* special_function */
644 AARCH64_R_STR (ADR_PREL_LO21
), /* name */
645 FALSE
, /* partial_inplace */
646 0x1fffff, /* src_mask */
647 0x1fffff, /* dst_mask */
648 TRUE
), /* pcrel_offset */
650 /* ADRP: ((PG(S+A)-PG(P)) >> 12) & 0x1fffff */
651 HOWTO (AARCH64_R (ADR_PREL_PG_HI21
), /* type */
653 2, /* size (0 = byte, 1 = short, 2 = long) */
655 TRUE
, /* pc_relative */
657 complain_overflow_signed
, /* complain_on_overflow */
658 bfd_elf_generic_reloc
, /* special_function */
659 AARCH64_R_STR (ADR_PREL_PG_HI21
), /* name */
660 FALSE
, /* partial_inplace */
661 0x1fffff, /* src_mask */
662 0x1fffff, /* dst_mask */
663 TRUE
), /* pcrel_offset */
665 /* ADRP: ((PG(S+A)-PG(P)) >> 12) & 0x1fffff [no overflow check] */
666 HOWTO64 (AARCH64_R (ADR_PREL_PG_HI21_NC
), /* type */
668 2, /* size (0 = byte, 1 = short, 2 = long) */
670 TRUE
, /* pc_relative */
672 complain_overflow_dont
, /* complain_on_overflow */
673 bfd_elf_generic_reloc
, /* special_function */
674 AARCH64_R_STR (ADR_PREL_PG_HI21_NC
), /* name */
675 FALSE
, /* partial_inplace */
676 0x1fffff, /* src_mask */
677 0x1fffff, /* dst_mask */
678 TRUE
), /* pcrel_offset */
680 /* ADD: (S+A) & 0xfff [no overflow check] */
681 HOWTO (AARCH64_R (ADD_ABS_LO12_NC
), /* type */
683 2, /* size (0 = byte, 1 = short, 2 = long) */
685 FALSE
, /* pc_relative */
687 complain_overflow_dont
, /* complain_on_overflow */
688 bfd_elf_generic_reloc
, /* special_function */
689 AARCH64_R_STR (ADD_ABS_LO12_NC
), /* name */
690 FALSE
, /* partial_inplace */
691 0x3ffc00, /* src_mask */
692 0x3ffc00, /* dst_mask */
693 FALSE
), /* pcrel_offset */
695 /* LD/ST8: (S+A) & 0xfff */
696 HOWTO (AARCH64_R (LDST8_ABS_LO12_NC
), /* type */
698 2, /* size (0 = byte, 1 = short, 2 = long) */
700 FALSE
, /* pc_relative */
702 complain_overflow_dont
, /* complain_on_overflow */
703 bfd_elf_generic_reloc
, /* special_function */
704 AARCH64_R_STR (LDST8_ABS_LO12_NC
), /* name */
705 FALSE
, /* partial_inplace */
706 0xfff, /* src_mask */
707 0xfff, /* dst_mask */
708 FALSE
), /* pcrel_offset */
710 /* Relocations for control-flow instructions. */
712 /* TBZ/NZ: ((S+A-P) >> 2) & 0x3fff */
713 HOWTO (AARCH64_R (TSTBR14
), /* type */
715 2, /* size (0 = byte, 1 = short, 2 = long) */
717 TRUE
, /* pc_relative */
719 complain_overflow_signed
, /* complain_on_overflow */
720 bfd_elf_generic_reloc
, /* special_function */
721 AARCH64_R_STR (TSTBR14
), /* name */
722 FALSE
, /* partial_inplace */
723 0x3fff, /* src_mask */
724 0x3fff, /* dst_mask */
725 TRUE
), /* pcrel_offset */
727 /* B.cond: ((S+A-P) >> 2) & 0x7ffff */
728 HOWTO (AARCH64_R (CONDBR19
), /* type */
730 2, /* size (0 = byte, 1 = short, 2 = long) */
732 TRUE
, /* pc_relative */
734 complain_overflow_signed
, /* complain_on_overflow */
735 bfd_elf_generic_reloc
, /* special_function */
736 AARCH64_R_STR (CONDBR19
), /* name */
737 FALSE
, /* partial_inplace */
738 0x7ffff, /* src_mask */
739 0x7ffff, /* dst_mask */
740 TRUE
), /* pcrel_offset */
742 /* B: ((S+A-P) >> 2) & 0x3ffffff */
743 HOWTO (AARCH64_R (JUMP26
), /* type */
745 2, /* size (0 = byte, 1 = short, 2 = long) */
747 TRUE
, /* pc_relative */
749 complain_overflow_signed
, /* complain_on_overflow */
750 bfd_elf_generic_reloc
, /* special_function */
751 AARCH64_R_STR (JUMP26
), /* name */
752 FALSE
, /* partial_inplace */
753 0x3ffffff, /* src_mask */
754 0x3ffffff, /* dst_mask */
755 TRUE
), /* pcrel_offset */
757 /* BL: ((S+A-P) >> 2) & 0x3ffffff */
758 HOWTO (AARCH64_R (CALL26
), /* type */
760 2, /* size (0 = byte, 1 = short, 2 = long) */
762 TRUE
, /* pc_relative */
764 complain_overflow_signed
, /* complain_on_overflow */
765 bfd_elf_generic_reloc
, /* special_function */
766 AARCH64_R_STR (CALL26
), /* name */
767 FALSE
, /* partial_inplace */
768 0x3ffffff, /* src_mask */
769 0x3ffffff, /* dst_mask */
770 TRUE
), /* pcrel_offset */
772 /* LD/ST16: (S+A) & 0xffe */
773 HOWTO (AARCH64_R (LDST16_ABS_LO12_NC
), /* type */
775 2, /* size (0 = byte, 1 = short, 2 = long) */
777 FALSE
, /* pc_relative */
779 complain_overflow_dont
, /* complain_on_overflow */
780 bfd_elf_generic_reloc
, /* special_function */
781 AARCH64_R_STR (LDST16_ABS_LO12_NC
), /* name */
782 FALSE
, /* partial_inplace */
783 0xffe, /* src_mask */
784 0xffe, /* dst_mask */
785 FALSE
), /* pcrel_offset */
787 /* LD/ST32: (S+A) & 0xffc */
788 HOWTO (AARCH64_R (LDST32_ABS_LO12_NC
), /* type */
790 2, /* size (0 = byte, 1 = short, 2 = long) */
792 FALSE
, /* pc_relative */
794 complain_overflow_dont
, /* complain_on_overflow */
795 bfd_elf_generic_reloc
, /* special_function */
796 AARCH64_R_STR (LDST32_ABS_LO12_NC
), /* name */
797 FALSE
, /* partial_inplace */
798 0xffc, /* src_mask */
799 0xffc, /* dst_mask */
800 FALSE
), /* pcrel_offset */
802 /* LD/ST64: (S+A) & 0xff8 */
803 HOWTO (AARCH64_R (LDST64_ABS_LO12_NC
), /* type */
805 2, /* size (0 = byte, 1 = short, 2 = long) */
807 FALSE
, /* pc_relative */
809 complain_overflow_dont
, /* complain_on_overflow */
810 bfd_elf_generic_reloc
, /* special_function */
811 AARCH64_R_STR (LDST64_ABS_LO12_NC
), /* name */
812 FALSE
, /* partial_inplace */
813 0xff8, /* src_mask */
814 0xff8, /* dst_mask */
815 FALSE
), /* pcrel_offset */
817 /* LD/ST128: (S+A) & 0xff0 */
818 HOWTO (AARCH64_R (LDST128_ABS_LO12_NC
), /* type */
820 2, /* size (0 = byte, 1 = short, 2 = long) */
822 FALSE
, /* pc_relative */
824 complain_overflow_dont
, /* complain_on_overflow */
825 bfd_elf_generic_reloc
, /* special_function */
826 AARCH64_R_STR (LDST128_ABS_LO12_NC
), /* name */
827 FALSE
, /* partial_inplace */
828 0xff0, /* src_mask */
829 0xff0, /* dst_mask */
830 FALSE
), /* pcrel_offset */
832 /* Set a load-literal immediate field to bits
833 0x1FFFFC of G(S)-P */
834 HOWTO (AARCH64_R (GOT_LD_PREL19
), /* type */
836 2, /* size (0 = byte,1 = short,2 = long) */
838 TRUE
, /* pc_relative */
840 complain_overflow_signed
, /* complain_on_overflow */
841 bfd_elf_generic_reloc
, /* special_function */
842 AARCH64_R_STR (GOT_LD_PREL19
), /* name */
843 FALSE
, /* partial_inplace */
844 0xffffe0, /* src_mask */
845 0xffffe0, /* dst_mask */
846 TRUE
), /* pcrel_offset */
848 /* Get to the page for the GOT entry for the symbol
849 (G(S) - P) using an ADRP instruction. */
850 HOWTO (AARCH64_R (ADR_GOT_PAGE
), /* type */
852 2, /* size (0 = byte, 1 = short, 2 = long) */
854 TRUE
, /* pc_relative */
856 complain_overflow_dont
, /* complain_on_overflow */
857 bfd_elf_generic_reloc
, /* special_function */
858 AARCH64_R_STR (ADR_GOT_PAGE
), /* name */
859 FALSE
, /* partial_inplace */
860 0x1fffff, /* src_mask */
861 0x1fffff, /* dst_mask */
862 TRUE
), /* pcrel_offset */
864 /* LD64: GOT offset G(S) & 0xff8 */
865 HOWTO64 (AARCH64_R (LD64_GOT_LO12_NC
), /* type */
867 2, /* size (0 = byte, 1 = short, 2 = long) */
869 FALSE
, /* pc_relative */
871 complain_overflow_dont
, /* complain_on_overflow */
872 bfd_elf_generic_reloc
, /* special_function */
873 AARCH64_R_STR (LD64_GOT_LO12_NC
), /* name */
874 FALSE
, /* partial_inplace */
875 0xff8, /* src_mask */
876 0xff8, /* dst_mask */
877 FALSE
), /* pcrel_offset */
879 /* LD32: GOT offset G(S) & 0xffc */
880 HOWTO32 (AARCH64_R (LD32_GOT_LO12_NC
), /* type */
882 2, /* size (0 = byte, 1 = short, 2 = long) */
884 FALSE
, /* pc_relative */
886 complain_overflow_dont
, /* complain_on_overflow */
887 bfd_elf_generic_reloc
, /* special_function */
888 AARCH64_R_STR (LD32_GOT_LO12_NC
), /* name */
889 FALSE
, /* partial_inplace */
890 0xffc, /* src_mask */
891 0xffc, /* dst_mask */
892 FALSE
), /* pcrel_offset */
894 /* Lower 16 bits of GOT offset for the symbol. */
895 HOWTO64 (AARCH64_R (MOVW_GOTOFF_G0_NC
), /* type */
897 2, /* size (0 = byte, 1 = short, 2 = long) */
899 FALSE
, /* pc_relative */
901 complain_overflow_dont
, /* complain_on_overflow */
902 bfd_elf_generic_reloc
, /* special_function */
903 AARCH64_R_STR (MOVW_GOTOFF_G0_NC
), /* name */
904 FALSE
, /* partial_inplace */
905 0xffff, /* src_mask */
906 0xffff, /* dst_mask */
907 FALSE
), /* pcrel_offset */
909 /* Higher 16 bits of GOT offset for the symbol. */
910 HOWTO64 (AARCH64_R (MOVW_GOTOFF_G1
), /* type */
912 2, /* size (0 = byte, 1 = short, 2 = long) */
914 FALSE
, /* pc_relative */
916 complain_overflow_unsigned
, /* complain_on_overflow */
917 bfd_elf_generic_reloc
, /* special_function */
918 AARCH64_R_STR (MOVW_GOTOFF_G1
), /* name */
919 FALSE
, /* partial_inplace */
920 0xffff, /* src_mask */
921 0xffff, /* dst_mask */
922 FALSE
), /* pcrel_offset */
924 /* LD64: GOT offset for the symbol. */
925 HOWTO64 (AARCH64_R (LD64_GOTOFF_LO15
), /* type */
927 2, /* size (0 = byte, 1 = short, 2 = long) */
929 FALSE
, /* pc_relative */
931 complain_overflow_unsigned
, /* complain_on_overflow */
932 bfd_elf_generic_reloc
, /* special_function */
933 AARCH64_R_STR (LD64_GOTOFF_LO15
), /* name */
934 FALSE
, /* partial_inplace */
935 0x7ff8, /* src_mask */
936 0x7ff8, /* dst_mask */
937 FALSE
), /* pcrel_offset */
939 /* LD32: GOT offset to the page address of GOT table.
940 (G(S) - PAGE (_GLOBAL_OFFSET_TABLE_)) & 0x5ffc. */
941 HOWTO32 (AARCH64_R (LD32_GOTPAGE_LO14
), /* type */
943 2, /* size (0 = byte, 1 = short, 2 = long) */
945 FALSE
, /* pc_relative */
947 complain_overflow_unsigned
, /* complain_on_overflow */
948 bfd_elf_generic_reloc
, /* special_function */
949 AARCH64_R_STR (LD32_GOTPAGE_LO14
), /* name */
950 FALSE
, /* partial_inplace */
951 0x5ffc, /* src_mask */
952 0x5ffc, /* dst_mask */
953 FALSE
), /* pcrel_offset */
955 /* LD64: GOT offset to the page address of GOT table.
956 (G(S) - PAGE (_GLOBAL_OFFSET_TABLE_)) & 0x7ff8. */
957 HOWTO64 (AARCH64_R (LD64_GOTPAGE_LO15
), /* type */
959 2, /* size (0 = byte, 1 = short, 2 = long) */
961 FALSE
, /* pc_relative */
963 complain_overflow_unsigned
, /* complain_on_overflow */
964 bfd_elf_generic_reloc
, /* special_function */
965 AARCH64_R_STR (LD64_GOTPAGE_LO15
), /* name */
966 FALSE
, /* partial_inplace */
967 0x7ff8, /* src_mask */
968 0x7ff8, /* dst_mask */
969 FALSE
), /* pcrel_offset */
971 /* Get to the page for the GOT entry for the symbol
972 (G(S) - P) using an ADRP instruction. */
973 HOWTO (AARCH64_R (TLSGD_ADR_PAGE21
), /* type */
975 2, /* size (0 = byte, 1 = short, 2 = long) */
977 TRUE
, /* pc_relative */
979 complain_overflow_dont
, /* complain_on_overflow */
980 bfd_elf_generic_reloc
, /* special_function */
981 AARCH64_R_STR (TLSGD_ADR_PAGE21
), /* name */
982 FALSE
, /* partial_inplace */
983 0x1fffff, /* src_mask */
984 0x1fffff, /* dst_mask */
985 TRUE
), /* pcrel_offset */
987 HOWTO (AARCH64_R (TLSGD_ADR_PREL21
), /* type */
989 2, /* size (0 = byte, 1 = short, 2 = long) */
991 TRUE
, /* pc_relative */
993 complain_overflow_dont
, /* complain_on_overflow */
994 bfd_elf_generic_reloc
, /* special_function */
995 AARCH64_R_STR (TLSGD_ADR_PREL21
), /* name */
996 FALSE
, /* partial_inplace */
997 0x1fffff, /* src_mask */
998 0x1fffff, /* dst_mask */
999 TRUE
), /* pcrel_offset */
1001 /* ADD: GOT offset G(S) & 0xff8 [no overflow check] */
1002 HOWTO (AARCH64_R (TLSGD_ADD_LO12_NC
), /* type */
1004 2, /* size (0 = byte, 1 = short, 2 = long) */
1006 FALSE
, /* pc_relative */
1008 complain_overflow_dont
, /* complain_on_overflow */
1009 bfd_elf_generic_reloc
, /* special_function */
1010 AARCH64_R_STR (TLSGD_ADD_LO12_NC
), /* name */
1011 FALSE
, /* partial_inplace */
1012 0xfff, /* src_mask */
1013 0xfff, /* dst_mask */
1014 FALSE
), /* pcrel_offset */
1016 /* Lower 16 bits of GOT offset to tls_index. */
1017 HOWTO64 (AARCH64_R (TLSGD_MOVW_G0_NC
), /* type */
1019 2, /* size (0 = byte, 1 = short, 2 = long) */
1021 FALSE
, /* pc_relative */
1023 complain_overflow_dont
, /* complain_on_overflow */
1024 bfd_elf_generic_reloc
, /* special_function */
1025 AARCH64_R_STR (TLSGD_MOVW_G0_NC
), /* name */
1026 FALSE
, /* partial_inplace */
1027 0xffff, /* src_mask */
1028 0xffff, /* dst_mask */
1029 FALSE
), /* pcrel_offset */
1031 /* Higher 16 bits of GOT offset to tls_index. */
1032 HOWTO64 (AARCH64_R (TLSGD_MOVW_G1
), /* type */
1033 16, /* rightshift */
1034 2, /* size (0 = byte, 1 = short, 2 = long) */
1036 FALSE
, /* pc_relative */
1038 complain_overflow_unsigned
, /* complain_on_overflow */
1039 bfd_elf_generic_reloc
, /* special_function */
1040 AARCH64_R_STR (TLSGD_MOVW_G1
), /* name */
1041 FALSE
, /* partial_inplace */
1042 0xffff, /* src_mask */
1043 0xffff, /* dst_mask */
1044 FALSE
), /* pcrel_offset */
1046 HOWTO (AARCH64_R (TLSIE_ADR_GOTTPREL_PAGE21
), /* type */
1047 12, /* rightshift */
1048 2, /* size (0 = byte, 1 = short, 2 = long) */
1050 FALSE
, /* pc_relative */
1052 complain_overflow_dont
, /* complain_on_overflow */
1053 bfd_elf_generic_reloc
, /* special_function */
1054 AARCH64_R_STR (TLSIE_ADR_GOTTPREL_PAGE21
), /* name */
1055 FALSE
, /* partial_inplace */
1056 0x1fffff, /* src_mask */
1057 0x1fffff, /* dst_mask */
1058 FALSE
), /* pcrel_offset */
1060 HOWTO64 (AARCH64_R (TLSIE_LD64_GOTTPREL_LO12_NC
), /* type */
1062 2, /* size (0 = byte, 1 = short, 2 = long) */
1064 FALSE
, /* pc_relative */
1066 complain_overflow_dont
, /* complain_on_overflow */
1067 bfd_elf_generic_reloc
, /* special_function */
1068 AARCH64_R_STR (TLSIE_LD64_GOTTPREL_LO12_NC
), /* name */
1069 FALSE
, /* partial_inplace */
1070 0xff8, /* src_mask */
1071 0xff8, /* dst_mask */
1072 FALSE
), /* pcrel_offset */
1074 HOWTO32 (AARCH64_R (TLSIE_LD32_GOTTPREL_LO12_NC
), /* type */
1076 2, /* size (0 = byte, 1 = short, 2 = long) */
1078 FALSE
, /* pc_relative */
1080 complain_overflow_dont
, /* complain_on_overflow */
1081 bfd_elf_generic_reloc
, /* special_function */
1082 AARCH64_R_STR (TLSIE_LD32_GOTTPREL_LO12_NC
), /* name */
1083 FALSE
, /* partial_inplace */
1084 0xffc, /* src_mask */
1085 0xffc, /* dst_mask */
1086 FALSE
), /* pcrel_offset */
1088 HOWTO (AARCH64_R (TLSIE_LD_GOTTPREL_PREL19
), /* type */
1090 2, /* size (0 = byte, 1 = short, 2 = long) */
1092 FALSE
, /* pc_relative */
1094 complain_overflow_dont
, /* complain_on_overflow */
1095 bfd_elf_generic_reloc
, /* special_function */
1096 AARCH64_R_STR (TLSIE_LD_GOTTPREL_PREL19
), /* name */
1097 FALSE
, /* partial_inplace */
1098 0x1ffffc, /* src_mask */
1099 0x1ffffc, /* dst_mask */
1100 FALSE
), /* pcrel_offset */
1102 HOWTO64 (AARCH64_R (TLSIE_MOVW_GOTTPREL_G0_NC
), /* type */
1104 2, /* size (0 = byte, 1 = short, 2 = long) */
1106 FALSE
, /* pc_relative */
1108 complain_overflow_dont
, /* complain_on_overflow */
1109 bfd_elf_generic_reloc
, /* special_function */
1110 AARCH64_R_STR (TLSIE_MOVW_GOTTPREL_G0_NC
), /* name */
1111 FALSE
, /* partial_inplace */
1112 0xffff, /* src_mask */
1113 0xffff, /* dst_mask */
1114 FALSE
), /* pcrel_offset */
1116 HOWTO64 (AARCH64_R (TLSIE_MOVW_GOTTPREL_G1
), /* type */
1117 16, /* rightshift */
1118 2, /* size (0 = byte, 1 = short, 2 = long) */
1120 FALSE
, /* pc_relative */
1122 complain_overflow_unsigned
, /* complain_on_overflow */
1123 bfd_elf_generic_reloc
, /* special_function */
1124 AARCH64_R_STR (TLSIE_MOVW_GOTTPREL_G1
), /* name */
1125 FALSE
, /* partial_inplace */
1126 0xffff, /* src_mask */
1127 0xffff, /* dst_mask */
1128 FALSE
), /* pcrel_offset */
1130 /* ADD: bit[23:12] of byte offset to module TLS base address. */
1131 HOWTO (AARCH64_R (TLSLD_ADD_DTPREL_HI12
), /* type */
1132 12, /* rightshift */
1133 2, /* size (0 = byte, 1 = short, 2 = long) */
1135 FALSE
, /* pc_relative */
1137 complain_overflow_unsigned
, /* complain_on_overflow */
1138 bfd_elf_generic_reloc
, /* special_function */
1139 AARCH64_R_STR (TLSLD_ADD_DTPREL_HI12
), /* name */
1140 FALSE
, /* partial_inplace */
1141 0xfff, /* src_mask */
1142 0xfff, /* dst_mask */
1143 FALSE
), /* pcrel_offset */
1145 /* Unsigned 12 bit byte offset to module TLS base address. */
1146 HOWTO (AARCH64_R (TLSLD_ADD_DTPREL_LO12
), /* type */
1148 2, /* size (0 = byte, 1 = short, 2 = long) */
1150 FALSE
, /* pc_relative */
1152 complain_overflow_unsigned
, /* complain_on_overflow */
1153 bfd_elf_generic_reloc
, /* special_function */
1154 AARCH64_R_STR (TLSLD_ADD_DTPREL_LO12
), /* name */
1155 FALSE
, /* partial_inplace */
1156 0xfff, /* src_mask */
1157 0xfff, /* dst_mask */
1158 FALSE
), /* pcrel_offset */
1160 /* No overflow check version of BFD_RELOC_AARCH64_TLSLD_ADD_DTPREL_LO12. */
1161 HOWTO (AARCH64_R (TLSLD_ADD_DTPREL_LO12_NC
), /* type */
1163 2, /* size (0 = byte, 1 = short, 2 = long) */
1165 FALSE
, /* pc_relative */
1167 complain_overflow_dont
, /* complain_on_overflow */
1168 bfd_elf_generic_reloc
, /* special_function */
1169 AARCH64_R_STR (TLSLD_ADD_DTPREL_LO12_NC
), /* name */
1170 FALSE
, /* partial_inplace */
1171 0xfff, /* src_mask */
1172 0xfff, /* dst_mask */
1173 FALSE
), /* pcrel_offset */
1175 /* ADD: GOT offset G(S) & 0xff8 [no overflow check] */
1176 HOWTO (AARCH64_R (TLSLD_ADD_LO12_NC
), /* type */
1178 2, /* size (0 = byte, 1 = short, 2 = long) */
1180 FALSE
, /* pc_relative */
1182 complain_overflow_dont
, /* complain_on_overflow */
1183 bfd_elf_generic_reloc
, /* special_function */
1184 AARCH64_R_STR (TLSLD_ADD_LO12_NC
), /* name */
1185 FALSE
, /* partial_inplace */
1186 0xfff, /* src_mask */
1187 0xfff, /* dst_mask */
1188 FALSE
), /* pcrel_offset */
1190 /* Get to the page for the GOT entry for the symbol
1191 (G(S) - P) using an ADRP instruction. */
1192 HOWTO (AARCH64_R (TLSLD_ADR_PAGE21
), /* type */
1193 12, /* rightshift */
1194 2, /* size (0 = byte, 1 = short, 2 = long) */
1196 TRUE
, /* pc_relative */
1198 complain_overflow_signed
, /* complain_on_overflow */
1199 bfd_elf_generic_reloc
, /* special_function */
1200 AARCH64_R_STR (TLSLD_ADR_PAGE21
), /* name */
1201 FALSE
, /* partial_inplace */
1202 0x1fffff, /* src_mask */
1203 0x1fffff, /* dst_mask */
1204 TRUE
), /* pcrel_offset */
1206 HOWTO (AARCH64_R (TLSLD_ADR_PREL21
), /* type */
1208 2, /* size (0 = byte, 1 = short, 2 = long) */
1210 TRUE
, /* pc_relative */
1212 complain_overflow_signed
, /* complain_on_overflow */
1213 bfd_elf_generic_reloc
, /* special_function */
1214 AARCH64_R_STR (TLSLD_ADR_PREL21
), /* name */
1215 FALSE
, /* partial_inplace */
1216 0x1fffff, /* src_mask */
1217 0x1fffff, /* dst_mask */
1218 TRUE
), /* pcrel_offset */
1220 /* LD/ST16: bit[11:1] of byte offset to module TLS base address. */
1221 HOWTO64 (AARCH64_R (TLSLD_LDST16_DTPREL_LO12
), /* type */
1223 2, /* size (0 = byte, 1 = short, 2 = long) */
1225 FALSE
, /* pc_relative */
1227 complain_overflow_unsigned
, /* complain_on_overflow */
1228 bfd_elf_generic_reloc
, /* special_function */
1229 AARCH64_R_STR (TLSLD_LDST16_DTPREL_LO12
), /* name */
1230 FALSE
, /* partial_inplace */
1231 0x1ffc00, /* src_mask */
1232 0x1ffc00, /* dst_mask */
1233 FALSE
), /* pcrel_offset */
1235 /* Same as BFD_RELOC_AARCH64_TLSLD_LDST16_DTPREL_LO12, but no overflow check. */
1236 HOWTO64 (AARCH64_R (TLSLD_LDST16_DTPREL_LO12_NC
), /* type */
1238 2, /* size (0 = byte, 1 = short, 2 = long) */
1240 FALSE
, /* pc_relative */
1242 complain_overflow_dont
, /* complain_on_overflow */
1243 bfd_elf_generic_reloc
, /* special_function */
1244 AARCH64_R_STR (TLSLD_LDST16_DTPREL_LO12_NC
), /* name */
1245 FALSE
, /* partial_inplace */
1246 0x1ffc00, /* src_mask */
1247 0x1ffc00, /* dst_mask */
1248 FALSE
), /* pcrel_offset */
1250 /* LD/ST32: bit[11:2] of byte offset to module TLS base address. */
1251 HOWTO64 (AARCH64_R (TLSLD_LDST32_DTPREL_LO12
), /* type */
1253 2, /* size (0 = byte, 1 = short, 2 = long) */
1255 FALSE
, /* pc_relative */
1257 complain_overflow_unsigned
, /* complain_on_overflow */
1258 bfd_elf_generic_reloc
, /* special_function */
1259 AARCH64_R_STR (TLSLD_LDST32_DTPREL_LO12
), /* name */
1260 FALSE
, /* partial_inplace */
1261 0x3ffc00, /* src_mask */
1262 0x3ffc00, /* dst_mask */
1263 FALSE
), /* pcrel_offset */
1265 /* Same as BFD_RELOC_AARCH64_TLSLD_LDST32_DTPREL_LO12, but no overflow check. */
1266 HOWTO64 (AARCH64_R (TLSLD_LDST32_DTPREL_LO12_NC
), /* type */
1268 2, /* size (0 = byte, 1 = short, 2 = long) */
1270 FALSE
, /* pc_relative */
1272 complain_overflow_dont
, /* complain_on_overflow */
1273 bfd_elf_generic_reloc
, /* special_function */
1274 AARCH64_R_STR (TLSLD_LDST32_DTPREL_LO12_NC
), /* name */
1275 FALSE
, /* partial_inplace */
1276 0xffc00, /* src_mask */
1277 0xffc00, /* dst_mask */
1278 FALSE
), /* pcrel_offset */
1280 /* LD/ST64: bit[11:3] of byte offset to module TLS base address. */
1281 HOWTO64 (AARCH64_R (TLSLD_LDST64_DTPREL_LO12
), /* type */
1283 2, /* size (0 = byte, 1 = short, 2 = long) */
1285 FALSE
, /* pc_relative */
1287 complain_overflow_unsigned
, /* complain_on_overflow */
1288 bfd_elf_generic_reloc
, /* special_function */
1289 AARCH64_R_STR (TLSLD_LDST64_DTPREL_LO12
), /* name */
1290 FALSE
, /* partial_inplace */
1291 0x3ffc00, /* src_mask */
1292 0x3ffc00, /* dst_mask */
1293 FALSE
), /* pcrel_offset */
1295 /* Same as BFD_RELOC_AARCH64_TLSLD_LDST64_DTPREL_LO12, but no overflow check. */
1296 HOWTO64 (AARCH64_R (TLSLD_LDST64_DTPREL_LO12_NC
), /* type */
1298 2, /* size (0 = byte, 1 = short, 2 = long) */
1300 FALSE
, /* pc_relative */
1302 complain_overflow_dont
, /* complain_on_overflow */
1303 bfd_elf_generic_reloc
, /* special_function */
1304 AARCH64_R_STR (TLSLD_LDST64_DTPREL_LO12_NC
), /* name */
1305 FALSE
, /* partial_inplace */
1306 0x7fc00, /* src_mask */
1307 0x7fc00, /* dst_mask */
1308 FALSE
), /* pcrel_offset */
1310 /* LD/ST8: bit[11:0] of byte offset to module TLS base address. */
1311 HOWTO64 (AARCH64_R (TLSLD_LDST8_DTPREL_LO12
), /* type */
1313 2, /* size (0 = byte, 1 = short, 2 = long) */
1315 FALSE
, /* pc_relative */
1317 complain_overflow_unsigned
, /* complain_on_overflow */
1318 bfd_elf_generic_reloc
, /* special_function */
1319 AARCH64_R_STR (TLSLD_LDST8_DTPREL_LO12
), /* name */
1320 FALSE
, /* partial_inplace */
1321 0x3ffc00, /* src_mask */
1322 0x3ffc00, /* dst_mask */
1323 FALSE
), /* pcrel_offset */
1325 /* Same as BFD_RELOC_AARCH64_TLSLD_LDST8_DTPREL_LO12, but no overflow check. */
1326 HOWTO64 (AARCH64_R (TLSLD_LDST8_DTPREL_LO12_NC
), /* type */
1328 2, /* size (0 = byte, 1 = short, 2 = long) */
1330 FALSE
, /* pc_relative */
1332 complain_overflow_dont
, /* complain_on_overflow */
1333 bfd_elf_generic_reloc
, /* special_function */
1334 AARCH64_R_STR (TLSLD_LDST8_DTPREL_LO12_NC
), /* name */
1335 FALSE
, /* partial_inplace */
1336 0x3ffc00, /* src_mask */
1337 0x3ffc00, /* dst_mask */
1338 FALSE
), /* pcrel_offset */
1340 /* MOVZ: bit[15:0] of byte offset to module TLS base address. */
1341 HOWTO (AARCH64_R (TLSLD_MOVW_DTPREL_G0
), /* type */
1343 2, /* size (0 = byte, 1 = short, 2 = long) */
1345 FALSE
, /* pc_relative */
1347 complain_overflow_unsigned
, /* complain_on_overflow */
1348 bfd_elf_generic_reloc
, /* special_function */
1349 AARCH64_R_STR (TLSLD_MOVW_DTPREL_G0
), /* name */
1350 FALSE
, /* partial_inplace */
1351 0xffff, /* src_mask */
1352 0xffff, /* dst_mask */
1353 FALSE
), /* pcrel_offset */
1355 /* No overflow check version of BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G0. */
1356 HOWTO (AARCH64_R (TLSLD_MOVW_DTPREL_G0_NC
), /* type */
1358 2, /* size (0 = byte, 1 = short, 2 = long) */
1360 FALSE
, /* pc_relative */
1362 complain_overflow_dont
, /* complain_on_overflow */
1363 bfd_elf_generic_reloc
, /* special_function */
1364 AARCH64_R_STR (TLSLD_MOVW_DTPREL_G0_NC
), /* name */
1365 FALSE
, /* partial_inplace */
1366 0xffff, /* src_mask */
1367 0xffff, /* dst_mask */
1368 FALSE
), /* pcrel_offset */
1370 /* MOVZ: bit[31:16] of byte offset to module TLS base address. */
1371 HOWTO (AARCH64_R (TLSLD_MOVW_DTPREL_G1
), /* type */
1372 16, /* rightshift */
1373 2, /* size (0 = byte, 1 = short, 2 = long) */
1375 FALSE
, /* pc_relative */
1377 complain_overflow_unsigned
, /* complain_on_overflow */
1378 bfd_elf_generic_reloc
, /* special_function */
1379 AARCH64_R_STR (TLSLD_MOVW_DTPREL_G1
), /* name */
1380 FALSE
, /* partial_inplace */
1381 0xffff, /* src_mask */
1382 0xffff, /* dst_mask */
1383 FALSE
), /* pcrel_offset */
1385 /* No overflow check version of BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G1. */
1386 HOWTO64 (AARCH64_R (TLSLD_MOVW_DTPREL_G1_NC
), /* type */
1387 16, /* rightshift */
1388 2, /* size (0 = byte, 1 = short, 2 = long) */
1390 FALSE
, /* pc_relative */
1392 complain_overflow_dont
, /* complain_on_overflow */
1393 bfd_elf_generic_reloc
, /* special_function */
1394 AARCH64_R_STR (TLSLD_MOVW_DTPREL_G1_NC
), /* name */
1395 FALSE
, /* partial_inplace */
1396 0xffff, /* src_mask */
1397 0xffff, /* dst_mask */
1398 FALSE
), /* pcrel_offset */
1400 /* MOVZ: bit[47:32] of byte offset to module TLS base address. */
1401 HOWTO64 (AARCH64_R (TLSLD_MOVW_DTPREL_G2
), /* type */
1402 32, /* rightshift */
1403 2, /* size (0 = byte, 1 = short, 2 = long) */
1405 FALSE
, /* pc_relative */
1407 complain_overflow_unsigned
, /* complain_on_overflow */
1408 bfd_elf_generic_reloc
, /* special_function */
1409 AARCH64_R_STR (TLSLD_MOVW_DTPREL_G2
), /* name */
1410 FALSE
, /* partial_inplace */
1411 0xffff, /* src_mask */
1412 0xffff, /* dst_mask */
1413 FALSE
), /* pcrel_offset */
1415 HOWTO64 (AARCH64_R (TLSLE_MOVW_TPREL_G2
), /* type */
1416 32, /* rightshift */
1417 2, /* size (0 = byte, 1 = short, 2 = long) */
1419 FALSE
, /* pc_relative */
1421 complain_overflow_unsigned
, /* complain_on_overflow */
1422 bfd_elf_generic_reloc
, /* special_function */
1423 AARCH64_R_STR (TLSLE_MOVW_TPREL_G2
), /* name */
1424 FALSE
, /* partial_inplace */
1425 0xffff, /* src_mask */
1426 0xffff, /* dst_mask */
1427 FALSE
), /* pcrel_offset */
1429 HOWTO (AARCH64_R (TLSLE_MOVW_TPREL_G1
), /* type */
1430 16, /* rightshift */
1431 2, /* size (0 = byte, 1 = short, 2 = long) */
1433 FALSE
, /* pc_relative */
1435 complain_overflow_dont
, /* complain_on_overflow */
1436 bfd_elf_generic_reloc
, /* special_function */
1437 AARCH64_R_STR (TLSLE_MOVW_TPREL_G1
), /* name */
1438 FALSE
, /* partial_inplace */
1439 0xffff, /* src_mask */
1440 0xffff, /* dst_mask */
1441 FALSE
), /* pcrel_offset */
1443 HOWTO64 (AARCH64_R (TLSLE_MOVW_TPREL_G1_NC
), /* type */
1444 16, /* rightshift */
1445 2, /* size (0 = byte, 1 = short, 2 = long) */
1447 FALSE
, /* pc_relative */
1449 complain_overflow_dont
, /* complain_on_overflow */
1450 bfd_elf_generic_reloc
, /* special_function */
1451 AARCH64_R_STR (TLSLE_MOVW_TPREL_G1_NC
), /* name */
1452 FALSE
, /* partial_inplace */
1453 0xffff, /* src_mask */
1454 0xffff, /* dst_mask */
1455 FALSE
), /* pcrel_offset */
1457 HOWTO (AARCH64_R (TLSLE_MOVW_TPREL_G0
), /* type */
1459 2, /* size (0 = byte, 1 = short, 2 = long) */
1461 FALSE
, /* pc_relative */
1463 complain_overflow_dont
, /* complain_on_overflow */
1464 bfd_elf_generic_reloc
, /* special_function */
1465 AARCH64_R_STR (TLSLE_MOVW_TPREL_G0
), /* name */
1466 FALSE
, /* partial_inplace */
1467 0xffff, /* src_mask */
1468 0xffff, /* dst_mask */
1469 FALSE
), /* pcrel_offset */
1471 HOWTO (AARCH64_R (TLSLE_MOVW_TPREL_G0_NC
), /* type */
1473 2, /* size (0 = byte, 1 = short, 2 = long) */
1475 FALSE
, /* pc_relative */
1477 complain_overflow_dont
, /* complain_on_overflow */
1478 bfd_elf_generic_reloc
, /* special_function */
1479 AARCH64_R_STR (TLSLE_MOVW_TPREL_G0_NC
), /* name */
1480 FALSE
, /* partial_inplace */
1481 0xffff, /* src_mask */
1482 0xffff, /* dst_mask */
1483 FALSE
), /* pcrel_offset */
1485 HOWTO (AARCH64_R (TLSLE_ADD_TPREL_HI12
), /* type */
1486 12, /* rightshift */
1487 2, /* size (0 = byte, 1 = short, 2 = long) */
1489 FALSE
, /* pc_relative */
1491 complain_overflow_unsigned
, /* complain_on_overflow */
1492 bfd_elf_generic_reloc
, /* special_function */
1493 AARCH64_R_STR (TLSLE_ADD_TPREL_HI12
), /* name */
1494 FALSE
, /* partial_inplace */
1495 0xfff, /* src_mask */
1496 0xfff, /* dst_mask */
1497 FALSE
), /* pcrel_offset */
1499 HOWTO (AARCH64_R (TLSLE_ADD_TPREL_LO12
), /* type */
1501 2, /* size (0 = byte, 1 = short, 2 = long) */
1503 FALSE
, /* pc_relative */
1505 complain_overflow_unsigned
, /* complain_on_overflow */
1506 bfd_elf_generic_reloc
, /* special_function */
1507 AARCH64_R_STR (TLSLE_ADD_TPREL_LO12
), /* name */
1508 FALSE
, /* partial_inplace */
1509 0xfff, /* src_mask */
1510 0xfff, /* dst_mask */
1511 FALSE
), /* pcrel_offset */
1513 HOWTO (AARCH64_R (TLSLE_ADD_TPREL_LO12_NC
), /* type */
1515 2, /* size (0 = byte, 1 = short, 2 = long) */
1517 FALSE
, /* pc_relative */
1519 complain_overflow_dont
, /* complain_on_overflow */
1520 bfd_elf_generic_reloc
, /* special_function */
1521 AARCH64_R_STR (TLSLE_ADD_TPREL_LO12_NC
), /* name */
1522 FALSE
, /* partial_inplace */
1523 0xfff, /* src_mask */
1524 0xfff, /* dst_mask */
1525 FALSE
), /* pcrel_offset */
1527 HOWTO (AARCH64_R (TLSDESC_LD_PREL19
), /* type */
1529 2, /* size (0 = byte, 1 = short, 2 = long) */
1531 TRUE
, /* pc_relative */
1533 complain_overflow_dont
, /* complain_on_overflow */
1534 bfd_elf_generic_reloc
, /* special_function */
1535 AARCH64_R_STR (TLSDESC_LD_PREL19
), /* name */
1536 FALSE
, /* partial_inplace */
1537 0x0ffffe0, /* src_mask */
1538 0x0ffffe0, /* dst_mask */
1539 TRUE
), /* pcrel_offset */
1541 HOWTO (AARCH64_R (TLSDESC_ADR_PREL21
), /* type */
1543 2, /* size (0 = byte, 1 = short, 2 = long) */
1545 TRUE
, /* pc_relative */
1547 complain_overflow_dont
, /* complain_on_overflow */
1548 bfd_elf_generic_reloc
, /* special_function */
1549 AARCH64_R_STR (TLSDESC_ADR_PREL21
), /* name */
1550 FALSE
, /* partial_inplace */
1551 0x1fffff, /* src_mask */
1552 0x1fffff, /* dst_mask */
1553 TRUE
), /* pcrel_offset */
1555 /* Get to the page for the GOT entry for the symbol
1556 (G(S) - P) using an ADRP instruction. */
1557 HOWTO (AARCH64_R (TLSDESC_ADR_PAGE21
), /* type */
1558 12, /* rightshift */
1559 2, /* size (0 = byte, 1 = short, 2 = long) */
1561 TRUE
, /* pc_relative */
1563 complain_overflow_dont
, /* complain_on_overflow */
1564 bfd_elf_generic_reloc
, /* special_function */
1565 AARCH64_R_STR (TLSDESC_ADR_PAGE21
), /* name */
1566 FALSE
, /* partial_inplace */
1567 0x1fffff, /* src_mask */
1568 0x1fffff, /* dst_mask */
1569 TRUE
), /* pcrel_offset */
1571 /* LD64: GOT offset G(S) & 0xff8. */
1572 HOWTO64 (AARCH64_R (TLSDESC_LD64_LO12_NC
), /* type */
1574 2, /* size (0 = byte, 1 = short, 2 = long) */
1576 FALSE
, /* pc_relative */
1578 complain_overflow_dont
, /* complain_on_overflow */
1579 bfd_elf_generic_reloc
, /* special_function */
1580 AARCH64_R_STR (TLSDESC_LD64_LO12_NC
), /* name */
1581 FALSE
, /* partial_inplace */
1582 0xff8, /* src_mask */
1583 0xff8, /* dst_mask */
1584 FALSE
), /* pcrel_offset */
1586 /* LD32: GOT offset G(S) & 0xffc. */
1587 HOWTO32 (AARCH64_R (TLSDESC_LD32_LO12_NC
), /* type */
1589 2, /* size (0 = byte, 1 = short, 2 = long) */
1591 FALSE
, /* pc_relative */
1593 complain_overflow_dont
, /* complain_on_overflow */
1594 bfd_elf_generic_reloc
, /* special_function */
1595 AARCH64_R_STR (TLSDESC_LD32_LO12_NC
), /* name */
1596 FALSE
, /* partial_inplace */
1597 0xffc, /* src_mask */
1598 0xffc, /* dst_mask */
1599 FALSE
), /* pcrel_offset */
1601 /* ADD: GOT offset G(S) & 0xfff. */
1602 HOWTO (AARCH64_R (TLSDESC_ADD_LO12_NC
), /* type */
1604 2, /* size (0 = byte, 1 = short, 2 = long) */
1606 FALSE
, /* pc_relative */
1608 complain_overflow_dont
, /* complain_on_overflow */
1609 bfd_elf_generic_reloc
, /* special_function */
1610 AARCH64_R_STR (TLSDESC_ADD_LO12_NC
), /* name */
1611 FALSE
, /* partial_inplace */
1612 0xfff, /* src_mask */
1613 0xfff, /* dst_mask */
1614 FALSE
), /* pcrel_offset */
1616 HOWTO64 (AARCH64_R (TLSDESC_OFF_G1
), /* type */
1617 16, /* rightshift */
1618 2, /* size (0 = byte, 1 = short, 2 = long) */
1620 FALSE
, /* pc_relative */
1622 complain_overflow_unsigned
, /* complain_on_overflow */
1623 bfd_elf_generic_reloc
, /* special_function */
1624 AARCH64_R_STR (TLSDESC_OFF_G1
), /* name */
1625 FALSE
, /* partial_inplace */
1626 0xffff, /* src_mask */
1627 0xffff, /* dst_mask */
1628 FALSE
), /* pcrel_offset */
1630 HOWTO64 (AARCH64_R (TLSDESC_OFF_G0_NC
), /* type */
1632 2, /* size (0 = byte, 1 = short, 2 = long) */
1634 FALSE
, /* pc_relative */
1636 complain_overflow_dont
, /* complain_on_overflow */
1637 bfd_elf_generic_reloc
, /* special_function */
1638 AARCH64_R_STR (TLSDESC_OFF_G0_NC
), /* name */
1639 FALSE
, /* partial_inplace */
1640 0xffff, /* src_mask */
1641 0xffff, /* dst_mask */
1642 FALSE
), /* pcrel_offset */
1644 HOWTO64 (AARCH64_R (TLSDESC_LDR
), /* type */
1646 2, /* size (0 = byte, 1 = short, 2 = long) */
1648 FALSE
, /* pc_relative */
1650 complain_overflow_dont
, /* complain_on_overflow */
1651 bfd_elf_generic_reloc
, /* special_function */
1652 AARCH64_R_STR (TLSDESC_LDR
), /* name */
1653 FALSE
, /* partial_inplace */
1656 FALSE
), /* pcrel_offset */
1658 HOWTO64 (AARCH64_R (TLSDESC_ADD
), /* type */
1660 2, /* size (0 = byte, 1 = short, 2 = long) */
1662 FALSE
, /* pc_relative */
1664 complain_overflow_dont
, /* complain_on_overflow */
1665 bfd_elf_generic_reloc
, /* special_function */
1666 AARCH64_R_STR (TLSDESC_ADD
), /* name */
1667 FALSE
, /* partial_inplace */
1670 FALSE
), /* pcrel_offset */
1672 HOWTO (AARCH64_R (TLSDESC_CALL
), /* type */
1674 2, /* size (0 = byte, 1 = short, 2 = long) */
1676 FALSE
, /* pc_relative */
1678 complain_overflow_dont
, /* complain_on_overflow */
1679 bfd_elf_generic_reloc
, /* special_function */
1680 AARCH64_R_STR (TLSDESC_CALL
), /* name */
1681 FALSE
, /* partial_inplace */
1684 FALSE
), /* pcrel_offset */
1686 HOWTO (AARCH64_R (COPY
), /* type */
1688 2, /* size (0 = byte, 1 = short, 2 = long) */
1690 FALSE
, /* pc_relative */
1692 complain_overflow_bitfield
, /* complain_on_overflow */
1693 bfd_elf_generic_reloc
, /* special_function */
1694 AARCH64_R_STR (COPY
), /* name */
1695 TRUE
, /* partial_inplace */
1696 0xffffffff, /* src_mask */
1697 0xffffffff, /* dst_mask */
1698 FALSE
), /* pcrel_offset */
1700 HOWTO (AARCH64_R (GLOB_DAT
), /* type */
1702 2, /* size (0 = byte, 1 = short, 2 = long) */
1704 FALSE
, /* pc_relative */
1706 complain_overflow_bitfield
, /* complain_on_overflow */
1707 bfd_elf_generic_reloc
, /* special_function */
1708 AARCH64_R_STR (GLOB_DAT
), /* name */
1709 TRUE
, /* partial_inplace */
1710 0xffffffff, /* src_mask */
1711 0xffffffff, /* dst_mask */
1712 FALSE
), /* pcrel_offset */
1714 HOWTO (AARCH64_R (JUMP_SLOT
), /* type */
1716 2, /* size (0 = byte, 1 = short, 2 = long) */
1718 FALSE
, /* pc_relative */
1720 complain_overflow_bitfield
, /* complain_on_overflow */
1721 bfd_elf_generic_reloc
, /* special_function */
1722 AARCH64_R_STR (JUMP_SLOT
), /* name */
1723 TRUE
, /* partial_inplace */
1724 0xffffffff, /* src_mask */
1725 0xffffffff, /* dst_mask */
1726 FALSE
), /* pcrel_offset */
1728 HOWTO (AARCH64_R (RELATIVE
), /* type */
1730 2, /* size (0 = byte, 1 = short, 2 = long) */
1732 FALSE
, /* pc_relative */
1734 complain_overflow_bitfield
, /* complain_on_overflow */
1735 bfd_elf_generic_reloc
, /* special_function */
1736 AARCH64_R_STR (RELATIVE
), /* name */
1737 TRUE
, /* partial_inplace */
1738 ALL_ONES
, /* src_mask */
1739 ALL_ONES
, /* dst_mask */
1740 FALSE
), /* pcrel_offset */
1742 HOWTO (AARCH64_R (TLS_DTPMOD
), /* type */
1744 2, /* size (0 = byte, 1 = short, 2 = long) */
1746 FALSE
, /* pc_relative */
1748 complain_overflow_dont
, /* complain_on_overflow */
1749 bfd_elf_generic_reloc
, /* special_function */
1751 AARCH64_R_STR (TLS_DTPMOD64
), /* name */
1753 AARCH64_R_STR (TLS_DTPMOD
), /* name */
1755 FALSE
, /* partial_inplace */
1757 ALL_ONES
, /* dst_mask */
1758 FALSE
), /* pc_reloffset */
1760 HOWTO (AARCH64_R (TLS_DTPREL
), /* type */
1762 2, /* size (0 = byte, 1 = short, 2 = long) */
1764 FALSE
, /* pc_relative */
1766 complain_overflow_dont
, /* complain_on_overflow */
1767 bfd_elf_generic_reloc
, /* special_function */
1769 AARCH64_R_STR (TLS_DTPREL64
), /* name */
1771 AARCH64_R_STR (TLS_DTPREL
), /* name */
1773 FALSE
, /* partial_inplace */
1775 ALL_ONES
, /* dst_mask */
1776 FALSE
), /* pcrel_offset */
1778 HOWTO (AARCH64_R (TLS_TPREL
), /* type */
1780 2, /* size (0 = byte, 1 = short, 2 = long) */
1782 FALSE
, /* pc_relative */
1784 complain_overflow_dont
, /* complain_on_overflow */
1785 bfd_elf_generic_reloc
, /* special_function */
1787 AARCH64_R_STR (TLS_TPREL64
), /* name */
1789 AARCH64_R_STR (TLS_TPREL
), /* name */
1791 FALSE
, /* partial_inplace */
1793 ALL_ONES
, /* dst_mask */
1794 FALSE
), /* pcrel_offset */
1796 HOWTO (AARCH64_R (TLSDESC
), /* type */
1798 2, /* size (0 = byte, 1 = short, 2 = long) */
1800 FALSE
, /* pc_relative */
1802 complain_overflow_dont
, /* complain_on_overflow */
1803 bfd_elf_generic_reloc
, /* special_function */
1804 AARCH64_R_STR (TLSDESC
), /* name */
1805 FALSE
, /* partial_inplace */
1807 ALL_ONES
, /* dst_mask */
1808 FALSE
), /* pcrel_offset */
1810 HOWTO (AARCH64_R (IRELATIVE
), /* type */
1812 2, /* size (0 = byte, 1 = short, 2 = long) */
1814 FALSE
, /* pc_relative */
1816 complain_overflow_bitfield
, /* complain_on_overflow */
1817 bfd_elf_generic_reloc
, /* special_function */
1818 AARCH64_R_STR (IRELATIVE
), /* name */
1819 FALSE
, /* partial_inplace */
1821 ALL_ONES
, /* dst_mask */
1822 FALSE
), /* pcrel_offset */
1827 static reloc_howto_type elfNN_aarch64_howto_none
=
1828 HOWTO (R_AARCH64_NONE
, /* type */
1830 3, /* size (0 = byte, 1 = short, 2 = long) */
1832 FALSE
, /* pc_relative */
1834 complain_overflow_dont
,/* complain_on_overflow */
1835 bfd_elf_generic_reloc
, /* special_function */
1836 "R_AARCH64_NONE", /* name */
1837 FALSE
, /* partial_inplace */
1840 FALSE
); /* pcrel_offset */
1842 /* Given HOWTO, return the bfd internal relocation enumerator. */
1844 static bfd_reloc_code_real_type
1845 elfNN_aarch64_bfd_reloc_from_howto (reloc_howto_type
*howto
)
1848 = (int) ARRAY_SIZE (elfNN_aarch64_howto_table
);
1849 const ptrdiff_t offset
1850 = howto
- elfNN_aarch64_howto_table
;
1852 if (offset
> 0 && offset
< size
- 1)
1853 return BFD_RELOC_AARCH64_RELOC_START
+ offset
;
1855 if (howto
== &elfNN_aarch64_howto_none
)
1856 return BFD_RELOC_AARCH64_NONE
;
1858 return BFD_RELOC_AARCH64_RELOC_START
;
1861 /* Given R_TYPE, return the bfd internal relocation enumerator. */
1863 static bfd_reloc_code_real_type
1864 elfNN_aarch64_bfd_reloc_from_type (unsigned int r_type
)
1866 static bfd_boolean initialized_p
= FALSE
;
1867 /* Indexed by R_TYPE, values are offsets in the howto_table. */
1868 static unsigned int offsets
[R_AARCH64_end
];
1870 if (initialized_p
== FALSE
)
1874 for (i
= 1; i
< ARRAY_SIZE (elfNN_aarch64_howto_table
) - 1; ++i
)
1875 if (elfNN_aarch64_howto_table
[i
].type
!= 0)
1876 offsets
[elfNN_aarch64_howto_table
[i
].type
] = i
;
1878 initialized_p
= TRUE
;
1881 if (r_type
== R_AARCH64_NONE
|| r_type
== R_AARCH64_NULL
)
1882 return BFD_RELOC_AARCH64_NONE
;
1884 /* PR 17512: file: b371e70a. */
1885 if (r_type
>= R_AARCH64_end
)
1887 _bfd_error_handler (_("Invalid AArch64 reloc number: %d"), r_type
);
1888 bfd_set_error (bfd_error_bad_value
);
1889 return BFD_RELOC_AARCH64_NONE
;
1892 return BFD_RELOC_AARCH64_RELOC_START
+ offsets
[r_type
];
1895 struct elf_aarch64_reloc_map
1897 bfd_reloc_code_real_type from
;
1898 bfd_reloc_code_real_type to
;
1901 /* Map bfd generic reloc to AArch64-specific reloc. */
1902 static const struct elf_aarch64_reloc_map elf_aarch64_reloc_map
[] =
1904 {BFD_RELOC_NONE
, BFD_RELOC_AARCH64_NONE
},
1906 /* Basic data relocations. */
1907 {BFD_RELOC_CTOR
, BFD_RELOC_AARCH64_NN
},
1908 {BFD_RELOC_64
, BFD_RELOC_AARCH64_64
},
1909 {BFD_RELOC_32
, BFD_RELOC_AARCH64_32
},
1910 {BFD_RELOC_16
, BFD_RELOC_AARCH64_16
},
1911 {BFD_RELOC_64_PCREL
, BFD_RELOC_AARCH64_64_PCREL
},
1912 {BFD_RELOC_32_PCREL
, BFD_RELOC_AARCH64_32_PCREL
},
1913 {BFD_RELOC_16_PCREL
, BFD_RELOC_AARCH64_16_PCREL
},
1916 /* Given the bfd internal relocation enumerator in CODE, return the
1917 corresponding howto entry. */
1919 static reloc_howto_type
*
1920 elfNN_aarch64_howto_from_bfd_reloc (bfd_reloc_code_real_type code
)
1924 /* Convert bfd generic reloc to AArch64-specific reloc. */
1925 if (code
< BFD_RELOC_AARCH64_RELOC_START
1926 || code
> BFD_RELOC_AARCH64_RELOC_END
)
1927 for (i
= 0; i
< ARRAY_SIZE (elf_aarch64_reloc_map
); i
++)
1928 if (elf_aarch64_reloc_map
[i
].from
== code
)
1930 code
= elf_aarch64_reloc_map
[i
].to
;
1934 if (code
> BFD_RELOC_AARCH64_RELOC_START
1935 && code
< BFD_RELOC_AARCH64_RELOC_END
)
1936 if (elfNN_aarch64_howto_table
[code
- BFD_RELOC_AARCH64_RELOC_START
].type
)
1937 return &elfNN_aarch64_howto_table
[code
- BFD_RELOC_AARCH64_RELOC_START
];
1939 if (code
== BFD_RELOC_AARCH64_NONE
)
1940 return &elfNN_aarch64_howto_none
;
1945 static reloc_howto_type
*
1946 elfNN_aarch64_howto_from_type (unsigned int r_type
)
1948 bfd_reloc_code_real_type val
;
1949 reloc_howto_type
*howto
;
1954 bfd_set_error (bfd_error_bad_value
);
1959 if (r_type
== R_AARCH64_NONE
)
1960 return &elfNN_aarch64_howto_none
;
1962 val
= elfNN_aarch64_bfd_reloc_from_type (r_type
);
1963 howto
= elfNN_aarch64_howto_from_bfd_reloc (val
);
1968 bfd_set_error (bfd_error_bad_value
);
1973 elfNN_aarch64_info_to_howto (bfd
*abfd ATTRIBUTE_UNUSED
, arelent
*bfd_reloc
,
1974 Elf_Internal_Rela
*elf_reloc
)
1976 unsigned int r_type
;
1978 r_type
= ELFNN_R_TYPE (elf_reloc
->r_info
);
1979 bfd_reloc
->howto
= elfNN_aarch64_howto_from_type (r_type
);
1982 static reloc_howto_type
*
1983 elfNN_aarch64_reloc_type_lookup (bfd
*abfd ATTRIBUTE_UNUSED
,
1984 bfd_reloc_code_real_type code
)
1986 reloc_howto_type
*howto
= elfNN_aarch64_howto_from_bfd_reloc (code
);
1991 bfd_set_error (bfd_error_bad_value
);
1995 static reloc_howto_type
*
1996 elfNN_aarch64_reloc_name_lookup (bfd
*abfd ATTRIBUTE_UNUSED
,
2001 for (i
= 1; i
< ARRAY_SIZE (elfNN_aarch64_howto_table
) - 1; ++i
)
2002 if (elfNN_aarch64_howto_table
[i
].name
!= NULL
2003 && strcasecmp (elfNN_aarch64_howto_table
[i
].name
, r_name
) == 0)
2004 return &elfNN_aarch64_howto_table
[i
];
2009 #define TARGET_LITTLE_SYM aarch64_elfNN_le_vec
2010 #define TARGET_LITTLE_NAME "elfNN-littleaarch64"
2011 #define TARGET_BIG_SYM aarch64_elfNN_be_vec
2012 #define TARGET_BIG_NAME "elfNN-bigaarch64"
2014 /* The linker script knows the section names for placement.
2015 The entry_names are used to do simple name mangling on the stubs.
2016 Given a function name, and its type, the stub can be found. The
2017 name can be changed. The only requirement is the %s be present. */
2018 #define STUB_ENTRY_NAME "__%s_veneer"
2020 /* The name of the dynamic interpreter. This is put in the .interp
2022 #define ELF_DYNAMIC_INTERPRETER "/lib/ld.so.1"
2024 #define AARCH64_MAX_FWD_BRANCH_OFFSET \
2025 (((1 << 25) - 1) << 2)
2026 #define AARCH64_MAX_BWD_BRANCH_OFFSET \
2029 #define AARCH64_MAX_ADRP_IMM ((1 << 20) - 1)
2030 #define AARCH64_MIN_ADRP_IMM (-(1 << 20))
2033 aarch64_valid_for_adrp_p (bfd_vma value
, bfd_vma place
)
2035 bfd_signed_vma offset
= (bfd_signed_vma
) (PG (value
) - PG (place
)) >> 12;
2036 return offset
<= AARCH64_MAX_ADRP_IMM
&& offset
>= AARCH64_MIN_ADRP_IMM
;
2040 aarch64_valid_branch_p (bfd_vma value
, bfd_vma place
)
2042 bfd_signed_vma offset
= (bfd_signed_vma
) (value
- place
);
2043 return (offset
<= AARCH64_MAX_FWD_BRANCH_OFFSET
2044 && offset
>= AARCH64_MAX_BWD_BRANCH_OFFSET
);
2047 static const uint32_t aarch64_adrp_branch_stub
[] =
2049 0x90000010, /* adrp ip0, X */
2050 /* R_AARCH64_ADR_HI21_PCREL(X) */
2051 0x91000210, /* add ip0, ip0, :lo12:X */
2052 /* R_AARCH64_ADD_ABS_LO12_NC(X) */
2053 0xd61f0200, /* br ip0 */
2056 static const uint32_t aarch64_long_branch_stub
[] =
2059 0x58000090, /* ldr ip0, 1f */
2061 0x18000090, /* ldr wip0, 1f */
2063 0x10000011, /* adr ip1, #0 */
2064 0x8b110210, /* add ip0, ip0, ip1 */
2065 0xd61f0200, /* br ip0 */
2066 0x00000000, /* 1: .xword or .word
2067 R_AARCH64_PRELNN(X) + 12
2072 static const uint32_t aarch64_erratum_835769_stub
[] =
2074 0x00000000, /* Placeholder for multiply accumulate. */
2075 0x14000000, /* b <label> */
2078 static const uint32_t aarch64_erratum_843419_stub
[] =
2080 0x00000000, /* Placeholder for LDR instruction. */
2081 0x14000000, /* b <label> */
2084 /* Section name for stubs is the associated section name plus this
2086 #define STUB_SUFFIX ".stub"
2088 enum elf_aarch64_stub_type
2091 aarch64_stub_adrp_branch
,
2092 aarch64_stub_long_branch
,
2093 aarch64_stub_erratum_835769_veneer
,
2094 aarch64_stub_erratum_843419_veneer
,
2097 struct elf_aarch64_stub_hash_entry
2099 /* Base hash table entry structure. */
2100 struct bfd_hash_entry root
;
2102 /* The stub section. */
2105 /* Offset within stub_sec of the beginning of this stub. */
2106 bfd_vma stub_offset
;
2108 /* Given the symbol's value and its section we can determine its final
2109 value when building the stubs (so the stub knows where to jump). */
2110 bfd_vma target_value
;
2111 asection
*target_section
;
2113 enum elf_aarch64_stub_type stub_type
;
2115 /* The symbol table entry, if any, that this was derived from. */
2116 struct elf_aarch64_link_hash_entry
*h
;
2118 /* Destination symbol type */
2119 unsigned char st_type
;
2121 /* Where this stub is being called from, or, in the case of combined
2122 stub sections, the first input section in the group. */
2125 /* The name for the local symbol at the start of this stub. The
2126 stub name in the hash table has to be unique; this does not, so
2127 it can be friendlier. */
2130 /* The instruction which caused this stub to be generated (only valid for
2131 erratum 835769 workaround stubs at present). */
2132 uint32_t veneered_insn
;
2134 /* In an erratum 843419 workaround stub, the ADRP instruction offset. */
2135 bfd_vma adrp_offset
;
2138 /* Used to build a map of a section. This is required for mixed-endian
2141 typedef struct elf_elf_section_map
2146 elf_aarch64_section_map
;
2149 typedef struct _aarch64_elf_section_data
2151 struct bfd_elf_section_data elf
;
2152 unsigned int mapcount
;
2153 unsigned int mapsize
;
2154 elf_aarch64_section_map
*map
;
2156 _aarch64_elf_section_data
;
2158 #define elf_aarch64_section_data(sec) \
2159 ((_aarch64_elf_section_data *) elf_section_data (sec))
2161 /* The size of the thread control block which is defined to be two pointers. */
2162 #define TCB_SIZE (ARCH_SIZE/8)*2
2164 struct elf_aarch64_local_symbol
2166 unsigned int got_type
;
2167 bfd_signed_vma got_refcount
;
2170 /* Offset of the GOTPLT entry reserved for the TLS descriptor. The
2171 offset is from the end of the jump table and reserved entries
2174 The magic value (bfd_vma) -1 indicates that an offset has not be
2176 bfd_vma tlsdesc_got_jump_table_offset
;
2179 struct elf_aarch64_obj_tdata
2181 struct elf_obj_tdata root
;
2183 /* local symbol descriptors */
2184 struct elf_aarch64_local_symbol
*locals
;
2186 /* Zero to warn when linking objects with incompatible enum sizes. */
2187 int no_enum_size_warning
;
2189 /* Zero to warn when linking objects with incompatible wchar_t sizes. */
2190 int no_wchar_size_warning
;
2193 #define elf_aarch64_tdata(bfd) \
2194 ((struct elf_aarch64_obj_tdata *) (bfd)->tdata.any)
2196 #define elf_aarch64_locals(bfd) (elf_aarch64_tdata (bfd)->locals)
2198 #define is_aarch64_elf(bfd) \
2199 (bfd_get_flavour (bfd) == bfd_target_elf_flavour \
2200 && elf_tdata (bfd) != NULL \
2201 && elf_object_id (bfd) == AARCH64_ELF_DATA)
2204 elfNN_aarch64_mkobject (bfd
*abfd
)
2206 return bfd_elf_allocate_object (abfd
, sizeof (struct elf_aarch64_obj_tdata
),
2210 #define elf_aarch64_hash_entry(ent) \
2211 ((struct elf_aarch64_link_hash_entry *)(ent))
2213 #define GOT_UNKNOWN 0
2214 #define GOT_NORMAL 1
2215 #define GOT_TLS_GD 2
2216 #define GOT_TLS_IE 4
2217 #define GOT_TLSDESC_GD 8
2219 #define GOT_TLS_GD_ANY_P(type) ((type & GOT_TLS_GD) || (type & GOT_TLSDESC_GD))
2221 /* AArch64 ELF linker hash entry. */
2222 struct elf_aarch64_link_hash_entry
2224 struct elf_link_hash_entry root
;
2226 /* Track dynamic relocs copied for this symbol. */
2227 struct elf_dyn_relocs
*dyn_relocs
;
2229 /* Since PLT entries have variable size, we need to record the
2230 index into .got.plt instead of recomputing it from the PLT
2232 bfd_signed_vma plt_got_offset
;
2234 /* Bit mask representing the type of GOT entry(s) if any required by
2236 unsigned int got_type
;
2238 /* A pointer to the most recently used stub hash entry against this
2240 struct elf_aarch64_stub_hash_entry
*stub_cache
;
2242 /* Offset of the GOTPLT entry reserved for the TLS descriptor. The offset
2243 is from the end of the jump table and reserved entries within the PLTGOT.
2245 The magic value (bfd_vma) -1 indicates that an offset has not
2247 bfd_vma tlsdesc_got_jump_table_offset
;
2251 elfNN_aarch64_symbol_got_type (struct elf_link_hash_entry
*h
,
2253 unsigned long r_symndx
)
2256 return elf_aarch64_hash_entry (h
)->got_type
;
2258 if (! elf_aarch64_locals (abfd
))
2261 return elf_aarch64_locals (abfd
)[r_symndx
].got_type
;
2264 /* Get the AArch64 elf linker hash table from a link_info structure. */
2265 #define elf_aarch64_hash_table(info) \
2266 ((struct elf_aarch64_link_hash_table *) ((info)->hash))
2268 #define aarch64_stub_hash_lookup(table, string, create, copy) \
2269 ((struct elf_aarch64_stub_hash_entry *) \
2270 bfd_hash_lookup ((table), (string), (create), (copy)))
2272 /* AArch64 ELF linker hash table. */
2273 struct elf_aarch64_link_hash_table
2275 /* The main hash table. */
2276 struct elf_link_hash_table root
;
2278 /* Nonzero to force PIC branch veneers. */
2281 /* Fix erratum 835769. */
2282 int fix_erratum_835769
;
2284 /* Fix erratum 843419. */
2285 int fix_erratum_843419
;
2287 /* Enable ADRP->ADR rewrite for erratum 843419 workaround. */
2288 int fix_erratum_843419_adr
;
2290 /* Don't apply link-time values for dynamic relocations. */
2291 int no_apply_dynamic_relocs
;
2293 /* The number of bytes in the initial entry in the PLT. */
2294 bfd_size_type plt_header_size
;
2296 /* The number of bytes in the subsequent PLT etries. */
2297 bfd_size_type plt_entry_size
;
2299 /* Small local sym cache. */
2300 struct sym_cache sym_cache
;
2302 /* For convenience in allocate_dynrelocs. */
2305 /* The amount of space used by the reserved portion of the sgotplt
2306 section, plus whatever space is used by the jump slots. */
2307 bfd_vma sgotplt_jump_table_size
;
2309 /* The stub hash table. */
2310 struct bfd_hash_table stub_hash_table
;
2312 /* Linker stub bfd. */
2315 /* Linker call-backs. */
2316 asection
*(*add_stub_section
) (const char *, asection
*);
2317 void (*layout_sections_again
) (void);
2319 /* Array to keep track of which stub sections have been created, and
2320 information on stub grouping. */
2323 /* This is the section to which stubs in the group will be
2326 /* The stub section. */
2330 /* Assorted information used by elfNN_aarch64_size_stubs. */
2331 unsigned int bfd_count
;
2332 unsigned int top_index
;
2333 asection
**input_list
;
2335 /* The offset into splt of the PLT entry for the TLS descriptor
2336 resolver. Special values are 0, if not necessary (or not found
2337 to be necessary yet), and -1 if needed but not determined
2339 bfd_vma tlsdesc_plt
;
2341 /* The GOT offset for the lazy trampoline. Communicated to the
2342 loader via DT_TLSDESC_GOT. The magic value (bfd_vma) -1
2343 indicates an offset is not allocated. */
2344 bfd_vma dt_tlsdesc_got
;
2346 /* Used by local STT_GNU_IFUNC symbols. */
2347 htab_t loc_hash_table
;
2348 void * loc_hash_memory
;
2351 /* Create an entry in an AArch64 ELF linker hash table. */
2353 static struct bfd_hash_entry
*
2354 elfNN_aarch64_link_hash_newfunc (struct bfd_hash_entry
*entry
,
2355 struct bfd_hash_table
*table
,
2358 struct elf_aarch64_link_hash_entry
*ret
=
2359 (struct elf_aarch64_link_hash_entry
*) entry
;
2361 /* Allocate the structure if it has not already been allocated by a
2364 ret
= bfd_hash_allocate (table
,
2365 sizeof (struct elf_aarch64_link_hash_entry
));
2367 return (struct bfd_hash_entry
*) ret
;
2369 /* Call the allocation method of the superclass. */
2370 ret
= ((struct elf_aarch64_link_hash_entry
*)
2371 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry
*) ret
,
2375 ret
->dyn_relocs
= NULL
;
2376 ret
->got_type
= GOT_UNKNOWN
;
2377 ret
->plt_got_offset
= (bfd_vma
) - 1;
2378 ret
->stub_cache
= NULL
;
2379 ret
->tlsdesc_got_jump_table_offset
= (bfd_vma
) - 1;
2382 return (struct bfd_hash_entry
*) ret
;
2385 /* Initialize an entry in the stub hash table. */
2387 static struct bfd_hash_entry
*
2388 stub_hash_newfunc (struct bfd_hash_entry
*entry
,
2389 struct bfd_hash_table
*table
, const char *string
)
2391 /* Allocate the structure if it has not already been allocated by a
2395 entry
= bfd_hash_allocate (table
,
2397 elf_aarch64_stub_hash_entry
));
2402 /* Call the allocation method of the superclass. */
2403 entry
= bfd_hash_newfunc (entry
, table
, string
);
2406 struct elf_aarch64_stub_hash_entry
*eh
;
2408 /* Initialize the local fields. */
2409 eh
= (struct elf_aarch64_stub_hash_entry
*) entry
;
2410 eh
->adrp_offset
= 0;
2411 eh
->stub_sec
= NULL
;
2412 eh
->stub_offset
= 0;
2413 eh
->target_value
= 0;
2414 eh
->target_section
= NULL
;
2415 eh
->stub_type
= aarch64_stub_none
;
2423 /* Compute a hash of a local hash entry. We use elf_link_hash_entry
2424 for local symbol so that we can handle local STT_GNU_IFUNC symbols
2425 as global symbol. We reuse indx and dynstr_index for local symbol
2426 hash since they aren't used by global symbols in this backend. */
2429 elfNN_aarch64_local_htab_hash (const void *ptr
)
2431 struct elf_link_hash_entry
*h
2432 = (struct elf_link_hash_entry
*) ptr
;
2433 return ELF_LOCAL_SYMBOL_HASH (h
->indx
, h
->dynstr_index
);
2436 /* Compare local hash entries. */
2439 elfNN_aarch64_local_htab_eq (const void *ptr1
, const void *ptr2
)
2441 struct elf_link_hash_entry
*h1
2442 = (struct elf_link_hash_entry
*) ptr1
;
2443 struct elf_link_hash_entry
*h2
2444 = (struct elf_link_hash_entry
*) ptr2
;
2446 return h1
->indx
== h2
->indx
&& h1
->dynstr_index
== h2
->dynstr_index
;
2449 /* Find and/or create a hash entry for local symbol. */
2451 static struct elf_link_hash_entry
*
2452 elfNN_aarch64_get_local_sym_hash (struct elf_aarch64_link_hash_table
*htab
,
2453 bfd
*abfd
, const Elf_Internal_Rela
*rel
,
2456 struct elf_aarch64_link_hash_entry e
, *ret
;
2457 asection
*sec
= abfd
->sections
;
2458 hashval_t h
= ELF_LOCAL_SYMBOL_HASH (sec
->id
,
2459 ELFNN_R_SYM (rel
->r_info
));
2462 e
.root
.indx
= sec
->id
;
2463 e
.root
.dynstr_index
= ELFNN_R_SYM (rel
->r_info
);
2464 slot
= htab_find_slot_with_hash (htab
->loc_hash_table
, &e
, h
,
2465 create
? INSERT
: NO_INSERT
);
2472 ret
= (struct elf_aarch64_link_hash_entry
*) *slot
;
2476 ret
= (struct elf_aarch64_link_hash_entry
*)
2477 objalloc_alloc ((struct objalloc
*) htab
->loc_hash_memory
,
2478 sizeof (struct elf_aarch64_link_hash_entry
));
2481 memset (ret
, 0, sizeof (*ret
));
2482 ret
->root
.indx
= sec
->id
;
2483 ret
->root
.dynstr_index
= ELFNN_R_SYM (rel
->r_info
);
2484 ret
->root
.dynindx
= -1;
2490 /* Copy the extra info we tack onto an elf_link_hash_entry. */
2493 elfNN_aarch64_copy_indirect_symbol (struct bfd_link_info
*info
,
2494 struct elf_link_hash_entry
*dir
,
2495 struct elf_link_hash_entry
*ind
)
2497 struct elf_aarch64_link_hash_entry
*edir
, *eind
;
2499 edir
= (struct elf_aarch64_link_hash_entry
*) dir
;
2500 eind
= (struct elf_aarch64_link_hash_entry
*) ind
;
2502 if (eind
->dyn_relocs
!= NULL
)
2504 if (edir
->dyn_relocs
!= NULL
)
2506 struct elf_dyn_relocs
**pp
;
2507 struct elf_dyn_relocs
*p
;
2509 /* Add reloc counts against the indirect sym to the direct sym
2510 list. Merge any entries against the same section. */
2511 for (pp
= &eind
->dyn_relocs
; (p
= *pp
) != NULL
;)
2513 struct elf_dyn_relocs
*q
;
2515 for (q
= edir
->dyn_relocs
; q
!= NULL
; q
= q
->next
)
2516 if (q
->sec
== p
->sec
)
2518 q
->pc_count
+= p
->pc_count
;
2519 q
->count
+= p
->count
;
2526 *pp
= edir
->dyn_relocs
;
2529 edir
->dyn_relocs
= eind
->dyn_relocs
;
2530 eind
->dyn_relocs
= NULL
;
2533 if (ind
->root
.type
== bfd_link_hash_indirect
)
2535 /* Copy over PLT info. */
2536 if (dir
->got
.refcount
<= 0)
2538 edir
->got_type
= eind
->got_type
;
2539 eind
->got_type
= GOT_UNKNOWN
;
2543 _bfd_elf_link_hash_copy_indirect (info
, dir
, ind
);
2546 /* Destroy an AArch64 elf linker hash table. */
2549 elfNN_aarch64_link_hash_table_free (bfd
*obfd
)
2551 struct elf_aarch64_link_hash_table
*ret
2552 = (struct elf_aarch64_link_hash_table
*) obfd
->link
.hash
;
2554 if (ret
->loc_hash_table
)
2555 htab_delete (ret
->loc_hash_table
);
2556 if (ret
->loc_hash_memory
)
2557 objalloc_free ((struct objalloc
*) ret
->loc_hash_memory
);
2559 bfd_hash_table_free (&ret
->stub_hash_table
);
2560 _bfd_elf_link_hash_table_free (obfd
);
2563 /* Create an AArch64 elf linker hash table. */
2565 static struct bfd_link_hash_table
*
2566 elfNN_aarch64_link_hash_table_create (bfd
*abfd
)
2568 struct elf_aarch64_link_hash_table
*ret
;
2569 bfd_size_type amt
= sizeof (struct elf_aarch64_link_hash_table
);
2571 ret
= bfd_zmalloc (amt
);
2575 if (!_bfd_elf_link_hash_table_init
2576 (&ret
->root
, abfd
, elfNN_aarch64_link_hash_newfunc
,
2577 sizeof (struct elf_aarch64_link_hash_entry
), AARCH64_ELF_DATA
))
2583 ret
->plt_header_size
= PLT_ENTRY_SIZE
;
2584 ret
->plt_entry_size
= PLT_SMALL_ENTRY_SIZE
;
2586 ret
->dt_tlsdesc_got
= (bfd_vma
) - 1;
2588 if (!bfd_hash_table_init (&ret
->stub_hash_table
, stub_hash_newfunc
,
2589 sizeof (struct elf_aarch64_stub_hash_entry
)))
2591 _bfd_elf_link_hash_table_free (abfd
);
2595 ret
->loc_hash_table
= htab_try_create (1024,
2596 elfNN_aarch64_local_htab_hash
,
2597 elfNN_aarch64_local_htab_eq
,
2599 ret
->loc_hash_memory
= objalloc_create ();
2600 if (!ret
->loc_hash_table
|| !ret
->loc_hash_memory
)
2602 elfNN_aarch64_link_hash_table_free (abfd
);
2605 ret
->root
.root
.hash_table_free
= elfNN_aarch64_link_hash_table_free
;
2607 return &ret
->root
.root
;
2611 aarch64_relocate (unsigned int r_type
, bfd
*input_bfd
, asection
*input_section
,
2612 bfd_vma offset
, bfd_vma value
)
2614 reloc_howto_type
*howto
;
2617 howto
= elfNN_aarch64_howto_from_type (r_type
);
2618 place
= (input_section
->output_section
->vma
+ input_section
->output_offset
2621 r_type
= elfNN_aarch64_bfd_reloc_from_type (r_type
);
2622 value
= _bfd_aarch64_elf_resolve_relocation (r_type
, place
, value
, 0, FALSE
);
2623 return _bfd_aarch64_elf_put_addend (input_bfd
,
2624 input_section
->contents
+ offset
, r_type
,
2628 static enum elf_aarch64_stub_type
2629 aarch64_select_branch_stub (bfd_vma value
, bfd_vma place
)
2631 if (aarch64_valid_for_adrp_p (value
, place
))
2632 return aarch64_stub_adrp_branch
;
2633 return aarch64_stub_long_branch
;
2636 /* Determine the type of stub needed, if any, for a call. */
2638 static enum elf_aarch64_stub_type
2639 aarch64_type_of_stub (asection
*input_sec
,
2640 const Elf_Internal_Rela
*rel
,
2642 unsigned char st_type
,
2643 bfd_vma destination
)
2646 bfd_signed_vma branch_offset
;
2647 unsigned int r_type
;
2648 enum elf_aarch64_stub_type stub_type
= aarch64_stub_none
;
2650 if (st_type
!= STT_FUNC
2651 && (sym_sec
== input_sec
))
2654 /* Determine where the call point is. */
2655 location
= (input_sec
->output_offset
2656 + input_sec
->output_section
->vma
+ rel
->r_offset
);
2658 branch_offset
= (bfd_signed_vma
) (destination
- location
);
2660 r_type
= ELFNN_R_TYPE (rel
->r_info
);
2662 /* We don't want to redirect any old unconditional jump in this way,
2663 only one which is being used for a sibcall, where it is
2664 acceptable for the IP0 and IP1 registers to be clobbered. */
2665 if ((r_type
== AARCH64_R (CALL26
) || r_type
== AARCH64_R (JUMP26
))
2666 && (branch_offset
> AARCH64_MAX_FWD_BRANCH_OFFSET
2667 || branch_offset
< AARCH64_MAX_BWD_BRANCH_OFFSET
))
2669 stub_type
= aarch64_stub_long_branch
;
2675 /* Build a name for an entry in the stub hash table. */
2678 elfNN_aarch64_stub_name (const asection
*input_section
,
2679 const asection
*sym_sec
,
2680 const struct elf_aarch64_link_hash_entry
*hash
,
2681 const Elf_Internal_Rela
*rel
)
2688 len
= 8 + 1 + strlen (hash
->root
.root
.root
.string
) + 1 + 16 + 1;
2689 stub_name
= bfd_malloc (len
);
2690 if (stub_name
!= NULL
)
2691 snprintf (stub_name
, len
, "%08x_%s+%" BFD_VMA_FMT
"x",
2692 (unsigned int) input_section
->id
,
2693 hash
->root
.root
.root
.string
,
2698 len
= 8 + 1 + 8 + 1 + 8 + 1 + 16 + 1;
2699 stub_name
= bfd_malloc (len
);
2700 if (stub_name
!= NULL
)
2701 snprintf (stub_name
, len
, "%08x_%x:%x+%" BFD_VMA_FMT
"x",
2702 (unsigned int) input_section
->id
,
2703 (unsigned int) sym_sec
->id
,
2704 (unsigned int) ELFNN_R_SYM (rel
->r_info
),
2711 /* Return TRUE if symbol H should be hashed in the `.gnu.hash' section. For
2712 executable PLT slots where the executable never takes the address of those
2713 functions, the function symbols are not added to the hash table. */
2716 elf_aarch64_hash_symbol (struct elf_link_hash_entry
*h
)
2718 if (h
->plt
.offset
!= (bfd_vma
) -1
2720 && !h
->pointer_equality_needed
)
2723 return _bfd_elf_hash_symbol (h
);
2727 /* Look up an entry in the stub hash. Stub entries are cached because
2728 creating the stub name takes a bit of time. */
2730 static struct elf_aarch64_stub_hash_entry
*
2731 elfNN_aarch64_get_stub_entry (const asection
*input_section
,
2732 const asection
*sym_sec
,
2733 struct elf_link_hash_entry
*hash
,
2734 const Elf_Internal_Rela
*rel
,
2735 struct elf_aarch64_link_hash_table
*htab
)
2737 struct elf_aarch64_stub_hash_entry
*stub_entry
;
2738 struct elf_aarch64_link_hash_entry
*h
=
2739 (struct elf_aarch64_link_hash_entry
*) hash
;
2740 const asection
*id_sec
;
2742 if ((input_section
->flags
& SEC_CODE
) == 0)
2745 /* If this input section is part of a group of sections sharing one
2746 stub section, then use the id of the first section in the group.
2747 Stub names need to include a section id, as there may well be
2748 more than one stub used to reach say, printf, and we need to
2749 distinguish between them. */
2750 id_sec
= htab
->stub_group
[input_section
->id
].link_sec
;
2752 if (h
!= NULL
&& h
->stub_cache
!= NULL
2753 && h
->stub_cache
->h
== h
&& h
->stub_cache
->id_sec
== id_sec
)
2755 stub_entry
= h
->stub_cache
;
2761 stub_name
= elfNN_aarch64_stub_name (id_sec
, sym_sec
, h
, rel
);
2762 if (stub_name
== NULL
)
2765 stub_entry
= aarch64_stub_hash_lookup (&htab
->stub_hash_table
,
2766 stub_name
, FALSE
, FALSE
);
2768 h
->stub_cache
= stub_entry
;
2777 /* Create a stub section. */
2780 _bfd_aarch64_create_stub_section (asection
*section
,
2781 struct elf_aarch64_link_hash_table
*htab
)
2787 namelen
= strlen (section
->name
);
2788 len
= namelen
+ sizeof (STUB_SUFFIX
);
2789 s_name
= bfd_alloc (htab
->stub_bfd
, len
);
2793 memcpy (s_name
, section
->name
, namelen
);
2794 memcpy (s_name
+ namelen
, STUB_SUFFIX
, sizeof (STUB_SUFFIX
));
2795 return (*htab
->add_stub_section
) (s_name
, section
);
2799 /* Find or create a stub section for a link section.
2801 Fix or create the stub section used to collect stubs attached to
2802 the specified link section. */
2805 _bfd_aarch64_get_stub_for_link_section (asection
*link_section
,
2806 struct elf_aarch64_link_hash_table
*htab
)
2808 if (htab
->stub_group
[link_section
->id
].stub_sec
== NULL
)
2809 htab
->stub_group
[link_section
->id
].stub_sec
2810 = _bfd_aarch64_create_stub_section (link_section
, htab
);
2811 return htab
->stub_group
[link_section
->id
].stub_sec
;
2815 /* Find or create a stub section in the stub group for an input
2819 _bfd_aarch64_create_or_find_stub_sec (asection
*section
,
2820 struct elf_aarch64_link_hash_table
*htab
)
2822 asection
*link_sec
= htab
->stub_group
[section
->id
].link_sec
;
2823 return _bfd_aarch64_get_stub_for_link_section (link_sec
, htab
);
2827 /* Add a new stub entry in the stub group associated with an input
2828 section to the stub hash. Not all fields of the new stub entry are
2831 static struct elf_aarch64_stub_hash_entry
*
2832 _bfd_aarch64_add_stub_entry_in_group (const char *stub_name
,
2834 struct elf_aarch64_link_hash_table
*htab
)
2838 struct elf_aarch64_stub_hash_entry
*stub_entry
;
2840 link_sec
= htab
->stub_group
[section
->id
].link_sec
;
2841 stub_sec
= _bfd_aarch64_create_or_find_stub_sec (section
, htab
);
2843 /* Enter this entry into the linker stub hash table. */
2844 stub_entry
= aarch64_stub_hash_lookup (&htab
->stub_hash_table
, stub_name
,
2846 if (stub_entry
== NULL
)
2848 /* xgettext:c-format */
2849 _bfd_error_handler (_("%s: cannot create stub entry %s"),
2850 section
->owner
, stub_name
);
2854 stub_entry
->stub_sec
= stub_sec
;
2855 stub_entry
->stub_offset
= 0;
2856 stub_entry
->id_sec
= link_sec
;
2861 /* Add a new stub entry in the final stub section to the stub hash.
2862 Not all fields of the new stub entry are initialised. */
2864 static struct elf_aarch64_stub_hash_entry
*
2865 _bfd_aarch64_add_stub_entry_after (const char *stub_name
,
2866 asection
*link_section
,
2867 struct elf_aarch64_link_hash_table
*htab
)
2870 struct elf_aarch64_stub_hash_entry
*stub_entry
;
2872 stub_sec
= _bfd_aarch64_get_stub_for_link_section (link_section
, htab
);
2873 stub_entry
= aarch64_stub_hash_lookup (&htab
->stub_hash_table
, stub_name
,
2875 if (stub_entry
== NULL
)
2877 _bfd_error_handler (_("cannot create stub entry %s"), stub_name
);
2881 stub_entry
->stub_sec
= stub_sec
;
2882 stub_entry
->stub_offset
= 0;
2883 stub_entry
->id_sec
= link_section
;
2890 aarch64_build_one_stub (struct bfd_hash_entry
*gen_entry
,
2891 void *in_arg ATTRIBUTE_UNUSED
)
2893 struct elf_aarch64_stub_hash_entry
*stub_entry
;
2898 bfd_vma veneered_insn_loc
;
2899 bfd_vma veneer_entry_loc
;
2900 bfd_signed_vma branch_offset
= 0;
2901 unsigned int template_size
;
2902 const uint32_t *template;
2905 /* Massage our args to the form they really have. */
2906 stub_entry
= (struct elf_aarch64_stub_hash_entry
*) gen_entry
;
2908 stub_sec
= stub_entry
->stub_sec
;
2910 /* Make a note of the offset within the stubs for this entry. */
2911 stub_entry
->stub_offset
= stub_sec
->size
;
2912 loc
= stub_sec
->contents
+ stub_entry
->stub_offset
;
2914 stub_bfd
= stub_sec
->owner
;
2916 /* This is the address of the stub destination. */
2917 sym_value
= (stub_entry
->target_value
2918 + stub_entry
->target_section
->output_offset
2919 + stub_entry
->target_section
->output_section
->vma
);
2921 if (stub_entry
->stub_type
== aarch64_stub_long_branch
)
2923 bfd_vma place
= (stub_entry
->stub_offset
+ stub_sec
->output_section
->vma
2924 + stub_sec
->output_offset
);
2926 /* See if we can relax the stub. */
2927 if (aarch64_valid_for_adrp_p (sym_value
, place
))
2928 stub_entry
->stub_type
= aarch64_select_branch_stub (sym_value
, place
);
2931 switch (stub_entry
->stub_type
)
2933 case aarch64_stub_adrp_branch
:
2934 template = aarch64_adrp_branch_stub
;
2935 template_size
= sizeof (aarch64_adrp_branch_stub
);
2937 case aarch64_stub_long_branch
:
2938 template = aarch64_long_branch_stub
;
2939 template_size
= sizeof (aarch64_long_branch_stub
);
2941 case aarch64_stub_erratum_835769_veneer
:
2942 template = aarch64_erratum_835769_stub
;
2943 template_size
= sizeof (aarch64_erratum_835769_stub
);
2945 case aarch64_stub_erratum_843419_veneer
:
2946 template = aarch64_erratum_843419_stub
;
2947 template_size
= sizeof (aarch64_erratum_843419_stub
);
2953 for (i
= 0; i
< (template_size
/ sizeof template[0]); i
++)
2955 bfd_putl32 (template[i
], loc
);
2959 template_size
= (template_size
+ 7) & ~7;
2960 stub_sec
->size
+= template_size
;
2962 switch (stub_entry
->stub_type
)
2964 case aarch64_stub_adrp_branch
:
2965 if (aarch64_relocate (AARCH64_R (ADR_PREL_PG_HI21
), stub_bfd
, stub_sec
,
2966 stub_entry
->stub_offset
, sym_value
))
2967 /* The stub would not have been relaxed if the offset was out
2971 if (aarch64_relocate (AARCH64_R (ADD_ABS_LO12_NC
), stub_bfd
, stub_sec
,
2972 stub_entry
->stub_offset
+ 4, sym_value
))
2976 case aarch64_stub_long_branch
:
2977 /* We want the value relative to the address 12 bytes back from the
2979 if (aarch64_relocate (AARCH64_R (PRELNN
), stub_bfd
, stub_sec
,
2980 stub_entry
->stub_offset
+ 16, sym_value
+ 12))
2984 case aarch64_stub_erratum_835769_veneer
:
2985 veneered_insn_loc
= stub_entry
->target_section
->output_section
->vma
2986 + stub_entry
->target_section
->output_offset
2987 + stub_entry
->target_value
;
2988 veneer_entry_loc
= stub_entry
->stub_sec
->output_section
->vma
2989 + stub_entry
->stub_sec
->output_offset
2990 + stub_entry
->stub_offset
;
2991 branch_offset
= veneered_insn_loc
- veneer_entry_loc
;
2992 branch_offset
>>= 2;
2993 branch_offset
&= 0x3ffffff;
2994 bfd_putl32 (stub_entry
->veneered_insn
,
2995 stub_sec
->contents
+ stub_entry
->stub_offset
);
2996 bfd_putl32 (template[1] | branch_offset
,
2997 stub_sec
->contents
+ stub_entry
->stub_offset
+ 4);
3000 case aarch64_stub_erratum_843419_veneer
:
3001 if (aarch64_relocate (AARCH64_R (JUMP26
), stub_bfd
, stub_sec
,
3002 stub_entry
->stub_offset
+ 4, sym_value
+ 4))
3013 /* As above, but don't actually build the stub. Just bump offset so
3014 we know stub section sizes. */
3017 aarch64_size_one_stub (struct bfd_hash_entry
*gen_entry
,
3018 void *in_arg ATTRIBUTE_UNUSED
)
3020 struct elf_aarch64_stub_hash_entry
*stub_entry
;
3023 /* Massage our args to the form they really have. */
3024 stub_entry
= (struct elf_aarch64_stub_hash_entry
*) gen_entry
;
3026 switch (stub_entry
->stub_type
)
3028 case aarch64_stub_adrp_branch
:
3029 size
= sizeof (aarch64_adrp_branch_stub
);
3031 case aarch64_stub_long_branch
:
3032 size
= sizeof (aarch64_long_branch_stub
);
3034 case aarch64_stub_erratum_835769_veneer
:
3035 size
= sizeof (aarch64_erratum_835769_stub
);
3037 case aarch64_stub_erratum_843419_veneer
:
3038 size
= sizeof (aarch64_erratum_843419_stub
);
3044 size
= (size
+ 7) & ~7;
3045 stub_entry
->stub_sec
->size
+= size
;
3049 /* External entry points for sizing and building linker stubs. */
3051 /* Set up various things so that we can make a list of input sections
3052 for each output section included in the link. Returns -1 on error,
3053 0 when no stubs will be needed, and 1 on success. */
3056 elfNN_aarch64_setup_section_lists (bfd
*output_bfd
,
3057 struct bfd_link_info
*info
)
3060 unsigned int bfd_count
;
3061 unsigned int top_id
, top_index
;
3063 asection
**input_list
, **list
;
3065 struct elf_aarch64_link_hash_table
*htab
=
3066 elf_aarch64_hash_table (info
);
3068 if (!is_elf_hash_table (htab
))
3071 /* Count the number of input BFDs and find the top input section id. */
3072 for (input_bfd
= info
->input_bfds
, bfd_count
= 0, top_id
= 0;
3073 input_bfd
!= NULL
; input_bfd
= input_bfd
->link
.next
)
3076 for (section
= input_bfd
->sections
;
3077 section
!= NULL
; section
= section
->next
)
3079 if (top_id
< section
->id
)
3080 top_id
= section
->id
;
3083 htab
->bfd_count
= bfd_count
;
3085 amt
= sizeof (struct map_stub
) * (top_id
+ 1);
3086 htab
->stub_group
= bfd_zmalloc (amt
);
3087 if (htab
->stub_group
== NULL
)
3090 /* We can't use output_bfd->section_count here to find the top output
3091 section index as some sections may have been removed, and
3092 _bfd_strip_section_from_output doesn't renumber the indices. */
3093 for (section
= output_bfd
->sections
, top_index
= 0;
3094 section
!= NULL
; section
= section
->next
)
3096 if (top_index
< section
->index
)
3097 top_index
= section
->index
;
3100 htab
->top_index
= top_index
;
3101 amt
= sizeof (asection
*) * (top_index
+ 1);
3102 input_list
= bfd_malloc (amt
);
3103 htab
->input_list
= input_list
;
3104 if (input_list
== NULL
)
3107 /* For sections we aren't interested in, mark their entries with a
3108 value we can check later. */
3109 list
= input_list
+ top_index
;
3111 *list
= bfd_abs_section_ptr
;
3112 while (list
-- != input_list
);
3114 for (section
= output_bfd
->sections
;
3115 section
!= NULL
; section
= section
->next
)
3117 if ((section
->flags
& SEC_CODE
) != 0)
3118 input_list
[section
->index
] = NULL
;
3124 /* Used by elfNN_aarch64_next_input_section and group_sections. */
3125 #define PREV_SEC(sec) (htab->stub_group[(sec)->id].link_sec)
3127 /* The linker repeatedly calls this function for each input section,
3128 in the order that input sections are linked into output sections.
3129 Build lists of input sections to determine groupings between which
3130 we may insert linker stubs. */
3133 elfNN_aarch64_next_input_section (struct bfd_link_info
*info
, asection
*isec
)
3135 struct elf_aarch64_link_hash_table
*htab
=
3136 elf_aarch64_hash_table (info
);
3138 if (isec
->output_section
->index
<= htab
->top_index
)
3140 asection
**list
= htab
->input_list
+ isec
->output_section
->index
;
3142 if (*list
!= bfd_abs_section_ptr
)
3144 /* Steal the link_sec pointer for our list. */
3145 /* This happens to make the list in reverse order,
3146 which is what we want. */
3147 PREV_SEC (isec
) = *list
;
3153 /* See whether we can group stub sections together. Grouping stub
3154 sections may result in fewer stubs. More importantly, we need to
3155 put all .init* and .fini* stubs at the beginning of the .init or
3156 .fini output sections respectively, because glibc splits the
3157 _init and _fini functions into multiple parts. Putting a stub in
3158 the middle of a function is not a good idea. */
3161 group_sections (struct elf_aarch64_link_hash_table
*htab
,
3162 bfd_size_type stub_group_size
,
3163 bfd_boolean stubs_always_before_branch
)
3165 asection
**list
= htab
->input_list
+ htab
->top_index
;
3169 asection
*tail
= *list
;
3171 if (tail
== bfd_abs_section_ptr
)
3174 while (tail
!= NULL
)
3178 bfd_size_type total
;
3182 while ((prev
= PREV_SEC (curr
)) != NULL
3183 && ((total
+= curr
->output_offset
- prev
->output_offset
)
3187 /* OK, the size from the start of CURR to the end is less
3188 than stub_group_size and thus can be handled by one stub
3189 section. (Or the tail section is itself larger than
3190 stub_group_size, in which case we may be toast.)
3191 We should really be keeping track of the total size of
3192 stubs added here, as stubs contribute to the final output
3196 prev
= PREV_SEC (tail
);
3197 /* Set up this stub group. */
3198 htab
->stub_group
[tail
->id
].link_sec
= curr
;
3200 while (tail
!= curr
&& (tail
= prev
) != NULL
);
3202 /* But wait, there's more! Input sections up to stub_group_size
3203 bytes before the stub section can be handled by it too. */
3204 if (!stubs_always_before_branch
)
3208 && ((total
+= tail
->output_offset
- prev
->output_offset
)
3212 prev
= PREV_SEC (tail
);
3213 htab
->stub_group
[tail
->id
].link_sec
= curr
;
3219 while (list
-- != htab
->input_list
);
3221 free (htab
->input_list
);
3226 #define AARCH64_BITS(x, pos, n) (((x) >> (pos)) & ((1 << (n)) - 1))
3228 #define AARCH64_RT(insn) AARCH64_BITS (insn, 0, 5)
3229 #define AARCH64_RT2(insn) AARCH64_BITS (insn, 10, 5)
3230 #define AARCH64_RA(insn) AARCH64_BITS (insn, 10, 5)
3231 #define AARCH64_RD(insn) AARCH64_BITS (insn, 0, 5)
3232 #define AARCH64_RN(insn) AARCH64_BITS (insn, 5, 5)
3233 #define AARCH64_RM(insn) AARCH64_BITS (insn, 16, 5)
3235 #define AARCH64_MAC(insn) (((insn) & 0xff000000) == 0x9b000000)
3236 #define AARCH64_BIT(insn, n) AARCH64_BITS (insn, n, 1)
3237 #define AARCH64_OP31(insn) AARCH64_BITS (insn, 21, 3)
3238 #define AARCH64_ZR 0x1f
3240 /* All ld/st ops. See C4-182 of the ARM ARM. The encoding space for
3241 LD_PCREL, LDST_RO, LDST_UI and LDST_UIMM cover prefetch ops. */
3243 #define AARCH64_LD(insn) (AARCH64_BIT (insn, 22) == 1)
3244 #define AARCH64_LDST(insn) (((insn) & 0x0a000000) == 0x08000000)
3245 #define AARCH64_LDST_EX(insn) (((insn) & 0x3f000000) == 0x08000000)
3246 #define AARCH64_LDST_PCREL(insn) (((insn) & 0x3b000000) == 0x18000000)
3247 #define AARCH64_LDST_NAP(insn) (((insn) & 0x3b800000) == 0x28000000)
3248 #define AARCH64_LDSTP_PI(insn) (((insn) & 0x3b800000) == 0x28800000)
3249 #define AARCH64_LDSTP_O(insn) (((insn) & 0x3b800000) == 0x29000000)
3250 #define AARCH64_LDSTP_PRE(insn) (((insn) & 0x3b800000) == 0x29800000)
3251 #define AARCH64_LDST_UI(insn) (((insn) & 0x3b200c00) == 0x38000000)
3252 #define AARCH64_LDST_PIIMM(insn) (((insn) & 0x3b200c00) == 0x38000400)
3253 #define AARCH64_LDST_U(insn) (((insn) & 0x3b200c00) == 0x38000800)
3254 #define AARCH64_LDST_PREIMM(insn) (((insn) & 0x3b200c00) == 0x38000c00)
3255 #define AARCH64_LDST_RO(insn) (((insn) & 0x3b200c00) == 0x38200800)
3256 #define AARCH64_LDST_UIMM(insn) (((insn) & 0x3b000000) == 0x39000000)
3257 #define AARCH64_LDST_SIMD_M(insn) (((insn) & 0xbfbf0000) == 0x0c000000)
3258 #define AARCH64_LDST_SIMD_M_PI(insn) (((insn) & 0xbfa00000) == 0x0c800000)
3259 #define AARCH64_LDST_SIMD_S(insn) (((insn) & 0xbf9f0000) == 0x0d000000)
3260 #define AARCH64_LDST_SIMD_S_PI(insn) (((insn) & 0xbf800000) == 0x0d800000)
3262 /* Classify an INSN if it is indeed a load/store.
3264 Return TRUE if INSN is a LD/ST instruction otherwise return FALSE.
3266 For scalar LD/ST instructions PAIR is FALSE, RT is returned and RT2
3269 For LD/ST pair instructions PAIR is TRUE, RT and RT2 are returned.
3274 aarch64_mem_op_p (uint32_t insn
, unsigned int *rt
, unsigned int *rt2
,
3275 bfd_boolean
*pair
, bfd_boolean
*load
)
3283 /* Bail out quickly if INSN doesn't fall into the the load-store
3285 if (!AARCH64_LDST (insn
))
3290 if (AARCH64_LDST_EX (insn
))
3292 *rt
= AARCH64_RT (insn
);
3294 if (AARCH64_BIT (insn
, 21) == 1)
3297 *rt2
= AARCH64_RT2 (insn
);
3299 *load
= AARCH64_LD (insn
);
3302 else if (AARCH64_LDST_NAP (insn
)
3303 || AARCH64_LDSTP_PI (insn
)
3304 || AARCH64_LDSTP_O (insn
)
3305 || AARCH64_LDSTP_PRE (insn
))
3308 *rt
= AARCH64_RT (insn
);
3309 *rt2
= AARCH64_RT2 (insn
);
3310 *load
= AARCH64_LD (insn
);
3313 else if (AARCH64_LDST_PCREL (insn
)
3314 || AARCH64_LDST_UI (insn
)
3315 || AARCH64_LDST_PIIMM (insn
)
3316 || AARCH64_LDST_U (insn
)
3317 || AARCH64_LDST_PREIMM (insn
)
3318 || AARCH64_LDST_RO (insn
)
3319 || AARCH64_LDST_UIMM (insn
))
3321 *rt
= AARCH64_RT (insn
);
3323 if (AARCH64_LDST_PCREL (insn
))
3325 opc
= AARCH64_BITS (insn
, 22, 2);
3326 v
= AARCH64_BIT (insn
, 26);
3327 opc_v
= opc
| (v
<< 2);
3328 *load
= (opc_v
== 1 || opc_v
== 2 || opc_v
== 3
3329 || opc_v
== 5 || opc_v
== 7);
3332 else if (AARCH64_LDST_SIMD_M (insn
)
3333 || AARCH64_LDST_SIMD_M_PI (insn
))
3335 *rt
= AARCH64_RT (insn
);
3336 *load
= AARCH64_BIT (insn
, 22);
3337 opcode
= (insn
>> 12) & 0xf;
3364 else if (AARCH64_LDST_SIMD_S (insn
)
3365 || AARCH64_LDST_SIMD_S_PI (insn
))
3367 *rt
= AARCH64_RT (insn
);
3368 r
= (insn
>> 21) & 1;
3369 *load
= AARCH64_BIT (insn
, 22);
3370 opcode
= (insn
>> 13) & 0x7;
3382 *rt2
= *rt
+ (r
== 0 ? 2 : 3);
3390 *rt2
= *rt
+ (r
== 0 ? 2 : 3);
3402 /* Return TRUE if INSN is multiply-accumulate. */
3405 aarch64_mlxl_p (uint32_t insn
)
3407 uint32_t op31
= AARCH64_OP31 (insn
);
3409 if (AARCH64_MAC (insn
)
3410 && (op31
== 0 || op31
== 1 || op31
== 5)
3411 /* Exclude MUL instructions which are encoded as a multiple accumulate
3413 && AARCH64_RA (insn
) != AARCH64_ZR
)
3419 /* Some early revisions of the Cortex-A53 have an erratum (835769) whereby
3420 it is possible for a 64-bit multiply-accumulate instruction to generate an
3421 incorrect result. The details are quite complex and hard to
3422 determine statically, since branches in the code may exist in some
3423 circumstances, but all cases end with a memory (load, store, or
3424 prefetch) instruction followed immediately by the multiply-accumulate
3425 operation. We employ a linker patching technique, by moving the potentially
3426 affected multiply-accumulate instruction into a patch region and replacing
3427 the original instruction with a branch to the patch. This function checks
3428 if INSN_1 is the memory operation followed by a multiply-accumulate
3429 operation (INSN_2). Return TRUE if an erratum sequence is found, FALSE
3430 if INSN_1 and INSN_2 are safe. */
3433 aarch64_erratum_sequence (uint32_t insn_1
, uint32_t insn_2
)
3443 if (aarch64_mlxl_p (insn_2
)
3444 && aarch64_mem_op_p (insn_1
, &rt
, &rt2
, &pair
, &load
))
3446 /* Any SIMD memory op is independent of the subsequent MLA
3447 by definition of the erratum. */
3448 if (AARCH64_BIT (insn_1
, 26))
3451 /* If not SIMD, check for integer memory ops and MLA relationship. */
3452 rn
= AARCH64_RN (insn_2
);
3453 ra
= AARCH64_RA (insn_2
);
3454 rm
= AARCH64_RM (insn_2
);
3456 /* If this is a load and there's a true(RAW) dependency, we are safe
3457 and this is not an erratum sequence. */
3459 (rt
== rn
|| rt
== rm
|| rt
== ra
3460 || (pair
&& (rt2
== rn
|| rt2
== rm
|| rt2
== ra
))))
3463 /* We conservatively put out stubs for all other cases (including
3471 /* Used to order a list of mapping symbols by address. */
3474 elf_aarch64_compare_mapping (const void *a
, const void *b
)
3476 const elf_aarch64_section_map
*amap
= (const elf_aarch64_section_map
*) a
;
3477 const elf_aarch64_section_map
*bmap
= (const elf_aarch64_section_map
*) b
;
3479 if (amap
->vma
> bmap
->vma
)
3481 else if (amap
->vma
< bmap
->vma
)
3483 else if (amap
->type
> bmap
->type
)
3484 /* Ensure results do not depend on the host qsort for objects with
3485 multiple mapping symbols at the same address by sorting on type
3488 else if (amap
->type
< bmap
->type
)
3496 _bfd_aarch64_erratum_835769_stub_name (unsigned num_fixes
)
3498 char *stub_name
= (char *) bfd_malloc
3499 (strlen ("__erratum_835769_veneer_") + 16);
3500 sprintf (stub_name
,"__erratum_835769_veneer_%d", num_fixes
);
3504 /* Scan for Cortex-A53 erratum 835769 sequence.
3506 Return TRUE else FALSE on abnormal termination. */
3509 _bfd_aarch64_erratum_835769_scan (bfd
*input_bfd
,
3510 struct bfd_link_info
*info
,
3511 unsigned int *num_fixes_p
)
3514 struct elf_aarch64_link_hash_table
*htab
= elf_aarch64_hash_table (info
);
3515 unsigned int num_fixes
= *num_fixes_p
;
3520 for (section
= input_bfd
->sections
;
3522 section
= section
->next
)
3524 bfd_byte
*contents
= NULL
;
3525 struct _aarch64_elf_section_data
*sec_data
;
3528 if (elf_section_type (section
) != SHT_PROGBITS
3529 || (elf_section_flags (section
) & SHF_EXECINSTR
) == 0
3530 || (section
->flags
& SEC_EXCLUDE
) != 0
3531 || (section
->sec_info_type
== SEC_INFO_TYPE_JUST_SYMS
)
3532 || (section
->output_section
== bfd_abs_section_ptr
))
3535 if (elf_section_data (section
)->this_hdr
.contents
!= NULL
)
3536 contents
= elf_section_data (section
)->this_hdr
.contents
;
3537 else if (! bfd_malloc_and_get_section (input_bfd
, section
, &contents
))
3540 sec_data
= elf_aarch64_section_data (section
);
3542 qsort (sec_data
->map
, sec_data
->mapcount
,
3543 sizeof (elf_aarch64_section_map
), elf_aarch64_compare_mapping
);
3545 for (span
= 0; span
< sec_data
->mapcount
; span
++)
3547 unsigned int span_start
= sec_data
->map
[span
].vma
;
3548 unsigned int span_end
= ((span
== sec_data
->mapcount
- 1)
3549 ? sec_data
->map
[0].vma
+ section
->size
3550 : sec_data
->map
[span
+ 1].vma
);
3552 char span_type
= sec_data
->map
[span
].type
;
3554 if (span_type
== 'd')
3557 for (i
= span_start
; i
+ 4 < span_end
; i
+= 4)
3559 uint32_t insn_1
= bfd_getl32 (contents
+ i
);
3560 uint32_t insn_2
= bfd_getl32 (contents
+ i
+ 4);
3562 if (aarch64_erratum_sequence (insn_1
, insn_2
))
3564 struct elf_aarch64_stub_hash_entry
*stub_entry
;
3565 char *stub_name
= _bfd_aarch64_erratum_835769_stub_name (num_fixes
);
3569 stub_entry
= _bfd_aarch64_add_stub_entry_in_group (stub_name
,
3575 stub_entry
->stub_type
= aarch64_stub_erratum_835769_veneer
;
3576 stub_entry
->target_section
= section
;
3577 stub_entry
->target_value
= i
+ 4;
3578 stub_entry
->veneered_insn
= insn_2
;
3579 stub_entry
->output_name
= stub_name
;
3584 if (elf_section_data (section
)->this_hdr
.contents
== NULL
)
3588 *num_fixes_p
= num_fixes
;
3594 /* Test if instruction INSN is ADRP. */
3597 _bfd_aarch64_adrp_p (uint32_t insn
)
3599 return ((insn
& 0x9f000000) == 0x90000000);
3603 /* Helper predicate to look for cortex-a53 erratum 843419 sequence 1. */
3606 _bfd_aarch64_erratum_843419_sequence_p (uint32_t insn_1
, uint32_t insn_2
,
3614 return (aarch64_mem_op_p (insn_2
, &rt
, &rt2
, &pair
, &load
)
3617 && AARCH64_LDST_UIMM (insn_3
)
3618 && AARCH64_RN (insn_3
) == AARCH64_RD (insn_1
));
3622 /* Test for the presence of Cortex-A53 erratum 843419 instruction sequence.
3624 Return TRUE if section CONTENTS at offset I contains one of the
3625 erratum 843419 sequences, otherwise return FALSE. If a sequence is
3626 seen set P_VENEER_I to the offset of the final LOAD/STORE
3627 instruction in the sequence.
3631 _bfd_aarch64_erratum_843419_p (bfd_byte
*contents
, bfd_vma vma
,
3632 bfd_vma i
, bfd_vma span_end
,
3633 bfd_vma
*p_veneer_i
)
3635 uint32_t insn_1
= bfd_getl32 (contents
+ i
);
3637 if (!_bfd_aarch64_adrp_p (insn_1
))
3640 if (span_end
< i
+ 12)
3643 uint32_t insn_2
= bfd_getl32 (contents
+ i
+ 4);
3644 uint32_t insn_3
= bfd_getl32 (contents
+ i
+ 8);
3646 if ((vma
& 0xfff) != 0xff8 && (vma
& 0xfff) != 0xffc)
3649 if (_bfd_aarch64_erratum_843419_sequence_p (insn_1
, insn_2
, insn_3
))
3651 *p_veneer_i
= i
+ 8;
3655 if (span_end
< i
+ 16)
3658 uint32_t insn_4
= bfd_getl32 (contents
+ i
+ 12);
3660 if (_bfd_aarch64_erratum_843419_sequence_p (insn_1
, insn_2
, insn_4
))
3662 *p_veneer_i
= i
+ 12;
3670 /* Resize all stub sections. */
3673 _bfd_aarch64_resize_stubs (struct elf_aarch64_link_hash_table
*htab
)
3677 /* OK, we've added some stubs. Find out the new size of the
3679 for (section
= htab
->stub_bfd
->sections
;
3680 section
!= NULL
; section
= section
->next
)
3682 /* Ignore non-stub sections. */
3683 if (!strstr (section
->name
, STUB_SUFFIX
))
3688 bfd_hash_traverse (&htab
->stub_hash_table
, aarch64_size_one_stub
, htab
);
3690 for (section
= htab
->stub_bfd
->sections
;
3691 section
!= NULL
; section
= section
->next
)
3693 if (!strstr (section
->name
, STUB_SUFFIX
))
3699 /* Ensure all stub sections have a size which is a multiple of
3700 4096. This is important in order to ensure that the insertion
3701 of stub sections does not in itself move existing code around
3702 in such a way that new errata sequences are created. */
3703 if (htab
->fix_erratum_843419
)
3705 section
->size
= BFD_ALIGN (section
->size
, 0x1000);
3710 /* Construct an erratum 843419 workaround stub name.
3714 _bfd_aarch64_erratum_843419_stub_name (asection
*input_section
,
3717 const bfd_size_type len
= 8 + 4 + 1 + 8 + 1 + 16 + 1;
3718 char *stub_name
= bfd_malloc (len
);
3720 if (stub_name
!= NULL
)
3721 snprintf (stub_name
, len
, "e843419@%04x_%08x_%" BFD_VMA_FMT
"x",
3722 input_section
->owner
->id
,
3728 /* Build a stub_entry structure describing an 843419 fixup.
3730 The stub_entry constructed is populated with the bit pattern INSN
3731 of the instruction located at OFFSET within input SECTION.
3733 Returns TRUE on success. */
3736 _bfd_aarch64_erratum_843419_fixup (uint32_t insn
,
3737 bfd_vma adrp_offset
,
3738 bfd_vma ldst_offset
,
3740 struct bfd_link_info
*info
)
3742 struct elf_aarch64_link_hash_table
*htab
= elf_aarch64_hash_table (info
);
3744 struct elf_aarch64_stub_hash_entry
*stub_entry
;
3746 stub_name
= _bfd_aarch64_erratum_843419_stub_name (section
, ldst_offset
);
3747 stub_entry
= aarch64_stub_hash_lookup (&htab
->stub_hash_table
, stub_name
,
3755 /* We always place an 843419 workaround veneer in the stub section
3756 attached to the input section in which an erratum sequence has
3757 been found. This ensures that later in the link process (in
3758 elfNN_aarch64_write_section) when we copy the veneered
3759 instruction from the input section into the stub section the
3760 copied instruction will have had any relocations applied to it.
3761 If we placed workaround veneers in any other stub section then we
3762 could not assume that all relocations have been processed on the
3763 corresponding input section at the point we output the stub
3767 stub_entry
= _bfd_aarch64_add_stub_entry_after (stub_name
, section
, htab
);
3768 if (stub_entry
== NULL
)
3774 stub_entry
->adrp_offset
= adrp_offset
;
3775 stub_entry
->target_value
= ldst_offset
;
3776 stub_entry
->target_section
= section
;
3777 stub_entry
->stub_type
= aarch64_stub_erratum_843419_veneer
;
3778 stub_entry
->veneered_insn
= insn
;
3779 stub_entry
->output_name
= stub_name
;
3785 /* Scan an input section looking for the signature of erratum 843419.
3787 Scans input SECTION in INPUT_BFD looking for erratum 843419
3788 signatures, for each signature found a stub_entry is created
3789 describing the location of the erratum for subsequent fixup.
3791 Return TRUE on successful scan, FALSE on failure to scan.
3795 _bfd_aarch64_erratum_843419_scan (bfd
*input_bfd
, asection
*section
,
3796 struct bfd_link_info
*info
)
3798 struct elf_aarch64_link_hash_table
*htab
= elf_aarch64_hash_table (info
);
3803 if (elf_section_type (section
) != SHT_PROGBITS
3804 || (elf_section_flags (section
) & SHF_EXECINSTR
) == 0
3805 || (section
->flags
& SEC_EXCLUDE
) != 0
3806 || (section
->sec_info_type
== SEC_INFO_TYPE_JUST_SYMS
)
3807 || (section
->output_section
== bfd_abs_section_ptr
))
3812 bfd_byte
*contents
= NULL
;
3813 struct _aarch64_elf_section_data
*sec_data
;
3816 if (elf_section_data (section
)->this_hdr
.contents
!= NULL
)
3817 contents
= elf_section_data (section
)->this_hdr
.contents
;
3818 else if (! bfd_malloc_and_get_section (input_bfd
, section
, &contents
))
3821 sec_data
= elf_aarch64_section_data (section
);
3823 qsort (sec_data
->map
, sec_data
->mapcount
,
3824 sizeof (elf_aarch64_section_map
), elf_aarch64_compare_mapping
);
3826 for (span
= 0; span
< sec_data
->mapcount
; span
++)
3828 unsigned int span_start
= sec_data
->map
[span
].vma
;
3829 unsigned int span_end
= ((span
== sec_data
->mapcount
- 1)
3830 ? sec_data
->map
[0].vma
+ section
->size
3831 : sec_data
->map
[span
+ 1].vma
);
3833 char span_type
= sec_data
->map
[span
].type
;
3835 if (span_type
== 'd')
3838 for (i
= span_start
; i
+ 8 < span_end
; i
+= 4)
3840 bfd_vma vma
= (section
->output_section
->vma
3841 + section
->output_offset
3845 if (_bfd_aarch64_erratum_843419_p
3846 (contents
, vma
, i
, span_end
, &veneer_i
))
3848 uint32_t insn
= bfd_getl32 (contents
+ veneer_i
);
3850 if (!_bfd_aarch64_erratum_843419_fixup (insn
, i
, veneer_i
,
3857 if (elf_section_data (section
)->this_hdr
.contents
== NULL
)
3866 /* Determine and set the size of the stub section for a final link.
3868 The basic idea here is to examine all the relocations looking for
3869 PC-relative calls to a target that is unreachable with a "bl"
3873 elfNN_aarch64_size_stubs (bfd
*output_bfd
,
3875 struct bfd_link_info
*info
,
3876 bfd_signed_vma group_size
,
3877 asection
* (*add_stub_section
) (const char *,
3879 void (*layout_sections_again
) (void))
3881 bfd_size_type stub_group_size
;
3882 bfd_boolean stubs_always_before_branch
;
3883 bfd_boolean stub_changed
= FALSE
;
3884 struct elf_aarch64_link_hash_table
*htab
= elf_aarch64_hash_table (info
);
3885 unsigned int num_erratum_835769_fixes
= 0;
3887 /* Propagate mach to stub bfd, because it may not have been
3888 finalized when we created stub_bfd. */
3889 bfd_set_arch_mach (stub_bfd
, bfd_get_arch (output_bfd
),
3890 bfd_get_mach (output_bfd
));
3892 /* Stash our params away. */
3893 htab
->stub_bfd
= stub_bfd
;
3894 htab
->add_stub_section
= add_stub_section
;
3895 htab
->layout_sections_again
= layout_sections_again
;
3896 stubs_always_before_branch
= group_size
< 0;
3898 stub_group_size
= -group_size
;
3900 stub_group_size
= group_size
;
3902 if (stub_group_size
== 1)
3904 /* Default values. */
3905 /* AArch64 branch range is +-128MB. The value used is 1MB less. */
3906 stub_group_size
= 127 * 1024 * 1024;
3909 group_sections (htab
, stub_group_size
, stubs_always_before_branch
);
3911 (*htab
->layout_sections_again
) ();
3913 if (htab
->fix_erratum_835769
)
3917 for (input_bfd
= info
->input_bfds
;
3918 input_bfd
!= NULL
; input_bfd
= input_bfd
->link
.next
)
3919 if (!_bfd_aarch64_erratum_835769_scan (input_bfd
, info
,
3920 &num_erratum_835769_fixes
))
3923 _bfd_aarch64_resize_stubs (htab
);
3924 (*htab
->layout_sections_again
) ();
3927 if (htab
->fix_erratum_843419
)
3931 for (input_bfd
= info
->input_bfds
;
3933 input_bfd
= input_bfd
->link
.next
)
3937 for (section
= input_bfd
->sections
;
3939 section
= section
->next
)
3940 if (!_bfd_aarch64_erratum_843419_scan (input_bfd
, section
, info
))
3944 _bfd_aarch64_resize_stubs (htab
);
3945 (*htab
->layout_sections_again
) ();
3952 for (input_bfd
= info
->input_bfds
;
3953 input_bfd
!= NULL
; input_bfd
= input_bfd
->link
.next
)
3955 Elf_Internal_Shdr
*symtab_hdr
;
3957 Elf_Internal_Sym
*local_syms
= NULL
;
3959 /* We'll need the symbol table in a second. */
3960 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
3961 if (symtab_hdr
->sh_info
== 0)
3964 /* Walk over each section attached to the input bfd. */
3965 for (section
= input_bfd
->sections
;
3966 section
!= NULL
; section
= section
->next
)
3968 Elf_Internal_Rela
*internal_relocs
, *irelaend
, *irela
;
3970 /* If there aren't any relocs, then there's nothing more
3972 if ((section
->flags
& SEC_RELOC
) == 0
3973 || section
->reloc_count
== 0
3974 || (section
->flags
& SEC_CODE
) == 0)
3977 /* If this section is a link-once section that will be
3978 discarded, then don't create any stubs. */
3979 if (section
->output_section
== NULL
3980 || section
->output_section
->owner
!= output_bfd
)
3983 /* Get the relocs. */
3985 = _bfd_elf_link_read_relocs (input_bfd
, section
, NULL
,
3986 NULL
, info
->keep_memory
);
3987 if (internal_relocs
== NULL
)
3988 goto error_ret_free_local
;
3990 /* Now examine each relocation. */
3991 irela
= internal_relocs
;
3992 irelaend
= irela
+ section
->reloc_count
;
3993 for (; irela
< irelaend
; irela
++)
3995 unsigned int r_type
, r_indx
;
3996 enum elf_aarch64_stub_type stub_type
;
3997 struct elf_aarch64_stub_hash_entry
*stub_entry
;
4000 bfd_vma destination
;
4001 struct elf_aarch64_link_hash_entry
*hash
;
4002 const char *sym_name
;
4004 const asection
*id_sec
;
4005 unsigned char st_type
;
4008 r_type
= ELFNN_R_TYPE (irela
->r_info
);
4009 r_indx
= ELFNN_R_SYM (irela
->r_info
);
4011 if (r_type
>= (unsigned int) R_AARCH64_end
)
4013 bfd_set_error (bfd_error_bad_value
);
4014 error_ret_free_internal
:
4015 if (elf_section_data (section
)->relocs
== NULL
)
4016 free (internal_relocs
);
4017 goto error_ret_free_local
;
4020 /* Only look for stubs on unconditional branch and
4021 branch and link instructions. */
4022 if (r_type
!= (unsigned int) AARCH64_R (CALL26
)
4023 && r_type
!= (unsigned int) AARCH64_R (JUMP26
))
4026 /* Now determine the call target, its name, value,
4033 if (r_indx
< symtab_hdr
->sh_info
)
4035 /* It's a local symbol. */
4036 Elf_Internal_Sym
*sym
;
4037 Elf_Internal_Shdr
*hdr
;
4039 if (local_syms
== NULL
)
4042 = (Elf_Internal_Sym
*) symtab_hdr
->contents
;
4043 if (local_syms
== NULL
)
4045 = bfd_elf_get_elf_syms (input_bfd
, symtab_hdr
,
4046 symtab_hdr
->sh_info
, 0,
4048 if (local_syms
== NULL
)
4049 goto error_ret_free_internal
;
4052 sym
= local_syms
+ r_indx
;
4053 hdr
= elf_elfsections (input_bfd
)[sym
->st_shndx
];
4054 sym_sec
= hdr
->bfd_section
;
4056 /* This is an undefined symbol. It can never
4060 if (ELF_ST_TYPE (sym
->st_info
) != STT_SECTION
)
4061 sym_value
= sym
->st_value
;
4062 destination
= (sym_value
+ irela
->r_addend
4063 + sym_sec
->output_offset
4064 + sym_sec
->output_section
->vma
);
4065 st_type
= ELF_ST_TYPE (sym
->st_info
);
4067 = bfd_elf_string_from_elf_section (input_bfd
,
4068 symtab_hdr
->sh_link
,
4075 e_indx
= r_indx
- symtab_hdr
->sh_info
;
4076 hash
= ((struct elf_aarch64_link_hash_entry
*)
4077 elf_sym_hashes (input_bfd
)[e_indx
]);
4079 while (hash
->root
.root
.type
== bfd_link_hash_indirect
4080 || hash
->root
.root
.type
== bfd_link_hash_warning
)
4081 hash
= ((struct elf_aarch64_link_hash_entry
*)
4082 hash
->root
.root
.u
.i
.link
);
4084 if (hash
->root
.root
.type
== bfd_link_hash_defined
4085 || hash
->root
.root
.type
== bfd_link_hash_defweak
)
4087 struct elf_aarch64_link_hash_table
*globals
=
4088 elf_aarch64_hash_table (info
);
4089 sym_sec
= hash
->root
.root
.u
.def
.section
;
4090 sym_value
= hash
->root
.root
.u
.def
.value
;
4091 /* For a destination in a shared library,
4092 use the PLT stub as target address to
4093 decide whether a branch stub is
4095 if (globals
->root
.splt
!= NULL
&& hash
!= NULL
4096 && hash
->root
.plt
.offset
!= (bfd_vma
) - 1)
4098 sym_sec
= globals
->root
.splt
;
4099 sym_value
= hash
->root
.plt
.offset
;
4100 if (sym_sec
->output_section
!= NULL
)
4101 destination
= (sym_value
4102 + sym_sec
->output_offset
4104 sym_sec
->output_section
->vma
);
4106 else if (sym_sec
->output_section
!= NULL
)
4107 destination
= (sym_value
+ irela
->r_addend
4108 + sym_sec
->output_offset
4109 + sym_sec
->output_section
->vma
);
4111 else if (hash
->root
.root
.type
== bfd_link_hash_undefined
4112 || (hash
->root
.root
.type
4113 == bfd_link_hash_undefweak
))
4115 /* For a shared library, use the PLT stub as
4116 target address to decide whether a long
4117 branch stub is needed.
4118 For absolute code, they cannot be handled. */
4119 struct elf_aarch64_link_hash_table
*globals
=
4120 elf_aarch64_hash_table (info
);
4122 if (globals
->root
.splt
!= NULL
&& hash
!= NULL
4123 && hash
->root
.plt
.offset
!= (bfd_vma
) - 1)
4125 sym_sec
= globals
->root
.splt
;
4126 sym_value
= hash
->root
.plt
.offset
;
4127 if (sym_sec
->output_section
!= NULL
)
4128 destination
= (sym_value
4129 + sym_sec
->output_offset
4131 sym_sec
->output_section
->vma
);
4138 bfd_set_error (bfd_error_bad_value
);
4139 goto error_ret_free_internal
;
4141 st_type
= ELF_ST_TYPE (hash
->root
.type
);
4142 sym_name
= hash
->root
.root
.root
.string
;
4145 /* Determine what (if any) linker stub is needed. */
4146 stub_type
= aarch64_type_of_stub (section
, irela
, sym_sec
,
4147 st_type
, destination
);
4148 if (stub_type
== aarch64_stub_none
)
4151 /* Support for grouping stub sections. */
4152 id_sec
= htab
->stub_group
[section
->id
].link_sec
;
4154 /* Get the name of this stub. */
4155 stub_name
= elfNN_aarch64_stub_name (id_sec
, sym_sec
, hash
,
4158 goto error_ret_free_internal
;
4161 aarch64_stub_hash_lookup (&htab
->stub_hash_table
,
4162 stub_name
, FALSE
, FALSE
);
4163 if (stub_entry
!= NULL
)
4165 /* The proper stub has already been created. */
4170 stub_entry
= _bfd_aarch64_add_stub_entry_in_group
4171 (stub_name
, section
, htab
);
4172 if (stub_entry
== NULL
)
4175 goto error_ret_free_internal
;
4178 stub_entry
->target_value
= sym_value
+ irela
->r_addend
;
4179 stub_entry
->target_section
= sym_sec
;
4180 stub_entry
->stub_type
= stub_type
;
4181 stub_entry
->h
= hash
;
4182 stub_entry
->st_type
= st_type
;
4184 if (sym_name
== NULL
)
4185 sym_name
= "unnamed";
4186 len
= sizeof (STUB_ENTRY_NAME
) + strlen (sym_name
);
4187 stub_entry
->output_name
= bfd_alloc (htab
->stub_bfd
, len
);
4188 if (stub_entry
->output_name
== NULL
)
4191 goto error_ret_free_internal
;
4194 snprintf (stub_entry
->output_name
, len
, STUB_ENTRY_NAME
,
4197 stub_changed
= TRUE
;
4200 /* We're done with the internal relocs, free them. */
4201 if (elf_section_data (section
)->relocs
== NULL
)
4202 free (internal_relocs
);
4209 _bfd_aarch64_resize_stubs (htab
);
4211 /* Ask the linker to do its stuff. */
4212 (*htab
->layout_sections_again
) ();
4213 stub_changed
= FALSE
;
4218 error_ret_free_local
:
4222 /* Build all the stubs associated with the current output file. The
4223 stubs are kept in a hash table attached to the main linker hash
4224 table. We also set up the .plt entries for statically linked PIC
4225 functions here. This function is called via aarch64_elf_finish in the
4229 elfNN_aarch64_build_stubs (struct bfd_link_info
*info
)
4232 struct bfd_hash_table
*table
;
4233 struct elf_aarch64_link_hash_table
*htab
;
4235 htab
= elf_aarch64_hash_table (info
);
4237 for (stub_sec
= htab
->stub_bfd
->sections
;
4238 stub_sec
!= NULL
; stub_sec
= stub_sec
->next
)
4242 /* Ignore non-stub sections. */
4243 if (!strstr (stub_sec
->name
, STUB_SUFFIX
))
4246 /* Allocate memory to hold the linker stubs. */
4247 size
= stub_sec
->size
;
4248 stub_sec
->contents
= bfd_zalloc (htab
->stub_bfd
, size
);
4249 if (stub_sec
->contents
== NULL
&& size
!= 0)
4253 bfd_putl32 (0x14000000 | (size
>> 2), stub_sec
->contents
);
4254 stub_sec
->size
+= 4;
4257 /* Build the stubs as directed by the stub hash table. */
4258 table
= &htab
->stub_hash_table
;
4259 bfd_hash_traverse (table
, aarch64_build_one_stub
, info
);
4265 /* Add an entry to the code/data map for section SEC. */
4268 elfNN_aarch64_section_map_add (asection
*sec
, char type
, bfd_vma vma
)
4270 struct _aarch64_elf_section_data
*sec_data
=
4271 elf_aarch64_section_data (sec
);
4272 unsigned int newidx
;
4274 if (sec_data
->map
== NULL
)
4276 sec_data
->map
= bfd_malloc (sizeof (elf_aarch64_section_map
));
4277 sec_data
->mapcount
= 0;
4278 sec_data
->mapsize
= 1;
4281 newidx
= sec_data
->mapcount
++;
4283 if (sec_data
->mapcount
> sec_data
->mapsize
)
4285 sec_data
->mapsize
*= 2;
4286 sec_data
->map
= bfd_realloc_or_free
4287 (sec_data
->map
, sec_data
->mapsize
* sizeof (elf_aarch64_section_map
));
4292 sec_data
->map
[newidx
].vma
= vma
;
4293 sec_data
->map
[newidx
].type
= type
;
4298 /* Initialise maps of insn/data for input BFDs. */
4300 bfd_elfNN_aarch64_init_maps (bfd
*abfd
)
4302 Elf_Internal_Sym
*isymbuf
;
4303 Elf_Internal_Shdr
*hdr
;
4304 unsigned int i
, localsyms
;
4306 /* Make sure that we are dealing with an AArch64 elf binary. */
4307 if (!is_aarch64_elf (abfd
))
4310 if ((abfd
->flags
& DYNAMIC
) != 0)
4313 hdr
= &elf_symtab_hdr (abfd
);
4314 localsyms
= hdr
->sh_info
;
4316 /* Obtain a buffer full of symbols for this BFD. The hdr->sh_info field
4317 should contain the number of local symbols, which should come before any
4318 global symbols. Mapping symbols are always local. */
4319 isymbuf
= bfd_elf_get_elf_syms (abfd
, hdr
, localsyms
, 0, NULL
, NULL
, NULL
);
4321 /* No internal symbols read? Skip this BFD. */
4322 if (isymbuf
== NULL
)
4325 for (i
= 0; i
< localsyms
; i
++)
4327 Elf_Internal_Sym
*isym
= &isymbuf
[i
];
4328 asection
*sec
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
4331 if (sec
!= NULL
&& ELF_ST_BIND (isym
->st_info
) == STB_LOCAL
)
4333 name
= bfd_elf_string_from_elf_section (abfd
,
4337 if (bfd_is_aarch64_special_symbol_name
4338 (name
, BFD_AARCH64_SPECIAL_SYM_TYPE_MAP
))
4339 elfNN_aarch64_section_map_add (sec
, name
[1], isym
->st_value
);
4344 /* Set option values needed during linking. */
4346 bfd_elfNN_aarch64_set_options (struct bfd
*output_bfd
,
4347 struct bfd_link_info
*link_info
,
4349 int no_wchar_warn
, int pic_veneer
,
4350 int fix_erratum_835769
,
4351 int fix_erratum_843419
,
4352 int no_apply_dynamic_relocs
)
4354 struct elf_aarch64_link_hash_table
*globals
;
4356 globals
= elf_aarch64_hash_table (link_info
);
4357 globals
->pic_veneer
= pic_veneer
;
4358 globals
->fix_erratum_835769
= fix_erratum_835769
;
4359 globals
->fix_erratum_843419
= fix_erratum_843419
;
4360 globals
->fix_erratum_843419_adr
= TRUE
;
4361 globals
->no_apply_dynamic_relocs
= no_apply_dynamic_relocs
;
4363 BFD_ASSERT (is_aarch64_elf (output_bfd
));
4364 elf_aarch64_tdata (output_bfd
)->no_enum_size_warning
= no_enum_warn
;
4365 elf_aarch64_tdata (output_bfd
)->no_wchar_size_warning
= no_wchar_warn
;
4369 aarch64_calculate_got_entry_vma (struct elf_link_hash_entry
*h
,
4370 struct elf_aarch64_link_hash_table
4371 *globals
, struct bfd_link_info
*info
,
4372 bfd_vma value
, bfd
*output_bfd
,
4373 bfd_boolean
*unresolved_reloc_p
)
4375 bfd_vma off
= (bfd_vma
) - 1;
4376 asection
*basegot
= globals
->root
.sgot
;
4377 bfd_boolean dyn
= globals
->root
.dynamic_sections_created
;
4381 BFD_ASSERT (basegot
!= NULL
);
4382 off
= h
->got
.offset
;
4383 BFD_ASSERT (off
!= (bfd_vma
) - 1);
4384 if (!WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, bfd_link_pic (info
), h
)
4385 || (bfd_link_pic (info
)
4386 && SYMBOL_REFERENCES_LOCAL (info
, h
))
4387 || (ELF_ST_VISIBILITY (h
->other
)
4388 && h
->root
.type
== bfd_link_hash_undefweak
))
4390 /* This is actually a static link, or it is a -Bsymbolic link
4391 and the symbol is defined locally. We must initialize this
4392 entry in the global offset table. Since the offset must
4393 always be a multiple of 8 (4 in the case of ILP32), we use
4394 the least significant bit to record whether we have
4395 initialized it already.
4396 When doing a dynamic link, we create a .rel(a).got relocation
4397 entry to initialize the value. This is done in the
4398 finish_dynamic_symbol routine. */
4403 bfd_put_NN (output_bfd
, value
, basegot
->contents
+ off
);
4408 *unresolved_reloc_p
= FALSE
;
4410 off
= off
+ basegot
->output_section
->vma
+ basegot
->output_offset
;
4416 /* Change R_TYPE to a more efficient access model where possible,
4417 return the new reloc type. */
4419 static bfd_reloc_code_real_type
4420 aarch64_tls_transition_without_check (bfd_reloc_code_real_type r_type
,
4421 struct elf_link_hash_entry
*h
)
4423 bfd_boolean is_local
= h
== NULL
;
4427 case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21
:
4428 case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21
:
4430 ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1
4431 : BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21
);
4433 case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21
:
4435 ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC
4438 case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19
:
4440 ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1
4441 : BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19
);
4443 case BFD_RELOC_AARCH64_TLSDESC_LDR
:
4445 ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC
4446 : BFD_RELOC_AARCH64_NONE
);
4448 case BFD_RELOC_AARCH64_TLSDESC_OFF_G0_NC
:
4450 ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1_NC
4451 : BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G0_NC
);
4453 case BFD_RELOC_AARCH64_TLSDESC_OFF_G1
:
4455 ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G2
4456 : BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G1
);
4458 case BFD_RELOC_AARCH64_TLSDESC_LDNN_LO12_NC
:
4459 case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC
:
4461 ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC
4462 : BFD_RELOC_AARCH64_TLSIE_LDNN_GOTTPREL_LO12_NC
);
4464 case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21
:
4465 return is_local
? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1
: r_type
;
4467 case BFD_RELOC_AARCH64_TLSIE_LDNN_GOTTPREL_LO12_NC
:
4468 return is_local
? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC
: r_type
;
4470 case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19
:
4473 case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21
:
4475 ? BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_HI12
4476 : BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19
);
4478 case BFD_RELOC_AARCH64_TLSDESC_ADD
:
4479 case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12_NC
:
4480 case BFD_RELOC_AARCH64_TLSDESC_CALL
:
4481 /* Instructions with these relocations will become NOPs. */
4482 return BFD_RELOC_AARCH64_NONE
;
4484 case BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC
:
4485 case BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21
:
4486 case BFD_RELOC_AARCH64_TLSLD_ADR_PREL21
:
4487 return is_local
? BFD_RELOC_AARCH64_NONE
: r_type
;
4490 case BFD_RELOC_AARCH64_TLSGD_MOVW_G0_NC
:
4492 ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1_NC
4493 : BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G0_NC
;
4495 case BFD_RELOC_AARCH64_TLSGD_MOVW_G1
:
4497 ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G2
4498 : BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G1
;
4509 aarch64_reloc_got_type (bfd_reloc_code_real_type r_type
)
4513 case BFD_RELOC_AARCH64_ADR_GOT_PAGE
:
4514 case BFD_RELOC_AARCH64_GOT_LD_PREL19
:
4515 case BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14
:
4516 case BFD_RELOC_AARCH64_LD32_GOT_LO12_NC
:
4517 case BFD_RELOC_AARCH64_LD64_GOTOFF_LO15
:
4518 case BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15
:
4519 case BFD_RELOC_AARCH64_LD64_GOT_LO12_NC
:
4520 case BFD_RELOC_AARCH64_MOVW_GOTOFF_G0_NC
:
4521 case BFD_RELOC_AARCH64_MOVW_GOTOFF_G1
:
4524 case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC
:
4525 case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21
:
4526 case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21
:
4527 case BFD_RELOC_AARCH64_TLSGD_MOVW_G0_NC
:
4528 case BFD_RELOC_AARCH64_TLSGD_MOVW_G1
:
4529 case BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC
:
4530 case BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21
:
4531 case BFD_RELOC_AARCH64_TLSLD_ADR_PREL21
:
4534 case BFD_RELOC_AARCH64_TLSDESC_ADD
:
4535 case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12_NC
:
4536 case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21
:
4537 case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21
:
4538 case BFD_RELOC_AARCH64_TLSDESC_CALL
:
4539 case BFD_RELOC_AARCH64_TLSDESC_LD32_LO12_NC
:
4540 case BFD_RELOC_AARCH64_TLSDESC_LD64_LO12_NC
:
4541 case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19
:
4542 case BFD_RELOC_AARCH64_TLSDESC_LDR
:
4543 case BFD_RELOC_AARCH64_TLSDESC_OFF_G0_NC
:
4544 case BFD_RELOC_AARCH64_TLSDESC_OFF_G1
:
4545 return GOT_TLSDESC_GD
;
4547 case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21
:
4548 case BFD_RELOC_AARCH64_TLSIE_LD32_GOTTPREL_LO12_NC
:
4549 case BFD_RELOC_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC
:
4550 case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19
:
4551 case BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G0_NC
:
4552 case BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G1
:
4562 aarch64_can_relax_tls (bfd
*input_bfd
,
4563 struct bfd_link_info
*info
,
4564 bfd_reloc_code_real_type r_type
,
4565 struct elf_link_hash_entry
*h
,
4566 unsigned long r_symndx
)
4568 unsigned int symbol_got_type
;
4569 unsigned int reloc_got_type
;
4571 if (! IS_AARCH64_TLS_RELAX_RELOC (r_type
))
4574 symbol_got_type
= elfNN_aarch64_symbol_got_type (h
, input_bfd
, r_symndx
);
4575 reloc_got_type
= aarch64_reloc_got_type (r_type
);
4577 if (symbol_got_type
== GOT_TLS_IE
&& GOT_TLS_GD_ANY_P (reloc_got_type
))
4580 if (bfd_link_pic (info
))
4583 if (h
&& h
->root
.type
== bfd_link_hash_undefweak
)
4589 /* Given the relocation code R_TYPE, return the relaxed bfd reloc
4592 static bfd_reloc_code_real_type
4593 aarch64_tls_transition (bfd
*input_bfd
,
4594 struct bfd_link_info
*info
,
4595 unsigned int r_type
,
4596 struct elf_link_hash_entry
*h
,
4597 unsigned long r_symndx
)
4599 bfd_reloc_code_real_type bfd_r_type
4600 = elfNN_aarch64_bfd_reloc_from_type (r_type
);
4602 if (! aarch64_can_relax_tls (input_bfd
, info
, bfd_r_type
, h
, r_symndx
))
4605 return aarch64_tls_transition_without_check (bfd_r_type
, h
);
4608 /* Return the base VMA address which should be subtracted from real addresses
4609 when resolving R_AARCH64_TLS_DTPREL relocation. */
4612 dtpoff_base (struct bfd_link_info
*info
)
4614 /* If tls_sec is NULL, we should have signalled an error already. */
4615 BFD_ASSERT (elf_hash_table (info
)->tls_sec
!= NULL
);
4616 return elf_hash_table (info
)->tls_sec
->vma
;
4619 /* Return the base VMA address which should be subtracted from real addresses
4620 when resolving R_AARCH64_TLS_GOTTPREL64 relocations. */
4623 tpoff_base (struct bfd_link_info
*info
)
4625 struct elf_link_hash_table
*htab
= elf_hash_table (info
);
4627 /* If tls_sec is NULL, we should have signalled an error already. */
4628 BFD_ASSERT (htab
->tls_sec
!= NULL
);
4630 bfd_vma base
= align_power ((bfd_vma
) TCB_SIZE
,
4631 htab
->tls_sec
->alignment_power
);
4632 return htab
->tls_sec
->vma
- base
;
4636 symbol_got_offset_ref (bfd
*input_bfd
, struct elf_link_hash_entry
*h
,
4637 unsigned long r_symndx
)
4639 /* Calculate the address of the GOT entry for symbol
4640 referred to in h. */
4642 return &h
->got
.offset
;
4646 struct elf_aarch64_local_symbol
*l
;
4648 l
= elf_aarch64_locals (input_bfd
);
4649 return &l
[r_symndx
].got_offset
;
4654 symbol_got_offset_mark (bfd
*input_bfd
, struct elf_link_hash_entry
*h
,
4655 unsigned long r_symndx
)
4658 p
= symbol_got_offset_ref (input_bfd
, h
, r_symndx
);
4663 symbol_got_offset_mark_p (bfd
*input_bfd
, struct elf_link_hash_entry
*h
,
4664 unsigned long r_symndx
)
4667 value
= * symbol_got_offset_ref (input_bfd
, h
, r_symndx
);
4672 symbol_got_offset (bfd
*input_bfd
, struct elf_link_hash_entry
*h
,
4673 unsigned long r_symndx
)
4676 value
= * symbol_got_offset_ref (input_bfd
, h
, r_symndx
);
4682 symbol_tlsdesc_got_offset_ref (bfd
*input_bfd
, struct elf_link_hash_entry
*h
,
4683 unsigned long r_symndx
)
4685 /* Calculate the address of the GOT entry for symbol
4686 referred to in h. */
4689 struct elf_aarch64_link_hash_entry
*eh
;
4690 eh
= (struct elf_aarch64_link_hash_entry
*) h
;
4691 return &eh
->tlsdesc_got_jump_table_offset
;
4696 struct elf_aarch64_local_symbol
*l
;
4698 l
= elf_aarch64_locals (input_bfd
);
4699 return &l
[r_symndx
].tlsdesc_got_jump_table_offset
;
4704 symbol_tlsdesc_got_offset_mark (bfd
*input_bfd
, struct elf_link_hash_entry
*h
,
4705 unsigned long r_symndx
)
4708 p
= symbol_tlsdesc_got_offset_ref (input_bfd
, h
, r_symndx
);
4713 symbol_tlsdesc_got_offset_mark_p (bfd
*input_bfd
,
4714 struct elf_link_hash_entry
*h
,
4715 unsigned long r_symndx
)
4718 value
= * symbol_tlsdesc_got_offset_ref (input_bfd
, h
, r_symndx
);
4723 symbol_tlsdesc_got_offset (bfd
*input_bfd
, struct elf_link_hash_entry
*h
,
4724 unsigned long r_symndx
)
4727 value
= * symbol_tlsdesc_got_offset_ref (input_bfd
, h
, r_symndx
);
4732 /* Data for make_branch_to_erratum_835769_stub(). */
4734 struct erratum_835769_branch_to_stub_data
4736 struct bfd_link_info
*info
;
4737 asection
*output_section
;
4741 /* Helper to insert branches to erratum 835769 stubs in the right
4742 places for a particular section. */
4745 make_branch_to_erratum_835769_stub (struct bfd_hash_entry
*gen_entry
,
4748 struct elf_aarch64_stub_hash_entry
*stub_entry
;
4749 struct erratum_835769_branch_to_stub_data
*data
;
4751 unsigned long branch_insn
= 0;
4752 bfd_vma veneered_insn_loc
, veneer_entry_loc
;
4753 bfd_signed_vma branch_offset
;
4754 unsigned int target
;
4757 stub_entry
= (struct elf_aarch64_stub_hash_entry
*) gen_entry
;
4758 data
= (struct erratum_835769_branch_to_stub_data
*) in_arg
;
4760 if (stub_entry
->target_section
!= data
->output_section
4761 || stub_entry
->stub_type
!= aarch64_stub_erratum_835769_veneer
)
4764 contents
= data
->contents
;
4765 veneered_insn_loc
= stub_entry
->target_section
->output_section
->vma
4766 + stub_entry
->target_section
->output_offset
4767 + stub_entry
->target_value
;
4768 veneer_entry_loc
= stub_entry
->stub_sec
->output_section
->vma
4769 + stub_entry
->stub_sec
->output_offset
4770 + stub_entry
->stub_offset
;
4771 branch_offset
= veneer_entry_loc
- veneered_insn_loc
;
4773 abfd
= stub_entry
->target_section
->owner
;
4774 if (!aarch64_valid_branch_p (veneer_entry_loc
, veneered_insn_loc
))
4776 (_("%B: error: Erratum 835769 stub out "
4777 "of range (input file too large)"), abfd
);
4779 target
= stub_entry
->target_value
;
4780 branch_insn
= 0x14000000;
4781 branch_offset
>>= 2;
4782 branch_offset
&= 0x3ffffff;
4783 branch_insn
|= branch_offset
;
4784 bfd_putl32 (branch_insn
, &contents
[target
]);
4791 _bfd_aarch64_erratum_843419_branch_to_stub (struct bfd_hash_entry
*gen_entry
,
4794 struct elf_aarch64_stub_hash_entry
*stub_entry
4795 = (struct elf_aarch64_stub_hash_entry
*) gen_entry
;
4796 struct erratum_835769_branch_to_stub_data
*data
4797 = (struct erratum_835769_branch_to_stub_data
*) in_arg
;
4798 struct bfd_link_info
*info
;
4799 struct elf_aarch64_link_hash_table
*htab
;
4807 contents
= data
->contents
;
4808 section
= data
->output_section
;
4810 htab
= elf_aarch64_hash_table (info
);
4812 if (stub_entry
->target_section
!= section
4813 || stub_entry
->stub_type
!= aarch64_stub_erratum_843419_veneer
)
4816 insn
= bfd_getl32 (contents
+ stub_entry
->target_value
);
4818 stub_entry
->stub_sec
->contents
+ stub_entry
->stub_offset
);
4820 place
= (section
->output_section
->vma
+ section
->output_offset
4821 + stub_entry
->adrp_offset
);
4822 insn
= bfd_getl32 (contents
+ stub_entry
->adrp_offset
);
4824 if ((insn
& AARCH64_ADRP_OP_MASK
) != AARCH64_ADRP_OP
)
4827 bfd_signed_vma imm
=
4828 (_bfd_aarch64_sign_extend
4829 ((bfd_vma
) _bfd_aarch64_decode_adrp_imm (insn
) << 12, 33)
4832 if (htab
->fix_erratum_843419_adr
4833 && (imm
>= AARCH64_MIN_ADRP_IMM
&& imm
<= AARCH64_MAX_ADRP_IMM
))
4835 insn
= (_bfd_aarch64_reencode_adr_imm (AARCH64_ADR_OP
, imm
)
4836 | AARCH64_RT (insn
));
4837 bfd_putl32 (insn
, contents
+ stub_entry
->adrp_offset
);
4841 bfd_vma veneered_insn_loc
;
4842 bfd_vma veneer_entry_loc
;
4843 bfd_signed_vma branch_offset
;
4844 uint32_t branch_insn
;
4846 veneered_insn_loc
= stub_entry
->target_section
->output_section
->vma
4847 + stub_entry
->target_section
->output_offset
4848 + stub_entry
->target_value
;
4849 veneer_entry_loc
= stub_entry
->stub_sec
->output_section
->vma
4850 + stub_entry
->stub_sec
->output_offset
4851 + stub_entry
->stub_offset
;
4852 branch_offset
= veneer_entry_loc
- veneered_insn_loc
;
4854 abfd
= stub_entry
->target_section
->owner
;
4855 if (!aarch64_valid_branch_p (veneer_entry_loc
, veneered_insn_loc
))
4857 (_("%B: error: Erratum 843419 stub out "
4858 "of range (input file too large)"), abfd
);
4860 branch_insn
= 0x14000000;
4861 branch_offset
>>= 2;
4862 branch_offset
&= 0x3ffffff;
4863 branch_insn
|= branch_offset
;
4864 bfd_putl32 (branch_insn
, contents
+ stub_entry
->target_value
);
4871 elfNN_aarch64_write_section (bfd
*output_bfd ATTRIBUTE_UNUSED
,
4872 struct bfd_link_info
*link_info
,
4877 struct elf_aarch64_link_hash_table
*globals
=
4878 elf_aarch64_hash_table (link_info
);
4880 if (globals
== NULL
)
4883 /* Fix code to point to erratum 835769 stubs. */
4884 if (globals
->fix_erratum_835769
)
4886 struct erratum_835769_branch_to_stub_data data
;
4888 data
.info
= link_info
;
4889 data
.output_section
= sec
;
4890 data
.contents
= contents
;
4891 bfd_hash_traverse (&globals
->stub_hash_table
,
4892 make_branch_to_erratum_835769_stub
, &data
);
4895 if (globals
->fix_erratum_843419
)
4897 struct erratum_835769_branch_to_stub_data data
;
4899 data
.info
= link_info
;
4900 data
.output_section
= sec
;
4901 data
.contents
= contents
;
4902 bfd_hash_traverse (&globals
->stub_hash_table
,
4903 _bfd_aarch64_erratum_843419_branch_to_stub
, &data
);
4909 /* Perform a relocation as part of a final link. The input relocation type
4910 should be TLS relaxed. */
4912 static bfd_reloc_status_type
4913 elfNN_aarch64_final_link_relocate (reloc_howto_type
*howto
,
4916 asection
*input_section
,
4918 Elf_Internal_Rela
*rel
,
4920 struct bfd_link_info
*info
,
4922 struct elf_link_hash_entry
*h
,
4923 bfd_boolean
*unresolved_reloc_p
,
4924 bfd_boolean save_addend
,
4925 bfd_vma
*saved_addend
,
4926 Elf_Internal_Sym
*sym
)
4928 Elf_Internal_Shdr
*symtab_hdr
;
4929 unsigned int r_type
= howto
->type
;
4930 bfd_reloc_code_real_type bfd_r_type
4931 = elfNN_aarch64_bfd_reloc_from_howto (howto
);
4932 unsigned long r_symndx
;
4933 bfd_byte
*hit_data
= contents
+ rel
->r_offset
;
4935 bfd_signed_vma signed_addend
;
4936 struct elf_aarch64_link_hash_table
*globals
;
4937 bfd_boolean weak_undef_p
;
4940 globals
= elf_aarch64_hash_table (info
);
4942 symtab_hdr
= &elf_symtab_hdr (input_bfd
);
4944 BFD_ASSERT (is_aarch64_elf (input_bfd
));
4946 r_symndx
= ELFNN_R_SYM (rel
->r_info
);
4948 place
= input_section
->output_section
->vma
4949 + input_section
->output_offset
+ rel
->r_offset
;
4951 /* Get addend, accumulating the addend for consecutive relocs
4952 which refer to the same offset. */
4953 signed_addend
= saved_addend
? *saved_addend
: 0;
4954 signed_addend
+= rel
->r_addend
;
4956 weak_undef_p
= (h
? h
->root
.type
== bfd_link_hash_undefweak
4957 : bfd_is_und_section (sym_sec
));
4959 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle
4960 it here if it is defined in a non-shared object. */
4962 && h
->type
== STT_GNU_IFUNC
4969 if ((input_section
->flags
& SEC_ALLOC
) == 0
4970 || h
->plt
.offset
== (bfd_vma
) -1)
4973 /* STT_GNU_IFUNC symbol must go through PLT. */
4974 plt
= globals
->root
.splt
? globals
->root
.splt
: globals
->root
.iplt
;
4975 value
= (plt
->output_section
->vma
+ plt
->output_offset
+ h
->plt
.offset
);
4980 if (h
->root
.root
.string
)
4981 name
= h
->root
.root
.string
;
4983 name
= bfd_elf_sym_name (input_bfd
, symtab_hdr
, sym
,
4986 /* xgettext:c-format */
4987 (_("%B: relocation %s against STT_GNU_IFUNC "
4988 "symbol `%s' isn't handled by %s"), input_bfd
,
4989 howto
->name
, name
, __FUNCTION__
);
4990 bfd_set_error (bfd_error_bad_value
);
4993 case BFD_RELOC_AARCH64_NN
:
4994 if (rel
->r_addend
!= 0)
4996 if (h
->root
.root
.string
)
4997 name
= h
->root
.root
.string
;
4999 name
= bfd_elf_sym_name (input_bfd
, symtab_hdr
,
5002 /* xgettext:c-format */
5003 (_("%B: relocation %s against STT_GNU_IFUNC "
5004 "symbol `%s' has non-zero addend: %d"),
5005 input_bfd
, howto
->name
, name
, rel
->r_addend
);
5006 bfd_set_error (bfd_error_bad_value
);
5010 /* Generate dynamic relocation only when there is a
5011 non-GOT reference in a shared object. */
5012 if (bfd_link_pic (info
) && h
->non_got_ref
)
5014 Elf_Internal_Rela outrel
;
5017 /* Need a dynamic relocation to get the real function
5019 outrel
.r_offset
= _bfd_elf_section_offset (output_bfd
,
5023 if (outrel
.r_offset
== (bfd_vma
) -1
5024 || outrel
.r_offset
== (bfd_vma
) -2)
5027 outrel
.r_offset
+= (input_section
->output_section
->vma
5028 + input_section
->output_offset
);
5030 if (h
->dynindx
== -1
5032 || bfd_link_executable (info
))
5034 /* This symbol is resolved locally. */
5035 outrel
.r_info
= ELFNN_R_INFO (0, AARCH64_R (IRELATIVE
));
5036 outrel
.r_addend
= (h
->root
.u
.def
.value
5037 + h
->root
.u
.def
.section
->output_section
->vma
5038 + h
->root
.u
.def
.section
->output_offset
);
5042 outrel
.r_info
= ELFNN_R_INFO (h
->dynindx
, r_type
);
5043 outrel
.r_addend
= 0;
5046 sreloc
= globals
->root
.irelifunc
;
5047 elf_append_rela (output_bfd
, sreloc
, &outrel
);
5049 /* If this reloc is against an external symbol, we
5050 do not want to fiddle with the addend. Otherwise,
5051 we need to include the symbol value so that it
5052 becomes an addend for the dynamic reloc. For an
5053 internal symbol, we have updated addend. */
5054 return bfd_reloc_ok
;
5057 case BFD_RELOC_AARCH64_CALL26
:
5058 case BFD_RELOC_AARCH64_JUMP26
:
5059 value
= _bfd_aarch64_elf_resolve_relocation (bfd_r_type
, place
, value
,
5062 return _bfd_aarch64_elf_put_addend (input_bfd
, hit_data
, bfd_r_type
,
5064 case BFD_RELOC_AARCH64_ADR_GOT_PAGE
:
5065 case BFD_RELOC_AARCH64_GOT_LD_PREL19
:
5066 case BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14
:
5067 case BFD_RELOC_AARCH64_LD32_GOT_LO12_NC
:
5068 case BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15
:
5069 case BFD_RELOC_AARCH64_MOVW_GOTOFF_G0_NC
:
5070 case BFD_RELOC_AARCH64_MOVW_GOTOFF_G1
:
5071 case BFD_RELOC_AARCH64_LD64_GOTOFF_LO15
:
5072 case BFD_RELOC_AARCH64_LD64_GOT_LO12_NC
:
5073 base_got
= globals
->root
.sgot
;
5074 off
= h
->got
.offset
;
5076 if (base_got
== NULL
)
5079 if (off
== (bfd_vma
) -1)
5083 /* We can't use h->got.offset here to save state, or
5084 even just remember the offset, as finish_dynamic_symbol
5085 would use that as offset into .got. */
5087 if (globals
->root
.splt
!= NULL
)
5089 plt_index
= ((h
->plt
.offset
- globals
->plt_header_size
) /
5090 globals
->plt_entry_size
);
5091 off
= (plt_index
+ 3) * GOT_ENTRY_SIZE
;
5092 base_got
= globals
->root
.sgotplt
;
5096 plt_index
= h
->plt
.offset
/ globals
->plt_entry_size
;
5097 off
= plt_index
* GOT_ENTRY_SIZE
;
5098 base_got
= globals
->root
.igotplt
;
5101 if (h
->dynindx
== -1
5105 /* This references the local definition. We must
5106 initialize this entry in the global offset table.
5107 Since the offset must always be a multiple of 8,
5108 we use the least significant bit to record
5109 whether we have initialized it already.
5111 When doing a dynamic link, we create a .rela.got
5112 relocation entry to initialize the value. This
5113 is done in the finish_dynamic_symbol routine. */
5118 bfd_put_NN (output_bfd
, value
,
5119 base_got
->contents
+ off
);
5120 /* Note that this is harmless as -1 | 1 still is -1. */
5124 value
= (base_got
->output_section
->vma
5125 + base_got
->output_offset
+ off
);
5128 value
= aarch64_calculate_got_entry_vma (h
, globals
, info
,
5130 unresolved_reloc_p
);
5134 case BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14
:
5135 case BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15
:
5136 addend
= (globals
->root
.sgot
->output_section
->vma
5137 + globals
->root
.sgot
->output_offset
);
5139 case BFD_RELOC_AARCH64_MOVW_GOTOFF_G0_NC
:
5140 case BFD_RELOC_AARCH64_MOVW_GOTOFF_G1
:
5141 case BFD_RELOC_AARCH64_LD64_GOTOFF_LO15
:
5142 value
= (value
- globals
->root
.sgot
->output_section
->vma
5143 - globals
->root
.sgot
->output_offset
);
5148 value
= _bfd_aarch64_elf_resolve_relocation (bfd_r_type
, place
, value
,
5149 addend
, weak_undef_p
);
5150 return _bfd_aarch64_elf_put_addend (input_bfd
, hit_data
, bfd_r_type
, howto
, value
);
5151 case BFD_RELOC_AARCH64_ADD_LO12
:
5152 case BFD_RELOC_AARCH64_ADR_HI21_PCREL
:
5159 case BFD_RELOC_AARCH64_NONE
:
5160 case BFD_RELOC_AARCH64_TLSDESC_ADD
:
5161 case BFD_RELOC_AARCH64_TLSDESC_CALL
:
5162 case BFD_RELOC_AARCH64_TLSDESC_LDR
:
5163 *unresolved_reloc_p
= FALSE
;
5164 return bfd_reloc_ok
;
5166 case BFD_RELOC_AARCH64_NN
:
5168 /* When generating a shared object or relocatable executable, these
5169 relocations are copied into the output file to be resolved at
5171 if (((bfd_link_pic (info
) == TRUE
)
5172 || globals
->root
.is_relocatable_executable
)
5173 && (input_section
->flags
& SEC_ALLOC
)
5175 || ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
5176 || h
->root
.type
!= bfd_link_hash_undefweak
))
5178 Elf_Internal_Rela outrel
;
5180 bfd_boolean skip
, relocate
;
5183 *unresolved_reloc_p
= FALSE
;
5188 outrel
.r_addend
= signed_addend
;
5190 _bfd_elf_section_offset (output_bfd
, info
, input_section
,
5192 if (outrel
.r_offset
== (bfd_vma
) - 1)
5194 else if (outrel
.r_offset
== (bfd_vma
) - 2)
5200 outrel
.r_offset
+= (input_section
->output_section
->vma
5201 + input_section
->output_offset
);
5204 memset (&outrel
, 0, sizeof outrel
);
5207 && (!bfd_link_pic (info
)
5208 || !(bfd_link_pie (info
)
5209 || SYMBOLIC_BIND (info
, h
))
5210 || !h
->def_regular
))
5211 outrel
.r_info
= ELFNN_R_INFO (h
->dynindx
, r_type
);
5216 /* On SVR4-ish systems, the dynamic loader cannot
5217 relocate the text and data segments independently,
5218 so the symbol does not matter. */
5220 relocate
= globals
->no_apply_dynamic_relocs
? FALSE
: TRUE
;
5221 outrel
.r_info
= ELFNN_R_INFO (symbol
, AARCH64_R (RELATIVE
));
5222 outrel
.r_addend
+= value
;
5225 sreloc
= elf_section_data (input_section
)->sreloc
;
5226 if (sreloc
== NULL
|| sreloc
->contents
== NULL
)
5227 return bfd_reloc_notsupported
;
5229 loc
= sreloc
->contents
+ sreloc
->reloc_count
++ * RELOC_SIZE (globals
);
5230 bfd_elfNN_swap_reloca_out (output_bfd
, &outrel
, loc
);
5232 if (sreloc
->reloc_count
* RELOC_SIZE (globals
) > sreloc
->size
)
5234 /* Sanity to check that we have previously allocated
5235 sufficient space in the relocation section for the
5236 number of relocations we actually want to emit. */
5240 /* If this reloc is against an external symbol, we do not want to
5241 fiddle with the addend. Otherwise, we need to include the symbol
5242 value so that it becomes an addend for the dynamic reloc. */
5244 return bfd_reloc_ok
;
5246 return _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
5247 contents
, rel
->r_offset
, value
,
5251 value
+= signed_addend
;
5254 case BFD_RELOC_AARCH64_CALL26
:
5255 case BFD_RELOC_AARCH64_JUMP26
:
5257 asection
*splt
= globals
->root
.splt
;
5258 bfd_boolean via_plt_p
=
5259 splt
!= NULL
&& h
!= NULL
&& h
->plt
.offset
!= (bfd_vma
) - 1;
5261 /* A call to an undefined weak symbol is converted to a jump to
5262 the next instruction unless a PLT entry will be created.
5263 The jump to the next instruction is optimized as a NOP.
5264 Do the same for local undefined symbols. */
5265 if (weak_undef_p
&& ! via_plt_p
)
5267 bfd_putl32 (INSN_NOP
, hit_data
);
5268 return bfd_reloc_ok
;
5271 /* If the call goes through a PLT entry, make sure to
5272 check distance to the right destination address. */
5274 value
= (splt
->output_section
->vma
5275 + splt
->output_offset
+ h
->plt
.offset
);
5277 /* Check if a stub has to be inserted because the destination
5279 struct elf_aarch64_stub_hash_entry
*stub_entry
= NULL
;
5281 /* If the branch destination is directed to plt stub, "value" will be
5282 the final destination, otherwise we should plus signed_addend, it may
5283 contain non-zero value, for example call to local function symbol
5284 which are turned into "sec_sym + sec_off", and sec_off is kept in
5286 if (! aarch64_valid_branch_p (via_plt_p
? value
: value
+ signed_addend
,
5288 /* The target is out of reach, so redirect the branch to
5289 the local stub for this function. */
5290 stub_entry
= elfNN_aarch64_get_stub_entry (input_section
, sym_sec
, h
,
5292 if (stub_entry
!= NULL
)
5294 value
= (stub_entry
->stub_offset
5295 + stub_entry
->stub_sec
->output_offset
5296 + stub_entry
->stub_sec
->output_section
->vma
);
5298 /* We have redirected the destination to stub entry address,
5299 so ignore any addend record in the original rela entry. */
5303 value
= _bfd_aarch64_elf_resolve_relocation (bfd_r_type
, place
, value
,
5304 signed_addend
, weak_undef_p
);
5305 *unresolved_reloc_p
= FALSE
;
5308 case BFD_RELOC_AARCH64_16_PCREL
:
5309 case BFD_RELOC_AARCH64_32_PCREL
:
5310 case BFD_RELOC_AARCH64_64_PCREL
:
5311 case BFD_RELOC_AARCH64_ADR_HI21_NC_PCREL
:
5312 case BFD_RELOC_AARCH64_ADR_HI21_PCREL
:
5313 case BFD_RELOC_AARCH64_ADR_LO21_PCREL
:
5314 case BFD_RELOC_AARCH64_LD_LO19_PCREL
:
5315 if (bfd_link_pic (info
)
5316 && (input_section
->flags
& SEC_ALLOC
) != 0
5317 && (input_section
->flags
& SEC_READONLY
) != 0
5321 int howto_index
= bfd_r_type
- BFD_RELOC_AARCH64_RELOC_START
;
5324 /* xgettext:c-format */
5325 (_("%B: relocation %s against external symbol `%s' can not be used"
5326 " when making a shared object; recompile with -fPIC"),
5327 input_bfd
, elfNN_aarch64_howto_table
[howto_index
].name
,
5328 h
->root
.root
.string
);
5329 bfd_set_error (bfd_error_bad_value
);
5334 case BFD_RELOC_AARCH64_16
:
5336 case BFD_RELOC_AARCH64_32
:
5338 case BFD_RELOC_AARCH64_ADD_LO12
:
5339 case BFD_RELOC_AARCH64_BRANCH19
:
5340 case BFD_RELOC_AARCH64_LDST128_LO12
:
5341 case BFD_RELOC_AARCH64_LDST16_LO12
:
5342 case BFD_RELOC_AARCH64_LDST32_LO12
:
5343 case BFD_RELOC_AARCH64_LDST64_LO12
:
5344 case BFD_RELOC_AARCH64_LDST8_LO12
:
5345 case BFD_RELOC_AARCH64_MOVW_G0
:
5346 case BFD_RELOC_AARCH64_MOVW_G0_NC
:
5347 case BFD_RELOC_AARCH64_MOVW_G0_S
:
5348 case BFD_RELOC_AARCH64_MOVW_G1
:
5349 case BFD_RELOC_AARCH64_MOVW_G1_NC
:
5350 case BFD_RELOC_AARCH64_MOVW_G1_S
:
5351 case BFD_RELOC_AARCH64_MOVW_G2
:
5352 case BFD_RELOC_AARCH64_MOVW_G2_NC
:
5353 case BFD_RELOC_AARCH64_MOVW_G2_S
:
5354 case BFD_RELOC_AARCH64_MOVW_G3
:
5355 case BFD_RELOC_AARCH64_TSTBR14
:
5356 value
= _bfd_aarch64_elf_resolve_relocation (bfd_r_type
, place
, value
,
5357 signed_addend
, weak_undef_p
);
5360 case BFD_RELOC_AARCH64_ADR_GOT_PAGE
:
5361 case BFD_RELOC_AARCH64_GOT_LD_PREL19
:
5362 case BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14
:
5363 case BFD_RELOC_AARCH64_LD32_GOT_LO12_NC
:
5364 case BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15
:
5365 case BFD_RELOC_AARCH64_LD64_GOT_LO12_NC
:
5366 if (globals
->root
.sgot
== NULL
)
5367 BFD_ASSERT (h
!= NULL
);
5372 value
= aarch64_calculate_got_entry_vma (h
, globals
, info
, value
,
5374 unresolved_reloc_p
);
5375 if (bfd_r_type
== BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15
5376 || bfd_r_type
== BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14
)
5377 addend
= (globals
->root
.sgot
->output_section
->vma
5378 + globals
->root
.sgot
->output_offset
);
5379 value
= _bfd_aarch64_elf_resolve_relocation (bfd_r_type
, place
, value
,
5380 addend
, weak_undef_p
);
5385 struct elf_aarch64_local_symbol
*locals
5386 = elf_aarch64_locals (input_bfd
);
5390 int howto_index
= bfd_r_type
- BFD_RELOC_AARCH64_RELOC_START
;
5392 /* xgettext:c-format */
5393 (_("%B: Local symbol descriptor table be NULL when applying "
5394 "relocation %s against local symbol"),
5395 input_bfd
, elfNN_aarch64_howto_table
[howto_index
].name
);
5399 off
= symbol_got_offset (input_bfd
, h
, r_symndx
);
5400 base_got
= globals
->root
.sgot
;
5401 bfd_vma got_entry_addr
= (base_got
->output_section
->vma
5402 + base_got
->output_offset
+ off
);
5404 if (!symbol_got_offset_mark_p (input_bfd
, h
, r_symndx
))
5406 bfd_put_64 (output_bfd
, value
, base_got
->contents
+ off
);
5408 if (bfd_link_pic (info
))
5411 Elf_Internal_Rela outrel
;
5413 /* For local symbol, we have done absolute relocation in static
5414 linking stageh. While for share library, we need to update
5415 the content of GOT entry according to the share objects
5416 loading base address. So we need to generate a
5417 R_AARCH64_RELATIVE reloc for dynamic linker. */
5418 s
= globals
->root
.srelgot
;
5422 outrel
.r_offset
= got_entry_addr
;
5423 outrel
.r_info
= ELFNN_R_INFO (0, AARCH64_R (RELATIVE
));
5424 outrel
.r_addend
= value
;
5425 elf_append_rela (output_bfd
, s
, &outrel
);
5428 symbol_got_offset_mark (input_bfd
, h
, r_symndx
);
5431 /* Update the relocation value to GOT entry addr as we have transformed
5432 the direct data access into indirect data access through GOT. */
5433 value
= got_entry_addr
;
5435 if (bfd_r_type
== BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15
5436 || bfd_r_type
== BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14
)
5437 addend
= base_got
->output_section
->vma
+ base_got
->output_offset
;
5439 value
= _bfd_aarch64_elf_resolve_relocation (bfd_r_type
, place
, value
,
5440 addend
, weak_undef_p
);
5445 case BFD_RELOC_AARCH64_LD64_GOTOFF_LO15
:
5446 case BFD_RELOC_AARCH64_MOVW_GOTOFF_G0_NC
:
5447 case BFD_RELOC_AARCH64_MOVW_GOTOFF_G1
:
5449 value
= aarch64_calculate_got_entry_vma (h
, globals
, info
, value
,
5451 unresolved_reloc_p
);
5454 struct elf_aarch64_local_symbol
*locals
5455 = elf_aarch64_locals (input_bfd
);
5459 int howto_index
= bfd_r_type
- BFD_RELOC_AARCH64_RELOC_START
;
5461 /* xgettext:c-format */
5462 (_("%B: Local symbol descriptor table be NULL when applying "
5463 "relocation %s against local symbol"),
5464 input_bfd
, elfNN_aarch64_howto_table
[howto_index
].name
);
5468 off
= symbol_got_offset (input_bfd
, h
, r_symndx
);
5469 base_got
= globals
->root
.sgot
;
5470 if (base_got
== NULL
)
5473 bfd_vma got_entry_addr
= (base_got
->output_section
->vma
5474 + base_got
->output_offset
+ off
);
5476 if (!symbol_got_offset_mark_p (input_bfd
, h
, r_symndx
))
5478 bfd_put_64 (output_bfd
, value
, base_got
->contents
+ off
);
5480 if (bfd_link_pic (info
))
5483 Elf_Internal_Rela outrel
;
5485 /* For local symbol, we have done absolute relocation in static
5486 linking stage. While for share library, we need to update
5487 the content of GOT entry according to the share objects
5488 loading base address. So we need to generate a
5489 R_AARCH64_RELATIVE reloc for dynamic linker. */
5490 s
= globals
->root
.srelgot
;
5494 outrel
.r_offset
= got_entry_addr
;
5495 outrel
.r_info
= ELFNN_R_INFO (0, AARCH64_R (RELATIVE
));
5496 outrel
.r_addend
= value
;
5497 elf_append_rela (output_bfd
, s
, &outrel
);
5500 symbol_got_offset_mark (input_bfd
, h
, r_symndx
);
5504 /* Update the relocation value to GOT entry addr as we have transformed
5505 the direct data access into indirect data access through GOT. */
5506 value
= symbol_got_offset (input_bfd
, h
, r_symndx
);
5507 value
= _bfd_aarch64_elf_resolve_relocation (bfd_r_type
, place
, value
,
5509 *unresolved_reloc_p
= FALSE
;
5512 case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC
:
5513 case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21
:
5514 case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21
:
5515 case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21
:
5516 case BFD_RELOC_AARCH64_TLSIE_LD32_GOTTPREL_LO12_NC
:
5517 case BFD_RELOC_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC
:
5518 case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19
:
5519 case BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC
:
5520 case BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21
:
5521 case BFD_RELOC_AARCH64_TLSLD_ADR_PREL21
:
5522 if (globals
->root
.sgot
== NULL
)
5523 return bfd_reloc_notsupported
;
5525 value
= (symbol_got_offset (input_bfd
, h
, r_symndx
)
5526 + globals
->root
.sgot
->output_section
->vma
5527 + globals
->root
.sgot
->output_offset
);
5529 value
= _bfd_aarch64_elf_resolve_relocation (bfd_r_type
, place
, value
,
5531 *unresolved_reloc_p
= FALSE
;
5534 case BFD_RELOC_AARCH64_TLSGD_MOVW_G0_NC
:
5535 case BFD_RELOC_AARCH64_TLSGD_MOVW_G1
:
5536 case BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G0_NC
:
5537 case BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G1
:
5538 if (globals
->root
.sgot
== NULL
)
5539 return bfd_reloc_notsupported
;
5541 value
= symbol_got_offset (input_bfd
, h
, r_symndx
);
5542 value
= _bfd_aarch64_elf_resolve_relocation (bfd_r_type
, place
, value
,
5544 *unresolved_reloc_p
= FALSE
;
5547 case BFD_RELOC_AARCH64_TLSLD_ADD_DTPREL_HI12
:
5548 case BFD_RELOC_AARCH64_TLSLD_ADD_DTPREL_LO12
:
5549 case BFD_RELOC_AARCH64_TLSLD_ADD_DTPREL_LO12_NC
:
5550 case BFD_RELOC_AARCH64_TLSLD_LDST16_DTPREL_LO12
:
5551 case BFD_RELOC_AARCH64_TLSLD_LDST16_DTPREL_LO12_NC
:
5552 case BFD_RELOC_AARCH64_TLSLD_LDST32_DTPREL_LO12
:
5553 case BFD_RELOC_AARCH64_TLSLD_LDST32_DTPREL_LO12_NC
:
5554 case BFD_RELOC_AARCH64_TLSLD_LDST64_DTPREL_LO12
:
5555 case BFD_RELOC_AARCH64_TLSLD_LDST64_DTPREL_LO12_NC
:
5556 case BFD_RELOC_AARCH64_TLSLD_LDST8_DTPREL_LO12
:
5557 case BFD_RELOC_AARCH64_TLSLD_LDST8_DTPREL_LO12_NC
:
5558 case BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G0
:
5559 case BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G0_NC
:
5560 case BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G1
:
5561 case BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G1_NC
:
5562 case BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G2
:
5563 value
= _bfd_aarch64_elf_resolve_relocation (bfd_r_type
, place
, value
,
5564 signed_addend
- dtpoff_base (info
),
5568 case BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_HI12
:
5569 case BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_LO12
:
5570 case BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_LO12_NC
:
5571 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0
:
5572 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC
:
5573 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1
:
5574 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1_NC
:
5575 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G2
:
5576 value
= _bfd_aarch64_elf_resolve_relocation (bfd_r_type
, place
, value
,
5577 signed_addend
- tpoff_base (info
),
5579 *unresolved_reloc_p
= FALSE
;
5582 case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12_NC
:
5583 case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21
:
5584 case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21
:
5585 case BFD_RELOC_AARCH64_TLSDESC_LD32_LO12_NC
:
5586 case BFD_RELOC_AARCH64_TLSDESC_LD64_LO12_NC
:
5587 case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19
:
5588 if (globals
->root
.sgot
== NULL
)
5589 return bfd_reloc_notsupported
;
5590 value
= (symbol_tlsdesc_got_offset (input_bfd
, h
, r_symndx
)
5591 + globals
->root
.sgotplt
->output_section
->vma
5592 + globals
->root
.sgotplt
->output_offset
5593 + globals
->sgotplt_jump_table_size
);
5595 value
= _bfd_aarch64_elf_resolve_relocation (bfd_r_type
, place
, value
,
5597 *unresolved_reloc_p
= FALSE
;
5600 case BFD_RELOC_AARCH64_TLSDESC_OFF_G0_NC
:
5601 case BFD_RELOC_AARCH64_TLSDESC_OFF_G1
:
5602 if (globals
->root
.sgot
== NULL
)
5603 return bfd_reloc_notsupported
;
5605 value
= (symbol_tlsdesc_got_offset (input_bfd
, h
, r_symndx
)
5606 + globals
->root
.sgotplt
->output_section
->vma
5607 + globals
->root
.sgotplt
->output_offset
5608 + globals
->sgotplt_jump_table_size
);
5610 value
-= (globals
->root
.sgot
->output_section
->vma
5611 + globals
->root
.sgot
->output_offset
);
5613 value
= _bfd_aarch64_elf_resolve_relocation (bfd_r_type
, place
, value
,
5615 *unresolved_reloc_p
= FALSE
;
5619 return bfd_reloc_notsupported
;
5623 *saved_addend
= value
;
5625 /* Only apply the final relocation in a sequence. */
5627 return bfd_reloc_continue
;
5629 return _bfd_aarch64_elf_put_addend (input_bfd
, hit_data
, bfd_r_type
,
5633 /* Handle TLS relaxations. Relaxing is possible for symbols that use
5634 R_AARCH64_TLSDESC_ADR_{PAGE, LD64_LO12_NC, ADD_LO12_NC} during a static
5637 Return bfd_reloc_ok if we're done, bfd_reloc_continue if the caller
5638 is to then call final_link_relocate. Return other values in the
5641 static bfd_reloc_status_type
5642 elfNN_aarch64_tls_relax (struct elf_aarch64_link_hash_table
*globals
,
5643 bfd
*input_bfd
, bfd_byte
*contents
,
5644 Elf_Internal_Rela
*rel
, struct elf_link_hash_entry
*h
)
5646 bfd_boolean is_local
= h
== NULL
;
5647 unsigned int r_type
= ELFNN_R_TYPE (rel
->r_info
);
5650 BFD_ASSERT (globals
&& input_bfd
&& contents
&& rel
);
5652 switch (elfNN_aarch64_bfd_reloc_from_type (r_type
))
5654 case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21
:
5655 case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21
:
5658 /* GD->LE relaxation:
5659 adrp x0, :tlsgd:var => movz x0, :tprel_g1:var
5661 adrp x0, :tlsdesc:var => movz x0, :tprel_g1:var
5663 bfd_putl32 (0xd2a00000, contents
+ rel
->r_offset
);
5664 return bfd_reloc_continue
;
5668 /* GD->IE relaxation:
5669 adrp x0, :tlsgd:var => adrp x0, :gottprel:var
5671 adrp x0, :tlsdesc:var => adrp x0, :gottprel:var
5673 return bfd_reloc_continue
;
5676 case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21
:
5680 case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19
:
5683 /* Tiny TLSDESC->LE relaxation:
5684 ldr x1, :tlsdesc:var => movz x0, #:tprel_g1:var
5685 adr x0, :tlsdesc:var => movk x0, #:tprel_g0_nc:var
5689 BFD_ASSERT (ELFNN_R_TYPE (rel
[1].r_info
) == AARCH64_R (TLSDESC_ADR_PREL21
));
5690 BFD_ASSERT (ELFNN_R_TYPE (rel
[2].r_info
) == AARCH64_R (TLSDESC_CALL
));
5692 rel
[1].r_info
= ELFNN_R_INFO (ELFNN_R_SYM (rel
->r_info
),
5693 AARCH64_R (TLSLE_MOVW_TPREL_G0_NC
));
5694 rel
[2].r_info
= ELFNN_R_INFO (STN_UNDEF
, R_AARCH64_NONE
);
5696 bfd_putl32 (0xd2a00000, contents
+ rel
->r_offset
);
5697 bfd_putl32 (0xf2800000, contents
+ rel
->r_offset
+ 4);
5698 bfd_putl32 (INSN_NOP
, contents
+ rel
->r_offset
+ 8);
5699 return bfd_reloc_continue
;
5703 /* Tiny TLSDESC->IE relaxation:
5704 ldr x1, :tlsdesc:var => ldr x0, :gottprel:var
5705 adr x0, :tlsdesc:var => nop
5709 BFD_ASSERT (ELFNN_R_TYPE (rel
[1].r_info
) == AARCH64_R (TLSDESC_ADR_PREL21
));
5710 BFD_ASSERT (ELFNN_R_TYPE (rel
[2].r_info
) == AARCH64_R (TLSDESC_CALL
));
5712 rel
[1].r_info
= ELFNN_R_INFO (STN_UNDEF
, R_AARCH64_NONE
);
5713 rel
[2].r_info
= ELFNN_R_INFO (STN_UNDEF
, R_AARCH64_NONE
);
5715 bfd_putl32 (0x58000000, contents
+ rel
->r_offset
);
5716 bfd_putl32 (INSN_NOP
, contents
+ rel
->r_offset
+ 4);
5717 bfd_putl32 (INSN_NOP
, contents
+ rel
->r_offset
+ 8);
5718 return bfd_reloc_continue
;
5721 case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21
:
5724 /* Tiny GD->LE relaxation:
5725 adr x0, :tlsgd:var => mrs x1, tpidr_el0
5726 bl __tls_get_addr => add x0, x1, #:tprel_hi12:x, lsl #12
5727 nop => add x0, x0, #:tprel_lo12_nc:x
5730 /* First kill the tls_get_addr reloc on the bl instruction. */
5731 BFD_ASSERT (rel
->r_offset
+ 4 == rel
[1].r_offset
);
5733 bfd_putl32 (0xd53bd041, contents
+ rel
->r_offset
+ 0);
5734 bfd_putl32 (0x91400020, contents
+ rel
->r_offset
+ 4);
5735 bfd_putl32 (0x91000000, contents
+ rel
->r_offset
+ 8);
5737 rel
[1].r_info
= ELFNN_R_INFO (ELFNN_R_SYM (rel
->r_info
),
5738 AARCH64_R (TLSLE_ADD_TPREL_LO12_NC
));
5739 rel
[1].r_offset
= rel
->r_offset
+ 8;
5741 /* Move the current relocation to the second instruction in
5744 rel
->r_info
= ELFNN_R_INFO (ELFNN_R_SYM (rel
->r_info
),
5745 AARCH64_R (TLSLE_ADD_TPREL_HI12
));
5746 return bfd_reloc_continue
;
5750 /* Tiny GD->IE relaxation:
5751 adr x0, :tlsgd:var => ldr x0, :gottprel:var
5752 bl __tls_get_addr => mrs x1, tpidr_el0
5753 nop => add x0, x0, x1
5756 /* First kill the tls_get_addr reloc on the bl instruction. */
5757 BFD_ASSERT (rel
->r_offset
+ 4 == rel
[1].r_offset
);
5758 rel
[1].r_info
= ELFNN_R_INFO (STN_UNDEF
, R_AARCH64_NONE
);
5760 bfd_putl32 (0x58000000, contents
+ rel
->r_offset
);
5761 bfd_putl32 (0xd53bd041, contents
+ rel
->r_offset
+ 4);
5762 bfd_putl32 (0x8b000020, contents
+ rel
->r_offset
+ 8);
5763 return bfd_reloc_continue
;
5767 case BFD_RELOC_AARCH64_TLSGD_MOVW_G1
:
5768 BFD_ASSERT (ELFNN_R_TYPE (rel
[1].r_info
) == AARCH64_R (TLSGD_MOVW_G0_NC
));
5769 BFD_ASSERT (rel
->r_offset
+ 12 == rel
[2].r_offset
);
5770 BFD_ASSERT (ELFNN_R_TYPE (rel
[2].r_info
) == AARCH64_R (CALL26
));
5774 /* Large GD->LE relaxation:
5775 movz x0, #:tlsgd_g1:var => movz x0, #:tprel_g2:var, lsl #32
5776 movk x0, #:tlsgd_g0_nc:var => movk x0, #:tprel_g1_nc:var, lsl #16
5777 add x0, gp, x0 => movk x0, #:tprel_g0_nc:var
5778 bl __tls_get_addr => mrs x1, tpidr_el0
5779 nop => add x0, x0, x1
5781 rel
[2].r_info
= ELFNN_R_INFO (ELFNN_R_SYM (rel
->r_info
),
5782 AARCH64_R (TLSLE_MOVW_TPREL_G0_NC
));
5783 rel
[2].r_offset
= rel
->r_offset
+ 8;
5785 bfd_putl32 (0xd2c00000, contents
+ rel
->r_offset
+ 0);
5786 bfd_putl32 (0xf2a00000, contents
+ rel
->r_offset
+ 4);
5787 bfd_putl32 (0xf2800000, contents
+ rel
->r_offset
+ 8);
5788 bfd_putl32 (0xd53bd041, contents
+ rel
->r_offset
+ 12);
5789 bfd_putl32 (0x8b000020, contents
+ rel
->r_offset
+ 16);
5793 /* Large GD->IE relaxation:
5794 movz x0, #:tlsgd_g1:var => movz x0, #:gottprel_g1:var, lsl #16
5795 movk x0, #:tlsgd_g0_nc:var => movk x0, #:gottprel_g0_nc:var
5796 add x0, gp, x0 => ldr x0, [gp, x0]
5797 bl __tls_get_addr => mrs x1, tpidr_el0
5798 nop => add x0, x0, x1
5800 rel
[2].r_info
= ELFNN_R_INFO (STN_UNDEF
, R_AARCH64_NONE
);
5801 bfd_putl32 (0xd2a80000, contents
+ rel
->r_offset
+ 0);
5802 bfd_putl32 (0x58000000, contents
+ rel
->r_offset
+ 8);
5803 bfd_putl32 (0xd53bd041, contents
+ rel
->r_offset
+ 12);
5804 bfd_putl32 (0x8b000020, contents
+ rel
->r_offset
+ 16);
5806 return bfd_reloc_continue
;
5808 case BFD_RELOC_AARCH64_TLSGD_MOVW_G0_NC
:
5809 return bfd_reloc_continue
;
5812 case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19
:
5813 return bfd_reloc_continue
;
5815 case BFD_RELOC_AARCH64_TLSDESC_LDNN_LO12_NC
:
5818 /* GD->LE relaxation:
5819 ldr xd, [x0, #:tlsdesc_lo12:var] => movk x0, :tprel_g0_nc:var
5821 bfd_putl32 (0xf2800000, contents
+ rel
->r_offset
);
5822 return bfd_reloc_continue
;
5826 /* GD->IE relaxation:
5827 ldr xd, [x0, #:tlsdesc_lo12:var] => ldr x0, [x0, #:gottprel_lo12:var]
5829 insn
= bfd_getl32 (contents
+ rel
->r_offset
);
5831 bfd_putl32 (insn
, contents
+ rel
->r_offset
);
5832 return bfd_reloc_continue
;
5835 case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC
:
5838 /* GD->LE relaxation
5839 add x0, #:tlsgd_lo12:var => movk x0, :tprel_g0_nc:var
5840 bl __tls_get_addr => mrs x1, tpidr_el0
5841 nop => add x0, x1, x0
5844 /* First kill the tls_get_addr reloc on the bl instruction. */
5845 BFD_ASSERT (rel
->r_offset
+ 4 == rel
[1].r_offset
);
5846 rel
[1].r_info
= ELFNN_R_INFO (STN_UNDEF
, R_AARCH64_NONE
);
5848 bfd_putl32 (0xf2800000, contents
+ rel
->r_offset
);
5849 bfd_putl32 (0xd53bd041, contents
+ rel
->r_offset
+ 4);
5850 bfd_putl32 (0x8b000020, contents
+ rel
->r_offset
+ 8);
5851 return bfd_reloc_continue
;
5855 /* GD->IE relaxation
5856 ADD x0, #:tlsgd_lo12:var => ldr R0, [x0, #:gottprel_lo12:var]
5857 BL __tls_get_addr => mrs x1, tpidr_el0
5859 NOP => add R0, R1, R0
5861 Where R is x for lp64 mode, and w for ilp32 mode. */
5863 BFD_ASSERT (ELFNN_R_TYPE (rel
[1].r_info
) == AARCH64_R (CALL26
));
5865 /* Remove the relocation on the BL instruction. */
5866 rel
[1].r_info
= ELFNN_R_INFO (STN_UNDEF
, R_AARCH64_NONE
);
5868 /* We choose to fixup the BL and NOP instructions using the
5869 offset from the second relocation to allow flexibility in
5870 scheduling instructions between the ADD and BL. */
5872 bfd_putl32 (0xb9400000, contents
+ rel
->r_offset
);
5873 bfd_putl32 (0x0b000020, contents
+ rel
[1].r_offset
+ 4);
5875 bfd_putl32 (0xf9400000, contents
+ rel
->r_offset
);
5876 bfd_putl32 (0x8b000020, contents
+ rel
[1].r_offset
+ 4);
5878 bfd_putl32 (0xd53bd041, contents
+ rel
[1].r_offset
);
5879 return bfd_reloc_continue
;
5882 case BFD_RELOC_AARCH64_TLSDESC_ADD
:
5883 case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12_NC
:
5884 case BFD_RELOC_AARCH64_TLSDESC_CALL
:
5885 /* GD->IE/LE relaxation:
5886 add x0, x0, #:tlsdesc_lo12:var => nop
5889 bfd_putl32 (INSN_NOP
, contents
+ rel
->r_offset
);
5890 return bfd_reloc_ok
;
5892 case BFD_RELOC_AARCH64_TLSDESC_LDR
:
5895 /* GD->LE relaxation:
5896 ldr xd, [gp, xn] => movk x0, #:tprel_g0_nc:var
5898 bfd_putl32 (0xf2800000, contents
+ rel
->r_offset
);
5899 return bfd_reloc_continue
;
5903 /* GD->IE relaxation:
5904 ldr xd, [gp, xn] => ldr x0, [gp, xn]
5906 insn
= bfd_getl32 (contents
+ rel
->r_offset
);
5908 bfd_putl32 (insn
, contents
+ rel
->r_offset
);
5909 return bfd_reloc_ok
;
5912 case BFD_RELOC_AARCH64_TLSDESC_OFF_G0_NC
:
5913 /* GD->LE relaxation:
5914 movk xd, #:tlsdesc_off_g0_nc:var => movk x0, #:tprel_g1_nc:var, lsl #16
5916 movk xd, #:tlsdesc_off_g0_nc:var => movk xd, #:gottprel_g0_nc:var
5919 bfd_putl32 (0xf2a00000, contents
+ rel
->r_offset
);
5920 return bfd_reloc_continue
;
5922 case BFD_RELOC_AARCH64_TLSDESC_OFF_G1
:
5925 /* GD->LE relaxation:
5926 movz xd, #:tlsdesc_off_g1:var => movz x0, #:tprel_g2:var, lsl #32
5928 bfd_putl32 (0xd2c00000, contents
+ rel
->r_offset
);
5929 return bfd_reloc_continue
;
5933 /* GD->IE relaxation:
5934 movz xd, #:tlsdesc_off_g1:var => movz xd, #:gottprel_g1:var, lsl #16
5936 insn
= bfd_getl32 (contents
+ rel
->r_offset
);
5937 bfd_putl32 (0xd2a00000 | (insn
& 0x1f), contents
+ rel
->r_offset
);
5938 return bfd_reloc_continue
;
5941 case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21
:
5942 /* IE->LE relaxation:
5943 adrp xd, :gottprel:var => movz xd, :tprel_g1:var
5947 insn
= bfd_getl32 (contents
+ rel
->r_offset
);
5948 bfd_putl32 (0xd2a00000 | (insn
& 0x1f), contents
+ rel
->r_offset
);
5950 return bfd_reloc_continue
;
5952 case BFD_RELOC_AARCH64_TLSIE_LDNN_GOTTPREL_LO12_NC
:
5953 /* IE->LE relaxation:
5954 ldr xd, [xm, #:gottprel_lo12:var] => movk xd, :tprel_g0_nc:var
5958 insn
= bfd_getl32 (contents
+ rel
->r_offset
);
5959 bfd_putl32 (0xf2800000 | (insn
& 0x1f), contents
+ rel
->r_offset
);
5961 return bfd_reloc_continue
;
5963 case BFD_RELOC_AARCH64_TLSLD_ADR_PREL21
:
5964 /* LD->LE relaxation (tiny):
5965 adr x0, :tlsldm:x => mrs x0, tpidr_el0
5966 bl __tls_get_addr => add R0, R0, TCB_SIZE
5968 Where R is x for lp64 mode, and w for ilp32 mode. */
5971 BFD_ASSERT (rel
->r_offset
+ 4 == rel
[1].r_offset
);
5972 BFD_ASSERT (ELFNN_R_TYPE (rel
[1].r_info
) == AARCH64_R (CALL26
));
5973 /* No need of CALL26 relocation for tls_get_addr. */
5974 rel
[1].r_info
= ELFNN_R_INFO (STN_UNDEF
, R_AARCH64_NONE
);
5975 bfd_putl32 (0xd53bd040, contents
+ rel
->r_offset
+ 0);
5977 bfd_putl32 (0x91004000, contents
+ rel
->r_offset
+ 4);
5979 bfd_putl32 (0x11002000, contents
+ rel
->r_offset
+ 4);
5981 return bfd_reloc_ok
;
5983 return bfd_reloc_continue
;
5985 case BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21
:
5986 /* LD->LE relaxation (small):
5987 adrp x0, :tlsldm:x => mrs x0, tpidr_el0
5991 bfd_putl32 (0xd53bd040, contents
+ rel
->r_offset
);
5992 return bfd_reloc_ok
;
5994 return bfd_reloc_continue
;
5996 case BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC
:
5997 /* LD->LE relaxation (small):
5998 add x0, #:tlsldm_lo12:x => add R0, R0, TCB_SIZE
5999 bl __tls_get_addr => nop
6001 Where R is x for lp64 mode, and w for ilp32 mode. */
6004 BFD_ASSERT (rel
->r_offset
+ 4 == rel
[1].r_offset
);
6005 BFD_ASSERT (ELFNN_R_TYPE (rel
[1].r_info
) == AARCH64_R (CALL26
));
6006 /* No need of CALL26 relocation for tls_get_addr. */
6007 rel
[1].r_info
= ELFNN_R_INFO (STN_UNDEF
, R_AARCH64_NONE
);
6009 bfd_putl32 (0x91004000, contents
+ rel
->r_offset
+ 0);
6011 bfd_putl32 (0x11002000, contents
+ rel
->r_offset
+ 0);
6013 bfd_putl32 (INSN_NOP
, contents
+ rel
->r_offset
+ 4);
6014 return bfd_reloc_ok
;
6016 return bfd_reloc_continue
;
6019 return bfd_reloc_continue
;
6022 return bfd_reloc_ok
;
6025 /* Relocate an AArch64 ELF section. */
6028 elfNN_aarch64_relocate_section (bfd
*output_bfd
,
6029 struct bfd_link_info
*info
,
6031 asection
*input_section
,
6033 Elf_Internal_Rela
*relocs
,
6034 Elf_Internal_Sym
*local_syms
,
6035 asection
**local_sections
)
6037 Elf_Internal_Shdr
*symtab_hdr
;
6038 struct elf_link_hash_entry
**sym_hashes
;
6039 Elf_Internal_Rela
*rel
;
6040 Elf_Internal_Rela
*relend
;
6042 struct elf_aarch64_link_hash_table
*globals
;
6043 bfd_boolean save_addend
= FALSE
;
6046 globals
= elf_aarch64_hash_table (info
);
6048 symtab_hdr
= &elf_symtab_hdr (input_bfd
);
6049 sym_hashes
= elf_sym_hashes (input_bfd
);
6052 relend
= relocs
+ input_section
->reloc_count
;
6053 for (; rel
< relend
; rel
++)
6055 unsigned int r_type
;
6056 bfd_reloc_code_real_type bfd_r_type
;
6057 bfd_reloc_code_real_type relaxed_bfd_r_type
;
6058 reloc_howto_type
*howto
;
6059 unsigned long r_symndx
;
6060 Elf_Internal_Sym
*sym
;
6062 struct elf_link_hash_entry
*h
;
6064 bfd_reloc_status_type r
;
6067 bfd_boolean unresolved_reloc
= FALSE
;
6068 char *error_message
= NULL
;
6070 r_symndx
= ELFNN_R_SYM (rel
->r_info
);
6071 r_type
= ELFNN_R_TYPE (rel
->r_info
);
6073 bfd_reloc
.howto
= elfNN_aarch64_howto_from_type (r_type
);
6074 howto
= bfd_reloc
.howto
;
6078 /* xgettext:c-format */
6080 (_("%B: unrecognized relocation (0x%x) in section `%A'"),
6081 input_bfd
, input_section
, r_type
);
6084 bfd_r_type
= elfNN_aarch64_bfd_reloc_from_howto (howto
);
6090 if (r_symndx
< symtab_hdr
->sh_info
)
6092 sym
= local_syms
+ r_symndx
;
6093 sym_type
= ELFNN_ST_TYPE (sym
->st_info
);
6094 sec
= local_sections
[r_symndx
];
6096 /* An object file might have a reference to a local
6097 undefined symbol. This is a daft object file, but we
6098 should at least do something about it. */
6099 if (r_type
!= R_AARCH64_NONE
&& r_type
!= R_AARCH64_NULL
6100 && bfd_is_und_section (sec
)
6101 && ELF_ST_BIND (sym
->st_info
) != STB_WEAK
)
6102 (*info
->callbacks
->undefined_symbol
)
6103 (info
, bfd_elf_string_from_elf_section
6104 (input_bfd
, symtab_hdr
->sh_link
, sym
->st_name
),
6105 input_bfd
, input_section
, rel
->r_offset
, TRUE
);
6107 relocation
= _bfd_elf_rela_local_sym (output_bfd
, sym
, &sec
, rel
);
6109 /* Relocate against local STT_GNU_IFUNC symbol. */
6110 if (!bfd_link_relocatable (info
)
6111 && ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
)
6113 h
= elfNN_aarch64_get_local_sym_hash (globals
, input_bfd
,
6118 /* Set STT_GNU_IFUNC symbol value. */
6119 h
->root
.u
.def
.value
= sym
->st_value
;
6120 h
->root
.u
.def
.section
= sec
;
6125 bfd_boolean warned
, ignored
;
6127 RELOC_FOR_GLOBAL_SYMBOL (info
, input_bfd
, input_section
, rel
,
6128 r_symndx
, symtab_hdr
, sym_hashes
,
6130 unresolved_reloc
, warned
, ignored
);
6135 if (sec
!= NULL
&& discarded_section (sec
))
6136 RELOC_AGAINST_DISCARDED_SECTION (info
, input_bfd
, input_section
,
6137 rel
, 1, relend
, howto
, 0, contents
);
6139 if (bfd_link_relocatable (info
))
6143 name
= h
->root
.root
.string
;
6146 name
= (bfd_elf_string_from_elf_section
6147 (input_bfd
, symtab_hdr
->sh_link
, sym
->st_name
));
6148 if (name
== NULL
|| *name
== '\0')
6149 name
= bfd_section_name (input_bfd
, sec
);
6153 && r_type
!= R_AARCH64_NONE
6154 && r_type
!= R_AARCH64_NULL
6156 || h
->root
.type
== bfd_link_hash_defined
6157 || h
->root
.type
== bfd_link_hash_defweak
)
6158 && IS_AARCH64_TLS_RELOC (bfd_r_type
) != (sym_type
== STT_TLS
))
6161 ((sym_type
== STT_TLS
6162 /* xgettext:c-format */
6163 ? _("%B(%A+0x%lx): %s used with TLS symbol %s")
6164 /* xgettext:c-format */
6165 : _("%B(%A+0x%lx): %s used with non-TLS symbol %s")),
6167 input_section
, (long) rel
->r_offset
, howto
->name
, name
);
6170 /* We relax only if we can see that there can be a valid transition
6171 from a reloc type to another.
6172 We call elfNN_aarch64_final_link_relocate unless we're completely
6173 done, i.e., the relaxation produced the final output we want. */
6175 relaxed_bfd_r_type
= aarch64_tls_transition (input_bfd
, info
, r_type
,
6177 if (relaxed_bfd_r_type
!= bfd_r_type
)
6179 bfd_r_type
= relaxed_bfd_r_type
;
6180 howto
= elfNN_aarch64_howto_from_bfd_reloc (bfd_r_type
);
6181 BFD_ASSERT (howto
!= NULL
);
6182 r_type
= howto
->type
;
6183 r
= elfNN_aarch64_tls_relax (globals
, input_bfd
, contents
, rel
, h
);
6184 unresolved_reloc
= 0;
6187 r
= bfd_reloc_continue
;
6189 /* There may be multiple consecutive relocations for the
6190 same offset. In that case we are supposed to treat the
6191 output of each relocation as the addend for the next. */
6192 if (rel
+ 1 < relend
6193 && rel
->r_offset
== rel
[1].r_offset
6194 && ELFNN_R_TYPE (rel
[1].r_info
) != R_AARCH64_NONE
6195 && ELFNN_R_TYPE (rel
[1].r_info
) != R_AARCH64_NULL
)
6198 save_addend
= FALSE
;
6200 if (r
== bfd_reloc_continue
)
6201 r
= elfNN_aarch64_final_link_relocate (howto
, input_bfd
, output_bfd
,
6202 input_section
, contents
, rel
,
6203 relocation
, info
, sec
,
6204 h
, &unresolved_reloc
,
6205 save_addend
, &addend
, sym
);
6207 switch (elfNN_aarch64_bfd_reloc_from_type (r_type
))
6209 case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC
:
6210 case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21
:
6211 case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21
:
6212 case BFD_RELOC_AARCH64_TLSGD_MOVW_G0_NC
:
6213 case BFD_RELOC_AARCH64_TLSGD_MOVW_G1
:
6214 case BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC
:
6215 case BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21
:
6216 case BFD_RELOC_AARCH64_TLSLD_ADR_PREL21
:
6217 if (! symbol_got_offset_mark_p (input_bfd
, h
, r_symndx
))
6219 bfd_boolean need_relocs
= FALSE
;
6224 off
= symbol_got_offset (input_bfd
, h
, r_symndx
);
6225 indx
= h
&& h
->dynindx
!= -1 ? h
->dynindx
: 0;
6228 (bfd_link_pic (info
) || indx
!= 0) &&
6230 || ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
6231 || h
->root
.type
!= bfd_link_hash_undefweak
);
6233 BFD_ASSERT (globals
->root
.srelgot
!= NULL
);
6237 Elf_Internal_Rela rela
;
6238 rela
.r_info
= ELFNN_R_INFO (indx
, AARCH64_R (TLS_DTPMOD
));
6240 rela
.r_offset
= globals
->root
.sgot
->output_section
->vma
+
6241 globals
->root
.sgot
->output_offset
+ off
;
6244 loc
= globals
->root
.srelgot
->contents
;
6245 loc
+= globals
->root
.srelgot
->reloc_count
++
6246 * RELOC_SIZE (htab
);
6247 bfd_elfNN_swap_reloca_out (output_bfd
, &rela
, loc
);
6249 bfd_reloc_code_real_type real_type
=
6250 elfNN_aarch64_bfd_reloc_from_type (r_type
);
6252 if (real_type
== BFD_RELOC_AARCH64_TLSLD_ADR_PREL21
6253 || real_type
== BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21
6254 || real_type
== BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC
)
6256 /* For local dynamic, don't generate DTPREL in any case.
6257 Initialize the DTPREL slot into zero, so we get module
6258 base address when invoke runtime TLS resolver. */
6259 bfd_put_NN (output_bfd
, 0,
6260 globals
->root
.sgot
->contents
+ off
6265 bfd_put_NN (output_bfd
,
6266 relocation
- dtpoff_base (info
),
6267 globals
->root
.sgot
->contents
+ off
6272 /* This TLS symbol is global. We emit a
6273 relocation to fixup the tls offset at load
6276 ELFNN_R_INFO (indx
, AARCH64_R (TLS_DTPREL
));
6279 (globals
->root
.sgot
->output_section
->vma
6280 + globals
->root
.sgot
->output_offset
+ off
6283 loc
= globals
->root
.srelgot
->contents
;
6284 loc
+= globals
->root
.srelgot
->reloc_count
++
6285 * RELOC_SIZE (globals
);
6286 bfd_elfNN_swap_reloca_out (output_bfd
, &rela
, loc
);
6287 bfd_put_NN (output_bfd
, (bfd_vma
) 0,
6288 globals
->root
.sgot
->contents
+ off
6294 bfd_put_NN (output_bfd
, (bfd_vma
) 1,
6295 globals
->root
.sgot
->contents
+ off
);
6296 bfd_put_NN (output_bfd
,
6297 relocation
- dtpoff_base (info
),
6298 globals
->root
.sgot
->contents
+ off
6302 symbol_got_offset_mark (input_bfd
, h
, r_symndx
);
6306 case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21
:
6307 case BFD_RELOC_AARCH64_TLSIE_LDNN_GOTTPREL_LO12_NC
:
6308 case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19
:
6309 case BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G0_NC
:
6310 case BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G1
:
6311 if (! symbol_got_offset_mark_p (input_bfd
, h
, r_symndx
))
6313 bfd_boolean need_relocs
= FALSE
;
6318 off
= symbol_got_offset (input_bfd
, h
, r_symndx
);
6320 indx
= h
&& h
->dynindx
!= -1 ? h
->dynindx
: 0;
6323 (bfd_link_pic (info
) || indx
!= 0) &&
6325 || ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
6326 || h
->root
.type
!= bfd_link_hash_undefweak
);
6328 BFD_ASSERT (globals
->root
.srelgot
!= NULL
);
6332 Elf_Internal_Rela rela
;
6335 rela
.r_addend
= relocation
- dtpoff_base (info
);
6339 rela
.r_info
= ELFNN_R_INFO (indx
, AARCH64_R (TLS_TPREL
));
6340 rela
.r_offset
= globals
->root
.sgot
->output_section
->vma
+
6341 globals
->root
.sgot
->output_offset
+ off
;
6343 loc
= globals
->root
.srelgot
->contents
;
6344 loc
+= globals
->root
.srelgot
->reloc_count
++
6345 * RELOC_SIZE (htab
);
6347 bfd_elfNN_swap_reloca_out (output_bfd
, &rela
, loc
);
6349 bfd_put_NN (output_bfd
, rela
.r_addend
,
6350 globals
->root
.sgot
->contents
+ off
);
6353 bfd_put_NN (output_bfd
, relocation
- tpoff_base (info
),
6354 globals
->root
.sgot
->contents
+ off
);
6356 symbol_got_offset_mark (input_bfd
, h
, r_symndx
);
6360 case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12_NC
:
6361 case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21
:
6362 case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21
:
6363 case BFD_RELOC_AARCH64_TLSDESC_LDNN_LO12_NC
:
6364 case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19
:
6365 case BFD_RELOC_AARCH64_TLSDESC_OFF_G0_NC
:
6366 case BFD_RELOC_AARCH64_TLSDESC_OFF_G1
:
6367 if (! symbol_tlsdesc_got_offset_mark_p (input_bfd
, h
, r_symndx
))
6369 bfd_boolean need_relocs
= FALSE
;
6370 int indx
= h
&& h
->dynindx
!= -1 ? h
->dynindx
: 0;
6371 bfd_vma off
= symbol_tlsdesc_got_offset (input_bfd
, h
, r_symndx
);
6373 need_relocs
= (h
== NULL
6374 || ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
6375 || h
->root
.type
!= bfd_link_hash_undefweak
);
6377 BFD_ASSERT (globals
->root
.srelgot
!= NULL
);
6378 BFD_ASSERT (globals
->root
.sgot
!= NULL
);
6383 Elf_Internal_Rela rela
;
6384 rela
.r_info
= ELFNN_R_INFO (indx
, AARCH64_R (TLSDESC
));
6387 rela
.r_offset
= (globals
->root
.sgotplt
->output_section
->vma
6388 + globals
->root
.sgotplt
->output_offset
6389 + off
+ globals
->sgotplt_jump_table_size
);
6392 rela
.r_addend
= relocation
- dtpoff_base (info
);
6394 /* Allocate the next available slot in the PLT reloc
6395 section to hold our R_AARCH64_TLSDESC, the next
6396 available slot is determined from reloc_count,
6397 which we step. But note, reloc_count was
6398 artifically moved down while allocating slots for
6399 real PLT relocs such that all of the PLT relocs
6400 will fit above the initial reloc_count and the
6401 extra stuff will fit below. */
6402 loc
= globals
->root
.srelplt
->contents
;
6403 loc
+= globals
->root
.srelplt
->reloc_count
++
6404 * RELOC_SIZE (globals
);
6406 bfd_elfNN_swap_reloca_out (output_bfd
, &rela
, loc
);
6408 bfd_put_NN (output_bfd
, (bfd_vma
) 0,
6409 globals
->root
.sgotplt
->contents
+ off
+
6410 globals
->sgotplt_jump_table_size
);
6411 bfd_put_NN (output_bfd
, (bfd_vma
) 0,
6412 globals
->root
.sgotplt
->contents
+ off
+
6413 globals
->sgotplt_jump_table_size
+
6417 symbol_tlsdesc_got_offset_mark (input_bfd
, h
, r_symndx
);
6424 /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
6425 because such sections are not SEC_ALLOC and thus ld.so will
6426 not process them. */
6427 if (unresolved_reloc
6428 && !((input_section
->flags
& SEC_DEBUGGING
) != 0
6430 && _bfd_elf_section_offset (output_bfd
, info
, input_section
,
6431 +rel
->r_offset
) != (bfd_vma
) - 1)
6434 /* xgettext:c-format */
6435 (_("%B(%A+0x%lx): unresolvable %s relocation against symbol `%s'"),
6436 input_bfd
, input_section
, (long) rel
->r_offset
, howto
->name
,
6437 h
->root
.root
.string
);
6441 if (r
!= bfd_reloc_ok
&& r
!= bfd_reloc_continue
)
6443 bfd_reloc_code_real_type real_r_type
6444 = elfNN_aarch64_bfd_reloc_from_type (r_type
);
6448 case bfd_reloc_overflow
:
6449 (*info
->callbacks
->reloc_overflow
)
6450 (info
, (h
? &h
->root
: NULL
), name
, howto
->name
, (bfd_vma
) 0,
6451 input_bfd
, input_section
, rel
->r_offset
);
6452 if (real_r_type
== BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15
6453 || real_r_type
== BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14
)
6455 (*info
->callbacks
->warning
)
6457 _("Too many GOT entries for -fpic, "
6458 "please recompile with -fPIC"),
6459 name
, input_bfd
, input_section
, rel
->r_offset
);
6462 /* Overflow can occur when a variable is referenced with a type
6463 that has a larger alignment than the type with which it was
6465 file1.c: extern int foo; int a (void) { return foo; }
6466 file2.c: char bar, foo, baz;
6467 If the variable is placed into a data section at an offset
6468 that is incompatible with the larger alignment requirement
6469 overflow will occur. (Strictly speaking this is not overflow
6470 but rather an alignment problem, but the bfd_reloc_ error
6471 enum does not have a value to cover that situation).
6473 Try to catch this situation here and provide a more helpful
6474 error message to the user. */
6475 if (addend
& ((1 << howto
->rightshift
) - 1)
6476 /* FIXME: Are we testing all of the appropriate reloc
6478 && (real_r_type
== BFD_RELOC_AARCH64_LD_LO19_PCREL
6479 || real_r_type
== BFD_RELOC_AARCH64_LDST16_LO12
6480 || real_r_type
== BFD_RELOC_AARCH64_LDST32_LO12
6481 || real_r_type
== BFD_RELOC_AARCH64_LDST64_LO12
6482 || real_r_type
== BFD_RELOC_AARCH64_LDST128_LO12
))
6484 info
->callbacks
->warning
6485 (info
, _("One possible cause of this error is that the \
6486 symbol is being referenced in the indicated code as if it had a larger \
6487 alignment than was declared where it was defined."),
6488 name
, input_bfd
, input_section
, rel
->r_offset
);
6492 case bfd_reloc_undefined
:
6493 (*info
->callbacks
->undefined_symbol
)
6494 (info
, name
, input_bfd
, input_section
, rel
->r_offset
, TRUE
);
6497 case bfd_reloc_outofrange
:
6498 error_message
= _("out of range");
6501 case bfd_reloc_notsupported
:
6502 error_message
= _("unsupported relocation");
6505 case bfd_reloc_dangerous
:
6506 /* error_message should already be set. */
6510 error_message
= _("unknown error");
6514 BFD_ASSERT (error_message
!= NULL
);
6515 (*info
->callbacks
->reloc_dangerous
)
6516 (info
, error_message
, input_bfd
, input_section
, rel
->r_offset
);
6528 /* Set the right machine number. */
6531 elfNN_aarch64_object_p (bfd
*abfd
)
6534 bfd_default_set_arch_mach (abfd
, bfd_arch_aarch64
, bfd_mach_aarch64_ilp32
);
6536 bfd_default_set_arch_mach (abfd
, bfd_arch_aarch64
, bfd_mach_aarch64
);
6541 /* Function to keep AArch64 specific flags in the ELF header. */
6544 elfNN_aarch64_set_private_flags (bfd
*abfd
, flagword flags
)
6546 if (elf_flags_init (abfd
) && elf_elfheader (abfd
)->e_flags
!= flags
)
6551 elf_elfheader (abfd
)->e_flags
= flags
;
6552 elf_flags_init (abfd
) = TRUE
;
6558 /* Merge backend specific data from an object file to the output
6559 object file when linking. */
6562 elfNN_aarch64_merge_private_bfd_data (bfd
*ibfd
, struct bfd_link_info
*info
)
6564 bfd
*obfd
= info
->output_bfd
;
6567 bfd_boolean flags_compatible
= TRUE
;
6570 /* Check if we have the same endianess. */
6571 if (!_bfd_generic_verify_endian_match (ibfd
, info
))
6574 if (!is_aarch64_elf (ibfd
) || !is_aarch64_elf (obfd
))
6577 /* The input BFD must have had its flags initialised. */
6578 /* The following seems bogus to me -- The flags are initialized in
6579 the assembler but I don't think an elf_flags_init field is
6580 written into the object. */
6581 /* BFD_ASSERT (elf_flags_init (ibfd)); */
6583 in_flags
= elf_elfheader (ibfd
)->e_flags
;
6584 out_flags
= elf_elfheader (obfd
)->e_flags
;
6586 if (!elf_flags_init (obfd
))
6588 /* If the input is the default architecture and had the default
6589 flags then do not bother setting the flags for the output
6590 architecture, instead allow future merges to do this. If no
6591 future merges ever set these flags then they will retain their
6592 uninitialised values, which surprise surprise, correspond
6593 to the default values. */
6594 if (bfd_get_arch_info (ibfd
)->the_default
6595 && elf_elfheader (ibfd
)->e_flags
== 0)
6598 elf_flags_init (obfd
) = TRUE
;
6599 elf_elfheader (obfd
)->e_flags
= in_flags
;
6601 if (bfd_get_arch (obfd
) == bfd_get_arch (ibfd
)
6602 && bfd_get_arch_info (obfd
)->the_default
)
6603 return bfd_set_arch_mach (obfd
, bfd_get_arch (ibfd
),
6604 bfd_get_mach (ibfd
));
6609 /* Identical flags must be compatible. */
6610 if (in_flags
== out_flags
)
6613 /* Check to see if the input BFD actually contains any sections. If
6614 not, its flags may not have been initialised either, but it
6615 cannot actually cause any incompatiblity. Do not short-circuit
6616 dynamic objects; their section list may be emptied by
6617 elf_link_add_object_symbols.
6619 Also check to see if there are no code sections in the input.
6620 In this case there is no need to check for code specific flags.
6621 XXX - do we need to worry about floating-point format compatability
6622 in data sections ? */
6623 if (!(ibfd
->flags
& DYNAMIC
))
6625 bfd_boolean null_input_bfd
= TRUE
;
6626 bfd_boolean only_data_sections
= TRUE
;
6628 for (sec
= ibfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
6630 if ((bfd_get_section_flags (ibfd
, sec
)
6631 & (SEC_LOAD
| SEC_CODE
| SEC_HAS_CONTENTS
))
6632 == (SEC_LOAD
| SEC_CODE
| SEC_HAS_CONTENTS
))
6633 only_data_sections
= FALSE
;
6635 null_input_bfd
= FALSE
;
6639 if (null_input_bfd
|| only_data_sections
)
6643 return flags_compatible
;
6646 /* Display the flags field. */
6649 elfNN_aarch64_print_private_bfd_data (bfd
*abfd
, void *ptr
)
6651 FILE *file
= (FILE *) ptr
;
6652 unsigned long flags
;
6654 BFD_ASSERT (abfd
!= NULL
&& ptr
!= NULL
);
6656 /* Print normal ELF private data. */
6657 _bfd_elf_print_private_bfd_data (abfd
, ptr
);
6659 flags
= elf_elfheader (abfd
)->e_flags
;
6660 /* Ignore init flag - it may not be set, despite the flags field
6661 containing valid data. */
6663 /* xgettext:c-format */
6664 fprintf (file
, _("private flags = %lx:"), elf_elfheader (abfd
)->e_flags
);
6667 fprintf (file
, _("<Unrecognised flag bits set>"));
6674 /* Update the got entry reference counts for the section being removed. */
6677 elfNN_aarch64_gc_sweep_hook (bfd
*abfd
,
6678 struct bfd_link_info
*info
,
6680 const Elf_Internal_Rela
* relocs
)
6682 struct elf_aarch64_link_hash_table
*htab
;
6683 Elf_Internal_Shdr
*symtab_hdr
;
6684 struct elf_link_hash_entry
**sym_hashes
;
6685 struct elf_aarch64_local_symbol
*locals
;
6686 const Elf_Internal_Rela
*rel
, *relend
;
6688 if (bfd_link_relocatable (info
))
6691 htab
= elf_aarch64_hash_table (info
);
6696 elf_section_data (sec
)->local_dynrel
= NULL
;
6698 symtab_hdr
= &elf_symtab_hdr (abfd
);
6699 sym_hashes
= elf_sym_hashes (abfd
);
6701 locals
= elf_aarch64_locals (abfd
);
6703 relend
= relocs
+ sec
->reloc_count
;
6704 for (rel
= relocs
; rel
< relend
; rel
++)
6706 unsigned long r_symndx
;
6707 unsigned int r_type
;
6708 struct elf_link_hash_entry
*h
= NULL
;
6710 r_symndx
= ELFNN_R_SYM (rel
->r_info
);
6712 if (r_symndx
>= symtab_hdr
->sh_info
)
6715 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
6716 while (h
->root
.type
== bfd_link_hash_indirect
6717 || h
->root
.type
== bfd_link_hash_warning
)
6718 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
6722 Elf_Internal_Sym
*isym
;
6724 /* A local symbol. */
6725 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
6728 /* Check relocation against local STT_GNU_IFUNC symbol. */
6730 && ELF_ST_TYPE (isym
->st_info
) == STT_GNU_IFUNC
)
6732 h
= elfNN_aarch64_get_local_sym_hash (htab
, abfd
, rel
, FALSE
);
6740 struct elf_aarch64_link_hash_entry
*eh
;
6741 struct elf_dyn_relocs
**pp
;
6742 struct elf_dyn_relocs
*p
;
6744 eh
= (struct elf_aarch64_link_hash_entry
*) h
;
6746 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; pp
= &p
->next
)
6749 /* Everything must go for SEC. */
6755 r_type
= ELFNN_R_TYPE (rel
->r_info
);
6756 switch (aarch64_tls_transition (abfd
,info
, r_type
, h
,r_symndx
))
6758 case BFD_RELOC_AARCH64_ADR_GOT_PAGE
:
6759 case BFD_RELOC_AARCH64_GOT_LD_PREL19
:
6760 case BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14
:
6761 case BFD_RELOC_AARCH64_LD32_GOT_LO12_NC
:
6762 case BFD_RELOC_AARCH64_LD64_GOTOFF_LO15
:
6763 case BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15
:
6764 case BFD_RELOC_AARCH64_LD64_GOT_LO12_NC
:
6765 case BFD_RELOC_AARCH64_MOVW_GOTOFF_G0_NC
:
6766 case BFD_RELOC_AARCH64_MOVW_GOTOFF_G1
:
6767 case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12_NC
:
6768 case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21
:
6769 case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21
:
6770 case BFD_RELOC_AARCH64_TLSDESC_LD32_LO12_NC
:
6771 case BFD_RELOC_AARCH64_TLSDESC_LD64_LO12_NC
:
6772 case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19
:
6773 case BFD_RELOC_AARCH64_TLSDESC_OFF_G0_NC
:
6774 case BFD_RELOC_AARCH64_TLSDESC_OFF_G1
:
6775 case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC
:
6776 case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21
:
6777 case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21
:
6778 case BFD_RELOC_AARCH64_TLSGD_MOVW_G0_NC
:
6779 case BFD_RELOC_AARCH64_TLSGD_MOVW_G1
:
6780 case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21
:
6781 case BFD_RELOC_AARCH64_TLSIE_LD32_GOTTPREL_LO12_NC
:
6782 case BFD_RELOC_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC
:
6783 case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19
:
6784 case BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G0_NC
:
6785 case BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G1
:
6786 case BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC
:
6787 case BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21
:
6788 case BFD_RELOC_AARCH64_TLSLD_ADR_PREL21
:
6791 if (h
->got
.refcount
> 0)
6792 h
->got
.refcount
-= 1;
6794 if (h
->type
== STT_GNU_IFUNC
)
6796 if (h
->plt
.refcount
> 0)
6797 h
->plt
.refcount
-= 1;
6800 else if (locals
!= NULL
)
6802 if (locals
[r_symndx
].got_refcount
> 0)
6803 locals
[r_symndx
].got_refcount
-= 1;
6807 case BFD_RELOC_AARCH64_CALL26
:
6808 case BFD_RELOC_AARCH64_JUMP26
:
6809 /* If this is a local symbol then we resolve it
6810 directly without creating a PLT entry. */
6814 if (h
->plt
.refcount
> 0)
6815 h
->plt
.refcount
-= 1;
6818 case BFD_RELOC_AARCH64_ADR_HI21_NC_PCREL
:
6819 case BFD_RELOC_AARCH64_ADR_HI21_PCREL
:
6820 case BFD_RELOC_AARCH64_ADR_LO21_PCREL
:
6821 case BFD_RELOC_AARCH64_MOVW_G0_NC
:
6822 case BFD_RELOC_AARCH64_MOVW_G1_NC
:
6823 case BFD_RELOC_AARCH64_MOVW_G2_NC
:
6824 case BFD_RELOC_AARCH64_MOVW_G3
:
6825 case BFD_RELOC_AARCH64_NN
:
6826 if (h
!= NULL
&& bfd_link_executable (info
))
6828 if (h
->plt
.refcount
> 0)
6829 h
->plt
.refcount
-= 1;
6841 /* Adjust a symbol defined by a dynamic object and referenced by a
6842 regular object. The current definition is in some section of the
6843 dynamic object, but we're not including those sections. We have to
6844 change the definition to something the rest of the link can
6848 elfNN_aarch64_adjust_dynamic_symbol (struct bfd_link_info
*info
,
6849 struct elf_link_hash_entry
*h
)
6851 struct elf_aarch64_link_hash_table
*htab
;
6854 /* If this is a function, put it in the procedure linkage table. We
6855 will fill in the contents of the procedure linkage table later,
6856 when we know the address of the .got section. */
6857 if (h
->type
== STT_FUNC
|| h
->type
== STT_GNU_IFUNC
|| h
->needs_plt
)
6859 if (h
->plt
.refcount
<= 0
6860 || (h
->type
!= STT_GNU_IFUNC
6861 && (SYMBOL_CALLS_LOCAL (info
, h
)
6862 || (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
6863 && h
->root
.type
== bfd_link_hash_undefweak
))))
6865 /* This case can occur if we saw a CALL26 reloc in
6866 an input file, but the symbol wasn't referred to
6867 by a dynamic object or all references were
6868 garbage collected. In which case we can end up
6870 h
->plt
.offset
= (bfd_vma
) - 1;
6877 /* Otherwise, reset to -1. */
6878 h
->plt
.offset
= (bfd_vma
) - 1;
6881 /* If this is a weak symbol, and there is a real definition, the
6882 processor independent code will have arranged for us to see the
6883 real definition first, and we can just use the same value. */
6884 if (h
->u
.weakdef
!= NULL
)
6886 BFD_ASSERT (h
->u
.weakdef
->root
.type
== bfd_link_hash_defined
6887 || h
->u
.weakdef
->root
.type
== bfd_link_hash_defweak
);
6888 h
->root
.u
.def
.section
= h
->u
.weakdef
->root
.u
.def
.section
;
6889 h
->root
.u
.def
.value
= h
->u
.weakdef
->root
.u
.def
.value
;
6890 if (ELIMINATE_COPY_RELOCS
|| info
->nocopyreloc
)
6891 h
->non_got_ref
= h
->u
.weakdef
->non_got_ref
;
6895 /* If we are creating a shared library, we must presume that the
6896 only references to the symbol are via the global offset table.
6897 For such cases we need not do anything here; the relocations will
6898 be handled correctly by relocate_section. */
6899 if (bfd_link_pic (info
))
6902 /* If there are no references to this symbol that do not use the
6903 GOT, we don't need to generate a copy reloc. */
6904 if (!h
->non_got_ref
)
6907 /* If -z nocopyreloc was given, we won't generate them either. */
6908 if (info
->nocopyreloc
)
6914 /* We must allocate the symbol in our .dynbss section, which will
6915 become part of the .bss section of the executable. There will be
6916 an entry for this symbol in the .dynsym section. The dynamic
6917 object will contain position independent code, so all references
6918 from the dynamic object to this symbol will go through the global
6919 offset table. The dynamic linker will use the .dynsym entry to
6920 determine the address it must put in the global offset table, so
6921 both the dynamic object and the regular object will refer to the
6922 same memory location for the variable. */
6924 htab
= elf_aarch64_hash_table (info
);
6926 /* We must generate a R_AARCH64_COPY reloc to tell the dynamic linker
6927 to copy the initial value out of the dynamic object and into the
6928 runtime process image. */
6929 if ((h
->root
.u
.def
.section
->flags
& SEC_READONLY
) != 0)
6931 s
= htab
->root
.sdynrelro
;
6932 srel
= htab
->root
.sreldynrelro
;
6936 s
= htab
->root
.sdynbss
;
6937 srel
= htab
->root
.srelbss
;
6939 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0 && h
->size
!= 0)
6941 srel
->size
+= RELOC_SIZE (htab
);
6945 return _bfd_elf_adjust_dynamic_copy (info
, h
, s
);
6950 elfNN_aarch64_allocate_local_symbols (bfd
*abfd
, unsigned number
)
6952 struct elf_aarch64_local_symbol
*locals
;
6953 locals
= elf_aarch64_locals (abfd
);
6956 locals
= (struct elf_aarch64_local_symbol
*)
6957 bfd_zalloc (abfd
, number
* sizeof (struct elf_aarch64_local_symbol
));
6960 elf_aarch64_locals (abfd
) = locals
;
6965 /* Create the .got section to hold the global offset table. */
6968 aarch64_elf_create_got_section (bfd
*abfd
, struct bfd_link_info
*info
)
6970 const struct elf_backend_data
*bed
= get_elf_backend_data (abfd
);
6973 struct elf_link_hash_entry
*h
;
6974 struct elf_link_hash_table
*htab
= elf_hash_table (info
);
6976 /* This function may be called more than once. */
6977 if (htab
->sgot
!= NULL
)
6980 flags
= bed
->dynamic_sec_flags
;
6982 s
= bfd_make_section_anyway_with_flags (abfd
,
6983 (bed
->rela_plts_and_copies_p
6984 ? ".rela.got" : ".rel.got"),
6985 (bed
->dynamic_sec_flags
6988 || ! bfd_set_section_alignment (abfd
, s
, bed
->s
->log_file_align
))
6992 s
= bfd_make_section_anyway_with_flags (abfd
, ".got", flags
);
6994 || !bfd_set_section_alignment (abfd
, s
, bed
->s
->log_file_align
))
6997 htab
->sgot
->size
+= GOT_ENTRY_SIZE
;
6999 if (bed
->want_got_sym
)
7001 /* Define the symbol _GLOBAL_OFFSET_TABLE_ at the start of the .got
7002 (or .got.plt) section. We don't do this in the linker script
7003 because we don't want to define the symbol if we are not creating
7004 a global offset table. */
7005 h
= _bfd_elf_define_linkage_sym (abfd
, info
, s
,
7006 "_GLOBAL_OFFSET_TABLE_");
7007 elf_hash_table (info
)->hgot
= h
;
7012 if (bed
->want_got_plt
)
7014 s
= bfd_make_section_anyway_with_flags (abfd
, ".got.plt", flags
);
7016 || !bfd_set_section_alignment (abfd
, s
,
7017 bed
->s
->log_file_align
))
7022 /* The first bit of the global offset table is the header. */
7023 s
->size
+= bed
->got_header_size
;
7028 /* Look through the relocs for a section during the first phase. */
7031 elfNN_aarch64_check_relocs (bfd
*abfd
, struct bfd_link_info
*info
,
7032 asection
*sec
, const Elf_Internal_Rela
*relocs
)
7034 Elf_Internal_Shdr
*symtab_hdr
;
7035 struct elf_link_hash_entry
**sym_hashes
;
7036 const Elf_Internal_Rela
*rel
;
7037 const Elf_Internal_Rela
*rel_end
;
7040 struct elf_aarch64_link_hash_table
*htab
;
7042 if (bfd_link_relocatable (info
))
7045 BFD_ASSERT (is_aarch64_elf (abfd
));
7047 htab
= elf_aarch64_hash_table (info
);
7050 symtab_hdr
= &elf_symtab_hdr (abfd
);
7051 sym_hashes
= elf_sym_hashes (abfd
);
7053 rel_end
= relocs
+ sec
->reloc_count
;
7054 for (rel
= relocs
; rel
< rel_end
; rel
++)
7056 struct elf_link_hash_entry
*h
;
7057 unsigned long r_symndx
;
7058 unsigned int r_type
;
7059 bfd_reloc_code_real_type bfd_r_type
;
7060 Elf_Internal_Sym
*isym
;
7062 r_symndx
= ELFNN_R_SYM (rel
->r_info
);
7063 r_type
= ELFNN_R_TYPE (rel
->r_info
);
7065 if (r_symndx
>= NUM_SHDR_ENTRIES (symtab_hdr
))
7067 /* xgettext:c-format */
7068 _bfd_error_handler (_("%B: bad symbol index: %d"), abfd
, r_symndx
);
7072 if (r_symndx
< symtab_hdr
->sh_info
)
7074 /* A local symbol. */
7075 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
7080 /* Check relocation against local STT_GNU_IFUNC symbol. */
7081 if (ELF_ST_TYPE (isym
->st_info
) == STT_GNU_IFUNC
)
7083 h
= elfNN_aarch64_get_local_sym_hash (htab
, abfd
, rel
,
7088 /* Fake a STT_GNU_IFUNC symbol. */
7089 h
->type
= STT_GNU_IFUNC
;
7092 h
->forced_local
= 1;
7093 h
->root
.type
= bfd_link_hash_defined
;
7100 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
7101 while (h
->root
.type
== bfd_link_hash_indirect
7102 || h
->root
.type
== bfd_link_hash_warning
)
7103 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
7105 /* PR15323, ref flags aren't set for references in the same
7107 h
->root
.non_ir_ref
= 1;
7110 /* Could be done earlier, if h were already available. */
7111 bfd_r_type
= aarch64_tls_transition (abfd
, info
, r_type
, h
, r_symndx
);
7115 /* If a relocation refers to _GLOBAL_OFFSET_TABLE_, create the .got.
7116 This shows up in particular in an R_AARCH64_PREL64 in large model
7117 when calculating the pc-relative address to .got section which is
7118 used to initialize the gp register. */
7119 if (h
->root
.root
.string
7120 && strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_") == 0)
7122 if (htab
->root
.dynobj
== NULL
)
7123 htab
->root
.dynobj
= abfd
;
7125 if (! aarch64_elf_create_got_section (htab
->root
.dynobj
, info
))
7128 BFD_ASSERT (h
== htab
->root
.hgot
);
7131 /* Create the ifunc sections for static executables. If we
7132 never see an indirect function symbol nor we are building
7133 a static executable, those sections will be empty and
7134 won't appear in output. */
7140 case BFD_RELOC_AARCH64_ADD_LO12
:
7141 case BFD_RELOC_AARCH64_ADR_GOT_PAGE
:
7142 case BFD_RELOC_AARCH64_ADR_HI21_PCREL
:
7143 case BFD_RELOC_AARCH64_CALL26
:
7144 case BFD_RELOC_AARCH64_GOT_LD_PREL19
:
7145 case BFD_RELOC_AARCH64_JUMP26
:
7146 case BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14
:
7147 case BFD_RELOC_AARCH64_LD32_GOT_LO12_NC
:
7148 case BFD_RELOC_AARCH64_LD64_GOTOFF_LO15
:
7149 case BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15
:
7150 case BFD_RELOC_AARCH64_LD64_GOT_LO12_NC
:
7151 case BFD_RELOC_AARCH64_MOVW_GOTOFF_G0_NC
:
7152 case BFD_RELOC_AARCH64_MOVW_GOTOFF_G1
:
7153 case BFD_RELOC_AARCH64_NN
:
7154 if (htab
->root
.dynobj
== NULL
)
7155 htab
->root
.dynobj
= abfd
;
7156 if (!_bfd_elf_create_ifunc_sections (htab
->root
.dynobj
, info
))
7161 /* It is referenced by a non-shared object. */
7163 h
->root
.non_ir_ref
= 1;
7168 case BFD_RELOC_AARCH64_NN
:
7170 /* We don't need to handle relocs into sections not going into
7171 the "real" output. */
7172 if ((sec
->flags
& SEC_ALLOC
) == 0)
7177 if (!bfd_link_pic (info
))
7180 h
->plt
.refcount
+= 1;
7181 h
->pointer_equality_needed
= 1;
7184 /* No need to do anything if we're not creating a shared
7186 if (! bfd_link_pic (info
))
7190 struct elf_dyn_relocs
*p
;
7191 struct elf_dyn_relocs
**head
;
7193 /* We must copy these reloc types into the output file.
7194 Create a reloc section in dynobj and make room for
7198 if (htab
->root
.dynobj
== NULL
)
7199 htab
->root
.dynobj
= abfd
;
7201 sreloc
= _bfd_elf_make_dynamic_reloc_section
7202 (sec
, htab
->root
.dynobj
, LOG_FILE_ALIGN
, abfd
, /*rela? */ TRUE
);
7208 /* If this is a global symbol, we count the number of
7209 relocations we need for this symbol. */
7212 struct elf_aarch64_link_hash_entry
*eh
;
7213 eh
= (struct elf_aarch64_link_hash_entry
*) h
;
7214 head
= &eh
->dyn_relocs
;
7218 /* Track dynamic relocs needed for local syms too.
7219 We really need local syms available to do this
7225 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
7230 s
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
7234 /* Beware of type punned pointers vs strict aliasing
7236 vpp
= &(elf_section_data (s
)->local_dynrel
);
7237 head
= (struct elf_dyn_relocs
**) vpp
;
7241 if (p
== NULL
|| p
->sec
!= sec
)
7243 bfd_size_type amt
= sizeof *p
;
7244 p
= ((struct elf_dyn_relocs
*)
7245 bfd_zalloc (htab
->root
.dynobj
, amt
));
7258 /* RR: We probably want to keep a consistency check that
7259 there are no dangling GOT_PAGE relocs. */
7260 case BFD_RELOC_AARCH64_ADR_GOT_PAGE
:
7261 case BFD_RELOC_AARCH64_GOT_LD_PREL19
:
7262 case BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14
:
7263 case BFD_RELOC_AARCH64_LD32_GOT_LO12_NC
:
7264 case BFD_RELOC_AARCH64_LD64_GOTOFF_LO15
:
7265 case BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15
:
7266 case BFD_RELOC_AARCH64_LD64_GOT_LO12_NC
:
7267 case BFD_RELOC_AARCH64_MOVW_GOTOFF_G0_NC
:
7268 case BFD_RELOC_AARCH64_MOVW_GOTOFF_G1
:
7269 case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12_NC
:
7270 case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21
:
7271 case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21
:
7272 case BFD_RELOC_AARCH64_TLSDESC_LD32_LO12_NC
:
7273 case BFD_RELOC_AARCH64_TLSDESC_LD64_LO12_NC
:
7274 case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19
:
7275 case BFD_RELOC_AARCH64_TLSDESC_OFF_G0_NC
:
7276 case BFD_RELOC_AARCH64_TLSDESC_OFF_G1
:
7277 case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC
:
7278 case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21
:
7279 case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21
:
7280 case BFD_RELOC_AARCH64_TLSGD_MOVW_G0_NC
:
7281 case BFD_RELOC_AARCH64_TLSGD_MOVW_G1
:
7282 case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21
:
7283 case BFD_RELOC_AARCH64_TLSIE_LD32_GOTTPREL_LO12_NC
:
7284 case BFD_RELOC_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC
:
7285 case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19
:
7286 case BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G0_NC
:
7287 case BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G1
:
7288 case BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC
:
7289 case BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21
:
7290 case BFD_RELOC_AARCH64_TLSLD_ADR_PREL21
:
7291 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1
:
7292 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1_NC
:
7293 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G2
:
7296 unsigned old_got_type
;
7298 got_type
= aarch64_reloc_got_type (bfd_r_type
);
7302 h
->got
.refcount
+= 1;
7303 old_got_type
= elf_aarch64_hash_entry (h
)->got_type
;
7307 struct elf_aarch64_local_symbol
*locals
;
7309 if (!elfNN_aarch64_allocate_local_symbols
7310 (abfd
, symtab_hdr
->sh_info
))
7313 locals
= elf_aarch64_locals (abfd
);
7314 BFD_ASSERT (r_symndx
< symtab_hdr
->sh_info
);
7315 locals
[r_symndx
].got_refcount
+= 1;
7316 old_got_type
= locals
[r_symndx
].got_type
;
7319 /* If a variable is accessed with both general dynamic TLS
7320 methods, two slots may be created. */
7321 if (GOT_TLS_GD_ANY_P (old_got_type
) && GOT_TLS_GD_ANY_P (got_type
))
7322 got_type
|= old_got_type
;
7324 /* We will already have issued an error message if there
7325 is a TLS/non-TLS mismatch, based on the symbol type.
7326 So just combine any TLS types needed. */
7327 if (old_got_type
!= GOT_UNKNOWN
&& old_got_type
!= GOT_NORMAL
7328 && got_type
!= GOT_NORMAL
)
7329 got_type
|= old_got_type
;
7331 /* If the symbol is accessed by both IE and GD methods, we
7332 are able to relax. Turn off the GD flag, without
7333 messing up with any other kind of TLS types that may be
7335 if ((got_type
& GOT_TLS_IE
) && GOT_TLS_GD_ANY_P (got_type
))
7336 got_type
&= ~ (GOT_TLSDESC_GD
| GOT_TLS_GD
);
7338 if (old_got_type
!= got_type
)
7341 elf_aarch64_hash_entry (h
)->got_type
= got_type
;
7344 struct elf_aarch64_local_symbol
*locals
;
7345 locals
= elf_aarch64_locals (abfd
);
7346 BFD_ASSERT (r_symndx
< symtab_hdr
->sh_info
);
7347 locals
[r_symndx
].got_type
= got_type
;
7351 if (htab
->root
.dynobj
== NULL
)
7352 htab
->root
.dynobj
= abfd
;
7353 if (! aarch64_elf_create_got_section (htab
->root
.dynobj
, info
))
7358 case BFD_RELOC_AARCH64_MOVW_G0_NC
:
7359 case BFD_RELOC_AARCH64_MOVW_G1_NC
:
7360 case BFD_RELOC_AARCH64_MOVW_G2_NC
:
7361 case BFD_RELOC_AARCH64_MOVW_G3
:
7362 if (bfd_link_pic (info
))
7364 int howto_index
= bfd_r_type
- BFD_RELOC_AARCH64_RELOC_START
;
7366 /* xgettext:c-format */
7367 (_("%B: relocation %s against `%s' can not be used when making "
7368 "a shared object; recompile with -fPIC"),
7369 abfd
, elfNN_aarch64_howto_table
[howto_index
].name
,
7370 (h
) ? h
->root
.root
.string
: "a local symbol");
7371 bfd_set_error (bfd_error_bad_value
);
7376 case BFD_RELOC_AARCH64_ADR_HI21_NC_PCREL
:
7377 case BFD_RELOC_AARCH64_ADR_HI21_PCREL
:
7378 case BFD_RELOC_AARCH64_ADR_LO21_PCREL
:
7379 if (h
!= NULL
&& bfd_link_executable (info
))
7381 /* If this reloc is in a read-only section, we might
7382 need a copy reloc. We can't check reliably at this
7383 stage whether the section is read-only, as input
7384 sections have not yet been mapped to output sections.
7385 Tentatively set the flag for now, and correct in
7386 adjust_dynamic_symbol. */
7388 h
->plt
.refcount
+= 1;
7389 h
->pointer_equality_needed
= 1;
7391 /* FIXME:: RR need to handle these in shared libraries
7392 and essentially bomb out as these being non-PIC
7393 relocations in shared libraries. */
7396 case BFD_RELOC_AARCH64_CALL26
:
7397 case BFD_RELOC_AARCH64_JUMP26
:
7398 /* If this is a local symbol then we resolve it
7399 directly without creating a PLT entry. */
7404 if (h
->plt
.refcount
<= 0)
7405 h
->plt
.refcount
= 1;
7407 h
->plt
.refcount
+= 1;
7418 /* Treat mapping symbols as special target symbols. */
7421 elfNN_aarch64_is_target_special_symbol (bfd
*abfd ATTRIBUTE_UNUSED
,
7424 return bfd_is_aarch64_special_symbol_name (sym
->name
,
7425 BFD_AARCH64_SPECIAL_SYM_TYPE_ANY
);
7428 /* This is a copy of elf_find_function () from elf.c except that
7429 AArch64 mapping symbols are ignored when looking for function names. */
7432 aarch64_elf_find_function (bfd
*abfd ATTRIBUTE_UNUSED
,
7436 const char **filename_ptr
,
7437 const char **functionname_ptr
)
7439 const char *filename
= NULL
;
7440 asymbol
*func
= NULL
;
7441 bfd_vma low_func
= 0;
7444 for (p
= symbols
; *p
!= NULL
; p
++)
7448 q
= (elf_symbol_type
*) * p
;
7450 switch (ELF_ST_TYPE (q
->internal_elf_sym
.st_info
))
7455 filename
= bfd_asymbol_name (&q
->symbol
);
7459 /* Skip mapping symbols. */
7460 if ((q
->symbol
.flags
& BSF_LOCAL
)
7461 && (bfd_is_aarch64_special_symbol_name
7462 (q
->symbol
.name
, BFD_AARCH64_SPECIAL_SYM_TYPE_ANY
)))
7465 if (bfd_get_section (&q
->symbol
) == section
7466 && q
->symbol
.value
>= low_func
&& q
->symbol
.value
<= offset
)
7468 func
= (asymbol
*) q
;
7469 low_func
= q
->symbol
.value
;
7479 *filename_ptr
= filename
;
7480 if (functionname_ptr
)
7481 *functionname_ptr
= bfd_asymbol_name (func
);
7487 /* Find the nearest line to a particular section and offset, for error
7488 reporting. This code is a duplicate of the code in elf.c, except
7489 that it uses aarch64_elf_find_function. */
7492 elfNN_aarch64_find_nearest_line (bfd
*abfd
,
7496 const char **filename_ptr
,
7497 const char **functionname_ptr
,
7498 unsigned int *line_ptr
,
7499 unsigned int *discriminator_ptr
)
7501 bfd_boolean found
= FALSE
;
7503 if (_bfd_dwarf2_find_nearest_line (abfd
, symbols
, NULL
, section
, offset
,
7504 filename_ptr
, functionname_ptr
,
7505 line_ptr
, discriminator_ptr
,
7506 dwarf_debug_sections
, 0,
7507 &elf_tdata (abfd
)->dwarf2_find_line_info
))
7509 if (!*functionname_ptr
)
7510 aarch64_elf_find_function (abfd
, symbols
, section
, offset
,
7511 *filename_ptr
? NULL
: filename_ptr
,
7517 /* Skip _bfd_dwarf1_find_nearest_line since no known AArch64
7518 toolchain uses DWARF1. */
7520 if (!_bfd_stab_section_find_nearest_line (abfd
, symbols
, section
, offset
,
7521 &found
, filename_ptr
,
7522 functionname_ptr
, line_ptr
,
7523 &elf_tdata (abfd
)->line_info
))
7526 if (found
&& (*functionname_ptr
|| *line_ptr
))
7529 if (symbols
== NULL
)
7532 if (!aarch64_elf_find_function (abfd
, symbols
, section
, offset
,
7533 filename_ptr
, functionname_ptr
))
7541 elfNN_aarch64_find_inliner_info (bfd
*abfd
,
7542 const char **filename_ptr
,
7543 const char **functionname_ptr
,
7544 unsigned int *line_ptr
)
7547 found
= _bfd_dwarf2_find_inliner_info
7548 (abfd
, filename_ptr
,
7549 functionname_ptr
, line_ptr
, &elf_tdata (abfd
)->dwarf2_find_line_info
);
7555 elfNN_aarch64_post_process_headers (bfd
*abfd
,
7556 struct bfd_link_info
*link_info
)
7558 Elf_Internal_Ehdr
*i_ehdrp
; /* ELF file header, internal form. */
7560 i_ehdrp
= elf_elfheader (abfd
);
7561 i_ehdrp
->e_ident
[EI_ABIVERSION
] = AARCH64_ELF_ABI_VERSION
;
7563 _bfd_elf_post_process_headers (abfd
, link_info
);
7566 static enum elf_reloc_type_class
7567 elfNN_aarch64_reloc_type_class (const struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
7568 const asection
*rel_sec ATTRIBUTE_UNUSED
,
7569 const Elf_Internal_Rela
*rela
)
7571 switch ((int) ELFNN_R_TYPE (rela
->r_info
))
7573 case AARCH64_R (RELATIVE
):
7574 return reloc_class_relative
;
7575 case AARCH64_R (JUMP_SLOT
):
7576 return reloc_class_plt
;
7577 case AARCH64_R (COPY
):
7578 return reloc_class_copy
;
7580 return reloc_class_normal
;
7584 /* Handle an AArch64 specific section when reading an object file. This is
7585 called when bfd_section_from_shdr finds a section with an unknown
7589 elfNN_aarch64_section_from_shdr (bfd
*abfd
,
7590 Elf_Internal_Shdr
*hdr
,
7591 const char *name
, int shindex
)
7593 /* There ought to be a place to keep ELF backend specific flags, but
7594 at the moment there isn't one. We just keep track of the
7595 sections by their name, instead. Fortunately, the ABI gives
7596 names for all the AArch64 specific sections, so we will probably get
7598 switch (hdr
->sh_type
)
7600 case SHT_AARCH64_ATTRIBUTES
:
7607 if (!_bfd_elf_make_section_from_shdr (abfd
, hdr
, name
, shindex
))
7613 /* A structure used to record a list of sections, independently
7614 of the next and prev fields in the asection structure. */
7615 typedef struct section_list
7618 struct section_list
*next
;
7619 struct section_list
*prev
;
7623 /* Unfortunately we need to keep a list of sections for which
7624 an _aarch64_elf_section_data structure has been allocated. This
7625 is because it is possible for functions like elfNN_aarch64_write_section
7626 to be called on a section which has had an elf_data_structure
7627 allocated for it (and so the used_by_bfd field is valid) but
7628 for which the AArch64 extended version of this structure - the
7629 _aarch64_elf_section_data structure - has not been allocated. */
7630 static section_list
*sections_with_aarch64_elf_section_data
= NULL
;
7633 record_section_with_aarch64_elf_section_data (asection
*sec
)
7635 struct section_list
*entry
;
7637 entry
= bfd_malloc (sizeof (*entry
));
7641 entry
->next
= sections_with_aarch64_elf_section_data
;
7643 if (entry
->next
!= NULL
)
7644 entry
->next
->prev
= entry
;
7645 sections_with_aarch64_elf_section_data
= entry
;
7648 static struct section_list
*
7649 find_aarch64_elf_section_entry (asection
*sec
)
7651 struct section_list
*entry
;
7652 static struct section_list
*last_entry
= NULL
;
7654 /* This is a short cut for the typical case where the sections are added
7655 to the sections_with_aarch64_elf_section_data list in forward order and
7656 then looked up here in backwards order. This makes a real difference
7657 to the ld-srec/sec64k.exp linker test. */
7658 entry
= sections_with_aarch64_elf_section_data
;
7659 if (last_entry
!= NULL
)
7661 if (last_entry
->sec
== sec
)
7663 else if (last_entry
->next
!= NULL
&& last_entry
->next
->sec
== sec
)
7664 entry
= last_entry
->next
;
7667 for (; entry
; entry
= entry
->next
)
7668 if (entry
->sec
== sec
)
7672 /* Record the entry prior to this one - it is the entry we are
7673 most likely to want to locate next time. Also this way if we
7674 have been called from
7675 unrecord_section_with_aarch64_elf_section_data () we will not
7676 be caching a pointer that is about to be freed. */
7677 last_entry
= entry
->prev
;
7683 unrecord_section_with_aarch64_elf_section_data (asection
*sec
)
7685 struct section_list
*entry
;
7687 entry
= find_aarch64_elf_section_entry (sec
);
7691 if (entry
->prev
!= NULL
)
7692 entry
->prev
->next
= entry
->next
;
7693 if (entry
->next
!= NULL
)
7694 entry
->next
->prev
= entry
->prev
;
7695 if (entry
== sections_with_aarch64_elf_section_data
)
7696 sections_with_aarch64_elf_section_data
= entry
->next
;
7705 struct bfd_link_info
*info
;
7708 int (*func
) (void *, const char *, Elf_Internal_Sym
*,
7709 asection
*, struct elf_link_hash_entry
*);
7710 } output_arch_syminfo
;
7712 enum map_symbol_type
7719 /* Output a single mapping symbol. */
7722 elfNN_aarch64_output_map_sym (output_arch_syminfo
*osi
,
7723 enum map_symbol_type type
, bfd_vma offset
)
7725 static const char *names
[2] = { "$x", "$d" };
7726 Elf_Internal_Sym sym
;
7728 sym
.st_value
= (osi
->sec
->output_section
->vma
7729 + osi
->sec
->output_offset
+ offset
);
7732 sym
.st_info
= ELF_ST_INFO (STB_LOCAL
, STT_NOTYPE
);
7733 sym
.st_shndx
= osi
->sec_shndx
;
7734 return osi
->func (osi
->finfo
, names
[type
], &sym
, osi
->sec
, NULL
) == 1;
7737 /* Output a single local symbol for a generated stub. */
7740 elfNN_aarch64_output_stub_sym (output_arch_syminfo
*osi
, const char *name
,
7741 bfd_vma offset
, bfd_vma size
)
7743 Elf_Internal_Sym sym
;
7745 sym
.st_value
= (osi
->sec
->output_section
->vma
7746 + osi
->sec
->output_offset
+ offset
);
7749 sym
.st_info
= ELF_ST_INFO (STB_LOCAL
, STT_FUNC
);
7750 sym
.st_shndx
= osi
->sec_shndx
;
7751 return osi
->func (osi
->finfo
, name
, &sym
, osi
->sec
, NULL
) == 1;
7755 aarch64_map_one_stub (struct bfd_hash_entry
*gen_entry
, void *in_arg
)
7757 struct elf_aarch64_stub_hash_entry
*stub_entry
;
7761 output_arch_syminfo
*osi
;
7763 /* Massage our args to the form they really have. */
7764 stub_entry
= (struct elf_aarch64_stub_hash_entry
*) gen_entry
;
7765 osi
= (output_arch_syminfo
*) in_arg
;
7767 stub_sec
= stub_entry
->stub_sec
;
7769 /* Ensure this stub is attached to the current section being
7771 if (stub_sec
!= osi
->sec
)
7774 addr
= (bfd_vma
) stub_entry
->stub_offset
;
7776 stub_name
= stub_entry
->output_name
;
7778 switch (stub_entry
->stub_type
)
7780 case aarch64_stub_adrp_branch
:
7781 if (!elfNN_aarch64_output_stub_sym (osi
, stub_name
, addr
,
7782 sizeof (aarch64_adrp_branch_stub
)))
7784 if (!elfNN_aarch64_output_map_sym (osi
, AARCH64_MAP_INSN
, addr
))
7787 case aarch64_stub_long_branch
:
7788 if (!elfNN_aarch64_output_stub_sym
7789 (osi
, stub_name
, addr
, sizeof (aarch64_long_branch_stub
)))
7791 if (!elfNN_aarch64_output_map_sym (osi
, AARCH64_MAP_INSN
, addr
))
7793 if (!elfNN_aarch64_output_map_sym (osi
, AARCH64_MAP_DATA
, addr
+ 16))
7796 case aarch64_stub_erratum_835769_veneer
:
7797 if (!elfNN_aarch64_output_stub_sym (osi
, stub_name
, addr
,
7798 sizeof (aarch64_erratum_835769_stub
)))
7800 if (!elfNN_aarch64_output_map_sym (osi
, AARCH64_MAP_INSN
, addr
))
7803 case aarch64_stub_erratum_843419_veneer
:
7804 if (!elfNN_aarch64_output_stub_sym (osi
, stub_name
, addr
,
7805 sizeof (aarch64_erratum_843419_stub
)))
7807 if (!elfNN_aarch64_output_map_sym (osi
, AARCH64_MAP_INSN
, addr
))
7818 /* Output mapping symbols for linker generated sections. */
7821 elfNN_aarch64_output_arch_local_syms (bfd
*output_bfd
,
7822 struct bfd_link_info
*info
,
7824 int (*func
) (void *, const char *,
7827 struct elf_link_hash_entry
7830 output_arch_syminfo osi
;
7831 struct elf_aarch64_link_hash_table
*htab
;
7833 htab
= elf_aarch64_hash_table (info
);
7839 /* Long calls stubs. */
7840 if (htab
->stub_bfd
&& htab
->stub_bfd
->sections
)
7844 for (stub_sec
= htab
->stub_bfd
->sections
;
7845 stub_sec
!= NULL
; stub_sec
= stub_sec
->next
)
7847 /* Ignore non-stub sections. */
7848 if (!strstr (stub_sec
->name
, STUB_SUFFIX
))
7853 osi
.sec_shndx
= _bfd_elf_section_from_bfd_section
7854 (output_bfd
, osi
.sec
->output_section
);
7856 /* The first instruction in a stub is always a branch. */
7857 if (!elfNN_aarch64_output_map_sym (&osi
, AARCH64_MAP_INSN
, 0))
7860 bfd_hash_traverse (&htab
->stub_hash_table
, aarch64_map_one_stub
,
7865 /* Finally, output mapping symbols for the PLT. */
7866 if (!htab
->root
.splt
|| htab
->root
.splt
->size
== 0)
7869 osi
.sec_shndx
= _bfd_elf_section_from_bfd_section
7870 (output_bfd
, htab
->root
.splt
->output_section
);
7871 osi
.sec
= htab
->root
.splt
;
7873 elfNN_aarch64_output_map_sym (&osi
, AARCH64_MAP_INSN
, 0);
7879 /* Allocate target specific section data. */
7882 elfNN_aarch64_new_section_hook (bfd
*abfd
, asection
*sec
)
7884 if (!sec
->used_by_bfd
)
7886 _aarch64_elf_section_data
*sdata
;
7887 bfd_size_type amt
= sizeof (*sdata
);
7889 sdata
= bfd_zalloc (abfd
, amt
);
7892 sec
->used_by_bfd
= sdata
;
7895 record_section_with_aarch64_elf_section_data (sec
);
7897 return _bfd_elf_new_section_hook (abfd
, sec
);
7902 unrecord_section_via_map_over_sections (bfd
*abfd ATTRIBUTE_UNUSED
,
7904 void *ignore ATTRIBUTE_UNUSED
)
7906 unrecord_section_with_aarch64_elf_section_data (sec
);
7910 elfNN_aarch64_close_and_cleanup (bfd
*abfd
)
7913 bfd_map_over_sections (abfd
,
7914 unrecord_section_via_map_over_sections
, NULL
);
7916 return _bfd_elf_close_and_cleanup (abfd
);
7920 elfNN_aarch64_bfd_free_cached_info (bfd
*abfd
)
7923 bfd_map_over_sections (abfd
,
7924 unrecord_section_via_map_over_sections
, NULL
);
7926 return _bfd_free_cached_info (abfd
);
7929 /* Create dynamic sections. This is different from the ARM backend in that
7930 the got, plt, gotplt and their relocation sections are all created in the
7931 standard part of the bfd elf backend. */
7934 elfNN_aarch64_create_dynamic_sections (bfd
*dynobj
,
7935 struct bfd_link_info
*info
)
7937 /* We need to create .got section. */
7938 if (!aarch64_elf_create_got_section (dynobj
, info
))
7941 return _bfd_elf_create_dynamic_sections (dynobj
, info
);
7945 /* Allocate space in .plt, .got and associated reloc sections for
7949 elfNN_aarch64_allocate_dynrelocs (struct elf_link_hash_entry
*h
, void *inf
)
7951 struct bfd_link_info
*info
;
7952 struct elf_aarch64_link_hash_table
*htab
;
7953 struct elf_aarch64_link_hash_entry
*eh
;
7954 struct elf_dyn_relocs
*p
;
7956 /* An example of a bfd_link_hash_indirect symbol is versioned
7957 symbol. For example: __gxx_personality_v0(bfd_link_hash_indirect)
7958 -> __gxx_personality_v0(bfd_link_hash_defined)
7960 There is no need to process bfd_link_hash_indirect symbols here
7961 because we will also be presented with the concrete instance of
7962 the symbol and elfNN_aarch64_copy_indirect_symbol () will have been
7963 called to copy all relevant data from the generic to the concrete
7966 if (h
->root
.type
== bfd_link_hash_indirect
)
7969 if (h
->root
.type
== bfd_link_hash_warning
)
7970 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
7972 info
= (struct bfd_link_info
*) inf
;
7973 htab
= elf_aarch64_hash_table (info
);
7975 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle it
7976 here if it is defined and referenced in a non-shared object. */
7977 if (h
->type
== STT_GNU_IFUNC
7980 else if (htab
->root
.dynamic_sections_created
&& h
->plt
.refcount
> 0)
7982 /* Make sure this symbol is output as a dynamic symbol.
7983 Undefined weak syms won't yet be marked as dynamic. */
7984 if (h
->dynindx
== -1 && !h
->forced_local
)
7986 if (!bfd_elf_link_record_dynamic_symbol (info
, h
))
7990 if (bfd_link_pic (info
) || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h
))
7992 asection
*s
= htab
->root
.splt
;
7994 /* If this is the first .plt entry, make room for the special
7997 s
->size
+= htab
->plt_header_size
;
7999 h
->plt
.offset
= s
->size
;
8001 /* If this symbol is not defined in a regular file, and we are
8002 not generating a shared library, then set the symbol to this
8003 location in the .plt. This is required to make function
8004 pointers compare as equal between the normal executable and
8005 the shared library. */
8006 if (!bfd_link_pic (info
) && !h
->def_regular
)
8008 h
->root
.u
.def
.section
= s
;
8009 h
->root
.u
.def
.value
= h
->plt
.offset
;
8012 /* Make room for this entry. For now we only create the
8013 small model PLT entries. We later need to find a way
8014 of relaxing into these from the large model PLT entries. */
8015 s
->size
+= PLT_SMALL_ENTRY_SIZE
;
8017 /* We also need to make an entry in the .got.plt section, which
8018 will be placed in the .got section by the linker script. */
8019 htab
->root
.sgotplt
->size
+= GOT_ENTRY_SIZE
;
8021 /* We also need to make an entry in the .rela.plt section. */
8022 htab
->root
.srelplt
->size
+= RELOC_SIZE (htab
);
8024 /* We need to ensure that all GOT entries that serve the PLT
8025 are consecutive with the special GOT slots [0] [1] and
8026 [2]. Any addtional relocations, such as
8027 R_AARCH64_TLSDESC, must be placed after the PLT related
8028 entries. We abuse the reloc_count such that during
8029 sizing we adjust reloc_count to indicate the number of
8030 PLT related reserved entries. In subsequent phases when
8031 filling in the contents of the reloc entries, PLT related
8032 entries are placed by computing their PLT index (0
8033 .. reloc_count). While other none PLT relocs are placed
8034 at the slot indicated by reloc_count and reloc_count is
8037 htab
->root
.srelplt
->reloc_count
++;
8041 h
->plt
.offset
= (bfd_vma
) - 1;
8047 h
->plt
.offset
= (bfd_vma
) - 1;
8051 eh
= (struct elf_aarch64_link_hash_entry
*) h
;
8052 eh
->tlsdesc_got_jump_table_offset
= (bfd_vma
) - 1;
8054 if (h
->got
.refcount
> 0)
8057 unsigned got_type
= elf_aarch64_hash_entry (h
)->got_type
;
8059 h
->got
.offset
= (bfd_vma
) - 1;
8061 dyn
= htab
->root
.dynamic_sections_created
;
8063 /* Make sure this symbol is output as a dynamic symbol.
8064 Undefined weak syms won't yet be marked as dynamic. */
8065 if (dyn
&& h
->dynindx
== -1 && !h
->forced_local
)
8067 if (!bfd_elf_link_record_dynamic_symbol (info
, h
))
8071 if (got_type
== GOT_UNKNOWN
)
8074 else if (got_type
== GOT_NORMAL
)
8076 h
->got
.offset
= htab
->root
.sgot
->size
;
8077 htab
->root
.sgot
->size
+= GOT_ENTRY_SIZE
;
8078 if ((ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
8079 || h
->root
.type
!= bfd_link_hash_undefweak
)
8080 && (bfd_link_pic (info
)
8081 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, 0, h
)))
8083 htab
->root
.srelgot
->size
+= RELOC_SIZE (htab
);
8089 if (got_type
& GOT_TLSDESC_GD
)
8091 eh
->tlsdesc_got_jump_table_offset
=
8092 (htab
->root
.sgotplt
->size
8093 - aarch64_compute_jump_table_size (htab
));
8094 htab
->root
.sgotplt
->size
+= GOT_ENTRY_SIZE
* 2;
8095 h
->got
.offset
= (bfd_vma
) - 2;
8098 if (got_type
& GOT_TLS_GD
)
8100 h
->got
.offset
= htab
->root
.sgot
->size
;
8101 htab
->root
.sgot
->size
+= GOT_ENTRY_SIZE
* 2;
8104 if (got_type
& GOT_TLS_IE
)
8106 h
->got
.offset
= htab
->root
.sgot
->size
;
8107 htab
->root
.sgot
->size
+= GOT_ENTRY_SIZE
;
8110 indx
= h
&& h
->dynindx
!= -1 ? h
->dynindx
: 0;
8111 if ((ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
8112 || h
->root
.type
!= bfd_link_hash_undefweak
)
8113 && (bfd_link_pic (info
)
8115 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, 0, h
)))
8117 if (got_type
& GOT_TLSDESC_GD
)
8119 htab
->root
.srelplt
->size
+= RELOC_SIZE (htab
);
8120 /* Note reloc_count not incremented here! We have
8121 already adjusted reloc_count for this relocation
8124 /* TLSDESC PLT is now needed, but not yet determined. */
8125 htab
->tlsdesc_plt
= (bfd_vma
) - 1;
8128 if (got_type
& GOT_TLS_GD
)
8129 htab
->root
.srelgot
->size
+= RELOC_SIZE (htab
) * 2;
8131 if (got_type
& GOT_TLS_IE
)
8132 htab
->root
.srelgot
->size
+= RELOC_SIZE (htab
);
8138 h
->got
.offset
= (bfd_vma
) - 1;
8141 if (eh
->dyn_relocs
== NULL
)
8144 /* In the shared -Bsymbolic case, discard space allocated for
8145 dynamic pc-relative relocs against symbols which turn out to be
8146 defined in regular objects. For the normal shared case, discard
8147 space for pc-relative relocs that have become local due to symbol
8148 visibility changes. */
8150 if (bfd_link_pic (info
))
8152 /* Relocs that use pc_count are those that appear on a call
8153 insn, or certain REL relocs that can generated via assembly.
8154 We want calls to protected symbols to resolve directly to the
8155 function rather than going via the plt. If people want
8156 function pointer comparisons to work as expected then they
8157 should avoid writing weird assembly. */
8158 if (SYMBOL_CALLS_LOCAL (info
, h
))
8160 struct elf_dyn_relocs
**pp
;
8162 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
;)
8164 p
->count
-= p
->pc_count
;
8173 /* Also discard relocs on undefined weak syms with non-default
8175 if (eh
->dyn_relocs
!= NULL
&& h
->root
.type
== bfd_link_hash_undefweak
)
8177 if (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
)
8178 eh
->dyn_relocs
= NULL
;
8180 /* Make sure undefined weak symbols are output as a dynamic
8182 else if (h
->dynindx
== -1
8184 && !bfd_elf_link_record_dynamic_symbol (info
, h
))
8189 else if (ELIMINATE_COPY_RELOCS
)
8191 /* For the non-shared case, discard space for relocs against
8192 symbols which turn out to need copy relocs or are not
8198 || (htab
->root
.dynamic_sections_created
8199 && (h
->root
.type
== bfd_link_hash_undefweak
8200 || h
->root
.type
== bfd_link_hash_undefined
))))
8202 /* Make sure this symbol is output as a dynamic symbol.
8203 Undefined weak syms won't yet be marked as dynamic. */
8204 if (h
->dynindx
== -1
8206 && !bfd_elf_link_record_dynamic_symbol (info
, h
))
8209 /* If that succeeded, we know we'll be keeping all the
8211 if (h
->dynindx
!= -1)
8215 eh
->dyn_relocs
= NULL
;
8220 /* Finally, allocate space. */
8221 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
8225 sreloc
= elf_section_data (p
->sec
)->sreloc
;
8227 BFD_ASSERT (sreloc
!= NULL
);
8229 sreloc
->size
+= p
->count
* RELOC_SIZE (htab
);
8235 /* Allocate space in .plt, .got and associated reloc sections for
8236 ifunc dynamic relocs. */
8239 elfNN_aarch64_allocate_ifunc_dynrelocs (struct elf_link_hash_entry
*h
,
8242 struct bfd_link_info
*info
;
8243 struct elf_aarch64_link_hash_table
*htab
;
8244 struct elf_aarch64_link_hash_entry
*eh
;
8246 /* An example of a bfd_link_hash_indirect symbol is versioned
8247 symbol. For example: __gxx_personality_v0(bfd_link_hash_indirect)
8248 -> __gxx_personality_v0(bfd_link_hash_defined)
8250 There is no need to process bfd_link_hash_indirect symbols here
8251 because we will also be presented with the concrete instance of
8252 the symbol and elfNN_aarch64_copy_indirect_symbol () will have been
8253 called to copy all relevant data from the generic to the concrete
8256 if (h
->root
.type
== bfd_link_hash_indirect
)
8259 if (h
->root
.type
== bfd_link_hash_warning
)
8260 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
8262 info
= (struct bfd_link_info
*) inf
;
8263 htab
= elf_aarch64_hash_table (info
);
8265 eh
= (struct elf_aarch64_link_hash_entry
*) h
;
8267 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle it
8268 here if it is defined and referenced in a non-shared object. */
8269 if (h
->type
== STT_GNU_IFUNC
8271 return _bfd_elf_allocate_ifunc_dyn_relocs (info
, h
,
8274 htab
->plt_entry_size
,
8275 htab
->plt_header_size
,
8281 /* Allocate space in .plt, .got and associated reloc sections for
8282 local dynamic relocs. */
8285 elfNN_aarch64_allocate_local_dynrelocs (void **slot
, void *inf
)
8287 struct elf_link_hash_entry
*h
8288 = (struct elf_link_hash_entry
*) *slot
;
8290 if (h
->type
!= STT_GNU_IFUNC
8294 || h
->root
.type
!= bfd_link_hash_defined
)
8297 return elfNN_aarch64_allocate_dynrelocs (h
, inf
);
8300 /* Allocate space in .plt, .got and associated reloc sections for
8301 local ifunc dynamic relocs. */
8304 elfNN_aarch64_allocate_local_ifunc_dynrelocs (void **slot
, void *inf
)
8306 struct elf_link_hash_entry
*h
8307 = (struct elf_link_hash_entry
*) *slot
;
8309 if (h
->type
!= STT_GNU_IFUNC
8313 || h
->root
.type
!= bfd_link_hash_defined
)
8316 return elfNN_aarch64_allocate_ifunc_dynrelocs (h
, inf
);
8319 /* Find any dynamic relocs that apply to read-only sections. */
8322 aarch64_readonly_dynrelocs (struct elf_link_hash_entry
* h
, void * inf
)
8324 struct elf_aarch64_link_hash_entry
* eh
;
8325 struct elf_dyn_relocs
* p
;
8327 eh
= (struct elf_aarch64_link_hash_entry
*) h
;
8328 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
8330 asection
*s
= p
->sec
;
8332 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
8334 struct bfd_link_info
*info
= (struct bfd_link_info
*) inf
;
8336 info
->flags
|= DF_TEXTREL
;
8338 /* Not an error, just cut short the traversal. */
8345 /* This is the most important function of all . Innocuosly named
8348 elfNN_aarch64_size_dynamic_sections (bfd
*output_bfd ATTRIBUTE_UNUSED
,
8349 struct bfd_link_info
*info
)
8351 struct elf_aarch64_link_hash_table
*htab
;
8357 htab
= elf_aarch64_hash_table ((info
));
8358 dynobj
= htab
->root
.dynobj
;
8360 BFD_ASSERT (dynobj
!= NULL
);
8362 if (htab
->root
.dynamic_sections_created
)
8364 if (bfd_link_executable (info
) && !info
->nointerp
)
8366 s
= bfd_get_linker_section (dynobj
, ".interp");
8369 s
->size
= sizeof ELF_DYNAMIC_INTERPRETER
;
8370 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
8374 /* Set up .got offsets for local syms, and space for local dynamic
8376 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
8378 struct elf_aarch64_local_symbol
*locals
= NULL
;
8379 Elf_Internal_Shdr
*symtab_hdr
;
8383 if (!is_aarch64_elf (ibfd
))
8386 for (s
= ibfd
->sections
; s
!= NULL
; s
= s
->next
)
8388 struct elf_dyn_relocs
*p
;
8390 for (p
= (struct elf_dyn_relocs
*)
8391 (elf_section_data (s
)->local_dynrel
); p
!= NULL
; p
= p
->next
)
8393 if (!bfd_is_abs_section (p
->sec
)
8394 && bfd_is_abs_section (p
->sec
->output_section
))
8396 /* Input section has been discarded, either because
8397 it is a copy of a linkonce section or due to
8398 linker script /DISCARD/, so we'll be discarding
8401 else if (p
->count
!= 0)
8403 srel
= elf_section_data (p
->sec
)->sreloc
;
8404 srel
->size
+= p
->count
* RELOC_SIZE (htab
);
8405 if ((p
->sec
->output_section
->flags
& SEC_READONLY
) != 0)
8406 info
->flags
|= DF_TEXTREL
;
8411 locals
= elf_aarch64_locals (ibfd
);
8415 symtab_hdr
= &elf_symtab_hdr (ibfd
);
8416 srel
= htab
->root
.srelgot
;
8417 for (i
= 0; i
< symtab_hdr
->sh_info
; i
++)
8419 locals
[i
].got_offset
= (bfd_vma
) - 1;
8420 locals
[i
].tlsdesc_got_jump_table_offset
= (bfd_vma
) - 1;
8421 if (locals
[i
].got_refcount
> 0)
8423 unsigned got_type
= locals
[i
].got_type
;
8424 if (got_type
& GOT_TLSDESC_GD
)
8426 locals
[i
].tlsdesc_got_jump_table_offset
=
8427 (htab
->root
.sgotplt
->size
8428 - aarch64_compute_jump_table_size (htab
));
8429 htab
->root
.sgotplt
->size
+= GOT_ENTRY_SIZE
* 2;
8430 locals
[i
].got_offset
= (bfd_vma
) - 2;
8433 if (got_type
& GOT_TLS_GD
)
8435 locals
[i
].got_offset
= htab
->root
.sgot
->size
;
8436 htab
->root
.sgot
->size
+= GOT_ENTRY_SIZE
* 2;
8439 if (got_type
& GOT_TLS_IE
8440 || got_type
& GOT_NORMAL
)
8442 locals
[i
].got_offset
= htab
->root
.sgot
->size
;
8443 htab
->root
.sgot
->size
+= GOT_ENTRY_SIZE
;
8446 if (got_type
== GOT_UNKNOWN
)
8450 if (bfd_link_pic (info
))
8452 if (got_type
& GOT_TLSDESC_GD
)
8454 htab
->root
.srelplt
->size
+= RELOC_SIZE (htab
);
8455 /* Note RELOC_COUNT not incremented here! */
8456 htab
->tlsdesc_plt
= (bfd_vma
) - 1;
8459 if (got_type
& GOT_TLS_GD
)
8460 htab
->root
.srelgot
->size
+= RELOC_SIZE (htab
) * 2;
8462 if (got_type
& GOT_TLS_IE
8463 || got_type
& GOT_NORMAL
)
8464 htab
->root
.srelgot
->size
+= RELOC_SIZE (htab
);
8469 locals
[i
].got_refcount
= (bfd_vma
) - 1;
8475 /* Allocate global sym .plt and .got entries, and space for global
8476 sym dynamic relocs. */
8477 elf_link_hash_traverse (&htab
->root
, elfNN_aarch64_allocate_dynrelocs
,
8480 /* Allocate global ifunc sym .plt and .got entries, and space for global
8481 ifunc sym dynamic relocs. */
8482 elf_link_hash_traverse (&htab
->root
, elfNN_aarch64_allocate_ifunc_dynrelocs
,
8485 /* Allocate .plt and .got entries, and space for local symbols. */
8486 htab_traverse (htab
->loc_hash_table
,
8487 elfNN_aarch64_allocate_local_dynrelocs
,
8490 /* Allocate .plt and .got entries, and space for local ifunc symbols. */
8491 htab_traverse (htab
->loc_hash_table
,
8492 elfNN_aarch64_allocate_local_ifunc_dynrelocs
,
8495 /* For every jump slot reserved in the sgotplt, reloc_count is
8496 incremented. However, when we reserve space for TLS descriptors,
8497 it's not incremented, so in order to compute the space reserved
8498 for them, it suffices to multiply the reloc count by the jump
8501 if (htab
->root
.srelplt
)
8502 htab
->sgotplt_jump_table_size
= aarch64_compute_jump_table_size (htab
);
8504 if (htab
->tlsdesc_plt
)
8506 if (htab
->root
.splt
->size
== 0)
8507 htab
->root
.splt
->size
+= PLT_ENTRY_SIZE
;
8509 htab
->tlsdesc_plt
= htab
->root
.splt
->size
;
8510 htab
->root
.splt
->size
+= PLT_TLSDESC_ENTRY_SIZE
;
8512 /* If we're not using lazy TLS relocations, don't generate the
8513 GOT entry required. */
8514 if (!(info
->flags
& DF_BIND_NOW
))
8516 htab
->dt_tlsdesc_got
= htab
->root
.sgot
->size
;
8517 htab
->root
.sgot
->size
+= GOT_ENTRY_SIZE
;
8521 /* Init mapping symbols information to use later to distingush between
8522 code and data while scanning for errata. */
8523 if (htab
->fix_erratum_835769
|| htab
->fix_erratum_843419
)
8524 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
8526 if (!is_aarch64_elf (ibfd
))
8528 bfd_elfNN_aarch64_init_maps (ibfd
);
8531 /* We now have determined the sizes of the various dynamic sections.
8532 Allocate memory for them. */
8534 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
8536 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
8539 if (s
== htab
->root
.splt
8540 || s
== htab
->root
.sgot
8541 || s
== htab
->root
.sgotplt
8542 || s
== htab
->root
.iplt
8543 || s
== htab
->root
.igotplt
8544 || s
== htab
->root
.sdynbss
8545 || s
== htab
->root
.sdynrelro
)
8547 /* Strip this section if we don't need it; see the
8550 else if (CONST_STRNEQ (bfd_get_section_name (dynobj
, s
), ".rela"))
8552 if (s
->size
!= 0 && s
!= htab
->root
.srelplt
)
8555 /* We use the reloc_count field as a counter if we need
8556 to copy relocs into the output file. */
8557 if (s
!= htab
->root
.srelplt
)
8562 /* It's not one of our sections, so don't allocate space. */
8568 /* If we don't need this section, strip it from the
8569 output file. This is mostly to handle .rela.bss and
8570 .rela.plt. We must create both sections in
8571 create_dynamic_sections, because they must be created
8572 before the linker maps input sections to output
8573 sections. The linker does that before
8574 adjust_dynamic_symbol is called, and it is that
8575 function which decides whether anything needs to go
8576 into these sections. */
8578 s
->flags
|= SEC_EXCLUDE
;
8582 if ((s
->flags
& SEC_HAS_CONTENTS
) == 0)
8585 /* Allocate memory for the section contents. We use bfd_zalloc
8586 here in case unused entries are not reclaimed before the
8587 section's contents are written out. This should not happen,
8588 but this way if it does, we get a R_AARCH64_NONE reloc instead
8590 s
->contents
= (bfd_byte
*) bfd_zalloc (dynobj
, s
->size
);
8591 if (s
->contents
== NULL
)
8595 if (htab
->root
.dynamic_sections_created
)
8597 /* Add some entries to the .dynamic section. We fill in the
8598 values later, in elfNN_aarch64_finish_dynamic_sections, but we
8599 must add the entries now so that we get the correct size for
8600 the .dynamic section. The DT_DEBUG entry is filled in by the
8601 dynamic linker and used by the debugger. */
8602 #define add_dynamic_entry(TAG, VAL) \
8603 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
8605 if (bfd_link_executable (info
))
8607 if (!add_dynamic_entry (DT_DEBUG
, 0))
8611 if (htab
->root
.splt
->size
!= 0)
8613 if (!add_dynamic_entry (DT_PLTGOT
, 0)
8614 || !add_dynamic_entry (DT_PLTRELSZ
, 0)
8615 || !add_dynamic_entry (DT_PLTREL
, DT_RELA
)
8616 || !add_dynamic_entry (DT_JMPREL
, 0))
8619 if (htab
->tlsdesc_plt
8620 && (!add_dynamic_entry (DT_TLSDESC_PLT
, 0)
8621 || !add_dynamic_entry (DT_TLSDESC_GOT
, 0)))
8627 if (!add_dynamic_entry (DT_RELA
, 0)
8628 || !add_dynamic_entry (DT_RELASZ
, 0)
8629 || !add_dynamic_entry (DT_RELAENT
, RELOC_SIZE (htab
)))
8632 /* If any dynamic relocs apply to a read-only section,
8633 then we need a DT_TEXTREL entry. */
8634 if ((info
->flags
& DF_TEXTREL
) == 0)
8635 elf_link_hash_traverse (& htab
->root
, aarch64_readonly_dynrelocs
,
8638 if ((info
->flags
& DF_TEXTREL
) != 0)
8640 if (!add_dynamic_entry (DT_TEXTREL
, 0))
8645 #undef add_dynamic_entry
8651 elf_aarch64_update_plt_entry (bfd
*output_bfd
,
8652 bfd_reloc_code_real_type r_type
,
8653 bfd_byte
*plt_entry
, bfd_vma value
)
8655 reloc_howto_type
*howto
= elfNN_aarch64_howto_from_bfd_reloc (r_type
);
8657 _bfd_aarch64_elf_put_addend (output_bfd
, plt_entry
, r_type
, howto
, value
);
8661 elfNN_aarch64_create_small_pltn_entry (struct elf_link_hash_entry
*h
,
8662 struct elf_aarch64_link_hash_table
8663 *htab
, bfd
*output_bfd
,
8664 struct bfd_link_info
*info
)
8666 bfd_byte
*plt_entry
;
8669 bfd_vma gotplt_entry_address
;
8670 bfd_vma plt_entry_address
;
8671 Elf_Internal_Rela rela
;
8673 asection
*plt
, *gotplt
, *relplt
;
8675 /* When building a static executable, use .iplt, .igot.plt and
8676 .rela.iplt sections for STT_GNU_IFUNC symbols. */
8677 if (htab
->root
.splt
!= NULL
)
8679 plt
= htab
->root
.splt
;
8680 gotplt
= htab
->root
.sgotplt
;
8681 relplt
= htab
->root
.srelplt
;
8685 plt
= htab
->root
.iplt
;
8686 gotplt
= htab
->root
.igotplt
;
8687 relplt
= htab
->root
.irelplt
;
8690 /* Get the index in the procedure linkage table which
8691 corresponds to this symbol. This is the index of this symbol
8692 in all the symbols for which we are making plt entries. The
8693 first entry in the procedure linkage table is reserved.
8695 Get the offset into the .got table of the entry that
8696 corresponds to this function. Each .got entry is GOT_ENTRY_SIZE
8697 bytes. The first three are reserved for the dynamic linker.
8699 For static executables, we don't reserve anything. */
8701 if (plt
== htab
->root
.splt
)
8703 plt_index
= (h
->plt
.offset
- htab
->plt_header_size
) / htab
->plt_entry_size
;
8704 got_offset
= (plt_index
+ 3) * GOT_ENTRY_SIZE
;
8708 plt_index
= h
->plt
.offset
/ htab
->plt_entry_size
;
8709 got_offset
= plt_index
* GOT_ENTRY_SIZE
;
8712 plt_entry
= plt
->contents
+ h
->plt
.offset
;
8713 plt_entry_address
= plt
->output_section
->vma
8714 + plt
->output_offset
+ h
->plt
.offset
;
8715 gotplt_entry_address
= gotplt
->output_section
->vma
+
8716 gotplt
->output_offset
+ got_offset
;
8718 /* Copy in the boiler-plate for the PLTn entry. */
8719 memcpy (plt_entry
, elfNN_aarch64_small_plt_entry
, PLT_SMALL_ENTRY_SIZE
);
8721 /* Fill in the top 21 bits for this: ADRP x16, PLT_GOT + n * 8.
8722 ADRP: ((PG(S+A)-PG(P)) >> 12) & 0x1fffff */
8723 elf_aarch64_update_plt_entry (output_bfd
, BFD_RELOC_AARCH64_ADR_HI21_PCREL
,
8725 PG (gotplt_entry_address
) -
8726 PG (plt_entry_address
));
8728 /* Fill in the lo12 bits for the load from the pltgot. */
8729 elf_aarch64_update_plt_entry (output_bfd
, BFD_RELOC_AARCH64_LDSTNN_LO12
,
8731 PG_OFFSET (gotplt_entry_address
));
8733 /* Fill in the lo12 bits for the add from the pltgot entry. */
8734 elf_aarch64_update_plt_entry (output_bfd
, BFD_RELOC_AARCH64_ADD_LO12
,
8736 PG_OFFSET (gotplt_entry_address
));
8738 /* All the GOTPLT Entries are essentially initialized to PLT0. */
8739 bfd_put_NN (output_bfd
,
8740 plt
->output_section
->vma
+ plt
->output_offset
,
8741 gotplt
->contents
+ got_offset
);
8743 rela
.r_offset
= gotplt_entry_address
;
8745 if (h
->dynindx
== -1
8746 || ((bfd_link_executable (info
)
8747 || ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
)
8749 && h
->type
== STT_GNU_IFUNC
))
8751 /* If an STT_GNU_IFUNC symbol is locally defined, generate
8752 R_AARCH64_IRELATIVE instead of R_AARCH64_JUMP_SLOT. */
8753 rela
.r_info
= ELFNN_R_INFO (0, AARCH64_R (IRELATIVE
));
8754 rela
.r_addend
= (h
->root
.u
.def
.value
8755 + h
->root
.u
.def
.section
->output_section
->vma
8756 + h
->root
.u
.def
.section
->output_offset
);
8760 /* Fill in the entry in the .rela.plt section. */
8761 rela
.r_info
= ELFNN_R_INFO (h
->dynindx
, AARCH64_R (JUMP_SLOT
));
8765 /* Compute the relocation entry to used based on PLT index and do
8766 not adjust reloc_count. The reloc_count has already been adjusted
8767 to account for this entry. */
8768 loc
= relplt
->contents
+ plt_index
* RELOC_SIZE (htab
);
8769 bfd_elfNN_swap_reloca_out (output_bfd
, &rela
, loc
);
8772 /* Size sections even though they're not dynamic. We use it to setup
8773 _TLS_MODULE_BASE_, if needed. */
8776 elfNN_aarch64_always_size_sections (bfd
*output_bfd
,
8777 struct bfd_link_info
*info
)
8781 if (bfd_link_relocatable (info
))
8784 tls_sec
= elf_hash_table (info
)->tls_sec
;
8788 struct elf_link_hash_entry
*tlsbase
;
8790 tlsbase
= elf_link_hash_lookup (elf_hash_table (info
),
8791 "_TLS_MODULE_BASE_", TRUE
, TRUE
, FALSE
);
8795 struct bfd_link_hash_entry
*h
= NULL
;
8796 const struct elf_backend_data
*bed
=
8797 get_elf_backend_data (output_bfd
);
8799 if (!(_bfd_generic_link_add_one_symbol
8800 (info
, output_bfd
, "_TLS_MODULE_BASE_", BSF_LOCAL
,
8801 tls_sec
, 0, NULL
, FALSE
, bed
->collect
, &h
)))
8804 tlsbase
->type
= STT_TLS
;
8805 tlsbase
= (struct elf_link_hash_entry
*) h
;
8806 tlsbase
->def_regular
= 1;
8807 tlsbase
->other
= STV_HIDDEN
;
8808 (*bed
->elf_backend_hide_symbol
) (info
, tlsbase
, TRUE
);
8815 /* Finish up dynamic symbol handling. We set the contents of various
8816 dynamic sections here. */
8818 elfNN_aarch64_finish_dynamic_symbol (bfd
*output_bfd
,
8819 struct bfd_link_info
*info
,
8820 struct elf_link_hash_entry
*h
,
8821 Elf_Internal_Sym
*sym
)
8823 struct elf_aarch64_link_hash_table
*htab
;
8824 htab
= elf_aarch64_hash_table (info
);
8826 if (h
->plt
.offset
!= (bfd_vma
) - 1)
8828 asection
*plt
, *gotplt
, *relplt
;
8830 /* This symbol has an entry in the procedure linkage table. Set
8833 /* When building a static executable, use .iplt, .igot.plt and
8834 .rela.iplt sections for STT_GNU_IFUNC symbols. */
8835 if (htab
->root
.splt
!= NULL
)
8837 plt
= htab
->root
.splt
;
8838 gotplt
= htab
->root
.sgotplt
;
8839 relplt
= htab
->root
.srelplt
;
8843 plt
= htab
->root
.iplt
;
8844 gotplt
= htab
->root
.igotplt
;
8845 relplt
= htab
->root
.irelplt
;
8848 /* This symbol has an entry in the procedure linkage table. Set
8850 if ((h
->dynindx
== -1
8851 && !((h
->forced_local
|| bfd_link_executable (info
))
8853 && h
->type
== STT_GNU_IFUNC
))
8859 elfNN_aarch64_create_small_pltn_entry (h
, htab
, output_bfd
, info
);
8860 if (!h
->def_regular
)
8862 /* Mark the symbol as undefined, rather than as defined in
8863 the .plt section. */
8864 sym
->st_shndx
= SHN_UNDEF
;
8865 /* If the symbol is weak we need to clear the value.
8866 Otherwise, the PLT entry would provide a definition for
8867 the symbol even if the symbol wasn't defined anywhere,
8868 and so the symbol would never be NULL. Leave the value if
8869 there were any relocations where pointer equality matters
8870 (this is a clue for the dynamic linker, to make function
8871 pointer comparisons work between an application and shared
8873 if (!h
->ref_regular_nonweak
|| !h
->pointer_equality_needed
)
8878 if (h
->got
.offset
!= (bfd_vma
) - 1
8879 && elf_aarch64_hash_entry (h
)->got_type
== GOT_NORMAL
)
8881 Elf_Internal_Rela rela
;
8884 /* This symbol has an entry in the global offset table. Set it
8886 if (htab
->root
.sgot
== NULL
|| htab
->root
.srelgot
== NULL
)
8889 rela
.r_offset
= (htab
->root
.sgot
->output_section
->vma
8890 + htab
->root
.sgot
->output_offset
8891 + (h
->got
.offset
& ~(bfd_vma
) 1));
8894 && h
->type
== STT_GNU_IFUNC
)
8896 if (bfd_link_pic (info
))
8898 /* Generate R_AARCH64_GLOB_DAT. */
8905 if (!h
->pointer_equality_needed
)
8908 /* For non-shared object, we can't use .got.plt, which
8909 contains the real function address if we need pointer
8910 equality. We load the GOT entry with the PLT entry. */
8911 plt
= htab
->root
.splt
? htab
->root
.splt
: htab
->root
.iplt
;
8912 bfd_put_NN (output_bfd
, (plt
->output_section
->vma
8913 + plt
->output_offset
8915 htab
->root
.sgot
->contents
8916 + (h
->got
.offset
& ~(bfd_vma
) 1));
8920 else if (bfd_link_pic (info
) && SYMBOL_REFERENCES_LOCAL (info
, h
))
8922 if (!h
->def_regular
)
8925 BFD_ASSERT ((h
->got
.offset
& 1) != 0);
8926 rela
.r_info
= ELFNN_R_INFO (0, AARCH64_R (RELATIVE
));
8927 rela
.r_addend
= (h
->root
.u
.def
.value
8928 + h
->root
.u
.def
.section
->output_section
->vma
8929 + h
->root
.u
.def
.section
->output_offset
);
8934 BFD_ASSERT ((h
->got
.offset
& 1) == 0);
8935 bfd_put_NN (output_bfd
, (bfd_vma
) 0,
8936 htab
->root
.sgot
->contents
+ h
->got
.offset
);
8937 rela
.r_info
= ELFNN_R_INFO (h
->dynindx
, AARCH64_R (GLOB_DAT
));
8941 loc
= htab
->root
.srelgot
->contents
;
8942 loc
+= htab
->root
.srelgot
->reloc_count
++ * RELOC_SIZE (htab
);
8943 bfd_elfNN_swap_reloca_out (output_bfd
, &rela
, loc
);
8948 Elf_Internal_Rela rela
;
8952 /* This symbol needs a copy reloc. Set it up. */
8954 if (h
->dynindx
== -1
8955 || (h
->root
.type
!= bfd_link_hash_defined
8956 && h
->root
.type
!= bfd_link_hash_defweak
)
8957 || htab
->root
.srelbss
== NULL
)
8960 rela
.r_offset
= (h
->root
.u
.def
.value
8961 + h
->root
.u
.def
.section
->output_section
->vma
8962 + h
->root
.u
.def
.section
->output_offset
);
8963 rela
.r_info
= ELFNN_R_INFO (h
->dynindx
, AARCH64_R (COPY
));
8965 if ((h
->root
.u
.def
.section
->flags
& SEC_READONLY
) != 0)
8966 s
= htab
->root
.sreldynrelro
;
8968 s
= htab
->root
.srelbss
;
8969 loc
= s
->contents
+ s
->reloc_count
++ * RELOC_SIZE (htab
);
8970 bfd_elfNN_swap_reloca_out (output_bfd
, &rela
, loc
);
8973 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. SYM may
8974 be NULL for local symbols. */
8976 && (h
== elf_hash_table (info
)->hdynamic
8977 || h
== elf_hash_table (info
)->hgot
))
8978 sym
->st_shndx
= SHN_ABS
;
8983 /* Finish up local dynamic symbol handling. We set the contents of
8984 various dynamic sections here. */
8987 elfNN_aarch64_finish_local_dynamic_symbol (void **slot
, void *inf
)
8989 struct elf_link_hash_entry
*h
8990 = (struct elf_link_hash_entry
*) *slot
;
8991 struct bfd_link_info
*info
8992 = (struct bfd_link_info
*) inf
;
8994 return elfNN_aarch64_finish_dynamic_symbol (info
->output_bfd
,
8999 elfNN_aarch64_init_small_plt0_entry (bfd
*output_bfd ATTRIBUTE_UNUSED
,
9000 struct elf_aarch64_link_hash_table
9003 /* Fill in PLT0. Fixme:RR Note this doesn't distinguish between
9004 small and large plts and at the minute just generates
9007 /* PLT0 of the small PLT looks like this in ELF64 -
9008 stp x16, x30, [sp, #-16]! // Save the reloc and lr on stack.
9009 adrp x16, PLT_GOT + 16 // Get the page base of the GOTPLT
9010 ldr x17, [x16, #:lo12:PLT_GOT+16] // Load the address of the
9012 add x16, x16, #:lo12:PLT_GOT+16 // Load the lo12 bits of the
9013 // GOTPLT entry for this.
9015 PLT0 will be slightly different in ELF32 due to different got entry
9018 bfd_vma plt_got_2nd_ent
; /* Address of GOT[2]. */
9022 memcpy (htab
->root
.splt
->contents
, elfNN_aarch64_small_plt0_entry
,
9024 elf_section_data (htab
->root
.splt
->output_section
)->this_hdr
.sh_entsize
=
9027 plt_got_2nd_ent
= (htab
->root
.sgotplt
->output_section
->vma
9028 + htab
->root
.sgotplt
->output_offset
9029 + GOT_ENTRY_SIZE
* 2);
9031 plt_base
= htab
->root
.splt
->output_section
->vma
+
9032 htab
->root
.splt
->output_offset
;
9034 /* Fill in the top 21 bits for this: ADRP x16, PLT_GOT + n * 8.
9035 ADRP: ((PG(S+A)-PG(P)) >> 12) & 0x1fffff */
9036 elf_aarch64_update_plt_entry (output_bfd
, BFD_RELOC_AARCH64_ADR_HI21_PCREL
,
9037 htab
->root
.splt
->contents
+ 4,
9038 PG (plt_got_2nd_ent
) - PG (plt_base
+ 4));
9040 elf_aarch64_update_plt_entry (output_bfd
, BFD_RELOC_AARCH64_LDSTNN_LO12
,
9041 htab
->root
.splt
->contents
+ 8,
9042 PG_OFFSET (plt_got_2nd_ent
));
9044 elf_aarch64_update_plt_entry (output_bfd
, BFD_RELOC_AARCH64_ADD_LO12
,
9045 htab
->root
.splt
->contents
+ 12,
9046 PG_OFFSET (plt_got_2nd_ent
));
9050 elfNN_aarch64_finish_dynamic_sections (bfd
*output_bfd
,
9051 struct bfd_link_info
*info
)
9053 struct elf_aarch64_link_hash_table
*htab
;
9057 htab
= elf_aarch64_hash_table (info
);
9058 dynobj
= htab
->root
.dynobj
;
9059 sdyn
= bfd_get_linker_section (dynobj
, ".dynamic");
9061 if (htab
->root
.dynamic_sections_created
)
9063 ElfNN_External_Dyn
*dyncon
, *dynconend
;
9065 if (sdyn
== NULL
|| htab
->root
.sgot
== NULL
)
9068 dyncon
= (ElfNN_External_Dyn
*) sdyn
->contents
;
9069 dynconend
= (ElfNN_External_Dyn
*) (sdyn
->contents
+ sdyn
->size
);
9070 for (; dyncon
< dynconend
; dyncon
++)
9072 Elf_Internal_Dyn dyn
;
9075 bfd_elfNN_swap_dyn_in (dynobj
, dyncon
, &dyn
);
9083 s
= htab
->root
.sgotplt
;
9084 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
9088 s
= htab
->root
.srelplt
;
9089 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
9093 s
= htab
->root
.srelplt
;
9094 dyn
.d_un
.d_val
= s
->size
;
9097 case DT_TLSDESC_PLT
:
9098 s
= htab
->root
.splt
;
9099 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
9100 + htab
->tlsdesc_plt
;
9103 case DT_TLSDESC_GOT
:
9104 s
= htab
->root
.sgot
;
9105 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
9106 + htab
->dt_tlsdesc_got
;
9110 bfd_elfNN_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
9115 /* Fill in the special first entry in the procedure linkage table. */
9116 if (htab
->root
.splt
&& htab
->root
.splt
->size
> 0)
9118 elfNN_aarch64_init_small_plt0_entry (output_bfd
, htab
);
9120 elf_section_data (htab
->root
.splt
->output_section
)->
9121 this_hdr
.sh_entsize
= htab
->plt_entry_size
;
9124 if (htab
->tlsdesc_plt
)
9126 bfd_put_NN (output_bfd
, (bfd_vma
) 0,
9127 htab
->root
.sgot
->contents
+ htab
->dt_tlsdesc_got
);
9129 memcpy (htab
->root
.splt
->contents
+ htab
->tlsdesc_plt
,
9130 elfNN_aarch64_tlsdesc_small_plt_entry
,
9131 sizeof (elfNN_aarch64_tlsdesc_small_plt_entry
));
9134 bfd_vma adrp1_addr
=
9135 htab
->root
.splt
->output_section
->vma
9136 + htab
->root
.splt
->output_offset
+ htab
->tlsdesc_plt
+ 4;
9138 bfd_vma adrp2_addr
= adrp1_addr
+ 4;
9141 htab
->root
.sgot
->output_section
->vma
9142 + htab
->root
.sgot
->output_offset
;
9144 bfd_vma pltgot_addr
=
9145 htab
->root
.sgotplt
->output_section
->vma
9146 + htab
->root
.sgotplt
->output_offset
;
9148 bfd_vma dt_tlsdesc_got
= got_addr
+ htab
->dt_tlsdesc_got
;
9150 bfd_byte
*plt_entry
=
9151 htab
->root
.splt
->contents
+ htab
->tlsdesc_plt
;
9153 /* adrp x2, DT_TLSDESC_GOT */
9154 elf_aarch64_update_plt_entry (output_bfd
,
9155 BFD_RELOC_AARCH64_ADR_HI21_PCREL
,
9157 (PG (dt_tlsdesc_got
)
9158 - PG (adrp1_addr
)));
9161 elf_aarch64_update_plt_entry (output_bfd
,
9162 BFD_RELOC_AARCH64_ADR_HI21_PCREL
,
9165 - PG (adrp2_addr
)));
9167 /* ldr x2, [x2, #0] */
9168 elf_aarch64_update_plt_entry (output_bfd
,
9169 BFD_RELOC_AARCH64_LDSTNN_LO12
,
9171 PG_OFFSET (dt_tlsdesc_got
));
9174 elf_aarch64_update_plt_entry (output_bfd
,
9175 BFD_RELOC_AARCH64_ADD_LO12
,
9177 PG_OFFSET (pltgot_addr
));
9182 if (htab
->root
.sgotplt
)
9184 if (bfd_is_abs_section (htab
->root
.sgotplt
->output_section
))
9187 (_("discarded output section: `%A'"), htab
->root
.sgotplt
);
9191 /* Fill in the first three entries in the global offset table. */
9192 if (htab
->root
.sgotplt
->size
> 0)
9194 bfd_put_NN (output_bfd
, (bfd_vma
) 0, htab
->root
.sgotplt
->contents
);
9196 /* Write GOT[1] and GOT[2], needed for the dynamic linker. */
9197 bfd_put_NN (output_bfd
,
9199 htab
->root
.sgotplt
->contents
+ GOT_ENTRY_SIZE
);
9200 bfd_put_NN (output_bfd
,
9202 htab
->root
.sgotplt
->contents
+ GOT_ENTRY_SIZE
* 2);
9205 if (htab
->root
.sgot
)
9207 if (htab
->root
.sgot
->size
> 0)
9210 sdyn
? sdyn
->output_section
->vma
+ sdyn
->output_offset
: 0;
9211 bfd_put_NN (output_bfd
, addr
, htab
->root
.sgot
->contents
);
9215 elf_section_data (htab
->root
.sgotplt
->output_section
)->
9216 this_hdr
.sh_entsize
= GOT_ENTRY_SIZE
;
9219 if (htab
->root
.sgot
&& htab
->root
.sgot
->size
> 0)
9220 elf_section_data (htab
->root
.sgot
->output_section
)->this_hdr
.sh_entsize
9223 /* Fill PLT and GOT entries for local STT_GNU_IFUNC symbols. */
9224 htab_traverse (htab
->loc_hash_table
,
9225 elfNN_aarch64_finish_local_dynamic_symbol
,
9231 /* Return address for Ith PLT stub in section PLT, for relocation REL
9232 or (bfd_vma) -1 if it should not be included. */
9235 elfNN_aarch64_plt_sym_val (bfd_vma i
, const asection
*plt
,
9236 const arelent
*rel ATTRIBUTE_UNUSED
)
9238 return plt
->vma
+ PLT_ENTRY_SIZE
+ i
* PLT_SMALL_ENTRY_SIZE
;
9241 /* Returns TRUE if NAME is an AArch64 mapping symbol.
9242 The ARM ELF standard defines $x (for A64 code) and $d (for data).
9243 It also allows a period initiated suffix to be added to the symbol, ie:
9244 "$[adtx]\.[:sym_char]+". */
9247 is_aarch64_mapping_symbol (const char * name
)
9249 return name
!= NULL
/* Paranoia. */
9250 && name
[0] == '$' /* Note: if objcopy --prefix-symbols has been used then
9251 the mapping symbols could have acquired a prefix.
9252 We do not support this here, since such symbols no
9253 longer conform to the ARM ELF ABI. */
9254 && (name
[1] == 'd' || name
[1] == 'x')
9255 && (name
[2] == 0 || name
[2] == '.');
9256 /* FIXME: Strictly speaking the symbol is only a valid mapping symbol if
9257 any characters that follow the period are legal characters for the body
9258 of a symbol's name. For now we just assume that this is the case. */
9261 /* Make sure that mapping symbols in object files are not removed via the
9262 "strip --strip-unneeded" tool. These symbols might needed in order to
9263 correctly generate linked files. Once an object file has been linked,
9264 it should be safe to remove them. */
9267 elfNN_aarch64_backend_symbol_processing (bfd
*abfd
, asymbol
*sym
)
9269 if (((abfd
->flags
& (EXEC_P
| DYNAMIC
)) == 0)
9270 && sym
->section
!= bfd_abs_section_ptr
9271 && is_aarch64_mapping_symbol (sym
->name
))
9272 sym
->flags
|= BSF_KEEP
;
9276 /* We use this so we can override certain functions
9277 (though currently we don't). */
9279 const struct elf_size_info elfNN_aarch64_size_info
=
9281 sizeof (ElfNN_External_Ehdr
),
9282 sizeof (ElfNN_External_Phdr
),
9283 sizeof (ElfNN_External_Shdr
),
9284 sizeof (ElfNN_External_Rel
),
9285 sizeof (ElfNN_External_Rela
),
9286 sizeof (ElfNN_External_Sym
),
9287 sizeof (ElfNN_External_Dyn
),
9288 sizeof (Elf_External_Note
),
9289 4, /* Hash table entry size. */
9290 1, /* Internal relocs per external relocs. */
9291 ARCH_SIZE
, /* Arch size. */
9292 LOG_FILE_ALIGN
, /* Log_file_align. */
9293 ELFCLASSNN
, EV_CURRENT
,
9294 bfd_elfNN_write_out_phdrs
,
9295 bfd_elfNN_write_shdrs_and_ehdr
,
9296 bfd_elfNN_checksum_contents
,
9297 bfd_elfNN_write_relocs
,
9298 bfd_elfNN_swap_symbol_in
,
9299 bfd_elfNN_swap_symbol_out
,
9300 bfd_elfNN_slurp_reloc_table
,
9301 bfd_elfNN_slurp_symbol_table
,
9302 bfd_elfNN_swap_dyn_in
,
9303 bfd_elfNN_swap_dyn_out
,
9304 bfd_elfNN_swap_reloc_in
,
9305 bfd_elfNN_swap_reloc_out
,
9306 bfd_elfNN_swap_reloca_in
,
9307 bfd_elfNN_swap_reloca_out
9310 #define ELF_ARCH bfd_arch_aarch64
9311 #define ELF_MACHINE_CODE EM_AARCH64
9312 #define ELF_MAXPAGESIZE 0x10000
9313 #define ELF_MINPAGESIZE 0x1000
9314 #define ELF_COMMONPAGESIZE 0x1000
9316 #define bfd_elfNN_close_and_cleanup \
9317 elfNN_aarch64_close_and_cleanup
9319 #define bfd_elfNN_bfd_free_cached_info \
9320 elfNN_aarch64_bfd_free_cached_info
9322 #define bfd_elfNN_bfd_is_target_special_symbol \
9323 elfNN_aarch64_is_target_special_symbol
9325 #define bfd_elfNN_bfd_link_hash_table_create \
9326 elfNN_aarch64_link_hash_table_create
9328 #define bfd_elfNN_bfd_merge_private_bfd_data \
9329 elfNN_aarch64_merge_private_bfd_data
9331 #define bfd_elfNN_bfd_print_private_bfd_data \
9332 elfNN_aarch64_print_private_bfd_data
9334 #define bfd_elfNN_bfd_reloc_type_lookup \
9335 elfNN_aarch64_reloc_type_lookup
9337 #define bfd_elfNN_bfd_reloc_name_lookup \
9338 elfNN_aarch64_reloc_name_lookup
9340 #define bfd_elfNN_bfd_set_private_flags \
9341 elfNN_aarch64_set_private_flags
9343 #define bfd_elfNN_find_inliner_info \
9344 elfNN_aarch64_find_inliner_info
9346 #define bfd_elfNN_find_nearest_line \
9347 elfNN_aarch64_find_nearest_line
9349 #define bfd_elfNN_mkobject \
9350 elfNN_aarch64_mkobject
9352 #define bfd_elfNN_new_section_hook \
9353 elfNN_aarch64_new_section_hook
9355 #define elf_backend_adjust_dynamic_symbol \
9356 elfNN_aarch64_adjust_dynamic_symbol
9358 #define elf_backend_always_size_sections \
9359 elfNN_aarch64_always_size_sections
9361 #define elf_backend_check_relocs \
9362 elfNN_aarch64_check_relocs
9364 #define elf_backend_copy_indirect_symbol \
9365 elfNN_aarch64_copy_indirect_symbol
9367 /* Create .dynbss, and .rela.bss sections in DYNOBJ, and set up shortcuts
9368 to them in our hash. */
9369 #define elf_backend_create_dynamic_sections \
9370 elfNN_aarch64_create_dynamic_sections
9372 #define elf_backend_init_index_section \
9373 _bfd_elf_init_2_index_sections
9375 #define elf_backend_finish_dynamic_sections \
9376 elfNN_aarch64_finish_dynamic_sections
9378 #define elf_backend_finish_dynamic_symbol \
9379 elfNN_aarch64_finish_dynamic_symbol
9381 #define elf_backend_gc_sweep_hook \
9382 elfNN_aarch64_gc_sweep_hook
9384 #define elf_backend_object_p \
9385 elfNN_aarch64_object_p
9387 #define elf_backend_output_arch_local_syms \
9388 elfNN_aarch64_output_arch_local_syms
9390 #define elf_backend_plt_sym_val \
9391 elfNN_aarch64_plt_sym_val
9393 #define elf_backend_post_process_headers \
9394 elfNN_aarch64_post_process_headers
9396 #define elf_backend_relocate_section \
9397 elfNN_aarch64_relocate_section
9399 #define elf_backend_reloc_type_class \
9400 elfNN_aarch64_reloc_type_class
9402 #define elf_backend_section_from_shdr \
9403 elfNN_aarch64_section_from_shdr
9405 #define elf_backend_size_dynamic_sections \
9406 elfNN_aarch64_size_dynamic_sections
9408 #define elf_backend_size_info \
9409 elfNN_aarch64_size_info
9411 #define elf_backend_write_section \
9412 elfNN_aarch64_write_section
9414 #define elf_backend_symbol_processing \
9415 elfNN_aarch64_backend_symbol_processing
9417 #define elf_backend_can_refcount 1
9418 #define elf_backend_can_gc_sections 1
9419 #define elf_backend_plt_readonly 1
9420 #define elf_backend_want_got_plt 1
9421 #define elf_backend_want_plt_sym 0
9422 #define elf_backend_want_dynrelro 1
9423 #define elf_backend_may_use_rel_p 0
9424 #define elf_backend_may_use_rela_p 1
9425 #define elf_backend_default_use_rela_p 1
9426 #define elf_backend_rela_normal 1
9427 #define elf_backend_dtrel_excludes_plt 1
9428 #define elf_backend_got_header_size (GOT_ENTRY_SIZE * 3)
9429 #define elf_backend_default_execstack 0
9430 #define elf_backend_extern_protected_data 1
9431 #define elf_backend_hash_symbol elf_aarch64_hash_symbol
9433 #undef elf_backend_obj_attrs_section
9434 #define elf_backend_obj_attrs_section ".ARM.attributes"
9436 #include "elfNN-target.h"
9438 /* CloudABI support. */
9440 #undef TARGET_LITTLE_SYM
9441 #define TARGET_LITTLE_SYM aarch64_elfNN_le_cloudabi_vec
9442 #undef TARGET_LITTLE_NAME
9443 #define TARGET_LITTLE_NAME "elfNN-littleaarch64-cloudabi"
9444 #undef TARGET_BIG_SYM
9445 #define TARGET_BIG_SYM aarch64_elfNN_be_cloudabi_vec
9446 #undef TARGET_BIG_NAME
9447 #define TARGET_BIG_NAME "elfNN-bigaarch64-cloudabi"
9450 #define ELF_OSABI ELFOSABI_CLOUDABI
9453 #define elfNN_bed elfNN_aarch64_cloudabi_bed
9455 #include "elfNN-target.h"