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_SMALL_ENTRY_SIZE (24)
272 /* PLT sizes with PAC insn. */
273 #define PLT_PAC_SMALL_ENTRY_SIZE (24)
274 /* PLT sizes with BTI and PAC insn. */
275 #define PLT_BTI_PAC_SMALL_ENTRY_SIZE (24)
277 /* Encoding of the nop instruction. */
278 #define INSN_NOP 0xd503201f
280 #define aarch64_compute_jump_table_size(htab) \
281 (((htab)->root.srelplt == NULL) ? 0 \
282 : (htab)->root.srelplt->reloc_count * GOT_ENTRY_SIZE)
284 /* The first entry in a procedure linkage table looks like this
285 if the distance between the PLTGOT and the PLT is < 4GB use
286 these PLT entries. Note that the dynamic linker gets &PLTGOT[2]
287 in x16 and needs to work out PLTGOT[1] by using an address of
288 [x16,#-GOT_ENTRY_SIZE]. */
289 static const bfd_byte elfNN_aarch64_small_plt0_entry
[PLT_ENTRY_SIZE
] =
291 0xf0, 0x7b, 0xbf, 0xa9, /* stp x16, x30, [sp, #-16]! */
292 0x10, 0x00, 0x00, 0x90, /* adrp x16, (GOT+16) */
294 0x11, 0x0A, 0x40, 0xf9, /* ldr x17, [x16, #PLT_GOT+0x10] */
295 0x10, 0x42, 0x00, 0x91, /* add x16, x16,#PLT_GOT+0x10 */
297 0x11, 0x0A, 0x40, 0xb9, /* ldr w17, [x16, #PLT_GOT+0x8] */
298 0x10, 0x22, 0x00, 0x11, /* add w16, w16,#PLT_GOT+0x8 */
300 0x20, 0x02, 0x1f, 0xd6, /* br x17 */
301 0x1f, 0x20, 0x03, 0xd5, /* nop */
302 0x1f, 0x20, 0x03, 0xd5, /* nop */
303 0x1f, 0x20, 0x03, 0xd5, /* nop */
306 static const bfd_byte elfNN_aarch64_small_plt0_bti_entry
[PLT_ENTRY_SIZE
] =
308 0x5f, 0x24, 0x03, 0xd5, /* bti c. */
309 0xf0, 0x7b, 0xbf, 0xa9, /* stp x16, x30, [sp, #-16]! */
310 0x10, 0x00, 0x00, 0x90, /* adrp x16, (GOT+16) */
312 0x11, 0x0A, 0x40, 0xf9, /* ldr x17, [x16, #PLT_GOT+0x10] */
313 0x10, 0x42, 0x00, 0x91, /* add x16, x16,#PLT_GOT+0x10 */
315 0x11, 0x0A, 0x40, 0xb9, /* ldr w17, [x16, #PLT_GOT+0x8] */
316 0x10, 0x22, 0x00, 0x11, /* add w16, w16,#PLT_GOT+0x8 */
318 0x20, 0x02, 0x1f, 0xd6, /* br x17 */
319 0x1f, 0x20, 0x03, 0xd5, /* nop */
320 0x1f, 0x20, 0x03, 0xd5, /* nop */
323 /* Per function entry in a procedure linkage table looks like this
324 if the distance between the PLTGOT and the PLT is < 4GB use
325 these PLT entries. Use BTI versions of the PLTs when enabled. */
326 static const bfd_byte elfNN_aarch64_small_plt_entry
[PLT_SMALL_ENTRY_SIZE
] =
328 0x10, 0x00, 0x00, 0x90, /* adrp x16, PLTGOT + n * 8 */
330 0x11, 0x02, 0x40, 0xf9, /* ldr x17, [x16, PLTGOT + n * 8] */
331 0x10, 0x02, 0x00, 0x91, /* add x16, x16, :lo12:PLTGOT + n * 8 */
333 0x11, 0x02, 0x40, 0xb9, /* ldr w17, [x16, PLTGOT + n * 4] */
334 0x10, 0x02, 0x00, 0x11, /* add w16, w16, :lo12:PLTGOT + n * 4 */
336 0x20, 0x02, 0x1f, 0xd6, /* br x17. */
339 static const bfd_byte
340 elfNN_aarch64_small_plt_bti_entry
[PLT_BTI_SMALL_ENTRY_SIZE
] =
342 0x5f, 0x24, 0x03, 0xd5, /* bti c. */
343 0x10, 0x00, 0x00, 0x90, /* adrp x16, PLTGOT + n * 8 */
345 0x11, 0x02, 0x40, 0xf9, /* ldr x17, [x16, PLTGOT + n * 8] */
346 0x10, 0x02, 0x00, 0x91, /* add x16, x16, :lo12:PLTGOT + n * 8 */
348 0x11, 0x02, 0x40, 0xb9, /* ldr w17, [x16, PLTGOT + n * 4] */
349 0x10, 0x02, 0x00, 0x11, /* add w16, w16, :lo12:PLTGOT + n * 4 */
351 0x20, 0x02, 0x1f, 0xd6, /* br x17. */
352 0x1f, 0x20, 0x03, 0xd5, /* nop */
355 static const bfd_byte
356 elfNN_aarch64_small_plt_pac_entry
[PLT_PAC_SMALL_ENTRY_SIZE
] =
358 0x10, 0x00, 0x00, 0x90, /* adrp x16, PLTGOT + n * 8 */
360 0x11, 0x02, 0x40, 0xf9, /* ldr x17, [x16, PLTGOT + n * 8] */
361 0x10, 0x02, 0x00, 0x91, /* add x16, x16, :lo12:PLTGOT + n * 8 */
363 0x11, 0x02, 0x40, 0xb9, /* ldr w17, [x16, PLTGOT + n * 4] */
364 0x10, 0x02, 0x00, 0x11, /* add w16, w16, :lo12:PLTGOT + n * 4 */
366 0x9f, 0x21, 0x03, 0xd5, /* autia1716 */
367 0x20, 0x02, 0x1f, 0xd6, /* br x17. */
368 0x1f, 0x20, 0x03, 0xd5, /* nop */
371 static const bfd_byte
372 elfNN_aarch64_small_plt_bti_pac_entry
[PLT_BTI_PAC_SMALL_ENTRY_SIZE
] =
374 0x5f, 0x24, 0x03, 0xd5, /* bti c. */
375 0x10, 0x00, 0x00, 0x90, /* adrp x16, PLTGOT + n * 8 */
377 0x11, 0x02, 0x40, 0xf9, /* ldr x17, [x16, PLTGOT + n * 8] */
378 0x10, 0x02, 0x00, 0x91, /* add x16, x16, :lo12:PLTGOT + n * 8 */
380 0x11, 0x02, 0x40, 0xb9, /* ldr w17, [x16, PLTGOT + n * 4] */
381 0x10, 0x02, 0x00, 0x11, /* add w16, w16, :lo12:PLTGOT + n * 4 */
383 0x9f, 0x21, 0x03, 0xd5, /* autia1716 */
384 0x20, 0x02, 0x1f, 0xd6, /* br x17. */
387 static const bfd_byte
388 elfNN_aarch64_tlsdesc_small_plt_entry
[PLT_TLSDESC_ENTRY_SIZE
] =
390 0xe2, 0x0f, 0xbf, 0xa9, /* stp x2, x3, [sp, #-16]! */
391 0x02, 0x00, 0x00, 0x90, /* adrp x2, 0 */
392 0x03, 0x00, 0x00, 0x90, /* adrp x3, 0 */
394 0x42, 0x00, 0x40, 0xf9, /* ldr x2, [x2, #0] */
395 0x63, 0x00, 0x00, 0x91, /* add x3, x3, 0 */
397 0x42, 0x00, 0x40, 0xb9, /* ldr w2, [x2, #0] */
398 0x63, 0x00, 0x00, 0x11, /* add w3, w3, 0 */
400 0x40, 0x00, 0x1f, 0xd6, /* br x2 */
401 0x1f, 0x20, 0x03, 0xd5, /* nop */
402 0x1f, 0x20, 0x03, 0xd5, /* nop */
405 static const bfd_byte
406 elfNN_aarch64_tlsdesc_small_plt_bti_entry
[PLT_TLSDESC_ENTRY_SIZE
] =
408 0x5f, 0x24, 0x03, 0xd5, /* bti c. */
409 0xe2, 0x0f, 0xbf, 0xa9, /* stp x2, x3, [sp, #-16]! */
410 0x02, 0x00, 0x00, 0x90, /* adrp x2, 0 */
411 0x03, 0x00, 0x00, 0x90, /* adrp x3, 0 */
413 0x42, 0x00, 0x40, 0xf9, /* ldr x2, [x2, #0] */
414 0x63, 0x00, 0x00, 0x91, /* add x3, x3, 0 */
416 0x42, 0x00, 0x40, 0xb9, /* ldr w2, [x2, #0] */
417 0x63, 0x00, 0x00, 0x11, /* add w3, w3, 0 */
419 0x40, 0x00, 0x1f, 0xd6, /* br x2 */
420 0x1f, 0x20, 0x03, 0xd5, /* nop */
423 #define elf_info_to_howto elfNN_aarch64_info_to_howto
424 #define elf_info_to_howto_rel elfNN_aarch64_info_to_howto
426 #define AARCH64_ELF_ABI_VERSION 0
428 /* In case we're on a 32-bit machine, construct a 64-bit "-1" value. */
429 #define ALL_ONES (~ (bfd_vma) 0)
431 /* Indexed by the bfd interal reloc enumerators.
432 Therefore, the table needs to be synced with BFD_RELOC_AARCH64_*
435 static reloc_howto_type elfNN_aarch64_howto_table
[] =
439 /* Basic data relocations. */
441 /* Deprecated, but retained for backwards compatibility. */
442 HOWTO64 (R_AARCH64_NULL
, /* type */
444 3, /* size (0 = byte, 1 = short, 2 = long) */
446 FALSE
, /* pc_relative */
448 complain_overflow_dont
, /* complain_on_overflow */
449 bfd_elf_generic_reloc
, /* special_function */
450 "R_AARCH64_NULL", /* name */
451 FALSE
, /* partial_inplace */
454 FALSE
), /* pcrel_offset */
455 HOWTO (R_AARCH64_NONE
, /* type */
457 3, /* size (0 = byte, 1 = short, 2 = long) */
459 FALSE
, /* pc_relative */
461 complain_overflow_dont
, /* complain_on_overflow */
462 bfd_elf_generic_reloc
, /* special_function */
463 "R_AARCH64_NONE", /* name */
464 FALSE
, /* partial_inplace */
467 FALSE
), /* pcrel_offset */
470 HOWTO64 (AARCH64_R (ABS64
), /* type */
472 4, /* size (4 = long long) */
474 FALSE
, /* pc_relative */
476 complain_overflow_unsigned
, /* complain_on_overflow */
477 bfd_elf_generic_reloc
, /* special_function */
478 AARCH64_R_STR (ABS64
), /* name */
479 FALSE
, /* partial_inplace */
480 ALL_ONES
, /* src_mask */
481 ALL_ONES
, /* dst_mask */
482 FALSE
), /* pcrel_offset */
485 HOWTO (AARCH64_R (ABS32
), /* type */
487 2, /* size (0 = byte, 1 = short, 2 = long) */
489 FALSE
, /* pc_relative */
491 complain_overflow_unsigned
, /* complain_on_overflow */
492 bfd_elf_generic_reloc
, /* special_function */
493 AARCH64_R_STR (ABS32
), /* name */
494 FALSE
, /* partial_inplace */
495 0xffffffff, /* src_mask */
496 0xffffffff, /* dst_mask */
497 FALSE
), /* pcrel_offset */
500 HOWTO (AARCH64_R (ABS16
), /* type */
502 1, /* size (0 = byte, 1 = short, 2 = long) */
504 FALSE
, /* pc_relative */
506 complain_overflow_unsigned
, /* complain_on_overflow */
507 bfd_elf_generic_reloc
, /* special_function */
508 AARCH64_R_STR (ABS16
), /* name */
509 FALSE
, /* partial_inplace */
510 0xffff, /* src_mask */
511 0xffff, /* dst_mask */
512 FALSE
), /* pcrel_offset */
514 /* .xword: (S+A-P) */
515 HOWTO64 (AARCH64_R (PREL64
), /* type */
517 4, /* size (4 = long long) */
519 TRUE
, /* pc_relative */
521 complain_overflow_signed
, /* complain_on_overflow */
522 bfd_elf_generic_reloc
, /* special_function */
523 AARCH64_R_STR (PREL64
), /* name */
524 FALSE
, /* partial_inplace */
525 ALL_ONES
, /* src_mask */
526 ALL_ONES
, /* dst_mask */
527 TRUE
), /* pcrel_offset */
530 HOWTO (AARCH64_R (PREL32
), /* type */
532 2, /* size (0 = byte, 1 = short, 2 = long) */
534 TRUE
, /* pc_relative */
536 complain_overflow_signed
, /* complain_on_overflow */
537 bfd_elf_generic_reloc
, /* special_function */
538 AARCH64_R_STR (PREL32
), /* name */
539 FALSE
, /* partial_inplace */
540 0xffffffff, /* src_mask */
541 0xffffffff, /* dst_mask */
542 TRUE
), /* pcrel_offset */
545 HOWTO (AARCH64_R (PREL16
), /* type */
547 1, /* size (0 = byte, 1 = short, 2 = long) */
549 TRUE
, /* pc_relative */
551 complain_overflow_signed
, /* complain_on_overflow */
552 bfd_elf_generic_reloc
, /* special_function */
553 AARCH64_R_STR (PREL16
), /* name */
554 FALSE
, /* partial_inplace */
555 0xffff, /* src_mask */
556 0xffff, /* dst_mask */
557 TRUE
), /* pcrel_offset */
559 /* Group relocations to create a 16, 32, 48 or 64 bit
560 unsigned data or abs address inline. */
562 /* MOVZ: ((S+A) >> 0) & 0xffff */
563 HOWTO (AARCH64_R (MOVW_UABS_G0
), /* type */
565 2, /* size (0 = byte, 1 = short, 2 = long) */
567 FALSE
, /* pc_relative */
569 complain_overflow_unsigned
, /* complain_on_overflow */
570 bfd_elf_generic_reloc
, /* special_function */
571 AARCH64_R_STR (MOVW_UABS_G0
), /* name */
572 FALSE
, /* partial_inplace */
573 0xffff, /* src_mask */
574 0xffff, /* dst_mask */
575 FALSE
), /* pcrel_offset */
577 /* MOVK: ((S+A) >> 0) & 0xffff [no overflow check] */
578 HOWTO (AARCH64_R (MOVW_UABS_G0_NC
), /* type */
580 2, /* size (0 = byte, 1 = short, 2 = long) */
582 FALSE
, /* pc_relative */
584 complain_overflow_dont
, /* complain_on_overflow */
585 bfd_elf_generic_reloc
, /* special_function */
586 AARCH64_R_STR (MOVW_UABS_G0_NC
), /* name */
587 FALSE
, /* partial_inplace */
588 0xffff, /* src_mask */
589 0xffff, /* dst_mask */
590 FALSE
), /* pcrel_offset */
592 /* MOVZ: ((S+A) >> 16) & 0xffff */
593 HOWTO (AARCH64_R (MOVW_UABS_G1
), /* type */
595 2, /* size (0 = byte, 1 = short, 2 = long) */
597 FALSE
, /* pc_relative */
599 complain_overflow_unsigned
, /* complain_on_overflow */
600 bfd_elf_generic_reloc
, /* special_function */
601 AARCH64_R_STR (MOVW_UABS_G1
), /* name */
602 FALSE
, /* partial_inplace */
603 0xffff, /* src_mask */
604 0xffff, /* dst_mask */
605 FALSE
), /* pcrel_offset */
607 /* MOVK: ((S+A) >> 16) & 0xffff [no overflow check] */
608 HOWTO64 (AARCH64_R (MOVW_UABS_G1_NC
), /* type */
610 2, /* size (0 = byte, 1 = short, 2 = long) */
612 FALSE
, /* pc_relative */
614 complain_overflow_dont
, /* complain_on_overflow */
615 bfd_elf_generic_reloc
, /* special_function */
616 AARCH64_R_STR (MOVW_UABS_G1_NC
), /* name */
617 FALSE
, /* partial_inplace */
618 0xffff, /* src_mask */
619 0xffff, /* dst_mask */
620 FALSE
), /* pcrel_offset */
622 /* MOVZ: ((S+A) >> 32) & 0xffff */
623 HOWTO64 (AARCH64_R (MOVW_UABS_G2
), /* type */
625 2, /* size (0 = byte, 1 = short, 2 = long) */
627 FALSE
, /* pc_relative */
629 complain_overflow_unsigned
, /* complain_on_overflow */
630 bfd_elf_generic_reloc
, /* special_function */
631 AARCH64_R_STR (MOVW_UABS_G2
), /* name */
632 FALSE
, /* partial_inplace */
633 0xffff, /* src_mask */
634 0xffff, /* dst_mask */
635 FALSE
), /* pcrel_offset */
637 /* MOVK: ((S+A) >> 32) & 0xffff [no overflow check] */
638 HOWTO64 (AARCH64_R (MOVW_UABS_G2_NC
), /* type */
640 2, /* size (0 = byte, 1 = short, 2 = long) */
642 FALSE
, /* pc_relative */
644 complain_overflow_dont
, /* complain_on_overflow */
645 bfd_elf_generic_reloc
, /* special_function */
646 AARCH64_R_STR (MOVW_UABS_G2_NC
), /* name */
647 FALSE
, /* partial_inplace */
648 0xffff, /* src_mask */
649 0xffff, /* dst_mask */
650 FALSE
), /* pcrel_offset */
652 /* MOVZ: ((S+A) >> 48) & 0xffff */
653 HOWTO64 (AARCH64_R (MOVW_UABS_G3
), /* type */
655 2, /* size (0 = byte, 1 = short, 2 = long) */
657 FALSE
, /* pc_relative */
659 complain_overflow_unsigned
, /* complain_on_overflow */
660 bfd_elf_generic_reloc
, /* special_function */
661 AARCH64_R_STR (MOVW_UABS_G3
), /* name */
662 FALSE
, /* partial_inplace */
663 0xffff, /* src_mask */
664 0xffff, /* dst_mask */
665 FALSE
), /* pcrel_offset */
667 /* Group relocations to create high part of a 16, 32, 48 or 64 bit
668 signed data or abs address inline. Will change instruction
669 to MOVN or MOVZ depending on sign of calculated value. */
671 /* MOV[ZN]: ((S+A) >> 0) & 0xffff */
672 HOWTO (AARCH64_R (MOVW_SABS_G0
), /* type */
674 2, /* size (0 = byte, 1 = short, 2 = long) */
676 FALSE
, /* pc_relative */
678 complain_overflow_signed
, /* complain_on_overflow */
679 bfd_elf_generic_reloc
, /* special_function */
680 AARCH64_R_STR (MOVW_SABS_G0
), /* name */
681 FALSE
, /* partial_inplace */
682 0xffff, /* src_mask */
683 0xffff, /* dst_mask */
684 FALSE
), /* pcrel_offset */
686 /* MOV[ZN]: ((S+A) >> 16) & 0xffff */
687 HOWTO64 (AARCH64_R (MOVW_SABS_G1
), /* type */
689 2, /* size (0 = byte, 1 = short, 2 = long) */
691 FALSE
, /* pc_relative */
693 complain_overflow_signed
, /* complain_on_overflow */
694 bfd_elf_generic_reloc
, /* special_function */
695 AARCH64_R_STR (MOVW_SABS_G1
), /* name */
696 FALSE
, /* partial_inplace */
697 0xffff, /* src_mask */
698 0xffff, /* dst_mask */
699 FALSE
), /* pcrel_offset */
701 /* MOV[ZN]: ((S+A) >> 32) & 0xffff */
702 HOWTO64 (AARCH64_R (MOVW_SABS_G2
), /* type */
704 2, /* size (0 = byte, 1 = short, 2 = long) */
706 FALSE
, /* pc_relative */
708 complain_overflow_signed
, /* complain_on_overflow */
709 bfd_elf_generic_reloc
, /* special_function */
710 AARCH64_R_STR (MOVW_SABS_G2
), /* name */
711 FALSE
, /* partial_inplace */
712 0xffff, /* src_mask */
713 0xffff, /* dst_mask */
714 FALSE
), /* pcrel_offset */
716 /* Group relocations to create a 16, 32, 48 or 64 bit
717 PC relative address inline. */
719 /* MOV[NZ]: ((S+A-P) >> 0) & 0xffff */
720 HOWTO64 (AARCH64_R (MOVW_PREL_G0
), /* type */
722 2, /* size (0 = byte, 1 = short, 2 = long) */
724 TRUE
, /* pc_relative */
726 complain_overflow_signed
, /* complain_on_overflow */
727 bfd_elf_generic_reloc
, /* special_function */
728 AARCH64_R_STR (MOVW_PREL_G0
), /* name */
729 FALSE
, /* partial_inplace */
730 0xffff, /* src_mask */
731 0xffff, /* dst_mask */
732 TRUE
), /* pcrel_offset */
734 /* MOVK: ((S+A-P) >> 0) & 0xffff [no overflow check] */
735 HOWTO64 (AARCH64_R (MOVW_PREL_G0_NC
), /* type */
737 2, /* size (0 = byte, 1 = short, 2 = long) */
739 TRUE
, /* pc_relative */
741 complain_overflow_dont
, /* complain_on_overflow */
742 bfd_elf_generic_reloc
, /* special_function */
743 AARCH64_R_STR (MOVW_PREL_G0_NC
), /* name */
744 FALSE
, /* partial_inplace */
745 0xffff, /* src_mask */
746 0xffff, /* dst_mask */
747 TRUE
), /* pcrel_offset */
749 /* MOV[NZ]: ((S+A-P) >> 16) & 0xffff */
750 HOWTO64 (AARCH64_R (MOVW_PREL_G1
), /* type */
752 2, /* size (0 = byte, 1 = short, 2 = long) */
754 TRUE
, /* pc_relative */
756 complain_overflow_signed
, /* complain_on_overflow */
757 bfd_elf_generic_reloc
, /* special_function */
758 AARCH64_R_STR (MOVW_PREL_G1
), /* name */
759 FALSE
, /* partial_inplace */
760 0xffff, /* src_mask */
761 0xffff, /* dst_mask */
762 TRUE
), /* pcrel_offset */
764 /* MOVK: ((S+A-P) >> 16) & 0xffff [no overflow check] */
765 HOWTO64 (AARCH64_R (MOVW_PREL_G1_NC
), /* type */
767 2, /* size (0 = byte, 1 = short, 2 = long) */
769 TRUE
, /* pc_relative */
771 complain_overflow_dont
, /* complain_on_overflow */
772 bfd_elf_generic_reloc
, /* special_function */
773 AARCH64_R_STR (MOVW_PREL_G1_NC
), /* name */
774 FALSE
, /* partial_inplace */
775 0xffff, /* src_mask */
776 0xffff, /* dst_mask */
777 TRUE
), /* pcrel_offset */
779 /* MOV[NZ]: ((S+A-P) >> 32) & 0xffff */
780 HOWTO64 (AARCH64_R (MOVW_PREL_G2
), /* type */
782 2, /* size (0 = byte, 1 = short, 2 = long) */
784 TRUE
, /* pc_relative */
786 complain_overflow_signed
, /* complain_on_overflow */
787 bfd_elf_generic_reloc
, /* special_function */
788 AARCH64_R_STR (MOVW_PREL_G2
), /* name */
789 FALSE
, /* partial_inplace */
790 0xffff, /* src_mask */
791 0xffff, /* dst_mask */
792 TRUE
), /* pcrel_offset */
794 /* MOVK: ((S+A-P) >> 32) & 0xffff [no overflow check] */
795 HOWTO64 (AARCH64_R (MOVW_PREL_G2_NC
), /* type */
797 2, /* size (0 = byte, 1 = short, 2 = long) */
799 TRUE
, /* pc_relative */
801 complain_overflow_dont
, /* complain_on_overflow */
802 bfd_elf_generic_reloc
, /* special_function */
803 AARCH64_R_STR (MOVW_PREL_G2_NC
), /* name */
804 FALSE
, /* partial_inplace */
805 0xffff, /* src_mask */
806 0xffff, /* dst_mask */
807 TRUE
), /* pcrel_offset */
809 /* MOV[NZ]: ((S+A-P) >> 48) & 0xffff */
810 HOWTO64 (AARCH64_R (MOVW_PREL_G3
), /* type */
812 2, /* size (0 = byte, 1 = short, 2 = long) */
814 TRUE
, /* pc_relative */
816 complain_overflow_dont
, /* complain_on_overflow */
817 bfd_elf_generic_reloc
, /* special_function */
818 AARCH64_R_STR (MOVW_PREL_G3
), /* name */
819 FALSE
, /* partial_inplace */
820 0xffff, /* src_mask */
821 0xffff, /* dst_mask */
822 TRUE
), /* pcrel_offset */
824 /* Relocations to generate 19, 21 and 33 bit PC-relative load/store
825 addresses: PG(x) is (x & ~0xfff). */
827 /* LD-lit: ((S+A-P) >> 2) & 0x7ffff */
828 HOWTO (AARCH64_R (LD_PREL_LO19
), /* type */
830 2, /* size (0 = byte, 1 = short, 2 = long) */
832 TRUE
, /* pc_relative */
834 complain_overflow_signed
, /* complain_on_overflow */
835 bfd_elf_generic_reloc
, /* special_function */
836 AARCH64_R_STR (LD_PREL_LO19
), /* name */
837 FALSE
, /* partial_inplace */
838 0x7ffff, /* src_mask */
839 0x7ffff, /* dst_mask */
840 TRUE
), /* pcrel_offset */
842 /* ADR: (S+A-P) & 0x1fffff */
843 HOWTO (AARCH64_R (ADR_PREL_LO21
), /* type */
845 2, /* size (0 = byte, 1 = short, 2 = long) */
847 TRUE
, /* pc_relative */
849 complain_overflow_signed
, /* complain_on_overflow */
850 bfd_elf_generic_reloc
, /* special_function */
851 AARCH64_R_STR (ADR_PREL_LO21
), /* name */
852 FALSE
, /* partial_inplace */
853 0x1fffff, /* src_mask */
854 0x1fffff, /* dst_mask */
855 TRUE
), /* pcrel_offset */
857 /* ADRP: ((PG(S+A)-PG(P)) >> 12) & 0x1fffff */
858 HOWTO (AARCH64_R (ADR_PREL_PG_HI21
), /* type */
860 2, /* size (0 = byte, 1 = short, 2 = long) */
862 TRUE
, /* pc_relative */
864 complain_overflow_signed
, /* complain_on_overflow */
865 bfd_elf_generic_reloc
, /* special_function */
866 AARCH64_R_STR (ADR_PREL_PG_HI21
), /* name */
867 FALSE
, /* partial_inplace */
868 0x1fffff, /* src_mask */
869 0x1fffff, /* dst_mask */
870 TRUE
), /* pcrel_offset */
872 /* ADRP: ((PG(S+A)-PG(P)) >> 12) & 0x1fffff [no overflow check] */
873 HOWTO64 (AARCH64_R (ADR_PREL_PG_HI21_NC
), /* type */
875 2, /* size (0 = byte, 1 = short, 2 = long) */
877 TRUE
, /* pc_relative */
879 complain_overflow_dont
, /* complain_on_overflow */
880 bfd_elf_generic_reloc
, /* special_function */
881 AARCH64_R_STR (ADR_PREL_PG_HI21_NC
), /* name */
882 FALSE
, /* partial_inplace */
883 0x1fffff, /* src_mask */
884 0x1fffff, /* dst_mask */
885 TRUE
), /* pcrel_offset */
887 /* ADD: (S+A) & 0xfff [no overflow check] */
888 HOWTO (AARCH64_R (ADD_ABS_LO12_NC
), /* type */
890 2, /* size (0 = byte, 1 = short, 2 = long) */
892 FALSE
, /* pc_relative */
894 complain_overflow_dont
, /* complain_on_overflow */
895 bfd_elf_generic_reloc
, /* special_function */
896 AARCH64_R_STR (ADD_ABS_LO12_NC
), /* name */
897 FALSE
, /* partial_inplace */
898 0x3ffc00, /* src_mask */
899 0x3ffc00, /* dst_mask */
900 FALSE
), /* pcrel_offset */
902 /* LD/ST8: (S+A) & 0xfff */
903 HOWTO (AARCH64_R (LDST8_ABS_LO12_NC
), /* type */
905 2, /* size (0 = byte, 1 = short, 2 = long) */
907 FALSE
, /* pc_relative */
909 complain_overflow_dont
, /* complain_on_overflow */
910 bfd_elf_generic_reloc
, /* special_function */
911 AARCH64_R_STR (LDST8_ABS_LO12_NC
), /* name */
912 FALSE
, /* partial_inplace */
913 0xfff, /* src_mask */
914 0xfff, /* dst_mask */
915 FALSE
), /* pcrel_offset */
917 /* Relocations for control-flow instructions. */
919 /* TBZ/NZ: ((S+A-P) >> 2) & 0x3fff */
920 HOWTO (AARCH64_R (TSTBR14
), /* type */
922 2, /* size (0 = byte, 1 = short, 2 = long) */
924 TRUE
, /* pc_relative */
926 complain_overflow_signed
, /* complain_on_overflow */
927 bfd_elf_generic_reloc
, /* special_function */
928 AARCH64_R_STR (TSTBR14
), /* name */
929 FALSE
, /* partial_inplace */
930 0x3fff, /* src_mask */
931 0x3fff, /* dst_mask */
932 TRUE
), /* pcrel_offset */
934 /* B.cond: ((S+A-P) >> 2) & 0x7ffff */
935 HOWTO (AARCH64_R (CONDBR19
), /* type */
937 2, /* size (0 = byte, 1 = short, 2 = long) */
939 TRUE
, /* pc_relative */
941 complain_overflow_signed
, /* complain_on_overflow */
942 bfd_elf_generic_reloc
, /* special_function */
943 AARCH64_R_STR (CONDBR19
), /* name */
944 FALSE
, /* partial_inplace */
945 0x7ffff, /* src_mask */
946 0x7ffff, /* dst_mask */
947 TRUE
), /* pcrel_offset */
949 /* B: ((S+A-P) >> 2) & 0x3ffffff */
950 HOWTO (AARCH64_R (JUMP26
), /* type */
952 2, /* size (0 = byte, 1 = short, 2 = long) */
954 TRUE
, /* pc_relative */
956 complain_overflow_signed
, /* complain_on_overflow */
957 bfd_elf_generic_reloc
, /* special_function */
958 AARCH64_R_STR (JUMP26
), /* name */
959 FALSE
, /* partial_inplace */
960 0x3ffffff, /* src_mask */
961 0x3ffffff, /* dst_mask */
962 TRUE
), /* pcrel_offset */
964 /* BL: ((S+A-P) >> 2) & 0x3ffffff */
965 HOWTO (AARCH64_R (CALL26
), /* type */
967 2, /* size (0 = byte, 1 = short, 2 = long) */
969 TRUE
, /* pc_relative */
971 complain_overflow_signed
, /* complain_on_overflow */
972 bfd_elf_generic_reloc
, /* special_function */
973 AARCH64_R_STR (CALL26
), /* name */
974 FALSE
, /* partial_inplace */
975 0x3ffffff, /* src_mask */
976 0x3ffffff, /* dst_mask */
977 TRUE
), /* pcrel_offset */
979 /* LD/ST16: (S+A) & 0xffe */
980 HOWTO (AARCH64_R (LDST16_ABS_LO12_NC
), /* type */
982 2, /* size (0 = byte, 1 = short, 2 = long) */
984 FALSE
, /* pc_relative */
986 complain_overflow_dont
, /* complain_on_overflow */
987 bfd_elf_generic_reloc
, /* special_function */
988 AARCH64_R_STR (LDST16_ABS_LO12_NC
), /* name */
989 FALSE
, /* partial_inplace */
990 0xffe, /* src_mask */
991 0xffe, /* dst_mask */
992 FALSE
), /* pcrel_offset */
994 /* LD/ST32: (S+A) & 0xffc */
995 HOWTO (AARCH64_R (LDST32_ABS_LO12_NC
), /* type */
997 2, /* size (0 = byte, 1 = short, 2 = long) */
999 FALSE
, /* pc_relative */
1001 complain_overflow_dont
, /* complain_on_overflow */
1002 bfd_elf_generic_reloc
, /* special_function */
1003 AARCH64_R_STR (LDST32_ABS_LO12_NC
), /* name */
1004 FALSE
, /* partial_inplace */
1005 0xffc, /* src_mask */
1006 0xffc, /* dst_mask */
1007 FALSE
), /* pcrel_offset */
1009 /* LD/ST64: (S+A) & 0xff8 */
1010 HOWTO (AARCH64_R (LDST64_ABS_LO12_NC
), /* type */
1012 2, /* size (0 = byte, 1 = short, 2 = long) */
1014 FALSE
, /* pc_relative */
1016 complain_overflow_dont
, /* complain_on_overflow */
1017 bfd_elf_generic_reloc
, /* special_function */
1018 AARCH64_R_STR (LDST64_ABS_LO12_NC
), /* name */
1019 FALSE
, /* partial_inplace */
1020 0xff8, /* src_mask */
1021 0xff8, /* dst_mask */
1022 FALSE
), /* pcrel_offset */
1024 /* LD/ST128: (S+A) & 0xff0 */
1025 HOWTO (AARCH64_R (LDST128_ABS_LO12_NC
), /* type */
1027 2, /* size (0 = byte, 1 = short, 2 = long) */
1029 FALSE
, /* pc_relative */
1031 complain_overflow_dont
, /* complain_on_overflow */
1032 bfd_elf_generic_reloc
, /* special_function */
1033 AARCH64_R_STR (LDST128_ABS_LO12_NC
), /* name */
1034 FALSE
, /* partial_inplace */
1035 0xff0, /* src_mask */
1036 0xff0, /* dst_mask */
1037 FALSE
), /* pcrel_offset */
1039 /* Set a load-literal immediate field to bits
1040 0x1FFFFC of G(S)-P */
1041 HOWTO (AARCH64_R (GOT_LD_PREL19
), /* type */
1043 2, /* size (0 = byte,1 = short,2 = long) */
1045 TRUE
, /* pc_relative */
1047 complain_overflow_signed
, /* complain_on_overflow */
1048 bfd_elf_generic_reloc
, /* special_function */
1049 AARCH64_R_STR (GOT_LD_PREL19
), /* name */
1050 FALSE
, /* partial_inplace */
1051 0xffffe0, /* src_mask */
1052 0xffffe0, /* dst_mask */
1053 TRUE
), /* pcrel_offset */
1055 /* Get to the page for the GOT entry for the symbol
1056 (G(S) - P) using an ADRP instruction. */
1057 HOWTO (AARCH64_R (ADR_GOT_PAGE
), /* type */
1058 12, /* rightshift */
1059 2, /* size (0 = byte, 1 = short, 2 = long) */
1061 TRUE
, /* pc_relative */
1063 complain_overflow_dont
, /* complain_on_overflow */
1064 bfd_elf_generic_reloc
, /* special_function */
1065 AARCH64_R_STR (ADR_GOT_PAGE
), /* name */
1066 FALSE
, /* partial_inplace */
1067 0x1fffff, /* src_mask */
1068 0x1fffff, /* dst_mask */
1069 TRUE
), /* pcrel_offset */
1071 /* LD64: GOT offset G(S) & 0xff8 */
1072 HOWTO64 (AARCH64_R (LD64_GOT_LO12_NC
), /* type */
1074 2, /* size (0 = byte, 1 = short, 2 = long) */
1076 FALSE
, /* pc_relative */
1078 complain_overflow_dont
, /* complain_on_overflow */
1079 bfd_elf_generic_reloc
, /* special_function */
1080 AARCH64_R_STR (LD64_GOT_LO12_NC
), /* name */
1081 FALSE
, /* partial_inplace */
1082 0xff8, /* src_mask */
1083 0xff8, /* dst_mask */
1084 FALSE
), /* pcrel_offset */
1086 /* LD32: GOT offset G(S) & 0xffc */
1087 HOWTO32 (AARCH64_R (LD32_GOT_LO12_NC
), /* type */
1089 2, /* size (0 = byte, 1 = short, 2 = long) */
1091 FALSE
, /* pc_relative */
1093 complain_overflow_dont
, /* complain_on_overflow */
1094 bfd_elf_generic_reloc
, /* special_function */
1095 AARCH64_R_STR (LD32_GOT_LO12_NC
), /* name */
1096 FALSE
, /* partial_inplace */
1097 0xffc, /* src_mask */
1098 0xffc, /* dst_mask */
1099 FALSE
), /* pcrel_offset */
1101 /* Lower 16 bits of GOT offset for the symbol. */
1102 HOWTO64 (AARCH64_R (MOVW_GOTOFF_G0_NC
), /* type */
1104 2, /* size (0 = byte, 1 = short, 2 = long) */
1106 FALSE
, /* pc_relative */
1108 complain_overflow_dont
, /* complain_on_overflow */
1109 bfd_elf_generic_reloc
, /* special_function */
1110 AARCH64_R_STR (MOVW_GOTOFF_G0_NC
), /* name */
1111 FALSE
, /* partial_inplace */
1112 0xffff, /* src_mask */
1113 0xffff, /* dst_mask */
1114 FALSE
), /* pcrel_offset */
1116 /* Higher 16 bits of GOT offset for the symbol. */
1117 HOWTO64 (AARCH64_R (MOVW_GOTOFF_G1
), /* type */
1118 16, /* rightshift */
1119 2, /* size (0 = byte, 1 = short, 2 = long) */
1121 FALSE
, /* pc_relative */
1123 complain_overflow_unsigned
, /* complain_on_overflow */
1124 bfd_elf_generic_reloc
, /* special_function */
1125 AARCH64_R_STR (MOVW_GOTOFF_G1
), /* name */
1126 FALSE
, /* partial_inplace */
1127 0xffff, /* src_mask */
1128 0xffff, /* dst_mask */
1129 FALSE
), /* pcrel_offset */
1131 /* LD64: GOT offset for the symbol. */
1132 HOWTO64 (AARCH64_R (LD64_GOTOFF_LO15
), /* type */
1134 2, /* size (0 = byte, 1 = short, 2 = long) */
1136 FALSE
, /* pc_relative */
1138 complain_overflow_unsigned
, /* complain_on_overflow */
1139 bfd_elf_generic_reloc
, /* special_function */
1140 AARCH64_R_STR (LD64_GOTOFF_LO15
), /* name */
1141 FALSE
, /* partial_inplace */
1142 0x7ff8, /* src_mask */
1143 0x7ff8, /* dst_mask */
1144 FALSE
), /* pcrel_offset */
1146 /* LD32: GOT offset to the page address of GOT table.
1147 (G(S) - PAGE (_GLOBAL_OFFSET_TABLE_)) & 0x5ffc. */
1148 HOWTO32 (AARCH64_R (LD32_GOTPAGE_LO14
), /* type */
1150 2, /* size (0 = byte, 1 = short, 2 = long) */
1152 FALSE
, /* pc_relative */
1154 complain_overflow_unsigned
, /* complain_on_overflow */
1155 bfd_elf_generic_reloc
, /* special_function */
1156 AARCH64_R_STR (LD32_GOTPAGE_LO14
), /* name */
1157 FALSE
, /* partial_inplace */
1158 0x5ffc, /* src_mask */
1159 0x5ffc, /* dst_mask */
1160 FALSE
), /* pcrel_offset */
1162 /* LD64: GOT offset to the page address of GOT table.
1163 (G(S) - PAGE (_GLOBAL_OFFSET_TABLE_)) & 0x7ff8. */
1164 HOWTO64 (AARCH64_R (LD64_GOTPAGE_LO15
), /* type */
1166 2, /* size (0 = byte, 1 = short, 2 = long) */
1168 FALSE
, /* pc_relative */
1170 complain_overflow_unsigned
, /* complain_on_overflow */
1171 bfd_elf_generic_reloc
, /* special_function */
1172 AARCH64_R_STR (LD64_GOTPAGE_LO15
), /* name */
1173 FALSE
, /* partial_inplace */
1174 0x7ff8, /* src_mask */
1175 0x7ff8, /* dst_mask */
1176 FALSE
), /* pcrel_offset */
1178 /* Get to the page for the GOT entry for the symbol
1179 (G(S) - P) using an ADRP instruction. */
1180 HOWTO (AARCH64_R (TLSGD_ADR_PAGE21
), /* type */
1181 12, /* rightshift */
1182 2, /* size (0 = byte, 1 = short, 2 = long) */
1184 TRUE
, /* pc_relative */
1186 complain_overflow_dont
, /* complain_on_overflow */
1187 bfd_elf_generic_reloc
, /* special_function */
1188 AARCH64_R_STR (TLSGD_ADR_PAGE21
), /* name */
1189 FALSE
, /* partial_inplace */
1190 0x1fffff, /* src_mask */
1191 0x1fffff, /* dst_mask */
1192 TRUE
), /* pcrel_offset */
1194 HOWTO (AARCH64_R (TLSGD_ADR_PREL21
), /* type */
1196 2, /* size (0 = byte, 1 = short, 2 = long) */
1198 TRUE
, /* pc_relative */
1200 complain_overflow_dont
, /* complain_on_overflow */
1201 bfd_elf_generic_reloc
, /* special_function */
1202 AARCH64_R_STR (TLSGD_ADR_PREL21
), /* name */
1203 FALSE
, /* partial_inplace */
1204 0x1fffff, /* src_mask */
1205 0x1fffff, /* dst_mask */
1206 TRUE
), /* pcrel_offset */
1208 /* ADD: GOT offset G(S) & 0xff8 [no overflow check] */
1209 HOWTO (AARCH64_R (TLSGD_ADD_LO12_NC
), /* type */
1211 2, /* size (0 = byte, 1 = short, 2 = long) */
1213 FALSE
, /* pc_relative */
1215 complain_overflow_dont
, /* complain_on_overflow */
1216 bfd_elf_generic_reloc
, /* special_function */
1217 AARCH64_R_STR (TLSGD_ADD_LO12_NC
), /* name */
1218 FALSE
, /* partial_inplace */
1219 0xfff, /* src_mask */
1220 0xfff, /* dst_mask */
1221 FALSE
), /* pcrel_offset */
1223 /* Lower 16 bits of GOT offset to tls_index. */
1224 HOWTO64 (AARCH64_R (TLSGD_MOVW_G0_NC
), /* type */
1226 2, /* size (0 = byte, 1 = short, 2 = long) */
1228 FALSE
, /* pc_relative */
1230 complain_overflow_dont
, /* complain_on_overflow */
1231 bfd_elf_generic_reloc
, /* special_function */
1232 AARCH64_R_STR (TLSGD_MOVW_G0_NC
), /* name */
1233 FALSE
, /* partial_inplace */
1234 0xffff, /* src_mask */
1235 0xffff, /* dst_mask */
1236 FALSE
), /* pcrel_offset */
1238 /* Higher 16 bits of GOT offset to tls_index. */
1239 HOWTO64 (AARCH64_R (TLSGD_MOVW_G1
), /* type */
1240 16, /* rightshift */
1241 2, /* size (0 = byte, 1 = short, 2 = long) */
1243 FALSE
, /* pc_relative */
1245 complain_overflow_unsigned
, /* complain_on_overflow */
1246 bfd_elf_generic_reloc
, /* special_function */
1247 AARCH64_R_STR (TLSGD_MOVW_G1
), /* name */
1248 FALSE
, /* partial_inplace */
1249 0xffff, /* src_mask */
1250 0xffff, /* dst_mask */
1251 FALSE
), /* pcrel_offset */
1253 HOWTO (AARCH64_R (TLSIE_ADR_GOTTPREL_PAGE21
), /* type */
1254 12, /* rightshift */
1255 2, /* size (0 = byte, 1 = short, 2 = long) */
1257 FALSE
, /* pc_relative */
1259 complain_overflow_dont
, /* complain_on_overflow */
1260 bfd_elf_generic_reloc
, /* special_function */
1261 AARCH64_R_STR (TLSIE_ADR_GOTTPREL_PAGE21
), /* name */
1262 FALSE
, /* partial_inplace */
1263 0x1fffff, /* src_mask */
1264 0x1fffff, /* dst_mask */
1265 FALSE
), /* pcrel_offset */
1267 HOWTO64 (AARCH64_R (TLSIE_LD64_GOTTPREL_LO12_NC
), /* type */
1269 2, /* size (0 = byte, 1 = short, 2 = long) */
1271 FALSE
, /* pc_relative */
1273 complain_overflow_dont
, /* complain_on_overflow */
1274 bfd_elf_generic_reloc
, /* special_function */
1275 AARCH64_R_STR (TLSIE_LD64_GOTTPREL_LO12_NC
), /* name */
1276 FALSE
, /* partial_inplace */
1277 0xff8, /* src_mask */
1278 0xff8, /* dst_mask */
1279 FALSE
), /* pcrel_offset */
1281 HOWTO32 (AARCH64_R (TLSIE_LD32_GOTTPREL_LO12_NC
), /* type */
1283 2, /* size (0 = byte, 1 = short, 2 = long) */
1285 FALSE
, /* pc_relative */
1287 complain_overflow_dont
, /* complain_on_overflow */
1288 bfd_elf_generic_reloc
, /* special_function */
1289 AARCH64_R_STR (TLSIE_LD32_GOTTPREL_LO12_NC
), /* name */
1290 FALSE
, /* partial_inplace */
1291 0xffc, /* src_mask */
1292 0xffc, /* dst_mask */
1293 FALSE
), /* pcrel_offset */
1295 HOWTO (AARCH64_R (TLSIE_LD_GOTTPREL_PREL19
), /* type */
1297 2, /* size (0 = byte, 1 = short, 2 = long) */
1299 FALSE
, /* pc_relative */
1301 complain_overflow_dont
, /* complain_on_overflow */
1302 bfd_elf_generic_reloc
, /* special_function */
1303 AARCH64_R_STR (TLSIE_LD_GOTTPREL_PREL19
), /* name */
1304 FALSE
, /* partial_inplace */
1305 0x1ffffc, /* src_mask */
1306 0x1ffffc, /* dst_mask */
1307 FALSE
), /* pcrel_offset */
1309 HOWTO64 (AARCH64_R (TLSIE_MOVW_GOTTPREL_G0_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_MOVW_GOTTPREL_G0_NC
), /* name */
1318 FALSE
, /* partial_inplace */
1319 0xffff, /* src_mask */
1320 0xffff, /* dst_mask */
1321 FALSE
), /* pcrel_offset */
1323 HOWTO64 (AARCH64_R (TLSIE_MOVW_GOTTPREL_G1
), /* type */
1324 16, /* rightshift */
1325 2, /* size (0 = byte, 1 = short, 2 = long) */
1327 FALSE
, /* pc_relative */
1329 complain_overflow_unsigned
, /* complain_on_overflow */
1330 bfd_elf_generic_reloc
, /* special_function */
1331 AARCH64_R_STR (TLSIE_MOVW_GOTTPREL_G1
), /* name */
1332 FALSE
, /* partial_inplace */
1333 0xffff, /* src_mask */
1334 0xffff, /* dst_mask */
1335 FALSE
), /* pcrel_offset */
1337 /* ADD: bit[23:12] of byte offset to module TLS base address. */
1338 HOWTO (AARCH64_R (TLSLD_ADD_DTPREL_HI12
), /* type */
1339 12, /* rightshift */
1340 2, /* size (0 = byte, 1 = short, 2 = long) */
1342 FALSE
, /* pc_relative */
1344 complain_overflow_unsigned
, /* complain_on_overflow */
1345 bfd_elf_generic_reloc
, /* special_function */
1346 AARCH64_R_STR (TLSLD_ADD_DTPREL_HI12
), /* name */
1347 FALSE
, /* partial_inplace */
1348 0xfff, /* src_mask */
1349 0xfff, /* dst_mask */
1350 FALSE
), /* pcrel_offset */
1352 /* Unsigned 12 bit byte offset to module TLS base address. */
1353 HOWTO (AARCH64_R (TLSLD_ADD_DTPREL_LO12
), /* type */
1355 2, /* size (0 = byte, 1 = short, 2 = long) */
1357 FALSE
, /* pc_relative */
1359 complain_overflow_unsigned
, /* complain_on_overflow */
1360 bfd_elf_generic_reloc
, /* special_function */
1361 AARCH64_R_STR (TLSLD_ADD_DTPREL_LO12
), /* name */
1362 FALSE
, /* partial_inplace */
1363 0xfff, /* src_mask */
1364 0xfff, /* dst_mask */
1365 FALSE
), /* pcrel_offset */
1367 /* No overflow check version of BFD_RELOC_AARCH64_TLSLD_ADD_DTPREL_LO12. */
1368 HOWTO (AARCH64_R (TLSLD_ADD_DTPREL_LO12_NC
), /* type */
1370 2, /* size (0 = byte, 1 = short, 2 = long) */
1372 FALSE
, /* pc_relative */
1374 complain_overflow_dont
, /* complain_on_overflow */
1375 bfd_elf_generic_reloc
, /* special_function */
1376 AARCH64_R_STR (TLSLD_ADD_DTPREL_LO12_NC
), /* name */
1377 FALSE
, /* partial_inplace */
1378 0xfff, /* src_mask */
1379 0xfff, /* dst_mask */
1380 FALSE
), /* pcrel_offset */
1382 /* ADD: GOT offset G(S) & 0xff8 [no overflow check] */
1383 HOWTO (AARCH64_R (TLSLD_ADD_LO12_NC
), /* type */
1385 2, /* size (0 = byte, 1 = short, 2 = long) */
1387 FALSE
, /* pc_relative */
1389 complain_overflow_dont
, /* complain_on_overflow */
1390 bfd_elf_generic_reloc
, /* special_function */
1391 AARCH64_R_STR (TLSLD_ADD_LO12_NC
), /* name */
1392 FALSE
, /* partial_inplace */
1393 0xfff, /* src_mask */
1394 0xfff, /* dst_mask */
1395 FALSE
), /* pcrel_offset */
1397 /* Get to the page for the GOT entry for the symbol
1398 (G(S) - P) using an ADRP instruction. */
1399 HOWTO (AARCH64_R (TLSLD_ADR_PAGE21
), /* type */
1400 12, /* rightshift */
1401 2, /* size (0 = byte, 1 = short, 2 = long) */
1403 TRUE
, /* pc_relative */
1405 complain_overflow_signed
, /* complain_on_overflow */
1406 bfd_elf_generic_reloc
, /* special_function */
1407 AARCH64_R_STR (TLSLD_ADR_PAGE21
), /* name */
1408 FALSE
, /* partial_inplace */
1409 0x1fffff, /* src_mask */
1410 0x1fffff, /* dst_mask */
1411 TRUE
), /* pcrel_offset */
1413 HOWTO (AARCH64_R (TLSLD_ADR_PREL21
), /* type */
1415 2, /* size (0 = byte, 1 = short, 2 = long) */
1417 TRUE
, /* pc_relative */
1419 complain_overflow_signed
, /* complain_on_overflow */
1420 bfd_elf_generic_reloc
, /* special_function */
1421 AARCH64_R_STR (TLSLD_ADR_PREL21
), /* name */
1422 FALSE
, /* partial_inplace */
1423 0x1fffff, /* src_mask */
1424 0x1fffff, /* dst_mask */
1425 TRUE
), /* pcrel_offset */
1427 /* LD/ST16: bit[11:1] of byte offset to module TLS base address. */
1428 HOWTO64 (AARCH64_R (TLSLD_LDST16_DTPREL_LO12
), /* type */
1430 2, /* size (0 = byte, 1 = short, 2 = long) */
1432 FALSE
, /* pc_relative */
1434 complain_overflow_unsigned
, /* complain_on_overflow */
1435 bfd_elf_generic_reloc
, /* special_function */
1436 AARCH64_R_STR (TLSLD_LDST16_DTPREL_LO12
), /* name */
1437 FALSE
, /* partial_inplace */
1438 0x1ffc00, /* src_mask */
1439 0x1ffc00, /* dst_mask */
1440 FALSE
), /* pcrel_offset */
1442 /* Same as BFD_RELOC_AARCH64_TLSLD_LDST16_DTPREL_LO12, but no overflow check. */
1443 HOWTO64 (AARCH64_R (TLSLD_LDST16_DTPREL_LO12_NC
), /* type */
1445 2, /* size (0 = byte, 1 = short, 2 = long) */
1447 FALSE
, /* pc_relative */
1449 complain_overflow_dont
, /* complain_on_overflow */
1450 bfd_elf_generic_reloc
, /* special_function */
1451 AARCH64_R_STR (TLSLD_LDST16_DTPREL_LO12_NC
), /* name */
1452 FALSE
, /* partial_inplace */
1453 0x1ffc00, /* src_mask */
1454 0x1ffc00, /* dst_mask */
1455 FALSE
), /* pcrel_offset */
1457 /* LD/ST32: bit[11:2] of byte offset to module TLS base address. */
1458 HOWTO64 (AARCH64_R (TLSLD_LDST32_DTPREL_LO12
), /* type */
1460 2, /* size (0 = byte, 1 = short, 2 = long) */
1462 FALSE
, /* pc_relative */
1464 complain_overflow_unsigned
, /* complain_on_overflow */
1465 bfd_elf_generic_reloc
, /* special_function */
1466 AARCH64_R_STR (TLSLD_LDST32_DTPREL_LO12
), /* name */
1467 FALSE
, /* partial_inplace */
1468 0x3ffc00, /* src_mask */
1469 0x3ffc00, /* dst_mask */
1470 FALSE
), /* pcrel_offset */
1472 /* Same as BFD_RELOC_AARCH64_TLSLD_LDST32_DTPREL_LO12, but no overflow check. */
1473 HOWTO64 (AARCH64_R (TLSLD_LDST32_DTPREL_LO12_NC
), /* type */
1475 2, /* size (0 = byte, 1 = short, 2 = long) */
1477 FALSE
, /* pc_relative */
1479 complain_overflow_dont
, /* complain_on_overflow */
1480 bfd_elf_generic_reloc
, /* special_function */
1481 AARCH64_R_STR (TLSLD_LDST32_DTPREL_LO12_NC
), /* name */
1482 FALSE
, /* partial_inplace */
1483 0xffc00, /* src_mask */
1484 0xffc00, /* dst_mask */
1485 FALSE
), /* pcrel_offset */
1487 /* LD/ST64: bit[11:3] of byte offset to module TLS base address. */
1488 HOWTO64 (AARCH64_R (TLSLD_LDST64_DTPREL_LO12
), /* type */
1490 2, /* size (0 = byte, 1 = short, 2 = long) */
1492 FALSE
, /* pc_relative */
1494 complain_overflow_unsigned
, /* complain_on_overflow */
1495 bfd_elf_generic_reloc
, /* special_function */
1496 AARCH64_R_STR (TLSLD_LDST64_DTPREL_LO12
), /* name */
1497 FALSE
, /* partial_inplace */
1498 0x3ffc00, /* src_mask */
1499 0x3ffc00, /* dst_mask */
1500 FALSE
), /* pcrel_offset */
1502 /* Same as BFD_RELOC_AARCH64_TLSLD_LDST64_DTPREL_LO12, but no overflow check. */
1503 HOWTO64 (AARCH64_R (TLSLD_LDST64_DTPREL_LO12_NC
), /* type */
1505 2, /* size (0 = byte, 1 = short, 2 = long) */
1507 FALSE
, /* pc_relative */
1509 complain_overflow_dont
, /* complain_on_overflow */
1510 bfd_elf_generic_reloc
, /* special_function */
1511 AARCH64_R_STR (TLSLD_LDST64_DTPREL_LO12_NC
), /* name */
1512 FALSE
, /* partial_inplace */
1513 0x7fc00, /* src_mask */
1514 0x7fc00, /* dst_mask */
1515 FALSE
), /* pcrel_offset */
1517 /* LD/ST8: bit[11:0] of byte offset to module TLS base address. */
1518 HOWTO64 (AARCH64_R (TLSLD_LDST8_DTPREL_LO12
), /* type */
1520 2, /* size (0 = byte, 1 = short, 2 = long) */
1522 FALSE
, /* pc_relative */
1524 complain_overflow_unsigned
, /* complain_on_overflow */
1525 bfd_elf_generic_reloc
, /* special_function */
1526 AARCH64_R_STR (TLSLD_LDST8_DTPREL_LO12
), /* name */
1527 FALSE
, /* partial_inplace */
1528 0x3ffc00, /* src_mask */
1529 0x3ffc00, /* dst_mask */
1530 FALSE
), /* pcrel_offset */
1532 /* Same as BFD_RELOC_AARCH64_TLSLD_LDST8_DTPREL_LO12, but no overflow check. */
1533 HOWTO64 (AARCH64_R (TLSLD_LDST8_DTPREL_LO12_NC
), /* type */
1535 2, /* size (0 = byte, 1 = short, 2 = long) */
1537 FALSE
, /* pc_relative */
1539 complain_overflow_dont
, /* complain_on_overflow */
1540 bfd_elf_generic_reloc
, /* special_function */
1541 AARCH64_R_STR (TLSLD_LDST8_DTPREL_LO12_NC
), /* name */
1542 FALSE
, /* partial_inplace */
1543 0x3ffc00, /* src_mask */
1544 0x3ffc00, /* dst_mask */
1545 FALSE
), /* pcrel_offset */
1547 /* MOVZ: bit[15:0] of byte offset to module TLS base address. */
1548 HOWTO (AARCH64_R (TLSLD_MOVW_DTPREL_G0
), /* type */
1550 2, /* size (0 = byte, 1 = short, 2 = long) */
1552 FALSE
, /* pc_relative */
1554 complain_overflow_unsigned
, /* complain_on_overflow */
1555 bfd_elf_generic_reloc
, /* special_function */
1556 AARCH64_R_STR (TLSLD_MOVW_DTPREL_G0
), /* name */
1557 FALSE
, /* partial_inplace */
1558 0xffff, /* src_mask */
1559 0xffff, /* dst_mask */
1560 FALSE
), /* pcrel_offset */
1562 /* No overflow check version of BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G0. */
1563 HOWTO (AARCH64_R (TLSLD_MOVW_DTPREL_G0_NC
), /* type */
1565 2, /* size (0 = byte, 1 = short, 2 = long) */
1567 FALSE
, /* pc_relative */
1569 complain_overflow_dont
, /* complain_on_overflow */
1570 bfd_elf_generic_reloc
, /* special_function */
1571 AARCH64_R_STR (TLSLD_MOVW_DTPREL_G0_NC
), /* name */
1572 FALSE
, /* partial_inplace */
1573 0xffff, /* src_mask */
1574 0xffff, /* dst_mask */
1575 FALSE
), /* pcrel_offset */
1577 /* MOVZ: bit[31:16] of byte offset to module TLS base address. */
1578 HOWTO (AARCH64_R (TLSLD_MOVW_DTPREL_G1
), /* type */
1579 16, /* rightshift */
1580 2, /* size (0 = byte, 1 = short, 2 = long) */
1582 FALSE
, /* pc_relative */
1584 complain_overflow_unsigned
, /* complain_on_overflow */
1585 bfd_elf_generic_reloc
, /* special_function */
1586 AARCH64_R_STR (TLSLD_MOVW_DTPREL_G1
), /* name */
1587 FALSE
, /* partial_inplace */
1588 0xffff, /* src_mask */
1589 0xffff, /* dst_mask */
1590 FALSE
), /* pcrel_offset */
1592 /* No overflow check version of BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G1. */
1593 HOWTO64 (AARCH64_R (TLSLD_MOVW_DTPREL_G1_NC
), /* type */
1594 16, /* rightshift */
1595 2, /* size (0 = byte, 1 = short, 2 = long) */
1597 FALSE
, /* pc_relative */
1599 complain_overflow_dont
, /* complain_on_overflow */
1600 bfd_elf_generic_reloc
, /* special_function */
1601 AARCH64_R_STR (TLSLD_MOVW_DTPREL_G1_NC
), /* name */
1602 FALSE
, /* partial_inplace */
1603 0xffff, /* src_mask */
1604 0xffff, /* dst_mask */
1605 FALSE
), /* pcrel_offset */
1607 /* MOVZ: bit[47:32] of byte offset to module TLS base address. */
1608 HOWTO64 (AARCH64_R (TLSLD_MOVW_DTPREL_G2
), /* type */
1609 32, /* rightshift */
1610 2, /* size (0 = byte, 1 = short, 2 = long) */
1612 FALSE
, /* pc_relative */
1614 complain_overflow_unsigned
, /* complain_on_overflow */
1615 bfd_elf_generic_reloc
, /* special_function */
1616 AARCH64_R_STR (TLSLD_MOVW_DTPREL_G2
), /* name */
1617 FALSE
, /* partial_inplace */
1618 0xffff, /* src_mask */
1619 0xffff, /* dst_mask */
1620 FALSE
), /* pcrel_offset */
1622 HOWTO64 (AARCH64_R (TLSLE_MOVW_TPREL_G2
), /* type */
1623 32, /* rightshift */
1624 2, /* size (0 = byte, 1 = short, 2 = long) */
1626 FALSE
, /* pc_relative */
1628 complain_overflow_unsigned
, /* complain_on_overflow */
1629 bfd_elf_generic_reloc
, /* special_function */
1630 AARCH64_R_STR (TLSLE_MOVW_TPREL_G2
), /* name */
1631 FALSE
, /* partial_inplace */
1632 0xffff, /* src_mask */
1633 0xffff, /* dst_mask */
1634 FALSE
), /* pcrel_offset */
1636 HOWTO (AARCH64_R (TLSLE_MOVW_TPREL_G1
), /* type */
1637 16, /* rightshift */
1638 2, /* size (0 = byte, 1 = short, 2 = long) */
1640 FALSE
, /* pc_relative */
1642 complain_overflow_dont
, /* complain_on_overflow */
1643 bfd_elf_generic_reloc
, /* special_function */
1644 AARCH64_R_STR (TLSLE_MOVW_TPREL_G1
), /* name */
1645 FALSE
, /* partial_inplace */
1646 0xffff, /* src_mask */
1647 0xffff, /* dst_mask */
1648 FALSE
), /* pcrel_offset */
1650 HOWTO64 (AARCH64_R (TLSLE_MOVW_TPREL_G1_NC
), /* type */
1651 16, /* rightshift */
1652 2, /* size (0 = byte, 1 = short, 2 = long) */
1654 FALSE
, /* pc_relative */
1656 complain_overflow_dont
, /* complain_on_overflow */
1657 bfd_elf_generic_reloc
, /* special_function */
1658 AARCH64_R_STR (TLSLE_MOVW_TPREL_G1_NC
), /* name */
1659 FALSE
, /* partial_inplace */
1660 0xffff, /* src_mask */
1661 0xffff, /* dst_mask */
1662 FALSE
), /* pcrel_offset */
1664 HOWTO (AARCH64_R (TLSLE_MOVW_TPREL_G0
), /* type */
1666 2, /* size (0 = byte, 1 = short, 2 = long) */
1668 FALSE
, /* pc_relative */
1670 complain_overflow_dont
, /* complain_on_overflow */
1671 bfd_elf_generic_reloc
, /* special_function */
1672 AARCH64_R_STR (TLSLE_MOVW_TPREL_G0
), /* name */
1673 FALSE
, /* partial_inplace */
1674 0xffff, /* src_mask */
1675 0xffff, /* dst_mask */
1676 FALSE
), /* pcrel_offset */
1678 HOWTO (AARCH64_R (TLSLE_MOVW_TPREL_G0_NC
), /* type */
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_G0_NC
), /* name */
1687 FALSE
, /* partial_inplace */
1688 0xffff, /* src_mask */
1689 0xffff, /* dst_mask */
1690 FALSE
), /* pcrel_offset */
1692 HOWTO (AARCH64_R (TLSLE_ADD_TPREL_HI12
), /* type */
1693 12, /* rightshift */
1694 2, /* size (0 = byte, 1 = short, 2 = long) */
1696 FALSE
, /* pc_relative */
1698 complain_overflow_unsigned
, /* complain_on_overflow */
1699 bfd_elf_generic_reloc
, /* special_function */
1700 AARCH64_R_STR (TLSLE_ADD_TPREL_HI12
), /* name */
1701 FALSE
, /* partial_inplace */
1702 0xfff, /* src_mask */
1703 0xfff, /* dst_mask */
1704 FALSE
), /* pcrel_offset */
1706 HOWTO (AARCH64_R (TLSLE_ADD_TPREL_LO12
), /* type */
1708 2, /* size (0 = byte, 1 = short, 2 = long) */
1710 FALSE
, /* pc_relative */
1712 complain_overflow_unsigned
, /* complain_on_overflow */
1713 bfd_elf_generic_reloc
, /* special_function */
1714 AARCH64_R_STR (TLSLE_ADD_TPREL_LO12
), /* name */
1715 FALSE
, /* partial_inplace */
1716 0xfff, /* src_mask */
1717 0xfff, /* dst_mask */
1718 FALSE
), /* pcrel_offset */
1720 HOWTO (AARCH64_R (TLSLE_ADD_TPREL_LO12_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_ADD_TPREL_LO12_NC
), /* name */
1729 FALSE
, /* partial_inplace */
1730 0xfff, /* src_mask */
1731 0xfff, /* dst_mask */
1732 FALSE
), /* pcrel_offset */
1734 /* LD/ST16: bit[11:1] of byte offset to module TLS base address. */
1735 HOWTO (AARCH64_R (TLSLE_LDST16_TPREL_LO12
), /* type */
1737 2, /* size (0 = byte, 1 = short, 2 = long) */
1739 FALSE
, /* pc_relative */
1741 complain_overflow_unsigned
, /* complain_on_overflow */
1742 bfd_elf_generic_reloc
, /* special_function */
1743 AARCH64_R_STR (TLSLE_LDST16_TPREL_LO12
), /* name */
1744 FALSE
, /* partial_inplace */
1745 0x1ffc00, /* src_mask */
1746 0x1ffc00, /* dst_mask */
1747 FALSE
), /* pcrel_offset */
1749 /* Same as BFD_RELOC_AARCH64_TLSLE_LDST16_TPREL_LO12, but no overflow check. */
1750 HOWTO (AARCH64_R (TLSLE_LDST16_TPREL_LO12_NC
), /* type */
1752 2, /* size (0 = byte, 1 = short, 2 = long) */
1754 FALSE
, /* pc_relative */
1756 complain_overflow_dont
, /* complain_on_overflow */
1757 bfd_elf_generic_reloc
, /* special_function */
1758 AARCH64_R_STR (TLSLE_LDST16_TPREL_LO12_NC
), /* name */
1759 FALSE
, /* partial_inplace */
1760 0x1ffc00, /* src_mask */
1761 0x1ffc00, /* dst_mask */
1762 FALSE
), /* pcrel_offset */
1764 /* LD/ST32: bit[11:2] of byte offset to module TLS base address. */
1765 HOWTO (AARCH64_R (TLSLE_LDST32_TPREL_LO12
), /* type */
1767 2, /* size (0 = byte, 1 = short, 2 = long) */
1769 FALSE
, /* pc_relative */
1771 complain_overflow_unsigned
, /* complain_on_overflow */
1772 bfd_elf_generic_reloc
, /* special_function */
1773 AARCH64_R_STR (TLSLE_LDST32_TPREL_LO12
), /* name */
1774 FALSE
, /* partial_inplace */
1775 0xffc00, /* src_mask */
1776 0xffc00, /* dst_mask */
1777 FALSE
), /* pcrel_offset */
1779 /* Same as BFD_RELOC_AARCH64_TLSLE_LDST32_TPREL_LO12, but no overflow check. */
1780 HOWTO (AARCH64_R (TLSLE_LDST32_TPREL_LO12_NC
), /* type */
1782 2, /* size (0 = byte, 1 = short, 2 = long) */
1784 FALSE
, /* pc_relative */
1786 complain_overflow_dont
, /* complain_on_overflow */
1787 bfd_elf_generic_reloc
, /* special_function */
1788 AARCH64_R_STR (TLSLE_LDST32_TPREL_LO12_NC
), /* name */
1789 FALSE
, /* partial_inplace */
1790 0xffc00, /* src_mask */
1791 0xffc00, /* dst_mask */
1792 FALSE
), /* pcrel_offset */
1794 /* LD/ST64: bit[11:3] of byte offset to module TLS base address. */
1795 HOWTO (AARCH64_R (TLSLE_LDST64_TPREL_LO12
), /* type */
1797 2, /* size (0 = byte, 1 = short, 2 = long) */
1799 FALSE
, /* pc_relative */
1801 complain_overflow_unsigned
, /* complain_on_overflow */
1802 bfd_elf_generic_reloc
, /* special_function */
1803 AARCH64_R_STR (TLSLE_LDST64_TPREL_LO12
), /* name */
1804 FALSE
, /* partial_inplace */
1805 0x7fc00, /* src_mask */
1806 0x7fc00, /* dst_mask */
1807 FALSE
), /* pcrel_offset */
1809 /* Same as BFD_RELOC_AARCH64_TLSLE_LDST64_TPREL_LO12, but no overflow check. */
1810 HOWTO (AARCH64_R (TLSLE_LDST64_TPREL_LO12_NC
), /* type */
1812 2, /* size (0 = byte, 1 = short, 2 = long) */
1814 FALSE
, /* pc_relative */
1816 complain_overflow_dont
, /* complain_on_overflow */
1817 bfd_elf_generic_reloc
, /* special_function */
1818 AARCH64_R_STR (TLSLE_LDST64_TPREL_LO12_NC
), /* name */
1819 FALSE
, /* partial_inplace */
1820 0x7fc00, /* src_mask */
1821 0x7fc00, /* dst_mask */
1822 FALSE
), /* pcrel_offset */
1824 /* LD/ST8: bit[11:0] of byte offset to module TLS base address. */
1825 HOWTO (AARCH64_R (TLSLE_LDST8_TPREL_LO12
), /* type */
1827 2, /* size (0 = byte, 1 = short, 2 = long) */
1829 FALSE
, /* pc_relative */
1831 complain_overflow_unsigned
, /* complain_on_overflow */
1832 bfd_elf_generic_reloc
, /* special_function */
1833 AARCH64_R_STR (TLSLE_LDST8_TPREL_LO12
), /* name */
1834 FALSE
, /* partial_inplace */
1835 0x3ffc00, /* src_mask */
1836 0x3ffc00, /* dst_mask */
1837 FALSE
), /* pcrel_offset */
1839 /* Same as BFD_RELOC_AARCH64_TLSLE_LDST8_TPREL_LO12, but no overflow check. */
1840 HOWTO (AARCH64_R (TLSLE_LDST8_TPREL_LO12_NC
), /* type */
1842 2, /* size (0 = byte, 1 = short, 2 = long) */
1844 FALSE
, /* pc_relative */
1846 complain_overflow_dont
, /* complain_on_overflow */
1847 bfd_elf_generic_reloc
, /* special_function */
1848 AARCH64_R_STR (TLSLE_LDST8_TPREL_LO12_NC
), /* name */
1849 FALSE
, /* partial_inplace */
1850 0x3ffc00, /* src_mask */
1851 0x3ffc00, /* dst_mask */
1852 FALSE
), /* pcrel_offset */
1854 HOWTO (AARCH64_R (TLSDESC_LD_PREL19
), /* type */
1856 2, /* size (0 = byte, 1 = short, 2 = long) */
1858 TRUE
, /* pc_relative */
1860 complain_overflow_dont
, /* complain_on_overflow */
1861 bfd_elf_generic_reloc
, /* special_function */
1862 AARCH64_R_STR (TLSDESC_LD_PREL19
), /* name */
1863 FALSE
, /* partial_inplace */
1864 0x0ffffe0, /* src_mask */
1865 0x0ffffe0, /* dst_mask */
1866 TRUE
), /* pcrel_offset */
1868 HOWTO (AARCH64_R (TLSDESC_ADR_PREL21
), /* type */
1870 2, /* size (0 = byte, 1 = short, 2 = long) */
1872 TRUE
, /* pc_relative */
1874 complain_overflow_dont
, /* complain_on_overflow */
1875 bfd_elf_generic_reloc
, /* special_function */
1876 AARCH64_R_STR (TLSDESC_ADR_PREL21
), /* name */
1877 FALSE
, /* partial_inplace */
1878 0x1fffff, /* src_mask */
1879 0x1fffff, /* dst_mask */
1880 TRUE
), /* pcrel_offset */
1882 /* Get to the page for the GOT entry for the symbol
1883 (G(S) - P) using an ADRP instruction. */
1884 HOWTO (AARCH64_R (TLSDESC_ADR_PAGE21
), /* type */
1885 12, /* rightshift */
1886 2, /* size (0 = byte, 1 = short, 2 = long) */
1888 TRUE
, /* pc_relative */
1890 complain_overflow_dont
, /* complain_on_overflow */
1891 bfd_elf_generic_reloc
, /* special_function */
1892 AARCH64_R_STR (TLSDESC_ADR_PAGE21
), /* name */
1893 FALSE
, /* partial_inplace */
1894 0x1fffff, /* src_mask */
1895 0x1fffff, /* dst_mask */
1896 TRUE
), /* pcrel_offset */
1898 /* LD64: GOT offset G(S) & 0xff8. */
1899 HOWTO64 (AARCH64_R (TLSDESC_LD64_LO12
), /* type */
1901 2, /* size (0 = byte, 1 = short, 2 = long) */
1903 FALSE
, /* pc_relative */
1905 complain_overflow_dont
, /* complain_on_overflow */
1906 bfd_elf_generic_reloc
, /* special_function */
1907 AARCH64_R_STR (TLSDESC_LD64_LO12
), /* name */
1908 FALSE
, /* partial_inplace */
1909 0xff8, /* src_mask */
1910 0xff8, /* dst_mask */
1911 FALSE
), /* pcrel_offset */
1913 /* LD32: GOT offset G(S) & 0xffc. */
1914 HOWTO32 (AARCH64_R (TLSDESC_LD32_LO12_NC
), /* type */
1916 2, /* size (0 = byte, 1 = short, 2 = long) */
1918 FALSE
, /* pc_relative */
1920 complain_overflow_dont
, /* complain_on_overflow */
1921 bfd_elf_generic_reloc
, /* special_function */
1922 AARCH64_R_STR (TLSDESC_LD32_LO12_NC
), /* name */
1923 FALSE
, /* partial_inplace */
1924 0xffc, /* src_mask */
1925 0xffc, /* dst_mask */
1926 FALSE
), /* pcrel_offset */
1928 /* ADD: GOT offset G(S) & 0xfff. */
1929 HOWTO (AARCH64_R (TLSDESC_ADD_LO12
), /* type */
1931 2, /* size (0 = byte, 1 = short, 2 = long) */
1933 FALSE
, /* pc_relative */
1935 complain_overflow_dont
,/* complain_on_overflow */
1936 bfd_elf_generic_reloc
, /* special_function */
1937 AARCH64_R_STR (TLSDESC_ADD_LO12
), /* name */
1938 FALSE
, /* partial_inplace */
1939 0xfff, /* src_mask */
1940 0xfff, /* dst_mask */
1941 FALSE
), /* pcrel_offset */
1943 HOWTO64 (AARCH64_R (TLSDESC_OFF_G1
), /* type */
1944 16, /* rightshift */
1945 2, /* size (0 = byte, 1 = short, 2 = long) */
1947 FALSE
, /* pc_relative */
1949 complain_overflow_unsigned
, /* complain_on_overflow */
1950 bfd_elf_generic_reloc
, /* special_function */
1951 AARCH64_R_STR (TLSDESC_OFF_G1
), /* name */
1952 FALSE
, /* partial_inplace */
1953 0xffff, /* src_mask */
1954 0xffff, /* dst_mask */
1955 FALSE
), /* pcrel_offset */
1957 HOWTO64 (AARCH64_R (TLSDESC_OFF_G0_NC
), /* type */
1959 2, /* size (0 = byte, 1 = short, 2 = long) */
1961 FALSE
, /* pc_relative */
1963 complain_overflow_dont
, /* complain_on_overflow */
1964 bfd_elf_generic_reloc
, /* special_function */
1965 AARCH64_R_STR (TLSDESC_OFF_G0_NC
), /* name */
1966 FALSE
, /* partial_inplace */
1967 0xffff, /* src_mask */
1968 0xffff, /* dst_mask */
1969 FALSE
), /* pcrel_offset */
1971 HOWTO64 (AARCH64_R (TLSDESC_LDR
), /* 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_LDR
), /* name */
1980 FALSE
, /* partial_inplace */
1983 FALSE
), /* pcrel_offset */
1985 HOWTO64 (AARCH64_R (TLSDESC_ADD
), /* type */
1987 2, /* size (0 = byte, 1 = short, 2 = long) */
1989 FALSE
, /* pc_relative */
1991 complain_overflow_dont
, /* complain_on_overflow */
1992 bfd_elf_generic_reloc
, /* special_function */
1993 AARCH64_R_STR (TLSDESC_ADD
), /* name */
1994 FALSE
, /* partial_inplace */
1997 FALSE
), /* pcrel_offset */
1999 HOWTO (AARCH64_R (TLSDESC_CALL
), /* 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_CALL
), /* name */
2008 FALSE
, /* partial_inplace */
2011 FALSE
), /* pcrel_offset */
2013 HOWTO (AARCH64_R (COPY
), /* type */
2015 2, /* size (0 = byte, 1 = short, 2 = long) */
2017 FALSE
, /* pc_relative */
2019 complain_overflow_bitfield
, /* complain_on_overflow */
2020 bfd_elf_generic_reloc
, /* special_function */
2021 AARCH64_R_STR (COPY
), /* name */
2022 TRUE
, /* partial_inplace */
2023 0xffffffff, /* src_mask */
2024 0xffffffff, /* dst_mask */
2025 FALSE
), /* pcrel_offset */
2027 HOWTO (AARCH64_R (GLOB_DAT
), /* type */
2029 2, /* size (0 = byte, 1 = short, 2 = long) */
2031 FALSE
, /* pc_relative */
2033 complain_overflow_bitfield
, /* complain_on_overflow */
2034 bfd_elf_generic_reloc
, /* special_function */
2035 AARCH64_R_STR (GLOB_DAT
), /* name */
2036 TRUE
, /* partial_inplace */
2037 0xffffffff, /* src_mask */
2038 0xffffffff, /* dst_mask */
2039 FALSE
), /* pcrel_offset */
2041 HOWTO (AARCH64_R (JUMP_SLOT
), /* type */
2043 2, /* size (0 = byte, 1 = short, 2 = long) */
2045 FALSE
, /* pc_relative */
2047 complain_overflow_bitfield
, /* complain_on_overflow */
2048 bfd_elf_generic_reloc
, /* special_function */
2049 AARCH64_R_STR (JUMP_SLOT
), /* name */
2050 TRUE
, /* partial_inplace */
2051 0xffffffff, /* src_mask */
2052 0xffffffff, /* dst_mask */
2053 FALSE
), /* pcrel_offset */
2055 HOWTO (AARCH64_R (RELATIVE
), /* 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 (RELATIVE
), /* name */
2064 TRUE
, /* partial_inplace */
2065 ALL_ONES
, /* src_mask */
2066 ALL_ONES
, /* dst_mask */
2067 FALSE
), /* pcrel_offset */
2069 HOWTO (AARCH64_R (TLS_DTPMOD
), /* type */
2071 2, /* size (0 = byte, 1 = short, 2 = long) */
2073 FALSE
, /* pc_relative */
2075 complain_overflow_dont
, /* complain_on_overflow */
2076 bfd_elf_generic_reloc
, /* special_function */
2078 AARCH64_R_STR (TLS_DTPMOD64
), /* name */
2080 AARCH64_R_STR (TLS_DTPMOD
), /* name */
2082 FALSE
, /* partial_inplace */
2084 ALL_ONES
, /* dst_mask */
2085 FALSE
), /* pc_reloffset */
2087 HOWTO (AARCH64_R (TLS_DTPREL
), /* type */
2089 2, /* size (0 = byte, 1 = short, 2 = long) */
2091 FALSE
, /* pc_relative */
2093 complain_overflow_dont
, /* complain_on_overflow */
2094 bfd_elf_generic_reloc
, /* special_function */
2096 AARCH64_R_STR (TLS_DTPREL64
), /* name */
2098 AARCH64_R_STR (TLS_DTPREL
), /* name */
2100 FALSE
, /* partial_inplace */
2102 ALL_ONES
, /* dst_mask */
2103 FALSE
), /* pcrel_offset */
2105 HOWTO (AARCH64_R (TLS_TPREL
), /* type */
2107 2, /* size (0 = byte, 1 = short, 2 = long) */
2109 FALSE
, /* pc_relative */
2111 complain_overflow_dont
, /* complain_on_overflow */
2112 bfd_elf_generic_reloc
, /* special_function */
2114 AARCH64_R_STR (TLS_TPREL64
), /* name */
2116 AARCH64_R_STR (TLS_TPREL
), /* name */
2118 FALSE
, /* partial_inplace */
2120 ALL_ONES
, /* dst_mask */
2121 FALSE
), /* pcrel_offset */
2123 HOWTO (AARCH64_R (TLSDESC
), /* type */
2125 2, /* size (0 = byte, 1 = short, 2 = long) */
2127 FALSE
, /* pc_relative */
2129 complain_overflow_dont
, /* complain_on_overflow */
2130 bfd_elf_generic_reloc
, /* special_function */
2131 AARCH64_R_STR (TLSDESC
), /* name */
2132 FALSE
, /* partial_inplace */
2134 ALL_ONES
, /* dst_mask */
2135 FALSE
), /* pcrel_offset */
2137 HOWTO (AARCH64_R (IRELATIVE
), /* type */
2139 2, /* size (0 = byte, 1 = short, 2 = long) */
2141 FALSE
, /* pc_relative */
2143 complain_overflow_bitfield
, /* complain_on_overflow */
2144 bfd_elf_generic_reloc
, /* special_function */
2145 AARCH64_R_STR (IRELATIVE
), /* name */
2146 FALSE
, /* partial_inplace */
2148 ALL_ONES
, /* dst_mask */
2149 FALSE
), /* pcrel_offset */
2154 static reloc_howto_type elfNN_aarch64_howto_none
=
2155 HOWTO (R_AARCH64_NONE
, /* type */
2157 3, /* size (0 = byte, 1 = short, 2 = long) */
2159 FALSE
, /* pc_relative */
2161 complain_overflow_dont
,/* complain_on_overflow */
2162 bfd_elf_generic_reloc
, /* special_function */
2163 "R_AARCH64_NONE", /* name */
2164 FALSE
, /* partial_inplace */
2167 FALSE
); /* pcrel_offset */
2169 /* Given HOWTO, return the bfd internal relocation enumerator. */
2171 static bfd_reloc_code_real_type
2172 elfNN_aarch64_bfd_reloc_from_howto (reloc_howto_type
*howto
)
2175 = (int) ARRAY_SIZE (elfNN_aarch64_howto_table
);
2176 const ptrdiff_t offset
2177 = howto
- elfNN_aarch64_howto_table
;
2179 if (offset
> 0 && offset
< size
- 1)
2180 return BFD_RELOC_AARCH64_RELOC_START
+ offset
;
2182 if (howto
== &elfNN_aarch64_howto_none
)
2183 return BFD_RELOC_AARCH64_NONE
;
2185 return BFD_RELOC_AARCH64_RELOC_START
;
2188 /* Given R_TYPE, return the bfd internal relocation enumerator. */
2190 static bfd_reloc_code_real_type
2191 elfNN_aarch64_bfd_reloc_from_type (bfd
*abfd
, unsigned int r_type
)
2193 static bfd_boolean initialized_p
= FALSE
;
2194 /* Indexed by R_TYPE, values are offsets in the howto_table. */
2195 static unsigned int offsets
[R_AARCH64_end
];
2201 for (i
= 1; i
< ARRAY_SIZE (elfNN_aarch64_howto_table
) - 1; ++i
)
2202 if (elfNN_aarch64_howto_table
[i
].type
!= 0)
2203 offsets
[elfNN_aarch64_howto_table
[i
].type
] = i
;
2205 initialized_p
= TRUE
;
2208 if (r_type
== R_AARCH64_NONE
|| r_type
== R_AARCH64_NULL
)
2209 return BFD_RELOC_AARCH64_NONE
;
2211 /* PR 17512: file: b371e70a. */
2212 if (r_type
>= R_AARCH64_end
)
2214 _bfd_error_handler (_("%pB: unsupported relocation type %#x"),
2216 bfd_set_error (bfd_error_bad_value
);
2217 return BFD_RELOC_AARCH64_NONE
;
2220 return BFD_RELOC_AARCH64_RELOC_START
+ offsets
[r_type
];
2223 struct elf_aarch64_reloc_map
2225 bfd_reloc_code_real_type from
;
2226 bfd_reloc_code_real_type to
;
2229 /* Map bfd generic reloc to AArch64-specific reloc. */
2230 static const struct elf_aarch64_reloc_map elf_aarch64_reloc_map
[] =
2232 {BFD_RELOC_NONE
, BFD_RELOC_AARCH64_NONE
},
2234 /* Basic data relocations. */
2235 {BFD_RELOC_CTOR
, BFD_RELOC_AARCH64_NN
},
2236 {BFD_RELOC_64
, BFD_RELOC_AARCH64_64
},
2237 {BFD_RELOC_32
, BFD_RELOC_AARCH64_32
},
2238 {BFD_RELOC_16
, BFD_RELOC_AARCH64_16
},
2239 {BFD_RELOC_64_PCREL
, BFD_RELOC_AARCH64_64_PCREL
},
2240 {BFD_RELOC_32_PCREL
, BFD_RELOC_AARCH64_32_PCREL
},
2241 {BFD_RELOC_16_PCREL
, BFD_RELOC_AARCH64_16_PCREL
},
2244 /* Given the bfd internal relocation enumerator in CODE, return the
2245 corresponding howto entry. */
2247 static reloc_howto_type
*
2248 elfNN_aarch64_howto_from_bfd_reloc (bfd_reloc_code_real_type code
)
2252 /* Convert bfd generic reloc to AArch64-specific reloc. */
2253 if (code
< BFD_RELOC_AARCH64_RELOC_START
2254 || code
> BFD_RELOC_AARCH64_RELOC_END
)
2255 for (i
= 0; i
< ARRAY_SIZE (elf_aarch64_reloc_map
); i
++)
2256 if (elf_aarch64_reloc_map
[i
].from
== code
)
2258 code
= elf_aarch64_reloc_map
[i
].to
;
2262 if (code
> BFD_RELOC_AARCH64_RELOC_START
2263 && code
< BFD_RELOC_AARCH64_RELOC_END
)
2264 if (elfNN_aarch64_howto_table
[code
- BFD_RELOC_AARCH64_RELOC_START
].type
)
2265 return &elfNN_aarch64_howto_table
[code
- BFD_RELOC_AARCH64_RELOC_START
];
2267 if (code
== BFD_RELOC_AARCH64_NONE
)
2268 return &elfNN_aarch64_howto_none
;
2273 static reloc_howto_type
*
2274 elfNN_aarch64_howto_from_type (bfd
*abfd
, unsigned int r_type
)
2276 bfd_reloc_code_real_type val
;
2277 reloc_howto_type
*howto
;
2282 bfd_set_error (bfd_error_bad_value
);
2287 if (r_type
== R_AARCH64_NONE
)
2288 return &elfNN_aarch64_howto_none
;
2290 val
= elfNN_aarch64_bfd_reloc_from_type (abfd
, r_type
);
2291 howto
= elfNN_aarch64_howto_from_bfd_reloc (val
);
2296 bfd_set_error (bfd_error_bad_value
);
2301 elfNN_aarch64_info_to_howto (bfd
*abfd
, arelent
*bfd_reloc
,
2302 Elf_Internal_Rela
*elf_reloc
)
2304 unsigned int r_type
;
2306 r_type
= ELFNN_R_TYPE (elf_reloc
->r_info
);
2307 bfd_reloc
->howto
= elfNN_aarch64_howto_from_type (abfd
, r_type
);
2309 if (bfd_reloc
->howto
== NULL
)
2311 /* xgettext:c-format */
2312 _bfd_error_handler (_("%pB: unsupported relocation type %#x"), abfd
, r_type
);
2318 static reloc_howto_type
*
2319 elfNN_aarch64_reloc_type_lookup (bfd
*abfd ATTRIBUTE_UNUSED
,
2320 bfd_reloc_code_real_type code
)
2322 reloc_howto_type
*howto
= elfNN_aarch64_howto_from_bfd_reloc (code
);
2327 bfd_set_error (bfd_error_bad_value
);
2331 static reloc_howto_type
*
2332 elfNN_aarch64_reloc_name_lookup (bfd
*abfd ATTRIBUTE_UNUSED
,
2337 for (i
= 1; i
< ARRAY_SIZE (elfNN_aarch64_howto_table
) - 1; ++i
)
2338 if (elfNN_aarch64_howto_table
[i
].name
!= NULL
2339 && strcasecmp (elfNN_aarch64_howto_table
[i
].name
, r_name
) == 0)
2340 return &elfNN_aarch64_howto_table
[i
];
2345 #define TARGET_LITTLE_SYM aarch64_elfNN_le_vec
2346 #define TARGET_LITTLE_NAME "elfNN-littleaarch64"
2347 #define TARGET_BIG_SYM aarch64_elfNN_be_vec
2348 #define TARGET_BIG_NAME "elfNN-bigaarch64"
2350 /* The linker script knows the section names for placement.
2351 The entry_names are used to do simple name mangling on the stubs.
2352 Given a function name, and its type, the stub can be found. The
2353 name can be changed. The only requirement is the %s be present. */
2354 #define STUB_ENTRY_NAME "__%s_veneer"
2356 /* The name of the dynamic interpreter. This is put in the .interp
2358 #define ELF_DYNAMIC_INTERPRETER "/lib/ld.so.1"
2360 #define AARCH64_MAX_FWD_BRANCH_OFFSET \
2361 (((1 << 25) - 1) << 2)
2362 #define AARCH64_MAX_BWD_BRANCH_OFFSET \
2365 #define AARCH64_MAX_ADRP_IMM ((1 << 20) - 1)
2366 #define AARCH64_MIN_ADRP_IMM (-(1 << 20))
2369 aarch64_valid_for_adrp_p (bfd_vma value
, bfd_vma place
)
2371 bfd_signed_vma offset
= (bfd_signed_vma
) (PG (value
) - PG (place
)) >> 12;
2372 return offset
<= AARCH64_MAX_ADRP_IMM
&& offset
>= AARCH64_MIN_ADRP_IMM
;
2376 aarch64_valid_branch_p (bfd_vma value
, bfd_vma place
)
2378 bfd_signed_vma offset
= (bfd_signed_vma
) (value
- place
);
2379 return (offset
<= AARCH64_MAX_FWD_BRANCH_OFFSET
2380 && offset
>= AARCH64_MAX_BWD_BRANCH_OFFSET
);
2383 static const uint32_t aarch64_adrp_branch_stub
[] =
2385 0x90000010, /* adrp ip0, X */
2386 /* R_AARCH64_ADR_HI21_PCREL(X) */
2387 0x91000210, /* add ip0, ip0, :lo12:X */
2388 /* R_AARCH64_ADD_ABS_LO12_NC(X) */
2389 0xd61f0200, /* br ip0 */
2392 static const uint32_t aarch64_long_branch_stub
[] =
2395 0x58000090, /* ldr ip0, 1f */
2397 0x18000090, /* ldr wip0, 1f */
2399 0x10000011, /* adr ip1, #0 */
2400 0x8b110210, /* add ip0, ip0, ip1 */
2401 0xd61f0200, /* br ip0 */
2402 0x00000000, /* 1: .xword or .word
2403 R_AARCH64_PRELNN(X) + 12
2408 static const uint32_t aarch64_erratum_835769_stub
[] =
2410 0x00000000, /* Placeholder for multiply accumulate. */
2411 0x14000000, /* b <label> */
2414 static const uint32_t aarch64_erratum_843419_stub
[] =
2416 0x00000000, /* Placeholder for LDR instruction. */
2417 0x14000000, /* b <label> */
2420 /* Section name for stubs is the associated section name plus this
2422 #define STUB_SUFFIX ".stub"
2424 enum elf_aarch64_stub_type
2427 aarch64_stub_adrp_branch
,
2428 aarch64_stub_long_branch
,
2429 aarch64_stub_erratum_835769_veneer
,
2430 aarch64_stub_erratum_843419_veneer
,
2433 struct elf_aarch64_stub_hash_entry
2435 /* Base hash table entry structure. */
2436 struct bfd_hash_entry root
;
2438 /* The stub section. */
2441 /* Offset within stub_sec of the beginning of this stub. */
2442 bfd_vma stub_offset
;
2444 /* Given the symbol's value and its section we can determine its final
2445 value when building the stubs (so the stub knows where to jump). */
2446 bfd_vma target_value
;
2447 asection
*target_section
;
2449 enum elf_aarch64_stub_type stub_type
;
2451 /* The symbol table entry, if any, that this was derived from. */
2452 struct elf_aarch64_link_hash_entry
*h
;
2454 /* Destination symbol type */
2455 unsigned char st_type
;
2457 /* Where this stub is being called from, or, in the case of combined
2458 stub sections, the first input section in the group. */
2461 /* The name for the local symbol at the start of this stub. The
2462 stub name in the hash table has to be unique; this does not, so
2463 it can be friendlier. */
2466 /* The instruction which caused this stub to be generated (only valid for
2467 erratum 835769 workaround stubs at present). */
2468 uint32_t veneered_insn
;
2470 /* In an erratum 843419 workaround stub, the ADRP instruction offset. */
2471 bfd_vma adrp_offset
;
2474 /* Used to build a map of a section. This is required for mixed-endian
2477 typedef struct elf_elf_section_map
2482 elf_aarch64_section_map
;
2485 typedef struct _aarch64_elf_section_data
2487 struct bfd_elf_section_data elf
;
2488 unsigned int mapcount
;
2489 unsigned int mapsize
;
2490 elf_aarch64_section_map
*map
;
2492 _aarch64_elf_section_data
;
2494 #define elf_aarch64_section_data(sec) \
2495 ((_aarch64_elf_section_data *) elf_section_data (sec))
2497 /* The size of the thread control block which is defined to be two pointers. */
2498 #define TCB_SIZE (ARCH_SIZE/8)*2
2500 struct elf_aarch64_local_symbol
2502 unsigned int got_type
;
2503 bfd_signed_vma got_refcount
;
2506 /* Offset of the GOTPLT entry reserved for the TLS descriptor. The
2507 offset is from the end of the jump table and reserved entries
2510 The magic value (bfd_vma) -1 indicates that an offset has not be
2512 bfd_vma tlsdesc_got_jump_table_offset
;
2515 struct elf_aarch64_obj_tdata
2517 struct elf_obj_tdata root
;
2519 /* local symbol descriptors */
2520 struct elf_aarch64_local_symbol
*locals
;
2522 /* Zero to warn when linking objects with incompatible enum sizes. */
2523 int no_enum_size_warning
;
2525 /* Zero to warn when linking objects with incompatible wchar_t sizes. */
2526 int no_wchar_size_warning
;
2528 /* All GNU_PROPERTY_AARCH64_FEATURE_1_AND properties. */
2529 uint32_t gnu_and_prop
;
2531 /* Zero to warn when linking objects with incompatible
2532 GNU_PROPERTY_AARCH64_FEATURE_1_BTI. */
2535 /* PLT type based on security. */
2536 aarch64_plt_type plt_type
;
2539 #define elf_aarch64_tdata(bfd) \
2540 ((struct elf_aarch64_obj_tdata *) (bfd)->tdata.any)
2542 #define elf_aarch64_locals(bfd) (elf_aarch64_tdata (bfd)->locals)
2544 #define is_aarch64_elf(bfd) \
2545 (bfd_get_flavour (bfd) == bfd_target_elf_flavour \
2546 && elf_tdata (bfd) != NULL \
2547 && elf_object_id (bfd) == AARCH64_ELF_DATA)
2550 elfNN_aarch64_mkobject (bfd
*abfd
)
2552 return bfd_elf_allocate_object (abfd
, sizeof (struct elf_aarch64_obj_tdata
),
2556 #define elf_aarch64_hash_entry(ent) \
2557 ((struct elf_aarch64_link_hash_entry *)(ent))
2559 #define GOT_UNKNOWN 0
2560 #define GOT_NORMAL 1
2561 #define GOT_TLS_GD 2
2562 #define GOT_TLS_IE 4
2563 #define GOT_TLSDESC_GD 8
2565 #define GOT_TLS_GD_ANY_P(type) ((type & GOT_TLS_GD) || (type & GOT_TLSDESC_GD))
2567 /* AArch64 ELF linker hash entry. */
2568 struct elf_aarch64_link_hash_entry
2570 struct elf_link_hash_entry root
;
2572 /* Track dynamic relocs copied for this symbol. */
2573 struct elf_dyn_relocs
*dyn_relocs
;
2575 /* Since PLT entries have variable size, we need to record the
2576 index into .got.plt instead of recomputing it from the PLT
2578 bfd_signed_vma plt_got_offset
;
2580 /* Bit mask representing the type of GOT entry(s) if any required by
2582 unsigned int got_type
;
2584 /* A pointer to the most recently used stub hash entry against this
2586 struct elf_aarch64_stub_hash_entry
*stub_cache
;
2588 /* Offset of the GOTPLT entry reserved for the TLS descriptor. The offset
2589 is from the end of the jump table and reserved entries within the PLTGOT.
2591 The magic value (bfd_vma) -1 indicates that an offset has not
2593 bfd_vma tlsdesc_got_jump_table_offset
;
2597 elfNN_aarch64_symbol_got_type (struct elf_link_hash_entry
*h
,
2599 unsigned long r_symndx
)
2602 return elf_aarch64_hash_entry (h
)->got_type
;
2604 if (! elf_aarch64_locals (abfd
))
2607 return elf_aarch64_locals (abfd
)[r_symndx
].got_type
;
2610 /* Get the AArch64 elf linker hash table from a link_info structure. */
2611 #define elf_aarch64_hash_table(info) \
2612 ((struct elf_aarch64_link_hash_table *) ((info)->hash))
2614 #define aarch64_stub_hash_lookup(table, string, create, copy) \
2615 ((struct elf_aarch64_stub_hash_entry *) \
2616 bfd_hash_lookup ((table), (string), (create), (copy)))
2618 /* AArch64 ELF linker hash table. */
2619 struct elf_aarch64_link_hash_table
2621 /* The main hash table. */
2622 struct elf_link_hash_table root
;
2624 /* Nonzero to force PIC branch veneers. */
2627 /* Fix erratum 835769. */
2628 int fix_erratum_835769
;
2630 /* Fix erratum 843419. */
2631 erratum_84319_opts fix_erratum_843419
;
2633 /* Don't apply link-time values for dynamic relocations. */
2634 int no_apply_dynamic_relocs
;
2636 /* The number of bytes in the initial entry in the PLT. */
2637 bfd_size_type plt_header_size
;
2639 /* The bytes of the initial PLT entry. */
2640 const bfd_byte
*plt0_entry
;
2642 /* The number of bytes in the subsequent PLT entries. */
2643 bfd_size_type plt_entry_size
;
2645 /* The bytes of the subsequent PLT entry. */
2646 const bfd_byte
*plt_entry
;
2648 /* Small local sym cache. */
2649 struct sym_cache sym_cache
;
2651 /* For convenience in allocate_dynrelocs. */
2654 /* The amount of space used by the reserved portion of the sgotplt
2655 section, plus whatever space is used by the jump slots. */
2656 bfd_vma sgotplt_jump_table_size
;
2658 /* The stub hash table. */
2659 struct bfd_hash_table stub_hash_table
;
2661 /* Linker stub bfd. */
2664 /* Linker call-backs. */
2665 asection
*(*add_stub_section
) (const char *, asection
*);
2666 void (*layout_sections_again
) (void);
2668 /* Array to keep track of which stub sections have been created, and
2669 information on stub grouping. */
2672 /* This is the section to which stubs in the group will be
2675 /* The stub section. */
2679 /* Assorted information used by elfNN_aarch64_size_stubs. */
2680 unsigned int bfd_count
;
2681 unsigned int top_index
;
2682 asection
**input_list
;
2684 /* The offset into splt of the PLT entry for the TLS descriptor
2685 resolver. Special values are 0, if not necessary (or not found
2686 to be necessary yet), and -1 if needed but not determined
2688 bfd_vma tlsdesc_plt
;
2690 /* The number of bytes in the PLT enty for the TLS descriptor. */
2691 bfd_size_type tlsdesc_plt_entry_size
;
2693 /* The GOT offset for the lazy trampoline. Communicated to the
2694 loader via DT_TLSDESC_GOT. The magic value (bfd_vma) -1
2695 indicates an offset is not allocated. */
2696 bfd_vma dt_tlsdesc_got
;
2698 /* Used by local STT_GNU_IFUNC symbols. */
2699 htab_t loc_hash_table
;
2700 void * loc_hash_memory
;
2703 /* Create an entry in an AArch64 ELF linker hash table. */
2705 static struct bfd_hash_entry
*
2706 elfNN_aarch64_link_hash_newfunc (struct bfd_hash_entry
*entry
,
2707 struct bfd_hash_table
*table
,
2710 struct elf_aarch64_link_hash_entry
*ret
=
2711 (struct elf_aarch64_link_hash_entry
*) entry
;
2713 /* Allocate the structure if it has not already been allocated by a
2716 ret
= bfd_hash_allocate (table
,
2717 sizeof (struct elf_aarch64_link_hash_entry
));
2719 return (struct bfd_hash_entry
*) ret
;
2721 /* Call the allocation method of the superclass. */
2722 ret
= ((struct elf_aarch64_link_hash_entry
*)
2723 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry
*) ret
,
2727 ret
->dyn_relocs
= NULL
;
2728 ret
->got_type
= GOT_UNKNOWN
;
2729 ret
->plt_got_offset
= (bfd_vma
) - 1;
2730 ret
->stub_cache
= NULL
;
2731 ret
->tlsdesc_got_jump_table_offset
= (bfd_vma
) - 1;
2734 return (struct bfd_hash_entry
*) ret
;
2737 /* Initialize an entry in the stub hash table. */
2739 static struct bfd_hash_entry
*
2740 stub_hash_newfunc (struct bfd_hash_entry
*entry
,
2741 struct bfd_hash_table
*table
, const char *string
)
2743 /* Allocate the structure if it has not already been allocated by a
2747 entry
= bfd_hash_allocate (table
,
2749 elf_aarch64_stub_hash_entry
));
2754 /* Call the allocation method of the superclass. */
2755 entry
= bfd_hash_newfunc (entry
, table
, string
);
2758 struct elf_aarch64_stub_hash_entry
*eh
;
2760 /* Initialize the local fields. */
2761 eh
= (struct elf_aarch64_stub_hash_entry
*) entry
;
2762 eh
->adrp_offset
= 0;
2763 eh
->stub_sec
= NULL
;
2764 eh
->stub_offset
= 0;
2765 eh
->target_value
= 0;
2766 eh
->target_section
= NULL
;
2767 eh
->stub_type
= aarch64_stub_none
;
2775 /* Compute a hash of a local hash entry. We use elf_link_hash_entry
2776 for local symbol so that we can handle local STT_GNU_IFUNC symbols
2777 as global symbol. We reuse indx and dynstr_index for local symbol
2778 hash since they aren't used by global symbols in this backend. */
2781 elfNN_aarch64_local_htab_hash (const void *ptr
)
2783 struct elf_link_hash_entry
*h
2784 = (struct elf_link_hash_entry
*) ptr
;
2785 return ELF_LOCAL_SYMBOL_HASH (h
->indx
, h
->dynstr_index
);
2788 /* Compare local hash entries. */
2791 elfNN_aarch64_local_htab_eq (const void *ptr1
, const void *ptr2
)
2793 struct elf_link_hash_entry
*h1
2794 = (struct elf_link_hash_entry
*) ptr1
;
2795 struct elf_link_hash_entry
*h2
2796 = (struct elf_link_hash_entry
*) ptr2
;
2798 return h1
->indx
== h2
->indx
&& h1
->dynstr_index
== h2
->dynstr_index
;
2801 /* Find and/or create a hash entry for local symbol. */
2803 static struct elf_link_hash_entry
*
2804 elfNN_aarch64_get_local_sym_hash (struct elf_aarch64_link_hash_table
*htab
,
2805 bfd
*abfd
, const Elf_Internal_Rela
*rel
,
2808 struct elf_aarch64_link_hash_entry e
, *ret
;
2809 asection
*sec
= abfd
->sections
;
2810 hashval_t h
= ELF_LOCAL_SYMBOL_HASH (sec
->id
,
2811 ELFNN_R_SYM (rel
->r_info
));
2814 e
.root
.indx
= sec
->id
;
2815 e
.root
.dynstr_index
= ELFNN_R_SYM (rel
->r_info
);
2816 slot
= htab_find_slot_with_hash (htab
->loc_hash_table
, &e
, h
,
2817 create
? INSERT
: NO_INSERT
);
2824 ret
= (struct elf_aarch64_link_hash_entry
*) *slot
;
2828 ret
= (struct elf_aarch64_link_hash_entry
*)
2829 objalloc_alloc ((struct objalloc
*) htab
->loc_hash_memory
,
2830 sizeof (struct elf_aarch64_link_hash_entry
));
2833 memset (ret
, 0, sizeof (*ret
));
2834 ret
->root
.indx
= sec
->id
;
2835 ret
->root
.dynstr_index
= ELFNN_R_SYM (rel
->r_info
);
2836 ret
->root
.dynindx
= -1;
2842 /* Copy the extra info we tack onto an elf_link_hash_entry. */
2845 elfNN_aarch64_copy_indirect_symbol (struct bfd_link_info
*info
,
2846 struct elf_link_hash_entry
*dir
,
2847 struct elf_link_hash_entry
*ind
)
2849 struct elf_aarch64_link_hash_entry
*edir
, *eind
;
2851 edir
= (struct elf_aarch64_link_hash_entry
*) dir
;
2852 eind
= (struct elf_aarch64_link_hash_entry
*) ind
;
2854 if (eind
->dyn_relocs
!= NULL
)
2856 if (edir
->dyn_relocs
!= NULL
)
2858 struct elf_dyn_relocs
**pp
;
2859 struct elf_dyn_relocs
*p
;
2861 /* Add reloc counts against the indirect sym to the direct sym
2862 list. Merge any entries against the same section. */
2863 for (pp
= &eind
->dyn_relocs
; (p
= *pp
) != NULL
;)
2865 struct elf_dyn_relocs
*q
;
2867 for (q
= edir
->dyn_relocs
; q
!= NULL
; q
= q
->next
)
2868 if (q
->sec
== p
->sec
)
2870 q
->pc_count
+= p
->pc_count
;
2871 q
->count
+= p
->count
;
2878 *pp
= edir
->dyn_relocs
;
2881 edir
->dyn_relocs
= eind
->dyn_relocs
;
2882 eind
->dyn_relocs
= NULL
;
2885 if (ind
->root
.type
== bfd_link_hash_indirect
)
2887 /* Copy over PLT info. */
2888 if (dir
->got
.refcount
<= 0)
2890 edir
->got_type
= eind
->got_type
;
2891 eind
->got_type
= GOT_UNKNOWN
;
2895 _bfd_elf_link_hash_copy_indirect (info
, dir
, ind
);
2898 /* Destroy an AArch64 elf linker hash table. */
2901 elfNN_aarch64_link_hash_table_free (bfd
*obfd
)
2903 struct elf_aarch64_link_hash_table
*ret
2904 = (struct elf_aarch64_link_hash_table
*) obfd
->link
.hash
;
2906 if (ret
->loc_hash_table
)
2907 htab_delete (ret
->loc_hash_table
);
2908 if (ret
->loc_hash_memory
)
2909 objalloc_free ((struct objalloc
*) ret
->loc_hash_memory
);
2911 bfd_hash_table_free (&ret
->stub_hash_table
);
2912 _bfd_elf_link_hash_table_free (obfd
);
2915 /* Create an AArch64 elf linker hash table. */
2917 static struct bfd_link_hash_table
*
2918 elfNN_aarch64_link_hash_table_create (bfd
*abfd
)
2920 struct elf_aarch64_link_hash_table
*ret
;
2921 bfd_size_type amt
= sizeof (struct elf_aarch64_link_hash_table
);
2923 ret
= bfd_zmalloc (amt
);
2927 if (!_bfd_elf_link_hash_table_init
2928 (&ret
->root
, abfd
, elfNN_aarch64_link_hash_newfunc
,
2929 sizeof (struct elf_aarch64_link_hash_entry
), AARCH64_ELF_DATA
))
2935 ret
->plt_header_size
= PLT_ENTRY_SIZE
;
2936 ret
->plt0_entry
= elfNN_aarch64_small_plt0_entry
;
2937 ret
->plt_entry_size
= PLT_SMALL_ENTRY_SIZE
;
2938 ret
->plt_entry
= elfNN_aarch64_small_plt_entry
;
2939 ret
->tlsdesc_plt_entry_size
= PLT_TLSDESC_ENTRY_SIZE
;
2941 ret
->dt_tlsdesc_got
= (bfd_vma
) - 1;
2943 if (!bfd_hash_table_init (&ret
->stub_hash_table
, stub_hash_newfunc
,
2944 sizeof (struct elf_aarch64_stub_hash_entry
)))
2946 _bfd_elf_link_hash_table_free (abfd
);
2950 ret
->loc_hash_table
= htab_try_create (1024,
2951 elfNN_aarch64_local_htab_hash
,
2952 elfNN_aarch64_local_htab_eq
,
2954 ret
->loc_hash_memory
= objalloc_create ();
2955 if (!ret
->loc_hash_table
|| !ret
->loc_hash_memory
)
2957 elfNN_aarch64_link_hash_table_free (abfd
);
2960 ret
->root
.root
.hash_table_free
= elfNN_aarch64_link_hash_table_free
;
2962 return &ret
->root
.root
;
2965 /* Perform relocation R_TYPE. Returns TRUE upon success, FALSE otherwise. */
2968 aarch64_relocate (unsigned int r_type
, bfd
*input_bfd
, asection
*input_section
,
2969 bfd_vma offset
, bfd_vma value
)
2971 reloc_howto_type
*howto
;
2974 howto
= elfNN_aarch64_howto_from_type (input_bfd
, r_type
);
2975 place
= (input_section
->output_section
->vma
+ input_section
->output_offset
2978 r_type
= elfNN_aarch64_bfd_reloc_from_type (input_bfd
, r_type
);
2979 value
= _bfd_aarch64_elf_resolve_relocation (r_type
, place
, value
, 0, FALSE
);
2980 return _bfd_aarch64_elf_put_addend (input_bfd
,
2981 input_section
->contents
+ offset
, r_type
,
2982 howto
, value
) == bfd_reloc_ok
;
2985 static enum elf_aarch64_stub_type
2986 aarch64_select_branch_stub (bfd_vma value
, bfd_vma place
)
2988 if (aarch64_valid_for_adrp_p (value
, place
))
2989 return aarch64_stub_adrp_branch
;
2990 return aarch64_stub_long_branch
;
2993 /* Determine the type of stub needed, if any, for a call. */
2995 static enum elf_aarch64_stub_type
2996 aarch64_type_of_stub (asection
*input_sec
,
2997 const Elf_Internal_Rela
*rel
,
2999 unsigned char st_type
,
3000 bfd_vma destination
)
3003 bfd_signed_vma branch_offset
;
3004 unsigned int r_type
;
3005 enum elf_aarch64_stub_type stub_type
= aarch64_stub_none
;
3007 if (st_type
!= STT_FUNC
3008 && (sym_sec
== input_sec
))
3011 /* Determine where the call point is. */
3012 location
= (input_sec
->output_offset
3013 + input_sec
->output_section
->vma
+ rel
->r_offset
);
3015 branch_offset
= (bfd_signed_vma
) (destination
- location
);
3017 r_type
= ELFNN_R_TYPE (rel
->r_info
);
3019 /* We don't want to redirect any old unconditional jump in this way,
3020 only one which is being used for a sibcall, where it is
3021 acceptable for the IP0 and IP1 registers to be clobbered. */
3022 if ((r_type
== AARCH64_R (CALL26
) || r_type
== AARCH64_R (JUMP26
))
3023 && (branch_offset
> AARCH64_MAX_FWD_BRANCH_OFFSET
3024 || branch_offset
< AARCH64_MAX_BWD_BRANCH_OFFSET
))
3026 stub_type
= aarch64_stub_long_branch
;
3032 /* Build a name for an entry in the stub hash table. */
3035 elfNN_aarch64_stub_name (const asection
*input_section
,
3036 const asection
*sym_sec
,
3037 const struct elf_aarch64_link_hash_entry
*hash
,
3038 const Elf_Internal_Rela
*rel
)
3045 len
= 8 + 1 + strlen (hash
->root
.root
.root
.string
) + 1 + 16 + 1;
3046 stub_name
= bfd_malloc (len
);
3047 if (stub_name
!= NULL
)
3048 snprintf (stub_name
, len
, "%08x_%s+%" BFD_VMA_FMT
"x",
3049 (unsigned int) input_section
->id
,
3050 hash
->root
.root
.root
.string
,
3055 len
= 8 + 1 + 8 + 1 + 8 + 1 + 16 + 1;
3056 stub_name
= bfd_malloc (len
);
3057 if (stub_name
!= NULL
)
3058 snprintf (stub_name
, len
, "%08x_%x:%x+%" BFD_VMA_FMT
"x",
3059 (unsigned int) input_section
->id
,
3060 (unsigned int) sym_sec
->id
,
3061 (unsigned int) ELFNN_R_SYM (rel
->r_info
),
3068 /* Return TRUE if symbol H should be hashed in the `.gnu.hash' section. For
3069 executable PLT slots where the executable never takes the address of those
3070 functions, the function symbols are not added to the hash table. */
3073 elf_aarch64_hash_symbol (struct elf_link_hash_entry
*h
)
3075 if (h
->plt
.offset
!= (bfd_vma
) -1
3077 && !h
->pointer_equality_needed
)
3080 return _bfd_elf_hash_symbol (h
);
3084 /* Look up an entry in the stub hash. Stub entries are cached because
3085 creating the stub name takes a bit of time. */
3087 static struct elf_aarch64_stub_hash_entry
*
3088 elfNN_aarch64_get_stub_entry (const asection
*input_section
,
3089 const asection
*sym_sec
,
3090 struct elf_link_hash_entry
*hash
,
3091 const Elf_Internal_Rela
*rel
,
3092 struct elf_aarch64_link_hash_table
*htab
)
3094 struct elf_aarch64_stub_hash_entry
*stub_entry
;
3095 struct elf_aarch64_link_hash_entry
*h
=
3096 (struct elf_aarch64_link_hash_entry
*) hash
;
3097 const asection
*id_sec
;
3099 if ((input_section
->flags
& SEC_CODE
) == 0)
3102 /* If this input section is part of a group of sections sharing one
3103 stub section, then use the id of the first section in the group.
3104 Stub names need to include a section id, as there may well be
3105 more than one stub used to reach say, printf, and we need to
3106 distinguish between them. */
3107 id_sec
= htab
->stub_group
[input_section
->id
].link_sec
;
3109 if (h
!= NULL
&& h
->stub_cache
!= NULL
3110 && h
->stub_cache
->h
== h
&& h
->stub_cache
->id_sec
== id_sec
)
3112 stub_entry
= h
->stub_cache
;
3118 stub_name
= elfNN_aarch64_stub_name (id_sec
, sym_sec
, h
, rel
);
3119 if (stub_name
== NULL
)
3122 stub_entry
= aarch64_stub_hash_lookup (&htab
->stub_hash_table
,
3123 stub_name
, FALSE
, FALSE
);
3125 h
->stub_cache
= stub_entry
;
3134 /* Create a stub section. */
3137 _bfd_aarch64_create_stub_section (asection
*section
,
3138 struct elf_aarch64_link_hash_table
*htab
)
3144 namelen
= strlen (section
->name
);
3145 len
= namelen
+ sizeof (STUB_SUFFIX
);
3146 s_name
= bfd_alloc (htab
->stub_bfd
, len
);
3150 memcpy (s_name
, section
->name
, namelen
);
3151 memcpy (s_name
+ namelen
, STUB_SUFFIX
, sizeof (STUB_SUFFIX
));
3152 return (*htab
->add_stub_section
) (s_name
, section
);
3156 /* Find or create a stub section for a link section.
3158 Fix or create the stub section used to collect stubs attached to
3159 the specified link section. */
3162 _bfd_aarch64_get_stub_for_link_section (asection
*link_section
,
3163 struct elf_aarch64_link_hash_table
*htab
)
3165 if (htab
->stub_group
[link_section
->id
].stub_sec
== NULL
)
3166 htab
->stub_group
[link_section
->id
].stub_sec
3167 = _bfd_aarch64_create_stub_section (link_section
, htab
);
3168 return htab
->stub_group
[link_section
->id
].stub_sec
;
3172 /* Find or create a stub section in the stub group for an input
3176 _bfd_aarch64_create_or_find_stub_sec (asection
*section
,
3177 struct elf_aarch64_link_hash_table
*htab
)
3179 asection
*link_sec
= htab
->stub_group
[section
->id
].link_sec
;
3180 return _bfd_aarch64_get_stub_for_link_section (link_sec
, htab
);
3184 /* Add a new stub entry in the stub group associated with an input
3185 section to the stub hash. Not all fields of the new stub entry are
3188 static struct elf_aarch64_stub_hash_entry
*
3189 _bfd_aarch64_add_stub_entry_in_group (const char *stub_name
,
3191 struct elf_aarch64_link_hash_table
*htab
)
3195 struct elf_aarch64_stub_hash_entry
*stub_entry
;
3197 link_sec
= htab
->stub_group
[section
->id
].link_sec
;
3198 stub_sec
= _bfd_aarch64_create_or_find_stub_sec (section
, htab
);
3200 /* Enter this entry into the linker stub hash table. */
3201 stub_entry
= aarch64_stub_hash_lookup (&htab
->stub_hash_table
, stub_name
,
3203 if (stub_entry
== NULL
)
3205 /* xgettext:c-format */
3206 _bfd_error_handler (_("%pB: cannot create stub entry %s"),
3207 section
->owner
, stub_name
);
3211 stub_entry
->stub_sec
= stub_sec
;
3212 stub_entry
->stub_offset
= 0;
3213 stub_entry
->id_sec
= link_sec
;
3218 /* Add a new stub entry in the final stub section to the stub hash.
3219 Not all fields of the new stub entry are initialised. */
3221 static struct elf_aarch64_stub_hash_entry
*
3222 _bfd_aarch64_add_stub_entry_after (const char *stub_name
,
3223 asection
*link_section
,
3224 struct elf_aarch64_link_hash_table
*htab
)
3227 struct elf_aarch64_stub_hash_entry
*stub_entry
;
3230 /* Only create the actual stub if we will end up needing it. */
3231 if (htab
->fix_erratum_843419
& ERRAT_ADRP
)
3232 stub_sec
= _bfd_aarch64_get_stub_for_link_section (link_section
, htab
);
3233 stub_entry
= aarch64_stub_hash_lookup (&htab
->stub_hash_table
, stub_name
,
3235 if (stub_entry
== NULL
)
3237 _bfd_error_handler (_("cannot create stub entry %s"), stub_name
);
3241 stub_entry
->stub_sec
= stub_sec
;
3242 stub_entry
->stub_offset
= 0;
3243 stub_entry
->id_sec
= link_section
;
3250 aarch64_build_one_stub (struct bfd_hash_entry
*gen_entry
,
3251 void *in_arg ATTRIBUTE_UNUSED
)
3253 struct elf_aarch64_stub_hash_entry
*stub_entry
;
3258 bfd_vma veneered_insn_loc
;
3259 bfd_vma veneer_entry_loc
;
3260 bfd_signed_vma branch_offset
= 0;
3261 unsigned int template_size
;
3262 const uint32_t *template;
3265 /* Massage our args to the form they really have. */
3266 stub_entry
= (struct elf_aarch64_stub_hash_entry
*) gen_entry
;
3268 stub_sec
= stub_entry
->stub_sec
;
3270 /* Make a note of the offset within the stubs for this entry. */
3271 stub_entry
->stub_offset
= stub_sec
->size
;
3272 loc
= stub_sec
->contents
+ stub_entry
->stub_offset
;
3274 stub_bfd
= stub_sec
->owner
;
3276 /* This is the address of the stub destination. */
3277 sym_value
= (stub_entry
->target_value
3278 + stub_entry
->target_section
->output_offset
3279 + stub_entry
->target_section
->output_section
->vma
);
3281 if (stub_entry
->stub_type
== aarch64_stub_long_branch
)
3283 bfd_vma place
= (stub_entry
->stub_offset
+ stub_sec
->output_section
->vma
3284 + stub_sec
->output_offset
);
3286 /* See if we can relax the stub. */
3287 if (aarch64_valid_for_adrp_p (sym_value
, place
))
3288 stub_entry
->stub_type
= aarch64_select_branch_stub (sym_value
, place
);
3291 switch (stub_entry
->stub_type
)
3293 case aarch64_stub_adrp_branch
:
3294 template = aarch64_adrp_branch_stub
;
3295 template_size
= sizeof (aarch64_adrp_branch_stub
);
3297 case aarch64_stub_long_branch
:
3298 template = aarch64_long_branch_stub
;
3299 template_size
= sizeof (aarch64_long_branch_stub
);
3301 case aarch64_stub_erratum_835769_veneer
:
3302 template = aarch64_erratum_835769_stub
;
3303 template_size
= sizeof (aarch64_erratum_835769_stub
);
3305 case aarch64_stub_erratum_843419_veneer
:
3306 template = aarch64_erratum_843419_stub
;
3307 template_size
= sizeof (aarch64_erratum_843419_stub
);
3313 for (i
= 0; i
< (template_size
/ sizeof template[0]); i
++)
3315 bfd_putl32 (template[i
], loc
);
3319 template_size
= (template_size
+ 7) & ~7;
3320 stub_sec
->size
+= template_size
;
3322 switch (stub_entry
->stub_type
)
3324 case aarch64_stub_adrp_branch
:
3325 if (!aarch64_relocate (AARCH64_R (ADR_PREL_PG_HI21
), stub_bfd
, stub_sec
,
3326 stub_entry
->stub_offset
, sym_value
))
3327 /* The stub would not have been relaxed if the offset was out
3331 if (!aarch64_relocate (AARCH64_R (ADD_ABS_LO12_NC
), stub_bfd
, stub_sec
,
3332 stub_entry
->stub_offset
+ 4, sym_value
))
3336 case aarch64_stub_long_branch
:
3337 /* We want the value relative to the address 12 bytes back from the
3339 if (!aarch64_relocate (AARCH64_R (PRELNN
), stub_bfd
, stub_sec
,
3340 stub_entry
->stub_offset
+ 16, sym_value
+ 12))
3344 case aarch64_stub_erratum_835769_veneer
:
3345 veneered_insn_loc
= stub_entry
->target_section
->output_section
->vma
3346 + stub_entry
->target_section
->output_offset
3347 + stub_entry
->target_value
;
3348 veneer_entry_loc
= stub_entry
->stub_sec
->output_section
->vma
3349 + stub_entry
->stub_sec
->output_offset
3350 + stub_entry
->stub_offset
;
3351 branch_offset
= veneered_insn_loc
- veneer_entry_loc
;
3352 branch_offset
>>= 2;
3353 branch_offset
&= 0x3ffffff;
3354 bfd_putl32 (stub_entry
->veneered_insn
,
3355 stub_sec
->contents
+ stub_entry
->stub_offset
);
3356 bfd_putl32 (template[1] | branch_offset
,
3357 stub_sec
->contents
+ stub_entry
->stub_offset
+ 4);
3360 case aarch64_stub_erratum_843419_veneer
:
3361 if (!aarch64_relocate (AARCH64_R (JUMP26
), stub_bfd
, stub_sec
,
3362 stub_entry
->stub_offset
+ 4, sym_value
+ 4))
3373 /* As above, but don't actually build the stub. Just bump offset so
3374 we know stub section sizes. */
3377 aarch64_size_one_stub (struct bfd_hash_entry
*gen_entry
, void *in_arg
)
3379 struct elf_aarch64_stub_hash_entry
*stub_entry
;
3380 struct elf_aarch64_link_hash_table
*htab
;
3383 /* Massage our args to the form they really have. */
3384 stub_entry
= (struct elf_aarch64_stub_hash_entry
*) gen_entry
;
3385 htab
= (struct elf_aarch64_link_hash_table
*) in_arg
;
3387 switch (stub_entry
->stub_type
)
3389 case aarch64_stub_adrp_branch
:
3390 size
= sizeof (aarch64_adrp_branch_stub
);
3392 case aarch64_stub_long_branch
:
3393 size
= sizeof (aarch64_long_branch_stub
);
3395 case aarch64_stub_erratum_835769_veneer
:
3396 size
= sizeof (aarch64_erratum_835769_stub
);
3398 case aarch64_stub_erratum_843419_veneer
:
3400 if (htab
->fix_erratum_843419
== ERRAT_ADR
)
3402 size
= sizeof (aarch64_erratum_843419_stub
);
3409 size
= (size
+ 7) & ~7;
3410 stub_entry
->stub_sec
->size
+= size
;
3414 /* External entry points for sizing and building linker stubs. */
3416 /* Set up various things so that we can make a list of input sections
3417 for each output section included in the link. Returns -1 on error,
3418 0 when no stubs will be needed, and 1 on success. */
3421 elfNN_aarch64_setup_section_lists (bfd
*output_bfd
,
3422 struct bfd_link_info
*info
)
3425 unsigned int bfd_count
;
3426 unsigned int top_id
, top_index
;
3428 asection
**input_list
, **list
;
3430 struct elf_aarch64_link_hash_table
*htab
=
3431 elf_aarch64_hash_table (info
);
3433 if (!is_elf_hash_table (htab
))
3436 /* Count the number of input BFDs and find the top input section id. */
3437 for (input_bfd
= info
->input_bfds
, bfd_count
= 0, top_id
= 0;
3438 input_bfd
!= NULL
; input_bfd
= input_bfd
->link
.next
)
3441 for (section
= input_bfd
->sections
;
3442 section
!= NULL
; section
= section
->next
)
3444 if (top_id
< section
->id
)
3445 top_id
= section
->id
;
3448 htab
->bfd_count
= bfd_count
;
3450 amt
= sizeof (struct map_stub
) * (top_id
+ 1);
3451 htab
->stub_group
= bfd_zmalloc (amt
);
3452 if (htab
->stub_group
== NULL
)
3455 /* We can't use output_bfd->section_count here to find the top output
3456 section index as some sections may have been removed, and
3457 _bfd_strip_section_from_output doesn't renumber the indices. */
3458 for (section
= output_bfd
->sections
, top_index
= 0;
3459 section
!= NULL
; section
= section
->next
)
3461 if (top_index
< section
->index
)
3462 top_index
= section
->index
;
3465 htab
->top_index
= top_index
;
3466 amt
= sizeof (asection
*) * (top_index
+ 1);
3467 input_list
= bfd_malloc (amt
);
3468 htab
->input_list
= input_list
;
3469 if (input_list
== NULL
)
3472 /* For sections we aren't interested in, mark their entries with a
3473 value we can check later. */
3474 list
= input_list
+ top_index
;
3476 *list
= bfd_abs_section_ptr
;
3477 while (list
-- != input_list
);
3479 for (section
= output_bfd
->sections
;
3480 section
!= NULL
; section
= section
->next
)
3482 if ((section
->flags
& SEC_CODE
) != 0)
3483 input_list
[section
->index
] = NULL
;
3489 /* Used by elfNN_aarch64_next_input_section and group_sections. */
3490 #define PREV_SEC(sec) (htab->stub_group[(sec)->id].link_sec)
3492 /* The linker repeatedly calls this function for each input section,
3493 in the order that input sections are linked into output sections.
3494 Build lists of input sections to determine groupings between which
3495 we may insert linker stubs. */
3498 elfNN_aarch64_next_input_section (struct bfd_link_info
*info
, asection
*isec
)
3500 struct elf_aarch64_link_hash_table
*htab
=
3501 elf_aarch64_hash_table (info
);
3503 if (isec
->output_section
->index
<= htab
->top_index
)
3505 asection
**list
= htab
->input_list
+ isec
->output_section
->index
;
3507 if (*list
!= bfd_abs_section_ptr
)
3509 /* Steal the link_sec pointer for our list. */
3510 /* This happens to make the list in reverse order,
3511 which is what we want. */
3512 PREV_SEC (isec
) = *list
;
3518 /* See whether we can group stub sections together. Grouping stub
3519 sections may result in fewer stubs. More importantly, we need to
3520 put all .init* and .fini* stubs at the beginning of the .init or
3521 .fini output sections respectively, because glibc splits the
3522 _init and _fini functions into multiple parts. Putting a stub in
3523 the middle of a function is not a good idea. */
3526 group_sections (struct elf_aarch64_link_hash_table
*htab
,
3527 bfd_size_type stub_group_size
,
3528 bfd_boolean stubs_always_before_branch
)
3530 asection
**list
= htab
->input_list
+ htab
->top_index
;
3534 asection
*tail
= *list
;
3536 if (tail
== bfd_abs_section_ptr
)
3539 while (tail
!= NULL
)
3543 bfd_size_type total
;
3547 while ((prev
= PREV_SEC (curr
)) != NULL
3548 && ((total
+= curr
->output_offset
- prev
->output_offset
)
3552 /* OK, the size from the start of CURR to the end is less
3553 than stub_group_size and thus can be handled by one stub
3554 section. (Or the tail section is itself larger than
3555 stub_group_size, in which case we may be toast.)
3556 We should really be keeping track of the total size of
3557 stubs added here, as stubs contribute to the final output
3561 prev
= PREV_SEC (tail
);
3562 /* Set up this stub group. */
3563 htab
->stub_group
[tail
->id
].link_sec
= curr
;
3565 while (tail
!= curr
&& (tail
= prev
) != NULL
);
3567 /* But wait, there's more! Input sections up to stub_group_size
3568 bytes before the stub section can be handled by it too. */
3569 if (!stubs_always_before_branch
)
3573 && ((total
+= tail
->output_offset
- prev
->output_offset
)
3577 prev
= PREV_SEC (tail
);
3578 htab
->stub_group
[tail
->id
].link_sec
= curr
;
3584 while (list
-- != htab
->input_list
);
3586 free (htab
->input_list
);
3591 #define AARCH64_BITS(x, pos, n) (((x) >> (pos)) & ((1 << (n)) - 1))
3593 #define AARCH64_RT(insn) AARCH64_BITS (insn, 0, 5)
3594 #define AARCH64_RT2(insn) AARCH64_BITS (insn, 10, 5)
3595 #define AARCH64_RA(insn) AARCH64_BITS (insn, 10, 5)
3596 #define AARCH64_RD(insn) AARCH64_BITS (insn, 0, 5)
3597 #define AARCH64_RN(insn) AARCH64_BITS (insn, 5, 5)
3598 #define AARCH64_RM(insn) AARCH64_BITS (insn, 16, 5)
3600 #define AARCH64_MAC(insn) (((insn) & 0xff000000) == 0x9b000000)
3601 #define AARCH64_BIT(insn, n) AARCH64_BITS (insn, n, 1)
3602 #define AARCH64_OP31(insn) AARCH64_BITS (insn, 21, 3)
3603 #define AARCH64_ZR 0x1f
3605 /* All ld/st ops. See C4-182 of the ARM ARM. The encoding space for
3606 LD_PCREL, LDST_RO, LDST_UI and LDST_UIMM cover prefetch ops. */
3608 #define AARCH64_LD(insn) (AARCH64_BIT (insn, 22) == 1)
3609 #define AARCH64_LDST(insn) (((insn) & 0x0a000000) == 0x08000000)
3610 #define AARCH64_LDST_EX(insn) (((insn) & 0x3f000000) == 0x08000000)
3611 #define AARCH64_LDST_PCREL(insn) (((insn) & 0x3b000000) == 0x18000000)
3612 #define AARCH64_LDST_NAP(insn) (((insn) & 0x3b800000) == 0x28000000)
3613 #define AARCH64_LDSTP_PI(insn) (((insn) & 0x3b800000) == 0x28800000)
3614 #define AARCH64_LDSTP_O(insn) (((insn) & 0x3b800000) == 0x29000000)
3615 #define AARCH64_LDSTP_PRE(insn) (((insn) & 0x3b800000) == 0x29800000)
3616 #define AARCH64_LDST_UI(insn) (((insn) & 0x3b200c00) == 0x38000000)
3617 #define AARCH64_LDST_PIIMM(insn) (((insn) & 0x3b200c00) == 0x38000400)
3618 #define AARCH64_LDST_U(insn) (((insn) & 0x3b200c00) == 0x38000800)
3619 #define AARCH64_LDST_PREIMM(insn) (((insn) & 0x3b200c00) == 0x38000c00)
3620 #define AARCH64_LDST_RO(insn) (((insn) & 0x3b200c00) == 0x38200800)
3621 #define AARCH64_LDST_UIMM(insn) (((insn) & 0x3b000000) == 0x39000000)
3622 #define AARCH64_LDST_SIMD_M(insn) (((insn) & 0xbfbf0000) == 0x0c000000)
3623 #define AARCH64_LDST_SIMD_M_PI(insn) (((insn) & 0xbfa00000) == 0x0c800000)
3624 #define AARCH64_LDST_SIMD_S(insn) (((insn) & 0xbf9f0000) == 0x0d000000)
3625 #define AARCH64_LDST_SIMD_S_PI(insn) (((insn) & 0xbf800000) == 0x0d800000)
3627 /* Classify an INSN if it is indeed a load/store.
3629 Return TRUE if INSN is a LD/ST instruction otherwise return FALSE.
3631 For scalar LD/ST instructions PAIR is FALSE, RT is returned and RT2
3634 For LD/ST pair instructions PAIR is TRUE, RT and RT2 are returned. */
3637 aarch64_mem_op_p (uint32_t insn
, unsigned int *rt
, unsigned int *rt2
,
3638 bfd_boolean
*pair
, bfd_boolean
*load
)
3646 /* Bail out quickly if INSN doesn't fall into the load-store
3648 if (!AARCH64_LDST (insn
))
3653 if (AARCH64_LDST_EX (insn
))
3655 *rt
= AARCH64_RT (insn
);
3657 if (AARCH64_BIT (insn
, 21) == 1)
3660 *rt2
= AARCH64_RT2 (insn
);
3662 *load
= AARCH64_LD (insn
);
3665 else if (AARCH64_LDST_NAP (insn
)
3666 || AARCH64_LDSTP_PI (insn
)
3667 || AARCH64_LDSTP_O (insn
)
3668 || AARCH64_LDSTP_PRE (insn
))
3671 *rt
= AARCH64_RT (insn
);
3672 *rt2
= AARCH64_RT2 (insn
);
3673 *load
= AARCH64_LD (insn
);
3676 else if (AARCH64_LDST_PCREL (insn
)
3677 || AARCH64_LDST_UI (insn
)
3678 || AARCH64_LDST_PIIMM (insn
)
3679 || AARCH64_LDST_U (insn
)
3680 || AARCH64_LDST_PREIMM (insn
)
3681 || AARCH64_LDST_RO (insn
)
3682 || AARCH64_LDST_UIMM (insn
))
3684 *rt
= AARCH64_RT (insn
);
3686 if (AARCH64_LDST_PCREL (insn
))
3688 opc
= AARCH64_BITS (insn
, 22, 2);
3689 v
= AARCH64_BIT (insn
, 26);
3690 opc_v
= opc
| (v
<< 2);
3691 *load
= (opc_v
== 1 || opc_v
== 2 || opc_v
== 3
3692 || opc_v
== 5 || opc_v
== 7);
3695 else if (AARCH64_LDST_SIMD_M (insn
)
3696 || AARCH64_LDST_SIMD_M_PI (insn
))
3698 *rt
= AARCH64_RT (insn
);
3699 *load
= AARCH64_BIT (insn
, 22);
3700 opcode
= (insn
>> 12) & 0xf;
3727 else if (AARCH64_LDST_SIMD_S (insn
)
3728 || AARCH64_LDST_SIMD_S_PI (insn
))
3730 *rt
= AARCH64_RT (insn
);
3731 r
= (insn
>> 21) & 1;
3732 *load
= AARCH64_BIT (insn
, 22);
3733 opcode
= (insn
>> 13) & 0x7;
3745 *rt2
= *rt
+ (r
== 0 ? 2 : 3);
3753 *rt2
= *rt
+ (r
== 0 ? 2 : 3);
3765 /* Return TRUE if INSN is multiply-accumulate. */
3768 aarch64_mlxl_p (uint32_t insn
)
3770 uint32_t op31
= AARCH64_OP31 (insn
);
3772 if (AARCH64_MAC (insn
)
3773 && (op31
== 0 || op31
== 1 || op31
== 5)
3774 /* Exclude MUL instructions which are encoded as a multiple accumulate
3776 && AARCH64_RA (insn
) != AARCH64_ZR
)
3782 /* Some early revisions of the Cortex-A53 have an erratum (835769) whereby
3783 it is possible for a 64-bit multiply-accumulate instruction to generate an
3784 incorrect result. The details are quite complex and hard to
3785 determine statically, since branches in the code may exist in some
3786 circumstances, but all cases end with a memory (load, store, or
3787 prefetch) instruction followed immediately by the multiply-accumulate
3788 operation. We employ a linker patching technique, by moving the potentially
3789 affected multiply-accumulate instruction into a patch region and replacing
3790 the original instruction with a branch to the patch. This function checks
3791 if INSN_1 is the memory operation followed by a multiply-accumulate
3792 operation (INSN_2). Return TRUE if an erratum sequence is found, FALSE
3793 if INSN_1 and INSN_2 are safe. */
3796 aarch64_erratum_sequence (uint32_t insn_1
, uint32_t insn_2
)
3806 if (aarch64_mlxl_p (insn_2
)
3807 && aarch64_mem_op_p (insn_1
, &rt
, &rt2
, &pair
, &load
))
3809 /* Any SIMD memory op is independent of the subsequent MLA
3810 by definition of the erratum. */
3811 if (AARCH64_BIT (insn_1
, 26))
3814 /* If not SIMD, check for integer memory ops and MLA relationship. */
3815 rn
= AARCH64_RN (insn_2
);
3816 ra
= AARCH64_RA (insn_2
);
3817 rm
= AARCH64_RM (insn_2
);
3819 /* If this is a load and there's a true(RAW) dependency, we are safe
3820 and this is not an erratum sequence. */
3822 (rt
== rn
|| rt
== rm
|| rt
== ra
3823 || (pair
&& (rt2
== rn
|| rt2
== rm
|| rt2
== ra
))))
3826 /* We conservatively put out stubs for all other cases (including
3834 /* Used to order a list of mapping symbols by address. */
3837 elf_aarch64_compare_mapping (const void *a
, const void *b
)
3839 const elf_aarch64_section_map
*amap
= (const elf_aarch64_section_map
*) a
;
3840 const elf_aarch64_section_map
*bmap
= (const elf_aarch64_section_map
*) b
;
3842 if (amap
->vma
> bmap
->vma
)
3844 else if (amap
->vma
< bmap
->vma
)
3846 else if (amap
->type
> bmap
->type
)
3847 /* Ensure results do not depend on the host qsort for objects with
3848 multiple mapping symbols at the same address by sorting on type
3851 else if (amap
->type
< bmap
->type
)
3859 _bfd_aarch64_erratum_835769_stub_name (unsigned num_fixes
)
3861 char *stub_name
= (char *) bfd_malloc
3862 (strlen ("__erratum_835769_veneer_") + 16);
3863 if (stub_name
!= NULL
)
3864 sprintf (stub_name
,"__erratum_835769_veneer_%d", num_fixes
);
3868 /* Scan for Cortex-A53 erratum 835769 sequence.
3870 Return TRUE else FALSE on abnormal termination. */
3873 _bfd_aarch64_erratum_835769_scan (bfd
*input_bfd
,
3874 struct bfd_link_info
*info
,
3875 unsigned int *num_fixes_p
)
3878 struct elf_aarch64_link_hash_table
*htab
= elf_aarch64_hash_table (info
);
3879 unsigned int num_fixes
= *num_fixes_p
;
3884 for (section
= input_bfd
->sections
;
3886 section
= section
->next
)
3888 bfd_byte
*contents
= NULL
;
3889 struct _aarch64_elf_section_data
*sec_data
;
3892 if (elf_section_type (section
) != SHT_PROGBITS
3893 || (elf_section_flags (section
) & SHF_EXECINSTR
) == 0
3894 || (section
->flags
& SEC_EXCLUDE
) != 0
3895 || (section
->sec_info_type
== SEC_INFO_TYPE_JUST_SYMS
)
3896 || (section
->output_section
== bfd_abs_section_ptr
))
3899 if (elf_section_data (section
)->this_hdr
.contents
!= NULL
)
3900 contents
= elf_section_data (section
)->this_hdr
.contents
;
3901 else if (! bfd_malloc_and_get_section (input_bfd
, section
, &contents
))
3904 sec_data
= elf_aarch64_section_data (section
);
3906 qsort (sec_data
->map
, sec_data
->mapcount
,
3907 sizeof (elf_aarch64_section_map
), elf_aarch64_compare_mapping
);
3909 for (span
= 0; span
< sec_data
->mapcount
; span
++)
3911 unsigned int span_start
= sec_data
->map
[span
].vma
;
3912 unsigned int span_end
= ((span
== sec_data
->mapcount
- 1)
3913 ? sec_data
->map
[0].vma
+ section
->size
3914 : sec_data
->map
[span
+ 1].vma
);
3916 char span_type
= sec_data
->map
[span
].type
;
3918 if (span_type
== 'd')
3921 for (i
= span_start
; i
+ 4 < span_end
; i
+= 4)
3923 uint32_t insn_1
= bfd_getl32 (contents
+ i
);
3924 uint32_t insn_2
= bfd_getl32 (contents
+ i
+ 4);
3926 if (aarch64_erratum_sequence (insn_1
, insn_2
))
3928 struct elf_aarch64_stub_hash_entry
*stub_entry
;
3929 char *stub_name
= _bfd_aarch64_erratum_835769_stub_name (num_fixes
);
3933 stub_entry
= _bfd_aarch64_add_stub_entry_in_group (stub_name
,
3939 stub_entry
->stub_type
= aarch64_stub_erratum_835769_veneer
;
3940 stub_entry
->target_section
= section
;
3941 stub_entry
->target_value
= i
+ 4;
3942 stub_entry
->veneered_insn
= insn_2
;
3943 stub_entry
->output_name
= stub_name
;
3948 if (elf_section_data (section
)->this_hdr
.contents
== NULL
)
3952 *num_fixes_p
= num_fixes
;
3958 /* Test if instruction INSN is ADRP. */
3961 _bfd_aarch64_adrp_p (uint32_t insn
)
3963 return ((insn
& AARCH64_ADRP_OP_MASK
) == AARCH64_ADRP_OP
);
3967 /* Helper predicate to look for cortex-a53 erratum 843419 sequence 1. */
3970 _bfd_aarch64_erratum_843419_sequence_p (uint32_t insn_1
, uint32_t insn_2
,
3978 return (aarch64_mem_op_p (insn_2
, &rt
, &rt2
, &pair
, &load
)
3981 && AARCH64_LDST_UIMM (insn_3
)
3982 && AARCH64_RN (insn_3
) == AARCH64_RD (insn_1
));
3986 /* Test for the presence of Cortex-A53 erratum 843419 instruction sequence.
3988 Return TRUE if section CONTENTS at offset I contains one of the
3989 erratum 843419 sequences, otherwise return FALSE. If a sequence is
3990 seen set P_VENEER_I to the offset of the final LOAD/STORE
3991 instruction in the sequence.
3995 _bfd_aarch64_erratum_843419_p (bfd_byte
*contents
, bfd_vma vma
,
3996 bfd_vma i
, bfd_vma span_end
,
3997 bfd_vma
*p_veneer_i
)
3999 uint32_t insn_1
= bfd_getl32 (contents
+ i
);
4001 if (!_bfd_aarch64_adrp_p (insn_1
))
4004 if (span_end
< i
+ 12)
4007 uint32_t insn_2
= bfd_getl32 (contents
+ i
+ 4);
4008 uint32_t insn_3
= bfd_getl32 (contents
+ i
+ 8);
4010 if ((vma
& 0xfff) != 0xff8 && (vma
& 0xfff) != 0xffc)
4013 if (_bfd_aarch64_erratum_843419_sequence_p (insn_1
, insn_2
, insn_3
))
4015 *p_veneer_i
= i
+ 8;
4019 if (span_end
< i
+ 16)
4022 uint32_t insn_4
= bfd_getl32 (contents
+ i
+ 12);
4024 if (_bfd_aarch64_erratum_843419_sequence_p (insn_1
, insn_2
, insn_4
))
4026 *p_veneer_i
= i
+ 12;
4034 /* Resize all stub sections. */
4037 _bfd_aarch64_resize_stubs (struct elf_aarch64_link_hash_table
*htab
)
4041 /* OK, we've added some stubs. Find out the new size of the
4043 for (section
= htab
->stub_bfd
->sections
;
4044 section
!= NULL
; section
= section
->next
)
4046 /* Ignore non-stub sections. */
4047 if (!strstr (section
->name
, STUB_SUFFIX
))
4052 bfd_hash_traverse (&htab
->stub_hash_table
, aarch64_size_one_stub
, htab
);
4054 for (section
= htab
->stub_bfd
->sections
;
4055 section
!= NULL
; section
= section
->next
)
4057 if (!strstr (section
->name
, STUB_SUFFIX
))
4060 /* Add space for a branch. Add 8 bytes to keep section 8 byte aligned,
4061 as long branch stubs contain a 64-bit address. */
4065 /* Ensure all stub sections have a size which is a multiple of
4066 4096. This is important in order to ensure that the insertion
4067 of stub sections does not in itself move existing code around
4068 in such a way that new errata sequences are created. We only do this
4069 when the ADRP workaround is enabled. If only the ADR workaround is
4070 enabled then the stubs workaround won't ever be used. */
4071 if (htab
->fix_erratum_843419
& ERRAT_ADRP
)
4073 section
->size
= BFD_ALIGN (section
->size
, 0x1000);
4077 /* Construct an erratum 843419 workaround stub name. */
4080 _bfd_aarch64_erratum_843419_stub_name (asection
*input_section
,
4083 const bfd_size_type len
= 8 + 4 + 1 + 8 + 1 + 16 + 1;
4084 char *stub_name
= bfd_malloc (len
);
4086 if (stub_name
!= NULL
)
4087 snprintf (stub_name
, len
, "e843419@%04x_%08x_%" BFD_VMA_FMT
"x",
4088 input_section
->owner
->id
,
4094 /* Build a stub_entry structure describing an 843419 fixup.
4096 The stub_entry constructed is populated with the bit pattern INSN
4097 of the instruction located at OFFSET within input SECTION.
4099 Returns TRUE on success. */
4102 _bfd_aarch64_erratum_843419_fixup (uint32_t insn
,
4103 bfd_vma adrp_offset
,
4104 bfd_vma ldst_offset
,
4106 struct bfd_link_info
*info
)
4108 struct elf_aarch64_link_hash_table
*htab
= elf_aarch64_hash_table (info
);
4110 struct elf_aarch64_stub_hash_entry
*stub_entry
;
4112 stub_name
= _bfd_aarch64_erratum_843419_stub_name (section
, ldst_offset
);
4113 if (stub_name
== NULL
)
4115 stub_entry
= aarch64_stub_hash_lookup (&htab
->stub_hash_table
, stub_name
,
4123 /* We always place an 843419 workaround veneer in the stub section
4124 attached to the input section in which an erratum sequence has
4125 been found. This ensures that later in the link process (in
4126 elfNN_aarch64_write_section) when we copy the veneered
4127 instruction from the input section into the stub section the
4128 copied instruction will have had any relocations applied to it.
4129 If we placed workaround veneers in any other stub section then we
4130 could not assume that all relocations have been processed on the
4131 corresponding input section at the point we output the stub
4134 stub_entry
= _bfd_aarch64_add_stub_entry_after (stub_name
, section
, htab
);
4135 if (stub_entry
== NULL
)
4141 stub_entry
->adrp_offset
= adrp_offset
;
4142 stub_entry
->target_value
= ldst_offset
;
4143 stub_entry
->target_section
= section
;
4144 stub_entry
->stub_type
= aarch64_stub_erratum_843419_veneer
;
4145 stub_entry
->veneered_insn
= insn
;
4146 stub_entry
->output_name
= stub_name
;
4152 /* Scan an input section looking for the signature of erratum 843419.
4154 Scans input SECTION in INPUT_BFD looking for erratum 843419
4155 signatures, for each signature found a stub_entry is created
4156 describing the location of the erratum for subsequent fixup.
4158 Return TRUE on successful scan, FALSE on failure to scan.
4162 _bfd_aarch64_erratum_843419_scan (bfd
*input_bfd
, asection
*section
,
4163 struct bfd_link_info
*info
)
4165 struct elf_aarch64_link_hash_table
*htab
= elf_aarch64_hash_table (info
);
4170 if (elf_section_type (section
) != SHT_PROGBITS
4171 || (elf_section_flags (section
) & SHF_EXECINSTR
) == 0
4172 || (section
->flags
& SEC_EXCLUDE
) != 0
4173 || (section
->sec_info_type
== SEC_INFO_TYPE_JUST_SYMS
)
4174 || (section
->output_section
== bfd_abs_section_ptr
))
4179 bfd_byte
*contents
= NULL
;
4180 struct _aarch64_elf_section_data
*sec_data
;
4183 if (elf_section_data (section
)->this_hdr
.contents
!= NULL
)
4184 contents
= elf_section_data (section
)->this_hdr
.contents
;
4185 else if (! bfd_malloc_and_get_section (input_bfd
, section
, &contents
))
4188 sec_data
= elf_aarch64_section_data (section
);
4190 qsort (sec_data
->map
, sec_data
->mapcount
,
4191 sizeof (elf_aarch64_section_map
), elf_aarch64_compare_mapping
);
4193 for (span
= 0; span
< sec_data
->mapcount
; span
++)
4195 unsigned int span_start
= sec_data
->map
[span
].vma
;
4196 unsigned int span_end
= ((span
== sec_data
->mapcount
- 1)
4197 ? sec_data
->map
[0].vma
+ section
->size
4198 : sec_data
->map
[span
+ 1].vma
);
4200 char span_type
= sec_data
->map
[span
].type
;
4202 if (span_type
== 'd')
4205 for (i
= span_start
; i
+ 8 < span_end
; i
+= 4)
4207 bfd_vma vma
= (section
->output_section
->vma
4208 + section
->output_offset
4212 if (_bfd_aarch64_erratum_843419_p
4213 (contents
, vma
, i
, span_end
, &veneer_i
))
4215 uint32_t insn
= bfd_getl32 (contents
+ veneer_i
);
4217 if (!_bfd_aarch64_erratum_843419_fixup (insn
, i
, veneer_i
,
4224 if (elf_section_data (section
)->this_hdr
.contents
== NULL
)
4233 /* Determine and set the size of the stub section for a final link.
4235 The basic idea here is to examine all the relocations looking for
4236 PC-relative calls to a target that is unreachable with a "bl"
4240 elfNN_aarch64_size_stubs (bfd
*output_bfd
,
4242 struct bfd_link_info
*info
,
4243 bfd_signed_vma group_size
,
4244 asection
* (*add_stub_section
) (const char *,
4246 void (*layout_sections_again
) (void))
4248 bfd_size_type stub_group_size
;
4249 bfd_boolean stubs_always_before_branch
;
4250 bfd_boolean stub_changed
= FALSE
;
4251 struct elf_aarch64_link_hash_table
*htab
= elf_aarch64_hash_table (info
);
4252 unsigned int num_erratum_835769_fixes
= 0;
4254 /* Propagate mach to stub bfd, because it may not have been
4255 finalized when we created stub_bfd. */
4256 bfd_set_arch_mach (stub_bfd
, bfd_get_arch (output_bfd
),
4257 bfd_get_mach (output_bfd
));
4259 /* Stash our params away. */
4260 htab
->stub_bfd
= stub_bfd
;
4261 htab
->add_stub_section
= add_stub_section
;
4262 htab
->layout_sections_again
= layout_sections_again
;
4263 stubs_always_before_branch
= group_size
< 0;
4265 stub_group_size
= -group_size
;
4267 stub_group_size
= group_size
;
4269 if (stub_group_size
== 1)
4271 /* Default values. */
4272 /* AArch64 branch range is +-128MB. The value used is 1MB less. */
4273 stub_group_size
= 127 * 1024 * 1024;
4276 group_sections (htab
, stub_group_size
, stubs_always_before_branch
);
4278 (*htab
->layout_sections_again
) ();
4280 if (htab
->fix_erratum_835769
)
4284 for (input_bfd
= info
->input_bfds
;
4285 input_bfd
!= NULL
; input_bfd
= input_bfd
->link
.next
)
4286 if (!_bfd_aarch64_erratum_835769_scan (input_bfd
, info
,
4287 &num_erratum_835769_fixes
))
4290 _bfd_aarch64_resize_stubs (htab
);
4291 (*htab
->layout_sections_again
) ();
4294 if (htab
->fix_erratum_843419
!= ERRAT_NONE
)
4298 for (input_bfd
= info
->input_bfds
;
4300 input_bfd
= input_bfd
->link
.next
)
4304 for (section
= input_bfd
->sections
;
4306 section
= section
->next
)
4307 if (!_bfd_aarch64_erratum_843419_scan (input_bfd
, section
, info
))
4311 _bfd_aarch64_resize_stubs (htab
);
4312 (*htab
->layout_sections_again
) ();
4319 for (input_bfd
= info
->input_bfds
;
4320 input_bfd
!= NULL
; input_bfd
= input_bfd
->link
.next
)
4322 Elf_Internal_Shdr
*symtab_hdr
;
4324 Elf_Internal_Sym
*local_syms
= NULL
;
4326 /* We'll need the symbol table in a second. */
4327 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
4328 if (symtab_hdr
->sh_info
== 0)
4331 /* Walk over each section attached to the input bfd. */
4332 for (section
= input_bfd
->sections
;
4333 section
!= NULL
; section
= section
->next
)
4335 Elf_Internal_Rela
*internal_relocs
, *irelaend
, *irela
;
4337 /* If there aren't any relocs, then there's nothing more
4339 if ((section
->flags
& SEC_RELOC
) == 0
4340 || section
->reloc_count
== 0
4341 || (section
->flags
& SEC_CODE
) == 0)
4344 /* If this section is a link-once section that will be
4345 discarded, then don't create any stubs. */
4346 if (section
->output_section
== NULL
4347 || section
->output_section
->owner
!= output_bfd
)
4350 /* Get the relocs. */
4352 = _bfd_elf_link_read_relocs (input_bfd
, section
, NULL
,
4353 NULL
, info
->keep_memory
);
4354 if (internal_relocs
== NULL
)
4355 goto error_ret_free_local
;
4357 /* Now examine each relocation. */
4358 irela
= internal_relocs
;
4359 irelaend
= irela
+ section
->reloc_count
;
4360 for (; irela
< irelaend
; irela
++)
4362 unsigned int r_type
, r_indx
;
4363 enum elf_aarch64_stub_type stub_type
;
4364 struct elf_aarch64_stub_hash_entry
*stub_entry
;
4367 bfd_vma destination
;
4368 struct elf_aarch64_link_hash_entry
*hash
;
4369 const char *sym_name
;
4371 const asection
*id_sec
;
4372 unsigned char st_type
;
4375 r_type
= ELFNN_R_TYPE (irela
->r_info
);
4376 r_indx
= ELFNN_R_SYM (irela
->r_info
);
4378 if (r_type
>= (unsigned int) R_AARCH64_end
)
4380 bfd_set_error (bfd_error_bad_value
);
4381 error_ret_free_internal
:
4382 if (elf_section_data (section
)->relocs
== NULL
)
4383 free (internal_relocs
);
4384 goto error_ret_free_local
;
4387 /* Only look for stubs on unconditional branch and
4388 branch and link instructions. */
4389 if (r_type
!= (unsigned int) AARCH64_R (CALL26
)
4390 && r_type
!= (unsigned int) AARCH64_R (JUMP26
))
4393 /* Now determine the call target, its name, value,
4400 if (r_indx
< symtab_hdr
->sh_info
)
4402 /* It's a local symbol. */
4403 Elf_Internal_Sym
*sym
;
4404 Elf_Internal_Shdr
*hdr
;
4406 if (local_syms
== NULL
)
4409 = (Elf_Internal_Sym
*) symtab_hdr
->contents
;
4410 if (local_syms
== NULL
)
4412 = bfd_elf_get_elf_syms (input_bfd
, symtab_hdr
,
4413 symtab_hdr
->sh_info
, 0,
4415 if (local_syms
== NULL
)
4416 goto error_ret_free_internal
;
4419 sym
= local_syms
+ r_indx
;
4420 hdr
= elf_elfsections (input_bfd
)[sym
->st_shndx
];
4421 sym_sec
= hdr
->bfd_section
;
4423 /* This is an undefined symbol. It can never
4427 if (ELF_ST_TYPE (sym
->st_info
) != STT_SECTION
)
4428 sym_value
= sym
->st_value
;
4429 destination
= (sym_value
+ irela
->r_addend
4430 + sym_sec
->output_offset
4431 + sym_sec
->output_section
->vma
);
4432 st_type
= ELF_ST_TYPE (sym
->st_info
);
4434 = bfd_elf_string_from_elf_section (input_bfd
,
4435 symtab_hdr
->sh_link
,
4442 e_indx
= r_indx
- symtab_hdr
->sh_info
;
4443 hash
= ((struct elf_aarch64_link_hash_entry
*)
4444 elf_sym_hashes (input_bfd
)[e_indx
]);
4446 while (hash
->root
.root
.type
== bfd_link_hash_indirect
4447 || hash
->root
.root
.type
== bfd_link_hash_warning
)
4448 hash
= ((struct elf_aarch64_link_hash_entry
*)
4449 hash
->root
.root
.u
.i
.link
);
4451 if (hash
->root
.root
.type
== bfd_link_hash_defined
4452 || hash
->root
.root
.type
== bfd_link_hash_defweak
)
4454 struct elf_aarch64_link_hash_table
*globals
=
4455 elf_aarch64_hash_table (info
);
4456 sym_sec
= hash
->root
.root
.u
.def
.section
;
4457 sym_value
= hash
->root
.root
.u
.def
.value
;
4458 /* For a destination in a shared library,
4459 use the PLT stub as target address to
4460 decide whether a branch stub is
4462 if (globals
->root
.splt
!= NULL
&& hash
!= NULL
4463 && hash
->root
.plt
.offset
!= (bfd_vma
) - 1)
4465 sym_sec
= globals
->root
.splt
;
4466 sym_value
= hash
->root
.plt
.offset
;
4467 if (sym_sec
->output_section
!= NULL
)
4468 destination
= (sym_value
4469 + sym_sec
->output_offset
4471 sym_sec
->output_section
->vma
);
4473 else if (sym_sec
->output_section
!= NULL
)
4474 destination
= (sym_value
+ irela
->r_addend
4475 + sym_sec
->output_offset
4476 + sym_sec
->output_section
->vma
);
4478 else if (hash
->root
.root
.type
== bfd_link_hash_undefined
4479 || (hash
->root
.root
.type
4480 == bfd_link_hash_undefweak
))
4482 /* For a shared library, use the PLT stub as
4483 target address to decide whether a long
4484 branch stub is needed.
4485 For absolute code, they cannot be handled. */
4486 struct elf_aarch64_link_hash_table
*globals
=
4487 elf_aarch64_hash_table (info
);
4489 if (globals
->root
.splt
!= NULL
&& hash
!= NULL
4490 && hash
->root
.plt
.offset
!= (bfd_vma
) - 1)
4492 sym_sec
= globals
->root
.splt
;
4493 sym_value
= hash
->root
.plt
.offset
;
4494 if (sym_sec
->output_section
!= NULL
)
4495 destination
= (sym_value
4496 + sym_sec
->output_offset
4498 sym_sec
->output_section
->vma
);
4505 bfd_set_error (bfd_error_bad_value
);
4506 goto error_ret_free_internal
;
4508 st_type
= ELF_ST_TYPE (hash
->root
.type
);
4509 sym_name
= hash
->root
.root
.root
.string
;
4512 /* Determine what (if any) linker stub is needed. */
4513 stub_type
= aarch64_type_of_stub (section
, irela
, sym_sec
,
4514 st_type
, destination
);
4515 if (stub_type
== aarch64_stub_none
)
4518 /* Support for grouping stub sections. */
4519 id_sec
= htab
->stub_group
[section
->id
].link_sec
;
4521 /* Get the name of this stub. */
4522 stub_name
= elfNN_aarch64_stub_name (id_sec
, sym_sec
, hash
,
4525 goto error_ret_free_internal
;
4528 aarch64_stub_hash_lookup (&htab
->stub_hash_table
,
4529 stub_name
, FALSE
, FALSE
);
4530 if (stub_entry
!= NULL
)
4532 /* The proper stub has already been created. */
4534 /* Always update this stub's target since it may have
4535 changed after layout. */
4536 stub_entry
->target_value
= sym_value
+ irela
->r_addend
;
4540 stub_entry
= _bfd_aarch64_add_stub_entry_in_group
4541 (stub_name
, section
, htab
);
4542 if (stub_entry
== NULL
)
4545 goto error_ret_free_internal
;
4548 stub_entry
->target_value
= sym_value
+ irela
->r_addend
;
4549 stub_entry
->target_section
= sym_sec
;
4550 stub_entry
->stub_type
= stub_type
;
4551 stub_entry
->h
= hash
;
4552 stub_entry
->st_type
= st_type
;
4554 if (sym_name
== NULL
)
4555 sym_name
= "unnamed";
4556 len
= sizeof (STUB_ENTRY_NAME
) + strlen (sym_name
);
4557 stub_entry
->output_name
= bfd_alloc (htab
->stub_bfd
, len
);
4558 if (stub_entry
->output_name
== NULL
)
4561 goto error_ret_free_internal
;
4564 snprintf (stub_entry
->output_name
, len
, STUB_ENTRY_NAME
,
4567 stub_changed
= TRUE
;
4570 /* We're done with the internal relocs, free them. */
4571 if (elf_section_data (section
)->relocs
== NULL
)
4572 free (internal_relocs
);
4579 _bfd_aarch64_resize_stubs (htab
);
4581 /* Ask the linker to do its stuff. */
4582 (*htab
->layout_sections_again
) ();
4583 stub_changed
= FALSE
;
4588 error_ret_free_local
:
4592 /* Build all the stubs associated with the current output file. The
4593 stubs are kept in a hash table attached to the main linker hash
4594 table. We also set up the .plt entries for statically linked PIC
4595 functions here. This function is called via aarch64_elf_finish in the
4599 elfNN_aarch64_build_stubs (struct bfd_link_info
*info
)
4602 struct bfd_hash_table
*table
;
4603 struct elf_aarch64_link_hash_table
*htab
;
4605 htab
= elf_aarch64_hash_table (info
);
4607 for (stub_sec
= htab
->stub_bfd
->sections
;
4608 stub_sec
!= NULL
; stub_sec
= stub_sec
->next
)
4612 /* Ignore non-stub sections. */
4613 if (!strstr (stub_sec
->name
, STUB_SUFFIX
))
4616 /* Allocate memory to hold the linker stubs. */
4617 size
= stub_sec
->size
;
4618 stub_sec
->contents
= bfd_zalloc (htab
->stub_bfd
, size
);
4619 if (stub_sec
->contents
== NULL
&& size
!= 0)
4623 /* Add a branch around the stub section, and a nop, to keep it 8 byte
4624 aligned, as long branch stubs contain a 64-bit address. */
4625 bfd_putl32 (0x14000000 | (size
>> 2), stub_sec
->contents
);
4626 bfd_putl32 (INSN_NOP
, stub_sec
->contents
+ 4);
4627 stub_sec
->size
+= 8;
4630 /* Build the stubs as directed by the stub hash table. */
4631 table
= &htab
->stub_hash_table
;
4632 bfd_hash_traverse (table
, aarch64_build_one_stub
, info
);
4638 /* Add an entry to the code/data map for section SEC. */
4641 elfNN_aarch64_section_map_add (asection
*sec
, char type
, bfd_vma vma
)
4643 struct _aarch64_elf_section_data
*sec_data
=
4644 elf_aarch64_section_data (sec
);
4645 unsigned int newidx
;
4647 if (sec_data
->map
== NULL
)
4649 sec_data
->map
= bfd_malloc (sizeof (elf_aarch64_section_map
));
4650 sec_data
->mapcount
= 0;
4651 sec_data
->mapsize
= 1;
4654 newidx
= sec_data
->mapcount
++;
4656 if (sec_data
->mapcount
> sec_data
->mapsize
)
4658 sec_data
->mapsize
*= 2;
4659 sec_data
->map
= bfd_realloc_or_free
4660 (sec_data
->map
, sec_data
->mapsize
* sizeof (elf_aarch64_section_map
));
4665 sec_data
->map
[newidx
].vma
= vma
;
4666 sec_data
->map
[newidx
].type
= type
;
4671 /* Initialise maps of insn/data for input BFDs. */
4673 bfd_elfNN_aarch64_init_maps (bfd
*abfd
)
4675 Elf_Internal_Sym
*isymbuf
;
4676 Elf_Internal_Shdr
*hdr
;
4677 unsigned int i
, localsyms
;
4679 /* Make sure that we are dealing with an AArch64 elf binary. */
4680 if (!is_aarch64_elf (abfd
))
4683 if ((abfd
->flags
& DYNAMIC
) != 0)
4686 hdr
= &elf_symtab_hdr (abfd
);
4687 localsyms
= hdr
->sh_info
;
4689 /* Obtain a buffer full of symbols for this BFD. The hdr->sh_info field
4690 should contain the number of local symbols, which should come before any
4691 global symbols. Mapping symbols are always local. */
4692 isymbuf
= bfd_elf_get_elf_syms (abfd
, hdr
, localsyms
, 0, NULL
, NULL
, NULL
);
4694 /* No internal symbols read? Skip this BFD. */
4695 if (isymbuf
== NULL
)
4698 for (i
= 0; i
< localsyms
; i
++)
4700 Elf_Internal_Sym
*isym
= &isymbuf
[i
];
4701 asection
*sec
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
4704 if (sec
!= NULL
&& ELF_ST_BIND (isym
->st_info
) == STB_LOCAL
)
4706 name
= bfd_elf_string_from_elf_section (abfd
,
4710 if (bfd_is_aarch64_special_symbol_name
4711 (name
, BFD_AARCH64_SPECIAL_SYM_TYPE_MAP
))
4712 elfNN_aarch64_section_map_add (sec
, name
[1], isym
->st_value
);
4718 setup_plt_values (struct bfd_link_info
*link_info
,
4719 aarch64_plt_type plt_type
)
4721 struct elf_aarch64_link_hash_table
*globals
;
4722 globals
= elf_aarch64_hash_table (link_info
);
4724 if (plt_type
== PLT_BTI_PAC
)
4726 globals
->plt0_entry
= elfNN_aarch64_small_plt0_bti_entry
;
4728 /* Only in ET_EXEC we need PLTn with BTI. */
4729 if (bfd_link_pde (link_info
))
4731 globals
->plt_entry_size
= PLT_BTI_PAC_SMALL_ENTRY_SIZE
;
4732 globals
->plt_entry
= elfNN_aarch64_small_plt_bti_pac_entry
;
4736 globals
->plt_entry_size
= PLT_PAC_SMALL_ENTRY_SIZE
;
4737 globals
->plt_entry
= elfNN_aarch64_small_plt_pac_entry
;
4740 else if (plt_type
== PLT_BTI
)
4742 globals
->plt0_entry
= elfNN_aarch64_small_plt0_bti_entry
;
4744 /* Only in ET_EXEC we need PLTn with BTI. */
4745 if (bfd_link_pde (link_info
))
4747 globals
->plt_entry_size
= PLT_BTI_SMALL_ENTRY_SIZE
;
4748 globals
->plt_entry
= elfNN_aarch64_small_plt_bti_entry
;
4751 else if (plt_type
== PLT_PAC
)
4753 globals
->plt_entry_size
= PLT_PAC_SMALL_ENTRY_SIZE
;
4754 globals
->plt_entry
= elfNN_aarch64_small_plt_pac_entry
;
4758 /* Set option values needed during linking. */
4760 bfd_elfNN_aarch64_set_options (struct bfd
*output_bfd
,
4761 struct bfd_link_info
*link_info
,
4763 int no_wchar_warn
, int pic_veneer
,
4764 int fix_erratum_835769
,
4765 erratum_84319_opts fix_erratum_843419
,
4766 int no_apply_dynamic_relocs
,
4767 aarch64_bti_pac_info bp_info
)
4769 struct elf_aarch64_link_hash_table
*globals
;
4771 globals
= elf_aarch64_hash_table (link_info
);
4772 globals
->pic_veneer
= pic_veneer
;
4773 globals
->fix_erratum_835769
= fix_erratum_835769
;
4774 /* If the default options are used, then ERRAT_ADR will be set by default
4775 which will enable the ADRP->ADR workaround for the erratum 843419
4777 globals
->fix_erratum_843419
= fix_erratum_843419
;
4778 globals
->no_apply_dynamic_relocs
= no_apply_dynamic_relocs
;
4780 BFD_ASSERT (is_aarch64_elf (output_bfd
));
4781 elf_aarch64_tdata (output_bfd
)->no_enum_size_warning
= no_enum_warn
;
4782 elf_aarch64_tdata (output_bfd
)->no_wchar_size_warning
= no_wchar_warn
;
4784 switch (bp_info
.bti_type
)
4787 elf_aarch64_tdata (output_bfd
)->no_bti_warn
= 0;
4788 elf_aarch64_tdata (output_bfd
)->gnu_and_prop
4789 |= GNU_PROPERTY_AARCH64_FEATURE_1_BTI
;
4795 elf_aarch64_tdata (output_bfd
)->plt_type
= bp_info
.plt_type
;
4796 setup_plt_values (link_info
, bp_info
.plt_type
);
4800 aarch64_calculate_got_entry_vma (struct elf_link_hash_entry
*h
,
4801 struct elf_aarch64_link_hash_table
4802 *globals
, struct bfd_link_info
*info
,
4803 bfd_vma value
, bfd
*output_bfd
,
4804 bfd_boolean
*unresolved_reloc_p
)
4806 bfd_vma off
= (bfd_vma
) - 1;
4807 asection
*basegot
= globals
->root
.sgot
;
4808 bfd_boolean dyn
= globals
->root
.dynamic_sections_created
;
4812 BFD_ASSERT (basegot
!= NULL
);
4813 off
= h
->got
.offset
;
4814 BFD_ASSERT (off
!= (bfd_vma
) - 1);
4815 if (!WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, bfd_link_pic (info
), h
)
4816 || (bfd_link_pic (info
)
4817 && SYMBOL_REFERENCES_LOCAL (info
, h
))
4818 || (ELF_ST_VISIBILITY (h
->other
)
4819 && h
->root
.type
== bfd_link_hash_undefweak
))
4821 /* This is actually a static link, or it is a -Bsymbolic link
4822 and the symbol is defined locally. We must initialize this
4823 entry in the global offset table. Since the offset must
4824 always be a multiple of 8 (4 in the case of ILP32), we use
4825 the least significant bit to record whether we have
4826 initialized it already.
4827 When doing a dynamic link, we create a .rel(a).got relocation
4828 entry to initialize the value. This is done in the
4829 finish_dynamic_symbol routine. */
4834 bfd_put_NN (output_bfd
, value
, basegot
->contents
+ off
);
4839 *unresolved_reloc_p
= FALSE
;
4841 off
= off
+ basegot
->output_section
->vma
+ basegot
->output_offset
;
4847 /* Change R_TYPE to a more efficient access model where possible,
4848 return the new reloc type. */
4850 static bfd_reloc_code_real_type
4851 aarch64_tls_transition_without_check (bfd_reloc_code_real_type r_type
,
4852 struct elf_link_hash_entry
*h
)
4854 bfd_boolean is_local
= h
== NULL
;
4858 case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21
:
4859 case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21
:
4861 ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1
4862 : BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21
);
4864 case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21
:
4866 ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC
4869 case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19
:
4871 ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1
4872 : BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19
);
4874 case BFD_RELOC_AARCH64_TLSDESC_LDR
:
4876 ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC
4877 : BFD_RELOC_AARCH64_NONE
);
4879 case BFD_RELOC_AARCH64_TLSDESC_OFF_G0_NC
:
4881 ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1_NC
4882 : BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G0_NC
);
4884 case BFD_RELOC_AARCH64_TLSDESC_OFF_G1
:
4886 ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G2
4887 : BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G1
);
4889 case BFD_RELOC_AARCH64_TLSDESC_LDNN_LO12_NC
:
4890 case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC
:
4892 ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC
4893 : BFD_RELOC_AARCH64_TLSIE_LDNN_GOTTPREL_LO12_NC
);
4895 case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21
:
4896 return is_local
? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1
: r_type
;
4898 case BFD_RELOC_AARCH64_TLSIE_LDNN_GOTTPREL_LO12_NC
:
4899 return is_local
? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC
: r_type
;
4901 case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19
:
4904 case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21
:
4906 ? BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_HI12
4907 : BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19
);
4909 case BFD_RELOC_AARCH64_TLSDESC_ADD
:
4910 case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12
:
4911 case BFD_RELOC_AARCH64_TLSDESC_CALL
:
4912 /* Instructions with these relocations will become NOPs. */
4913 return BFD_RELOC_AARCH64_NONE
;
4915 case BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC
:
4916 case BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21
:
4917 case BFD_RELOC_AARCH64_TLSLD_ADR_PREL21
:
4918 return is_local
? BFD_RELOC_AARCH64_NONE
: r_type
;
4921 case BFD_RELOC_AARCH64_TLSGD_MOVW_G0_NC
:
4923 ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1_NC
4924 : BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G0_NC
;
4926 case BFD_RELOC_AARCH64_TLSGD_MOVW_G1
:
4928 ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G2
4929 : BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G1
;
4940 aarch64_reloc_got_type (bfd_reloc_code_real_type r_type
)
4944 case BFD_RELOC_AARCH64_ADR_GOT_PAGE
:
4945 case BFD_RELOC_AARCH64_GOT_LD_PREL19
:
4946 case BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14
:
4947 case BFD_RELOC_AARCH64_LD32_GOT_LO12_NC
:
4948 case BFD_RELOC_AARCH64_LD64_GOTOFF_LO15
:
4949 case BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15
:
4950 case BFD_RELOC_AARCH64_LD64_GOT_LO12_NC
:
4951 case BFD_RELOC_AARCH64_MOVW_GOTOFF_G0_NC
:
4952 case BFD_RELOC_AARCH64_MOVW_GOTOFF_G1
:
4955 case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC
:
4956 case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21
:
4957 case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21
:
4958 case BFD_RELOC_AARCH64_TLSGD_MOVW_G0_NC
:
4959 case BFD_RELOC_AARCH64_TLSGD_MOVW_G1
:
4960 case BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC
:
4961 case BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21
:
4962 case BFD_RELOC_AARCH64_TLSLD_ADR_PREL21
:
4965 case BFD_RELOC_AARCH64_TLSDESC_ADD
:
4966 case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12
:
4967 case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21
:
4968 case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21
:
4969 case BFD_RELOC_AARCH64_TLSDESC_CALL
:
4970 case BFD_RELOC_AARCH64_TLSDESC_LD32_LO12_NC
:
4971 case BFD_RELOC_AARCH64_TLSDESC_LD64_LO12
:
4972 case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19
:
4973 case BFD_RELOC_AARCH64_TLSDESC_LDR
:
4974 case BFD_RELOC_AARCH64_TLSDESC_OFF_G0_NC
:
4975 case BFD_RELOC_AARCH64_TLSDESC_OFF_G1
:
4976 return GOT_TLSDESC_GD
;
4978 case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21
:
4979 case BFD_RELOC_AARCH64_TLSIE_LD32_GOTTPREL_LO12_NC
:
4980 case BFD_RELOC_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC
:
4981 case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19
:
4982 case BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G0_NC
:
4983 case BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G1
:
4993 aarch64_can_relax_tls (bfd
*input_bfd
,
4994 struct bfd_link_info
*info
,
4995 bfd_reloc_code_real_type r_type
,
4996 struct elf_link_hash_entry
*h
,
4997 unsigned long r_symndx
)
4999 unsigned int symbol_got_type
;
5000 unsigned int reloc_got_type
;
5002 if (! IS_AARCH64_TLS_RELAX_RELOC (r_type
))
5005 symbol_got_type
= elfNN_aarch64_symbol_got_type (h
, input_bfd
, r_symndx
);
5006 reloc_got_type
= aarch64_reloc_got_type (r_type
);
5008 if (symbol_got_type
== GOT_TLS_IE
&& GOT_TLS_GD_ANY_P (reloc_got_type
))
5011 if (!bfd_link_executable (info
))
5014 if (h
&& h
->root
.type
== bfd_link_hash_undefweak
)
5020 /* Given the relocation code R_TYPE, return the relaxed bfd reloc
5023 static bfd_reloc_code_real_type
5024 aarch64_tls_transition (bfd
*input_bfd
,
5025 struct bfd_link_info
*info
,
5026 unsigned int r_type
,
5027 struct elf_link_hash_entry
*h
,
5028 unsigned long r_symndx
)
5030 bfd_reloc_code_real_type bfd_r_type
5031 = elfNN_aarch64_bfd_reloc_from_type (input_bfd
, r_type
);
5033 if (! aarch64_can_relax_tls (input_bfd
, info
, bfd_r_type
, h
, r_symndx
))
5036 return aarch64_tls_transition_without_check (bfd_r_type
, h
);
5039 /* Return the base VMA address which should be subtracted from real addresses
5040 when resolving R_AARCH64_TLS_DTPREL relocation. */
5043 dtpoff_base (struct bfd_link_info
*info
)
5045 /* If tls_sec is NULL, we should have signalled an error already. */
5046 BFD_ASSERT (elf_hash_table (info
)->tls_sec
!= NULL
);
5047 return elf_hash_table (info
)->tls_sec
->vma
;
5050 /* Return the base VMA address which should be subtracted from real addresses
5051 when resolving R_AARCH64_TLS_GOTTPREL64 relocations. */
5054 tpoff_base (struct bfd_link_info
*info
)
5056 struct elf_link_hash_table
*htab
= elf_hash_table (info
);
5058 /* If tls_sec is NULL, we should have signalled an error already. */
5059 BFD_ASSERT (htab
->tls_sec
!= NULL
);
5061 bfd_vma base
= align_power ((bfd_vma
) TCB_SIZE
,
5062 htab
->tls_sec
->alignment_power
);
5063 return htab
->tls_sec
->vma
- base
;
5067 symbol_got_offset_ref (bfd
*input_bfd
, struct elf_link_hash_entry
*h
,
5068 unsigned long r_symndx
)
5070 /* Calculate the address of the GOT entry for symbol
5071 referred to in h. */
5073 return &h
->got
.offset
;
5077 struct elf_aarch64_local_symbol
*l
;
5079 l
= elf_aarch64_locals (input_bfd
);
5080 return &l
[r_symndx
].got_offset
;
5085 symbol_got_offset_mark (bfd
*input_bfd
, struct elf_link_hash_entry
*h
,
5086 unsigned long r_symndx
)
5089 p
= symbol_got_offset_ref (input_bfd
, h
, r_symndx
);
5094 symbol_got_offset_mark_p (bfd
*input_bfd
, struct elf_link_hash_entry
*h
,
5095 unsigned long r_symndx
)
5098 value
= * symbol_got_offset_ref (input_bfd
, h
, r_symndx
);
5103 symbol_got_offset (bfd
*input_bfd
, struct elf_link_hash_entry
*h
,
5104 unsigned long r_symndx
)
5107 value
= * symbol_got_offset_ref (input_bfd
, h
, r_symndx
);
5113 symbol_tlsdesc_got_offset_ref (bfd
*input_bfd
, struct elf_link_hash_entry
*h
,
5114 unsigned long r_symndx
)
5116 /* Calculate the address of the GOT entry for symbol
5117 referred to in h. */
5120 struct elf_aarch64_link_hash_entry
*eh
;
5121 eh
= (struct elf_aarch64_link_hash_entry
*) h
;
5122 return &eh
->tlsdesc_got_jump_table_offset
;
5127 struct elf_aarch64_local_symbol
*l
;
5129 l
= elf_aarch64_locals (input_bfd
);
5130 return &l
[r_symndx
].tlsdesc_got_jump_table_offset
;
5135 symbol_tlsdesc_got_offset_mark (bfd
*input_bfd
, struct elf_link_hash_entry
*h
,
5136 unsigned long r_symndx
)
5139 p
= symbol_tlsdesc_got_offset_ref (input_bfd
, h
, r_symndx
);
5144 symbol_tlsdesc_got_offset_mark_p (bfd
*input_bfd
,
5145 struct elf_link_hash_entry
*h
,
5146 unsigned long r_symndx
)
5149 value
= * symbol_tlsdesc_got_offset_ref (input_bfd
, h
, r_symndx
);
5154 symbol_tlsdesc_got_offset (bfd
*input_bfd
, struct elf_link_hash_entry
*h
,
5155 unsigned long r_symndx
)
5158 value
= * symbol_tlsdesc_got_offset_ref (input_bfd
, h
, r_symndx
);
5163 /* Data for make_branch_to_erratum_835769_stub(). */
5165 struct erratum_835769_branch_to_stub_data
5167 struct bfd_link_info
*info
;
5168 asection
*output_section
;
5172 /* Helper to insert branches to erratum 835769 stubs in the right
5173 places for a particular section. */
5176 make_branch_to_erratum_835769_stub (struct bfd_hash_entry
*gen_entry
,
5179 struct elf_aarch64_stub_hash_entry
*stub_entry
;
5180 struct erratum_835769_branch_to_stub_data
*data
;
5182 unsigned long branch_insn
= 0;
5183 bfd_vma veneered_insn_loc
, veneer_entry_loc
;
5184 bfd_signed_vma branch_offset
;
5185 unsigned int target
;
5188 stub_entry
= (struct elf_aarch64_stub_hash_entry
*) gen_entry
;
5189 data
= (struct erratum_835769_branch_to_stub_data
*) in_arg
;
5191 if (stub_entry
->target_section
!= data
->output_section
5192 || stub_entry
->stub_type
!= aarch64_stub_erratum_835769_veneer
)
5195 contents
= data
->contents
;
5196 veneered_insn_loc
= stub_entry
->target_section
->output_section
->vma
5197 + stub_entry
->target_section
->output_offset
5198 + stub_entry
->target_value
;
5199 veneer_entry_loc
= stub_entry
->stub_sec
->output_section
->vma
5200 + stub_entry
->stub_sec
->output_offset
5201 + stub_entry
->stub_offset
;
5202 branch_offset
= veneer_entry_loc
- veneered_insn_loc
;
5204 abfd
= stub_entry
->target_section
->owner
;
5205 if (!aarch64_valid_branch_p (veneer_entry_loc
, veneered_insn_loc
))
5207 (_("%pB: error: erratum 835769 stub out "
5208 "of range (input file too large)"), abfd
);
5210 target
= stub_entry
->target_value
;
5211 branch_insn
= 0x14000000;
5212 branch_offset
>>= 2;
5213 branch_offset
&= 0x3ffffff;
5214 branch_insn
|= branch_offset
;
5215 bfd_putl32 (branch_insn
, &contents
[target
]);
5222 _bfd_aarch64_erratum_843419_branch_to_stub (struct bfd_hash_entry
*gen_entry
,
5225 struct elf_aarch64_stub_hash_entry
*stub_entry
5226 = (struct elf_aarch64_stub_hash_entry
*) gen_entry
;
5227 struct erratum_835769_branch_to_stub_data
*data
5228 = (struct erratum_835769_branch_to_stub_data
*) in_arg
;
5229 struct bfd_link_info
*info
;
5230 struct elf_aarch64_link_hash_table
*htab
;
5238 contents
= data
->contents
;
5239 section
= data
->output_section
;
5241 htab
= elf_aarch64_hash_table (info
);
5243 if (stub_entry
->target_section
!= section
5244 || stub_entry
->stub_type
!= aarch64_stub_erratum_843419_veneer
)
5247 BFD_ASSERT (((htab
->fix_erratum_843419
& ERRAT_ADRP
) && stub_entry
->stub_sec
)
5248 || (htab
->fix_erratum_843419
& ERRAT_ADR
));
5250 /* Only update the stub section if we have one. We should always have one if
5251 we're allowed to use the ADRP errata workaround, otherwise it is not
5253 if (stub_entry
->stub_sec
)
5255 insn
= bfd_getl32 (contents
+ stub_entry
->target_value
);
5257 stub_entry
->stub_sec
->contents
+ stub_entry
->stub_offset
);
5260 place
= (section
->output_section
->vma
+ section
->output_offset
5261 + stub_entry
->adrp_offset
);
5262 insn
= bfd_getl32 (contents
+ stub_entry
->adrp_offset
);
5264 if (!_bfd_aarch64_adrp_p (insn
))
5267 bfd_signed_vma imm
=
5268 (_bfd_aarch64_sign_extend
5269 ((bfd_vma
) _bfd_aarch64_decode_adrp_imm (insn
) << 12, 33)
5272 if ((htab
->fix_erratum_843419
& ERRAT_ADR
)
5273 && (imm
>= AARCH64_MIN_ADRP_IMM
&& imm
<= AARCH64_MAX_ADRP_IMM
))
5275 insn
= (_bfd_aarch64_reencode_adr_imm (AARCH64_ADR_OP
, imm
)
5276 | AARCH64_RT (insn
));
5277 bfd_putl32 (insn
, contents
+ stub_entry
->adrp_offset
);
5278 /* Stub is not needed, don't map it out. */
5279 stub_entry
->stub_type
= aarch64_stub_none
;
5281 else if (htab
->fix_erratum_843419
& ERRAT_ADRP
)
5283 bfd_vma veneered_insn_loc
;
5284 bfd_vma veneer_entry_loc
;
5285 bfd_signed_vma branch_offset
;
5286 uint32_t branch_insn
;
5288 veneered_insn_loc
= stub_entry
->target_section
->output_section
->vma
5289 + stub_entry
->target_section
->output_offset
5290 + stub_entry
->target_value
;
5291 veneer_entry_loc
= stub_entry
->stub_sec
->output_section
->vma
5292 + stub_entry
->stub_sec
->output_offset
5293 + stub_entry
->stub_offset
;
5294 branch_offset
= veneer_entry_loc
- veneered_insn_loc
;
5296 abfd
= stub_entry
->target_section
->owner
;
5297 if (!aarch64_valid_branch_p (veneer_entry_loc
, veneered_insn_loc
))
5299 (_("%pB: error: erratum 843419 stub out "
5300 "of range (input file too large)"), abfd
);
5302 branch_insn
= 0x14000000;
5303 branch_offset
>>= 2;
5304 branch_offset
&= 0x3ffffff;
5305 branch_insn
|= branch_offset
;
5306 bfd_putl32 (branch_insn
, contents
+ stub_entry
->target_value
);
5310 abfd
= stub_entry
->target_section
->owner
;
5312 (_("%pB: error: erratum 843419 immediate 0x%lx "
5313 "out of range for ADR (input file too large) and "
5314 "--fix-cortex-a53-843419=adr used. Run the linker with "
5315 "--fix-cortex-a53-843419=full instead"), abfd
, imm
);
5316 bfd_set_error (bfd_error_bad_value
);
5317 /* This function is called inside a hashtable traversal and the error
5318 handlers called above turn into non-fatal errors. Which means this
5319 case ld returns an exit code 0 and also produces a broken object file.
5320 To prevent this, issue a hard abort. */
5328 elfNN_aarch64_write_section (bfd
*output_bfd ATTRIBUTE_UNUSED
,
5329 struct bfd_link_info
*link_info
,
5334 struct elf_aarch64_link_hash_table
*globals
=
5335 elf_aarch64_hash_table (link_info
);
5337 if (globals
== NULL
)
5340 /* Fix code to point to erratum 835769 stubs. */
5341 if (globals
->fix_erratum_835769
)
5343 struct erratum_835769_branch_to_stub_data data
;
5345 data
.info
= link_info
;
5346 data
.output_section
= sec
;
5347 data
.contents
= contents
;
5348 bfd_hash_traverse (&globals
->stub_hash_table
,
5349 make_branch_to_erratum_835769_stub
, &data
);
5352 if (globals
->fix_erratum_843419
)
5354 struct erratum_835769_branch_to_stub_data data
;
5356 data
.info
= link_info
;
5357 data
.output_section
= sec
;
5358 data
.contents
= contents
;
5359 bfd_hash_traverse (&globals
->stub_hash_table
,
5360 _bfd_aarch64_erratum_843419_branch_to_stub
, &data
);
5366 /* Return TRUE if RELOC is a relocation against the base of GOT table. */
5369 aarch64_relocation_aginst_gp_p (bfd_reloc_code_real_type reloc
)
5371 return (reloc
== BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14
5372 || reloc
== BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15
5373 || reloc
== BFD_RELOC_AARCH64_LD64_GOTOFF_LO15
5374 || reloc
== BFD_RELOC_AARCH64_MOVW_GOTOFF_G0_NC
5375 || reloc
== BFD_RELOC_AARCH64_MOVW_GOTOFF_G1
);
5378 /* Perform a relocation as part of a final link. The input relocation type
5379 should be TLS relaxed. */
5381 static bfd_reloc_status_type
5382 elfNN_aarch64_final_link_relocate (reloc_howto_type
*howto
,
5385 asection
*input_section
,
5387 Elf_Internal_Rela
*rel
,
5389 struct bfd_link_info
*info
,
5391 struct elf_link_hash_entry
*h
,
5392 bfd_boolean
*unresolved_reloc_p
,
5393 bfd_boolean save_addend
,
5394 bfd_vma
*saved_addend
,
5395 Elf_Internal_Sym
*sym
)
5397 Elf_Internal_Shdr
*symtab_hdr
;
5398 unsigned int r_type
= howto
->type
;
5399 bfd_reloc_code_real_type bfd_r_type
5400 = elfNN_aarch64_bfd_reloc_from_howto (howto
);
5401 unsigned long r_symndx
;
5402 bfd_byte
*hit_data
= contents
+ rel
->r_offset
;
5403 bfd_vma place
, off
, got_entry_addr
= 0;
5404 bfd_signed_vma signed_addend
;
5405 struct elf_aarch64_link_hash_table
*globals
;
5406 bfd_boolean weak_undef_p
;
5407 bfd_boolean relative_reloc
;
5409 bfd_vma orig_value
= value
;
5410 bfd_boolean resolved_to_zero
;
5411 bfd_boolean abs_symbol_p
;
5413 globals
= elf_aarch64_hash_table (info
);
5415 symtab_hdr
= &elf_symtab_hdr (input_bfd
);
5417 BFD_ASSERT (is_aarch64_elf (input_bfd
));
5419 r_symndx
= ELFNN_R_SYM (rel
->r_info
);
5421 place
= input_section
->output_section
->vma
5422 + input_section
->output_offset
+ rel
->r_offset
;
5424 /* Get addend, accumulating the addend for consecutive relocs
5425 which refer to the same offset. */
5426 signed_addend
= saved_addend
? *saved_addend
: 0;
5427 signed_addend
+= rel
->r_addend
;
5429 weak_undef_p
= (h
? h
->root
.type
== bfd_link_hash_undefweak
5430 : bfd_is_und_section (sym_sec
));
5431 abs_symbol_p
= h
!= NULL
&& bfd_is_abs_symbol (&h
->root
);
5434 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle
5435 it here if it is defined in a non-shared object. */
5437 && h
->type
== STT_GNU_IFUNC
5444 if ((input_section
->flags
& SEC_ALLOC
) == 0)
5446 /* If this is a SHT_NOTE section without SHF_ALLOC, treat
5447 STT_GNU_IFUNC symbol as STT_FUNC. */
5448 if (elf_section_type (input_section
) == SHT_NOTE
)
5451 /* Dynamic relocs are not propagated for SEC_DEBUGGING
5452 sections because such sections are not SEC_ALLOC and
5453 thus ld.so will not process them. */
5454 if ((input_section
->flags
& SEC_DEBUGGING
) != 0)
5455 return bfd_reloc_ok
;
5457 if (h
->root
.root
.string
)
5458 name
= h
->root
.root
.string
;
5460 name
= bfd_elf_sym_name (input_bfd
, symtab_hdr
, sym
, NULL
);
5462 /* xgettext:c-format */
5463 (_("%pB(%pA+%#" PRIx64
"): "
5464 "unresolvable %s relocation against symbol `%s'"),
5465 input_bfd
, input_section
, (uint64_t) rel
->r_offset
,
5467 bfd_set_error (bfd_error_bad_value
);
5468 return bfd_reloc_notsupported
;
5470 else if (h
->plt
.offset
== (bfd_vma
) -1)
5471 goto bad_ifunc_reloc
;
5473 /* STT_GNU_IFUNC symbol must go through PLT. */
5474 plt
= globals
->root
.splt
? globals
->root
.splt
: globals
->root
.iplt
;
5475 value
= (plt
->output_section
->vma
+ plt
->output_offset
+ h
->plt
.offset
);
5481 if (h
->root
.root
.string
)
5482 name
= h
->root
.root
.string
;
5484 name
= bfd_elf_sym_name (input_bfd
, symtab_hdr
, sym
,
5487 /* xgettext:c-format */
5488 (_("%pB: relocation %s against STT_GNU_IFUNC "
5489 "symbol `%s' isn't handled by %s"), input_bfd
,
5490 howto
->name
, name
, __FUNCTION__
);
5491 bfd_set_error (bfd_error_bad_value
);
5492 return bfd_reloc_notsupported
;
5494 case BFD_RELOC_AARCH64_NN
:
5495 if (rel
->r_addend
!= 0)
5497 if (h
->root
.root
.string
)
5498 name
= h
->root
.root
.string
;
5500 name
= bfd_elf_sym_name (input_bfd
, symtab_hdr
,
5503 /* xgettext:c-format */
5504 (_("%pB: relocation %s against STT_GNU_IFUNC "
5505 "symbol `%s' has non-zero addend: %" PRId64
),
5506 input_bfd
, howto
->name
, name
, (int64_t) rel
->r_addend
);
5507 bfd_set_error (bfd_error_bad_value
);
5508 return bfd_reloc_notsupported
;
5511 /* Generate dynamic relocation only when there is a
5512 non-GOT reference in a shared object. */
5513 if (bfd_link_pic (info
) && h
->non_got_ref
)
5515 Elf_Internal_Rela outrel
;
5518 /* Need a dynamic relocation to get the real function
5520 outrel
.r_offset
= _bfd_elf_section_offset (output_bfd
,
5524 if (outrel
.r_offset
== (bfd_vma
) -1
5525 || outrel
.r_offset
== (bfd_vma
) -2)
5528 outrel
.r_offset
+= (input_section
->output_section
->vma
5529 + input_section
->output_offset
);
5531 if (h
->dynindx
== -1
5533 || bfd_link_executable (info
))
5535 /* This symbol is resolved locally. */
5536 outrel
.r_info
= ELFNN_R_INFO (0, AARCH64_R (IRELATIVE
));
5537 outrel
.r_addend
= (h
->root
.u
.def
.value
5538 + h
->root
.u
.def
.section
->output_section
->vma
5539 + h
->root
.u
.def
.section
->output_offset
);
5543 outrel
.r_info
= ELFNN_R_INFO (h
->dynindx
, r_type
);
5544 outrel
.r_addend
= 0;
5547 sreloc
= globals
->root
.irelifunc
;
5548 elf_append_rela (output_bfd
, sreloc
, &outrel
);
5550 /* If this reloc is against an external symbol, we
5551 do not want to fiddle with the addend. Otherwise,
5552 we need to include the symbol value so that it
5553 becomes an addend for the dynamic reloc. For an
5554 internal symbol, we have updated addend. */
5555 return bfd_reloc_ok
;
5558 case BFD_RELOC_AARCH64_CALL26
:
5559 case BFD_RELOC_AARCH64_JUMP26
:
5560 value
= _bfd_aarch64_elf_resolve_relocation (bfd_r_type
, place
, value
,
5563 return _bfd_aarch64_elf_put_addend (input_bfd
, hit_data
, bfd_r_type
,
5565 case BFD_RELOC_AARCH64_ADR_GOT_PAGE
:
5566 case BFD_RELOC_AARCH64_GOT_LD_PREL19
:
5567 case BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14
:
5568 case BFD_RELOC_AARCH64_LD32_GOT_LO12_NC
:
5569 case BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15
:
5570 case BFD_RELOC_AARCH64_MOVW_GOTOFF_G0_NC
:
5571 case BFD_RELOC_AARCH64_MOVW_GOTOFF_G1
:
5572 case BFD_RELOC_AARCH64_LD64_GOTOFF_LO15
:
5573 case BFD_RELOC_AARCH64_LD64_GOT_LO12_NC
:
5574 base_got
= globals
->root
.sgot
;
5575 off
= h
->got
.offset
;
5577 if (base_got
== NULL
)
5580 if (off
== (bfd_vma
) -1)
5584 /* We can't use h->got.offset here to save state, or
5585 even just remember the offset, as finish_dynamic_symbol
5586 would use that as offset into .got. */
5588 if (globals
->root
.splt
!= NULL
)
5590 plt_index
= ((h
->plt
.offset
- globals
->plt_header_size
) /
5591 globals
->plt_entry_size
);
5592 off
= (plt_index
+ 3) * GOT_ENTRY_SIZE
;
5593 base_got
= globals
->root
.sgotplt
;
5597 plt_index
= h
->plt
.offset
/ globals
->plt_entry_size
;
5598 off
= plt_index
* GOT_ENTRY_SIZE
;
5599 base_got
= globals
->root
.igotplt
;
5602 if (h
->dynindx
== -1
5606 /* This references the local definition. We must
5607 initialize this entry in the global offset table.
5608 Since the offset must always be a multiple of 8,
5609 we use the least significant bit to record
5610 whether we have initialized it already.
5612 When doing a dynamic link, we create a .rela.got
5613 relocation entry to initialize the value. This
5614 is done in the finish_dynamic_symbol routine. */
5619 bfd_put_NN (output_bfd
, value
,
5620 base_got
->contents
+ off
);
5621 /* Note that this is harmless as -1 | 1 still is -1. */
5625 value
= (base_got
->output_section
->vma
5626 + base_got
->output_offset
+ off
);
5629 value
= aarch64_calculate_got_entry_vma (h
, globals
, info
,
5631 unresolved_reloc_p
);
5633 if (aarch64_relocation_aginst_gp_p (bfd_r_type
))
5634 addend
= (globals
->root
.sgot
->output_section
->vma
5635 + globals
->root
.sgot
->output_offset
);
5637 value
= _bfd_aarch64_elf_resolve_relocation (bfd_r_type
, place
, value
,
5638 addend
, weak_undef_p
);
5639 return _bfd_aarch64_elf_put_addend (input_bfd
, hit_data
, bfd_r_type
, howto
, value
);
5640 case BFD_RELOC_AARCH64_ADD_LO12
:
5641 case BFD_RELOC_AARCH64_ADR_HI21_PCREL
:
5647 resolved_to_zero
= (h
!= NULL
5648 && UNDEFWEAK_NO_DYNAMIC_RELOC (info
, h
));
5652 case BFD_RELOC_AARCH64_NONE
:
5653 case BFD_RELOC_AARCH64_TLSDESC_ADD
:
5654 case BFD_RELOC_AARCH64_TLSDESC_CALL
:
5655 case BFD_RELOC_AARCH64_TLSDESC_LDR
:
5656 *unresolved_reloc_p
= FALSE
;
5657 return bfd_reloc_ok
;
5659 case BFD_RELOC_AARCH64_NN
:
5661 /* When generating a shared object or relocatable executable, these
5662 relocations are copied into the output file to be resolved at
5664 if (((bfd_link_pic (info
)
5665 || globals
->root
.is_relocatable_executable
)
5666 && (input_section
->flags
& SEC_ALLOC
)
5668 || (ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
5669 && !resolved_to_zero
)
5670 || h
->root
.type
!= bfd_link_hash_undefweak
))
5671 /* Or we are creating an executable, we may need to keep relocations
5672 for symbols satisfied by a dynamic library if we manage to avoid
5673 copy relocs for the symbol. */
5674 || (ELIMINATE_COPY_RELOCS
5675 && !bfd_link_pic (info
)
5677 && (input_section
->flags
& SEC_ALLOC
)
5682 || h
->root
.type
== bfd_link_hash_undefweak
5683 || h
->root
.type
== bfd_link_hash_undefined
)))
5685 Elf_Internal_Rela outrel
;
5687 bfd_boolean skip
, relocate
;
5690 *unresolved_reloc_p
= FALSE
;
5695 outrel
.r_addend
= signed_addend
;
5697 _bfd_elf_section_offset (output_bfd
, info
, input_section
,
5699 if (outrel
.r_offset
== (bfd_vma
) - 1)
5701 else if (outrel
.r_offset
== (bfd_vma
) - 2)
5706 else if (abs_symbol_p
)
5708 /* Local absolute symbol. */
5709 skip
= (h
->forced_local
|| (h
->dynindx
== -1));
5713 outrel
.r_offset
+= (input_section
->output_section
->vma
5714 + input_section
->output_offset
);
5717 memset (&outrel
, 0, sizeof outrel
);
5720 && (!bfd_link_pic (info
)
5721 || !(bfd_link_pie (info
) || SYMBOLIC_BIND (info
, h
))
5722 || !h
->def_regular
))
5723 outrel
.r_info
= ELFNN_R_INFO (h
->dynindx
, r_type
);
5728 /* On SVR4-ish systems, the dynamic loader cannot
5729 relocate the text and data segments independently,
5730 so the symbol does not matter. */
5732 relocate
= globals
->no_apply_dynamic_relocs
? FALSE
: TRUE
;
5733 outrel
.r_info
= ELFNN_R_INFO (symbol
, AARCH64_R (RELATIVE
));
5734 outrel
.r_addend
+= value
;
5737 sreloc
= elf_section_data (input_section
)->sreloc
;
5738 if (sreloc
== NULL
|| sreloc
->contents
== NULL
)
5739 return bfd_reloc_notsupported
;
5741 loc
= sreloc
->contents
+ sreloc
->reloc_count
++ * RELOC_SIZE (globals
);
5742 bfd_elfNN_swap_reloca_out (output_bfd
, &outrel
, loc
);
5744 if (sreloc
->reloc_count
* RELOC_SIZE (globals
) > sreloc
->size
)
5746 /* Sanity to check that we have previously allocated
5747 sufficient space in the relocation section for the
5748 number of relocations we actually want to emit. */
5752 /* If this reloc is against an external symbol, we do not want to
5753 fiddle with the addend. Otherwise, we need to include the symbol
5754 value so that it becomes an addend for the dynamic reloc. */
5756 return bfd_reloc_ok
;
5758 return _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
5759 contents
, rel
->r_offset
, value
,
5763 value
+= signed_addend
;
5766 case BFD_RELOC_AARCH64_CALL26
:
5767 case BFD_RELOC_AARCH64_JUMP26
:
5769 asection
*splt
= globals
->root
.splt
;
5770 bfd_boolean via_plt_p
=
5771 splt
!= NULL
&& h
!= NULL
&& h
->plt
.offset
!= (bfd_vma
) - 1;
5773 /* A call to an undefined weak symbol is converted to a jump to
5774 the next instruction unless a PLT entry will be created.
5775 The jump to the next instruction is optimized as a NOP.
5776 Do the same for local undefined symbols. */
5777 if (weak_undef_p
&& ! via_plt_p
)
5779 bfd_putl32 (INSN_NOP
, hit_data
);
5780 return bfd_reloc_ok
;
5783 /* If the call goes through a PLT entry, make sure to
5784 check distance to the right destination address. */
5786 value
= (splt
->output_section
->vma
5787 + splt
->output_offset
+ h
->plt
.offset
);
5789 /* Check if a stub has to be inserted because the destination
5791 struct elf_aarch64_stub_hash_entry
*stub_entry
= NULL
;
5793 /* If the branch destination is directed to plt stub, "value" will be
5794 the final destination, otherwise we should plus signed_addend, it may
5795 contain non-zero value, for example call to local function symbol
5796 which are turned into "sec_sym + sec_off", and sec_off is kept in
5798 if (! aarch64_valid_branch_p (via_plt_p
? value
: value
+ signed_addend
,
5800 /* The target is out of reach, so redirect the branch to
5801 the local stub for this function. */
5802 stub_entry
= elfNN_aarch64_get_stub_entry (input_section
, sym_sec
, h
,
5804 if (stub_entry
!= NULL
)
5806 value
= (stub_entry
->stub_offset
5807 + stub_entry
->stub_sec
->output_offset
5808 + stub_entry
->stub_sec
->output_section
->vma
);
5810 /* We have redirected the destination to stub entry address,
5811 so ignore any addend record in the original rela entry. */
5815 value
= _bfd_aarch64_elf_resolve_relocation (bfd_r_type
, place
, value
,
5816 signed_addend
, weak_undef_p
);
5817 *unresolved_reloc_p
= FALSE
;
5820 case BFD_RELOC_AARCH64_16_PCREL
:
5821 case BFD_RELOC_AARCH64_32_PCREL
:
5822 case BFD_RELOC_AARCH64_64_PCREL
:
5823 case BFD_RELOC_AARCH64_ADR_HI21_NC_PCREL
:
5824 case BFD_RELOC_AARCH64_ADR_HI21_PCREL
:
5825 case BFD_RELOC_AARCH64_ADR_LO21_PCREL
:
5826 case BFD_RELOC_AARCH64_LD_LO19_PCREL
:
5827 case BFD_RELOC_AARCH64_MOVW_PREL_G0
:
5828 case BFD_RELOC_AARCH64_MOVW_PREL_G0_NC
:
5829 case BFD_RELOC_AARCH64_MOVW_PREL_G1
:
5830 case BFD_RELOC_AARCH64_MOVW_PREL_G1_NC
:
5831 case BFD_RELOC_AARCH64_MOVW_PREL_G2
:
5832 case BFD_RELOC_AARCH64_MOVW_PREL_G2_NC
:
5833 case BFD_RELOC_AARCH64_MOVW_PREL_G3
:
5834 if (bfd_link_pic (info
)
5835 && (input_section
->flags
& SEC_ALLOC
) != 0
5836 && (input_section
->flags
& SEC_READONLY
) != 0
5837 && !SYMBOL_REFERENCES_LOCAL (info
, h
))
5839 int howto_index
= bfd_r_type
- BFD_RELOC_AARCH64_RELOC_START
;
5842 /* xgettext:c-format */
5843 (_("%pB: relocation %s against symbol `%s' which may bind "
5844 "externally can not be used when making a shared object; "
5845 "recompile with -fPIC"),
5846 input_bfd
, elfNN_aarch64_howto_table
[howto_index
].name
,
5847 h
->root
.root
.string
);
5848 bfd_set_error (bfd_error_bad_value
);
5849 return bfd_reloc_notsupported
;
5853 case BFD_RELOC_AARCH64_16
:
5855 case BFD_RELOC_AARCH64_32
:
5857 case BFD_RELOC_AARCH64_ADD_LO12
:
5858 case BFD_RELOC_AARCH64_BRANCH19
:
5859 case BFD_RELOC_AARCH64_LDST128_LO12
:
5860 case BFD_RELOC_AARCH64_LDST16_LO12
:
5861 case BFD_RELOC_AARCH64_LDST32_LO12
:
5862 case BFD_RELOC_AARCH64_LDST64_LO12
:
5863 case BFD_RELOC_AARCH64_LDST8_LO12
:
5864 case BFD_RELOC_AARCH64_MOVW_G0
:
5865 case BFD_RELOC_AARCH64_MOVW_G0_NC
:
5866 case BFD_RELOC_AARCH64_MOVW_G0_S
:
5867 case BFD_RELOC_AARCH64_MOVW_G1
:
5868 case BFD_RELOC_AARCH64_MOVW_G1_NC
:
5869 case BFD_RELOC_AARCH64_MOVW_G1_S
:
5870 case BFD_RELOC_AARCH64_MOVW_G2
:
5871 case BFD_RELOC_AARCH64_MOVW_G2_NC
:
5872 case BFD_RELOC_AARCH64_MOVW_G2_S
:
5873 case BFD_RELOC_AARCH64_MOVW_G3
:
5874 case BFD_RELOC_AARCH64_TSTBR14
:
5875 value
= _bfd_aarch64_elf_resolve_relocation (bfd_r_type
, place
, value
,
5876 signed_addend
, weak_undef_p
);
5879 case BFD_RELOC_AARCH64_ADR_GOT_PAGE
:
5880 case BFD_RELOC_AARCH64_GOT_LD_PREL19
:
5881 case BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14
:
5882 case BFD_RELOC_AARCH64_LD32_GOT_LO12_NC
:
5883 case BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15
:
5884 case BFD_RELOC_AARCH64_LD64_GOT_LO12_NC
:
5885 case BFD_RELOC_AARCH64_LD64_GOTOFF_LO15
:
5886 case BFD_RELOC_AARCH64_MOVW_GOTOFF_G0_NC
:
5887 case BFD_RELOC_AARCH64_MOVW_GOTOFF_G1
:
5888 if (globals
->root
.sgot
== NULL
)
5889 BFD_ASSERT (h
!= NULL
);
5891 relative_reloc
= FALSE
;
5896 /* If a symbol is not dynamic and is not undefined weak, bind it
5897 locally and generate a RELATIVE relocation under PIC mode.
5899 NOTE: one symbol may be referenced by several relocations, we
5900 should only generate one RELATIVE relocation for that symbol.
5901 Therefore, check GOT offset mark first. */
5902 if (h
->dynindx
== -1
5904 && h
->root
.type
!= bfd_link_hash_undefweak
5905 && bfd_link_pic (info
)
5906 && !symbol_got_offset_mark_p (input_bfd
, h
, r_symndx
))
5907 relative_reloc
= TRUE
;
5909 value
= aarch64_calculate_got_entry_vma (h
, globals
, info
, value
,
5911 unresolved_reloc_p
);
5912 /* Record the GOT entry address which will be used when generating
5913 RELATIVE relocation. */
5915 got_entry_addr
= value
;
5917 if (aarch64_relocation_aginst_gp_p (bfd_r_type
))
5918 addend
= (globals
->root
.sgot
->output_section
->vma
5919 + globals
->root
.sgot
->output_offset
);
5920 value
= _bfd_aarch64_elf_resolve_relocation (bfd_r_type
, place
, value
,
5921 addend
, weak_undef_p
);
5926 struct elf_aarch64_local_symbol
*locals
5927 = elf_aarch64_locals (input_bfd
);
5931 int howto_index
= bfd_r_type
- BFD_RELOC_AARCH64_RELOC_START
;
5933 /* xgettext:c-format */
5934 (_("%pB: local symbol descriptor table be NULL when applying "
5935 "relocation %s against local symbol"),
5936 input_bfd
, elfNN_aarch64_howto_table
[howto_index
].name
);
5940 off
= symbol_got_offset (input_bfd
, h
, r_symndx
);
5941 base_got
= globals
->root
.sgot
;
5942 got_entry_addr
= (base_got
->output_section
->vma
5943 + base_got
->output_offset
+ off
);
5945 if (!symbol_got_offset_mark_p (input_bfd
, h
, r_symndx
))
5947 bfd_put_64 (output_bfd
, value
, base_got
->contents
+ off
);
5949 /* For local symbol, we have done absolute relocation in static
5950 linking stage. While for shared library, we need to update the
5951 content of GOT entry according to the shared object's runtime
5952 base address. So, we need to generate a R_AARCH64_RELATIVE reloc
5953 for dynamic linker. */
5954 if (bfd_link_pic (info
))
5955 relative_reloc
= TRUE
;
5957 symbol_got_offset_mark (input_bfd
, h
, r_symndx
);
5960 /* Update the relocation value to GOT entry addr as we have transformed
5961 the direct data access into indirect data access through GOT. */
5962 value
= got_entry_addr
;
5964 if (aarch64_relocation_aginst_gp_p (bfd_r_type
))
5965 addend
= base_got
->output_section
->vma
+ base_got
->output_offset
;
5967 value
= _bfd_aarch64_elf_resolve_relocation (bfd_r_type
, place
, value
,
5968 addend
, weak_undef_p
);
5974 Elf_Internal_Rela outrel
;
5976 s
= globals
->root
.srelgot
;
5980 outrel
.r_offset
= got_entry_addr
;
5981 outrel
.r_info
= ELFNN_R_INFO (0, AARCH64_R (RELATIVE
));
5982 outrel
.r_addend
= orig_value
;
5983 elf_append_rela (output_bfd
, s
, &outrel
);
5987 case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC
:
5988 case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21
:
5989 case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21
:
5990 case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21
:
5991 case BFD_RELOC_AARCH64_TLSIE_LD32_GOTTPREL_LO12_NC
:
5992 case BFD_RELOC_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC
:
5993 case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19
:
5994 case BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC
:
5995 case BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21
:
5996 case BFD_RELOC_AARCH64_TLSLD_ADR_PREL21
:
5997 if (globals
->root
.sgot
== NULL
)
5998 return bfd_reloc_notsupported
;
6000 value
= (symbol_got_offset (input_bfd
, h
, r_symndx
)
6001 + globals
->root
.sgot
->output_section
->vma
6002 + globals
->root
.sgot
->output_offset
);
6004 value
= _bfd_aarch64_elf_resolve_relocation (bfd_r_type
, place
, value
,
6006 *unresolved_reloc_p
= FALSE
;
6009 case BFD_RELOC_AARCH64_TLSGD_MOVW_G0_NC
:
6010 case BFD_RELOC_AARCH64_TLSGD_MOVW_G1
:
6011 case BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G0_NC
:
6012 case BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G1
:
6013 if (globals
->root
.sgot
== NULL
)
6014 return bfd_reloc_notsupported
;
6016 value
= symbol_got_offset (input_bfd
, h
, r_symndx
);
6017 value
= _bfd_aarch64_elf_resolve_relocation (bfd_r_type
, place
, value
,
6019 *unresolved_reloc_p
= FALSE
;
6022 case BFD_RELOC_AARCH64_TLSLD_ADD_DTPREL_HI12
:
6023 case BFD_RELOC_AARCH64_TLSLD_ADD_DTPREL_LO12
:
6024 case BFD_RELOC_AARCH64_TLSLD_ADD_DTPREL_LO12_NC
:
6025 case BFD_RELOC_AARCH64_TLSLD_LDST16_DTPREL_LO12
:
6026 case BFD_RELOC_AARCH64_TLSLD_LDST16_DTPREL_LO12_NC
:
6027 case BFD_RELOC_AARCH64_TLSLD_LDST32_DTPREL_LO12
:
6028 case BFD_RELOC_AARCH64_TLSLD_LDST32_DTPREL_LO12_NC
:
6029 case BFD_RELOC_AARCH64_TLSLD_LDST64_DTPREL_LO12
:
6030 case BFD_RELOC_AARCH64_TLSLD_LDST64_DTPREL_LO12_NC
:
6031 case BFD_RELOC_AARCH64_TLSLD_LDST8_DTPREL_LO12
:
6032 case BFD_RELOC_AARCH64_TLSLD_LDST8_DTPREL_LO12_NC
:
6033 case BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G0
:
6034 case BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G0_NC
:
6035 case BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G1
:
6036 case BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G1_NC
:
6037 case BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G2
:
6038 value
= _bfd_aarch64_elf_resolve_relocation (bfd_r_type
, place
, value
,
6039 signed_addend
- dtpoff_base (info
),
6043 case BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_HI12
:
6044 case BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_LO12
:
6045 case BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_LO12_NC
:
6046 case BFD_RELOC_AARCH64_TLSLE_LDST16_TPREL_LO12
:
6047 case BFD_RELOC_AARCH64_TLSLE_LDST16_TPREL_LO12_NC
:
6048 case BFD_RELOC_AARCH64_TLSLE_LDST32_TPREL_LO12
:
6049 case BFD_RELOC_AARCH64_TLSLE_LDST32_TPREL_LO12_NC
:
6050 case BFD_RELOC_AARCH64_TLSLE_LDST64_TPREL_LO12
:
6051 case BFD_RELOC_AARCH64_TLSLE_LDST64_TPREL_LO12_NC
:
6052 case BFD_RELOC_AARCH64_TLSLE_LDST8_TPREL_LO12
:
6053 case BFD_RELOC_AARCH64_TLSLE_LDST8_TPREL_LO12_NC
:
6054 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0
:
6055 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC
:
6056 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1
:
6057 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1_NC
:
6058 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G2
:
6059 value
= _bfd_aarch64_elf_resolve_relocation (bfd_r_type
, place
, value
,
6060 signed_addend
- tpoff_base (info
),
6062 *unresolved_reloc_p
= FALSE
;
6065 case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12
:
6066 case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21
:
6067 case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21
:
6068 case BFD_RELOC_AARCH64_TLSDESC_LD32_LO12_NC
:
6069 case BFD_RELOC_AARCH64_TLSDESC_LD64_LO12
:
6070 case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19
:
6071 if (globals
->root
.sgot
== NULL
)
6072 return bfd_reloc_notsupported
;
6073 value
= (symbol_tlsdesc_got_offset (input_bfd
, h
, r_symndx
)
6074 + globals
->root
.sgotplt
->output_section
->vma
6075 + globals
->root
.sgotplt
->output_offset
6076 + globals
->sgotplt_jump_table_size
);
6078 value
= _bfd_aarch64_elf_resolve_relocation (bfd_r_type
, place
, value
,
6080 *unresolved_reloc_p
= FALSE
;
6083 case BFD_RELOC_AARCH64_TLSDESC_OFF_G0_NC
:
6084 case BFD_RELOC_AARCH64_TLSDESC_OFF_G1
:
6085 if (globals
->root
.sgot
== NULL
)
6086 return bfd_reloc_notsupported
;
6088 value
= (symbol_tlsdesc_got_offset (input_bfd
, h
, r_symndx
)
6089 + globals
->root
.sgotplt
->output_section
->vma
6090 + globals
->root
.sgotplt
->output_offset
6091 + globals
->sgotplt_jump_table_size
);
6093 value
-= (globals
->root
.sgot
->output_section
->vma
6094 + globals
->root
.sgot
->output_offset
);
6096 value
= _bfd_aarch64_elf_resolve_relocation (bfd_r_type
, place
, value
,
6098 *unresolved_reloc_p
= FALSE
;
6102 return bfd_reloc_notsupported
;
6106 *saved_addend
= value
;
6108 /* Only apply the final relocation in a sequence. */
6110 return bfd_reloc_continue
;
6112 return _bfd_aarch64_elf_put_addend (input_bfd
, hit_data
, bfd_r_type
,
6116 /* LP64 and ILP32 operates on x- and w-registers respectively.
6117 Next definitions take into account the difference between
6118 corresponding machine codes. R means x-register if the target
6119 arch is LP64, and w-register if the target is ILP32. */
6122 # define add_R0_R0 (0x91000000)
6123 # define add_R0_R0_R1 (0x8b000020)
6124 # define add_R0_R1 (0x91400020)
6125 # define ldr_R0 (0x58000000)
6126 # define ldr_R0_mask(i) (i & 0xffffffe0)
6127 # define ldr_R0_x0 (0xf9400000)
6128 # define ldr_hw_R0 (0xf2a00000)
6129 # define movk_R0 (0xf2800000)
6130 # define movz_R0 (0xd2a00000)
6131 # define movz_hw_R0 (0xd2c00000)
6132 #else /*ARCH_SIZE == 32 */
6133 # define add_R0_R0 (0x11000000)
6134 # define add_R0_R0_R1 (0x0b000020)
6135 # define add_R0_R1 (0x11400020)
6136 # define ldr_R0 (0x18000000)
6137 # define ldr_R0_mask(i) (i & 0xbfffffe0)
6138 # define ldr_R0_x0 (0xb9400000)
6139 # define ldr_hw_R0 (0x72a00000)
6140 # define movk_R0 (0x72800000)
6141 # define movz_R0 (0x52a00000)
6142 # define movz_hw_R0 (0x52c00000)
6145 /* Structure to hold payload for _bfd_aarch64_erratum_843419_clear_stub,
6146 it is used to identify the stub information to reset. */
6148 struct erratum_843419_branch_to_stub_clear_data
6150 bfd_vma adrp_offset
;
6151 asection
*output_section
;
6154 /* Clear the erratum information for GEN_ENTRY if the ADRP_OFFSET and
6155 section inside IN_ARG matches. The clearing is done by setting the
6156 stub_type to none. */
6159 _bfd_aarch64_erratum_843419_clear_stub (struct bfd_hash_entry
*gen_entry
,
6162 struct elf_aarch64_stub_hash_entry
*stub_entry
6163 = (struct elf_aarch64_stub_hash_entry
*) gen_entry
;
6164 struct erratum_843419_branch_to_stub_clear_data
*data
6165 = (struct erratum_843419_branch_to_stub_clear_data
*) in_arg
;
6167 if (stub_entry
->target_section
!= data
->output_section
6168 || stub_entry
->stub_type
!= aarch64_stub_erratum_843419_veneer
6169 || stub_entry
->adrp_offset
!= data
->adrp_offset
)
6172 /* Change the stub type instead of removing the entry, removing from the hash
6173 table would be slower and we have already reserved the memory for the entry
6174 so there wouldn't be much gain. Changing the stub also keeps around a
6175 record of what was there before. */
6176 stub_entry
->stub_type
= aarch64_stub_none
;
6178 /* We're done and there could have been only one matching stub at that
6179 particular offset, so abort further traversal. */
6183 /* TLS Relaxations may relax an adrp sequence that matches the erratum 843419
6184 sequence. In this case the erratum no longer applies and we need to remove
6185 the entry from the pending stub generation. This clears matching adrp insn
6186 at ADRP_OFFSET in INPUT_SECTION in the stub table defined in GLOBALS. */
6189 clear_erratum_843419_entry (struct elf_aarch64_link_hash_table
*globals
,
6190 bfd_vma adrp_offset
, asection
*input_section
)
6192 if (globals
->fix_erratum_843419
& ERRAT_ADRP
)
6194 struct erratum_843419_branch_to_stub_clear_data data
;
6195 data
.adrp_offset
= adrp_offset
;
6196 data
.output_section
= input_section
;
6198 bfd_hash_traverse (&globals
->stub_hash_table
,
6199 _bfd_aarch64_erratum_843419_clear_stub
, &data
);
6203 /* Handle TLS relaxations. Relaxing is possible for symbols that use
6204 R_AARCH64_TLSDESC_ADR_{PAGE, LD64_LO12_NC, ADD_LO12_NC} during a static
6207 Return bfd_reloc_ok if we're done, bfd_reloc_continue if the caller
6208 is to then call final_link_relocate. Return other values in the
6211 static bfd_reloc_status_type
6212 elfNN_aarch64_tls_relax (struct elf_aarch64_link_hash_table
*globals
,
6213 bfd
*input_bfd
, asection
*input_section
,
6214 bfd_byte
*contents
, Elf_Internal_Rela
*rel
,
6215 struct elf_link_hash_entry
*h
)
6217 bfd_boolean is_local
= h
== NULL
;
6218 unsigned int r_type
= ELFNN_R_TYPE (rel
->r_info
);
6221 BFD_ASSERT (globals
&& input_bfd
&& contents
&& rel
);
6223 switch (elfNN_aarch64_bfd_reloc_from_type (input_bfd
, r_type
))
6225 case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21
:
6226 case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21
:
6229 /* GD->LE relaxation:
6230 adrp x0, :tlsgd:var => movz R0, :tprel_g1:var
6232 adrp x0, :tlsdesc:var => movz R0, :tprel_g1:var
6234 Where R is x for LP64, and w for ILP32. */
6235 bfd_putl32 (movz_R0
, contents
+ rel
->r_offset
);
6236 /* We have relaxed the adrp into a mov, we may have to clear any
6237 pending erratum fixes. */
6238 clear_erratum_843419_entry (globals
, rel
->r_offset
, input_section
);
6239 return bfd_reloc_continue
;
6243 /* GD->IE relaxation:
6244 adrp x0, :tlsgd:var => adrp x0, :gottprel:var
6246 adrp x0, :tlsdesc:var => adrp x0, :gottprel:var
6248 return bfd_reloc_continue
;
6251 case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21
:
6255 case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19
:
6258 /* Tiny TLSDESC->LE relaxation:
6259 ldr x1, :tlsdesc:var => movz R0, #:tprel_g1:var
6260 adr x0, :tlsdesc:var => movk R0, #:tprel_g0_nc:var
6264 Where R is x for LP64, and w for ILP32. */
6265 BFD_ASSERT (ELFNN_R_TYPE (rel
[1].r_info
) == AARCH64_R (TLSDESC_ADR_PREL21
));
6266 BFD_ASSERT (ELFNN_R_TYPE (rel
[2].r_info
) == AARCH64_R (TLSDESC_CALL
));
6268 rel
[1].r_info
= ELFNN_R_INFO (ELFNN_R_SYM (rel
->r_info
),
6269 AARCH64_R (TLSLE_MOVW_TPREL_G0_NC
));
6270 rel
[2].r_info
= ELFNN_R_INFO (STN_UNDEF
, R_AARCH64_NONE
);
6272 bfd_putl32 (movz_R0
, contents
+ rel
->r_offset
);
6273 bfd_putl32 (movk_R0
, contents
+ rel
->r_offset
+ 4);
6274 bfd_putl32 (INSN_NOP
, contents
+ rel
->r_offset
+ 8);
6275 return bfd_reloc_continue
;
6279 /* Tiny TLSDESC->IE relaxation:
6280 ldr x1, :tlsdesc:var => ldr x0, :gottprel:var
6281 adr x0, :tlsdesc:var => nop
6285 BFD_ASSERT (ELFNN_R_TYPE (rel
[1].r_info
) == AARCH64_R (TLSDESC_ADR_PREL21
));
6286 BFD_ASSERT (ELFNN_R_TYPE (rel
[2].r_info
) == AARCH64_R (TLSDESC_CALL
));
6288 rel
[1].r_info
= ELFNN_R_INFO (STN_UNDEF
, R_AARCH64_NONE
);
6289 rel
[2].r_info
= ELFNN_R_INFO (STN_UNDEF
, R_AARCH64_NONE
);
6291 bfd_putl32 (ldr_R0
, contents
+ rel
->r_offset
);
6292 bfd_putl32 (INSN_NOP
, contents
+ rel
->r_offset
+ 4);
6293 bfd_putl32 (INSN_NOP
, contents
+ rel
->r_offset
+ 8);
6294 return bfd_reloc_continue
;
6297 case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21
:
6300 /* Tiny GD->LE relaxation:
6301 adr x0, :tlsgd:var => mrs x1, tpidr_el0
6302 bl __tls_get_addr => add R0, R1, #:tprel_hi12:x, lsl #12
6303 nop => add R0, R0, #:tprel_lo12_nc:x
6305 Where R is x for LP64, and x for Ilp32. */
6307 /* First kill the tls_get_addr reloc on the bl instruction. */
6308 BFD_ASSERT (rel
->r_offset
+ 4 == rel
[1].r_offset
);
6310 bfd_putl32 (0xd53bd041, contents
+ rel
->r_offset
+ 0);
6311 bfd_putl32 (add_R0_R1
, contents
+ rel
->r_offset
+ 4);
6312 bfd_putl32 (add_R0_R0
, contents
+ rel
->r_offset
+ 8);
6314 rel
[1].r_info
= ELFNN_R_INFO (ELFNN_R_SYM (rel
->r_info
),
6315 AARCH64_R (TLSLE_ADD_TPREL_LO12_NC
));
6316 rel
[1].r_offset
= rel
->r_offset
+ 8;
6318 /* Move the current relocation to the second instruction in
6321 rel
->r_info
= ELFNN_R_INFO (ELFNN_R_SYM (rel
->r_info
),
6322 AARCH64_R (TLSLE_ADD_TPREL_HI12
));
6323 return bfd_reloc_continue
;
6327 /* Tiny GD->IE relaxation:
6328 adr x0, :tlsgd:var => ldr R0, :gottprel:var
6329 bl __tls_get_addr => mrs x1, tpidr_el0
6330 nop => add R0, R0, R1
6332 Where R is x for LP64, and w for Ilp32. */
6334 /* First kill the tls_get_addr reloc on the bl instruction. */
6335 BFD_ASSERT (rel
->r_offset
+ 4 == rel
[1].r_offset
);
6336 rel
[1].r_info
= ELFNN_R_INFO (STN_UNDEF
, R_AARCH64_NONE
);
6338 bfd_putl32 (ldr_R0
, contents
+ rel
->r_offset
);
6339 bfd_putl32 (0xd53bd041, contents
+ rel
->r_offset
+ 4);
6340 bfd_putl32 (add_R0_R0_R1
, contents
+ rel
->r_offset
+ 8);
6341 return bfd_reloc_continue
;
6345 case BFD_RELOC_AARCH64_TLSGD_MOVW_G1
:
6346 BFD_ASSERT (ELFNN_R_TYPE (rel
[1].r_info
) == AARCH64_R (TLSGD_MOVW_G0_NC
));
6347 BFD_ASSERT (rel
->r_offset
+ 12 == rel
[2].r_offset
);
6348 BFD_ASSERT (ELFNN_R_TYPE (rel
[2].r_info
) == AARCH64_R (CALL26
));
6352 /* Large GD->LE relaxation:
6353 movz x0, #:tlsgd_g1:var => movz x0, #:tprel_g2:var, lsl #32
6354 movk x0, #:tlsgd_g0_nc:var => movk x0, #:tprel_g1_nc:var, lsl #16
6355 add x0, gp, x0 => movk x0, #:tprel_g0_nc:var
6356 bl __tls_get_addr => mrs x1, tpidr_el0
6357 nop => add x0, x0, x1
6359 rel
[2].r_info
= ELFNN_R_INFO (ELFNN_R_SYM (rel
->r_info
),
6360 AARCH64_R (TLSLE_MOVW_TPREL_G0_NC
));
6361 rel
[2].r_offset
= rel
->r_offset
+ 8;
6363 bfd_putl32 (movz_hw_R0
, contents
+ rel
->r_offset
+ 0);
6364 bfd_putl32 (ldr_hw_R0
, contents
+ rel
->r_offset
+ 4);
6365 bfd_putl32 (movk_R0
, contents
+ rel
->r_offset
+ 8);
6366 bfd_putl32 (0xd53bd041, contents
+ rel
->r_offset
+ 12);
6367 bfd_putl32 (add_R0_R0_R1
, contents
+ rel
->r_offset
+ 16);
6371 /* Large GD->IE relaxation:
6372 movz x0, #:tlsgd_g1:var => movz x0, #:gottprel_g1:var, lsl #16
6373 movk x0, #:tlsgd_g0_nc:var => movk x0, #:gottprel_g0_nc:var
6374 add x0, gp, x0 => ldr x0, [gp, x0]
6375 bl __tls_get_addr => mrs x1, tpidr_el0
6376 nop => add x0, x0, x1
6378 rel
[2].r_info
= ELFNN_R_INFO (STN_UNDEF
, R_AARCH64_NONE
);
6379 bfd_putl32 (0xd2a80000, contents
+ rel
->r_offset
+ 0);
6380 bfd_putl32 (ldr_R0
, contents
+ rel
->r_offset
+ 8);
6381 bfd_putl32 (0xd53bd041, contents
+ rel
->r_offset
+ 12);
6382 bfd_putl32 (add_R0_R0_R1
, contents
+ rel
->r_offset
+ 16);
6384 return bfd_reloc_continue
;
6386 case BFD_RELOC_AARCH64_TLSGD_MOVW_G0_NC
:
6387 return bfd_reloc_continue
;
6390 case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19
:
6391 return bfd_reloc_continue
;
6393 case BFD_RELOC_AARCH64_TLSDESC_LDNN_LO12_NC
:
6396 /* GD->LE relaxation:
6397 ldr xd, [x0, #:tlsdesc_lo12:var] => movk x0, :tprel_g0_nc:var
6399 Where R is x for lp64 mode, and w for ILP32 mode. */
6400 bfd_putl32 (movk_R0
, contents
+ rel
->r_offset
);
6401 return bfd_reloc_continue
;
6405 /* GD->IE relaxation:
6406 ldr xd, [x0, #:tlsdesc_lo12:var] => ldr R0, [x0, #:gottprel_lo12:var]
6408 Where R is x for lp64 mode, and w for ILP32 mode. */
6409 insn
= bfd_getl32 (contents
+ rel
->r_offset
);
6410 bfd_putl32 (ldr_R0_mask (insn
), contents
+ rel
->r_offset
);
6411 return bfd_reloc_continue
;
6414 case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC
:
6417 /* GD->LE relaxation
6418 add x0, #:tlsgd_lo12:var => movk R0, :tprel_g0_nc:var
6419 bl __tls_get_addr => mrs x1, tpidr_el0
6420 nop => add R0, R1, R0
6422 Where R is x for lp64 mode, and w for ILP32 mode. */
6424 /* First kill the tls_get_addr reloc on the bl instruction. */
6425 BFD_ASSERT (rel
->r_offset
+ 4 == rel
[1].r_offset
);
6426 rel
[1].r_info
= ELFNN_R_INFO (STN_UNDEF
, R_AARCH64_NONE
);
6428 bfd_putl32 (movk_R0
, contents
+ rel
->r_offset
);
6429 bfd_putl32 (0xd53bd041, contents
+ rel
->r_offset
+ 4);
6430 bfd_putl32 (add_R0_R0_R1
, contents
+ rel
->r_offset
+ 8);
6431 return bfd_reloc_continue
;
6435 /* GD->IE relaxation
6436 ADD x0, #:tlsgd_lo12:var => ldr R0, [x0, #:gottprel_lo12:var]
6437 BL __tls_get_addr => mrs x1, tpidr_el0
6439 NOP => add R0, R1, R0
6441 Where R is x for lp64 mode, and w for ilp32 mode. */
6443 BFD_ASSERT (ELFNN_R_TYPE (rel
[1].r_info
) == AARCH64_R (CALL26
));
6445 /* Remove the relocation on the BL instruction. */
6446 rel
[1].r_info
= ELFNN_R_INFO (STN_UNDEF
, R_AARCH64_NONE
);
6448 /* We choose to fixup the BL and NOP instructions using the
6449 offset from the second relocation to allow flexibility in
6450 scheduling instructions between the ADD and BL. */
6451 bfd_putl32 (ldr_R0_x0
, contents
+ rel
->r_offset
);
6452 bfd_putl32 (0xd53bd041, contents
+ rel
[1].r_offset
);
6453 bfd_putl32 (add_R0_R0_R1
, contents
+ rel
[1].r_offset
+ 4);
6454 return bfd_reloc_continue
;
6457 case BFD_RELOC_AARCH64_TLSDESC_ADD
:
6458 case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12
:
6459 case BFD_RELOC_AARCH64_TLSDESC_CALL
:
6460 /* GD->IE/LE relaxation:
6461 add x0, x0, #:tlsdesc_lo12:var => nop
6464 bfd_putl32 (INSN_NOP
, contents
+ rel
->r_offset
);
6465 return bfd_reloc_ok
;
6467 case BFD_RELOC_AARCH64_TLSDESC_LDR
:
6470 /* GD->LE relaxation:
6471 ldr xd, [gp, xn] => movk R0, #:tprel_g0_nc:var
6473 Where R is x for lp64 mode, and w for ILP32 mode. */
6474 bfd_putl32 (movk_R0
, contents
+ rel
->r_offset
);
6475 return bfd_reloc_continue
;
6479 /* GD->IE relaxation:
6480 ldr xd, [gp, xn] => ldr R0, [gp, xn]
6482 Where R is x for lp64 mode, and w for ILP32 mode. */
6483 insn
= bfd_getl32 (contents
+ rel
->r_offset
);
6484 bfd_putl32 (ldr_R0_mask (insn
), contents
+ rel
->r_offset
);
6485 return bfd_reloc_ok
;
6488 case BFD_RELOC_AARCH64_TLSDESC_OFF_G0_NC
:
6489 /* GD->LE relaxation:
6490 movk xd, #:tlsdesc_off_g0_nc:var => movk R0, #:tprel_g1_nc:var, lsl #16
6492 movk xd, #:tlsdesc_off_g0_nc:var => movk Rd, #:gottprel_g0_nc:var
6494 Where R is x for lp64 mode, and w for ILP32 mode. */
6496 bfd_putl32 (ldr_hw_R0
, contents
+ rel
->r_offset
);
6497 return bfd_reloc_continue
;
6499 case BFD_RELOC_AARCH64_TLSDESC_OFF_G1
:
6502 /* GD->LE relaxation:
6503 movz xd, #:tlsdesc_off_g1:var => movz R0, #:tprel_g2:var, lsl #32
6505 Where R is x for lp64 mode, and w for ILP32 mode. */
6506 bfd_putl32 (movz_hw_R0
, contents
+ rel
->r_offset
);
6507 return bfd_reloc_continue
;
6511 /* GD->IE relaxation:
6512 movz xd, #:tlsdesc_off_g1:var => movz Rd, #:gottprel_g1:var, lsl #16
6514 Where R is x for lp64 mode, and w for ILP32 mode. */
6515 insn
= bfd_getl32 (contents
+ rel
->r_offset
);
6516 bfd_putl32 (movz_R0
| (insn
& 0x1f), contents
+ rel
->r_offset
);
6517 return bfd_reloc_continue
;
6520 case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21
:
6521 /* IE->LE relaxation:
6522 adrp xd, :gottprel:var => movz Rd, :tprel_g1:var
6524 Where R is x for lp64 mode, and w for ILP32 mode. */
6527 insn
= bfd_getl32 (contents
+ rel
->r_offset
);
6528 bfd_putl32 (movz_R0
| (insn
& 0x1f), contents
+ rel
->r_offset
);
6529 /* We have relaxed the adrp into a mov, we may have to clear any
6530 pending erratum fixes. */
6531 clear_erratum_843419_entry (globals
, rel
->r_offset
, input_section
);
6533 return bfd_reloc_continue
;
6535 case BFD_RELOC_AARCH64_TLSIE_LDNN_GOTTPREL_LO12_NC
:
6536 /* IE->LE relaxation:
6537 ldr xd, [xm, #:gottprel_lo12:var] => movk Rd, :tprel_g0_nc:var
6539 Where R is x for lp64 mode, and w for ILP32 mode. */
6542 insn
= bfd_getl32 (contents
+ rel
->r_offset
);
6543 bfd_putl32 (movk_R0
| (insn
& 0x1f), contents
+ rel
->r_offset
);
6545 return bfd_reloc_continue
;
6547 case BFD_RELOC_AARCH64_TLSLD_ADR_PREL21
:
6548 /* LD->LE relaxation (tiny):
6549 adr x0, :tlsldm:x => mrs x0, tpidr_el0
6550 bl __tls_get_addr => add R0, R0, TCB_SIZE
6552 Where R is x for lp64 mode, and w for ilp32 mode. */
6555 BFD_ASSERT (rel
->r_offset
+ 4 == rel
[1].r_offset
);
6556 BFD_ASSERT (ELFNN_R_TYPE (rel
[1].r_info
) == AARCH64_R (CALL26
));
6557 /* No need of CALL26 relocation for tls_get_addr. */
6558 rel
[1].r_info
= ELFNN_R_INFO (STN_UNDEF
, R_AARCH64_NONE
);
6559 bfd_putl32 (0xd53bd040, contents
+ rel
->r_offset
+ 0);
6560 bfd_putl32 (add_R0_R0
| (TCB_SIZE
<< 10),
6561 contents
+ rel
->r_offset
+ 4);
6562 return bfd_reloc_ok
;
6564 return bfd_reloc_continue
;
6566 case BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21
:
6567 /* LD->LE relaxation (small):
6568 adrp x0, :tlsldm:x => mrs x0, tpidr_el0
6572 bfd_putl32 (0xd53bd040, contents
+ rel
->r_offset
);
6573 return bfd_reloc_ok
;
6575 return bfd_reloc_continue
;
6577 case BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC
:
6578 /* LD->LE relaxation (small):
6579 add x0, #:tlsldm_lo12:x => add R0, R0, TCB_SIZE
6580 bl __tls_get_addr => nop
6582 Where R is x for lp64 mode, and w for ilp32 mode. */
6585 BFD_ASSERT (rel
->r_offset
+ 4 == rel
[1].r_offset
);
6586 BFD_ASSERT (ELFNN_R_TYPE (rel
[1].r_info
) == AARCH64_R (CALL26
));
6587 /* No need of CALL26 relocation for tls_get_addr. */
6588 rel
[1].r_info
= ELFNN_R_INFO (STN_UNDEF
, R_AARCH64_NONE
);
6589 bfd_putl32 (add_R0_R0
| (TCB_SIZE
<< 10),
6590 contents
+ rel
->r_offset
+ 0);
6591 bfd_putl32 (INSN_NOP
, contents
+ rel
->r_offset
+ 4);
6592 return bfd_reloc_ok
;
6594 return bfd_reloc_continue
;
6597 return bfd_reloc_continue
;
6600 return bfd_reloc_ok
;
6603 /* Relocate an AArch64 ELF section. */
6606 elfNN_aarch64_relocate_section (bfd
*output_bfd
,
6607 struct bfd_link_info
*info
,
6609 asection
*input_section
,
6611 Elf_Internal_Rela
*relocs
,
6612 Elf_Internal_Sym
*local_syms
,
6613 asection
**local_sections
)
6615 Elf_Internal_Shdr
*symtab_hdr
;
6616 struct elf_link_hash_entry
**sym_hashes
;
6617 Elf_Internal_Rela
*rel
;
6618 Elf_Internal_Rela
*relend
;
6620 struct elf_aarch64_link_hash_table
*globals
;
6621 bfd_boolean save_addend
= FALSE
;
6624 globals
= elf_aarch64_hash_table (info
);
6626 symtab_hdr
= &elf_symtab_hdr (input_bfd
);
6627 sym_hashes
= elf_sym_hashes (input_bfd
);
6630 relend
= relocs
+ input_section
->reloc_count
;
6631 for (; rel
< relend
; rel
++)
6633 unsigned int r_type
;
6634 bfd_reloc_code_real_type bfd_r_type
;
6635 bfd_reloc_code_real_type relaxed_bfd_r_type
;
6636 reloc_howto_type
*howto
;
6637 unsigned long r_symndx
;
6638 Elf_Internal_Sym
*sym
;
6640 struct elf_link_hash_entry
*h
;
6642 bfd_reloc_status_type r
;
6645 bfd_boolean unresolved_reloc
= FALSE
;
6646 char *error_message
= NULL
;
6648 r_symndx
= ELFNN_R_SYM (rel
->r_info
);
6649 r_type
= ELFNN_R_TYPE (rel
->r_info
);
6651 bfd_reloc
.howto
= elfNN_aarch64_howto_from_type (input_bfd
, r_type
);
6652 howto
= bfd_reloc
.howto
;
6655 return _bfd_unrecognized_reloc (input_bfd
, input_section
, r_type
);
6657 bfd_r_type
= elfNN_aarch64_bfd_reloc_from_howto (howto
);
6663 if (r_symndx
< symtab_hdr
->sh_info
)
6665 sym
= local_syms
+ r_symndx
;
6666 sym_type
= ELFNN_ST_TYPE (sym
->st_info
);
6667 sec
= local_sections
[r_symndx
];
6669 /* An object file might have a reference to a local
6670 undefined symbol. This is a daft object file, but we
6671 should at least do something about it. */
6672 if (r_type
!= R_AARCH64_NONE
&& r_type
!= R_AARCH64_NULL
6673 && bfd_is_und_section (sec
)
6674 && ELF_ST_BIND (sym
->st_info
) != STB_WEAK
)
6675 (*info
->callbacks
->undefined_symbol
)
6676 (info
, bfd_elf_string_from_elf_section
6677 (input_bfd
, symtab_hdr
->sh_link
, sym
->st_name
),
6678 input_bfd
, input_section
, rel
->r_offset
, TRUE
);
6680 relocation
= _bfd_elf_rela_local_sym (output_bfd
, sym
, &sec
, rel
);
6682 /* Relocate against local STT_GNU_IFUNC symbol. */
6683 if (!bfd_link_relocatable (info
)
6684 && ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
)
6686 h
= elfNN_aarch64_get_local_sym_hash (globals
, input_bfd
,
6691 /* Set STT_GNU_IFUNC symbol value. */
6692 h
->root
.u
.def
.value
= sym
->st_value
;
6693 h
->root
.u
.def
.section
= sec
;
6698 bfd_boolean warned
, ignored
;
6700 RELOC_FOR_GLOBAL_SYMBOL (info
, input_bfd
, input_section
, rel
,
6701 r_symndx
, symtab_hdr
, sym_hashes
,
6703 unresolved_reloc
, warned
, ignored
);
6708 if (sec
!= NULL
&& discarded_section (sec
))
6709 RELOC_AGAINST_DISCARDED_SECTION (info
, input_bfd
, input_section
,
6710 rel
, 1, relend
, howto
, 0, contents
);
6712 if (bfd_link_relocatable (info
))
6716 name
= h
->root
.root
.string
;
6719 name
= (bfd_elf_string_from_elf_section
6720 (input_bfd
, symtab_hdr
->sh_link
, sym
->st_name
));
6721 if (name
== NULL
|| *name
== '\0')
6722 name
= bfd_section_name (input_bfd
, sec
);
6726 && r_type
!= R_AARCH64_NONE
6727 && r_type
!= R_AARCH64_NULL
6729 || h
->root
.type
== bfd_link_hash_defined
6730 || h
->root
.type
== bfd_link_hash_defweak
)
6731 && IS_AARCH64_TLS_RELOC (bfd_r_type
) != (sym_type
== STT_TLS
))
6734 ((sym_type
== STT_TLS
6735 /* xgettext:c-format */
6736 ? _("%pB(%pA+%#" PRIx64
"): %s used with TLS symbol %s")
6737 /* xgettext:c-format */
6738 : _("%pB(%pA+%#" PRIx64
"): %s used with non-TLS symbol %s")),
6740 input_section
, (uint64_t) rel
->r_offset
, howto
->name
, name
);
6743 /* We relax only if we can see that there can be a valid transition
6744 from a reloc type to another.
6745 We call elfNN_aarch64_final_link_relocate unless we're completely
6746 done, i.e., the relaxation produced the final output we want. */
6748 relaxed_bfd_r_type
= aarch64_tls_transition (input_bfd
, info
, r_type
,
6750 if (relaxed_bfd_r_type
!= bfd_r_type
)
6752 bfd_r_type
= relaxed_bfd_r_type
;
6753 howto
= elfNN_aarch64_howto_from_bfd_reloc (bfd_r_type
);
6754 BFD_ASSERT (howto
!= NULL
);
6755 r_type
= howto
->type
;
6756 r
= elfNN_aarch64_tls_relax (globals
, input_bfd
, input_section
,
6758 unresolved_reloc
= 0;
6761 r
= bfd_reloc_continue
;
6763 /* There may be multiple consecutive relocations for the
6764 same offset. In that case we are supposed to treat the
6765 output of each relocation as the addend for the next. */
6766 if (rel
+ 1 < relend
6767 && rel
->r_offset
== rel
[1].r_offset
6768 && ELFNN_R_TYPE (rel
[1].r_info
) != R_AARCH64_NONE
6769 && ELFNN_R_TYPE (rel
[1].r_info
) != R_AARCH64_NULL
)
6772 save_addend
= FALSE
;
6774 if (r
== bfd_reloc_continue
)
6775 r
= elfNN_aarch64_final_link_relocate (howto
, input_bfd
, output_bfd
,
6776 input_section
, contents
, rel
,
6777 relocation
, info
, sec
,
6778 h
, &unresolved_reloc
,
6779 save_addend
, &addend
, sym
);
6781 switch (elfNN_aarch64_bfd_reloc_from_type (input_bfd
, r_type
))
6783 case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC
:
6784 case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21
:
6785 case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21
:
6786 case BFD_RELOC_AARCH64_TLSGD_MOVW_G0_NC
:
6787 case BFD_RELOC_AARCH64_TLSGD_MOVW_G1
:
6788 case BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC
:
6789 case BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21
:
6790 case BFD_RELOC_AARCH64_TLSLD_ADR_PREL21
:
6791 if (! symbol_got_offset_mark_p (input_bfd
, h
, r_symndx
))
6793 bfd_boolean need_relocs
= FALSE
;
6798 off
= symbol_got_offset (input_bfd
, h
, r_symndx
);
6799 indx
= h
&& h
->dynindx
!= -1 ? h
->dynindx
: 0;
6802 (!bfd_link_executable (info
) || indx
!= 0) &&
6804 || ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
6805 || h
->root
.type
!= bfd_link_hash_undefweak
);
6807 BFD_ASSERT (globals
->root
.srelgot
!= NULL
);
6811 Elf_Internal_Rela rela
;
6812 rela
.r_info
= ELFNN_R_INFO (indx
, AARCH64_R (TLS_DTPMOD
));
6814 rela
.r_offset
= globals
->root
.sgot
->output_section
->vma
+
6815 globals
->root
.sgot
->output_offset
+ off
;
6818 loc
= globals
->root
.srelgot
->contents
;
6819 loc
+= globals
->root
.srelgot
->reloc_count
++
6820 * RELOC_SIZE (htab
);
6821 bfd_elfNN_swap_reloca_out (output_bfd
, &rela
, loc
);
6823 bfd_reloc_code_real_type real_type
=
6824 elfNN_aarch64_bfd_reloc_from_type (input_bfd
, r_type
);
6826 if (real_type
== BFD_RELOC_AARCH64_TLSLD_ADR_PREL21
6827 || real_type
== BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21
6828 || real_type
== BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC
)
6830 /* For local dynamic, don't generate DTPREL in any case.
6831 Initialize the DTPREL slot into zero, so we get module
6832 base address when invoke runtime TLS resolver. */
6833 bfd_put_NN (output_bfd
, 0,
6834 globals
->root
.sgot
->contents
+ off
6839 bfd_put_NN (output_bfd
,
6840 relocation
- dtpoff_base (info
),
6841 globals
->root
.sgot
->contents
+ off
6846 /* This TLS symbol is global. We emit a
6847 relocation to fixup the tls offset at load
6850 ELFNN_R_INFO (indx
, AARCH64_R (TLS_DTPREL
));
6853 (globals
->root
.sgot
->output_section
->vma
6854 + globals
->root
.sgot
->output_offset
+ off
6857 loc
= globals
->root
.srelgot
->contents
;
6858 loc
+= globals
->root
.srelgot
->reloc_count
++
6859 * RELOC_SIZE (globals
);
6860 bfd_elfNN_swap_reloca_out (output_bfd
, &rela
, loc
);
6861 bfd_put_NN (output_bfd
, (bfd_vma
) 0,
6862 globals
->root
.sgot
->contents
+ off
6868 bfd_put_NN (output_bfd
, (bfd_vma
) 1,
6869 globals
->root
.sgot
->contents
+ off
);
6870 bfd_put_NN (output_bfd
,
6871 relocation
- dtpoff_base (info
),
6872 globals
->root
.sgot
->contents
+ off
6876 symbol_got_offset_mark (input_bfd
, h
, r_symndx
);
6880 case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21
:
6881 case BFD_RELOC_AARCH64_TLSIE_LDNN_GOTTPREL_LO12_NC
:
6882 case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19
:
6883 case BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G0_NC
:
6884 case BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G1
:
6885 if (! symbol_got_offset_mark_p (input_bfd
, h
, r_symndx
))
6887 bfd_boolean need_relocs
= FALSE
;
6892 off
= symbol_got_offset (input_bfd
, h
, r_symndx
);
6894 indx
= h
&& h
->dynindx
!= -1 ? h
->dynindx
: 0;
6897 (!bfd_link_executable (info
) || indx
!= 0) &&
6899 || ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
6900 || h
->root
.type
!= bfd_link_hash_undefweak
);
6902 BFD_ASSERT (globals
->root
.srelgot
!= NULL
);
6906 Elf_Internal_Rela rela
;
6909 rela
.r_addend
= relocation
- dtpoff_base (info
);
6913 rela
.r_info
= ELFNN_R_INFO (indx
, AARCH64_R (TLS_TPREL
));
6914 rela
.r_offset
= globals
->root
.sgot
->output_section
->vma
+
6915 globals
->root
.sgot
->output_offset
+ off
;
6917 loc
= globals
->root
.srelgot
->contents
;
6918 loc
+= globals
->root
.srelgot
->reloc_count
++
6919 * RELOC_SIZE (htab
);
6921 bfd_elfNN_swap_reloca_out (output_bfd
, &rela
, loc
);
6923 bfd_put_NN (output_bfd
, rela
.r_addend
,
6924 globals
->root
.sgot
->contents
+ off
);
6927 bfd_put_NN (output_bfd
, relocation
- tpoff_base (info
),
6928 globals
->root
.sgot
->contents
+ off
);
6930 symbol_got_offset_mark (input_bfd
, h
, r_symndx
);
6934 case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12
:
6935 case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21
:
6936 case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21
:
6937 case BFD_RELOC_AARCH64_TLSDESC_LDNN_LO12_NC
:
6938 case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19
:
6939 case BFD_RELOC_AARCH64_TLSDESC_OFF_G0_NC
:
6940 case BFD_RELOC_AARCH64_TLSDESC_OFF_G1
:
6941 if (! symbol_tlsdesc_got_offset_mark_p (input_bfd
, h
, r_symndx
))
6943 bfd_boolean need_relocs
= FALSE
;
6944 int indx
= h
&& h
->dynindx
!= -1 ? h
->dynindx
: 0;
6945 bfd_vma off
= symbol_tlsdesc_got_offset (input_bfd
, h
, r_symndx
);
6947 need_relocs
= (h
== NULL
6948 || ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
6949 || h
->root
.type
!= bfd_link_hash_undefweak
);
6951 BFD_ASSERT (globals
->root
.srelgot
!= NULL
);
6952 BFD_ASSERT (globals
->root
.sgot
!= NULL
);
6957 Elf_Internal_Rela rela
;
6958 rela
.r_info
= ELFNN_R_INFO (indx
, AARCH64_R (TLSDESC
));
6961 rela
.r_offset
= (globals
->root
.sgotplt
->output_section
->vma
6962 + globals
->root
.sgotplt
->output_offset
6963 + off
+ globals
->sgotplt_jump_table_size
);
6966 rela
.r_addend
= relocation
- dtpoff_base (info
);
6968 /* Allocate the next available slot in the PLT reloc
6969 section to hold our R_AARCH64_TLSDESC, the next
6970 available slot is determined from reloc_count,
6971 which we step. But note, reloc_count was
6972 artifically moved down while allocating slots for
6973 real PLT relocs such that all of the PLT relocs
6974 will fit above the initial reloc_count and the
6975 extra stuff will fit below. */
6976 loc
= globals
->root
.srelplt
->contents
;
6977 loc
+= globals
->root
.srelplt
->reloc_count
++
6978 * RELOC_SIZE (globals
);
6980 bfd_elfNN_swap_reloca_out (output_bfd
, &rela
, loc
);
6982 bfd_put_NN (output_bfd
, (bfd_vma
) 0,
6983 globals
->root
.sgotplt
->contents
+ off
+
6984 globals
->sgotplt_jump_table_size
);
6985 bfd_put_NN (output_bfd
, (bfd_vma
) 0,
6986 globals
->root
.sgotplt
->contents
+ off
+
6987 globals
->sgotplt_jump_table_size
+
6991 symbol_tlsdesc_got_offset_mark (input_bfd
, h
, r_symndx
);
6998 /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
6999 because such sections are not SEC_ALLOC and thus ld.so will
7000 not process them. */
7001 if (unresolved_reloc
7002 && !((input_section
->flags
& SEC_DEBUGGING
) != 0
7004 && _bfd_elf_section_offset (output_bfd
, info
, input_section
,
7005 +rel
->r_offset
) != (bfd_vma
) - 1)
7008 /* xgettext:c-format */
7009 (_("%pB(%pA+%#" PRIx64
"): "
7010 "unresolvable %s relocation against symbol `%s'"),
7011 input_bfd
, input_section
, (uint64_t) rel
->r_offset
, howto
->name
,
7012 h
->root
.root
.string
);
7016 if (r
!= bfd_reloc_ok
&& r
!= bfd_reloc_continue
)
7018 bfd_reloc_code_real_type real_r_type
7019 = elfNN_aarch64_bfd_reloc_from_type (input_bfd
, r_type
);
7023 case bfd_reloc_overflow
:
7024 (*info
->callbacks
->reloc_overflow
)
7025 (info
, (h
? &h
->root
: NULL
), name
, howto
->name
, (bfd_vma
) 0,
7026 input_bfd
, input_section
, rel
->r_offset
);
7027 if (real_r_type
== BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15
7028 || real_r_type
== BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14
)
7030 (*info
->callbacks
->warning
)
7032 _("too many GOT entries for -fpic, "
7033 "please recompile with -fPIC"),
7034 name
, input_bfd
, input_section
, rel
->r_offset
);
7037 /* Overflow can occur when a variable is referenced with a type
7038 that has a larger alignment than the type with which it was
7040 file1.c: extern int foo; int a (void) { return foo; }
7041 file2.c: char bar, foo, baz;
7042 If the variable is placed into a data section at an offset
7043 that is incompatible with the larger alignment requirement
7044 overflow will occur. (Strictly speaking this is not overflow
7045 but rather an alignment problem, but the bfd_reloc_ error
7046 enum does not have a value to cover that situation).
7048 Try to catch this situation here and provide a more helpful
7049 error message to the user. */
7050 if (addend
& ((1 << howto
->rightshift
) - 1)
7051 /* FIXME: Are we testing all of the appropriate reloc
7053 && (real_r_type
== BFD_RELOC_AARCH64_LD_LO19_PCREL
7054 || real_r_type
== BFD_RELOC_AARCH64_LDST16_LO12
7055 || real_r_type
== BFD_RELOC_AARCH64_LDST32_LO12
7056 || real_r_type
== BFD_RELOC_AARCH64_LDST64_LO12
7057 || real_r_type
== BFD_RELOC_AARCH64_LDST128_LO12
))
7059 info
->callbacks
->warning
7060 (info
, _("one possible cause of this error is that the \
7061 symbol is being referenced in the indicated code as if it had a larger \
7062 alignment than was declared where it was defined"),
7063 name
, input_bfd
, input_section
, rel
->r_offset
);
7067 case bfd_reloc_undefined
:
7068 (*info
->callbacks
->undefined_symbol
)
7069 (info
, name
, input_bfd
, input_section
, rel
->r_offset
, TRUE
);
7072 case bfd_reloc_outofrange
:
7073 error_message
= _("out of range");
7076 case bfd_reloc_notsupported
:
7077 error_message
= _("unsupported relocation");
7080 case bfd_reloc_dangerous
:
7081 /* error_message should already be set. */
7085 error_message
= _("unknown error");
7089 BFD_ASSERT (error_message
!= NULL
);
7090 (*info
->callbacks
->reloc_dangerous
)
7091 (info
, error_message
, input_bfd
, input_section
, rel
->r_offset
);
7103 /* Set the right machine number. */
7106 elfNN_aarch64_object_p (bfd
*abfd
)
7109 bfd_default_set_arch_mach (abfd
, bfd_arch_aarch64
, bfd_mach_aarch64_ilp32
);
7111 bfd_default_set_arch_mach (abfd
, bfd_arch_aarch64
, bfd_mach_aarch64
);
7116 /* Function to keep AArch64 specific flags in the ELF header. */
7119 elfNN_aarch64_set_private_flags (bfd
*abfd
, flagword flags
)
7121 if (elf_flags_init (abfd
) && elf_elfheader (abfd
)->e_flags
!= flags
)
7126 elf_elfheader (abfd
)->e_flags
= flags
;
7127 elf_flags_init (abfd
) = TRUE
;
7133 /* Merge backend specific data from an object file to the output
7134 object file when linking. */
7137 elfNN_aarch64_merge_private_bfd_data (bfd
*ibfd
, struct bfd_link_info
*info
)
7139 bfd
*obfd
= info
->output_bfd
;
7142 bfd_boolean flags_compatible
= TRUE
;
7145 /* Check if we have the same endianess. */
7146 if (!_bfd_generic_verify_endian_match (ibfd
, info
))
7149 if (!is_aarch64_elf (ibfd
) || !is_aarch64_elf (obfd
))
7152 /* The input BFD must have had its flags initialised. */
7153 /* The following seems bogus to me -- The flags are initialized in
7154 the assembler but I don't think an elf_flags_init field is
7155 written into the object. */
7156 /* BFD_ASSERT (elf_flags_init (ibfd)); */
7158 in_flags
= elf_elfheader (ibfd
)->e_flags
;
7159 out_flags
= elf_elfheader (obfd
)->e_flags
;
7161 if (!elf_flags_init (obfd
))
7163 /* If the input is the default architecture and had the default
7164 flags then do not bother setting the flags for the output
7165 architecture, instead allow future merges to do this. If no
7166 future merges ever set these flags then they will retain their
7167 uninitialised values, which surprise surprise, correspond
7168 to the default values. */
7169 if (bfd_get_arch_info (ibfd
)->the_default
7170 && elf_elfheader (ibfd
)->e_flags
== 0)
7173 elf_flags_init (obfd
) = TRUE
;
7174 elf_elfheader (obfd
)->e_flags
= in_flags
;
7176 if (bfd_get_arch (obfd
) == bfd_get_arch (ibfd
)
7177 && bfd_get_arch_info (obfd
)->the_default
)
7178 return bfd_set_arch_mach (obfd
, bfd_get_arch (ibfd
),
7179 bfd_get_mach (ibfd
));
7184 /* Identical flags must be compatible. */
7185 if (in_flags
== out_flags
)
7188 /* Check to see if the input BFD actually contains any sections. If
7189 not, its flags may not have been initialised either, but it
7190 cannot actually cause any incompatiblity. Do not short-circuit
7191 dynamic objects; their section list may be emptied by
7192 elf_link_add_object_symbols.
7194 Also check to see if there are no code sections in the input.
7195 In this case there is no need to check for code specific flags.
7196 XXX - do we need to worry about floating-point format compatability
7197 in data sections ? */
7198 if (!(ibfd
->flags
& DYNAMIC
))
7200 bfd_boolean null_input_bfd
= TRUE
;
7201 bfd_boolean only_data_sections
= TRUE
;
7203 for (sec
= ibfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
7205 if ((bfd_get_section_flags (ibfd
, sec
)
7206 & (SEC_LOAD
| SEC_CODE
| SEC_HAS_CONTENTS
))
7207 == (SEC_LOAD
| SEC_CODE
| SEC_HAS_CONTENTS
))
7208 only_data_sections
= FALSE
;
7210 null_input_bfd
= FALSE
;
7214 if (null_input_bfd
|| only_data_sections
)
7218 return flags_compatible
;
7221 /* Display the flags field. */
7224 elfNN_aarch64_print_private_bfd_data (bfd
*abfd
, void *ptr
)
7226 FILE *file
= (FILE *) ptr
;
7227 unsigned long flags
;
7229 BFD_ASSERT (abfd
!= NULL
&& ptr
!= NULL
);
7231 /* Print normal ELF private data. */
7232 _bfd_elf_print_private_bfd_data (abfd
, ptr
);
7234 flags
= elf_elfheader (abfd
)->e_flags
;
7235 /* Ignore init flag - it may not be set, despite the flags field
7236 containing valid data. */
7238 /* xgettext:c-format */
7239 fprintf (file
, _("private flags = %lx:"), elf_elfheader (abfd
)->e_flags
);
7242 fprintf (file
, _("<Unrecognised flag bits set>"));
7249 /* Find dynamic relocs for H that apply to read-only sections. */
7252 readonly_dynrelocs (struct elf_link_hash_entry
*h
)
7254 struct elf_dyn_relocs
*p
;
7256 for (p
= elf_aarch64_hash_entry (h
)->dyn_relocs
; p
!= NULL
; p
= p
->next
)
7258 asection
*s
= p
->sec
->output_section
;
7260 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
7266 /* Return true if we need copy relocation against EH. */
7269 need_copy_relocation_p (struct elf_aarch64_link_hash_entry
*eh
)
7271 struct elf_dyn_relocs
*p
;
7274 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
7276 /* If there is any pc-relative reference, we need to keep copy relocation
7277 to avoid propagating the relocation into runtime that current glibc
7278 does not support. */
7282 s
= p
->sec
->output_section
;
7283 /* Need copy relocation if it's against read-only section. */
7284 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
7291 /* Adjust a symbol defined by a dynamic object and referenced by a
7292 regular object. The current definition is in some section of the
7293 dynamic object, but we're not including those sections. We have to
7294 change the definition to something the rest of the link can
7298 elfNN_aarch64_adjust_dynamic_symbol (struct bfd_link_info
*info
,
7299 struct elf_link_hash_entry
*h
)
7301 struct elf_aarch64_link_hash_table
*htab
;
7304 /* If this is a function, put it in the procedure linkage table. We
7305 will fill in the contents of the procedure linkage table later,
7306 when we know the address of the .got section. */
7307 if (h
->type
== STT_FUNC
|| h
->type
== STT_GNU_IFUNC
|| h
->needs_plt
)
7309 if (h
->plt
.refcount
<= 0
7310 || (h
->type
!= STT_GNU_IFUNC
7311 && (SYMBOL_CALLS_LOCAL (info
, h
)
7312 || (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
7313 && h
->root
.type
== bfd_link_hash_undefweak
))))
7315 /* This case can occur if we saw a CALL26 reloc in
7316 an input file, but the symbol wasn't referred to
7317 by a dynamic object or all references were
7318 garbage collected. In which case we can end up
7320 h
->plt
.offset
= (bfd_vma
) - 1;
7327 /* Otherwise, reset to -1. */
7328 h
->plt
.offset
= (bfd_vma
) - 1;
7331 /* If this is a weak symbol, and there is a real definition, the
7332 processor independent code will have arranged for us to see the
7333 real definition first, and we can just use the same value. */
7334 if (h
->is_weakalias
)
7336 struct elf_link_hash_entry
*def
= weakdef (h
);
7337 BFD_ASSERT (def
->root
.type
== bfd_link_hash_defined
);
7338 h
->root
.u
.def
.section
= def
->root
.u
.def
.section
;
7339 h
->root
.u
.def
.value
= def
->root
.u
.def
.value
;
7340 if (ELIMINATE_COPY_RELOCS
|| info
->nocopyreloc
)
7341 h
->non_got_ref
= def
->non_got_ref
;
7345 /* If we are creating a shared library, we must presume that the
7346 only references to the symbol are via the global offset table.
7347 For such cases we need not do anything here; the relocations will
7348 be handled correctly by relocate_section. */
7349 if (bfd_link_pic (info
))
7352 /* If there are no references to this symbol that do not use the
7353 GOT, we don't need to generate a copy reloc. */
7354 if (!h
->non_got_ref
)
7357 /* If -z nocopyreloc was given, we won't generate them either. */
7358 if (info
->nocopyreloc
)
7364 if (ELIMINATE_COPY_RELOCS
)
7366 struct elf_aarch64_link_hash_entry
*eh
;
7367 /* If we don't find any dynamic relocs in read-only sections, then
7368 we'll be keeping the dynamic relocs and avoiding the copy reloc. */
7369 eh
= (struct elf_aarch64_link_hash_entry
*) h
;
7370 if (!need_copy_relocation_p (eh
))
7377 /* We must allocate the symbol in our .dynbss section, which will
7378 become part of the .bss section of the executable. There will be
7379 an entry for this symbol in the .dynsym section. The dynamic
7380 object will contain position independent code, so all references
7381 from the dynamic object to this symbol will go through the global
7382 offset table. The dynamic linker will use the .dynsym entry to
7383 determine the address it must put in the global offset table, so
7384 both the dynamic object and the regular object will refer to the
7385 same memory location for the variable. */
7387 htab
= elf_aarch64_hash_table (info
);
7389 /* We must generate a R_AARCH64_COPY reloc to tell the dynamic linker
7390 to copy the initial value out of the dynamic object and into the
7391 runtime process image. */
7392 if ((h
->root
.u
.def
.section
->flags
& SEC_READONLY
) != 0)
7394 s
= htab
->root
.sdynrelro
;
7395 srel
= htab
->root
.sreldynrelro
;
7399 s
= htab
->root
.sdynbss
;
7400 srel
= htab
->root
.srelbss
;
7402 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0 && h
->size
!= 0)
7404 srel
->size
+= RELOC_SIZE (htab
);
7408 return _bfd_elf_adjust_dynamic_copy (info
, h
, s
);
7413 elfNN_aarch64_allocate_local_symbols (bfd
*abfd
, unsigned number
)
7415 struct elf_aarch64_local_symbol
*locals
;
7416 locals
= elf_aarch64_locals (abfd
);
7419 locals
= (struct elf_aarch64_local_symbol
*)
7420 bfd_zalloc (abfd
, number
* sizeof (struct elf_aarch64_local_symbol
));
7423 elf_aarch64_locals (abfd
) = locals
;
7428 /* Create the .got section to hold the global offset table. */
7431 aarch64_elf_create_got_section (bfd
*abfd
, struct bfd_link_info
*info
)
7433 const struct elf_backend_data
*bed
= get_elf_backend_data (abfd
);
7436 struct elf_link_hash_entry
*h
;
7437 struct elf_link_hash_table
*htab
= elf_hash_table (info
);
7439 /* This function may be called more than once. */
7440 if (htab
->sgot
!= NULL
)
7443 flags
= bed
->dynamic_sec_flags
;
7445 s
= bfd_make_section_anyway_with_flags (abfd
,
7446 (bed
->rela_plts_and_copies_p
7447 ? ".rela.got" : ".rel.got"),
7448 (bed
->dynamic_sec_flags
7451 || ! bfd_set_section_alignment (abfd
, s
, bed
->s
->log_file_align
))
7455 s
= bfd_make_section_anyway_with_flags (abfd
, ".got", flags
);
7457 || !bfd_set_section_alignment (abfd
, s
, bed
->s
->log_file_align
))
7460 htab
->sgot
->size
+= GOT_ENTRY_SIZE
;
7462 if (bed
->want_got_sym
)
7464 /* Define the symbol _GLOBAL_OFFSET_TABLE_ at the start of the .got
7465 (or .got.plt) section. We don't do this in the linker script
7466 because we don't want to define the symbol if we are not creating
7467 a global offset table. */
7468 h
= _bfd_elf_define_linkage_sym (abfd
, info
, s
,
7469 "_GLOBAL_OFFSET_TABLE_");
7470 elf_hash_table (info
)->hgot
= h
;
7475 if (bed
->want_got_plt
)
7477 s
= bfd_make_section_anyway_with_flags (abfd
, ".got.plt", flags
);
7479 || !bfd_set_section_alignment (abfd
, s
,
7480 bed
->s
->log_file_align
))
7485 /* The first bit of the global offset table is the header. */
7486 s
->size
+= bed
->got_header_size
;
7491 /* Look through the relocs for a section during the first phase. */
7494 elfNN_aarch64_check_relocs (bfd
*abfd
, struct bfd_link_info
*info
,
7495 asection
*sec
, const Elf_Internal_Rela
*relocs
)
7497 Elf_Internal_Shdr
*symtab_hdr
;
7498 struct elf_link_hash_entry
**sym_hashes
;
7499 const Elf_Internal_Rela
*rel
;
7500 const Elf_Internal_Rela
*rel_end
;
7503 struct elf_aarch64_link_hash_table
*htab
;
7505 if (bfd_link_relocatable (info
))
7508 BFD_ASSERT (is_aarch64_elf (abfd
));
7510 htab
= elf_aarch64_hash_table (info
);
7513 symtab_hdr
= &elf_symtab_hdr (abfd
);
7514 sym_hashes
= elf_sym_hashes (abfd
);
7516 rel_end
= relocs
+ sec
->reloc_count
;
7517 for (rel
= relocs
; rel
< rel_end
; rel
++)
7519 struct elf_link_hash_entry
*h
;
7520 unsigned int r_symndx
;
7521 unsigned int r_type
;
7522 bfd_reloc_code_real_type bfd_r_type
;
7523 Elf_Internal_Sym
*isym
;
7525 r_symndx
= ELFNN_R_SYM (rel
->r_info
);
7526 r_type
= ELFNN_R_TYPE (rel
->r_info
);
7528 if (r_symndx
>= NUM_SHDR_ENTRIES (symtab_hdr
))
7530 /* xgettext:c-format */
7531 _bfd_error_handler (_("%pB: bad symbol index: %d"), abfd
, r_symndx
);
7535 if (r_symndx
< symtab_hdr
->sh_info
)
7537 /* A local symbol. */
7538 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
7543 /* Check relocation against local STT_GNU_IFUNC symbol. */
7544 if (ELF_ST_TYPE (isym
->st_info
) == STT_GNU_IFUNC
)
7546 h
= elfNN_aarch64_get_local_sym_hash (htab
, abfd
, rel
,
7551 /* Fake a STT_GNU_IFUNC symbol. */
7552 h
->type
= STT_GNU_IFUNC
;
7555 h
->forced_local
= 1;
7556 h
->root
.type
= bfd_link_hash_defined
;
7563 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
7564 while (h
->root
.type
== bfd_link_hash_indirect
7565 || h
->root
.type
== bfd_link_hash_warning
)
7566 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
7569 /* Could be done earlier, if h were already available. */
7570 bfd_r_type
= aarch64_tls_transition (abfd
, info
, r_type
, h
, r_symndx
);
7574 /* If a relocation refers to _GLOBAL_OFFSET_TABLE_, create the .got.
7575 This shows up in particular in an R_AARCH64_PREL64 in large model
7576 when calculating the pc-relative address to .got section which is
7577 used to initialize the gp register. */
7578 if (h
->root
.root
.string
7579 && strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_") == 0)
7581 if (htab
->root
.dynobj
== NULL
)
7582 htab
->root
.dynobj
= abfd
;
7584 if (! aarch64_elf_create_got_section (htab
->root
.dynobj
, info
))
7587 BFD_ASSERT (h
== htab
->root
.hgot
);
7590 /* Create the ifunc sections for static executables. If we
7591 never see an indirect function symbol nor we are building
7592 a static executable, those sections will be empty and
7593 won't appear in output. */
7599 case BFD_RELOC_AARCH64_ADD_LO12
:
7600 case BFD_RELOC_AARCH64_ADR_GOT_PAGE
:
7601 case BFD_RELOC_AARCH64_ADR_HI21_PCREL
:
7602 case BFD_RELOC_AARCH64_CALL26
:
7603 case BFD_RELOC_AARCH64_GOT_LD_PREL19
:
7604 case BFD_RELOC_AARCH64_JUMP26
:
7605 case BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14
:
7606 case BFD_RELOC_AARCH64_LD32_GOT_LO12_NC
:
7607 case BFD_RELOC_AARCH64_LD64_GOTOFF_LO15
:
7608 case BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15
:
7609 case BFD_RELOC_AARCH64_LD64_GOT_LO12_NC
:
7610 case BFD_RELOC_AARCH64_MOVW_GOTOFF_G0_NC
:
7611 case BFD_RELOC_AARCH64_MOVW_GOTOFF_G1
:
7612 case BFD_RELOC_AARCH64_NN
:
7613 if (htab
->root
.dynobj
== NULL
)
7614 htab
->root
.dynobj
= abfd
;
7615 if (!_bfd_elf_create_ifunc_sections (htab
->root
.dynobj
, info
))
7620 /* It is referenced by a non-shared object. */
7626 case BFD_RELOC_AARCH64_16
:
7628 case BFD_RELOC_AARCH64_32
:
7630 if (bfd_link_pic (info
) && (sec
->flags
& SEC_ALLOC
) != 0)
7633 /* This is an absolute symbol. It represents a value instead
7635 && (bfd_is_abs_symbol (&h
->root
)
7636 /* This is an undefined symbol. */
7637 || h
->root
.type
== bfd_link_hash_undefined
))
7640 /* For local symbols, defined global symbols in a non-ABS section,
7641 it is assumed that the value is an address. */
7642 int howto_index
= bfd_r_type
- BFD_RELOC_AARCH64_RELOC_START
;
7644 /* xgettext:c-format */
7645 (_("%pB: relocation %s against `%s' can not be used when making "
7647 abfd
, elfNN_aarch64_howto_table
[howto_index
].name
,
7648 (h
) ? h
->root
.root
.string
: "a local symbol");
7649 bfd_set_error (bfd_error_bad_value
);
7655 case BFD_RELOC_AARCH64_MOVW_G0_NC
:
7656 case BFD_RELOC_AARCH64_MOVW_G1_NC
:
7657 case BFD_RELOC_AARCH64_MOVW_G2_NC
:
7658 case BFD_RELOC_AARCH64_MOVW_G3
:
7659 if (bfd_link_pic (info
))
7661 int howto_index
= bfd_r_type
- BFD_RELOC_AARCH64_RELOC_START
;
7663 /* xgettext:c-format */
7664 (_("%pB: relocation %s against `%s' can not be used when making "
7665 "a shared object; recompile with -fPIC"),
7666 abfd
, elfNN_aarch64_howto_table
[howto_index
].name
,
7667 (h
) ? h
->root
.root
.string
: "a local symbol");
7668 bfd_set_error (bfd_error_bad_value
);
7673 case BFD_RELOC_AARCH64_16_PCREL
:
7674 case BFD_RELOC_AARCH64_32_PCREL
:
7675 case BFD_RELOC_AARCH64_64_PCREL
:
7676 case BFD_RELOC_AARCH64_ADD_LO12
:
7677 case BFD_RELOC_AARCH64_ADR_HI21_NC_PCREL
:
7678 case BFD_RELOC_AARCH64_ADR_HI21_PCREL
:
7679 case BFD_RELOC_AARCH64_ADR_LO21_PCREL
:
7680 case BFD_RELOC_AARCH64_LDST128_LO12
:
7681 case BFD_RELOC_AARCH64_LDST16_LO12
:
7682 case BFD_RELOC_AARCH64_LDST32_LO12
:
7683 case BFD_RELOC_AARCH64_LDST64_LO12
:
7684 case BFD_RELOC_AARCH64_LDST8_LO12
:
7685 case BFD_RELOC_AARCH64_LD_LO19_PCREL
:
7686 if (h
== NULL
|| bfd_link_pic (info
))
7690 case BFD_RELOC_AARCH64_NN
:
7692 /* We don't need to handle relocs into sections not going into
7693 the "real" output. */
7694 if ((sec
->flags
& SEC_ALLOC
) == 0)
7699 if (!bfd_link_pic (info
))
7702 h
->plt
.refcount
+= 1;
7703 h
->pointer_equality_needed
= 1;
7706 /* No need to do anything if we're not creating a shared
7708 if (!(bfd_link_pic (info
)
7709 /* If on the other hand, we are creating an executable, we
7710 may need to keep relocations for symbols satisfied by a
7711 dynamic library if we manage to avoid copy relocs for the
7714 NOTE: Currently, there is no support of copy relocs
7715 elimination on pc-relative relocation types, because there is
7716 no dynamic relocation support for them in glibc. We still
7717 record the dynamic symbol reference for them. This is
7718 because one symbol may be referenced by both absolute
7719 relocation (for example, BFD_RELOC_AARCH64_NN) and
7720 pc-relative relocation. We need full symbol reference
7721 information to make correct decision later in
7722 elfNN_aarch64_adjust_dynamic_symbol. */
7723 || (ELIMINATE_COPY_RELOCS
7724 && !bfd_link_pic (info
)
7726 && (h
->root
.type
== bfd_link_hash_defweak
7727 || !h
->def_regular
))))
7731 struct elf_dyn_relocs
*p
;
7732 struct elf_dyn_relocs
**head
;
7733 int howto_index
= bfd_r_type
- BFD_RELOC_AARCH64_RELOC_START
;
7735 /* We must copy these reloc types into the output file.
7736 Create a reloc section in dynobj and make room for
7740 if (htab
->root
.dynobj
== NULL
)
7741 htab
->root
.dynobj
= abfd
;
7743 sreloc
= _bfd_elf_make_dynamic_reloc_section
7744 (sec
, htab
->root
.dynobj
, LOG_FILE_ALIGN
, abfd
, /*rela? */ TRUE
);
7750 /* If this is a global symbol, we count the number of
7751 relocations we need for this symbol. */
7754 struct elf_aarch64_link_hash_entry
*eh
;
7755 eh
= (struct elf_aarch64_link_hash_entry
*) h
;
7756 head
= &eh
->dyn_relocs
;
7760 /* Track dynamic relocs needed for local syms too.
7761 We really need local syms available to do this
7767 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
7772 s
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
7776 /* Beware of type punned pointers vs strict aliasing
7778 vpp
= &(elf_section_data (s
)->local_dynrel
);
7779 head
= (struct elf_dyn_relocs
**) vpp
;
7783 if (p
== NULL
|| p
->sec
!= sec
)
7785 bfd_size_type amt
= sizeof *p
;
7786 p
= ((struct elf_dyn_relocs
*)
7787 bfd_zalloc (htab
->root
.dynobj
, amt
));
7797 if (elfNN_aarch64_howto_table
[howto_index
].pc_relative
)
7802 /* RR: We probably want to keep a consistency check that
7803 there are no dangling GOT_PAGE relocs. */
7804 case BFD_RELOC_AARCH64_ADR_GOT_PAGE
:
7805 case BFD_RELOC_AARCH64_GOT_LD_PREL19
:
7806 case BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14
:
7807 case BFD_RELOC_AARCH64_LD32_GOT_LO12_NC
:
7808 case BFD_RELOC_AARCH64_LD64_GOTOFF_LO15
:
7809 case BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15
:
7810 case BFD_RELOC_AARCH64_LD64_GOT_LO12_NC
:
7811 case BFD_RELOC_AARCH64_MOVW_GOTOFF_G0_NC
:
7812 case BFD_RELOC_AARCH64_MOVW_GOTOFF_G1
:
7813 case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12
:
7814 case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21
:
7815 case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21
:
7816 case BFD_RELOC_AARCH64_TLSDESC_LD32_LO12_NC
:
7817 case BFD_RELOC_AARCH64_TLSDESC_LD64_LO12
:
7818 case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19
:
7819 case BFD_RELOC_AARCH64_TLSDESC_OFF_G0_NC
:
7820 case BFD_RELOC_AARCH64_TLSDESC_OFF_G1
:
7821 case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC
:
7822 case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21
:
7823 case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21
:
7824 case BFD_RELOC_AARCH64_TLSGD_MOVW_G0_NC
:
7825 case BFD_RELOC_AARCH64_TLSGD_MOVW_G1
:
7826 case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21
:
7827 case BFD_RELOC_AARCH64_TLSIE_LD32_GOTTPREL_LO12_NC
:
7828 case BFD_RELOC_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC
:
7829 case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19
:
7830 case BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G0_NC
:
7831 case BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G1
:
7832 case BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC
:
7833 case BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21
:
7834 case BFD_RELOC_AARCH64_TLSLD_ADR_PREL21
:
7837 unsigned old_got_type
;
7839 got_type
= aarch64_reloc_got_type (bfd_r_type
);
7843 h
->got
.refcount
+= 1;
7844 old_got_type
= elf_aarch64_hash_entry (h
)->got_type
;
7848 struct elf_aarch64_local_symbol
*locals
;
7850 if (!elfNN_aarch64_allocate_local_symbols
7851 (abfd
, symtab_hdr
->sh_info
))
7854 locals
= elf_aarch64_locals (abfd
);
7855 BFD_ASSERT (r_symndx
< symtab_hdr
->sh_info
);
7856 locals
[r_symndx
].got_refcount
+= 1;
7857 old_got_type
= locals
[r_symndx
].got_type
;
7860 /* If a variable is accessed with both general dynamic TLS
7861 methods, two slots may be created. */
7862 if (GOT_TLS_GD_ANY_P (old_got_type
) && GOT_TLS_GD_ANY_P (got_type
))
7863 got_type
|= old_got_type
;
7865 /* We will already have issued an error message if there
7866 is a TLS/non-TLS mismatch, based on the symbol type.
7867 So just combine any TLS types needed. */
7868 if (old_got_type
!= GOT_UNKNOWN
&& old_got_type
!= GOT_NORMAL
7869 && got_type
!= GOT_NORMAL
)
7870 got_type
|= old_got_type
;
7872 /* If the symbol is accessed by both IE and GD methods, we
7873 are able to relax. Turn off the GD flag, without
7874 messing up with any other kind of TLS types that may be
7876 if ((got_type
& GOT_TLS_IE
) && GOT_TLS_GD_ANY_P (got_type
))
7877 got_type
&= ~ (GOT_TLSDESC_GD
| GOT_TLS_GD
);
7879 if (old_got_type
!= got_type
)
7882 elf_aarch64_hash_entry (h
)->got_type
= got_type
;
7885 struct elf_aarch64_local_symbol
*locals
;
7886 locals
= elf_aarch64_locals (abfd
);
7887 BFD_ASSERT (r_symndx
< symtab_hdr
->sh_info
);
7888 locals
[r_symndx
].got_type
= got_type
;
7892 if (htab
->root
.dynobj
== NULL
)
7893 htab
->root
.dynobj
= abfd
;
7894 if (! aarch64_elf_create_got_section (htab
->root
.dynobj
, info
))
7899 case BFD_RELOC_AARCH64_CALL26
:
7900 case BFD_RELOC_AARCH64_JUMP26
:
7901 /* If this is a local symbol then we resolve it
7902 directly without creating a PLT entry. */
7907 if (h
->plt
.refcount
<= 0)
7908 h
->plt
.refcount
= 1;
7910 h
->plt
.refcount
+= 1;
7921 /* Treat mapping symbols as special target symbols. */
7924 elfNN_aarch64_is_target_special_symbol (bfd
*abfd ATTRIBUTE_UNUSED
,
7927 return bfd_is_aarch64_special_symbol_name (sym
->name
,
7928 BFD_AARCH64_SPECIAL_SYM_TYPE_ANY
);
7931 /* This is a copy of elf_find_function () from elf.c except that
7932 AArch64 mapping symbols are ignored when looking for function names. */
7935 aarch64_elf_find_function (bfd
*abfd ATTRIBUTE_UNUSED
,
7939 const char **filename_ptr
,
7940 const char **functionname_ptr
)
7942 const char *filename
= NULL
;
7943 asymbol
*func
= NULL
;
7944 bfd_vma low_func
= 0;
7947 for (p
= symbols
; *p
!= NULL
; p
++)
7951 q
= (elf_symbol_type
*) * p
;
7953 switch (ELF_ST_TYPE (q
->internal_elf_sym
.st_info
))
7958 filename
= bfd_asymbol_name (&q
->symbol
);
7962 /* Skip mapping symbols. */
7963 if ((q
->symbol
.flags
& BSF_LOCAL
)
7964 && (bfd_is_aarch64_special_symbol_name
7965 (q
->symbol
.name
, BFD_AARCH64_SPECIAL_SYM_TYPE_ANY
)))
7968 if (bfd_get_section (&q
->symbol
) == section
7969 && q
->symbol
.value
>= low_func
&& q
->symbol
.value
<= offset
)
7971 func
= (asymbol
*) q
;
7972 low_func
= q
->symbol
.value
;
7982 *filename_ptr
= filename
;
7983 if (functionname_ptr
)
7984 *functionname_ptr
= bfd_asymbol_name (func
);
7990 /* Find the nearest line to a particular section and offset, for error
7991 reporting. This code is a duplicate of the code in elf.c, except
7992 that it uses aarch64_elf_find_function. */
7995 elfNN_aarch64_find_nearest_line (bfd
*abfd
,
7999 const char **filename_ptr
,
8000 const char **functionname_ptr
,
8001 unsigned int *line_ptr
,
8002 unsigned int *discriminator_ptr
)
8004 bfd_boolean found
= FALSE
;
8006 if (_bfd_dwarf2_find_nearest_line (abfd
, symbols
, NULL
, section
, offset
,
8007 filename_ptr
, functionname_ptr
,
8008 line_ptr
, discriminator_ptr
,
8009 dwarf_debug_sections
, 0,
8010 &elf_tdata (abfd
)->dwarf2_find_line_info
))
8012 if (!*functionname_ptr
)
8013 aarch64_elf_find_function (abfd
, symbols
, section
, offset
,
8014 *filename_ptr
? NULL
: filename_ptr
,
8020 /* Skip _bfd_dwarf1_find_nearest_line since no known AArch64
8021 toolchain uses DWARF1. */
8023 if (!_bfd_stab_section_find_nearest_line (abfd
, symbols
, section
, offset
,
8024 &found
, filename_ptr
,
8025 functionname_ptr
, line_ptr
,
8026 &elf_tdata (abfd
)->line_info
))
8029 if (found
&& (*functionname_ptr
|| *line_ptr
))
8032 if (symbols
== NULL
)
8035 if (!aarch64_elf_find_function (abfd
, symbols
, section
, offset
,
8036 filename_ptr
, functionname_ptr
))
8044 elfNN_aarch64_find_inliner_info (bfd
*abfd
,
8045 const char **filename_ptr
,
8046 const char **functionname_ptr
,
8047 unsigned int *line_ptr
)
8050 found
= _bfd_dwarf2_find_inliner_info
8051 (abfd
, filename_ptr
,
8052 functionname_ptr
, line_ptr
, &elf_tdata (abfd
)->dwarf2_find_line_info
);
8058 elfNN_aarch64_post_process_headers (bfd
*abfd
,
8059 struct bfd_link_info
*link_info
)
8061 Elf_Internal_Ehdr
*i_ehdrp
; /* ELF file header, internal form. */
8063 i_ehdrp
= elf_elfheader (abfd
);
8064 i_ehdrp
->e_ident
[EI_ABIVERSION
] = AARCH64_ELF_ABI_VERSION
;
8066 _bfd_elf_post_process_headers (abfd
, link_info
);
8069 static enum elf_reloc_type_class
8070 elfNN_aarch64_reloc_type_class (const struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
8071 const asection
*rel_sec ATTRIBUTE_UNUSED
,
8072 const Elf_Internal_Rela
*rela
)
8074 struct elf_aarch64_link_hash_table
*htab
= elf_aarch64_hash_table (info
);
8076 if (htab
->root
.dynsym
!= NULL
8077 && htab
->root
.dynsym
->contents
!= NULL
)
8079 /* Check relocation against STT_GNU_IFUNC symbol if there are
8081 bfd
*abfd
= info
->output_bfd
;
8082 const struct elf_backend_data
*bed
= get_elf_backend_data (abfd
);
8083 unsigned long r_symndx
= ELFNN_R_SYM (rela
->r_info
);
8084 if (r_symndx
!= STN_UNDEF
)
8086 Elf_Internal_Sym sym
;
8087 if (!bed
->s
->swap_symbol_in (abfd
,
8088 (htab
->root
.dynsym
->contents
8089 + r_symndx
* bed
->s
->sizeof_sym
),
8092 /* xgettext:c-format */
8093 _bfd_error_handler (_("%pB symbol number %lu references"
8094 " nonexistent SHT_SYMTAB_SHNDX section"),
8096 /* Ideally an error class should be returned here. */
8098 else if (ELF_ST_TYPE (sym
.st_info
) == STT_GNU_IFUNC
)
8099 return reloc_class_ifunc
;
8103 switch ((int) ELFNN_R_TYPE (rela
->r_info
))
8105 case AARCH64_R (IRELATIVE
):
8106 return reloc_class_ifunc
;
8107 case AARCH64_R (RELATIVE
):
8108 return reloc_class_relative
;
8109 case AARCH64_R (JUMP_SLOT
):
8110 return reloc_class_plt
;
8111 case AARCH64_R (COPY
):
8112 return reloc_class_copy
;
8114 return reloc_class_normal
;
8118 /* Handle an AArch64 specific section when reading an object file. This is
8119 called when bfd_section_from_shdr finds a section with an unknown
8123 elfNN_aarch64_section_from_shdr (bfd
*abfd
,
8124 Elf_Internal_Shdr
*hdr
,
8125 const char *name
, int shindex
)
8127 /* There ought to be a place to keep ELF backend specific flags, but
8128 at the moment there isn't one. We just keep track of the
8129 sections by their name, instead. Fortunately, the ABI gives
8130 names for all the AArch64 specific sections, so we will probably get
8132 switch (hdr
->sh_type
)
8134 case SHT_AARCH64_ATTRIBUTES
:
8141 if (!_bfd_elf_make_section_from_shdr (abfd
, hdr
, name
, shindex
))
8147 /* A structure used to record a list of sections, independently
8148 of the next and prev fields in the asection structure. */
8149 typedef struct section_list
8152 struct section_list
*next
;
8153 struct section_list
*prev
;
8157 /* Unfortunately we need to keep a list of sections for which
8158 an _aarch64_elf_section_data structure has been allocated. This
8159 is because it is possible for functions like elfNN_aarch64_write_section
8160 to be called on a section which has had an elf_data_structure
8161 allocated for it (and so the used_by_bfd field is valid) but
8162 for which the AArch64 extended version of this structure - the
8163 _aarch64_elf_section_data structure - has not been allocated. */
8164 static section_list
*sections_with_aarch64_elf_section_data
= NULL
;
8167 record_section_with_aarch64_elf_section_data (asection
*sec
)
8169 struct section_list
*entry
;
8171 entry
= bfd_malloc (sizeof (*entry
));
8175 entry
->next
= sections_with_aarch64_elf_section_data
;
8177 if (entry
->next
!= NULL
)
8178 entry
->next
->prev
= entry
;
8179 sections_with_aarch64_elf_section_data
= entry
;
8182 static struct section_list
*
8183 find_aarch64_elf_section_entry (asection
*sec
)
8185 struct section_list
*entry
;
8186 static struct section_list
*last_entry
= NULL
;
8188 /* This is a short cut for the typical case where the sections are added
8189 to the sections_with_aarch64_elf_section_data list in forward order and
8190 then looked up here in backwards order. This makes a real difference
8191 to the ld-srec/sec64k.exp linker test. */
8192 entry
= sections_with_aarch64_elf_section_data
;
8193 if (last_entry
!= NULL
)
8195 if (last_entry
->sec
== sec
)
8197 else if (last_entry
->next
!= NULL
&& last_entry
->next
->sec
== sec
)
8198 entry
= last_entry
->next
;
8201 for (; entry
; entry
= entry
->next
)
8202 if (entry
->sec
== sec
)
8206 /* Record the entry prior to this one - it is the entry we are
8207 most likely to want to locate next time. Also this way if we
8208 have been called from
8209 unrecord_section_with_aarch64_elf_section_data () we will not
8210 be caching a pointer that is about to be freed. */
8211 last_entry
= entry
->prev
;
8217 unrecord_section_with_aarch64_elf_section_data (asection
*sec
)
8219 struct section_list
*entry
;
8221 entry
= find_aarch64_elf_section_entry (sec
);
8225 if (entry
->prev
!= NULL
)
8226 entry
->prev
->next
= entry
->next
;
8227 if (entry
->next
!= NULL
)
8228 entry
->next
->prev
= entry
->prev
;
8229 if (entry
== sections_with_aarch64_elf_section_data
)
8230 sections_with_aarch64_elf_section_data
= entry
->next
;
8239 struct bfd_link_info
*info
;
8242 int (*func
) (void *, const char *, Elf_Internal_Sym
*,
8243 asection
*, struct elf_link_hash_entry
*);
8244 } output_arch_syminfo
;
8246 enum map_symbol_type
8253 /* Output a single mapping symbol. */
8256 elfNN_aarch64_output_map_sym (output_arch_syminfo
*osi
,
8257 enum map_symbol_type type
, bfd_vma offset
)
8259 static const char *names
[2] = { "$x", "$d" };
8260 Elf_Internal_Sym sym
;
8262 sym
.st_value
= (osi
->sec
->output_section
->vma
8263 + osi
->sec
->output_offset
+ offset
);
8266 sym
.st_info
= ELF_ST_INFO (STB_LOCAL
, STT_NOTYPE
);
8267 sym
.st_shndx
= osi
->sec_shndx
;
8268 return osi
->func (osi
->finfo
, names
[type
], &sym
, osi
->sec
, NULL
) == 1;
8271 /* Output a single local symbol for a generated stub. */
8274 elfNN_aarch64_output_stub_sym (output_arch_syminfo
*osi
, const char *name
,
8275 bfd_vma offset
, bfd_vma size
)
8277 Elf_Internal_Sym sym
;
8279 sym
.st_value
= (osi
->sec
->output_section
->vma
8280 + osi
->sec
->output_offset
+ offset
);
8283 sym
.st_info
= ELF_ST_INFO (STB_LOCAL
, STT_FUNC
);
8284 sym
.st_shndx
= osi
->sec_shndx
;
8285 return osi
->func (osi
->finfo
, name
, &sym
, osi
->sec
, NULL
) == 1;
8289 aarch64_map_one_stub (struct bfd_hash_entry
*gen_entry
, void *in_arg
)
8291 struct elf_aarch64_stub_hash_entry
*stub_entry
;
8295 output_arch_syminfo
*osi
;
8297 /* Massage our args to the form they really have. */
8298 stub_entry
= (struct elf_aarch64_stub_hash_entry
*) gen_entry
;
8299 osi
= (output_arch_syminfo
*) in_arg
;
8301 stub_sec
= stub_entry
->stub_sec
;
8303 /* Ensure this stub is attached to the current section being
8305 if (stub_sec
!= osi
->sec
)
8308 addr
= (bfd_vma
) stub_entry
->stub_offset
;
8310 stub_name
= stub_entry
->output_name
;
8312 switch (stub_entry
->stub_type
)
8314 case aarch64_stub_adrp_branch
:
8315 if (!elfNN_aarch64_output_stub_sym (osi
, stub_name
, addr
,
8316 sizeof (aarch64_adrp_branch_stub
)))
8318 if (!elfNN_aarch64_output_map_sym (osi
, AARCH64_MAP_INSN
, addr
))
8321 case aarch64_stub_long_branch
:
8322 if (!elfNN_aarch64_output_stub_sym
8323 (osi
, stub_name
, addr
, sizeof (aarch64_long_branch_stub
)))
8325 if (!elfNN_aarch64_output_map_sym (osi
, AARCH64_MAP_INSN
, addr
))
8327 if (!elfNN_aarch64_output_map_sym (osi
, AARCH64_MAP_DATA
, addr
+ 16))
8330 case aarch64_stub_erratum_835769_veneer
:
8331 if (!elfNN_aarch64_output_stub_sym (osi
, stub_name
, addr
,
8332 sizeof (aarch64_erratum_835769_stub
)))
8334 if (!elfNN_aarch64_output_map_sym (osi
, AARCH64_MAP_INSN
, addr
))
8337 case aarch64_stub_erratum_843419_veneer
:
8338 if (!elfNN_aarch64_output_stub_sym (osi
, stub_name
, addr
,
8339 sizeof (aarch64_erratum_843419_stub
)))
8341 if (!elfNN_aarch64_output_map_sym (osi
, AARCH64_MAP_INSN
, addr
))
8344 case aarch64_stub_none
:
8354 /* Output mapping symbols for linker generated sections. */
8357 elfNN_aarch64_output_arch_local_syms (bfd
*output_bfd
,
8358 struct bfd_link_info
*info
,
8360 int (*func
) (void *, const char *,
8363 struct elf_link_hash_entry
8366 output_arch_syminfo osi
;
8367 struct elf_aarch64_link_hash_table
*htab
;
8369 htab
= elf_aarch64_hash_table (info
);
8375 /* Long calls stubs. */
8376 if (htab
->stub_bfd
&& htab
->stub_bfd
->sections
)
8380 for (stub_sec
= htab
->stub_bfd
->sections
;
8381 stub_sec
!= NULL
; stub_sec
= stub_sec
->next
)
8383 /* Ignore non-stub sections. */
8384 if (!strstr (stub_sec
->name
, STUB_SUFFIX
))
8389 osi
.sec_shndx
= _bfd_elf_section_from_bfd_section
8390 (output_bfd
, osi
.sec
->output_section
);
8392 /* The first instruction in a stub is always a branch. */
8393 if (!elfNN_aarch64_output_map_sym (&osi
, AARCH64_MAP_INSN
, 0))
8396 bfd_hash_traverse (&htab
->stub_hash_table
, aarch64_map_one_stub
,
8401 /* Finally, output mapping symbols for the PLT. */
8402 if (!htab
->root
.splt
|| htab
->root
.splt
->size
== 0)
8405 osi
.sec_shndx
= _bfd_elf_section_from_bfd_section
8406 (output_bfd
, htab
->root
.splt
->output_section
);
8407 osi
.sec
= htab
->root
.splt
;
8409 elfNN_aarch64_output_map_sym (&osi
, AARCH64_MAP_INSN
, 0);
8415 /* Allocate target specific section data. */
8418 elfNN_aarch64_new_section_hook (bfd
*abfd
, asection
*sec
)
8420 if (!sec
->used_by_bfd
)
8422 _aarch64_elf_section_data
*sdata
;
8423 bfd_size_type amt
= sizeof (*sdata
);
8425 sdata
= bfd_zalloc (abfd
, amt
);
8428 sec
->used_by_bfd
= sdata
;
8431 record_section_with_aarch64_elf_section_data (sec
);
8433 return _bfd_elf_new_section_hook (abfd
, sec
);
8438 unrecord_section_via_map_over_sections (bfd
*abfd ATTRIBUTE_UNUSED
,
8440 void *ignore ATTRIBUTE_UNUSED
)
8442 unrecord_section_with_aarch64_elf_section_data (sec
);
8446 elfNN_aarch64_close_and_cleanup (bfd
*abfd
)
8449 bfd_map_over_sections (abfd
,
8450 unrecord_section_via_map_over_sections
, NULL
);
8452 return _bfd_elf_close_and_cleanup (abfd
);
8456 elfNN_aarch64_bfd_free_cached_info (bfd
*abfd
)
8459 bfd_map_over_sections (abfd
,
8460 unrecord_section_via_map_over_sections
, NULL
);
8462 return _bfd_free_cached_info (abfd
);
8465 /* Create dynamic sections. This is different from the ARM backend in that
8466 the got, plt, gotplt and their relocation sections are all created in the
8467 standard part of the bfd elf backend. */
8470 elfNN_aarch64_create_dynamic_sections (bfd
*dynobj
,
8471 struct bfd_link_info
*info
)
8473 /* We need to create .got section. */
8474 if (!aarch64_elf_create_got_section (dynobj
, info
))
8477 return _bfd_elf_create_dynamic_sections (dynobj
, info
);
8481 /* Allocate space in .plt, .got and associated reloc sections for
8485 elfNN_aarch64_allocate_dynrelocs (struct elf_link_hash_entry
*h
, void *inf
)
8487 struct bfd_link_info
*info
;
8488 struct elf_aarch64_link_hash_table
*htab
;
8489 struct elf_aarch64_link_hash_entry
*eh
;
8490 struct elf_dyn_relocs
*p
;
8492 /* An example of a bfd_link_hash_indirect symbol is versioned
8493 symbol. For example: __gxx_personality_v0(bfd_link_hash_indirect)
8494 -> __gxx_personality_v0(bfd_link_hash_defined)
8496 There is no need to process bfd_link_hash_indirect symbols here
8497 because we will also be presented with the concrete instance of
8498 the symbol and elfNN_aarch64_copy_indirect_symbol () will have been
8499 called to copy all relevant data from the generic to the concrete
8501 if (h
->root
.type
== bfd_link_hash_indirect
)
8504 if (h
->root
.type
== bfd_link_hash_warning
)
8505 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
8507 info
= (struct bfd_link_info
*) inf
;
8508 htab
= elf_aarch64_hash_table (info
);
8510 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle it
8511 here if it is defined and referenced in a non-shared object. */
8512 if (h
->type
== STT_GNU_IFUNC
8515 else if (htab
->root
.dynamic_sections_created
&& h
->plt
.refcount
> 0)
8517 /* Make sure this symbol is output as a dynamic symbol.
8518 Undefined weak syms won't yet be marked as dynamic. */
8519 if (h
->dynindx
== -1 && !h
->forced_local
8520 && h
->root
.type
== bfd_link_hash_undefweak
)
8522 if (!bfd_elf_link_record_dynamic_symbol (info
, h
))
8526 if (bfd_link_pic (info
) || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h
))
8528 asection
*s
= htab
->root
.splt
;
8530 /* If this is the first .plt entry, make room for the special
8533 s
->size
+= htab
->plt_header_size
;
8535 h
->plt
.offset
= s
->size
;
8537 /* If this symbol is not defined in a regular file, and we are
8538 not generating a shared library, then set the symbol to this
8539 location in the .plt. This is required to make function
8540 pointers compare as equal between the normal executable and
8541 the shared library. */
8542 if (!bfd_link_pic (info
) && !h
->def_regular
)
8544 h
->root
.u
.def
.section
= s
;
8545 h
->root
.u
.def
.value
= h
->plt
.offset
;
8548 /* Make room for this entry. For now we only create the
8549 small model PLT entries. We later need to find a way
8550 of relaxing into these from the large model PLT entries. */
8551 s
->size
+= htab
->plt_entry_size
;
8553 /* We also need to make an entry in the .got.plt section, which
8554 will be placed in the .got section by the linker script. */
8555 htab
->root
.sgotplt
->size
+= GOT_ENTRY_SIZE
;
8557 /* We also need to make an entry in the .rela.plt section. */
8558 htab
->root
.srelplt
->size
+= RELOC_SIZE (htab
);
8560 /* We need to ensure that all GOT entries that serve the PLT
8561 are consecutive with the special GOT slots [0] [1] and
8562 [2]. Any addtional relocations, such as
8563 R_AARCH64_TLSDESC, must be placed after the PLT related
8564 entries. We abuse the reloc_count such that during
8565 sizing we adjust reloc_count to indicate the number of
8566 PLT related reserved entries. In subsequent phases when
8567 filling in the contents of the reloc entries, PLT related
8568 entries are placed by computing their PLT index (0
8569 .. reloc_count). While other none PLT relocs are placed
8570 at the slot indicated by reloc_count and reloc_count is
8573 htab
->root
.srelplt
->reloc_count
++;
8577 h
->plt
.offset
= (bfd_vma
) - 1;
8583 h
->plt
.offset
= (bfd_vma
) - 1;
8587 eh
= (struct elf_aarch64_link_hash_entry
*) h
;
8588 eh
->tlsdesc_got_jump_table_offset
= (bfd_vma
) - 1;
8590 if (h
->got
.refcount
> 0)
8593 unsigned got_type
= elf_aarch64_hash_entry (h
)->got_type
;
8595 h
->got
.offset
= (bfd_vma
) - 1;
8597 dyn
= htab
->root
.dynamic_sections_created
;
8599 /* Make sure this symbol is output as a dynamic symbol.
8600 Undefined weak syms won't yet be marked as dynamic. */
8601 if (dyn
&& h
->dynindx
== -1 && !h
->forced_local
8602 && h
->root
.type
== bfd_link_hash_undefweak
)
8604 if (!bfd_elf_link_record_dynamic_symbol (info
, h
))
8608 if (got_type
== GOT_UNKNOWN
)
8611 else if (got_type
== GOT_NORMAL
)
8613 h
->got
.offset
= htab
->root
.sgot
->size
;
8614 htab
->root
.sgot
->size
+= GOT_ENTRY_SIZE
;
8615 if ((ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
8616 || h
->root
.type
!= bfd_link_hash_undefweak
)
8617 && (bfd_link_pic (info
)
8618 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, 0, h
))
8619 /* Undefined weak symbol in static PIE resolves to 0 without
8620 any dynamic relocations. */
8621 && !UNDEFWEAK_NO_DYNAMIC_RELOC (info
, h
))
8623 htab
->root
.srelgot
->size
+= RELOC_SIZE (htab
);
8629 if (got_type
& GOT_TLSDESC_GD
)
8631 eh
->tlsdesc_got_jump_table_offset
=
8632 (htab
->root
.sgotplt
->size
8633 - aarch64_compute_jump_table_size (htab
));
8634 htab
->root
.sgotplt
->size
+= GOT_ENTRY_SIZE
* 2;
8635 h
->got
.offset
= (bfd_vma
) - 2;
8638 if (got_type
& GOT_TLS_GD
)
8640 h
->got
.offset
= htab
->root
.sgot
->size
;
8641 htab
->root
.sgot
->size
+= GOT_ENTRY_SIZE
* 2;
8644 if (got_type
& GOT_TLS_IE
)
8646 h
->got
.offset
= htab
->root
.sgot
->size
;
8647 htab
->root
.sgot
->size
+= GOT_ENTRY_SIZE
;
8650 indx
= h
&& h
->dynindx
!= -1 ? h
->dynindx
: 0;
8651 if ((ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
8652 || h
->root
.type
!= bfd_link_hash_undefweak
)
8653 && (!bfd_link_executable (info
)
8655 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, 0, h
)))
8657 if (got_type
& GOT_TLSDESC_GD
)
8659 htab
->root
.srelplt
->size
+= RELOC_SIZE (htab
);
8660 /* Note reloc_count not incremented here! We have
8661 already adjusted reloc_count for this relocation
8664 /* TLSDESC PLT is now needed, but not yet determined. */
8665 htab
->tlsdesc_plt
= (bfd_vma
) - 1;
8668 if (got_type
& GOT_TLS_GD
)
8669 htab
->root
.srelgot
->size
+= RELOC_SIZE (htab
) * 2;
8671 if (got_type
& GOT_TLS_IE
)
8672 htab
->root
.srelgot
->size
+= RELOC_SIZE (htab
);
8678 h
->got
.offset
= (bfd_vma
) - 1;
8681 if (eh
->dyn_relocs
== NULL
)
8684 /* In the shared -Bsymbolic case, discard space allocated for
8685 dynamic pc-relative relocs against symbols which turn out to be
8686 defined in regular objects. For the normal shared case, discard
8687 space for pc-relative relocs that have become local due to symbol
8688 visibility changes. */
8690 if (bfd_link_pic (info
))
8692 /* Relocs that use pc_count are those that appear on a call
8693 insn, or certain REL relocs that can generated via assembly.
8694 We want calls to protected symbols to resolve directly to the
8695 function rather than going via the plt. If people want
8696 function pointer comparisons to work as expected then they
8697 should avoid writing weird assembly. */
8698 if (SYMBOL_CALLS_LOCAL (info
, h
))
8700 struct elf_dyn_relocs
**pp
;
8702 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
;)
8704 p
->count
-= p
->pc_count
;
8713 /* Also discard relocs on undefined weak syms with non-default
8715 if (eh
->dyn_relocs
!= NULL
&& h
->root
.type
== bfd_link_hash_undefweak
)
8717 if (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
8718 || UNDEFWEAK_NO_DYNAMIC_RELOC (info
, h
))
8719 eh
->dyn_relocs
= NULL
;
8721 /* Make sure undefined weak symbols are output as a dynamic
8723 else if (h
->dynindx
== -1
8725 && h
->root
.type
== bfd_link_hash_undefweak
8726 && !bfd_elf_link_record_dynamic_symbol (info
, h
))
8731 else if (ELIMINATE_COPY_RELOCS
)
8733 /* For the non-shared case, discard space for relocs against
8734 symbols which turn out to need copy relocs or are not
8740 || (htab
->root
.dynamic_sections_created
8741 && (h
->root
.type
== bfd_link_hash_undefweak
8742 || h
->root
.type
== bfd_link_hash_undefined
))))
8744 /* Make sure this symbol is output as a dynamic symbol.
8745 Undefined weak syms won't yet be marked as dynamic. */
8746 if (h
->dynindx
== -1
8748 && h
->root
.type
== bfd_link_hash_undefweak
8749 && !bfd_elf_link_record_dynamic_symbol (info
, h
))
8752 /* If that succeeded, we know we'll be keeping all the
8754 if (h
->dynindx
!= -1)
8758 eh
->dyn_relocs
= NULL
;
8763 /* Finally, allocate space. */
8764 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
8768 sreloc
= elf_section_data (p
->sec
)->sreloc
;
8770 BFD_ASSERT (sreloc
!= NULL
);
8772 sreloc
->size
+= p
->count
* RELOC_SIZE (htab
);
8778 /* Allocate space in .plt, .got and associated reloc sections for
8779 ifunc dynamic relocs. */
8782 elfNN_aarch64_allocate_ifunc_dynrelocs (struct elf_link_hash_entry
*h
,
8785 struct bfd_link_info
*info
;
8786 struct elf_aarch64_link_hash_table
*htab
;
8787 struct elf_aarch64_link_hash_entry
*eh
;
8789 /* An example of a bfd_link_hash_indirect symbol is versioned
8790 symbol. For example: __gxx_personality_v0(bfd_link_hash_indirect)
8791 -> __gxx_personality_v0(bfd_link_hash_defined)
8793 There is no need to process bfd_link_hash_indirect symbols here
8794 because we will also be presented with the concrete instance of
8795 the symbol and elfNN_aarch64_copy_indirect_symbol () will have been
8796 called to copy all relevant data from the generic to the concrete
8798 if (h
->root
.type
== bfd_link_hash_indirect
)
8801 if (h
->root
.type
== bfd_link_hash_warning
)
8802 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
8804 info
= (struct bfd_link_info
*) inf
;
8805 htab
= elf_aarch64_hash_table (info
);
8807 eh
= (struct elf_aarch64_link_hash_entry
*) h
;
8809 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle it
8810 here if it is defined and referenced in a non-shared object. */
8811 if (h
->type
== STT_GNU_IFUNC
8813 return _bfd_elf_allocate_ifunc_dyn_relocs (info
, h
,
8816 htab
->plt_entry_size
,
8817 htab
->plt_header_size
,
8823 /* Allocate space in .plt, .got and associated reloc sections for
8824 local dynamic relocs. */
8827 elfNN_aarch64_allocate_local_dynrelocs (void **slot
, void *inf
)
8829 struct elf_link_hash_entry
*h
8830 = (struct elf_link_hash_entry
*) *slot
;
8832 if (h
->type
!= STT_GNU_IFUNC
8836 || h
->root
.type
!= bfd_link_hash_defined
)
8839 return elfNN_aarch64_allocate_dynrelocs (h
, inf
);
8842 /* Allocate space in .plt, .got and associated reloc sections for
8843 local ifunc dynamic relocs. */
8846 elfNN_aarch64_allocate_local_ifunc_dynrelocs (void **slot
, void *inf
)
8848 struct elf_link_hash_entry
*h
8849 = (struct elf_link_hash_entry
*) *slot
;
8851 if (h
->type
!= STT_GNU_IFUNC
8855 || h
->root
.type
!= bfd_link_hash_defined
)
8858 return elfNN_aarch64_allocate_ifunc_dynrelocs (h
, inf
);
8861 /* Set DF_TEXTREL if we find any dynamic relocs that apply to
8862 read-only sections. */
8865 maybe_set_textrel (struct elf_link_hash_entry
*h
, void *info_p
)
8869 if (h
->root
.type
== bfd_link_hash_indirect
)
8872 sec
= readonly_dynrelocs (h
);
8875 struct bfd_link_info
*info
= (struct bfd_link_info
*) info_p
;
8877 info
->flags
|= DF_TEXTREL
;
8878 info
->callbacks
->minfo
8879 (_("%pB: dynamic relocation against `%pT' in read-only section `%pA'\n"),
8880 sec
->owner
, h
->root
.root
.string
, sec
);
8882 /* Not an error, just cut short the traversal. */
8888 /* This is the most important function of all . Innocuosly named
8892 elfNN_aarch64_size_dynamic_sections (bfd
*output_bfd ATTRIBUTE_UNUSED
,
8893 struct bfd_link_info
*info
)
8895 struct elf_aarch64_link_hash_table
*htab
;
8901 htab
= elf_aarch64_hash_table ((info
));
8902 dynobj
= htab
->root
.dynobj
;
8904 BFD_ASSERT (dynobj
!= NULL
);
8906 if (htab
->root
.dynamic_sections_created
)
8908 if (bfd_link_executable (info
) && !info
->nointerp
)
8910 s
= bfd_get_linker_section (dynobj
, ".interp");
8913 s
->size
= sizeof ELF_DYNAMIC_INTERPRETER
;
8914 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
8918 /* Set up .got offsets for local syms, and space for local dynamic
8920 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
8922 struct elf_aarch64_local_symbol
*locals
= NULL
;
8923 Elf_Internal_Shdr
*symtab_hdr
;
8927 if (!is_aarch64_elf (ibfd
))
8930 for (s
= ibfd
->sections
; s
!= NULL
; s
= s
->next
)
8932 struct elf_dyn_relocs
*p
;
8934 for (p
= (struct elf_dyn_relocs
*)
8935 (elf_section_data (s
)->local_dynrel
); p
!= NULL
; p
= p
->next
)
8937 if (!bfd_is_abs_section (p
->sec
)
8938 && bfd_is_abs_section (p
->sec
->output_section
))
8940 /* Input section has been discarded, either because
8941 it is a copy of a linkonce section or due to
8942 linker script /DISCARD/, so we'll be discarding
8945 else if (p
->count
!= 0)
8947 srel
= elf_section_data (p
->sec
)->sreloc
;
8948 srel
->size
+= p
->count
* RELOC_SIZE (htab
);
8949 if ((p
->sec
->output_section
->flags
& SEC_READONLY
) != 0)
8950 info
->flags
|= DF_TEXTREL
;
8955 locals
= elf_aarch64_locals (ibfd
);
8959 symtab_hdr
= &elf_symtab_hdr (ibfd
);
8960 srel
= htab
->root
.srelgot
;
8961 for (i
= 0; i
< symtab_hdr
->sh_info
; i
++)
8963 locals
[i
].got_offset
= (bfd_vma
) - 1;
8964 locals
[i
].tlsdesc_got_jump_table_offset
= (bfd_vma
) - 1;
8965 if (locals
[i
].got_refcount
> 0)
8967 unsigned got_type
= locals
[i
].got_type
;
8968 if (got_type
& GOT_TLSDESC_GD
)
8970 locals
[i
].tlsdesc_got_jump_table_offset
=
8971 (htab
->root
.sgotplt
->size
8972 - aarch64_compute_jump_table_size (htab
));
8973 htab
->root
.sgotplt
->size
+= GOT_ENTRY_SIZE
* 2;
8974 locals
[i
].got_offset
= (bfd_vma
) - 2;
8977 if (got_type
& GOT_TLS_GD
)
8979 locals
[i
].got_offset
= htab
->root
.sgot
->size
;
8980 htab
->root
.sgot
->size
+= GOT_ENTRY_SIZE
* 2;
8983 if (got_type
& GOT_TLS_IE
8984 || got_type
& GOT_NORMAL
)
8986 locals
[i
].got_offset
= htab
->root
.sgot
->size
;
8987 htab
->root
.sgot
->size
+= GOT_ENTRY_SIZE
;
8990 if (got_type
== GOT_UNKNOWN
)
8994 if (bfd_link_pic (info
))
8996 if (got_type
& GOT_TLSDESC_GD
)
8998 htab
->root
.srelplt
->size
+= RELOC_SIZE (htab
);
8999 /* Note RELOC_COUNT not incremented here! */
9000 htab
->tlsdesc_plt
= (bfd_vma
) - 1;
9003 if (got_type
& GOT_TLS_GD
)
9004 htab
->root
.srelgot
->size
+= RELOC_SIZE (htab
) * 2;
9006 if (got_type
& GOT_TLS_IE
9007 || got_type
& GOT_NORMAL
)
9008 htab
->root
.srelgot
->size
+= RELOC_SIZE (htab
);
9013 locals
[i
].got_refcount
= (bfd_vma
) - 1;
9019 /* Allocate global sym .plt and .got entries, and space for global
9020 sym dynamic relocs. */
9021 elf_link_hash_traverse (&htab
->root
, elfNN_aarch64_allocate_dynrelocs
,
9024 /* Allocate global ifunc sym .plt and .got entries, and space for global
9025 ifunc sym dynamic relocs. */
9026 elf_link_hash_traverse (&htab
->root
, elfNN_aarch64_allocate_ifunc_dynrelocs
,
9029 /* Allocate .plt and .got entries, and space for local symbols. */
9030 htab_traverse (htab
->loc_hash_table
,
9031 elfNN_aarch64_allocate_local_dynrelocs
,
9034 /* Allocate .plt and .got entries, and space for local ifunc symbols. */
9035 htab_traverse (htab
->loc_hash_table
,
9036 elfNN_aarch64_allocate_local_ifunc_dynrelocs
,
9039 /* For every jump slot reserved in the sgotplt, reloc_count is
9040 incremented. However, when we reserve space for TLS descriptors,
9041 it's not incremented, so in order to compute the space reserved
9042 for them, it suffices to multiply the reloc count by the jump
9045 if (htab
->root
.srelplt
)
9046 htab
->sgotplt_jump_table_size
= aarch64_compute_jump_table_size (htab
);
9048 if (htab
->tlsdesc_plt
)
9050 if (htab
->root
.splt
->size
== 0)
9051 htab
->root
.splt
->size
+= htab
->plt_header_size
;
9053 /* If we're not using lazy TLS relocations, don't generate the
9054 GOT and PLT entry required. */
9055 if (!(info
->flags
& DF_BIND_NOW
))
9057 htab
->tlsdesc_plt
= htab
->root
.splt
->size
;
9058 htab
->root
.splt
->size
+= htab
->tlsdesc_plt_entry_size
;
9060 htab
->dt_tlsdesc_got
= htab
->root
.sgot
->size
;
9061 htab
->root
.sgot
->size
+= GOT_ENTRY_SIZE
;
9065 /* Init mapping symbols information to use later to distingush between
9066 code and data while scanning for errata. */
9067 if (htab
->fix_erratum_835769
|| htab
->fix_erratum_843419
)
9068 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
9070 if (!is_aarch64_elf (ibfd
))
9072 bfd_elfNN_aarch64_init_maps (ibfd
);
9075 /* We now have determined the sizes of the various dynamic sections.
9076 Allocate memory for them. */
9078 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
9080 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
9083 if (s
== htab
->root
.splt
9084 || s
== htab
->root
.sgot
9085 || s
== htab
->root
.sgotplt
9086 || s
== htab
->root
.iplt
9087 || s
== htab
->root
.igotplt
9088 || s
== htab
->root
.sdynbss
9089 || s
== htab
->root
.sdynrelro
)
9091 /* Strip this section if we don't need it; see the
9094 else if (CONST_STRNEQ (bfd_get_section_name (dynobj
, s
), ".rela"))
9096 if (s
->size
!= 0 && s
!= htab
->root
.srelplt
)
9099 /* We use the reloc_count field as a counter if we need
9100 to copy relocs into the output file. */
9101 if (s
!= htab
->root
.srelplt
)
9106 /* It's not one of our sections, so don't allocate space. */
9112 /* If we don't need this section, strip it from the
9113 output file. This is mostly to handle .rela.bss and
9114 .rela.plt. We must create both sections in
9115 create_dynamic_sections, because they must be created
9116 before the linker maps input sections to output
9117 sections. The linker does that before
9118 adjust_dynamic_symbol is called, and it is that
9119 function which decides whether anything needs to go
9120 into these sections. */
9121 s
->flags
|= SEC_EXCLUDE
;
9125 if ((s
->flags
& SEC_HAS_CONTENTS
) == 0)
9128 /* Allocate memory for the section contents. We use bfd_zalloc
9129 here in case unused entries are not reclaimed before the
9130 section's contents are written out. This should not happen,
9131 but this way if it does, we get a R_AARCH64_NONE reloc instead
9133 s
->contents
= (bfd_byte
*) bfd_zalloc (dynobj
, s
->size
);
9134 if (s
->contents
== NULL
)
9138 if (htab
->root
.dynamic_sections_created
)
9140 /* Add some entries to the .dynamic section. We fill in the
9141 values later, in elfNN_aarch64_finish_dynamic_sections, but we
9142 must add the entries now so that we get the correct size for
9143 the .dynamic section. The DT_DEBUG entry is filled in by the
9144 dynamic linker and used by the debugger. */
9145 #define add_dynamic_entry(TAG, VAL) \
9146 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
9148 if (bfd_link_executable (info
))
9150 if (!add_dynamic_entry (DT_DEBUG
, 0))
9154 if (htab
->root
.splt
->size
!= 0)
9156 if (!add_dynamic_entry (DT_PLTGOT
, 0)
9157 || !add_dynamic_entry (DT_PLTRELSZ
, 0)
9158 || !add_dynamic_entry (DT_PLTREL
, DT_RELA
)
9159 || !add_dynamic_entry (DT_JMPREL
, 0))
9162 if (htab
->tlsdesc_plt
9163 && !(info
->flags
& DF_BIND_NOW
)
9164 && (!add_dynamic_entry (DT_TLSDESC_PLT
, 0)
9165 || !add_dynamic_entry (DT_TLSDESC_GOT
, 0)))
9168 if ((elf_aarch64_tdata (output_bfd
)->plt_type
== PLT_BTI_PAC
)
9169 && (!add_dynamic_entry (DT_AARCH64_BTI_PLT
, 0)
9170 || !add_dynamic_entry (DT_AARCH64_PAC_PLT
, 0)))
9173 else if ((elf_aarch64_tdata (output_bfd
)->plt_type
== PLT_BTI
)
9174 && !add_dynamic_entry (DT_AARCH64_BTI_PLT
, 0))
9177 else if ((elf_aarch64_tdata (output_bfd
)->plt_type
== PLT_PAC
)
9178 && !add_dynamic_entry (DT_AARCH64_PAC_PLT
, 0))
9184 if (!add_dynamic_entry (DT_RELA
, 0)
9185 || !add_dynamic_entry (DT_RELASZ
, 0)
9186 || !add_dynamic_entry (DT_RELAENT
, RELOC_SIZE (htab
)))
9189 /* If any dynamic relocs apply to a read-only section,
9190 then we need a DT_TEXTREL entry. */
9191 if ((info
->flags
& DF_TEXTREL
) == 0)
9192 elf_link_hash_traverse (&htab
->root
, maybe_set_textrel
, info
);
9194 if ((info
->flags
& DF_TEXTREL
) != 0)
9196 if (!add_dynamic_entry (DT_TEXTREL
, 0))
9201 #undef add_dynamic_entry
9207 elf_aarch64_update_plt_entry (bfd
*output_bfd
,
9208 bfd_reloc_code_real_type r_type
,
9209 bfd_byte
*plt_entry
, bfd_vma value
)
9211 reloc_howto_type
*howto
= elfNN_aarch64_howto_from_bfd_reloc (r_type
);
9213 /* FIXME: We should check the return value from this function call. */
9214 (void) _bfd_aarch64_elf_put_addend (output_bfd
, plt_entry
, r_type
, howto
, value
);
9218 elfNN_aarch64_create_small_pltn_entry (struct elf_link_hash_entry
*h
,
9219 struct elf_aarch64_link_hash_table
9220 *htab
, bfd
*output_bfd
,
9221 struct bfd_link_info
*info
)
9223 bfd_byte
*plt_entry
;
9226 bfd_vma gotplt_entry_address
;
9227 bfd_vma plt_entry_address
;
9228 Elf_Internal_Rela rela
;
9230 asection
*plt
, *gotplt
, *relplt
;
9232 /* When building a static executable, use .iplt, .igot.plt and
9233 .rela.iplt sections for STT_GNU_IFUNC symbols. */
9234 if (htab
->root
.splt
!= NULL
)
9236 plt
= htab
->root
.splt
;
9237 gotplt
= htab
->root
.sgotplt
;
9238 relplt
= htab
->root
.srelplt
;
9242 plt
= htab
->root
.iplt
;
9243 gotplt
= htab
->root
.igotplt
;
9244 relplt
= htab
->root
.irelplt
;
9247 /* Get the index in the procedure linkage table which
9248 corresponds to this symbol. This is the index of this symbol
9249 in all the symbols for which we are making plt entries. The
9250 first entry in the procedure linkage table is reserved.
9252 Get the offset into the .got table of the entry that
9253 corresponds to this function. Each .got entry is GOT_ENTRY_SIZE
9254 bytes. The first three are reserved for the dynamic linker.
9256 For static executables, we don't reserve anything. */
9258 if (plt
== htab
->root
.splt
)
9260 plt_index
= (h
->plt
.offset
- htab
->plt_header_size
) / htab
->plt_entry_size
;
9261 got_offset
= (plt_index
+ 3) * GOT_ENTRY_SIZE
;
9265 plt_index
= h
->plt
.offset
/ htab
->plt_entry_size
;
9266 got_offset
= plt_index
* GOT_ENTRY_SIZE
;
9269 plt_entry
= plt
->contents
+ h
->plt
.offset
;
9270 plt_entry_address
= plt
->output_section
->vma
9271 + plt
->output_offset
+ h
->plt
.offset
;
9272 gotplt_entry_address
= gotplt
->output_section
->vma
+
9273 gotplt
->output_offset
+ got_offset
;
9275 /* Copy in the boiler-plate for the PLTn entry. */
9276 memcpy (plt_entry
, htab
->plt_entry
, htab
->plt_entry_size
);
9278 /* First instruction in BTI enabled PLT stub is a BTI
9279 instruction so skip it. */
9280 if (elf_aarch64_tdata (output_bfd
)->plt_type
& PLT_BTI
9281 && elf_elfheader (output_bfd
)->e_type
== ET_EXEC
)
9282 plt_entry
= plt_entry
+ 4;
9284 /* Fill in the top 21 bits for this: ADRP x16, PLT_GOT + n * 8.
9285 ADRP: ((PG(S+A)-PG(P)) >> 12) & 0x1fffff */
9286 elf_aarch64_update_plt_entry (output_bfd
, BFD_RELOC_AARCH64_ADR_HI21_PCREL
,
9288 PG (gotplt_entry_address
) -
9289 PG (plt_entry_address
));
9291 /* Fill in the lo12 bits for the load from the pltgot. */
9292 elf_aarch64_update_plt_entry (output_bfd
, BFD_RELOC_AARCH64_LDSTNN_LO12
,
9294 PG_OFFSET (gotplt_entry_address
));
9296 /* Fill in the lo12 bits for the add from the pltgot entry. */
9297 elf_aarch64_update_plt_entry (output_bfd
, BFD_RELOC_AARCH64_ADD_LO12
,
9299 PG_OFFSET (gotplt_entry_address
));
9301 /* All the GOTPLT Entries are essentially initialized to PLT0. */
9302 bfd_put_NN (output_bfd
,
9303 plt
->output_section
->vma
+ plt
->output_offset
,
9304 gotplt
->contents
+ got_offset
);
9306 rela
.r_offset
= gotplt_entry_address
;
9308 if (h
->dynindx
== -1
9309 || ((bfd_link_executable (info
)
9310 || ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
)
9312 && h
->type
== STT_GNU_IFUNC
))
9314 /* If an STT_GNU_IFUNC symbol is locally defined, generate
9315 R_AARCH64_IRELATIVE instead of R_AARCH64_JUMP_SLOT. */
9316 rela
.r_info
= ELFNN_R_INFO (0, AARCH64_R (IRELATIVE
));
9317 rela
.r_addend
= (h
->root
.u
.def
.value
9318 + h
->root
.u
.def
.section
->output_section
->vma
9319 + h
->root
.u
.def
.section
->output_offset
);
9323 /* Fill in the entry in the .rela.plt section. */
9324 rela
.r_info
= ELFNN_R_INFO (h
->dynindx
, AARCH64_R (JUMP_SLOT
));
9328 /* Compute the relocation entry to used based on PLT index and do
9329 not adjust reloc_count. The reloc_count has already been adjusted
9330 to account for this entry. */
9331 loc
= relplt
->contents
+ plt_index
* RELOC_SIZE (htab
);
9332 bfd_elfNN_swap_reloca_out (output_bfd
, &rela
, loc
);
9335 /* Size sections even though they're not dynamic. We use it to setup
9336 _TLS_MODULE_BASE_, if needed. */
9339 elfNN_aarch64_always_size_sections (bfd
*output_bfd
,
9340 struct bfd_link_info
*info
)
9344 if (bfd_link_relocatable (info
))
9347 tls_sec
= elf_hash_table (info
)->tls_sec
;
9351 struct elf_link_hash_entry
*tlsbase
;
9353 tlsbase
= elf_link_hash_lookup (elf_hash_table (info
),
9354 "_TLS_MODULE_BASE_", TRUE
, TRUE
, FALSE
);
9358 struct bfd_link_hash_entry
*h
= NULL
;
9359 const struct elf_backend_data
*bed
=
9360 get_elf_backend_data (output_bfd
);
9362 if (!(_bfd_generic_link_add_one_symbol
9363 (info
, output_bfd
, "_TLS_MODULE_BASE_", BSF_LOCAL
,
9364 tls_sec
, 0, NULL
, FALSE
, bed
->collect
, &h
)))
9367 tlsbase
->type
= STT_TLS
;
9368 tlsbase
= (struct elf_link_hash_entry
*) h
;
9369 tlsbase
->def_regular
= 1;
9370 tlsbase
->other
= STV_HIDDEN
;
9371 (*bed
->elf_backend_hide_symbol
) (info
, tlsbase
, TRUE
);
9378 /* Finish up dynamic symbol handling. We set the contents of various
9379 dynamic sections here. */
9382 elfNN_aarch64_finish_dynamic_symbol (bfd
*output_bfd
,
9383 struct bfd_link_info
*info
,
9384 struct elf_link_hash_entry
*h
,
9385 Elf_Internal_Sym
*sym
)
9387 struct elf_aarch64_link_hash_table
*htab
;
9388 htab
= elf_aarch64_hash_table (info
);
9390 if (h
->plt
.offset
!= (bfd_vma
) - 1)
9392 asection
*plt
, *gotplt
, *relplt
;
9394 /* This symbol has an entry in the procedure linkage table. Set
9397 /* When building a static executable, use .iplt, .igot.plt and
9398 .rela.iplt sections for STT_GNU_IFUNC symbols. */
9399 if (htab
->root
.splt
!= NULL
)
9401 plt
= htab
->root
.splt
;
9402 gotplt
= htab
->root
.sgotplt
;
9403 relplt
= htab
->root
.srelplt
;
9407 plt
= htab
->root
.iplt
;
9408 gotplt
= htab
->root
.igotplt
;
9409 relplt
= htab
->root
.irelplt
;
9412 /* This symbol has an entry in the procedure linkage table. Set
9414 if ((h
->dynindx
== -1
9415 && !((h
->forced_local
|| bfd_link_executable (info
))
9417 && h
->type
== STT_GNU_IFUNC
))
9423 elfNN_aarch64_create_small_pltn_entry (h
, htab
, output_bfd
, info
);
9424 if (!h
->def_regular
)
9426 /* Mark the symbol as undefined, rather than as defined in
9427 the .plt section. */
9428 sym
->st_shndx
= SHN_UNDEF
;
9429 /* If the symbol is weak we need to clear the value.
9430 Otherwise, the PLT entry would provide a definition for
9431 the symbol even if the symbol wasn't defined anywhere,
9432 and so the symbol would never be NULL. Leave the value if
9433 there were any relocations where pointer equality matters
9434 (this is a clue for the dynamic linker, to make function
9435 pointer comparisons work between an application and shared
9437 if (!h
->ref_regular_nonweak
|| !h
->pointer_equality_needed
)
9442 if (h
->got
.offset
!= (bfd_vma
) - 1
9443 && elf_aarch64_hash_entry (h
)->got_type
== GOT_NORMAL
9444 /* Undefined weak symbol in static PIE resolves to 0 without
9445 any dynamic relocations. */
9446 && !UNDEFWEAK_NO_DYNAMIC_RELOC (info
, h
))
9448 Elf_Internal_Rela rela
;
9451 /* This symbol has an entry in the global offset table. Set it
9453 if (htab
->root
.sgot
== NULL
|| htab
->root
.srelgot
== NULL
)
9456 rela
.r_offset
= (htab
->root
.sgot
->output_section
->vma
9457 + htab
->root
.sgot
->output_offset
9458 + (h
->got
.offset
& ~(bfd_vma
) 1));
9461 && h
->type
== STT_GNU_IFUNC
)
9463 if (bfd_link_pic (info
))
9465 /* Generate R_AARCH64_GLOB_DAT. */
9472 if (!h
->pointer_equality_needed
)
9475 /* For non-shared object, we can't use .got.plt, which
9476 contains the real function address if we need pointer
9477 equality. We load the GOT entry with the PLT entry. */
9478 plt
= htab
->root
.splt
? htab
->root
.splt
: htab
->root
.iplt
;
9479 bfd_put_NN (output_bfd
, (plt
->output_section
->vma
9480 + plt
->output_offset
9482 htab
->root
.sgot
->contents
9483 + (h
->got
.offset
& ~(bfd_vma
) 1));
9487 else if (bfd_link_pic (info
) && SYMBOL_REFERENCES_LOCAL (info
, h
))
9489 if (!(h
->def_regular
|| ELF_COMMON_DEF_P (h
)))
9492 BFD_ASSERT ((h
->got
.offset
& 1) != 0);
9493 rela
.r_info
= ELFNN_R_INFO (0, AARCH64_R (RELATIVE
));
9494 rela
.r_addend
= (h
->root
.u
.def
.value
9495 + h
->root
.u
.def
.section
->output_section
->vma
9496 + h
->root
.u
.def
.section
->output_offset
);
9501 BFD_ASSERT ((h
->got
.offset
& 1) == 0);
9502 bfd_put_NN (output_bfd
, (bfd_vma
) 0,
9503 htab
->root
.sgot
->contents
+ h
->got
.offset
);
9504 rela
.r_info
= ELFNN_R_INFO (h
->dynindx
, AARCH64_R (GLOB_DAT
));
9508 loc
= htab
->root
.srelgot
->contents
;
9509 loc
+= htab
->root
.srelgot
->reloc_count
++ * RELOC_SIZE (htab
);
9510 bfd_elfNN_swap_reloca_out (output_bfd
, &rela
, loc
);
9515 Elf_Internal_Rela rela
;
9519 /* This symbol needs a copy reloc. Set it up. */
9520 if (h
->dynindx
== -1
9521 || (h
->root
.type
!= bfd_link_hash_defined
9522 && h
->root
.type
!= bfd_link_hash_defweak
)
9523 || htab
->root
.srelbss
== NULL
)
9526 rela
.r_offset
= (h
->root
.u
.def
.value
9527 + h
->root
.u
.def
.section
->output_section
->vma
9528 + h
->root
.u
.def
.section
->output_offset
);
9529 rela
.r_info
= ELFNN_R_INFO (h
->dynindx
, AARCH64_R (COPY
));
9531 if (h
->root
.u
.def
.section
== htab
->root
.sdynrelro
)
9532 s
= htab
->root
.sreldynrelro
;
9534 s
= htab
->root
.srelbss
;
9535 loc
= s
->contents
+ s
->reloc_count
++ * RELOC_SIZE (htab
);
9536 bfd_elfNN_swap_reloca_out (output_bfd
, &rela
, loc
);
9539 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. SYM may
9540 be NULL for local symbols. */
9542 && (h
== elf_hash_table (info
)->hdynamic
9543 || h
== elf_hash_table (info
)->hgot
))
9544 sym
->st_shndx
= SHN_ABS
;
9549 /* Finish up local dynamic symbol handling. We set the contents of
9550 various dynamic sections here. */
9553 elfNN_aarch64_finish_local_dynamic_symbol (void **slot
, void *inf
)
9555 struct elf_link_hash_entry
*h
9556 = (struct elf_link_hash_entry
*) *slot
;
9557 struct bfd_link_info
*info
9558 = (struct bfd_link_info
*) inf
;
9560 return elfNN_aarch64_finish_dynamic_symbol (info
->output_bfd
,
9565 elfNN_aarch64_init_small_plt0_entry (bfd
*output_bfd ATTRIBUTE_UNUSED
,
9566 struct elf_aarch64_link_hash_table
9569 /* Fill in PLT0. Fixme:RR Note this doesn't distinguish between
9570 small and large plts and at the minute just generates
9573 /* PLT0 of the small PLT looks like this in ELF64 -
9574 stp x16, x30, [sp, #-16]! // Save the reloc and lr on stack.
9575 adrp x16, PLT_GOT + 16 // Get the page base of the GOTPLT
9576 ldr x17, [x16, #:lo12:PLT_GOT+16] // Load the address of the
9578 add x16, x16, #:lo12:PLT_GOT+16 // Load the lo12 bits of the
9579 // GOTPLT entry for this.
9581 PLT0 will be slightly different in ELF32 due to different got entry
9583 bfd_vma plt_got_2nd_ent
; /* Address of GOT[2]. */
9587 memcpy (htab
->root
.splt
->contents
, htab
->plt0_entry
,
9588 htab
->plt_header_size
);
9589 elf_section_data (htab
->root
.splt
->output_section
)->this_hdr
.sh_entsize
=
9590 htab
->plt_header_size
;
9592 plt_got_2nd_ent
= (htab
->root
.sgotplt
->output_section
->vma
9593 + htab
->root
.sgotplt
->output_offset
9594 + GOT_ENTRY_SIZE
* 2);
9596 plt_base
= htab
->root
.splt
->output_section
->vma
+
9597 htab
->root
.splt
->output_offset
;
9599 /* First instruction in BTI enabled PLT stub is a BTI
9600 instruction so skip it. */
9601 bfd_byte
*plt0_entry
= htab
->root
.splt
->contents
;
9602 if (elf_aarch64_tdata (output_bfd
)->plt_type
& PLT_BTI
)
9603 plt0_entry
= plt0_entry
+ 4;
9605 /* Fill in the top 21 bits for this: ADRP x16, PLT_GOT + n * 8.
9606 ADRP: ((PG(S+A)-PG(P)) >> 12) & 0x1fffff */
9607 elf_aarch64_update_plt_entry (output_bfd
, BFD_RELOC_AARCH64_ADR_HI21_PCREL
,
9609 PG (plt_got_2nd_ent
) - PG (plt_base
+ 4));
9611 elf_aarch64_update_plt_entry (output_bfd
, BFD_RELOC_AARCH64_LDSTNN_LO12
,
9613 PG_OFFSET (plt_got_2nd_ent
));
9615 elf_aarch64_update_plt_entry (output_bfd
, BFD_RELOC_AARCH64_ADD_LO12
,
9617 PG_OFFSET (plt_got_2nd_ent
));
9621 elfNN_aarch64_finish_dynamic_sections (bfd
*output_bfd
,
9622 struct bfd_link_info
*info
)
9624 struct elf_aarch64_link_hash_table
*htab
;
9628 htab
= elf_aarch64_hash_table (info
);
9629 dynobj
= htab
->root
.dynobj
;
9630 sdyn
= bfd_get_linker_section (dynobj
, ".dynamic");
9632 if (htab
->root
.dynamic_sections_created
)
9634 ElfNN_External_Dyn
*dyncon
, *dynconend
;
9636 if (sdyn
== NULL
|| htab
->root
.sgot
== NULL
)
9639 dyncon
= (ElfNN_External_Dyn
*) sdyn
->contents
;
9640 dynconend
= (ElfNN_External_Dyn
*) (sdyn
->contents
+ sdyn
->size
);
9641 for (; dyncon
< dynconend
; dyncon
++)
9643 Elf_Internal_Dyn dyn
;
9646 bfd_elfNN_swap_dyn_in (dynobj
, dyncon
, &dyn
);
9654 s
= htab
->root
.sgotplt
;
9655 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
9659 s
= htab
->root
.srelplt
;
9660 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
9664 s
= htab
->root
.srelplt
;
9665 dyn
.d_un
.d_val
= s
->size
;
9668 case DT_TLSDESC_PLT
:
9669 s
= htab
->root
.splt
;
9670 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
9671 + htab
->tlsdesc_plt
;
9674 case DT_TLSDESC_GOT
:
9675 s
= htab
->root
.sgot
;
9676 BFD_ASSERT (htab
->dt_tlsdesc_got
!= (bfd_vma
)-1);
9677 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
9678 + htab
->dt_tlsdesc_got
;
9682 bfd_elfNN_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
9687 /* Fill in the special first entry in the procedure linkage table. */
9688 if (htab
->root
.splt
&& htab
->root
.splt
->size
> 0)
9690 elfNN_aarch64_init_small_plt0_entry (output_bfd
, htab
);
9692 elf_section_data (htab
->root
.splt
->output_section
)->
9693 this_hdr
.sh_entsize
= htab
->plt_entry_size
;
9696 if (htab
->tlsdesc_plt
&& !(info
->flags
& DF_BIND_NOW
))
9698 BFD_ASSERT (htab
->dt_tlsdesc_got
!= (bfd_vma
)-1);
9699 bfd_put_NN (output_bfd
, (bfd_vma
) 0,
9700 htab
->root
.sgot
->contents
+ htab
->dt_tlsdesc_got
);
9702 const bfd_byte
*entry
= elfNN_aarch64_tlsdesc_small_plt_entry
;
9703 htab
->tlsdesc_plt_entry_size
= PLT_TLSDESC_ENTRY_SIZE
;
9705 aarch64_plt_type type
= elf_aarch64_tdata (output_bfd
)->plt_type
;
9706 if (type
== PLT_BTI
|| type
== PLT_BTI_PAC
)
9708 entry
= elfNN_aarch64_tlsdesc_small_plt_bti_entry
;
9711 memcpy (htab
->root
.splt
->contents
+ htab
->tlsdesc_plt
,
9712 entry
, htab
->tlsdesc_plt_entry_size
);
9715 bfd_vma adrp1_addr
=
9716 htab
->root
.splt
->output_section
->vma
9717 + htab
->root
.splt
->output_offset
+ htab
->tlsdesc_plt
+ 4;
9719 bfd_vma adrp2_addr
= adrp1_addr
+ 4;
9722 htab
->root
.sgot
->output_section
->vma
9723 + htab
->root
.sgot
->output_offset
;
9725 bfd_vma pltgot_addr
=
9726 htab
->root
.sgotplt
->output_section
->vma
9727 + htab
->root
.sgotplt
->output_offset
;
9729 bfd_vma dt_tlsdesc_got
= got_addr
+ htab
->dt_tlsdesc_got
;
9731 bfd_byte
*plt_entry
=
9732 htab
->root
.splt
->contents
+ htab
->tlsdesc_plt
;
9734 /* First instruction in BTI enabled PLT stub is a BTI
9735 instruction so skip it. */
9738 plt_entry
= plt_entry
+ 4;
9739 adrp1_addr
= adrp1_addr
+ 4;
9740 adrp2_addr
= adrp2_addr
+ 4;
9743 /* adrp x2, DT_TLSDESC_GOT */
9744 elf_aarch64_update_plt_entry (output_bfd
,
9745 BFD_RELOC_AARCH64_ADR_HI21_PCREL
,
9747 (PG (dt_tlsdesc_got
)
9748 - PG (adrp1_addr
)));
9751 elf_aarch64_update_plt_entry (output_bfd
,
9752 BFD_RELOC_AARCH64_ADR_HI21_PCREL
,
9755 - PG (adrp2_addr
)));
9757 /* ldr x2, [x2, #0] */
9758 elf_aarch64_update_plt_entry (output_bfd
,
9759 BFD_RELOC_AARCH64_LDSTNN_LO12
,
9761 PG_OFFSET (dt_tlsdesc_got
));
9764 elf_aarch64_update_plt_entry (output_bfd
,
9765 BFD_RELOC_AARCH64_ADD_LO12
,
9767 PG_OFFSET (pltgot_addr
));
9772 if (htab
->root
.sgotplt
)
9774 if (bfd_is_abs_section (htab
->root
.sgotplt
->output_section
))
9777 (_("discarded output section: `%pA'"), htab
->root
.sgotplt
);
9781 /* Fill in the first three entries in the global offset table. */
9782 if (htab
->root
.sgotplt
->size
> 0)
9784 bfd_put_NN (output_bfd
, (bfd_vma
) 0, htab
->root
.sgotplt
->contents
);
9786 /* Write GOT[1] and GOT[2], needed for the dynamic linker. */
9787 bfd_put_NN (output_bfd
,
9789 htab
->root
.sgotplt
->contents
+ GOT_ENTRY_SIZE
);
9790 bfd_put_NN (output_bfd
,
9792 htab
->root
.sgotplt
->contents
+ GOT_ENTRY_SIZE
* 2);
9795 if (htab
->root
.sgot
)
9797 if (htab
->root
.sgot
->size
> 0)
9800 sdyn
? sdyn
->output_section
->vma
+ sdyn
->output_offset
: 0;
9801 bfd_put_NN (output_bfd
, addr
, htab
->root
.sgot
->contents
);
9805 elf_section_data (htab
->root
.sgotplt
->output_section
)->
9806 this_hdr
.sh_entsize
= GOT_ENTRY_SIZE
;
9809 if (htab
->root
.sgot
&& htab
->root
.sgot
->size
> 0)
9810 elf_section_data (htab
->root
.sgot
->output_section
)->this_hdr
.sh_entsize
9813 /* Fill PLT and GOT entries for local STT_GNU_IFUNC symbols. */
9814 htab_traverse (htab
->loc_hash_table
,
9815 elfNN_aarch64_finish_local_dynamic_symbol
,
9821 /* Check if BTI enabled PLTs are needed. Returns the type needed. */
9822 static aarch64_plt_type
9823 get_plt_type (bfd
*abfd
)
9825 aarch64_plt_type ret
= PLT_NORMAL
;
9826 bfd_byte
*contents
, *extdyn
, *extdynend
;
9827 asection
*sec
= bfd_get_section_by_name (abfd
, ".dynamic");
9828 if (!sec
|| !bfd_malloc_and_get_section (abfd
, sec
, &contents
))
9831 extdynend
= contents
+ sec
->size
;
9832 for (; extdyn
< extdynend
; extdyn
+= sizeof (ElfNN_External_Dyn
))
9834 Elf_Internal_Dyn dyn
;
9835 bfd_elfNN_swap_dyn_in (abfd
, extdyn
, &dyn
);
9837 /* Let's check the processor specific dynamic array tags. */
9838 bfd_vma tag
= dyn
.d_tag
;
9839 if (tag
< DT_LOPROC
|| tag
> DT_HIPROC
)
9844 case DT_AARCH64_BTI_PLT
:
9848 case DT_AARCH64_PAC_PLT
:
9860 elfNN_aarch64_get_synthetic_symtab (bfd
*abfd
,
9867 elf_aarch64_tdata (abfd
)->plt_type
= get_plt_type (abfd
);
9868 return _bfd_elf_get_synthetic_symtab (abfd
, symcount
, syms
,
9869 dynsymcount
, dynsyms
, ret
);
9872 /* Return address for Ith PLT stub in section PLT, for relocation REL
9873 or (bfd_vma) -1 if it should not be included. */
9876 elfNN_aarch64_plt_sym_val (bfd_vma i
, const asection
*plt
,
9877 const arelent
*rel ATTRIBUTE_UNUSED
)
9879 size_t plt0_size
= PLT_ENTRY_SIZE
;
9880 size_t pltn_size
= PLT_SMALL_ENTRY_SIZE
;
9882 if (elf_aarch64_tdata (plt
->owner
)->plt_type
== PLT_BTI_PAC
)
9884 if (elf_elfheader (plt
->owner
)->e_type
== ET_EXEC
)
9885 pltn_size
= PLT_BTI_PAC_SMALL_ENTRY_SIZE
;
9887 pltn_size
= PLT_PAC_SMALL_ENTRY_SIZE
;
9889 else if (elf_aarch64_tdata (plt
->owner
)->plt_type
== PLT_BTI
)
9891 if (elf_elfheader (plt
->owner
)->e_type
== ET_EXEC
)
9892 pltn_size
= PLT_BTI_SMALL_ENTRY_SIZE
;
9894 else if (elf_aarch64_tdata (plt
->owner
)->plt_type
== PLT_PAC
)
9896 pltn_size
= PLT_PAC_SMALL_ENTRY_SIZE
;
9899 return plt
->vma
+ plt0_size
+ i
* pltn_size
;
9902 /* Returns TRUE if NAME is an AArch64 mapping symbol.
9903 The ARM ELF standard defines $x (for A64 code) and $d (for data).
9904 It also allows a period initiated suffix to be added to the symbol, ie:
9905 "$[adtx]\.[:sym_char]+". */
9908 is_aarch64_mapping_symbol (const char * name
)
9910 return name
!= NULL
/* Paranoia. */
9911 && name
[0] == '$' /* Note: if objcopy --prefix-symbols has been used then
9912 the mapping symbols could have acquired a prefix.
9913 We do not support this here, since such symbols no
9914 longer conform to the ARM ELF ABI. */
9915 && (name
[1] == 'd' || name
[1] == 'x')
9916 && (name
[2] == 0 || name
[2] == '.');
9917 /* FIXME: Strictly speaking the symbol is only a valid mapping symbol if
9918 any characters that follow the period are legal characters for the body
9919 of a symbol's name. For now we just assume that this is the case. */
9922 /* Make sure that mapping symbols in object files are not removed via the
9923 "strip --strip-unneeded" tool. These symbols might needed in order to
9924 correctly generate linked files. Once an object file has been linked,
9925 it should be safe to remove them. */
9928 elfNN_aarch64_backend_symbol_processing (bfd
*abfd
, asymbol
*sym
)
9930 if (((abfd
->flags
& (EXEC_P
| DYNAMIC
)) == 0)
9931 && sym
->section
!= bfd_abs_section_ptr
9932 && is_aarch64_mapping_symbol (sym
->name
))
9933 sym
->flags
|= BSF_KEEP
;
9936 /* Implement elf_backend_setup_gnu_properties for AArch64. It serves as a
9937 wrapper function for _bfd_aarch64_elf_link_setup_gnu_properties to account
9938 for the effect of GNU properties of the output_bfd. */
9940 elfNN_aarch64_link_setup_gnu_properties (struct bfd_link_info
*info
)
9942 uint32_t prop
= elf_aarch64_tdata (info
->output_bfd
)->gnu_and_prop
;
9943 bfd
*pbfd
= _bfd_aarch64_elf_link_setup_gnu_properties (info
, &prop
);
9944 elf_aarch64_tdata (info
->output_bfd
)->gnu_and_prop
= prop
;
9945 elf_aarch64_tdata (info
->output_bfd
)->plt_type
9946 |= (prop
& GNU_PROPERTY_AARCH64_FEATURE_1_BTI
) ? PLT_BTI
: 0;
9947 setup_plt_values (info
, elf_aarch64_tdata (info
->output_bfd
)->plt_type
);
9951 /* Implement elf_backend_merge_gnu_properties for AArch64. It serves as a
9952 wrapper function for _bfd_aarch64_elf_merge_gnu_properties to account
9953 for the effect of GNU properties of the output_bfd. */
9955 elfNN_aarch64_merge_gnu_properties (struct bfd_link_info
*info
,
9956 bfd
*abfd
, bfd
*bbfd
,
9957 elf_property
*aprop
,
9958 elf_property
*bprop
)
9961 = elf_aarch64_tdata (info
->output_bfd
)->gnu_and_prop
;
9963 /* If output has been marked with BTI using command line argument, give out
9964 warning if necessary. */
9965 /* Properties are merged per type, hence only check for warnings when merging
9966 GNU_PROPERTY_AARCH64_FEATURE_1_AND. */
9967 if (((aprop
&& aprop
->pr_type
== GNU_PROPERTY_AARCH64_FEATURE_1_AND
)
9968 || (bprop
&& bprop
->pr_type
== GNU_PROPERTY_AARCH64_FEATURE_1_AND
))
9969 && (prop
& GNU_PROPERTY_AARCH64_FEATURE_1_BTI
)
9970 && (!elf_aarch64_tdata (info
->output_bfd
)->no_bti_warn
))
9972 if ((aprop
&& !(aprop
->u
.number
& GNU_PROPERTY_AARCH64_FEATURE_1_BTI
))
9975 _bfd_error_handler (_("%pB: warning: BTI turned on by --force-bti when "
9976 "all inputs do not have BTI in NOTE section."),
9979 if ((bprop
&& !(bprop
->u
.number
& GNU_PROPERTY_AARCH64_FEATURE_1_BTI
))
9982 _bfd_error_handler (_("%pB: warning: BTI turned on by --force-bti when "
9983 "all inputs do not have BTI in NOTE section."),
9988 return _bfd_aarch64_elf_merge_gnu_properties (info
, abfd
, aprop
,
9992 /* We use this so we can override certain functions
9993 (though currently we don't). */
9995 const struct elf_size_info elfNN_aarch64_size_info
=
9997 sizeof (ElfNN_External_Ehdr
),
9998 sizeof (ElfNN_External_Phdr
),
9999 sizeof (ElfNN_External_Shdr
),
10000 sizeof (ElfNN_External_Rel
),
10001 sizeof (ElfNN_External_Rela
),
10002 sizeof (ElfNN_External_Sym
),
10003 sizeof (ElfNN_External_Dyn
),
10004 sizeof (Elf_External_Note
),
10005 4, /* Hash table entry size. */
10006 1, /* Internal relocs per external relocs. */
10007 ARCH_SIZE
, /* Arch size. */
10008 LOG_FILE_ALIGN
, /* Log_file_align. */
10009 ELFCLASSNN
, EV_CURRENT
,
10010 bfd_elfNN_write_out_phdrs
,
10011 bfd_elfNN_write_shdrs_and_ehdr
,
10012 bfd_elfNN_checksum_contents
,
10013 bfd_elfNN_write_relocs
,
10014 bfd_elfNN_swap_symbol_in
,
10015 bfd_elfNN_swap_symbol_out
,
10016 bfd_elfNN_slurp_reloc_table
,
10017 bfd_elfNN_slurp_symbol_table
,
10018 bfd_elfNN_swap_dyn_in
,
10019 bfd_elfNN_swap_dyn_out
,
10020 bfd_elfNN_swap_reloc_in
,
10021 bfd_elfNN_swap_reloc_out
,
10022 bfd_elfNN_swap_reloca_in
,
10023 bfd_elfNN_swap_reloca_out
10026 #define ELF_ARCH bfd_arch_aarch64
10027 #define ELF_MACHINE_CODE EM_AARCH64
10028 #define ELF_MAXPAGESIZE 0x10000
10029 #define ELF_MINPAGESIZE 0x1000
10030 #define ELF_COMMONPAGESIZE 0x1000
10032 #define bfd_elfNN_close_and_cleanup \
10033 elfNN_aarch64_close_and_cleanup
10035 #define bfd_elfNN_bfd_free_cached_info \
10036 elfNN_aarch64_bfd_free_cached_info
10038 #define bfd_elfNN_bfd_is_target_special_symbol \
10039 elfNN_aarch64_is_target_special_symbol
10041 #define bfd_elfNN_bfd_link_hash_table_create \
10042 elfNN_aarch64_link_hash_table_create
10044 #define bfd_elfNN_bfd_merge_private_bfd_data \
10045 elfNN_aarch64_merge_private_bfd_data
10047 #define bfd_elfNN_bfd_print_private_bfd_data \
10048 elfNN_aarch64_print_private_bfd_data
10050 #define bfd_elfNN_bfd_reloc_type_lookup \
10051 elfNN_aarch64_reloc_type_lookup
10053 #define bfd_elfNN_bfd_reloc_name_lookup \
10054 elfNN_aarch64_reloc_name_lookup
10056 #define bfd_elfNN_bfd_set_private_flags \
10057 elfNN_aarch64_set_private_flags
10059 #define bfd_elfNN_find_inliner_info \
10060 elfNN_aarch64_find_inliner_info
10062 #define bfd_elfNN_find_nearest_line \
10063 elfNN_aarch64_find_nearest_line
10065 #define bfd_elfNN_get_synthetic_symtab \
10066 elfNN_aarch64_get_synthetic_symtab
10068 #define bfd_elfNN_mkobject \
10069 elfNN_aarch64_mkobject
10071 #define bfd_elfNN_new_section_hook \
10072 elfNN_aarch64_new_section_hook
10074 #define elf_backend_adjust_dynamic_symbol \
10075 elfNN_aarch64_adjust_dynamic_symbol
10077 #define elf_backend_always_size_sections \
10078 elfNN_aarch64_always_size_sections
10080 #define elf_backend_check_relocs \
10081 elfNN_aarch64_check_relocs
10083 #define elf_backend_copy_indirect_symbol \
10084 elfNN_aarch64_copy_indirect_symbol
10086 /* Create .dynbss, and .rela.bss sections in DYNOBJ, and set up shortcuts
10087 to them in our hash. */
10088 #define elf_backend_create_dynamic_sections \
10089 elfNN_aarch64_create_dynamic_sections
10091 #define elf_backend_init_index_section \
10092 _bfd_elf_init_2_index_sections
10094 #define elf_backend_finish_dynamic_sections \
10095 elfNN_aarch64_finish_dynamic_sections
10097 #define elf_backend_finish_dynamic_symbol \
10098 elfNN_aarch64_finish_dynamic_symbol
10100 #define elf_backend_object_p \
10101 elfNN_aarch64_object_p
10103 #define elf_backend_output_arch_local_syms \
10104 elfNN_aarch64_output_arch_local_syms
10106 #define elf_backend_plt_sym_val \
10107 elfNN_aarch64_plt_sym_val
10109 #define elf_backend_post_process_headers \
10110 elfNN_aarch64_post_process_headers
10112 #define elf_backend_relocate_section \
10113 elfNN_aarch64_relocate_section
10115 #define elf_backend_reloc_type_class \
10116 elfNN_aarch64_reloc_type_class
10118 #define elf_backend_section_from_shdr \
10119 elfNN_aarch64_section_from_shdr
10121 #define elf_backend_size_dynamic_sections \
10122 elfNN_aarch64_size_dynamic_sections
10124 #define elf_backend_size_info \
10125 elfNN_aarch64_size_info
10127 #define elf_backend_write_section \
10128 elfNN_aarch64_write_section
10130 #define elf_backend_symbol_processing \
10131 elfNN_aarch64_backend_symbol_processing
10133 #define elf_backend_setup_gnu_properties \
10134 elfNN_aarch64_link_setup_gnu_properties
10136 #define elf_backend_merge_gnu_properties \
10137 elfNN_aarch64_merge_gnu_properties
10139 #define elf_backend_can_refcount 1
10140 #define elf_backend_can_gc_sections 1
10141 #define elf_backend_plt_readonly 1
10142 #define elf_backend_want_got_plt 1
10143 #define elf_backend_want_plt_sym 0
10144 #define elf_backend_want_dynrelro 1
10145 #define elf_backend_may_use_rel_p 0
10146 #define elf_backend_may_use_rela_p 1
10147 #define elf_backend_default_use_rela_p 1
10148 #define elf_backend_rela_normal 1
10149 #define elf_backend_dtrel_excludes_plt 1
10150 #define elf_backend_got_header_size (GOT_ENTRY_SIZE * 3)
10151 #define elf_backend_default_execstack 0
10152 #define elf_backend_extern_protected_data 1
10153 #define elf_backend_hash_symbol elf_aarch64_hash_symbol
10155 #undef elf_backend_obj_attrs_section
10156 #define elf_backend_obj_attrs_section ".ARM.attributes"
10158 #include "elfNN-target.h"
10160 /* CloudABI support. */
10162 #undef TARGET_LITTLE_SYM
10163 #define TARGET_LITTLE_SYM aarch64_elfNN_le_cloudabi_vec
10164 #undef TARGET_LITTLE_NAME
10165 #define TARGET_LITTLE_NAME "elfNN-littleaarch64-cloudabi"
10166 #undef TARGET_BIG_SYM
10167 #define TARGET_BIG_SYM aarch64_elfNN_be_cloudabi_vec
10168 #undef TARGET_BIG_NAME
10169 #define TARGET_BIG_NAME "elfNN-bigaarch64-cloudabi"
10172 #define ELF_OSABI ELFOSABI_CLOUDABI
10175 #define elfNN_bed elfNN_aarch64_cloudabi_bed
10177 #include "elfNN-target.h"