1 /* ELF support for AArch64.
2 Copyright 2009, 2010, 2011, 2012 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_PAGE(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_PAGE,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_DTPMOD64
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_DTPREL64 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 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_PAGE,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 elf64_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 elf64_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 elf64_aarch64_relocate_section ()
124 Calls elf64_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 elf64_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 "elf/aarch64.h"
147 static bfd_reloc_status_type
148 bfd_elf_aarch64_put_addend (bfd
*abfd
,
150 reloc_howto_type
*howto
, bfd_signed_vma addend
);
152 #define IS_AARCH64_TLS_RELOC(R_TYPE) \
153 ((R_TYPE) == R_AARCH64_TLSGD_ADR_PAGE21 \
154 || (R_TYPE) == R_AARCH64_TLSGD_ADD_LO12_NC \
155 || (R_TYPE) == R_AARCH64_TLSIE_MOVW_GOTTPREL_G1 \
156 || (R_TYPE) == R_AARCH64_TLSIE_MOVW_GOTTPREL_G0_NC \
157 || (R_TYPE) == R_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21 \
158 || (R_TYPE) == R_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC \
159 || (R_TYPE) == R_AARCH64_TLSIE_LD_GOTTPREL_PREL19 \
160 || (R_TYPE) == R_AARCH64_TLSLE_ADD_TPREL_LO12 \
161 || (R_TYPE) == R_AARCH64_TLSLE_ADD_TPREL_HI12 \
162 || (R_TYPE) == R_AARCH64_TLSLE_ADD_TPREL_LO12_NC \
163 || (R_TYPE) == R_AARCH64_TLSLE_MOVW_TPREL_G2 \
164 || (R_TYPE) == R_AARCH64_TLSLE_MOVW_TPREL_G1 \
165 || (R_TYPE) == R_AARCH64_TLSLE_MOVW_TPREL_G1_NC \
166 || (R_TYPE) == R_AARCH64_TLSLE_MOVW_TPREL_G0 \
167 || (R_TYPE) == R_AARCH64_TLSLE_MOVW_TPREL_G0_NC \
168 || (R_TYPE) == R_AARCH64_TLS_DTPMOD64 \
169 || (R_TYPE) == R_AARCH64_TLS_DTPREL64 \
170 || (R_TYPE) == R_AARCH64_TLS_TPREL64 \
171 || IS_AARCH64_TLSDESC_RELOC ((R_TYPE)))
173 #define IS_AARCH64_TLSDESC_RELOC(R_TYPE) \
174 ((R_TYPE) == R_AARCH64_TLSDESC_LD64_PREL19 \
175 || (R_TYPE) == R_AARCH64_TLSDESC_ADR_PREL21 \
176 || (R_TYPE) == R_AARCH64_TLSDESC_ADR_PAGE \
177 || (R_TYPE) == R_AARCH64_TLSDESC_ADD_LO12_NC \
178 || (R_TYPE) == R_AARCH64_TLSDESC_LD64_LO12_NC \
179 || (R_TYPE) == R_AARCH64_TLSDESC_OFF_G1 \
180 || (R_TYPE) == R_AARCH64_TLSDESC_OFF_G0_NC \
181 || (R_TYPE) == R_AARCH64_TLSDESC_LDR \
182 || (R_TYPE) == R_AARCH64_TLSDESC_ADD \
183 || (R_TYPE) == R_AARCH64_TLSDESC_CALL \
184 || (R_TYPE) == R_AARCH64_TLSDESC)
186 #define ELIMINATE_COPY_RELOCS 0
188 /* Return the relocation section associated with NAME. HTAB is the
189 bfd's elf64_aarch64_link_hash_entry. */
190 #define RELOC_SECTION(HTAB, NAME) \
191 ((HTAB)->use_rel ? ".rel" NAME : ".rela" NAME)
193 /* Return size of a relocation entry. HTAB is the bfd's
194 elf64_aarch64_link_hash_entry. */
195 #define RELOC_SIZE(HTAB) (sizeof (Elf64_External_Rela))
197 /* Return function to swap relocations in. HTAB is the bfd's
198 elf64_aarch64_link_hash_entry. */
199 #define SWAP_RELOC_IN(HTAB) (bfd_elf64_swap_reloca_in)
201 /* Return function to swap relocations out. HTAB is the bfd's
202 elf64_aarch64_link_hash_entry. */
203 #define SWAP_RELOC_OUT(HTAB) (bfd_elf64_swap_reloca_out)
205 /* GOT Entry size - 8 bytes. */
206 #define GOT_ENTRY_SIZE (8)
207 #define PLT_ENTRY_SIZE (32)
208 #define PLT_SMALL_ENTRY_SIZE (16)
209 #define PLT_TLSDESC_ENTRY_SIZE (32)
211 /* Take the PAGE component of an address or offset. */
212 #define PG(x) ((x) & ~ 0xfff)
213 #define PG_OFFSET(x) ((x) & 0xfff)
215 /* Encoding of the nop instruction */
216 #define INSN_NOP 0xd503201f
218 #define aarch64_compute_jump_table_size(htab) \
219 (((htab)->root.srelplt == NULL) ? 0 \
220 : (htab)->root.srelplt->reloc_count * GOT_ENTRY_SIZE)
222 /* The first entry in a procedure linkage table looks like this
223 if the distance between the PLTGOT and the PLT is < 4GB use
224 these PLT entries. Note that the dynamic linker gets &PLTGOT[2]
225 in x16 and needs to work out PLTGOT[1] by using an address of
227 static const bfd_byte elf64_aarch64_small_plt0_entry
[PLT_ENTRY_SIZE
] =
229 0xf0, 0x7b, 0xbf, 0xa9, /* stp x16, x30, [sp, #-16]! */
230 0x10, 0x00, 0x00, 0x90, /* adrp x16, (GOT+16) */
231 0x11, 0x0A, 0x40, 0xf9, /* ldr x17, [x16, #PLT_GOT+0x10] */
232 0x10, 0x42, 0x00, 0x91, /* add x16, x16,#PLT_GOT+0x10 */
233 0x20, 0x02, 0x1f, 0xd6, /* br x17 */
234 0x1f, 0x20, 0x03, 0xd5, /* nop */
235 0x1f, 0x20, 0x03, 0xd5, /* nop */
236 0x1f, 0x20, 0x03, 0xd5, /* nop */
239 /* Per function entry in a procedure linkage table looks like this
240 if the distance between the PLTGOT and the PLT is < 4GB use
241 these PLT entries. */
242 static const bfd_byte elf64_aarch64_small_plt_entry
[PLT_SMALL_ENTRY_SIZE
] =
244 0x10, 0x00, 0x00, 0x90, /* adrp x16, PLTGOT + n * 8 */
245 0x11, 0x02, 0x40, 0xf9, /* ldr x17, [x16, PLTGOT + n * 8] */
246 0x10, 0x02, 0x00, 0x91, /* add x16, x16, :lo12:PLTGOT + n * 8 */
247 0x20, 0x02, 0x1f, 0xd6, /* br x17. */
250 static const bfd_byte
251 elf64_aarch64_tlsdesc_small_plt_entry
[PLT_TLSDESC_ENTRY_SIZE
] =
253 0xe2, 0x0f, 0xbf, 0xa9, /* stp x2, x3, [sp, #-16]! */
254 0x02, 0x00, 0x00, 0x90, /* adrp x2, 0 */
255 0x03, 0x00, 0x00, 0x90, /* adrp x3, 0 */
256 0x42, 0x08, 0x40, 0xF9, /* ldr x2, [x2, #0] */
257 0x63, 0x00, 0x00, 0x91, /* add x3, x3, 0 */
258 0x40, 0x00, 0x1F, 0xD6, /* br x2 */
259 0x1f, 0x20, 0x03, 0xd5, /* nop */
260 0x1f, 0x20, 0x03, 0xd5, /* nop */
263 #define elf_info_to_howto elf64_aarch64_info_to_howto
264 #define elf_info_to_howto_rel elf64_aarch64_info_to_howto
266 #define AARCH64_ELF_ABI_VERSION 0
267 #define AARCH64_ELF_OS_ABI_VERSION 0
269 /* In case we're on a 32-bit machine, construct a 64-bit "-1" value. */
270 #define ALL_ONES (~ (bfd_vma) 0)
272 static reloc_howto_type elf64_aarch64_howto_none
=
273 HOWTO (R_AARCH64_NONE
, /* type */
275 0, /* size (0 = byte, 1 = short, 2 = long) */
277 FALSE
, /* pc_relative */
279 complain_overflow_dont
,/* complain_on_overflow */
280 bfd_elf_generic_reloc
, /* special_function */
281 "R_AARCH64_NONE", /* name */
282 FALSE
, /* partial_inplace */
285 FALSE
); /* pcrel_offset */
287 static reloc_howto_type elf64_aarch64_howto_dynrelocs
[] =
289 HOWTO (R_AARCH64_COPY
, /* type */
291 2, /* size (0 = byte, 1 = short, 2 = long) */
293 FALSE
, /* pc_relative */
295 complain_overflow_bitfield
, /* complain_on_overflow */
296 bfd_elf_generic_reloc
, /* special_function */
297 "R_AARCH64_COPY", /* name */
298 TRUE
, /* partial_inplace */
299 0xffffffff, /* src_mask */
300 0xffffffff, /* dst_mask */
301 FALSE
), /* pcrel_offset */
303 HOWTO (R_AARCH64_GLOB_DAT
, /* type */
305 2, /* size (0 = byte, 1 = short, 2 = long) */
307 FALSE
, /* pc_relative */
309 complain_overflow_bitfield
, /* complain_on_overflow */
310 bfd_elf_generic_reloc
, /* special_function */
311 "R_AARCH64_GLOB_DAT", /* name */
312 TRUE
, /* partial_inplace */
313 0xffffffff, /* src_mask */
314 0xffffffff, /* dst_mask */
315 FALSE
), /* pcrel_offset */
317 HOWTO (R_AARCH64_JUMP_SLOT
, /* type */
319 2, /* size (0 = byte, 1 = short, 2 = long) */
321 FALSE
, /* pc_relative */
323 complain_overflow_bitfield
, /* complain_on_overflow */
324 bfd_elf_generic_reloc
, /* special_function */
325 "R_AARCH64_JUMP_SLOT", /* name */
326 TRUE
, /* partial_inplace */
327 0xffffffff, /* src_mask */
328 0xffffffff, /* dst_mask */
329 FALSE
), /* pcrel_offset */
331 HOWTO (R_AARCH64_RELATIVE
, /* type */
333 2, /* size (0 = byte, 1 = short, 2 = long) */
335 FALSE
, /* pc_relative */
337 complain_overflow_bitfield
, /* complain_on_overflow */
338 bfd_elf_generic_reloc
, /* special_function */
339 "R_AARCH64_RELATIVE", /* name */
340 TRUE
, /* partial_inplace */
341 ALL_ONES
, /* src_mask */
342 ALL_ONES
, /* dst_mask */
343 FALSE
), /* pcrel_offset */
345 HOWTO (R_AARCH64_TLS_DTPMOD64
, /* type */
347 2, /* size (0 = byte, 1 = short, 2 = long) */
349 FALSE
, /* pc_relative */
351 complain_overflow_dont
, /* complain_on_overflow */
352 bfd_elf_generic_reloc
, /* special_function */
353 "R_AARCH64_TLS_DTPMOD64", /* name */
354 FALSE
, /* partial_inplace */
356 ALL_ONES
, /* dst_mask */
357 FALSE
), /* pc_reloffset */
359 HOWTO (R_AARCH64_TLS_DTPREL64
, /* type */
361 2, /* 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_TLS_DTPREL64", /* name */
368 FALSE
, /* partial_inplace */
370 ALL_ONES
, /* dst_mask */
371 FALSE
), /* pcrel_offset */
373 HOWTO (R_AARCH64_TLS_TPREL64
, /* type */
375 2, /* size (0 = byte, 1 = short, 2 = long) */
377 FALSE
, /* pc_relative */
379 complain_overflow_dont
, /* complain_on_overflow */
380 bfd_elf_generic_reloc
, /* special_function */
381 "R_AARCH64_TLS_TPREL64", /* name */
382 FALSE
, /* partial_inplace */
384 ALL_ONES
, /* dst_mask */
385 FALSE
), /* pcrel_offset */
387 HOWTO (R_AARCH64_TLSDESC
, /* type */
389 2, /* size (0 = byte, 1 = short, 2 = long) */
391 FALSE
, /* pc_relative */
393 complain_overflow_dont
, /* complain_on_overflow */
394 bfd_elf_generic_reloc
, /* special_function */
395 "R_AARCH64_TLSDESC", /* name */
396 FALSE
, /* partial_inplace */
398 ALL_ONES
, /* dst_mask */
399 FALSE
), /* pcrel_offset */
403 /* Note: code such as elf64_aarch64_reloc_type_lookup expect to use e.g.
404 R_AARCH64_PREL64 as an index into this, and find the R_AARCH64_PREL64 HOWTO
407 static reloc_howto_type elf64_aarch64_howto_table
[] =
409 /* Basic data relocations. */
411 HOWTO (R_AARCH64_NULL
, /* type */
413 0, /* size (0 = byte, 1 = short, 2 = long) */
415 FALSE
, /* pc_relative */
417 complain_overflow_dont
, /* complain_on_overflow */
418 bfd_elf_generic_reloc
, /* special_function */
419 "R_AARCH64_NULL", /* name */
420 FALSE
, /* partial_inplace */
423 FALSE
), /* pcrel_offset */
426 HOWTO (R_AARCH64_ABS64
, /* type */
428 4, /* size (4 = long long) */
430 FALSE
, /* pc_relative */
432 complain_overflow_unsigned
, /* complain_on_overflow */
433 bfd_elf_generic_reloc
, /* special_function */
434 "R_AARCH64_ABS64", /* name */
435 FALSE
, /* partial_inplace */
436 ALL_ONES
, /* src_mask */
437 ALL_ONES
, /* dst_mask */
438 FALSE
), /* pcrel_offset */
441 HOWTO (R_AARCH64_ABS32
, /* type */
443 2, /* size (0 = byte, 1 = short, 2 = long) */
445 FALSE
, /* pc_relative */
447 complain_overflow_unsigned
, /* complain_on_overflow */
448 bfd_elf_generic_reloc
, /* special_function */
449 "R_AARCH64_ABS32", /* name */
450 FALSE
, /* partial_inplace */
451 0xffffffff, /* src_mask */
452 0xffffffff, /* dst_mask */
453 FALSE
), /* pcrel_offset */
456 HOWTO (R_AARCH64_ABS16
, /* type */
458 1, /* size (0 = byte, 1 = short, 2 = long) */
460 FALSE
, /* pc_relative */
462 complain_overflow_unsigned
, /* complain_on_overflow */
463 bfd_elf_generic_reloc
, /* special_function */
464 "R_AARCH64_ABS16", /* name */
465 FALSE
, /* partial_inplace */
466 0xffff, /* src_mask */
467 0xffff, /* dst_mask */
468 FALSE
), /* pcrel_offset */
470 /* .xword: (S+A-P) */
471 HOWTO (R_AARCH64_PREL64
, /* type */
473 4, /* size (4 = long long) */
475 TRUE
, /* pc_relative */
477 complain_overflow_signed
, /* complain_on_overflow */
478 bfd_elf_generic_reloc
, /* special_function */
479 "R_AARCH64_PREL64", /* name */
480 FALSE
, /* partial_inplace */
481 ALL_ONES
, /* src_mask */
482 ALL_ONES
, /* dst_mask */
483 TRUE
), /* pcrel_offset */
486 HOWTO (R_AARCH64_PREL32
, /* type */
488 2, /* size (0 = byte, 1 = short, 2 = long) */
490 TRUE
, /* pc_relative */
492 complain_overflow_signed
, /* complain_on_overflow */
493 bfd_elf_generic_reloc
, /* special_function */
494 "R_AARCH64_PREL32", /* name */
495 FALSE
, /* partial_inplace */
496 0xffffffff, /* src_mask */
497 0xffffffff, /* dst_mask */
498 TRUE
), /* pcrel_offset */
501 HOWTO (R_AARCH64_PREL16
, /* type */
503 1, /* size (0 = byte, 1 = short, 2 = long) */
505 TRUE
, /* pc_relative */
507 complain_overflow_signed
, /* complain_on_overflow */
508 bfd_elf_generic_reloc
, /* special_function */
509 "R_AARCH64_PREL16", /* name */
510 FALSE
, /* partial_inplace */
511 0xffff, /* src_mask */
512 0xffff, /* dst_mask */
513 TRUE
), /* pcrel_offset */
515 /* Group relocations to create a 16, 32, 48 or 64 bit
516 unsigned data or abs address inline. */
518 /* MOVZ: ((S+A) >> 0) & 0xffff */
519 HOWTO (R_AARCH64_MOVW_UABS_G0
, /* type */
521 2, /* size (0 = byte, 1 = short, 2 = long) */
523 FALSE
, /* pc_relative */
525 complain_overflow_unsigned
, /* complain_on_overflow */
526 bfd_elf_generic_reloc
, /* special_function */
527 "R_AARCH64_MOVW_UABS_G0", /* name */
528 FALSE
, /* partial_inplace */
529 0xffff, /* src_mask */
530 0xffff, /* dst_mask */
531 FALSE
), /* pcrel_offset */
533 /* MOVK: ((S+A) >> 0) & 0xffff [no overflow check] */
534 HOWTO (R_AARCH64_MOVW_UABS_G0_NC
, /* type */
536 2, /* size (0 = byte, 1 = short, 2 = long) */
538 FALSE
, /* pc_relative */
540 complain_overflow_dont
, /* complain_on_overflow */
541 bfd_elf_generic_reloc
, /* special_function */
542 "R_AARCH64_MOVW_UABS_G0_NC", /* name */
543 FALSE
, /* partial_inplace */
544 0xffff, /* src_mask */
545 0xffff, /* dst_mask */
546 FALSE
), /* pcrel_offset */
548 /* MOVZ: ((S+A) >> 16) & 0xffff */
549 HOWTO (R_AARCH64_MOVW_UABS_G1
, /* type */
551 2, /* size (0 = byte, 1 = short, 2 = long) */
553 FALSE
, /* pc_relative */
555 complain_overflow_unsigned
, /* complain_on_overflow */
556 bfd_elf_generic_reloc
, /* special_function */
557 "R_AARCH64_MOVW_UABS_G1", /* name */
558 FALSE
, /* partial_inplace */
559 0xffff, /* src_mask */
560 0xffff, /* dst_mask */
561 FALSE
), /* pcrel_offset */
563 /* MOVK: ((S+A) >> 16) & 0xffff [no overflow check] */
564 HOWTO (R_AARCH64_MOVW_UABS_G1_NC
, /* type */
566 2, /* size (0 = byte, 1 = short, 2 = long) */
568 FALSE
, /* pc_relative */
570 complain_overflow_dont
, /* complain_on_overflow */
571 bfd_elf_generic_reloc
, /* special_function */
572 "R_AARCH64_MOVW_UABS_G1_NC", /* name */
573 FALSE
, /* partial_inplace */
574 0xffff, /* src_mask */
575 0xffff, /* dst_mask */
576 FALSE
), /* pcrel_offset */
578 /* MOVZ: ((S+A) >> 32) & 0xffff */
579 HOWTO (R_AARCH64_MOVW_UABS_G2
, /* type */
581 2, /* size (0 = byte, 1 = short, 2 = long) */
583 FALSE
, /* pc_relative */
585 complain_overflow_unsigned
, /* complain_on_overflow */
586 bfd_elf_generic_reloc
, /* special_function */
587 "R_AARCH64_MOVW_UABS_G2", /* name */
588 FALSE
, /* partial_inplace */
589 0xffff, /* src_mask */
590 0xffff, /* dst_mask */
591 FALSE
), /* pcrel_offset */
593 /* MOVK: ((S+A) >> 32) & 0xffff [no overflow check] */
594 HOWTO (R_AARCH64_MOVW_UABS_G2_NC
, /* type */
596 2, /* size (0 = byte, 1 = short, 2 = long) */
598 FALSE
, /* pc_relative */
600 complain_overflow_dont
, /* complain_on_overflow */
601 bfd_elf_generic_reloc
, /* special_function */
602 "R_AARCH64_MOVW_UABS_G2_NC", /* name */
603 FALSE
, /* partial_inplace */
604 0xffff, /* src_mask */
605 0xffff, /* dst_mask */
606 FALSE
), /* pcrel_offset */
608 /* MOVZ: ((S+A) >> 48) & 0xffff */
609 HOWTO (R_AARCH64_MOVW_UABS_G3
, /* type */
611 2, /* size (0 = byte, 1 = short, 2 = long) */
613 FALSE
, /* pc_relative */
615 complain_overflow_unsigned
, /* complain_on_overflow */
616 bfd_elf_generic_reloc
, /* special_function */
617 "R_AARCH64_MOVW_UABS_G3", /* name */
618 FALSE
, /* partial_inplace */
619 0xffff, /* src_mask */
620 0xffff, /* dst_mask */
621 FALSE
), /* pcrel_offset */
623 /* Group relocations to create high part of a 16, 32, 48 or 64 bit
624 signed data or abs address inline. Will change instruction
625 to MOVN or MOVZ depending on sign of calculated value. */
627 /* MOV[ZN]: ((S+A) >> 0) & 0xffff */
628 HOWTO (R_AARCH64_MOVW_SABS_G0
, /* type */
630 2, /* size (0 = byte, 1 = short, 2 = long) */
632 FALSE
, /* pc_relative */
634 complain_overflow_signed
, /* complain_on_overflow */
635 bfd_elf_generic_reloc
, /* special_function */
636 "R_AARCH64_MOVW_SABS_G0", /* name */
637 FALSE
, /* partial_inplace */
638 0xffff, /* src_mask */
639 0xffff, /* dst_mask */
640 FALSE
), /* pcrel_offset */
642 /* MOV[ZN]: ((S+A) >> 16) & 0xffff */
643 HOWTO (R_AARCH64_MOVW_SABS_G1
, /* type */
645 2, /* size (0 = byte, 1 = short, 2 = long) */
647 FALSE
, /* pc_relative */
649 complain_overflow_signed
, /* complain_on_overflow */
650 bfd_elf_generic_reloc
, /* special_function */
651 "R_AARCH64_MOVW_SABS_G1", /* name */
652 FALSE
, /* partial_inplace */
653 0xffff, /* src_mask */
654 0xffff, /* dst_mask */
655 FALSE
), /* pcrel_offset */
657 /* MOV[ZN]: ((S+A) >> 32) & 0xffff */
658 HOWTO (R_AARCH64_MOVW_SABS_G2
, /* type */
660 2, /* size (0 = byte, 1 = short, 2 = long) */
662 FALSE
, /* pc_relative */
664 complain_overflow_signed
, /* complain_on_overflow */
665 bfd_elf_generic_reloc
, /* special_function */
666 "R_AARCH64_MOVW_SABS_G2", /* name */
667 FALSE
, /* partial_inplace */
668 0xffff, /* src_mask */
669 0xffff, /* dst_mask */
670 FALSE
), /* pcrel_offset */
672 /* Relocations to generate 19, 21 and 33 bit PC-relative load/store
673 addresses: PG(x) is (x & ~0xfff). */
675 /* LD-lit: ((S+A-P) >> 2) & 0x7ffff */
676 HOWTO (R_AARCH64_LD_PREL_LO19
, /* type */
678 2, /* size (0 = byte, 1 = short, 2 = long) */
680 TRUE
, /* pc_relative */
682 complain_overflow_signed
, /* complain_on_overflow */
683 bfd_elf_generic_reloc
, /* special_function */
684 "R_AARCH64_LD_PREL_LO19", /* name */
685 FALSE
, /* partial_inplace */
686 0x7ffff, /* src_mask */
687 0x7ffff, /* dst_mask */
688 TRUE
), /* pcrel_offset */
690 /* ADR: (S+A-P) & 0x1fffff */
691 HOWTO (R_AARCH64_ADR_PREL_LO21
, /* type */
693 2, /* size (0 = byte, 1 = short, 2 = long) */
695 TRUE
, /* pc_relative */
697 complain_overflow_signed
, /* complain_on_overflow */
698 bfd_elf_generic_reloc
, /* special_function */
699 "R_AARCH64_ADR_PREL_LO21", /* name */
700 FALSE
, /* partial_inplace */
701 0x1fffff, /* src_mask */
702 0x1fffff, /* dst_mask */
703 TRUE
), /* pcrel_offset */
705 /* ADRP: ((PG(S+A)-PG(P)) >> 12) & 0x1fffff */
706 HOWTO (R_AARCH64_ADR_PREL_PG_HI21
, /* type */
708 2, /* size (0 = byte, 1 = short, 2 = long) */
710 TRUE
, /* pc_relative */
712 complain_overflow_signed
, /* complain_on_overflow */
713 bfd_elf_generic_reloc
, /* special_function */
714 "R_AARCH64_ADR_PREL_PG_HI21", /* name */
715 FALSE
, /* partial_inplace */
716 0x1fffff, /* src_mask */
717 0x1fffff, /* dst_mask */
718 TRUE
), /* pcrel_offset */
720 /* ADRP: ((PG(S+A)-PG(P)) >> 12) & 0x1fffff [no overflow check] */
721 HOWTO (R_AARCH64_ADR_PREL_PG_HI21_NC
, /* type */
723 2, /* size (0 = byte, 1 = short, 2 = long) */
725 TRUE
, /* pc_relative */
727 complain_overflow_dont
, /* complain_on_overflow */
728 bfd_elf_generic_reloc
, /* special_function */
729 "R_AARCH64_ADR_PREL_PG_HI21_NC", /* name */
730 FALSE
, /* partial_inplace */
731 0x1fffff, /* src_mask */
732 0x1fffff, /* dst_mask */
733 TRUE
), /* pcrel_offset */
735 /* ADD: (S+A) & 0xfff [no overflow check] */
736 HOWTO (R_AARCH64_ADD_ABS_LO12_NC
, /* type */
738 2, /* size (0 = byte, 1 = short, 2 = long) */
740 FALSE
, /* pc_relative */
742 complain_overflow_dont
, /* complain_on_overflow */
743 bfd_elf_generic_reloc
, /* special_function */
744 "R_AARCH64_ADD_ABS_LO12_NC", /* name */
745 FALSE
, /* partial_inplace */
746 0x3ffc00, /* src_mask */
747 0x3ffc00, /* dst_mask */
748 FALSE
), /* pcrel_offset */
750 /* LD/ST8: (S+A) & 0xfff */
751 HOWTO (R_AARCH64_LDST8_ABS_LO12_NC
, /* type */
753 2, /* size (0 = byte, 1 = short, 2 = long) */
755 FALSE
, /* pc_relative */
757 complain_overflow_dont
, /* complain_on_overflow */
758 bfd_elf_generic_reloc
, /* special_function */
759 "R_AARCH64_LDST8_ABS_LO12_NC", /* name */
760 FALSE
, /* partial_inplace */
761 0xfff, /* src_mask */
762 0xfff, /* dst_mask */
763 FALSE
), /* pcrel_offset */
765 /* Relocations for control-flow instructions. */
767 /* TBZ/NZ: ((S+A-P) >> 2) & 0x3fff */
768 HOWTO (R_AARCH64_TSTBR14
, /* type */
770 2, /* size (0 = byte, 1 = short, 2 = long) */
772 TRUE
, /* pc_relative */
774 complain_overflow_signed
, /* complain_on_overflow */
775 bfd_elf_generic_reloc
, /* special_function */
776 "R_AARCH64_TSTBR14", /* name */
777 FALSE
, /* partial_inplace */
778 0x3fff, /* src_mask */
779 0x3fff, /* dst_mask */
780 TRUE
), /* pcrel_offset */
782 /* B.cond: ((S+A-P) >> 2) & 0x7ffff */
783 HOWTO (R_AARCH64_CONDBR19
, /* type */
785 2, /* size (0 = byte, 1 = short, 2 = long) */
787 TRUE
, /* pc_relative */
789 complain_overflow_signed
, /* complain_on_overflow */
790 bfd_elf_generic_reloc
, /* special_function */
791 "R_AARCH64_CONDBR19", /* name */
792 FALSE
, /* partial_inplace */
793 0x7ffff, /* src_mask */
794 0x7ffff, /* dst_mask */
795 TRUE
), /* pcrel_offset */
799 /* B: ((S+A-P) >> 2) & 0x3ffffff */
800 HOWTO (R_AARCH64_JUMP26
, /* type */
802 2, /* size (0 = byte, 1 = short, 2 = long) */
804 TRUE
, /* pc_relative */
806 complain_overflow_signed
, /* complain_on_overflow */
807 bfd_elf_generic_reloc
, /* special_function */
808 "R_AARCH64_JUMP26", /* name */
809 FALSE
, /* partial_inplace */
810 0x3ffffff, /* src_mask */
811 0x3ffffff, /* dst_mask */
812 TRUE
), /* pcrel_offset */
814 /* BL: ((S+A-P) >> 2) & 0x3ffffff */
815 HOWTO (R_AARCH64_CALL26
, /* type */
817 2, /* size (0 = byte, 1 = short, 2 = long) */
819 TRUE
, /* pc_relative */
821 complain_overflow_signed
, /* complain_on_overflow */
822 bfd_elf_generic_reloc
, /* special_function */
823 "R_AARCH64_CALL26", /* name */
824 FALSE
, /* partial_inplace */
825 0x3ffffff, /* src_mask */
826 0x3ffffff, /* dst_mask */
827 TRUE
), /* pcrel_offset */
829 /* LD/ST16: (S+A) & 0xffe */
830 HOWTO (R_AARCH64_LDST16_ABS_LO12_NC
, /* type */
832 2, /* size (0 = byte, 1 = short, 2 = long) */
834 FALSE
, /* pc_relative */
836 complain_overflow_dont
, /* complain_on_overflow */
837 bfd_elf_generic_reloc
, /* special_function */
838 "R_AARCH64_LDST16_ABS_LO12_NC", /* name */
839 FALSE
, /* partial_inplace */
840 0xffe, /* src_mask */
841 0xffe, /* dst_mask */
842 FALSE
), /* pcrel_offset */
844 /* LD/ST32: (S+A) & 0xffc */
845 HOWTO (R_AARCH64_LDST32_ABS_LO12_NC
, /* type */
847 2, /* size (0 = byte, 1 = short, 2 = long) */
849 FALSE
, /* pc_relative */
851 complain_overflow_dont
, /* complain_on_overflow */
852 bfd_elf_generic_reloc
, /* special_function */
853 "R_AARCH64_LDST32_ABS_LO12_NC", /* name */
854 FALSE
, /* partial_inplace */
855 0xffc, /* src_mask */
856 0xffc, /* dst_mask */
857 FALSE
), /* pcrel_offset */
859 /* LD/ST64: (S+A) & 0xff8 */
860 HOWTO (R_AARCH64_LDST64_ABS_LO12_NC
, /* type */
862 2, /* size (0 = byte, 1 = short, 2 = long) */
864 FALSE
, /* pc_relative */
866 complain_overflow_dont
, /* complain_on_overflow */
867 bfd_elf_generic_reloc
, /* special_function */
868 "R_AARCH64_LDST64_ABS_LO12_NC", /* name */
869 FALSE
, /* partial_inplace */
870 0xff8, /* src_mask */
871 0xff8, /* dst_mask */
872 FALSE
), /* pcrel_offset */
887 /* LD/ST128: (S+A) & 0xff0 */
888 HOWTO (R_AARCH64_LDST128_ABS_LO12_NC
, /* type */
890 2, /* size (0 = byte, 1 = short, 2 = long) */
892 FALSE
, /* pc_relative */
894 complain_overflow_dont
, /* complain_on_overflow */
895 bfd_elf_generic_reloc
, /* special_function */
896 "R_AARCH64_LDST128_ABS_LO12_NC", /* name */
897 FALSE
, /* partial_inplace */
898 0xff0, /* src_mask */
899 0xff0, /* dst_mask */
900 FALSE
), /* pcrel_offset */
912 /* Set a load-literal immediate field to bits
913 0x1FFFFC of G(S)-P */
914 HOWTO (R_AARCH64_GOT_LD_PREL19
, /* type */
916 2, /* size (0 = byte,1 = short,2 = long) */
918 TRUE
, /* pc_relative */
920 complain_overflow_signed
, /* complain_on_overflow */
921 bfd_elf_generic_reloc
, /* special_function */
922 "R_AARCH64_GOT_LD_PREL19", /* name */
923 FALSE
, /* partial_inplace */
924 0xffffe0, /* src_mask */
925 0xffffe0, /* dst_mask */
926 TRUE
), /* pcrel_offset */
930 /* Get to the page for the GOT entry for the symbol
931 (G(S) - P) using an ADRP instruction. */
932 HOWTO (R_AARCH64_ADR_GOT_PAGE
, /* type */
934 2, /* size (0 = byte, 1 = short, 2 = long) */
936 TRUE
, /* pc_relative */
938 complain_overflow_dont
, /* complain_on_overflow */
939 bfd_elf_generic_reloc
, /* special_function */
940 "R_AARCH64_ADR_GOT_PAGE", /* name */
941 FALSE
, /* partial_inplace */
942 0x1fffff, /* src_mask */
943 0x1fffff, /* dst_mask */
944 TRUE
), /* pcrel_offset */
946 /* LD64: GOT offset G(S) & 0xff8 */
947 HOWTO (R_AARCH64_LD64_GOT_LO12_NC
, /* type */
949 2, /* size (0 = byte, 1 = short, 2 = long) */
951 FALSE
, /* pc_relative */
953 complain_overflow_dont
, /* complain_on_overflow */
954 bfd_elf_generic_reloc
, /* special_function */
955 "R_AARCH64_LD64_GOT_LO12_NC", /* name */
956 FALSE
, /* partial_inplace */
957 0xff8, /* src_mask */
958 0xff8, /* dst_mask */
959 FALSE
) /* pcrel_offset */
962 static reloc_howto_type elf64_aarch64_tls_howto_table
[] =
966 /* Get to the page for the GOT entry for the symbol
967 (G(S) - P) using an ADRP instruction. */
968 HOWTO (R_AARCH64_TLSGD_ADR_PAGE21
, /* type */
970 2, /* size (0 = byte, 1 = short, 2 = long) */
972 TRUE
, /* pc_relative */
974 complain_overflow_dont
, /* complain_on_overflow */
975 bfd_elf_generic_reloc
, /* special_function */
976 "R_AARCH64_TLSGD_ADR_PAGE21", /* name */
977 FALSE
, /* partial_inplace */
978 0x1fffff, /* src_mask */
979 0x1fffff, /* dst_mask */
980 TRUE
), /* pcrel_offset */
982 /* ADD: GOT offset G(S) & 0xff8 [no overflow check] */
983 HOWTO (R_AARCH64_TLSGD_ADD_LO12_NC
, /* type */
985 2, /* size (0 = byte, 1 = short, 2 = long) */
987 FALSE
, /* pc_relative */
989 complain_overflow_dont
, /* complain_on_overflow */
990 bfd_elf_generic_reloc
, /* special_function */
991 "R_AARCH64_TLSGD_ADD_LO12_NC", /* name */
992 FALSE
, /* partial_inplace */
993 0xfff, /* src_mask */
994 0xfff, /* dst_mask */
995 FALSE
), /* pcrel_offset */
1022 HOWTO (R_AARCH64_TLSIE_MOVW_GOTTPREL_G1
, /* type */
1023 16, /* rightshift */
1024 2, /* size (0 = byte, 1 = short, 2 = long) */
1026 FALSE
, /* pc_relative */
1028 complain_overflow_dont
, /* complain_on_overflow */
1029 bfd_elf_generic_reloc
, /* special_function */
1030 "R_AARCH64_TLSIE_MOVW_GOTTPREL_G1", /* name */
1031 FALSE
, /* partial_inplace */
1032 0xffff, /* src_mask */
1033 0xffff, /* dst_mask */
1034 FALSE
), /* pcrel_offset */
1036 HOWTO (R_AARCH64_TLSIE_MOVW_GOTTPREL_G0_NC
, /* type */
1038 2, /* size (0 = byte, 1 = short, 2 = long) */
1040 FALSE
, /* pc_relative */
1042 complain_overflow_dont
, /* complain_on_overflow */
1043 bfd_elf_generic_reloc
, /* special_function */
1044 "R_AARCH64_TLSIE_MOVW_GOTTPREL_G0_NC", /* name */
1045 FALSE
, /* partial_inplace */
1046 0xffff, /* src_mask */
1047 0xffff, /* dst_mask */
1048 FALSE
), /* pcrel_offset */
1050 HOWTO (R_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21
, /* type */
1051 12, /* rightshift */
1052 2, /* size (0 = byte, 1 = short, 2 = long) */
1054 FALSE
, /* pc_relative */
1056 complain_overflow_dont
, /* complain_on_overflow */
1057 bfd_elf_generic_reloc
, /* special_function */
1058 "R_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21", /* name */
1059 FALSE
, /* partial_inplace */
1060 0x1fffff, /* src_mask */
1061 0x1fffff, /* dst_mask */
1062 FALSE
), /* pcrel_offset */
1064 HOWTO (R_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC
, /* type */
1066 2, /* size (0 = byte, 1 = short, 2 = long) */
1068 FALSE
, /* pc_relative */
1070 complain_overflow_dont
, /* complain_on_overflow */
1071 bfd_elf_generic_reloc
, /* special_function */
1072 "R_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC", /* name */
1073 FALSE
, /* partial_inplace */
1074 0xff8, /* src_mask */
1075 0xff8, /* dst_mask */
1076 FALSE
), /* pcrel_offset */
1078 HOWTO (R_AARCH64_TLSIE_LD_GOTTPREL_PREL19
, /* type */
1080 2, /* size (0 = byte, 1 = short, 2 = long) */
1082 FALSE
, /* pc_relative */
1084 complain_overflow_dont
, /* complain_on_overflow */
1085 bfd_elf_generic_reloc
, /* special_function */
1086 "R_AARCH64_TLSIE_LD_GOTTPREL_PREL19", /* name */
1087 FALSE
, /* partial_inplace */
1088 0x1ffffc, /* src_mask */
1089 0x1ffffc, /* dst_mask */
1090 FALSE
), /* pcrel_offset */
1092 HOWTO (R_AARCH64_TLSLE_MOVW_TPREL_G2
, /* type */
1093 32, /* rightshift */
1094 2, /* size (0 = byte, 1 = short, 2 = long) */
1096 FALSE
, /* pc_relative */
1098 complain_overflow_dont
, /* complain_on_overflow */
1099 bfd_elf_generic_reloc
, /* special_function */
1100 "R_AARCH64_TLSLE_MOVW_TPREL_G2", /* name */
1101 FALSE
, /* partial_inplace */
1102 0xffff, /* src_mask */
1103 0xffff, /* dst_mask */
1104 FALSE
), /* pcrel_offset */
1106 HOWTO (R_AARCH64_TLSLE_MOVW_TPREL_G1
, /* type */
1107 16, /* rightshift */
1108 2, /* size (0 = byte, 1 = short, 2 = long) */
1110 FALSE
, /* pc_relative */
1112 complain_overflow_dont
, /* complain_on_overflow */
1113 bfd_elf_generic_reloc
, /* special_function */
1114 "R_AARCH64_TLSLE_MOVW_TPREL_G1", /* name */
1115 FALSE
, /* partial_inplace */
1116 0xffff, /* src_mask */
1117 0xffff, /* dst_mask */
1118 FALSE
), /* pcrel_offset */
1120 HOWTO (R_AARCH64_TLSLE_MOVW_TPREL_G1_NC
, /* type */
1121 16, /* rightshift */
1122 2, /* size (0 = byte, 1 = short, 2 = long) */
1124 FALSE
, /* pc_relative */
1126 complain_overflow_dont
, /* complain_on_overflow */
1127 bfd_elf_generic_reloc
, /* special_function */
1128 "R_AARCH64_TLSLE_MOVW_TPREL_G1_NC", /* name */
1129 FALSE
, /* partial_inplace */
1130 0xffff, /* src_mask */
1131 0xffff, /* dst_mask */
1132 FALSE
), /* pcrel_offset */
1134 HOWTO (R_AARCH64_TLSLE_MOVW_TPREL_G0
, /* type */
1136 2, /* size (0 = byte, 1 = short, 2 = long) */
1138 FALSE
, /* pc_relative */
1140 complain_overflow_dont
, /* complain_on_overflow */
1141 bfd_elf_generic_reloc
, /* special_function */
1142 "R_AARCH64_TLSLE_MOVW_TPREL_G0", /* name */
1143 FALSE
, /* partial_inplace */
1144 0xffff, /* src_mask */
1145 0xffff, /* dst_mask */
1146 FALSE
), /* pcrel_offset */
1148 HOWTO (R_AARCH64_TLSLE_MOVW_TPREL_G0_NC
, /* type */
1150 2, /* size (0 = byte, 1 = short, 2 = long) */
1152 FALSE
, /* pc_relative */
1154 complain_overflow_dont
, /* complain_on_overflow */
1155 bfd_elf_generic_reloc
, /* special_function */
1156 "R_AARCH64_TLSLE_MOVW_TPREL_G0_NC", /* name */
1157 FALSE
, /* partial_inplace */
1158 0xffff, /* src_mask */
1159 0xffff, /* dst_mask */
1160 FALSE
), /* pcrel_offset */
1162 HOWTO (R_AARCH64_TLSLE_ADD_TPREL_HI12
, /* type */
1163 12, /* rightshift */
1164 2, /* size (0 = byte, 1 = short, 2 = long) */
1166 FALSE
, /* pc_relative */
1168 complain_overflow_dont
, /* complain_on_overflow */
1169 bfd_elf_generic_reloc
, /* special_function */
1170 "R_AARCH64_TLSLE_ADD_TPREL_HI12", /* name */
1171 FALSE
, /* partial_inplace */
1172 0xfff, /* src_mask */
1173 0xfff, /* dst_mask */
1174 FALSE
), /* pcrel_offset */
1176 HOWTO (R_AARCH64_TLSLE_ADD_TPREL_LO12
, /* type */
1178 2, /* size (0 = byte, 1 = short, 2 = long) */
1180 FALSE
, /* pc_relative */
1182 complain_overflow_dont
, /* complain_on_overflow */
1183 bfd_elf_generic_reloc
, /* special_function */
1184 "R_AARCH64_TLSLE_ADD_TPREL_LO12", /* name */
1185 FALSE
, /* partial_inplace */
1186 0xfff, /* src_mask */
1187 0xfff, /* dst_mask */
1188 FALSE
), /* pcrel_offset */
1190 HOWTO (R_AARCH64_TLSLE_ADD_TPREL_LO12_NC
, /* type */
1192 2, /* size (0 = byte, 1 = short, 2 = long) */
1194 FALSE
, /* pc_relative */
1196 complain_overflow_dont
, /* complain_on_overflow */
1197 bfd_elf_generic_reloc
, /* special_function */
1198 "R_AARCH64_TLSLE_ADD_TPREL_LO12_NC", /* name */
1199 FALSE
, /* partial_inplace */
1200 0xfff, /* src_mask */
1201 0xfff, /* dst_mask */
1202 FALSE
), /* pcrel_offset */
1205 static reloc_howto_type elf64_aarch64_tlsdesc_howto_table
[] =
1207 HOWTO (R_AARCH64_TLSDESC_LD64_PREL19
, /* type */
1209 2, /* size (0 = byte, 1 = short, 2 = long) */
1211 TRUE
, /* pc_relative */
1213 complain_overflow_dont
, /* complain_on_overflow */
1214 bfd_elf_generic_reloc
, /* special_function */
1215 "R_AARCH64_TLSDESC_LD64_PREL19", /* name */
1216 FALSE
, /* partial_inplace */
1217 0x1ffffc, /* src_mask */
1218 0x1ffffc, /* dst_mask */
1219 TRUE
), /* pcrel_offset */
1221 HOWTO (R_AARCH64_TLSDESC_ADR_PREL21
, /* type */
1223 2, /* size (0 = byte, 1 = short, 2 = long) */
1225 TRUE
, /* pc_relative */
1227 complain_overflow_dont
, /* complain_on_overflow */
1228 bfd_elf_generic_reloc
, /* special_function */
1229 "R_AARCH64_TLSDESC_ADR_PREL21", /* name */
1230 FALSE
, /* partial_inplace */
1231 0x1fffff, /* src_mask */
1232 0x1fffff, /* dst_mask */
1233 TRUE
), /* pcrel_offset */
1235 /* Get to the page for the GOT entry for the symbol
1236 (G(S) - P) using an ADRP instruction. */
1237 HOWTO (R_AARCH64_TLSDESC_ADR_PAGE
, /* type */
1238 12, /* rightshift */
1239 2, /* size (0 = byte, 1 = short, 2 = long) */
1241 TRUE
, /* pc_relative */
1243 complain_overflow_dont
, /* complain_on_overflow */
1244 bfd_elf_generic_reloc
, /* special_function */
1245 "R_AARCH64_TLSDESC_ADR_PAGE", /* name */
1246 FALSE
, /* partial_inplace */
1247 0x1fffff, /* src_mask */
1248 0x1fffff, /* dst_mask */
1249 TRUE
), /* pcrel_offset */
1251 /* LD64: GOT offset G(S) & 0xfff. */
1252 HOWTO (R_AARCH64_TLSDESC_LD64_LO12_NC
, /* type */
1254 2, /* size (0 = byte, 1 = short, 2 = long) */
1256 FALSE
, /* pc_relative */
1258 complain_overflow_dont
, /* complain_on_overflow */
1259 bfd_elf_generic_reloc
, /* special_function */
1260 "R_AARCH64_TLSDESC_LD64_LO12_NC", /* name */
1261 FALSE
, /* partial_inplace */
1262 0xfff, /* src_mask */
1263 0xfff, /* dst_mask */
1264 FALSE
), /* pcrel_offset */
1266 /* ADD: GOT offset G(S) & 0xfff. */
1267 HOWTO (R_AARCH64_TLSDESC_ADD_LO12_NC
, /* type */
1269 2, /* size (0 = byte, 1 = short, 2 = long) */
1271 FALSE
, /* pc_relative */
1273 complain_overflow_dont
, /* complain_on_overflow */
1274 bfd_elf_generic_reloc
, /* special_function */
1275 "R_AARCH64_TLSDESC_ADD_LO12_NC", /* name */
1276 FALSE
, /* partial_inplace */
1277 0xfff, /* src_mask */
1278 0xfff, /* dst_mask */
1279 FALSE
), /* pcrel_offset */
1281 HOWTO (R_AARCH64_TLSDESC_OFF_G1
, /* type */
1282 16, /* rightshift */
1283 2, /* size (0 = byte, 1 = short, 2 = long) */
1285 FALSE
, /* pc_relative */
1287 complain_overflow_dont
, /* complain_on_overflow */
1288 bfd_elf_generic_reloc
, /* special_function */
1289 "R_AARCH64_TLSDESC_OFF_G1", /* name */
1290 FALSE
, /* partial_inplace */
1291 0xffff, /* src_mask */
1292 0xffff, /* dst_mask */
1293 FALSE
), /* pcrel_offset */
1295 HOWTO (R_AARCH64_TLSDESC_OFF_G0_NC
, /* type */
1297 2, /* size (0 = byte, 1 = short, 2 = long) */
1299 FALSE
, /* pc_relative */
1301 complain_overflow_dont
, /* complain_on_overflow */
1302 bfd_elf_generic_reloc
, /* special_function */
1303 "R_AARCH64_TLSDESC_OFF_G0_NC", /* name */
1304 FALSE
, /* partial_inplace */
1305 0xffff, /* src_mask */
1306 0xffff, /* dst_mask */
1307 FALSE
), /* pcrel_offset */
1309 HOWTO (R_AARCH64_TLSDESC_LDR
, /* type */
1311 2, /* size (0 = byte, 1 = short, 2 = long) */
1313 FALSE
, /* pc_relative */
1315 complain_overflow_dont
, /* complain_on_overflow */
1316 bfd_elf_generic_reloc
, /* special_function */
1317 "R_AARCH64_TLSDESC_LDR", /* name */
1318 FALSE
, /* partial_inplace */
1321 FALSE
), /* pcrel_offset */
1323 HOWTO (R_AARCH64_TLSDESC_ADD
, /* type */
1325 2, /* size (0 = byte, 1 = short, 2 = long) */
1327 FALSE
, /* pc_relative */
1329 complain_overflow_dont
, /* complain_on_overflow */
1330 bfd_elf_generic_reloc
, /* special_function */
1331 "R_AARCH64_TLSDESC_ADD", /* name */
1332 FALSE
, /* partial_inplace */
1335 FALSE
), /* pcrel_offset */
1337 HOWTO (R_AARCH64_TLSDESC_CALL
, /* type */
1339 2, /* size (0 = byte, 1 = short, 2 = long) */
1341 FALSE
, /* pc_relative */
1343 complain_overflow_dont
, /* complain_on_overflow */
1344 bfd_elf_generic_reloc
, /* special_function */
1345 "R_AARCH64_TLSDESC_CALL", /* name */
1346 FALSE
, /* partial_inplace */
1349 FALSE
), /* pcrel_offset */
1352 static reloc_howto_type
*
1353 elf64_aarch64_howto_from_type (unsigned int r_type
)
1355 if (r_type
>= R_AARCH64_static_min
&& r_type
< R_AARCH64_static_max
)
1356 return &elf64_aarch64_howto_table
[r_type
- R_AARCH64_static_min
];
1358 if (r_type
>= R_AARCH64_tls_min
&& r_type
< R_AARCH64_tls_max
)
1359 return &elf64_aarch64_tls_howto_table
[r_type
- R_AARCH64_tls_min
];
1361 if (r_type
>= R_AARCH64_tlsdesc_min
&& r_type
< R_AARCH64_tlsdesc_max
)
1362 return &elf64_aarch64_tlsdesc_howto_table
[r_type
- R_AARCH64_tlsdesc_min
];
1364 if (r_type
>= R_AARCH64_dyn_min
&& r_type
< R_AARCH64_dyn_max
)
1365 return &elf64_aarch64_howto_dynrelocs
[r_type
- R_AARCH64_dyn_min
];
1369 case R_AARCH64_NONE
:
1370 return &elf64_aarch64_howto_none
;
1373 bfd_set_error (bfd_error_bad_value
);
1378 elf64_aarch64_info_to_howto (bfd
*abfd ATTRIBUTE_UNUSED
, arelent
*bfd_reloc
,
1379 Elf_Internal_Rela
*elf_reloc
)
1381 unsigned int r_type
;
1383 r_type
= ELF64_R_TYPE (elf_reloc
->r_info
);
1384 bfd_reloc
->howto
= elf64_aarch64_howto_from_type (r_type
);
1387 struct elf64_aarch64_reloc_map
1389 bfd_reloc_code_real_type bfd_reloc_val
;
1390 unsigned int elf_reloc_val
;
1393 /* All entries in this list must also be present in
1394 elf64_aarch64_howto_table. */
1395 static const struct elf64_aarch64_reloc_map elf64_aarch64_reloc_map
[] =
1397 {BFD_RELOC_NONE
, R_AARCH64_NONE
},
1399 /* Basic data relocations. */
1400 {BFD_RELOC_CTOR
, R_AARCH64_ABS64
},
1401 {BFD_RELOC_64
, R_AARCH64_ABS64
},
1402 {BFD_RELOC_32
, R_AARCH64_ABS32
},
1403 {BFD_RELOC_16
, R_AARCH64_ABS16
},
1404 {BFD_RELOC_64_PCREL
, R_AARCH64_PREL64
},
1405 {BFD_RELOC_32_PCREL
, R_AARCH64_PREL32
},
1406 {BFD_RELOC_16_PCREL
, R_AARCH64_PREL16
},
1408 /* Group relocations to low order bits of a 16, 32, 48 or 64 bit
1410 {BFD_RELOC_AARCH64_MOVW_G0_NC
, R_AARCH64_MOVW_UABS_G0_NC
},
1411 {BFD_RELOC_AARCH64_MOVW_G1_NC
, R_AARCH64_MOVW_UABS_G1_NC
},
1412 {BFD_RELOC_AARCH64_MOVW_G2_NC
, R_AARCH64_MOVW_UABS_G2_NC
},
1414 /* Group relocations to create high bits of a 16, 32, 48 or 64 bit
1415 signed value inline. */
1416 {BFD_RELOC_AARCH64_MOVW_G0_S
, R_AARCH64_MOVW_SABS_G0
},
1417 {BFD_RELOC_AARCH64_MOVW_G1_S
, R_AARCH64_MOVW_SABS_G1
},
1418 {BFD_RELOC_AARCH64_MOVW_G2_S
, R_AARCH64_MOVW_SABS_G2
},
1420 /* Group relocations to create high bits of a 16, 32, 48 or 64 bit
1421 unsigned value inline. */
1422 {BFD_RELOC_AARCH64_MOVW_G0
, R_AARCH64_MOVW_UABS_G0
},
1423 {BFD_RELOC_AARCH64_MOVW_G1
, R_AARCH64_MOVW_UABS_G1
},
1424 {BFD_RELOC_AARCH64_MOVW_G2
, R_AARCH64_MOVW_UABS_G2
},
1425 {BFD_RELOC_AARCH64_MOVW_G3
, R_AARCH64_MOVW_UABS_G3
},
1427 /* Relocations to generate 19, 21 and 33 bit PC-relative load/store. */
1428 {BFD_RELOC_AARCH64_LD_LO19_PCREL
, R_AARCH64_LD_PREL_LO19
},
1429 {BFD_RELOC_AARCH64_ADR_LO21_PCREL
, R_AARCH64_ADR_PREL_LO21
},
1430 {BFD_RELOC_AARCH64_ADR_HI21_PCREL
, R_AARCH64_ADR_PREL_PG_HI21
},
1431 {BFD_RELOC_AARCH64_ADR_HI21_NC_PCREL
, R_AARCH64_ADR_PREL_PG_HI21_NC
},
1432 {BFD_RELOC_AARCH64_ADD_LO12
, R_AARCH64_ADD_ABS_LO12_NC
},
1433 {BFD_RELOC_AARCH64_LDST8_LO12
, R_AARCH64_LDST8_ABS_LO12_NC
},
1434 {BFD_RELOC_AARCH64_LDST16_LO12
, R_AARCH64_LDST16_ABS_LO12_NC
},
1435 {BFD_RELOC_AARCH64_LDST32_LO12
, R_AARCH64_LDST32_ABS_LO12_NC
},
1436 {BFD_RELOC_AARCH64_LDST64_LO12
, R_AARCH64_LDST64_ABS_LO12_NC
},
1437 {BFD_RELOC_AARCH64_LDST128_LO12
, R_AARCH64_LDST128_ABS_LO12_NC
},
1439 /* Relocations for control-flow instructions. */
1440 {BFD_RELOC_AARCH64_TSTBR14
, R_AARCH64_TSTBR14
},
1441 {BFD_RELOC_AARCH64_BRANCH19
, R_AARCH64_CONDBR19
},
1442 {BFD_RELOC_AARCH64_JUMP26
, R_AARCH64_JUMP26
},
1443 {BFD_RELOC_AARCH64_CALL26
, R_AARCH64_CALL26
},
1445 /* Relocations for PIC. */
1446 {BFD_RELOC_AARCH64_GOT_LD_PREL19
, R_AARCH64_GOT_LD_PREL19
},
1447 {BFD_RELOC_AARCH64_ADR_GOT_PAGE
, R_AARCH64_ADR_GOT_PAGE
},
1448 {BFD_RELOC_AARCH64_LD64_GOT_LO12_NC
, R_AARCH64_LD64_GOT_LO12_NC
},
1450 /* Relocations for TLS. */
1451 {BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21
, R_AARCH64_TLSGD_ADR_PAGE21
},
1452 {BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC
, R_AARCH64_TLSGD_ADD_LO12_NC
},
1453 {BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G1
,
1454 R_AARCH64_TLSIE_MOVW_GOTTPREL_G1
},
1455 {BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G0_NC
,
1456 R_AARCH64_TLSIE_MOVW_GOTTPREL_G0_NC
},
1457 {BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21
,
1458 R_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21
},
1459 {BFD_RELOC_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC
,
1460 R_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC
},
1461 {BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19
,
1462 R_AARCH64_TLSIE_LD_GOTTPREL_PREL19
},
1463 {BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G2
, R_AARCH64_TLSLE_MOVW_TPREL_G2
},
1464 {BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1
, R_AARCH64_TLSLE_MOVW_TPREL_G1
},
1465 {BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1_NC
,
1466 R_AARCH64_TLSLE_MOVW_TPREL_G1_NC
},
1467 {BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0
, R_AARCH64_TLSLE_MOVW_TPREL_G0
},
1468 {BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC
,
1469 R_AARCH64_TLSLE_MOVW_TPREL_G0_NC
},
1470 {BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_LO12
, R_AARCH64_TLSLE_ADD_TPREL_LO12
},
1471 {BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_HI12
, R_AARCH64_TLSLE_ADD_TPREL_HI12
},
1472 {BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_LO12_NC
,
1473 R_AARCH64_TLSLE_ADD_TPREL_LO12_NC
},
1474 {BFD_RELOC_AARCH64_TLSDESC_LD64_PREL19
, R_AARCH64_TLSDESC_LD64_PREL19
},
1475 {BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21
, R_AARCH64_TLSDESC_ADR_PREL21
},
1476 {BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE
, R_AARCH64_TLSDESC_ADR_PAGE
},
1477 {BFD_RELOC_AARCH64_TLSDESC_ADD_LO12_NC
, R_AARCH64_TLSDESC_ADD_LO12_NC
},
1478 {BFD_RELOC_AARCH64_TLSDESC_LD64_LO12_NC
, R_AARCH64_TLSDESC_LD64_LO12_NC
},
1479 {BFD_RELOC_AARCH64_TLSDESC_OFF_G1
, R_AARCH64_TLSDESC_OFF_G1
},
1480 {BFD_RELOC_AARCH64_TLSDESC_OFF_G0_NC
, R_AARCH64_TLSDESC_OFF_G0_NC
},
1481 {BFD_RELOC_AARCH64_TLSDESC_LDR
, R_AARCH64_TLSDESC_LDR
},
1482 {BFD_RELOC_AARCH64_TLSDESC_ADD
, R_AARCH64_TLSDESC_ADD
},
1483 {BFD_RELOC_AARCH64_TLSDESC_CALL
, R_AARCH64_TLSDESC_CALL
},
1484 {BFD_RELOC_AARCH64_TLS_DTPMOD64
, R_AARCH64_TLS_DTPMOD64
},
1485 {BFD_RELOC_AARCH64_TLS_DTPREL64
, R_AARCH64_TLS_DTPREL64
},
1486 {BFD_RELOC_AARCH64_TLS_TPREL64
, R_AARCH64_TLS_TPREL64
},
1487 {BFD_RELOC_AARCH64_TLSDESC
, R_AARCH64_TLSDESC
},
1490 static reloc_howto_type
*
1491 elf64_aarch64_reloc_type_lookup (bfd
*abfd ATTRIBUTE_UNUSED
,
1492 bfd_reloc_code_real_type code
)
1496 for (i
= 0; i
< ARRAY_SIZE (elf64_aarch64_reloc_map
); i
++)
1497 if (elf64_aarch64_reloc_map
[i
].bfd_reloc_val
== code
)
1498 return elf64_aarch64_howto_from_type
1499 (elf64_aarch64_reloc_map
[i
].elf_reloc_val
);
1501 bfd_set_error (bfd_error_bad_value
);
1505 static reloc_howto_type
*
1506 elf64_aarch64_reloc_name_lookup (bfd
*abfd ATTRIBUTE_UNUSED
,
1511 for (i
= 0; i
< ARRAY_SIZE (elf64_aarch64_howto_table
); i
++)
1512 if (elf64_aarch64_howto_table
[i
].name
!= NULL
1513 && strcasecmp (elf64_aarch64_howto_table
[i
].name
, r_name
) == 0)
1514 return &elf64_aarch64_howto_table
[i
];
1519 #define TARGET_LITTLE_SYM bfd_elf64_littleaarch64_vec
1520 #define TARGET_LITTLE_NAME "elf64-littleaarch64"
1521 #define TARGET_BIG_SYM bfd_elf64_bigaarch64_vec
1522 #define TARGET_BIG_NAME "elf64-bigaarch64"
1524 typedef unsigned long int insn32
;
1526 /* The linker script knows the section names for placement.
1527 The entry_names are used to do simple name mangling on the stubs.
1528 Given a function name, and its type, the stub can be found. The
1529 name can be changed. The only requirement is the %s be present. */
1530 #define STUB_ENTRY_NAME "__%s_veneer"
1532 /* The name of the dynamic interpreter. This is put in the .interp
1534 #define ELF_DYNAMIC_INTERPRETER "/lib/ld.so.1"
1536 #define AARCH64_MAX_FWD_BRANCH_OFFSET \
1537 (((1 << 25) - 1) << 2)
1538 #define AARCH64_MAX_BWD_BRANCH_OFFSET \
1541 #define AARCH64_MAX_ADRP_IMM ((1 << 20) - 1)
1542 #define AARCH64_MIN_ADRP_IMM (-(1 << 20))
1545 aarch64_valid_for_adrp_p (bfd_vma value
, bfd_vma place
)
1547 bfd_signed_vma offset
= (bfd_signed_vma
) (PG (value
) - PG (place
)) >> 12;
1548 return offset
<= AARCH64_MAX_ADRP_IMM
&& offset
>= AARCH64_MIN_ADRP_IMM
;
1552 aarch64_valid_branch_p (bfd_vma value
, bfd_vma place
)
1554 bfd_signed_vma offset
= (bfd_signed_vma
) (value
- place
);
1555 return (offset
<= AARCH64_MAX_FWD_BRANCH_OFFSET
1556 && offset
>= AARCH64_MAX_BWD_BRANCH_OFFSET
);
1559 static const uint32_t aarch64_adrp_branch_stub
[] =
1561 0x90000010, /* adrp ip0, X */
1562 /* R_AARCH64_ADR_HI21_PCREL(X) */
1563 0x91000210, /* add ip0, ip0, :lo12:X */
1564 /* R_AARCH64_ADD_ABS_LO12_NC(X) */
1565 0xd61f0200, /* br ip0 */
1568 static const uint32_t aarch64_long_branch_stub
[] =
1570 0x58000090, /* ldr ip0, 1f */
1571 0x10000011, /* adr ip1, #0 */
1572 0x8b110210, /* add ip0, ip0, ip1 */
1573 0xd61f0200, /* br ip0 */
1574 0x00000000, /* 1: .xword
1575 R_AARCH64_PREL64(X) + 12
1580 /* Section name for stubs is the associated section name plus this
1582 #define STUB_SUFFIX ".stub"
1584 enum elf64_aarch64_stub_type
1587 aarch64_stub_adrp_branch
,
1588 aarch64_stub_long_branch
,
1591 struct elf64_aarch64_stub_hash_entry
1593 /* Base hash table entry structure. */
1594 struct bfd_hash_entry root
;
1596 /* The stub section. */
1599 /* Offset within stub_sec of the beginning of this stub. */
1600 bfd_vma stub_offset
;
1602 /* Given the symbol's value and its section we can determine its final
1603 value when building the stubs (so the stub knows where to jump). */
1604 bfd_vma target_value
;
1605 asection
*target_section
;
1607 enum elf64_aarch64_stub_type stub_type
;
1609 /* The symbol table entry, if any, that this was derived from. */
1610 struct elf64_aarch64_link_hash_entry
*h
;
1612 /* Destination symbol type */
1613 unsigned char st_type
;
1615 /* Where this stub is being called from, or, in the case of combined
1616 stub sections, the first input section in the group. */
1619 /* The name for the local symbol at the start of this stub. The
1620 stub name in the hash table has to be unique; this does not, so
1621 it can be friendlier. */
1625 /* Used to build a map of a section. This is required for mixed-endian
1628 typedef struct elf64_elf_section_map
1633 elf64_aarch64_section_map
;
1636 typedef struct _aarch64_elf_section_data
1638 struct bfd_elf_section_data elf
;
1639 unsigned int mapcount
;
1640 unsigned int mapsize
;
1641 elf64_aarch64_section_map
*map
;
1643 _aarch64_elf_section_data
;
1645 #define elf64_aarch64_section_data(sec) \
1646 ((_aarch64_elf_section_data *) elf_section_data (sec))
1648 /* The size of the thread control block. */
1651 struct elf_aarch64_local_symbol
1653 unsigned int got_type
;
1654 bfd_signed_vma got_refcount
;
1657 /* Offset of the GOTPLT entry reserved for the TLS descriptor. The
1658 offset is from the end of the jump table and reserved entries
1661 The magic value (bfd_vma) -1 indicates that an offset has not be
1663 bfd_vma tlsdesc_got_jump_table_offset
;
1666 struct elf_aarch64_obj_tdata
1668 struct elf_obj_tdata root
;
1670 /* local symbol descriptors */
1671 struct elf_aarch64_local_symbol
*locals
;
1673 /* Zero to warn when linking objects with incompatible enum sizes. */
1674 int no_enum_size_warning
;
1676 /* Zero to warn when linking objects with incompatible wchar_t sizes. */
1677 int no_wchar_size_warning
;
1680 #define elf_aarch64_tdata(bfd) \
1681 ((struct elf_aarch64_obj_tdata *) (bfd)->tdata.any)
1683 #define elf64_aarch64_locals(bfd) (elf_aarch64_tdata (bfd)->locals)
1685 #define is_aarch64_elf(bfd) \
1686 (bfd_get_flavour (bfd) == bfd_target_elf_flavour \
1687 && elf_tdata (bfd) != NULL \
1688 && elf_object_id (bfd) == AARCH64_ELF_DATA)
1691 elf64_aarch64_mkobject (bfd
*abfd
)
1693 return bfd_elf_allocate_object (abfd
, sizeof (struct elf_aarch64_obj_tdata
),
1697 /* The AArch64 linker needs to keep track of the number of relocs that it
1698 decides to copy in check_relocs for each symbol. This is so that
1699 it can discard PC relative relocs if it doesn't need them when
1700 linking with -Bsymbolic. We store the information in a field
1701 extending the regular ELF linker hash table. */
1703 /* This structure keeps track of the number of relocs we have copied
1704 for a given symbol. */
1705 struct elf64_aarch64_relocs_copied
1708 struct elf64_aarch64_relocs_copied
*next
;
1709 /* A section in dynobj. */
1711 /* Number of relocs copied in this section. */
1712 bfd_size_type count
;
1713 /* Number of PC-relative relocs copied in this section. */
1714 bfd_size_type pc_count
;
1717 #define elf64_aarch64_hash_entry(ent) \
1718 ((struct elf64_aarch64_link_hash_entry *)(ent))
1720 #define GOT_UNKNOWN 0
1721 #define GOT_NORMAL 1
1722 #define GOT_TLS_GD 2
1723 #define GOT_TLS_IE 4
1724 #define GOT_TLSDESC_GD 8
1726 #define GOT_TLS_GD_ANY_P(type) ((type & GOT_TLS_GD) || (type & GOT_TLSDESC_GD))
1728 /* AArch64 ELF linker hash entry. */
1729 struct elf64_aarch64_link_hash_entry
1731 struct elf_link_hash_entry root
;
1733 /* Track dynamic relocs copied for this symbol. */
1734 struct elf_dyn_relocs
*dyn_relocs
;
1736 /* Number of PC relative relocs copied for this symbol. */
1737 struct elf64_aarch64_relocs_copied
*relocs_copied
;
1739 /* Since PLT entries have variable size, we need to record the
1740 index into .got.plt instead of recomputing it from the PLT
1742 bfd_signed_vma plt_got_offset
;
1744 /* Bit mask representing the type of GOT entry(s) if any required by
1746 unsigned int got_type
;
1748 /* A pointer to the most recently used stub hash entry against this
1750 struct elf64_aarch64_stub_hash_entry
*stub_cache
;
1752 /* Offset of the GOTPLT entry reserved for the TLS descriptor. The offset
1753 is from the end of the jump table and reserved entries within the PLTGOT.
1755 The magic value (bfd_vma) -1 indicates that an offset has not
1757 bfd_vma tlsdesc_got_jump_table_offset
;
1761 elf64_aarch64_symbol_got_type (struct elf_link_hash_entry
*h
,
1763 unsigned long r_symndx
)
1766 return elf64_aarch64_hash_entry (h
)->got_type
;
1768 if (! elf64_aarch64_locals (abfd
))
1771 return elf64_aarch64_locals (abfd
)[r_symndx
].got_type
;
1774 /* Traverse an AArch64 ELF linker hash table. */
1775 #define elf64_aarch64_link_hash_traverse(table, func, info) \
1776 (elf_link_hash_traverse \
1778 (bfd_boolean (*) (struct elf_link_hash_entry *, void *)) (func), \
1781 /* Get the AArch64 elf linker hash table from a link_info structure. */
1782 #define elf64_aarch64_hash_table(info) \
1783 ((struct elf64_aarch64_link_hash_table *) ((info)->hash))
1785 #define aarch64_stub_hash_lookup(table, string, create, copy) \
1786 ((struct elf64_aarch64_stub_hash_entry *) \
1787 bfd_hash_lookup ((table), (string), (create), (copy)))
1789 /* AArch64 ELF linker hash table. */
1790 struct elf64_aarch64_link_hash_table
1792 /* The main hash table. */
1793 struct elf_link_hash_table root
;
1795 /* Nonzero to force PIC branch veneers. */
1798 /* The number of bytes in the initial entry in the PLT. */
1799 bfd_size_type plt_header_size
;
1801 /* The number of bytes in the subsequent PLT etries. */
1802 bfd_size_type plt_entry_size
;
1804 /* Short-cuts to get to dynamic linker sections. */
1808 /* Small local sym cache. */
1809 struct sym_cache sym_cache
;
1811 /* For convenience in allocate_dynrelocs. */
1814 /* The amount of space used by the reserved portion of the sgotplt
1815 section, plus whatever space is used by the jump slots. */
1816 bfd_vma sgotplt_jump_table_size
;
1818 /* The stub hash table. */
1819 struct bfd_hash_table stub_hash_table
;
1821 /* Linker stub bfd. */
1824 /* Linker call-backs. */
1825 asection
*(*add_stub_section
) (const char *, asection
*);
1826 void (*layout_sections_again
) (void);
1828 /* Array to keep track of which stub sections have been created, and
1829 information on stub grouping. */
1832 /* This is the section to which stubs in the group will be
1835 /* The stub section. */
1839 /* Assorted information used by elf64_aarch64_size_stubs. */
1840 unsigned int bfd_count
;
1842 asection
**input_list
;
1844 /* The offset into splt of the PLT entry for the TLS descriptor
1845 resolver. Special values are 0, if not necessary (or not found
1846 to be necessary yet), and -1 if needed but not determined
1848 bfd_vma tlsdesc_plt
;
1850 /* The GOT offset for the lazy trampoline. Communicated to the
1851 loader via DT_TLSDESC_GOT. The magic value (bfd_vma) -1
1852 indicates an offset is not allocated. */
1853 bfd_vma dt_tlsdesc_got
;
1857 /* Return non-zero if the indicated VALUE has overflowed the maximum
1858 range expressible by a unsigned number with the indicated number of
1861 static bfd_reloc_status_type
1862 aarch64_unsigned_overflow (bfd_vma value
, unsigned int bits
)
1865 if (bits
>= sizeof (bfd_vma
) * 8)
1866 return bfd_reloc_ok
;
1867 lim
= (bfd_vma
) 1 << bits
;
1869 return bfd_reloc_overflow
;
1870 return bfd_reloc_ok
;
1874 /* Return non-zero if the indicated VALUE has overflowed the maximum
1875 range expressible by an signed number with the indicated number of
1878 static bfd_reloc_status_type
1879 aarch64_signed_overflow (bfd_vma value
, unsigned int bits
)
1881 bfd_signed_vma svalue
= (bfd_signed_vma
) value
;
1884 if (bits
>= sizeof (bfd_vma
) * 8)
1885 return bfd_reloc_ok
;
1886 lim
= (bfd_signed_vma
) 1 << (bits
- 1);
1887 if (svalue
< -lim
|| svalue
>= lim
)
1888 return bfd_reloc_overflow
;
1889 return bfd_reloc_ok
;
1892 /* Create an entry in an AArch64 ELF linker hash table. */
1894 static struct bfd_hash_entry
*
1895 elf64_aarch64_link_hash_newfunc (struct bfd_hash_entry
*entry
,
1896 struct bfd_hash_table
*table
,
1899 struct elf64_aarch64_link_hash_entry
*ret
=
1900 (struct elf64_aarch64_link_hash_entry
*) entry
;
1902 /* Allocate the structure if it has not already been allocated by a
1905 ret
= bfd_hash_allocate (table
,
1906 sizeof (struct elf64_aarch64_link_hash_entry
));
1908 return (struct bfd_hash_entry
*) ret
;
1910 /* Call the allocation method of the superclass. */
1911 ret
= ((struct elf64_aarch64_link_hash_entry
*)
1912 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry
*) ret
,
1916 ret
->dyn_relocs
= NULL
;
1917 ret
->relocs_copied
= NULL
;
1918 ret
->got_type
= GOT_UNKNOWN
;
1919 ret
->plt_got_offset
= (bfd_vma
) - 1;
1920 ret
->stub_cache
= NULL
;
1921 ret
->tlsdesc_got_jump_table_offset
= (bfd_vma
) - 1;
1924 return (struct bfd_hash_entry
*) ret
;
1927 /* Initialize an entry in the stub hash table. */
1929 static struct bfd_hash_entry
*
1930 stub_hash_newfunc (struct bfd_hash_entry
*entry
,
1931 struct bfd_hash_table
*table
, const char *string
)
1933 /* Allocate the structure if it has not already been allocated by a
1937 entry
= bfd_hash_allocate (table
,
1939 elf64_aarch64_stub_hash_entry
));
1944 /* Call the allocation method of the superclass. */
1945 entry
= bfd_hash_newfunc (entry
, table
, string
);
1948 struct elf64_aarch64_stub_hash_entry
*eh
;
1950 /* Initialize the local fields. */
1951 eh
= (struct elf64_aarch64_stub_hash_entry
*) entry
;
1952 eh
->stub_sec
= NULL
;
1953 eh
->stub_offset
= 0;
1954 eh
->target_value
= 0;
1955 eh
->target_section
= NULL
;
1956 eh
->stub_type
= aarch64_stub_none
;
1965 /* Copy the extra info we tack onto an elf_link_hash_entry. */
1968 elf64_aarch64_copy_indirect_symbol (struct bfd_link_info
*info
,
1969 struct elf_link_hash_entry
*dir
,
1970 struct elf_link_hash_entry
*ind
)
1972 struct elf64_aarch64_link_hash_entry
*edir
, *eind
;
1974 edir
= (struct elf64_aarch64_link_hash_entry
*) dir
;
1975 eind
= (struct elf64_aarch64_link_hash_entry
*) ind
;
1977 if (eind
->dyn_relocs
!= NULL
)
1979 if (edir
->dyn_relocs
!= NULL
)
1981 struct elf_dyn_relocs
**pp
;
1982 struct elf_dyn_relocs
*p
;
1984 /* Add reloc counts against the indirect sym to the direct sym
1985 list. Merge any entries against the same section. */
1986 for (pp
= &eind
->dyn_relocs
; (p
= *pp
) != NULL
;)
1988 struct elf_dyn_relocs
*q
;
1990 for (q
= edir
->dyn_relocs
; q
!= NULL
; q
= q
->next
)
1991 if (q
->sec
== p
->sec
)
1993 q
->pc_count
+= p
->pc_count
;
1994 q
->count
+= p
->count
;
2001 *pp
= edir
->dyn_relocs
;
2004 edir
->dyn_relocs
= eind
->dyn_relocs
;
2005 eind
->dyn_relocs
= NULL
;
2008 if (eind
->relocs_copied
!= NULL
)
2010 if (edir
->relocs_copied
!= NULL
)
2012 struct elf64_aarch64_relocs_copied
**pp
;
2013 struct elf64_aarch64_relocs_copied
*p
;
2015 /* Add reloc counts against the indirect sym to the direct sym
2016 list. Merge any entries against the same section. */
2017 for (pp
= &eind
->relocs_copied
; (p
= *pp
) != NULL
;)
2019 struct elf64_aarch64_relocs_copied
*q
;
2021 for (q
= edir
->relocs_copied
; q
!= NULL
; q
= q
->next
)
2022 if (q
->section
== p
->section
)
2024 q
->pc_count
+= p
->pc_count
;
2025 q
->count
+= p
->count
;
2032 *pp
= edir
->relocs_copied
;
2035 edir
->relocs_copied
= eind
->relocs_copied
;
2036 eind
->relocs_copied
= NULL
;
2039 if (ind
->root
.type
== bfd_link_hash_indirect
)
2041 /* Copy over PLT info. */
2042 if (dir
->got
.refcount
<= 0)
2044 edir
->got_type
= eind
->got_type
;
2045 eind
->got_type
= GOT_UNKNOWN
;
2049 _bfd_elf_link_hash_copy_indirect (info
, dir
, ind
);
2052 /* Create an AArch64 elf linker hash table. */
2054 static struct bfd_link_hash_table
*
2055 elf64_aarch64_link_hash_table_create (bfd
*abfd
)
2057 struct elf64_aarch64_link_hash_table
*ret
;
2058 bfd_size_type amt
= sizeof (struct elf64_aarch64_link_hash_table
);
2060 ret
= bfd_malloc (amt
);
2064 if (!_bfd_elf_link_hash_table_init
2065 (&ret
->root
, abfd
, elf64_aarch64_link_hash_newfunc
,
2066 sizeof (struct elf64_aarch64_link_hash_entry
), AARCH64_ELF_DATA
))
2072 ret
->sdynbss
= NULL
;
2073 ret
->srelbss
= NULL
;
2075 ret
->plt_header_size
= PLT_ENTRY_SIZE
;
2076 ret
->plt_entry_size
= PLT_SMALL_ENTRY_SIZE
;
2078 ret
->sym_cache
.abfd
= NULL
;
2081 ret
->stub_bfd
= NULL
;
2082 ret
->add_stub_section
= NULL
;
2083 ret
->layout_sections_again
= NULL
;
2084 ret
->stub_group
= NULL
;
2087 ret
->input_list
= NULL
;
2088 ret
->tlsdesc_plt
= 0;
2089 ret
->dt_tlsdesc_got
= (bfd_vma
) - 1;
2091 if (!bfd_hash_table_init (&ret
->stub_hash_table
, stub_hash_newfunc
,
2092 sizeof (struct elf64_aarch64_stub_hash_entry
)))
2098 return &ret
->root
.root
;
2101 /* Free the derived linker hash table. */
2104 elf64_aarch64_hash_table_free (struct bfd_link_hash_table
*hash
)
2106 struct elf64_aarch64_link_hash_table
*ret
2107 = (struct elf64_aarch64_link_hash_table
*) hash
;
2109 bfd_hash_table_free (&ret
->stub_hash_table
);
2110 _bfd_generic_link_hash_table_free (hash
);
2114 aarch64_resolve_relocation (unsigned int r_type
, bfd_vma place
, bfd_vma value
,
2115 bfd_vma addend
, bfd_boolean weak_undef_p
)
2119 case R_AARCH64_TLSDESC_CALL
:
2120 case R_AARCH64_NONE
:
2121 case R_AARCH64_NULL
:
2124 case R_AARCH64_ADR_PREL_LO21
:
2125 case R_AARCH64_CONDBR19
:
2126 case R_AARCH64_LD_PREL_LO19
:
2127 case R_AARCH64_PREL16
:
2128 case R_AARCH64_PREL32
:
2129 case R_AARCH64_PREL64
:
2130 case R_AARCH64_TSTBR14
:
2133 value
= value
+ addend
- place
;
2136 case R_AARCH64_CALL26
:
2137 case R_AARCH64_JUMP26
:
2138 value
= value
+ addend
- place
;
2141 case R_AARCH64_ABS16
:
2142 case R_AARCH64_ABS32
:
2143 case R_AARCH64_MOVW_SABS_G0
:
2144 case R_AARCH64_MOVW_SABS_G1
:
2145 case R_AARCH64_MOVW_SABS_G2
:
2146 case R_AARCH64_MOVW_UABS_G0
:
2147 case R_AARCH64_MOVW_UABS_G0_NC
:
2148 case R_AARCH64_MOVW_UABS_G1
:
2149 case R_AARCH64_MOVW_UABS_G1_NC
:
2150 case R_AARCH64_MOVW_UABS_G2
:
2151 case R_AARCH64_MOVW_UABS_G2_NC
:
2152 case R_AARCH64_MOVW_UABS_G3
:
2153 value
= value
+ addend
;
2156 case R_AARCH64_ADR_PREL_PG_HI21
:
2157 case R_AARCH64_ADR_PREL_PG_HI21_NC
:
2160 value
= PG (value
+ addend
) - PG (place
);
2163 case R_AARCH64_GOT_LD_PREL19
:
2164 value
= value
+ addend
- place
;
2167 case R_AARCH64_ADR_GOT_PAGE
:
2168 case R_AARCH64_TLSDESC_ADR_PAGE
:
2169 case R_AARCH64_TLSGD_ADR_PAGE21
:
2170 case R_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21
:
2171 value
= PG (value
+ addend
) - PG (place
);
2174 case R_AARCH64_ADD_ABS_LO12_NC
:
2175 case R_AARCH64_LD64_GOT_LO12_NC
:
2176 case R_AARCH64_LDST8_ABS_LO12_NC
:
2177 case R_AARCH64_LDST16_ABS_LO12_NC
:
2178 case R_AARCH64_LDST32_ABS_LO12_NC
:
2179 case R_AARCH64_LDST64_ABS_LO12_NC
:
2180 case R_AARCH64_LDST128_ABS_LO12_NC
:
2181 case R_AARCH64_TLSDESC_ADD_LO12_NC
:
2182 case R_AARCH64_TLSDESC_ADD
:
2183 case R_AARCH64_TLSDESC_LD64_LO12_NC
:
2184 case R_AARCH64_TLSDESC_LDR
:
2185 case R_AARCH64_TLSGD_ADD_LO12_NC
:
2186 case R_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC
:
2187 case R_AARCH64_TLSLE_ADD_TPREL_LO12
:
2188 case R_AARCH64_TLSLE_ADD_TPREL_LO12_NC
:
2189 value
= PG_OFFSET (value
+ addend
);
2192 case R_AARCH64_TLSLE_MOVW_TPREL_G1
:
2193 case R_AARCH64_TLSLE_MOVW_TPREL_G1_NC
:
2194 value
= (value
+ addend
) & (bfd_vma
) 0xffff0000;
2196 case R_AARCH64_TLSLE_ADD_TPREL_HI12
:
2197 value
= (value
+ addend
) & (bfd_vma
) 0xfff000;
2200 case R_AARCH64_TLSLE_MOVW_TPREL_G0
:
2201 case R_AARCH64_TLSLE_MOVW_TPREL_G0_NC
:
2202 value
= (value
+ addend
) & (bfd_vma
) 0xffff;
2205 case R_AARCH64_TLSLE_MOVW_TPREL_G2
:
2206 value
= (value
+ addend
) & ~(bfd_vma
) 0xffffffff;
2207 value
-= place
& ~(bfd_vma
) 0xffffffff;
2214 aarch64_relocate (unsigned int r_type
, bfd
*input_bfd
, asection
*input_section
,
2215 bfd_vma offset
, bfd_vma value
)
2217 reloc_howto_type
*howto
;
2220 howto
= elf64_aarch64_howto_from_type (r_type
);
2221 place
= (input_section
->output_section
->vma
+ input_section
->output_offset
2223 value
= aarch64_resolve_relocation (r_type
, place
, value
, 0, FALSE
);
2224 return bfd_elf_aarch64_put_addend (input_bfd
,
2225 input_section
->contents
+ offset
,
2229 static enum elf64_aarch64_stub_type
2230 aarch64_select_branch_stub (bfd_vma value
, bfd_vma place
)
2232 if (aarch64_valid_for_adrp_p (value
, place
))
2233 return aarch64_stub_adrp_branch
;
2234 return aarch64_stub_long_branch
;
2237 /* Determine the type of stub needed, if any, for a call. */
2239 static enum elf64_aarch64_stub_type
2240 aarch64_type_of_stub (struct bfd_link_info
*info
,
2241 asection
*input_sec
,
2242 const Elf_Internal_Rela
*rel
,
2243 unsigned char st_type
,
2244 struct elf64_aarch64_link_hash_entry
*hash
,
2245 bfd_vma destination
)
2248 bfd_signed_vma branch_offset
;
2249 unsigned int r_type
;
2250 struct elf64_aarch64_link_hash_table
*globals
;
2251 enum elf64_aarch64_stub_type stub_type
= aarch64_stub_none
;
2252 bfd_boolean via_plt_p
;
2254 if (st_type
!= STT_FUNC
)
2257 globals
= elf64_aarch64_hash_table (info
);
2258 via_plt_p
= (globals
->root
.splt
!= NULL
&& hash
!= NULL
2259 && hash
->root
.plt
.offset
!= (bfd_vma
) - 1);
2264 /* Determine where the call point is. */
2265 location
= (input_sec
->output_offset
2266 + input_sec
->output_section
->vma
+ rel
->r_offset
);
2268 branch_offset
= (bfd_signed_vma
) (destination
- location
);
2270 r_type
= ELF64_R_TYPE (rel
->r_info
);
2272 /* We don't want to redirect any old unconditional jump in this way,
2273 only one which is being used for a sibcall, where it is
2274 acceptable for the IP0 and IP1 registers to be clobbered. */
2275 if ((r_type
== R_AARCH64_CALL26
|| r_type
== R_AARCH64_JUMP26
)
2276 && (branch_offset
> AARCH64_MAX_FWD_BRANCH_OFFSET
2277 || branch_offset
< AARCH64_MAX_BWD_BRANCH_OFFSET
))
2279 stub_type
= aarch64_stub_long_branch
;
2285 /* Build a name for an entry in the stub hash table. */
2288 elf64_aarch64_stub_name (const asection
*input_section
,
2289 const asection
*sym_sec
,
2290 const struct elf64_aarch64_link_hash_entry
*hash
,
2291 const Elf_Internal_Rela
*rel
)
2298 len
= 8 + 1 + strlen (hash
->root
.root
.root
.string
) + 1 + 16 + 1;
2299 stub_name
= bfd_malloc (len
);
2300 if (stub_name
!= NULL
)
2301 snprintf (stub_name
, len
, "%08x_%s+%" BFD_VMA_FMT
"x",
2302 (unsigned int) input_section
->id
,
2303 hash
->root
.root
.root
.string
,
2308 len
= 8 + 1 + 8 + 1 + 8 + 1 + 16 + 1;
2309 stub_name
= bfd_malloc (len
);
2310 if (stub_name
!= NULL
)
2311 snprintf (stub_name
, len
, "%08x_%x:%x+%" BFD_VMA_FMT
"x",
2312 (unsigned int) input_section
->id
,
2313 (unsigned int) sym_sec
->id
,
2314 (unsigned int) ELF64_R_SYM (rel
->r_info
),
2321 /* Look up an entry in the stub hash. Stub entries are cached because
2322 creating the stub name takes a bit of time. */
2324 static struct elf64_aarch64_stub_hash_entry
*
2325 elf64_aarch64_get_stub_entry (const asection
*input_section
,
2326 const asection
*sym_sec
,
2327 struct elf_link_hash_entry
*hash
,
2328 const Elf_Internal_Rela
*rel
,
2329 struct elf64_aarch64_link_hash_table
*htab
)
2331 struct elf64_aarch64_stub_hash_entry
*stub_entry
;
2332 struct elf64_aarch64_link_hash_entry
*h
=
2333 (struct elf64_aarch64_link_hash_entry
*) hash
;
2334 const asection
*id_sec
;
2336 if ((input_section
->flags
& SEC_CODE
) == 0)
2339 /* If this input section is part of a group of sections sharing one
2340 stub section, then use the id of the first section in the group.
2341 Stub names need to include a section id, as there may well be
2342 more than one stub used to reach say, printf, and we need to
2343 distinguish between them. */
2344 id_sec
= htab
->stub_group
[input_section
->id
].link_sec
;
2346 if (h
!= NULL
&& h
->stub_cache
!= NULL
2347 && h
->stub_cache
->h
== h
&& h
->stub_cache
->id_sec
== id_sec
)
2349 stub_entry
= h
->stub_cache
;
2355 stub_name
= elf64_aarch64_stub_name (id_sec
, sym_sec
, h
, rel
);
2356 if (stub_name
== NULL
)
2359 stub_entry
= aarch64_stub_hash_lookup (&htab
->stub_hash_table
,
2360 stub_name
, FALSE
, FALSE
);
2362 h
->stub_cache
= stub_entry
;
2370 /* Add a new stub entry to the stub hash. Not all fields of the new
2371 stub entry are initialised. */
2373 static struct elf64_aarch64_stub_hash_entry
*
2374 elf64_aarch64_add_stub (const char *stub_name
,
2376 struct elf64_aarch64_link_hash_table
*htab
)
2380 struct elf64_aarch64_stub_hash_entry
*stub_entry
;
2382 link_sec
= htab
->stub_group
[section
->id
].link_sec
;
2383 stub_sec
= htab
->stub_group
[section
->id
].stub_sec
;
2384 if (stub_sec
== NULL
)
2386 stub_sec
= htab
->stub_group
[link_sec
->id
].stub_sec
;
2387 if (stub_sec
== NULL
)
2393 namelen
= strlen (link_sec
->name
);
2394 len
= namelen
+ sizeof (STUB_SUFFIX
);
2395 s_name
= bfd_alloc (htab
->stub_bfd
, len
);
2399 memcpy (s_name
, link_sec
->name
, namelen
);
2400 memcpy (s_name
+ namelen
, STUB_SUFFIX
, sizeof (STUB_SUFFIX
));
2401 stub_sec
= (*htab
->add_stub_section
) (s_name
, link_sec
);
2402 if (stub_sec
== NULL
)
2404 htab
->stub_group
[link_sec
->id
].stub_sec
= stub_sec
;
2406 htab
->stub_group
[section
->id
].stub_sec
= stub_sec
;
2409 /* Enter this entry into the linker stub hash table. */
2410 stub_entry
= aarch64_stub_hash_lookup (&htab
->stub_hash_table
, stub_name
,
2412 if (stub_entry
== NULL
)
2414 (*_bfd_error_handler
) (_("%s: cannot create stub entry %s"),
2415 section
->owner
, stub_name
);
2419 stub_entry
->stub_sec
= stub_sec
;
2420 stub_entry
->stub_offset
= 0;
2421 stub_entry
->id_sec
= link_sec
;
2427 aarch64_build_one_stub (struct bfd_hash_entry
*gen_entry
,
2428 void *in_arg ATTRIBUTE_UNUSED
)
2430 struct elf64_aarch64_stub_hash_entry
*stub_entry
;
2435 unsigned int template_size
;
2436 const uint32_t *template;
2439 /* Massage our args to the form they really have. */
2440 stub_entry
= (struct elf64_aarch64_stub_hash_entry
*) gen_entry
;
2442 stub_sec
= stub_entry
->stub_sec
;
2444 /* Make a note of the offset within the stubs for this entry. */
2445 stub_entry
->stub_offset
= stub_sec
->size
;
2446 loc
= stub_sec
->contents
+ stub_entry
->stub_offset
;
2448 stub_bfd
= stub_sec
->owner
;
2450 /* This is the address of the stub destination. */
2451 sym_value
= (stub_entry
->target_value
2452 + stub_entry
->target_section
->output_offset
2453 + stub_entry
->target_section
->output_section
->vma
);
2455 if (stub_entry
->stub_type
== aarch64_stub_long_branch
)
2457 bfd_vma place
= (stub_entry
->stub_offset
+ stub_sec
->output_section
->vma
2458 + stub_sec
->output_offset
);
2460 /* See if we can relax the stub. */
2461 if (aarch64_valid_for_adrp_p (sym_value
, place
))
2462 stub_entry
->stub_type
= aarch64_select_branch_stub (sym_value
, place
);
2465 switch (stub_entry
->stub_type
)
2467 case aarch64_stub_adrp_branch
:
2468 template = aarch64_adrp_branch_stub
;
2469 template_size
= sizeof (aarch64_adrp_branch_stub
);
2471 case aarch64_stub_long_branch
:
2472 template = aarch64_long_branch_stub
;
2473 template_size
= sizeof (aarch64_long_branch_stub
);
2480 for (i
= 0; i
< (template_size
/ sizeof template[0]); i
++)
2482 bfd_putl32 (template[i
], loc
);
2486 template_size
= (template_size
+ 7) & ~7;
2487 stub_sec
->size
+= template_size
;
2489 switch (stub_entry
->stub_type
)
2491 case aarch64_stub_adrp_branch
:
2492 if (aarch64_relocate (R_AARCH64_ADR_PREL_PG_HI21
, stub_bfd
, stub_sec
,
2493 stub_entry
->stub_offset
, sym_value
))
2494 /* The stub would not have been relaxed if the offset was out
2498 _bfd_final_link_relocate
2499 (elf64_aarch64_howto_from_type (R_AARCH64_ADD_ABS_LO12_NC
),
2503 stub_entry
->stub_offset
+ 4,
2508 case aarch64_stub_long_branch
:
2509 /* We want the value relative to the address 12 bytes back from the
2511 _bfd_final_link_relocate (elf64_aarch64_howto_from_type
2512 (R_AARCH64_PREL64
), stub_bfd
, stub_sec
,
2514 stub_entry
->stub_offset
+ 16,
2524 /* As above, but don't actually build the stub. Just bump offset so
2525 we know stub section sizes. */
2528 aarch64_size_one_stub (struct bfd_hash_entry
*gen_entry
,
2529 void *in_arg ATTRIBUTE_UNUSED
)
2531 struct elf64_aarch64_stub_hash_entry
*stub_entry
;
2534 /* Massage our args to the form they really have. */
2535 stub_entry
= (struct elf64_aarch64_stub_hash_entry
*) gen_entry
;
2537 switch (stub_entry
->stub_type
)
2539 case aarch64_stub_adrp_branch
:
2540 size
= sizeof (aarch64_adrp_branch_stub
);
2542 case aarch64_stub_long_branch
:
2543 size
= sizeof (aarch64_long_branch_stub
);
2551 size
= (size
+ 7) & ~7;
2552 stub_entry
->stub_sec
->size
+= size
;
2556 /* External entry points for sizing and building linker stubs. */
2558 /* Set up various things so that we can make a list of input sections
2559 for each output section included in the link. Returns -1 on error,
2560 0 when no stubs will be needed, and 1 on success. */
2563 elf64_aarch64_setup_section_lists (bfd
*output_bfd
,
2564 struct bfd_link_info
*info
)
2567 unsigned int bfd_count
;
2568 int top_id
, top_index
;
2570 asection
**input_list
, **list
;
2572 struct elf64_aarch64_link_hash_table
*htab
=
2573 elf64_aarch64_hash_table (info
);
2575 if (!is_elf_hash_table (htab
))
2578 /* Count the number of input BFDs and find the top input section id. */
2579 for (input_bfd
= info
->input_bfds
, bfd_count
= 0, top_id
= 0;
2580 input_bfd
!= NULL
; input_bfd
= input_bfd
->link_next
)
2583 for (section
= input_bfd
->sections
;
2584 section
!= NULL
; section
= section
->next
)
2586 if (top_id
< section
->id
)
2587 top_id
= section
->id
;
2590 htab
->bfd_count
= bfd_count
;
2592 amt
= sizeof (struct map_stub
) * (top_id
+ 1);
2593 htab
->stub_group
= bfd_zmalloc (amt
);
2594 if (htab
->stub_group
== NULL
)
2597 /* We can't use output_bfd->section_count here to find the top output
2598 section index as some sections may have been removed, and
2599 _bfd_strip_section_from_output doesn't renumber the indices. */
2600 for (section
= output_bfd
->sections
, top_index
= 0;
2601 section
!= NULL
; section
= section
->next
)
2603 if (top_index
< section
->index
)
2604 top_index
= section
->index
;
2607 htab
->top_index
= top_index
;
2608 amt
= sizeof (asection
*) * (top_index
+ 1);
2609 input_list
= bfd_malloc (amt
);
2610 htab
->input_list
= input_list
;
2611 if (input_list
== NULL
)
2614 /* For sections we aren't interested in, mark their entries with a
2615 value we can check later. */
2616 list
= input_list
+ top_index
;
2618 *list
= bfd_abs_section_ptr
;
2619 while (list
-- != input_list
);
2621 for (section
= output_bfd
->sections
;
2622 section
!= NULL
; section
= section
->next
)
2624 if ((section
->flags
& SEC_CODE
) != 0)
2625 input_list
[section
->index
] = NULL
;
2631 /* Used by elf64_aarch64_next_input_section and group_sections. */
2632 #define PREV_SEC(sec) (htab->stub_group[(sec)->id].link_sec)
2634 /* The linker repeatedly calls this function for each input section,
2635 in the order that input sections are linked into output sections.
2636 Build lists of input sections to determine groupings between which
2637 we may insert linker stubs. */
2640 elf64_aarch64_next_input_section (struct bfd_link_info
*info
, asection
*isec
)
2642 struct elf64_aarch64_link_hash_table
*htab
=
2643 elf64_aarch64_hash_table (info
);
2645 if (isec
->output_section
->index
<= htab
->top_index
)
2647 asection
**list
= htab
->input_list
+ isec
->output_section
->index
;
2649 if (*list
!= bfd_abs_section_ptr
)
2651 /* Steal the link_sec pointer for our list. */
2652 /* This happens to make the list in reverse order,
2653 which is what we want. */
2654 PREV_SEC (isec
) = *list
;
2660 /* See whether we can group stub sections together. Grouping stub
2661 sections may result in fewer stubs. More importantly, we need to
2662 put all .init* and .fini* stubs at the beginning of the .init or
2663 .fini output sections respectively, because glibc splits the
2664 _init and _fini functions into multiple parts. Putting a stub in
2665 the middle of a function is not a good idea. */
2668 group_sections (struct elf64_aarch64_link_hash_table
*htab
,
2669 bfd_size_type stub_group_size
,
2670 bfd_boolean stubs_always_before_branch
)
2672 asection
**list
= htab
->input_list
+ htab
->top_index
;
2676 asection
*tail
= *list
;
2678 if (tail
== bfd_abs_section_ptr
)
2681 while (tail
!= NULL
)
2685 bfd_size_type total
;
2689 while ((prev
= PREV_SEC (curr
)) != NULL
2690 && ((total
+= curr
->output_offset
- prev
->output_offset
)
2694 /* OK, the size from the start of CURR to the end is less
2695 than stub_group_size and thus can be handled by one stub
2696 section. (Or the tail section is itself larger than
2697 stub_group_size, in which case we may be toast.)
2698 We should really be keeping track of the total size of
2699 stubs added here, as stubs contribute to the final output
2703 prev
= PREV_SEC (tail
);
2704 /* Set up this stub group. */
2705 htab
->stub_group
[tail
->id
].link_sec
= curr
;
2707 while (tail
!= curr
&& (tail
= prev
) != NULL
);
2709 /* But wait, there's more! Input sections up to stub_group_size
2710 bytes before the stub section can be handled by it too. */
2711 if (!stubs_always_before_branch
)
2715 && ((total
+= tail
->output_offset
- prev
->output_offset
)
2719 prev
= PREV_SEC (tail
);
2720 htab
->stub_group
[tail
->id
].link_sec
= curr
;
2726 while (list
-- != htab
->input_list
);
2728 free (htab
->input_list
);
2733 /* Determine and set the size of the stub section for a final link.
2735 The basic idea here is to examine all the relocations looking for
2736 PC-relative calls to a target that is unreachable with a "bl"
2740 elf64_aarch64_size_stubs (bfd
*output_bfd
,
2742 struct bfd_link_info
*info
,
2743 bfd_signed_vma group_size
,
2744 asection
* (*add_stub_section
) (const char *,
2746 void (*layout_sections_again
) (void))
2748 bfd_size_type stub_group_size
;
2749 bfd_boolean stubs_always_before_branch
;
2750 bfd_boolean stub_changed
= 0;
2751 struct elf64_aarch64_link_hash_table
*htab
= elf64_aarch64_hash_table (info
);
2753 /* Propagate mach to stub bfd, because it may not have been
2754 finalized when we created stub_bfd. */
2755 bfd_set_arch_mach (stub_bfd
, bfd_get_arch (output_bfd
),
2756 bfd_get_mach (output_bfd
));
2758 /* Stash our params away. */
2759 htab
->stub_bfd
= stub_bfd
;
2760 htab
->add_stub_section
= add_stub_section
;
2761 htab
->layout_sections_again
= layout_sections_again
;
2762 stubs_always_before_branch
= group_size
< 0;
2764 stub_group_size
= -group_size
;
2766 stub_group_size
= group_size
;
2768 if (stub_group_size
== 1)
2770 /* Default values. */
2771 /* Aarch64 branch range is +-128MB. The value used is 1MB less. */
2772 stub_group_size
= 127 * 1024 * 1024;
2775 group_sections (htab
, stub_group_size
, stubs_always_before_branch
);
2780 unsigned int bfd_indx
;
2783 for (input_bfd
= info
->input_bfds
, bfd_indx
= 0;
2784 input_bfd
!= NULL
; input_bfd
= input_bfd
->link_next
, bfd_indx
++)
2786 Elf_Internal_Shdr
*symtab_hdr
;
2788 Elf_Internal_Sym
*local_syms
= NULL
;
2790 /* We'll need the symbol table in a second. */
2791 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
2792 if (symtab_hdr
->sh_info
== 0)
2795 /* Walk over each section attached to the input bfd. */
2796 for (section
= input_bfd
->sections
;
2797 section
!= NULL
; section
= section
->next
)
2799 Elf_Internal_Rela
*internal_relocs
, *irelaend
, *irela
;
2801 /* If there aren't any relocs, then there's nothing more
2803 if ((section
->flags
& SEC_RELOC
) == 0
2804 || section
->reloc_count
== 0
2805 || (section
->flags
& SEC_CODE
) == 0)
2808 /* If this section is a link-once section that will be
2809 discarded, then don't create any stubs. */
2810 if (section
->output_section
== NULL
2811 || section
->output_section
->owner
!= output_bfd
)
2814 /* Get the relocs. */
2816 = _bfd_elf_link_read_relocs (input_bfd
, section
, NULL
,
2817 NULL
, info
->keep_memory
);
2818 if (internal_relocs
== NULL
)
2819 goto error_ret_free_local
;
2821 /* Now examine each relocation. */
2822 irela
= internal_relocs
;
2823 irelaend
= irela
+ section
->reloc_count
;
2824 for (; irela
< irelaend
; irela
++)
2826 unsigned int r_type
, r_indx
;
2827 enum elf64_aarch64_stub_type stub_type
;
2828 struct elf64_aarch64_stub_hash_entry
*stub_entry
;
2831 bfd_vma destination
;
2832 struct elf64_aarch64_link_hash_entry
*hash
;
2833 const char *sym_name
;
2835 const asection
*id_sec
;
2836 unsigned char st_type
;
2839 r_type
= ELF64_R_TYPE (irela
->r_info
);
2840 r_indx
= ELF64_R_SYM (irela
->r_info
);
2842 if (r_type
>= (unsigned int) R_AARCH64_end
)
2844 bfd_set_error (bfd_error_bad_value
);
2845 error_ret_free_internal
:
2846 if (elf_section_data (section
)->relocs
== NULL
)
2847 free (internal_relocs
);
2848 goto error_ret_free_local
;
2851 /* Only look for stubs on unconditional branch and
2852 branch and link instructions. */
2853 if (r_type
!= (unsigned int) R_AARCH64_CALL26
2854 && r_type
!= (unsigned int) R_AARCH64_JUMP26
)
2857 /* Now determine the call target, its name, value,
2864 if (r_indx
< symtab_hdr
->sh_info
)
2866 /* It's a local symbol. */
2867 Elf_Internal_Sym
*sym
;
2868 Elf_Internal_Shdr
*hdr
;
2870 if (local_syms
== NULL
)
2873 = (Elf_Internal_Sym
*) symtab_hdr
->contents
;
2874 if (local_syms
== NULL
)
2876 = bfd_elf_get_elf_syms (input_bfd
, symtab_hdr
,
2877 symtab_hdr
->sh_info
, 0,
2879 if (local_syms
== NULL
)
2880 goto error_ret_free_internal
;
2883 sym
= local_syms
+ r_indx
;
2884 hdr
= elf_elfsections (input_bfd
)[sym
->st_shndx
];
2885 sym_sec
= hdr
->bfd_section
;
2887 /* This is an undefined symbol. It can never
2891 if (ELF_ST_TYPE (sym
->st_info
) != STT_SECTION
)
2892 sym_value
= sym
->st_value
;
2893 destination
= (sym_value
+ irela
->r_addend
2894 + sym_sec
->output_offset
2895 + sym_sec
->output_section
->vma
);
2896 st_type
= ELF_ST_TYPE (sym
->st_info
);
2898 = bfd_elf_string_from_elf_section (input_bfd
,
2899 symtab_hdr
->sh_link
,
2906 e_indx
= r_indx
- symtab_hdr
->sh_info
;
2907 hash
= ((struct elf64_aarch64_link_hash_entry
*)
2908 elf_sym_hashes (input_bfd
)[e_indx
]);
2910 while (hash
->root
.root
.type
== bfd_link_hash_indirect
2911 || hash
->root
.root
.type
== bfd_link_hash_warning
)
2912 hash
= ((struct elf64_aarch64_link_hash_entry
*)
2913 hash
->root
.root
.u
.i
.link
);
2915 if (hash
->root
.root
.type
== bfd_link_hash_defined
2916 || hash
->root
.root
.type
== bfd_link_hash_defweak
)
2918 struct elf64_aarch64_link_hash_table
*globals
=
2919 elf64_aarch64_hash_table (info
);
2920 sym_sec
= hash
->root
.root
.u
.def
.section
;
2921 sym_value
= hash
->root
.root
.u
.def
.value
;
2922 /* For a destination in a shared library,
2923 use the PLT stub as target address to
2924 decide whether a branch stub is
2926 if (globals
->root
.splt
!= NULL
&& hash
!= NULL
2927 && hash
->root
.plt
.offset
!= (bfd_vma
) - 1)
2929 sym_sec
= globals
->root
.splt
;
2930 sym_value
= hash
->root
.plt
.offset
;
2931 if (sym_sec
->output_section
!= NULL
)
2932 destination
= (sym_value
2933 + sym_sec
->output_offset
2935 sym_sec
->output_section
->vma
);
2937 else if (sym_sec
->output_section
!= NULL
)
2938 destination
= (sym_value
+ irela
->r_addend
2939 + sym_sec
->output_offset
2940 + sym_sec
->output_section
->vma
);
2942 else if (hash
->root
.root
.type
== bfd_link_hash_undefined
2943 || (hash
->root
.root
.type
2944 == bfd_link_hash_undefweak
))
2946 /* For a shared library, use the PLT stub as
2947 target address to decide whether a long
2948 branch stub is needed.
2949 For absolute code, they cannot be handled. */
2950 struct elf64_aarch64_link_hash_table
*globals
=
2951 elf64_aarch64_hash_table (info
);
2953 if (globals
->root
.splt
!= NULL
&& hash
!= NULL
2954 && hash
->root
.plt
.offset
!= (bfd_vma
) - 1)
2956 sym_sec
= globals
->root
.splt
;
2957 sym_value
= hash
->root
.plt
.offset
;
2958 if (sym_sec
->output_section
!= NULL
)
2959 destination
= (sym_value
2960 + sym_sec
->output_offset
2962 sym_sec
->output_section
->vma
);
2969 bfd_set_error (bfd_error_bad_value
);
2970 goto error_ret_free_internal
;
2972 st_type
= ELF_ST_TYPE (hash
->root
.type
);
2973 sym_name
= hash
->root
.root
.root
.string
;
2976 /* Determine what (if any) linker stub is needed. */
2977 stub_type
= aarch64_type_of_stub
2978 (info
, section
, irela
, st_type
, hash
, destination
);
2979 if (stub_type
== aarch64_stub_none
)
2982 /* Support for grouping stub sections. */
2983 id_sec
= htab
->stub_group
[section
->id
].link_sec
;
2985 /* Get the name of this stub. */
2986 stub_name
= elf64_aarch64_stub_name (id_sec
, sym_sec
, hash
,
2989 goto error_ret_free_internal
;
2992 aarch64_stub_hash_lookup (&htab
->stub_hash_table
,
2993 stub_name
, FALSE
, FALSE
);
2994 if (stub_entry
!= NULL
)
2996 /* The proper stub has already been created. */
3001 stub_entry
= elf64_aarch64_add_stub (stub_name
, section
,
3003 if (stub_entry
== NULL
)
3006 goto error_ret_free_internal
;
3009 stub_entry
->target_value
= sym_value
;
3010 stub_entry
->target_section
= sym_sec
;
3011 stub_entry
->stub_type
= stub_type
;
3012 stub_entry
->h
= hash
;
3013 stub_entry
->st_type
= st_type
;
3015 if (sym_name
== NULL
)
3016 sym_name
= "unnamed";
3017 len
= sizeof (STUB_ENTRY_NAME
) + strlen (sym_name
);
3018 stub_entry
->output_name
= bfd_alloc (htab
->stub_bfd
, len
);
3019 if (stub_entry
->output_name
== NULL
)
3022 goto error_ret_free_internal
;
3025 snprintf (stub_entry
->output_name
, len
, STUB_ENTRY_NAME
,
3028 stub_changed
= TRUE
;
3031 /* We're done with the internal relocs, free them. */
3032 if (elf_section_data (section
)->relocs
== NULL
)
3033 free (internal_relocs
);
3040 /* OK, we've added some stubs. Find out the new size of the
3042 for (stub_sec
= htab
->stub_bfd
->sections
;
3043 stub_sec
!= NULL
; stub_sec
= stub_sec
->next
)
3046 bfd_hash_traverse (&htab
->stub_hash_table
, aarch64_size_one_stub
, htab
);
3048 /* Ask the linker to do its stuff. */
3049 (*htab
->layout_sections_again
) ();
3050 stub_changed
= FALSE
;
3055 error_ret_free_local
:
3059 /* Build all the stubs associated with the current output file. The
3060 stubs are kept in a hash table attached to the main linker hash
3061 table. We also set up the .plt entries for statically linked PIC
3062 functions here. This function is called via aarch64_elf_finish in the
3066 elf64_aarch64_build_stubs (struct bfd_link_info
*info
)
3069 struct bfd_hash_table
*table
;
3070 struct elf64_aarch64_link_hash_table
*htab
;
3072 htab
= elf64_aarch64_hash_table (info
);
3074 for (stub_sec
= htab
->stub_bfd
->sections
;
3075 stub_sec
!= NULL
; stub_sec
= stub_sec
->next
)
3079 /* Ignore non-stub sections. */
3080 if (!strstr (stub_sec
->name
, STUB_SUFFIX
))
3083 /* Allocate memory to hold the linker stubs. */
3084 size
= stub_sec
->size
;
3085 stub_sec
->contents
= bfd_zalloc (htab
->stub_bfd
, size
);
3086 if (stub_sec
->contents
== NULL
&& size
!= 0)
3091 /* Build the stubs as directed by the stub hash table. */
3092 table
= &htab
->stub_hash_table
;
3093 bfd_hash_traverse (table
, aarch64_build_one_stub
, info
);
3099 /* Add an entry to the code/data map for section SEC. */
3102 elf64_aarch64_section_map_add (asection
*sec
, char type
, bfd_vma vma
)
3104 struct _aarch64_elf_section_data
*sec_data
=
3105 elf64_aarch64_section_data (sec
);
3106 unsigned int newidx
;
3108 if (sec_data
->map
== NULL
)
3110 sec_data
->map
= bfd_malloc (sizeof (elf64_aarch64_section_map
));
3111 sec_data
->mapcount
= 0;
3112 sec_data
->mapsize
= 1;
3115 newidx
= sec_data
->mapcount
++;
3117 if (sec_data
->mapcount
> sec_data
->mapsize
)
3119 sec_data
->mapsize
*= 2;
3120 sec_data
->map
= bfd_realloc_or_free
3121 (sec_data
->map
, sec_data
->mapsize
* sizeof (elf64_aarch64_section_map
));
3126 sec_data
->map
[newidx
].vma
= vma
;
3127 sec_data
->map
[newidx
].type
= type
;
3132 /* Initialise maps of insn/data for input BFDs. */
3134 bfd_elf64_aarch64_init_maps (bfd
*abfd
)
3136 Elf_Internal_Sym
*isymbuf
;
3137 Elf_Internal_Shdr
*hdr
;
3138 unsigned int i
, localsyms
;
3140 /* Make sure that we are dealing with an AArch64 elf binary. */
3141 if (!is_aarch64_elf (abfd
))
3144 if ((abfd
->flags
& DYNAMIC
) != 0)
3147 hdr
= &elf_symtab_hdr (abfd
);
3148 localsyms
= hdr
->sh_info
;
3150 /* Obtain a buffer full of symbols for this BFD. The hdr->sh_info field
3151 should contain the number of local symbols, which should come before any
3152 global symbols. Mapping symbols are always local. */
3153 isymbuf
= bfd_elf_get_elf_syms (abfd
, hdr
, localsyms
, 0, NULL
, NULL
, NULL
);
3155 /* No internal symbols read? Skip this BFD. */
3156 if (isymbuf
== NULL
)
3159 for (i
= 0; i
< localsyms
; i
++)
3161 Elf_Internal_Sym
*isym
= &isymbuf
[i
];
3162 asection
*sec
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
3165 if (sec
!= NULL
&& ELF_ST_BIND (isym
->st_info
) == STB_LOCAL
)
3167 name
= bfd_elf_string_from_elf_section (abfd
,
3171 if (bfd_is_aarch64_special_symbol_name
3172 (name
, BFD_AARCH64_SPECIAL_SYM_TYPE_MAP
))
3173 elf64_aarch64_section_map_add (sec
, name
[1], isym
->st_value
);
3178 /* Set option values needed during linking. */
3180 bfd_elf64_aarch64_set_options (struct bfd
*output_bfd
,
3181 struct bfd_link_info
*link_info
,
3183 int no_wchar_warn
, int pic_veneer
)
3185 struct elf64_aarch64_link_hash_table
*globals
;
3187 globals
= elf64_aarch64_hash_table (link_info
);
3188 globals
->pic_veneer
= pic_veneer
;
3190 BFD_ASSERT (is_aarch64_elf (output_bfd
));
3191 elf_aarch64_tdata (output_bfd
)->no_enum_size_warning
= no_enum_warn
;
3192 elf_aarch64_tdata (output_bfd
)->no_wchar_size_warning
= no_wchar_warn
;
3195 #define MASK(n) ((1u << (n)) - 1)
3197 /* Decode the 26-bit offset of unconditional branch. */
3198 static inline uint32_t
3199 decode_branch_ofs_26 (uint32_t insn
)
3201 return insn
& MASK (26);
3204 /* Decode the 19-bit offset of conditional branch and compare & branch. */
3205 static inline uint32_t
3206 decode_cond_branch_ofs_19 (uint32_t insn
)
3208 return (insn
>> 5) & MASK (19);
3211 /* Decode the 19-bit offset of load literal. */
3212 static inline uint32_t
3213 decode_ld_lit_ofs_19 (uint32_t insn
)
3215 return (insn
>> 5) & MASK (19);
3218 /* Decode the 14-bit offset of test & branch. */
3219 static inline uint32_t
3220 decode_tst_branch_ofs_14 (uint32_t insn
)
3222 return (insn
>> 5) & MASK (14);
3225 /* Decode the 16-bit imm of move wide. */
3226 static inline uint32_t
3227 decode_movw_imm (uint32_t insn
)
3229 return (insn
>> 5) & MASK (16);
3232 /* Decode the 21-bit imm of adr. */
3233 static inline uint32_t
3234 decode_adr_imm (uint32_t insn
)
3236 return ((insn
>> 29) & MASK (2)) | ((insn
>> 3) & (MASK (19) << 2));
3239 /* Decode the 12-bit imm of add immediate. */
3240 static inline uint32_t
3241 decode_add_imm (uint32_t insn
)
3243 return (insn
>> 10) & MASK (12);
3247 /* Encode the 26-bit offset of unconditional branch. */
3248 static inline uint32_t
3249 reencode_branch_ofs_26 (uint32_t insn
, uint32_t ofs
)
3251 return (insn
& ~MASK (26)) | (ofs
& MASK (26));
3254 /* Encode the 19-bit offset of conditional branch and compare & branch. */
3255 static inline uint32_t
3256 reencode_cond_branch_ofs_19 (uint32_t insn
, uint32_t ofs
)
3258 return (insn
& ~(MASK (19) << 5)) | ((ofs
& MASK (19)) << 5);
3261 /* Decode the 19-bit offset of load literal. */
3262 static inline uint32_t
3263 reencode_ld_lit_ofs_19 (uint32_t insn
, uint32_t ofs
)
3265 return (insn
& ~(MASK (19) << 5)) | ((ofs
& MASK (19)) << 5);
3268 /* Encode the 14-bit offset of test & branch. */
3269 static inline uint32_t
3270 reencode_tst_branch_ofs_14 (uint32_t insn
, uint32_t ofs
)
3272 return (insn
& ~(MASK (14) << 5)) | ((ofs
& MASK (14)) << 5);
3275 /* Reencode the imm field of move wide. */
3276 static inline uint32_t
3277 reencode_movw_imm (uint32_t insn
, uint32_t imm
)
3279 return (insn
& ~(MASK (16) << 5)) | ((imm
& MASK (16)) << 5);
3282 /* Reencode the imm field of adr. */
3283 static inline uint32_t
3284 reencode_adr_imm (uint32_t insn
, uint32_t imm
)
3286 return (insn
& ~((MASK (2) << 29) | (MASK (19) << 5)))
3287 | ((imm
& MASK (2)) << 29) | ((imm
& (MASK (19) << 2)) << 3);
3290 /* Reencode the imm field of ld/st pos immediate. */
3291 static inline uint32_t
3292 reencode_ldst_pos_imm (uint32_t insn
, uint32_t imm
)
3294 return (insn
& ~(MASK (12) << 10)) | ((imm
& MASK (12)) << 10);
3297 /* Reencode the imm field of add immediate. */
3298 static inline uint32_t
3299 reencode_add_imm (uint32_t insn
, uint32_t imm
)
3301 return (insn
& ~(MASK (12) << 10)) | ((imm
& MASK (12)) << 10);
3304 /* Reencode mov[zn] to movz. */
3305 static inline uint32_t
3306 reencode_movzn_to_movz (uint32_t opcode
)
3308 return opcode
| (1 << 30);
3311 /* Reencode mov[zn] to movn. */
3312 static inline uint32_t
3313 reencode_movzn_to_movn (uint32_t opcode
)
3315 return opcode
& ~(1 << 30);
3318 /* Insert the addend/value into the instruction or data object being
3320 static bfd_reloc_status_type
3321 bfd_elf_aarch64_put_addend (bfd
*abfd
,
3323 reloc_howto_type
*howto
, bfd_signed_vma addend
)
3325 bfd_reloc_status_type status
= bfd_reloc_ok
;
3326 bfd_signed_vma old_addend
= addend
;
3330 size
= bfd_get_reloc_size (howto
);
3334 contents
= bfd_get_16 (abfd
, address
);
3337 if (howto
->src_mask
!= 0xffffffff)
3338 /* Must be 32-bit instruction, always little-endian. */
3339 contents
= bfd_getl32 (address
);
3341 /* Must be 32-bit data (endianness dependent). */
3342 contents
= bfd_get_32 (abfd
, address
);
3345 contents
= bfd_get_64 (abfd
, address
);
3351 switch (howto
->complain_on_overflow
)
3353 case complain_overflow_dont
:
3355 case complain_overflow_signed
:
3356 status
= aarch64_signed_overflow (addend
,
3357 howto
->bitsize
+ howto
->rightshift
);
3359 case complain_overflow_unsigned
:
3360 status
= aarch64_unsigned_overflow (addend
,
3361 howto
->bitsize
+ howto
->rightshift
);
3363 case complain_overflow_bitfield
:
3368 addend
>>= howto
->rightshift
;
3370 switch (howto
->type
)
3372 case R_AARCH64_JUMP26
:
3373 case R_AARCH64_CALL26
:
3374 contents
= reencode_branch_ofs_26 (contents
, addend
);
3377 case R_AARCH64_CONDBR19
:
3378 contents
= reencode_cond_branch_ofs_19 (contents
, addend
);
3381 case R_AARCH64_TSTBR14
:
3382 contents
= reencode_tst_branch_ofs_14 (contents
, addend
);
3385 case R_AARCH64_LD_PREL_LO19
:
3386 case R_AARCH64_GOT_LD_PREL19
:
3387 if (old_addend
& ((1 << howto
->rightshift
) - 1))
3388 return bfd_reloc_overflow
;
3389 contents
= reencode_ld_lit_ofs_19 (contents
, addend
);
3392 case R_AARCH64_TLSDESC_CALL
:
3395 case R_AARCH64_TLSGD_ADR_PAGE21
:
3396 case R_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21
:
3397 case R_AARCH64_TLSDESC_ADR_PAGE
:
3398 case R_AARCH64_ADR_GOT_PAGE
:
3399 case R_AARCH64_ADR_PREL_LO21
:
3400 case R_AARCH64_ADR_PREL_PG_HI21
:
3401 case R_AARCH64_ADR_PREL_PG_HI21_NC
:
3402 contents
= reencode_adr_imm (contents
, addend
);
3405 case R_AARCH64_TLSGD_ADD_LO12_NC
:
3406 case R_AARCH64_TLSLE_ADD_TPREL_LO12
:
3407 case R_AARCH64_TLSLE_ADD_TPREL_HI12
:
3408 case R_AARCH64_TLSLE_ADD_TPREL_LO12_NC
:
3409 case R_AARCH64_TLSDESC_ADD_LO12_NC
:
3410 case R_AARCH64_ADD_ABS_LO12_NC
:
3411 /* Corresponds to: add rd, rn, #uimm12 to provide the low order
3412 12 bits of the page offset following
3413 R_AARCH64_ADR_PREL_PG_HI21 which computes the
3414 (pc-relative) page base. */
3415 contents
= reencode_add_imm (contents
, addend
);
3418 case R_AARCH64_LDST8_ABS_LO12_NC
:
3419 case R_AARCH64_LDST16_ABS_LO12_NC
:
3420 case R_AARCH64_LDST32_ABS_LO12_NC
:
3421 case R_AARCH64_LDST64_ABS_LO12_NC
:
3422 case R_AARCH64_LDST128_ABS_LO12_NC
:
3423 case R_AARCH64_TLSDESC_LD64_LO12_NC
:
3424 case R_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC
:
3425 case R_AARCH64_LD64_GOT_LO12_NC
:
3426 if (old_addend
& ((1 << howto
->rightshift
) - 1))
3427 return bfd_reloc_overflow
;
3428 /* Used for ldr*|str* rt, [rn, #uimm12] to provide the low order
3429 12 bits of the page offset following R_AARCH64_ADR_PREL_PG_HI21
3430 which computes the (pc-relative) page base. */
3431 contents
= reencode_ldst_pos_imm (contents
, addend
);
3434 /* Group relocations to create high bits of a 16, 32, 48 or 64
3435 bit signed data or abs address inline. Will change
3436 instruction to MOVN or MOVZ depending on sign of calculated
3439 case R_AARCH64_TLSLE_MOVW_TPREL_G2
:
3440 case R_AARCH64_TLSLE_MOVW_TPREL_G1
:
3441 case R_AARCH64_TLSLE_MOVW_TPREL_G1_NC
:
3442 case R_AARCH64_TLSLE_MOVW_TPREL_G0
:
3443 case R_AARCH64_TLSLE_MOVW_TPREL_G0_NC
:
3444 case R_AARCH64_MOVW_SABS_G0
:
3445 case R_AARCH64_MOVW_SABS_G1
:
3446 case R_AARCH64_MOVW_SABS_G2
:
3447 /* NOTE: We can only come here with movz or movn. */
3450 /* Force use of MOVN. */
3452 contents
= reencode_movzn_to_movn (contents
);
3456 /* Force use of MOVZ. */
3457 contents
= reencode_movzn_to_movz (contents
);
3461 /* Group relocations to create a 16, 32, 48 or 64 bit unsigned
3462 data or abs address inline. */
3464 case R_AARCH64_MOVW_UABS_G0
:
3465 case R_AARCH64_MOVW_UABS_G0_NC
:
3466 case R_AARCH64_MOVW_UABS_G1
:
3467 case R_AARCH64_MOVW_UABS_G1_NC
:
3468 case R_AARCH64_MOVW_UABS_G2
:
3469 case R_AARCH64_MOVW_UABS_G2_NC
:
3470 case R_AARCH64_MOVW_UABS_G3
:
3471 contents
= reencode_movw_imm (contents
, addend
);
3475 /* Repack simple data */
3476 if (howto
->dst_mask
& (howto
->dst_mask
+ 1))
3477 return bfd_reloc_notsupported
;
3479 contents
= ((contents
& ~howto
->dst_mask
) | (addend
& howto
->dst_mask
));
3486 bfd_put_16 (abfd
, contents
, address
);
3489 if (howto
->dst_mask
!= 0xffffffff)
3490 /* must be 32-bit instruction, always little-endian */
3491 bfd_putl32 (contents
, address
);
3493 /* must be 32-bit data (endianness dependent) */
3494 bfd_put_32 (abfd
, contents
, address
);
3497 bfd_put_64 (abfd
, contents
, address
);
3507 aarch64_calculate_got_entry_vma (struct elf_link_hash_entry
*h
,
3508 struct elf64_aarch64_link_hash_table
3509 *globals
, struct bfd_link_info
*info
,
3510 bfd_vma value
, bfd
*output_bfd
,
3511 bfd_boolean
*unresolved_reloc_p
)
3513 bfd_vma off
= (bfd_vma
) - 1;
3514 asection
*basegot
= globals
->root
.sgot
;
3515 bfd_boolean dyn
= globals
->root
.dynamic_sections_created
;
3519 off
= h
->got
.offset
;
3520 BFD_ASSERT (off
!= (bfd_vma
) - 1);
3521 if (!WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, info
->shared
, h
)
3523 && SYMBOL_REFERENCES_LOCAL (info
, h
))
3524 || (ELF_ST_VISIBILITY (h
->other
)
3525 && h
->root
.type
== bfd_link_hash_undefweak
))
3527 /* This is actually a static link, or it is a -Bsymbolic link
3528 and the symbol is defined locally. We must initialize this
3529 entry in the global offset table. Since the offset must
3530 always be a multiple of 8, we use the least significant bit
3531 to record whether we have initialized it already.
3532 When doing a dynamic link, we create a .rel(a).got relocation
3533 entry to initialize the value. This is done in the
3534 finish_dynamic_symbol routine. */
3539 bfd_put_64 (output_bfd
, value
, basegot
->contents
+ off
);
3544 *unresolved_reloc_p
= FALSE
;
3546 off
= off
+ basegot
->output_section
->vma
+ basegot
->output_offset
;
3552 /* Change R_TYPE to a more efficient access model where possible,
3553 return the new reloc type. */
3556 aarch64_tls_transition_without_check (unsigned int r_type
,
3557 struct elf_link_hash_entry
*h
)
3559 bfd_boolean is_local
= h
== NULL
;
3562 case R_AARCH64_TLSGD_ADR_PAGE21
:
3563 case R_AARCH64_TLSDESC_ADR_PAGE
:
3565 ? R_AARCH64_TLSLE_MOVW_TPREL_G1
: R_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21
;
3567 case R_AARCH64_TLSGD_ADD_LO12_NC
:
3568 case R_AARCH64_TLSDESC_LD64_LO12_NC
:
3570 ? R_AARCH64_TLSLE_MOVW_TPREL_G0_NC
3571 : R_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC
;
3573 case R_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21
:
3574 return is_local
? R_AARCH64_TLSLE_MOVW_TPREL_G1
: r_type
;
3576 case R_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC
:
3577 return is_local
? R_AARCH64_TLSLE_MOVW_TPREL_G0_NC
: r_type
;
3579 case R_AARCH64_TLSDESC_ADD_LO12_NC
:
3580 case R_AARCH64_TLSDESC_CALL
:
3581 /* Instructions with these relocations will become NOPs. */
3582 return R_AARCH64_NONE
;
3589 aarch64_reloc_got_type (unsigned int r_type
)
3593 case R_AARCH64_LD64_GOT_LO12_NC
:
3594 case R_AARCH64_ADR_GOT_PAGE
:
3595 case R_AARCH64_GOT_LD_PREL19
:
3598 case R_AARCH64_TLSGD_ADR_PAGE21
:
3599 case R_AARCH64_TLSGD_ADD_LO12_NC
:
3602 case R_AARCH64_TLSDESC_ADD_LO12_NC
:
3603 case R_AARCH64_TLSDESC_ADR_PAGE
:
3604 case R_AARCH64_TLSDESC_CALL
:
3605 case R_AARCH64_TLSDESC_LD64_LO12_NC
:
3606 return GOT_TLSDESC_GD
;
3608 case R_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21
:
3609 case R_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC
:
3612 case R_AARCH64_TLSLE_ADD_TPREL_HI12
:
3613 case R_AARCH64_TLSLE_ADD_TPREL_LO12
:
3614 case R_AARCH64_TLSLE_ADD_TPREL_LO12_NC
:
3615 case R_AARCH64_TLSLE_MOVW_TPREL_G0
:
3616 case R_AARCH64_TLSLE_MOVW_TPREL_G0_NC
:
3617 case R_AARCH64_TLSLE_MOVW_TPREL_G1
:
3618 case R_AARCH64_TLSLE_MOVW_TPREL_G1_NC
:
3619 case R_AARCH64_TLSLE_MOVW_TPREL_G2
:
3626 aarch64_can_relax_tls (bfd
*input_bfd
,
3627 struct bfd_link_info
*info
,
3628 unsigned int r_type
,
3629 struct elf_link_hash_entry
*h
,
3630 unsigned long r_symndx
)
3632 unsigned int symbol_got_type
;
3633 unsigned int reloc_got_type
;
3635 if (! IS_AARCH64_TLS_RELOC (r_type
))
3638 symbol_got_type
= elf64_aarch64_symbol_got_type (h
, input_bfd
, r_symndx
);
3639 reloc_got_type
= aarch64_reloc_got_type (r_type
);
3641 if (symbol_got_type
== GOT_TLS_IE
&& GOT_TLS_GD_ANY_P (reloc_got_type
))
3647 if (h
&& h
->root
.type
== bfd_link_hash_undefweak
)
3654 aarch64_tls_transition (bfd
*input_bfd
,
3655 struct bfd_link_info
*info
,
3656 unsigned int r_type
,
3657 struct elf_link_hash_entry
*h
,
3658 unsigned long r_symndx
)
3660 if (! aarch64_can_relax_tls (input_bfd
, info
, r_type
, h
, r_symndx
))
3663 return aarch64_tls_transition_without_check (r_type
, h
);
3666 /* Return the base VMA address which should be subtracted from real addresses
3667 when resolving R_AARCH64_TLS_DTPREL64 relocation. */
3670 dtpoff_base (struct bfd_link_info
*info
)
3672 /* If tls_sec is NULL, we should have signalled an error already. */
3673 BFD_ASSERT (elf_hash_table (info
)->tls_sec
!= NULL
);
3674 return elf_hash_table (info
)->tls_sec
->vma
;
3678 /* Return the base VMA address which should be subtracted from real addresses
3679 when resolving R_AARCH64_TLS_GOTTPREL64 relocations. */
3682 tpoff_base (struct bfd_link_info
*info
)
3684 struct elf_link_hash_table
*htab
= elf_hash_table (info
);
3686 /* If tls_sec is NULL, we should have signalled an error already. */
3687 if (htab
->tls_sec
== NULL
)
3690 bfd_vma base
= align_power ((bfd_vma
) TCB_SIZE
,
3691 htab
->tls_sec
->alignment_power
);
3692 return htab
->tls_sec
->vma
- base
;
3696 symbol_got_offset_ref (bfd
*input_bfd
, struct elf_link_hash_entry
*h
,
3697 unsigned long r_symndx
)
3699 /* Calculate the address of the GOT entry for symbol
3700 referred to in h. */
3702 return &h
->got
.offset
;
3706 struct elf_aarch64_local_symbol
*l
;
3708 l
= elf64_aarch64_locals (input_bfd
);
3709 return &l
[r_symndx
].got_offset
;
3714 symbol_got_offset_mark (bfd
*input_bfd
, struct elf_link_hash_entry
*h
,
3715 unsigned long r_symndx
)
3718 p
= symbol_got_offset_ref (input_bfd
, h
, r_symndx
);
3723 symbol_got_offset_mark_p (bfd
*input_bfd
, struct elf_link_hash_entry
*h
,
3724 unsigned long r_symndx
)
3727 value
= * symbol_got_offset_ref (input_bfd
, h
, r_symndx
);
3732 symbol_got_offset (bfd
*input_bfd
, struct elf_link_hash_entry
*h
,
3733 unsigned long r_symndx
)
3736 value
= * symbol_got_offset_ref (input_bfd
, h
, r_symndx
);
3742 symbol_tlsdesc_got_offset_ref (bfd
*input_bfd
, struct elf_link_hash_entry
*h
,
3743 unsigned long r_symndx
)
3745 /* Calculate the address of the GOT entry for symbol
3746 referred to in h. */
3749 struct elf64_aarch64_link_hash_entry
*eh
;
3750 eh
= (struct elf64_aarch64_link_hash_entry
*) h
;
3751 return &eh
->tlsdesc_got_jump_table_offset
;
3756 struct elf_aarch64_local_symbol
*l
;
3758 l
= elf64_aarch64_locals (input_bfd
);
3759 return &l
[r_symndx
].tlsdesc_got_jump_table_offset
;
3764 symbol_tlsdesc_got_offset_mark (bfd
*input_bfd
, struct elf_link_hash_entry
*h
,
3765 unsigned long r_symndx
)
3768 p
= symbol_tlsdesc_got_offset_ref (input_bfd
, h
, r_symndx
);
3773 symbol_tlsdesc_got_offset_mark_p (bfd
*input_bfd
,
3774 struct elf_link_hash_entry
*h
,
3775 unsigned long r_symndx
)
3778 value
= * symbol_tlsdesc_got_offset_ref (input_bfd
, h
, r_symndx
);
3783 symbol_tlsdesc_got_offset (bfd
*input_bfd
, struct elf_link_hash_entry
*h
,
3784 unsigned long r_symndx
)
3787 value
= * symbol_tlsdesc_got_offset_ref (input_bfd
, h
, r_symndx
);
3792 /* Perform a relocation as part of a final link. */
3793 static bfd_reloc_status_type
3794 elf64_aarch64_final_link_relocate (reloc_howto_type
*howto
,
3797 asection
*input_section
,
3799 Elf_Internal_Rela
*rel
,
3801 struct bfd_link_info
*info
,
3803 struct elf_link_hash_entry
*h
,
3804 bfd_boolean
*unresolved_reloc_p
,
3805 bfd_boolean save_addend
,
3806 bfd_vma
*saved_addend
)
3808 unsigned int r_type
= howto
->type
;
3809 unsigned long r_symndx
;
3810 bfd_byte
*hit_data
= contents
+ rel
->r_offset
;
3812 bfd_signed_vma signed_addend
;
3813 struct elf64_aarch64_link_hash_table
*globals
;
3814 bfd_boolean weak_undef_p
;
3816 globals
= elf64_aarch64_hash_table (info
);
3818 BFD_ASSERT (is_aarch64_elf (input_bfd
));
3820 r_symndx
= ELF64_R_SYM (rel
->r_info
);
3822 /* It is possible to have linker relaxations on some TLS access
3823 models. Update our information here. */
3824 r_type
= aarch64_tls_transition (input_bfd
, info
, r_type
, h
, r_symndx
);
3826 if (r_type
!= howto
->type
)
3827 howto
= elf64_aarch64_howto_from_type (r_type
);
3829 place
= input_section
->output_section
->vma
3830 + input_section
->output_offset
+ rel
->r_offset
;
3832 /* Get addend, accumulating the addend for consecutive relocs
3833 which refer to the same offset. */
3834 signed_addend
= saved_addend
? *saved_addend
: 0;
3835 signed_addend
+= rel
->r_addend
;
3837 weak_undef_p
= (h
? h
->root
.type
== bfd_link_hash_undefweak
3838 : bfd_is_und_section (sym_sec
));
3841 case R_AARCH64_NONE
:
3842 case R_AARCH64_NULL
:
3843 case R_AARCH64_TLSDESC_CALL
:
3844 *unresolved_reloc_p
= FALSE
;
3845 return bfd_reloc_ok
;
3847 case R_AARCH64_ABS64
:
3849 /* When generating a shared object or relocatable executable, these
3850 relocations are copied into the output file to be resolved at
3852 if (((info
->shared
== TRUE
) || globals
->root
.is_relocatable_executable
)
3853 && (input_section
->flags
& SEC_ALLOC
)
3855 || ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
3856 || h
->root
.type
!= bfd_link_hash_undefweak
))
3858 Elf_Internal_Rela outrel
;
3860 bfd_boolean skip
, relocate
;
3863 *unresolved_reloc_p
= FALSE
;
3865 sreloc
= _bfd_elf_get_dynamic_reloc_section (input_bfd
,
3868 return bfd_reloc_notsupported
;
3873 outrel
.r_addend
= signed_addend
;
3875 _bfd_elf_section_offset (output_bfd
, info
, input_section
,
3877 if (outrel
.r_offset
== (bfd_vma
) - 1)
3879 else if (outrel
.r_offset
== (bfd_vma
) - 2)
3885 outrel
.r_offset
+= (input_section
->output_section
->vma
3886 + input_section
->output_offset
);
3889 memset (&outrel
, 0, sizeof outrel
);
3892 && (!info
->shared
|| !info
->symbolic
|| !h
->def_regular
))
3893 outrel
.r_info
= ELF64_R_INFO (h
->dynindx
, r_type
);
3898 /* On SVR4-ish systems, the dynamic loader cannot
3899 relocate the text and data segments independently,
3900 so the symbol does not matter. */
3902 outrel
.r_info
= ELF64_R_INFO (symbol
, R_AARCH64_RELATIVE
);
3903 outrel
.r_addend
+= value
;
3906 loc
= sreloc
->contents
+ sreloc
->reloc_count
++ * RELOC_SIZE (htab
);
3907 bfd_elf64_swap_reloca_out (output_bfd
, &outrel
, loc
);
3909 if (sreloc
->reloc_count
* RELOC_SIZE (htab
) > sreloc
->size
)
3911 /* Sanity to check that we have previously allocated
3912 sufficient space in the relocation section for the
3913 number of relocations we actually want to emit. */
3917 /* If this reloc is against an external symbol, we do not want to
3918 fiddle with the addend. Otherwise, we need to include the symbol
3919 value so that it becomes an addend for the dynamic reloc. */
3921 return bfd_reloc_ok
;
3923 return _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
3924 contents
, rel
->r_offset
, value
,
3928 value
+= signed_addend
;
3931 case R_AARCH64_JUMP26
:
3932 case R_AARCH64_CALL26
:
3934 asection
*splt
= globals
->root
.splt
;
3935 bfd_boolean via_plt_p
=
3936 splt
!= NULL
&& h
!= NULL
&& h
->plt
.offset
!= (bfd_vma
) - 1;
3938 /* A call to an undefined weak symbol is converted to a jump to
3939 the next instruction unless a PLT entry will be created.
3940 The jump to the next instruction is optimized as a NOP.
3941 Do the same for local undefined symbols. */
3942 if (weak_undef_p
&& ! via_plt_p
)
3944 bfd_putl32 (INSN_NOP
, hit_data
);
3945 return bfd_reloc_ok
;
3948 /* If the call goes through a PLT entry, make sure to
3949 check distance to the right destination address. */
3952 value
= (splt
->output_section
->vma
3953 + splt
->output_offset
+ h
->plt
.offset
);
3954 *unresolved_reloc_p
= FALSE
;
3957 /* If the target symbol is global and marked as a function the
3958 relocation applies a function call or a tail call. In this
3959 situation we can veneer out of range branches. The veneers
3960 use IP0 and IP1 hence cannot be used arbitrary out of range
3961 branches that occur within the body of a function. */
3962 if (h
&& h
->type
== STT_FUNC
)
3964 /* Check if a stub has to be inserted because the destination
3966 if (! aarch64_valid_branch_p (value
, place
))
3968 /* The target is out of reach, so redirect the branch to
3969 the local stub for this function. */
3970 struct elf64_aarch64_stub_hash_entry
*stub_entry
;
3971 stub_entry
= elf64_aarch64_get_stub_entry (input_section
,
3974 if (stub_entry
!= NULL
)
3975 value
= (stub_entry
->stub_offset
3976 + stub_entry
->stub_sec
->output_offset
3977 + stub_entry
->stub_sec
->output_section
->vma
);
3981 value
= aarch64_resolve_relocation (r_type
, place
, value
,
3982 signed_addend
, weak_undef_p
);
3985 case R_AARCH64_ABS16
:
3986 case R_AARCH64_ABS32
:
3987 case R_AARCH64_ADD_ABS_LO12_NC
:
3988 case R_AARCH64_ADR_PREL_LO21
:
3989 case R_AARCH64_ADR_PREL_PG_HI21
:
3990 case R_AARCH64_ADR_PREL_PG_HI21_NC
:
3991 case R_AARCH64_CONDBR19
:
3992 case R_AARCH64_LD_PREL_LO19
:
3993 case R_AARCH64_LDST8_ABS_LO12_NC
:
3994 case R_AARCH64_LDST16_ABS_LO12_NC
:
3995 case R_AARCH64_LDST32_ABS_LO12_NC
:
3996 case R_AARCH64_LDST64_ABS_LO12_NC
:
3997 case R_AARCH64_LDST128_ABS_LO12_NC
:
3998 case R_AARCH64_MOVW_SABS_G0
:
3999 case R_AARCH64_MOVW_SABS_G1
:
4000 case R_AARCH64_MOVW_SABS_G2
:
4001 case R_AARCH64_MOVW_UABS_G0
:
4002 case R_AARCH64_MOVW_UABS_G0_NC
:
4003 case R_AARCH64_MOVW_UABS_G1
:
4004 case R_AARCH64_MOVW_UABS_G1_NC
:
4005 case R_AARCH64_MOVW_UABS_G2
:
4006 case R_AARCH64_MOVW_UABS_G2_NC
:
4007 case R_AARCH64_MOVW_UABS_G3
:
4008 case R_AARCH64_PREL16
:
4009 case R_AARCH64_PREL32
:
4010 case R_AARCH64_PREL64
:
4011 case R_AARCH64_TSTBR14
:
4012 value
= aarch64_resolve_relocation (r_type
, place
, value
,
4013 signed_addend
, weak_undef_p
);
4016 case R_AARCH64_LD64_GOT_LO12_NC
:
4017 case R_AARCH64_ADR_GOT_PAGE
:
4018 case R_AARCH64_GOT_LD_PREL19
:
4019 if (globals
->root
.sgot
== NULL
)
4020 BFD_ASSERT (h
!= NULL
);
4024 value
= aarch64_calculate_got_entry_vma (h
, globals
, info
, value
,
4026 unresolved_reloc_p
);
4027 value
= aarch64_resolve_relocation (r_type
, place
, value
,
4032 case R_AARCH64_TLSGD_ADR_PAGE21
:
4033 case R_AARCH64_TLSGD_ADD_LO12_NC
:
4034 case R_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21
:
4035 case R_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC
:
4036 if (globals
->root
.sgot
== NULL
)
4037 return bfd_reloc_notsupported
;
4039 value
= (symbol_got_offset (input_bfd
, h
, r_symndx
)
4040 + globals
->root
.sgot
->output_section
->vma
4041 + globals
->root
.sgot
->output_section
->output_offset
);
4043 value
= aarch64_resolve_relocation (r_type
, place
, value
,
4045 *unresolved_reloc_p
= FALSE
;
4048 case R_AARCH64_TLSLE_ADD_TPREL_HI12
:
4049 case R_AARCH64_TLSLE_ADD_TPREL_LO12
:
4050 case R_AARCH64_TLSLE_ADD_TPREL_LO12_NC
:
4051 case R_AARCH64_TLSLE_MOVW_TPREL_G0
:
4052 case R_AARCH64_TLSLE_MOVW_TPREL_G0_NC
:
4053 case R_AARCH64_TLSLE_MOVW_TPREL_G1
:
4054 case R_AARCH64_TLSLE_MOVW_TPREL_G1_NC
:
4055 case R_AARCH64_TLSLE_MOVW_TPREL_G2
:
4056 value
= aarch64_resolve_relocation (r_type
, place
, value
,
4057 signed_addend
- tpoff_base (info
), weak_undef_p
);
4058 *unresolved_reloc_p
= FALSE
;
4061 case R_AARCH64_TLSDESC_ADR_PAGE
:
4062 case R_AARCH64_TLSDESC_LD64_LO12_NC
:
4063 case R_AARCH64_TLSDESC_ADD_LO12_NC
:
4064 case R_AARCH64_TLSDESC_ADD
:
4065 case R_AARCH64_TLSDESC_LDR
:
4066 if (globals
->root
.sgot
== NULL
)
4067 return bfd_reloc_notsupported
;
4069 value
= (symbol_tlsdesc_got_offset (input_bfd
, h
, r_symndx
)
4070 + globals
->root
.sgotplt
->output_section
->vma
4071 + globals
->root
.sgotplt
->output_section
->output_offset
4072 + globals
->sgotplt_jump_table_size
);
4074 value
= aarch64_resolve_relocation (r_type
, place
, value
,
4076 *unresolved_reloc_p
= FALSE
;
4080 return bfd_reloc_notsupported
;
4084 *saved_addend
= value
;
4086 /* Only apply the final relocation in a sequence. */
4088 return bfd_reloc_continue
;
4090 return bfd_elf_aarch64_put_addend (input_bfd
, hit_data
, howto
, value
);
4093 /* Handle TLS relaxations. Relaxing is possible for symbols that use
4094 R_AARCH64_TLSDESC_ADR_{PAGE, LD64_LO12_NC, ADD_LO12_NC} during a static
4097 Return bfd_reloc_ok if we're done, bfd_reloc_continue if the caller
4098 is to then call final_link_relocate. Return other values in the
4101 static bfd_reloc_status_type
4102 elf64_aarch64_tls_relax (struct elf64_aarch64_link_hash_table
*globals
,
4103 bfd
*input_bfd
, bfd_byte
*contents
,
4104 Elf_Internal_Rela
*rel
, struct elf_link_hash_entry
*h
)
4106 bfd_boolean is_local
= h
== NULL
;
4107 unsigned int r_type
= ELF64_R_TYPE (rel
->r_info
);
4110 BFD_ASSERT (globals
&& input_bfd
&& contents
&& rel
);
4114 case R_AARCH64_TLSGD_ADR_PAGE21
:
4115 case R_AARCH64_TLSDESC_ADR_PAGE
:
4118 /* GD->LE relaxation:
4119 adrp x0, :tlsgd:var => movz x0, :tprel_g1:var
4121 adrp x0, :tlsdesc:var => movz x0, :tprel_g1:var
4123 bfd_putl32 (0xd2a00000, contents
+ rel
->r_offset
);
4124 return bfd_reloc_continue
;
4128 /* GD->IE relaxation:
4129 adrp x0, :tlsgd:var => adrp x0, :gottprel:var
4131 adrp x0, :tlsdesc:var => adrp x0, :gottprel:var
4133 insn
= bfd_getl32 (contents
+ rel
->r_offset
);
4134 return bfd_reloc_continue
;
4137 case R_AARCH64_TLSDESC_LD64_LO12_NC
:
4140 /* GD->LE relaxation:
4141 ldr xd, [x0, #:tlsdesc_lo12:var] => movk x0, :tprel_g0_nc:var
4143 bfd_putl32 (0xf2800000, contents
+ rel
->r_offset
);
4144 return bfd_reloc_continue
;
4148 /* GD->IE relaxation:
4149 ldr xd, [x0, #:tlsdesc_lo12:var] => ldr x0, [x0, #:gottprel_lo12:var]
4151 insn
= bfd_getl32 (contents
+ rel
->r_offset
);
4153 bfd_putl32 (insn
, contents
+ rel
->r_offset
);
4154 return bfd_reloc_continue
;
4157 case R_AARCH64_TLSGD_ADD_LO12_NC
:
4160 /* GD->LE relaxation
4161 add x0, #:tlsgd_lo12:var => movk x0, :tprel_g0_nc:var
4162 bl __tls_get_addr => mrs x1, tpidr_el0
4163 nop => add x0, x1, x0
4166 /* First kill the tls_get_addr reloc on the bl instruction. */
4167 BFD_ASSERT (rel
->r_offset
+ 4 == rel
[1].r_offset
);
4168 rel
[1].r_info
= ELF64_R_INFO (STN_UNDEF
, R_AARCH64_NONE
);
4170 bfd_putl32 (0xf2800000, contents
+ rel
->r_offset
);
4171 bfd_putl32 (0xd53bd041, contents
+ rel
->r_offset
+ 4);
4172 bfd_putl32 (0x8b000020, contents
+ rel
->r_offset
+ 8);
4173 return bfd_reloc_continue
;
4177 /* GD->IE relaxation
4178 ADD x0, #:tlsgd_lo12:var => ldr x0, [x0, #:gottprel_lo12:var]
4179 BL __tls_get_addr => mrs x1, tpidr_el0
4181 NOP => add x0, x1, x0
4184 BFD_ASSERT (ELF64_R_TYPE (rel
[1].r_info
) == R_AARCH64_CALL26
);
4186 /* Remove the relocation on the BL instruction. */
4187 rel
[1].r_info
= ELF64_R_INFO (STN_UNDEF
, R_AARCH64_NONE
);
4189 bfd_putl32 (0xf9400000, contents
+ rel
->r_offset
);
4191 /* We choose to fixup the BL and NOP instructions using the
4192 offset from the second relocation to allow flexibility in
4193 scheduling instructions between the ADD and BL. */
4194 bfd_putl32 (0xd53bd041, contents
+ rel
[1].r_offset
);
4195 bfd_putl32 (0x8b000020, contents
+ rel
[1].r_offset
+ 4);
4196 return bfd_reloc_continue
;
4199 case R_AARCH64_TLSDESC_ADD_LO12_NC
:
4200 case R_AARCH64_TLSDESC_CALL
:
4201 /* GD->IE/LE relaxation:
4202 add x0, x0, #:tlsdesc_lo12:var => nop
4205 bfd_putl32 (INSN_NOP
, contents
+ rel
->r_offset
);
4206 return bfd_reloc_ok
;
4208 case R_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21
:
4209 /* IE->LE relaxation:
4210 adrp xd, :gottprel:var => movz xd, :tprel_g1:var
4214 insn
= bfd_getl32 (contents
+ rel
->r_offset
);
4215 bfd_putl32 (0xd2a00000 | (insn
& 0x1f), contents
+ rel
->r_offset
);
4217 return bfd_reloc_continue
;
4219 case R_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC
:
4220 /* IE->LE relaxation:
4221 ldr xd, [xm, #:gottprel_lo12:var] => movk xd, :tprel_g0_nc:var
4225 insn
= bfd_getl32 (contents
+ rel
->r_offset
);
4226 bfd_putl32 (0xf2800000 | (insn
& 0x1f), contents
+ rel
->r_offset
);
4228 return bfd_reloc_continue
;
4231 return bfd_reloc_continue
;
4234 return bfd_reloc_ok
;
4237 /* Relocate an AArch64 ELF section. */
4240 elf64_aarch64_relocate_section (bfd
*output_bfd
,
4241 struct bfd_link_info
*info
,
4243 asection
*input_section
,
4245 Elf_Internal_Rela
*relocs
,
4246 Elf_Internal_Sym
*local_syms
,
4247 asection
**local_sections
)
4249 Elf_Internal_Shdr
*symtab_hdr
;
4250 struct elf_link_hash_entry
**sym_hashes
;
4251 Elf_Internal_Rela
*rel
;
4252 Elf_Internal_Rela
*relend
;
4254 struct elf64_aarch64_link_hash_table
*globals
;
4255 bfd_boolean save_addend
= FALSE
;
4258 globals
= elf64_aarch64_hash_table (info
);
4260 symtab_hdr
= &elf_symtab_hdr (input_bfd
);
4261 sym_hashes
= elf_sym_hashes (input_bfd
);
4264 relend
= relocs
+ input_section
->reloc_count
;
4265 for (; rel
< relend
; rel
++)
4267 unsigned int r_type
;
4268 unsigned int relaxed_r_type
;
4269 reloc_howto_type
*howto
;
4270 unsigned long r_symndx
;
4271 Elf_Internal_Sym
*sym
;
4273 struct elf_link_hash_entry
*h
;
4275 bfd_reloc_status_type r
;
4278 bfd_boolean unresolved_reloc
= FALSE
;
4279 char *error_message
= NULL
;
4281 r_symndx
= ELF64_R_SYM (rel
->r_info
);
4282 r_type
= ELF64_R_TYPE (rel
->r_info
);
4284 bfd_reloc
.howto
= elf64_aarch64_howto_from_type (r_type
);
4285 howto
= bfd_reloc
.howto
;
4291 if (r_symndx
< symtab_hdr
->sh_info
)
4293 sym
= local_syms
+ r_symndx
;
4294 sym_type
= ELF64_ST_TYPE (sym
->st_info
);
4295 sec
= local_sections
[r_symndx
];
4297 /* An object file might have a reference to a local
4298 undefined symbol. This is a daft object file, but we
4299 should at least do something about it. */
4300 if (r_type
!= R_AARCH64_NONE
&& r_type
!= R_AARCH64_NULL
4301 && bfd_is_und_section (sec
)
4302 && ELF_ST_BIND (sym
->st_info
) != STB_WEAK
)
4304 if (!info
->callbacks
->undefined_symbol
4305 (info
, bfd_elf_string_from_elf_section
4306 (input_bfd
, symtab_hdr
->sh_link
, sym
->st_name
),
4307 input_bfd
, input_section
, rel
->r_offset
, TRUE
))
4311 if (r_type
>= R_AARCH64_dyn_max
)
4313 bfd_set_error (bfd_error_bad_value
);
4317 relocation
= _bfd_elf_rela_local_sym (output_bfd
, sym
, &sec
, rel
);
4323 RELOC_FOR_GLOBAL_SYMBOL (info
, input_bfd
, input_section
, rel
,
4324 r_symndx
, symtab_hdr
, sym_hashes
,
4326 unresolved_reloc
, warned
);
4331 if (sec
!= NULL
&& discarded_section (sec
))
4332 RELOC_AGAINST_DISCARDED_SECTION (info
, input_bfd
, input_section
,
4333 rel
, 1, relend
, howto
, 0, contents
);
4335 if (info
->relocatable
)
4337 /* This is a relocatable link. We don't have to change
4338 anything, unless the reloc is against a section symbol,
4339 in which case we have to adjust according to where the
4340 section symbol winds up in the output section. */
4341 if (sym
!= NULL
&& ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
4342 rel
->r_addend
+= sec
->output_offset
;
4347 name
= h
->root
.root
.string
;
4350 name
= (bfd_elf_string_from_elf_section
4351 (input_bfd
, symtab_hdr
->sh_link
, sym
->st_name
));
4352 if (name
== NULL
|| *name
== '\0')
4353 name
= bfd_section_name (input_bfd
, sec
);
4357 && r_type
!= R_AARCH64_NONE
4358 && r_type
!= R_AARCH64_NULL
4360 || h
->root
.type
== bfd_link_hash_defined
4361 || h
->root
.type
== bfd_link_hash_defweak
)
4362 && IS_AARCH64_TLS_RELOC (r_type
) != (sym_type
== STT_TLS
))
4364 (*_bfd_error_handler
)
4365 ((sym_type
== STT_TLS
4366 ? _("%B(%A+0x%lx): %s used with TLS symbol %s")
4367 : _("%B(%A+0x%lx): %s used with non-TLS symbol %s")),
4369 input_section
, (long) rel
->r_offset
, howto
->name
, name
);
4373 /* We relax only if we can see that there can be a valid transition
4374 from a reloc type to another.
4375 We call elf64_aarch64_final_link_relocate unless we're completely
4376 done, i.e., the relaxation produced the final output we want. */
4378 relaxed_r_type
= aarch64_tls_transition (input_bfd
, info
, r_type
,
4380 if (relaxed_r_type
!= r_type
)
4382 r_type
= relaxed_r_type
;
4383 howto
= elf64_aarch64_howto_from_type (r_type
);
4385 r
= elf64_aarch64_tls_relax (globals
, input_bfd
, contents
, rel
, h
);
4386 unresolved_reloc
= 0;
4389 r
= bfd_reloc_continue
;
4391 /* There may be multiple consecutive relocations for the
4392 same offset. In that case we are supposed to treat the
4393 output of each relocation as the addend for the next. */
4394 if (rel
+ 1 < relend
4395 && rel
->r_offset
== rel
[1].r_offset
4396 && ELF64_R_TYPE (rel
[1].r_info
) != R_AARCH64_NONE
4397 && ELF64_R_TYPE (rel
[1].r_info
) != R_AARCH64_NULL
)
4400 save_addend
= FALSE
;
4402 if (r
== bfd_reloc_continue
)
4403 r
= elf64_aarch64_final_link_relocate (howto
, input_bfd
, output_bfd
,
4404 input_section
, contents
, rel
,
4405 relocation
, info
, sec
,
4406 h
, &unresolved_reloc
,
4407 save_addend
, &addend
);
4411 case R_AARCH64_TLSGD_ADR_PAGE21
:
4412 case R_AARCH64_TLSGD_ADD_LO12_NC
:
4413 if (! symbol_got_offset_mark_p (input_bfd
, h
, r_symndx
))
4415 bfd_boolean need_relocs
= FALSE
;
4420 off
= symbol_got_offset (input_bfd
, h
, r_symndx
);
4421 indx
= h
&& h
->dynindx
!= -1 ? h
->dynindx
: 0;
4424 (info
->shared
|| indx
!= 0) &&
4426 || ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
4427 || h
->root
.type
!= bfd_link_hash_undefweak
);
4429 BFD_ASSERT (globals
->root
.srelgot
!= NULL
);
4433 Elf_Internal_Rela rela
;
4434 rela
.r_info
= ELF64_R_INFO (indx
, R_AARCH64_TLS_DTPMOD64
);
4436 rela
.r_offset
= globals
->root
.sgot
->output_section
->vma
+
4437 globals
->root
.sgot
->output_offset
+ off
;
4440 loc
= globals
->root
.srelgot
->contents
;
4441 loc
+= globals
->root
.srelgot
->reloc_count
++
4442 * RELOC_SIZE (htab
);
4443 bfd_elf64_swap_reloca_out (output_bfd
, &rela
, loc
);
4447 bfd_put_64 (output_bfd
,
4448 relocation
- dtpoff_base (info
),
4449 globals
->root
.sgot
->contents
+ off
4454 /* This TLS symbol is global. We emit a
4455 relocation to fixup the tls offset at load
4458 ELF64_R_INFO (indx
, R_AARCH64_TLS_DTPREL64
);
4461 (globals
->root
.sgot
->output_section
->vma
4462 + globals
->root
.sgot
->output_offset
+ off
4465 loc
= globals
->root
.srelgot
->contents
;
4466 loc
+= globals
->root
.srelgot
->reloc_count
++
4467 * RELOC_SIZE (globals
);
4468 bfd_elf64_swap_reloca_out (output_bfd
, &rela
, loc
);
4469 bfd_put_64 (output_bfd
, (bfd_vma
) 0,
4470 globals
->root
.sgot
->contents
+ off
4476 bfd_put_64 (output_bfd
, (bfd_vma
) 1,
4477 globals
->root
.sgot
->contents
+ off
);
4478 bfd_put_64 (output_bfd
,
4479 relocation
- dtpoff_base (info
),
4480 globals
->root
.sgot
->contents
+ off
4484 symbol_got_offset_mark (input_bfd
, h
, r_symndx
);
4488 case R_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21
:
4489 case R_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC
:
4490 if (! symbol_got_offset_mark_p (input_bfd
, h
, r_symndx
))
4492 bfd_boolean need_relocs
= FALSE
;
4497 off
= symbol_got_offset (input_bfd
, h
, r_symndx
);
4499 indx
= h
&& h
->dynindx
!= -1 ? h
->dynindx
: 0;
4502 (info
->shared
|| indx
!= 0) &&
4504 || ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
4505 || h
->root
.type
!= bfd_link_hash_undefweak
);
4507 BFD_ASSERT (globals
->root
.srelgot
!= NULL
);
4511 Elf_Internal_Rela rela
;
4514 rela
.r_addend
= relocation
- dtpoff_base (info
);
4518 rela
.r_info
= ELF64_R_INFO (indx
, R_AARCH64_TLS_TPREL64
);
4519 rela
.r_offset
= globals
->root
.sgot
->output_section
->vma
+
4520 globals
->root
.sgot
->output_offset
+ off
;
4522 loc
= globals
->root
.srelgot
->contents
;
4523 loc
+= globals
->root
.srelgot
->reloc_count
++
4524 * RELOC_SIZE (htab
);
4526 bfd_elf64_swap_reloca_out (output_bfd
, &rela
, loc
);
4528 bfd_put_64 (output_bfd
, rela
.r_addend
,
4529 globals
->root
.sgot
->contents
+ off
);
4532 bfd_put_64 (output_bfd
, relocation
- tpoff_base (info
),
4533 globals
->root
.sgot
->contents
+ off
);
4535 symbol_got_offset_mark (input_bfd
, h
, r_symndx
);
4539 case R_AARCH64_TLSLE_ADD_TPREL_LO12
:
4540 case R_AARCH64_TLSLE_ADD_TPREL_HI12
:
4541 case R_AARCH64_TLSLE_ADD_TPREL_LO12_NC
:
4542 case R_AARCH64_TLSLE_MOVW_TPREL_G2
:
4543 case R_AARCH64_TLSLE_MOVW_TPREL_G1
:
4544 case R_AARCH64_TLSLE_MOVW_TPREL_G1_NC
:
4545 case R_AARCH64_TLSLE_MOVW_TPREL_G0
:
4546 case R_AARCH64_TLSLE_MOVW_TPREL_G0_NC
:
4549 case R_AARCH64_TLSDESC_ADR_PAGE
:
4550 case R_AARCH64_TLSDESC_LD64_LO12_NC
:
4551 case R_AARCH64_TLSDESC_ADD_LO12_NC
:
4552 if (! symbol_tlsdesc_got_offset_mark_p (input_bfd
, h
, r_symndx
))
4554 bfd_boolean need_relocs
= FALSE
;
4555 int indx
= h
&& h
->dynindx
!= -1 ? h
->dynindx
: 0;
4556 bfd_vma off
= symbol_tlsdesc_got_offset (input_bfd
, h
, r_symndx
);
4558 need_relocs
= (h
== NULL
4559 || ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
4560 || h
->root
.type
!= bfd_link_hash_undefweak
);
4562 BFD_ASSERT (globals
->root
.srelgot
!= NULL
);
4563 BFD_ASSERT (globals
->root
.sgot
!= NULL
);
4568 Elf_Internal_Rela rela
;
4569 rela
.r_info
= ELF64_R_INFO (indx
, R_AARCH64_TLSDESC
);
4571 rela
.r_offset
= (globals
->root
.sgotplt
->output_section
->vma
4572 + globals
->root
.sgotplt
->output_offset
4573 + off
+ globals
->sgotplt_jump_table_size
);
4576 rela
.r_addend
= relocation
- dtpoff_base (info
);
4578 /* Allocate the next available slot in the PLT reloc
4579 section to hold our R_AARCH64_TLSDESC, the next
4580 available slot is determined from reloc_count,
4581 which we step. But note, reloc_count was
4582 artifically moved down while allocating slots for
4583 real PLT relocs such that all of the PLT relocs
4584 will fit above the initial reloc_count and the
4585 extra stuff will fit below. */
4586 loc
= globals
->root
.srelplt
->contents
;
4587 loc
+= globals
->root
.srelplt
->reloc_count
++
4588 * RELOC_SIZE (globals
);
4590 bfd_elf64_swap_reloca_out (output_bfd
, &rela
, loc
);
4592 bfd_put_64 (output_bfd
, (bfd_vma
) 0,
4593 globals
->root
.sgotplt
->contents
+ off
+
4594 globals
->sgotplt_jump_table_size
);
4595 bfd_put_64 (output_bfd
, (bfd_vma
) 0,
4596 globals
->root
.sgotplt
->contents
+ off
+
4597 globals
->sgotplt_jump_table_size
+
4601 symbol_tlsdesc_got_offset_mark (input_bfd
, h
, r_symndx
);
4610 /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
4611 because such sections are not SEC_ALLOC and thus ld.so will
4612 not process them. */
4613 if (unresolved_reloc
4614 && !((input_section
->flags
& SEC_DEBUGGING
) != 0
4616 && _bfd_elf_section_offset (output_bfd
, info
, input_section
,
4617 +rel
->r_offset
) != (bfd_vma
) - 1)
4619 (*_bfd_error_handler
)
4621 ("%B(%A+0x%lx): unresolvable %s relocation against symbol `%s'"),
4622 input_bfd
, input_section
, (long) rel
->r_offset
, howto
->name
,
4623 h
->root
.root
.string
);
4627 if (r
!= bfd_reloc_ok
&& r
!= bfd_reloc_continue
)
4631 case bfd_reloc_overflow
:
4632 /* If the overflowing reloc was to an undefined symbol,
4633 we have already printed one error message and there
4634 is no point complaining again. */
4636 h
->root
.type
!= bfd_link_hash_undefined
)
4637 && (!((*info
->callbacks
->reloc_overflow
)
4638 (info
, (h
? &h
->root
: NULL
), name
, howto
->name
,
4639 (bfd_vma
) 0, input_bfd
, input_section
,
4644 case bfd_reloc_undefined
:
4645 if (!((*info
->callbacks
->undefined_symbol
)
4646 (info
, name
, input_bfd
, input_section
,
4647 rel
->r_offset
, TRUE
)))
4651 case bfd_reloc_outofrange
:
4652 error_message
= _("out of range");
4655 case bfd_reloc_notsupported
:
4656 error_message
= _("unsupported relocation");
4659 case bfd_reloc_dangerous
:
4660 /* error_message should already be set. */
4664 error_message
= _("unknown error");
4668 BFD_ASSERT (error_message
!= NULL
);
4669 if (!((*info
->callbacks
->reloc_dangerous
)
4670 (info
, error_message
, input_bfd
, input_section
,
4681 /* Set the right machine number. */
4684 elf64_aarch64_object_p (bfd
*abfd
)
4686 bfd_default_set_arch_mach (abfd
, bfd_arch_aarch64
, bfd_mach_aarch64
);
4690 /* Function to keep AArch64 specific flags in the ELF header. */
4693 elf64_aarch64_set_private_flags (bfd
*abfd
, flagword flags
)
4695 if (elf_flags_init (abfd
) && elf_elfheader (abfd
)->e_flags
!= flags
)
4700 elf_elfheader (abfd
)->e_flags
= flags
;
4701 elf_flags_init (abfd
) = TRUE
;
4707 /* Copy backend specific data from one object module to another. */
4710 elf64_aarch64_copy_private_bfd_data (bfd
*ibfd
, bfd
*obfd
)
4714 if (!is_aarch64_elf (ibfd
) || !is_aarch64_elf (obfd
))
4717 in_flags
= elf_elfheader (ibfd
)->e_flags
;
4719 elf_elfheader (obfd
)->e_flags
= in_flags
;
4720 elf_flags_init (obfd
) = TRUE
;
4722 /* Also copy the EI_OSABI field. */
4723 elf_elfheader (obfd
)->e_ident
[EI_OSABI
] =
4724 elf_elfheader (ibfd
)->e_ident
[EI_OSABI
];
4726 /* Copy object attributes. */
4727 _bfd_elf_copy_obj_attributes (ibfd
, obfd
);
4732 /* Merge backend specific data from an object file to the output
4733 object file when linking. */
4736 elf64_aarch64_merge_private_bfd_data (bfd
*ibfd
, bfd
*obfd
)
4740 bfd_boolean flags_compatible
= TRUE
;
4743 /* Check if we have the same endianess. */
4744 if (!_bfd_generic_verify_endian_match (ibfd
, obfd
))
4747 if (!is_aarch64_elf (ibfd
) || !is_aarch64_elf (obfd
))
4750 /* The input BFD must have had its flags initialised. */
4751 /* The following seems bogus to me -- The flags are initialized in
4752 the assembler but I don't think an elf_flags_init field is
4753 written into the object. */
4754 /* BFD_ASSERT (elf_flags_init (ibfd)); */
4756 in_flags
= elf_elfheader (ibfd
)->e_flags
;
4757 out_flags
= elf_elfheader (obfd
)->e_flags
;
4759 if (!elf_flags_init (obfd
))
4761 /* If the input is the default architecture and had the default
4762 flags then do not bother setting the flags for the output
4763 architecture, instead allow future merges to do this. If no
4764 future merges ever set these flags then they will retain their
4765 uninitialised values, which surprise surprise, correspond
4766 to the default values. */
4767 if (bfd_get_arch_info (ibfd
)->the_default
4768 && elf_elfheader (ibfd
)->e_flags
== 0)
4771 elf_flags_init (obfd
) = TRUE
;
4772 elf_elfheader (obfd
)->e_flags
= in_flags
;
4774 if (bfd_get_arch (obfd
) == bfd_get_arch (ibfd
)
4775 && bfd_get_arch_info (obfd
)->the_default
)
4776 return bfd_set_arch_mach (obfd
, bfd_get_arch (ibfd
),
4777 bfd_get_mach (ibfd
));
4782 /* Identical flags must be compatible. */
4783 if (in_flags
== out_flags
)
4786 /* Check to see if the input BFD actually contains any sections. If
4787 not, its flags may not have been initialised either, but it
4788 cannot actually cause any incompatiblity. Do not short-circuit
4789 dynamic objects; their section list may be emptied by
4790 elf_link_add_object_symbols.
4792 Also check to see if there are no code sections in the input.
4793 In this case there is no need to check for code specific flags.
4794 XXX - do we need to worry about floating-point format compatability
4795 in data sections ? */
4796 if (!(ibfd
->flags
& DYNAMIC
))
4798 bfd_boolean null_input_bfd
= TRUE
;
4799 bfd_boolean only_data_sections
= TRUE
;
4801 for (sec
= ibfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
4803 if ((bfd_get_section_flags (ibfd
, sec
)
4804 & (SEC_LOAD
| SEC_CODE
| SEC_HAS_CONTENTS
))
4805 == (SEC_LOAD
| SEC_CODE
| SEC_HAS_CONTENTS
))
4806 only_data_sections
= FALSE
;
4808 null_input_bfd
= FALSE
;
4812 if (null_input_bfd
|| only_data_sections
)
4816 return flags_compatible
;
4819 /* Display the flags field. */
4822 elf64_aarch64_print_private_bfd_data (bfd
*abfd
, void *ptr
)
4824 FILE *file
= (FILE *) ptr
;
4825 unsigned long flags
;
4827 BFD_ASSERT (abfd
!= NULL
&& ptr
!= NULL
);
4829 /* Print normal ELF private data. */
4830 _bfd_elf_print_private_bfd_data (abfd
, ptr
);
4832 flags
= elf_elfheader (abfd
)->e_flags
;
4833 /* Ignore init flag - it may not be set, despite the flags field
4834 containing valid data. */
4836 /* xgettext:c-format */
4837 fprintf (file
, _("private flags = %lx:"), elf_elfheader (abfd
)->e_flags
);
4840 fprintf (file
, _("<Unrecognised flag bits set>"));
4847 /* Update the got entry reference counts for the section being removed. */
4850 elf64_aarch64_gc_sweep_hook (bfd
*abfd ATTRIBUTE_UNUSED
,
4851 struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
4852 asection
*sec ATTRIBUTE_UNUSED
,
4853 const Elf_Internal_Rela
*
4854 relocs ATTRIBUTE_UNUSED
)
4859 /* Adjust a symbol defined by a dynamic object and referenced by a
4860 regular object. The current definition is in some section of the
4861 dynamic object, but we're not including those sections. We have to
4862 change the definition to something the rest of the link can
4866 elf64_aarch64_adjust_dynamic_symbol (struct bfd_link_info
*info
,
4867 struct elf_link_hash_entry
*h
)
4869 struct elf64_aarch64_link_hash_table
*htab
;
4872 /* If this is a function, put it in the procedure linkage table. We
4873 will fill in the contents of the procedure linkage table later,
4874 when we know the address of the .got section. */
4875 if (h
->type
== STT_FUNC
|| h
->needs_plt
)
4877 if (h
->plt
.refcount
<= 0
4878 || SYMBOL_CALLS_LOCAL (info
, h
)
4879 || (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
4880 && h
->root
.type
== bfd_link_hash_undefweak
))
4882 /* This case can occur if we saw a CALL26 reloc in
4883 an input file, but the symbol wasn't referred to
4884 by a dynamic object or all references were
4885 garbage collected. In which case we can end up
4887 h
->plt
.offset
= (bfd_vma
) - 1;
4894 /* It's possible that we incorrectly decided a .plt reloc was
4895 needed for an R_X86_64_PC32 reloc to a non-function sym in
4896 check_relocs. We can't decide accurately between function and
4897 non-function syms in check-relocs; Objects loaded later in
4898 the link may change h->type. So fix it now. */
4899 h
->plt
.offset
= (bfd_vma
) - 1;
4902 /* If this is a weak symbol, and there is a real definition, the
4903 processor independent code will have arranged for us to see the
4904 real definition first, and we can just use the same value. */
4905 if (h
->u
.weakdef
!= NULL
)
4907 BFD_ASSERT (h
->u
.weakdef
->root
.type
== bfd_link_hash_defined
4908 || h
->u
.weakdef
->root
.type
== bfd_link_hash_defweak
);
4909 h
->root
.u
.def
.section
= h
->u
.weakdef
->root
.u
.def
.section
;
4910 h
->root
.u
.def
.value
= h
->u
.weakdef
->root
.u
.def
.value
;
4911 if (ELIMINATE_COPY_RELOCS
|| info
->nocopyreloc
)
4912 h
->non_got_ref
= h
->u
.weakdef
->non_got_ref
;
4916 /* If we are creating a shared library, we must presume that the
4917 only references to the symbol are via the global offset table.
4918 For such cases we need not do anything here; the relocations will
4919 be handled correctly by relocate_section. */
4923 /* If there are no references to this symbol that do not use the
4924 GOT, we don't need to generate a copy reloc. */
4925 if (!h
->non_got_ref
)
4928 /* If -z nocopyreloc was given, we won't generate them either. */
4929 if (info
->nocopyreloc
)
4935 /* We must allocate the symbol in our .dynbss section, which will
4936 become part of the .bss section of the executable. There will be
4937 an entry for this symbol in the .dynsym section. The dynamic
4938 object will contain position independent code, so all references
4939 from the dynamic object to this symbol will go through the global
4940 offset table. The dynamic linker will use the .dynsym entry to
4941 determine the address it must put in the global offset table, so
4942 both the dynamic object and the regular object will refer to the
4943 same memory location for the variable. */
4945 htab
= elf64_aarch64_hash_table (info
);
4947 /* We must generate a R_AARCH64_COPY reloc to tell the dynamic linker
4948 to copy the initial value out of the dynamic object and into the
4949 runtime process image. */
4950 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0 && h
->size
!= 0)
4952 htab
->srelbss
->size
+= RELOC_SIZE (htab
);
4958 return _bfd_elf_adjust_dynamic_copy (h
, s
);
4963 elf64_aarch64_allocate_local_symbols (bfd
*abfd
, unsigned number
)
4965 struct elf_aarch64_local_symbol
*locals
;
4966 locals
= elf64_aarch64_locals (abfd
);
4969 locals
= (struct elf_aarch64_local_symbol
*)
4970 bfd_zalloc (abfd
, number
* sizeof (struct elf_aarch64_local_symbol
));
4973 elf64_aarch64_locals (abfd
) = locals
;
4978 /* Look through the relocs for a section during the first phase. */
4981 elf64_aarch64_check_relocs (bfd
*abfd
, struct bfd_link_info
*info
,
4982 asection
*sec
, const Elf_Internal_Rela
*relocs
)
4984 Elf_Internal_Shdr
*symtab_hdr
;
4985 struct elf_link_hash_entry
**sym_hashes
;
4986 const Elf_Internal_Rela
*rel
;
4987 const Elf_Internal_Rela
*rel_end
;
4990 struct elf64_aarch64_link_hash_table
*htab
;
4992 unsigned long nsyms
;
4994 if (info
->relocatable
)
4997 BFD_ASSERT (is_aarch64_elf (abfd
));
4999 htab
= elf64_aarch64_hash_table (info
);
5002 symtab_hdr
= &elf_symtab_hdr (abfd
);
5003 sym_hashes
= elf_sym_hashes (abfd
);
5004 nsyms
= NUM_SHDR_ENTRIES (symtab_hdr
);
5006 rel_end
= relocs
+ sec
->reloc_count
;
5007 for (rel
= relocs
; rel
< rel_end
; rel
++)
5009 struct elf_link_hash_entry
*h
;
5010 unsigned long r_symndx
;
5011 unsigned int r_type
;
5013 r_symndx
= ELF64_R_SYM (rel
->r_info
);
5014 r_type
= ELF64_R_TYPE (rel
->r_info
);
5016 if (r_symndx
>= NUM_SHDR_ENTRIES (symtab_hdr
))
5018 (*_bfd_error_handler
) (_("%B: bad symbol index: %d"), abfd
,
5023 if (r_symndx
>= nsyms
5024 /* PR 9934: It is possible to have relocations that do not
5025 refer to symbols, thus it is also possible to have an
5026 object file containing relocations but no symbol table. */
5027 && (r_symndx
> 0 || nsyms
> 0))
5029 (*_bfd_error_handler
) (_("%B: bad symbol index: %d"), abfd
,
5034 if (nsyms
== 0 || r_symndx
< symtab_hdr
->sh_info
)
5038 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
5039 while (h
->root
.type
== bfd_link_hash_indirect
5040 || h
->root
.type
== bfd_link_hash_warning
)
5041 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
5044 /* Could be done earlier, if h were already available. */
5045 r_type
= aarch64_tls_transition (abfd
, info
, r_type
, h
, r_symndx
);
5049 case R_AARCH64_ABS64
:
5051 /* We don't need to handle relocs into sections not going into
5052 the "real" output. */
5053 if ((sec
->flags
& SEC_ALLOC
) == 0)
5061 h
->plt
.refcount
+= 1;
5062 h
->pointer_equality_needed
= 1;
5065 /* No need to do anything if we're not creating a shared
5071 struct elf_dyn_relocs
*p
;
5072 struct elf_dyn_relocs
**head
;
5074 /* We must copy these reloc types into the output file.
5075 Create a reloc section in dynobj and make room for
5079 if (htab
->root
.dynobj
== NULL
)
5080 htab
->root
.dynobj
= abfd
;
5082 sreloc
= _bfd_elf_make_dynamic_reloc_section
5083 (sec
, htab
->root
.dynobj
, 3, abfd
, /*rela? */ TRUE
);
5089 /* If this is a global symbol, we count the number of
5090 relocations we need for this symbol. */
5093 struct elf64_aarch64_link_hash_entry
*eh
;
5094 eh
= (struct elf64_aarch64_link_hash_entry
*) h
;
5095 head
= &eh
->dyn_relocs
;
5099 /* Track dynamic relocs needed for local syms too.
5100 We really need local syms available to do this
5105 Elf_Internal_Sym
*isym
;
5107 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
5112 s
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
5116 /* Beware of type punned pointers vs strict aliasing
5118 vpp
= &(elf_section_data (s
)->local_dynrel
);
5119 head
= (struct elf_dyn_relocs
**) vpp
;
5123 if (p
== NULL
|| p
->sec
!= sec
)
5125 bfd_size_type amt
= sizeof *p
;
5126 p
= ((struct elf_dyn_relocs
*)
5127 bfd_zalloc (htab
->root
.dynobj
, amt
));
5140 /* RR: We probably want to keep a consistency check that
5141 there are no dangling GOT_PAGE relocs. */
5142 case R_AARCH64_LD64_GOT_LO12_NC
:
5143 case R_AARCH64_GOT_LD_PREL19
:
5144 case R_AARCH64_ADR_GOT_PAGE
:
5145 case R_AARCH64_TLSGD_ADR_PAGE21
:
5146 case R_AARCH64_TLSGD_ADD_LO12_NC
:
5147 case R_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21
:
5148 case R_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC
:
5149 case R_AARCH64_TLSLE_ADD_TPREL_LO12
:
5150 case R_AARCH64_TLSLE_ADD_TPREL_HI12
:
5151 case R_AARCH64_TLSLE_ADD_TPREL_LO12_NC
:
5152 case R_AARCH64_TLSLE_MOVW_TPREL_G2
:
5153 case R_AARCH64_TLSLE_MOVW_TPREL_G1
:
5154 case R_AARCH64_TLSLE_MOVW_TPREL_G1_NC
:
5155 case R_AARCH64_TLSLE_MOVW_TPREL_G0
:
5156 case R_AARCH64_TLSLE_MOVW_TPREL_G0_NC
:
5157 case R_AARCH64_TLSDESC_ADR_PAGE
:
5158 case R_AARCH64_TLSDESC_ADD_LO12_NC
:
5159 case R_AARCH64_TLSDESC_LD64_LO12_NC
:
5162 unsigned old_got_type
;
5164 got_type
= aarch64_reloc_got_type (r_type
);
5168 h
->got
.refcount
+= 1;
5169 old_got_type
= elf64_aarch64_hash_entry (h
)->got_type
;
5173 struct elf_aarch64_local_symbol
*locals
;
5175 if (!elf64_aarch64_allocate_local_symbols
5176 (abfd
, symtab_hdr
->sh_info
))
5179 locals
= elf64_aarch64_locals (abfd
);
5180 BFD_ASSERT (r_symndx
< symtab_hdr
->sh_info
);
5181 locals
[r_symndx
].got_refcount
+= 1;
5182 old_got_type
= locals
[r_symndx
].got_type
;
5185 /* If a variable is accessed with both general dynamic TLS
5186 methods, two slots may be created. */
5187 if (GOT_TLS_GD_ANY_P (old_got_type
) && GOT_TLS_GD_ANY_P (got_type
))
5188 got_type
|= old_got_type
;
5190 /* We will already have issued an error message if there
5191 is a TLS/non-TLS mismatch, based on the symbol type.
5192 So just combine any TLS types needed. */
5193 if (old_got_type
!= GOT_UNKNOWN
&& old_got_type
!= GOT_NORMAL
5194 && got_type
!= GOT_NORMAL
)
5195 got_type
|= old_got_type
;
5197 /* If the symbol is accessed by both IE and GD methods, we
5198 are able to relax. Turn off the GD flag, without
5199 messing up with any other kind of TLS types that may be
5201 if ((got_type
& GOT_TLS_IE
) && GOT_TLS_GD_ANY_P (got_type
))
5202 got_type
&= ~ (GOT_TLSDESC_GD
| GOT_TLS_GD
);
5204 if (old_got_type
!= got_type
)
5207 elf64_aarch64_hash_entry (h
)->got_type
= got_type
;
5210 struct elf_aarch64_local_symbol
*locals
;
5211 locals
= elf64_aarch64_locals (abfd
);
5212 BFD_ASSERT (r_symndx
< symtab_hdr
->sh_info
);
5213 locals
[r_symndx
].got_type
= got_type
;
5217 if (htab
->root
.sgot
== NULL
)
5219 if (htab
->root
.dynobj
== NULL
)
5220 htab
->root
.dynobj
= abfd
;
5221 if (!_bfd_elf_create_got_section (htab
->root
.dynobj
, info
))
5227 case R_AARCH64_ADR_PREL_PG_HI21_NC
:
5228 case R_AARCH64_ADR_PREL_PG_HI21
:
5229 case R_AARCH64_ADR_PREL_LO21
:
5230 if (h
!= NULL
&& info
->executable
)
5232 /* If this reloc is in a read-only section, we might
5233 need a copy reloc. We can't check reliably at this
5234 stage whether the section is read-only, as input
5235 sections have not yet been mapped to output sections.
5236 Tentatively set the flag for now, and correct in
5237 adjust_dynamic_symbol. */
5239 h
->plt
.refcount
+= 1;
5240 h
->pointer_equality_needed
= 1;
5242 /* FIXME:: RR need to handle these in shared libraries
5243 and essentially bomb out as these being non-PIC
5244 relocations in shared libraries. */
5247 case R_AARCH64_CALL26
:
5248 case R_AARCH64_JUMP26
:
5249 /* If this is a local symbol then we resolve it
5250 directly without creating a PLT entry. */
5255 h
->plt
.refcount
+= 1;
5262 /* Treat mapping symbols as special target symbols. */
5265 elf64_aarch64_is_target_special_symbol (bfd
*abfd ATTRIBUTE_UNUSED
,
5268 return bfd_is_aarch64_special_symbol_name (sym
->name
,
5269 BFD_AARCH64_SPECIAL_SYM_TYPE_ANY
);
5272 /* This is a copy of elf_find_function () from elf.c except that
5273 AArch64 mapping symbols are ignored when looking for function names. */
5276 aarch64_elf_find_function (bfd
*abfd ATTRIBUTE_UNUSED
,
5280 const char **filename_ptr
,
5281 const char **functionname_ptr
)
5283 const char *filename
= NULL
;
5284 asymbol
*func
= NULL
;
5285 bfd_vma low_func
= 0;
5288 for (p
= symbols
; *p
!= NULL
; p
++)
5292 q
= (elf_symbol_type
*) * p
;
5294 switch (ELF_ST_TYPE (q
->internal_elf_sym
.st_info
))
5299 filename
= bfd_asymbol_name (&q
->symbol
);
5303 /* Skip mapping symbols. */
5304 if ((q
->symbol
.flags
& BSF_LOCAL
)
5305 && (bfd_is_aarch64_special_symbol_name
5306 (q
->symbol
.name
, BFD_AARCH64_SPECIAL_SYM_TYPE_ANY
)))
5309 if (bfd_get_section (&q
->symbol
) == section
5310 && q
->symbol
.value
>= low_func
&& q
->symbol
.value
<= offset
)
5312 func
= (asymbol
*) q
;
5313 low_func
= q
->symbol
.value
;
5323 *filename_ptr
= filename
;
5324 if (functionname_ptr
)
5325 *functionname_ptr
= bfd_asymbol_name (func
);
5331 /* Find the nearest line to a particular section and offset, for error
5332 reporting. This code is a duplicate of the code in elf.c, except
5333 that it uses aarch64_elf_find_function. */
5336 elf64_aarch64_find_nearest_line (bfd
*abfd
,
5340 const char **filename_ptr
,
5341 const char **functionname_ptr
,
5342 unsigned int *line_ptr
)
5344 bfd_boolean found
= FALSE
;
5346 /* We skip _bfd_dwarf1_find_nearest_line since no known AArch64
5347 toolchain uses it. */
5349 if (_bfd_dwarf2_find_nearest_line (abfd
, dwarf_debug_sections
,
5350 section
, symbols
, offset
,
5351 filename_ptr
, functionname_ptr
,
5353 &elf_tdata (abfd
)->dwarf2_find_line_info
))
5355 if (!*functionname_ptr
)
5356 aarch64_elf_find_function (abfd
, section
, symbols
, offset
,
5357 *filename_ptr
? NULL
: filename_ptr
,
5363 if (!_bfd_stab_section_find_nearest_line (abfd
, symbols
, section
, offset
,
5364 &found
, filename_ptr
,
5365 functionname_ptr
, line_ptr
,
5366 &elf_tdata (abfd
)->line_info
))
5369 if (found
&& (*functionname_ptr
|| *line_ptr
))
5372 if (symbols
== NULL
)
5375 if (!aarch64_elf_find_function (abfd
, section
, symbols
, offset
,
5376 filename_ptr
, functionname_ptr
))
5384 elf64_aarch64_find_inliner_info (bfd
*abfd
,
5385 const char **filename_ptr
,
5386 const char **functionname_ptr
,
5387 unsigned int *line_ptr
)
5390 found
= _bfd_dwarf2_find_inliner_info
5391 (abfd
, filename_ptr
,
5392 functionname_ptr
, line_ptr
, &elf_tdata (abfd
)->dwarf2_find_line_info
);
5398 elf64_aarch64_post_process_headers (bfd
*abfd
,
5399 struct bfd_link_info
*link_info
5402 Elf_Internal_Ehdr
*i_ehdrp
; /* ELF file header, internal form. */
5404 i_ehdrp
= elf_elfheader (abfd
);
5405 i_ehdrp
->e_ident
[EI_OSABI
] = 0;
5406 i_ehdrp
->e_ident
[EI_ABIVERSION
] = AARCH64_ELF_ABI_VERSION
;
5409 static enum elf_reloc_type_class
5410 elf64_aarch64_reloc_type_class (const Elf_Internal_Rela
*rela
)
5412 switch ((int) ELF64_R_TYPE (rela
->r_info
))
5414 case R_AARCH64_RELATIVE
:
5415 return reloc_class_relative
;
5416 case R_AARCH64_JUMP_SLOT
:
5417 return reloc_class_plt
;
5418 case R_AARCH64_COPY
:
5419 return reloc_class_copy
;
5421 return reloc_class_normal
;
5425 /* Set the right machine number for an AArch64 ELF file. */
5428 elf64_aarch64_section_flags (flagword
*flags
, const Elf_Internal_Shdr
*hdr
)
5430 if (hdr
->sh_type
== SHT_NOTE
)
5431 *flags
|= SEC_LINK_ONCE
| SEC_LINK_DUPLICATES_SAME_CONTENTS
;
5436 /* Handle an AArch64 specific section when reading an object file. This is
5437 called when bfd_section_from_shdr finds a section with an unknown
5441 elf64_aarch64_section_from_shdr (bfd
*abfd
,
5442 Elf_Internal_Shdr
*hdr
,
5443 const char *name
, int shindex
)
5445 /* There ought to be a place to keep ELF backend specific flags, but
5446 at the moment there isn't one. We just keep track of the
5447 sections by their name, instead. Fortunately, the ABI gives
5448 names for all the AArch64 specific sections, so we will probably get
5450 switch (hdr
->sh_type
)
5452 case SHT_AARCH64_ATTRIBUTES
:
5459 if (!_bfd_elf_make_section_from_shdr (abfd
, hdr
, name
, shindex
))
5465 /* A structure used to record a list of sections, independently
5466 of the next and prev fields in the asection structure. */
5467 typedef struct section_list
5470 struct section_list
*next
;
5471 struct section_list
*prev
;
5475 /* Unfortunately we need to keep a list of sections for which
5476 an _aarch64_elf_section_data structure has been allocated. This
5477 is because it is possible for functions like elf64_aarch64_write_section
5478 to be called on a section which has had an elf_data_structure
5479 allocated for it (and so the used_by_bfd field is valid) but
5480 for which the AArch64 extended version of this structure - the
5481 _aarch64_elf_section_data structure - has not been allocated. */
5482 static section_list
*sections_with_aarch64_elf_section_data
= NULL
;
5485 record_section_with_aarch64_elf_section_data (asection
*sec
)
5487 struct section_list
*entry
;
5489 entry
= bfd_malloc (sizeof (*entry
));
5493 entry
->next
= sections_with_aarch64_elf_section_data
;
5495 if (entry
->next
!= NULL
)
5496 entry
->next
->prev
= entry
;
5497 sections_with_aarch64_elf_section_data
= entry
;
5500 static struct section_list
*
5501 find_aarch64_elf_section_entry (asection
*sec
)
5503 struct section_list
*entry
;
5504 static struct section_list
*last_entry
= NULL
;
5506 /* This is a short cut for the typical case where the sections are added
5507 to the sections_with_aarch64_elf_section_data list in forward order and
5508 then looked up here in backwards order. This makes a real difference
5509 to the ld-srec/sec64k.exp linker test. */
5510 entry
= sections_with_aarch64_elf_section_data
;
5511 if (last_entry
!= NULL
)
5513 if (last_entry
->sec
== sec
)
5515 else if (last_entry
->next
!= NULL
&& last_entry
->next
->sec
== sec
)
5516 entry
= last_entry
->next
;
5519 for (; entry
; entry
= entry
->next
)
5520 if (entry
->sec
== sec
)
5524 /* Record the entry prior to this one - it is the entry we are
5525 most likely to want to locate next time. Also this way if we
5526 have been called from
5527 unrecord_section_with_aarch64_elf_section_data () we will not
5528 be caching a pointer that is about to be freed. */
5529 last_entry
= entry
->prev
;
5535 unrecord_section_with_aarch64_elf_section_data (asection
*sec
)
5537 struct section_list
*entry
;
5539 entry
= find_aarch64_elf_section_entry (sec
);
5543 if (entry
->prev
!= NULL
)
5544 entry
->prev
->next
= entry
->next
;
5545 if (entry
->next
!= NULL
)
5546 entry
->next
->prev
= entry
->prev
;
5547 if (entry
== sections_with_aarch64_elf_section_data
)
5548 sections_with_aarch64_elf_section_data
= entry
->next
;
5557 struct bfd_link_info
*info
;
5560 int (*func
) (void *, const char *, Elf_Internal_Sym
*,
5561 asection
*, struct elf_link_hash_entry
*);
5562 } output_arch_syminfo
;
5564 enum map_symbol_type
5571 /* Output a single mapping symbol. */
5574 elf64_aarch64_output_map_sym (output_arch_syminfo
*osi
,
5575 enum map_symbol_type type
, bfd_vma offset
)
5577 static const char *names
[2] = { "$x", "$d" };
5578 Elf_Internal_Sym sym
;
5580 sym
.st_value
= (osi
->sec
->output_section
->vma
5581 + osi
->sec
->output_offset
+ offset
);
5584 sym
.st_info
= ELF_ST_INFO (STB_LOCAL
, STT_NOTYPE
);
5585 sym
.st_shndx
= osi
->sec_shndx
;
5586 return osi
->func (osi
->finfo
, names
[type
], &sym
, osi
->sec
, NULL
) == 1;
5591 /* Output mapping symbols for PLT entries associated with H. */
5594 elf64_aarch64_output_plt_map (struct elf_link_hash_entry
*h
, void *inf
)
5596 output_arch_syminfo
*osi
= (output_arch_syminfo
*) inf
;
5599 if (h
->root
.type
== bfd_link_hash_indirect
)
5602 if (h
->root
.type
== bfd_link_hash_warning
)
5603 /* When warning symbols are created, they **replace** the "real"
5604 entry in the hash table, thus we never get to see the real
5605 symbol in a hash traversal. So look at it now. */
5606 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
5608 if (h
->plt
.offset
== (bfd_vma
) - 1)
5611 addr
= h
->plt
.offset
;
5614 if (!elf64_aarch64_output_map_sym (osi
, AARCH64_MAP_INSN
, addr
))
5621 /* Output a single local symbol for a generated stub. */
5624 elf64_aarch64_output_stub_sym (output_arch_syminfo
*osi
, const char *name
,
5625 bfd_vma offset
, bfd_vma size
)
5627 Elf_Internal_Sym sym
;
5629 sym
.st_value
= (osi
->sec
->output_section
->vma
5630 + osi
->sec
->output_offset
+ offset
);
5633 sym
.st_info
= ELF_ST_INFO (STB_LOCAL
, STT_FUNC
);
5634 sym
.st_shndx
= osi
->sec_shndx
;
5635 return osi
->func (osi
->finfo
, name
, &sym
, osi
->sec
, NULL
) == 1;
5639 aarch64_map_one_stub (struct bfd_hash_entry
*gen_entry
, void *in_arg
)
5641 struct elf64_aarch64_stub_hash_entry
*stub_entry
;
5645 output_arch_syminfo
*osi
;
5647 /* Massage our args to the form they really have. */
5648 stub_entry
= (struct elf64_aarch64_stub_hash_entry
*) gen_entry
;
5649 osi
= (output_arch_syminfo
*) in_arg
;
5651 stub_sec
= stub_entry
->stub_sec
;
5653 /* Ensure this stub is attached to the current section being
5655 if (stub_sec
!= osi
->sec
)
5658 addr
= (bfd_vma
) stub_entry
->stub_offset
;
5660 stub_name
= stub_entry
->output_name
;
5662 switch (stub_entry
->stub_type
)
5664 case aarch64_stub_adrp_branch
:
5665 if (!elf64_aarch64_output_stub_sym (osi
, stub_name
, addr
,
5666 sizeof (aarch64_adrp_branch_stub
)))
5668 if (!elf64_aarch64_output_map_sym (osi
, AARCH64_MAP_INSN
, addr
))
5671 case aarch64_stub_long_branch
:
5672 if (!elf64_aarch64_output_stub_sym
5673 (osi
, stub_name
, addr
, sizeof (aarch64_long_branch_stub
)))
5675 if (!elf64_aarch64_output_map_sym (osi
, AARCH64_MAP_INSN
, addr
))
5677 if (!elf64_aarch64_output_map_sym (osi
, AARCH64_MAP_DATA
, addr
+ 16))
5687 /* Output mapping symbols for linker generated sections. */
5690 elf64_aarch64_output_arch_local_syms (bfd
*output_bfd
,
5691 struct bfd_link_info
*info
,
5693 int (*func
) (void *, const char *,
5696 struct elf_link_hash_entry
5699 output_arch_syminfo osi
;
5700 struct elf64_aarch64_link_hash_table
*htab
;
5702 htab
= elf64_aarch64_hash_table (info
);
5708 /* Long calls stubs. */
5709 if (htab
->stub_bfd
&& htab
->stub_bfd
->sections
)
5713 for (stub_sec
= htab
->stub_bfd
->sections
;
5714 stub_sec
!= NULL
; stub_sec
= stub_sec
->next
)
5716 /* Ignore non-stub sections. */
5717 if (!strstr (stub_sec
->name
, STUB_SUFFIX
))
5722 osi
.sec_shndx
= _bfd_elf_section_from_bfd_section
5723 (output_bfd
, osi
.sec
->output_section
);
5725 bfd_hash_traverse (&htab
->stub_hash_table
, aarch64_map_one_stub
,
5730 /* Finally, output mapping symbols for the PLT. */
5731 if (!htab
->root
.splt
|| htab
->root
.splt
->size
== 0)
5734 /* For now live without mapping symbols for the plt. */
5735 osi
.sec_shndx
= _bfd_elf_section_from_bfd_section
5736 (output_bfd
, htab
->root
.splt
->output_section
);
5737 osi
.sec
= htab
->root
.splt
;
5739 elf_link_hash_traverse (&htab
->root
, elf64_aarch64_output_plt_map
,
5746 /* Allocate target specific section data. */
5749 elf64_aarch64_new_section_hook (bfd
*abfd
, asection
*sec
)
5751 if (!sec
->used_by_bfd
)
5753 _aarch64_elf_section_data
*sdata
;
5754 bfd_size_type amt
= sizeof (*sdata
);
5756 sdata
= bfd_zalloc (abfd
, amt
);
5759 sec
->used_by_bfd
= sdata
;
5762 record_section_with_aarch64_elf_section_data (sec
);
5764 return _bfd_elf_new_section_hook (abfd
, sec
);
5769 unrecord_section_via_map_over_sections (bfd
*abfd ATTRIBUTE_UNUSED
,
5771 void *ignore ATTRIBUTE_UNUSED
)
5773 unrecord_section_with_aarch64_elf_section_data (sec
);
5777 elf64_aarch64_close_and_cleanup (bfd
*abfd
)
5780 bfd_map_over_sections (abfd
,
5781 unrecord_section_via_map_over_sections
, NULL
);
5783 return _bfd_elf_close_and_cleanup (abfd
);
5787 elf64_aarch64_bfd_free_cached_info (bfd
*abfd
)
5790 bfd_map_over_sections (abfd
,
5791 unrecord_section_via_map_over_sections
, NULL
);
5793 return _bfd_free_cached_info (abfd
);
5797 elf64_aarch64_is_function_type (unsigned int type
)
5799 return type
== STT_FUNC
;
5802 /* Create dynamic sections. This is different from the ARM backend in that
5803 the got, plt, gotplt and their relocation sections are all created in the
5804 standard part of the bfd elf backend. */
5807 elf64_aarch64_create_dynamic_sections (bfd
*dynobj
,
5808 struct bfd_link_info
*info
)
5810 struct elf64_aarch64_link_hash_table
*htab
;
5811 struct elf_link_hash_entry
*h
;
5813 if (!_bfd_elf_create_dynamic_sections (dynobj
, info
))
5816 htab
= elf64_aarch64_hash_table (info
);
5817 htab
->sdynbss
= bfd_get_linker_section (dynobj
, ".dynbss");
5819 htab
->srelbss
= bfd_get_linker_section (dynobj
, ".rela.bss");
5821 if (!htab
->sdynbss
|| (!info
->shared
&& !htab
->srelbss
))
5824 /* Define the symbol _GLOBAL_OFFSET_TABLE_ at the start of the
5825 dynobj's .got section. We don't do this in the linker script
5826 because we don't want to define the symbol if we are not creating
5827 a global offset table. */
5828 h
= _bfd_elf_define_linkage_sym (dynobj
, info
,
5829 htab
->root
.sgot
, "_GLOBAL_OFFSET_TABLE_");
5830 elf_hash_table (info
)->hgot
= h
;
5838 /* Allocate space in .plt, .got and associated reloc sections for
5842 elf64_aarch64_allocate_dynrelocs (struct elf_link_hash_entry
*h
, void *inf
)
5844 struct bfd_link_info
*info
;
5845 struct elf64_aarch64_link_hash_table
*htab
;
5846 struct elf64_aarch64_link_hash_entry
*eh
;
5847 struct elf_dyn_relocs
*p
;
5849 /* An example of a bfd_link_hash_indirect symbol is versioned
5850 symbol. For example: __gxx_personality_v0(bfd_link_hash_indirect)
5851 -> __gxx_personality_v0(bfd_link_hash_defined)
5853 There is no need to process bfd_link_hash_indirect symbols here
5854 because we will also be presented with the concrete instance of
5855 the symbol and elf64_aarch64_copy_indirect_symbol () will have been
5856 called to copy all relevant data from the generic to the concrete
5859 if (h
->root
.type
== bfd_link_hash_indirect
)
5862 if (h
->root
.type
== bfd_link_hash_warning
)
5863 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
5865 info
= (struct bfd_link_info
*) inf
;
5866 htab
= elf64_aarch64_hash_table (info
);
5868 if (htab
->root
.dynamic_sections_created
&& h
->plt
.refcount
> 0)
5870 /* Make sure this symbol is output as a dynamic symbol.
5871 Undefined weak syms won't yet be marked as dynamic. */
5872 if (h
->dynindx
== -1 && !h
->forced_local
)
5874 if (!bfd_elf_link_record_dynamic_symbol (info
, h
))
5878 if (info
->shared
|| WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h
))
5880 asection
*s
= htab
->root
.splt
;
5882 /* If this is the first .plt entry, make room for the special
5885 s
->size
+= htab
->plt_header_size
;
5887 h
->plt
.offset
= s
->size
;
5889 /* If this symbol is not defined in a regular file, and we are
5890 not generating a shared library, then set the symbol to this
5891 location in the .plt. This is required to make function
5892 pointers compare as equal between the normal executable and
5893 the shared library. */
5894 if (!info
->shared
&& !h
->def_regular
)
5896 h
->root
.u
.def
.section
= s
;
5897 h
->root
.u
.def
.value
= h
->plt
.offset
;
5900 /* Make room for this entry. For now we only create the
5901 small model PLT entries. We later need to find a way
5902 of relaxing into these from the large model PLT entries. */
5903 s
->size
+= PLT_SMALL_ENTRY_SIZE
;
5905 /* We also need to make an entry in the .got.plt section, which
5906 will be placed in the .got section by the linker script. */
5907 htab
->root
.sgotplt
->size
+= GOT_ENTRY_SIZE
;
5909 /* We also need to make an entry in the .rela.plt section. */
5910 htab
->root
.srelplt
->size
+= RELOC_SIZE (htab
);
5912 /* We need to ensure that all GOT entries that serve the PLT
5913 are consecutive with the special GOT slots [0] [1] and
5914 [2]. Any addtional relocations, such as
5915 R_AARCH64_TLSDESC, must be placed after the PLT related
5916 entries. We abuse the reloc_count such that during
5917 sizing we adjust reloc_count to indicate the number of
5918 PLT related reserved entries. In subsequent phases when
5919 filling in the contents of the reloc entries, PLT related
5920 entries are placed by computing their PLT index (0
5921 .. reloc_count). While other none PLT relocs are placed
5922 at the slot indicated by reloc_count and reloc_count is
5925 htab
->root
.srelplt
->reloc_count
++;
5929 h
->plt
.offset
= (bfd_vma
) - 1;
5935 h
->plt
.offset
= (bfd_vma
) - 1;
5939 eh
= (struct elf64_aarch64_link_hash_entry
*) h
;
5940 eh
->tlsdesc_got_jump_table_offset
= (bfd_vma
) - 1;
5942 if (h
->got
.refcount
> 0)
5945 unsigned got_type
= elf64_aarch64_hash_entry (h
)->got_type
;
5947 h
->got
.offset
= (bfd_vma
) - 1;
5949 dyn
= htab
->root
.dynamic_sections_created
;
5951 /* Make sure this symbol is output as a dynamic symbol.
5952 Undefined weak syms won't yet be marked as dynamic. */
5953 if (dyn
&& h
->dynindx
== -1 && !h
->forced_local
)
5955 if (!bfd_elf_link_record_dynamic_symbol (info
, h
))
5959 if (got_type
== GOT_UNKNOWN
)
5962 else if (got_type
== GOT_NORMAL
)
5964 h
->got
.offset
= htab
->root
.sgot
->size
;
5965 htab
->root
.sgot
->size
+= GOT_ENTRY_SIZE
;
5966 if ((ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
5967 || h
->root
.type
!= bfd_link_hash_undefweak
)
5969 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, 0, h
)))
5971 htab
->root
.srelgot
->size
+= RELOC_SIZE (htab
);
5977 if (got_type
& GOT_TLSDESC_GD
)
5979 eh
->tlsdesc_got_jump_table_offset
=
5980 (htab
->root
.sgotplt
->size
5981 - aarch64_compute_jump_table_size (htab
));
5982 htab
->root
.sgotplt
->size
+= GOT_ENTRY_SIZE
* 2;
5983 h
->got
.offset
= (bfd_vma
) - 2;
5986 if (got_type
& GOT_TLS_GD
)
5988 h
->got
.offset
= htab
->root
.sgot
->size
;
5989 htab
->root
.sgot
->size
+= GOT_ENTRY_SIZE
* 2;
5992 if (got_type
& GOT_TLS_IE
)
5994 h
->got
.offset
= htab
->root
.sgot
->size
;
5995 htab
->root
.sgot
->size
+= GOT_ENTRY_SIZE
;
5998 indx
= h
&& h
->dynindx
!= -1 ? h
->dynindx
: 0;
5999 if ((ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
6000 || h
->root
.type
!= bfd_link_hash_undefweak
)
6003 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, 0, h
)))
6005 if (got_type
& GOT_TLSDESC_GD
)
6007 htab
->root
.srelplt
->size
+= RELOC_SIZE (htab
);
6008 /* Note reloc_count not incremented here! We have
6009 already adjusted reloc_count for this relocation
6012 /* TLSDESC PLT is now needed, but not yet determined. */
6013 htab
->tlsdesc_plt
= (bfd_vma
) - 1;
6016 if (got_type
& GOT_TLS_GD
)
6017 htab
->root
.srelgot
->size
+= RELOC_SIZE (htab
) * 2;
6019 if (got_type
& GOT_TLS_IE
)
6020 htab
->root
.srelgot
->size
+= RELOC_SIZE (htab
);
6026 h
->got
.offset
= (bfd_vma
) - 1;
6029 if (eh
->dyn_relocs
== NULL
)
6032 /* In the shared -Bsymbolic case, discard space allocated for
6033 dynamic pc-relative relocs against symbols which turn out to be
6034 defined in regular objects. For the normal shared case, discard
6035 space for pc-relative relocs that have become local due to symbol
6036 visibility changes. */
6040 /* Relocs that use pc_count are those that appear on a call
6041 insn, or certain REL relocs that can generated via assembly.
6042 We want calls to protected symbols to resolve directly to the
6043 function rather than going via the plt. If people want
6044 function pointer comparisons to work as expected then they
6045 should avoid writing weird assembly. */
6046 if (SYMBOL_CALLS_LOCAL (info
, h
))
6048 struct elf_dyn_relocs
**pp
;
6050 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
;)
6052 p
->count
-= p
->pc_count
;
6061 /* Also discard relocs on undefined weak syms with non-default
6063 if (eh
->dyn_relocs
!= NULL
&& h
->root
.type
== bfd_link_hash_undefweak
)
6065 if (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
)
6066 eh
->dyn_relocs
= NULL
;
6068 /* Make sure undefined weak symbols are output as a dynamic
6070 else if (h
->dynindx
== -1
6072 && !bfd_elf_link_record_dynamic_symbol (info
, h
))
6077 else if (ELIMINATE_COPY_RELOCS
)
6079 /* For the non-shared case, discard space for relocs against
6080 symbols which turn out to need copy relocs or are not
6086 || (htab
->root
.dynamic_sections_created
6087 && (h
->root
.type
== bfd_link_hash_undefweak
6088 || h
->root
.type
== bfd_link_hash_undefined
))))
6090 /* Make sure this symbol is output as a dynamic symbol.
6091 Undefined weak syms won't yet be marked as dynamic. */
6092 if (h
->dynindx
== -1
6094 && !bfd_elf_link_record_dynamic_symbol (info
, h
))
6097 /* If that succeeded, we know we'll be keeping all the
6099 if (h
->dynindx
!= -1)
6103 eh
->dyn_relocs
= NULL
;
6108 /* Finally, allocate space. */
6109 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
6113 sreloc
= elf_section_data (p
->sec
)->sreloc
;
6115 BFD_ASSERT (sreloc
!= NULL
);
6117 sreloc
->size
+= p
->count
* RELOC_SIZE (htab
);
6126 /* This is the most important function of all . Innocuosly named
6129 elf64_aarch64_size_dynamic_sections (bfd
*output_bfd ATTRIBUTE_UNUSED
,
6130 struct bfd_link_info
*info
)
6132 struct elf64_aarch64_link_hash_table
*htab
;
6138 htab
= elf64_aarch64_hash_table ((info
));
6139 dynobj
= htab
->root
.dynobj
;
6141 BFD_ASSERT (dynobj
!= NULL
);
6143 if (htab
->root
.dynamic_sections_created
)
6145 if (info
->executable
)
6147 s
= bfd_get_linker_section (dynobj
, ".interp");
6150 s
->size
= sizeof ELF_DYNAMIC_INTERPRETER
;
6151 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
6155 /* Set up .got offsets for local syms, and space for local dynamic
6157 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link_next
)
6159 struct elf_aarch64_local_symbol
*locals
= NULL
;
6160 Elf_Internal_Shdr
*symtab_hdr
;
6164 if (!is_aarch64_elf (ibfd
))
6167 for (s
= ibfd
->sections
; s
!= NULL
; s
= s
->next
)
6169 struct elf_dyn_relocs
*p
;
6171 for (p
= (struct elf_dyn_relocs
*)
6172 (elf_section_data (s
)->local_dynrel
); p
!= NULL
; p
= p
->next
)
6174 if (!bfd_is_abs_section (p
->sec
)
6175 && bfd_is_abs_section (p
->sec
->output_section
))
6177 /* Input section has been discarded, either because
6178 it is a copy of a linkonce section or due to
6179 linker script /DISCARD/, so we'll be discarding
6182 else if (p
->count
!= 0)
6184 srel
= elf_section_data (p
->sec
)->sreloc
;
6185 srel
->size
+= p
->count
* RELOC_SIZE (htab
);
6186 if ((p
->sec
->output_section
->flags
& SEC_READONLY
) != 0)
6187 info
->flags
|= DF_TEXTREL
;
6192 locals
= elf64_aarch64_locals (ibfd
);
6196 symtab_hdr
= &elf_symtab_hdr (ibfd
);
6197 srel
= htab
->root
.srelgot
;
6198 for (i
= 0; i
< symtab_hdr
->sh_info
; i
++)
6200 locals
[i
].got_offset
= (bfd_vma
) - 1;
6201 locals
[i
].tlsdesc_got_jump_table_offset
= (bfd_vma
) - 1;
6202 if (locals
[i
].got_refcount
> 0)
6204 unsigned got_type
= locals
[i
].got_type
;
6205 if (got_type
& GOT_TLSDESC_GD
)
6207 locals
[i
].tlsdesc_got_jump_table_offset
=
6208 (htab
->root
.sgotplt
->size
6209 - aarch64_compute_jump_table_size (htab
));
6210 htab
->root
.sgotplt
->size
+= GOT_ENTRY_SIZE
* 2;
6211 locals
[i
].got_offset
= (bfd_vma
) - 2;
6214 if (got_type
& GOT_TLS_GD
)
6216 locals
[i
].got_offset
= htab
->root
.sgot
->size
;
6217 htab
->root
.sgot
->size
+= GOT_ENTRY_SIZE
* 2;
6220 if (got_type
& GOT_TLS_IE
)
6222 locals
[i
].got_offset
= htab
->root
.sgot
->size
;
6223 htab
->root
.sgot
->size
+= GOT_ENTRY_SIZE
;
6226 if (got_type
== GOT_UNKNOWN
)
6230 if (got_type
== GOT_NORMAL
)
6236 if (got_type
& GOT_TLSDESC_GD
)
6238 htab
->root
.srelplt
->size
+= RELOC_SIZE (htab
);
6239 /* Note RELOC_COUNT not incremented here! */
6240 htab
->tlsdesc_plt
= (bfd_vma
) - 1;
6243 if (got_type
& GOT_TLS_GD
)
6244 htab
->root
.srelgot
->size
+= RELOC_SIZE (htab
) * 2;
6246 if (got_type
& GOT_TLS_IE
)
6247 htab
->root
.srelgot
->size
+= RELOC_SIZE (htab
);
6252 locals
[i
].got_refcount
= (bfd_vma
) - 1;
6258 /* Allocate global sym .plt and .got entries, and space for global
6259 sym dynamic relocs. */
6260 elf_link_hash_traverse (&htab
->root
, elf64_aarch64_allocate_dynrelocs
,
6264 /* For every jump slot reserved in the sgotplt, reloc_count is
6265 incremented. However, when we reserve space for TLS descriptors,
6266 it's not incremented, so in order to compute the space reserved
6267 for them, it suffices to multiply the reloc count by the jump
6270 if (htab
->root
.srelplt
)
6271 htab
->sgotplt_jump_table_size
= aarch64_compute_jump_table_size (htab
);
6273 if (htab
->tlsdesc_plt
)
6275 if (htab
->root
.splt
->size
== 0)
6276 htab
->root
.splt
->size
+= PLT_ENTRY_SIZE
;
6278 htab
->tlsdesc_plt
= htab
->root
.splt
->size
;
6279 htab
->root
.splt
->size
+= PLT_TLSDESC_ENTRY_SIZE
;
6281 /* If we're not using lazy TLS relocations, don't generate the
6282 GOT entry required. */
6283 if (!(info
->flags
& DF_BIND_NOW
))
6285 htab
->dt_tlsdesc_got
= htab
->root
.sgot
->size
;
6286 htab
->root
.sgot
->size
+= GOT_ENTRY_SIZE
;
6290 /* We now have determined the sizes of the various dynamic sections.
6291 Allocate memory for them. */
6293 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
6295 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
6298 if (s
== htab
->root
.splt
6299 || s
== htab
->root
.sgot
6300 || s
== htab
->root
.sgotplt
6301 || s
== htab
->root
.iplt
6302 || s
== htab
->root
.igotplt
|| s
== htab
->sdynbss
)
6304 /* Strip this section if we don't need it; see the
6307 else if (CONST_STRNEQ (bfd_get_section_name (dynobj
, s
), ".rela"))
6309 if (s
->size
!= 0 && s
!= htab
->root
.srelplt
)
6312 /* We use the reloc_count field as a counter if we need
6313 to copy relocs into the output file. */
6314 if (s
!= htab
->root
.srelplt
)
6319 /* It's not one of our sections, so don't allocate space. */
6325 /* If we don't need this section, strip it from the
6326 output file. This is mostly to handle .rela.bss and
6327 .rela.plt. We must create both sections in
6328 create_dynamic_sections, because they must be created
6329 before the linker maps input sections to output
6330 sections. The linker does that before
6331 adjust_dynamic_symbol is called, and it is that
6332 function which decides whether anything needs to go
6333 into these sections. */
6335 s
->flags
|= SEC_EXCLUDE
;
6339 if ((s
->flags
& SEC_HAS_CONTENTS
) == 0)
6342 /* Allocate memory for the section contents. We use bfd_zalloc
6343 here in case unused entries are not reclaimed before the
6344 section's contents are written out. This should not happen,
6345 but this way if it does, we get a R_AARCH64_NONE reloc instead
6347 s
->contents
= (bfd_byte
*) bfd_zalloc (dynobj
, s
->size
);
6348 if (s
->contents
== NULL
)
6352 if (htab
->root
.dynamic_sections_created
)
6354 /* Add some entries to the .dynamic section. We fill in the
6355 values later, in elf64_aarch64_finish_dynamic_sections, but we
6356 must add the entries now so that we get the correct size for
6357 the .dynamic section. The DT_DEBUG entry is filled in by the
6358 dynamic linker and used by the debugger. */
6359 #define add_dynamic_entry(TAG, VAL) \
6360 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
6362 if (info
->executable
)
6364 if (!add_dynamic_entry (DT_DEBUG
, 0))
6368 if (htab
->root
.splt
->size
!= 0)
6370 if (!add_dynamic_entry (DT_PLTGOT
, 0)
6371 || !add_dynamic_entry (DT_PLTRELSZ
, 0)
6372 || !add_dynamic_entry (DT_PLTREL
, DT_RELA
)
6373 || !add_dynamic_entry (DT_JMPREL
, 0))
6376 if (htab
->tlsdesc_plt
6377 && (!add_dynamic_entry (DT_TLSDESC_PLT
, 0)
6378 || !add_dynamic_entry (DT_TLSDESC_GOT
, 0)))
6384 if (!add_dynamic_entry (DT_RELA
, 0)
6385 || !add_dynamic_entry (DT_RELASZ
, 0)
6386 || !add_dynamic_entry (DT_RELAENT
, RELOC_SIZE (htab
)))
6389 /* If any dynamic relocs apply to a read-only section,
6390 then we need a DT_TEXTREL entry. */
6391 if ((info
->flags
& DF_TEXTREL
) != 0)
6393 if (!add_dynamic_entry (DT_TEXTREL
, 0))
6398 #undef add_dynamic_entry
6406 elf64_aarch64_update_plt_entry (bfd
*output_bfd
,
6407 unsigned int r_type
,
6408 bfd_byte
*plt_entry
, bfd_vma value
)
6410 reloc_howto_type
*howto
;
6411 howto
= elf64_aarch64_howto_from_type (r_type
);
6412 bfd_elf_aarch64_put_addend (output_bfd
, plt_entry
, howto
, value
);
6416 elf64_aarch64_create_small_pltn_entry (struct elf_link_hash_entry
*h
,
6417 struct elf64_aarch64_link_hash_table
6418 *htab
, bfd
*output_bfd
)
6420 bfd_byte
*plt_entry
;
6423 bfd_vma gotplt_entry_address
;
6424 bfd_vma plt_entry_address
;
6425 Elf_Internal_Rela rela
;
6428 plt_index
= (h
->plt
.offset
- htab
->plt_header_size
) / htab
->plt_entry_size
;
6430 /* Offset in the GOT is PLT index plus got GOT headers(3)
6432 got_offset
= (plt_index
+ 3) * GOT_ENTRY_SIZE
;
6433 plt_entry
= htab
->root
.splt
->contents
+ h
->plt
.offset
;
6434 plt_entry_address
= htab
->root
.splt
->output_section
->vma
6435 + htab
->root
.splt
->output_section
->output_offset
+ h
->plt
.offset
;
6436 gotplt_entry_address
= htab
->root
.sgotplt
->output_section
->vma
+
6437 htab
->root
.sgotplt
->output_offset
+ got_offset
;
6439 /* Copy in the boiler-plate for the PLTn entry. */
6440 memcpy (plt_entry
, elf64_aarch64_small_plt_entry
, PLT_SMALL_ENTRY_SIZE
);
6442 /* Fill in the top 21 bits for this: ADRP x16, PLT_GOT + n * 8.
6443 ADRP: ((PG(S+A)-PG(P)) >> 12) & 0x1fffff */
6444 elf64_aarch64_update_plt_entry (output_bfd
, R_AARCH64_ADR_PREL_PG_HI21
,
6446 PG (gotplt_entry_address
) -
6447 PG (plt_entry_address
));
6449 /* Fill in the lo12 bits for the load from the pltgot. */
6450 elf64_aarch64_update_plt_entry (output_bfd
, R_AARCH64_LDST64_ABS_LO12_NC
,
6452 PG_OFFSET (gotplt_entry_address
));
6454 /* Fill in the the lo12 bits for the add from the pltgot entry. */
6455 elf64_aarch64_update_plt_entry (output_bfd
, R_AARCH64_ADD_ABS_LO12_NC
,
6457 PG_OFFSET (gotplt_entry_address
));
6459 /* All the GOTPLT Entries are essentially initialized to PLT0. */
6460 bfd_put_64 (output_bfd
,
6461 (htab
->root
.splt
->output_section
->vma
6462 + htab
->root
.splt
->output_offset
),
6463 htab
->root
.sgotplt
->contents
+ got_offset
);
6465 /* Fill in the entry in the .rela.plt section. */
6466 rela
.r_offset
= gotplt_entry_address
;
6467 rela
.r_info
= ELF64_R_INFO (h
->dynindx
, R_AARCH64_JUMP_SLOT
);
6470 /* Compute the relocation entry to used based on PLT index and do
6471 not adjust reloc_count. The reloc_count has already been adjusted
6472 to account for this entry. */
6473 loc
= htab
->root
.srelplt
->contents
+ plt_index
* RELOC_SIZE (htab
);
6474 bfd_elf64_swap_reloca_out (output_bfd
, &rela
, loc
);
6477 /* Size sections even though they're not dynamic. We use it to setup
6478 _TLS_MODULE_BASE_, if needed. */
6481 elf64_aarch64_always_size_sections (bfd
*output_bfd
,
6482 struct bfd_link_info
*info
)
6486 if (info
->relocatable
)
6489 tls_sec
= elf_hash_table (info
)->tls_sec
;
6493 struct elf_link_hash_entry
*tlsbase
;
6495 tlsbase
= elf_link_hash_lookup (elf_hash_table (info
),
6496 "_TLS_MODULE_BASE_", TRUE
, TRUE
, FALSE
);
6500 struct bfd_link_hash_entry
*h
= NULL
;
6501 const struct elf_backend_data
*bed
=
6502 get_elf_backend_data (output_bfd
);
6504 if (!(_bfd_generic_link_add_one_symbol
6505 (info
, output_bfd
, "_TLS_MODULE_BASE_", BSF_LOCAL
,
6506 tls_sec
, 0, NULL
, FALSE
, bed
->collect
, &h
)))
6509 tlsbase
->type
= STT_TLS
;
6510 tlsbase
= (struct elf_link_hash_entry
*) h
;
6511 tlsbase
->def_regular
= 1;
6512 tlsbase
->other
= STV_HIDDEN
;
6513 (*bed
->elf_backend_hide_symbol
) (info
, tlsbase
, TRUE
);
6520 /* Finish up dynamic symbol handling. We set the contents of various
6521 dynamic sections here. */
6523 elf64_aarch64_finish_dynamic_symbol (bfd
*output_bfd
,
6524 struct bfd_link_info
*info
,
6525 struct elf_link_hash_entry
*h
,
6526 Elf_Internal_Sym
*sym
)
6528 struct elf64_aarch64_link_hash_table
*htab
;
6529 htab
= elf64_aarch64_hash_table (info
);
6531 if (h
->plt
.offset
!= (bfd_vma
) - 1)
6533 /* This symbol has an entry in the procedure linkage table. Set
6536 if (h
->dynindx
== -1
6537 || htab
->root
.splt
== NULL
6538 || htab
->root
.sgotplt
== NULL
|| htab
->root
.srelplt
== NULL
)
6541 elf64_aarch64_create_small_pltn_entry (h
, htab
, output_bfd
);
6542 if (!h
->def_regular
)
6544 /* Mark the symbol as undefined, rather than as defined in
6545 the .plt section. Leave the value alone. This is a clue
6546 for the dynamic linker, to make function pointer
6547 comparisons work between an application and shared
6549 sym
->st_shndx
= SHN_UNDEF
;
6553 if (h
->got
.offset
!= (bfd_vma
) - 1
6554 && elf64_aarch64_hash_entry (h
)->got_type
== GOT_NORMAL
)
6556 Elf_Internal_Rela rela
;
6559 /* This symbol has an entry in the global offset table. Set it
6561 if (htab
->root
.sgot
== NULL
|| htab
->root
.srelgot
== NULL
)
6564 rela
.r_offset
= (htab
->root
.sgot
->output_section
->vma
6565 + htab
->root
.sgot
->output_offset
6566 + (h
->got
.offset
& ~(bfd_vma
) 1));
6568 if (info
->shared
&& SYMBOL_REFERENCES_LOCAL (info
, h
))
6570 if (!h
->def_regular
)
6573 BFD_ASSERT ((h
->got
.offset
& 1) != 0);
6574 rela
.r_info
= ELF64_R_INFO (0, R_AARCH64_RELATIVE
);
6575 rela
.r_addend
= (h
->root
.u
.def
.value
6576 + h
->root
.u
.def
.section
->output_section
->vma
6577 + h
->root
.u
.def
.section
->output_offset
);
6581 BFD_ASSERT ((h
->got
.offset
& 1) == 0);
6582 bfd_put_64 (output_bfd
, (bfd_vma
) 0,
6583 htab
->root
.sgot
->contents
+ h
->got
.offset
);
6584 rela
.r_info
= ELF64_R_INFO (h
->dynindx
, R_AARCH64_GLOB_DAT
);
6588 loc
= htab
->root
.srelgot
->contents
;
6589 loc
+= htab
->root
.srelgot
->reloc_count
++ * RELOC_SIZE (htab
);
6590 bfd_elf64_swap_reloca_out (output_bfd
, &rela
, loc
);
6595 Elf_Internal_Rela rela
;
6598 /* This symbol needs a copy reloc. Set it up. */
6600 if (h
->dynindx
== -1
6601 || (h
->root
.type
!= bfd_link_hash_defined
6602 && h
->root
.type
!= bfd_link_hash_defweak
)
6603 || htab
->srelbss
== NULL
)
6606 rela
.r_offset
= (h
->root
.u
.def
.value
6607 + h
->root
.u
.def
.section
->output_section
->vma
6608 + h
->root
.u
.def
.section
->output_offset
);
6609 rela
.r_info
= ELF64_R_INFO (h
->dynindx
, R_AARCH64_COPY
);
6611 loc
= htab
->srelbss
->contents
;
6612 loc
+= htab
->srelbss
->reloc_count
++ * RELOC_SIZE (htab
);
6613 bfd_elf64_swap_reloca_out (output_bfd
, &rela
, loc
);
6616 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. SYM may
6617 be NULL for local symbols. */
6619 && (h
== elf_hash_table (info
)->hdynamic
6620 || h
== elf_hash_table (info
)->hgot
))
6621 sym
->st_shndx
= SHN_ABS
;
6627 elf64_aarch64_init_small_plt0_entry (bfd
*output_bfd ATTRIBUTE_UNUSED
,
6628 struct elf64_aarch64_link_hash_table
6631 /* Fill in PLT0. Fixme:RR Note this doesn't distinguish between
6632 small and large plts and at the minute just generates
6635 /* PLT0 of the small PLT looks like this -
6636 stp x16, x30, [sp, #-16]! // Save the reloc and lr on stack.
6637 adrp x16, PLT_GOT + 16 // Get the page base of the GOTPLT
6638 ldr x17, [x16, #:lo12:PLT_GOT+16] // Load the address of the
6640 add x16, x16, #:lo12:PLT_GOT+16 // Load the lo12 bits of the
6641 // GOTPLT entry for this.
6644 bfd_vma plt_got_base
;
6648 memcpy (htab
->root
.splt
->contents
, elf64_aarch64_small_plt0_entry
,
6650 elf_section_data (htab
->root
.splt
->output_section
)->this_hdr
.sh_entsize
=
6653 plt_got_base
= (htab
->root
.sgotplt
->output_section
->vma
6654 + htab
->root
.sgotplt
->output_offset
);
6656 plt_base
= htab
->root
.splt
->output_section
->vma
+
6657 htab
->root
.splt
->output_section
->output_offset
;
6659 /* Fill in the top 21 bits for this: ADRP x16, PLT_GOT + n * 8.
6660 ADRP: ((PG(S+A)-PG(P)) >> 12) & 0x1fffff */
6661 elf64_aarch64_update_plt_entry (output_bfd
, R_AARCH64_ADR_PREL_PG_HI21
,
6662 htab
->root
.splt
->contents
+ 4,
6663 PG (plt_got_base
+ 16) - PG (plt_base
+ 4));
6665 elf64_aarch64_update_plt_entry (output_bfd
, R_AARCH64_LDST64_ABS_LO12_NC
,
6666 htab
->root
.splt
->contents
+ 8,
6667 PG_OFFSET (plt_got_base
+ 16));
6669 elf64_aarch64_update_plt_entry (output_bfd
, R_AARCH64_ADD_ABS_LO12_NC
,
6670 htab
->root
.splt
->contents
+ 12,
6671 PG_OFFSET (plt_got_base
+ 16));
6675 elf64_aarch64_finish_dynamic_sections (bfd
*output_bfd
,
6676 struct bfd_link_info
*info
)
6678 struct elf64_aarch64_link_hash_table
*htab
;
6682 htab
= elf64_aarch64_hash_table (info
);
6683 dynobj
= htab
->root
.dynobj
;
6684 sdyn
= bfd_get_linker_section (dynobj
, ".dynamic");
6686 if (htab
->root
.dynamic_sections_created
)
6688 Elf64_External_Dyn
*dyncon
, *dynconend
;
6690 if (sdyn
== NULL
|| htab
->root
.sgot
== NULL
)
6693 dyncon
= (Elf64_External_Dyn
*) sdyn
->contents
;
6694 dynconend
= (Elf64_External_Dyn
*) (sdyn
->contents
+ sdyn
->size
);
6695 for (; dyncon
< dynconend
; dyncon
++)
6697 Elf_Internal_Dyn dyn
;
6700 bfd_elf64_swap_dyn_in (dynobj
, dyncon
, &dyn
);
6708 s
= htab
->root
.sgotplt
;
6709 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
6713 dyn
.d_un
.d_ptr
= htab
->root
.srelplt
->output_section
->vma
;
6717 s
= htab
->root
.srelplt
->output_section
;
6718 dyn
.d_un
.d_val
= s
->size
;
6722 /* The procedure linkage table relocs (DT_JMPREL) should
6723 not be included in the overall relocs (DT_RELA).
6724 Therefore, we override the DT_RELASZ entry here to
6725 make it not include the JMPREL relocs. Since the
6726 linker script arranges for .rela.plt to follow all
6727 other relocation sections, we don't have to worry
6728 about changing the DT_RELA entry. */
6729 if (htab
->root
.srelplt
!= NULL
)
6731 s
= htab
->root
.srelplt
->output_section
;
6732 dyn
.d_un
.d_val
-= s
->size
;
6736 case DT_TLSDESC_PLT
:
6737 s
= htab
->root
.splt
;
6738 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
6739 + htab
->tlsdesc_plt
;
6742 case DT_TLSDESC_GOT
:
6743 s
= htab
->root
.sgot
;
6744 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
6745 + htab
->dt_tlsdesc_got
;
6749 bfd_elf64_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
6754 /* Fill in the special first entry in the procedure linkage table. */
6755 if (htab
->root
.splt
&& htab
->root
.splt
->size
> 0)
6757 elf64_aarch64_init_small_plt0_entry (output_bfd
, htab
);
6759 elf_section_data (htab
->root
.splt
->output_section
)->
6760 this_hdr
.sh_entsize
= htab
->plt_entry_size
;
6763 if (htab
->tlsdesc_plt
)
6765 bfd_put_64 (output_bfd
, (bfd_vma
) 0,
6766 htab
->root
.sgot
->contents
+ htab
->dt_tlsdesc_got
);
6768 memcpy (htab
->root
.splt
->contents
+ htab
->tlsdesc_plt
,
6769 elf64_aarch64_tlsdesc_small_plt_entry
,
6770 sizeof (elf64_aarch64_tlsdesc_small_plt_entry
));
6773 bfd_vma adrp1_addr
=
6774 htab
->root
.splt
->output_section
->vma
6775 + htab
->root
.splt
->output_offset
+ htab
->tlsdesc_plt
+ 4;
6777 bfd_vma adrp2_addr
=
6778 htab
->root
.splt
->output_section
->vma
6779 + htab
->root
.splt
->output_offset
+ htab
->tlsdesc_plt
+ 8;
6782 htab
->root
.sgot
->output_section
->vma
6783 + htab
->root
.sgot
->output_offset
;
6785 bfd_vma pltgot_addr
=
6786 htab
->root
.sgotplt
->output_section
->vma
6787 + htab
->root
.sgotplt
->output_offset
;
6789 bfd_vma dt_tlsdesc_got
= got_addr
+ htab
->dt_tlsdesc_got
;
6792 /* adrp x2, DT_TLSDESC_GOT */
6793 opcode
= bfd_get_32 (output_bfd
,
6794 htab
->root
.splt
->contents
6795 + htab
->tlsdesc_plt
+ 4);
6796 opcode
= reencode_adr_imm
6797 (opcode
, (PG (dt_tlsdesc_got
) - PG (adrp1_addr
)) >> 12);
6798 bfd_put_32 (output_bfd
, opcode
,
6799 htab
->root
.splt
->contents
+ htab
->tlsdesc_plt
+ 4);
6802 opcode
= bfd_get_32 (output_bfd
,
6803 htab
->root
.splt
->contents
6804 + htab
->tlsdesc_plt
+ 8);
6805 opcode
= reencode_adr_imm
6806 (opcode
, (PG (pltgot_addr
) - PG (adrp2_addr
)) >> 12);
6807 bfd_put_32 (output_bfd
, opcode
,
6808 htab
->root
.splt
->contents
+ htab
->tlsdesc_plt
+ 8);
6810 /* ldr x2, [x2, #0] */
6811 opcode
= bfd_get_32 (output_bfd
,
6812 htab
->root
.splt
->contents
6813 + htab
->tlsdesc_plt
+ 12);
6814 opcode
= reencode_ldst_pos_imm (opcode
,
6815 PG_OFFSET (dt_tlsdesc_got
) >> 3);
6816 bfd_put_32 (output_bfd
, opcode
,
6817 htab
->root
.splt
->contents
+ htab
->tlsdesc_plt
+ 12);
6820 opcode
= bfd_get_32 (output_bfd
,
6821 htab
->root
.splt
->contents
6822 + htab
->tlsdesc_plt
+ 16);
6823 opcode
= reencode_add_imm (opcode
, PG_OFFSET (pltgot_addr
));
6824 bfd_put_32 (output_bfd
, opcode
,
6825 htab
->root
.splt
->contents
+ htab
->tlsdesc_plt
+ 16);
6830 if (htab
->root
.sgotplt
)
6832 if (bfd_is_abs_section (htab
->root
.sgotplt
->output_section
))
6834 (*_bfd_error_handler
)
6835 (_("discarded output section: `%A'"), htab
->root
.sgotplt
);
6839 /* Fill in the first three entries in the global offset table. */
6840 if (htab
->root
.sgotplt
->size
> 0)
6842 /* Set the first entry in the global offset table to the address of
6843 the dynamic section. */
6845 bfd_put_64 (output_bfd
, (bfd_vma
) 0,
6846 htab
->root
.sgotplt
->contents
);
6848 bfd_put_64 (output_bfd
,
6849 sdyn
->output_section
->vma
+ sdyn
->output_offset
,
6850 htab
->root
.sgotplt
->contents
);
6851 /* Write GOT[1] and GOT[2], needed for the dynamic linker. */
6852 bfd_put_64 (output_bfd
,
6854 htab
->root
.sgotplt
->contents
+ GOT_ENTRY_SIZE
);
6855 bfd_put_64 (output_bfd
,
6857 htab
->root
.sgotplt
->contents
+ GOT_ENTRY_SIZE
* 2);
6860 elf_section_data (htab
->root
.sgotplt
->output_section
)->
6861 this_hdr
.sh_entsize
= GOT_ENTRY_SIZE
;
6864 if (htab
->root
.sgot
&& htab
->root
.sgot
->size
> 0)
6865 elf_section_data (htab
->root
.sgot
->output_section
)->this_hdr
.sh_entsize
6871 /* Return address for Ith PLT stub in section PLT, for relocation REL
6872 or (bfd_vma) -1 if it should not be included. */
6875 elf64_aarch64_plt_sym_val (bfd_vma i
, const asection
*plt
,
6876 const arelent
*rel ATTRIBUTE_UNUSED
)
6878 return plt
->vma
+ PLT_ENTRY_SIZE
+ i
* PLT_SMALL_ENTRY_SIZE
;
6882 /* We use this so we can override certain functions
6883 (though currently we don't). */
6885 const struct elf_size_info elf64_aarch64_size_info
=
6887 sizeof (Elf64_External_Ehdr
),
6888 sizeof (Elf64_External_Phdr
),
6889 sizeof (Elf64_External_Shdr
),
6890 sizeof (Elf64_External_Rel
),
6891 sizeof (Elf64_External_Rela
),
6892 sizeof (Elf64_External_Sym
),
6893 sizeof (Elf64_External_Dyn
),
6894 sizeof (Elf_External_Note
),
6895 4, /* Hash table entry size. */
6896 1, /* Internal relocs per external relocs. */
6897 64, /* Arch size. */
6898 3, /* Log_file_align. */
6899 ELFCLASS64
, EV_CURRENT
,
6900 bfd_elf64_write_out_phdrs
,
6901 bfd_elf64_write_shdrs_and_ehdr
,
6902 bfd_elf64_checksum_contents
,
6903 bfd_elf64_write_relocs
,
6904 bfd_elf64_swap_symbol_in
,
6905 bfd_elf64_swap_symbol_out
,
6906 bfd_elf64_slurp_reloc_table
,
6907 bfd_elf64_slurp_symbol_table
,
6908 bfd_elf64_swap_dyn_in
,
6909 bfd_elf64_swap_dyn_out
,
6910 bfd_elf64_swap_reloc_in
,
6911 bfd_elf64_swap_reloc_out
,
6912 bfd_elf64_swap_reloca_in
,
6913 bfd_elf64_swap_reloca_out
6916 #define ELF_ARCH bfd_arch_aarch64
6917 #define ELF_MACHINE_CODE EM_AARCH64
6918 #define ELF_MAXPAGESIZE 0x10000
6919 #define ELF_MINPAGESIZE 0x1000
6920 #define ELF_COMMONPAGESIZE 0x1000
6922 #define bfd_elf64_close_and_cleanup \
6923 elf64_aarch64_close_and_cleanup
6925 #define bfd_elf64_bfd_copy_private_bfd_data \
6926 elf64_aarch64_copy_private_bfd_data
6928 #define bfd_elf64_bfd_free_cached_info \
6929 elf64_aarch64_bfd_free_cached_info
6931 #define bfd_elf64_bfd_is_target_special_symbol \
6932 elf64_aarch64_is_target_special_symbol
6934 #define bfd_elf64_bfd_link_hash_table_create \
6935 elf64_aarch64_link_hash_table_create
6937 #define bfd_elf64_bfd_link_hash_table_free \
6938 elf64_aarch64_hash_table_free
6940 #define bfd_elf64_bfd_merge_private_bfd_data \
6941 elf64_aarch64_merge_private_bfd_data
6943 #define bfd_elf64_bfd_print_private_bfd_data \
6944 elf64_aarch64_print_private_bfd_data
6946 #define bfd_elf64_bfd_reloc_type_lookup \
6947 elf64_aarch64_reloc_type_lookup
6949 #define bfd_elf64_bfd_reloc_name_lookup \
6950 elf64_aarch64_reloc_name_lookup
6952 #define bfd_elf64_bfd_set_private_flags \
6953 elf64_aarch64_set_private_flags
6955 #define bfd_elf64_find_inliner_info \
6956 elf64_aarch64_find_inliner_info
6958 #define bfd_elf64_find_nearest_line \
6959 elf64_aarch64_find_nearest_line
6961 #define bfd_elf64_mkobject \
6962 elf64_aarch64_mkobject
6964 #define bfd_elf64_new_section_hook \
6965 elf64_aarch64_new_section_hook
6967 #define elf_backend_adjust_dynamic_symbol \
6968 elf64_aarch64_adjust_dynamic_symbol
6970 #define elf_backend_always_size_sections \
6971 elf64_aarch64_always_size_sections
6973 #define elf_backend_check_relocs \
6974 elf64_aarch64_check_relocs
6976 #define elf_backend_copy_indirect_symbol \
6977 elf64_aarch64_copy_indirect_symbol
6979 /* Create .dynbss, and .rela.bss sections in DYNOBJ, and set up shortcuts
6980 to them in our hash. */
6981 #define elf_backend_create_dynamic_sections \
6982 elf64_aarch64_create_dynamic_sections
6984 #define elf_backend_init_index_section \
6985 _bfd_elf_init_2_index_sections
6987 #define elf_backend_is_function_type \
6988 elf64_aarch64_is_function_type
6990 #define elf_backend_finish_dynamic_sections \
6991 elf64_aarch64_finish_dynamic_sections
6993 #define elf_backend_finish_dynamic_symbol \
6994 elf64_aarch64_finish_dynamic_symbol
6996 #define elf_backend_gc_sweep_hook \
6997 elf64_aarch64_gc_sweep_hook
6999 #define elf_backend_object_p \
7000 elf64_aarch64_object_p
7002 #define elf_backend_output_arch_local_syms \
7003 elf64_aarch64_output_arch_local_syms
7005 #define elf_backend_plt_sym_val \
7006 elf64_aarch64_plt_sym_val
7008 #define elf_backend_post_process_headers \
7009 elf64_aarch64_post_process_headers
7011 #define elf_backend_relocate_section \
7012 elf64_aarch64_relocate_section
7014 #define elf_backend_reloc_type_class \
7015 elf64_aarch64_reloc_type_class
7017 #define elf_backend_section_flags \
7018 elf64_aarch64_section_flags
7020 #define elf_backend_section_from_shdr \
7021 elf64_aarch64_section_from_shdr
7023 #define elf_backend_size_dynamic_sections \
7024 elf64_aarch64_size_dynamic_sections
7026 #define elf_backend_size_info \
7027 elf64_aarch64_size_info
7029 #define elf_backend_can_refcount 1
7030 #define elf_backend_can_gc_sections 0
7031 #define elf_backend_plt_readonly 1
7032 #define elf_backend_want_got_plt 1
7033 #define elf_backend_want_plt_sym 0
7034 #define elf_backend_may_use_rel_p 0
7035 #define elf_backend_may_use_rela_p 1
7036 #define elf_backend_default_use_rela_p 1
7037 #define elf_backend_got_header_size (GOT_ENTRY_SIZE * 3)
7039 #undef elf_backend_obj_attrs_section
7040 #define elf_backend_obj_attrs_section ".ARM.attributes"
7042 #include "elf64-target.h"