1 /* AArch64-specific support for NN-bit ELF.
2 Copyright (C) 2009-2017 Free Software Foundation, Inc.
3 Contributed by ARM Ltd.
5 This file is part of BFD, the Binary File Descriptor library.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; see the file COPYING3. If not,
19 see <http://www.gnu.org/licenses/>. */
21 /* Notes on implementation:
23 Thread Local Store (TLS)
27 The implementation currently supports both traditional TLS and TLS
28 descriptors, but only general dynamic (GD).
30 For traditional TLS the assembler will present us with code
31 fragments of the form:
34 R_AARCH64_TLSGD_ADR_PAGE21(foo)
35 add x0, :tlsgd_lo12:foo
36 R_AARCH64_TLSGD_ADD_LO12_NC(foo)
40 For TLS descriptors the assembler will present us with code
41 fragments of the form:
43 adrp x0, :tlsdesc:foo R_AARCH64_TLSDESC_ADR_PAGE21(foo)
44 ldr x1, [x0, #:tlsdesc_lo12:foo] R_AARCH64_TLSDESC_LD64_LO12(foo)
45 add x0, x0, #:tlsdesc_lo12:foo R_AARCH64_TLSDESC_ADD_LO12(foo)
47 blr x1 R_AARCH64_TLSDESC_CALL(foo)
49 The relocations R_AARCH64_TLSGD_{ADR_PREL21,ADD_LO12_NC} against foo
50 indicate that foo is thread local and should be accessed via the
51 traditional TLS mechanims.
53 The relocations R_AARCH64_TLSDESC_{ADR_PAGE21,LD64_LO12_NC,ADD_LO12_NC}
54 against foo indicate that 'foo' is thread local and should be accessed
55 via a TLS descriptor mechanism.
57 The precise instruction sequence is only relevant from the
58 perspective of linker relaxation which is currently not implemented.
60 The static linker must detect that 'foo' is a TLS object and
61 allocate a double GOT entry. The GOT entry must be created for both
62 global and local TLS symbols. Note that this is different to none
63 TLS local objects which do not need a GOT entry.
65 In the traditional TLS mechanism, the double GOT entry is used to
66 provide the tls_index structure, containing module and offset
67 entries. The static linker places the relocation R_AARCH64_TLS_DTPMOD
68 on the module entry. The loader will subsequently fixup this
69 relocation with the module identity.
71 For global traditional TLS symbols the static linker places an
72 R_AARCH64_TLS_DTPREL relocation on the offset entry. The loader
73 will subsequently fixup the offset. For local TLS symbols the static
74 linker fixes up offset.
76 In the TLS descriptor mechanism the double GOT entry is used to
77 provide the descriptor. The static linker places the relocation
78 R_AARCH64_TLSDESC on the first GOT slot. The loader will
79 subsequently fix this up.
83 The handling of TLS symbols is implemented across a number of
84 different backend functions. The following is a top level view of
85 what processing is performed where.
87 The TLS implementation maintains state information for each TLS
88 symbol. The state information for local and global symbols is kept
89 in different places. Global symbols use generic BFD structures while
90 local symbols use backend specific structures that are allocated and
91 maintained entirely by the backend.
95 elfNN_aarch64_check_relocs()
97 This function is invoked for each relocation.
99 The TLS relocations R_AARCH64_TLSGD_{ADR_PREL21,ADD_LO12_NC} and
100 R_AARCH64_TLSDESC_{ADR_PAGE21,LD64_LO12_NC,ADD_LO12_NC} are
101 spotted. One time creation of local symbol data structures are
102 created when the first local symbol is seen.
104 The reference count for a symbol is incremented. The GOT type for
105 each symbol is marked as general dynamic.
107 elfNN_aarch64_allocate_dynrelocs ()
109 For each global with positive reference count we allocate a double
110 GOT slot. For a traditional TLS symbol we allocate space for two
111 relocation entries on the GOT, for a TLS descriptor symbol we
112 allocate space for one relocation on the slot. Record the GOT offset
115 elfNN_aarch64_size_dynamic_sections ()
117 Iterate all input BFDS, look for in the local symbol data structure
118 constructed earlier for local TLS symbols and allocate them double
119 GOT slots along with space for a single GOT relocation. Update the
120 local symbol structure to record the GOT offset allocated.
122 elfNN_aarch64_relocate_section ()
124 Calls elfNN_aarch64_final_link_relocate ()
126 Emit the relevant TLS relocations against the GOT for each TLS
127 symbol. For local TLS symbols emit the GOT offset directly. The GOT
128 relocations are emitted once the first time a TLS symbol is
129 encountered. The implementation uses the LSB of the GOT offset to
130 flag that the relevant GOT relocations for a symbol have been
131 emitted. All of the TLS code that uses the GOT offset needs to take
132 care to mask out this flag bit before using the offset.
134 elfNN_aarch64_final_link_relocate ()
136 Fixup the R_AARCH64_TLSGD_{ADR_PREL21, ADD_LO12_NC} relocations. */
140 #include "libiberty.h"
142 #include "bfd_stdint.h"
145 #include "objalloc.h"
146 #include "elf/aarch64.h"
147 #include "elfxx-aarch64.h"
152 #define AARCH64_R(NAME) R_AARCH64_ ## NAME
153 #define AARCH64_R_STR(NAME) "R_AARCH64_" #NAME
154 #define HOWTO64(...) HOWTO (__VA_ARGS__)
155 #define HOWTO32(...) EMPTY_HOWTO (0)
156 #define LOG_FILE_ALIGN 3
157 #define BFD_RELOC_AARCH64_TLSDESC_LD64_LO12_NC BFD_RELOC_AARCH64_TLSDESC_LD64_LO12
161 #define AARCH64_R(NAME) R_AARCH64_P32_ ## NAME
162 #define AARCH64_R_STR(NAME) "R_AARCH64_P32_" #NAME
163 #define HOWTO64(...) EMPTY_HOWTO (0)
164 #define HOWTO32(...) HOWTO (__VA_ARGS__)
165 #define LOG_FILE_ALIGN 2
166 #define BFD_RELOC_AARCH64_TLSDESC_LD32_LO12 BFD_RELOC_AARCH64_TLSDESC_LD32_LO12_NC
167 #define R_AARCH64_P32_TLSDESC_ADD_LO12 R_AARCH64_P32_TLSDESC_ADD_LO12_NC
170 #define IS_AARCH64_TLS_RELOC(R_TYPE) \
171 ((R_TYPE) == BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC \
172 || (R_TYPE) == BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21 \
173 || (R_TYPE) == BFD_RELOC_AARCH64_TLSGD_ADR_PREL21 \
174 || (R_TYPE) == BFD_RELOC_AARCH64_TLSGD_MOVW_G0_NC \
175 || (R_TYPE) == BFD_RELOC_AARCH64_TLSGD_MOVW_G1 \
176 || (R_TYPE) == BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21 \
177 || (R_TYPE) == BFD_RELOC_AARCH64_TLSIE_LD32_GOTTPREL_LO12_NC \
178 || (R_TYPE) == BFD_RELOC_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC \
179 || (R_TYPE) == BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19 \
180 || (R_TYPE) == BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G0_NC \
181 || (R_TYPE) == BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G1 \
182 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_ADD_DTPREL_HI12 \
183 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_ADD_DTPREL_LO12 \
184 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_ADD_DTPREL_LO12_NC \
185 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC \
186 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21 \
187 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_ADR_PREL21 \
188 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_LDST16_DTPREL_LO12 \
189 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_LDST16_DTPREL_LO12_NC \
190 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_LDST32_DTPREL_LO12 \
191 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_LDST32_DTPREL_LO12_NC \
192 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_LDST64_DTPREL_LO12 \
193 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_LDST64_DTPREL_LO12_NC \
194 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_LDST8_DTPREL_LO12 \
195 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_LDST8_DTPREL_LO12_NC \
196 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G0 \
197 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G0_NC \
198 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G1 \
199 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G1_NC \
200 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G2 \
201 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_HI12 \
202 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_LO12 \
203 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_LO12_NC \
204 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0 \
205 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC \
206 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1 \
207 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1_NC \
208 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G2 \
209 || (R_TYPE) == BFD_RELOC_AARCH64_TLS_DTPMOD \
210 || (R_TYPE) == BFD_RELOC_AARCH64_TLS_DTPREL \
211 || (R_TYPE) == BFD_RELOC_AARCH64_TLS_TPREL \
212 || IS_AARCH64_TLSDESC_RELOC ((R_TYPE)))
214 #define IS_AARCH64_TLS_RELAX_RELOC(R_TYPE) \
215 ((R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_ADD \
216 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_ADD_LO12 \
217 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21 \
218 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21 \
219 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_CALL \
220 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_LD_PREL19 \
221 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_LDNN_LO12_NC \
222 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_LDR \
223 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_OFF_G0_NC \
224 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_OFF_G1 \
225 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_LDR \
226 || (R_TYPE) == BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21 \
227 || (R_TYPE) == BFD_RELOC_AARCH64_TLSGD_ADR_PREL21 \
228 || (R_TYPE) == BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC \
229 || (R_TYPE) == BFD_RELOC_AARCH64_TLSGD_MOVW_G0_NC \
230 || (R_TYPE) == BFD_RELOC_AARCH64_TLSGD_MOVW_G1 \
231 || (R_TYPE) == BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21 \
232 || (R_TYPE) == BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19 \
233 || (R_TYPE) == BFD_RELOC_AARCH64_TLSIE_LDNN_GOTTPREL_LO12_NC \
234 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC \
235 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21 \
236 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_ADR_PREL21)
238 #define IS_AARCH64_TLSDESC_RELOC(R_TYPE) \
239 ((R_TYPE) == BFD_RELOC_AARCH64_TLSDESC \
240 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_ADD \
241 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_ADD_LO12 \
242 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21 \
243 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21 \
244 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_CALL \
245 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_LD32_LO12_NC \
246 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_LD64_LO12 \
247 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_LDR \
248 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_LD_PREL19 \
249 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_OFF_G0_NC \
250 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_OFF_G1)
252 #define ELIMINATE_COPY_RELOCS 0
254 /* Return size of a relocation entry. HTAB is the bfd's
255 elf_aarch64_link_hash_entry. */
256 #define RELOC_SIZE(HTAB) (sizeof (ElfNN_External_Rela))
258 /* GOT Entry size - 8 bytes in ELF64 and 4 bytes in ELF32. */
259 #define GOT_ENTRY_SIZE (ARCH_SIZE / 8)
260 #define PLT_ENTRY_SIZE (32)
261 #define PLT_SMALL_ENTRY_SIZE (16)
262 #define PLT_TLSDESC_ENTRY_SIZE (32)
264 /* Encoding of the nop instruction. */
265 #define INSN_NOP 0xd503201f
267 #define aarch64_compute_jump_table_size(htab) \
268 (((htab)->root.srelplt == NULL) ? 0 \
269 : (htab)->root.srelplt->reloc_count * GOT_ENTRY_SIZE)
271 /* The first entry in a procedure linkage table looks like this
272 if the distance between the PLTGOT and the PLT is < 4GB use
273 these PLT entries. Note that the dynamic linker gets &PLTGOT[2]
274 in x16 and needs to work out PLTGOT[1] by using an address of
275 [x16,#-GOT_ENTRY_SIZE]. */
276 static const bfd_byte elfNN_aarch64_small_plt0_entry
[PLT_ENTRY_SIZE
] =
278 0xf0, 0x7b, 0xbf, 0xa9, /* stp x16, x30, [sp, #-16]! */
279 0x10, 0x00, 0x00, 0x90, /* adrp x16, (GOT+16) */
281 0x11, 0x0A, 0x40, 0xf9, /* ldr x17, [x16, #PLT_GOT+0x10] */
282 0x10, 0x42, 0x00, 0x91, /* add x16, x16,#PLT_GOT+0x10 */
284 0x11, 0x0A, 0x40, 0xb9, /* ldr w17, [x16, #PLT_GOT+0x8] */
285 0x10, 0x22, 0x00, 0x11, /* add w16, w16,#PLT_GOT+0x8 */
287 0x20, 0x02, 0x1f, 0xd6, /* br x17 */
288 0x1f, 0x20, 0x03, 0xd5, /* nop */
289 0x1f, 0x20, 0x03, 0xd5, /* nop */
290 0x1f, 0x20, 0x03, 0xd5, /* nop */
293 /* Per function entry in a procedure linkage table looks like this
294 if the distance between the PLTGOT and the PLT is < 4GB use
295 these PLT entries. */
296 static const bfd_byte elfNN_aarch64_small_plt_entry
[PLT_SMALL_ENTRY_SIZE
] =
298 0x10, 0x00, 0x00, 0x90, /* adrp x16, PLTGOT + n * 8 */
300 0x11, 0x02, 0x40, 0xf9, /* ldr x17, [x16, PLTGOT + n * 8] */
301 0x10, 0x02, 0x00, 0x91, /* add x16, x16, :lo12:PLTGOT + n * 8 */
303 0x11, 0x02, 0x40, 0xb9, /* ldr w17, [x16, PLTGOT + n * 4] */
304 0x10, 0x02, 0x00, 0x11, /* add w16, w16, :lo12:PLTGOT + n * 4 */
306 0x20, 0x02, 0x1f, 0xd6, /* br x17. */
309 static const bfd_byte
310 elfNN_aarch64_tlsdesc_small_plt_entry
[PLT_TLSDESC_ENTRY_SIZE
] =
312 0xe2, 0x0f, 0xbf, 0xa9, /* stp x2, x3, [sp, #-16]! */
313 0x02, 0x00, 0x00, 0x90, /* adrp x2, 0 */
314 0x03, 0x00, 0x00, 0x90, /* adrp x3, 0 */
316 0x42, 0x00, 0x40, 0xf9, /* ldr x2, [x2, #0] */
317 0x63, 0x00, 0x00, 0x91, /* add x3, x3, 0 */
319 0x42, 0x00, 0x40, 0xb9, /* ldr w2, [x2, #0] */
320 0x63, 0x00, 0x00, 0x11, /* add w3, w3, 0 */
322 0x40, 0x00, 0x1f, 0xd6, /* br x2 */
323 0x1f, 0x20, 0x03, 0xd5, /* nop */
324 0x1f, 0x20, 0x03, 0xd5, /* nop */
327 #define elf_info_to_howto elfNN_aarch64_info_to_howto
328 #define elf_info_to_howto_rel elfNN_aarch64_info_to_howto
330 #define AARCH64_ELF_ABI_VERSION 0
332 /* In case we're on a 32-bit machine, construct a 64-bit "-1" value. */
333 #define ALL_ONES (~ (bfd_vma) 0)
335 /* Indexed by the bfd interal reloc enumerators.
336 Therefore, the table needs to be synced with BFD_RELOC_AARCH64_*
339 static reloc_howto_type elfNN_aarch64_howto_table
[] =
343 /* Basic data relocations. */
345 /* Deprecated, but retained for backwards compatibility. */
346 HOWTO64 (R_AARCH64_NULL
, /* type */
348 3, /* size (0 = byte, 1 = short, 2 = long) */
350 FALSE
, /* pc_relative */
352 complain_overflow_dont
, /* complain_on_overflow */
353 bfd_elf_generic_reloc
, /* special_function */
354 "R_AARCH64_NULL", /* name */
355 FALSE
, /* partial_inplace */
358 FALSE
), /* pcrel_offset */
359 HOWTO (R_AARCH64_NONE
, /* type */
361 3, /* size (0 = byte, 1 = short, 2 = long) */
363 FALSE
, /* pc_relative */
365 complain_overflow_dont
, /* complain_on_overflow */
366 bfd_elf_generic_reloc
, /* special_function */
367 "R_AARCH64_NONE", /* name */
368 FALSE
, /* partial_inplace */
371 FALSE
), /* pcrel_offset */
374 HOWTO64 (AARCH64_R (ABS64
), /* type */
376 4, /* size (4 = long long) */
378 FALSE
, /* pc_relative */
380 complain_overflow_unsigned
, /* complain_on_overflow */
381 bfd_elf_generic_reloc
, /* special_function */
382 AARCH64_R_STR (ABS64
), /* name */
383 FALSE
, /* partial_inplace */
384 ALL_ONES
, /* src_mask */
385 ALL_ONES
, /* dst_mask */
386 FALSE
), /* pcrel_offset */
389 HOWTO (AARCH64_R (ABS32
), /* type */
391 2, /* size (0 = byte, 1 = short, 2 = long) */
393 FALSE
, /* pc_relative */
395 complain_overflow_unsigned
, /* complain_on_overflow */
396 bfd_elf_generic_reloc
, /* special_function */
397 AARCH64_R_STR (ABS32
), /* name */
398 FALSE
, /* partial_inplace */
399 0xffffffff, /* src_mask */
400 0xffffffff, /* dst_mask */
401 FALSE
), /* pcrel_offset */
404 HOWTO (AARCH64_R (ABS16
), /* type */
406 1, /* size (0 = byte, 1 = short, 2 = long) */
408 FALSE
, /* pc_relative */
410 complain_overflow_unsigned
, /* complain_on_overflow */
411 bfd_elf_generic_reloc
, /* special_function */
412 AARCH64_R_STR (ABS16
), /* name */
413 FALSE
, /* partial_inplace */
414 0xffff, /* src_mask */
415 0xffff, /* dst_mask */
416 FALSE
), /* pcrel_offset */
418 /* .xword: (S+A-P) */
419 HOWTO64 (AARCH64_R (PREL64
), /* type */
421 4, /* size (4 = long long) */
423 TRUE
, /* pc_relative */
425 complain_overflow_signed
, /* complain_on_overflow */
426 bfd_elf_generic_reloc
, /* special_function */
427 AARCH64_R_STR (PREL64
), /* name */
428 FALSE
, /* partial_inplace */
429 ALL_ONES
, /* src_mask */
430 ALL_ONES
, /* dst_mask */
431 TRUE
), /* pcrel_offset */
434 HOWTO (AARCH64_R (PREL32
), /* type */
436 2, /* size (0 = byte, 1 = short, 2 = long) */
438 TRUE
, /* pc_relative */
440 complain_overflow_signed
, /* complain_on_overflow */
441 bfd_elf_generic_reloc
, /* special_function */
442 AARCH64_R_STR (PREL32
), /* name */
443 FALSE
, /* partial_inplace */
444 0xffffffff, /* src_mask */
445 0xffffffff, /* dst_mask */
446 TRUE
), /* pcrel_offset */
449 HOWTO (AARCH64_R (PREL16
), /* type */
451 1, /* size (0 = byte, 1 = short, 2 = long) */
453 TRUE
, /* pc_relative */
455 complain_overflow_signed
, /* complain_on_overflow */
456 bfd_elf_generic_reloc
, /* special_function */
457 AARCH64_R_STR (PREL16
), /* name */
458 FALSE
, /* partial_inplace */
459 0xffff, /* src_mask */
460 0xffff, /* dst_mask */
461 TRUE
), /* pcrel_offset */
463 /* Group relocations to create a 16, 32, 48 or 64 bit
464 unsigned data or abs address inline. */
466 /* MOVZ: ((S+A) >> 0) & 0xffff */
467 HOWTO (AARCH64_R (MOVW_UABS_G0
), /* type */
469 2, /* size (0 = byte, 1 = short, 2 = long) */
471 FALSE
, /* pc_relative */
473 complain_overflow_unsigned
, /* complain_on_overflow */
474 bfd_elf_generic_reloc
, /* special_function */
475 AARCH64_R_STR (MOVW_UABS_G0
), /* name */
476 FALSE
, /* partial_inplace */
477 0xffff, /* src_mask */
478 0xffff, /* dst_mask */
479 FALSE
), /* pcrel_offset */
481 /* MOVK: ((S+A) >> 0) & 0xffff [no overflow check] */
482 HOWTO (AARCH64_R (MOVW_UABS_G0_NC
), /* type */
484 2, /* size (0 = byte, 1 = short, 2 = long) */
486 FALSE
, /* pc_relative */
488 complain_overflow_dont
, /* complain_on_overflow */
489 bfd_elf_generic_reloc
, /* special_function */
490 AARCH64_R_STR (MOVW_UABS_G0_NC
), /* name */
491 FALSE
, /* partial_inplace */
492 0xffff, /* src_mask */
493 0xffff, /* dst_mask */
494 FALSE
), /* pcrel_offset */
496 /* MOVZ: ((S+A) >> 16) & 0xffff */
497 HOWTO (AARCH64_R (MOVW_UABS_G1
), /* type */
499 2, /* size (0 = byte, 1 = short, 2 = long) */
501 FALSE
, /* pc_relative */
503 complain_overflow_unsigned
, /* complain_on_overflow */
504 bfd_elf_generic_reloc
, /* special_function */
505 AARCH64_R_STR (MOVW_UABS_G1
), /* name */
506 FALSE
, /* partial_inplace */
507 0xffff, /* src_mask */
508 0xffff, /* dst_mask */
509 FALSE
), /* pcrel_offset */
511 /* MOVK: ((S+A) >> 16) & 0xffff [no overflow check] */
512 HOWTO64 (AARCH64_R (MOVW_UABS_G1_NC
), /* type */
514 2, /* size (0 = byte, 1 = short, 2 = long) */
516 FALSE
, /* pc_relative */
518 complain_overflow_dont
, /* complain_on_overflow */
519 bfd_elf_generic_reloc
, /* special_function */
520 AARCH64_R_STR (MOVW_UABS_G1_NC
), /* name */
521 FALSE
, /* partial_inplace */
522 0xffff, /* src_mask */
523 0xffff, /* dst_mask */
524 FALSE
), /* pcrel_offset */
526 /* MOVZ: ((S+A) >> 32) & 0xffff */
527 HOWTO64 (AARCH64_R (MOVW_UABS_G2
), /* type */
529 2, /* size (0 = byte, 1 = short, 2 = long) */
531 FALSE
, /* pc_relative */
533 complain_overflow_unsigned
, /* complain_on_overflow */
534 bfd_elf_generic_reloc
, /* special_function */
535 AARCH64_R_STR (MOVW_UABS_G2
), /* name */
536 FALSE
, /* partial_inplace */
537 0xffff, /* src_mask */
538 0xffff, /* dst_mask */
539 FALSE
), /* pcrel_offset */
541 /* MOVK: ((S+A) >> 32) & 0xffff [no overflow check] */
542 HOWTO64 (AARCH64_R (MOVW_UABS_G2_NC
), /* type */
544 2, /* size (0 = byte, 1 = short, 2 = long) */
546 FALSE
, /* pc_relative */
548 complain_overflow_dont
, /* complain_on_overflow */
549 bfd_elf_generic_reloc
, /* special_function */
550 AARCH64_R_STR (MOVW_UABS_G2_NC
), /* name */
551 FALSE
, /* partial_inplace */
552 0xffff, /* src_mask */
553 0xffff, /* dst_mask */
554 FALSE
), /* pcrel_offset */
556 /* MOVZ: ((S+A) >> 48) & 0xffff */
557 HOWTO64 (AARCH64_R (MOVW_UABS_G3
), /* type */
559 2, /* size (0 = byte, 1 = short, 2 = long) */
561 FALSE
, /* pc_relative */
563 complain_overflow_unsigned
, /* complain_on_overflow */
564 bfd_elf_generic_reloc
, /* special_function */
565 AARCH64_R_STR (MOVW_UABS_G3
), /* name */
566 FALSE
, /* partial_inplace */
567 0xffff, /* src_mask */
568 0xffff, /* dst_mask */
569 FALSE
), /* pcrel_offset */
571 /* Group relocations to create high part of a 16, 32, 48 or 64 bit
572 signed data or abs address inline. Will change instruction
573 to MOVN or MOVZ depending on sign of calculated value. */
575 /* MOV[ZN]: ((S+A) >> 0) & 0xffff */
576 HOWTO (AARCH64_R (MOVW_SABS_G0
), /* type */
578 2, /* size (0 = byte, 1 = short, 2 = long) */
580 FALSE
, /* pc_relative */
582 complain_overflow_signed
, /* complain_on_overflow */
583 bfd_elf_generic_reloc
, /* special_function */
584 AARCH64_R_STR (MOVW_SABS_G0
), /* name */
585 FALSE
, /* partial_inplace */
586 0xffff, /* src_mask */
587 0xffff, /* dst_mask */
588 FALSE
), /* pcrel_offset */
590 /* MOV[ZN]: ((S+A) >> 16) & 0xffff */
591 HOWTO64 (AARCH64_R (MOVW_SABS_G1
), /* type */
593 2, /* size (0 = byte, 1 = short, 2 = long) */
595 FALSE
, /* pc_relative */
597 complain_overflow_signed
, /* complain_on_overflow */
598 bfd_elf_generic_reloc
, /* special_function */
599 AARCH64_R_STR (MOVW_SABS_G1
), /* name */
600 FALSE
, /* partial_inplace */
601 0xffff, /* src_mask */
602 0xffff, /* dst_mask */
603 FALSE
), /* pcrel_offset */
605 /* MOV[ZN]: ((S+A) >> 32) & 0xffff */
606 HOWTO64 (AARCH64_R (MOVW_SABS_G2
), /* type */
608 2, /* size (0 = byte, 1 = short, 2 = long) */
610 FALSE
, /* pc_relative */
612 complain_overflow_signed
, /* complain_on_overflow */
613 bfd_elf_generic_reloc
, /* special_function */
614 AARCH64_R_STR (MOVW_SABS_G2
), /* name */
615 FALSE
, /* partial_inplace */
616 0xffff, /* src_mask */
617 0xffff, /* dst_mask */
618 FALSE
), /* pcrel_offset */
620 /* Relocations to generate 19, 21 and 33 bit PC-relative load/store
621 addresses: PG(x) is (x & ~0xfff). */
623 /* LD-lit: ((S+A-P) >> 2) & 0x7ffff */
624 HOWTO (AARCH64_R (LD_PREL_LO19
), /* type */
626 2, /* size (0 = byte, 1 = short, 2 = long) */
628 TRUE
, /* pc_relative */
630 complain_overflow_signed
, /* complain_on_overflow */
631 bfd_elf_generic_reloc
, /* special_function */
632 AARCH64_R_STR (LD_PREL_LO19
), /* name */
633 FALSE
, /* partial_inplace */
634 0x7ffff, /* src_mask */
635 0x7ffff, /* dst_mask */
636 TRUE
), /* pcrel_offset */
638 /* ADR: (S+A-P) & 0x1fffff */
639 HOWTO (AARCH64_R (ADR_PREL_LO21
), /* type */
641 2, /* size (0 = byte, 1 = short, 2 = long) */
643 TRUE
, /* pc_relative */
645 complain_overflow_signed
, /* complain_on_overflow */
646 bfd_elf_generic_reloc
, /* special_function */
647 AARCH64_R_STR (ADR_PREL_LO21
), /* name */
648 FALSE
, /* partial_inplace */
649 0x1fffff, /* src_mask */
650 0x1fffff, /* dst_mask */
651 TRUE
), /* pcrel_offset */
653 /* ADRP: ((PG(S+A)-PG(P)) >> 12) & 0x1fffff */
654 HOWTO (AARCH64_R (ADR_PREL_PG_HI21
), /* type */
656 2, /* size (0 = byte, 1 = short, 2 = long) */
658 TRUE
, /* pc_relative */
660 complain_overflow_signed
, /* complain_on_overflow */
661 bfd_elf_generic_reloc
, /* special_function */
662 AARCH64_R_STR (ADR_PREL_PG_HI21
), /* name */
663 FALSE
, /* partial_inplace */
664 0x1fffff, /* src_mask */
665 0x1fffff, /* dst_mask */
666 TRUE
), /* pcrel_offset */
668 /* ADRP: ((PG(S+A)-PG(P)) >> 12) & 0x1fffff [no overflow check] */
669 HOWTO64 (AARCH64_R (ADR_PREL_PG_HI21_NC
), /* type */
671 2, /* size (0 = byte, 1 = short, 2 = long) */
673 TRUE
, /* pc_relative */
675 complain_overflow_dont
, /* complain_on_overflow */
676 bfd_elf_generic_reloc
, /* special_function */
677 AARCH64_R_STR (ADR_PREL_PG_HI21_NC
), /* name */
678 FALSE
, /* partial_inplace */
679 0x1fffff, /* src_mask */
680 0x1fffff, /* dst_mask */
681 TRUE
), /* pcrel_offset */
683 /* ADD: (S+A) & 0xfff [no overflow check] */
684 HOWTO (AARCH64_R (ADD_ABS_LO12_NC
), /* type */
686 2, /* size (0 = byte, 1 = short, 2 = long) */
688 FALSE
, /* pc_relative */
690 complain_overflow_dont
, /* complain_on_overflow */
691 bfd_elf_generic_reloc
, /* special_function */
692 AARCH64_R_STR (ADD_ABS_LO12_NC
), /* name */
693 FALSE
, /* partial_inplace */
694 0x3ffc00, /* src_mask */
695 0x3ffc00, /* dst_mask */
696 FALSE
), /* pcrel_offset */
698 /* LD/ST8: (S+A) & 0xfff */
699 HOWTO (AARCH64_R (LDST8_ABS_LO12_NC
), /* type */
701 2, /* size (0 = byte, 1 = short, 2 = long) */
703 FALSE
, /* pc_relative */
705 complain_overflow_dont
, /* complain_on_overflow */
706 bfd_elf_generic_reloc
, /* special_function */
707 AARCH64_R_STR (LDST8_ABS_LO12_NC
), /* name */
708 FALSE
, /* partial_inplace */
709 0xfff, /* src_mask */
710 0xfff, /* dst_mask */
711 FALSE
), /* pcrel_offset */
713 /* Relocations for control-flow instructions. */
715 /* TBZ/NZ: ((S+A-P) >> 2) & 0x3fff */
716 HOWTO (AARCH64_R (TSTBR14
), /* type */
718 2, /* size (0 = byte, 1 = short, 2 = long) */
720 TRUE
, /* pc_relative */
722 complain_overflow_signed
, /* complain_on_overflow */
723 bfd_elf_generic_reloc
, /* special_function */
724 AARCH64_R_STR (TSTBR14
), /* name */
725 FALSE
, /* partial_inplace */
726 0x3fff, /* src_mask */
727 0x3fff, /* dst_mask */
728 TRUE
), /* pcrel_offset */
730 /* B.cond: ((S+A-P) >> 2) & 0x7ffff */
731 HOWTO (AARCH64_R (CONDBR19
), /* type */
733 2, /* size (0 = byte, 1 = short, 2 = long) */
735 TRUE
, /* pc_relative */
737 complain_overflow_signed
, /* complain_on_overflow */
738 bfd_elf_generic_reloc
, /* special_function */
739 AARCH64_R_STR (CONDBR19
), /* name */
740 FALSE
, /* partial_inplace */
741 0x7ffff, /* src_mask */
742 0x7ffff, /* dst_mask */
743 TRUE
), /* pcrel_offset */
745 /* B: ((S+A-P) >> 2) & 0x3ffffff */
746 HOWTO (AARCH64_R (JUMP26
), /* type */
748 2, /* size (0 = byte, 1 = short, 2 = long) */
750 TRUE
, /* pc_relative */
752 complain_overflow_signed
, /* complain_on_overflow */
753 bfd_elf_generic_reloc
, /* special_function */
754 AARCH64_R_STR (JUMP26
), /* name */
755 FALSE
, /* partial_inplace */
756 0x3ffffff, /* src_mask */
757 0x3ffffff, /* dst_mask */
758 TRUE
), /* pcrel_offset */
760 /* BL: ((S+A-P) >> 2) & 0x3ffffff */
761 HOWTO (AARCH64_R (CALL26
), /* type */
763 2, /* size (0 = byte, 1 = short, 2 = long) */
765 TRUE
, /* pc_relative */
767 complain_overflow_signed
, /* complain_on_overflow */
768 bfd_elf_generic_reloc
, /* special_function */
769 AARCH64_R_STR (CALL26
), /* name */
770 FALSE
, /* partial_inplace */
771 0x3ffffff, /* src_mask */
772 0x3ffffff, /* dst_mask */
773 TRUE
), /* pcrel_offset */
775 /* LD/ST16: (S+A) & 0xffe */
776 HOWTO (AARCH64_R (LDST16_ABS_LO12_NC
), /* type */
778 2, /* size (0 = byte, 1 = short, 2 = long) */
780 FALSE
, /* pc_relative */
782 complain_overflow_dont
, /* complain_on_overflow */
783 bfd_elf_generic_reloc
, /* special_function */
784 AARCH64_R_STR (LDST16_ABS_LO12_NC
), /* name */
785 FALSE
, /* partial_inplace */
786 0xffe, /* src_mask */
787 0xffe, /* dst_mask */
788 FALSE
), /* pcrel_offset */
790 /* LD/ST32: (S+A) & 0xffc */
791 HOWTO (AARCH64_R (LDST32_ABS_LO12_NC
), /* type */
793 2, /* size (0 = byte, 1 = short, 2 = long) */
795 FALSE
, /* pc_relative */
797 complain_overflow_dont
, /* complain_on_overflow */
798 bfd_elf_generic_reloc
, /* special_function */
799 AARCH64_R_STR (LDST32_ABS_LO12_NC
), /* name */
800 FALSE
, /* partial_inplace */
801 0xffc, /* src_mask */
802 0xffc, /* dst_mask */
803 FALSE
), /* pcrel_offset */
805 /* LD/ST64: (S+A) & 0xff8 */
806 HOWTO (AARCH64_R (LDST64_ABS_LO12_NC
), /* type */
808 2, /* size (0 = byte, 1 = short, 2 = long) */
810 FALSE
, /* pc_relative */
812 complain_overflow_dont
, /* complain_on_overflow */
813 bfd_elf_generic_reloc
, /* special_function */
814 AARCH64_R_STR (LDST64_ABS_LO12_NC
), /* name */
815 FALSE
, /* partial_inplace */
816 0xff8, /* src_mask */
817 0xff8, /* dst_mask */
818 FALSE
), /* pcrel_offset */
820 /* LD/ST128: (S+A) & 0xff0 */
821 HOWTO (AARCH64_R (LDST128_ABS_LO12_NC
), /* type */
823 2, /* size (0 = byte, 1 = short, 2 = long) */
825 FALSE
, /* pc_relative */
827 complain_overflow_dont
, /* complain_on_overflow */
828 bfd_elf_generic_reloc
, /* special_function */
829 AARCH64_R_STR (LDST128_ABS_LO12_NC
), /* name */
830 FALSE
, /* partial_inplace */
831 0xff0, /* src_mask */
832 0xff0, /* dst_mask */
833 FALSE
), /* pcrel_offset */
835 /* Set a load-literal immediate field to bits
836 0x1FFFFC of G(S)-P */
837 HOWTO (AARCH64_R (GOT_LD_PREL19
), /* type */
839 2, /* size (0 = byte,1 = short,2 = long) */
841 TRUE
, /* pc_relative */
843 complain_overflow_signed
, /* complain_on_overflow */
844 bfd_elf_generic_reloc
, /* special_function */
845 AARCH64_R_STR (GOT_LD_PREL19
), /* name */
846 FALSE
, /* partial_inplace */
847 0xffffe0, /* src_mask */
848 0xffffe0, /* dst_mask */
849 TRUE
), /* pcrel_offset */
851 /* Get to the page for the GOT entry for the symbol
852 (G(S) - P) using an ADRP instruction. */
853 HOWTO (AARCH64_R (ADR_GOT_PAGE
), /* type */
855 2, /* size (0 = byte, 1 = short, 2 = long) */
857 TRUE
, /* pc_relative */
859 complain_overflow_dont
, /* complain_on_overflow */
860 bfd_elf_generic_reloc
, /* special_function */
861 AARCH64_R_STR (ADR_GOT_PAGE
), /* name */
862 FALSE
, /* partial_inplace */
863 0x1fffff, /* src_mask */
864 0x1fffff, /* dst_mask */
865 TRUE
), /* pcrel_offset */
867 /* LD64: GOT offset G(S) & 0xff8 */
868 HOWTO64 (AARCH64_R (LD64_GOT_LO12_NC
), /* type */
870 2, /* size (0 = byte, 1 = short, 2 = long) */
872 FALSE
, /* pc_relative */
874 complain_overflow_dont
, /* complain_on_overflow */
875 bfd_elf_generic_reloc
, /* special_function */
876 AARCH64_R_STR (LD64_GOT_LO12_NC
), /* name */
877 FALSE
, /* partial_inplace */
878 0xff8, /* src_mask */
879 0xff8, /* dst_mask */
880 FALSE
), /* pcrel_offset */
882 /* LD32: GOT offset G(S) & 0xffc */
883 HOWTO32 (AARCH64_R (LD32_GOT_LO12_NC
), /* type */
885 2, /* size (0 = byte, 1 = short, 2 = long) */
887 FALSE
, /* pc_relative */
889 complain_overflow_dont
, /* complain_on_overflow */
890 bfd_elf_generic_reloc
, /* special_function */
891 AARCH64_R_STR (LD32_GOT_LO12_NC
), /* name */
892 FALSE
, /* partial_inplace */
893 0xffc, /* src_mask */
894 0xffc, /* dst_mask */
895 FALSE
), /* pcrel_offset */
897 /* Lower 16 bits of GOT offset for the symbol. */
898 HOWTO64 (AARCH64_R (MOVW_GOTOFF_G0_NC
), /* type */
900 2, /* size (0 = byte, 1 = short, 2 = long) */
902 FALSE
, /* pc_relative */
904 complain_overflow_dont
, /* complain_on_overflow */
905 bfd_elf_generic_reloc
, /* special_function */
906 AARCH64_R_STR (MOVW_GOTOFF_G0_NC
), /* name */
907 FALSE
, /* partial_inplace */
908 0xffff, /* src_mask */
909 0xffff, /* dst_mask */
910 FALSE
), /* pcrel_offset */
912 /* Higher 16 bits of GOT offset for the symbol. */
913 HOWTO64 (AARCH64_R (MOVW_GOTOFF_G1
), /* type */
915 2, /* size (0 = byte, 1 = short, 2 = long) */
917 FALSE
, /* pc_relative */
919 complain_overflow_unsigned
, /* complain_on_overflow */
920 bfd_elf_generic_reloc
, /* special_function */
921 AARCH64_R_STR (MOVW_GOTOFF_G1
), /* name */
922 FALSE
, /* partial_inplace */
923 0xffff, /* src_mask */
924 0xffff, /* dst_mask */
925 FALSE
), /* pcrel_offset */
927 /* LD64: GOT offset for the symbol. */
928 HOWTO64 (AARCH64_R (LD64_GOTOFF_LO15
), /* type */
930 2, /* size (0 = byte, 1 = short, 2 = long) */
932 FALSE
, /* pc_relative */
934 complain_overflow_unsigned
, /* complain_on_overflow */
935 bfd_elf_generic_reloc
, /* special_function */
936 AARCH64_R_STR (LD64_GOTOFF_LO15
), /* name */
937 FALSE
, /* partial_inplace */
938 0x7ff8, /* src_mask */
939 0x7ff8, /* dst_mask */
940 FALSE
), /* pcrel_offset */
942 /* LD32: GOT offset to the page address of GOT table.
943 (G(S) - PAGE (_GLOBAL_OFFSET_TABLE_)) & 0x5ffc. */
944 HOWTO32 (AARCH64_R (LD32_GOTPAGE_LO14
), /* type */
946 2, /* size (0 = byte, 1 = short, 2 = long) */
948 FALSE
, /* pc_relative */
950 complain_overflow_unsigned
, /* complain_on_overflow */
951 bfd_elf_generic_reloc
, /* special_function */
952 AARCH64_R_STR (LD32_GOTPAGE_LO14
), /* name */
953 FALSE
, /* partial_inplace */
954 0x5ffc, /* src_mask */
955 0x5ffc, /* dst_mask */
956 FALSE
), /* pcrel_offset */
958 /* LD64: GOT offset to the page address of GOT table.
959 (G(S) - PAGE (_GLOBAL_OFFSET_TABLE_)) & 0x7ff8. */
960 HOWTO64 (AARCH64_R (LD64_GOTPAGE_LO15
), /* type */
962 2, /* size (0 = byte, 1 = short, 2 = long) */
964 FALSE
, /* pc_relative */
966 complain_overflow_unsigned
, /* complain_on_overflow */
967 bfd_elf_generic_reloc
, /* special_function */
968 AARCH64_R_STR (LD64_GOTPAGE_LO15
), /* name */
969 FALSE
, /* partial_inplace */
970 0x7ff8, /* src_mask */
971 0x7ff8, /* dst_mask */
972 FALSE
), /* pcrel_offset */
974 /* Get to the page for the GOT entry for the symbol
975 (G(S) - P) using an ADRP instruction. */
976 HOWTO (AARCH64_R (TLSGD_ADR_PAGE21
), /* type */
978 2, /* size (0 = byte, 1 = short, 2 = long) */
980 TRUE
, /* pc_relative */
982 complain_overflow_dont
, /* complain_on_overflow */
983 bfd_elf_generic_reloc
, /* special_function */
984 AARCH64_R_STR (TLSGD_ADR_PAGE21
), /* name */
985 FALSE
, /* partial_inplace */
986 0x1fffff, /* src_mask */
987 0x1fffff, /* dst_mask */
988 TRUE
), /* pcrel_offset */
990 HOWTO (AARCH64_R (TLSGD_ADR_PREL21
), /* type */
992 2, /* size (0 = byte, 1 = short, 2 = long) */
994 TRUE
, /* pc_relative */
996 complain_overflow_dont
, /* complain_on_overflow */
997 bfd_elf_generic_reloc
, /* special_function */
998 AARCH64_R_STR (TLSGD_ADR_PREL21
), /* name */
999 FALSE
, /* partial_inplace */
1000 0x1fffff, /* src_mask */
1001 0x1fffff, /* dst_mask */
1002 TRUE
), /* pcrel_offset */
1004 /* ADD: GOT offset G(S) & 0xff8 [no overflow check] */
1005 HOWTO (AARCH64_R (TLSGD_ADD_LO12_NC
), /* type */
1007 2, /* size (0 = byte, 1 = short, 2 = long) */
1009 FALSE
, /* pc_relative */
1011 complain_overflow_dont
, /* complain_on_overflow */
1012 bfd_elf_generic_reloc
, /* special_function */
1013 AARCH64_R_STR (TLSGD_ADD_LO12_NC
), /* name */
1014 FALSE
, /* partial_inplace */
1015 0xfff, /* src_mask */
1016 0xfff, /* dst_mask */
1017 FALSE
), /* pcrel_offset */
1019 /* Lower 16 bits of GOT offset to tls_index. */
1020 HOWTO64 (AARCH64_R (TLSGD_MOVW_G0_NC
), /* type */
1022 2, /* size (0 = byte, 1 = short, 2 = long) */
1024 FALSE
, /* pc_relative */
1026 complain_overflow_dont
, /* complain_on_overflow */
1027 bfd_elf_generic_reloc
, /* special_function */
1028 AARCH64_R_STR (TLSGD_MOVW_G0_NC
), /* name */
1029 FALSE
, /* partial_inplace */
1030 0xffff, /* src_mask */
1031 0xffff, /* dst_mask */
1032 FALSE
), /* pcrel_offset */
1034 /* Higher 16 bits of GOT offset to tls_index. */
1035 HOWTO64 (AARCH64_R (TLSGD_MOVW_G1
), /* type */
1036 16, /* rightshift */
1037 2, /* size (0 = byte, 1 = short, 2 = long) */
1039 FALSE
, /* pc_relative */
1041 complain_overflow_unsigned
, /* complain_on_overflow */
1042 bfd_elf_generic_reloc
, /* special_function */
1043 AARCH64_R_STR (TLSGD_MOVW_G1
), /* name */
1044 FALSE
, /* partial_inplace */
1045 0xffff, /* src_mask */
1046 0xffff, /* dst_mask */
1047 FALSE
), /* pcrel_offset */
1049 HOWTO (AARCH64_R (TLSIE_ADR_GOTTPREL_PAGE21
), /* type */
1050 12, /* rightshift */
1051 2, /* size (0 = byte, 1 = short, 2 = long) */
1053 FALSE
, /* pc_relative */
1055 complain_overflow_dont
, /* complain_on_overflow */
1056 bfd_elf_generic_reloc
, /* special_function */
1057 AARCH64_R_STR (TLSIE_ADR_GOTTPREL_PAGE21
), /* name */
1058 FALSE
, /* partial_inplace */
1059 0x1fffff, /* src_mask */
1060 0x1fffff, /* dst_mask */
1061 FALSE
), /* pcrel_offset */
1063 HOWTO64 (AARCH64_R (TLSIE_LD64_GOTTPREL_LO12_NC
), /* type */
1065 2, /* size (0 = byte, 1 = short, 2 = long) */
1067 FALSE
, /* pc_relative */
1069 complain_overflow_dont
, /* complain_on_overflow */
1070 bfd_elf_generic_reloc
, /* special_function */
1071 AARCH64_R_STR (TLSIE_LD64_GOTTPREL_LO12_NC
), /* name */
1072 FALSE
, /* partial_inplace */
1073 0xff8, /* src_mask */
1074 0xff8, /* dst_mask */
1075 FALSE
), /* pcrel_offset */
1077 HOWTO32 (AARCH64_R (TLSIE_LD32_GOTTPREL_LO12_NC
), /* type */
1079 2, /* size (0 = byte, 1 = short, 2 = long) */
1081 FALSE
, /* pc_relative */
1083 complain_overflow_dont
, /* complain_on_overflow */
1084 bfd_elf_generic_reloc
, /* special_function */
1085 AARCH64_R_STR (TLSIE_LD32_GOTTPREL_LO12_NC
), /* name */
1086 FALSE
, /* partial_inplace */
1087 0xffc, /* src_mask */
1088 0xffc, /* dst_mask */
1089 FALSE
), /* pcrel_offset */
1091 HOWTO (AARCH64_R (TLSIE_LD_GOTTPREL_PREL19
), /* type */
1093 2, /* size (0 = byte, 1 = short, 2 = long) */
1095 FALSE
, /* pc_relative */
1097 complain_overflow_dont
, /* complain_on_overflow */
1098 bfd_elf_generic_reloc
, /* special_function */
1099 AARCH64_R_STR (TLSIE_LD_GOTTPREL_PREL19
), /* name */
1100 FALSE
, /* partial_inplace */
1101 0x1ffffc, /* src_mask */
1102 0x1ffffc, /* dst_mask */
1103 FALSE
), /* pcrel_offset */
1105 HOWTO64 (AARCH64_R (TLSIE_MOVW_GOTTPREL_G0_NC
), /* type */
1107 2, /* size (0 = byte, 1 = short, 2 = long) */
1109 FALSE
, /* pc_relative */
1111 complain_overflow_dont
, /* complain_on_overflow */
1112 bfd_elf_generic_reloc
, /* special_function */
1113 AARCH64_R_STR (TLSIE_MOVW_GOTTPREL_G0_NC
), /* name */
1114 FALSE
, /* partial_inplace */
1115 0xffff, /* src_mask */
1116 0xffff, /* dst_mask */
1117 FALSE
), /* pcrel_offset */
1119 HOWTO64 (AARCH64_R (TLSIE_MOVW_GOTTPREL_G1
), /* type */
1120 16, /* rightshift */
1121 2, /* size (0 = byte, 1 = short, 2 = long) */
1123 FALSE
, /* pc_relative */
1125 complain_overflow_unsigned
, /* complain_on_overflow */
1126 bfd_elf_generic_reloc
, /* special_function */
1127 AARCH64_R_STR (TLSIE_MOVW_GOTTPREL_G1
), /* name */
1128 FALSE
, /* partial_inplace */
1129 0xffff, /* src_mask */
1130 0xffff, /* dst_mask */
1131 FALSE
), /* pcrel_offset */
1133 /* ADD: bit[23:12] of byte offset to module TLS base address. */
1134 HOWTO (AARCH64_R (TLSLD_ADD_DTPREL_HI12
), /* type */
1135 12, /* rightshift */
1136 2, /* size (0 = byte, 1 = short, 2 = long) */
1138 FALSE
, /* pc_relative */
1140 complain_overflow_unsigned
, /* complain_on_overflow */
1141 bfd_elf_generic_reloc
, /* special_function */
1142 AARCH64_R_STR (TLSLD_ADD_DTPREL_HI12
), /* name */
1143 FALSE
, /* partial_inplace */
1144 0xfff, /* src_mask */
1145 0xfff, /* dst_mask */
1146 FALSE
), /* pcrel_offset */
1148 /* Unsigned 12 bit byte offset to module TLS base address. */
1149 HOWTO (AARCH64_R (TLSLD_ADD_DTPREL_LO12
), /* type */
1151 2, /* size (0 = byte, 1 = short, 2 = long) */
1153 FALSE
, /* pc_relative */
1155 complain_overflow_unsigned
, /* complain_on_overflow */
1156 bfd_elf_generic_reloc
, /* special_function */
1157 AARCH64_R_STR (TLSLD_ADD_DTPREL_LO12
), /* name */
1158 FALSE
, /* partial_inplace */
1159 0xfff, /* src_mask */
1160 0xfff, /* dst_mask */
1161 FALSE
), /* pcrel_offset */
1163 /* No overflow check version of BFD_RELOC_AARCH64_TLSLD_ADD_DTPREL_LO12. */
1164 HOWTO (AARCH64_R (TLSLD_ADD_DTPREL_LO12_NC
), /* type */
1166 2, /* size (0 = byte, 1 = short, 2 = long) */
1168 FALSE
, /* pc_relative */
1170 complain_overflow_dont
, /* complain_on_overflow */
1171 bfd_elf_generic_reloc
, /* special_function */
1172 AARCH64_R_STR (TLSLD_ADD_DTPREL_LO12_NC
), /* name */
1173 FALSE
, /* partial_inplace */
1174 0xfff, /* src_mask */
1175 0xfff, /* dst_mask */
1176 FALSE
), /* pcrel_offset */
1178 /* ADD: GOT offset G(S) & 0xff8 [no overflow check] */
1179 HOWTO (AARCH64_R (TLSLD_ADD_LO12_NC
), /* type */
1181 2, /* size (0 = byte, 1 = short, 2 = long) */
1183 FALSE
, /* pc_relative */
1185 complain_overflow_dont
, /* complain_on_overflow */
1186 bfd_elf_generic_reloc
, /* special_function */
1187 AARCH64_R_STR (TLSLD_ADD_LO12_NC
), /* name */
1188 FALSE
, /* partial_inplace */
1189 0xfff, /* src_mask */
1190 0xfff, /* dst_mask */
1191 FALSE
), /* pcrel_offset */
1193 /* Get to the page for the GOT entry for the symbol
1194 (G(S) - P) using an ADRP instruction. */
1195 HOWTO (AARCH64_R (TLSLD_ADR_PAGE21
), /* type */
1196 12, /* rightshift */
1197 2, /* size (0 = byte, 1 = short, 2 = long) */
1199 TRUE
, /* pc_relative */
1201 complain_overflow_signed
, /* complain_on_overflow */
1202 bfd_elf_generic_reloc
, /* special_function */
1203 AARCH64_R_STR (TLSLD_ADR_PAGE21
), /* name */
1204 FALSE
, /* partial_inplace */
1205 0x1fffff, /* src_mask */
1206 0x1fffff, /* dst_mask */
1207 TRUE
), /* pcrel_offset */
1209 HOWTO (AARCH64_R (TLSLD_ADR_PREL21
), /* type */
1211 2, /* size (0 = byte, 1 = short, 2 = long) */
1213 TRUE
, /* pc_relative */
1215 complain_overflow_signed
, /* complain_on_overflow */
1216 bfd_elf_generic_reloc
, /* special_function */
1217 AARCH64_R_STR (TLSLD_ADR_PREL21
), /* name */
1218 FALSE
, /* partial_inplace */
1219 0x1fffff, /* src_mask */
1220 0x1fffff, /* dst_mask */
1221 TRUE
), /* pcrel_offset */
1223 /* LD/ST16: bit[11:1] of byte offset to module TLS base address. */
1224 HOWTO64 (AARCH64_R (TLSLD_LDST16_DTPREL_LO12
), /* type */
1226 2, /* size (0 = byte, 1 = short, 2 = long) */
1228 FALSE
, /* pc_relative */
1230 complain_overflow_unsigned
, /* complain_on_overflow */
1231 bfd_elf_generic_reloc
, /* special_function */
1232 AARCH64_R_STR (TLSLD_LDST16_DTPREL_LO12
), /* name */
1233 FALSE
, /* partial_inplace */
1234 0x1ffc00, /* src_mask */
1235 0x1ffc00, /* dst_mask */
1236 FALSE
), /* pcrel_offset */
1238 /* Same as BFD_RELOC_AARCH64_TLSLD_LDST16_DTPREL_LO12, but no overflow check. */
1239 HOWTO64 (AARCH64_R (TLSLD_LDST16_DTPREL_LO12_NC
), /* type */
1241 2, /* size (0 = byte, 1 = short, 2 = long) */
1243 FALSE
, /* pc_relative */
1245 complain_overflow_dont
, /* complain_on_overflow */
1246 bfd_elf_generic_reloc
, /* special_function */
1247 AARCH64_R_STR (TLSLD_LDST16_DTPREL_LO12_NC
), /* name */
1248 FALSE
, /* partial_inplace */
1249 0x1ffc00, /* src_mask */
1250 0x1ffc00, /* dst_mask */
1251 FALSE
), /* pcrel_offset */
1253 /* LD/ST32: bit[11:2] of byte offset to module TLS base address. */
1254 HOWTO64 (AARCH64_R (TLSLD_LDST32_DTPREL_LO12
), /* type */
1256 2, /* size (0 = byte, 1 = short, 2 = long) */
1258 FALSE
, /* pc_relative */
1260 complain_overflow_unsigned
, /* complain_on_overflow */
1261 bfd_elf_generic_reloc
, /* special_function */
1262 AARCH64_R_STR (TLSLD_LDST32_DTPREL_LO12
), /* name */
1263 FALSE
, /* partial_inplace */
1264 0x3ffc00, /* src_mask */
1265 0x3ffc00, /* dst_mask */
1266 FALSE
), /* pcrel_offset */
1268 /* Same as BFD_RELOC_AARCH64_TLSLD_LDST32_DTPREL_LO12, but no overflow check. */
1269 HOWTO64 (AARCH64_R (TLSLD_LDST32_DTPREL_LO12_NC
), /* type */
1271 2, /* size (0 = byte, 1 = short, 2 = long) */
1273 FALSE
, /* pc_relative */
1275 complain_overflow_dont
, /* complain_on_overflow */
1276 bfd_elf_generic_reloc
, /* special_function */
1277 AARCH64_R_STR (TLSLD_LDST32_DTPREL_LO12_NC
), /* name */
1278 FALSE
, /* partial_inplace */
1279 0xffc00, /* src_mask */
1280 0xffc00, /* dst_mask */
1281 FALSE
), /* pcrel_offset */
1283 /* LD/ST64: bit[11:3] of byte offset to module TLS base address. */
1284 HOWTO64 (AARCH64_R (TLSLD_LDST64_DTPREL_LO12
), /* type */
1286 2, /* size (0 = byte, 1 = short, 2 = long) */
1288 FALSE
, /* pc_relative */
1290 complain_overflow_unsigned
, /* complain_on_overflow */
1291 bfd_elf_generic_reloc
, /* special_function */
1292 AARCH64_R_STR (TLSLD_LDST64_DTPREL_LO12
), /* name */
1293 FALSE
, /* partial_inplace */
1294 0x3ffc00, /* src_mask */
1295 0x3ffc00, /* dst_mask */
1296 FALSE
), /* pcrel_offset */
1298 /* Same as BFD_RELOC_AARCH64_TLSLD_LDST64_DTPREL_LO12, but no overflow check. */
1299 HOWTO64 (AARCH64_R (TLSLD_LDST64_DTPREL_LO12_NC
), /* type */
1301 2, /* size (0 = byte, 1 = short, 2 = long) */
1303 FALSE
, /* pc_relative */
1305 complain_overflow_dont
, /* complain_on_overflow */
1306 bfd_elf_generic_reloc
, /* special_function */
1307 AARCH64_R_STR (TLSLD_LDST64_DTPREL_LO12_NC
), /* name */
1308 FALSE
, /* partial_inplace */
1309 0x7fc00, /* src_mask */
1310 0x7fc00, /* dst_mask */
1311 FALSE
), /* pcrel_offset */
1313 /* LD/ST8: bit[11:0] of byte offset to module TLS base address. */
1314 HOWTO64 (AARCH64_R (TLSLD_LDST8_DTPREL_LO12
), /* type */
1316 2, /* size (0 = byte, 1 = short, 2 = long) */
1318 FALSE
, /* pc_relative */
1320 complain_overflow_unsigned
, /* complain_on_overflow */
1321 bfd_elf_generic_reloc
, /* special_function */
1322 AARCH64_R_STR (TLSLD_LDST8_DTPREL_LO12
), /* name */
1323 FALSE
, /* partial_inplace */
1324 0x3ffc00, /* src_mask */
1325 0x3ffc00, /* dst_mask */
1326 FALSE
), /* pcrel_offset */
1328 /* Same as BFD_RELOC_AARCH64_TLSLD_LDST8_DTPREL_LO12, but no overflow check. */
1329 HOWTO64 (AARCH64_R (TLSLD_LDST8_DTPREL_LO12_NC
), /* type */
1331 2, /* size (0 = byte, 1 = short, 2 = long) */
1333 FALSE
, /* pc_relative */
1335 complain_overflow_dont
, /* complain_on_overflow */
1336 bfd_elf_generic_reloc
, /* special_function */
1337 AARCH64_R_STR (TLSLD_LDST8_DTPREL_LO12_NC
), /* name */
1338 FALSE
, /* partial_inplace */
1339 0x3ffc00, /* src_mask */
1340 0x3ffc00, /* dst_mask */
1341 FALSE
), /* pcrel_offset */
1343 /* MOVZ: bit[15:0] of byte offset to module TLS base address. */
1344 HOWTO (AARCH64_R (TLSLD_MOVW_DTPREL_G0
), /* type */
1346 2, /* size (0 = byte, 1 = short, 2 = long) */
1348 FALSE
, /* pc_relative */
1350 complain_overflow_unsigned
, /* complain_on_overflow */
1351 bfd_elf_generic_reloc
, /* special_function */
1352 AARCH64_R_STR (TLSLD_MOVW_DTPREL_G0
), /* name */
1353 FALSE
, /* partial_inplace */
1354 0xffff, /* src_mask */
1355 0xffff, /* dst_mask */
1356 FALSE
), /* pcrel_offset */
1358 /* No overflow check version of BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G0. */
1359 HOWTO (AARCH64_R (TLSLD_MOVW_DTPREL_G0_NC
), /* type */
1361 2, /* size (0 = byte, 1 = short, 2 = long) */
1363 FALSE
, /* pc_relative */
1365 complain_overflow_dont
, /* complain_on_overflow */
1366 bfd_elf_generic_reloc
, /* special_function */
1367 AARCH64_R_STR (TLSLD_MOVW_DTPREL_G0_NC
), /* name */
1368 FALSE
, /* partial_inplace */
1369 0xffff, /* src_mask */
1370 0xffff, /* dst_mask */
1371 FALSE
), /* pcrel_offset */
1373 /* MOVZ: bit[31:16] of byte offset to module TLS base address. */
1374 HOWTO (AARCH64_R (TLSLD_MOVW_DTPREL_G1
), /* type */
1375 16, /* rightshift */
1376 2, /* size (0 = byte, 1 = short, 2 = long) */
1378 FALSE
, /* pc_relative */
1380 complain_overflow_unsigned
, /* complain_on_overflow */
1381 bfd_elf_generic_reloc
, /* special_function */
1382 AARCH64_R_STR (TLSLD_MOVW_DTPREL_G1
), /* name */
1383 FALSE
, /* partial_inplace */
1384 0xffff, /* src_mask */
1385 0xffff, /* dst_mask */
1386 FALSE
), /* pcrel_offset */
1388 /* No overflow check version of BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G1. */
1389 HOWTO64 (AARCH64_R (TLSLD_MOVW_DTPREL_G1_NC
), /* type */
1390 16, /* rightshift */
1391 2, /* size (0 = byte, 1 = short, 2 = long) */
1393 FALSE
, /* pc_relative */
1395 complain_overflow_dont
, /* complain_on_overflow */
1396 bfd_elf_generic_reloc
, /* special_function */
1397 AARCH64_R_STR (TLSLD_MOVW_DTPREL_G1_NC
), /* name */
1398 FALSE
, /* partial_inplace */
1399 0xffff, /* src_mask */
1400 0xffff, /* dst_mask */
1401 FALSE
), /* pcrel_offset */
1403 /* MOVZ: bit[47:32] of byte offset to module TLS base address. */
1404 HOWTO64 (AARCH64_R (TLSLD_MOVW_DTPREL_G2
), /* type */
1405 32, /* rightshift */
1406 2, /* size (0 = byte, 1 = short, 2 = long) */
1408 FALSE
, /* pc_relative */
1410 complain_overflow_unsigned
, /* complain_on_overflow */
1411 bfd_elf_generic_reloc
, /* special_function */
1412 AARCH64_R_STR (TLSLD_MOVW_DTPREL_G2
), /* name */
1413 FALSE
, /* partial_inplace */
1414 0xffff, /* src_mask */
1415 0xffff, /* dst_mask */
1416 FALSE
), /* pcrel_offset */
1418 HOWTO64 (AARCH64_R (TLSLE_MOVW_TPREL_G2
), /* type */
1419 32, /* rightshift */
1420 2, /* size (0 = byte, 1 = short, 2 = long) */
1422 FALSE
, /* pc_relative */
1424 complain_overflow_unsigned
, /* complain_on_overflow */
1425 bfd_elf_generic_reloc
, /* special_function */
1426 AARCH64_R_STR (TLSLE_MOVW_TPREL_G2
), /* name */
1427 FALSE
, /* partial_inplace */
1428 0xffff, /* src_mask */
1429 0xffff, /* dst_mask */
1430 FALSE
), /* pcrel_offset */
1432 HOWTO (AARCH64_R (TLSLE_MOVW_TPREL_G1
), /* type */
1433 16, /* rightshift */
1434 2, /* size (0 = byte, 1 = short, 2 = long) */
1436 FALSE
, /* pc_relative */
1438 complain_overflow_dont
, /* complain_on_overflow */
1439 bfd_elf_generic_reloc
, /* special_function */
1440 AARCH64_R_STR (TLSLE_MOVW_TPREL_G1
), /* name */
1441 FALSE
, /* partial_inplace */
1442 0xffff, /* src_mask */
1443 0xffff, /* dst_mask */
1444 FALSE
), /* pcrel_offset */
1446 HOWTO64 (AARCH64_R (TLSLE_MOVW_TPREL_G1_NC
), /* type */
1447 16, /* rightshift */
1448 2, /* size (0 = byte, 1 = short, 2 = long) */
1450 FALSE
, /* pc_relative */
1452 complain_overflow_dont
, /* complain_on_overflow */
1453 bfd_elf_generic_reloc
, /* special_function */
1454 AARCH64_R_STR (TLSLE_MOVW_TPREL_G1_NC
), /* name */
1455 FALSE
, /* partial_inplace */
1456 0xffff, /* src_mask */
1457 0xffff, /* dst_mask */
1458 FALSE
), /* pcrel_offset */
1460 HOWTO (AARCH64_R (TLSLE_MOVW_TPREL_G0
), /* type */
1462 2, /* size (0 = byte, 1 = short, 2 = long) */
1464 FALSE
, /* pc_relative */
1466 complain_overflow_dont
, /* complain_on_overflow */
1467 bfd_elf_generic_reloc
, /* special_function */
1468 AARCH64_R_STR (TLSLE_MOVW_TPREL_G0
), /* name */
1469 FALSE
, /* partial_inplace */
1470 0xffff, /* src_mask */
1471 0xffff, /* dst_mask */
1472 FALSE
), /* pcrel_offset */
1474 HOWTO (AARCH64_R (TLSLE_MOVW_TPREL_G0_NC
), /* type */
1476 2, /* size (0 = byte, 1 = short, 2 = long) */
1478 FALSE
, /* pc_relative */
1480 complain_overflow_dont
, /* complain_on_overflow */
1481 bfd_elf_generic_reloc
, /* special_function */
1482 AARCH64_R_STR (TLSLE_MOVW_TPREL_G0_NC
), /* name */
1483 FALSE
, /* partial_inplace */
1484 0xffff, /* src_mask */
1485 0xffff, /* dst_mask */
1486 FALSE
), /* pcrel_offset */
1488 HOWTO (AARCH64_R (TLSLE_ADD_TPREL_HI12
), /* type */
1489 12, /* rightshift */
1490 2, /* size (0 = byte, 1 = short, 2 = long) */
1492 FALSE
, /* pc_relative */
1494 complain_overflow_unsigned
, /* complain_on_overflow */
1495 bfd_elf_generic_reloc
, /* special_function */
1496 AARCH64_R_STR (TLSLE_ADD_TPREL_HI12
), /* name */
1497 FALSE
, /* partial_inplace */
1498 0xfff, /* src_mask */
1499 0xfff, /* dst_mask */
1500 FALSE
), /* pcrel_offset */
1502 HOWTO (AARCH64_R (TLSLE_ADD_TPREL_LO12
), /* type */
1504 2, /* size (0 = byte, 1 = short, 2 = long) */
1506 FALSE
, /* pc_relative */
1508 complain_overflow_unsigned
, /* complain_on_overflow */
1509 bfd_elf_generic_reloc
, /* special_function */
1510 AARCH64_R_STR (TLSLE_ADD_TPREL_LO12
), /* name */
1511 FALSE
, /* partial_inplace */
1512 0xfff, /* src_mask */
1513 0xfff, /* dst_mask */
1514 FALSE
), /* pcrel_offset */
1516 HOWTO (AARCH64_R (TLSLE_ADD_TPREL_LO12_NC
), /* type */
1518 2, /* size (0 = byte, 1 = short, 2 = long) */
1520 FALSE
, /* pc_relative */
1522 complain_overflow_dont
, /* complain_on_overflow */
1523 bfd_elf_generic_reloc
, /* special_function */
1524 AARCH64_R_STR (TLSLE_ADD_TPREL_LO12_NC
), /* name */
1525 FALSE
, /* partial_inplace */
1526 0xfff, /* src_mask */
1527 0xfff, /* dst_mask */
1528 FALSE
), /* pcrel_offset */
1530 HOWTO (AARCH64_R (TLSDESC_LD_PREL19
), /* type */
1532 2, /* size (0 = byte, 1 = short, 2 = long) */
1534 TRUE
, /* pc_relative */
1536 complain_overflow_dont
, /* complain_on_overflow */
1537 bfd_elf_generic_reloc
, /* special_function */
1538 AARCH64_R_STR (TLSDESC_LD_PREL19
), /* name */
1539 FALSE
, /* partial_inplace */
1540 0x0ffffe0, /* src_mask */
1541 0x0ffffe0, /* dst_mask */
1542 TRUE
), /* pcrel_offset */
1544 HOWTO (AARCH64_R (TLSDESC_ADR_PREL21
), /* type */
1546 2, /* size (0 = byte, 1 = short, 2 = long) */
1548 TRUE
, /* pc_relative */
1550 complain_overflow_dont
, /* complain_on_overflow */
1551 bfd_elf_generic_reloc
, /* special_function */
1552 AARCH64_R_STR (TLSDESC_ADR_PREL21
), /* name */
1553 FALSE
, /* partial_inplace */
1554 0x1fffff, /* src_mask */
1555 0x1fffff, /* dst_mask */
1556 TRUE
), /* pcrel_offset */
1558 /* Get to the page for the GOT entry for the symbol
1559 (G(S) - P) using an ADRP instruction. */
1560 HOWTO (AARCH64_R (TLSDESC_ADR_PAGE21
), /* type */
1561 12, /* rightshift */
1562 2, /* size (0 = byte, 1 = short, 2 = long) */
1564 TRUE
, /* pc_relative */
1566 complain_overflow_dont
, /* complain_on_overflow */
1567 bfd_elf_generic_reloc
, /* special_function */
1568 AARCH64_R_STR (TLSDESC_ADR_PAGE21
), /* name */
1569 FALSE
, /* partial_inplace */
1570 0x1fffff, /* src_mask */
1571 0x1fffff, /* dst_mask */
1572 TRUE
), /* pcrel_offset */
1574 /* LD64: GOT offset G(S) & 0xff8. */
1575 HOWTO64 (AARCH64_R (TLSDESC_LD64_LO12
), /* type */
1577 2, /* size (0 = byte, 1 = short, 2 = long) */
1579 FALSE
, /* pc_relative */
1581 complain_overflow_dont
, /* complain_on_overflow */
1582 bfd_elf_generic_reloc
, /* special_function */
1583 AARCH64_R_STR (TLSDESC_LD64_LO12
), /* name */
1584 FALSE
, /* partial_inplace */
1585 0xff8, /* src_mask */
1586 0xff8, /* dst_mask */
1587 FALSE
), /* pcrel_offset */
1589 /* LD32: GOT offset G(S) & 0xffc. */
1590 HOWTO32 (AARCH64_R (TLSDESC_LD32_LO12_NC
), /* type */
1592 2, /* size (0 = byte, 1 = short, 2 = long) */
1594 FALSE
, /* pc_relative */
1596 complain_overflow_dont
, /* complain_on_overflow */
1597 bfd_elf_generic_reloc
, /* special_function */
1598 AARCH64_R_STR (TLSDESC_LD32_LO12_NC
), /* name */
1599 FALSE
, /* partial_inplace */
1600 0xffc, /* src_mask */
1601 0xffc, /* dst_mask */
1602 FALSE
), /* pcrel_offset */
1604 /* ADD: GOT offset G(S) & 0xfff. */
1605 HOWTO (AARCH64_R (TLSDESC_ADD_LO12
), /* type */
1607 2, /* size (0 = byte, 1 = short, 2 = long) */
1609 FALSE
, /* pc_relative */
1611 complain_overflow_dont
,/* complain_on_overflow */
1612 bfd_elf_generic_reloc
, /* special_function */
1613 AARCH64_R_STR (TLSDESC_ADD_LO12
), /* name */
1614 FALSE
, /* partial_inplace */
1615 0xfff, /* src_mask */
1616 0xfff, /* dst_mask */
1617 FALSE
), /* pcrel_offset */
1619 HOWTO64 (AARCH64_R (TLSDESC_OFF_G1
), /* type */
1620 16, /* rightshift */
1621 2, /* size (0 = byte, 1 = short, 2 = long) */
1623 FALSE
, /* pc_relative */
1625 complain_overflow_unsigned
, /* complain_on_overflow */
1626 bfd_elf_generic_reloc
, /* special_function */
1627 AARCH64_R_STR (TLSDESC_OFF_G1
), /* name */
1628 FALSE
, /* partial_inplace */
1629 0xffff, /* src_mask */
1630 0xffff, /* dst_mask */
1631 FALSE
), /* pcrel_offset */
1633 HOWTO64 (AARCH64_R (TLSDESC_OFF_G0_NC
), /* type */
1635 2, /* size (0 = byte, 1 = short, 2 = long) */
1637 FALSE
, /* pc_relative */
1639 complain_overflow_dont
, /* complain_on_overflow */
1640 bfd_elf_generic_reloc
, /* special_function */
1641 AARCH64_R_STR (TLSDESC_OFF_G0_NC
), /* name */
1642 FALSE
, /* partial_inplace */
1643 0xffff, /* src_mask */
1644 0xffff, /* dst_mask */
1645 FALSE
), /* pcrel_offset */
1647 HOWTO64 (AARCH64_R (TLSDESC_LDR
), /* type */
1649 2, /* size (0 = byte, 1 = short, 2 = long) */
1651 FALSE
, /* pc_relative */
1653 complain_overflow_dont
, /* complain_on_overflow */
1654 bfd_elf_generic_reloc
, /* special_function */
1655 AARCH64_R_STR (TLSDESC_LDR
), /* name */
1656 FALSE
, /* partial_inplace */
1659 FALSE
), /* pcrel_offset */
1661 HOWTO64 (AARCH64_R (TLSDESC_ADD
), /* type */
1663 2, /* size (0 = byte, 1 = short, 2 = long) */
1665 FALSE
, /* pc_relative */
1667 complain_overflow_dont
, /* complain_on_overflow */
1668 bfd_elf_generic_reloc
, /* special_function */
1669 AARCH64_R_STR (TLSDESC_ADD
), /* name */
1670 FALSE
, /* partial_inplace */
1673 FALSE
), /* pcrel_offset */
1675 HOWTO (AARCH64_R (TLSDESC_CALL
), /* type */
1677 2, /* size (0 = byte, 1 = short, 2 = long) */
1679 FALSE
, /* pc_relative */
1681 complain_overflow_dont
, /* complain_on_overflow */
1682 bfd_elf_generic_reloc
, /* special_function */
1683 AARCH64_R_STR (TLSDESC_CALL
), /* name */
1684 FALSE
, /* partial_inplace */
1687 FALSE
), /* pcrel_offset */
1689 HOWTO (AARCH64_R (COPY
), /* type */
1691 2, /* size (0 = byte, 1 = short, 2 = long) */
1693 FALSE
, /* pc_relative */
1695 complain_overflow_bitfield
, /* complain_on_overflow */
1696 bfd_elf_generic_reloc
, /* special_function */
1697 AARCH64_R_STR (COPY
), /* name */
1698 TRUE
, /* partial_inplace */
1699 0xffffffff, /* src_mask */
1700 0xffffffff, /* dst_mask */
1701 FALSE
), /* pcrel_offset */
1703 HOWTO (AARCH64_R (GLOB_DAT
), /* type */
1705 2, /* size (0 = byte, 1 = short, 2 = long) */
1707 FALSE
, /* pc_relative */
1709 complain_overflow_bitfield
, /* complain_on_overflow */
1710 bfd_elf_generic_reloc
, /* special_function */
1711 AARCH64_R_STR (GLOB_DAT
), /* name */
1712 TRUE
, /* partial_inplace */
1713 0xffffffff, /* src_mask */
1714 0xffffffff, /* dst_mask */
1715 FALSE
), /* pcrel_offset */
1717 HOWTO (AARCH64_R (JUMP_SLOT
), /* type */
1719 2, /* size (0 = byte, 1 = short, 2 = long) */
1721 FALSE
, /* pc_relative */
1723 complain_overflow_bitfield
, /* complain_on_overflow */
1724 bfd_elf_generic_reloc
, /* special_function */
1725 AARCH64_R_STR (JUMP_SLOT
), /* name */
1726 TRUE
, /* partial_inplace */
1727 0xffffffff, /* src_mask */
1728 0xffffffff, /* dst_mask */
1729 FALSE
), /* pcrel_offset */
1731 HOWTO (AARCH64_R (RELATIVE
), /* type */
1733 2, /* size (0 = byte, 1 = short, 2 = long) */
1735 FALSE
, /* pc_relative */
1737 complain_overflow_bitfield
, /* complain_on_overflow */
1738 bfd_elf_generic_reloc
, /* special_function */
1739 AARCH64_R_STR (RELATIVE
), /* name */
1740 TRUE
, /* partial_inplace */
1741 ALL_ONES
, /* src_mask */
1742 ALL_ONES
, /* dst_mask */
1743 FALSE
), /* pcrel_offset */
1745 HOWTO (AARCH64_R (TLS_DTPMOD
), /* type */
1747 2, /* size (0 = byte, 1 = short, 2 = long) */
1749 FALSE
, /* pc_relative */
1751 complain_overflow_dont
, /* complain_on_overflow */
1752 bfd_elf_generic_reloc
, /* special_function */
1754 AARCH64_R_STR (TLS_DTPMOD64
), /* name */
1756 AARCH64_R_STR (TLS_DTPMOD
), /* name */
1758 FALSE
, /* partial_inplace */
1760 ALL_ONES
, /* dst_mask */
1761 FALSE
), /* pc_reloffset */
1763 HOWTO (AARCH64_R (TLS_DTPREL
), /* type */
1765 2, /* size (0 = byte, 1 = short, 2 = long) */
1767 FALSE
, /* pc_relative */
1769 complain_overflow_dont
, /* complain_on_overflow */
1770 bfd_elf_generic_reloc
, /* special_function */
1772 AARCH64_R_STR (TLS_DTPREL64
), /* name */
1774 AARCH64_R_STR (TLS_DTPREL
), /* name */
1776 FALSE
, /* partial_inplace */
1778 ALL_ONES
, /* dst_mask */
1779 FALSE
), /* pcrel_offset */
1781 HOWTO (AARCH64_R (TLS_TPREL
), /* type */
1783 2, /* size (0 = byte, 1 = short, 2 = long) */
1785 FALSE
, /* pc_relative */
1787 complain_overflow_dont
, /* complain_on_overflow */
1788 bfd_elf_generic_reloc
, /* special_function */
1790 AARCH64_R_STR (TLS_TPREL64
), /* name */
1792 AARCH64_R_STR (TLS_TPREL
), /* name */
1794 FALSE
, /* partial_inplace */
1796 ALL_ONES
, /* dst_mask */
1797 FALSE
), /* pcrel_offset */
1799 HOWTO (AARCH64_R (TLSDESC
), /* type */
1801 2, /* size (0 = byte, 1 = short, 2 = long) */
1803 FALSE
, /* pc_relative */
1805 complain_overflow_dont
, /* complain_on_overflow */
1806 bfd_elf_generic_reloc
, /* special_function */
1807 AARCH64_R_STR (TLSDESC
), /* name */
1808 FALSE
, /* partial_inplace */
1810 ALL_ONES
, /* dst_mask */
1811 FALSE
), /* pcrel_offset */
1813 HOWTO (AARCH64_R (IRELATIVE
), /* type */
1815 2, /* size (0 = byte, 1 = short, 2 = long) */
1817 FALSE
, /* pc_relative */
1819 complain_overflow_bitfield
, /* complain_on_overflow */
1820 bfd_elf_generic_reloc
, /* special_function */
1821 AARCH64_R_STR (IRELATIVE
), /* name */
1822 FALSE
, /* partial_inplace */
1824 ALL_ONES
, /* dst_mask */
1825 FALSE
), /* pcrel_offset */
1830 static reloc_howto_type elfNN_aarch64_howto_none
=
1831 HOWTO (R_AARCH64_NONE
, /* type */
1833 3, /* size (0 = byte, 1 = short, 2 = long) */
1835 FALSE
, /* pc_relative */
1837 complain_overflow_dont
,/* complain_on_overflow */
1838 bfd_elf_generic_reloc
, /* special_function */
1839 "R_AARCH64_NONE", /* name */
1840 FALSE
, /* partial_inplace */
1843 FALSE
); /* pcrel_offset */
1845 /* Given HOWTO, return the bfd internal relocation enumerator. */
1847 static bfd_reloc_code_real_type
1848 elfNN_aarch64_bfd_reloc_from_howto (reloc_howto_type
*howto
)
1851 = (int) ARRAY_SIZE (elfNN_aarch64_howto_table
);
1852 const ptrdiff_t offset
1853 = howto
- elfNN_aarch64_howto_table
;
1855 if (offset
> 0 && offset
< size
- 1)
1856 return BFD_RELOC_AARCH64_RELOC_START
+ offset
;
1858 if (howto
== &elfNN_aarch64_howto_none
)
1859 return BFD_RELOC_AARCH64_NONE
;
1861 return BFD_RELOC_AARCH64_RELOC_START
;
1864 /* Given R_TYPE, return the bfd internal relocation enumerator. */
1866 static bfd_reloc_code_real_type
1867 elfNN_aarch64_bfd_reloc_from_type (unsigned int r_type
)
1869 static bfd_boolean initialized_p
= FALSE
;
1870 /* Indexed by R_TYPE, values are offsets in the howto_table. */
1871 static unsigned int offsets
[R_AARCH64_end
];
1873 if (initialized_p
== FALSE
)
1877 for (i
= 1; i
< ARRAY_SIZE (elfNN_aarch64_howto_table
) - 1; ++i
)
1878 if (elfNN_aarch64_howto_table
[i
].type
!= 0)
1879 offsets
[elfNN_aarch64_howto_table
[i
].type
] = i
;
1881 initialized_p
= TRUE
;
1884 if (r_type
== R_AARCH64_NONE
|| r_type
== R_AARCH64_NULL
)
1885 return BFD_RELOC_AARCH64_NONE
;
1887 /* PR 17512: file: b371e70a. */
1888 if (r_type
>= R_AARCH64_end
)
1890 _bfd_error_handler (_("Invalid AArch64 reloc number: %d"), r_type
);
1891 bfd_set_error (bfd_error_bad_value
);
1892 return BFD_RELOC_AARCH64_NONE
;
1895 return BFD_RELOC_AARCH64_RELOC_START
+ offsets
[r_type
];
1898 struct elf_aarch64_reloc_map
1900 bfd_reloc_code_real_type from
;
1901 bfd_reloc_code_real_type to
;
1904 /* Map bfd generic reloc to AArch64-specific reloc. */
1905 static const struct elf_aarch64_reloc_map elf_aarch64_reloc_map
[] =
1907 {BFD_RELOC_NONE
, BFD_RELOC_AARCH64_NONE
},
1909 /* Basic data relocations. */
1910 {BFD_RELOC_CTOR
, BFD_RELOC_AARCH64_NN
},
1911 {BFD_RELOC_64
, BFD_RELOC_AARCH64_64
},
1912 {BFD_RELOC_32
, BFD_RELOC_AARCH64_32
},
1913 {BFD_RELOC_16
, BFD_RELOC_AARCH64_16
},
1914 {BFD_RELOC_64_PCREL
, BFD_RELOC_AARCH64_64_PCREL
},
1915 {BFD_RELOC_32_PCREL
, BFD_RELOC_AARCH64_32_PCREL
},
1916 {BFD_RELOC_16_PCREL
, BFD_RELOC_AARCH64_16_PCREL
},
1919 /* Given the bfd internal relocation enumerator in CODE, return the
1920 corresponding howto entry. */
1922 static reloc_howto_type
*
1923 elfNN_aarch64_howto_from_bfd_reloc (bfd_reloc_code_real_type code
)
1927 /* Convert bfd generic reloc to AArch64-specific reloc. */
1928 if (code
< BFD_RELOC_AARCH64_RELOC_START
1929 || code
> BFD_RELOC_AARCH64_RELOC_END
)
1930 for (i
= 0; i
< ARRAY_SIZE (elf_aarch64_reloc_map
); i
++)
1931 if (elf_aarch64_reloc_map
[i
].from
== code
)
1933 code
= elf_aarch64_reloc_map
[i
].to
;
1937 if (code
> BFD_RELOC_AARCH64_RELOC_START
1938 && code
< BFD_RELOC_AARCH64_RELOC_END
)
1939 if (elfNN_aarch64_howto_table
[code
- BFD_RELOC_AARCH64_RELOC_START
].type
)
1940 return &elfNN_aarch64_howto_table
[code
- BFD_RELOC_AARCH64_RELOC_START
];
1942 if (code
== BFD_RELOC_AARCH64_NONE
)
1943 return &elfNN_aarch64_howto_none
;
1948 static reloc_howto_type
*
1949 elfNN_aarch64_howto_from_type (unsigned int r_type
)
1951 bfd_reloc_code_real_type val
;
1952 reloc_howto_type
*howto
;
1957 bfd_set_error (bfd_error_bad_value
);
1962 if (r_type
== R_AARCH64_NONE
)
1963 return &elfNN_aarch64_howto_none
;
1965 val
= elfNN_aarch64_bfd_reloc_from_type (r_type
);
1966 howto
= elfNN_aarch64_howto_from_bfd_reloc (val
);
1971 bfd_set_error (bfd_error_bad_value
);
1976 elfNN_aarch64_info_to_howto (bfd
*abfd ATTRIBUTE_UNUSED
, arelent
*bfd_reloc
,
1977 Elf_Internal_Rela
*elf_reloc
)
1979 unsigned int r_type
;
1981 r_type
= ELFNN_R_TYPE (elf_reloc
->r_info
);
1982 bfd_reloc
->howto
= elfNN_aarch64_howto_from_type (r_type
);
1985 static reloc_howto_type
*
1986 elfNN_aarch64_reloc_type_lookup (bfd
*abfd ATTRIBUTE_UNUSED
,
1987 bfd_reloc_code_real_type code
)
1989 reloc_howto_type
*howto
= elfNN_aarch64_howto_from_bfd_reloc (code
);
1994 bfd_set_error (bfd_error_bad_value
);
1998 static reloc_howto_type
*
1999 elfNN_aarch64_reloc_name_lookup (bfd
*abfd ATTRIBUTE_UNUSED
,
2004 for (i
= 1; i
< ARRAY_SIZE (elfNN_aarch64_howto_table
) - 1; ++i
)
2005 if (elfNN_aarch64_howto_table
[i
].name
!= NULL
2006 && strcasecmp (elfNN_aarch64_howto_table
[i
].name
, r_name
) == 0)
2007 return &elfNN_aarch64_howto_table
[i
];
2012 #define TARGET_LITTLE_SYM aarch64_elfNN_le_vec
2013 #define TARGET_LITTLE_NAME "elfNN-littleaarch64"
2014 #define TARGET_BIG_SYM aarch64_elfNN_be_vec
2015 #define TARGET_BIG_NAME "elfNN-bigaarch64"
2017 /* The linker script knows the section names for placement.
2018 The entry_names are used to do simple name mangling on the stubs.
2019 Given a function name, and its type, the stub can be found. The
2020 name can be changed. The only requirement is the %s be present. */
2021 #define STUB_ENTRY_NAME "__%s_veneer"
2023 /* The name of the dynamic interpreter. This is put in the .interp
2025 #define ELF_DYNAMIC_INTERPRETER "/lib/ld.so.1"
2027 #define AARCH64_MAX_FWD_BRANCH_OFFSET \
2028 (((1 << 25) - 1) << 2)
2029 #define AARCH64_MAX_BWD_BRANCH_OFFSET \
2032 #define AARCH64_MAX_ADRP_IMM ((1 << 20) - 1)
2033 #define AARCH64_MIN_ADRP_IMM (-(1 << 20))
2036 aarch64_valid_for_adrp_p (bfd_vma value
, bfd_vma place
)
2038 bfd_signed_vma offset
= (bfd_signed_vma
) (PG (value
) - PG (place
)) >> 12;
2039 return offset
<= AARCH64_MAX_ADRP_IMM
&& offset
>= AARCH64_MIN_ADRP_IMM
;
2043 aarch64_valid_branch_p (bfd_vma value
, bfd_vma place
)
2045 bfd_signed_vma offset
= (bfd_signed_vma
) (value
- place
);
2046 return (offset
<= AARCH64_MAX_FWD_BRANCH_OFFSET
2047 && offset
>= AARCH64_MAX_BWD_BRANCH_OFFSET
);
2050 static const uint32_t aarch64_adrp_branch_stub
[] =
2052 0x90000010, /* adrp ip0, X */
2053 /* R_AARCH64_ADR_HI21_PCREL(X) */
2054 0x91000210, /* add ip0, ip0, :lo12:X */
2055 /* R_AARCH64_ADD_ABS_LO12_NC(X) */
2056 0xd61f0200, /* br ip0 */
2059 static const uint32_t aarch64_long_branch_stub
[] =
2062 0x58000090, /* ldr ip0, 1f */
2064 0x18000090, /* ldr wip0, 1f */
2066 0x10000011, /* adr ip1, #0 */
2067 0x8b110210, /* add ip0, ip0, ip1 */
2068 0xd61f0200, /* br ip0 */
2069 0x00000000, /* 1: .xword or .word
2070 R_AARCH64_PRELNN(X) + 12
2075 static const uint32_t aarch64_erratum_835769_stub
[] =
2077 0x00000000, /* Placeholder for multiply accumulate. */
2078 0x14000000, /* b <label> */
2081 static const uint32_t aarch64_erratum_843419_stub
[] =
2083 0x00000000, /* Placeholder for LDR instruction. */
2084 0x14000000, /* b <label> */
2087 /* Section name for stubs is the associated section name plus this
2089 #define STUB_SUFFIX ".stub"
2091 enum elf_aarch64_stub_type
2094 aarch64_stub_adrp_branch
,
2095 aarch64_stub_long_branch
,
2096 aarch64_stub_erratum_835769_veneer
,
2097 aarch64_stub_erratum_843419_veneer
,
2100 struct elf_aarch64_stub_hash_entry
2102 /* Base hash table entry structure. */
2103 struct bfd_hash_entry root
;
2105 /* The stub section. */
2108 /* Offset within stub_sec of the beginning of this stub. */
2109 bfd_vma stub_offset
;
2111 /* Given the symbol's value and its section we can determine its final
2112 value when building the stubs (so the stub knows where to jump). */
2113 bfd_vma target_value
;
2114 asection
*target_section
;
2116 enum elf_aarch64_stub_type stub_type
;
2118 /* The symbol table entry, if any, that this was derived from. */
2119 struct elf_aarch64_link_hash_entry
*h
;
2121 /* Destination symbol type */
2122 unsigned char st_type
;
2124 /* Where this stub is being called from, or, in the case of combined
2125 stub sections, the first input section in the group. */
2128 /* The name for the local symbol at the start of this stub. The
2129 stub name in the hash table has to be unique; this does not, so
2130 it can be friendlier. */
2133 /* The instruction which caused this stub to be generated (only valid for
2134 erratum 835769 workaround stubs at present). */
2135 uint32_t veneered_insn
;
2137 /* In an erratum 843419 workaround stub, the ADRP instruction offset. */
2138 bfd_vma adrp_offset
;
2141 /* Used to build a map of a section. This is required for mixed-endian
2144 typedef struct elf_elf_section_map
2149 elf_aarch64_section_map
;
2152 typedef struct _aarch64_elf_section_data
2154 struct bfd_elf_section_data elf
;
2155 unsigned int mapcount
;
2156 unsigned int mapsize
;
2157 elf_aarch64_section_map
*map
;
2159 _aarch64_elf_section_data
;
2161 #define elf_aarch64_section_data(sec) \
2162 ((_aarch64_elf_section_data *) elf_section_data (sec))
2164 /* The size of the thread control block which is defined to be two pointers. */
2165 #define TCB_SIZE (ARCH_SIZE/8)*2
2167 struct elf_aarch64_local_symbol
2169 unsigned int got_type
;
2170 bfd_signed_vma got_refcount
;
2173 /* Offset of the GOTPLT entry reserved for the TLS descriptor. The
2174 offset is from the end of the jump table and reserved entries
2177 The magic value (bfd_vma) -1 indicates that an offset has not be
2179 bfd_vma tlsdesc_got_jump_table_offset
;
2182 struct elf_aarch64_obj_tdata
2184 struct elf_obj_tdata root
;
2186 /* local symbol descriptors */
2187 struct elf_aarch64_local_symbol
*locals
;
2189 /* Zero to warn when linking objects with incompatible enum sizes. */
2190 int no_enum_size_warning
;
2192 /* Zero to warn when linking objects with incompatible wchar_t sizes. */
2193 int no_wchar_size_warning
;
2196 #define elf_aarch64_tdata(bfd) \
2197 ((struct elf_aarch64_obj_tdata *) (bfd)->tdata.any)
2199 #define elf_aarch64_locals(bfd) (elf_aarch64_tdata (bfd)->locals)
2201 #define is_aarch64_elf(bfd) \
2202 (bfd_get_flavour (bfd) == bfd_target_elf_flavour \
2203 && elf_tdata (bfd) != NULL \
2204 && elf_object_id (bfd) == AARCH64_ELF_DATA)
2207 elfNN_aarch64_mkobject (bfd
*abfd
)
2209 return bfd_elf_allocate_object (abfd
, sizeof (struct elf_aarch64_obj_tdata
),
2213 #define elf_aarch64_hash_entry(ent) \
2214 ((struct elf_aarch64_link_hash_entry *)(ent))
2216 #define GOT_UNKNOWN 0
2217 #define GOT_NORMAL 1
2218 #define GOT_TLS_GD 2
2219 #define GOT_TLS_IE 4
2220 #define GOT_TLSDESC_GD 8
2222 #define GOT_TLS_GD_ANY_P(type) ((type & GOT_TLS_GD) || (type & GOT_TLSDESC_GD))
2224 /* AArch64 ELF linker hash entry. */
2225 struct elf_aarch64_link_hash_entry
2227 struct elf_link_hash_entry root
;
2229 /* Track dynamic relocs copied for this symbol. */
2230 struct elf_dyn_relocs
*dyn_relocs
;
2232 /* Since PLT entries have variable size, we need to record the
2233 index into .got.plt instead of recomputing it from the PLT
2235 bfd_signed_vma plt_got_offset
;
2237 /* Bit mask representing the type of GOT entry(s) if any required by
2239 unsigned int got_type
;
2241 /* A pointer to the most recently used stub hash entry against this
2243 struct elf_aarch64_stub_hash_entry
*stub_cache
;
2245 /* Offset of the GOTPLT entry reserved for the TLS descriptor. The offset
2246 is from the end of the jump table and reserved entries within the PLTGOT.
2248 The magic value (bfd_vma) -1 indicates that an offset has not
2250 bfd_vma tlsdesc_got_jump_table_offset
;
2254 elfNN_aarch64_symbol_got_type (struct elf_link_hash_entry
*h
,
2256 unsigned long r_symndx
)
2259 return elf_aarch64_hash_entry (h
)->got_type
;
2261 if (! elf_aarch64_locals (abfd
))
2264 return elf_aarch64_locals (abfd
)[r_symndx
].got_type
;
2267 /* Get the AArch64 elf linker hash table from a link_info structure. */
2268 #define elf_aarch64_hash_table(info) \
2269 ((struct elf_aarch64_link_hash_table *) ((info)->hash))
2271 #define aarch64_stub_hash_lookup(table, string, create, copy) \
2272 ((struct elf_aarch64_stub_hash_entry *) \
2273 bfd_hash_lookup ((table), (string), (create), (copy)))
2275 /* AArch64 ELF linker hash table. */
2276 struct elf_aarch64_link_hash_table
2278 /* The main hash table. */
2279 struct elf_link_hash_table root
;
2281 /* Nonzero to force PIC branch veneers. */
2284 /* Fix erratum 835769. */
2285 int fix_erratum_835769
;
2287 /* Fix erratum 843419. */
2288 int fix_erratum_843419
;
2290 /* Enable ADRP->ADR rewrite for erratum 843419 workaround. */
2291 int fix_erratum_843419_adr
;
2293 /* Don't apply link-time values for dynamic relocations. */
2294 int no_apply_dynamic_relocs
;
2296 /* The number of bytes in the initial entry in the PLT. */
2297 bfd_size_type plt_header_size
;
2299 /* The number of bytes in the subsequent PLT etries. */
2300 bfd_size_type plt_entry_size
;
2302 /* Small local sym cache. */
2303 struct sym_cache sym_cache
;
2305 /* For convenience in allocate_dynrelocs. */
2308 /* The amount of space used by the reserved portion of the sgotplt
2309 section, plus whatever space is used by the jump slots. */
2310 bfd_vma sgotplt_jump_table_size
;
2312 /* The stub hash table. */
2313 struct bfd_hash_table stub_hash_table
;
2315 /* Linker stub bfd. */
2318 /* Linker call-backs. */
2319 asection
*(*add_stub_section
) (const char *, asection
*);
2320 void (*layout_sections_again
) (void);
2322 /* Array to keep track of which stub sections have been created, and
2323 information on stub grouping. */
2326 /* This is the section to which stubs in the group will be
2329 /* The stub section. */
2333 /* Assorted information used by elfNN_aarch64_size_stubs. */
2334 unsigned int bfd_count
;
2335 unsigned int top_index
;
2336 asection
**input_list
;
2338 /* The offset into splt of the PLT entry for the TLS descriptor
2339 resolver. Special values are 0, if not necessary (or not found
2340 to be necessary yet), and -1 if needed but not determined
2342 bfd_vma tlsdesc_plt
;
2344 /* The GOT offset for the lazy trampoline. Communicated to the
2345 loader via DT_TLSDESC_GOT. The magic value (bfd_vma) -1
2346 indicates an offset is not allocated. */
2347 bfd_vma dt_tlsdesc_got
;
2349 /* Used by local STT_GNU_IFUNC symbols. */
2350 htab_t loc_hash_table
;
2351 void * loc_hash_memory
;
2354 /* Create an entry in an AArch64 ELF linker hash table. */
2356 static struct bfd_hash_entry
*
2357 elfNN_aarch64_link_hash_newfunc (struct bfd_hash_entry
*entry
,
2358 struct bfd_hash_table
*table
,
2361 struct elf_aarch64_link_hash_entry
*ret
=
2362 (struct elf_aarch64_link_hash_entry
*) entry
;
2364 /* Allocate the structure if it has not already been allocated by a
2367 ret
= bfd_hash_allocate (table
,
2368 sizeof (struct elf_aarch64_link_hash_entry
));
2370 return (struct bfd_hash_entry
*) ret
;
2372 /* Call the allocation method of the superclass. */
2373 ret
= ((struct elf_aarch64_link_hash_entry
*)
2374 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry
*) ret
,
2378 ret
->dyn_relocs
= NULL
;
2379 ret
->got_type
= GOT_UNKNOWN
;
2380 ret
->plt_got_offset
= (bfd_vma
) - 1;
2381 ret
->stub_cache
= NULL
;
2382 ret
->tlsdesc_got_jump_table_offset
= (bfd_vma
) - 1;
2385 return (struct bfd_hash_entry
*) ret
;
2388 /* Initialize an entry in the stub hash table. */
2390 static struct bfd_hash_entry
*
2391 stub_hash_newfunc (struct bfd_hash_entry
*entry
,
2392 struct bfd_hash_table
*table
, const char *string
)
2394 /* Allocate the structure if it has not already been allocated by a
2398 entry
= bfd_hash_allocate (table
,
2400 elf_aarch64_stub_hash_entry
));
2405 /* Call the allocation method of the superclass. */
2406 entry
= bfd_hash_newfunc (entry
, table
, string
);
2409 struct elf_aarch64_stub_hash_entry
*eh
;
2411 /* Initialize the local fields. */
2412 eh
= (struct elf_aarch64_stub_hash_entry
*) entry
;
2413 eh
->adrp_offset
= 0;
2414 eh
->stub_sec
= NULL
;
2415 eh
->stub_offset
= 0;
2416 eh
->target_value
= 0;
2417 eh
->target_section
= NULL
;
2418 eh
->stub_type
= aarch64_stub_none
;
2426 /* Compute a hash of a local hash entry. We use elf_link_hash_entry
2427 for local symbol so that we can handle local STT_GNU_IFUNC symbols
2428 as global symbol. We reuse indx and dynstr_index for local symbol
2429 hash since they aren't used by global symbols in this backend. */
2432 elfNN_aarch64_local_htab_hash (const void *ptr
)
2434 struct elf_link_hash_entry
*h
2435 = (struct elf_link_hash_entry
*) ptr
;
2436 return ELF_LOCAL_SYMBOL_HASH (h
->indx
, h
->dynstr_index
);
2439 /* Compare local hash entries. */
2442 elfNN_aarch64_local_htab_eq (const void *ptr1
, const void *ptr2
)
2444 struct elf_link_hash_entry
*h1
2445 = (struct elf_link_hash_entry
*) ptr1
;
2446 struct elf_link_hash_entry
*h2
2447 = (struct elf_link_hash_entry
*) ptr2
;
2449 return h1
->indx
== h2
->indx
&& h1
->dynstr_index
== h2
->dynstr_index
;
2452 /* Find and/or create a hash entry for local symbol. */
2454 static struct elf_link_hash_entry
*
2455 elfNN_aarch64_get_local_sym_hash (struct elf_aarch64_link_hash_table
*htab
,
2456 bfd
*abfd
, const Elf_Internal_Rela
*rel
,
2459 struct elf_aarch64_link_hash_entry e
, *ret
;
2460 asection
*sec
= abfd
->sections
;
2461 hashval_t h
= ELF_LOCAL_SYMBOL_HASH (sec
->id
,
2462 ELFNN_R_SYM (rel
->r_info
));
2465 e
.root
.indx
= sec
->id
;
2466 e
.root
.dynstr_index
= ELFNN_R_SYM (rel
->r_info
);
2467 slot
= htab_find_slot_with_hash (htab
->loc_hash_table
, &e
, h
,
2468 create
? INSERT
: NO_INSERT
);
2475 ret
= (struct elf_aarch64_link_hash_entry
*) *slot
;
2479 ret
= (struct elf_aarch64_link_hash_entry
*)
2480 objalloc_alloc ((struct objalloc
*) htab
->loc_hash_memory
,
2481 sizeof (struct elf_aarch64_link_hash_entry
));
2484 memset (ret
, 0, sizeof (*ret
));
2485 ret
->root
.indx
= sec
->id
;
2486 ret
->root
.dynstr_index
= ELFNN_R_SYM (rel
->r_info
);
2487 ret
->root
.dynindx
= -1;
2493 /* Copy the extra info we tack onto an elf_link_hash_entry. */
2496 elfNN_aarch64_copy_indirect_symbol (struct bfd_link_info
*info
,
2497 struct elf_link_hash_entry
*dir
,
2498 struct elf_link_hash_entry
*ind
)
2500 struct elf_aarch64_link_hash_entry
*edir
, *eind
;
2502 edir
= (struct elf_aarch64_link_hash_entry
*) dir
;
2503 eind
= (struct elf_aarch64_link_hash_entry
*) ind
;
2505 if (eind
->dyn_relocs
!= NULL
)
2507 if (edir
->dyn_relocs
!= NULL
)
2509 struct elf_dyn_relocs
**pp
;
2510 struct elf_dyn_relocs
*p
;
2512 /* Add reloc counts against the indirect sym to the direct sym
2513 list. Merge any entries against the same section. */
2514 for (pp
= &eind
->dyn_relocs
; (p
= *pp
) != NULL
;)
2516 struct elf_dyn_relocs
*q
;
2518 for (q
= edir
->dyn_relocs
; q
!= NULL
; q
= q
->next
)
2519 if (q
->sec
== p
->sec
)
2521 q
->pc_count
+= p
->pc_count
;
2522 q
->count
+= p
->count
;
2529 *pp
= edir
->dyn_relocs
;
2532 edir
->dyn_relocs
= eind
->dyn_relocs
;
2533 eind
->dyn_relocs
= NULL
;
2536 if (ind
->root
.type
== bfd_link_hash_indirect
)
2538 /* Copy over PLT info. */
2539 if (dir
->got
.refcount
<= 0)
2541 edir
->got_type
= eind
->got_type
;
2542 eind
->got_type
= GOT_UNKNOWN
;
2546 _bfd_elf_link_hash_copy_indirect (info
, dir
, ind
);
2549 /* Destroy an AArch64 elf linker hash table. */
2552 elfNN_aarch64_link_hash_table_free (bfd
*obfd
)
2554 struct elf_aarch64_link_hash_table
*ret
2555 = (struct elf_aarch64_link_hash_table
*) obfd
->link
.hash
;
2557 if (ret
->loc_hash_table
)
2558 htab_delete (ret
->loc_hash_table
);
2559 if (ret
->loc_hash_memory
)
2560 objalloc_free ((struct objalloc
*) ret
->loc_hash_memory
);
2562 bfd_hash_table_free (&ret
->stub_hash_table
);
2563 _bfd_elf_link_hash_table_free (obfd
);
2566 /* Create an AArch64 elf linker hash table. */
2568 static struct bfd_link_hash_table
*
2569 elfNN_aarch64_link_hash_table_create (bfd
*abfd
)
2571 struct elf_aarch64_link_hash_table
*ret
;
2572 bfd_size_type amt
= sizeof (struct elf_aarch64_link_hash_table
);
2574 ret
= bfd_zmalloc (amt
);
2578 if (!_bfd_elf_link_hash_table_init
2579 (&ret
->root
, abfd
, elfNN_aarch64_link_hash_newfunc
,
2580 sizeof (struct elf_aarch64_link_hash_entry
), AARCH64_ELF_DATA
))
2586 ret
->plt_header_size
= PLT_ENTRY_SIZE
;
2587 ret
->plt_entry_size
= PLT_SMALL_ENTRY_SIZE
;
2589 ret
->dt_tlsdesc_got
= (bfd_vma
) - 1;
2591 if (!bfd_hash_table_init (&ret
->stub_hash_table
, stub_hash_newfunc
,
2592 sizeof (struct elf_aarch64_stub_hash_entry
)))
2594 _bfd_elf_link_hash_table_free (abfd
);
2598 ret
->loc_hash_table
= htab_try_create (1024,
2599 elfNN_aarch64_local_htab_hash
,
2600 elfNN_aarch64_local_htab_eq
,
2602 ret
->loc_hash_memory
= objalloc_create ();
2603 if (!ret
->loc_hash_table
|| !ret
->loc_hash_memory
)
2605 elfNN_aarch64_link_hash_table_free (abfd
);
2608 ret
->root
.root
.hash_table_free
= elfNN_aarch64_link_hash_table_free
;
2610 return &ret
->root
.root
;
2614 aarch64_relocate (unsigned int r_type
, bfd
*input_bfd
, asection
*input_section
,
2615 bfd_vma offset
, bfd_vma value
)
2617 reloc_howto_type
*howto
;
2620 howto
= elfNN_aarch64_howto_from_type (r_type
);
2621 place
= (input_section
->output_section
->vma
+ input_section
->output_offset
2624 r_type
= elfNN_aarch64_bfd_reloc_from_type (r_type
);
2625 value
= _bfd_aarch64_elf_resolve_relocation (r_type
, place
, value
, 0, FALSE
);
2626 return _bfd_aarch64_elf_put_addend (input_bfd
,
2627 input_section
->contents
+ offset
, r_type
,
2631 static enum elf_aarch64_stub_type
2632 aarch64_select_branch_stub (bfd_vma value
, bfd_vma place
)
2634 if (aarch64_valid_for_adrp_p (value
, place
))
2635 return aarch64_stub_adrp_branch
;
2636 return aarch64_stub_long_branch
;
2639 /* Determine the type of stub needed, if any, for a call. */
2641 static enum elf_aarch64_stub_type
2642 aarch64_type_of_stub (asection
*input_sec
,
2643 const Elf_Internal_Rela
*rel
,
2645 unsigned char st_type
,
2646 bfd_vma destination
)
2649 bfd_signed_vma branch_offset
;
2650 unsigned int r_type
;
2651 enum elf_aarch64_stub_type stub_type
= aarch64_stub_none
;
2653 if (st_type
!= STT_FUNC
2654 && (sym_sec
== input_sec
))
2657 /* Determine where the call point is. */
2658 location
= (input_sec
->output_offset
2659 + input_sec
->output_section
->vma
+ rel
->r_offset
);
2661 branch_offset
= (bfd_signed_vma
) (destination
- location
);
2663 r_type
= ELFNN_R_TYPE (rel
->r_info
);
2665 /* We don't want to redirect any old unconditional jump in this way,
2666 only one which is being used for a sibcall, where it is
2667 acceptable for the IP0 and IP1 registers to be clobbered. */
2668 if ((r_type
== AARCH64_R (CALL26
) || r_type
== AARCH64_R (JUMP26
))
2669 && (branch_offset
> AARCH64_MAX_FWD_BRANCH_OFFSET
2670 || branch_offset
< AARCH64_MAX_BWD_BRANCH_OFFSET
))
2672 stub_type
= aarch64_stub_long_branch
;
2678 /* Build a name for an entry in the stub hash table. */
2681 elfNN_aarch64_stub_name (const asection
*input_section
,
2682 const asection
*sym_sec
,
2683 const struct elf_aarch64_link_hash_entry
*hash
,
2684 const Elf_Internal_Rela
*rel
)
2691 len
= 8 + 1 + strlen (hash
->root
.root
.root
.string
) + 1 + 16 + 1;
2692 stub_name
= bfd_malloc (len
);
2693 if (stub_name
!= NULL
)
2694 snprintf (stub_name
, len
, "%08x_%s+%" BFD_VMA_FMT
"x",
2695 (unsigned int) input_section
->id
,
2696 hash
->root
.root
.root
.string
,
2701 len
= 8 + 1 + 8 + 1 + 8 + 1 + 16 + 1;
2702 stub_name
= bfd_malloc (len
);
2703 if (stub_name
!= NULL
)
2704 snprintf (stub_name
, len
, "%08x_%x:%x+%" BFD_VMA_FMT
"x",
2705 (unsigned int) input_section
->id
,
2706 (unsigned int) sym_sec
->id
,
2707 (unsigned int) ELFNN_R_SYM (rel
->r_info
),
2714 /* Return TRUE if symbol H should be hashed in the `.gnu.hash' section. For
2715 executable PLT slots where the executable never takes the address of those
2716 functions, the function symbols are not added to the hash table. */
2719 elf_aarch64_hash_symbol (struct elf_link_hash_entry
*h
)
2721 if (h
->plt
.offset
!= (bfd_vma
) -1
2723 && !h
->pointer_equality_needed
)
2726 return _bfd_elf_hash_symbol (h
);
2730 /* Look up an entry in the stub hash. Stub entries are cached because
2731 creating the stub name takes a bit of time. */
2733 static struct elf_aarch64_stub_hash_entry
*
2734 elfNN_aarch64_get_stub_entry (const asection
*input_section
,
2735 const asection
*sym_sec
,
2736 struct elf_link_hash_entry
*hash
,
2737 const Elf_Internal_Rela
*rel
,
2738 struct elf_aarch64_link_hash_table
*htab
)
2740 struct elf_aarch64_stub_hash_entry
*stub_entry
;
2741 struct elf_aarch64_link_hash_entry
*h
=
2742 (struct elf_aarch64_link_hash_entry
*) hash
;
2743 const asection
*id_sec
;
2745 if ((input_section
->flags
& SEC_CODE
) == 0)
2748 /* If this input section is part of a group of sections sharing one
2749 stub section, then use the id of the first section in the group.
2750 Stub names need to include a section id, as there may well be
2751 more than one stub used to reach say, printf, and we need to
2752 distinguish between them. */
2753 id_sec
= htab
->stub_group
[input_section
->id
].link_sec
;
2755 if (h
!= NULL
&& h
->stub_cache
!= NULL
2756 && h
->stub_cache
->h
== h
&& h
->stub_cache
->id_sec
== id_sec
)
2758 stub_entry
= h
->stub_cache
;
2764 stub_name
= elfNN_aarch64_stub_name (id_sec
, sym_sec
, h
, rel
);
2765 if (stub_name
== NULL
)
2768 stub_entry
= aarch64_stub_hash_lookup (&htab
->stub_hash_table
,
2769 stub_name
, FALSE
, FALSE
);
2771 h
->stub_cache
= stub_entry
;
2780 /* Create a stub section. */
2783 _bfd_aarch64_create_stub_section (asection
*section
,
2784 struct elf_aarch64_link_hash_table
*htab
)
2790 namelen
= strlen (section
->name
);
2791 len
= namelen
+ sizeof (STUB_SUFFIX
);
2792 s_name
= bfd_alloc (htab
->stub_bfd
, len
);
2796 memcpy (s_name
, section
->name
, namelen
);
2797 memcpy (s_name
+ namelen
, STUB_SUFFIX
, sizeof (STUB_SUFFIX
));
2798 return (*htab
->add_stub_section
) (s_name
, section
);
2802 /* Find or create a stub section for a link section.
2804 Fix or create the stub section used to collect stubs attached to
2805 the specified link section. */
2808 _bfd_aarch64_get_stub_for_link_section (asection
*link_section
,
2809 struct elf_aarch64_link_hash_table
*htab
)
2811 if (htab
->stub_group
[link_section
->id
].stub_sec
== NULL
)
2812 htab
->stub_group
[link_section
->id
].stub_sec
2813 = _bfd_aarch64_create_stub_section (link_section
, htab
);
2814 return htab
->stub_group
[link_section
->id
].stub_sec
;
2818 /* Find or create a stub section in the stub group for an input
2822 _bfd_aarch64_create_or_find_stub_sec (asection
*section
,
2823 struct elf_aarch64_link_hash_table
*htab
)
2825 asection
*link_sec
= htab
->stub_group
[section
->id
].link_sec
;
2826 return _bfd_aarch64_get_stub_for_link_section (link_sec
, htab
);
2830 /* Add a new stub entry in the stub group associated with an input
2831 section to the stub hash. Not all fields of the new stub entry are
2834 static struct elf_aarch64_stub_hash_entry
*
2835 _bfd_aarch64_add_stub_entry_in_group (const char *stub_name
,
2837 struct elf_aarch64_link_hash_table
*htab
)
2841 struct elf_aarch64_stub_hash_entry
*stub_entry
;
2843 link_sec
= htab
->stub_group
[section
->id
].link_sec
;
2844 stub_sec
= _bfd_aarch64_create_or_find_stub_sec (section
, htab
);
2846 /* Enter this entry into the linker stub hash table. */
2847 stub_entry
= aarch64_stub_hash_lookup (&htab
->stub_hash_table
, stub_name
,
2849 if (stub_entry
== NULL
)
2851 /* xgettext:c-format */
2852 _bfd_error_handler (_("%B: cannot create stub entry %s"),
2853 section
->owner
, stub_name
);
2857 stub_entry
->stub_sec
= stub_sec
;
2858 stub_entry
->stub_offset
= 0;
2859 stub_entry
->id_sec
= link_sec
;
2864 /* Add a new stub entry in the final stub section to the stub hash.
2865 Not all fields of the new stub entry are initialised. */
2867 static struct elf_aarch64_stub_hash_entry
*
2868 _bfd_aarch64_add_stub_entry_after (const char *stub_name
,
2869 asection
*link_section
,
2870 struct elf_aarch64_link_hash_table
*htab
)
2873 struct elf_aarch64_stub_hash_entry
*stub_entry
;
2875 stub_sec
= _bfd_aarch64_get_stub_for_link_section (link_section
, htab
);
2876 stub_entry
= aarch64_stub_hash_lookup (&htab
->stub_hash_table
, stub_name
,
2878 if (stub_entry
== NULL
)
2880 _bfd_error_handler (_("cannot create stub entry %s"), stub_name
);
2884 stub_entry
->stub_sec
= stub_sec
;
2885 stub_entry
->stub_offset
= 0;
2886 stub_entry
->id_sec
= link_section
;
2893 aarch64_build_one_stub (struct bfd_hash_entry
*gen_entry
,
2894 void *in_arg ATTRIBUTE_UNUSED
)
2896 struct elf_aarch64_stub_hash_entry
*stub_entry
;
2901 bfd_vma veneered_insn_loc
;
2902 bfd_vma veneer_entry_loc
;
2903 bfd_signed_vma branch_offset
= 0;
2904 unsigned int template_size
;
2905 const uint32_t *template;
2908 /* Massage our args to the form they really have. */
2909 stub_entry
= (struct elf_aarch64_stub_hash_entry
*) gen_entry
;
2911 stub_sec
= stub_entry
->stub_sec
;
2913 /* Make a note of the offset within the stubs for this entry. */
2914 stub_entry
->stub_offset
= stub_sec
->size
;
2915 loc
= stub_sec
->contents
+ stub_entry
->stub_offset
;
2917 stub_bfd
= stub_sec
->owner
;
2919 /* This is the address of the stub destination. */
2920 sym_value
= (stub_entry
->target_value
2921 + stub_entry
->target_section
->output_offset
2922 + stub_entry
->target_section
->output_section
->vma
);
2924 if (stub_entry
->stub_type
== aarch64_stub_long_branch
)
2926 bfd_vma place
= (stub_entry
->stub_offset
+ stub_sec
->output_section
->vma
2927 + stub_sec
->output_offset
);
2929 /* See if we can relax the stub. */
2930 if (aarch64_valid_for_adrp_p (sym_value
, place
))
2931 stub_entry
->stub_type
= aarch64_select_branch_stub (sym_value
, place
);
2934 switch (stub_entry
->stub_type
)
2936 case aarch64_stub_adrp_branch
:
2937 template = aarch64_adrp_branch_stub
;
2938 template_size
= sizeof (aarch64_adrp_branch_stub
);
2940 case aarch64_stub_long_branch
:
2941 template = aarch64_long_branch_stub
;
2942 template_size
= sizeof (aarch64_long_branch_stub
);
2944 case aarch64_stub_erratum_835769_veneer
:
2945 template = aarch64_erratum_835769_stub
;
2946 template_size
= sizeof (aarch64_erratum_835769_stub
);
2948 case aarch64_stub_erratum_843419_veneer
:
2949 template = aarch64_erratum_843419_stub
;
2950 template_size
= sizeof (aarch64_erratum_843419_stub
);
2956 for (i
= 0; i
< (template_size
/ sizeof template[0]); i
++)
2958 bfd_putl32 (template[i
], loc
);
2962 template_size
= (template_size
+ 7) & ~7;
2963 stub_sec
->size
+= template_size
;
2965 switch (stub_entry
->stub_type
)
2967 case aarch64_stub_adrp_branch
:
2968 if (aarch64_relocate (AARCH64_R (ADR_PREL_PG_HI21
), stub_bfd
, stub_sec
,
2969 stub_entry
->stub_offset
, sym_value
))
2970 /* The stub would not have been relaxed if the offset was out
2974 if (aarch64_relocate (AARCH64_R (ADD_ABS_LO12_NC
), stub_bfd
, stub_sec
,
2975 stub_entry
->stub_offset
+ 4, sym_value
))
2979 case aarch64_stub_long_branch
:
2980 /* We want the value relative to the address 12 bytes back from the
2982 if (aarch64_relocate (AARCH64_R (PRELNN
), stub_bfd
, stub_sec
,
2983 stub_entry
->stub_offset
+ 16, sym_value
+ 12))
2987 case aarch64_stub_erratum_835769_veneer
:
2988 veneered_insn_loc
= stub_entry
->target_section
->output_section
->vma
2989 + stub_entry
->target_section
->output_offset
2990 + stub_entry
->target_value
;
2991 veneer_entry_loc
= stub_entry
->stub_sec
->output_section
->vma
2992 + stub_entry
->stub_sec
->output_offset
2993 + stub_entry
->stub_offset
;
2994 branch_offset
= veneered_insn_loc
- veneer_entry_loc
;
2995 branch_offset
>>= 2;
2996 branch_offset
&= 0x3ffffff;
2997 bfd_putl32 (stub_entry
->veneered_insn
,
2998 stub_sec
->contents
+ stub_entry
->stub_offset
);
2999 bfd_putl32 (template[1] | branch_offset
,
3000 stub_sec
->contents
+ stub_entry
->stub_offset
+ 4);
3003 case aarch64_stub_erratum_843419_veneer
:
3004 if (aarch64_relocate (AARCH64_R (JUMP26
), stub_bfd
, stub_sec
,
3005 stub_entry
->stub_offset
+ 4, sym_value
+ 4))
3016 /* As above, but don't actually build the stub. Just bump offset so
3017 we know stub section sizes. */
3020 aarch64_size_one_stub (struct bfd_hash_entry
*gen_entry
,
3021 void *in_arg ATTRIBUTE_UNUSED
)
3023 struct elf_aarch64_stub_hash_entry
*stub_entry
;
3026 /* Massage our args to the form they really have. */
3027 stub_entry
= (struct elf_aarch64_stub_hash_entry
*) gen_entry
;
3029 switch (stub_entry
->stub_type
)
3031 case aarch64_stub_adrp_branch
:
3032 size
= sizeof (aarch64_adrp_branch_stub
);
3034 case aarch64_stub_long_branch
:
3035 size
= sizeof (aarch64_long_branch_stub
);
3037 case aarch64_stub_erratum_835769_veneer
:
3038 size
= sizeof (aarch64_erratum_835769_stub
);
3040 case aarch64_stub_erratum_843419_veneer
:
3041 size
= sizeof (aarch64_erratum_843419_stub
);
3047 size
= (size
+ 7) & ~7;
3048 stub_entry
->stub_sec
->size
+= size
;
3052 /* External entry points for sizing and building linker stubs. */
3054 /* Set up various things so that we can make a list of input sections
3055 for each output section included in the link. Returns -1 on error,
3056 0 when no stubs will be needed, and 1 on success. */
3059 elfNN_aarch64_setup_section_lists (bfd
*output_bfd
,
3060 struct bfd_link_info
*info
)
3063 unsigned int bfd_count
;
3064 unsigned int top_id
, top_index
;
3066 asection
**input_list
, **list
;
3068 struct elf_aarch64_link_hash_table
*htab
=
3069 elf_aarch64_hash_table (info
);
3071 if (!is_elf_hash_table (htab
))
3074 /* Count the number of input BFDs and find the top input section id. */
3075 for (input_bfd
= info
->input_bfds
, bfd_count
= 0, top_id
= 0;
3076 input_bfd
!= NULL
; input_bfd
= input_bfd
->link
.next
)
3079 for (section
= input_bfd
->sections
;
3080 section
!= NULL
; section
= section
->next
)
3082 if (top_id
< section
->id
)
3083 top_id
= section
->id
;
3086 htab
->bfd_count
= bfd_count
;
3088 amt
= sizeof (struct map_stub
) * (top_id
+ 1);
3089 htab
->stub_group
= bfd_zmalloc (amt
);
3090 if (htab
->stub_group
== NULL
)
3093 /* We can't use output_bfd->section_count here to find the top output
3094 section index as some sections may have been removed, and
3095 _bfd_strip_section_from_output doesn't renumber the indices. */
3096 for (section
= output_bfd
->sections
, top_index
= 0;
3097 section
!= NULL
; section
= section
->next
)
3099 if (top_index
< section
->index
)
3100 top_index
= section
->index
;
3103 htab
->top_index
= top_index
;
3104 amt
= sizeof (asection
*) * (top_index
+ 1);
3105 input_list
= bfd_malloc (amt
);
3106 htab
->input_list
= input_list
;
3107 if (input_list
== NULL
)
3110 /* For sections we aren't interested in, mark their entries with a
3111 value we can check later. */
3112 list
= input_list
+ top_index
;
3114 *list
= bfd_abs_section_ptr
;
3115 while (list
-- != input_list
);
3117 for (section
= output_bfd
->sections
;
3118 section
!= NULL
; section
= section
->next
)
3120 if ((section
->flags
& SEC_CODE
) != 0)
3121 input_list
[section
->index
] = NULL
;
3127 /* Used by elfNN_aarch64_next_input_section and group_sections. */
3128 #define PREV_SEC(sec) (htab->stub_group[(sec)->id].link_sec)
3130 /* The linker repeatedly calls this function for each input section,
3131 in the order that input sections are linked into output sections.
3132 Build lists of input sections to determine groupings between which
3133 we may insert linker stubs. */
3136 elfNN_aarch64_next_input_section (struct bfd_link_info
*info
, asection
*isec
)
3138 struct elf_aarch64_link_hash_table
*htab
=
3139 elf_aarch64_hash_table (info
);
3141 if (isec
->output_section
->index
<= htab
->top_index
)
3143 asection
**list
= htab
->input_list
+ isec
->output_section
->index
;
3145 if (*list
!= bfd_abs_section_ptr
)
3147 /* Steal the link_sec pointer for our list. */
3148 /* This happens to make the list in reverse order,
3149 which is what we want. */
3150 PREV_SEC (isec
) = *list
;
3156 /* See whether we can group stub sections together. Grouping stub
3157 sections may result in fewer stubs. More importantly, we need to
3158 put all .init* and .fini* stubs at the beginning of the .init or
3159 .fini output sections respectively, because glibc splits the
3160 _init and _fini functions into multiple parts. Putting a stub in
3161 the middle of a function is not a good idea. */
3164 group_sections (struct elf_aarch64_link_hash_table
*htab
,
3165 bfd_size_type stub_group_size
,
3166 bfd_boolean stubs_always_before_branch
)
3168 asection
**list
= htab
->input_list
+ htab
->top_index
;
3172 asection
*tail
= *list
;
3174 if (tail
== bfd_abs_section_ptr
)
3177 while (tail
!= NULL
)
3181 bfd_size_type total
;
3185 while ((prev
= PREV_SEC (curr
)) != NULL
3186 && ((total
+= curr
->output_offset
- prev
->output_offset
)
3190 /* OK, the size from the start of CURR to the end is less
3191 than stub_group_size and thus can be handled by one stub
3192 section. (Or the tail section is itself larger than
3193 stub_group_size, in which case we may be toast.)
3194 We should really be keeping track of the total size of
3195 stubs added here, as stubs contribute to the final output
3199 prev
= PREV_SEC (tail
);
3200 /* Set up this stub group. */
3201 htab
->stub_group
[tail
->id
].link_sec
= curr
;
3203 while (tail
!= curr
&& (tail
= prev
) != NULL
);
3205 /* But wait, there's more! Input sections up to stub_group_size
3206 bytes before the stub section can be handled by it too. */
3207 if (!stubs_always_before_branch
)
3211 && ((total
+= tail
->output_offset
- prev
->output_offset
)
3215 prev
= PREV_SEC (tail
);
3216 htab
->stub_group
[tail
->id
].link_sec
= curr
;
3222 while (list
-- != htab
->input_list
);
3224 free (htab
->input_list
);
3229 #define AARCH64_BITS(x, pos, n) (((x) >> (pos)) & ((1 << (n)) - 1))
3231 #define AARCH64_RT(insn) AARCH64_BITS (insn, 0, 5)
3232 #define AARCH64_RT2(insn) AARCH64_BITS (insn, 10, 5)
3233 #define AARCH64_RA(insn) AARCH64_BITS (insn, 10, 5)
3234 #define AARCH64_RD(insn) AARCH64_BITS (insn, 0, 5)
3235 #define AARCH64_RN(insn) AARCH64_BITS (insn, 5, 5)
3236 #define AARCH64_RM(insn) AARCH64_BITS (insn, 16, 5)
3238 #define AARCH64_MAC(insn) (((insn) & 0xff000000) == 0x9b000000)
3239 #define AARCH64_BIT(insn, n) AARCH64_BITS (insn, n, 1)
3240 #define AARCH64_OP31(insn) AARCH64_BITS (insn, 21, 3)
3241 #define AARCH64_ZR 0x1f
3243 /* All ld/st ops. See C4-182 of the ARM ARM. The encoding space for
3244 LD_PCREL, LDST_RO, LDST_UI and LDST_UIMM cover prefetch ops. */
3246 #define AARCH64_LD(insn) (AARCH64_BIT (insn, 22) == 1)
3247 #define AARCH64_LDST(insn) (((insn) & 0x0a000000) == 0x08000000)
3248 #define AARCH64_LDST_EX(insn) (((insn) & 0x3f000000) == 0x08000000)
3249 #define AARCH64_LDST_PCREL(insn) (((insn) & 0x3b000000) == 0x18000000)
3250 #define AARCH64_LDST_NAP(insn) (((insn) & 0x3b800000) == 0x28000000)
3251 #define AARCH64_LDSTP_PI(insn) (((insn) & 0x3b800000) == 0x28800000)
3252 #define AARCH64_LDSTP_O(insn) (((insn) & 0x3b800000) == 0x29000000)
3253 #define AARCH64_LDSTP_PRE(insn) (((insn) & 0x3b800000) == 0x29800000)
3254 #define AARCH64_LDST_UI(insn) (((insn) & 0x3b200c00) == 0x38000000)
3255 #define AARCH64_LDST_PIIMM(insn) (((insn) & 0x3b200c00) == 0x38000400)
3256 #define AARCH64_LDST_U(insn) (((insn) & 0x3b200c00) == 0x38000800)
3257 #define AARCH64_LDST_PREIMM(insn) (((insn) & 0x3b200c00) == 0x38000c00)
3258 #define AARCH64_LDST_RO(insn) (((insn) & 0x3b200c00) == 0x38200800)
3259 #define AARCH64_LDST_UIMM(insn) (((insn) & 0x3b000000) == 0x39000000)
3260 #define AARCH64_LDST_SIMD_M(insn) (((insn) & 0xbfbf0000) == 0x0c000000)
3261 #define AARCH64_LDST_SIMD_M_PI(insn) (((insn) & 0xbfa00000) == 0x0c800000)
3262 #define AARCH64_LDST_SIMD_S(insn) (((insn) & 0xbf9f0000) == 0x0d000000)
3263 #define AARCH64_LDST_SIMD_S_PI(insn) (((insn) & 0xbf800000) == 0x0d800000)
3265 /* Classify an INSN if it is indeed a load/store.
3267 Return TRUE if INSN is a LD/ST instruction otherwise return FALSE.
3269 For scalar LD/ST instructions PAIR is FALSE, RT is returned and RT2
3272 For LD/ST pair instructions PAIR is TRUE, RT and RT2 are returned. */
3275 aarch64_mem_op_p (uint32_t insn
, unsigned int *rt
, unsigned int *rt2
,
3276 bfd_boolean
*pair
, bfd_boolean
*load
)
3284 /* Bail out quickly if INSN doesn't fall into the the load-store
3286 if (!AARCH64_LDST (insn
))
3291 if (AARCH64_LDST_EX (insn
))
3293 *rt
= AARCH64_RT (insn
);
3295 if (AARCH64_BIT (insn
, 21) == 1)
3298 *rt2
= AARCH64_RT2 (insn
);
3300 *load
= AARCH64_LD (insn
);
3303 else if (AARCH64_LDST_NAP (insn
)
3304 || AARCH64_LDSTP_PI (insn
)
3305 || AARCH64_LDSTP_O (insn
)
3306 || AARCH64_LDSTP_PRE (insn
))
3309 *rt
= AARCH64_RT (insn
);
3310 *rt2
= AARCH64_RT2 (insn
);
3311 *load
= AARCH64_LD (insn
);
3314 else if (AARCH64_LDST_PCREL (insn
)
3315 || AARCH64_LDST_UI (insn
)
3316 || AARCH64_LDST_PIIMM (insn
)
3317 || AARCH64_LDST_U (insn
)
3318 || AARCH64_LDST_PREIMM (insn
)
3319 || AARCH64_LDST_RO (insn
)
3320 || AARCH64_LDST_UIMM (insn
))
3322 *rt
= AARCH64_RT (insn
);
3324 if (AARCH64_LDST_PCREL (insn
))
3326 opc
= AARCH64_BITS (insn
, 22, 2);
3327 v
= AARCH64_BIT (insn
, 26);
3328 opc_v
= opc
| (v
<< 2);
3329 *load
= (opc_v
== 1 || opc_v
== 2 || opc_v
== 3
3330 || opc_v
== 5 || opc_v
== 7);
3333 else if (AARCH64_LDST_SIMD_M (insn
)
3334 || AARCH64_LDST_SIMD_M_PI (insn
))
3336 *rt
= AARCH64_RT (insn
);
3337 *load
= AARCH64_BIT (insn
, 22);
3338 opcode
= (insn
>> 12) & 0xf;
3365 else if (AARCH64_LDST_SIMD_S (insn
)
3366 || AARCH64_LDST_SIMD_S_PI (insn
))
3368 *rt
= AARCH64_RT (insn
);
3369 r
= (insn
>> 21) & 1;
3370 *load
= AARCH64_BIT (insn
, 22);
3371 opcode
= (insn
>> 13) & 0x7;
3383 *rt2
= *rt
+ (r
== 0 ? 2 : 3);
3391 *rt2
= *rt
+ (r
== 0 ? 2 : 3);
3403 /* Return TRUE if INSN is multiply-accumulate. */
3406 aarch64_mlxl_p (uint32_t insn
)
3408 uint32_t op31
= AARCH64_OP31 (insn
);
3410 if (AARCH64_MAC (insn
)
3411 && (op31
== 0 || op31
== 1 || op31
== 5)
3412 /* Exclude MUL instructions which are encoded as a multiple accumulate
3414 && AARCH64_RA (insn
) != AARCH64_ZR
)
3420 /* Some early revisions of the Cortex-A53 have an erratum (835769) whereby
3421 it is possible for a 64-bit multiply-accumulate instruction to generate an
3422 incorrect result. The details are quite complex and hard to
3423 determine statically, since branches in the code may exist in some
3424 circumstances, but all cases end with a memory (load, store, or
3425 prefetch) instruction followed immediately by the multiply-accumulate
3426 operation. We employ a linker patching technique, by moving the potentially
3427 affected multiply-accumulate instruction into a patch region and replacing
3428 the original instruction with a branch to the patch. This function checks
3429 if INSN_1 is the memory operation followed by a multiply-accumulate
3430 operation (INSN_2). Return TRUE if an erratum sequence is found, FALSE
3431 if INSN_1 and INSN_2 are safe. */
3434 aarch64_erratum_sequence (uint32_t insn_1
, uint32_t insn_2
)
3444 if (aarch64_mlxl_p (insn_2
)
3445 && aarch64_mem_op_p (insn_1
, &rt
, &rt2
, &pair
, &load
))
3447 /* Any SIMD memory op is independent of the subsequent MLA
3448 by definition of the erratum. */
3449 if (AARCH64_BIT (insn_1
, 26))
3452 /* If not SIMD, check for integer memory ops and MLA relationship. */
3453 rn
= AARCH64_RN (insn_2
);
3454 ra
= AARCH64_RA (insn_2
);
3455 rm
= AARCH64_RM (insn_2
);
3457 /* If this is a load and there's a true(RAW) dependency, we are safe
3458 and this is not an erratum sequence. */
3460 (rt
== rn
|| rt
== rm
|| rt
== ra
3461 || (pair
&& (rt2
== rn
|| rt2
== rm
|| rt2
== ra
))))
3464 /* We conservatively put out stubs for all other cases (including
3472 /* Used to order a list of mapping symbols by address. */
3475 elf_aarch64_compare_mapping (const void *a
, const void *b
)
3477 const elf_aarch64_section_map
*amap
= (const elf_aarch64_section_map
*) a
;
3478 const elf_aarch64_section_map
*bmap
= (const elf_aarch64_section_map
*) b
;
3480 if (amap
->vma
> bmap
->vma
)
3482 else if (amap
->vma
< bmap
->vma
)
3484 else if (amap
->type
> bmap
->type
)
3485 /* Ensure results do not depend on the host qsort for objects with
3486 multiple mapping symbols at the same address by sorting on type
3489 else if (amap
->type
< bmap
->type
)
3497 _bfd_aarch64_erratum_835769_stub_name (unsigned num_fixes
)
3499 char *stub_name
= (char *) bfd_malloc
3500 (strlen ("__erratum_835769_veneer_") + 16);
3501 sprintf (stub_name
,"__erratum_835769_veneer_%d", num_fixes
);
3505 /* Scan for Cortex-A53 erratum 835769 sequence.
3507 Return TRUE else FALSE on abnormal termination. */
3510 _bfd_aarch64_erratum_835769_scan (bfd
*input_bfd
,
3511 struct bfd_link_info
*info
,
3512 unsigned int *num_fixes_p
)
3515 struct elf_aarch64_link_hash_table
*htab
= elf_aarch64_hash_table (info
);
3516 unsigned int num_fixes
= *num_fixes_p
;
3521 for (section
= input_bfd
->sections
;
3523 section
= section
->next
)
3525 bfd_byte
*contents
= NULL
;
3526 struct _aarch64_elf_section_data
*sec_data
;
3529 if (elf_section_type (section
) != SHT_PROGBITS
3530 || (elf_section_flags (section
) & SHF_EXECINSTR
) == 0
3531 || (section
->flags
& SEC_EXCLUDE
) != 0
3532 || (section
->sec_info_type
== SEC_INFO_TYPE_JUST_SYMS
)
3533 || (section
->output_section
== bfd_abs_section_ptr
))
3536 if (elf_section_data (section
)->this_hdr
.contents
!= NULL
)
3537 contents
= elf_section_data (section
)->this_hdr
.contents
;
3538 else if (! bfd_malloc_and_get_section (input_bfd
, section
, &contents
))
3541 sec_data
= elf_aarch64_section_data (section
);
3543 qsort (sec_data
->map
, sec_data
->mapcount
,
3544 sizeof (elf_aarch64_section_map
), elf_aarch64_compare_mapping
);
3546 for (span
= 0; span
< sec_data
->mapcount
; span
++)
3548 unsigned int span_start
= sec_data
->map
[span
].vma
;
3549 unsigned int span_end
= ((span
== sec_data
->mapcount
- 1)
3550 ? sec_data
->map
[0].vma
+ section
->size
3551 : sec_data
->map
[span
+ 1].vma
);
3553 char span_type
= sec_data
->map
[span
].type
;
3555 if (span_type
== 'd')
3558 for (i
= span_start
; i
+ 4 < span_end
; i
+= 4)
3560 uint32_t insn_1
= bfd_getl32 (contents
+ i
);
3561 uint32_t insn_2
= bfd_getl32 (contents
+ i
+ 4);
3563 if (aarch64_erratum_sequence (insn_1
, insn_2
))
3565 struct elf_aarch64_stub_hash_entry
*stub_entry
;
3566 char *stub_name
= _bfd_aarch64_erratum_835769_stub_name (num_fixes
);
3570 stub_entry
= _bfd_aarch64_add_stub_entry_in_group (stub_name
,
3576 stub_entry
->stub_type
= aarch64_stub_erratum_835769_veneer
;
3577 stub_entry
->target_section
= section
;
3578 stub_entry
->target_value
= i
+ 4;
3579 stub_entry
->veneered_insn
= insn_2
;
3580 stub_entry
->output_name
= stub_name
;
3585 if (elf_section_data (section
)->this_hdr
.contents
== NULL
)
3589 *num_fixes_p
= num_fixes
;
3595 /* Test if instruction INSN is ADRP. */
3598 _bfd_aarch64_adrp_p (uint32_t insn
)
3600 return ((insn
& 0x9f000000) == 0x90000000);
3604 /* Helper predicate to look for cortex-a53 erratum 843419 sequence 1. */
3607 _bfd_aarch64_erratum_843419_sequence_p (uint32_t insn_1
, uint32_t insn_2
,
3615 return (aarch64_mem_op_p (insn_2
, &rt
, &rt2
, &pair
, &load
)
3618 && AARCH64_LDST_UIMM (insn_3
)
3619 && AARCH64_RN (insn_3
) == AARCH64_RD (insn_1
));
3623 /* Test for the presence of Cortex-A53 erratum 843419 instruction sequence.
3625 Return TRUE if section CONTENTS at offset I contains one of the
3626 erratum 843419 sequences, otherwise return FALSE. If a sequence is
3627 seen set P_VENEER_I to the offset of the final LOAD/STORE
3628 instruction in the sequence.
3632 _bfd_aarch64_erratum_843419_p (bfd_byte
*contents
, bfd_vma vma
,
3633 bfd_vma i
, bfd_vma span_end
,
3634 bfd_vma
*p_veneer_i
)
3636 uint32_t insn_1
= bfd_getl32 (contents
+ i
);
3638 if (!_bfd_aarch64_adrp_p (insn_1
))
3641 if (span_end
< i
+ 12)
3644 uint32_t insn_2
= bfd_getl32 (contents
+ i
+ 4);
3645 uint32_t insn_3
= bfd_getl32 (contents
+ i
+ 8);
3647 if ((vma
& 0xfff) != 0xff8 && (vma
& 0xfff) != 0xffc)
3650 if (_bfd_aarch64_erratum_843419_sequence_p (insn_1
, insn_2
, insn_3
))
3652 *p_veneer_i
= i
+ 8;
3656 if (span_end
< i
+ 16)
3659 uint32_t insn_4
= bfd_getl32 (contents
+ i
+ 12);
3661 if (_bfd_aarch64_erratum_843419_sequence_p (insn_1
, insn_2
, insn_4
))
3663 *p_veneer_i
= i
+ 12;
3671 /* Resize all stub sections. */
3674 _bfd_aarch64_resize_stubs (struct elf_aarch64_link_hash_table
*htab
)
3678 /* OK, we've added some stubs. Find out the new size of the
3680 for (section
= htab
->stub_bfd
->sections
;
3681 section
!= NULL
; section
= section
->next
)
3683 /* Ignore non-stub sections. */
3684 if (!strstr (section
->name
, STUB_SUFFIX
))
3689 bfd_hash_traverse (&htab
->stub_hash_table
, aarch64_size_one_stub
, htab
);
3691 for (section
= htab
->stub_bfd
->sections
;
3692 section
!= NULL
; section
= section
->next
)
3694 if (!strstr (section
->name
, STUB_SUFFIX
))
3700 /* Ensure all stub sections have a size which is a multiple of
3701 4096. This is important in order to ensure that the insertion
3702 of stub sections does not in itself move existing code around
3703 in such a way that new errata sequences are created. */
3704 if (htab
->fix_erratum_843419
)
3706 section
->size
= BFD_ALIGN (section
->size
, 0x1000);
3711 /* Construct an erratum 843419 workaround stub name.
3715 _bfd_aarch64_erratum_843419_stub_name (asection
*input_section
,
3718 const bfd_size_type len
= 8 + 4 + 1 + 8 + 1 + 16 + 1;
3719 char *stub_name
= bfd_malloc (len
);
3721 if (stub_name
!= NULL
)
3722 snprintf (stub_name
, len
, "e843419@%04x_%08x_%" BFD_VMA_FMT
"x",
3723 input_section
->owner
->id
,
3729 /* Build a stub_entry structure describing an 843419 fixup.
3731 The stub_entry constructed is populated with the bit pattern INSN
3732 of the instruction located at OFFSET within input SECTION.
3734 Returns TRUE on success. */
3737 _bfd_aarch64_erratum_843419_fixup (uint32_t insn
,
3738 bfd_vma adrp_offset
,
3739 bfd_vma ldst_offset
,
3741 struct bfd_link_info
*info
)
3743 struct elf_aarch64_link_hash_table
*htab
= elf_aarch64_hash_table (info
);
3745 struct elf_aarch64_stub_hash_entry
*stub_entry
;
3747 stub_name
= _bfd_aarch64_erratum_843419_stub_name (section
, ldst_offset
);
3748 stub_entry
= aarch64_stub_hash_lookup (&htab
->stub_hash_table
, stub_name
,
3756 /* We always place an 843419 workaround veneer in the stub section
3757 attached to the input section in which an erratum sequence has
3758 been found. This ensures that later in the link process (in
3759 elfNN_aarch64_write_section) when we copy the veneered
3760 instruction from the input section into the stub section the
3761 copied instruction will have had any relocations applied to it.
3762 If we placed workaround veneers in any other stub section then we
3763 could not assume that all relocations have been processed on the
3764 corresponding input section at the point we output the stub
3768 stub_entry
= _bfd_aarch64_add_stub_entry_after (stub_name
, section
, htab
);
3769 if (stub_entry
== NULL
)
3775 stub_entry
->adrp_offset
= adrp_offset
;
3776 stub_entry
->target_value
= ldst_offset
;
3777 stub_entry
->target_section
= section
;
3778 stub_entry
->stub_type
= aarch64_stub_erratum_843419_veneer
;
3779 stub_entry
->veneered_insn
= insn
;
3780 stub_entry
->output_name
= stub_name
;
3786 /* Scan an input section looking for the signature of erratum 843419.
3788 Scans input SECTION in INPUT_BFD looking for erratum 843419
3789 signatures, for each signature found a stub_entry is created
3790 describing the location of the erratum for subsequent fixup.
3792 Return TRUE on successful scan, FALSE on failure to scan.
3796 _bfd_aarch64_erratum_843419_scan (bfd
*input_bfd
, asection
*section
,
3797 struct bfd_link_info
*info
)
3799 struct elf_aarch64_link_hash_table
*htab
= elf_aarch64_hash_table (info
);
3804 if (elf_section_type (section
) != SHT_PROGBITS
3805 || (elf_section_flags (section
) & SHF_EXECINSTR
) == 0
3806 || (section
->flags
& SEC_EXCLUDE
) != 0
3807 || (section
->sec_info_type
== SEC_INFO_TYPE_JUST_SYMS
)
3808 || (section
->output_section
== bfd_abs_section_ptr
))
3813 bfd_byte
*contents
= NULL
;
3814 struct _aarch64_elf_section_data
*sec_data
;
3817 if (elf_section_data (section
)->this_hdr
.contents
!= NULL
)
3818 contents
= elf_section_data (section
)->this_hdr
.contents
;
3819 else if (! bfd_malloc_and_get_section (input_bfd
, section
, &contents
))
3822 sec_data
= elf_aarch64_section_data (section
);
3824 qsort (sec_data
->map
, sec_data
->mapcount
,
3825 sizeof (elf_aarch64_section_map
), elf_aarch64_compare_mapping
);
3827 for (span
= 0; span
< sec_data
->mapcount
; span
++)
3829 unsigned int span_start
= sec_data
->map
[span
].vma
;
3830 unsigned int span_end
= ((span
== sec_data
->mapcount
- 1)
3831 ? sec_data
->map
[0].vma
+ section
->size
3832 : sec_data
->map
[span
+ 1].vma
);
3834 char span_type
= sec_data
->map
[span
].type
;
3836 if (span_type
== 'd')
3839 for (i
= span_start
; i
+ 8 < span_end
; i
+= 4)
3841 bfd_vma vma
= (section
->output_section
->vma
3842 + section
->output_offset
3846 if (_bfd_aarch64_erratum_843419_p
3847 (contents
, vma
, i
, span_end
, &veneer_i
))
3849 uint32_t insn
= bfd_getl32 (contents
+ veneer_i
);
3851 if (!_bfd_aarch64_erratum_843419_fixup (insn
, i
, veneer_i
,
3858 if (elf_section_data (section
)->this_hdr
.contents
== NULL
)
3867 /* Determine and set the size of the stub section for a final link.
3869 The basic idea here is to examine all the relocations looking for
3870 PC-relative calls to a target that is unreachable with a "bl"
3874 elfNN_aarch64_size_stubs (bfd
*output_bfd
,
3876 struct bfd_link_info
*info
,
3877 bfd_signed_vma group_size
,
3878 asection
* (*add_stub_section
) (const char *,
3880 void (*layout_sections_again
) (void))
3882 bfd_size_type stub_group_size
;
3883 bfd_boolean stubs_always_before_branch
;
3884 bfd_boolean stub_changed
= FALSE
;
3885 struct elf_aarch64_link_hash_table
*htab
= elf_aarch64_hash_table (info
);
3886 unsigned int num_erratum_835769_fixes
= 0;
3888 /* Propagate mach to stub bfd, because it may not have been
3889 finalized when we created stub_bfd. */
3890 bfd_set_arch_mach (stub_bfd
, bfd_get_arch (output_bfd
),
3891 bfd_get_mach (output_bfd
));
3893 /* Stash our params away. */
3894 htab
->stub_bfd
= stub_bfd
;
3895 htab
->add_stub_section
= add_stub_section
;
3896 htab
->layout_sections_again
= layout_sections_again
;
3897 stubs_always_before_branch
= group_size
< 0;
3899 stub_group_size
= -group_size
;
3901 stub_group_size
= group_size
;
3903 if (stub_group_size
== 1)
3905 /* Default values. */
3906 /* AArch64 branch range is +-128MB. The value used is 1MB less. */
3907 stub_group_size
= 127 * 1024 * 1024;
3910 group_sections (htab
, stub_group_size
, stubs_always_before_branch
);
3912 (*htab
->layout_sections_again
) ();
3914 if (htab
->fix_erratum_835769
)
3918 for (input_bfd
= info
->input_bfds
;
3919 input_bfd
!= NULL
; input_bfd
= input_bfd
->link
.next
)
3920 if (!_bfd_aarch64_erratum_835769_scan (input_bfd
, info
,
3921 &num_erratum_835769_fixes
))
3924 _bfd_aarch64_resize_stubs (htab
);
3925 (*htab
->layout_sections_again
) ();
3928 if (htab
->fix_erratum_843419
)
3932 for (input_bfd
= info
->input_bfds
;
3934 input_bfd
= input_bfd
->link
.next
)
3938 for (section
= input_bfd
->sections
;
3940 section
= section
->next
)
3941 if (!_bfd_aarch64_erratum_843419_scan (input_bfd
, section
, info
))
3945 _bfd_aarch64_resize_stubs (htab
);
3946 (*htab
->layout_sections_again
) ();
3953 for (input_bfd
= info
->input_bfds
;
3954 input_bfd
!= NULL
; input_bfd
= input_bfd
->link
.next
)
3956 Elf_Internal_Shdr
*symtab_hdr
;
3958 Elf_Internal_Sym
*local_syms
= NULL
;
3960 /* We'll need the symbol table in a second. */
3961 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
3962 if (symtab_hdr
->sh_info
== 0)
3965 /* Walk over each section attached to the input bfd. */
3966 for (section
= input_bfd
->sections
;
3967 section
!= NULL
; section
= section
->next
)
3969 Elf_Internal_Rela
*internal_relocs
, *irelaend
, *irela
;
3971 /* If there aren't any relocs, then there's nothing more
3973 if ((section
->flags
& SEC_RELOC
) == 0
3974 || section
->reloc_count
== 0
3975 || (section
->flags
& SEC_CODE
) == 0)
3978 /* If this section is a link-once section that will be
3979 discarded, then don't create any stubs. */
3980 if (section
->output_section
== NULL
3981 || section
->output_section
->owner
!= output_bfd
)
3984 /* Get the relocs. */
3986 = _bfd_elf_link_read_relocs (input_bfd
, section
, NULL
,
3987 NULL
, info
->keep_memory
);
3988 if (internal_relocs
== NULL
)
3989 goto error_ret_free_local
;
3991 /* Now examine each relocation. */
3992 irela
= internal_relocs
;
3993 irelaend
= irela
+ section
->reloc_count
;
3994 for (; irela
< irelaend
; irela
++)
3996 unsigned int r_type
, r_indx
;
3997 enum elf_aarch64_stub_type stub_type
;
3998 struct elf_aarch64_stub_hash_entry
*stub_entry
;
4001 bfd_vma destination
;
4002 struct elf_aarch64_link_hash_entry
*hash
;
4003 const char *sym_name
;
4005 const asection
*id_sec
;
4006 unsigned char st_type
;
4009 r_type
= ELFNN_R_TYPE (irela
->r_info
);
4010 r_indx
= ELFNN_R_SYM (irela
->r_info
);
4012 if (r_type
>= (unsigned int) R_AARCH64_end
)
4014 bfd_set_error (bfd_error_bad_value
);
4015 error_ret_free_internal
:
4016 if (elf_section_data (section
)->relocs
== NULL
)
4017 free (internal_relocs
);
4018 goto error_ret_free_local
;
4021 /* Only look for stubs on unconditional branch and
4022 branch and link instructions. */
4023 if (r_type
!= (unsigned int) AARCH64_R (CALL26
)
4024 && r_type
!= (unsigned int) AARCH64_R (JUMP26
))
4027 /* Now determine the call target, its name, value,
4034 if (r_indx
< symtab_hdr
->sh_info
)
4036 /* It's a local symbol. */
4037 Elf_Internal_Sym
*sym
;
4038 Elf_Internal_Shdr
*hdr
;
4040 if (local_syms
== NULL
)
4043 = (Elf_Internal_Sym
*) symtab_hdr
->contents
;
4044 if (local_syms
== NULL
)
4046 = bfd_elf_get_elf_syms (input_bfd
, symtab_hdr
,
4047 symtab_hdr
->sh_info
, 0,
4049 if (local_syms
== NULL
)
4050 goto error_ret_free_internal
;
4053 sym
= local_syms
+ r_indx
;
4054 hdr
= elf_elfsections (input_bfd
)[sym
->st_shndx
];
4055 sym_sec
= hdr
->bfd_section
;
4057 /* This is an undefined symbol. It can never
4061 if (ELF_ST_TYPE (sym
->st_info
) != STT_SECTION
)
4062 sym_value
= sym
->st_value
;
4063 destination
= (sym_value
+ irela
->r_addend
4064 + sym_sec
->output_offset
4065 + sym_sec
->output_section
->vma
);
4066 st_type
= ELF_ST_TYPE (sym
->st_info
);
4068 = bfd_elf_string_from_elf_section (input_bfd
,
4069 symtab_hdr
->sh_link
,
4076 e_indx
= r_indx
- symtab_hdr
->sh_info
;
4077 hash
= ((struct elf_aarch64_link_hash_entry
*)
4078 elf_sym_hashes (input_bfd
)[e_indx
]);
4080 while (hash
->root
.root
.type
== bfd_link_hash_indirect
4081 || hash
->root
.root
.type
== bfd_link_hash_warning
)
4082 hash
= ((struct elf_aarch64_link_hash_entry
*)
4083 hash
->root
.root
.u
.i
.link
);
4085 if (hash
->root
.root
.type
== bfd_link_hash_defined
4086 || hash
->root
.root
.type
== bfd_link_hash_defweak
)
4088 struct elf_aarch64_link_hash_table
*globals
=
4089 elf_aarch64_hash_table (info
);
4090 sym_sec
= hash
->root
.root
.u
.def
.section
;
4091 sym_value
= hash
->root
.root
.u
.def
.value
;
4092 /* For a destination in a shared library,
4093 use the PLT stub as target address to
4094 decide whether a branch stub is
4096 if (globals
->root
.splt
!= NULL
&& hash
!= NULL
4097 && hash
->root
.plt
.offset
!= (bfd_vma
) - 1)
4099 sym_sec
= globals
->root
.splt
;
4100 sym_value
= hash
->root
.plt
.offset
;
4101 if (sym_sec
->output_section
!= NULL
)
4102 destination
= (sym_value
4103 + sym_sec
->output_offset
4105 sym_sec
->output_section
->vma
);
4107 else if (sym_sec
->output_section
!= NULL
)
4108 destination
= (sym_value
+ irela
->r_addend
4109 + sym_sec
->output_offset
4110 + sym_sec
->output_section
->vma
);
4112 else if (hash
->root
.root
.type
== bfd_link_hash_undefined
4113 || (hash
->root
.root
.type
4114 == bfd_link_hash_undefweak
))
4116 /* For a shared library, use the PLT stub as
4117 target address to decide whether a long
4118 branch stub is needed.
4119 For absolute code, they cannot be handled. */
4120 struct elf_aarch64_link_hash_table
*globals
=
4121 elf_aarch64_hash_table (info
);
4123 if (globals
->root
.splt
!= NULL
&& hash
!= NULL
4124 && hash
->root
.plt
.offset
!= (bfd_vma
) - 1)
4126 sym_sec
= globals
->root
.splt
;
4127 sym_value
= hash
->root
.plt
.offset
;
4128 if (sym_sec
->output_section
!= NULL
)
4129 destination
= (sym_value
4130 + sym_sec
->output_offset
4132 sym_sec
->output_section
->vma
);
4139 bfd_set_error (bfd_error_bad_value
);
4140 goto error_ret_free_internal
;
4142 st_type
= ELF_ST_TYPE (hash
->root
.type
);
4143 sym_name
= hash
->root
.root
.root
.string
;
4146 /* Determine what (if any) linker stub is needed. */
4147 stub_type
= aarch64_type_of_stub (section
, irela
, sym_sec
,
4148 st_type
, destination
);
4149 if (stub_type
== aarch64_stub_none
)
4152 /* Support for grouping stub sections. */
4153 id_sec
= htab
->stub_group
[section
->id
].link_sec
;
4155 /* Get the name of this stub. */
4156 stub_name
= elfNN_aarch64_stub_name (id_sec
, sym_sec
, hash
,
4159 goto error_ret_free_internal
;
4162 aarch64_stub_hash_lookup (&htab
->stub_hash_table
,
4163 stub_name
, FALSE
, FALSE
);
4164 if (stub_entry
!= NULL
)
4166 /* The proper stub has already been created. */
4171 stub_entry
= _bfd_aarch64_add_stub_entry_in_group
4172 (stub_name
, section
, htab
);
4173 if (stub_entry
== NULL
)
4176 goto error_ret_free_internal
;
4179 stub_entry
->target_value
= sym_value
+ irela
->r_addend
;
4180 stub_entry
->target_section
= sym_sec
;
4181 stub_entry
->stub_type
= stub_type
;
4182 stub_entry
->h
= hash
;
4183 stub_entry
->st_type
= st_type
;
4185 if (sym_name
== NULL
)
4186 sym_name
= "unnamed";
4187 len
= sizeof (STUB_ENTRY_NAME
) + strlen (sym_name
);
4188 stub_entry
->output_name
= bfd_alloc (htab
->stub_bfd
, len
);
4189 if (stub_entry
->output_name
== NULL
)
4192 goto error_ret_free_internal
;
4195 snprintf (stub_entry
->output_name
, len
, STUB_ENTRY_NAME
,
4198 stub_changed
= TRUE
;
4201 /* We're done with the internal relocs, free them. */
4202 if (elf_section_data (section
)->relocs
== NULL
)
4203 free (internal_relocs
);
4210 _bfd_aarch64_resize_stubs (htab
);
4212 /* Ask the linker to do its stuff. */
4213 (*htab
->layout_sections_again
) ();
4214 stub_changed
= FALSE
;
4219 error_ret_free_local
:
4223 /* Build all the stubs associated with the current output file. The
4224 stubs are kept in a hash table attached to the main linker hash
4225 table. We also set up the .plt entries for statically linked PIC
4226 functions here. This function is called via aarch64_elf_finish in the
4230 elfNN_aarch64_build_stubs (struct bfd_link_info
*info
)
4233 struct bfd_hash_table
*table
;
4234 struct elf_aarch64_link_hash_table
*htab
;
4236 htab
= elf_aarch64_hash_table (info
);
4238 for (stub_sec
= htab
->stub_bfd
->sections
;
4239 stub_sec
!= NULL
; stub_sec
= stub_sec
->next
)
4243 /* Ignore non-stub sections. */
4244 if (!strstr (stub_sec
->name
, STUB_SUFFIX
))
4247 /* Allocate memory to hold the linker stubs. */
4248 size
= stub_sec
->size
;
4249 stub_sec
->contents
= bfd_zalloc (htab
->stub_bfd
, size
);
4250 if (stub_sec
->contents
== NULL
&& size
!= 0)
4254 bfd_putl32 (0x14000000 | (size
>> 2), stub_sec
->contents
);
4255 stub_sec
->size
+= 4;
4258 /* Build the stubs as directed by the stub hash table. */
4259 table
= &htab
->stub_hash_table
;
4260 bfd_hash_traverse (table
, aarch64_build_one_stub
, info
);
4266 /* Add an entry to the code/data map for section SEC. */
4269 elfNN_aarch64_section_map_add (asection
*sec
, char type
, bfd_vma vma
)
4271 struct _aarch64_elf_section_data
*sec_data
=
4272 elf_aarch64_section_data (sec
);
4273 unsigned int newidx
;
4275 if (sec_data
->map
== NULL
)
4277 sec_data
->map
= bfd_malloc (sizeof (elf_aarch64_section_map
));
4278 sec_data
->mapcount
= 0;
4279 sec_data
->mapsize
= 1;
4282 newidx
= sec_data
->mapcount
++;
4284 if (sec_data
->mapcount
> sec_data
->mapsize
)
4286 sec_data
->mapsize
*= 2;
4287 sec_data
->map
= bfd_realloc_or_free
4288 (sec_data
->map
, sec_data
->mapsize
* sizeof (elf_aarch64_section_map
));
4293 sec_data
->map
[newidx
].vma
= vma
;
4294 sec_data
->map
[newidx
].type
= type
;
4299 /* Initialise maps of insn/data for input BFDs. */
4301 bfd_elfNN_aarch64_init_maps (bfd
*abfd
)
4303 Elf_Internal_Sym
*isymbuf
;
4304 Elf_Internal_Shdr
*hdr
;
4305 unsigned int i
, localsyms
;
4307 /* Make sure that we are dealing with an AArch64 elf binary. */
4308 if (!is_aarch64_elf (abfd
))
4311 if ((abfd
->flags
& DYNAMIC
) != 0)
4314 hdr
= &elf_symtab_hdr (abfd
);
4315 localsyms
= hdr
->sh_info
;
4317 /* Obtain a buffer full of symbols for this BFD. The hdr->sh_info field
4318 should contain the number of local symbols, which should come before any
4319 global symbols. Mapping symbols are always local. */
4320 isymbuf
= bfd_elf_get_elf_syms (abfd
, hdr
, localsyms
, 0, NULL
, NULL
, NULL
);
4322 /* No internal symbols read? Skip this BFD. */
4323 if (isymbuf
== NULL
)
4326 for (i
= 0; i
< localsyms
; i
++)
4328 Elf_Internal_Sym
*isym
= &isymbuf
[i
];
4329 asection
*sec
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
4332 if (sec
!= NULL
&& ELF_ST_BIND (isym
->st_info
) == STB_LOCAL
)
4334 name
= bfd_elf_string_from_elf_section (abfd
,
4338 if (bfd_is_aarch64_special_symbol_name
4339 (name
, BFD_AARCH64_SPECIAL_SYM_TYPE_MAP
))
4340 elfNN_aarch64_section_map_add (sec
, name
[1], isym
->st_value
);
4345 /* Set option values needed during linking. */
4347 bfd_elfNN_aarch64_set_options (struct bfd
*output_bfd
,
4348 struct bfd_link_info
*link_info
,
4350 int no_wchar_warn
, int pic_veneer
,
4351 int fix_erratum_835769
,
4352 int fix_erratum_843419
,
4353 int no_apply_dynamic_relocs
)
4355 struct elf_aarch64_link_hash_table
*globals
;
4357 globals
= elf_aarch64_hash_table (link_info
);
4358 globals
->pic_veneer
= pic_veneer
;
4359 globals
->fix_erratum_835769
= fix_erratum_835769
;
4360 globals
->fix_erratum_843419
= fix_erratum_843419
;
4361 globals
->fix_erratum_843419_adr
= TRUE
;
4362 globals
->no_apply_dynamic_relocs
= no_apply_dynamic_relocs
;
4364 BFD_ASSERT (is_aarch64_elf (output_bfd
));
4365 elf_aarch64_tdata (output_bfd
)->no_enum_size_warning
= no_enum_warn
;
4366 elf_aarch64_tdata (output_bfd
)->no_wchar_size_warning
= no_wchar_warn
;
4370 aarch64_calculate_got_entry_vma (struct elf_link_hash_entry
*h
,
4371 struct elf_aarch64_link_hash_table
4372 *globals
, struct bfd_link_info
*info
,
4373 bfd_vma value
, bfd
*output_bfd
,
4374 bfd_boolean
*unresolved_reloc_p
)
4376 bfd_vma off
= (bfd_vma
) - 1;
4377 asection
*basegot
= globals
->root
.sgot
;
4378 bfd_boolean dyn
= globals
->root
.dynamic_sections_created
;
4382 BFD_ASSERT (basegot
!= NULL
);
4383 off
= h
->got
.offset
;
4384 BFD_ASSERT (off
!= (bfd_vma
) - 1);
4385 if (!WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, bfd_link_pic (info
), h
)
4386 || (bfd_link_pic (info
)
4387 && SYMBOL_REFERENCES_LOCAL (info
, h
))
4388 || (ELF_ST_VISIBILITY (h
->other
)
4389 && h
->root
.type
== bfd_link_hash_undefweak
))
4391 /* This is actually a static link, or it is a -Bsymbolic link
4392 and the symbol is defined locally. We must initialize this
4393 entry in the global offset table. Since the offset must
4394 always be a multiple of 8 (4 in the case of ILP32), we use
4395 the least significant bit to record whether we have
4396 initialized it already.
4397 When doing a dynamic link, we create a .rel(a).got relocation
4398 entry to initialize the value. This is done in the
4399 finish_dynamic_symbol routine. */
4404 bfd_put_NN (output_bfd
, value
, basegot
->contents
+ off
);
4409 *unresolved_reloc_p
= FALSE
;
4411 off
= off
+ basegot
->output_section
->vma
+ basegot
->output_offset
;
4417 /* Change R_TYPE to a more efficient access model where possible,
4418 return the new reloc type. */
4420 static bfd_reloc_code_real_type
4421 aarch64_tls_transition_without_check (bfd_reloc_code_real_type r_type
,
4422 struct elf_link_hash_entry
*h
)
4424 bfd_boolean is_local
= h
== NULL
;
4428 case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21
:
4429 case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21
:
4431 ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1
4432 : BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21
);
4434 case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21
:
4436 ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC
4439 case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19
:
4441 ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1
4442 : BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19
);
4444 case BFD_RELOC_AARCH64_TLSDESC_LDR
:
4446 ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC
4447 : BFD_RELOC_AARCH64_NONE
);
4449 case BFD_RELOC_AARCH64_TLSDESC_OFF_G0_NC
:
4451 ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1_NC
4452 : BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G0_NC
);
4454 case BFD_RELOC_AARCH64_TLSDESC_OFF_G1
:
4456 ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G2
4457 : BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G1
);
4459 case BFD_RELOC_AARCH64_TLSDESC_LDNN_LO12_NC
:
4460 case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC
:
4462 ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC
4463 : BFD_RELOC_AARCH64_TLSIE_LDNN_GOTTPREL_LO12_NC
);
4465 case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21
:
4466 return is_local
? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1
: r_type
;
4468 case BFD_RELOC_AARCH64_TLSIE_LDNN_GOTTPREL_LO12_NC
:
4469 return is_local
? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC
: r_type
;
4471 case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19
:
4474 case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21
:
4476 ? BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_HI12
4477 : BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19
);
4479 case BFD_RELOC_AARCH64_TLSDESC_ADD
:
4480 case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12
:
4481 case BFD_RELOC_AARCH64_TLSDESC_CALL
:
4482 /* Instructions with these relocations will become NOPs. */
4483 return BFD_RELOC_AARCH64_NONE
;
4485 case BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC
:
4486 case BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21
:
4487 case BFD_RELOC_AARCH64_TLSLD_ADR_PREL21
:
4488 return is_local
? BFD_RELOC_AARCH64_NONE
: r_type
;
4491 case BFD_RELOC_AARCH64_TLSGD_MOVW_G0_NC
:
4493 ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1_NC
4494 : BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G0_NC
;
4496 case BFD_RELOC_AARCH64_TLSGD_MOVW_G1
:
4498 ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G2
4499 : BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G1
;
4510 aarch64_reloc_got_type (bfd_reloc_code_real_type r_type
)
4514 case BFD_RELOC_AARCH64_ADR_GOT_PAGE
:
4515 case BFD_RELOC_AARCH64_GOT_LD_PREL19
:
4516 case BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14
:
4517 case BFD_RELOC_AARCH64_LD32_GOT_LO12_NC
:
4518 case BFD_RELOC_AARCH64_LD64_GOTOFF_LO15
:
4519 case BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15
:
4520 case BFD_RELOC_AARCH64_LD64_GOT_LO12_NC
:
4521 case BFD_RELOC_AARCH64_MOVW_GOTOFF_G0_NC
:
4522 case BFD_RELOC_AARCH64_MOVW_GOTOFF_G1
:
4525 case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC
:
4526 case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21
:
4527 case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21
:
4528 case BFD_RELOC_AARCH64_TLSGD_MOVW_G0_NC
:
4529 case BFD_RELOC_AARCH64_TLSGD_MOVW_G1
:
4530 case BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC
:
4531 case BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21
:
4532 case BFD_RELOC_AARCH64_TLSLD_ADR_PREL21
:
4535 case BFD_RELOC_AARCH64_TLSDESC_ADD
:
4536 case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12
:
4537 case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21
:
4538 case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21
:
4539 case BFD_RELOC_AARCH64_TLSDESC_CALL
:
4540 case BFD_RELOC_AARCH64_TLSDESC_LD32_LO12_NC
:
4541 case BFD_RELOC_AARCH64_TLSDESC_LD64_LO12
:
4542 case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19
:
4543 case BFD_RELOC_AARCH64_TLSDESC_LDR
:
4544 case BFD_RELOC_AARCH64_TLSDESC_OFF_G0_NC
:
4545 case BFD_RELOC_AARCH64_TLSDESC_OFF_G1
:
4546 return GOT_TLSDESC_GD
;
4548 case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21
:
4549 case BFD_RELOC_AARCH64_TLSIE_LD32_GOTTPREL_LO12_NC
:
4550 case BFD_RELOC_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC
:
4551 case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19
:
4552 case BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G0_NC
:
4553 case BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G1
:
4563 aarch64_can_relax_tls (bfd
*input_bfd
,
4564 struct bfd_link_info
*info
,
4565 bfd_reloc_code_real_type r_type
,
4566 struct elf_link_hash_entry
*h
,
4567 unsigned long r_symndx
)
4569 unsigned int symbol_got_type
;
4570 unsigned int reloc_got_type
;
4572 if (! IS_AARCH64_TLS_RELAX_RELOC (r_type
))
4575 symbol_got_type
= elfNN_aarch64_symbol_got_type (h
, input_bfd
, r_symndx
);
4576 reloc_got_type
= aarch64_reloc_got_type (r_type
);
4578 if (symbol_got_type
== GOT_TLS_IE
&& GOT_TLS_GD_ANY_P (reloc_got_type
))
4581 if (bfd_link_pic (info
))
4584 if (h
&& h
->root
.type
== bfd_link_hash_undefweak
)
4590 /* Given the relocation code R_TYPE, return the relaxed bfd reloc
4593 static bfd_reloc_code_real_type
4594 aarch64_tls_transition (bfd
*input_bfd
,
4595 struct bfd_link_info
*info
,
4596 unsigned int r_type
,
4597 struct elf_link_hash_entry
*h
,
4598 unsigned long r_symndx
)
4600 bfd_reloc_code_real_type bfd_r_type
4601 = elfNN_aarch64_bfd_reloc_from_type (r_type
);
4603 if (! aarch64_can_relax_tls (input_bfd
, info
, bfd_r_type
, h
, r_symndx
))
4606 return aarch64_tls_transition_without_check (bfd_r_type
, h
);
4609 /* Return the base VMA address which should be subtracted from real addresses
4610 when resolving R_AARCH64_TLS_DTPREL relocation. */
4613 dtpoff_base (struct bfd_link_info
*info
)
4615 /* If tls_sec is NULL, we should have signalled an error already. */
4616 BFD_ASSERT (elf_hash_table (info
)->tls_sec
!= NULL
);
4617 return elf_hash_table (info
)->tls_sec
->vma
;
4620 /* Return the base VMA address which should be subtracted from real addresses
4621 when resolving R_AARCH64_TLS_GOTTPREL64 relocations. */
4624 tpoff_base (struct bfd_link_info
*info
)
4626 struct elf_link_hash_table
*htab
= elf_hash_table (info
);
4628 /* If tls_sec is NULL, we should have signalled an error already. */
4629 BFD_ASSERT (htab
->tls_sec
!= NULL
);
4631 bfd_vma base
= align_power ((bfd_vma
) TCB_SIZE
,
4632 htab
->tls_sec
->alignment_power
);
4633 return htab
->tls_sec
->vma
- base
;
4637 symbol_got_offset_ref (bfd
*input_bfd
, struct elf_link_hash_entry
*h
,
4638 unsigned long r_symndx
)
4640 /* Calculate the address of the GOT entry for symbol
4641 referred to in h. */
4643 return &h
->got
.offset
;
4647 struct elf_aarch64_local_symbol
*l
;
4649 l
= elf_aarch64_locals (input_bfd
);
4650 return &l
[r_symndx
].got_offset
;
4655 symbol_got_offset_mark (bfd
*input_bfd
, struct elf_link_hash_entry
*h
,
4656 unsigned long r_symndx
)
4659 p
= symbol_got_offset_ref (input_bfd
, h
, r_symndx
);
4664 symbol_got_offset_mark_p (bfd
*input_bfd
, struct elf_link_hash_entry
*h
,
4665 unsigned long r_symndx
)
4668 value
= * symbol_got_offset_ref (input_bfd
, h
, r_symndx
);
4673 symbol_got_offset (bfd
*input_bfd
, struct elf_link_hash_entry
*h
,
4674 unsigned long r_symndx
)
4677 value
= * symbol_got_offset_ref (input_bfd
, h
, r_symndx
);
4683 symbol_tlsdesc_got_offset_ref (bfd
*input_bfd
, struct elf_link_hash_entry
*h
,
4684 unsigned long r_symndx
)
4686 /* Calculate the address of the GOT entry for symbol
4687 referred to in h. */
4690 struct elf_aarch64_link_hash_entry
*eh
;
4691 eh
= (struct elf_aarch64_link_hash_entry
*) h
;
4692 return &eh
->tlsdesc_got_jump_table_offset
;
4697 struct elf_aarch64_local_symbol
*l
;
4699 l
= elf_aarch64_locals (input_bfd
);
4700 return &l
[r_symndx
].tlsdesc_got_jump_table_offset
;
4705 symbol_tlsdesc_got_offset_mark (bfd
*input_bfd
, struct elf_link_hash_entry
*h
,
4706 unsigned long r_symndx
)
4709 p
= symbol_tlsdesc_got_offset_ref (input_bfd
, h
, r_symndx
);
4714 symbol_tlsdesc_got_offset_mark_p (bfd
*input_bfd
,
4715 struct elf_link_hash_entry
*h
,
4716 unsigned long r_symndx
)
4719 value
= * symbol_tlsdesc_got_offset_ref (input_bfd
, h
, r_symndx
);
4724 symbol_tlsdesc_got_offset (bfd
*input_bfd
, struct elf_link_hash_entry
*h
,
4725 unsigned long r_symndx
)
4728 value
= * symbol_tlsdesc_got_offset_ref (input_bfd
, h
, r_symndx
);
4733 /* Data for make_branch_to_erratum_835769_stub(). */
4735 struct erratum_835769_branch_to_stub_data
4737 struct bfd_link_info
*info
;
4738 asection
*output_section
;
4742 /* Helper to insert branches to erratum 835769 stubs in the right
4743 places for a particular section. */
4746 make_branch_to_erratum_835769_stub (struct bfd_hash_entry
*gen_entry
,
4749 struct elf_aarch64_stub_hash_entry
*stub_entry
;
4750 struct erratum_835769_branch_to_stub_data
*data
;
4752 unsigned long branch_insn
= 0;
4753 bfd_vma veneered_insn_loc
, veneer_entry_loc
;
4754 bfd_signed_vma branch_offset
;
4755 unsigned int target
;
4758 stub_entry
= (struct elf_aarch64_stub_hash_entry
*) gen_entry
;
4759 data
= (struct erratum_835769_branch_to_stub_data
*) in_arg
;
4761 if (stub_entry
->target_section
!= data
->output_section
4762 || stub_entry
->stub_type
!= aarch64_stub_erratum_835769_veneer
)
4765 contents
= data
->contents
;
4766 veneered_insn_loc
= stub_entry
->target_section
->output_section
->vma
4767 + stub_entry
->target_section
->output_offset
4768 + stub_entry
->target_value
;
4769 veneer_entry_loc
= stub_entry
->stub_sec
->output_section
->vma
4770 + stub_entry
->stub_sec
->output_offset
4771 + stub_entry
->stub_offset
;
4772 branch_offset
= veneer_entry_loc
- veneered_insn_loc
;
4774 abfd
= stub_entry
->target_section
->owner
;
4775 if (!aarch64_valid_branch_p (veneer_entry_loc
, veneered_insn_loc
))
4777 (_("%B: error: Erratum 835769 stub out "
4778 "of range (input file too large)"), abfd
);
4780 target
= stub_entry
->target_value
;
4781 branch_insn
= 0x14000000;
4782 branch_offset
>>= 2;
4783 branch_offset
&= 0x3ffffff;
4784 branch_insn
|= branch_offset
;
4785 bfd_putl32 (branch_insn
, &contents
[target
]);
4792 _bfd_aarch64_erratum_843419_branch_to_stub (struct bfd_hash_entry
*gen_entry
,
4795 struct elf_aarch64_stub_hash_entry
*stub_entry
4796 = (struct elf_aarch64_stub_hash_entry
*) gen_entry
;
4797 struct erratum_835769_branch_to_stub_data
*data
4798 = (struct erratum_835769_branch_to_stub_data
*) in_arg
;
4799 struct bfd_link_info
*info
;
4800 struct elf_aarch64_link_hash_table
*htab
;
4808 contents
= data
->contents
;
4809 section
= data
->output_section
;
4811 htab
= elf_aarch64_hash_table (info
);
4813 if (stub_entry
->target_section
!= section
4814 || stub_entry
->stub_type
!= aarch64_stub_erratum_843419_veneer
)
4817 insn
= bfd_getl32 (contents
+ stub_entry
->target_value
);
4819 stub_entry
->stub_sec
->contents
+ stub_entry
->stub_offset
);
4821 place
= (section
->output_section
->vma
+ section
->output_offset
4822 + stub_entry
->adrp_offset
);
4823 insn
= bfd_getl32 (contents
+ stub_entry
->adrp_offset
);
4825 if ((insn
& AARCH64_ADRP_OP_MASK
) != AARCH64_ADRP_OP
)
4828 bfd_signed_vma imm
=
4829 (_bfd_aarch64_sign_extend
4830 ((bfd_vma
) _bfd_aarch64_decode_adrp_imm (insn
) << 12, 33)
4833 if (htab
->fix_erratum_843419_adr
4834 && (imm
>= AARCH64_MIN_ADRP_IMM
&& imm
<= AARCH64_MAX_ADRP_IMM
))
4836 insn
= (_bfd_aarch64_reencode_adr_imm (AARCH64_ADR_OP
, imm
)
4837 | AARCH64_RT (insn
));
4838 bfd_putl32 (insn
, contents
+ stub_entry
->adrp_offset
);
4842 bfd_vma veneered_insn_loc
;
4843 bfd_vma veneer_entry_loc
;
4844 bfd_signed_vma branch_offset
;
4845 uint32_t branch_insn
;
4847 veneered_insn_loc
= stub_entry
->target_section
->output_section
->vma
4848 + stub_entry
->target_section
->output_offset
4849 + stub_entry
->target_value
;
4850 veneer_entry_loc
= stub_entry
->stub_sec
->output_section
->vma
4851 + stub_entry
->stub_sec
->output_offset
4852 + stub_entry
->stub_offset
;
4853 branch_offset
= veneer_entry_loc
- veneered_insn_loc
;
4855 abfd
= stub_entry
->target_section
->owner
;
4856 if (!aarch64_valid_branch_p (veneer_entry_loc
, veneered_insn_loc
))
4858 (_("%B: error: Erratum 843419 stub out "
4859 "of range (input file too large)"), abfd
);
4861 branch_insn
= 0x14000000;
4862 branch_offset
>>= 2;
4863 branch_offset
&= 0x3ffffff;
4864 branch_insn
|= branch_offset
;
4865 bfd_putl32 (branch_insn
, contents
+ stub_entry
->target_value
);
4872 elfNN_aarch64_write_section (bfd
*output_bfd ATTRIBUTE_UNUSED
,
4873 struct bfd_link_info
*link_info
,
4878 struct elf_aarch64_link_hash_table
*globals
=
4879 elf_aarch64_hash_table (link_info
);
4881 if (globals
== NULL
)
4884 /* Fix code to point to erratum 835769 stubs. */
4885 if (globals
->fix_erratum_835769
)
4887 struct erratum_835769_branch_to_stub_data data
;
4889 data
.info
= link_info
;
4890 data
.output_section
= sec
;
4891 data
.contents
= contents
;
4892 bfd_hash_traverse (&globals
->stub_hash_table
,
4893 make_branch_to_erratum_835769_stub
, &data
);
4896 if (globals
->fix_erratum_843419
)
4898 struct erratum_835769_branch_to_stub_data data
;
4900 data
.info
= link_info
;
4901 data
.output_section
= sec
;
4902 data
.contents
= contents
;
4903 bfd_hash_traverse (&globals
->stub_hash_table
,
4904 _bfd_aarch64_erratum_843419_branch_to_stub
, &data
);
4910 /* Perform a relocation as part of a final link. The input relocation type
4911 should be TLS relaxed. */
4913 static bfd_reloc_status_type
4914 elfNN_aarch64_final_link_relocate (reloc_howto_type
*howto
,
4917 asection
*input_section
,
4919 Elf_Internal_Rela
*rel
,
4921 struct bfd_link_info
*info
,
4923 struct elf_link_hash_entry
*h
,
4924 bfd_boolean
*unresolved_reloc_p
,
4925 bfd_boolean save_addend
,
4926 bfd_vma
*saved_addend
,
4927 Elf_Internal_Sym
*sym
)
4929 Elf_Internal_Shdr
*symtab_hdr
;
4930 unsigned int r_type
= howto
->type
;
4931 bfd_reloc_code_real_type bfd_r_type
4932 = elfNN_aarch64_bfd_reloc_from_howto (howto
);
4933 unsigned long r_symndx
;
4934 bfd_byte
*hit_data
= contents
+ rel
->r_offset
;
4936 bfd_signed_vma signed_addend
;
4937 struct elf_aarch64_link_hash_table
*globals
;
4938 bfd_boolean weak_undef_p
;
4941 globals
= elf_aarch64_hash_table (info
);
4943 symtab_hdr
= &elf_symtab_hdr (input_bfd
);
4945 BFD_ASSERT (is_aarch64_elf (input_bfd
));
4947 r_symndx
= ELFNN_R_SYM (rel
->r_info
);
4949 place
= input_section
->output_section
->vma
4950 + input_section
->output_offset
+ rel
->r_offset
;
4952 /* Get addend, accumulating the addend for consecutive relocs
4953 which refer to the same offset. */
4954 signed_addend
= saved_addend
? *saved_addend
: 0;
4955 signed_addend
+= rel
->r_addend
;
4957 weak_undef_p
= (h
? h
->root
.type
== bfd_link_hash_undefweak
4958 : bfd_is_und_section (sym_sec
));
4960 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle
4961 it here if it is defined in a non-shared object. */
4963 && h
->type
== STT_GNU_IFUNC
4970 if ((input_section
->flags
& SEC_ALLOC
) == 0
4971 || h
->plt
.offset
== (bfd_vma
) -1)
4974 /* STT_GNU_IFUNC symbol must go through PLT. */
4975 plt
= globals
->root
.splt
? globals
->root
.splt
: globals
->root
.iplt
;
4976 value
= (plt
->output_section
->vma
+ plt
->output_offset
+ h
->plt
.offset
);
4981 if (h
->root
.root
.string
)
4982 name
= h
->root
.root
.string
;
4984 name
= bfd_elf_sym_name (input_bfd
, symtab_hdr
, sym
,
4987 /* xgettext:c-format */
4988 (_("%B: relocation %s against STT_GNU_IFUNC "
4989 "symbol `%s' isn't handled by %s"), input_bfd
,
4990 howto
->name
, name
, __FUNCTION__
);
4991 bfd_set_error (bfd_error_bad_value
);
4994 case BFD_RELOC_AARCH64_NN
:
4995 if (rel
->r_addend
!= 0)
4997 if (h
->root
.root
.string
)
4998 name
= h
->root
.root
.string
;
5000 name
= bfd_elf_sym_name (input_bfd
, symtab_hdr
,
5003 /* xgettext:c-format */
5004 (_("%B: relocation %s against STT_GNU_IFUNC "
5005 "symbol `%s' has non-zero addend: %d"),
5006 input_bfd
, howto
->name
, name
, rel
->r_addend
);
5007 bfd_set_error (bfd_error_bad_value
);
5011 /* Generate dynamic relocation only when there is a
5012 non-GOT reference in a shared object. */
5013 if (bfd_link_pic (info
) && h
->non_got_ref
)
5015 Elf_Internal_Rela outrel
;
5018 /* Need a dynamic relocation to get the real function
5020 outrel
.r_offset
= _bfd_elf_section_offset (output_bfd
,
5024 if (outrel
.r_offset
== (bfd_vma
) -1
5025 || outrel
.r_offset
== (bfd_vma
) -2)
5028 outrel
.r_offset
+= (input_section
->output_section
->vma
5029 + input_section
->output_offset
);
5031 if (h
->dynindx
== -1
5033 || bfd_link_executable (info
))
5035 /* This symbol is resolved locally. */
5036 outrel
.r_info
= ELFNN_R_INFO (0, AARCH64_R (IRELATIVE
));
5037 outrel
.r_addend
= (h
->root
.u
.def
.value
5038 + h
->root
.u
.def
.section
->output_section
->vma
5039 + h
->root
.u
.def
.section
->output_offset
);
5043 outrel
.r_info
= ELFNN_R_INFO (h
->dynindx
, r_type
);
5044 outrel
.r_addend
= 0;
5047 sreloc
= globals
->root
.irelifunc
;
5048 elf_append_rela (output_bfd
, sreloc
, &outrel
);
5050 /* If this reloc is against an external symbol, we
5051 do not want to fiddle with the addend. Otherwise,
5052 we need to include the symbol value so that it
5053 becomes an addend for the dynamic reloc. For an
5054 internal symbol, we have updated addend. */
5055 return bfd_reloc_ok
;
5058 case BFD_RELOC_AARCH64_CALL26
:
5059 case BFD_RELOC_AARCH64_JUMP26
:
5060 value
= _bfd_aarch64_elf_resolve_relocation (bfd_r_type
, place
, value
,
5063 return _bfd_aarch64_elf_put_addend (input_bfd
, hit_data
, bfd_r_type
,
5065 case BFD_RELOC_AARCH64_ADR_GOT_PAGE
:
5066 case BFD_RELOC_AARCH64_GOT_LD_PREL19
:
5067 case BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14
:
5068 case BFD_RELOC_AARCH64_LD32_GOT_LO12_NC
:
5069 case BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15
:
5070 case BFD_RELOC_AARCH64_MOVW_GOTOFF_G0_NC
:
5071 case BFD_RELOC_AARCH64_MOVW_GOTOFF_G1
:
5072 case BFD_RELOC_AARCH64_LD64_GOTOFF_LO15
:
5073 case BFD_RELOC_AARCH64_LD64_GOT_LO12_NC
:
5074 base_got
= globals
->root
.sgot
;
5075 off
= h
->got
.offset
;
5077 if (base_got
== NULL
)
5080 if (off
== (bfd_vma
) -1)
5084 /* We can't use h->got.offset here to save state, or
5085 even just remember the offset, as finish_dynamic_symbol
5086 would use that as offset into .got. */
5088 if (globals
->root
.splt
!= NULL
)
5090 plt_index
= ((h
->plt
.offset
- globals
->plt_header_size
) /
5091 globals
->plt_entry_size
);
5092 off
= (plt_index
+ 3) * GOT_ENTRY_SIZE
;
5093 base_got
= globals
->root
.sgotplt
;
5097 plt_index
= h
->plt
.offset
/ globals
->plt_entry_size
;
5098 off
= plt_index
* GOT_ENTRY_SIZE
;
5099 base_got
= globals
->root
.igotplt
;
5102 if (h
->dynindx
== -1
5106 /* This references the local definition. We must
5107 initialize this entry in the global offset table.
5108 Since the offset must always be a multiple of 8,
5109 we use the least significant bit to record
5110 whether we have initialized it already.
5112 When doing a dynamic link, we create a .rela.got
5113 relocation entry to initialize the value. This
5114 is done in the finish_dynamic_symbol routine. */
5119 bfd_put_NN (output_bfd
, value
,
5120 base_got
->contents
+ off
);
5121 /* Note that this is harmless as -1 | 1 still is -1. */
5125 value
= (base_got
->output_section
->vma
5126 + base_got
->output_offset
+ off
);
5129 value
= aarch64_calculate_got_entry_vma (h
, globals
, info
,
5131 unresolved_reloc_p
);
5135 case BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14
:
5136 case BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15
:
5137 addend
= (globals
->root
.sgot
->output_section
->vma
5138 + globals
->root
.sgot
->output_offset
);
5140 case BFD_RELOC_AARCH64_MOVW_GOTOFF_G0_NC
:
5141 case BFD_RELOC_AARCH64_MOVW_GOTOFF_G1
:
5142 case BFD_RELOC_AARCH64_LD64_GOTOFF_LO15
:
5143 value
= (value
- globals
->root
.sgot
->output_section
->vma
5144 - globals
->root
.sgot
->output_offset
);
5149 value
= _bfd_aarch64_elf_resolve_relocation (bfd_r_type
, place
, value
,
5150 addend
, weak_undef_p
);
5151 return _bfd_aarch64_elf_put_addend (input_bfd
, hit_data
, bfd_r_type
, howto
, value
);
5152 case BFD_RELOC_AARCH64_ADD_LO12
:
5153 case BFD_RELOC_AARCH64_ADR_HI21_PCREL
:
5160 case BFD_RELOC_AARCH64_NONE
:
5161 case BFD_RELOC_AARCH64_TLSDESC_ADD
:
5162 case BFD_RELOC_AARCH64_TLSDESC_CALL
:
5163 case BFD_RELOC_AARCH64_TLSDESC_LDR
:
5164 *unresolved_reloc_p
= FALSE
;
5165 return bfd_reloc_ok
;
5167 case BFD_RELOC_AARCH64_NN
:
5169 /* When generating a shared object or relocatable executable, these
5170 relocations are copied into the output file to be resolved at
5172 if (((bfd_link_pic (info
) == TRUE
)
5173 || globals
->root
.is_relocatable_executable
)
5174 && (input_section
->flags
& SEC_ALLOC
)
5176 || ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
5177 || h
->root
.type
!= bfd_link_hash_undefweak
))
5179 Elf_Internal_Rela outrel
;
5181 bfd_boolean skip
, relocate
;
5184 *unresolved_reloc_p
= FALSE
;
5189 outrel
.r_addend
= signed_addend
;
5191 _bfd_elf_section_offset (output_bfd
, info
, input_section
,
5193 if (outrel
.r_offset
== (bfd_vma
) - 1)
5195 else if (outrel
.r_offset
== (bfd_vma
) - 2)
5201 outrel
.r_offset
+= (input_section
->output_section
->vma
5202 + input_section
->output_offset
);
5205 memset (&outrel
, 0, sizeof outrel
);
5208 && (!bfd_link_pic (info
)
5209 || !(bfd_link_pie (info
)
5210 || SYMBOLIC_BIND (info
, h
))
5211 || !h
->def_regular
))
5212 outrel
.r_info
= ELFNN_R_INFO (h
->dynindx
, r_type
);
5217 /* On SVR4-ish systems, the dynamic loader cannot
5218 relocate the text and data segments independently,
5219 so the symbol does not matter. */
5221 relocate
= globals
->no_apply_dynamic_relocs
? FALSE
: TRUE
;
5222 outrel
.r_info
= ELFNN_R_INFO (symbol
, AARCH64_R (RELATIVE
));
5223 outrel
.r_addend
+= value
;
5226 sreloc
= elf_section_data (input_section
)->sreloc
;
5227 if (sreloc
== NULL
|| sreloc
->contents
== NULL
)
5228 return bfd_reloc_notsupported
;
5230 loc
= sreloc
->contents
+ sreloc
->reloc_count
++ * RELOC_SIZE (globals
);
5231 bfd_elfNN_swap_reloca_out (output_bfd
, &outrel
, loc
);
5233 if (sreloc
->reloc_count
* RELOC_SIZE (globals
) > sreloc
->size
)
5235 /* Sanity to check that we have previously allocated
5236 sufficient space in the relocation section for the
5237 number of relocations we actually want to emit. */
5241 /* If this reloc is against an external symbol, we do not want to
5242 fiddle with the addend. Otherwise, we need to include the symbol
5243 value so that it becomes an addend for the dynamic reloc. */
5245 return bfd_reloc_ok
;
5247 return _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
5248 contents
, rel
->r_offset
, value
,
5252 value
+= signed_addend
;
5255 case BFD_RELOC_AARCH64_CALL26
:
5256 case BFD_RELOC_AARCH64_JUMP26
:
5258 asection
*splt
= globals
->root
.splt
;
5259 bfd_boolean via_plt_p
=
5260 splt
!= NULL
&& h
!= NULL
&& h
->plt
.offset
!= (bfd_vma
) - 1;
5262 /* A call to an undefined weak symbol is converted to a jump to
5263 the next instruction unless a PLT entry will be created.
5264 The jump to the next instruction is optimized as a NOP.
5265 Do the same for local undefined symbols. */
5266 if (weak_undef_p
&& ! via_plt_p
)
5268 bfd_putl32 (INSN_NOP
, hit_data
);
5269 return bfd_reloc_ok
;
5272 /* If the call goes through a PLT entry, make sure to
5273 check distance to the right destination address. */
5275 value
= (splt
->output_section
->vma
5276 + splt
->output_offset
+ h
->plt
.offset
);
5278 /* Check if a stub has to be inserted because the destination
5280 struct elf_aarch64_stub_hash_entry
*stub_entry
= NULL
;
5282 /* If the branch destination is directed to plt stub, "value" will be
5283 the final destination, otherwise we should plus signed_addend, it may
5284 contain non-zero value, for example call to local function symbol
5285 which are turned into "sec_sym + sec_off", and sec_off is kept in
5287 if (! aarch64_valid_branch_p (via_plt_p
? value
: value
+ signed_addend
,
5289 /* The target is out of reach, so redirect the branch to
5290 the local stub for this function. */
5291 stub_entry
= elfNN_aarch64_get_stub_entry (input_section
, sym_sec
, h
,
5293 if (stub_entry
!= NULL
)
5295 value
= (stub_entry
->stub_offset
5296 + stub_entry
->stub_sec
->output_offset
5297 + stub_entry
->stub_sec
->output_section
->vma
);
5299 /* We have redirected the destination to stub entry address,
5300 so ignore any addend record in the original rela entry. */
5304 value
= _bfd_aarch64_elf_resolve_relocation (bfd_r_type
, place
, value
,
5305 signed_addend
, weak_undef_p
);
5306 *unresolved_reloc_p
= FALSE
;
5309 case BFD_RELOC_AARCH64_16_PCREL
:
5310 case BFD_RELOC_AARCH64_32_PCREL
:
5311 case BFD_RELOC_AARCH64_64_PCREL
:
5312 case BFD_RELOC_AARCH64_ADR_HI21_NC_PCREL
:
5313 case BFD_RELOC_AARCH64_ADR_HI21_PCREL
:
5314 case BFD_RELOC_AARCH64_ADR_LO21_PCREL
:
5315 case BFD_RELOC_AARCH64_LD_LO19_PCREL
:
5316 if (bfd_link_pic (info
)
5317 && (input_section
->flags
& SEC_ALLOC
) != 0
5318 && (input_section
->flags
& SEC_READONLY
) != 0
5322 int howto_index
= bfd_r_type
- BFD_RELOC_AARCH64_RELOC_START
;
5325 /* xgettext:c-format */
5326 (_("%B: relocation %s against external symbol `%s' can not be used"
5327 " when making a shared object; recompile with -fPIC"),
5328 input_bfd
, elfNN_aarch64_howto_table
[howto_index
].name
,
5329 h
->root
.root
.string
);
5330 bfd_set_error (bfd_error_bad_value
);
5335 case BFD_RELOC_AARCH64_16
:
5337 case BFD_RELOC_AARCH64_32
:
5339 case BFD_RELOC_AARCH64_ADD_LO12
:
5340 case BFD_RELOC_AARCH64_BRANCH19
:
5341 case BFD_RELOC_AARCH64_LDST128_LO12
:
5342 case BFD_RELOC_AARCH64_LDST16_LO12
:
5343 case BFD_RELOC_AARCH64_LDST32_LO12
:
5344 case BFD_RELOC_AARCH64_LDST64_LO12
:
5345 case BFD_RELOC_AARCH64_LDST8_LO12
:
5346 case BFD_RELOC_AARCH64_MOVW_G0
:
5347 case BFD_RELOC_AARCH64_MOVW_G0_NC
:
5348 case BFD_RELOC_AARCH64_MOVW_G0_S
:
5349 case BFD_RELOC_AARCH64_MOVW_G1
:
5350 case BFD_RELOC_AARCH64_MOVW_G1_NC
:
5351 case BFD_RELOC_AARCH64_MOVW_G1_S
:
5352 case BFD_RELOC_AARCH64_MOVW_G2
:
5353 case BFD_RELOC_AARCH64_MOVW_G2_NC
:
5354 case BFD_RELOC_AARCH64_MOVW_G2_S
:
5355 case BFD_RELOC_AARCH64_MOVW_G3
:
5356 case BFD_RELOC_AARCH64_TSTBR14
:
5357 value
= _bfd_aarch64_elf_resolve_relocation (bfd_r_type
, place
, value
,
5358 signed_addend
, weak_undef_p
);
5361 case BFD_RELOC_AARCH64_ADR_GOT_PAGE
:
5362 case BFD_RELOC_AARCH64_GOT_LD_PREL19
:
5363 case BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14
:
5364 case BFD_RELOC_AARCH64_LD32_GOT_LO12_NC
:
5365 case BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15
:
5366 case BFD_RELOC_AARCH64_LD64_GOT_LO12_NC
:
5367 if (globals
->root
.sgot
== NULL
)
5368 BFD_ASSERT (h
!= NULL
);
5373 value
= aarch64_calculate_got_entry_vma (h
, globals
, info
, value
,
5375 unresolved_reloc_p
);
5376 if (bfd_r_type
== BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15
5377 || bfd_r_type
== BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14
)
5378 addend
= (globals
->root
.sgot
->output_section
->vma
5379 + globals
->root
.sgot
->output_offset
);
5380 value
= _bfd_aarch64_elf_resolve_relocation (bfd_r_type
, place
, value
,
5381 addend
, weak_undef_p
);
5386 struct elf_aarch64_local_symbol
*locals
5387 = elf_aarch64_locals (input_bfd
);
5391 int howto_index
= bfd_r_type
- BFD_RELOC_AARCH64_RELOC_START
;
5393 /* xgettext:c-format */
5394 (_("%B: Local symbol descriptor table be NULL when applying "
5395 "relocation %s against local symbol"),
5396 input_bfd
, elfNN_aarch64_howto_table
[howto_index
].name
);
5400 off
= symbol_got_offset (input_bfd
, h
, r_symndx
);
5401 base_got
= globals
->root
.sgot
;
5402 bfd_vma got_entry_addr
= (base_got
->output_section
->vma
5403 + base_got
->output_offset
+ off
);
5405 if (!symbol_got_offset_mark_p (input_bfd
, h
, r_symndx
))
5407 bfd_put_64 (output_bfd
, value
, base_got
->contents
+ off
);
5409 if (bfd_link_pic (info
))
5412 Elf_Internal_Rela outrel
;
5414 /* For local symbol, we have done absolute relocation in static
5415 linking stageh. While for share library, we need to update
5416 the content of GOT entry according to the share objects
5417 loading base address. So we need to generate a
5418 R_AARCH64_RELATIVE reloc for dynamic linker. */
5419 s
= globals
->root
.srelgot
;
5423 outrel
.r_offset
= got_entry_addr
;
5424 outrel
.r_info
= ELFNN_R_INFO (0, AARCH64_R (RELATIVE
));
5425 outrel
.r_addend
= value
;
5426 elf_append_rela (output_bfd
, s
, &outrel
);
5429 symbol_got_offset_mark (input_bfd
, h
, r_symndx
);
5432 /* Update the relocation value to GOT entry addr as we have transformed
5433 the direct data access into indirect data access through GOT. */
5434 value
= got_entry_addr
;
5436 if (bfd_r_type
== BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15
5437 || bfd_r_type
== BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14
)
5438 addend
= base_got
->output_section
->vma
+ base_got
->output_offset
;
5440 value
= _bfd_aarch64_elf_resolve_relocation (bfd_r_type
, place
, value
,
5441 addend
, weak_undef_p
);
5446 case BFD_RELOC_AARCH64_LD64_GOTOFF_LO15
:
5447 case BFD_RELOC_AARCH64_MOVW_GOTOFF_G0_NC
:
5448 case BFD_RELOC_AARCH64_MOVW_GOTOFF_G1
:
5450 value
= aarch64_calculate_got_entry_vma (h
, globals
, info
, value
,
5452 unresolved_reloc_p
);
5455 struct elf_aarch64_local_symbol
*locals
5456 = elf_aarch64_locals (input_bfd
);
5460 int howto_index
= bfd_r_type
- BFD_RELOC_AARCH64_RELOC_START
;
5462 /* xgettext:c-format */
5463 (_("%B: Local symbol descriptor table be NULL when applying "
5464 "relocation %s against local symbol"),
5465 input_bfd
, elfNN_aarch64_howto_table
[howto_index
].name
);
5469 off
= symbol_got_offset (input_bfd
, h
, r_symndx
);
5470 base_got
= globals
->root
.sgot
;
5471 if (base_got
== NULL
)
5474 bfd_vma got_entry_addr
= (base_got
->output_section
->vma
5475 + base_got
->output_offset
+ off
);
5477 if (!symbol_got_offset_mark_p (input_bfd
, h
, r_symndx
))
5479 bfd_put_64 (output_bfd
, value
, base_got
->contents
+ off
);
5481 if (bfd_link_pic (info
))
5484 Elf_Internal_Rela outrel
;
5486 /* For local symbol, we have done absolute relocation in static
5487 linking stage. While for share library, we need to update
5488 the content of GOT entry according to the share objects
5489 loading base address. So we need to generate a
5490 R_AARCH64_RELATIVE reloc for dynamic linker. */
5491 s
= globals
->root
.srelgot
;
5495 outrel
.r_offset
= got_entry_addr
;
5496 outrel
.r_info
= ELFNN_R_INFO (0, AARCH64_R (RELATIVE
));
5497 outrel
.r_addend
= value
;
5498 elf_append_rela (output_bfd
, s
, &outrel
);
5501 symbol_got_offset_mark (input_bfd
, h
, r_symndx
);
5505 /* Update the relocation value to GOT entry addr as we have transformed
5506 the direct data access into indirect data access through GOT. */
5507 value
= symbol_got_offset (input_bfd
, h
, r_symndx
);
5508 value
= _bfd_aarch64_elf_resolve_relocation (bfd_r_type
, place
, value
,
5510 *unresolved_reloc_p
= FALSE
;
5513 case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC
:
5514 case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21
:
5515 case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21
:
5516 case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21
:
5517 case BFD_RELOC_AARCH64_TLSIE_LD32_GOTTPREL_LO12_NC
:
5518 case BFD_RELOC_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC
:
5519 case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19
:
5520 case BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC
:
5521 case BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21
:
5522 case BFD_RELOC_AARCH64_TLSLD_ADR_PREL21
:
5523 if (globals
->root
.sgot
== NULL
)
5524 return bfd_reloc_notsupported
;
5526 value
= (symbol_got_offset (input_bfd
, h
, r_symndx
)
5527 + globals
->root
.sgot
->output_section
->vma
5528 + globals
->root
.sgot
->output_offset
);
5530 value
= _bfd_aarch64_elf_resolve_relocation (bfd_r_type
, place
, value
,
5532 *unresolved_reloc_p
= FALSE
;
5535 case BFD_RELOC_AARCH64_TLSGD_MOVW_G0_NC
:
5536 case BFD_RELOC_AARCH64_TLSGD_MOVW_G1
:
5537 case BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G0_NC
:
5538 case BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G1
:
5539 if (globals
->root
.sgot
== NULL
)
5540 return bfd_reloc_notsupported
;
5542 value
= symbol_got_offset (input_bfd
, h
, r_symndx
);
5543 value
= _bfd_aarch64_elf_resolve_relocation (bfd_r_type
, place
, value
,
5545 *unresolved_reloc_p
= FALSE
;
5548 case BFD_RELOC_AARCH64_TLSLD_ADD_DTPREL_HI12
:
5549 case BFD_RELOC_AARCH64_TLSLD_ADD_DTPREL_LO12
:
5550 case BFD_RELOC_AARCH64_TLSLD_ADD_DTPREL_LO12_NC
:
5551 case BFD_RELOC_AARCH64_TLSLD_LDST16_DTPREL_LO12
:
5552 case BFD_RELOC_AARCH64_TLSLD_LDST16_DTPREL_LO12_NC
:
5553 case BFD_RELOC_AARCH64_TLSLD_LDST32_DTPREL_LO12
:
5554 case BFD_RELOC_AARCH64_TLSLD_LDST32_DTPREL_LO12_NC
:
5555 case BFD_RELOC_AARCH64_TLSLD_LDST64_DTPREL_LO12
:
5556 case BFD_RELOC_AARCH64_TLSLD_LDST64_DTPREL_LO12_NC
:
5557 case BFD_RELOC_AARCH64_TLSLD_LDST8_DTPREL_LO12
:
5558 case BFD_RELOC_AARCH64_TLSLD_LDST8_DTPREL_LO12_NC
:
5559 case BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G0
:
5560 case BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G0_NC
:
5561 case BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G1
:
5562 case BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G1_NC
:
5563 case BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G2
:
5564 value
= _bfd_aarch64_elf_resolve_relocation (bfd_r_type
, place
, value
,
5565 signed_addend
- dtpoff_base (info
),
5569 case BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_HI12
:
5570 case BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_LO12
:
5571 case BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_LO12_NC
:
5572 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0
:
5573 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC
:
5574 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1
:
5575 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1_NC
:
5576 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G2
:
5577 value
= _bfd_aarch64_elf_resolve_relocation (bfd_r_type
, place
, value
,
5578 signed_addend
- tpoff_base (info
),
5580 *unresolved_reloc_p
= FALSE
;
5583 case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12
:
5584 case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21
:
5585 case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21
:
5586 case BFD_RELOC_AARCH64_TLSDESC_LD32_LO12_NC
:
5587 case BFD_RELOC_AARCH64_TLSDESC_LD64_LO12
:
5588 case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19
:
5589 if (globals
->root
.sgot
== NULL
)
5590 return bfd_reloc_notsupported
;
5591 value
= (symbol_tlsdesc_got_offset (input_bfd
, h
, r_symndx
)
5592 + globals
->root
.sgotplt
->output_section
->vma
5593 + globals
->root
.sgotplt
->output_offset
5594 + globals
->sgotplt_jump_table_size
);
5596 value
= _bfd_aarch64_elf_resolve_relocation (bfd_r_type
, place
, value
,
5598 *unresolved_reloc_p
= FALSE
;
5601 case BFD_RELOC_AARCH64_TLSDESC_OFF_G0_NC
:
5602 case BFD_RELOC_AARCH64_TLSDESC_OFF_G1
:
5603 if (globals
->root
.sgot
== NULL
)
5604 return bfd_reloc_notsupported
;
5606 value
= (symbol_tlsdesc_got_offset (input_bfd
, h
, r_symndx
)
5607 + globals
->root
.sgotplt
->output_section
->vma
5608 + globals
->root
.sgotplt
->output_offset
5609 + globals
->sgotplt_jump_table_size
);
5611 value
-= (globals
->root
.sgot
->output_section
->vma
5612 + globals
->root
.sgot
->output_offset
);
5614 value
= _bfd_aarch64_elf_resolve_relocation (bfd_r_type
, place
, value
,
5616 *unresolved_reloc_p
= FALSE
;
5620 return bfd_reloc_notsupported
;
5624 *saved_addend
= value
;
5626 /* Only apply the final relocation in a sequence. */
5628 return bfd_reloc_continue
;
5630 return _bfd_aarch64_elf_put_addend (input_bfd
, hit_data
, bfd_r_type
,
5634 /* LP64 and ILP32 operates on x- and w-registers respectively.
5635 Next definitions take into account the difference between
5636 corresponding machine codes. R means x-register if the target
5637 arch is LP64, and w-register if the target is ILP32. */
5640 # define add_R0_R0 (0x91000000)
5641 # define add_R0_R0_R1 (0x8b000020)
5642 # define add_R0_R1 (0x91400020)
5643 # define ldr_R0 (0x58000000)
5644 # define ldr_R0_mask(i) (i & 0xffffffe0)
5645 # define ldr_R0_x0 (0xf9400000)
5646 # define ldr_hw_R0 (0xf2a00000)
5647 # define movk_R0 (0xf2800000)
5648 # define movz_R0 (0xd2a00000)
5649 # define movz_hw_R0 (0xd2c00000)
5650 #else /*ARCH_SIZE == 32 */
5651 # define add_R0_R0 (0x11000000)
5652 # define add_R0_R0_R1 (0x0b000020)
5653 # define add_R0_R1 (0x11400020)
5654 # define ldr_R0 (0x18000000)
5655 # define ldr_R0_mask(i) (i & 0xbfffffe0)
5656 # define ldr_R0_x0 (0xb9400000)
5657 # define ldr_hw_R0 (0x72a00000)
5658 # define movk_R0 (0x72800000)
5659 # define movz_R0 (0x52a00000)
5660 # define movz_hw_R0 (0x52c00000)
5663 /* Handle TLS relaxations. Relaxing is possible for symbols that use
5664 R_AARCH64_TLSDESC_ADR_{PAGE, LD64_LO12_NC, ADD_LO12_NC} during a static
5667 Return bfd_reloc_ok if we're done, bfd_reloc_continue if the caller
5668 is to then call final_link_relocate. Return other values in the
5671 static bfd_reloc_status_type
5672 elfNN_aarch64_tls_relax (struct elf_aarch64_link_hash_table
*globals
,
5673 bfd
*input_bfd
, bfd_byte
*contents
,
5674 Elf_Internal_Rela
*rel
, struct elf_link_hash_entry
*h
)
5676 bfd_boolean is_local
= h
== NULL
;
5677 unsigned int r_type
= ELFNN_R_TYPE (rel
->r_info
);
5680 BFD_ASSERT (globals
&& input_bfd
&& contents
&& rel
);
5682 switch (elfNN_aarch64_bfd_reloc_from_type (r_type
))
5684 case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21
:
5685 case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21
:
5688 /* GD->LE relaxation:
5689 adrp x0, :tlsgd:var => movz R0, :tprel_g1:var
5691 adrp x0, :tlsdesc:var => movz R0, :tprel_g1:var
5693 Where R is x for LP64, and w for ILP32. */
5694 bfd_putl32 (movz_R0
, contents
+ rel
->r_offset
);
5695 return bfd_reloc_continue
;
5699 /* GD->IE relaxation:
5700 adrp x0, :tlsgd:var => adrp x0, :gottprel:var
5702 adrp x0, :tlsdesc:var => adrp x0, :gottprel:var
5704 return bfd_reloc_continue
;
5707 case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21
:
5711 case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19
:
5714 /* Tiny TLSDESC->LE relaxation:
5715 ldr x1, :tlsdesc:var => movz R0, #:tprel_g1:var
5716 adr x0, :tlsdesc:var => movk R0, #:tprel_g0_nc:var
5720 Where R is x for LP64, and w for ILP32. */
5721 BFD_ASSERT (ELFNN_R_TYPE (rel
[1].r_info
) == AARCH64_R (TLSDESC_ADR_PREL21
));
5722 BFD_ASSERT (ELFNN_R_TYPE (rel
[2].r_info
) == AARCH64_R (TLSDESC_CALL
));
5724 rel
[1].r_info
= ELFNN_R_INFO (ELFNN_R_SYM (rel
->r_info
),
5725 AARCH64_R (TLSLE_MOVW_TPREL_G0_NC
));
5726 rel
[2].r_info
= ELFNN_R_INFO (STN_UNDEF
, R_AARCH64_NONE
);
5728 bfd_putl32 (movz_R0
, contents
+ rel
->r_offset
);
5729 bfd_putl32 (movk_R0
, contents
+ rel
->r_offset
+ 4);
5730 bfd_putl32 (INSN_NOP
, contents
+ rel
->r_offset
+ 8);
5731 return bfd_reloc_continue
;
5735 /* Tiny TLSDESC->IE relaxation:
5736 ldr x1, :tlsdesc:var => ldr x0, :gottprel:var
5737 adr x0, :tlsdesc:var => nop
5741 BFD_ASSERT (ELFNN_R_TYPE (rel
[1].r_info
) == AARCH64_R (TLSDESC_ADR_PREL21
));
5742 BFD_ASSERT (ELFNN_R_TYPE (rel
[2].r_info
) == AARCH64_R (TLSDESC_CALL
));
5744 rel
[1].r_info
= ELFNN_R_INFO (STN_UNDEF
, R_AARCH64_NONE
);
5745 rel
[2].r_info
= ELFNN_R_INFO (STN_UNDEF
, R_AARCH64_NONE
);
5747 bfd_putl32 (ldr_R0
, contents
+ rel
->r_offset
);
5748 bfd_putl32 (INSN_NOP
, contents
+ rel
->r_offset
+ 4);
5749 bfd_putl32 (INSN_NOP
, contents
+ rel
->r_offset
+ 8);
5750 return bfd_reloc_continue
;
5753 case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21
:
5756 /* Tiny GD->LE relaxation:
5757 adr x0, :tlsgd:var => mrs x1, tpidr_el0
5758 bl __tls_get_addr => add R0, R1, #:tprel_hi12:x, lsl #12
5759 nop => add R0, R0, #:tprel_lo12_nc:x
5761 Where R is x for LP64, and x for Ilp32. */
5763 /* First kill the tls_get_addr reloc on the bl instruction. */
5764 BFD_ASSERT (rel
->r_offset
+ 4 == rel
[1].r_offset
);
5766 bfd_putl32 (0xd53bd041, contents
+ rel
->r_offset
+ 0);
5767 bfd_putl32 (add_R0_R1
, contents
+ rel
->r_offset
+ 4);
5768 bfd_putl32 (add_R0_R0
, contents
+ rel
->r_offset
+ 8);
5770 rel
[1].r_info
= ELFNN_R_INFO (ELFNN_R_SYM (rel
->r_info
),
5771 AARCH64_R (TLSLE_ADD_TPREL_LO12_NC
));
5772 rel
[1].r_offset
= rel
->r_offset
+ 8;
5774 /* Move the current relocation to the second instruction in
5777 rel
->r_info
= ELFNN_R_INFO (ELFNN_R_SYM (rel
->r_info
),
5778 AARCH64_R (TLSLE_ADD_TPREL_HI12
));
5779 return bfd_reloc_continue
;
5783 /* Tiny GD->IE relaxation:
5784 adr x0, :tlsgd:var => ldr R0, :gottprel:var
5785 bl __tls_get_addr => mrs x1, tpidr_el0
5786 nop => add R0, R0, R1
5788 Where R is x for LP64, and w for Ilp32. */
5790 /* First kill the tls_get_addr reloc on the bl instruction. */
5791 BFD_ASSERT (rel
->r_offset
+ 4 == rel
[1].r_offset
);
5792 rel
[1].r_info
= ELFNN_R_INFO (STN_UNDEF
, R_AARCH64_NONE
);
5794 bfd_putl32 (ldr_R0
, contents
+ rel
->r_offset
);
5795 bfd_putl32 (0xd53bd041, contents
+ rel
->r_offset
+ 4);
5796 bfd_putl32 (add_R0_R0_R1
, contents
+ rel
->r_offset
+ 8);
5797 return bfd_reloc_continue
;
5801 case BFD_RELOC_AARCH64_TLSGD_MOVW_G1
:
5802 BFD_ASSERT (ELFNN_R_TYPE (rel
[1].r_info
) == AARCH64_R (TLSGD_MOVW_G0_NC
));
5803 BFD_ASSERT (rel
->r_offset
+ 12 == rel
[2].r_offset
);
5804 BFD_ASSERT (ELFNN_R_TYPE (rel
[2].r_info
) == AARCH64_R (CALL26
));
5808 /* Large GD->LE relaxation:
5809 movz x0, #:tlsgd_g1:var => movz x0, #:tprel_g2:var, lsl #32
5810 movk x0, #:tlsgd_g0_nc:var => movk x0, #:tprel_g1_nc:var, lsl #16
5811 add x0, gp, x0 => movk x0, #:tprel_g0_nc:var
5812 bl __tls_get_addr => mrs x1, tpidr_el0
5813 nop => add x0, x0, x1
5815 rel
[2].r_info
= ELFNN_R_INFO (ELFNN_R_SYM (rel
->r_info
),
5816 AARCH64_R (TLSLE_MOVW_TPREL_G0_NC
));
5817 rel
[2].r_offset
= rel
->r_offset
+ 8;
5819 bfd_putl32 (movz_hw_R0
, contents
+ rel
->r_offset
+ 0);
5820 bfd_putl32 (ldr_hw_R0
, contents
+ rel
->r_offset
+ 4);
5821 bfd_putl32 (movk_R0
, contents
+ rel
->r_offset
+ 8);
5822 bfd_putl32 (0xd53bd041, contents
+ rel
->r_offset
+ 12);
5823 bfd_putl32 (add_R0_R0_R1
, contents
+ rel
->r_offset
+ 16);
5827 /* Large GD->IE relaxation:
5828 movz x0, #:tlsgd_g1:var => movz x0, #:gottprel_g1:var, lsl #16
5829 movk x0, #:tlsgd_g0_nc:var => movk x0, #:gottprel_g0_nc:var
5830 add x0, gp, x0 => ldr x0, [gp, x0]
5831 bl __tls_get_addr => mrs x1, tpidr_el0
5832 nop => add x0, x0, x1
5834 rel
[2].r_info
= ELFNN_R_INFO (STN_UNDEF
, R_AARCH64_NONE
);
5835 bfd_putl32 (0xd2a80000, contents
+ rel
->r_offset
+ 0);
5836 bfd_putl32 (ldr_R0
, contents
+ rel
->r_offset
+ 8);
5837 bfd_putl32 (0xd53bd041, contents
+ rel
->r_offset
+ 12);
5838 bfd_putl32 (add_R0_R0_R1
, contents
+ rel
->r_offset
+ 16);
5840 return bfd_reloc_continue
;
5842 case BFD_RELOC_AARCH64_TLSGD_MOVW_G0_NC
:
5843 return bfd_reloc_continue
;
5846 case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19
:
5847 return bfd_reloc_continue
;
5849 case BFD_RELOC_AARCH64_TLSDESC_LDNN_LO12_NC
:
5852 /* GD->LE relaxation:
5853 ldr xd, [x0, #:tlsdesc_lo12:var] => movk x0, :tprel_g0_nc:var
5855 Where R is x for lp64 mode, and w for ILP32 mode. */
5856 bfd_putl32 (movk_R0
, contents
+ rel
->r_offset
);
5857 return bfd_reloc_continue
;
5861 /* GD->IE relaxation:
5862 ldr xd, [x0, #:tlsdesc_lo12:var] => ldr R0, [x0, #:gottprel_lo12:var]
5864 Where R is x for lp64 mode, and w for ILP32 mode. */
5865 insn
= bfd_getl32 (contents
+ rel
->r_offset
);
5866 bfd_putl32 (ldr_R0_mask (insn
), contents
+ rel
->r_offset
);
5867 return bfd_reloc_continue
;
5870 case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC
:
5873 /* GD->LE relaxation
5874 add x0, #:tlsgd_lo12:var => movk R0, :tprel_g0_nc:var
5875 bl __tls_get_addr => mrs x1, tpidr_el0
5876 nop => add R0, R1, R0
5878 Where R is x for lp64 mode, and w for ILP32 mode. */
5880 /* First kill the tls_get_addr reloc on the bl instruction. */
5881 BFD_ASSERT (rel
->r_offset
+ 4 == rel
[1].r_offset
);
5882 rel
[1].r_info
= ELFNN_R_INFO (STN_UNDEF
, R_AARCH64_NONE
);
5884 bfd_putl32 (movk_R0
, contents
+ rel
->r_offset
);
5885 bfd_putl32 (0xd53bd041, contents
+ rel
->r_offset
+ 4);
5886 bfd_putl32 (add_R0_R0_R1
, contents
+ rel
->r_offset
+ 8);
5887 return bfd_reloc_continue
;
5891 /* GD->IE relaxation
5892 ADD x0, #:tlsgd_lo12:var => ldr R0, [x0, #:gottprel_lo12:var]
5893 BL __tls_get_addr => mrs x1, tpidr_el0
5895 NOP => add R0, R1, R0
5897 Where R is x for lp64 mode, and w for ilp32 mode. */
5899 BFD_ASSERT (ELFNN_R_TYPE (rel
[1].r_info
) == AARCH64_R (CALL26
));
5901 /* Remove the relocation on the BL instruction. */
5902 rel
[1].r_info
= ELFNN_R_INFO (STN_UNDEF
, R_AARCH64_NONE
);
5904 /* We choose to fixup the BL and NOP instructions using the
5905 offset from the second relocation to allow flexibility in
5906 scheduling instructions between the ADD and BL. */
5907 bfd_putl32 (ldr_R0_x0
, contents
+ rel
->r_offset
);
5908 bfd_putl32 (0xd53bd041, contents
+ rel
[1].r_offset
);
5909 bfd_putl32 (add_R0_R0_R1
, contents
+ rel
[1].r_offset
+ 4);
5910 return bfd_reloc_continue
;
5913 case BFD_RELOC_AARCH64_TLSDESC_ADD
:
5914 case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12
:
5915 case BFD_RELOC_AARCH64_TLSDESC_CALL
:
5916 /* GD->IE/LE relaxation:
5917 add x0, x0, #:tlsdesc_lo12:var => nop
5920 bfd_putl32 (INSN_NOP
, contents
+ rel
->r_offset
);
5921 return bfd_reloc_ok
;
5923 case BFD_RELOC_AARCH64_TLSDESC_LDR
:
5926 /* GD->LE relaxation:
5927 ldr xd, [gp, xn] => movk R0, #:tprel_g0_nc:var
5929 Where R is x for lp64 mode, and w for ILP32 mode. */
5930 bfd_putl32 (movk_R0
, contents
+ rel
->r_offset
);
5931 return bfd_reloc_continue
;
5935 /* GD->IE relaxation:
5936 ldr xd, [gp, xn] => ldr R0, [gp, xn]
5938 Where R is x for lp64 mode, and w for ILP32 mode. */
5939 insn
= bfd_getl32 (contents
+ rel
->r_offset
);
5940 bfd_putl32 (ldr_R0_mask (insn
), contents
+ rel
->r_offset
);
5941 return bfd_reloc_ok
;
5944 case BFD_RELOC_AARCH64_TLSDESC_OFF_G0_NC
:
5945 /* GD->LE relaxation:
5946 movk xd, #:tlsdesc_off_g0_nc:var => movk R0, #:tprel_g1_nc:var, lsl #16
5948 movk xd, #:tlsdesc_off_g0_nc:var => movk Rd, #:gottprel_g0_nc:var
5950 Where R is x for lp64 mode, and w for ILP32 mode. */
5952 bfd_putl32 (ldr_hw_R0
, contents
+ rel
->r_offset
);
5953 return bfd_reloc_continue
;
5955 case BFD_RELOC_AARCH64_TLSDESC_OFF_G1
:
5958 /* GD->LE relaxation:
5959 movz xd, #:tlsdesc_off_g1:var => movz R0, #:tprel_g2:var, lsl #32
5961 Where R is x for lp64 mode, and w for ILP32 mode. */
5962 bfd_putl32 (movz_hw_R0
, contents
+ rel
->r_offset
);
5963 return bfd_reloc_continue
;
5967 /* GD->IE relaxation:
5968 movz xd, #:tlsdesc_off_g1:var => movz Rd, #:gottprel_g1:var, lsl #16
5970 Where R is x for lp64 mode, and w for ILP32 mode. */
5971 insn
= bfd_getl32 (contents
+ rel
->r_offset
);
5972 bfd_putl32 (movz_R0
| (insn
& 0x1f), contents
+ rel
->r_offset
);
5973 return bfd_reloc_continue
;
5976 case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21
:
5977 /* IE->LE relaxation:
5978 adrp xd, :gottprel:var => movz Rd, :tprel_g1:var
5980 Where R is x for lp64 mode, and w for ILP32 mode. */
5983 insn
= bfd_getl32 (contents
+ rel
->r_offset
);
5984 bfd_putl32 (movz_R0
| (insn
& 0x1f), contents
+ rel
->r_offset
);
5986 return bfd_reloc_continue
;
5988 case BFD_RELOC_AARCH64_TLSIE_LDNN_GOTTPREL_LO12_NC
:
5989 /* IE->LE relaxation:
5990 ldr xd, [xm, #:gottprel_lo12:var] => movk Rd, :tprel_g0_nc:var
5992 Where R is x for lp64 mode, and w for ILP32 mode. */
5995 insn
= bfd_getl32 (contents
+ rel
->r_offset
);
5996 bfd_putl32 (movk_R0
| (insn
& 0x1f), contents
+ rel
->r_offset
);
5998 return bfd_reloc_continue
;
6000 case BFD_RELOC_AARCH64_TLSLD_ADR_PREL21
:
6001 /* LD->LE relaxation (tiny):
6002 adr x0, :tlsldm:x => mrs x0, tpidr_el0
6003 bl __tls_get_addr => add R0, R0, TCB_SIZE
6005 Where R is x for lp64 mode, and w for ilp32 mode. */
6008 BFD_ASSERT (rel
->r_offset
+ 4 == rel
[1].r_offset
);
6009 BFD_ASSERT (ELFNN_R_TYPE (rel
[1].r_info
) == AARCH64_R (CALL26
));
6010 /* No need of CALL26 relocation for tls_get_addr. */
6011 rel
[1].r_info
= ELFNN_R_INFO (STN_UNDEF
, R_AARCH64_NONE
);
6012 bfd_putl32 (0xd53bd040, contents
+ rel
->r_offset
+ 0);
6013 bfd_putl32 (add_R0_R0
| (TCB_SIZE
<< 10),
6014 contents
+ rel
->r_offset
+ 4);
6015 return bfd_reloc_ok
;
6017 return bfd_reloc_continue
;
6019 case BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21
:
6020 /* LD->LE relaxation (small):
6021 adrp x0, :tlsldm:x => mrs x0, tpidr_el0
6025 bfd_putl32 (0xd53bd040, contents
+ rel
->r_offset
);
6026 return bfd_reloc_ok
;
6028 return bfd_reloc_continue
;
6030 case BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC
:
6031 /* LD->LE relaxation (small):
6032 add x0, #:tlsldm_lo12:x => add R0, R0, TCB_SIZE
6033 bl __tls_get_addr => nop
6035 Where R is x for lp64 mode, and w for ilp32 mode. */
6038 BFD_ASSERT (rel
->r_offset
+ 4 == rel
[1].r_offset
);
6039 BFD_ASSERT (ELFNN_R_TYPE (rel
[1].r_info
) == AARCH64_R (CALL26
));
6040 /* No need of CALL26 relocation for tls_get_addr. */
6041 rel
[1].r_info
= ELFNN_R_INFO (STN_UNDEF
, R_AARCH64_NONE
);
6042 bfd_putl32 (add_R0_R0
| (TCB_SIZE
<< 10),
6043 contents
+ rel
->r_offset
+ 0);
6044 bfd_putl32 (INSN_NOP
, contents
+ rel
->r_offset
+ 4);
6045 return bfd_reloc_ok
;
6047 return bfd_reloc_continue
;
6050 return bfd_reloc_continue
;
6053 return bfd_reloc_ok
;
6056 /* Relocate an AArch64 ELF section. */
6059 elfNN_aarch64_relocate_section (bfd
*output_bfd
,
6060 struct bfd_link_info
*info
,
6062 asection
*input_section
,
6064 Elf_Internal_Rela
*relocs
,
6065 Elf_Internal_Sym
*local_syms
,
6066 asection
**local_sections
)
6068 Elf_Internal_Shdr
*symtab_hdr
;
6069 struct elf_link_hash_entry
**sym_hashes
;
6070 Elf_Internal_Rela
*rel
;
6071 Elf_Internal_Rela
*relend
;
6073 struct elf_aarch64_link_hash_table
*globals
;
6074 bfd_boolean save_addend
= FALSE
;
6077 globals
= elf_aarch64_hash_table (info
);
6079 symtab_hdr
= &elf_symtab_hdr (input_bfd
);
6080 sym_hashes
= elf_sym_hashes (input_bfd
);
6083 relend
= relocs
+ input_section
->reloc_count
;
6084 for (; rel
< relend
; rel
++)
6086 unsigned int r_type
;
6087 bfd_reloc_code_real_type bfd_r_type
;
6088 bfd_reloc_code_real_type relaxed_bfd_r_type
;
6089 reloc_howto_type
*howto
;
6090 unsigned long r_symndx
;
6091 Elf_Internal_Sym
*sym
;
6093 struct elf_link_hash_entry
*h
;
6095 bfd_reloc_status_type r
;
6098 bfd_boolean unresolved_reloc
= FALSE
;
6099 char *error_message
= NULL
;
6101 r_symndx
= ELFNN_R_SYM (rel
->r_info
);
6102 r_type
= ELFNN_R_TYPE (rel
->r_info
);
6104 bfd_reloc
.howto
= elfNN_aarch64_howto_from_type (r_type
);
6105 howto
= bfd_reloc
.howto
;
6109 /* xgettext:c-format */
6111 (_("%B: unrecognized relocation (0x%x) in section `%A'"),
6112 input_bfd
, r_type
, input_section
);
6115 bfd_r_type
= elfNN_aarch64_bfd_reloc_from_howto (howto
);
6121 if (r_symndx
< symtab_hdr
->sh_info
)
6123 sym
= local_syms
+ r_symndx
;
6124 sym_type
= ELFNN_ST_TYPE (sym
->st_info
);
6125 sec
= local_sections
[r_symndx
];
6127 /* An object file might have a reference to a local
6128 undefined symbol. This is a daft object file, but we
6129 should at least do something about it. */
6130 if (r_type
!= R_AARCH64_NONE
&& r_type
!= R_AARCH64_NULL
6131 && bfd_is_und_section (sec
)
6132 && ELF_ST_BIND (sym
->st_info
) != STB_WEAK
)
6133 (*info
->callbacks
->undefined_symbol
)
6134 (info
, bfd_elf_string_from_elf_section
6135 (input_bfd
, symtab_hdr
->sh_link
, sym
->st_name
),
6136 input_bfd
, input_section
, rel
->r_offset
, TRUE
);
6138 relocation
= _bfd_elf_rela_local_sym (output_bfd
, sym
, &sec
, rel
);
6140 /* Relocate against local STT_GNU_IFUNC symbol. */
6141 if (!bfd_link_relocatable (info
)
6142 && ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
)
6144 h
= elfNN_aarch64_get_local_sym_hash (globals
, input_bfd
,
6149 /* Set STT_GNU_IFUNC symbol value. */
6150 h
->root
.u
.def
.value
= sym
->st_value
;
6151 h
->root
.u
.def
.section
= sec
;
6156 bfd_boolean warned
, ignored
;
6158 RELOC_FOR_GLOBAL_SYMBOL (info
, input_bfd
, input_section
, rel
,
6159 r_symndx
, symtab_hdr
, sym_hashes
,
6161 unresolved_reloc
, warned
, ignored
);
6166 if (sec
!= NULL
&& discarded_section (sec
))
6167 RELOC_AGAINST_DISCARDED_SECTION (info
, input_bfd
, input_section
,
6168 rel
, 1, relend
, howto
, 0, contents
);
6170 if (bfd_link_relocatable (info
))
6174 name
= h
->root
.root
.string
;
6177 name
= (bfd_elf_string_from_elf_section
6178 (input_bfd
, symtab_hdr
->sh_link
, sym
->st_name
));
6179 if (name
== NULL
|| *name
== '\0')
6180 name
= bfd_section_name (input_bfd
, sec
);
6184 && r_type
!= R_AARCH64_NONE
6185 && r_type
!= R_AARCH64_NULL
6187 || h
->root
.type
== bfd_link_hash_defined
6188 || h
->root
.type
== bfd_link_hash_defweak
)
6189 && IS_AARCH64_TLS_RELOC (bfd_r_type
) != (sym_type
== STT_TLS
))
6192 ((sym_type
== STT_TLS
6193 /* xgettext:c-format */
6194 ? _("%B(%A+0x%lx): %s used with TLS symbol %s")
6195 /* xgettext:c-format */
6196 : _("%B(%A+0x%lx): %s used with non-TLS symbol %s")),
6198 input_section
, (long) rel
->r_offset
, howto
->name
, name
);
6201 /* We relax only if we can see that there can be a valid transition
6202 from a reloc type to another.
6203 We call elfNN_aarch64_final_link_relocate unless we're completely
6204 done, i.e., the relaxation produced the final output we want. */
6206 relaxed_bfd_r_type
= aarch64_tls_transition (input_bfd
, info
, r_type
,
6208 if (relaxed_bfd_r_type
!= bfd_r_type
)
6210 bfd_r_type
= relaxed_bfd_r_type
;
6211 howto
= elfNN_aarch64_howto_from_bfd_reloc (bfd_r_type
);
6212 BFD_ASSERT (howto
!= NULL
);
6213 r_type
= howto
->type
;
6214 r
= elfNN_aarch64_tls_relax (globals
, input_bfd
, contents
, rel
, h
);
6215 unresolved_reloc
= 0;
6218 r
= bfd_reloc_continue
;
6220 /* There may be multiple consecutive relocations for the
6221 same offset. In that case we are supposed to treat the
6222 output of each relocation as the addend for the next. */
6223 if (rel
+ 1 < relend
6224 && rel
->r_offset
== rel
[1].r_offset
6225 && ELFNN_R_TYPE (rel
[1].r_info
) != R_AARCH64_NONE
6226 && ELFNN_R_TYPE (rel
[1].r_info
) != R_AARCH64_NULL
)
6229 save_addend
= FALSE
;
6231 if (r
== bfd_reloc_continue
)
6232 r
= elfNN_aarch64_final_link_relocate (howto
, input_bfd
, output_bfd
,
6233 input_section
, contents
, rel
,
6234 relocation
, info
, sec
,
6235 h
, &unresolved_reloc
,
6236 save_addend
, &addend
, sym
);
6238 switch (elfNN_aarch64_bfd_reloc_from_type (r_type
))
6240 case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC
:
6241 case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21
:
6242 case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21
:
6243 case BFD_RELOC_AARCH64_TLSGD_MOVW_G0_NC
:
6244 case BFD_RELOC_AARCH64_TLSGD_MOVW_G1
:
6245 case BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC
:
6246 case BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21
:
6247 case BFD_RELOC_AARCH64_TLSLD_ADR_PREL21
:
6248 if (! symbol_got_offset_mark_p (input_bfd
, h
, r_symndx
))
6250 bfd_boolean need_relocs
= FALSE
;
6255 off
= symbol_got_offset (input_bfd
, h
, r_symndx
);
6256 indx
= h
&& h
->dynindx
!= -1 ? h
->dynindx
: 0;
6259 (bfd_link_pic (info
) || indx
!= 0) &&
6261 || ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
6262 || h
->root
.type
!= bfd_link_hash_undefweak
);
6264 BFD_ASSERT (globals
->root
.srelgot
!= NULL
);
6268 Elf_Internal_Rela rela
;
6269 rela
.r_info
= ELFNN_R_INFO (indx
, AARCH64_R (TLS_DTPMOD
));
6271 rela
.r_offset
= globals
->root
.sgot
->output_section
->vma
+
6272 globals
->root
.sgot
->output_offset
+ off
;
6275 loc
= globals
->root
.srelgot
->contents
;
6276 loc
+= globals
->root
.srelgot
->reloc_count
++
6277 * RELOC_SIZE (htab
);
6278 bfd_elfNN_swap_reloca_out (output_bfd
, &rela
, loc
);
6280 bfd_reloc_code_real_type real_type
=
6281 elfNN_aarch64_bfd_reloc_from_type (r_type
);
6283 if (real_type
== BFD_RELOC_AARCH64_TLSLD_ADR_PREL21
6284 || real_type
== BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21
6285 || real_type
== BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC
)
6287 /* For local dynamic, don't generate DTPREL in any case.
6288 Initialize the DTPREL slot into zero, so we get module
6289 base address when invoke runtime TLS resolver. */
6290 bfd_put_NN (output_bfd
, 0,
6291 globals
->root
.sgot
->contents
+ off
6296 bfd_put_NN (output_bfd
,
6297 relocation
- dtpoff_base (info
),
6298 globals
->root
.sgot
->contents
+ off
6303 /* This TLS symbol is global. We emit a
6304 relocation to fixup the tls offset at load
6307 ELFNN_R_INFO (indx
, AARCH64_R (TLS_DTPREL
));
6310 (globals
->root
.sgot
->output_section
->vma
6311 + globals
->root
.sgot
->output_offset
+ off
6314 loc
= globals
->root
.srelgot
->contents
;
6315 loc
+= globals
->root
.srelgot
->reloc_count
++
6316 * RELOC_SIZE (globals
);
6317 bfd_elfNN_swap_reloca_out (output_bfd
, &rela
, loc
);
6318 bfd_put_NN (output_bfd
, (bfd_vma
) 0,
6319 globals
->root
.sgot
->contents
+ off
6325 bfd_put_NN (output_bfd
, (bfd_vma
) 1,
6326 globals
->root
.sgot
->contents
+ off
);
6327 bfd_put_NN (output_bfd
,
6328 relocation
- dtpoff_base (info
),
6329 globals
->root
.sgot
->contents
+ off
6333 symbol_got_offset_mark (input_bfd
, h
, r_symndx
);
6337 case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21
:
6338 case BFD_RELOC_AARCH64_TLSIE_LDNN_GOTTPREL_LO12_NC
:
6339 case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19
:
6340 case BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G0_NC
:
6341 case BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G1
:
6342 if (! symbol_got_offset_mark_p (input_bfd
, h
, r_symndx
))
6344 bfd_boolean need_relocs
= FALSE
;
6349 off
= symbol_got_offset (input_bfd
, h
, r_symndx
);
6351 indx
= h
&& h
->dynindx
!= -1 ? h
->dynindx
: 0;
6354 (bfd_link_pic (info
) || indx
!= 0) &&
6356 || ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
6357 || h
->root
.type
!= bfd_link_hash_undefweak
);
6359 BFD_ASSERT (globals
->root
.srelgot
!= NULL
);
6363 Elf_Internal_Rela rela
;
6366 rela
.r_addend
= relocation
- dtpoff_base (info
);
6370 rela
.r_info
= ELFNN_R_INFO (indx
, AARCH64_R (TLS_TPREL
));
6371 rela
.r_offset
= globals
->root
.sgot
->output_section
->vma
+
6372 globals
->root
.sgot
->output_offset
+ off
;
6374 loc
= globals
->root
.srelgot
->contents
;
6375 loc
+= globals
->root
.srelgot
->reloc_count
++
6376 * RELOC_SIZE (htab
);
6378 bfd_elfNN_swap_reloca_out (output_bfd
, &rela
, loc
);
6380 bfd_put_NN (output_bfd
, rela
.r_addend
,
6381 globals
->root
.sgot
->contents
+ off
);
6384 bfd_put_NN (output_bfd
, relocation
- tpoff_base (info
),
6385 globals
->root
.sgot
->contents
+ off
);
6387 symbol_got_offset_mark (input_bfd
, h
, r_symndx
);
6391 case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12
:
6392 case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21
:
6393 case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21
:
6394 case BFD_RELOC_AARCH64_TLSDESC_LDNN_LO12_NC
:
6395 case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19
:
6396 case BFD_RELOC_AARCH64_TLSDESC_OFF_G0_NC
:
6397 case BFD_RELOC_AARCH64_TLSDESC_OFF_G1
:
6398 if (! symbol_tlsdesc_got_offset_mark_p (input_bfd
, h
, r_symndx
))
6400 bfd_boolean need_relocs
= FALSE
;
6401 int indx
= h
&& h
->dynindx
!= -1 ? h
->dynindx
: 0;
6402 bfd_vma off
= symbol_tlsdesc_got_offset (input_bfd
, h
, r_symndx
);
6404 need_relocs
= (h
== NULL
6405 || ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
6406 || h
->root
.type
!= bfd_link_hash_undefweak
);
6408 BFD_ASSERT (globals
->root
.srelgot
!= NULL
);
6409 BFD_ASSERT (globals
->root
.sgot
!= NULL
);
6414 Elf_Internal_Rela rela
;
6415 rela
.r_info
= ELFNN_R_INFO (indx
, AARCH64_R (TLSDESC
));
6418 rela
.r_offset
= (globals
->root
.sgotplt
->output_section
->vma
6419 + globals
->root
.sgotplt
->output_offset
6420 + off
+ globals
->sgotplt_jump_table_size
);
6423 rela
.r_addend
= relocation
- dtpoff_base (info
);
6425 /* Allocate the next available slot in the PLT reloc
6426 section to hold our R_AARCH64_TLSDESC, the next
6427 available slot is determined from reloc_count,
6428 which we step. But note, reloc_count was
6429 artifically moved down while allocating slots for
6430 real PLT relocs such that all of the PLT relocs
6431 will fit above the initial reloc_count and the
6432 extra stuff will fit below. */
6433 loc
= globals
->root
.srelplt
->contents
;
6434 loc
+= globals
->root
.srelplt
->reloc_count
++
6435 * RELOC_SIZE (globals
);
6437 bfd_elfNN_swap_reloca_out (output_bfd
, &rela
, loc
);
6439 bfd_put_NN (output_bfd
, (bfd_vma
) 0,
6440 globals
->root
.sgotplt
->contents
+ off
+
6441 globals
->sgotplt_jump_table_size
);
6442 bfd_put_NN (output_bfd
, (bfd_vma
) 0,
6443 globals
->root
.sgotplt
->contents
+ off
+
6444 globals
->sgotplt_jump_table_size
+
6448 symbol_tlsdesc_got_offset_mark (input_bfd
, h
, r_symndx
);
6455 /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
6456 because such sections are not SEC_ALLOC and thus ld.so will
6457 not process them. */
6458 if (unresolved_reloc
6459 && !((input_section
->flags
& SEC_DEBUGGING
) != 0
6461 && _bfd_elf_section_offset (output_bfd
, info
, input_section
,
6462 +rel
->r_offset
) != (bfd_vma
) - 1)
6465 /* xgettext:c-format */
6466 (_("%B(%A+0x%lx): unresolvable %s relocation against symbol `%s'"),
6467 input_bfd
, input_section
, (long) rel
->r_offset
, howto
->name
,
6468 h
->root
.root
.string
);
6472 if (r
!= bfd_reloc_ok
&& r
!= bfd_reloc_continue
)
6474 bfd_reloc_code_real_type real_r_type
6475 = elfNN_aarch64_bfd_reloc_from_type (r_type
);
6479 case bfd_reloc_overflow
:
6480 (*info
->callbacks
->reloc_overflow
)
6481 (info
, (h
? &h
->root
: NULL
), name
, howto
->name
, (bfd_vma
) 0,
6482 input_bfd
, input_section
, rel
->r_offset
);
6483 if (real_r_type
== BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15
6484 || real_r_type
== BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14
)
6486 (*info
->callbacks
->warning
)
6488 _("Too many GOT entries for -fpic, "
6489 "please recompile with -fPIC"),
6490 name
, input_bfd
, input_section
, rel
->r_offset
);
6493 /* Overflow can occur when a variable is referenced with a type
6494 that has a larger alignment than the type with which it was
6496 file1.c: extern int foo; int a (void) { return foo; }
6497 file2.c: char bar, foo, baz;
6498 If the variable is placed into a data section at an offset
6499 that is incompatible with the larger alignment requirement
6500 overflow will occur. (Strictly speaking this is not overflow
6501 but rather an alignment problem, but the bfd_reloc_ error
6502 enum does not have a value to cover that situation).
6504 Try to catch this situation here and provide a more helpful
6505 error message to the user. */
6506 if (addend
& ((1 << howto
->rightshift
) - 1)
6507 /* FIXME: Are we testing all of the appropriate reloc
6509 && (real_r_type
== BFD_RELOC_AARCH64_LD_LO19_PCREL
6510 || real_r_type
== BFD_RELOC_AARCH64_LDST16_LO12
6511 || real_r_type
== BFD_RELOC_AARCH64_LDST32_LO12
6512 || real_r_type
== BFD_RELOC_AARCH64_LDST64_LO12
6513 || real_r_type
== BFD_RELOC_AARCH64_LDST128_LO12
))
6515 info
->callbacks
->warning
6516 (info
, _("One possible cause of this error is that the \
6517 symbol is being referenced in the indicated code as if it had a larger \
6518 alignment than was declared where it was defined."),
6519 name
, input_bfd
, input_section
, rel
->r_offset
);
6523 case bfd_reloc_undefined
:
6524 (*info
->callbacks
->undefined_symbol
)
6525 (info
, name
, input_bfd
, input_section
, rel
->r_offset
, TRUE
);
6528 case bfd_reloc_outofrange
:
6529 error_message
= _("out of range");
6532 case bfd_reloc_notsupported
:
6533 error_message
= _("unsupported relocation");
6536 case bfd_reloc_dangerous
:
6537 /* error_message should already be set. */
6541 error_message
= _("unknown error");
6545 BFD_ASSERT (error_message
!= NULL
);
6546 (*info
->callbacks
->reloc_dangerous
)
6547 (info
, error_message
, input_bfd
, input_section
, rel
->r_offset
);
6559 /* Set the right machine number. */
6562 elfNN_aarch64_object_p (bfd
*abfd
)
6565 bfd_default_set_arch_mach (abfd
, bfd_arch_aarch64
, bfd_mach_aarch64_ilp32
);
6567 bfd_default_set_arch_mach (abfd
, bfd_arch_aarch64
, bfd_mach_aarch64
);
6572 /* Function to keep AArch64 specific flags in the ELF header. */
6575 elfNN_aarch64_set_private_flags (bfd
*abfd
, flagword flags
)
6577 if (elf_flags_init (abfd
) && elf_elfheader (abfd
)->e_flags
!= flags
)
6582 elf_elfheader (abfd
)->e_flags
= flags
;
6583 elf_flags_init (abfd
) = TRUE
;
6589 /* Merge backend specific data from an object file to the output
6590 object file when linking. */
6593 elfNN_aarch64_merge_private_bfd_data (bfd
*ibfd
, struct bfd_link_info
*info
)
6595 bfd
*obfd
= info
->output_bfd
;
6598 bfd_boolean flags_compatible
= TRUE
;
6601 /* Check if we have the same endianess. */
6602 if (!_bfd_generic_verify_endian_match (ibfd
, info
))
6605 if (!is_aarch64_elf (ibfd
) || !is_aarch64_elf (obfd
))
6608 /* The input BFD must have had its flags initialised. */
6609 /* The following seems bogus to me -- The flags are initialized in
6610 the assembler but I don't think an elf_flags_init field is
6611 written into the object. */
6612 /* BFD_ASSERT (elf_flags_init (ibfd)); */
6614 in_flags
= elf_elfheader (ibfd
)->e_flags
;
6615 out_flags
= elf_elfheader (obfd
)->e_flags
;
6617 if (!elf_flags_init (obfd
))
6619 /* If the input is the default architecture and had the default
6620 flags then do not bother setting the flags for the output
6621 architecture, instead allow future merges to do this. If no
6622 future merges ever set these flags then they will retain their
6623 uninitialised values, which surprise surprise, correspond
6624 to the default values. */
6625 if (bfd_get_arch_info (ibfd
)->the_default
6626 && elf_elfheader (ibfd
)->e_flags
== 0)
6629 elf_flags_init (obfd
) = TRUE
;
6630 elf_elfheader (obfd
)->e_flags
= in_flags
;
6632 if (bfd_get_arch (obfd
) == bfd_get_arch (ibfd
)
6633 && bfd_get_arch_info (obfd
)->the_default
)
6634 return bfd_set_arch_mach (obfd
, bfd_get_arch (ibfd
),
6635 bfd_get_mach (ibfd
));
6640 /* Identical flags must be compatible. */
6641 if (in_flags
== out_flags
)
6644 /* Check to see if the input BFD actually contains any sections. If
6645 not, its flags may not have been initialised either, but it
6646 cannot actually cause any incompatiblity. Do not short-circuit
6647 dynamic objects; their section list may be emptied by
6648 elf_link_add_object_symbols.
6650 Also check to see if there are no code sections in the input.
6651 In this case there is no need to check for code specific flags.
6652 XXX - do we need to worry about floating-point format compatability
6653 in data sections ? */
6654 if (!(ibfd
->flags
& DYNAMIC
))
6656 bfd_boolean null_input_bfd
= TRUE
;
6657 bfd_boolean only_data_sections
= TRUE
;
6659 for (sec
= ibfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
6661 if ((bfd_get_section_flags (ibfd
, sec
)
6662 & (SEC_LOAD
| SEC_CODE
| SEC_HAS_CONTENTS
))
6663 == (SEC_LOAD
| SEC_CODE
| SEC_HAS_CONTENTS
))
6664 only_data_sections
= FALSE
;
6666 null_input_bfd
= FALSE
;
6670 if (null_input_bfd
|| only_data_sections
)
6674 return flags_compatible
;
6677 /* Display the flags field. */
6680 elfNN_aarch64_print_private_bfd_data (bfd
*abfd
, void *ptr
)
6682 FILE *file
= (FILE *) ptr
;
6683 unsigned long flags
;
6685 BFD_ASSERT (abfd
!= NULL
&& ptr
!= NULL
);
6687 /* Print normal ELF private data. */
6688 _bfd_elf_print_private_bfd_data (abfd
, ptr
);
6690 flags
= elf_elfheader (abfd
)->e_flags
;
6691 /* Ignore init flag - it may not be set, despite the flags field
6692 containing valid data. */
6694 /* xgettext:c-format */
6695 fprintf (file
, _("private flags = %lx:"), elf_elfheader (abfd
)->e_flags
);
6698 fprintf (file
, _("<Unrecognised flag bits set>"));
6705 /* Update the got entry reference counts for the section being removed. */
6708 elfNN_aarch64_gc_sweep_hook (bfd
*abfd
,
6709 struct bfd_link_info
*info
,
6711 const Elf_Internal_Rela
* relocs
)
6713 struct elf_aarch64_link_hash_table
*htab
;
6714 Elf_Internal_Shdr
*symtab_hdr
;
6715 struct elf_link_hash_entry
**sym_hashes
;
6716 struct elf_aarch64_local_symbol
*locals
;
6717 const Elf_Internal_Rela
*rel
, *relend
;
6719 if (bfd_link_relocatable (info
))
6722 htab
= elf_aarch64_hash_table (info
);
6727 elf_section_data (sec
)->local_dynrel
= NULL
;
6729 symtab_hdr
= &elf_symtab_hdr (abfd
);
6730 sym_hashes
= elf_sym_hashes (abfd
);
6732 locals
= elf_aarch64_locals (abfd
);
6734 relend
= relocs
+ sec
->reloc_count
;
6735 for (rel
= relocs
; rel
< relend
; rel
++)
6737 unsigned long r_symndx
;
6738 unsigned int r_type
;
6739 struct elf_link_hash_entry
*h
= NULL
;
6741 r_symndx
= ELFNN_R_SYM (rel
->r_info
);
6743 if (r_symndx
>= symtab_hdr
->sh_info
)
6746 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
6747 while (h
->root
.type
== bfd_link_hash_indirect
6748 || h
->root
.type
== bfd_link_hash_warning
)
6749 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
6753 Elf_Internal_Sym
*isym
;
6755 /* A local symbol. */
6756 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
6759 /* Check relocation against local STT_GNU_IFUNC symbol. */
6761 && ELF_ST_TYPE (isym
->st_info
) == STT_GNU_IFUNC
)
6763 h
= elfNN_aarch64_get_local_sym_hash (htab
, abfd
, rel
, FALSE
);
6771 struct elf_aarch64_link_hash_entry
*eh
;
6772 struct elf_dyn_relocs
**pp
;
6773 struct elf_dyn_relocs
*p
;
6775 eh
= (struct elf_aarch64_link_hash_entry
*) h
;
6777 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; pp
= &p
->next
)
6780 /* Everything must go for SEC. */
6786 r_type
= ELFNN_R_TYPE (rel
->r_info
);
6787 switch (aarch64_tls_transition (abfd
,info
, r_type
, h
,r_symndx
))
6789 case BFD_RELOC_AARCH64_ADR_GOT_PAGE
:
6790 case BFD_RELOC_AARCH64_GOT_LD_PREL19
:
6791 case BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14
:
6792 case BFD_RELOC_AARCH64_LD32_GOT_LO12_NC
:
6793 case BFD_RELOC_AARCH64_LD64_GOTOFF_LO15
:
6794 case BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15
:
6795 case BFD_RELOC_AARCH64_LD64_GOT_LO12_NC
:
6796 case BFD_RELOC_AARCH64_MOVW_GOTOFF_G0_NC
:
6797 case BFD_RELOC_AARCH64_MOVW_GOTOFF_G1
:
6798 case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12
:
6799 case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21
:
6800 case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21
:
6801 case BFD_RELOC_AARCH64_TLSDESC_LD32_LO12_NC
:
6802 case BFD_RELOC_AARCH64_TLSDESC_LD64_LO12
:
6803 case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19
:
6804 case BFD_RELOC_AARCH64_TLSDESC_OFF_G0_NC
:
6805 case BFD_RELOC_AARCH64_TLSDESC_OFF_G1
:
6806 case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC
:
6807 case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21
:
6808 case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21
:
6809 case BFD_RELOC_AARCH64_TLSGD_MOVW_G0_NC
:
6810 case BFD_RELOC_AARCH64_TLSGD_MOVW_G1
:
6811 case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21
:
6812 case BFD_RELOC_AARCH64_TLSIE_LD32_GOTTPREL_LO12_NC
:
6813 case BFD_RELOC_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC
:
6814 case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19
:
6815 case BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G0_NC
:
6816 case BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G1
:
6817 case BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC
:
6818 case BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21
:
6819 case BFD_RELOC_AARCH64_TLSLD_ADR_PREL21
:
6822 if (h
->got
.refcount
> 0)
6823 h
->got
.refcount
-= 1;
6825 if (h
->type
== STT_GNU_IFUNC
)
6827 if (h
->plt
.refcount
> 0)
6828 h
->plt
.refcount
-= 1;
6831 else if (locals
!= NULL
)
6833 if (locals
[r_symndx
].got_refcount
> 0)
6834 locals
[r_symndx
].got_refcount
-= 1;
6838 case BFD_RELOC_AARCH64_CALL26
:
6839 case BFD_RELOC_AARCH64_JUMP26
:
6840 /* If this is a local symbol then we resolve it
6841 directly without creating a PLT entry. */
6845 if (h
->plt
.refcount
> 0)
6846 h
->plt
.refcount
-= 1;
6849 case BFD_RELOC_AARCH64_ADR_HI21_NC_PCREL
:
6850 case BFD_RELOC_AARCH64_ADR_HI21_PCREL
:
6851 case BFD_RELOC_AARCH64_ADR_LO21_PCREL
:
6852 case BFD_RELOC_AARCH64_MOVW_G0_NC
:
6853 case BFD_RELOC_AARCH64_MOVW_G1_NC
:
6854 case BFD_RELOC_AARCH64_MOVW_G2_NC
:
6855 case BFD_RELOC_AARCH64_MOVW_G3
:
6856 case BFD_RELOC_AARCH64_NN
:
6857 if (h
!= NULL
&& bfd_link_executable (info
))
6859 if (h
->plt
.refcount
> 0)
6860 h
->plt
.refcount
-= 1;
6872 /* Adjust a symbol defined by a dynamic object and referenced by a
6873 regular object. The current definition is in some section of the
6874 dynamic object, but we're not including those sections. We have to
6875 change the definition to something the rest of the link can
6879 elfNN_aarch64_adjust_dynamic_symbol (struct bfd_link_info
*info
,
6880 struct elf_link_hash_entry
*h
)
6882 struct elf_aarch64_link_hash_table
*htab
;
6885 /* If this is a function, put it in the procedure linkage table. We
6886 will fill in the contents of the procedure linkage table later,
6887 when we know the address of the .got section. */
6888 if (h
->type
== STT_FUNC
|| h
->type
== STT_GNU_IFUNC
|| h
->needs_plt
)
6890 if (h
->plt
.refcount
<= 0
6891 || (h
->type
!= STT_GNU_IFUNC
6892 && (SYMBOL_CALLS_LOCAL (info
, h
)
6893 || (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
6894 && h
->root
.type
== bfd_link_hash_undefweak
))))
6896 /* This case can occur if we saw a CALL26 reloc in
6897 an input file, but the symbol wasn't referred to
6898 by a dynamic object or all references were
6899 garbage collected. In which case we can end up
6901 h
->plt
.offset
= (bfd_vma
) - 1;
6908 /* Otherwise, reset to -1. */
6909 h
->plt
.offset
= (bfd_vma
) - 1;
6912 /* If this is a weak symbol, and there is a real definition, the
6913 processor independent code will have arranged for us to see the
6914 real definition first, and we can just use the same value. */
6915 if (h
->u
.weakdef
!= NULL
)
6917 BFD_ASSERT (h
->u
.weakdef
->root
.type
== bfd_link_hash_defined
6918 || h
->u
.weakdef
->root
.type
== bfd_link_hash_defweak
);
6919 h
->root
.u
.def
.section
= h
->u
.weakdef
->root
.u
.def
.section
;
6920 h
->root
.u
.def
.value
= h
->u
.weakdef
->root
.u
.def
.value
;
6921 if (ELIMINATE_COPY_RELOCS
|| info
->nocopyreloc
)
6922 h
->non_got_ref
= h
->u
.weakdef
->non_got_ref
;
6926 /* If we are creating a shared library, we must presume that the
6927 only references to the symbol are via the global offset table.
6928 For such cases we need not do anything here; the relocations will
6929 be handled correctly by relocate_section. */
6930 if (bfd_link_pic (info
))
6933 /* If there are no references to this symbol that do not use the
6934 GOT, we don't need to generate a copy reloc. */
6935 if (!h
->non_got_ref
)
6938 /* If -z nocopyreloc was given, we won't generate them either. */
6939 if (info
->nocopyreloc
)
6945 /* We must allocate the symbol in our .dynbss section, which will
6946 become part of the .bss section of the executable. There will be
6947 an entry for this symbol in the .dynsym section. The dynamic
6948 object will contain position independent code, so all references
6949 from the dynamic object to this symbol will go through the global
6950 offset table. The dynamic linker will use the .dynsym entry to
6951 determine the address it must put in the global offset table, so
6952 both the dynamic object and the regular object will refer to the
6953 same memory location for the variable. */
6955 htab
= elf_aarch64_hash_table (info
);
6957 /* We must generate a R_AARCH64_COPY reloc to tell the dynamic linker
6958 to copy the initial value out of the dynamic object and into the
6959 runtime process image. */
6960 if ((h
->root
.u
.def
.section
->flags
& SEC_READONLY
) != 0)
6962 s
= htab
->root
.sdynrelro
;
6963 srel
= htab
->root
.sreldynrelro
;
6967 s
= htab
->root
.sdynbss
;
6968 srel
= htab
->root
.srelbss
;
6970 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0 && h
->size
!= 0)
6972 srel
->size
+= RELOC_SIZE (htab
);
6976 return _bfd_elf_adjust_dynamic_copy (info
, h
, s
);
6981 elfNN_aarch64_allocate_local_symbols (bfd
*abfd
, unsigned number
)
6983 struct elf_aarch64_local_symbol
*locals
;
6984 locals
= elf_aarch64_locals (abfd
);
6987 locals
= (struct elf_aarch64_local_symbol
*)
6988 bfd_zalloc (abfd
, number
* sizeof (struct elf_aarch64_local_symbol
));
6991 elf_aarch64_locals (abfd
) = locals
;
6996 /* Create the .got section to hold the global offset table. */
6999 aarch64_elf_create_got_section (bfd
*abfd
, struct bfd_link_info
*info
)
7001 const struct elf_backend_data
*bed
= get_elf_backend_data (abfd
);
7004 struct elf_link_hash_entry
*h
;
7005 struct elf_link_hash_table
*htab
= elf_hash_table (info
);
7007 /* This function may be called more than once. */
7008 if (htab
->sgot
!= NULL
)
7011 flags
= bed
->dynamic_sec_flags
;
7013 s
= bfd_make_section_anyway_with_flags (abfd
,
7014 (bed
->rela_plts_and_copies_p
7015 ? ".rela.got" : ".rel.got"),
7016 (bed
->dynamic_sec_flags
7019 || ! bfd_set_section_alignment (abfd
, s
, bed
->s
->log_file_align
))
7023 s
= bfd_make_section_anyway_with_flags (abfd
, ".got", flags
);
7025 || !bfd_set_section_alignment (abfd
, s
, bed
->s
->log_file_align
))
7028 htab
->sgot
->size
+= GOT_ENTRY_SIZE
;
7030 if (bed
->want_got_sym
)
7032 /* Define the symbol _GLOBAL_OFFSET_TABLE_ at the start of the .got
7033 (or .got.plt) section. We don't do this in the linker script
7034 because we don't want to define the symbol if we are not creating
7035 a global offset table. */
7036 h
= _bfd_elf_define_linkage_sym (abfd
, info
, s
,
7037 "_GLOBAL_OFFSET_TABLE_");
7038 elf_hash_table (info
)->hgot
= h
;
7043 if (bed
->want_got_plt
)
7045 s
= bfd_make_section_anyway_with_flags (abfd
, ".got.plt", flags
);
7047 || !bfd_set_section_alignment (abfd
, s
,
7048 bed
->s
->log_file_align
))
7053 /* The first bit of the global offset table is the header. */
7054 s
->size
+= bed
->got_header_size
;
7059 /* Look through the relocs for a section during the first phase. */
7062 elfNN_aarch64_check_relocs (bfd
*abfd
, struct bfd_link_info
*info
,
7063 asection
*sec
, const Elf_Internal_Rela
*relocs
)
7065 Elf_Internal_Shdr
*symtab_hdr
;
7066 struct elf_link_hash_entry
**sym_hashes
;
7067 const Elf_Internal_Rela
*rel
;
7068 const Elf_Internal_Rela
*rel_end
;
7071 struct elf_aarch64_link_hash_table
*htab
;
7073 if (bfd_link_relocatable (info
))
7076 BFD_ASSERT (is_aarch64_elf (abfd
));
7078 htab
= elf_aarch64_hash_table (info
);
7081 symtab_hdr
= &elf_symtab_hdr (abfd
);
7082 sym_hashes
= elf_sym_hashes (abfd
);
7084 rel_end
= relocs
+ sec
->reloc_count
;
7085 for (rel
= relocs
; rel
< rel_end
; rel
++)
7087 struct elf_link_hash_entry
*h
;
7088 unsigned long r_symndx
;
7089 unsigned int r_type
;
7090 bfd_reloc_code_real_type bfd_r_type
;
7091 Elf_Internal_Sym
*isym
;
7093 r_symndx
= ELFNN_R_SYM (rel
->r_info
);
7094 r_type
= ELFNN_R_TYPE (rel
->r_info
);
7096 if (r_symndx
>= NUM_SHDR_ENTRIES (symtab_hdr
))
7098 /* xgettext:c-format */
7099 _bfd_error_handler (_("%B: bad symbol index: %d"), abfd
, r_symndx
);
7103 if (r_symndx
< symtab_hdr
->sh_info
)
7105 /* A local symbol. */
7106 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
7111 /* Check relocation against local STT_GNU_IFUNC symbol. */
7112 if (ELF_ST_TYPE (isym
->st_info
) == STT_GNU_IFUNC
)
7114 h
= elfNN_aarch64_get_local_sym_hash (htab
, abfd
, rel
,
7119 /* Fake a STT_GNU_IFUNC symbol. */
7120 h
->type
= STT_GNU_IFUNC
;
7123 h
->forced_local
= 1;
7124 h
->root
.type
= bfd_link_hash_defined
;
7131 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
7132 while (h
->root
.type
== bfd_link_hash_indirect
7133 || h
->root
.type
== bfd_link_hash_warning
)
7134 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
7136 /* PR15323, ref flags aren't set for references in the same
7138 h
->root
.non_ir_ref
= 1;
7141 /* Could be done earlier, if h were already available. */
7142 bfd_r_type
= aarch64_tls_transition (abfd
, info
, r_type
, h
, r_symndx
);
7146 /* If a relocation refers to _GLOBAL_OFFSET_TABLE_, create the .got.
7147 This shows up in particular in an R_AARCH64_PREL64 in large model
7148 when calculating the pc-relative address to .got section which is
7149 used to initialize the gp register. */
7150 if (h
->root
.root
.string
7151 && strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_") == 0)
7153 if (htab
->root
.dynobj
== NULL
)
7154 htab
->root
.dynobj
= abfd
;
7156 if (! aarch64_elf_create_got_section (htab
->root
.dynobj
, info
))
7159 BFD_ASSERT (h
== htab
->root
.hgot
);
7162 /* Create the ifunc sections for static executables. If we
7163 never see an indirect function symbol nor we are building
7164 a static executable, those sections will be empty and
7165 won't appear in output. */
7171 case BFD_RELOC_AARCH64_ADD_LO12
:
7172 case BFD_RELOC_AARCH64_ADR_GOT_PAGE
:
7173 case BFD_RELOC_AARCH64_ADR_HI21_PCREL
:
7174 case BFD_RELOC_AARCH64_CALL26
:
7175 case BFD_RELOC_AARCH64_GOT_LD_PREL19
:
7176 case BFD_RELOC_AARCH64_JUMP26
:
7177 case BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14
:
7178 case BFD_RELOC_AARCH64_LD32_GOT_LO12_NC
:
7179 case BFD_RELOC_AARCH64_LD64_GOTOFF_LO15
:
7180 case BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15
:
7181 case BFD_RELOC_AARCH64_LD64_GOT_LO12_NC
:
7182 case BFD_RELOC_AARCH64_MOVW_GOTOFF_G0_NC
:
7183 case BFD_RELOC_AARCH64_MOVW_GOTOFF_G1
:
7184 case BFD_RELOC_AARCH64_NN
:
7185 if (htab
->root
.dynobj
== NULL
)
7186 htab
->root
.dynobj
= abfd
;
7187 if (!_bfd_elf_create_ifunc_sections (htab
->root
.dynobj
, info
))
7192 /* It is referenced by a non-shared object. */
7194 h
->root
.non_ir_ref
= 1;
7199 case BFD_RELOC_AARCH64_NN
:
7201 /* We don't need to handle relocs into sections not going into
7202 the "real" output. */
7203 if ((sec
->flags
& SEC_ALLOC
) == 0)
7208 if (!bfd_link_pic (info
))
7211 h
->plt
.refcount
+= 1;
7212 h
->pointer_equality_needed
= 1;
7215 /* No need to do anything if we're not creating a shared
7217 if (! bfd_link_pic (info
))
7221 struct elf_dyn_relocs
*p
;
7222 struct elf_dyn_relocs
**head
;
7224 /* We must copy these reloc types into the output file.
7225 Create a reloc section in dynobj and make room for
7229 if (htab
->root
.dynobj
== NULL
)
7230 htab
->root
.dynobj
= abfd
;
7232 sreloc
= _bfd_elf_make_dynamic_reloc_section
7233 (sec
, htab
->root
.dynobj
, LOG_FILE_ALIGN
, abfd
, /*rela? */ TRUE
);
7239 /* If this is a global symbol, we count the number of
7240 relocations we need for this symbol. */
7243 struct elf_aarch64_link_hash_entry
*eh
;
7244 eh
= (struct elf_aarch64_link_hash_entry
*) h
;
7245 head
= &eh
->dyn_relocs
;
7249 /* Track dynamic relocs needed for local syms too.
7250 We really need local syms available to do this
7256 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
7261 s
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
7265 /* Beware of type punned pointers vs strict aliasing
7267 vpp
= &(elf_section_data (s
)->local_dynrel
);
7268 head
= (struct elf_dyn_relocs
**) vpp
;
7272 if (p
== NULL
|| p
->sec
!= sec
)
7274 bfd_size_type amt
= sizeof *p
;
7275 p
= ((struct elf_dyn_relocs
*)
7276 bfd_zalloc (htab
->root
.dynobj
, amt
));
7289 /* RR: We probably want to keep a consistency check that
7290 there are no dangling GOT_PAGE relocs. */
7291 case BFD_RELOC_AARCH64_ADR_GOT_PAGE
:
7292 case BFD_RELOC_AARCH64_GOT_LD_PREL19
:
7293 case BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14
:
7294 case BFD_RELOC_AARCH64_LD32_GOT_LO12_NC
:
7295 case BFD_RELOC_AARCH64_LD64_GOTOFF_LO15
:
7296 case BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15
:
7297 case BFD_RELOC_AARCH64_LD64_GOT_LO12_NC
:
7298 case BFD_RELOC_AARCH64_MOVW_GOTOFF_G0_NC
:
7299 case BFD_RELOC_AARCH64_MOVW_GOTOFF_G1
:
7300 case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12
:
7301 case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21
:
7302 case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21
:
7303 case BFD_RELOC_AARCH64_TLSDESC_LD32_LO12_NC
:
7304 case BFD_RELOC_AARCH64_TLSDESC_LD64_LO12
:
7305 case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19
:
7306 case BFD_RELOC_AARCH64_TLSDESC_OFF_G0_NC
:
7307 case BFD_RELOC_AARCH64_TLSDESC_OFF_G1
:
7308 case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC
:
7309 case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21
:
7310 case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21
:
7311 case BFD_RELOC_AARCH64_TLSGD_MOVW_G0_NC
:
7312 case BFD_RELOC_AARCH64_TLSGD_MOVW_G1
:
7313 case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21
:
7314 case BFD_RELOC_AARCH64_TLSIE_LD32_GOTTPREL_LO12_NC
:
7315 case BFD_RELOC_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC
:
7316 case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19
:
7317 case BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G0_NC
:
7318 case BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G1
:
7319 case BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC
:
7320 case BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21
:
7321 case BFD_RELOC_AARCH64_TLSLD_ADR_PREL21
:
7322 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1
:
7323 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1_NC
:
7324 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G2
:
7327 unsigned old_got_type
;
7329 got_type
= aarch64_reloc_got_type (bfd_r_type
);
7333 h
->got
.refcount
+= 1;
7334 old_got_type
= elf_aarch64_hash_entry (h
)->got_type
;
7338 struct elf_aarch64_local_symbol
*locals
;
7340 if (!elfNN_aarch64_allocate_local_symbols
7341 (abfd
, symtab_hdr
->sh_info
))
7344 locals
= elf_aarch64_locals (abfd
);
7345 BFD_ASSERT (r_symndx
< symtab_hdr
->sh_info
);
7346 locals
[r_symndx
].got_refcount
+= 1;
7347 old_got_type
= locals
[r_symndx
].got_type
;
7350 /* If a variable is accessed with both general dynamic TLS
7351 methods, two slots may be created. */
7352 if (GOT_TLS_GD_ANY_P (old_got_type
) && GOT_TLS_GD_ANY_P (got_type
))
7353 got_type
|= old_got_type
;
7355 /* We will already have issued an error message if there
7356 is a TLS/non-TLS mismatch, based on the symbol type.
7357 So just combine any TLS types needed. */
7358 if (old_got_type
!= GOT_UNKNOWN
&& old_got_type
!= GOT_NORMAL
7359 && got_type
!= GOT_NORMAL
)
7360 got_type
|= old_got_type
;
7362 /* If the symbol is accessed by both IE and GD methods, we
7363 are able to relax. Turn off the GD flag, without
7364 messing up with any other kind of TLS types that may be
7366 if ((got_type
& GOT_TLS_IE
) && GOT_TLS_GD_ANY_P (got_type
))
7367 got_type
&= ~ (GOT_TLSDESC_GD
| GOT_TLS_GD
);
7369 if (old_got_type
!= got_type
)
7372 elf_aarch64_hash_entry (h
)->got_type
= got_type
;
7375 struct elf_aarch64_local_symbol
*locals
;
7376 locals
= elf_aarch64_locals (abfd
);
7377 BFD_ASSERT (r_symndx
< symtab_hdr
->sh_info
);
7378 locals
[r_symndx
].got_type
= got_type
;
7382 if (htab
->root
.dynobj
== NULL
)
7383 htab
->root
.dynobj
= abfd
;
7384 if (! aarch64_elf_create_got_section (htab
->root
.dynobj
, info
))
7389 case BFD_RELOC_AARCH64_MOVW_G0_NC
:
7390 case BFD_RELOC_AARCH64_MOVW_G1_NC
:
7391 case BFD_RELOC_AARCH64_MOVW_G2_NC
:
7392 case BFD_RELOC_AARCH64_MOVW_G3
:
7393 if (bfd_link_pic (info
))
7395 int howto_index
= bfd_r_type
- BFD_RELOC_AARCH64_RELOC_START
;
7397 /* xgettext:c-format */
7398 (_("%B: relocation %s against `%s' can not be used when making "
7399 "a shared object; recompile with -fPIC"),
7400 abfd
, elfNN_aarch64_howto_table
[howto_index
].name
,
7401 (h
) ? h
->root
.root
.string
: "a local symbol");
7402 bfd_set_error (bfd_error_bad_value
);
7407 case BFD_RELOC_AARCH64_ADR_HI21_NC_PCREL
:
7408 case BFD_RELOC_AARCH64_ADR_HI21_PCREL
:
7409 case BFD_RELOC_AARCH64_ADR_LO21_PCREL
:
7410 if (h
!= NULL
&& bfd_link_executable (info
))
7412 /* If this reloc is in a read-only section, we might
7413 need a copy reloc. We can't check reliably at this
7414 stage whether the section is read-only, as input
7415 sections have not yet been mapped to output sections.
7416 Tentatively set the flag for now, and correct in
7417 adjust_dynamic_symbol. */
7419 h
->plt
.refcount
+= 1;
7420 h
->pointer_equality_needed
= 1;
7422 /* FIXME:: RR need to handle these in shared libraries
7423 and essentially bomb out as these being non-PIC
7424 relocations in shared libraries. */
7427 case BFD_RELOC_AARCH64_CALL26
:
7428 case BFD_RELOC_AARCH64_JUMP26
:
7429 /* If this is a local symbol then we resolve it
7430 directly without creating a PLT entry. */
7435 if (h
->plt
.refcount
<= 0)
7436 h
->plt
.refcount
= 1;
7438 h
->plt
.refcount
+= 1;
7449 /* Treat mapping symbols as special target symbols. */
7452 elfNN_aarch64_is_target_special_symbol (bfd
*abfd ATTRIBUTE_UNUSED
,
7455 return bfd_is_aarch64_special_symbol_name (sym
->name
,
7456 BFD_AARCH64_SPECIAL_SYM_TYPE_ANY
);
7459 /* This is a copy of elf_find_function () from elf.c except that
7460 AArch64 mapping symbols are ignored when looking for function names. */
7463 aarch64_elf_find_function (bfd
*abfd ATTRIBUTE_UNUSED
,
7467 const char **filename_ptr
,
7468 const char **functionname_ptr
)
7470 const char *filename
= NULL
;
7471 asymbol
*func
= NULL
;
7472 bfd_vma low_func
= 0;
7475 for (p
= symbols
; *p
!= NULL
; p
++)
7479 q
= (elf_symbol_type
*) * p
;
7481 switch (ELF_ST_TYPE (q
->internal_elf_sym
.st_info
))
7486 filename
= bfd_asymbol_name (&q
->symbol
);
7490 /* Skip mapping symbols. */
7491 if ((q
->symbol
.flags
& BSF_LOCAL
)
7492 && (bfd_is_aarch64_special_symbol_name
7493 (q
->symbol
.name
, BFD_AARCH64_SPECIAL_SYM_TYPE_ANY
)))
7496 if (bfd_get_section (&q
->symbol
) == section
7497 && q
->symbol
.value
>= low_func
&& q
->symbol
.value
<= offset
)
7499 func
= (asymbol
*) q
;
7500 low_func
= q
->symbol
.value
;
7510 *filename_ptr
= filename
;
7511 if (functionname_ptr
)
7512 *functionname_ptr
= bfd_asymbol_name (func
);
7518 /* Find the nearest line to a particular section and offset, for error
7519 reporting. This code is a duplicate of the code in elf.c, except
7520 that it uses aarch64_elf_find_function. */
7523 elfNN_aarch64_find_nearest_line (bfd
*abfd
,
7527 const char **filename_ptr
,
7528 const char **functionname_ptr
,
7529 unsigned int *line_ptr
,
7530 unsigned int *discriminator_ptr
)
7532 bfd_boolean found
= FALSE
;
7534 if (_bfd_dwarf2_find_nearest_line (abfd
, symbols
, NULL
, section
, offset
,
7535 filename_ptr
, functionname_ptr
,
7536 line_ptr
, discriminator_ptr
,
7537 dwarf_debug_sections
, 0,
7538 &elf_tdata (abfd
)->dwarf2_find_line_info
))
7540 if (!*functionname_ptr
)
7541 aarch64_elf_find_function (abfd
, symbols
, section
, offset
,
7542 *filename_ptr
? NULL
: filename_ptr
,
7548 /* Skip _bfd_dwarf1_find_nearest_line since no known AArch64
7549 toolchain uses DWARF1. */
7551 if (!_bfd_stab_section_find_nearest_line (abfd
, symbols
, section
, offset
,
7552 &found
, filename_ptr
,
7553 functionname_ptr
, line_ptr
,
7554 &elf_tdata (abfd
)->line_info
))
7557 if (found
&& (*functionname_ptr
|| *line_ptr
))
7560 if (symbols
== NULL
)
7563 if (!aarch64_elf_find_function (abfd
, symbols
, section
, offset
,
7564 filename_ptr
, functionname_ptr
))
7572 elfNN_aarch64_find_inliner_info (bfd
*abfd
,
7573 const char **filename_ptr
,
7574 const char **functionname_ptr
,
7575 unsigned int *line_ptr
)
7578 found
= _bfd_dwarf2_find_inliner_info
7579 (abfd
, filename_ptr
,
7580 functionname_ptr
, line_ptr
, &elf_tdata (abfd
)->dwarf2_find_line_info
);
7586 elfNN_aarch64_post_process_headers (bfd
*abfd
,
7587 struct bfd_link_info
*link_info
)
7589 Elf_Internal_Ehdr
*i_ehdrp
; /* ELF file header, internal form. */
7591 i_ehdrp
= elf_elfheader (abfd
);
7592 i_ehdrp
->e_ident
[EI_ABIVERSION
] = AARCH64_ELF_ABI_VERSION
;
7594 _bfd_elf_post_process_headers (abfd
, link_info
);
7597 static enum elf_reloc_type_class
7598 elfNN_aarch64_reloc_type_class (const struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
7599 const asection
*rel_sec ATTRIBUTE_UNUSED
,
7600 const Elf_Internal_Rela
*rela
)
7602 switch ((int) ELFNN_R_TYPE (rela
->r_info
))
7604 case AARCH64_R (RELATIVE
):
7605 return reloc_class_relative
;
7606 case AARCH64_R (JUMP_SLOT
):
7607 return reloc_class_plt
;
7608 case AARCH64_R (COPY
):
7609 return reloc_class_copy
;
7611 return reloc_class_normal
;
7615 /* Handle an AArch64 specific section when reading an object file. This is
7616 called when bfd_section_from_shdr finds a section with an unknown
7620 elfNN_aarch64_section_from_shdr (bfd
*abfd
,
7621 Elf_Internal_Shdr
*hdr
,
7622 const char *name
, int shindex
)
7624 /* There ought to be a place to keep ELF backend specific flags, but
7625 at the moment there isn't one. We just keep track of the
7626 sections by their name, instead. Fortunately, the ABI gives
7627 names for all the AArch64 specific sections, so we will probably get
7629 switch (hdr
->sh_type
)
7631 case SHT_AARCH64_ATTRIBUTES
:
7638 if (!_bfd_elf_make_section_from_shdr (abfd
, hdr
, name
, shindex
))
7644 /* A structure used to record a list of sections, independently
7645 of the next and prev fields in the asection structure. */
7646 typedef struct section_list
7649 struct section_list
*next
;
7650 struct section_list
*prev
;
7654 /* Unfortunately we need to keep a list of sections for which
7655 an _aarch64_elf_section_data structure has been allocated. This
7656 is because it is possible for functions like elfNN_aarch64_write_section
7657 to be called on a section which has had an elf_data_structure
7658 allocated for it (and so the used_by_bfd field is valid) but
7659 for which the AArch64 extended version of this structure - the
7660 _aarch64_elf_section_data structure - has not been allocated. */
7661 static section_list
*sections_with_aarch64_elf_section_data
= NULL
;
7664 record_section_with_aarch64_elf_section_data (asection
*sec
)
7666 struct section_list
*entry
;
7668 entry
= bfd_malloc (sizeof (*entry
));
7672 entry
->next
= sections_with_aarch64_elf_section_data
;
7674 if (entry
->next
!= NULL
)
7675 entry
->next
->prev
= entry
;
7676 sections_with_aarch64_elf_section_data
= entry
;
7679 static struct section_list
*
7680 find_aarch64_elf_section_entry (asection
*sec
)
7682 struct section_list
*entry
;
7683 static struct section_list
*last_entry
= NULL
;
7685 /* This is a short cut for the typical case where the sections are added
7686 to the sections_with_aarch64_elf_section_data list in forward order and
7687 then looked up here in backwards order. This makes a real difference
7688 to the ld-srec/sec64k.exp linker test. */
7689 entry
= sections_with_aarch64_elf_section_data
;
7690 if (last_entry
!= NULL
)
7692 if (last_entry
->sec
== sec
)
7694 else if (last_entry
->next
!= NULL
&& last_entry
->next
->sec
== sec
)
7695 entry
= last_entry
->next
;
7698 for (; entry
; entry
= entry
->next
)
7699 if (entry
->sec
== sec
)
7703 /* Record the entry prior to this one - it is the entry we are
7704 most likely to want to locate next time. Also this way if we
7705 have been called from
7706 unrecord_section_with_aarch64_elf_section_data () we will not
7707 be caching a pointer that is about to be freed. */
7708 last_entry
= entry
->prev
;
7714 unrecord_section_with_aarch64_elf_section_data (asection
*sec
)
7716 struct section_list
*entry
;
7718 entry
= find_aarch64_elf_section_entry (sec
);
7722 if (entry
->prev
!= NULL
)
7723 entry
->prev
->next
= entry
->next
;
7724 if (entry
->next
!= NULL
)
7725 entry
->next
->prev
= entry
->prev
;
7726 if (entry
== sections_with_aarch64_elf_section_data
)
7727 sections_with_aarch64_elf_section_data
= entry
->next
;
7736 struct bfd_link_info
*info
;
7739 int (*func
) (void *, const char *, Elf_Internal_Sym
*,
7740 asection
*, struct elf_link_hash_entry
*);
7741 } output_arch_syminfo
;
7743 enum map_symbol_type
7750 /* Output a single mapping symbol. */
7753 elfNN_aarch64_output_map_sym (output_arch_syminfo
*osi
,
7754 enum map_symbol_type type
, bfd_vma offset
)
7756 static const char *names
[2] = { "$x", "$d" };
7757 Elf_Internal_Sym sym
;
7759 sym
.st_value
= (osi
->sec
->output_section
->vma
7760 + osi
->sec
->output_offset
+ offset
);
7763 sym
.st_info
= ELF_ST_INFO (STB_LOCAL
, STT_NOTYPE
);
7764 sym
.st_shndx
= osi
->sec_shndx
;
7765 return osi
->func (osi
->finfo
, names
[type
], &sym
, osi
->sec
, NULL
) == 1;
7768 /* Output a single local symbol for a generated stub. */
7771 elfNN_aarch64_output_stub_sym (output_arch_syminfo
*osi
, const char *name
,
7772 bfd_vma offset
, bfd_vma size
)
7774 Elf_Internal_Sym sym
;
7776 sym
.st_value
= (osi
->sec
->output_section
->vma
7777 + osi
->sec
->output_offset
+ offset
);
7780 sym
.st_info
= ELF_ST_INFO (STB_LOCAL
, STT_FUNC
);
7781 sym
.st_shndx
= osi
->sec_shndx
;
7782 return osi
->func (osi
->finfo
, name
, &sym
, osi
->sec
, NULL
) == 1;
7786 aarch64_map_one_stub (struct bfd_hash_entry
*gen_entry
, void *in_arg
)
7788 struct elf_aarch64_stub_hash_entry
*stub_entry
;
7792 output_arch_syminfo
*osi
;
7794 /* Massage our args to the form they really have. */
7795 stub_entry
= (struct elf_aarch64_stub_hash_entry
*) gen_entry
;
7796 osi
= (output_arch_syminfo
*) in_arg
;
7798 stub_sec
= stub_entry
->stub_sec
;
7800 /* Ensure this stub is attached to the current section being
7802 if (stub_sec
!= osi
->sec
)
7805 addr
= (bfd_vma
) stub_entry
->stub_offset
;
7807 stub_name
= stub_entry
->output_name
;
7809 switch (stub_entry
->stub_type
)
7811 case aarch64_stub_adrp_branch
:
7812 if (!elfNN_aarch64_output_stub_sym (osi
, stub_name
, addr
,
7813 sizeof (aarch64_adrp_branch_stub
)))
7815 if (!elfNN_aarch64_output_map_sym (osi
, AARCH64_MAP_INSN
, addr
))
7818 case aarch64_stub_long_branch
:
7819 if (!elfNN_aarch64_output_stub_sym
7820 (osi
, stub_name
, addr
, sizeof (aarch64_long_branch_stub
)))
7822 if (!elfNN_aarch64_output_map_sym (osi
, AARCH64_MAP_INSN
, addr
))
7824 if (!elfNN_aarch64_output_map_sym (osi
, AARCH64_MAP_DATA
, addr
+ 16))
7827 case aarch64_stub_erratum_835769_veneer
:
7828 if (!elfNN_aarch64_output_stub_sym (osi
, stub_name
, addr
,
7829 sizeof (aarch64_erratum_835769_stub
)))
7831 if (!elfNN_aarch64_output_map_sym (osi
, AARCH64_MAP_INSN
, addr
))
7834 case aarch64_stub_erratum_843419_veneer
:
7835 if (!elfNN_aarch64_output_stub_sym (osi
, stub_name
, addr
,
7836 sizeof (aarch64_erratum_843419_stub
)))
7838 if (!elfNN_aarch64_output_map_sym (osi
, AARCH64_MAP_INSN
, addr
))
7849 /* Output mapping symbols for linker generated sections. */
7852 elfNN_aarch64_output_arch_local_syms (bfd
*output_bfd
,
7853 struct bfd_link_info
*info
,
7855 int (*func
) (void *, const char *,
7858 struct elf_link_hash_entry
7861 output_arch_syminfo osi
;
7862 struct elf_aarch64_link_hash_table
*htab
;
7864 htab
= elf_aarch64_hash_table (info
);
7870 /* Long calls stubs. */
7871 if (htab
->stub_bfd
&& htab
->stub_bfd
->sections
)
7875 for (stub_sec
= htab
->stub_bfd
->sections
;
7876 stub_sec
!= NULL
; stub_sec
= stub_sec
->next
)
7878 /* Ignore non-stub sections. */
7879 if (!strstr (stub_sec
->name
, STUB_SUFFIX
))
7884 osi
.sec_shndx
= _bfd_elf_section_from_bfd_section
7885 (output_bfd
, osi
.sec
->output_section
);
7887 /* The first instruction in a stub is always a branch. */
7888 if (!elfNN_aarch64_output_map_sym (&osi
, AARCH64_MAP_INSN
, 0))
7891 bfd_hash_traverse (&htab
->stub_hash_table
, aarch64_map_one_stub
,
7896 /* Finally, output mapping symbols for the PLT. */
7897 if (!htab
->root
.splt
|| htab
->root
.splt
->size
== 0)
7900 osi
.sec_shndx
= _bfd_elf_section_from_bfd_section
7901 (output_bfd
, htab
->root
.splt
->output_section
);
7902 osi
.sec
= htab
->root
.splt
;
7904 elfNN_aarch64_output_map_sym (&osi
, AARCH64_MAP_INSN
, 0);
7910 /* Allocate target specific section data. */
7913 elfNN_aarch64_new_section_hook (bfd
*abfd
, asection
*sec
)
7915 if (!sec
->used_by_bfd
)
7917 _aarch64_elf_section_data
*sdata
;
7918 bfd_size_type amt
= sizeof (*sdata
);
7920 sdata
= bfd_zalloc (abfd
, amt
);
7923 sec
->used_by_bfd
= sdata
;
7926 record_section_with_aarch64_elf_section_data (sec
);
7928 return _bfd_elf_new_section_hook (abfd
, sec
);
7933 unrecord_section_via_map_over_sections (bfd
*abfd ATTRIBUTE_UNUSED
,
7935 void *ignore ATTRIBUTE_UNUSED
)
7937 unrecord_section_with_aarch64_elf_section_data (sec
);
7941 elfNN_aarch64_close_and_cleanup (bfd
*abfd
)
7944 bfd_map_over_sections (abfd
,
7945 unrecord_section_via_map_over_sections
, NULL
);
7947 return _bfd_elf_close_and_cleanup (abfd
);
7951 elfNN_aarch64_bfd_free_cached_info (bfd
*abfd
)
7954 bfd_map_over_sections (abfd
,
7955 unrecord_section_via_map_over_sections
, NULL
);
7957 return _bfd_free_cached_info (abfd
);
7960 /* Create dynamic sections. This is different from the ARM backend in that
7961 the got, plt, gotplt and their relocation sections are all created in the
7962 standard part of the bfd elf backend. */
7965 elfNN_aarch64_create_dynamic_sections (bfd
*dynobj
,
7966 struct bfd_link_info
*info
)
7968 /* We need to create .got section. */
7969 if (!aarch64_elf_create_got_section (dynobj
, info
))
7972 return _bfd_elf_create_dynamic_sections (dynobj
, info
);
7976 /* Allocate space in .plt, .got and associated reloc sections for
7980 elfNN_aarch64_allocate_dynrelocs (struct elf_link_hash_entry
*h
, void *inf
)
7982 struct bfd_link_info
*info
;
7983 struct elf_aarch64_link_hash_table
*htab
;
7984 struct elf_aarch64_link_hash_entry
*eh
;
7985 struct elf_dyn_relocs
*p
;
7987 /* An example of a bfd_link_hash_indirect symbol is versioned
7988 symbol. For example: __gxx_personality_v0(bfd_link_hash_indirect)
7989 -> __gxx_personality_v0(bfd_link_hash_defined)
7991 There is no need to process bfd_link_hash_indirect symbols here
7992 because we will also be presented with the concrete instance of
7993 the symbol and elfNN_aarch64_copy_indirect_symbol () will have been
7994 called to copy all relevant data from the generic to the concrete
7996 if (h
->root
.type
== bfd_link_hash_indirect
)
7999 if (h
->root
.type
== bfd_link_hash_warning
)
8000 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
8002 info
= (struct bfd_link_info
*) inf
;
8003 htab
= elf_aarch64_hash_table (info
);
8005 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle it
8006 here if it is defined and referenced in a non-shared object. */
8007 if (h
->type
== STT_GNU_IFUNC
8010 else if (htab
->root
.dynamic_sections_created
&& h
->plt
.refcount
> 0)
8012 /* Make sure this symbol is output as a dynamic symbol.
8013 Undefined weak syms won't yet be marked as dynamic. */
8014 if (h
->dynindx
== -1 && !h
->forced_local
)
8016 if (!bfd_elf_link_record_dynamic_symbol (info
, h
))
8020 if (bfd_link_pic (info
) || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h
))
8022 asection
*s
= htab
->root
.splt
;
8024 /* If this is the first .plt entry, make room for the special
8027 s
->size
+= htab
->plt_header_size
;
8029 h
->plt
.offset
= s
->size
;
8031 /* If this symbol is not defined in a regular file, and we are
8032 not generating a shared library, then set the symbol to this
8033 location in the .plt. This is required to make function
8034 pointers compare as equal between the normal executable and
8035 the shared library. */
8036 if (!bfd_link_pic (info
) && !h
->def_regular
)
8038 h
->root
.u
.def
.section
= s
;
8039 h
->root
.u
.def
.value
= h
->plt
.offset
;
8042 /* Make room for this entry. For now we only create the
8043 small model PLT entries. We later need to find a way
8044 of relaxing into these from the large model PLT entries. */
8045 s
->size
+= PLT_SMALL_ENTRY_SIZE
;
8047 /* We also need to make an entry in the .got.plt section, which
8048 will be placed in the .got section by the linker script. */
8049 htab
->root
.sgotplt
->size
+= GOT_ENTRY_SIZE
;
8051 /* We also need to make an entry in the .rela.plt section. */
8052 htab
->root
.srelplt
->size
+= RELOC_SIZE (htab
);
8054 /* We need to ensure that all GOT entries that serve the PLT
8055 are consecutive with the special GOT slots [0] [1] and
8056 [2]. Any addtional relocations, such as
8057 R_AARCH64_TLSDESC, must be placed after the PLT related
8058 entries. We abuse the reloc_count such that during
8059 sizing we adjust reloc_count to indicate the number of
8060 PLT related reserved entries. In subsequent phases when
8061 filling in the contents of the reloc entries, PLT related
8062 entries are placed by computing their PLT index (0
8063 .. reloc_count). While other none PLT relocs are placed
8064 at the slot indicated by reloc_count and reloc_count is
8067 htab
->root
.srelplt
->reloc_count
++;
8071 h
->plt
.offset
= (bfd_vma
) - 1;
8077 h
->plt
.offset
= (bfd_vma
) - 1;
8081 eh
= (struct elf_aarch64_link_hash_entry
*) h
;
8082 eh
->tlsdesc_got_jump_table_offset
= (bfd_vma
) - 1;
8084 if (h
->got
.refcount
> 0)
8087 unsigned got_type
= elf_aarch64_hash_entry (h
)->got_type
;
8089 h
->got
.offset
= (bfd_vma
) - 1;
8091 dyn
= htab
->root
.dynamic_sections_created
;
8093 /* Make sure this symbol is output as a dynamic symbol.
8094 Undefined weak syms won't yet be marked as dynamic. */
8095 if (dyn
&& h
->dynindx
== -1 && !h
->forced_local
)
8097 if (!bfd_elf_link_record_dynamic_symbol (info
, h
))
8101 if (got_type
== GOT_UNKNOWN
)
8104 else if (got_type
== GOT_NORMAL
)
8106 h
->got
.offset
= htab
->root
.sgot
->size
;
8107 htab
->root
.sgot
->size
+= GOT_ENTRY_SIZE
;
8108 if ((ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
8109 || h
->root
.type
!= bfd_link_hash_undefweak
)
8110 && (bfd_link_pic (info
)
8111 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, 0, h
)))
8113 htab
->root
.srelgot
->size
+= RELOC_SIZE (htab
);
8119 if (got_type
& GOT_TLSDESC_GD
)
8121 eh
->tlsdesc_got_jump_table_offset
=
8122 (htab
->root
.sgotplt
->size
8123 - aarch64_compute_jump_table_size (htab
));
8124 htab
->root
.sgotplt
->size
+= GOT_ENTRY_SIZE
* 2;
8125 h
->got
.offset
= (bfd_vma
) - 2;
8128 if (got_type
& GOT_TLS_GD
)
8130 h
->got
.offset
= htab
->root
.sgot
->size
;
8131 htab
->root
.sgot
->size
+= GOT_ENTRY_SIZE
* 2;
8134 if (got_type
& GOT_TLS_IE
)
8136 h
->got
.offset
= htab
->root
.sgot
->size
;
8137 htab
->root
.sgot
->size
+= GOT_ENTRY_SIZE
;
8140 indx
= h
&& h
->dynindx
!= -1 ? h
->dynindx
: 0;
8141 if ((ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
8142 || h
->root
.type
!= bfd_link_hash_undefweak
)
8143 && (bfd_link_pic (info
)
8145 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, 0, h
)))
8147 if (got_type
& GOT_TLSDESC_GD
)
8149 htab
->root
.srelplt
->size
+= RELOC_SIZE (htab
);
8150 /* Note reloc_count not incremented here! We have
8151 already adjusted reloc_count for this relocation
8154 /* TLSDESC PLT is now needed, but not yet determined. */
8155 htab
->tlsdesc_plt
= (bfd_vma
) - 1;
8158 if (got_type
& GOT_TLS_GD
)
8159 htab
->root
.srelgot
->size
+= RELOC_SIZE (htab
) * 2;
8161 if (got_type
& GOT_TLS_IE
)
8162 htab
->root
.srelgot
->size
+= RELOC_SIZE (htab
);
8168 h
->got
.offset
= (bfd_vma
) - 1;
8171 if (eh
->dyn_relocs
== NULL
)
8174 /* In the shared -Bsymbolic case, discard space allocated for
8175 dynamic pc-relative relocs against symbols which turn out to be
8176 defined in regular objects. For the normal shared case, discard
8177 space for pc-relative relocs that have become local due to symbol
8178 visibility changes. */
8180 if (bfd_link_pic (info
))
8182 /* Relocs that use pc_count are those that appear on a call
8183 insn, or certain REL relocs that can generated via assembly.
8184 We want calls to protected symbols to resolve directly to the
8185 function rather than going via the plt. If people want
8186 function pointer comparisons to work as expected then they
8187 should avoid writing weird assembly. */
8188 if (SYMBOL_CALLS_LOCAL (info
, h
))
8190 struct elf_dyn_relocs
**pp
;
8192 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
;)
8194 p
->count
-= p
->pc_count
;
8203 /* Also discard relocs on undefined weak syms with non-default
8205 if (eh
->dyn_relocs
!= NULL
&& h
->root
.type
== bfd_link_hash_undefweak
)
8207 if (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
)
8208 eh
->dyn_relocs
= NULL
;
8210 /* Make sure undefined weak symbols are output as a dynamic
8212 else if (h
->dynindx
== -1
8214 && !bfd_elf_link_record_dynamic_symbol (info
, h
))
8219 else if (ELIMINATE_COPY_RELOCS
)
8221 /* For the non-shared case, discard space for relocs against
8222 symbols which turn out to need copy relocs or are not
8228 || (htab
->root
.dynamic_sections_created
8229 && (h
->root
.type
== bfd_link_hash_undefweak
8230 || h
->root
.type
== bfd_link_hash_undefined
))))
8232 /* Make sure this symbol is output as a dynamic symbol.
8233 Undefined weak syms won't yet be marked as dynamic. */
8234 if (h
->dynindx
== -1
8236 && !bfd_elf_link_record_dynamic_symbol (info
, h
))
8239 /* If that succeeded, we know we'll be keeping all the
8241 if (h
->dynindx
!= -1)
8245 eh
->dyn_relocs
= NULL
;
8250 /* Finally, allocate space. */
8251 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
8255 sreloc
= elf_section_data (p
->sec
)->sreloc
;
8257 BFD_ASSERT (sreloc
!= NULL
);
8259 sreloc
->size
+= p
->count
* RELOC_SIZE (htab
);
8265 /* Allocate space in .plt, .got and associated reloc sections for
8266 ifunc dynamic relocs. */
8269 elfNN_aarch64_allocate_ifunc_dynrelocs (struct elf_link_hash_entry
*h
,
8272 struct bfd_link_info
*info
;
8273 struct elf_aarch64_link_hash_table
*htab
;
8274 struct elf_aarch64_link_hash_entry
*eh
;
8276 /* An example of a bfd_link_hash_indirect symbol is versioned
8277 symbol. For example: __gxx_personality_v0(bfd_link_hash_indirect)
8278 -> __gxx_personality_v0(bfd_link_hash_defined)
8280 There is no need to process bfd_link_hash_indirect symbols here
8281 because we will also be presented with the concrete instance of
8282 the symbol and elfNN_aarch64_copy_indirect_symbol () will have been
8283 called to copy all relevant data from the generic to the concrete
8285 if (h
->root
.type
== bfd_link_hash_indirect
)
8288 if (h
->root
.type
== bfd_link_hash_warning
)
8289 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
8291 info
= (struct bfd_link_info
*) inf
;
8292 htab
= elf_aarch64_hash_table (info
);
8294 eh
= (struct elf_aarch64_link_hash_entry
*) h
;
8296 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle it
8297 here if it is defined and referenced in a non-shared object. */
8298 if (h
->type
== STT_GNU_IFUNC
8300 return _bfd_elf_allocate_ifunc_dyn_relocs (info
, h
,
8303 htab
->plt_entry_size
,
8304 htab
->plt_header_size
,
8310 /* Allocate space in .plt, .got and associated reloc sections for
8311 local dynamic relocs. */
8314 elfNN_aarch64_allocate_local_dynrelocs (void **slot
, void *inf
)
8316 struct elf_link_hash_entry
*h
8317 = (struct elf_link_hash_entry
*) *slot
;
8319 if (h
->type
!= STT_GNU_IFUNC
8323 || h
->root
.type
!= bfd_link_hash_defined
)
8326 return elfNN_aarch64_allocate_dynrelocs (h
, inf
);
8329 /* Allocate space in .plt, .got and associated reloc sections for
8330 local ifunc dynamic relocs. */
8333 elfNN_aarch64_allocate_local_ifunc_dynrelocs (void **slot
, void *inf
)
8335 struct elf_link_hash_entry
*h
8336 = (struct elf_link_hash_entry
*) *slot
;
8338 if (h
->type
!= STT_GNU_IFUNC
8342 || h
->root
.type
!= bfd_link_hash_defined
)
8345 return elfNN_aarch64_allocate_ifunc_dynrelocs (h
, inf
);
8348 /* Find any dynamic relocs that apply to read-only sections. */
8351 aarch64_readonly_dynrelocs (struct elf_link_hash_entry
* h
, void * inf
)
8353 struct elf_aarch64_link_hash_entry
* eh
;
8354 struct elf_dyn_relocs
* p
;
8356 eh
= (struct elf_aarch64_link_hash_entry
*) h
;
8357 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
8359 asection
*s
= p
->sec
;
8361 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
8363 struct bfd_link_info
*info
= (struct bfd_link_info
*) inf
;
8365 info
->flags
|= DF_TEXTREL
;
8367 /* Not an error, just cut short the traversal. */
8374 /* This is the most important function of all . Innocuosly named
8378 elfNN_aarch64_size_dynamic_sections (bfd
*output_bfd ATTRIBUTE_UNUSED
,
8379 struct bfd_link_info
*info
)
8381 struct elf_aarch64_link_hash_table
*htab
;
8387 htab
= elf_aarch64_hash_table ((info
));
8388 dynobj
= htab
->root
.dynobj
;
8390 BFD_ASSERT (dynobj
!= NULL
);
8392 if (htab
->root
.dynamic_sections_created
)
8394 if (bfd_link_executable (info
) && !info
->nointerp
)
8396 s
= bfd_get_linker_section (dynobj
, ".interp");
8399 s
->size
= sizeof ELF_DYNAMIC_INTERPRETER
;
8400 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
8404 /* Set up .got offsets for local syms, and space for local dynamic
8406 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
8408 struct elf_aarch64_local_symbol
*locals
= NULL
;
8409 Elf_Internal_Shdr
*symtab_hdr
;
8413 if (!is_aarch64_elf (ibfd
))
8416 for (s
= ibfd
->sections
; s
!= NULL
; s
= s
->next
)
8418 struct elf_dyn_relocs
*p
;
8420 for (p
= (struct elf_dyn_relocs
*)
8421 (elf_section_data (s
)->local_dynrel
); p
!= NULL
; p
= p
->next
)
8423 if (!bfd_is_abs_section (p
->sec
)
8424 && bfd_is_abs_section (p
->sec
->output_section
))
8426 /* Input section has been discarded, either because
8427 it is a copy of a linkonce section or due to
8428 linker script /DISCARD/, so we'll be discarding
8431 else if (p
->count
!= 0)
8433 srel
= elf_section_data (p
->sec
)->sreloc
;
8434 srel
->size
+= p
->count
* RELOC_SIZE (htab
);
8435 if ((p
->sec
->output_section
->flags
& SEC_READONLY
) != 0)
8436 info
->flags
|= DF_TEXTREL
;
8441 locals
= elf_aarch64_locals (ibfd
);
8445 symtab_hdr
= &elf_symtab_hdr (ibfd
);
8446 srel
= htab
->root
.srelgot
;
8447 for (i
= 0; i
< symtab_hdr
->sh_info
; i
++)
8449 locals
[i
].got_offset
= (bfd_vma
) - 1;
8450 locals
[i
].tlsdesc_got_jump_table_offset
= (bfd_vma
) - 1;
8451 if (locals
[i
].got_refcount
> 0)
8453 unsigned got_type
= locals
[i
].got_type
;
8454 if (got_type
& GOT_TLSDESC_GD
)
8456 locals
[i
].tlsdesc_got_jump_table_offset
=
8457 (htab
->root
.sgotplt
->size
8458 - aarch64_compute_jump_table_size (htab
));
8459 htab
->root
.sgotplt
->size
+= GOT_ENTRY_SIZE
* 2;
8460 locals
[i
].got_offset
= (bfd_vma
) - 2;
8463 if (got_type
& GOT_TLS_GD
)
8465 locals
[i
].got_offset
= htab
->root
.sgot
->size
;
8466 htab
->root
.sgot
->size
+= GOT_ENTRY_SIZE
* 2;
8469 if (got_type
& GOT_TLS_IE
8470 || got_type
& GOT_NORMAL
)
8472 locals
[i
].got_offset
= htab
->root
.sgot
->size
;
8473 htab
->root
.sgot
->size
+= GOT_ENTRY_SIZE
;
8476 if (got_type
== GOT_UNKNOWN
)
8480 if (bfd_link_pic (info
))
8482 if (got_type
& GOT_TLSDESC_GD
)
8484 htab
->root
.srelplt
->size
+= RELOC_SIZE (htab
);
8485 /* Note RELOC_COUNT not incremented here! */
8486 htab
->tlsdesc_plt
= (bfd_vma
) - 1;
8489 if (got_type
& GOT_TLS_GD
)
8490 htab
->root
.srelgot
->size
+= RELOC_SIZE (htab
) * 2;
8492 if (got_type
& GOT_TLS_IE
8493 || got_type
& GOT_NORMAL
)
8494 htab
->root
.srelgot
->size
+= RELOC_SIZE (htab
);
8499 locals
[i
].got_refcount
= (bfd_vma
) - 1;
8505 /* Allocate global sym .plt and .got entries, and space for global
8506 sym dynamic relocs. */
8507 elf_link_hash_traverse (&htab
->root
, elfNN_aarch64_allocate_dynrelocs
,
8510 /* Allocate global ifunc sym .plt and .got entries, and space for global
8511 ifunc sym dynamic relocs. */
8512 elf_link_hash_traverse (&htab
->root
, elfNN_aarch64_allocate_ifunc_dynrelocs
,
8515 /* Allocate .plt and .got entries, and space for local symbols. */
8516 htab_traverse (htab
->loc_hash_table
,
8517 elfNN_aarch64_allocate_local_dynrelocs
,
8520 /* Allocate .plt and .got entries, and space for local ifunc symbols. */
8521 htab_traverse (htab
->loc_hash_table
,
8522 elfNN_aarch64_allocate_local_ifunc_dynrelocs
,
8525 /* For every jump slot reserved in the sgotplt, reloc_count is
8526 incremented. However, when we reserve space for TLS descriptors,
8527 it's not incremented, so in order to compute the space reserved
8528 for them, it suffices to multiply the reloc count by the jump
8531 if (htab
->root
.srelplt
)
8532 htab
->sgotplt_jump_table_size
= aarch64_compute_jump_table_size (htab
);
8534 if (htab
->tlsdesc_plt
)
8536 if (htab
->root
.splt
->size
== 0)
8537 htab
->root
.splt
->size
+= PLT_ENTRY_SIZE
;
8539 htab
->tlsdesc_plt
= htab
->root
.splt
->size
;
8540 htab
->root
.splt
->size
+= PLT_TLSDESC_ENTRY_SIZE
;
8542 /* If we're not using lazy TLS relocations, don't generate the
8543 GOT entry required. */
8544 if (!(info
->flags
& DF_BIND_NOW
))
8546 htab
->dt_tlsdesc_got
= htab
->root
.sgot
->size
;
8547 htab
->root
.sgot
->size
+= GOT_ENTRY_SIZE
;
8551 /* Init mapping symbols information to use later to distingush between
8552 code and data while scanning for errata. */
8553 if (htab
->fix_erratum_835769
|| htab
->fix_erratum_843419
)
8554 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
8556 if (!is_aarch64_elf (ibfd
))
8558 bfd_elfNN_aarch64_init_maps (ibfd
);
8561 /* We now have determined the sizes of the various dynamic sections.
8562 Allocate memory for them. */
8564 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
8566 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
8569 if (s
== htab
->root
.splt
8570 || s
== htab
->root
.sgot
8571 || s
== htab
->root
.sgotplt
8572 || s
== htab
->root
.iplt
8573 || s
== htab
->root
.igotplt
8574 || s
== htab
->root
.sdynbss
8575 || s
== htab
->root
.sdynrelro
)
8577 /* Strip this section if we don't need it; see the
8580 else if (CONST_STRNEQ (bfd_get_section_name (dynobj
, s
), ".rela"))
8582 if (s
->size
!= 0 && s
!= htab
->root
.srelplt
)
8585 /* We use the reloc_count field as a counter if we need
8586 to copy relocs into the output file. */
8587 if (s
!= htab
->root
.srelplt
)
8592 /* It's not one of our sections, so don't allocate space. */
8598 /* If we don't need this section, strip it from the
8599 output file. This is mostly to handle .rela.bss and
8600 .rela.plt. We must create both sections in
8601 create_dynamic_sections, because they must be created
8602 before the linker maps input sections to output
8603 sections. The linker does that before
8604 adjust_dynamic_symbol is called, and it is that
8605 function which decides whether anything needs to go
8606 into these sections. */
8607 s
->flags
|= SEC_EXCLUDE
;
8611 if ((s
->flags
& SEC_HAS_CONTENTS
) == 0)
8614 /* Allocate memory for the section contents. We use bfd_zalloc
8615 here in case unused entries are not reclaimed before the
8616 section's contents are written out. This should not happen,
8617 but this way if it does, we get a R_AARCH64_NONE reloc instead
8619 s
->contents
= (bfd_byte
*) bfd_zalloc (dynobj
, s
->size
);
8620 if (s
->contents
== NULL
)
8624 if (htab
->root
.dynamic_sections_created
)
8626 /* Add some entries to the .dynamic section. We fill in the
8627 values later, in elfNN_aarch64_finish_dynamic_sections, but we
8628 must add the entries now so that we get the correct size for
8629 the .dynamic section. The DT_DEBUG entry is filled in by the
8630 dynamic linker and used by the debugger. */
8631 #define add_dynamic_entry(TAG, VAL) \
8632 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
8634 if (bfd_link_executable (info
))
8636 if (!add_dynamic_entry (DT_DEBUG
, 0))
8640 if (htab
->root
.splt
->size
!= 0)
8642 if (!add_dynamic_entry (DT_PLTGOT
, 0)
8643 || !add_dynamic_entry (DT_PLTRELSZ
, 0)
8644 || !add_dynamic_entry (DT_PLTREL
, DT_RELA
)
8645 || !add_dynamic_entry (DT_JMPREL
, 0))
8648 if (htab
->tlsdesc_plt
8649 && (!add_dynamic_entry (DT_TLSDESC_PLT
, 0)
8650 || !add_dynamic_entry (DT_TLSDESC_GOT
, 0)))
8656 if (!add_dynamic_entry (DT_RELA
, 0)
8657 || !add_dynamic_entry (DT_RELASZ
, 0)
8658 || !add_dynamic_entry (DT_RELAENT
, RELOC_SIZE (htab
)))
8661 /* If any dynamic relocs apply to a read-only section,
8662 then we need a DT_TEXTREL entry. */
8663 if ((info
->flags
& DF_TEXTREL
) == 0)
8664 elf_link_hash_traverse (& htab
->root
, aarch64_readonly_dynrelocs
,
8667 if ((info
->flags
& DF_TEXTREL
) != 0)
8669 if (!add_dynamic_entry (DT_TEXTREL
, 0))
8674 #undef add_dynamic_entry
8680 elf_aarch64_update_plt_entry (bfd
*output_bfd
,
8681 bfd_reloc_code_real_type r_type
,
8682 bfd_byte
*plt_entry
, bfd_vma value
)
8684 reloc_howto_type
*howto
= elfNN_aarch64_howto_from_bfd_reloc (r_type
);
8686 _bfd_aarch64_elf_put_addend (output_bfd
, plt_entry
, r_type
, howto
, value
);
8690 elfNN_aarch64_create_small_pltn_entry (struct elf_link_hash_entry
*h
,
8691 struct elf_aarch64_link_hash_table
8692 *htab
, bfd
*output_bfd
,
8693 struct bfd_link_info
*info
)
8695 bfd_byte
*plt_entry
;
8698 bfd_vma gotplt_entry_address
;
8699 bfd_vma plt_entry_address
;
8700 Elf_Internal_Rela rela
;
8702 asection
*plt
, *gotplt
, *relplt
;
8704 /* When building a static executable, use .iplt, .igot.plt and
8705 .rela.iplt sections for STT_GNU_IFUNC symbols. */
8706 if (htab
->root
.splt
!= NULL
)
8708 plt
= htab
->root
.splt
;
8709 gotplt
= htab
->root
.sgotplt
;
8710 relplt
= htab
->root
.srelplt
;
8714 plt
= htab
->root
.iplt
;
8715 gotplt
= htab
->root
.igotplt
;
8716 relplt
= htab
->root
.irelplt
;
8719 /* Get the index in the procedure linkage table which
8720 corresponds to this symbol. This is the index of this symbol
8721 in all the symbols for which we are making plt entries. The
8722 first entry in the procedure linkage table is reserved.
8724 Get the offset into the .got table of the entry that
8725 corresponds to this function. Each .got entry is GOT_ENTRY_SIZE
8726 bytes. The first three are reserved for the dynamic linker.
8728 For static executables, we don't reserve anything. */
8730 if (plt
== htab
->root
.splt
)
8732 plt_index
= (h
->plt
.offset
- htab
->plt_header_size
) / htab
->plt_entry_size
;
8733 got_offset
= (plt_index
+ 3) * GOT_ENTRY_SIZE
;
8737 plt_index
= h
->plt
.offset
/ htab
->plt_entry_size
;
8738 got_offset
= plt_index
* GOT_ENTRY_SIZE
;
8741 plt_entry
= plt
->contents
+ h
->plt
.offset
;
8742 plt_entry_address
= plt
->output_section
->vma
8743 + plt
->output_offset
+ h
->plt
.offset
;
8744 gotplt_entry_address
= gotplt
->output_section
->vma
+
8745 gotplt
->output_offset
+ got_offset
;
8747 /* Copy in the boiler-plate for the PLTn entry. */
8748 memcpy (plt_entry
, elfNN_aarch64_small_plt_entry
, PLT_SMALL_ENTRY_SIZE
);
8750 /* Fill in the top 21 bits for this: ADRP x16, PLT_GOT + n * 8.
8751 ADRP: ((PG(S+A)-PG(P)) >> 12) & 0x1fffff */
8752 elf_aarch64_update_plt_entry (output_bfd
, BFD_RELOC_AARCH64_ADR_HI21_PCREL
,
8754 PG (gotplt_entry_address
) -
8755 PG (plt_entry_address
));
8757 /* Fill in the lo12 bits for the load from the pltgot. */
8758 elf_aarch64_update_plt_entry (output_bfd
, BFD_RELOC_AARCH64_LDSTNN_LO12
,
8760 PG_OFFSET (gotplt_entry_address
));
8762 /* Fill in the lo12 bits for the add from the pltgot entry. */
8763 elf_aarch64_update_plt_entry (output_bfd
, BFD_RELOC_AARCH64_ADD_LO12
,
8765 PG_OFFSET (gotplt_entry_address
));
8767 /* All the GOTPLT Entries are essentially initialized to PLT0. */
8768 bfd_put_NN (output_bfd
,
8769 plt
->output_section
->vma
+ plt
->output_offset
,
8770 gotplt
->contents
+ got_offset
);
8772 rela
.r_offset
= gotplt_entry_address
;
8774 if (h
->dynindx
== -1
8775 || ((bfd_link_executable (info
)
8776 || ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
)
8778 && h
->type
== STT_GNU_IFUNC
))
8780 /* If an STT_GNU_IFUNC symbol is locally defined, generate
8781 R_AARCH64_IRELATIVE instead of R_AARCH64_JUMP_SLOT. */
8782 rela
.r_info
= ELFNN_R_INFO (0, AARCH64_R (IRELATIVE
));
8783 rela
.r_addend
= (h
->root
.u
.def
.value
8784 + h
->root
.u
.def
.section
->output_section
->vma
8785 + h
->root
.u
.def
.section
->output_offset
);
8789 /* Fill in the entry in the .rela.plt section. */
8790 rela
.r_info
= ELFNN_R_INFO (h
->dynindx
, AARCH64_R (JUMP_SLOT
));
8794 /* Compute the relocation entry to used based on PLT index and do
8795 not adjust reloc_count. The reloc_count has already been adjusted
8796 to account for this entry. */
8797 loc
= relplt
->contents
+ plt_index
* RELOC_SIZE (htab
);
8798 bfd_elfNN_swap_reloca_out (output_bfd
, &rela
, loc
);
8801 /* Size sections even though they're not dynamic. We use it to setup
8802 _TLS_MODULE_BASE_, if needed. */
8805 elfNN_aarch64_always_size_sections (bfd
*output_bfd
,
8806 struct bfd_link_info
*info
)
8810 if (bfd_link_relocatable (info
))
8813 tls_sec
= elf_hash_table (info
)->tls_sec
;
8817 struct elf_link_hash_entry
*tlsbase
;
8819 tlsbase
= elf_link_hash_lookup (elf_hash_table (info
),
8820 "_TLS_MODULE_BASE_", TRUE
, TRUE
, FALSE
);
8824 struct bfd_link_hash_entry
*h
= NULL
;
8825 const struct elf_backend_data
*bed
=
8826 get_elf_backend_data (output_bfd
);
8828 if (!(_bfd_generic_link_add_one_symbol
8829 (info
, output_bfd
, "_TLS_MODULE_BASE_", BSF_LOCAL
,
8830 tls_sec
, 0, NULL
, FALSE
, bed
->collect
, &h
)))
8833 tlsbase
->type
= STT_TLS
;
8834 tlsbase
= (struct elf_link_hash_entry
*) h
;
8835 tlsbase
->def_regular
= 1;
8836 tlsbase
->other
= STV_HIDDEN
;
8837 (*bed
->elf_backend_hide_symbol
) (info
, tlsbase
, TRUE
);
8844 /* Finish up dynamic symbol handling. We set the contents of various
8845 dynamic sections here. */
8848 elfNN_aarch64_finish_dynamic_symbol (bfd
*output_bfd
,
8849 struct bfd_link_info
*info
,
8850 struct elf_link_hash_entry
*h
,
8851 Elf_Internal_Sym
*sym
)
8853 struct elf_aarch64_link_hash_table
*htab
;
8854 htab
= elf_aarch64_hash_table (info
);
8856 if (h
->plt
.offset
!= (bfd_vma
) - 1)
8858 asection
*plt
, *gotplt
, *relplt
;
8860 /* This symbol has an entry in the procedure linkage table. Set
8863 /* When building a static executable, use .iplt, .igot.plt and
8864 .rela.iplt sections for STT_GNU_IFUNC symbols. */
8865 if (htab
->root
.splt
!= NULL
)
8867 plt
= htab
->root
.splt
;
8868 gotplt
= htab
->root
.sgotplt
;
8869 relplt
= htab
->root
.srelplt
;
8873 plt
= htab
->root
.iplt
;
8874 gotplt
= htab
->root
.igotplt
;
8875 relplt
= htab
->root
.irelplt
;
8878 /* This symbol has an entry in the procedure linkage table. Set
8880 if ((h
->dynindx
== -1
8881 && !((h
->forced_local
|| bfd_link_executable (info
))
8883 && h
->type
== STT_GNU_IFUNC
))
8889 elfNN_aarch64_create_small_pltn_entry (h
, htab
, output_bfd
, info
);
8890 if (!h
->def_regular
)
8892 /* Mark the symbol as undefined, rather than as defined in
8893 the .plt section. */
8894 sym
->st_shndx
= SHN_UNDEF
;
8895 /* If the symbol is weak we need to clear the value.
8896 Otherwise, the PLT entry would provide a definition for
8897 the symbol even if the symbol wasn't defined anywhere,
8898 and so the symbol would never be NULL. Leave the value if
8899 there were any relocations where pointer equality matters
8900 (this is a clue for the dynamic linker, to make function
8901 pointer comparisons work between an application and shared
8903 if (!h
->ref_regular_nonweak
|| !h
->pointer_equality_needed
)
8908 if (h
->got
.offset
!= (bfd_vma
) - 1
8909 && elf_aarch64_hash_entry (h
)->got_type
== GOT_NORMAL
)
8911 Elf_Internal_Rela rela
;
8914 /* This symbol has an entry in the global offset table. Set it
8916 if (htab
->root
.sgot
== NULL
|| htab
->root
.srelgot
== NULL
)
8919 rela
.r_offset
= (htab
->root
.sgot
->output_section
->vma
8920 + htab
->root
.sgot
->output_offset
8921 + (h
->got
.offset
& ~(bfd_vma
) 1));
8924 && h
->type
== STT_GNU_IFUNC
)
8926 if (bfd_link_pic (info
))
8928 /* Generate R_AARCH64_GLOB_DAT. */
8935 if (!h
->pointer_equality_needed
)
8938 /* For non-shared object, we can't use .got.plt, which
8939 contains the real function address if we need pointer
8940 equality. We load the GOT entry with the PLT entry. */
8941 plt
= htab
->root
.splt
? htab
->root
.splt
: htab
->root
.iplt
;
8942 bfd_put_NN (output_bfd
, (plt
->output_section
->vma
8943 + plt
->output_offset
8945 htab
->root
.sgot
->contents
8946 + (h
->got
.offset
& ~(bfd_vma
) 1));
8950 else if (bfd_link_pic (info
) && SYMBOL_REFERENCES_LOCAL (info
, h
))
8952 if (!h
->def_regular
)
8955 BFD_ASSERT ((h
->got
.offset
& 1) != 0);
8956 rela
.r_info
= ELFNN_R_INFO (0, AARCH64_R (RELATIVE
));
8957 rela
.r_addend
= (h
->root
.u
.def
.value
8958 + h
->root
.u
.def
.section
->output_section
->vma
8959 + h
->root
.u
.def
.section
->output_offset
);
8964 BFD_ASSERT ((h
->got
.offset
& 1) == 0);
8965 bfd_put_NN (output_bfd
, (bfd_vma
) 0,
8966 htab
->root
.sgot
->contents
+ h
->got
.offset
);
8967 rela
.r_info
= ELFNN_R_INFO (h
->dynindx
, AARCH64_R (GLOB_DAT
));
8971 loc
= htab
->root
.srelgot
->contents
;
8972 loc
+= htab
->root
.srelgot
->reloc_count
++ * RELOC_SIZE (htab
);
8973 bfd_elfNN_swap_reloca_out (output_bfd
, &rela
, loc
);
8978 Elf_Internal_Rela rela
;
8982 /* This symbol needs a copy reloc. Set it up. */
8983 if (h
->dynindx
== -1
8984 || (h
->root
.type
!= bfd_link_hash_defined
8985 && h
->root
.type
!= bfd_link_hash_defweak
)
8986 || htab
->root
.srelbss
== NULL
)
8989 rela
.r_offset
= (h
->root
.u
.def
.value
8990 + h
->root
.u
.def
.section
->output_section
->vma
8991 + h
->root
.u
.def
.section
->output_offset
);
8992 rela
.r_info
= ELFNN_R_INFO (h
->dynindx
, AARCH64_R (COPY
));
8994 if (h
->root
.u
.def
.section
== htab
->root
.sdynrelro
)
8995 s
= htab
->root
.sreldynrelro
;
8997 s
= htab
->root
.srelbss
;
8998 loc
= s
->contents
+ s
->reloc_count
++ * RELOC_SIZE (htab
);
8999 bfd_elfNN_swap_reloca_out (output_bfd
, &rela
, loc
);
9002 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. SYM may
9003 be NULL for local symbols. */
9005 && (h
== elf_hash_table (info
)->hdynamic
9006 || h
== elf_hash_table (info
)->hgot
))
9007 sym
->st_shndx
= SHN_ABS
;
9012 /* Finish up local dynamic symbol handling. We set the contents of
9013 various dynamic sections here. */
9016 elfNN_aarch64_finish_local_dynamic_symbol (void **slot
, void *inf
)
9018 struct elf_link_hash_entry
*h
9019 = (struct elf_link_hash_entry
*) *slot
;
9020 struct bfd_link_info
*info
9021 = (struct bfd_link_info
*) inf
;
9023 return elfNN_aarch64_finish_dynamic_symbol (info
->output_bfd
,
9028 elfNN_aarch64_init_small_plt0_entry (bfd
*output_bfd ATTRIBUTE_UNUSED
,
9029 struct elf_aarch64_link_hash_table
9032 /* Fill in PLT0. Fixme:RR Note this doesn't distinguish between
9033 small and large plts and at the minute just generates
9036 /* PLT0 of the small PLT looks like this in ELF64 -
9037 stp x16, x30, [sp, #-16]! // Save the reloc and lr on stack.
9038 adrp x16, PLT_GOT + 16 // Get the page base of the GOTPLT
9039 ldr x17, [x16, #:lo12:PLT_GOT+16] // Load the address of the
9041 add x16, x16, #:lo12:PLT_GOT+16 // Load the lo12 bits of the
9042 // GOTPLT entry for this.
9044 PLT0 will be slightly different in ELF32 due to different got entry
9046 bfd_vma plt_got_2nd_ent
; /* Address of GOT[2]. */
9050 memcpy (htab
->root
.splt
->contents
, elfNN_aarch64_small_plt0_entry
,
9052 elf_section_data (htab
->root
.splt
->output_section
)->this_hdr
.sh_entsize
=
9055 plt_got_2nd_ent
= (htab
->root
.sgotplt
->output_section
->vma
9056 + htab
->root
.sgotplt
->output_offset
9057 + GOT_ENTRY_SIZE
* 2);
9059 plt_base
= htab
->root
.splt
->output_section
->vma
+
9060 htab
->root
.splt
->output_offset
;
9062 /* Fill in the top 21 bits for this: ADRP x16, PLT_GOT + n * 8.
9063 ADRP: ((PG(S+A)-PG(P)) >> 12) & 0x1fffff */
9064 elf_aarch64_update_plt_entry (output_bfd
, BFD_RELOC_AARCH64_ADR_HI21_PCREL
,
9065 htab
->root
.splt
->contents
+ 4,
9066 PG (plt_got_2nd_ent
) - PG (plt_base
+ 4));
9068 elf_aarch64_update_plt_entry (output_bfd
, BFD_RELOC_AARCH64_LDSTNN_LO12
,
9069 htab
->root
.splt
->contents
+ 8,
9070 PG_OFFSET (plt_got_2nd_ent
));
9072 elf_aarch64_update_plt_entry (output_bfd
, BFD_RELOC_AARCH64_ADD_LO12
,
9073 htab
->root
.splt
->contents
+ 12,
9074 PG_OFFSET (plt_got_2nd_ent
));
9078 elfNN_aarch64_finish_dynamic_sections (bfd
*output_bfd
,
9079 struct bfd_link_info
*info
)
9081 struct elf_aarch64_link_hash_table
*htab
;
9085 htab
= elf_aarch64_hash_table (info
);
9086 dynobj
= htab
->root
.dynobj
;
9087 sdyn
= bfd_get_linker_section (dynobj
, ".dynamic");
9089 if (htab
->root
.dynamic_sections_created
)
9091 ElfNN_External_Dyn
*dyncon
, *dynconend
;
9093 if (sdyn
== NULL
|| htab
->root
.sgot
== NULL
)
9096 dyncon
= (ElfNN_External_Dyn
*) sdyn
->contents
;
9097 dynconend
= (ElfNN_External_Dyn
*) (sdyn
->contents
+ sdyn
->size
);
9098 for (; dyncon
< dynconend
; dyncon
++)
9100 Elf_Internal_Dyn dyn
;
9103 bfd_elfNN_swap_dyn_in (dynobj
, dyncon
, &dyn
);
9111 s
= htab
->root
.sgotplt
;
9112 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
9116 s
= htab
->root
.srelplt
;
9117 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
9121 s
= htab
->root
.srelplt
;
9122 dyn
.d_un
.d_val
= s
->size
;
9125 case DT_TLSDESC_PLT
:
9126 s
= htab
->root
.splt
;
9127 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
9128 + htab
->tlsdesc_plt
;
9131 case DT_TLSDESC_GOT
:
9132 s
= htab
->root
.sgot
;
9133 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
9134 + htab
->dt_tlsdesc_got
;
9138 bfd_elfNN_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
9143 /* Fill in the special first entry in the procedure linkage table. */
9144 if (htab
->root
.splt
&& htab
->root
.splt
->size
> 0)
9146 elfNN_aarch64_init_small_plt0_entry (output_bfd
, htab
);
9148 elf_section_data (htab
->root
.splt
->output_section
)->
9149 this_hdr
.sh_entsize
= htab
->plt_entry_size
;
9152 if (htab
->tlsdesc_plt
)
9154 bfd_put_NN (output_bfd
, (bfd_vma
) 0,
9155 htab
->root
.sgot
->contents
+ htab
->dt_tlsdesc_got
);
9157 memcpy (htab
->root
.splt
->contents
+ htab
->tlsdesc_plt
,
9158 elfNN_aarch64_tlsdesc_small_plt_entry
,
9159 sizeof (elfNN_aarch64_tlsdesc_small_plt_entry
));
9162 bfd_vma adrp1_addr
=
9163 htab
->root
.splt
->output_section
->vma
9164 + htab
->root
.splt
->output_offset
+ htab
->tlsdesc_plt
+ 4;
9166 bfd_vma adrp2_addr
= adrp1_addr
+ 4;
9169 htab
->root
.sgot
->output_section
->vma
9170 + htab
->root
.sgot
->output_offset
;
9172 bfd_vma pltgot_addr
=
9173 htab
->root
.sgotplt
->output_section
->vma
9174 + htab
->root
.sgotplt
->output_offset
;
9176 bfd_vma dt_tlsdesc_got
= got_addr
+ htab
->dt_tlsdesc_got
;
9178 bfd_byte
*plt_entry
=
9179 htab
->root
.splt
->contents
+ htab
->tlsdesc_plt
;
9181 /* adrp x2, DT_TLSDESC_GOT */
9182 elf_aarch64_update_plt_entry (output_bfd
,
9183 BFD_RELOC_AARCH64_ADR_HI21_PCREL
,
9185 (PG (dt_tlsdesc_got
)
9186 - PG (adrp1_addr
)));
9189 elf_aarch64_update_plt_entry (output_bfd
,
9190 BFD_RELOC_AARCH64_ADR_HI21_PCREL
,
9193 - PG (adrp2_addr
)));
9195 /* ldr x2, [x2, #0] */
9196 elf_aarch64_update_plt_entry (output_bfd
,
9197 BFD_RELOC_AARCH64_LDSTNN_LO12
,
9199 PG_OFFSET (dt_tlsdesc_got
));
9202 elf_aarch64_update_plt_entry (output_bfd
,
9203 BFD_RELOC_AARCH64_ADD_LO12
,
9205 PG_OFFSET (pltgot_addr
));
9210 if (htab
->root
.sgotplt
)
9212 if (bfd_is_abs_section (htab
->root
.sgotplt
->output_section
))
9215 (_("discarded output section: `%A'"), htab
->root
.sgotplt
);
9219 /* Fill in the first three entries in the global offset table. */
9220 if (htab
->root
.sgotplt
->size
> 0)
9222 bfd_put_NN (output_bfd
, (bfd_vma
) 0, htab
->root
.sgotplt
->contents
);
9224 /* Write GOT[1] and GOT[2], needed for the dynamic linker. */
9225 bfd_put_NN (output_bfd
,
9227 htab
->root
.sgotplt
->contents
+ GOT_ENTRY_SIZE
);
9228 bfd_put_NN (output_bfd
,
9230 htab
->root
.sgotplt
->contents
+ GOT_ENTRY_SIZE
* 2);
9233 if (htab
->root
.sgot
)
9235 if (htab
->root
.sgot
->size
> 0)
9238 sdyn
? sdyn
->output_section
->vma
+ sdyn
->output_offset
: 0;
9239 bfd_put_NN (output_bfd
, addr
, htab
->root
.sgot
->contents
);
9243 elf_section_data (htab
->root
.sgotplt
->output_section
)->
9244 this_hdr
.sh_entsize
= GOT_ENTRY_SIZE
;
9247 if (htab
->root
.sgot
&& htab
->root
.sgot
->size
> 0)
9248 elf_section_data (htab
->root
.sgot
->output_section
)->this_hdr
.sh_entsize
9251 /* Fill PLT and GOT entries for local STT_GNU_IFUNC symbols. */
9252 htab_traverse (htab
->loc_hash_table
,
9253 elfNN_aarch64_finish_local_dynamic_symbol
,
9259 /* Return address for Ith PLT stub in section PLT, for relocation REL
9260 or (bfd_vma) -1 if it should not be included. */
9263 elfNN_aarch64_plt_sym_val (bfd_vma i
, const asection
*plt
,
9264 const arelent
*rel ATTRIBUTE_UNUSED
)
9266 return plt
->vma
+ PLT_ENTRY_SIZE
+ i
* PLT_SMALL_ENTRY_SIZE
;
9269 /* Returns TRUE if NAME is an AArch64 mapping symbol.
9270 The ARM ELF standard defines $x (for A64 code) and $d (for data).
9271 It also allows a period initiated suffix to be added to the symbol, ie:
9272 "$[adtx]\.[:sym_char]+". */
9275 is_aarch64_mapping_symbol (const char * name
)
9277 return name
!= NULL
/* Paranoia. */
9278 && name
[0] == '$' /* Note: if objcopy --prefix-symbols has been used then
9279 the mapping symbols could have acquired a prefix.
9280 We do not support this here, since such symbols no
9281 longer conform to the ARM ELF ABI. */
9282 && (name
[1] == 'd' || name
[1] == 'x')
9283 && (name
[2] == 0 || name
[2] == '.');
9284 /* FIXME: Strictly speaking the symbol is only a valid mapping symbol if
9285 any characters that follow the period are legal characters for the body
9286 of a symbol's name. For now we just assume that this is the case. */
9289 /* Make sure that mapping symbols in object files are not removed via the
9290 "strip --strip-unneeded" tool. These symbols might needed in order to
9291 correctly generate linked files. Once an object file has been linked,
9292 it should be safe to remove them. */
9295 elfNN_aarch64_backend_symbol_processing (bfd
*abfd
, asymbol
*sym
)
9297 if (((abfd
->flags
& (EXEC_P
| DYNAMIC
)) == 0)
9298 && sym
->section
!= bfd_abs_section_ptr
9299 && is_aarch64_mapping_symbol (sym
->name
))
9300 sym
->flags
|= BSF_KEEP
;
9304 /* We use this so we can override certain functions
9305 (though currently we don't). */
9307 const struct elf_size_info elfNN_aarch64_size_info
=
9309 sizeof (ElfNN_External_Ehdr
),
9310 sizeof (ElfNN_External_Phdr
),
9311 sizeof (ElfNN_External_Shdr
),
9312 sizeof (ElfNN_External_Rel
),
9313 sizeof (ElfNN_External_Rela
),
9314 sizeof (ElfNN_External_Sym
),
9315 sizeof (ElfNN_External_Dyn
),
9316 sizeof (Elf_External_Note
),
9317 4, /* Hash table entry size. */
9318 1, /* Internal relocs per external relocs. */
9319 ARCH_SIZE
, /* Arch size. */
9320 LOG_FILE_ALIGN
, /* Log_file_align. */
9321 ELFCLASSNN
, EV_CURRENT
,
9322 bfd_elfNN_write_out_phdrs
,
9323 bfd_elfNN_write_shdrs_and_ehdr
,
9324 bfd_elfNN_checksum_contents
,
9325 bfd_elfNN_write_relocs
,
9326 bfd_elfNN_swap_symbol_in
,
9327 bfd_elfNN_swap_symbol_out
,
9328 bfd_elfNN_slurp_reloc_table
,
9329 bfd_elfNN_slurp_symbol_table
,
9330 bfd_elfNN_swap_dyn_in
,
9331 bfd_elfNN_swap_dyn_out
,
9332 bfd_elfNN_swap_reloc_in
,
9333 bfd_elfNN_swap_reloc_out
,
9334 bfd_elfNN_swap_reloca_in
,
9335 bfd_elfNN_swap_reloca_out
9338 #define ELF_ARCH bfd_arch_aarch64
9339 #define ELF_MACHINE_CODE EM_AARCH64
9340 #define ELF_MAXPAGESIZE 0x10000
9341 #define ELF_MINPAGESIZE 0x1000
9342 #define ELF_COMMONPAGESIZE 0x1000
9344 #define bfd_elfNN_close_and_cleanup \
9345 elfNN_aarch64_close_and_cleanup
9347 #define bfd_elfNN_bfd_free_cached_info \
9348 elfNN_aarch64_bfd_free_cached_info
9350 #define bfd_elfNN_bfd_is_target_special_symbol \
9351 elfNN_aarch64_is_target_special_symbol
9353 #define bfd_elfNN_bfd_link_hash_table_create \
9354 elfNN_aarch64_link_hash_table_create
9356 #define bfd_elfNN_bfd_merge_private_bfd_data \
9357 elfNN_aarch64_merge_private_bfd_data
9359 #define bfd_elfNN_bfd_print_private_bfd_data \
9360 elfNN_aarch64_print_private_bfd_data
9362 #define bfd_elfNN_bfd_reloc_type_lookup \
9363 elfNN_aarch64_reloc_type_lookup
9365 #define bfd_elfNN_bfd_reloc_name_lookup \
9366 elfNN_aarch64_reloc_name_lookup
9368 #define bfd_elfNN_bfd_set_private_flags \
9369 elfNN_aarch64_set_private_flags
9371 #define bfd_elfNN_find_inliner_info \
9372 elfNN_aarch64_find_inliner_info
9374 #define bfd_elfNN_find_nearest_line \
9375 elfNN_aarch64_find_nearest_line
9377 #define bfd_elfNN_mkobject \
9378 elfNN_aarch64_mkobject
9380 #define bfd_elfNN_new_section_hook \
9381 elfNN_aarch64_new_section_hook
9383 #define elf_backend_adjust_dynamic_symbol \
9384 elfNN_aarch64_adjust_dynamic_symbol
9386 #define elf_backend_always_size_sections \
9387 elfNN_aarch64_always_size_sections
9389 #define elf_backend_check_relocs \
9390 elfNN_aarch64_check_relocs
9392 #define elf_backend_copy_indirect_symbol \
9393 elfNN_aarch64_copy_indirect_symbol
9395 /* Create .dynbss, and .rela.bss sections in DYNOBJ, and set up shortcuts
9396 to them in our hash. */
9397 #define elf_backend_create_dynamic_sections \
9398 elfNN_aarch64_create_dynamic_sections
9400 #define elf_backend_init_index_section \
9401 _bfd_elf_init_2_index_sections
9403 #define elf_backend_finish_dynamic_sections \
9404 elfNN_aarch64_finish_dynamic_sections
9406 #define elf_backend_finish_dynamic_symbol \
9407 elfNN_aarch64_finish_dynamic_symbol
9409 #define elf_backend_gc_sweep_hook \
9410 elfNN_aarch64_gc_sweep_hook
9412 #define elf_backend_object_p \
9413 elfNN_aarch64_object_p
9415 #define elf_backend_output_arch_local_syms \
9416 elfNN_aarch64_output_arch_local_syms
9418 #define elf_backend_plt_sym_val \
9419 elfNN_aarch64_plt_sym_val
9421 #define elf_backend_post_process_headers \
9422 elfNN_aarch64_post_process_headers
9424 #define elf_backend_relocate_section \
9425 elfNN_aarch64_relocate_section
9427 #define elf_backend_reloc_type_class \
9428 elfNN_aarch64_reloc_type_class
9430 #define elf_backend_section_from_shdr \
9431 elfNN_aarch64_section_from_shdr
9433 #define elf_backend_size_dynamic_sections \
9434 elfNN_aarch64_size_dynamic_sections
9436 #define elf_backend_size_info \
9437 elfNN_aarch64_size_info
9439 #define elf_backend_write_section \
9440 elfNN_aarch64_write_section
9442 #define elf_backend_symbol_processing \
9443 elfNN_aarch64_backend_symbol_processing
9445 #define elf_backend_can_refcount 1
9446 #define elf_backend_can_gc_sections 1
9447 #define elf_backend_plt_readonly 1
9448 #define elf_backend_want_got_plt 1
9449 #define elf_backend_want_plt_sym 0
9450 #define elf_backend_want_dynrelro 1
9451 #define elf_backend_may_use_rel_p 0
9452 #define elf_backend_may_use_rela_p 1
9453 #define elf_backend_default_use_rela_p 1
9454 #define elf_backend_rela_normal 1
9455 #define elf_backend_dtrel_excludes_plt 1
9456 #define elf_backend_got_header_size (GOT_ENTRY_SIZE * 3)
9457 #define elf_backend_default_execstack 0
9458 #define elf_backend_extern_protected_data 1
9459 #define elf_backend_hash_symbol elf_aarch64_hash_symbol
9461 #undef elf_backend_obj_attrs_section
9462 #define elf_backend_obj_attrs_section ".ARM.attributes"
9464 #include "elfNN-target.h"
9466 /* CloudABI support. */
9468 #undef TARGET_LITTLE_SYM
9469 #define TARGET_LITTLE_SYM aarch64_elfNN_le_cloudabi_vec
9470 #undef TARGET_LITTLE_NAME
9471 #define TARGET_LITTLE_NAME "elfNN-littleaarch64-cloudabi"
9472 #undef TARGET_BIG_SYM
9473 #define TARGET_BIG_SYM aarch64_elfNN_be_cloudabi_vec
9474 #undef TARGET_BIG_NAME
9475 #define TARGET_BIG_NAME "elfNN-bigaarch64-cloudabi"
9478 #define ELF_OSABI ELFOSABI_CLOUDABI
9481 #define elfNN_bed elfNN_aarch64_cloudabi_bed
9483 #include "elfNN-target.h"