1 /* AArch64-specific support for NN-bit ELF.
2 Copyright (C) 2009-2019 Free Software Foundation, Inc.
3 Contributed by ARM Ltd.
5 This file is part of BFD, the Binary File Descriptor library.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; see the file COPYING3. If not,
19 see <http://www.gnu.org/licenses/>. */
21 /* Notes on implementation:
23 Thread Local Store (TLS)
27 The implementation currently supports both traditional TLS and TLS
28 descriptors, but only general dynamic (GD).
30 For traditional TLS the assembler will present us with code
31 fragments of the form:
34 R_AARCH64_TLSGD_ADR_PAGE21(foo)
35 add x0, :tlsgd_lo12:foo
36 R_AARCH64_TLSGD_ADD_LO12_NC(foo)
40 For TLS descriptors the assembler will present us with code
41 fragments of the form:
43 adrp x0, :tlsdesc:foo R_AARCH64_TLSDESC_ADR_PAGE21(foo)
44 ldr x1, [x0, #:tlsdesc_lo12:foo] R_AARCH64_TLSDESC_LD64_LO12(foo)
45 add x0, x0, #:tlsdesc_lo12:foo R_AARCH64_TLSDESC_ADD_LO12(foo)
47 blr x1 R_AARCH64_TLSDESC_CALL(foo)
49 The relocations R_AARCH64_TLSGD_{ADR_PREL21,ADD_LO12_NC} against foo
50 indicate that foo is thread local and should be accessed via the
51 traditional TLS mechanims.
53 The relocations R_AARCH64_TLSDESC_{ADR_PAGE21,LD64_LO12_NC,ADD_LO12_NC}
54 against foo indicate that 'foo' is thread local and should be accessed
55 via a TLS descriptor mechanism.
57 The precise instruction sequence is only relevant from the
58 perspective of linker relaxation which is currently not implemented.
60 The static linker must detect that 'foo' is a TLS object and
61 allocate a double GOT entry. The GOT entry must be created for both
62 global and local TLS symbols. Note that this is different to none
63 TLS local objects which do not need a GOT entry.
65 In the traditional TLS mechanism, the double GOT entry is used to
66 provide the tls_index structure, containing module and offset
67 entries. The static linker places the relocation R_AARCH64_TLS_DTPMOD
68 on the module entry. The loader will subsequently fixup this
69 relocation with the module identity.
71 For global traditional TLS symbols the static linker places an
72 R_AARCH64_TLS_DTPREL relocation on the offset entry. The loader
73 will subsequently fixup the offset. For local TLS symbols the static
74 linker fixes up offset.
76 In the TLS descriptor mechanism the double GOT entry is used to
77 provide the descriptor. The static linker places the relocation
78 R_AARCH64_TLSDESC on the first GOT slot. The loader will
79 subsequently fix this up.
83 The handling of TLS symbols is implemented across a number of
84 different backend functions. The following is a top level view of
85 what processing is performed where.
87 The TLS implementation maintains state information for each TLS
88 symbol. The state information for local and global symbols is kept
89 in different places. Global symbols use generic BFD structures while
90 local symbols use backend specific structures that are allocated and
91 maintained entirely by the backend.
95 elfNN_aarch64_check_relocs()
97 This function is invoked for each relocation.
99 The TLS relocations R_AARCH64_TLSGD_{ADR_PREL21,ADD_LO12_NC} and
100 R_AARCH64_TLSDESC_{ADR_PAGE21,LD64_LO12_NC,ADD_LO12_NC} are
101 spotted. One time creation of local symbol data structures are
102 created when the first local symbol is seen.
104 The reference count for a symbol is incremented. The GOT type for
105 each symbol is marked as general dynamic.
107 elfNN_aarch64_allocate_dynrelocs ()
109 For each global with positive reference count we allocate a double
110 GOT slot. For a traditional TLS symbol we allocate space for two
111 relocation entries on the GOT, for a TLS descriptor symbol we
112 allocate space for one relocation on the slot. Record the GOT offset
115 elfNN_aarch64_size_dynamic_sections ()
117 Iterate all input BFDS, look for in the local symbol data structure
118 constructed earlier for local TLS symbols and allocate them double
119 GOT slots along with space for a single GOT relocation. Update the
120 local symbol structure to record the GOT offset allocated.
122 elfNN_aarch64_relocate_section ()
124 Calls elfNN_aarch64_final_link_relocate ()
126 Emit the relevant TLS relocations against the GOT for each TLS
127 symbol. For local TLS symbols emit the GOT offset directly. The GOT
128 relocations are emitted once the first time a TLS symbol is
129 encountered. The implementation uses the LSB of the GOT offset to
130 flag that the relevant GOT relocations for a symbol have been
131 emitted. All of the TLS code that uses the GOT offset needs to take
132 care to mask out this flag bit before using the offset.
134 elfNN_aarch64_final_link_relocate ()
136 Fixup the R_AARCH64_TLSGD_{ADR_PREL21, ADD_LO12_NC} relocations. */
140 #include "libiberty.h"
144 #include "objalloc.h"
145 #include "elf/aarch64.h"
146 #include "elfxx-aarch64.h"
151 #define AARCH64_R(NAME) R_AARCH64_ ## NAME
152 #define AARCH64_R_STR(NAME) "R_AARCH64_" #NAME
153 #define HOWTO64(...) HOWTO (__VA_ARGS__)
154 #define HOWTO32(...) EMPTY_HOWTO (0)
155 #define LOG_FILE_ALIGN 3
156 #define BFD_RELOC_AARCH64_TLSDESC_LD64_LO12_NC BFD_RELOC_AARCH64_TLSDESC_LD64_LO12
160 #define AARCH64_R(NAME) R_AARCH64_P32_ ## NAME
161 #define AARCH64_R_STR(NAME) "R_AARCH64_P32_" #NAME
162 #define HOWTO64(...) EMPTY_HOWTO (0)
163 #define HOWTO32(...) HOWTO (__VA_ARGS__)
164 #define LOG_FILE_ALIGN 2
165 #define BFD_RELOC_AARCH64_TLSDESC_LD32_LO12 BFD_RELOC_AARCH64_TLSDESC_LD32_LO12_NC
166 #define R_AARCH64_P32_TLSDESC_ADD_LO12 R_AARCH64_P32_TLSDESC_ADD_LO12_NC
169 #define IS_AARCH64_TLS_RELOC(R_TYPE) \
170 ((R_TYPE) == BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC \
171 || (R_TYPE) == BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21 \
172 || (R_TYPE) == BFD_RELOC_AARCH64_TLSGD_ADR_PREL21 \
173 || (R_TYPE) == BFD_RELOC_AARCH64_TLSGD_MOVW_G0_NC \
174 || (R_TYPE) == BFD_RELOC_AARCH64_TLSGD_MOVW_G1 \
175 || (R_TYPE) == BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21 \
176 || (R_TYPE) == BFD_RELOC_AARCH64_TLSIE_LD32_GOTTPREL_LO12_NC \
177 || (R_TYPE) == BFD_RELOC_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC \
178 || (R_TYPE) == BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19 \
179 || (R_TYPE) == BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G0_NC \
180 || (R_TYPE) == BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G1 \
181 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_ADD_DTPREL_HI12 \
182 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_ADD_DTPREL_LO12 \
183 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_ADD_DTPREL_LO12_NC \
184 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC \
185 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21 \
186 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_ADR_PREL21 \
187 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_LDST16_DTPREL_LO12 \
188 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_LDST16_DTPREL_LO12_NC \
189 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_LDST32_DTPREL_LO12 \
190 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_LDST32_DTPREL_LO12_NC \
191 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_LDST64_DTPREL_LO12 \
192 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_LDST64_DTPREL_LO12_NC \
193 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_LDST8_DTPREL_LO12 \
194 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_LDST8_DTPREL_LO12_NC \
195 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G0 \
196 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G0_NC \
197 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G1 \
198 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G1_NC \
199 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G2 \
200 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_HI12 \
201 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_LO12 \
202 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_LO12_NC \
203 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_LDST16_TPREL_LO12 \
204 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_LDST16_TPREL_LO12_NC \
205 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_LDST32_TPREL_LO12 \
206 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_LDST32_TPREL_LO12_NC \
207 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_LDST64_TPREL_LO12 \
208 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_LDST64_TPREL_LO12_NC \
209 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_LDST8_TPREL_LO12 \
210 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_LDST8_TPREL_LO12_NC \
211 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0 \
212 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC \
213 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1 \
214 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1_NC \
215 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G2 \
216 || (R_TYPE) == BFD_RELOC_AARCH64_TLS_DTPMOD \
217 || (R_TYPE) == BFD_RELOC_AARCH64_TLS_DTPREL \
218 || (R_TYPE) == BFD_RELOC_AARCH64_TLS_TPREL \
219 || IS_AARCH64_TLSDESC_RELOC ((R_TYPE)))
221 #define IS_AARCH64_TLS_RELAX_RELOC(R_TYPE) \
222 ((R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_ADD \
223 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_ADD_LO12 \
224 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21 \
225 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21 \
226 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_CALL \
227 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_LD_PREL19 \
228 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_LDNN_LO12_NC \
229 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_LDR \
230 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_OFF_G0_NC \
231 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_OFF_G1 \
232 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_LDR \
233 || (R_TYPE) == BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21 \
234 || (R_TYPE) == BFD_RELOC_AARCH64_TLSGD_ADR_PREL21 \
235 || (R_TYPE) == BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC \
236 || (R_TYPE) == BFD_RELOC_AARCH64_TLSGD_MOVW_G0_NC \
237 || (R_TYPE) == BFD_RELOC_AARCH64_TLSGD_MOVW_G1 \
238 || (R_TYPE) == BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21 \
239 || (R_TYPE) == BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19 \
240 || (R_TYPE) == BFD_RELOC_AARCH64_TLSIE_LDNN_GOTTPREL_LO12_NC \
241 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC \
242 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21 \
243 || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_ADR_PREL21)
245 #define IS_AARCH64_TLSDESC_RELOC(R_TYPE) \
246 ((R_TYPE) == BFD_RELOC_AARCH64_TLSDESC \
247 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_ADD \
248 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_ADD_LO12 \
249 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21 \
250 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21 \
251 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_CALL \
252 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_LD32_LO12_NC \
253 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_LD64_LO12 \
254 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_LDR \
255 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_LD_PREL19 \
256 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_OFF_G0_NC \
257 || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_OFF_G1)
259 #define ELIMINATE_COPY_RELOCS 1
261 /* Return size of a relocation entry. HTAB is the bfd's
262 elf_aarch64_link_hash_entry. */
263 #define RELOC_SIZE(HTAB) (sizeof (ElfNN_External_Rela))
265 /* GOT Entry size - 8 bytes in ELF64 and 4 bytes in ELF32. */
266 #define GOT_ENTRY_SIZE (ARCH_SIZE / 8)
267 #define PLT_ENTRY_SIZE (32)
268 #define PLT_SMALL_ENTRY_SIZE (16)
269 #define PLT_TLSDESC_ENTRY_SIZE (32)
270 /* PLT sizes with BTI insn. */
271 #define PLT_BTI_ENTRY_SIZE (36)
272 #define PLT_BTI_SMALL_ENTRY_SIZE (20)
273 #define PLT_BTI_TLSDESC_ENTRY_SIZE (36)
274 /* PLT sizes with PAC insn. */
275 #define PLT_PAC_ENTRY_SIZE (36)
276 #define PLT_PAC_SMALL_ENTRY_SIZE (20)
277 /* PLT sizes with BTI and PAC insn. */
278 #define PLT_BTI_PAC_ENTRY_SIZE (40)
279 #define PLT_BTI_PAC_SMALL_ENTRY_SIZE (24)
281 /* Encoding of the nop instruction. */
282 #define INSN_NOP 0xd503201f
284 #define aarch64_compute_jump_table_size(htab) \
285 (((htab)->root.srelplt == NULL) ? 0 \
286 : (htab)->root.srelplt->reloc_count * GOT_ENTRY_SIZE)
288 /* The first entry in a procedure linkage table looks like this
289 if the distance between the PLTGOT and the PLT is < 4GB use
290 these PLT entries. Note that the dynamic linker gets &PLTGOT[2]
291 in x16 and needs to work out PLTGOT[1] by using an address of
292 [x16,#-GOT_ENTRY_SIZE]. */
293 static const bfd_byte elfNN_aarch64_small_plt0_entry
[PLT_ENTRY_SIZE
] =
295 0xf0, 0x7b, 0xbf, 0xa9, /* stp x16, x30, [sp, #-16]! */
296 0x10, 0x00, 0x00, 0x90, /* adrp x16, (GOT+16) */
298 0x11, 0x0A, 0x40, 0xf9, /* ldr x17, [x16, #PLT_GOT+0x10] */
299 0x10, 0x42, 0x00, 0x91, /* add x16, x16,#PLT_GOT+0x10 */
301 0x11, 0x0A, 0x40, 0xb9, /* ldr w17, [x16, #PLT_GOT+0x8] */
302 0x10, 0x22, 0x00, 0x11, /* add w16, w16,#PLT_GOT+0x8 */
304 0x20, 0x02, 0x1f, 0xd6, /* br x17 */
305 0x1f, 0x20, 0x03, 0xd5, /* nop */
306 0x1f, 0x20, 0x03, 0xd5, /* nop */
307 0x1f, 0x20, 0x03, 0xd5, /* nop */
310 static const bfd_byte elfNN_aarch64_small_plt0_bti_entry
[PLT_BTI_ENTRY_SIZE
] =
312 0x5f, 0x24, 0x03, 0xd5, /* bti c. */
313 0xf0, 0x7b, 0xbf, 0xa9, /* stp x16, x30, [sp, #-16]! */
314 0x10, 0x00, 0x00, 0x90, /* adrp x16, (GOT+16) */
316 0x11, 0x0A, 0x40, 0xf9, /* ldr x17, [x16, #PLT_GOT+0x10] */
317 0x10, 0x42, 0x00, 0x91, /* add x16, x16,#PLT_GOT+0x10 */
319 0x11, 0x0A, 0x40, 0xb9, /* ldr w17, [x16, #PLT_GOT+0x8] */
320 0x10, 0x22, 0x00, 0x11, /* add w16, w16,#PLT_GOT+0x8 */
322 0x20, 0x02, 0x1f, 0xd6, /* br x17 */
323 0x1f, 0x20, 0x03, 0xd5, /* nop */
324 0x1f, 0x20, 0x03, 0xd5, /* nop */
325 0x1f, 0x20, 0x03, 0xd5, /* nop */
328 static const bfd_byte elfNN_aarch64_small_plt0_pac_entry
[PLT_PAC_ENTRY_SIZE
] =
330 0xf0, 0x7b, 0xbf, 0xa9, /* stp x16, x30, [sp, #-16]! */
331 0x10, 0x00, 0x00, 0x90, /* adrp x16, (GOT+16) */
333 0x11, 0x0A, 0x40, 0xf9, /* ldr x17, [x16, #PLT_GOT+0x10] */
334 0x10, 0x42, 0x00, 0x91, /* add x16, x16,#PLT_GOT+0x10 */
336 0x11, 0x0A, 0x40, 0xb9, /* ldr w17, [x16, #PLT_GOT+0x8] */
337 0x10, 0x22, 0x00, 0x11, /* add w16, w16,#PLT_GOT+0x8 */
339 0x9f, 0x21, 0x03, 0xd5, /* autia1716 */
340 0x20, 0x02, 0x1f, 0xd6, /* br x17 */
341 0x1f, 0x20, 0x03, 0xd5, /* nop */
342 0x1f, 0x20, 0x03, 0xd5, /* nop */
343 0x1f, 0x20, 0x03, 0xd5, /* nop */
346 static const bfd_byte
347 elfNN_aarch64_small_plt0_bti_pac_entry
[PLT_BTI_PAC_ENTRY_SIZE
] =
349 0x5f, 0x24, 0x03, 0xd5, /* bti c. */
350 0xf0, 0x7b, 0xbf, 0xa9, /* stp x16, x30, [sp, #-16]! */
351 0x10, 0x00, 0x00, 0x90, /* adrp x16, (GOT+16) */
353 0x11, 0x0A, 0x40, 0xf9, /* ldr x17, [x16, #PLT_GOT+0x10] */
354 0x10, 0x42, 0x00, 0x91, /* add x16, x16,#PLT_GOT+0x10 */
356 0x11, 0x0A, 0x40, 0xb9, /* ldr w17, [x16, #PLT_GOT+0x8] */
357 0x10, 0x22, 0x00, 0x11, /* add w16, w16,#PLT_GOT+0x8 */
359 0x9f, 0x21, 0x03, 0xd5, /* autia1716 */
360 0x20, 0x02, 0x1f, 0xd6, /* br x17 */
361 0x1f, 0x20, 0x03, 0xd5, /* nop */
362 0x1f, 0x20, 0x03, 0xd5, /* nop */
363 0x1f, 0x20, 0x03, 0xd5, /* nop */
366 /* Per function entry in a procedure linkage table looks like this
367 if the distance between the PLTGOT and the PLT is < 4GB use
368 these PLT entries. Use BTI versions of the PLTs when enabled. */
369 static const bfd_byte elfNN_aarch64_small_plt_entry
[PLT_SMALL_ENTRY_SIZE
] =
371 0x10, 0x00, 0x00, 0x90, /* adrp x16, PLTGOT + n * 8 */
373 0x11, 0x02, 0x40, 0xf9, /* ldr x17, [x16, PLTGOT + n * 8] */
374 0x10, 0x02, 0x00, 0x91, /* add x16, x16, :lo12:PLTGOT + n * 8 */
376 0x11, 0x02, 0x40, 0xb9, /* ldr w17, [x16, PLTGOT + n * 4] */
377 0x10, 0x02, 0x00, 0x11, /* add w16, w16, :lo12:PLTGOT + n * 4 */
379 0x20, 0x02, 0x1f, 0xd6, /* br x17. */
382 static const bfd_byte
383 elfNN_aarch64_small_plt_bti_entry
[PLT_BTI_SMALL_ENTRY_SIZE
] =
385 0x5f, 0x24, 0x03, 0xd5, /* bti c. */
386 0x10, 0x00, 0x00, 0x90, /* adrp x16, PLTGOT + n * 8 */
388 0x11, 0x02, 0x40, 0xf9, /* ldr x17, [x16, PLTGOT + n * 8] */
389 0x10, 0x02, 0x00, 0x91, /* add x16, x16, :lo12:PLTGOT + n * 8 */
391 0x11, 0x02, 0x40, 0xb9, /* ldr w17, [x16, PLTGOT + n * 4] */
392 0x10, 0x02, 0x00, 0x11, /* add w16, w16, :lo12:PLTGOT + n * 4 */
394 0x20, 0x02, 0x1f, 0xd6, /* br x17. */
397 static const bfd_byte
398 elfNN_aarch64_small_plt_pac_entry
[PLT_PAC_SMALL_ENTRY_SIZE
] =
400 0x10, 0x00, 0x00, 0x90, /* adrp x16, PLTGOT + n * 8 */
402 0x11, 0x02, 0x40, 0xf9, /* ldr x17, [x16, PLTGOT + n * 8] */
403 0x10, 0x02, 0x00, 0x91, /* add x16, x16, :lo12:PLTGOT + n * 8 */
405 0x11, 0x02, 0x40, 0xb9, /* ldr w17, [x16, PLTGOT + n * 4] */
406 0x10, 0x02, 0x00, 0x11, /* add w16, w16, :lo12:PLTGOT + n * 4 */
408 0x9f, 0x21, 0x03, 0xd5, /* autia1716 */
409 0x20, 0x02, 0x1f, 0xd6, /* br x17. */
412 static const bfd_byte
413 elfNN_aarch64_small_plt_bti_pac_entry
[PLT_BTI_PAC_SMALL_ENTRY_SIZE
] =
415 0x5f, 0x24, 0x03, 0xd5, /* bti c. */
416 0x10, 0x00, 0x00, 0x90, /* adrp x16, PLTGOT + n * 8 */
418 0x11, 0x02, 0x40, 0xf9, /* ldr x17, [x16, PLTGOT + n * 8] */
419 0x10, 0x02, 0x00, 0x91, /* add x16, x16, :lo12:PLTGOT + n * 8 */
421 0x11, 0x02, 0x40, 0xb9, /* ldr w17, [x16, PLTGOT + n * 4] */
422 0x10, 0x02, 0x00, 0x11, /* add w16, w16, :lo12:PLTGOT + n * 4 */
424 0x9f, 0x21, 0x03, 0xd5, /* autia1716 */
425 0x20, 0x02, 0x1f, 0xd6, /* br x17. */
428 static const bfd_byte
429 elfNN_aarch64_tlsdesc_small_plt_entry
[PLT_TLSDESC_ENTRY_SIZE
] =
431 0xe2, 0x0f, 0xbf, 0xa9, /* stp x2, x3, [sp, #-16]! */
432 0x02, 0x00, 0x00, 0x90, /* adrp x2, 0 */
433 0x03, 0x00, 0x00, 0x90, /* adrp x3, 0 */
435 0x42, 0x00, 0x40, 0xf9, /* ldr x2, [x2, #0] */
436 0x63, 0x00, 0x00, 0x91, /* add x3, x3, 0 */
438 0x42, 0x00, 0x40, 0xb9, /* ldr w2, [x2, #0] */
439 0x63, 0x00, 0x00, 0x11, /* add w3, w3, 0 */
441 0x40, 0x00, 0x1f, 0xd6, /* br x2 */
442 0x1f, 0x20, 0x03, 0xd5, /* nop */
443 0x1f, 0x20, 0x03, 0xd5, /* nop */
446 static const bfd_byte
447 elfNN_aarch64_tlsdesc_small_plt_bti_entry
[PLT_BTI_TLSDESC_ENTRY_SIZE
] =
449 0x5f, 0x24, 0x03, 0xd5, /* bti c. */
450 0xe2, 0x0f, 0xbf, 0xa9, /* stp x2, x3, [sp, #-16]! */
451 0x02, 0x00, 0x00, 0x90, /* adrp x2, 0 */
452 0x03, 0x00, 0x00, 0x90, /* adrp x3, 0 */
454 0x42, 0x00, 0x40, 0xf9, /* ldr x2, [x2, #0] */
455 0x63, 0x00, 0x00, 0x91, /* add x3, x3, 0 */
457 0x42, 0x00, 0x40, 0xb9, /* ldr w2, [x2, #0] */
458 0x63, 0x00, 0x00, 0x11, /* add w3, w3, 0 */
460 0x40, 0x00, 0x1f, 0xd6, /* br x2 */
461 0x1f, 0x20, 0x03, 0xd5, /* nop */
462 0x1f, 0x20, 0x03, 0xd5, /* nop */
465 #define elf_info_to_howto elfNN_aarch64_info_to_howto
466 #define elf_info_to_howto_rel elfNN_aarch64_info_to_howto
468 #define AARCH64_ELF_ABI_VERSION 0
470 /* In case we're on a 32-bit machine, construct a 64-bit "-1" value. */
471 #define ALL_ONES (~ (bfd_vma) 0)
473 /* Indexed by the bfd interal reloc enumerators.
474 Therefore, the table needs to be synced with BFD_RELOC_AARCH64_*
477 static reloc_howto_type elfNN_aarch64_howto_table
[] =
481 /* Basic data relocations. */
483 /* Deprecated, but retained for backwards compatibility. */
484 HOWTO64 (R_AARCH64_NULL
, /* type */
486 3, /* size (0 = byte, 1 = short, 2 = long) */
488 FALSE
, /* pc_relative */
490 complain_overflow_dont
, /* complain_on_overflow */
491 bfd_elf_generic_reloc
, /* special_function */
492 "R_AARCH64_NULL", /* name */
493 FALSE
, /* partial_inplace */
496 FALSE
), /* pcrel_offset */
497 HOWTO (R_AARCH64_NONE
, /* type */
499 3, /* size (0 = byte, 1 = short, 2 = long) */
501 FALSE
, /* pc_relative */
503 complain_overflow_dont
, /* complain_on_overflow */
504 bfd_elf_generic_reloc
, /* special_function */
505 "R_AARCH64_NONE", /* name */
506 FALSE
, /* partial_inplace */
509 FALSE
), /* pcrel_offset */
512 HOWTO64 (AARCH64_R (ABS64
), /* type */
514 4, /* size (4 = long long) */
516 FALSE
, /* pc_relative */
518 complain_overflow_unsigned
, /* complain_on_overflow */
519 bfd_elf_generic_reloc
, /* special_function */
520 AARCH64_R_STR (ABS64
), /* name */
521 FALSE
, /* partial_inplace */
522 ALL_ONES
, /* src_mask */
523 ALL_ONES
, /* dst_mask */
524 FALSE
), /* pcrel_offset */
527 HOWTO (AARCH64_R (ABS32
), /* type */
529 2, /* size (0 = byte, 1 = short, 2 = long) */
531 FALSE
, /* pc_relative */
533 complain_overflow_unsigned
, /* complain_on_overflow */
534 bfd_elf_generic_reloc
, /* special_function */
535 AARCH64_R_STR (ABS32
), /* name */
536 FALSE
, /* partial_inplace */
537 0xffffffff, /* src_mask */
538 0xffffffff, /* dst_mask */
539 FALSE
), /* pcrel_offset */
542 HOWTO (AARCH64_R (ABS16
), /* type */
544 1, /* size (0 = byte, 1 = short, 2 = long) */
546 FALSE
, /* pc_relative */
548 complain_overflow_unsigned
, /* complain_on_overflow */
549 bfd_elf_generic_reloc
, /* special_function */
550 AARCH64_R_STR (ABS16
), /* name */
551 FALSE
, /* partial_inplace */
552 0xffff, /* src_mask */
553 0xffff, /* dst_mask */
554 FALSE
), /* pcrel_offset */
556 /* .xword: (S+A-P) */
557 HOWTO64 (AARCH64_R (PREL64
), /* type */
559 4, /* size (4 = long long) */
561 TRUE
, /* pc_relative */
563 complain_overflow_signed
, /* complain_on_overflow */
564 bfd_elf_generic_reloc
, /* special_function */
565 AARCH64_R_STR (PREL64
), /* name */
566 FALSE
, /* partial_inplace */
567 ALL_ONES
, /* src_mask */
568 ALL_ONES
, /* dst_mask */
569 TRUE
), /* pcrel_offset */
572 HOWTO (AARCH64_R (PREL32
), /* type */
574 2, /* size (0 = byte, 1 = short, 2 = long) */
576 TRUE
, /* pc_relative */
578 complain_overflow_signed
, /* complain_on_overflow */
579 bfd_elf_generic_reloc
, /* special_function */
580 AARCH64_R_STR (PREL32
), /* name */
581 FALSE
, /* partial_inplace */
582 0xffffffff, /* src_mask */
583 0xffffffff, /* dst_mask */
584 TRUE
), /* pcrel_offset */
587 HOWTO (AARCH64_R (PREL16
), /* type */
589 1, /* size (0 = byte, 1 = short, 2 = long) */
591 TRUE
, /* pc_relative */
593 complain_overflow_signed
, /* complain_on_overflow */
594 bfd_elf_generic_reloc
, /* special_function */
595 AARCH64_R_STR (PREL16
), /* name */
596 FALSE
, /* partial_inplace */
597 0xffff, /* src_mask */
598 0xffff, /* dst_mask */
599 TRUE
), /* pcrel_offset */
601 /* Group relocations to create a 16, 32, 48 or 64 bit
602 unsigned data or abs address inline. */
604 /* MOVZ: ((S+A) >> 0) & 0xffff */
605 HOWTO (AARCH64_R (MOVW_UABS_G0
), /* type */
607 2, /* size (0 = byte, 1 = short, 2 = long) */
609 FALSE
, /* pc_relative */
611 complain_overflow_unsigned
, /* complain_on_overflow */
612 bfd_elf_generic_reloc
, /* special_function */
613 AARCH64_R_STR (MOVW_UABS_G0
), /* name */
614 FALSE
, /* partial_inplace */
615 0xffff, /* src_mask */
616 0xffff, /* dst_mask */
617 FALSE
), /* pcrel_offset */
619 /* MOVK: ((S+A) >> 0) & 0xffff [no overflow check] */
620 HOWTO (AARCH64_R (MOVW_UABS_G0_NC
), /* type */
622 2, /* size (0 = byte, 1 = short, 2 = long) */
624 FALSE
, /* pc_relative */
626 complain_overflow_dont
, /* complain_on_overflow */
627 bfd_elf_generic_reloc
, /* special_function */
628 AARCH64_R_STR (MOVW_UABS_G0_NC
), /* name */
629 FALSE
, /* partial_inplace */
630 0xffff, /* src_mask */
631 0xffff, /* dst_mask */
632 FALSE
), /* pcrel_offset */
634 /* MOVZ: ((S+A) >> 16) & 0xffff */
635 HOWTO (AARCH64_R (MOVW_UABS_G1
), /* type */
637 2, /* size (0 = byte, 1 = short, 2 = long) */
639 FALSE
, /* pc_relative */
641 complain_overflow_unsigned
, /* complain_on_overflow */
642 bfd_elf_generic_reloc
, /* special_function */
643 AARCH64_R_STR (MOVW_UABS_G1
), /* name */
644 FALSE
, /* partial_inplace */
645 0xffff, /* src_mask */
646 0xffff, /* dst_mask */
647 FALSE
), /* pcrel_offset */
649 /* MOVK: ((S+A) >> 16) & 0xffff [no overflow check] */
650 HOWTO64 (AARCH64_R (MOVW_UABS_G1_NC
), /* type */
652 2, /* size (0 = byte, 1 = short, 2 = long) */
654 FALSE
, /* pc_relative */
656 complain_overflow_dont
, /* complain_on_overflow */
657 bfd_elf_generic_reloc
, /* special_function */
658 AARCH64_R_STR (MOVW_UABS_G1_NC
), /* name */
659 FALSE
, /* partial_inplace */
660 0xffff, /* src_mask */
661 0xffff, /* dst_mask */
662 FALSE
), /* pcrel_offset */
664 /* MOVZ: ((S+A) >> 32) & 0xffff */
665 HOWTO64 (AARCH64_R (MOVW_UABS_G2
), /* type */
667 2, /* size (0 = byte, 1 = short, 2 = long) */
669 FALSE
, /* pc_relative */
671 complain_overflow_unsigned
, /* complain_on_overflow */
672 bfd_elf_generic_reloc
, /* special_function */
673 AARCH64_R_STR (MOVW_UABS_G2
), /* name */
674 FALSE
, /* partial_inplace */
675 0xffff, /* src_mask */
676 0xffff, /* dst_mask */
677 FALSE
), /* pcrel_offset */
679 /* MOVK: ((S+A) >> 32) & 0xffff [no overflow check] */
680 HOWTO64 (AARCH64_R (MOVW_UABS_G2_NC
), /* type */
682 2, /* size (0 = byte, 1 = short, 2 = long) */
684 FALSE
, /* pc_relative */
686 complain_overflow_dont
, /* complain_on_overflow */
687 bfd_elf_generic_reloc
, /* special_function */
688 AARCH64_R_STR (MOVW_UABS_G2_NC
), /* name */
689 FALSE
, /* partial_inplace */
690 0xffff, /* src_mask */
691 0xffff, /* dst_mask */
692 FALSE
), /* pcrel_offset */
694 /* MOVZ: ((S+A) >> 48) & 0xffff */
695 HOWTO64 (AARCH64_R (MOVW_UABS_G3
), /* type */
697 2, /* size (0 = byte, 1 = short, 2 = long) */
699 FALSE
, /* pc_relative */
701 complain_overflow_unsigned
, /* complain_on_overflow */
702 bfd_elf_generic_reloc
, /* special_function */
703 AARCH64_R_STR (MOVW_UABS_G3
), /* name */
704 FALSE
, /* partial_inplace */
705 0xffff, /* src_mask */
706 0xffff, /* dst_mask */
707 FALSE
), /* pcrel_offset */
709 /* Group relocations to create high part of a 16, 32, 48 or 64 bit
710 signed data or abs address inline. Will change instruction
711 to MOVN or MOVZ depending on sign of calculated value. */
713 /* MOV[ZN]: ((S+A) >> 0) & 0xffff */
714 HOWTO (AARCH64_R (MOVW_SABS_G0
), /* type */
716 2, /* size (0 = byte, 1 = short, 2 = long) */
718 FALSE
, /* pc_relative */
720 complain_overflow_signed
, /* complain_on_overflow */
721 bfd_elf_generic_reloc
, /* special_function */
722 AARCH64_R_STR (MOVW_SABS_G0
), /* name */
723 FALSE
, /* partial_inplace */
724 0xffff, /* src_mask */
725 0xffff, /* dst_mask */
726 FALSE
), /* pcrel_offset */
728 /* MOV[ZN]: ((S+A) >> 16) & 0xffff */
729 HOWTO64 (AARCH64_R (MOVW_SABS_G1
), /* type */
731 2, /* size (0 = byte, 1 = short, 2 = long) */
733 FALSE
, /* pc_relative */
735 complain_overflow_signed
, /* complain_on_overflow */
736 bfd_elf_generic_reloc
, /* special_function */
737 AARCH64_R_STR (MOVW_SABS_G1
), /* name */
738 FALSE
, /* partial_inplace */
739 0xffff, /* src_mask */
740 0xffff, /* dst_mask */
741 FALSE
), /* pcrel_offset */
743 /* MOV[ZN]: ((S+A) >> 32) & 0xffff */
744 HOWTO64 (AARCH64_R (MOVW_SABS_G2
), /* type */
746 2, /* size (0 = byte, 1 = short, 2 = long) */
748 FALSE
, /* pc_relative */
750 complain_overflow_signed
, /* complain_on_overflow */
751 bfd_elf_generic_reloc
, /* special_function */
752 AARCH64_R_STR (MOVW_SABS_G2
), /* name */
753 FALSE
, /* partial_inplace */
754 0xffff, /* src_mask */
755 0xffff, /* dst_mask */
756 FALSE
), /* pcrel_offset */
758 /* Group relocations to create a 16, 32, 48 or 64 bit
759 PC relative address inline. */
761 /* MOV[NZ]: ((S+A-P) >> 0) & 0xffff */
762 HOWTO64 (AARCH64_R (MOVW_PREL_G0
), /* type */
764 2, /* size (0 = byte, 1 = short, 2 = long) */
766 TRUE
, /* pc_relative */
768 complain_overflow_signed
, /* complain_on_overflow */
769 bfd_elf_generic_reloc
, /* special_function */
770 AARCH64_R_STR (MOVW_PREL_G0
), /* name */
771 FALSE
, /* partial_inplace */
772 0xffff, /* src_mask */
773 0xffff, /* dst_mask */
774 TRUE
), /* pcrel_offset */
776 /* MOVK: ((S+A-P) >> 0) & 0xffff [no overflow check] */
777 HOWTO64 (AARCH64_R (MOVW_PREL_G0_NC
), /* type */
779 2, /* size (0 = byte, 1 = short, 2 = long) */
781 TRUE
, /* pc_relative */
783 complain_overflow_dont
, /* complain_on_overflow */
784 bfd_elf_generic_reloc
, /* special_function */
785 AARCH64_R_STR (MOVW_PREL_G0_NC
), /* name */
786 FALSE
, /* partial_inplace */
787 0xffff, /* src_mask */
788 0xffff, /* dst_mask */
789 TRUE
), /* pcrel_offset */
791 /* MOV[NZ]: ((S+A-P) >> 16) & 0xffff */
792 HOWTO64 (AARCH64_R (MOVW_PREL_G1
), /* type */
794 2, /* size (0 = byte, 1 = short, 2 = long) */
796 TRUE
, /* pc_relative */
798 complain_overflow_signed
, /* complain_on_overflow */
799 bfd_elf_generic_reloc
, /* special_function */
800 AARCH64_R_STR (MOVW_PREL_G1
), /* name */
801 FALSE
, /* partial_inplace */
802 0xffff, /* src_mask */
803 0xffff, /* dst_mask */
804 TRUE
), /* pcrel_offset */
806 /* MOVK: ((S+A-P) >> 16) & 0xffff [no overflow check] */
807 HOWTO64 (AARCH64_R (MOVW_PREL_G1_NC
), /* type */
809 2, /* size (0 = byte, 1 = short, 2 = long) */
811 TRUE
, /* pc_relative */
813 complain_overflow_dont
, /* complain_on_overflow */
814 bfd_elf_generic_reloc
, /* special_function */
815 AARCH64_R_STR (MOVW_PREL_G1_NC
), /* name */
816 FALSE
, /* partial_inplace */
817 0xffff, /* src_mask */
818 0xffff, /* dst_mask */
819 TRUE
), /* pcrel_offset */
821 /* MOV[NZ]: ((S+A-P) >> 32) & 0xffff */
822 HOWTO64 (AARCH64_R (MOVW_PREL_G2
), /* type */
824 2, /* size (0 = byte, 1 = short, 2 = long) */
826 TRUE
, /* pc_relative */
828 complain_overflow_signed
, /* complain_on_overflow */
829 bfd_elf_generic_reloc
, /* special_function */
830 AARCH64_R_STR (MOVW_PREL_G2
), /* name */
831 FALSE
, /* partial_inplace */
832 0xffff, /* src_mask */
833 0xffff, /* dst_mask */
834 TRUE
), /* pcrel_offset */
836 /* MOVK: ((S+A-P) >> 32) & 0xffff [no overflow check] */
837 HOWTO64 (AARCH64_R (MOVW_PREL_G2_NC
), /* type */
839 2, /* size (0 = byte, 1 = short, 2 = long) */
841 TRUE
, /* pc_relative */
843 complain_overflow_dont
, /* complain_on_overflow */
844 bfd_elf_generic_reloc
, /* special_function */
845 AARCH64_R_STR (MOVW_PREL_G2_NC
), /* name */
846 FALSE
, /* partial_inplace */
847 0xffff, /* src_mask */
848 0xffff, /* dst_mask */
849 TRUE
), /* pcrel_offset */
851 /* MOV[NZ]: ((S+A-P) >> 48) & 0xffff */
852 HOWTO64 (AARCH64_R (MOVW_PREL_G3
), /* type */
854 2, /* size (0 = byte, 1 = short, 2 = long) */
856 TRUE
, /* pc_relative */
858 complain_overflow_dont
, /* complain_on_overflow */
859 bfd_elf_generic_reloc
, /* special_function */
860 AARCH64_R_STR (MOVW_PREL_G3
), /* name */
861 FALSE
, /* partial_inplace */
862 0xffff, /* src_mask */
863 0xffff, /* dst_mask */
864 TRUE
), /* pcrel_offset */
866 /* Relocations to generate 19, 21 and 33 bit PC-relative load/store
867 addresses: PG(x) is (x & ~0xfff). */
869 /* LD-lit: ((S+A-P) >> 2) & 0x7ffff */
870 HOWTO (AARCH64_R (LD_PREL_LO19
), /* type */
872 2, /* size (0 = byte, 1 = short, 2 = long) */
874 TRUE
, /* pc_relative */
876 complain_overflow_signed
, /* complain_on_overflow */
877 bfd_elf_generic_reloc
, /* special_function */
878 AARCH64_R_STR (LD_PREL_LO19
), /* name */
879 FALSE
, /* partial_inplace */
880 0x7ffff, /* src_mask */
881 0x7ffff, /* dst_mask */
882 TRUE
), /* pcrel_offset */
884 /* ADR: (S+A-P) & 0x1fffff */
885 HOWTO (AARCH64_R (ADR_PREL_LO21
), /* type */
887 2, /* size (0 = byte, 1 = short, 2 = long) */
889 TRUE
, /* pc_relative */
891 complain_overflow_signed
, /* complain_on_overflow */
892 bfd_elf_generic_reloc
, /* special_function */
893 AARCH64_R_STR (ADR_PREL_LO21
), /* name */
894 FALSE
, /* partial_inplace */
895 0x1fffff, /* src_mask */
896 0x1fffff, /* dst_mask */
897 TRUE
), /* pcrel_offset */
899 /* ADRP: ((PG(S+A)-PG(P)) >> 12) & 0x1fffff */
900 HOWTO (AARCH64_R (ADR_PREL_PG_HI21
), /* type */
902 2, /* size (0 = byte, 1 = short, 2 = long) */
904 TRUE
, /* pc_relative */
906 complain_overflow_signed
, /* complain_on_overflow */
907 bfd_elf_generic_reloc
, /* special_function */
908 AARCH64_R_STR (ADR_PREL_PG_HI21
), /* name */
909 FALSE
, /* partial_inplace */
910 0x1fffff, /* src_mask */
911 0x1fffff, /* dst_mask */
912 TRUE
), /* pcrel_offset */
914 /* ADRP: ((PG(S+A)-PG(P)) >> 12) & 0x1fffff [no overflow check] */
915 HOWTO64 (AARCH64_R (ADR_PREL_PG_HI21_NC
), /* type */
917 2, /* size (0 = byte, 1 = short, 2 = long) */
919 TRUE
, /* pc_relative */
921 complain_overflow_dont
, /* complain_on_overflow */
922 bfd_elf_generic_reloc
, /* special_function */
923 AARCH64_R_STR (ADR_PREL_PG_HI21_NC
), /* name */
924 FALSE
, /* partial_inplace */
925 0x1fffff, /* src_mask */
926 0x1fffff, /* dst_mask */
927 TRUE
), /* pcrel_offset */
929 /* ADD: (S+A) & 0xfff [no overflow check] */
930 HOWTO (AARCH64_R (ADD_ABS_LO12_NC
), /* type */
932 2, /* size (0 = byte, 1 = short, 2 = long) */
934 FALSE
, /* pc_relative */
936 complain_overflow_dont
, /* complain_on_overflow */
937 bfd_elf_generic_reloc
, /* special_function */
938 AARCH64_R_STR (ADD_ABS_LO12_NC
), /* name */
939 FALSE
, /* partial_inplace */
940 0x3ffc00, /* src_mask */
941 0x3ffc00, /* dst_mask */
942 FALSE
), /* pcrel_offset */
944 /* LD/ST8: (S+A) & 0xfff */
945 HOWTO (AARCH64_R (LDST8_ABS_LO12_NC
), /* type */
947 2, /* size (0 = byte, 1 = short, 2 = long) */
949 FALSE
, /* pc_relative */
951 complain_overflow_dont
, /* complain_on_overflow */
952 bfd_elf_generic_reloc
, /* special_function */
953 AARCH64_R_STR (LDST8_ABS_LO12_NC
), /* name */
954 FALSE
, /* partial_inplace */
955 0xfff, /* src_mask */
956 0xfff, /* dst_mask */
957 FALSE
), /* pcrel_offset */
959 /* Relocations for control-flow instructions. */
961 /* TBZ/NZ: ((S+A-P) >> 2) & 0x3fff */
962 HOWTO (AARCH64_R (TSTBR14
), /* type */
964 2, /* size (0 = byte, 1 = short, 2 = long) */
966 TRUE
, /* pc_relative */
968 complain_overflow_signed
, /* complain_on_overflow */
969 bfd_elf_generic_reloc
, /* special_function */
970 AARCH64_R_STR (TSTBR14
), /* name */
971 FALSE
, /* partial_inplace */
972 0x3fff, /* src_mask */
973 0x3fff, /* dst_mask */
974 TRUE
), /* pcrel_offset */
976 /* B.cond: ((S+A-P) >> 2) & 0x7ffff */
977 HOWTO (AARCH64_R (CONDBR19
), /* type */
979 2, /* size (0 = byte, 1 = short, 2 = long) */
981 TRUE
, /* pc_relative */
983 complain_overflow_signed
, /* complain_on_overflow */
984 bfd_elf_generic_reloc
, /* special_function */
985 AARCH64_R_STR (CONDBR19
), /* name */
986 FALSE
, /* partial_inplace */
987 0x7ffff, /* src_mask */
988 0x7ffff, /* dst_mask */
989 TRUE
), /* pcrel_offset */
991 /* B: ((S+A-P) >> 2) & 0x3ffffff */
992 HOWTO (AARCH64_R (JUMP26
), /* type */
994 2, /* size (0 = byte, 1 = short, 2 = long) */
996 TRUE
, /* pc_relative */
998 complain_overflow_signed
, /* complain_on_overflow */
999 bfd_elf_generic_reloc
, /* special_function */
1000 AARCH64_R_STR (JUMP26
), /* name */
1001 FALSE
, /* partial_inplace */
1002 0x3ffffff, /* src_mask */
1003 0x3ffffff, /* dst_mask */
1004 TRUE
), /* pcrel_offset */
1006 /* BL: ((S+A-P) >> 2) & 0x3ffffff */
1007 HOWTO (AARCH64_R (CALL26
), /* type */
1009 2, /* size (0 = byte, 1 = short, 2 = long) */
1011 TRUE
, /* pc_relative */
1013 complain_overflow_signed
, /* complain_on_overflow */
1014 bfd_elf_generic_reloc
, /* special_function */
1015 AARCH64_R_STR (CALL26
), /* name */
1016 FALSE
, /* partial_inplace */
1017 0x3ffffff, /* src_mask */
1018 0x3ffffff, /* dst_mask */
1019 TRUE
), /* pcrel_offset */
1021 /* LD/ST16: (S+A) & 0xffe */
1022 HOWTO (AARCH64_R (LDST16_ABS_LO12_NC
), /* type */
1024 2, /* size (0 = byte, 1 = short, 2 = long) */
1026 FALSE
, /* pc_relative */
1028 complain_overflow_dont
, /* complain_on_overflow */
1029 bfd_elf_generic_reloc
, /* special_function */
1030 AARCH64_R_STR (LDST16_ABS_LO12_NC
), /* name */
1031 FALSE
, /* partial_inplace */
1032 0xffe, /* src_mask */
1033 0xffe, /* dst_mask */
1034 FALSE
), /* pcrel_offset */
1036 /* LD/ST32: (S+A) & 0xffc */
1037 HOWTO (AARCH64_R (LDST32_ABS_LO12_NC
), /* type */
1039 2, /* size (0 = byte, 1 = short, 2 = long) */
1041 FALSE
, /* pc_relative */
1043 complain_overflow_dont
, /* complain_on_overflow */
1044 bfd_elf_generic_reloc
, /* special_function */
1045 AARCH64_R_STR (LDST32_ABS_LO12_NC
), /* name */
1046 FALSE
, /* partial_inplace */
1047 0xffc, /* src_mask */
1048 0xffc, /* dst_mask */
1049 FALSE
), /* pcrel_offset */
1051 /* LD/ST64: (S+A) & 0xff8 */
1052 HOWTO (AARCH64_R (LDST64_ABS_LO12_NC
), /* type */
1054 2, /* size (0 = byte, 1 = short, 2 = long) */
1056 FALSE
, /* pc_relative */
1058 complain_overflow_dont
, /* complain_on_overflow */
1059 bfd_elf_generic_reloc
, /* special_function */
1060 AARCH64_R_STR (LDST64_ABS_LO12_NC
), /* name */
1061 FALSE
, /* partial_inplace */
1062 0xff8, /* src_mask */
1063 0xff8, /* dst_mask */
1064 FALSE
), /* pcrel_offset */
1066 /* LD/ST128: (S+A) & 0xff0 */
1067 HOWTO (AARCH64_R (LDST128_ABS_LO12_NC
), /* type */
1069 2, /* size (0 = byte, 1 = short, 2 = long) */
1071 FALSE
, /* pc_relative */
1073 complain_overflow_dont
, /* complain_on_overflow */
1074 bfd_elf_generic_reloc
, /* special_function */
1075 AARCH64_R_STR (LDST128_ABS_LO12_NC
), /* name */
1076 FALSE
, /* partial_inplace */
1077 0xff0, /* src_mask */
1078 0xff0, /* dst_mask */
1079 FALSE
), /* pcrel_offset */
1081 /* Set a load-literal immediate field to bits
1082 0x1FFFFC of G(S)-P */
1083 HOWTO (AARCH64_R (GOT_LD_PREL19
), /* type */
1085 2, /* size (0 = byte,1 = short,2 = long) */
1087 TRUE
, /* pc_relative */
1089 complain_overflow_signed
, /* complain_on_overflow */
1090 bfd_elf_generic_reloc
, /* special_function */
1091 AARCH64_R_STR (GOT_LD_PREL19
), /* name */
1092 FALSE
, /* partial_inplace */
1093 0xffffe0, /* src_mask */
1094 0xffffe0, /* dst_mask */
1095 TRUE
), /* pcrel_offset */
1097 /* Get to the page for the GOT entry for the symbol
1098 (G(S) - P) using an ADRP instruction. */
1099 HOWTO (AARCH64_R (ADR_GOT_PAGE
), /* type */
1100 12, /* rightshift */
1101 2, /* size (0 = byte, 1 = short, 2 = long) */
1103 TRUE
, /* pc_relative */
1105 complain_overflow_dont
, /* complain_on_overflow */
1106 bfd_elf_generic_reloc
, /* special_function */
1107 AARCH64_R_STR (ADR_GOT_PAGE
), /* name */
1108 FALSE
, /* partial_inplace */
1109 0x1fffff, /* src_mask */
1110 0x1fffff, /* dst_mask */
1111 TRUE
), /* pcrel_offset */
1113 /* LD64: GOT offset G(S) & 0xff8 */
1114 HOWTO64 (AARCH64_R (LD64_GOT_LO12_NC
), /* type */
1116 2, /* size (0 = byte, 1 = short, 2 = long) */
1118 FALSE
, /* pc_relative */
1120 complain_overflow_dont
, /* complain_on_overflow */
1121 bfd_elf_generic_reloc
, /* special_function */
1122 AARCH64_R_STR (LD64_GOT_LO12_NC
), /* name */
1123 FALSE
, /* partial_inplace */
1124 0xff8, /* src_mask */
1125 0xff8, /* dst_mask */
1126 FALSE
), /* pcrel_offset */
1128 /* LD32: GOT offset G(S) & 0xffc */
1129 HOWTO32 (AARCH64_R (LD32_GOT_LO12_NC
), /* type */
1131 2, /* size (0 = byte, 1 = short, 2 = long) */
1133 FALSE
, /* pc_relative */
1135 complain_overflow_dont
, /* complain_on_overflow */
1136 bfd_elf_generic_reloc
, /* special_function */
1137 AARCH64_R_STR (LD32_GOT_LO12_NC
), /* name */
1138 FALSE
, /* partial_inplace */
1139 0xffc, /* src_mask */
1140 0xffc, /* dst_mask */
1141 FALSE
), /* pcrel_offset */
1143 /* Lower 16 bits of GOT offset for the symbol. */
1144 HOWTO64 (AARCH64_R (MOVW_GOTOFF_G0_NC
), /* type */
1146 2, /* size (0 = byte, 1 = short, 2 = long) */
1148 FALSE
, /* pc_relative */
1150 complain_overflow_dont
, /* complain_on_overflow */
1151 bfd_elf_generic_reloc
, /* special_function */
1152 AARCH64_R_STR (MOVW_GOTOFF_G0_NC
), /* name */
1153 FALSE
, /* partial_inplace */
1154 0xffff, /* src_mask */
1155 0xffff, /* dst_mask */
1156 FALSE
), /* pcrel_offset */
1158 /* Higher 16 bits of GOT offset for the symbol. */
1159 HOWTO64 (AARCH64_R (MOVW_GOTOFF_G1
), /* type */
1160 16, /* rightshift */
1161 2, /* size (0 = byte, 1 = short, 2 = long) */
1163 FALSE
, /* pc_relative */
1165 complain_overflow_unsigned
, /* complain_on_overflow */
1166 bfd_elf_generic_reloc
, /* special_function */
1167 AARCH64_R_STR (MOVW_GOTOFF_G1
), /* name */
1168 FALSE
, /* partial_inplace */
1169 0xffff, /* src_mask */
1170 0xffff, /* dst_mask */
1171 FALSE
), /* pcrel_offset */
1173 /* LD64: GOT offset for the symbol. */
1174 HOWTO64 (AARCH64_R (LD64_GOTOFF_LO15
), /* type */
1176 2, /* size (0 = byte, 1 = short, 2 = long) */
1178 FALSE
, /* pc_relative */
1180 complain_overflow_unsigned
, /* complain_on_overflow */
1181 bfd_elf_generic_reloc
, /* special_function */
1182 AARCH64_R_STR (LD64_GOTOFF_LO15
), /* name */
1183 FALSE
, /* partial_inplace */
1184 0x7ff8, /* src_mask */
1185 0x7ff8, /* dst_mask */
1186 FALSE
), /* pcrel_offset */
1188 /* LD32: GOT offset to the page address of GOT table.
1189 (G(S) - PAGE (_GLOBAL_OFFSET_TABLE_)) & 0x5ffc. */
1190 HOWTO32 (AARCH64_R (LD32_GOTPAGE_LO14
), /* type */
1192 2, /* size (0 = byte, 1 = short, 2 = long) */
1194 FALSE
, /* pc_relative */
1196 complain_overflow_unsigned
, /* complain_on_overflow */
1197 bfd_elf_generic_reloc
, /* special_function */
1198 AARCH64_R_STR (LD32_GOTPAGE_LO14
), /* name */
1199 FALSE
, /* partial_inplace */
1200 0x5ffc, /* src_mask */
1201 0x5ffc, /* dst_mask */
1202 FALSE
), /* pcrel_offset */
1204 /* LD64: GOT offset to the page address of GOT table.
1205 (G(S) - PAGE (_GLOBAL_OFFSET_TABLE_)) & 0x7ff8. */
1206 HOWTO64 (AARCH64_R (LD64_GOTPAGE_LO15
), /* type */
1208 2, /* size (0 = byte, 1 = short, 2 = long) */
1210 FALSE
, /* pc_relative */
1212 complain_overflow_unsigned
, /* complain_on_overflow */
1213 bfd_elf_generic_reloc
, /* special_function */
1214 AARCH64_R_STR (LD64_GOTPAGE_LO15
), /* name */
1215 FALSE
, /* partial_inplace */
1216 0x7ff8, /* src_mask */
1217 0x7ff8, /* dst_mask */
1218 FALSE
), /* pcrel_offset */
1220 /* Get to the page for the GOT entry for the symbol
1221 (G(S) - P) using an ADRP instruction. */
1222 HOWTO (AARCH64_R (TLSGD_ADR_PAGE21
), /* type */
1223 12, /* rightshift */
1224 2, /* size (0 = byte, 1 = short, 2 = long) */
1226 TRUE
, /* pc_relative */
1228 complain_overflow_dont
, /* complain_on_overflow */
1229 bfd_elf_generic_reloc
, /* special_function */
1230 AARCH64_R_STR (TLSGD_ADR_PAGE21
), /* name */
1231 FALSE
, /* partial_inplace */
1232 0x1fffff, /* src_mask */
1233 0x1fffff, /* dst_mask */
1234 TRUE
), /* pcrel_offset */
1236 HOWTO (AARCH64_R (TLSGD_ADR_PREL21
), /* type */
1238 2, /* size (0 = byte, 1 = short, 2 = long) */
1240 TRUE
, /* pc_relative */
1242 complain_overflow_dont
, /* complain_on_overflow */
1243 bfd_elf_generic_reloc
, /* special_function */
1244 AARCH64_R_STR (TLSGD_ADR_PREL21
), /* name */
1245 FALSE
, /* partial_inplace */
1246 0x1fffff, /* src_mask */
1247 0x1fffff, /* dst_mask */
1248 TRUE
), /* pcrel_offset */
1250 /* ADD: GOT offset G(S) & 0xff8 [no overflow check] */
1251 HOWTO (AARCH64_R (TLSGD_ADD_LO12_NC
), /* type */
1253 2, /* size (0 = byte, 1 = short, 2 = long) */
1255 FALSE
, /* pc_relative */
1257 complain_overflow_dont
, /* complain_on_overflow */
1258 bfd_elf_generic_reloc
, /* special_function */
1259 AARCH64_R_STR (TLSGD_ADD_LO12_NC
), /* name */
1260 FALSE
, /* partial_inplace */
1261 0xfff, /* src_mask */
1262 0xfff, /* dst_mask */
1263 FALSE
), /* pcrel_offset */
1265 /* Lower 16 bits of GOT offset to tls_index. */
1266 HOWTO64 (AARCH64_R (TLSGD_MOVW_G0_NC
), /* type */
1268 2, /* size (0 = byte, 1 = short, 2 = long) */
1270 FALSE
, /* pc_relative */
1272 complain_overflow_dont
, /* complain_on_overflow */
1273 bfd_elf_generic_reloc
, /* special_function */
1274 AARCH64_R_STR (TLSGD_MOVW_G0_NC
), /* name */
1275 FALSE
, /* partial_inplace */
1276 0xffff, /* src_mask */
1277 0xffff, /* dst_mask */
1278 FALSE
), /* pcrel_offset */
1280 /* Higher 16 bits of GOT offset to tls_index. */
1281 HOWTO64 (AARCH64_R (TLSGD_MOVW_G1
), /* type */
1282 16, /* rightshift */
1283 2, /* size (0 = byte, 1 = short, 2 = long) */
1285 FALSE
, /* pc_relative */
1287 complain_overflow_unsigned
, /* complain_on_overflow */
1288 bfd_elf_generic_reloc
, /* special_function */
1289 AARCH64_R_STR (TLSGD_MOVW_G1
), /* name */
1290 FALSE
, /* partial_inplace */
1291 0xffff, /* src_mask */
1292 0xffff, /* dst_mask */
1293 FALSE
), /* pcrel_offset */
1295 HOWTO (AARCH64_R (TLSIE_ADR_GOTTPREL_PAGE21
), /* type */
1296 12, /* rightshift */
1297 2, /* size (0 = byte, 1 = short, 2 = long) */
1299 FALSE
, /* pc_relative */
1301 complain_overflow_dont
, /* complain_on_overflow */
1302 bfd_elf_generic_reloc
, /* special_function */
1303 AARCH64_R_STR (TLSIE_ADR_GOTTPREL_PAGE21
), /* name */
1304 FALSE
, /* partial_inplace */
1305 0x1fffff, /* src_mask */
1306 0x1fffff, /* dst_mask */
1307 FALSE
), /* pcrel_offset */
1309 HOWTO64 (AARCH64_R (TLSIE_LD64_GOTTPREL_LO12_NC
), /* type */
1311 2, /* size (0 = byte, 1 = short, 2 = long) */
1313 FALSE
, /* pc_relative */
1315 complain_overflow_dont
, /* complain_on_overflow */
1316 bfd_elf_generic_reloc
, /* special_function */
1317 AARCH64_R_STR (TLSIE_LD64_GOTTPREL_LO12_NC
), /* name */
1318 FALSE
, /* partial_inplace */
1319 0xff8, /* src_mask */
1320 0xff8, /* dst_mask */
1321 FALSE
), /* pcrel_offset */
1323 HOWTO32 (AARCH64_R (TLSIE_LD32_GOTTPREL_LO12_NC
), /* type */
1325 2, /* size (0 = byte, 1 = short, 2 = long) */
1327 FALSE
, /* pc_relative */
1329 complain_overflow_dont
, /* complain_on_overflow */
1330 bfd_elf_generic_reloc
, /* special_function */
1331 AARCH64_R_STR (TLSIE_LD32_GOTTPREL_LO12_NC
), /* name */
1332 FALSE
, /* partial_inplace */
1333 0xffc, /* src_mask */
1334 0xffc, /* dst_mask */
1335 FALSE
), /* pcrel_offset */
1337 HOWTO (AARCH64_R (TLSIE_LD_GOTTPREL_PREL19
), /* type */
1339 2, /* size (0 = byte, 1 = short, 2 = long) */
1341 FALSE
, /* pc_relative */
1343 complain_overflow_dont
, /* complain_on_overflow */
1344 bfd_elf_generic_reloc
, /* special_function */
1345 AARCH64_R_STR (TLSIE_LD_GOTTPREL_PREL19
), /* name */
1346 FALSE
, /* partial_inplace */
1347 0x1ffffc, /* src_mask */
1348 0x1ffffc, /* dst_mask */
1349 FALSE
), /* pcrel_offset */
1351 HOWTO64 (AARCH64_R (TLSIE_MOVW_GOTTPREL_G0_NC
), /* type */
1353 2, /* size (0 = byte, 1 = short, 2 = long) */
1355 FALSE
, /* pc_relative */
1357 complain_overflow_dont
, /* complain_on_overflow */
1358 bfd_elf_generic_reloc
, /* special_function */
1359 AARCH64_R_STR (TLSIE_MOVW_GOTTPREL_G0_NC
), /* name */
1360 FALSE
, /* partial_inplace */
1361 0xffff, /* src_mask */
1362 0xffff, /* dst_mask */
1363 FALSE
), /* pcrel_offset */
1365 HOWTO64 (AARCH64_R (TLSIE_MOVW_GOTTPREL_G1
), /* type */
1366 16, /* rightshift */
1367 2, /* size (0 = byte, 1 = short, 2 = long) */
1369 FALSE
, /* pc_relative */
1371 complain_overflow_unsigned
, /* complain_on_overflow */
1372 bfd_elf_generic_reloc
, /* special_function */
1373 AARCH64_R_STR (TLSIE_MOVW_GOTTPREL_G1
), /* name */
1374 FALSE
, /* partial_inplace */
1375 0xffff, /* src_mask */
1376 0xffff, /* dst_mask */
1377 FALSE
), /* pcrel_offset */
1379 /* ADD: bit[23:12] of byte offset to module TLS base address. */
1380 HOWTO (AARCH64_R (TLSLD_ADD_DTPREL_HI12
), /* type */
1381 12, /* rightshift */
1382 2, /* size (0 = byte, 1 = short, 2 = long) */
1384 FALSE
, /* pc_relative */
1386 complain_overflow_unsigned
, /* complain_on_overflow */
1387 bfd_elf_generic_reloc
, /* special_function */
1388 AARCH64_R_STR (TLSLD_ADD_DTPREL_HI12
), /* name */
1389 FALSE
, /* partial_inplace */
1390 0xfff, /* src_mask */
1391 0xfff, /* dst_mask */
1392 FALSE
), /* pcrel_offset */
1394 /* Unsigned 12 bit byte offset to module TLS base address. */
1395 HOWTO (AARCH64_R (TLSLD_ADD_DTPREL_LO12
), /* type */
1397 2, /* size (0 = byte, 1 = short, 2 = long) */
1399 FALSE
, /* pc_relative */
1401 complain_overflow_unsigned
, /* complain_on_overflow */
1402 bfd_elf_generic_reloc
, /* special_function */
1403 AARCH64_R_STR (TLSLD_ADD_DTPREL_LO12
), /* name */
1404 FALSE
, /* partial_inplace */
1405 0xfff, /* src_mask */
1406 0xfff, /* dst_mask */
1407 FALSE
), /* pcrel_offset */
1409 /* No overflow check version of BFD_RELOC_AARCH64_TLSLD_ADD_DTPREL_LO12. */
1410 HOWTO (AARCH64_R (TLSLD_ADD_DTPREL_LO12_NC
), /* type */
1412 2, /* size (0 = byte, 1 = short, 2 = long) */
1414 FALSE
, /* pc_relative */
1416 complain_overflow_dont
, /* complain_on_overflow */
1417 bfd_elf_generic_reloc
, /* special_function */
1418 AARCH64_R_STR (TLSLD_ADD_DTPREL_LO12_NC
), /* name */
1419 FALSE
, /* partial_inplace */
1420 0xfff, /* src_mask */
1421 0xfff, /* dst_mask */
1422 FALSE
), /* pcrel_offset */
1424 /* ADD: GOT offset G(S) & 0xff8 [no overflow check] */
1425 HOWTO (AARCH64_R (TLSLD_ADD_LO12_NC
), /* type */
1427 2, /* size (0 = byte, 1 = short, 2 = long) */
1429 FALSE
, /* pc_relative */
1431 complain_overflow_dont
, /* complain_on_overflow */
1432 bfd_elf_generic_reloc
, /* special_function */
1433 AARCH64_R_STR (TLSLD_ADD_LO12_NC
), /* name */
1434 FALSE
, /* partial_inplace */
1435 0xfff, /* src_mask */
1436 0xfff, /* dst_mask */
1437 FALSE
), /* pcrel_offset */
1439 /* Get to the page for the GOT entry for the symbol
1440 (G(S) - P) using an ADRP instruction. */
1441 HOWTO (AARCH64_R (TLSLD_ADR_PAGE21
), /* type */
1442 12, /* rightshift */
1443 2, /* size (0 = byte, 1 = short, 2 = long) */
1445 TRUE
, /* pc_relative */
1447 complain_overflow_signed
, /* complain_on_overflow */
1448 bfd_elf_generic_reloc
, /* special_function */
1449 AARCH64_R_STR (TLSLD_ADR_PAGE21
), /* name */
1450 FALSE
, /* partial_inplace */
1451 0x1fffff, /* src_mask */
1452 0x1fffff, /* dst_mask */
1453 TRUE
), /* pcrel_offset */
1455 HOWTO (AARCH64_R (TLSLD_ADR_PREL21
), /* type */
1457 2, /* size (0 = byte, 1 = short, 2 = long) */
1459 TRUE
, /* pc_relative */
1461 complain_overflow_signed
, /* complain_on_overflow */
1462 bfd_elf_generic_reloc
, /* special_function */
1463 AARCH64_R_STR (TLSLD_ADR_PREL21
), /* name */
1464 FALSE
, /* partial_inplace */
1465 0x1fffff, /* src_mask */
1466 0x1fffff, /* dst_mask */
1467 TRUE
), /* pcrel_offset */
1469 /* LD/ST16: bit[11:1] of byte offset to module TLS base address. */
1470 HOWTO64 (AARCH64_R (TLSLD_LDST16_DTPREL_LO12
), /* type */
1472 2, /* size (0 = byte, 1 = short, 2 = long) */
1474 FALSE
, /* pc_relative */
1476 complain_overflow_unsigned
, /* complain_on_overflow */
1477 bfd_elf_generic_reloc
, /* special_function */
1478 AARCH64_R_STR (TLSLD_LDST16_DTPREL_LO12
), /* name */
1479 FALSE
, /* partial_inplace */
1480 0x1ffc00, /* src_mask */
1481 0x1ffc00, /* dst_mask */
1482 FALSE
), /* pcrel_offset */
1484 /* Same as BFD_RELOC_AARCH64_TLSLD_LDST16_DTPREL_LO12, but no overflow check. */
1485 HOWTO64 (AARCH64_R (TLSLD_LDST16_DTPREL_LO12_NC
), /* type */
1487 2, /* size (0 = byte, 1 = short, 2 = long) */
1489 FALSE
, /* pc_relative */
1491 complain_overflow_dont
, /* complain_on_overflow */
1492 bfd_elf_generic_reloc
, /* special_function */
1493 AARCH64_R_STR (TLSLD_LDST16_DTPREL_LO12_NC
), /* name */
1494 FALSE
, /* partial_inplace */
1495 0x1ffc00, /* src_mask */
1496 0x1ffc00, /* dst_mask */
1497 FALSE
), /* pcrel_offset */
1499 /* LD/ST32: bit[11:2] of byte offset to module TLS base address. */
1500 HOWTO64 (AARCH64_R (TLSLD_LDST32_DTPREL_LO12
), /* type */
1502 2, /* size (0 = byte, 1 = short, 2 = long) */
1504 FALSE
, /* pc_relative */
1506 complain_overflow_unsigned
, /* complain_on_overflow */
1507 bfd_elf_generic_reloc
, /* special_function */
1508 AARCH64_R_STR (TLSLD_LDST32_DTPREL_LO12
), /* name */
1509 FALSE
, /* partial_inplace */
1510 0x3ffc00, /* src_mask */
1511 0x3ffc00, /* dst_mask */
1512 FALSE
), /* pcrel_offset */
1514 /* Same as BFD_RELOC_AARCH64_TLSLD_LDST32_DTPREL_LO12, but no overflow check. */
1515 HOWTO64 (AARCH64_R (TLSLD_LDST32_DTPREL_LO12_NC
), /* type */
1517 2, /* size (0 = byte, 1 = short, 2 = long) */
1519 FALSE
, /* pc_relative */
1521 complain_overflow_dont
, /* complain_on_overflow */
1522 bfd_elf_generic_reloc
, /* special_function */
1523 AARCH64_R_STR (TLSLD_LDST32_DTPREL_LO12_NC
), /* name */
1524 FALSE
, /* partial_inplace */
1525 0xffc00, /* src_mask */
1526 0xffc00, /* dst_mask */
1527 FALSE
), /* pcrel_offset */
1529 /* LD/ST64: bit[11:3] of byte offset to module TLS base address. */
1530 HOWTO64 (AARCH64_R (TLSLD_LDST64_DTPREL_LO12
), /* type */
1532 2, /* size (0 = byte, 1 = short, 2 = long) */
1534 FALSE
, /* pc_relative */
1536 complain_overflow_unsigned
, /* complain_on_overflow */
1537 bfd_elf_generic_reloc
, /* special_function */
1538 AARCH64_R_STR (TLSLD_LDST64_DTPREL_LO12
), /* name */
1539 FALSE
, /* partial_inplace */
1540 0x3ffc00, /* src_mask */
1541 0x3ffc00, /* dst_mask */
1542 FALSE
), /* pcrel_offset */
1544 /* Same as BFD_RELOC_AARCH64_TLSLD_LDST64_DTPREL_LO12, but no overflow check. */
1545 HOWTO64 (AARCH64_R (TLSLD_LDST64_DTPREL_LO12_NC
), /* type */
1547 2, /* size (0 = byte, 1 = short, 2 = long) */
1549 FALSE
, /* pc_relative */
1551 complain_overflow_dont
, /* complain_on_overflow */
1552 bfd_elf_generic_reloc
, /* special_function */
1553 AARCH64_R_STR (TLSLD_LDST64_DTPREL_LO12_NC
), /* name */
1554 FALSE
, /* partial_inplace */
1555 0x7fc00, /* src_mask */
1556 0x7fc00, /* dst_mask */
1557 FALSE
), /* pcrel_offset */
1559 /* LD/ST8: bit[11:0] of byte offset to module TLS base address. */
1560 HOWTO64 (AARCH64_R (TLSLD_LDST8_DTPREL_LO12
), /* type */
1562 2, /* size (0 = byte, 1 = short, 2 = long) */
1564 FALSE
, /* pc_relative */
1566 complain_overflow_unsigned
, /* complain_on_overflow */
1567 bfd_elf_generic_reloc
, /* special_function */
1568 AARCH64_R_STR (TLSLD_LDST8_DTPREL_LO12
), /* name */
1569 FALSE
, /* partial_inplace */
1570 0x3ffc00, /* src_mask */
1571 0x3ffc00, /* dst_mask */
1572 FALSE
), /* pcrel_offset */
1574 /* Same as BFD_RELOC_AARCH64_TLSLD_LDST8_DTPREL_LO12, but no overflow check. */
1575 HOWTO64 (AARCH64_R (TLSLD_LDST8_DTPREL_LO12_NC
), /* type */
1577 2, /* size (0 = byte, 1 = short, 2 = long) */
1579 FALSE
, /* pc_relative */
1581 complain_overflow_dont
, /* complain_on_overflow */
1582 bfd_elf_generic_reloc
, /* special_function */
1583 AARCH64_R_STR (TLSLD_LDST8_DTPREL_LO12_NC
), /* name */
1584 FALSE
, /* partial_inplace */
1585 0x3ffc00, /* src_mask */
1586 0x3ffc00, /* dst_mask */
1587 FALSE
), /* pcrel_offset */
1589 /* MOVZ: bit[15:0] of byte offset to module TLS base address. */
1590 HOWTO (AARCH64_R (TLSLD_MOVW_DTPREL_G0
), /* type */
1592 2, /* size (0 = byte, 1 = short, 2 = long) */
1594 FALSE
, /* pc_relative */
1596 complain_overflow_unsigned
, /* complain_on_overflow */
1597 bfd_elf_generic_reloc
, /* special_function */
1598 AARCH64_R_STR (TLSLD_MOVW_DTPREL_G0
), /* name */
1599 FALSE
, /* partial_inplace */
1600 0xffff, /* src_mask */
1601 0xffff, /* dst_mask */
1602 FALSE
), /* pcrel_offset */
1604 /* No overflow check version of BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G0. */
1605 HOWTO (AARCH64_R (TLSLD_MOVW_DTPREL_G0_NC
), /* type */
1607 2, /* size (0 = byte, 1 = short, 2 = long) */
1609 FALSE
, /* pc_relative */
1611 complain_overflow_dont
, /* complain_on_overflow */
1612 bfd_elf_generic_reloc
, /* special_function */
1613 AARCH64_R_STR (TLSLD_MOVW_DTPREL_G0_NC
), /* name */
1614 FALSE
, /* partial_inplace */
1615 0xffff, /* src_mask */
1616 0xffff, /* dst_mask */
1617 FALSE
), /* pcrel_offset */
1619 /* MOVZ: bit[31:16] of byte offset to module TLS base address. */
1620 HOWTO (AARCH64_R (TLSLD_MOVW_DTPREL_G1
), /* type */
1621 16, /* rightshift */
1622 2, /* size (0 = byte, 1 = short, 2 = long) */
1624 FALSE
, /* pc_relative */
1626 complain_overflow_unsigned
, /* complain_on_overflow */
1627 bfd_elf_generic_reloc
, /* special_function */
1628 AARCH64_R_STR (TLSLD_MOVW_DTPREL_G1
), /* name */
1629 FALSE
, /* partial_inplace */
1630 0xffff, /* src_mask */
1631 0xffff, /* dst_mask */
1632 FALSE
), /* pcrel_offset */
1634 /* No overflow check version of BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G1. */
1635 HOWTO64 (AARCH64_R (TLSLD_MOVW_DTPREL_G1_NC
), /* type */
1636 16, /* rightshift */
1637 2, /* size (0 = byte, 1 = short, 2 = long) */
1639 FALSE
, /* pc_relative */
1641 complain_overflow_dont
, /* complain_on_overflow */
1642 bfd_elf_generic_reloc
, /* special_function */
1643 AARCH64_R_STR (TLSLD_MOVW_DTPREL_G1_NC
), /* name */
1644 FALSE
, /* partial_inplace */
1645 0xffff, /* src_mask */
1646 0xffff, /* dst_mask */
1647 FALSE
), /* pcrel_offset */
1649 /* MOVZ: bit[47:32] of byte offset to module TLS base address. */
1650 HOWTO64 (AARCH64_R (TLSLD_MOVW_DTPREL_G2
), /* type */
1651 32, /* rightshift */
1652 2, /* size (0 = byte, 1 = short, 2 = long) */
1654 FALSE
, /* pc_relative */
1656 complain_overflow_unsigned
, /* complain_on_overflow */
1657 bfd_elf_generic_reloc
, /* special_function */
1658 AARCH64_R_STR (TLSLD_MOVW_DTPREL_G2
), /* name */
1659 FALSE
, /* partial_inplace */
1660 0xffff, /* src_mask */
1661 0xffff, /* dst_mask */
1662 FALSE
), /* pcrel_offset */
1664 HOWTO64 (AARCH64_R (TLSLE_MOVW_TPREL_G2
), /* type */
1665 32, /* rightshift */
1666 2, /* size (0 = byte, 1 = short, 2 = long) */
1668 FALSE
, /* pc_relative */
1670 complain_overflow_unsigned
, /* complain_on_overflow */
1671 bfd_elf_generic_reloc
, /* special_function */
1672 AARCH64_R_STR (TLSLE_MOVW_TPREL_G2
), /* name */
1673 FALSE
, /* partial_inplace */
1674 0xffff, /* src_mask */
1675 0xffff, /* dst_mask */
1676 FALSE
), /* pcrel_offset */
1678 HOWTO (AARCH64_R (TLSLE_MOVW_TPREL_G1
), /* type */
1679 16, /* rightshift */
1680 2, /* size (0 = byte, 1 = short, 2 = long) */
1682 FALSE
, /* pc_relative */
1684 complain_overflow_dont
, /* complain_on_overflow */
1685 bfd_elf_generic_reloc
, /* special_function */
1686 AARCH64_R_STR (TLSLE_MOVW_TPREL_G1
), /* name */
1687 FALSE
, /* partial_inplace */
1688 0xffff, /* src_mask */
1689 0xffff, /* dst_mask */
1690 FALSE
), /* pcrel_offset */
1692 HOWTO64 (AARCH64_R (TLSLE_MOVW_TPREL_G1_NC
), /* type */
1693 16, /* rightshift */
1694 2, /* size (0 = byte, 1 = short, 2 = long) */
1696 FALSE
, /* pc_relative */
1698 complain_overflow_dont
, /* complain_on_overflow */
1699 bfd_elf_generic_reloc
, /* special_function */
1700 AARCH64_R_STR (TLSLE_MOVW_TPREL_G1_NC
), /* name */
1701 FALSE
, /* partial_inplace */
1702 0xffff, /* src_mask */
1703 0xffff, /* dst_mask */
1704 FALSE
), /* pcrel_offset */
1706 HOWTO (AARCH64_R (TLSLE_MOVW_TPREL_G0
), /* type */
1708 2, /* size (0 = byte, 1 = short, 2 = long) */
1710 FALSE
, /* pc_relative */
1712 complain_overflow_dont
, /* complain_on_overflow */
1713 bfd_elf_generic_reloc
, /* special_function */
1714 AARCH64_R_STR (TLSLE_MOVW_TPREL_G0
), /* name */
1715 FALSE
, /* partial_inplace */
1716 0xffff, /* src_mask */
1717 0xffff, /* dst_mask */
1718 FALSE
), /* pcrel_offset */
1720 HOWTO (AARCH64_R (TLSLE_MOVW_TPREL_G0_NC
), /* type */
1722 2, /* size (0 = byte, 1 = short, 2 = long) */
1724 FALSE
, /* pc_relative */
1726 complain_overflow_dont
, /* complain_on_overflow */
1727 bfd_elf_generic_reloc
, /* special_function */
1728 AARCH64_R_STR (TLSLE_MOVW_TPREL_G0_NC
), /* name */
1729 FALSE
, /* partial_inplace */
1730 0xffff, /* src_mask */
1731 0xffff, /* dst_mask */
1732 FALSE
), /* pcrel_offset */
1734 HOWTO (AARCH64_R (TLSLE_ADD_TPREL_HI12
), /* type */
1735 12, /* rightshift */
1736 2, /* size (0 = byte, 1 = short, 2 = long) */
1738 FALSE
, /* pc_relative */
1740 complain_overflow_unsigned
, /* complain_on_overflow */
1741 bfd_elf_generic_reloc
, /* special_function */
1742 AARCH64_R_STR (TLSLE_ADD_TPREL_HI12
), /* name */
1743 FALSE
, /* partial_inplace */
1744 0xfff, /* src_mask */
1745 0xfff, /* dst_mask */
1746 FALSE
), /* pcrel_offset */
1748 HOWTO (AARCH64_R (TLSLE_ADD_TPREL_LO12
), /* type */
1750 2, /* size (0 = byte, 1 = short, 2 = long) */
1752 FALSE
, /* pc_relative */
1754 complain_overflow_unsigned
, /* complain_on_overflow */
1755 bfd_elf_generic_reloc
, /* special_function */
1756 AARCH64_R_STR (TLSLE_ADD_TPREL_LO12
), /* name */
1757 FALSE
, /* partial_inplace */
1758 0xfff, /* src_mask */
1759 0xfff, /* dst_mask */
1760 FALSE
), /* pcrel_offset */
1762 HOWTO (AARCH64_R (TLSLE_ADD_TPREL_LO12_NC
), /* type */
1764 2, /* size (0 = byte, 1 = short, 2 = long) */
1766 FALSE
, /* pc_relative */
1768 complain_overflow_dont
, /* complain_on_overflow */
1769 bfd_elf_generic_reloc
, /* special_function */
1770 AARCH64_R_STR (TLSLE_ADD_TPREL_LO12_NC
), /* name */
1771 FALSE
, /* partial_inplace */
1772 0xfff, /* src_mask */
1773 0xfff, /* dst_mask */
1774 FALSE
), /* pcrel_offset */
1776 /* LD/ST16: bit[11:1] of byte offset to module TLS base address. */
1777 HOWTO (AARCH64_R (TLSLE_LDST16_TPREL_LO12
), /* type */
1779 2, /* size (0 = byte, 1 = short, 2 = long) */
1781 FALSE
, /* pc_relative */
1783 complain_overflow_unsigned
, /* complain_on_overflow */
1784 bfd_elf_generic_reloc
, /* special_function */
1785 AARCH64_R_STR (TLSLE_LDST16_TPREL_LO12
), /* name */
1786 FALSE
, /* partial_inplace */
1787 0x1ffc00, /* src_mask */
1788 0x1ffc00, /* dst_mask */
1789 FALSE
), /* pcrel_offset */
1791 /* Same as BFD_RELOC_AARCH64_TLSLE_LDST16_TPREL_LO12, but no overflow check. */
1792 HOWTO (AARCH64_R (TLSLE_LDST16_TPREL_LO12_NC
), /* type */
1794 2, /* size (0 = byte, 1 = short, 2 = long) */
1796 FALSE
, /* pc_relative */
1798 complain_overflow_dont
, /* complain_on_overflow */
1799 bfd_elf_generic_reloc
, /* special_function */
1800 AARCH64_R_STR (TLSLE_LDST16_TPREL_LO12_NC
), /* name */
1801 FALSE
, /* partial_inplace */
1802 0x1ffc00, /* src_mask */
1803 0x1ffc00, /* dst_mask */
1804 FALSE
), /* pcrel_offset */
1806 /* LD/ST32: bit[11:2] of byte offset to module TLS base address. */
1807 HOWTO (AARCH64_R (TLSLE_LDST32_TPREL_LO12
), /* type */
1809 2, /* size (0 = byte, 1 = short, 2 = long) */
1811 FALSE
, /* pc_relative */
1813 complain_overflow_unsigned
, /* complain_on_overflow */
1814 bfd_elf_generic_reloc
, /* special_function */
1815 AARCH64_R_STR (TLSLE_LDST32_TPREL_LO12
), /* name */
1816 FALSE
, /* partial_inplace */
1817 0xffc00, /* src_mask */
1818 0xffc00, /* dst_mask */
1819 FALSE
), /* pcrel_offset */
1821 /* Same as BFD_RELOC_AARCH64_TLSLE_LDST32_TPREL_LO12, but no overflow check. */
1822 HOWTO (AARCH64_R (TLSLE_LDST32_TPREL_LO12_NC
), /* type */
1824 2, /* size (0 = byte, 1 = short, 2 = long) */
1826 FALSE
, /* pc_relative */
1828 complain_overflow_dont
, /* complain_on_overflow */
1829 bfd_elf_generic_reloc
, /* special_function */
1830 AARCH64_R_STR (TLSLE_LDST32_TPREL_LO12_NC
), /* name */
1831 FALSE
, /* partial_inplace */
1832 0xffc00, /* src_mask */
1833 0xffc00, /* dst_mask */
1834 FALSE
), /* pcrel_offset */
1836 /* LD/ST64: bit[11:3] of byte offset to module TLS base address. */
1837 HOWTO (AARCH64_R (TLSLE_LDST64_TPREL_LO12
), /* type */
1839 2, /* size (0 = byte, 1 = short, 2 = long) */
1841 FALSE
, /* pc_relative */
1843 complain_overflow_unsigned
, /* complain_on_overflow */
1844 bfd_elf_generic_reloc
, /* special_function */
1845 AARCH64_R_STR (TLSLE_LDST64_TPREL_LO12
), /* name */
1846 FALSE
, /* partial_inplace */
1847 0x7fc00, /* src_mask */
1848 0x7fc00, /* dst_mask */
1849 FALSE
), /* pcrel_offset */
1851 /* Same as BFD_RELOC_AARCH64_TLSLE_LDST64_TPREL_LO12, but no overflow check. */
1852 HOWTO (AARCH64_R (TLSLE_LDST64_TPREL_LO12_NC
), /* type */
1854 2, /* size (0 = byte, 1 = short, 2 = long) */
1856 FALSE
, /* pc_relative */
1858 complain_overflow_dont
, /* complain_on_overflow */
1859 bfd_elf_generic_reloc
, /* special_function */
1860 AARCH64_R_STR (TLSLE_LDST64_TPREL_LO12_NC
), /* name */
1861 FALSE
, /* partial_inplace */
1862 0x7fc00, /* src_mask */
1863 0x7fc00, /* dst_mask */
1864 FALSE
), /* pcrel_offset */
1866 /* LD/ST8: bit[11:0] of byte offset to module TLS base address. */
1867 HOWTO (AARCH64_R (TLSLE_LDST8_TPREL_LO12
), /* type */
1869 2, /* size (0 = byte, 1 = short, 2 = long) */
1871 FALSE
, /* pc_relative */
1873 complain_overflow_unsigned
, /* complain_on_overflow */
1874 bfd_elf_generic_reloc
, /* special_function */
1875 AARCH64_R_STR (TLSLE_LDST8_TPREL_LO12
), /* name */
1876 FALSE
, /* partial_inplace */
1877 0x3ffc00, /* src_mask */
1878 0x3ffc00, /* dst_mask */
1879 FALSE
), /* pcrel_offset */
1881 /* Same as BFD_RELOC_AARCH64_TLSLE_LDST8_TPREL_LO12, but no overflow check. */
1882 HOWTO (AARCH64_R (TLSLE_LDST8_TPREL_LO12_NC
), /* type */
1884 2, /* size (0 = byte, 1 = short, 2 = long) */
1886 FALSE
, /* pc_relative */
1888 complain_overflow_dont
, /* complain_on_overflow */
1889 bfd_elf_generic_reloc
, /* special_function */
1890 AARCH64_R_STR (TLSLE_LDST8_TPREL_LO12_NC
), /* name */
1891 FALSE
, /* partial_inplace */
1892 0x3ffc00, /* src_mask */
1893 0x3ffc00, /* dst_mask */
1894 FALSE
), /* pcrel_offset */
1896 HOWTO (AARCH64_R (TLSDESC_LD_PREL19
), /* type */
1898 2, /* size (0 = byte, 1 = short, 2 = long) */
1900 TRUE
, /* pc_relative */
1902 complain_overflow_dont
, /* complain_on_overflow */
1903 bfd_elf_generic_reloc
, /* special_function */
1904 AARCH64_R_STR (TLSDESC_LD_PREL19
), /* name */
1905 FALSE
, /* partial_inplace */
1906 0x0ffffe0, /* src_mask */
1907 0x0ffffe0, /* dst_mask */
1908 TRUE
), /* pcrel_offset */
1910 HOWTO (AARCH64_R (TLSDESC_ADR_PREL21
), /* type */
1912 2, /* size (0 = byte, 1 = short, 2 = long) */
1914 TRUE
, /* pc_relative */
1916 complain_overflow_dont
, /* complain_on_overflow */
1917 bfd_elf_generic_reloc
, /* special_function */
1918 AARCH64_R_STR (TLSDESC_ADR_PREL21
), /* name */
1919 FALSE
, /* partial_inplace */
1920 0x1fffff, /* src_mask */
1921 0x1fffff, /* dst_mask */
1922 TRUE
), /* pcrel_offset */
1924 /* Get to the page for the GOT entry for the symbol
1925 (G(S) - P) using an ADRP instruction. */
1926 HOWTO (AARCH64_R (TLSDESC_ADR_PAGE21
), /* type */
1927 12, /* rightshift */
1928 2, /* size (0 = byte, 1 = short, 2 = long) */
1930 TRUE
, /* pc_relative */
1932 complain_overflow_dont
, /* complain_on_overflow */
1933 bfd_elf_generic_reloc
, /* special_function */
1934 AARCH64_R_STR (TLSDESC_ADR_PAGE21
), /* name */
1935 FALSE
, /* partial_inplace */
1936 0x1fffff, /* src_mask */
1937 0x1fffff, /* dst_mask */
1938 TRUE
), /* pcrel_offset */
1940 /* LD64: GOT offset G(S) & 0xff8. */
1941 HOWTO64 (AARCH64_R (TLSDESC_LD64_LO12
), /* type */
1943 2, /* size (0 = byte, 1 = short, 2 = long) */
1945 FALSE
, /* pc_relative */
1947 complain_overflow_dont
, /* complain_on_overflow */
1948 bfd_elf_generic_reloc
, /* special_function */
1949 AARCH64_R_STR (TLSDESC_LD64_LO12
), /* name */
1950 FALSE
, /* partial_inplace */
1951 0xff8, /* src_mask */
1952 0xff8, /* dst_mask */
1953 FALSE
), /* pcrel_offset */
1955 /* LD32: GOT offset G(S) & 0xffc. */
1956 HOWTO32 (AARCH64_R (TLSDESC_LD32_LO12_NC
), /* type */
1958 2, /* size (0 = byte, 1 = short, 2 = long) */
1960 FALSE
, /* pc_relative */
1962 complain_overflow_dont
, /* complain_on_overflow */
1963 bfd_elf_generic_reloc
, /* special_function */
1964 AARCH64_R_STR (TLSDESC_LD32_LO12_NC
), /* name */
1965 FALSE
, /* partial_inplace */
1966 0xffc, /* src_mask */
1967 0xffc, /* dst_mask */
1968 FALSE
), /* pcrel_offset */
1970 /* ADD: GOT offset G(S) & 0xfff. */
1971 HOWTO (AARCH64_R (TLSDESC_ADD_LO12
), /* type */
1973 2, /* size (0 = byte, 1 = short, 2 = long) */
1975 FALSE
, /* pc_relative */
1977 complain_overflow_dont
,/* complain_on_overflow */
1978 bfd_elf_generic_reloc
, /* special_function */
1979 AARCH64_R_STR (TLSDESC_ADD_LO12
), /* name */
1980 FALSE
, /* partial_inplace */
1981 0xfff, /* src_mask */
1982 0xfff, /* dst_mask */
1983 FALSE
), /* pcrel_offset */
1985 HOWTO64 (AARCH64_R (TLSDESC_OFF_G1
), /* type */
1986 16, /* rightshift */
1987 2, /* size (0 = byte, 1 = short, 2 = long) */
1989 FALSE
, /* pc_relative */
1991 complain_overflow_unsigned
, /* complain_on_overflow */
1992 bfd_elf_generic_reloc
, /* special_function */
1993 AARCH64_R_STR (TLSDESC_OFF_G1
), /* name */
1994 FALSE
, /* partial_inplace */
1995 0xffff, /* src_mask */
1996 0xffff, /* dst_mask */
1997 FALSE
), /* pcrel_offset */
1999 HOWTO64 (AARCH64_R (TLSDESC_OFF_G0_NC
), /* type */
2001 2, /* size (0 = byte, 1 = short, 2 = long) */
2003 FALSE
, /* pc_relative */
2005 complain_overflow_dont
, /* complain_on_overflow */
2006 bfd_elf_generic_reloc
, /* special_function */
2007 AARCH64_R_STR (TLSDESC_OFF_G0_NC
), /* name */
2008 FALSE
, /* partial_inplace */
2009 0xffff, /* src_mask */
2010 0xffff, /* dst_mask */
2011 FALSE
), /* pcrel_offset */
2013 HOWTO64 (AARCH64_R (TLSDESC_LDR
), /* type */
2015 2, /* size (0 = byte, 1 = short, 2 = long) */
2017 FALSE
, /* pc_relative */
2019 complain_overflow_dont
, /* complain_on_overflow */
2020 bfd_elf_generic_reloc
, /* special_function */
2021 AARCH64_R_STR (TLSDESC_LDR
), /* name */
2022 FALSE
, /* partial_inplace */
2025 FALSE
), /* pcrel_offset */
2027 HOWTO64 (AARCH64_R (TLSDESC_ADD
), /* type */
2029 2, /* size (0 = byte, 1 = short, 2 = long) */
2031 FALSE
, /* pc_relative */
2033 complain_overflow_dont
, /* complain_on_overflow */
2034 bfd_elf_generic_reloc
, /* special_function */
2035 AARCH64_R_STR (TLSDESC_ADD
), /* name */
2036 FALSE
, /* partial_inplace */
2039 FALSE
), /* pcrel_offset */
2041 HOWTO (AARCH64_R (TLSDESC_CALL
), /* type */
2043 2, /* size (0 = byte, 1 = short, 2 = long) */
2045 FALSE
, /* pc_relative */
2047 complain_overflow_dont
, /* complain_on_overflow */
2048 bfd_elf_generic_reloc
, /* special_function */
2049 AARCH64_R_STR (TLSDESC_CALL
), /* name */
2050 FALSE
, /* partial_inplace */
2053 FALSE
), /* pcrel_offset */
2055 HOWTO (AARCH64_R (COPY
), /* type */
2057 2, /* size (0 = byte, 1 = short, 2 = long) */
2059 FALSE
, /* pc_relative */
2061 complain_overflow_bitfield
, /* complain_on_overflow */
2062 bfd_elf_generic_reloc
, /* special_function */
2063 AARCH64_R_STR (COPY
), /* name */
2064 TRUE
, /* partial_inplace */
2065 0xffffffff, /* src_mask */
2066 0xffffffff, /* dst_mask */
2067 FALSE
), /* pcrel_offset */
2069 HOWTO (AARCH64_R (GLOB_DAT
), /* type */
2071 2, /* size (0 = byte, 1 = short, 2 = long) */
2073 FALSE
, /* pc_relative */
2075 complain_overflow_bitfield
, /* complain_on_overflow */
2076 bfd_elf_generic_reloc
, /* special_function */
2077 AARCH64_R_STR (GLOB_DAT
), /* name */
2078 TRUE
, /* partial_inplace */
2079 0xffffffff, /* src_mask */
2080 0xffffffff, /* dst_mask */
2081 FALSE
), /* pcrel_offset */
2083 HOWTO (AARCH64_R (JUMP_SLOT
), /* type */
2085 2, /* size (0 = byte, 1 = short, 2 = long) */
2087 FALSE
, /* pc_relative */
2089 complain_overflow_bitfield
, /* complain_on_overflow */
2090 bfd_elf_generic_reloc
, /* special_function */
2091 AARCH64_R_STR (JUMP_SLOT
), /* name */
2092 TRUE
, /* partial_inplace */
2093 0xffffffff, /* src_mask */
2094 0xffffffff, /* dst_mask */
2095 FALSE
), /* pcrel_offset */
2097 HOWTO (AARCH64_R (RELATIVE
), /* type */
2099 2, /* size (0 = byte, 1 = short, 2 = long) */
2101 FALSE
, /* pc_relative */
2103 complain_overflow_bitfield
, /* complain_on_overflow */
2104 bfd_elf_generic_reloc
, /* special_function */
2105 AARCH64_R_STR (RELATIVE
), /* name */
2106 TRUE
, /* partial_inplace */
2107 ALL_ONES
, /* src_mask */
2108 ALL_ONES
, /* dst_mask */
2109 FALSE
), /* pcrel_offset */
2111 HOWTO (AARCH64_R (TLS_DTPMOD
), /* type */
2113 2, /* size (0 = byte, 1 = short, 2 = long) */
2115 FALSE
, /* pc_relative */
2117 complain_overflow_dont
, /* complain_on_overflow */
2118 bfd_elf_generic_reloc
, /* special_function */
2120 AARCH64_R_STR (TLS_DTPMOD64
), /* name */
2122 AARCH64_R_STR (TLS_DTPMOD
), /* name */
2124 FALSE
, /* partial_inplace */
2126 ALL_ONES
, /* dst_mask */
2127 FALSE
), /* pc_reloffset */
2129 HOWTO (AARCH64_R (TLS_DTPREL
), /* type */
2131 2, /* size (0 = byte, 1 = short, 2 = long) */
2133 FALSE
, /* pc_relative */
2135 complain_overflow_dont
, /* complain_on_overflow */
2136 bfd_elf_generic_reloc
, /* special_function */
2138 AARCH64_R_STR (TLS_DTPREL64
), /* name */
2140 AARCH64_R_STR (TLS_DTPREL
), /* name */
2142 FALSE
, /* partial_inplace */
2144 ALL_ONES
, /* dst_mask */
2145 FALSE
), /* pcrel_offset */
2147 HOWTO (AARCH64_R (TLS_TPREL
), /* type */
2149 2, /* size (0 = byte, 1 = short, 2 = long) */
2151 FALSE
, /* pc_relative */
2153 complain_overflow_dont
, /* complain_on_overflow */
2154 bfd_elf_generic_reloc
, /* special_function */
2156 AARCH64_R_STR (TLS_TPREL64
), /* name */
2158 AARCH64_R_STR (TLS_TPREL
), /* name */
2160 FALSE
, /* partial_inplace */
2162 ALL_ONES
, /* dst_mask */
2163 FALSE
), /* pcrel_offset */
2165 HOWTO (AARCH64_R (TLSDESC
), /* type */
2167 2, /* size (0 = byte, 1 = short, 2 = long) */
2169 FALSE
, /* pc_relative */
2171 complain_overflow_dont
, /* complain_on_overflow */
2172 bfd_elf_generic_reloc
, /* special_function */
2173 AARCH64_R_STR (TLSDESC
), /* name */
2174 FALSE
, /* partial_inplace */
2176 ALL_ONES
, /* dst_mask */
2177 FALSE
), /* pcrel_offset */
2179 HOWTO (AARCH64_R (IRELATIVE
), /* type */
2181 2, /* size (0 = byte, 1 = short, 2 = long) */
2183 FALSE
, /* pc_relative */
2185 complain_overflow_bitfield
, /* complain_on_overflow */
2186 bfd_elf_generic_reloc
, /* special_function */
2187 AARCH64_R_STR (IRELATIVE
), /* name */
2188 FALSE
, /* partial_inplace */
2190 ALL_ONES
, /* dst_mask */
2191 FALSE
), /* pcrel_offset */
2196 static reloc_howto_type elfNN_aarch64_howto_none
=
2197 HOWTO (R_AARCH64_NONE
, /* type */
2199 3, /* size (0 = byte, 1 = short, 2 = long) */
2201 FALSE
, /* pc_relative */
2203 complain_overflow_dont
,/* complain_on_overflow */
2204 bfd_elf_generic_reloc
, /* special_function */
2205 "R_AARCH64_NONE", /* name */
2206 FALSE
, /* partial_inplace */
2209 FALSE
); /* pcrel_offset */
2211 /* Given HOWTO, return the bfd internal relocation enumerator. */
2213 static bfd_reloc_code_real_type
2214 elfNN_aarch64_bfd_reloc_from_howto (reloc_howto_type
*howto
)
2217 = (int) ARRAY_SIZE (elfNN_aarch64_howto_table
);
2218 const ptrdiff_t offset
2219 = howto
- elfNN_aarch64_howto_table
;
2221 if (offset
> 0 && offset
< size
- 1)
2222 return BFD_RELOC_AARCH64_RELOC_START
+ offset
;
2224 if (howto
== &elfNN_aarch64_howto_none
)
2225 return BFD_RELOC_AARCH64_NONE
;
2227 return BFD_RELOC_AARCH64_RELOC_START
;
2230 /* Given R_TYPE, return the bfd internal relocation enumerator. */
2232 static bfd_reloc_code_real_type
2233 elfNN_aarch64_bfd_reloc_from_type (bfd
*abfd
, unsigned int r_type
)
2235 static bfd_boolean initialized_p
= FALSE
;
2236 /* Indexed by R_TYPE, values are offsets in the howto_table. */
2237 static unsigned int offsets
[R_AARCH64_end
];
2243 for (i
= 1; i
< ARRAY_SIZE (elfNN_aarch64_howto_table
) - 1; ++i
)
2244 if (elfNN_aarch64_howto_table
[i
].type
!= 0)
2245 offsets
[elfNN_aarch64_howto_table
[i
].type
] = i
;
2247 initialized_p
= TRUE
;
2250 if (r_type
== R_AARCH64_NONE
|| r_type
== R_AARCH64_NULL
)
2251 return BFD_RELOC_AARCH64_NONE
;
2253 /* PR 17512: file: b371e70a. */
2254 if (r_type
>= R_AARCH64_end
)
2256 _bfd_error_handler (_("%pB: unsupported relocation type %#x"),
2258 bfd_set_error (bfd_error_bad_value
);
2259 return BFD_RELOC_AARCH64_NONE
;
2262 return BFD_RELOC_AARCH64_RELOC_START
+ offsets
[r_type
];
2265 struct elf_aarch64_reloc_map
2267 bfd_reloc_code_real_type from
;
2268 bfd_reloc_code_real_type to
;
2271 /* Map bfd generic reloc to AArch64-specific reloc. */
2272 static const struct elf_aarch64_reloc_map elf_aarch64_reloc_map
[] =
2274 {BFD_RELOC_NONE
, BFD_RELOC_AARCH64_NONE
},
2276 /* Basic data relocations. */
2277 {BFD_RELOC_CTOR
, BFD_RELOC_AARCH64_NN
},
2278 {BFD_RELOC_64
, BFD_RELOC_AARCH64_64
},
2279 {BFD_RELOC_32
, BFD_RELOC_AARCH64_32
},
2280 {BFD_RELOC_16
, BFD_RELOC_AARCH64_16
},
2281 {BFD_RELOC_64_PCREL
, BFD_RELOC_AARCH64_64_PCREL
},
2282 {BFD_RELOC_32_PCREL
, BFD_RELOC_AARCH64_32_PCREL
},
2283 {BFD_RELOC_16_PCREL
, BFD_RELOC_AARCH64_16_PCREL
},
2286 /* Given the bfd internal relocation enumerator in CODE, return the
2287 corresponding howto entry. */
2289 static reloc_howto_type
*
2290 elfNN_aarch64_howto_from_bfd_reloc (bfd_reloc_code_real_type code
)
2294 /* Convert bfd generic reloc to AArch64-specific reloc. */
2295 if (code
< BFD_RELOC_AARCH64_RELOC_START
2296 || code
> BFD_RELOC_AARCH64_RELOC_END
)
2297 for (i
= 0; i
< ARRAY_SIZE (elf_aarch64_reloc_map
); i
++)
2298 if (elf_aarch64_reloc_map
[i
].from
== code
)
2300 code
= elf_aarch64_reloc_map
[i
].to
;
2304 if (code
> BFD_RELOC_AARCH64_RELOC_START
2305 && code
< BFD_RELOC_AARCH64_RELOC_END
)
2306 if (elfNN_aarch64_howto_table
[code
- BFD_RELOC_AARCH64_RELOC_START
].type
)
2307 return &elfNN_aarch64_howto_table
[code
- BFD_RELOC_AARCH64_RELOC_START
];
2309 if (code
== BFD_RELOC_AARCH64_NONE
)
2310 return &elfNN_aarch64_howto_none
;
2315 static reloc_howto_type
*
2316 elfNN_aarch64_howto_from_type (bfd
*abfd
, unsigned int r_type
)
2318 bfd_reloc_code_real_type val
;
2319 reloc_howto_type
*howto
;
2324 bfd_set_error (bfd_error_bad_value
);
2329 if (r_type
== R_AARCH64_NONE
)
2330 return &elfNN_aarch64_howto_none
;
2332 val
= elfNN_aarch64_bfd_reloc_from_type (abfd
, r_type
);
2333 howto
= elfNN_aarch64_howto_from_bfd_reloc (val
);
2338 bfd_set_error (bfd_error_bad_value
);
2343 elfNN_aarch64_info_to_howto (bfd
*abfd
, arelent
*bfd_reloc
,
2344 Elf_Internal_Rela
*elf_reloc
)
2346 unsigned int r_type
;
2348 r_type
= ELFNN_R_TYPE (elf_reloc
->r_info
);
2349 bfd_reloc
->howto
= elfNN_aarch64_howto_from_type (abfd
, r_type
);
2351 if (bfd_reloc
->howto
== NULL
)
2353 /* xgettext:c-format */
2354 _bfd_error_handler (_("%pB: unsupported relocation type %#x"), abfd
, r_type
);
2360 static reloc_howto_type
*
2361 elfNN_aarch64_reloc_type_lookup (bfd
*abfd ATTRIBUTE_UNUSED
,
2362 bfd_reloc_code_real_type code
)
2364 reloc_howto_type
*howto
= elfNN_aarch64_howto_from_bfd_reloc (code
);
2369 bfd_set_error (bfd_error_bad_value
);
2373 static reloc_howto_type
*
2374 elfNN_aarch64_reloc_name_lookup (bfd
*abfd ATTRIBUTE_UNUSED
,
2379 for (i
= 1; i
< ARRAY_SIZE (elfNN_aarch64_howto_table
) - 1; ++i
)
2380 if (elfNN_aarch64_howto_table
[i
].name
!= NULL
2381 && strcasecmp (elfNN_aarch64_howto_table
[i
].name
, r_name
) == 0)
2382 return &elfNN_aarch64_howto_table
[i
];
2387 #define TARGET_LITTLE_SYM aarch64_elfNN_le_vec
2388 #define TARGET_LITTLE_NAME "elfNN-littleaarch64"
2389 #define TARGET_BIG_SYM aarch64_elfNN_be_vec
2390 #define TARGET_BIG_NAME "elfNN-bigaarch64"
2392 /* The linker script knows the section names for placement.
2393 The entry_names are used to do simple name mangling on the stubs.
2394 Given a function name, and its type, the stub can be found. The
2395 name can be changed. The only requirement is the %s be present. */
2396 #define STUB_ENTRY_NAME "__%s_veneer"
2398 /* The name of the dynamic interpreter. This is put in the .interp
2400 #define ELF_DYNAMIC_INTERPRETER "/lib/ld.so.1"
2402 #define AARCH64_MAX_FWD_BRANCH_OFFSET \
2403 (((1 << 25) - 1) << 2)
2404 #define AARCH64_MAX_BWD_BRANCH_OFFSET \
2407 #define AARCH64_MAX_ADRP_IMM ((1 << 20) - 1)
2408 #define AARCH64_MIN_ADRP_IMM (-(1 << 20))
2411 aarch64_valid_for_adrp_p (bfd_vma value
, bfd_vma place
)
2413 bfd_signed_vma offset
= (bfd_signed_vma
) (PG (value
) - PG (place
)) >> 12;
2414 return offset
<= AARCH64_MAX_ADRP_IMM
&& offset
>= AARCH64_MIN_ADRP_IMM
;
2418 aarch64_valid_branch_p (bfd_vma value
, bfd_vma place
)
2420 bfd_signed_vma offset
= (bfd_signed_vma
) (value
- place
);
2421 return (offset
<= AARCH64_MAX_FWD_BRANCH_OFFSET
2422 && offset
>= AARCH64_MAX_BWD_BRANCH_OFFSET
);
2425 static const uint32_t aarch64_adrp_branch_stub
[] =
2427 0x90000010, /* adrp ip0, X */
2428 /* R_AARCH64_ADR_HI21_PCREL(X) */
2429 0x91000210, /* add ip0, ip0, :lo12:X */
2430 /* R_AARCH64_ADD_ABS_LO12_NC(X) */
2431 0xd61f0200, /* br ip0 */
2434 static const uint32_t aarch64_long_branch_stub
[] =
2437 0x58000090, /* ldr ip0, 1f */
2439 0x18000090, /* ldr wip0, 1f */
2441 0x10000011, /* adr ip1, #0 */
2442 0x8b110210, /* add ip0, ip0, ip1 */
2443 0xd61f0200, /* br ip0 */
2444 0x00000000, /* 1: .xword or .word
2445 R_AARCH64_PRELNN(X) + 12
2450 static const uint32_t aarch64_erratum_835769_stub
[] =
2452 0x00000000, /* Placeholder for multiply accumulate. */
2453 0x14000000, /* b <label> */
2456 static const uint32_t aarch64_erratum_843419_stub
[] =
2458 0x00000000, /* Placeholder for LDR instruction. */
2459 0x14000000, /* b <label> */
2462 /* Section name for stubs is the associated section name plus this
2464 #define STUB_SUFFIX ".stub"
2466 enum elf_aarch64_stub_type
2469 aarch64_stub_adrp_branch
,
2470 aarch64_stub_long_branch
,
2471 aarch64_stub_erratum_835769_veneer
,
2472 aarch64_stub_erratum_843419_veneer
,
2475 struct elf_aarch64_stub_hash_entry
2477 /* Base hash table entry structure. */
2478 struct bfd_hash_entry root
;
2480 /* The stub section. */
2483 /* Offset within stub_sec of the beginning of this stub. */
2484 bfd_vma stub_offset
;
2486 /* Given the symbol's value and its section we can determine its final
2487 value when building the stubs (so the stub knows where to jump). */
2488 bfd_vma target_value
;
2489 asection
*target_section
;
2491 enum elf_aarch64_stub_type stub_type
;
2493 /* The symbol table entry, if any, that this was derived from. */
2494 struct elf_aarch64_link_hash_entry
*h
;
2496 /* Destination symbol type */
2497 unsigned char st_type
;
2499 /* Where this stub is being called from, or, in the case of combined
2500 stub sections, the first input section in the group. */
2503 /* The name for the local symbol at the start of this stub. The
2504 stub name in the hash table has to be unique; this does not, so
2505 it can be friendlier. */
2508 /* The instruction which caused this stub to be generated (only valid for
2509 erratum 835769 workaround stubs at present). */
2510 uint32_t veneered_insn
;
2512 /* In an erratum 843419 workaround stub, the ADRP instruction offset. */
2513 bfd_vma adrp_offset
;
2516 /* Used to build a map of a section. This is required for mixed-endian
2519 typedef struct elf_elf_section_map
2524 elf_aarch64_section_map
;
2527 typedef struct _aarch64_elf_section_data
2529 struct bfd_elf_section_data elf
;
2530 unsigned int mapcount
;
2531 unsigned int mapsize
;
2532 elf_aarch64_section_map
*map
;
2534 _aarch64_elf_section_data
;
2536 #define elf_aarch64_section_data(sec) \
2537 ((_aarch64_elf_section_data *) elf_section_data (sec))
2539 /* The size of the thread control block which is defined to be two pointers. */
2540 #define TCB_SIZE (ARCH_SIZE/8)*2
2542 struct elf_aarch64_local_symbol
2544 unsigned int got_type
;
2545 bfd_signed_vma got_refcount
;
2548 /* Offset of the GOTPLT entry reserved for the TLS descriptor. The
2549 offset is from the end of the jump table and reserved entries
2552 The magic value (bfd_vma) -1 indicates that an offset has not be
2554 bfd_vma tlsdesc_got_jump_table_offset
;
2557 struct elf_aarch64_obj_tdata
2559 struct elf_obj_tdata root
;
2561 /* local symbol descriptors */
2562 struct elf_aarch64_local_symbol
*locals
;
2564 /* Zero to warn when linking objects with incompatible enum sizes. */
2565 int no_enum_size_warning
;
2567 /* Zero to warn when linking objects with incompatible wchar_t sizes. */
2568 int no_wchar_size_warning
;
2570 /* All GNU_PROPERTY_AARCH64_FEATURE_1_AND properties. */
2571 uint32_t gnu_and_prop
;
2573 /* Zero to warn when linking objects with incompatible
2574 GNU_PROPERTY_AARCH64_FEATURE_1_BTI. */
2577 /* PLT type based on security. */
2578 aarch64_plt_type plt_type
;
2581 #define elf_aarch64_tdata(bfd) \
2582 ((struct elf_aarch64_obj_tdata *) (bfd)->tdata.any)
2584 #define elf_aarch64_locals(bfd) (elf_aarch64_tdata (bfd)->locals)
2586 #define is_aarch64_elf(bfd) \
2587 (bfd_get_flavour (bfd) == bfd_target_elf_flavour \
2588 && elf_tdata (bfd) != NULL \
2589 && elf_object_id (bfd) == AARCH64_ELF_DATA)
2592 elfNN_aarch64_mkobject (bfd
*abfd
)
2594 return bfd_elf_allocate_object (abfd
, sizeof (struct elf_aarch64_obj_tdata
),
2598 #define elf_aarch64_hash_entry(ent) \
2599 ((struct elf_aarch64_link_hash_entry *)(ent))
2601 #define GOT_UNKNOWN 0
2602 #define GOT_NORMAL 1
2603 #define GOT_TLS_GD 2
2604 #define GOT_TLS_IE 4
2605 #define GOT_TLSDESC_GD 8
2607 #define GOT_TLS_GD_ANY_P(type) ((type & GOT_TLS_GD) || (type & GOT_TLSDESC_GD))
2609 /* AArch64 ELF linker hash entry. */
2610 struct elf_aarch64_link_hash_entry
2612 struct elf_link_hash_entry root
;
2614 /* Track dynamic relocs copied for this symbol. */
2615 struct elf_dyn_relocs
*dyn_relocs
;
2617 /* Since PLT entries have variable size, we need to record the
2618 index into .got.plt instead of recomputing it from the PLT
2620 bfd_signed_vma plt_got_offset
;
2622 /* Bit mask representing the type of GOT entry(s) if any required by
2624 unsigned int got_type
;
2626 /* A pointer to the most recently used stub hash entry against this
2628 struct elf_aarch64_stub_hash_entry
*stub_cache
;
2630 /* Offset of the GOTPLT entry reserved for the TLS descriptor. The offset
2631 is from the end of the jump table and reserved entries within the PLTGOT.
2633 The magic value (bfd_vma) -1 indicates that an offset has not
2635 bfd_vma tlsdesc_got_jump_table_offset
;
2639 elfNN_aarch64_symbol_got_type (struct elf_link_hash_entry
*h
,
2641 unsigned long r_symndx
)
2644 return elf_aarch64_hash_entry (h
)->got_type
;
2646 if (! elf_aarch64_locals (abfd
))
2649 return elf_aarch64_locals (abfd
)[r_symndx
].got_type
;
2652 /* Get the AArch64 elf linker hash table from a link_info structure. */
2653 #define elf_aarch64_hash_table(info) \
2654 ((struct elf_aarch64_link_hash_table *) ((info)->hash))
2656 #define aarch64_stub_hash_lookup(table, string, create, copy) \
2657 ((struct elf_aarch64_stub_hash_entry *) \
2658 bfd_hash_lookup ((table), (string), (create), (copy)))
2660 /* AArch64 ELF linker hash table. */
2661 struct elf_aarch64_link_hash_table
2663 /* The main hash table. */
2664 struct elf_link_hash_table root
;
2666 /* Nonzero to force PIC branch veneers. */
2669 /* Fix erratum 835769. */
2670 int fix_erratum_835769
;
2672 /* Fix erratum 843419. */
2673 int fix_erratum_843419
;
2675 /* Enable ADRP->ADR rewrite for erratum 843419 workaround. */
2676 int fix_erratum_843419_adr
;
2678 /* Don't apply link-time values for dynamic relocations. */
2679 int no_apply_dynamic_relocs
;
2681 /* The number of bytes in the initial entry in the PLT. */
2682 bfd_size_type plt_header_size
;
2684 /* The bytes of the initial PLT entry. */
2685 const bfd_byte
*plt0_entry
;
2687 /* The number of bytes in the subsequent PLT entries. */
2688 bfd_size_type plt_entry_size
;
2690 /* The bytes of the subsequent PLT entry. */
2691 const bfd_byte
*plt_entry
;
2693 /* Small local sym cache. */
2694 struct sym_cache sym_cache
;
2696 /* For convenience in allocate_dynrelocs. */
2699 /* The amount of space used by the reserved portion of the sgotplt
2700 section, plus whatever space is used by the jump slots. */
2701 bfd_vma sgotplt_jump_table_size
;
2703 /* The stub hash table. */
2704 struct bfd_hash_table stub_hash_table
;
2706 /* Linker stub bfd. */
2709 /* Linker call-backs. */
2710 asection
*(*add_stub_section
) (const char *, asection
*);
2711 void (*layout_sections_again
) (void);
2713 /* Array to keep track of which stub sections have been created, and
2714 information on stub grouping. */
2717 /* This is the section to which stubs in the group will be
2720 /* The stub section. */
2724 /* Assorted information used by elfNN_aarch64_size_stubs. */
2725 unsigned int bfd_count
;
2726 unsigned int top_index
;
2727 asection
**input_list
;
2729 /* The offset into splt of the PLT entry for the TLS descriptor
2730 resolver. Special values are 0, if not necessary (or not found
2731 to be necessary yet), and -1 if needed but not determined
2733 bfd_vma tlsdesc_plt
;
2735 /* The number of bytes in the PLT enty for the TLS descriptor. */
2736 bfd_size_type tlsdesc_plt_entry_size
;
2738 /* The GOT offset for the lazy trampoline. Communicated to the
2739 loader via DT_TLSDESC_GOT. The magic value (bfd_vma) -1
2740 indicates an offset is not allocated. */
2741 bfd_vma dt_tlsdesc_got
;
2743 /* Used by local STT_GNU_IFUNC symbols. */
2744 htab_t loc_hash_table
;
2745 void * loc_hash_memory
;
2748 /* Create an entry in an AArch64 ELF linker hash table. */
2750 static struct bfd_hash_entry
*
2751 elfNN_aarch64_link_hash_newfunc (struct bfd_hash_entry
*entry
,
2752 struct bfd_hash_table
*table
,
2755 struct elf_aarch64_link_hash_entry
*ret
=
2756 (struct elf_aarch64_link_hash_entry
*) entry
;
2758 /* Allocate the structure if it has not already been allocated by a
2761 ret
= bfd_hash_allocate (table
,
2762 sizeof (struct elf_aarch64_link_hash_entry
));
2764 return (struct bfd_hash_entry
*) ret
;
2766 /* Call the allocation method of the superclass. */
2767 ret
= ((struct elf_aarch64_link_hash_entry
*)
2768 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry
*) ret
,
2772 ret
->dyn_relocs
= NULL
;
2773 ret
->got_type
= GOT_UNKNOWN
;
2774 ret
->plt_got_offset
= (bfd_vma
) - 1;
2775 ret
->stub_cache
= NULL
;
2776 ret
->tlsdesc_got_jump_table_offset
= (bfd_vma
) - 1;
2779 return (struct bfd_hash_entry
*) ret
;
2782 /* Initialize an entry in the stub hash table. */
2784 static struct bfd_hash_entry
*
2785 stub_hash_newfunc (struct bfd_hash_entry
*entry
,
2786 struct bfd_hash_table
*table
, const char *string
)
2788 /* Allocate the structure if it has not already been allocated by a
2792 entry
= bfd_hash_allocate (table
,
2794 elf_aarch64_stub_hash_entry
));
2799 /* Call the allocation method of the superclass. */
2800 entry
= bfd_hash_newfunc (entry
, table
, string
);
2803 struct elf_aarch64_stub_hash_entry
*eh
;
2805 /* Initialize the local fields. */
2806 eh
= (struct elf_aarch64_stub_hash_entry
*) entry
;
2807 eh
->adrp_offset
= 0;
2808 eh
->stub_sec
= NULL
;
2809 eh
->stub_offset
= 0;
2810 eh
->target_value
= 0;
2811 eh
->target_section
= NULL
;
2812 eh
->stub_type
= aarch64_stub_none
;
2820 /* Compute a hash of a local hash entry. We use elf_link_hash_entry
2821 for local symbol so that we can handle local STT_GNU_IFUNC symbols
2822 as global symbol. We reuse indx and dynstr_index for local symbol
2823 hash since they aren't used by global symbols in this backend. */
2826 elfNN_aarch64_local_htab_hash (const void *ptr
)
2828 struct elf_link_hash_entry
*h
2829 = (struct elf_link_hash_entry
*) ptr
;
2830 return ELF_LOCAL_SYMBOL_HASH (h
->indx
, h
->dynstr_index
);
2833 /* Compare local hash entries. */
2836 elfNN_aarch64_local_htab_eq (const void *ptr1
, const void *ptr2
)
2838 struct elf_link_hash_entry
*h1
2839 = (struct elf_link_hash_entry
*) ptr1
;
2840 struct elf_link_hash_entry
*h2
2841 = (struct elf_link_hash_entry
*) ptr2
;
2843 return h1
->indx
== h2
->indx
&& h1
->dynstr_index
== h2
->dynstr_index
;
2846 /* Find and/or create a hash entry for local symbol. */
2848 static struct elf_link_hash_entry
*
2849 elfNN_aarch64_get_local_sym_hash (struct elf_aarch64_link_hash_table
*htab
,
2850 bfd
*abfd
, const Elf_Internal_Rela
*rel
,
2853 struct elf_aarch64_link_hash_entry e
, *ret
;
2854 asection
*sec
= abfd
->sections
;
2855 hashval_t h
= ELF_LOCAL_SYMBOL_HASH (sec
->id
,
2856 ELFNN_R_SYM (rel
->r_info
));
2859 e
.root
.indx
= sec
->id
;
2860 e
.root
.dynstr_index
= ELFNN_R_SYM (rel
->r_info
);
2861 slot
= htab_find_slot_with_hash (htab
->loc_hash_table
, &e
, h
,
2862 create
? INSERT
: NO_INSERT
);
2869 ret
= (struct elf_aarch64_link_hash_entry
*) *slot
;
2873 ret
= (struct elf_aarch64_link_hash_entry
*)
2874 objalloc_alloc ((struct objalloc
*) htab
->loc_hash_memory
,
2875 sizeof (struct elf_aarch64_link_hash_entry
));
2878 memset (ret
, 0, sizeof (*ret
));
2879 ret
->root
.indx
= sec
->id
;
2880 ret
->root
.dynstr_index
= ELFNN_R_SYM (rel
->r_info
);
2881 ret
->root
.dynindx
= -1;
2887 /* Copy the extra info we tack onto an elf_link_hash_entry. */
2890 elfNN_aarch64_copy_indirect_symbol (struct bfd_link_info
*info
,
2891 struct elf_link_hash_entry
*dir
,
2892 struct elf_link_hash_entry
*ind
)
2894 struct elf_aarch64_link_hash_entry
*edir
, *eind
;
2896 edir
= (struct elf_aarch64_link_hash_entry
*) dir
;
2897 eind
= (struct elf_aarch64_link_hash_entry
*) ind
;
2899 if (eind
->dyn_relocs
!= NULL
)
2901 if (edir
->dyn_relocs
!= NULL
)
2903 struct elf_dyn_relocs
**pp
;
2904 struct elf_dyn_relocs
*p
;
2906 /* Add reloc counts against the indirect sym to the direct sym
2907 list. Merge any entries against the same section. */
2908 for (pp
= &eind
->dyn_relocs
; (p
= *pp
) != NULL
;)
2910 struct elf_dyn_relocs
*q
;
2912 for (q
= edir
->dyn_relocs
; q
!= NULL
; q
= q
->next
)
2913 if (q
->sec
== p
->sec
)
2915 q
->pc_count
+= p
->pc_count
;
2916 q
->count
+= p
->count
;
2923 *pp
= edir
->dyn_relocs
;
2926 edir
->dyn_relocs
= eind
->dyn_relocs
;
2927 eind
->dyn_relocs
= NULL
;
2930 if (ind
->root
.type
== bfd_link_hash_indirect
)
2932 /* Copy over PLT info. */
2933 if (dir
->got
.refcount
<= 0)
2935 edir
->got_type
= eind
->got_type
;
2936 eind
->got_type
= GOT_UNKNOWN
;
2940 _bfd_elf_link_hash_copy_indirect (info
, dir
, ind
);
2943 /* Destroy an AArch64 elf linker hash table. */
2946 elfNN_aarch64_link_hash_table_free (bfd
*obfd
)
2948 struct elf_aarch64_link_hash_table
*ret
2949 = (struct elf_aarch64_link_hash_table
*) obfd
->link
.hash
;
2951 if (ret
->loc_hash_table
)
2952 htab_delete (ret
->loc_hash_table
);
2953 if (ret
->loc_hash_memory
)
2954 objalloc_free ((struct objalloc
*) ret
->loc_hash_memory
);
2956 bfd_hash_table_free (&ret
->stub_hash_table
);
2957 _bfd_elf_link_hash_table_free (obfd
);
2960 /* Create an AArch64 elf linker hash table. */
2962 static struct bfd_link_hash_table
*
2963 elfNN_aarch64_link_hash_table_create (bfd
*abfd
)
2965 struct elf_aarch64_link_hash_table
*ret
;
2966 bfd_size_type amt
= sizeof (struct elf_aarch64_link_hash_table
);
2968 ret
= bfd_zmalloc (amt
);
2972 if (!_bfd_elf_link_hash_table_init
2973 (&ret
->root
, abfd
, elfNN_aarch64_link_hash_newfunc
,
2974 sizeof (struct elf_aarch64_link_hash_entry
), AARCH64_ELF_DATA
))
2980 ret
->plt_header_size
= PLT_ENTRY_SIZE
;
2981 ret
->plt0_entry
= elfNN_aarch64_small_plt0_entry
;
2982 ret
->plt_entry_size
= PLT_SMALL_ENTRY_SIZE
;
2983 ret
->plt_entry
= elfNN_aarch64_small_plt_entry
;
2984 ret
->tlsdesc_plt_entry_size
= PLT_TLSDESC_ENTRY_SIZE
;
2986 ret
->dt_tlsdesc_got
= (bfd_vma
) - 1;
2988 if (!bfd_hash_table_init (&ret
->stub_hash_table
, stub_hash_newfunc
,
2989 sizeof (struct elf_aarch64_stub_hash_entry
)))
2991 _bfd_elf_link_hash_table_free (abfd
);
2995 ret
->loc_hash_table
= htab_try_create (1024,
2996 elfNN_aarch64_local_htab_hash
,
2997 elfNN_aarch64_local_htab_eq
,
2999 ret
->loc_hash_memory
= objalloc_create ();
3000 if (!ret
->loc_hash_table
|| !ret
->loc_hash_memory
)
3002 elfNN_aarch64_link_hash_table_free (abfd
);
3005 ret
->root
.root
.hash_table_free
= elfNN_aarch64_link_hash_table_free
;
3007 return &ret
->root
.root
;
3010 /* Perform relocation R_TYPE. Returns TRUE upon success, FALSE otherwise. */
3013 aarch64_relocate (unsigned int r_type
, bfd
*input_bfd
, asection
*input_section
,
3014 bfd_vma offset
, bfd_vma value
)
3016 reloc_howto_type
*howto
;
3019 howto
= elfNN_aarch64_howto_from_type (input_bfd
, r_type
);
3020 place
= (input_section
->output_section
->vma
+ input_section
->output_offset
3023 r_type
= elfNN_aarch64_bfd_reloc_from_type (input_bfd
, r_type
);
3024 value
= _bfd_aarch64_elf_resolve_relocation (r_type
, place
, value
, 0, FALSE
);
3025 return _bfd_aarch64_elf_put_addend (input_bfd
,
3026 input_section
->contents
+ offset
, r_type
,
3027 howto
, value
) == bfd_reloc_ok
;
3030 static enum elf_aarch64_stub_type
3031 aarch64_select_branch_stub (bfd_vma value
, bfd_vma place
)
3033 if (aarch64_valid_for_adrp_p (value
, place
))
3034 return aarch64_stub_adrp_branch
;
3035 return aarch64_stub_long_branch
;
3038 /* Determine the type of stub needed, if any, for a call. */
3040 static enum elf_aarch64_stub_type
3041 aarch64_type_of_stub (asection
*input_sec
,
3042 const Elf_Internal_Rela
*rel
,
3044 unsigned char st_type
,
3045 bfd_vma destination
)
3048 bfd_signed_vma branch_offset
;
3049 unsigned int r_type
;
3050 enum elf_aarch64_stub_type stub_type
= aarch64_stub_none
;
3052 if (st_type
!= STT_FUNC
3053 && (sym_sec
== input_sec
))
3056 /* Determine where the call point is. */
3057 location
= (input_sec
->output_offset
3058 + input_sec
->output_section
->vma
+ rel
->r_offset
);
3060 branch_offset
= (bfd_signed_vma
) (destination
- location
);
3062 r_type
= ELFNN_R_TYPE (rel
->r_info
);
3064 /* We don't want to redirect any old unconditional jump in this way,
3065 only one which is being used for a sibcall, where it is
3066 acceptable for the IP0 and IP1 registers to be clobbered. */
3067 if ((r_type
== AARCH64_R (CALL26
) || r_type
== AARCH64_R (JUMP26
))
3068 && (branch_offset
> AARCH64_MAX_FWD_BRANCH_OFFSET
3069 || branch_offset
< AARCH64_MAX_BWD_BRANCH_OFFSET
))
3071 stub_type
= aarch64_stub_long_branch
;
3077 /* Build a name for an entry in the stub hash table. */
3080 elfNN_aarch64_stub_name (const asection
*input_section
,
3081 const asection
*sym_sec
,
3082 const struct elf_aarch64_link_hash_entry
*hash
,
3083 const Elf_Internal_Rela
*rel
)
3090 len
= 8 + 1 + strlen (hash
->root
.root
.root
.string
) + 1 + 16 + 1;
3091 stub_name
= bfd_malloc (len
);
3092 if (stub_name
!= NULL
)
3093 snprintf (stub_name
, len
, "%08x_%s+%" BFD_VMA_FMT
"x",
3094 (unsigned int) input_section
->id
,
3095 hash
->root
.root
.root
.string
,
3100 len
= 8 + 1 + 8 + 1 + 8 + 1 + 16 + 1;
3101 stub_name
= bfd_malloc (len
);
3102 if (stub_name
!= NULL
)
3103 snprintf (stub_name
, len
, "%08x_%x:%x+%" BFD_VMA_FMT
"x",
3104 (unsigned int) input_section
->id
,
3105 (unsigned int) sym_sec
->id
,
3106 (unsigned int) ELFNN_R_SYM (rel
->r_info
),
3113 /* Return TRUE if symbol H should be hashed in the `.gnu.hash' section. For
3114 executable PLT slots where the executable never takes the address of those
3115 functions, the function symbols are not added to the hash table. */
3118 elf_aarch64_hash_symbol (struct elf_link_hash_entry
*h
)
3120 if (h
->plt
.offset
!= (bfd_vma
) -1
3122 && !h
->pointer_equality_needed
)
3125 return _bfd_elf_hash_symbol (h
);
3129 /* Look up an entry in the stub hash. Stub entries are cached because
3130 creating the stub name takes a bit of time. */
3132 static struct elf_aarch64_stub_hash_entry
*
3133 elfNN_aarch64_get_stub_entry (const asection
*input_section
,
3134 const asection
*sym_sec
,
3135 struct elf_link_hash_entry
*hash
,
3136 const Elf_Internal_Rela
*rel
,
3137 struct elf_aarch64_link_hash_table
*htab
)
3139 struct elf_aarch64_stub_hash_entry
*stub_entry
;
3140 struct elf_aarch64_link_hash_entry
*h
=
3141 (struct elf_aarch64_link_hash_entry
*) hash
;
3142 const asection
*id_sec
;
3144 if ((input_section
->flags
& SEC_CODE
) == 0)
3147 /* If this input section is part of a group of sections sharing one
3148 stub section, then use the id of the first section in the group.
3149 Stub names need to include a section id, as there may well be
3150 more than one stub used to reach say, printf, and we need to
3151 distinguish between them. */
3152 id_sec
= htab
->stub_group
[input_section
->id
].link_sec
;
3154 if (h
!= NULL
&& h
->stub_cache
!= NULL
3155 && h
->stub_cache
->h
== h
&& h
->stub_cache
->id_sec
== id_sec
)
3157 stub_entry
= h
->stub_cache
;
3163 stub_name
= elfNN_aarch64_stub_name (id_sec
, sym_sec
, h
, rel
);
3164 if (stub_name
== NULL
)
3167 stub_entry
= aarch64_stub_hash_lookup (&htab
->stub_hash_table
,
3168 stub_name
, FALSE
, FALSE
);
3170 h
->stub_cache
= stub_entry
;
3179 /* Create a stub section. */
3182 _bfd_aarch64_create_stub_section (asection
*section
,
3183 struct elf_aarch64_link_hash_table
*htab
)
3189 namelen
= strlen (section
->name
);
3190 len
= namelen
+ sizeof (STUB_SUFFIX
);
3191 s_name
= bfd_alloc (htab
->stub_bfd
, len
);
3195 memcpy (s_name
, section
->name
, namelen
);
3196 memcpy (s_name
+ namelen
, STUB_SUFFIX
, sizeof (STUB_SUFFIX
));
3197 return (*htab
->add_stub_section
) (s_name
, section
);
3201 /* Find or create a stub section for a link section.
3203 Fix or create the stub section used to collect stubs attached to
3204 the specified link section. */
3207 _bfd_aarch64_get_stub_for_link_section (asection
*link_section
,
3208 struct elf_aarch64_link_hash_table
*htab
)
3210 if (htab
->stub_group
[link_section
->id
].stub_sec
== NULL
)
3211 htab
->stub_group
[link_section
->id
].stub_sec
3212 = _bfd_aarch64_create_stub_section (link_section
, htab
);
3213 return htab
->stub_group
[link_section
->id
].stub_sec
;
3217 /* Find or create a stub section in the stub group for an input
3221 _bfd_aarch64_create_or_find_stub_sec (asection
*section
,
3222 struct elf_aarch64_link_hash_table
*htab
)
3224 asection
*link_sec
= htab
->stub_group
[section
->id
].link_sec
;
3225 return _bfd_aarch64_get_stub_for_link_section (link_sec
, htab
);
3229 /* Add a new stub entry in the stub group associated with an input
3230 section to the stub hash. Not all fields of the new stub entry are
3233 static struct elf_aarch64_stub_hash_entry
*
3234 _bfd_aarch64_add_stub_entry_in_group (const char *stub_name
,
3236 struct elf_aarch64_link_hash_table
*htab
)
3240 struct elf_aarch64_stub_hash_entry
*stub_entry
;
3242 link_sec
= htab
->stub_group
[section
->id
].link_sec
;
3243 stub_sec
= _bfd_aarch64_create_or_find_stub_sec (section
, htab
);
3245 /* Enter this entry into the linker stub hash table. */
3246 stub_entry
= aarch64_stub_hash_lookup (&htab
->stub_hash_table
, stub_name
,
3248 if (stub_entry
== NULL
)
3250 /* xgettext:c-format */
3251 _bfd_error_handler (_("%pB: cannot create stub entry %s"),
3252 section
->owner
, stub_name
);
3256 stub_entry
->stub_sec
= stub_sec
;
3257 stub_entry
->stub_offset
= 0;
3258 stub_entry
->id_sec
= link_sec
;
3263 /* Add a new stub entry in the final stub section to the stub hash.
3264 Not all fields of the new stub entry are initialised. */
3266 static struct elf_aarch64_stub_hash_entry
*
3267 _bfd_aarch64_add_stub_entry_after (const char *stub_name
,
3268 asection
*link_section
,
3269 struct elf_aarch64_link_hash_table
*htab
)
3272 struct elf_aarch64_stub_hash_entry
*stub_entry
;
3274 stub_sec
= _bfd_aarch64_get_stub_for_link_section (link_section
, htab
);
3275 stub_entry
= aarch64_stub_hash_lookup (&htab
->stub_hash_table
, stub_name
,
3277 if (stub_entry
== NULL
)
3279 _bfd_error_handler (_("cannot create stub entry %s"), stub_name
);
3283 stub_entry
->stub_sec
= stub_sec
;
3284 stub_entry
->stub_offset
= 0;
3285 stub_entry
->id_sec
= link_section
;
3292 aarch64_build_one_stub (struct bfd_hash_entry
*gen_entry
,
3293 void *in_arg ATTRIBUTE_UNUSED
)
3295 struct elf_aarch64_stub_hash_entry
*stub_entry
;
3300 bfd_vma veneered_insn_loc
;
3301 bfd_vma veneer_entry_loc
;
3302 bfd_signed_vma branch_offset
= 0;
3303 unsigned int template_size
;
3304 const uint32_t *template;
3307 /* Massage our args to the form they really have. */
3308 stub_entry
= (struct elf_aarch64_stub_hash_entry
*) gen_entry
;
3310 stub_sec
= stub_entry
->stub_sec
;
3312 /* Make a note of the offset within the stubs for this entry. */
3313 stub_entry
->stub_offset
= stub_sec
->size
;
3314 loc
= stub_sec
->contents
+ stub_entry
->stub_offset
;
3316 stub_bfd
= stub_sec
->owner
;
3318 /* This is the address of the stub destination. */
3319 sym_value
= (stub_entry
->target_value
3320 + stub_entry
->target_section
->output_offset
3321 + stub_entry
->target_section
->output_section
->vma
);
3323 if (stub_entry
->stub_type
== aarch64_stub_long_branch
)
3325 bfd_vma place
= (stub_entry
->stub_offset
+ stub_sec
->output_section
->vma
3326 + stub_sec
->output_offset
);
3328 /* See if we can relax the stub. */
3329 if (aarch64_valid_for_adrp_p (sym_value
, place
))
3330 stub_entry
->stub_type
= aarch64_select_branch_stub (sym_value
, place
);
3333 switch (stub_entry
->stub_type
)
3335 case aarch64_stub_adrp_branch
:
3336 template = aarch64_adrp_branch_stub
;
3337 template_size
= sizeof (aarch64_adrp_branch_stub
);
3339 case aarch64_stub_long_branch
:
3340 template = aarch64_long_branch_stub
;
3341 template_size
= sizeof (aarch64_long_branch_stub
);
3343 case aarch64_stub_erratum_835769_veneer
:
3344 template = aarch64_erratum_835769_stub
;
3345 template_size
= sizeof (aarch64_erratum_835769_stub
);
3347 case aarch64_stub_erratum_843419_veneer
:
3348 template = aarch64_erratum_843419_stub
;
3349 template_size
= sizeof (aarch64_erratum_843419_stub
);
3355 for (i
= 0; i
< (template_size
/ sizeof template[0]); i
++)
3357 bfd_putl32 (template[i
], loc
);
3361 template_size
= (template_size
+ 7) & ~7;
3362 stub_sec
->size
+= template_size
;
3364 switch (stub_entry
->stub_type
)
3366 case aarch64_stub_adrp_branch
:
3367 if (!aarch64_relocate (AARCH64_R (ADR_PREL_PG_HI21
), stub_bfd
, stub_sec
,
3368 stub_entry
->stub_offset
, sym_value
))
3369 /* The stub would not have been relaxed if the offset was out
3373 if (!aarch64_relocate (AARCH64_R (ADD_ABS_LO12_NC
), stub_bfd
, stub_sec
,
3374 stub_entry
->stub_offset
+ 4, sym_value
))
3378 case aarch64_stub_long_branch
:
3379 /* We want the value relative to the address 12 bytes back from the
3381 if (!aarch64_relocate (AARCH64_R (PRELNN
), stub_bfd
, stub_sec
,
3382 stub_entry
->stub_offset
+ 16, sym_value
+ 12))
3386 case aarch64_stub_erratum_835769_veneer
:
3387 veneered_insn_loc
= stub_entry
->target_section
->output_section
->vma
3388 + stub_entry
->target_section
->output_offset
3389 + stub_entry
->target_value
;
3390 veneer_entry_loc
= stub_entry
->stub_sec
->output_section
->vma
3391 + stub_entry
->stub_sec
->output_offset
3392 + stub_entry
->stub_offset
;
3393 branch_offset
= veneered_insn_loc
- veneer_entry_loc
;
3394 branch_offset
>>= 2;
3395 branch_offset
&= 0x3ffffff;
3396 bfd_putl32 (stub_entry
->veneered_insn
,
3397 stub_sec
->contents
+ stub_entry
->stub_offset
);
3398 bfd_putl32 (template[1] | branch_offset
,
3399 stub_sec
->contents
+ stub_entry
->stub_offset
+ 4);
3402 case aarch64_stub_erratum_843419_veneer
:
3403 if (!aarch64_relocate (AARCH64_R (JUMP26
), stub_bfd
, stub_sec
,
3404 stub_entry
->stub_offset
+ 4, sym_value
+ 4))
3415 /* As above, but don't actually build the stub. Just bump offset so
3416 we know stub section sizes. */
3419 aarch64_size_one_stub (struct bfd_hash_entry
*gen_entry
,
3420 void *in_arg ATTRIBUTE_UNUSED
)
3422 struct elf_aarch64_stub_hash_entry
*stub_entry
;
3425 /* Massage our args to the form they really have. */
3426 stub_entry
= (struct elf_aarch64_stub_hash_entry
*) gen_entry
;
3428 switch (stub_entry
->stub_type
)
3430 case aarch64_stub_adrp_branch
:
3431 size
= sizeof (aarch64_adrp_branch_stub
);
3433 case aarch64_stub_long_branch
:
3434 size
= sizeof (aarch64_long_branch_stub
);
3436 case aarch64_stub_erratum_835769_veneer
:
3437 size
= sizeof (aarch64_erratum_835769_stub
);
3439 case aarch64_stub_erratum_843419_veneer
:
3440 size
= sizeof (aarch64_erratum_843419_stub
);
3446 size
= (size
+ 7) & ~7;
3447 stub_entry
->stub_sec
->size
+= size
;
3451 /* External entry points for sizing and building linker stubs. */
3453 /* Set up various things so that we can make a list of input sections
3454 for each output section included in the link. Returns -1 on error,
3455 0 when no stubs will be needed, and 1 on success. */
3458 elfNN_aarch64_setup_section_lists (bfd
*output_bfd
,
3459 struct bfd_link_info
*info
)
3462 unsigned int bfd_count
;
3463 unsigned int top_id
, top_index
;
3465 asection
**input_list
, **list
;
3467 struct elf_aarch64_link_hash_table
*htab
=
3468 elf_aarch64_hash_table (info
);
3470 if (!is_elf_hash_table (htab
))
3473 /* Count the number of input BFDs and find the top input section id. */
3474 for (input_bfd
= info
->input_bfds
, bfd_count
= 0, top_id
= 0;
3475 input_bfd
!= NULL
; input_bfd
= input_bfd
->link
.next
)
3478 for (section
= input_bfd
->sections
;
3479 section
!= NULL
; section
= section
->next
)
3481 if (top_id
< section
->id
)
3482 top_id
= section
->id
;
3485 htab
->bfd_count
= bfd_count
;
3487 amt
= sizeof (struct map_stub
) * (top_id
+ 1);
3488 htab
->stub_group
= bfd_zmalloc (amt
);
3489 if (htab
->stub_group
== NULL
)
3492 /* We can't use output_bfd->section_count here to find the top output
3493 section index as some sections may have been removed, and
3494 _bfd_strip_section_from_output doesn't renumber the indices. */
3495 for (section
= output_bfd
->sections
, top_index
= 0;
3496 section
!= NULL
; section
= section
->next
)
3498 if (top_index
< section
->index
)
3499 top_index
= section
->index
;
3502 htab
->top_index
= top_index
;
3503 amt
= sizeof (asection
*) * (top_index
+ 1);
3504 input_list
= bfd_malloc (amt
);
3505 htab
->input_list
= input_list
;
3506 if (input_list
== NULL
)
3509 /* For sections we aren't interested in, mark their entries with a
3510 value we can check later. */
3511 list
= input_list
+ top_index
;
3513 *list
= bfd_abs_section_ptr
;
3514 while (list
-- != input_list
);
3516 for (section
= output_bfd
->sections
;
3517 section
!= NULL
; section
= section
->next
)
3519 if ((section
->flags
& SEC_CODE
) != 0)
3520 input_list
[section
->index
] = NULL
;
3526 /* Used by elfNN_aarch64_next_input_section and group_sections. */
3527 #define PREV_SEC(sec) (htab->stub_group[(sec)->id].link_sec)
3529 /* The linker repeatedly calls this function for each input section,
3530 in the order that input sections are linked into output sections.
3531 Build lists of input sections to determine groupings between which
3532 we may insert linker stubs. */
3535 elfNN_aarch64_next_input_section (struct bfd_link_info
*info
, asection
*isec
)
3537 struct elf_aarch64_link_hash_table
*htab
=
3538 elf_aarch64_hash_table (info
);
3540 if (isec
->output_section
->index
<= htab
->top_index
)
3542 asection
**list
= htab
->input_list
+ isec
->output_section
->index
;
3544 if (*list
!= bfd_abs_section_ptr
)
3546 /* Steal the link_sec pointer for our list. */
3547 /* This happens to make the list in reverse order,
3548 which is what we want. */
3549 PREV_SEC (isec
) = *list
;
3555 /* See whether we can group stub sections together. Grouping stub
3556 sections may result in fewer stubs. More importantly, we need to
3557 put all .init* and .fini* stubs at the beginning of the .init or
3558 .fini output sections respectively, because glibc splits the
3559 _init and _fini functions into multiple parts. Putting a stub in
3560 the middle of a function is not a good idea. */
3563 group_sections (struct elf_aarch64_link_hash_table
*htab
,
3564 bfd_size_type stub_group_size
,
3565 bfd_boolean stubs_always_before_branch
)
3567 asection
**list
= htab
->input_list
+ htab
->top_index
;
3571 asection
*tail
= *list
;
3573 if (tail
== bfd_abs_section_ptr
)
3576 while (tail
!= NULL
)
3580 bfd_size_type total
;
3584 while ((prev
= PREV_SEC (curr
)) != NULL
3585 && ((total
+= curr
->output_offset
- prev
->output_offset
)
3589 /* OK, the size from the start of CURR to the end is less
3590 than stub_group_size and thus can be handled by one stub
3591 section. (Or the tail section is itself larger than
3592 stub_group_size, in which case we may be toast.)
3593 We should really be keeping track of the total size of
3594 stubs added here, as stubs contribute to the final output
3598 prev
= PREV_SEC (tail
);
3599 /* Set up this stub group. */
3600 htab
->stub_group
[tail
->id
].link_sec
= curr
;
3602 while (tail
!= curr
&& (tail
= prev
) != NULL
);
3604 /* But wait, there's more! Input sections up to stub_group_size
3605 bytes before the stub section can be handled by it too. */
3606 if (!stubs_always_before_branch
)
3610 && ((total
+= tail
->output_offset
- prev
->output_offset
)
3614 prev
= PREV_SEC (tail
);
3615 htab
->stub_group
[tail
->id
].link_sec
= curr
;
3621 while (list
-- != htab
->input_list
);
3623 free (htab
->input_list
);
3628 #define AARCH64_BITS(x, pos, n) (((x) >> (pos)) & ((1 << (n)) - 1))
3630 #define AARCH64_RT(insn) AARCH64_BITS (insn, 0, 5)
3631 #define AARCH64_RT2(insn) AARCH64_BITS (insn, 10, 5)
3632 #define AARCH64_RA(insn) AARCH64_BITS (insn, 10, 5)
3633 #define AARCH64_RD(insn) AARCH64_BITS (insn, 0, 5)
3634 #define AARCH64_RN(insn) AARCH64_BITS (insn, 5, 5)
3635 #define AARCH64_RM(insn) AARCH64_BITS (insn, 16, 5)
3637 #define AARCH64_MAC(insn) (((insn) & 0xff000000) == 0x9b000000)
3638 #define AARCH64_BIT(insn, n) AARCH64_BITS (insn, n, 1)
3639 #define AARCH64_OP31(insn) AARCH64_BITS (insn, 21, 3)
3640 #define AARCH64_ZR 0x1f
3642 /* All ld/st ops. See C4-182 of the ARM ARM. The encoding space for
3643 LD_PCREL, LDST_RO, LDST_UI and LDST_UIMM cover prefetch ops. */
3645 #define AARCH64_LD(insn) (AARCH64_BIT (insn, 22) == 1)
3646 #define AARCH64_LDST(insn) (((insn) & 0x0a000000) == 0x08000000)
3647 #define AARCH64_LDST_EX(insn) (((insn) & 0x3f000000) == 0x08000000)
3648 #define AARCH64_LDST_PCREL(insn) (((insn) & 0x3b000000) == 0x18000000)
3649 #define AARCH64_LDST_NAP(insn) (((insn) & 0x3b800000) == 0x28000000)
3650 #define AARCH64_LDSTP_PI(insn) (((insn) & 0x3b800000) == 0x28800000)
3651 #define AARCH64_LDSTP_O(insn) (((insn) & 0x3b800000) == 0x29000000)
3652 #define AARCH64_LDSTP_PRE(insn) (((insn) & 0x3b800000) == 0x29800000)
3653 #define AARCH64_LDST_UI(insn) (((insn) & 0x3b200c00) == 0x38000000)
3654 #define AARCH64_LDST_PIIMM(insn) (((insn) & 0x3b200c00) == 0x38000400)
3655 #define AARCH64_LDST_U(insn) (((insn) & 0x3b200c00) == 0x38000800)
3656 #define AARCH64_LDST_PREIMM(insn) (((insn) & 0x3b200c00) == 0x38000c00)
3657 #define AARCH64_LDST_RO(insn) (((insn) & 0x3b200c00) == 0x38200800)
3658 #define AARCH64_LDST_UIMM(insn) (((insn) & 0x3b000000) == 0x39000000)
3659 #define AARCH64_LDST_SIMD_M(insn) (((insn) & 0xbfbf0000) == 0x0c000000)
3660 #define AARCH64_LDST_SIMD_M_PI(insn) (((insn) & 0xbfa00000) == 0x0c800000)
3661 #define AARCH64_LDST_SIMD_S(insn) (((insn) & 0xbf9f0000) == 0x0d000000)
3662 #define AARCH64_LDST_SIMD_S_PI(insn) (((insn) & 0xbf800000) == 0x0d800000)
3664 /* Classify an INSN if it is indeed a load/store.
3666 Return TRUE if INSN is a LD/ST instruction otherwise return FALSE.
3668 For scalar LD/ST instructions PAIR is FALSE, RT is returned and RT2
3671 For LD/ST pair instructions PAIR is TRUE, RT and RT2 are returned. */
3674 aarch64_mem_op_p (uint32_t insn
, unsigned int *rt
, unsigned int *rt2
,
3675 bfd_boolean
*pair
, bfd_boolean
*load
)
3683 /* Bail out quickly if INSN doesn't fall into the load-store
3685 if (!AARCH64_LDST (insn
))
3690 if (AARCH64_LDST_EX (insn
))
3692 *rt
= AARCH64_RT (insn
);
3694 if (AARCH64_BIT (insn
, 21) == 1)
3697 *rt2
= AARCH64_RT2 (insn
);
3699 *load
= AARCH64_LD (insn
);
3702 else if (AARCH64_LDST_NAP (insn
)
3703 || AARCH64_LDSTP_PI (insn
)
3704 || AARCH64_LDSTP_O (insn
)
3705 || AARCH64_LDSTP_PRE (insn
))
3708 *rt
= AARCH64_RT (insn
);
3709 *rt2
= AARCH64_RT2 (insn
);
3710 *load
= AARCH64_LD (insn
);
3713 else if (AARCH64_LDST_PCREL (insn
)
3714 || AARCH64_LDST_UI (insn
)
3715 || AARCH64_LDST_PIIMM (insn
)
3716 || AARCH64_LDST_U (insn
)
3717 || AARCH64_LDST_PREIMM (insn
)
3718 || AARCH64_LDST_RO (insn
)
3719 || AARCH64_LDST_UIMM (insn
))
3721 *rt
= AARCH64_RT (insn
);
3723 if (AARCH64_LDST_PCREL (insn
))
3725 opc
= AARCH64_BITS (insn
, 22, 2);
3726 v
= AARCH64_BIT (insn
, 26);
3727 opc_v
= opc
| (v
<< 2);
3728 *load
= (opc_v
== 1 || opc_v
== 2 || opc_v
== 3
3729 || opc_v
== 5 || opc_v
== 7);
3732 else if (AARCH64_LDST_SIMD_M (insn
)
3733 || AARCH64_LDST_SIMD_M_PI (insn
))
3735 *rt
= AARCH64_RT (insn
);
3736 *load
= AARCH64_BIT (insn
, 22);
3737 opcode
= (insn
>> 12) & 0xf;
3764 else if (AARCH64_LDST_SIMD_S (insn
)
3765 || AARCH64_LDST_SIMD_S_PI (insn
))
3767 *rt
= AARCH64_RT (insn
);
3768 r
= (insn
>> 21) & 1;
3769 *load
= AARCH64_BIT (insn
, 22);
3770 opcode
= (insn
>> 13) & 0x7;
3782 *rt2
= *rt
+ (r
== 0 ? 2 : 3);
3790 *rt2
= *rt
+ (r
== 0 ? 2 : 3);
3802 /* Return TRUE if INSN is multiply-accumulate. */
3805 aarch64_mlxl_p (uint32_t insn
)
3807 uint32_t op31
= AARCH64_OP31 (insn
);
3809 if (AARCH64_MAC (insn
)
3810 && (op31
== 0 || op31
== 1 || op31
== 5)
3811 /* Exclude MUL instructions which are encoded as a multiple accumulate
3813 && AARCH64_RA (insn
) != AARCH64_ZR
)
3819 /* Some early revisions of the Cortex-A53 have an erratum (835769) whereby
3820 it is possible for a 64-bit multiply-accumulate instruction to generate an
3821 incorrect result. The details are quite complex and hard to
3822 determine statically, since branches in the code may exist in some
3823 circumstances, but all cases end with a memory (load, store, or
3824 prefetch) instruction followed immediately by the multiply-accumulate
3825 operation. We employ a linker patching technique, by moving the potentially
3826 affected multiply-accumulate instruction into a patch region and replacing
3827 the original instruction with a branch to the patch. This function checks
3828 if INSN_1 is the memory operation followed by a multiply-accumulate
3829 operation (INSN_2). Return TRUE if an erratum sequence is found, FALSE
3830 if INSN_1 and INSN_2 are safe. */
3833 aarch64_erratum_sequence (uint32_t insn_1
, uint32_t insn_2
)
3843 if (aarch64_mlxl_p (insn_2
)
3844 && aarch64_mem_op_p (insn_1
, &rt
, &rt2
, &pair
, &load
))
3846 /* Any SIMD memory op is independent of the subsequent MLA
3847 by definition of the erratum. */
3848 if (AARCH64_BIT (insn_1
, 26))
3851 /* If not SIMD, check for integer memory ops and MLA relationship. */
3852 rn
= AARCH64_RN (insn_2
);
3853 ra
= AARCH64_RA (insn_2
);
3854 rm
= AARCH64_RM (insn_2
);
3856 /* If this is a load and there's a true(RAW) dependency, we are safe
3857 and this is not an erratum sequence. */
3859 (rt
== rn
|| rt
== rm
|| rt
== ra
3860 || (pair
&& (rt2
== rn
|| rt2
== rm
|| rt2
== ra
))))
3863 /* We conservatively put out stubs for all other cases (including
3871 /* Used to order a list of mapping symbols by address. */
3874 elf_aarch64_compare_mapping (const void *a
, const void *b
)
3876 const elf_aarch64_section_map
*amap
= (const elf_aarch64_section_map
*) a
;
3877 const elf_aarch64_section_map
*bmap
= (const elf_aarch64_section_map
*) b
;
3879 if (amap
->vma
> bmap
->vma
)
3881 else if (amap
->vma
< bmap
->vma
)
3883 else if (amap
->type
> bmap
->type
)
3884 /* Ensure results do not depend on the host qsort for objects with
3885 multiple mapping symbols at the same address by sorting on type
3888 else if (amap
->type
< bmap
->type
)
3896 _bfd_aarch64_erratum_835769_stub_name (unsigned num_fixes
)
3898 char *stub_name
= (char *) bfd_malloc
3899 (strlen ("__erratum_835769_veneer_") + 16);
3900 if (stub_name
!= NULL
)
3901 sprintf (stub_name
,"__erratum_835769_veneer_%d", num_fixes
);
3905 /* Scan for Cortex-A53 erratum 835769 sequence.
3907 Return TRUE else FALSE on abnormal termination. */
3910 _bfd_aarch64_erratum_835769_scan (bfd
*input_bfd
,
3911 struct bfd_link_info
*info
,
3912 unsigned int *num_fixes_p
)
3915 struct elf_aarch64_link_hash_table
*htab
= elf_aarch64_hash_table (info
);
3916 unsigned int num_fixes
= *num_fixes_p
;
3921 for (section
= input_bfd
->sections
;
3923 section
= section
->next
)
3925 bfd_byte
*contents
= NULL
;
3926 struct _aarch64_elf_section_data
*sec_data
;
3929 if (elf_section_type (section
) != SHT_PROGBITS
3930 || (elf_section_flags (section
) & SHF_EXECINSTR
) == 0
3931 || (section
->flags
& SEC_EXCLUDE
) != 0
3932 || (section
->sec_info_type
== SEC_INFO_TYPE_JUST_SYMS
)
3933 || (section
->output_section
== bfd_abs_section_ptr
))
3936 if (elf_section_data (section
)->this_hdr
.contents
!= NULL
)
3937 contents
= elf_section_data (section
)->this_hdr
.contents
;
3938 else if (! bfd_malloc_and_get_section (input_bfd
, section
, &contents
))
3941 sec_data
= elf_aarch64_section_data (section
);
3943 qsort (sec_data
->map
, sec_data
->mapcount
,
3944 sizeof (elf_aarch64_section_map
), elf_aarch64_compare_mapping
);
3946 for (span
= 0; span
< sec_data
->mapcount
; span
++)
3948 unsigned int span_start
= sec_data
->map
[span
].vma
;
3949 unsigned int span_end
= ((span
== sec_data
->mapcount
- 1)
3950 ? sec_data
->map
[0].vma
+ section
->size
3951 : sec_data
->map
[span
+ 1].vma
);
3953 char span_type
= sec_data
->map
[span
].type
;
3955 if (span_type
== 'd')
3958 for (i
= span_start
; i
+ 4 < span_end
; i
+= 4)
3960 uint32_t insn_1
= bfd_getl32 (contents
+ i
);
3961 uint32_t insn_2
= bfd_getl32 (contents
+ i
+ 4);
3963 if (aarch64_erratum_sequence (insn_1
, insn_2
))
3965 struct elf_aarch64_stub_hash_entry
*stub_entry
;
3966 char *stub_name
= _bfd_aarch64_erratum_835769_stub_name (num_fixes
);
3970 stub_entry
= _bfd_aarch64_add_stub_entry_in_group (stub_name
,
3976 stub_entry
->stub_type
= aarch64_stub_erratum_835769_veneer
;
3977 stub_entry
->target_section
= section
;
3978 stub_entry
->target_value
= i
+ 4;
3979 stub_entry
->veneered_insn
= insn_2
;
3980 stub_entry
->output_name
= stub_name
;
3985 if (elf_section_data (section
)->this_hdr
.contents
== NULL
)
3989 *num_fixes_p
= num_fixes
;
3995 /* Test if instruction INSN is ADRP. */
3998 _bfd_aarch64_adrp_p (uint32_t insn
)
4000 return ((insn
& AARCH64_ADRP_OP_MASK
) == AARCH64_ADRP_OP
);
4004 /* Helper predicate to look for cortex-a53 erratum 843419 sequence 1. */
4007 _bfd_aarch64_erratum_843419_sequence_p (uint32_t insn_1
, uint32_t insn_2
,
4015 return (aarch64_mem_op_p (insn_2
, &rt
, &rt2
, &pair
, &load
)
4018 && AARCH64_LDST_UIMM (insn_3
)
4019 && AARCH64_RN (insn_3
) == AARCH64_RD (insn_1
));
4023 /* Test for the presence of Cortex-A53 erratum 843419 instruction sequence.
4025 Return TRUE if section CONTENTS at offset I contains one of the
4026 erratum 843419 sequences, otherwise return FALSE. If a sequence is
4027 seen set P_VENEER_I to the offset of the final LOAD/STORE
4028 instruction in the sequence.
4032 _bfd_aarch64_erratum_843419_p (bfd_byte
*contents
, bfd_vma vma
,
4033 bfd_vma i
, bfd_vma span_end
,
4034 bfd_vma
*p_veneer_i
)
4036 uint32_t insn_1
= bfd_getl32 (contents
+ i
);
4038 if (!_bfd_aarch64_adrp_p (insn_1
))
4041 if (span_end
< i
+ 12)
4044 uint32_t insn_2
= bfd_getl32 (contents
+ i
+ 4);
4045 uint32_t insn_3
= bfd_getl32 (contents
+ i
+ 8);
4047 if ((vma
& 0xfff) != 0xff8 && (vma
& 0xfff) != 0xffc)
4050 if (_bfd_aarch64_erratum_843419_sequence_p (insn_1
, insn_2
, insn_3
))
4052 *p_veneer_i
= i
+ 8;
4056 if (span_end
< i
+ 16)
4059 uint32_t insn_4
= bfd_getl32 (contents
+ i
+ 12);
4061 if (_bfd_aarch64_erratum_843419_sequence_p (insn_1
, insn_2
, insn_4
))
4063 *p_veneer_i
= i
+ 12;
4071 /* Resize all stub sections. */
4074 _bfd_aarch64_resize_stubs (struct elf_aarch64_link_hash_table
*htab
)
4078 /* OK, we've added some stubs. Find out the new size of the
4080 for (section
= htab
->stub_bfd
->sections
;
4081 section
!= NULL
; section
= section
->next
)
4083 /* Ignore non-stub sections. */
4084 if (!strstr (section
->name
, STUB_SUFFIX
))
4089 bfd_hash_traverse (&htab
->stub_hash_table
, aarch64_size_one_stub
, htab
);
4091 for (section
= htab
->stub_bfd
->sections
;
4092 section
!= NULL
; section
= section
->next
)
4094 if (!strstr (section
->name
, STUB_SUFFIX
))
4097 /* Add space for a branch. Add 8 bytes to keep section 8 byte aligned,
4098 as long branch stubs contain a 64-bit address. */
4102 /* Ensure all stub sections have a size which is a multiple of
4103 4096. This is important in order to ensure that the insertion
4104 of stub sections does not in itself move existing code around
4105 in such a way that new errata sequences are created. */
4106 if (htab
->fix_erratum_843419
)
4108 section
->size
= BFD_ALIGN (section
->size
, 0x1000);
4112 /* Construct an erratum 843419 workaround stub name. */
4115 _bfd_aarch64_erratum_843419_stub_name (asection
*input_section
,
4118 const bfd_size_type len
= 8 + 4 + 1 + 8 + 1 + 16 + 1;
4119 char *stub_name
= bfd_malloc (len
);
4121 if (stub_name
!= NULL
)
4122 snprintf (stub_name
, len
, "e843419@%04x_%08x_%" BFD_VMA_FMT
"x",
4123 input_section
->owner
->id
,
4129 /* Build a stub_entry structure describing an 843419 fixup.
4131 The stub_entry constructed is populated with the bit pattern INSN
4132 of the instruction located at OFFSET within input SECTION.
4134 Returns TRUE on success. */
4137 _bfd_aarch64_erratum_843419_fixup (uint32_t insn
,
4138 bfd_vma adrp_offset
,
4139 bfd_vma ldst_offset
,
4141 struct bfd_link_info
*info
)
4143 struct elf_aarch64_link_hash_table
*htab
= elf_aarch64_hash_table (info
);
4145 struct elf_aarch64_stub_hash_entry
*stub_entry
;
4147 stub_name
= _bfd_aarch64_erratum_843419_stub_name (section
, ldst_offset
);
4148 if (stub_name
== NULL
)
4150 stub_entry
= aarch64_stub_hash_lookup (&htab
->stub_hash_table
, stub_name
,
4158 /* We always place an 843419 workaround veneer in the stub section
4159 attached to the input section in which an erratum sequence has
4160 been found. This ensures that later in the link process (in
4161 elfNN_aarch64_write_section) when we copy the veneered
4162 instruction from the input section into the stub section the
4163 copied instruction will have had any relocations applied to it.
4164 If we placed workaround veneers in any other stub section then we
4165 could not assume that all relocations have been processed on the
4166 corresponding input section at the point we output the stub
4169 stub_entry
= _bfd_aarch64_add_stub_entry_after (stub_name
, section
, htab
);
4170 if (stub_entry
== NULL
)
4176 stub_entry
->adrp_offset
= adrp_offset
;
4177 stub_entry
->target_value
= ldst_offset
;
4178 stub_entry
->target_section
= section
;
4179 stub_entry
->stub_type
= aarch64_stub_erratum_843419_veneer
;
4180 stub_entry
->veneered_insn
= insn
;
4181 stub_entry
->output_name
= stub_name
;
4187 /* Scan an input section looking for the signature of erratum 843419.
4189 Scans input SECTION in INPUT_BFD looking for erratum 843419
4190 signatures, for each signature found a stub_entry is created
4191 describing the location of the erratum for subsequent fixup.
4193 Return TRUE on successful scan, FALSE on failure to scan.
4197 _bfd_aarch64_erratum_843419_scan (bfd
*input_bfd
, asection
*section
,
4198 struct bfd_link_info
*info
)
4200 struct elf_aarch64_link_hash_table
*htab
= elf_aarch64_hash_table (info
);
4205 if (elf_section_type (section
) != SHT_PROGBITS
4206 || (elf_section_flags (section
) & SHF_EXECINSTR
) == 0
4207 || (section
->flags
& SEC_EXCLUDE
) != 0
4208 || (section
->sec_info_type
== SEC_INFO_TYPE_JUST_SYMS
)
4209 || (section
->output_section
== bfd_abs_section_ptr
))
4214 bfd_byte
*contents
= NULL
;
4215 struct _aarch64_elf_section_data
*sec_data
;
4218 if (elf_section_data (section
)->this_hdr
.contents
!= NULL
)
4219 contents
= elf_section_data (section
)->this_hdr
.contents
;
4220 else if (! bfd_malloc_and_get_section (input_bfd
, section
, &contents
))
4223 sec_data
= elf_aarch64_section_data (section
);
4225 qsort (sec_data
->map
, sec_data
->mapcount
,
4226 sizeof (elf_aarch64_section_map
), elf_aarch64_compare_mapping
);
4228 for (span
= 0; span
< sec_data
->mapcount
; span
++)
4230 unsigned int span_start
= sec_data
->map
[span
].vma
;
4231 unsigned int span_end
= ((span
== sec_data
->mapcount
- 1)
4232 ? sec_data
->map
[0].vma
+ section
->size
4233 : sec_data
->map
[span
+ 1].vma
);
4235 char span_type
= sec_data
->map
[span
].type
;
4237 if (span_type
== 'd')
4240 for (i
= span_start
; i
+ 8 < span_end
; i
+= 4)
4242 bfd_vma vma
= (section
->output_section
->vma
4243 + section
->output_offset
4247 if (_bfd_aarch64_erratum_843419_p
4248 (contents
, vma
, i
, span_end
, &veneer_i
))
4250 uint32_t insn
= bfd_getl32 (contents
+ veneer_i
);
4252 if (!_bfd_aarch64_erratum_843419_fixup (insn
, i
, veneer_i
,
4259 if (elf_section_data (section
)->this_hdr
.contents
== NULL
)
4268 /* Determine and set the size of the stub section for a final link.
4270 The basic idea here is to examine all the relocations looking for
4271 PC-relative calls to a target that is unreachable with a "bl"
4275 elfNN_aarch64_size_stubs (bfd
*output_bfd
,
4277 struct bfd_link_info
*info
,
4278 bfd_signed_vma group_size
,
4279 asection
* (*add_stub_section
) (const char *,
4281 void (*layout_sections_again
) (void))
4283 bfd_size_type stub_group_size
;
4284 bfd_boolean stubs_always_before_branch
;
4285 bfd_boolean stub_changed
= FALSE
;
4286 struct elf_aarch64_link_hash_table
*htab
= elf_aarch64_hash_table (info
);
4287 unsigned int num_erratum_835769_fixes
= 0;
4289 /* Propagate mach to stub bfd, because it may not have been
4290 finalized when we created stub_bfd. */
4291 bfd_set_arch_mach (stub_bfd
, bfd_get_arch (output_bfd
),
4292 bfd_get_mach (output_bfd
));
4294 /* Stash our params away. */
4295 htab
->stub_bfd
= stub_bfd
;
4296 htab
->add_stub_section
= add_stub_section
;
4297 htab
->layout_sections_again
= layout_sections_again
;
4298 stubs_always_before_branch
= group_size
< 0;
4300 stub_group_size
= -group_size
;
4302 stub_group_size
= group_size
;
4304 if (stub_group_size
== 1)
4306 /* Default values. */
4307 /* AArch64 branch range is +-128MB. The value used is 1MB less. */
4308 stub_group_size
= 127 * 1024 * 1024;
4311 group_sections (htab
, stub_group_size
, stubs_always_before_branch
);
4313 (*htab
->layout_sections_again
) ();
4315 if (htab
->fix_erratum_835769
)
4319 for (input_bfd
= info
->input_bfds
;
4320 input_bfd
!= NULL
; input_bfd
= input_bfd
->link
.next
)
4321 if (!_bfd_aarch64_erratum_835769_scan (input_bfd
, info
,
4322 &num_erratum_835769_fixes
))
4325 _bfd_aarch64_resize_stubs (htab
);
4326 (*htab
->layout_sections_again
) ();
4329 if (htab
->fix_erratum_843419
)
4333 for (input_bfd
= info
->input_bfds
;
4335 input_bfd
= input_bfd
->link
.next
)
4339 for (section
= input_bfd
->sections
;
4341 section
= section
->next
)
4342 if (!_bfd_aarch64_erratum_843419_scan (input_bfd
, section
, info
))
4346 _bfd_aarch64_resize_stubs (htab
);
4347 (*htab
->layout_sections_again
) ();
4354 for (input_bfd
= info
->input_bfds
;
4355 input_bfd
!= NULL
; input_bfd
= input_bfd
->link
.next
)
4357 Elf_Internal_Shdr
*symtab_hdr
;
4359 Elf_Internal_Sym
*local_syms
= NULL
;
4361 /* We'll need the symbol table in a second. */
4362 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
4363 if (symtab_hdr
->sh_info
== 0)
4366 /* Walk over each section attached to the input bfd. */
4367 for (section
= input_bfd
->sections
;
4368 section
!= NULL
; section
= section
->next
)
4370 Elf_Internal_Rela
*internal_relocs
, *irelaend
, *irela
;
4372 /* If there aren't any relocs, then there's nothing more
4374 if ((section
->flags
& SEC_RELOC
) == 0
4375 || section
->reloc_count
== 0
4376 || (section
->flags
& SEC_CODE
) == 0)
4379 /* If this section is a link-once section that will be
4380 discarded, then don't create any stubs. */
4381 if (section
->output_section
== NULL
4382 || section
->output_section
->owner
!= output_bfd
)
4385 /* Get the relocs. */
4387 = _bfd_elf_link_read_relocs (input_bfd
, section
, NULL
,
4388 NULL
, info
->keep_memory
);
4389 if (internal_relocs
== NULL
)
4390 goto error_ret_free_local
;
4392 /* Now examine each relocation. */
4393 irela
= internal_relocs
;
4394 irelaend
= irela
+ section
->reloc_count
;
4395 for (; irela
< irelaend
; irela
++)
4397 unsigned int r_type
, r_indx
;
4398 enum elf_aarch64_stub_type stub_type
;
4399 struct elf_aarch64_stub_hash_entry
*stub_entry
;
4402 bfd_vma destination
;
4403 struct elf_aarch64_link_hash_entry
*hash
;
4404 const char *sym_name
;
4406 const asection
*id_sec
;
4407 unsigned char st_type
;
4410 r_type
= ELFNN_R_TYPE (irela
->r_info
);
4411 r_indx
= ELFNN_R_SYM (irela
->r_info
);
4413 if (r_type
>= (unsigned int) R_AARCH64_end
)
4415 bfd_set_error (bfd_error_bad_value
);
4416 error_ret_free_internal
:
4417 if (elf_section_data (section
)->relocs
== NULL
)
4418 free (internal_relocs
);
4419 goto error_ret_free_local
;
4422 /* Only look for stubs on unconditional branch and
4423 branch and link instructions. */
4424 if (r_type
!= (unsigned int) AARCH64_R (CALL26
)
4425 && r_type
!= (unsigned int) AARCH64_R (JUMP26
))
4428 /* Now determine the call target, its name, value,
4435 if (r_indx
< symtab_hdr
->sh_info
)
4437 /* It's a local symbol. */
4438 Elf_Internal_Sym
*sym
;
4439 Elf_Internal_Shdr
*hdr
;
4441 if (local_syms
== NULL
)
4444 = (Elf_Internal_Sym
*) symtab_hdr
->contents
;
4445 if (local_syms
== NULL
)
4447 = bfd_elf_get_elf_syms (input_bfd
, symtab_hdr
,
4448 symtab_hdr
->sh_info
, 0,
4450 if (local_syms
== NULL
)
4451 goto error_ret_free_internal
;
4454 sym
= local_syms
+ r_indx
;
4455 hdr
= elf_elfsections (input_bfd
)[sym
->st_shndx
];
4456 sym_sec
= hdr
->bfd_section
;
4458 /* This is an undefined symbol. It can never
4462 if (ELF_ST_TYPE (sym
->st_info
) != STT_SECTION
)
4463 sym_value
= sym
->st_value
;
4464 destination
= (sym_value
+ irela
->r_addend
4465 + sym_sec
->output_offset
4466 + sym_sec
->output_section
->vma
);
4467 st_type
= ELF_ST_TYPE (sym
->st_info
);
4469 = bfd_elf_string_from_elf_section (input_bfd
,
4470 symtab_hdr
->sh_link
,
4477 e_indx
= r_indx
- symtab_hdr
->sh_info
;
4478 hash
= ((struct elf_aarch64_link_hash_entry
*)
4479 elf_sym_hashes (input_bfd
)[e_indx
]);
4481 while (hash
->root
.root
.type
== bfd_link_hash_indirect
4482 || hash
->root
.root
.type
== bfd_link_hash_warning
)
4483 hash
= ((struct elf_aarch64_link_hash_entry
*)
4484 hash
->root
.root
.u
.i
.link
);
4486 if (hash
->root
.root
.type
== bfd_link_hash_defined
4487 || hash
->root
.root
.type
== bfd_link_hash_defweak
)
4489 struct elf_aarch64_link_hash_table
*globals
=
4490 elf_aarch64_hash_table (info
);
4491 sym_sec
= hash
->root
.root
.u
.def
.section
;
4492 sym_value
= hash
->root
.root
.u
.def
.value
;
4493 /* For a destination in a shared library,
4494 use the PLT stub as target address to
4495 decide whether a branch stub is
4497 if (globals
->root
.splt
!= NULL
&& hash
!= NULL
4498 && hash
->root
.plt
.offset
!= (bfd_vma
) - 1)
4500 sym_sec
= globals
->root
.splt
;
4501 sym_value
= hash
->root
.plt
.offset
;
4502 if (sym_sec
->output_section
!= NULL
)
4503 destination
= (sym_value
4504 + sym_sec
->output_offset
4506 sym_sec
->output_section
->vma
);
4508 else if (sym_sec
->output_section
!= NULL
)
4509 destination
= (sym_value
+ irela
->r_addend
4510 + sym_sec
->output_offset
4511 + sym_sec
->output_section
->vma
);
4513 else if (hash
->root
.root
.type
== bfd_link_hash_undefined
4514 || (hash
->root
.root
.type
4515 == bfd_link_hash_undefweak
))
4517 /* For a shared library, use the PLT stub as
4518 target address to decide whether a long
4519 branch stub is needed.
4520 For absolute code, they cannot be handled. */
4521 struct elf_aarch64_link_hash_table
*globals
=
4522 elf_aarch64_hash_table (info
);
4524 if (globals
->root
.splt
!= NULL
&& hash
!= NULL
4525 && hash
->root
.plt
.offset
!= (bfd_vma
) - 1)
4527 sym_sec
= globals
->root
.splt
;
4528 sym_value
= hash
->root
.plt
.offset
;
4529 if (sym_sec
->output_section
!= NULL
)
4530 destination
= (sym_value
4531 + sym_sec
->output_offset
4533 sym_sec
->output_section
->vma
);
4540 bfd_set_error (bfd_error_bad_value
);
4541 goto error_ret_free_internal
;
4543 st_type
= ELF_ST_TYPE (hash
->root
.type
);
4544 sym_name
= hash
->root
.root
.root
.string
;
4547 /* Determine what (if any) linker stub is needed. */
4548 stub_type
= aarch64_type_of_stub (section
, irela
, sym_sec
,
4549 st_type
, destination
);
4550 if (stub_type
== aarch64_stub_none
)
4553 /* Support for grouping stub sections. */
4554 id_sec
= htab
->stub_group
[section
->id
].link_sec
;
4556 /* Get the name of this stub. */
4557 stub_name
= elfNN_aarch64_stub_name (id_sec
, sym_sec
, hash
,
4560 goto error_ret_free_internal
;
4563 aarch64_stub_hash_lookup (&htab
->stub_hash_table
,
4564 stub_name
, FALSE
, FALSE
);
4565 if (stub_entry
!= NULL
)
4567 /* The proper stub has already been created. */
4569 /* Always update this stub's target since it may have
4570 changed after layout. */
4571 stub_entry
->target_value
= sym_value
+ irela
->r_addend
;
4575 stub_entry
= _bfd_aarch64_add_stub_entry_in_group
4576 (stub_name
, section
, htab
);
4577 if (stub_entry
== NULL
)
4580 goto error_ret_free_internal
;
4583 stub_entry
->target_value
= sym_value
+ irela
->r_addend
;
4584 stub_entry
->target_section
= sym_sec
;
4585 stub_entry
->stub_type
= stub_type
;
4586 stub_entry
->h
= hash
;
4587 stub_entry
->st_type
= st_type
;
4589 if (sym_name
== NULL
)
4590 sym_name
= "unnamed";
4591 len
= sizeof (STUB_ENTRY_NAME
) + strlen (sym_name
);
4592 stub_entry
->output_name
= bfd_alloc (htab
->stub_bfd
, len
);
4593 if (stub_entry
->output_name
== NULL
)
4596 goto error_ret_free_internal
;
4599 snprintf (stub_entry
->output_name
, len
, STUB_ENTRY_NAME
,
4602 stub_changed
= TRUE
;
4605 /* We're done with the internal relocs, free them. */
4606 if (elf_section_data (section
)->relocs
== NULL
)
4607 free (internal_relocs
);
4614 _bfd_aarch64_resize_stubs (htab
);
4616 /* Ask the linker to do its stuff. */
4617 (*htab
->layout_sections_again
) ();
4618 stub_changed
= FALSE
;
4623 error_ret_free_local
:
4627 /* Build all the stubs associated with the current output file. The
4628 stubs are kept in a hash table attached to the main linker hash
4629 table. We also set up the .plt entries for statically linked PIC
4630 functions here. This function is called via aarch64_elf_finish in the
4634 elfNN_aarch64_build_stubs (struct bfd_link_info
*info
)
4637 struct bfd_hash_table
*table
;
4638 struct elf_aarch64_link_hash_table
*htab
;
4640 htab
= elf_aarch64_hash_table (info
);
4642 for (stub_sec
= htab
->stub_bfd
->sections
;
4643 stub_sec
!= NULL
; stub_sec
= stub_sec
->next
)
4647 /* Ignore non-stub sections. */
4648 if (!strstr (stub_sec
->name
, STUB_SUFFIX
))
4651 /* Allocate memory to hold the linker stubs. */
4652 size
= stub_sec
->size
;
4653 stub_sec
->contents
= bfd_zalloc (htab
->stub_bfd
, size
);
4654 if (stub_sec
->contents
== NULL
&& size
!= 0)
4658 /* Add a branch around the stub section, and a nop, to keep it 8 byte
4659 aligned, as long branch stubs contain a 64-bit address. */
4660 bfd_putl32 (0x14000000 | (size
>> 2), stub_sec
->contents
);
4661 bfd_putl32 (INSN_NOP
, stub_sec
->contents
+ 4);
4662 stub_sec
->size
+= 8;
4665 /* Build the stubs as directed by the stub hash table. */
4666 table
= &htab
->stub_hash_table
;
4667 bfd_hash_traverse (table
, aarch64_build_one_stub
, info
);
4673 /* Add an entry to the code/data map for section SEC. */
4676 elfNN_aarch64_section_map_add (asection
*sec
, char type
, bfd_vma vma
)
4678 struct _aarch64_elf_section_data
*sec_data
=
4679 elf_aarch64_section_data (sec
);
4680 unsigned int newidx
;
4682 if (sec_data
->map
== NULL
)
4684 sec_data
->map
= bfd_malloc (sizeof (elf_aarch64_section_map
));
4685 sec_data
->mapcount
= 0;
4686 sec_data
->mapsize
= 1;
4689 newidx
= sec_data
->mapcount
++;
4691 if (sec_data
->mapcount
> sec_data
->mapsize
)
4693 sec_data
->mapsize
*= 2;
4694 sec_data
->map
= bfd_realloc_or_free
4695 (sec_data
->map
, sec_data
->mapsize
* sizeof (elf_aarch64_section_map
));
4700 sec_data
->map
[newidx
].vma
= vma
;
4701 sec_data
->map
[newidx
].type
= type
;
4706 /* Initialise maps of insn/data for input BFDs. */
4708 bfd_elfNN_aarch64_init_maps (bfd
*abfd
)
4710 Elf_Internal_Sym
*isymbuf
;
4711 Elf_Internal_Shdr
*hdr
;
4712 unsigned int i
, localsyms
;
4714 /* Make sure that we are dealing with an AArch64 elf binary. */
4715 if (!is_aarch64_elf (abfd
))
4718 if ((abfd
->flags
& DYNAMIC
) != 0)
4721 hdr
= &elf_symtab_hdr (abfd
);
4722 localsyms
= hdr
->sh_info
;
4724 /* Obtain a buffer full of symbols for this BFD. The hdr->sh_info field
4725 should contain the number of local symbols, which should come before any
4726 global symbols. Mapping symbols are always local. */
4727 isymbuf
= bfd_elf_get_elf_syms (abfd
, hdr
, localsyms
, 0, NULL
, NULL
, NULL
);
4729 /* No internal symbols read? Skip this BFD. */
4730 if (isymbuf
== NULL
)
4733 for (i
= 0; i
< localsyms
; i
++)
4735 Elf_Internal_Sym
*isym
= &isymbuf
[i
];
4736 asection
*sec
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
4739 if (sec
!= NULL
&& ELF_ST_BIND (isym
->st_info
) == STB_LOCAL
)
4741 name
= bfd_elf_string_from_elf_section (abfd
,
4745 if (bfd_is_aarch64_special_symbol_name
4746 (name
, BFD_AARCH64_SPECIAL_SYM_TYPE_MAP
))
4747 elfNN_aarch64_section_map_add (sec
, name
[1], isym
->st_value
);
4753 setup_plt_values (struct bfd_link_info
*link_info
,
4754 aarch64_plt_type plt_type
)
4756 struct elf_aarch64_link_hash_table
*globals
;
4757 globals
= elf_aarch64_hash_table (link_info
);
4759 if (plt_type
== PLT_BTI_PAC
)
4761 globals
->plt_header_size
= PLT_BTI_PAC_ENTRY_SIZE
;
4762 globals
->plt0_entry
= elfNN_aarch64_small_plt0_bti_pac_entry
;
4763 globals
->tlsdesc_plt_entry_size
= PLT_BTI_TLSDESC_ENTRY_SIZE
;
4765 /* Only in ET_EXEC we need PLTn with BTI. */
4766 if (bfd_link_pde (link_info
))
4768 globals
->plt_entry_size
= PLT_BTI_PAC_SMALL_ENTRY_SIZE
;
4769 globals
->plt_entry
= elfNN_aarch64_small_plt_bti_pac_entry
;
4773 globals
->plt_entry_size
= PLT_PAC_SMALL_ENTRY_SIZE
;
4774 globals
->plt_entry
= elfNN_aarch64_small_plt_pac_entry
;
4777 else if (plt_type
== PLT_BTI
)
4779 globals
->plt_header_size
= PLT_BTI_ENTRY_SIZE
;
4780 globals
->plt0_entry
= elfNN_aarch64_small_plt0_bti_entry
;
4781 globals
->tlsdesc_plt_entry_size
= PLT_BTI_TLSDESC_ENTRY_SIZE
;
4783 /* Only in ET_EXEC we need PLTn with BTI. */
4784 if (bfd_link_pde (link_info
))
4786 globals
->plt_entry_size
= PLT_BTI_SMALL_ENTRY_SIZE
;
4787 globals
->plt_entry
= elfNN_aarch64_small_plt_bti_entry
;
4790 else if (plt_type
== PLT_PAC
)
4792 globals
->plt_header_size
= PLT_PAC_ENTRY_SIZE
;
4793 globals
->plt0_entry
= elfNN_aarch64_small_plt0_pac_entry
;
4794 globals
->tlsdesc_plt_entry_size
= PLT_TLSDESC_ENTRY_SIZE
;
4795 globals
->plt_entry_size
= PLT_PAC_SMALL_ENTRY_SIZE
;
4796 globals
->plt_entry
= elfNN_aarch64_small_plt_pac_entry
;
4800 /* Set option values needed during linking. */
4802 bfd_elfNN_aarch64_set_options (struct bfd
*output_bfd
,
4803 struct bfd_link_info
*link_info
,
4805 int no_wchar_warn
, int pic_veneer
,
4806 int fix_erratum_835769
,
4807 int fix_erratum_843419
,
4808 int no_apply_dynamic_relocs
,
4809 aarch64_bti_pac_info bp_info
)
4811 struct elf_aarch64_link_hash_table
*globals
;
4813 globals
= elf_aarch64_hash_table (link_info
);
4814 globals
->pic_veneer
= pic_veneer
;
4815 globals
->fix_erratum_835769
= fix_erratum_835769
;
4816 globals
->fix_erratum_843419
= fix_erratum_843419
;
4817 globals
->fix_erratum_843419_adr
= TRUE
;
4818 globals
->no_apply_dynamic_relocs
= no_apply_dynamic_relocs
;
4820 BFD_ASSERT (is_aarch64_elf (output_bfd
));
4821 elf_aarch64_tdata (output_bfd
)->no_enum_size_warning
= no_enum_warn
;
4822 elf_aarch64_tdata (output_bfd
)->no_wchar_size_warning
= no_wchar_warn
;
4824 switch (bp_info
.bti_type
)
4827 elf_aarch64_tdata (output_bfd
)->no_bti_warn
= 0;
4828 elf_aarch64_tdata (output_bfd
)->gnu_and_prop
4829 |= GNU_PROPERTY_AARCH64_FEATURE_1_BTI
;
4835 elf_aarch64_tdata (output_bfd
)->plt_type
= bp_info
.plt_type
;
4836 setup_plt_values (link_info
, bp_info
.plt_type
);
4840 aarch64_calculate_got_entry_vma (struct elf_link_hash_entry
*h
,
4841 struct elf_aarch64_link_hash_table
4842 *globals
, struct bfd_link_info
*info
,
4843 bfd_vma value
, bfd
*output_bfd
,
4844 bfd_boolean
*unresolved_reloc_p
)
4846 bfd_vma off
= (bfd_vma
) - 1;
4847 asection
*basegot
= globals
->root
.sgot
;
4848 bfd_boolean dyn
= globals
->root
.dynamic_sections_created
;
4852 BFD_ASSERT (basegot
!= NULL
);
4853 off
= h
->got
.offset
;
4854 BFD_ASSERT (off
!= (bfd_vma
) - 1);
4855 if (!WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, bfd_link_pic (info
), h
)
4856 || (bfd_link_pic (info
)
4857 && SYMBOL_REFERENCES_LOCAL (info
, h
))
4858 || (ELF_ST_VISIBILITY (h
->other
)
4859 && h
->root
.type
== bfd_link_hash_undefweak
))
4861 /* This is actually a static link, or it is a -Bsymbolic link
4862 and the symbol is defined locally. We must initialize this
4863 entry in the global offset table. Since the offset must
4864 always be a multiple of 8 (4 in the case of ILP32), we use
4865 the least significant bit to record whether we have
4866 initialized it already.
4867 When doing a dynamic link, we create a .rel(a).got relocation
4868 entry to initialize the value. This is done in the
4869 finish_dynamic_symbol routine. */
4874 bfd_put_NN (output_bfd
, value
, basegot
->contents
+ off
);
4879 *unresolved_reloc_p
= FALSE
;
4881 off
= off
+ basegot
->output_section
->vma
+ basegot
->output_offset
;
4887 /* Change R_TYPE to a more efficient access model where possible,
4888 return the new reloc type. */
4890 static bfd_reloc_code_real_type
4891 aarch64_tls_transition_without_check (bfd_reloc_code_real_type r_type
,
4892 struct elf_link_hash_entry
*h
)
4894 bfd_boolean is_local
= h
== NULL
;
4898 case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21
:
4899 case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21
:
4901 ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1
4902 : BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21
);
4904 case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21
:
4906 ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC
4909 case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19
:
4911 ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1
4912 : BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19
);
4914 case BFD_RELOC_AARCH64_TLSDESC_LDR
:
4916 ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC
4917 : BFD_RELOC_AARCH64_NONE
);
4919 case BFD_RELOC_AARCH64_TLSDESC_OFF_G0_NC
:
4921 ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1_NC
4922 : BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G0_NC
);
4924 case BFD_RELOC_AARCH64_TLSDESC_OFF_G1
:
4926 ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G2
4927 : BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G1
);
4929 case BFD_RELOC_AARCH64_TLSDESC_LDNN_LO12_NC
:
4930 case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC
:
4932 ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC
4933 : BFD_RELOC_AARCH64_TLSIE_LDNN_GOTTPREL_LO12_NC
);
4935 case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21
:
4936 return is_local
? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1
: r_type
;
4938 case BFD_RELOC_AARCH64_TLSIE_LDNN_GOTTPREL_LO12_NC
:
4939 return is_local
? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC
: r_type
;
4941 case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19
:
4944 case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21
:
4946 ? BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_HI12
4947 : BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19
);
4949 case BFD_RELOC_AARCH64_TLSDESC_ADD
:
4950 case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12
:
4951 case BFD_RELOC_AARCH64_TLSDESC_CALL
:
4952 /* Instructions with these relocations will become NOPs. */
4953 return BFD_RELOC_AARCH64_NONE
;
4955 case BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC
:
4956 case BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21
:
4957 case BFD_RELOC_AARCH64_TLSLD_ADR_PREL21
:
4958 return is_local
? BFD_RELOC_AARCH64_NONE
: r_type
;
4961 case BFD_RELOC_AARCH64_TLSGD_MOVW_G0_NC
:
4963 ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1_NC
4964 : BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G0_NC
;
4966 case BFD_RELOC_AARCH64_TLSGD_MOVW_G1
:
4968 ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G2
4969 : BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G1
;
4980 aarch64_reloc_got_type (bfd_reloc_code_real_type r_type
)
4984 case BFD_RELOC_AARCH64_ADR_GOT_PAGE
:
4985 case BFD_RELOC_AARCH64_GOT_LD_PREL19
:
4986 case BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14
:
4987 case BFD_RELOC_AARCH64_LD32_GOT_LO12_NC
:
4988 case BFD_RELOC_AARCH64_LD64_GOTOFF_LO15
:
4989 case BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15
:
4990 case BFD_RELOC_AARCH64_LD64_GOT_LO12_NC
:
4991 case BFD_RELOC_AARCH64_MOVW_GOTOFF_G0_NC
:
4992 case BFD_RELOC_AARCH64_MOVW_GOTOFF_G1
:
4995 case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC
:
4996 case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21
:
4997 case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21
:
4998 case BFD_RELOC_AARCH64_TLSGD_MOVW_G0_NC
:
4999 case BFD_RELOC_AARCH64_TLSGD_MOVW_G1
:
5000 case BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC
:
5001 case BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21
:
5002 case BFD_RELOC_AARCH64_TLSLD_ADR_PREL21
:
5005 case BFD_RELOC_AARCH64_TLSDESC_ADD
:
5006 case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12
:
5007 case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21
:
5008 case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21
:
5009 case BFD_RELOC_AARCH64_TLSDESC_CALL
:
5010 case BFD_RELOC_AARCH64_TLSDESC_LD32_LO12_NC
:
5011 case BFD_RELOC_AARCH64_TLSDESC_LD64_LO12
:
5012 case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19
:
5013 case BFD_RELOC_AARCH64_TLSDESC_LDR
:
5014 case BFD_RELOC_AARCH64_TLSDESC_OFF_G0_NC
:
5015 case BFD_RELOC_AARCH64_TLSDESC_OFF_G1
:
5016 return GOT_TLSDESC_GD
;
5018 case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21
:
5019 case BFD_RELOC_AARCH64_TLSIE_LD32_GOTTPREL_LO12_NC
:
5020 case BFD_RELOC_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC
:
5021 case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19
:
5022 case BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G0_NC
:
5023 case BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G1
:
5033 aarch64_can_relax_tls (bfd
*input_bfd
,
5034 struct bfd_link_info
*info
,
5035 bfd_reloc_code_real_type r_type
,
5036 struct elf_link_hash_entry
*h
,
5037 unsigned long r_symndx
)
5039 unsigned int symbol_got_type
;
5040 unsigned int reloc_got_type
;
5042 if (! IS_AARCH64_TLS_RELAX_RELOC (r_type
))
5045 symbol_got_type
= elfNN_aarch64_symbol_got_type (h
, input_bfd
, r_symndx
);
5046 reloc_got_type
= aarch64_reloc_got_type (r_type
);
5048 if (symbol_got_type
== GOT_TLS_IE
&& GOT_TLS_GD_ANY_P (reloc_got_type
))
5051 if (!bfd_link_executable (info
))
5054 if (h
&& h
->root
.type
== bfd_link_hash_undefweak
)
5060 /* Given the relocation code R_TYPE, return the relaxed bfd reloc
5063 static bfd_reloc_code_real_type
5064 aarch64_tls_transition (bfd
*input_bfd
,
5065 struct bfd_link_info
*info
,
5066 unsigned int r_type
,
5067 struct elf_link_hash_entry
*h
,
5068 unsigned long r_symndx
)
5070 bfd_reloc_code_real_type bfd_r_type
5071 = elfNN_aarch64_bfd_reloc_from_type (input_bfd
, r_type
);
5073 if (! aarch64_can_relax_tls (input_bfd
, info
, bfd_r_type
, h
, r_symndx
))
5076 return aarch64_tls_transition_without_check (bfd_r_type
, h
);
5079 /* Return the base VMA address which should be subtracted from real addresses
5080 when resolving R_AARCH64_TLS_DTPREL relocation. */
5083 dtpoff_base (struct bfd_link_info
*info
)
5085 /* If tls_sec is NULL, we should have signalled an error already. */
5086 BFD_ASSERT (elf_hash_table (info
)->tls_sec
!= NULL
);
5087 return elf_hash_table (info
)->tls_sec
->vma
;
5090 /* Return the base VMA address which should be subtracted from real addresses
5091 when resolving R_AARCH64_TLS_GOTTPREL64 relocations. */
5094 tpoff_base (struct bfd_link_info
*info
)
5096 struct elf_link_hash_table
*htab
= elf_hash_table (info
);
5098 /* If tls_sec is NULL, we should have signalled an error already. */
5099 BFD_ASSERT (htab
->tls_sec
!= NULL
);
5101 bfd_vma base
= align_power ((bfd_vma
) TCB_SIZE
,
5102 htab
->tls_sec
->alignment_power
);
5103 return htab
->tls_sec
->vma
- base
;
5107 symbol_got_offset_ref (bfd
*input_bfd
, struct elf_link_hash_entry
*h
,
5108 unsigned long r_symndx
)
5110 /* Calculate the address of the GOT entry for symbol
5111 referred to in h. */
5113 return &h
->got
.offset
;
5117 struct elf_aarch64_local_symbol
*l
;
5119 l
= elf_aarch64_locals (input_bfd
);
5120 return &l
[r_symndx
].got_offset
;
5125 symbol_got_offset_mark (bfd
*input_bfd
, struct elf_link_hash_entry
*h
,
5126 unsigned long r_symndx
)
5129 p
= symbol_got_offset_ref (input_bfd
, h
, r_symndx
);
5134 symbol_got_offset_mark_p (bfd
*input_bfd
, struct elf_link_hash_entry
*h
,
5135 unsigned long r_symndx
)
5138 value
= * symbol_got_offset_ref (input_bfd
, h
, r_symndx
);
5143 symbol_got_offset (bfd
*input_bfd
, struct elf_link_hash_entry
*h
,
5144 unsigned long r_symndx
)
5147 value
= * symbol_got_offset_ref (input_bfd
, h
, r_symndx
);
5153 symbol_tlsdesc_got_offset_ref (bfd
*input_bfd
, struct elf_link_hash_entry
*h
,
5154 unsigned long r_symndx
)
5156 /* Calculate the address of the GOT entry for symbol
5157 referred to in h. */
5160 struct elf_aarch64_link_hash_entry
*eh
;
5161 eh
= (struct elf_aarch64_link_hash_entry
*) h
;
5162 return &eh
->tlsdesc_got_jump_table_offset
;
5167 struct elf_aarch64_local_symbol
*l
;
5169 l
= elf_aarch64_locals (input_bfd
);
5170 return &l
[r_symndx
].tlsdesc_got_jump_table_offset
;
5175 symbol_tlsdesc_got_offset_mark (bfd
*input_bfd
, struct elf_link_hash_entry
*h
,
5176 unsigned long r_symndx
)
5179 p
= symbol_tlsdesc_got_offset_ref (input_bfd
, h
, r_symndx
);
5184 symbol_tlsdesc_got_offset_mark_p (bfd
*input_bfd
,
5185 struct elf_link_hash_entry
*h
,
5186 unsigned long r_symndx
)
5189 value
= * symbol_tlsdesc_got_offset_ref (input_bfd
, h
, r_symndx
);
5194 symbol_tlsdesc_got_offset (bfd
*input_bfd
, struct elf_link_hash_entry
*h
,
5195 unsigned long r_symndx
)
5198 value
= * symbol_tlsdesc_got_offset_ref (input_bfd
, h
, r_symndx
);
5203 /* Data for make_branch_to_erratum_835769_stub(). */
5205 struct erratum_835769_branch_to_stub_data
5207 struct bfd_link_info
*info
;
5208 asection
*output_section
;
5212 /* Helper to insert branches to erratum 835769 stubs in the right
5213 places for a particular section. */
5216 make_branch_to_erratum_835769_stub (struct bfd_hash_entry
*gen_entry
,
5219 struct elf_aarch64_stub_hash_entry
*stub_entry
;
5220 struct erratum_835769_branch_to_stub_data
*data
;
5222 unsigned long branch_insn
= 0;
5223 bfd_vma veneered_insn_loc
, veneer_entry_loc
;
5224 bfd_signed_vma branch_offset
;
5225 unsigned int target
;
5228 stub_entry
= (struct elf_aarch64_stub_hash_entry
*) gen_entry
;
5229 data
= (struct erratum_835769_branch_to_stub_data
*) in_arg
;
5231 if (stub_entry
->target_section
!= data
->output_section
5232 || stub_entry
->stub_type
!= aarch64_stub_erratum_835769_veneer
)
5235 contents
= data
->contents
;
5236 veneered_insn_loc
= stub_entry
->target_section
->output_section
->vma
5237 + stub_entry
->target_section
->output_offset
5238 + stub_entry
->target_value
;
5239 veneer_entry_loc
= stub_entry
->stub_sec
->output_section
->vma
5240 + stub_entry
->stub_sec
->output_offset
5241 + stub_entry
->stub_offset
;
5242 branch_offset
= veneer_entry_loc
- veneered_insn_loc
;
5244 abfd
= stub_entry
->target_section
->owner
;
5245 if (!aarch64_valid_branch_p (veneer_entry_loc
, veneered_insn_loc
))
5247 (_("%pB: error: erratum 835769 stub out "
5248 "of range (input file too large)"), abfd
);
5250 target
= stub_entry
->target_value
;
5251 branch_insn
= 0x14000000;
5252 branch_offset
>>= 2;
5253 branch_offset
&= 0x3ffffff;
5254 branch_insn
|= branch_offset
;
5255 bfd_putl32 (branch_insn
, &contents
[target
]);
5262 _bfd_aarch64_erratum_843419_branch_to_stub (struct bfd_hash_entry
*gen_entry
,
5265 struct elf_aarch64_stub_hash_entry
*stub_entry
5266 = (struct elf_aarch64_stub_hash_entry
*) gen_entry
;
5267 struct erratum_835769_branch_to_stub_data
*data
5268 = (struct erratum_835769_branch_to_stub_data
*) in_arg
;
5269 struct bfd_link_info
*info
;
5270 struct elf_aarch64_link_hash_table
*htab
;
5278 contents
= data
->contents
;
5279 section
= data
->output_section
;
5281 htab
= elf_aarch64_hash_table (info
);
5283 if (stub_entry
->target_section
!= section
5284 || stub_entry
->stub_type
!= aarch64_stub_erratum_843419_veneer
)
5287 insn
= bfd_getl32 (contents
+ stub_entry
->target_value
);
5289 stub_entry
->stub_sec
->contents
+ stub_entry
->stub_offset
);
5291 place
= (section
->output_section
->vma
+ section
->output_offset
5292 + stub_entry
->adrp_offset
);
5293 insn
= bfd_getl32 (contents
+ stub_entry
->adrp_offset
);
5295 if (!_bfd_aarch64_adrp_p (insn
))
5298 bfd_signed_vma imm
=
5299 (_bfd_aarch64_sign_extend
5300 ((bfd_vma
) _bfd_aarch64_decode_adrp_imm (insn
) << 12, 33)
5303 if (htab
->fix_erratum_843419_adr
5304 && (imm
>= AARCH64_MIN_ADRP_IMM
&& imm
<= AARCH64_MAX_ADRP_IMM
))
5306 insn
= (_bfd_aarch64_reencode_adr_imm (AARCH64_ADR_OP
, imm
)
5307 | AARCH64_RT (insn
));
5308 bfd_putl32 (insn
, contents
+ stub_entry
->adrp_offset
);
5312 bfd_vma veneered_insn_loc
;
5313 bfd_vma veneer_entry_loc
;
5314 bfd_signed_vma branch_offset
;
5315 uint32_t branch_insn
;
5317 veneered_insn_loc
= stub_entry
->target_section
->output_section
->vma
5318 + stub_entry
->target_section
->output_offset
5319 + stub_entry
->target_value
;
5320 veneer_entry_loc
= stub_entry
->stub_sec
->output_section
->vma
5321 + stub_entry
->stub_sec
->output_offset
5322 + stub_entry
->stub_offset
;
5323 branch_offset
= veneer_entry_loc
- veneered_insn_loc
;
5325 abfd
= stub_entry
->target_section
->owner
;
5326 if (!aarch64_valid_branch_p (veneer_entry_loc
, veneered_insn_loc
))
5328 (_("%pB: error: erratum 843419 stub out "
5329 "of range (input file too large)"), abfd
);
5331 branch_insn
= 0x14000000;
5332 branch_offset
>>= 2;
5333 branch_offset
&= 0x3ffffff;
5334 branch_insn
|= branch_offset
;
5335 bfd_putl32 (branch_insn
, contents
+ stub_entry
->target_value
);
5342 elfNN_aarch64_write_section (bfd
*output_bfd ATTRIBUTE_UNUSED
,
5343 struct bfd_link_info
*link_info
,
5348 struct elf_aarch64_link_hash_table
*globals
=
5349 elf_aarch64_hash_table (link_info
);
5351 if (globals
== NULL
)
5354 /* Fix code to point to erratum 835769 stubs. */
5355 if (globals
->fix_erratum_835769
)
5357 struct erratum_835769_branch_to_stub_data data
;
5359 data
.info
= link_info
;
5360 data
.output_section
= sec
;
5361 data
.contents
= contents
;
5362 bfd_hash_traverse (&globals
->stub_hash_table
,
5363 make_branch_to_erratum_835769_stub
, &data
);
5366 if (globals
->fix_erratum_843419
)
5368 struct erratum_835769_branch_to_stub_data data
;
5370 data
.info
= link_info
;
5371 data
.output_section
= sec
;
5372 data
.contents
= contents
;
5373 bfd_hash_traverse (&globals
->stub_hash_table
,
5374 _bfd_aarch64_erratum_843419_branch_to_stub
, &data
);
5380 /* Return TRUE if RELOC is a relocation against the base of GOT table. */
5383 aarch64_relocation_aginst_gp_p (bfd_reloc_code_real_type reloc
)
5385 return (reloc
== BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14
5386 || reloc
== BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15
5387 || reloc
== BFD_RELOC_AARCH64_LD64_GOTOFF_LO15
5388 || reloc
== BFD_RELOC_AARCH64_MOVW_GOTOFF_G0_NC
5389 || reloc
== BFD_RELOC_AARCH64_MOVW_GOTOFF_G1
);
5392 /* Perform a relocation as part of a final link. The input relocation type
5393 should be TLS relaxed. */
5395 static bfd_reloc_status_type
5396 elfNN_aarch64_final_link_relocate (reloc_howto_type
*howto
,
5399 asection
*input_section
,
5401 Elf_Internal_Rela
*rel
,
5403 struct bfd_link_info
*info
,
5405 struct elf_link_hash_entry
*h
,
5406 bfd_boolean
*unresolved_reloc_p
,
5407 bfd_boolean save_addend
,
5408 bfd_vma
*saved_addend
,
5409 Elf_Internal_Sym
*sym
)
5411 Elf_Internal_Shdr
*symtab_hdr
;
5412 unsigned int r_type
= howto
->type
;
5413 bfd_reloc_code_real_type bfd_r_type
5414 = elfNN_aarch64_bfd_reloc_from_howto (howto
);
5415 unsigned long r_symndx
;
5416 bfd_byte
*hit_data
= contents
+ rel
->r_offset
;
5417 bfd_vma place
, off
, got_entry_addr
= 0;
5418 bfd_signed_vma signed_addend
;
5419 struct elf_aarch64_link_hash_table
*globals
;
5420 bfd_boolean weak_undef_p
;
5421 bfd_boolean relative_reloc
;
5423 bfd_vma orig_value
= value
;
5424 bfd_boolean resolved_to_zero
;
5425 bfd_boolean abs_symbol_p
;
5427 globals
= elf_aarch64_hash_table (info
);
5429 symtab_hdr
= &elf_symtab_hdr (input_bfd
);
5431 BFD_ASSERT (is_aarch64_elf (input_bfd
));
5433 r_symndx
= ELFNN_R_SYM (rel
->r_info
);
5435 place
= input_section
->output_section
->vma
5436 + input_section
->output_offset
+ rel
->r_offset
;
5438 /* Get addend, accumulating the addend for consecutive relocs
5439 which refer to the same offset. */
5440 signed_addend
= saved_addend
? *saved_addend
: 0;
5441 signed_addend
+= rel
->r_addend
;
5443 weak_undef_p
= (h
? h
->root
.type
== bfd_link_hash_undefweak
5444 : bfd_is_und_section (sym_sec
));
5445 abs_symbol_p
= h
!= NULL
&& bfd_is_abs_symbol (&h
->root
);
5448 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle
5449 it here if it is defined in a non-shared object. */
5451 && h
->type
== STT_GNU_IFUNC
5458 if ((input_section
->flags
& SEC_ALLOC
) == 0)
5460 /* If this is a SHT_NOTE section without SHF_ALLOC, treat
5461 STT_GNU_IFUNC symbol as STT_FUNC. */
5462 if (elf_section_type (input_section
) == SHT_NOTE
)
5465 /* Dynamic relocs are not propagated for SEC_DEBUGGING
5466 sections because such sections are not SEC_ALLOC and
5467 thus ld.so will not process them. */
5468 if ((input_section
->flags
& SEC_DEBUGGING
) != 0)
5469 return bfd_reloc_ok
;
5471 if (h
->root
.root
.string
)
5472 name
= h
->root
.root
.string
;
5474 name
= bfd_elf_sym_name (input_bfd
, symtab_hdr
, sym
, NULL
);
5476 /* xgettext:c-format */
5477 (_("%pB(%pA+%#" PRIx64
"): "
5478 "unresolvable %s relocation against symbol `%s'"),
5479 input_bfd
, input_section
, (uint64_t) rel
->r_offset
,
5481 bfd_set_error (bfd_error_bad_value
);
5482 return bfd_reloc_notsupported
;
5484 else if (h
->plt
.offset
== (bfd_vma
) -1)
5485 goto bad_ifunc_reloc
;
5487 /* STT_GNU_IFUNC symbol must go through PLT. */
5488 plt
= globals
->root
.splt
? globals
->root
.splt
: globals
->root
.iplt
;
5489 value
= (plt
->output_section
->vma
+ plt
->output_offset
+ h
->plt
.offset
);
5495 if (h
->root
.root
.string
)
5496 name
= h
->root
.root
.string
;
5498 name
= bfd_elf_sym_name (input_bfd
, symtab_hdr
, sym
,
5501 /* xgettext:c-format */
5502 (_("%pB: relocation %s against STT_GNU_IFUNC "
5503 "symbol `%s' isn't handled by %s"), input_bfd
,
5504 howto
->name
, name
, __FUNCTION__
);
5505 bfd_set_error (bfd_error_bad_value
);
5506 return bfd_reloc_notsupported
;
5508 case BFD_RELOC_AARCH64_NN
:
5509 if (rel
->r_addend
!= 0)
5511 if (h
->root
.root
.string
)
5512 name
= h
->root
.root
.string
;
5514 name
= bfd_elf_sym_name (input_bfd
, symtab_hdr
,
5517 /* xgettext:c-format */
5518 (_("%pB: relocation %s against STT_GNU_IFUNC "
5519 "symbol `%s' has non-zero addend: %" PRId64
),
5520 input_bfd
, howto
->name
, name
, (int64_t) rel
->r_addend
);
5521 bfd_set_error (bfd_error_bad_value
);
5522 return bfd_reloc_notsupported
;
5525 /* Generate dynamic relocation only when there is a
5526 non-GOT reference in a shared object. */
5527 if (bfd_link_pic (info
) && h
->non_got_ref
)
5529 Elf_Internal_Rela outrel
;
5532 /* Need a dynamic relocation to get the real function
5534 outrel
.r_offset
= _bfd_elf_section_offset (output_bfd
,
5538 if (outrel
.r_offset
== (bfd_vma
) -1
5539 || outrel
.r_offset
== (bfd_vma
) -2)
5542 outrel
.r_offset
+= (input_section
->output_section
->vma
5543 + input_section
->output_offset
);
5545 if (h
->dynindx
== -1
5547 || bfd_link_executable (info
))
5549 /* This symbol is resolved locally. */
5550 outrel
.r_info
= ELFNN_R_INFO (0, AARCH64_R (IRELATIVE
));
5551 outrel
.r_addend
= (h
->root
.u
.def
.value
5552 + h
->root
.u
.def
.section
->output_section
->vma
5553 + h
->root
.u
.def
.section
->output_offset
);
5557 outrel
.r_info
= ELFNN_R_INFO (h
->dynindx
, r_type
);
5558 outrel
.r_addend
= 0;
5561 sreloc
= globals
->root
.irelifunc
;
5562 elf_append_rela (output_bfd
, sreloc
, &outrel
);
5564 /* If this reloc is against an external symbol, we
5565 do not want to fiddle with the addend. Otherwise,
5566 we need to include the symbol value so that it
5567 becomes an addend for the dynamic reloc. For an
5568 internal symbol, we have updated addend. */
5569 return bfd_reloc_ok
;
5572 case BFD_RELOC_AARCH64_CALL26
:
5573 case BFD_RELOC_AARCH64_JUMP26
:
5574 value
= _bfd_aarch64_elf_resolve_relocation (bfd_r_type
, place
, value
,
5577 return _bfd_aarch64_elf_put_addend (input_bfd
, hit_data
, bfd_r_type
,
5579 case BFD_RELOC_AARCH64_ADR_GOT_PAGE
:
5580 case BFD_RELOC_AARCH64_GOT_LD_PREL19
:
5581 case BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14
:
5582 case BFD_RELOC_AARCH64_LD32_GOT_LO12_NC
:
5583 case BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15
:
5584 case BFD_RELOC_AARCH64_MOVW_GOTOFF_G0_NC
:
5585 case BFD_RELOC_AARCH64_MOVW_GOTOFF_G1
:
5586 case BFD_RELOC_AARCH64_LD64_GOTOFF_LO15
:
5587 case BFD_RELOC_AARCH64_LD64_GOT_LO12_NC
:
5588 base_got
= globals
->root
.sgot
;
5589 off
= h
->got
.offset
;
5591 if (base_got
== NULL
)
5594 if (off
== (bfd_vma
) -1)
5598 /* We can't use h->got.offset here to save state, or
5599 even just remember the offset, as finish_dynamic_symbol
5600 would use that as offset into .got. */
5602 if (globals
->root
.splt
!= NULL
)
5604 plt_index
= ((h
->plt
.offset
- globals
->plt_header_size
) /
5605 globals
->plt_entry_size
);
5606 off
= (plt_index
+ 3) * GOT_ENTRY_SIZE
;
5607 base_got
= globals
->root
.sgotplt
;
5611 plt_index
= h
->plt
.offset
/ globals
->plt_entry_size
;
5612 off
= plt_index
* GOT_ENTRY_SIZE
;
5613 base_got
= globals
->root
.igotplt
;
5616 if (h
->dynindx
== -1
5620 /* This references the local definition. We must
5621 initialize this entry in the global offset table.
5622 Since the offset must always be a multiple of 8,
5623 we use the least significant bit to record
5624 whether we have initialized it already.
5626 When doing a dynamic link, we create a .rela.got
5627 relocation entry to initialize the value. This
5628 is done in the finish_dynamic_symbol routine. */
5633 bfd_put_NN (output_bfd
, value
,
5634 base_got
->contents
+ off
);
5635 /* Note that this is harmless as -1 | 1 still is -1. */
5639 value
= (base_got
->output_section
->vma
5640 + base_got
->output_offset
+ off
);
5643 value
= aarch64_calculate_got_entry_vma (h
, globals
, info
,
5645 unresolved_reloc_p
);
5647 if (aarch64_relocation_aginst_gp_p (bfd_r_type
))
5648 addend
= (globals
->root
.sgot
->output_section
->vma
5649 + globals
->root
.sgot
->output_offset
);
5651 value
= _bfd_aarch64_elf_resolve_relocation (bfd_r_type
, place
, value
,
5652 addend
, weak_undef_p
);
5653 return _bfd_aarch64_elf_put_addend (input_bfd
, hit_data
, bfd_r_type
, howto
, value
);
5654 case BFD_RELOC_AARCH64_ADD_LO12
:
5655 case BFD_RELOC_AARCH64_ADR_HI21_PCREL
:
5661 resolved_to_zero
= (h
!= NULL
5662 && UNDEFWEAK_NO_DYNAMIC_RELOC (info
, h
));
5666 case BFD_RELOC_AARCH64_NONE
:
5667 case BFD_RELOC_AARCH64_TLSDESC_ADD
:
5668 case BFD_RELOC_AARCH64_TLSDESC_CALL
:
5669 case BFD_RELOC_AARCH64_TLSDESC_LDR
:
5670 *unresolved_reloc_p
= FALSE
;
5671 return bfd_reloc_ok
;
5673 case BFD_RELOC_AARCH64_NN
:
5675 /* When generating a shared object or relocatable executable, these
5676 relocations are copied into the output file to be resolved at
5678 if (((bfd_link_pic (info
)
5679 || globals
->root
.is_relocatable_executable
)
5680 && (input_section
->flags
& SEC_ALLOC
)
5682 || (ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
5683 && !resolved_to_zero
)
5684 || h
->root
.type
!= bfd_link_hash_undefweak
))
5685 /* Or we are creating an executable, we may need to keep relocations
5686 for symbols satisfied by a dynamic library if we manage to avoid
5687 copy relocs for the symbol. */
5688 || (ELIMINATE_COPY_RELOCS
5689 && !bfd_link_pic (info
)
5691 && (input_section
->flags
& SEC_ALLOC
)
5696 || h
->root
.type
== bfd_link_hash_undefweak
5697 || h
->root
.type
== bfd_link_hash_undefined
)))
5699 Elf_Internal_Rela outrel
;
5701 bfd_boolean skip
, relocate
;
5704 *unresolved_reloc_p
= FALSE
;
5709 outrel
.r_addend
= signed_addend
;
5711 _bfd_elf_section_offset (output_bfd
, info
, input_section
,
5713 if (outrel
.r_offset
== (bfd_vma
) - 1)
5715 else if (outrel
.r_offset
== (bfd_vma
) - 2)
5720 else if (abs_symbol_p
)
5722 /* Local absolute symbol. */
5723 skip
= (h
->forced_local
|| (h
->dynindx
== -1));
5727 outrel
.r_offset
+= (input_section
->output_section
->vma
5728 + input_section
->output_offset
);
5731 memset (&outrel
, 0, sizeof outrel
);
5734 && (!bfd_link_pic (info
)
5735 || !(bfd_link_pie (info
) || SYMBOLIC_BIND (info
, h
))
5736 || !h
->def_regular
))
5737 outrel
.r_info
= ELFNN_R_INFO (h
->dynindx
, r_type
);
5742 /* On SVR4-ish systems, the dynamic loader cannot
5743 relocate the text and data segments independently,
5744 so the symbol does not matter. */
5746 relocate
= globals
->no_apply_dynamic_relocs
? FALSE
: TRUE
;
5747 outrel
.r_info
= ELFNN_R_INFO (symbol
, AARCH64_R (RELATIVE
));
5748 outrel
.r_addend
+= value
;
5751 sreloc
= elf_section_data (input_section
)->sreloc
;
5752 if (sreloc
== NULL
|| sreloc
->contents
== NULL
)
5753 return bfd_reloc_notsupported
;
5755 loc
= sreloc
->contents
+ sreloc
->reloc_count
++ * RELOC_SIZE (globals
);
5756 bfd_elfNN_swap_reloca_out (output_bfd
, &outrel
, loc
);
5758 if (sreloc
->reloc_count
* RELOC_SIZE (globals
) > sreloc
->size
)
5760 /* Sanity to check that we have previously allocated
5761 sufficient space in the relocation section for the
5762 number of relocations we actually want to emit. */
5766 /* If this reloc is against an external symbol, we do not want to
5767 fiddle with the addend. Otherwise, we need to include the symbol
5768 value so that it becomes an addend for the dynamic reloc. */
5770 return bfd_reloc_ok
;
5772 return _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
5773 contents
, rel
->r_offset
, value
,
5777 value
+= signed_addend
;
5780 case BFD_RELOC_AARCH64_CALL26
:
5781 case BFD_RELOC_AARCH64_JUMP26
:
5783 asection
*splt
= globals
->root
.splt
;
5784 bfd_boolean via_plt_p
=
5785 splt
!= NULL
&& h
!= NULL
&& h
->plt
.offset
!= (bfd_vma
) - 1;
5787 /* A call to an undefined weak symbol is converted to a jump to
5788 the next instruction unless a PLT entry will be created.
5789 The jump to the next instruction is optimized as a NOP.
5790 Do the same for local undefined symbols. */
5791 if (weak_undef_p
&& ! via_plt_p
)
5793 bfd_putl32 (INSN_NOP
, hit_data
);
5794 return bfd_reloc_ok
;
5797 /* If the call goes through a PLT entry, make sure to
5798 check distance to the right destination address. */
5800 value
= (splt
->output_section
->vma
5801 + splt
->output_offset
+ h
->plt
.offset
);
5803 /* Check if a stub has to be inserted because the destination
5805 struct elf_aarch64_stub_hash_entry
*stub_entry
= NULL
;
5807 /* If the branch destination is directed to plt stub, "value" will be
5808 the final destination, otherwise we should plus signed_addend, it may
5809 contain non-zero value, for example call to local function symbol
5810 which are turned into "sec_sym + sec_off", and sec_off is kept in
5812 if (! aarch64_valid_branch_p (via_plt_p
? value
: value
+ signed_addend
,
5814 /* The target is out of reach, so redirect the branch to
5815 the local stub for this function. */
5816 stub_entry
= elfNN_aarch64_get_stub_entry (input_section
, sym_sec
, h
,
5818 if (stub_entry
!= NULL
)
5820 value
= (stub_entry
->stub_offset
5821 + stub_entry
->stub_sec
->output_offset
5822 + stub_entry
->stub_sec
->output_section
->vma
);
5824 /* We have redirected the destination to stub entry address,
5825 so ignore any addend record in the original rela entry. */
5829 value
= _bfd_aarch64_elf_resolve_relocation (bfd_r_type
, place
, value
,
5830 signed_addend
, weak_undef_p
);
5831 *unresolved_reloc_p
= FALSE
;
5834 case BFD_RELOC_AARCH64_16_PCREL
:
5835 case BFD_RELOC_AARCH64_32_PCREL
:
5836 case BFD_RELOC_AARCH64_64_PCREL
:
5837 case BFD_RELOC_AARCH64_ADR_HI21_NC_PCREL
:
5838 case BFD_RELOC_AARCH64_ADR_HI21_PCREL
:
5839 case BFD_RELOC_AARCH64_ADR_LO21_PCREL
:
5840 case BFD_RELOC_AARCH64_LD_LO19_PCREL
:
5841 case BFD_RELOC_AARCH64_MOVW_PREL_G0
:
5842 case BFD_RELOC_AARCH64_MOVW_PREL_G0_NC
:
5843 case BFD_RELOC_AARCH64_MOVW_PREL_G1
:
5844 case BFD_RELOC_AARCH64_MOVW_PREL_G1_NC
:
5845 case BFD_RELOC_AARCH64_MOVW_PREL_G2
:
5846 case BFD_RELOC_AARCH64_MOVW_PREL_G2_NC
:
5847 case BFD_RELOC_AARCH64_MOVW_PREL_G3
:
5848 if (bfd_link_pic (info
)
5849 && (input_section
->flags
& SEC_ALLOC
) != 0
5850 && (input_section
->flags
& SEC_READONLY
) != 0
5851 && !SYMBOL_REFERENCES_LOCAL (info
, h
))
5853 int howto_index
= bfd_r_type
- BFD_RELOC_AARCH64_RELOC_START
;
5856 /* xgettext:c-format */
5857 (_("%pB: relocation %s against symbol `%s' which may bind "
5858 "externally can not be used when making a shared object; "
5859 "recompile with -fPIC"),
5860 input_bfd
, elfNN_aarch64_howto_table
[howto_index
].name
,
5861 h
->root
.root
.string
);
5862 bfd_set_error (bfd_error_bad_value
);
5863 return bfd_reloc_notsupported
;
5867 case BFD_RELOC_AARCH64_16
:
5869 case BFD_RELOC_AARCH64_32
:
5871 case BFD_RELOC_AARCH64_ADD_LO12
:
5872 case BFD_RELOC_AARCH64_BRANCH19
:
5873 case BFD_RELOC_AARCH64_LDST128_LO12
:
5874 case BFD_RELOC_AARCH64_LDST16_LO12
:
5875 case BFD_RELOC_AARCH64_LDST32_LO12
:
5876 case BFD_RELOC_AARCH64_LDST64_LO12
:
5877 case BFD_RELOC_AARCH64_LDST8_LO12
:
5878 case BFD_RELOC_AARCH64_MOVW_G0
:
5879 case BFD_RELOC_AARCH64_MOVW_G0_NC
:
5880 case BFD_RELOC_AARCH64_MOVW_G0_S
:
5881 case BFD_RELOC_AARCH64_MOVW_G1
:
5882 case BFD_RELOC_AARCH64_MOVW_G1_NC
:
5883 case BFD_RELOC_AARCH64_MOVW_G1_S
:
5884 case BFD_RELOC_AARCH64_MOVW_G2
:
5885 case BFD_RELOC_AARCH64_MOVW_G2_NC
:
5886 case BFD_RELOC_AARCH64_MOVW_G2_S
:
5887 case BFD_RELOC_AARCH64_MOVW_G3
:
5888 case BFD_RELOC_AARCH64_TSTBR14
:
5889 value
= _bfd_aarch64_elf_resolve_relocation (bfd_r_type
, place
, value
,
5890 signed_addend
, weak_undef_p
);
5893 case BFD_RELOC_AARCH64_ADR_GOT_PAGE
:
5894 case BFD_RELOC_AARCH64_GOT_LD_PREL19
:
5895 case BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14
:
5896 case BFD_RELOC_AARCH64_LD32_GOT_LO12_NC
:
5897 case BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15
:
5898 case BFD_RELOC_AARCH64_LD64_GOT_LO12_NC
:
5899 case BFD_RELOC_AARCH64_LD64_GOTOFF_LO15
:
5900 case BFD_RELOC_AARCH64_MOVW_GOTOFF_G0_NC
:
5901 case BFD_RELOC_AARCH64_MOVW_GOTOFF_G1
:
5902 if (globals
->root
.sgot
== NULL
)
5903 BFD_ASSERT (h
!= NULL
);
5905 relative_reloc
= FALSE
;
5910 /* If a symbol is not dynamic and is not undefined weak, bind it
5911 locally and generate a RELATIVE relocation under PIC mode.
5913 NOTE: one symbol may be referenced by several relocations, we
5914 should only generate one RELATIVE relocation for that symbol.
5915 Therefore, check GOT offset mark first. */
5916 if (h
->dynindx
== -1
5918 && h
->root
.type
!= bfd_link_hash_undefweak
5919 && bfd_link_pic (info
)
5920 && !symbol_got_offset_mark_p (input_bfd
, h
, r_symndx
))
5921 relative_reloc
= TRUE
;
5923 value
= aarch64_calculate_got_entry_vma (h
, globals
, info
, value
,
5925 unresolved_reloc_p
);
5926 /* Record the GOT entry address which will be used when generating
5927 RELATIVE relocation. */
5929 got_entry_addr
= value
;
5931 if (aarch64_relocation_aginst_gp_p (bfd_r_type
))
5932 addend
= (globals
->root
.sgot
->output_section
->vma
5933 + globals
->root
.sgot
->output_offset
);
5934 value
= _bfd_aarch64_elf_resolve_relocation (bfd_r_type
, place
, value
,
5935 addend
, weak_undef_p
);
5940 struct elf_aarch64_local_symbol
*locals
5941 = elf_aarch64_locals (input_bfd
);
5945 int howto_index
= bfd_r_type
- BFD_RELOC_AARCH64_RELOC_START
;
5947 /* xgettext:c-format */
5948 (_("%pB: local symbol descriptor table be NULL when applying "
5949 "relocation %s against local symbol"),
5950 input_bfd
, elfNN_aarch64_howto_table
[howto_index
].name
);
5954 off
= symbol_got_offset (input_bfd
, h
, r_symndx
);
5955 base_got
= globals
->root
.sgot
;
5956 got_entry_addr
= (base_got
->output_section
->vma
5957 + base_got
->output_offset
+ off
);
5959 if (!symbol_got_offset_mark_p (input_bfd
, h
, r_symndx
))
5961 bfd_put_64 (output_bfd
, value
, base_got
->contents
+ off
);
5963 /* For local symbol, we have done absolute relocation in static
5964 linking stage. While for shared library, we need to update the
5965 content of GOT entry according to the shared object's runtime
5966 base address. So, we need to generate a R_AARCH64_RELATIVE reloc
5967 for dynamic linker. */
5968 if (bfd_link_pic (info
))
5969 relative_reloc
= TRUE
;
5971 symbol_got_offset_mark (input_bfd
, h
, r_symndx
);
5974 /* Update the relocation value to GOT entry addr as we have transformed
5975 the direct data access into indirect data access through GOT. */
5976 value
= got_entry_addr
;
5978 if (aarch64_relocation_aginst_gp_p (bfd_r_type
))
5979 addend
= base_got
->output_section
->vma
+ base_got
->output_offset
;
5981 value
= _bfd_aarch64_elf_resolve_relocation (bfd_r_type
, place
, value
,
5982 addend
, weak_undef_p
);
5988 Elf_Internal_Rela outrel
;
5990 s
= globals
->root
.srelgot
;
5994 outrel
.r_offset
= got_entry_addr
;
5995 outrel
.r_info
= ELFNN_R_INFO (0, AARCH64_R (RELATIVE
));
5996 outrel
.r_addend
= orig_value
;
5997 elf_append_rela (output_bfd
, s
, &outrel
);
6001 case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC
:
6002 case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21
:
6003 case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21
:
6004 case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21
:
6005 case BFD_RELOC_AARCH64_TLSIE_LD32_GOTTPREL_LO12_NC
:
6006 case BFD_RELOC_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC
:
6007 case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19
:
6008 case BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC
:
6009 case BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21
:
6010 case BFD_RELOC_AARCH64_TLSLD_ADR_PREL21
:
6011 if (globals
->root
.sgot
== NULL
)
6012 return bfd_reloc_notsupported
;
6014 value
= (symbol_got_offset (input_bfd
, h
, r_symndx
)
6015 + globals
->root
.sgot
->output_section
->vma
6016 + globals
->root
.sgot
->output_offset
);
6018 value
= _bfd_aarch64_elf_resolve_relocation (bfd_r_type
, place
, value
,
6020 *unresolved_reloc_p
= FALSE
;
6023 case BFD_RELOC_AARCH64_TLSGD_MOVW_G0_NC
:
6024 case BFD_RELOC_AARCH64_TLSGD_MOVW_G1
:
6025 case BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G0_NC
:
6026 case BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G1
:
6027 if (globals
->root
.sgot
== NULL
)
6028 return bfd_reloc_notsupported
;
6030 value
= symbol_got_offset (input_bfd
, h
, r_symndx
);
6031 value
= _bfd_aarch64_elf_resolve_relocation (bfd_r_type
, place
, value
,
6033 *unresolved_reloc_p
= FALSE
;
6036 case BFD_RELOC_AARCH64_TLSLD_ADD_DTPREL_HI12
:
6037 case BFD_RELOC_AARCH64_TLSLD_ADD_DTPREL_LO12
:
6038 case BFD_RELOC_AARCH64_TLSLD_ADD_DTPREL_LO12_NC
:
6039 case BFD_RELOC_AARCH64_TLSLD_LDST16_DTPREL_LO12
:
6040 case BFD_RELOC_AARCH64_TLSLD_LDST16_DTPREL_LO12_NC
:
6041 case BFD_RELOC_AARCH64_TLSLD_LDST32_DTPREL_LO12
:
6042 case BFD_RELOC_AARCH64_TLSLD_LDST32_DTPREL_LO12_NC
:
6043 case BFD_RELOC_AARCH64_TLSLD_LDST64_DTPREL_LO12
:
6044 case BFD_RELOC_AARCH64_TLSLD_LDST64_DTPREL_LO12_NC
:
6045 case BFD_RELOC_AARCH64_TLSLD_LDST8_DTPREL_LO12
:
6046 case BFD_RELOC_AARCH64_TLSLD_LDST8_DTPREL_LO12_NC
:
6047 case BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G0
:
6048 case BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G0_NC
:
6049 case BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G1
:
6050 case BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G1_NC
:
6051 case BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G2
:
6052 value
= _bfd_aarch64_elf_resolve_relocation (bfd_r_type
, place
, value
,
6053 signed_addend
- dtpoff_base (info
),
6057 case BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_HI12
:
6058 case BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_LO12
:
6059 case BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_LO12_NC
:
6060 case BFD_RELOC_AARCH64_TLSLE_LDST16_TPREL_LO12
:
6061 case BFD_RELOC_AARCH64_TLSLE_LDST16_TPREL_LO12_NC
:
6062 case BFD_RELOC_AARCH64_TLSLE_LDST32_TPREL_LO12
:
6063 case BFD_RELOC_AARCH64_TLSLE_LDST32_TPREL_LO12_NC
:
6064 case BFD_RELOC_AARCH64_TLSLE_LDST64_TPREL_LO12
:
6065 case BFD_RELOC_AARCH64_TLSLE_LDST64_TPREL_LO12_NC
:
6066 case BFD_RELOC_AARCH64_TLSLE_LDST8_TPREL_LO12
:
6067 case BFD_RELOC_AARCH64_TLSLE_LDST8_TPREL_LO12_NC
:
6068 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0
:
6069 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC
:
6070 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1
:
6071 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1_NC
:
6072 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G2
:
6073 value
= _bfd_aarch64_elf_resolve_relocation (bfd_r_type
, place
, value
,
6074 signed_addend
- tpoff_base (info
),
6076 *unresolved_reloc_p
= FALSE
;
6079 case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12
:
6080 case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21
:
6081 case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21
:
6082 case BFD_RELOC_AARCH64_TLSDESC_LD32_LO12_NC
:
6083 case BFD_RELOC_AARCH64_TLSDESC_LD64_LO12
:
6084 case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19
:
6085 if (globals
->root
.sgot
== NULL
)
6086 return bfd_reloc_notsupported
;
6087 value
= (symbol_tlsdesc_got_offset (input_bfd
, h
, r_symndx
)
6088 + globals
->root
.sgotplt
->output_section
->vma
6089 + globals
->root
.sgotplt
->output_offset
6090 + globals
->sgotplt_jump_table_size
);
6092 value
= _bfd_aarch64_elf_resolve_relocation (bfd_r_type
, place
, value
,
6094 *unresolved_reloc_p
= FALSE
;
6097 case BFD_RELOC_AARCH64_TLSDESC_OFF_G0_NC
:
6098 case BFD_RELOC_AARCH64_TLSDESC_OFF_G1
:
6099 if (globals
->root
.sgot
== NULL
)
6100 return bfd_reloc_notsupported
;
6102 value
= (symbol_tlsdesc_got_offset (input_bfd
, h
, r_symndx
)
6103 + globals
->root
.sgotplt
->output_section
->vma
6104 + globals
->root
.sgotplt
->output_offset
6105 + globals
->sgotplt_jump_table_size
);
6107 value
-= (globals
->root
.sgot
->output_section
->vma
6108 + globals
->root
.sgot
->output_offset
);
6110 value
= _bfd_aarch64_elf_resolve_relocation (bfd_r_type
, place
, value
,
6112 *unresolved_reloc_p
= FALSE
;
6116 return bfd_reloc_notsupported
;
6120 *saved_addend
= value
;
6122 /* Only apply the final relocation in a sequence. */
6124 return bfd_reloc_continue
;
6126 return _bfd_aarch64_elf_put_addend (input_bfd
, hit_data
, bfd_r_type
,
6130 /* LP64 and ILP32 operates on x- and w-registers respectively.
6131 Next definitions take into account the difference between
6132 corresponding machine codes. R means x-register if the target
6133 arch is LP64, and w-register if the target is ILP32. */
6136 # define add_R0_R0 (0x91000000)
6137 # define add_R0_R0_R1 (0x8b000020)
6138 # define add_R0_R1 (0x91400020)
6139 # define ldr_R0 (0x58000000)
6140 # define ldr_R0_mask(i) (i & 0xffffffe0)
6141 # define ldr_R0_x0 (0xf9400000)
6142 # define ldr_hw_R0 (0xf2a00000)
6143 # define movk_R0 (0xf2800000)
6144 # define movz_R0 (0xd2a00000)
6145 # define movz_hw_R0 (0xd2c00000)
6146 #else /*ARCH_SIZE == 32 */
6147 # define add_R0_R0 (0x11000000)
6148 # define add_R0_R0_R1 (0x0b000020)
6149 # define add_R0_R1 (0x11400020)
6150 # define ldr_R0 (0x18000000)
6151 # define ldr_R0_mask(i) (i & 0xbfffffe0)
6152 # define ldr_R0_x0 (0xb9400000)
6153 # define ldr_hw_R0 (0x72a00000)
6154 # define movk_R0 (0x72800000)
6155 # define movz_R0 (0x52a00000)
6156 # define movz_hw_R0 (0x52c00000)
6159 /* Structure to hold payload for _bfd_aarch64_erratum_843419_clear_stub,
6160 it is used to identify the stub information to reset. */
6162 struct erratum_843419_branch_to_stub_clear_data
6164 bfd_vma adrp_offset
;
6165 asection
*output_section
;
6168 /* Clear the erratum information for GEN_ENTRY if the ADRP_OFFSET and
6169 section inside IN_ARG matches. The clearing is done by setting the
6170 stub_type to none. */
6173 _bfd_aarch64_erratum_843419_clear_stub (struct bfd_hash_entry
*gen_entry
,
6176 struct elf_aarch64_stub_hash_entry
*stub_entry
6177 = (struct elf_aarch64_stub_hash_entry
*) gen_entry
;
6178 struct erratum_843419_branch_to_stub_clear_data
*data
6179 = (struct erratum_843419_branch_to_stub_clear_data
*) in_arg
;
6181 if (stub_entry
->target_section
!= data
->output_section
6182 || stub_entry
->stub_type
!= aarch64_stub_erratum_843419_veneer
6183 || stub_entry
->adrp_offset
!= data
->adrp_offset
)
6186 /* Change the stub type instead of removing the entry, removing from the hash
6187 table would be slower and we have already reserved the memory for the entry
6188 so there wouldn't be much gain. Changing the stub also keeps around a
6189 record of what was there before. */
6190 stub_entry
->stub_type
= aarch64_stub_none
;
6192 /* We're done and there could have been only one matching stub at that
6193 particular offset, so abort further traversal. */
6197 /* TLS Relaxations may relax an adrp sequence that matches the erratum 843419
6198 sequence. In this case the erratum no longer applies and we need to remove
6199 the entry from the pending stub generation. This clears matching adrp insn
6200 at ADRP_OFFSET in INPUT_SECTION in the stub table defined in GLOBALS. */
6203 clear_erratum_843419_entry (struct elf_aarch64_link_hash_table
*globals
,
6204 bfd_vma adrp_offset
, asection
*input_section
)
6206 if (globals
->fix_erratum_843419
)
6208 struct erratum_843419_branch_to_stub_clear_data data
;
6209 data
.adrp_offset
= adrp_offset
;
6210 data
.output_section
= input_section
;
6212 bfd_hash_traverse (&globals
->stub_hash_table
,
6213 _bfd_aarch64_erratum_843419_clear_stub
, &data
);
6217 /* Handle TLS relaxations. Relaxing is possible for symbols that use
6218 R_AARCH64_TLSDESC_ADR_{PAGE, LD64_LO12_NC, ADD_LO12_NC} during a static
6221 Return bfd_reloc_ok if we're done, bfd_reloc_continue if the caller
6222 is to then call final_link_relocate. Return other values in the
6225 static bfd_reloc_status_type
6226 elfNN_aarch64_tls_relax (struct elf_aarch64_link_hash_table
*globals
,
6227 bfd
*input_bfd
, asection
*input_section
,
6228 bfd_byte
*contents
, Elf_Internal_Rela
*rel
,
6229 struct elf_link_hash_entry
*h
)
6231 bfd_boolean is_local
= h
== NULL
;
6232 unsigned int r_type
= ELFNN_R_TYPE (rel
->r_info
);
6235 BFD_ASSERT (globals
&& input_bfd
&& contents
&& rel
);
6237 switch (elfNN_aarch64_bfd_reloc_from_type (input_bfd
, r_type
))
6239 case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21
:
6240 case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21
:
6243 /* GD->LE relaxation:
6244 adrp x0, :tlsgd:var => movz R0, :tprel_g1:var
6246 adrp x0, :tlsdesc:var => movz R0, :tprel_g1:var
6248 Where R is x for LP64, and w for ILP32. */
6249 bfd_putl32 (movz_R0
, contents
+ rel
->r_offset
);
6250 /* We have relaxed the adrp into a mov, we may have to clear any
6251 pending erratum fixes. */
6252 clear_erratum_843419_entry (globals
, rel
->r_offset
, input_section
);
6253 return bfd_reloc_continue
;
6257 /* GD->IE relaxation:
6258 adrp x0, :tlsgd:var => adrp x0, :gottprel:var
6260 adrp x0, :tlsdesc:var => adrp x0, :gottprel:var
6262 return bfd_reloc_continue
;
6265 case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21
:
6269 case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19
:
6272 /* Tiny TLSDESC->LE relaxation:
6273 ldr x1, :tlsdesc:var => movz R0, #:tprel_g1:var
6274 adr x0, :tlsdesc:var => movk R0, #:tprel_g0_nc:var
6278 Where R is x for LP64, and w for ILP32. */
6279 BFD_ASSERT (ELFNN_R_TYPE (rel
[1].r_info
) == AARCH64_R (TLSDESC_ADR_PREL21
));
6280 BFD_ASSERT (ELFNN_R_TYPE (rel
[2].r_info
) == AARCH64_R (TLSDESC_CALL
));
6282 rel
[1].r_info
= ELFNN_R_INFO (ELFNN_R_SYM (rel
->r_info
),
6283 AARCH64_R (TLSLE_MOVW_TPREL_G0_NC
));
6284 rel
[2].r_info
= ELFNN_R_INFO (STN_UNDEF
, R_AARCH64_NONE
);
6286 bfd_putl32 (movz_R0
, contents
+ rel
->r_offset
);
6287 bfd_putl32 (movk_R0
, contents
+ rel
->r_offset
+ 4);
6288 bfd_putl32 (INSN_NOP
, contents
+ rel
->r_offset
+ 8);
6289 return bfd_reloc_continue
;
6293 /* Tiny TLSDESC->IE relaxation:
6294 ldr x1, :tlsdesc:var => ldr x0, :gottprel:var
6295 adr x0, :tlsdesc:var => nop
6299 BFD_ASSERT (ELFNN_R_TYPE (rel
[1].r_info
) == AARCH64_R (TLSDESC_ADR_PREL21
));
6300 BFD_ASSERT (ELFNN_R_TYPE (rel
[2].r_info
) == AARCH64_R (TLSDESC_CALL
));
6302 rel
[1].r_info
= ELFNN_R_INFO (STN_UNDEF
, R_AARCH64_NONE
);
6303 rel
[2].r_info
= ELFNN_R_INFO (STN_UNDEF
, R_AARCH64_NONE
);
6305 bfd_putl32 (ldr_R0
, contents
+ rel
->r_offset
);
6306 bfd_putl32 (INSN_NOP
, contents
+ rel
->r_offset
+ 4);
6307 bfd_putl32 (INSN_NOP
, contents
+ rel
->r_offset
+ 8);
6308 return bfd_reloc_continue
;
6311 case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21
:
6314 /* Tiny GD->LE relaxation:
6315 adr x0, :tlsgd:var => mrs x1, tpidr_el0
6316 bl __tls_get_addr => add R0, R1, #:tprel_hi12:x, lsl #12
6317 nop => add R0, R0, #:tprel_lo12_nc:x
6319 Where R is x for LP64, and x for Ilp32. */
6321 /* First kill the tls_get_addr reloc on the bl instruction. */
6322 BFD_ASSERT (rel
->r_offset
+ 4 == rel
[1].r_offset
);
6324 bfd_putl32 (0xd53bd041, contents
+ rel
->r_offset
+ 0);
6325 bfd_putl32 (add_R0_R1
, contents
+ rel
->r_offset
+ 4);
6326 bfd_putl32 (add_R0_R0
, contents
+ rel
->r_offset
+ 8);
6328 rel
[1].r_info
= ELFNN_R_INFO (ELFNN_R_SYM (rel
->r_info
),
6329 AARCH64_R (TLSLE_ADD_TPREL_LO12_NC
));
6330 rel
[1].r_offset
= rel
->r_offset
+ 8;
6332 /* Move the current relocation to the second instruction in
6335 rel
->r_info
= ELFNN_R_INFO (ELFNN_R_SYM (rel
->r_info
),
6336 AARCH64_R (TLSLE_ADD_TPREL_HI12
));
6337 return bfd_reloc_continue
;
6341 /* Tiny GD->IE relaxation:
6342 adr x0, :tlsgd:var => ldr R0, :gottprel:var
6343 bl __tls_get_addr => mrs x1, tpidr_el0
6344 nop => add R0, R0, R1
6346 Where R is x for LP64, and w for Ilp32. */
6348 /* First kill the tls_get_addr reloc on the bl instruction. */
6349 BFD_ASSERT (rel
->r_offset
+ 4 == rel
[1].r_offset
);
6350 rel
[1].r_info
= ELFNN_R_INFO (STN_UNDEF
, R_AARCH64_NONE
);
6352 bfd_putl32 (ldr_R0
, contents
+ rel
->r_offset
);
6353 bfd_putl32 (0xd53bd041, contents
+ rel
->r_offset
+ 4);
6354 bfd_putl32 (add_R0_R0_R1
, contents
+ rel
->r_offset
+ 8);
6355 return bfd_reloc_continue
;
6359 case BFD_RELOC_AARCH64_TLSGD_MOVW_G1
:
6360 BFD_ASSERT (ELFNN_R_TYPE (rel
[1].r_info
) == AARCH64_R (TLSGD_MOVW_G0_NC
));
6361 BFD_ASSERT (rel
->r_offset
+ 12 == rel
[2].r_offset
);
6362 BFD_ASSERT (ELFNN_R_TYPE (rel
[2].r_info
) == AARCH64_R (CALL26
));
6366 /* Large GD->LE relaxation:
6367 movz x0, #:tlsgd_g1:var => movz x0, #:tprel_g2:var, lsl #32
6368 movk x0, #:tlsgd_g0_nc:var => movk x0, #:tprel_g1_nc:var, lsl #16
6369 add x0, gp, x0 => movk x0, #:tprel_g0_nc:var
6370 bl __tls_get_addr => mrs x1, tpidr_el0
6371 nop => add x0, x0, x1
6373 rel
[2].r_info
= ELFNN_R_INFO (ELFNN_R_SYM (rel
->r_info
),
6374 AARCH64_R (TLSLE_MOVW_TPREL_G0_NC
));
6375 rel
[2].r_offset
= rel
->r_offset
+ 8;
6377 bfd_putl32 (movz_hw_R0
, contents
+ rel
->r_offset
+ 0);
6378 bfd_putl32 (ldr_hw_R0
, contents
+ rel
->r_offset
+ 4);
6379 bfd_putl32 (movk_R0
, contents
+ rel
->r_offset
+ 8);
6380 bfd_putl32 (0xd53bd041, contents
+ rel
->r_offset
+ 12);
6381 bfd_putl32 (add_R0_R0_R1
, contents
+ rel
->r_offset
+ 16);
6385 /* Large GD->IE relaxation:
6386 movz x0, #:tlsgd_g1:var => movz x0, #:gottprel_g1:var, lsl #16
6387 movk x0, #:tlsgd_g0_nc:var => movk x0, #:gottprel_g0_nc:var
6388 add x0, gp, x0 => ldr x0, [gp, x0]
6389 bl __tls_get_addr => mrs x1, tpidr_el0
6390 nop => add x0, x0, x1
6392 rel
[2].r_info
= ELFNN_R_INFO (STN_UNDEF
, R_AARCH64_NONE
);
6393 bfd_putl32 (0xd2a80000, contents
+ rel
->r_offset
+ 0);
6394 bfd_putl32 (ldr_R0
, contents
+ rel
->r_offset
+ 8);
6395 bfd_putl32 (0xd53bd041, contents
+ rel
->r_offset
+ 12);
6396 bfd_putl32 (add_R0_R0_R1
, contents
+ rel
->r_offset
+ 16);
6398 return bfd_reloc_continue
;
6400 case BFD_RELOC_AARCH64_TLSGD_MOVW_G0_NC
:
6401 return bfd_reloc_continue
;
6404 case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19
:
6405 return bfd_reloc_continue
;
6407 case BFD_RELOC_AARCH64_TLSDESC_LDNN_LO12_NC
:
6410 /* GD->LE relaxation:
6411 ldr xd, [x0, #:tlsdesc_lo12:var] => movk x0, :tprel_g0_nc:var
6413 Where R is x for lp64 mode, and w for ILP32 mode. */
6414 bfd_putl32 (movk_R0
, contents
+ rel
->r_offset
);
6415 return bfd_reloc_continue
;
6419 /* GD->IE relaxation:
6420 ldr xd, [x0, #:tlsdesc_lo12:var] => ldr R0, [x0, #:gottprel_lo12:var]
6422 Where R is x for lp64 mode, and w for ILP32 mode. */
6423 insn
= bfd_getl32 (contents
+ rel
->r_offset
);
6424 bfd_putl32 (ldr_R0_mask (insn
), contents
+ rel
->r_offset
);
6425 return bfd_reloc_continue
;
6428 case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC
:
6431 /* GD->LE relaxation
6432 add x0, #:tlsgd_lo12:var => movk R0, :tprel_g0_nc:var
6433 bl __tls_get_addr => mrs x1, tpidr_el0
6434 nop => add R0, R1, R0
6436 Where R is x for lp64 mode, and w for ILP32 mode. */
6438 /* First kill the tls_get_addr reloc on the bl instruction. */
6439 BFD_ASSERT (rel
->r_offset
+ 4 == rel
[1].r_offset
);
6440 rel
[1].r_info
= ELFNN_R_INFO (STN_UNDEF
, R_AARCH64_NONE
);
6442 bfd_putl32 (movk_R0
, contents
+ rel
->r_offset
);
6443 bfd_putl32 (0xd53bd041, contents
+ rel
->r_offset
+ 4);
6444 bfd_putl32 (add_R0_R0_R1
, contents
+ rel
->r_offset
+ 8);
6445 return bfd_reloc_continue
;
6449 /* GD->IE relaxation
6450 ADD x0, #:tlsgd_lo12:var => ldr R0, [x0, #:gottprel_lo12:var]
6451 BL __tls_get_addr => mrs x1, tpidr_el0
6453 NOP => add R0, R1, R0
6455 Where R is x for lp64 mode, and w for ilp32 mode. */
6457 BFD_ASSERT (ELFNN_R_TYPE (rel
[1].r_info
) == AARCH64_R (CALL26
));
6459 /* Remove the relocation on the BL instruction. */
6460 rel
[1].r_info
= ELFNN_R_INFO (STN_UNDEF
, R_AARCH64_NONE
);
6462 /* We choose to fixup the BL and NOP instructions using the
6463 offset from the second relocation to allow flexibility in
6464 scheduling instructions between the ADD and BL. */
6465 bfd_putl32 (ldr_R0_x0
, contents
+ rel
->r_offset
);
6466 bfd_putl32 (0xd53bd041, contents
+ rel
[1].r_offset
);
6467 bfd_putl32 (add_R0_R0_R1
, contents
+ rel
[1].r_offset
+ 4);
6468 return bfd_reloc_continue
;
6471 case BFD_RELOC_AARCH64_TLSDESC_ADD
:
6472 case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12
:
6473 case BFD_RELOC_AARCH64_TLSDESC_CALL
:
6474 /* GD->IE/LE relaxation:
6475 add x0, x0, #:tlsdesc_lo12:var => nop
6478 bfd_putl32 (INSN_NOP
, contents
+ rel
->r_offset
);
6479 return bfd_reloc_ok
;
6481 case BFD_RELOC_AARCH64_TLSDESC_LDR
:
6484 /* GD->LE relaxation:
6485 ldr xd, [gp, xn] => movk R0, #:tprel_g0_nc:var
6487 Where R is x for lp64 mode, and w for ILP32 mode. */
6488 bfd_putl32 (movk_R0
, contents
+ rel
->r_offset
);
6489 return bfd_reloc_continue
;
6493 /* GD->IE relaxation:
6494 ldr xd, [gp, xn] => ldr R0, [gp, xn]
6496 Where R is x for lp64 mode, and w for ILP32 mode. */
6497 insn
= bfd_getl32 (contents
+ rel
->r_offset
);
6498 bfd_putl32 (ldr_R0_mask (insn
), contents
+ rel
->r_offset
);
6499 return bfd_reloc_ok
;
6502 case BFD_RELOC_AARCH64_TLSDESC_OFF_G0_NC
:
6503 /* GD->LE relaxation:
6504 movk xd, #:tlsdesc_off_g0_nc:var => movk R0, #:tprel_g1_nc:var, lsl #16
6506 movk xd, #:tlsdesc_off_g0_nc:var => movk Rd, #:gottprel_g0_nc:var
6508 Where R is x for lp64 mode, and w for ILP32 mode. */
6510 bfd_putl32 (ldr_hw_R0
, contents
+ rel
->r_offset
);
6511 return bfd_reloc_continue
;
6513 case BFD_RELOC_AARCH64_TLSDESC_OFF_G1
:
6516 /* GD->LE relaxation:
6517 movz xd, #:tlsdesc_off_g1:var => movz R0, #:tprel_g2:var, lsl #32
6519 Where R is x for lp64 mode, and w for ILP32 mode. */
6520 bfd_putl32 (movz_hw_R0
, contents
+ rel
->r_offset
);
6521 return bfd_reloc_continue
;
6525 /* GD->IE relaxation:
6526 movz xd, #:tlsdesc_off_g1:var => movz Rd, #:gottprel_g1:var, lsl #16
6528 Where R is x for lp64 mode, and w for ILP32 mode. */
6529 insn
= bfd_getl32 (contents
+ rel
->r_offset
);
6530 bfd_putl32 (movz_R0
| (insn
& 0x1f), contents
+ rel
->r_offset
);
6531 return bfd_reloc_continue
;
6534 case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21
:
6535 /* IE->LE relaxation:
6536 adrp xd, :gottprel:var => movz Rd, :tprel_g1:var
6538 Where R is x for lp64 mode, and w for ILP32 mode. */
6541 insn
= bfd_getl32 (contents
+ rel
->r_offset
);
6542 bfd_putl32 (movz_R0
| (insn
& 0x1f), contents
+ rel
->r_offset
);
6543 /* We have relaxed the adrp into a mov, we may have to clear any
6544 pending erratum fixes. */
6545 clear_erratum_843419_entry (globals
, rel
->r_offset
, input_section
);
6547 return bfd_reloc_continue
;
6549 case BFD_RELOC_AARCH64_TLSIE_LDNN_GOTTPREL_LO12_NC
:
6550 /* IE->LE relaxation:
6551 ldr xd, [xm, #:gottprel_lo12:var] => movk Rd, :tprel_g0_nc:var
6553 Where R is x for lp64 mode, and w for ILP32 mode. */
6556 insn
= bfd_getl32 (contents
+ rel
->r_offset
);
6557 bfd_putl32 (movk_R0
| (insn
& 0x1f), contents
+ rel
->r_offset
);
6559 return bfd_reloc_continue
;
6561 case BFD_RELOC_AARCH64_TLSLD_ADR_PREL21
:
6562 /* LD->LE relaxation (tiny):
6563 adr x0, :tlsldm:x => mrs x0, tpidr_el0
6564 bl __tls_get_addr => add R0, R0, TCB_SIZE
6566 Where R is x for lp64 mode, and w for ilp32 mode. */
6569 BFD_ASSERT (rel
->r_offset
+ 4 == rel
[1].r_offset
);
6570 BFD_ASSERT (ELFNN_R_TYPE (rel
[1].r_info
) == AARCH64_R (CALL26
));
6571 /* No need of CALL26 relocation for tls_get_addr. */
6572 rel
[1].r_info
= ELFNN_R_INFO (STN_UNDEF
, R_AARCH64_NONE
);
6573 bfd_putl32 (0xd53bd040, contents
+ rel
->r_offset
+ 0);
6574 bfd_putl32 (add_R0_R0
| (TCB_SIZE
<< 10),
6575 contents
+ rel
->r_offset
+ 4);
6576 return bfd_reloc_ok
;
6578 return bfd_reloc_continue
;
6580 case BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21
:
6581 /* LD->LE relaxation (small):
6582 adrp x0, :tlsldm:x => mrs x0, tpidr_el0
6586 bfd_putl32 (0xd53bd040, contents
+ rel
->r_offset
);
6587 return bfd_reloc_ok
;
6589 return bfd_reloc_continue
;
6591 case BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC
:
6592 /* LD->LE relaxation (small):
6593 add x0, #:tlsldm_lo12:x => add R0, R0, TCB_SIZE
6594 bl __tls_get_addr => nop
6596 Where R is x for lp64 mode, and w for ilp32 mode. */
6599 BFD_ASSERT (rel
->r_offset
+ 4 == rel
[1].r_offset
);
6600 BFD_ASSERT (ELFNN_R_TYPE (rel
[1].r_info
) == AARCH64_R (CALL26
));
6601 /* No need of CALL26 relocation for tls_get_addr. */
6602 rel
[1].r_info
= ELFNN_R_INFO (STN_UNDEF
, R_AARCH64_NONE
);
6603 bfd_putl32 (add_R0_R0
| (TCB_SIZE
<< 10),
6604 contents
+ rel
->r_offset
+ 0);
6605 bfd_putl32 (INSN_NOP
, contents
+ rel
->r_offset
+ 4);
6606 return bfd_reloc_ok
;
6608 return bfd_reloc_continue
;
6611 return bfd_reloc_continue
;
6614 return bfd_reloc_ok
;
6617 /* Relocate an AArch64 ELF section. */
6620 elfNN_aarch64_relocate_section (bfd
*output_bfd
,
6621 struct bfd_link_info
*info
,
6623 asection
*input_section
,
6625 Elf_Internal_Rela
*relocs
,
6626 Elf_Internal_Sym
*local_syms
,
6627 asection
**local_sections
)
6629 Elf_Internal_Shdr
*symtab_hdr
;
6630 struct elf_link_hash_entry
**sym_hashes
;
6631 Elf_Internal_Rela
*rel
;
6632 Elf_Internal_Rela
*relend
;
6634 struct elf_aarch64_link_hash_table
*globals
;
6635 bfd_boolean save_addend
= FALSE
;
6638 globals
= elf_aarch64_hash_table (info
);
6640 symtab_hdr
= &elf_symtab_hdr (input_bfd
);
6641 sym_hashes
= elf_sym_hashes (input_bfd
);
6644 relend
= relocs
+ input_section
->reloc_count
;
6645 for (; rel
< relend
; rel
++)
6647 unsigned int r_type
;
6648 bfd_reloc_code_real_type bfd_r_type
;
6649 bfd_reloc_code_real_type relaxed_bfd_r_type
;
6650 reloc_howto_type
*howto
;
6651 unsigned long r_symndx
;
6652 Elf_Internal_Sym
*sym
;
6654 struct elf_link_hash_entry
*h
;
6656 bfd_reloc_status_type r
;
6659 bfd_boolean unresolved_reloc
= FALSE
;
6660 char *error_message
= NULL
;
6662 r_symndx
= ELFNN_R_SYM (rel
->r_info
);
6663 r_type
= ELFNN_R_TYPE (rel
->r_info
);
6665 bfd_reloc
.howto
= elfNN_aarch64_howto_from_type (input_bfd
, r_type
);
6666 howto
= bfd_reloc
.howto
;
6669 return _bfd_unrecognized_reloc (input_bfd
, input_section
, r_type
);
6671 bfd_r_type
= elfNN_aarch64_bfd_reloc_from_howto (howto
);
6677 if (r_symndx
< symtab_hdr
->sh_info
)
6679 sym
= local_syms
+ r_symndx
;
6680 sym_type
= ELFNN_ST_TYPE (sym
->st_info
);
6681 sec
= local_sections
[r_symndx
];
6683 /* An object file might have a reference to a local
6684 undefined symbol. This is a daft object file, but we
6685 should at least do something about it. */
6686 if (r_type
!= R_AARCH64_NONE
&& r_type
!= R_AARCH64_NULL
6687 && bfd_is_und_section (sec
)
6688 && ELF_ST_BIND (sym
->st_info
) != STB_WEAK
)
6689 (*info
->callbacks
->undefined_symbol
)
6690 (info
, bfd_elf_string_from_elf_section
6691 (input_bfd
, symtab_hdr
->sh_link
, sym
->st_name
),
6692 input_bfd
, input_section
, rel
->r_offset
, TRUE
);
6694 relocation
= _bfd_elf_rela_local_sym (output_bfd
, sym
, &sec
, rel
);
6696 /* Relocate against local STT_GNU_IFUNC symbol. */
6697 if (!bfd_link_relocatable (info
)
6698 && ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
)
6700 h
= elfNN_aarch64_get_local_sym_hash (globals
, input_bfd
,
6705 /* Set STT_GNU_IFUNC symbol value. */
6706 h
->root
.u
.def
.value
= sym
->st_value
;
6707 h
->root
.u
.def
.section
= sec
;
6712 bfd_boolean warned
, ignored
;
6714 RELOC_FOR_GLOBAL_SYMBOL (info
, input_bfd
, input_section
, rel
,
6715 r_symndx
, symtab_hdr
, sym_hashes
,
6717 unresolved_reloc
, warned
, ignored
);
6722 if (sec
!= NULL
&& discarded_section (sec
))
6723 RELOC_AGAINST_DISCARDED_SECTION (info
, input_bfd
, input_section
,
6724 rel
, 1, relend
, howto
, 0, contents
);
6726 if (bfd_link_relocatable (info
))
6730 name
= h
->root
.root
.string
;
6733 name
= (bfd_elf_string_from_elf_section
6734 (input_bfd
, symtab_hdr
->sh_link
, sym
->st_name
));
6735 if (name
== NULL
|| *name
== '\0')
6736 name
= bfd_section_name (input_bfd
, sec
);
6740 && r_type
!= R_AARCH64_NONE
6741 && r_type
!= R_AARCH64_NULL
6743 || h
->root
.type
== bfd_link_hash_defined
6744 || h
->root
.type
== bfd_link_hash_defweak
)
6745 && IS_AARCH64_TLS_RELOC (bfd_r_type
) != (sym_type
== STT_TLS
))
6748 ((sym_type
== STT_TLS
6749 /* xgettext:c-format */
6750 ? _("%pB(%pA+%#" PRIx64
"): %s used with TLS symbol %s")
6751 /* xgettext:c-format */
6752 : _("%pB(%pA+%#" PRIx64
"): %s used with non-TLS symbol %s")),
6754 input_section
, (uint64_t) rel
->r_offset
, howto
->name
, name
);
6757 /* We relax only if we can see that there can be a valid transition
6758 from a reloc type to another.
6759 We call elfNN_aarch64_final_link_relocate unless we're completely
6760 done, i.e., the relaxation produced the final output we want. */
6762 relaxed_bfd_r_type
= aarch64_tls_transition (input_bfd
, info
, r_type
,
6764 if (relaxed_bfd_r_type
!= bfd_r_type
)
6766 bfd_r_type
= relaxed_bfd_r_type
;
6767 howto
= elfNN_aarch64_howto_from_bfd_reloc (bfd_r_type
);
6768 BFD_ASSERT (howto
!= NULL
);
6769 r_type
= howto
->type
;
6770 r
= elfNN_aarch64_tls_relax (globals
, input_bfd
, input_section
,
6772 unresolved_reloc
= 0;
6775 r
= bfd_reloc_continue
;
6777 /* There may be multiple consecutive relocations for the
6778 same offset. In that case we are supposed to treat the
6779 output of each relocation as the addend for the next. */
6780 if (rel
+ 1 < relend
6781 && rel
->r_offset
== rel
[1].r_offset
6782 && ELFNN_R_TYPE (rel
[1].r_info
) != R_AARCH64_NONE
6783 && ELFNN_R_TYPE (rel
[1].r_info
) != R_AARCH64_NULL
)
6786 save_addend
= FALSE
;
6788 if (r
== bfd_reloc_continue
)
6789 r
= elfNN_aarch64_final_link_relocate (howto
, input_bfd
, output_bfd
,
6790 input_section
, contents
, rel
,
6791 relocation
, info
, sec
,
6792 h
, &unresolved_reloc
,
6793 save_addend
, &addend
, sym
);
6795 switch (elfNN_aarch64_bfd_reloc_from_type (input_bfd
, r_type
))
6797 case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC
:
6798 case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21
:
6799 case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21
:
6800 case BFD_RELOC_AARCH64_TLSGD_MOVW_G0_NC
:
6801 case BFD_RELOC_AARCH64_TLSGD_MOVW_G1
:
6802 case BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC
:
6803 case BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21
:
6804 case BFD_RELOC_AARCH64_TLSLD_ADR_PREL21
:
6805 if (! symbol_got_offset_mark_p (input_bfd
, h
, r_symndx
))
6807 bfd_boolean need_relocs
= FALSE
;
6812 off
= symbol_got_offset (input_bfd
, h
, r_symndx
);
6813 indx
= h
&& h
->dynindx
!= -1 ? h
->dynindx
: 0;
6816 (!bfd_link_executable (info
) || indx
!= 0) &&
6818 || ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
6819 || h
->root
.type
!= bfd_link_hash_undefweak
);
6821 BFD_ASSERT (globals
->root
.srelgot
!= NULL
);
6825 Elf_Internal_Rela rela
;
6826 rela
.r_info
= ELFNN_R_INFO (indx
, AARCH64_R (TLS_DTPMOD
));
6828 rela
.r_offset
= globals
->root
.sgot
->output_section
->vma
+
6829 globals
->root
.sgot
->output_offset
+ off
;
6832 loc
= globals
->root
.srelgot
->contents
;
6833 loc
+= globals
->root
.srelgot
->reloc_count
++
6834 * RELOC_SIZE (htab
);
6835 bfd_elfNN_swap_reloca_out (output_bfd
, &rela
, loc
);
6837 bfd_reloc_code_real_type real_type
=
6838 elfNN_aarch64_bfd_reloc_from_type (input_bfd
, r_type
);
6840 if (real_type
== BFD_RELOC_AARCH64_TLSLD_ADR_PREL21
6841 || real_type
== BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21
6842 || real_type
== BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC
)
6844 /* For local dynamic, don't generate DTPREL in any case.
6845 Initialize the DTPREL slot into zero, so we get module
6846 base address when invoke runtime TLS resolver. */
6847 bfd_put_NN (output_bfd
, 0,
6848 globals
->root
.sgot
->contents
+ off
6853 bfd_put_NN (output_bfd
,
6854 relocation
- dtpoff_base (info
),
6855 globals
->root
.sgot
->contents
+ off
6860 /* This TLS symbol is global. We emit a
6861 relocation to fixup the tls offset at load
6864 ELFNN_R_INFO (indx
, AARCH64_R (TLS_DTPREL
));
6867 (globals
->root
.sgot
->output_section
->vma
6868 + globals
->root
.sgot
->output_offset
+ off
6871 loc
= globals
->root
.srelgot
->contents
;
6872 loc
+= globals
->root
.srelgot
->reloc_count
++
6873 * RELOC_SIZE (globals
);
6874 bfd_elfNN_swap_reloca_out (output_bfd
, &rela
, loc
);
6875 bfd_put_NN (output_bfd
, (bfd_vma
) 0,
6876 globals
->root
.sgot
->contents
+ off
6882 bfd_put_NN (output_bfd
, (bfd_vma
) 1,
6883 globals
->root
.sgot
->contents
+ off
);
6884 bfd_put_NN (output_bfd
,
6885 relocation
- dtpoff_base (info
),
6886 globals
->root
.sgot
->contents
+ off
6890 symbol_got_offset_mark (input_bfd
, h
, r_symndx
);
6894 case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21
:
6895 case BFD_RELOC_AARCH64_TLSIE_LDNN_GOTTPREL_LO12_NC
:
6896 case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19
:
6897 case BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G0_NC
:
6898 case BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G1
:
6899 if (! symbol_got_offset_mark_p (input_bfd
, h
, r_symndx
))
6901 bfd_boolean need_relocs
= FALSE
;
6906 off
= symbol_got_offset (input_bfd
, h
, r_symndx
);
6908 indx
= h
&& h
->dynindx
!= -1 ? h
->dynindx
: 0;
6911 (!bfd_link_executable (info
) || indx
!= 0) &&
6913 || ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
6914 || h
->root
.type
!= bfd_link_hash_undefweak
);
6916 BFD_ASSERT (globals
->root
.srelgot
!= NULL
);
6920 Elf_Internal_Rela rela
;
6923 rela
.r_addend
= relocation
- dtpoff_base (info
);
6927 rela
.r_info
= ELFNN_R_INFO (indx
, AARCH64_R (TLS_TPREL
));
6928 rela
.r_offset
= globals
->root
.sgot
->output_section
->vma
+
6929 globals
->root
.sgot
->output_offset
+ off
;
6931 loc
= globals
->root
.srelgot
->contents
;
6932 loc
+= globals
->root
.srelgot
->reloc_count
++
6933 * RELOC_SIZE (htab
);
6935 bfd_elfNN_swap_reloca_out (output_bfd
, &rela
, loc
);
6937 bfd_put_NN (output_bfd
, rela
.r_addend
,
6938 globals
->root
.sgot
->contents
+ off
);
6941 bfd_put_NN (output_bfd
, relocation
- tpoff_base (info
),
6942 globals
->root
.sgot
->contents
+ off
);
6944 symbol_got_offset_mark (input_bfd
, h
, r_symndx
);
6948 case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12
:
6949 case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21
:
6950 case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21
:
6951 case BFD_RELOC_AARCH64_TLSDESC_LDNN_LO12_NC
:
6952 case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19
:
6953 case BFD_RELOC_AARCH64_TLSDESC_OFF_G0_NC
:
6954 case BFD_RELOC_AARCH64_TLSDESC_OFF_G1
:
6955 if (! symbol_tlsdesc_got_offset_mark_p (input_bfd
, h
, r_symndx
))
6957 bfd_boolean need_relocs
= FALSE
;
6958 int indx
= h
&& h
->dynindx
!= -1 ? h
->dynindx
: 0;
6959 bfd_vma off
= symbol_tlsdesc_got_offset (input_bfd
, h
, r_symndx
);
6961 need_relocs
= (h
== NULL
6962 || ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
6963 || h
->root
.type
!= bfd_link_hash_undefweak
);
6965 BFD_ASSERT (globals
->root
.srelgot
!= NULL
);
6966 BFD_ASSERT (globals
->root
.sgot
!= NULL
);
6971 Elf_Internal_Rela rela
;
6972 rela
.r_info
= ELFNN_R_INFO (indx
, AARCH64_R (TLSDESC
));
6975 rela
.r_offset
= (globals
->root
.sgotplt
->output_section
->vma
6976 + globals
->root
.sgotplt
->output_offset
6977 + off
+ globals
->sgotplt_jump_table_size
);
6980 rela
.r_addend
= relocation
- dtpoff_base (info
);
6982 /* Allocate the next available slot in the PLT reloc
6983 section to hold our R_AARCH64_TLSDESC, the next
6984 available slot is determined from reloc_count,
6985 which we step. But note, reloc_count was
6986 artifically moved down while allocating slots for
6987 real PLT relocs such that all of the PLT relocs
6988 will fit above the initial reloc_count and the
6989 extra stuff will fit below. */
6990 loc
= globals
->root
.srelplt
->contents
;
6991 loc
+= globals
->root
.srelplt
->reloc_count
++
6992 * RELOC_SIZE (globals
);
6994 bfd_elfNN_swap_reloca_out (output_bfd
, &rela
, loc
);
6996 bfd_put_NN (output_bfd
, (bfd_vma
) 0,
6997 globals
->root
.sgotplt
->contents
+ off
+
6998 globals
->sgotplt_jump_table_size
);
6999 bfd_put_NN (output_bfd
, (bfd_vma
) 0,
7000 globals
->root
.sgotplt
->contents
+ off
+
7001 globals
->sgotplt_jump_table_size
+
7005 symbol_tlsdesc_got_offset_mark (input_bfd
, h
, r_symndx
);
7012 /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
7013 because such sections are not SEC_ALLOC and thus ld.so will
7014 not process them. */
7015 if (unresolved_reloc
7016 && !((input_section
->flags
& SEC_DEBUGGING
) != 0
7018 && _bfd_elf_section_offset (output_bfd
, info
, input_section
,
7019 +rel
->r_offset
) != (bfd_vma
) - 1)
7022 /* xgettext:c-format */
7023 (_("%pB(%pA+%#" PRIx64
"): "
7024 "unresolvable %s relocation against symbol `%s'"),
7025 input_bfd
, input_section
, (uint64_t) rel
->r_offset
, howto
->name
,
7026 h
->root
.root
.string
);
7030 if (r
!= bfd_reloc_ok
&& r
!= bfd_reloc_continue
)
7032 bfd_reloc_code_real_type real_r_type
7033 = elfNN_aarch64_bfd_reloc_from_type (input_bfd
, r_type
);
7037 case bfd_reloc_overflow
:
7038 (*info
->callbacks
->reloc_overflow
)
7039 (info
, (h
? &h
->root
: NULL
), name
, howto
->name
, (bfd_vma
) 0,
7040 input_bfd
, input_section
, rel
->r_offset
);
7041 if (real_r_type
== BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15
7042 || real_r_type
== BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14
)
7044 (*info
->callbacks
->warning
)
7046 _("too many GOT entries for -fpic, "
7047 "please recompile with -fPIC"),
7048 name
, input_bfd
, input_section
, rel
->r_offset
);
7051 /* Overflow can occur when a variable is referenced with a type
7052 that has a larger alignment than the type with which it was
7054 file1.c: extern int foo; int a (void) { return foo; }
7055 file2.c: char bar, foo, baz;
7056 If the variable is placed into a data section at an offset
7057 that is incompatible with the larger alignment requirement
7058 overflow will occur. (Strictly speaking this is not overflow
7059 but rather an alignment problem, but the bfd_reloc_ error
7060 enum does not have a value to cover that situation).
7062 Try to catch this situation here and provide a more helpful
7063 error message to the user. */
7064 if (addend
& ((1 << howto
->rightshift
) - 1)
7065 /* FIXME: Are we testing all of the appropriate reloc
7067 && (real_r_type
== BFD_RELOC_AARCH64_LD_LO19_PCREL
7068 || real_r_type
== BFD_RELOC_AARCH64_LDST16_LO12
7069 || real_r_type
== BFD_RELOC_AARCH64_LDST32_LO12
7070 || real_r_type
== BFD_RELOC_AARCH64_LDST64_LO12
7071 || real_r_type
== BFD_RELOC_AARCH64_LDST128_LO12
))
7073 info
->callbacks
->warning
7074 (info
, _("one possible cause of this error is that the \
7075 symbol is being referenced in the indicated code as if it had a larger \
7076 alignment than was declared where it was defined"),
7077 name
, input_bfd
, input_section
, rel
->r_offset
);
7081 case bfd_reloc_undefined
:
7082 (*info
->callbacks
->undefined_symbol
)
7083 (info
, name
, input_bfd
, input_section
, rel
->r_offset
, TRUE
);
7086 case bfd_reloc_outofrange
:
7087 error_message
= _("out of range");
7090 case bfd_reloc_notsupported
:
7091 error_message
= _("unsupported relocation");
7094 case bfd_reloc_dangerous
:
7095 /* error_message should already be set. */
7099 error_message
= _("unknown error");
7103 BFD_ASSERT (error_message
!= NULL
);
7104 (*info
->callbacks
->reloc_dangerous
)
7105 (info
, error_message
, input_bfd
, input_section
, rel
->r_offset
);
7117 /* Set the right machine number. */
7120 elfNN_aarch64_object_p (bfd
*abfd
)
7123 bfd_default_set_arch_mach (abfd
, bfd_arch_aarch64
, bfd_mach_aarch64_ilp32
);
7125 bfd_default_set_arch_mach (abfd
, bfd_arch_aarch64
, bfd_mach_aarch64
);
7130 /* Function to keep AArch64 specific flags in the ELF header. */
7133 elfNN_aarch64_set_private_flags (bfd
*abfd
, flagword flags
)
7135 if (elf_flags_init (abfd
) && elf_elfheader (abfd
)->e_flags
!= flags
)
7140 elf_elfheader (abfd
)->e_flags
= flags
;
7141 elf_flags_init (abfd
) = TRUE
;
7147 /* Merge backend specific data from an object file to the output
7148 object file when linking. */
7151 elfNN_aarch64_merge_private_bfd_data (bfd
*ibfd
, struct bfd_link_info
*info
)
7153 bfd
*obfd
= info
->output_bfd
;
7156 bfd_boolean flags_compatible
= TRUE
;
7159 /* Check if we have the same endianess. */
7160 if (!_bfd_generic_verify_endian_match (ibfd
, info
))
7163 if (!is_aarch64_elf (ibfd
) || !is_aarch64_elf (obfd
))
7166 /* The input BFD must have had its flags initialised. */
7167 /* The following seems bogus to me -- The flags are initialized in
7168 the assembler but I don't think an elf_flags_init field is
7169 written into the object. */
7170 /* BFD_ASSERT (elf_flags_init (ibfd)); */
7172 in_flags
= elf_elfheader (ibfd
)->e_flags
;
7173 out_flags
= elf_elfheader (obfd
)->e_flags
;
7175 if (!elf_flags_init (obfd
))
7177 /* If the input is the default architecture and had the default
7178 flags then do not bother setting the flags for the output
7179 architecture, instead allow future merges to do this. If no
7180 future merges ever set these flags then they will retain their
7181 uninitialised values, which surprise surprise, correspond
7182 to the default values. */
7183 if (bfd_get_arch_info (ibfd
)->the_default
7184 && elf_elfheader (ibfd
)->e_flags
== 0)
7187 elf_flags_init (obfd
) = TRUE
;
7188 elf_elfheader (obfd
)->e_flags
= in_flags
;
7190 if (bfd_get_arch (obfd
) == bfd_get_arch (ibfd
)
7191 && bfd_get_arch_info (obfd
)->the_default
)
7192 return bfd_set_arch_mach (obfd
, bfd_get_arch (ibfd
),
7193 bfd_get_mach (ibfd
));
7198 /* Identical flags must be compatible. */
7199 if (in_flags
== out_flags
)
7202 /* Check to see if the input BFD actually contains any sections. If
7203 not, its flags may not have been initialised either, but it
7204 cannot actually cause any incompatiblity. Do not short-circuit
7205 dynamic objects; their section list may be emptied by
7206 elf_link_add_object_symbols.
7208 Also check to see if there are no code sections in the input.
7209 In this case there is no need to check for code specific flags.
7210 XXX - do we need to worry about floating-point format compatability
7211 in data sections ? */
7212 if (!(ibfd
->flags
& DYNAMIC
))
7214 bfd_boolean null_input_bfd
= TRUE
;
7215 bfd_boolean only_data_sections
= TRUE
;
7217 for (sec
= ibfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
7219 if ((bfd_get_section_flags (ibfd
, sec
)
7220 & (SEC_LOAD
| SEC_CODE
| SEC_HAS_CONTENTS
))
7221 == (SEC_LOAD
| SEC_CODE
| SEC_HAS_CONTENTS
))
7222 only_data_sections
= FALSE
;
7224 null_input_bfd
= FALSE
;
7228 if (null_input_bfd
|| only_data_sections
)
7232 return flags_compatible
;
7235 /* Display the flags field. */
7238 elfNN_aarch64_print_private_bfd_data (bfd
*abfd
, void *ptr
)
7240 FILE *file
= (FILE *) ptr
;
7241 unsigned long flags
;
7243 BFD_ASSERT (abfd
!= NULL
&& ptr
!= NULL
);
7245 /* Print normal ELF private data. */
7246 _bfd_elf_print_private_bfd_data (abfd
, ptr
);
7248 flags
= elf_elfheader (abfd
)->e_flags
;
7249 /* Ignore init flag - it may not be set, despite the flags field
7250 containing valid data. */
7252 /* xgettext:c-format */
7253 fprintf (file
, _("private flags = %lx:"), elf_elfheader (abfd
)->e_flags
);
7256 fprintf (file
, _("<Unrecognised flag bits set>"));
7263 /* Find dynamic relocs for H that apply to read-only sections. */
7266 readonly_dynrelocs (struct elf_link_hash_entry
*h
)
7268 struct elf_dyn_relocs
*p
;
7270 for (p
= elf_aarch64_hash_entry (h
)->dyn_relocs
; p
!= NULL
; p
= p
->next
)
7272 asection
*s
= p
->sec
->output_section
;
7274 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
7280 /* Return true if we need copy relocation against EH. */
7283 need_copy_relocation_p (struct elf_aarch64_link_hash_entry
*eh
)
7285 struct elf_dyn_relocs
*p
;
7288 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
7290 /* If there is any pc-relative reference, we need to keep copy relocation
7291 to avoid propagating the relocation into runtime that current glibc
7292 does not support. */
7296 s
= p
->sec
->output_section
;
7297 /* Need copy relocation if it's against read-only section. */
7298 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
7305 /* Adjust a symbol defined by a dynamic object and referenced by a
7306 regular object. The current definition is in some section of the
7307 dynamic object, but we're not including those sections. We have to
7308 change the definition to something the rest of the link can
7312 elfNN_aarch64_adjust_dynamic_symbol (struct bfd_link_info
*info
,
7313 struct elf_link_hash_entry
*h
)
7315 struct elf_aarch64_link_hash_table
*htab
;
7318 /* If this is a function, put it in the procedure linkage table. We
7319 will fill in the contents of the procedure linkage table later,
7320 when we know the address of the .got section. */
7321 if (h
->type
== STT_FUNC
|| h
->type
== STT_GNU_IFUNC
|| h
->needs_plt
)
7323 if (h
->plt
.refcount
<= 0
7324 || (h
->type
!= STT_GNU_IFUNC
7325 && (SYMBOL_CALLS_LOCAL (info
, h
)
7326 || (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
7327 && h
->root
.type
== bfd_link_hash_undefweak
))))
7329 /* This case can occur if we saw a CALL26 reloc in
7330 an input file, but the symbol wasn't referred to
7331 by a dynamic object or all references were
7332 garbage collected. In which case we can end up
7334 h
->plt
.offset
= (bfd_vma
) - 1;
7341 /* Otherwise, reset to -1. */
7342 h
->plt
.offset
= (bfd_vma
) - 1;
7345 /* If this is a weak symbol, and there is a real definition, the
7346 processor independent code will have arranged for us to see the
7347 real definition first, and we can just use the same value. */
7348 if (h
->is_weakalias
)
7350 struct elf_link_hash_entry
*def
= weakdef (h
);
7351 BFD_ASSERT (def
->root
.type
== bfd_link_hash_defined
);
7352 h
->root
.u
.def
.section
= def
->root
.u
.def
.section
;
7353 h
->root
.u
.def
.value
= def
->root
.u
.def
.value
;
7354 if (ELIMINATE_COPY_RELOCS
|| info
->nocopyreloc
)
7355 h
->non_got_ref
= def
->non_got_ref
;
7359 /* If we are creating a shared library, we must presume that the
7360 only references to the symbol are via the global offset table.
7361 For such cases we need not do anything here; the relocations will
7362 be handled correctly by relocate_section. */
7363 if (bfd_link_pic (info
))
7366 /* If there are no references to this symbol that do not use the
7367 GOT, we don't need to generate a copy reloc. */
7368 if (!h
->non_got_ref
)
7371 /* If -z nocopyreloc was given, we won't generate them either. */
7372 if (info
->nocopyreloc
)
7378 if (ELIMINATE_COPY_RELOCS
)
7380 struct elf_aarch64_link_hash_entry
*eh
;
7381 /* If we don't find any dynamic relocs in read-only sections, then
7382 we'll be keeping the dynamic relocs and avoiding the copy reloc. */
7383 eh
= (struct elf_aarch64_link_hash_entry
*) h
;
7384 if (!need_copy_relocation_p (eh
))
7391 /* We must allocate the symbol in our .dynbss section, which will
7392 become part of the .bss section of the executable. There will be
7393 an entry for this symbol in the .dynsym section. The dynamic
7394 object will contain position independent code, so all references
7395 from the dynamic object to this symbol will go through the global
7396 offset table. The dynamic linker will use the .dynsym entry to
7397 determine the address it must put in the global offset table, so
7398 both the dynamic object and the regular object will refer to the
7399 same memory location for the variable. */
7401 htab
= elf_aarch64_hash_table (info
);
7403 /* We must generate a R_AARCH64_COPY reloc to tell the dynamic linker
7404 to copy the initial value out of the dynamic object and into the
7405 runtime process image. */
7406 if ((h
->root
.u
.def
.section
->flags
& SEC_READONLY
) != 0)
7408 s
= htab
->root
.sdynrelro
;
7409 srel
= htab
->root
.sreldynrelro
;
7413 s
= htab
->root
.sdynbss
;
7414 srel
= htab
->root
.srelbss
;
7416 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0 && h
->size
!= 0)
7418 srel
->size
+= RELOC_SIZE (htab
);
7422 return _bfd_elf_adjust_dynamic_copy (info
, h
, s
);
7427 elfNN_aarch64_allocate_local_symbols (bfd
*abfd
, unsigned number
)
7429 struct elf_aarch64_local_symbol
*locals
;
7430 locals
= elf_aarch64_locals (abfd
);
7433 locals
= (struct elf_aarch64_local_symbol
*)
7434 bfd_zalloc (abfd
, number
* sizeof (struct elf_aarch64_local_symbol
));
7437 elf_aarch64_locals (abfd
) = locals
;
7442 /* Create the .got section to hold the global offset table. */
7445 aarch64_elf_create_got_section (bfd
*abfd
, struct bfd_link_info
*info
)
7447 const struct elf_backend_data
*bed
= get_elf_backend_data (abfd
);
7450 struct elf_link_hash_entry
*h
;
7451 struct elf_link_hash_table
*htab
= elf_hash_table (info
);
7453 /* This function may be called more than once. */
7454 if (htab
->sgot
!= NULL
)
7457 flags
= bed
->dynamic_sec_flags
;
7459 s
= bfd_make_section_anyway_with_flags (abfd
,
7460 (bed
->rela_plts_and_copies_p
7461 ? ".rela.got" : ".rel.got"),
7462 (bed
->dynamic_sec_flags
7465 || ! bfd_set_section_alignment (abfd
, s
, bed
->s
->log_file_align
))
7469 s
= bfd_make_section_anyway_with_flags (abfd
, ".got", flags
);
7471 || !bfd_set_section_alignment (abfd
, s
, bed
->s
->log_file_align
))
7474 htab
->sgot
->size
+= GOT_ENTRY_SIZE
;
7476 if (bed
->want_got_sym
)
7478 /* Define the symbol _GLOBAL_OFFSET_TABLE_ at the start of the .got
7479 (or .got.plt) section. We don't do this in the linker script
7480 because we don't want to define the symbol if we are not creating
7481 a global offset table. */
7482 h
= _bfd_elf_define_linkage_sym (abfd
, info
, s
,
7483 "_GLOBAL_OFFSET_TABLE_");
7484 elf_hash_table (info
)->hgot
= h
;
7489 if (bed
->want_got_plt
)
7491 s
= bfd_make_section_anyway_with_flags (abfd
, ".got.plt", flags
);
7493 || !bfd_set_section_alignment (abfd
, s
,
7494 bed
->s
->log_file_align
))
7499 /* The first bit of the global offset table is the header. */
7500 s
->size
+= bed
->got_header_size
;
7505 /* Look through the relocs for a section during the first phase. */
7508 elfNN_aarch64_check_relocs (bfd
*abfd
, struct bfd_link_info
*info
,
7509 asection
*sec
, const Elf_Internal_Rela
*relocs
)
7511 Elf_Internal_Shdr
*symtab_hdr
;
7512 struct elf_link_hash_entry
**sym_hashes
;
7513 const Elf_Internal_Rela
*rel
;
7514 const Elf_Internal_Rela
*rel_end
;
7517 struct elf_aarch64_link_hash_table
*htab
;
7519 if (bfd_link_relocatable (info
))
7522 BFD_ASSERT (is_aarch64_elf (abfd
));
7524 htab
= elf_aarch64_hash_table (info
);
7527 symtab_hdr
= &elf_symtab_hdr (abfd
);
7528 sym_hashes
= elf_sym_hashes (abfd
);
7530 rel_end
= relocs
+ sec
->reloc_count
;
7531 for (rel
= relocs
; rel
< rel_end
; rel
++)
7533 struct elf_link_hash_entry
*h
;
7534 unsigned int r_symndx
;
7535 unsigned int r_type
;
7536 bfd_reloc_code_real_type bfd_r_type
;
7537 Elf_Internal_Sym
*isym
;
7539 r_symndx
= ELFNN_R_SYM (rel
->r_info
);
7540 r_type
= ELFNN_R_TYPE (rel
->r_info
);
7542 if (r_symndx
>= NUM_SHDR_ENTRIES (symtab_hdr
))
7544 /* xgettext:c-format */
7545 _bfd_error_handler (_("%pB: bad symbol index: %d"), abfd
, r_symndx
);
7549 if (r_symndx
< symtab_hdr
->sh_info
)
7551 /* A local symbol. */
7552 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
7557 /* Check relocation against local STT_GNU_IFUNC symbol. */
7558 if (ELF_ST_TYPE (isym
->st_info
) == STT_GNU_IFUNC
)
7560 h
= elfNN_aarch64_get_local_sym_hash (htab
, abfd
, rel
,
7565 /* Fake a STT_GNU_IFUNC symbol. */
7566 h
->type
= STT_GNU_IFUNC
;
7569 h
->forced_local
= 1;
7570 h
->root
.type
= bfd_link_hash_defined
;
7577 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
7578 while (h
->root
.type
== bfd_link_hash_indirect
7579 || h
->root
.type
== bfd_link_hash_warning
)
7580 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
7583 /* Could be done earlier, if h were already available. */
7584 bfd_r_type
= aarch64_tls_transition (abfd
, info
, r_type
, h
, r_symndx
);
7588 /* If a relocation refers to _GLOBAL_OFFSET_TABLE_, create the .got.
7589 This shows up in particular in an R_AARCH64_PREL64 in large model
7590 when calculating the pc-relative address to .got section which is
7591 used to initialize the gp register. */
7592 if (h
->root
.root
.string
7593 && strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_") == 0)
7595 if (htab
->root
.dynobj
== NULL
)
7596 htab
->root
.dynobj
= abfd
;
7598 if (! aarch64_elf_create_got_section (htab
->root
.dynobj
, info
))
7601 BFD_ASSERT (h
== htab
->root
.hgot
);
7604 /* Create the ifunc sections for static executables. If we
7605 never see an indirect function symbol nor we are building
7606 a static executable, those sections will be empty and
7607 won't appear in output. */
7613 case BFD_RELOC_AARCH64_ADD_LO12
:
7614 case BFD_RELOC_AARCH64_ADR_GOT_PAGE
:
7615 case BFD_RELOC_AARCH64_ADR_HI21_PCREL
:
7616 case BFD_RELOC_AARCH64_CALL26
:
7617 case BFD_RELOC_AARCH64_GOT_LD_PREL19
:
7618 case BFD_RELOC_AARCH64_JUMP26
:
7619 case BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14
:
7620 case BFD_RELOC_AARCH64_LD32_GOT_LO12_NC
:
7621 case BFD_RELOC_AARCH64_LD64_GOTOFF_LO15
:
7622 case BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15
:
7623 case BFD_RELOC_AARCH64_LD64_GOT_LO12_NC
:
7624 case BFD_RELOC_AARCH64_MOVW_GOTOFF_G0_NC
:
7625 case BFD_RELOC_AARCH64_MOVW_GOTOFF_G1
:
7626 case BFD_RELOC_AARCH64_NN
:
7627 if (htab
->root
.dynobj
== NULL
)
7628 htab
->root
.dynobj
= abfd
;
7629 if (!_bfd_elf_create_ifunc_sections (htab
->root
.dynobj
, info
))
7634 /* It is referenced by a non-shared object. */
7640 case BFD_RELOC_AARCH64_16
:
7642 case BFD_RELOC_AARCH64_32
:
7644 if (bfd_link_pic (info
) && (sec
->flags
& SEC_ALLOC
) != 0)
7647 /* This is an absolute symbol. It represents a value instead
7649 && (bfd_is_abs_symbol (&h
->root
)
7650 /* This is an undefined symbol. */
7651 || h
->root
.type
== bfd_link_hash_undefined
))
7654 /* For local symbols, defined global symbols in a non-ABS section,
7655 it is assumed that the value is an address. */
7656 int howto_index
= bfd_r_type
- BFD_RELOC_AARCH64_RELOC_START
;
7658 /* xgettext:c-format */
7659 (_("%pB: relocation %s against `%s' can not be used when making "
7661 abfd
, elfNN_aarch64_howto_table
[howto_index
].name
,
7662 (h
) ? h
->root
.root
.string
: "a local symbol");
7663 bfd_set_error (bfd_error_bad_value
);
7669 case BFD_RELOC_AARCH64_MOVW_G0_NC
:
7670 case BFD_RELOC_AARCH64_MOVW_G1_NC
:
7671 case BFD_RELOC_AARCH64_MOVW_G2_NC
:
7672 case BFD_RELOC_AARCH64_MOVW_G3
:
7673 if (bfd_link_pic (info
))
7675 int howto_index
= bfd_r_type
- BFD_RELOC_AARCH64_RELOC_START
;
7677 /* xgettext:c-format */
7678 (_("%pB: relocation %s against `%s' can not be used when making "
7679 "a shared object; recompile with -fPIC"),
7680 abfd
, elfNN_aarch64_howto_table
[howto_index
].name
,
7681 (h
) ? h
->root
.root
.string
: "a local symbol");
7682 bfd_set_error (bfd_error_bad_value
);
7687 case BFD_RELOC_AARCH64_16_PCREL
:
7688 case BFD_RELOC_AARCH64_32_PCREL
:
7689 case BFD_RELOC_AARCH64_64_PCREL
:
7690 case BFD_RELOC_AARCH64_ADD_LO12
:
7691 case BFD_RELOC_AARCH64_ADR_HI21_NC_PCREL
:
7692 case BFD_RELOC_AARCH64_ADR_HI21_PCREL
:
7693 case BFD_RELOC_AARCH64_ADR_LO21_PCREL
:
7694 case BFD_RELOC_AARCH64_LDST128_LO12
:
7695 case BFD_RELOC_AARCH64_LDST16_LO12
:
7696 case BFD_RELOC_AARCH64_LDST32_LO12
:
7697 case BFD_RELOC_AARCH64_LDST64_LO12
:
7698 case BFD_RELOC_AARCH64_LDST8_LO12
:
7699 case BFD_RELOC_AARCH64_LD_LO19_PCREL
:
7700 if (h
== NULL
|| bfd_link_pic (info
))
7704 case BFD_RELOC_AARCH64_NN
:
7706 /* We don't need to handle relocs into sections not going into
7707 the "real" output. */
7708 if ((sec
->flags
& SEC_ALLOC
) == 0)
7713 if (!bfd_link_pic (info
))
7716 h
->plt
.refcount
+= 1;
7717 h
->pointer_equality_needed
= 1;
7720 /* No need to do anything if we're not creating a shared
7722 if (!(bfd_link_pic (info
)
7723 /* If on the other hand, we are creating an executable, we
7724 may need to keep relocations for symbols satisfied by a
7725 dynamic library if we manage to avoid copy relocs for the
7728 NOTE: Currently, there is no support of copy relocs
7729 elimination on pc-relative relocation types, because there is
7730 no dynamic relocation support for them in glibc. We still
7731 record the dynamic symbol reference for them. This is
7732 because one symbol may be referenced by both absolute
7733 relocation (for example, BFD_RELOC_AARCH64_NN) and
7734 pc-relative relocation. We need full symbol reference
7735 information to make correct decision later in
7736 elfNN_aarch64_adjust_dynamic_symbol. */
7737 || (ELIMINATE_COPY_RELOCS
7738 && !bfd_link_pic (info
)
7740 && (h
->root
.type
== bfd_link_hash_defweak
7741 || !h
->def_regular
))))
7745 struct elf_dyn_relocs
*p
;
7746 struct elf_dyn_relocs
**head
;
7747 int howto_index
= bfd_r_type
- BFD_RELOC_AARCH64_RELOC_START
;
7749 /* We must copy these reloc types into the output file.
7750 Create a reloc section in dynobj and make room for
7754 if (htab
->root
.dynobj
== NULL
)
7755 htab
->root
.dynobj
= abfd
;
7757 sreloc
= _bfd_elf_make_dynamic_reloc_section
7758 (sec
, htab
->root
.dynobj
, LOG_FILE_ALIGN
, abfd
, /*rela? */ TRUE
);
7764 /* If this is a global symbol, we count the number of
7765 relocations we need for this symbol. */
7768 struct elf_aarch64_link_hash_entry
*eh
;
7769 eh
= (struct elf_aarch64_link_hash_entry
*) h
;
7770 head
= &eh
->dyn_relocs
;
7774 /* Track dynamic relocs needed for local syms too.
7775 We really need local syms available to do this
7781 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
7786 s
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
7790 /* Beware of type punned pointers vs strict aliasing
7792 vpp
= &(elf_section_data (s
)->local_dynrel
);
7793 head
= (struct elf_dyn_relocs
**) vpp
;
7797 if (p
== NULL
|| p
->sec
!= sec
)
7799 bfd_size_type amt
= sizeof *p
;
7800 p
= ((struct elf_dyn_relocs
*)
7801 bfd_zalloc (htab
->root
.dynobj
, amt
));
7811 if (elfNN_aarch64_howto_table
[howto_index
].pc_relative
)
7816 /* RR: We probably want to keep a consistency check that
7817 there are no dangling GOT_PAGE relocs. */
7818 case BFD_RELOC_AARCH64_ADR_GOT_PAGE
:
7819 case BFD_RELOC_AARCH64_GOT_LD_PREL19
:
7820 case BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14
:
7821 case BFD_RELOC_AARCH64_LD32_GOT_LO12_NC
:
7822 case BFD_RELOC_AARCH64_LD64_GOTOFF_LO15
:
7823 case BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15
:
7824 case BFD_RELOC_AARCH64_LD64_GOT_LO12_NC
:
7825 case BFD_RELOC_AARCH64_MOVW_GOTOFF_G0_NC
:
7826 case BFD_RELOC_AARCH64_MOVW_GOTOFF_G1
:
7827 case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12
:
7828 case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21
:
7829 case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21
:
7830 case BFD_RELOC_AARCH64_TLSDESC_LD32_LO12_NC
:
7831 case BFD_RELOC_AARCH64_TLSDESC_LD64_LO12
:
7832 case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19
:
7833 case BFD_RELOC_AARCH64_TLSDESC_OFF_G0_NC
:
7834 case BFD_RELOC_AARCH64_TLSDESC_OFF_G1
:
7835 case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC
:
7836 case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21
:
7837 case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21
:
7838 case BFD_RELOC_AARCH64_TLSGD_MOVW_G0_NC
:
7839 case BFD_RELOC_AARCH64_TLSGD_MOVW_G1
:
7840 case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21
:
7841 case BFD_RELOC_AARCH64_TLSIE_LD32_GOTTPREL_LO12_NC
:
7842 case BFD_RELOC_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC
:
7843 case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19
:
7844 case BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G0_NC
:
7845 case BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G1
:
7846 case BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC
:
7847 case BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21
:
7848 case BFD_RELOC_AARCH64_TLSLD_ADR_PREL21
:
7851 unsigned old_got_type
;
7853 got_type
= aarch64_reloc_got_type (bfd_r_type
);
7857 h
->got
.refcount
+= 1;
7858 old_got_type
= elf_aarch64_hash_entry (h
)->got_type
;
7862 struct elf_aarch64_local_symbol
*locals
;
7864 if (!elfNN_aarch64_allocate_local_symbols
7865 (abfd
, symtab_hdr
->sh_info
))
7868 locals
= elf_aarch64_locals (abfd
);
7869 BFD_ASSERT (r_symndx
< symtab_hdr
->sh_info
);
7870 locals
[r_symndx
].got_refcount
+= 1;
7871 old_got_type
= locals
[r_symndx
].got_type
;
7874 /* If a variable is accessed with both general dynamic TLS
7875 methods, two slots may be created. */
7876 if (GOT_TLS_GD_ANY_P (old_got_type
) && GOT_TLS_GD_ANY_P (got_type
))
7877 got_type
|= old_got_type
;
7879 /* We will already have issued an error message if there
7880 is a TLS/non-TLS mismatch, based on the symbol type.
7881 So just combine any TLS types needed. */
7882 if (old_got_type
!= GOT_UNKNOWN
&& old_got_type
!= GOT_NORMAL
7883 && got_type
!= GOT_NORMAL
)
7884 got_type
|= old_got_type
;
7886 /* If the symbol is accessed by both IE and GD methods, we
7887 are able to relax. Turn off the GD flag, without
7888 messing up with any other kind of TLS types that may be
7890 if ((got_type
& GOT_TLS_IE
) && GOT_TLS_GD_ANY_P (got_type
))
7891 got_type
&= ~ (GOT_TLSDESC_GD
| GOT_TLS_GD
);
7893 if (old_got_type
!= got_type
)
7896 elf_aarch64_hash_entry (h
)->got_type
= got_type
;
7899 struct elf_aarch64_local_symbol
*locals
;
7900 locals
= elf_aarch64_locals (abfd
);
7901 BFD_ASSERT (r_symndx
< symtab_hdr
->sh_info
);
7902 locals
[r_symndx
].got_type
= got_type
;
7906 if (htab
->root
.dynobj
== NULL
)
7907 htab
->root
.dynobj
= abfd
;
7908 if (! aarch64_elf_create_got_section (htab
->root
.dynobj
, info
))
7913 case BFD_RELOC_AARCH64_CALL26
:
7914 case BFD_RELOC_AARCH64_JUMP26
:
7915 /* If this is a local symbol then we resolve it
7916 directly without creating a PLT entry. */
7921 if (h
->plt
.refcount
<= 0)
7922 h
->plt
.refcount
= 1;
7924 h
->plt
.refcount
+= 1;
7935 /* Treat mapping symbols as special target symbols. */
7938 elfNN_aarch64_is_target_special_symbol (bfd
*abfd ATTRIBUTE_UNUSED
,
7941 return bfd_is_aarch64_special_symbol_name (sym
->name
,
7942 BFD_AARCH64_SPECIAL_SYM_TYPE_ANY
);
7945 /* This is a copy of elf_find_function () from elf.c except that
7946 AArch64 mapping symbols are ignored when looking for function names. */
7949 aarch64_elf_find_function (bfd
*abfd ATTRIBUTE_UNUSED
,
7953 const char **filename_ptr
,
7954 const char **functionname_ptr
)
7956 const char *filename
= NULL
;
7957 asymbol
*func
= NULL
;
7958 bfd_vma low_func
= 0;
7961 for (p
= symbols
; *p
!= NULL
; p
++)
7965 q
= (elf_symbol_type
*) * p
;
7967 switch (ELF_ST_TYPE (q
->internal_elf_sym
.st_info
))
7972 filename
= bfd_asymbol_name (&q
->symbol
);
7976 /* Skip mapping symbols. */
7977 if ((q
->symbol
.flags
& BSF_LOCAL
)
7978 && (bfd_is_aarch64_special_symbol_name
7979 (q
->symbol
.name
, BFD_AARCH64_SPECIAL_SYM_TYPE_ANY
)))
7982 if (bfd_get_section (&q
->symbol
) == section
7983 && q
->symbol
.value
>= low_func
&& q
->symbol
.value
<= offset
)
7985 func
= (asymbol
*) q
;
7986 low_func
= q
->symbol
.value
;
7996 *filename_ptr
= filename
;
7997 if (functionname_ptr
)
7998 *functionname_ptr
= bfd_asymbol_name (func
);
8004 /* Find the nearest line to a particular section and offset, for error
8005 reporting. This code is a duplicate of the code in elf.c, except
8006 that it uses aarch64_elf_find_function. */
8009 elfNN_aarch64_find_nearest_line (bfd
*abfd
,
8013 const char **filename_ptr
,
8014 const char **functionname_ptr
,
8015 unsigned int *line_ptr
,
8016 unsigned int *discriminator_ptr
)
8018 bfd_boolean found
= FALSE
;
8020 if (_bfd_dwarf2_find_nearest_line (abfd
, symbols
, NULL
, section
, offset
,
8021 filename_ptr
, functionname_ptr
,
8022 line_ptr
, discriminator_ptr
,
8023 dwarf_debug_sections
, 0,
8024 &elf_tdata (abfd
)->dwarf2_find_line_info
))
8026 if (!*functionname_ptr
)
8027 aarch64_elf_find_function (abfd
, symbols
, section
, offset
,
8028 *filename_ptr
? NULL
: filename_ptr
,
8034 /* Skip _bfd_dwarf1_find_nearest_line since no known AArch64
8035 toolchain uses DWARF1. */
8037 if (!_bfd_stab_section_find_nearest_line (abfd
, symbols
, section
, offset
,
8038 &found
, filename_ptr
,
8039 functionname_ptr
, line_ptr
,
8040 &elf_tdata (abfd
)->line_info
))
8043 if (found
&& (*functionname_ptr
|| *line_ptr
))
8046 if (symbols
== NULL
)
8049 if (!aarch64_elf_find_function (abfd
, symbols
, section
, offset
,
8050 filename_ptr
, functionname_ptr
))
8058 elfNN_aarch64_find_inliner_info (bfd
*abfd
,
8059 const char **filename_ptr
,
8060 const char **functionname_ptr
,
8061 unsigned int *line_ptr
)
8064 found
= _bfd_dwarf2_find_inliner_info
8065 (abfd
, filename_ptr
,
8066 functionname_ptr
, line_ptr
, &elf_tdata (abfd
)->dwarf2_find_line_info
);
8072 elfNN_aarch64_post_process_headers (bfd
*abfd
,
8073 struct bfd_link_info
*link_info
)
8075 Elf_Internal_Ehdr
*i_ehdrp
; /* ELF file header, internal form. */
8077 i_ehdrp
= elf_elfheader (abfd
);
8078 i_ehdrp
->e_ident
[EI_ABIVERSION
] = AARCH64_ELF_ABI_VERSION
;
8080 _bfd_elf_post_process_headers (abfd
, link_info
);
8083 static enum elf_reloc_type_class
8084 elfNN_aarch64_reloc_type_class (const struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
8085 const asection
*rel_sec ATTRIBUTE_UNUSED
,
8086 const Elf_Internal_Rela
*rela
)
8088 struct elf_aarch64_link_hash_table
*htab
= elf_aarch64_hash_table (info
);
8090 if (htab
->root
.dynsym
!= NULL
8091 && htab
->root
.dynsym
->contents
!= NULL
)
8093 /* Check relocation against STT_GNU_IFUNC symbol if there are
8095 bfd
*abfd
= info
->output_bfd
;
8096 const struct elf_backend_data
*bed
= get_elf_backend_data (abfd
);
8097 unsigned long r_symndx
= ELFNN_R_SYM (rela
->r_info
);
8098 if (r_symndx
!= STN_UNDEF
)
8100 Elf_Internal_Sym sym
;
8101 if (!bed
->s
->swap_symbol_in (abfd
,
8102 (htab
->root
.dynsym
->contents
8103 + r_symndx
* bed
->s
->sizeof_sym
),
8106 /* xgettext:c-format */
8107 _bfd_error_handler (_("%pB symbol number %lu references"
8108 " nonexistent SHT_SYMTAB_SHNDX section"),
8110 /* Ideally an error class should be returned here. */
8112 else if (ELF_ST_TYPE (sym
.st_info
) == STT_GNU_IFUNC
)
8113 return reloc_class_ifunc
;
8117 switch ((int) ELFNN_R_TYPE (rela
->r_info
))
8119 case AARCH64_R (IRELATIVE
):
8120 return reloc_class_ifunc
;
8121 case AARCH64_R (RELATIVE
):
8122 return reloc_class_relative
;
8123 case AARCH64_R (JUMP_SLOT
):
8124 return reloc_class_plt
;
8125 case AARCH64_R (COPY
):
8126 return reloc_class_copy
;
8128 return reloc_class_normal
;
8132 /* Handle an AArch64 specific section when reading an object file. This is
8133 called when bfd_section_from_shdr finds a section with an unknown
8137 elfNN_aarch64_section_from_shdr (bfd
*abfd
,
8138 Elf_Internal_Shdr
*hdr
,
8139 const char *name
, int shindex
)
8141 /* There ought to be a place to keep ELF backend specific flags, but
8142 at the moment there isn't one. We just keep track of the
8143 sections by their name, instead. Fortunately, the ABI gives
8144 names for all the AArch64 specific sections, so we will probably get
8146 switch (hdr
->sh_type
)
8148 case SHT_AARCH64_ATTRIBUTES
:
8155 if (!_bfd_elf_make_section_from_shdr (abfd
, hdr
, name
, shindex
))
8161 /* A structure used to record a list of sections, independently
8162 of the next and prev fields in the asection structure. */
8163 typedef struct section_list
8166 struct section_list
*next
;
8167 struct section_list
*prev
;
8171 /* Unfortunately we need to keep a list of sections for which
8172 an _aarch64_elf_section_data structure has been allocated. This
8173 is because it is possible for functions like elfNN_aarch64_write_section
8174 to be called on a section which has had an elf_data_structure
8175 allocated for it (and so the used_by_bfd field is valid) but
8176 for which the AArch64 extended version of this structure - the
8177 _aarch64_elf_section_data structure - has not been allocated. */
8178 static section_list
*sections_with_aarch64_elf_section_data
= NULL
;
8181 record_section_with_aarch64_elf_section_data (asection
*sec
)
8183 struct section_list
*entry
;
8185 entry
= bfd_malloc (sizeof (*entry
));
8189 entry
->next
= sections_with_aarch64_elf_section_data
;
8191 if (entry
->next
!= NULL
)
8192 entry
->next
->prev
= entry
;
8193 sections_with_aarch64_elf_section_data
= entry
;
8196 static struct section_list
*
8197 find_aarch64_elf_section_entry (asection
*sec
)
8199 struct section_list
*entry
;
8200 static struct section_list
*last_entry
= NULL
;
8202 /* This is a short cut for the typical case where the sections are added
8203 to the sections_with_aarch64_elf_section_data list in forward order and
8204 then looked up here in backwards order. This makes a real difference
8205 to the ld-srec/sec64k.exp linker test. */
8206 entry
= sections_with_aarch64_elf_section_data
;
8207 if (last_entry
!= NULL
)
8209 if (last_entry
->sec
== sec
)
8211 else if (last_entry
->next
!= NULL
&& last_entry
->next
->sec
== sec
)
8212 entry
= last_entry
->next
;
8215 for (; entry
; entry
= entry
->next
)
8216 if (entry
->sec
== sec
)
8220 /* Record the entry prior to this one - it is the entry we are
8221 most likely to want to locate next time. Also this way if we
8222 have been called from
8223 unrecord_section_with_aarch64_elf_section_data () we will not
8224 be caching a pointer that is about to be freed. */
8225 last_entry
= entry
->prev
;
8231 unrecord_section_with_aarch64_elf_section_data (asection
*sec
)
8233 struct section_list
*entry
;
8235 entry
= find_aarch64_elf_section_entry (sec
);
8239 if (entry
->prev
!= NULL
)
8240 entry
->prev
->next
= entry
->next
;
8241 if (entry
->next
!= NULL
)
8242 entry
->next
->prev
= entry
->prev
;
8243 if (entry
== sections_with_aarch64_elf_section_data
)
8244 sections_with_aarch64_elf_section_data
= entry
->next
;
8253 struct bfd_link_info
*info
;
8256 int (*func
) (void *, const char *, Elf_Internal_Sym
*,
8257 asection
*, struct elf_link_hash_entry
*);
8258 } output_arch_syminfo
;
8260 enum map_symbol_type
8267 /* Output a single mapping symbol. */
8270 elfNN_aarch64_output_map_sym (output_arch_syminfo
*osi
,
8271 enum map_symbol_type type
, bfd_vma offset
)
8273 static const char *names
[2] = { "$x", "$d" };
8274 Elf_Internal_Sym sym
;
8276 sym
.st_value
= (osi
->sec
->output_section
->vma
8277 + osi
->sec
->output_offset
+ offset
);
8280 sym
.st_info
= ELF_ST_INFO (STB_LOCAL
, STT_NOTYPE
);
8281 sym
.st_shndx
= osi
->sec_shndx
;
8282 return osi
->func (osi
->finfo
, names
[type
], &sym
, osi
->sec
, NULL
) == 1;
8285 /* Output a single local symbol for a generated stub. */
8288 elfNN_aarch64_output_stub_sym (output_arch_syminfo
*osi
, const char *name
,
8289 bfd_vma offset
, bfd_vma size
)
8291 Elf_Internal_Sym sym
;
8293 sym
.st_value
= (osi
->sec
->output_section
->vma
8294 + osi
->sec
->output_offset
+ offset
);
8297 sym
.st_info
= ELF_ST_INFO (STB_LOCAL
, STT_FUNC
);
8298 sym
.st_shndx
= osi
->sec_shndx
;
8299 return osi
->func (osi
->finfo
, name
, &sym
, osi
->sec
, NULL
) == 1;
8303 aarch64_map_one_stub (struct bfd_hash_entry
*gen_entry
, void *in_arg
)
8305 struct elf_aarch64_stub_hash_entry
*stub_entry
;
8309 output_arch_syminfo
*osi
;
8311 /* Massage our args to the form they really have. */
8312 stub_entry
= (struct elf_aarch64_stub_hash_entry
*) gen_entry
;
8313 osi
= (output_arch_syminfo
*) in_arg
;
8315 stub_sec
= stub_entry
->stub_sec
;
8317 /* Ensure this stub is attached to the current section being
8319 if (stub_sec
!= osi
->sec
)
8322 addr
= (bfd_vma
) stub_entry
->stub_offset
;
8324 stub_name
= stub_entry
->output_name
;
8326 switch (stub_entry
->stub_type
)
8328 case aarch64_stub_adrp_branch
:
8329 if (!elfNN_aarch64_output_stub_sym (osi
, stub_name
, addr
,
8330 sizeof (aarch64_adrp_branch_stub
)))
8332 if (!elfNN_aarch64_output_map_sym (osi
, AARCH64_MAP_INSN
, addr
))
8335 case aarch64_stub_long_branch
:
8336 if (!elfNN_aarch64_output_stub_sym
8337 (osi
, stub_name
, addr
, sizeof (aarch64_long_branch_stub
)))
8339 if (!elfNN_aarch64_output_map_sym (osi
, AARCH64_MAP_INSN
, addr
))
8341 if (!elfNN_aarch64_output_map_sym (osi
, AARCH64_MAP_DATA
, addr
+ 16))
8344 case aarch64_stub_erratum_835769_veneer
:
8345 if (!elfNN_aarch64_output_stub_sym (osi
, stub_name
, addr
,
8346 sizeof (aarch64_erratum_835769_stub
)))
8348 if (!elfNN_aarch64_output_map_sym (osi
, AARCH64_MAP_INSN
, addr
))
8351 case aarch64_stub_erratum_843419_veneer
:
8352 if (!elfNN_aarch64_output_stub_sym (osi
, stub_name
, addr
,
8353 sizeof (aarch64_erratum_843419_stub
)))
8355 if (!elfNN_aarch64_output_map_sym (osi
, AARCH64_MAP_INSN
, addr
))
8358 case aarch64_stub_none
:
8368 /* Output mapping symbols for linker generated sections. */
8371 elfNN_aarch64_output_arch_local_syms (bfd
*output_bfd
,
8372 struct bfd_link_info
*info
,
8374 int (*func
) (void *, const char *,
8377 struct elf_link_hash_entry
8380 output_arch_syminfo osi
;
8381 struct elf_aarch64_link_hash_table
*htab
;
8383 htab
= elf_aarch64_hash_table (info
);
8389 /* Long calls stubs. */
8390 if (htab
->stub_bfd
&& htab
->stub_bfd
->sections
)
8394 for (stub_sec
= htab
->stub_bfd
->sections
;
8395 stub_sec
!= NULL
; stub_sec
= stub_sec
->next
)
8397 /* Ignore non-stub sections. */
8398 if (!strstr (stub_sec
->name
, STUB_SUFFIX
))
8403 osi
.sec_shndx
= _bfd_elf_section_from_bfd_section
8404 (output_bfd
, osi
.sec
->output_section
);
8406 /* The first instruction in a stub is always a branch. */
8407 if (!elfNN_aarch64_output_map_sym (&osi
, AARCH64_MAP_INSN
, 0))
8410 bfd_hash_traverse (&htab
->stub_hash_table
, aarch64_map_one_stub
,
8415 /* Finally, output mapping symbols for the PLT. */
8416 if (!htab
->root
.splt
|| htab
->root
.splt
->size
== 0)
8419 osi
.sec_shndx
= _bfd_elf_section_from_bfd_section
8420 (output_bfd
, htab
->root
.splt
->output_section
);
8421 osi
.sec
= htab
->root
.splt
;
8423 elfNN_aarch64_output_map_sym (&osi
, AARCH64_MAP_INSN
, 0);
8429 /* Allocate target specific section data. */
8432 elfNN_aarch64_new_section_hook (bfd
*abfd
, asection
*sec
)
8434 if (!sec
->used_by_bfd
)
8436 _aarch64_elf_section_data
*sdata
;
8437 bfd_size_type amt
= sizeof (*sdata
);
8439 sdata
= bfd_zalloc (abfd
, amt
);
8442 sec
->used_by_bfd
= sdata
;
8445 record_section_with_aarch64_elf_section_data (sec
);
8447 return _bfd_elf_new_section_hook (abfd
, sec
);
8452 unrecord_section_via_map_over_sections (bfd
*abfd ATTRIBUTE_UNUSED
,
8454 void *ignore ATTRIBUTE_UNUSED
)
8456 unrecord_section_with_aarch64_elf_section_data (sec
);
8460 elfNN_aarch64_close_and_cleanup (bfd
*abfd
)
8463 bfd_map_over_sections (abfd
,
8464 unrecord_section_via_map_over_sections
, NULL
);
8466 return _bfd_elf_close_and_cleanup (abfd
);
8470 elfNN_aarch64_bfd_free_cached_info (bfd
*abfd
)
8473 bfd_map_over_sections (abfd
,
8474 unrecord_section_via_map_over_sections
, NULL
);
8476 return _bfd_free_cached_info (abfd
);
8479 /* Create dynamic sections. This is different from the ARM backend in that
8480 the got, plt, gotplt and their relocation sections are all created in the
8481 standard part of the bfd elf backend. */
8484 elfNN_aarch64_create_dynamic_sections (bfd
*dynobj
,
8485 struct bfd_link_info
*info
)
8487 /* We need to create .got section. */
8488 if (!aarch64_elf_create_got_section (dynobj
, info
))
8491 return _bfd_elf_create_dynamic_sections (dynobj
, info
);
8495 /* Allocate space in .plt, .got and associated reloc sections for
8499 elfNN_aarch64_allocate_dynrelocs (struct elf_link_hash_entry
*h
, void *inf
)
8501 struct bfd_link_info
*info
;
8502 struct elf_aarch64_link_hash_table
*htab
;
8503 struct elf_aarch64_link_hash_entry
*eh
;
8504 struct elf_dyn_relocs
*p
;
8506 /* An example of a bfd_link_hash_indirect symbol is versioned
8507 symbol. For example: __gxx_personality_v0(bfd_link_hash_indirect)
8508 -> __gxx_personality_v0(bfd_link_hash_defined)
8510 There is no need to process bfd_link_hash_indirect symbols here
8511 because we will also be presented with the concrete instance of
8512 the symbol and elfNN_aarch64_copy_indirect_symbol () will have been
8513 called to copy all relevant data from the generic to the concrete
8515 if (h
->root
.type
== bfd_link_hash_indirect
)
8518 if (h
->root
.type
== bfd_link_hash_warning
)
8519 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
8521 info
= (struct bfd_link_info
*) inf
;
8522 htab
= elf_aarch64_hash_table (info
);
8524 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle it
8525 here if it is defined and referenced in a non-shared object. */
8526 if (h
->type
== STT_GNU_IFUNC
8529 else if (htab
->root
.dynamic_sections_created
&& h
->plt
.refcount
> 0)
8531 /* Make sure this symbol is output as a dynamic symbol.
8532 Undefined weak syms won't yet be marked as dynamic. */
8533 if (h
->dynindx
== -1 && !h
->forced_local
8534 && h
->root
.type
== bfd_link_hash_undefweak
)
8536 if (!bfd_elf_link_record_dynamic_symbol (info
, h
))
8540 if (bfd_link_pic (info
) || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h
))
8542 asection
*s
= htab
->root
.splt
;
8544 /* If this is the first .plt entry, make room for the special
8547 s
->size
+= htab
->plt_header_size
;
8549 h
->plt
.offset
= s
->size
;
8551 /* If this symbol is not defined in a regular file, and we are
8552 not generating a shared library, then set the symbol to this
8553 location in the .plt. This is required to make function
8554 pointers compare as equal between the normal executable and
8555 the shared library. */
8556 if (!bfd_link_pic (info
) && !h
->def_regular
)
8558 h
->root
.u
.def
.section
= s
;
8559 h
->root
.u
.def
.value
= h
->plt
.offset
;
8562 /* Make room for this entry. For now we only create the
8563 small model PLT entries. We later need to find a way
8564 of relaxing into these from the large model PLT entries. */
8565 s
->size
+= htab
->plt_entry_size
;
8567 /* We also need to make an entry in the .got.plt section, which
8568 will be placed in the .got section by the linker script. */
8569 htab
->root
.sgotplt
->size
+= GOT_ENTRY_SIZE
;
8571 /* We also need to make an entry in the .rela.plt section. */
8572 htab
->root
.srelplt
->size
+= RELOC_SIZE (htab
);
8574 /* We need to ensure that all GOT entries that serve the PLT
8575 are consecutive with the special GOT slots [0] [1] and
8576 [2]. Any addtional relocations, such as
8577 R_AARCH64_TLSDESC, must be placed after the PLT related
8578 entries. We abuse the reloc_count such that during
8579 sizing we adjust reloc_count to indicate the number of
8580 PLT related reserved entries. In subsequent phases when
8581 filling in the contents of the reloc entries, PLT related
8582 entries are placed by computing their PLT index (0
8583 .. reloc_count). While other none PLT relocs are placed
8584 at the slot indicated by reloc_count and reloc_count is
8587 htab
->root
.srelplt
->reloc_count
++;
8591 h
->plt
.offset
= (bfd_vma
) - 1;
8597 h
->plt
.offset
= (bfd_vma
) - 1;
8601 eh
= (struct elf_aarch64_link_hash_entry
*) h
;
8602 eh
->tlsdesc_got_jump_table_offset
= (bfd_vma
) - 1;
8604 if (h
->got
.refcount
> 0)
8607 unsigned got_type
= elf_aarch64_hash_entry (h
)->got_type
;
8609 h
->got
.offset
= (bfd_vma
) - 1;
8611 dyn
= htab
->root
.dynamic_sections_created
;
8613 /* Make sure this symbol is output as a dynamic symbol.
8614 Undefined weak syms won't yet be marked as dynamic. */
8615 if (dyn
&& h
->dynindx
== -1 && !h
->forced_local
8616 && h
->root
.type
== bfd_link_hash_undefweak
)
8618 if (!bfd_elf_link_record_dynamic_symbol (info
, h
))
8622 if (got_type
== GOT_UNKNOWN
)
8625 else if (got_type
== GOT_NORMAL
)
8627 h
->got
.offset
= htab
->root
.sgot
->size
;
8628 htab
->root
.sgot
->size
+= GOT_ENTRY_SIZE
;
8629 if ((ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
8630 || h
->root
.type
!= bfd_link_hash_undefweak
)
8631 && (bfd_link_pic (info
)
8632 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, 0, h
))
8633 /* Undefined weak symbol in static PIE resolves to 0 without
8634 any dynamic relocations. */
8635 && !UNDEFWEAK_NO_DYNAMIC_RELOC (info
, h
))
8637 htab
->root
.srelgot
->size
+= RELOC_SIZE (htab
);
8643 if (got_type
& GOT_TLSDESC_GD
)
8645 eh
->tlsdesc_got_jump_table_offset
=
8646 (htab
->root
.sgotplt
->size
8647 - aarch64_compute_jump_table_size (htab
));
8648 htab
->root
.sgotplt
->size
+= GOT_ENTRY_SIZE
* 2;
8649 h
->got
.offset
= (bfd_vma
) - 2;
8652 if (got_type
& GOT_TLS_GD
)
8654 h
->got
.offset
= htab
->root
.sgot
->size
;
8655 htab
->root
.sgot
->size
+= GOT_ENTRY_SIZE
* 2;
8658 if (got_type
& GOT_TLS_IE
)
8660 h
->got
.offset
= htab
->root
.sgot
->size
;
8661 htab
->root
.sgot
->size
+= GOT_ENTRY_SIZE
;
8664 indx
= h
&& h
->dynindx
!= -1 ? h
->dynindx
: 0;
8665 if ((ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
8666 || h
->root
.type
!= bfd_link_hash_undefweak
)
8667 && (!bfd_link_executable (info
)
8669 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, 0, h
)))
8671 if (got_type
& GOT_TLSDESC_GD
)
8673 htab
->root
.srelplt
->size
+= RELOC_SIZE (htab
);
8674 /* Note reloc_count not incremented here! We have
8675 already adjusted reloc_count for this relocation
8678 /* TLSDESC PLT is now needed, but not yet determined. */
8679 htab
->tlsdesc_plt
= (bfd_vma
) - 1;
8682 if (got_type
& GOT_TLS_GD
)
8683 htab
->root
.srelgot
->size
+= RELOC_SIZE (htab
) * 2;
8685 if (got_type
& GOT_TLS_IE
)
8686 htab
->root
.srelgot
->size
+= RELOC_SIZE (htab
);
8692 h
->got
.offset
= (bfd_vma
) - 1;
8695 if (eh
->dyn_relocs
== NULL
)
8698 /* In the shared -Bsymbolic case, discard space allocated for
8699 dynamic pc-relative relocs against symbols which turn out to be
8700 defined in regular objects. For the normal shared case, discard
8701 space for pc-relative relocs that have become local due to symbol
8702 visibility changes. */
8704 if (bfd_link_pic (info
))
8706 /* Relocs that use pc_count are those that appear on a call
8707 insn, or certain REL relocs that can generated via assembly.
8708 We want calls to protected symbols to resolve directly to the
8709 function rather than going via the plt. If people want
8710 function pointer comparisons to work as expected then they
8711 should avoid writing weird assembly. */
8712 if (SYMBOL_CALLS_LOCAL (info
, h
))
8714 struct elf_dyn_relocs
**pp
;
8716 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
;)
8718 p
->count
-= p
->pc_count
;
8727 /* Also discard relocs on undefined weak syms with non-default
8729 if (eh
->dyn_relocs
!= NULL
&& h
->root
.type
== bfd_link_hash_undefweak
)
8731 if (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
8732 || UNDEFWEAK_NO_DYNAMIC_RELOC (info
, h
))
8733 eh
->dyn_relocs
= NULL
;
8735 /* Make sure undefined weak symbols are output as a dynamic
8737 else if (h
->dynindx
== -1
8739 && h
->root
.type
== bfd_link_hash_undefweak
8740 && !bfd_elf_link_record_dynamic_symbol (info
, h
))
8745 else if (ELIMINATE_COPY_RELOCS
)
8747 /* For the non-shared case, discard space for relocs against
8748 symbols which turn out to need copy relocs or are not
8754 || (htab
->root
.dynamic_sections_created
8755 && (h
->root
.type
== bfd_link_hash_undefweak
8756 || h
->root
.type
== bfd_link_hash_undefined
))))
8758 /* Make sure this symbol is output as a dynamic symbol.
8759 Undefined weak syms won't yet be marked as dynamic. */
8760 if (h
->dynindx
== -1
8762 && h
->root
.type
== bfd_link_hash_undefweak
8763 && !bfd_elf_link_record_dynamic_symbol (info
, h
))
8766 /* If that succeeded, we know we'll be keeping all the
8768 if (h
->dynindx
!= -1)
8772 eh
->dyn_relocs
= NULL
;
8777 /* Finally, allocate space. */
8778 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
8782 sreloc
= elf_section_data (p
->sec
)->sreloc
;
8784 BFD_ASSERT (sreloc
!= NULL
);
8786 sreloc
->size
+= p
->count
* RELOC_SIZE (htab
);
8792 /* Allocate space in .plt, .got and associated reloc sections for
8793 ifunc dynamic relocs. */
8796 elfNN_aarch64_allocate_ifunc_dynrelocs (struct elf_link_hash_entry
*h
,
8799 struct bfd_link_info
*info
;
8800 struct elf_aarch64_link_hash_table
*htab
;
8801 struct elf_aarch64_link_hash_entry
*eh
;
8803 /* An example of a bfd_link_hash_indirect symbol is versioned
8804 symbol. For example: __gxx_personality_v0(bfd_link_hash_indirect)
8805 -> __gxx_personality_v0(bfd_link_hash_defined)
8807 There is no need to process bfd_link_hash_indirect symbols here
8808 because we will also be presented with the concrete instance of
8809 the symbol and elfNN_aarch64_copy_indirect_symbol () will have been
8810 called to copy all relevant data from the generic to the concrete
8812 if (h
->root
.type
== bfd_link_hash_indirect
)
8815 if (h
->root
.type
== bfd_link_hash_warning
)
8816 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
8818 info
= (struct bfd_link_info
*) inf
;
8819 htab
= elf_aarch64_hash_table (info
);
8821 eh
= (struct elf_aarch64_link_hash_entry
*) h
;
8823 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle it
8824 here if it is defined and referenced in a non-shared object. */
8825 if (h
->type
== STT_GNU_IFUNC
8827 return _bfd_elf_allocate_ifunc_dyn_relocs (info
, h
,
8830 htab
->plt_entry_size
,
8831 htab
->plt_header_size
,
8837 /* Allocate space in .plt, .got and associated reloc sections for
8838 local dynamic relocs. */
8841 elfNN_aarch64_allocate_local_dynrelocs (void **slot
, void *inf
)
8843 struct elf_link_hash_entry
*h
8844 = (struct elf_link_hash_entry
*) *slot
;
8846 if (h
->type
!= STT_GNU_IFUNC
8850 || h
->root
.type
!= bfd_link_hash_defined
)
8853 return elfNN_aarch64_allocate_dynrelocs (h
, inf
);
8856 /* Allocate space in .plt, .got and associated reloc sections for
8857 local ifunc dynamic relocs. */
8860 elfNN_aarch64_allocate_local_ifunc_dynrelocs (void **slot
, void *inf
)
8862 struct elf_link_hash_entry
*h
8863 = (struct elf_link_hash_entry
*) *slot
;
8865 if (h
->type
!= STT_GNU_IFUNC
8869 || h
->root
.type
!= bfd_link_hash_defined
)
8872 return elfNN_aarch64_allocate_ifunc_dynrelocs (h
, inf
);
8875 /* Set DF_TEXTREL if we find any dynamic relocs that apply to
8876 read-only sections. */
8879 maybe_set_textrel (struct elf_link_hash_entry
*h
, void *info_p
)
8883 if (h
->root
.type
== bfd_link_hash_indirect
)
8886 sec
= readonly_dynrelocs (h
);
8889 struct bfd_link_info
*info
= (struct bfd_link_info
*) info_p
;
8891 info
->flags
|= DF_TEXTREL
;
8892 info
->callbacks
->minfo
8893 (_("%pB: dynamic relocation against `%pT' in read-only section `%pA'\n"),
8894 sec
->owner
, h
->root
.root
.string
, sec
);
8896 /* Not an error, just cut short the traversal. */
8902 /* This is the most important function of all . Innocuosly named
8906 elfNN_aarch64_size_dynamic_sections (bfd
*output_bfd ATTRIBUTE_UNUSED
,
8907 struct bfd_link_info
*info
)
8909 struct elf_aarch64_link_hash_table
*htab
;
8915 htab
= elf_aarch64_hash_table ((info
));
8916 dynobj
= htab
->root
.dynobj
;
8918 BFD_ASSERT (dynobj
!= NULL
);
8920 if (htab
->root
.dynamic_sections_created
)
8922 if (bfd_link_executable (info
) && !info
->nointerp
)
8924 s
= bfd_get_linker_section (dynobj
, ".interp");
8927 s
->size
= sizeof ELF_DYNAMIC_INTERPRETER
;
8928 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
8932 /* Set up .got offsets for local syms, and space for local dynamic
8934 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
8936 struct elf_aarch64_local_symbol
*locals
= NULL
;
8937 Elf_Internal_Shdr
*symtab_hdr
;
8941 if (!is_aarch64_elf (ibfd
))
8944 for (s
= ibfd
->sections
; s
!= NULL
; s
= s
->next
)
8946 struct elf_dyn_relocs
*p
;
8948 for (p
= (struct elf_dyn_relocs
*)
8949 (elf_section_data (s
)->local_dynrel
); p
!= NULL
; p
= p
->next
)
8951 if (!bfd_is_abs_section (p
->sec
)
8952 && bfd_is_abs_section (p
->sec
->output_section
))
8954 /* Input section has been discarded, either because
8955 it is a copy of a linkonce section or due to
8956 linker script /DISCARD/, so we'll be discarding
8959 else if (p
->count
!= 0)
8961 srel
= elf_section_data (p
->sec
)->sreloc
;
8962 srel
->size
+= p
->count
* RELOC_SIZE (htab
);
8963 if ((p
->sec
->output_section
->flags
& SEC_READONLY
) != 0)
8964 info
->flags
|= DF_TEXTREL
;
8969 locals
= elf_aarch64_locals (ibfd
);
8973 symtab_hdr
= &elf_symtab_hdr (ibfd
);
8974 srel
= htab
->root
.srelgot
;
8975 for (i
= 0; i
< symtab_hdr
->sh_info
; i
++)
8977 locals
[i
].got_offset
= (bfd_vma
) - 1;
8978 locals
[i
].tlsdesc_got_jump_table_offset
= (bfd_vma
) - 1;
8979 if (locals
[i
].got_refcount
> 0)
8981 unsigned got_type
= locals
[i
].got_type
;
8982 if (got_type
& GOT_TLSDESC_GD
)
8984 locals
[i
].tlsdesc_got_jump_table_offset
=
8985 (htab
->root
.sgotplt
->size
8986 - aarch64_compute_jump_table_size (htab
));
8987 htab
->root
.sgotplt
->size
+= GOT_ENTRY_SIZE
* 2;
8988 locals
[i
].got_offset
= (bfd_vma
) - 2;
8991 if (got_type
& GOT_TLS_GD
)
8993 locals
[i
].got_offset
= htab
->root
.sgot
->size
;
8994 htab
->root
.sgot
->size
+= GOT_ENTRY_SIZE
* 2;
8997 if (got_type
& GOT_TLS_IE
8998 || got_type
& GOT_NORMAL
)
9000 locals
[i
].got_offset
= htab
->root
.sgot
->size
;
9001 htab
->root
.sgot
->size
+= GOT_ENTRY_SIZE
;
9004 if (got_type
== GOT_UNKNOWN
)
9008 if (bfd_link_pic (info
))
9010 if (got_type
& GOT_TLSDESC_GD
)
9012 htab
->root
.srelplt
->size
+= RELOC_SIZE (htab
);
9013 /* Note RELOC_COUNT not incremented here! */
9014 htab
->tlsdesc_plt
= (bfd_vma
) - 1;
9017 if (got_type
& GOT_TLS_GD
)
9018 htab
->root
.srelgot
->size
+= RELOC_SIZE (htab
) * 2;
9020 if (got_type
& GOT_TLS_IE
9021 || got_type
& GOT_NORMAL
)
9022 htab
->root
.srelgot
->size
+= RELOC_SIZE (htab
);
9027 locals
[i
].got_refcount
= (bfd_vma
) - 1;
9033 /* Allocate global sym .plt and .got entries, and space for global
9034 sym dynamic relocs. */
9035 elf_link_hash_traverse (&htab
->root
, elfNN_aarch64_allocate_dynrelocs
,
9038 /* Allocate global ifunc sym .plt and .got entries, and space for global
9039 ifunc sym dynamic relocs. */
9040 elf_link_hash_traverse (&htab
->root
, elfNN_aarch64_allocate_ifunc_dynrelocs
,
9043 /* Allocate .plt and .got entries, and space for local symbols. */
9044 htab_traverse (htab
->loc_hash_table
,
9045 elfNN_aarch64_allocate_local_dynrelocs
,
9048 /* Allocate .plt and .got entries, and space for local ifunc symbols. */
9049 htab_traverse (htab
->loc_hash_table
,
9050 elfNN_aarch64_allocate_local_ifunc_dynrelocs
,
9053 /* For every jump slot reserved in the sgotplt, reloc_count is
9054 incremented. However, when we reserve space for TLS descriptors,
9055 it's not incremented, so in order to compute the space reserved
9056 for them, it suffices to multiply the reloc count by the jump
9059 if (htab
->root
.srelplt
)
9060 htab
->sgotplt_jump_table_size
= aarch64_compute_jump_table_size (htab
);
9062 if (htab
->tlsdesc_plt
)
9064 if (htab
->root
.splt
->size
== 0)
9065 htab
->root
.splt
->size
+= htab
->plt_header_size
;
9067 htab
->tlsdesc_plt
= htab
->root
.splt
->size
;
9068 htab
->root
.splt
->size
+= htab
->tlsdesc_plt_entry_size
;
9070 /* If we're not using lazy TLS relocations, don't generate the
9071 GOT entry required. */
9072 if (!(info
->flags
& DF_BIND_NOW
))
9074 htab
->dt_tlsdesc_got
= htab
->root
.sgot
->size
;
9075 htab
->root
.sgot
->size
+= GOT_ENTRY_SIZE
;
9079 /* Init mapping symbols information to use later to distingush between
9080 code and data while scanning for errata. */
9081 if (htab
->fix_erratum_835769
|| htab
->fix_erratum_843419
)
9082 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
9084 if (!is_aarch64_elf (ibfd
))
9086 bfd_elfNN_aarch64_init_maps (ibfd
);
9089 /* We now have determined the sizes of the various dynamic sections.
9090 Allocate memory for them. */
9092 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
9094 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
9097 if (s
== htab
->root
.splt
9098 || s
== htab
->root
.sgot
9099 || s
== htab
->root
.sgotplt
9100 || s
== htab
->root
.iplt
9101 || s
== htab
->root
.igotplt
9102 || s
== htab
->root
.sdynbss
9103 || s
== htab
->root
.sdynrelro
)
9105 /* Strip this section if we don't need it; see the
9108 else if (CONST_STRNEQ (bfd_get_section_name (dynobj
, s
), ".rela"))
9110 if (s
->size
!= 0 && s
!= htab
->root
.srelplt
)
9113 /* We use the reloc_count field as a counter if we need
9114 to copy relocs into the output file. */
9115 if (s
!= htab
->root
.srelplt
)
9120 /* It's not one of our sections, so don't allocate space. */
9126 /* If we don't need this section, strip it from the
9127 output file. This is mostly to handle .rela.bss and
9128 .rela.plt. We must create both sections in
9129 create_dynamic_sections, because they must be created
9130 before the linker maps input sections to output
9131 sections. The linker does that before
9132 adjust_dynamic_symbol is called, and it is that
9133 function which decides whether anything needs to go
9134 into these sections. */
9135 s
->flags
|= SEC_EXCLUDE
;
9139 if ((s
->flags
& SEC_HAS_CONTENTS
) == 0)
9142 /* Allocate memory for the section contents. We use bfd_zalloc
9143 here in case unused entries are not reclaimed before the
9144 section's contents are written out. This should not happen,
9145 but this way if it does, we get a R_AARCH64_NONE reloc instead
9147 s
->contents
= (bfd_byte
*) bfd_zalloc (dynobj
, s
->size
);
9148 if (s
->contents
== NULL
)
9152 if (htab
->root
.dynamic_sections_created
)
9154 /* Add some entries to the .dynamic section. We fill in the
9155 values later, in elfNN_aarch64_finish_dynamic_sections, but we
9156 must add the entries now so that we get the correct size for
9157 the .dynamic section. The DT_DEBUG entry is filled in by the
9158 dynamic linker and used by the debugger. */
9159 #define add_dynamic_entry(TAG, VAL) \
9160 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
9162 if (bfd_link_executable (info
))
9164 if (!add_dynamic_entry (DT_DEBUG
, 0))
9168 if (htab
->root
.splt
->size
!= 0)
9170 if (!add_dynamic_entry (DT_PLTGOT
, 0)
9171 || !add_dynamic_entry (DT_PLTRELSZ
, 0)
9172 || !add_dynamic_entry (DT_PLTREL
, DT_RELA
)
9173 || !add_dynamic_entry (DT_JMPREL
, 0))
9176 if (htab
->tlsdesc_plt
9177 && (!add_dynamic_entry (DT_TLSDESC_PLT
, 0)
9178 || !add_dynamic_entry (DT_TLSDESC_GOT
, 0)))
9181 if ((elf_aarch64_tdata (output_bfd
)->plt_type
== PLT_BTI_PAC
)
9182 && (!add_dynamic_entry (DT_AARCH64_BTI_PLT
, 0)
9183 || !add_dynamic_entry (DT_AARCH64_PAC_PLT
, 0)))
9186 else if ((elf_aarch64_tdata (output_bfd
)->plt_type
== PLT_BTI
)
9187 && !add_dynamic_entry (DT_AARCH64_BTI_PLT
, 0))
9190 else if ((elf_aarch64_tdata (output_bfd
)->plt_type
== PLT_PAC
)
9191 && !add_dynamic_entry (DT_AARCH64_PAC_PLT
, 0))
9197 if (!add_dynamic_entry (DT_RELA
, 0)
9198 || !add_dynamic_entry (DT_RELASZ
, 0)
9199 || !add_dynamic_entry (DT_RELAENT
, RELOC_SIZE (htab
)))
9202 /* If any dynamic relocs apply to a read-only section,
9203 then we need a DT_TEXTREL entry. */
9204 if ((info
->flags
& DF_TEXTREL
) == 0)
9205 elf_link_hash_traverse (&htab
->root
, maybe_set_textrel
, info
);
9207 if ((info
->flags
& DF_TEXTREL
) != 0)
9209 if (!add_dynamic_entry (DT_TEXTREL
, 0))
9214 #undef add_dynamic_entry
9220 elf_aarch64_update_plt_entry (bfd
*output_bfd
,
9221 bfd_reloc_code_real_type r_type
,
9222 bfd_byte
*plt_entry
, bfd_vma value
)
9224 reloc_howto_type
*howto
= elfNN_aarch64_howto_from_bfd_reloc (r_type
);
9226 /* FIXME: We should check the return value from this function call. */
9227 (void) _bfd_aarch64_elf_put_addend (output_bfd
, plt_entry
, r_type
, howto
, value
);
9231 elfNN_aarch64_create_small_pltn_entry (struct elf_link_hash_entry
*h
,
9232 struct elf_aarch64_link_hash_table
9233 *htab
, bfd
*output_bfd
,
9234 struct bfd_link_info
*info
)
9236 bfd_byte
*plt_entry
;
9239 bfd_vma gotplt_entry_address
;
9240 bfd_vma plt_entry_address
;
9241 Elf_Internal_Rela rela
;
9243 asection
*plt
, *gotplt
, *relplt
;
9245 /* When building a static executable, use .iplt, .igot.plt and
9246 .rela.iplt sections for STT_GNU_IFUNC symbols. */
9247 if (htab
->root
.splt
!= NULL
)
9249 plt
= htab
->root
.splt
;
9250 gotplt
= htab
->root
.sgotplt
;
9251 relplt
= htab
->root
.srelplt
;
9255 plt
= htab
->root
.iplt
;
9256 gotplt
= htab
->root
.igotplt
;
9257 relplt
= htab
->root
.irelplt
;
9260 /* Get the index in the procedure linkage table which
9261 corresponds to this symbol. This is the index of this symbol
9262 in all the symbols for which we are making plt entries. The
9263 first entry in the procedure linkage table is reserved.
9265 Get the offset into the .got table of the entry that
9266 corresponds to this function. Each .got entry is GOT_ENTRY_SIZE
9267 bytes. The first three are reserved for the dynamic linker.
9269 For static executables, we don't reserve anything. */
9271 if (plt
== htab
->root
.splt
)
9273 plt_index
= (h
->plt
.offset
- htab
->plt_header_size
) / htab
->plt_entry_size
;
9274 got_offset
= (plt_index
+ 3) * GOT_ENTRY_SIZE
;
9278 plt_index
= h
->plt
.offset
/ htab
->plt_entry_size
;
9279 got_offset
= plt_index
* GOT_ENTRY_SIZE
;
9282 plt_entry
= plt
->contents
+ h
->plt
.offset
;
9283 plt_entry_address
= plt
->output_section
->vma
9284 + plt
->output_offset
+ h
->plt
.offset
;
9285 gotplt_entry_address
= gotplt
->output_section
->vma
+
9286 gotplt
->output_offset
+ got_offset
;
9288 /* Copy in the boiler-plate for the PLTn entry. */
9289 memcpy (plt_entry
, htab
->plt_entry
, htab
->plt_entry_size
);
9291 /* First instruction in BTI enabled PLT stub is a BTI
9292 instruction so skip it. */
9293 if (elf_aarch64_tdata (output_bfd
)->plt_type
& PLT_BTI
9294 && elf_elfheader (output_bfd
)->e_type
== ET_EXEC
)
9295 plt_entry
= plt_entry
+ 4;
9297 /* Fill in the top 21 bits for this: ADRP x16, PLT_GOT + n * 8.
9298 ADRP: ((PG(S+A)-PG(P)) >> 12) & 0x1fffff */
9299 elf_aarch64_update_plt_entry (output_bfd
, BFD_RELOC_AARCH64_ADR_HI21_PCREL
,
9301 PG (gotplt_entry_address
) -
9302 PG (plt_entry_address
));
9304 /* Fill in the lo12 bits for the load from the pltgot. */
9305 elf_aarch64_update_plt_entry (output_bfd
, BFD_RELOC_AARCH64_LDSTNN_LO12
,
9307 PG_OFFSET (gotplt_entry_address
));
9309 /* Fill in the lo12 bits for the add from the pltgot entry. */
9310 elf_aarch64_update_plt_entry (output_bfd
, BFD_RELOC_AARCH64_ADD_LO12
,
9312 PG_OFFSET (gotplt_entry_address
));
9314 /* All the GOTPLT Entries are essentially initialized to PLT0. */
9315 bfd_put_NN (output_bfd
,
9316 plt
->output_section
->vma
+ plt
->output_offset
,
9317 gotplt
->contents
+ got_offset
);
9319 rela
.r_offset
= gotplt_entry_address
;
9321 if (h
->dynindx
== -1
9322 || ((bfd_link_executable (info
)
9323 || ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
)
9325 && h
->type
== STT_GNU_IFUNC
))
9327 /* If an STT_GNU_IFUNC symbol is locally defined, generate
9328 R_AARCH64_IRELATIVE instead of R_AARCH64_JUMP_SLOT. */
9329 rela
.r_info
= ELFNN_R_INFO (0, AARCH64_R (IRELATIVE
));
9330 rela
.r_addend
= (h
->root
.u
.def
.value
9331 + h
->root
.u
.def
.section
->output_section
->vma
9332 + h
->root
.u
.def
.section
->output_offset
);
9336 /* Fill in the entry in the .rela.plt section. */
9337 rela
.r_info
= ELFNN_R_INFO (h
->dynindx
, AARCH64_R (JUMP_SLOT
));
9341 /* Compute the relocation entry to used based on PLT index and do
9342 not adjust reloc_count. The reloc_count has already been adjusted
9343 to account for this entry. */
9344 loc
= relplt
->contents
+ plt_index
* RELOC_SIZE (htab
);
9345 bfd_elfNN_swap_reloca_out (output_bfd
, &rela
, loc
);
9348 /* Size sections even though they're not dynamic. We use it to setup
9349 _TLS_MODULE_BASE_, if needed. */
9352 elfNN_aarch64_always_size_sections (bfd
*output_bfd
,
9353 struct bfd_link_info
*info
)
9357 if (bfd_link_relocatable (info
))
9360 tls_sec
= elf_hash_table (info
)->tls_sec
;
9364 struct elf_link_hash_entry
*tlsbase
;
9366 tlsbase
= elf_link_hash_lookup (elf_hash_table (info
),
9367 "_TLS_MODULE_BASE_", TRUE
, TRUE
, FALSE
);
9371 struct bfd_link_hash_entry
*h
= NULL
;
9372 const struct elf_backend_data
*bed
=
9373 get_elf_backend_data (output_bfd
);
9375 if (!(_bfd_generic_link_add_one_symbol
9376 (info
, output_bfd
, "_TLS_MODULE_BASE_", BSF_LOCAL
,
9377 tls_sec
, 0, NULL
, FALSE
, bed
->collect
, &h
)))
9380 tlsbase
->type
= STT_TLS
;
9381 tlsbase
= (struct elf_link_hash_entry
*) h
;
9382 tlsbase
->def_regular
= 1;
9383 tlsbase
->other
= STV_HIDDEN
;
9384 (*bed
->elf_backend_hide_symbol
) (info
, tlsbase
, TRUE
);
9391 /* Finish up dynamic symbol handling. We set the contents of various
9392 dynamic sections here. */
9395 elfNN_aarch64_finish_dynamic_symbol (bfd
*output_bfd
,
9396 struct bfd_link_info
*info
,
9397 struct elf_link_hash_entry
*h
,
9398 Elf_Internal_Sym
*sym
)
9400 struct elf_aarch64_link_hash_table
*htab
;
9401 htab
= elf_aarch64_hash_table (info
);
9403 if (h
->plt
.offset
!= (bfd_vma
) - 1)
9405 asection
*plt
, *gotplt
, *relplt
;
9407 /* This symbol has an entry in the procedure linkage table. Set
9410 /* When building a static executable, use .iplt, .igot.plt and
9411 .rela.iplt sections for STT_GNU_IFUNC symbols. */
9412 if (htab
->root
.splt
!= NULL
)
9414 plt
= htab
->root
.splt
;
9415 gotplt
= htab
->root
.sgotplt
;
9416 relplt
= htab
->root
.srelplt
;
9420 plt
= htab
->root
.iplt
;
9421 gotplt
= htab
->root
.igotplt
;
9422 relplt
= htab
->root
.irelplt
;
9425 /* This symbol has an entry in the procedure linkage table. Set
9427 if ((h
->dynindx
== -1
9428 && !((h
->forced_local
|| bfd_link_executable (info
))
9430 && h
->type
== STT_GNU_IFUNC
))
9436 elfNN_aarch64_create_small_pltn_entry (h
, htab
, output_bfd
, info
);
9437 if (!h
->def_regular
)
9439 /* Mark the symbol as undefined, rather than as defined in
9440 the .plt section. */
9441 sym
->st_shndx
= SHN_UNDEF
;
9442 /* If the symbol is weak we need to clear the value.
9443 Otherwise, the PLT entry would provide a definition for
9444 the symbol even if the symbol wasn't defined anywhere,
9445 and so the symbol would never be NULL. Leave the value if
9446 there were any relocations where pointer equality matters
9447 (this is a clue for the dynamic linker, to make function
9448 pointer comparisons work between an application and shared
9450 if (!h
->ref_regular_nonweak
|| !h
->pointer_equality_needed
)
9455 if (h
->got
.offset
!= (bfd_vma
) - 1
9456 && elf_aarch64_hash_entry (h
)->got_type
== GOT_NORMAL
9457 /* Undefined weak symbol in static PIE resolves to 0 without
9458 any dynamic relocations. */
9459 && !UNDEFWEAK_NO_DYNAMIC_RELOC (info
, h
))
9461 Elf_Internal_Rela rela
;
9464 /* This symbol has an entry in the global offset table. Set it
9466 if (htab
->root
.sgot
== NULL
|| htab
->root
.srelgot
== NULL
)
9469 rela
.r_offset
= (htab
->root
.sgot
->output_section
->vma
9470 + htab
->root
.sgot
->output_offset
9471 + (h
->got
.offset
& ~(bfd_vma
) 1));
9474 && h
->type
== STT_GNU_IFUNC
)
9476 if (bfd_link_pic (info
))
9478 /* Generate R_AARCH64_GLOB_DAT. */
9485 if (!h
->pointer_equality_needed
)
9488 /* For non-shared object, we can't use .got.plt, which
9489 contains the real function address if we need pointer
9490 equality. We load the GOT entry with the PLT entry. */
9491 plt
= htab
->root
.splt
? htab
->root
.splt
: htab
->root
.iplt
;
9492 bfd_put_NN (output_bfd
, (plt
->output_section
->vma
9493 + plt
->output_offset
9495 htab
->root
.sgot
->contents
9496 + (h
->got
.offset
& ~(bfd_vma
) 1));
9500 else if (bfd_link_pic (info
) && SYMBOL_REFERENCES_LOCAL (info
, h
))
9502 if (!(h
->def_regular
|| ELF_COMMON_DEF_P (h
)))
9505 BFD_ASSERT ((h
->got
.offset
& 1) != 0);
9506 rela
.r_info
= ELFNN_R_INFO (0, AARCH64_R (RELATIVE
));
9507 rela
.r_addend
= (h
->root
.u
.def
.value
9508 + h
->root
.u
.def
.section
->output_section
->vma
9509 + h
->root
.u
.def
.section
->output_offset
);
9514 BFD_ASSERT ((h
->got
.offset
& 1) == 0);
9515 bfd_put_NN (output_bfd
, (bfd_vma
) 0,
9516 htab
->root
.sgot
->contents
+ h
->got
.offset
);
9517 rela
.r_info
= ELFNN_R_INFO (h
->dynindx
, AARCH64_R (GLOB_DAT
));
9521 loc
= htab
->root
.srelgot
->contents
;
9522 loc
+= htab
->root
.srelgot
->reloc_count
++ * RELOC_SIZE (htab
);
9523 bfd_elfNN_swap_reloca_out (output_bfd
, &rela
, loc
);
9528 Elf_Internal_Rela rela
;
9532 /* This symbol needs a copy reloc. Set it up. */
9533 if (h
->dynindx
== -1
9534 || (h
->root
.type
!= bfd_link_hash_defined
9535 && h
->root
.type
!= bfd_link_hash_defweak
)
9536 || htab
->root
.srelbss
== NULL
)
9539 rela
.r_offset
= (h
->root
.u
.def
.value
9540 + h
->root
.u
.def
.section
->output_section
->vma
9541 + h
->root
.u
.def
.section
->output_offset
);
9542 rela
.r_info
= ELFNN_R_INFO (h
->dynindx
, AARCH64_R (COPY
));
9544 if (h
->root
.u
.def
.section
== htab
->root
.sdynrelro
)
9545 s
= htab
->root
.sreldynrelro
;
9547 s
= htab
->root
.srelbss
;
9548 loc
= s
->contents
+ s
->reloc_count
++ * RELOC_SIZE (htab
);
9549 bfd_elfNN_swap_reloca_out (output_bfd
, &rela
, loc
);
9552 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. SYM may
9553 be NULL for local symbols. */
9555 && (h
== elf_hash_table (info
)->hdynamic
9556 || h
== elf_hash_table (info
)->hgot
))
9557 sym
->st_shndx
= SHN_ABS
;
9562 /* Finish up local dynamic symbol handling. We set the contents of
9563 various dynamic sections here. */
9566 elfNN_aarch64_finish_local_dynamic_symbol (void **slot
, void *inf
)
9568 struct elf_link_hash_entry
*h
9569 = (struct elf_link_hash_entry
*) *slot
;
9570 struct bfd_link_info
*info
9571 = (struct bfd_link_info
*) inf
;
9573 return elfNN_aarch64_finish_dynamic_symbol (info
->output_bfd
,
9578 elfNN_aarch64_init_small_plt0_entry (bfd
*output_bfd ATTRIBUTE_UNUSED
,
9579 struct elf_aarch64_link_hash_table
9582 /* Fill in PLT0. Fixme:RR Note this doesn't distinguish between
9583 small and large plts and at the minute just generates
9586 /* PLT0 of the small PLT looks like this in ELF64 -
9587 stp x16, x30, [sp, #-16]! // Save the reloc and lr on stack.
9588 adrp x16, PLT_GOT + 16 // Get the page base of the GOTPLT
9589 ldr x17, [x16, #:lo12:PLT_GOT+16] // Load the address of the
9591 add x16, x16, #:lo12:PLT_GOT+16 // Load the lo12 bits of the
9592 // GOTPLT entry for this.
9594 PLT0 will be slightly different in ELF32 due to different got entry
9596 bfd_vma plt_got_2nd_ent
; /* Address of GOT[2]. */
9600 memcpy (htab
->root
.splt
->contents
, htab
->plt0_entry
,
9601 htab
->plt_header_size
);
9602 elf_section_data (htab
->root
.splt
->output_section
)->this_hdr
.sh_entsize
=
9603 htab
->plt_header_size
;
9605 plt_got_2nd_ent
= (htab
->root
.sgotplt
->output_section
->vma
9606 + htab
->root
.sgotplt
->output_offset
9607 + GOT_ENTRY_SIZE
* 2);
9609 plt_base
= htab
->root
.splt
->output_section
->vma
+
9610 htab
->root
.splt
->output_offset
;
9612 /* First instruction in BTI enabled PLT stub is a BTI
9613 instruction so skip it. */
9614 bfd_byte
*plt0_entry
= htab
->root
.splt
->contents
;
9615 if (elf_aarch64_tdata (output_bfd
)->plt_type
& PLT_BTI
)
9616 plt0_entry
= plt0_entry
+ 4;
9618 /* Fill in the top 21 bits for this: ADRP x16, PLT_GOT + n * 8.
9619 ADRP: ((PG(S+A)-PG(P)) >> 12) & 0x1fffff */
9620 elf_aarch64_update_plt_entry (output_bfd
, BFD_RELOC_AARCH64_ADR_HI21_PCREL
,
9622 PG (plt_got_2nd_ent
) - PG (plt_base
+ 4));
9624 elf_aarch64_update_plt_entry (output_bfd
, BFD_RELOC_AARCH64_LDSTNN_LO12
,
9626 PG_OFFSET (plt_got_2nd_ent
));
9628 elf_aarch64_update_plt_entry (output_bfd
, BFD_RELOC_AARCH64_ADD_LO12
,
9630 PG_OFFSET (plt_got_2nd_ent
));
9634 elfNN_aarch64_finish_dynamic_sections (bfd
*output_bfd
,
9635 struct bfd_link_info
*info
)
9637 struct elf_aarch64_link_hash_table
*htab
;
9641 htab
= elf_aarch64_hash_table (info
);
9642 dynobj
= htab
->root
.dynobj
;
9643 sdyn
= bfd_get_linker_section (dynobj
, ".dynamic");
9645 if (htab
->root
.dynamic_sections_created
)
9647 ElfNN_External_Dyn
*dyncon
, *dynconend
;
9649 if (sdyn
== NULL
|| htab
->root
.sgot
== NULL
)
9652 dyncon
= (ElfNN_External_Dyn
*) sdyn
->contents
;
9653 dynconend
= (ElfNN_External_Dyn
*) (sdyn
->contents
+ sdyn
->size
);
9654 for (; dyncon
< dynconend
; dyncon
++)
9656 Elf_Internal_Dyn dyn
;
9659 bfd_elfNN_swap_dyn_in (dynobj
, dyncon
, &dyn
);
9667 s
= htab
->root
.sgotplt
;
9668 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
9672 s
= htab
->root
.srelplt
;
9673 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
9677 s
= htab
->root
.srelplt
;
9678 dyn
.d_un
.d_val
= s
->size
;
9681 case DT_TLSDESC_PLT
:
9682 s
= htab
->root
.splt
;
9683 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
9684 + htab
->tlsdesc_plt
;
9687 case DT_TLSDESC_GOT
:
9688 s
= htab
->root
.sgot
;
9689 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
9690 + htab
->dt_tlsdesc_got
;
9694 bfd_elfNN_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
9699 /* Fill in the special first entry in the procedure linkage table. */
9700 if (htab
->root
.splt
&& htab
->root
.splt
->size
> 0)
9702 elfNN_aarch64_init_small_plt0_entry (output_bfd
, htab
);
9704 elf_section_data (htab
->root
.splt
->output_section
)->
9705 this_hdr
.sh_entsize
= htab
->plt_entry_size
;
9708 if (htab
->tlsdesc_plt
)
9710 bfd_put_NN (output_bfd
, (bfd_vma
) 0,
9711 htab
->root
.sgot
->contents
+ htab
->dt_tlsdesc_got
);
9713 const bfd_byte
*entry
= elfNN_aarch64_tlsdesc_small_plt_entry
;
9714 htab
->tlsdesc_plt_entry_size
= PLT_TLSDESC_ENTRY_SIZE
;
9716 aarch64_plt_type type
= elf_aarch64_tdata (output_bfd
)->plt_type
;
9717 if (type
== PLT_BTI
|| type
== PLT_BTI_PAC
)
9719 entry
= elfNN_aarch64_tlsdesc_small_plt_bti_entry
;
9720 htab
->tlsdesc_plt_entry_size
= PLT_BTI_TLSDESC_ENTRY_SIZE
;
9723 memcpy (htab
->root
.splt
->contents
+ htab
->tlsdesc_plt
,
9724 entry
, htab
->tlsdesc_plt_entry_size
);
9727 bfd_vma adrp1_addr
=
9728 htab
->root
.splt
->output_section
->vma
9729 + htab
->root
.splt
->output_offset
+ htab
->tlsdesc_plt
+ 4;
9731 bfd_vma adrp2_addr
= adrp1_addr
+ 4;
9734 htab
->root
.sgot
->output_section
->vma
9735 + htab
->root
.sgot
->output_offset
;
9737 bfd_vma pltgot_addr
=
9738 htab
->root
.sgotplt
->output_section
->vma
9739 + htab
->root
.sgotplt
->output_offset
;
9741 bfd_vma dt_tlsdesc_got
= got_addr
+ htab
->dt_tlsdesc_got
;
9743 bfd_byte
*plt_entry
=
9744 htab
->root
.splt
->contents
+ htab
->tlsdesc_plt
;
9746 /* First instruction in BTI enabled PLT stub is a BTI
9747 instruction so skip it. */
9750 plt_entry
= plt_entry
+ 4;
9751 adrp1_addr
= adrp1_addr
+ 4;
9752 adrp2_addr
= adrp2_addr
+ 4;
9755 /* adrp x2, DT_TLSDESC_GOT */
9756 elf_aarch64_update_plt_entry (output_bfd
,
9757 BFD_RELOC_AARCH64_ADR_HI21_PCREL
,
9759 (PG (dt_tlsdesc_got
)
9760 - PG (adrp1_addr
)));
9763 elf_aarch64_update_plt_entry (output_bfd
,
9764 BFD_RELOC_AARCH64_ADR_HI21_PCREL
,
9767 - PG (adrp2_addr
)));
9769 /* ldr x2, [x2, #0] */
9770 elf_aarch64_update_plt_entry (output_bfd
,
9771 BFD_RELOC_AARCH64_LDSTNN_LO12
,
9773 PG_OFFSET (dt_tlsdesc_got
));
9776 elf_aarch64_update_plt_entry (output_bfd
,
9777 BFD_RELOC_AARCH64_ADD_LO12
,
9779 PG_OFFSET (pltgot_addr
));
9784 if (htab
->root
.sgotplt
)
9786 if (bfd_is_abs_section (htab
->root
.sgotplt
->output_section
))
9789 (_("discarded output section: `%pA'"), htab
->root
.sgotplt
);
9793 /* Fill in the first three entries in the global offset table. */
9794 if (htab
->root
.sgotplt
->size
> 0)
9796 bfd_put_NN (output_bfd
, (bfd_vma
) 0, htab
->root
.sgotplt
->contents
);
9798 /* Write GOT[1] and GOT[2], needed for the dynamic linker. */
9799 bfd_put_NN (output_bfd
,
9801 htab
->root
.sgotplt
->contents
+ GOT_ENTRY_SIZE
);
9802 bfd_put_NN (output_bfd
,
9804 htab
->root
.sgotplt
->contents
+ GOT_ENTRY_SIZE
* 2);
9807 if (htab
->root
.sgot
)
9809 if (htab
->root
.sgot
->size
> 0)
9812 sdyn
? sdyn
->output_section
->vma
+ sdyn
->output_offset
: 0;
9813 bfd_put_NN (output_bfd
, addr
, htab
->root
.sgot
->contents
);
9817 elf_section_data (htab
->root
.sgotplt
->output_section
)->
9818 this_hdr
.sh_entsize
= GOT_ENTRY_SIZE
;
9821 if (htab
->root
.sgot
&& htab
->root
.sgot
->size
> 0)
9822 elf_section_data (htab
->root
.sgot
->output_section
)->this_hdr
.sh_entsize
9825 /* Fill PLT and GOT entries for local STT_GNU_IFUNC symbols. */
9826 htab_traverse (htab
->loc_hash_table
,
9827 elfNN_aarch64_finish_local_dynamic_symbol
,
9833 /* Check if BTI enabled PLTs are needed. Returns the type needed. */
9834 static aarch64_plt_type
9835 get_plt_type (bfd
*abfd
)
9837 aarch64_plt_type ret
= PLT_NORMAL
;
9838 bfd_byte
*contents
, *extdyn
, *extdynend
;
9839 asection
*sec
= bfd_get_section_by_name (abfd
, ".dynamic");
9840 if (!sec
|| !bfd_malloc_and_get_section (abfd
, sec
, &contents
))
9843 extdynend
= contents
+ sec
->size
;
9844 for (; extdyn
< extdynend
; extdyn
+= sizeof (ElfNN_External_Dyn
))
9846 Elf_Internal_Dyn dyn
;
9847 bfd_elfNN_swap_dyn_in (abfd
, extdyn
, &dyn
);
9849 /* Let's check the processor specific dynamic array tags. */
9850 bfd_vma tag
= dyn
.d_tag
;
9851 if (tag
< DT_LOPROC
|| tag
> DT_HIPROC
)
9856 case DT_AARCH64_BTI_PLT
:
9860 case DT_AARCH64_PAC_PLT
:
9872 elfNN_aarch64_get_synthetic_symtab (bfd
*abfd
,
9879 elf_aarch64_tdata (abfd
)->plt_type
= get_plt_type (abfd
);
9880 return _bfd_elf_get_synthetic_symtab (abfd
, symcount
, syms
,
9881 dynsymcount
, dynsyms
, ret
);
9884 /* Return address for Ith PLT stub in section PLT, for relocation REL
9885 or (bfd_vma) -1 if it should not be included. */
9888 elfNN_aarch64_plt_sym_val (bfd_vma i
, const asection
*plt
,
9889 const arelent
*rel ATTRIBUTE_UNUSED
)
9891 size_t plt0_size
= PLT_ENTRY_SIZE
;
9892 size_t pltn_size
= PLT_SMALL_ENTRY_SIZE
;
9894 if (elf_aarch64_tdata (plt
->owner
)->plt_type
== PLT_BTI_PAC
)
9896 plt0_size
= PLT_BTI_PAC_ENTRY_SIZE
;
9897 if (elf_elfheader (plt
->owner
)->e_type
== ET_EXEC
)
9898 pltn_size
= PLT_BTI_PAC_SMALL_ENTRY_SIZE
;
9900 pltn_size
= PLT_PAC_SMALL_ENTRY_SIZE
;
9902 else if (elf_aarch64_tdata (plt
->owner
)->plt_type
== PLT_BTI
)
9904 plt0_size
= PLT_BTI_ENTRY_SIZE
;
9905 if (elf_elfheader (plt
->owner
)->e_type
== ET_EXEC
)
9906 pltn_size
= PLT_BTI_SMALL_ENTRY_SIZE
;
9908 else if (elf_aarch64_tdata (plt
->owner
)->plt_type
== PLT_PAC
)
9910 plt0_size
= PLT_PAC_ENTRY_SIZE
;
9911 pltn_size
= PLT_PAC_SMALL_ENTRY_SIZE
;
9914 return plt
->vma
+ plt0_size
+ i
* pltn_size
;
9917 /* Returns TRUE if NAME is an AArch64 mapping symbol.
9918 The ARM ELF standard defines $x (for A64 code) and $d (for data).
9919 It also allows a period initiated suffix to be added to the symbol, ie:
9920 "$[adtx]\.[:sym_char]+". */
9923 is_aarch64_mapping_symbol (const char * name
)
9925 return name
!= NULL
/* Paranoia. */
9926 && name
[0] == '$' /* Note: if objcopy --prefix-symbols has been used then
9927 the mapping symbols could have acquired a prefix.
9928 We do not support this here, since such symbols no
9929 longer conform to the ARM ELF ABI. */
9930 && (name
[1] == 'd' || name
[1] == 'x')
9931 && (name
[2] == 0 || name
[2] == '.');
9932 /* FIXME: Strictly speaking the symbol is only a valid mapping symbol if
9933 any characters that follow the period are legal characters for the body
9934 of a symbol's name. For now we just assume that this is the case. */
9937 /* Make sure that mapping symbols in object files are not removed via the
9938 "strip --strip-unneeded" tool. These symbols might needed in order to
9939 correctly generate linked files. Once an object file has been linked,
9940 it should be safe to remove them. */
9943 elfNN_aarch64_backend_symbol_processing (bfd
*abfd
, asymbol
*sym
)
9945 if (((abfd
->flags
& (EXEC_P
| DYNAMIC
)) == 0)
9946 && sym
->section
!= bfd_abs_section_ptr
9947 && is_aarch64_mapping_symbol (sym
->name
))
9948 sym
->flags
|= BSF_KEEP
;
9951 /* Implement elf_backend_setup_gnu_properties for AArch64. It serves as a
9952 wrapper function for _bfd_aarch64_elf_link_setup_gnu_properties to account
9953 for the effect of GNU properties of the output_bfd. */
9955 elfNN_aarch64_link_setup_gnu_properties (struct bfd_link_info
*info
)
9957 uint32_t prop
= elf_aarch64_tdata (info
->output_bfd
)->gnu_and_prop
;
9958 bfd
*pbfd
= _bfd_aarch64_elf_link_setup_gnu_properties (info
, &prop
);
9959 elf_aarch64_tdata (info
->output_bfd
)->gnu_and_prop
= prop
;
9960 elf_aarch64_tdata (info
->output_bfd
)->plt_type
9961 |= (prop
& GNU_PROPERTY_AARCH64_FEATURE_1_BTI
) ? PLT_BTI
: 0;
9962 setup_plt_values (info
, elf_aarch64_tdata (info
->output_bfd
)->plt_type
);
9966 /* Implement elf_backend_merge_gnu_properties for AArch64. It serves as a
9967 wrapper function for _bfd_aarch64_elf_merge_gnu_properties to account
9968 for the effect of GNU properties of the output_bfd. */
9970 elfNN_aarch64_merge_gnu_properties (struct bfd_link_info
*info
,
9972 elf_property
*aprop
,
9973 elf_property
*bprop
)
9976 = elf_aarch64_tdata (info
->output_bfd
)->gnu_and_prop
;
9978 /* If output has been marked with BTI using command line argument, give out
9979 warning if necessary. */
9980 if ((prop
& GNU_PROPERTY_AARCH64_FEATURE_1_BTI
)
9981 && (!elf_aarch64_tdata (info
->output_bfd
)->no_bti_warn
))
9983 if ((aprop
&& !(aprop
->u
.number
& GNU_PROPERTY_AARCH64_FEATURE_1_BTI
))
9984 || (bprop
&& !(bprop
->u
.number
& GNU_PROPERTY_AARCH64_FEATURE_1_BTI
))
9985 /* If either property is NULL, it means its bfd did not have any
9987 || !aprop
|| !bprop
)
9989 _bfd_error_handler (_("warning: BTI turned on by --force-bti when "
9990 "all inputs do not have BTI in NOTE section."));
9994 return _bfd_aarch64_elf_merge_gnu_properties (info
, abfd
, aprop
,
9998 /* We use this so we can override certain functions
9999 (though currently we don't). */
10001 const struct elf_size_info elfNN_aarch64_size_info
=
10003 sizeof (ElfNN_External_Ehdr
),
10004 sizeof (ElfNN_External_Phdr
),
10005 sizeof (ElfNN_External_Shdr
),
10006 sizeof (ElfNN_External_Rel
),
10007 sizeof (ElfNN_External_Rela
),
10008 sizeof (ElfNN_External_Sym
),
10009 sizeof (ElfNN_External_Dyn
),
10010 sizeof (Elf_External_Note
),
10011 4, /* Hash table entry size. */
10012 1, /* Internal relocs per external relocs. */
10013 ARCH_SIZE
, /* Arch size. */
10014 LOG_FILE_ALIGN
, /* Log_file_align. */
10015 ELFCLASSNN
, EV_CURRENT
,
10016 bfd_elfNN_write_out_phdrs
,
10017 bfd_elfNN_write_shdrs_and_ehdr
,
10018 bfd_elfNN_checksum_contents
,
10019 bfd_elfNN_write_relocs
,
10020 bfd_elfNN_swap_symbol_in
,
10021 bfd_elfNN_swap_symbol_out
,
10022 bfd_elfNN_slurp_reloc_table
,
10023 bfd_elfNN_slurp_symbol_table
,
10024 bfd_elfNN_swap_dyn_in
,
10025 bfd_elfNN_swap_dyn_out
,
10026 bfd_elfNN_swap_reloc_in
,
10027 bfd_elfNN_swap_reloc_out
,
10028 bfd_elfNN_swap_reloca_in
,
10029 bfd_elfNN_swap_reloca_out
10032 #define ELF_ARCH bfd_arch_aarch64
10033 #define ELF_MACHINE_CODE EM_AARCH64
10034 #define ELF_MAXPAGESIZE 0x10000
10035 #define ELF_MINPAGESIZE 0x1000
10036 #define ELF_COMMONPAGESIZE 0x1000
10038 #define bfd_elfNN_close_and_cleanup \
10039 elfNN_aarch64_close_and_cleanup
10041 #define bfd_elfNN_bfd_free_cached_info \
10042 elfNN_aarch64_bfd_free_cached_info
10044 #define bfd_elfNN_bfd_is_target_special_symbol \
10045 elfNN_aarch64_is_target_special_symbol
10047 #define bfd_elfNN_bfd_link_hash_table_create \
10048 elfNN_aarch64_link_hash_table_create
10050 #define bfd_elfNN_bfd_merge_private_bfd_data \
10051 elfNN_aarch64_merge_private_bfd_data
10053 #define bfd_elfNN_bfd_print_private_bfd_data \
10054 elfNN_aarch64_print_private_bfd_data
10056 #define bfd_elfNN_bfd_reloc_type_lookup \
10057 elfNN_aarch64_reloc_type_lookup
10059 #define bfd_elfNN_bfd_reloc_name_lookup \
10060 elfNN_aarch64_reloc_name_lookup
10062 #define bfd_elfNN_bfd_set_private_flags \
10063 elfNN_aarch64_set_private_flags
10065 #define bfd_elfNN_find_inliner_info \
10066 elfNN_aarch64_find_inliner_info
10068 #define bfd_elfNN_find_nearest_line \
10069 elfNN_aarch64_find_nearest_line
10071 #define bfd_elfNN_get_synthetic_symtab \
10072 elfNN_aarch64_get_synthetic_symtab
10074 #define bfd_elfNN_mkobject \
10075 elfNN_aarch64_mkobject
10077 #define bfd_elfNN_new_section_hook \
10078 elfNN_aarch64_new_section_hook
10080 #define elf_backend_adjust_dynamic_symbol \
10081 elfNN_aarch64_adjust_dynamic_symbol
10083 #define elf_backend_always_size_sections \
10084 elfNN_aarch64_always_size_sections
10086 #define elf_backend_check_relocs \
10087 elfNN_aarch64_check_relocs
10089 #define elf_backend_copy_indirect_symbol \
10090 elfNN_aarch64_copy_indirect_symbol
10092 /* Create .dynbss, and .rela.bss sections in DYNOBJ, and set up shortcuts
10093 to them in our hash. */
10094 #define elf_backend_create_dynamic_sections \
10095 elfNN_aarch64_create_dynamic_sections
10097 #define elf_backend_init_index_section \
10098 _bfd_elf_init_2_index_sections
10100 #define elf_backend_finish_dynamic_sections \
10101 elfNN_aarch64_finish_dynamic_sections
10103 #define elf_backend_finish_dynamic_symbol \
10104 elfNN_aarch64_finish_dynamic_symbol
10106 #define elf_backend_object_p \
10107 elfNN_aarch64_object_p
10109 #define elf_backend_output_arch_local_syms \
10110 elfNN_aarch64_output_arch_local_syms
10112 #define elf_backend_plt_sym_val \
10113 elfNN_aarch64_plt_sym_val
10115 #define elf_backend_post_process_headers \
10116 elfNN_aarch64_post_process_headers
10118 #define elf_backend_relocate_section \
10119 elfNN_aarch64_relocate_section
10121 #define elf_backend_reloc_type_class \
10122 elfNN_aarch64_reloc_type_class
10124 #define elf_backend_section_from_shdr \
10125 elfNN_aarch64_section_from_shdr
10127 #define elf_backend_size_dynamic_sections \
10128 elfNN_aarch64_size_dynamic_sections
10130 #define elf_backend_size_info \
10131 elfNN_aarch64_size_info
10133 #define elf_backend_write_section \
10134 elfNN_aarch64_write_section
10136 #define elf_backend_symbol_processing \
10137 elfNN_aarch64_backend_symbol_processing
10139 #define elf_backend_setup_gnu_properties \
10140 elfNN_aarch64_link_setup_gnu_properties
10142 #define elf_backend_merge_gnu_properties \
10143 elfNN_aarch64_merge_gnu_properties
10145 #define elf_backend_can_refcount 1
10146 #define elf_backend_can_gc_sections 1
10147 #define elf_backend_plt_readonly 1
10148 #define elf_backend_want_got_plt 1
10149 #define elf_backend_want_plt_sym 0
10150 #define elf_backend_want_dynrelro 1
10151 #define elf_backend_may_use_rel_p 0
10152 #define elf_backend_may_use_rela_p 1
10153 #define elf_backend_default_use_rela_p 1
10154 #define elf_backend_rela_normal 1
10155 #define elf_backend_dtrel_excludes_plt 1
10156 #define elf_backend_got_header_size (GOT_ENTRY_SIZE * 3)
10157 #define elf_backend_default_execstack 0
10158 #define elf_backend_extern_protected_data 1
10159 #define elf_backend_hash_symbol elf_aarch64_hash_symbol
10161 #undef elf_backend_obj_attrs_section
10162 #define elf_backend_obj_attrs_section ".ARM.attributes"
10164 #include "elfNN-target.h"
10166 /* CloudABI support. */
10168 #undef TARGET_LITTLE_SYM
10169 #define TARGET_LITTLE_SYM aarch64_elfNN_le_cloudabi_vec
10170 #undef TARGET_LITTLE_NAME
10171 #define TARGET_LITTLE_NAME "elfNN-littleaarch64-cloudabi"
10172 #undef TARGET_BIG_SYM
10173 #define TARGET_BIG_SYM aarch64_elfNN_be_cloudabi_vec
10174 #undef TARGET_BIG_NAME
10175 #define TARGET_BIG_NAME "elfNN-bigaarch64-cloudabi"
10178 #define ELF_OSABI ELFOSABI_CLOUDABI
10181 #define elfNN_bed elfNN_aarch64_cloudabi_bed
10183 #include "elfNN-target.h"