[GAS][AARCH64]Add TLSDESC large memory model support.
[deliverable/binutils-gdb.git] / bfd / elfnn-aarch64.c
CommitLineData
cec5225b 1/* AArch64-specific support for NN-bit ELF.
b90efa5b 2 Copyright (C) 2009-2015 Free Software Foundation, Inc.
a06ea964
NC
3 Contributed by ARM Ltd.
4
5 This file is part of BFD, the Binary File Descriptor library.
6
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.
11
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.
16
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/>. */
20
21/* Notes on implementation:
22
23 Thread Local Store (TLS)
24
25 Overview:
26
27 The implementation currently supports both traditional TLS and TLS
28 descriptors, but only general dynamic (GD).
29
30 For traditional TLS the assembler will present us with code
31 fragments of the form:
32
33 adrp x0, :tlsgd:foo
34 R_AARCH64_TLSGD_ADR_PAGE21(foo)
35 add x0, :tlsgd_lo12:foo
36 R_AARCH64_TLSGD_ADD_LO12_NC(foo)
37 bl __tls_get_addr
38 nop
39
40 For TLS descriptors the assembler will present us with code
41 fragments of the form:
42
418009c2 43 adrp x0, :tlsdesc:foo R_AARCH64_TLSDESC_ADR_PAGE21(foo)
a06ea964
NC
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)
46 .tlsdesccall foo
47 blr x1 R_AARCH64_TLSDESC_CALL(foo)
48
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.
52
a6bb11b2 53 The relocations R_AARCH64_TLSDESC_{ADR_PAGE21,LD64_LO12_NC,ADD_LO12_NC}
a06ea964
NC
54 against foo indicate that 'foo' is thread local and should be accessed
55 via a TLS descriptor mechanism.
56
57 The precise instruction sequence is only relevant from the
58 perspective of linker relaxation which is currently not implemented.
59
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.
64
65 In the traditional TLS mechanism, the double GOT entry is used to
66 provide the tls_index structure, containing module and offset
a6bb11b2 67 entries. The static linker places the relocation R_AARCH64_TLS_DTPMOD
a06ea964
NC
68 on the module entry. The loader will subsequently fixup this
69 relocation with the module identity.
70
71 For global traditional TLS symbols the static linker places an
a6bb11b2 72 R_AARCH64_TLS_DTPREL relocation on the offset entry. The loader
a06ea964
NC
73 will subsequently fixup the offset. For local TLS symbols the static
74 linker fixes up offset.
75
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.
80
81 Implementation:
82
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.
86
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.
92
93 The flow:
94
cec5225b 95 elfNN_aarch64_check_relocs()
a06ea964
NC
96
97 This function is invoked for each relocation.
98
99 The TLS relocations R_AARCH64_TLSGD_{ADR_PREL21,ADD_LO12_NC} and
a6bb11b2 100 R_AARCH64_TLSDESC_{ADR_PAGE21,LD64_LO12_NC,ADD_LO12_NC} are
a06ea964
NC
101 spotted. One time creation of local symbol data structures are
102 created when the first local symbol is seen.
103
104 The reference count for a symbol is incremented. The GOT type for
105 each symbol is marked as general dynamic.
106
cec5225b 107 elfNN_aarch64_allocate_dynrelocs ()
a06ea964
NC
108
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
113 for this symbol.
114
cec5225b 115 elfNN_aarch64_size_dynamic_sections ()
a06ea964
NC
116
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.
121
cec5225b 122 elfNN_aarch64_relocate_section ()
a06ea964 123
cec5225b 124 Calls elfNN_aarch64_final_link_relocate ()
a06ea964
NC
125
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.
133
cec5225b 134 elfNN_aarch64_final_link_relocate ()
a06ea964
NC
135
136 Fixup the R_AARCH64_TLSGD_{ADR_PREL21, ADD_LO12_NC} relocations. */
137
138#include "sysdep.h"
139#include "bfd.h"
140#include "libiberty.h"
141#include "libbfd.h"
142#include "bfd_stdint.h"
143#include "elf-bfd.h"
144#include "bfdlink.h"
1419bbe5 145#include "objalloc.h"
a06ea964 146#include "elf/aarch64.h"
caed7120 147#include "elfxx-aarch64.h"
a06ea964 148
cec5225b
YZ
149#define ARCH_SIZE NN
150
151#if ARCH_SIZE == 64
152#define AARCH64_R(NAME) R_AARCH64_ ## NAME
153#define AARCH64_R_STR(NAME) "R_AARCH64_" #NAME
a6bb11b2
YZ
154#define HOWTO64(...) HOWTO (__VA_ARGS__)
155#define HOWTO32(...) EMPTY_HOWTO (0)
cec5225b
YZ
156#define LOG_FILE_ALIGN 3
157#endif
158
159#if ARCH_SIZE == 32
160#define AARCH64_R(NAME) R_AARCH64_P32_ ## NAME
161#define AARCH64_R_STR(NAME) "R_AARCH64_P32_" #NAME
a6bb11b2
YZ
162#define HOWTO64(...) EMPTY_HOWTO (0)
163#define HOWTO32(...) HOWTO (__VA_ARGS__)
cec5225b
YZ
164#define LOG_FILE_ALIGN 2
165#endif
166
a6bb11b2 167#define IS_AARCH64_TLS_RELOC(R_TYPE) \
4c0a9a6f
JW
168 ((R_TYPE) == BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC \
169 || (R_TYPE) == BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21 \
3c12b054 170 || (R_TYPE) == BFD_RELOC_AARCH64_TLSGD_ADR_PREL21 \
3e8286c0 171 || (R_TYPE) == BFD_RELOC_AARCH64_TLSGD_MOVW_G0_NC \
1aa66fb1 172 || (R_TYPE) == BFD_RELOC_AARCH64_TLSGD_MOVW_G1 \
a6bb11b2 173 || (R_TYPE) == BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21 \
a6bb11b2 174 || (R_TYPE) == BFD_RELOC_AARCH64_TLSIE_LD32_GOTTPREL_LO12_NC \
4c0a9a6f 175 || (R_TYPE) == BFD_RELOC_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC \
a6bb11b2 176 || (R_TYPE) == BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19 \
4c0a9a6f
JW
177 || (R_TYPE) == BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G0_NC \
178 || (R_TYPE) == BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G1 \
6ffe9a1b 179 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_ADD_DTPREL_HI12 \
40fbed84 180 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_ADD_DTPREL_LO12 \
753999c1 181 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_ADD_DTPREL_LO12_NC \
73f925cc 182 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC \
f69e4920 183 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21 \
77a69ff8 184 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_ADR_PREL21 \
07c9aa07
JW
185 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_LDST16_DTPREL_LO12 \
186 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_LDST16_DTPREL_LO12_NC \
187 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_LDST32_DTPREL_LO12 \
188 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_LDST32_DTPREL_LO12_NC \
189 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_LDST64_DTPREL_LO12 \
190 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_LDST64_DTPREL_LO12_NC \
191 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_LDST8_DTPREL_LO12 \
192 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_LDST8_DTPREL_LO12_NC \
6ffe9a1b
JW
193 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G0 \
194 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G0_NC \
195 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G1 \
196 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G1_NC \
197 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G2 \
a6bb11b2 198 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_HI12 \
4c0a9a6f 199 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_LO12 \
a6bb11b2 200 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_LO12_NC \
a6bb11b2
YZ
201 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0 \
202 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC \
4c0a9a6f
JW
203 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1 \
204 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1_NC \
205 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G2 \
a6bb11b2
YZ
206 || (R_TYPE) == BFD_RELOC_AARCH64_TLS_DTPMOD \
207 || (R_TYPE) == BFD_RELOC_AARCH64_TLS_DTPREL \
208 || (R_TYPE) == BFD_RELOC_AARCH64_TLS_TPREL \
a06ea964
NC
209 || IS_AARCH64_TLSDESC_RELOC ((R_TYPE)))
210
9331eea1 211#define IS_AARCH64_TLS_RELAX_RELOC(R_TYPE) \
4af68b9c
JW
212 ((R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_ADD_LO12_NC \
213 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21 \
214 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21 \
215 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_CALL \
216 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_LD_PREL19 \
217 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_LDNN_LO12_NC \
218 || (R_TYPE) == BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21 \
9331eea1
JW
219 || (R_TYPE) == BFD_RELOC_AARCH64_TLSGD_ADR_PREL21 \
220 || (R_TYPE) == BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC \
ac734732
RL
221 || (R_TYPE) == BFD_RELOC_AARCH64_TLSGD_MOVW_G0_NC \
222 || (R_TYPE) == BFD_RELOC_AARCH64_TLSGD_MOVW_G1 \
9331eea1
JW
223 || (R_TYPE) == BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21 \
224 || (R_TYPE) == BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19 \
225 || (R_TYPE) == BFD_RELOC_AARCH64_TLSIE_LDNN_GOTTPREL_LO12_NC \
259364ad
JW
226 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC \
227 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21 \
4af68b9c 228 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_ADR_PREL21)
9331eea1 229
a6bb11b2 230#define IS_AARCH64_TLSDESC_RELOC(R_TYPE) \
4c0a9a6f
JW
231 ((R_TYPE) == BFD_RELOC_AARCH64_TLSDESC \
232 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_ADD \
233 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_ADD_LO12_NC \
a6bb11b2 234 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21 \
389b8029 235 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21 \
4c0a9a6f 236 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_CALL \
a6bb11b2 237 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_LD32_LO12_NC \
4c0a9a6f 238 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_LD64_LO12_NC \
a6bb11b2 239 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_LDR \
4c0a9a6f
JW
240 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_LD_PREL19 \
241 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_OFF_G0_NC \
242 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_OFF_G1)
a06ea964
NC
243
244#define ELIMINATE_COPY_RELOCS 0
245
a06ea964 246/* Return size of a relocation entry. HTAB is the bfd's
cec5225b
YZ
247 elf_aarch64_link_hash_entry. */
248#define RELOC_SIZE(HTAB) (sizeof (ElfNN_External_Rela))
a06ea964 249
cec5225b
YZ
250/* GOT Entry size - 8 bytes in ELF64 and 4 bytes in ELF32. */
251#define GOT_ENTRY_SIZE (ARCH_SIZE / 8)
a06ea964
NC
252#define PLT_ENTRY_SIZE (32)
253#define PLT_SMALL_ENTRY_SIZE (16)
254#define PLT_TLSDESC_ENTRY_SIZE (32)
255
a06ea964
NC
256/* Encoding of the nop instruction */
257#define INSN_NOP 0xd503201f
258
259#define aarch64_compute_jump_table_size(htab) \
260 (((htab)->root.srelplt == NULL) ? 0 \
261 : (htab)->root.srelplt->reloc_count * GOT_ENTRY_SIZE)
262
263/* The first entry in a procedure linkage table looks like this
264 if the distance between the PLTGOT and the PLT is < 4GB use
265 these PLT entries. Note that the dynamic linker gets &PLTGOT[2]
266 in x16 and needs to work out PLTGOT[1] by using an address of
cec5225b
YZ
267 [x16,#-GOT_ENTRY_SIZE]. */
268static const bfd_byte elfNN_aarch64_small_plt0_entry[PLT_ENTRY_SIZE] =
a06ea964
NC
269{
270 0xf0, 0x7b, 0xbf, 0xa9, /* stp x16, x30, [sp, #-16]! */
271 0x10, 0x00, 0x00, 0x90, /* adrp x16, (GOT+16) */
caed7120 272#if ARCH_SIZE == 64
a06ea964
NC
273 0x11, 0x0A, 0x40, 0xf9, /* ldr x17, [x16, #PLT_GOT+0x10] */
274 0x10, 0x42, 0x00, 0x91, /* add x16, x16,#PLT_GOT+0x10 */
caed7120
YZ
275#else
276 0x11, 0x0A, 0x40, 0xb9, /* ldr w17, [x16, #PLT_GOT+0x8] */
277 0x10, 0x22, 0x00, 0x11, /* add w16, w16,#PLT_GOT+0x8 */
278#endif
a06ea964
NC
279 0x20, 0x02, 0x1f, 0xd6, /* br x17 */
280 0x1f, 0x20, 0x03, 0xd5, /* nop */
281 0x1f, 0x20, 0x03, 0xd5, /* nop */
282 0x1f, 0x20, 0x03, 0xd5, /* nop */
283};
284
285/* Per function entry in a procedure linkage table looks like this
286 if the distance between the PLTGOT and the PLT is < 4GB use
287 these PLT entries. */
cec5225b 288static const bfd_byte elfNN_aarch64_small_plt_entry[PLT_SMALL_ENTRY_SIZE] =
a06ea964
NC
289{
290 0x10, 0x00, 0x00, 0x90, /* adrp x16, PLTGOT + n * 8 */
caed7120 291#if ARCH_SIZE == 64
a06ea964
NC
292 0x11, 0x02, 0x40, 0xf9, /* ldr x17, [x16, PLTGOT + n * 8] */
293 0x10, 0x02, 0x00, 0x91, /* add x16, x16, :lo12:PLTGOT + n * 8 */
caed7120
YZ
294#else
295 0x11, 0x02, 0x40, 0xb9, /* ldr w17, [x16, PLTGOT + n * 4] */
296 0x10, 0x02, 0x00, 0x11, /* add w16, w16, :lo12:PLTGOT + n * 4 */
297#endif
a06ea964
NC
298 0x20, 0x02, 0x1f, 0xd6, /* br x17. */
299};
300
301static const bfd_byte
cec5225b 302elfNN_aarch64_tlsdesc_small_plt_entry[PLT_TLSDESC_ENTRY_SIZE] =
a06ea964
NC
303{
304 0xe2, 0x0f, 0xbf, 0xa9, /* stp x2, x3, [sp, #-16]! */
305 0x02, 0x00, 0x00, 0x90, /* adrp x2, 0 */
306 0x03, 0x00, 0x00, 0x90, /* adrp x3, 0 */
caed7120
YZ
307#if ARCH_SIZE == 64
308 0x42, 0x00, 0x40, 0xf9, /* ldr x2, [x2, #0] */
a06ea964 309 0x63, 0x00, 0x00, 0x91, /* add x3, x3, 0 */
caed7120
YZ
310#else
311 0x42, 0x00, 0x40, 0xb9, /* ldr w2, [x2, #0] */
312 0x63, 0x00, 0x00, 0x11, /* add w3, w3, 0 */
313#endif
314 0x40, 0x00, 0x1f, 0xd6, /* br x2 */
a06ea964
NC
315 0x1f, 0x20, 0x03, 0xd5, /* nop */
316 0x1f, 0x20, 0x03, 0xd5, /* nop */
317};
318
cec5225b
YZ
319#define elf_info_to_howto elfNN_aarch64_info_to_howto
320#define elf_info_to_howto_rel elfNN_aarch64_info_to_howto
a06ea964
NC
321
322#define AARCH64_ELF_ABI_VERSION 0
a06ea964
NC
323
324/* In case we're on a 32-bit machine, construct a 64-bit "-1" value. */
325#define ALL_ONES (~ (bfd_vma) 0)
326
a6bb11b2
YZ
327/* Indexed by the bfd interal reloc enumerators.
328 Therefore, the table needs to be synced with BFD_RELOC_AARCH64_*
329 in reloc.c. */
a06ea964 330
a6bb11b2 331static reloc_howto_type elfNN_aarch64_howto_table[] =
a06ea964 332{
a6bb11b2 333 EMPTY_HOWTO (0),
a06ea964 334
a6bb11b2 335 /* Basic data relocations. */
a06ea964 336
a6bb11b2
YZ
337#if ARCH_SIZE == 64
338 HOWTO (R_AARCH64_NULL, /* type */
a06ea964 339 0, /* rightshift */
6346d5ca 340 3, /* size (0 = byte, 1 = short, 2 = long) */
a6bb11b2 341 0, /* bitsize */
a06ea964
NC
342 FALSE, /* pc_relative */
343 0, /* bitpos */
344 complain_overflow_dont, /* complain_on_overflow */
345 bfd_elf_generic_reloc, /* special_function */
a6bb11b2 346 "R_AARCH64_NULL", /* name */
a06ea964
NC
347 FALSE, /* partial_inplace */
348 0, /* src_mask */
a6bb11b2 349 0, /* dst_mask */
a06ea964 350 FALSE), /* pcrel_offset */
a6bb11b2
YZ
351#else
352 HOWTO (R_AARCH64_NONE, /* type */
a06ea964 353 0, /* rightshift */
6346d5ca 354 3, /* size (0 = byte, 1 = short, 2 = long) */
a06ea964
NC
355 0, /* bitsize */
356 FALSE, /* pc_relative */
357 0, /* bitpos */
358 complain_overflow_dont, /* complain_on_overflow */
359 bfd_elf_generic_reloc, /* special_function */
a6bb11b2 360 "R_AARCH64_NONE", /* name */
a06ea964
NC
361 FALSE, /* partial_inplace */
362 0, /* src_mask */
363 0, /* dst_mask */
364 FALSE), /* pcrel_offset */
a6bb11b2 365#endif
a06ea964
NC
366
367 /* .xword: (S+A) */
a6bb11b2 368 HOWTO64 (AARCH64_R (ABS64), /* type */
a06ea964
NC
369 0, /* rightshift */
370 4, /* size (4 = long long) */
371 64, /* bitsize */
372 FALSE, /* pc_relative */
373 0, /* bitpos */
374 complain_overflow_unsigned, /* complain_on_overflow */
375 bfd_elf_generic_reloc, /* special_function */
a6bb11b2 376 AARCH64_R_STR (ABS64), /* name */
a06ea964
NC
377 FALSE, /* partial_inplace */
378 ALL_ONES, /* src_mask */
379 ALL_ONES, /* dst_mask */
380 FALSE), /* pcrel_offset */
381
382 /* .word: (S+A) */
a6bb11b2 383 HOWTO (AARCH64_R (ABS32), /* type */
a06ea964
NC
384 0, /* rightshift */
385 2, /* size (0 = byte, 1 = short, 2 = long) */
386 32, /* bitsize */
387 FALSE, /* pc_relative */
388 0, /* bitpos */
389 complain_overflow_unsigned, /* complain_on_overflow */
390 bfd_elf_generic_reloc, /* special_function */
a6bb11b2 391 AARCH64_R_STR (ABS32), /* name */
a06ea964
NC
392 FALSE, /* partial_inplace */
393 0xffffffff, /* src_mask */
394 0xffffffff, /* dst_mask */
395 FALSE), /* pcrel_offset */
396
397 /* .half: (S+A) */
a6bb11b2 398 HOWTO (AARCH64_R (ABS16), /* type */
a06ea964
NC
399 0, /* rightshift */
400 1, /* size (0 = byte, 1 = short, 2 = long) */
401 16, /* bitsize */
402 FALSE, /* pc_relative */
403 0, /* bitpos */
404 complain_overflow_unsigned, /* complain_on_overflow */
405 bfd_elf_generic_reloc, /* special_function */
a6bb11b2 406 AARCH64_R_STR (ABS16), /* name */
a06ea964
NC
407 FALSE, /* partial_inplace */
408 0xffff, /* src_mask */
409 0xffff, /* dst_mask */
410 FALSE), /* pcrel_offset */
411
412 /* .xword: (S+A-P) */
a6bb11b2 413 HOWTO64 (AARCH64_R (PREL64), /* type */
a06ea964
NC
414 0, /* rightshift */
415 4, /* size (4 = long long) */
416 64, /* bitsize */
417 TRUE, /* pc_relative */
418 0, /* bitpos */
419 complain_overflow_signed, /* complain_on_overflow */
420 bfd_elf_generic_reloc, /* special_function */
a6bb11b2 421 AARCH64_R_STR (PREL64), /* name */
a06ea964
NC
422 FALSE, /* partial_inplace */
423 ALL_ONES, /* src_mask */
424 ALL_ONES, /* dst_mask */
425 TRUE), /* pcrel_offset */
426
427 /* .word: (S+A-P) */
a6bb11b2 428 HOWTO (AARCH64_R (PREL32), /* type */
a06ea964
NC
429 0, /* rightshift */
430 2, /* size (0 = byte, 1 = short, 2 = long) */
431 32, /* bitsize */
432 TRUE, /* pc_relative */
433 0, /* bitpos */
434 complain_overflow_signed, /* complain_on_overflow */
435 bfd_elf_generic_reloc, /* special_function */
a6bb11b2 436 AARCH64_R_STR (PREL32), /* name */
a06ea964
NC
437 FALSE, /* partial_inplace */
438 0xffffffff, /* src_mask */
439 0xffffffff, /* dst_mask */
440 TRUE), /* pcrel_offset */
441
442 /* .half: (S+A-P) */
a6bb11b2 443 HOWTO (AARCH64_R (PREL16), /* type */
a06ea964
NC
444 0, /* rightshift */
445 1, /* size (0 = byte, 1 = short, 2 = long) */
446 16, /* bitsize */
447 TRUE, /* pc_relative */
448 0, /* bitpos */
449 complain_overflow_signed, /* complain_on_overflow */
450 bfd_elf_generic_reloc, /* special_function */
a6bb11b2 451 AARCH64_R_STR (PREL16), /* name */
a06ea964
NC
452 FALSE, /* partial_inplace */
453 0xffff, /* src_mask */
454 0xffff, /* dst_mask */
455 TRUE), /* pcrel_offset */
456
457 /* Group relocations to create a 16, 32, 48 or 64 bit
458 unsigned data or abs address inline. */
459
460 /* MOVZ: ((S+A) >> 0) & 0xffff */
a6bb11b2 461 HOWTO (AARCH64_R (MOVW_UABS_G0), /* type */
a06ea964
NC
462 0, /* rightshift */
463 2, /* size (0 = byte, 1 = short, 2 = long) */
464 16, /* bitsize */
465 FALSE, /* pc_relative */
466 0, /* bitpos */
467 complain_overflow_unsigned, /* complain_on_overflow */
468 bfd_elf_generic_reloc, /* special_function */
a6bb11b2 469 AARCH64_R_STR (MOVW_UABS_G0), /* name */
a06ea964
NC
470 FALSE, /* partial_inplace */
471 0xffff, /* src_mask */
472 0xffff, /* dst_mask */
473 FALSE), /* pcrel_offset */
474
475 /* MOVK: ((S+A) >> 0) & 0xffff [no overflow check] */
a6bb11b2 476 HOWTO (AARCH64_R (MOVW_UABS_G0_NC), /* type */
a06ea964
NC
477 0, /* rightshift */
478 2, /* size (0 = byte, 1 = short, 2 = long) */
479 16, /* bitsize */
480 FALSE, /* pc_relative */
481 0, /* bitpos */
482 complain_overflow_dont, /* complain_on_overflow */
483 bfd_elf_generic_reloc, /* special_function */
a6bb11b2 484 AARCH64_R_STR (MOVW_UABS_G0_NC), /* name */
a06ea964
NC
485 FALSE, /* partial_inplace */
486 0xffff, /* src_mask */
487 0xffff, /* dst_mask */
488 FALSE), /* pcrel_offset */
489
490 /* MOVZ: ((S+A) >> 16) & 0xffff */
a6bb11b2 491 HOWTO (AARCH64_R (MOVW_UABS_G1), /* type */
a06ea964
NC
492 16, /* rightshift */
493 2, /* size (0 = byte, 1 = short, 2 = long) */
494 16, /* bitsize */
495 FALSE, /* pc_relative */
496 0, /* bitpos */
497 complain_overflow_unsigned, /* complain_on_overflow */
498 bfd_elf_generic_reloc, /* special_function */
a6bb11b2 499 AARCH64_R_STR (MOVW_UABS_G1), /* name */
a06ea964
NC
500 FALSE, /* partial_inplace */
501 0xffff, /* src_mask */
502 0xffff, /* dst_mask */
503 FALSE), /* pcrel_offset */
504
505 /* MOVK: ((S+A) >> 16) & 0xffff [no overflow check] */
a6bb11b2 506 HOWTO64 (AARCH64_R (MOVW_UABS_G1_NC), /* type */
a06ea964
NC
507 16, /* rightshift */
508 2, /* size (0 = byte, 1 = short, 2 = long) */
509 16, /* bitsize */
510 FALSE, /* pc_relative */
511 0, /* bitpos */
512 complain_overflow_dont, /* complain_on_overflow */
513 bfd_elf_generic_reloc, /* special_function */
a6bb11b2 514 AARCH64_R_STR (MOVW_UABS_G1_NC), /* name */
a06ea964
NC
515 FALSE, /* partial_inplace */
516 0xffff, /* src_mask */
517 0xffff, /* dst_mask */
518 FALSE), /* pcrel_offset */
519
520 /* MOVZ: ((S+A) >> 32) & 0xffff */
a6bb11b2 521 HOWTO64 (AARCH64_R (MOVW_UABS_G2), /* type */
a06ea964
NC
522 32, /* rightshift */
523 2, /* size (0 = byte, 1 = short, 2 = long) */
524 16, /* bitsize */
525 FALSE, /* pc_relative */
526 0, /* bitpos */
527 complain_overflow_unsigned, /* complain_on_overflow */
528 bfd_elf_generic_reloc, /* special_function */
a6bb11b2 529 AARCH64_R_STR (MOVW_UABS_G2), /* name */
a06ea964
NC
530 FALSE, /* partial_inplace */
531 0xffff, /* src_mask */
532 0xffff, /* dst_mask */
533 FALSE), /* pcrel_offset */
534
535 /* MOVK: ((S+A) >> 32) & 0xffff [no overflow check] */
a6bb11b2 536 HOWTO64 (AARCH64_R (MOVW_UABS_G2_NC), /* type */
a06ea964
NC
537 32, /* rightshift */
538 2, /* size (0 = byte, 1 = short, 2 = long) */
539 16, /* bitsize */
540 FALSE, /* pc_relative */
541 0, /* bitpos */
542 complain_overflow_dont, /* complain_on_overflow */
543 bfd_elf_generic_reloc, /* special_function */
a6bb11b2 544 AARCH64_R_STR (MOVW_UABS_G2_NC), /* name */
a06ea964
NC
545 FALSE, /* partial_inplace */
546 0xffff, /* src_mask */
547 0xffff, /* dst_mask */
548 FALSE), /* pcrel_offset */
549
550 /* MOVZ: ((S+A) >> 48) & 0xffff */
a6bb11b2 551 HOWTO64 (AARCH64_R (MOVW_UABS_G3), /* type */
a06ea964
NC
552 48, /* rightshift */
553 2, /* size (0 = byte, 1 = short, 2 = long) */
554 16, /* bitsize */
555 FALSE, /* pc_relative */
556 0, /* bitpos */
557 complain_overflow_unsigned, /* complain_on_overflow */
558 bfd_elf_generic_reloc, /* special_function */
a6bb11b2 559 AARCH64_R_STR (MOVW_UABS_G3), /* name */
a06ea964
NC
560 FALSE, /* partial_inplace */
561 0xffff, /* src_mask */
562 0xffff, /* dst_mask */
563 FALSE), /* pcrel_offset */
564
565 /* Group relocations to create high part of a 16, 32, 48 or 64 bit
566 signed data or abs address inline. Will change instruction
567 to MOVN or MOVZ depending on sign of calculated value. */
568
569 /* MOV[ZN]: ((S+A) >> 0) & 0xffff */
a6bb11b2 570 HOWTO (AARCH64_R (MOVW_SABS_G0), /* type */
a06ea964
NC
571 0, /* rightshift */
572 2, /* size (0 = byte, 1 = short, 2 = long) */
573 16, /* bitsize */
574 FALSE, /* pc_relative */
575 0, /* bitpos */
576 complain_overflow_signed, /* complain_on_overflow */
577 bfd_elf_generic_reloc, /* special_function */
a6bb11b2 578 AARCH64_R_STR (MOVW_SABS_G0), /* name */
a06ea964
NC
579 FALSE, /* partial_inplace */
580 0xffff, /* src_mask */
581 0xffff, /* dst_mask */
582 FALSE), /* pcrel_offset */
583
584 /* MOV[ZN]: ((S+A) >> 16) & 0xffff */
a6bb11b2 585 HOWTO64 (AARCH64_R (MOVW_SABS_G1), /* type */
a06ea964
NC
586 16, /* rightshift */
587 2, /* size (0 = byte, 1 = short, 2 = long) */
588 16, /* bitsize */
589 FALSE, /* pc_relative */
590 0, /* bitpos */
591 complain_overflow_signed, /* complain_on_overflow */
592 bfd_elf_generic_reloc, /* special_function */
a6bb11b2 593 AARCH64_R_STR (MOVW_SABS_G1), /* name */
a06ea964
NC
594 FALSE, /* partial_inplace */
595 0xffff, /* src_mask */
596 0xffff, /* dst_mask */
597 FALSE), /* pcrel_offset */
598
599 /* MOV[ZN]: ((S+A) >> 32) & 0xffff */
a6bb11b2 600 HOWTO64 (AARCH64_R (MOVW_SABS_G2), /* type */
a06ea964
NC
601 32, /* rightshift */
602 2, /* size (0 = byte, 1 = short, 2 = long) */
603 16, /* bitsize */
604 FALSE, /* pc_relative */
605 0, /* bitpos */
606 complain_overflow_signed, /* complain_on_overflow */
607 bfd_elf_generic_reloc, /* special_function */
a6bb11b2 608 AARCH64_R_STR (MOVW_SABS_G2), /* name */
a06ea964
NC
609 FALSE, /* partial_inplace */
610 0xffff, /* src_mask */
611 0xffff, /* dst_mask */
612 FALSE), /* pcrel_offset */
613
614/* Relocations to generate 19, 21 and 33 bit PC-relative load/store
615 addresses: PG(x) is (x & ~0xfff). */
616
617 /* LD-lit: ((S+A-P) >> 2) & 0x7ffff */
a6bb11b2 618 HOWTO (AARCH64_R (LD_PREL_LO19), /* type */
a06ea964
NC
619 2, /* rightshift */
620 2, /* size (0 = byte, 1 = short, 2 = long) */
621 19, /* bitsize */
622 TRUE, /* pc_relative */
623 0, /* bitpos */
624 complain_overflow_signed, /* complain_on_overflow */
625 bfd_elf_generic_reloc, /* special_function */
a6bb11b2 626 AARCH64_R_STR (LD_PREL_LO19), /* name */
a06ea964
NC
627 FALSE, /* partial_inplace */
628 0x7ffff, /* src_mask */
629 0x7ffff, /* dst_mask */
630 TRUE), /* pcrel_offset */
631
632 /* ADR: (S+A-P) & 0x1fffff */
a6bb11b2 633 HOWTO (AARCH64_R (ADR_PREL_LO21), /* type */
a06ea964
NC
634 0, /* rightshift */
635 2, /* size (0 = byte, 1 = short, 2 = long) */
636 21, /* bitsize */
637 TRUE, /* pc_relative */
638 0, /* bitpos */
639 complain_overflow_signed, /* complain_on_overflow */
640 bfd_elf_generic_reloc, /* special_function */
a6bb11b2 641 AARCH64_R_STR (ADR_PREL_LO21), /* name */
a06ea964
NC
642 FALSE, /* partial_inplace */
643 0x1fffff, /* src_mask */
644 0x1fffff, /* dst_mask */
645 TRUE), /* pcrel_offset */
646
647 /* ADRP: ((PG(S+A)-PG(P)) >> 12) & 0x1fffff */
a6bb11b2 648 HOWTO (AARCH64_R (ADR_PREL_PG_HI21), /* type */
a06ea964
NC
649 12, /* rightshift */
650 2, /* size (0 = byte, 1 = short, 2 = long) */
651 21, /* bitsize */
652 TRUE, /* pc_relative */
653 0, /* bitpos */
654 complain_overflow_signed, /* complain_on_overflow */
655 bfd_elf_generic_reloc, /* special_function */
a6bb11b2 656 AARCH64_R_STR (ADR_PREL_PG_HI21), /* name */
a06ea964
NC
657 FALSE, /* partial_inplace */
658 0x1fffff, /* src_mask */
659 0x1fffff, /* dst_mask */
660 TRUE), /* pcrel_offset */
661
662 /* ADRP: ((PG(S+A)-PG(P)) >> 12) & 0x1fffff [no overflow check] */
a6bb11b2 663 HOWTO64 (AARCH64_R (ADR_PREL_PG_HI21_NC), /* type */
a06ea964
NC
664 12, /* rightshift */
665 2, /* size (0 = byte, 1 = short, 2 = long) */
666 21, /* bitsize */
667 TRUE, /* pc_relative */
668 0, /* bitpos */
669 complain_overflow_dont, /* complain_on_overflow */
670 bfd_elf_generic_reloc, /* special_function */
a6bb11b2 671 AARCH64_R_STR (ADR_PREL_PG_HI21_NC), /* name */
a06ea964
NC
672 FALSE, /* partial_inplace */
673 0x1fffff, /* src_mask */
674 0x1fffff, /* dst_mask */
675 TRUE), /* pcrel_offset */
676
677 /* ADD: (S+A) & 0xfff [no overflow check] */
a6bb11b2 678 HOWTO (AARCH64_R (ADD_ABS_LO12_NC), /* type */
a06ea964
NC
679 0, /* rightshift */
680 2, /* size (0 = byte, 1 = short, 2 = long) */
681 12, /* bitsize */
682 FALSE, /* pc_relative */
683 10, /* bitpos */
684 complain_overflow_dont, /* complain_on_overflow */
685 bfd_elf_generic_reloc, /* special_function */
a6bb11b2 686 AARCH64_R_STR (ADD_ABS_LO12_NC), /* name */
a06ea964
NC
687 FALSE, /* partial_inplace */
688 0x3ffc00, /* src_mask */
689 0x3ffc00, /* dst_mask */
690 FALSE), /* pcrel_offset */
691
692 /* LD/ST8: (S+A) & 0xfff */
a6bb11b2 693 HOWTO (AARCH64_R (LDST8_ABS_LO12_NC), /* type */
a06ea964
NC
694 0, /* rightshift */
695 2, /* size (0 = byte, 1 = short, 2 = long) */
696 12, /* bitsize */
697 FALSE, /* pc_relative */
698 0, /* bitpos */
699 complain_overflow_dont, /* complain_on_overflow */
700 bfd_elf_generic_reloc, /* special_function */
a6bb11b2 701 AARCH64_R_STR (LDST8_ABS_LO12_NC), /* name */
a06ea964
NC
702 FALSE, /* partial_inplace */
703 0xfff, /* src_mask */
704 0xfff, /* dst_mask */
705 FALSE), /* pcrel_offset */
706
707 /* Relocations for control-flow instructions. */
708
709 /* TBZ/NZ: ((S+A-P) >> 2) & 0x3fff */
a6bb11b2 710 HOWTO (AARCH64_R (TSTBR14), /* type */
a06ea964
NC
711 2, /* rightshift */
712 2, /* size (0 = byte, 1 = short, 2 = long) */
713 14, /* bitsize */
714 TRUE, /* pc_relative */
715 0, /* bitpos */
716 complain_overflow_signed, /* complain_on_overflow */
717 bfd_elf_generic_reloc, /* special_function */
a6bb11b2 718 AARCH64_R_STR (TSTBR14), /* name */
a06ea964
NC
719 FALSE, /* partial_inplace */
720 0x3fff, /* src_mask */
721 0x3fff, /* dst_mask */
722 TRUE), /* pcrel_offset */
723
724 /* B.cond: ((S+A-P) >> 2) & 0x7ffff */
a6bb11b2 725 HOWTO (AARCH64_R (CONDBR19), /* type */
a06ea964
NC
726 2, /* rightshift */
727 2, /* size (0 = byte, 1 = short, 2 = long) */
728 19, /* bitsize */
729 TRUE, /* pc_relative */
730 0, /* bitpos */
731 complain_overflow_signed, /* complain_on_overflow */
732 bfd_elf_generic_reloc, /* special_function */
a6bb11b2 733 AARCH64_R_STR (CONDBR19), /* name */
a06ea964
NC
734 FALSE, /* partial_inplace */
735 0x7ffff, /* src_mask */
736 0x7ffff, /* dst_mask */
737 TRUE), /* pcrel_offset */
738
a06ea964 739 /* B: ((S+A-P) >> 2) & 0x3ffffff */
a6bb11b2 740 HOWTO (AARCH64_R (JUMP26), /* type */
a06ea964
NC
741 2, /* rightshift */
742 2, /* size (0 = byte, 1 = short, 2 = long) */
743 26, /* bitsize */
744 TRUE, /* pc_relative */
745 0, /* bitpos */
746 complain_overflow_signed, /* complain_on_overflow */
747 bfd_elf_generic_reloc, /* special_function */
a6bb11b2 748 AARCH64_R_STR (JUMP26), /* name */
a06ea964
NC
749 FALSE, /* partial_inplace */
750 0x3ffffff, /* src_mask */
751 0x3ffffff, /* dst_mask */
752 TRUE), /* pcrel_offset */
753
754 /* BL: ((S+A-P) >> 2) & 0x3ffffff */
a6bb11b2 755 HOWTO (AARCH64_R (CALL26), /* type */
a06ea964
NC
756 2, /* rightshift */
757 2, /* size (0 = byte, 1 = short, 2 = long) */
758 26, /* bitsize */
759 TRUE, /* pc_relative */
760 0, /* bitpos */
761 complain_overflow_signed, /* complain_on_overflow */
762 bfd_elf_generic_reloc, /* special_function */
a6bb11b2 763 AARCH64_R_STR (CALL26), /* name */
a06ea964
NC
764 FALSE, /* partial_inplace */
765 0x3ffffff, /* src_mask */
766 0x3ffffff, /* dst_mask */
767 TRUE), /* pcrel_offset */
768
769 /* LD/ST16: (S+A) & 0xffe */
a6bb11b2 770 HOWTO (AARCH64_R (LDST16_ABS_LO12_NC), /* type */
a06ea964
NC
771 1, /* rightshift */
772 2, /* size (0 = byte, 1 = short, 2 = long) */
773 12, /* bitsize */
774 FALSE, /* pc_relative */
775 0, /* bitpos */
776 complain_overflow_dont, /* complain_on_overflow */
777 bfd_elf_generic_reloc, /* special_function */
a6bb11b2 778 AARCH64_R_STR (LDST16_ABS_LO12_NC), /* name */
a06ea964
NC
779 FALSE, /* partial_inplace */
780 0xffe, /* src_mask */
781 0xffe, /* dst_mask */
782 FALSE), /* pcrel_offset */
783
784 /* LD/ST32: (S+A) & 0xffc */
a6bb11b2 785 HOWTO (AARCH64_R (LDST32_ABS_LO12_NC), /* type */
a06ea964
NC
786 2, /* rightshift */
787 2, /* size (0 = byte, 1 = short, 2 = long) */
788 12, /* bitsize */
789 FALSE, /* pc_relative */
790 0, /* bitpos */
791 complain_overflow_dont, /* complain_on_overflow */
792 bfd_elf_generic_reloc, /* special_function */
a6bb11b2 793 AARCH64_R_STR (LDST32_ABS_LO12_NC), /* name */
a06ea964
NC
794 FALSE, /* partial_inplace */
795 0xffc, /* src_mask */
796 0xffc, /* dst_mask */
797 FALSE), /* pcrel_offset */
798
799 /* LD/ST64: (S+A) & 0xff8 */
a6bb11b2 800 HOWTO (AARCH64_R (LDST64_ABS_LO12_NC), /* type */
a06ea964
NC
801 3, /* rightshift */
802 2, /* size (0 = byte, 1 = short, 2 = long) */
803 12, /* bitsize */
804 FALSE, /* pc_relative */
805 0, /* bitpos */
806 complain_overflow_dont, /* complain_on_overflow */
807 bfd_elf_generic_reloc, /* special_function */
a6bb11b2 808 AARCH64_R_STR (LDST64_ABS_LO12_NC), /* name */
a06ea964
NC
809 FALSE, /* partial_inplace */
810 0xff8, /* src_mask */
811 0xff8, /* dst_mask */
812 FALSE), /* pcrel_offset */
813
a06ea964 814 /* LD/ST128: (S+A) & 0xff0 */
a6bb11b2 815 HOWTO (AARCH64_R (LDST128_ABS_LO12_NC), /* type */
a06ea964
NC
816 4, /* rightshift */
817 2, /* size (0 = byte, 1 = short, 2 = long) */
818 12, /* bitsize */
819 FALSE, /* pc_relative */
820 0, /* bitpos */
821 complain_overflow_dont, /* complain_on_overflow */
822 bfd_elf_generic_reloc, /* special_function */
a6bb11b2 823 AARCH64_R_STR (LDST128_ABS_LO12_NC), /* name */
a06ea964
NC
824 FALSE, /* partial_inplace */
825 0xff0, /* src_mask */
826 0xff0, /* dst_mask */
827 FALSE), /* pcrel_offset */
828
f41aef5f
RE
829 /* Set a load-literal immediate field to bits
830 0x1FFFFC of G(S)-P */
a6bb11b2 831 HOWTO (AARCH64_R (GOT_LD_PREL19), /* type */
f41aef5f
RE
832 2, /* rightshift */
833 2, /* size (0 = byte,1 = short,2 = long) */
834 19, /* bitsize */
835 TRUE, /* pc_relative */
836 0, /* bitpos */
837 complain_overflow_signed, /* complain_on_overflow */
838 bfd_elf_generic_reloc, /* special_function */
a6bb11b2 839 AARCH64_R_STR (GOT_LD_PREL19), /* name */
f41aef5f
RE
840 FALSE, /* partial_inplace */
841 0xffffe0, /* src_mask */
842 0xffffe0, /* dst_mask */
843 TRUE), /* pcrel_offset */
844
a06ea964
NC
845 /* Get to the page for the GOT entry for the symbol
846 (G(S) - P) using an ADRP instruction. */
a6bb11b2 847 HOWTO (AARCH64_R (ADR_GOT_PAGE), /* type */
a06ea964
NC
848 12, /* rightshift */
849 2, /* size (0 = byte, 1 = short, 2 = long) */
850 21, /* bitsize */
851 TRUE, /* pc_relative */
852 0, /* bitpos */
853 complain_overflow_dont, /* complain_on_overflow */
854 bfd_elf_generic_reloc, /* special_function */
a6bb11b2 855 AARCH64_R_STR (ADR_GOT_PAGE), /* name */
a06ea964
NC
856 FALSE, /* partial_inplace */
857 0x1fffff, /* src_mask */
858 0x1fffff, /* dst_mask */
859 TRUE), /* pcrel_offset */
860
a6bb11b2
YZ
861 /* LD64: GOT offset G(S) & 0xff8 */
862 HOWTO64 (AARCH64_R (LD64_GOT_LO12_NC), /* type */
a06ea964
NC
863 3, /* rightshift */
864 2, /* size (0 = byte, 1 = short, 2 = long) */
865 12, /* bitsize */
866 FALSE, /* pc_relative */
867 0, /* bitpos */
868 complain_overflow_dont, /* complain_on_overflow */
869 bfd_elf_generic_reloc, /* special_function */
a6bb11b2 870 AARCH64_R_STR (LD64_GOT_LO12_NC), /* name */
a06ea964
NC
871 FALSE, /* partial_inplace */
872 0xff8, /* src_mask */
873 0xff8, /* dst_mask */
a6bb11b2 874 FALSE), /* pcrel_offset */
a06ea964 875
a6bb11b2
YZ
876 /* LD32: GOT offset G(S) & 0xffc */
877 HOWTO32 (AARCH64_R (LD32_GOT_LO12_NC), /* type */
878 2, /* rightshift */
879 2, /* size (0 = byte, 1 = short, 2 = long) */
880 12, /* bitsize */
881 FALSE, /* pc_relative */
882 0, /* bitpos */
883 complain_overflow_dont, /* complain_on_overflow */
884 bfd_elf_generic_reloc, /* special_function */
885 AARCH64_R_STR (LD32_GOT_LO12_NC), /* name */
886 FALSE, /* partial_inplace */
887 0xffc, /* src_mask */
888 0xffc, /* dst_mask */
889 FALSE), /* pcrel_offset */
a06ea964 890
ca632371
RL
891 /* Lower 16 bits of GOT offset for the symbol. */
892 HOWTO64 (AARCH64_R (MOVW_GOTOFF_G0_NC), /* type */
893 0, /* rightshift */
894 2, /* size (0 = byte, 1 = short, 2 = long) */
895 16, /* bitsize */
896 FALSE, /* pc_relative */
897 0, /* bitpos */
898 complain_overflow_dont, /* complain_on_overflow */
899 bfd_elf_generic_reloc, /* special_function */
900 AARCH64_R_STR (MOVW_GOTOFF_G0_NC), /* name */
901 FALSE, /* partial_inplace */
902 0xffff, /* src_mask */
903 0xffff, /* dst_mask */
904 FALSE), /* pcrel_offset */
905
654248e7
RL
906 /* Higher 16 bits of GOT offset for the symbol. */
907 HOWTO64 (AARCH64_R (MOVW_GOTOFF_G1), /* type */
908 16, /* rightshift */
909 2, /* size (0 = byte, 1 = short, 2 = long) */
910 16, /* bitsize */
911 FALSE, /* pc_relative */
912 0, /* bitpos */
913 complain_overflow_unsigned, /* complain_on_overflow */
914 bfd_elf_generic_reloc, /* special_function */
915 AARCH64_R_STR (MOVW_GOTOFF_G1), /* name */
916 FALSE, /* partial_inplace */
917 0xffff, /* src_mask */
918 0xffff, /* dst_mask */
919 FALSE), /* pcrel_offset */
920
87f5fbcc
RL
921 /* LD64: GOT offset for the symbol. */
922 HOWTO64 (AARCH64_R (LD64_GOTOFF_LO15), /* type */
923 3, /* rightshift */
924 2, /* size (0 = byte, 1 = short, 2 = long) */
925 12, /* bitsize */
926 FALSE, /* pc_relative */
927 0, /* bitpos */
928 complain_overflow_unsigned, /* complain_on_overflow */
929 bfd_elf_generic_reloc, /* special_function */
930 AARCH64_R_STR (LD64_GOTOFF_LO15), /* name */
931 FALSE, /* partial_inplace */
932 0x7ff8, /* src_mask */
933 0x7ff8, /* dst_mask */
934 FALSE), /* pcrel_offset */
935
3d715ce4
JW
936 /* LD32: GOT offset to the page address of GOT table.
937 (G(S) - PAGE (_GLOBAL_OFFSET_TABLE_)) & 0x5ffc. */
938 HOWTO32 (AARCH64_R (LD32_GOTPAGE_LO14), /* type */
939 2, /* rightshift */
940 2, /* size (0 = byte, 1 = short, 2 = long) */
941 12, /* bitsize */
942 FALSE, /* pc_relative */
943 0, /* bitpos */
944 complain_overflow_unsigned, /* complain_on_overflow */
945 bfd_elf_generic_reloc, /* special_function */
946 AARCH64_R_STR (LD32_GOTPAGE_LO14), /* name */
947 FALSE, /* partial_inplace */
948 0x5ffc, /* src_mask */
949 0x5ffc, /* dst_mask */
950 FALSE), /* pcrel_offset */
951
a921b5bd
JW
952 /* LD64: GOT offset to the page address of GOT table.
953 (G(S) - PAGE (_GLOBAL_OFFSET_TABLE_)) & 0x7ff8. */
954 HOWTO64 (AARCH64_R (LD64_GOTPAGE_LO15), /* type */
955 3, /* rightshift */
956 2, /* size (0 = byte, 1 = short, 2 = long) */
957 12, /* bitsize */
958 FALSE, /* pc_relative */
959 0, /* bitpos */
960 complain_overflow_unsigned, /* complain_on_overflow */
961 bfd_elf_generic_reloc, /* special_function */
962 AARCH64_R_STR (LD64_GOTPAGE_LO15), /* name */
963 FALSE, /* partial_inplace */
964 0x7ff8, /* src_mask */
965 0x7ff8, /* dst_mask */
966 FALSE), /* pcrel_offset */
967
a06ea964
NC
968 /* Get to the page for the GOT entry for the symbol
969 (G(S) - P) using an ADRP instruction. */
a6bb11b2 970 HOWTO (AARCH64_R (TLSGD_ADR_PAGE21), /* type */
a06ea964
NC
971 12, /* rightshift */
972 2, /* size (0 = byte, 1 = short, 2 = long) */
973 21, /* bitsize */
974 TRUE, /* pc_relative */
975 0, /* bitpos */
976 complain_overflow_dont, /* complain_on_overflow */
977 bfd_elf_generic_reloc, /* special_function */
a6bb11b2 978 AARCH64_R_STR (TLSGD_ADR_PAGE21), /* name */
a06ea964
NC
979 FALSE, /* partial_inplace */
980 0x1fffff, /* src_mask */
981 0x1fffff, /* dst_mask */
982 TRUE), /* pcrel_offset */
983
3c12b054
MS
984 HOWTO (AARCH64_R (TLSGD_ADR_PREL21), /* type */
985 0, /* rightshift */
986 2, /* size (0 = byte, 1 = short, 2 = long) */
987 21, /* bitsize */
988 TRUE, /* pc_relative */
989 0, /* bitpos */
990 complain_overflow_dont, /* complain_on_overflow */
991 bfd_elf_generic_reloc, /* special_function */
992 AARCH64_R_STR (TLSGD_ADR_PREL21), /* name */
993 FALSE, /* partial_inplace */
994 0x1fffff, /* src_mask */
995 0x1fffff, /* dst_mask */
996 TRUE), /* pcrel_offset */
997
a06ea964 998 /* ADD: GOT offset G(S) & 0xff8 [no overflow check] */
a6bb11b2 999 HOWTO (AARCH64_R (TLSGD_ADD_LO12_NC), /* type */
a06ea964
NC
1000 0, /* rightshift */
1001 2, /* size (0 = byte, 1 = short, 2 = long) */
1002 12, /* bitsize */
1003 FALSE, /* pc_relative */
1004 0, /* bitpos */
1005 complain_overflow_dont, /* complain_on_overflow */
1006 bfd_elf_generic_reloc, /* special_function */
a6bb11b2 1007 AARCH64_R_STR (TLSGD_ADD_LO12_NC), /* name */
a06ea964
NC
1008 FALSE, /* partial_inplace */
1009 0xfff, /* src_mask */
1010 0xfff, /* dst_mask */
1011 FALSE), /* pcrel_offset */
1012
3e8286c0
RL
1013 /* Lower 16 bits of GOT offset to tls_index. */
1014 HOWTO64 (AARCH64_R (TLSGD_MOVW_G0_NC), /* type */
1015 0, /* rightshift */
1016 2, /* size (0 = byte, 1 = short, 2 = long) */
1017 16, /* bitsize */
1018 FALSE, /* pc_relative */
1019 0, /* bitpos */
1020 complain_overflow_dont, /* complain_on_overflow */
1021 bfd_elf_generic_reloc, /* special_function */
1022 AARCH64_R_STR (TLSGD_MOVW_G0_NC), /* name */
1023 FALSE, /* partial_inplace */
1024 0xffff, /* src_mask */
1025 0xffff, /* dst_mask */
1026 FALSE), /* pcrel_offset */
1027
1aa66fb1
RL
1028 /* Higher 16 bits of GOT offset to tls_index. */
1029 HOWTO64 (AARCH64_R (TLSGD_MOVW_G1), /* type */
1030 16, /* rightshift */
1031 2, /* size (0 = byte, 1 = short, 2 = long) */
1032 16, /* bitsize */
1033 FALSE, /* pc_relative */
1034 0, /* bitpos */
1035 complain_overflow_unsigned, /* complain_on_overflow */
1036 bfd_elf_generic_reloc, /* special_function */
1037 AARCH64_R_STR (TLSGD_MOVW_G1), /* name */
1038 FALSE, /* partial_inplace */
1039 0xffff, /* src_mask */
1040 0xffff, /* dst_mask */
1041 FALSE), /* pcrel_offset */
1042
a6bb11b2 1043 HOWTO (AARCH64_R (TLSIE_ADR_GOTTPREL_PAGE21), /* type */
a06ea964
NC
1044 12, /* rightshift */
1045 2, /* size (0 = byte, 1 = short, 2 = long) */
1046 21, /* bitsize */
1047 FALSE, /* pc_relative */
1048 0, /* bitpos */
1049 complain_overflow_dont, /* complain_on_overflow */
1050 bfd_elf_generic_reloc, /* special_function */
a6bb11b2 1051 AARCH64_R_STR (TLSIE_ADR_GOTTPREL_PAGE21), /* name */
a06ea964
NC
1052 FALSE, /* partial_inplace */
1053 0x1fffff, /* src_mask */
1054 0x1fffff, /* dst_mask */
1055 FALSE), /* pcrel_offset */
1056
a6bb11b2 1057 HOWTO64 (AARCH64_R (TLSIE_LD64_GOTTPREL_LO12_NC), /* type */
a06ea964
NC
1058 3, /* rightshift */
1059 2, /* size (0 = byte, 1 = short, 2 = long) */
1060 12, /* bitsize */
1061 FALSE, /* pc_relative */
1062 0, /* bitpos */
1063 complain_overflow_dont, /* complain_on_overflow */
1064 bfd_elf_generic_reloc, /* special_function */
a6bb11b2 1065 AARCH64_R_STR (TLSIE_LD64_GOTTPREL_LO12_NC), /* name */
a06ea964
NC
1066 FALSE, /* partial_inplace */
1067 0xff8, /* src_mask */
1068 0xff8, /* dst_mask */
1069 FALSE), /* pcrel_offset */
1070
a6bb11b2
YZ
1071 HOWTO32 (AARCH64_R (TLSIE_LD32_GOTTPREL_LO12_NC), /* type */
1072 2, /* rightshift */
1073 2, /* size (0 = byte, 1 = short, 2 = long) */
1074 12, /* bitsize */
1075 FALSE, /* pc_relative */
1076 0, /* bitpos */
1077 complain_overflow_dont, /* complain_on_overflow */
1078 bfd_elf_generic_reloc, /* special_function */
1079 AARCH64_R_STR (TLSIE_LD32_GOTTPREL_LO12_NC), /* name */
1080 FALSE, /* partial_inplace */
1081 0xffc, /* src_mask */
1082 0xffc, /* dst_mask */
1083 FALSE), /* pcrel_offset */
1084
1085 HOWTO (AARCH64_R (TLSIE_LD_GOTTPREL_PREL19), /* type */
bb3f9ed8 1086 2, /* rightshift */
a06ea964 1087 2, /* size (0 = byte, 1 = short, 2 = long) */
043bf05a 1088 19, /* bitsize */
a06ea964
NC
1089 FALSE, /* pc_relative */
1090 0, /* bitpos */
1091 complain_overflow_dont, /* complain_on_overflow */
1092 bfd_elf_generic_reloc, /* special_function */
a6bb11b2 1093 AARCH64_R_STR (TLSIE_LD_GOTTPREL_PREL19), /* name */
a06ea964
NC
1094 FALSE, /* partial_inplace */
1095 0x1ffffc, /* src_mask */
1096 0x1ffffc, /* dst_mask */
1097 FALSE), /* pcrel_offset */
1098
3b957e5b
RL
1099 HOWTO64 (AARCH64_R (TLSIE_MOVW_GOTTPREL_G0_NC), /* type */
1100 0, /* rightshift */
1101 2, /* size (0 = byte, 1 = short, 2 = long) */
1102 16, /* bitsize */
1103 FALSE, /* pc_relative */
1104 0, /* bitpos */
1105 complain_overflow_dont, /* complain_on_overflow */
1106 bfd_elf_generic_reloc, /* special_function */
1107 AARCH64_R_STR (TLSIE_MOVW_GOTTPREL_G0_NC), /* name */
1108 FALSE, /* partial_inplace */
1109 0xffff, /* src_mask */
1110 0xffff, /* dst_mask */
1111 FALSE), /* pcrel_offset */
1112
1113 HOWTO64 (AARCH64_R (TLSIE_MOVW_GOTTPREL_G1), /* type */
1114 16, /* rightshift */
1115 2, /* size (0 = byte, 1 = short, 2 = long) */
1116 16, /* bitsize */
1117 FALSE, /* pc_relative */
1118 0, /* bitpos */
1119 complain_overflow_unsigned, /* complain_on_overflow */
1120 bfd_elf_generic_reloc, /* special_function */
1121 AARCH64_R_STR (TLSIE_MOVW_GOTTPREL_G1), /* name */
1122 FALSE, /* partial_inplace */
1123 0xffff, /* src_mask */
1124 0xffff, /* dst_mask */
1125 FALSE), /* pcrel_offset */
1126
49df5539
JW
1127 /* ADD: bit[23:12] of byte offset to module TLS base address. */
1128 HOWTO (AARCH64_R (TLSLD_ADD_DTPREL_HI12), /* type */
1129 12, /* rightshift */
1130 2, /* size (0 = byte, 1 = short, 2 = long) */
1131 12, /* bitsize */
1132 FALSE, /* pc_relative */
1133 0, /* bitpos */
1134 complain_overflow_unsigned, /* complain_on_overflow */
1135 bfd_elf_generic_reloc, /* special_function */
1136 AARCH64_R_STR (TLSLD_ADD_DTPREL_HI12), /* name */
1137 FALSE, /* partial_inplace */
1138 0xfff, /* src_mask */
1139 0xfff, /* dst_mask */
1140 FALSE), /* pcrel_offset */
1141
70151fb5
JW
1142 /* Unsigned 12 bit byte offset to module TLS base address. */
1143 HOWTO (AARCH64_R (TLSLD_ADD_DTPREL_LO12), /* type */
1144 0, /* rightshift */
1145 2, /* size (0 = byte, 1 = short, 2 = long) */
1146 12, /* bitsize */
1147 FALSE, /* pc_relative */
1148 0, /* bitpos */
1149 complain_overflow_unsigned, /* complain_on_overflow */
1150 bfd_elf_generic_reloc, /* special_function */
1151 AARCH64_R_STR (TLSLD_ADD_DTPREL_LO12), /* name */
1152 FALSE, /* partial_inplace */
1153 0xfff, /* src_mask */
1154 0xfff, /* dst_mask */
1155 FALSE), /* pcrel_offset */
13289c10
JW
1156
1157 /* No overflow check version of BFD_RELOC_AARCH64_TLSLD_ADD_DTPREL_LO12. */
1158 HOWTO (AARCH64_R (TLSLD_ADD_DTPREL_LO12_NC), /* type */
1159 0, /* rightshift */
1160 2, /* size (0 = byte, 1 = short, 2 = long) */
1161 12, /* bitsize */
1162 FALSE, /* pc_relative */
1163 0, /* bitpos */
1164 complain_overflow_dont, /* complain_on_overflow */
1165 bfd_elf_generic_reloc, /* special_function */
1166 AARCH64_R_STR (TLSLD_ADD_DTPREL_LO12_NC), /* name */
1167 FALSE, /* partial_inplace */
1168 0xfff, /* src_mask */
1169 0xfff, /* dst_mask */
1170 FALSE), /* pcrel_offset */
70151fb5 1171
a12fad50
JW
1172 /* ADD: GOT offset G(S) & 0xff8 [no overflow check] */
1173 HOWTO (AARCH64_R (TLSLD_ADD_LO12_NC), /* type */
1174 0, /* rightshift */
1175 2, /* size (0 = byte, 1 = short, 2 = long) */
1176 12, /* bitsize */
1177 FALSE, /* pc_relative */
1178 0, /* bitpos */
1179 complain_overflow_dont, /* complain_on_overflow */
1180 bfd_elf_generic_reloc, /* special_function */
1181 AARCH64_R_STR (TLSLD_ADD_LO12_NC), /* name */
1182 FALSE, /* partial_inplace */
1183 0xfff, /* src_mask */
1184 0xfff, /* dst_mask */
1185 FALSE), /* pcrel_offset */
1186
1107e076
JW
1187 /* Get to the page for the GOT entry for the symbol
1188 (G(S) - P) using an ADRP instruction. */
1189 HOWTO (AARCH64_R (TLSLD_ADR_PAGE21), /* type */
1190 12, /* rightshift */
1191 2, /* size (0 = byte, 1 = short, 2 = long) */
1192 21, /* bitsize */
1193 TRUE, /* pc_relative */
1194 0, /* bitpos */
1195 complain_overflow_signed, /* complain_on_overflow */
1196 bfd_elf_generic_reloc, /* special_function */
1197 AARCH64_R_STR (TLSLD_ADR_PAGE21), /* name */
1198 FALSE, /* partial_inplace */
1199 0x1fffff, /* src_mask */
1200 0x1fffff, /* dst_mask */
1201 TRUE), /* pcrel_offset */
1202
6c37fedc
JW
1203 HOWTO (AARCH64_R (TLSLD_ADR_PREL21), /* type */
1204 0, /* rightshift */
1205 2, /* size (0 = byte, 1 = short, 2 = long) */
1206 21, /* bitsize */
1207 TRUE, /* pc_relative */
1208 0, /* bitpos */
1209 complain_overflow_signed, /* complain_on_overflow */
1210 bfd_elf_generic_reloc, /* special_function */
1211 AARCH64_R_STR (TLSLD_ADR_PREL21), /* name */
1212 FALSE, /* partial_inplace */
1213 0x1fffff, /* src_mask */
1214 0x1fffff, /* dst_mask */
1215 TRUE), /* pcrel_offset */
1216
4c562523
JW
1217 /* LD/ST16: bit[11:1] of byte offset to module TLS base address. */
1218 HOWTO64 (AARCH64_R (TLSLD_LDST16_DTPREL_LO12), /* type */
1219 1, /* rightshift */
1220 2, /* size (0 = byte, 1 = short, 2 = long) */
1221 11, /* bitsize */
1222 FALSE, /* pc_relative */
1223 10, /* bitpos */
1224 complain_overflow_unsigned, /* complain_on_overflow */
1225 bfd_elf_generic_reloc, /* special_function */
1226 AARCH64_R_STR (TLSLD_LDST16_DTPREL_LO12), /* name */
1227 FALSE, /* partial_inplace */
1228 0x1ffc00, /* src_mask */
1229 0x1ffc00, /* dst_mask */
1230 FALSE), /* pcrel_offset */
1231
1232 /* Same as BFD_RELOC_AARCH64_TLSLD_LDST16_DTPREL_LO12, but no overflow check. */
1233 HOWTO64 (AARCH64_R (TLSLD_LDST16_DTPREL_LO12_NC), /* type */
1234 1, /* rightshift */
1235 2, /* size (0 = byte, 1 = short, 2 = long) */
1236 11, /* bitsize */
1237 FALSE, /* pc_relative */
1238 10, /* bitpos */
1239 complain_overflow_dont, /* complain_on_overflow */
1240 bfd_elf_generic_reloc, /* special_function */
1241 AARCH64_R_STR (TLSLD_LDST16_DTPREL_LO12_NC), /* name */
1242 FALSE, /* partial_inplace */
1243 0x1ffc00, /* src_mask */
1244 0x1ffc00, /* dst_mask */
1245 FALSE), /* pcrel_offset */
1246
1247 /* LD/ST32: bit[11:2] of byte offset to module TLS base address. */
1248 HOWTO64 (AARCH64_R (TLSLD_LDST32_DTPREL_LO12), /* type */
1249 2, /* rightshift */
1250 2, /* size (0 = byte, 1 = short, 2 = long) */
1251 10, /* bitsize */
1252 FALSE, /* pc_relative */
1253 10, /* bitpos */
1254 complain_overflow_unsigned, /* complain_on_overflow */
1255 bfd_elf_generic_reloc, /* special_function */
1256 AARCH64_R_STR (TLSLD_LDST32_DTPREL_LO12), /* name */
1257 FALSE, /* partial_inplace */
1258 0x3ffc00, /* src_mask */
1259 0x3ffc00, /* dst_mask */
1260 FALSE), /* pcrel_offset */
1261
1262 /* Same as BFD_RELOC_AARCH64_TLSLD_LDST32_DTPREL_LO12, but no overflow check. */
1263 HOWTO64 (AARCH64_R (TLSLD_LDST32_DTPREL_LO12_NC), /* type */
1264 2, /* rightshift */
1265 2, /* size (0 = byte, 1 = short, 2 = long) */
1266 10, /* bitsize */
1267 FALSE, /* pc_relative */
1268 10, /* bitpos */
1269 complain_overflow_dont, /* complain_on_overflow */
1270 bfd_elf_generic_reloc, /* special_function */
1271 AARCH64_R_STR (TLSLD_LDST32_DTPREL_LO12_NC), /* name */
1272 FALSE, /* partial_inplace */
1273 0xffc00, /* src_mask */
1274 0xffc00, /* dst_mask */
1275 FALSE), /* pcrel_offset */
1276
1277 /* LD/ST64: bit[11:3] of byte offset to module TLS base address. */
1278 HOWTO64 (AARCH64_R (TLSLD_LDST64_DTPREL_LO12), /* type */
1279 3, /* rightshift */
1280 2, /* size (0 = byte, 1 = short, 2 = long) */
1281 9, /* bitsize */
1282 FALSE, /* pc_relative */
1283 10, /* bitpos */
1284 complain_overflow_unsigned, /* complain_on_overflow */
1285 bfd_elf_generic_reloc, /* special_function */
1286 AARCH64_R_STR (TLSLD_LDST64_DTPREL_LO12), /* name */
1287 FALSE, /* partial_inplace */
1288 0x3ffc00, /* src_mask */
1289 0x3ffc00, /* dst_mask */
1290 FALSE), /* pcrel_offset */
1291
1292 /* Same as BFD_RELOC_AARCH64_TLSLD_LDST64_DTPREL_LO12, but no overflow check. */
1293 HOWTO64 (AARCH64_R (TLSLD_LDST64_DTPREL_LO12_NC), /* type */
1294 3, /* rightshift */
1295 2, /* size (0 = byte, 1 = short, 2 = long) */
1296 9, /* bitsize */
1297 FALSE, /* pc_relative */
1298 10, /* bitpos */
1299 complain_overflow_dont, /* complain_on_overflow */
1300 bfd_elf_generic_reloc, /* special_function */
1301 AARCH64_R_STR (TLSLD_LDST64_DTPREL_LO12_NC), /* name */
1302 FALSE, /* partial_inplace */
1303 0x7fc00, /* src_mask */
1304 0x7fc00, /* dst_mask */
1305 FALSE), /* pcrel_offset */
1306
1307 /* LD/ST8: bit[11:0] of byte offset to module TLS base address. */
1308 HOWTO64 (AARCH64_R (TLSLD_LDST8_DTPREL_LO12), /* type */
1309 0, /* rightshift */
1310 2, /* size (0 = byte, 1 = short, 2 = long) */
1311 12, /* bitsize */
1312 FALSE, /* pc_relative */
1313 10, /* bitpos */
1314 complain_overflow_unsigned, /* complain_on_overflow */
1315 bfd_elf_generic_reloc, /* special_function */
1316 AARCH64_R_STR (TLSLD_LDST8_DTPREL_LO12), /* name */
1317 FALSE, /* partial_inplace */
1318 0x3ffc00, /* src_mask */
1319 0x3ffc00, /* dst_mask */
1320 FALSE), /* pcrel_offset */
1321
1322 /* Same as BFD_RELOC_AARCH64_TLSLD_LDST8_DTPREL_LO12, but no overflow check. */
1323 HOWTO64 (AARCH64_R (TLSLD_LDST8_DTPREL_LO12_NC), /* type */
1324 0, /* rightshift */
1325 2, /* size (0 = byte, 1 = short, 2 = long) */
1326 12, /* bitsize */
1327 FALSE, /* pc_relative */
1328 10, /* bitpos */
1329 complain_overflow_dont, /* complain_on_overflow */
1330 bfd_elf_generic_reloc, /* special_function */
1331 AARCH64_R_STR (TLSLD_LDST8_DTPREL_LO12_NC), /* name */
1332 FALSE, /* partial_inplace */
1333 0x3ffc00, /* src_mask */
1334 0x3ffc00, /* dst_mask */
1335 FALSE), /* pcrel_offset */
1336
49df5539
JW
1337 /* MOVZ: bit[15:0] of byte offset to module TLS base address. */
1338 HOWTO (AARCH64_R (TLSLD_MOVW_DTPREL_G0), /* type */
1339 0, /* rightshift */
1340 2, /* size (0 = byte, 1 = short, 2 = long) */
1341 16, /* bitsize */
1342 FALSE, /* pc_relative */
1343 0, /* bitpos */
1344 complain_overflow_unsigned, /* complain_on_overflow */
1345 bfd_elf_generic_reloc, /* special_function */
1346 AARCH64_R_STR (TLSLD_MOVW_DTPREL_G0), /* name */
1347 FALSE, /* partial_inplace */
1348 0xffff, /* src_mask */
1349 0xffff, /* dst_mask */
1350 FALSE), /* pcrel_offset */
1351
1352 /* No overflow check version of BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G0. */
1353 HOWTO (AARCH64_R (TLSLD_MOVW_DTPREL_G0_NC), /* type */
1354 0, /* rightshift */
1355 2, /* size (0 = byte, 1 = short, 2 = long) */
1356 16, /* bitsize */
1357 FALSE, /* pc_relative */
1358 0, /* bitpos */
1359 complain_overflow_dont, /* complain_on_overflow */
1360 bfd_elf_generic_reloc, /* special_function */
1361 AARCH64_R_STR (TLSLD_MOVW_DTPREL_G0_NC), /* name */
1362 FALSE, /* partial_inplace */
1363 0xffff, /* src_mask */
1364 0xffff, /* dst_mask */
1365 FALSE), /* pcrel_offset */
1366
1367 /* MOVZ: bit[31:16] of byte offset to module TLS base address. */
1368 HOWTO (AARCH64_R (TLSLD_MOVW_DTPREL_G1), /* type */
1369 16, /* rightshift */
1370 2, /* size (0 = byte, 1 = short, 2 = long) */
1371 16, /* bitsize */
1372 FALSE, /* pc_relative */
1373 0, /* bitpos */
1374 complain_overflow_unsigned, /* complain_on_overflow */
1375 bfd_elf_generic_reloc, /* special_function */
1376 AARCH64_R_STR (TLSLD_MOVW_DTPREL_G1), /* name */
1377 FALSE, /* partial_inplace */
1378 0xffff, /* src_mask */
1379 0xffff, /* dst_mask */
1380 FALSE), /* pcrel_offset */
1381
1382 /* No overflow check version of BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G1. */
1383 HOWTO64 (AARCH64_R (TLSLD_MOVW_DTPREL_G1_NC), /* type */
1384 16, /* rightshift */
1385 2, /* size (0 = byte, 1 = short, 2 = long) */
1386 16, /* bitsize */
1387 FALSE, /* pc_relative */
1388 0, /* bitpos */
1389 complain_overflow_dont, /* complain_on_overflow */
1390 bfd_elf_generic_reloc, /* special_function */
1391 AARCH64_R_STR (TLSLD_MOVW_DTPREL_G1_NC), /* name */
1392 FALSE, /* partial_inplace */
1393 0xffff, /* src_mask */
1394 0xffff, /* dst_mask */
1395 FALSE), /* pcrel_offset */
1396
1397 /* MOVZ: bit[47:32] of byte offset to module TLS base address. */
1398 HOWTO64 (AARCH64_R (TLSLD_MOVW_DTPREL_G2), /* type */
1399 32, /* rightshift */
1400 2, /* size (0 = byte, 1 = short, 2 = long) */
1401 16, /* bitsize */
1402 FALSE, /* pc_relative */
1403 0, /* bitpos */
1404 complain_overflow_unsigned, /* complain_on_overflow */
1405 bfd_elf_generic_reloc, /* special_function */
1406 AARCH64_R_STR (TLSLD_MOVW_DTPREL_G2), /* name */
1407 FALSE, /* partial_inplace */
1408 0xffff, /* src_mask */
1409 0xffff, /* dst_mask */
1410 FALSE), /* pcrel_offset */
1411
a6bb11b2 1412 HOWTO64 (AARCH64_R (TLSLE_MOVW_TPREL_G2), /* type */
bb3f9ed8 1413 32, /* rightshift */
a06ea964 1414 2, /* size (0 = byte, 1 = short, 2 = long) */
07875fbc 1415 16, /* bitsize */
a06ea964
NC
1416 FALSE, /* pc_relative */
1417 0, /* bitpos */
0172429c 1418 complain_overflow_unsigned, /* complain_on_overflow */
a06ea964 1419 bfd_elf_generic_reloc, /* special_function */
a6bb11b2 1420 AARCH64_R_STR (TLSLE_MOVW_TPREL_G2), /* name */
a06ea964
NC
1421 FALSE, /* partial_inplace */
1422 0xffff, /* src_mask */
1423 0xffff, /* dst_mask */
1424 FALSE), /* pcrel_offset */
1425
a6bb11b2 1426 HOWTO (AARCH64_R (TLSLE_MOVW_TPREL_G1), /* type */
bb3f9ed8 1427 16, /* rightshift */
a06ea964 1428 2, /* size (0 = byte, 1 = short, 2 = long) */
07875fbc 1429 16, /* bitsize */
a06ea964
NC
1430 FALSE, /* pc_relative */
1431 0, /* bitpos */
1432 complain_overflow_dont, /* complain_on_overflow */
1433 bfd_elf_generic_reloc, /* special_function */
a6bb11b2 1434 AARCH64_R_STR (TLSLE_MOVW_TPREL_G1), /* name */
a06ea964
NC
1435 FALSE, /* partial_inplace */
1436 0xffff, /* src_mask */
1437 0xffff, /* dst_mask */
1438 FALSE), /* pcrel_offset */
1439
a6bb11b2 1440 HOWTO64 (AARCH64_R (TLSLE_MOVW_TPREL_G1_NC), /* type */
bb3f9ed8 1441 16, /* rightshift */
a06ea964 1442 2, /* size (0 = byte, 1 = short, 2 = long) */
07875fbc 1443 16, /* bitsize */
a06ea964
NC
1444 FALSE, /* pc_relative */
1445 0, /* bitpos */
1446 complain_overflow_dont, /* complain_on_overflow */
1447 bfd_elf_generic_reloc, /* special_function */
a6bb11b2 1448 AARCH64_R_STR (TLSLE_MOVW_TPREL_G1_NC), /* name */
a06ea964
NC
1449 FALSE, /* partial_inplace */
1450 0xffff, /* src_mask */
1451 0xffff, /* dst_mask */
1452 FALSE), /* pcrel_offset */
1453
a6bb11b2 1454 HOWTO (AARCH64_R (TLSLE_MOVW_TPREL_G0), /* type */
a06ea964
NC
1455 0, /* rightshift */
1456 2, /* size (0 = byte, 1 = short, 2 = long) */
07875fbc 1457 16, /* bitsize */
a06ea964
NC
1458 FALSE, /* pc_relative */
1459 0, /* bitpos */
1460 complain_overflow_dont, /* complain_on_overflow */
1461 bfd_elf_generic_reloc, /* special_function */
a6bb11b2 1462 AARCH64_R_STR (TLSLE_MOVW_TPREL_G0), /* name */
a06ea964
NC
1463 FALSE, /* partial_inplace */
1464 0xffff, /* src_mask */
1465 0xffff, /* dst_mask */
1466 FALSE), /* pcrel_offset */
1467
a6bb11b2 1468 HOWTO (AARCH64_R (TLSLE_MOVW_TPREL_G0_NC), /* type */
a06ea964
NC
1469 0, /* rightshift */
1470 2, /* size (0 = byte, 1 = short, 2 = long) */
07875fbc 1471 16, /* bitsize */
a06ea964
NC
1472 FALSE, /* pc_relative */
1473 0, /* bitpos */
1474 complain_overflow_dont, /* complain_on_overflow */
1475 bfd_elf_generic_reloc, /* special_function */
a6bb11b2 1476 AARCH64_R_STR (TLSLE_MOVW_TPREL_G0_NC), /* name */
a06ea964
NC
1477 FALSE, /* partial_inplace */
1478 0xffff, /* src_mask */
1479 0xffff, /* dst_mask */
1480 FALSE), /* pcrel_offset */
1481
a6bb11b2 1482 HOWTO (AARCH64_R (TLSLE_ADD_TPREL_HI12), /* type */
bb3f9ed8 1483 12, /* rightshift */
a06ea964
NC
1484 2, /* size (0 = byte, 1 = short, 2 = long) */
1485 12, /* bitsize */
1486 FALSE, /* pc_relative */
1487 0, /* bitpos */
bab91cce 1488 complain_overflow_unsigned, /* complain_on_overflow */
a06ea964 1489 bfd_elf_generic_reloc, /* special_function */
a6bb11b2 1490 AARCH64_R_STR (TLSLE_ADD_TPREL_HI12), /* name */
a06ea964
NC
1491 FALSE, /* partial_inplace */
1492 0xfff, /* src_mask */
1493 0xfff, /* dst_mask */
1494 FALSE), /* pcrel_offset */
1495
a6bb11b2 1496 HOWTO (AARCH64_R (TLSLE_ADD_TPREL_LO12), /* type */
a06ea964
NC
1497 0, /* rightshift */
1498 2, /* size (0 = byte, 1 = short, 2 = long) */
1499 12, /* bitsize */
1500 FALSE, /* pc_relative */
1501 0, /* bitpos */
36e6c140 1502 complain_overflow_unsigned, /* complain_on_overflow */
a06ea964 1503 bfd_elf_generic_reloc, /* special_function */
a6bb11b2 1504 AARCH64_R_STR (TLSLE_ADD_TPREL_LO12), /* name */
a06ea964
NC
1505 FALSE, /* partial_inplace */
1506 0xfff, /* src_mask */
1507 0xfff, /* dst_mask */
1508 FALSE), /* pcrel_offset */
1509
a6bb11b2 1510 HOWTO (AARCH64_R (TLSLE_ADD_TPREL_LO12_NC), /* type */
a06ea964
NC
1511 0, /* rightshift */
1512 2, /* size (0 = byte, 1 = short, 2 = long) */
1513 12, /* bitsize */
1514 FALSE, /* pc_relative */
1515 0, /* bitpos */
1516 complain_overflow_dont, /* complain_on_overflow */
1517 bfd_elf_generic_reloc, /* special_function */
a6bb11b2 1518 AARCH64_R_STR (TLSLE_ADD_TPREL_LO12_NC), /* name */
a06ea964
NC
1519 FALSE, /* partial_inplace */
1520 0xfff, /* src_mask */
1521 0xfff, /* dst_mask */
1522 FALSE), /* pcrel_offset */
a06ea964 1523
a6bb11b2 1524 HOWTO (AARCH64_R (TLSDESC_LD_PREL19), /* type */
bb3f9ed8 1525 2, /* rightshift */
a06ea964 1526 2, /* size (0 = byte, 1 = short, 2 = long) */
1ada945d 1527 19, /* bitsize */
a06ea964
NC
1528 TRUE, /* pc_relative */
1529 0, /* bitpos */
1530 complain_overflow_dont, /* complain_on_overflow */
1531 bfd_elf_generic_reloc, /* special_function */
a6bb11b2 1532 AARCH64_R_STR (TLSDESC_LD_PREL19), /* name */
a06ea964 1533 FALSE, /* partial_inplace */
1ada945d
MS
1534 0x0ffffe0, /* src_mask */
1535 0x0ffffe0, /* dst_mask */
a06ea964
NC
1536 TRUE), /* pcrel_offset */
1537
a6bb11b2 1538 HOWTO (AARCH64_R (TLSDESC_ADR_PREL21), /* type */
a06ea964
NC
1539 0, /* rightshift */
1540 2, /* size (0 = byte, 1 = short, 2 = long) */
1541 21, /* bitsize */
1542 TRUE, /* pc_relative */
1543 0, /* bitpos */
1544 complain_overflow_dont, /* complain_on_overflow */
1545 bfd_elf_generic_reloc, /* special_function */
a6bb11b2 1546 AARCH64_R_STR (TLSDESC_ADR_PREL21), /* name */
a06ea964
NC
1547 FALSE, /* partial_inplace */
1548 0x1fffff, /* src_mask */
1549 0x1fffff, /* dst_mask */
1550 TRUE), /* pcrel_offset */
1551
1552 /* Get to the page for the GOT entry for the symbol
1553 (G(S) - P) using an ADRP instruction. */
a6bb11b2 1554 HOWTO (AARCH64_R (TLSDESC_ADR_PAGE21), /* type */
a06ea964
NC
1555 12, /* rightshift */
1556 2, /* size (0 = byte, 1 = short, 2 = long) */
1557 21, /* bitsize */
1558 TRUE, /* pc_relative */
1559 0, /* bitpos */
1560 complain_overflow_dont, /* complain_on_overflow */
1561 bfd_elf_generic_reloc, /* special_function */
a6bb11b2 1562 AARCH64_R_STR (TLSDESC_ADR_PAGE21), /* name */
a06ea964
NC
1563 FALSE, /* partial_inplace */
1564 0x1fffff, /* src_mask */
1565 0x1fffff, /* dst_mask */
1566 TRUE), /* pcrel_offset */
1567
a6bb11b2
YZ
1568 /* LD64: GOT offset G(S) & 0xff8. */
1569 HOWTO64 (AARCH64_R (TLSDESC_LD64_LO12_NC), /* type */
a06ea964
NC
1570 3, /* rightshift */
1571 2, /* size (0 = byte, 1 = short, 2 = long) */
1572 12, /* bitsize */
1573 FALSE, /* pc_relative */
1574 0, /* bitpos */
1575 complain_overflow_dont, /* complain_on_overflow */
1576 bfd_elf_generic_reloc, /* special_function */
a6bb11b2 1577 AARCH64_R_STR (TLSDESC_LD64_LO12_NC), /* name */
a06ea964 1578 FALSE, /* partial_inplace */
a6bb11b2
YZ
1579 0xff8, /* src_mask */
1580 0xff8, /* dst_mask */
1581 FALSE), /* pcrel_offset */
1582
1583 /* LD32: GOT offset G(S) & 0xffc. */
1584 HOWTO32 (AARCH64_R (TLSDESC_LD32_LO12_NC), /* type */
1585 2, /* rightshift */
1586 2, /* size (0 = byte, 1 = short, 2 = long) */
1587 12, /* bitsize */
1588 FALSE, /* pc_relative */
1589 0, /* bitpos */
1590 complain_overflow_dont, /* complain_on_overflow */
1591 bfd_elf_generic_reloc, /* special_function */
1592 AARCH64_R_STR (TLSDESC_LD32_LO12_NC), /* name */
1593 FALSE, /* partial_inplace */
1594 0xffc, /* src_mask */
1595 0xffc, /* dst_mask */
a06ea964
NC
1596 FALSE), /* pcrel_offset */
1597
1598 /* ADD: GOT offset G(S) & 0xfff. */
a6bb11b2 1599 HOWTO (AARCH64_R (TLSDESC_ADD_LO12_NC), /* type */
a06ea964
NC
1600 0, /* rightshift */
1601 2, /* size (0 = byte, 1 = short, 2 = long) */
1602 12, /* bitsize */
1603 FALSE, /* pc_relative */
1604 0, /* bitpos */
1605 complain_overflow_dont, /* complain_on_overflow */
1606 bfd_elf_generic_reloc, /* special_function */
a6bb11b2 1607 AARCH64_R_STR (TLSDESC_ADD_LO12_NC), /* name */
a06ea964
NC
1608 FALSE, /* partial_inplace */
1609 0xfff, /* src_mask */
1610 0xfff, /* dst_mask */
1611 FALSE), /* pcrel_offset */
1612
a6bb11b2 1613 HOWTO64 (AARCH64_R (TLSDESC_OFF_G1), /* type */
bb3f9ed8 1614 16, /* rightshift */
a06ea964
NC
1615 2, /* size (0 = byte, 1 = short, 2 = long) */
1616 12, /* bitsize */
1617 FALSE, /* pc_relative */
1618 0, /* bitpos */
43a357f9 1619 complain_overflow_unsigned, /* complain_on_overflow */
a06ea964 1620 bfd_elf_generic_reloc, /* special_function */
a6bb11b2 1621 AARCH64_R_STR (TLSDESC_OFF_G1), /* name */
a06ea964
NC
1622 FALSE, /* partial_inplace */
1623 0xffff, /* src_mask */
1624 0xffff, /* dst_mask */
1625 FALSE), /* pcrel_offset */
1626
a6bb11b2 1627 HOWTO64 (AARCH64_R (TLSDESC_OFF_G0_NC), /* type */
a06ea964
NC
1628 0, /* rightshift */
1629 2, /* size (0 = byte, 1 = short, 2 = long) */
1630 12, /* bitsize */
1631 FALSE, /* pc_relative */
1632 0, /* bitpos */
1633 complain_overflow_dont, /* complain_on_overflow */
1634 bfd_elf_generic_reloc, /* special_function */
a6bb11b2 1635 AARCH64_R_STR (TLSDESC_OFF_G0_NC), /* name */
a06ea964
NC
1636 FALSE, /* partial_inplace */
1637 0xffff, /* src_mask */
1638 0xffff, /* dst_mask */
1639 FALSE), /* pcrel_offset */
1640
a6bb11b2 1641 HOWTO64 (AARCH64_R (TLSDESC_LDR), /* type */
a06ea964
NC
1642 0, /* rightshift */
1643 2, /* size (0 = byte, 1 = short, 2 = long) */
1644 12, /* bitsize */
1645 FALSE, /* pc_relative */
1646 0, /* bitpos */
1647 complain_overflow_dont, /* complain_on_overflow */
1648 bfd_elf_generic_reloc, /* special_function */
a6bb11b2 1649 AARCH64_R_STR (TLSDESC_LDR), /* name */
a06ea964
NC
1650 FALSE, /* partial_inplace */
1651 0x0, /* src_mask */
1652 0x0, /* dst_mask */
1653 FALSE), /* pcrel_offset */
1654
a6bb11b2 1655 HOWTO64 (AARCH64_R (TLSDESC_ADD), /* type */
a06ea964
NC
1656 0, /* rightshift */
1657 2, /* size (0 = byte, 1 = short, 2 = long) */
1658 12, /* bitsize */
1659 FALSE, /* pc_relative */
1660 0, /* bitpos */
1661 complain_overflow_dont, /* complain_on_overflow */
1662 bfd_elf_generic_reloc, /* special_function */
a6bb11b2 1663 AARCH64_R_STR (TLSDESC_ADD), /* name */
a06ea964
NC
1664 FALSE, /* partial_inplace */
1665 0x0, /* src_mask */
1666 0x0, /* dst_mask */
1667 FALSE), /* pcrel_offset */
1668
a6bb11b2 1669 HOWTO (AARCH64_R (TLSDESC_CALL), /* type */
a06ea964
NC
1670 0, /* rightshift */
1671 2, /* size (0 = byte, 1 = short, 2 = long) */
7366006f 1672 0, /* bitsize */
a06ea964
NC
1673 FALSE, /* pc_relative */
1674 0, /* bitpos */
1675 complain_overflow_dont, /* complain_on_overflow */
1676 bfd_elf_generic_reloc, /* special_function */
a6bb11b2 1677 AARCH64_R_STR (TLSDESC_CALL), /* name */
a06ea964
NC
1678 FALSE, /* partial_inplace */
1679 0x0, /* src_mask */
1680 0x0, /* dst_mask */
1681 FALSE), /* pcrel_offset */
a6bb11b2
YZ
1682
1683 HOWTO (AARCH64_R (COPY), /* type */
1684 0, /* rightshift */
1685 2, /* size (0 = byte, 1 = short, 2 = long) */
1686 64, /* bitsize */
1687 FALSE, /* pc_relative */
1688 0, /* bitpos */
1689 complain_overflow_bitfield, /* complain_on_overflow */
1690 bfd_elf_generic_reloc, /* special_function */
1691 AARCH64_R_STR (COPY), /* name */
1692 TRUE, /* partial_inplace */
1693 0xffffffff, /* src_mask */
1694 0xffffffff, /* dst_mask */
1695 FALSE), /* pcrel_offset */
1696
1697 HOWTO (AARCH64_R (GLOB_DAT), /* type */
1698 0, /* rightshift */
1699 2, /* size (0 = byte, 1 = short, 2 = long) */
1700 64, /* bitsize */
1701 FALSE, /* pc_relative */
1702 0, /* bitpos */
1703 complain_overflow_bitfield, /* complain_on_overflow */
1704 bfd_elf_generic_reloc, /* special_function */
1705 AARCH64_R_STR (GLOB_DAT), /* name */
1706 TRUE, /* partial_inplace */
1707 0xffffffff, /* src_mask */
1708 0xffffffff, /* dst_mask */
1709 FALSE), /* pcrel_offset */
1710
1711 HOWTO (AARCH64_R (JUMP_SLOT), /* type */
1712 0, /* rightshift */
1713 2, /* size (0 = byte, 1 = short, 2 = long) */
1714 64, /* bitsize */
1715 FALSE, /* pc_relative */
1716 0, /* bitpos */
1717 complain_overflow_bitfield, /* complain_on_overflow */
1718 bfd_elf_generic_reloc, /* special_function */
1719 AARCH64_R_STR (JUMP_SLOT), /* name */
1720 TRUE, /* partial_inplace */
1721 0xffffffff, /* src_mask */
1722 0xffffffff, /* dst_mask */
1723 FALSE), /* pcrel_offset */
1724
1725 HOWTO (AARCH64_R (RELATIVE), /* type */
1726 0, /* rightshift */
1727 2, /* size (0 = byte, 1 = short, 2 = long) */
1728 64, /* bitsize */
1729 FALSE, /* pc_relative */
1730 0, /* bitpos */
1731 complain_overflow_bitfield, /* complain_on_overflow */
1732 bfd_elf_generic_reloc, /* special_function */
1733 AARCH64_R_STR (RELATIVE), /* name */
1734 TRUE, /* partial_inplace */
1735 ALL_ONES, /* src_mask */
1736 ALL_ONES, /* dst_mask */
1737 FALSE), /* pcrel_offset */
1738
1739 HOWTO (AARCH64_R (TLS_DTPMOD), /* type */
1740 0, /* rightshift */
1741 2, /* size (0 = byte, 1 = short, 2 = long) */
1742 64, /* bitsize */
1743 FALSE, /* pc_relative */
1744 0, /* bitpos */
1745 complain_overflow_dont, /* complain_on_overflow */
1746 bfd_elf_generic_reloc, /* special_function */
da0781dc
YZ
1747#if ARCH_SIZE == 64
1748 AARCH64_R_STR (TLS_DTPMOD64), /* name */
1749#else
a6bb11b2 1750 AARCH64_R_STR (TLS_DTPMOD), /* name */
da0781dc 1751#endif
a6bb11b2
YZ
1752 FALSE, /* partial_inplace */
1753 0, /* src_mask */
1754 ALL_ONES, /* dst_mask */
1755 FALSE), /* pc_reloffset */
1756
1757 HOWTO (AARCH64_R (TLS_DTPREL), /* type */
1758 0, /* rightshift */
1759 2, /* size (0 = byte, 1 = short, 2 = long) */
1760 64, /* bitsize */
1761 FALSE, /* pc_relative */
1762 0, /* bitpos */
1763 complain_overflow_dont, /* complain_on_overflow */
1764 bfd_elf_generic_reloc, /* special_function */
da0781dc
YZ
1765#if ARCH_SIZE == 64
1766 AARCH64_R_STR (TLS_DTPREL64), /* name */
1767#else
a6bb11b2 1768 AARCH64_R_STR (TLS_DTPREL), /* name */
da0781dc 1769#endif
a6bb11b2
YZ
1770 FALSE, /* partial_inplace */
1771 0, /* src_mask */
1772 ALL_ONES, /* dst_mask */
1773 FALSE), /* pcrel_offset */
1774
1775 HOWTO (AARCH64_R (TLS_TPREL), /* type */
1776 0, /* rightshift */
1777 2, /* size (0 = byte, 1 = short, 2 = long) */
1778 64, /* bitsize */
1779 FALSE, /* pc_relative */
1780 0, /* bitpos */
1781 complain_overflow_dont, /* complain_on_overflow */
1782 bfd_elf_generic_reloc, /* special_function */
da0781dc
YZ
1783#if ARCH_SIZE == 64
1784 AARCH64_R_STR (TLS_TPREL64), /* name */
1785#else
a6bb11b2 1786 AARCH64_R_STR (TLS_TPREL), /* name */
da0781dc 1787#endif
a6bb11b2
YZ
1788 FALSE, /* partial_inplace */
1789 0, /* src_mask */
1790 ALL_ONES, /* dst_mask */
1791 FALSE), /* pcrel_offset */
1792
1793 HOWTO (AARCH64_R (TLSDESC), /* type */
1794 0, /* rightshift */
1795 2, /* size (0 = byte, 1 = short, 2 = long) */
1796 64, /* bitsize */
1797 FALSE, /* pc_relative */
1798 0, /* bitpos */
1799 complain_overflow_dont, /* complain_on_overflow */
1800 bfd_elf_generic_reloc, /* special_function */
1801 AARCH64_R_STR (TLSDESC), /* name */
1802 FALSE, /* partial_inplace */
1803 0, /* src_mask */
1804 ALL_ONES, /* dst_mask */
1805 FALSE), /* pcrel_offset */
1806
1807 HOWTO (AARCH64_R (IRELATIVE), /* type */
1808 0, /* rightshift */
1809 2, /* size (0 = byte, 1 = short, 2 = long) */
1810 64, /* bitsize */
1811 FALSE, /* pc_relative */
1812 0, /* bitpos */
1813 complain_overflow_bitfield, /* complain_on_overflow */
1814 bfd_elf_generic_reloc, /* special_function */
1815 AARCH64_R_STR (IRELATIVE), /* name */
1816 FALSE, /* partial_inplace */
1817 0, /* src_mask */
1818 ALL_ONES, /* dst_mask */
1819 FALSE), /* pcrel_offset */
1820
1821 EMPTY_HOWTO (0),
a06ea964
NC
1822};
1823
a6bb11b2
YZ
1824static reloc_howto_type elfNN_aarch64_howto_none =
1825 HOWTO (R_AARCH64_NONE, /* type */
1826 0, /* rightshift */
6346d5ca 1827 3, /* size (0 = byte, 1 = short, 2 = long) */
a6bb11b2
YZ
1828 0, /* bitsize */
1829 FALSE, /* pc_relative */
1830 0, /* bitpos */
1831 complain_overflow_dont,/* complain_on_overflow */
1832 bfd_elf_generic_reloc, /* special_function */
1833 "R_AARCH64_NONE", /* name */
1834 FALSE, /* partial_inplace */
1835 0, /* src_mask */
1836 0, /* dst_mask */
1837 FALSE); /* pcrel_offset */
1838
1839/* Given HOWTO, return the bfd internal relocation enumerator. */
1840
1841static bfd_reloc_code_real_type
1842elfNN_aarch64_bfd_reloc_from_howto (reloc_howto_type *howto)
1843{
1844 const int size
1845 = (int) ARRAY_SIZE (elfNN_aarch64_howto_table);
1846 const ptrdiff_t offset
1847 = howto - elfNN_aarch64_howto_table;
1848
1849 if (offset > 0 && offset < size - 1)
1850 return BFD_RELOC_AARCH64_RELOC_START + offset;
1851
1852 if (howto == &elfNN_aarch64_howto_none)
1853 return BFD_RELOC_AARCH64_NONE;
1854
1855 return BFD_RELOC_AARCH64_RELOC_START;
1856}
1857
1858/* Given R_TYPE, return the bfd internal relocation enumerator. */
1859
1860static bfd_reloc_code_real_type
1861elfNN_aarch64_bfd_reloc_from_type (unsigned int r_type)
1862{
1863 static bfd_boolean initialized_p = FALSE;
1864 /* Indexed by R_TYPE, values are offsets in the howto_table. */
1865 static unsigned int offsets[R_AARCH64_end];
1866
1867 if (initialized_p == FALSE)
1868 {
1869 unsigned int i;
1870
1871 for (i = 1; i < ARRAY_SIZE (elfNN_aarch64_howto_table) - 1; ++i)
1872 if (elfNN_aarch64_howto_table[i].type != 0)
1873 offsets[elfNN_aarch64_howto_table[i].type] = i;
1874
1875 initialized_p = TRUE;
1876 }
1877
1878 if (r_type == R_AARCH64_NONE || r_type == R_AARCH64_NULL)
1879 return BFD_RELOC_AARCH64_NONE;
1880
5860e3f8
NC
1881 /* PR 17512: file: b371e70a. */
1882 if (r_type >= R_AARCH64_end)
1883 {
1884 _bfd_error_handler (_("Invalid AArch64 reloc number: %d"), r_type);
1885 bfd_set_error (bfd_error_bad_value);
1886 return BFD_RELOC_AARCH64_NONE;
1887 }
1888
a6bb11b2
YZ
1889 return BFD_RELOC_AARCH64_RELOC_START + offsets[r_type];
1890}
1891
1892struct elf_aarch64_reloc_map
1893{
1894 bfd_reloc_code_real_type from;
1895 bfd_reloc_code_real_type to;
1896};
1897
1898/* Map bfd generic reloc to AArch64-specific reloc. */
1899static const struct elf_aarch64_reloc_map elf_aarch64_reloc_map[] =
1900{
1901 {BFD_RELOC_NONE, BFD_RELOC_AARCH64_NONE},
1902
1903 /* Basic data relocations. */
1904 {BFD_RELOC_CTOR, BFD_RELOC_AARCH64_NN},
1905 {BFD_RELOC_64, BFD_RELOC_AARCH64_64},
1906 {BFD_RELOC_32, BFD_RELOC_AARCH64_32},
1907 {BFD_RELOC_16, BFD_RELOC_AARCH64_16},
1908 {BFD_RELOC_64_PCREL, BFD_RELOC_AARCH64_64_PCREL},
1909 {BFD_RELOC_32_PCREL, BFD_RELOC_AARCH64_32_PCREL},
1910 {BFD_RELOC_16_PCREL, BFD_RELOC_AARCH64_16_PCREL},
1911};
1912
1913/* Given the bfd internal relocation enumerator in CODE, return the
1914 corresponding howto entry. */
1915
1916static reloc_howto_type *
1917elfNN_aarch64_howto_from_bfd_reloc (bfd_reloc_code_real_type code)
1918{
1919 unsigned int i;
1920
1921 /* Convert bfd generic reloc to AArch64-specific reloc. */
1922 if (code < BFD_RELOC_AARCH64_RELOC_START
1923 || code > BFD_RELOC_AARCH64_RELOC_END)
1924 for (i = 0; i < ARRAY_SIZE (elf_aarch64_reloc_map); i++)
1925 if (elf_aarch64_reloc_map[i].from == code)
1926 {
1927 code = elf_aarch64_reloc_map[i].to;
1928 break;
1929 }
1930
1931 if (code > BFD_RELOC_AARCH64_RELOC_START
1932 && code < BFD_RELOC_AARCH64_RELOC_END)
1933 if (elfNN_aarch64_howto_table[code - BFD_RELOC_AARCH64_RELOC_START].type)
1934 return &elfNN_aarch64_howto_table[code - BFD_RELOC_AARCH64_RELOC_START];
1935
54757ed1
AP
1936 if (code == BFD_RELOC_AARCH64_NONE)
1937 return &elfNN_aarch64_howto_none;
1938
a6bb11b2
YZ
1939 return NULL;
1940}
1941
a06ea964 1942static reloc_howto_type *
cec5225b 1943elfNN_aarch64_howto_from_type (unsigned int r_type)
a06ea964 1944{
a6bb11b2
YZ
1945 bfd_reloc_code_real_type val;
1946 reloc_howto_type *howto;
1947
cec5225b
YZ
1948#if ARCH_SIZE == 32
1949 if (r_type > 256)
1950 {
1951 bfd_set_error (bfd_error_bad_value);
1952 return NULL;
1953 }
1954#endif
1955
a6bb11b2
YZ
1956 if (r_type == R_AARCH64_NONE)
1957 return &elfNN_aarch64_howto_none;
a06ea964 1958
a6bb11b2
YZ
1959 val = elfNN_aarch64_bfd_reloc_from_type (r_type);
1960 howto = elfNN_aarch64_howto_from_bfd_reloc (val);
a06ea964 1961
a6bb11b2
YZ
1962 if (howto != NULL)
1963 return howto;
a06ea964 1964
a06ea964
NC
1965 bfd_set_error (bfd_error_bad_value);
1966 return NULL;
1967}
1968
1969static void
cec5225b 1970elfNN_aarch64_info_to_howto (bfd *abfd ATTRIBUTE_UNUSED, arelent *bfd_reloc,
a06ea964
NC
1971 Elf_Internal_Rela *elf_reloc)
1972{
1973 unsigned int r_type;
1974
cec5225b
YZ
1975 r_type = ELFNN_R_TYPE (elf_reloc->r_info);
1976 bfd_reloc->howto = elfNN_aarch64_howto_from_type (r_type);
a06ea964
NC
1977}
1978
a06ea964 1979static reloc_howto_type *
cec5225b 1980elfNN_aarch64_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED,
a06ea964
NC
1981 bfd_reloc_code_real_type code)
1982{
a6bb11b2 1983 reloc_howto_type *howto = elfNN_aarch64_howto_from_bfd_reloc (code);
a06ea964 1984
a6bb11b2
YZ
1985 if (howto != NULL)
1986 return howto;
a06ea964
NC
1987
1988 bfd_set_error (bfd_error_bad_value);
1989 return NULL;
1990}
1991
1992static reloc_howto_type *
cec5225b 1993elfNN_aarch64_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED,
a06ea964
NC
1994 const char *r_name)
1995{
1996 unsigned int i;
1997
a6bb11b2
YZ
1998 for (i = 1; i < ARRAY_SIZE (elfNN_aarch64_howto_table) - 1; ++i)
1999 if (elfNN_aarch64_howto_table[i].name != NULL
2000 && strcasecmp (elfNN_aarch64_howto_table[i].name, r_name) == 0)
2001 return &elfNN_aarch64_howto_table[i];
a06ea964
NC
2002
2003 return NULL;
2004}
2005
6d00b590 2006#define TARGET_LITTLE_SYM aarch64_elfNN_le_vec
cec5225b 2007#define TARGET_LITTLE_NAME "elfNN-littleaarch64"
6d00b590 2008#define TARGET_BIG_SYM aarch64_elfNN_be_vec
cec5225b 2009#define TARGET_BIG_NAME "elfNN-bigaarch64"
a06ea964 2010
a06ea964
NC
2011/* The linker script knows the section names for placement.
2012 The entry_names are used to do simple name mangling on the stubs.
2013 Given a function name, and its type, the stub can be found. The
2014 name can be changed. The only requirement is the %s be present. */
2015#define STUB_ENTRY_NAME "__%s_veneer"
2016
2017/* The name of the dynamic interpreter. This is put in the .interp
2018 section. */
2019#define ELF_DYNAMIC_INTERPRETER "/lib/ld.so.1"
2020
2021#define AARCH64_MAX_FWD_BRANCH_OFFSET \
2022 (((1 << 25) - 1) << 2)
2023#define AARCH64_MAX_BWD_BRANCH_OFFSET \
2024 (-((1 << 25) << 2))
2025
2026#define AARCH64_MAX_ADRP_IMM ((1 << 20) - 1)
2027#define AARCH64_MIN_ADRP_IMM (-(1 << 20))
2028
2029static int
2030aarch64_valid_for_adrp_p (bfd_vma value, bfd_vma place)
2031{
2032 bfd_signed_vma offset = (bfd_signed_vma) (PG (value) - PG (place)) >> 12;
2033 return offset <= AARCH64_MAX_ADRP_IMM && offset >= AARCH64_MIN_ADRP_IMM;
2034}
2035
2036static int
2037aarch64_valid_branch_p (bfd_vma value, bfd_vma place)
2038{
2039 bfd_signed_vma offset = (bfd_signed_vma) (value - place);
2040 return (offset <= AARCH64_MAX_FWD_BRANCH_OFFSET
2041 && offset >= AARCH64_MAX_BWD_BRANCH_OFFSET);
2042}
2043
2044static const uint32_t aarch64_adrp_branch_stub [] =
2045{
2046 0x90000010, /* adrp ip0, X */
2047 /* R_AARCH64_ADR_HI21_PCREL(X) */
2048 0x91000210, /* add ip0, ip0, :lo12:X */
2049 /* R_AARCH64_ADD_ABS_LO12_NC(X) */
2050 0xd61f0200, /* br ip0 */
2051};
2052
2053static const uint32_t aarch64_long_branch_stub[] =
2054{
cec5225b 2055#if ARCH_SIZE == 64
a06ea964 2056 0x58000090, /* ldr ip0, 1f */
cec5225b
YZ
2057#else
2058 0x18000090, /* ldr wip0, 1f */
2059#endif
a06ea964
NC
2060 0x10000011, /* adr ip1, #0 */
2061 0x8b110210, /* add ip0, ip0, ip1 */
2062 0xd61f0200, /* br ip0 */
cec5225b
YZ
2063 0x00000000, /* 1: .xword or .word
2064 R_AARCH64_PRELNN(X) + 12
a06ea964
NC
2065 */
2066 0x00000000,
2067};
2068
68fcca92
JW
2069static const uint32_t aarch64_erratum_835769_stub[] =
2070{
2071 0x00000000, /* Placeholder for multiply accumulate. */
2072 0x14000000, /* b <label> */
2073};
2074
4106101c
MS
2075static const uint32_t aarch64_erratum_843419_stub[] =
2076{
2077 0x00000000, /* Placeholder for LDR instruction. */
2078 0x14000000, /* b <label> */
2079};
2080
a06ea964
NC
2081/* Section name for stubs is the associated section name plus this
2082 string. */
2083#define STUB_SUFFIX ".stub"
2084
cec5225b 2085enum elf_aarch64_stub_type
a06ea964
NC
2086{
2087 aarch64_stub_none,
2088 aarch64_stub_adrp_branch,
2089 aarch64_stub_long_branch,
68fcca92 2090 aarch64_stub_erratum_835769_veneer,
4106101c 2091 aarch64_stub_erratum_843419_veneer,
a06ea964
NC
2092};
2093
cec5225b 2094struct elf_aarch64_stub_hash_entry
a06ea964
NC
2095{
2096 /* Base hash table entry structure. */
2097 struct bfd_hash_entry root;
2098
2099 /* The stub section. */
2100 asection *stub_sec;
2101
2102 /* Offset within stub_sec of the beginning of this stub. */
2103 bfd_vma stub_offset;
2104
2105 /* Given the symbol's value and its section we can determine its final
2106 value when building the stubs (so the stub knows where to jump). */
2107 bfd_vma target_value;
2108 asection *target_section;
2109
cec5225b 2110 enum elf_aarch64_stub_type stub_type;
a06ea964
NC
2111
2112 /* The symbol table entry, if any, that this was derived from. */
cec5225b 2113 struct elf_aarch64_link_hash_entry *h;
a06ea964
NC
2114
2115 /* Destination symbol type */
2116 unsigned char st_type;
2117
2118 /* Where this stub is being called from, or, in the case of combined
2119 stub sections, the first input section in the group. */
2120 asection *id_sec;
2121
2122 /* The name for the local symbol at the start of this stub. The
2123 stub name in the hash table has to be unique; this does not, so
2124 it can be friendlier. */
2125 char *output_name;
68fcca92
JW
2126
2127 /* The instruction which caused this stub to be generated (only valid for
2128 erratum 835769 workaround stubs at present). */
2129 uint32_t veneered_insn;
4106101c
MS
2130
2131 /* In an erratum 843419 workaround stub, the ADRP instruction offset. */
2132 bfd_vma adrp_offset;
a06ea964
NC
2133};
2134
2135/* Used to build a map of a section. This is required for mixed-endian
2136 code/data. */
2137
cec5225b 2138typedef struct elf_elf_section_map
a06ea964
NC
2139{
2140 bfd_vma vma;
2141 char type;
2142}
cec5225b 2143elf_aarch64_section_map;
a06ea964
NC
2144
2145
2146typedef struct _aarch64_elf_section_data
2147{
2148 struct bfd_elf_section_data elf;
2149 unsigned int mapcount;
2150 unsigned int mapsize;
cec5225b 2151 elf_aarch64_section_map *map;
a06ea964
NC
2152}
2153_aarch64_elf_section_data;
2154
cec5225b 2155#define elf_aarch64_section_data(sec) \
a06ea964
NC
2156 ((_aarch64_elf_section_data *) elf_section_data (sec))
2157
4e8516b2
AP
2158/* The size of the thread control block which is defined to be two pointers. */
2159#define TCB_SIZE (ARCH_SIZE/8)*2
a06ea964
NC
2160
2161struct elf_aarch64_local_symbol
2162{
2163 unsigned int got_type;
2164 bfd_signed_vma got_refcount;
2165 bfd_vma got_offset;
2166
2167 /* Offset of the GOTPLT entry reserved for the TLS descriptor. The
2168 offset is from the end of the jump table and reserved entries
2169 within the PLTGOT.
2170
2171 The magic value (bfd_vma) -1 indicates that an offset has not be
2172 allocated. */
2173 bfd_vma tlsdesc_got_jump_table_offset;
2174};
2175
2176struct elf_aarch64_obj_tdata
2177{
2178 struct elf_obj_tdata root;
2179
2180 /* local symbol descriptors */
2181 struct elf_aarch64_local_symbol *locals;
2182
2183 /* Zero to warn when linking objects with incompatible enum sizes. */
2184 int no_enum_size_warning;
2185
2186 /* Zero to warn when linking objects with incompatible wchar_t sizes. */
2187 int no_wchar_size_warning;
2188};
2189
2190#define elf_aarch64_tdata(bfd) \
2191 ((struct elf_aarch64_obj_tdata *) (bfd)->tdata.any)
2192
cec5225b 2193#define elf_aarch64_locals(bfd) (elf_aarch64_tdata (bfd)->locals)
a06ea964
NC
2194
2195#define is_aarch64_elf(bfd) \
2196 (bfd_get_flavour (bfd) == bfd_target_elf_flavour \
2197 && elf_tdata (bfd) != NULL \
2198 && elf_object_id (bfd) == AARCH64_ELF_DATA)
2199
2200static bfd_boolean
cec5225b 2201elfNN_aarch64_mkobject (bfd *abfd)
a06ea964
NC
2202{
2203 return bfd_elf_allocate_object (abfd, sizeof (struct elf_aarch64_obj_tdata),
2204 AARCH64_ELF_DATA);
2205}
2206
cec5225b
YZ
2207#define elf_aarch64_hash_entry(ent) \
2208 ((struct elf_aarch64_link_hash_entry *)(ent))
a06ea964
NC
2209
2210#define GOT_UNKNOWN 0
2211#define GOT_NORMAL 1
2212#define GOT_TLS_GD 2
2213#define GOT_TLS_IE 4
2214#define GOT_TLSDESC_GD 8
2215
2216#define GOT_TLS_GD_ANY_P(type) ((type & GOT_TLS_GD) || (type & GOT_TLSDESC_GD))
2217
2218/* AArch64 ELF linker hash entry. */
cec5225b 2219struct elf_aarch64_link_hash_entry
a06ea964
NC
2220{
2221 struct elf_link_hash_entry root;
2222
2223 /* Track dynamic relocs copied for this symbol. */
2224 struct elf_dyn_relocs *dyn_relocs;
2225
a06ea964
NC
2226 /* Since PLT entries have variable size, we need to record the
2227 index into .got.plt instead of recomputing it from the PLT
2228 offset. */
2229 bfd_signed_vma plt_got_offset;
2230
2231 /* Bit mask representing the type of GOT entry(s) if any required by
2232 this symbol. */
2233 unsigned int got_type;
2234
2235 /* A pointer to the most recently used stub hash entry against this
2236 symbol. */
cec5225b 2237 struct elf_aarch64_stub_hash_entry *stub_cache;
a06ea964
NC
2238
2239 /* Offset of the GOTPLT entry reserved for the TLS descriptor. The offset
2240 is from the end of the jump table and reserved entries within the PLTGOT.
2241
2242 The magic value (bfd_vma) -1 indicates that an offset has not
2243 be allocated. */
2244 bfd_vma tlsdesc_got_jump_table_offset;
2245};
2246
2247static unsigned int
cec5225b 2248elfNN_aarch64_symbol_got_type (struct elf_link_hash_entry *h,
a06ea964
NC
2249 bfd *abfd,
2250 unsigned long r_symndx)
2251{
2252 if (h)
cec5225b 2253 return elf_aarch64_hash_entry (h)->got_type;
a06ea964 2254
cec5225b 2255 if (! elf_aarch64_locals (abfd))
a06ea964
NC
2256 return GOT_UNKNOWN;
2257
cec5225b 2258 return elf_aarch64_locals (abfd)[r_symndx].got_type;
a06ea964
NC
2259}
2260
a06ea964 2261/* Get the AArch64 elf linker hash table from a link_info structure. */
cec5225b
YZ
2262#define elf_aarch64_hash_table(info) \
2263 ((struct elf_aarch64_link_hash_table *) ((info)->hash))
a06ea964
NC
2264
2265#define aarch64_stub_hash_lookup(table, string, create, copy) \
cec5225b 2266 ((struct elf_aarch64_stub_hash_entry *) \
a06ea964
NC
2267 bfd_hash_lookup ((table), (string), (create), (copy)))
2268
2269/* AArch64 ELF linker hash table. */
cec5225b 2270struct elf_aarch64_link_hash_table
a06ea964
NC
2271{
2272 /* The main hash table. */
2273 struct elf_link_hash_table root;
2274
2275 /* Nonzero to force PIC branch veneers. */
2276 int pic_veneer;
2277
68fcca92
JW
2278 /* Fix erratum 835769. */
2279 int fix_erratum_835769;
2280
4106101c
MS
2281 /* Fix erratum 843419. */
2282 int fix_erratum_843419;
2283
2284 /* Enable ADRP->ADR rewrite for erratum 843419 workaround. */
2285 int fix_erratum_843419_adr;
2286
a06ea964
NC
2287 /* The number of bytes in the initial entry in the PLT. */
2288 bfd_size_type plt_header_size;
2289
2290 /* The number of bytes in the subsequent PLT etries. */
2291 bfd_size_type plt_entry_size;
2292
2293 /* Short-cuts to get to dynamic linker sections. */
2294 asection *sdynbss;
2295 asection *srelbss;
2296
2297 /* Small local sym cache. */
2298 struct sym_cache sym_cache;
2299
2300 /* For convenience in allocate_dynrelocs. */
2301 bfd *obfd;
2302
2303 /* The amount of space used by the reserved portion of the sgotplt
2304 section, plus whatever space is used by the jump slots. */
2305 bfd_vma sgotplt_jump_table_size;
2306
2307 /* The stub hash table. */
2308 struct bfd_hash_table stub_hash_table;
2309
2310 /* Linker stub bfd. */
2311 bfd *stub_bfd;
2312
2313 /* Linker call-backs. */
2314 asection *(*add_stub_section) (const char *, asection *);
2315 void (*layout_sections_again) (void);
2316
2317 /* Array to keep track of which stub sections have been created, and
2318 information on stub grouping. */
2319 struct map_stub
2320 {
2321 /* This is the section to which stubs in the group will be
2322 attached. */
2323 asection *link_sec;
2324 /* The stub section. */
2325 asection *stub_sec;
2326 } *stub_group;
2327
cec5225b 2328 /* Assorted information used by elfNN_aarch64_size_stubs. */
a06ea964 2329 unsigned int bfd_count;
7292b3ac 2330 unsigned int top_index;
a06ea964
NC
2331 asection **input_list;
2332
2333 /* The offset into splt of the PLT entry for the TLS descriptor
2334 resolver. Special values are 0, if not necessary (or not found
2335 to be necessary yet), and -1 if needed but not determined
2336 yet. */
2337 bfd_vma tlsdesc_plt;
2338
2339 /* The GOT offset for the lazy trampoline. Communicated to the
2340 loader via DT_TLSDESC_GOT. The magic value (bfd_vma) -1
2341 indicates an offset is not allocated. */
2342 bfd_vma dt_tlsdesc_got;
1419bbe5
WN
2343
2344 /* Used by local STT_GNU_IFUNC symbols. */
2345 htab_t loc_hash_table;
2346 void * loc_hash_memory;
a06ea964
NC
2347};
2348
a06ea964
NC
2349/* Create an entry in an AArch64 ELF linker hash table. */
2350
2351static struct bfd_hash_entry *
cec5225b 2352elfNN_aarch64_link_hash_newfunc (struct bfd_hash_entry *entry,
a06ea964
NC
2353 struct bfd_hash_table *table,
2354 const char *string)
2355{
cec5225b
YZ
2356 struct elf_aarch64_link_hash_entry *ret =
2357 (struct elf_aarch64_link_hash_entry *) entry;
a06ea964
NC
2358
2359 /* Allocate the structure if it has not already been allocated by a
2360 subclass. */
2361 if (ret == NULL)
2362 ret = bfd_hash_allocate (table,
cec5225b 2363 sizeof (struct elf_aarch64_link_hash_entry));
a06ea964
NC
2364 if (ret == NULL)
2365 return (struct bfd_hash_entry *) ret;
2366
2367 /* Call the allocation method of the superclass. */
cec5225b 2368 ret = ((struct elf_aarch64_link_hash_entry *)
a06ea964
NC
2369 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry *) ret,
2370 table, string));
2371 if (ret != NULL)
2372 {
2373 ret->dyn_relocs = NULL;
a06ea964
NC
2374 ret->got_type = GOT_UNKNOWN;
2375 ret->plt_got_offset = (bfd_vma) - 1;
2376 ret->stub_cache = NULL;
2377 ret->tlsdesc_got_jump_table_offset = (bfd_vma) - 1;
2378 }
2379
2380 return (struct bfd_hash_entry *) ret;
2381}
2382
2383/* Initialize an entry in the stub hash table. */
2384
2385static struct bfd_hash_entry *
2386stub_hash_newfunc (struct bfd_hash_entry *entry,
2387 struct bfd_hash_table *table, const char *string)
2388{
2389 /* Allocate the structure if it has not already been allocated by a
2390 subclass. */
2391 if (entry == NULL)
2392 {
2393 entry = bfd_hash_allocate (table,
2394 sizeof (struct
cec5225b 2395 elf_aarch64_stub_hash_entry));
a06ea964
NC
2396 if (entry == NULL)
2397 return entry;
2398 }
2399
2400 /* Call the allocation method of the superclass. */
2401 entry = bfd_hash_newfunc (entry, table, string);
2402 if (entry != NULL)
2403 {
cec5225b 2404 struct elf_aarch64_stub_hash_entry *eh;
a06ea964
NC
2405
2406 /* Initialize the local fields. */
cec5225b 2407 eh = (struct elf_aarch64_stub_hash_entry *) entry;
4106101c 2408 eh->adrp_offset = 0;
a06ea964
NC
2409 eh->stub_sec = NULL;
2410 eh->stub_offset = 0;
2411 eh->target_value = 0;
2412 eh->target_section = NULL;
2413 eh->stub_type = aarch64_stub_none;
2414 eh->h = NULL;
2415 eh->id_sec = NULL;
2416 }
2417
2418 return entry;
2419}
2420
1419bbe5
WN
2421/* Compute a hash of a local hash entry. We use elf_link_hash_entry
2422 for local symbol so that we can handle local STT_GNU_IFUNC symbols
2423 as global symbol. We reuse indx and dynstr_index for local symbol
2424 hash since they aren't used by global symbols in this backend. */
2425
2426static hashval_t
2427elfNN_aarch64_local_htab_hash (const void *ptr)
2428{
2429 struct elf_link_hash_entry *h
2430 = (struct elf_link_hash_entry *) ptr;
2431 return ELF_LOCAL_SYMBOL_HASH (h->indx, h->dynstr_index);
2432}
2433
2434/* Compare local hash entries. */
2435
2436static int
2437elfNN_aarch64_local_htab_eq (const void *ptr1, const void *ptr2)
2438{
2439 struct elf_link_hash_entry *h1
2440 = (struct elf_link_hash_entry *) ptr1;
2441 struct elf_link_hash_entry *h2
2442 = (struct elf_link_hash_entry *) ptr2;
2443
2444 return h1->indx == h2->indx && h1->dynstr_index == h2->dynstr_index;
2445}
2446
2447/* Find and/or create a hash entry for local symbol. */
2448
2449static struct elf_link_hash_entry *
2450elfNN_aarch64_get_local_sym_hash (struct elf_aarch64_link_hash_table *htab,
2451 bfd *abfd, const Elf_Internal_Rela *rel,
2452 bfd_boolean create)
2453{
2454 struct elf_aarch64_link_hash_entry e, *ret;
2455 asection *sec = abfd->sections;
2456 hashval_t h = ELF_LOCAL_SYMBOL_HASH (sec->id,
2457 ELFNN_R_SYM (rel->r_info));
2458 void **slot;
2459
2460 e.root.indx = sec->id;
2461 e.root.dynstr_index = ELFNN_R_SYM (rel->r_info);
2462 slot = htab_find_slot_with_hash (htab->loc_hash_table, &e, h,
2463 create ? INSERT : NO_INSERT);
2464
2465 if (!slot)
2466 return NULL;
2467
2468 if (*slot)
2469 {
2470 ret = (struct elf_aarch64_link_hash_entry *) *slot;
2471 return &ret->root;
2472 }
2473
2474 ret = (struct elf_aarch64_link_hash_entry *)
2475 objalloc_alloc ((struct objalloc *) htab->loc_hash_memory,
2476 sizeof (struct elf_aarch64_link_hash_entry));
2477 if (ret)
2478 {
2479 memset (ret, 0, sizeof (*ret));
2480 ret->root.indx = sec->id;
2481 ret->root.dynstr_index = ELFNN_R_SYM (rel->r_info);
2482 ret->root.dynindx = -1;
2483 *slot = ret;
2484 }
2485 return &ret->root;
2486}
a06ea964
NC
2487
2488/* Copy the extra info we tack onto an elf_link_hash_entry. */
2489
2490static void
cec5225b 2491elfNN_aarch64_copy_indirect_symbol (struct bfd_link_info *info,
a06ea964
NC
2492 struct elf_link_hash_entry *dir,
2493 struct elf_link_hash_entry *ind)
2494{
cec5225b 2495 struct elf_aarch64_link_hash_entry *edir, *eind;
a06ea964 2496
cec5225b
YZ
2497 edir = (struct elf_aarch64_link_hash_entry *) dir;
2498 eind = (struct elf_aarch64_link_hash_entry *) ind;
a06ea964
NC
2499
2500 if (eind->dyn_relocs != NULL)
2501 {
2502 if (edir->dyn_relocs != NULL)
2503 {
2504 struct elf_dyn_relocs **pp;
2505 struct elf_dyn_relocs *p;
2506
2507 /* Add reloc counts against the indirect sym to the direct sym
2508 list. Merge any entries against the same section. */
2509 for (pp = &eind->dyn_relocs; (p = *pp) != NULL;)
2510 {
2511 struct elf_dyn_relocs *q;
2512
2513 for (q = edir->dyn_relocs; q != NULL; q = q->next)
2514 if (q->sec == p->sec)
2515 {
2516 q->pc_count += p->pc_count;
2517 q->count += p->count;
2518 *pp = p->next;
2519 break;
2520 }
2521 if (q == NULL)
2522 pp = &p->next;
2523 }
2524 *pp = edir->dyn_relocs;
2525 }
2526
2527 edir->dyn_relocs = eind->dyn_relocs;
2528 eind->dyn_relocs = NULL;
2529 }
2530
a06ea964
NC
2531 if (ind->root.type == bfd_link_hash_indirect)
2532 {
2533 /* Copy over PLT info. */
2534 if (dir->got.refcount <= 0)
2535 {
2536 edir->got_type = eind->got_type;
2537 eind->got_type = GOT_UNKNOWN;
2538 }
2539 }
2540
2541 _bfd_elf_link_hash_copy_indirect (info, dir, ind);
2542}
2543
68faa637
AM
2544/* Destroy an AArch64 elf linker hash table. */
2545
2546static void
d495ab0d 2547elfNN_aarch64_link_hash_table_free (bfd *obfd)
68faa637
AM
2548{
2549 struct elf_aarch64_link_hash_table *ret
d495ab0d 2550 = (struct elf_aarch64_link_hash_table *) obfd->link.hash;
68faa637
AM
2551
2552 if (ret->loc_hash_table)
2553 htab_delete (ret->loc_hash_table);
2554 if (ret->loc_hash_memory)
2555 objalloc_free ((struct objalloc *) ret->loc_hash_memory);
2556
2557 bfd_hash_table_free (&ret->stub_hash_table);
d495ab0d 2558 _bfd_elf_link_hash_table_free (obfd);
68faa637
AM
2559}
2560
a06ea964
NC
2561/* Create an AArch64 elf linker hash table. */
2562
2563static struct bfd_link_hash_table *
cec5225b 2564elfNN_aarch64_link_hash_table_create (bfd *abfd)
a06ea964 2565{
cec5225b
YZ
2566 struct elf_aarch64_link_hash_table *ret;
2567 bfd_size_type amt = sizeof (struct elf_aarch64_link_hash_table);
a06ea964 2568
7bf52ea2 2569 ret = bfd_zmalloc (amt);
a06ea964
NC
2570 if (ret == NULL)
2571 return NULL;
2572
2573 if (!_bfd_elf_link_hash_table_init
cec5225b
YZ
2574 (&ret->root, abfd, elfNN_aarch64_link_hash_newfunc,
2575 sizeof (struct elf_aarch64_link_hash_entry), AARCH64_ELF_DATA))
a06ea964
NC
2576 {
2577 free (ret);
2578 return NULL;
2579 }
2580
a06ea964
NC
2581 ret->plt_header_size = PLT_ENTRY_SIZE;
2582 ret->plt_entry_size = PLT_SMALL_ENTRY_SIZE;
a06ea964 2583 ret->obfd = abfd;
a06ea964
NC
2584 ret->dt_tlsdesc_got = (bfd_vma) - 1;
2585
2586 if (!bfd_hash_table_init (&ret->stub_hash_table, stub_hash_newfunc,
cec5225b 2587 sizeof (struct elf_aarch64_stub_hash_entry)))
a06ea964 2588 {
d495ab0d 2589 _bfd_elf_link_hash_table_free (abfd);
a06ea964
NC
2590 return NULL;
2591 }
2592
1419bbe5
WN
2593 ret->loc_hash_table = htab_try_create (1024,
2594 elfNN_aarch64_local_htab_hash,
2595 elfNN_aarch64_local_htab_eq,
2596 NULL);
2597 ret->loc_hash_memory = objalloc_create ();
2598 if (!ret->loc_hash_table || !ret->loc_hash_memory)
2599 {
d495ab0d 2600 elfNN_aarch64_link_hash_table_free (abfd);
1419bbe5
WN
2601 return NULL;
2602 }
d495ab0d 2603 ret->root.root.hash_table_free = elfNN_aarch64_link_hash_table_free;
1419bbe5 2604
a06ea964
NC
2605 return &ret->root.root;
2606}
2607
a06ea964
NC
2608static bfd_boolean
2609aarch64_relocate (unsigned int r_type, bfd *input_bfd, asection *input_section,
2610 bfd_vma offset, bfd_vma value)
2611{
2612 reloc_howto_type *howto;
2613 bfd_vma place;
2614
cec5225b 2615 howto = elfNN_aarch64_howto_from_type (r_type);
a06ea964
NC
2616 place = (input_section->output_section->vma + input_section->output_offset
2617 + offset);
caed7120
YZ
2618
2619 r_type = elfNN_aarch64_bfd_reloc_from_type (r_type);
2620 value = _bfd_aarch64_elf_resolve_relocation (r_type, place, value, 0, FALSE);
2621 return _bfd_aarch64_elf_put_addend (input_bfd,
2622 input_section->contents + offset, r_type,
2623 howto, value);
a06ea964
NC
2624}
2625
cec5225b 2626static enum elf_aarch64_stub_type
a06ea964
NC
2627aarch64_select_branch_stub (bfd_vma value, bfd_vma place)
2628{
2629 if (aarch64_valid_for_adrp_p (value, place))
2630 return aarch64_stub_adrp_branch;
2631 return aarch64_stub_long_branch;
2632}
2633
2634/* Determine the type of stub needed, if any, for a call. */
2635
cec5225b 2636static enum elf_aarch64_stub_type
a06ea964
NC
2637aarch64_type_of_stub (struct bfd_link_info *info,
2638 asection *input_sec,
2639 const Elf_Internal_Rela *rel,
f678ded7 2640 asection *sym_sec,
a06ea964 2641 unsigned char st_type,
cec5225b 2642 struct elf_aarch64_link_hash_entry *hash,
a06ea964
NC
2643 bfd_vma destination)
2644{
2645 bfd_vma location;
2646 bfd_signed_vma branch_offset;
2647 unsigned int r_type;
cec5225b
YZ
2648 struct elf_aarch64_link_hash_table *globals;
2649 enum elf_aarch64_stub_type stub_type = aarch64_stub_none;
a06ea964
NC
2650 bfd_boolean via_plt_p;
2651
f678ded7
JW
2652 if (st_type != STT_FUNC
2653 && (sym_sec != bfd_abs_section_ptr))
a06ea964
NC
2654 return stub_type;
2655
cec5225b 2656 globals = elf_aarch64_hash_table (info);
a06ea964
NC
2657 via_plt_p = (globals->root.splt != NULL && hash != NULL
2658 && hash->root.plt.offset != (bfd_vma) - 1);
07f9ddfe 2659 /* Make sure call to plt stub can fit into the branch range. */
a06ea964 2660 if (via_plt_p)
07f9ddfe
JW
2661 destination = (globals->root.splt->output_section->vma
2662 + globals->root.splt->output_offset
2663 + hash->root.plt.offset);
a06ea964
NC
2664
2665 /* Determine where the call point is. */
2666 location = (input_sec->output_offset
2667 + input_sec->output_section->vma + rel->r_offset);
2668
2669 branch_offset = (bfd_signed_vma) (destination - location);
2670
cec5225b 2671 r_type = ELFNN_R_TYPE (rel->r_info);
a06ea964
NC
2672
2673 /* We don't want to redirect any old unconditional jump in this way,
2674 only one which is being used for a sibcall, where it is
2675 acceptable for the IP0 and IP1 registers to be clobbered. */
a6bb11b2 2676 if ((r_type == AARCH64_R (CALL26) || r_type == AARCH64_R (JUMP26))
a06ea964
NC
2677 && (branch_offset > AARCH64_MAX_FWD_BRANCH_OFFSET
2678 || branch_offset < AARCH64_MAX_BWD_BRANCH_OFFSET))
2679 {
2680 stub_type = aarch64_stub_long_branch;
2681 }
2682
2683 return stub_type;
2684}
2685
2686/* Build a name for an entry in the stub hash table. */
2687
2688static char *
cec5225b 2689elfNN_aarch64_stub_name (const asection *input_section,
a06ea964 2690 const asection *sym_sec,
cec5225b 2691 const struct elf_aarch64_link_hash_entry *hash,
a06ea964
NC
2692 const Elf_Internal_Rela *rel)
2693{
2694 char *stub_name;
2695 bfd_size_type len;
2696
2697 if (hash)
2698 {
2699 len = 8 + 1 + strlen (hash->root.root.root.string) + 1 + 16 + 1;
2700 stub_name = bfd_malloc (len);
2701 if (stub_name != NULL)
2702 snprintf (stub_name, len, "%08x_%s+%" BFD_VMA_FMT "x",
2703 (unsigned int) input_section->id,
2704 hash->root.root.root.string,
2705 rel->r_addend);
2706 }
2707 else
2708 {
2709 len = 8 + 1 + 8 + 1 + 8 + 1 + 16 + 1;
2710 stub_name = bfd_malloc (len);
2711 if (stub_name != NULL)
2712 snprintf (stub_name, len, "%08x_%x:%x+%" BFD_VMA_FMT "x",
2713 (unsigned int) input_section->id,
2714 (unsigned int) sym_sec->id,
cec5225b 2715 (unsigned int) ELFNN_R_SYM (rel->r_info),
a06ea964
NC
2716 rel->r_addend);
2717 }
2718
2719 return stub_name;
2720}
2721
2722/* Look up an entry in the stub hash. Stub entries are cached because
2723 creating the stub name takes a bit of time. */
2724
cec5225b
YZ
2725static struct elf_aarch64_stub_hash_entry *
2726elfNN_aarch64_get_stub_entry (const asection *input_section,
a06ea964
NC
2727 const asection *sym_sec,
2728 struct elf_link_hash_entry *hash,
2729 const Elf_Internal_Rela *rel,
cec5225b 2730 struct elf_aarch64_link_hash_table *htab)
a06ea964 2731{
cec5225b
YZ
2732 struct elf_aarch64_stub_hash_entry *stub_entry;
2733 struct elf_aarch64_link_hash_entry *h =
2734 (struct elf_aarch64_link_hash_entry *) hash;
a06ea964
NC
2735 const asection *id_sec;
2736
2737 if ((input_section->flags & SEC_CODE) == 0)
2738 return NULL;
2739
2740 /* If this input section is part of a group of sections sharing one
2741 stub section, then use the id of the first section in the group.
2742 Stub names need to include a section id, as there may well be
2743 more than one stub used to reach say, printf, and we need to
2744 distinguish between them. */
2745 id_sec = htab->stub_group[input_section->id].link_sec;
2746
2747 if (h != NULL && h->stub_cache != NULL
2748 && h->stub_cache->h == h && h->stub_cache->id_sec == id_sec)
2749 {
2750 stub_entry = h->stub_cache;
2751 }
2752 else
2753 {
2754 char *stub_name;
2755
cec5225b 2756 stub_name = elfNN_aarch64_stub_name (id_sec, sym_sec, h, rel);
a06ea964
NC
2757 if (stub_name == NULL)
2758 return NULL;
2759
2760 stub_entry = aarch64_stub_hash_lookup (&htab->stub_hash_table,
2761 stub_name, FALSE, FALSE);
2762 if (h != NULL)
2763 h->stub_cache = stub_entry;
2764
2765 free (stub_name);
2766 }
2767
2768 return stub_entry;
2769}
2770
a06ea964 2771
66585675
MS
2772/* Create a stub section. */
2773
2774static asection *
2775_bfd_aarch64_create_stub_section (asection *section,
2776 struct elf_aarch64_link_hash_table *htab)
2777{
2778 size_t namelen;
2779 bfd_size_type len;
2780 char *s_name;
2781
2782 namelen = strlen (section->name);
2783 len = namelen + sizeof (STUB_SUFFIX);
2784 s_name = bfd_alloc (htab->stub_bfd, len);
2785 if (s_name == NULL)
2786 return NULL;
2787
2788 memcpy (s_name, section->name, namelen);
2789 memcpy (s_name + namelen, STUB_SUFFIX, sizeof (STUB_SUFFIX));
2790 return (*htab->add_stub_section) (s_name, section);
2791}
2792
2793
fc6d53be
MS
2794/* Find or create a stub section for a link section.
2795
2796 Fix or create the stub section used to collect stubs attached to
2797 the specified link section. */
2798
2799static asection *
2800_bfd_aarch64_get_stub_for_link_section (asection *link_section,
2801 struct elf_aarch64_link_hash_table *htab)
2802{
2803 if (htab->stub_group[link_section->id].stub_sec == NULL)
2804 htab->stub_group[link_section->id].stub_sec
2805 = _bfd_aarch64_create_stub_section (link_section, htab);
2806 return htab->stub_group[link_section->id].stub_sec;
2807}
2808
2809
ef857521
MS
2810/* Find or create a stub section in the stub group for an input
2811 section. */
2812
2813static asection *
2814_bfd_aarch64_create_or_find_stub_sec (asection *section,
2815 struct elf_aarch64_link_hash_table *htab)
a06ea964 2816{
fc6d53be
MS
2817 asection *link_sec = htab->stub_group[section->id].link_sec;
2818 return _bfd_aarch64_get_stub_for_link_section (link_sec, htab);
ef857521
MS
2819}
2820
2821
2822/* Add a new stub entry in the stub group associated with an input
2823 section to the stub hash. Not all fields of the new stub entry are
2824 initialised. */
2825
2826static struct elf_aarch64_stub_hash_entry *
2827_bfd_aarch64_add_stub_entry_in_group (const char *stub_name,
2828 asection *section,
2829 struct elf_aarch64_link_hash_table *htab)
2830{
2831 asection *link_sec;
2832 asection *stub_sec;
2833 struct elf_aarch64_stub_hash_entry *stub_entry;
2834
2835 link_sec = htab->stub_group[section->id].link_sec;
2836 stub_sec = _bfd_aarch64_create_or_find_stub_sec (section, htab);
2837
a06ea964
NC
2838 /* Enter this entry into the linker stub hash table. */
2839 stub_entry = aarch64_stub_hash_lookup (&htab->stub_hash_table, stub_name,
2840 TRUE, FALSE);
2841 if (stub_entry == NULL)
2842 {
2843 (*_bfd_error_handler) (_("%s: cannot create stub entry %s"),
2844 section->owner, stub_name);
2845 return NULL;
2846 }
2847
2848 stub_entry->stub_sec = stub_sec;
2849 stub_entry->stub_offset = 0;
2850 stub_entry->id_sec = link_sec;
2851
2852 return stub_entry;
2853}
2854
4106101c
MS
2855/* Add a new stub entry in the final stub section to the stub hash.
2856 Not all fields of the new stub entry are initialised. */
2857
2858static struct elf_aarch64_stub_hash_entry *
2859_bfd_aarch64_add_stub_entry_after (const char *stub_name,
2860 asection *link_section,
2861 struct elf_aarch64_link_hash_table *htab)
2862{
2863 asection *stub_sec;
2864 struct elf_aarch64_stub_hash_entry *stub_entry;
2865
2866 stub_sec = _bfd_aarch64_get_stub_for_link_section (link_section, htab);
2867 stub_entry = aarch64_stub_hash_lookup (&htab->stub_hash_table, stub_name,
2868 TRUE, FALSE);
2869 if (stub_entry == NULL)
2870 {
2871 (*_bfd_error_handler) (_("cannot create stub entry %s"), stub_name);
2872 return NULL;
2873 }
2874
2875 stub_entry->stub_sec = stub_sec;
2876 stub_entry->stub_offset = 0;
2877 stub_entry->id_sec = link_section;
2878
2879 return stub_entry;
2880}
2881
2882
a06ea964
NC
2883static bfd_boolean
2884aarch64_build_one_stub (struct bfd_hash_entry *gen_entry,
2885 void *in_arg ATTRIBUTE_UNUSED)
2886{
cec5225b 2887 struct elf_aarch64_stub_hash_entry *stub_entry;
a06ea964
NC
2888 asection *stub_sec;
2889 bfd *stub_bfd;
2890 bfd_byte *loc;
2891 bfd_vma sym_value;
68fcca92
JW
2892 bfd_vma veneered_insn_loc;
2893 bfd_vma veneer_entry_loc;
2894 bfd_signed_vma branch_offset = 0;
a06ea964
NC
2895 unsigned int template_size;
2896 const uint32_t *template;
2897 unsigned int i;
2898
2899 /* Massage our args to the form they really have. */
cec5225b 2900 stub_entry = (struct elf_aarch64_stub_hash_entry *) gen_entry;
a06ea964
NC
2901
2902 stub_sec = stub_entry->stub_sec;
2903
2904 /* Make a note of the offset within the stubs for this entry. */
2905 stub_entry->stub_offset = stub_sec->size;
2906 loc = stub_sec->contents + stub_entry->stub_offset;
2907
2908 stub_bfd = stub_sec->owner;
2909
2910 /* This is the address of the stub destination. */
2911 sym_value = (stub_entry->target_value
2912 + stub_entry->target_section->output_offset
2913 + stub_entry->target_section->output_section->vma);
2914
2915 if (stub_entry->stub_type == aarch64_stub_long_branch)
2916 {
2917 bfd_vma place = (stub_entry->stub_offset + stub_sec->output_section->vma
2918 + stub_sec->output_offset);
2919
2920 /* See if we can relax the stub. */
2921 if (aarch64_valid_for_adrp_p (sym_value, place))
2922 stub_entry->stub_type = aarch64_select_branch_stub (sym_value, place);
2923 }
2924
2925 switch (stub_entry->stub_type)
2926 {
2927 case aarch64_stub_adrp_branch:
2928 template = aarch64_adrp_branch_stub;
2929 template_size = sizeof (aarch64_adrp_branch_stub);
2930 break;
2931 case aarch64_stub_long_branch:
2932 template = aarch64_long_branch_stub;
2933 template_size = sizeof (aarch64_long_branch_stub);
2934 break;
68fcca92
JW
2935 case aarch64_stub_erratum_835769_veneer:
2936 template = aarch64_erratum_835769_stub;
2937 template_size = sizeof (aarch64_erratum_835769_stub);
2938 break;
4106101c
MS
2939 case aarch64_stub_erratum_843419_veneer:
2940 template = aarch64_erratum_843419_stub;
2941 template_size = sizeof (aarch64_erratum_843419_stub);
2942 break;
a06ea964 2943 default:
8e2fe09f 2944 abort ();
a06ea964
NC
2945 }
2946
2947 for (i = 0; i < (template_size / sizeof template[0]); i++)
2948 {
2949 bfd_putl32 (template[i], loc);
2950 loc += 4;
2951 }
2952
2953 template_size = (template_size + 7) & ~7;
2954 stub_sec->size += template_size;
2955
2956 switch (stub_entry->stub_type)
2957 {
2958 case aarch64_stub_adrp_branch:
a6bb11b2 2959 if (aarch64_relocate (AARCH64_R (ADR_PREL_PG_HI21), stub_bfd, stub_sec,
a06ea964
NC
2960 stub_entry->stub_offset, sym_value))
2961 /* The stub would not have been relaxed if the offset was out
2962 of range. */
2963 BFD_FAIL ();
2964
93ca8569
TB
2965 if (aarch64_relocate (AARCH64_R (ADD_ABS_LO12_NC), stub_bfd, stub_sec,
2966 stub_entry->stub_offset + 4, sym_value))
2967 BFD_FAIL ();
a06ea964
NC
2968 break;
2969
2970 case aarch64_stub_long_branch:
2971 /* We want the value relative to the address 12 bytes back from the
2972 value itself. */
93ca8569
TB
2973 if (aarch64_relocate (AARCH64_R (PRELNN), stub_bfd, stub_sec,
2974 stub_entry->stub_offset + 16, sym_value + 12))
2975 BFD_FAIL ();
a06ea964 2976 break;
68fcca92
JW
2977
2978 case aarch64_stub_erratum_835769_veneer:
2979 veneered_insn_loc = stub_entry->target_section->output_section->vma
2980 + stub_entry->target_section->output_offset
2981 + stub_entry->target_value;
2982 veneer_entry_loc = stub_entry->stub_sec->output_section->vma
2983 + stub_entry->stub_sec->output_offset
2984 + stub_entry->stub_offset;
2985 branch_offset = veneered_insn_loc - veneer_entry_loc;
2986 branch_offset >>= 2;
2987 branch_offset &= 0x3ffffff;
2988 bfd_putl32 (stub_entry->veneered_insn,
2989 stub_sec->contents + stub_entry->stub_offset);
2990 bfd_putl32 (template[1] | branch_offset,
2991 stub_sec->contents + stub_entry->stub_offset + 4);
2992 break;
2993
4106101c
MS
2994 case aarch64_stub_erratum_843419_veneer:
2995 if (aarch64_relocate (AARCH64_R (JUMP26), stub_bfd, stub_sec,
2996 stub_entry->stub_offset + 4, sym_value + 4))
2997 BFD_FAIL ();
2998 break;
2999
a06ea964 3000 default:
8e2fe09f 3001 abort ();
a06ea964
NC
3002 }
3003
3004 return TRUE;
3005}
3006
3007/* As above, but don't actually build the stub. Just bump offset so
3008 we know stub section sizes. */
3009
3010static bfd_boolean
3011aarch64_size_one_stub (struct bfd_hash_entry *gen_entry,
3012 void *in_arg ATTRIBUTE_UNUSED)
3013{
cec5225b 3014 struct elf_aarch64_stub_hash_entry *stub_entry;
a06ea964
NC
3015 int size;
3016
3017 /* Massage our args to the form they really have. */
cec5225b 3018 stub_entry = (struct elf_aarch64_stub_hash_entry *) gen_entry;
a06ea964
NC
3019
3020 switch (stub_entry->stub_type)
3021 {
3022 case aarch64_stub_adrp_branch:
3023 size = sizeof (aarch64_adrp_branch_stub);
3024 break;
3025 case aarch64_stub_long_branch:
3026 size = sizeof (aarch64_long_branch_stub);
3027 break;
68fcca92
JW
3028 case aarch64_stub_erratum_835769_veneer:
3029 size = sizeof (aarch64_erratum_835769_stub);
3030 break;
4106101c
MS
3031 case aarch64_stub_erratum_843419_veneer:
3032 size = sizeof (aarch64_erratum_843419_stub);
3033 break;
a06ea964 3034 default:
8e2fe09f 3035 abort ();
a06ea964
NC
3036 }
3037
3038 size = (size + 7) & ~7;
3039 stub_entry->stub_sec->size += size;
3040 return TRUE;
3041}
3042
3043/* External entry points for sizing and building linker stubs. */
3044
3045/* Set up various things so that we can make a list of input sections
3046 for each output section included in the link. Returns -1 on error,
3047 0 when no stubs will be needed, and 1 on success. */
3048
3049int
cec5225b 3050elfNN_aarch64_setup_section_lists (bfd *output_bfd,
a06ea964
NC
3051 struct bfd_link_info *info)
3052{
3053 bfd *input_bfd;
3054 unsigned int bfd_count;
7292b3ac 3055 unsigned int top_id, top_index;
a06ea964
NC
3056 asection *section;
3057 asection **input_list, **list;
3058 bfd_size_type amt;
cec5225b
YZ
3059 struct elf_aarch64_link_hash_table *htab =
3060 elf_aarch64_hash_table (info);
a06ea964
NC
3061
3062 if (!is_elf_hash_table (htab))
3063 return 0;
3064
3065 /* Count the number of input BFDs and find the top input section id. */
3066 for (input_bfd = info->input_bfds, bfd_count = 0, top_id = 0;
c72f2fb2 3067 input_bfd != NULL; input_bfd = input_bfd->link.next)
a06ea964
NC
3068 {
3069 bfd_count += 1;
3070 for (section = input_bfd->sections;
3071 section != NULL; section = section->next)
3072 {
3073 if (top_id < section->id)
3074 top_id = section->id;
3075 }
3076 }
3077 htab->bfd_count = bfd_count;
3078
3079 amt = sizeof (struct map_stub) * (top_id + 1);
3080 htab->stub_group = bfd_zmalloc (amt);
3081 if (htab->stub_group == NULL)
3082 return -1;
3083
3084 /* We can't use output_bfd->section_count here to find the top output
3085 section index as some sections may have been removed, and
3086 _bfd_strip_section_from_output doesn't renumber the indices. */
3087 for (section = output_bfd->sections, top_index = 0;
3088 section != NULL; section = section->next)
3089 {
3090 if (top_index < section->index)
3091 top_index = section->index;
3092 }
3093
3094 htab->top_index = top_index;
3095 amt = sizeof (asection *) * (top_index + 1);
3096 input_list = bfd_malloc (amt);
3097 htab->input_list = input_list;
3098 if (input_list == NULL)
3099 return -1;
3100
3101 /* For sections we aren't interested in, mark their entries with a
3102 value we can check later. */
3103 list = input_list + top_index;
3104 do
3105 *list = bfd_abs_section_ptr;
3106 while (list-- != input_list);
3107
3108 for (section = output_bfd->sections;
3109 section != NULL; section = section->next)
3110 {
3111 if ((section->flags & SEC_CODE) != 0)
3112 input_list[section->index] = NULL;
3113 }
3114
3115 return 1;
3116}
3117
cec5225b 3118/* Used by elfNN_aarch64_next_input_section and group_sections. */
a06ea964
NC
3119#define PREV_SEC(sec) (htab->stub_group[(sec)->id].link_sec)
3120
3121/* The linker repeatedly calls this function for each input section,
3122 in the order that input sections are linked into output sections.
3123 Build lists of input sections to determine groupings between which
3124 we may insert linker stubs. */
3125
3126void
cec5225b 3127elfNN_aarch64_next_input_section (struct bfd_link_info *info, asection *isec)
a06ea964 3128{
cec5225b
YZ
3129 struct elf_aarch64_link_hash_table *htab =
3130 elf_aarch64_hash_table (info);
a06ea964
NC
3131
3132 if (isec->output_section->index <= htab->top_index)
3133 {
3134 asection **list = htab->input_list + isec->output_section->index;
3135
3136 if (*list != bfd_abs_section_ptr)
3137 {
3138 /* Steal the link_sec pointer for our list. */
3139 /* This happens to make the list in reverse order,
3140 which is what we want. */
3141 PREV_SEC (isec) = *list;
3142 *list = isec;
3143 }
3144 }
3145}
3146
3147/* See whether we can group stub sections together. Grouping stub
3148 sections may result in fewer stubs. More importantly, we need to
3149 put all .init* and .fini* stubs at the beginning of the .init or
3150 .fini output sections respectively, because glibc splits the
3151 _init and _fini functions into multiple parts. Putting a stub in
3152 the middle of a function is not a good idea. */
3153
3154static void
cec5225b 3155group_sections (struct elf_aarch64_link_hash_table *htab,
a06ea964
NC
3156 bfd_size_type stub_group_size,
3157 bfd_boolean stubs_always_before_branch)
3158{
3159 asection **list = htab->input_list + htab->top_index;
3160
3161 do
3162 {
3163 asection *tail = *list;
3164
3165 if (tail == bfd_abs_section_ptr)
3166 continue;
3167
3168 while (tail != NULL)
3169 {
3170 asection *curr;
3171 asection *prev;
3172 bfd_size_type total;
3173
3174 curr = tail;
3175 total = tail->size;
3176 while ((prev = PREV_SEC (curr)) != NULL
3177 && ((total += curr->output_offset - prev->output_offset)
3178 < stub_group_size))
3179 curr = prev;
3180
3181 /* OK, the size from the start of CURR to the end is less
3182 than stub_group_size and thus can be handled by one stub
3183 section. (Or the tail section is itself larger than
3184 stub_group_size, in which case we may be toast.)
3185 We should really be keeping track of the total size of
3186 stubs added here, as stubs contribute to the final output
3187 section size. */
3188 do
3189 {
3190 prev = PREV_SEC (tail);
3191 /* Set up this stub group. */
3192 htab->stub_group[tail->id].link_sec = curr;
3193 }
3194 while (tail != curr && (tail = prev) != NULL);
3195
3196 /* But wait, there's more! Input sections up to stub_group_size
3197 bytes before the stub section can be handled by it too. */
3198 if (!stubs_always_before_branch)
3199 {
3200 total = 0;
3201 while (prev != NULL
3202 && ((total += tail->output_offset - prev->output_offset)
3203 < stub_group_size))
3204 {
3205 tail = prev;
3206 prev = PREV_SEC (tail);
3207 htab->stub_group[tail->id].link_sec = curr;
3208 }
3209 }
3210 tail = prev;
3211 }
3212 }
3213 while (list-- != htab->input_list);
3214
3215 free (htab->input_list);
3216}
3217
3218#undef PREV_SEC
3219
68fcca92
JW
3220#define AARCH64_BITS(x, pos, n) (((x) >> (pos)) & ((1 << (n)) - 1))
3221
3222#define AARCH64_RT(insn) AARCH64_BITS (insn, 0, 5)
3223#define AARCH64_RT2(insn) AARCH64_BITS (insn, 10, 5)
3224#define AARCH64_RA(insn) AARCH64_BITS (insn, 10, 5)
3225#define AARCH64_RD(insn) AARCH64_BITS (insn, 0, 5)
3226#define AARCH64_RN(insn) AARCH64_BITS (insn, 5, 5)
3227#define AARCH64_RM(insn) AARCH64_BITS (insn, 16, 5)
3228
3229#define AARCH64_MAC(insn) (((insn) & 0xff000000) == 0x9b000000)
3230#define AARCH64_BIT(insn, n) AARCH64_BITS (insn, n, 1)
3231#define AARCH64_OP31(insn) AARCH64_BITS (insn, 21, 3)
3232#define AARCH64_ZR 0x1f
3233
3234/* All ld/st ops. See C4-182 of the ARM ARM. The encoding space for
3235 LD_PCREL, LDST_RO, LDST_UI and LDST_UIMM cover prefetch ops. */
3236
3237#define AARCH64_LD(insn) (AARCH64_BIT (insn, 22) == 1)
3238#define AARCH64_LDST(insn) (((insn) & 0x0a000000) == 0x08000000)
3239#define AARCH64_LDST_EX(insn) (((insn) & 0x3f000000) == 0x08000000)
3240#define AARCH64_LDST_PCREL(insn) (((insn) & 0x3b000000) == 0x18000000)
3241#define AARCH64_LDST_NAP(insn) (((insn) & 0x3b800000) == 0x28000000)
3242#define AARCH64_LDSTP_PI(insn) (((insn) & 0x3b800000) == 0x28800000)
3243#define AARCH64_LDSTP_O(insn) (((insn) & 0x3b800000) == 0x29000000)
3244#define AARCH64_LDSTP_PRE(insn) (((insn) & 0x3b800000) == 0x29800000)
3245#define AARCH64_LDST_UI(insn) (((insn) & 0x3b200c00) == 0x38000000)
3246#define AARCH64_LDST_PIIMM(insn) (((insn) & 0x3b200c00) == 0x38000400)
3247#define AARCH64_LDST_U(insn) (((insn) & 0x3b200c00) == 0x38000800)
3248#define AARCH64_LDST_PREIMM(insn) (((insn) & 0x3b200c00) == 0x38000c00)
3249#define AARCH64_LDST_RO(insn) (((insn) & 0x3b200c00) == 0x38200800)
3250#define AARCH64_LDST_UIMM(insn) (((insn) & 0x3b000000) == 0x39000000)
3251#define AARCH64_LDST_SIMD_M(insn) (((insn) & 0xbfbf0000) == 0x0c000000)
3252#define AARCH64_LDST_SIMD_M_PI(insn) (((insn) & 0xbfa00000) == 0x0c800000)
3253#define AARCH64_LDST_SIMD_S(insn) (((insn) & 0xbf9f0000) == 0x0d000000)
3254#define AARCH64_LDST_SIMD_S_PI(insn) (((insn) & 0xbf800000) == 0x0d800000)
3255
3d14faea
MS
3256/* Classify an INSN if it is indeed a load/store.
3257
3258 Return TRUE if INSN is a LD/ST instruction otherwise return FALSE.
3259
3260 For scalar LD/ST instructions PAIR is FALSE, RT is returned and RT2
3261 is set equal to RT.
3262
3263 For LD/ST pair instructions PAIR is TRUE, RT and RT2 are returned.
3264
3265 */
68fcca92
JW
3266
3267static bfd_boolean
3d14faea 3268aarch64_mem_op_p (uint32_t insn, unsigned int *rt, unsigned int *rt2,
68fcca92
JW
3269 bfd_boolean *pair, bfd_boolean *load)
3270{
3271 uint32_t opcode;
3272 unsigned int r;
3273 uint32_t opc = 0;
3274 uint32_t v = 0;
3275 uint32_t opc_v = 0;
3276
3277 /* Bail out quickly if INSN doesn't fall into the the load-store
3278 encoding space. */
3279 if (!AARCH64_LDST (insn))
3280 return FALSE;
3281
3282 *pair = FALSE;
3283 *load = FALSE;
3284 if (AARCH64_LDST_EX (insn))
3285 {
3286 *rt = AARCH64_RT (insn);
3d14faea 3287 *rt2 = *rt;
68fcca92
JW
3288 if (AARCH64_BIT (insn, 21) == 1)
3289 {
3290 *pair = TRUE;
3d14faea 3291 *rt2 = AARCH64_RT2 (insn);
68fcca92
JW
3292 }
3293 *load = AARCH64_LD (insn);
3294 return TRUE;
3295 }
3296 else if (AARCH64_LDST_NAP (insn)
3297 || AARCH64_LDSTP_PI (insn)
3298 || AARCH64_LDSTP_O (insn)
3299 || AARCH64_LDSTP_PRE (insn))
3300 {
3301 *pair = TRUE;
3302 *rt = AARCH64_RT (insn);
3d14faea 3303 *rt2 = AARCH64_RT2 (insn);
68fcca92
JW
3304 *load = AARCH64_LD (insn);
3305 return TRUE;
3306 }
3307 else if (AARCH64_LDST_PCREL (insn)
3308 || AARCH64_LDST_UI (insn)
3309 || AARCH64_LDST_PIIMM (insn)
3310 || AARCH64_LDST_U (insn)
3311 || AARCH64_LDST_PREIMM (insn)
3312 || AARCH64_LDST_RO (insn)
3313 || AARCH64_LDST_UIMM (insn))
3314 {
3315 *rt = AARCH64_RT (insn);
3d14faea 3316 *rt2 = *rt;
68fcca92
JW
3317 if (AARCH64_LDST_PCREL (insn))
3318 *load = TRUE;
3319 opc = AARCH64_BITS (insn, 22, 2);
3320 v = AARCH64_BIT (insn, 26);
3321 opc_v = opc | (v << 2);
3322 *load = (opc_v == 1 || opc_v == 2 || opc_v == 3
3323 || opc_v == 5 || opc_v == 7);
3324 return TRUE;
3325 }
3326 else if (AARCH64_LDST_SIMD_M (insn)
3327 || AARCH64_LDST_SIMD_M_PI (insn))
3328 {
3329 *rt = AARCH64_RT (insn);
3330 *load = AARCH64_BIT (insn, 22);
3331 opcode = (insn >> 12) & 0xf;
3332 switch (opcode)
3333 {
3334 case 0:
3335 case 2:
3d14faea 3336 *rt2 = *rt + 3;
68fcca92
JW
3337 break;
3338
3339 case 4:
3340 case 6:
3d14faea 3341 *rt2 = *rt + 2;
68fcca92
JW
3342 break;
3343
3344 case 7:
3d14faea 3345 *rt2 = *rt;
68fcca92
JW
3346 break;
3347
3348 case 8:
3349 case 10:
3d14faea 3350 *rt2 = *rt + 1;
68fcca92
JW
3351 break;
3352
3353 default:
3354 return FALSE;
3355 }
3356 return TRUE;
3357 }
3358 else if (AARCH64_LDST_SIMD_S (insn)
3359 || AARCH64_LDST_SIMD_S_PI (insn))
3360 {
3361 *rt = AARCH64_RT (insn);
3362 r = (insn >> 21) & 1;
3363 *load = AARCH64_BIT (insn, 22);
3364 opcode = (insn >> 13) & 0x7;
3365 switch (opcode)
3366 {
3367 case 0:
3368 case 2:
3369 case 4:
3d14faea 3370 *rt2 = *rt + r;
68fcca92
JW
3371 break;
3372
3373 case 1:
3374 case 3:
3375 case 5:
3d14faea 3376 *rt2 = *rt + (r == 0 ? 2 : 3);
68fcca92
JW
3377 break;
3378
3379 case 6:
3d14faea 3380 *rt2 = *rt + r;
68fcca92
JW
3381 break;
3382
3383 case 7:
3d14faea 3384 *rt2 = *rt + (r == 0 ? 2 : 3);
68fcca92
JW
3385 break;
3386
3387 default:
3388 return FALSE;
3389 }
3390 return TRUE;
3391 }
3392
3393 return FALSE;
3394}
3395
3396/* Return TRUE if INSN is multiply-accumulate. */
3397
3398static bfd_boolean
3399aarch64_mlxl_p (uint32_t insn)
3400{
3401 uint32_t op31 = AARCH64_OP31 (insn);
3402
3403 if (AARCH64_MAC (insn)
3404 && (op31 == 0 || op31 == 1 || op31 == 5)
3405 /* Exclude MUL instructions which are encoded as a multiple accumulate
3406 with RA = XZR. */
3407 && AARCH64_RA (insn) != AARCH64_ZR)
3408 return TRUE;
3409
3410 return FALSE;
3411}
3412
3413/* Some early revisions of the Cortex-A53 have an erratum (835769) whereby
3414 it is possible for a 64-bit multiply-accumulate instruction to generate an
3415 incorrect result. The details are quite complex and hard to
3416 determine statically, since branches in the code may exist in some
3417 circumstances, but all cases end with a memory (load, store, or
3418 prefetch) instruction followed immediately by the multiply-accumulate
3419 operation. We employ a linker patching technique, by moving the potentially
3420 affected multiply-accumulate instruction into a patch region and replacing
3421 the original instruction with a branch to the patch. This function checks
3422 if INSN_1 is the memory operation followed by a multiply-accumulate
3423 operation (INSN_2). Return TRUE if an erratum sequence is found, FALSE
3424 if INSN_1 and INSN_2 are safe. */
3425
3426static bfd_boolean
3427aarch64_erratum_sequence (uint32_t insn_1, uint32_t insn_2)
3428{
3429 uint32_t rt;
3d14faea 3430 uint32_t rt2;
68fcca92
JW
3431 uint32_t rn;
3432 uint32_t rm;
3433 uint32_t ra;
3434 bfd_boolean pair;
3435 bfd_boolean load;
3436
3437 if (aarch64_mlxl_p (insn_2)
3d14faea 3438 && aarch64_mem_op_p (insn_1, &rt, &rt2, &pair, &load))
68fcca92
JW
3439 {
3440 /* Any SIMD memory op is independent of the subsequent MLA
3441 by definition of the erratum. */
3442 if (AARCH64_BIT (insn_1, 26))
3443 return TRUE;
3444
3445 /* If not SIMD, check for integer memory ops and MLA relationship. */
3446 rn = AARCH64_RN (insn_2);
3447 ra = AARCH64_RA (insn_2);
3448 rm = AARCH64_RM (insn_2);
3449
3450 /* If this is a load and there's a true(RAW) dependency, we are safe
3451 and this is not an erratum sequence. */
3452 if (load &&
3453 (rt == rn || rt == rm || rt == ra
3d14faea 3454 || (pair && (rt2 == rn || rt2 == rm || rt2 == ra))))
68fcca92
JW
3455 return FALSE;
3456
3457 /* We conservatively put out stubs for all other cases (including
3458 writebacks). */
3459 return TRUE;
3460 }
3461
3462 return FALSE;
3463}
3464
520c7b56
JW
3465/* Used to order a list of mapping symbols by address. */
3466
3467static int
3468elf_aarch64_compare_mapping (const void *a, const void *b)
3469{
3470 const elf_aarch64_section_map *amap = (const elf_aarch64_section_map *) a;
3471 const elf_aarch64_section_map *bmap = (const elf_aarch64_section_map *) b;
3472
3473 if (amap->vma > bmap->vma)
3474 return 1;
3475 else if (amap->vma < bmap->vma)
3476 return -1;
3477 else if (amap->type > bmap->type)
3478 /* Ensure results do not depend on the host qsort for objects with
3479 multiple mapping symbols at the same address by sorting on type
3480 after vma. */
3481 return 1;
3482 else if (amap->type < bmap->type)
3483 return -1;
3484 else
3485 return 0;
3486}
3487
2144188d 3488
35fee8b7
MS
3489static char *
3490_bfd_aarch64_erratum_835769_stub_name (unsigned num_fixes)
3491{
3492 char *stub_name = (char *) bfd_malloc
3493 (strlen ("__erratum_835769_veneer_") + 16);
3494 sprintf (stub_name,"__erratum_835769_veneer_%d", num_fixes);
3495 return stub_name;
3496}
3497
4106101c 3498/* Scan for Cortex-A53 erratum 835769 sequence.
2144188d
MS
3499
3500 Return TRUE else FALSE on abnormal termination. */
3501
68fcca92 3502static bfd_boolean
5421cc6e
MS
3503_bfd_aarch64_erratum_835769_scan (bfd *input_bfd,
3504 struct bfd_link_info *info,
3505 unsigned int *num_fixes_p)
68fcca92
JW
3506{
3507 asection *section;
3508 struct elf_aarch64_link_hash_table *htab = elf_aarch64_hash_table (info);
68fcca92 3509 unsigned int num_fixes = *num_fixes_p;
68fcca92
JW
3510
3511 if (htab == NULL)
2144188d 3512 return TRUE;
68fcca92
JW
3513
3514 for (section = input_bfd->sections;
3515 section != NULL;
3516 section = section->next)
3517 {
3518 bfd_byte *contents = NULL;
3519 struct _aarch64_elf_section_data *sec_data;
3520 unsigned int span;
3521
3522 if (elf_section_type (section) != SHT_PROGBITS
3523 || (elf_section_flags (section) & SHF_EXECINSTR) == 0
3524 || (section->flags & SEC_EXCLUDE) != 0
3525 || (section->sec_info_type == SEC_INFO_TYPE_JUST_SYMS)
3526 || (section->output_section == bfd_abs_section_ptr))
3527 continue;
3528
3529 if (elf_section_data (section)->this_hdr.contents != NULL)
3530 contents = elf_section_data (section)->this_hdr.contents;
3531 else if (! bfd_malloc_and_get_section (input_bfd, section, &contents))
2144188d 3532 return FALSE;
68fcca92
JW
3533
3534 sec_data = elf_aarch64_section_data (section);
520c7b56
JW
3535
3536 qsort (sec_data->map, sec_data->mapcount,
3537 sizeof (elf_aarch64_section_map), elf_aarch64_compare_mapping);
3538
68fcca92
JW
3539 for (span = 0; span < sec_data->mapcount; span++)
3540 {
3541 unsigned int span_start = sec_data->map[span].vma;
3542 unsigned int span_end = ((span == sec_data->mapcount - 1)
3543 ? sec_data->map[0].vma + section->size
3544 : sec_data->map[span + 1].vma);
3545 unsigned int i;
3546 char span_type = sec_data->map[span].type;
3547
3548 if (span_type == 'd')
3549 continue;
3550
3551 for (i = span_start; i + 4 < span_end; i += 4)
3552 {
3553 uint32_t insn_1 = bfd_getl32 (contents + i);
3554 uint32_t insn_2 = bfd_getl32 (contents + i + 4);
3555
3556 if (aarch64_erratum_sequence (insn_1, insn_2))
3557 {
5421cc6e 3558 struct elf_aarch64_stub_hash_entry *stub_entry;
35fee8b7
MS
3559 char *stub_name = _bfd_aarch64_erratum_835769_stub_name (num_fixes);
3560 if (! stub_name)
2144188d 3561 return FALSE;
68fcca92 3562
5421cc6e
MS
3563 stub_entry = _bfd_aarch64_add_stub_entry_in_group (stub_name,
3564 section,
3565 htab);
3566 if (! stub_entry)
3567 return FALSE;
68fcca92 3568
5421cc6e
MS
3569 stub_entry->stub_type = aarch64_stub_erratum_835769_veneer;
3570 stub_entry->target_section = section;
3571 stub_entry->target_value = i + 4;
3572 stub_entry->veneered_insn = insn_2;
3573 stub_entry->output_name = stub_name;
68fcca92
JW
3574 num_fixes++;
3575 }
3576 }
3577 }
3578 if (elf_section_data (section)->this_hdr.contents == NULL)
3579 free (contents);
3580 }
3581
357d1523
MS
3582 *num_fixes_p = num_fixes;
3583
2144188d 3584 return TRUE;
68fcca92
JW
3585}
3586
13f622ec 3587
4106101c
MS
3588/* Test if instruction INSN is ADRP. */
3589
3590static bfd_boolean
3591_bfd_aarch64_adrp_p (uint32_t insn)
3592{
3593 return ((insn & 0x9f000000) == 0x90000000);
3594}
3595
3596
3597/* Helper predicate to look for cortex-a53 erratum 843419 sequence 1. */
3598
3599static bfd_boolean
3600_bfd_aarch64_erratum_843419_sequence_p (uint32_t insn_1, uint32_t insn_2,
3601 uint32_t insn_3)
3602{
3603 uint32_t rt;
3604 uint32_t rt2;
3605 bfd_boolean pair;
3606 bfd_boolean load;
3607
3608 return (aarch64_mem_op_p (insn_2, &rt, &rt2, &pair, &load)
3609 && (!pair
3610 || (pair && !load))
3611 && AARCH64_LDST_UIMM (insn_3)
3612 && AARCH64_RN (insn_3) == AARCH64_RD (insn_1));
3613}
3614
3615
3616/* Test for the presence of Cortex-A53 erratum 843419 instruction sequence.
3617
3618 Return TRUE if section CONTENTS at offset I contains one of the
3619 erratum 843419 sequences, otherwise return FALSE. If a sequence is
3620 seen set P_VENEER_I to the offset of the final LOAD/STORE
3621 instruction in the sequence.
3622 */
3623
3624static bfd_boolean
3625_bfd_aarch64_erratum_843419_p (bfd_byte *contents, bfd_vma vma,
3626 bfd_vma i, bfd_vma span_end,
3627 bfd_vma *p_veneer_i)
3628{
3629 uint32_t insn_1 = bfd_getl32 (contents + i);
3630
3631 if (!_bfd_aarch64_adrp_p (insn_1))
3632 return FALSE;
3633
3634 if (span_end < i + 12)
3635 return FALSE;
3636
3637 uint32_t insn_2 = bfd_getl32 (contents + i + 4);
3638 uint32_t insn_3 = bfd_getl32 (contents + i + 8);
3639
3640 if ((vma & 0xfff) != 0xff8 && (vma & 0xfff) != 0xffc)
3641 return FALSE;
3642
3643 if (_bfd_aarch64_erratum_843419_sequence_p (insn_1, insn_2, insn_3))
3644 {
3645 *p_veneer_i = i + 8;
3646 return TRUE;
3647 }
3648
3649 if (span_end < i + 16)
3650 return FALSE;
3651
3652 uint32_t insn_4 = bfd_getl32 (contents + i + 12);
3653
3654 if (_bfd_aarch64_erratum_843419_sequence_p (insn_1, insn_2, insn_4))
3655 {
3656 *p_veneer_i = i + 12;
3657 return TRUE;
3658 }
3659
3660 return FALSE;
3661}
3662
3663
13f622ec
MS
3664/* Resize all stub sections. */
3665
3666static void
3667_bfd_aarch64_resize_stubs (struct elf_aarch64_link_hash_table *htab)
3668{
3669 asection *section;
3670
3671 /* OK, we've added some stubs. Find out the new size of the
3672 stub sections. */
3673 for (section = htab->stub_bfd->sections;
3674 section != NULL; section = section->next)
3675 {
3676 /* Ignore non-stub sections. */
3677 if (!strstr (section->name, STUB_SUFFIX))
3678 continue;
3679 section->size = 0;
3680 }
3681
3682 bfd_hash_traverse (&htab->stub_hash_table, aarch64_size_one_stub, htab);
13f622ec 3683
61865519
MS
3684 for (section = htab->stub_bfd->sections;
3685 section != NULL; section = section->next)
3686 {
3687 if (!strstr (section->name, STUB_SUFFIX))
3688 continue;
3689
3690 if (section->size)
3691 section->size += 4;
4106101c
MS
3692
3693 /* Ensure all stub sections have a size which is a multiple of
3694 4096. This is important in order to ensure that the insertion
3695 of stub sections does not in itself move existing code around
3696 in such a way that new errata sequences are created. */
3697 if (htab->fix_erratum_843419)
3698 if (section->size)
3699 section->size = BFD_ALIGN (section->size, 0x1000);
3700 }
3701}
3702
3703
3704/* Construct an erratum 843419 workaround stub name.
3705 */
3706
3707static char *
3708_bfd_aarch64_erratum_843419_stub_name (asection *input_section,
3709 bfd_vma offset)
3710{
3711 const bfd_size_type len = 8 + 4 + 1 + 8 + 1 + 16 + 1;
3712 char *stub_name = bfd_malloc (len);
3713
3714 if (stub_name != NULL)
3715 snprintf (stub_name, len, "e843419@%04x_%08x_%" BFD_VMA_FMT "x",
3716 input_section->owner->id,
3717 input_section->id,
3718 offset);
3719 return stub_name;
3720}
3721
3722/* Build a stub_entry structure describing an 843419 fixup.
3723
3724 The stub_entry constructed is populated with the bit pattern INSN
3725 of the instruction located at OFFSET within input SECTION.
3726
3727 Returns TRUE on success. */
3728
3729static bfd_boolean
3730_bfd_aarch64_erratum_843419_fixup (uint32_t insn,
3731 bfd_vma adrp_offset,
3732 bfd_vma ldst_offset,
3733 asection *section,
3734 struct bfd_link_info *info)
3735{
3736 struct elf_aarch64_link_hash_table *htab = elf_aarch64_hash_table (info);
3737 char *stub_name;
3738 struct elf_aarch64_stub_hash_entry *stub_entry;
3739
3740 stub_name = _bfd_aarch64_erratum_843419_stub_name (section, ldst_offset);
3741 stub_entry = aarch64_stub_hash_lookup (&htab->stub_hash_table, stub_name,
3742 FALSE, FALSE);
3743 if (stub_entry)
3744 {
3745 free (stub_name);
3746 return TRUE;
3747 }
3748
3749 /* We always place an 843419 workaround veneer in the stub section
3750 attached to the input section in which an erratum sequence has
3751 been found. This ensures that later in the link process (in
3752 elfNN_aarch64_write_section) when we copy the veneered
3753 instruction from the input section into the stub section the
3754 copied instruction will have had any relocations applied to it.
3755 If we placed workaround veneers in any other stub section then we
3756 could not assume that all relocations have been processed on the
3757 corresponding input section at the point we output the stub
3758 section.
3759 */
3760
3761 stub_entry = _bfd_aarch64_add_stub_entry_after (stub_name, section, htab);
3762 if (stub_entry == NULL)
3763 {
3764 free (stub_name);
3765 return FALSE;
3766 }
3767
3768 stub_entry->adrp_offset = adrp_offset;
3769 stub_entry->target_value = ldst_offset;
3770 stub_entry->target_section = section;
3771 stub_entry->stub_type = aarch64_stub_erratum_843419_veneer;
3772 stub_entry->veneered_insn = insn;
3773 stub_entry->output_name = stub_name;
3774
3775 return TRUE;
3776}
3777
3778
3779/* Scan an input section looking for the signature of erratum 843419.
3780
3781 Scans input SECTION in INPUT_BFD looking for erratum 843419
3782 signatures, for each signature found a stub_entry is created
3783 describing the location of the erratum for subsequent fixup.
3784
3785 Return TRUE on successful scan, FALSE on failure to scan.
3786 */
3787
3788static bfd_boolean
3789_bfd_aarch64_erratum_843419_scan (bfd *input_bfd, asection *section,
3790 struct bfd_link_info *info)
3791{
3792 struct elf_aarch64_link_hash_table *htab = elf_aarch64_hash_table (info);
3793
3794 if (htab == NULL)
3795 return TRUE;
3796
3797 if (elf_section_type (section) != SHT_PROGBITS
3798 || (elf_section_flags (section) & SHF_EXECINSTR) == 0
3799 || (section->flags & SEC_EXCLUDE) != 0
3800 || (section->sec_info_type == SEC_INFO_TYPE_JUST_SYMS)
3801 || (section->output_section == bfd_abs_section_ptr))
3802 return TRUE;
3803
3804 do
3805 {
3806 bfd_byte *contents = NULL;
3807 struct _aarch64_elf_section_data *sec_data;
3808 unsigned int span;
3809
3810 if (elf_section_data (section)->this_hdr.contents != NULL)
3811 contents = elf_section_data (section)->this_hdr.contents;
3812 else if (! bfd_malloc_and_get_section (input_bfd, section, &contents))
3813 return FALSE;
3814
3815 sec_data = elf_aarch64_section_data (section);
3816
3817 qsort (sec_data->map, sec_data->mapcount,
3818 sizeof (elf_aarch64_section_map), elf_aarch64_compare_mapping);
3819
3820 for (span = 0; span < sec_data->mapcount; span++)
3821 {
3822 unsigned int span_start = sec_data->map[span].vma;
3823 unsigned int span_end = ((span == sec_data->mapcount - 1)
3824 ? sec_data->map[0].vma + section->size
3825 : sec_data->map[span + 1].vma);
3826 unsigned int i;
3827 char span_type = sec_data->map[span].type;
3828
3829 if (span_type == 'd')
3830 continue;
3831
3832 for (i = span_start; i + 8 < span_end; i += 4)
3833 {
3834 bfd_vma vma = (section->output_section->vma
3835 + section->output_offset
3836 + i);
3837 bfd_vma veneer_i;
3838
3839 if (_bfd_aarch64_erratum_843419_p
3840 (contents, vma, i, span_end, &veneer_i))
3841 {
3842 uint32_t insn = bfd_getl32 (contents + veneer_i);
3843
3844 if (!_bfd_aarch64_erratum_843419_fixup (insn, i, veneer_i,
3845 section, info))
3846 return FALSE;
3847 }
3848 }
3849 }
3850
3851 if (elf_section_data (section)->this_hdr.contents == NULL)
3852 free (contents);
61865519 3853 }
4106101c
MS
3854 while (0);
3855
3856 return TRUE;
61865519 3857}
13f622ec 3858
4106101c 3859
a06ea964
NC
3860/* Determine and set the size of the stub section for a final link.
3861
3862 The basic idea here is to examine all the relocations looking for
3863 PC-relative calls to a target that is unreachable with a "bl"
3864 instruction. */
3865
3866bfd_boolean
cec5225b 3867elfNN_aarch64_size_stubs (bfd *output_bfd,
a06ea964
NC
3868 bfd *stub_bfd,
3869 struct bfd_link_info *info,
3870 bfd_signed_vma group_size,
3871 asection * (*add_stub_section) (const char *,
3872 asection *),
3873 void (*layout_sections_again) (void))
3874{
3875 bfd_size_type stub_group_size;
3876 bfd_boolean stubs_always_before_branch;
5421cc6e 3877 bfd_boolean stub_changed = FALSE;
cec5225b 3878 struct elf_aarch64_link_hash_table *htab = elf_aarch64_hash_table (info);
68fcca92 3879 unsigned int num_erratum_835769_fixes = 0;
a06ea964
NC
3880
3881 /* Propagate mach to stub bfd, because it may not have been
3882 finalized when we created stub_bfd. */
3883 bfd_set_arch_mach (stub_bfd, bfd_get_arch (output_bfd),
3884 bfd_get_mach (output_bfd));
3885
3886 /* Stash our params away. */
3887 htab->stub_bfd = stub_bfd;
3888 htab->add_stub_section = add_stub_section;
3889 htab->layout_sections_again = layout_sections_again;
3890 stubs_always_before_branch = group_size < 0;
3891 if (group_size < 0)
3892 stub_group_size = -group_size;
3893 else
3894 stub_group_size = group_size;
3895
3896 if (stub_group_size == 1)
3897 {
3898 /* Default values. */
b9eead84 3899 /* AArch64 branch range is +-128MB. The value used is 1MB less. */
a06ea964
NC
3900 stub_group_size = 127 * 1024 * 1024;
3901 }
3902
3903 group_sections (htab, stub_group_size, stubs_always_before_branch);
3904
4106101c
MS
3905 (*htab->layout_sections_again) ();
3906
5421cc6e
MS
3907 if (htab->fix_erratum_835769)
3908 {
3909 bfd *input_bfd;
3910
3911 for (input_bfd = info->input_bfds;
3912 input_bfd != NULL; input_bfd = input_bfd->link.next)
3913 if (!_bfd_aarch64_erratum_835769_scan (input_bfd, info,
3914 &num_erratum_835769_fixes))
3915 return FALSE;
3916
4106101c
MS
3917 _bfd_aarch64_resize_stubs (htab);
3918 (*htab->layout_sections_again) ();
3919 }
3920
3921 if (htab->fix_erratum_843419)
3922 {
3923 bfd *input_bfd;
3924
3925 for (input_bfd = info->input_bfds;
3926 input_bfd != NULL;
3927 input_bfd = input_bfd->link.next)
3928 {
3929 asection *section;
3930
3931 for (section = input_bfd->sections;
3932 section != NULL;
3933 section = section->next)
3934 if (!_bfd_aarch64_erratum_843419_scan (input_bfd, section, info))
3935 return FALSE;
3936 }
3937
3938 _bfd_aarch64_resize_stubs (htab);
3939 (*htab->layout_sections_again) ();
5421cc6e
MS
3940 }
3941
a06ea964
NC
3942 while (1)
3943 {
3944 bfd *input_bfd;
a06ea964 3945
9b9971aa
MS
3946 for (input_bfd = info->input_bfds;
3947 input_bfd != NULL; input_bfd = input_bfd->link.next)
a06ea964
NC
3948 {
3949 Elf_Internal_Shdr *symtab_hdr;
3950 asection *section;
3951 Elf_Internal_Sym *local_syms = NULL;
3952
3953 /* We'll need the symbol table in a second. */
3954 symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
3955 if (symtab_hdr->sh_info == 0)
3956 continue;
3957
3958 /* Walk over each section attached to the input bfd. */
3959 for (section = input_bfd->sections;
3960 section != NULL; section = section->next)
3961 {
3962 Elf_Internal_Rela *internal_relocs, *irelaend, *irela;
3963
3964 /* If there aren't any relocs, then there's nothing more
3965 to do. */
3966 if ((section->flags & SEC_RELOC) == 0
3967 || section->reloc_count == 0
3968 || (section->flags & SEC_CODE) == 0)
3969 continue;
3970
3971 /* If this section is a link-once section that will be
3972 discarded, then don't create any stubs. */
3973 if (section->output_section == NULL
3974 || section->output_section->owner != output_bfd)
3975 continue;
3976
3977 /* Get the relocs. */
3978 internal_relocs
3979 = _bfd_elf_link_read_relocs (input_bfd, section, NULL,
3980 NULL, info->keep_memory);
3981 if (internal_relocs == NULL)
3982 goto error_ret_free_local;
3983
3984 /* Now examine each relocation. */
3985 irela = internal_relocs;
3986 irelaend = irela + section->reloc_count;
3987 for (; irela < irelaend; irela++)
3988 {
3989 unsigned int r_type, r_indx;
cec5225b
YZ
3990 enum elf_aarch64_stub_type stub_type;
3991 struct elf_aarch64_stub_hash_entry *stub_entry;
a06ea964
NC
3992 asection *sym_sec;
3993 bfd_vma sym_value;
3994 bfd_vma destination;
cec5225b 3995 struct elf_aarch64_link_hash_entry *hash;
a06ea964
NC
3996 const char *sym_name;
3997 char *stub_name;
3998 const asection *id_sec;
3999 unsigned char st_type;
4000 bfd_size_type len;
4001
cec5225b
YZ
4002 r_type = ELFNN_R_TYPE (irela->r_info);
4003 r_indx = ELFNN_R_SYM (irela->r_info);
a06ea964
NC
4004
4005 if (r_type >= (unsigned int) R_AARCH64_end)
4006 {
4007 bfd_set_error (bfd_error_bad_value);
4008 error_ret_free_internal:
4009 if (elf_section_data (section)->relocs == NULL)
4010 free (internal_relocs);
4011 goto error_ret_free_local;
4012 }
4013
4014 /* Only look for stubs on unconditional branch and
4015 branch and link instructions. */
a6bb11b2
YZ
4016 if (r_type != (unsigned int) AARCH64_R (CALL26)
4017 && r_type != (unsigned int) AARCH64_R (JUMP26))
a06ea964
NC
4018 continue;
4019
4020 /* Now determine the call target, its name, value,
4021 section. */
4022 sym_sec = NULL;
4023 sym_value = 0;
4024 destination = 0;
4025 hash = NULL;
4026 sym_name = NULL;
4027 if (r_indx < symtab_hdr->sh_info)
4028 {
4029 /* It's a local symbol. */
4030 Elf_Internal_Sym *sym;
4031 Elf_Internal_Shdr *hdr;
4032
4033 if (local_syms == NULL)
4034 {
4035 local_syms
4036 = (Elf_Internal_Sym *) symtab_hdr->contents;
4037 if (local_syms == NULL)
4038 local_syms
4039 = bfd_elf_get_elf_syms (input_bfd, symtab_hdr,
4040 symtab_hdr->sh_info, 0,
4041 NULL, NULL, NULL);
4042 if (local_syms == NULL)
4043 goto error_ret_free_internal;
4044 }
4045
4046 sym = local_syms + r_indx;
4047 hdr = elf_elfsections (input_bfd)[sym->st_shndx];
4048 sym_sec = hdr->bfd_section;
4049 if (!sym_sec)
4050 /* This is an undefined symbol. It can never
4051 be resolved. */
4052 continue;
4053
4054 if (ELF_ST_TYPE (sym->st_info) != STT_SECTION)
4055 sym_value = sym->st_value;
4056 destination = (sym_value + irela->r_addend
4057 + sym_sec->output_offset
4058 + sym_sec->output_section->vma);
4059 st_type = ELF_ST_TYPE (sym->st_info);
4060 sym_name
4061 = bfd_elf_string_from_elf_section (input_bfd,
4062 symtab_hdr->sh_link,
4063 sym->st_name);
4064 }
4065 else
4066 {
4067 int e_indx;
4068
4069 e_indx = r_indx - symtab_hdr->sh_info;
cec5225b 4070 hash = ((struct elf_aarch64_link_hash_entry *)
a06ea964
NC
4071 elf_sym_hashes (input_bfd)[e_indx]);
4072
4073 while (hash->root.root.type == bfd_link_hash_indirect
4074 || hash->root.root.type == bfd_link_hash_warning)
cec5225b 4075 hash = ((struct elf_aarch64_link_hash_entry *)
a06ea964
NC
4076 hash->root.root.u.i.link);
4077
4078 if (hash->root.root.type == bfd_link_hash_defined
4079 || hash->root.root.type == bfd_link_hash_defweak)
4080 {
cec5225b
YZ
4081 struct elf_aarch64_link_hash_table *globals =
4082 elf_aarch64_hash_table (info);
a06ea964
NC
4083 sym_sec = hash->root.root.u.def.section;
4084 sym_value = hash->root.root.u.def.value;
4085 /* For a destination in a shared library,
4086 use the PLT stub as target address to
4087 decide whether a branch stub is
4088 needed. */
4089 if (globals->root.splt != NULL && hash != NULL
4090 && hash->root.plt.offset != (bfd_vma) - 1)
4091 {
4092 sym_sec = globals->root.splt;
4093 sym_value = hash->root.plt.offset;
4094 if (sym_sec->output_section != NULL)
4095 destination = (sym_value
4096 + sym_sec->output_offset
4097 +
4098 sym_sec->output_section->vma);
4099 }
4100 else if (sym_sec->output_section != NULL)
4101 destination = (sym_value + irela->r_addend
4102 + sym_sec->output_offset
4103 + sym_sec->output_section->vma);
4104 }
4105 else if (hash->root.root.type == bfd_link_hash_undefined
4106 || (hash->root.root.type
4107 == bfd_link_hash_undefweak))
4108 {
4109 /* For a shared library, use the PLT stub as
4110 target address to decide whether a long
4111 branch stub is needed.
4112 For absolute code, they cannot be handled. */
cec5225b
YZ
4113 struct elf_aarch64_link_hash_table *globals =
4114 elf_aarch64_hash_table (info);
a06ea964
NC
4115
4116 if (globals->root.splt != NULL && hash != NULL
4117 && hash->root.plt.offset != (bfd_vma) - 1)
4118 {
4119 sym_sec = globals->root.splt;
4120 sym_value = hash->root.plt.offset;
4121 if (sym_sec->output_section != NULL)
4122 destination = (sym_value
4123 + sym_sec->output_offset
4124 +
4125 sym_sec->output_section->vma);
4126 }
4127 else
4128 continue;
4129 }
4130 else
4131 {
4132 bfd_set_error (bfd_error_bad_value);
4133 goto error_ret_free_internal;
4134 }
4135 st_type = ELF_ST_TYPE (hash->root.type);
4136 sym_name = hash->root.root.root.string;
4137 }
4138
4139 /* Determine what (if any) linker stub is needed. */
4140 stub_type = aarch64_type_of_stub
f678ded7 4141 (info, section, irela, sym_sec, st_type, hash, destination);
a06ea964
NC
4142 if (stub_type == aarch64_stub_none)
4143 continue;
4144
4145 /* Support for grouping stub sections. */
4146 id_sec = htab->stub_group[section->id].link_sec;
4147
4148 /* Get the name of this stub. */
cec5225b 4149 stub_name = elfNN_aarch64_stub_name (id_sec, sym_sec, hash,
a06ea964
NC
4150 irela);
4151 if (!stub_name)
4152 goto error_ret_free_internal;
4153
4154 stub_entry =
4155 aarch64_stub_hash_lookup (&htab->stub_hash_table,
4156 stub_name, FALSE, FALSE);
4157 if (stub_entry != NULL)
4158 {
4159 /* The proper stub has already been created. */
4160 free (stub_name);
4161 continue;
4162 }
4163
ef857521
MS
4164 stub_entry = _bfd_aarch64_add_stub_entry_in_group
4165 (stub_name, section, htab);
a06ea964
NC
4166 if (stub_entry == NULL)
4167 {
4168 free (stub_name);
4169 goto error_ret_free_internal;
4170 }
4171
4172 stub_entry->target_value = sym_value;
4173 stub_entry->target_section = sym_sec;
4174 stub_entry->stub_type = stub_type;
4175 stub_entry->h = hash;
4176 stub_entry->st_type = st_type;
4177
4178 if (sym_name == NULL)
4179 sym_name = "unnamed";
4180 len = sizeof (STUB_ENTRY_NAME) + strlen (sym_name);
4181 stub_entry->output_name = bfd_alloc (htab->stub_bfd, len);
4182 if (stub_entry->output_name == NULL)
4183 {
4184 free (stub_name);
4185 goto error_ret_free_internal;
4186 }
4187
4188 snprintf (stub_entry->output_name, len, STUB_ENTRY_NAME,
4189 sym_name);
4190
4191 stub_changed = TRUE;
4192 }
4193
4194 /* We're done with the internal relocs, free them. */
4195 if (elf_section_data (section)->relocs == NULL)
4196 free (internal_relocs);
4197 }
4198 }
4199
4200 if (!stub_changed)
4201 break;
4202
13f622ec 4203 _bfd_aarch64_resize_stubs (htab);
a06ea964
NC
4204
4205 /* Ask the linker to do its stuff. */
4206 (*htab->layout_sections_again) ();
4207 stub_changed = FALSE;
4208 }
4209
4210 return TRUE;
4211
4212error_ret_free_local:
4213 return FALSE;
4214}
4215
4216/* Build all the stubs associated with the current output file. The
4217 stubs are kept in a hash table attached to the main linker hash
4218 table. We also set up the .plt entries for statically linked PIC
4219 functions here. This function is called via aarch64_elf_finish in the
4220 linker. */
4221
4222bfd_boolean
cec5225b 4223elfNN_aarch64_build_stubs (struct bfd_link_info *info)
a06ea964
NC
4224{
4225 asection *stub_sec;
4226 struct bfd_hash_table *table;
cec5225b 4227 struct elf_aarch64_link_hash_table *htab;
a06ea964 4228
cec5225b 4229 htab = elf_aarch64_hash_table (info);
a06ea964
NC
4230
4231 for (stub_sec = htab->stub_bfd->sections;
4232 stub_sec != NULL; stub_sec = stub_sec->next)
4233 {
4234 bfd_size_type size;
4235
4236 /* Ignore non-stub sections. */
4237 if (!strstr (stub_sec->name, STUB_SUFFIX))
4238 continue;
4239
4240 /* Allocate memory to hold the linker stubs. */
4241 size = stub_sec->size;
4242 stub_sec->contents = bfd_zalloc (htab->stub_bfd, size);
4243 if (stub_sec->contents == NULL && size != 0)
4244 return FALSE;
4245 stub_sec->size = 0;
61865519
MS
4246
4247 bfd_putl32 (0x14000000 | (size >> 2), stub_sec->contents);
4248 stub_sec->size += 4;
a06ea964
NC
4249 }
4250
4251 /* Build the stubs as directed by the stub hash table. */
4252 table = &htab->stub_hash_table;
4253 bfd_hash_traverse (table, aarch64_build_one_stub, info);
4254
4255 return TRUE;
4256}
4257
4258
4259/* Add an entry to the code/data map for section SEC. */
4260
4261static void
cec5225b 4262elfNN_aarch64_section_map_add (asection *sec, char type, bfd_vma vma)
a06ea964
NC
4263{
4264 struct _aarch64_elf_section_data *sec_data =
cec5225b 4265 elf_aarch64_section_data (sec);
a06ea964
NC
4266 unsigned int newidx;
4267
4268 if (sec_data->map == NULL)
4269 {
cec5225b 4270 sec_data->map = bfd_malloc (sizeof (elf_aarch64_section_map));
a06ea964
NC
4271 sec_data->mapcount = 0;
4272 sec_data->mapsize = 1;
4273 }
4274
4275 newidx = sec_data->mapcount++;
4276
4277 if (sec_data->mapcount > sec_data->mapsize)
4278 {
4279 sec_data->mapsize *= 2;
4280 sec_data->map = bfd_realloc_or_free
cec5225b 4281 (sec_data->map, sec_data->mapsize * sizeof (elf_aarch64_section_map));
a06ea964
NC
4282 }
4283
4284 if (sec_data->map)
4285 {
4286 sec_data->map[newidx].vma = vma;
4287 sec_data->map[newidx].type = type;
4288 }
4289}
4290
4291
4292/* Initialise maps of insn/data for input BFDs. */
4293void
cec5225b 4294bfd_elfNN_aarch64_init_maps (bfd *abfd)
a06ea964
NC
4295{
4296 Elf_Internal_Sym *isymbuf;
4297 Elf_Internal_Shdr *hdr;
4298 unsigned int i, localsyms;
4299
4300 /* Make sure that we are dealing with an AArch64 elf binary. */
4301 if (!is_aarch64_elf (abfd))
4302 return;
4303
4304 if ((abfd->flags & DYNAMIC) != 0)
68fcca92 4305 return;
a06ea964
NC
4306
4307 hdr = &elf_symtab_hdr (abfd);
4308 localsyms = hdr->sh_info;
4309
4310 /* Obtain a buffer full of symbols for this BFD. The hdr->sh_info field
4311 should contain the number of local symbols, which should come before any
4312 global symbols. Mapping symbols are always local. */
4313 isymbuf = bfd_elf_get_elf_syms (abfd, hdr, localsyms, 0, NULL, NULL, NULL);
4314
4315 /* No internal symbols read? Skip this BFD. */
4316 if (isymbuf == NULL)
4317 return;
4318
4319 for (i = 0; i < localsyms; i++)
4320 {
4321 Elf_Internal_Sym *isym = &isymbuf[i];
4322 asection *sec = bfd_section_from_elf_index (abfd, isym->st_shndx);
4323 const char *name;
4324
4325 if (sec != NULL && ELF_ST_BIND (isym->st_info) == STB_LOCAL)
4326 {
4327 name = bfd_elf_string_from_elf_section (abfd,
4328 hdr->sh_link,
4329 isym->st_name);
4330
4331 if (bfd_is_aarch64_special_symbol_name
4332 (name, BFD_AARCH64_SPECIAL_SYM_TYPE_MAP))
cec5225b 4333 elfNN_aarch64_section_map_add (sec, name[1], isym->st_value);
a06ea964
NC
4334 }
4335 }
4336}
4337
4338/* Set option values needed during linking. */
4339void
cec5225b 4340bfd_elfNN_aarch64_set_options (struct bfd *output_bfd,
a06ea964
NC
4341 struct bfd_link_info *link_info,
4342 int no_enum_warn,
68fcca92 4343 int no_wchar_warn, int pic_veneer,
4106101c
MS
4344 int fix_erratum_835769,
4345 int fix_erratum_843419)
a06ea964 4346{
cec5225b 4347 struct elf_aarch64_link_hash_table *globals;
a06ea964 4348
cec5225b 4349 globals = elf_aarch64_hash_table (link_info);
a06ea964 4350 globals->pic_veneer = pic_veneer;
68fcca92 4351 globals->fix_erratum_835769 = fix_erratum_835769;
4106101c
MS
4352 globals->fix_erratum_843419 = fix_erratum_843419;
4353 globals->fix_erratum_843419_adr = TRUE;
a06ea964
NC
4354
4355 BFD_ASSERT (is_aarch64_elf (output_bfd));
4356 elf_aarch64_tdata (output_bfd)->no_enum_size_warning = no_enum_warn;
4357 elf_aarch64_tdata (output_bfd)->no_wchar_size_warning = no_wchar_warn;
4358}
4359
a06ea964
NC
4360static bfd_vma
4361aarch64_calculate_got_entry_vma (struct elf_link_hash_entry *h,
cec5225b 4362 struct elf_aarch64_link_hash_table
a06ea964
NC
4363 *globals, struct bfd_link_info *info,
4364 bfd_vma value, bfd *output_bfd,
4365 bfd_boolean *unresolved_reloc_p)
4366{
4367 bfd_vma off = (bfd_vma) - 1;
4368 asection *basegot = globals->root.sgot;
4369 bfd_boolean dyn = globals->root.dynamic_sections_created;
4370
4371 if (h != NULL)
4372 {
a6bb11b2 4373 BFD_ASSERT (basegot != NULL);
a06ea964
NC
4374 off = h->got.offset;
4375 BFD_ASSERT (off != (bfd_vma) - 1);
0e1862bb
L
4376 if (!WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, bfd_link_pic (info), h)
4377 || (bfd_link_pic (info)
a06ea964
NC
4378 && SYMBOL_REFERENCES_LOCAL (info, h))
4379 || (ELF_ST_VISIBILITY (h->other)
4380 && h->root.type == bfd_link_hash_undefweak))
4381 {
4382 /* This is actually a static link, or it is a -Bsymbolic link
4383 and the symbol is defined locally. We must initialize this
4384 entry in the global offset table. Since the offset must
a6bb11b2
YZ
4385 always be a multiple of 8 (4 in the case of ILP32), we use
4386 the least significant bit to record whether we have
4387 initialized it already.
a06ea964
NC
4388 When doing a dynamic link, we create a .rel(a).got relocation
4389 entry to initialize the value. This is done in the
4390 finish_dynamic_symbol routine. */
4391 if ((off & 1) != 0)
4392 off &= ~1;
4393 else
4394 {
cec5225b 4395 bfd_put_NN (output_bfd, value, basegot->contents + off);
a06ea964
NC
4396 h->got.offset |= 1;
4397 }
4398 }
4399 else
4400 *unresolved_reloc_p = FALSE;
4401
4402 off = off + basegot->output_section->vma + basegot->output_offset;
4403 }
4404
4405 return off;
4406}
4407
4408/* Change R_TYPE to a more efficient access model where possible,
4409 return the new reloc type. */
4410
a6bb11b2
YZ
4411static bfd_reloc_code_real_type
4412aarch64_tls_transition_without_check (bfd_reloc_code_real_type r_type,
a06ea964
NC
4413 struct elf_link_hash_entry *h)
4414{
4415 bfd_boolean is_local = h == NULL;
a6bb11b2 4416
a06ea964
NC
4417 switch (r_type)
4418 {
a6bb11b2 4419 case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21:
ce336788 4420 case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21:
a6bb11b2
YZ
4421 return (is_local
4422 ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1
4423 : BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21);
4424
389b8029
MS
4425 case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21:
4426 return (is_local
4427 ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC
4428 : r_type);
4429
1ada945d
MS
4430 case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19:
4431 return (is_local
4432 ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1
4433 : BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19);
4434
a6bb11b2 4435 case BFD_RELOC_AARCH64_TLSDESC_LDNN_LO12_NC:
ce336788 4436 case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC:
a6bb11b2
YZ
4437 return (is_local
4438 ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC
4439 : BFD_RELOC_AARCH64_TLSIE_LDNN_GOTTPREL_LO12_NC);
4440
4441 case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21:
4442 return is_local ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1 : r_type;
4443
4444 case BFD_RELOC_AARCH64_TLSIE_LDNN_GOTTPREL_LO12_NC:
4445 return is_local ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC : r_type;
4446
043bf05a
MS
4447 case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19:
4448 return r_type;
4449
3c12b054
MS
4450 case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21:
4451 return (is_local
4452 ? BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_HI12
4453 : BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19);
4454
a6bb11b2
YZ
4455 case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12_NC:
4456 case BFD_RELOC_AARCH64_TLSDESC_CALL:
a06ea964 4457 /* Instructions with these relocations will become NOPs. */
a6bb11b2
YZ
4458 return BFD_RELOC_AARCH64_NONE;
4459
259364ad
JW
4460 case BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC:
4461 case BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21:
4462 case BFD_RELOC_AARCH64_TLSLD_ADR_PREL21:
4463 return is_local ? BFD_RELOC_AARCH64_NONE : r_type;
4464
ac734732
RL
4465#if ARCH_SIZE == 64
4466 case BFD_RELOC_AARCH64_TLSGD_MOVW_G0_NC:
4467 return is_local
4468 ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1_NC
4469 : BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G0_NC;
4470
4471 case BFD_RELOC_AARCH64_TLSGD_MOVW_G1:
4472 return is_local
4473 ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G2
4474 : BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G1;
4475#endif
4476
a6bb11b2
YZ
4477 default:
4478 break;
a06ea964
NC
4479 }
4480
4481 return r_type;
4482}
4483
4484static unsigned int
a6bb11b2 4485aarch64_reloc_got_type (bfd_reloc_code_real_type r_type)
a06ea964
NC
4486{
4487 switch (r_type)
4488 {
a6bb11b2
YZ
4489 case BFD_RELOC_AARCH64_ADR_GOT_PAGE:
4490 case BFD_RELOC_AARCH64_GOT_LD_PREL19:
7018c030 4491 case BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14:
ce336788 4492 case BFD_RELOC_AARCH64_LD32_GOT_LO12_NC:
a2e1db00 4493 case BFD_RELOC_AARCH64_LD64_GOTOFF_LO15:
99ad26cb 4494 case BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15:
ce336788 4495 case BFD_RELOC_AARCH64_LD64_GOT_LO12_NC:
dc8008f5 4496 case BFD_RELOC_AARCH64_MOVW_GOTOFF_G0_NC:
74a1bfe1 4497 case BFD_RELOC_AARCH64_MOVW_GOTOFF_G1:
a06ea964
NC
4498 return GOT_NORMAL;
4499
ce336788 4500 case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC:
a6bb11b2 4501 case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21:
3c12b054 4502 case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21:
7ba7cfe4 4503 case BFD_RELOC_AARCH64_TLSGD_MOVW_G0_NC:
94facae3 4504 case BFD_RELOC_AARCH64_TLSGD_MOVW_G1:
73f925cc 4505 case BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC:
f69e4920 4506 case BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21:
77a69ff8 4507 case BFD_RELOC_AARCH64_TLSLD_ADR_PREL21:
a06ea964
NC
4508 return GOT_TLS_GD;
4509
a6bb11b2
YZ
4510 case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12_NC:
4511 case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21:
389b8029 4512 case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21:
a6bb11b2 4513 case BFD_RELOC_AARCH64_TLSDESC_CALL:
a6bb11b2 4514 case BFD_RELOC_AARCH64_TLSDESC_LD32_LO12_NC:
ce336788 4515 case BFD_RELOC_AARCH64_TLSDESC_LD64_LO12_NC:
1ada945d 4516 case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19:
a06ea964
NC
4517 return GOT_TLSDESC_GD;
4518
a6bb11b2 4519 case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21:
a6bb11b2 4520 case BFD_RELOC_AARCH64_TLSIE_LD32_GOTTPREL_LO12_NC:
ce336788 4521 case BFD_RELOC_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC:
043bf05a 4522 case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19:
3b957e5b
RL
4523 case BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G0_NC:
4524 case BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G1:
a06ea964
NC
4525 return GOT_TLS_IE;
4526
a6bb11b2
YZ
4527 default:
4528 break;
a06ea964
NC
4529 }
4530 return GOT_UNKNOWN;
4531}
4532
4533static bfd_boolean
4534aarch64_can_relax_tls (bfd *input_bfd,
4535 struct bfd_link_info *info,
a6bb11b2 4536 bfd_reloc_code_real_type r_type,
a06ea964
NC
4537 struct elf_link_hash_entry *h,
4538 unsigned long r_symndx)
4539{
4540 unsigned int symbol_got_type;
4541 unsigned int reloc_got_type;
4542
9331eea1 4543 if (! IS_AARCH64_TLS_RELAX_RELOC (r_type))
a06ea964
NC
4544 return FALSE;
4545
cec5225b 4546 symbol_got_type = elfNN_aarch64_symbol_got_type (h, input_bfd, r_symndx);
a06ea964
NC
4547 reloc_got_type = aarch64_reloc_got_type (r_type);
4548
4549 if (symbol_got_type == GOT_TLS_IE && GOT_TLS_GD_ANY_P (reloc_got_type))
4550 return TRUE;
4551
0e1862bb 4552 if (bfd_link_pic (info))
a06ea964
NC
4553 return FALSE;
4554
4555 if (h && h->root.type == bfd_link_hash_undefweak)
4556 return FALSE;
4557
4558 return TRUE;
4559}
4560
a6bb11b2
YZ
4561/* Given the relocation code R_TYPE, return the relaxed bfd reloc
4562 enumerator. */
4563
4564static bfd_reloc_code_real_type
a06ea964
NC
4565aarch64_tls_transition (bfd *input_bfd,
4566 struct bfd_link_info *info,
4567 unsigned int r_type,
4568 struct elf_link_hash_entry *h,
4569 unsigned long r_symndx)
4570{
a6bb11b2
YZ
4571 bfd_reloc_code_real_type bfd_r_type
4572 = elfNN_aarch64_bfd_reloc_from_type (r_type);
a06ea964 4573
a6bb11b2
YZ
4574 if (! aarch64_can_relax_tls (input_bfd, info, bfd_r_type, h, r_symndx))
4575 return bfd_r_type;
4576
4577 return aarch64_tls_transition_without_check (bfd_r_type, h);
a06ea964
NC
4578}
4579
4580/* Return the base VMA address which should be subtracted from real addresses
a6bb11b2 4581 when resolving R_AARCH64_TLS_DTPREL relocation. */
a06ea964
NC
4582
4583static bfd_vma
4584dtpoff_base (struct bfd_link_info *info)
4585{
4586 /* If tls_sec is NULL, we should have signalled an error already. */
4587 BFD_ASSERT (elf_hash_table (info)->tls_sec != NULL);
4588 return elf_hash_table (info)->tls_sec->vma;
4589}
4590
a06ea964
NC
4591/* Return the base VMA address which should be subtracted from real addresses
4592 when resolving R_AARCH64_TLS_GOTTPREL64 relocations. */
4593
4594static bfd_vma
4595tpoff_base (struct bfd_link_info *info)
4596{
4597 struct elf_link_hash_table *htab = elf_hash_table (info);
4598
4599 /* If tls_sec is NULL, we should have signalled an error already. */
ac21917f 4600 BFD_ASSERT (htab->tls_sec != NULL);
a06ea964
NC
4601
4602 bfd_vma base = align_power ((bfd_vma) TCB_SIZE,
4603 htab->tls_sec->alignment_power);
4604 return htab->tls_sec->vma - base;
4605}
4606
4607static bfd_vma *
4608symbol_got_offset_ref (bfd *input_bfd, struct elf_link_hash_entry *h,
4609 unsigned long r_symndx)
4610{
4611 /* Calculate the address of the GOT entry for symbol
4612 referred to in h. */
4613 if (h != NULL)
4614 return &h->got.offset;
4615 else
4616 {
4617 /* local symbol */
4618 struct elf_aarch64_local_symbol *l;
4619
cec5225b 4620 l = elf_aarch64_locals (input_bfd);
a06ea964
NC
4621 return &l[r_symndx].got_offset;
4622 }
4623}
4624
4625static void
4626symbol_got_offset_mark (bfd *input_bfd, struct elf_link_hash_entry *h,
4627 unsigned long r_symndx)
4628{
4629 bfd_vma *p;
4630 p = symbol_got_offset_ref (input_bfd, h, r_symndx);
4631 *p |= 1;
4632}
4633
4634static int
4635symbol_got_offset_mark_p (bfd *input_bfd, struct elf_link_hash_entry *h,
4636 unsigned long r_symndx)
4637{
4638 bfd_vma value;
4639 value = * symbol_got_offset_ref (input_bfd, h, r_symndx);
4640 return value & 1;
4641}
4642
4643static bfd_vma
4644symbol_got_offset (bfd *input_bfd, struct elf_link_hash_entry *h,
4645 unsigned long r_symndx)
4646{
4647 bfd_vma value;
4648 value = * symbol_got_offset_ref (input_bfd, h, r_symndx);
4649 value &= ~1;
4650 return value;
4651}
4652
4653static bfd_vma *
4654symbol_tlsdesc_got_offset_ref (bfd *input_bfd, struct elf_link_hash_entry *h,
4655 unsigned long r_symndx)
4656{
4657 /* Calculate the address of the GOT entry for symbol
4658 referred to in h. */
4659 if (h != NULL)
4660 {
cec5225b
YZ
4661 struct elf_aarch64_link_hash_entry *eh;
4662 eh = (struct elf_aarch64_link_hash_entry *) h;
a06ea964
NC
4663 return &eh->tlsdesc_got_jump_table_offset;
4664 }
4665 else
4666 {
4667 /* local symbol */
4668 struct elf_aarch64_local_symbol *l;
4669
cec5225b 4670 l = elf_aarch64_locals (input_bfd);
a06ea964
NC
4671 return &l[r_symndx].tlsdesc_got_jump_table_offset;
4672 }
4673}
4674
4675static void
4676symbol_tlsdesc_got_offset_mark (bfd *input_bfd, struct elf_link_hash_entry *h,
4677 unsigned long r_symndx)
4678{
4679 bfd_vma *p;
4680 p = symbol_tlsdesc_got_offset_ref (input_bfd, h, r_symndx);
4681 *p |= 1;
4682}
4683
4684static int
4685symbol_tlsdesc_got_offset_mark_p (bfd *input_bfd,
4686 struct elf_link_hash_entry *h,
4687 unsigned long r_symndx)
4688{
4689 bfd_vma value;
4690 value = * symbol_tlsdesc_got_offset_ref (input_bfd, h, r_symndx);
4691 return value & 1;
4692}
4693
4694static bfd_vma
4695symbol_tlsdesc_got_offset (bfd *input_bfd, struct elf_link_hash_entry *h,
4696 unsigned long r_symndx)
4697{
4698 bfd_vma value;
4699 value = * symbol_tlsdesc_got_offset_ref (input_bfd, h, r_symndx);
4700 value &= ~1;
4701 return value;
4702}
4703
68fcca92
JW
4704/* Data for make_branch_to_erratum_835769_stub(). */
4705
4706struct erratum_835769_branch_to_stub_data
4707{
4106101c 4708 struct bfd_link_info *info;
68fcca92
JW
4709 asection *output_section;
4710 bfd_byte *contents;
4711};
4712
4713/* Helper to insert branches to erratum 835769 stubs in the right
4714 places for a particular section. */
4715
4716static bfd_boolean
4717make_branch_to_erratum_835769_stub (struct bfd_hash_entry *gen_entry,
4718 void *in_arg)
4719{
4720 struct elf_aarch64_stub_hash_entry *stub_entry;
4721 struct erratum_835769_branch_to_stub_data *data;
4722 bfd_byte *contents;
4723 unsigned long branch_insn = 0;
4724 bfd_vma veneered_insn_loc, veneer_entry_loc;
4725 bfd_signed_vma branch_offset;
4726 unsigned int target;
4727 bfd *abfd;
4728
4729 stub_entry = (struct elf_aarch64_stub_hash_entry *) gen_entry;
4730 data = (struct erratum_835769_branch_to_stub_data *) in_arg;
4731
4732 if (stub_entry->target_section != data->output_section
4733 || stub_entry->stub_type != aarch64_stub_erratum_835769_veneer)
4734 return TRUE;
4735
4736 contents = data->contents;
4737 veneered_insn_loc = stub_entry->target_section->output_section->vma
4738 + stub_entry->target_section->output_offset
4739 + stub_entry->target_value;
4740 veneer_entry_loc = stub_entry->stub_sec->output_section->vma
4741 + stub_entry->stub_sec->output_offset
4742 + stub_entry->stub_offset;
4743 branch_offset = veneer_entry_loc - veneered_insn_loc;
4744
4745 abfd = stub_entry->target_section->owner;
4746 if (!aarch64_valid_branch_p (veneer_entry_loc, veneered_insn_loc))
4747 (*_bfd_error_handler)
4748 (_("%B: error: Erratum 835769 stub out "
4749 "of range (input file too large)"), abfd);
4750
4751 target = stub_entry->target_value;
4752 branch_insn = 0x14000000;
4753 branch_offset >>= 2;
4754 branch_offset &= 0x3ffffff;
4755 branch_insn |= branch_offset;
4756 bfd_putl32 (branch_insn, &contents[target]);
4757
4758 return TRUE;
4759}
4760
4106101c
MS
4761
4762static bfd_boolean
4763_bfd_aarch64_erratum_843419_branch_to_stub (struct bfd_hash_entry *gen_entry,
4764 void *in_arg)
4765{
4766 struct elf_aarch64_stub_hash_entry *stub_entry
4767 = (struct elf_aarch64_stub_hash_entry *) gen_entry;
4768 struct erratum_835769_branch_to_stub_data *data
4769 = (struct erratum_835769_branch_to_stub_data *) in_arg;
4770 struct bfd_link_info *info;
4771 struct elf_aarch64_link_hash_table *htab;
4772 bfd_byte *contents;
4773 asection *section;
4774 bfd *abfd;
4775 bfd_vma place;
4776 uint32_t insn;
4777
4778 info = data->info;
4779 contents = data->contents;
4780 section = data->output_section;
4781
4782 htab = elf_aarch64_hash_table (info);
4783
4784 if (stub_entry->target_section != section
4785 || stub_entry->stub_type != aarch64_stub_erratum_843419_veneer)
4786 return TRUE;
4787
4788 insn = bfd_getl32 (contents + stub_entry->target_value);
4789 bfd_putl32 (insn,
4790 stub_entry->stub_sec->contents + stub_entry->stub_offset);
4791
4792 place = (section->output_section->vma + section->output_offset
4793 + stub_entry->adrp_offset);
4794 insn = bfd_getl32 (contents + stub_entry->adrp_offset);
4795
4796 if ((insn & AARCH64_ADRP_OP_MASK) != AARCH64_ADRP_OP)
4797 abort ();
4798
4799 bfd_signed_vma imm =
4800 (_bfd_aarch64_sign_extend
4801 ((bfd_vma) _bfd_aarch64_decode_adrp_imm (insn) << 12, 33)
4802 - (place & 0xfff));
4803
4804 if (htab->fix_erratum_843419_adr
4805 && (imm >= AARCH64_MIN_ADRP_IMM && imm <= AARCH64_MAX_ADRP_IMM))
4806 {
4807 insn = (_bfd_aarch64_reencode_adr_imm (AARCH64_ADR_OP, imm)
4808 | AARCH64_RT (insn));
4809 bfd_putl32 (insn, contents + stub_entry->adrp_offset);
4810 }
4811 else
4812 {
4813 bfd_vma veneered_insn_loc;
4814 bfd_vma veneer_entry_loc;
4815 bfd_signed_vma branch_offset;
4816 uint32_t branch_insn;
4817
4818 veneered_insn_loc = stub_entry->target_section->output_section->vma
4819 + stub_entry->target_section->output_offset
4820 + stub_entry->target_value;
4821 veneer_entry_loc = stub_entry->stub_sec->output_section->vma
4822 + stub_entry->stub_sec->output_offset
4823 + stub_entry->stub_offset;
4824 branch_offset = veneer_entry_loc - veneered_insn_loc;
4825
4826 abfd = stub_entry->target_section->owner;
4827 if (!aarch64_valid_branch_p (veneer_entry_loc, veneered_insn_loc))
4828 (*_bfd_error_handler)
4829 (_("%B: error: Erratum 843419 stub out "
4830 "of range (input file too large)"), abfd);
4831
4832 branch_insn = 0x14000000;
4833 branch_offset >>= 2;
4834 branch_offset &= 0x3ffffff;
4835 branch_insn |= branch_offset;
4836 bfd_putl32 (branch_insn, contents + stub_entry->target_value);
4837 }
4838 return TRUE;
4839}
4840
4841
68fcca92
JW
4842static bfd_boolean
4843elfNN_aarch64_write_section (bfd *output_bfd ATTRIBUTE_UNUSED,
4844 struct bfd_link_info *link_info,
4845 asection *sec,
4846 bfd_byte *contents)
4847
4848{
4849 struct elf_aarch64_link_hash_table *globals =
f872121a 4850 elf_aarch64_hash_table (link_info);
68fcca92
JW
4851
4852 if (globals == NULL)
4853 return FALSE;
4854
4855 /* Fix code to point to erratum 835769 stubs. */
4856 if (globals->fix_erratum_835769)
4857 {
4858 struct erratum_835769_branch_to_stub_data data;
4859
4106101c 4860 data.info = link_info;
68fcca92
JW
4861 data.output_section = sec;
4862 data.contents = contents;
4863 bfd_hash_traverse (&globals->stub_hash_table,
4864 make_branch_to_erratum_835769_stub, &data);
4865 }
4866
4106101c
MS
4867 if (globals->fix_erratum_843419)
4868 {
4869 struct erratum_835769_branch_to_stub_data data;
4870
4871 data.info = link_info;
4872 data.output_section = sec;
4873 data.contents = contents;
4874 bfd_hash_traverse (&globals->stub_hash_table,
4875 _bfd_aarch64_erratum_843419_branch_to_stub, &data);
4876 }
4877
68fcca92
JW
4878 return FALSE;
4879}
4880
a06ea964
NC
4881/* Perform a relocation as part of a final link. */
4882static bfd_reloc_status_type
cec5225b 4883elfNN_aarch64_final_link_relocate (reloc_howto_type *howto,
a06ea964
NC
4884 bfd *input_bfd,
4885 bfd *output_bfd,
4886 asection *input_section,
4887 bfd_byte *contents,
4888 Elf_Internal_Rela *rel,
4889 bfd_vma value,
4890 struct bfd_link_info *info,
4891 asection *sym_sec,
4892 struct elf_link_hash_entry *h,
4893 bfd_boolean *unresolved_reloc_p,
4894 bfd_boolean save_addend,
1419bbe5
WN
4895 bfd_vma *saved_addend,
4896 Elf_Internal_Sym *sym)
a06ea964 4897{
1419bbe5 4898 Elf_Internal_Shdr *symtab_hdr;
a06ea964 4899 unsigned int r_type = howto->type;
a6bb11b2
YZ
4900 bfd_reloc_code_real_type bfd_r_type
4901 = elfNN_aarch64_bfd_reloc_from_howto (howto);
4902 bfd_reloc_code_real_type new_bfd_r_type;
a06ea964
NC
4903 unsigned long r_symndx;
4904 bfd_byte *hit_data = contents + rel->r_offset;
b53b1bed 4905 bfd_vma place, off;
a06ea964 4906 bfd_signed_vma signed_addend;
cec5225b 4907 struct elf_aarch64_link_hash_table *globals;
a06ea964 4908 bfd_boolean weak_undef_p;
b53b1bed 4909 asection *base_got;
a06ea964 4910
cec5225b 4911 globals = elf_aarch64_hash_table (info);
a06ea964 4912
1419bbe5
WN
4913 symtab_hdr = &elf_symtab_hdr (input_bfd);
4914
a06ea964
NC
4915 BFD_ASSERT (is_aarch64_elf (input_bfd));
4916
cec5225b 4917 r_symndx = ELFNN_R_SYM (rel->r_info);
a06ea964
NC
4918
4919 /* It is possible to have linker relaxations on some TLS access
4920 models. Update our information here. */
a6bb11b2
YZ
4921 new_bfd_r_type = aarch64_tls_transition (input_bfd, info, r_type, h, r_symndx);
4922 if (new_bfd_r_type != bfd_r_type)
4923 {
4924 bfd_r_type = new_bfd_r_type;
4925 howto = elfNN_aarch64_howto_from_bfd_reloc (bfd_r_type);
4926 BFD_ASSERT (howto != NULL);
4927 r_type = howto->type;
4928 }
a06ea964
NC
4929
4930 place = input_section->output_section->vma
4931 + input_section->output_offset + rel->r_offset;
4932
4933 /* Get addend, accumulating the addend for consecutive relocs
4934 which refer to the same offset. */
4935 signed_addend = saved_addend ? *saved_addend : 0;
4936 signed_addend += rel->r_addend;
4937
4938 weak_undef_p = (h ? h->root.type == bfd_link_hash_undefweak
4939 : bfd_is_und_section (sym_sec));
a6bb11b2 4940
1419bbe5
WN
4941 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle
4942 it here if it is defined in a non-shared object. */
4943 if (h != NULL
4944 && h->type == STT_GNU_IFUNC
4945 && h->def_regular)
4946 {
4947 asection *plt;
4948 const char *name;
99ad26cb 4949 bfd_vma addend = 0;
1419bbe5
WN
4950
4951 if ((input_section->flags & SEC_ALLOC) == 0
4952 || h->plt.offset == (bfd_vma) -1)
4953 abort ();
4954
4955 /* STT_GNU_IFUNC symbol must go through PLT. */
4956 plt = globals->root.splt ? globals->root.splt : globals->root.iplt;
4957 value = (plt->output_section->vma + plt->output_offset + h->plt.offset);
4958
4959 switch (bfd_r_type)
4960 {
4961 default:
4962 if (h->root.root.string)
4963 name = h->root.root.string;
4964 else
4965 name = bfd_elf_sym_name (input_bfd, symtab_hdr, sym,
4966 NULL);
4967 (*_bfd_error_handler)
4968 (_("%B: relocation %s against STT_GNU_IFUNC "
4969 "symbol `%s' isn't handled by %s"), input_bfd,
4970 howto->name, name, __FUNCTION__);
4971 bfd_set_error (bfd_error_bad_value);
4972 return FALSE;
4973
4974 case BFD_RELOC_AARCH64_NN:
4975 if (rel->r_addend != 0)
4976 {
4977 if (h->root.root.string)
4978 name = h->root.root.string;
4979 else
4980 name = bfd_elf_sym_name (input_bfd, symtab_hdr,
4981 sym, NULL);
4982 (*_bfd_error_handler)
4983 (_("%B: relocation %s against STT_GNU_IFUNC "
4984 "symbol `%s' has non-zero addend: %d"),
4985 input_bfd, howto->name, name, rel->r_addend);
4986 bfd_set_error (bfd_error_bad_value);
4987 return FALSE;
4988 }
4989
4990 /* Generate dynamic relocation only when there is a
4991 non-GOT reference in a shared object. */
0e1862bb 4992 if (bfd_link_pic (info) && h->non_got_ref)
1419bbe5
WN
4993 {
4994 Elf_Internal_Rela outrel;
4995 asection *sreloc;
4996
4997 /* Need a dynamic relocation to get the real function
4998 address. */
4999 outrel.r_offset = _bfd_elf_section_offset (output_bfd,
5000 info,
5001 input_section,
5002 rel->r_offset);
5003 if (outrel.r_offset == (bfd_vma) -1
5004 || outrel.r_offset == (bfd_vma) -2)
5005 abort ();
5006
5007 outrel.r_offset += (input_section->output_section->vma
5008 + input_section->output_offset);
5009
5010 if (h->dynindx == -1
5011 || h->forced_local
0e1862bb 5012 || bfd_link_executable (info))
1419bbe5
WN
5013 {
5014 /* This symbol is resolved locally. */
5015 outrel.r_info = ELFNN_R_INFO (0, AARCH64_R (IRELATIVE));
5016 outrel.r_addend = (h->root.u.def.value
5017 + h->root.u.def.section->output_section->vma
5018 + h->root.u.def.section->output_offset);
5019 }
5020 else
5021 {
5022 outrel.r_info = ELFNN_R_INFO (h->dynindx, r_type);
5023 outrel.r_addend = 0;
5024 }
5025
5026 sreloc = globals->root.irelifunc;
5027 elf_append_rela (output_bfd, sreloc, &outrel);
5028
5029 /* If this reloc is against an external symbol, we
5030 do not want to fiddle with the addend. Otherwise,
5031 we need to include the symbol value so that it
5032 becomes an addend for the dynamic reloc. For an
5033 internal symbol, we have updated addend. */
5034 return bfd_reloc_ok;
5035 }
5036 /* FALLTHROUGH */
1419bbe5 5037 case BFD_RELOC_AARCH64_CALL26:
ce336788 5038 case BFD_RELOC_AARCH64_JUMP26:
1419bbe5
WN
5039 value = _bfd_aarch64_elf_resolve_relocation (bfd_r_type, place, value,
5040 signed_addend,
5041 weak_undef_p);
5042 return _bfd_aarch64_elf_put_addend (input_bfd, hit_data, bfd_r_type,
5043 howto, value);
1419bbe5
WN
5044 case BFD_RELOC_AARCH64_ADR_GOT_PAGE:
5045 case BFD_RELOC_AARCH64_GOT_LD_PREL19:
7018c030 5046 case BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14:
ce336788 5047 case BFD_RELOC_AARCH64_LD32_GOT_LO12_NC:
99ad26cb 5048 case BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15:
dc8008f5 5049 case BFD_RELOC_AARCH64_MOVW_GOTOFF_G0_NC:
74a1bfe1 5050 case BFD_RELOC_AARCH64_MOVW_GOTOFF_G1:
a2e1db00 5051 case BFD_RELOC_AARCH64_LD64_GOTOFF_LO15:
ce336788 5052 case BFD_RELOC_AARCH64_LD64_GOT_LO12_NC:
1419bbe5
WN
5053 base_got = globals->root.sgot;
5054 off = h->got.offset;
5055
5056 if (base_got == NULL)
5057 abort ();
5058
5059 if (off == (bfd_vma) -1)
5060 {
5061 bfd_vma plt_index;
5062
5063 /* We can't use h->got.offset here to save state, or
5064 even just remember the offset, as finish_dynamic_symbol
5065 would use that as offset into .got. */
5066
5067 if (globals->root.splt != NULL)
5068 {
b1ee0cc4
WN
5069 plt_index = ((h->plt.offset - globals->plt_header_size) /
5070 globals->plt_entry_size);
1419bbe5
WN
5071 off = (plt_index + 3) * GOT_ENTRY_SIZE;
5072 base_got = globals->root.sgotplt;
5073 }
5074 else
5075 {
5076 plt_index = h->plt.offset / globals->plt_entry_size;
5077 off = plt_index * GOT_ENTRY_SIZE;
5078 base_got = globals->root.igotplt;
5079 }
5080
5081 if (h->dynindx == -1
5082 || h->forced_local
5083 || info->symbolic)
5084 {
5085 /* This references the local definition. We must
5086 initialize this entry in the global offset table.
5087 Since the offset must always be a multiple of 8,
5088 we use the least significant bit to record
5089 whether we have initialized it already.
5090
5091 When doing a dynamic link, we create a .rela.got
5092 relocation entry to initialize the value. This
5093 is done in the finish_dynamic_symbol routine. */
5094 if ((off & 1) != 0)
5095 off &= ~1;
5096 else
5097 {
5098 bfd_put_NN (output_bfd, value,
5099 base_got->contents + off);
5100 /* Note that this is harmless as -1 | 1 still is -1. */
5101 h->got.offset |= 1;
5102 }
5103 }
5104 value = (base_got->output_section->vma
5105 + base_got->output_offset + off);
5106 }
5107 else
5108 value = aarch64_calculate_got_entry_vma (h, globals, info,
5109 value, output_bfd,
5110 unresolved_reloc_p);
a0becb89
RL
5111
5112 switch (bfd_r_type)
5113 {
5114 case BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14:
5115 case BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15:
5116 addend = (globals->root.sgot->output_section->vma
5117 + globals->root.sgot->output_offset);
5118 break;
dc8008f5 5119 case BFD_RELOC_AARCH64_MOVW_GOTOFF_G0_NC:
74a1bfe1 5120 case BFD_RELOC_AARCH64_MOVW_GOTOFF_G1:
a2e1db00
RL
5121 case BFD_RELOC_AARCH64_LD64_GOTOFF_LO15:
5122 value = (value - globals->root.sgot->output_section->vma
5123 - globals->root.sgot->output_offset);
a0becb89
RL
5124 default:
5125 break;
5126 }
5127
1419bbe5 5128 value = _bfd_aarch64_elf_resolve_relocation (bfd_r_type, place, value,
99ad26cb 5129 addend, weak_undef_p);
1419bbe5 5130 return _bfd_aarch64_elf_put_addend (input_bfd, hit_data, bfd_r_type, howto, value);
1419bbe5 5131 case BFD_RELOC_AARCH64_ADD_LO12:
ce336788 5132 case BFD_RELOC_AARCH64_ADR_HI21_PCREL:
1419bbe5
WN
5133 break;
5134 }
5135 }
5136
a6bb11b2 5137 switch (bfd_r_type)
a06ea964 5138 {
a6bb11b2
YZ
5139 case BFD_RELOC_AARCH64_NONE:
5140 case BFD_RELOC_AARCH64_TLSDESC_CALL:
a06ea964
NC
5141 *unresolved_reloc_p = FALSE;
5142 return bfd_reloc_ok;
5143
a6bb11b2 5144 case BFD_RELOC_AARCH64_NN:
a06ea964
NC
5145
5146 /* When generating a shared object or relocatable executable, these
5147 relocations are copied into the output file to be resolved at
5148 run time. */
0e1862bb
L
5149 if (((bfd_link_pic (info) == TRUE)
5150 || globals->root.is_relocatable_executable)
a06ea964
NC
5151 && (input_section->flags & SEC_ALLOC)
5152 && (h == NULL
5153 || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
5154 || h->root.type != bfd_link_hash_undefweak))
5155 {
5156 Elf_Internal_Rela outrel;
5157 bfd_byte *loc;
5158 bfd_boolean skip, relocate;
5159 asection *sreloc;
5160
5161 *unresolved_reloc_p = FALSE;
5162
a06ea964
NC
5163 skip = FALSE;
5164 relocate = FALSE;
5165
5166 outrel.r_addend = signed_addend;
5167 outrel.r_offset =
5168 _bfd_elf_section_offset (output_bfd, info, input_section,
5169 rel->r_offset);
5170 if (outrel.r_offset == (bfd_vma) - 1)
5171 skip = TRUE;
5172 else if (outrel.r_offset == (bfd_vma) - 2)
5173 {
5174 skip = TRUE;
5175 relocate = TRUE;
5176 }
5177
5178 outrel.r_offset += (input_section->output_section->vma
5179 + input_section->output_offset);
5180
5181 if (skip)
5182 memset (&outrel, 0, sizeof outrel);
5183 else if (h != NULL
5184 && h->dynindx != -1
0e1862bb
L
5185 && (!bfd_link_pic (info)
5186 || !SYMBOLIC_BIND (info, h)
5187 || !h->def_regular))
cec5225b 5188 outrel.r_info = ELFNN_R_INFO (h->dynindx, r_type);
a06ea964
NC
5189 else
5190 {
5191 int symbol;
5192
5193 /* On SVR4-ish systems, the dynamic loader cannot
5194 relocate the text and data segments independently,
5195 so the symbol does not matter. */
5196 symbol = 0;
a6bb11b2 5197 outrel.r_info = ELFNN_R_INFO (symbol, AARCH64_R (RELATIVE));
a06ea964
NC
5198 outrel.r_addend += value;
5199 }
5200
1419bbe5
WN
5201 sreloc = elf_section_data (input_section)->sreloc;
5202 if (sreloc == NULL || sreloc->contents == NULL)
5203 return bfd_reloc_notsupported;
5204
5205 loc = sreloc->contents + sreloc->reloc_count++ * RELOC_SIZE (globals);
cec5225b 5206 bfd_elfNN_swap_reloca_out (output_bfd, &outrel, loc);
a06ea964 5207
1419bbe5 5208 if (sreloc->reloc_count * RELOC_SIZE (globals) > sreloc->size)
a06ea964
NC
5209 {
5210 /* Sanity to check that we have previously allocated
5211 sufficient space in the relocation section for the
5212 number of relocations we actually want to emit. */
5213 abort ();
5214 }
5215
5216 /* If this reloc is against an external symbol, we do not want to
5217 fiddle with the addend. Otherwise, we need to include the symbol
5218 value so that it becomes an addend for the dynamic reloc. */
5219 if (!relocate)
5220 return bfd_reloc_ok;
5221
5222 return _bfd_final_link_relocate (howto, input_bfd, input_section,
5223 contents, rel->r_offset, value,
5224 signed_addend);
5225 }
5226 else
5227 value += signed_addend;
5228 break;
5229
a6bb11b2 5230 case BFD_RELOC_AARCH64_CALL26:
ce336788 5231 case BFD_RELOC_AARCH64_JUMP26:
a06ea964
NC
5232 {
5233 asection *splt = globals->root.splt;
5234 bfd_boolean via_plt_p =
5235 splt != NULL && h != NULL && h->plt.offset != (bfd_vma) - 1;
5236
5237 /* A call to an undefined weak symbol is converted to a jump to
5238 the next instruction unless a PLT entry will be created.
5239 The jump to the next instruction is optimized as a NOP.
5240 Do the same for local undefined symbols. */
5241 if (weak_undef_p && ! via_plt_p)
5242 {
5243 bfd_putl32 (INSN_NOP, hit_data);
5244 return bfd_reloc_ok;
5245 }
5246
5247 /* If the call goes through a PLT entry, make sure to
5248 check distance to the right destination address. */
5249 if (via_plt_p)
07f9ddfe
JW
5250 value = (splt->output_section->vma
5251 + splt->output_offset + h->plt.offset);
5252
5253 /* Check if a stub has to be inserted because the destination
5254 is too far away. */
5255 struct elf_aarch64_stub_hash_entry *stub_entry = NULL;
5256 if (! aarch64_valid_branch_p (value, place))
5257 /* The target is out of reach, so redirect the branch to
5258 the local stub for this function. */
5259 stub_entry = elfNN_aarch64_get_stub_entry (input_section, sym_sec, h,
5260 rel, globals);
5261 if (stub_entry != NULL)
5262 value = (stub_entry->stub_offset
5263 + stub_entry->stub_sec->output_offset
5264 + stub_entry->stub_sec->output_section->vma);
a06ea964 5265 }
caed7120
YZ
5266 value = _bfd_aarch64_elf_resolve_relocation (bfd_r_type, place, value,
5267 signed_addend, weak_undef_p);
07f9ddfe 5268 *unresolved_reloc_p = FALSE;
a06ea964
NC
5269 break;
5270
dcbd20eb
JW
5271 case BFD_RELOC_AARCH64_16_PCREL:
5272 case BFD_RELOC_AARCH64_32_PCREL:
5273 case BFD_RELOC_AARCH64_64_PCREL:
ce336788
JW
5274 case BFD_RELOC_AARCH64_ADR_HI21_NC_PCREL:
5275 case BFD_RELOC_AARCH64_ADR_HI21_PCREL:
5276 case BFD_RELOC_AARCH64_ADR_LO21_PCREL:
5277 case BFD_RELOC_AARCH64_LD_LO19_PCREL:
0e1862bb 5278 if (bfd_link_pic (info)
dcbd20eb
JW
5279 && (input_section->flags & SEC_ALLOC) != 0
5280 && (input_section->flags & SEC_READONLY) != 0
5281 && h != NULL
5282 && !h->def_regular)
5283 {
5284 int howto_index = bfd_r_type - BFD_RELOC_AARCH64_RELOC_START;
5285
5286 (*_bfd_error_handler)
5287 (_("%B: relocation %s against external symbol `%s' can not be used"
5288 " when making a shared object; recompile with -fPIC"),
5289 input_bfd, elfNN_aarch64_howto_table[howto_index].name,
5290 h->root.root.string);
5291 bfd_set_error (bfd_error_bad_value);
5292 return FALSE;
5293 }
5294
a6bb11b2
YZ
5295 case BFD_RELOC_AARCH64_16:
5296#if ARCH_SIZE == 64
5297 case BFD_RELOC_AARCH64_32:
5298#endif
5299 case BFD_RELOC_AARCH64_ADD_LO12:
a6bb11b2 5300 case BFD_RELOC_AARCH64_BRANCH19:
ce336788 5301 case BFD_RELOC_AARCH64_LDST128_LO12:
a6bb11b2
YZ
5302 case BFD_RELOC_AARCH64_LDST16_LO12:
5303 case BFD_RELOC_AARCH64_LDST32_LO12:
5304 case BFD_RELOC_AARCH64_LDST64_LO12:
ce336788 5305 case BFD_RELOC_AARCH64_LDST8_LO12:
a6bb11b2
YZ
5306 case BFD_RELOC_AARCH64_MOVW_G0:
5307 case BFD_RELOC_AARCH64_MOVW_G0_NC:
ce336788 5308 case BFD_RELOC_AARCH64_MOVW_G0_S:
a6bb11b2
YZ
5309 case BFD_RELOC_AARCH64_MOVW_G1:
5310 case BFD_RELOC_AARCH64_MOVW_G1_NC:
ce336788 5311 case BFD_RELOC_AARCH64_MOVW_G1_S:
a6bb11b2
YZ
5312 case BFD_RELOC_AARCH64_MOVW_G2:
5313 case BFD_RELOC_AARCH64_MOVW_G2_NC:
ce336788 5314 case BFD_RELOC_AARCH64_MOVW_G2_S:
a6bb11b2 5315 case BFD_RELOC_AARCH64_MOVW_G3:
a6bb11b2 5316 case BFD_RELOC_AARCH64_TSTBR14:
caed7120
YZ
5317 value = _bfd_aarch64_elf_resolve_relocation (bfd_r_type, place, value,
5318 signed_addend, weak_undef_p);
a06ea964
NC
5319 break;
5320
a6bb11b2
YZ
5321 case BFD_RELOC_AARCH64_ADR_GOT_PAGE:
5322 case BFD_RELOC_AARCH64_GOT_LD_PREL19:
7018c030 5323 case BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14:
ce336788 5324 case BFD_RELOC_AARCH64_LD32_GOT_LO12_NC:
99ad26cb 5325 case BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15:
ce336788 5326 case BFD_RELOC_AARCH64_LD64_GOT_LO12_NC:
a06ea964
NC
5327 if (globals->root.sgot == NULL)
5328 BFD_ASSERT (h != NULL);
5329
5330 if (h != NULL)
5331 {
99ad26cb 5332 bfd_vma addend = 0;
a06ea964
NC
5333 value = aarch64_calculate_got_entry_vma (h, globals, info, value,
5334 output_bfd,
5335 unresolved_reloc_p);
7018c030
JW
5336 if (bfd_r_type == BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15
5337 || bfd_r_type == BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14)
99ad26cb
JW
5338 addend = (globals->root.sgot->output_section->vma
5339 + globals->root.sgot->output_offset);
caed7120 5340 value = _bfd_aarch64_elf_resolve_relocation (bfd_r_type, place, value,
99ad26cb 5341 addend, weak_undef_p);
a06ea964 5342 }
b53b1bed
JW
5343 else
5344 {
99ad26cb 5345 bfd_vma addend = 0;
b53b1bed
JW
5346 struct elf_aarch64_local_symbol *locals
5347 = elf_aarch64_locals (input_bfd);
5348
5349 if (locals == NULL)
5350 {
5351 int howto_index = bfd_r_type - BFD_RELOC_AARCH64_RELOC_START;
5352 (*_bfd_error_handler)
5353 (_("%B: Local symbol descriptor table be NULL when applying "
5354 "relocation %s against local symbol"),
5355 input_bfd, elfNN_aarch64_howto_table[howto_index].name);
5356 abort ();
5357 }
5358
5359 off = symbol_got_offset (input_bfd, h, r_symndx);
5360 base_got = globals->root.sgot;
5361 bfd_vma got_entry_addr = (base_got->output_section->vma
5362 + base_got->output_offset + off);
5363
5364 if (!symbol_got_offset_mark_p (input_bfd, h, r_symndx))
5365 {
5366 bfd_put_64 (output_bfd, value, base_got->contents + off);
5367
0e1862bb 5368 if (bfd_link_pic (info))
b53b1bed
JW
5369 {
5370 asection *s;
5371 Elf_Internal_Rela outrel;
5372
5373 /* For local symbol, we have done absolute relocation in static
5374 linking stageh. While for share library, we need to update
5375 the content of GOT entry according to the share objects
5376 loading base address. So we need to generate a
5377 R_AARCH64_RELATIVE reloc for dynamic linker. */
5378 s = globals->root.srelgot;
5379 if (s == NULL)
5380 abort ();
5381
5382 outrel.r_offset = got_entry_addr;
5383 outrel.r_info = ELFNN_R_INFO (0, AARCH64_R (RELATIVE));
5384 outrel.r_addend = value;
5385 elf_append_rela (output_bfd, s, &outrel);
5386 }
5387
5388 symbol_got_offset_mark (input_bfd, h, r_symndx);
5389 }
5390
5391 /* Update the relocation value to GOT entry addr as we have transformed
5392 the direct data access into indirect data access through GOT. */
5393 value = got_entry_addr;
99ad26cb 5394
7018c030
JW
5395 if (bfd_r_type == BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15
5396 || bfd_r_type == BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14)
99ad26cb
JW
5397 addend = base_got->output_section->vma + base_got->output_offset;
5398
5399 value = _bfd_aarch64_elf_resolve_relocation (bfd_r_type, place, value,
5400 addend, weak_undef_p);
b53b1bed
JW
5401 }
5402
a06ea964
NC
5403 break;
5404
a2e1db00 5405 case BFD_RELOC_AARCH64_LD64_GOTOFF_LO15:
dc8008f5 5406 case BFD_RELOC_AARCH64_MOVW_GOTOFF_G0_NC:
74a1bfe1 5407 case BFD_RELOC_AARCH64_MOVW_GOTOFF_G1:
a2e1db00
RL
5408 if (h != NULL)
5409 value = aarch64_calculate_got_entry_vma (h, globals, info, value,
5410 output_bfd,
5411 unresolved_reloc_p);
5412 else
5413 {
5414 struct elf_aarch64_local_symbol *locals
5415 = elf_aarch64_locals (input_bfd);
5416
5417 if (locals == NULL)
5418 {
5419 int howto_index = bfd_r_type - BFD_RELOC_AARCH64_RELOC_START;
5420 (*_bfd_error_handler)
5421 (_("%B: Local symbol descriptor table be NULL when applying "
5422 "relocation %s against local symbol"),
5423 input_bfd, elfNN_aarch64_howto_table[howto_index].name);
5424 abort ();
5425 }
5426
5427 off = symbol_got_offset (input_bfd, h, r_symndx);
5428 base_got = globals->root.sgot;
5429 if (base_got == NULL)
5430 abort ();
5431
5432 bfd_vma got_entry_addr = (base_got->output_section->vma
5433 + base_got->output_offset + off);
5434
5435 if (!symbol_got_offset_mark_p (input_bfd, h, r_symndx))
5436 {
5437 bfd_put_64 (output_bfd, value, base_got->contents + off);
5438
5439 if (bfd_link_pic (info))
5440 {
5441 asection *s;
5442 Elf_Internal_Rela outrel;
5443
5444 /* For local symbol, we have done absolute relocation in static
5445 linking stage. While for share library, we need to update
5446 the content of GOT entry according to the share objects
5447 loading base address. So we need to generate a
5448 R_AARCH64_RELATIVE reloc for dynamic linker. */
5449 s = globals->root.srelgot;
5450 if (s == NULL)
5451 abort ();
5452
5453 outrel.r_offset = got_entry_addr;
5454 outrel.r_info = ELFNN_R_INFO (0, AARCH64_R (RELATIVE));
5455 outrel.r_addend = value;
5456 elf_append_rela (output_bfd, s, &outrel);
5457 }
5458
5459 symbol_got_offset_mark (input_bfd, h, r_symndx);
5460 }
5461 }
5462
5463 /* Update the relocation value to GOT entry addr as we have transformed
5464 the direct data access into indirect data access through GOT. */
5465 value = symbol_got_offset (input_bfd, h, r_symndx);
5466 value = _bfd_aarch64_elf_resolve_relocation (bfd_r_type, place, value,
5467 0, weak_undef_p);
5468 *unresolved_reloc_p = FALSE;
5469 break;
5470
ce336788 5471 case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC:
a6bb11b2 5472 case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21:
3c12b054 5473 case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21:
a6bb11b2 5474 case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21:
a6bb11b2 5475 case BFD_RELOC_AARCH64_TLSIE_LD32_GOTTPREL_LO12_NC:
ce336788 5476 case BFD_RELOC_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC:
043bf05a 5477 case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19:
73f925cc 5478 case BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC:
f69e4920 5479 case BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21:
77a69ff8 5480 case BFD_RELOC_AARCH64_TLSLD_ADR_PREL21:
a06ea964
NC
5481 if (globals->root.sgot == NULL)
5482 return bfd_reloc_notsupported;
5483
5484 value = (symbol_got_offset (input_bfd, h, r_symndx)
5485 + globals->root.sgot->output_section->vma
f44a1f8e 5486 + globals->root.sgot->output_offset);
a06ea964 5487
caed7120
YZ
5488 value = _bfd_aarch64_elf_resolve_relocation (bfd_r_type, place, value,
5489 0, weak_undef_p);
a06ea964
NC
5490 *unresolved_reloc_p = FALSE;
5491 break;
5492
7ba7cfe4 5493 case BFD_RELOC_AARCH64_TLSGD_MOVW_G0_NC:
94facae3 5494 case BFD_RELOC_AARCH64_TLSGD_MOVW_G1:
3b957e5b
RL
5495 case BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G0_NC:
5496 case BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G1:
94facae3
RL
5497 if (globals->root.sgot == NULL)
5498 return bfd_reloc_notsupported;
5499
5500 value = symbol_got_offset (input_bfd, h, r_symndx);
5501 value = _bfd_aarch64_elf_resolve_relocation (bfd_r_type, place, value,
5502 0, weak_undef_p);
5503 *unresolved_reloc_p = FALSE;
5504 break;
5505
6ffe9a1b 5506 case BFD_RELOC_AARCH64_TLSLD_ADD_DTPREL_HI12:
40fbed84 5507 case BFD_RELOC_AARCH64_TLSLD_ADD_DTPREL_LO12:
753999c1 5508 case BFD_RELOC_AARCH64_TLSLD_ADD_DTPREL_LO12_NC:
07c9aa07
JW
5509 case BFD_RELOC_AARCH64_TLSLD_LDST16_DTPREL_LO12:
5510 case BFD_RELOC_AARCH64_TLSLD_LDST16_DTPREL_LO12_NC:
5511 case BFD_RELOC_AARCH64_TLSLD_LDST32_DTPREL_LO12:
5512 case BFD_RELOC_AARCH64_TLSLD_LDST32_DTPREL_LO12_NC:
5513 case BFD_RELOC_AARCH64_TLSLD_LDST64_DTPREL_LO12:
5514 case BFD_RELOC_AARCH64_TLSLD_LDST64_DTPREL_LO12_NC:
5515 case BFD_RELOC_AARCH64_TLSLD_LDST8_DTPREL_LO12:
5516 case BFD_RELOC_AARCH64_TLSLD_LDST8_DTPREL_LO12_NC:
6ffe9a1b
JW
5517 case BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G0:
5518 case BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G0_NC:
5519 case BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G1:
5520 case BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G1_NC:
5521 case BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G2:
40fbed84
JW
5522 value = _bfd_aarch64_elf_resolve_relocation (bfd_r_type, place, value,
5523 signed_addend - dtpoff_base (info),
5524 weak_undef_p);
5525 break;
5526
a6bb11b2
YZ
5527 case BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_HI12:
5528 case BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_LO12:
5529 case BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_LO12_NC:
5530 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0:
5531 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC:
5532 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1:
5533 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1_NC:
5534 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G2:
caed7120
YZ
5535 value = _bfd_aarch64_elf_resolve_relocation (bfd_r_type, place, value,
5536 signed_addend - tpoff_base (info),
5537 weak_undef_p);
a06ea964
NC
5538 *unresolved_reloc_p = FALSE;
5539 break;
5540
7bcccb57
MS
5541 case BFD_RELOC_AARCH64_TLSDESC_ADD:
5542 case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12_NC:
a6bb11b2 5543 case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21:
389b8029 5544 case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21:
a6bb11b2 5545 case BFD_RELOC_AARCH64_TLSDESC_LD32_LO12_NC:
7bcccb57 5546 case BFD_RELOC_AARCH64_TLSDESC_LD64_LO12_NC:
a6bb11b2 5547 case BFD_RELOC_AARCH64_TLSDESC_LDR:
1ada945d 5548 case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19:
a06ea964
NC
5549 if (globals->root.sgot == NULL)
5550 return bfd_reloc_notsupported;
a06ea964
NC
5551 value = (symbol_tlsdesc_got_offset (input_bfd, h, r_symndx)
5552 + globals->root.sgotplt->output_section->vma
f44a1f8e 5553 + globals->root.sgotplt->output_offset
a06ea964
NC
5554 + globals->sgotplt_jump_table_size);
5555
caed7120
YZ
5556 value = _bfd_aarch64_elf_resolve_relocation (bfd_r_type, place, value,
5557 0, weak_undef_p);
a06ea964
NC
5558 *unresolved_reloc_p = FALSE;
5559 break;
5560
5561 default:
5562 return bfd_reloc_notsupported;
5563 }
5564
5565 if (saved_addend)
5566 *saved_addend = value;
5567
5568 /* Only apply the final relocation in a sequence. */
5569 if (save_addend)
5570 return bfd_reloc_continue;
5571
caed7120
YZ
5572 return _bfd_aarch64_elf_put_addend (input_bfd, hit_data, bfd_r_type,
5573 howto, value);
a06ea964
NC
5574}
5575
5576/* Handle TLS relaxations. Relaxing is possible for symbols that use
5577 R_AARCH64_TLSDESC_ADR_{PAGE, LD64_LO12_NC, ADD_LO12_NC} during a static
5578 link.
5579
5580 Return bfd_reloc_ok if we're done, bfd_reloc_continue if the caller
5581 is to then call final_link_relocate. Return other values in the
5582 case of error. */
5583
5584static bfd_reloc_status_type
cec5225b 5585elfNN_aarch64_tls_relax (struct elf_aarch64_link_hash_table *globals,
a06ea964
NC
5586 bfd *input_bfd, bfd_byte *contents,
5587 Elf_Internal_Rela *rel, struct elf_link_hash_entry *h)
5588{
5589 bfd_boolean is_local = h == NULL;
cec5225b 5590 unsigned int r_type = ELFNN_R_TYPE (rel->r_info);
a06ea964
NC
5591 unsigned long insn;
5592
5593 BFD_ASSERT (globals && input_bfd && contents && rel);
5594
a6bb11b2 5595 switch (elfNN_aarch64_bfd_reloc_from_type (r_type))
a06ea964 5596 {
a6bb11b2 5597 case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21:
ce336788 5598 case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21:
a06ea964
NC
5599 if (is_local)
5600 {
5601 /* GD->LE relaxation:
5602 adrp x0, :tlsgd:var => movz x0, :tprel_g1:var
5603 or
5604 adrp x0, :tlsdesc:var => movz x0, :tprel_g1:var
5605 */
5606 bfd_putl32 (0xd2a00000, contents + rel->r_offset);
5607 return bfd_reloc_continue;
5608 }
5609 else
5610 {
5611 /* GD->IE relaxation:
5612 adrp x0, :tlsgd:var => adrp x0, :gottprel:var
5613 or
5614 adrp x0, :tlsdesc:var => adrp x0, :gottprel:var
5615 */
a06ea964
NC
5616 return bfd_reloc_continue;
5617 }
5618
389b8029
MS
5619 case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21:
5620 BFD_ASSERT (0);
5621 break;
5622
1ada945d
MS
5623 case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19:
5624 if (is_local)
5625 {
5626 /* Tiny TLSDESC->LE relaxation:
5627 ldr x1, :tlsdesc:var => movz x0, #:tprel_g1:var
5628 adr x0, :tlsdesc:var => movk x0, #:tprel_g0_nc:var
5629 .tlsdesccall var
5630 blr x1 => nop
5631 */
5632 BFD_ASSERT (ELFNN_R_TYPE (rel[1].r_info) == AARCH64_R (TLSDESC_ADR_PREL21));
5633 BFD_ASSERT (ELFNN_R_TYPE (rel[2].r_info) == AARCH64_R (TLSDESC_CALL));
5634
5635 rel[1].r_info = ELFNN_R_INFO (ELFNN_R_SYM (rel->r_info),
5636 AARCH64_R (TLSLE_MOVW_TPREL_G0_NC));
5637 rel[2].r_info = ELFNN_R_INFO (STN_UNDEF, R_AARCH64_NONE);
5638
5639 bfd_putl32 (0xd2a00000, contents + rel->r_offset);
5640 bfd_putl32 (0xf2800000, contents + rel->r_offset + 4);
5641 bfd_putl32 (INSN_NOP, contents + rel->r_offset + 8);
5642 return bfd_reloc_continue;
5643 }
5644 else
5645 {
5646 /* Tiny TLSDESC->IE relaxation:
5647 ldr x1, :tlsdesc:var => ldr x0, :gottprel:var
5648 adr x0, :tlsdesc:var => nop
5649 .tlsdesccall var
5650 blr x1 => nop
5651 */
5652 BFD_ASSERT (ELFNN_R_TYPE (rel[1].r_info) == AARCH64_R (TLSDESC_ADR_PREL21));
5653 BFD_ASSERT (ELFNN_R_TYPE (rel[2].r_info) == AARCH64_R (TLSDESC_CALL));
5654
5655 rel[1].r_info = ELFNN_R_INFO (STN_UNDEF, R_AARCH64_NONE);
5656 rel[2].r_info = ELFNN_R_INFO (STN_UNDEF, R_AARCH64_NONE);
5657
5658 bfd_putl32 (0x58000000, contents + rel->r_offset);
5659 bfd_putl32 (INSN_NOP, contents + rel->r_offset + 4);
5660 bfd_putl32 (INSN_NOP, contents + rel->r_offset + 8);
5661 return bfd_reloc_continue;
5662 }
5663
3c12b054
MS
5664 case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21:
5665 if (is_local)
5666 {
5667 /* Tiny GD->LE relaxation:
5668 adr x0, :tlsgd:var => mrs x1, tpidr_el0
5669 bl __tls_get_addr => add x0, x1, #:tprel_hi12:x, lsl #12
5670 nop => add x0, x0, #:tprel_lo12_nc:x
5671 */
5672
5673 /* First kill the tls_get_addr reloc on the bl instruction. */
5674 BFD_ASSERT (rel->r_offset + 4 == rel[1].r_offset);
5675
5676 bfd_putl32 (0xd53bd041, contents + rel->r_offset + 0);
5677 bfd_putl32 (0x91400020, contents + rel->r_offset + 4);
5678 bfd_putl32 (0x91000000, contents + rel->r_offset + 8);
5679
5680 rel[1].r_info = ELFNN_R_INFO (ELFNN_R_SYM (rel->r_info),
5681 AARCH64_R (TLSLE_ADD_TPREL_LO12_NC));
5682 rel[1].r_offset = rel->r_offset + 8;
5683
5684 /* Move the current relocation to the second instruction in
5685 the sequence. */
5686 rel->r_offset += 4;
5687 rel->r_info = ELFNN_R_INFO (ELFNN_R_SYM (rel->r_info),
5688 AARCH64_R (TLSLE_ADD_TPREL_HI12));
5689 return bfd_reloc_continue;
5690 }
5691 else
5692 {
5693 /* Tiny GD->IE relaxation:
5694 adr x0, :tlsgd:var => ldr x0, :gottprel:var
5695 bl __tls_get_addr => mrs x1, tpidr_el0
5696 nop => add x0, x0, x1
5697 */
5698
5699 /* First kill the tls_get_addr reloc on the bl instruction. */
5700 BFD_ASSERT (rel->r_offset + 4 == rel[1].r_offset);
5701 rel[1].r_info = ELFNN_R_INFO (STN_UNDEF, R_AARCH64_NONE);
5702
5703 bfd_putl32 (0x58000000, contents + rel->r_offset);
5704 bfd_putl32 (0xd53bd041, contents + rel->r_offset + 4);
5705 bfd_putl32 (0x8b000020, contents + rel->r_offset + 8);
5706 return bfd_reloc_continue;
5707 }
5708
ac734732
RL
5709#if ARCH_SIZE == 64
5710 case BFD_RELOC_AARCH64_TLSGD_MOVW_G1:
5711 BFD_ASSERT (ELFNN_R_TYPE (rel[1].r_info) == AARCH64_R (TLSGD_MOVW_G0_NC));
5712 BFD_ASSERT (rel->r_offset + 12 == rel[2].r_offset);
5713 BFD_ASSERT (ELFNN_R_TYPE (rel[2].r_info) == AARCH64_R (CALL26));
5714
5715 if (is_local)
5716 {
5717 /* Large GD->LE relaxation:
5718 movz x0, #:tlsgd_g1:var => movz x0, #:tprel_g2:var, lsl #32
5719 movk x0, #:tlsgd_g0_nc:var => movk x0, #:tprel_g1_nc:var, lsl #16
5720 add x0, gp, x0 => movk x0, #:tprel_g0_nc:var
5721 bl __tls_get_addr => mrs x1, tpidr_el0
5722 nop => add x0, x0, x1
5723 */
5724 rel[2].r_info = ELFNN_R_INFO (ELFNN_R_SYM (rel->r_info),
5725 AARCH64_R (TLSLE_MOVW_TPREL_G0_NC));
5726 rel[2].r_offset = rel->r_offset + 8;
5727
5728 bfd_putl32 (0xd2c00000, contents + rel->r_offset + 0);
5729 bfd_putl32 (0xf2a00000, contents + rel->r_offset + 4);
5730 bfd_putl32 (0xf2800000, contents + rel->r_offset + 8);
5731 bfd_putl32 (0xd53bd041, contents + rel->r_offset + 12);
5732 bfd_putl32 (0x8b000020, contents + rel->r_offset + 16);
5733 }
5734 else
5735 {
5736 /* Large GD->IE relaxation:
5737 movz x0, #:tlsgd_g1:var => movz x0, #:gottprel_g1:var, lsl #16
5738 movk x0, #:tlsgd_g0_nc:var => movk x0, #:gottprel_g0_nc:var
5739 add x0, gp, x0 => ldr x0, [gp, x0]
5740 bl __tls_get_addr => mrs x1, tpidr_el0
5741 nop => add x0, x0, x1
5742 */
5743 rel[2].r_info = ELFNN_R_INFO (STN_UNDEF, R_AARCH64_NONE);
5744 bfd_putl32 (0xd2a80000, contents + rel->r_offset + 0);
5745 bfd_putl32 (0x58000000, contents + rel->r_offset + 8);
5746 bfd_putl32 (0xd53bd041, contents + rel->r_offset + 12);
5747 bfd_putl32 (0x8b000020, contents + rel->r_offset + 16);
5748 }
5749 return bfd_reloc_continue;
5750
5751 case BFD_RELOC_AARCH64_TLSGD_MOVW_G0_NC:
5752 return bfd_reloc_continue;
5753#endif
5754
043bf05a
MS
5755 case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19:
5756 return bfd_reloc_continue;
5757
a6bb11b2 5758 case BFD_RELOC_AARCH64_TLSDESC_LDNN_LO12_NC:
a06ea964
NC
5759 if (is_local)
5760 {
5761 /* GD->LE relaxation:
5762 ldr xd, [x0, #:tlsdesc_lo12:var] => movk x0, :tprel_g0_nc:var
5763 */
5764 bfd_putl32 (0xf2800000, contents + rel->r_offset);
5765 return bfd_reloc_continue;
5766 }
5767 else
5768 {
5769 /* GD->IE relaxation:
5770 ldr xd, [x0, #:tlsdesc_lo12:var] => ldr x0, [x0, #:gottprel_lo12:var]
5771 */
5772 insn = bfd_getl32 (contents + rel->r_offset);
fa85fb9a 5773 insn &= 0xffffffe0;
a06ea964
NC
5774 bfd_putl32 (insn, contents + rel->r_offset);
5775 return bfd_reloc_continue;
5776 }
5777
a6bb11b2 5778 case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC:
a06ea964
NC
5779 if (is_local)
5780 {
5781 /* GD->LE relaxation
5782 add x0, #:tlsgd_lo12:var => movk x0, :tprel_g0_nc:var
5783 bl __tls_get_addr => mrs x1, tpidr_el0
5784 nop => add x0, x1, x0
5785 */
5786
5787 /* First kill the tls_get_addr reloc on the bl instruction. */
5788 BFD_ASSERT (rel->r_offset + 4 == rel[1].r_offset);
cec5225b 5789 rel[1].r_info = ELFNN_R_INFO (STN_UNDEF, R_AARCH64_NONE);
a06ea964
NC
5790
5791 bfd_putl32 (0xf2800000, contents + rel->r_offset);
5792 bfd_putl32 (0xd53bd041, contents + rel->r_offset + 4);
5793 bfd_putl32 (0x8b000020, contents + rel->r_offset + 8);
5794 return bfd_reloc_continue;
5795 }
5796 else
5797 {
5798 /* GD->IE relaxation
5799 ADD x0, #:tlsgd_lo12:var => ldr x0, [x0, #:gottprel_lo12:var]
5800 BL __tls_get_addr => mrs x1, tpidr_el0
5801 R_AARCH64_CALL26
5802 NOP => add x0, x1, x0
5803 */
5804
a6bb11b2 5805 BFD_ASSERT (ELFNN_R_TYPE (rel[1].r_info) == AARCH64_R (CALL26));
a06ea964
NC
5806
5807 /* Remove the relocation on the BL instruction. */
cec5225b 5808 rel[1].r_info = ELFNN_R_INFO (STN_UNDEF, R_AARCH64_NONE);
a06ea964
NC
5809
5810 bfd_putl32 (0xf9400000, contents + rel->r_offset);
5811
5812 /* We choose to fixup the BL and NOP instructions using the
5813 offset from the second relocation to allow flexibility in
5814 scheduling instructions between the ADD and BL. */
5815 bfd_putl32 (0xd53bd041, contents + rel[1].r_offset);
5816 bfd_putl32 (0x8b000020, contents + rel[1].r_offset + 4);
5817 return bfd_reloc_continue;
5818 }
5819
a6bb11b2
YZ
5820 case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12_NC:
5821 case BFD_RELOC_AARCH64_TLSDESC_CALL:
a06ea964
NC
5822 /* GD->IE/LE relaxation:
5823 add x0, x0, #:tlsdesc_lo12:var => nop
5824 blr xd => nop
5825 */
5826 bfd_putl32 (INSN_NOP, contents + rel->r_offset);
5827 return bfd_reloc_ok;
5828
a6bb11b2 5829 case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21:
a06ea964
NC
5830 /* IE->LE relaxation:
5831 adrp xd, :gottprel:var => movz xd, :tprel_g1:var
5832 */
5833 if (is_local)
5834 {
5835 insn = bfd_getl32 (contents + rel->r_offset);
5836 bfd_putl32 (0xd2a00000 | (insn & 0x1f), contents + rel->r_offset);
5837 }
5838 return bfd_reloc_continue;
5839
a6bb11b2 5840 case BFD_RELOC_AARCH64_TLSIE_LDNN_GOTTPREL_LO12_NC:
a06ea964
NC
5841 /* IE->LE relaxation:
5842 ldr xd, [xm, #:gottprel_lo12:var] => movk xd, :tprel_g0_nc:var
5843 */
5844 if (is_local)
5845 {
5846 insn = bfd_getl32 (contents + rel->r_offset);
5847 bfd_putl32 (0xf2800000 | (insn & 0x1f), contents + rel->r_offset);
5848 }
5849 return bfd_reloc_continue;
5850
259364ad
JW
5851 case BFD_RELOC_AARCH64_TLSLD_ADR_PREL21:
5852 /* LD->LE relaxation (tiny):
5853 adr x0, :tlsldm:x => mrs x0, tpidr_el0
5854 bl __tls_get_addr => add x0, x0, TCB_SIZE
5855 */
5856 if (is_local)
5857 {
5858 BFD_ASSERT (rel->r_offset + 4 == rel[1].r_offset);
5859 BFD_ASSERT (ELFNN_R_TYPE (rel[1].r_info) == AARCH64_R (CALL26));
5860 /* No need of CALL26 relocation for tls_get_addr. */
5861 rel[1].r_info = ELFNN_R_INFO (STN_UNDEF, R_AARCH64_NONE);
5862 bfd_putl32 (0xd53bd040, contents + rel->r_offset + 0);
5863 bfd_putl32 (0x91004000, contents + rel->r_offset + 4);
5864 return bfd_reloc_ok;
5865 }
5866 return bfd_reloc_continue;
5867
5868 case BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21:
5869 /* LD->LE relaxation (small):
5870 adrp x0, :tlsldm:x => mrs x0, tpidr_el0
5871 */
5872 if (is_local)
5873 {
5874 bfd_putl32 (0xd53bd040, contents + rel->r_offset);
5875 return bfd_reloc_ok;
5876 }
5877 return bfd_reloc_continue;
5878
5879 case BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC:
5880 /* LD->LE relaxation (small):
5881 add x0, #:tlsldm_lo12:x => add x0, x0, TCB_SIZE
5882 bl __tls_get_addr => nop
5883 */
5884 if (is_local)
5885 {
5886 BFD_ASSERT (rel->r_offset + 4 == rel[1].r_offset);
5887 BFD_ASSERT (ELFNN_R_TYPE (rel[1].r_info) == AARCH64_R (CALL26));
5888 /* No need of CALL26 relocation for tls_get_addr. */
5889 rel[1].r_info = ELFNN_R_INFO (STN_UNDEF, R_AARCH64_NONE);
5890 bfd_putl32 (0x91004000, contents + rel->r_offset + 0);
5891 bfd_putl32 (0xd503201f, contents + rel->r_offset + 4);
5892 return bfd_reloc_ok;
5893 }
5894 return bfd_reloc_continue;
5895
a06ea964
NC
5896 default:
5897 return bfd_reloc_continue;
5898 }
5899
5900 return bfd_reloc_ok;
5901}
5902
5903/* Relocate an AArch64 ELF section. */
5904
5905static bfd_boolean
cec5225b 5906elfNN_aarch64_relocate_section (bfd *output_bfd,
a06ea964
NC
5907 struct bfd_link_info *info,
5908 bfd *input_bfd,
5909 asection *input_section,
5910 bfd_byte *contents,
5911 Elf_Internal_Rela *relocs,
5912 Elf_Internal_Sym *local_syms,
5913 asection **local_sections)
5914{
5915 Elf_Internal_Shdr *symtab_hdr;
5916 struct elf_link_hash_entry **sym_hashes;
5917 Elf_Internal_Rela *rel;
5918 Elf_Internal_Rela *relend;
5919 const char *name;
cec5225b 5920 struct elf_aarch64_link_hash_table *globals;
a06ea964
NC
5921 bfd_boolean save_addend = FALSE;
5922 bfd_vma addend = 0;
5923
cec5225b 5924 globals = elf_aarch64_hash_table (info);
a06ea964
NC
5925
5926 symtab_hdr = &elf_symtab_hdr (input_bfd);
5927 sym_hashes = elf_sym_hashes (input_bfd);
5928
5929 rel = relocs;
5930 relend = relocs + input_section->reloc_count;
5931 for (; rel < relend; rel++)
5932 {
5933 unsigned int r_type;
a6bb11b2
YZ
5934 bfd_reloc_code_real_type bfd_r_type;
5935 bfd_reloc_code_real_type relaxed_bfd_r_type;
a06ea964
NC
5936 reloc_howto_type *howto;
5937 unsigned long r_symndx;
5938 Elf_Internal_Sym *sym;
5939 asection *sec;
5940 struct elf_link_hash_entry *h;
5941 bfd_vma relocation;
5942 bfd_reloc_status_type r;
5943 arelent bfd_reloc;
5944 char sym_type;
5945 bfd_boolean unresolved_reloc = FALSE;
5946 char *error_message = NULL;
5947
cec5225b
YZ
5948 r_symndx = ELFNN_R_SYM (rel->r_info);
5949 r_type = ELFNN_R_TYPE (rel->r_info);
a06ea964 5950
cec5225b 5951 bfd_reloc.howto = elfNN_aarch64_howto_from_type (r_type);
a06ea964
NC
5952 howto = bfd_reloc.howto;
5953
7fcfd62d
NC
5954 if (howto == NULL)
5955 {
5956 (*_bfd_error_handler)
5957 (_("%B: unrecognized relocation (0x%x) in section `%A'"),
5958 input_bfd, input_section, r_type);
5959 return FALSE;
5960 }
a6bb11b2 5961 bfd_r_type = elfNN_aarch64_bfd_reloc_from_howto (howto);
7fcfd62d 5962
a06ea964
NC
5963 h = NULL;
5964 sym = NULL;
5965 sec = NULL;
5966
5967 if (r_symndx < symtab_hdr->sh_info)
5968 {
5969 sym = local_syms + r_symndx;
cec5225b 5970 sym_type = ELFNN_ST_TYPE (sym->st_info);
a06ea964
NC
5971 sec = local_sections[r_symndx];
5972
5973 /* An object file might have a reference to a local
5974 undefined symbol. This is a daft object file, but we
5975 should at least do something about it. */
5976 if (r_type != R_AARCH64_NONE && r_type != R_AARCH64_NULL
5977 && bfd_is_und_section (sec)
5978 && ELF_ST_BIND (sym->st_info) != STB_WEAK)
5979 {
5980 if (!info->callbacks->undefined_symbol
5981 (info, bfd_elf_string_from_elf_section
5982 (input_bfd, symtab_hdr->sh_link, sym->st_name),
5983 input_bfd, input_section, rel->r_offset, TRUE))
5984 return FALSE;
5985 }
5986
a06ea964 5987 relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel);
1419bbe5
WN
5988
5989 /* Relocate against local STT_GNU_IFUNC symbol. */
0e1862bb 5990 if (!bfd_link_relocatable (info)
1419bbe5
WN
5991 && ELF_ST_TYPE (sym->st_info) == STT_GNU_IFUNC)
5992 {
5993 h = elfNN_aarch64_get_local_sym_hash (globals, input_bfd,
5994 rel, FALSE);
5995 if (h == NULL)
5996 abort ();
5997
5998 /* Set STT_GNU_IFUNC symbol value. */
5999 h->root.u.def.value = sym->st_value;
6000 h->root.u.def.section = sec;
6001 }
a06ea964
NC
6002 }
6003 else
6004 {
62d887d4 6005 bfd_boolean warned, ignored;
a06ea964
NC
6006
6007 RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel,
6008 r_symndx, symtab_hdr, sym_hashes,
6009 h, sec, relocation,
62d887d4 6010 unresolved_reloc, warned, ignored);
a06ea964
NC
6011
6012 sym_type = h->type;
6013 }
6014
6015 if (sec != NULL && discarded_section (sec))
6016 RELOC_AGAINST_DISCARDED_SECTION (info, input_bfd, input_section,
6017 rel, 1, relend, howto, 0, contents);
6018
0e1862bb 6019 if (bfd_link_relocatable (info))
2e0488d3 6020 continue;
a06ea964
NC
6021
6022 if (h != NULL)
6023 name = h->root.root.string;
6024 else
6025 {
6026 name = (bfd_elf_string_from_elf_section
6027 (input_bfd, symtab_hdr->sh_link, sym->st_name));
6028 if (name == NULL || *name == '\0')
6029 name = bfd_section_name (input_bfd, sec);
6030 }
6031
6032 if (r_symndx != 0
6033 && r_type != R_AARCH64_NONE
6034 && r_type != R_AARCH64_NULL
6035 && (h == NULL
6036 || h->root.type == bfd_link_hash_defined
6037 || h->root.type == bfd_link_hash_defweak)
a6bb11b2 6038 && IS_AARCH64_TLS_RELOC (bfd_r_type) != (sym_type == STT_TLS))
a06ea964
NC
6039 {
6040 (*_bfd_error_handler)
6041 ((sym_type == STT_TLS
6042 ? _("%B(%A+0x%lx): %s used with TLS symbol %s")
6043 : _("%B(%A+0x%lx): %s used with non-TLS symbol %s")),
6044 input_bfd,
6045 input_section, (long) rel->r_offset, howto->name, name);
6046 }
6047
a06ea964
NC
6048 /* We relax only if we can see that there can be a valid transition
6049 from a reloc type to another.
cec5225b 6050 We call elfNN_aarch64_final_link_relocate unless we're completely
a06ea964
NC
6051 done, i.e., the relaxation produced the final output we want. */
6052
a6bb11b2
YZ
6053 relaxed_bfd_r_type = aarch64_tls_transition (input_bfd, info, r_type,
6054 h, r_symndx);
6055 if (relaxed_bfd_r_type != bfd_r_type)
a06ea964 6056 {
a6bb11b2
YZ
6057 bfd_r_type = relaxed_bfd_r_type;
6058 howto = elfNN_aarch64_howto_from_bfd_reloc (bfd_r_type);
6059 BFD_ASSERT (howto != NULL);
6060 r_type = howto->type;
cec5225b 6061 r = elfNN_aarch64_tls_relax (globals, input_bfd, contents, rel, h);
a06ea964
NC
6062 unresolved_reloc = 0;
6063 }
6064 else
6065 r = bfd_reloc_continue;
6066
6067 /* There may be multiple consecutive relocations for the
6068 same offset. In that case we are supposed to treat the
6069 output of each relocation as the addend for the next. */
6070 if (rel + 1 < relend
6071 && rel->r_offset == rel[1].r_offset
cec5225b
YZ
6072 && ELFNN_R_TYPE (rel[1].r_info) != R_AARCH64_NONE
6073 && ELFNN_R_TYPE (rel[1].r_info) != R_AARCH64_NULL)
a06ea964
NC
6074 save_addend = TRUE;
6075 else
6076 save_addend = FALSE;
6077
6078 if (r == bfd_reloc_continue)
cec5225b 6079 r = elfNN_aarch64_final_link_relocate (howto, input_bfd, output_bfd,
a06ea964
NC
6080 input_section, contents, rel,
6081 relocation, info, sec,
6082 h, &unresolved_reloc,
1419bbe5 6083 save_addend, &addend, sym);
a06ea964 6084
a6bb11b2 6085 switch (elfNN_aarch64_bfd_reloc_from_type (r_type))
a06ea964 6086 {
ce336788 6087 case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC:
a6bb11b2 6088 case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21:
3c12b054 6089 case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21:
7ba7cfe4 6090 case BFD_RELOC_AARCH64_TLSGD_MOVW_G0_NC:
94facae3 6091 case BFD_RELOC_AARCH64_TLSGD_MOVW_G1:
73f925cc 6092 case BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC:
f69e4920 6093 case BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21:
77a69ff8 6094 case BFD_RELOC_AARCH64_TLSLD_ADR_PREL21:
a06ea964
NC
6095 if (! symbol_got_offset_mark_p (input_bfd, h, r_symndx))
6096 {
6097 bfd_boolean need_relocs = FALSE;
6098 bfd_byte *loc;
6099 int indx;
6100 bfd_vma off;
6101
6102 off = symbol_got_offset (input_bfd, h, r_symndx);
6103 indx = h && h->dynindx != -1 ? h->dynindx : 0;
6104
6105 need_relocs =
0e1862bb 6106 (bfd_link_pic (info) || indx != 0) &&
a06ea964
NC
6107 (h == NULL
6108 || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
6109 || h->root.type != bfd_link_hash_undefweak);
6110
6111 BFD_ASSERT (globals->root.srelgot != NULL);
6112
6113 if (need_relocs)
6114 {
6115 Elf_Internal_Rela rela;
a6bb11b2 6116 rela.r_info = ELFNN_R_INFO (indx, AARCH64_R (TLS_DTPMOD));
a06ea964
NC
6117 rela.r_addend = 0;
6118 rela.r_offset = globals->root.sgot->output_section->vma +
6119 globals->root.sgot->output_offset + off;
6120
6121
6122 loc = globals->root.srelgot->contents;
6123 loc += globals->root.srelgot->reloc_count++
6124 * RELOC_SIZE (htab);
cec5225b 6125 bfd_elfNN_swap_reloca_out (output_bfd, &rela, loc);
a06ea964 6126
f69e4920
JW
6127 bfd_reloc_code_real_type real_type =
6128 elfNN_aarch64_bfd_reloc_from_type (r_type);
6129
6130 if (real_type == BFD_RELOC_AARCH64_TLSLD_ADR_PREL21
73f925cc
JW
6131 || real_type == BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21
6132 || real_type == BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC)
77a69ff8
JW
6133 {
6134 /* For local dynamic, don't generate DTPREL in any case.
6135 Initialize the DTPREL slot into zero, so we get module
6136 base address when invoke runtime TLS resolver. */
6137 bfd_put_NN (output_bfd, 0,
6138 globals->root.sgot->contents + off
6139 + GOT_ENTRY_SIZE);
6140 }
6141 else if (indx == 0)
a06ea964 6142 {
cec5225b 6143 bfd_put_NN (output_bfd,
a06ea964
NC
6144 relocation - dtpoff_base (info),
6145 globals->root.sgot->contents + off
6146 + GOT_ENTRY_SIZE);
6147 }
6148 else
6149 {
6150 /* This TLS symbol is global. We emit a
6151 relocation to fixup the tls offset at load
6152 time. */
6153 rela.r_info =
a6bb11b2 6154 ELFNN_R_INFO (indx, AARCH64_R (TLS_DTPREL));
a06ea964
NC
6155 rela.r_addend = 0;
6156 rela.r_offset =
6157 (globals->root.sgot->output_section->vma
6158 + globals->root.sgot->output_offset + off
6159 + GOT_ENTRY_SIZE);
6160
6161 loc = globals->root.srelgot->contents;
6162 loc += globals->root.srelgot->reloc_count++
6163 * RELOC_SIZE (globals);
cec5225b
YZ
6164 bfd_elfNN_swap_reloca_out (output_bfd, &rela, loc);
6165 bfd_put_NN (output_bfd, (bfd_vma) 0,
a06ea964
NC
6166 globals->root.sgot->contents + off
6167 + GOT_ENTRY_SIZE);
6168 }
6169 }
6170 else
6171 {
cec5225b 6172 bfd_put_NN (output_bfd, (bfd_vma) 1,
a06ea964 6173 globals->root.sgot->contents + off);
cec5225b 6174 bfd_put_NN (output_bfd,
a06ea964
NC
6175 relocation - dtpoff_base (info),
6176 globals->root.sgot->contents + off
6177 + GOT_ENTRY_SIZE);
6178 }
6179
6180 symbol_got_offset_mark (input_bfd, h, r_symndx);
6181 }
6182 break;
6183
a6bb11b2
YZ
6184 case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21:
6185 case BFD_RELOC_AARCH64_TLSIE_LDNN_GOTTPREL_LO12_NC:
043bf05a 6186 case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19:
3b957e5b
RL
6187 case BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G0_NC:
6188 case BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G1:
a06ea964
NC
6189 if (! symbol_got_offset_mark_p (input_bfd, h, r_symndx))
6190 {
6191 bfd_boolean need_relocs = FALSE;
6192 bfd_byte *loc;
6193 int indx;
6194 bfd_vma off;
6195
6196 off = symbol_got_offset (input_bfd, h, r_symndx);
6197
6198 indx = h && h->dynindx != -1 ? h->dynindx : 0;
6199
6200 need_relocs =
0e1862bb 6201 (bfd_link_pic (info) || indx != 0) &&
a06ea964
NC
6202 (h == NULL
6203 || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
6204 || h->root.type != bfd_link_hash_undefweak);
6205
6206 BFD_ASSERT (globals->root.srelgot != NULL);
6207
6208 if (need_relocs)
6209 {
6210 Elf_Internal_Rela rela;
6211
6212 if (indx == 0)
6213 rela.r_addend = relocation - dtpoff_base (info);
6214 else
6215 rela.r_addend = 0;
6216
a6bb11b2 6217 rela.r_info = ELFNN_R_INFO (indx, AARCH64_R (TLS_TPREL));
a06ea964
NC
6218 rela.r_offset = globals->root.sgot->output_section->vma +
6219 globals->root.sgot->output_offset + off;
6220
6221 loc = globals->root.srelgot->contents;
6222 loc += globals->root.srelgot->reloc_count++
6223 * RELOC_SIZE (htab);
6224
cec5225b 6225 bfd_elfNN_swap_reloca_out (output_bfd, &rela, loc);
a06ea964 6226
cec5225b 6227 bfd_put_NN (output_bfd, rela.r_addend,
a06ea964
NC
6228 globals->root.sgot->contents + off);
6229 }
6230 else
cec5225b 6231 bfd_put_NN (output_bfd, relocation - tpoff_base (info),
a06ea964
NC
6232 globals->root.sgot->contents + off);
6233
6234 symbol_got_offset_mark (input_bfd, h, r_symndx);
6235 }
6236 break;
6237
7bcccb57 6238 case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12_NC:
a6bb11b2 6239 case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21:
389b8029 6240 case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21:
a6bb11b2 6241 case BFD_RELOC_AARCH64_TLSDESC_LDNN_LO12_NC:
1ada945d 6242 case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19:
a06ea964
NC
6243 if (! symbol_tlsdesc_got_offset_mark_p (input_bfd, h, r_symndx))
6244 {
6245 bfd_boolean need_relocs = FALSE;
6246 int indx = h && h->dynindx != -1 ? h->dynindx : 0;
6247 bfd_vma off = symbol_tlsdesc_got_offset (input_bfd, h, r_symndx);
6248
6249 need_relocs = (h == NULL
6250 || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
6251 || h->root.type != bfd_link_hash_undefweak);
6252
6253 BFD_ASSERT (globals->root.srelgot != NULL);
6254 BFD_ASSERT (globals->root.sgot != NULL);
6255
6256 if (need_relocs)
6257 {
6258 bfd_byte *loc;
6259 Elf_Internal_Rela rela;
a6bb11b2
YZ
6260 rela.r_info = ELFNN_R_INFO (indx, AARCH64_R (TLSDESC));
6261
a06ea964
NC
6262 rela.r_addend = 0;
6263 rela.r_offset = (globals->root.sgotplt->output_section->vma
6264 + globals->root.sgotplt->output_offset
6265 + off + globals->sgotplt_jump_table_size);
6266
6267 if (indx == 0)
6268 rela.r_addend = relocation - dtpoff_base (info);
6269
6270 /* Allocate the next available slot in the PLT reloc
6271 section to hold our R_AARCH64_TLSDESC, the next
6272 available slot is determined from reloc_count,
6273 which we step. But note, reloc_count was
6274 artifically moved down while allocating slots for
6275 real PLT relocs such that all of the PLT relocs
6276 will fit above the initial reloc_count and the
6277 extra stuff will fit below. */
6278 loc = globals->root.srelplt->contents;
6279 loc += globals->root.srelplt->reloc_count++
6280 * RELOC_SIZE (globals);
6281
cec5225b 6282 bfd_elfNN_swap_reloca_out (output_bfd, &rela, loc);
a06ea964 6283
cec5225b 6284 bfd_put_NN (output_bfd, (bfd_vma) 0,
a06ea964
NC
6285 globals->root.sgotplt->contents + off +
6286 globals->sgotplt_jump_table_size);
cec5225b 6287 bfd_put_NN (output_bfd, (bfd_vma) 0,
a06ea964
NC
6288 globals->root.sgotplt->contents + off +
6289 globals->sgotplt_jump_table_size +
6290 GOT_ENTRY_SIZE);
6291 }
6292
6293 symbol_tlsdesc_got_offset_mark (input_bfd, h, r_symndx);
6294 }
6295 break;
a6bb11b2
YZ
6296 default:
6297 break;
a06ea964
NC
6298 }
6299
6300 if (!save_addend)
6301 addend = 0;
6302
6303
6304 /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
6305 because such sections are not SEC_ALLOC and thus ld.so will
6306 not process them. */
6307 if (unresolved_reloc
6308 && !((input_section->flags & SEC_DEBUGGING) != 0
6309 && h->def_dynamic)
6310 && _bfd_elf_section_offset (output_bfd, info, input_section,
6311 +rel->r_offset) != (bfd_vma) - 1)
6312 {
6313 (*_bfd_error_handler)
6314 (_
6315 ("%B(%A+0x%lx): unresolvable %s relocation against symbol `%s'"),
6316 input_bfd, input_section, (long) rel->r_offset, howto->name,
6317 h->root.root.string);
6318 return FALSE;
6319 }
6320
6321 if (r != bfd_reloc_ok && r != bfd_reloc_continue)
6322 {
c674f5cd
JW
6323 bfd_reloc_code_real_type real_r_type
6324 = elfNN_aarch64_bfd_reloc_from_type (r_type);
6325
a06ea964
NC
6326 switch (r)
6327 {
6328 case bfd_reloc_overflow:
fdc3b1b1
JW
6329 if (!(*info->callbacks->reloc_overflow)
6330 (info, (h ? &h->root : NULL), name, howto->name, (bfd_vma) 0,
6331 input_bfd, input_section, rel->r_offset))
a06ea964 6332 return FALSE;
c674f5cd
JW
6333 if (real_r_type == BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15
6334 || real_r_type == BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14)
6335 {
6336 (*info->callbacks->warning)
6337 (info,
6338 _("Too many GOT entries for -fpic, "
6339 "please recompile with -fPIC"),
6340 name, input_bfd, input_section, rel->r_offset);
6341 return FALSE;
6342 }
a06ea964
NC
6343 break;
6344
6345 case bfd_reloc_undefined:
6346 if (!((*info->callbacks->undefined_symbol)
6347 (info, name, input_bfd, input_section,
6348 rel->r_offset, TRUE)))
6349 return FALSE;
6350 break;
6351
6352 case bfd_reloc_outofrange:
6353 error_message = _("out of range");
6354 goto common_error;
6355
6356 case bfd_reloc_notsupported:
6357 error_message = _("unsupported relocation");
6358 goto common_error;
6359
6360 case bfd_reloc_dangerous:
6361 /* error_message should already be set. */
6362 goto common_error;
6363
6364 default:
6365 error_message = _("unknown error");
6366 /* Fall through. */
6367
6368 common_error:
6369 BFD_ASSERT (error_message != NULL);
6370 if (!((*info->callbacks->reloc_dangerous)
6371 (info, error_message, input_bfd, input_section,
6372 rel->r_offset)))
6373 return FALSE;
6374 break;
6375 }
6376 }
6377 }
6378
6379 return TRUE;
6380}
6381
6382/* Set the right machine number. */
6383
6384static bfd_boolean
cec5225b 6385elfNN_aarch64_object_p (bfd *abfd)
a06ea964 6386{
cec5225b
YZ
6387#if ARCH_SIZE == 32
6388 bfd_default_set_arch_mach (abfd, bfd_arch_aarch64, bfd_mach_aarch64_ilp32);
6389#else
a06ea964 6390 bfd_default_set_arch_mach (abfd, bfd_arch_aarch64, bfd_mach_aarch64);
cec5225b 6391#endif
a06ea964
NC
6392 return TRUE;
6393}
6394
6395/* Function to keep AArch64 specific flags in the ELF header. */
6396
6397static bfd_boolean
cec5225b 6398elfNN_aarch64_set_private_flags (bfd *abfd, flagword flags)
a06ea964
NC
6399{
6400 if (elf_flags_init (abfd) && elf_elfheader (abfd)->e_flags != flags)
6401 {
6402 }
6403 else
6404 {
6405 elf_elfheader (abfd)->e_flags = flags;
6406 elf_flags_init (abfd) = TRUE;
6407 }
6408
6409 return TRUE;
6410}
6411
a06ea964
NC
6412/* Merge backend specific data from an object file to the output
6413 object file when linking. */
6414
6415static bfd_boolean
cec5225b 6416elfNN_aarch64_merge_private_bfd_data (bfd *ibfd, bfd *obfd)
a06ea964
NC
6417{
6418 flagword out_flags;
6419 flagword in_flags;
6420 bfd_boolean flags_compatible = TRUE;
6421 asection *sec;
6422
6423 /* Check if we have the same endianess. */
6424 if (!_bfd_generic_verify_endian_match (ibfd, obfd))
6425 return FALSE;
6426
6427 if (!is_aarch64_elf (ibfd) || !is_aarch64_elf (obfd))
6428 return TRUE;
6429
6430 /* The input BFD must have had its flags initialised. */
6431 /* The following seems bogus to me -- The flags are initialized in
6432 the assembler but I don't think an elf_flags_init field is
6433 written into the object. */
6434 /* BFD_ASSERT (elf_flags_init (ibfd)); */
6435
6436 in_flags = elf_elfheader (ibfd)->e_flags;
6437 out_flags = elf_elfheader (obfd)->e_flags;
6438
6439 if (!elf_flags_init (obfd))
6440 {
6441 /* If the input is the default architecture and had the default
6442 flags then do not bother setting the flags for the output
6443 architecture, instead allow future merges to do this. If no
6444 future merges ever set these flags then they will retain their
6445 uninitialised values, which surprise surprise, correspond
6446 to the default values. */
6447 if (bfd_get_arch_info (ibfd)->the_default
6448 && elf_elfheader (ibfd)->e_flags == 0)
6449 return TRUE;
6450
6451 elf_flags_init (obfd) = TRUE;
6452 elf_elfheader (obfd)->e_flags = in_flags;
6453
6454 if (bfd_get_arch (obfd) == bfd_get_arch (ibfd)
6455 && bfd_get_arch_info (obfd)->the_default)
6456 return bfd_set_arch_mach (obfd, bfd_get_arch (ibfd),
6457 bfd_get_mach (ibfd));
6458
6459 return TRUE;
6460 }
6461
6462 /* Identical flags must be compatible. */
6463 if (in_flags == out_flags)
6464 return TRUE;
6465
6466 /* Check to see if the input BFD actually contains any sections. If
6467 not, its flags may not have been initialised either, but it
6468 cannot actually cause any incompatiblity. Do not short-circuit
6469 dynamic objects; their section list may be emptied by
6470 elf_link_add_object_symbols.
6471
6472 Also check to see if there are no code sections in the input.
6473 In this case there is no need to check for code specific flags.
6474 XXX - do we need to worry about floating-point format compatability
6475 in data sections ? */
6476 if (!(ibfd->flags & DYNAMIC))
6477 {
6478 bfd_boolean null_input_bfd = TRUE;
6479 bfd_boolean only_data_sections = TRUE;
6480
6481 for (sec = ibfd->sections; sec != NULL; sec = sec->next)
6482 {
6483 if ((bfd_get_section_flags (ibfd, sec)
6484 & (SEC_LOAD | SEC_CODE | SEC_HAS_CONTENTS))
6485 == (SEC_LOAD | SEC_CODE | SEC_HAS_CONTENTS))
6486 only_data_sections = FALSE;
6487
6488 null_input_bfd = FALSE;
6489 break;
6490 }
6491
6492 if (null_input_bfd || only_data_sections)
6493 return TRUE;
6494 }
6495
6496 return flags_compatible;
6497}
6498
6499/* Display the flags field. */
6500
6501static bfd_boolean
cec5225b 6502elfNN_aarch64_print_private_bfd_data (bfd *abfd, void *ptr)
a06ea964
NC
6503{
6504 FILE *file = (FILE *) ptr;
6505 unsigned long flags;
6506
6507 BFD_ASSERT (abfd != NULL && ptr != NULL);
6508
6509 /* Print normal ELF private data. */
6510 _bfd_elf_print_private_bfd_data (abfd, ptr);
6511
6512 flags = elf_elfheader (abfd)->e_flags;
6513 /* Ignore init flag - it may not be set, despite the flags field
6514 containing valid data. */
6515
6516 /* xgettext:c-format */
6517 fprintf (file, _("private flags = %lx:"), elf_elfheader (abfd)->e_flags);
6518
6519 if (flags)
6520 fprintf (file, _("<Unrecognised flag bits set>"));
6521
6522 fputc ('\n', file);
6523
6524 return TRUE;
6525}
6526
6527/* Update the got entry reference counts for the section being removed. */
6528
6529static bfd_boolean
cec5225b 6530elfNN_aarch64_gc_sweep_hook (bfd *abfd,
cb8af559
NC
6531 struct bfd_link_info *info,
6532 asection *sec,
6533 const Elf_Internal_Rela * relocs)
a06ea964 6534{
cec5225b 6535 struct elf_aarch64_link_hash_table *htab;
59c108f7
NC
6536 Elf_Internal_Shdr *symtab_hdr;
6537 struct elf_link_hash_entry **sym_hashes;
cb8af559 6538 struct elf_aarch64_local_symbol *locals;
59c108f7
NC
6539 const Elf_Internal_Rela *rel, *relend;
6540
0e1862bb 6541 if (bfd_link_relocatable (info))
59c108f7
NC
6542 return TRUE;
6543
cec5225b 6544 htab = elf_aarch64_hash_table (info);
59c108f7
NC
6545
6546 if (htab == NULL)
6547 return FALSE;
6548
6549 elf_section_data (sec)->local_dynrel = NULL;
6550
6551 symtab_hdr = &elf_symtab_hdr (abfd);
6552 sym_hashes = elf_sym_hashes (abfd);
6553
cec5225b 6554 locals = elf_aarch64_locals (abfd);
59c108f7
NC
6555
6556 relend = relocs + sec->reloc_count;
6557 for (rel = relocs; rel < relend; rel++)
6558 {
6559 unsigned long r_symndx;
6560 unsigned int r_type;
6561 struct elf_link_hash_entry *h = NULL;
6562
cec5225b 6563 r_symndx = ELFNN_R_SYM (rel->r_info);
8847944f 6564
59c108f7
NC
6565 if (r_symndx >= symtab_hdr->sh_info)
6566 {
8847944f 6567
59c108f7
NC
6568 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
6569 while (h->root.type == bfd_link_hash_indirect
6570 || h->root.type == bfd_link_hash_warning)
6571 h = (struct elf_link_hash_entry *) h->root.u.i.link;
59c108f7
NC
6572 }
6573 else
6574 {
6575 Elf_Internal_Sym *isym;
6576
8847944f 6577 /* A local symbol. */
59c108f7
NC
6578 isym = bfd_sym_from_r_symndx (&htab->sym_cache,
6579 abfd, r_symndx);
1419bbe5
WN
6580
6581 /* Check relocation against local STT_GNU_IFUNC symbol. */
6582 if (isym != NULL
6583 && ELF_ST_TYPE (isym->st_info) == STT_GNU_IFUNC)
6584 {
6585 h = elfNN_aarch64_get_local_sym_hash (htab, abfd, rel, FALSE);
6586 if (h == NULL)
6587 abort ();
6588 }
6589 }
6590
6591 if (h)
6592 {
6593 struct elf_aarch64_link_hash_entry *eh;
6594 struct elf_dyn_relocs **pp;
6595 struct elf_dyn_relocs *p;
6596
6597 eh = (struct elf_aarch64_link_hash_entry *) h;
6598
6599 for (pp = &eh->dyn_relocs; (p = *pp) != NULL; pp = &p->next)
6600 if (p->sec == sec)
6601 {
6602 /* Everything must go for SEC. */
6603 *pp = p->next;
6604 break;
6605 }
59c108f7
NC
6606 }
6607
cec5225b 6608 r_type = ELFNN_R_TYPE (rel->r_info);
a6bb11b2 6609 switch (aarch64_tls_transition (abfd,info, r_type, h ,r_symndx))
59c108f7 6610 {
a6bb11b2 6611 case BFD_RELOC_AARCH64_ADR_GOT_PAGE:
7bcccb57 6612 case BFD_RELOC_AARCH64_GOT_LD_PREL19:
7018c030 6613 case BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14:
7bcccb57 6614 case BFD_RELOC_AARCH64_LD32_GOT_LO12_NC:
a2e1db00 6615 case BFD_RELOC_AARCH64_LD64_GOTOFF_LO15:
99ad26cb 6616 case BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15:
7bcccb57 6617 case BFD_RELOC_AARCH64_LD64_GOT_LO12_NC:
dc8008f5 6618 case BFD_RELOC_AARCH64_MOVW_GOTOFF_G0_NC:
74a1bfe1 6619 case BFD_RELOC_AARCH64_MOVW_GOTOFF_G1:
7bcccb57
MS
6620 case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12_NC:
6621 case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21:
389b8029 6622 case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21:
7bcccb57
MS
6623 case BFD_RELOC_AARCH64_TLSDESC_LD32_LO12_NC:
6624 case BFD_RELOC_AARCH64_TLSDESC_LD64_LO12_NC:
1ada945d 6625 case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19:
a6bb11b2 6626 case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC:
7bcccb57 6627 case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21:
3c12b054 6628 case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21:
7ba7cfe4 6629 case BFD_RELOC_AARCH64_TLSGD_MOVW_G0_NC:
94facae3 6630 case BFD_RELOC_AARCH64_TLSGD_MOVW_G1:
a6bb11b2 6631 case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21:
a6bb11b2 6632 case BFD_RELOC_AARCH64_TLSIE_LD32_GOTTPREL_LO12_NC:
7bcccb57 6633 case BFD_RELOC_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC:
043bf05a 6634 case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19:
3b957e5b
RL
6635 case BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G0_NC:
6636 case BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G1:
73f925cc 6637 case BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC:
f69e4920 6638 case BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21:
77a69ff8 6639 case BFD_RELOC_AARCH64_TLSLD_ADR_PREL21:
a6bb11b2 6640 if (h != NULL)
59c108f7
NC
6641 {
6642 if (h->got.refcount > 0)
6643 h->got.refcount -= 1;
1419bbe5
WN
6644
6645 if (h->type == STT_GNU_IFUNC)
6646 {
6647 if (h->plt.refcount > 0)
6648 h->plt.refcount -= 1;
6649 }
59c108f7 6650 }
cb8af559 6651 else if (locals != NULL)
59c108f7 6652 {
cb8af559
NC
6653 if (locals[r_symndx].got_refcount > 0)
6654 locals[r_symndx].got_refcount -= 1;
59c108f7
NC
6655 }
6656 break;
6657
a6bb11b2
YZ
6658 case BFD_RELOC_AARCH64_CALL26:
6659 case BFD_RELOC_AARCH64_JUMP26:
6660 /* If this is a local symbol then we resolve it
6661 directly without creating a PLT entry. */
59c108f7
NC
6662 if (h == NULL)
6663 continue;
6664
6665 if (h->plt.refcount > 0)
6666 h->plt.refcount -= 1;
6667 break;
6668
ce336788
JW
6669 case BFD_RELOC_AARCH64_ADR_HI21_NC_PCREL:
6670 case BFD_RELOC_AARCH64_ADR_HI21_PCREL:
6671 case BFD_RELOC_AARCH64_ADR_LO21_PCREL:
614b09ce
JW
6672 case BFD_RELOC_AARCH64_MOVW_G0_NC:
6673 case BFD_RELOC_AARCH64_MOVW_G1_NC:
6674 case BFD_RELOC_AARCH64_MOVW_G2_NC:
6675 case BFD_RELOC_AARCH64_MOVW_G3:
a6bb11b2 6676 case BFD_RELOC_AARCH64_NN:
0e1862bb 6677 if (h != NULL && bfd_link_executable (info))
59c108f7
NC
6678 {
6679 if (h->plt.refcount > 0)
6680 h->plt.refcount -= 1;
6681 }
6682 break;
cec5225b 6683
59c108f7
NC
6684 default:
6685 break;
6686 }
6687 }
6688
a06ea964
NC
6689 return TRUE;
6690}
6691
6692/* Adjust a symbol defined by a dynamic object and referenced by a
6693 regular object. The current definition is in some section of the
6694 dynamic object, but we're not including those sections. We have to
6695 change the definition to something the rest of the link can
6696 understand. */
6697
6698static bfd_boolean
cec5225b 6699elfNN_aarch64_adjust_dynamic_symbol (struct bfd_link_info *info,
a06ea964
NC
6700 struct elf_link_hash_entry *h)
6701{
cec5225b 6702 struct elf_aarch64_link_hash_table *htab;
a06ea964
NC
6703 asection *s;
6704
6705 /* If this is a function, put it in the procedure linkage table. We
6706 will fill in the contents of the procedure linkage table later,
6707 when we know the address of the .got section. */
1419bbe5 6708 if (h->type == STT_FUNC || h->type == STT_GNU_IFUNC || h->needs_plt)
a06ea964
NC
6709 {
6710 if (h->plt.refcount <= 0
1419bbe5
WN
6711 || (h->type != STT_GNU_IFUNC
6712 && (SYMBOL_CALLS_LOCAL (info, h)
6713 || (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
6714 && h->root.type == bfd_link_hash_undefweak))))
a06ea964
NC
6715 {
6716 /* This case can occur if we saw a CALL26 reloc in
6717 an input file, but the symbol wasn't referred to
6718 by a dynamic object or all references were
6719 garbage collected. In which case we can end up
6720 resolving. */
6721 h->plt.offset = (bfd_vma) - 1;
6722 h->needs_plt = 0;
6723 }
6724
6725 return TRUE;
6726 }
6727 else
80de0c6d 6728 /* Otherwise, reset to -1. */
a06ea964
NC
6729 h->plt.offset = (bfd_vma) - 1;
6730
6731
6732 /* If this is a weak symbol, and there is a real definition, the
6733 processor independent code will have arranged for us to see the
6734 real definition first, and we can just use the same value. */
6735 if (h->u.weakdef != NULL)
6736 {
6737 BFD_ASSERT (h->u.weakdef->root.type == bfd_link_hash_defined
6738 || h->u.weakdef->root.type == bfd_link_hash_defweak);
6739 h->root.u.def.section = h->u.weakdef->root.u.def.section;
6740 h->root.u.def.value = h->u.weakdef->root.u.def.value;
6741 if (ELIMINATE_COPY_RELOCS || info->nocopyreloc)
6742 h->non_got_ref = h->u.weakdef->non_got_ref;
6743 return TRUE;
6744 }
6745
6746 /* If we are creating a shared library, we must presume that the
6747 only references to the symbol are via the global offset table.
6748 For such cases we need not do anything here; the relocations will
6749 be handled correctly by relocate_section. */
0e1862bb 6750 if (bfd_link_pic (info))
a06ea964
NC
6751 return TRUE;
6752
6753 /* If there are no references to this symbol that do not use the
6754 GOT, we don't need to generate a copy reloc. */
6755 if (!h->non_got_ref)
6756 return TRUE;
6757
6758 /* If -z nocopyreloc was given, we won't generate them either. */
6759 if (info->nocopyreloc)
6760 {
6761 h->non_got_ref = 0;
6762 return TRUE;
6763 }
6764
6765 /* We must allocate the symbol in our .dynbss section, which will
6766 become part of the .bss section of the executable. There will be
6767 an entry for this symbol in the .dynsym section. The dynamic
6768 object will contain position independent code, so all references
6769 from the dynamic object to this symbol will go through the global
6770 offset table. The dynamic linker will use the .dynsym entry to
6771 determine the address it must put in the global offset table, so
6772 both the dynamic object and the regular object will refer to the
6773 same memory location for the variable. */
6774
cec5225b 6775 htab = elf_aarch64_hash_table (info);
a06ea964
NC
6776
6777 /* We must generate a R_AARCH64_COPY reloc to tell the dynamic linker
6778 to copy the initial value out of the dynamic object and into the
6779 runtime process image. */
6780 if ((h->root.u.def.section->flags & SEC_ALLOC) != 0 && h->size != 0)
6781 {
6782 htab->srelbss->size += RELOC_SIZE (htab);
6783 h->needs_copy = 1;
6784 }
6785
6786 s = htab->sdynbss;
6787
6cabe1ea 6788 return _bfd_elf_adjust_dynamic_copy (info, h, s);
a06ea964
NC
6789
6790}
6791
6792static bfd_boolean
cec5225b 6793elfNN_aarch64_allocate_local_symbols (bfd *abfd, unsigned number)
a06ea964
NC
6794{
6795 struct elf_aarch64_local_symbol *locals;
cec5225b 6796 locals = elf_aarch64_locals (abfd);
a06ea964
NC
6797 if (locals == NULL)
6798 {
6799 locals = (struct elf_aarch64_local_symbol *)
6800 bfd_zalloc (abfd, number * sizeof (struct elf_aarch64_local_symbol));
6801 if (locals == NULL)
6802 return FALSE;
cec5225b 6803 elf_aarch64_locals (abfd) = locals;
a06ea964
NC
6804 }
6805 return TRUE;
6806}
6807
cc0efaa8
MS
6808/* Create the .got section to hold the global offset table. */
6809
6810static bfd_boolean
6811aarch64_elf_create_got_section (bfd *abfd, struct bfd_link_info *info)
6812{
6813 const struct elf_backend_data *bed = get_elf_backend_data (abfd);
6814 flagword flags;
6815 asection *s;
6816 struct elf_link_hash_entry *h;
6817 struct elf_link_hash_table *htab = elf_hash_table (info);
6818
6819 /* This function may be called more than once. */
6820 s = bfd_get_linker_section (abfd, ".got");
6821 if (s != NULL)
6822 return TRUE;
6823
6824 flags = bed->dynamic_sec_flags;
6825
6826 s = bfd_make_section_anyway_with_flags (abfd,
6827 (bed->rela_plts_and_copies_p
6828 ? ".rela.got" : ".rel.got"),
6829 (bed->dynamic_sec_flags
6830 | SEC_READONLY));
6831 if (s == NULL
6832 || ! bfd_set_section_alignment (abfd, s, bed->s->log_file_align))
6833 return FALSE;
6834 htab->srelgot = s;
6835
6836 s = bfd_make_section_anyway_with_flags (abfd, ".got", flags);
6837 if (s == NULL
6838 || !bfd_set_section_alignment (abfd, s, bed->s->log_file_align))
6839 return FALSE;
6840 htab->sgot = s;
6841 htab->sgot->size += GOT_ENTRY_SIZE;
6842
6843 if (bed->want_got_sym)
6844 {
6845 /* Define the symbol _GLOBAL_OFFSET_TABLE_ at the start of the .got
6846 (or .got.plt) section. We don't do this in the linker script
6847 because we don't want to define the symbol if we are not creating
6848 a global offset table. */
6849 h = _bfd_elf_define_linkage_sym (abfd, info, s,
6850 "_GLOBAL_OFFSET_TABLE_");
6851 elf_hash_table (info)->hgot = h;
6852 if (h == NULL)
6853 return FALSE;
6854 }
6855
6856 if (bed->want_got_plt)
6857 {
6858 s = bfd_make_section_anyway_with_flags (abfd, ".got.plt", flags);
6859 if (s == NULL
6860 || !bfd_set_section_alignment (abfd, s,
6861 bed->s->log_file_align))
6862 return FALSE;
6863 htab->sgotplt = s;
6864 }
6865
6866 /* The first bit of the global offset table is the header. */
6867 s->size += bed->got_header_size;
6868
6869 return TRUE;
6870}
6871
a06ea964
NC
6872/* Look through the relocs for a section during the first phase. */
6873
6874static bfd_boolean
cec5225b 6875elfNN_aarch64_check_relocs (bfd *abfd, struct bfd_link_info *info,
a06ea964
NC
6876 asection *sec, const Elf_Internal_Rela *relocs)
6877{
6878 Elf_Internal_Shdr *symtab_hdr;
6879 struct elf_link_hash_entry **sym_hashes;
6880 const Elf_Internal_Rela *rel;
6881 const Elf_Internal_Rela *rel_end;
6882 asection *sreloc;
6883
cec5225b 6884 struct elf_aarch64_link_hash_table *htab;
a06ea964 6885
0e1862bb 6886 if (bfd_link_relocatable (info))
a06ea964
NC
6887 return TRUE;
6888
6889 BFD_ASSERT (is_aarch64_elf (abfd));
6890
cec5225b 6891 htab = elf_aarch64_hash_table (info);
a06ea964
NC
6892 sreloc = NULL;
6893
6894 symtab_hdr = &elf_symtab_hdr (abfd);
6895 sym_hashes = elf_sym_hashes (abfd);
a06ea964
NC
6896
6897 rel_end = relocs + sec->reloc_count;
6898 for (rel = relocs; rel < rel_end; rel++)
6899 {
6900 struct elf_link_hash_entry *h;
6901 unsigned long r_symndx;
6902 unsigned int r_type;
a6bb11b2 6903 bfd_reloc_code_real_type bfd_r_type;
1419bbe5 6904 Elf_Internal_Sym *isym;
a06ea964 6905
cec5225b
YZ
6906 r_symndx = ELFNN_R_SYM (rel->r_info);
6907 r_type = ELFNN_R_TYPE (rel->r_info);
a06ea964
NC
6908
6909 if (r_symndx >= NUM_SHDR_ENTRIES (symtab_hdr))
6910 {
6911 (*_bfd_error_handler) (_("%B: bad symbol index: %d"), abfd,
6912 r_symndx);
6913 return FALSE;
6914 }
6915
ed5acf27 6916 if (r_symndx < symtab_hdr->sh_info)
1419bbe5
WN
6917 {
6918 /* A local symbol. */
6919 isym = bfd_sym_from_r_symndx (&htab->sym_cache,
6920 abfd, r_symndx);
6921 if (isym == NULL)
6922 return FALSE;
6923
6924 /* Check relocation against local STT_GNU_IFUNC symbol. */
6925 if (ELF_ST_TYPE (isym->st_info) == STT_GNU_IFUNC)
6926 {
6927 h = elfNN_aarch64_get_local_sym_hash (htab, abfd, rel,
6928 TRUE);
6929 if (h == NULL)
6930 return FALSE;
6931
6932 /* Fake a STT_GNU_IFUNC symbol. */
6933 h->type = STT_GNU_IFUNC;
6934 h->def_regular = 1;
6935 h->ref_regular = 1;
6936 h->forced_local = 1;
6937 h->root.type = bfd_link_hash_defined;
6938 }
6939 else
6940 h = NULL;
6941 }
a06ea964
NC
6942 else
6943 {
6944 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
6945 while (h->root.type == bfd_link_hash_indirect
6946 || h->root.type == bfd_link_hash_warning)
6947 h = (struct elf_link_hash_entry *) h->root.u.i.link;
81fbe831
AM
6948
6949 /* PR15323, ref flags aren't set for references in the same
6950 object. */
6951 h->root.non_ir_ref = 1;
a06ea964
NC
6952 }
6953
6954 /* Could be done earlier, if h were already available. */
a6bb11b2 6955 bfd_r_type = aarch64_tls_transition (abfd, info, r_type, h, r_symndx);
a06ea964 6956
1419bbe5
WN
6957 if (h != NULL)
6958 {
6959 /* Create the ifunc sections for static executables. If we
6960 never see an indirect function symbol nor we are building
6961 a static executable, those sections will be empty and
6962 won't appear in output. */
6963 switch (bfd_r_type)
6964 {
6965 default:
6966 break;
6967
ce336788
JW
6968 case BFD_RELOC_AARCH64_ADD_LO12:
6969 case BFD_RELOC_AARCH64_ADR_GOT_PAGE:
6970 case BFD_RELOC_AARCH64_ADR_HI21_PCREL:
1419bbe5 6971 case BFD_RELOC_AARCH64_CALL26:
ce336788 6972 case BFD_RELOC_AARCH64_GOT_LD_PREL19:
1419bbe5 6973 case BFD_RELOC_AARCH64_JUMP26:
7018c030 6974 case BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14:
1419bbe5 6975 case BFD_RELOC_AARCH64_LD32_GOT_LO12_NC:
a2e1db00 6976 case BFD_RELOC_AARCH64_LD64_GOTOFF_LO15:
99ad26cb 6977 case BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15:
1419bbe5 6978 case BFD_RELOC_AARCH64_LD64_GOT_LO12_NC:
dc8008f5 6979 case BFD_RELOC_AARCH64_MOVW_GOTOFF_G0_NC:
74a1bfe1 6980 case BFD_RELOC_AARCH64_MOVW_GOTOFF_G1:
ce336788 6981 case BFD_RELOC_AARCH64_NN:
1419bbe5
WN
6982 if (htab->root.dynobj == NULL)
6983 htab->root.dynobj = abfd;
6984 if (!_bfd_elf_create_ifunc_sections (htab->root.dynobj, info))
6985 return FALSE;
6986 break;
6987 }
6988
6989 /* It is referenced by a non-shared object. */
6990 h->ref_regular = 1;
6991 h->root.non_ir_ref = 1;
6992 }
6993
a6bb11b2 6994 switch (bfd_r_type)
a06ea964 6995 {
a6bb11b2 6996 case BFD_RELOC_AARCH64_NN:
a06ea964
NC
6997
6998 /* We don't need to handle relocs into sections not going into
6999 the "real" output. */
7000 if ((sec->flags & SEC_ALLOC) == 0)
7001 break;
7002
7003 if (h != NULL)
7004 {
0e1862bb 7005 if (!bfd_link_pic (info))
a06ea964
NC
7006 h->non_got_ref = 1;
7007
7008 h->plt.refcount += 1;
7009 h->pointer_equality_needed = 1;
7010 }
7011
7012 /* No need to do anything if we're not creating a shared
7013 object. */
0e1862bb 7014 if (! bfd_link_pic (info))
a06ea964
NC
7015 break;
7016
7017 {
7018 struct elf_dyn_relocs *p;
7019 struct elf_dyn_relocs **head;
7020
7021 /* We must copy these reloc types into the output file.
7022 Create a reloc section in dynobj and make room for
7023 this reloc. */
7024 if (sreloc == NULL)
7025 {
7026 if (htab->root.dynobj == NULL)
7027 htab->root.dynobj = abfd;
7028
7029 sreloc = _bfd_elf_make_dynamic_reloc_section
0608afa7 7030 (sec, htab->root.dynobj, LOG_FILE_ALIGN, abfd, /*rela? */ TRUE);
a06ea964
NC
7031
7032 if (sreloc == NULL)
7033 return FALSE;
7034 }
7035
7036 /* If this is a global symbol, we count the number of
7037 relocations we need for this symbol. */
7038 if (h != NULL)
7039 {
cec5225b
YZ
7040 struct elf_aarch64_link_hash_entry *eh;
7041 eh = (struct elf_aarch64_link_hash_entry *) h;
a06ea964
NC
7042 head = &eh->dyn_relocs;
7043 }
7044 else
7045 {
7046 /* Track dynamic relocs needed for local syms too.
7047 We really need local syms available to do this
7048 easily. Oh well. */
7049
7050 asection *s;
7051 void **vpp;
a06ea964
NC
7052
7053 isym = bfd_sym_from_r_symndx (&htab->sym_cache,
7054 abfd, r_symndx);
7055 if (isym == NULL)
7056 return FALSE;
7057
7058 s = bfd_section_from_elf_index (abfd, isym->st_shndx);
7059 if (s == NULL)
7060 s = sec;
7061
7062 /* Beware of type punned pointers vs strict aliasing
7063 rules. */
7064 vpp = &(elf_section_data (s)->local_dynrel);
7065 head = (struct elf_dyn_relocs **) vpp;
7066 }
7067
7068 p = *head;
7069 if (p == NULL || p->sec != sec)
7070 {
7071 bfd_size_type amt = sizeof *p;
7072 p = ((struct elf_dyn_relocs *)
7073 bfd_zalloc (htab->root.dynobj, amt));
7074 if (p == NULL)
7075 return FALSE;
7076 p->next = *head;
7077 *head = p;
7078 p->sec = sec;
7079 }
7080
7081 p->count += 1;
7082
7083 }
7084 break;
7085
7086 /* RR: We probably want to keep a consistency check that
7087 there are no dangling GOT_PAGE relocs. */
a6bb11b2 7088 case BFD_RELOC_AARCH64_ADR_GOT_PAGE:
7bcccb57 7089 case BFD_RELOC_AARCH64_GOT_LD_PREL19:
7018c030 7090 case BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14:
7bcccb57 7091 case BFD_RELOC_AARCH64_LD32_GOT_LO12_NC:
a2e1db00 7092 case BFD_RELOC_AARCH64_LD64_GOTOFF_LO15:
99ad26cb 7093 case BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15:
7bcccb57 7094 case BFD_RELOC_AARCH64_LD64_GOT_LO12_NC:
dc8008f5 7095 case BFD_RELOC_AARCH64_MOVW_GOTOFF_G0_NC:
74a1bfe1 7096 case BFD_RELOC_AARCH64_MOVW_GOTOFF_G1:
7bcccb57
MS
7097 case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12_NC:
7098 case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21:
389b8029 7099 case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21:
7bcccb57
MS
7100 case BFD_RELOC_AARCH64_TLSDESC_LD32_LO12_NC:
7101 case BFD_RELOC_AARCH64_TLSDESC_LD64_LO12_NC:
1ada945d 7102 case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19:
a6bb11b2 7103 case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC:
7bcccb57 7104 case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21:
3c12b054 7105 case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21:
7ba7cfe4 7106 case BFD_RELOC_AARCH64_TLSGD_MOVW_G0_NC:
94facae3 7107 case BFD_RELOC_AARCH64_TLSGD_MOVW_G1:
a6bb11b2 7108 case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21:
a6bb11b2 7109 case BFD_RELOC_AARCH64_TLSIE_LD32_GOTTPREL_LO12_NC:
7bcccb57 7110 case BFD_RELOC_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC:
043bf05a 7111 case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19:
3b957e5b
RL
7112 case BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G0_NC:
7113 case BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G1:
73f925cc 7114 case BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC:
f69e4920 7115 case BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21:
77a69ff8 7116 case BFD_RELOC_AARCH64_TLSLD_ADR_PREL21:
b7a944fe
RL
7117 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1:
7118 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1_NC:
7119 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G2:
a06ea964
NC
7120 {
7121 unsigned got_type;
7122 unsigned old_got_type;
7123
a6bb11b2 7124 got_type = aarch64_reloc_got_type (bfd_r_type);
a06ea964
NC
7125
7126 if (h)
7127 {
7128 h->got.refcount += 1;
cec5225b 7129 old_got_type = elf_aarch64_hash_entry (h)->got_type;
a06ea964
NC
7130 }
7131 else
7132 {
7133 struct elf_aarch64_local_symbol *locals;
7134
cec5225b 7135 if (!elfNN_aarch64_allocate_local_symbols
a06ea964
NC
7136 (abfd, symtab_hdr->sh_info))
7137 return FALSE;
7138
cec5225b 7139 locals = elf_aarch64_locals (abfd);
a06ea964
NC
7140 BFD_ASSERT (r_symndx < symtab_hdr->sh_info);
7141 locals[r_symndx].got_refcount += 1;
7142 old_got_type = locals[r_symndx].got_type;
7143 }
7144
7145 /* If a variable is accessed with both general dynamic TLS
7146 methods, two slots may be created. */
7147 if (GOT_TLS_GD_ANY_P (old_got_type) && GOT_TLS_GD_ANY_P (got_type))
7148 got_type |= old_got_type;
7149
7150 /* We will already have issued an error message if there
7151 is a TLS/non-TLS mismatch, based on the symbol type.
7152 So just combine any TLS types needed. */
7153 if (old_got_type != GOT_UNKNOWN && old_got_type != GOT_NORMAL
7154 && got_type != GOT_NORMAL)
7155 got_type |= old_got_type;
7156
7157 /* If the symbol is accessed by both IE and GD methods, we
7158 are able to relax. Turn off the GD flag, without
7159 messing up with any other kind of TLS types that may be
7160 involved. */
7161 if ((got_type & GOT_TLS_IE) && GOT_TLS_GD_ANY_P (got_type))
7162 got_type &= ~ (GOT_TLSDESC_GD | GOT_TLS_GD);
7163
7164 if (old_got_type != got_type)
7165 {
7166 if (h != NULL)
cec5225b 7167 elf_aarch64_hash_entry (h)->got_type = got_type;
a06ea964
NC
7168 else
7169 {
7170 struct elf_aarch64_local_symbol *locals;
cec5225b 7171 locals = elf_aarch64_locals (abfd);
a06ea964
NC
7172 BFD_ASSERT (r_symndx < symtab_hdr->sh_info);
7173 locals[r_symndx].got_type = got_type;
7174 }
7175 }
7176
cc0efaa8
MS
7177 if (htab->root.dynobj == NULL)
7178 htab->root.dynobj = abfd;
7179 if (! aarch64_elf_create_got_section (htab->root.dynobj, info))
7180 return FALSE;
a06ea964
NC
7181 break;
7182 }
7183
614b09ce
JW
7184 case BFD_RELOC_AARCH64_MOVW_G0_NC:
7185 case BFD_RELOC_AARCH64_MOVW_G1_NC:
7186 case BFD_RELOC_AARCH64_MOVW_G2_NC:
7187 case BFD_RELOC_AARCH64_MOVW_G3:
0e1862bb 7188 if (bfd_link_pic (info))
614b09ce
JW
7189 {
7190 int howto_index = bfd_r_type - BFD_RELOC_AARCH64_RELOC_START;
7191 (*_bfd_error_handler)
7192 (_("%B: relocation %s against `%s' can not be used when making "
7193 "a shared object; recompile with -fPIC"),
7194 abfd, elfNN_aarch64_howto_table[howto_index].name,
7195 (h) ? h->root.root.string : "a local symbol");
7196 bfd_set_error (bfd_error_bad_value);
7197 return FALSE;
7198 }
7199
a6bb11b2
YZ
7200 case BFD_RELOC_AARCH64_ADR_HI21_NC_PCREL:
7201 case BFD_RELOC_AARCH64_ADR_HI21_PCREL:
7202 case BFD_RELOC_AARCH64_ADR_LO21_PCREL:
0e1862bb 7203 if (h != NULL && bfd_link_executable (info))
a06ea964
NC
7204 {
7205 /* If this reloc is in a read-only section, we might
7206 need a copy reloc. We can't check reliably at this
7207 stage whether the section is read-only, as input
7208 sections have not yet been mapped to output sections.
7209 Tentatively set the flag for now, and correct in
7210 adjust_dynamic_symbol. */
7211 h->non_got_ref = 1;
7212 h->plt.refcount += 1;
7213 h->pointer_equality_needed = 1;
7214 }
7215 /* FIXME:: RR need to handle these in shared libraries
7216 and essentially bomb out as these being non-PIC
7217 relocations in shared libraries. */
7218 break;
7219
a6bb11b2
YZ
7220 case BFD_RELOC_AARCH64_CALL26:
7221 case BFD_RELOC_AARCH64_JUMP26:
a06ea964
NC
7222 /* If this is a local symbol then we resolve it
7223 directly without creating a PLT entry. */
7224 if (h == NULL)
7225 continue;
7226
7227 h->needs_plt = 1;
1419bbe5
WN
7228 if (h->plt.refcount <= 0)
7229 h->plt.refcount = 1;
7230 else
7231 h->plt.refcount += 1;
a06ea964 7232 break;
a6bb11b2
YZ
7233
7234 default:
7235 break;
a06ea964
NC
7236 }
7237 }
a6bb11b2 7238
a06ea964
NC
7239 return TRUE;
7240}
7241
7242/* Treat mapping symbols as special target symbols. */
7243
7244static bfd_boolean
cec5225b 7245elfNN_aarch64_is_target_special_symbol (bfd *abfd ATTRIBUTE_UNUSED,
a06ea964
NC
7246 asymbol *sym)
7247{
7248 return bfd_is_aarch64_special_symbol_name (sym->name,
7249 BFD_AARCH64_SPECIAL_SYM_TYPE_ANY);
7250}
7251
7252/* This is a copy of elf_find_function () from elf.c except that
7253 AArch64 mapping symbols are ignored when looking for function names. */
7254
7255static bfd_boolean
7256aarch64_elf_find_function (bfd *abfd ATTRIBUTE_UNUSED,
a06ea964 7257 asymbol **symbols,
fb167eb2 7258 asection *section,
a06ea964
NC
7259 bfd_vma offset,
7260 const char **filename_ptr,
7261 const char **functionname_ptr)
7262{
7263 const char *filename = NULL;
7264 asymbol *func = NULL;
7265 bfd_vma low_func = 0;
7266 asymbol **p;
7267
7268 for (p = symbols; *p != NULL; p++)
7269 {
7270 elf_symbol_type *q;
7271
7272 q = (elf_symbol_type *) * p;
7273
7274 switch (ELF_ST_TYPE (q->internal_elf_sym.st_info))
7275 {
7276 default:
7277 break;
7278 case STT_FILE:
7279 filename = bfd_asymbol_name (&q->symbol);
7280 break;
7281 case STT_FUNC:
7282 case STT_NOTYPE:
7283 /* Skip mapping symbols. */
7284 if ((q->symbol.flags & BSF_LOCAL)
7285 && (bfd_is_aarch64_special_symbol_name
7286 (q->symbol.name, BFD_AARCH64_SPECIAL_SYM_TYPE_ANY)))
7287 continue;
7288 /* Fall through. */
7289 if (bfd_get_section (&q->symbol) == section
7290 && q->symbol.value >= low_func && q->symbol.value <= offset)
7291 {
7292 func = (asymbol *) q;
7293 low_func = q->symbol.value;
7294 }
7295 break;
7296 }
7297 }
7298
7299 if (func == NULL)
7300 return FALSE;
7301
7302 if (filename_ptr)
7303 *filename_ptr = filename;
7304 if (functionname_ptr)
7305 *functionname_ptr = bfd_asymbol_name (func);
7306
7307 return TRUE;
7308}
7309
7310
7311/* Find the nearest line to a particular section and offset, for error
7312 reporting. This code is a duplicate of the code in elf.c, except
7313 that it uses aarch64_elf_find_function. */
7314
7315static bfd_boolean
cec5225b 7316elfNN_aarch64_find_nearest_line (bfd *abfd,
a06ea964 7317 asymbol **symbols,
fb167eb2 7318 asection *section,
a06ea964
NC
7319 bfd_vma offset,
7320 const char **filename_ptr,
7321 const char **functionname_ptr,
fb167eb2
AM
7322 unsigned int *line_ptr,
7323 unsigned int *discriminator_ptr)
a06ea964
NC
7324{
7325 bfd_boolean found = FALSE;
7326
fb167eb2 7327 if (_bfd_dwarf2_find_nearest_line (abfd, symbols, NULL, section, offset,
a06ea964 7328 filename_ptr, functionname_ptr,
fb167eb2
AM
7329 line_ptr, discriminator_ptr,
7330 dwarf_debug_sections, 0,
a06ea964
NC
7331 &elf_tdata (abfd)->dwarf2_find_line_info))
7332 {
7333 if (!*functionname_ptr)
fb167eb2 7334 aarch64_elf_find_function (abfd, symbols, section, offset,
a06ea964
NC
7335 *filename_ptr ? NULL : filename_ptr,
7336 functionname_ptr);
7337
7338 return TRUE;
7339 }
7340
fb167eb2
AM
7341 /* Skip _bfd_dwarf1_find_nearest_line since no known AArch64
7342 toolchain uses DWARF1. */
7343
a06ea964
NC
7344 if (!_bfd_stab_section_find_nearest_line (abfd, symbols, section, offset,
7345 &found, filename_ptr,
7346 functionname_ptr, line_ptr,
7347 &elf_tdata (abfd)->line_info))
7348 return FALSE;
7349
7350 if (found && (*functionname_ptr || *line_ptr))
7351 return TRUE;
7352
7353 if (symbols == NULL)
7354 return FALSE;
7355
fb167eb2 7356 if (!aarch64_elf_find_function (abfd, symbols, section, offset,
a06ea964
NC
7357 filename_ptr, functionname_ptr))
7358 return FALSE;
7359
7360 *line_ptr = 0;
7361 return TRUE;
7362}
7363
7364static bfd_boolean
cec5225b 7365elfNN_aarch64_find_inliner_info (bfd *abfd,
a06ea964
NC
7366 const char **filename_ptr,
7367 const char **functionname_ptr,
7368 unsigned int *line_ptr)
7369{
7370 bfd_boolean found;
7371 found = _bfd_dwarf2_find_inliner_info
7372 (abfd, filename_ptr,
7373 functionname_ptr, line_ptr, &elf_tdata (abfd)->dwarf2_find_line_info);
7374 return found;
7375}
7376
7377
7378static void
cec5225b 7379elfNN_aarch64_post_process_headers (bfd *abfd,
1419bbe5 7380 struct bfd_link_info *link_info)
a06ea964
NC
7381{
7382 Elf_Internal_Ehdr *i_ehdrp; /* ELF file header, internal form. */
7383
7384 i_ehdrp = elf_elfheader (abfd);
a06ea964 7385 i_ehdrp->e_ident[EI_ABIVERSION] = AARCH64_ELF_ABI_VERSION;
1419bbe5 7386
78245035 7387 _bfd_elf_post_process_headers (abfd, link_info);
a06ea964
NC
7388}
7389
7390static enum elf_reloc_type_class
cec5225b 7391elfNN_aarch64_reloc_type_class (const struct bfd_link_info *info ATTRIBUTE_UNUSED,
7e612e98
AM
7392 const asection *rel_sec ATTRIBUTE_UNUSED,
7393 const Elf_Internal_Rela *rela)
a06ea964 7394{
cec5225b 7395 switch ((int) ELFNN_R_TYPE (rela->r_info))
a06ea964 7396 {
a6bb11b2 7397 case AARCH64_R (RELATIVE):
a06ea964 7398 return reloc_class_relative;
a6bb11b2 7399 case AARCH64_R (JUMP_SLOT):
a06ea964 7400 return reloc_class_plt;
a6bb11b2 7401 case AARCH64_R (COPY):
a06ea964
NC
7402 return reloc_class_copy;
7403 default:
7404 return reloc_class_normal;
7405 }
7406}
7407
a06ea964
NC
7408/* Handle an AArch64 specific section when reading an object file. This is
7409 called when bfd_section_from_shdr finds a section with an unknown
7410 type. */
7411
7412static bfd_boolean
cec5225b 7413elfNN_aarch64_section_from_shdr (bfd *abfd,
a06ea964
NC
7414 Elf_Internal_Shdr *hdr,
7415 const char *name, int shindex)
7416{
7417 /* There ought to be a place to keep ELF backend specific flags, but
7418 at the moment there isn't one. We just keep track of the
7419 sections by their name, instead. Fortunately, the ABI gives
7420 names for all the AArch64 specific sections, so we will probably get
7421 away with this. */
7422 switch (hdr->sh_type)
7423 {
7424 case SHT_AARCH64_ATTRIBUTES:
7425 break;
7426
7427 default:
7428 return FALSE;
7429 }
7430
7431 if (!_bfd_elf_make_section_from_shdr (abfd, hdr, name, shindex))
7432 return FALSE;
7433
7434 return TRUE;
7435}
7436
7437/* A structure used to record a list of sections, independently
7438 of the next and prev fields in the asection structure. */
7439typedef struct section_list
7440{
7441 asection *sec;
7442 struct section_list *next;
7443 struct section_list *prev;
7444}
7445section_list;
7446
7447/* Unfortunately we need to keep a list of sections for which
7448 an _aarch64_elf_section_data structure has been allocated. This
cec5225b 7449 is because it is possible for functions like elfNN_aarch64_write_section
a06ea964
NC
7450 to be called on a section which has had an elf_data_structure
7451 allocated for it (and so the used_by_bfd field is valid) but
7452 for which the AArch64 extended version of this structure - the
7453 _aarch64_elf_section_data structure - has not been allocated. */
7454static section_list *sections_with_aarch64_elf_section_data = NULL;
7455
7456static void
7457record_section_with_aarch64_elf_section_data (asection *sec)
7458{
7459 struct section_list *entry;
7460
7461 entry = bfd_malloc (sizeof (*entry));
7462 if (entry == NULL)
7463 return;
7464 entry->sec = sec;
7465 entry->next = sections_with_aarch64_elf_section_data;
7466 entry->prev = NULL;
7467 if (entry->next != NULL)
7468 entry->next->prev = entry;
7469 sections_with_aarch64_elf_section_data = entry;
7470}
7471
7472static struct section_list *
7473find_aarch64_elf_section_entry (asection *sec)
7474{
7475 struct section_list *entry;
7476 static struct section_list *last_entry = NULL;
7477
7478 /* This is a short cut for the typical case where the sections are added
7479 to the sections_with_aarch64_elf_section_data list in forward order and
7480 then looked up here in backwards order. This makes a real difference
7481 to the ld-srec/sec64k.exp linker test. */
7482 entry = sections_with_aarch64_elf_section_data;
7483 if (last_entry != NULL)
7484 {
7485 if (last_entry->sec == sec)
7486 entry = last_entry;
7487 else if (last_entry->next != NULL && last_entry->next->sec == sec)
7488 entry = last_entry->next;
7489 }
7490
7491 for (; entry; entry = entry->next)
7492 if (entry->sec == sec)
7493 break;
7494
7495 if (entry)
7496 /* Record the entry prior to this one - it is the entry we are
7497 most likely to want to locate next time. Also this way if we
7498 have been called from
7499 unrecord_section_with_aarch64_elf_section_data () we will not
7500 be caching a pointer that is about to be freed. */
7501 last_entry = entry->prev;
7502
7503 return entry;
7504}
7505
7506static void
7507unrecord_section_with_aarch64_elf_section_data (asection *sec)
7508{
7509 struct section_list *entry;
7510
7511 entry = find_aarch64_elf_section_entry (sec);
7512
7513 if (entry)
7514 {
7515 if (entry->prev != NULL)
7516 entry->prev->next = entry->next;
7517 if (entry->next != NULL)
7518 entry->next->prev = entry->prev;
7519 if (entry == sections_with_aarch64_elf_section_data)
7520 sections_with_aarch64_elf_section_data = entry->next;
7521 free (entry);
7522 }
7523}
7524
7525
7526typedef struct
7527{
7528 void *finfo;
7529 struct bfd_link_info *info;
7530 asection *sec;
7531 int sec_shndx;
7532 int (*func) (void *, const char *, Elf_Internal_Sym *,
7533 asection *, struct elf_link_hash_entry *);
7534} output_arch_syminfo;
7535
7536enum map_symbol_type
7537{
7538 AARCH64_MAP_INSN,
7539 AARCH64_MAP_DATA
7540};
7541
7542
7543/* Output a single mapping symbol. */
7544
7545static bfd_boolean
cec5225b 7546elfNN_aarch64_output_map_sym (output_arch_syminfo *osi,
a06ea964
NC
7547 enum map_symbol_type type, bfd_vma offset)
7548{
7549 static const char *names[2] = { "$x", "$d" };
7550 Elf_Internal_Sym sym;
7551
7552 sym.st_value = (osi->sec->output_section->vma
7553 + osi->sec->output_offset + offset);
7554 sym.st_size = 0;
7555 sym.st_other = 0;
7556 sym.st_info = ELF_ST_INFO (STB_LOCAL, STT_NOTYPE);
7557 sym.st_shndx = osi->sec_shndx;
7558 return osi->func (osi->finfo, names[type], &sym, osi->sec, NULL) == 1;
7559}
7560
a06ea964
NC
7561/* Output a single local symbol for a generated stub. */
7562
7563static bfd_boolean
cec5225b 7564elfNN_aarch64_output_stub_sym (output_arch_syminfo *osi, const char *name,
a06ea964
NC
7565 bfd_vma offset, bfd_vma size)
7566{
7567 Elf_Internal_Sym sym;
7568
7569 sym.st_value = (osi->sec->output_section->vma
7570 + osi->sec->output_offset + offset);
7571 sym.st_size = size;
7572 sym.st_other = 0;
7573 sym.st_info = ELF_ST_INFO (STB_LOCAL, STT_FUNC);
7574 sym.st_shndx = osi->sec_shndx;
7575 return osi->func (osi->finfo, name, &sym, osi->sec, NULL) == 1;
7576}
7577
7578static bfd_boolean
7579aarch64_map_one_stub (struct bfd_hash_entry *gen_entry, void *in_arg)
7580{
cec5225b 7581 struct elf_aarch64_stub_hash_entry *stub_entry;
a06ea964
NC
7582 asection *stub_sec;
7583 bfd_vma addr;
7584 char *stub_name;
7585 output_arch_syminfo *osi;
7586
7587 /* Massage our args to the form they really have. */
cec5225b 7588 stub_entry = (struct elf_aarch64_stub_hash_entry *) gen_entry;
a06ea964
NC
7589 osi = (output_arch_syminfo *) in_arg;
7590
7591 stub_sec = stub_entry->stub_sec;
7592
7593 /* Ensure this stub is attached to the current section being
7594 processed. */
7595 if (stub_sec != osi->sec)
7596 return TRUE;
7597
7598 addr = (bfd_vma) stub_entry->stub_offset;
7599
7600 stub_name = stub_entry->output_name;
7601
7602 switch (stub_entry->stub_type)
7603 {
7604 case aarch64_stub_adrp_branch:
cec5225b 7605 if (!elfNN_aarch64_output_stub_sym (osi, stub_name, addr,
a06ea964
NC
7606 sizeof (aarch64_adrp_branch_stub)))
7607 return FALSE;
cec5225b 7608 if (!elfNN_aarch64_output_map_sym (osi, AARCH64_MAP_INSN, addr))
a06ea964
NC
7609 return FALSE;
7610 break;
7611 case aarch64_stub_long_branch:
cec5225b 7612 if (!elfNN_aarch64_output_stub_sym
a06ea964
NC
7613 (osi, stub_name, addr, sizeof (aarch64_long_branch_stub)))
7614 return FALSE;
cec5225b 7615 if (!elfNN_aarch64_output_map_sym (osi, AARCH64_MAP_INSN, addr))
a06ea964 7616 return FALSE;
cec5225b 7617 if (!elfNN_aarch64_output_map_sym (osi, AARCH64_MAP_DATA, addr + 16))
a06ea964
NC
7618 return FALSE;
7619 break;
68fcca92
JW
7620 case aarch64_stub_erratum_835769_veneer:
7621 if (!elfNN_aarch64_output_stub_sym (osi, stub_name, addr,
7622 sizeof (aarch64_erratum_835769_stub)))
7623 return FALSE;
7624 if (!elfNN_aarch64_output_map_sym (osi, AARCH64_MAP_INSN, addr))
7625 return FALSE;
7626 break;
4106101c
MS
7627 case aarch64_stub_erratum_843419_veneer:
7628 if (!elfNN_aarch64_output_stub_sym (osi, stub_name, addr,
7629 sizeof (aarch64_erratum_843419_stub)))
7630 return FALSE;
7631 if (!elfNN_aarch64_output_map_sym (osi, AARCH64_MAP_INSN, addr))
7632 return FALSE;
7633 break;
7634
a06ea964 7635 default:
8e2fe09f 7636 abort ();
a06ea964
NC
7637 }
7638
7639 return TRUE;
7640}
7641
7642/* Output mapping symbols for linker generated sections. */
7643
7644static bfd_boolean
cec5225b 7645elfNN_aarch64_output_arch_local_syms (bfd *output_bfd,
a06ea964
NC
7646 struct bfd_link_info *info,
7647 void *finfo,
7648 int (*func) (void *, const char *,
7649 Elf_Internal_Sym *,
7650 asection *,
7651 struct elf_link_hash_entry
7652 *))
7653{
7654 output_arch_syminfo osi;
cec5225b 7655 struct elf_aarch64_link_hash_table *htab;
a06ea964 7656
cec5225b 7657 htab = elf_aarch64_hash_table (info);
a06ea964
NC
7658
7659 osi.finfo = finfo;
7660 osi.info = info;
7661 osi.func = func;
7662
7663 /* Long calls stubs. */
7664 if (htab->stub_bfd && htab->stub_bfd->sections)
7665 {
7666 asection *stub_sec;
7667
7668 for (stub_sec = htab->stub_bfd->sections;
7669 stub_sec != NULL; stub_sec = stub_sec->next)
7670 {
7671 /* Ignore non-stub sections. */
7672 if (!strstr (stub_sec->name, STUB_SUFFIX))
7673 continue;
7674
7675 osi.sec = stub_sec;
7676
7677 osi.sec_shndx = _bfd_elf_section_from_bfd_section
7678 (output_bfd, osi.sec->output_section);
7679
61865519
MS
7680 /* The first instruction in a stub is always a branch. */
7681 if (!elfNN_aarch64_output_map_sym (&osi, AARCH64_MAP_INSN, 0))
7682 return FALSE;
7683
a06ea964
NC
7684 bfd_hash_traverse (&htab->stub_hash_table, aarch64_map_one_stub,
7685 &osi);
7686 }
7687 }
7688
7689 /* Finally, output mapping symbols for the PLT. */
7690 if (!htab->root.splt || htab->root.splt->size == 0)
7691 return TRUE;
7692
a06ea964
NC
7693 osi.sec_shndx = _bfd_elf_section_from_bfd_section
7694 (output_bfd, htab->root.splt->output_section);
7695 osi.sec = htab->root.splt;
7696
73524045 7697 elfNN_aarch64_output_map_sym (&osi, AARCH64_MAP_INSN, 0);
a06ea964
NC
7698
7699 return TRUE;
7700
7701}
7702
7703/* Allocate target specific section data. */
7704
7705static bfd_boolean
cec5225b 7706elfNN_aarch64_new_section_hook (bfd *abfd, asection *sec)
a06ea964
NC
7707{
7708 if (!sec->used_by_bfd)
7709 {
7710 _aarch64_elf_section_data *sdata;
7711 bfd_size_type amt = sizeof (*sdata);
7712
7713 sdata = bfd_zalloc (abfd, amt);
7714 if (sdata == NULL)
7715 return FALSE;
7716 sec->used_by_bfd = sdata;
7717 }
7718
7719 record_section_with_aarch64_elf_section_data (sec);
7720
7721 return _bfd_elf_new_section_hook (abfd, sec);
7722}
7723
7724
7725static void
7726unrecord_section_via_map_over_sections (bfd *abfd ATTRIBUTE_UNUSED,
7727 asection *sec,
7728 void *ignore ATTRIBUTE_UNUSED)
7729{
7730 unrecord_section_with_aarch64_elf_section_data (sec);
7731}
7732
7733static bfd_boolean
cec5225b 7734elfNN_aarch64_close_and_cleanup (bfd *abfd)
a06ea964
NC
7735{
7736 if (abfd->sections)
7737 bfd_map_over_sections (abfd,
7738 unrecord_section_via_map_over_sections, NULL);
7739
7740 return _bfd_elf_close_and_cleanup (abfd);
7741}
7742
7743static bfd_boolean
cec5225b 7744elfNN_aarch64_bfd_free_cached_info (bfd *abfd)
a06ea964
NC
7745{
7746 if (abfd->sections)
7747 bfd_map_over_sections (abfd,
7748 unrecord_section_via_map_over_sections, NULL);
7749
7750 return _bfd_free_cached_info (abfd);
7751}
7752
a06ea964
NC
7753/* Create dynamic sections. This is different from the ARM backend in that
7754 the got, plt, gotplt and their relocation sections are all created in the
7755 standard part of the bfd elf backend. */
7756
7757static bfd_boolean
cec5225b 7758elfNN_aarch64_create_dynamic_sections (bfd *dynobj,
a06ea964
NC
7759 struct bfd_link_info *info)
7760{
cec5225b 7761 struct elf_aarch64_link_hash_table *htab;
cc0efaa8
MS
7762
7763 /* We need to create .got section. */
7764 if (!aarch64_elf_create_got_section (dynobj, info))
7765 return FALSE;
a06ea964
NC
7766
7767 if (!_bfd_elf_create_dynamic_sections (dynobj, info))
7768 return FALSE;
7769
cec5225b 7770 htab = elf_aarch64_hash_table (info);
a06ea964 7771 htab->sdynbss = bfd_get_linker_section (dynobj, ".dynbss");
0e1862bb 7772 if (!bfd_link_pic (info))
a06ea964
NC
7773 htab->srelbss = bfd_get_linker_section (dynobj, ".rela.bss");
7774
0e1862bb 7775 if (!htab->sdynbss || (!bfd_link_pic (info) && !htab->srelbss))
a06ea964
NC
7776 abort ();
7777
a06ea964
NC
7778 return TRUE;
7779}
7780
7781
7782/* Allocate space in .plt, .got and associated reloc sections for
7783 dynamic relocs. */
7784
7785static bfd_boolean
cec5225b 7786elfNN_aarch64_allocate_dynrelocs (struct elf_link_hash_entry *h, void *inf)
a06ea964
NC
7787{
7788 struct bfd_link_info *info;
cec5225b
YZ
7789 struct elf_aarch64_link_hash_table *htab;
7790 struct elf_aarch64_link_hash_entry *eh;
a06ea964
NC
7791 struct elf_dyn_relocs *p;
7792
7793 /* An example of a bfd_link_hash_indirect symbol is versioned
7794 symbol. For example: __gxx_personality_v0(bfd_link_hash_indirect)
7795 -> __gxx_personality_v0(bfd_link_hash_defined)
7796
7797 There is no need to process bfd_link_hash_indirect symbols here
7798 because we will also be presented with the concrete instance of
cec5225b 7799 the symbol and elfNN_aarch64_copy_indirect_symbol () will have been
a06ea964
NC
7800 called to copy all relevant data from the generic to the concrete
7801 symbol instance.
7802 */
7803 if (h->root.type == bfd_link_hash_indirect)
7804 return TRUE;
7805
7806 if (h->root.type == bfd_link_hash_warning)
7807 h = (struct elf_link_hash_entry *) h->root.u.i.link;
7808
7809 info = (struct bfd_link_info *) inf;
cec5225b 7810 htab = elf_aarch64_hash_table (info);
a06ea964 7811
1419bbe5
WN
7812 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle it
7813 here if it is defined and referenced in a non-shared object. */
7814 if (h->type == STT_GNU_IFUNC
7815 && h->def_regular)
7816 return TRUE;
7817 else if (htab->root.dynamic_sections_created && h->plt.refcount > 0)
a06ea964
NC
7818 {
7819 /* Make sure this symbol is output as a dynamic symbol.
7820 Undefined weak syms won't yet be marked as dynamic. */
7821 if (h->dynindx == -1 && !h->forced_local)
7822 {
7823 if (!bfd_elf_link_record_dynamic_symbol (info, h))
7824 return FALSE;
7825 }
7826
0e1862bb 7827 if (bfd_link_pic (info) || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h))
a06ea964
NC
7828 {
7829 asection *s = htab->root.splt;
7830
7831 /* If this is the first .plt entry, make room for the special
7832 first entry. */
7833 if (s->size == 0)
7834 s->size += htab->plt_header_size;
7835
7836 h->plt.offset = s->size;
7837
7838 /* If this symbol is not defined in a regular file, and we are
7839 not generating a shared library, then set the symbol to this
7840 location in the .plt. This is required to make function
7841 pointers compare as equal between the normal executable and
7842 the shared library. */
0e1862bb 7843 if (!bfd_link_pic (info) && !h->def_regular)
a06ea964
NC
7844 {
7845 h->root.u.def.section = s;
7846 h->root.u.def.value = h->plt.offset;
7847 }
7848
7849 /* Make room for this entry. For now we only create the
7850 small model PLT entries. We later need to find a way
7851 of relaxing into these from the large model PLT entries. */
7852 s->size += PLT_SMALL_ENTRY_SIZE;
7853
7854 /* We also need to make an entry in the .got.plt section, which
7855 will be placed in the .got section by the linker script. */
7856 htab->root.sgotplt->size += GOT_ENTRY_SIZE;
7857
7858 /* We also need to make an entry in the .rela.plt section. */
7859 htab->root.srelplt->size += RELOC_SIZE (htab);
7860
7861 /* We need to ensure that all GOT entries that serve the PLT
7862 are consecutive with the special GOT slots [0] [1] and
7863 [2]. Any addtional relocations, such as
7864 R_AARCH64_TLSDESC, must be placed after the PLT related
7865 entries. We abuse the reloc_count such that during
7866 sizing we adjust reloc_count to indicate the number of
7867 PLT related reserved entries. In subsequent phases when
7868 filling in the contents of the reloc entries, PLT related
7869 entries are placed by computing their PLT index (0
7870 .. reloc_count). While other none PLT relocs are placed
7871 at the slot indicated by reloc_count and reloc_count is
7872 updated. */
7873
7874 htab->root.srelplt->reloc_count++;
7875 }
7876 else
7877 {
7878 h->plt.offset = (bfd_vma) - 1;
7879 h->needs_plt = 0;
7880 }
7881 }
7882 else
7883 {
7884 h->plt.offset = (bfd_vma) - 1;
7885 h->needs_plt = 0;
7886 }
7887
cec5225b 7888 eh = (struct elf_aarch64_link_hash_entry *) h;
a06ea964
NC
7889 eh->tlsdesc_got_jump_table_offset = (bfd_vma) - 1;
7890
7891 if (h->got.refcount > 0)
7892 {
7893 bfd_boolean dyn;
cec5225b 7894 unsigned got_type = elf_aarch64_hash_entry (h)->got_type;
a06ea964
NC
7895
7896 h->got.offset = (bfd_vma) - 1;
7897
7898 dyn = htab->root.dynamic_sections_created;
7899
7900 /* Make sure this symbol is output as a dynamic symbol.
7901 Undefined weak syms won't yet be marked as dynamic. */
7902 if (dyn && h->dynindx == -1 && !h->forced_local)
7903 {
7904 if (!bfd_elf_link_record_dynamic_symbol (info, h))
7905 return FALSE;
7906 }
7907
7908 if (got_type == GOT_UNKNOWN)
7909 {
7910 }
7911 else if (got_type == GOT_NORMAL)
7912 {
7913 h->got.offset = htab->root.sgot->size;
7914 htab->root.sgot->size += GOT_ENTRY_SIZE;
7915 if ((ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
7916 || h->root.type != bfd_link_hash_undefweak)
0e1862bb 7917 && (bfd_link_pic (info)
a06ea964
NC
7918 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, 0, h)))
7919 {
7920 htab->root.srelgot->size += RELOC_SIZE (htab);
7921 }
7922 }
7923 else
7924 {
7925 int indx;
7926 if (got_type & GOT_TLSDESC_GD)
7927 {
7928 eh->tlsdesc_got_jump_table_offset =
7929 (htab->root.sgotplt->size
7930 - aarch64_compute_jump_table_size (htab));
7931 htab->root.sgotplt->size += GOT_ENTRY_SIZE * 2;
7932 h->got.offset = (bfd_vma) - 2;
7933 }
7934
7935 if (got_type & GOT_TLS_GD)
7936 {
7937 h->got.offset = htab->root.sgot->size;
7938 htab->root.sgot->size += GOT_ENTRY_SIZE * 2;
7939 }
7940
7941 if (got_type & GOT_TLS_IE)
7942 {
7943 h->got.offset = htab->root.sgot->size;
7944 htab->root.sgot->size += GOT_ENTRY_SIZE;
7945 }
7946
7947 indx = h && h->dynindx != -1 ? h->dynindx : 0;
7948 if ((ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
7949 || h->root.type != bfd_link_hash_undefweak)
0e1862bb 7950 && (bfd_link_pic (info)
a06ea964
NC
7951 || indx != 0
7952 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, 0, h)))
7953 {
7954 if (got_type & GOT_TLSDESC_GD)
7955 {
7956 htab->root.srelplt->size += RELOC_SIZE (htab);
7957 /* Note reloc_count not incremented here! We have
7958 already adjusted reloc_count for this relocation
7959 type. */
7960
7961 /* TLSDESC PLT is now needed, but not yet determined. */
7962 htab->tlsdesc_plt = (bfd_vma) - 1;
7963 }
7964
7965 if (got_type & GOT_TLS_GD)
7966 htab->root.srelgot->size += RELOC_SIZE (htab) * 2;
7967
7968 if (got_type & GOT_TLS_IE)
7969 htab->root.srelgot->size += RELOC_SIZE (htab);
7970 }
7971 }
7972 }
7973 else
7974 {
7975 h->got.offset = (bfd_vma) - 1;
7976 }
7977
7978 if (eh->dyn_relocs == NULL)
7979 return TRUE;
7980
7981 /* In the shared -Bsymbolic case, discard space allocated for
7982 dynamic pc-relative relocs against symbols which turn out to be
7983 defined in regular objects. For the normal shared case, discard
7984 space for pc-relative relocs that have become local due to symbol
7985 visibility changes. */
7986
0e1862bb 7987 if (bfd_link_pic (info))
a06ea964
NC
7988 {
7989 /* Relocs that use pc_count are those that appear on a call
7990 insn, or certain REL relocs that can generated via assembly.
7991 We want calls to protected symbols to resolve directly to the
7992 function rather than going via the plt. If people want
7993 function pointer comparisons to work as expected then they
7994 should avoid writing weird assembly. */
7995 if (SYMBOL_CALLS_LOCAL (info, h))
7996 {
7997 struct elf_dyn_relocs **pp;
7998
7999 for (pp = &eh->dyn_relocs; (p = *pp) != NULL;)
8000 {
8001 p->count -= p->pc_count;
8002 p->pc_count = 0;
8003 if (p->count == 0)
8004 *pp = p->next;
8005 else
8006 pp = &p->next;
8007 }
8008 }
8009
8010 /* Also discard relocs on undefined weak syms with non-default
8011 visibility. */
8012 if (eh->dyn_relocs != NULL && h->root.type == bfd_link_hash_undefweak)
8013 {
8014 if (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT)
8015 eh->dyn_relocs = NULL;
8016
8017 /* Make sure undefined weak symbols are output as a dynamic
8018 symbol in PIEs. */
8019 else if (h->dynindx == -1
8020 && !h->forced_local
8021 && !bfd_elf_link_record_dynamic_symbol (info, h))
8022 return FALSE;
8023 }
8024
8025 }
8026 else if (ELIMINATE_COPY_RELOCS)
8027 {
8028 /* For the non-shared case, discard space for relocs against
8029 symbols which turn out to need copy relocs or are not
8030 dynamic. */
8031
8032 if (!h->non_got_ref
8033 && ((h->def_dynamic
8034 && !h->def_regular)
8035 || (htab->root.dynamic_sections_created
8036 && (h->root.type == bfd_link_hash_undefweak
8037 || h->root.type == bfd_link_hash_undefined))))
8038 {
8039 /* Make sure this symbol is output as a dynamic symbol.
8040 Undefined weak syms won't yet be marked as dynamic. */
8041 if (h->dynindx == -1
8042 && !h->forced_local
8043 && !bfd_elf_link_record_dynamic_symbol (info, h))
8044 return FALSE;
8045
8046 /* If that succeeded, we know we'll be keeping all the
8047 relocs. */
8048 if (h->dynindx != -1)
8049 goto keep;
8050 }
8051
8052 eh->dyn_relocs = NULL;
8053
8054 keep:;
8055 }
8056
8057 /* Finally, allocate space. */
8058 for (p = eh->dyn_relocs; p != NULL; p = p->next)
8059 {
8060 asection *sreloc;
8061
8062 sreloc = elf_section_data (p->sec)->sreloc;
8063
8064 BFD_ASSERT (sreloc != NULL);
8065
8066 sreloc->size += p->count * RELOC_SIZE (htab);
8067 }
8068
8069 return TRUE;
8070}
8071
1419bbe5
WN
8072/* Allocate space in .plt, .got and associated reloc sections for
8073 ifunc dynamic relocs. */
8074
8075static bfd_boolean
8076elfNN_aarch64_allocate_ifunc_dynrelocs (struct elf_link_hash_entry *h,
8077 void *inf)
8078{
8079 struct bfd_link_info *info;
8080 struct elf_aarch64_link_hash_table *htab;
8081 struct elf_aarch64_link_hash_entry *eh;
8082
8083 /* An example of a bfd_link_hash_indirect symbol is versioned
8084 symbol. For example: __gxx_personality_v0(bfd_link_hash_indirect)
8085 -> __gxx_personality_v0(bfd_link_hash_defined)
8086
8087 There is no need to process bfd_link_hash_indirect symbols here
8088 because we will also be presented with the concrete instance of
8089 the symbol and elfNN_aarch64_copy_indirect_symbol () will have been
8090 called to copy all relevant data from the generic to the concrete
8091 symbol instance.
8092 */
8093 if (h->root.type == bfd_link_hash_indirect)
8094 return TRUE;
8095
8096 if (h->root.type == bfd_link_hash_warning)
8097 h = (struct elf_link_hash_entry *) h->root.u.i.link;
8098
8099 info = (struct bfd_link_info *) inf;
8100 htab = elf_aarch64_hash_table (info);
8101
8102 eh = (struct elf_aarch64_link_hash_entry *) h;
8103
8104 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle it
8105 here if it is defined and referenced in a non-shared object. */
8106 if (h->type == STT_GNU_IFUNC
8107 && h->def_regular)
8108 return _bfd_elf_allocate_ifunc_dyn_relocs (info, h,
8109 &eh->dyn_relocs,
8110 htab->plt_entry_size,
8111 htab->plt_header_size,
8112 GOT_ENTRY_SIZE);
8113 return TRUE;
8114}
8115
8116/* Allocate space in .plt, .got and associated reloc sections for
8117 local dynamic relocs. */
8118
8119static bfd_boolean
8120elfNN_aarch64_allocate_local_dynrelocs (void **slot, void *inf)
8121{
8122 struct elf_link_hash_entry *h
8123 = (struct elf_link_hash_entry *) *slot;
8124
8125 if (h->type != STT_GNU_IFUNC
8126 || !h->def_regular
8127 || !h->ref_regular
8128 || !h->forced_local
8129 || h->root.type != bfd_link_hash_defined)
8130 abort ();
8131
8132 return elfNN_aarch64_allocate_dynrelocs (h, inf);
8133}
8134
8135/* Allocate space in .plt, .got and associated reloc sections for
8136 local ifunc dynamic relocs. */
8137
8138static bfd_boolean
8139elfNN_aarch64_allocate_local_ifunc_dynrelocs (void **slot, void *inf)
8140{
8141 struct elf_link_hash_entry *h
8142 = (struct elf_link_hash_entry *) *slot;
8143
8144 if (h->type != STT_GNU_IFUNC
8145 || !h->def_regular
8146 || !h->ref_regular
8147 || !h->forced_local
8148 || h->root.type != bfd_link_hash_defined)
8149 abort ();
8150
8151 return elfNN_aarch64_allocate_ifunc_dynrelocs (h, inf);
8152}
a06ea964 8153
c2170589
JW
8154/* Find any dynamic relocs that apply to read-only sections. */
8155
8156static bfd_boolean
8157aarch64_readonly_dynrelocs (struct elf_link_hash_entry * h, void * inf)
8158{
8159 struct elf_aarch64_link_hash_entry * eh;
8160 struct elf_dyn_relocs * p;
8161
8162 eh = (struct elf_aarch64_link_hash_entry *) h;
8163 for (p = eh->dyn_relocs; p != NULL; p = p->next)
8164 {
8165 asection *s = p->sec;
8166
8167 if (s != NULL && (s->flags & SEC_READONLY) != 0)
8168 {
8169 struct bfd_link_info *info = (struct bfd_link_info *) inf;
8170
8171 info->flags |= DF_TEXTREL;
8172
8173 /* Not an error, just cut short the traversal. */
8174 return FALSE;
8175 }
8176 }
8177 return TRUE;
8178}
8179
a06ea964
NC
8180/* This is the most important function of all . Innocuosly named
8181 though ! */
8182static bfd_boolean
cec5225b 8183elfNN_aarch64_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
a06ea964
NC
8184 struct bfd_link_info *info)
8185{
cec5225b 8186 struct elf_aarch64_link_hash_table *htab;
a06ea964
NC
8187 bfd *dynobj;
8188 asection *s;
8189 bfd_boolean relocs;
8190 bfd *ibfd;
8191
cec5225b 8192 htab = elf_aarch64_hash_table ((info));
a06ea964
NC
8193 dynobj = htab->root.dynobj;
8194
8195 BFD_ASSERT (dynobj != NULL);
8196
8197 if (htab->root.dynamic_sections_created)
8198 {
9b8b325a 8199 if (bfd_link_executable (info) && !info->nointerp)
a06ea964
NC
8200 {
8201 s = bfd_get_linker_section (dynobj, ".interp");
8202 if (s == NULL)
8203 abort ();
8204 s->size = sizeof ELF_DYNAMIC_INTERPRETER;
8205 s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
8206 }
8207 }
8208
8209 /* Set up .got offsets for local syms, and space for local dynamic
8210 relocs. */
c72f2fb2 8211 for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link.next)
a06ea964
NC
8212 {
8213 struct elf_aarch64_local_symbol *locals = NULL;
8214 Elf_Internal_Shdr *symtab_hdr;
8215 asection *srel;
8216 unsigned int i;
8217
8218 if (!is_aarch64_elf (ibfd))
8219 continue;
8220
8221 for (s = ibfd->sections; s != NULL; s = s->next)
8222 {
8223 struct elf_dyn_relocs *p;
8224
8225 for (p = (struct elf_dyn_relocs *)
8226 (elf_section_data (s)->local_dynrel); p != NULL; p = p->next)
8227 {
8228 if (!bfd_is_abs_section (p->sec)
8229 && bfd_is_abs_section (p->sec->output_section))
8230 {
8231 /* Input section has been discarded, either because
8232 it is a copy of a linkonce section or due to
8233 linker script /DISCARD/, so we'll be discarding
8234 the relocs too. */
8235 }
8236 else if (p->count != 0)
8237 {
8238 srel = elf_section_data (p->sec)->sreloc;
8239 srel->size += p->count * RELOC_SIZE (htab);
8240 if ((p->sec->output_section->flags & SEC_READONLY) != 0)
8241 info->flags |= DF_TEXTREL;
8242 }
8243 }
8244 }
8245
cec5225b 8246 locals = elf_aarch64_locals (ibfd);
a06ea964
NC
8247 if (!locals)
8248 continue;
8249
8250 symtab_hdr = &elf_symtab_hdr (ibfd);
8251 srel = htab->root.srelgot;
8252 for (i = 0; i < symtab_hdr->sh_info; i++)
8253 {
8254 locals[i].got_offset = (bfd_vma) - 1;
8255 locals[i].tlsdesc_got_jump_table_offset = (bfd_vma) - 1;
8256 if (locals[i].got_refcount > 0)
8257 {
8258 unsigned got_type = locals[i].got_type;
8259 if (got_type & GOT_TLSDESC_GD)
8260 {
8261 locals[i].tlsdesc_got_jump_table_offset =
8262 (htab->root.sgotplt->size
8263 - aarch64_compute_jump_table_size (htab));
8264 htab->root.sgotplt->size += GOT_ENTRY_SIZE * 2;
8265 locals[i].got_offset = (bfd_vma) - 2;
8266 }
8267
8268 if (got_type & GOT_TLS_GD)
8269 {
8270 locals[i].got_offset = htab->root.sgot->size;
8271 htab->root.sgot->size += GOT_ENTRY_SIZE * 2;
8272 }
8273
b53b1bed
JW
8274 if (got_type & GOT_TLS_IE
8275 || got_type & GOT_NORMAL)
a06ea964
NC
8276 {
8277 locals[i].got_offset = htab->root.sgot->size;
8278 htab->root.sgot->size += GOT_ENTRY_SIZE;
8279 }
8280
8281 if (got_type == GOT_UNKNOWN)
8282 {
8283 }
8284
0e1862bb 8285 if (bfd_link_pic (info))
a06ea964
NC
8286 {
8287 if (got_type & GOT_TLSDESC_GD)
8288 {
8289 htab->root.srelplt->size += RELOC_SIZE (htab);
8290 /* Note RELOC_COUNT not incremented here! */
8291 htab->tlsdesc_plt = (bfd_vma) - 1;
8292 }
8293
8294 if (got_type & GOT_TLS_GD)
8295 htab->root.srelgot->size += RELOC_SIZE (htab) * 2;
8296
b53b1bed
JW
8297 if (got_type & GOT_TLS_IE
8298 || got_type & GOT_NORMAL)
a06ea964
NC
8299 htab->root.srelgot->size += RELOC_SIZE (htab);
8300 }
8301 }
8302 else
8303 {
8304 locals[i].got_refcount = (bfd_vma) - 1;
8305 }
8306 }
8307 }
8308
8309
8310 /* Allocate global sym .plt and .got entries, and space for global
8311 sym dynamic relocs. */
cec5225b 8312 elf_link_hash_traverse (&htab->root, elfNN_aarch64_allocate_dynrelocs,
a06ea964
NC
8313 info);
8314
1419bbe5
WN
8315 /* Allocate global ifunc sym .plt and .got entries, and space for global
8316 ifunc sym dynamic relocs. */
8317 elf_link_hash_traverse (&htab->root, elfNN_aarch64_allocate_ifunc_dynrelocs,
8318 info);
8319
8320 /* Allocate .plt and .got entries, and space for local symbols. */
8321 htab_traverse (htab->loc_hash_table,
8322 elfNN_aarch64_allocate_local_dynrelocs,
8323 info);
8324
8325 /* Allocate .plt and .got entries, and space for local ifunc symbols. */
8326 htab_traverse (htab->loc_hash_table,
8327 elfNN_aarch64_allocate_local_ifunc_dynrelocs,
8328 info);
a06ea964
NC
8329
8330 /* For every jump slot reserved in the sgotplt, reloc_count is
8331 incremented. However, when we reserve space for TLS descriptors,
8332 it's not incremented, so in order to compute the space reserved
8333 for them, it suffices to multiply the reloc count by the jump
8334 slot size. */
8335
8336 if (htab->root.srelplt)
8847944f 8337 htab->sgotplt_jump_table_size = aarch64_compute_jump_table_size (htab);
a06ea964
NC
8338
8339 if (htab->tlsdesc_plt)
8340 {
8341 if (htab->root.splt->size == 0)
8342 htab->root.splt->size += PLT_ENTRY_SIZE;
8343
8344 htab->tlsdesc_plt = htab->root.splt->size;
8345 htab->root.splt->size += PLT_TLSDESC_ENTRY_SIZE;
8346
8347 /* If we're not using lazy TLS relocations, don't generate the
8348 GOT entry required. */
8349 if (!(info->flags & DF_BIND_NOW))
8350 {
8351 htab->dt_tlsdesc_got = htab->root.sgot->size;
8352 htab->root.sgot->size += GOT_ENTRY_SIZE;
8353 }
8354 }
8355
68fcca92 8356 /* Init mapping symbols information to use later to distingush between
4106101c
MS
8357 code and data while scanning for errata. */
8358 if (htab->fix_erratum_835769 || htab->fix_erratum_843419)
68fcca92
JW
8359 for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link.next)
8360 {
8361 if (!is_aarch64_elf (ibfd))
8362 continue;
8363 bfd_elfNN_aarch64_init_maps (ibfd);
8364 }
8365
a06ea964
NC
8366 /* We now have determined the sizes of the various dynamic sections.
8367 Allocate memory for them. */
8368 relocs = FALSE;
8369 for (s = dynobj->sections; s != NULL; s = s->next)
8370 {
8371 if ((s->flags & SEC_LINKER_CREATED) == 0)
8372 continue;
8373
8374 if (s == htab->root.splt
8375 || s == htab->root.sgot
8376 || s == htab->root.sgotplt
8377 || s == htab->root.iplt
8378 || s == htab->root.igotplt || s == htab->sdynbss)
8379 {
8380 /* Strip this section if we don't need it; see the
8381 comment below. */
8382 }
8383 else if (CONST_STRNEQ (bfd_get_section_name (dynobj, s), ".rela"))
8384 {
8385 if (s->size != 0 && s != htab->root.srelplt)
8386 relocs = TRUE;
8387
8388 /* We use the reloc_count field as a counter if we need
8389 to copy relocs into the output file. */
8390 if (s != htab->root.srelplt)
8391 s->reloc_count = 0;
8392 }
8393 else
8394 {
8395 /* It's not one of our sections, so don't allocate space. */
8396 continue;
8397 }
8398
8399 if (s->size == 0)
8400 {
8401 /* If we don't need this section, strip it from the
8402 output file. This is mostly to handle .rela.bss and
8403 .rela.plt. We must create both sections in
8404 create_dynamic_sections, because they must be created
8405 before the linker maps input sections to output
8406 sections. The linker does that before
8407 adjust_dynamic_symbol is called, and it is that
8408 function which decides whether anything needs to go
8409 into these sections. */
8410
8411 s->flags |= SEC_EXCLUDE;
8412 continue;
8413 }
8414
8415 if ((s->flags & SEC_HAS_CONTENTS) == 0)
8416 continue;
8417
8418 /* Allocate memory for the section contents. We use bfd_zalloc
8419 here in case unused entries are not reclaimed before the
8420 section's contents are written out. This should not happen,
8421 but this way if it does, we get a R_AARCH64_NONE reloc instead
8422 of garbage. */
8423 s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->size);
8424 if (s->contents == NULL)
8425 return FALSE;
8426 }
8427
8428 if (htab->root.dynamic_sections_created)
8429 {
8430 /* Add some entries to the .dynamic section. We fill in the
cec5225b 8431 values later, in elfNN_aarch64_finish_dynamic_sections, but we
a06ea964
NC
8432 must add the entries now so that we get the correct size for
8433 the .dynamic section. The DT_DEBUG entry is filled in by the
8434 dynamic linker and used by the debugger. */
8435#define add_dynamic_entry(TAG, VAL) \
8436 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
8437
0e1862bb 8438 if (bfd_link_executable (info))
a06ea964
NC
8439 {
8440 if (!add_dynamic_entry (DT_DEBUG, 0))
8441 return FALSE;
8442 }
8443
8444 if (htab->root.splt->size != 0)
8445 {
8446 if (!add_dynamic_entry (DT_PLTGOT, 0)
8447 || !add_dynamic_entry (DT_PLTRELSZ, 0)
8448 || !add_dynamic_entry (DT_PLTREL, DT_RELA)
8449 || !add_dynamic_entry (DT_JMPREL, 0))
8450 return FALSE;
8451
8452 if (htab->tlsdesc_plt
8453 && (!add_dynamic_entry (DT_TLSDESC_PLT, 0)
8454 || !add_dynamic_entry (DT_TLSDESC_GOT, 0)))
8455 return FALSE;
8456 }
8457
8458 if (relocs)
8459 {
8460 if (!add_dynamic_entry (DT_RELA, 0)
8461 || !add_dynamic_entry (DT_RELASZ, 0)
8462 || !add_dynamic_entry (DT_RELAENT, RELOC_SIZE (htab)))
8463 return FALSE;
8464
8465 /* If any dynamic relocs apply to a read-only section,
8466 then we need a DT_TEXTREL entry. */
c2170589
JW
8467 if ((info->flags & DF_TEXTREL) == 0)
8468 elf_link_hash_traverse (& htab->root, aarch64_readonly_dynrelocs,
8469 info);
8470
a06ea964
NC
8471 if ((info->flags & DF_TEXTREL) != 0)
8472 {
8473 if (!add_dynamic_entry (DT_TEXTREL, 0))
8474 return FALSE;
8475 }
8476 }
8477 }
8478#undef add_dynamic_entry
8479
8480 return TRUE;
a06ea964
NC
8481}
8482
8483static inline void
caed7120
YZ
8484elf_aarch64_update_plt_entry (bfd *output_bfd,
8485 bfd_reloc_code_real_type r_type,
8486 bfd_byte *plt_entry, bfd_vma value)
a06ea964 8487{
caed7120
YZ
8488 reloc_howto_type *howto = elfNN_aarch64_howto_from_bfd_reloc (r_type);
8489
8490 _bfd_aarch64_elf_put_addend (output_bfd, plt_entry, r_type, howto, value);
a06ea964
NC
8491}
8492
8493static void
cec5225b
YZ
8494elfNN_aarch64_create_small_pltn_entry (struct elf_link_hash_entry *h,
8495 struct elf_aarch64_link_hash_table
1419bbe5
WN
8496 *htab, bfd *output_bfd,
8497 struct bfd_link_info *info)
a06ea964
NC
8498{
8499 bfd_byte *plt_entry;
8500 bfd_vma plt_index;
8501 bfd_vma got_offset;
8502 bfd_vma gotplt_entry_address;
8503 bfd_vma plt_entry_address;
8504 Elf_Internal_Rela rela;
8505 bfd_byte *loc;
1419bbe5
WN
8506 asection *plt, *gotplt, *relplt;
8507
8508 /* When building a static executable, use .iplt, .igot.plt and
8509 .rela.iplt sections for STT_GNU_IFUNC symbols. */
8510 if (htab->root.splt != NULL)
8511 {
8512 plt = htab->root.splt;
8513 gotplt = htab->root.sgotplt;
8514 relplt = htab->root.srelplt;
8515 }
8516 else
8517 {
8518 plt = htab->root.iplt;
8519 gotplt = htab->root.igotplt;
8520 relplt = htab->root.irelplt;
8521 }
8522
8523 /* Get the index in the procedure linkage table which
8524 corresponds to this symbol. This is the index of this symbol
8525 in all the symbols for which we are making plt entries. The
8526 first entry in the procedure linkage table is reserved.
a06ea964 8527
1419bbe5
WN
8528 Get the offset into the .got table of the entry that
8529 corresponds to this function. Each .got entry is GOT_ENTRY_SIZE
8530 bytes. The first three are reserved for the dynamic linker.
692e2b8b 8531
1419bbe5
WN
8532 For static executables, we don't reserve anything. */
8533
8534 if (plt == htab->root.splt)
8535 {
8536 plt_index = (h->plt.offset - htab->plt_header_size) / htab->plt_entry_size;
8537 got_offset = (plt_index + 3) * GOT_ENTRY_SIZE;
8538 }
8539 else
8540 {
8541 plt_index = h->plt.offset / htab->plt_entry_size;
8542 got_offset = plt_index * GOT_ENTRY_SIZE;
8543 }
8544
8545 plt_entry = plt->contents + h->plt.offset;
8546 plt_entry_address = plt->output_section->vma
f44a1f8e 8547 + plt->output_offset + h->plt.offset;
1419bbe5
WN
8548 gotplt_entry_address = gotplt->output_section->vma +
8549 gotplt->output_offset + got_offset;
a06ea964
NC
8550
8551 /* Copy in the boiler-plate for the PLTn entry. */
cec5225b 8552 memcpy (plt_entry, elfNN_aarch64_small_plt_entry, PLT_SMALL_ENTRY_SIZE);
a06ea964
NC
8553
8554 /* Fill in the top 21 bits for this: ADRP x16, PLT_GOT + n * 8.
8555 ADRP: ((PG(S+A)-PG(P)) >> 12) & 0x1fffff */
caed7120
YZ
8556 elf_aarch64_update_plt_entry (output_bfd, BFD_RELOC_AARCH64_ADR_HI21_PCREL,
8557 plt_entry,
8558 PG (gotplt_entry_address) -
8559 PG (plt_entry_address));
a06ea964
NC
8560
8561 /* Fill in the lo12 bits for the load from the pltgot. */
caed7120
YZ
8562 elf_aarch64_update_plt_entry (output_bfd, BFD_RELOC_AARCH64_LDSTNN_LO12,
8563 plt_entry + 4,
8564 PG_OFFSET (gotplt_entry_address));
a06ea964 8565
9aff4b7a 8566 /* Fill in the lo12 bits for the add from the pltgot entry. */
caed7120
YZ
8567 elf_aarch64_update_plt_entry (output_bfd, BFD_RELOC_AARCH64_ADD_LO12,
8568 plt_entry + 8,
8569 PG_OFFSET (gotplt_entry_address));
a06ea964
NC
8570
8571 /* All the GOTPLT Entries are essentially initialized to PLT0. */
cec5225b 8572 bfd_put_NN (output_bfd,
1419bbe5
WN
8573 plt->output_section->vma + plt->output_offset,
8574 gotplt->contents + got_offset);
a06ea964 8575
a06ea964 8576 rela.r_offset = gotplt_entry_address;
1419bbe5
WN
8577
8578 if (h->dynindx == -1
0e1862bb 8579 || ((bfd_link_executable (info)
1419bbe5
WN
8580 || ELF_ST_VISIBILITY (h->other) != STV_DEFAULT)
8581 && h->def_regular
8582 && h->type == STT_GNU_IFUNC))
8583 {
8584 /* If an STT_GNU_IFUNC symbol is locally defined, generate
8585 R_AARCH64_IRELATIVE instead of R_AARCH64_JUMP_SLOT. */
8586 rela.r_info = ELFNN_R_INFO (0, AARCH64_R (IRELATIVE));
8587 rela.r_addend = (h->root.u.def.value
8588 + h->root.u.def.section->output_section->vma
8589 + h->root.u.def.section->output_offset);
8590 }
8591 else
8592 {
8593 /* Fill in the entry in the .rela.plt section. */
8594 rela.r_info = ELFNN_R_INFO (h->dynindx, AARCH64_R (JUMP_SLOT));
8595 rela.r_addend = 0;
8596 }
a06ea964
NC
8597
8598 /* Compute the relocation entry to used based on PLT index and do
8599 not adjust reloc_count. The reloc_count has already been adjusted
8600 to account for this entry. */
1419bbe5 8601 loc = relplt->contents + plt_index * RELOC_SIZE (htab);
cec5225b 8602 bfd_elfNN_swap_reloca_out (output_bfd, &rela, loc);
a06ea964
NC
8603}
8604
8605/* Size sections even though they're not dynamic. We use it to setup
8606 _TLS_MODULE_BASE_, if needed. */
8607
8608static bfd_boolean
cec5225b 8609elfNN_aarch64_always_size_sections (bfd *output_bfd,
a06ea964
NC
8610 struct bfd_link_info *info)
8611{
8612 asection *tls_sec;
8613
0e1862bb 8614 if (bfd_link_relocatable (info))
a06ea964
NC
8615 return TRUE;
8616
8617 tls_sec = elf_hash_table (info)->tls_sec;
8618
8619 if (tls_sec)
8620 {
8621 struct elf_link_hash_entry *tlsbase;
8622
8623 tlsbase = elf_link_hash_lookup (elf_hash_table (info),
8624 "_TLS_MODULE_BASE_", TRUE, TRUE, FALSE);
8625
8626 if (tlsbase)
8627 {
8628 struct bfd_link_hash_entry *h = NULL;
8629 const struct elf_backend_data *bed =
8630 get_elf_backend_data (output_bfd);
8631
8632 if (!(_bfd_generic_link_add_one_symbol
8633 (info, output_bfd, "_TLS_MODULE_BASE_", BSF_LOCAL,
8634 tls_sec, 0, NULL, FALSE, bed->collect, &h)))
8635 return FALSE;
8636
8637 tlsbase->type = STT_TLS;
8638 tlsbase = (struct elf_link_hash_entry *) h;
8639 tlsbase->def_regular = 1;
8640 tlsbase->other = STV_HIDDEN;
8641 (*bed->elf_backend_hide_symbol) (info, tlsbase, TRUE);
8642 }
8643 }
8644
8645 return TRUE;
8646}
8647
8648/* Finish up dynamic symbol handling. We set the contents of various
8649 dynamic sections here. */
8650static bfd_boolean
cec5225b 8651elfNN_aarch64_finish_dynamic_symbol (bfd *output_bfd,
a06ea964
NC
8652 struct bfd_link_info *info,
8653 struct elf_link_hash_entry *h,
8654 Elf_Internal_Sym *sym)
8655{
cec5225b
YZ
8656 struct elf_aarch64_link_hash_table *htab;
8657 htab = elf_aarch64_hash_table (info);
a06ea964
NC
8658
8659 if (h->plt.offset != (bfd_vma) - 1)
8660 {
1419bbe5
WN
8661 asection *plt, *gotplt, *relplt;
8662
a06ea964
NC
8663 /* This symbol has an entry in the procedure linkage table. Set
8664 it up. */
8665
1419bbe5
WN
8666 /* When building a static executable, use .iplt, .igot.plt and
8667 .rela.iplt sections for STT_GNU_IFUNC symbols. */
8668 if (htab->root.splt != NULL)
8669 {
8670 plt = htab->root.splt;
8671 gotplt = htab->root.sgotplt;
8672 relplt = htab->root.srelplt;
8673 }
8674 else
8675 {
8676 plt = htab->root.iplt;
8677 gotplt = htab->root.igotplt;
8678 relplt = htab->root.irelplt;
8679 }
8680
8681 /* This symbol has an entry in the procedure linkage table. Set
8682 it up. */
8683 if ((h->dynindx == -1
0e1862bb 8684 && !((h->forced_local || bfd_link_executable (info))
1419bbe5
WN
8685 && h->def_regular
8686 && h->type == STT_GNU_IFUNC))
8687 || plt == NULL
8688 || gotplt == NULL
8689 || relplt == NULL)
a06ea964
NC
8690 abort ();
8691
1419bbe5 8692 elfNN_aarch64_create_small_pltn_entry (h, htab, output_bfd, info);
a06ea964
NC
8693 if (!h->def_regular)
8694 {
8695 /* Mark the symbol as undefined, rather than as defined in
46b87d49 8696 the .plt section. */
a06ea964 8697 sym->st_shndx = SHN_UNDEF;
46b87d49
WN
8698 /* If the symbol is weak we need to clear the value.
8699 Otherwise, the PLT entry would provide a definition for
8700 the symbol even if the symbol wasn't defined anywhere,
8701 and so the symbol would never be NULL. Leave the value if
8702 there were any relocations where pointer equality matters
8703 (this is a clue for the dynamic linker, to make function
8704 pointer comparisons work between an application and shared
8705 library). */
8706 if (!h->ref_regular_nonweak || !h->pointer_equality_needed)
8707 sym->st_value = 0;
a06ea964
NC
8708 }
8709 }
8710
8711 if (h->got.offset != (bfd_vma) - 1
cec5225b 8712 && elf_aarch64_hash_entry (h)->got_type == GOT_NORMAL)
a06ea964
NC
8713 {
8714 Elf_Internal_Rela rela;
8715 bfd_byte *loc;
8716
8717 /* This symbol has an entry in the global offset table. Set it
8718 up. */
8719 if (htab->root.sgot == NULL || htab->root.srelgot == NULL)
8720 abort ();
8721
8722 rela.r_offset = (htab->root.sgot->output_section->vma
8723 + htab->root.sgot->output_offset
8724 + (h->got.offset & ~(bfd_vma) 1));
8725
49206388
WN
8726 if (h->def_regular
8727 && h->type == STT_GNU_IFUNC)
8728 {
0e1862bb 8729 if (bfd_link_pic (info))
49206388
WN
8730 {
8731 /* Generate R_AARCH64_GLOB_DAT. */
8732 goto do_glob_dat;
8733 }
8734 else
8735 {
8736 asection *plt;
8737
8738 if (!h->pointer_equality_needed)
8739 abort ();
8740
8741 /* For non-shared object, we can't use .got.plt, which
8742 contains the real function address if we need pointer
8743 equality. We load the GOT entry with the PLT entry. */
8744 plt = htab->root.splt ? htab->root.splt : htab->root.iplt;
8745 bfd_put_NN (output_bfd, (plt->output_section->vma
8746 + plt->output_offset
8747 + h->plt.offset),
8748 htab->root.sgot->contents
8749 + (h->got.offset & ~(bfd_vma) 1));
8750 return TRUE;
8751 }
8752 }
0e1862bb 8753 else if (bfd_link_pic (info) && SYMBOL_REFERENCES_LOCAL (info, h))
a06ea964
NC
8754 {
8755 if (!h->def_regular)
8756 return FALSE;
8757
8758 BFD_ASSERT ((h->got.offset & 1) != 0);
a6bb11b2 8759 rela.r_info = ELFNN_R_INFO (0, AARCH64_R (RELATIVE));
a06ea964
NC
8760 rela.r_addend = (h->root.u.def.value
8761 + h->root.u.def.section->output_section->vma
8762 + h->root.u.def.section->output_offset);
8763 }
8764 else
8765 {
49206388 8766do_glob_dat:
a06ea964 8767 BFD_ASSERT ((h->got.offset & 1) == 0);
cec5225b 8768 bfd_put_NN (output_bfd, (bfd_vma) 0,
a06ea964 8769 htab->root.sgot->contents + h->got.offset);
a6bb11b2 8770 rela.r_info = ELFNN_R_INFO (h->dynindx, AARCH64_R (GLOB_DAT));
a06ea964
NC
8771 rela.r_addend = 0;
8772 }
8773
8774 loc = htab->root.srelgot->contents;
8775 loc += htab->root.srelgot->reloc_count++ * RELOC_SIZE (htab);
cec5225b 8776 bfd_elfNN_swap_reloca_out (output_bfd, &rela, loc);
a06ea964
NC
8777 }
8778
8779 if (h->needs_copy)
8780 {
8781 Elf_Internal_Rela rela;
8782 bfd_byte *loc;
8783
8784 /* This symbol needs a copy reloc. Set it up. */
8785
8786 if (h->dynindx == -1
8787 || (h->root.type != bfd_link_hash_defined
8788 && h->root.type != bfd_link_hash_defweak)
8789 || htab->srelbss == NULL)
8790 abort ();
8791
8792 rela.r_offset = (h->root.u.def.value
8793 + h->root.u.def.section->output_section->vma
8794 + h->root.u.def.section->output_offset);
a6bb11b2 8795 rela.r_info = ELFNN_R_INFO (h->dynindx, AARCH64_R (COPY));
a06ea964
NC
8796 rela.r_addend = 0;
8797 loc = htab->srelbss->contents;
8798 loc += htab->srelbss->reloc_count++ * RELOC_SIZE (htab);
cec5225b 8799 bfd_elfNN_swap_reloca_out (output_bfd, &rela, loc);
a06ea964
NC
8800 }
8801
8802 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. SYM may
8803 be NULL for local symbols. */
8804 if (sym != NULL
9637f6ef 8805 && (h == elf_hash_table (info)->hdynamic
a06ea964
NC
8806 || h == elf_hash_table (info)->hgot))
8807 sym->st_shndx = SHN_ABS;
8808
8809 return TRUE;
8810}
8811
1419bbe5
WN
8812/* Finish up local dynamic symbol handling. We set the contents of
8813 various dynamic sections here. */
8814
8815static bfd_boolean
8816elfNN_aarch64_finish_local_dynamic_symbol (void **slot, void *inf)
8817{
8818 struct elf_link_hash_entry *h
8819 = (struct elf_link_hash_entry *) *slot;
8820 struct bfd_link_info *info
8821 = (struct bfd_link_info *) inf;
8822
8823 return elfNN_aarch64_finish_dynamic_symbol (info->output_bfd,
8824 info, h, NULL);
8825}
8826
a06ea964 8827static void
cec5225b
YZ
8828elfNN_aarch64_init_small_plt0_entry (bfd *output_bfd ATTRIBUTE_UNUSED,
8829 struct elf_aarch64_link_hash_table
a06ea964
NC
8830 *htab)
8831{
8832 /* Fill in PLT0. Fixme:RR Note this doesn't distinguish between
8833 small and large plts and at the minute just generates
8834 the small PLT. */
8835
cec5225b 8836 /* PLT0 of the small PLT looks like this in ELF64 -
a06ea964
NC
8837 stp x16, x30, [sp, #-16]! // Save the reloc and lr on stack.
8838 adrp x16, PLT_GOT + 16 // Get the page base of the GOTPLT
8839 ldr x17, [x16, #:lo12:PLT_GOT+16] // Load the address of the
8840 // symbol resolver
8841 add x16, x16, #:lo12:PLT_GOT+16 // Load the lo12 bits of the
8842 // GOTPLT entry for this.
8843 br x17
cec5225b
YZ
8844 PLT0 will be slightly different in ELF32 due to different got entry
8845 size.
a06ea964 8846 */
caed7120 8847 bfd_vma plt_got_2nd_ent; /* Address of GOT[2]. */
a06ea964
NC
8848 bfd_vma plt_base;
8849
8850
cec5225b 8851 memcpy (htab->root.splt->contents, elfNN_aarch64_small_plt0_entry,
a06ea964
NC
8852 PLT_ENTRY_SIZE);
8853 elf_section_data (htab->root.splt->output_section)->this_hdr.sh_entsize =
8854 PLT_ENTRY_SIZE;
8855
caed7120
YZ
8856 plt_got_2nd_ent = (htab->root.sgotplt->output_section->vma
8857 + htab->root.sgotplt->output_offset
8858 + GOT_ENTRY_SIZE * 2);
a06ea964
NC
8859
8860 plt_base = htab->root.splt->output_section->vma +
f44a1f8e 8861 htab->root.splt->output_offset;
a06ea964
NC
8862
8863 /* Fill in the top 21 bits for this: ADRP x16, PLT_GOT + n * 8.
8864 ADRP: ((PG(S+A)-PG(P)) >> 12) & 0x1fffff */
caed7120
YZ
8865 elf_aarch64_update_plt_entry (output_bfd, BFD_RELOC_AARCH64_ADR_HI21_PCREL,
8866 htab->root.splt->contents + 4,
8867 PG (plt_got_2nd_ent) - PG (plt_base + 4));
a06ea964 8868
caed7120
YZ
8869 elf_aarch64_update_plt_entry (output_bfd, BFD_RELOC_AARCH64_LDSTNN_LO12,
8870 htab->root.splt->contents + 8,
8871 PG_OFFSET (plt_got_2nd_ent));
a06ea964 8872
caed7120
YZ
8873 elf_aarch64_update_plt_entry (output_bfd, BFD_RELOC_AARCH64_ADD_LO12,
8874 htab->root.splt->contents + 12,
8875 PG_OFFSET (plt_got_2nd_ent));
a06ea964
NC
8876}
8877
8878static bfd_boolean
cec5225b 8879elfNN_aarch64_finish_dynamic_sections (bfd *output_bfd,
a06ea964
NC
8880 struct bfd_link_info *info)
8881{
cec5225b 8882 struct elf_aarch64_link_hash_table *htab;
a06ea964
NC
8883 bfd *dynobj;
8884 asection *sdyn;
8885
cec5225b 8886 htab = elf_aarch64_hash_table (info);
a06ea964
NC
8887 dynobj = htab->root.dynobj;
8888 sdyn = bfd_get_linker_section (dynobj, ".dynamic");
8889
8890 if (htab->root.dynamic_sections_created)
8891 {
cec5225b 8892 ElfNN_External_Dyn *dyncon, *dynconend;
a06ea964
NC
8893
8894 if (sdyn == NULL || htab->root.sgot == NULL)
8895 abort ();
8896
cec5225b
YZ
8897 dyncon = (ElfNN_External_Dyn *) sdyn->contents;
8898 dynconend = (ElfNN_External_Dyn *) (sdyn->contents + sdyn->size);
a06ea964
NC
8899 for (; dyncon < dynconend; dyncon++)
8900 {
8901 Elf_Internal_Dyn dyn;
8902 asection *s;
8903
cec5225b 8904 bfd_elfNN_swap_dyn_in (dynobj, dyncon, &dyn);
a06ea964
NC
8905
8906 switch (dyn.d_tag)
8907 {
8908 default:
8909 continue;
8910
8911 case DT_PLTGOT:
8912 s = htab->root.sgotplt;
8913 dyn.d_un.d_ptr = s->output_section->vma + s->output_offset;
8914 break;
8915
8916 case DT_JMPREL:
8917 dyn.d_un.d_ptr = htab->root.srelplt->output_section->vma;
8918 break;
8919
8920 case DT_PLTRELSZ:
c955de36 8921 s = htab->root.srelplt;
a06ea964
NC
8922 dyn.d_un.d_val = s->size;
8923 break;
8924
8925 case DT_RELASZ:
8926 /* The procedure linkage table relocs (DT_JMPREL) should
8927 not be included in the overall relocs (DT_RELA).
8928 Therefore, we override the DT_RELASZ entry here to
8929 make it not include the JMPREL relocs. Since the
8930 linker script arranges for .rela.plt to follow all
8931 other relocation sections, we don't have to worry
8932 about changing the DT_RELA entry. */
8933 if (htab->root.srelplt != NULL)
8934 {
c955de36 8935 s = htab->root.srelplt;
a06ea964
NC
8936 dyn.d_un.d_val -= s->size;
8937 }
8938 break;
8939
8940 case DT_TLSDESC_PLT:
8941 s = htab->root.splt;
8942 dyn.d_un.d_ptr = s->output_section->vma + s->output_offset
8943 + htab->tlsdesc_plt;
8944 break;
8945
8946 case DT_TLSDESC_GOT:
8947 s = htab->root.sgot;
8948 dyn.d_un.d_ptr = s->output_section->vma + s->output_offset
8949 + htab->dt_tlsdesc_got;
8950 break;
8951 }
8952
cec5225b 8953 bfd_elfNN_swap_dyn_out (output_bfd, &dyn, dyncon);
a06ea964
NC
8954 }
8955
8956 }
8957
8958 /* Fill in the special first entry in the procedure linkage table. */
8959 if (htab->root.splt && htab->root.splt->size > 0)
8960 {
cec5225b 8961 elfNN_aarch64_init_small_plt0_entry (output_bfd, htab);
a06ea964
NC
8962
8963 elf_section_data (htab->root.splt->output_section)->
8964 this_hdr.sh_entsize = htab->plt_entry_size;
8965
8966
8967 if (htab->tlsdesc_plt)
8968 {
cec5225b 8969 bfd_put_NN (output_bfd, (bfd_vma) 0,
a06ea964
NC
8970 htab->root.sgot->contents + htab->dt_tlsdesc_got);
8971
8972 memcpy (htab->root.splt->contents + htab->tlsdesc_plt,
cec5225b
YZ
8973 elfNN_aarch64_tlsdesc_small_plt_entry,
8974 sizeof (elfNN_aarch64_tlsdesc_small_plt_entry));
a06ea964
NC
8975
8976 {
8977 bfd_vma adrp1_addr =
8978 htab->root.splt->output_section->vma
8979 + htab->root.splt->output_offset + htab->tlsdesc_plt + 4;
8980
caed7120 8981 bfd_vma adrp2_addr = adrp1_addr + 4;
a06ea964
NC
8982
8983 bfd_vma got_addr =
8984 htab->root.sgot->output_section->vma
8985 + htab->root.sgot->output_offset;
8986
8987 bfd_vma pltgot_addr =
8988 htab->root.sgotplt->output_section->vma
8989 + htab->root.sgotplt->output_offset;
8990
8991 bfd_vma dt_tlsdesc_got = got_addr + htab->dt_tlsdesc_got;
caed7120
YZ
8992
8993 bfd_byte *plt_entry =
8994 htab->root.splt->contents + htab->tlsdesc_plt;
a06ea964
NC
8995
8996 /* adrp x2, DT_TLSDESC_GOT */
caed7120
YZ
8997 elf_aarch64_update_plt_entry (output_bfd,
8998 BFD_RELOC_AARCH64_ADR_HI21_PCREL,
8999 plt_entry + 4,
9000 (PG (dt_tlsdesc_got)
9001 - PG (adrp1_addr)));
a06ea964
NC
9002
9003 /* adrp x3, 0 */
caed7120
YZ
9004 elf_aarch64_update_plt_entry (output_bfd,
9005 BFD_RELOC_AARCH64_ADR_HI21_PCREL,
9006 plt_entry + 8,
9007 (PG (pltgot_addr)
9008 - PG (adrp2_addr)));
a06ea964
NC
9009
9010 /* ldr x2, [x2, #0] */
caed7120
YZ
9011 elf_aarch64_update_plt_entry (output_bfd,
9012 BFD_RELOC_AARCH64_LDSTNN_LO12,
9013 plt_entry + 12,
9014 PG_OFFSET (dt_tlsdesc_got));
a06ea964
NC
9015
9016 /* add x3, x3, 0 */
caed7120
YZ
9017 elf_aarch64_update_plt_entry (output_bfd,
9018 BFD_RELOC_AARCH64_ADD_LO12,
9019 plt_entry + 16,
9020 PG_OFFSET (pltgot_addr));
a06ea964
NC
9021 }
9022 }
9023 }
9024
9025 if (htab->root.sgotplt)
9026 {
9027 if (bfd_is_abs_section (htab->root.sgotplt->output_section))
9028 {
9029 (*_bfd_error_handler)
9030 (_("discarded output section: `%A'"), htab->root.sgotplt);
9031 return FALSE;
9032 }
9033
9034 /* Fill in the first three entries in the global offset table. */
9035 if (htab->root.sgotplt->size > 0)
9036 {
8db339a6
MS
9037 bfd_put_NN (output_bfd, (bfd_vma) 0, htab->root.sgotplt->contents);
9038
a06ea964 9039 /* Write GOT[1] and GOT[2], needed for the dynamic linker. */
cec5225b 9040 bfd_put_NN (output_bfd,
a06ea964
NC
9041 (bfd_vma) 0,
9042 htab->root.sgotplt->contents + GOT_ENTRY_SIZE);
cec5225b 9043 bfd_put_NN (output_bfd,
a06ea964
NC
9044 (bfd_vma) 0,
9045 htab->root.sgotplt->contents + GOT_ENTRY_SIZE * 2);
9046 }
9047
8db339a6
MS
9048 if (htab->root.sgot)
9049 {
9050 if (htab->root.sgot->size > 0)
9051 {
9052 bfd_vma addr =
9053 sdyn ? sdyn->output_section->vma + sdyn->output_offset : 0;
9054 bfd_put_NN (output_bfd, addr, htab->root.sgot->contents);
9055 }
9056 }
9057
a06ea964
NC
9058 elf_section_data (htab->root.sgotplt->output_section)->
9059 this_hdr.sh_entsize = GOT_ENTRY_SIZE;
9060 }
9061
9062 if (htab->root.sgot && htab->root.sgot->size > 0)
9063 elf_section_data (htab->root.sgot->output_section)->this_hdr.sh_entsize
9064 = GOT_ENTRY_SIZE;
9065
1419bbe5
WN
9066 /* Fill PLT and GOT entries for local STT_GNU_IFUNC symbols. */
9067 htab_traverse (htab->loc_hash_table,
9068 elfNN_aarch64_finish_local_dynamic_symbol,
9069 info);
9070
a06ea964
NC
9071 return TRUE;
9072}
9073
9074/* Return address for Ith PLT stub in section PLT, for relocation REL
9075 or (bfd_vma) -1 if it should not be included. */
9076
9077static bfd_vma
cec5225b 9078elfNN_aarch64_plt_sym_val (bfd_vma i, const asection *plt,
a06ea964
NC
9079 const arelent *rel ATTRIBUTE_UNUSED)
9080{
9081 return plt->vma + PLT_ENTRY_SIZE + i * PLT_SMALL_ENTRY_SIZE;
9082}
9083
9084
9085/* We use this so we can override certain functions
9086 (though currently we don't). */
9087
cec5225b 9088const struct elf_size_info elfNN_aarch64_size_info =
a06ea964 9089{
cec5225b
YZ
9090 sizeof (ElfNN_External_Ehdr),
9091 sizeof (ElfNN_External_Phdr),
9092 sizeof (ElfNN_External_Shdr),
9093 sizeof (ElfNN_External_Rel),
9094 sizeof (ElfNN_External_Rela),
9095 sizeof (ElfNN_External_Sym),
9096 sizeof (ElfNN_External_Dyn),
a06ea964
NC
9097 sizeof (Elf_External_Note),
9098 4, /* Hash table entry size. */
9099 1, /* Internal relocs per external relocs. */
cec5225b
YZ
9100 ARCH_SIZE, /* Arch size. */
9101 LOG_FILE_ALIGN, /* Log_file_align. */
9102 ELFCLASSNN, EV_CURRENT,
9103 bfd_elfNN_write_out_phdrs,
9104 bfd_elfNN_write_shdrs_and_ehdr,
9105 bfd_elfNN_checksum_contents,
9106 bfd_elfNN_write_relocs,
9107 bfd_elfNN_swap_symbol_in,
9108 bfd_elfNN_swap_symbol_out,
9109 bfd_elfNN_slurp_reloc_table,
9110 bfd_elfNN_slurp_symbol_table,
9111 bfd_elfNN_swap_dyn_in,
9112 bfd_elfNN_swap_dyn_out,
9113 bfd_elfNN_swap_reloc_in,
9114 bfd_elfNN_swap_reloc_out,
9115 bfd_elfNN_swap_reloca_in,
9116 bfd_elfNN_swap_reloca_out
a06ea964
NC
9117};
9118
9119#define ELF_ARCH bfd_arch_aarch64
9120#define ELF_MACHINE_CODE EM_AARCH64
9121#define ELF_MAXPAGESIZE 0x10000
9122#define ELF_MINPAGESIZE 0x1000
9123#define ELF_COMMONPAGESIZE 0x1000
9124
cec5225b
YZ
9125#define bfd_elfNN_close_and_cleanup \
9126 elfNN_aarch64_close_and_cleanup
a06ea964 9127
cec5225b
YZ
9128#define bfd_elfNN_bfd_free_cached_info \
9129 elfNN_aarch64_bfd_free_cached_info
a06ea964 9130
cec5225b
YZ
9131#define bfd_elfNN_bfd_is_target_special_symbol \
9132 elfNN_aarch64_is_target_special_symbol
a06ea964 9133
cec5225b
YZ
9134#define bfd_elfNN_bfd_link_hash_table_create \
9135 elfNN_aarch64_link_hash_table_create
a06ea964 9136
cec5225b
YZ
9137#define bfd_elfNN_bfd_merge_private_bfd_data \
9138 elfNN_aarch64_merge_private_bfd_data
a06ea964 9139
cec5225b
YZ
9140#define bfd_elfNN_bfd_print_private_bfd_data \
9141 elfNN_aarch64_print_private_bfd_data
a06ea964 9142
cec5225b
YZ
9143#define bfd_elfNN_bfd_reloc_type_lookup \
9144 elfNN_aarch64_reloc_type_lookup
a06ea964 9145
cec5225b
YZ
9146#define bfd_elfNN_bfd_reloc_name_lookup \
9147 elfNN_aarch64_reloc_name_lookup
a06ea964 9148
cec5225b
YZ
9149#define bfd_elfNN_bfd_set_private_flags \
9150 elfNN_aarch64_set_private_flags
a06ea964 9151
cec5225b
YZ
9152#define bfd_elfNN_find_inliner_info \
9153 elfNN_aarch64_find_inliner_info
a06ea964 9154
cec5225b
YZ
9155#define bfd_elfNN_find_nearest_line \
9156 elfNN_aarch64_find_nearest_line
a06ea964 9157
cec5225b
YZ
9158#define bfd_elfNN_mkobject \
9159 elfNN_aarch64_mkobject
a06ea964 9160
cec5225b
YZ
9161#define bfd_elfNN_new_section_hook \
9162 elfNN_aarch64_new_section_hook
a06ea964
NC
9163
9164#define elf_backend_adjust_dynamic_symbol \
cec5225b 9165 elfNN_aarch64_adjust_dynamic_symbol
a06ea964
NC
9166
9167#define elf_backend_always_size_sections \
cec5225b 9168 elfNN_aarch64_always_size_sections
a06ea964
NC
9169
9170#define elf_backend_check_relocs \
cec5225b 9171 elfNN_aarch64_check_relocs
a06ea964
NC
9172
9173#define elf_backend_copy_indirect_symbol \
cec5225b 9174 elfNN_aarch64_copy_indirect_symbol
a06ea964
NC
9175
9176/* Create .dynbss, and .rela.bss sections in DYNOBJ, and set up shortcuts
9177 to them in our hash. */
9178#define elf_backend_create_dynamic_sections \
cec5225b 9179 elfNN_aarch64_create_dynamic_sections
a06ea964
NC
9180
9181#define elf_backend_init_index_section \
9182 _bfd_elf_init_2_index_sections
9183
a06ea964 9184#define elf_backend_finish_dynamic_sections \
cec5225b 9185 elfNN_aarch64_finish_dynamic_sections
a06ea964
NC
9186
9187#define elf_backend_finish_dynamic_symbol \
cec5225b 9188 elfNN_aarch64_finish_dynamic_symbol
a06ea964
NC
9189
9190#define elf_backend_gc_sweep_hook \
cec5225b 9191 elfNN_aarch64_gc_sweep_hook
a06ea964
NC
9192
9193#define elf_backend_object_p \
cec5225b 9194 elfNN_aarch64_object_p
a06ea964
NC
9195
9196#define elf_backend_output_arch_local_syms \
cec5225b 9197 elfNN_aarch64_output_arch_local_syms
a06ea964
NC
9198
9199#define elf_backend_plt_sym_val \
cec5225b 9200 elfNN_aarch64_plt_sym_val
a06ea964
NC
9201
9202#define elf_backend_post_process_headers \
cec5225b 9203 elfNN_aarch64_post_process_headers
a06ea964
NC
9204
9205#define elf_backend_relocate_section \
cec5225b 9206 elfNN_aarch64_relocate_section
a06ea964
NC
9207
9208#define elf_backend_reloc_type_class \
cec5225b 9209 elfNN_aarch64_reloc_type_class
a06ea964 9210
a06ea964 9211#define elf_backend_section_from_shdr \
cec5225b 9212 elfNN_aarch64_section_from_shdr
a06ea964
NC
9213
9214#define elf_backend_size_dynamic_sections \
cec5225b 9215 elfNN_aarch64_size_dynamic_sections
a06ea964
NC
9216
9217#define elf_backend_size_info \
cec5225b 9218 elfNN_aarch64_size_info
a06ea964 9219
68fcca92
JW
9220#define elf_backend_write_section \
9221 elfNN_aarch64_write_section
9222
a06ea964 9223#define elf_backend_can_refcount 1
59c108f7 9224#define elf_backend_can_gc_sections 1
a06ea964
NC
9225#define elf_backend_plt_readonly 1
9226#define elf_backend_want_got_plt 1
9227#define elf_backend_want_plt_sym 0
9228#define elf_backend_may_use_rel_p 0
9229#define elf_backend_may_use_rela_p 1
9230#define elf_backend_default_use_rela_p 1
2e0488d3 9231#define elf_backend_rela_normal 1
a06ea964 9232#define elf_backend_got_header_size (GOT_ENTRY_SIZE * 3)
c495064d 9233#define elf_backend_default_execstack 0
32f573bc 9234#define elf_backend_extern_protected_data 1
a06ea964
NC
9235
9236#undef elf_backend_obj_attrs_section
9237#define elf_backend_obj_attrs_section ".ARM.attributes"
9238
cec5225b 9239#include "elfNN-target.h"
This page took 0.716794 seconds and 4 git commands to generate.