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