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. */
4899 static bfd_reloc_status_type
4900 elfNN_aarch64_final_link_relocate (reloc_howto_type
*howto
,
4903 asection
*input_section
,
4905 Elf_Internal_Rela
*rel
,
4907 struct bfd_link_info
*info
,
4909 struct elf_link_hash_entry
*h
,
4910 bfd_boolean
*unresolved_reloc_p
,
4911 bfd_boolean save_addend
,
4912 bfd_vma
*saved_addend
,
4913 Elf_Internal_Sym
*sym
)
4915 Elf_Internal_Shdr
*symtab_hdr
;
4916 unsigned int r_type
= howto
->type
;
4917 bfd_reloc_code_real_type bfd_r_type
4918 = elfNN_aarch64_bfd_reloc_from_howto (howto
);
4919 bfd_reloc_code_real_type new_bfd_r_type
;
4920 unsigned long r_symndx
;
4921 bfd_byte
*hit_data
= contents
+ rel
->r_offset
;
4923 bfd_signed_vma signed_addend
;
4924 struct elf_aarch64_link_hash_table
*globals
;
4925 bfd_boolean weak_undef_p
;
4928 globals
= elf_aarch64_hash_table (info
);
4930 symtab_hdr
= &elf_symtab_hdr (input_bfd
);
4932 BFD_ASSERT (is_aarch64_elf (input_bfd
));
4934 r_symndx
= ELFNN_R_SYM (rel
->r_info
);
4936 /* It is possible to have linker relaxations on some TLS access
4937 models. Update our information here. */
4938 new_bfd_r_type
= aarch64_tls_transition (input_bfd
, info
, r_type
, h
, r_symndx
);
4939 if (new_bfd_r_type
!= bfd_r_type
)
4941 bfd_r_type
= new_bfd_r_type
;
4942 howto
= elfNN_aarch64_howto_from_bfd_reloc (bfd_r_type
);
4943 BFD_ASSERT (howto
!= NULL
);
4944 r_type
= howto
->type
;
4947 place
= input_section
->output_section
->vma
4948 + input_section
->output_offset
+ rel
->r_offset
;
4950 /* Get addend, accumulating the addend for consecutive relocs
4951 which refer to the same offset. */
4952 signed_addend
= saved_addend
? *saved_addend
: 0;
4953 signed_addend
+= rel
->r_addend
;
4955 weak_undef_p
= (h
? h
->root
.type
== bfd_link_hash_undefweak
4956 : bfd_is_und_section (sym_sec
));
4958 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle
4959 it here if it is defined in a non-shared object. */
4961 && h
->type
== STT_GNU_IFUNC
4968 if ((input_section
->flags
& SEC_ALLOC
) == 0
4969 || h
->plt
.offset
== (bfd_vma
) -1)
4972 /* STT_GNU_IFUNC symbol must go through PLT. */
4973 plt
= globals
->root
.splt
? globals
->root
.splt
: globals
->root
.iplt
;
4974 value
= (plt
->output_section
->vma
+ plt
->output_offset
+ h
->plt
.offset
);
4979 if (h
->root
.root
.string
)
4980 name
= h
->root
.root
.string
;
4982 name
= bfd_elf_sym_name (input_bfd
, symtab_hdr
, sym
,
4984 (*_bfd_error_handler
)
4985 (_("%B: relocation %s against STT_GNU_IFUNC "
4986 "symbol `%s' isn't handled by %s"), input_bfd
,
4987 howto
->name
, name
, __FUNCTION__
);
4988 bfd_set_error (bfd_error_bad_value
);
4991 case BFD_RELOC_AARCH64_NN
:
4992 if (rel
->r_addend
!= 0)
4994 if (h
->root
.root
.string
)
4995 name
= h
->root
.root
.string
;
4997 name
= bfd_elf_sym_name (input_bfd
, symtab_hdr
,
4999 (*_bfd_error_handler
)
5000 (_("%B: relocation %s against STT_GNU_IFUNC "
5001 "symbol `%s' has non-zero addend: %d"),
5002 input_bfd
, howto
->name
, name
, rel
->r_addend
);
5003 bfd_set_error (bfd_error_bad_value
);
5007 /* Generate dynamic relocation only when there is a
5008 non-GOT reference in a shared object. */
5009 if (bfd_link_pic (info
) && h
->non_got_ref
)
5011 Elf_Internal_Rela outrel
;
5014 /* Need a dynamic relocation to get the real function
5016 outrel
.r_offset
= _bfd_elf_section_offset (output_bfd
,
5020 if (outrel
.r_offset
== (bfd_vma
) -1
5021 || outrel
.r_offset
== (bfd_vma
) -2)
5024 outrel
.r_offset
+= (input_section
->output_section
->vma
5025 + input_section
->output_offset
);
5027 if (h
->dynindx
== -1
5029 || bfd_link_executable (info
))
5031 /* This symbol is resolved locally. */
5032 outrel
.r_info
= ELFNN_R_INFO (0, AARCH64_R (IRELATIVE
));
5033 outrel
.r_addend
= (h
->root
.u
.def
.value
5034 + h
->root
.u
.def
.section
->output_section
->vma
5035 + h
->root
.u
.def
.section
->output_offset
);
5039 outrel
.r_info
= ELFNN_R_INFO (h
->dynindx
, r_type
);
5040 outrel
.r_addend
= 0;
5043 sreloc
= globals
->root
.irelifunc
;
5044 elf_append_rela (output_bfd
, sreloc
, &outrel
);
5046 /* If this reloc is against an external symbol, we
5047 do not want to fiddle with the addend. Otherwise,
5048 we need to include the symbol value so that it
5049 becomes an addend for the dynamic reloc. For an
5050 internal symbol, we have updated addend. */
5051 return bfd_reloc_ok
;
5054 case BFD_RELOC_AARCH64_CALL26
:
5055 case BFD_RELOC_AARCH64_JUMP26
:
5056 value
= _bfd_aarch64_elf_resolve_relocation (bfd_r_type
, place
, value
,
5059 return _bfd_aarch64_elf_put_addend (input_bfd
, hit_data
, bfd_r_type
,
5061 case BFD_RELOC_AARCH64_ADR_GOT_PAGE
:
5062 case BFD_RELOC_AARCH64_GOT_LD_PREL19
:
5063 case BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14
:
5064 case BFD_RELOC_AARCH64_LD32_GOT_LO12_NC
:
5065 case BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15
:
5066 case BFD_RELOC_AARCH64_MOVW_GOTOFF_G0_NC
:
5067 case BFD_RELOC_AARCH64_MOVW_GOTOFF_G1
:
5068 case BFD_RELOC_AARCH64_LD64_GOTOFF_LO15
:
5069 case BFD_RELOC_AARCH64_LD64_GOT_LO12_NC
:
5070 base_got
= globals
->root
.sgot
;
5071 off
= h
->got
.offset
;
5073 if (base_got
== NULL
)
5076 if (off
== (bfd_vma
) -1)
5080 /* We can't use h->got.offset here to save state, or
5081 even just remember the offset, as finish_dynamic_symbol
5082 would use that as offset into .got. */
5084 if (globals
->root
.splt
!= NULL
)
5086 plt_index
= ((h
->plt
.offset
- globals
->plt_header_size
) /
5087 globals
->plt_entry_size
);
5088 off
= (plt_index
+ 3) * GOT_ENTRY_SIZE
;
5089 base_got
= globals
->root
.sgotplt
;
5093 plt_index
= h
->plt
.offset
/ globals
->plt_entry_size
;
5094 off
= plt_index
* GOT_ENTRY_SIZE
;
5095 base_got
= globals
->root
.igotplt
;
5098 if (h
->dynindx
== -1
5102 /* This references the local definition. We must
5103 initialize this entry in the global offset table.
5104 Since the offset must always be a multiple of 8,
5105 we use the least significant bit to record
5106 whether we have initialized it already.
5108 When doing a dynamic link, we create a .rela.got
5109 relocation entry to initialize the value. This
5110 is done in the finish_dynamic_symbol routine. */
5115 bfd_put_NN (output_bfd
, value
,
5116 base_got
->contents
+ off
);
5117 /* Note that this is harmless as -1 | 1 still is -1. */
5121 value
= (base_got
->output_section
->vma
5122 + base_got
->output_offset
+ off
);
5125 value
= aarch64_calculate_got_entry_vma (h
, globals
, info
,
5127 unresolved_reloc_p
);
5131 case BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14
:
5132 case BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15
:
5133 addend
= (globals
->root
.sgot
->output_section
->vma
5134 + globals
->root
.sgot
->output_offset
);
5136 case BFD_RELOC_AARCH64_MOVW_GOTOFF_G0_NC
:
5137 case BFD_RELOC_AARCH64_MOVW_GOTOFF_G1
:
5138 case BFD_RELOC_AARCH64_LD64_GOTOFF_LO15
:
5139 value
= (value
- globals
->root
.sgot
->output_section
->vma
5140 - globals
->root
.sgot
->output_offset
);
5145 value
= _bfd_aarch64_elf_resolve_relocation (bfd_r_type
, place
, value
,
5146 addend
, weak_undef_p
);
5147 return _bfd_aarch64_elf_put_addend (input_bfd
, hit_data
, bfd_r_type
, howto
, value
);
5148 case BFD_RELOC_AARCH64_ADD_LO12
:
5149 case BFD_RELOC_AARCH64_ADR_HI21_PCREL
:
5156 case BFD_RELOC_AARCH64_NONE
:
5157 case BFD_RELOC_AARCH64_TLSDESC_ADD
:
5158 case BFD_RELOC_AARCH64_TLSDESC_CALL
:
5159 case BFD_RELOC_AARCH64_TLSDESC_LDR
:
5160 *unresolved_reloc_p
= FALSE
;
5161 return bfd_reloc_ok
;
5163 case BFD_RELOC_AARCH64_NN
:
5165 /* When generating a shared object or relocatable executable, these
5166 relocations are copied into the output file to be resolved at
5168 if (((bfd_link_pic (info
) == TRUE
)
5169 || globals
->root
.is_relocatable_executable
)
5170 && (input_section
->flags
& SEC_ALLOC
)
5172 || ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
5173 || h
->root
.type
!= bfd_link_hash_undefweak
))
5175 Elf_Internal_Rela outrel
;
5177 bfd_boolean skip
, relocate
;
5180 *unresolved_reloc_p
= FALSE
;
5185 outrel
.r_addend
= signed_addend
;
5187 _bfd_elf_section_offset (output_bfd
, info
, input_section
,
5189 if (outrel
.r_offset
== (bfd_vma
) - 1)
5191 else if (outrel
.r_offset
== (bfd_vma
) - 2)
5197 outrel
.r_offset
+= (input_section
->output_section
->vma
5198 + input_section
->output_offset
);
5201 memset (&outrel
, 0, sizeof outrel
);
5204 && (!bfd_link_pic (info
)
5205 || !SYMBOLIC_BIND (info
, h
)
5206 || !h
->def_regular
))
5207 outrel
.r_info
= ELFNN_R_INFO (h
->dynindx
, r_type
);
5212 /* On SVR4-ish systems, the dynamic loader cannot
5213 relocate the text and data segments independently,
5214 so the symbol does not matter. */
5216 relocate
= globals
->no_apply_dynamic_relocs
? FALSE
: TRUE
;
5217 outrel
.r_info
= ELFNN_R_INFO (symbol
, AARCH64_R (RELATIVE
));
5218 outrel
.r_addend
+= value
;
5221 sreloc
= elf_section_data (input_section
)->sreloc
;
5222 if (sreloc
== NULL
|| sreloc
->contents
== NULL
)
5223 return bfd_reloc_notsupported
;
5225 loc
= sreloc
->contents
+ sreloc
->reloc_count
++ * RELOC_SIZE (globals
);
5226 bfd_elfNN_swap_reloca_out (output_bfd
, &outrel
, loc
);
5228 if (sreloc
->reloc_count
* RELOC_SIZE (globals
) > sreloc
->size
)
5230 /* Sanity to check that we have previously allocated
5231 sufficient space in the relocation section for the
5232 number of relocations we actually want to emit. */
5236 /* If this reloc is against an external symbol, we do not want to
5237 fiddle with the addend. Otherwise, we need to include the symbol
5238 value so that it becomes an addend for the dynamic reloc. */
5240 return bfd_reloc_ok
;
5242 return _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
5243 contents
, rel
->r_offset
, value
,
5247 value
+= signed_addend
;
5250 case BFD_RELOC_AARCH64_CALL26
:
5251 case BFD_RELOC_AARCH64_JUMP26
:
5253 asection
*splt
= globals
->root
.splt
;
5254 bfd_boolean via_plt_p
=
5255 splt
!= NULL
&& h
!= NULL
&& h
->plt
.offset
!= (bfd_vma
) - 1;
5257 /* A call to an undefined weak symbol is converted to a jump to
5258 the next instruction unless a PLT entry will be created.
5259 The jump to the next instruction is optimized as a NOP.
5260 Do the same for local undefined symbols. */
5261 if (weak_undef_p
&& ! via_plt_p
)
5263 bfd_putl32 (INSN_NOP
, hit_data
);
5264 return bfd_reloc_ok
;
5267 /* If the call goes through a PLT entry, make sure to
5268 check distance to the right destination address. */
5270 value
= (splt
->output_section
->vma
5271 + splt
->output_offset
+ h
->plt
.offset
);
5273 /* Check if a stub has to be inserted because the destination
5275 struct elf_aarch64_stub_hash_entry
*stub_entry
= NULL
;
5277 /* If the branch destination is directed to plt stub, "value" will be
5278 the final destination, otherwise we should plus signed_addend, it may
5279 contain non-zero value, for example call to local function symbol
5280 which are turned into "sec_sym + sec_off", and sec_off is kept in
5282 if (! aarch64_valid_branch_p (via_plt_p
? value
: value
+ signed_addend
,
5284 /* The target is out of reach, so redirect the branch to
5285 the local stub for this function. */
5286 stub_entry
= elfNN_aarch64_get_stub_entry (input_section
, sym_sec
, h
,
5288 if (stub_entry
!= NULL
)
5290 value
= (stub_entry
->stub_offset
5291 + stub_entry
->stub_sec
->output_offset
5292 + stub_entry
->stub_sec
->output_section
->vma
);
5294 /* We have redirected the destination to stub entry address,
5295 so ignore any addend record in the original rela entry. */
5299 value
= _bfd_aarch64_elf_resolve_relocation (bfd_r_type
, place
, value
,
5300 signed_addend
, weak_undef_p
);
5301 *unresolved_reloc_p
= FALSE
;
5304 case BFD_RELOC_AARCH64_16_PCREL
:
5305 case BFD_RELOC_AARCH64_32_PCREL
:
5306 case BFD_RELOC_AARCH64_64_PCREL
:
5307 case BFD_RELOC_AARCH64_ADR_HI21_NC_PCREL
:
5308 case BFD_RELOC_AARCH64_ADR_HI21_PCREL
:
5309 case BFD_RELOC_AARCH64_ADR_LO21_PCREL
:
5310 case BFD_RELOC_AARCH64_LD_LO19_PCREL
:
5311 if (bfd_link_pic (info
)
5312 && (input_section
->flags
& SEC_ALLOC
) != 0
5313 && (input_section
->flags
& SEC_READONLY
) != 0
5317 int howto_index
= bfd_r_type
- BFD_RELOC_AARCH64_RELOC_START
;
5319 (*_bfd_error_handler
)
5320 (_("%B: relocation %s against external symbol `%s' can not be used"
5321 " when making a shared object; recompile with -fPIC"),
5322 input_bfd
, elfNN_aarch64_howto_table
[howto_index
].name
,
5323 h
->root
.root
.string
);
5324 bfd_set_error (bfd_error_bad_value
);
5328 case BFD_RELOC_AARCH64_16
:
5330 case BFD_RELOC_AARCH64_32
:
5332 case BFD_RELOC_AARCH64_ADD_LO12
:
5333 case BFD_RELOC_AARCH64_BRANCH19
:
5334 case BFD_RELOC_AARCH64_LDST128_LO12
:
5335 case BFD_RELOC_AARCH64_LDST16_LO12
:
5336 case BFD_RELOC_AARCH64_LDST32_LO12
:
5337 case BFD_RELOC_AARCH64_LDST64_LO12
:
5338 case BFD_RELOC_AARCH64_LDST8_LO12
:
5339 case BFD_RELOC_AARCH64_MOVW_G0
:
5340 case BFD_RELOC_AARCH64_MOVW_G0_NC
:
5341 case BFD_RELOC_AARCH64_MOVW_G0_S
:
5342 case BFD_RELOC_AARCH64_MOVW_G1
:
5343 case BFD_RELOC_AARCH64_MOVW_G1_NC
:
5344 case BFD_RELOC_AARCH64_MOVW_G1_S
:
5345 case BFD_RELOC_AARCH64_MOVW_G2
:
5346 case BFD_RELOC_AARCH64_MOVW_G2_NC
:
5347 case BFD_RELOC_AARCH64_MOVW_G2_S
:
5348 case BFD_RELOC_AARCH64_MOVW_G3
:
5349 case BFD_RELOC_AARCH64_TSTBR14
:
5350 value
= _bfd_aarch64_elf_resolve_relocation (bfd_r_type
, place
, value
,
5351 signed_addend
, weak_undef_p
);
5354 case BFD_RELOC_AARCH64_ADR_GOT_PAGE
:
5355 case BFD_RELOC_AARCH64_GOT_LD_PREL19
:
5356 case BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14
:
5357 case BFD_RELOC_AARCH64_LD32_GOT_LO12_NC
:
5358 case BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15
:
5359 case BFD_RELOC_AARCH64_LD64_GOT_LO12_NC
:
5360 if (globals
->root
.sgot
== NULL
)
5361 BFD_ASSERT (h
!= NULL
);
5366 value
= aarch64_calculate_got_entry_vma (h
, globals
, info
, value
,
5368 unresolved_reloc_p
);
5369 if (bfd_r_type
== BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15
5370 || bfd_r_type
== BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14
)
5371 addend
= (globals
->root
.sgot
->output_section
->vma
5372 + globals
->root
.sgot
->output_offset
);
5373 value
= _bfd_aarch64_elf_resolve_relocation (bfd_r_type
, place
, value
,
5374 addend
, weak_undef_p
);
5379 struct elf_aarch64_local_symbol
*locals
5380 = elf_aarch64_locals (input_bfd
);
5384 int howto_index
= bfd_r_type
- BFD_RELOC_AARCH64_RELOC_START
;
5385 (*_bfd_error_handler
)
5386 (_("%B: Local symbol descriptor table be NULL when applying "
5387 "relocation %s against local symbol"),
5388 input_bfd
, elfNN_aarch64_howto_table
[howto_index
].name
);
5392 off
= symbol_got_offset (input_bfd
, h
, r_symndx
);
5393 base_got
= globals
->root
.sgot
;
5394 bfd_vma got_entry_addr
= (base_got
->output_section
->vma
5395 + base_got
->output_offset
+ off
);
5397 if (!symbol_got_offset_mark_p (input_bfd
, h
, r_symndx
))
5399 bfd_put_64 (output_bfd
, value
, base_got
->contents
+ off
);
5401 if (bfd_link_pic (info
))
5404 Elf_Internal_Rela outrel
;
5406 /* For local symbol, we have done absolute relocation in static
5407 linking stageh. While for share library, we need to update
5408 the content of GOT entry according to the share objects
5409 loading base address. So we need to generate a
5410 R_AARCH64_RELATIVE reloc for dynamic linker. */
5411 s
= globals
->root
.srelgot
;
5415 outrel
.r_offset
= got_entry_addr
;
5416 outrel
.r_info
= ELFNN_R_INFO (0, AARCH64_R (RELATIVE
));
5417 outrel
.r_addend
= value
;
5418 elf_append_rela (output_bfd
, s
, &outrel
);
5421 symbol_got_offset_mark (input_bfd
, h
, r_symndx
);
5424 /* Update the relocation value to GOT entry addr as we have transformed
5425 the direct data access into indirect data access through GOT. */
5426 value
= got_entry_addr
;
5428 if (bfd_r_type
== BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15
5429 || bfd_r_type
== BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14
)
5430 addend
= base_got
->output_section
->vma
+ base_got
->output_offset
;
5432 value
= _bfd_aarch64_elf_resolve_relocation (bfd_r_type
, place
, value
,
5433 addend
, weak_undef_p
);
5438 case BFD_RELOC_AARCH64_LD64_GOTOFF_LO15
:
5439 case BFD_RELOC_AARCH64_MOVW_GOTOFF_G0_NC
:
5440 case BFD_RELOC_AARCH64_MOVW_GOTOFF_G1
:
5442 value
= aarch64_calculate_got_entry_vma (h
, globals
, info
, value
,
5444 unresolved_reloc_p
);
5447 struct elf_aarch64_local_symbol
*locals
5448 = elf_aarch64_locals (input_bfd
);
5452 int howto_index
= bfd_r_type
- BFD_RELOC_AARCH64_RELOC_START
;
5453 (*_bfd_error_handler
)
5454 (_("%B: Local symbol descriptor table be NULL when applying "
5455 "relocation %s against local symbol"),
5456 input_bfd
, elfNN_aarch64_howto_table
[howto_index
].name
);
5460 off
= symbol_got_offset (input_bfd
, h
, r_symndx
);
5461 base_got
= globals
->root
.sgot
;
5462 if (base_got
== NULL
)
5465 bfd_vma got_entry_addr
= (base_got
->output_section
->vma
5466 + base_got
->output_offset
+ off
);
5468 if (!symbol_got_offset_mark_p (input_bfd
, h
, r_symndx
))
5470 bfd_put_64 (output_bfd
, value
, base_got
->contents
+ off
);
5472 if (bfd_link_pic (info
))
5475 Elf_Internal_Rela outrel
;
5477 /* For local symbol, we have done absolute relocation in static
5478 linking stage. While for share library, we need to update
5479 the content of GOT entry according to the share objects
5480 loading base address. So we need to generate a
5481 R_AARCH64_RELATIVE reloc for dynamic linker. */
5482 s
= globals
->root
.srelgot
;
5486 outrel
.r_offset
= got_entry_addr
;
5487 outrel
.r_info
= ELFNN_R_INFO (0, AARCH64_R (RELATIVE
));
5488 outrel
.r_addend
= value
;
5489 elf_append_rela (output_bfd
, s
, &outrel
);
5492 symbol_got_offset_mark (input_bfd
, h
, r_symndx
);
5496 /* Update the relocation value to GOT entry addr as we have transformed
5497 the direct data access into indirect data access through GOT. */
5498 value
= symbol_got_offset (input_bfd
, h
, r_symndx
);
5499 value
= _bfd_aarch64_elf_resolve_relocation (bfd_r_type
, place
, value
,
5501 *unresolved_reloc_p
= FALSE
;
5504 case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC
:
5505 case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21
:
5506 case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21
:
5507 case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21
:
5508 case BFD_RELOC_AARCH64_TLSIE_LD32_GOTTPREL_LO12_NC
:
5509 case BFD_RELOC_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC
:
5510 case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19
:
5511 case BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC
:
5512 case BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21
:
5513 case BFD_RELOC_AARCH64_TLSLD_ADR_PREL21
:
5514 if (globals
->root
.sgot
== NULL
)
5515 return bfd_reloc_notsupported
;
5517 value
= (symbol_got_offset (input_bfd
, h
, r_symndx
)
5518 + globals
->root
.sgot
->output_section
->vma
5519 + globals
->root
.sgot
->output_offset
);
5521 value
= _bfd_aarch64_elf_resolve_relocation (bfd_r_type
, place
, value
,
5523 *unresolved_reloc_p
= FALSE
;
5526 case BFD_RELOC_AARCH64_TLSGD_MOVW_G0_NC
:
5527 case BFD_RELOC_AARCH64_TLSGD_MOVW_G1
:
5528 case BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G0_NC
:
5529 case BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G1
:
5530 if (globals
->root
.sgot
== NULL
)
5531 return bfd_reloc_notsupported
;
5533 value
= symbol_got_offset (input_bfd
, h
, r_symndx
);
5534 value
= _bfd_aarch64_elf_resolve_relocation (bfd_r_type
, place
, value
,
5536 *unresolved_reloc_p
= FALSE
;
5539 case BFD_RELOC_AARCH64_TLSLD_ADD_DTPREL_HI12
:
5540 case BFD_RELOC_AARCH64_TLSLD_ADD_DTPREL_LO12
:
5541 case BFD_RELOC_AARCH64_TLSLD_ADD_DTPREL_LO12_NC
:
5542 case BFD_RELOC_AARCH64_TLSLD_LDST16_DTPREL_LO12
:
5543 case BFD_RELOC_AARCH64_TLSLD_LDST16_DTPREL_LO12_NC
:
5544 case BFD_RELOC_AARCH64_TLSLD_LDST32_DTPREL_LO12
:
5545 case BFD_RELOC_AARCH64_TLSLD_LDST32_DTPREL_LO12_NC
:
5546 case BFD_RELOC_AARCH64_TLSLD_LDST64_DTPREL_LO12
:
5547 case BFD_RELOC_AARCH64_TLSLD_LDST64_DTPREL_LO12_NC
:
5548 case BFD_RELOC_AARCH64_TLSLD_LDST8_DTPREL_LO12
:
5549 case BFD_RELOC_AARCH64_TLSLD_LDST8_DTPREL_LO12_NC
:
5550 case BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G0
:
5551 case BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G0_NC
:
5552 case BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G1
:
5553 case BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G1_NC
:
5554 case BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G2
:
5555 value
= _bfd_aarch64_elf_resolve_relocation (bfd_r_type
, place
, value
,
5556 signed_addend
- dtpoff_base (info
),
5560 case BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_HI12
:
5561 case BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_LO12
:
5562 case BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_LO12_NC
:
5563 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0
:
5564 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC
:
5565 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1
:
5566 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1_NC
:
5567 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G2
:
5568 value
= _bfd_aarch64_elf_resolve_relocation (bfd_r_type
, place
, value
,
5569 signed_addend
- tpoff_base (info
),
5571 *unresolved_reloc_p
= FALSE
;
5574 case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12_NC
:
5575 case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21
:
5576 case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21
:
5577 case BFD_RELOC_AARCH64_TLSDESC_LD32_LO12_NC
:
5578 case BFD_RELOC_AARCH64_TLSDESC_LD64_LO12_NC
:
5579 case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19
:
5580 if (globals
->root
.sgot
== NULL
)
5581 return bfd_reloc_notsupported
;
5582 value
= (symbol_tlsdesc_got_offset (input_bfd
, h
, r_symndx
)
5583 + globals
->root
.sgotplt
->output_section
->vma
5584 + globals
->root
.sgotplt
->output_offset
5585 + globals
->sgotplt_jump_table_size
);
5587 value
= _bfd_aarch64_elf_resolve_relocation (bfd_r_type
, place
, value
,
5589 *unresolved_reloc_p
= FALSE
;
5592 case BFD_RELOC_AARCH64_TLSDESC_OFF_G0_NC
:
5593 case BFD_RELOC_AARCH64_TLSDESC_OFF_G1
:
5594 if (globals
->root
.sgot
== NULL
)
5595 return bfd_reloc_notsupported
;
5597 value
= (symbol_tlsdesc_got_offset (input_bfd
, h
, r_symndx
)
5598 + globals
->root
.sgotplt
->output_section
->vma
5599 + globals
->root
.sgotplt
->output_offset
5600 + globals
->sgotplt_jump_table_size
);
5602 value
-= (globals
->root
.sgot
->output_section
->vma
5603 + globals
->root
.sgot
->output_offset
);
5605 value
= _bfd_aarch64_elf_resolve_relocation (bfd_r_type
, place
, value
,
5607 *unresolved_reloc_p
= FALSE
;
5611 return bfd_reloc_notsupported
;
5615 *saved_addend
= value
;
5617 /* Only apply the final relocation in a sequence. */
5619 return bfd_reloc_continue
;
5621 return _bfd_aarch64_elf_put_addend (input_bfd
, hit_data
, bfd_r_type
,
5625 /* Handle TLS relaxations. Relaxing is possible for symbols that use
5626 R_AARCH64_TLSDESC_ADR_{PAGE, LD64_LO12_NC, ADD_LO12_NC} during a static
5629 Return bfd_reloc_ok if we're done, bfd_reloc_continue if the caller
5630 is to then call final_link_relocate. Return other values in the
5633 static bfd_reloc_status_type
5634 elfNN_aarch64_tls_relax (struct elf_aarch64_link_hash_table
*globals
,
5635 bfd
*input_bfd
, bfd_byte
*contents
,
5636 Elf_Internal_Rela
*rel
, struct elf_link_hash_entry
*h
)
5638 bfd_boolean is_local
= h
== NULL
;
5639 unsigned int r_type
= ELFNN_R_TYPE (rel
->r_info
);
5642 BFD_ASSERT (globals
&& input_bfd
&& contents
&& rel
);
5644 switch (elfNN_aarch64_bfd_reloc_from_type (r_type
))
5646 case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21
:
5647 case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21
:
5650 /* GD->LE relaxation:
5651 adrp x0, :tlsgd:var => movz x0, :tprel_g1:var
5653 adrp x0, :tlsdesc:var => movz x0, :tprel_g1:var
5655 bfd_putl32 (0xd2a00000, contents
+ rel
->r_offset
);
5656 return bfd_reloc_continue
;
5660 /* GD->IE relaxation:
5661 adrp x0, :tlsgd:var => adrp x0, :gottprel:var
5663 adrp x0, :tlsdesc:var => adrp x0, :gottprel:var
5665 return bfd_reloc_continue
;
5668 case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21
:
5672 case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19
:
5675 /* Tiny TLSDESC->LE relaxation:
5676 ldr x1, :tlsdesc:var => movz x0, #:tprel_g1:var
5677 adr x0, :tlsdesc:var => movk x0, #:tprel_g0_nc:var
5681 BFD_ASSERT (ELFNN_R_TYPE (rel
[1].r_info
) == AARCH64_R (TLSDESC_ADR_PREL21
));
5682 BFD_ASSERT (ELFNN_R_TYPE (rel
[2].r_info
) == AARCH64_R (TLSDESC_CALL
));
5684 rel
[1].r_info
= ELFNN_R_INFO (ELFNN_R_SYM (rel
->r_info
),
5685 AARCH64_R (TLSLE_MOVW_TPREL_G0_NC
));
5686 rel
[2].r_info
= ELFNN_R_INFO (STN_UNDEF
, R_AARCH64_NONE
);
5688 bfd_putl32 (0xd2a00000, contents
+ rel
->r_offset
);
5689 bfd_putl32 (0xf2800000, contents
+ rel
->r_offset
+ 4);
5690 bfd_putl32 (INSN_NOP
, contents
+ rel
->r_offset
+ 8);
5691 return bfd_reloc_continue
;
5695 /* Tiny TLSDESC->IE relaxation:
5696 ldr x1, :tlsdesc:var => ldr x0, :gottprel:var
5697 adr x0, :tlsdesc:var => nop
5701 BFD_ASSERT (ELFNN_R_TYPE (rel
[1].r_info
) == AARCH64_R (TLSDESC_ADR_PREL21
));
5702 BFD_ASSERT (ELFNN_R_TYPE (rel
[2].r_info
) == AARCH64_R (TLSDESC_CALL
));
5704 rel
[1].r_info
= ELFNN_R_INFO (STN_UNDEF
, R_AARCH64_NONE
);
5705 rel
[2].r_info
= ELFNN_R_INFO (STN_UNDEF
, R_AARCH64_NONE
);
5707 bfd_putl32 (0x58000000, contents
+ rel
->r_offset
);
5708 bfd_putl32 (INSN_NOP
, contents
+ rel
->r_offset
+ 4);
5709 bfd_putl32 (INSN_NOP
, contents
+ rel
->r_offset
+ 8);
5710 return bfd_reloc_continue
;
5713 case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21
:
5716 /* Tiny GD->LE relaxation:
5717 adr x0, :tlsgd:var => mrs x1, tpidr_el0
5718 bl __tls_get_addr => add x0, x1, #:tprel_hi12:x, lsl #12
5719 nop => add x0, x0, #:tprel_lo12_nc:x
5722 /* First kill the tls_get_addr reloc on the bl instruction. */
5723 BFD_ASSERT (rel
->r_offset
+ 4 == rel
[1].r_offset
);
5725 bfd_putl32 (0xd53bd041, contents
+ rel
->r_offset
+ 0);
5726 bfd_putl32 (0x91400020, contents
+ rel
->r_offset
+ 4);
5727 bfd_putl32 (0x91000000, contents
+ rel
->r_offset
+ 8);
5729 rel
[1].r_info
= ELFNN_R_INFO (ELFNN_R_SYM (rel
->r_info
),
5730 AARCH64_R (TLSLE_ADD_TPREL_LO12_NC
));
5731 rel
[1].r_offset
= rel
->r_offset
+ 8;
5733 /* Move the current relocation to the second instruction in
5736 rel
->r_info
= ELFNN_R_INFO (ELFNN_R_SYM (rel
->r_info
),
5737 AARCH64_R (TLSLE_ADD_TPREL_HI12
));
5738 return bfd_reloc_continue
;
5742 /* Tiny GD->IE relaxation:
5743 adr x0, :tlsgd:var => ldr x0, :gottprel:var
5744 bl __tls_get_addr => mrs x1, tpidr_el0
5745 nop => add x0, x0, x1
5748 /* First kill the tls_get_addr reloc on the bl instruction. */
5749 BFD_ASSERT (rel
->r_offset
+ 4 == rel
[1].r_offset
);
5750 rel
[1].r_info
= ELFNN_R_INFO (STN_UNDEF
, R_AARCH64_NONE
);
5752 bfd_putl32 (0x58000000, contents
+ rel
->r_offset
);
5753 bfd_putl32 (0xd53bd041, contents
+ rel
->r_offset
+ 4);
5754 bfd_putl32 (0x8b000020, contents
+ rel
->r_offset
+ 8);
5755 return bfd_reloc_continue
;
5759 case BFD_RELOC_AARCH64_TLSGD_MOVW_G1
:
5760 BFD_ASSERT (ELFNN_R_TYPE (rel
[1].r_info
) == AARCH64_R (TLSGD_MOVW_G0_NC
));
5761 BFD_ASSERT (rel
->r_offset
+ 12 == rel
[2].r_offset
);
5762 BFD_ASSERT (ELFNN_R_TYPE (rel
[2].r_info
) == AARCH64_R (CALL26
));
5766 /* Large GD->LE relaxation:
5767 movz x0, #:tlsgd_g1:var => movz x0, #:tprel_g2:var, lsl #32
5768 movk x0, #:tlsgd_g0_nc:var => movk x0, #:tprel_g1_nc:var, lsl #16
5769 add x0, gp, x0 => movk x0, #:tprel_g0_nc:var
5770 bl __tls_get_addr => mrs x1, tpidr_el0
5771 nop => add x0, x0, x1
5773 rel
[2].r_info
= ELFNN_R_INFO (ELFNN_R_SYM (rel
->r_info
),
5774 AARCH64_R (TLSLE_MOVW_TPREL_G0_NC
));
5775 rel
[2].r_offset
= rel
->r_offset
+ 8;
5777 bfd_putl32 (0xd2c00000, contents
+ rel
->r_offset
+ 0);
5778 bfd_putl32 (0xf2a00000, contents
+ rel
->r_offset
+ 4);
5779 bfd_putl32 (0xf2800000, contents
+ rel
->r_offset
+ 8);
5780 bfd_putl32 (0xd53bd041, contents
+ rel
->r_offset
+ 12);
5781 bfd_putl32 (0x8b000020, contents
+ rel
->r_offset
+ 16);
5785 /* Large GD->IE relaxation:
5786 movz x0, #:tlsgd_g1:var => movz x0, #:gottprel_g1:var, lsl #16
5787 movk x0, #:tlsgd_g0_nc:var => movk x0, #:gottprel_g0_nc:var
5788 add x0, gp, x0 => ldr x0, [gp, x0]
5789 bl __tls_get_addr => mrs x1, tpidr_el0
5790 nop => add x0, x0, x1
5792 rel
[2].r_info
= ELFNN_R_INFO (STN_UNDEF
, R_AARCH64_NONE
);
5793 bfd_putl32 (0xd2a80000, contents
+ rel
->r_offset
+ 0);
5794 bfd_putl32 (0x58000000, contents
+ rel
->r_offset
+ 8);
5795 bfd_putl32 (0xd53bd041, contents
+ rel
->r_offset
+ 12);
5796 bfd_putl32 (0x8b000020, contents
+ rel
->r_offset
+ 16);
5798 return bfd_reloc_continue
;
5800 case BFD_RELOC_AARCH64_TLSGD_MOVW_G0_NC
:
5801 return bfd_reloc_continue
;
5804 case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19
:
5805 return bfd_reloc_continue
;
5807 case BFD_RELOC_AARCH64_TLSDESC_LDNN_LO12_NC
:
5810 /* GD->LE relaxation:
5811 ldr xd, [x0, #:tlsdesc_lo12:var] => movk x0, :tprel_g0_nc:var
5813 bfd_putl32 (0xf2800000, contents
+ rel
->r_offset
);
5814 return bfd_reloc_continue
;
5818 /* GD->IE relaxation:
5819 ldr xd, [x0, #:tlsdesc_lo12:var] => ldr x0, [x0, #:gottprel_lo12:var]
5821 insn
= bfd_getl32 (contents
+ rel
->r_offset
);
5823 bfd_putl32 (insn
, contents
+ rel
->r_offset
);
5824 return bfd_reloc_continue
;
5827 case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC
:
5830 /* GD->LE relaxation
5831 add x0, #:tlsgd_lo12:var => movk x0, :tprel_g0_nc:var
5832 bl __tls_get_addr => mrs x1, tpidr_el0
5833 nop => add x0, x1, x0
5836 /* First kill the tls_get_addr reloc on the bl instruction. */
5837 BFD_ASSERT (rel
->r_offset
+ 4 == rel
[1].r_offset
);
5838 rel
[1].r_info
= ELFNN_R_INFO (STN_UNDEF
, R_AARCH64_NONE
);
5840 bfd_putl32 (0xf2800000, contents
+ rel
->r_offset
);
5841 bfd_putl32 (0xd53bd041, contents
+ rel
->r_offset
+ 4);
5842 bfd_putl32 (0x8b000020, contents
+ rel
->r_offset
+ 8);
5843 return bfd_reloc_continue
;
5847 /* GD->IE relaxation
5848 ADD x0, #:tlsgd_lo12:var => ldr x0, [x0, #:gottprel_lo12:var]
5849 BL __tls_get_addr => mrs x1, tpidr_el0
5851 NOP => add x0, x1, x0
5854 BFD_ASSERT (ELFNN_R_TYPE (rel
[1].r_info
) == AARCH64_R (CALL26
));
5856 /* Remove the relocation on the BL instruction. */
5857 rel
[1].r_info
= ELFNN_R_INFO (STN_UNDEF
, R_AARCH64_NONE
);
5859 bfd_putl32 (0xf9400000, contents
+ rel
->r_offset
);
5861 /* We choose to fixup the BL and NOP instructions using the
5862 offset from the second relocation to allow flexibility in
5863 scheduling instructions between the ADD and BL. */
5864 bfd_putl32 (0xd53bd041, contents
+ rel
[1].r_offset
);
5865 bfd_putl32 (0x8b000020, contents
+ rel
[1].r_offset
+ 4);
5866 return bfd_reloc_continue
;
5869 case BFD_RELOC_AARCH64_TLSDESC_ADD
:
5870 case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12_NC
:
5871 case BFD_RELOC_AARCH64_TLSDESC_CALL
:
5872 /* GD->IE/LE relaxation:
5873 add x0, x0, #:tlsdesc_lo12:var => nop
5876 bfd_putl32 (INSN_NOP
, contents
+ rel
->r_offset
);
5877 return bfd_reloc_ok
;
5879 case BFD_RELOC_AARCH64_TLSDESC_LDR
:
5882 /* GD->LE relaxation:
5883 ldr xd, [gp, xn] => movk x0, #:tprel_g0_nc:var
5885 bfd_putl32 (0xf2800000, contents
+ rel
->r_offset
);
5886 return bfd_reloc_continue
;
5890 /* GD->IE relaxation:
5891 ldr xd, [gp, xn] => ldr x0, [gp, xn]
5893 insn
= bfd_getl32 (contents
+ rel
->r_offset
);
5895 bfd_putl32 (insn
, contents
+ rel
->r_offset
);
5896 return bfd_reloc_ok
;
5899 case BFD_RELOC_AARCH64_TLSDESC_OFF_G0_NC
:
5900 /* GD->LE relaxation:
5901 movk xd, #:tlsdesc_off_g0_nc:var => movk x0, #:tprel_g1_nc:var, lsl #16
5903 movk xd, #:tlsdesc_off_g0_nc:var => movk xd, #:gottprel_g0_nc:var
5906 bfd_putl32 (0xf2a00000, contents
+ rel
->r_offset
);
5907 return bfd_reloc_continue
;
5909 case BFD_RELOC_AARCH64_TLSDESC_OFF_G1
:
5912 /* GD->LE relaxation:
5913 movz xd, #:tlsdesc_off_g1:var => movz x0, #:tprel_g2:var, lsl #32
5915 bfd_putl32 (0xd2c00000, contents
+ rel
->r_offset
);
5916 return bfd_reloc_continue
;
5920 /* GD->IE relaxation:
5921 movz xd, #:tlsdesc_off_g1:var => movz xd, #:gottprel_g1:var, lsl #16
5923 insn
= bfd_getl32 (contents
+ rel
->r_offset
);
5924 bfd_putl32 (0xd2a00000 | (insn
& 0x1f), contents
+ rel
->r_offset
);
5925 return bfd_reloc_continue
;
5928 case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21
:
5929 /* IE->LE relaxation:
5930 adrp xd, :gottprel:var => movz xd, :tprel_g1:var
5934 insn
= bfd_getl32 (contents
+ rel
->r_offset
);
5935 bfd_putl32 (0xd2a00000 | (insn
& 0x1f), contents
+ rel
->r_offset
);
5937 return bfd_reloc_continue
;
5939 case BFD_RELOC_AARCH64_TLSIE_LDNN_GOTTPREL_LO12_NC
:
5940 /* IE->LE relaxation:
5941 ldr xd, [xm, #:gottprel_lo12:var] => movk xd, :tprel_g0_nc:var
5945 insn
= bfd_getl32 (contents
+ rel
->r_offset
);
5946 bfd_putl32 (0xf2800000 | (insn
& 0x1f), contents
+ rel
->r_offset
);
5948 return bfd_reloc_continue
;
5950 case BFD_RELOC_AARCH64_TLSLD_ADR_PREL21
:
5951 /* LD->LE relaxation (tiny):
5952 adr x0, :tlsldm:x => mrs x0, tpidr_el0
5953 bl __tls_get_addr => add x0, x0, TCB_SIZE
5957 BFD_ASSERT (rel
->r_offset
+ 4 == rel
[1].r_offset
);
5958 BFD_ASSERT (ELFNN_R_TYPE (rel
[1].r_info
) == AARCH64_R (CALL26
));
5959 /* No need of CALL26 relocation for tls_get_addr. */
5960 rel
[1].r_info
= ELFNN_R_INFO (STN_UNDEF
, R_AARCH64_NONE
);
5961 bfd_putl32 (0xd53bd040, contents
+ rel
->r_offset
+ 0);
5962 bfd_putl32 (0x91004000, contents
+ rel
->r_offset
+ 4);
5963 return bfd_reloc_ok
;
5965 return bfd_reloc_continue
;
5967 case BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21
:
5968 /* LD->LE relaxation (small):
5969 adrp x0, :tlsldm:x => mrs x0, tpidr_el0
5973 bfd_putl32 (0xd53bd040, contents
+ rel
->r_offset
);
5974 return bfd_reloc_ok
;
5976 return bfd_reloc_continue
;
5978 case BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC
:
5979 /* LD->LE relaxation (small):
5980 add x0, #:tlsldm_lo12:x => add x0, x0, TCB_SIZE
5981 bl __tls_get_addr => nop
5985 BFD_ASSERT (rel
->r_offset
+ 4 == rel
[1].r_offset
);
5986 BFD_ASSERT (ELFNN_R_TYPE (rel
[1].r_info
) == AARCH64_R (CALL26
));
5987 /* No need of CALL26 relocation for tls_get_addr. */
5988 rel
[1].r_info
= ELFNN_R_INFO (STN_UNDEF
, R_AARCH64_NONE
);
5989 bfd_putl32 (0x91004000, contents
+ rel
->r_offset
+ 0);
5990 bfd_putl32 (0xd503201f, contents
+ rel
->r_offset
+ 4);
5991 return bfd_reloc_ok
;
5993 return bfd_reloc_continue
;
5996 return bfd_reloc_continue
;
5999 return bfd_reloc_ok
;
6002 /* Relocate an AArch64 ELF section. */
6005 elfNN_aarch64_relocate_section (bfd
*output_bfd
,
6006 struct bfd_link_info
*info
,
6008 asection
*input_section
,
6010 Elf_Internal_Rela
*relocs
,
6011 Elf_Internal_Sym
*local_syms
,
6012 asection
**local_sections
)
6014 Elf_Internal_Shdr
*symtab_hdr
;
6015 struct elf_link_hash_entry
**sym_hashes
;
6016 Elf_Internal_Rela
*rel
;
6017 Elf_Internal_Rela
*relend
;
6019 struct elf_aarch64_link_hash_table
*globals
;
6020 bfd_boolean save_addend
= FALSE
;
6023 globals
= elf_aarch64_hash_table (info
);
6025 symtab_hdr
= &elf_symtab_hdr (input_bfd
);
6026 sym_hashes
= elf_sym_hashes (input_bfd
);
6029 relend
= relocs
+ input_section
->reloc_count
;
6030 for (; rel
< relend
; rel
++)
6032 unsigned int r_type
;
6033 bfd_reloc_code_real_type bfd_r_type
;
6034 bfd_reloc_code_real_type relaxed_bfd_r_type
;
6035 reloc_howto_type
*howto
;
6036 unsigned long r_symndx
;
6037 Elf_Internal_Sym
*sym
;
6039 struct elf_link_hash_entry
*h
;
6041 bfd_reloc_status_type r
;
6044 bfd_boolean unresolved_reloc
= FALSE
;
6045 char *error_message
= NULL
;
6047 r_symndx
= ELFNN_R_SYM (rel
->r_info
);
6048 r_type
= ELFNN_R_TYPE (rel
->r_info
);
6050 bfd_reloc
.howto
= elfNN_aarch64_howto_from_type (r_type
);
6051 howto
= bfd_reloc
.howto
;
6055 (*_bfd_error_handler
)
6056 (_("%B: unrecognized relocation (0x%x) in section `%A'"),
6057 input_bfd
, input_section
, r_type
);
6060 bfd_r_type
= elfNN_aarch64_bfd_reloc_from_howto (howto
);
6066 if (r_symndx
< symtab_hdr
->sh_info
)
6068 sym
= local_syms
+ r_symndx
;
6069 sym_type
= ELFNN_ST_TYPE (sym
->st_info
);
6070 sec
= local_sections
[r_symndx
];
6072 /* An object file might have a reference to a local
6073 undefined symbol. This is a daft object file, but we
6074 should at least do something about it. */
6075 if (r_type
!= R_AARCH64_NONE
&& r_type
!= R_AARCH64_NULL
6076 && bfd_is_und_section (sec
)
6077 && ELF_ST_BIND (sym
->st_info
) != STB_WEAK
)
6079 if (!info
->callbacks
->undefined_symbol
6080 (info
, bfd_elf_string_from_elf_section
6081 (input_bfd
, symtab_hdr
->sh_link
, sym
->st_name
),
6082 input_bfd
, input_section
, rel
->r_offset
, TRUE
))
6086 relocation
= _bfd_elf_rela_local_sym (output_bfd
, sym
, &sec
, rel
);
6088 /* Relocate against local STT_GNU_IFUNC symbol. */
6089 if (!bfd_link_relocatable (info
)
6090 && ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
)
6092 h
= elfNN_aarch64_get_local_sym_hash (globals
, input_bfd
,
6097 /* Set STT_GNU_IFUNC symbol value. */
6098 h
->root
.u
.def
.value
= sym
->st_value
;
6099 h
->root
.u
.def
.section
= sec
;
6104 bfd_boolean warned
, ignored
;
6106 RELOC_FOR_GLOBAL_SYMBOL (info
, input_bfd
, input_section
, rel
,
6107 r_symndx
, symtab_hdr
, sym_hashes
,
6109 unresolved_reloc
, warned
, ignored
);
6114 if (sec
!= NULL
&& discarded_section (sec
))
6115 RELOC_AGAINST_DISCARDED_SECTION (info
, input_bfd
, input_section
,
6116 rel
, 1, relend
, howto
, 0, contents
);
6118 if (bfd_link_relocatable (info
))
6122 name
= h
->root
.root
.string
;
6125 name
= (bfd_elf_string_from_elf_section
6126 (input_bfd
, symtab_hdr
->sh_link
, sym
->st_name
));
6127 if (name
== NULL
|| *name
== '\0')
6128 name
= bfd_section_name (input_bfd
, sec
);
6132 && r_type
!= R_AARCH64_NONE
6133 && r_type
!= R_AARCH64_NULL
6135 || h
->root
.type
== bfd_link_hash_defined
6136 || h
->root
.type
== bfd_link_hash_defweak
)
6137 && IS_AARCH64_TLS_RELOC (bfd_r_type
) != (sym_type
== STT_TLS
))
6139 (*_bfd_error_handler
)
6140 ((sym_type
== STT_TLS
6141 ? _("%B(%A+0x%lx): %s used with TLS symbol %s")
6142 : _("%B(%A+0x%lx): %s used with non-TLS symbol %s")),
6144 input_section
, (long) rel
->r_offset
, howto
->name
, name
);
6147 /* We relax only if we can see that there can be a valid transition
6148 from a reloc type to another.
6149 We call elfNN_aarch64_final_link_relocate unless we're completely
6150 done, i.e., the relaxation produced the final output we want. */
6152 relaxed_bfd_r_type
= aarch64_tls_transition (input_bfd
, info
, r_type
,
6154 if (relaxed_bfd_r_type
!= bfd_r_type
)
6156 bfd_r_type
= relaxed_bfd_r_type
;
6157 howto
= elfNN_aarch64_howto_from_bfd_reloc (bfd_r_type
);
6158 BFD_ASSERT (howto
!= NULL
);
6159 r_type
= howto
->type
;
6160 r
= elfNN_aarch64_tls_relax (globals
, input_bfd
, contents
, rel
, h
);
6161 unresolved_reloc
= 0;
6164 r
= bfd_reloc_continue
;
6166 /* There may be multiple consecutive relocations for the
6167 same offset. In that case we are supposed to treat the
6168 output of each relocation as the addend for the next. */
6169 if (rel
+ 1 < relend
6170 && rel
->r_offset
== rel
[1].r_offset
6171 && ELFNN_R_TYPE (rel
[1].r_info
) != R_AARCH64_NONE
6172 && ELFNN_R_TYPE (rel
[1].r_info
) != R_AARCH64_NULL
)
6175 save_addend
= FALSE
;
6177 if (r
== bfd_reloc_continue
)
6178 r
= elfNN_aarch64_final_link_relocate (howto
, input_bfd
, output_bfd
,
6179 input_section
, contents
, rel
,
6180 relocation
, info
, sec
,
6181 h
, &unresolved_reloc
,
6182 save_addend
, &addend
, sym
);
6184 switch (elfNN_aarch64_bfd_reloc_from_type (r_type
))
6186 case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC
:
6187 case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21
:
6188 case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21
:
6189 case BFD_RELOC_AARCH64_TLSGD_MOVW_G0_NC
:
6190 case BFD_RELOC_AARCH64_TLSGD_MOVW_G1
:
6191 case BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC
:
6192 case BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21
:
6193 case BFD_RELOC_AARCH64_TLSLD_ADR_PREL21
:
6194 if (! symbol_got_offset_mark_p (input_bfd
, h
, r_symndx
))
6196 bfd_boolean need_relocs
= FALSE
;
6201 off
= symbol_got_offset (input_bfd
, h
, r_symndx
);
6202 indx
= h
&& h
->dynindx
!= -1 ? h
->dynindx
: 0;
6205 (bfd_link_pic (info
) || indx
!= 0) &&
6207 || ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
6208 || h
->root
.type
!= bfd_link_hash_undefweak
);
6210 BFD_ASSERT (globals
->root
.srelgot
!= NULL
);
6214 Elf_Internal_Rela rela
;
6215 rela
.r_info
= ELFNN_R_INFO (indx
, AARCH64_R (TLS_DTPMOD
));
6217 rela
.r_offset
= globals
->root
.sgot
->output_section
->vma
+
6218 globals
->root
.sgot
->output_offset
+ off
;
6221 loc
= globals
->root
.srelgot
->contents
;
6222 loc
+= globals
->root
.srelgot
->reloc_count
++
6223 * RELOC_SIZE (htab
);
6224 bfd_elfNN_swap_reloca_out (output_bfd
, &rela
, loc
);
6226 bfd_reloc_code_real_type real_type
=
6227 elfNN_aarch64_bfd_reloc_from_type (r_type
);
6229 if (real_type
== BFD_RELOC_AARCH64_TLSLD_ADR_PREL21
6230 || real_type
== BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21
6231 || real_type
== BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC
)
6233 /* For local dynamic, don't generate DTPREL in any case.
6234 Initialize the DTPREL slot into zero, so we get module
6235 base address when invoke runtime TLS resolver. */
6236 bfd_put_NN (output_bfd
, 0,
6237 globals
->root
.sgot
->contents
+ off
6242 bfd_put_NN (output_bfd
,
6243 relocation
- dtpoff_base (info
),
6244 globals
->root
.sgot
->contents
+ off
6249 /* This TLS symbol is global. We emit a
6250 relocation to fixup the tls offset at load
6253 ELFNN_R_INFO (indx
, AARCH64_R (TLS_DTPREL
));
6256 (globals
->root
.sgot
->output_section
->vma
6257 + globals
->root
.sgot
->output_offset
+ off
6260 loc
= globals
->root
.srelgot
->contents
;
6261 loc
+= globals
->root
.srelgot
->reloc_count
++
6262 * RELOC_SIZE (globals
);
6263 bfd_elfNN_swap_reloca_out (output_bfd
, &rela
, loc
);
6264 bfd_put_NN (output_bfd
, (bfd_vma
) 0,
6265 globals
->root
.sgot
->contents
+ off
6271 bfd_put_NN (output_bfd
, (bfd_vma
) 1,
6272 globals
->root
.sgot
->contents
+ off
);
6273 bfd_put_NN (output_bfd
,
6274 relocation
- dtpoff_base (info
),
6275 globals
->root
.sgot
->contents
+ off
6279 symbol_got_offset_mark (input_bfd
, h
, r_symndx
);
6283 case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21
:
6284 case BFD_RELOC_AARCH64_TLSIE_LDNN_GOTTPREL_LO12_NC
:
6285 case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19
:
6286 case BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G0_NC
:
6287 case BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G1
:
6288 if (! symbol_got_offset_mark_p (input_bfd
, h
, r_symndx
))
6290 bfd_boolean need_relocs
= FALSE
;
6295 off
= symbol_got_offset (input_bfd
, h
, r_symndx
);
6297 indx
= h
&& h
->dynindx
!= -1 ? h
->dynindx
: 0;
6300 (bfd_link_pic (info
) || indx
!= 0) &&
6302 || ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
6303 || h
->root
.type
!= bfd_link_hash_undefweak
);
6305 BFD_ASSERT (globals
->root
.srelgot
!= NULL
);
6309 Elf_Internal_Rela rela
;
6312 rela
.r_addend
= relocation
- dtpoff_base (info
);
6316 rela
.r_info
= ELFNN_R_INFO (indx
, AARCH64_R (TLS_TPREL
));
6317 rela
.r_offset
= globals
->root
.sgot
->output_section
->vma
+
6318 globals
->root
.sgot
->output_offset
+ off
;
6320 loc
= globals
->root
.srelgot
->contents
;
6321 loc
+= globals
->root
.srelgot
->reloc_count
++
6322 * RELOC_SIZE (htab
);
6324 bfd_elfNN_swap_reloca_out (output_bfd
, &rela
, loc
);
6326 bfd_put_NN (output_bfd
, rela
.r_addend
,
6327 globals
->root
.sgot
->contents
+ off
);
6330 bfd_put_NN (output_bfd
, relocation
- tpoff_base (info
),
6331 globals
->root
.sgot
->contents
+ off
);
6333 symbol_got_offset_mark (input_bfd
, h
, r_symndx
);
6337 case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12_NC
:
6338 case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21
:
6339 case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21
:
6340 case BFD_RELOC_AARCH64_TLSDESC_LDNN_LO12_NC
:
6341 case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19
:
6342 case BFD_RELOC_AARCH64_TLSDESC_OFF_G0_NC
:
6343 case BFD_RELOC_AARCH64_TLSDESC_OFF_G1
:
6344 if (! symbol_tlsdesc_got_offset_mark_p (input_bfd
, h
, r_symndx
))
6346 bfd_boolean need_relocs
= FALSE
;
6347 int indx
= h
&& h
->dynindx
!= -1 ? h
->dynindx
: 0;
6348 bfd_vma off
= symbol_tlsdesc_got_offset (input_bfd
, h
, r_symndx
);
6350 need_relocs
= (h
== NULL
6351 || ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
6352 || h
->root
.type
!= bfd_link_hash_undefweak
);
6354 BFD_ASSERT (globals
->root
.srelgot
!= NULL
);
6355 BFD_ASSERT (globals
->root
.sgot
!= NULL
);
6360 Elf_Internal_Rela rela
;
6361 rela
.r_info
= ELFNN_R_INFO (indx
, AARCH64_R (TLSDESC
));
6364 rela
.r_offset
= (globals
->root
.sgotplt
->output_section
->vma
6365 + globals
->root
.sgotplt
->output_offset
6366 + off
+ globals
->sgotplt_jump_table_size
);
6369 rela
.r_addend
= relocation
- dtpoff_base (info
);
6371 /* Allocate the next available slot in the PLT reloc
6372 section to hold our R_AARCH64_TLSDESC, the next
6373 available slot is determined from reloc_count,
6374 which we step. But note, reloc_count was
6375 artifically moved down while allocating slots for
6376 real PLT relocs such that all of the PLT relocs
6377 will fit above the initial reloc_count and the
6378 extra stuff will fit below. */
6379 loc
= globals
->root
.srelplt
->contents
;
6380 loc
+= globals
->root
.srelplt
->reloc_count
++
6381 * RELOC_SIZE (globals
);
6383 bfd_elfNN_swap_reloca_out (output_bfd
, &rela
, loc
);
6385 bfd_put_NN (output_bfd
, (bfd_vma
) 0,
6386 globals
->root
.sgotplt
->contents
+ off
+
6387 globals
->sgotplt_jump_table_size
);
6388 bfd_put_NN (output_bfd
, (bfd_vma
) 0,
6389 globals
->root
.sgotplt
->contents
+ off
+
6390 globals
->sgotplt_jump_table_size
+
6394 symbol_tlsdesc_got_offset_mark (input_bfd
, h
, r_symndx
);
6401 /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
6402 because such sections are not SEC_ALLOC and thus ld.so will
6403 not process them. */
6404 if (unresolved_reloc
6405 && !((input_section
->flags
& SEC_DEBUGGING
) != 0
6407 && _bfd_elf_section_offset (output_bfd
, info
, input_section
,
6408 +rel
->r_offset
) != (bfd_vma
) - 1)
6410 (*_bfd_error_handler
)
6412 ("%B(%A+0x%lx): unresolvable %s relocation against symbol `%s'"),
6413 input_bfd
, input_section
, (long) rel
->r_offset
, howto
->name
,
6414 h
->root
.root
.string
);
6418 if (r
!= bfd_reloc_ok
&& r
!= bfd_reloc_continue
)
6420 bfd_reloc_code_real_type real_r_type
6421 = elfNN_aarch64_bfd_reloc_from_type (r_type
);
6425 case bfd_reloc_overflow
:
6426 if (!(*info
->callbacks
->reloc_overflow
)
6427 (info
, (h
? &h
->root
: NULL
), name
, howto
->name
, (bfd_vma
) 0,
6428 input_bfd
, input_section
, rel
->r_offset
))
6430 if (real_r_type
== BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15
6431 || real_r_type
== BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14
)
6433 (*info
->callbacks
->warning
)
6435 _("Too many GOT entries for -fpic, "
6436 "please recompile with -fPIC"),
6437 name
, input_bfd
, input_section
, rel
->r_offset
);
6440 /* Overflow can occur when a variable is referenced with a type
6441 that has a larger alignment than the type with which it was
6443 file1.c: extern int foo; int a (void) { return foo; }
6444 file2.c: char bar, foo, baz;
6445 If the variable is placed into a data section at an offset
6446 that is incompatible with the larger alignment requirement
6447 overflow will occur. (Strictly speaking this is not overflow
6448 but rather an alignment problem, but the bfd_reloc_ error
6449 enum does not have a value to cover that situation).
6451 Try to catch this situation here and provide a more helpful
6452 error message to the user. */
6453 if (addend
& ((1 << howto
->rightshift
) - 1)
6454 /* FIXME: Are we testing all of the appropriate reloc
6456 && (real_r_type
== BFD_RELOC_AARCH64_LD_LO19_PCREL
6457 || real_r_type
== BFD_RELOC_AARCH64_LDST16_LO12
6458 || real_r_type
== BFD_RELOC_AARCH64_LDST32_LO12
6459 || real_r_type
== BFD_RELOC_AARCH64_LDST64_LO12
6460 || real_r_type
== BFD_RELOC_AARCH64_LDST128_LO12
))
6462 info
->callbacks
->warning
6463 (info
, _("One possible cause of this error is that the \
6464 symbol is being referenced in the indicated code as if it had a larger \
6465 alignment than was declared where it was defined."),
6466 name
, input_bfd
, input_section
, rel
->r_offset
);
6470 case bfd_reloc_undefined
:
6471 if (!((*info
->callbacks
->undefined_symbol
)
6472 (info
, name
, input_bfd
, input_section
,
6473 rel
->r_offset
, TRUE
)))
6477 case bfd_reloc_outofrange
:
6478 error_message
= _("out of range");
6481 case bfd_reloc_notsupported
:
6482 error_message
= _("unsupported relocation");
6485 case bfd_reloc_dangerous
:
6486 /* error_message should already be set. */
6490 error_message
= _("unknown error");
6494 BFD_ASSERT (error_message
!= NULL
);
6495 if (!((*info
->callbacks
->reloc_dangerous
)
6496 (info
, error_message
, input_bfd
, input_section
,
6510 /* Set the right machine number. */
6513 elfNN_aarch64_object_p (bfd
*abfd
)
6516 bfd_default_set_arch_mach (abfd
, bfd_arch_aarch64
, bfd_mach_aarch64_ilp32
);
6518 bfd_default_set_arch_mach (abfd
, bfd_arch_aarch64
, bfd_mach_aarch64
);
6523 /* Function to keep AArch64 specific flags in the ELF header. */
6526 elfNN_aarch64_set_private_flags (bfd
*abfd
, flagword flags
)
6528 if (elf_flags_init (abfd
) && elf_elfheader (abfd
)->e_flags
!= flags
)
6533 elf_elfheader (abfd
)->e_flags
= flags
;
6534 elf_flags_init (abfd
) = TRUE
;
6540 /* Merge backend specific data from an object file to the output
6541 object file when linking. */
6544 elfNN_aarch64_merge_private_bfd_data (bfd
*ibfd
, bfd
*obfd
)
6548 bfd_boolean flags_compatible
= TRUE
;
6551 /* Check if we have the same endianess. */
6552 if (!_bfd_generic_verify_endian_match (ibfd
, obfd
))
6555 if (!is_aarch64_elf (ibfd
) || !is_aarch64_elf (obfd
))
6558 /* The input BFD must have had its flags initialised. */
6559 /* The following seems bogus to me -- The flags are initialized in
6560 the assembler but I don't think an elf_flags_init field is
6561 written into the object. */
6562 /* BFD_ASSERT (elf_flags_init (ibfd)); */
6564 in_flags
= elf_elfheader (ibfd
)->e_flags
;
6565 out_flags
= elf_elfheader (obfd
)->e_flags
;
6567 if (!elf_flags_init (obfd
))
6569 /* If the input is the default architecture and had the default
6570 flags then do not bother setting the flags for the output
6571 architecture, instead allow future merges to do this. If no
6572 future merges ever set these flags then they will retain their
6573 uninitialised values, which surprise surprise, correspond
6574 to the default values. */
6575 if (bfd_get_arch_info (ibfd
)->the_default
6576 && elf_elfheader (ibfd
)->e_flags
== 0)
6579 elf_flags_init (obfd
) = TRUE
;
6580 elf_elfheader (obfd
)->e_flags
= in_flags
;
6582 if (bfd_get_arch (obfd
) == bfd_get_arch (ibfd
)
6583 && bfd_get_arch_info (obfd
)->the_default
)
6584 return bfd_set_arch_mach (obfd
, bfd_get_arch (ibfd
),
6585 bfd_get_mach (ibfd
));
6590 /* Identical flags must be compatible. */
6591 if (in_flags
== out_flags
)
6594 /* Check to see if the input BFD actually contains any sections. If
6595 not, its flags may not have been initialised either, but it
6596 cannot actually cause any incompatiblity. Do not short-circuit
6597 dynamic objects; their section list may be emptied by
6598 elf_link_add_object_symbols.
6600 Also check to see if there are no code sections in the input.
6601 In this case there is no need to check for code specific flags.
6602 XXX - do we need to worry about floating-point format compatability
6603 in data sections ? */
6604 if (!(ibfd
->flags
& DYNAMIC
))
6606 bfd_boolean null_input_bfd
= TRUE
;
6607 bfd_boolean only_data_sections
= TRUE
;
6609 for (sec
= ibfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
6611 if ((bfd_get_section_flags (ibfd
, sec
)
6612 & (SEC_LOAD
| SEC_CODE
| SEC_HAS_CONTENTS
))
6613 == (SEC_LOAD
| SEC_CODE
| SEC_HAS_CONTENTS
))
6614 only_data_sections
= FALSE
;
6616 null_input_bfd
= FALSE
;
6620 if (null_input_bfd
|| only_data_sections
)
6624 return flags_compatible
;
6627 /* Display the flags field. */
6630 elfNN_aarch64_print_private_bfd_data (bfd
*abfd
, void *ptr
)
6632 FILE *file
= (FILE *) ptr
;
6633 unsigned long flags
;
6635 BFD_ASSERT (abfd
!= NULL
&& ptr
!= NULL
);
6637 /* Print normal ELF private data. */
6638 _bfd_elf_print_private_bfd_data (abfd
, ptr
);
6640 flags
= elf_elfheader (abfd
)->e_flags
;
6641 /* Ignore init flag - it may not be set, despite the flags field
6642 containing valid data. */
6644 /* xgettext:c-format */
6645 fprintf (file
, _("private flags = %lx:"), elf_elfheader (abfd
)->e_flags
);
6648 fprintf (file
, _("<Unrecognised flag bits set>"));
6655 /* Update the got entry reference counts for the section being removed. */
6658 elfNN_aarch64_gc_sweep_hook (bfd
*abfd
,
6659 struct bfd_link_info
*info
,
6661 const Elf_Internal_Rela
* relocs
)
6663 struct elf_aarch64_link_hash_table
*htab
;
6664 Elf_Internal_Shdr
*symtab_hdr
;
6665 struct elf_link_hash_entry
**sym_hashes
;
6666 struct elf_aarch64_local_symbol
*locals
;
6667 const Elf_Internal_Rela
*rel
, *relend
;
6669 if (bfd_link_relocatable (info
))
6672 htab
= elf_aarch64_hash_table (info
);
6677 elf_section_data (sec
)->local_dynrel
= NULL
;
6679 symtab_hdr
= &elf_symtab_hdr (abfd
);
6680 sym_hashes
= elf_sym_hashes (abfd
);
6682 locals
= elf_aarch64_locals (abfd
);
6684 relend
= relocs
+ sec
->reloc_count
;
6685 for (rel
= relocs
; rel
< relend
; rel
++)
6687 unsigned long r_symndx
;
6688 unsigned int r_type
;
6689 struct elf_link_hash_entry
*h
= NULL
;
6691 r_symndx
= ELFNN_R_SYM (rel
->r_info
);
6693 if (r_symndx
>= symtab_hdr
->sh_info
)
6696 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
6697 while (h
->root
.type
== bfd_link_hash_indirect
6698 || h
->root
.type
== bfd_link_hash_warning
)
6699 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
6703 Elf_Internal_Sym
*isym
;
6705 /* A local symbol. */
6706 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
6709 /* Check relocation against local STT_GNU_IFUNC symbol. */
6711 && ELF_ST_TYPE (isym
->st_info
) == STT_GNU_IFUNC
)
6713 h
= elfNN_aarch64_get_local_sym_hash (htab
, abfd
, rel
, FALSE
);
6721 struct elf_aarch64_link_hash_entry
*eh
;
6722 struct elf_dyn_relocs
**pp
;
6723 struct elf_dyn_relocs
*p
;
6725 eh
= (struct elf_aarch64_link_hash_entry
*) h
;
6727 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; pp
= &p
->next
)
6730 /* Everything must go for SEC. */
6736 r_type
= ELFNN_R_TYPE (rel
->r_info
);
6737 switch (aarch64_tls_transition (abfd
,info
, r_type
, h
,r_symndx
))
6739 case BFD_RELOC_AARCH64_ADR_GOT_PAGE
:
6740 case BFD_RELOC_AARCH64_GOT_LD_PREL19
:
6741 case BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14
:
6742 case BFD_RELOC_AARCH64_LD32_GOT_LO12_NC
:
6743 case BFD_RELOC_AARCH64_LD64_GOTOFF_LO15
:
6744 case BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15
:
6745 case BFD_RELOC_AARCH64_LD64_GOT_LO12_NC
:
6746 case BFD_RELOC_AARCH64_MOVW_GOTOFF_G0_NC
:
6747 case BFD_RELOC_AARCH64_MOVW_GOTOFF_G1
:
6748 case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12_NC
:
6749 case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21
:
6750 case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21
:
6751 case BFD_RELOC_AARCH64_TLSDESC_LD32_LO12_NC
:
6752 case BFD_RELOC_AARCH64_TLSDESC_LD64_LO12_NC
:
6753 case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19
:
6754 case BFD_RELOC_AARCH64_TLSDESC_OFF_G0_NC
:
6755 case BFD_RELOC_AARCH64_TLSDESC_OFF_G1
:
6756 case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC
:
6757 case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21
:
6758 case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21
:
6759 case BFD_RELOC_AARCH64_TLSGD_MOVW_G0_NC
:
6760 case BFD_RELOC_AARCH64_TLSGD_MOVW_G1
:
6761 case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21
:
6762 case BFD_RELOC_AARCH64_TLSIE_LD32_GOTTPREL_LO12_NC
:
6763 case BFD_RELOC_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC
:
6764 case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19
:
6765 case BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G0_NC
:
6766 case BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G1
:
6767 case BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC
:
6768 case BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21
:
6769 case BFD_RELOC_AARCH64_TLSLD_ADR_PREL21
:
6772 if (h
->got
.refcount
> 0)
6773 h
->got
.refcount
-= 1;
6775 if (h
->type
== STT_GNU_IFUNC
)
6777 if (h
->plt
.refcount
> 0)
6778 h
->plt
.refcount
-= 1;
6781 else if (locals
!= NULL
)
6783 if (locals
[r_symndx
].got_refcount
> 0)
6784 locals
[r_symndx
].got_refcount
-= 1;
6788 case BFD_RELOC_AARCH64_CALL26
:
6789 case BFD_RELOC_AARCH64_JUMP26
:
6790 /* If this is a local symbol then we resolve it
6791 directly without creating a PLT entry. */
6795 if (h
->plt
.refcount
> 0)
6796 h
->plt
.refcount
-= 1;
6799 case BFD_RELOC_AARCH64_ADR_HI21_NC_PCREL
:
6800 case BFD_RELOC_AARCH64_ADR_HI21_PCREL
:
6801 case BFD_RELOC_AARCH64_ADR_LO21_PCREL
:
6802 case BFD_RELOC_AARCH64_MOVW_G0_NC
:
6803 case BFD_RELOC_AARCH64_MOVW_G1_NC
:
6804 case BFD_RELOC_AARCH64_MOVW_G2_NC
:
6805 case BFD_RELOC_AARCH64_MOVW_G3
:
6806 case BFD_RELOC_AARCH64_NN
:
6807 if (h
!= NULL
&& bfd_link_executable (info
))
6809 if (h
->plt
.refcount
> 0)
6810 h
->plt
.refcount
-= 1;
6822 /* Adjust a symbol defined by a dynamic object and referenced by a
6823 regular object. The current definition is in some section of the
6824 dynamic object, but we're not including those sections. We have to
6825 change the definition to something the rest of the link can
6829 elfNN_aarch64_adjust_dynamic_symbol (struct bfd_link_info
*info
,
6830 struct elf_link_hash_entry
*h
)
6832 struct elf_aarch64_link_hash_table
*htab
;
6835 /* If this is a function, put it in the procedure linkage table. We
6836 will fill in the contents of the procedure linkage table later,
6837 when we know the address of the .got section. */
6838 if (h
->type
== STT_FUNC
|| h
->type
== STT_GNU_IFUNC
|| h
->needs_plt
)
6840 if (h
->plt
.refcount
<= 0
6841 || (h
->type
!= STT_GNU_IFUNC
6842 && (SYMBOL_CALLS_LOCAL (info
, h
)
6843 || (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
6844 && h
->root
.type
== bfd_link_hash_undefweak
))))
6846 /* This case can occur if we saw a CALL26 reloc in
6847 an input file, but the symbol wasn't referred to
6848 by a dynamic object or all references were
6849 garbage collected. In which case we can end up
6851 h
->plt
.offset
= (bfd_vma
) - 1;
6858 /* Otherwise, reset to -1. */
6859 h
->plt
.offset
= (bfd_vma
) - 1;
6862 /* If this is a weak symbol, and there is a real definition, the
6863 processor independent code will have arranged for us to see the
6864 real definition first, and we can just use the same value. */
6865 if (h
->u
.weakdef
!= NULL
)
6867 BFD_ASSERT (h
->u
.weakdef
->root
.type
== bfd_link_hash_defined
6868 || h
->u
.weakdef
->root
.type
== bfd_link_hash_defweak
);
6869 h
->root
.u
.def
.section
= h
->u
.weakdef
->root
.u
.def
.section
;
6870 h
->root
.u
.def
.value
= h
->u
.weakdef
->root
.u
.def
.value
;
6871 if (ELIMINATE_COPY_RELOCS
|| info
->nocopyreloc
)
6872 h
->non_got_ref
= h
->u
.weakdef
->non_got_ref
;
6876 /* If we are creating a shared library, we must presume that the
6877 only references to the symbol are via the global offset table.
6878 For such cases we need not do anything here; the relocations will
6879 be handled correctly by relocate_section. */
6880 if (bfd_link_pic (info
))
6883 /* If there are no references to this symbol that do not use the
6884 GOT, we don't need to generate a copy reloc. */
6885 if (!h
->non_got_ref
)
6888 /* If -z nocopyreloc was given, we won't generate them either. */
6889 if (info
->nocopyreloc
)
6895 /* We must allocate the symbol in our .dynbss section, which will
6896 become part of the .bss section of the executable. There will be
6897 an entry for this symbol in the .dynsym section. The dynamic
6898 object will contain position independent code, so all references
6899 from the dynamic object to this symbol will go through the global
6900 offset table. The dynamic linker will use the .dynsym entry to
6901 determine the address it must put in the global offset table, so
6902 both the dynamic object and the regular object will refer to the
6903 same memory location for the variable. */
6905 htab
= elf_aarch64_hash_table (info
);
6907 /* We must generate a R_AARCH64_COPY reloc to tell the dynamic linker
6908 to copy the initial value out of the dynamic object and into the
6909 runtime process image. */
6910 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0 && h
->size
!= 0)
6912 htab
->srelbss
->size
+= RELOC_SIZE (htab
);
6918 return _bfd_elf_adjust_dynamic_copy (info
, h
, s
);
6923 elfNN_aarch64_allocate_local_symbols (bfd
*abfd
, unsigned number
)
6925 struct elf_aarch64_local_symbol
*locals
;
6926 locals
= elf_aarch64_locals (abfd
);
6929 locals
= (struct elf_aarch64_local_symbol
*)
6930 bfd_zalloc (abfd
, number
* sizeof (struct elf_aarch64_local_symbol
));
6933 elf_aarch64_locals (abfd
) = locals
;
6938 /* Create the .got section to hold the global offset table. */
6941 aarch64_elf_create_got_section (bfd
*abfd
, struct bfd_link_info
*info
)
6943 const struct elf_backend_data
*bed
= get_elf_backend_data (abfd
);
6946 struct elf_link_hash_entry
*h
;
6947 struct elf_link_hash_table
*htab
= elf_hash_table (info
);
6949 /* This function may be called more than once. */
6950 s
= bfd_get_linker_section (abfd
, ".got");
6954 flags
= bed
->dynamic_sec_flags
;
6956 s
= bfd_make_section_anyway_with_flags (abfd
,
6957 (bed
->rela_plts_and_copies_p
6958 ? ".rela.got" : ".rel.got"),
6959 (bed
->dynamic_sec_flags
6962 || ! bfd_set_section_alignment (abfd
, s
, bed
->s
->log_file_align
))
6966 s
= bfd_make_section_anyway_with_flags (abfd
, ".got", flags
);
6968 || !bfd_set_section_alignment (abfd
, s
, bed
->s
->log_file_align
))
6971 htab
->sgot
->size
+= GOT_ENTRY_SIZE
;
6973 if (bed
->want_got_sym
)
6975 /* Define the symbol _GLOBAL_OFFSET_TABLE_ at the start of the .got
6976 (or .got.plt) section. We don't do this in the linker script
6977 because we don't want to define the symbol if we are not creating
6978 a global offset table. */
6979 h
= _bfd_elf_define_linkage_sym (abfd
, info
, s
,
6980 "_GLOBAL_OFFSET_TABLE_");
6981 elf_hash_table (info
)->hgot
= h
;
6986 if (bed
->want_got_plt
)
6988 s
= bfd_make_section_anyway_with_flags (abfd
, ".got.plt", flags
);
6990 || !bfd_set_section_alignment (abfd
, s
,
6991 bed
->s
->log_file_align
))
6996 /* The first bit of the global offset table is the header. */
6997 s
->size
+= bed
->got_header_size
;
7002 /* Look through the relocs for a section during the first phase. */
7005 elfNN_aarch64_check_relocs (bfd
*abfd
, struct bfd_link_info
*info
,
7006 asection
*sec
, const Elf_Internal_Rela
*relocs
)
7008 Elf_Internal_Shdr
*symtab_hdr
;
7009 struct elf_link_hash_entry
**sym_hashes
;
7010 const Elf_Internal_Rela
*rel
;
7011 const Elf_Internal_Rela
*rel_end
;
7014 struct elf_aarch64_link_hash_table
*htab
;
7016 if (bfd_link_relocatable (info
))
7019 BFD_ASSERT (is_aarch64_elf (abfd
));
7021 htab
= elf_aarch64_hash_table (info
);
7024 symtab_hdr
= &elf_symtab_hdr (abfd
);
7025 sym_hashes
= elf_sym_hashes (abfd
);
7027 rel_end
= relocs
+ sec
->reloc_count
;
7028 for (rel
= relocs
; rel
< rel_end
; rel
++)
7030 struct elf_link_hash_entry
*h
;
7031 unsigned long r_symndx
;
7032 unsigned int r_type
;
7033 bfd_reloc_code_real_type bfd_r_type
;
7034 Elf_Internal_Sym
*isym
;
7036 r_symndx
= ELFNN_R_SYM (rel
->r_info
);
7037 r_type
= ELFNN_R_TYPE (rel
->r_info
);
7039 if (r_symndx
>= NUM_SHDR_ENTRIES (symtab_hdr
))
7041 (*_bfd_error_handler
) (_("%B: bad symbol index: %d"), abfd
,
7046 if (r_symndx
< symtab_hdr
->sh_info
)
7048 /* A local symbol. */
7049 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
7054 /* Check relocation against local STT_GNU_IFUNC symbol. */
7055 if (ELF_ST_TYPE (isym
->st_info
) == STT_GNU_IFUNC
)
7057 h
= elfNN_aarch64_get_local_sym_hash (htab
, abfd
, rel
,
7062 /* Fake a STT_GNU_IFUNC symbol. */
7063 h
->type
= STT_GNU_IFUNC
;
7066 h
->forced_local
= 1;
7067 h
->root
.type
= bfd_link_hash_defined
;
7074 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
7075 while (h
->root
.type
== bfd_link_hash_indirect
7076 || h
->root
.type
== bfd_link_hash_warning
)
7077 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
7079 /* PR15323, ref flags aren't set for references in the same
7081 h
->root
.non_ir_ref
= 1;
7084 /* Could be done earlier, if h were already available. */
7085 bfd_r_type
= aarch64_tls_transition (abfd
, info
, r_type
, h
, r_symndx
);
7089 /* If a relocation refers to _GLOBAL_OFFSET_TABLE_, create the .got.
7090 This shows up in particular in an R_AARCH64_PREL64 in large model
7091 when calculating the pc-relative address to .got section which is
7092 used to initialize the gp register. */
7093 if (h
->root
.root
.string
7094 && strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_") == 0)
7096 if (htab
->root
.dynobj
== NULL
)
7097 htab
->root
.dynobj
= abfd
;
7099 if (! aarch64_elf_create_got_section (htab
->root
.dynobj
, info
))
7102 BFD_ASSERT (h
== htab
->root
.hgot
);
7105 /* Create the ifunc sections for static executables. If we
7106 never see an indirect function symbol nor we are building
7107 a static executable, those sections will be empty and
7108 won't appear in output. */
7114 case BFD_RELOC_AARCH64_ADD_LO12
:
7115 case BFD_RELOC_AARCH64_ADR_GOT_PAGE
:
7116 case BFD_RELOC_AARCH64_ADR_HI21_PCREL
:
7117 case BFD_RELOC_AARCH64_CALL26
:
7118 case BFD_RELOC_AARCH64_GOT_LD_PREL19
:
7119 case BFD_RELOC_AARCH64_JUMP26
:
7120 case BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14
:
7121 case BFD_RELOC_AARCH64_LD32_GOT_LO12_NC
:
7122 case BFD_RELOC_AARCH64_LD64_GOTOFF_LO15
:
7123 case BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15
:
7124 case BFD_RELOC_AARCH64_LD64_GOT_LO12_NC
:
7125 case BFD_RELOC_AARCH64_MOVW_GOTOFF_G0_NC
:
7126 case BFD_RELOC_AARCH64_MOVW_GOTOFF_G1
:
7127 case BFD_RELOC_AARCH64_NN
:
7128 if (htab
->root
.dynobj
== NULL
)
7129 htab
->root
.dynobj
= abfd
;
7130 if (!_bfd_elf_create_ifunc_sections (htab
->root
.dynobj
, info
))
7135 /* It is referenced by a non-shared object. */
7137 h
->root
.non_ir_ref
= 1;
7142 case BFD_RELOC_AARCH64_NN
:
7144 /* We don't need to handle relocs into sections not going into
7145 the "real" output. */
7146 if ((sec
->flags
& SEC_ALLOC
) == 0)
7151 if (!bfd_link_pic (info
))
7154 h
->plt
.refcount
+= 1;
7155 h
->pointer_equality_needed
= 1;
7158 /* No need to do anything if we're not creating a shared
7160 if (! bfd_link_pic (info
))
7164 struct elf_dyn_relocs
*p
;
7165 struct elf_dyn_relocs
**head
;
7167 /* We must copy these reloc types into the output file.
7168 Create a reloc section in dynobj and make room for
7172 if (htab
->root
.dynobj
== NULL
)
7173 htab
->root
.dynobj
= abfd
;
7175 sreloc
= _bfd_elf_make_dynamic_reloc_section
7176 (sec
, htab
->root
.dynobj
, LOG_FILE_ALIGN
, abfd
, /*rela? */ TRUE
);
7182 /* If this is a global symbol, we count the number of
7183 relocations we need for this symbol. */
7186 struct elf_aarch64_link_hash_entry
*eh
;
7187 eh
= (struct elf_aarch64_link_hash_entry
*) h
;
7188 head
= &eh
->dyn_relocs
;
7192 /* Track dynamic relocs needed for local syms too.
7193 We really need local syms available to do this
7199 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
7204 s
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
7208 /* Beware of type punned pointers vs strict aliasing
7210 vpp
= &(elf_section_data (s
)->local_dynrel
);
7211 head
= (struct elf_dyn_relocs
**) vpp
;
7215 if (p
== NULL
|| p
->sec
!= sec
)
7217 bfd_size_type amt
= sizeof *p
;
7218 p
= ((struct elf_dyn_relocs
*)
7219 bfd_zalloc (htab
->root
.dynobj
, amt
));
7232 /* RR: We probably want to keep a consistency check that
7233 there are no dangling GOT_PAGE relocs. */
7234 case BFD_RELOC_AARCH64_ADR_GOT_PAGE
:
7235 case BFD_RELOC_AARCH64_GOT_LD_PREL19
:
7236 case BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14
:
7237 case BFD_RELOC_AARCH64_LD32_GOT_LO12_NC
:
7238 case BFD_RELOC_AARCH64_LD64_GOTOFF_LO15
:
7239 case BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15
:
7240 case BFD_RELOC_AARCH64_LD64_GOT_LO12_NC
:
7241 case BFD_RELOC_AARCH64_MOVW_GOTOFF_G0_NC
:
7242 case BFD_RELOC_AARCH64_MOVW_GOTOFF_G1
:
7243 case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12_NC
:
7244 case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21
:
7245 case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21
:
7246 case BFD_RELOC_AARCH64_TLSDESC_LD32_LO12_NC
:
7247 case BFD_RELOC_AARCH64_TLSDESC_LD64_LO12_NC
:
7248 case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19
:
7249 case BFD_RELOC_AARCH64_TLSDESC_OFF_G0_NC
:
7250 case BFD_RELOC_AARCH64_TLSDESC_OFF_G1
:
7251 case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC
:
7252 case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21
:
7253 case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21
:
7254 case BFD_RELOC_AARCH64_TLSGD_MOVW_G0_NC
:
7255 case BFD_RELOC_AARCH64_TLSGD_MOVW_G1
:
7256 case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21
:
7257 case BFD_RELOC_AARCH64_TLSIE_LD32_GOTTPREL_LO12_NC
:
7258 case BFD_RELOC_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC
:
7259 case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19
:
7260 case BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G0_NC
:
7261 case BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G1
:
7262 case BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC
:
7263 case BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21
:
7264 case BFD_RELOC_AARCH64_TLSLD_ADR_PREL21
:
7265 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1
:
7266 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1_NC
:
7267 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G2
:
7270 unsigned old_got_type
;
7272 got_type
= aarch64_reloc_got_type (bfd_r_type
);
7276 h
->got
.refcount
+= 1;
7277 old_got_type
= elf_aarch64_hash_entry (h
)->got_type
;
7281 struct elf_aarch64_local_symbol
*locals
;
7283 if (!elfNN_aarch64_allocate_local_symbols
7284 (abfd
, symtab_hdr
->sh_info
))
7287 locals
= elf_aarch64_locals (abfd
);
7288 BFD_ASSERT (r_symndx
< symtab_hdr
->sh_info
);
7289 locals
[r_symndx
].got_refcount
+= 1;
7290 old_got_type
= locals
[r_symndx
].got_type
;
7293 /* If a variable is accessed with both general dynamic TLS
7294 methods, two slots may be created. */
7295 if (GOT_TLS_GD_ANY_P (old_got_type
) && GOT_TLS_GD_ANY_P (got_type
))
7296 got_type
|= old_got_type
;
7298 /* We will already have issued an error message if there
7299 is a TLS/non-TLS mismatch, based on the symbol type.
7300 So just combine any TLS types needed. */
7301 if (old_got_type
!= GOT_UNKNOWN
&& old_got_type
!= GOT_NORMAL
7302 && got_type
!= GOT_NORMAL
)
7303 got_type
|= old_got_type
;
7305 /* If the symbol is accessed by both IE and GD methods, we
7306 are able to relax. Turn off the GD flag, without
7307 messing up with any other kind of TLS types that may be
7309 if ((got_type
& GOT_TLS_IE
) && GOT_TLS_GD_ANY_P (got_type
))
7310 got_type
&= ~ (GOT_TLSDESC_GD
| GOT_TLS_GD
);
7312 if (old_got_type
!= got_type
)
7315 elf_aarch64_hash_entry (h
)->got_type
= got_type
;
7318 struct elf_aarch64_local_symbol
*locals
;
7319 locals
= elf_aarch64_locals (abfd
);
7320 BFD_ASSERT (r_symndx
< symtab_hdr
->sh_info
);
7321 locals
[r_symndx
].got_type
= got_type
;
7325 if (htab
->root
.dynobj
== NULL
)
7326 htab
->root
.dynobj
= abfd
;
7327 if (! aarch64_elf_create_got_section (htab
->root
.dynobj
, info
))
7332 case BFD_RELOC_AARCH64_MOVW_G0_NC
:
7333 case BFD_RELOC_AARCH64_MOVW_G1_NC
:
7334 case BFD_RELOC_AARCH64_MOVW_G2_NC
:
7335 case BFD_RELOC_AARCH64_MOVW_G3
:
7336 if (bfd_link_pic (info
))
7338 int howto_index
= bfd_r_type
- BFD_RELOC_AARCH64_RELOC_START
;
7339 (*_bfd_error_handler
)
7340 (_("%B: relocation %s against `%s' can not be used when making "
7341 "a shared object; recompile with -fPIC"),
7342 abfd
, elfNN_aarch64_howto_table
[howto_index
].name
,
7343 (h
) ? h
->root
.root
.string
: "a local symbol");
7344 bfd_set_error (bfd_error_bad_value
);
7348 case BFD_RELOC_AARCH64_ADR_HI21_NC_PCREL
:
7349 case BFD_RELOC_AARCH64_ADR_HI21_PCREL
:
7350 case BFD_RELOC_AARCH64_ADR_LO21_PCREL
:
7351 if (h
!= NULL
&& bfd_link_executable (info
))
7353 /* If this reloc is in a read-only section, we might
7354 need a copy reloc. We can't check reliably at this
7355 stage whether the section is read-only, as input
7356 sections have not yet been mapped to output sections.
7357 Tentatively set the flag for now, and correct in
7358 adjust_dynamic_symbol. */
7360 h
->plt
.refcount
+= 1;
7361 h
->pointer_equality_needed
= 1;
7363 /* FIXME:: RR need to handle these in shared libraries
7364 and essentially bomb out as these being non-PIC
7365 relocations in shared libraries. */
7368 case BFD_RELOC_AARCH64_CALL26
:
7369 case BFD_RELOC_AARCH64_JUMP26
:
7370 /* If this is a local symbol then we resolve it
7371 directly without creating a PLT entry. */
7376 if (h
->plt
.refcount
<= 0)
7377 h
->plt
.refcount
= 1;
7379 h
->plt
.refcount
+= 1;
7390 /* Treat mapping symbols as special target symbols. */
7393 elfNN_aarch64_is_target_special_symbol (bfd
*abfd ATTRIBUTE_UNUSED
,
7396 return bfd_is_aarch64_special_symbol_name (sym
->name
,
7397 BFD_AARCH64_SPECIAL_SYM_TYPE_ANY
);
7400 /* This is a copy of elf_find_function () from elf.c except that
7401 AArch64 mapping symbols are ignored when looking for function names. */
7404 aarch64_elf_find_function (bfd
*abfd ATTRIBUTE_UNUSED
,
7408 const char **filename_ptr
,
7409 const char **functionname_ptr
)
7411 const char *filename
= NULL
;
7412 asymbol
*func
= NULL
;
7413 bfd_vma low_func
= 0;
7416 for (p
= symbols
; *p
!= NULL
; p
++)
7420 q
= (elf_symbol_type
*) * p
;
7422 switch (ELF_ST_TYPE (q
->internal_elf_sym
.st_info
))
7427 filename
= bfd_asymbol_name (&q
->symbol
);
7431 /* Skip mapping symbols. */
7432 if ((q
->symbol
.flags
& BSF_LOCAL
)
7433 && (bfd_is_aarch64_special_symbol_name
7434 (q
->symbol
.name
, BFD_AARCH64_SPECIAL_SYM_TYPE_ANY
)))
7437 if (bfd_get_section (&q
->symbol
) == section
7438 && q
->symbol
.value
>= low_func
&& q
->symbol
.value
<= offset
)
7440 func
= (asymbol
*) q
;
7441 low_func
= q
->symbol
.value
;
7451 *filename_ptr
= filename
;
7452 if (functionname_ptr
)
7453 *functionname_ptr
= bfd_asymbol_name (func
);
7459 /* Find the nearest line to a particular section and offset, for error
7460 reporting. This code is a duplicate of the code in elf.c, except
7461 that it uses aarch64_elf_find_function. */
7464 elfNN_aarch64_find_nearest_line (bfd
*abfd
,
7468 const char **filename_ptr
,
7469 const char **functionname_ptr
,
7470 unsigned int *line_ptr
,
7471 unsigned int *discriminator_ptr
)
7473 bfd_boolean found
= FALSE
;
7475 if (_bfd_dwarf2_find_nearest_line (abfd
, symbols
, NULL
, section
, offset
,
7476 filename_ptr
, functionname_ptr
,
7477 line_ptr
, discriminator_ptr
,
7478 dwarf_debug_sections
, 0,
7479 &elf_tdata (abfd
)->dwarf2_find_line_info
))
7481 if (!*functionname_ptr
)
7482 aarch64_elf_find_function (abfd
, symbols
, section
, offset
,
7483 *filename_ptr
? NULL
: filename_ptr
,
7489 /* Skip _bfd_dwarf1_find_nearest_line since no known AArch64
7490 toolchain uses DWARF1. */
7492 if (!_bfd_stab_section_find_nearest_line (abfd
, symbols
, section
, offset
,
7493 &found
, filename_ptr
,
7494 functionname_ptr
, line_ptr
,
7495 &elf_tdata (abfd
)->line_info
))
7498 if (found
&& (*functionname_ptr
|| *line_ptr
))
7501 if (symbols
== NULL
)
7504 if (!aarch64_elf_find_function (abfd
, symbols
, section
, offset
,
7505 filename_ptr
, functionname_ptr
))
7513 elfNN_aarch64_find_inliner_info (bfd
*abfd
,
7514 const char **filename_ptr
,
7515 const char **functionname_ptr
,
7516 unsigned int *line_ptr
)
7519 found
= _bfd_dwarf2_find_inliner_info
7520 (abfd
, filename_ptr
,
7521 functionname_ptr
, line_ptr
, &elf_tdata (abfd
)->dwarf2_find_line_info
);
7527 elfNN_aarch64_post_process_headers (bfd
*abfd
,
7528 struct bfd_link_info
*link_info
)
7530 Elf_Internal_Ehdr
*i_ehdrp
; /* ELF file header, internal form. */
7532 i_ehdrp
= elf_elfheader (abfd
);
7533 i_ehdrp
->e_ident
[EI_ABIVERSION
] = AARCH64_ELF_ABI_VERSION
;
7535 _bfd_elf_post_process_headers (abfd
, link_info
);
7538 static enum elf_reloc_type_class
7539 elfNN_aarch64_reloc_type_class (const struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
7540 const asection
*rel_sec ATTRIBUTE_UNUSED
,
7541 const Elf_Internal_Rela
*rela
)
7543 switch ((int) ELFNN_R_TYPE (rela
->r_info
))
7545 case AARCH64_R (RELATIVE
):
7546 return reloc_class_relative
;
7547 case AARCH64_R (JUMP_SLOT
):
7548 return reloc_class_plt
;
7549 case AARCH64_R (COPY
):
7550 return reloc_class_copy
;
7552 return reloc_class_normal
;
7556 /* Handle an AArch64 specific section when reading an object file. This is
7557 called when bfd_section_from_shdr finds a section with an unknown
7561 elfNN_aarch64_section_from_shdr (bfd
*abfd
,
7562 Elf_Internal_Shdr
*hdr
,
7563 const char *name
, int shindex
)
7565 /* There ought to be a place to keep ELF backend specific flags, but
7566 at the moment there isn't one. We just keep track of the
7567 sections by their name, instead. Fortunately, the ABI gives
7568 names for all the AArch64 specific sections, so we will probably get
7570 switch (hdr
->sh_type
)
7572 case SHT_AARCH64_ATTRIBUTES
:
7579 if (!_bfd_elf_make_section_from_shdr (abfd
, hdr
, name
, shindex
))
7585 /* A structure used to record a list of sections, independently
7586 of the next and prev fields in the asection structure. */
7587 typedef struct section_list
7590 struct section_list
*next
;
7591 struct section_list
*prev
;
7595 /* Unfortunately we need to keep a list of sections for which
7596 an _aarch64_elf_section_data structure has been allocated. This
7597 is because it is possible for functions like elfNN_aarch64_write_section
7598 to be called on a section which has had an elf_data_structure
7599 allocated for it (and so the used_by_bfd field is valid) but
7600 for which the AArch64 extended version of this structure - the
7601 _aarch64_elf_section_data structure - has not been allocated. */
7602 static section_list
*sections_with_aarch64_elf_section_data
= NULL
;
7605 record_section_with_aarch64_elf_section_data (asection
*sec
)
7607 struct section_list
*entry
;
7609 entry
= bfd_malloc (sizeof (*entry
));
7613 entry
->next
= sections_with_aarch64_elf_section_data
;
7615 if (entry
->next
!= NULL
)
7616 entry
->next
->prev
= entry
;
7617 sections_with_aarch64_elf_section_data
= entry
;
7620 static struct section_list
*
7621 find_aarch64_elf_section_entry (asection
*sec
)
7623 struct section_list
*entry
;
7624 static struct section_list
*last_entry
= NULL
;
7626 /* This is a short cut for the typical case where the sections are added
7627 to the sections_with_aarch64_elf_section_data list in forward order and
7628 then looked up here in backwards order. This makes a real difference
7629 to the ld-srec/sec64k.exp linker test. */
7630 entry
= sections_with_aarch64_elf_section_data
;
7631 if (last_entry
!= NULL
)
7633 if (last_entry
->sec
== sec
)
7635 else if (last_entry
->next
!= NULL
&& last_entry
->next
->sec
== sec
)
7636 entry
= last_entry
->next
;
7639 for (; entry
; entry
= entry
->next
)
7640 if (entry
->sec
== sec
)
7644 /* Record the entry prior to this one - it is the entry we are
7645 most likely to want to locate next time. Also this way if we
7646 have been called from
7647 unrecord_section_with_aarch64_elf_section_data () we will not
7648 be caching a pointer that is about to be freed. */
7649 last_entry
= entry
->prev
;
7655 unrecord_section_with_aarch64_elf_section_data (asection
*sec
)
7657 struct section_list
*entry
;
7659 entry
= find_aarch64_elf_section_entry (sec
);
7663 if (entry
->prev
!= NULL
)
7664 entry
->prev
->next
= entry
->next
;
7665 if (entry
->next
!= NULL
)
7666 entry
->next
->prev
= entry
->prev
;
7667 if (entry
== sections_with_aarch64_elf_section_data
)
7668 sections_with_aarch64_elf_section_data
= entry
->next
;
7677 struct bfd_link_info
*info
;
7680 int (*func
) (void *, const char *, Elf_Internal_Sym
*,
7681 asection
*, struct elf_link_hash_entry
*);
7682 } output_arch_syminfo
;
7684 enum map_symbol_type
7691 /* Output a single mapping symbol. */
7694 elfNN_aarch64_output_map_sym (output_arch_syminfo
*osi
,
7695 enum map_symbol_type type
, bfd_vma offset
)
7697 static const char *names
[2] = { "$x", "$d" };
7698 Elf_Internal_Sym sym
;
7700 sym
.st_value
= (osi
->sec
->output_section
->vma
7701 + osi
->sec
->output_offset
+ offset
);
7704 sym
.st_info
= ELF_ST_INFO (STB_LOCAL
, STT_NOTYPE
);
7705 sym
.st_shndx
= osi
->sec_shndx
;
7706 return osi
->func (osi
->finfo
, names
[type
], &sym
, osi
->sec
, NULL
) == 1;
7709 /* Output a single local symbol for a generated stub. */
7712 elfNN_aarch64_output_stub_sym (output_arch_syminfo
*osi
, const char *name
,
7713 bfd_vma offset
, bfd_vma size
)
7715 Elf_Internal_Sym sym
;
7717 sym
.st_value
= (osi
->sec
->output_section
->vma
7718 + osi
->sec
->output_offset
+ offset
);
7721 sym
.st_info
= ELF_ST_INFO (STB_LOCAL
, STT_FUNC
);
7722 sym
.st_shndx
= osi
->sec_shndx
;
7723 return osi
->func (osi
->finfo
, name
, &sym
, osi
->sec
, NULL
) == 1;
7727 aarch64_map_one_stub (struct bfd_hash_entry
*gen_entry
, void *in_arg
)
7729 struct elf_aarch64_stub_hash_entry
*stub_entry
;
7733 output_arch_syminfo
*osi
;
7735 /* Massage our args to the form they really have. */
7736 stub_entry
= (struct elf_aarch64_stub_hash_entry
*) gen_entry
;
7737 osi
= (output_arch_syminfo
*) in_arg
;
7739 stub_sec
= stub_entry
->stub_sec
;
7741 /* Ensure this stub is attached to the current section being
7743 if (stub_sec
!= osi
->sec
)
7746 addr
= (bfd_vma
) stub_entry
->stub_offset
;
7748 stub_name
= stub_entry
->output_name
;
7750 switch (stub_entry
->stub_type
)
7752 case aarch64_stub_adrp_branch
:
7753 if (!elfNN_aarch64_output_stub_sym (osi
, stub_name
, addr
,
7754 sizeof (aarch64_adrp_branch_stub
)))
7756 if (!elfNN_aarch64_output_map_sym (osi
, AARCH64_MAP_INSN
, addr
))
7759 case aarch64_stub_long_branch
:
7760 if (!elfNN_aarch64_output_stub_sym
7761 (osi
, stub_name
, addr
, sizeof (aarch64_long_branch_stub
)))
7763 if (!elfNN_aarch64_output_map_sym (osi
, AARCH64_MAP_INSN
, addr
))
7765 if (!elfNN_aarch64_output_map_sym (osi
, AARCH64_MAP_DATA
, addr
+ 16))
7768 case aarch64_stub_erratum_835769_veneer
:
7769 if (!elfNN_aarch64_output_stub_sym (osi
, stub_name
, addr
,
7770 sizeof (aarch64_erratum_835769_stub
)))
7772 if (!elfNN_aarch64_output_map_sym (osi
, AARCH64_MAP_INSN
, addr
))
7775 case aarch64_stub_erratum_843419_veneer
:
7776 if (!elfNN_aarch64_output_stub_sym (osi
, stub_name
, addr
,
7777 sizeof (aarch64_erratum_843419_stub
)))
7779 if (!elfNN_aarch64_output_map_sym (osi
, AARCH64_MAP_INSN
, addr
))
7790 /* Output mapping symbols for linker generated sections. */
7793 elfNN_aarch64_output_arch_local_syms (bfd
*output_bfd
,
7794 struct bfd_link_info
*info
,
7796 int (*func
) (void *, const char *,
7799 struct elf_link_hash_entry
7802 output_arch_syminfo osi
;
7803 struct elf_aarch64_link_hash_table
*htab
;
7805 htab
= elf_aarch64_hash_table (info
);
7811 /* Long calls stubs. */
7812 if (htab
->stub_bfd
&& htab
->stub_bfd
->sections
)
7816 for (stub_sec
= htab
->stub_bfd
->sections
;
7817 stub_sec
!= NULL
; stub_sec
= stub_sec
->next
)
7819 /* Ignore non-stub sections. */
7820 if (!strstr (stub_sec
->name
, STUB_SUFFIX
))
7825 osi
.sec_shndx
= _bfd_elf_section_from_bfd_section
7826 (output_bfd
, osi
.sec
->output_section
);
7828 /* The first instruction in a stub is always a branch. */
7829 if (!elfNN_aarch64_output_map_sym (&osi
, AARCH64_MAP_INSN
, 0))
7832 bfd_hash_traverse (&htab
->stub_hash_table
, aarch64_map_one_stub
,
7837 /* Finally, output mapping symbols for the PLT. */
7838 if (!htab
->root
.splt
|| htab
->root
.splt
->size
== 0)
7841 osi
.sec_shndx
= _bfd_elf_section_from_bfd_section
7842 (output_bfd
, htab
->root
.splt
->output_section
);
7843 osi
.sec
= htab
->root
.splt
;
7845 elfNN_aarch64_output_map_sym (&osi
, AARCH64_MAP_INSN
, 0);
7851 /* Allocate target specific section data. */
7854 elfNN_aarch64_new_section_hook (bfd
*abfd
, asection
*sec
)
7856 if (!sec
->used_by_bfd
)
7858 _aarch64_elf_section_data
*sdata
;
7859 bfd_size_type amt
= sizeof (*sdata
);
7861 sdata
= bfd_zalloc (abfd
, amt
);
7864 sec
->used_by_bfd
= sdata
;
7867 record_section_with_aarch64_elf_section_data (sec
);
7869 return _bfd_elf_new_section_hook (abfd
, sec
);
7874 unrecord_section_via_map_over_sections (bfd
*abfd ATTRIBUTE_UNUSED
,
7876 void *ignore ATTRIBUTE_UNUSED
)
7878 unrecord_section_with_aarch64_elf_section_data (sec
);
7882 elfNN_aarch64_close_and_cleanup (bfd
*abfd
)
7885 bfd_map_over_sections (abfd
,
7886 unrecord_section_via_map_over_sections
, NULL
);
7888 return _bfd_elf_close_and_cleanup (abfd
);
7892 elfNN_aarch64_bfd_free_cached_info (bfd
*abfd
)
7895 bfd_map_over_sections (abfd
,
7896 unrecord_section_via_map_over_sections
, NULL
);
7898 return _bfd_free_cached_info (abfd
);
7901 /* Create dynamic sections. This is different from the ARM backend in that
7902 the got, plt, gotplt and their relocation sections are all created in the
7903 standard part of the bfd elf backend. */
7906 elfNN_aarch64_create_dynamic_sections (bfd
*dynobj
,
7907 struct bfd_link_info
*info
)
7909 struct elf_aarch64_link_hash_table
*htab
;
7911 /* We need to create .got section. */
7912 if (!aarch64_elf_create_got_section (dynobj
, info
))
7915 if (!_bfd_elf_create_dynamic_sections (dynobj
, info
))
7918 htab
= elf_aarch64_hash_table (info
);
7919 htab
->sdynbss
= bfd_get_linker_section (dynobj
, ".dynbss");
7920 if (!bfd_link_pic (info
))
7921 htab
->srelbss
= bfd_get_linker_section (dynobj
, ".rela.bss");
7923 if (!htab
->sdynbss
|| (!bfd_link_pic (info
) && !htab
->srelbss
))
7930 /* Allocate space in .plt, .got and associated reloc sections for
7934 elfNN_aarch64_allocate_dynrelocs (struct elf_link_hash_entry
*h
, void *inf
)
7936 struct bfd_link_info
*info
;
7937 struct elf_aarch64_link_hash_table
*htab
;
7938 struct elf_aarch64_link_hash_entry
*eh
;
7939 struct elf_dyn_relocs
*p
;
7941 /* An example of a bfd_link_hash_indirect symbol is versioned
7942 symbol. For example: __gxx_personality_v0(bfd_link_hash_indirect)
7943 -> __gxx_personality_v0(bfd_link_hash_defined)
7945 There is no need to process bfd_link_hash_indirect symbols here
7946 because we will also be presented with the concrete instance of
7947 the symbol and elfNN_aarch64_copy_indirect_symbol () will have been
7948 called to copy all relevant data from the generic to the concrete
7951 if (h
->root
.type
== bfd_link_hash_indirect
)
7954 if (h
->root
.type
== bfd_link_hash_warning
)
7955 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
7957 info
= (struct bfd_link_info
*) inf
;
7958 htab
= elf_aarch64_hash_table (info
);
7960 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle it
7961 here if it is defined and referenced in a non-shared object. */
7962 if (h
->type
== STT_GNU_IFUNC
7965 else if (htab
->root
.dynamic_sections_created
&& h
->plt
.refcount
> 0)
7967 /* Make sure this symbol is output as a dynamic symbol.
7968 Undefined weak syms won't yet be marked as dynamic. */
7969 if (h
->dynindx
== -1 && !h
->forced_local
)
7971 if (!bfd_elf_link_record_dynamic_symbol (info
, h
))
7975 if (bfd_link_pic (info
) || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h
))
7977 asection
*s
= htab
->root
.splt
;
7979 /* If this is the first .plt entry, make room for the special
7982 s
->size
+= htab
->plt_header_size
;
7984 h
->plt
.offset
= s
->size
;
7986 /* If this symbol is not defined in a regular file, and we are
7987 not generating a shared library, then set the symbol to this
7988 location in the .plt. This is required to make function
7989 pointers compare as equal between the normal executable and
7990 the shared library. */
7991 if (!bfd_link_pic (info
) && !h
->def_regular
)
7993 h
->root
.u
.def
.section
= s
;
7994 h
->root
.u
.def
.value
= h
->plt
.offset
;
7997 /* Make room for this entry. For now we only create the
7998 small model PLT entries. We later need to find a way
7999 of relaxing into these from the large model PLT entries. */
8000 s
->size
+= PLT_SMALL_ENTRY_SIZE
;
8002 /* We also need to make an entry in the .got.plt section, which
8003 will be placed in the .got section by the linker script. */
8004 htab
->root
.sgotplt
->size
+= GOT_ENTRY_SIZE
;
8006 /* We also need to make an entry in the .rela.plt section. */
8007 htab
->root
.srelplt
->size
+= RELOC_SIZE (htab
);
8009 /* We need to ensure that all GOT entries that serve the PLT
8010 are consecutive with the special GOT slots [0] [1] and
8011 [2]. Any addtional relocations, such as
8012 R_AARCH64_TLSDESC, must be placed after the PLT related
8013 entries. We abuse the reloc_count such that during
8014 sizing we adjust reloc_count to indicate the number of
8015 PLT related reserved entries. In subsequent phases when
8016 filling in the contents of the reloc entries, PLT related
8017 entries are placed by computing their PLT index (0
8018 .. reloc_count). While other none PLT relocs are placed
8019 at the slot indicated by reloc_count and reloc_count is
8022 htab
->root
.srelplt
->reloc_count
++;
8026 h
->plt
.offset
= (bfd_vma
) - 1;
8032 h
->plt
.offset
= (bfd_vma
) - 1;
8036 eh
= (struct elf_aarch64_link_hash_entry
*) h
;
8037 eh
->tlsdesc_got_jump_table_offset
= (bfd_vma
) - 1;
8039 if (h
->got
.refcount
> 0)
8042 unsigned got_type
= elf_aarch64_hash_entry (h
)->got_type
;
8044 h
->got
.offset
= (bfd_vma
) - 1;
8046 dyn
= htab
->root
.dynamic_sections_created
;
8048 /* Make sure this symbol is output as a dynamic symbol.
8049 Undefined weak syms won't yet be marked as dynamic. */
8050 if (dyn
&& h
->dynindx
== -1 && !h
->forced_local
)
8052 if (!bfd_elf_link_record_dynamic_symbol (info
, h
))
8056 if (got_type
== GOT_UNKNOWN
)
8059 else if (got_type
== GOT_NORMAL
)
8061 h
->got
.offset
= htab
->root
.sgot
->size
;
8062 htab
->root
.sgot
->size
+= GOT_ENTRY_SIZE
;
8063 if ((ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
8064 || h
->root
.type
!= bfd_link_hash_undefweak
)
8065 && (bfd_link_pic (info
)
8066 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, 0, h
)))
8068 htab
->root
.srelgot
->size
+= RELOC_SIZE (htab
);
8074 if (got_type
& GOT_TLSDESC_GD
)
8076 eh
->tlsdesc_got_jump_table_offset
=
8077 (htab
->root
.sgotplt
->size
8078 - aarch64_compute_jump_table_size (htab
));
8079 htab
->root
.sgotplt
->size
+= GOT_ENTRY_SIZE
* 2;
8080 h
->got
.offset
= (bfd_vma
) - 2;
8083 if (got_type
& GOT_TLS_GD
)
8085 h
->got
.offset
= htab
->root
.sgot
->size
;
8086 htab
->root
.sgot
->size
+= GOT_ENTRY_SIZE
* 2;
8089 if (got_type
& GOT_TLS_IE
)
8091 h
->got
.offset
= htab
->root
.sgot
->size
;
8092 htab
->root
.sgot
->size
+= GOT_ENTRY_SIZE
;
8095 indx
= h
&& h
->dynindx
!= -1 ? h
->dynindx
: 0;
8096 if ((ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
8097 || h
->root
.type
!= bfd_link_hash_undefweak
)
8098 && (bfd_link_pic (info
)
8100 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, 0, h
)))
8102 if (got_type
& GOT_TLSDESC_GD
)
8104 htab
->root
.srelplt
->size
+= RELOC_SIZE (htab
);
8105 /* Note reloc_count not incremented here! We have
8106 already adjusted reloc_count for this relocation
8109 /* TLSDESC PLT is now needed, but not yet determined. */
8110 htab
->tlsdesc_plt
= (bfd_vma
) - 1;
8113 if (got_type
& GOT_TLS_GD
)
8114 htab
->root
.srelgot
->size
+= RELOC_SIZE (htab
) * 2;
8116 if (got_type
& GOT_TLS_IE
)
8117 htab
->root
.srelgot
->size
+= RELOC_SIZE (htab
);
8123 h
->got
.offset
= (bfd_vma
) - 1;
8126 if (eh
->dyn_relocs
== NULL
)
8129 /* In the shared -Bsymbolic case, discard space allocated for
8130 dynamic pc-relative relocs against symbols which turn out to be
8131 defined in regular objects. For the normal shared case, discard
8132 space for pc-relative relocs that have become local due to symbol
8133 visibility changes. */
8135 if (bfd_link_pic (info
))
8137 /* Relocs that use pc_count are those that appear on a call
8138 insn, or certain REL relocs that can generated via assembly.
8139 We want calls to protected symbols to resolve directly to the
8140 function rather than going via the plt. If people want
8141 function pointer comparisons to work as expected then they
8142 should avoid writing weird assembly. */
8143 if (SYMBOL_CALLS_LOCAL (info
, h
))
8145 struct elf_dyn_relocs
**pp
;
8147 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
;)
8149 p
->count
-= p
->pc_count
;
8158 /* Also discard relocs on undefined weak syms with non-default
8160 if (eh
->dyn_relocs
!= NULL
&& h
->root
.type
== bfd_link_hash_undefweak
)
8162 if (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
)
8163 eh
->dyn_relocs
= NULL
;
8165 /* Make sure undefined weak symbols are output as a dynamic
8167 else if (h
->dynindx
== -1
8169 && !bfd_elf_link_record_dynamic_symbol (info
, h
))
8174 else if (ELIMINATE_COPY_RELOCS
)
8176 /* For the non-shared case, discard space for relocs against
8177 symbols which turn out to need copy relocs or are not
8183 || (htab
->root
.dynamic_sections_created
8184 && (h
->root
.type
== bfd_link_hash_undefweak
8185 || h
->root
.type
== bfd_link_hash_undefined
))))
8187 /* Make sure this symbol is output as a dynamic symbol.
8188 Undefined weak syms won't yet be marked as dynamic. */
8189 if (h
->dynindx
== -1
8191 && !bfd_elf_link_record_dynamic_symbol (info
, h
))
8194 /* If that succeeded, we know we'll be keeping all the
8196 if (h
->dynindx
!= -1)
8200 eh
->dyn_relocs
= NULL
;
8205 /* Finally, allocate space. */
8206 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
8210 sreloc
= elf_section_data (p
->sec
)->sreloc
;
8212 BFD_ASSERT (sreloc
!= NULL
);
8214 sreloc
->size
+= p
->count
* RELOC_SIZE (htab
);
8220 /* Allocate space in .plt, .got and associated reloc sections for
8221 ifunc dynamic relocs. */
8224 elfNN_aarch64_allocate_ifunc_dynrelocs (struct elf_link_hash_entry
*h
,
8227 struct bfd_link_info
*info
;
8228 struct elf_aarch64_link_hash_table
*htab
;
8229 struct elf_aarch64_link_hash_entry
*eh
;
8231 /* An example of a bfd_link_hash_indirect symbol is versioned
8232 symbol. For example: __gxx_personality_v0(bfd_link_hash_indirect)
8233 -> __gxx_personality_v0(bfd_link_hash_defined)
8235 There is no need to process bfd_link_hash_indirect symbols here
8236 because we will also be presented with the concrete instance of
8237 the symbol and elfNN_aarch64_copy_indirect_symbol () will have been
8238 called to copy all relevant data from the generic to the concrete
8241 if (h
->root
.type
== bfd_link_hash_indirect
)
8244 if (h
->root
.type
== bfd_link_hash_warning
)
8245 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
8247 info
= (struct bfd_link_info
*) inf
;
8248 htab
= elf_aarch64_hash_table (info
);
8250 eh
= (struct elf_aarch64_link_hash_entry
*) h
;
8252 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle it
8253 here if it is defined and referenced in a non-shared object. */
8254 if (h
->type
== STT_GNU_IFUNC
8256 return _bfd_elf_allocate_ifunc_dyn_relocs (info
, h
,
8259 htab
->plt_entry_size
,
8260 htab
->plt_header_size
,
8265 /* Allocate space in .plt, .got and associated reloc sections for
8266 local dynamic relocs. */
8269 elfNN_aarch64_allocate_local_dynrelocs (void **slot
, void *inf
)
8271 struct elf_link_hash_entry
*h
8272 = (struct elf_link_hash_entry
*) *slot
;
8274 if (h
->type
!= STT_GNU_IFUNC
8278 || h
->root
.type
!= bfd_link_hash_defined
)
8281 return elfNN_aarch64_allocate_dynrelocs (h
, inf
);
8284 /* Allocate space in .plt, .got and associated reloc sections for
8285 local ifunc dynamic relocs. */
8288 elfNN_aarch64_allocate_local_ifunc_dynrelocs (void **slot
, void *inf
)
8290 struct elf_link_hash_entry
*h
8291 = (struct elf_link_hash_entry
*) *slot
;
8293 if (h
->type
!= STT_GNU_IFUNC
8297 || h
->root
.type
!= bfd_link_hash_defined
)
8300 return elfNN_aarch64_allocate_ifunc_dynrelocs (h
, inf
);
8303 /* Find any dynamic relocs that apply to read-only sections. */
8306 aarch64_readonly_dynrelocs (struct elf_link_hash_entry
* h
, void * inf
)
8308 struct elf_aarch64_link_hash_entry
* eh
;
8309 struct elf_dyn_relocs
* p
;
8311 eh
= (struct elf_aarch64_link_hash_entry
*) h
;
8312 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
8314 asection
*s
= p
->sec
;
8316 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
8318 struct bfd_link_info
*info
= (struct bfd_link_info
*) inf
;
8320 info
->flags
|= DF_TEXTREL
;
8322 /* Not an error, just cut short the traversal. */
8329 /* This is the most important function of all . Innocuosly named
8332 elfNN_aarch64_size_dynamic_sections (bfd
*output_bfd ATTRIBUTE_UNUSED
,
8333 struct bfd_link_info
*info
)
8335 struct elf_aarch64_link_hash_table
*htab
;
8341 htab
= elf_aarch64_hash_table ((info
));
8342 dynobj
= htab
->root
.dynobj
;
8344 BFD_ASSERT (dynobj
!= NULL
);
8346 if (htab
->root
.dynamic_sections_created
)
8348 if (bfd_link_executable (info
) && !info
->nointerp
)
8350 s
= bfd_get_linker_section (dynobj
, ".interp");
8353 s
->size
= sizeof ELF_DYNAMIC_INTERPRETER
;
8354 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
8358 /* Set up .got offsets for local syms, and space for local dynamic
8360 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
8362 struct elf_aarch64_local_symbol
*locals
= NULL
;
8363 Elf_Internal_Shdr
*symtab_hdr
;
8367 if (!is_aarch64_elf (ibfd
))
8370 for (s
= ibfd
->sections
; s
!= NULL
; s
= s
->next
)
8372 struct elf_dyn_relocs
*p
;
8374 for (p
= (struct elf_dyn_relocs
*)
8375 (elf_section_data (s
)->local_dynrel
); p
!= NULL
; p
= p
->next
)
8377 if (!bfd_is_abs_section (p
->sec
)
8378 && bfd_is_abs_section (p
->sec
->output_section
))
8380 /* Input section has been discarded, either because
8381 it is a copy of a linkonce section or due to
8382 linker script /DISCARD/, so we'll be discarding
8385 else if (p
->count
!= 0)
8387 srel
= elf_section_data (p
->sec
)->sreloc
;
8388 srel
->size
+= p
->count
* RELOC_SIZE (htab
);
8389 if ((p
->sec
->output_section
->flags
& SEC_READONLY
) != 0)
8390 info
->flags
|= DF_TEXTREL
;
8395 locals
= elf_aarch64_locals (ibfd
);
8399 symtab_hdr
= &elf_symtab_hdr (ibfd
);
8400 srel
= htab
->root
.srelgot
;
8401 for (i
= 0; i
< symtab_hdr
->sh_info
; i
++)
8403 locals
[i
].got_offset
= (bfd_vma
) - 1;
8404 locals
[i
].tlsdesc_got_jump_table_offset
= (bfd_vma
) - 1;
8405 if (locals
[i
].got_refcount
> 0)
8407 unsigned got_type
= locals
[i
].got_type
;
8408 if (got_type
& GOT_TLSDESC_GD
)
8410 locals
[i
].tlsdesc_got_jump_table_offset
=
8411 (htab
->root
.sgotplt
->size
8412 - aarch64_compute_jump_table_size (htab
));
8413 htab
->root
.sgotplt
->size
+= GOT_ENTRY_SIZE
* 2;
8414 locals
[i
].got_offset
= (bfd_vma
) - 2;
8417 if (got_type
& GOT_TLS_GD
)
8419 locals
[i
].got_offset
= htab
->root
.sgot
->size
;
8420 htab
->root
.sgot
->size
+= GOT_ENTRY_SIZE
* 2;
8423 if (got_type
& GOT_TLS_IE
8424 || got_type
& GOT_NORMAL
)
8426 locals
[i
].got_offset
= htab
->root
.sgot
->size
;
8427 htab
->root
.sgot
->size
+= GOT_ENTRY_SIZE
;
8430 if (got_type
== GOT_UNKNOWN
)
8434 if (bfd_link_pic (info
))
8436 if (got_type
& GOT_TLSDESC_GD
)
8438 htab
->root
.srelplt
->size
+= RELOC_SIZE (htab
);
8439 /* Note RELOC_COUNT not incremented here! */
8440 htab
->tlsdesc_plt
= (bfd_vma
) - 1;
8443 if (got_type
& GOT_TLS_GD
)
8444 htab
->root
.srelgot
->size
+= RELOC_SIZE (htab
) * 2;
8446 if (got_type
& GOT_TLS_IE
8447 || got_type
& GOT_NORMAL
)
8448 htab
->root
.srelgot
->size
+= RELOC_SIZE (htab
);
8453 locals
[i
].got_refcount
= (bfd_vma
) - 1;
8459 /* Allocate global sym .plt and .got entries, and space for global
8460 sym dynamic relocs. */
8461 elf_link_hash_traverse (&htab
->root
, elfNN_aarch64_allocate_dynrelocs
,
8464 /* Allocate global ifunc sym .plt and .got entries, and space for global
8465 ifunc sym dynamic relocs. */
8466 elf_link_hash_traverse (&htab
->root
, elfNN_aarch64_allocate_ifunc_dynrelocs
,
8469 /* Allocate .plt and .got entries, and space for local symbols. */
8470 htab_traverse (htab
->loc_hash_table
,
8471 elfNN_aarch64_allocate_local_dynrelocs
,
8474 /* Allocate .plt and .got entries, and space for local ifunc symbols. */
8475 htab_traverse (htab
->loc_hash_table
,
8476 elfNN_aarch64_allocate_local_ifunc_dynrelocs
,
8479 /* For every jump slot reserved in the sgotplt, reloc_count is
8480 incremented. However, when we reserve space for TLS descriptors,
8481 it's not incremented, so in order to compute the space reserved
8482 for them, it suffices to multiply the reloc count by the jump
8485 if (htab
->root
.srelplt
)
8486 htab
->sgotplt_jump_table_size
= aarch64_compute_jump_table_size (htab
);
8488 if (htab
->tlsdesc_plt
)
8490 if (htab
->root
.splt
->size
== 0)
8491 htab
->root
.splt
->size
+= PLT_ENTRY_SIZE
;
8493 htab
->tlsdesc_plt
= htab
->root
.splt
->size
;
8494 htab
->root
.splt
->size
+= PLT_TLSDESC_ENTRY_SIZE
;
8496 /* If we're not using lazy TLS relocations, don't generate the
8497 GOT entry required. */
8498 if (!(info
->flags
& DF_BIND_NOW
))
8500 htab
->dt_tlsdesc_got
= htab
->root
.sgot
->size
;
8501 htab
->root
.sgot
->size
+= GOT_ENTRY_SIZE
;
8505 /* Init mapping symbols information to use later to distingush between
8506 code and data while scanning for errata. */
8507 if (htab
->fix_erratum_835769
|| htab
->fix_erratum_843419
)
8508 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
8510 if (!is_aarch64_elf (ibfd
))
8512 bfd_elfNN_aarch64_init_maps (ibfd
);
8515 /* We now have determined the sizes of the various dynamic sections.
8516 Allocate memory for them. */
8518 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
8520 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
8523 if (s
== htab
->root
.splt
8524 || s
== htab
->root
.sgot
8525 || s
== htab
->root
.sgotplt
8526 || s
== htab
->root
.iplt
8527 || s
== htab
->root
.igotplt
|| s
== htab
->sdynbss
)
8529 /* Strip this section if we don't need it; see the
8532 else if (CONST_STRNEQ (bfd_get_section_name (dynobj
, s
), ".rela"))
8534 if (s
->size
!= 0 && s
!= htab
->root
.srelplt
)
8537 /* We use the reloc_count field as a counter if we need
8538 to copy relocs into the output file. */
8539 if (s
!= htab
->root
.srelplt
)
8544 /* It's not one of our sections, so don't allocate space. */
8550 /* If we don't need this section, strip it from the
8551 output file. This is mostly to handle .rela.bss and
8552 .rela.plt. We must create both sections in
8553 create_dynamic_sections, because they must be created
8554 before the linker maps input sections to output
8555 sections. The linker does that before
8556 adjust_dynamic_symbol is called, and it is that
8557 function which decides whether anything needs to go
8558 into these sections. */
8560 s
->flags
|= SEC_EXCLUDE
;
8564 if ((s
->flags
& SEC_HAS_CONTENTS
) == 0)
8567 /* Allocate memory for the section contents. We use bfd_zalloc
8568 here in case unused entries are not reclaimed before the
8569 section's contents are written out. This should not happen,
8570 but this way if it does, we get a R_AARCH64_NONE reloc instead
8572 s
->contents
= (bfd_byte
*) bfd_zalloc (dynobj
, s
->size
);
8573 if (s
->contents
== NULL
)
8577 if (htab
->root
.dynamic_sections_created
)
8579 /* Add some entries to the .dynamic section. We fill in the
8580 values later, in elfNN_aarch64_finish_dynamic_sections, but we
8581 must add the entries now so that we get the correct size for
8582 the .dynamic section. The DT_DEBUG entry is filled in by the
8583 dynamic linker and used by the debugger. */
8584 #define add_dynamic_entry(TAG, VAL) \
8585 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
8587 if (bfd_link_executable (info
))
8589 if (!add_dynamic_entry (DT_DEBUG
, 0))
8593 if (htab
->root
.splt
->size
!= 0)
8595 if (!add_dynamic_entry (DT_PLTGOT
, 0)
8596 || !add_dynamic_entry (DT_PLTRELSZ
, 0)
8597 || !add_dynamic_entry (DT_PLTREL
, DT_RELA
)
8598 || !add_dynamic_entry (DT_JMPREL
, 0))
8601 if (htab
->tlsdesc_plt
8602 && (!add_dynamic_entry (DT_TLSDESC_PLT
, 0)
8603 || !add_dynamic_entry (DT_TLSDESC_GOT
, 0)))
8609 if (!add_dynamic_entry (DT_RELA
, 0)
8610 || !add_dynamic_entry (DT_RELASZ
, 0)
8611 || !add_dynamic_entry (DT_RELAENT
, RELOC_SIZE (htab
)))
8614 /* If any dynamic relocs apply to a read-only section,
8615 then we need a DT_TEXTREL entry. */
8616 if ((info
->flags
& DF_TEXTREL
) == 0)
8617 elf_link_hash_traverse (& htab
->root
, aarch64_readonly_dynrelocs
,
8620 if ((info
->flags
& DF_TEXTREL
) != 0)
8622 if (!add_dynamic_entry (DT_TEXTREL
, 0))
8627 #undef add_dynamic_entry
8633 elf_aarch64_update_plt_entry (bfd
*output_bfd
,
8634 bfd_reloc_code_real_type r_type
,
8635 bfd_byte
*plt_entry
, bfd_vma value
)
8637 reloc_howto_type
*howto
= elfNN_aarch64_howto_from_bfd_reloc (r_type
);
8639 _bfd_aarch64_elf_put_addend (output_bfd
, plt_entry
, r_type
, howto
, value
);
8643 elfNN_aarch64_create_small_pltn_entry (struct elf_link_hash_entry
*h
,
8644 struct elf_aarch64_link_hash_table
8645 *htab
, bfd
*output_bfd
,
8646 struct bfd_link_info
*info
)
8648 bfd_byte
*plt_entry
;
8651 bfd_vma gotplt_entry_address
;
8652 bfd_vma plt_entry_address
;
8653 Elf_Internal_Rela rela
;
8655 asection
*plt
, *gotplt
, *relplt
;
8657 /* When building a static executable, use .iplt, .igot.plt and
8658 .rela.iplt sections for STT_GNU_IFUNC symbols. */
8659 if (htab
->root
.splt
!= NULL
)
8661 plt
= htab
->root
.splt
;
8662 gotplt
= htab
->root
.sgotplt
;
8663 relplt
= htab
->root
.srelplt
;
8667 plt
= htab
->root
.iplt
;
8668 gotplt
= htab
->root
.igotplt
;
8669 relplt
= htab
->root
.irelplt
;
8672 /* Get the index in the procedure linkage table which
8673 corresponds to this symbol. This is the index of this symbol
8674 in all the symbols for which we are making plt entries. The
8675 first entry in the procedure linkage table is reserved.
8677 Get the offset into the .got table of the entry that
8678 corresponds to this function. Each .got entry is GOT_ENTRY_SIZE
8679 bytes. The first three are reserved for the dynamic linker.
8681 For static executables, we don't reserve anything. */
8683 if (plt
== htab
->root
.splt
)
8685 plt_index
= (h
->plt
.offset
- htab
->plt_header_size
) / htab
->plt_entry_size
;
8686 got_offset
= (plt_index
+ 3) * GOT_ENTRY_SIZE
;
8690 plt_index
= h
->plt
.offset
/ htab
->plt_entry_size
;
8691 got_offset
= plt_index
* GOT_ENTRY_SIZE
;
8694 plt_entry
= plt
->contents
+ h
->plt
.offset
;
8695 plt_entry_address
= plt
->output_section
->vma
8696 + plt
->output_offset
+ h
->plt
.offset
;
8697 gotplt_entry_address
= gotplt
->output_section
->vma
+
8698 gotplt
->output_offset
+ got_offset
;
8700 /* Copy in the boiler-plate for the PLTn entry. */
8701 memcpy (plt_entry
, elfNN_aarch64_small_plt_entry
, PLT_SMALL_ENTRY_SIZE
);
8703 /* Fill in the top 21 bits for this: ADRP x16, PLT_GOT + n * 8.
8704 ADRP: ((PG(S+A)-PG(P)) >> 12) & 0x1fffff */
8705 elf_aarch64_update_plt_entry (output_bfd
, BFD_RELOC_AARCH64_ADR_HI21_PCREL
,
8707 PG (gotplt_entry_address
) -
8708 PG (plt_entry_address
));
8710 /* Fill in the lo12 bits for the load from the pltgot. */
8711 elf_aarch64_update_plt_entry (output_bfd
, BFD_RELOC_AARCH64_LDSTNN_LO12
,
8713 PG_OFFSET (gotplt_entry_address
));
8715 /* Fill in the lo12 bits for the add from the pltgot entry. */
8716 elf_aarch64_update_plt_entry (output_bfd
, BFD_RELOC_AARCH64_ADD_LO12
,
8718 PG_OFFSET (gotplt_entry_address
));
8720 /* All the GOTPLT Entries are essentially initialized to PLT0. */
8721 bfd_put_NN (output_bfd
,
8722 plt
->output_section
->vma
+ plt
->output_offset
,
8723 gotplt
->contents
+ got_offset
);
8725 rela
.r_offset
= gotplt_entry_address
;
8727 if (h
->dynindx
== -1
8728 || ((bfd_link_executable (info
)
8729 || ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
)
8731 && h
->type
== STT_GNU_IFUNC
))
8733 /* If an STT_GNU_IFUNC symbol is locally defined, generate
8734 R_AARCH64_IRELATIVE instead of R_AARCH64_JUMP_SLOT. */
8735 rela
.r_info
= ELFNN_R_INFO (0, AARCH64_R (IRELATIVE
));
8736 rela
.r_addend
= (h
->root
.u
.def
.value
8737 + h
->root
.u
.def
.section
->output_section
->vma
8738 + h
->root
.u
.def
.section
->output_offset
);
8742 /* Fill in the entry in the .rela.plt section. */
8743 rela
.r_info
= ELFNN_R_INFO (h
->dynindx
, AARCH64_R (JUMP_SLOT
));
8747 /* Compute the relocation entry to used based on PLT index and do
8748 not adjust reloc_count. The reloc_count has already been adjusted
8749 to account for this entry. */
8750 loc
= relplt
->contents
+ plt_index
* RELOC_SIZE (htab
);
8751 bfd_elfNN_swap_reloca_out (output_bfd
, &rela
, loc
);
8754 /* Size sections even though they're not dynamic. We use it to setup
8755 _TLS_MODULE_BASE_, if needed. */
8758 elfNN_aarch64_always_size_sections (bfd
*output_bfd
,
8759 struct bfd_link_info
*info
)
8763 if (bfd_link_relocatable (info
))
8766 tls_sec
= elf_hash_table (info
)->tls_sec
;
8770 struct elf_link_hash_entry
*tlsbase
;
8772 tlsbase
= elf_link_hash_lookup (elf_hash_table (info
),
8773 "_TLS_MODULE_BASE_", TRUE
, TRUE
, FALSE
);
8777 struct bfd_link_hash_entry
*h
= NULL
;
8778 const struct elf_backend_data
*bed
=
8779 get_elf_backend_data (output_bfd
);
8781 if (!(_bfd_generic_link_add_one_symbol
8782 (info
, output_bfd
, "_TLS_MODULE_BASE_", BSF_LOCAL
,
8783 tls_sec
, 0, NULL
, FALSE
, bed
->collect
, &h
)))
8786 tlsbase
->type
= STT_TLS
;
8787 tlsbase
= (struct elf_link_hash_entry
*) h
;
8788 tlsbase
->def_regular
= 1;
8789 tlsbase
->other
= STV_HIDDEN
;
8790 (*bed
->elf_backend_hide_symbol
) (info
, tlsbase
, TRUE
);
8797 /* Finish up dynamic symbol handling. We set the contents of various
8798 dynamic sections here. */
8800 elfNN_aarch64_finish_dynamic_symbol (bfd
*output_bfd
,
8801 struct bfd_link_info
*info
,
8802 struct elf_link_hash_entry
*h
,
8803 Elf_Internal_Sym
*sym
)
8805 struct elf_aarch64_link_hash_table
*htab
;
8806 htab
= elf_aarch64_hash_table (info
);
8808 if (h
->plt
.offset
!= (bfd_vma
) - 1)
8810 asection
*plt
, *gotplt
, *relplt
;
8812 /* This symbol has an entry in the procedure linkage table. Set
8815 /* When building a static executable, use .iplt, .igot.plt and
8816 .rela.iplt sections for STT_GNU_IFUNC symbols. */
8817 if (htab
->root
.splt
!= NULL
)
8819 plt
= htab
->root
.splt
;
8820 gotplt
= htab
->root
.sgotplt
;
8821 relplt
= htab
->root
.srelplt
;
8825 plt
= htab
->root
.iplt
;
8826 gotplt
= htab
->root
.igotplt
;
8827 relplt
= htab
->root
.irelplt
;
8830 /* This symbol has an entry in the procedure linkage table. Set
8832 if ((h
->dynindx
== -1
8833 && !((h
->forced_local
|| bfd_link_executable (info
))
8835 && h
->type
== STT_GNU_IFUNC
))
8841 elfNN_aarch64_create_small_pltn_entry (h
, htab
, output_bfd
, info
);
8842 if (!h
->def_regular
)
8844 /* Mark the symbol as undefined, rather than as defined in
8845 the .plt section. */
8846 sym
->st_shndx
= SHN_UNDEF
;
8847 /* If the symbol is weak we need to clear the value.
8848 Otherwise, the PLT entry would provide a definition for
8849 the symbol even if the symbol wasn't defined anywhere,
8850 and so the symbol would never be NULL. Leave the value if
8851 there were any relocations where pointer equality matters
8852 (this is a clue for the dynamic linker, to make function
8853 pointer comparisons work between an application and shared
8855 if (!h
->ref_regular_nonweak
|| !h
->pointer_equality_needed
)
8860 if (h
->got
.offset
!= (bfd_vma
) - 1
8861 && elf_aarch64_hash_entry (h
)->got_type
== GOT_NORMAL
)
8863 Elf_Internal_Rela rela
;
8866 /* This symbol has an entry in the global offset table. Set it
8868 if (htab
->root
.sgot
== NULL
|| htab
->root
.srelgot
== NULL
)
8871 rela
.r_offset
= (htab
->root
.sgot
->output_section
->vma
8872 + htab
->root
.sgot
->output_offset
8873 + (h
->got
.offset
& ~(bfd_vma
) 1));
8876 && h
->type
== STT_GNU_IFUNC
)
8878 if (bfd_link_pic (info
))
8880 /* Generate R_AARCH64_GLOB_DAT. */
8887 if (!h
->pointer_equality_needed
)
8890 /* For non-shared object, we can't use .got.plt, which
8891 contains the real function address if we need pointer
8892 equality. We load the GOT entry with the PLT entry. */
8893 plt
= htab
->root
.splt
? htab
->root
.splt
: htab
->root
.iplt
;
8894 bfd_put_NN (output_bfd
, (plt
->output_section
->vma
8895 + plt
->output_offset
8897 htab
->root
.sgot
->contents
8898 + (h
->got
.offset
& ~(bfd_vma
) 1));
8902 else if (bfd_link_pic (info
) && SYMBOL_REFERENCES_LOCAL (info
, h
))
8904 if (!h
->def_regular
)
8907 BFD_ASSERT ((h
->got
.offset
& 1) != 0);
8908 rela
.r_info
= ELFNN_R_INFO (0, AARCH64_R (RELATIVE
));
8909 rela
.r_addend
= (h
->root
.u
.def
.value
8910 + h
->root
.u
.def
.section
->output_section
->vma
8911 + h
->root
.u
.def
.section
->output_offset
);
8916 BFD_ASSERT ((h
->got
.offset
& 1) == 0);
8917 bfd_put_NN (output_bfd
, (bfd_vma
) 0,
8918 htab
->root
.sgot
->contents
+ h
->got
.offset
);
8919 rela
.r_info
= ELFNN_R_INFO (h
->dynindx
, AARCH64_R (GLOB_DAT
));
8923 loc
= htab
->root
.srelgot
->contents
;
8924 loc
+= htab
->root
.srelgot
->reloc_count
++ * RELOC_SIZE (htab
);
8925 bfd_elfNN_swap_reloca_out (output_bfd
, &rela
, loc
);
8930 Elf_Internal_Rela rela
;
8933 /* This symbol needs a copy reloc. Set it up. */
8935 if (h
->dynindx
== -1
8936 || (h
->root
.type
!= bfd_link_hash_defined
8937 && h
->root
.type
!= bfd_link_hash_defweak
)
8938 || htab
->srelbss
== NULL
)
8941 rela
.r_offset
= (h
->root
.u
.def
.value
8942 + h
->root
.u
.def
.section
->output_section
->vma
8943 + h
->root
.u
.def
.section
->output_offset
);
8944 rela
.r_info
= ELFNN_R_INFO (h
->dynindx
, AARCH64_R (COPY
));
8946 loc
= htab
->srelbss
->contents
;
8947 loc
+= htab
->srelbss
->reloc_count
++ * RELOC_SIZE (htab
);
8948 bfd_elfNN_swap_reloca_out (output_bfd
, &rela
, loc
);
8951 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. SYM may
8952 be NULL for local symbols. */
8954 && (h
== elf_hash_table (info
)->hdynamic
8955 || h
== elf_hash_table (info
)->hgot
))
8956 sym
->st_shndx
= SHN_ABS
;
8961 /* Finish up local dynamic symbol handling. We set the contents of
8962 various dynamic sections here. */
8965 elfNN_aarch64_finish_local_dynamic_symbol (void **slot
, void *inf
)
8967 struct elf_link_hash_entry
*h
8968 = (struct elf_link_hash_entry
*) *slot
;
8969 struct bfd_link_info
*info
8970 = (struct bfd_link_info
*) inf
;
8972 return elfNN_aarch64_finish_dynamic_symbol (info
->output_bfd
,
8977 elfNN_aarch64_init_small_plt0_entry (bfd
*output_bfd ATTRIBUTE_UNUSED
,
8978 struct elf_aarch64_link_hash_table
8981 /* Fill in PLT0. Fixme:RR Note this doesn't distinguish between
8982 small and large plts and at the minute just generates
8985 /* PLT0 of the small PLT looks like this in ELF64 -
8986 stp x16, x30, [sp, #-16]! // Save the reloc and lr on stack.
8987 adrp x16, PLT_GOT + 16 // Get the page base of the GOTPLT
8988 ldr x17, [x16, #:lo12:PLT_GOT+16] // Load the address of the
8990 add x16, x16, #:lo12:PLT_GOT+16 // Load the lo12 bits of the
8991 // GOTPLT entry for this.
8993 PLT0 will be slightly different in ELF32 due to different got entry
8996 bfd_vma plt_got_2nd_ent
; /* Address of GOT[2]. */
9000 memcpy (htab
->root
.splt
->contents
, elfNN_aarch64_small_plt0_entry
,
9002 elf_section_data (htab
->root
.splt
->output_section
)->this_hdr
.sh_entsize
=
9005 plt_got_2nd_ent
= (htab
->root
.sgotplt
->output_section
->vma
9006 + htab
->root
.sgotplt
->output_offset
9007 + GOT_ENTRY_SIZE
* 2);
9009 plt_base
= htab
->root
.splt
->output_section
->vma
+
9010 htab
->root
.splt
->output_offset
;
9012 /* Fill in the top 21 bits for this: ADRP x16, PLT_GOT + n * 8.
9013 ADRP: ((PG(S+A)-PG(P)) >> 12) & 0x1fffff */
9014 elf_aarch64_update_plt_entry (output_bfd
, BFD_RELOC_AARCH64_ADR_HI21_PCREL
,
9015 htab
->root
.splt
->contents
+ 4,
9016 PG (plt_got_2nd_ent
) - PG (plt_base
+ 4));
9018 elf_aarch64_update_plt_entry (output_bfd
, BFD_RELOC_AARCH64_LDSTNN_LO12
,
9019 htab
->root
.splt
->contents
+ 8,
9020 PG_OFFSET (plt_got_2nd_ent
));
9022 elf_aarch64_update_plt_entry (output_bfd
, BFD_RELOC_AARCH64_ADD_LO12
,
9023 htab
->root
.splt
->contents
+ 12,
9024 PG_OFFSET (plt_got_2nd_ent
));
9028 elfNN_aarch64_finish_dynamic_sections (bfd
*output_bfd
,
9029 struct bfd_link_info
*info
)
9031 struct elf_aarch64_link_hash_table
*htab
;
9035 htab
= elf_aarch64_hash_table (info
);
9036 dynobj
= htab
->root
.dynobj
;
9037 sdyn
= bfd_get_linker_section (dynobj
, ".dynamic");
9039 if (htab
->root
.dynamic_sections_created
)
9041 ElfNN_External_Dyn
*dyncon
, *dynconend
;
9043 if (sdyn
== NULL
|| htab
->root
.sgot
== NULL
)
9046 dyncon
= (ElfNN_External_Dyn
*) sdyn
->contents
;
9047 dynconend
= (ElfNN_External_Dyn
*) (sdyn
->contents
+ sdyn
->size
);
9048 for (; dyncon
< dynconend
; dyncon
++)
9050 Elf_Internal_Dyn dyn
;
9053 bfd_elfNN_swap_dyn_in (dynobj
, dyncon
, &dyn
);
9061 s
= htab
->root
.sgotplt
;
9062 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
9066 dyn
.d_un
.d_ptr
= htab
->root
.srelplt
->output_section
->vma
;
9070 s
= htab
->root
.srelplt
;
9071 dyn
.d_un
.d_val
= s
->size
;
9075 /* The procedure linkage table relocs (DT_JMPREL) should
9076 not be included in the overall relocs (DT_RELA).
9077 Therefore, we override the DT_RELASZ entry here to
9078 make it not include the JMPREL relocs. Since the
9079 linker script arranges for .rela.plt to follow all
9080 other relocation sections, we don't have to worry
9081 about changing the DT_RELA entry. */
9082 if (htab
->root
.srelplt
!= NULL
)
9084 s
= htab
->root
.srelplt
;
9085 dyn
.d_un
.d_val
-= s
->size
;
9089 case DT_TLSDESC_PLT
:
9090 s
= htab
->root
.splt
;
9091 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
9092 + htab
->tlsdesc_plt
;
9095 case DT_TLSDESC_GOT
:
9096 s
= htab
->root
.sgot
;
9097 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
9098 + htab
->dt_tlsdesc_got
;
9102 bfd_elfNN_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
9107 /* Fill in the special first entry in the procedure linkage table. */
9108 if (htab
->root
.splt
&& htab
->root
.splt
->size
> 0)
9110 elfNN_aarch64_init_small_plt0_entry (output_bfd
, htab
);
9112 elf_section_data (htab
->root
.splt
->output_section
)->
9113 this_hdr
.sh_entsize
= htab
->plt_entry_size
;
9116 if (htab
->tlsdesc_plt
)
9118 bfd_put_NN (output_bfd
, (bfd_vma
) 0,
9119 htab
->root
.sgot
->contents
+ htab
->dt_tlsdesc_got
);
9121 memcpy (htab
->root
.splt
->contents
+ htab
->tlsdesc_plt
,
9122 elfNN_aarch64_tlsdesc_small_plt_entry
,
9123 sizeof (elfNN_aarch64_tlsdesc_small_plt_entry
));
9126 bfd_vma adrp1_addr
=
9127 htab
->root
.splt
->output_section
->vma
9128 + htab
->root
.splt
->output_offset
+ htab
->tlsdesc_plt
+ 4;
9130 bfd_vma adrp2_addr
= adrp1_addr
+ 4;
9133 htab
->root
.sgot
->output_section
->vma
9134 + htab
->root
.sgot
->output_offset
;
9136 bfd_vma pltgot_addr
=
9137 htab
->root
.sgotplt
->output_section
->vma
9138 + htab
->root
.sgotplt
->output_offset
;
9140 bfd_vma dt_tlsdesc_got
= got_addr
+ htab
->dt_tlsdesc_got
;
9142 bfd_byte
*plt_entry
=
9143 htab
->root
.splt
->contents
+ htab
->tlsdesc_plt
;
9145 /* adrp x2, DT_TLSDESC_GOT */
9146 elf_aarch64_update_plt_entry (output_bfd
,
9147 BFD_RELOC_AARCH64_ADR_HI21_PCREL
,
9149 (PG (dt_tlsdesc_got
)
9150 - PG (adrp1_addr
)));
9153 elf_aarch64_update_plt_entry (output_bfd
,
9154 BFD_RELOC_AARCH64_ADR_HI21_PCREL
,
9157 - PG (adrp2_addr
)));
9159 /* ldr x2, [x2, #0] */
9160 elf_aarch64_update_plt_entry (output_bfd
,
9161 BFD_RELOC_AARCH64_LDSTNN_LO12
,
9163 PG_OFFSET (dt_tlsdesc_got
));
9166 elf_aarch64_update_plt_entry (output_bfd
,
9167 BFD_RELOC_AARCH64_ADD_LO12
,
9169 PG_OFFSET (pltgot_addr
));
9174 if (htab
->root
.sgotplt
)
9176 if (bfd_is_abs_section (htab
->root
.sgotplt
->output_section
))
9178 (*_bfd_error_handler
)
9179 (_("discarded output section: `%A'"), htab
->root
.sgotplt
);
9183 /* Fill in the first three entries in the global offset table. */
9184 if (htab
->root
.sgotplt
->size
> 0)
9186 bfd_put_NN (output_bfd
, (bfd_vma
) 0, htab
->root
.sgotplt
->contents
);
9188 /* Write GOT[1] and GOT[2], needed for the dynamic linker. */
9189 bfd_put_NN (output_bfd
,
9191 htab
->root
.sgotplt
->contents
+ GOT_ENTRY_SIZE
);
9192 bfd_put_NN (output_bfd
,
9194 htab
->root
.sgotplt
->contents
+ GOT_ENTRY_SIZE
* 2);
9197 if (htab
->root
.sgot
)
9199 if (htab
->root
.sgot
->size
> 0)
9202 sdyn
? sdyn
->output_section
->vma
+ sdyn
->output_offset
: 0;
9203 bfd_put_NN (output_bfd
, addr
, htab
->root
.sgot
->contents
);
9207 elf_section_data (htab
->root
.sgotplt
->output_section
)->
9208 this_hdr
.sh_entsize
= GOT_ENTRY_SIZE
;
9211 if (htab
->root
.sgot
&& htab
->root
.sgot
->size
> 0)
9212 elf_section_data (htab
->root
.sgot
->output_section
)->this_hdr
.sh_entsize
9215 /* Fill PLT and GOT entries for local STT_GNU_IFUNC symbols. */
9216 htab_traverse (htab
->loc_hash_table
,
9217 elfNN_aarch64_finish_local_dynamic_symbol
,
9223 /* Return address for Ith PLT stub in section PLT, for relocation REL
9224 or (bfd_vma) -1 if it should not be included. */
9227 elfNN_aarch64_plt_sym_val (bfd_vma i
, const asection
*plt
,
9228 const arelent
*rel ATTRIBUTE_UNUSED
)
9230 return plt
->vma
+ PLT_ENTRY_SIZE
+ i
* PLT_SMALL_ENTRY_SIZE
;
9234 /* We use this so we can override certain functions
9235 (though currently we don't). */
9237 const struct elf_size_info elfNN_aarch64_size_info
=
9239 sizeof (ElfNN_External_Ehdr
),
9240 sizeof (ElfNN_External_Phdr
),
9241 sizeof (ElfNN_External_Shdr
),
9242 sizeof (ElfNN_External_Rel
),
9243 sizeof (ElfNN_External_Rela
),
9244 sizeof (ElfNN_External_Sym
),
9245 sizeof (ElfNN_External_Dyn
),
9246 sizeof (Elf_External_Note
),
9247 4, /* Hash table entry size. */
9248 1, /* Internal relocs per external relocs. */
9249 ARCH_SIZE
, /* Arch size. */
9250 LOG_FILE_ALIGN
, /* Log_file_align. */
9251 ELFCLASSNN
, EV_CURRENT
,
9252 bfd_elfNN_write_out_phdrs
,
9253 bfd_elfNN_write_shdrs_and_ehdr
,
9254 bfd_elfNN_checksum_contents
,
9255 bfd_elfNN_write_relocs
,
9256 bfd_elfNN_swap_symbol_in
,
9257 bfd_elfNN_swap_symbol_out
,
9258 bfd_elfNN_slurp_reloc_table
,
9259 bfd_elfNN_slurp_symbol_table
,
9260 bfd_elfNN_swap_dyn_in
,
9261 bfd_elfNN_swap_dyn_out
,
9262 bfd_elfNN_swap_reloc_in
,
9263 bfd_elfNN_swap_reloc_out
,
9264 bfd_elfNN_swap_reloca_in
,
9265 bfd_elfNN_swap_reloca_out
9268 #define ELF_ARCH bfd_arch_aarch64
9269 #define ELF_MACHINE_CODE EM_AARCH64
9270 #define ELF_MAXPAGESIZE 0x10000
9271 #define ELF_MINPAGESIZE 0x1000
9272 #define ELF_COMMONPAGESIZE 0x1000
9274 #define bfd_elfNN_close_and_cleanup \
9275 elfNN_aarch64_close_and_cleanup
9277 #define bfd_elfNN_bfd_free_cached_info \
9278 elfNN_aarch64_bfd_free_cached_info
9280 #define bfd_elfNN_bfd_is_target_special_symbol \
9281 elfNN_aarch64_is_target_special_symbol
9283 #define bfd_elfNN_bfd_link_hash_table_create \
9284 elfNN_aarch64_link_hash_table_create
9286 #define bfd_elfNN_bfd_merge_private_bfd_data \
9287 elfNN_aarch64_merge_private_bfd_data
9289 #define bfd_elfNN_bfd_print_private_bfd_data \
9290 elfNN_aarch64_print_private_bfd_data
9292 #define bfd_elfNN_bfd_reloc_type_lookup \
9293 elfNN_aarch64_reloc_type_lookup
9295 #define bfd_elfNN_bfd_reloc_name_lookup \
9296 elfNN_aarch64_reloc_name_lookup
9298 #define bfd_elfNN_bfd_set_private_flags \
9299 elfNN_aarch64_set_private_flags
9301 #define bfd_elfNN_find_inliner_info \
9302 elfNN_aarch64_find_inliner_info
9304 #define bfd_elfNN_find_nearest_line \
9305 elfNN_aarch64_find_nearest_line
9307 #define bfd_elfNN_mkobject \
9308 elfNN_aarch64_mkobject
9310 #define bfd_elfNN_new_section_hook \
9311 elfNN_aarch64_new_section_hook
9313 #define elf_backend_adjust_dynamic_symbol \
9314 elfNN_aarch64_adjust_dynamic_symbol
9316 #define elf_backend_always_size_sections \
9317 elfNN_aarch64_always_size_sections
9319 #define elf_backend_check_relocs \
9320 elfNN_aarch64_check_relocs
9322 #define elf_backend_copy_indirect_symbol \
9323 elfNN_aarch64_copy_indirect_symbol
9325 /* Create .dynbss, and .rela.bss sections in DYNOBJ, and set up shortcuts
9326 to them in our hash. */
9327 #define elf_backend_create_dynamic_sections \
9328 elfNN_aarch64_create_dynamic_sections
9330 #define elf_backend_init_index_section \
9331 _bfd_elf_init_2_index_sections
9333 #define elf_backend_finish_dynamic_sections \
9334 elfNN_aarch64_finish_dynamic_sections
9336 #define elf_backend_finish_dynamic_symbol \
9337 elfNN_aarch64_finish_dynamic_symbol
9339 #define elf_backend_gc_sweep_hook \
9340 elfNN_aarch64_gc_sweep_hook
9342 #define elf_backend_object_p \
9343 elfNN_aarch64_object_p
9345 #define elf_backend_output_arch_local_syms \
9346 elfNN_aarch64_output_arch_local_syms
9348 #define elf_backend_plt_sym_val \
9349 elfNN_aarch64_plt_sym_val
9351 #define elf_backend_post_process_headers \
9352 elfNN_aarch64_post_process_headers
9354 #define elf_backend_relocate_section \
9355 elfNN_aarch64_relocate_section
9357 #define elf_backend_reloc_type_class \
9358 elfNN_aarch64_reloc_type_class
9360 #define elf_backend_section_from_shdr \
9361 elfNN_aarch64_section_from_shdr
9363 #define elf_backend_size_dynamic_sections \
9364 elfNN_aarch64_size_dynamic_sections
9366 #define elf_backend_size_info \
9367 elfNN_aarch64_size_info
9369 #define elf_backend_write_section \
9370 elfNN_aarch64_write_section
9372 #define elf_backend_can_refcount 1
9373 #define elf_backend_can_gc_sections 1
9374 #define elf_backend_plt_readonly 1
9375 #define elf_backend_want_got_plt 1
9376 #define elf_backend_want_plt_sym 0
9377 #define elf_backend_may_use_rel_p 0
9378 #define elf_backend_may_use_rela_p 1
9379 #define elf_backend_default_use_rela_p 1
9380 #define elf_backend_rela_normal 1
9381 #define elf_backend_got_header_size (GOT_ENTRY_SIZE * 3)
9382 #define elf_backend_default_execstack 0
9383 #define elf_backend_extern_protected_data 1
9385 #undef elf_backend_obj_attrs_section
9386 #define elf_backend_obj_attrs_section ".ARM.attributes"
9388 #include "elfNN-target.h"
9390 /* CloudABI support. */
9392 #undef TARGET_LITTLE_SYM
9393 #define TARGET_LITTLE_SYM aarch64_elfNN_le_cloudabi_vec
9394 #undef TARGET_LITTLE_NAME
9395 #define TARGET_LITTLE_NAME "elfNN-littleaarch64-cloudabi"
9396 #undef TARGET_BIG_SYM
9397 #define TARGET_BIG_SYM aarch64_elfNN_be_cloudabi_vec
9398 #undef TARGET_BIG_NAME
9399 #define TARGET_BIG_NAME "elfNN-bigaarch64-cloudabi"
9402 #define ELF_OSABI ELFOSABI_CLOUDABI
9405 #define elfNN_bed elfNN_aarch64_cloudabi_bed
9407 #include "elfNN-target.h"