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