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