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 /* Don't apply link-time values for dynamic relocations. */
2293 int no_apply_dynamic_relocs;
2295 /* The number of bytes in the initial entry in the PLT. */
2296 bfd_size_type plt_header_size;
2298 /* The number of bytes in the subsequent PLT etries. */
2299 bfd_size_type plt_entry_size;
2301 /* Short-cuts to get to dynamic linker sections. */
2305 /* Small local sym cache. */
2306 struct sym_cache sym_cache;
2308 /* For convenience in allocate_dynrelocs. */
2311 /* The amount of space used by the reserved portion of the sgotplt
2312 section, plus whatever space is used by the jump slots. */
2313 bfd_vma sgotplt_jump_table_size;
2315 /* The stub hash table. */
2316 struct bfd_hash_table stub_hash_table;
2318 /* Linker stub bfd. */
2321 /* Linker call-backs. */
2322 asection *(*add_stub_section) (const char *, asection *);
2323 void (*layout_sections_again) (void);
2325 /* Array to keep track of which stub sections have been created, and
2326 information on stub grouping. */
2329 /* This is the section to which stubs in the group will be
2332 /* The stub section. */
2336 /* Assorted information used by elfNN_aarch64_size_stubs. */
2337 unsigned int bfd_count;
2338 unsigned int top_index;
2339 asection **input_list;
2341 /* The offset into splt of the PLT entry for the TLS descriptor
2342 resolver. Special values are 0, if not necessary (or not found
2343 to be necessary yet), and -1 if needed but not determined
2345 bfd_vma tlsdesc_plt;
2347 /* The GOT offset for the lazy trampoline. Communicated to the
2348 loader via DT_TLSDESC_GOT. The magic value (bfd_vma) -1
2349 indicates an offset is not allocated. */
2350 bfd_vma dt_tlsdesc_got;
2352 /* Used by local STT_GNU_IFUNC symbols. */
2353 htab_t loc_hash_table;
2354 void * loc_hash_memory;
2357 /* Create an entry in an AArch64 ELF linker hash table. */
2359 static struct bfd_hash_entry *
2360 elfNN_aarch64_link_hash_newfunc (struct bfd_hash_entry *entry,
2361 struct bfd_hash_table *table,
2364 struct elf_aarch64_link_hash_entry *ret =
2365 (struct elf_aarch64_link_hash_entry *) entry;
2367 /* Allocate the structure if it has not already been allocated by a
2370 ret = bfd_hash_allocate (table,
2371 sizeof (struct elf_aarch64_link_hash_entry));
2373 return (struct bfd_hash_entry *) ret;
2375 /* Call the allocation method of the superclass. */
2376 ret = ((struct elf_aarch64_link_hash_entry *)
2377 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry *) ret,
2381 ret->dyn_relocs = NULL;
2382 ret->got_type = GOT_UNKNOWN;
2383 ret->plt_got_offset = (bfd_vma) - 1;
2384 ret->stub_cache = NULL;
2385 ret->tlsdesc_got_jump_table_offset = (bfd_vma) - 1;
2388 return (struct bfd_hash_entry *) ret;
2391 /* Initialize an entry in the stub hash table. */
2393 static struct bfd_hash_entry *
2394 stub_hash_newfunc (struct bfd_hash_entry *entry,
2395 struct bfd_hash_table *table, const char *string)
2397 /* Allocate the structure if it has not already been allocated by a
2401 entry = bfd_hash_allocate (table,
2403 elf_aarch64_stub_hash_entry));
2408 /* Call the allocation method of the superclass. */
2409 entry = bfd_hash_newfunc (entry, table, string);
2412 struct elf_aarch64_stub_hash_entry *eh;
2414 /* Initialize the local fields. */
2415 eh = (struct elf_aarch64_stub_hash_entry *) entry;
2416 eh->adrp_offset = 0;
2417 eh->stub_sec = NULL;
2418 eh->stub_offset = 0;
2419 eh->target_value = 0;
2420 eh->target_section = NULL;
2421 eh->stub_type = aarch64_stub_none;
2429 /* Compute a hash of a local hash entry. We use elf_link_hash_entry
2430 for local symbol so that we can handle local STT_GNU_IFUNC symbols
2431 as global symbol. We reuse indx and dynstr_index for local symbol
2432 hash since they aren't used by global symbols in this backend. */
2435 elfNN_aarch64_local_htab_hash (const void *ptr)
2437 struct elf_link_hash_entry *h
2438 = (struct elf_link_hash_entry *) ptr;
2439 return ELF_LOCAL_SYMBOL_HASH (h->indx, h->dynstr_index);
2442 /* Compare local hash entries. */
2445 elfNN_aarch64_local_htab_eq (const void *ptr1, const void *ptr2)
2447 struct elf_link_hash_entry *h1
2448 = (struct elf_link_hash_entry *) ptr1;
2449 struct elf_link_hash_entry *h2
2450 = (struct elf_link_hash_entry *) ptr2;
2452 return h1->indx == h2->indx && h1->dynstr_index == h2->dynstr_index;
2455 /* Find and/or create a hash entry for local symbol. */
2457 static struct elf_link_hash_entry *
2458 elfNN_aarch64_get_local_sym_hash (struct elf_aarch64_link_hash_table *htab,
2459 bfd *abfd, const Elf_Internal_Rela *rel,
2462 struct elf_aarch64_link_hash_entry e, *ret;
2463 asection *sec = abfd->sections;
2464 hashval_t h = ELF_LOCAL_SYMBOL_HASH (sec->id,
2465 ELFNN_R_SYM (rel->r_info));
2468 e.root.indx = sec->id;
2469 e.root.dynstr_index = ELFNN_R_SYM (rel->r_info);
2470 slot = htab_find_slot_with_hash (htab->loc_hash_table, &e, h,
2471 create ? INSERT : NO_INSERT);
2478 ret = (struct elf_aarch64_link_hash_entry *) *slot;
2482 ret = (struct elf_aarch64_link_hash_entry *)
2483 objalloc_alloc ((struct objalloc *) htab->loc_hash_memory,
2484 sizeof (struct elf_aarch64_link_hash_entry));
2487 memset (ret, 0, sizeof (*ret));
2488 ret->root.indx = sec->id;
2489 ret->root.dynstr_index = ELFNN_R_SYM (rel->r_info);
2490 ret->root.dynindx = -1;
2496 /* Copy the extra info we tack onto an elf_link_hash_entry. */
2499 elfNN_aarch64_copy_indirect_symbol (struct bfd_link_info *info,
2500 struct elf_link_hash_entry *dir,
2501 struct elf_link_hash_entry *ind)
2503 struct elf_aarch64_link_hash_entry *edir, *eind;
2505 edir = (struct elf_aarch64_link_hash_entry *) dir;
2506 eind = (struct elf_aarch64_link_hash_entry *) ind;
2508 if (eind->dyn_relocs != NULL)
2510 if (edir->dyn_relocs != NULL)
2512 struct elf_dyn_relocs **pp;
2513 struct elf_dyn_relocs *p;
2515 /* Add reloc counts against the indirect sym to the direct sym
2516 list. Merge any entries against the same section. */
2517 for (pp = &eind->dyn_relocs; (p = *pp) != NULL;)
2519 struct elf_dyn_relocs *q;
2521 for (q = edir->dyn_relocs; q != NULL; q = q->next)
2522 if (q->sec == p->sec)
2524 q->pc_count += p->pc_count;
2525 q->count += p->count;
2532 *pp = edir->dyn_relocs;
2535 edir->dyn_relocs = eind->dyn_relocs;
2536 eind->dyn_relocs = NULL;
2539 if (ind->root.type == bfd_link_hash_indirect)
2541 /* Copy over PLT info. */
2542 if (dir->got.refcount <= 0)
2544 edir->got_type = eind->got_type;
2545 eind->got_type = GOT_UNKNOWN;
2549 _bfd_elf_link_hash_copy_indirect (info, dir, ind);
2552 /* Destroy an AArch64 elf linker hash table. */
2555 elfNN_aarch64_link_hash_table_free (bfd *obfd)
2557 struct elf_aarch64_link_hash_table *ret
2558 = (struct elf_aarch64_link_hash_table *) obfd->link.hash;
2560 if (ret->loc_hash_table)
2561 htab_delete (ret->loc_hash_table);
2562 if (ret->loc_hash_memory)
2563 objalloc_free ((struct objalloc *) ret->loc_hash_memory);
2565 bfd_hash_table_free (&ret->stub_hash_table);
2566 _bfd_elf_link_hash_table_free (obfd);
2569 /* Create an AArch64 elf linker hash table. */
2571 static struct bfd_link_hash_table *
2572 elfNN_aarch64_link_hash_table_create (bfd *abfd)
2574 struct elf_aarch64_link_hash_table *ret;
2575 bfd_size_type amt = sizeof (struct elf_aarch64_link_hash_table);
2577 ret = bfd_zmalloc (amt);
2581 if (!_bfd_elf_link_hash_table_init
2582 (&ret->root, abfd, elfNN_aarch64_link_hash_newfunc,
2583 sizeof (struct elf_aarch64_link_hash_entry), AARCH64_ELF_DATA))
2589 ret->plt_header_size = PLT_ENTRY_SIZE;
2590 ret->plt_entry_size = PLT_SMALL_ENTRY_SIZE;
2592 ret->dt_tlsdesc_got = (bfd_vma) - 1;
2594 if (!bfd_hash_table_init (&ret->stub_hash_table, stub_hash_newfunc,
2595 sizeof (struct elf_aarch64_stub_hash_entry)))
2597 _bfd_elf_link_hash_table_free (abfd);
2601 ret->loc_hash_table = htab_try_create (1024,
2602 elfNN_aarch64_local_htab_hash,
2603 elfNN_aarch64_local_htab_eq,
2605 ret->loc_hash_memory = objalloc_create ();
2606 if (!ret->loc_hash_table || !ret->loc_hash_memory)
2608 elfNN_aarch64_link_hash_table_free (abfd);
2611 ret->root.root.hash_table_free = elfNN_aarch64_link_hash_table_free;
2613 return &ret->root.root;
2617 aarch64_relocate (unsigned int r_type, bfd *input_bfd, asection *input_section,
2618 bfd_vma offset, bfd_vma value)
2620 reloc_howto_type *howto;
2623 howto = elfNN_aarch64_howto_from_type (r_type);
2624 place = (input_section->output_section->vma + input_section->output_offset
2627 r_type = elfNN_aarch64_bfd_reloc_from_type (r_type);
2628 value = _bfd_aarch64_elf_resolve_relocation (r_type, place, value, 0, FALSE);
2629 return _bfd_aarch64_elf_put_addend (input_bfd,
2630 input_section->contents + offset, r_type,
2634 static enum elf_aarch64_stub_type
2635 aarch64_select_branch_stub (bfd_vma value, bfd_vma place)
2637 if (aarch64_valid_for_adrp_p (value, place))
2638 return aarch64_stub_adrp_branch;
2639 return aarch64_stub_long_branch;
2642 /* Determine the type of stub needed, if any, for a call. */
2644 static enum elf_aarch64_stub_type
2645 aarch64_type_of_stub (asection *input_sec,
2646 const Elf_Internal_Rela *rel,
2648 unsigned char st_type,
2649 bfd_vma destination)
2652 bfd_signed_vma branch_offset;
2653 unsigned int r_type;
2654 enum elf_aarch64_stub_type stub_type = aarch64_stub_none;
2656 if (st_type != STT_FUNC
2657 && (sym_sec == input_sec))
2660 /* Determine where the call point is. */
2661 location = (input_sec->output_offset
2662 + input_sec->output_section->vma + rel->r_offset);
2664 branch_offset = (bfd_signed_vma) (destination - location);
2666 r_type = ELFNN_R_TYPE (rel->r_info);
2668 /* We don't want to redirect any old unconditional jump in this way,
2669 only one which is being used for a sibcall, where it is
2670 acceptable for the IP0 and IP1 registers to be clobbered. */
2671 if ((r_type == AARCH64_R (CALL26) || r_type == AARCH64_R (JUMP26))
2672 && (branch_offset > AARCH64_MAX_FWD_BRANCH_OFFSET
2673 || branch_offset < AARCH64_MAX_BWD_BRANCH_OFFSET))
2675 stub_type = aarch64_stub_long_branch;
2681 /* Build a name for an entry in the stub hash table. */
2684 elfNN_aarch64_stub_name (const asection *input_section,
2685 const asection *sym_sec,
2686 const struct elf_aarch64_link_hash_entry *hash,
2687 const Elf_Internal_Rela *rel)
2694 len = 8 + 1 + strlen (hash->root.root.root.string) + 1 + 16 + 1;
2695 stub_name = bfd_malloc (len);
2696 if (stub_name != NULL)
2697 snprintf (stub_name, len, "%08x_%s+%" BFD_VMA_FMT "x",
2698 (unsigned int) input_section->id,
2699 hash->root.root.root.string,
2704 len = 8 + 1 + 8 + 1 + 8 + 1 + 16 + 1;
2705 stub_name = bfd_malloc (len);
2706 if (stub_name != NULL)
2707 snprintf (stub_name, len, "%08x_%x:%x+%" BFD_VMA_FMT "x",
2708 (unsigned int) input_section->id,
2709 (unsigned int) sym_sec->id,
2710 (unsigned int) ELFNN_R_SYM (rel->r_info),
2717 /* Look up an entry in the stub hash. Stub entries are cached because
2718 creating the stub name takes a bit of time. */
2720 static struct elf_aarch64_stub_hash_entry *
2721 elfNN_aarch64_get_stub_entry (const asection *input_section,
2722 const asection *sym_sec,
2723 struct elf_link_hash_entry *hash,
2724 const Elf_Internal_Rela *rel,
2725 struct elf_aarch64_link_hash_table *htab)
2727 struct elf_aarch64_stub_hash_entry *stub_entry;
2728 struct elf_aarch64_link_hash_entry *h =
2729 (struct elf_aarch64_link_hash_entry *) hash;
2730 const asection *id_sec;
2732 if ((input_section->flags & SEC_CODE) == 0)
2735 /* If this input section is part of a group of sections sharing one
2736 stub section, then use the id of the first section in the group.
2737 Stub names need to include a section id, as there may well be
2738 more than one stub used to reach say, printf, and we need to
2739 distinguish between them. */
2740 id_sec = htab->stub_group[input_section->id].link_sec;
2742 if (h != NULL && h->stub_cache != NULL
2743 && h->stub_cache->h == h && h->stub_cache->id_sec == id_sec)
2745 stub_entry = h->stub_cache;
2751 stub_name = elfNN_aarch64_stub_name (id_sec, sym_sec, h, rel);
2752 if (stub_name == NULL)
2755 stub_entry = aarch64_stub_hash_lookup (&htab->stub_hash_table,
2756 stub_name, FALSE, FALSE);
2758 h->stub_cache = stub_entry;
2767 /* Create a stub section. */
2770 _bfd_aarch64_create_stub_section (asection *section,
2771 struct elf_aarch64_link_hash_table *htab)
2777 namelen = strlen (section->name);
2778 len = namelen + sizeof (STUB_SUFFIX);
2779 s_name = bfd_alloc (htab->stub_bfd, len);
2783 memcpy (s_name, section->name, namelen);
2784 memcpy (s_name + namelen, STUB_SUFFIX, sizeof (STUB_SUFFIX));
2785 return (*htab->add_stub_section) (s_name, section);
2789 /* Find or create a stub section for a link section.
2791 Fix or create the stub section used to collect stubs attached to
2792 the specified link section. */
2795 _bfd_aarch64_get_stub_for_link_section (asection *link_section,
2796 struct elf_aarch64_link_hash_table *htab)
2798 if (htab->stub_group[link_section->id].stub_sec == NULL)
2799 htab->stub_group[link_section->id].stub_sec
2800 = _bfd_aarch64_create_stub_section (link_section, htab);
2801 return htab->stub_group[link_section->id].stub_sec;
2805 /* Find or create a stub section in the stub group for an input
2809 _bfd_aarch64_create_or_find_stub_sec (asection *section,
2810 struct elf_aarch64_link_hash_table *htab)
2812 asection *link_sec = htab->stub_group[section->id].link_sec;
2813 return _bfd_aarch64_get_stub_for_link_section (link_sec, htab);
2817 /* Add a new stub entry in the stub group associated with an input
2818 section to the stub hash. Not all fields of the new stub entry are
2821 static struct elf_aarch64_stub_hash_entry *
2822 _bfd_aarch64_add_stub_entry_in_group (const char *stub_name,
2824 struct elf_aarch64_link_hash_table *htab)
2828 struct elf_aarch64_stub_hash_entry *stub_entry;
2830 link_sec = htab->stub_group[section->id].link_sec;
2831 stub_sec = _bfd_aarch64_create_or_find_stub_sec (section, htab);
2833 /* Enter this entry into the linker stub hash table. */
2834 stub_entry = aarch64_stub_hash_lookup (&htab->stub_hash_table, stub_name,
2836 if (stub_entry == NULL)
2838 (*_bfd_error_handler) (_("%s: cannot create stub entry %s"),
2839 section->owner, stub_name);
2843 stub_entry->stub_sec = stub_sec;
2844 stub_entry->stub_offset = 0;
2845 stub_entry->id_sec = link_sec;
2850 /* Add a new stub entry in the final stub section to the stub hash.
2851 Not all fields of the new stub entry are initialised. */
2853 static struct elf_aarch64_stub_hash_entry *
2854 _bfd_aarch64_add_stub_entry_after (const char *stub_name,
2855 asection *link_section,
2856 struct elf_aarch64_link_hash_table *htab)
2859 struct elf_aarch64_stub_hash_entry *stub_entry;
2861 stub_sec = _bfd_aarch64_get_stub_for_link_section (link_section, htab);
2862 stub_entry = aarch64_stub_hash_lookup (&htab->stub_hash_table, stub_name,
2864 if (stub_entry == NULL)
2866 (*_bfd_error_handler) (_("cannot create stub entry %s"), stub_name);
2870 stub_entry->stub_sec = stub_sec;
2871 stub_entry->stub_offset = 0;
2872 stub_entry->id_sec = link_section;
2879 aarch64_build_one_stub (struct bfd_hash_entry *gen_entry,
2880 void *in_arg ATTRIBUTE_UNUSED)
2882 struct elf_aarch64_stub_hash_entry *stub_entry;
2887 bfd_vma veneered_insn_loc;
2888 bfd_vma veneer_entry_loc;
2889 bfd_signed_vma branch_offset = 0;
2890 unsigned int template_size;
2891 const uint32_t *template;
2894 /* Massage our args to the form they really have. */
2895 stub_entry = (struct elf_aarch64_stub_hash_entry *) gen_entry;
2897 stub_sec = stub_entry->stub_sec;
2899 /* Make a note of the offset within the stubs for this entry. */
2900 stub_entry->stub_offset = stub_sec->size;
2901 loc = stub_sec->contents + stub_entry->stub_offset;
2903 stub_bfd = stub_sec->owner;
2905 /* This is the address of the stub destination. */
2906 sym_value = (stub_entry->target_value
2907 + stub_entry->target_section->output_offset
2908 + stub_entry->target_section->output_section->vma);
2910 if (stub_entry->stub_type == aarch64_stub_long_branch)
2912 bfd_vma place = (stub_entry->stub_offset + stub_sec->output_section->vma
2913 + stub_sec->output_offset);
2915 /* See if we can relax the stub. */
2916 if (aarch64_valid_for_adrp_p (sym_value, place))
2917 stub_entry->stub_type = aarch64_select_branch_stub (sym_value, place);
2920 switch (stub_entry->stub_type)
2922 case aarch64_stub_adrp_branch:
2923 template = aarch64_adrp_branch_stub;
2924 template_size = sizeof (aarch64_adrp_branch_stub);
2926 case aarch64_stub_long_branch:
2927 template = aarch64_long_branch_stub;
2928 template_size = sizeof (aarch64_long_branch_stub);
2930 case aarch64_stub_erratum_835769_veneer:
2931 template = aarch64_erratum_835769_stub;
2932 template_size = sizeof (aarch64_erratum_835769_stub);
2934 case aarch64_stub_erratum_843419_veneer:
2935 template = aarch64_erratum_843419_stub;
2936 template_size = sizeof (aarch64_erratum_843419_stub);
2942 for (i = 0; i < (template_size / sizeof template[0]); i++)
2944 bfd_putl32 (template[i], loc);
2948 template_size = (template_size + 7) & ~7;
2949 stub_sec->size += template_size;
2951 switch (stub_entry->stub_type)
2953 case aarch64_stub_adrp_branch:
2954 if (aarch64_relocate (AARCH64_R (ADR_PREL_PG_HI21), stub_bfd, stub_sec,
2955 stub_entry->stub_offset, sym_value))
2956 /* The stub would not have been relaxed if the offset was out
2960 if (aarch64_relocate (AARCH64_R (ADD_ABS_LO12_NC), stub_bfd, stub_sec,
2961 stub_entry->stub_offset + 4, sym_value))
2965 case aarch64_stub_long_branch:
2966 /* We want the value relative to the address 12 bytes back from the
2968 if (aarch64_relocate (AARCH64_R (PRELNN), stub_bfd, stub_sec,
2969 stub_entry->stub_offset + 16, sym_value + 12))
2973 case aarch64_stub_erratum_835769_veneer:
2974 veneered_insn_loc = stub_entry->target_section->output_section->vma
2975 + stub_entry->target_section->output_offset
2976 + stub_entry->target_value;
2977 veneer_entry_loc = stub_entry->stub_sec->output_section->vma
2978 + stub_entry->stub_sec->output_offset
2979 + stub_entry->stub_offset;
2980 branch_offset = veneered_insn_loc - veneer_entry_loc;
2981 branch_offset >>= 2;
2982 branch_offset &= 0x3ffffff;
2983 bfd_putl32 (stub_entry->veneered_insn,
2984 stub_sec->contents + stub_entry->stub_offset);
2985 bfd_putl32 (template[1] | branch_offset,
2986 stub_sec->contents + stub_entry->stub_offset + 4);
2989 case aarch64_stub_erratum_843419_veneer:
2990 if (aarch64_relocate (AARCH64_R (JUMP26), stub_bfd, stub_sec,
2991 stub_entry->stub_offset + 4, sym_value + 4))
3002 /* As above, but don't actually build the stub. Just bump offset so
3003 we know stub section sizes. */
3006 aarch64_size_one_stub (struct bfd_hash_entry *gen_entry,
3007 void *in_arg ATTRIBUTE_UNUSED)
3009 struct elf_aarch64_stub_hash_entry *stub_entry;
3012 /* Massage our args to the form they really have. */
3013 stub_entry = (struct elf_aarch64_stub_hash_entry *) gen_entry;
3015 switch (stub_entry->stub_type)
3017 case aarch64_stub_adrp_branch:
3018 size = sizeof (aarch64_adrp_branch_stub);
3020 case aarch64_stub_long_branch:
3021 size = sizeof (aarch64_long_branch_stub);
3023 case aarch64_stub_erratum_835769_veneer:
3024 size = sizeof (aarch64_erratum_835769_stub);
3026 case aarch64_stub_erratum_843419_veneer:
3027 size = sizeof (aarch64_erratum_843419_stub);
3033 size = (size + 7) & ~7;
3034 stub_entry->stub_sec->size += size;
3038 /* External entry points for sizing and building linker stubs. */
3040 /* Set up various things so that we can make a list of input sections
3041 for each output section included in the link. Returns -1 on error,
3042 0 when no stubs will be needed, and 1 on success. */
3045 elfNN_aarch64_setup_section_lists (bfd *output_bfd,
3046 struct bfd_link_info *info)
3049 unsigned int bfd_count;
3050 unsigned int top_id, top_index;
3052 asection **input_list, **list;
3054 struct elf_aarch64_link_hash_table *htab =
3055 elf_aarch64_hash_table (info);
3057 if (!is_elf_hash_table (htab))
3060 /* Count the number of input BFDs and find the top input section id. */
3061 for (input_bfd = info->input_bfds, bfd_count = 0, top_id = 0;
3062 input_bfd != NULL; input_bfd = input_bfd->link.next)
3065 for (section = input_bfd->sections;
3066 section != NULL; section = section->next)
3068 if (top_id < section->id)
3069 top_id = section->id;
3072 htab->bfd_count = bfd_count;
3074 amt = sizeof (struct map_stub) * (top_id + 1);
3075 htab->stub_group = bfd_zmalloc (amt);
3076 if (htab->stub_group == NULL)
3079 /* We can't use output_bfd->section_count here to find the top output
3080 section index as some sections may have been removed, and
3081 _bfd_strip_section_from_output doesn't renumber the indices. */
3082 for (section = output_bfd->sections, top_index = 0;
3083 section != NULL; section = section->next)
3085 if (top_index < section->index)
3086 top_index = section->index;
3089 htab->top_index = top_index;
3090 amt = sizeof (asection *) * (top_index + 1);
3091 input_list = bfd_malloc (amt);
3092 htab->input_list = input_list;
3093 if (input_list == NULL)
3096 /* For sections we aren't interested in, mark their entries with a
3097 value we can check later. */
3098 list = input_list + top_index;
3100 *list = bfd_abs_section_ptr;
3101 while (list-- != input_list);
3103 for (section = output_bfd->sections;
3104 section != NULL; section = section->next)
3106 if ((section->flags & SEC_CODE) != 0)
3107 input_list[section->index] = NULL;
3113 /* Used by elfNN_aarch64_next_input_section and group_sections. */
3114 #define PREV_SEC(sec) (htab->stub_group[(sec)->id].link_sec)
3116 /* The linker repeatedly calls this function for each input section,
3117 in the order that input sections are linked into output sections.
3118 Build lists of input sections to determine groupings between which
3119 we may insert linker stubs. */
3122 elfNN_aarch64_next_input_section (struct bfd_link_info *info, asection *isec)
3124 struct elf_aarch64_link_hash_table *htab =
3125 elf_aarch64_hash_table (info);
3127 if (isec->output_section->index <= htab->top_index)
3129 asection **list = htab->input_list + isec->output_section->index;
3131 if (*list != bfd_abs_section_ptr)
3133 /* Steal the link_sec pointer for our list. */
3134 /* This happens to make the list in reverse order,
3135 which is what we want. */
3136 PREV_SEC (isec) = *list;
3142 /* See whether we can group stub sections together. Grouping stub
3143 sections may result in fewer stubs. More importantly, we need to
3144 put all .init* and .fini* stubs at the beginning of the .init or
3145 .fini output sections respectively, because glibc splits the
3146 _init and _fini functions into multiple parts. Putting a stub in
3147 the middle of a function is not a good idea. */
3150 group_sections (struct elf_aarch64_link_hash_table *htab,
3151 bfd_size_type stub_group_size,
3152 bfd_boolean stubs_always_before_branch)
3154 asection **list = htab->input_list + htab->top_index;
3158 asection *tail = *list;
3160 if (tail == bfd_abs_section_ptr)
3163 while (tail != NULL)
3167 bfd_size_type total;
3171 while ((prev = PREV_SEC (curr)) != NULL
3172 && ((total += curr->output_offset - prev->output_offset)
3176 /* OK, the size from the start of CURR to the end is less
3177 than stub_group_size and thus can be handled by one stub
3178 section. (Or the tail section is itself larger than
3179 stub_group_size, in which case we may be toast.)
3180 We should really be keeping track of the total size of
3181 stubs added here, as stubs contribute to the final output
3185 prev = PREV_SEC (tail);
3186 /* Set up this stub group. */
3187 htab->stub_group[tail->id].link_sec = curr;
3189 while (tail != curr && (tail = prev) != NULL);
3191 /* But wait, there's more! Input sections up to stub_group_size
3192 bytes before the stub section can be handled by it too. */
3193 if (!stubs_always_before_branch)
3197 && ((total += tail->output_offset - prev->output_offset)
3201 prev = PREV_SEC (tail);
3202 htab->stub_group[tail->id].link_sec = curr;
3208 while (list-- != htab->input_list);
3210 free (htab->input_list);
3215 #define AARCH64_BITS(x, pos, n) (((x) >> (pos)) & ((1 << (n)) - 1))
3217 #define AARCH64_RT(insn) AARCH64_BITS (insn, 0, 5)
3218 #define AARCH64_RT2(insn) AARCH64_BITS (insn, 10, 5)
3219 #define AARCH64_RA(insn) AARCH64_BITS (insn, 10, 5)
3220 #define AARCH64_RD(insn) AARCH64_BITS (insn, 0, 5)
3221 #define AARCH64_RN(insn) AARCH64_BITS (insn, 5, 5)
3222 #define AARCH64_RM(insn) AARCH64_BITS (insn, 16, 5)
3224 #define AARCH64_MAC(insn) (((insn) & 0xff000000) == 0x9b000000)
3225 #define AARCH64_BIT(insn, n) AARCH64_BITS (insn, n, 1)
3226 #define AARCH64_OP31(insn) AARCH64_BITS (insn, 21, 3)
3227 #define AARCH64_ZR 0x1f
3229 /* All ld/st ops. See C4-182 of the ARM ARM. The encoding space for
3230 LD_PCREL, LDST_RO, LDST_UI and LDST_UIMM cover prefetch ops. */
3232 #define AARCH64_LD(insn) (AARCH64_BIT (insn, 22) == 1)
3233 #define AARCH64_LDST(insn) (((insn) & 0x0a000000) == 0x08000000)
3234 #define AARCH64_LDST_EX(insn) (((insn) & 0x3f000000) == 0x08000000)
3235 #define AARCH64_LDST_PCREL(insn) (((insn) & 0x3b000000) == 0x18000000)
3236 #define AARCH64_LDST_NAP(insn) (((insn) & 0x3b800000) == 0x28000000)
3237 #define AARCH64_LDSTP_PI(insn) (((insn) & 0x3b800000) == 0x28800000)
3238 #define AARCH64_LDSTP_O(insn) (((insn) & 0x3b800000) == 0x29000000)
3239 #define AARCH64_LDSTP_PRE(insn) (((insn) & 0x3b800000) == 0x29800000)
3240 #define AARCH64_LDST_UI(insn) (((insn) & 0x3b200c00) == 0x38000000)
3241 #define AARCH64_LDST_PIIMM(insn) (((insn) & 0x3b200c00) == 0x38000400)
3242 #define AARCH64_LDST_U(insn) (((insn) & 0x3b200c00) == 0x38000800)
3243 #define AARCH64_LDST_PREIMM(insn) (((insn) & 0x3b200c00) == 0x38000c00)
3244 #define AARCH64_LDST_RO(insn) (((insn) & 0x3b200c00) == 0x38200800)
3245 #define AARCH64_LDST_UIMM(insn) (((insn) & 0x3b000000) == 0x39000000)
3246 #define AARCH64_LDST_SIMD_M(insn) (((insn) & 0xbfbf0000) == 0x0c000000)
3247 #define AARCH64_LDST_SIMD_M_PI(insn) (((insn) & 0xbfa00000) == 0x0c800000)
3248 #define AARCH64_LDST_SIMD_S(insn) (((insn) & 0xbf9f0000) == 0x0d000000)
3249 #define AARCH64_LDST_SIMD_S_PI(insn) (((insn) & 0xbf800000) == 0x0d800000)
3251 /* Classify an INSN if it is indeed a load/store.
3253 Return TRUE if INSN is a LD/ST instruction otherwise return FALSE.
3255 For scalar LD/ST instructions PAIR is FALSE, RT is returned and RT2
3258 For LD/ST pair instructions PAIR is TRUE, RT and RT2 are returned.
3263 aarch64_mem_op_p (uint32_t insn, unsigned int *rt, unsigned int *rt2,
3264 bfd_boolean *pair, bfd_boolean *load)
3272 /* Bail out quickly if INSN doesn't fall into the the load-store
3274 if (!AARCH64_LDST (insn))
3279 if (AARCH64_LDST_EX (insn))
3281 *rt = AARCH64_RT (insn);
3283 if (AARCH64_BIT (insn, 21) == 1)
3286 *rt2 = AARCH64_RT2 (insn);
3288 *load = AARCH64_LD (insn);
3291 else if (AARCH64_LDST_NAP (insn)
3292 || AARCH64_LDSTP_PI (insn)
3293 || AARCH64_LDSTP_O (insn)
3294 || AARCH64_LDSTP_PRE (insn))
3297 *rt = AARCH64_RT (insn);
3298 *rt2 = AARCH64_RT2 (insn);
3299 *load = AARCH64_LD (insn);
3302 else if (AARCH64_LDST_PCREL (insn)
3303 || AARCH64_LDST_UI (insn)
3304 || AARCH64_LDST_PIIMM (insn)
3305 || AARCH64_LDST_U (insn)
3306 || AARCH64_LDST_PREIMM (insn)
3307 || AARCH64_LDST_RO (insn)
3308 || AARCH64_LDST_UIMM (insn))
3310 *rt = AARCH64_RT (insn);
3312 if (AARCH64_LDST_PCREL (insn))
3314 opc = AARCH64_BITS (insn, 22, 2);
3315 v = AARCH64_BIT (insn, 26);
3316 opc_v = opc | (v << 2);
3317 *load = (opc_v == 1 || opc_v == 2 || opc_v == 3
3318 || opc_v == 5 || opc_v == 7);
3321 else if (AARCH64_LDST_SIMD_M (insn)
3322 || AARCH64_LDST_SIMD_M_PI (insn))
3324 *rt = AARCH64_RT (insn);
3325 *load = AARCH64_BIT (insn, 22);
3326 opcode = (insn >> 12) & 0xf;
3353 else if (AARCH64_LDST_SIMD_S (insn)
3354 || AARCH64_LDST_SIMD_S_PI (insn))
3356 *rt = AARCH64_RT (insn);
3357 r = (insn >> 21) & 1;
3358 *load = AARCH64_BIT (insn, 22);
3359 opcode = (insn >> 13) & 0x7;
3371 *rt2 = *rt + (r == 0 ? 2 : 3);
3379 *rt2 = *rt + (r == 0 ? 2 : 3);
3391 /* Return TRUE if INSN is multiply-accumulate. */
3394 aarch64_mlxl_p (uint32_t insn)
3396 uint32_t op31 = AARCH64_OP31 (insn);
3398 if (AARCH64_MAC (insn)
3399 && (op31 == 0 || op31 == 1 || op31 == 5)
3400 /* Exclude MUL instructions which are encoded as a multiple accumulate
3402 && AARCH64_RA (insn) != AARCH64_ZR)
3408 /* Some early revisions of the Cortex-A53 have an erratum (835769) whereby
3409 it is possible for a 64-bit multiply-accumulate instruction to generate an
3410 incorrect result. The details are quite complex and hard to
3411 determine statically, since branches in the code may exist in some
3412 circumstances, but all cases end with a memory (load, store, or
3413 prefetch) instruction followed immediately by the multiply-accumulate
3414 operation. We employ a linker patching technique, by moving the potentially
3415 affected multiply-accumulate instruction into a patch region and replacing
3416 the original instruction with a branch to the patch. This function checks
3417 if INSN_1 is the memory operation followed by a multiply-accumulate
3418 operation (INSN_2). Return TRUE if an erratum sequence is found, FALSE
3419 if INSN_1 and INSN_2 are safe. */
3422 aarch64_erratum_sequence (uint32_t insn_1, uint32_t insn_2)
3432 if (aarch64_mlxl_p (insn_2)
3433 && aarch64_mem_op_p (insn_1, &rt, &rt2, &pair, &load))
3435 /* Any SIMD memory op is independent of the subsequent MLA
3436 by definition of the erratum. */
3437 if (AARCH64_BIT (insn_1, 26))
3440 /* If not SIMD, check for integer memory ops and MLA relationship. */
3441 rn = AARCH64_RN (insn_2);
3442 ra = AARCH64_RA (insn_2);
3443 rm = AARCH64_RM (insn_2);
3445 /* If this is a load and there's a true(RAW) dependency, we are safe
3446 and this is not an erratum sequence. */
3448 (rt == rn || rt == rm || rt == ra
3449 || (pair && (rt2 == rn || rt2 == rm || rt2 == ra))))
3452 /* We conservatively put out stubs for all other cases (including
3460 /* Used to order a list of mapping symbols by address. */
3463 elf_aarch64_compare_mapping (const void *a, const void *b)
3465 const elf_aarch64_section_map *amap = (const elf_aarch64_section_map *) a;
3466 const elf_aarch64_section_map *bmap = (const elf_aarch64_section_map *) b;
3468 if (amap->vma > bmap->vma)
3470 else if (amap->vma < bmap->vma)
3472 else if (amap->type > bmap->type)
3473 /* Ensure results do not depend on the host qsort for objects with
3474 multiple mapping symbols at the same address by sorting on type
3477 else if (amap->type < bmap->type)
3485 _bfd_aarch64_erratum_835769_stub_name (unsigned num_fixes)
3487 char *stub_name = (char *) bfd_malloc
3488 (strlen ("__erratum_835769_veneer_") + 16);
3489 sprintf (stub_name,"__erratum_835769_veneer_%d", num_fixes);
3493 /* Scan for Cortex-A53 erratum 835769 sequence.
3495 Return TRUE else FALSE on abnormal termination. */
3498 _bfd_aarch64_erratum_835769_scan (bfd *input_bfd,
3499 struct bfd_link_info *info,
3500 unsigned int *num_fixes_p)
3503 struct elf_aarch64_link_hash_table *htab = elf_aarch64_hash_table (info);
3504 unsigned int num_fixes = *num_fixes_p;
3509 for (section = input_bfd->sections;
3511 section = section->next)
3513 bfd_byte *contents = NULL;
3514 struct _aarch64_elf_section_data *sec_data;
3517 if (elf_section_type (section) != SHT_PROGBITS
3518 || (elf_section_flags (section) & SHF_EXECINSTR) == 0
3519 || (section->flags & SEC_EXCLUDE) != 0
3520 || (section->sec_info_type == SEC_INFO_TYPE_JUST_SYMS)
3521 || (section->output_section == bfd_abs_section_ptr))
3524 if (elf_section_data (section)->this_hdr.contents != NULL)
3525 contents = elf_section_data (section)->this_hdr.contents;
3526 else if (! bfd_malloc_and_get_section (input_bfd, section, &contents))
3529 sec_data = elf_aarch64_section_data (section);
3531 qsort (sec_data->map, sec_data->mapcount,
3532 sizeof (elf_aarch64_section_map), elf_aarch64_compare_mapping);
3534 for (span = 0; span < sec_data->mapcount; span++)
3536 unsigned int span_start = sec_data->map[span].vma;
3537 unsigned int span_end = ((span == sec_data->mapcount - 1)
3538 ? sec_data->map[0].vma + section->size
3539 : sec_data->map[span + 1].vma);
3541 char span_type = sec_data->map[span].type;
3543 if (span_type == 'd')
3546 for (i = span_start; i + 4 < span_end; i += 4)
3548 uint32_t insn_1 = bfd_getl32 (contents + i);
3549 uint32_t insn_2 = bfd_getl32 (contents + i + 4);
3551 if (aarch64_erratum_sequence (insn_1, insn_2))
3553 struct elf_aarch64_stub_hash_entry *stub_entry;
3554 char *stub_name = _bfd_aarch64_erratum_835769_stub_name (num_fixes);
3558 stub_entry = _bfd_aarch64_add_stub_entry_in_group (stub_name,
3564 stub_entry->stub_type = aarch64_stub_erratum_835769_veneer;
3565 stub_entry->target_section = section;
3566 stub_entry->target_value = i + 4;
3567 stub_entry->veneered_insn = insn_2;
3568 stub_entry->output_name = stub_name;
3573 if (elf_section_data (section)->this_hdr.contents == NULL)
3577 *num_fixes_p = num_fixes;
3583 /* Test if instruction INSN is ADRP. */
3586 _bfd_aarch64_adrp_p (uint32_t insn)
3588 return ((insn & 0x9f000000) == 0x90000000);
3592 /* Helper predicate to look for cortex-a53 erratum 843419 sequence 1. */
3595 _bfd_aarch64_erratum_843419_sequence_p (uint32_t insn_1, uint32_t insn_2,
3603 return (aarch64_mem_op_p (insn_2, &rt, &rt2, &pair, &load)
3606 && AARCH64_LDST_UIMM (insn_3)
3607 && AARCH64_RN (insn_3) == AARCH64_RD (insn_1));
3611 /* Test for the presence of Cortex-A53 erratum 843419 instruction sequence.
3613 Return TRUE if section CONTENTS at offset I contains one of the
3614 erratum 843419 sequences, otherwise return FALSE. If a sequence is
3615 seen set P_VENEER_I to the offset of the final LOAD/STORE
3616 instruction in the sequence.
3620 _bfd_aarch64_erratum_843419_p (bfd_byte *contents, bfd_vma vma,
3621 bfd_vma i, bfd_vma span_end,
3622 bfd_vma *p_veneer_i)
3624 uint32_t insn_1 = bfd_getl32 (contents + i);
3626 if (!_bfd_aarch64_adrp_p (insn_1))
3629 if (span_end < i + 12)
3632 uint32_t insn_2 = bfd_getl32 (contents + i + 4);
3633 uint32_t insn_3 = bfd_getl32 (contents + i + 8);
3635 if ((vma & 0xfff) != 0xff8 && (vma & 0xfff) != 0xffc)
3638 if (_bfd_aarch64_erratum_843419_sequence_p (insn_1, insn_2, insn_3))
3640 *p_veneer_i = i + 8;
3644 if (span_end < i + 16)
3647 uint32_t insn_4 = bfd_getl32 (contents + i + 12);
3649 if (_bfd_aarch64_erratum_843419_sequence_p (insn_1, insn_2, insn_4))
3651 *p_veneer_i = i + 12;
3659 /* Resize all stub sections. */
3662 _bfd_aarch64_resize_stubs (struct elf_aarch64_link_hash_table *htab)
3666 /* OK, we've added some stubs. Find out the new size of the
3668 for (section = htab->stub_bfd->sections;
3669 section != NULL; section = section->next)
3671 /* Ignore non-stub sections. */
3672 if (!strstr (section->name, STUB_SUFFIX))
3677 bfd_hash_traverse (&htab->stub_hash_table, aarch64_size_one_stub, htab);
3679 for (section = htab->stub_bfd->sections;
3680 section != NULL; section = section->next)
3682 if (!strstr (section->name, STUB_SUFFIX))
3688 /* Ensure all stub sections have a size which is a multiple of
3689 4096. This is important in order to ensure that the insertion
3690 of stub sections does not in itself move existing code around
3691 in such a way that new errata sequences are created. */
3692 if (htab->fix_erratum_843419)
3694 section->size = BFD_ALIGN (section->size, 0x1000);
3699 /* Construct an erratum 843419 workaround stub name.
3703 _bfd_aarch64_erratum_843419_stub_name (asection *input_section,
3706 const bfd_size_type len = 8 + 4 + 1 + 8 + 1 + 16 + 1;
3707 char *stub_name = bfd_malloc (len);
3709 if (stub_name != NULL)
3710 snprintf (stub_name, len, "e843419@%04x_%08x_%" BFD_VMA_FMT "x",
3711 input_section->owner->id,
3717 /* Build a stub_entry structure describing an 843419 fixup.
3719 The stub_entry constructed is populated with the bit pattern INSN
3720 of the instruction located at OFFSET within input SECTION.
3722 Returns TRUE on success. */
3725 _bfd_aarch64_erratum_843419_fixup (uint32_t insn,
3726 bfd_vma adrp_offset,
3727 bfd_vma ldst_offset,
3729 struct bfd_link_info *info)
3731 struct elf_aarch64_link_hash_table *htab = elf_aarch64_hash_table (info);
3733 struct elf_aarch64_stub_hash_entry *stub_entry;
3735 stub_name = _bfd_aarch64_erratum_843419_stub_name (section, ldst_offset);
3736 stub_entry = aarch64_stub_hash_lookup (&htab->stub_hash_table, stub_name,
3744 /* We always place an 843419 workaround veneer in the stub section
3745 attached to the input section in which an erratum sequence has
3746 been found. This ensures that later in the link process (in
3747 elfNN_aarch64_write_section) when we copy the veneered
3748 instruction from the input section into the stub section the
3749 copied instruction will have had any relocations applied to it.
3750 If we placed workaround veneers in any other stub section then we
3751 could not assume that all relocations have been processed on the
3752 corresponding input section at the point we output the stub
3756 stub_entry = _bfd_aarch64_add_stub_entry_after (stub_name, section, htab);
3757 if (stub_entry == NULL)
3763 stub_entry->adrp_offset = adrp_offset;
3764 stub_entry->target_value = ldst_offset;
3765 stub_entry->target_section = section;
3766 stub_entry->stub_type = aarch64_stub_erratum_843419_veneer;
3767 stub_entry->veneered_insn = insn;
3768 stub_entry->output_name = stub_name;
3774 /* Scan an input section looking for the signature of erratum 843419.
3776 Scans input SECTION in INPUT_BFD looking for erratum 843419
3777 signatures, for each signature found a stub_entry is created
3778 describing the location of the erratum for subsequent fixup.
3780 Return TRUE on successful scan, FALSE on failure to scan.
3784 _bfd_aarch64_erratum_843419_scan (bfd *input_bfd, asection *section,
3785 struct bfd_link_info *info)
3787 struct elf_aarch64_link_hash_table *htab = elf_aarch64_hash_table (info);
3792 if (elf_section_type (section) != SHT_PROGBITS
3793 || (elf_section_flags (section) & SHF_EXECINSTR) == 0
3794 || (section->flags & SEC_EXCLUDE) != 0
3795 || (section->sec_info_type == SEC_INFO_TYPE_JUST_SYMS)
3796 || (section->output_section == bfd_abs_section_ptr))
3801 bfd_byte *contents = NULL;
3802 struct _aarch64_elf_section_data *sec_data;
3805 if (elf_section_data (section)->this_hdr.contents != NULL)
3806 contents = elf_section_data (section)->this_hdr.contents;
3807 else if (! bfd_malloc_and_get_section (input_bfd, section, &contents))
3810 sec_data = elf_aarch64_section_data (section);
3812 qsort (sec_data->map, sec_data->mapcount,
3813 sizeof (elf_aarch64_section_map), elf_aarch64_compare_mapping);
3815 for (span = 0; span < sec_data->mapcount; span++)
3817 unsigned int span_start = sec_data->map[span].vma;
3818 unsigned int span_end = ((span == sec_data->mapcount - 1)
3819 ? sec_data->map[0].vma + section->size
3820 : sec_data->map[span + 1].vma);
3822 char span_type = sec_data->map[span].type;
3824 if (span_type == 'd')
3827 for (i = span_start; i + 8 < span_end; i += 4)
3829 bfd_vma vma = (section->output_section->vma
3830 + section->output_offset
3834 if (_bfd_aarch64_erratum_843419_p
3835 (contents, vma, i, span_end, &veneer_i))
3837 uint32_t insn = bfd_getl32 (contents + veneer_i);
3839 if (!_bfd_aarch64_erratum_843419_fixup (insn, i, veneer_i,
3846 if (elf_section_data (section)->this_hdr.contents == NULL)
3855 /* Determine and set the size of the stub section for a final link.
3857 The basic idea here is to examine all the relocations looking for
3858 PC-relative calls to a target that is unreachable with a "bl"
3862 elfNN_aarch64_size_stubs (bfd *output_bfd,
3864 struct bfd_link_info *info,
3865 bfd_signed_vma group_size,
3866 asection * (*add_stub_section) (const char *,
3868 void (*layout_sections_again) (void))
3870 bfd_size_type stub_group_size;
3871 bfd_boolean stubs_always_before_branch;
3872 bfd_boolean stub_changed = FALSE;
3873 struct elf_aarch64_link_hash_table *htab = elf_aarch64_hash_table (info);
3874 unsigned int num_erratum_835769_fixes = 0;
3876 /* Propagate mach to stub bfd, because it may not have been
3877 finalized when we created stub_bfd. */
3878 bfd_set_arch_mach (stub_bfd, bfd_get_arch (output_bfd),
3879 bfd_get_mach (output_bfd));
3881 /* Stash our params away. */
3882 htab->stub_bfd = stub_bfd;
3883 htab->add_stub_section = add_stub_section;
3884 htab->layout_sections_again = layout_sections_again;
3885 stubs_always_before_branch = group_size < 0;
3887 stub_group_size = -group_size;
3889 stub_group_size = group_size;
3891 if (stub_group_size == 1)
3893 /* Default values. */
3894 /* AArch64 branch range is +-128MB. The value used is 1MB less. */
3895 stub_group_size = 127 * 1024 * 1024;
3898 group_sections (htab, stub_group_size, stubs_always_before_branch);
3900 (*htab->layout_sections_again) ();
3902 if (htab->fix_erratum_835769)
3906 for (input_bfd = info->input_bfds;
3907 input_bfd != NULL; input_bfd = input_bfd->link.next)
3908 if (!_bfd_aarch64_erratum_835769_scan (input_bfd, info,
3909 &num_erratum_835769_fixes))
3912 _bfd_aarch64_resize_stubs (htab);
3913 (*htab->layout_sections_again) ();
3916 if (htab->fix_erratum_843419)
3920 for (input_bfd = info->input_bfds;
3922 input_bfd = input_bfd->link.next)
3926 for (section = input_bfd->sections;
3928 section = section->next)
3929 if (!_bfd_aarch64_erratum_843419_scan (input_bfd, section, info))
3933 _bfd_aarch64_resize_stubs (htab);
3934 (*htab->layout_sections_again) ();
3941 for (input_bfd = info->input_bfds;
3942 input_bfd != NULL; input_bfd = input_bfd->link.next)
3944 Elf_Internal_Shdr *symtab_hdr;
3946 Elf_Internal_Sym *local_syms = NULL;
3948 /* We'll need the symbol table in a second. */
3949 symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
3950 if (symtab_hdr->sh_info == 0)
3953 /* Walk over each section attached to the input bfd. */
3954 for (section = input_bfd->sections;
3955 section != NULL; section = section->next)
3957 Elf_Internal_Rela *internal_relocs, *irelaend, *irela;
3959 /* If there aren't any relocs, then there's nothing more
3961 if ((section->flags & SEC_RELOC) == 0
3962 || section->reloc_count == 0
3963 || (section->flags & SEC_CODE) == 0)
3966 /* If this section is a link-once section that will be
3967 discarded, then don't create any stubs. */
3968 if (section->output_section == NULL
3969 || section->output_section->owner != output_bfd)
3972 /* Get the relocs. */
3974 = _bfd_elf_link_read_relocs (input_bfd, section, NULL,
3975 NULL, info->keep_memory);
3976 if (internal_relocs == NULL)
3977 goto error_ret_free_local;
3979 /* Now examine each relocation. */
3980 irela = internal_relocs;
3981 irelaend = irela + section->reloc_count;
3982 for (; irela < irelaend; irela++)
3984 unsigned int r_type, r_indx;
3985 enum elf_aarch64_stub_type stub_type;
3986 struct elf_aarch64_stub_hash_entry *stub_entry;
3989 bfd_vma destination;
3990 struct elf_aarch64_link_hash_entry *hash;
3991 const char *sym_name;
3993 const asection *id_sec;
3994 unsigned char st_type;
3997 r_type = ELFNN_R_TYPE (irela->r_info);
3998 r_indx = ELFNN_R_SYM (irela->r_info);
4000 if (r_type >= (unsigned int) R_AARCH64_end)
4002 bfd_set_error (bfd_error_bad_value);
4003 error_ret_free_internal:
4004 if (elf_section_data (section)->relocs == NULL)
4005 free (internal_relocs);
4006 goto error_ret_free_local;
4009 /* Only look for stubs on unconditional branch and
4010 branch and link instructions. */
4011 if (r_type != (unsigned int) AARCH64_R (CALL26)
4012 && r_type != (unsigned int) AARCH64_R (JUMP26))
4015 /* Now determine the call target, its name, value,
4022 if (r_indx < symtab_hdr->sh_info)
4024 /* It's a local symbol. */
4025 Elf_Internal_Sym *sym;
4026 Elf_Internal_Shdr *hdr;
4028 if (local_syms == NULL)
4031 = (Elf_Internal_Sym *) symtab_hdr->contents;
4032 if (local_syms == NULL)
4034 = bfd_elf_get_elf_syms (input_bfd, symtab_hdr,
4035 symtab_hdr->sh_info, 0,
4037 if (local_syms == NULL)
4038 goto error_ret_free_internal;
4041 sym = local_syms + r_indx;
4042 hdr = elf_elfsections (input_bfd)[sym->st_shndx];
4043 sym_sec = hdr->bfd_section;
4045 /* This is an undefined symbol. It can never
4049 if (ELF_ST_TYPE (sym->st_info) != STT_SECTION)
4050 sym_value = sym->st_value;
4051 destination = (sym_value + irela->r_addend
4052 + sym_sec->output_offset
4053 + sym_sec->output_section->vma);
4054 st_type = ELF_ST_TYPE (sym->st_info);
4056 = bfd_elf_string_from_elf_section (input_bfd,
4057 symtab_hdr->sh_link,
4064 e_indx = r_indx - symtab_hdr->sh_info;
4065 hash = ((struct elf_aarch64_link_hash_entry *)
4066 elf_sym_hashes (input_bfd)[e_indx]);
4068 while (hash->root.root.type == bfd_link_hash_indirect
4069 || hash->root.root.type == bfd_link_hash_warning)
4070 hash = ((struct elf_aarch64_link_hash_entry *)
4071 hash->root.root.u.i.link);
4073 if (hash->root.root.type == bfd_link_hash_defined
4074 || hash->root.root.type == bfd_link_hash_defweak)
4076 struct elf_aarch64_link_hash_table *globals =
4077 elf_aarch64_hash_table (info);
4078 sym_sec = hash->root.root.u.def.section;
4079 sym_value = hash->root.root.u.def.value;
4080 /* For a destination in a shared library,
4081 use the PLT stub as target address to
4082 decide whether a branch stub is
4084 if (globals->root.splt != NULL && hash != NULL
4085 && hash->root.plt.offset != (bfd_vma) - 1)
4087 sym_sec = globals->root.splt;
4088 sym_value = hash->root.plt.offset;
4089 if (sym_sec->output_section != NULL)
4090 destination = (sym_value
4091 + sym_sec->output_offset
4093 sym_sec->output_section->vma);
4095 else if (sym_sec->output_section != NULL)
4096 destination = (sym_value + irela->r_addend
4097 + sym_sec->output_offset
4098 + sym_sec->output_section->vma);
4100 else if (hash->root.root.type == bfd_link_hash_undefined
4101 || (hash->root.root.type
4102 == bfd_link_hash_undefweak))
4104 /* For a shared library, use the PLT stub as
4105 target address to decide whether a long
4106 branch stub is needed.
4107 For absolute code, they cannot be handled. */
4108 struct elf_aarch64_link_hash_table *globals =
4109 elf_aarch64_hash_table (info);
4111 if (globals->root.splt != NULL && hash != NULL
4112 && hash->root.plt.offset != (bfd_vma) - 1)
4114 sym_sec = globals->root.splt;
4115 sym_value = hash->root.plt.offset;
4116 if (sym_sec->output_section != NULL)
4117 destination = (sym_value
4118 + sym_sec->output_offset
4120 sym_sec->output_section->vma);
4127 bfd_set_error (bfd_error_bad_value);
4128 goto error_ret_free_internal;
4130 st_type = ELF_ST_TYPE (hash->root.type);
4131 sym_name = hash->root.root.root.string;
4134 /* Determine what (if any) linker stub is needed. */
4135 stub_type = aarch64_type_of_stub (section, irela, sym_sec,
4136 st_type, destination);
4137 if (stub_type == aarch64_stub_none)
4140 /* Support for grouping stub sections. */
4141 id_sec = htab->stub_group[section->id].link_sec;
4143 /* Get the name of this stub. */
4144 stub_name = elfNN_aarch64_stub_name (id_sec, sym_sec, hash,
4147 goto error_ret_free_internal;
4150 aarch64_stub_hash_lookup (&htab->stub_hash_table,
4151 stub_name, FALSE, FALSE);
4152 if (stub_entry != NULL)
4154 /* The proper stub has already been created. */
4159 stub_entry = _bfd_aarch64_add_stub_entry_in_group
4160 (stub_name, section, htab);
4161 if (stub_entry == NULL)
4164 goto error_ret_free_internal;
4167 stub_entry->target_value = sym_value + irela->r_addend;
4168 stub_entry->target_section = sym_sec;
4169 stub_entry->stub_type = stub_type;
4170 stub_entry->h = hash;
4171 stub_entry->st_type = st_type;
4173 if (sym_name == NULL)
4174 sym_name = "unnamed";
4175 len = sizeof (STUB_ENTRY_NAME) + strlen (sym_name);
4176 stub_entry->output_name = bfd_alloc (htab->stub_bfd, len);
4177 if (stub_entry->output_name == NULL)
4180 goto error_ret_free_internal;
4183 snprintf (stub_entry->output_name, len, STUB_ENTRY_NAME,
4186 stub_changed = TRUE;
4189 /* We're done with the internal relocs, free them. */
4190 if (elf_section_data (section)->relocs == NULL)
4191 free (internal_relocs);
4198 _bfd_aarch64_resize_stubs (htab);
4200 /* Ask the linker to do its stuff. */
4201 (*htab->layout_sections_again) ();
4202 stub_changed = FALSE;
4207 error_ret_free_local:
4211 /* Build all the stubs associated with the current output file. The
4212 stubs are kept in a hash table attached to the main linker hash
4213 table. We also set up the .plt entries for statically linked PIC
4214 functions here. This function is called via aarch64_elf_finish in the
4218 elfNN_aarch64_build_stubs (struct bfd_link_info *info)
4221 struct bfd_hash_table *table;
4222 struct elf_aarch64_link_hash_table *htab;
4224 htab = elf_aarch64_hash_table (info);
4226 for (stub_sec = htab->stub_bfd->sections;
4227 stub_sec != NULL; stub_sec = stub_sec->next)
4231 /* Ignore non-stub sections. */
4232 if (!strstr (stub_sec->name, STUB_SUFFIX))
4235 /* Allocate memory to hold the linker stubs. */
4236 size = stub_sec->size;
4237 stub_sec->contents = bfd_zalloc (htab->stub_bfd, size);
4238 if (stub_sec->contents == NULL && size != 0)
4242 bfd_putl32 (0x14000000 | (size >> 2), stub_sec->contents);
4243 stub_sec->size += 4;
4246 /* Build the stubs as directed by the stub hash table. */
4247 table = &htab->stub_hash_table;
4248 bfd_hash_traverse (table, aarch64_build_one_stub, info);
4254 /* Add an entry to the code/data map for section SEC. */
4257 elfNN_aarch64_section_map_add (asection *sec, char type, bfd_vma vma)
4259 struct _aarch64_elf_section_data *sec_data =
4260 elf_aarch64_section_data (sec);
4261 unsigned int newidx;
4263 if (sec_data->map == NULL)
4265 sec_data->map = bfd_malloc (sizeof (elf_aarch64_section_map));
4266 sec_data->mapcount = 0;
4267 sec_data->mapsize = 1;
4270 newidx = sec_data->mapcount++;
4272 if (sec_data->mapcount > sec_data->mapsize)
4274 sec_data->mapsize *= 2;
4275 sec_data->map = bfd_realloc_or_free
4276 (sec_data->map, sec_data->mapsize * sizeof (elf_aarch64_section_map));
4281 sec_data->map[newidx].vma = vma;
4282 sec_data->map[newidx].type = type;
4287 /* Initialise maps of insn/data for input BFDs. */
4289 bfd_elfNN_aarch64_init_maps (bfd *abfd)
4291 Elf_Internal_Sym *isymbuf;
4292 Elf_Internal_Shdr *hdr;
4293 unsigned int i, localsyms;
4295 /* Make sure that we are dealing with an AArch64 elf binary. */
4296 if (!is_aarch64_elf (abfd))
4299 if ((abfd->flags & DYNAMIC) != 0)
4302 hdr = &elf_symtab_hdr (abfd);
4303 localsyms = hdr->sh_info;
4305 /* Obtain a buffer full of symbols for this BFD. The hdr->sh_info field
4306 should contain the number of local symbols, which should come before any
4307 global symbols. Mapping symbols are always local. */
4308 isymbuf = bfd_elf_get_elf_syms (abfd, hdr, localsyms, 0, NULL, NULL, NULL);
4310 /* No internal symbols read? Skip this BFD. */
4311 if (isymbuf == NULL)
4314 for (i = 0; i < localsyms; i++)
4316 Elf_Internal_Sym *isym = &isymbuf[i];
4317 asection *sec = bfd_section_from_elf_index (abfd, isym->st_shndx);
4320 if (sec != NULL && ELF_ST_BIND (isym->st_info) == STB_LOCAL)
4322 name = bfd_elf_string_from_elf_section (abfd,
4326 if (bfd_is_aarch64_special_symbol_name
4327 (name, BFD_AARCH64_SPECIAL_SYM_TYPE_MAP))
4328 elfNN_aarch64_section_map_add (sec, name[1], isym->st_value);
4333 /* Set option values needed during linking. */
4335 bfd_elfNN_aarch64_set_options (struct bfd *output_bfd,
4336 struct bfd_link_info *link_info,
4338 int no_wchar_warn, int pic_veneer,
4339 int fix_erratum_835769,
4340 int fix_erratum_843419,
4341 int no_apply_dynamic_relocs)
4343 struct elf_aarch64_link_hash_table *globals;
4345 globals = elf_aarch64_hash_table (link_info);
4346 globals->pic_veneer = pic_veneer;
4347 globals->fix_erratum_835769 = fix_erratum_835769;
4348 globals->fix_erratum_843419 = fix_erratum_843419;
4349 globals->fix_erratum_843419_adr = TRUE;
4350 globals->no_apply_dynamic_relocs = no_apply_dynamic_relocs;
4352 BFD_ASSERT (is_aarch64_elf (output_bfd));
4353 elf_aarch64_tdata (output_bfd)->no_enum_size_warning = no_enum_warn;
4354 elf_aarch64_tdata (output_bfd)->no_wchar_size_warning = no_wchar_warn;
4358 aarch64_calculate_got_entry_vma (struct elf_link_hash_entry *h,
4359 struct elf_aarch64_link_hash_table
4360 *globals, struct bfd_link_info *info,
4361 bfd_vma value, bfd *output_bfd,
4362 bfd_boolean *unresolved_reloc_p)
4364 bfd_vma off = (bfd_vma) - 1;
4365 asection *basegot = globals->root.sgot;
4366 bfd_boolean dyn = globals->root.dynamic_sections_created;
4370 BFD_ASSERT (basegot != NULL);
4371 off = h->got.offset;
4372 BFD_ASSERT (off != (bfd_vma) - 1);
4373 if (!WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, bfd_link_pic (info), h)
4374 || (bfd_link_pic (info)
4375 && SYMBOL_REFERENCES_LOCAL (info, h))
4376 || (ELF_ST_VISIBILITY (h->other)
4377 && h->root.type == bfd_link_hash_undefweak))
4379 /* This is actually a static link, or it is a -Bsymbolic link
4380 and the symbol is defined locally. We must initialize this
4381 entry in the global offset table. Since the offset must
4382 always be a multiple of 8 (4 in the case of ILP32), we use
4383 the least significant bit to record whether we have
4384 initialized it already.
4385 When doing a dynamic link, we create a .rel(a).got relocation
4386 entry to initialize the value. This is done in the
4387 finish_dynamic_symbol routine. */
4392 bfd_put_NN (output_bfd, value, basegot->contents + off);
4397 *unresolved_reloc_p = FALSE;
4399 off = off + basegot->output_section->vma + basegot->output_offset;
4405 /* Change R_TYPE to a more efficient access model where possible,
4406 return the new reloc type. */
4408 static bfd_reloc_code_real_type
4409 aarch64_tls_transition_without_check (bfd_reloc_code_real_type r_type,
4410 struct elf_link_hash_entry *h)
4412 bfd_boolean is_local = h == NULL;
4416 case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21:
4417 case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21:
4419 ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1
4420 : BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21);
4422 case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21:
4424 ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC
4427 case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19:
4429 ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1
4430 : BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19);
4432 case BFD_RELOC_AARCH64_TLSDESC_LDR:
4434 ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC
4435 : BFD_RELOC_AARCH64_NONE);
4437 case BFD_RELOC_AARCH64_TLSDESC_OFF_G0_NC:
4439 ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1_NC
4440 : BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G0_NC);
4442 case BFD_RELOC_AARCH64_TLSDESC_OFF_G1:
4444 ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G2
4445 : BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G1);
4447 case BFD_RELOC_AARCH64_TLSDESC_LDNN_LO12_NC:
4448 case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC:
4450 ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC
4451 : BFD_RELOC_AARCH64_TLSIE_LDNN_GOTTPREL_LO12_NC);
4453 case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21:
4454 return is_local ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1 : r_type;
4456 case BFD_RELOC_AARCH64_TLSIE_LDNN_GOTTPREL_LO12_NC:
4457 return is_local ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC : r_type;
4459 case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19:
4462 case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21:
4464 ? BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_HI12
4465 : BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19);
4467 case BFD_RELOC_AARCH64_TLSDESC_ADD:
4468 case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12_NC:
4469 case BFD_RELOC_AARCH64_TLSDESC_CALL:
4470 /* Instructions with these relocations will become NOPs. */
4471 return BFD_RELOC_AARCH64_NONE;
4473 case BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC:
4474 case BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21:
4475 case BFD_RELOC_AARCH64_TLSLD_ADR_PREL21:
4476 return is_local ? BFD_RELOC_AARCH64_NONE : r_type;
4479 case BFD_RELOC_AARCH64_TLSGD_MOVW_G0_NC:
4481 ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1_NC
4482 : BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G0_NC;
4484 case BFD_RELOC_AARCH64_TLSGD_MOVW_G1:
4486 ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G2
4487 : BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G1;
4498 aarch64_reloc_got_type (bfd_reloc_code_real_type r_type)
4502 case BFD_RELOC_AARCH64_ADR_GOT_PAGE:
4503 case BFD_RELOC_AARCH64_GOT_LD_PREL19:
4504 case BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14:
4505 case BFD_RELOC_AARCH64_LD32_GOT_LO12_NC:
4506 case BFD_RELOC_AARCH64_LD64_GOTOFF_LO15:
4507 case BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15:
4508 case BFD_RELOC_AARCH64_LD64_GOT_LO12_NC:
4509 case BFD_RELOC_AARCH64_MOVW_GOTOFF_G0_NC:
4510 case BFD_RELOC_AARCH64_MOVW_GOTOFF_G1:
4513 case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC:
4514 case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21:
4515 case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21:
4516 case BFD_RELOC_AARCH64_TLSGD_MOVW_G0_NC:
4517 case BFD_RELOC_AARCH64_TLSGD_MOVW_G1:
4518 case BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC:
4519 case BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21:
4520 case BFD_RELOC_AARCH64_TLSLD_ADR_PREL21:
4523 case BFD_RELOC_AARCH64_TLSDESC_ADD:
4524 case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12_NC:
4525 case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21:
4526 case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21:
4527 case BFD_RELOC_AARCH64_TLSDESC_CALL:
4528 case BFD_RELOC_AARCH64_TLSDESC_LD32_LO12_NC:
4529 case BFD_RELOC_AARCH64_TLSDESC_LD64_LO12_NC:
4530 case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19:
4531 case BFD_RELOC_AARCH64_TLSDESC_LDR:
4532 case BFD_RELOC_AARCH64_TLSDESC_OFF_G0_NC:
4533 case BFD_RELOC_AARCH64_TLSDESC_OFF_G1:
4534 return GOT_TLSDESC_GD;
4536 case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21:
4537 case BFD_RELOC_AARCH64_TLSIE_LD32_GOTTPREL_LO12_NC:
4538 case BFD_RELOC_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC:
4539 case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19:
4540 case BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G0_NC:
4541 case BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G1:
4551 aarch64_can_relax_tls (bfd *input_bfd,
4552 struct bfd_link_info *info,
4553 bfd_reloc_code_real_type r_type,
4554 struct elf_link_hash_entry *h,
4555 unsigned long r_symndx)
4557 unsigned int symbol_got_type;
4558 unsigned int reloc_got_type;
4560 if (! IS_AARCH64_TLS_RELAX_RELOC (r_type))
4563 symbol_got_type = elfNN_aarch64_symbol_got_type (h, input_bfd, r_symndx);
4564 reloc_got_type = aarch64_reloc_got_type (r_type);
4566 if (symbol_got_type == GOT_TLS_IE && GOT_TLS_GD_ANY_P (reloc_got_type))
4569 if (bfd_link_pic (info))
4572 if (h && h->root.type == bfd_link_hash_undefweak)
4578 /* Given the relocation code R_TYPE, return the relaxed bfd reloc
4581 static bfd_reloc_code_real_type
4582 aarch64_tls_transition (bfd *input_bfd,
4583 struct bfd_link_info *info,
4584 unsigned int r_type,
4585 struct elf_link_hash_entry *h,
4586 unsigned long r_symndx)
4588 bfd_reloc_code_real_type bfd_r_type
4589 = elfNN_aarch64_bfd_reloc_from_type (r_type);
4591 if (! aarch64_can_relax_tls (input_bfd, info, bfd_r_type, h, r_symndx))
4594 return aarch64_tls_transition_without_check (bfd_r_type, h);
4597 /* Return the base VMA address which should be subtracted from real addresses
4598 when resolving R_AARCH64_TLS_DTPREL relocation. */
4601 dtpoff_base (struct bfd_link_info *info)
4603 /* If tls_sec is NULL, we should have signalled an error already. */
4604 BFD_ASSERT (elf_hash_table (info)->tls_sec != NULL);
4605 return elf_hash_table (info)->tls_sec->vma;
4608 /* Return the base VMA address which should be subtracted from real addresses
4609 when resolving R_AARCH64_TLS_GOTTPREL64 relocations. */
4612 tpoff_base (struct bfd_link_info *info)
4614 struct elf_link_hash_table *htab = elf_hash_table (info);
4616 /* If tls_sec is NULL, we should have signalled an error already. */
4617 BFD_ASSERT (htab->tls_sec != NULL);
4619 bfd_vma base = align_power ((bfd_vma) TCB_SIZE,
4620 htab->tls_sec->alignment_power);
4621 return htab->tls_sec->vma - base;
4625 symbol_got_offset_ref (bfd *input_bfd, struct elf_link_hash_entry *h,
4626 unsigned long r_symndx)
4628 /* Calculate the address of the GOT entry for symbol
4629 referred to in h. */
4631 return &h->got.offset;
4635 struct elf_aarch64_local_symbol *l;
4637 l = elf_aarch64_locals (input_bfd);
4638 return &l[r_symndx].got_offset;
4643 symbol_got_offset_mark (bfd *input_bfd, struct elf_link_hash_entry *h,
4644 unsigned long r_symndx)
4647 p = symbol_got_offset_ref (input_bfd, h, r_symndx);
4652 symbol_got_offset_mark_p (bfd *input_bfd, struct elf_link_hash_entry *h,
4653 unsigned long r_symndx)
4656 value = * symbol_got_offset_ref (input_bfd, h, r_symndx);
4661 symbol_got_offset (bfd *input_bfd, struct elf_link_hash_entry *h,
4662 unsigned long r_symndx)
4665 value = * symbol_got_offset_ref (input_bfd, h, r_symndx);
4671 symbol_tlsdesc_got_offset_ref (bfd *input_bfd, struct elf_link_hash_entry *h,
4672 unsigned long r_symndx)
4674 /* Calculate the address of the GOT entry for symbol
4675 referred to in h. */
4678 struct elf_aarch64_link_hash_entry *eh;
4679 eh = (struct elf_aarch64_link_hash_entry *) h;
4680 return &eh->tlsdesc_got_jump_table_offset;
4685 struct elf_aarch64_local_symbol *l;
4687 l = elf_aarch64_locals (input_bfd);
4688 return &l[r_symndx].tlsdesc_got_jump_table_offset;
4693 symbol_tlsdesc_got_offset_mark (bfd *input_bfd, struct elf_link_hash_entry *h,
4694 unsigned long r_symndx)
4697 p = symbol_tlsdesc_got_offset_ref (input_bfd, h, r_symndx);
4702 symbol_tlsdesc_got_offset_mark_p (bfd *input_bfd,
4703 struct elf_link_hash_entry *h,
4704 unsigned long r_symndx)
4707 value = * symbol_tlsdesc_got_offset_ref (input_bfd, h, r_symndx);
4712 symbol_tlsdesc_got_offset (bfd *input_bfd, struct elf_link_hash_entry *h,
4713 unsigned long r_symndx)
4716 value = * symbol_tlsdesc_got_offset_ref (input_bfd, h, r_symndx);
4721 /* Data for make_branch_to_erratum_835769_stub(). */
4723 struct erratum_835769_branch_to_stub_data
4725 struct bfd_link_info *info;
4726 asection *output_section;
4730 /* Helper to insert branches to erratum 835769 stubs in the right
4731 places for a particular section. */
4734 make_branch_to_erratum_835769_stub (struct bfd_hash_entry *gen_entry,
4737 struct elf_aarch64_stub_hash_entry *stub_entry;
4738 struct erratum_835769_branch_to_stub_data *data;
4740 unsigned long branch_insn = 0;
4741 bfd_vma veneered_insn_loc, veneer_entry_loc;
4742 bfd_signed_vma branch_offset;
4743 unsigned int target;
4746 stub_entry = (struct elf_aarch64_stub_hash_entry *) gen_entry;
4747 data = (struct erratum_835769_branch_to_stub_data *) in_arg;
4749 if (stub_entry->target_section != data->output_section
4750 || stub_entry->stub_type != aarch64_stub_erratum_835769_veneer)
4753 contents = data->contents;
4754 veneered_insn_loc = stub_entry->target_section->output_section->vma
4755 + stub_entry->target_section->output_offset
4756 + stub_entry->target_value;
4757 veneer_entry_loc = stub_entry->stub_sec->output_section->vma
4758 + stub_entry->stub_sec->output_offset
4759 + stub_entry->stub_offset;
4760 branch_offset = veneer_entry_loc - veneered_insn_loc;
4762 abfd = stub_entry->target_section->owner;
4763 if (!aarch64_valid_branch_p (veneer_entry_loc, veneered_insn_loc))
4764 (*_bfd_error_handler)
4765 (_("%B: error: Erratum 835769 stub out "
4766 "of range (input file too large)"), abfd);
4768 target = stub_entry->target_value;
4769 branch_insn = 0x14000000;
4770 branch_offset >>= 2;
4771 branch_offset &= 0x3ffffff;
4772 branch_insn |= branch_offset;
4773 bfd_putl32 (branch_insn, &contents[target]);
4780 _bfd_aarch64_erratum_843419_branch_to_stub (struct bfd_hash_entry *gen_entry,
4783 struct elf_aarch64_stub_hash_entry *stub_entry
4784 = (struct elf_aarch64_stub_hash_entry *) gen_entry;
4785 struct erratum_835769_branch_to_stub_data *data
4786 = (struct erratum_835769_branch_to_stub_data *) in_arg;
4787 struct bfd_link_info *info;
4788 struct elf_aarch64_link_hash_table *htab;
4796 contents = data->contents;
4797 section = data->output_section;
4799 htab = elf_aarch64_hash_table (info);
4801 if (stub_entry->target_section != section
4802 || stub_entry->stub_type != aarch64_stub_erratum_843419_veneer)
4805 insn = bfd_getl32 (contents + stub_entry->target_value);
4807 stub_entry->stub_sec->contents + stub_entry->stub_offset);
4809 place = (section->output_section->vma + section->output_offset
4810 + stub_entry->adrp_offset);
4811 insn = bfd_getl32 (contents + stub_entry->adrp_offset);
4813 if ((insn & AARCH64_ADRP_OP_MASK) != AARCH64_ADRP_OP)
4816 bfd_signed_vma imm =
4817 (_bfd_aarch64_sign_extend
4818 ((bfd_vma) _bfd_aarch64_decode_adrp_imm (insn) << 12, 33)
4821 if (htab->fix_erratum_843419_adr
4822 && (imm >= AARCH64_MIN_ADRP_IMM && imm <= AARCH64_MAX_ADRP_IMM))
4824 insn = (_bfd_aarch64_reencode_adr_imm (AARCH64_ADR_OP, imm)
4825 | AARCH64_RT (insn));
4826 bfd_putl32 (insn, contents + stub_entry->adrp_offset);
4830 bfd_vma veneered_insn_loc;
4831 bfd_vma veneer_entry_loc;
4832 bfd_signed_vma branch_offset;
4833 uint32_t branch_insn;
4835 veneered_insn_loc = stub_entry->target_section->output_section->vma
4836 + stub_entry->target_section->output_offset
4837 + stub_entry->target_value;
4838 veneer_entry_loc = stub_entry->stub_sec->output_section->vma
4839 + stub_entry->stub_sec->output_offset
4840 + stub_entry->stub_offset;
4841 branch_offset = veneer_entry_loc - veneered_insn_loc;
4843 abfd = stub_entry->target_section->owner;
4844 if (!aarch64_valid_branch_p (veneer_entry_loc, veneered_insn_loc))
4845 (*_bfd_error_handler)
4846 (_("%B: error: Erratum 843419 stub out "
4847 "of range (input file too large)"), abfd);
4849 branch_insn = 0x14000000;
4850 branch_offset >>= 2;
4851 branch_offset &= 0x3ffffff;
4852 branch_insn |= branch_offset;
4853 bfd_putl32 (branch_insn, contents + stub_entry->target_value);
4860 elfNN_aarch64_write_section (bfd *output_bfd ATTRIBUTE_UNUSED,
4861 struct bfd_link_info *link_info,
4866 struct elf_aarch64_link_hash_table *globals =
4867 elf_aarch64_hash_table (link_info);
4869 if (globals == NULL)
4872 /* Fix code to point to erratum 835769 stubs. */
4873 if (globals->fix_erratum_835769)
4875 struct erratum_835769_branch_to_stub_data data;
4877 data.info = link_info;
4878 data.output_section = sec;
4879 data.contents = contents;
4880 bfd_hash_traverse (&globals->stub_hash_table,
4881 make_branch_to_erratum_835769_stub, &data);
4884 if (globals->fix_erratum_843419)
4886 struct erratum_835769_branch_to_stub_data data;
4888 data.info = link_info;
4889 data.output_section = sec;
4890 data.contents = contents;
4891 bfd_hash_traverse (&globals->stub_hash_table,
4892 _bfd_aarch64_erratum_843419_branch_to_stub, &data);
4898 /* Perform a relocation as part of a final link. The input relocation type
4899 should be TLS relaxed. */
4901 static bfd_reloc_status_type
4902 elfNN_aarch64_final_link_relocate (reloc_howto_type *howto,
4905 asection *input_section,
4907 Elf_Internal_Rela *rel,
4909 struct bfd_link_info *info,
4911 struct elf_link_hash_entry *h,
4912 bfd_boolean *unresolved_reloc_p,
4913 bfd_boolean save_addend,
4914 bfd_vma *saved_addend,
4915 Elf_Internal_Sym *sym)
4917 Elf_Internal_Shdr *symtab_hdr;
4918 unsigned int r_type = howto->type;
4919 bfd_reloc_code_real_type bfd_r_type
4920 = elfNN_aarch64_bfd_reloc_from_howto (howto);
4921 unsigned long r_symndx;
4922 bfd_byte *hit_data = contents + rel->r_offset;
4924 bfd_signed_vma signed_addend;
4925 struct elf_aarch64_link_hash_table *globals;
4926 bfd_boolean weak_undef_p;
4929 globals = elf_aarch64_hash_table (info);
4931 symtab_hdr = &elf_symtab_hdr (input_bfd);
4933 BFD_ASSERT (is_aarch64_elf (input_bfd));
4935 r_symndx = ELFNN_R_SYM (rel->r_info);
4937 place = input_section->output_section->vma
4938 + input_section->output_offset + rel->r_offset;
4940 /* Get addend, accumulating the addend for consecutive relocs
4941 which refer to the same offset. */
4942 signed_addend = saved_addend ? *saved_addend : 0;
4943 signed_addend += rel->r_addend;
4945 weak_undef_p = (h ? h->root.type == bfd_link_hash_undefweak
4946 : bfd_is_und_section (sym_sec));
4948 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle
4949 it here if it is defined in a non-shared object. */
4951 && h->type == STT_GNU_IFUNC
4958 if ((input_section->flags & SEC_ALLOC) == 0
4959 || h->plt.offset == (bfd_vma) -1)
4962 /* STT_GNU_IFUNC symbol must go through PLT. */
4963 plt = globals->root.splt ? globals->root.splt : globals->root.iplt;
4964 value = (plt->output_section->vma + plt->output_offset + h->plt.offset);
4969 if (h->root.root.string)
4970 name = h->root.root.string;
4972 name = bfd_elf_sym_name (input_bfd, symtab_hdr, sym,
4974 (*_bfd_error_handler)
4975 (_("%B: relocation %s against STT_GNU_IFUNC "
4976 "symbol `%s' isn't handled by %s"), input_bfd,
4977 howto->name, name, __FUNCTION__);
4978 bfd_set_error (bfd_error_bad_value);
4981 case BFD_RELOC_AARCH64_NN:
4982 if (rel->r_addend != 0)
4984 if (h->root.root.string)
4985 name = h->root.root.string;
4987 name = bfd_elf_sym_name (input_bfd, symtab_hdr,
4989 (*_bfd_error_handler)
4990 (_("%B: relocation %s against STT_GNU_IFUNC "
4991 "symbol `%s' has non-zero addend: %d"),
4992 input_bfd, howto->name, name, rel->r_addend);
4993 bfd_set_error (bfd_error_bad_value);
4997 /* Generate dynamic relocation only when there is a
4998 non-GOT reference in a shared object. */
4999 if (bfd_link_pic (info) && h->non_got_ref)
5001 Elf_Internal_Rela outrel;
5004 /* Need a dynamic relocation to get the real function
5006 outrel.r_offset = _bfd_elf_section_offset (output_bfd,
5010 if (outrel.r_offset == (bfd_vma) -1
5011 || outrel.r_offset == (bfd_vma) -2)
5014 outrel.r_offset += (input_section->output_section->vma
5015 + input_section->output_offset);
5017 if (h->dynindx == -1
5019 || bfd_link_executable (info))
5021 /* This symbol is resolved locally. */
5022 outrel.r_info = ELFNN_R_INFO (0, AARCH64_R (IRELATIVE));
5023 outrel.r_addend = (h->root.u.def.value
5024 + h->root.u.def.section->output_section->vma
5025 + h->root.u.def.section->output_offset);
5029 outrel.r_info = ELFNN_R_INFO (h->dynindx, r_type);
5030 outrel.r_addend = 0;
5033 sreloc = globals->root.irelifunc;
5034 elf_append_rela (output_bfd, sreloc, &outrel);
5036 /* If this reloc is against an external symbol, we
5037 do not want to fiddle with the addend. Otherwise,
5038 we need to include the symbol value so that it
5039 becomes an addend for the dynamic reloc. For an
5040 internal symbol, we have updated addend. */
5041 return bfd_reloc_ok;
5044 case BFD_RELOC_AARCH64_CALL26:
5045 case BFD_RELOC_AARCH64_JUMP26:
5046 value = _bfd_aarch64_elf_resolve_relocation (bfd_r_type, place, value,
5049 return _bfd_aarch64_elf_put_addend (input_bfd, hit_data, bfd_r_type,
5051 case BFD_RELOC_AARCH64_ADR_GOT_PAGE:
5052 case BFD_RELOC_AARCH64_GOT_LD_PREL19:
5053 case BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14:
5054 case BFD_RELOC_AARCH64_LD32_GOT_LO12_NC:
5055 case BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15:
5056 case BFD_RELOC_AARCH64_MOVW_GOTOFF_G0_NC:
5057 case BFD_RELOC_AARCH64_MOVW_GOTOFF_G1:
5058 case BFD_RELOC_AARCH64_LD64_GOTOFF_LO15:
5059 case BFD_RELOC_AARCH64_LD64_GOT_LO12_NC:
5060 base_got = globals->root.sgot;
5061 off = h->got.offset;
5063 if (base_got == NULL)
5066 if (off == (bfd_vma) -1)
5070 /* We can't use h->got.offset here to save state, or
5071 even just remember the offset, as finish_dynamic_symbol
5072 would use that as offset into .got. */
5074 if (globals->root.splt != NULL)
5076 plt_index = ((h->plt.offset - globals->plt_header_size) /
5077 globals->plt_entry_size);
5078 off = (plt_index + 3) * GOT_ENTRY_SIZE;
5079 base_got = globals->root.sgotplt;
5083 plt_index = h->plt.offset / globals->plt_entry_size;
5084 off = plt_index * GOT_ENTRY_SIZE;
5085 base_got = globals->root.igotplt;
5088 if (h->dynindx == -1
5092 /* This references the local definition. We must
5093 initialize this entry in the global offset table.
5094 Since the offset must always be a multiple of 8,
5095 we use the least significant bit to record
5096 whether we have initialized it already.
5098 When doing a dynamic link, we create a .rela.got
5099 relocation entry to initialize the value. This
5100 is done in the finish_dynamic_symbol routine. */
5105 bfd_put_NN (output_bfd, value,
5106 base_got->contents + off);
5107 /* Note that this is harmless as -1 | 1 still is -1. */
5111 value = (base_got->output_section->vma
5112 + base_got->output_offset + off);
5115 value = aarch64_calculate_got_entry_vma (h, globals, info,
5117 unresolved_reloc_p);
5121 case BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14:
5122 case BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15:
5123 addend = (globals->root.sgot->output_section->vma
5124 + globals->root.sgot->output_offset);
5126 case BFD_RELOC_AARCH64_MOVW_GOTOFF_G0_NC:
5127 case BFD_RELOC_AARCH64_MOVW_GOTOFF_G1:
5128 case BFD_RELOC_AARCH64_LD64_GOTOFF_LO15:
5129 value = (value - globals->root.sgot->output_section->vma
5130 - globals->root.sgot->output_offset);
5135 value = _bfd_aarch64_elf_resolve_relocation (bfd_r_type, place, value,
5136 addend, weak_undef_p);
5137 return _bfd_aarch64_elf_put_addend (input_bfd, hit_data, bfd_r_type, howto, value);
5138 case BFD_RELOC_AARCH64_ADD_LO12:
5139 case BFD_RELOC_AARCH64_ADR_HI21_PCREL:
5146 case BFD_RELOC_AARCH64_NONE:
5147 case BFD_RELOC_AARCH64_TLSDESC_ADD:
5148 case BFD_RELOC_AARCH64_TLSDESC_CALL:
5149 case BFD_RELOC_AARCH64_TLSDESC_LDR:
5150 *unresolved_reloc_p = FALSE;
5151 return bfd_reloc_ok;
5153 case BFD_RELOC_AARCH64_NN:
5155 /* When generating a shared object or relocatable executable, these
5156 relocations are copied into the output file to be resolved at
5158 if (((bfd_link_pic (info) == TRUE)
5159 || globals->root.is_relocatable_executable)
5160 && (input_section->flags & SEC_ALLOC)
5162 || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
5163 || h->root.type != bfd_link_hash_undefweak))
5165 Elf_Internal_Rela outrel;
5167 bfd_boolean skip, relocate;
5170 *unresolved_reloc_p = FALSE;
5175 outrel.r_addend = signed_addend;
5177 _bfd_elf_section_offset (output_bfd, info, input_section,
5179 if (outrel.r_offset == (bfd_vma) - 1)
5181 else if (outrel.r_offset == (bfd_vma) - 2)
5187 outrel.r_offset += (input_section->output_section->vma
5188 + input_section->output_offset);
5191 memset (&outrel, 0, sizeof outrel);
5194 && (!bfd_link_pic (info)
5195 || !SYMBOLIC_BIND (info, h)
5196 || !h->def_regular))
5197 outrel.r_info = ELFNN_R_INFO (h->dynindx, r_type);
5202 /* On SVR4-ish systems, the dynamic loader cannot
5203 relocate the text and data segments independently,
5204 so the symbol does not matter. */
5206 relocate = globals->no_apply_dynamic_relocs ? FALSE : TRUE;
5207 outrel.r_info = ELFNN_R_INFO (symbol, AARCH64_R (RELATIVE));
5208 outrel.r_addend += value;
5211 sreloc = elf_section_data (input_section)->sreloc;
5212 if (sreloc == NULL || sreloc->contents == NULL)
5213 return bfd_reloc_notsupported;
5215 loc = sreloc->contents + sreloc->reloc_count++ * RELOC_SIZE (globals);
5216 bfd_elfNN_swap_reloca_out (output_bfd, &outrel, loc);
5218 if (sreloc->reloc_count * RELOC_SIZE (globals) > sreloc->size)
5220 /* Sanity to check that we have previously allocated
5221 sufficient space in the relocation section for the
5222 number of relocations we actually want to emit. */
5226 /* If this reloc is against an external symbol, we do not want to
5227 fiddle with the addend. Otherwise, we need to include the symbol
5228 value so that it becomes an addend for the dynamic reloc. */
5230 return bfd_reloc_ok;
5232 return _bfd_final_link_relocate (howto, input_bfd, input_section,
5233 contents, rel->r_offset, value,
5237 value += signed_addend;
5240 case BFD_RELOC_AARCH64_CALL26:
5241 case BFD_RELOC_AARCH64_JUMP26:
5243 asection *splt = globals->root.splt;
5244 bfd_boolean via_plt_p =
5245 splt != NULL && h != NULL && h->plt.offset != (bfd_vma) - 1;
5247 /* A call to an undefined weak symbol is converted to a jump to
5248 the next instruction unless a PLT entry will be created.
5249 The jump to the next instruction is optimized as a NOP.
5250 Do the same for local undefined symbols. */
5251 if (weak_undef_p && ! via_plt_p)
5253 bfd_putl32 (INSN_NOP, hit_data);
5254 return bfd_reloc_ok;
5257 /* If the call goes through a PLT entry, make sure to
5258 check distance to the right destination address. */
5260 value = (splt->output_section->vma
5261 + splt->output_offset + h->plt.offset);
5263 /* Check if a stub has to be inserted because the destination
5265 struct elf_aarch64_stub_hash_entry *stub_entry = NULL;
5267 /* If the branch destination is directed to plt stub, "value" will be
5268 the final destination, otherwise we should plus signed_addend, it may
5269 contain non-zero value, for example call to local function symbol
5270 which are turned into "sec_sym + sec_off", and sec_off is kept in
5272 if (! aarch64_valid_branch_p (via_plt_p ? value : value + signed_addend,
5274 /* The target is out of reach, so redirect the branch to
5275 the local stub for this function. */
5276 stub_entry = elfNN_aarch64_get_stub_entry (input_section, sym_sec, h,
5278 if (stub_entry != NULL)
5280 value = (stub_entry->stub_offset
5281 + stub_entry->stub_sec->output_offset
5282 + stub_entry->stub_sec->output_section->vma);
5284 /* We have redirected the destination to stub entry address,
5285 so ignore any addend record in the original rela entry. */
5289 value = _bfd_aarch64_elf_resolve_relocation (bfd_r_type, place, value,
5290 signed_addend, weak_undef_p);
5291 *unresolved_reloc_p = FALSE;
5294 case BFD_RELOC_AARCH64_16_PCREL:
5295 case BFD_RELOC_AARCH64_32_PCREL:
5296 case BFD_RELOC_AARCH64_64_PCREL:
5297 case BFD_RELOC_AARCH64_ADR_HI21_NC_PCREL:
5298 case BFD_RELOC_AARCH64_ADR_HI21_PCREL:
5299 case BFD_RELOC_AARCH64_ADR_LO21_PCREL:
5300 case BFD_RELOC_AARCH64_LD_LO19_PCREL:
5301 if (bfd_link_pic (info)
5302 && (input_section->flags & SEC_ALLOC) != 0
5303 && (input_section->flags & SEC_READONLY) != 0
5307 int howto_index = bfd_r_type - BFD_RELOC_AARCH64_RELOC_START;
5309 (*_bfd_error_handler)
5310 (_("%B: relocation %s against external symbol `%s' can not be used"
5311 " when making a shared object; recompile with -fPIC"),
5312 input_bfd, elfNN_aarch64_howto_table[howto_index].name,
5313 h->root.root.string);
5314 bfd_set_error (bfd_error_bad_value);
5318 case BFD_RELOC_AARCH64_16:
5320 case BFD_RELOC_AARCH64_32:
5322 case BFD_RELOC_AARCH64_ADD_LO12:
5323 case BFD_RELOC_AARCH64_BRANCH19:
5324 case BFD_RELOC_AARCH64_LDST128_LO12:
5325 case BFD_RELOC_AARCH64_LDST16_LO12:
5326 case BFD_RELOC_AARCH64_LDST32_LO12:
5327 case BFD_RELOC_AARCH64_LDST64_LO12:
5328 case BFD_RELOC_AARCH64_LDST8_LO12:
5329 case BFD_RELOC_AARCH64_MOVW_G0:
5330 case BFD_RELOC_AARCH64_MOVW_G0_NC:
5331 case BFD_RELOC_AARCH64_MOVW_G0_S:
5332 case BFD_RELOC_AARCH64_MOVW_G1:
5333 case BFD_RELOC_AARCH64_MOVW_G1_NC:
5334 case BFD_RELOC_AARCH64_MOVW_G1_S:
5335 case BFD_RELOC_AARCH64_MOVW_G2:
5336 case BFD_RELOC_AARCH64_MOVW_G2_NC:
5337 case BFD_RELOC_AARCH64_MOVW_G2_S:
5338 case BFD_RELOC_AARCH64_MOVW_G3:
5339 case BFD_RELOC_AARCH64_TSTBR14:
5340 value = _bfd_aarch64_elf_resolve_relocation (bfd_r_type, place, value,
5341 signed_addend, weak_undef_p);
5344 case BFD_RELOC_AARCH64_ADR_GOT_PAGE:
5345 case BFD_RELOC_AARCH64_GOT_LD_PREL19:
5346 case BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14:
5347 case BFD_RELOC_AARCH64_LD32_GOT_LO12_NC:
5348 case BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15:
5349 case BFD_RELOC_AARCH64_LD64_GOT_LO12_NC:
5350 if (globals->root.sgot == NULL)
5351 BFD_ASSERT (h != NULL);
5356 value = aarch64_calculate_got_entry_vma (h, globals, info, value,
5358 unresolved_reloc_p);
5359 if (bfd_r_type == BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15
5360 || bfd_r_type == BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14)
5361 addend = (globals->root.sgot->output_section->vma
5362 + globals->root.sgot->output_offset);
5363 value = _bfd_aarch64_elf_resolve_relocation (bfd_r_type, place, value,
5364 addend, weak_undef_p);
5369 struct elf_aarch64_local_symbol *locals
5370 = elf_aarch64_locals (input_bfd);
5374 int howto_index = bfd_r_type - BFD_RELOC_AARCH64_RELOC_START;
5375 (*_bfd_error_handler)
5376 (_("%B: Local symbol descriptor table be NULL when applying "
5377 "relocation %s against local symbol"),
5378 input_bfd, elfNN_aarch64_howto_table[howto_index].name);
5382 off = symbol_got_offset (input_bfd, h, r_symndx);
5383 base_got = globals->root.sgot;
5384 bfd_vma got_entry_addr = (base_got->output_section->vma
5385 + base_got->output_offset + off);
5387 if (!symbol_got_offset_mark_p (input_bfd, h, r_symndx))
5389 bfd_put_64 (output_bfd, value, base_got->contents + off);
5391 if (bfd_link_pic (info))
5394 Elf_Internal_Rela outrel;
5396 /* For local symbol, we have done absolute relocation in static
5397 linking stageh. While for share library, we need to update
5398 the content of GOT entry according to the share objects
5399 loading base address. So we need to generate a
5400 R_AARCH64_RELATIVE reloc for dynamic linker. */
5401 s = globals->root.srelgot;
5405 outrel.r_offset = got_entry_addr;
5406 outrel.r_info = ELFNN_R_INFO (0, AARCH64_R (RELATIVE));
5407 outrel.r_addend = value;
5408 elf_append_rela (output_bfd, s, &outrel);
5411 symbol_got_offset_mark (input_bfd, h, r_symndx);
5414 /* Update the relocation value to GOT entry addr as we have transformed
5415 the direct data access into indirect data access through GOT. */
5416 value = got_entry_addr;
5418 if (bfd_r_type == BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15
5419 || bfd_r_type == BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14)
5420 addend = base_got->output_section->vma + base_got->output_offset;
5422 value = _bfd_aarch64_elf_resolve_relocation (bfd_r_type, place, value,
5423 addend, weak_undef_p);
5428 case BFD_RELOC_AARCH64_LD64_GOTOFF_LO15:
5429 case BFD_RELOC_AARCH64_MOVW_GOTOFF_G0_NC:
5430 case BFD_RELOC_AARCH64_MOVW_GOTOFF_G1:
5432 value = aarch64_calculate_got_entry_vma (h, globals, info, value,
5434 unresolved_reloc_p);
5437 struct elf_aarch64_local_symbol *locals
5438 = elf_aarch64_locals (input_bfd);
5442 int howto_index = bfd_r_type - BFD_RELOC_AARCH64_RELOC_START;
5443 (*_bfd_error_handler)
5444 (_("%B: Local symbol descriptor table be NULL when applying "
5445 "relocation %s against local symbol"),
5446 input_bfd, elfNN_aarch64_howto_table[howto_index].name);
5450 off = symbol_got_offset (input_bfd, h, r_symndx);
5451 base_got = globals->root.sgot;
5452 if (base_got == NULL)
5455 bfd_vma got_entry_addr = (base_got->output_section->vma
5456 + base_got->output_offset + off);
5458 if (!symbol_got_offset_mark_p (input_bfd, h, r_symndx))
5460 bfd_put_64 (output_bfd, value, base_got->contents + off);
5462 if (bfd_link_pic (info))
5465 Elf_Internal_Rela outrel;
5467 /* For local symbol, we have done absolute relocation in static
5468 linking stage. While for share library, we need to update
5469 the content of GOT entry according to the share objects
5470 loading base address. So we need to generate a
5471 R_AARCH64_RELATIVE reloc for dynamic linker. */
5472 s = globals->root.srelgot;
5476 outrel.r_offset = got_entry_addr;
5477 outrel.r_info = ELFNN_R_INFO (0, AARCH64_R (RELATIVE));
5478 outrel.r_addend = value;
5479 elf_append_rela (output_bfd, s, &outrel);
5482 symbol_got_offset_mark (input_bfd, h, r_symndx);
5486 /* Update the relocation value to GOT entry addr as we have transformed
5487 the direct data access into indirect data access through GOT. */
5488 value = symbol_got_offset (input_bfd, h, r_symndx);
5489 value = _bfd_aarch64_elf_resolve_relocation (bfd_r_type, place, value,
5491 *unresolved_reloc_p = FALSE;
5494 case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC:
5495 case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21:
5496 case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21:
5497 case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21:
5498 case BFD_RELOC_AARCH64_TLSIE_LD32_GOTTPREL_LO12_NC:
5499 case BFD_RELOC_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC:
5500 case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19:
5501 case BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC:
5502 case BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21:
5503 case BFD_RELOC_AARCH64_TLSLD_ADR_PREL21:
5504 if (globals->root.sgot == NULL)
5505 return bfd_reloc_notsupported;
5507 value = (symbol_got_offset (input_bfd, h, r_symndx)
5508 + globals->root.sgot->output_section->vma
5509 + globals->root.sgot->output_offset);
5511 value = _bfd_aarch64_elf_resolve_relocation (bfd_r_type, place, value,
5513 *unresolved_reloc_p = FALSE;
5516 case BFD_RELOC_AARCH64_TLSGD_MOVW_G0_NC:
5517 case BFD_RELOC_AARCH64_TLSGD_MOVW_G1:
5518 case BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G0_NC:
5519 case BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G1:
5520 if (globals->root.sgot == NULL)
5521 return bfd_reloc_notsupported;
5523 value = symbol_got_offset (input_bfd, h, r_symndx);
5524 value = _bfd_aarch64_elf_resolve_relocation (bfd_r_type, place, value,
5526 *unresolved_reloc_p = FALSE;
5529 case BFD_RELOC_AARCH64_TLSLD_ADD_DTPREL_HI12:
5530 case BFD_RELOC_AARCH64_TLSLD_ADD_DTPREL_LO12:
5531 case BFD_RELOC_AARCH64_TLSLD_ADD_DTPREL_LO12_NC:
5532 case BFD_RELOC_AARCH64_TLSLD_LDST16_DTPREL_LO12:
5533 case BFD_RELOC_AARCH64_TLSLD_LDST16_DTPREL_LO12_NC:
5534 case BFD_RELOC_AARCH64_TLSLD_LDST32_DTPREL_LO12:
5535 case BFD_RELOC_AARCH64_TLSLD_LDST32_DTPREL_LO12_NC:
5536 case BFD_RELOC_AARCH64_TLSLD_LDST64_DTPREL_LO12:
5537 case BFD_RELOC_AARCH64_TLSLD_LDST64_DTPREL_LO12_NC:
5538 case BFD_RELOC_AARCH64_TLSLD_LDST8_DTPREL_LO12:
5539 case BFD_RELOC_AARCH64_TLSLD_LDST8_DTPREL_LO12_NC:
5540 case BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G0:
5541 case BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G0_NC:
5542 case BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G1:
5543 case BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G1_NC:
5544 case BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G2:
5545 value = _bfd_aarch64_elf_resolve_relocation (bfd_r_type, place, value,
5546 signed_addend - dtpoff_base (info),
5550 case BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_HI12:
5551 case BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_LO12:
5552 case BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_LO12_NC:
5553 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0:
5554 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC:
5555 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1:
5556 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1_NC:
5557 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G2:
5558 value = _bfd_aarch64_elf_resolve_relocation (bfd_r_type, place, value,
5559 signed_addend - tpoff_base (info),
5561 *unresolved_reloc_p = FALSE;
5564 case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12_NC:
5565 case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21:
5566 case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21:
5567 case BFD_RELOC_AARCH64_TLSDESC_LD32_LO12_NC:
5568 case BFD_RELOC_AARCH64_TLSDESC_LD64_LO12_NC:
5569 case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19:
5570 if (globals->root.sgot == NULL)
5571 return bfd_reloc_notsupported;
5572 value = (symbol_tlsdesc_got_offset (input_bfd, h, r_symndx)
5573 + globals->root.sgotplt->output_section->vma
5574 + globals->root.sgotplt->output_offset
5575 + globals->sgotplt_jump_table_size);
5577 value = _bfd_aarch64_elf_resolve_relocation (bfd_r_type, place, value,
5579 *unresolved_reloc_p = FALSE;
5582 case BFD_RELOC_AARCH64_TLSDESC_OFF_G0_NC:
5583 case BFD_RELOC_AARCH64_TLSDESC_OFF_G1:
5584 if (globals->root.sgot == NULL)
5585 return bfd_reloc_notsupported;
5587 value = (symbol_tlsdesc_got_offset (input_bfd, h, r_symndx)
5588 + globals->root.sgotplt->output_section->vma
5589 + globals->root.sgotplt->output_offset
5590 + globals->sgotplt_jump_table_size);
5592 value -= (globals->root.sgot->output_section->vma
5593 + globals->root.sgot->output_offset);
5595 value = _bfd_aarch64_elf_resolve_relocation (bfd_r_type, place, value,
5597 *unresolved_reloc_p = FALSE;
5601 return bfd_reloc_notsupported;
5605 *saved_addend = value;
5607 /* Only apply the final relocation in a sequence. */
5609 return bfd_reloc_continue;
5611 return _bfd_aarch64_elf_put_addend (input_bfd, hit_data, bfd_r_type,
5615 /* Handle TLS relaxations. Relaxing is possible for symbols that use
5616 R_AARCH64_TLSDESC_ADR_{PAGE, LD64_LO12_NC, ADD_LO12_NC} during a static
5619 Return bfd_reloc_ok if we're done, bfd_reloc_continue if the caller
5620 is to then call final_link_relocate. Return other values in the
5623 static bfd_reloc_status_type
5624 elfNN_aarch64_tls_relax (struct elf_aarch64_link_hash_table *globals,
5625 bfd *input_bfd, bfd_byte *contents,
5626 Elf_Internal_Rela *rel, struct elf_link_hash_entry *h)
5628 bfd_boolean is_local = h == NULL;
5629 unsigned int r_type = ELFNN_R_TYPE (rel->r_info);
5632 BFD_ASSERT (globals && input_bfd && contents && rel);
5634 switch (elfNN_aarch64_bfd_reloc_from_type (r_type))
5636 case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21:
5637 case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21:
5640 /* GD->LE relaxation:
5641 adrp x0, :tlsgd:var => movz x0, :tprel_g1:var
5643 adrp x0, :tlsdesc:var => movz x0, :tprel_g1:var
5645 bfd_putl32 (0xd2a00000, contents + rel->r_offset);
5646 return bfd_reloc_continue;
5650 /* GD->IE relaxation:
5651 adrp x0, :tlsgd:var => adrp x0, :gottprel:var
5653 adrp x0, :tlsdesc:var => adrp x0, :gottprel:var
5655 return bfd_reloc_continue;
5658 case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21:
5662 case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19:
5665 /* Tiny TLSDESC->LE relaxation:
5666 ldr x1, :tlsdesc:var => movz x0, #:tprel_g1:var
5667 adr x0, :tlsdesc:var => movk x0, #:tprel_g0_nc:var
5671 BFD_ASSERT (ELFNN_R_TYPE (rel[1].r_info) == AARCH64_R (TLSDESC_ADR_PREL21));
5672 BFD_ASSERT (ELFNN_R_TYPE (rel[2].r_info) == AARCH64_R (TLSDESC_CALL));
5674 rel[1].r_info = ELFNN_R_INFO (ELFNN_R_SYM (rel->r_info),
5675 AARCH64_R (TLSLE_MOVW_TPREL_G0_NC));
5676 rel[2].r_info = ELFNN_R_INFO (STN_UNDEF, R_AARCH64_NONE);
5678 bfd_putl32 (0xd2a00000, contents + rel->r_offset);
5679 bfd_putl32 (0xf2800000, contents + rel->r_offset + 4);
5680 bfd_putl32 (INSN_NOP, contents + rel->r_offset + 8);
5681 return bfd_reloc_continue;
5685 /* Tiny TLSDESC->IE relaxation:
5686 ldr x1, :tlsdesc:var => ldr x0, :gottprel:var
5687 adr x0, :tlsdesc:var => nop
5691 BFD_ASSERT (ELFNN_R_TYPE (rel[1].r_info) == AARCH64_R (TLSDESC_ADR_PREL21));
5692 BFD_ASSERT (ELFNN_R_TYPE (rel[2].r_info) == AARCH64_R (TLSDESC_CALL));
5694 rel[1].r_info = ELFNN_R_INFO (STN_UNDEF, R_AARCH64_NONE);
5695 rel[2].r_info = ELFNN_R_INFO (STN_UNDEF, R_AARCH64_NONE);
5697 bfd_putl32 (0x58000000, contents + rel->r_offset);
5698 bfd_putl32 (INSN_NOP, contents + rel->r_offset + 4);
5699 bfd_putl32 (INSN_NOP, contents + rel->r_offset + 8);
5700 return bfd_reloc_continue;
5703 case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21:
5706 /* Tiny GD->LE relaxation:
5707 adr x0, :tlsgd:var => mrs x1, tpidr_el0
5708 bl __tls_get_addr => add x0, x1, #:tprel_hi12:x, lsl #12
5709 nop => add x0, x0, #:tprel_lo12_nc:x
5712 /* First kill the tls_get_addr reloc on the bl instruction. */
5713 BFD_ASSERT (rel->r_offset + 4 == rel[1].r_offset);
5715 bfd_putl32 (0xd53bd041, contents + rel->r_offset + 0);
5716 bfd_putl32 (0x91400020, contents + rel->r_offset + 4);
5717 bfd_putl32 (0x91000000, contents + rel->r_offset + 8);
5719 rel[1].r_info = ELFNN_R_INFO (ELFNN_R_SYM (rel->r_info),
5720 AARCH64_R (TLSLE_ADD_TPREL_LO12_NC));
5721 rel[1].r_offset = rel->r_offset + 8;
5723 /* Move the current relocation to the second instruction in
5726 rel->r_info = ELFNN_R_INFO (ELFNN_R_SYM (rel->r_info),
5727 AARCH64_R (TLSLE_ADD_TPREL_HI12));
5728 return bfd_reloc_continue;
5732 /* Tiny GD->IE relaxation:
5733 adr x0, :tlsgd:var => ldr x0, :gottprel:var
5734 bl __tls_get_addr => mrs x1, tpidr_el0
5735 nop => add x0, x0, x1
5738 /* First kill the tls_get_addr reloc on the bl instruction. */
5739 BFD_ASSERT (rel->r_offset + 4 == rel[1].r_offset);
5740 rel[1].r_info = ELFNN_R_INFO (STN_UNDEF, R_AARCH64_NONE);
5742 bfd_putl32 (0x58000000, contents + rel->r_offset);
5743 bfd_putl32 (0xd53bd041, contents + rel->r_offset + 4);
5744 bfd_putl32 (0x8b000020, contents + rel->r_offset + 8);
5745 return bfd_reloc_continue;
5749 case BFD_RELOC_AARCH64_TLSGD_MOVW_G1:
5750 BFD_ASSERT (ELFNN_R_TYPE (rel[1].r_info) == AARCH64_R (TLSGD_MOVW_G0_NC));
5751 BFD_ASSERT (rel->r_offset + 12 == rel[2].r_offset);
5752 BFD_ASSERT (ELFNN_R_TYPE (rel[2].r_info) == AARCH64_R (CALL26));
5756 /* Large GD->LE relaxation:
5757 movz x0, #:tlsgd_g1:var => movz x0, #:tprel_g2:var, lsl #32
5758 movk x0, #:tlsgd_g0_nc:var => movk x0, #:tprel_g1_nc:var, lsl #16
5759 add x0, gp, x0 => movk x0, #:tprel_g0_nc:var
5760 bl __tls_get_addr => mrs x1, tpidr_el0
5761 nop => add x0, x0, x1
5763 rel[2].r_info = ELFNN_R_INFO (ELFNN_R_SYM (rel->r_info),
5764 AARCH64_R (TLSLE_MOVW_TPREL_G0_NC));
5765 rel[2].r_offset = rel->r_offset + 8;
5767 bfd_putl32 (0xd2c00000, contents + rel->r_offset + 0);
5768 bfd_putl32 (0xf2a00000, contents + rel->r_offset + 4);
5769 bfd_putl32 (0xf2800000, contents + rel->r_offset + 8);
5770 bfd_putl32 (0xd53bd041, contents + rel->r_offset + 12);
5771 bfd_putl32 (0x8b000020, contents + rel->r_offset + 16);
5775 /* Large GD->IE relaxation:
5776 movz x0, #:tlsgd_g1:var => movz x0, #:gottprel_g1:var, lsl #16
5777 movk x0, #:tlsgd_g0_nc:var => movk x0, #:gottprel_g0_nc:var
5778 add x0, gp, x0 => ldr x0, [gp, x0]
5779 bl __tls_get_addr => mrs x1, tpidr_el0
5780 nop => add x0, x0, x1
5782 rel[2].r_info = ELFNN_R_INFO (STN_UNDEF, R_AARCH64_NONE);
5783 bfd_putl32 (0xd2a80000, contents + rel->r_offset + 0);
5784 bfd_putl32 (0x58000000, contents + rel->r_offset + 8);
5785 bfd_putl32 (0xd53bd041, contents + rel->r_offset + 12);
5786 bfd_putl32 (0x8b000020, contents + rel->r_offset + 16);
5788 return bfd_reloc_continue;
5790 case BFD_RELOC_AARCH64_TLSGD_MOVW_G0_NC:
5791 return bfd_reloc_continue;
5794 case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19:
5795 return bfd_reloc_continue;
5797 case BFD_RELOC_AARCH64_TLSDESC_LDNN_LO12_NC:
5800 /* GD->LE relaxation:
5801 ldr xd, [x0, #:tlsdesc_lo12:var] => movk x0, :tprel_g0_nc:var
5803 bfd_putl32 (0xf2800000, contents + rel->r_offset);
5804 return bfd_reloc_continue;
5808 /* GD->IE relaxation:
5809 ldr xd, [x0, #:tlsdesc_lo12:var] => ldr x0, [x0, #:gottprel_lo12:var]
5811 insn = bfd_getl32 (contents + rel->r_offset);
5813 bfd_putl32 (insn, contents + rel->r_offset);
5814 return bfd_reloc_continue;
5817 case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC:
5820 /* GD->LE relaxation
5821 add x0, #:tlsgd_lo12:var => movk x0, :tprel_g0_nc:var
5822 bl __tls_get_addr => mrs x1, tpidr_el0
5823 nop => add x0, x1, x0
5826 /* First kill the tls_get_addr reloc on the bl instruction. */
5827 BFD_ASSERT (rel->r_offset + 4 == rel[1].r_offset);
5828 rel[1].r_info = ELFNN_R_INFO (STN_UNDEF, R_AARCH64_NONE);
5830 bfd_putl32 (0xf2800000, contents + rel->r_offset);
5831 bfd_putl32 (0xd53bd041, contents + rel->r_offset + 4);
5832 bfd_putl32 (0x8b000020, contents + rel->r_offset + 8);
5833 return bfd_reloc_continue;
5837 /* GD->IE relaxation
5838 ADD x0, #:tlsgd_lo12:var => ldr x0, [x0, #:gottprel_lo12:var]
5839 BL __tls_get_addr => mrs x1, tpidr_el0
5841 NOP => add x0, x1, x0
5844 BFD_ASSERT (ELFNN_R_TYPE (rel[1].r_info) == AARCH64_R (CALL26));
5846 /* Remove the relocation on the BL instruction. */
5847 rel[1].r_info = ELFNN_R_INFO (STN_UNDEF, R_AARCH64_NONE);
5849 bfd_putl32 (0xf9400000, contents + rel->r_offset);
5851 /* We choose to fixup the BL and NOP instructions using the
5852 offset from the second relocation to allow flexibility in
5853 scheduling instructions between the ADD and BL. */
5854 bfd_putl32 (0xd53bd041, contents + rel[1].r_offset);
5855 bfd_putl32 (0x8b000020, contents + rel[1].r_offset + 4);
5856 return bfd_reloc_continue;
5859 case BFD_RELOC_AARCH64_TLSDESC_ADD:
5860 case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12_NC:
5861 case BFD_RELOC_AARCH64_TLSDESC_CALL:
5862 /* GD->IE/LE relaxation:
5863 add x0, x0, #:tlsdesc_lo12:var => nop
5866 bfd_putl32 (INSN_NOP, contents + rel->r_offset);
5867 return bfd_reloc_ok;
5869 case BFD_RELOC_AARCH64_TLSDESC_LDR:
5872 /* GD->LE relaxation:
5873 ldr xd, [gp, xn] => movk x0, #:tprel_g0_nc:var
5875 bfd_putl32 (0xf2800000, contents + rel->r_offset);
5876 return bfd_reloc_continue;
5880 /* GD->IE relaxation:
5881 ldr xd, [gp, xn] => ldr x0, [gp, xn]
5883 insn = bfd_getl32 (contents + rel->r_offset);
5885 bfd_putl32 (insn, contents + rel->r_offset);
5886 return bfd_reloc_ok;
5889 case BFD_RELOC_AARCH64_TLSDESC_OFF_G0_NC:
5890 /* GD->LE relaxation:
5891 movk xd, #:tlsdesc_off_g0_nc:var => movk x0, #:tprel_g1_nc:var, lsl #16
5893 movk xd, #:tlsdesc_off_g0_nc:var => movk xd, #:gottprel_g0_nc:var
5896 bfd_putl32 (0xf2a00000, contents + rel->r_offset);
5897 return bfd_reloc_continue;
5899 case BFD_RELOC_AARCH64_TLSDESC_OFF_G1:
5902 /* GD->LE relaxation:
5903 movz xd, #:tlsdesc_off_g1:var => movz x0, #:tprel_g2:var, lsl #32
5905 bfd_putl32 (0xd2c00000, contents + rel->r_offset);
5906 return bfd_reloc_continue;
5910 /* GD->IE relaxation:
5911 movz xd, #:tlsdesc_off_g1:var => movz xd, #:gottprel_g1:var, lsl #16
5913 insn = bfd_getl32 (contents + rel->r_offset);
5914 bfd_putl32 (0xd2a00000 | (insn & 0x1f), contents + rel->r_offset);
5915 return bfd_reloc_continue;
5918 case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21:
5919 /* IE->LE relaxation:
5920 adrp xd, :gottprel:var => movz xd, :tprel_g1:var
5924 insn = bfd_getl32 (contents + rel->r_offset);
5925 bfd_putl32 (0xd2a00000 | (insn & 0x1f), contents + rel->r_offset);
5927 return bfd_reloc_continue;
5929 case BFD_RELOC_AARCH64_TLSIE_LDNN_GOTTPREL_LO12_NC:
5930 /* IE->LE relaxation:
5931 ldr xd, [xm, #:gottprel_lo12:var] => movk xd, :tprel_g0_nc:var
5935 insn = bfd_getl32 (contents + rel->r_offset);
5936 bfd_putl32 (0xf2800000 | (insn & 0x1f), contents + rel->r_offset);
5938 return bfd_reloc_continue;
5940 case BFD_RELOC_AARCH64_TLSLD_ADR_PREL21:
5941 /* LD->LE relaxation (tiny):
5942 adr x0, :tlsldm:x => mrs x0, tpidr_el0
5943 bl __tls_get_addr => add x0, x0, TCB_SIZE
5947 BFD_ASSERT (rel->r_offset + 4 == rel[1].r_offset);
5948 BFD_ASSERT (ELFNN_R_TYPE (rel[1].r_info) == AARCH64_R (CALL26));
5949 /* No need of CALL26 relocation for tls_get_addr. */
5950 rel[1].r_info = ELFNN_R_INFO (STN_UNDEF, R_AARCH64_NONE);
5951 bfd_putl32 (0xd53bd040, contents + rel->r_offset + 0);
5952 bfd_putl32 (0x91004000, contents + rel->r_offset + 4);
5953 return bfd_reloc_ok;
5955 return bfd_reloc_continue;
5957 case BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21:
5958 /* LD->LE relaxation (small):
5959 adrp x0, :tlsldm:x => mrs x0, tpidr_el0
5963 bfd_putl32 (0xd53bd040, contents + rel->r_offset);
5964 return bfd_reloc_ok;
5966 return bfd_reloc_continue;
5968 case BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC:
5969 /* LD->LE relaxation (small):
5970 add x0, #:tlsldm_lo12:x => add x0, x0, TCB_SIZE
5971 bl __tls_get_addr => nop
5975 BFD_ASSERT (rel->r_offset + 4 == rel[1].r_offset);
5976 BFD_ASSERT (ELFNN_R_TYPE (rel[1].r_info) == AARCH64_R (CALL26));
5977 /* No need of CALL26 relocation for tls_get_addr. */
5978 rel[1].r_info = ELFNN_R_INFO (STN_UNDEF, R_AARCH64_NONE);
5979 bfd_putl32 (0x91004000, contents + rel->r_offset + 0);
5980 bfd_putl32 (0xd503201f, contents + rel->r_offset + 4);
5981 return bfd_reloc_ok;
5983 return bfd_reloc_continue;
5986 return bfd_reloc_continue;
5989 return bfd_reloc_ok;
5992 /* Relocate an AArch64 ELF section. */
5995 elfNN_aarch64_relocate_section (bfd *output_bfd,
5996 struct bfd_link_info *info,
5998 asection *input_section,
6000 Elf_Internal_Rela *relocs,
6001 Elf_Internal_Sym *local_syms,
6002 asection **local_sections)
6004 Elf_Internal_Shdr *symtab_hdr;
6005 struct elf_link_hash_entry **sym_hashes;
6006 Elf_Internal_Rela *rel;
6007 Elf_Internal_Rela *relend;
6009 struct elf_aarch64_link_hash_table *globals;
6010 bfd_boolean save_addend = FALSE;
6013 globals = elf_aarch64_hash_table (info);
6015 symtab_hdr = &elf_symtab_hdr (input_bfd);
6016 sym_hashes = elf_sym_hashes (input_bfd);
6019 relend = relocs + input_section->reloc_count;
6020 for (; rel < relend; rel++)
6022 unsigned int r_type;
6023 bfd_reloc_code_real_type bfd_r_type;
6024 bfd_reloc_code_real_type relaxed_bfd_r_type;
6025 reloc_howto_type *howto;
6026 unsigned long r_symndx;
6027 Elf_Internal_Sym *sym;
6029 struct elf_link_hash_entry *h;
6031 bfd_reloc_status_type r;
6034 bfd_boolean unresolved_reloc = FALSE;
6035 char *error_message = NULL;
6037 r_symndx = ELFNN_R_SYM (rel->r_info);
6038 r_type = ELFNN_R_TYPE (rel->r_info);
6040 bfd_reloc.howto = elfNN_aarch64_howto_from_type (r_type);
6041 howto = bfd_reloc.howto;
6045 (*_bfd_error_handler)
6046 (_("%B: unrecognized relocation (0x%x) in section `%A'"),
6047 input_bfd, input_section, r_type);
6050 bfd_r_type = elfNN_aarch64_bfd_reloc_from_howto (howto);
6056 if (r_symndx < symtab_hdr->sh_info)
6058 sym = local_syms + r_symndx;
6059 sym_type = ELFNN_ST_TYPE (sym->st_info);
6060 sec = local_sections[r_symndx];
6062 /* An object file might have a reference to a local
6063 undefined symbol. This is a daft object file, but we
6064 should at least do something about it. */
6065 if (r_type != R_AARCH64_NONE && r_type != R_AARCH64_NULL
6066 && bfd_is_und_section (sec)
6067 && ELF_ST_BIND (sym->st_info) != STB_WEAK)
6069 if (!info->callbacks->undefined_symbol
6070 (info, bfd_elf_string_from_elf_section
6071 (input_bfd, symtab_hdr->sh_link, sym->st_name),
6072 input_bfd, input_section, rel->r_offset, TRUE))
6076 relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel);
6078 /* Relocate against local STT_GNU_IFUNC symbol. */
6079 if (!bfd_link_relocatable (info)
6080 && ELF_ST_TYPE (sym->st_info) == STT_GNU_IFUNC)
6082 h = elfNN_aarch64_get_local_sym_hash (globals, input_bfd,
6087 /* Set STT_GNU_IFUNC symbol value. */
6088 h->root.u.def.value = sym->st_value;
6089 h->root.u.def.section = sec;
6094 bfd_boolean warned, ignored;
6096 RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel,
6097 r_symndx, symtab_hdr, sym_hashes,
6099 unresolved_reloc, warned, ignored);
6104 if (sec != NULL && discarded_section (sec))
6105 RELOC_AGAINST_DISCARDED_SECTION (info, input_bfd, input_section,
6106 rel, 1, relend, howto, 0, contents);
6108 if (bfd_link_relocatable (info))
6112 name = h->root.root.string;
6115 name = (bfd_elf_string_from_elf_section
6116 (input_bfd, symtab_hdr->sh_link, sym->st_name));
6117 if (name == NULL || *name == '\0')
6118 name = bfd_section_name (input_bfd, sec);
6122 && r_type != R_AARCH64_NONE
6123 && r_type != R_AARCH64_NULL
6125 || h->root.type == bfd_link_hash_defined
6126 || h->root.type == bfd_link_hash_defweak)
6127 && IS_AARCH64_TLS_RELOC (bfd_r_type) != (sym_type == STT_TLS))
6129 (*_bfd_error_handler)
6130 ((sym_type == STT_TLS
6131 ? _("%B(%A+0x%lx): %s used with TLS symbol %s")
6132 : _("%B(%A+0x%lx): %s used with non-TLS symbol %s")),
6134 input_section, (long) rel->r_offset, howto->name, name);
6137 /* We relax only if we can see that there can be a valid transition
6138 from a reloc type to another.
6139 We call elfNN_aarch64_final_link_relocate unless we're completely
6140 done, i.e., the relaxation produced the final output we want. */
6142 relaxed_bfd_r_type = aarch64_tls_transition (input_bfd, info, r_type,
6144 if (relaxed_bfd_r_type != bfd_r_type)
6146 bfd_r_type = relaxed_bfd_r_type;
6147 howto = elfNN_aarch64_howto_from_bfd_reloc (bfd_r_type);
6148 BFD_ASSERT (howto != NULL);
6149 r_type = howto->type;
6150 r = elfNN_aarch64_tls_relax (globals, input_bfd, contents, rel, h);
6151 unresolved_reloc = 0;
6154 r = bfd_reloc_continue;
6156 /* There may be multiple consecutive relocations for the
6157 same offset. In that case we are supposed to treat the
6158 output of each relocation as the addend for the next. */
6159 if (rel + 1 < relend
6160 && rel->r_offset == rel[1].r_offset
6161 && ELFNN_R_TYPE (rel[1].r_info) != R_AARCH64_NONE
6162 && ELFNN_R_TYPE (rel[1].r_info) != R_AARCH64_NULL)
6165 save_addend = FALSE;
6167 if (r == bfd_reloc_continue)
6168 r = elfNN_aarch64_final_link_relocate (howto, input_bfd, output_bfd,
6169 input_section, contents, rel,
6170 relocation, info, sec,
6171 h, &unresolved_reloc,
6172 save_addend, &addend, sym);
6174 switch (elfNN_aarch64_bfd_reloc_from_type (r_type))
6176 case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC:
6177 case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21:
6178 case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21:
6179 case BFD_RELOC_AARCH64_TLSGD_MOVW_G0_NC:
6180 case BFD_RELOC_AARCH64_TLSGD_MOVW_G1:
6181 case BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC:
6182 case BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21:
6183 case BFD_RELOC_AARCH64_TLSLD_ADR_PREL21:
6184 if (! symbol_got_offset_mark_p (input_bfd, h, r_symndx))
6186 bfd_boolean need_relocs = FALSE;
6191 off = symbol_got_offset (input_bfd, h, r_symndx);
6192 indx = h && h->dynindx != -1 ? h->dynindx : 0;
6195 (bfd_link_pic (info) || indx != 0) &&
6197 || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
6198 || h->root.type != bfd_link_hash_undefweak);
6200 BFD_ASSERT (globals->root.srelgot != NULL);
6204 Elf_Internal_Rela rela;
6205 rela.r_info = ELFNN_R_INFO (indx, AARCH64_R (TLS_DTPMOD));
6207 rela.r_offset = globals->root.sgot->output_section->vma +
6208 globals->root.sgot->output_offset + off;
6211 loc = globals->root.srelgot->contents;
6212 loc += globals->root.srelgot->reloc_count++
6213 * RELOC_SIZE (htab);
6214 bfd_elfNN_swap_reloca_out (output_bfd, &rela, loc);
6216 bfd_reloc_code_real_type real_type =
6217 elfNN_aarch64_bfd_reloc_from_type (r_type);
6219 if (real_type == BFD_RELOC_AARCH64_TLSLD_ADR_PREL21
6220 || real_type == BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21
6221 || real_type == BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC)
6223 /* For local dynamic, don't generate DTPREL in any case.
6224 Initialize the DTPREL slot into zero, so we get module
6225 base address when invoke runtime TLS resolver. */
6226 bfd_put_NN (output_bfd, 0,
6227 globals->root.sgot->contents + off
6232 bfd_put_NN (output_bfd,
6233 relocation - dtpoff_base (info),
6234 globals->root.sgot->contents + off
6239 /* This TLS symbol is global. We emit a
6240 relocation to fixup the tls offset at load
6243 ELFNN_R_INFO (indx, AARCH64_R (TLS_DTPREL));
6246 (globals->root.sgot->output_section->vma
6247 + globals->root.sgot->output_offset + off
6250 loc = globals->root.srelgot->contents;
6251 loc += globals->root.srelgot->reloc_count++
6252 * RELOC_SIZE (globals);
6253 bfd_elfNN_swap_reloca_out (output_bfd, &rela, loc);
6254 bfd_put_NN (output_bfd, (bfd_vma) 0,
6255 globals->root.sgot->contents + off
6261 bfd_put_NN (output_bfd, (bfd_vma) 1,
6262 globals->root.sgot->contents + off);
6263 bfd_put_NN (output_bfd,
6264 relocation - dtpoff_base (info),
6265 globals->root.sgot->contents + off
6269 symbol_got_offset_mark (input_bfd, h, r_symndx);
6273 case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21:
6274 case BFD_RELOC_AARCH64_TLSIE_LDNN_GOTTPREL_LO12_NC:
6275 case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19:
6276 case BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G0_NC:
6277 case BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G1:
6278 if (! symbol_got_offset_mark_p (input_bfd, h, r_symndx))
6280 bfd_boolean need_relocs = FALSE;
6285 off = symbol_got_offset (input_bfd, h, r_symndx);
6287 indx = h && h->dynindx != -1 ? h->dynindx : 0;
6290 (bfd_link_pic (info) || indx != 0) &&
6292 || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
6293 || h->root.type != bfd_link_hash_undefweak);
6295 BFD_ASSERT (globals->root.srelgot != NULL);
6299 Elf_Internal_Rela rela;
6302 rela.r_addend = relocation - dtpoff_base (info);
6306 rela.r_info = ELFNN_R_INFO (indx, AARCH64_R (TLS_TPREL));
6307 rela.r_offset = globals->root.sgot->output_section->vma +
6308 globals->root.sgot->output_offset + off;
6310 loc = globals->root.srelgot->contents;
6311 loc += globals->root.srelgot->reloc_count++
6312 * RELOC_SIZE (htab);
6314 bfd_elfNN_swap_reloca_out (output_bfd, &rela, loc);
6316 bfd_put_NN (output_bfd, rela.r_addend,
6317 globals->root.sgot->contents + off);
6320 bfd_put_NN (output_bfd, relocation - tpoff_base (info),
6321 globals->root.sgot->contents + off);
6323 symbol_got_offset_mark (input_bfd, h, r_symndx);
6327 case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12_NC:
6328 case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21:
6329 case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21:
6330 case BFD_RELOC_AARCH64_TLSDESC_LDNN_LO12_NC:
6331 case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19:
6332 case BFD_RELOC_AARCH64_TLSDESC_OFF_G0_NC:
6333 case BFD_RELOC_AARCH64_TLSDESC_OFF_G1:
6334 if (! symbol_tlsdesc_got_offset_mark_p (input_bfd, h, r_symndx))
6336 bfd_boolean need_relocs = FALSE;
6337 int indx = h && h->dynindx != -1 ? h->dynindx : 0;
6338 bfd_vma off = symbol_tlsdesc_got_offset (input_bfd, h, r_symndx);
6340 need_relocs = (h == NULL
6341 || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
6342 || h->root.type != bfd_link_hash_undefweak);
6344 BFD_ASSERT (globals->root.srelgot != NULL);
6345 BFD_ASSERT (globals->root.sgot != NULL);
6350 Elf_Internal_Rela rela;
6351 rela.r_info = ELFNN_R_INFO (indx, AARCH64_R (TLSDESC));
6354 rela.r_offset = (globals->root.sgotplt->output_section->vma
6355 + globals->root.sgotplt->output_offset
6356 + off + globals->sgotplt_jump_table_size);
6359 rela.r_addend = relocation - dtpoff_base (info);
6361 /* Allocate the next available slot in the PLT reloc
6362 section to hold our R_AARCH64_TLSDESC, the next
6363 available slot is determined from reloc_count,
6364 which we step. But note, reloc_count was
6365 artifically moved down while allocating slots for
6366 real PLT relocs such that all of the PLT relocs
6367 will fit above the initial reloc_count and the
6368 extra stuff will fit below. */
6369 loc = globals->root.srelplt->contents;
6370 loc += globals->root.srelplt->reloc_count++
6371 * RELOC_SIZE (globals);
6373 bfd_elfNN_swap_reloca_out (output_bfd, &rela, loc);
6375 bfd_put_NN (output_bfd, (bfd_vma) 0,
6376 globals->root.sgotplt->contents + off +
6377 globals->sgotplt_jump_table_size);
6378 bfd_put_NN (output_bfd, (bfd_vma) 0,
6379 globals->root.sgotplt->contents + off +
6380 globals->sgotplt_jump_table_size +
6384 symbol_tlsdesc_got_offset_mark (input_bfd, h, r_symndx);
6391 /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
6392 because such sections are not SEC_ALLOC and thus ld.so will
6393 not process them. */
6394 if (unresolved_reloc
6395 && !((input_section->flags & SEC_DEBUGGING) != 0
6397 && _bfd_elf_section_offset (output_bfd, info, input_section,
6398 +rel->r_offset) != (bfd_vma) - 1)
6400 (*_bfd_error_handler)
6402 ("%B(%A+0x%lx): unresolvable %s relocation against symbol `%s'"),
6403 input_bfd, input_section, (long) rel->r_offset, howto->name,
6404 h->root.root.string);
6408 if (r != bfd_reloc_ok && r != bfd_reloc_continue)
6410 bfd_reloc_code_real_type real_r_type
6411 = elfNN_aarch64_bfd_reloc_from_type (r_type);
6415 case bfd_reloc_overflow:
6416 if (!(*info->callbacks->reloc_overflow)
6417 (info, (h ? &h->root : NULL), name, howto->name, (bfd_vma) 0,
6418 input_bfd, input_section, rel->r_offset))
6420 if (real_r_type == BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15
6421 || real_r_type == BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14)
6423 (*info->callbacks->warning)
6425 _("Too many GOT entries for -fpic, "
6426 "please recompile with -fPIC"),
6427 name, input_bfd, input_section, rel->r_offset);
6430 /* Overflow can occur when a variable is referenced with a type
6431 that has a larger alignment than the type with which it was
6433 file1.c: extern int foo; int a (void) { return foo; }
6434 file2.c: char bar, foo, baz;
6435 If the variable is placed into a data section at an offset
6436 that is incompatible with the larger alignment requirement
6437 overflow will occur. (Strictly speaking this is not overflow
6438 but rather an alignment problem, but the bfd_reloc_ error
6439 enum does not have a value to cover that situation).
6441 Try to catch this situation here and provide a more helpful
6442 error message to the user. */
6443 if (addend & ((1 << howto->rightshift) - 1)
6444 /* FIXME: Are we testing all of the appropriate reloc
6446 && (real_r_type == BFD_RELOC_AARCH64_LD_LO19_PCREL
6447 || real_r_type == BFD_RELOC_AARCH64_LDST16_LO12
6448 || real_r_type == BFD_RELOC_AARCH64_LDST32_LO12
6449 || real_r_type == BFD_RELOC_AARCH64_LDST64_LO12
6450 || real_r_type == BFD_RELOC_AARCH64_LDST128_LO12))
6452 info->callbacks->warning
6453 (info, _("One possible cause of this error is that the \
6454 symbol is being referenced in the indicated code as if it had a larger \
6455 alignment than was declared where it was defined."),
6456 name, input_bfd, input_section, rel->r_offset);
6460 case bfd_reloc_undefined:
6461 if (!((*info->callbacks->undefined_symbol)
6462 (info, name, input_bfd, input_section,
6463 rel->r_offset, TRUE)))
6467 case bfd_reloc_outofrange:
6468 error_message = _("out of range");
6471 case bfd_reloc_notsupported:
6472 error_message = _("unsupported relocation");
6475 case bfd_reloc_dangerous:
6476 /* error_message should already be set. */
6480 error_message = _("unknown error");
6484 BFD_ASSERT (error_message != NULL);
6485 if (!((*info->callbacks->reloc_dangerous)
6486 (info, error_message, input_bfd, input_section,
6500 /* Set the right machine number. */
6503 elfNN_aarch64_object_p (bfd *abfd)
6506 bfd_default_set_arch_mach (abfd, bfd_arch_aarch64, bfd_mach_aarch64_ilp32);
6508 bfd_default_set_arch_mach (abfd, bfd_arch_aarch64, bfd_mach_aarch64);
6513 /* Function to keep AArch64 specific flags in the ELF header. */
6516 elfNN_aarch64_set_private_flags (bfd *abfd, flagword flags)
6518 if (elf_flags_init (abfd) && elf_elfheader (abfd)->e_flags != flags)
6523 elf_elfheader (abfd)->e_flags = flags;
6524 elf_flags_init (abfd) = TRUE;
6530 /* Merge backend specific data from an object file to the output
6531 object file when linking. */
6534 elfNN_aarch64_merge_private_bfd_data (bfd *ibfd, bfd *obfd)
6538 bfd_boolean flags_compatible = TRUE;
6541 /* Check if we have the same endianess. */
6542 if (!_bfd_generic_verify_endian_match (ibfd, obfd))
6545 if (!is_aarch64_elf (ibfd) || !is_aarch64_elf (obfd))
6548 /* The input BFD must have had its flags initialised. */
6549 /* The following seems bogus to me -- The flags are initialized in
6550 the assembler but I don't think an elf_flags_init field is
6551 written into the object. */
6552 /* BFD_ASSERT (elf_flags_init (ibfd)); */
6554 in_flags = elf_elfheader (ibfd)->e_flags;
6555 out_flags = elf_elfheader (obfd)->e_flags;
6557 if (!elf_flags_init (obfd))
6559 /* If the input is the default architecture and had the default
6560 flags then do not bother setting the flags for the output
6561 architecture, instead allow future merges to do this. If no
6562 future merges ever set these flags then they will retain their
6563 uninitialised values, which surprise surprise, correspond
6564 to the default values. */
6565 if (bfd_get_arch_info (ibfd)->the_default
6566 && elf_elfheader (ibfd)->e_flags == 0)
6569 elf_flags_init (obfd) = TRUE;
6570 elf_elfheader (obfd)->e_flags = in_flags;
6572 if (bfd_get_arch (obfd) == bfd_get_arch (ibfd)
6573 && bfd_get_arch_info (obfd)->the_default)
6574 return bfd_set_arch_mach (obfd, bfd_get_arch (ibfd),
6575 bfd_get_mach (ibfd));
6580 /* Identical flags must be compatible. */
6581 if (in_flags == out_flags)
6584 /* Check to see if the input BFD actually contains any sections. If
6585 not, its flags may not have been initialised either, but it
6586 cannot actually cause any incompatiblity. Do not short-circuit
6587 dynamic objects; their section list may be emptied by
6588 elf_link_add_object_symbols.
6590 Also check to see if there are no code sections in the input.
6591 In this case there is no need to check for code specific flags.
6592 XXX - do we need to worry about floating-point format compatability
6593 in data sections ? */
6594 if (!(ibfd->flags & DYNAMIC))
6596 bfd_boolean null_input_bfd = TRUE;
6597 bfd_boolean only_data_sections = TRUE;
6599 for (sec = ibfd->sections; sec != NULL; sec = sec->next)
6601 if ((bfd_get_section_flags (ibfd, sec)
6602 & (SEC_LOAD | SEC_CODE | SEC_HAS_CONTENTS))
6603 == (SEC_LOAD | SEC_CODE | SEC_HAS_CONTENTS))
6604 only_data_sections = FALSE;
6606 null_input_bfd = FALSE;
6610 if (null_input_bfd || only_data_sections)
6614 return flags_compatible;
6617 /* Display the flags field. */
6620 elfNN_aarch64_print_private_bfd_data (bfd *abfd, void *ptr)
6622 FILE *file = (FILE *) ptr;
6623 unsigned long flags;
6625 BFD_ASSERT (abfd != NULL && ptr != NULL);
6627 /* Print normal ELF private data. */
6628 _bfd_elf_print_private_bfd_data (abfd, ptr);
6630 flags = elf_elfheader (abfd)->e_flags;
6631 /* Ignore init flag - it may not be set, despite the flags field
6632 containing valid data. */
6634 /* xgettext:c-format */
6635 fprintf (file, _("private flags = %lx:"), elf_elfheader (abfd)->e_flags);
6638 fprintf (file, _("<Unrecognised flag bits set>"));
6645 /* Update the got entry reference counts for the section being removed. */
6648 elfNN_aarch64_gc_sweep_hook (bfd *abfd,
6649 struct bfd_link_info *info,
6651 const Elf_Internal_Rela * relocs)
6653 struct elf_aarch64_link_hash_table *htab;
6654 Elf_Internal_Shdr *symtab_hdr;
6655 struct elf_link_hash_entry **sym_hashes;
6656 struct elf_aarch64_local_symbol *locals;
6657 const Elf_Internal_Rela *rel, *relend;
6659 if (bfd_link_relocatable (info))
6662 htab = elf_aarch64_hash_table (info);
6667 elf_section_data (sec)->local_dynrel = NULL;
6669 symtab_hdr = &elf_symtab_hdr (abfd);
6670 sym_hashes = elf_sym_hashes (abfd);
6672 locals = elf_aarch64_locals (abfd);
6674 relend = relocs + sec->reloc_count;
6675 for (rel = relocs; rel < relend; rel++)
6677 unsigned long r_symndx;
6678 unsigned int r_type;
6679 struct elf_link_hash_entry *h = NULL;
6681 r_symndx = ELFNN_R_SYM (rel->r_info);
6683 if (r_symndx >= symtab_hdr->sh_info)
6686 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
6687 while (h->root.type == bfd_link_hash_indirect
6688 || h->root.type == bfd_link_hash_warning)
6689 h = (struct elf_link_hash_entry *) h->root.u.i.link;
6693 Elf_Internal_Sym *isym;
6695 /* A local symbol. */
6696 isym = bfd_sym_from_r_symndx (&htab->sym_cache,
6699 /* Check relocation against local STT_GNU_IFUNC symbol. */
6701 && ELF_ST_TYPE (isym->st_info) == STT_GNU_IFUNC)
6703 h = elfNN_aarch64_get_local_sym_hash (htab, abfd, rel, FALSE);
6711 struct elf_aarch64_link_hash_entry *eh;
6712 struct elf_dyn_relocs **pp;
6713 struct elf_dyn_relocs *p;
6715 eh = (struct elf_aarch64_link_hash_entry *) h;
6717 for (pp = &eh->dyn_relocs; (p = *pp) != NULL; pp = &p->next)
6720 /* Everything must go for SEC. */
6726 r_type = ELFNN_R_TYPE (rel->r_info);
6727 switch (aarch64_tls_transition (abfd,info, r_type, h ,r_symndx))
6729 case BFD_RELOC_AARCH64_ADR_GOT_PAGE:
6730 case BFD_RELOC_AARCH64_GOT_LD_PREL19:
6731 case BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14:
6732 case BFD_RELOC_AARCH64_LD32_GOT_LO12_NC:
6733 case BFD_RELOC_AARCH64_LD64_GOTOFF_LO15:
6734 case BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15:
6735 case BFD_RELOC_AARCH64_LD64_GOT_LO12_NC:
6736 case BFD_RELOC_AARCH64_MOVW_GOTOFF_G0_NC:
6737 case BFD_RELOC_AARCH64_MOVW_GOTOFF_G1:
6738 case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12_NC:
6739 case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21:
6740 case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21:
6741 case BFD_RELOC_AARCH64_TLSDESC_LD32_LO12_NC:
6742 case BFD_RELOC_AARCH64_TLSDESC_LD64_LO12_NC:
6743 case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19:
6744 case BFD_RELOC_AARCH64_TLSDESC_OFF_G0_NC:
6745 case BFD_RELOC_AARCH64_TLSDESC_OFF_G1:
6746 case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC:
6747 case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21:
6748 case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21:
6749 case BFD_RELOC_AARCH64_TLSGD_MOVW_G0_NC:
6750 case BFD_RELOC_AARCH64_TLSGD_MOVW_G1:
6751 case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21:
6752 case BFD_RELOC_AARCH64_TLSIE_LD32_GOTTPREL_LO12_NC:
6753 case BFD_RELOC_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC:
6754 case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19:
6755 case BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G0_NC:
6756 case BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G1:
6757 case BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC:
6758 case BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21:
6759 case BFD_RELOC_AARCH64_TLSLD_ADR_PREL21:
6762 if (h->got.refcount > 0)
6763 h->got.refcount -= 1;
6765 if (h->type == STT_GNU_IFUNC)
6767 if (h->plt.refcount > 0)
6768 h->plt.refcount -= 1;
6771 else if (locals != NULL)
6773 if (locals[r_symndx].got_refcount > 0)
6774 locals[r_symndx].got_refcount -= 1;
6778 case BFD_RELOC_AARCH64_CALL26:
6779 case BFD_RELOC_AARCH64_JUMP26:
6780 /* If this is a local symbol then we resolve it
6781 directly without creating a PLT entry. */
6785 if (h->plt.refcount > 0)
6786 h->plt.refcount -= 1;
6789 case BFD_RELOC_AARCH64_ADR_HI21_NC_PCREL:
6790 case BFD_RELOC_AARCH64_ADR_HI21_PCREL:
6791 case BFD_RELOC_AARCH64_ADR_LO21_PCREL:
6792 case BFD_RELOC_AARCH64_MOVW_G0_NC:
6793 case BFD_RELOC_AARCH64_MOVW_G1_NC:
6794 case BFD_RELOC_AARCH64_MOVW_G2_NC:
6795 case BFD_RELOC_AARCH64_MOVW_G3:
6796 case BFD_RELOC_AARCH64_NN:
6797 if (h != NULL && bfd_link_executable (info))
6799 if (h->plt.refcount > 0)
6800 h->plt.refcount -= 1;
6812 /* Adjust a symbol defined by a dynamic object and referenced by a
6813 regular object. The current definition is in some section of the
6814 dynamic object, but we're not including those sections. We have to
6815 change the definition to something the rest of the link can
6819 elfNN_aarch64_adjust_dynamic_symbol (struct bfd_link_info *info,
6820 struct elf_link_hash_entry *h)
6822 struct elf_aarch64_link_hash_table *htab;
6825 /* If this is a function, put it in the procedure linkage table. We
6826 will fill in the contents of the procedure linkage table later,
6827 when we know the address of the .got section. */
6828 if (h->type == STT_FUNC || h->type == STT_GNU_IFUNC || h->needs_plt)
6830 if (h->plt.refcount <= 0
6831 || (h->type != STT_GNU_IFUNC
6832 && (SYMBOL_CALLS_LOCAL (info, h)
6833 || (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
6834 && h->root.type == bfd_link_hash_undefweak))))
6836 /* This case can occur if we saw a CALL26 reloc in
6837 an input file, but the symbol wasn't referred to
6838 by a dynamic object or all references were
6839 garbage collected. In which case we can end up
6841 h->plt.offset = (bfd_vma) - 1;
6848 /* Otherwise, reset to -1. */
6849 h->plt.offset = (bfd_vma) - 1;
6852 /* If this is a weak symbol, and there is a real definition, the
6853 processor independent code will have arranged for us to see the
6854 real definition first, and we can just use the same value. */
6855 if (h->u.weakdef != NULL)
6857 BFD_ASSERT (h->u.weakdef->root.type == bfd_link_hash_defined
6858 || h->u.weakdef->root.type == bfd_link_hash_defweak);
6859 h->root.u.def.section = h->u.weakdef->root.u.def.section;
6860 h->root.u.def.value = h->u.weakdef->root.u.def.value;
6861 if (ELIMINATE_COPY_RELOCS || info->nocopyreloc)
6862 h->non_got_ref = h->u.weakdef->non_got_ref;
6866 /* If we are creating a shared library, we must presume that the
6867 only references to the symbol are via the global offset table.
6868 For such cases we need not do anything here; the relocations will
6869 be handled correctly by relocate_section. */
6870 if (bfd_link_pic (info))
6873 /* If there are no references to this symbol that do not use the
6874 GOT, we don't need to generate a copy reloc. */
6875 if (!h->non_got_ref)
6878 /* If -z nocopyreloc was given, we won't generate them either. */
6879 if (info->nocopyreloc)
6885 /* We must allocate the symbol in our .dynbss section, which will
6886 become part of the .bss section of the executable. There will be
6887 an entry for this symbol in the .dynsym section. The dynamic
6888 object will contain position independent code, so all references
6889 from the dynamic object to this symbol will go through the global
6890 offset table. The dynamic linker will use the .dynsym entry to
6891 determine the address it must put in the global offset table, so
6892 both the dynamic object and the regular object will refer to the
6893 same memory location for the variable. */
6895 htab = elf_aarch64_hash_table (info);
6897 /* We must generate a R_AARCH64_COPY reloc to tell the dynamic linker
6898 to copy the initial value out of the dynamic object and into the
6899 runtime process image. */
6900 if ((h->root.u.def.section->flags & SEC_ALLOC) != 0 && h->size != 0)
6902 htab->srelbss->size += RELOC_SIZE (htab);
6908 return _bfd_elf_adjust_dynamic_copy (info, h, s);
6913 elfNN_aarch64_allocate_local_symbols (bfd *abfd, unsigned number)
6915 struct elf_aarch64_local_symbol *locals;
6916 locals = elf_aarch64_locals (abfd);
6919 locals = (struct elf_aarch64_local_symbol *)
6920 bfd_zalloc (abfd, number * sizeof (struct elf_aarch64_local_symbol));
6923 elf_aarch64_locals (abfd) = locals;
6928 /* Create the .got section to hold the global offset table. */
6931 aarch64_elf_create_got_section (bfd *abfd, struct bfd_link_info *info)
6933 const struct elf_backend_data *bed = get_elf_backend_data (abfd);
6936 struct elf_link_hash_entry *h;
6937 struct elf_link_hash_table *htab = elf_hash_table (info);
6939 /* This function may be called more than once. */
6940 s = bfd_get_linker_section (abfd, ".got");
6944 flags = bed->dynamic_sec_flags;
6946 s = bfd_make_section_anyway_with_flags (abfd,
6947 (bed->rela_plts_and_copies_p
6948 ? ".rela.got" : ".rel.got"),
6949 (bed->dynamic_sec_flags
6952 || ! bfd_set_section_alignment (abfd, s, bed->s->log_file_align))
6956 s = bfd_make_section_anyway_with_flags (abfd, ".got", flags);
6958 || !bfd_set_section_alignment (abfd, s, bed->s->log_file_align))
6961 htab->sgot->size += GOT_ENTRY_SIZE;
6963 if (bed->want_got_sym)
6965 /* Define the symbol _GLOBAL_OFFSET_TABLE_ at the start of the .got
6966 (or .got.plt) section. We don't do this in the linker script
6967 because we don't want to define the symbol if we are not creating
6968 a global offset table. */
6969 h = _bfd_elf_define_linkage_sym (abfd, info, s,
6970 "_GLOBAL_OFFSET_TABLE_");
6971 elf_hash_table (info)->hgot = h;
6976 if (bed->want_got_plt)
6978 s = bfd_make_section_anyway_with_flags (abfd, ".got.plt", flags);
6980 || !bfd_set_section_alignment (abfd, s,
6981 bed->s->log_file_align))
6986 /* The first bit of the global offset table is the header. */
6987 s->size += bed->got_header_size;
6992 /* Look through the relocs for a section during the first phase. */
6995 elfNN_aarch64_check_relocs (bfd *abfd, struct bfd_link_info *info,
6996 asection *sec, const Elf_Internal_Rela *relocs)
6998 Elf_Internal_Shdr *symtab_hdr;
6999 struct elf_link_hash_entry **sym_hashes;
7000 const Elf_Internal_Rela *rel;
7001 const Elf_Internal_Rela *rel_end;
7004 struct elf_aarch64_link_hash_table *htab;
7006 if (bfd_link_relocatable (info))
7009 BFD_ASSERT (is_aarch64_elf (abfd));
7011 htab = elf_aarch64_hash_table (info);
7014 symtab_hdr = &elf_symtab_hdr (abfd);
7015 sym_hashes = elf_sym_hashes (abfd);
7017 rel_end = relocs + sec->reloc_count;
7018 for (rel = relocs; rel < rel_end; rel++)
7020 struct elf_link_hash_entry *h;
7021 unsigned long r_symndx;
7022 unsigned int r_type;
7023 bfd_reloc_code_real_type bfd_r_type;
7024 Elf_Internal_Sym *isym;
7026 r_symndx = ELFNN_R_SYM (rel->r_info);
7027 r_type = ELFNN_R_TYPE (rel->r_info);
7029 if (r_symndx >= NUM_SHDR_ENTRIES (symtab_hdr))
7031 (*_bfd_error_handler) (_("%B: bad symbol index: %d"), abfd,
7036 if (r_symndx < symtab_hdr->sh_info)
7038 /* A local symbol. */
7039 isym = bfd_sym_from_r_symndx (&htab->sym_cache,
7044 /* Check relocation against local STT_GNU_IFUNC symbol. */
7045 if (ELF_ST_TYPE (isym->st_info) == STT_GNU_IFUNC)
7047 h = elfNN_aarch64_get_local_sym_hash (htab, abfd, rel,
7052 /* Fake a STT_GNU_IFUNC symbol. */
7053 h->type = STT_GNU_IFUNC;
7056 h->forced_local = 1;
7057 h->root.type = bfd_link_hash_defined;
7064 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
7065 while (h->root.type == bfd_link_hash_indirect
7066 || h->root.type == bfd_link_hash_warning)
7067 h = (struct elf_link_hash_entry *) h->root.u.i.link;
7069 /* PR15323, ref flags aren't set for references in the same
7071 h->root.non_ir_ref = 1;
7074 /* Could be done earlier, if h were already available. */
7075 bfd_r_type = aarch64_tls_transition (abfd, info, r_type, h, r_symndx);
7079 /* If a relocation refers to _GLOBAL_OFFSET_TABLE_, create the .got.
7080 This shows up in particular in an R_AARCH64_PREL64 in large model
7081 when calculating the pc-relative address to .got section which is
7082 used to initialize the gp register. */
7083 if (h->root.root.string
7084 && strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0)
7086 if (htab->root.dynobj == NULL)
7087 htab->root.dynobj = abfd;
7089 if (! aarch64_elf_create_got_section (htab->root.dynobj, info))
7092 BFD_ASSERT (h == htab->root.hgot);
7095 /* Create the ifunc sections for static executables. If we
7096 never see an indirect function symbol nor we are building
7097 a static executable, those sections will be empty and
7098 won't appear in output. */
7104 case BFD_RELOC_AARCH64_ADD_LO12:
7105 case BFD_RELOC_AARCH64_ADR_GOT_PAGE:
7106 case BFD_RELOC_AARCH64_ADR_HI21_PCREL:
7107 case BFD_RELOC_AARCH64_CALL26:
7108 case BFD_RELOC_AARCH64_GOT_LD_PREL19:
7109 case BFD_RELOC_AARCH64_JUMP26:
7110 case BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14:
7111 case BFD_RELOC_AARCH64_LD32_GOT_LO12_NC:
7112 case BFD_RELOC_AARCH64_LD64_GOTOFF_LO15:
7113 case BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15:
7114 case BFD_RELOC_AARCH64_LD64_GOT_LO12_NC:
7115 case BFD_RELOC_AARCH64_MOVW_GOTOFF_G0_NC:
7116 case BFD_RELOC_AARCH64_MOVW_GOTOFF_G1:
7117 case BFD_RELOC_AARCH64_NN:
7118 if (htab->root.dynobj == NULL)
7119 htab->root.dynobj = abfd;
7120 if (!_bfd_elf_create_ifunc_sections (htab->root.dynobj, info))
7125 /* It is referenced by a non-shared object. */
7127 h->root.non_ir_ref = 1;
7132 case BFD_RELOC_AARCH64_NN:
7134 /* We don't need to handle relocs into sections not going into
7135 the "real" output. */
7136 if ((sec->flags & SEC_ALLOC) == 0)
7141 if (!bfd_link_pic (info))
7144 h->plt.refcount += 1;
7145 h->pointer_equality_needed = 1;
7148 /* No need to do anything if we're not creating a shared
7150 if (! bfd_link_pic (info))
7154 struct elf_dyn_relocs *p;
7155 struct elf_dyn_relocs **head;
7157 /* We must copy these reloc types into the output file.
7158 Create a reloc section in dynobj and make room for
7162 if (htab->root.dynobj == NULL)
7163 htab->root.dynobj = abfd;
7165 sreloc = _bfd_elf_make_dynamic_reloc_section
7166 (sec, htab->root.dynobj, LOG_FILE_ALIGN, abfd, /*rela? */ TRUE);
7172 /* If this is a global symbol, we count the number of
7173 relocations we need for this symbol. */
7176 struct elf_aarch64_link_hash_entry *eh;
7177 eh = (struct elf_aarch64_link_hash_entry *) h;
7178 head = &eh->dyn_relocs;
7182 /* Track dynamic relocs needed for local syms too.
7183 We really need local syms available to do this
7189 isym = bfd_sym_from_r_symndx (&htab->sym_cache,
7194 s = bfd_section_from_elf_index (abfd, isym->st_shndx);
7198 /* Beware of type punned pointers vs strict aliasing
7200 vpp = &(elf_section_data (s)->local_dynrel);
7201 head = (struct elf_dyn_relocs **) vpp;
7205 if (p == NULL || p->sec != sec)
7207 bfd_size_type amt = sizeof *p;
7208 p = ((struct elf_dyn_relocs *)
7209 bfd_zalloc (htab->root.dynobj, amt));
7222 /* RR: We probably want to keep a consistency check that
7223 there are no dangling GOT_PAGE relocs. */
7224 case BFD_RELOC_AARCH64_ADR_GOT_PAGE:
7225 case BFD_RELOC_AARCH64_GOT_LD_PREL19:
7226 case BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14:
7227 case BFD_RELOC_AARCH64_LD32_GOT_LO12_NC:
7228 case BFD_RELOC_AARCH64_LD64_GOTOFF_LO15:
7229 case BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15:
7230 case BFD_RELOC_AARCH64_LD64_GOT_LO12_NC:
7231 case BFD_RELOC_AARCH64_MOVW_GOTOFF_G0_NC:
7232 case BFD_RELOC_AARCH64_MOVW_GOTOFF_G1:
7233 case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12_NC:
7234 case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21:
7235 case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21:
7236 case BFD_RELOC_AARCH64_TLSDESC_LD32_LO12_NC:
7237 case BFD_RELOC_AARCH64_TLSDESC_LD64_LO12_NC:
7238 case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19:
7239 case BFD_RELOC_AARCH64_TLSDESC_OFF_G0_NC:
7240 case BFD_RELOC_AARCH64_TLSDESC_OFF_G1:
7241 case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC:
7242 case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21:
7243 case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21:
7244 case BFD_RELOC_AARCH64_TLSGD_MOVW_G0_NC:
7245 case BFD_RELOC_AARCH64_TLSGD_MOVW_G1:
7246 case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21:
7247 case BFD_RELOC_AARCH64_TLSIE_LD32_GOTTPREL_LO12_NC:
7248 case BFD_RELOC_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC:
7249 case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19:
7250 case BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G0_NC:
7251 case BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G1:
7252 case BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC:
7253 case BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21:
7254 case BFD_RELOC_AARCH64_TLSLD_ADR_PREL21:
7255 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1:
7256 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1_NC:
7257 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G2:
7260 unsigned old_got_type;
7262 got_type = aarch64_reloc_got_type (bfd_r_type);
7266 h->got.refcount += 1;
7267 old_got_type = elf_aarch64_hash_entry (h)->got_type;
7271 struct elf_aarch64_local_symbol *locals;
7273 if (!elfNN_aarch64_allocate_local_symbols
7274 (abfd, symtab_hdr->sh_info))
7277 locals = elf_aarch64_locals (abfd);
7278 BFD_ASSERT (r_symndx < symtab_hdr->sh_info);
7279 locals[r_symndx].got_refcount += 1;
7280 old_got_type = locals[r_symndx].got_type;
7283 /* If a variable is accessed with both general dynamic TLS
7284 methods, two slots may be created. */
7285 if (GOT_TLS_GD_ANY_P (old_got_type) && GOT_TLS_GD_ANY_P (got_type))
7286 got_type |= old_got_type;
7288 /* We will already have issued an error message if there
7289 is a TLS/non-TLS mismatch, based on the symbol type.
7290 So just combine any TLS types needed. */
7291 if (old_got_type != GOT_UNKNOWN && old_got_type != GOT_NORMAL
7292 && got_type != GOT_NORMAL)
7293 got_type |= old_got_type;
7295 /* If the symbol is accessed by both IE and GD methods, we
7296 are able to relax. Turn off the GD flag, without
7297 messing up with any other kind of TLS types that may be
7299 if ((got_type & GOT_TLS_IE) && GOT_TLS_GD_ANY_P (got_type))
7300 got_type &= ~ (GOT_TLSDESC_GD | GOT_TLS_GD);
7302 if (old_got_type != got_type)
7305 elf_aarch64_hash_entry (h)->got_type = got_type;
7308 struct elf_aarch64_local_symbol *locals;
7309 locals = elf_aarch64_locals (abfd);
7310 BFD_ASSERT (r_symndx < symtab_hdr->sh_info);
7311 locals[r_symndx].got_type = got_type;
7315 if (htab->root.dynobj == NULL)
7316 htab->root.dynobj = abfd;
7317 if (! aarch64_elf_create_got_section (htab->root.dynobj, info))
7322 case BFD_RELOC_AARCH64_MOVW_G0_NC:
7323 case BFD_RELOC_AARCH64_MOVW_G1_NC:
7324 case BFD_RELOC_AARCH64_MOVW_G2_NC:
7325 case BFD_RELOC_AARCH64_MOVW_G3:
7326 if (bfd_link_pic (info))
7328 int howto_index = bfd_r_type - BFD_RELOC_AARCH64_RELOC_START;
7329 (*_bfd_error_handler)
7330 (_("%B: relocation %s against `%s' can not be used when making "
7331 "a shared object; recompile with -fPIC"),
7332 abfd, elfNN_aarch64_howto_table[howto_index].name,
7333 (h) ? h->root.root.string : "a local symbol");
7334 bfd_set_error (bfd_error_bad_value);
7338 case BFD_RELOC_AARCH64_ADR_HI21_NC_PCREL:
7339 case BFD_RELOC_AARCH64_ADR_HI21_PCREL:
7340 case BFD_RELOC_AARCH64_ADR_LO21_PCREL:
7341 if (h != NULL && bfd_link_executable (info))
7343 /* If this reloc is in a read-only section, we might
7344 need a copy reloc. We can't check reliably at this
7345 stage whether the section is read-only, as input
7346 sections have not yet been mapped to output sections.
7347 Tentatively set the flag for now, and correct in
7348 adjust_dynamic_symbol. */
7350 h->plt.refcount += 1;
7351 h->pointer_equality_needed = 1;
7353 /* FIXME:: RR need to handle these in shared libraries
7354 and essentially bomb out as these being non-PIC
7355 relocations in shared libraries. */
7358 case BFD_RELOC_AARCH64_CALL26:
7359 case BFD_RELOC_AARCH64_JUMP26:
7360 /* If this is a local symbol then we resolve it
7361 directly without creating a PLT entry. */
7366 if (h->plt.refcount <= 0)
7367 h->plt.refcount = 1;
7369 h->plt.refcount += 1;
7380 /* Treat mapping symbols as special target symbols. */
7383 elfNN_aarch64_is_target_special_symbol (bfd *abfd ATTRIBUTE_UNUSED,
7386 return bfd_is_aarch64_special_symbol_name (sym->name,
7387 BFD_AARCH64_SPECIAL_SYM_TYPE_ANY);
7390 /* This is a copy of elf_find_function () from elf.c except that
7391 AArch64 mapping symbols are ignored when looking for function names. */
7394 aarch64_elf_find_function (bfd *abfd ATTRIBUTE_UNUSED,
7398 const char **filename_ptr,
7399 const char **functionname_ptr)
7401 const char *filename = NULL;
7402 asymbol *func = NULL;
7403 bfd_vma low_func = 0;
7406 for (p = symbols; *p != NULL; p++)
7410 q = (elf_symbol_type *) * p;
7412 switch (ELF_ST_TYPE (q->internal_elf_sym.st_info))
7417 filename = bfd_asymbol_name (&q->symbol);
7421 /* Skip mapping symbols. */
7422 if ((q->symbol.flags & BSF_LOCAL)
7423 && (bfd_is_aarch64_special_symbol_name
7424 (q->symbol.name, BFD_AARCH64_SPECIAL_SYM_TYPE_ANY)))
7427 if (bfd_get_section (&q->symbol) == section
7428 && q->symbol.value >= low_func && q->symbol.value <= offset)
7430 func = (asymbol *) q;
7431 low_func = q->symbol.value;
7441 *filename_ptr = filename;
7442 if (functionname_ptr)
7443 *functionname_ptr = bfd_asymbol_name (func);
7449 /* Find the nearest line to a particular section and offset, for error
7450 reporting. This code is a duplicate of the code in elf.c, except
7451 that it uses aarch64_elf_find_function. */
7454 elfNN_aarch64_find_nearest_line (bfd *abfd,
7458 const char **filename_ptr,
7459 const char **functionname_ptr,
7460 unsigned int *line_ptr,
7461 unsigned int *discriminator_ptr)
7463 bfd_boolean found = FALSE;
7465 if (_bfd_dwarf2_find_nearest_line (abfd, symbols, NULL, section, offset,
7466 filename_ptr, functionname_ptr,
7467 line_ptr, discriminator_ptr,
7468 dwarf_debug_sections, 0,
7469 &elf_tdata (abfd)->dwarf2_find_line_info))
7471 if (!*functionname_ptr)
7472 aarch64_elf_find_function (abfd, symbols, section, offset,
7473 *filename_ptr ? NULL : filename_ptr,
7479 /* Skip _bfd_dwarf1_find_nearest_line since no known AArch64
7480 toolchain uses DWARF1. */
7482 if (!_bfd_stab_section_find_nearest_line (abfd, symbols, section, offset,
7483 &found, filename_ptr,
7484 functionname_ptr, line_ptr,
7485 &elf_tdata (abfd)->line_info))
7488 if (found && (*functionname_ptr || *line_ptr))
7491 if (symbols == NULL)
7494 if (!aarch64_elf_find_function (abfd, symbols, section, offset,
7495 filename_ptr, functionname_ptr))
7503 elfNN_aarch64_find_inliner_info (bfd *abfd,
7504 const char **filename_ptr,
7505 const char **functionname_ptr,
7506 unsigned int *line_ptr)
7509 found = _bfd_dwarf2_find_inliner_info
7510 (abfd, filename_ptr,
7511 functionname_ptr, line_ptr, &elf_tdata (abfd)->dwarf2_find_line_info);
7517 elfNN_aarch64_post_process_headers (bfd *abfd,
7518 struct bfd_link_info *link_info)
7520 Elf_Internal_Ehdr *i_ehdrp; /* ELF file header, internal form. */
7522 i_ehdrp = elf_elfheader (abfd);
7523 i_ehdrp->e_ident[EI_ABIVERSION] = AARCH64_ELF_ABI_VERSION;
7525 _bfd_elf_post_process_headers (abfd, link_info);
7528 static enum elf_reloc_type_class
7529 elfNN_aarch64_reloc_type_class (const struct bfd_link_info *info ATTRIBUTE_UNUSED,
7530 const asection *rel_sec ATTRIBUTE_UNUSED,
7531 const Elf_Internal_Rela *rela)
7533 switch ((int) ELFNN_R_TYPE (rela->r_info))
7535 case AARCH64_R (RELATIVE):
7536 return reloc_class_relative;
7537 case AARCH64_R (JUMP_SLOT):
7538 return reloc_class_plt;
7539 case AARCH64_R (COPY):
7540 return reloc_class_copy;
7542 return reloc_class_normal;
7546 /* Handle an AArch64 specific section when reading an object file. This is
7547 called when bfd_section_from_shdr finds a section with an unknown
7551 elfNN_aarch64_section_from_shdr (bfd *abfd,
7552 Elf_Internal_Shdr *hdr,
7553 const char *name, int shindex)
7555 /* There ought to be a place to keep ELF backend specific flags, but
7556 at the moment there isn't one. We just keep track of the
7557 sections by their name, instead. Fortunately, the ABI gives
7558 names for all the AArch64 specific sections, so we will probably get
7560 switch (hdr->sh_type)
7562 case SHT_AARCH64_ATTRIBUTES:
7569 if (!_bfd_elf_make_section_from_shdr (abfd, hdr, name, shindex))
7575 /* A structure used to record a list of sections, independently
7576 of the next and prev fields in the asection structure. */
7577 typedef struct section_list
7580 struct section_list *next;
7581 struct section_list *prev;
7585 /* Unfortunately we need to keep a list of sections for which
7586 an _aarch64_elf_section_data structure has been allocated. This
7587 is because it is possible for functions like elfNN_aarch64_write_section
7588 to be called on a section which has had an elf_data_structure
7589 allocated for it (and so the used_by_bfd field is valid) but
7590 for which the AArch64 extended version of this structure - the
7591 _aarch64_elf_section_data structure - has not been allocated. */
7592 static section_list *sections_with_aarch64_elf_section_data = NULL;
7595 record_section_with_aarch64_elf_section_data (asection *sec)
7597 struct section_list *entry;
7599 entry = bfd_malloc (sizeof (*entry));
7603 entry->next = sections_with_aarch64_elf_section_data;
7605 if (entry->next != NULL)
7606 entry->next->prev = entry;
7607 sections_with_aarch64_elf_section_data = entry;
7610 static struct section_list *
7611 find_aarch64_elf_section_entry (asection *sec)
7613 struct section_list *entry;
7614 static struct section_list *last_entry = NULL;
7616 /* This is a short cut for the typical case where the sections are added
7617 to the sections_with_aarch64_elf_section_data list in forward order and
7618 then looked up here in backwards order. This makes a real difference
7619 to the ld-srec/sec64k.exp linker test. */
7620 entry = sections_with_aarch64_elf_section_data;
7621 if (last_entry != NULL)
7623 if (last_entry->sec == sec)
7625 else if (last_entry->next != NULL && last_entry->next->sec == sec)
7626 entry = last_entry->next;
7629 for (; entry; entry = entry->next)
7630 if (entry->sec == sec)
7634 /* Record the entry prior to this one - it is the entry we are
7635 most likely to want to locate next time. Also this way if we
7636 have been called from
7637 unrecord_section_with_aarch64_elf_section_data () we will not
7638 be caching a pointer that is about to be freed. */
7639 last_entry = entry->prev;
7645 unrecord_section_with_aarch64_elf_section_data (asection *sec)
7647 struct section_list *entry;
7649 entry = find_aarch64_elf_section_entry (sec);
7653 if (entry->prev != NULL)
7654 entry->prev->next = entry->next;
7655 if (entry->next != NULL)
7656 entry->next->prev = entry->prev;
7657 if (entry == sections_with_aarch64_elf_section_data)
7658 sections_with_aarch64_elf_section_data = entry->next;
7667 struct bfd_link_info *info;
7670 int (*func) (void *, const char *, Elf_Internal_Sym *,
7671 asection *, struct elf_link_hash_entry *);
7672 } output_arch_syminfo;
7674 enum map_symbol_type
7681 /* Output a single mapping symbol. */
7684 elfNN_aarch64_output_map_sym (output_arch_syminfo *osi,
7685 enum map_symbol_type type, bfd_vma offset)
7687 static const char *names[2] = { "$x", "$d" };
7688 Elf_Internal_Sym sym;
7690 sym.st_value = (osi->sec->output_section->vma
7691 + osi->sec->output_offset + offset);
7694 sym.st_info = ELF_ST_INFO (STB_LOCAL, STT_NOTYPE);
7695 sym.st_shndx = osi->sec_shndx;
7696 return osi->func (osi->finfo, names[type], &sym, osi->sec, NULL) == 1;
7699 /* Output a single local symbol for a generated stub. */
7702 elfNN_aarch64_output_stub_sym (output_arch_syminfo *osi, const char *name,
7703 bfd_vma offset, bfd_vma size)
7705 Elf_Internal_Sym sym;
7707 sym.st_value = (osi->sec->output_section->vma
7708 + osi->sec->output_offset + offset);
7711 sym.st_info = ELF_ST_INFO (STB_LOCAL, STT_FUNC);
7712 sym.st_shndx = osi->sec_shndx;
7713 return osi->func (osi->finfo, name, &sym, osi->sec, NULL) == 1;
7717 aarch64_map_one_stub (struct bfd_hash_entry *gen_entry, void *in_arg)
7719 struct elf_aarch64_stub_hash_entry *stub_entry;
7723 output_arch_syminfo *osi;
7725 /* Massage our args to the form they really have. */
7726 stub_entry = (struct elf_aarch64_stub_hash_entry *) gen_entry;
7727 osi = (output_arch_syminfo *) in_arg;
7729 stub_sec = stub_entry->stub_sec;
7731 /* Ensure this stub is attached to the current section being
7733 if (stub_sec != osi->sec)
7736 addr = (bfd_vma) stub_entry->stub_offset;
7738 stub_name = stub_entry->output_name;
7740 switch (stub_entry->stub_type)
7742 case aarch64_stub_adrp_branch:
7743 if (!elfNN_aarch64_output_stub_sym (osi, stub_name, addr,
7744 sizeof (aarch64_adrp_branch_stub)))
7746 if (!elfNN_aarch64_output_map_sym (osi, AARCH64_MAP_INSN, addr))
7749 case aarch64_stub_long_branch:
7750 if (!elfNN_aarch64_output_stub_sym
7751 (osi, stub_name, addr, sizeof (aarch64_long_branch_stub)))
7753 if (!elfNN_aarch64_output_map_sym (osi, AARCH64_MAP_INSN, addr))
7755 if (!elfNN_aarch64_output_map_sym (osi, AARCH64_MAP_DATA, addr + 16))
7758 case aarch64_stub_erratum_835769_veneer:
7759 if (!elfNN_aarch64_output_stub_sym (osi, stub_name, addr,
7760 sizeof (aarch64_erratum_835769_stub)))
7762 if (!elfNN_aarch64_output_map_sym (osi, AARCH64_MAP_INSN, addr))
7765 case aarch64_stub_erratum_843419_veneer:
7766 if (!elfNN_aarch64_output_stub_sym (osi, stub_name, addr,
7767 sizeof (aarch64_erratum_843419_stub)))
7769 if (!elfNN_aarch64_output_map_sym (osi, AARCH64_MAP_INSN, addr))
7780 /* Output mapping symbols for linker generated sections. */
7783 elfNN_aarch64_output_arch_local_syms (bfd *output_bfd,
7784 struct bfd_link_info *info,
7786 int (*func) (void *, const char *,
7789 struct elf_link_hash_entry
7792 output_arch_syminfo osi;
7793 struct elf_aarch64_link_hash_table *htab;
7795 htab = elf_aarch64_hash_table (info);
7801 /* Long calls stubs. */
7802 if (htab->stub_bfd && htab->stub_bfd->sections)
7806 for (stub_sec = htab->stub_bfd->sections;
7807 stub_sec != NULL; stub_sec = stub_sec->next)
7809 /* Ignore non-stub sections. */
7810 if (!strstr (stub_sec->name, STUB_SUFFIX))
7815 osi.sec_shndx = _bfd_elf_section_from_bfd_section
7816 (output_bfd, osi.sec->output_section);
7818 /* The first instruction in a stub is always a branch. */
7819 if (!elfNN_aarch64_output_map_sym (&osi, AARCH64_MAP_INSN, 0))
7822 bfd_hash_traverse (&htab->stub_hash_table, aarch64_map_one_stub,
7827 /* Finally, output mapping symbols for the PLT. */
7828 if (!htab->root.splt || htab->root.splt->size == 0)
7831 osi.sec_shndx = _bfd_elf_section_from_bfd_section
7832 (output_bfd, htab->root.splt->output_section);
7833 osi.sec = htab->root.splt;
7835 elfNN_aarch64_output_map_sym (&osi, AARCH64_MAP_INSN, 0);
7841 /* Allocate target specific section data. */
7844 elfNN_aarch64_new_section_hook (bfd *abfd, asection *sec)
7846 if (!sec->used_by_bfd)
7848 _aarch64_elf_section_data *sdata;
7849 bfd_size_type amt = sizeof (*sdata);
7851 sdata = bfd_zalloc (abfd, amt);
7854 sec->used_by_bfd = sdata;
7857 record_section_with_aarch64_elf_section_data (sec);
7859 return _bfd_elf_new_section_hook (abfd, sec);
7864 unrecord_section_via_map_over_sections (bfd *abfd ATTRIBUTE_UNUSED,
7866 void *ignore ATTRIBUTE_UNUSED)
7868 unrecord_section_with_aarch64_elf_section_data (sec);
7872 elfNN_aarch64_close_and_cleanup (bfd *abfd)
7875 bfd_map_over_sections (abfd,
7876 unrecord_section_via_map_over_sections, NULL);
7878 return _bfd_elf_close_and_cleanup (abfd);
7882 elfNN_aarch64_bfd_free_cached_info (bfd *abfd)
7885 bfd_map_over_sections (abfd,
7886 unrecord_section_via_map_over_sections, NULL);
7888 return _bfd_free_cached_info (abfd);
7891 /* Create dynamic sections. This is different from the ARM backend in that
7892 the got, plt, gotplt and their relocation sections are all created in the
7893 standard part of the bfd elf backend. */
7896 elfNN_aarch64_create_dynamic_sections (bfd *dynobj,
7897 struct bfd_link_info *info)
7899 struct elf_aarch64_link_hash_table *htab;
7901 /* We need to create .got section. */
7902 if (!aarch64_elf_create_got_section (dynobj, info))
7905 if (!_bfd_elf_create_dynamic_sections (dynobj, info))
7908 htab = elf_aarch64_hash_table (info);
7909 htab->sdynbss = bfd_get_linker_section (dynobj, ".dynbss");
7910 if (!bfd_link_pic (info))
7911 htab->srelbss = bfd_get_linker_section (dynobj, ".rela.bss");
7913 if (!htab->sdynbss || (!bfd_link_pic (info) && !htab->srelbss))
7920 /* Allocate space in .plt, .got and associated reloc sections for
7924 elfNN_aarch64_allocate_dynrelocs (struct elf_link_hash_entry *h, void *inf)
7926 struct bfd_link_info *info;
7927 struct elf_aarch64_link_hash_table *htab;
7928 struct elf_aarch64_link_hash_entry *eh;
7929 struct elf_dyn_relocs *p;
7931 /* An example of a bfd_link_hash_indirect symbol is versioned
7932 symbol. For example: __gxx_personality_v0(bfd_link_hash_indirect)
7933 -> __gxx_personality_v0(bfd_link_hash_defined)
7935 There is no need to process bfd_link_hash_indirect symbols here
7936 because we will also be presented with the concrete instance of
7937 the symbol and elfNN_aarch64_copy_indirect_symbol () will have been
7938 called to copy all relevant data from the generic to the concrete
7941 if (h->root.type == bfd_link_hash_indirect)
7944 if (h->root.type == bfd_link_hash_warning)
7945 h = (struct elf_link_hash_entry *) h->root.u.i.link;
7947 info = (struct bfd_link_info *) inf;
7948 htab = elf_aarch64_hash_table (info);
7950 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle it
7951 here if it is defined and referenced in a non-shared object. */
7952 if (h->type == STT_GNU_IFUNC
7955 else if (htab->root.dynamic_sections_created && h->plt.refcount > 0)
7957 /* Make sure this symbol is output as a dynamic symbol.
7958 Undefined weak syms won't yet be marked as dynamic. */
7959 if (h->dynindx == -1 && !h->forced_local)
7961 if (!bfd_elf_link_record_dynamic_symbol (info, h))
7965 if (bfd_link_pic (info) || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h))
7967 asection *s = htab->root.splt;
7969 /* If this is the first .plt entry, make room for the special
7972 s->size += htab->plt_header_size;
7974 h->plt.offset = s->size;
7976 /* If this symbol is not defined in a regular file, and we are
7977 not generating a shared library, then set the symbol to this
7978 location in the .plt. This is required to make function
7979 pointers compare as equal between the normal executable and
7980 the shared library. */
7981 if (!bfd_link_pic (info) && !h->def_regular)
7983 h->root.u.def.section = s;
7984 h->root.u.def.value = h->plt.offset;
7987 /* Make room for this entry. For now we only create the
7988 small model PLT entries. We later need to find a way
7989 of relaxing into these from the large model PLT entries. */
7990 s->size += PLT_SMALL_ENTRY_SIZE;
7992 /* We also need to make an entry in the .got.plt section, which
7993 will be placed in the .got section by the linker script. */
7994 htab->root.sgotplt->size += GOT_ENTRY_SIZE;
7996 /* We also need to make an entry in the .rela.plt section. */
7997 htab->root.srelplt->size += RELOC_SIZE (htab);
7999 /* We need to ensure that all GOT entries that serve the PLT
8000 are consecutive with the special GOT slots [0] [1] and
8001 [2]. Any addtional relocations, such as
8002 R_AARCH64_TLSDESC, must be placed after the PLT related
8003 entries. We abuse the reloc_count such that during
8004 sizing we adjust reloc_count to indicate the number of
8005 PLT related reserved entries. In subsequent phases when
8006 filling in the contents of the reloc entries, PLT related
8007 entries are placed by computing their PLT index (0
8008 .. reloc_count). While other none PLT relocs are placed
8009 at the slot indicated by reloc_count and reloc_count is
8012 htab->root.srelplt->reloc_count++;
8016 h->plt.offset = (bfd_vma) - 1;
8022 h->plt.offset = (bfd_vma) - 1;
8026 eh = (struct elf_aarch64_link_hash_entry *) h;
8027 eh->tlsdesc_got_jump_table_offset = (bfd_vma) - 1;
8029 if (h->got.refcount > 0)
8032 unsigned got_type = elf_aarch64_hash_entry (h)->got_type;
8034 h->got.offset = (bfd_vma) - 1;
8036 dyn = htab->root.dynamic_sections_created;
8038 /* Make sure this symbol is output as a dynamic symbol.
8039 Undefined weak syms won't yet be marked as dynamic. */
8040 if (dyn && h->dynindx == -1 && !h->forced_local)
8042 if (!bfd_elf_link_record_dynamic_symbol (info, h))
8046 if (got_type == GOT_UNKNOWN)
8049 else if (got_type == GOT_NORMAL)
8051 h->got.offset = htab->root.sgot->size;
8052 htab->root.sgot->size += GOT_ENTRY_SIZE;
8053 if ((ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
8054 || h->root.type != bfd_link_hash_undefweak)
8055 && (bfd_link_pic (info)
8056 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, 0, h)))
8058 htab->root.srelgot->size += RELOC_SIZE (htab);
8064 if (got_type & GOT_TLSDESC_GD)
8066 eh->tlsdesc_got_jump_table_offset =
8067 (htab->root.sgotplt->size
8068 - aarch64_compute_jump_table_size (htab));
8069 htab->root.sgotplt->size += GOT_ENTRY_SIZE * 2;
8070 h->got.offset = (bfd_vma) - 2;
8073 if (got_type & GOT_TLS_GD)
8075 h->got.offset = htab->root.sgot->size;
8076 htab->root.sgot->size += GOT_ENTRY_SIZE * 2;
8079 if (got_type & GOT_TLS_IE)
8081 h->got.offset = htab->root.sgot->size;
8082 htab->root.sgot->size += GOT_ENTRY_SIZE;
8085 indx = h && h->dynindx != -1 ? h->dynindx : 0;
8086 if ((ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
8087 || h->root.type != bfd_link_hash_undefweak)
8088 && (bfd_link_pic (info)
8090 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, 0, h)))
8092 if (got_type & GOT_TLSDESC_GD)
8094 htab->root.srelplt->size += RELOC_SIZE (htab);
8095 /* Note reloc_count not incremented here! We have
8096 already adjusted reloc_count for this relocation
8099 /* TLSDESC PLT is now needed, but not yet determined. */
8100 htab->tlsdesc_plt = (bfd_vma) - 1;
8103 if (got_type & GOT_TLS_GD)
8104 htab->root.srelgot->size += RELOC_SIZE (htab) * 2;
8106 if (got_type & GOT_TLS_IE)
8107 htab->root.srelgot->size += RELOC_SIZE (htab);
8113 h->got.offset = (bfd_vma) - 1;
8116 if (eh->dyn_relocs == NULL)
8119 /* In the shared -Bsymbolic case, discard space allocated for
8120 dynamic pc-relative relocs against symbols which turn out to be
8121 defined in regular objects. For the normal shared case, discard
8122 space for pc-relative relocs that have become local due to symbol
8123 visibility changes. */
8125 if (bfd_link_pic (info))
8127 /* Relocs that use pc_count are those that appear on a call
8128 insn, or certain REL relocs that can generated via assembly.
8129 We want calls to protected symbols to resolve directly to the
8130 function rather than going via the plt. If people want
8131 function pointer comparisons to work as expected then they
8132 should avoid writing weird assembly. */
8133 if (SYMBOL_CALLS_LOCAL (info, h))
8135 struct elf_dyn_relocs **pp;
8137 for (pp = &eh->dyn_relocs; (p = *pp) != NULL;)
8139 p->count -= p->pc_count;
8148 /* Also discard relocs on undefined weak syms with non-default
8150 if (eh->dyn_relocs != NULL && h->root.type == bfd_link_hash_undefweak)
8152 if (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT)
8153 eh->dyn_relocs = NULL;
8155 /* Make sure undefined weak symbols are output as a dynamic
8157 else if (h->dynindx == -1
8159 && !bfd_elf_link_record_dynamic_symbol (info, h))
8164 else if (ELIMINATE_COPY_RELOCS)
8166 /* For the non-shared case, discard space for relocs against
8167 symbols which turn out to need copy relocs or are not
8173 || (htab->root.dynamic_sections_created
8174 && (h->root.type == bfd_link_hash_undefweak
8175 || h->root.type == bfd_link_hash_undefined))))
8177 /* Make sure this symbol is output as a dynamic symbol.
8178 Undefined weak syms won't yet be marked as dynamic. */
8179 if (h->dynindx == -1
8181 && !bfd_elf_link_record_dynamic_symbol (info, h))
8184 /* If that succeeded, we know we'll be keeping all the
8186 if (h->dynindx != -1)
8190 eh->dyn_relocs = NULL;
8195 /* Finally, allocate space. */
8196 for (p = eh->dyn_relocs; p != NULL; p = p->next)
8200 sreloc = elf_section_data (p->sec)->sreloc;
8202 BFD_ASSERT (sreloc != NULL);
8204 sreloc->size += p->count * RELOC_SIZE (htab);
8210 /* Allocate space in .plt, .got and associated reloc sections for
8211 ifunc dynamic relocs. */
8214 elfNN_aarch64_allocate_ifunc_dynrelocs (struct elf_link_hash_entry *h,
8217 struct bfd_link_info *info;
8218 struct elf_aarch64_link_hash_table *htab;
8219 struct elf_aarch64_link_hash_entry *eh;
8221 /* An example of a bfd_link_hash_indirect symbol is versioned
8222 symbol. For example: __gxx_personality_v0(bfd_link_hash_indirect)
8223 -> __gxx_personality_v0(bfd_link_hash_defined)
8225 There is no need to process bfd_link_hash_indirect symbols here
8226 because we will also be presented with the concrete instance of
8227 the symbol and elfNN_aarch64_copy_indirect_symbol () will have been
8228 called to copy all relevant data from the generic to the concrete
8231 if (h->root.type == bfd_link_hash_indirect)
8234 if (h->root.type == bfd_link_hash_warning)
8235 h = (struct elf_link_hash_entry *) h->root.u.i.link;
8237 info = (struct bfd_link_info *) inf;
8238 htab = elf_aarch64_hash_table (info);
8240 eh = (struct elf_aarch64_link_hash_entry *) h;
8242 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle it
8243 here if it is defined and referenced in a non-shared object. */
8244 if (h->type == STT_GNU_IFUNC
8246 return _bfd_elf_allocate_ifunc_dyn_relocs (info, h,
8249 htab->plt_entry_size,
8250 htab->plt_header_size,
8255 /* Allocate space in .plt, .got and associated reloc sections for
8256 local dynamic relocs. */
8259 elfNN_aarch64_allocate_local_dynrelocs (void **slot, void *inf)
8261 struct elf_link_hash_entry *h
8262 = (struct elf_link_hash_entry *) *slot;
8264 if (h->type != STT_GNU_IFUNC
8268 || h->root.type != bfd_link_hash_defined)
8271 return elfNN_aarch64_allocate_dynrelocs (h, inf);
8274 /* Allocate space in .plt, .got and associated reloc sections for
8275 local ifunc dynamic relocs. */
8278 elfNN_aarch64_allocate_local_ifunc_dynrelocs (void **slot, void *inf)
8280 struct elf_link_hash_entry *h
8281 = (struct elf_link_hash_entry *) *slot;
8283 if (h->type != STT_GNU_IFUNC
8287 || h->root.type != bfd_link_hash_defined)
8290 return elfNN_aarch64_allocate_ifunc_dynrelocs (h, inf);
8293 /* Find any dynamic relocs that apply to read-only sections. */
8296 aarch64_readonly_dynrelocs (struct elf_link_hash_entry * h, void * inf)
8298 struct elf_aarch64_link_hash_entry * eh;
8299 struct elf_dyn_relocs * p;
8301 eh = (struct elf_aarch64_link_hash_entry *) h;
8302 for (p = eh->dyn_relocs; p != NULL; p = p->next)
8304 asection *s = p->sec;
8306 if (s != NULL && (s->flags & SEC_READONLY) != 0)
8308 struct bfd_link_info *info = (struct bfd_link_info *) inf;
8310 info->flags |= DF_TEXTREL;
8312 /* Not an error, just cut short the traversal. */
8319 /* This is the most important function of all . Innocuosly named
8322 elfNN_aarch64_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
8323 struct bfd_link_info *info)
8325 struct elf_aarch64_link_hash_table *htab;
8331 htab = elf_aarch64_hash_table ((info));
8332 dynobj = htab->root.dynobj;
8334 BFD_ASSERT (dynobj != NULL);
8336 if (htab->root.dynamic_sections_created)
8338 if (bfd_link_executable (info) && !info->nointerp)
8340 s = bfd_get_linker_section (dynobj, ".interp");
8343 s->size = sizeof ELF_DYNAMIC_INTERPRETER;
8344 s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
8348 /* Set up .got offsets for local syms, and space for local dynamic
8350 for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link.next)
8352 struct elf_aarch64_local_symbol *locals = NULL;
8353 Elf_Internal_Shdr *symtab_hdr;
8357 if (!is_aarch64_elf (ibfd))
8360 for (s = ibfd->sections; s != NULL; s = s->next)
8362 struct elf_dyn_relocs *p;
8364 for (p = (struct elf_dyn_relocs *)
8365 (elf_section_data (s)->local_dynrel); p != NULL; p = p->next)
8367 if (!bfd_is_abs_section (p->sec)
8368 && bfd_is_abs_section (p->sec->output_section))
8370 /* Input section has been discarded, either because
8371 it is a copy of a linkonce section or due to
8372 linker script /DISCARD/, so we'll be discarding
8375 else if (p->count != 0)
8377 srel = elf_section_data (p->sec)->sreloc;
8378 srel->size += p->count * RELOC_SIZE (htab);
8379 if ((p->sec->output_section->flags & SEC_READONLY) != 0)
8380 info->flags |= DF_TEXTREL;
8385 locals = elf_aarch64_locals (ibfd);
8389 symtab_hdr = &elf_symtab_hdr (ibfd);
8390 srel = htab->root.srelgot;
8391 for (i = 0; i < symtab_hdr->sh_info; i++)
8393 locals[i].got_offset = (bfd_vma) - 1;
8394 locals[i].tlsdesc_got_jump_table_offset = (bfd_vma) - 1;
8395 if (locals[i].got_refcount > 0)
8397 unsigned got_type = locals[i].got_type;
8398 if (got_type & GOT_TLSDESC_GD)
8400 locals[i].tlsdesc_got_jump_table_offset =
8401 (htab->root.sgotplt->size
8402 - aarch64_compute_jump_table_size (htab));
8403 htab->root.sgotplt->size += GOT_ENTRY_SIZE * 2;
8404 locals[i].got_offset = (bfd_vma) - 2;
8407 if (got_type & GOT_TLS_GD)
8409 locals[i].got_offset = htab->root.sgot->size;
8410 htab->root.sgot->size += GOT_ENTRY_SIZE * 2;
8413 if (got_type & GOT_TLS_IE
8414 || got_type & GOT_NORMAL)
8416 locals[i].got_offset = htab->root.sgot->size;
8417 htab->root.sgot->size += GOT_ENTRY_SIZE;
8420 if (got_type == GOT_UNKNOWN)
8424 if (bfd_link_pic (info))
8426 if (got_type & GOT_TLSDESC_GD)
8428 htab->root.srelplt->size += RELOC_SIZE (htab);
8429 /* Note RELOC_COUNT not incremented here! */
8430 htab->tlsdesc_plt = (bfd_vma) - 1;
8433 if (got_type & GOT_TLS_GD)
8434 htab->root.srelgot->size += RELOC_SIZE (htab) * 2;
8436 if (got_type & GOT_TLS_IE
8437 || got_type & GOT_NORMAL)
8438 htab->root.srelgot->size += RELOC_SIZE (htab);
8443 locals[i].got_refcount = (bfd_vma) - 1;
8449 /* Allocate global sym .plt and .got entries, and space for global
8450 sym dynamic relocs. */
8451 elf_link_hash_traverse (&htab->root, elfNN_aarch64_allocate_dynrelocs,
8454 /* Allocate global ifunc sym .plt and .got entries, and space for global
8455 ifunc sym dynamic relocs. */
8456 elf_link_hash_traverse (&htab->root, elfNN_aarch64_allocate_ifunc_dynrelocs,
8459 /* Allocate .plt and .got entries, and space for local symbols. */
8460 htab_traverse (htab->loc_hash_table,
8461 elfNN_aarch64_allocate_local_dynrelocs,
8464 /* Allocate .plt and .got entries, and space for local ifunc symbols. */
8465 htab_traverse (htab->loc_hash_table,
8466 elfNN_aarch64_allocate_local_ifunc_dynrelocs,
8469 /* For every jump slot reserved in the sgotplt, reloc_count is
8470 incremented. However, when we reserve space for TLS descriptors,
8471 it's not incremented, so in order to compute the space reserved
8472 for them, it suffices to multiply the reloc count by the jump
8475 if (htab->root.srelplt)
8476 htab->sgotplt_jump_table_size = aarch64_compute_jump_table_size (htab);
8478 if (htab->tlsdesc_plt)
8480 if (htab->root.splt->size == 0)
8481 htab->root.splt->size += PLT_ENTRY_SIZE;
8483 htab->tlsdesc_plt = htab->root.splt->size;
8484 htab->root.splt->size += PLT_TLSDESC_ENTRY_SIZE;
8486 /* If we're not using lazy TLS relocations, don't generate the
8487 GOT entry required. */
8488 if (!(info->flags & DF_BIND_NOW))
8490 htab->dt_tlsdesc_got = htab->root.sgot->size;
8491 htab->root.sgot->size += GOT_ENTRY_SIZE;
8495 /* Init mapping symbols information to use later to distingush between
8496 code and data while scanning for errata. */
8497 if (htab->fix_erratum_835769 || htab->fix_erratum_843419)
8498 for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link.next)
8500 if (!is_aarch64_elf (ibfd))
8502 bfd_elfNN_aarch64_init_maps (ibfd);
8505 /* We now have determined the sizes of the various dynamic sections.
8506 Allocate memory for them. */
8508 for (s = dynobj->sections; s != NULL; s = s->next)
8510 if ((s->flags & SEC_LINKER_CREATED) == 0)
8513 if (s == htab->root.splt
8514 || s == htab->root.sgot
8515 || s == htab->root.sgotplt
8516 || s == htab->root.iplt
8517 || s == htab->root.igotplt || s == htab->sdynbss)
8519 /* Strip this section if we don't need it; see the
8522 else if (CONST_STRNEQ (bfd_get_section_name (dynobj, s), ".rela"))
8524 if (s->size != 0 && s != htab->root.srelplt)
8527 /* We use the reloc_count field as a counter if we need
8528 to copy relocs into the output file. */
8529 if (s != htab->root.srelplt)
8534 /* It's not one of our sections, so don't allocate space. */
8540 /* If we don't need this section, strip it from the
8541 output file. This is mostly to handle .rela.bss and
8542 .rela.plt. We must create both sections in
8543 create_dynamic_sections, because they must be created
8544 before the linker maps input sections to output
8545 sections. The linker does that before
8546 adjust_dynamic_symbol is called, and it is that
8547 function which decides whether anything needs to go
8548 into these sections. */
8550 s->flags |= SEC_EXCLUDE;
8554 if ((s->flags & SEC_HAS_CONTENTS) == 0)
8557 /* Allocate memory for the section contents. We use bfd_zalloc
8558 here in case unused entries are not reclaimed before the
8559 section's contents are written out. This should not happen,
8560 but this way if it does, we get a R_AARCH64_NONE reloc instead
8562 s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->size);
8563 if (s->contents == NULL)
8567 if (htab->root.dynamic_sections_created)
8569 /* Add some entries to the .dynamic section. We fill in the
8570 values later, in elfNN_aarch64_finish_dynamic_sections, but we
8571 must add the entries now so that we get the correct size for
8572 the .dynamic section. The DT_DEBUG entry is filled in by the
8573 dynamic linker and used by the debugger. */
8574 #define add_dynamic_entry(TAG, VAL) \
8575 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
8577 if (bfd_link_executable (info))
8579 if (!add_dynamic_entry (DT_DEBUG, 0))
8583 if (htab->root.splt->size != 0)
8585 if (!add_dynamic_entry (DT_PLTGOT, 0)
8586 || !add_dynamic_entry (DT_PLTRELSZ, 0)
8587 || !add_dynamic_entry (DT_PLTREL, DT_RELA)
8588 || !add_dynamic_entry (DT_JMPREL, 0))
8591 if (htab->tlsdesc_plt
8592 && (!add_dynamic_entry (DT_TLSDESC_PLT, 0)
8593 || !add_dynamic_entry (DT_TLSDESC_GOT, 0)))
8599 if (!add_dynamic_entry (DT_RELA, 0)
8600 || !add_dynamic_entry (DT_RELASZ, 0)
8601 || !add_dynamic_entry (DT_RELAENT, RELOC_SIZE (htab)))
8604 /* If any dynamic relocs apply to a read-only section,
8605 then we need a DT_TEXTREL entry. */
8606 if ((info->flags & DF_TEXTREL) == 0)
8607 elf_link_hash_traverse (& htab->root, aarch64_readonly_dynrelocs,
8610 if ((info->flags & DF_TEXTREL) != 0)
8612 if (!add_dynamic_entry (DT_TEXTREL, 0))
8617 #undef add_dynamic_entry
8623 elf_aarch64_update_plt_entry (bfd *output_bfd,
8624 bfd_reloc_code_real_type r_type,
8625 bfd_byte *plt_entry, bfd_vma value)
8627 reloc_howto_type *howto = elfNN_aarch64_howto_from_bfd_reloc (r_type);
8629 _bfd_aarch64_elf_put_addend (output_bfd, plt_entry, r_type, howto, value);
8633 elfNN_aarch64_create_small_pltn_entry (struct elf_link_hash_entry *h,
8634 struct elf_aarch64_link_hash_table
8635 *htab, bfd *output_bfd,
8636 struct bfd_link_info *info)
8638 bfd_byte *plt_entry;
8641 bfd_vma gotplt_entry_address;
8642 bfd_vma plt_entry_address;
8643 Elf_Internal_Rela rela;
8645 asection *plt, *gotplt, *relplt;
8647 /* When building a static executable, use .iplt, .igot.plt and
8648 .rela.iplt sections for STT_GNU_IFUNC symbols. */
8649 if (htab->root.splt != NULL)
8651 plt = htab->root.splt;
8652 gotplt = htab->root.sgotplt;
8653 relplt = htab->root.srelplt;
8657 plt = htab->root.iplt;
8658 gotplt = htab->root.igotplt;
8659 relplt = htab->root.irelplt;
8662 /* Get the index in the procedure linkage table which
8663 corresponds to this symbol. This is the index of this symbol
8664 in all the symbols for which we are making plt entries. The
8665 first entry in the procedure linkage table is reserved.
8667 Get the offset into the .got table of the entry that
8668 corresponds to this function. Each .got entry is GOT_ENTRY_SIZE
8669 bytes. The first three are reserved for the dynamic linker.
8671 For static executables, we don't reserve anything. */
8673 if (plt == htab->root.splt)
8675 plt_index = (h->plt.offset - htab->plt_header_size) / htab->plt_entry_size;
8676 got_offset = (plt_index + 3) * GOT_ENTRY_SIZE;
8680 plt_index = h->plt.offset / htab->plt_entry_size;
8681 got_offset = plt_index * GOT_ENTRY_SIZE;
8684 plt_entry = plt->contents + h->plt.offset;
8685 plt_entry_address = plt->output_section->vma
8686 + plt->output_offset + h->plt.offset;
8687 gotplt_entry_address = gotplt->output_section->vma +
8688 gotplt->output_offset + got_offset;
8690 /* Copy in the boiler-plate for the PLTn entry. */
8691 memcpy (plt_entry, elfNN_aarch64_small_plt_entry, PLT_SMALL_ENTRY_SIZE);
8693 /* Fill in the top 21 bits for this: ADRP x16, PLT_GOT + n * 8.
8694 ADRP: ((PG(S+A)-PG(P)) >> 12) & 0x1fffff */
8695 elf_aarch64_update_plt_entry (output_bfd, BFD_RELOC_AARCH64_ADR_HI21_PCREL,
8697 PG (gotplt_entry_address) -
8698 PG (plt_entry_address));
8700 /* Fill in the lo12 bits for the load from the pltgot. */
8701 elf_aarch64_update_plt_entry (output_bfd, BFD_RELOC_AARCH64_LDSTNN_LO12,
8703 PG_OFFSET (gotplt_entry_address));
8705 /* Fill in the lo12 bits for the add from the pltgot entry. */
8706 elf_aarch64_update_plt_entry (output_bfd, BFD_RELOC_AARCH64_ADD_LO12,
8708 PG_OFFSET (gotplt_entry_address));
8710 /* All the GOTPLT Entries are essentially initialized to PLT0. */
8711 bfd_put_NN (output_bfd,
8712 plt->output_section->vma + plt->output_offset,
8713 gotplt->contents + got_offset);
8715 rela.r_offset = gotplt_entry_address;
8717 if (h->dynindx == -1
8718 || ((bfd_link_executable (info)
8719 || ELF_ST_VISIBILITY (h->other) != STV_DEFAULT)
8721 && h->type == STT_GNU_IFUNC))
8723 /* If an STT_GNU_IFUNC symbol is locally defined, generate
8724 R_AARCH64_IRELATIVE instead of R_AARCH64_JUMP_SLOT. */
8725 rela.r_info = ELFNN_R_INFO (0, AARCH64_R (IRELATIVE));
8726 rela.r_addend = (h->root.u.def.value
8727 + h->root.u.def.section->output_section->vma
8728 + h->root.u.def.section->output_offset);
8732 /* Fill in the entry in the .rela.plt section. */
8733 rela.r_info = ELFNN_R_INFO (h->dynindx, AARCH64_R (JUMP_SLOT));
8737 /* Compute the relocation entry to used based on PLT index and do
8738 not adjust reloc_count. The reloc_count has already been adjusted
8739 to account for this entry. */
8740 loc = relplt->contents + plt_index * RELOC_SIZE (htab);
8741 bfd_elfNN_swap_reloca_out (output_bfd, &rela, loc);
8744 /* Size sections even though they're not dynamic. We use it to setup
8745 _TLS_MODULE_BASE_, if needed. */
8748 elfNN_aarch64_always_size_sections (bfd *output_bfd,
8749 struct bfd_link_info *info)
8753 if (bfd_link_relocatable (info))
8756 tls_sec = elf_hash_table (info)->tls_sec;
8760 struct elf_link_hash_entry *tlsbase;
8762 tlsbase = elf_link_hash_lookup (elf_hash_table (info),
8763 "_TLS_MODULE_BASE_", TRUE, TRUE, FALSE);
8767 struct bfd_link_hash_entry *h = NULL;
8768 const struct elf_backend_data *bed =
8769 get_elf_backend_data (output_bfd);
8771 if (!(_bfd_generic_link_add_one_symbol
8772 (info, output_bfd, "_TLS_MODULE_BASE_", BSF_LOCAL,
8773 tls_sec, 0, NULL, FALSE, bed->collect, &h)))
8776 tlsbase->type = STT_TLS;
8777 tlsbase = (struct elf_link_hash_entry *) h;
8778 tlsbase->def_regular = 1;
8779 tlsbase->other = STV_HIDDEN;
8780 (*bed->elf_backend_hide_symbol) (info, tlsbase, TRUE);
8787 /* Finish up dynamic symbol handling. We set the contents of various
8788 dynamic sections here. */
8790 elfNN_aarch64_finish_dynamic_symbol (bfd *output_bfd,
8791 struct bfd_link_info *info,
8792 struct elf_link_hash_entry *h,
8793 Elf_Internal_Sym *sym)
8795 struct elf_aarch64_link_hash_table *htab;
8796 htab = elf_aarch64_hash_table (info);
8798 if (h->plt.offset != (bfd_vma) - 1)
8800 asection *plt, *gotplt, *relplt;
8802 /* This symbol has an entry in the procedure linkage table. Set
8805 /* When building a static executable, use .iplt, .igot.plt and
8806 .rela.iplt sections for STT_GNU_IFUNC symbols. */
8807 if (htab->root.splt != NULL)
8809 plt = htab->root.splt;
8810 gotplt = htab->root.sgotplt;
8811 relplt = htab->root.srelplt;
8815 plt = htab->root.iplt;
8816 gotplt = htab->root.igotplt;
8817 relplt = htab->root.irelplt;
8820 /* This symbol has an entry in the procedure linkage table. Set
8822 if ((h->dynindx == -1
8823 && !((h->forced_local || bfd_link_executable (info))
8825 && h->type == STT_GNU_IFUNC))
8831 elfNN_aarch64_create_small_pltn_entry (h, htab, output_bfd, info);
8832 if (!h->def_regular)
8834 /* Mark the symbol as undefined, rather than as defined in
8835 the .plt section. */
8836 sym->st_shndx = SHN_UNDEF;
8837 /* If the symbol is weak we need to clear the value.
8838 Otherwise, the PLT entry would provide a definition for
8839 the symbol even if the symbol wasn't defined anywhere,
8840 and so the symbol would never be NULL. Leave the value if
8841 there were any relocations where pointer equality matters
8842 (this is a clue for the dynamic linker, to make function
8843 pointer comparisons work between an application and shared
8845 if (!h->ref_regular_nonweak || !h->pointer_equality_needed)
8850 if (h->got.offset != (bfd_vma) - 1
8851 && elf_aarch64_hash_entry (h)->got_type == GOT_NORMAL)
8853 Elf_Internal_Rela rela;
8856 /* This symbol has an entry in the global offset table. Set it
8858 if (htab->root.sgot == NULL || htab->root.srelgot == NULL)
8861 rela.r_offset = (htab->root.sgot->output_section->vma
8862 + htab->root.sgot->output_offset
8863 + (h->got.offset & ~(bfd_vma) 1));
8866 && h->type == STT_GNU_IFUNC)
8868 if (bfd_link_pic (info))
8870 /* Generate R_AARCH64_GLOB_DAT. */
8877 if (!h->pointer_equality_needed)
8880 /* For non-shared object, we can't use .got.plt, which
8881 contains the real function address if we need pointer
8882 equality. We load the GOT entry with the PLT entry. */
8883 plt = htab->root.splt ? htab->root.splt : htab->root.iplt;
8884 bfd_put_NN (output_bfd, (plt->output_section->vma
8885 + plt->output_offset
8887 htab->root.sgot->contents
8888 + (h->got.offset & ~(bfd_vma) 1));
8892 else if (bfd_link_pic (info) && SYMBOL_REFERENCES_LOCAL (info, h))
8894 if (!h->def_regular)
8897 BFD_ASSERT ((h->got.offset & 1) != 0);
8898 rela.r_info = ELFNN_R_INFO (0, AARCH64_R (RELATIVE));
8899 rela.r_addend = (h->root.u.def.value
8900 + h->root.u.def.section->output_section->vma
8901 + h->root.u.def.section->output_offset);
8906 BFD_ASSERT ((h->got.offset & 1) == 0);
8907 bfd_put_NN (output_bfd, (bfd_vma) 0,
8908 htab->root.sgot->contents + h->got.offset);
8909 rela.r_info = ELFNN_R_INFO (h->dynindx, AARCH64_R (GLOB_DAT));
8913 loc = htab->root.srelgot->contents;
8914 loc += htab->root.srelgot->reloc_count++ * RELOC_SIZE (htab);
8915 bfd_elfNN_swap_reloca_out (output_bfd, &rela, loc);
8920 Elf_Internal_Rela rela;
8923 /* This symbol needs a copy reloc. Set it up. */
8925 if (h->dynindx == -1
8926 || (h->root.type != bfd_link_hash_defined
8927 && h->root.type != bfd_link_hash_defweak)
8928 || htab->srelbss == NULL)
8931 rela.r_offset = (h->root.u.def.value
8932 + h->root.u.def.section->output_section->vma
8933 + h->root.u.def.section->output_offset);
8934 rela.r_info = ELFNN_R_INFO (h->dynindx, AARCH64_R (COPY));
8936 loc = htab->srelbss->contents;
8937 loc += htab->srelbss->reloc_count++ * RELOC_SIZE (htab);
8938 bfd_elfNN_swap_reloca_out (output_bfd, &rela, loc);
8941 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. SYM may
8942 be NULL for local symbols. */
8944 && (h == elf_hash_table (info)->hdynamic
8945 || h == elf_hash_table (info)->hgot))
8946 sym->st_shndx = SHN_ABS;
8951 /* Finish up local dynamic symbol handling. We set the contents of
8952 various dynamic sections here. */
8955 elfNN_aarch64_finish_local_dynamic_symbol (void **slot, void *inf)
8957 struct elf_link_hash_entry *h
8958 = (struct elf_link_hash_entry *) *slot;
8959 struct bfd_link_info *info
8960 = (struct bfd_link_info *) inf;
8962 return elfNN_aarch64_finish_dynamic_symbol (info->output_bfd,
8967 elfNN_aarch64_init_small_plt0_entry (bfd *output_bfd ATTRIBUTE_UNUSED,
8968 struct elf_aarch64_link_hash_table
8971 /* Fill in PLT0. Fixme:RR Note this doesn't distinguish between
8972 small and large plts and at the minute just generates
8975 /* PLT0 of the small PLT looks like this in ELF64 -
8976 stp x16, x30, [sp, #-16]! // Save the reloc and lr on stack.
8977 adrp x16, PLT_GOT + 16 // Get the page base of the GOTPLT
8978 ldr x17, [x16, #:lo12:PLT_GOT+16] // Load the address of the
8980 add x16, x16, #:lo12:PLT_GOT+16 // Load the lo12 bits of the
8981 // GOTPLT entry for this.
8983 PLT0 will be slightly different in ELF32 due to different got entry
8986 bfd_vma plt_got_2nd_ent; /* Address of GOT[2]. */
8990 memcpy (htab->root.splt->contents, elfNN_aarch64_small_plt0_entry,
8992 elf_section_data (htab->root.splt->output_section)->this_hdr.sh_entsize =
8995 plt_got_2nd_ent = (htab->root.sgotplt->output_section->vma
8996 + htab->root.sgotplt->output_offset
8997 + GOT_ENTRY_SIZE * 2);
8999 plt_base = htab->root.splt->output_section->vma +
9000 htab->root.splt->output_offset;
9002 /* Fill in the top 21 bits for this: ADRP x16, PLT_GOT + n * 8.
9003 ADRP: ((PG(S+A)-PG(P)) >> 12) & 0x1fffff */
9004 elf_aarch64_update_plt_entry (output_bfd, BFD_RELOC_AARCH64_ADR_HI21_PCREL,
9005 htab->root.splt->contents + 4,
9006 PG (plt_got_2nd_ent) - PG (plt_base + 4));
9008 elf_aarch64_update_plt_entry (output_bfd, BFD_RELOC_AARCH64_LDSTNN_LO12,
9009 htab->root.splt->contents + 8,
9010 PG_OFFSET (plt_got_2nd_ent));
9012 elf_aarch64_update_plt_entry (output_bfd, BFD_RELOC_AARCH64_ADD_LO12,
9013 htab->root.splt->contents + 12,
9014 PG_OFFSET (plt_got_2nd_ent));
9018 elfNN_aarch64_finish_dynamic_sections (bfd *output_bfd,
9019 struct bfd_link_info *info)
9021 struct elf_aarch64_link_hash_table *htab;
9025 htab = elf_aarch64_hash_table (info);
9026 dynobj = htab->root.dynobj;
9027 sdyn = bfd_get_linker_section (dynobj, ".dynamic");
9029 if (htab->root.dynamic_sections_created)
9031 ElfNN_External_Dyn *dyncon, *dynconend;
9033 if (sdyn == NULL || htab->root.sgot == NULL)
9036 dyncon = (ElfNN_External_Dyn *) sdyn->contents;
9037 dynconend = (ElfNN_External_Dyn *) (sdyn->contents + sdyn->size);
9038 for (; dyncon < dynconend; dyncon++)
9040 Elf_Internal_Dyn dyn;
9043 bfd_elfNN_swap_dyn_in (dynobj, dyncon, &dyn);
9051 s = htab->root.sgotplt;
9052 dyn.d_un.d_ptr = s->output_section->vma + s->output_offset;
9056 s = htab->root.srelplt;
9057 dyn.d_un.d_ptr = s->output_section->vma + s->output_offset;
9061 s = htab->root.srelplt;
9062 dyn.d_un.d_val = s->size;
9066 /* The procedure linkage table relocs (DT_JMPREL) should
9067 not be included in the overall relocs (DT_RELA).
9068 Therefore, we override the DT_RELASZ entry here to
9069 make it not include the JMPREL relocs. Since the
9070 linker script arranges for .rela.plt to follow all
9071 other relocation sections, we don't have to worry
9072 about changing the DT_RELA entry. */
9073 if (htab->root.srelplt != NULL)
9075 s = htab->root.srelplt;
9076 dyn.d_un.d_val -= s->size;
9080 case DT_TLSDESC_PLT:
9081 s = htab->root.splt;
9082 dyn.d_un.d_ptr = s->output_section->vma + s->output_offset
9083 + htab->tlsdesc_plt;
9086 case DT_TLSDESC_GOT:
9087 s = htab->root.sgot;
9088 dyn.d_un.d_ptr = s->output_section->vma + s->output_offset
9089 + htab->dt_tlsdesc_got;
9093 bfd_elfNN_swap_dyn_out (output_bfd, &dyn, dyncon);
9098 /* Fill in the special first entry in the procedure linkage table. */
9099 if (htab->root.splt && htab->root.splt->size > 0)
9101 elfNN_aarch64_init_small_plt0_entry (output_bfd, htab);
9103 elf_section_data (htab->root.splt->output_section)->
9104 this_hdr.sh_entsize = htab->plt_entry_size;
9107 if (htab->tlsdesc_plt)
9109 bfd_put_NN (output_bfd, (bfd_vma) 0,
9110 htab->root.sgot->contents + htab->dt_tlsdesc_got);
9112 memcpy (htab->root.splt->contents + htab->tlsdesc_plt,
9113 elfNN_aarch64_tlsdesc_small_plt_entry,
9114 sizeof (elfNN_aarch64_tlsdesc_small_plt_entry));
9117 bfd_vma adrp1_addr =
9118 htab->root.splt->output_section->vma
9119 + htab->root.splt->output_offset + htab->tlsdesc_plt + 4;
9121 bfd_vma adrp2_addr = adrp1_addr + 4;
9124 htab->root.sgot->output_section->vma
9125 + htab->root.sgot->output_offset;
9127 bfd_vma pltgot_addr =
9128 htab->root.sgotplt->output_section->vma
9129 + htab->root.sgotplt->output_offset;
9131 bfd_vma dt_tlsdesc_got = got_addr + htab->dt_tlsdesc_got;
9133 bfd_byte *plt_entry =
9134 htab->root.splt->contents + htab->tlsdesc_plt;
9136 /* adrp x2, DT_TLSDESC_GOT */
9137 elf_aarch64_update_plt_entry (output_bfd,
9138 BFD_RELOC_AARCH64_ADR_HI21_PCREL,
9140 (PG (dt_tlsdesc_got)
9141 - PG (adrp1_addr)));
9144 elf_aarch64_update_plt_entry (output_bfd,
9145 BFD_RELOC_AARCH64_ADR_HI21_PCREL,
9148 - PG (adrp2_addr)));
9150 /* ldr x2, [x2, #0] */
9151 elf_aarch64_update_plt_entry (output_bfd,
9152 BFD_RELOC_AARCH64_LDSTNN_LO12,
9154 PG_OFFSET (dt_tlsdesc_got));
9157 elf_aarch64_update_plt_entry (output_bfd,
9158 BFD_RELOC_AARCH64_ADD_LO12,
9160 PG_OFFSET (pltgot_addr));
9165 if (htab->root.sgotplt)
9167 if (bfd_is_abs_section (htab->root.sgotplt->output_section))
9169 (*_bfd_error_handler)
9170 (_("discarded output section: `%A'"), htab->root.sgotplt);
9174 /* Fill in the first three entries in the global offset table. */
9175 if (htab->root.sgotplt->size > 0)
9177 bfd_put_NN (output_bfd, (bfd_vma) 0, htab->root.sgotplt->contents);
9179 /* Write GOT[1] and GOT[2], needed for the dynamic linker. */
9180 bfd_put_NN (output_bfd,
9182 htab->root.sgotplt->contents + GOT_ENTRY_SIZE);
9183 bfd_put_NN (output_bfd,
9185 htab->root.sgotplt->contents + GOT_ENTRY_SIZE * 2);
9188 if (htab->root.sgot)
9190 if (htab->root.sgot->size > 0)
9193 sdyn ? sdyn->output_section->vma + sdyn->output_offset : 0;
9194 bfd_put_NN (output_bfd, addr, htab->root.sgot->contents);
9198 elf_section_data (htab->root.sgotplt->output_section)->
9199 this_hdr.sh_entsize = GOT_ENTRY_SIZE;
9202 if (htab->root.sgot && htab->root.sgot->size > 0)
9203 elf_section_data (htab->root.sgot->output_section)->this_hdr.sh_entsize
9206 /* Fill PLT and GOT entries for local STT_GNU_IFUNC symbols. */
9207 htab_traverse (htab->loc_hash_table,
9208 elfNN_aarch64_finish_local_dynamic_symbol,
9214 /* Return address for Ith PLT stub in section PLT, for relocation REL
9215 or (bfd_vma) -1 if it should not be included. */
9218 elfNN_aarch64_plt_sym_val (bfd_vma i, const asection *plt,
9219 const arelent *rel ATTRIBUTE_UNUSED)
9221 return plt->vma + PLT_ENTRY_SIZE + i * PLT_SMALL_ENTRY_SIZE;
9225 /* We use this so we can override certain functions
9226 (though currently we don't). */
9228 const struct elf_size_info elfNN_aarch64_size_info =
9230 sizeof (ElfNN_External_Ehdr),
9231 sizeof (ElfNN_External_Phdr),
9232 sizeof (ElfNN_External_Shdr),
9233 sizeof (ElfNN_External_Rel),
9234 sizeof (ElfNN_External_Rela),
9235 sizeof (ElfNN_External_Sym),
9236 sizeof (ElfNN_External_Dyn),
9237 sizeof (Elf_External_Note),
9238 4, /* Hash table entry size. */
9239 1, /* Internal relocs per external relocs. */
9240 ARCH_SIZE, /* Arch size. */
9241 LOG_FILE_ALIGN, /* Log_file_align. */
9242 ELFCLASSNN, EV_CURRENT,
9243 bfd_elfNN_write_out_phdrs,
9244 bfd_elfNN_write_shdrs_and_ehdr,
9245 bfd_elfNN_checksum_contents,
9246 bfd_elfNN_write_relocs,
9247 bfd_elfNN_swap_symbol_in,
9248 bfd_elfNN_swap_symbol_out,
9249 bfd_elfNN_slurp_reloc_table,
9250 bfd_elfNN_slurp_symbol_table,
9251 bfd_elfNN_swap_dyn_in,
9252 bfd_elfNN_swap_dyn_out,
9253 bfd_elfNN_swap_reloc_in,
9254 bfd_elfNN_swap_reloc_out,
9255 bfd_elfNN_swap_reloca_in,
9256 bfd_elfNN_swap_reloca_out
9259 #define ELF_ARCH bfd_arch_aarch64
9260 #define ELF_MACHINE_CODE EM_AARCH64
9261 #define ELF_MAXPAGESIZE 0x10000
9262 #define ELF_MINPAGESIZE 0x1000
9263 #define ELF_COMMONPAGESIZE 0x1000
9265 #define bfd_elfNN_close_and_cleanup \
9266 elfNN_aarch64_close_and_cleanup
9268 #define bfd_elfNN_bfd_free_cached_info \
9269 elfNN_aarch64_bfd_free_cached_info
9271 #define bfd_elfNN_bfd_is_target_special_symbol \
9272 elfNN_aarch64_is_target_special_symbol
9274 #define bfd_elfNN_bfd_link_hash_table_create \
9275 elfNN_aarch64_link_hash_table_create
9277 #define bfd_elfNN_bfd_merge_private_bfd_data \
9278 elfNN_aarch64_merge_private_bfd_data
9280 #define bfd_elfNN_bfd_print_private_bfd_data \
9281 elfNN_aarch64_print_private_bfd_data
9283 #define bfd_elfNN_bfd_reloc_type_lookup \
9284 elfNN_aarch64_reloc_type_lookup
9286 #define bfd_elfNN_bfd_reloc_name_lookup \
9287 elfNN_aarch64_reloc_name_lookup
9289 #define bfd_elfNN_bfd_set_private_flags \
9290 elfNN_aarch64_set_private_flags
9292 #define bfd_elfNN_find_inliner_info \
9293 elfNN_aarch64_find_inliner_info
9295 #define bfd_elfNN_find_nearest_line \
9296 elfNN_aarch64_find_nearest_line
9298 #define bfd_elfNN_mkobject \
9299 elfNN_aarch64_mkobject
9301 #define bfd_elfNN_new_section_hook \
9302 elfNN_aarch64_new_section_hook
9304 #define elf_backend_adjust_dynamic_symbol \
9305 elfNN_aarch64_adjust_dynamic_symbol
9307 #define elf_backend_always_size_sections \
9308 elfNN_aarch64_always_size_sections
9310 #define elf_backend_check_relocs \
9311 elfNN_aarch64_check_relocs
9313 #define elf_backend_copy_indirect_symbol \
9314 elfNN_aarch64_copy_indirect_symbol
9316 /* Create .dynbss, and .rela.bss sections in DYNOBJ, and set up shortcuts
9317 to them in our hash. */
9318 #define elf_backend_create_dynamic_sections \
9319 elfNN_aarch64_create_dynamic_sections
9321 #define elf_backend_init_index_section \
9322 _bfd_elf_init_2_index_sections
9324 #define elf_backend_finish_dynamic_sections \
9325 elfNN_aarch64_finish_dynamic_sections
9327 #define elf_backend_finish_dynamic_symbol \
9328 elfNN_aarch64_finish_dynamic_symbol
9330 #define elf_backend_gc_sweep_hook \
9331 elfNN_aarch64_gc_sweep_hook
9333 #define elf_backend_object_p \
9334 elfNN_aarch64_object_p
9336 #define elf_backend_output_arch_local_syms \
9337 elfNN_aarch64_output_arch_local_syms
9339 #define elf_backend_plt_sym_val \
9340 elfNN_aarch64_plt_sym_val
9342 #define elf_backend_post_process_headers \
9343 elfNN_aarch64_post_process_headers
9345 #define elf_backend_relocate_section \
9346 elfNN_aarch64_relocate_section
9348 #define elf_backend_reloc_type_class \
9349 elfNN_aarch64_reloc_type_class
9351 #define elf_backend_section_from_shdr \
9352 elfNN_aarch64_section_from_shdr
9354 #define elf_backend_size_dynamic_sections \
9355 elfNN_aarch64_size_dynamic_sections
9357 #define elf_backend_size_info \
9358 elfNN_aarch64_size_info
9360 #define elf_backend_write_section \
9361 elfNN_aarch64_write_section
9363 #define elf_backend_can_refcount 1
9364 #define elf_backend_can_gc_sections 1
9365 #define elf_backend_plt_readonly 1
9366 #define elf_backend_want_got_plt 1
9367 #define elf_backend_want_plt_sym 0
9368 #define elf_backend_may_use_rel_p 0
9369 #define elf_backend_may_use_rela_p 1
9370 #define elf_backend_default_use_rela_p 1
9371 #define elf_backend_rela_normal 1
9372 #define elf_backend_got_header_size (GOT_ENTRY_SIZE * 3)
9373 #define elf_backend_default_execstack 0
9374 #define elf_backend_extern_protected_data 1
9376 #undef elf_backend_obj_attrs_section
9377 #define elf_backend_obj_attrs_section ".ARM.attributes"
9379 #include "elfNN-target.h"
9381 /* CloudABI support. */
9383 #undef TARGET_LITTLE_SYM
9384 #define TARGET_LITTLE_SYM aarch64_elfNN_le_cloudabi_vec
9385 #undef TARGET_LITTLE_NAME
9386 #define TARGET_LITTLE_NAME "elfNN-littleaarch64-cloudabi"
9387 #undef TARGET_BIG_SYM
9388 #define TARGET_BIG_SYM aarch64_elfNN_be_cloudabi_vec
9389 #undef TARGET_BIG_NAME
9390 #define TARGET_BIG_NAME "elfNN-bigaarch64-cloudabi"
9393 #define ELF_OSABI ELFOSABI_CLOUDABI
9396 #define elfNN_bed elfNN_aarch64_cloudabi_bed
9398 #include "elfNN-target.h"