1 /* AArch64-specific support for NN-bit ELF.
2 Copyright (C) 2009-2016 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. */
343 HOWTO (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 */
357 HOWTO (R_AARCH64_NONE, /* type */
359 3, /* size (0 = byte, 1 = short, 2 = long) */
361 FALSE, /* pc_relative */
363 complain_overflow_dont, /* complain_on_overflow */
364 bfd_elf_generic_reloc, /* special_function */
365 "R_AARCH64_NONE", /* name */
366 FALSE, /* partial_inplace */
369 FALSE), /* pcrel_offset */
373 HOWTO64 (AARCH64_R (ABS64), /* type */
375 4, /* size (4 = long long) */
377 FALSE, /* pc_relative */
379 complain_overflow_unsigned, /* complain_on_overflow */
380 bfd_elf_generic_reloc, /* special_function */
381 AARCH64_R_STR (ABS64), /* name */
382 FALSE, /* partial_inplace */
383 ALL_ONES, /* src_mask */
384 ALL_ONES, /* dst_mask */
385 FALSE), /* pcrel_offset */
388 HOWTO (AARCH64_R (ABS32), /* type */
390 2, /* size (0 = byte, 1 = short, 2 = long) */
392 FALSE, /* pc_relative */
394 complain_overflow_unsigned, /* complain_on_overflow */
395 bfd_elf_generic_reloc, /* special_function */
396 AARCH64_R_STR (ABS32), /* name */
397 FALSE, /* partial_inplace */
398 0xffffffff, /* src_mask */
399 0xffffffff, /* dst_mask */
400 FALSE), /* pcrel_offset */
403 HOWTO (AARCH64_R (ABS16), /* type */
405 1, /* size (0 = byte, 1 = short, 2 = long) */
407 FALSE, /* pc_relative */
409 complain_overflow_unsigned, /* complain_on_overflow */
410 bfd_elf_generic_reloc, /* special_function */
411 AARCH64_R_STR (ABS16), /* name */
412 FALSE, /* partial_inplace */
413 0xffff, /* src_mask */
414 0xffff, /* dst_mask */
415 FALSE), /* pcrel_offset */
417 /* .xword: (S+A-P) */
418 HOWTO64 (AARCH64_R (PREL64), /* type */
420 4, /* size (4 = long long) */
422 TRUE, /* pc_relative */
424 complain_overflow_signed, /* complain_on_overflow */
425 bfd_elf_generic_reloc, /* special_function */
426 AARCH64_R_STR (PREL64), /* name */
427 FALSE, /* partial_inplace */
428 ALL_ONES, /* src_mask */
429 ALL_ONES, /* dst_mask */
430 TRUE), /* pcrel_offset */
433 HOWTO (AARCH64_R (PREL32), /* type */
435 2, /* size (0 = byte, 1 = short, 2 = long) */
437 TRUE, /* pc_relative */
439 complain_overflow_signed, /* complain_on_overflow */
440 bfd_elf_generic_reloc, /* special_function */
441 AARCH64_R_STR (PREL32), /* name */
442 FALSE, /* partial_inplace */
443 0xffffffff, /* src_mask */
444 0xffffffff, /* dst_mask */
445 TRUE), /* pcrel_offset */
448 HOWTO (AARCH64_R (PREL16), /* type */
450 1, /* size (0 = byte, 1 = short, 2 = long) */
452 TRUE, /* pc_relative */
454 complain_overflow_signed, /* complain_on_overflow */
455 bfd_elf_generic_reloc, /* special_function */
456 AARCH64_R_STR (PREL16), /* name */
457 FALSE, /* partial_inplace */
458 0xffff, /* src_mask */
459 0xffff, /* dst_mask */
460 TRUE), /* pcrel_offset */
462 /* Group relocations to create a 16, 32, 48 or 64 bit
463 unsigned data or abs address inline. */
465 /* MOVZ: ((S+A) >> 0) & 0xffff */
466 HOWTO (AARCH64_R (MOVW_UABS_G0), /* type */
468 2, /* size (0 = byte, 1 = short, 2 = long) */
470 FALSE, /* pc_relative */
472 complain_overflow_unsigned, /* complain_on_overflow */
473 bfd_elf_generic_reloc, /* special_function */
474 AARCH64_R_STR (MOVW_UABS_G0), /* name */
475 FALSE, /* partial_inplace */
476 0xffff, /* src_mask */
477 0xffff, /* dst_mask */
478 FALSE), /* pcrel_offset */
480 /* MOVK: ((S+A) >> 0) & 0xffff [no overflow check] */
481 HOWTO (AARCH64_R (MOVW_UABS_G0_NC), /* type */
483 2, /* size (0 = byte, 1 = short, 2 = long) */
485 FALSE, /* pc_relative */
487 complain_overflow_dont, /* complain_on_overflow */
488 bfd_elf_generic_reloc, /* special_function */
489 AARCH64_R_STR (MOVW_UABS_G0_NC), /* name */
490 FALSE, /* partial_inplace */
491 0xffff, /* src_mask */
492 0xffff, /* dst_mask */
493 FALSE), /* pcrel_offset */
495 /* MOVZ: ((S+A) >> 16) & 0xffff */
496 HOWTO (AARCH64_R (MOVW_UABS_G1), /* type */
498 2, /* size (0 = byte, 1 = short, 2 = long) */
500 FALSE, /* pc_relative */
502 complain_overflow_unsigned, /* complain_on_overflow */
503 bfd_elf_generic_reloc, /* special_function */
504 AARCH64_R_STR (MOVW_UABS_G1), /* name */
505 FALSE, /* partial_inplace */
506 0xffff, /* src_mask */
507 0xffff, /* dst_mask */
508 FALSE), /* pcrel_offset */
510 /* MOVK: ((S+A) >> 16) & 0xffff [no overflow check] */
511 HOWTO64 (AARCH64_R (MOVW_UABS_G1_NC), /* type */
513 2, /* size (0 = byte, 1 = short, 2 = long) */
515 FALSE, /* pc_relative */
517 complain_overflow_dont, /* complain_on_overflow */
518 bfd_elf_generic_reloc, /* special_function */
519 AARCH64_R_STR (MOVW_UABS_G1_NC), /* name */
520 FALSE, /* partial_inplace */
521 0xffff, /* src_mask */
522 0xffff, /* dst_mask */
523 FALSE), /* pcrel_offset */
525 /* MOVZ: ((S+A) >> 32) & 0xffff */
526 HOWTO64 (AARCH64_R (MOVW_UABS_G2), /* type */
528 2, /* size (0 = byte, 1 = short, 2 = long) */
530 FALSE, /* pc_relative */
532 complain_overflow_unsigned, /* complain_on_overflow */
533 bfd_elf_generic_reloc, /* special_function */
534 AARCH64_R_STR (MOVW_UABS_G2), /* name */
535 FALSE, /* partial_inplace */
536 0xffff, /* src_mask */
537 0xffff, /* dst_mask */
538 FALSE), /* pcrel_offset */
540 /* MOVK: ((S+A) >> 32) & 0xffff [no overflow check] */
541 HOWTO64 (AARCH64_R (MOVW_UABS_G2_NC), /* type */
543 2, /* size (0 = byte, 1 = short, 2 = long) */
545 FALSE, /* pc_relative */
547 complain_overflow_dont, /* complain_on_overflow */
548 bfd_elf_generic_reloc, /* special_function */
549 AARCH64_R_STR (MOVW_UABS_G2_NC), /* name */
550 FALSE, /* partial_inplace */
551 0xffff, /* src_mask */
552 0xffff, /* dst_mask */
553 FALSE), /* pcrel_offset */
555 /* MOVZ: ((S+A) >> 48) & 0xffff */
556 HOWTO64 (AARCH64_R (MOVW_UABS_G3), /* type */
558 2, /* size (0 = byte, 1 = short, 2 = long) */
560 FALSE, /* pc_relative */
562 complain_overflow_unsigned, /* complain_on_overflow */
563 bfd_elf_generic_reloc, /* special_function */
564 AARCH64_R_STR (MOVW_UABS_G3), /* name */
565 FALSE, /* partial_inplace */
566 0xffff, /* src_mask */
567 0xffff, /* dst_mask */
568 FALSE), /* pcrel_offset */
570 /* Group relocations to create high part of a 16, 32, 48 or 64 bit
571 signed data or abs address inline. Will change instruction
572 to MOVN or MOVZ depending on sign of calculated value. */
574 /* MOV[ZN]: ((S+A) >> 0) & 0xffff */
575 HOWTO (AARCH64_R (MOVW_SABS_G0), /* type */
577 2, /* size (0 = byte, 1 = short, 2 = long) */
579 FALSE, /* pc_relative */
581 complain_overflow_signed, /* complain_on_overflow */
582 bfd_elf_generic_reloc, /* special_function */
583 AARCH64_R_STR (MOVW_SABS_G0), /* name */
584 FALSE, /* partial_inplace */
585 0xffff, /* src_mask */
586 0xffff, /* dst_mask */
587 FALSE), /* pcrel_offset */
589 /* MOV[ZN]: ((S+A) >> 16) & 0xffff */
590 HOWTO64 (AARCH64_R (MOVW_SABS_G1), /* type */
592 2, /* size (0 = byte, 1 = short, 2 = long) */
594 FALSE, /* pc_relative */
596 complain_overflow_signed, /* complain_on_overflow */
597 bfd_elf_generic_reloc, /* special_function */
598 AARCH64_R_STR (MOVW_SABS_G1), /* name */
599 FALSE, /* partial_inplace */
600 0xffff, /* src_mask */
601 0xffff, /* dst_mask */
602 FALSE), /* pcrel_offset */
604 /* MOV[ZN]: ((S+A) >> 32) & 0xffff */
605 HOWTO64 (AARCH64_R (MOVW_SABS_G2), /* type */
607 2, /* size (0 = byte, 1 = short, 2 = long) */
609 FALSE, /* pc_relative */
611 complain_overflow_signed, /* complain_on_overflow */
612 bfd_elf_generic_reloc, /* special_function */
613 AARCH64_R_STR (MOVW_SABS_G2), /* name */
614 FALSE, /* partial_inplace */
615 0xffff, /* src_mask */
616 0xffff, /* dst_mask */
617 FALSE), /* pcrel_offset */
619 /* Relocations to generate 19, 21 and 33 bit PC-relative load/store
620 addresses: PG(x) is (x & ~0xfff). */
622 /* LD-lit: ((S+A-P) >> 2) & 0x7ffff */
623 HOWTO (AARCH64_R (LD_PREL_LO19), /* type */
625 2, /* size (0 = byte, 1 = short, 2 = long) */
627 TRUE, /* pc_relative */
629 complain_overflow_signed, /* complain_on_overflow */
630 bfd_elf_generic_reloc, /* special_function */
631 AARCH64_R_STR (LD_PREL_LO19), /* name */
632 FALSE, /* partial_inplace */
633 0x7ffff, /* src_mask */
634 0x7ffff, /* dst_mask */
635 TRUE), /* pcrel_offset */
637 /* ADR: (S+A-P) & 0x1fffff */
638 HOWTO (AARCH64_R (ADR_PREL_LO21), /* type */
640 2, /* size (0 = byte, 1 = short, 2 = long) */
642 TRUE, /* pc_relative */
644 complain_overflow_signed, /* complain_on_overflow */
645 bfd_elf_generic_reloc, /* special_function */
646 AARCH64_R_STR (ADR_PREL_LO21), /* name */
647 FALSE, /* partial_inplace */
648 0x1fffff, /* src_mask */
649 0x1fffff, /* dst_mask */
650 TRUE), /* pcrel_offset */
652 /* ADRP: ((PG(S+A)-PG(P)) >> 12) & 0x1fffff */
653 HOWTO (AARCH64_R (ADR_PREL_PG_HI21), /* type */
655 2, /* size (0 = byte, 1 = short, 2 = long) */
657 TRUE, /* pc_relative */
659 complain_overflow_signed, /* complain_on_overflow */
660 bfd_elf_generic_reloc, /* special_function */
661 AARCH64_R_STR (ADR_PREL_PG_HI21), /* name */
662 FALSE, /* partial_inplace */
663 0x1fffff, /* src_mask */
664 0x1fffff, /* dst_mask */
665 TRUE), /* pcrel_offset */
667 /* ADRP: ((PG(S+A)-PG(P)) >> 12) & 0x1fffff [no overflow check] */
668 HOWTO64 (AARCH64_R (ADR_PREL_PG_HI21_NC), /* type */
670 2, /* size (0 = byte, 1 = short, 2 = long) */
672 TRUE, /* pc_relative */
674 complain_overflow_dont, /* complain_on_overflow */
675 bfd_elf_generic_reloc, /* special_function */
676 AARCH64_R_STR (ADR_PREL_PG_HI21_NC), /* name */
677 FALSE, /* partial_inplace */
678 0x1fffff, /* src_mask */
679 0x1fffff, /* dst_mask */
680 TRUE), /* pcrel_offset */
682 /* ADD: (S+A) & 0xfff [no overflow check] */
683 HOWTO (AARCH64_R (ADD_ABS_LO12_NC), /* type */
685 2, /* size (0 = byte, 1 = short, 2 = long) */
687 FALSE, /* pc_relative */
689 complain_overflow_dont, /* complain_on_overflow */
690 bfd_elf_generic_reloc, /* special_function */
691 AARCH64_R_STR (ADD_ABS_LO12_NC), /* name */
692 FALSE, /* partial_inplace */
693 0x3ffc00, /* src_mask */
694 0x3ffc00, /* dst_mask */
695 FALSE), /* pcrel_offset */
697 /* LD/ST8: (S+A) & 0xfff */
698 HOWTO (AARCH64_R (LDST8_ABS_LO12_NC), /* type */
700 2, /* size (0 = byte, 1 = short, 2 = long) */
702 FALSE, /* pc_relative */
704 complain_overflow_dont, /* complain_on_overflow */
705 bfd_elf_generic_reloc, /* special_function */
706 AARCH64_R_STR (LDST8_ABS_LO12_NC), /* name */
707 FALSE, /* partial_inplace */
708 0xfff, /* src_mask */
709 0xfff, /* dst_mask */
710 FALSE), /* pcrel_offset */
712 /* Relocations for control-flow instructions. */
714 /* TBZ/NZ: ((S+A-P) >> 2) & 0x3fff */
715 HOWTO (AARCH64_R (TSTBR14), /* type */
717 2, /* size (0 = byte, 1 = short, 2 = long) */
719 TRUE, /* pc_relative */
721 complain_overflow_signed, /* complain_on_overflow */
722 bfd_elf_generic_reloc, /* special_function */
723 AARCH64_R_STR (TSTBR14), /* name */
724 FALSE, /* partial_inplace */
725 0x3fff, /* src_mask */
726 0x3fff, /* dst_mask */
727 TRUE), /* pcrel_offset */
729 /* B.cond: ((S+A-P) >> 2) & 0x7ffff */
730 HOWTO (AARCH64_R (CONDBR19), /* type */
732 2, /* size (0 = byte, 1 = short, 2 = long) */
734 TRUE, /* pc_relative */
736 complain_overflow_signed, /* complain_on_overflow */
737 bfd_elf_generic_reloc, /* special_function */
738 AARCH64_R_STR (CONDBR19), /* name */
739 FALSE, /* partial_inplace */
740 0x7ffff, /* src_mask */
741 0x7ffff, /* dst_mask */
742 TRUE), /* pcrel_offset */
744 /* B: ((S+A-P) >> 2) & 0x3ffffff */
745 HOWTO (AARCH64_R (JUMP26), /* type */
747 2, /* size (0 = byte, 1 = short, 2 = long) */
749 TRUE, /* pc_relative */
751 complain_overflow_signed, /* complain_on_overflow */
752 bfd_elf_generic_reloc, /* special_function */
753 AARCH64_R_STR (JUMP26), /* name */
754 FALSE, /* partial_inplace */
755 0x3ffffff, /* src_mask */
756 0x3ffffff, /* dst_mask */
757 TRUE), /* pcrel_offset */
759 /* BL: ((S+A-P) >> 2) & 0x3ffffff */
760 HOWTO (AARCH64_R (CALL26), /* type */
762 2, /* size (0 = byte, 1 = short, 2 = long) */
764 TRUE, /* pc_relative */
766 complain_overflow_signed, /* complain_on_overflow */
767 bfd_elf_generic_reloc, /* special_function */
768 AARCH64_R_STR (CALL26), /* name */
769 FALSE, /* partial_inplace */
770 0x3ffffff, /* src_mask */
771 0x3ffffff, /* dst_mask */
772 TRUE), /* pcrel_offset */
774 /* LD/ST16: (S+A) & 0xffe */
775 HOWTO (AARCH64_R (LDST16_ABS_LO12_NC), /* type */
777 2, /* size (0 = byte, 1 = short, 2 = long) */
779 FALSE, /* pc_relative */
781 complain_overflow_dont, /* complain_on_overflow */
782 bfd_elf_generic_reloc, /* special_function */
783 AARCH64_R_STR (LDST16_ABS_LO12_NC), /* name */
784 FALSE, /* partial_inplace */
785 0xffe, /* src_mask */
786 0xffe, /* dst_mask */
787 FALSE), /* pcrel_offset */
789 /* LD/ST32: (S+A) & 0xffc */
790 HOWTO (AARCH64_R (LDST32_ABS_LO12_NC), /* type */
792 2, /* size (0 = byte, 1 = short, 2 = long) */
794 FALSE, /* pc_relative */
796 complain_overflow_dont, /* complain_on_overflow */
797 bfd_elf_generic_reloc, /* special_function */
798 AARCH64_R_STR (LDST32_ABS_LO12_NC), /* name */
799 FALSE, /* partial_inplace */
800 0xffc, /* src_mask */
801 0xffc, /* dst_mask */
802 FALSE), /* pcrel_offset */
804 /* LD/ST64: (S+A) & 0xff8 */
805 HOWTO (AARCH64_R (LDST64_ABS_LO12_NC), /* type */
807 2, /* size (0 = byte, 1 = short, 2 = long) */
809 FALSE, /* pc_relative */
811 complain_overflow_dont, /* complain_on_overflow */
812 bfd_elf_generic_reloc, /* special_function */
813 AARCH64_R_STR (LDST64_ABS_LO12_NC), /* name */
814 FALSE, /* partial_inplace */
815 0xff8, /* src_mask */
816 0xff8, /* dst_mask */
817 FALSE), /* pcrel_offset */
819 /* LD/ST128: (S+A) & 0xff0 */
820 HOWTO (AARCH64_R (LDST128_ABS_LO12_NC), /* type */
822 2, /* size (0 = byte, 1 = short, 2 = long) */
824 FALSE, /* pc_relative */
826 complain_overflow_dont, /* complain_on_overflow */
827 bfd_elf_generic_reloc, /* special_function */
828 AARCH64_R_STR (LDST128_ABS_LO12_NC), /* name */
829 FALSE, /* partial_inplace */
830 0xff0, /* src_mask */
831 0xff0, /* dst_mask */
832 FALSE), /* pcrel_offset */
834 /* Set a load-literal immediate field to bits
835 0x1FFFFC of G(S)-P */
836 HOWTO (AARCH64_R (GOT_LD_PREL19), /* type */
838 2, /* size (0 = byte,1 = short,2 = long) */
840 TRUE, /* pc_relative */
842 complain_overflow_signed, /* complain_on_overflow */
843 bfd_elf_generic_reloc, /* special_function */
844 AARCH64_R_STR (GOT_LD_PREL19), /* name */
845 FALSE, /* partial_inplace */
846 0xffffe0, /* src_mask */
847 0xffffe0, /* dst_mask */
848 TRUE), /* pcrel_offset */
850 /* Get to the page for the GOT entry for the symbol
851 (G(S) - P) using an ADRP instruction. */
852 HOWTO (AARCH64_R (ADR_GOT_PAGE), /* type */
854 2, /* size (0 = byte, 1 = short, 2 = long) */
856 TRUE, /* pc_relative */
858 complain_overflow_dont, /* complain_on_overflow */
859 bfd_elf_generic_reloc, /* special_function */
860 AARCH64_R_STR (ADR_GOT_PAGE), /* name */
861 FALSE, /* partial_inplace */
862 0x1fffff, /* src_mask */
863 0x1fffff, /* dst_mask */
864 TRUE), /* pcrel_offset */
866 /* LD64: GOT offset G(S) & 0xff8 */
867 HOWTO64 (AARCH64_R (LD64_GOT_LO12_NC), /* type */
869 2, /* size (0 = byte, 1 = short, 2 = long) */
871 FALSE, /* pc_relative */
873 complain_overflow_dont, /* complain_on_overflow */
874 bfd_elf_generic_reloc, /* special_function */
875 AARCH64_R_STR (LD64_GOT_LO12_NC), /* name */
876 FALSE, /* partial_inplace */
877 0xff8, /* src_mask */
878 0xff8, /* dst_mask */
879 FALSE), /* pcrel_offset */
881 /* LD32: GOT offset G(S) & 0xffc */
882 HOWTO32 (AARCH64_R (LD32_GOT_LO12_NC), /* type */
884 2, /* size (0 = byte, 1 = short, 2 = long) */
886 FALSE, /* pc_relative */
888 complain_overflow_dont, /* complain_on_overflow */
889 bfd_elf_generic_reloc, /* special_function */
890 AARCH64_R_STR (LD32_GOT_LO12_NC), /* name */
891 FALSE, /* partial_inplace */
892 0xffc, /* src_mask */
893 0xffc, /* dst_mask */
894 FALSE), /* pcrel_offset */
896 /* Lower 16 bits of GOT offset for the symbol. */
897 HOWTO64 (AARCH64_R (MOVW_GOTOFF_G0_NC), /* type */
899 2, /* size (0 = byte, 1 = short, 2 = long) */
901 FALSE, /* pc_relative */
903 complain_overflow_dont, /* complain_on_overflow */
904 bfd_elf_generic_reloc, /* special_function */
905 AARCH64_R_STR (MOVW_GOTOFF_G0_NC), /* name */
906 FALSE, /* partial_inplace */
907 0xffff, /* src_mask */
908 0xffff, /* dst_mask */
909 FALSE), /* pcrel_offset */
911 /* Higher 16 bits of GOT offset for the symbol. */
912 HOWTO64 (AARCH64_R (MOVW_GOTOFF_G1), /* type */
914 2, /* size (0 = byte, 1 = short, 2 = long) */
916 FALSE, /* pc_relative */
918 complain_overflow_unsigned, /* complain_on_overflow */
919 bfd_elf_generic_reloc, /* special_function */
920 AARCH64_R_STR (MOVW_GOTOFF_G1), /* name */
921 FALSE, /* partial_inplace */
922 0xffff, /* src_mask */
923 0xffff, /* dst_mask */
924 FALSE), /* pcrel_offset */
926 /* LD64: GOT offset for the symbol. */
927 HOWTO64 (AARCH64_R (LD64_GOTOFF_LO15), /* type */
929 2, /* size (0 = byte, 1 = short, 2 = long) */
931 FALSE, /* pc_relative */
933 complain_overflow_unsigned, /* complain_on_overflow */
934 bfd_elf_generic_reloc, /* special_function */
935 AARCH64_R_STR (LD64_GOTOFF_LO15), /* name */
936 FALSE, /* partial_inplace */
937 0x7ff8, /* src_mask */
938 0x7ff8, /* dst_mask */
939 FALSE), /* pcrel_offset */
941 /* LD32: GOT offset to the page address of GOT table.
942 (G(S) - PAGE (_GLOBAL_OFFSET_TABLE_)) & 0x5ffc. */
943 HOWTO32 (AARCH64_R (LD32_GOTPAGE_LO14), /* type */
945 2, /* size (0 = byte, 1 = short, 2 = long) */
947 FALSE, /* pc_relative */
949 complain_overflow_unsigned, /* complain_on_overflow */
950 bfd_elf_generic_reloc, /* special_function */
951 AARCH64_R_STR (LD32_GOTPAGE_LO14), /* name */
952 FALSE, /* partial_inplace */
953 0x5ffc, /* src_mask */
954 0x5ffc, /* dst_mask */
955 FALSE), /* pcrel_offset */
957 /* LD64: GOT offset to the page address of GOT table.
958 (G(S) - PAGE (_GLOBAL_OFFSET_TABLE_)) & 0x7ff8. */
959 HOWTO64 (AARCH64_R (LD64_GOTPAGE_LO15), /* type */
961 2, /* size (0 = byte, 1 = short, 2 = long) */
963 FALSE, /* pc_relative */
965 complain_overflow_unsigned, /* complain_on_overflow */
966 bfd_elf_generic_reloc, /* special_function */
967 AARCH64_R_STR (LD64_GOTPAGE_LO15), /* name */
968 FALSE, /* partial_inplace */
969 0x7ff8, /* src_mask */
970 0x7ff8, /* dst_mask */
971 FALSE), /* pcrel_offset */
973 /* Get to the page for the GOT entry for the symbol
974 (G(S) - P) using an ADRP instruction. */
975 HOWTO (AARCH64_R (TLSGD_ADR_PAGE21), /* type */
977 2, /* size (0 = byte, 1 = short, 2 = long) */
979 TRUE, /* pc_relative */
981 complain_overflow_dont, /* complain_on_overflow */
982 bfd_elf_generic_reloc, /* special_function */
983 AARCH64_R_STR (TLSGD_ADR_PAGE21), /* name */
984 FALSE, /* partial_inplace */
985 0x1fffff, /* src_mask */
986 0x1fffff, /* dst_mask */
987 TRUE), /* pcrel_offset */
989 HOWTO (AARCH64_R (TLSGD_ADR_PREL21), /* type */
991 2, /* size (0 = byte, 1 = short, 2 = long) */
993 TRUE, /* pc_relative */
995 complain_overflow_dont, /* complain_on_overflow */
996 bfd_elf_generic_reloc, /* special_function */
997 AARCH64_R_STR (TLSGD_ADR_PREL21), /* name */
998 FALSE, /* partial_inplace */
999 0x1fffff, /* src_mask */
1000 0x1fffff, /* dst_mask */
1001 TRUE), /* pcrel_offset */
1003 /* ADD: GOT offset G(S) & 0xff8 [no overflow check] */
1004 HOWTO (AARCH64_R (TLSGD_ADD_LO12_NC), /* type */
1006 2, /* size (0 = byte, 1 = short, 2 = long) */
1008 FALSE, /* pc_relative */
1010 complain_overflow_dont, /* complain_on_overflow */
1011 bfd_elf_generic_reloc, /* special_function */
1012 AARCH64_R_STR (TLSGD_ADD_LO12_NC), /* name */
1013 FALSE, /* partial_inplace */
1014 0xfff, /* src_mask */
1015 0xfff, /* dst_mask */
1016 FALSE), /* pcrel_offset */
1018 /* Lower 16 bits of GOT offset to tls_index. */
1019 HOWTO64 (AARCH64_R (TLSGD_MOVW_G0_NC), /* type */
1021 2, /* size (0 = byte, 1 = short, 2 = long) */
1023 FALSE, /* pc_relative */
1025 complain_overflow_dont, /* complain_on_overflow */
1026 bfd_elf_generic_reloc, /* special_function */
1027 AARCH64_R_STR (TLSGD_MOVW_G0_NC), /* name */
1028 FALSE, /* partial_inplace */
1029 0xffff, /* src_mask */
1030 0xffff, /* dst_mask */
1031 FALSE), /* pcrel_offset */
1033 /* Higher 16 bits of GOT offset to tls_index. */
1034 HOWTO64 (AARCH64_R (TLSGD_MOVW_G1), /* type */
1035 16, /* rightshift */
1036 2, /* size (0 = byte, 1 = short, 2 = long) */
1038 FALSE, /* pc_relative */
1040 complain_overflow_unsigned, /* complain_on_overflow */
1041 bfd_elf_generic_reloc, /* special_function */
1042 AARCH64_R_STR (TLSGD_MOVW_G1), /* name */
1043 FALSE, /* partial_inplace */
1044 0xffff, /* src_mask */
1045 0xffff, /* dst_mask */
1046 FALSE), /* pcrel_offset */
1048 HOWTO (AARCH64_R (TLSIE_ADR_GOTTPREL_PAGE21), /* type */
1049 12, /* rightshift */
1050 2, /* size (0 = byte, 1 = short, 2 = long) */
1052 FALSE, /* pc_relative */
1054 complain_overflow_dont, /* complain_on_overflow */
1055 bfd_elf_generic_reloc, /* special_function */
1056 AARCH64_R_STR (TLSIE_ADR_GOTTPREL_PAGE21), /* name */
1057 FALSE, /* partial_inplace */
1058 0x1fffff, /* src_mask */
1059 0x1fffff, /* dst_mask */
1060 FALSE), /* pcrel_offset */
1062 HOWTO64 (AARCH64_R (TLSIE_LD64_GOTTPREL_LO12_NC), /* type */
1064 2, /* size (0 = byte, 1 = short, 2 = long) */
1066 FALSE, /* pc_relative */
1068 complain_overflow_dont, /* complain_on_overflow */
1069 bfd_elf_generic_reloc, /* special_function */
1070 AARCH64_R_STR (TLSIE_LD64_GOTTPREL_LO12_NC), /* name */
1071 FALSE, /* partial_inplace */
1072 0xff8, /* src_mask */
1073 0xff8, /* dst_mask */
1074 FALSE), /* pcrel_offset */
1076 HOWTO32 (AARCH64_R (TLSIE_LD32_GOTTPREL_LO12_NC), /* type */
1078 2, /* size (0 = byte, 1 = short, 2 = long) */
1080 FALSE, /* pc_relative */
1082 complain_overflow_dont, /* complain_on_overflow */
1083 bfd_elf_generic_reloc, /* special_function */
1084 AARCH64_R_STR (TLSIE_LD32_GOTTPREL_LO12_NC), /* name */
1085 FALSE, /* partial_inplace */
1086 0xffc, /* src_mask */
1087 0xffc, /* dst_mask */
1088 FALSE), /* pcrel_offset */
1090 HOWTO (AARCH64_R (TLSIE_LD_GOTTPREL_PREL19), /* type */
1092 2, /* size (0 = byte, 1 = short, 2 = long) */
1094 FALSE, /* pc_relative */
1096 complain_overflow_dont, /* complain_on_overflow */
1097 bfd_elf_generic_reloc, /* special_function */
1098 AARCH64_R_STR (TLSIE_LD_GOTTPREL_PREL19), /* name */
1099 FALSE, /* partial_inplace */
1100 0x1ffffc, /* src_mask */
1101 0x1ffffc, /* dst_mask */
1102 FALSE), /* pcrel_offset */
1104 HOWTO64 (AARCH64_R (TLSIE_MOVW_GOTTPREL_G0_NC), /* type */
1106 2, /* size (0 = byte, 1 = short, 2 = long) */
1108 FALSE, /* pc_relative */
1110 complain_overflow_dont, /* complain_on_overflow */
1111 bfd_elf_generic_reloc, /* special_function */
1112 AARCH64_R_STR (TLSIE_MOVW_GOTTPREL_G0_NC), /* name */
1113 FALSE, /* partial_inplace */
1114 0xffff, /* src_mask */
1115 0xffff, /* dst_mask */
1116 FALSE), /* pcrel_offset */
1118 HOWTO64 (AARCH64_R (TLSIE_MOVW_GOTTPREL_G1), /* type */
1119 16, /* rightshift */
1120 2, /* size (0 = byte, 1 = short, 2 = long) */
1122 FALSE, /* pc_relative */
1124 complain_overflow_unsigned, /* complain_on_overflow */
1125 bfd_elf_generic_reloc, /* special_function */
1126 AARCH64_R_STR (TLSIE_MOVW_GOTTPREL_G1), /* name */
1127 FALSE, /* partial_inplace */
1128 0xffff, /* src_mask */
1129 0xffff, /* dst_mask */
1130 FALSE), /* pcrel_offset */
1132 /* ADD: bit[23:12] of byte offset to module TLS base address. */
1133 HOWTO (AARCH64_R (TLSLD_ADD_DTPREL_HI12), /* type */
1134 12, /* rightshift */
1135 2, /* size (0 = byte, 1 = short, 2 = long) */
1137 FALSE, /* pc_relative */
1139 complain_overflow_unsigned, /* complain_on_overflow */
1140 bfd_elf_generic_reloc, /* special_function */
1141 AARCH64_R_STR (TLSLD_ADD_DTPREL_HI12), /* name */
1142 FALSE, /* partial_inplace */
1143 0xfff, /* src_mask */
1144 0xfff, /* dst_mask */
1145 FALSE), /* pcrel_offset */
1147 /* Unsigned 12 bit byte offset to module TLS base address. */
1148 HOWTO (AARCH64_R (TLSLD_ADD_DTPREL_LO12), /* type */
1150 2, /* size (0 = byte, 1 = short, 2 = long) */
1152 FALSE, /* pc_relative */
1154 complain_overflow_unsigned, /* complain_on_overflow */
1155 bfd_elf_generic_reloc, /* special_function */
1156 AARCH64_R_STR (TLSLD_ADD_DTPREL_LO12), /* name */
1157 FALSE, /* partial_inplace */
1158 0xfff, /* src_mask */
1159 0xfff, /* dst_mask */
1160 FALSE), /* pcrel_offset */
1162 /* No overflow check version of BFD_RELOC_AARCH64_TLSLD_ADD_DTPREL_LO12. */
1163 HOWTO (AARCH64_R (TLSLD_ADD_DTPREL_LO12_NC), /* type */
1165 2, /* size (0 = byte, 1 = short, 2 = long) */
1167 FALSE, /* pc_relative */
1169 complain_overflow_dont, /* complain_on_overflow */
1170 bfd_elf_generic_reloc, /* special_function */
1171 AARCH64_R_STR (TLSLD_ADD_DTPREL_LO12_NC), /* name */
1172 FALSE, /* partial_inplace */
1173 0xfff, /* src_mask */
1174 0xfff, /* dst_mask */
1175 FALSE), /* pcrel_offset */
1177 /* ADD: GOT offset G(S) & 0xff8 [no overflow check] */
1178 HOWTO (AARCH64_R (TLSLD_ADD_LO12_NC), /* type */
1180 2, /* size (0 = byte, 1 = short, 2 = long) */
1182 FALSE, /* pc_relative */
1184 complain_overflow_dont, /* complain_on_overflow */
1185 bfd_elf_generic_reloc, /* special_function */
1186 AARCH64_R_STR (TLSLD_ADD_LO12_NC), /* name */
1187 FALSE, /* partial_inplace */
1188 0xfff, /* src_mask */
1189 0xfff, /* dst_mask */
1190 FALSE), /* pcrel_offset */
1192 /* Get to the page for the GOT entry for the symbol
1193 (G(S) - P) using an ADRP instruction. */
1194 HOWTO (AARCH64_R (TLSLD_ADR_PAGE21), /* type */
1195 12, /* rightshift */
1196 2, /* size (0 = byte, 1 = short, 2 = long) */
1198 TRUE, /* pc_relative */
1200 complain_overflow_signed, /* complain_on_overflow */
1201 bfd_elf_generic_reloc, /* special_function */
1202 AARCH64_R_STR (TLSLD_ADR_PAGE21), /* name */
1203 FALSE, /* partial_inplace */
1204 0x1fffff, /* src_mask */
1205 0x1fffff, /* dst_mask */
1206 TRUE), /* pcrel_offset */
1208 HOWTO (AARCH64_R (TLSLD_ADR_PREL21), /* type */
1210 2, /* size (0 = byte, 1 = short, 2 = long) */
1212 TRUE, /* pc_relative */
1214 complain_overflow_signed, /* complain_on_overflow */
1215 bfd_elf_generic_reloc, /* special_function */
1216 AARCH64_R_STR (TLSLD_ADR_PREL21), /* name */
1217 FALSE, /* partial_inplace */
1218 0x1fffff, /* src_mask */
1219 0x1fffff, /* dst_mask */
1220 TRUE), /* pcrel_offset */
1222 /* LD/ST16: bit[11:1] of byte offset to module TLS base address. */
1223 HOWTO64 (AARCH64_R (TLSLD_LDST16_DTPREL_LO12), /* type */
1225 2, /* size (0 = byte, 1 = short, 2 = long) */
1227 FALSE, /* pc_relative */
1229 complain_overflow_unsigned, /* complain_on_overflow */
1230 bfd_elf_generic_reloc, /* special_function */
1231 AARCH64_R_STR (TLSLD_LDST16_DTPREL_LO12), /* name */
1232 FALSE, /* partial_inplace */
1233 0x1ffc00, /* src_mask */
1234 0x1ffc00, /* dst_mask */
1235 FALSE), /* pcrel_offset */
1237 /* Same as BFD_RELOC_AARCH64_TLSLD_LDST16_DTPREL_LO12, but no overflow check. */
1238 HOWTO64 (AARCH64_R (TLSLD_LDST16_DTPREL_LO12_NC), /* type */
1240 2, /* size (0 = byte, 1 = short, 2 = long) */
1242 FALSE, /* pc_relative */
1244 complain_overflow_dont, /* complain_on_overflow */
1245 bfd_elf_generic_reloc, /* special_function */
1246 AARCH64_R_STR (TLSLD_LDST16_DTPREL_LO12_NC), /* name */
1247 FALSE, /* partial_inplace */
1248 0x1ffc00, /* src_mask */
1249 0x1ffc00, /* dst_mask */
1250 FALSE), /* pcrel_offset */
1252 /* LD/ST32: bit[11:2] of byte offset to module TLS base address. */
1253 HOWTO64 (AARCH64_R (TLSLD_LDST32_DTPREL_LO12), /* type */
1255 2, /* size (0 = byte, 1 = short, 2 = long) */
1257 FALSE, /* pc_relative */
1259 complain_overflow_unsigned, /* complain_on_overflow */
1260 bfd_elf_generic_reloc, /* special_function */
1261 AARCH64_R_STR (TLSLD_LDST32_DTPREL_LO12), /* name */
1262 FALSE, /* partial_inplace */
1263 0x3ffc00, /* src_mask */
1264 0x3ffc00, /* dst_mask */
1265 FALSE), /* pcrel_offset */
1267 /* Same as BFD_RELOC_AARCH64_TLSLD_LDST32_DTPREL_LO12, but no overflow check. */
1268 HOWTO64 (AARCH64_R (TLSLD_LDST32_DTPREL_LO12_NC), /* type */
1270 2, /* size (0 = byte, 1 = short, 2 = long) */
1272 FALSE, /* pc_relative */
1274 complain_overflow_dont, /* complain_on_overflow */
1275 bfd_elf_generic_reloc, /* special_function */
1276 AARCH64_R_STR (TLSLD_LDST32_DTPREL_LO12_NC), /* name */
1277 FALSE, /* partial_inplace */
1278 0xffc00, /* src_mask */
1279 0xffc00, /* dst_mask */
1280 FALSE), /* pcrel_offset */
1282 /* LD/ST64: bit[11:3] of byte offset to module TLS base address. */
1283 HOWTO64 (AARCH64_R (TLSLD_LDST64_DTPREL_LO12), /* type */
1285 2, /* size (0 = byte, 1 = short, 2 = long) */
1287 FALSE, /* pc_relative */
1289 complain_overflow_unsigned, /* complain_on_overflow */
1290 bfd_elf_generic_reloc, /* special_function */
1291 AARCH64_R_STR (TLSLD_LDST64_DTPREL_LO12), /* name */
1292 FALSE, /* partial_inplace */
1293 0x3ffc00, /* src_mask */
1294 0x3ffc00, /* dst_mask */
1295 FALSE), /* pcrel_offset */
1297 /* Same as BFD_RELOC_AARCH64_TLSLD_LDST64_DTPREL_LO12, but no overflow check. */
1298 HOWTO64 (AARCH64_R (TLSLD_LDST64_DTPREL_LO12_NC), /* type */
1300 2, /* size (0 = byte, 1 = short, 2 = long) */
1302 FALSE, /* pc_relative */
1304 complain_overflow_dont, /* complain_on_overflow */
1305 bfd_elf_generic_reloc, /* special_function */
1306 AARCH64_R_STR (TLSLD_LDST64_DTPREL_LO12_NC), /* name */
1307 FALSE, /* partial_inplace */
1308 0x7fc00, /* src_mask */
1309 0x7fc00, /* dst_mask */
1310 FALSE), /* pcrel_offset */
1312 /* LD/ST8: bit[11:0] of byte offset to module TLS base address. */
1313 HOWTO64 (AARCH64_R (TLSLD_LDST8_DTPREL_LO12), /* type */
1315 2, /* size (0 = byte, 1 = short, 2 = long) */
1317 FALSE, /* pc_relative */
1319 complain_overflow_unsigned, /* complain_on_overflow */
1320 bfd_elf_generic_reloc, /* special_function */
1321 AARCH64_R_STR (TLSLD_LDST8_DTPREL_LO12), /* name */
1322 FALSE, /* partial_inplace */
1323 0x3ffc00, /* src_mask */
1324 0x3ffc00, /* dst_mask */
1325 FALSE), /* pcrel_offset */
1327 /* Same as BFD_RELOC_AARCH64_TLSLD_LDST8_DTPREL_LO12, but no overflow check. */
1328 HOWTO64 (AARCH64_R (TLSLD_LDST8_DTPREL_LO12_NC), /* type */
1330 2, /* size (0 = byte, 1 = short, 2 = long) */
1332 FALSE, /* pc_relative */
1334 complain_overflow_dont, /* complain_on_overflow */
1335 bfd_elf_generic_reloc, /* special_function */
1336 AARCH64_R_STR (TLSLD_LDST8_DTPREL_LO12_NC), /* name */
1337 FALSE, /* partial_inplace */
1338 0x3ffc00, /* src_mask */
1339 0x3ffc00, /* dst_mask */
1340 FALSE), /* pcrel_offset */
1342 /* MOVZ: bit[15:0] of byte offset to module TLS base address. */
1343 HOWTO (AARCH64_R (TLSLD_MOVW_DTPREL_G0), /* type */
1345 2, /* size (0 = byte, 1 = short, 2 = long) */
1347 FALSE, /* pc_relative */
1349 complain_overflow_unsigned, /* complain_on_overflow */
1350 bfd_elf_generic_reloc, /* special_function */
1351 AARCH64_R_STR (TLSLD_MOVW_DTPREL_G0), /* name */
1352 FALSE, /* partial_inplace */
1353 0xffff, /* src_mask */
1354 0xffff, /* dst_mask */
1355 FALSE), /* pcrel_offset */
1357 /* No overflow check version of BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G0. */
1358 HOWTO (AARCH64_R (TLSLD_MOVW_DTPREL_G0_NC), /* type */
1360 2, /* size (0 = byte, 1 = short, 2 = long) */
1362 FALSE, /* pc_relative */
1364 complain_overflow_dont, /* complain_on_overflow */
1365 bfd_elf_generic_reloc, /* special_function */
1366 AARCH64_R_STR (TLSLD_MOVW_DTPREL_G0_NC), /* name */
1367 FALSE, /* partial_inplace */
1368 0xffff, /* src_mask */
1369 0xffff, /* dst_mask */
1370 FALSE), /* pcrel_offset */
1372 /* MOVZ: bit[31:16] of byte offset to module TLS base address. */
1373 HOWTO (AARCH64_R (TLSLD_MOVW_DTPREL_G1), /* type */
1374 16, /* rightshift */
1375 2, /* size (0 = byte, 1 = short, 2 = long) */
1377 FALSE, /* pc_relative */
1379 complain_overflow_unsigned, /* complain_on_overflow */
1380 bfd_elf_generic_reloc, /* special_function */
1381 AARCH64_R_STR (TLSLD_MOVW_DTPREL_G1), /* name */
1382 FALSE, /* partial_inplace */
1383 0xffff, /* src_mask */
1384 0xffff, /* dst_mask */
1385 FALSE), /* pcrel_offset */
1387 /* No overflow check version of BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G1. */
1388 HOWTO64 (AARCH64_R (TLSLD_MOVW_DTPREL_G1_NC), /* type */
1389 16, /* rightshift */
1390 2, /* size (0 = byte, 1 = short, 2 = long) */
1392 FALSE, /* pc_relative */
1394 complain_overflow_dont, /* complain_on_overflow */
1395 bfd_elf_generic_reloc, /* special_function */
1396 AARCH64_R_STR (TLSLD_MOVW_DTPREL_G1_NC), /* name */
1397 FALSE, /* partial_inplace */
1398 0xffff, /* src_mask */
1399 0xffff, /* dst_mask */
1400 FALSE), /* pcrel_offset */
1402 /* MOVZ: bit[47:32] of byte offset to module TLS base address. */
1403 HOWTO64 (AARCH64_R (TLSLD_MOVW_DTPREL_G2), /* type */
1404 32, /* rightshift */
1405 2, /* size (0 = byte, 1 = short, 2 = long) */
1407 FALSE, /* pc_relative */
1409 complain_overflow_unsigned, /* complain_on_overflow */
1410 bfd_elf_generic_reloc, /* special_function */
1411 AARCH64_R_STR (TLSLD_MOVW_DTPREL_G2), /* name */
1412 FALSE, /* partial_inplace */
1413 0xffff, /* src_mask */
1414 0xffff, /* dst_mask */
1415 FALSE), /* pcrel_offset */
1417 HOWTO64 (AARCH64_R (TLSLE_MOVW_TPREL_G2), /* type */
1418 32, /* rightshift */
1419 2, /* size (0 = byte, 1 = short, 2 = long) */
1421 FALSE, /* pc_relative */
1423 complain_overflow_unsigned, /* complain_on_overflow */
1424 bfd_elf_generic_reloc, /* special_function */
1425 AARCH64_R_STR (TLSLE_MOVW_TPREL_G2), /* name */
1426 FALSE, /* partial_inplace */
1427 0xffff, /* src_mask */
1428 0xffff, /* dst_mask */
1429 FALSE), /* pcrel_offset */
1431 HOWTO (AARCH64_R (TLSLE_MOVW_TPREL_G1), /* type */
1432 16, /* rightshift */
1433 2, /* size (0 = byte, 1 = short, 2 = long) */
1435 FALSE, /* pc_relative */
1437 complain_overflow_dont, /* complain_on_overflow */
1438 bfd_elf_generic_reloc, /* special_function */
1439 AARCH64_R_STR (TLSLE_MOVW_TPREL_G1), /* name */
1440 FALSE, /* partial_inplace */
1441 0xffff, /* src_mask */
1442 0xffff, /* dst_mask */
1443 FALSE), /* pcrel_offset */
1445 HOWTO64 (AARCH64_R (TLSLE_MOVW_TPREL_G1_NC), /* type */
1446 16, /* rightshift */
1447 2, /* size (0 = byte, 1 = short, 2 = long) */
1449 FALSE, /* pc_relative */
1451 complain_overflow_dont, /* complain_on_overflow */
1452 bfd_elf_generic_reloc, /* special_function */
1453 AARCH64_R_STR (TLSLE_MOVW_TPREL_G1_NC), /* name */
1454 FALSE, /* partial_inplace */
1455 0xffff, /* src_mask */
1456 0xffff, /* dst_mask */
1457 FALSE), /* pcrel_offset */
1459 HOWTO (AARCH64_R (TLSLE_MOVW_TPREL_G0), /* type */
1461 2, /* size (0 = byte, 1 = short, 2 = long) */
1463 FALSE, /* pc_relative */
1465 complain_overflow_dont, /* complain_on_overflow */
1466 bfd_elf_generic_reloc, /* special_function */
1467 AARCH64_R_STR (TLSLE_MOVW_TPREL_G0), /* name */
1468 FALSE, /* partial_inplace */
1469 0xffff, /* src_mask */
1470 0xffff, /* dst_mask */
1471 FALSE), /* pcrel_offset */
1473 HOWTO (AARCH64_R (TLSLE_MOVW_TPREL_G0_NC), /* type */
1475 2, /* size (0 = byte, 1 = short, 2 = long) */
1477 FALSE, /* pc_relative */
1479 complain_overflow_dont, /* complain_on_overflow */
1480 bfd_elf_generic_reloc, /* special_function */
1481 AARCH64_R_STR (TLSLE_MOVW_TPREL_G0_NC), /* name */
1482 FALSE, /* partial_inplace */
1483 0xffff, /* src_mask */
1484 0xffff, /* dst_mask */
1485 FALSE), /* pcrel_offset */
1487 HOWTO (AARCH64_R (TLSLE_ADD_TPREL_HI12), /* type */
1488 12, /* rightshift */
1489 2, /* size (0 = byte, 1 = short, 2 = long) */
1491 FALSE, /* pc_relative */
1493 complain_overflow_unsigned, /* complain_on_overflow */
1494 bfd_elf_generic_reloc, /* special_function */
1495 AARCH64_R_STR (TLSLE_ADD_TPREL_HI12), /* name */
1496 FALSE, /* partial_inplace */
1497 0xfff, /* src_mask */
1498 0xfff, /* dst_mask */
1499 FALSE), /* pcrel_offset */
1501 HOWTO (AARCH64_R (TLSLE_ADD_TPREL_LO12), /* type */
1503 2, /* size (0 = byte, 1 = short, 2 = long) */
1505 FALSE, /* pc_relative */
1507 complain_overflow_unsigned, /* complain_on_overflow */
1508 bfd_elf_generic_reloc, /* special_function */
1509 AARCH64_R_STR (TLSLE_ADD_TPREL_LO12), /* name */
1510 FALSE, /* partial_inplace */
1511 0xfff, /* src_mask */
1512 0xfff, /* dst_mask */
1513 FALSE), /* pcrel_offset */
1515 HOWTO (AARCH64_R (TLSLE_ADD_TPREL_LO12_NC), /* type */
1517 2, /* size (0 = byte, 1 = short, 2 = long) */
1519 FALSE, /* pc_relative */
1521 complain_overflow_dont, /* complain_on_overflow */
1522 bfd_elf_generic_reloc, /* special_function */
1523 AARCH64_R_STR (TLSLE_ADD_TPREL_LO12_NC), /* name */
1524 FALSE, /* partial_inplace */
1525 0xfff, /* src_mask */
1526 0xfff, /* dst_mask */
1527 FALSE), /* pcrel_offset */
1529 HOWTO (AARCH64_R (TLSDESC_LD_PREL19), /* type */
1531 2, /* size (0 = byte, 1 = short, 2 = long) */
1533 TRUE, /* pc_relative */
1535 complain_overflow_dont, /* complain_on_overflow */
1536 bfd_elf_generic_reloc, /* special_function */
1537 AARCH64_R_STR (TLSDESC_LD_PREL19), /* name */
1538 FALSE, /* partial_inplace */
1539 0x0ffffe0, /* src_mask */
1540 0x0ffffe0, /* dst_mask */
1541 TRUE), /* pcrel_offset */
1543 HOWTO (AARCH64_R (TLSDESC_ADR_PREL21), /* type */
1545 2, /* size (0 = byte, 1 = short, 2 = long) */
1547 TRUE, /* pc_relative */
1549 complain_overflow_dont, /* complain_on_overflow */
1550 bfd_elf_generic_reloc, /* special_function */
1551 AARCH64_R_STR (TLSDESC_ADR_PREL21), /* name */
1552 FALSE, /* partial_inplace */
1553 0x1fffff, /* src_mask */
1554 0x1fffff, /* dst_mask */
1555 TRUE), /* pcrel_offset */
1557 /* Get to the page for the GOT entry for the symbol
1558 (G(S) - P) using an ADRP instruction. */
1559 HOWTO (AARCH64_R (TLSDESC_ADR_PAGE21), /* type */
1560 12, /* rightshift */
1561 2, /* size (0 = byte, 1 = short, 2 = long) */
1563 TRUE, /* pc_relative */
1565 complain_overflow_dont, /* complain_on_overflow */
1566 bfd_elf_generic_reloc, /* special_function */
1567 AARCH64_R_STR (TLSDESC_ADR_PAGE21), /* name */
1568 FALSE, /* partial_inplace */
1569 0x1fffff, /* src_mask */
1570 0x1fffff, /* dst_mask */
1571 TRUE), /* pcrel_offset */
1573 /* LD64: GOT offset G(S) & 0xff8. */
1574 HOWTO64 (AARCH64_R (TLSDESC_LD64_LO12_NC), /* type */
1576 2, /* size (0 = byte, 1 = short, 2 = long) */
1578 FALSE, /* pc_relative */
1580 complain_overflow_dont, /* complain_on_overflow */
1581 bfd_elf_generic_reloc, /* special_function */
1582 AARCH64_R_STR (TLSDESC_LD64_LO12_NC), /* name */
1583 FALSE, /* partial_inplace */
1584 0xff8, /* src_mask */
1585 0xff8, /* dst_mask */
1586 FALSE), /* pcrel_offset */
1588 /* LD32: GOT offset G(S) & 0xffc. */
1589 HOWTO32 (AARCH64_R (TLSDESC_LD32_LO12_NC), /* type */
1591 2, /* size (0 = byte, 1 = short, 2 = long) */
1593 FALSE, /* pc_relative */
1595 complain_overflow_dont, /* complain_on_overflow */
1596 bfd_elf_generic_reloc, /* special_function */
1597 AARCH64_R_STR (TLSDESC_LD32_LO12_NC), /* name */
1598 FALSE, /* partial_inplace */
1599 0xffc, /* src_mask */
1600 0xffc, /* dst_mask */
1601 FALSE), /* pcrel_offset */
1603 /* ADD: GOT offset G(S) & 0xfff. */
1604 HOWTO (AARCH64_R (TLSDESC_ADD_LO12_NC), /* type */
1606 2, /* size (0 = byte, 1 = short, 2 = long) */
1608 FALSE, /* pc_relative */
1610 complain_overflow_dont, /* complain_on_overflow */
1611 bfd_elf_generic_reloc, /* special_function */
1612 AARCH64_R_STR (TLSDESC_ADD_LO12_NC), /* name */
1613 FALSE, /* partial_inplace */
1614 0xfff, /* src_mask */
1615 0xfff, /* dst_mask */
1616 FALSE), /* pcrel_offset */
1618 HOWTO64 (AARCH64_R (TLSDESC_OFF_G1), /* type */
1619 16, /* rightshift */
1620 2, /* size (0 = byte, 1 = short, 2 = long) */
1622 FALSE, /* pc_relative */
1624 complain_overflow_unsigned, /* complain_on_overflow */
1625 bfd_elf_generic_reloc, /* special_function */
1626 AARCH64_R_STR (TLSDESC_OFF_G1), /* name */
1627 FALSE, /* partial_inplace */
1628 0xffff, /* src_mask */
1629 0xffff, /* dst_mask */
1630 FALSE), /* pcrel_offset */
1632 HOWTO64 (AARCH64_R (TLSDESC_OFF_G0_NC), /* type */
1634 2, /* size (0 = byte, 1 = short, 2 = long) */
1636 FALSE, /* pc_relative */
1638 complain_overflow_dont, /* complain_on_overflow */
1639 bfd_elf_generic_reloc, /* special_function */
1640 AARCH64_R_STR (TLSDESC_OFF_G0_NC), /* name */
1641 FALSE, /* partial_inplace */
1642 0xffff, /* src_mask */
1643 0xffff, /* dst_mask */
1644 FALSE), /* pcrel_offset */
1646 HOWTO64 (AARCH64_R (TLSDESC_LDR), /* type */
1648 2, /* size (0 = byte, 1 = short, 2 = long) */
1650 FALSE, /* pc_relative */
1652 complain_overflow_dont, /* complain_on_overflow */
1653 bfd_elf_generic_reloc, /* special_function */
1654 AARCH64_R_STR (TLSDESC_LDR), /* name */
1655 FALSE, /* partial_inplace */
1658 FALSE), /* pcrel_offset */
1660 HOWTO64 (AARCH64_R (TLSDESC_ADD), /* type */
1662 2, /* size (0 = byte, 1 = short, 2 = long) */
1664 FALSE, /* pc_relative */
1666 complain_overflow_dont, /* complain_on_overflow */
1667 bfd_elf_generic_reloc, /* special_function */
1668 AARCH64_R_STR (TLSDESC_ADD), /* name */
1669 FALSE, /* partial_inplace */
1672 FALSE), /* pcrel_offset */
1674 HOWTO (AARCH64_R (TLSDESC_CALL), /* type */
1676 2, /* size (0 = byte, 1 = short, 2 = long) */
1678 FALSE, /* pc_relative */
1680 complain_overflow_dont, /* complain_on_overflow */
1681 bfd_elf_generic_reloc, /* special_function */
1682 AARCH64_R_STR (TLSDESC_CALL), /* name */
1683 FALSE, /* partial_inplace */
1686 FALSE), /* pcrel_offset */
1688 HOWTO (AARCH64_R (COPY), /* type */
1690 2, /* size (0 = byte, 1 = short, 2 = long) */
1692 FALSE, /* pc_relative */
1694 complain_overflow_bitfield, /* complain_on_overflow */
1695 bfd_elf_generic_reloc, /* special_function */
1696 AARCH64_R_STR (COPY), /* name */
1697 TRUE, /* partial_inplace */
1698 0xffffffff, /* src_mask */
1699 0xffffffff, /* dst_mask */
1700 FALSE), /* pcrel_offset */
1702 HOWTO (AARCH64_R (GLOB_DAT), /* type */
1704 2, /* size (0 = byte, 1 = short, 2 = long) */
1706 FALSE, /* pc_relative */
1708 complain_overflow_bitfield, /* complain_on_overflow */
1709 bfd_elf_generic_reloc, /* special_function */
1710 AARCH64_R_STR (GLOB_DAT), /* name */
1711 TRUE, /* partial_inplace */
1712 0xffffffff, /* src_mask */
1713 0xffffffff, /* dst_mask */
1714 FALSE), /* pcrel_offset */
1716 HOWTO (AARCH64_R (JUMP_SLOT), /* type */
1718 2, /* size (0 = byte, 1 = short, 2 = long) */
1720 FALSE, /* pc_relative */
1722 complain_overflow_bitfield, /* complain_on_overflow */
1723 bfd_elf_generic_reloc, /* special_function */
1724 AARCH64_R_STR (JUMP_SLOT), /* name */
1725 TRUE, /* partial_inplace */
1726 0xffffffff, /* src_mask */
1727 0xffffffff, /* dst_mask */
1728 FALSE), /* pcrel_offset */
1730 HOWTO (AARCH64_R (RELATIVE), /* type */
1732 2, /* size (0 = byte, 1 = short, 2 = long) */
1734 FALSE, /* pc_relative */
1736 complain_overflow_bitfield, /* complain_on_overflow */
1737 bfd_elf_generic_reloc, /* special_function */
1738 AARCH64_R_STR (RELATIVE), /* name */
1739 TRUE, /* partial_inplace */
1740 ALL_ONES, /* src_mask */
1741 ALL_ONES, /* dst_mask */
1742 FALSE), /* pcrel_offset */
1744 HOWTO (AARCH64_R (TLS_DTPMOD), /* type */
1746 2, /* size (0 = byte, 1 = short, 2 = long) */
1748 FALSE, /* pc_relative */
1750 complain_overflow_dont, /* complain_on_overflow */
1751 bfd_elf_generic_reloc, /* special_function */
1753 AARCH64_R_STR (TLS_DTPMOD64), /* name */
1755 AARCH64_R_STR (TLS_DTPMOD), /* name */
1757 FALSE, /* partial_inplace */
1759 ALL_ONES, /* dst_mask */
1760 FALSE), /* pc_reloffset */
1762 HOWTO (AARCH64_R (TLS_DTPREL), /* type */
1764 2, /* size (0 = byte, 1 = short, 2 = long) */
1766 FALSE, /* pc_relative */
1768 complain_overflow_dont, /* complain_on_overflow */
1769 bfd_elf_generic_reloc, /* special_function */
1771 AARCH64_R_STR (TLS_DTPREL64), /* name */
1773 AARCH64_R_STR (TLS_DTPREL), /* name */
1775 FALSE, /* partial_inplace */
1777 ALL_ONES, /* dst_mask */
1778 FALSE), /* pcrel_offset */
1780 HOWTO (AARCH64_R (TLS_TPREL), /* type */
1782 2, /* size (0 = byte, 1 = short, 2 = long) */
1784 FALSE, /* pc_relative */
1786 complain_overflow_dont, /* complain_on_overflow */
1787 bfd_elf_generic_reloc, /* special_function */
1789 AARCH64_R_STR (TLS_TPREL64), /* name */
1791 AARCH64_R_STR (TLS_TPREL), /* name */
1793 FALSE, /* partial_inplace */
1795 ALL_ONES, /* dst_mask */
1796 FALSE), /* pcrel_offset */
1798 HOWTO (AARCH64_R (TLSDESC), /* type */
1800 2, /* size (0 = byte, 1 = short, 2 = long) */
1802 FALSE, /* pc_relative */
1804 complain_overflow_dont, /* complain_on_overflow */
1805 bfd_elf_generic_reloc, /* special_function */
1806 AARCH64_R_STR (TLSDESC), /* name */
1807 FALSE, /* partial_inplace */
1809 ALL_ONES, /* dst_mask */
1810 FALSE), /* pcrel_offset */
1812 HOWTO (AARCH64_R (IRELATIVE), /* type */
1814 2, /* size (0 = byte, 1 = short, 2 = long) */
1816 FALSE, /* pc_relative */
1818 complain_overflow_bitfield, /* complain_on_overflow */
1819 bfd_elf_generic_reloc, /* special_function */
1820 AARCH64_R_STR (IRELATIVE), /* name */
1821 FALSE, /* partial_inplace */
1823 ALL_ONES, /* dst_mask */
1824 FALSE), /* pcrel_offset */
1829 static reloc_howto_type elfNN_aarch64_howto_none =
1830 HOWTO (R_AARCH64_NONE, /* type */
1832 3, /* size (0 = byte, 1 = short, 2 = long) */
1834 FALSE, /* pc_relative */
1836 complain_overflow_dont,/* complain_on_overflow */
1837 bfd_elf_generic_reloc, /* special_function */
1838 "R_AARCH64_NONE", /* name */
1839 FALSE, /* partial_inplace */
1842 FALSE); /* pcrel_offset */
1844 /* Given HOWTO, return the bfd internal relocation enumerator. */
1846 static bfd_reloc_code_real_type
1847 elfNN_aarch64_bfd_reloc_from_howto (reloc_howto_type *howto)
1850 = (int) ARRAY_SIZE (elfNN_aarch64_howto_table);
1851 const ptrdiff_t offset
1852 = howto - elfNN_aarch64_howto_table;
1854 if (offset > 0 && offset < size - 1)
1855 return BFD_RELOC_AARCH64_RELOC_START + offset;
1857 if (howto == &elfNN_aarch64_howto_none)
1858 return BFD_RELOC_AARCH64_NONE;
1860 return BFD_RELOC_AARCH64_RELOC_START;
1863 /* Given R_TYPE, return the bfd internal relocation enumerator. */
1865 static bfd_reloc_code_real_type
1866 elfNN_aarch64_bfd_reloc_from_type (unsigned int r_type)
1868 static bfd_boolean initialized_p = FALSE;
1869 /* Indexed by R_TYPE, values are offsets in the howto_table. */
1870 static unsigned int offsets[R_AARCH64_end];
1872 if (initialized_p == FALSE)
1876 for (i = 1; i < ARRAY_SIZE (elfNN_aarch64_howto_table) - 1; ++i)
1877 if (elfNN_aarch64_howto_table[i].type != 0)
1878 offsets[elfNN_aarch64_howto_table[i].type] = i;
1880 initialized_p = TRUE;
1883 if (r_type == R_AARCH64_NONE || r_type == R_AARCH64_NULL)
1884 return BFD_RELOC_AARCH64_NONE;
1886 /* PR 17512: file: b371e70a. */
1887 if (r_type >= R_AARCH64_end)
1889 _bfd_error_handler (_("Invalid AArch64 reloc number: %d"), r_type);
1890 bfd_set_error (bfd_error_bad_value);
1891 return BFD_RELOC_AARCH64_NONE;
1894 return BFD_RELOC_AARCH64_RELOC_START + offsets[r_type];
1897 struct elf_aarch64_reloc_map
1899 bfd_reloc_code_real_type from;
1900 bfd_reloc_code_real_type to;
1903 /* Map bfd generic reloc to AArch64-specific reloc. */
1904 static const struct elf_aarch64_reloc_map elf_aarch64_reloc_map[] =
1906 {BFD_RELOC_NONE, BFD_RELOC_AARCH64_NONE},
1908 /* Basic data relocations. */
1909 {BFD_RELOC_CTOR, BFD_RELOC_AARCH64_NN},
1910 {BFD_RELOC_64, BFD_RELOC_AARCH64_64},
1911 {BFD_RELOC_32, BFD_RELOC_AARCH64_32},
1912 {BFD_RELOC_16, BFD_RELOC_AARCH64_16},
1913 {BFD_RELOC_64_PCREL, BFD_RELOC_AARCH64_64_PCREL},
1914 {BFD_RELOC_32_PCREL, BFD_RELOC_AARCH64_32_PCREL},
1915 {BFD_RELOC_16_PCREL, BFD_RELOC_AARCH64_16_PCREL},
1918 /* Given the bfd internal relocation enumerator in CODE, return the
1919 corresponding howto entry. */
1921 static reloc_howto_type *
1922 elfNN_aarch64_howto_from_bfd_reloc (bfd_reloc_code_real_type code)
1926 /* Convert bfd generic reloc to AArch64-specific reloc. */
1927 if (code < BFD_RELOC_AARCH64_RELOC_START
1928 || code > BFD_RELOC_AARCH64_RELOC_END)
1929 for (i = 0; i < ARRAY_SIZE (elf_aarch64_reloc_map); i++)
1930 if (elf_aarch64_reloc_map[i].from == code)
1932 code = elf_aarch64_reloc_map[i].to;
1936 if (code > BFD_RELOC_AARCH64_RELOC_START
1937 && code < BFD_RELOC_AARCH64_RELOC_END)
1938 if (elfNN_aarch64_howto_table[code - BFD_RELOC_AARCH64_RELOC_START].type)
1939 return &elfNN_aarch64_howto_table[code - BFD_RELOC_AARCH64_RELOC_START];
1941 if (code == BFD_RELOC_AARCH64_NONE)
1942 return &elfNN_aarch64_howto_none;
1947 static reloc_howto_type *
1948 elfNN_aarch64_howto_from_type (unsigned int r_type)
1950 bfd_reloc_code_real_type val;
1951 reloc_howto_type *howto;
1956 bfd_set_error (bfd_error_bad_value);
1961 if (r_type == R_AARCH64_NONE)
1962 return &elfNN_aarch64_howto_none;
1964 val = elfNN_aarch64_bfd_reloc_from_type (r_type);
1965 howto = elfNN_aarch64_howto_from_bfd_reloc (val);
1970 bfd_set_error (bfd_error_bad_value);
1975 elfNN_aarch64_info_to_howto (bfd *abfd ATTRIBUTE_UNUSED, arelent *bfd_reloc,
1976 Elf_Internal_Rela *elf_reloc)
1978 unsigned int r_type;
1980 r_type = ELFNN_R_TYPE (elf_reloc->r_info);
1981 bfd_reloc->howto = elfNN_aarch64_howto_from_type (r_type);
1984 static reloc_howto_type *
1985 elfNN_aarch64_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED,
1986 bfd_reloc_code_real_type code)
1988 reloc_howto_type *howto = elfNN_aarch64_howto_from_bfd_reloc (code);
1993 bfd_set_error (bfd_error_bad_value);
1997 static reloc_howto_type *
1998 elfNN_aarch64_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED,
2003 for (i = 1; i < ARRAY_SIZE (elfNN_aarch64_howto_table) - 1; ++i)
2004 if (elfNN_aarch64_howto_table[i].name != NULL
2005 && strcasecmp (elfNN_aarch64_howto_table[i].name, r_name) == 0)
2006 return &elfNN_aarch64_howto_table[i];
2011 #define TARGET_LITTLE_SYM aarch64_elfNN_le_vec
2012 #define TARGET_LITTLE_NAME "elfNN-littleaarch64"
2013 #define TARGET_BIG_SYM aarch64_elfNN_be_vec
2014 #define TARGET_BIG_NAME "elfNN-bigaarch64"
2016 /* The linker script knows the section names for placement.
2017 The entry_names are used to do simple name mangling on the stubs.
2018 Given a function name, and its type, the stub can be found. The
2019 name can be changed. The only requirement is the %s be present. */
2020 #define STUB_ENTRY_NAME "__%s_veneer"
2022 /* The name of the dynamic interpreter. This is put in the .interp
2024 #define ELF_DYNAMIC_INTERPRETER "/lib/ld.so.1"
2026 #define AARCH64_MAX_FWD_BRANCH_OFFSET \
2027 (((1 << 25) - 1) << 2)
2028 #define AARCH64_MAX_BWD_BRANCH_OFFSET \
2031 #define AARCH64_MAX_ADRP_IMM ((1 << 20) - 1)
2032 #define AARCH64_MIN_ADRP_IMM (-(1 << 20))
2035 aarch64_valid_for_adrp_p (bfd_vma value, bfd_vma place)
2037 bfd_signed_vma offset = (bfd_signed_vma) (PG (value) - PG (place)) >> 12;
2038 return offset <= AARCH64_MAX_ADRP_IMM && offset >= AARCH64_MIN_ADRP_IMM;
2042 aarch64_valid_branch_p (bfd_vma value, bfd_vma place)
2044 bfd_signed_vma offset = (bfd_signed_vma) (value - place);
2045 return (offset <= AARCH64_MAX_FWD_BRANCH_OFFSET
2046 && offset >= AARCH64_MAX_BWD_BRANCH_OFFSET);
2049 static const uint32_t aarch64_adrp_branch_stub [] =
2051 0x90000010, /* adrp ip0, X */
2052 /* R_AARCH64_ADR_HI21_PCREL(X) */
2053 0x91000210, /* add ip0, ip0, :lo12:X */
2054 /* R_AARCH64_ADD_ABS_LO12_NC(X) */
2055 0xd61f0200, /* br ip0 */
2058 static const uint32_t aarch64_long_branch_stub[] =
2061 0x58000090, /* ldr ip0, 1f */
2063 0x18000090, /* ldr wip0, 1f */
2065 0x10000011, /* adr ip1, #0 */
2066 0x8b110210, /* add ip0, ip0, ip1 */
2067 0xd61f0200, /* br ip0 */
2068 0x00000000, /* 1: .xword or .word
2069 R_AARCH64_PRELNN(X) + 12
2074 static const uint32_t aarch64_erratum_835769_stub[] =
2076 0x00000000, /* Placeholder for multiply accumulate. */
2077 0x14000000, /* b <label> */
2080 static const uint32_t aarch64_erratum_843419_stub[] =
2082 0x00000000, /* Placeholder for LDR instruction. */
2083 0x14000000, /* b <label> */
2086 /* Section name for stubs is the associated section name plus this
2088 #define STUB_SUFFIX ".stub"
2090 enum elf_aarch64_stub_type
2093 aarch64_stub_adrp_branch,
2094 aarch64_stub_long_branch,
2095 aarch64_stub_erratum_835769_veneer,
2096 aarch64_stub_erratum_843419_veneer,
2099 struct elf_aarch64_stub_hash_entry
2101 /* Base hash table entry structure. */
2102 struct bfd_hash_entry root;
2104 /* The stub section. */
2107 /* Offset within stub_sec of the beginning of this stub. */
2108 bfd_vma stub_offset;
2110 /* Given the symbol's value and its section we can determine its final
2111 value when building the stubs (so the stub knows where to jump). */
2112 bfd_vma target_value;
2113 asection *target_section;
2115 enum elf_aarch64_stub_type stub_type;
2117 /* The symbol table entry, if any, that this was derived from. */
2118 struct elf_aarch64_link_hash_entry *h;
2120 /* Destination symbol type */
2121 unsigned char st_type;
2123 /* Where this stub is being called from, or, in the case of combined
2124 stub sections, the first input section in the group. */
2127 /* The name for the local symbol at the start of this stub. The
2128 stub name in the hash table has to be unique; this does not, so
2129 it can be friendlier. */
2132 /* The instruction which caused this stub to be generated (only valid for
2133 erratum 835769 workaround stubs at present). */
2134 uint32_t veneered_insn;
2136 /* In an erratum 843419 workaround stub, the ADRP instruction offset. */
2137 bfd_vma adrp_offset;
2140 /* Used to build a map of a section. This is required for mixed-endian
2143 typedef struct elf_elf_section_map
2148 elf_aarch64_section_map;
2151 typedef struct _aarch64_elf_section_data
2153 struct bfd_elf_section_data elf;
2154 unsigned int mapcount;
2155 unsigned int mapsize;
2156 elf_aarch64_section_map *map;
2158 _aarch64_elf_section_data;
2160 #define elf_aarch64_section_data(sec) \
2161 ((_aarch64_elf_section_data *) elf_section_data (sec))
2163 /* The size of the thread control block which is defined to be two pointers. */
2164 #define TCB_SIZE (ARCH_SIZE/8)*2
2166 struct elf_aarch64_local_symbol
2168 unsigned int got_type;
2169 bfd_signed_vma got_refcount;
2172 /* Offset of the GOTPLT entry reserved for the TLS descriptor. The
2173 offset is from the end of the jump table and reserved entries
2176 The magic value (bfd_vma) -1 indicates that an offset has not be
2178 bfd_vma tlsdesc_got_jump_table_offset;
2181 struct elf_aarch64_obj_tdata
2183 struct elf_obj_tdata root;
2185 /* local symbol descriptors */
2186 struct elf_aarch64_local_symbol *locals;
2188 /* Zero to warn when linking objects with incompatible enum sizes. */
2189 int no_enum_size_warning;
2191 /* Zero to warn when linking objects with incompatible wchar_t sizes. */
2192 int no_wchar_size_warning;
2195 #define elf_aarch64_tdata(bfd) \
2196 ((struct elf_aarch64_obj_tdata *) (bfd)->tdata.any)
2198 #define elf_aarch64_locals(bfd) (elf_aarch64_tdata (bfd)->locals)
2200 #define is_aarch64_elf(bfd) \
2201 (bfd_get_flavour (bfd) == bfd_target_elf_flavour \
2202 && elf_tdata (bfd) != NULL \
2203 && elf_object_id (bfd) == AARCH64_ELF_DATA)
2206 elfNN_aarch64_mkobject (bfd *abfd)
2208 return bfd_elf_allocate_object (abfd, sizeof (struct elf_aarch64_obj_tdata),
2212 #define elf_aarch64_hash_entry(ent) \
2213 ((struct elf_aarch64_link_hash_entry *)(ent))
2215 #define GOT_UNKNOWN 0
2216 #define GOT_NORMAL 1
2217 #define GOT_TLS_GD 2
2218 #define GOT_TLS_IE 4
2219 #define GOT_TLSDESC_GD 8
2221 #define GOT_TLS_GD_ANY_P(type) ((type & GOT_TLS_GD) || (type & GOT_TLSDESC_GD))
2223 /* AArch64 ELF linker hash entry. */
2224 struct elf_aarch64_link_hash_entry
2226 struct elf_link_hash_entry root;
2228 /* Track dynamic relocs copied for this symbol. */
2229 struct elf_dyn_relocs *dyn_relocs;
2231 /* Since PLT entries have variable size, we need to record the
2232 index into .got.plt instead of recomputing it from the PLT
2234 bfd_signed_vma plt_got_offset;
2236 /* Bit mask representing the type of GOT entry(s) if any required by
2238 unsigned int got_type;
2240 /* A pointer to the most recently used stub hash entry against this
2242 struct elf_aarch64_stub_hash_entry *stub_cache;
2244 /* Offset of the GOTPLT entry reserved for the TLS descriptor. The offset
2245 is from the end of the jump table and reserved entries within the PLTGOT.
2247 The magic value (bfd_vma) -1 indicates that an offset has not
2249 bfd_vma tlsdesc_got_jump_table_offset;
2253 elfNN_aarch64_symbol_got_type (struct elf_link_hash_entry *h,
2255 unsigned long r_symndx)
2258 return elf_aarch64_hash_entry (h)->got_type;
2260 if (! elf_aarch64_locals (abfd))
2263 return elf_aarch64_locals (abfd)[r_symndx].got_type;
2266 /* Get the AArch64 elf linker hash table from a link_info structure. */
2267 #define elf_aarch64_hash_table(info) \
2268 ((struct elf_aarch64_link_hash_table *) ((info)->hash))
2270 #define aarch64_stub_hash_lookup(table, string, create, copy) \
2271 ((struct elf_aarch64_stub_hash_entry *) \
2272 bfd_hash_lookup ((table), (string), (create), (copy)))
2274 /* AArch64 ELF linker hash table. */
2275 struct elf_aarch64_link_hash_table
2277 /* The main hash table. */
2278 struct elf_link_hash_table root;
2280 /* Nonzero to force PIC branch veneers. */
2283 /* Fix erratum 835769. */
2284 int fix_erratum_835769;
2286 /* Fix erratum 843419. */
2287 int fix_erratum_843419;
2289 /* Enable ADRP->ADR rewrite for erratum 843419 workaround. */
2290 int fix_erratum_843419_adr;
2292 /* The number of bytes in the initial entry in the PLT. */
2293 bfd_size_type plt_header_size;
2295 /* The number of bytes in the subsequent PLT etries. */
2296 bfd_size_type plt_entry_size;
2298 /* Short-cuts to get to dynamic linker sections. */
2302 /* Small local sym cache. */
2303 struct sym_cache sym_cache;
2305 /* For convenience in allocate_dynrelocs. */
2308 /* The amount of space used by the reserved portion of the sgotplt
2309 section, plus whatever space is used by the jump slots. */
2310 bfd_vma sgotplt_jump_table_size;
2312 /* The stub hash table. */
2313 struct bfd_hash_table stub_hash_table;
2315 /* Linker stub bfd. */
2318 /* Linker call-backs. */
2319 asection *(*add_stub_section) (const char *, asection *);
2320 void (*layout_sections_again) (void);
2322 /* Array to keep track of which stub sections have been created, and
2323 information on stub grouping. */
2326 /* This is the section to which stubs in the group will be
2329 /* The stub section. */
2333 /* Assorted information used by elfNN_aarch64_size_stubs. */
2334 unsigned int bfd_count;
2335 unsigned int top_index;
2336 asection **input_list;
2338 /* The offset into splt of the PLT entry for the TLS descriptor
2339 resolver. Special values are 0, if not necessary (or not found
2340 to be necessary yet), and -1 if needed but not determined
2342 bfd_vma tlsdesc_plt;
2344 /* The GOT offset for the lazy trampoline. Communicated to the
2345 loader via DT_TLSDESC_GOT. The magic value (bfd_vma) -1
2346 indicates an offset is not allocated. */
2347 bfd_vma dt_tlsdesc_got;
2349 /* Used by local STT_GNU_IFUNC symbols. */
2350 htab_t loc_hash_table;
2351 void * loc_hash_memory;
2354 /* Create an entry in an AArch64 ELF linker hash table. */
2356 static struct bfd_hash_entry *
2357 elfNN_aarch64_link_hash_newfunc (struct bfd_hash_entry *entry,
2358 struct bfd_hash_table *table,
2361 struct elf_aarch64_link_hash_entry *ret =
2362 (struct elf_aarch64_link_hash_entry *) entry;
2364 /* Allocate the structure if it has not already been allocated by a
2367 ret = bfd_hash_allocate (table,
2368 sizeof (struct elf_aarch64_link_hash_entry));
2370 return (struct bfd_hash_entry *) ret;
2372 /* Call the allocation method of the superclass. */
2373 ret = ((struct elf_aarch64_link_hash_entry *)
2374 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry *) ret,
2378 ret->dyn_relocs = NULL;
2379 ret->got_type = GOT_UNKNOWN;
2380 ret->plt_got_offset = (bfd_vma) - 1;
2381 ret->stub_cache = NULL;
2382 ret->tlsdesc_got_jump_table_offset = (bfd_vma) - 1;
2385 return (struct bfd_hash_entry *) ret;
2388 /* Initialize an entry in the stub hash table. */
2390 static struct bfd_hash_entry *
2391 stub_hash_newfunc (struct bfd_hash_entry *entry,
2392 struct bfd_hash_table *table, const char *string)
2394 /* Allocate the structure if it has not already been allocated by a
2398 entry = bfd_hash_allocate (table,
2400 elf_aarch64_stub_hash_entry));
2405 /* Call the allocation method of the superclass. */
2406 entry = bfd_hash_newfunc (entry, table, string);
2409 struct elf_aarch64_stub_hash_entry *eh;
2411 /* Initialize the local fields. */
2412 eh = (struct elf_aarch64_stub_hash_entry *) entry;
2413 eh->adrp_offset = 0;
2414 eh->stub_sec = NULL;
2415 eh->stub_offset = 0;
2416 eh->target_value = 0;
2417 eh->target_section = NULL;
2418 eh->stub_type = aarch64_stub_none;
2426 /* Compute a hash of a local hash entry. We use elf_link_hash_entry
2427 for local symbol so that we can handle local STT_GNU_IFUNC symbols
2428 as global symbol. We reuse indx and dynstr_index for local symbol
2429 hash since they aren't used by global symbols in this backend. */
2432 elfNN_aarch64_local_htab_hash (const void *ptr)
2434 struct elf_link_hash_entry *h
2435 = (struct elf_link_hash_entry *) ptr;
2436 return ELF_LOCAL_SYMBOL_HASH (h->indx, h->dynstr_index);
2439 /* Compare local hash entries. */
2442 elfNN_aarch64_local_htab_eq (const void *ptr1, const void *ptr2)
2444 struct elf_link_hash_entry *h1
2445 = (struct elf_link_hash_entry *) ptr1;
2446 struct elf_link_hash_entry *h2
2447 = (struct elf_link_hash_entry *) ptr2;
2449 return h1->indx == h2->indx && h1->dynstr_index == h2->dynstr_index;
2452 /* Find and/or create a hash entry for local symbol. */
2454 static struct elf_link_hash_entry *
2455 elfNN_aarch64_get_local_sym_hash (struct elf_aarch64_link_hash_table *htab,
2456 bfd *abfd, const Elf_Internal_Rela *rel,
2459 struct elf_aarch64_link_hash_entry e, *ret;
2460 asection *sec = abfd->sections;
2461 hashval_t h = ELF_LOCAL_SYMBOL_HASH (sec->id,
2462 ELFNN_R_SYM (rel->r_info));
2465 e.root.indx = sec->id;
2466 e.root.dynstr_index = ELFNN_R_SYM (rel->r_info);
2467 slot = htab_find_slot_with_hash (htab->loc_hash_table, &e, h,
2468 create ? INSERT : NO_INSERT);
2475 ret = (struct elf_aarch64_link_hash_entry *) *slot;
2479 ret = (struct elf_aarch64_link_hash_entry *)
2480 objalloc_alloc ((struct objalloc *) htab->loc_hash_memory,
2481 sizeof (struct elf_aarch64_link_hash_entry));
2484 memset (ret, 0, sizeof (*ret));
2485 ret->root.indx = sec->id;
2486 ret->root.dynstr_index = ELFNN_R_SYM (rel->r_info);
2487 ret->root.dynindx = -1;
2493 /* Copy the extra info we tack onto an elf_link_hash_entry. */
2496 elfNN_aarch64_copy_indirect_symbol (struct bfd_link_info *info,
2497 struct elf_link_hash_entry *dir,
2498 struct elf_link_hash_entry *ind)
2500 struct elf_aarch64_link_hash_entry *edir, *eind;
2502 edir = (struct elf_aarch64_link_hash_entry *) dir;
2503 eind = (struct elf_aarch64_link_hash_entry *) ind;
2505 if (eind->dyn_relocs != NULL)
2507 if (edir->dyn_relocs != NULL)
2509 struct elf_dyn_relocs **pp;
2510 struct elf_dyn_relocs *p;
2512 /* Add reloc counts against the indirect sym to the direct sym
2513 list. Merge any entries against the same section. */
2514 for (pp = &eind->dyn_relocs; (p = *pp) != NULL;)
2516 struct elf_dyn_relocs *q;
2518 for (q = edir->dyn_relocs; q != NULL; q = q->next)
2519 if (q->sec == p->sec)
2521 q->pc_count += p->pc_count;
2522 q->count += p->count;
2529 *pp = edir->dyn_relocs;
2532 edir->dyn_relocs = eind->dyn_relocs;
2533 eind->dyn_relocs = NULL;
2536 if (ind->root.type == bfd_link_hash_indirect)
2538 /* Copy over PLT info. */
2539 if (dir->got.refcount <= 0)
2541 edir->got_type = eind->got_type;
2542 eind->got_type = GOT_UNKNOWN;
2546 _bfd_elf_link_hash_copy_indirect (info, dir, ind);
2549 /* Destroy an AArch64 elf linker hash table. */
2552 elfNN_aarch64_link_hash_table_free (bfd *obfd)
2554 struct elf_aarch64_link_hash_table *ret
2555 = (struct elf_aarch64_link_hash_table *) obfd->link.hash;
2557 if (ret->loc_hash_table)
2558 htab_delete (ret->loc_hash_table);
2559 if (ret->loc_hash_memory)
2560 objalloc_free ((struct objalloc *) ret->loc_hash_memory);
2562 bfd_hash_table_free (&ret->stub_hash_table);
2563 _bfd_elf_link_hash_table_free (obfd);
2566 /* Create an AArch64 elf linker hash table. */
2568 static struct bfd_link_hash_table *
2569 elfNN_aarch64_link_hash_table_create (bfd *abfd)
2571 struct elf_aarch64_link_hash_table *ret;
2572 bfd_size_type amt = sizeof (struct elf_aarch64_link_hash_table);
2574 ret = bfd_zmalloc (amt);
2578 if (!_bfd_elf_link_hash_table_init
2579 (&ret->root, abfd, elfNN_aarch64_link_hash_newfunc,
2580 sizeof (struct elf_aarch64_link_hash_entry), AARCH64_ELF_DATA))
2586 ret->plt_header_size = PLT_ENTRY_SIZE;
2587 ret->plt_entry_size = PLT_SMALL_ENTRY_SIZE;
2589 ret->dt_tlsdesc_got = (bfd_vma) - 1;
2591 if (!bfd_hash_table_init (&ret->stub_hash_table, stub_hash_newfunc,
2592 sizeof (struct elf_aarch64_stub_hash_entry)))
2594 _bfd_elf_link_hash_table_free (abfd);
2598 ret->loc_hash_table = htab_try_create (1024,
2599 elfNN_aarch64_local_htab_hash,
2600 elfNN_aarch64_local_htab_eq,
2602 ret->loc_hash_memory = objalloc_create ();
2603 if (!ret->loc_hash_table || !ret->loc_hash_memory)
2605 elfNN_aarch64_link_hash_table_free (abfd);
2608 ret->root.root.hash_table_free = elfNN_aarch64_link_hash_table_free;
2610 return &ret->root.root;
2614 aarch64_relocate (unsigned int r_type, bfd *input_bfd, asection *input_section,
2615 bfd_vma offset, bfd_vma value)
2617 reloc_howto_type *howto;
2620 howto = elfNN_aarch64_howto_from_type (r_type);
2621 place = (input_section->output_section->vma + input_section->output_offset
2624 r_type = elfNN_aarch64_bfd_reloc_from_type (r_type);
2625 value = _bfd_aarch64_elf_resolve_relocation (r_type, place, value, 0, FALSE);
2626 return _bfd_aarch64_elf_put_addend (input_bfd,
2627 input_section->contents + offset, r_type,
2631 static enum elf_aarch64_stub_type
2632 aarch64_select_branch_stub (bfd_vma value, bfd_vma place)
2634 if (aarch64_valid_for_adrp_p (value, place))
2635 return aarch64_stub_adrp_branch;
2636 return aarch64_stub_long_branch;
2639 /* Determine the type of stub needed, if any, for a call. */
2641 static enum elf_aarch64_stub_type
2642 aarch64_type_of_stub (struct bfd_link_info *info,
2643 asection *input_sec,
2644 const Elf_Internal_Rela *rel,
2646 unsigned char st_type,
2647 struct elf_aarch64_link_hash_entry *hash,
2648 bfd_vma destination)
2651 bfd_signed_vma branch_offset;
2652 unsigned int r_type;
2653 struct elf_aarch64_link_hash_table *globals;
2654 enum elf_aarch64_stub_type stub_type = aarch64_stub_none;
2655 bfd_boolean via_plt_p;
2657 if (st_type != STT_FUNC
2658 && (sym_sec == input_sec))
2661 globals = elf_aarch64_hash_table (info);
2662 via_plt_p = (globals->root.splt != NULL && hash != NULL
2663 && hash->root.plt.offset != (bfd_vma) - 1);
2664 /* Make sure call to plt stub can fit into the branch range. */
2666 destination = (globals->root.splt->output_section->vma
2667 + globals->root.splt->output_offset
2668 + hash->root.plt.offset);
2670 /* Determine where the call point is. */
2671 location = (input_sec->output_offset
2672 + input_sec->output_section->vma + rel->r_offset);
2674 branch_offset = (bfd_signed_vma) (destination - location);
2676 r_type = ELFNN_R_TYPE (rel->r_info);
2678 /* We don't want to redirect any old unconditional jump in this way,
2679 only one which is being used for a sibcall, where it is
2680 acceptable for the IP0 and IP1 registers to be clobbered. */
2681 if ((r_type == AARCH64_R (CALL26) || r_type == AARCH64_R (JUMP26))
2682 && (branch_offset > AARCH64_MAX_FWD_BRANCH_OFFSET
2683 || branch_offset < AARCH64_MAX_BWD_BRANCH_OFFSET))
2685 stub_type = aarch64_stub_long_branch;
2691 /* Build a name for an entry in the stub hash table. */
2694 elfNN_aarch64_stub_name (const asection *input_section,
2695 const asection *sym_sec,
2696 const struct elf_aarch64_link_hash_entry *hash,
2697 const Elf_Internal_Rela *rel)
2704 len = 8 + 1 + strlen (hash->root.root.root.string) + 1 + 16 + 1;
2705 stub_name = bfd_malloc (len);
2706 if (stub_name != NULL)
2707 snprintf (stub_name, len, "%08x_%s+%" BFD_VMA_FMT "x",
2708 (unsigned int) input_section->id,
2709 hash->root.root.root.string,
2714 len = 8 + 1 + 8 + 1 + 8 + 1 + 16 + 1;
2715 stub_name = bfd_malloc (len);
2716 if (stub_name != NULL)
2717 snprintf (stub_name, len, "%08x_%x:%x+%" BFD_VMA_FMT "x",
2718 (unsigned int) input_section->id,
2719 (unsigned int) sym_sec->id,
2720 (unsigned int) ELFNN_R_SYM (rel->r_info),
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 (*_bfd_error_handler) (_("%s: cannot create stub entry %s"),
2849 section->owner, stub_name);
2853 stub_entry->stub_sec = stub_sec;
2854 stub_entry->stub_offset = 0;
2855 stub_entry->id_sec = link_sec;
2860 /* Add a new stub entry in the final stub section to the stub hash.
2861 Not all fields of the new stub entry are initialised. */
2863 static struct elf_aarch64_stub_hash_entry *
2864 _bfd_aarch64_add_stub_entry_after (const char *stub_name,
2865 asection *link_section,
2866 struct elf_aarch64_link_hash_table *htab)
2869 struct elf_aarch64_stub_hash_entry *stub_entry;
2871 stub_sec = _bfd_aarch64_get_stub_for_link_section (link_section, htab);
2872 stub_entry = aarch64_stub_hash_lookup (&htab->stub_hash_table, stub_name,
2874 if (stub_entry == NULL)
2876 (*_bfd_error_handler) (_("cannot create stub entry %s"), stub_name);
2880 stub_entry->stub_sec = stub_sec;
2881 stub_entry->stub_offset = 0;
2882 stub_entry->id_sec = link_section;
2889 aarch64_build_one_stub (struct bfd_hash_entry *gen_entry,
2890 void *in_arg ATTRIBUTE_UNUSED)
2892 struct elf_aarch64_stub_hash_entry *stub_entry;
2897 bfd_vma veneered_insn_loc;
2898 bfd_vma veneer_entry_loc;
2899 bfd_signed_vma branch_offset = 0;
2900 unsigned int template_size;
2901 const uint32_t *template;
2904 /* Massage our args to the form they really have. */
2905 stub_entry = (struct elf_aarch64_stub_hash_entry *) gen_entry;
2907 stub_sec = stub_entry->stub_sec;
2909 /* Make a note of the offset within the stubs for this entry. */
2910 stub_entry->stub_offset = stub_sec->size;
2911 loc = stub_sec->contents + stub_entry->stub_offset;
2913 stub_bfd = stub_sec->owner;
2915 /* This is the address of the stub destination. */
2916 sym_value = (stub_entry->target_value
2917 + stub_entry->target_section->output_offset
2918 + stub_entry->target_section->output_section->vma);
2920 if (stub_entry->stub_type == aarch64_stub_long_branch)
2922 bfd_vma place = (stub_entry->stub_offset + stub_sec->output_section->vma
2923 + stub_sec->output_offset);
2925 /* See if we can relax the stub. */
2926 if (aarch64_valid_for_adrp_p (sym_value, place))
2927 stub_entry->stub_type = aarch64_select_branch_stub (sym_value, place);
2930 switch (stub_entry->stub_type)
2932 case aarch64_stub_adrp_branch:
2933 template = aarch64_adrp_branch_stub;
2934 template_size = sizeof (aarch64_adrp_branch_stub);
2936 case aarch64_stub_long_branch:
2937 template = aarch64_long_branch_stub;
2938 template_size = sizeof (aarch64_long_branch_stub);
2940 case aarch64_stub_erratum_835769_veneer:
2941 template = aarch64_erratum_835769_stub;
2942 template_size = sizeof (aarch64_erratum_835769_stub);
2944 case aarch64_stub_erratum_843419_veneer:
2945 template = aarch64_erratum_843419_stub;
2946 template_size = sizeof (aarch64_erratum_843419_stub);
2952 for (i = 0; i < (template_size / sizeof template[0]); i++)
2954 bfd_putl32 (template[i], loc);
2958 template_size = (template_size + 7) & ~7;
2959 stub_sec->size += template_size;
2961 switch (stub_entry->stub_type)
2963 case aarch64_stub_adrp_branch:
2964 if (aarch64_relocate (AARCH64_R (ADR_PREL_PG_HI21), stub_bfd, stub_sec,
2965 stub_entry->stub_offset, sym_value))
2966 /* The stub would not have been relaxed if the offset was out
2970 if (aarch64_relocate (AARCH64_R (ADD_ABS_LO12_NC), stub_bfd, stub_sec,
2971 stub_entry->stub_offset + 4, sym_value))
2975 case aarch64_stub_long_branch:
2976 /* We want the value relative to the address 12 bytes back from the
2978 if (aarch64_relocate (AARCH64_R (PRELNN), stub_bfd, stub_sec,
2979 stub_entry->stub_offset + 16, sym_value + 12))
2983 case aarch64_stub_erratum_835769_veneer:
2984 veneered_insn_loc = stub_entry->target_section->output_section->vma
2985 + stub_entry->target_section->output_offset
2986 + stub_entry->target_value;
2987 veneer_entry_loc = stub_entry->stub_sec->output_section->vma
2988 + stub_entry->stub_sec->output_offset
2989 + stub_entry->stub_offset;
2990 branch_offset = veneered_insn_loc - veneer_entry_loc;
2991 branch_offset >>= 2;
2992 branch_offset &= 0x3ffffff;
2993 bfd_putl32 (stub_entry->veneered_insn,
2994 stub_sec->contents + stub_entry->stub_offset);
2995 bfd_putl32 (template[1] | branch_offset,
2996 stub_sec->contents + stub_entry->stub_offset + 4);
2999 case aarch64_stub_erratum_843419_veneer:
3000 if (aarch64_relocate (AARCH64_R (JUMP26), stub_bfd, stub_sec,
3001 stub_entry->stub_offset + 4, sym_value + 4))
3012 /* As above, but don't actually build the stub. Just bump offset so
3013 we know stub section sizes. */
3016 aarch64_size_one_stub (struct bfd_hash_entry *gen_entry,
3017 void *in_arg ATTRIBUTE_UNUSED)
3019 struct elf_aarch64_stub_hash_entry *stub_entry;
3022 /* Massage our args to the form they really have. */
3023 stub_entry = (struct elf_aarch64_stub_hash_entry *) gen_entry;
3025 switch (stub_entry->stub_type)
3027 case aarch64_stub_adrp_branch:
3028 size = sizeof (aarch64_adrp_branch_stub);
3030 case aarch64_stub_long_branch:
3031 size = sizeof (aarch64_long_branch_stub);
3033 case aarch64_stub_erratum_835769_veneer:
3034 size = sizeof (aarch64_erratum_835769_stub);
3036 case aarch64_stub_erratum_843419_veneer:
3037 size = sizeof (aarch64_erratum_843419_stub);
3043 size = (size + 7) & ~7;
3044 stub_entry->stub_sec->size += size;
3048 /* External entry points for sizing and building linker stubs. */
3050 /* Set up various things so that we can make a list of input sections
3051 for each output section included in the link. Returns -1 on error,
3052 0 when no stubs will be needed, and 1 on success. */
3055 elfNN_aarch64_setup_section_lists (bfd *output_bfd,
3056 struct bfd_link_info *info)
3059 unsigned int bfd_count;
3060 unsigned int top_id, top_index;
3062 asection **input_list, **list;
3064 struct elf_aarch64_link_hash_table *htab =
3065 elf_aarch64_hash_table (info);
3067 if (!is_elf_hash_table (htab))
3070 /* Count the number of input BFDs and find the top input section id. */
3071 for (input_bfd = info->input_bfds, bfd_count = 0, top_id = 0;
3072 input_bfd != NULL; input_bfd = input_bfd->link.next)
3075 for (section = input_bfd->sections;
3076 section != NULL; section = section->next)
3078 if (top_id < section->id)
3079 top_id = section->id;
3082 htab->bfd_count = bfd_count;
3084 amt = sizeof (struct map_stub) * (top_id + 1);
3085 htab->stub_group = bfd_zmalloc (amt);
3086 if (htab->stub_group == NULL)
3089 /* We can't use output_bfd->section_count here to find the top output
3090 section index as some sections may have been removed, and
3091 _bfd_strip_section_from_output doesn't renumber the indices. */
3092 for (section = output_bfd->sections, top_index = 0;
3093 section != NULL; section = section->next)
3095 if (top_index < section->index)
3096 top_index = section->index;
3099 htab->top_index = top_index;
3100 amt = sizeof (asection *) * (top_index + 1);
3101 input_list = bfd_malloc (amt);
3102 htab->input_list = input_list;
3103 if (input_list == NULL)
3106 /* For sections we aren't interested in, mark their entries with a
3107 value we can check later. */
3108 list = input_list + top_index;
3110 *list = bfd_abs_section_ptr;
3111 while (list-- != input_list);
3113 for (section = output_bfd->sections;
3114 section != NULL; section = section->next)
3116 if ((section->flags & SEC_CODE) != 0)
3117 input_list[section->index] = NULL;
3123 /* Used by elfNN_aarch64_next_input_section and group_sections. */
3124 #define PREV_SEC(sec) (htab->stub_group[(sec)->id].link_sec)
3126 /* The linker repeatedly calls this function for each input section,
3127 in the order that input sections are linked into output sections.
3128 Build lists of input sections to determine groupings between which
3129 we may insert linker stubs. */
3132 elfNN_aarch64_next_input_section (struct bfd_link_info *info, asection *isec)
3134 struct elf_aarch64_link_hash_table *htab =
3135 elf_aarch64_hash_table (info);
3137 if (isec->output_section->index <= htab->top_index)
3139 asection **list = htab->input_list + isec->output_section->index;
3141 if (*list != bfd_abs_section_ptr)
3143 /* Steal the link_sec pointer for our list. */
3144 /* This happens to make the list in reverse order,
3145 which is what we want. */
3146 PREV_SEC (isec) = *list;
3152 /* See whether we can group stub sections together. Grouping stub
3153 sections may result in fewer stubs. More importantly, we need to
3154 put all .init* and .fini* stubs at the beginning of the .init or
3155 .fini output sections respectively, because glibc splits the
3156 _init and _fini functions into multiple parts. Putting a stub in
3157 the middle of a function is not a good idea. */
3160 group_sections (struct elf_aarch64_link_hash_table *htab,
3161 bfd_size_type stub_group_size,
3162 bfd_boolean stubs_always_before_branch)
3164 asection **list = htab->input_list + htab->top_index;
3168 asection *tail = *list;
3170 if (tail == bfd_abs_section_ptr)
3173 while (tail != NULL)
3177 bfd_size_type total;
3181 while ((prev = PREV_SEC (curr)) != NULL
3182 && ((total += curr->output_offset - prev->output_offset)
3186 /* OK, the size from the start of CURR to the end is less
3187 than stub_group_size and thus can be handled by one stub
3188 section. (Or the tail section is itself larger than
3189 stub_group_size, in which case we may be toast.)
3190 We should really be keeping track of the total size of
3191 stubs added here, as stubs contribute to the final output
3195 prev = PREV_SEC (tail);
3196 /* Set up this stub group. */
3197 htab->stub_group[tail->id].link_sec = curr;
3199 while (tail != curr && (tail = prev) != NULL);
3201 /* But wait, there's more! Input sections up to stub_group_size
3202 bytes before the stub section can be handled by it too. */
3203 if (!stubs_always_before_branch)
3207 && ((total += tail->output_offset - prev->output_offset)
3211 prev = PREV_SEC (tail);
3212 htab->stub_group[tail->id].link_sec = curr;
3218 while (list-- != htab->input_list);
3220 free (htab->input_list);
3225 #define AARCH64_BITS(x, pos, n) (((x) >> (pos)) & ((1 << (n)) - 1))
3227 #define AARCH64_RT(insn) AARCH64_BITS (insn, 0, 5)
3228 #define AARCH64_RT2(insn) AARCH64_BITS (insn, 10, 5)
3229 #define AARCH64_RA(insn) AARCH64_BITS (insn, 10, 5)
3230 #define AARCH64_RD(insn) AARCH64_BITS (insn, 0, 5)
3231 #define AARCH64_RN(insn) AARCH64_BITS (insn, 5, 5)
3232 #define AARCH64_RM(insn) AARCH64_BITS (insn, 16, 5)
3234 #define AARCH64_MAC(insn) (((insn) & 0xff000000) == 0x9b000000)
3235 #define AARCH64_BIT(insn, n) AARCH64_BITS (insn, n, 1)
3236 #define AARCH64_OP31(insn) AARCH64_BITS (insn, 21, 3)
3237 #define AARCH64_ZR 0x1f
3239 /* All ld/st ops. See C4-182 of the ARM ARM. The encoding space for
3240 LD_PCREL, LDST_RO, LDST_UI and LDST_UIMM cover prefetch ops. */
3242 #define AARCH64_LD(insn) (AARCH64_BIT (insn, 22) == 1)
3243 #define AARCH64_LDST(insn) (((insn) & 0x0a000000) == 0x08000000)
3244 #define AARCH64_LDST_EX(insn) (((insn) & 0x3f000000) == 0x08000000)
3245 #define AARCH64_LDST_PCREL(insn) (((insn) & 0x3b000000) == 0x18000000)
3246 #define AARCH64_LDST_NAP(insn) (((insn) & 0x3b800000) == 0x28000000)
3247 #define AARCH64_LDSTP_PI(insn) (((insn) & 0x3b800000) == 0x28800000)
3248 #define AARCH64_LDSTP_O(insn) (((insn) & 0x3b800000) == 0x29000000)
3249 #define AARCH64_LDSTP_PRE(insn) (((insn) & 0x3b800000) == 0x29800000)
3250 #define AARCH64_LDST_UI(insn) (((insn) & 0x3b200c00) == 0x38000000)
3251 #define AARCH64_LDST_PIIMM(insn) (((insn) & 0x3b200c00) == 0x38000400)
3252 #define AARCH64_LDST_U(insn) (((insn) & 0x3b200c00) == 0x38000800)
3253 #define AARCH64_LDST_PREIMM(insn) (((insn) & 0x3b200c00) == 0x38000c00)
3254 #define AARCH64_LDST_RO(insn) (((insn) & 0x3b200c00) == 0x38200800)
3255 #define AARCH64_LDST_UIMM(insn) (((insn) & 0x3b000000) == 0x39000000)
3256 #define AARCH64_LDST_SIMD_M(insn) (((insn) & 0xbfbf0000) == 0x0c000000)
3257 #define AARCH64_LDST_SIMD_M_PI(insn) (((insn) & 0xbfa00000) == 0x0c800000)
3258 #define AARCH64_LDST_SIMD_S(insn) (((insn) & 0xbf9f0000) == 0x0d000000)
3259 #define AARCH64_LDST_SIMD_S_PI(insn) (((insn) & 0xbf800000) == 0x0d800000)
3261 /* Classify an INSN if it is indeed a load/store.
3263 Return TRUE if INSN is a LD/ST instruction otherwise return FALSE.
3265 For scalar LD/ST instructions PAIR is FALSE, RT is returned and RT2
3268 For LD/ST pair instructions PAIR is TRUE, RT and RT2 are returned.
3273 aarch64_mem_op_p (uint32_t insn, unsigned int *rt, unsigned int *rt2,
3274 bfd_boolean *pair, bfd_boolean *load)
3282 /* Bail out quickly if INSN doesn't fall into the the load-store
3284 if (!AARCH64_LDST (insn))
3289 if (AARCH64_LDST_EX (insn))
3291 *rt = AARCH64_RT (insn);
3293 if (AARCH64_BIT (insn, 21) == 1)
3296 *rt2 = AARCH64_RT2 (insn);
3298 *load = AARCH64_LD (insn);
3301 else if (AARCH64_LDST_NAP (insn)
3302 || AARCH64_LDSTP_PI (insn)
3303 || AARCH64_LDSTP_O (insn)
3304 || AARCH64_LDSTP_PRE (insn))
3307 *rt = AARCH64_RT (insn);
3308 *rt2 = AARCH64_RT2 (insn);
3309 *load = AARCH64_LD (insn);
3312 else if (AARCH64_LDST_PCREL (insn)
3313 || AARCH64_LDST_UI (insn)
3314 || AARCH64_LDST_PIIMM (insn)
3315 || AARCH64_LDST_U (insn)
3316 || AARCH64_LDST_PREIMM (insn)
3317 || AARCH64_LDST_RO (insn)
3318 || AARCH64_LDST_UIMM (insn))
3320 *rt = AARCH64_RT (insn);
3322 if (AARCH64_LDST_PCREL (insn))
3324 opc = AARCH64_BITS (insn, 22, 2);
3325 v = AARCH64_BIT (insn, 26);
3326 opc_v = opc | (v << 2);
3327 *load = (opc_v == 1 || opc_v == 2 || opc_v == 3
3328 || opc_v == 5 || opc_v == 7);
3331 else if (AARCH64_LDST_SIMD_M (insn)
3332 || AARCH64_LDST_SIMD_M_PI (insn))
3334 *rt = AARCH64_RT (insn);
3335 *load = AARCH64_BIT (insn, 22);
3336 opcode = (insn >> 12) & 0xf;
3363 else if (AARCH64_LDST_SIMD_S (insn)
3364 || AARCH64_LDST_SIMD_S_PI (insn))
3366 *rt = AARCH64_RT (insn);
3367 r = (insn >> 21) & 1;
3368 *load = AARCH64_BIT (insn, 22);
3369 opcode = (insn >> 13) & 0x7;
3381 *rt2 = *rt + (r == 0 ? 2 : 3);
3389 *rt2 = *rt + (r == 0 ? 2 : 3);
3401 /* Return TRUE if INSN is multiply-accumulate. */
3404 aarch64_mlxl_p (uint32_t insn)
3406 uint32_t op31 = AARCH64_OP31 (insn);
3408 if (AARCH64_MAC (insn)
3409 && (op31 == 0 || op31 == 1 || op31 == 5)
3410 /* Exclude MUL instructions which are encoded as a multiple accumulate
3412 && AARCH64_RA (insn) != AARCH64_ZR)
3418 /* Some early revisions of the Cortex-A53 have an erratum (835769) whereby
3419 it is possible for a 64-bit multiply-accumulate instruction to generate an
3420 incorrect result. The details are quite complex and hard to
3421 determine statically, since branches in the code may exist in some
3422 circumstances, but all cases end with a memory (load, store, or
3423 prefetch) instruction followed immediately by the multiply-accumulate
3424 operation. We employ a linker patching technique, by moving the potentially
3425 affected multiply-accumulate instruction into a patch region and replacing
3426 the original instruction with a branch to the patch. This function checks
3427 if INSN_1 is the memory operation followed by a multiply-accumulate
3428 operation (INSN_2). Return TRUE if an erratum sequence is found, FALSE
3429 if INSN_1 and INSN_2 are safe. */
3432 aarch64_erratum_sequence (uint32_t insn_1, uint32_t insn_2)
3442 if (aarch64_mlxl_p (insn_2)
3443 && aarch64_mem_op_p (insn_1, &rt, &rt2, &pair, &load))
3445 /* Any SIMD memory op is independent of the subsequent MLA
3446 by definition of the erratum. */
3447 if (AARCH64_BIT (insn_1, 26))
3450 /* If not SIMD, check for integer memory ops and MLA relationship. */
3451 rn = AARCH64_RN (insn_2);
3452 ra = AARCH64_RA (insn_2);
3453 rm = AARCH64_RM (insn_2);
3455 /* If this is a load and there's a true(RAW) dependency, we are safe
3456 and this is not an erratum sequence. */
3458 (rt == rn || rt == rm || rt == ra
3459 || (pair && (rt2 == rn || rt2 == rm || rt2 == ra))))
3462 /* We conservatively put out stubs for all other cases (including
3470 /* Used to order a list of mapping symbols by address. */
3473 elf_aarch64_compare_mapping (const void *a, const void *b)
3475 const elf_aarch64_section_map *amap = (const elf_aarch64_section_map *) a;
3476 const elf_aarch64_section_map *bmap = (const elf_aarch64_section_map *) b;
3478 if (amap->vma > bmap->vma)
3480 else if (amap->vma < bmap->vma)
3482 else if (amap->type > bmap->type)
3483 /* Ensure results do not depend on the host qsort for objects with
3484 multiple mapping symbols at the same address by sorting on type
3487 else if (amap->type < bmap->type)
3495 _bfd_aarch64_erratum_835769_stub_name (unsigned num_fixes)
3497 char *stub_name = (char *) bfd_malloc
3498 (strlen ("__erratum_835769_veneer_") + 16);
3499 sprintf (stub_name,"__erratum_835769_veneer_%d", num_fixes);
3503 /* Scan for Cortex-A53 erratum 835769 sequence.
3505 Return TRUE else FALSE on abnormal termination. */
3508 _bfd_aarch64_erratum_835769_scan (bfd *input_bfd,
3509 struct bfd_link_info *info,
3510 unsigned int *num_fixes_p)
3513 struct elf_aarch64_link_hash_table *htab = elf_aarch64_hash_table (info);
3514 unsigned int num_fixes = *num_fixes_p;
3519 for (section = input_bfd->sections;
3521 section = section->next)
3523 bfd_byte *contents = NULL;
3524 struct _aarch64_elf_section_data *sec_data;
3527 if (elf_section_type (section) != SHT_PROGBITS
3528 || (elf_section_flags (section) & SHF_EXECINSTR) == 0
3529 || (section->flags & SEC_EXCLUDE) != 0
3530 || (section->sec_info_type == SEC_INFO_TYPE_JUST_SYMS)
3531 || (section->output_section == bfd_abs_section_ptr))
3534 if (elf_section_data (section)->this_hdr.contents != NULL)
3535 contents = elf_section_data (section)->this_hdr.contents;
3536 else if (! bfd_malloc_and_get_section (input_bfd, section, &contents))
3539 sec_data = elf_aarch64_section_data (section);
3541 qsort (sec_data->map, sec_data->mapcount,
3542 sizeof (elf_aarch64_section_map), elf_aarch64_compare_mapping);
3544 for (span = 0; span < sec_data->mapcount; span++)
3546 unsigned int span_start = sec_data->map[span].vma;
3547 unsigned int span_end = ((span == sec_data->mapcount - 1)
3548 ? sec_data->map[0].vma + section->size
3549 : sec_data->map[span + 1].vma);
3551 char span_type = sec_data->map[span].type;
3553 if (span_type == 'd')
3556 for (i = span_start; i + 4 < span_end; i += 4)
3558 uint32_t insn_1 = bfd_getl32 (contents + i);
3559 uint32_t insn_2 = bfd_getl32 (contents + i + 4);
3561 if (aarch64_erratum_sequence (insn_1, insn_2))
3563 struct elf_aarch64_stub_hash_entry *stub_entry;
3564 char *stub_name = _bfd_aarch64_erratum_835769_stub_name (num_fixes);
3568 stub_entry = _bfd_aarch64_add_stub_entry_in_group (stub_name,
3574 stub_entry->stub_type = aarch64_stub_erratum_835769_veneer;
3575 stub_entry->target_section = section;
3576 stub_entry->target_value = i + 4;
3577 stub_entry->veneered_insn = insn_2;
3578 stub_entry->output_name = stub_name;
3583 if (elf_section_data (section)->this_hdr.contents == NULL)
3587 *num_fixes_p = num_fixes;
3593 /* Test if instruction INSN is ADRP. */
3596 _bfd_aarch64_adrp_p (uint32_t insn)
3598 return ((insn & 0x9f000000) == 0x90000000);
3602 /* Helper predicate to look for cortex-a53 erratum 843419 sequence 1. */
3605 _bfd_aarch64_erratum_843419_sequence_p (uint32_t insn_1, uint32_t insn_2,
3613 return (aarch64_mem_op_p (insn_2, &rt, &rt2, &pair, &load)
3616 && AARCH64_LDST_UIMM (insn_3)
3617 && AARCH64_RN (insn_3) == AARCH64_RD (insn_1));
3621 /* Test for the presence of Cortex-A53 erratum 843419 instruction sequence.
3623 Return TRUE if section CONTENTS at offset I contains one of the
3624 erratum 843419 sequences, otherwise return FALSE. If a sequence is
3625 seen set P_VENEER_I to the offset of the final LOAD/STORE
3626 instruction in the sequence.
3630 _bfd_aarch64_erratum_843419_p (bfd_byte *contents, bfd_vma vma,
3631 bfd_vma i, bfd_vma span_end,
3632 bfd_vma *p_veneer_i)
3634 uint32_t insn_1 = bfd_getl32 (contents + i);
3636 if (!_bfd_aarch64_adrp_p (insn_1))
3639 if (span_end < i + 12)
3642 uint32_t insn_2 = bfd_getl32 (contents + i + 4);
3643 uint32_t insn_3 = bfd_getl32 (contents + i + 8);
3645 if ((vma & 0xfff) != 0xff8 && (vma & 0xfff) != 0xffc)
3648 if (_bfd_aarch64_erratum_843419_sequence_p (insn_1, insn_2, insn_3))
3650 *p_veneer_i = i + 8;
3654 if (span_end < i + 16)
3657 uint32_t insn_4 = bfd_getl32 (contents + i + 12);
3659 if (_bfd_aarch64_erratum_843419_sequence_p (insn_1, insn_2, insn_4))
3661 *p_veneer_i = i + 12;
3669 /* Resize all stub sections. */
3672 _bfd_aarch64_resize_stubs (struct elf_aarch64_link_hash_table *htab)
3676 /* OK, we've added some stubs. Find out the new size of the
3678 for (section = htab->stub_bfd->sections;
3679 section != NULL; section = section->next)
3681 /* Ignore non-stub sections. */
3682 if (!strstr (section->name, STUB_SUFFIX))
3687 bfd_hash_traverse (&htab->stub_hash_table, aarch64_size_one_stub, htab);
3689 for (section = htab->stub_bfd->sections;
3690 section != NULL; section = section->next)
3692 if (!strstr (section->name, STUB_SUFFIX))
3698 /* Ensure all stub sections have a size which is a multiple of
3699 4096. This is important in order to ensure that the insertion
3700 of stub sections does not in itself move existing code around
3701 in such a way that new errata sequences are created. */
3702 if (htab->fix_erratum_843419)
3704 section->size = BFD_ALIGN (section->size, 0x1000);
3709 /* Construct an erratum 843419 workaround stub name.
3713 _bfd_aarch64_erratum_843419_stub_name (asection *input_section,
3716 const bfd_size_type len = 8 + 4 + 1 + 8 + 1 + 16 + 1;
3717 char *stub_name = bfd_malloc (len);
3719 if (stub_name != NULL)
3720 snprintf (stub_name, len, "e843419@%04x_%08x_%" BFD_VMA_FMT "x",
3721 input_section->owner->id,
3727 /* Build a stub_entry structure describing an 843419 fixup.
3729 The stub_entry constructed is populated with the bit pattern INSN
3730 of the instruction located at OFFSET within input SECTION.
3732 Returns TRUE on success. */
3735 _bfd_aarch64_erratum_843419_fixup (uint32_t insn,
3736 bfd_vma adrp_offset,
3737 bfd_vma ldst_offset,
3739 struct bfd_link_info *info)
3741 struct elf_aarch64_link_hash_table *htab = elf_aarch64_hash_table (info);
3743 struct elf_aarch64_stub_hash_entry *stub_entry;
3745 stub_name = _bfd_aarch64_erratum_843419_stub_name (section, ldst_offset);
3746 stub_entry = aarch64_stub_hash_lookup (&htab->stub_hash_table, stub_name,
3754 /* We always place an 843419 workaround veneer in the stub section
3755 attached to the input section in which an erratum sequence has
3756 been found. This ensures that later in the link process (in
3757 elfNN_aarch64_write_section) when we copy the veneered
3758 instruction from the input section into the stub section the
3759 copied instruction will have had any relocations applied to it.
3760 If we placed workaround veneers in any other stub section then we
3761 could not assume that all relocations have been processed on the
3762 corresponding input section at the point we output the stub
3766 stub_entry = _bfd_aarch64_add_stub_entry_after (stub_name, section, htab);
3767 if (stub_entry == NULL)
3773 stub_entry->adrp_offset = adrp_offset;
3774 stub_entry->target_value = ldst_offset;
3775 stub_entry->target_section = section;
3776 stub_entry->stub_type = aarch64_stub_erratum_843419_veneer;
3777 stub_entry->veneered_insn = insn;
3778 stub_entry->output_name = stub_name;
3784 /* Scan an input section looking for the signature of erratum 843419.
3786 Scans input SECTION in INPUT_BFD looking for erratum 843419
3787 signatures, for each signature found a stub_entry is created
3788 describing the location of the erratum for subsequent fixup.
3790 Return TRUE on successful scan, FALSE on failure to scan.
3794 _bfd_aarch64_erratum_843419_scan (bfd *input_bfd, asection *section,
3795 struct bfd_link_info *info)
3797 struct elf_aarch64_link_hash_table *htab = elf_aarch64_hash_table (info);
3802 if (elf_section_type (section) != SHT_PROGBITS
3803 || (elf_section_flags (section) & SHF_EXECINSTR) == 0
3804 || (section->flags & SEC_EXCLUDE) != 0
3805 || (section->sec_info_type == SEC_INFO_TYPE_JUST_SYMS)
3806 || (section->output_section == bfd_abs_section_ptr))
3811 bfd_byte *contents = NULL;
3812 struct _aarch64_elf_section_data *sec_data;
3815 if (elf_section_data (section)->this_hdr.contents != NULL)
3816 contents = elf_section_data (section)->this_hdr.contents;
3817 else if (! bfd_malloc_and_get_section (input_bfd, section, &contents))
3820 sec_data = elf_aarch64_section_data (section);
3822 qsort (sec_data->map, sec_data->mapcount,
3823 sizeof (elf_aarch64_section_map), elf_aarch64_compare_mapping);
3825 for (span = 0; span < sec_data->mapcount; span++)
3827 unsigned int span_start = sec_data->map[span].vma;
3828 unsigned int span_end = ((span == sec_data->mapcount - 1)
3829 ? sec_data->map[0].vma + section->size
3830 : sec_data->map[span + 1].vma);
3832 char span_type = sec_data->map[span].type;
3834 if (span_type == 'd')
3837 for (i = span_start; i + 8 < span_end; i += 4)
3839 bfd_vma vma = (section->output_section->vma
3840 + section->output_offset
3844 if (_bfd_aarch64_erratum_843419_p
3845 (contents, vma, i, span_end, &veneer_i))
3847 uint32_t insn = bfd_getl32 (contents + veneer_i);
3849 if (!_bfd_aarch64_erratum_843419_fixup (insn, i, veneer_i,
3856 if (elf_section_data (section)->this_hdr.contents == NULL)
3865 /* Determine and set the size of the stub section for a final link.
3867 The basic idea here is to examine all the relocations looking for
3868 PC-relative calls to a target that is unreachable with a "bl"
3872 elfNN_aarch64_size_stubs (bfd *output_bfd,
3874 struct bfd_link_info *info,
3875 bfd_signed_vma group_size,
3876 asection * (*add_stub_section) (const char *,
3878 void (*layout_sections_again) (void))
3880 bfd_size_type stub_group_size;
3881 bfd_boolean stubs_always_before_branch;
3882 bfd_boolean stub_changed = FALSE;
3883 struct elf_aarch64_link_hash_table *htab = elf_aarch64_hash_table (info);
3884 unsigned int num_erratum_835769_fixes = 0;
3886 /* Propagate mach to stub bfd, because it may not have been
3887 finalized when we created stub_bfd. */
3888 bfd_set_arch_mach (stub_bfd, bfd_get_arch (output_bfd),
3889 bfd_get_mach (output_bfd));
3891 /* Stash our params away. */
3892 htab->stub_bfd = stub_bfd;
3893 htab->add_stub_section = add_stub_section;
3894 htab->layout_sections_again = layout_sections_again;
3895 stubs_always_before_branch = group_size < 0;
3897 stub_group_size = -group_size;
3899 stub_group_size = group_size;
3901 if (stub_group_size == 1)
3903 /* Default values. */
3904 /* AArch64 branch range is +-128MB. The value used is 1MB less. */
3905 stub_group_size = 127 * 1024 * 1024;
3908 group_sections (htab, stub_group_size, stubs_always_before_branch);
3910 (*htab->layout_sections_again) ();
3912 if (htab->fix_erratum_835769)
3916 for (input_bfd = info->input_bfds;
3917 input_bfd != NULL; input_bfd = input_bfd->link.next)
3918 if (!_bfd_aarch64_erratum_835769_scan (input_bfd, info,
3919 &num_erratum_835769_fixes))
3922 _bfd_aarch64_resize_stubs (htab);
3923 (*htab->layout_sections_again) ();
3926 if (htab->fix_erratum_843419)
3930 for (input_bfd = info->input_bfds;
3932 input_bfd = input_bfd->link.next)
3936 for (section = input_bfd->sections;
3938 section = section->next)
3939 if (!_bfd_aarch64_erratum_843419_scan (input_bfd, section, info))
3943 _bfd_aarch64_resize_stubs (htab);
3944 (*htab->layout_sections_again) ();
3951 for (input_bfd = info->input_bfds;
3952 input_bfd != NULL; input_bfd = input_bfd->link.next)
3954 Elf_Internal_Shdr *symtab_hdr;
3956 Elf_Internal_Sym *local_syms = NULL;
3958 /* We'll need the symbol table in a second. */
3959 symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
3960 if (symtab_hdr->sh_info == 0)
3963 /* Walk over each section attached to the input bfd. */
3964 for (section = input_bfd->sections;
3965 section != NULL; section = section->next)
3967 Elf_Internal_Rela *internal_relocs, *irelaend, *irela;
3969 /* If there aren't any relocs, then there's nothing more
3971 if ((section->flags & SEC_RELOC) == 0
3972 || section->reloc_count == 0
3973 || (section->flags & SEC_CODE) == 0)
3976 /* If this section is a link-once section that will be
3977 discarded, then don't create any stubs. */
3978 if (section->output_section == NULL
3979 || section->output_section->owner != output_bfd)
3982 /* Get the relocs. */
3984 = _bfd_elf_link_read_relocs (input_bfd, section, NULL,
3985 NULL, info->keep_memory);
3986 if (internal_relocs == NULL)
3987 goto error_ret_free_local;
3989 /* Now examine each relocation. */
3990 irela = internal_relocs;
3991 irelaend = irela + section->reloc_count;
3992 for (; irela < irelaend; irela++)
3994 unsigned int r_type, r_indx;
3995 enum elf_aarch64_stub_type stub_type;
3996 struct elf_aarch64_stub_hash_entry *stub_entry;
3999 bfd_vma destination;
4000 struct elf_aarch64_link_hash_entry *hash;
4001 const char *sym_name;
4003 const asection *id_sec;
4004 unsigned char st_type;
4007 r_type = ELFNN_R_TYPE (irela->r_info);
4008 r_indx = ELFNN_R_SYM (irela->r_info);
4010 if (r_type >= (unsigned int) R_AARCH64_end)
4012 bfd_set_error (bfd_error_bad_value);
4013 error_ret_free_internal:
4014 if (elf_section_data (section)->relocs == NULL)
4015 free (internal_relocs);
4016 goto error_ret_free_local;
4019 /* Only look for stubs on unconditional branch and
4020 branch and link instructions. */
4021 if (r_type != (unsigned int) AARCH64_R (CALL26)
4022 && r_type != (unsigned int) AARCH64_R (JUMP26))
4025 /* Now determine the call target, its name, value,
4032 if (r_indx < symtab_hdr->sh_info)
4034 /* It's a local symbol. */
4035 Elf_Internal_Sym *sym;
4036 Elf_Internal_Shdr *hdr;
4038 if (local_syms == NULL)
4041 = (Elf_Internal_Sym *) symtab_hdr->contents;
4042 if (local_syms == NULL)
4044 = bfd_elf_get_elf_syms (input_bfd, symtab_hdr,
4045 symtab_hdr->sh_info, 0,
4047 if (local_syms == NULL)
4048 goto error_ret_free_internal;
4051 sym = local_syms + r_indx;
4052 hdr = elf_elfsections (input_bfd)[sym->st_shndx];
4053 sym_sec = hdr->bfd_section;
4055 /* This is an undefined symbol. It can never
4059 if (ELF_ST_TYPE (sym->st_info) != STT_SECTION)
4060 sym_value = sym->st_value;
4061 destination = (sym_value + irela->r_addend
4062 + sym_sec->output_offset
4063 + sym_sec->output_section->vma);
4064 st_type = ELF_ST_TYPE (sym->st_info);
4066 = bfd_elf_string_from_elf_section (input_bfd,
4067 symtab_hdr->sh_link,
4074 e_indx = r_indx - symtab_hdr->sh_info;
4075 hash = ((struct elf_aarch64_link_hash_entry *)
4076 elf_sym_hashes (input_bfd)[e_indx]);
4078 while (hash->root.root.type == bfd_link_hash_indirect
4079 || hash->root.root.type == bfd_link_hash_warning)
4080 hash = ((struct elf_aarch64_link_hash_entry *)
4081 hash->root.root.u.i.link);
4083 if (hash->root.root.type == bfd_link_hash_defined
4084 || hash->root.root.type == bfd_link_hash_defweak)
4086 struct elf_aarch64_link_hash_table *globals =
4087 elf_aarch64_hash_table (info);
4088 sym_sec = hash->root.root.u.def.section;
4089 sym_value = hash->root.root.u.def.value;
4090 /* For a destination in a shared library,
4091 use the PLT stub as target address to
4092 decide whether a branch stub is
4094 if (globals->root.splt != NULL && hash != NULL
4095 && hash->root.plt.offset != (bfd_vma) - 1)
4097 sym_sec = globals->root.splt;
4098 sym_value = hash->root.plt.offset;
4099 if (sym_sec->output_section != NULL)
4100 destination = (sym_value
4101 + sym_sec->output_offset
4103 sym_sec->output_section->vma);
4105 else if (sym_sec->output_section != NULL)
4106 destination = (sym_value + irela->r_addend
4107 + sym_sec->output_offset
4108 + sym_sec->output_section->vma);
4110 else if (hash->root.root.type == bfd_link_hash_undefined
4111 || (hash->root.root.type
4112 == bfd_link_hash_undefweak))
4114 /* For a shared library, use the PLT stub as
4115 target address to decide whether a long
4116 branch stub is needed.
4117 For absolute code, they cannot be handled. */
4118 struct elf_aarch64_link_hash_table *globals =
4119 elf_aarch64_hash_table (info);
4121 if (globals->root.splt != NULL && hash != NULL
4122 && hash->root.plt.offset != (bfd_vma) - 1)
4124 sym_sec = globals->root.splt;
4125 sym_value = hash->root.plt.offset;
4126 if (sym_sec->output_section != NULL)
4127 destination = (sym_value
4128 + sym_sec->output_offset
4130 sym_sec->output_section->vma);
4137 bfd_set_error (bfd_error_bad_value);
4138 goto error_ret_free_internal;
4140 st_type = ELF_ST_TYPE (hash->root.type);
4141 sym_name = hash->root.root.root.string;
4144 /* Determine what (if any) linker stub is needed. */
4145 stub_type = aarch64_type_of_stub
4146 (info, section, irela, sym_sec, st_type, hash, destination);
4147 if (stub_type == aarch64_stub_none)
4150 /* Support for grouping stub sections. */
4151 id_sec = htab->stub_group[section->id].link_sec;
4153 /* Get the name of this stub. */
4154 stub_name = elfNN_aarch64_stub_name (id_sec, sym_sec, hash,
4157 goto error_ret_free_internal;
4160 aarch64_stub_hash_lookup (&htab->stub_hash_table,
4161 stub_name, FALSE, FALSE);
4162 if (stub_entry != NULL)
4164 /* The proper stub has already been created. */
4169 stub_entry = _bfd_aarch64_add_stub_entry_in_group
4170 (stub_name, section, htab);
4171 if (stub_entry == NULL)
4174 goto error_ret_free_internal;
4177 stub_entry->target_value = sym_value + irela->r_addend;
4178 stub_entry->target_section = sym_sec;
4179 stub_entry->stub_type = stub_type;
4180 stub_entry->h = hash;
4181 stub_entry->st_type = st_type;
4183 if (sym_name == NULL)
4184 sym_name = "unnamed";
4185 len = sizeof (STUB_ENTRY_NAME) + strlen (sym_name);
4186 stub_entry->output_name = bfd_alloc (htab->stub_bfd, len);
4187 if (stub_entry->output_name == NULL)
4190 goto error_ret_free_internal;
4193 snprintf (stub_entry->output_name, len, STUB_ENTRY_NAME,
4196 stub_changed = TRUE;
4199 /* We're done with the internal relocs, free them. */
4200 if (elf_section_data (section)->relocs == NULL)
4201 free (internal_relocs);
4208 _bfd_aarch64_resize_stubs (htab);
4210 /* Ask the linker to do its stuff. */
4211 (*htab->layout_sections_again) ();
4212 stub_changed = FALSE;
4217 error_ret_free_local:
4221 /* Build all the stubs associated with the current output file. The
4222 stubs are kept in a hash table attached to the main linker hash
4223 table. We also set up the .plt entries for statically linked PIC
4224 functions here. This function is called via aarch64_elf_finish in the
4228 elfNN_aarch64_build_stubs (struct bfd_link_info *info)
4231 struct bfd_hash_table *table;
4232 struct elf_aarch64_link_hash_table *htab;
4234 htab = elf_aarch64_hash_table (info);
4236 for (stub_sec = htab->stub_bfd->sections;
4237 stub_sec != NULL; stub_sec = stub_sec->next)
4241 /* Ignore non-stub sections. */
4242 if (!strstr (stub_sec->name, STUB_SUFFIX))
4245 /* Allocate memory to hold the linker stubs. */
4246 size = stub_sec->size;
4247 stub_sec->contents = bfd_zalloc (htab->stub_bfd, size);
4248 if (stub_sec->contents == NULL && size != 0)
4252 bfd_putl32 (0x14000000 | (size >> 2), stub_sec->contents);
4253 stub_sec->size += 4;
4256 /* Build the stubs as directed by the stub hash table. */
4257 table = &htab->stub_hash_table;
4258 bfd_hash_traverse (table, aarch64_build_one_stub, info);
4264 /* Add an entry to the code/data map for section SEC. */
4267 elfNN_aarch64_section_map_add (asection *sec, char type, bfd_vma vma)
4269 struct _aarch64_elf_section_data *sec_data =
4270 elf_aarch64_section_data (sec);
4271 unsigned int newidx;
4273 if (sec_data->map == NULL)
4275 sec_data->map = bfd_malloc (sizeof (elf_aarch64_section_map));
4276 sec_data->mapcount = 0;
4277 sec_data->mapsize = 1;
4280 newidx = sec_data->mapcount++;
4282 if (sec_data->mapcount > sec_data->mapsize)
4284 sec_data->mapsize *= 2;
4285 sec_data->map = bfd_realloc_or_free
4286 (sec_data->map, sec_data->mapsize * sizeof (elf_aarch64_section_map));
4291 sec_data->map[newidx].vma = vma;
4292 sec_data->map[newidx].type = type;
4297 /* Initialise maps of insn/data for input BFDs. */
4299 bfd_elfNN_aarch64_init_maps (bfd *abfd)
4301 Elf_Internal_Sym *isymbuf;
4302 Elf_Internal_Shdr *hdr;
4303 unsigned int i, localsyms;
4305 /* Make sure that we are dealing with an AArch64 elf binary. */
4306 if (!is_aarch64_elf (abfd))
4309 if ((abfd->flags & DYNAMIC) != 0)
4312 hdr = &elf_symtab_hdr (abfd);
4313 localsyms = hdr->sh_info;
4315 /* Obtain a buffer full of symbols for this BFD. The hdr->sh_info field
4316 should contain the number of local symbols, which should come before any
4317 global symbols. Mapping symbols are always local. */
4318 isymbuf = bfd_elf_get_elf_syms (abfd, hdr, localsyms, 0, NULL, NULL, NULL);
4320 /* No internal symbols read? Skip this BFD. */
4321 if (isymbuf == NULL)
4324 for (i = 0; i < localsyms; i++)
4326 Elf_Internal_Sym *isym = &isymbuf[i];
4327 asection *sec = bfd_section_from_elf_index (abfd, isym->st_shndx);
4330 if (sec != NULL && ELF_ST_BIND (isym->st_info) == STB_LOCAL)
4332 name = bfd_elf_string_from_elf_section (abfd,
4336 if (bfd_is_aarch64_special_symbol_name
4337 (name, BFD_AARCH64_SPECIAL_SYM_TYPE_MAP))
4338 elfNN_aarch64_section_map_add (sec, name[1], isym->st_value);
4343 /* Set option values needed during linking. */
4345 bfd_elfNN_aarch64_set_options (struct bfd *output_bfd,
4346 struct bfd_link_info *link_info,
4348 int no_wchar_warn, int pic_veneer,
4349 int fix_erratum_835769,
4350 int fix_erratum_843419)
4352 struct elf_aarch64_link_hash_table *globals;
4354 globals = elf_aarch64_hash_table (link_info);
4355 globals->pic_veneer = pic_veneer;
4356 globals->fix_erratum_835769 = fix_erratum_835769;
4357 globals->fix_erratum_843419 = fix_erratum_843419;
4358 globals->fix_erratum_843419_adr = TRUE;
4360 BFD_ASSERT (is_aarch64_elf (output_bfd));
4361 elf_aarch64_tdata (output_bfd)->no_enum_size_warning = no_enum_warn;
4362 elf_aarch64_tdata (output_bfd)->no_wchar_size_warning = no_wchar_warn;
4366 aarch64_calculate_got_entry_vma (struct elf_link_hash_entry *h,
4367 struct elf_aarch64_link_hash_table
4368 *globals, struct bfd_link_info *info,
4369 bfd_vma value, bfd *output_bfd,
4370 bfd_boolean *unresolved_reloc_p)
4372 bfd_vma off = (bfd_vma) - 1;
4373 asection *basegot = globals->root.sgot;
4374 bfd_boolean dyn = globals->root.dynamic_sections_created;
4378 BFD_ASSERT (basegot != NULL);
4379 off = h->got.offset;
4380 BFD_ASSERT (off != (bfd_vma) - 1);
4381 if (!WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, bfd_link_pic (info), h)
4382 || (bfd_link_pic (info)
4383 && SYMBOL_REFERENCES_LOCAL (info, h))
4384 || (ELF_ST_VISIBILITY (h->other)
4385 && h->root.type == bfd_link_hash_undefweak))
4387 /* This is actually a static link, or it is a -Bsymbolic link
4388 and the symbol is defined locally. We must initialize this
4389 entry in the global offset table. Since the offset must
4390 always be a multiple of 8 (4 in the case of ILP32), we use
4391 the least significant bit to record whether we have
4392 initialized it already.
4393 When doing a dynamic link, we create a .rel(a).got relocation
4394 entry to initialize the value. This is done in the
4395 finish_dynamic_symbol routine. */
4400 bfd_put_NN (output_bfd, value, basegot->contents + off);
4405 *unresolved_reloc_p = FALSE;
4407 off = off + basegot->output_section->vma + basegot->output_offset;
4413 /* Change R_TYPE to a more efficient access model where possible,
4414 return the new reloc type. */
4416 static bfd_reloc_code_real_type
4417 aarch64_tls_transition_without_check (bfd_reloc_code_real_type r_type,
4418 struct elf_link_hash_entry *h)
4420 bfd_boolean is_local = h == NULL;
4424 case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21:
4425 case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21:
4427 ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1
4428 : BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21);
4430 case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21:
4432 ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC
4435 case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19:
4437 ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1
4438 : BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19);
4440 case BFD_RELOC_AARCH64_TLSDESC_LDR:
4442 ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC
4443 : BFD_RELOC_AARCH64_NONE);
4445 case BFD_RELOC_AARCH64_TLSDESC_OFF_G0_NC:
4447 ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1_NC
4448 : BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G0_NC);
4450 case BFD_RELOC_AARCH64_TLSDESC_OFF_G1:
4452 ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G2
4453 : BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G1);
4455 case BFD_RELOC_AARCH64_TLSDESC_LDNN_LO12_NC:
4456 case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC:
4458 ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC
4459 : BFD_RELOC_AARCH64_TLSIE_LDNN_GOTTPREL_LO12_NC);
4461 case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21:
4462 return is_local ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1 : r_type;
4464 case BFD_RELOC_AARCH64_TLSIE_LDNN_GOTTPREL_LO12_NC:
4465 return is_local ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC : r_type;
4467 case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19:
4470 case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21:
4472 ? BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_HI12
4473 : BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19);
4475 case BFD_RELOC_AARCH64_TLSDESC_ADD:
4476 case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12_NC:
4477 case BFD_RELOC_AARCH64_TLSDESC_CALL:
4478 /* Instructions with these relocations will become NOPs. */
4479 return BFD_RELOC_AARCH64_NONE;
4481 case BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC:
4482 case BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21:
4483 case BFD_RELOC_AARCH64_TLSLD_ADR_PREL21:
4484 return is_local ? BFD_RELOC_AARCH64_NONE : r_type;
4487 case BFD_RELOC_AARCH64_TLSGD_MOVW_G0_NC:
4489 ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1_NC
4490 : BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G0_NC;
4492 case BFD_RELOC_AARCH64_TLSGD_MOVW_G1:
4494 ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G2
4495 : BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G1;
4506 aarch64_reloc_got_type (bfd_reloc_code_real_type r_type)
4510 case BFD_RELOC_AARCH64_ADR_GOT_PAGE:
4511 case BFD_RELOC_AARCH64_GOT_LD_PREL19:
4512 case BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14:
4513 case BFD_RELOC_AARCH64_LD32_GOT_LO12_NC:
4514 case BFD_RELOC_AARCH64_LD64_GOTOFF_LO15:
4515 case BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15:
4516 case BFD_RELOC_AARCH64_LD64_GOT_LO12_NC:
4517 case BFD_RELOC_AARCH64_MOVW_GOTOFF_G0_NC:
4518 case BFD_RELOC_AARCH64_MOVW_GOTOFF_G1:
4521 case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC:
4522 case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21:
4523 case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21:
4524 case BFD_RELOC_AARCH64_TLSGD_MOVW_G0_NC:
4525 case BFD_RELOC_AARCH64_TLSGD_MOVW_G1:
4526 case BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC:
4527 case BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21:
4528 case BFD_RELOC_AARCH64_TLSLD_ADR_PREL21:
4531 case BFD_RELOC_AARCH64_TLSDESC_ADD:
4532 case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12_NC:
4533 case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21:
4534 case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21:
4535 case BFD_RELOC_AARCH64_TLSDESC_CALL:
4536 case BFD_RELOC_AARCH64_TLSDESC_LD32_LO12_NC:
4537 case BFD_RELOC_AARCH64_TLSDESC_LD64_LO12_NC:
4538 case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19:
4539 case BFD_RELOC_AARCH64_TLSDESC_LDR:
4540 case BFD_RELOC_AARCH64_TLSDESC_OFF_G0_NC:
4541 case BFD_RELOC_AARCH64_TLSDESC_OFF_G1:
4542 return GOT_TLSDESC_GD;
4544 case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21:
4545 case BFD_RELOC_AARCH64_TLSIE_LD32_GOTTPREL_LO12_NC:
4546 case BFD_RELOC_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC:
4547 case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19:
4548 case BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G0_NC:
4549 case BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G1:
4559 aarch64_can_relax_tls (bfd *input_bfd,
4560 struct bfd_link_info *info,
4561 bfd_reloc_code_real_type r_type,
4562 struct elf_link_hash_entry *h,
4563 unsigned long r_symndx)
4565 unsigned int symbol_got_type;
4566 unsigned int reloc_got_type;
4568 if (! IS_AARCH64_TLS_RELAX_RELOC (r_type))
4571 symbol_got_type = elfNN_aarch64_symbol_got_type (h, input_bfd, r_symndx);
4572 reloc_got_type = aarch64_reloc_got_type (r_type);
4574 if (symbol_got_type == GOT_TLS_IE && GOT_TLS_GD_ANY_P (reloc_got_type))
4577 if (bfd_link_pic (info))
4580 if (h && h->root.type == bfd_link_hash_undefweak)
4586 /* Given the relocation code R_TYPE, return the relaxed bfd reloc
4589 static bfd_reloc_code_real_type
4590 aarch64_tls_transition (bfd *input_bfd,
4591 struct bfd_link_info *info,
4592 unsigned int r_type,
4593 struct elf_link_hash_entry *h,
4594 unsigned long r_symndx)
4596 bfd_reloc_code_real_type bfd_r_type
4597 = elfNN_aarch64_bfd_reloc_from_type (r_type);
4599 if (! aarch64_can_relax_tls (input_bfd, info, bfd_r_type, h, r_symndx))
4602 return aarch64_tls_transition_without_check (bfd_r_type, h);
4605 /* Return the base VMA address which should be subtracted from real addresses
4606 when resolving R_AARCH64_TLS_DTPREL relocation. */
4609 dtpoff_base (struct bfd_link_info *info)
4611 /* If tls_sec is NULL, we should have signalled an error already. */
4612 BFD_ASSERT (elf_hash_table (info)->tls_sec != NULL);
4613 return elf_hash_table (info)->tls_sec->vma;
4616 /* Return the base VMA address which should be subtracted from real addresses
4617 when resolving R_AARCH64_TLS_GOTTPREL64 relocations. */
4620 tpoff_base (struct bfd_link_info *info)
4622 struct elf_link_hash_table *htab = elf_hash_table (info);
4624 /* If tls_sec is NULL, we should have signalled an error already. */
4625 BFD_ASSERT (htab->tls_sec != NULL);
4627 bfd_vma base = align_power ((bfd_vma) TCB_SIZE,
4628 htab->tls_sec->alignment_power);
4629 return htab->tls_sec->vma - base;
4633 symbol_got_offset_ref (bfd *input_bfd, struct elf_link_hash_entry *h,
4634 unsigned long r_symndx)
4636 /* Calculate the address of the GOT entry for symbol
4637 referred to in h. */
4639 return &h->got.offset;
4643 struct elf_aarch64_local_symbol *l;
4645 l = elf_aarch64_locals (input_bfd);
4646 return &l[r_symndx].got_offset;
4651 symbol_got_offset_mark (bfd *input_bfd, struct elf_link_hash_entry *h,
4652 unsigned long r_symndx)
4655 p = symbol_got_offset_ref (input_bfd, h, r_symndx);
4660 symbol_got_offset_mark_p (bfd *input_bfd, struct elf_link_hash_entry *h,
4661 unsigned long r_symndx)
4664 value = * symbol_got_offset_ref (input_bfd, h, r_symndx);
4669 symbol_got_offset (bfd *input_bfd, struct elf_link_hash_entry *h,
4670 unsigned long r_symndx)
4673 value = * symbol_got_offset_ref (input_bfd, h, r_symndx);
4679 symbol_tlsdesc_got_offset_ref (bfd *input_bfd, struct elf_link_hash_entry *h,
4680 unsigned long r_symndx)
4682 /* Calculate the address of the GOT entry for symbol
4683 referred to in h. */
4686 struct elf_aarch64_link_hash_entry *eh;
4687 eh = (struct elf_aarch64_link_hash_entry *) h;
4688 return &eh->tlsdesc_got_jump_table_offset;
4693 struct elf_aarch64_local_symbol *l;
4695 l = elf_aarch64_locals (input_bfd);
4696 return &l[r_symndx].tlsdesc_got_jump_table_offset;
4701 symbol_tlsdesc_got_offset_mark (bfd *input_bfd, struct elf_link_hash_entry *h,
4702 unsigned long r_symndx)
4705 p = symbol_tlsdesc_got_offset_ref (input_bfd, h, r_symndx);
4710 symbol_tlsdesc_got_offset_mark_p (bfd *input_bfd,
4711 struct elf_link_hash_entry *h,
4712 unsigned long r_symndx)
4715 value = * symbol_tlsdesc_got_offset_ref (input_bfd, h, r_symndx);
4720 symbol_tlsdesc_got_offset (bfd *input_bfd, struct elf_link_hash_entry *h,
4721 unsigned long r_symndx)
4724 value = * symbol_tlsdesc_got_offset_ref (input_bfd, h, r_symndx);
4729 /* Data for make_branch_to_erratum_835769_stub(). */
4731 struct erratum_835769_branch_to_stub_data
4733 struct bfd_link_info *info;
4734 asection *output_section;
4738 /* Helper to insert branches to erratum 835769 stubs in the right
4739 places for a particular section. */
4742 make_branch_to_erratum_835769_stub (struct bfd_hash_entry *gen_entry,
4745 struct elf_aarch64_stub_hash_entry *stub_entry;
4746 struct erratum_835769_branch_to_stub_data *data;
4748 unsigned long branch_insn = 0;
4749 bfd_vma veneered_insn_loc, veneer_entry_loc;
4750 bfd_signed_vma branch_offset;
4751 unsigned int target;
4754 stub_entry = (struct elf_aarch64_stub_hash_entry *) gen_entry;
4755 data = (struct erratum_835769_branch_to_stub_data *) in_arg;
4757 if (stub_entry->target_section != data->output_section
4758 || stub_entry->stub_type != aarch64_stub_erratum_835769_veneer)
4761 contents = data->contents;
4762 veneered_insn_loc = stub_entry->target_section->output_section->vma
4763 + stub_entry->target_section->output_offset
4764 + stub_entry->target_value;
4765 veneer_entry_loc = stub_entry->stub_sec->output_section->vma
4766 + stub_entry->stub_sec->output_offset
4767 + stub_entry->stub_offset;
4768 branch_offset = veneer_entry_loc - veneered_insn_loc;
4770 abfd = stub_entry->target_section->owner;
4771 if (!aarch64_valid_branch_p (veneer_entry_loc, veneered_insn_loc))
4772 (*_bfd_error_handler)
4773 (_("%B: error: Erratum 835769 stub out "
4774 "of range (input file too large)"), abfd);
4776 target = stub_entry->target_value;
4777 branch_insn = 0x14000000;
4778 branch_offset >>= 2;
4779 branch_offset &= 0x3ffffff;
4780 branch_insn |= branch_offset;
4781 bfd_putl32 (branch_insn, &contents[target]);
4788 _bfd_aarch64_erratum_843419_branch_to_stub (struct bfd_hash_entry *gen_entry,
4791 struct elf_aarch64_stub_hash_entry *stub_entry
4792 = (struct elf_aarch64_stub_hash_entry *) gen_entry;
4793 struct erratum_835769_branch_to_stub_data *data
4794 = (struct erratum_835769_branch_to_stub_data *) in_arg;
4795 struct bfd_link_info *info;
4796 struct elf_aarch64_link_hash_table *htab;
4804 contents = data->contents;
4805 section = data->output_section;
4807 htab = elf_aarch64_hash_table (info);
4809 if (stub_entry->target_section != section
4810 || stub_entry->stub_type != aarch64_stub_erratum_843419_veneer)
4813 insn = bfd_getl32 (contents + stub_entry->target_value);
4815 stub_entry->stub_sec->contents + stub_entry->stub_offset);
4817 place = (section->output_section->vma + section->output_offset
4818 + stub_entry->adrp_offset);
4819 insn = bfd_getl32 (contents + stub_entry->adrp_offset);
4821 if ((insn & AARCH64_ADRP_OP_MASK) != AARCH64_ADRP_OP)
4824 bfd_signed_vma imm =
4825 (_bfd_aarch64_sign_extend
4826 ((bfd_vma) _bfd_aarch64_decode_adrp_imm (insn) << 12, 33)
4829 if (htab->fix_erratum_843419_adr
4830 && (imm >= AARCH64_MIN_ADRP_IMM && imm <= AARCH64_MAX_ADRP_IMM))
4832 insn = (_bfd_aarch64_reencode_adr_imm (AARCH64_ADR_OP, imm)
4833 | AARCH64_RT (insn));
4834 bfd_putl32 (insn, contents + stub_entry->adrp_offset);
4838 bfd_vma veneered_insn_loc;
4839 bfd_vma veneer_entry_loc;
4840 bfd_signed_vma branch_offset;
4841 uint32_t branch_insn;
4843 veneered_insn_loc = stub_entry->target_section->output_section->vma
4844 + stub_entry->target_section->output_offset
4845 + stub_entry->target_value;
4846 veneer_entry_loc = stub_entry->stub_sec->output_section->vma
4847 + stub_entry->stub_sec->output_offset
4848 + stub_entry->stub_offset;
4849 branch_offset = veneer_entry_loc - veneered_insn_loc;
4851 abfd = stub_entry->target_section->owner;
4852 if (!aarch64_valid_branch_p (veneer_entry_loc, veneered_insn_loc))
4853 (*_bfd_error_handler)
4854 (_("%B: error: Erratum 843419 stub out "
4855 "of range (input file too large)"), abfd);
4857 branch_insn = 0x14000000;
4858 branch_offset >>= 2;
4859 branch_offset &= 0x3ffffff;
4860 branch_insn |= branch_offset;
4861 bfd_putl32 (branch_insn, contents + stub_entry->target_value);
4868 elfNN_aarch64_write_section (bfd *output_bfd ATTRIBUTE_UNUSED,
4869 struct bfd_link_info *link_info,
4874 struct elf_aarch64_link_hash_table *globals =
4875 elf_aarch64_hash_table (link_info);
4877 if (globals == NULL)
4880 /* Fix code to point to erratum 835769 stubs. */
4881 if (globals->fix_erratum_835769)
4883 struct erratum_835769_branch_to_stub_data data;
4885 data.info = link_info;
4886 data.output_section = sec;
4887 data.contents = contents;
4888 bfd_hash_traverse (&globals->stub_hash_table,
4889 make_branch_to_erratum_835769_stub, &data);
4892 if (globals->fix_erratum_843419)
4894 struct erratum_835769_branch_to_stub_data data;
4896 data.info = link_info;
4897 data.output_section = sec;
4898 data.contents = contents;
4899 bfd_hash_traverse (&globals->stub_hash_table,
4900 _bfd_aarch64_erratum_843419_branch_to_stub, &data);
4906 /* Perform a relocation as part of a final link. */
4907 static bfd_reloc_status_type
4908 elfNN_aarch64_final_link_relocate (reloc_howto_type *howto,
4911 asection *input_section,
4913 Elf_Internal_Rela *rel,
4915 struct bfd_link_info *info,
4917 struct elf_link_hash_entry *h,
4918 bfd_boolean *unresolved_reloc_p,
4919 bfd_boolean save_addend,
4920 bfd_vma *saved_addend,
4921 Elf_Internal_Sym *sym)
4923 Elf_Internal_Shdr *symtab_hdr;
4924 unsigned int r_type = howto->type;
4925 bfd_reloc_code_real_type bfd_r_type
4926 = elfNN_aarch64_bfd_reloc_from_howto (howto);
4927 bfd_reloc_code_real_type new_bfd_r_type;
4928 unsigned long r_symndx;
4929 bfd_byte *hit_data = contents + rel->r_offset;
4931 bfd_signed_vma signed_addend;
4932 struct elf_aarch64_link_hash_table *globals;
4933 bfd_boolean weak_undef_p;
4936 globals = elf_aarch64_hash_table (info);
4938 symtab_hdr = &elf_symtab_hdr (input_bfd);
4940 BFD_ASSERT (is_aarch64_elf (input_bfd));
4942 r_symndx = ELFNN_R_SYM (rel->r_info);
4944 /* It is possible to have linker relaxations on some TLS access
4945 models. Update our information here. */
4946 new_bfd_r_type = aarch64_tls_transition (input_bfd, info, r_type, h, r_symndx);
4947 if (new_bfd_r_type != bfd_r_type)
4949 bfd_r_type = new_bfd_r_type;
4950 howto = elfNN_aarch64_howto_from_bfd_reloc (bfd_r_type);
4951 BFD_ASSERT (howto != NULL);
4952 r_type = howto->type;
4955 place = input_section->output_section->vma
4956 + input_section->output_offset + rel->r_offset;
4958 /* Get addend, accumulating the addend for consecutive relocs
4959 which refer to the same offset. */
4960 signed_addend = saved_addend ? *saved_addend : 0;
4961 signed_addend += rel->r_addend;
4963 weak_undef_p = (h ? h->root.type == bfd_link_hash_undefweak
4964 : bfd_is_und_section (sym_sec));
4966 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle
4967 it here if it is defined in a non-shared object. */
4969 && h->type == STT_GNU_IFUNC
4976 if ((input_section->flags & SEC_ALLOC) == 0
4977 || h->plt.offset == (bfd_vma) -1)
4980 /* STT_GNU_IFUNC symbol must go through PLT. */
4981 plt = globals->root.splt ? globals->root.splt : globals->root.iplt;
4982 value = (plt->output_section->vma + plt->output_offset + h->plt.offset);
4987 if (h->root.root.string)
4988 name = h->root.root.string;
4990 name = bfd_elf_sym_name (input_bfd, symtab_hdr, sym,
4992 (*_bfd_error_handler)
4993 (_("%B: relocation %s against STT_GNU_IFUNC "
4994 "symbol `%s' isn't handled by %s"), input_bfd,
4995 howto->name, name, __FUNCTION__);
4996 bfd_set_error (bfd_error_bad_value);
4999 case BFD_RELOC_AARCH64_NN:
5000 if (rel->r_addend != 0)
5002 if (h->root.root.string)
5003 name = h->root.root.string;
5005 name = bfd_elf_sym_name (input_bfd, symtab_hdr,
5007 (*_bfd_error_handler)
5008 (_("%B: relocation %s against STT_GNU_IFUNC "
5009 "symbol `%s' has non-zero addend: %d"),
5010 input_bfd, howto->name, name, rel->r_addend);
5011 bfd_set_error (bfd_error_bad_value);
5015 /* Generate dynamic relocation only when there is a
5016 non-GOT reference in a shared object. */
5017 if (bfd_link_pic (info) && h->non_got_ref)
5019 Elf_Internal_Rela outrel;
5022 /* Need a dynamic relocation to get the real function
5024 outrel.r_offset = _bfd_elf_section_offset (output_bfd,
5028 if (outrel.r_offset == (bfd_vma) -1
5029 || outrel.r_offset == (bfd_vma) -2)
5032 outrel.r_offset += (input_section->output_section->vma
5033 + input_section->output_offset);
5035 if (h->dynindx == -1
5037 || bfd_link_executable (info))
5039 /* This symbol is resolved locally. */
5040 outrel.r_info = ELFNN_R_INFO (0, AARCH64_R (IRELATIVE));
5041 outrel.r_addend = (h->root.u.def.value
5042 + h->root.u.def.section->output_section->vma
5043 + h->root.u.def.section->output_offset);
5047 outrel.r_info = ELFNN_R_INFO (h->dynindx, r_type);
5048 outrel.r_addend = 0;
5051 sreloc = globals->root.irelifunc;
5052 elf_append_rela (output_bfd, sreloc, &outrel);
5054 /* If this reloc is against an external symbol, we
5055 do not want to fiddle with the addend. Otherwise,
5056 we need to include the symbol value so that it
5057 becomes an addend for the dynamic reloc. For an
5058 internal symbol, we have updated addend. */
5059 return bfd_reloc_ok;
5062 case BFD_RELOC_AARCH64_CALL26:
5063 case BFD_RELOC_AARCH64_JUMP26:
5064 value = _bfd_aarch64_elf_resolve_relocation (bfd_r_type, place, value,
5067 return _bfd_aarch64_elf_put_addend (input_bfd, hit_data, bfd_r_type,
5069 case BFD_RELOC_AARCH64_ADR_GOT_PAGE:
5070 case BFD_RELOC_AARCH64_GOT_LD_PREL19:
5071 case BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14:
5072 case BFD_RELOC_AARCH64_LD32_GOT_LO12_NC:
5073 case BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15:
5074 case BFD_RELOC_AARCH64_MOVW_GOTOFF_G0_NC:
5075 case BFD_RELOC_AARCH64_MOVW_GOTOFF_G1:
5076 case BFD_RELOC_AARCH64_LD64_GOTOFF_LO15:
5077 case BFD_RELOC_AARCH64_LD64_GOT_LO12_NC:
5078 base_got = globals->root.sgot;
5079 off = h->got.offset;
5081 if (base_got == NULL)
5084 if (off == (bfd_vma) -1)
5088 /* We can't use h->got.offset here to save state, or
5089 even just remember the offset, as finish_dynamic_symbol
5090 would use that as offset into .got. */
5092 if (globals->root.splt != NULL)
5094 plt_index = ((h->plt.offset - globals->plt_header_size) /
5095 globals->plt_entry_size);
5096 off = (plt_index + 3) * GOT_ENTRY_SIZE;
5097 base_got = globals->root.sgotplt;
5101 plt_index = h->plt.offset / globals->plt_entry_size;
5102 off = plt_index * GOT_ENTRY_SIZE;
5103 base_got = globals->root.igotplt;
5106 if (h->dynindx == -1
5110 /* This references the local definition. We must
5111 initialize this entry in the global offset table.
5112 Since the offset must always be a multiple of 8,
5113 we use the least significant bit to record
5114 whether we have initialized it already.
5116 When doing a dynamic link, we create a .rela.got
5117 relocation entry to initialize the value. This
5118 is done in the finish_dynamic_symbol routine. */
5123 bfd_put_NN (output_bfd, value,
5124 base_got->contents + off);
5125 /* Note that this is harmless as -1 | 1 still is -1. */
5129 value = (base_got->output_section->vma
5130 + base_got->output_offset + off);
5133 value = aarch64_calculate_got_entry_vma (h, globals, info,
5135 unresolved_reloc_p);
5139 case BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14:
5140 case BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15:
5141 addend = (globals->root.sgot->output_section->vma
5142 + globals->root.sgot->output_offset);
5144 case BFD_RELOC_AARCH64_MOVW_GOTOFF_G0_NC:
5145 case BFD_RELOC_AARCH64_MOVW_GOTOFF_G1:
5146 case BFD_RELOC_AARCH64_LD64_GOTOFF_LO15:
5147 value = (value - globals->root.sgot->output_section->vma
5148 - globals->root.sgot->output_offset);
5153 value = _bfd_aarch64_elf_resolve_relocation (bfd_r_type, place, value,
5154 addend, weak_undef_p);
5155 return _bfd_aarch64_elf_put_addend (input_bfd, hit_data, bfd_r_type, howto, value);
5156 case BFD_RELOC_AARCH64_ADD_LO12:
5157 case BFD_RELOC_AARCH64_ADR_HI21_PCREL:
5164 case BFD_RELOC_AARCH64_NONE:
5165 case BFD_RELOC_AARCH64_TLSDESC_ADD:
5166 case BFD_RELOC_AARCH64_TLSDESC_CALL:
5167 case BFD_RELOC_AARCH64_TLSDESC_LDR:
5168 *unresolved_reloc_p = FALSE;
5169 return bfd_reloc_ok;
5171 case BFD_RELOC_AARCH64_NN:
5173 /* When generating a shared object or relocatable executable, these
5174 relocations are copied into the output file to be resolved at
5176 if (((bfd_link_pic (info) == TRUE)
5177 || globals->root.is_relocatable_executable)
5178 && (input_section->flags & SEC_ALLOC)
5180 || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
5181 || h->root.type != bfd_link_hash_undefweak))
5183 Elf_Internal_Rela outrel;
5185 bfd_boolean skip, relocate;
5188 *unresolved_reloc_p = FALSE;
5193 outrel.r_addend = signed_addend;
5195 _bfd_elf_section_offset (output_bfd, info, input_section,
5197 if (outrel.r_offset == (bfd_vma) - 1)
5199 else if (outrel.r_offset == (bfd_vma) - 2)
5205 outrel.r_offset += (input_section->output_section->vma
5206 + input_section->output_offset);
5209 memset (&outrel, 0, sizeof outrel);
5212 && (!bfd_link_pic (info)
5213 || !SYMBOLIC_BIND (info, h)
5214 || !h->def_regular))
5215 outrel.r_info = ELFNN_R_INFO (h->dynindx, r_type);
5220 /* On SVR4-ish systems, the dynamic loader cannot
5221 relocate the text and data segments independently,
5222 so the symbol does not matter. */
5224 outrel.r_info = ELFNN_R_INFO (symbol, AARCH64_R (RELATIVE));
5225 outrel.r_addend += value;
5228 sreloc = elf_section_data (input_section)->sreloc;
5229 if (sreloc == NULL || sreloc->contents == NULL)
5230 return bfd_reloc_notsupported;
5232 loc = sreloc->contents + sreloc->reloc_count++ * RELOC_SIZE (globals);
5233 bfd_elfNN_swap_reloca_out (output_bfd, &outrel, loc);
5235 if (sreloc->reloc_count * RELOC_SIZE (globals) > sreloc->size)
5237 /* Sanity to check that we have previously allocated
5238 sufficient space in the relocation section for the
5239 number of relocations we actually want to emit. */
5243 /* If this reloc is against an external symbol, we do not want to
5244 fiddle with the addend. Otherwise, we need to include the symbol
5245 value so that it becomes an addend for the dynamic reloc. */
5247 return bfd_reloc_ok;
5249 return _bfd_final_link_relocate (howto, input_bfd, input_section,
5250 contents, rel->r_offset, value,
5254 value += signed_addend;
5257 case BFD_RELOC_AARCH64_CALL26:
5258 case BFD_RELOC_AARCH64_JUMP26:
5260 asection *splt = globals->root.splt;
5261 bfd_boolean via_plt_p =
5262 splt != NULL && h != NULL && h->plt.offset != (bfd_vma) - 1;
5264 /* A call to an undefined weak symbol is converted to a jump to
5265 the next instruction unless a PLT entry will be created.
5266 The jump to the next instruction is optimized as a NOP.
5267 Do the same for local undefined symbols. */
5268 if (weak_undef_p && ! via_plt_p)
5270 bfd_putl32 (INSN_NOP, hit_data);
5271 return bfd_reloc_ok;
5274 /* If the call goes through a PLT entry, make sure to
5275 check distance to the right destination address. */
5277 value = (splt->output_section->vma
5278 + splt->output_offset + h->plt.offset);
5280 /* Check if a stub has to be inserted because the destination
5282 struct elf_aarch64_stub_hash_entry *stub_entry = NULL;
5284 /* If the branch destination is directed to plt stub, "value" will be
5285 the final destination, otherwise we should plus signed_addend, it may
5286 contain non-zero value, for example call to local function symbol
5287 which are turned into "sec_sym + sec_off", and sec_off is kept in
5289 if (! aarch64_valid_branch_p (via_plt_p ? value : value + signed_addend,
5291 /* The target is out of reach, so redirect the branch to
5292 the local stub for this function. */
5293 stub_entry = elfNN_aarch64_get_stub_entry (input_section, sym_sec, h,
5295 if (stub_entry != NULL)
5297 value = (stub_entry->stub_offset
5298 + stub_entry->stub_sec->output_offset
5299 + stub_entry->stub_sec->output_section->vma);
5301 /* We have redirected the destination to stub entry address,
5302 so ignore any addend record in the original rela entry. */
5306 value = _bfd_aarch64_elf_resolve_relocation (bfd_r_type, place, value,
5307 signed_addend, weak_undef_p);
5308 *unresolved_reloc_p = FALSE;
5311 case BFD_RELOC_AARCH64_16_PCREL:
5312 case BFD_RELOC_AARCH64_32_PCREL:
5313 case BFD_RELOC_AARCH64_64_PCREL:
5314 case BFD_RELOC_AARCH64_ADR_HI21_NC_PCREL:
5315 case BFD_RELOC_AARCH64_ADR_HI21_PCREL:
5316 case BFD_RELOC_AARCH64_ADR_LO21_PCREL:
5317 case BFD_RELOC_AARCH64_LD_LO19_PCREL:
5318 if (bfd_link_pic (info)
5319 && (input_section->flags & SEC_ALLOC) != 0
5320 && (input_section->flags & SEC_READONLY) != 0
5324 int howto_index = bfd_r_type - BFD_RELOC_AARCH64_RELOC_START;
5326 (*_bfd_error_handler)
5327 (_("%B: relocation %s against external symbol `%s' can not be used"
5328 " when making a shared object; recompile with -fPIC"),
5329 input_bfd, elfNN_aarch64_howto_table[howto_index].name,
5330 h->root.root.string);
5331 bfd_set_error (bfd_error_bad_value);
5335 case BFD_RELOC_AARCH64_16:
5337 case BFD_RELOC_AARCH64_32:
5339 case BFD_RELOC_AARCH64_ADD_LO12:
5340 case BFD_RELOC_AARCH64_BRANCH19:
5341 case BFD_RELOC_AARCH64_LDST128_LO12:
5342 case BFD_RELOC_AARCH64_LDST16_LO12:
5343 case BFD_RELOC_AARCH64_LDST32_LO12:
5344 case BFD_RELOC_AARCH64_LDST64_LO12:
5345 case BFD_RELOC_AARCH64_LDST8_LO12:
5346 case BFD_RELOC_AARCH64_MOVW_G0:
5347 case BFD_RELOC_AARCH64_MOVW_G0_NC:
5348 case BFD_RELOC_AARCH64_MOVW_G0_S:
5349 case BFD_RELOC_AARCH64_MOVW_G1:
5350 case BFD_RELOC_AARCH64_MOVW_G1_NC:
5351 case BFD_RELOC_AARCH64_MOVW_G1_S:
5352 case BFD_RELOC_AARCH64_MOVW_G2:
5353 case BFD_RELOC_AARCH64_MOVW_G2_NC:
5354 case BFD_RELOC_AARCH64_MOVW_G2_S:
5355 case BFD_RELOC_AARCH64_MOVW_G3:
5356 case BFD_RELOC_AARCH64_TSTBR14:
5357 value = _bfd_aarch64_elf_resolve_relocation (bfd_r_type, place, value,
5358 signed_addend, weak_undef_p);
5361 case BFD_RELOC_AARCH64_ADR_GOT_PAGE:
5362 case BFD_RELOC_AARCH64_GOT_LD_PREL19:
5363 case BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14:
5364 case BFD_RELOC_AARCH64_LD32_GOT_LO12_NC:
5365 case BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15:
5366 case BFD_RELOC_AARCH64_LD64_GOT_LO12_NC:
5367 if (globals->root.sgot == NULL)
5368 BFD_ASSERT (h != NULL);
5373 value = aarch64_calculate_got_entry_vma (h, globals, info, value,
5375 unresolved_reloc_p);
5376 if (bfd_r_type == BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15
5377 || bfd_r_type == BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14)
5378 addend = (globals->root.sgot->output_section->vma
5379 + globals->root.sgot->output_offset);
5380 value = _bfd_aarch64_elf_resolve_relocation (bfd_r_type, place, value,
5381 addend, weak_undef_p);
5386 struct elf_aarch64_local_symbol *locals
5387 = elf_aarch64_locals (input_bfd);
5391 int howto_index = bfd_r_type - BFD_RELOC_AARCH64_RELOC_START;
5392 (*_bfd_error_handler)
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;
5460 (*_bfd_error_handler)
5461 (_("%B: Local symbol descriptor table be NULL when applying "
5462 "relocation %s against local symbol"),
5463 input_bfd, elfNN_aarch64_howto_table[howto_index].name);
5467 off = symbol_got_offset (input_bfd, h, r_symndx);
5468 base_got = globals->root.sgot;
5469 if (base_got == NULL)
5472 bfd_vma got_entry_addr = (base_got->output_section->vma
5473 + base_got->output_offset + off);
5475 if (!symbol_got_offset_mark_p (input_bfd, h, r_symndx))
5477 bfd_put_64 (output_bfd, value, base_got->contents + off);
5479 if (bfd_link_pic (info))
5482 Elf_Internal_Rela outrel;
5484 /* For local symbol, we have done absolute relocation in static
5485 linking stage. While for share library, we need to update
5486 the content of GOT entry according to the share objects
5487 loading base address. So we need to generate a
5488 R_AARCH64_RELATIVE reloc for dynamic linker. */
5489 s = globals->root.srelgot;
5493 outrel.r_offset = got_entry_addr;
5494 outrel.r_info = ELFNN_R_INFO (0, AARCH64_R (RELATIVE));
5495 outrel.r_addend = value;
5496 elf_append_rela (output_bfd, s, &outrel);
5499 symbol_got_offset_mark (input_bfd, h, r_symndx);
5503 /* Update the relocation value to GOT entry addr as we have transformed
5504 the direct data access into indirect data access through GOT. */
5505 value = symbol_got_offset (input_bfd, h, r_symndx);
5506 value = _bfd_aarch64_elf_resolve_relocation (bfd_r_type, place, value,
5508 *unresolved_reloc_p = FALSE;
5511 case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC:
5512 case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21:
5513 case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21:
5514 case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21:
5515 case BFD_RELOC_AARCH64_TLSIE_LD32_GOTTPREL_LO12_NC:
5516 case BFD_RELOC_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC:
5517 case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19:
5518 case BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC:
5519 case BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21:
5520 case BFD_RELOC_AARCH64_TLSLD_ADR_PREL21:
5521 if (globals->root.sgot == NULL)
5522 return bfd_reloc_notsupported;
5524 value = (symbol_got_offset (input_bfd, h, r_symndx)
5525 + globals->root.sgot->output_section->vma
5526 + globals->root.sgot->output_offset);
5528 value = _bfd_aarch64_elf_resolve_relocation (bfd_r_type, place, value,
5530 *unresolved_reloc_p = FALSE;
5533 case BFD_RELOC_AARCH64_TLSGD_MOVW_G0_NC:
5534 case BFD_RELOC_AARCH64_TLSGD_MOVW_G1:
5535 case BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G0_NC:
5536 case BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G1:
5537 if (globals->root.sgot == NULL)
5538 return bfd_reloc_notsupported;
5540 value = symbol_got_offset (input_bfd, h, r_symndx);
5541 value = _bfd_aarch64_elf_resolve_relocation (bfd_r_type, place, value,
5543 *unresolved_reloc_p = FALSE;
5546 case BFD_RELOC_AARCH64_TLSLD_ADD_DTPREL_HI12:
5547 case BFD_RELOC_AARCH64_TLSLD_ADD_DTPREL_LO12:
5548 case BFD_RELOC_AARCH64_TLSLD_ADD_DTPREL_LO12_NC:
5549 case BFD_RELOC_AARCH64_TLSLD_LDST16_DTPREL_LO12:
5550 case BFD_RELOC_AARCH64_TLSLD_LDST16_DTPREL_LO12_NC:
5551 case BFD_RELOC_AARCH64_TLSLD_LDST32_DTPREL_LO12:
5552 case BFD_RELOC_AARCH64_TLSLD_LDST32_DTPREL_LO12_NC:
5553 case BFD_RELOC_AARCH64_TLSLD_LDST64_DTPREL_LO12:
5554 case BFD_RELOC_AARCH64_TLSLD_LDST64_DTPREL_LO12_NC:
5555 case BFD_RELOC_AARCH64_TLSLD_LDST8_DTPREL_LO12:
5556 case BFD_RELOC_AARCH64_TLSLD_LDST8_DTPREL_LO12_NC:
5557 case BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G0:
5558 case BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G0_NC:
5559 case BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G1:
5560 case BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G1_NC:
5561 case BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G2:
5562 value = _bfd_aarch64_elf_resolve_relocation (bfd_r_type, place, value,
5563 signed_addend - dtpoff_base (info),
5567 case BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_HI12:
5568 case BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_LO12:
5569 case BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_LO12_NC:
5570 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0:
5571 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC:
5572 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1:
5573 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1_NC:
5574 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G2:
5575 value = _bfd_aarch64_elf_resolve_relocation (bfd_r_type, place, value,
5576 signed_addend - tpoff_base (info),
5578 *unresolved_reloc_p = FALSE;
5581 case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12_NC:
5582 case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21:
5583 case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21:
5584 case BFD_RELOC_AARCH64_TLSDESC_LD32_LO12_NC:
5585 case BFD_RELOC_AARCH64_TLSDESC_LD64_LO12_NC:
5586 case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19:
5587 if (globals->root.sgot == NULL)
5588 return bfd_reloc_notsupported;
5589 value = (symbol_tlsdesc_got_offset (input_bfd, h, r_symndx)
5590 + globals->root.sgotplt->output_section->vma
5591 + globals->root.sgotplt->output_offset
5592 + globals->sgotplt_jump_table_size);
5594 value = _bfd_aarch64_elf_resolve_relocation (bfd_r_type, place, value,
5596 *unresolved_reloc_p = FALSE;
5599 case BFD_RELOC_AARCH64_TLSDESC_OFF_G0_NC:
5600 case BFD_RELOC_AARCH64_TLSDESC_OFF_G1:
5601 if (globals->root.sgot == NULL)
5602 return bfd_reloc_notsupported;
5604 value = (symbol_tlsdesc_got_offset (input_bfd, h, r_symndx)
5605 + globals->root.sgotplt->output_section->vma
5606 + globals->root.sgotplt->output_offset
5607 + globals->sgotplt_jump_table_size);
5609 value -= (globals->root.sgot->output_section->vma
5610 + globals->root.sgot->output_offset);
5612 value = _bfd_aarch64_elf_resolve_relocation (bfd_r_type, place, value,
5614 *unresolved_reloc_p = FALSE;
5618 return bfd_reloc_notsupported;
5622 *saved_addend = value;
5624 /* Only apply the final relocation in a sequence. */
5626 return bfd_reloc_continue;
5628 return _bfd_aarch64_elf_put_addend (input_bfd, hit_data, bfd_r_type,
5632 /* Handle TLS relaxations. Relaxing is possible for symbols that use
5633 R_AARCH64_TLSDESC_ADR_{PAGE, LD64_LO12_NC, ADD_LO12_NC} during a static
5636 Return bfd_reloc_ok if we're done, bfd_reloc_continue if the caller
5637 is to then call final_link_relocate. Return other values in the
5640 static bfd_reloc_status_type
5641 elfNN_aarch64_tls_relax (struct elf_aarch64_link_hash_table *globals,
5642 bfd *input_bfd, bfd_byte *contents,
5643 Elf_Internal_Rela *rel, struct elf_link_hash_entry *h)
5645 bfd_boolean is_local = h == NULL;
5646 unsigned int r_type = ELFNN_R_TYPE (rel->r_info);
5649 BFD_ASSERT (globals && input_bfd && contents && rel);
5651 switch (elfNN_aarch64_bfd_reloc_from_type (r_type))
5653 case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21:
5654 case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21:
5657 /* GD->LE relaxation:
5658 adrp x0, :tlsgd:var => movz x0, :tprel_g1:var
5660 adrp x0, :tlsdesc:var => movz x0, :tprel_g1:var
5662 bfd_putl32 (0xd2a00000, contents + rel->r_offset);
5663 return bfd_reloc_continue;
5667 /* GD->IE relaxation:
5668 adrp x0, :tlsgd:var => adrp x0, :gottprel:var
5670 adrp x0, :tlsdesc:var => adrp x0, :gottprel:var
5672 return bfd_reloc_continue;
5675 case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21:
5679 case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19:
5682 /* Tiny TLSDESC->LE relaxation:
5683 ldr x1, :tlsdesc:var => movz x0, #:tprel_g1:var
5684 adr x0, :tlsdesc:var => movk x0, #:tprel_g0_nc:var
5688 BFD_ASSERT (ELFNN_R_TYPE (rel[1].r_info) == AARCH64_R (TLSDESC_ADR_PREL21));
5689 BFD_ASSERT (ELFNN_R_TYPE (rel[2].r_info) == AARCH64_R (TLSDESC_CALL));
5691 rel[1].r_info = ELFNN_R_INFO (ELFNN_R_SYM (rel->r_info),
5692 AARCH64_R (TLSLE_MOVW_TPREL_G0_NC));
5693 rel[2].r_info = ELFNN_R_INFO (STN_UNDEF, R_AARCH64_NONE);
5695 bfd_putl32 (0xd2a00000, contents + rel->r_offset);
5696 bfd_putl32 (0xf2800000, contents + rel->r_offset + 4);
5697 bfd_putl32 (INSN_NOP, contents + rel->r_offset + 8);
5698 return bfd_reloc_continue;
5702 /* Tiny TLSDESC->IE relaxation:
5703 ldr x1, :tlsdesc:var => ldr x0, :gottprel:var
5704 adr x0, :tlsdesc:var => nop
5708 BFD_ASSERT (ELFNN_R_TYPE (rel[1].r_info) == AARCH64_R (TLSDESC_ADR_PREL21));
5709 BFD_ASSERT (ELFNN_R_TYPE (rel[2].r_info) == AARCH64_R (TLSDESC_CALL));
5711 rel[1].r_info = ELFNN_R_INFO (STN_UNDEF, R_AARCH64_NONE);
5712 rel[2].r_info = ELFNN_R_INFO (STN_UNDEF, R_AARCH64_NONE);
5714 bfd_putl32 (0x58000000, contents + rel->r_offset);
5715 bfd_putl32 (INSN_NOP, contents + rel->r_offset + 4);
5716 bfd_putl32 (INSN_NOP, contents + rel->r_offset + 8);
5717 return bfd_reloc_continue;
5720 case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21:
5723 /* Tiny GD->LE relaxation:
5724 adr x0, :tlsgd:var => mrs x1, tpidr_el0
5725 bl __tls_get_addr => add x0, x1, #:tprel_hi12:x, lsl #12
5726 nop => add x0, x0, #:tprel_lo12_nc:x
5729 /* First kill the tls_get_addr reloc on the bl instruction. */
5730 BFD_ASSERT (rel->r_offset + 4 == rel[1].r_offset);
5732 bfd_putl32 (0xd53bd041, contents + rel->r_offset + 0);
5733 bfd_putl32 (0x91400020, contents + rel->r_offset + 4);
5734 bfd_putl32 (0x91000000, contents + rel->r_offset + 8);
5736 rel[1].r_info = ELFNN_R_INFO (ELFNN_R_SYM (rel->r_info),
5737 AARCH64_R (TLSLE_ADD_TPREL_LO12_NC));
5738 rel[1].r_offset = rel->r_offset + 8;
5740 /* Move the current relocation to the second instruction in
5743 rel->r_info = ELFNN_R_INFO (ELFNN_R_SYM (rel->r_info),
5744 AARCH64_R (TLSLE_ADD_TPREL_HI12));
5745 return bfd_reloc_continue;
5749 /* Tiny GD->IE relaxation:
5750 adr x0, :tlsgd:var => ldr x0, :gottprel:var
5751 bl __tls_get_addr => mrs x1, tpidr_el0
5752 nop => add x0, x0, x1
5755 /* First kill the tls_get_addr reloc on the bl instruction. */
5756 BFD_ASSERT (rel->r_offset + 4 == rel[1].r_offset);
5757 rel[1].r_info = ELFNN_R_INFO (STN_UNDEF, R_AARCH64_NONE);
5759 bfd_putl32 (0x58000000, contents + rel->r_offset);
5760 bfd_putl32 (0xd53bd041, contents + rel->r_offset + 4);
5761 bfd_putl32 (0x8b000020, contents + rel->r_offset + 8);
5762 return bfd_reloc_continue;
5766 case BFD_RELOC_AARCH64_TLSGD_MOVW_G1:
5767 BFD_ASSERT (ELFNN_R_TYPE (rel[1].r_info) == AARCH64_R (TLSGD_MOVW_G0_NC));
5768 BFD_ASSERT (rel->r_offset + 12 == rel[2].r_offset);
5769 BFD_ASSERT (ELFNN_R_TYPE (rel[2].r_info) == AARCH64_R (CALL26));
5773 /* Large GD->LE relaxation:
5774 movz x0, #:tlsgd_g1:var => movz x0, #:tprel_g2:var, lsl #32
5775 movk x0, #:tlsgd_g0_nc:var => movk x0, #:tprel_g1_nc:var, lsl #16
5776 add x0, gp, x0 => movk x0, #:tprel_g0_nc:var
5777 bl __tls_get_addr => mrs x1, tpidr_el0
5778 nop => add x0, x0, x1
5780 rel[2].r_info = ELFNN_R_INFO (ELFNN_R_SYM (rel->r_info),
5781 AARCH64_R (TLSLE_MOVW_TPREL_G0_NC));
5782 rel[2].r_offset = rel->r_offset + 8;
5784 bfd_putl32 (0xd2c00000, contents + rel->r_offset + 0);
5785 bfd_putl32 (0xf2a00000, contents + rel->r_offset + 4);
5786 bfd_putl32 (0xf2800000, contents + rel->r_offset + 8);
5787 bfd_putl32 (0xd53bd041, contents + rel->r_offset + 12);
5788 bfd_putl32 (0x8b000020, contents + rel->r_offset + 16);
5792 /* Large GD->IE relaxation:
5793 movz x0, #:tlsgd_g1:var => movz x0, #:gottprel_g1:var, lsl #16
5794 movk x0, #:tlsgd_g0_nc:var => movk x0, #:gottprel_g0_nc:var
5795 add x0, gp, x0 => ldr x0, [gp, x0]
5796 bl __tls_get_addr => mrs x1, tpidr_el0
5797 nop => add x0, x0, x1
5799 rel[2].r_info = ELFNN_R_INFO (STN_UNDEF, R_AARCH64_NONE);
5800 bfd_putl32 (0xd2a80000, contents + rel->r_offset + 0);
5801 bfd_putl32 (0x58000000, contents + rel->r_offset + 8);
5802 bfd_putl32 (0xd53bd041, contents + rel->r_offset + 12);
5803 bfd_putl32 (0x8b000020, contents + rel->r_offset + 16);
5805 return bfd_reloc_continue;
5807 case BFD_RELOC_AARCH64_TLSGD_MOVW_G0_NC:
5808 return bfd_reloc_continue;
5811 case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19:
5812 return bfd_reloc_continue;
5814 case BFD_RELOC_AARCH64_TLSDESC_LDNN_LO12_NC:
5817 /* GD->LE relaxation:
5818 ldr xd, [x0, #:tlsdesc_lo12:var] => movk x0, :tprel_g0_nc:var
5820 bfd_putl32 (0xf2800000, contents + rel->r_offset);
5821 return bfd_reloc_continue;
5825 /* GD->IE relaxation:
5826 ldr xd, [x0, #:tlsdesc_lo12:var] => ldr x0, [x0, #:gottprel_lo12:var]
5828 insn = bfd_getl32 (contents + rel->r_offset);
5830 bfd_putl32 (insn, contents + rel->r_offset);
5831 return bfd_reloc_continue;
5834 case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC:
5837 /* GD->LE relaxation
5838 add x0, #:tlsgd_lo12:var => movk x0, :tprel_g0_nc:var
5839 bl __tls_get_addr => mrs x1, tpidr_el0
5840 nop => add x0, x1, x0
5843 /* First kill the tls_get_addr reloc on the bl instruction. */
5844 BFD_ASSERT (rel->r_offset + 4 == rel[1].r_offset);
5845 rel[1].r_info = ELFNN_R_INFO (STN_UNDEF, R_AARCH64_NONE);
5847 bfd_putl32 (0xf2800000, contents + rel->r_offset);
5848 bfd_putl32 (0xd53bd041, contents + rel->r_offset + 4);
5849 bfd_putl32 (0x8b000020, contents + rel->r_offset + 8);
5850 return bfd_reloc_continue;
5854 /* GD->IE relaxation
5855 ADD x0, #:tlsgd_lo12:var => ldr x0, [x0, #:gottprel_lo12:var]
5856 BL __tls_get_addr => mrs x1, tpidr_el0
5858 NOP => add x0, x1, x0
5861 BFD_ASSERT (ELFNN_R_TYPE (rel[1].r_info) == AARCH64_R (CALL26));
5863 /* Remove the relocation on the BL instruction. */
5864 rel[1].r_info = ELFNN_R_INFO (STN_UNDEF, R_AARCH64_NONE);
5866 bfd_putl32 (0xf9400000, contents + rel->r_offset);
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. */
5871 bfd_putl32 (0xd53bd041, contents + rel[1].r_offset);
5872 bfd_putl32 (0x8b000020, contents + rel[1].r_offset + 4);
5873 return bfd_reloc_continue;
5876 case BFD_RELOC_AARCH64_TLSDESC_ADD:
5877 case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12_NC:
5878 case BFD_RELOC_AARCH64_TLSDESC_CALL:
5879 /* GD->IE/LE relaxation:
5880 add x0, x0, #:tlsdesc_lo12:var => nop
5883 bfd_putl32 (INSN_NOP, contents + rel->r_offset);
5884 return bfd_reloc_ok;
5886 case BFD_RELOC_AARCH64_TLSDESC_LDR:
5889 /* GD->LE relaxation:
5890 ldr xd, [gp, xn] => movk x0, #:tprel_g0_nc:var
5892 bfd_putl32 (0xf2800000, contents + rel->r_offset);
5893 return bfd_reloc_continue;
5897 /* GD->IE relaxation:
5898 ldr xd, [gp, xn] => ldr x0, [gp, xn]
5900 insn = bfd_getl32 (contents + rel->r_offset);
5902 bfd_putl32 (insn, contents + rel->r_offset);
5903 return bfd_reloc_ok;
5906 case BFD_RELOC_AARCH64_TLSDESC_OFF_G0_NC:
5907 /* GD->LE relaxation:
5908 movk xd, #:tlsdesc_off_g0_nc:var => movk x0, #:tprel_g1_nc:var, lsl #16
5910 movk xd, #:tlsdesc_off_g0_nc:var => movk xd, #:gottprel_g0_nc:var
5913 bfd_putl32 (0xf2a00000, contents + rel->r_offset);
5914 return bfd_reloc_continue;
5916 case BFD_RELOC_AARCH64_TLSDESC_OFF_G1:
5919 /* GD->LE relaxation:
5920 movz xd, #:tlsdesc_off_g1:var => movz x0, #:tprel_g2:var, lsl #32
5922 bfd_putl32 (0xd2c00000, contents + rel->r_offset);
5923 return bfd_reloc_continue;
5927 /* GD->IE relaxation:
5928 movz xd, #:tlsdesc_off_g1:var => movz xd, #:gottprel_g1:var, lsl #16
5930 insn = bfd_getl32 (contents + rel->r_offset);
5931 bfd_putl32 (0xd2a00000 | (insn & 0x1f), contents + rel->r_offset);
5932 return bfd_reloc_continue;
5935 case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21:
5936 /* IE->LE relaxation:
5937 adrp xd, :gottprel:var => movz xd, :tprel_g1:var
5941 insn = bfd_getl32 (contents + rel->r_offset);
5942 bfd_putl32 (0xd2a00000 | (insn & 0x1f), contents + rel->r_offset);
5944 return bfd_reloc_continue;
5946 case BFD_RELOC_AARCH64_TLSIE_LDNN_GOTTPREL_LO12_NC:
5947 /* IE->LE relaxation:
5948 ldr xd, [xm, #:gottprel_lo12:var] => movk xd, :tprel_g0_nc:var
5952 insn = bfd_getl32 (contents + rel->r_offset);
5953 bfd_putl32 (0xf2800000 | (insn & 0x1f), contents + rel->r_offset);
5955 return bfd_reloc_continue;
5957 case BFD_RELOC_AARCH64_TLSLD_ADR_PREL21:
5958 /* LD->LE relaxation (tiny):
5959 adr x0, :tlsldm:x => mrs x0, tpidr_el0
5960 bl __tls_get_addr => add x0, x0, TCB_SIZE
5964 BFD_ASSERT (rel->r_offset + 4 == rel[1].r_offset);
5965 BFD_ASSERT (ELFNN_R_TYPE (rel[1].r_info) == AARCH64_R (CALL26));
5966 /* No need of CALL26 relocation for tls_get_addr. */
5967 rel[1].r_info = ELFNN_R_INFO (STN_UNDEF, R_AARCH64_NONE);
5968 bfd_putl32 (0xd53bd040, contents + rel->r_offset + 0);
5969 bfd_putl32 (0x91004000, contents + rel->r_offset + 4);
5970 return bfd_reloc_ok;
5972 return bfd_reloc_continue;
5974 case BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21:
5975 /* LD->LE relaxation (small):
5976 adrp x0, :tlsldm:x => mrs x0, tpidr_el0
5980 bfd_putl32 (0xd53bd040, contents + rel->r_offset);
5981 return bfd_reloc_ok;
5983 return bfd_reloc_continue;
5985 case BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC:
5986 /* LD->LE relaxation (small):
5987 add x0, #:tlsldm_lo12:x => add x0, x0, TCB_SIZE
5988 bl __tls_get_addr => nop
5992 BFD_ASSERT (rel->r_offset + 4 == rel[1].r_offset);
5993 BFD_ASSERT (ELFNN_R_TYPE (rel[1].r_info) == AARCH64_R (CALL26));
5994 /* No need of CALL26 relocation for tls_get_addr. */
5995 rel[1].r_info = ELFNN_R_INFO (STN_UNDEF, R_AARCH64_NONE);
5996 bfd_putl32 (0x91004000, contents + rel->r_offset + 0);
5997 bfd_putl32 (0xd503201f, contents + rel->r_offset + 4);
5998 return bfd_reloc_ok;
6000 return bfd_reloc_continue;
6003 return bfd_reloc_continue;
6006 return bfd_reloc_ok;
6009 /* Relocate an AArch64 ELF section. */
6012 elfNN_aarch64_relocate_section (bfd *output_bfd,
6013 struct bfd_link_info *info,
6015 asection *input_section,
6017 Elf_Internal_Rela *relocs,
6018 Elf_Internal_Sym *local_syms,
6019 asection **local_sections)
6021 Elf_Internal_Shdr *symtab_hdr;
6022 struct elf_link_hash_entry **sym_hashes;
6023 Elf_Internal_Rela *rel;
6024 Elf_Internal_Rela *relend;
6026 struct elf_aarch64_link_hash_table *globals;
6027 bfd_boolean save_addend = FALSE;
6030 globals = elf_aarch64_hash_table (info);
6032 symtab_hdr = &elf_symtab_hdr (input_bfd);
6033 sym_hashes = elf_sym_hashes (input_bfd);
6036 relend = relocs + input_section->reloc_count;
6037 for (; rel < relend; rel++)
6039 unsigned int r_type;
6040 bfd_reloc_code_real_type bfd_r_type;
6041 bfd_reloc_code_real_type relaxed_bfd_r_type;
6042 reloc_howto_type *howto;
6043 unsigned long r_symndx;
6044 Elf_Internal_Sym *sym;
6046 struct elf_link_hash_entry *h;
6048 bfd_reloc_status_type r;
6051 bfd_boolean unresolved_reloc = FALSE;
6052 char *error_message = NULL;
6054 r_symndx = ELFNN_R_SYM (rel->r_info);
6055 r_type = ELFNN_R_TYPE (rel->r_info);
6057 bfd_reloc.howto = elfNN_aarch64_howto_from_type (r_type);
6058 howto = bfd_reloc.howto;
6062 (*_bfd_error_handler)
6063 (_("%B: unrecognized relocation (0x%x) in section `%A'"),
6064 input_bfd, input_section, r_type);
6067 bfd_r_type = elfNN_aarch64_bfd_reloc_from_howto (howto);
6073 if (r_symndx < symtab_hdr->sh_info)
6075 sym = local_syms + r_symndx;
6076 sym_type = ELFNN_ST_TYPE (sym->st_info);
6077 sec = local_sections[r_symndx];
6079 /* An object file might have a reference to a local
6080 undefined symbol. This is a daft object file, but we
6081 should at least do something about it. */
6082 if (r_type != R_AARCH64_NONE && r_type != R_AARCH64_NULL
6083 && bfd_is_und_section (sec)
6084 && ELF_ST_BIND (sym->st_info) != STB_WEAK)
6086 if (!info->callbacks->undefined_symbol
6087 (info, bfd_elf_string_from_elf_section
6088 (input_bfd, symtab_hdr->sh_link, sym->st_name),
6089 input_bfd, input_section, rel->r_offset, TRUE))
6093 relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel);
6095 /* Relocate against local STT_GNU_IFUNC symbol. */
6096 if (!bfd_link_relocatable (info)
6097 && ELF_ST_TYPE (sym->st_info) == STT_GNU_IFUNC)
6099 h = elfNN_aarch64_get_local_sym_hash (globals, input_bfd,
6104 /* Set STT_GNU_IFUNC symbol value. */
6105 h->root.u.def.value = sym->st_value;
6106 h->root.u.def.section = sec;
6111 bfd_boolean warned, ignored;
6113 RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel,
6114 r_symndx, symtab_hdr, sym_hashes,
6116 unresolved_reloc, warned, ignored);
6121 if (sec != NULL && discarded_section (sec))
6122 RELOC_AGAINST_DISCARDED_SECTION (info, input_bfd, input_section,
6123 rel, 1, relend, howto, 0, contents);
6125 if (bfd_link_relocatable (info))
6129 name = h->root.root.string;
6132 name = (bfd_elf_string_from_elf_section
6133 (input_bfd, symtab_hdr->sh_link, sym->st_name));
6134 if (name == NULL || *name == '\0')
6135 name = bfd_section_name (input_bfd, sec);
6139 && r_type != R_AARCH64_NONE
6140 && r_type != R_AARCH64_NULL
6142 || h->root.type == bfd_link_hash_defined
6143 || h->root.type == bfd_link_hash_defweak)
6144 && IS_AARCH64_TLS_RELOC (bfd_r_type) != (sym_type == STT_TLS))
6146 (*_bfd_error_handler)
6147 ((sym_type == STT_TLS
6148 ? _("%B(%A+0x%lx): %s used with TLS symbol %s")
6149 : _("%B(%A+0x%lx): %s used with non-TLS symbol %s")),
6151 input_section, (long) rel->r_offset, howto->name, name);
6154 /* We relax only if we can see that there can be a valid transition
6155 from a reloc type to another.
6156 We call elfNN_aarch64_final_link_relocate unless we're completely
6157 done, i.e., the relaxation produced the final output we want. */
6159 relaxed_bfd_r_type = aarch64_tls_transition (input_bfd, info, r_type,
6161 if (relaxed_bfd_r_type != bfd_r_type)
6163 bfd_r_type = relaxed_bfd_r_type;
6164 howto = elfNN_aarch64_howto_from_bfd_reloc (bfd_r_type);
6165 BFD_ASSERT (howto != NULL);
6166 r_type = howto->type;
6167 r = elfNN_aarch64_tls_relax (globals, input_bfd, contents, rel, h);
6168 unresolved_reloc = 0;
6171 r = bfd_reloc_continue;
6173 /* There may be multiple consecutive relocations for the
6174 same offset. In that case we are supposed to treat the
6175 output of each relocation as the addend for the next. */
6176 if (rel + 1 < relend
6177 && rel->r_offset == rel[1].r_offset
6178 && ELFNN_R_TYPE (rel[1].r_info) != R_AARCH64_NONE
6179 && ELFNN_R_TYPE (rel[1].r_info) != R_AARCH64_NULL)
6182 save_addend = FALSE;
6184 if (r == bfd_reloc_continue)
6185 r = elfNN_aarch64_final_link_relocate (howto, input_bfd, output_bfd,
6186 input_section, contents, rel,
6187 relocation, info, sec,
6188 h, &unresolved_reloc,
6189 save_addend, &addend, sym);
6191 switch (elfNN_aarch64_bfd_reloc_from_type (r_type))
6193 case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC:
6194 case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21:
6195 case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21:
6196 case BFD_RELOC_AARCH64_TLSGD_MOVW_G0_NC:
6197 case BFD_RELOC_AARCH64_TLSGD_MOVW_G1:
6198 case BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC:
6199 case BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21:
6200 case BFD_RELOC_AARCH64_TLSLD_ADR_PREL21:
6201 if (! symbol_got_offset_mark_p (input_bfd, h, r_symndx))
6203 bfd_boolean need_relocs = FALSE;
6208 off = symbol_got_offset (input_bfd, h, r_symndx);
6209 indx = h && h->dynindx != -1 ? h->dynindx : 0;
6212 (bfd_link_pic (info) || indx != 0) &&
6214 || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
6215 || h->root.type != bfd_link_hash_undefweak);
6217 BFD_ASSERT (globals->root.srelgot != NULL);
6221 Elf_Internal_Rela rela;
6222 rela.r_info = ELFNN_R_INFO (indx, AARCH64_R (TLS_DTPMOD));
6224 rela.r_offset = globals->root.sgot->output_section->vma +
6225 globals->root.sgot->output_offset + off;
6228 loc = globals->root.srelgot->contents;
6229 loc += globals->root.srelgot->reloc_count++
6230 * RELOC_SIZE (htab);
6231 bfd_elfNN_swap_reloca_out (output_bfd, &rela, loc);
6233 bfd_reloc_code_real_type real_type =
6234 elfNN_aarch64_bfd_reloc_from_type (r_type);
6236 if (real_type == BFD_RELOC_AARCH64_TLSLD_ADR_PREL21
6237 || real_type == BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21
6238 || real_type == BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC)
6240 /* For local dynamic, don't generate DTPREL in any case.
6241 Initialize the DTPREL slot into zero, so we get module
6242 base address when invoke runtime TLS resolver. */
6243 bfd_put_NN (output_bfd, 0,
6244 globals->root.sgot->contents + off
6249 bfd_put_NN (output_bfd,
6250 relocation - dtpoff_base (info),
6251 globals->root.sgot->contents + off
6256 /* This TLS symbol is global. We emit a
6257 relocation to fixup the tls offset at load
6260 ELFNN_R_INFO (indx, AARCH64_R (TLS_DTPREL));
6263 (globals->root.sgot->output_section->vma
6264 + globals->root.sgot->output_offset + off
6267 loc = globals->root.srelgot->contents;
6268 loc += globals->root.srelgot->reloc_count++
6269 * RELOC_SIZE (globals);
6270 bfd_elfNN_swap_reloca_out (output_bfd, &rela, loc);
6271 bfd_put_NN (output_bfd, (bfd_vma) 0,
6272 globals->root.sgot->contents + off
6278 bfd_put_NN (output_bfd, (bfd_vma) 1,
6279 globals->root.sgot->contents + off);
6280 bfd_put_NN (output_bfd,
6281 relocation - dtpoff_base (info),
6282 globals->root.sgot->contents + off
6286 symbol_got_offset_mark (input_bfd, h, r_symndx);
6290 case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21:
6291 case BFD_RELOC_AARCH64_TLSIE_LDNN_GOTTPREL_LO12_NC:
6292 case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19:
6293 case BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G0_NC:
6294 case BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G1:
6295 if (! symbol_got_offset_mark_p (input_bfd, h, r_symndx))
6297 bfd_boolean need_relocs = FALSE;
6302 off = symbol_got_offset (input_bfd, h, r_symndx);
6304 indx = h && h->dynindx != -1 ? h->dynindx : 0;
6307 (bfd_link_pic (info) || indx != 0) &&
6309 || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
6310 || h->root.type != bfd_link_hash_undefweak);
6312 BFD_ASSERT (globals->root.srelgot != NULL);
6316 Elf_Internal_Rela rela;
6319 rela.r_addend = relocation - dtpoff_base (info);
6323 rela.r_info = ELFNN_R_INFO (indx, AARCH64_R (TLS_TPREL));
6324 rela.r_offset = globals->root.sgot->output_section->vma +
6325 globals->root.sgot->output_offset + off;
6327 loc = globals->root.srelgot->contents;
6328 loc += globals->root.srelgot->reloc_count++
6329 * RELOC_SIZE (htab);
6331 bfd_elfNN_swap_reloca_out (output_bfd, &rela, loc);
6333 bfd_put_NN (output_bfd, rela.r_addend,
6334 globals->root.sgot->contents + off);
6337 bfd_put_NN (output_bfd, relocation - tpoff_base (info),
6338 globals->root.sgot->contents + off);
6340 symbol_got_offset_mark (input_bfd, h, r_symndx);
6344 case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12_NC:
6345 case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21:
6346 case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21:
6347 case BFD_RELOC_AARCH64_TLSDESC_LDNN_LO12_NC:
6348 case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19:
6349 case BFD_RELOC_AARCH64_TLSDESC_OFF_G0_NC:
6350 case BFD_RELOC_AARCH64_TLSDESC_OFF_G1:
6351 if (! symbol_tlsdesc_got_offset_mark_p (input_bfd, h, r_symndx))
6353 bfd_boolean need_relocs = FALSE;
6354 int indx = h && h->dynindx != -1 ? h->dynindx : 0;
6355 bfd_vma off = symbol_tlsdesc_got_offset (input_bfd, h, r_symndx);
6357 need_relocs = (h == NULL
6358 || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
6359 || h->root.type != bfd_link_hash_undefweak);
6361 BFD_ASSERT (globals->root.srelgot != NULL);
6362 BFD_ASSERT (globals->root.sgot != NULL);
6367 Elf_Internal_Rela rela;
6368 rela.r_info = ELFNN_R_INFO (indx, AARCH64_R (TLSDESC));
6371 rela.r_offset = (globals->root.sgotplt->output_section->vma
6372 + globals->root.sgotplt->output_offset
6373 + off + globals->sgotplt_jump_table_size);
6376 rela.r_addend = relocation - dtpoff_base (info);
6378 /* Allocate the next available slot in the PLT reloc
6379 section to hold our R_AARCH64_TLSDESC, the next
6380 available slot is determined from reloc_count,
6381 which we step. But note, reloc_count was
6382 artifically moved down while allocating slots for
6383 real PLT relocs such that all of the PLT relocs
6384 will fit above the initial reloc_count and the
6385 extra stuff will fit below. */
6386 loc = globals->root.srelplt->contents;
6387 loc += globals->root.srelplt->reloc_count++
6388 * RELOC_SIZE (globals);
6390 bfd_elfNN_swap_reloca_out (output_bfd, &rela, loc);
6392 bfd_put_NN (output_bfd, (bfd_vma) 0,
6393 globals->root.sgotplt->contents + off +
6394 globals->sgotplt_jump_table_size);
6395 bfd_put_NN (output_bfd, (bfd_vma) 0,
6396 globals->root.sgotplt->contents + off +
6397 globals->sgotplt_jump_table_size +
6401 symbol_tlsdesc_got_offset_mark (input_bfd, h, r_symndx);
6412 /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
6413 because such sections are not SEC_ALLOC and thus ld.so will
6414 not process them. */
6415 if (unresolved_reloc
6416 && !((input_section->flags & SEC_DEBUGGING) != 0
6418 && _bfd_elf_section_offset (output_bfd, info, input_section,
6419 +rel->r_offset) != (bfd_vma) - 1)
6421 (*_bfd_error_handler)
6423 ("%B(%A+0x%lx): unresolvable %s relocation against symbol `%s'"),
6424 input_bfd, input_section, (long) rel->r_offset, howto->name,
6425 h->root.root.string);
6429 if (r != bfd_reloc_ok && r != bfd_reloc_continue)
6431 bfd_reloc_code_real_type real_r_type
6432 = elfNN_aarch64_bfd_reloc_from_type (r_type);
6436 case bfd_reloc_overflow:
6437 if (!(*info->callbacks->reloc_overflow)
6438 (info, (h ? &h->root : NULL), name, howto->name, (bfd_vma) 0,
6439 input_bfd, input_section, rel->r_offset))
6441 if (real_r_type == BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15
6442 || real_r_type == BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14)
6444 (*info->callbacks->warning)
6446 _("Too many GOT entries for -fpic, "
6447 "please recompile with -fPIC"),
6448 name, input_bfd, input_section, rel->r_offset);
6453 case bfd_reloc_undefined:
6454 if (!((*info->callbacks->undefined_symbol)
6455 (info, name, input_bfd, input_section,
6456 rel->r_offset, TRUE)))
6460 case bfd_reloc_outofrange:
6461 error_message = _("out of range");
6464 case bfd_reloc_notsupported:
6465 error_message = _("unsupported relocation");
6468 case bfd_reloc_dangerous:
6469 /* error_message should already be set. */
6473 error_message = _("unknown error");
6477 BFD_ASSERT (error_message != NULL);
6478 if (!((*info->callbacks->reloc_dangerous)
6479 (info, error_message, input_bfd, input_section,
6490 /* Set the right machine number. */
6493 elfNN_aarch64_object_p (bfd *abfd)
6496 bfd_default_set_arch_mach (abfd, bfd_arch_aarch64, bfd_mach_aarch64_ilp32);
6498 bfd_default_set_arch_mach (abfd, bfd_arch_aarch64, bfd_mach_aarch64);
6503 /* Function to keep AArch64 specific flags in the ELF header. */
6506 elfNN_aarch64_set_private_flags (bfd *abfd, flagword flags)
6508 if (elf_flags_init (abfd) && elf_elfheader (abfd)->e_flags != flags)
6513 elf_elfheader (abfd)->e_flags = flags;
6514 elf_flags_init (abfd) = TRUE;
6520 /* Merge backend specific data from an object file to the output
6521 object file when linking. */
6524 elfNN_aarch64_merge_private_bfd_data (bfd *ibfd, bfd *obfd)
6528 bfd_boolean flags_compatible = TRUE;
6531 /* Check if we have the same endianess. */
6532 if (!_bfd_generic_verify_endian_match (ibfd, obfd))
6535 if (!is_aarch64_elf (ibfd) || !is_aarch64_elf (obfd))
6538 /* The input BFD must have had its flags initialised. */
6539 /* The following seems bogus to me -- The flags are initialized in
6540 the assembler but I don't think an elf_flags_init field is
6541 written into the object. */
6542 /* BFD_ASSERT (elf_flags_init (ibfd)); */
6544 in_flags = elf_elfheader (ibfd)->e_flags;
6545 out_flags = elf_elfheader (obfd)->e_flags;
6547 if (!elf_flags_init (obfd))
6549 /* If the input is the default architecture and had the default
6550 flags then do not bother setting the flags for the output
6551 architecture, instead allow future merges to do this. If no
6552 future merges ever set these flags then they will retain their
6553 uninitialised values, which surprise surprise, correspond
6554 to the default values. */
6555 if (bfd_get_arch_info (ibfd)->the_default
6556 && elf_elfheader (ibfd)->e_flags == 0)
6559 elf_flags_init (obfd) = TRUE;
6560 elf_elfheader (obfd)->e_flags = in_flags;
6562 if (bfd_get_arch (obfd) == bfd_get_arch (ibfd)
6563 && bfd_get_arch_info (obfd)->the_default)
6564 return bfd_set_arch_mach (obfd, bfd_get_arch (ibfd),
6565 bfd_get_mach (ibfd));
6570 /* Identical flags must be compatible. */
6571 if (in_flags == out_flags)
6574 /* Check to see if the input BFD actually contains any sections. If
6575 not, its flags may not have been initialised either, but it
6576 cannot actually cause any incompatiblity. Do not short-circuit
6577 dynamic objects; their section list may be emptied by
6578 elf_link_add_object_symbols.
6580 Also check to see if there are no code sections in the input.
6581 In this case there is no need to check for code specific flags.
6582 XXX - do we need to worry about floating-point format compatability
6583 in data sections ? */
6584 if (!(ibfd->flags & DYNAMIC))
6586 bfd_boolean null_input_bfd = TRUE;
6587 bfd_boolean only_data_sections = TRUE;
6589 for (sec = ibfd->sections; sec != NULL; sec = sec->next)
6591 if ((bfd_get_section_flags (ibfd, sec)
6592 & (SEC_LOAD | SEC_CODE | SEC_HAS_CONTENTS))
6593 == (SEC_LOAD | SEC_CODE | SEC_HAS_CONTENTS))
6594 only_data_sections = FALSE;
6596 null_input_bfd = FALSE;
6600 if (null_input_bfd || only_data_sections)
6604 return flags_compatible;
6607 /* Display the flags field. */
6610 elfNN_aarch64_print_private_bfd_data (bfd *abfd, void *ptr)
6612 FILE *file = (FILE *) ptr;
6613 unsigned long flags;
6615 BFD_ASSERT (abfd != NULL && ptr != NULL);
6617 /* Print normal ELF private data. */
6618 _bfd_elf_print_private_bfd_data (abfd, ptr);
6620 flags = elf_elfheader (abfd)->e_flags;
6621 /* Ignore init flag - it may not be set, despite the flags field
6622 containing valid data. */
6624 /* xgettext:c-format */
6625 fprintf (file, _("private flags = %lx:"), elf_elfheader (abfd)->e_flags);
6628 fprintf (file, _("<Unrecognised flag bits set>"));
6635 /* Update the got entry reference counts for the section being removed. */
6638 elfNN_aarch64_gc_sweep_hook (bfd *abfd,
6639 struct bfd_link_info *info,
6641 const Elf_Internal_Rela * relocs)
6643 struct elf_aarch64_link_hash_table *htab;
6644 Elf_Internal_Shdr *symtab_hdr;
6645 struct elf_link_hash_entry **sym_hashes;
6646 struct elf_aarch64_local_symbol *locals;
6647 const Elf_Internal_Rela *rel, *relend;
6649 if (bfd_link_relocatable (info))
6652 htab = elf_aarch64_hash_table (info);
6657 elf_section_data (sec)->local_dynrel = NULL;
6659 symtab_hdr = &elf_symtab_hdr (abfd);
6660 sym_hashes = elf_sym_hashes (abfd);
6662 locals = elf_aarch64_locals (abfd);
6664 relend = relocs + sec->reloc_count;
6665 for (rel = relocs; rel < relend; rel++)
6667 unsigned long r_symndx;
6668 unsigned int r_type;
6669 struct elf_link_hash_entry *h = NULL;
6671 r_symndx = ELFNN_R_SYM (rel->r_info);
6673 if (r_symndx >= symtab_hdr->sh_info)
6676 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
6677 while (h->root.type == bfd_link_hash_indirect
6678 || h->root.type == bfd_link_hash_warning)
6679 h = (struct elf_link_hash_entry *) h->root.u.i.link;
6683 Elf_Internal_Sym *isym;
6685 /* A local symbol. */
6686 isym = bfd_sym_from_r_symndx (&htab->sym_cache,
6689 /* Check relocation against local STT_GNU_IFUNC symbol. */
6691 && ELF_ST_TYPE (isym->st_info) == STT_GNU_IFUNC)
6693 h = elfNN_aarch64_get_local_sym_hash (htab, abfd, rel, FALSE);
6701 struct elf_aarch64_link_hash_entry *eh;
6702 struct elf_dyn_relocs **pp;
6703 struct elf_dyn_relocs *p;
6705 eh = (struct elf_aarch64_link_hash_entry *) h;
6707 for (pp = &eh->dyn_relocs; (p = *pp) != NULL; pp = &p->next)
6710 /* Everything must go for SEC. */
6716 r_type = ELFNN_R_TYPE (rel->r_info);
6717 switch (aarch64_tls_transition (abfd,info, r_type, h ,r_symndx))
6719 case BFD_RELOC_AARCH64_ADR_GOT_PAGE:
6720 case BFD_RELOC_AARCH64_GOT_LD_PREL19:
6721 case BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14:
6722 case BFD_RELOC_AARCH64_LD32_GOT_LO12_NC:
6723 case BFD_RELOC_AARCH64_LD64_GOTOFF_LO15:
6724 case BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15:
6725 case BFD_RELOC_AARCH64_LD64_GOT_LO12_NC:
6726 case BFD_RELOC_AARCH64_MOVW_GOTOFF_G0_NC:
6727 case BFD_RELOC_AARCH64_MOVW_GOTOFF_G1:
6728 case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12_NC:
6729 case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21:
6730 case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21:
6731 case BFD_RELOC_AARCH64_TLSDESC_LD32_LO12_NC:
6732 case BFD_RELOC_AARCH64_TLSDESC_LD64_LO12_NC:
6733 case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19:
6734 case BFD_RELOC_AARCH64_TLSDESC_OFF_G0_NC:
6735 case BFD_RELOC_AARCH64_TLSDESC_OFF_G1:
6736 case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC:
6737 case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21:
6738 case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21:
6739 case BFD_RELOC_AARCH64_TLSGD_MOVW_G0_NC:
6740 case BFD_RELOC_AARCH64_TLSGD_MOVW_G1:
6741 case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21:
6742 case BFD_RELOC_AARCH64_TLSIE_LD32_GOTTPREL_LO12_NC:
6743 case BFD_RELOC_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC:
6744 case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19:
6745 case BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G0_NC:
6746 case BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G1:
6747 case BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC:
6748 case BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21:
6749 case BFD_RELOC_AARCH64_TLSLD_ADR_PREL21:
6752 if (h->got.refcount > 0)
6753 h->got.refcount -= 1;
6755 if (h->type == STT_GNU_IFUNC)
6757 if (h->plt.refcount > 0)
6758 h->plt.refcount -= 1;
6761 else if (locals != NULL)
6763 if (locals[r_symndx].got_refcount > 0)
6764 locals[r_symndx].got_refcount -= 1;
6768 case BFD_RELOC_AARCH64_CALL26:
6769 case BFD_RELOC_AARCH64_JUMP26:
6770 /* If this is a local symbol then we resolve it
6771 directly without creating a PLT entry. */
6775 if (h->plt.refcount > 0)
6776 h->plt.refcount -= 1;
6779 case BFD_RELOC_AARCH64_ADR_HI21_NC_PCREL:
6780 case BFD_RELOC_AARCH64_ADR_HI21_PCREL:
6781 case BFD_RELOC_AARCH64_ADR_LO21_PCREL:
6782 case BFD_RELOC_AARCH64_MOVW_G0_NC:
6783 case BFD_RELOC_AARCH64_MOVW_G1_NC:
6784 case BFD_RELOC_AARCH64_MOVW_G2_NC:
6785 case BFD_RELOC_AARCH64_MOVW_G3:
6786 case BFD_RELOC_AARCH64_NN:
6787 if (h != NULL && bfd_link_executable (info))
6789 if (h->plt.refcount > 0)
6790 h->plt.refcount -= 1;
6802 /* Adjust a symbol defined by a dynamic object and referenced by a
6803 regular object. The current definition is in some section of the
6804 dynamic object, but we're not including those sections. We have to
6805 change the definition to something the rest of the link can
6809 elfNN_aarch64_adjust_dynamic_symbol (struct bfd_link_info *info,
6810 struct elf_link_hash_entry *h)
6812 struct elf_aarch64_link_hash_table *htab;
6815 /* If this is a function, put it in the procedure linkage table. We
6816 will fill in the contents of the procedure linkage table later,
6817 when we know the address of the .got section. */
6818 if (h->type == STT_FUNC || h->type == STT_GNU_IFUNC || h->needs_plt)
6820 if (h->plt.refcount <= 0
6821 || (h->type != STT_GNU_IFUNC
6822 && (SYMBOL_CALLS_LOCAL (info, h)
6823 || (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
6824 && h->root.type == bfd_link_hash_undefweak))))
6826 /* This case can occur if we saw a CALL26 reloc in
6827 an input file, but the symbol wasn't referred to
6828 by a dynamic object or all references were
6829 garbage collected. In which case we can end up
6831 h->plt.offset = (bfd_vma) - 1;
6838 /* Otherwise, reset to -1. */
6839 h->plt.offset = (bfd_vma) - 1;
6842 /* If this is a weak symbol, and there is a real definition, the
6843 processor independent code will have arranged for us to see the
6844 real definition first, and we can just use the same value. */
6845 if (h->u.weakdef != NULL)
6847 BFD_ASSERT (h->u.weakdef->root.type == bfd_link_hash_defined
6848 || h->u.weakdef->root.type == bfd_link_hash_defweak);
6849 h->root.u.def.section = h->u.weakdef->root.u.def.section;
6850 h->root.u.def.value = h->u.weakdef->root.u.def.value;
6851 if (ELIMINATE_COPY_RELOCS || info->nocopyreloc)
6852 h->non_got_ref = h->u.weakdef->non_got_ref;
6856 /* If we are creating a shared library, we must presume that the
6857 only references to the symbol are via the global offset table.
6858 For such cases we need not do anything here; the relocations will
6859 be handled correctly by relocate_section. */
6860 if (bfd_link_pic (info))
6863 /* If there are no references to this symbol that do not use the
6864 GOT, we don't need to generate a copy reloc. */
6865 if (!h->non_got_ref)
6868 /* If -z nocopyreloc was given, we won't generate them either. */
6869 if (info->nocopyreloc)
6875 /* We must allocate the symbol in our .dynbss section, which will
6876 become part of the .bss section of the executable. There will be
6877 an entry for this symbol in the .dynsym section. The dynamic
6878 object will contain position independent code, so all references
6879 from the dynamic object to this symbol will go through the global
6880 offset table. The dynamic linker will use the .dynsym entry to
6881 determine the address it must put in the global offset table, so
6882 both the dynamic object and the regular object will refer to the
6883 same memory location for the variable. */
6885 htab = elf_aarch64_hash_table (info);
6887 /* We must generate a R_AARCH64_COPY reloc to tell the dynamic linker
6888 to copy the initial value out of the dynamic object and into the
6889 runtime process image. */
6890 if ((h->root.u.def.section->flags & SEC_ALLOC) != 0 && h->size != 0)
6892 htab->srelbss->size += RELOC_SIZE (htab);
6898 return _bfd_elf_adjust_dynamic_copy (info, h, s);
6903 elfNN_aarch64_allocate_local_symbols (bfd *abfd, unsigned number)
6905 struct elf_aarch64_local_symbol *locals;
6906 locals = elf_aarch64_locals (abfd);
6909 locals = (struct elf_aarch64_local_symbol *)
6910 bfd_zalloc (abfd, number * sizeof (struct elf_aarch64_local_symbol));
6913 elf_aarch64_locals (abfd) = locals;
6918 /* Create the .got section to hold the global offset table. */
6921 aarch64_elf_create_got_section (bfd *abfd, struct bfd_link_info *info)
6923 const struct elf_backend_data *bed = get_elf_backend_data (abfd);
6926 struct elf_link_hash_entry *h;
6927 struct elf_link_hash_table *htab = elf_hash_table (info);
6929 /* This function may be called more than once. */
6930 s = bfd_get_linker_section (abfd, ".got");
6934 flags = bed->dynamic_sec_flags;
6936 s = bfd_make_section_anyway_with_flags (abfd,
6937 (bed->rela_plts_and_copies_p
6938 ? ".rela.got" : ".rel.got"),
6939 (bed->dynamic_sec_flags
6942 || ! bfd_set_section_alignment (abfd, s, bed->s->log_file_align))
6946 s = bfd_make_section_anyway_with_flags (abfd, ".got", flags);
6948 || !bfd_set_section_alignment (abfd, s, bed->s->log_file_align))
6951 htab->sgot->size += GOT_ENTRY_SIZE;
6953 if (bed->want_got_sym)
6955 /* Define the symbol _GLOBAL_OFFSET_TABLE_ at the start of the .got
6956 (or .got.plt) section. We don't do this in the linker script
6957 because we don't want to define the symbol if we are not creating
6958 a global offset table. */
6959 h = _bfd_elf_define_linkage_sym (abfd, info, s,
6960 "_GLOBAL_OFFSET_TABLE_");
6961 elf_hash_table (info)->hgot = h;
6966 if (bed->want_got_plt)
6968 s = bfd_make_section_anyway_with_flags (abfd, ".got.plt", flags);
6970 || !bfd_set_section_alignment (abfd, s,
6971 bed->s->log_file_align))
6976 /* The first bit of the global offset table is the header. */
6977 s->size += bed->got_header_size;
6982 /* Look through the relocs for a section during the first phase. */
6985 elfNN_aarch64_check_relocs (bfd *abfd, struct bfd_link_info *info,
6986 asection *sec, const Elf_Internal_Rela *relocs)
6988 Elf_Internal_Shdr *symtab_hdr;
6989 struct elf_link_hash_entry **sym_hashes;
6990 const Elf_Internal_Rela *rel;
6991 const Elf_Internal_Rela *rel_end;
6994 struct elf_aarch64_link_hash_table *htab;
6996 if (bfd_link_relocatable (info))
6999 BFD_ASSERT (is_aarch64_elf (abfd));
7001 htab = elf_aarch64_hash_table (info);
7004 symtab_hdr = &elf_symtab_hdr (abfd);
7005 sym_hashes = elf_sym_hashes (abfd);
7007 rel_end = relocs + sec->reloc_count;
7008 for (rel = relocs; rel < rel_end; rel++)
7010 struct elf_link_hash_entry *h;
7011 unsigned long r_symndx;
7012 unsigned int r_type;
7013 bfd_reloc_code_real_type bfd_r_type;
7014 Elf_Internal_Sym *isym;
7016 r_symndx = ELFNN_R_SYM (rel->r_info);
7017 r_type = ELFNN_R_TYPE (rel->r_info);
7019 if (r_symndx >= NUM_SHDR_ENTRIES (symtab_hdr))
7021 (*_bfd_error_handler) (_("%B: bad symbol index: %d"), abfd,
7026 if (r_symndx < symtab_hdr->sh_info)
7028 /* A local symbol. */
7029 isym = bfd_sym_from_r_symndx (&htab->sym_cache,
7034 /* Check relocation against local STT_GNU_IFUNC symbol. */
7035 if (ELF_ST_TYPE (isym->st_info) == STT_GNU_IFUNC)
7037 h = elfNN_aarch64_get_local_sym_hash (htab, abfd, rel,
7042 /* Fake a STT_GNU_IFUNC symbol. */
7043 h->type = STT_GNU_IFUNC;
7046 h->forced_local = 1;
7047 h->root.type = bfd_link_hash_defined;
7054 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
7055 while (h->root.type == bfd_link_hash_indirect
7056 || h->root.type == bfd_link_hash_warning)
7057 h = (struct elf_link_hash_entry *) h->root.u.i.link;
7059 /* PR15323, ref flags aren't set for references in the same
7061 h->root.non_ir_ref = 1;
7064 /* Could be done earlier, if h were already available. */
7065 bfd_r_type = aarch64_tls_transition (abfd, info, r_type, h, r_symndx);
7069 /* Create the ifunc sections for static executables. If we
7070 never see an indirect function symbol nor we are building
7071 a static executable, those sections will be empty and
7072 won't appear in output. */
7078 case BFD_RELOC_AARCH64_ADD_LO12:
7079 case BFD_RELOC_AARCH64_ADR_GOT_PAGE:
7080 case BFD_RELOC_AARCH64_ADR_HI21_PCREL:
7081 case BFD_RELOC_AARCH64_CALL26:
7082 case BFD_RELOC_AARCH64_GOT_LD_PREL19:
7083 case BFD_RELOC_AARCH64_JUMP26:
7084 case BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14:
7085 case BFD_RELOC_AARCH64_LD32_GOT_LO12_NC:
7086 case BFD_RELOC_AARCH64_LD64_GOTOFF_LO15:
7087 case BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15:
7088 case BFD_RELOC_AARCH64_LD64_GOT_LO12_NC:
7089 case BFD_RELOC_AARCH64_MOVW_GOTOFF_G0_NC:
7090 case BFD_RELOC_AARCH64_MOVW_GOTOFF_G1:
7091 case BFD_RELOC_AARCH64_NN:
7092 if (htab->root.dynobj == NULL)
7093 htab->root.dynobj = abfd;
7094 if (!_bfd_elf_create_ifunc_sections (htab->root.dynobj, info))
7099 /* It is referenced by a non-shared object. */
7101 h->root.non_ir_ref = 1;
7106 case BFD_RELOC_AARCH64_NN:
7108 /* We don't need to handle relocs into sections not going into
7109 the "real" output. */
7110 if ((sec->flags & SEC_ALLOC) == 0)
7115 if (!bfd_link_pic (info))
7118 h->plt.refcount += 1;
7119 h->pointer_equality_needed = 1;
7122 /* No need to do anything if we're not creating a shared
7124 if (! bfd_link_pic (info))
7128 struct elf_dyn_relocs *p;
7129 struct elf_dyn_relocs **head;
7131 /* We must copy these reloc types into the output file.
7132 Create a reloc section in dynobj and make room for
7136 if (htab->root.dynobj == NULL)
7137 htab->root.dynobj = abfd;
7139 sreloc = _bfd_elf_make_dynamic_reloc_section
7140 (sec, htab->root.dynobj, LOG_FILE_ALIGN, abfd, /*rela? */ TRUE);
7146 /* If this is a global symbol, we count the number of
7147 relocations we need for this symbol. */
7150 struct elf_aarch64_link_hash_entry *eh;
7151 eh = (struct elf_aarch64_link_hash_entry *) h;
7152 head = &eh->dyn_relocs;
7156 /* Track dynamic relocs needed for local syms too.
7157 We really need local syms available to do this
7163 isym = bfd_sym_from_r_symndx (&htab->sym_cache,
7168 s = bfd_section_from_elf_index (abfd, isym->st_shndx);
7172 /* Beware of type punned pointers vs strict aliasing
7174 vpp = &(elf_section_data (s)->local_dynrel);
7175 head = (struct elf_dyn_relocs **) vpp;
7179 if (p == NULL || p->sec != sec)
7181 bfd_size_type amt = sizeof *p;
7182 p = ((struct elf_dyn_relocs *)
7183 bfd_zalloc (htab->root.dynobj, amt));
7196 /* RR: We probably want to keep a consistency check that
7197 there are no dangling GOT_PAGE relocs. */
7198 case BFD_RELOC_AARCH64_ADR_GOT_PAGE:
7199 case BFD_RELOC_AARCH64_GOT_LD_PREL19:
7200 case BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14:
7201 case BFD_RELOC_AARCH64_LD32_GOT_LO12_NC:
7202 case BFD_RELOC_AARCH64_LD64_GOTOFF_LO15:
7203 case BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15:
7204 case BFD_RELOC_AARCH64_LD64_GOT_LO12_NC:
7205 case BFD_RELOC_AARCH64_MOVW_GOTOFF_G0_NC:
7206 case BFD_RELOC_AARCH64_MOVW_GOTOFF_G1:
7207 case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12_NC:
7208 case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21:
7209 case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21:
7210 case BFD_RELOC_AARCH64_TLSDESC_LD32_LO12_NC:
7211 case BFD_RELOC_AARCH64_TLSDESC_LD64_LO12_NC:
7212 case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19:
7213 case BFD_RELOC_AARCH64_TLSDESC_OFF_G0_NC:
7214 case BFD_RELOC_AARCH64_TLSDESC_OFF_G1:
7215 case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC:
7216 case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21:
7217 case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21:
7218 case BFD_RELOC_AARCH64_TLSGD_MOVW_G0_NC:
7219 case BFD_RELOC_AARCH64_TLSGD_MOVW_G1:
7220 case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21:
7221 case BFD_RELOC_AARCH64_TLSIE_LD32_GOTTPREL_LO12_NC:
7222 case BFD_RELOC_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC:
7223 case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19:
7224 case BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G0_NC:
7225 case BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G1:
7226 case BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC:
7227 case BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21:
7228 case BFD_RELOC_AARCH64_TLSLD_ADR_PREL21:
7229 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1:
7230 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1_NC:
7231 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G2:
7234 unsigned old_got_type;
7236 got_type = aarch64_reloc_got_type (bfd_r_type);
7240 h->got.refcount += 1;
7241 old_got_type = elf_aarch64_hash_entry (h)->got_type;
7245 struct elf_aarch64_local_symbol *locals;
7247 if (!elfNN_aarch64_allocate_local_symbols
7248 (abfd, symtab_hdr->sh_info))
7251 locals = elf_aarch64_locals (abfd);
7252 BFD_ASSERT (r_symndx < symtab_hdr->sh_info);
7253 locals[r_symndx].got_refcount += 1;
7254 old_got_type = locals[r_symndx].got_type;
7257 /* If a variable is accessed with both general dynamic TLS
7258 methods, two slots may be created. */
7259 if (GOT_TLS_GD_ANY_P (old_got_type) && GOT_TLS_GD_ANY_P (got_type))
7260 got_type |= old_got_type;
7262 /* We will already have issued an error message if there
7263 is a TLS/non-TLS mismatch, based on the symbol type.
7264 So just combine any TLS types needed. */
7265 if (old_got_type != GOT_UNKNOWN && old_got_type != GOT_NORMAL
7266 && got_type != GOT_NORMAL)
7267 got_type |= old_got_type;
7269 /* If the symbol is accessed by both IE and GD methods, we
7270 are able to relax. Turn off the GD flag, without
7271 messing up with any other kind of TLS types that may be
7273 if ((got_type & GOT_TLS_IE) && GOT_TLS_GD_ANY_P (got_type))
7274 got_type &= ~ (GOT_TLSDESC_GD | GOT_TLS_GD);
7276 if (old_got_type != got_type)
7279 elf_aarch64_hash_entry (h)->got_type = got_type;
7282 struct elf_aarch64_local_symbol *locals;
7283 locals = elf_aarch64_locals (abfd);
7284 BFD_ASSERT (r_symndx < symtab_hdr->sh_info);
7285 locals[r_symndx].got_type = got_type;
7289 if (htab->root.dynobj == NULL)
7290 htab->root.dynobj = abfd;
7291 if (! aarch64_elf_create_got_section (htab->root.dynobj, info))
7296 case BFD_RELOC_AARCH64_MOVW_G0_NC:
7297 case BFD_RELOC_AARCH64_MOVW_G1_NC:
7298 case BFD_RELOC_AARCH64_MOVW_G2_NC:
7299 case BFD_RELOC_AARCH64_MOVW_G3:
7300 if (bfd_link_pic (info))
7302 int howto_index = bfd_r_type - BFD_RELOC_AARCH64_RELOC_START;
7303 (*_bfd_error_handler)
7304 (_("%B: relocation %s against `%s' can not be used when making "
7305 "a shared object; recompile with -fPIC"),
7306 abfd, elfNN_aarch64_howto_table[howto_index].name,
7307 (h) ? h->root.root.string : "a local symbol");
7308 bfd_set_error (bfd_error_bad_value);
7312 case BFD_RELOC_AARCH64_ADR_HI21_NC_PCREL:
7313 case BFD_RELOC_AARCH64_ADR_HI21_PCREL:
7314 case BFD_RELOC_AARCH64_ADR_LO21_PCREL:
7315 if (h != NULL && bfd_link_executable (info))
7317 /* If this reloc is in a read-only section, we might
7318 need a copy reloc. We can't check reliably at this
7319 stage whether the section is read-only, as input
7320 sections have not yet been mapped to output sections.
7321 Tentatively set the flag for now, and correct in
7322 adjust_dynamic_symbol. */
7324 h->plt.refcount += 1;
7325 h->pointer_equality_needed = 1;
7327 /* FIXME:: RR need to handle these in shared libraries
7328 and essentially bomb out as these being non-PIC
7329 relocations in shared libraries. */
7332 case BFD_RELOC_AARCH64_CALL26:
7333 case BFD_RELOC_AARCH64_JUMP26:
7334 /* If this is a local symbol then we resolve it
7335 directly without creating a PLT entry. */
7340 if (h->plt.refcount <= 0)
7341 h->plt.refcount = 1;
7343 h->plt.refcount += 1;
7354 /* Treat mapping symbols as special target symbols. */
7357 elfNN_aarch64_is_target_special_symbol (bfd *abfd ATTRIBUTE_UNUSED,
7360 return bfd_is_aarch64_special_symbol_name (sym->name,
7361 BFD_AARCH64_SPECIAL_SYM_TYPE_ANY);
7364 /* This is a copy of elf_find_function () from elf.c except that
7365 AArch64 mapping symbols are ignored when looking for function names. */
7368 aarch64_elf_find_function (bfd *abfd ATTRIBUTE_UNUSED,
7372 const char **filename_ptr,
7373 const char **functionname_ptr)
7375 const char *filename = NULL;
7376 asymbol *func = NULL;
7377 bfd_vma low_func = 0;
7380 for (p = symbols; *p != NULL; p++)
7384 q = (elf_symbol_type *) * p;
7386 switch (ELF_ST_TYPE (q->internal_elf_sym.st_info))
7391 filename = bfd_asymbol_name (&q->symbol);
7395 /* Skip mapping symbols. */
7396 if ((q->symbol.flags & BSF_LOCAL)
7397 && (bfd_is_aarch64_special_symbol_name
7398 (q->symbol.name, BFD_AARCH64_SPECIAL_SYM_TYPE_ANY)))
7401 if (bfd_get_section (&q->symbol) == section
7402 && q->symbol.value >= low_func && q->symbol.value <= offset)
7404 func = (asymbol *) q;
7405 low_func = q->symbol.value;
7415 *filename_ptr = filename;
7416 if (functionname_ptr)
7417 *functionname_ptr = bfd_asymbol_name (func);
7423 /* Find the nearest line to a particular section and offset, for error
7424 reporting. This code is a duplicate of the code in elf.c, except
7425 that it uses aarch64_elf_find_function. */
7428 elfNN_aarch64_find_nearest_line (bfd *abfd,
7432 const char **filename_ptr,
7433 const char **functionname_ptr,
7434 unsigned int *line_ptr,
7435 unsigned int *discriminator_ptr)
7437 bfd_boolean found = FALSE;
7439 if (_bfd_dwarf2_find_nearest_line (abfd, symbols, NULL, section, offset,
7440 filename_ptr, functionname_ptr,
7441 line_ptr, discriminator_ptr,
7442 dwarf_debug_sections, 0,
7443 &elf_tdata (abfd)->dwarf2_find_line_info))
7445 if (!*functionname_ptr)
7446 aarch64_elf_find_function (abfd, symbols, section, offset,
7447 *filename_ptr ? NULL : filename_ptr,
7453 /* Skip _bfd_dwarf1_find_nearest_line since no known AArch64
7454 toolchain uses DWARF1. */
7456 if (!_bfd_stab_section_find_nearest_line (abfd, symbols, section, offset,
7457 &found, filename_ptr,
7458 functionname_ptr, line_ptr,
7459 &elf_tdata (abfd)->line_info))
7462 if (found && (*functionname_ptr || *line_ptr))
7465 if (symbols == NULL)
7468 if (!aarch64_elf_find_function (abfd, symbols, section, offset,
7469 filename_ptr, functionname_ptr))
7477 elfNN_aarch64_find_inliner_info (bfd *abfd,
7478 const char **filename_ptr,
7479 const char **functionname_ptr,
7480 unsigned int *line_ptr)
7483 found = _bfd_dwarf2_find_inliner_info
7484 (abfd, filename_ptr,
7485 functionname_ptr, line_ptr, &elf_tdata (abfd)->dwarf2_find_line_info);
7491 elfNN_aarch64_post_process_headers (bfd *abfd,
7492 struct bfd_link_info *link_info)
7494 Elf_Internal_Ehdr *i_ehdrp; /* ELF file header, internal form. */
7496 i_ehdrp = elf_elfheader (abfd);
7497 i_ehdrp->e_ident[EI_ABIVERSION] = AARCH64_ELF_ABI_VERSION;
7499 _bfd_elf_post_process_headers (abfd, link_info);
7502 static enum elf_reloc_type_class
7503 elfNN_aarch64_reloc_type_class (const struct bfd_link_info *info ATTRIBUTE_UNUSED,
7504 const asection *rel_sec ATTRIBUTE_UNUSED,
7505 const Elf_Internal_Rela *rela)
7507 switch ((int) ELFNN_R_TYPE (rela->r_info))
7509 case AARCH64_R (RELATIVE):
7510 return reloc_class_relative;
7511 case AARCH64_R (JUMP_SLOT):
7512 return reloc_class_plt;
7513 case AARCH64_R (COPY):
7514 return reloc_class_copy;
7516 return reloc_class_normal;
7520 /* Handle an AArch64 specific section when reading an object file. This is
7521 called when bfd_section_from_shdr finds a section with an unknown
7525 elfNN_aarch64_section_from_shdr (bfd *abfd,
7526 Elf_Internal_Shdr *hdr,
7527 const char *name, int shindex)
7529 /* There ought to be a place to keep ELF backend specific flags, but
7530 at the moment there isn't one. We just keep track of the
7531 sections by their name, instead. Fortunately, the ABI gives
7532 names for all the AArch64 specific sections, so we will probably get
7534 switch (hdr->sh_type)
7536 case SHT_AARCH64_ATTRIBUTES:
7543 if (!_bfd_elf_make_section_from_shdr (abfd, hdr, name, shindex))
7549 /* A structure used to record a list of sections, independently
7550 of the next and prev fields in the asection structure. */
7551 typedef struct section_list
7554 struct section_list *next;
7555 struct section_list *prev;
7559 /* Unfortunately we need to keep a list of sections for which
7560 an _aarch64_elf_section_data structure has been allocated. This
7561 is because it is possible for functions like elfNN_aarch64_write_section
7562 to be called on a section which has had an elf_data_structure
7563 allocated for it (and so the used_by_bfd field is valid) but
7564 for which the AArch64 extended version of this structure - the
7565 _aarch64_elf_section_data structure - has not been allocated. */
7566 static section_list *sections_with_aarch64_elf_section_data = NULL;
7569 record_section_with_aarch64_elf_section_data (asection *sec)
7571 struct section_list *entry;
7573 entry = bfd_malloc (sizeof (*entry));
7577 entry->next = sections_with_aarch64_elf_section_data;
7579 if (entry->next != NULL)
7580 entry->next->prev = entry;
7581 sections_with_aarch64_elf_section_data = entry;
7584 static struct section_list *
7585 find_aarch64_elf_section_entry (asection *sec)
7587 struct section_list *entry;
7588 static struct section_list *last_entry = NULL;
7590 /* This is a short cut for the typical case where the sections are added
7591 to the sections_with_aarch64_elf_section_data list in forward order and
7592 then looked up here in backwards order. This makes a real difference
7593 to the ld-srec/sec64k.exp linker test. */
7594 entry = sections_with_aarch64_elf_section_data;
7595 if (last_entry != NULL)
7597 if (last_entry->sec == sec)
7599 else if (last_entry->next != NULL && last_entry->next->sec == sec)
7600 entry = last_entry->next;
7603 for (; entry; entry = entry->next)
7604 if (entry->sec == sec)
7608 /* Record the entry prior to this one - it is the entry we are
7609 most likely to want to locate next time. Also this way if we
7610 have been called from
7611 unrecord_section_with_aarch64_elf_section_data () we will not
7612 be caching a pointer that is about to be freed. */
7613 last_entry = entry->prev;
7619 unrecord_section_with_aarch64_elf_section_data (asection *sec)
7621 struct section_list *entry;
7623 entry = find_aarch64_elf_section_entry (sec);
7627 if (entry->prev != NULL)
7628 entry->prev->next = entry->next;
7629 if (entry->next != NULL)
7630 entry->next->prev = entry->prev;
7631 if (entry == sections_with_aarch64_elf_section_data)
7632 sections_with_aarch64_elf_section_data = entry->next;
7641 struct bfd_link_info *info;
7644 int (*func) (void *, const char *, Elf_Internal_Sym *,
7645 asection *, struct elf_link_hash_entry *);
7646 } output_arch_syminfo;
7648 enum map_symbol_type
7655 /* Output a single mapping symbol. */
7658 elfNN_aarch64_output_map_sym (output_arch_syminfo *osi,
7659 enum map_symbol_type type, bfd_vma offset)
7661 static const char *names[2] = { "$x", "$d" };
7662 Elf_Internal_Sym sym;
7664 sym.st_value = (osi->sec->output_section->vma
7665 + osi->sec->output_offset + offset);
7668 sym.st_info = ELF_ST_INFO (STB_LOCAL, STT_NOTYPE);
7669 sym.st_shndx = osi->sec_shndx;
7670 return osi->func (osi->finfo, names[type], &sym, osi->sec, NULL) == 1;
7673 /* Output a single local symbol for a generated stub. */
7676 elfNN_aarch64_output_stub_sym (output_arch_syminfo *osi, const char *name,
7677 bfd_vma offset, bfd_vma size)
7679 Elf_Internal_Sym sym;
7681 sym.st_value = (osi->sec->output_section->vma
7682 + osi->sec->output_offset + offset);
7685 sym.st_info = ELF_ST_INFO (STB_LOCAL, STT_FUNC);
7686 sym.st_shndx = osi->sec_shndx;
7687 return osi->func (osi->finfo, name, &sym, osi->sec, NULL) == 1;
7691 aarch64_map_one_stub (struct bfd_hash_entry *gen_entry, void *in_arg)
7693 struct elf_aarch64_stub_hash_entry *stub_entry;
7697 output_arch_syminfo *osi;
7699 /* Massage our args to the form they really have. */
7700 stub_entry = (struct elf_aarch64_stub_hash_entry *) gen_entry;
7701 osi = (output_arch_syminfo *) in_arg;
7703 stub_sec = stub_entry->stub_sec;
7705 /* Ensure this stub is attached to the current section being
7707 if (stub_sec != osi->sec)
7710 addr = (bfd_vma) stub_entry->stub_offset;
7712 stub_name = stub_entry->output_name;
7714 switch (stub_entry->stub_type)
7716 case aarch64_stub_adrp_branch:
7717 if (!elfNN_aarch64_output_stub_sym (osi, stub_name, addr,
7718 sizeof (aarch64_adrp_branch_stub)))
7720 if (!elfNN_aarch64_output_map_sym (osi, AARCH64_MAP_INSN, addr))
7723 case aarch64_stub_long_branch:
7724 if (!elfNN_aarch64_output_stub_sym
7725 (osi, stub_name, addr, sizeof (aarch64_long_branch_stub)))
7727 if (!elfNN_aarch64_output_map_sym (osi, AARCH64_MAP_INSN, addr))
7729 if (!elfNN_aarch64_output_map_sym (osi, AARCH64_MAP_DATA, addr + 16))
7732 case aarch64_stub_erratum_835769_veneer:
7733 if (!elfNN_aarch64_output_stub_sym (osi, stub_name, addr,
7734 sizeof (aarch64_erratum_835769_stub)))
7736 if (!elfNN_aarch64_output_map_sym (osi, AARCH64_MAP_INSN, addr))
7739 case aarch64_stub_erratum_843419_veneer:
7740 if (!elfNN_aarch64_output_stub_sym (osi, stub_name, addr,
7741 sizeof (aarch64_erratum_843419_stub)))
7743 if (!elfNN_aarch64_output_map_sym (osi, AARCH64_MAP_INSN, addr))
7754 /* Output mapping symbols for linker generated sections. */
7757 elfNN_aarch64_output_arch_local_syms (bfd *output_bfd,
7758 struct bfd_link_info *info,
7760 int (*func) (void *, const char *,
7763 struct elf_link_hash_entry
7766 output_arch_syminfo osi;
7767 struct elf_aarch64_link_hash_table *htab;
7769 htab = elf_aarch64_hash_table (info);
7775 /* Long calls stubs. */
7776 if (htab->stub_bfd && htab->stub_bfd->sections)
7780 for (stub_sec = htab->stub_bfd->sections;
7781 stub_sec != NULL; stub_sec = stub_sec->next)
7783 /* Ignore non-stub sections. */
7784 if (!strstr (stub_sec->name, STUB_SUFFIX))
7789 osi.sec_shndx = _bfd_elf_section_from_bfd_section
7790 (output_bfd, osi.sec->output_section);
7792 /* The first instruction in a stub is always a branch. */
7793 if (!elfNN_aarch64_output_map_sym (&osi, AARCH64_MAP_INSN, 0))
7796 bfd_hash_traverse (&htab->stub_hash_table, aarch64_map_one_stub,
7801 /* Finally, output mapping symbols for the PLT. */
7802 if (!htab->root.splt || htab->root.splt->size == 0)
7805 osi.sec_shndx = _bfd_elf_section_from_bfd_section
7806 (output_bfd, htab->root.splt->output_section);
7807 osi.sec = htab->root.splt;
7809 elfNN_aarch64_output_map_sym (&osi, AARCH64_MAP_INSN, 0);
7815 /* Allocate target specific section data. */
7818 elfNN_aarch64_new_section_hook (bfd *abfd, asection *sec)
7820 if (!sec->used_by_bfd)
7822 _aarch64_elf_section_data *sdata;
7823 bfd_size_type amt = sizeof (*sdata);
7825 sdata = bfd_zalloc (abfd, amt);
7828 sec->used_by_bfd = sdata;
7831 record_section_with_aarch64_elf_section_data (sec);
7833 return _bfd_elf_new_section_hook (abfd, sec);
7838 unrecord_section_via_map_over_sections (bfd *abfd ATTRIBUTE_UNUSED,
7840 void *ignore ATTRIBUTE_UNUSED)
7842 unrecord_section_with_aarch64_elf_section_data (sec);
7846 elfNN_aarch64_close_and_cleanup (bfd *abfd)
7849 bfd_map_over_sections (abfd,
7850 unrecord_section_via_map_over_sections, NULL);
7852 return _bfd_elf_close_and_cleanup (abfd);
7856 elfNN_aarch64_bfd_free_cached_info (bfd *abfd)
7859 bfd_map_over_sections (abfd,
7860 unrecord_section_via_map_over_sections, NULL);
7862 return _bfd_free_cached_info (abfd);
7865 /* Create dynamic sections. This is different from the ARM backend in that
7866 the got, plt, gotplt and their relocation sections are all created in the
7867 standard part of the bfd elf backend. */
7870 elfNN_aarch64_create_dynamic_sections (bfd *dynobj,
7871 struct bfd_link_info *info)
7873 struct elf_aarch64_link_hash_table *htab;
7875 /* We need to create .got section. */
7876 if (!aarch64_elf_create_got_section (dynobj, info))
7879 if (!_bfd_elf_create_dynamic_sections (dynobj, info))
7882 htab = elf_aarch64_hash_table (info);
7883 htab->sdynbss = bfd_get_linker_section (dynobj, ".dynbss");
7884 if (!bfd_link_pic (info))
7885 htab->srelbss = bfd_get_linker_section (dynobj, ".rela.bss");
7887 if (!htab->sdynbss || (!bfd_link_pic (info) && !htab->srelbss))
7894 /* Allocate space in .plt, .got and associated reloc sections for
7898 elfNN_aarch64_allocate_dynrelocs (struct elf_link_hash_entry *h, void *inf)
7900 struct bfd_link_info *info;
7901 struct elf_aarch64_link_hash_table *htab;
7902 struct elf_aarch64_link_hash_entry *eh;
7903 struct elf_dyn_relocs *p;
7905 /* An example of a bfd_link_hash_indirect symbol is versioned
7906 symbol. For example: __gxx_personality_v0(bfd_link_hash_indirect)
7907 -> __gxx_personality_v0(bfd_link_hash_defined)
7909 There is no need to process bfd_link_hash_indirect symbols here
7910 because we will also be presented with the concrete instance of
7911 the symbol and elfNN_aarch64_copy_indirect_symbol () will have been
7912 called to copy all relevant data from the generic to the concrete
7915 if (h->root.type == bfd_link_hash_indirect)
7918 if (h->root.type == bfd_link_hash_warning)
7919 h = (struct elf_link_hash_entry *) h->root.u.i.link;
7921 info = (struct bfd_link_info *) inf;
7922 htab = elf_aarch64_hash_table (info);
7924 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle it
7925 here if it is defined and referenced in a non-shared object. */
7926 if (h->type == STT_GNU_IFUNC
7929 else if (htab->root.dynamic_sections_created && h->plt.refcount > 0)
7931 /* Make sure this symbol is output as a dynamic symbol.
7932 Undefined weak syms won't yet be marked as dynamic. */
7933 if (h->dynindx == -1 && !h->forced_local)
7935 if (!bfd_elf_link_record_dynamic_symbol (info, h))
7939 if (bfd_link_pic (info) || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h))
7941 asection *s = htab->root.splt;
7943 /* If this is the first .plt entry, make room for the special
7946 s->size += htab->plt_header_size;
7948 h->plt.offset = s->size;
7950 /* If this symbol is not defined in a regular file, and we are
7951 not generating a shared library, then set the symbol to this
7952 location in the .plt. This is required to make function
7953 pointers compare as equal between the normal executable and
7954 the shared library. */
7955 if (!bfd_link_pic (info) && !h->def_regular)
7957 h->root.u.def.section = s;
7958 h->root.u.def.value = h->plt.offset;
7961 /* Make room for this entry. For now we only create the
7962 small model PLT entries. We later need to find a way
7963 of relaxing into these from the large model PLT entries. */
7964 s->size += PLT_SMALL_ENTRY_SIZE;
7966 /* We also need to make an entry in the .got.plt section, which
7967 will be placed in the .got section by the linker script. */
7968 htab->root.sgotplt->size += GOT_ENTRY_SIZE;
7970 /* We also need to make an entry in the .rela.plt section. */
7971 htab->root.srelplt->size += RELOC_SIZE (htab);
7973 /* We need to ensure that all GOT entries that serve the PLT
7974 are consecutive with the special GOT slots [0] [1] and
7975 [2]. Any addtional relocations, such as
7976 R_AARCH64_TLSDESC, must be placed after the PLT related
7977 entries. We abuse the reloc_count such that during
7978 sizing we adjust reloc_count to indicate the number of
7979 PLT related reserved entries. In subsequent phases when
7980 filling in the contents of the reloc entries, PLT related
7981 entries are placed by computing their PLT index (0
7982 .. reloc_count). While other none PLT relocs are placed
7983 at the slot indicated by reloc_count and reloc_count is
7986 htab->root.srelplt->reloc_count++;
7990 h->plt.offset = (bfd_vma) - 1;
7996 h->plt.offset = (bfd_vma) - 1;
8000 eh = (struct elf_aarch64_link_hash_entry *) h;
8001 eh->tlsdesc_got_jump_table_offset = (bfd_vma) - 1;
8003 if (h->got.refcount > 0)
8006 unsigned got_type = elf_aarch64_hash_entry (h)->got_type;
8008 h->got.offset = (bfd_vma) - 1;
8010 dyn = htab->root.dynamic_sections_created;
8012 /* Make sure this symbol is output as a dynamic symbol.
8013 Undefined weak syms won't yet be marked as dynamic. */
8014 if (dyn && h->dynindx == -1 && !h->forced_local)
8016 if (!bfd_elf_link_record_dynamic_symbol (info, h))
8020 if (got_type == GOT_UNKNOWN)
8023 else if (got_type == GOT_NORMAL)
8025 h->got.offset = htab->root.sgot->size;
8026 htab->root.sgot->size += GOT_ENTRY_SIZE;
8027 if ((ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
8028 || h->root.type != bfd_link_hash_undefweak)
8029 && (bfd_link_pic (info)
8030 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, 0, h)))
8032 htab->root.srelgot->size += RELOC_SIZE (htab);
8038 if (got_type & GOT_TLSDESC_GD)
8040 eh->tlsdesc_got_jump_table_offset =
8041 (htab->root.sgotplt->size
8042 - aarch64_compute_jump_table_size (htab));
8043 htab->root.sgotplt->size += GOT_ENTRY_SIZE * 2;
8044 h->got.offset = (bfd_vma) - 2;
8047 if (got_type & GOT_TLS_GD)
8049 h->got.offset = htab->root.sgot->size;
8050 htab->root.sgot->size += GOT_ENTRY_SIZE * 2;
8053 if (got_type & GOT_TLS_IE)
8055 h->got.offset = htab->root.sgot->size;
8056 htab->root.sgot->size += GOT_ENTRY_SIZE;
8059 indx = h && h->dynindx != -1 ? h->dynindx : 0;
8060 if ((ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
8061 || h->root.type != bfd_link_hash_undefweak)
8062 && (bfd_link_pic (info)
8064 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, 0, h)))
8066 if (got_type & GOT_TLSDESC_GD)
8068 htab->root.srelplt->size += RELOC_SIZE (htab);
8069 /* Note reloc_count not incremented here! We have
8070 already adjusted reloc_count for this relocation
8073 /* TLSDESC PLT is now needed, but not yet determined. */
8074 htab->tlsdesc_plt = (bfd_vma) - 1;
8077 if (got_type & GOT_TLS_GD)
8078 htab->root.srelgot->size += RELOC_SIZE (htab) * 2;
8080 if (got_type & GOT_TLS_IE)
8081 htab->root.srelgot->size += RELOC_SIZE (htab);
8087 h->got.offset = (bfd_vma) - 1;
8090 if (eh->dyn_relocs == NULL)
8093 /* In the shared -Bsymbolic case, discard space allocated for
8094 dynamic pc-relative relocs against symbols which turn out to be
8095 defined in regular objects. For the normal shared case, discard
8096 space for pc-relative relocs that have become local due to symbol
8097 visibility changes. */
8099 if (bfd_link_pic (info))
8101 /* Relocs that use pc_count are those that appear on a call
8102 insn, or certain REL relocs that can generated via assembly.
8103 We want calls to protected symbols to resolve directly to the
8104 function rather than going via the plt. If people want
8105 function pointer comparisons to work as expected then they
8106 should avoid writing weird assembly. */
8107 if (SYMBOL_CALLS_LOCAL (info, h))
8109 struct elf_dyn_relocs **pp;
8111 for (pp = &eh->dyn_relocs; (p = *pp) != NULL;)
8113 p->count -= p->pc_count;
8122 /* Also discard relocs on undefined weak syms with non-default
8124 if (eh->dyn_relocs != NULL && h->root.type == bfd_link_hash_undefweak)
8126 if (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT)
8127 eh->dyn_relocs = NULL;
8129 /* Make sure undefined weak symbols are output as a dynamic
8131 else if (h->dynindx == -1
8133 && !bfd_elf_link_record_dynamic_symbol (info, h))
8138 else if (ELIMINATE_COPY_RELOCS)
8140 /* For the non-shared case, discard space for relocs against
8141 symbols which turn out to need copy relocs or are not
8147 || (htab->root.dynamic_sections_created
8148 && (h->root.type == bfd_link_hash_undefweak
8149 || h->root.type == bfd_link_hash_undefined))))
8151 /* Make sure this symbol is output as a dynamic symbol.
8152 Undefined weak syms won't yet be marked as dynamic. */
8153 if (h->dynindx == -1
8155 && !bfd_elf_link_record_dynamic_symbol (info, h))
8158 /* If that succeeded, we know we'll be keeping all the
8160 if (h->dynindx != -1)
8164 eh->dyn_relocs = NULL;
8169 /* Finally, allocate space. */
8170 for (p = eh->dyn_relocs; p != NULL; p = p->next)
8174 sreloc = elf_section_data (p->sec)->sreloc;
8176 BFD_ASSERT (sreloc != NULL);
8178 sreloc->size += p->count * RELOC_SIZE (htab);
8184 /* Allocate space in .plt, .got and associated reloc sections for
8185 ifunc dynamic relocs. */
8188 elfNN_aarch64_allocate_ifunc_dynrelocs (struct elf_link_hash_entry *h,
8191 struct bfd_link_info *info;
8192 struct elf_aarch64_link_hash_table *htab;
8193 struct elf_aarch64_link_hash_entry *eh;
8195 /* An example of a bfd_link_hash_indirect symbol is versioned
8196 symbol. For example: __gxx_personality_v0(bfd_link_hash_indirect)
8197 -> __gxx_personality_v0(bfd_link_hash_defined)
8199 There is no need to process bfd_link_hash_indirect symbols here
8200 because we will also be presented with the concrete instance of
8201 the symbol and elfNN_aarch64_copy_indirect_symbol () will have been
8202 called to copy all relevant data from the generic to the concrete
8205 if (h->root.type == bfd_link_hash_indirect)
8208 if (h->root.type == bfd_link_hash_warning)
8209 h = (struct elf_link_hash_entry *) h->root.u.i.link;
8211 info = (struct bfd_link_info *) inf;
8212 htab = elf_aarch64_hash_table (info);
8214 eh = (struct elf_aarch64_link_hash_entry *) h;
8216 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle it
8217 here if it is defined and referenced in a non-shared object. */
8218 if (h->type == STT_GNU_IFUNC
8220 return _bfd_elf_allocate_ifunc_dyn_relocs (info, h,
8222 htab->plt_entry_size,
8223 htab->plt_header_size,
8228 /* Allocate space in .plt, .got and associated reloc sections for
8229 local dynamic relocs. */
8232 elfNN_aarch64_allocate_local_dynrelocs (void **slot, void *inf)
8234 struct elf_link_hash_entry *h
8235 = (struct elf_link_hash_entry *) *slot;
8237 if (h->type != STT_GNU_IFUNC
8241 || h->root.type != bfd_link_hash_defined)
8244 return elfNN_aarch64_allocate_dynrelocs (h, inf);
8247 /* Allocate space in .plt, .got and associated reloc sections for
8248 local ifunc dynamic relocs. */
8251 elfNN_aarch64_allocate_local_ifunc_dynrelocs (void **slot, void *inf)
8253 struct elf_link_hash_entry *h
8254 = (struct elf_link_hash_entry *) *slot;
8256 if (h->type != STT_GNU_IFUNC
8260 || h->root.type != bfd_link_hash_defined)
8263 return elfNN_aarch64_allocate_ifunc_dynrelocs (h, inf);
8266 /* Find any dynamic relocs that apply to read-only sections. */
8269 aarch64_readonly_dynrelocs (struct elf_link_hash_entry * h, void * inf)
8271 struct elf_aarch64_link_hash_entry * eh;
8272 struct elf_dyn_relocs * p;
8274 eh = (struct elf_aarch64_link_hash_entry *) h;
8275 for (p = eh->dyn_relocs; p != NULL; p = p->next)
8277 asection *s = p->sec;
8279 if (s != NULL && (s->flags & SEC_READONLY) != 0)
8281 struct bfd_link_info *info = (struct bfd_link_info *) inf;
8283 info->flags |= DF_TEXTREL;
8285 /* Not an error, just cut short the traversal. */
8292 /* This is the most important function of all . Innocuosly named
8295 elfNN_aarch64_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
8296 struct bfd_link_info *info)
8298 struct elf_aarch64_link_hash_table *htab;
8304 htab = elf_aarch64_hash_table ((info));
8305 dynobj = htab->root.dynobj;
8307 BFD_ASSERT (dynobj != NULL);
8309 if (htab->root.dynamic_sections_created)
8311 if (bfd_link_executable (info) && !info->nointerp)
8313 s = bfd_get_linker_section (dynobj, ".interp");
8316 s->size = sizeof ELF_DYNAMIC_INTERPRETER;
8317 s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
8321 /* Set up .got offsets for local syms, and space for local dynamic
8323 for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link.next)
8325 struct elf_aarch64_local_symbol *locals = NULL;
8326 Elf_Internal_Shdr *symtab_hdr;
8330 if (!is_aarch64_elf (ibfd))
8333 for (s = ibfd->sections; s != NULL; s = s->next)
8335 struct elf_dyn_relocs *p;
8337 for (p = (struct elf_dyn_relocs *)
8338 (elf_section_data (s)->local_dynrel); p != NULL; p = p->next)
8340 if (!bfd_is_abs_section (p->sec)
8341 && bfd_is_abs_section (p->sec->output_section))
8343 /* Input section has been discarded, either because
8344 it is a copy of a linkonce section or due to
8345 linker script /DISCARD/, so we'll be discarding
8348 else if (p->count != 0)
8350 srel = elf_section_data (p->sec)->sreloc;
8351 srel->size += p->count * RELOC_SIZE (htab);
8352 if ((p->sec->output_section->flags & SEC_READONLY) != 0)
8353 info->flags |= DF_TEXTREL;
8358 locals = elf_aarch64_locals (ibfd);
8362 symtab_hdr = &elf_symtab_hdr (ibfd);
8363 srel = htab->root.srelgot;
8364 for (i = 0; i < symtab_hdr->sh_info; i++)
8366 locals[i].got_offset = (bfd_vma) - 1;
8367 locals[i].tlsdesc_got_jump_table_offset = (bfd_vma) - 1;
8368 if (locals[i].got_refcount > 0)
8370 unsigned got_type = locals[i].got_type;
8371 if (got_type & GOT_TLSDESC_GD)
8373 locals[i].tlsdesc_got_jump_table_offset =
8374 (htab->root.sgotplt->size
8375 - aarch64_compute_jump_table_size (htab));
8376 htab->root.sgotplt->size += GOT_ENTRY_SIZE * 2;
8377 locals[i].got_offset = (bfd_vma) - 2;
8380 if (got_type & GOT_TLS_GD)
8382 locals[i].got_offset = htab->root.sgot->size;
8383 htab->root.sgot->size += GOT_ENTRY_SIZE * 2;
8386 if (got_type & GOT_TLS_IE
8387 || got_type & GOT_NORMAL)
8389 locals[i].got_offset = htab->root.sgot->size;
8390 htab->root.sgot->size += GOT_ENTRY_SIZE;
8393 if (got_type == GOT_UNKNOWN)
8397 if (bfd_link_pic (info))
8399 if (got_type & GOT_TLSDESC_GD)
8401 htab->root.srelplt->size += RELOC_SIZE (htab);
8402 /* Note RELOC_COUNT not incremented here! */
8403 htab->tlsdesc_plt = (bfd_vma) - 1;
8406 if (got_type & GOT_TLS_GD)
8407 htab->root.srelgot->size += RELOC_SIZE (htab) * 2;
8409 if (got_type & GOT_TLS_IE
8410 || got_type & GOT_NORMAL)
8411 htab->root.srelgot->size += RELOC_SIZE (htab);
8416 locals[i].got_refcount = (bfd_vma) - 1;
8422 /* Allocate global sym .plt and .got entries, and space for global
8423 sym dynamic relocs. */
8424 elf_link_hash_traverse (&htab->root, elfNN_aarch64_allocate_dynrelocs,
8427 /* Allocate global ifunc sym .plt and .got entries, and space for global
8428 ifunc sym dynamic relocs. */
8429 elf_link_hash_traverse (&htab->root, elfNN_aarch64_allocate_ifunc_dynrelocs,
8432 /* Allocate .plt and .got entries, and space for local symbols. */
8433 htab_traverse (htab->loc_hash_table,
8434 elfNN_aarch64_allocate_local_dynrelocs,
8437 /* Allocate .plt and .got entries, and space for local ifunc symbols. */
8438 htab_traverse (htab->loc_hash_table,
8439 elfNN_aarch64_allocate_local_ifunc_dynrelocs,
8442 /* For every jump slot reserved in the sgotplt, reloc_count is
8443 incremented. However, when we reserve space for TLS descriptors,
8444 it's not incremented, so in order to compute the space reserved
8445 for them, it suffices to multiply the reloc count by the jump
8448 if (htab->root.srelplt)
8449 htab->sgotplt_jump_table_size = aarch64_compute_jump_table_size (htab);
8451 if (htab->tlsdesc_plt)
8453 if (htab->root.splt->size == 0)
8454 htab->root.splt->size += PLT_ENTRY_SIZE;
8456 htab->tlsdesc_plt = htab->root.splt->size;
8457 htab->root.splt->size += PLT_TLSDESC_ENTRY_SIZE;
8459 /* If we're not using lazy TLS relocations, don't generate the
8460 GOT entry required. */
8461 if (!(info->flags & DF_BIND_NOW))
8463 htab->dt_tlsdesc_got = htab->root.sgot->size;
8464 htab->root.sgot->size += GOT_ENTRY_SIZE;
8468 /* Init mapping symbols information to use later to distingush between
8469 code and data while scanning for errata. */
8470 if (htab->fix_erratum_835769 || htab->fix_erratum_843419)
8471 for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link.next)
8473 if (!is_aarch64_elf (ibfd))
8475 bfd_elfNN_aarch64_init_maps (ibfd);
8478 /* We now have determined the sizes of the various dynamic sections.
8479 Allocate memory for them. */
8481 for (s = dynobj->sections; s != NULL; s = s->next)
8483 if ((s->flags & SEC_LINKER_CREATED) == 0)
8486 if (s == htab->root.splt
8487 || s == htab->root.sgot
8488 || s == htab->root.sgotplt
8489 || s == htab->root.iplt
8490 || s == htab->root.igotplt || s == htab->sdynbss)
8492 /* Strip this section if we don't need it; see the
8495 else if (CONST_STRNEQ (bfd_get_section_name (dynobj, s), ".rela"))
8497 if (s->size != 0 && s != htab->root.srelplt)
8500 /* We use the reloc_count field as a counter if we need
8501 to copy relocs into the output file. */
8502 if (s != htab->root.srelplt)
8507 /* It's not one of our sections, so don't allocate space. */
8513 /* If we don't need this section, strip it from the
8514 output file. This is mostly to handle .rela.bss and
8515 .rela.plt. We must create both sections in
8516 create_dynamic_sections, because they must be created
8517 before the linker maps input sections to output
8518 sections. The linker does that before
8519 adjust_dynamic_symbol is called, and it is that
8520 function which decides whether anything needs to go
8521 into these sections. */
8523 s->flags |= SEC_EXCLUDE;
8527 if ((s->flags & SEC_HAS_CONTENTS) == 0)
8530 /* Allocate memory for the section contents. We use bfd_zalloc
8531 here in case unused entries are not reclaimed before the
8532 section's contents are written out. This should not happen,
8533 but this way if it does, we get a R_AARCH64_NONE reloc instead
8535 s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->size);
8536 if (s->contents == NULL)
8540 if (htab->root.dynamic_sections_created)
8542 /* Add some entries to the .dynamic section. We fill in the
8543 values later, in elfNN_aarch64_finish_dynamic_sections, but we
8544 must add the entries now so that we get the correct size for
8545 the .dynamic section. The DT_DEBUG entry is filled in by the
8546 dynamic linker and used by the debugger. */
8547 #define add_dynamic_entry(TAG, VAL) \
8548 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
8550 if (bfd_link_executable (info))
8552 if (!add_dynamic_entry (DT_DEBUG, 0))
8556 if (htab->root.splt->size != 0)
8558 if (!add_dynamic_entry (DT_PLTGOT, 0)
8559 || !add_dynamic_entry (DT_PLTRELSZ, 0)
8560 || !add_dynamic_entry (DT_PLTREL, DT_RELA)
8561 || !add_dynamic_entry (DT_JMPREL, 0))
8564 if (htab->tlsdesc_plt
8565 && (!add_dynamic_entry (DT_TLSDESC_PLT, 0)
8566 || !add_dynamic_entry (DT_TLSDESC_GOT, 0)))
8572 if (!add_dynamic_entry (DT_RELA, 0)
8573 || !add_dynamic_entry (DT_RELASZ, 0)
8574 || !add_dynamic_entry (DT_RELAENT, RELOC_SIZE (htab)))
8577 /* If any dynamic relocs apply to a read-only section,
8578 then we need a DT_TEXTREL entry. */
8579 if ((info->flags & DF_TEXTREL) == 0)
8580 elf_link_hash_traverse (& htab->root, aarch64_readonly_dynrelocs,
8583 if ((info->flags & DF_TEXTREL) != 0)
8585 if (!add_dynamic_entry (DT_TEXTREL, 0))
8590 #undef add_dynamic_entry
8596 elf_aarch64_update_plt_entry (bfd *output_bfd,
8597 bfd_reloc_code_real_type r_type,
8598 bfd_byte *plt_entry, bfd_vma value)
8600 reloc_howto_type *howto = elfNN_aarch64_howto_from_bfd_reloc (r_type);
8602 _bfd_aarch64_elf_put_addend (output_bfd, plt_entry, r_type, howto, value);
8606 elfNN_aarch64_create_small_pltn_entry (struct elf_link_hash_entry *h,
8607 struct elf_aarch64_link_hash_table
8608 *htab, bfd *output_bfd,
8609 struct bfd_link_info *info)
8611 bfd_byte *plt_entry;
8614 bfd_vma gotplt_entry_address;
8615 bfd_vma plt_entry_address;
8616 Elf_Internal_Rela rela;
8618 asection *plt, *gotplt, *relplt;
8620 /* When building a static executable, use .iplt, .igot.plt and
8621 .rela.iplt sections for STT_GNU_IFUNC symbols. */
8622 if (htab->root.splt != NULL)
8624 plt = htab->root.splt;
8625 gotplt = htab->root.sgotplt;
8626 relplt = htab->root.srelplt;
8630 plt = htab->root.iplt;
8631 gotplt = htab->root.igotplt;
8632 relplt = htab->root.irelplt;
8635 /* Get the index in the procedure linkage table which
8636 corresponds to this symbol. This is the index of this symbol
8637 in all the symbols for which we are making plt entries. The
8638 first entry in the procedure linkage table is reserved.
8640 Get the offset into the .got table of the entry that
8641 corresponds to this function. Each .got entry is GOT_ENTRY_SIZE
8642 bytes. The first three are reserved for the dynamic linker.
8644 For static executables, we don't reserve anything. */
8646 if (plt == htab->root.splt)
8648 plt_index = (h->plt.offset - htab->plt_header_size) / htab->plt_entry_size;
8649 got_offset = (plt_index + 3) * GOT_ENTRY_SIZE;
8653 plt_index = h->plt.offset / htab->plt_entry_size;
8654 got_offset = plt_index * GOT_ENTRY_SIZE;
8657 plt_entry = plt->contents + h->plt.offset;
8658 plt_entry_address = plt->output_section->vma
8659 + plt->output_offset + h->plt.offset;
8660 gotplt_entry_address = gotplt->output_section->vma +
8661 gotplt->output_offset + got_offset;
8663 /* Copy in the boiler-plate for the PLTn entry. */
8664 memcpy (plt_entry, elfNN_aarch64_small_plt_entry, PLT_SMALL_ENTRY_SIZE);
8666 /* Fill in the top 21 bits for this: ADRP x16, PLT_GOT + n * 8.
8667 ADRP: ((PG(S+A)-PG(P)) >> 12) & 0x1fffff */
8668 elf_aarch64_update_plt_entry (output_bfd, BFD_RELOC_AARCH64_ADR_HI21_PCREL,
8670 PG (gotplt_entry_address) -
8671 PG (plt_entry_address));
8673 /* Fill in the lo12 bits for the load from the pltgot. */
8674 elf_aarch64_update_plt_entry (output_bfd, BFD_RELOC_AARCH64_LDSTNN_LO12,
8676 PG_OFFSET (gotplt_entry_address));
8678 /* Fill in the lo12 bits for the add from the pltgot entry. */
8679 elf_aarch64_update_plt_entry (output_bfd, BFD_RELOC_AARCH64_ADD_LO12,
8681 PG_OFFSET (gotplt_entry_address));
8683 /* All the GOTPLT Entries are essentially initialized to PLT0. */
8684 bfd_put_NN (output_bfd,
8685 plt->output_section->vma + plt->output_offset,
8686 gotplt->contents + got_offset);
8688 rela.r_offset = gotplt_entry_address;
8690 if (h->dynindx == -1
8691 || ((bfd_link_executable (info)
8692 || ELF_ST_VISIBILITY (h->other) != STV_DEFAULT)
8694 && h->type == STT_GNU_IFUNC))
8696 /* If an STT_GNU_IFUNC symbol is locally defined, generate
8697 R_AARCH64_IRELATIVE instead of R_AARCH64_JUMP_SLOT. */
8698 rela.r_info = ELFNN_R_INFO (0, AARCH64_R (IRELATIVE));
8699 rela.r_addend = (h->root.u.def.value
8700 + h->root.u.def.section->output_section->vma
8701 + h->root.u.def.section->output_offset);
8705 /* Fill in the entry in the .rela.plt section. */
8706 rela.r_info = ELFNN_R_INFO (h->dynindx, AARCH64_R (JUMP_SLOT));
8710 /* Compute the relocation entry to used based on PLT index and do
8711 not adjust reloc_count. The reloc_count has already been adjusted
8712 to account for this entry. */
8713 loc = relplt->contents + plt_index * RELOC_SIZE (htab);
8714 bfd_elfNN_swap_reloca_out (output_bfd, &rela, loc);
8717 /* Size sections even though they're not dynamic. We use it to setup
8718 _TLS_MODULE_BASE_, if needed. */
8721 elfNN_aarch64_always_size_sections (bfd *output_bfd,
8722 struct bfd_link_info *info)
8726 if (bfd_link_relocatable (info))
8729 tls_sec = elf_hash_table (info)->tls_sec;
8733 struct elf_link_hash_entry *tlsbase;
8735 tlsbase = elf_link_hash_lookup (elf_hash_table (info),
8736 "_TLS_MODULE_BASE_", TRUE, TRUE, FALSE);
8740 struct bfd_link_hash_entry *h = NULL;
8741 const struct elf_backend_data *bed =
8742 get_elf_backend_data (output_bfd);
8744 if (!(_bfd_generic_link_add_one_symbol
8745 (info, output_bfd, "_TLS_MODULE_BASE_", BSF_LOCAL,
8746 tls_sec, 0, NULL, FALSE, bed->collect, &h)))
8749 tlsbase->type = STT_TLS;
8750 tlsbase = (struct elf_link_hash_entry *) h;
8751 tlsbase->def_regular = 1;
8752 tlsbase->other = STV_HIDDEN;
8753 (*bed->elf_backend_hide_symbol) (info, tlsbase, TRUE);
8760 /* Finish up dynamic symbol handling. We set the contents of various
8761 dynamic sections here. */
8763 elfNN_aarch64_finish_dynamic_symbol (bfd *output_bfd,
8764 struct bfd_link_info *info,
8765 struct elf_link_hash_entry *h,
8766 Elf_Internal_Sym *sym)
8768 struct elf_aarch64_link_hash_table *htab;
8769 htab = elf_aarch64_hash_table (info);
8771 if (h->plt.offset != (bfd_vma) - 1)
8773 asection *plt, *gotplt, *relplt;
8775 /* This symbol has an entry in the procedure linkage table. Set
8778 /* When building a static executable, use .iplt, .igot.plt and
8779 .rela.iplt sections for STT_GNU_IFUNC symbols. */
8780 if (htab->root.splt != NULL)
8782 plt = htab->root.splt;
8783 gotplt = htab->root.sgotplt;
8784 relplt = htab->root.srelplt;
8788 plt = htab->root.iplt;
8789 gotplt = htab->root.igotplt;
8790 relplt = htab->root.irelplt;
8793 /* This symbol has an entry in the procedure linkage table. Set
8795 if ((h->dynindx == -1
8796 && !((h->forced_local || bfd_link_executable (info))
8798 && h->type == STT_GNU_IFUNC))
8804 elfNN_aarch64_create_small_pltn_entry (h, htab, output_bfd, info);
8805 if (!h->def_regular)
8807 /* Mark the symbol as undefined, rather than as defined in
8808 the .plt section. */
8809 sym->st_shndx = SHN_UNDEF;
8810 /* If the symbol is weak we need to clear the value.
8811 Otherwise, the PLT entry would provide a definition for
8812 the symbol even if the symbol wasn't defined anywhere,
8813 and so the symbol would never be NULL. Leave the value if
8814 there were any relocations where pointer equality matters
8815 (this is a clue for the dynamic linker, to make function
8816 pointer comparisons work between an application and shared
8818 if (!h->ref_regular_nonweak || !h->pointer_equality_needed)
8823 if (h->got.offset != (bfd_vma) - 1
8824 && elf_aarch64_hash_entry (h)->got_type == GOT_NORMAL)
8826 Elf_Internal_Rela rela;
8829 /* This symbol has an entry in the global offset table. Set it
8831 if (htab->root.sgot == NULL || htab->root.srelgot == NULL)
8834 rela.r_offset = (htab->root.sgot->output_section->vma
8835 + htab->root.sgot->output_offset
8836 + (h->got.offset & ~(bfd_vma) 1));
8839 && h->type == STT_GNU_IFUNC)
8841 if (bfd_link_pic (info))
8843 /* Generate R_AARCH64_GLOB_DAT. */
8850 if (!h->pointer_equality_needed)
8853 /* For non-shared object, we can't use .got.plt, which
8854 contains the real function address if we need pointer
8855 equality. We load the GOT entry with the PLT entry. */
8856 plt = htab->root.splt ? htab->root.splt : htab->root.iplt;
8857 bfd_put_NN (output_bfd, (plt->output_section->vma
8858 + plt->output_offset
8860 htab->root.sgot->contents
8861 + (h->got.offset & ~(bfd_vma) 1));
8865 else if (bfd_link_pic (info) && SYMBOL_REFERENCES_LOCAL (info, h))
8867 if (!h->def_regular)
8870 BFD_ASSERT ((h->got.offset & 1) != 0);
8871 rela.r_info = ELFNN_R_INFO (0, AARCH64_R (RELATIVE));
8872 rela.r_addend = (h->root.u.def.value
8873 + h->root.u.def.section->output_section->vma
8874 + h->root.u.def.section->output_offset);
8879 BFD_ASSERT ((h->got.offset & 1) == 0);
8880 bfd_put_NN (output_bfd, (bfd_vma) 0,
8881 htab->root.sgot->contents + h->got.offset);
8882 rela.r_info = ELFNN_R_INFO (h->dynindx, AARCH64_R (GLOB_DAT));
8886 loc = htab->root.srelgot->contents;
8887 loc += htab->root.srelgot->reloc_count++ * RELOC_SIZE (htab);
8888 bfd_elfNN_swap_reloca_out (output_bfd, &rela, loc);
8893 Elf_Internal_Rela rela;
8896 /* This symbol needs a copy reloc. Set it up. */
8898 if (h->dynindx == -1
8899 || (h->root.type != bfd_link_hash_defined
8900 && h->root.type != bfd_link_hash_defweak)
8901 || htab->srelbss == NULL)
8904 rela.r_offset = (h->root.u.def.value
8905 + h->root.u.def.section->output_section->vma
8906 + h->root.u.def.section->output_offset);
8907 rela.r_info = ELFNN_R_INFO (h->dynindx, AARCH64_R (COPY));
8909 loc = htab->srelbss->contents;
8910 loc += htab->srelbss->reloc_count++ * RELOC_SIZE (htab);
8911 bfd_elfNN_swap_reloca_out (output_bfd, &rela, loc);
8914 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. SYM may
8915 be NULL for local symbols. */
8917 && (h == elf_hash_table (info)->hdynamic
8918 || h == elf_hash_table (info)->hgot))
8919 sym->st_shndx = SHN_ABS;
8924 /* Finish up local dynamic symbol handling. We set the contents of
8925 various dynamic sections here. */
8928 elfNN_aarch64_finish_local_dynamic_symbol (void **slot, void *inf)
8930 struct elf_link_hash_entry *h
8931 = (struct elf_link_hash_entry *) *slot;
8932 struct bfd_link_info *info
8933 = (struct bfd_link_info *) inf;
8935 return elfNN_aarch64_finish_dynamic_symbol (info->output_bfd,
8940 elfNN_aarch64_init_small_plt0_entry (bfd *output_bfd ATTRIBUTE_UNUSED,
8941 struct elf_aarch64_link_hash_table
8944 /* Fill in PLT0. Fixme:RR Note this doesn't distinguish between
8945 small and large plts and at the minute just generates
8948 /* PLT0 of the small PLT looks like this in ELF64 -
8949 stp x16, x30, [sp, #-16]! // Save the reloc and lr on stack.
8950 adrp x16, PLT_GOT + 16 // Get the page base of the GOTPLT
8951 ldr x17, [x16, #:lo12:PLT_GOT+16] // Load the address of the
8953 add x16, x16, #:lo12:PLT_GOT+16 // Load the lo12 bits of the
8954 // GOTPLT entry for this.
8956 PLT0 will be slightly different in ELF32 due to different got entry
8959 bfd_vma plt_got_2nd_ent; /* Address of GOT[2]. */
8963 memcpy (htab->root.splt->contents, elfNN_aarch64_small_plt0_entry,
8965 elf_section_data (htab->root.splt->output_section)->this_hdr.sh_entsize =
8968 plt_got_2nd_ent = (htab->root.sgotplt->output_section->vma
8969 + htab->root.sgotplt->output_offset
8970 + GOT_ENTRY_SIZE * 2);
8972 plt_base = htab->root.splt->output_section->vma +
8973 htab->root.splt->output_offset;
8975 /* Fill in the top 21 bits for this: ADRP x16, PLT_GOT + n * 8.
8976 ADRP: ((PG(S+A)-PG(P)) >> 12) & 0x1fffff */
8977 elf_aarch64_update_plt_entry (output_bfd, BFD_RELOC_AARCH64_ADR_HI21_PCREL,
8978 htab->root.splt->contents + 4,
8979 PG (plt_got_2nd_ent) - PG (plt_base + 4));
8981 elf_aarch64_update_plt_entry (output_bfd, BFD_RELOC_AARCH64_LDSTNN_LO12,
8982 htab->root.splt->contents + 8,
8983 PG_OFFSET (plt_got_2nd_ent));
8985 elf_aarch64_update_plt_entry (output_bfd, BFD_RELOC_AARCH64_ADD_LO12,
8986 htab->root.splt->contents + 12,
8987 PG_OFFSET (plt_got_2nd_ent));
8991 elfNN_aarch64_finish_dynamic_sections (bfd *output_bfd,
8992 struct bfd_link_info *info)
8994 struct elf_aarch64_link_hash_table *htab;
8998 htab = elf_aarch64_hash_table (info);
8999 dynobj = htab->root.dynobj;
9000 sdyn = bfd_get_linker_section (dynobj, ".dynamic");
9002 if (htab->root.dynamic_sections_created)
9004 ElfNN_External_Dyn *dyncon, *dynconend;
9006 if (sdyn == NULL || htab->root.sgot == NULL)
9009 dyncon = (ElfNN_External_Dyn *) sdyn->contents;
9010 dynconend = (ElfNN_External_Dyn *) (sdyn->contents + sdyn->size);
9011 for (; dyncon < dynconend; dyncon++)
9013 Elf_Internal_Dyn dyn;
9016 bfd_elfNN_swap_dyn_in (dynobj, dyncon, &dyn);
9024 s = htab->root.sgotplt;
9025 dyn.d_un.d_ptr = s->output_section->vma + s->output_offset;
9029 dyn.d_un.d_ptr = htab->root.srelplt->output_section->vma;
9033 s = htab->root.srelplt;
9034 dyn.d_un.d_val = s->size;
9038 /* The procedure linkage table relocs (DT_JMPREL) should
9039 not be included in the overall relocs (DT_RELA).
9040 Therefore, we override the DT_RELASZ entry here to
9041 make it not include the JMPREL relocs. Since the
9042 linker script arranges for .rela.plt to follow all
9043 other relocation sections, we don't have to worry
9044 about changing the DT_RELA entry. */
9045 if (htab->root.srelplt != NULL)
9047 s = htab->root.srelplt;
9048 dyn.d_un.d_val -= s->size;
9052 case DT_TLSDESC_PLT:
9053 s = htab->root.splt;
9054 dyn.d_un.d_ptr = s->output_section->vma + s->output_offset
9055 + htab->tlsdesc_plt;
9058 case DT_TLSDESC_GOT:
9059 s = htab->root.sgot;
9060 dyn.d_un.d_ptr = s->output_section->vma + s->output_offset
9061 + htab->dt_tlsdesc_got;
9065 bfd_elfNN_swap_dyn_out (output_bfd, &dyn, dyncon);
9070 /* Fill in the special first entry in the procedure linkage table. */
9071 if (htab->root.splt && htab->root.splt->size > 0)
9073 elfNN_aarch64_init_small_plt0_entry (output_bfd, htab);
9075 elf_section_data (htab->root.splt->output_section)->
9076 this_hdr.sh_entsize = htab->plt_entry_size;
9079 if (htab->tlsdesc_plt)
9081 bfd_put_NN (output_bfd, (bfd_vma) 0,
9082 htab->root.sgot->contents + htab->dt_tlsdesc_got);
9084 memcpy (htab->root.splt->contents + htab->tlsdesc_plt,
9085 elfNN_aarch64_tlsdesc_small_plt_entry,
9086 sizeof (elfNN_aarch64_tlsdesc_small_plt_entry));
9089 bfd_vma adrp1_addr =
9090 htab->root.splt->output_section->vma
9091 + htab->root.splt->output_offset + htab->tlsdesc_plt + 4;
9093 bfd_vma adrp2_addr = adrp1_addr + 4;
9096 htab->root.sgot->output_section->vma
9097 + htab->root.sgot->output_offset;
9099 bfd_vma pltgot_addr =
9100 htab->root.sgotplt->output_section->vma
9101 + htab->root.sgotplt->output_offset;
9103 bfd_vma dt_tlsdesc_got = got_addr + htab->dt_tlsdesc_got;
9105 bfd_byte *plt_entry =
9106 htab->root.splt->contents + htab->tlsdesc_plt;
9108 /* adrp x2, DT_TLSDESC_GOT */
9109 elf_aarch64_update_plt_entry (output_bfd,
9110 BFD_RELOC_AARCH64_ADR_HI21_PCREL,
9112 (PG (dt_tlsdesc_got)
9113 - PG (adrp1_addr)));
9116 elf_aarch64_update_plt_entry (output_bfd,
9117 BFD_RELOC_AARCH64_ADR_HI21_PCREL,
9120 - PG (adrp2_addr)));
9122 /* ldr x2, [x2, #0] */
9123 elf_aarch64_update_plt_entry (output_bfd,
9124 BFD_RELOC_AARCH64_LDSTNN_LO12,
9126 PG_OFFSET (dt_tlsdesc_got));
9129 elf_aarch64_update_plt_entry (output_bfd,
9130 BFD_RELOC_AARCH64_ADD_LO12,
9132 PG_OFFSET (pltgot_addr));
9137 if (htab->root.sgotplt)
9139 if (bfd_is_abs_section (htab->root.sgotplt->output_section))
9141 (*_bfd_error_handler)
9142 (_("discarded output section: `%A'"), htab->root.sgotplt);
9146 /* Fill in the first three entries in the global offset table. */
9147 if (htab->root.sgotplt->size > 0)
9149 bfd_put_NN (output_bfd, (bfd_vma) 0, htab->root.sgotplt->contents);
9151 /* Write GOT[1] and GOT[2], needed for the dynamic linker. */
9152 bfd_put_NN (output_bfd,
9154 htab->root.sgotplt->contents + GOT_ENTRY_SIZE);
9155 bfd_put_NN (output_bfd,
9157 htab->root.sgotplt->contents + GOT_ENTRY_SIZE * 2);
9160 if (htab->root.sgot)
9162 if (htab->root.sgot->size > 0)
9165 sdyn ? sdyn->output_section->vma + sdyn->output_offset : 0;
9166 bfd_put_NN (output_bfd, addr, htab->root.sgot->contents);
9170 elf_section_data (htab->root.sgotplt->output_section)->
9171 this_hdr.sh_entsize = GOT_ENTRY_SIZE;
9174 if (htab->root.sgot && htab->root.sgot->size > 0)
9175 elf_section_data (htab->root.sgot->output_section)->this_hdr.sh_entsize
9178 /* Fill PLT and GOT entries for local STT_GNU_IFUNC symbols. */
9179 htab_traverse (htab->loc_hash_table,
9180 elfNN_aarch64_finish_local_dynamic_symbol,
9186 /* Return address for Ith PLT stub in section PLT, for relocation REL
9187 or (bfd_vma) -1 if it should not be included. */
9190 elfNN_aarch64_plt_sym_val (bfd_vma i, const asection *plt,
9191 const arelent *rel ATTRIBUTE_UNUSED)
9193 return plt->vma + PLT_ENTRY_SIZE + i * PLT_SMALL_ENTRY_SIZE;
9197 /* We use this so we can override certain functions
9198 (though currently we don't). */
9200 const struct elf_size_info elfNN_aarch64_size_info =
9202 sizeof (ElfNN_External_Ehdr),
9203 sizeof (ElfNN_External_Phdr),
9204 sizeof (ElfNN_External_Shdr),
9205 sizeof (ElfNN_External_Rel),
9206 sizeof (ElfNN_External_Rela),
9207 sizeof (ElfNN_External_Sym),
9208 sizeof (ElfNN_External_Dyn),
9209 sizeof (Elf_External_Note),
9210 4, /* Hash table entry size. */
9211 1, /* Internal relocs per external relocs. */
9212 ARCH_SIZE, /* Arch size. */
9213 LOG_FILE_ALIGN, /* Log_file_align. */
9214 ELFCLASSNN, EV_CURRENT,
9215 bfd_elfNN_write_out_phdrs,
9216 bfd_elfNN_write_shdrs_and_ehdr,
9217 bfd_elfNN_checksum_contents,
9218 bfd_elfNN_write_relocs,
9219 bfd_elfNN_swap_symbol_in,
9220 bfd_elfNN_swap_symbol_out,
9221 bfd_elfNN_slurp_reloc_table,
9222 bfd_elfNN_slurp_symbol_table,
9223 bfd_elfNN_swap_dyn_in,
9224 bfd_elfNN_swap_dyn_out,
9225 bfd_elfNN_swap_reloc_in,
9226 bfd_elfNN_swap_reloc_out,
9227 bfd_elfNN_swap_reloca_in,
9228 bfd_elfNN_swap_reloca_out
9231 #define ELF_ARCH bfd_arch_aarch64
9232 #define ELF_MACHINE_CODE EM_AARCH64
9233 #define ELF_MAXPAGESIZE 0x10000
9234 #define ELF_MINPAGESIZE 0x1000
9235 #define ELF_COMMONPAGESIZE 0x1000
9237 #define bfd_elfNN_close_and_cleanup \
9238 elfNN_aarch64_close_and_cleanup
9240 #define bfd_elfNN_bfd_free_cached_info \
9241 elfNN_aarch64_bfd_free_cached_info
9243 #define bfd_elfNN_bfd_is_target_special_symbol \
9244 elfNN_aarch64_is_target_special_symbol
9246 #define bfd_elfNN_bfd_link_hash_table_create \
9247 elfNN_aarch64_link_hash_table_create
9249 #define bfd_elfNN_bfd_merge_private_bfd_data \
9250 elfNN_aarch64_merge_private_bfd_data
9252 #define bfd_elfNN_bfd_print_private_bfd_data \
9253 elfNN_aarch64_print_private_bfd_data
9255 #define bfd_elfNN_bfd_reloc_type_lookup \
9256 elfNN_aarch64_reloc_type_lookup
9258 #define bfd_elfNN_bfd_reloc_name_lookup \
9259 elfNN_aarch64_reloc_name_lookup
9261 #define bfd_elfNN_bfd_set_private_flags \
9262 elfNN_aarch64_set_private_flags
9264 #define bfd_elfNN_find_inliner_info \
9265 elfNN_aarch64_find_inliner_info
9267 #define bfd_elfNN_find_nearest_line \
9268 elfNN_aarch64_find_nearest_line
9270 #define bfd_elfNN_mkobject \
9271 elfNN_aarch64_mkobject
9273 #define bfd_elfNN_new_section_hook \
9274 elfNN_aarch64_new_section_hook
9276 #define elf_backend_adjust_dynamic_symbol \
9277 elfNN_aarch64_adjust_dynamic_symbol
9279 #define elf_backend_always_size_sections \
9280 elfNN_aarch64_always_size_sections
9282 #define elf_backend_check_relocs \
9283 elfNN_aarch64_check_relocs
9285 #define elf_backend_copy_indirect_symbol \
9286 elfNN_aarch64_copy_indirect_symbol
9288 /* Create .dynbss, and .rela.bss sections in DYNOBJ, and set up shortcuts
9289 to them in our hash. */
9290 #define elf_backend_create_dynamic_sections \
9291 elfNN_aarch64_create_dynamic_sections
9293 #define elf_backend_init_index_section \
9294 _bfd_elf_init_2_index_sections
9296 #define elf_backend_finish_dynamic_sections \
9297 elfNN_aarch64_finish_dynamic_sections
9299 #define elf_backend_finish_dynamic_symbol \
9300 elfNN_aarch64_finish_dynamic_symbol
9302 #define elf_backend_gc_sweep_hook \
9303 elfNN_aarch64_gc_sweep_hook
9305 #define elf_backend_object_p \
9306 elfNN_aarch64_object_p
9308 #define elf_backend_output_arch_local_syms \
9309 elfNN_aarch64_output_arch_local_syms
9311 #define elf_backend_plt_sym_val \
9312 elfNN_aarch64_plt_sym_val
9314 #define elf_backend_post_process_headers \
9315 elfNN_aarch64_post_process_headers
9317 #define elf_backend_relocate_section \
9318 elfNN_aarch64_relocate_section
9320 #define elf_backend_reloc_type_class \
9321 elfNN_aarch64_reloc_type_class
9323 #define elf_backend_section_from_shdr \
9324 elfNN_aarch64_section_from_shdr
9326 #define elf_backend_size_dynamic_sections \
9327 elfNN_aarch64_size_dynamic_sections
9329 #define elf_backend_size_info \
9330 elfNN_aarch64_size_info
9332 #define elf_backend_write_section \
9333 elfNN_aarch64_write_section
9335 #define elf_backend_can_refcount 1
9336 #define elf_backend_can_gc_sections 1
9337 #define elf_backend_plt_readonly 1
9338 #define elf_backend_want_got_plt 1
9339 #define elf_backend_want_plt_sym 0
9340 #define elf_backend_may_use_rel_p 0
9341 #define elf_backend_may_use_rela_p 1
9342 #define elf_backend_default_use_rela_p 1
9343 #define elf_backend_rela_normal 1
9344 #define elf_backend_got_header_size (GOT_ENTRY_SIZE * 3)
9345 #define elf_backend_default_execstack 0
9346 #define elf_backend_extern_protected_data 1
9348 #undef elf_backend_obj_attrs_section
9349 #define elf_backend_obj_attrs_section ".ARM.attributes"
9351 #include "elfNN-target.h"
9353 /* CloudABI support. */
9355 #undef TARGET_LITTLE_SYM
9356 #define TARGET_LITTLE_SYM aarch64_elfNN_le_cloudabi_vec
9357 #undef TARGET_LITTLE_NAME
9358 #define TARGET_LITTLE_NAME "elfNN-littleaarch64-cloudabi"
9359 #undef TARGET_BIG_SYM
9360 #define TARGET_BIG_SYM aarch64_elfNN_be_cloudabi_vec
9361 #undef TARGET_BIG_NAME
9362 #define TARGET_BIG_NAME "elfNN-bigaarch64-cloudabi"
9365 #define ELF_OSABI ELFOSABI_CLOUDABI
9368 #define elfNN_bed elfNN_aarch64_cloudabi_bed
9370 #include "elfNN-target.h"