/src/binutils-gdb/bfd/elf64-aarch64.c
Line | Count | Source (jump to first uncovered line) |
1 | | #line 1 "elfnn-aarch64.c" |
2 | | /* AArch64-specific support for 64-bit ELF. |
3 | | Copyright (C) 2009-2023 Free Software Foundation, Inc. |
4 | | Contributed by ARM Ltd. |
5 | | |
6 | | This file is part of BFD, the Binary File Descriptor library. |
7 | | |
8 | | This program is free software; you can redistribute it and/or modify |
9 | | it under the terms of the GNU General Public License as published by |
10 | | the Free Software Foundation; either version 3 of the License, or |
11 | | (at your option) any later version. |
12 | | |
13 | | This program is distributed in the hope that it will be useful, |
14 | | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | | GNU General Public License for more details. |
17 | | |
18 | | You should have received a copy of the GNU General Public License |
19 | | along with this program; see the file COPYING3. If not, |
20 | | see <http://www.gnu.org/licenses/>. */ |
21 | | |
22 | | /* Notes on implementation: |
23 | | |
24 | | Thread Local Store (TLS) |
25 | | |
26 | | Overview: |
27 | | |
28 | | The implementation currently supports both traditional TLS and TLS |
29 | | descriptors, but only general dynamic (GD). |
30 | | |
31 | | For traditional TLS the assembler will present us with code |
32 | | fragments of the form: |
33 | | |
34 | | adrp x0, :tlsgd:foo |
35 | | R_AARCH64_TLSGD_ADR_PAGE21(foo) |
36 | | add x0, :tlsgd_lo12:foo |
37 | | R_AARCH64_TLSGD_ADD_LO12_NC(foo) |
38 | | bl __tls_get_addr |
39 | | nop |
40 | | |
41 | | For TLS descriptors the assembler will present us with code |
42 | | fragments of the form: |
43 | | |
44 | | adrp x0, :tlsdesc:foo R_AARCH64_TLSDESC_ADR_PAGE21(foo) |
45 | | ldr x1, [x0, #:tlsdesc_lo12:foo] R_AARCH64_TLSDESC_LD64_LO12(foo) |
46 | | add x0, x0, #:tlsdesc_lo12:foo R_AARCH64_TLSDESC_ADD_LO12(foo) |
47 | | .tlsdesccall foo |
48 | | blr x1 R_AARCH64_TLSDESC_CALL(foo) |
49 | | |
50 | | The relocations R_AARCH64_TLSGD_{ADR_PREL21,ADD_LO12_NC} against foo |
51 | | indicate that foo is thread local and should be accessed via the |
52 | | traditional TLS mechanims. |
53 | | |
54 | | The relocations R_AARCH64_TLSDESC_{ADR_PAGE21,LD64_LO12_NC,ADD_LO12_NC} |
55 | | against foo indicate that 'foo' is thread local and should be accessed |
56 | | via a TLS descriptor mechanism. |
57 | | |
58 | | The precise instruction sequence is only relevant from the |
59 | | perspective of linker relaxation which is currently not implemented. |
60 | | |
61 | | The static linker must detect that 'foo' is a TLS object and |
62 | | allocate a double GOT entry. The GOT entry must be created for both |
63 | | global and local TLS symbols. Note that this is different to none |
64 | | TLS local objects which do not need a GOT entry. |
65 | | |
66 | | In the traditional TLS mechanism, the double GOT entry is used to |
67 | | provide the tls_index structure, containing module and offset |
68 | | entries. The static linker places the relocation R_AARCH64_TLS_DTPMOD |
69 | | on the module entry. The loader will subsequently fixup this |
70 | | relocation with the module identity. |
71 | | |
72 | | For global traditional TLS symbols the static linker places an |
73 | | R_AARCH64_TLS_DTPREL relocation on the offset entry. The loader |
74 | | will subsequently fixup the offset. For local TLS symbols the static |
75 | | linker fixes up offset. |
76 | | |
77 | | In the TLS descriptor mechanism the double GOT entry is used to |
78 | | provide the descriptor. The static linker places the relocation |
79 | | R_AARCH64_TLSDESC on the first GOT slot. The loader will |
80 | | subsequently fix this up. |
81 | | |
82 | | Implementation: |
83 | | |
84 | | The handling of TLS symbols is implemented across a number of |
85 | | different backend functions. The following is a top level view of |
86 | | what processing is performed where. |
87 | | |
88 | | The TLS implementation maintains state information for each TLS |
89 | | symbol. The state information for local and global symbols is kept |
90 | | in different places. Global symbols use generic BFD structures while |
91 | | local symbols use backend specific structures that are allocated and |
92 | | maintained entirely by the backend. |
93 | | |
94 | | The flow: |
95 | | |
96 | | elf64_aarch64_check_relocs() |
97 | | |
98 | | This function is invoked for each relocation. |
99 | | |
100 | | The TLS relocations R_AARCH64_TLSGD_{ADR_PREL21,ADD_LO12_NC} and |
101 | | R_AARCH64_TLSDESC_{ADR_PAGE21,LD64_LO12_NC,ADD_LO12_NC} are |
102 | | spotted. One time creation of local symbol data structures are |
103 | | created when the first local symbol is seen. |
104 | | |
105 | | The reference count for a symbol is incremented. The GOT type for |
106 | | each symbol is marked as general dynamic. |
107 | | |
108 | | elf64_aarch64_allocate_dynrelocs () |
109 | | |
110 | | For each global with positive reference count we allocate a double |
111 | | GOT slot. For a traditional TLS symbol we allocate space for two |
112 | | relocation entries on the GOT, for a TLS descriptor symbol we |
113 | | allocate space for one relocation on the slot. Record the GOT offset |
114 | | for this symbol. |
115 | | |
116 | | elf64_aarch64_size_dynamic_sections () |
117 | | |
118 | | Iterate all input BFDS, look for in the local symbol data structure |
119 | | constructed earlier for local TLS symbols and allocate them double |
120 | | GOT slots along with space for a single GOT relocation. Update the |
121 | | local symbol structure to record the GOT offset allocated. |
122 | | |
123 | | elf64_aarch64_relocate_section () |
124 | | |
125 | | Calls elf64_aarch64_final_link_relocate () |
126 | | |
127 | | Emit the relevant TLS relocations against the GOT for each TLS |
128 | | symbol. For local TLS symbols emit the GOT offset directly. The GOT |
129 | | relocations are emitted once the first time a TLS symbol is |
130 | | encountered. The implementation uses the LSB of the GOT offset to |
131 | | flag that the relevant GOT relocations for a symbol have been |
132 | | emitted. All of the TLS code that uses the GOT offset needs to take |
133 | | care to mask out this flag bit before using the offset. |
134 | | |
135 | | elf64_aarch64_final_link_relocate () |
136 | | |
137 | | Fixup the R_AARCH64_TLSGD_{ADR_PREL21, ADD_LO12_NC} relocations. */ |
138 | | |
139 | | #include "sysdep.h" |
140 | | #include "bfd.h" |
141 | | #include "libiberty.h" |
142 | | #include "libbfd.h" |
143 | | #include "elf-bfd.h" |
144 | | #include "bfdlink.h" |
145 | | #include "objalloc.h" |
146 | | #include "elf/aarch64.h" |
147 | | #include "elfxx-aarch64.h" |
148 | | #include "cpu-aarch64.h" |
149 | | |
150 | 0 | #define ARCH_SIZE 64 |
151 | | |
152 | | #if ARCH_SIZE == 64 |
153 | 0 | #define AARCH64_R(NAME) R_AARCH64_ ## NAME |
154 | | #define AARCH64_R_STR(NAME) "R_AARCH64_" #NAME |
155 | | #define HOWTO64(...) HOWTO (__VA_ARGS__) |
156 | | #define HOWTO32(...) EMPTY_HOWTO (0) |
157 | 0 | #define LOG_FILE_ALIGN 3 |
158 | 0 | #define BFD_RELOC_AARCH64_TLSDESC_LD64_LO12_NC BFD_RELOC_AARCH64_TLSDESC_LD64_LO12 |
159 | | #endif |
160 | | |
161 | | #if ARCH_SIZE == 32 |
162 | | #define AARCH64_R(NAME) R_AARCH64_P32_ ## NAME |
163 | | #define AARCH64_R_STR(NAME) "R_AARCH64_P32_" #NAME |
164 | | #define HOWTO64(...) EMPTY_HOWTO (0) |
165 | | #define HOWTO32(...) HOWTO (__VA_ARGS__) |
166 | | #define LOG_FILE_ALIGN 2 |
167 | | #define BFD_RELOC_AARCH64_TLSDESC_LD32_LO12 BFD_RELOC_AARCH64_TLSDESC_LD32_LO12_NC |
168 | | #define R_AARCH64_P32_TLSDESC_ADD_LO12 R_AARCH64_P32_TLSDESC_ADD_LO12_NC |
169 | | #endif |
170 | | |
171 | | #define IS_AARCH64_TLS_RELOC(R_TYPE) \ |
172 | 0 | ((R_TYPE) == BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC \ |
173 | 0 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21 \ |
174 | 0 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSGD_ADR_PREL21 \ |
175 | 0 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSGD_MOVW_G0_NC \ |
176 | 0 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSGD_MOVW_G1 \ |
177 | 0 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21 \ |
178 | 0 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSIE_LD32_GOTTPREL_LO12_NC \ |
179 | 0 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC \ |
180 | 0 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19 \ |
181 | 0 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G0_NC \ |
182 | 0 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G1 \ |
183 | 0 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_ADD_DTPREL_HI12 \ |
184 | 0 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_ADD_DTPREL_LO12 \ |
185 | 0 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_ADD_DTPREL_LO12_NC \ |
186 | 0 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC \ |
187 | 0 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21 \ |
188 | 0 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_ADR_PREL21 \ |
189 | 0 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_LDST16_DTPREL_LO12 \ |
190 | 0 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_LDST16_DTPREL_LO12_NC \ |
191 | 0 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_LDST32_DTPREL_LO12 \ |
192 | 0 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_LDST32_DTPREL_LO12_NC \ |
193 | 0 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_LDST64_DTPREL_LO12 \ |
194 | 0 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_LDST64_DTPREL_LO12_NC \ |
195 | 0 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_LDST8_DTPREL_LO12 \ |
196 | 0 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_LDST8_DTPREL_LO12_NC \ |
197 | 0 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G0 \ |
198 | 0 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G0_NC \ |
199 | 0 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G1 \ |
200 | 0 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G1_NC \ |
201 | 0 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G2 \ |
202 | 0 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_HI12 \ |
203 | 0 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_LO12 \ |
204 | 0 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_LO12_NC \ |
205 | 0 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_LDST16_TPREL_LO12 \ |
206 | 0 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_LDST16_TPREL_LO12_NC \ |
207 | 0 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_LDST32_TPREL_LO12 \ |
208 | 0 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_LDST32_TPREL_LO12_NC \ |
209 | 0 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_LDST64_TPREL_LO12 \ |
210 | 0 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_LDST64_TPREL_LO12_NC \ |
211 | 0 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_LDST8_TPREL_LO12 \ |
212 | 0 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_LDST8_TPREL_LO12_NC \ |
213 | 0 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0 \ |
214 | 0 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC \ |
215 | 0 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1 \ |
216 | 0 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1_NC \ |
217 | 0 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G2 \ |
218 | 0 | || (R_TYPE) == BFD_RELOC_AARCH64_TLS_DTPMOD \ |
219 | 0 | || (R_TYPE) == BFD_RELOC_AARCH64_TLS_DTPREL \ |
220 | 0 | || (R_TYPE) == BFD_RELOC_AARCH64_TLS_TPREL \ |
221 | 0 | || IS_AARCH64_TLSDESC_RELOC ((R_TYPE))) |
222 | | |
223 | | #define IS_AARCH64_TLS_RELAX_RELOC(R_TYPE) \ |
224 | 0 | ((R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_ADD \ |
225 | 0 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_ADD_LO12 \ |
226 | 0 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21 \ |
227 | 0 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21 \ |
228 | 0 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_CALL \ |
229 | 0 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_LD_PREL19 \ |
230 | 0 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_LD64_LO12_NC \ |
231 | 0 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_LDR \ |
232 | 0 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_OFF_G0_NC \ |
233 | 0 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_OFF_G1 \ |
234 | 0 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_LDR \ |
235 | 0 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21 \ |
236 | 0 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSGD_ADR_PREL21 \ |
237 | 0 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC \ |
238 | 0 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSGD_MOVW_G0_NC \ |
239 | 0 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSGD_MOVW_G1 \ |
240 | 0 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21 \ |
241 | 0 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19 \ |
242 | 0 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC \ |
243 | 0 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC \ |
244 | 0 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21 \ |
245 | 0 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_ADR_PREL21) |
246 | | |
247 | | #define IS_AARCH64_TLSDESC_RELOC(R_TYPE) \ |
248 | 0 | ((R_TYPE) == BFD_RELOC_AARCH64_TLSDESC \ |
249 | 0 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_ADD \ |
250 | 0 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_ADD_LO12 \ |
251 | 0 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21 \ |
252 | 0 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21 \ |
253 | 0 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_CALL \ |
254 | 0 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_LD32_LO12_NC \ |
255 | 0 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_LD64_LO12 \ |
256 | 0 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_LDR \ |
257 | 0 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_LD_PREL19 \ |
258 | 0 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_OFF_G0_NC \ |
259 | 0 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_OFF_G1) |
260 | | |
261 | 0 | #define ELIMINATE_COPY_RELOCS 1 |
262 | | |
263 | | /* Return size of a relocation entry. HTAB is the bfd's |
264 | | elf_aarch64_link_hash_entry. */ |
265 | 0 | #define RELOC_SIZE(HTAB) (sizeof (Elf64_External_Rela)) |
266 | | |
267 | | /* GOT Entry size - 8 bytes in ELF64 and 4 bytes in ELF32. */ |
268 | 0 | #define GOT_ENTRY_SIZE (ARCH_SIZE / 8) |
269 | 0 | #define PLT_ENTRY_SIZE (32) |
270 | 0 | #define PLT_SMALL_ENTRY_SIZE (16) |
271 | 0 | #define PLT_TLSDESC_ENTRY_SIZE (32) |
272 | | /* PLT sizes with BTI insn. */ |
273 | 0 | #define PLT_BTI_SMALL_ENTRY_SIZE (24) |
274 | | /* PLT sizes with PAC insn. */ |
275 | 0 | #define PLT_PAC_SMALL_ENTRY_SIZE (24) |
276 | | /* PLT sizes with BTI and PAC insn. */ |
277 | 0 | #define PLT_BTI_PAC_SMALL_ENTRY_SIZE (24) |
278 | | |
279 | | /* Encoding of the nop instruction. */ |
280 | 0 | #define INSN_NOP 0xd503201f |
281 | | |
282 | | #define aarch64_compute_jump_table_size(htab) \ |
283 | 0 | (((htab)->root.srelplt == NULL) ? 0 \ |
284 | 0 | : (htab)->root.srelplt->reloc_count * GOT_ENTRY_SIZE) |
285 | | |
286 | | /* The first entry in a procedure linkage table looks like this |
287 | | if the distance between the PLTGOT and the PLT is < 4GB use |
288 | | these PLT entries. Note that the dynamic linker gets &PLTGOT[2] |
289 | | in x16 and needs to work out PLTGOT[1] by using an address of |
290 | | [x16,#-GOT_ENTRY_SIZE]. */ |
291 | | static const bfd_byte elf64_aarch64_small_plt0_entry[PLT_ENTRY_SIZE] = |
292 | | { |
293 | | 0xf0, 0x7b, 0xbf, 0xa9, /* stp x16, x30, [sp, #-16]! */ |
294 | | 0x10, 0x00, 0x00, 0x90, /* adrp x16, (GOT+16) */ |
295 | | #if ARCH_SIZE == 64 |
296 | | 0x11, 0x0A, 0x40, 0xf9, /* ldr x17, [x16, #PLT_GOT+0x10] */ |
297 | | 0x10, 0x42, 0x00, 0x91, /* add x16, x16,#PLT_GOT+0x10 */ |
298 | | #else |
299 | | 0x11, 0x0A, 0x40, 0xb9, /* ldr w17, [x16, #PLT_GOT+0x8] */ |
300 | | 0x10, 0x22, 0x00, 0x11, /* add w16, w16,#PLT_GOT+0x8 */ |
301 | | #endif |
302 | | 0x20, 0x02, 0x1f, 0xd6, /* br x17 */ |
303 | | 0x1f, 0x20, 0x03, 0xd5, /* nop */ |
304 | | 0x1f, 0x20, 0x03, 0xd5, /* nop */ |
305 | | 0x1f, 0x20, 0x03, 0xd5, /* nop */ |
306 | | }; |
307 | | |
308 | | static const bfd_byte elf64_aarch64_small_plt0_bti_entry[PLT_ENTRY_SIZE] = |
309 | | { |
310 | | 0x5f, 0x24, 0x03, 0xd5, /* bti c. */ |
311 | | 0xf0, 0x7b, 0xbf, 0xa9, /* stp x16, x30, [sp, #-16]! */ |
312 | | 0x10, 0x00, 0x00, 0x90, /* adrp x16, (GOT+16) */ |
313 | | #if ARCH_SIZE == 64 |
314 | | 0x11, 0x0A, 0x40, 0xf9, /* ldr x17, [x16, #PLT_GOT+0x10] */ |
315 | | 0x10, 0x42, 0x00, 0x91, /* add x16, x16,#PLT_GOT+0x10 */ |
316 | | #else |
317 | | 0x11, 0x0A, 0x40, 0xb9, /* ldr w17, [x16, #PLT_GOT+0x8] */ |
318 | | 0x10, 0x22, 0x00, 0x11, /* add w16, w16,#PLT_GOT+0x8 */ |
319 | | #endif |
320 | | 0x20, 0x02, 0x1f, 0xd6, /* br x17 */ |
321 | | 0x1f, 0x20, 0x03, 0xd5, /* nop */ |
322 | | 0x1f, 0x20, 0x03, 0xd5, /* nop */ |
323 | | }; |
324 | | |
325 | | /* Per function entry in a procedure linkage table looks like this |
326 | | if the distance between the PLTGOT and the PLT is < 4GB use |
327 | | these PLT entries. Use BTI versions of the PLTs when enabled. */ |
328 | | static const bfd_byte elf64_aarch64_small_plt_entry[PLT_SMALL_ENTRY_SIZE] = |
329 | | { |
330 | | 0x10, 0x00, 0x00, 0x90, /* adrp x16, PLTGOT + n * 8 */ |
331 | | #if ARCH_SIZE == 64 |
332 | | 0x11, 0x02, 0x40, 0xf9, /* ldr x17, [x16, PLTGOT + n * 8] */ |
333 | | 0x10, 0x02, 0x00, 0x91, /* add x16, x16, :lo12:PLTGOT + n * 8 */ |
334 | | #else |
335 | | 0x11, 0x02, 0x40, 0xb9, /* ldr w17, [x16, PLTGOT + n * 4] */ |
336 | | 0x10, 0x02, 0x00, 0x11, /* add w16, w16, :lo12:PLTGOT + n * 4 */ |
337 | | #endif |
338 | | 0x20, 0x02, 0x1f, 0xd6, /* br x17. */ |
339 | | }; |
340 | | |
341 | | static const bfd_byte |
342 | | elf64_aarch64_small_plt_bti_entry[PLT_BTI_SMALL_ENTRY_SIZE] = |
343 | | { |
344 | | 0x5f, 0x24, 0x03, 0xd5, /* bti c. */ |
345 | | 0x10, 0x00, 0x00, 0x90, /* adrp x16, PLTGOT + n * 8 */ |
346 | | #if ARCH_SIZE == 64 |
347 | | 0x11, 0x02, 0x40, 0xf9, /* ldr x17, [x16, PLTGOT + n * 8] */ |
348 | | 0x10, 0x02, 0x00, 0x91, /* add x16, x16, :lo12:PLTGOT + n * 8 */ |
349 | | #else |
350 | | 0x11, 0x02, 0x40, 0xb9, /* ldr w17, [x16, PLTGOT + n * 4] */ |
351 | | 0x10, 0x02, 0x00, 0x11, /* add w16, w16, :lo12:PLTGOT + n * 4 */ |
352 | | #endif |
353 | | 0x20, 0x02, 0x1f, 0xd6, /* br x17. */ |
354 | | 0x1f, 0x20, 0x03, 0xd5, /* nop */ |
355 | | }; |
356 | | |
357 | | static const bfd_byte |
358 | | elf64_aarch64_small_plt_pac_entry[PLT_PAC_SMALL_ENTRY_SIZE] = |
359 | | { |
360 | | 0x10, 0x00, 0x00, 0x90, /* adrp x16, PLTGOT + n * 8 */ |
361 | | #if ARCH_SIZE == 64 |
362 | | 0x11, 0x02, 0x40, 0xf9, /* ldr x17, [x16, PLTGOT + n * 8] */ |
363 | | 0x10, 0x02, 0x00, 0x91, /* add x16, x16, :lo12:PLTGOT + n * 8 */ |
364 | | #else |
365 | | 0x11, 0x02, 0x40, 0xb9, /* ldr w17, [x16, PLTGOT + n * 4] */ |
366 | | 0x10, 0x02, 0x00, 0x11, /* add w16, w16, :lo12:PLTGOT + n * 4 */ |
367 | | #endif |
368 | | 0x9f, 0x21, 0x03, 0xd5, /* autia1716 */ |
369 | | 0x20, 0x02, 0x1f, 0xd6, /* br x17. */ |
370 | | 0x1f, 0x20, 0x03, 0xd5, /* nop */ |
371 | | }; |
372 | | |
373 | | static const bfd_byte |
374 | | elf64_aarch64_small_plt_bti_pac_entry[PLT_BTI_PAC_SMALL_ENTRY_SIZE] = |
375 | | { |
376 | | 0x5f, 0x24, 0x03, 0xd5, /* bti c. */ |
377 | | 0x10, 0x00, 0x00, 0x90, /* adrp x16, PLTGOT + n * 8 */ |
378 | | #if ARCH_SIZE == 64 |
379 | | 0x11, 0x02, 0x40, 0xf9, /* ldr x17, [x16, PLTGOT + n * 8] */ |
380 | | 0x10, 0x02, 0x00, 0x91, /* add x16, x16, :lo12:PLTGOT + n * 8 */ |
381 | | #else |
382 | | 0x11, 0x02, 0x40, 0xb9, /* ldr w17, [x16, PLTGOT + n * 4] */ |
383 | | 0x10, 0x02, 0x00, 0x11, /* add w16, w16, :lo12:PLTGOT + n * 4 */ |
384 | | #endif |
385 | | 0x9f, 0x21, 0x03, 0xd5, /* autia1716 */ |
386 | | 0x20, 0x02, 0x1f, 0xd6, /* br x17. */ |
387 | | }; |
388 | | |
389 | | static const bfd_byte |
390 | | elf64_aarch64_tlsdesc_small_plt_entry[PLT_TLSDESC_ENTRY_SIZE] = |
391 | | { |
392 | | 0xe2, 0x0f, 0xbf, 0xa9, /* stp x2, x3, [sp, #-16]! */ |
393 | | 0x02, 0x00, 0x00, 0x90, /* adrp x2, 0 */ |
394 | | 0x03, 0x00, 0x00, 0x90, /* adrp x3, 0 */ |
395 | | #if ARCH_SIZE == 64 |
396 | | 0x42, 0x00, 0x40, 0xf9, /* ldr x2, [x2, #0] */ |
397 | | 0x63, 0x00, 0x00, 0x91, /* add x3, x3, 0 */ |
398 | | #else |
399 | | 0x42, 0x00, 0x40, 0xb9, /* ldr w2, [x2, #0] */ |
400 | | 0x63, 0x00, 0x00, 0x11, /* add w3, w3, 0 */ |
401 | | #endif |
402 | | 0x40, 0x00, 0x1f, 0xd6, /* br x2 */ |
403 | | 0x1f, 0x20, 0x03, 0xd5, /* nop */ |
404 | | 0x1f, 0x20, 0x03, 0xd5, /* nop */ |
405 | | }; |
406 | | |
407 | | static const bfd_byte |
408 | | elf64_aarch64_tlsdesc_small_plt_bti_entry[PLT_TLSDESC_ENTRY_SIZE] = |
409 | | { |
410 | | 0x5f, 0x24, 0x03, 0xd5, /* bti c. */ |
411 | | 0xe2, 0x0f, 0xbf, 0xa9, /* stp x2, x3, [sp, #-16]! */ |
412 | | 0x02, 0x00, 0x00, 0x90, /* adrp x2, 0 */ |
413 | | 0x03, 0x00, 0x00, 0x90, /* adrp x3, 0 */ |
414 | | #if ARCH_SIZE == 64 |
415 | | 0x42, 0x00, 0x40, 0xf9, /* ldr x2, [x2, #0] */ |
416 | | 0x63, 0x00, 0x00, 0x91, /* add x3, x3, 0 */ |
417 | | #else |
418 | | 0x42, 0x00, 0x40, 0xb9, /* ldr w2, [x2, #0] */ |
419 | | 0x63, 0x00, 0x00, 0x11, /* add w3, w3, 0 */ |
420 | | #endif |
421 | | 0x40, 0x00, 0x1f, 0xd6, /* br x2 */ |
422 | | 0x1f, 0x20, 0x03, 0xd5, /* nop */ |
423 | | }; |
424 | | |
425 | | #define elf_info_to_howto elf64_aarch64_info_to_howto |
426 | | #define elf_info_to_howto_rel elf64_aarch64_info_to_howto |
427 | | |
428 | 0 | #define AARCH64_ELF_ABI_VERSION 0 |
429 | | |
430 | | /* In case we're on a 32-bit machine, construct a 64-bit "-1" value. */ |
431 | | #define ALL_ONES (~ (bfd_vma) 0) |
432 | | |
433 | | /* Indexed by the bfd interal reloc enumerators. |
434 | | Therefore, the table needs to be synced with BFD_RELOC_AARCH64_* |
435 | | in reloc.c. */ |
436 | | |
437 | | static reloc_howto_type elf64_aarch64_howto_table[] = |
438 | | { |
439 | | EMPTY_HOWTO (0), |
440 | | |
441 | | /* Basic data relocations. */ |
442 | | |
443 | | /* Deprecated, but retained for backwards compatibility. */ |
444 | | HOWTO64 (R_AARCH64_NULL, /* type */ |
445 | | 0, /* rightshift */ |
446 | | 0, /* size */ |
447 | | 0, /* bitsize */ |
448 | | false, /* pc_relative */ |
449 | | 0, /* bitpos */ |
450 | | complain_overflow_dont, /* complain_on_overflow */ |
451 | | bfd_elf_generic_reloc, /* special_function */ |
452 | | "R_AARCH64_NULL", /* name */ |
453 | | false, /* partial_inplace */ |
454 | | 0, /* src_mask */ |
455 | | 0, /* dst_mask */ |
456 | | false), /* pcrel_offset */ |
457 | | HOWTO (R_AARCH64_NONE, /* type */ |
458 | | 0, /* rightshift */ |
459 | | 0, /* size */ |
460 | | 0, /* bitsize */ |
461 | | false, /* pc_relative */ |
462 | | 0, /* bitpos */ |
463 | | complain_overflow_dont, /* complain_on_overflow */ |
464 | | bfd_elf_generic_reloc, /* special_function */ |
465 | | "R_AARCH64_NONE", /* name */ |
466 | | false, /* partial_inplace */ |
467 | | 0, /* src_mask */ |
468 | | 0, /* dst_mask */ |
469 | | false), /* pcrel_offset */ |
470 | | |
471 | | /* .xword: (S+A) */ |
472 | | HOWTO64 (AARCH64_R (ABS64), /* type */ |
473 | | 0, /* rightshift */ |
474 | | 8, /* size */ |
475 | | 64, /* bitsize */ |
476 | | false, /* pc_relative */ |
477 | | 0, /* bitpos */ |
478 | | complain_overflow_unsigned, /* complain_on_overflow */ |
479 | | bfd_elf_generic_reloc, /* special_function */ |
480 | | AARCH64_R_STR (ABS64), /* name */ |
481 | | false, /* partial_inplace */ |
482 | | 0, /* src_mask */ |
483 | | ALL_ONES, /* dst_mask */ |
484 | | false), /* pcrel_offset */ |
485 | | |
486 | | /* .word: (S+A) */ |
487 | | HOWTO (AARCH64_R (ABS32), /* type */ |
488 | | 0, /* rightshift */ |
489 | | 4, /* size */ |
490 | | 32, /* bitsize */ |
491 | | false, /* pc_relative */ |
492 | | 0, /* bitpos */ |
493 | | complain_overflow_unsigned, /* complain_on_overflow */ |
494 | | bfd_elf_generic_reloc, /* special_function */ |
495 | | AARCH64_R_STR (ABS32), /* name */ |
496 | | false, /* partial_inplace */ |
497 | | 0, /* src_mask */ |
498 | | 0xffffffff, /* dst_mask */ |
499 | | false), /* pcrel_offset */ |
500 | | |
501 | | /* .half: (S+A) */ |
502 | | HOWTO (AARCH64_R (ABS16), /* type */ |
503 | | 0, /* rightshift */ |
504 | | 2, /* size */ |
505 | | 16, /* bitsize */ |
506 | | false, /* pc_relative */ |
507 | | 0, /* bitpos */ |
508 | | complain_overflow_unsigned, /* complain_on_overflow */ |
509 | | bfd_elf_generic_reloc, /* special_function */ |
510 | | AARCH64_R_STR (ABS16), /* name */ |
511 | | false, /* partial_inplace */ |
512 | | 0, /* src_mask */ |
513 | | 0xffff, /* dst_mask */ |
514 | | false), /* pcrel_offset */ |
515 | | |
516 | | /* .xword: (S+A-P) */ |
517 | | HOWTO64 (AARCH64_R (PREL64), /* type */ |
518 | | 0, /* rightshift */ |
519 | | 8, /* size */ |
520 | | 64, /* bitsize */ |
521 | | true, /* pc_relative */ |
522 | | 0, /* bitpos */ |
523 | | complain_overflow_signed, /* complain_on_overflow */ |
524 | | bfd_elf_generic_reloc, /* special_function */ |
525 | | AARCH64_R_STR (PREL64), /* name */ |
526 | | false, /* partial_inplace */ |
527 | | 0, /* src_mask */ |
528 | | ALL_ONES, /* dst_mask */ |
529 | | true), /* pcrel_offset */ |
530 | | |
531 | | /* .word: (S+A-P) */ |
532 | | HOWTO (AARCH64_R (PREL32), /* type */ |
533 | | 0, /* rightshift */ |
534 | | 4, /* size */ |
535 | | 32, /* bitsize */ |
536 | | true, /* pc_relative */ |
537 | | 0, /* bitpos */ |
538 | | complain_overflow_signed, /* complain_on_overflow */ |
539 | | bfd_elf_generic_reloc, /* special_function */ |
540 | | AARCH64_R_STR (PREL32), /* name */ |
541 | | false, /* partial_inplace */ |
542 | | 0, /* src_mask */ |
543 | | 0xffffffff, /* dst_mask */ |
544 | | true), /* pcrel_offset */ |
545 | | |
546 | | /* .half: (S+A-P) */ |
547 | | HOWTO (AARCH64_R (PREL16), /* type */ |
548 | | 0, /* rightshift */ |
549 | | 2, /* size */ |
550 | | 16, /* bitsize */ |
551 | | true, /* pc_relative */ |
552 | | 0, /* bitpos */ |
553 | | complain_overflow_signed, /* complain_on_overflow */ |
554 | | bfd_elf_generic_reloc, /* special_function */ |
555 | | AARCH64_R_STR (PREL16), /* name */ |
556 | | false, /* partial_inplace */ |
557 | | 0, /* src_mask */ |
558 | | 0xffff, /* dst_mask */ |
559 | | true), /* pcrel_offset */ |
560 | | |
561 | | /* Group relocations to create a 16, 32, 48 or 64 bit |
562 | | unsigned data or abs address inline. */ |
563 | | |
564 | | /* MOVZ: ((S+A) >> 0) & 0xffff */ |
565 | | HOWTO (AARCH64_R (MOVW_UABS_G0), /* type */ |
566 | | 0, /* rightshift */ |
567 | | 4, /* size */ |
568 | | 16, /* bitsize */ |
569 | | false, /* pc_relative */ |
570 | | 0, /* bitpos */ |
571 | | complain_overflow_unsigned, /* complain_on_overflow */ |
572 | | bfd_elf_generic_reloc, /* special_function */ |
573 | | AARCH64_R_STR (MOVW_UABS_G0), /* name */ |
574 | | false, /* partial_inplace */ |
575 | | 0, /* src_mask */ |
576 | | 0xffff, /* dst_mask */ |
577 | | false), /* pcrel_offset */ |
578 | | |
579 | | /* MOVK: ((S+A) >> 0) & 0xffff [no overflow check] */ |
580 | | HOWTO (AARCH64_R (MOVW_UABS_G0_NC), /* type */ |
581 | | 0, /* rightshift */ |
582 | | 4, /* size */ |
583 | | 16, /* bitsize */ |
584 | | false, /* pc_relative */ |
585 | | 0, /* bitpos */ |
586 | | complain_overflow_dont, /* complain_on_overflow */ |
587 | | bfd_elf_generic_reloc, /* special_function */ |
588 | | AARCH64_R_STR (MOVW_UABS_G0_NC), /* name */ |
589 | | false, /* partial_inplace */ |
590 | | 0, /* src_mask */ |
591 | | 0xffff, /* dst_mask */ |
592 | | false), /* pcrel_offset */ |
593 | | |
594 | | /* MOVZ: ((S+A) >> 16) & 0xffff */ |
595 | | HOWTO (AARCH64_R (MOVW_UABS_G1), /* type */ |
596 | | 16, /* rightshift */ |
597 | | 4, /* size */ |
598 | | 16, /* bitsize */ |
599 | | false, /* pc_relative */ |
600 | | 0, /* bitpos */ |
601 | | complain_overflow_unsigned, /* complain_on_overflow */ |
602 | | bfd_elf_generic_reloc, /* special_function */ |
603 | | AARCH64_R_STR (MOVW_UABS_G1), /* name */ |
604 | | false, /* partial_inplace */ |
605 | | 0, /* src_mask */ |
606 | | 0xffff, /* dst_mask */ |
607 | | false), /* pcrel_offset */ |
608 | | |
609 | | /* MOVK: ((S+A) >> 16) & 0xffff [no overflow check] */ |
610 | | HOWTO64 (AARCH64_R (MOVW_UABS_G1_NC), /* type */ |
611 | | 16, /* rightshift */ |
612 | | 4, /* size */ |
613 | | 16, /* bitsize */ |
614 | | false, /* pc_relative */ |
615 | | 0, /* bitpos */ |
616 | | complain_overflow_dont, /* complain_on_overflow */ |
617 | | bfd_elf_generic_reloc, /* special_function */ |
618 | | AARCH64_R_STR (MOVW_UABS_G1_NC), /* name */ |
619 | | false, /* partial_inplace */ |
620 | | 0, /* src_mask */ |
621 | | 0xffff, /* dst_mask */ |
622 | | false), /* pcrel_offset */ |
623 | | |
624 | | /* MOVZ: ((S+A) >> 32) & 0xffff */ |
625 | | HOWTO64 (AARCH64_R (MOVW_UABS_G2), /* type */ |
626 | | 32, /* rightshift */ |
627 | | 4, /* size */ |
628 | | 16, /* bitsize */ |
629 | | false, /* pc_relative */ |
630 | | 0, /* bitpos */ |
631 | | complain_overflow_unsigned, /* complain_on_overflow */ |
632 | | bfd_elf_generic_reloc, /* special_function */ |
633 | | AARCH64_R_STR (MOVW_UABS_G2), /* name */ |
634 | | false, /* partial_inplace */ |
635 | | 0, /* src_mask */ |
636 | | 0xffff, /* dst_mask */ |
637 | | false), /* pcrel_offset */ |
638 | | |
639 | | /* MOVK: ((S+A) >> 32) & 0xffff [no overflow check] */ |
640 | | HOWTO64 (AARCH64_R (MOVW_UABS_G2_NC), /* type */ |
641 | | 32, /* rightshift */ |
642 | | 4, /* size */ |
643 | | 16, /* bitsize */ |
644 | | false, /* pc_relative */ |
645 | | 0, /* bitpos */ |
646 | | complain_overflow_dont, /* complain_on_overflow */ |
647 | | bfd_elf_generic_reloc, /* special_function */ |
648 | | AARCH64_R_STR (MOVW_UABS_G2_NC), /* name */ |
649 | | false, /* partial_inplace */ |
650 | | 0, /* src_mask */ |
651 | | 0xffff, /* dst_mask */ |
652 | | false), /* pcrel_offset */ |
653 | | |
654 | | /* MOVZ: ((S+A) >> 48) & 0xffff */ |
655 | | HOWTO64 (AARCH64_R (MOVW_UABS_G3), /* type */ |
656 | | 48, /* rightshift */ |
657 | | 4, /* size */ |
658 | | 16, /* bitsize */ |
659 | | false, /* pc_relative */ |
660 | | 0, /* bitpos */ |
661 | | complain_overflow_unsigned, /* complain_on_overflow */ |
662 | | bfd_elf_generic_reloc, /* special_function */ |
663 | | AARCH64_R_STR (MOVW_UABS_G3), /* name */ |
664 | | false, /* partial_inplace */ |
665 | | 0, /* src_mask */ |
666 | | 0xffff, /* dst_mask */ |
667 | | false), /* pcrel_offset */ |
668 | | |
669 | | /* Group relocations to create high part of a 16, 32, 48 or 64 bit |
670 | | signed data or abs address inline. Will change instruction |
671 | | to MOVN or MOVZ depending on sign of calculated value. */ |
672 | | |
673 | | /* MOV[ZN]: ((S+A) >> 0) & 0xffff */ |
674 | | HOWTO (AARCH64_R (MOVW_SABS_G0), /* type */ |
675 | | 0, /* rightshift */ |
676 | | 4, /* size */ |
677 | | 17, /* bitsize */ |
678 | | false, /* pc_relative */ |
679 | | 0, /* bitpos */ |
680 | | complain_overflow_signed, /* complain_on_overflow */ |
681 | | bfd_elf_generic_reloc, /* special_function */ |
682 | | AARCH64_R_STR (MOVW_SABS_G0), /* name */ |
683 | | false, /* partial_inplace */ |
684 | | 0, /* src_mask */ |
685 | | 0xffff, /* dst_mask */ |
686 | | false), /* pcrel_offset */ |
687 | | |
688 | | /* MOV[ZN]: ((S+A) >> 16) & 0xffff */ |
689 | | HOWTO64 (AARCH64_R (MOVW_SABS_G1), /* type */ |
690 | | 16, /* rightshift */ |
691 | | 4, /* size */ |
692 | | 17, /* bitsize */ |
693 | | false, /* pc_relative */ |
694 | | 0, /* bitpos */ |
695 | | complain_overflow_signed, /* complain_on_overflow */ |
696 | | bfd_elf_generic_reloc, /* special_function */ |
697 | | AARCH64_R_STR (MOVW_SABS_G1), /* name */ |
698 | | false, /* partial_inplace */ |
699 | | 0, /* src_mask */ |
700 | | 0xffff, /* dst_mask */ |
701 | | false), /* pcrel_offset */ |
702 | | |
703 | | /* MOV[ZN]: ((S+A) >> 32) & 0xffff */ |
704 | | HOWTO64 (AARCH64_R (MOVW_SABS_G2), /* type */ |
705 | | 32, /* rightshift */ |
706 | | 4, /* size */ |
707 | | 17, /* bitsize */ |
708 | | false, /* pc_relative */ |
709 | | 0, /* bitpos */ |
710 | | complain_overflow_signed, /* complain_on_overflow */ |
711 | | bfd_elf_generic_reloc, /* special_function */ |
712 | | AARCH64_R_STR (MOVW_SABS_G2), /* name */ |
713 | | false, /* partial_inplace */ |
714 | | 0, /* src_mask */ |
715 | | 0xffff, /* dst_mask */ |
716 | | false), /* pcrel_offset */ |
717 | | |
718 | | /* Group relocations to create a 16, 32, 48 or 64 bit |
719 | | PC relative address inline. */ |
720 | | |
721 | | /* MOV[NZ]: ((S+A-P) >> 0) & 0xffff */ |
722 | | HOWTO (AARCH64_R (MOVW_PREL_G0), /* type */ |
723 | | 0, /* rightshift */ |
724 | | 4, /* size */ |
725 | | 17, /* bitsize */ |
726 | | true, /* pc_relative */ |
727 | | 0, /* bitpos */ |
728 | | complain_overflow_signed, /* complain_on_overflow */ |
729 | | bfd_elf_generic_reloc, /* special_function */ |
730 | | AARCH64_R_STR (MOVW_PREL_G0), /* name */ |
731 | | false, /* partial_inplace */ |
732 | | 0, /* src_mask */ |
733 | | 0xffff, /* dst_mask */ |
734 | | true), /* pcrel_offset */ |
735 | | |
736 | | /* MOVK: ((S+A-P) >> 0) & 0xffff [no overflow check] */ |
737 | | HOWTO (AARCH64_R (MOVW_PREL_G0_NC), /* type */ |
738 | | 0, /* rightshift */ |
739 | | 4, /* size */ |
740 | | 16, /* bitsize */ |
741 | | true, /* pc_relative */ |
742 | | 0, /* bitpos */ |
743 | | complain_overflow_dont, /* complain_on_overflow */ |
744 | | bfd_elf_generic_reloc, /* special_function */ |
745 | | AARCH64_R_STR (MOVW_PREL_G0_NC), /* name */ |
746 | | false, /* partial_inplace */ |
747 | | 0, /* src_mask */ |
748 | | 0xffff, /* dst_mask */ |
749 | | true), /* pcrel_offset */ |
750 | | |
751 | | /* MOV[NZ]: ((S+A-P) >> 16) & 0xffff */ |
752 | | HOWTO (AARCH64_R (MOVW_PREL_G1), /* type */ |
753 | | 16, /* rightshift */ |
754 | | 4, /* size */ |
755 | | 17, /* bitsize */ |
756 | | true, /* pc_relative */ |
757 | | 0, /* bitpos */ |
758 | | complain_overflow_signed, /* complain_on_overflow */ |
759 | | bfd_elf_generic_reloc, /* special_function */ |
760 | | AARCH64_R_STR (MOVW_PREL_G1), /* name */ |
761 | | false, /* partial_inplace */ |
762 | | 0, /* src_mask */ |
763 | | 0xffff, /* dst_mask */ |
764 | | true), /* pcrel_offset */ |
765 | | |
766 | | /* MOVK: ((S+A-P) >> 16) & 0xffff [no overflow check] */ |
767 | | HOWTO64 (AARCH64_R (MOVW_PREL_G1_NC), /* type */ |
768 | | 16, /* rightshift */ |
769 | | 4, /* size */ |
770 | | 16, /* bitsize */ |
771 | | true, /* pc_relative */ |
772 | | 0, /* bitpos */ |
773 | | complain_overflow_dont, /* complain_on_overflow */ |
774 | | bfd_elf_generic_reloc, /* special_function */ |
775 | | AARCH64_R_STR (MOVW_PREL_G1_NC), /* name */ |
776 | | false, /* partial_inplace */ |
777 | | 0, /* src_mask */ |
778 | | 0xffff, /* dst_mask */ |
779 | | true), /* pcrel_offset */ |
780 | | |
781 | | /* MOV[NZ]: ((S+A-P) >> 32) & 0xffff */ |
782 | | HOWTO64 (AARCH64_R (MOVW_PREL_G2), /* type */ |
783 | | 32, /* rightshift */ |
784 | | 4, /* size */ |
785 | | 17, /* bitsize */ |
786 | | true, /* pc_relative */ |
787 | | 0, /* bitpos */ |
788 | | complain_overflow_signed, /* complain_on_overflow */ |
789 | | bfd_elf_generic_reloc, /* special_function */ |
790 | | AARCH64_R_STR (MOVW_PREL_G2), /* name */ |
791 | | false, /* partial_inplace */ |
792 | | 0, /* src_mask */ |
793 | | 0xffff, /* dst_mask */ |
794 | | true), /* pcrel_offset */ |
795 | | |
796 | | /* MOVK: ((S+A-P) >> 32) & 0xffff [no overflow check] */ |
797 | | HOWTO64 (AARCH64_R (MOVW_PREL_G2_NC), /* type */ |
798 | | 32, /* rightshift */ |
799 | | 4, /* size */ |
800 | | 16, /* bitsize */ |
801 | | true, /* pc_relative */ |
802 | | 0, /* bitpos */ |
803 | | complain_overflow_dont, /* complain_on_overflow */ |
804 | | bfd_elf_generic_reloc, /* special_function */ |
805 | | AARCH64_R_STR (MOVW_PREL_G2_NC), /* name */ |
806 | | false, /* partial_inplace */ |
807 | | 0, /* src_mask */ |
808 | | 0xffff, /* dst_mask */ |
809 | | true), /* pcrel_offset */ |
810 | | |
811 | | /* MOV[NZ]: ((S+A-P) >> 48) & 0xffff */ |
812 | | HOWTO64 (AARCH64_R (MOVW_PREL_G3), /* type */ |
813 | | 48, /* rightshift */ |
814 | | 4, /* size */ |
815 | | 16, /* bitsize */ |
816 | | true, /* pc_relative */ |
817 | | 0, /* bitpos */ |
818 | | complain_overflow_dont, /* complain_on_overflow */ |
819 | | bfd_elf_generic_reloc, /* special_function */ |
820 | | AARCH64_R_STR (MOVW_PREL_G3), /* name */ |
821 | | false, /* partial_inplace */ |
822 | | 0, /* src_mask */ |
823 | | 0xffff, /* dst_mask */ |
824 | | true), /* pcrel_offset */ |
825 | | |
826 | | /* Relocations to generate 19, 21 and 33 bit PC-relative load/store |
827 | | addresses: PG(x) is (x & ~0xfff). */ |
828 | | |
829 | | /* LD-lit: ((S+A-P) >> 2) & 0x7ffff */ |
830 | | HOWTO (AARCH64_R (LD_PREL_LO19), /* type */ |
831 | | 2, /* rightshift */ |
832 | | 4, /* size */ |
833 | | 19, /* bitsize */ |
834 | | true, /* pc_relative */ |
835 | | 0, /* bitpos */ |
836 | | complain_overflow_signed, /* complain_on_overflow */ |
837 | | bfd_elf_generic_reloc, /* special_function */ |
838 | | AARCH64_R_STR (LD_PREL_LO19), /* name */ |
839 | | false, /* partial_inplace */ |
840 | | 0, /* src_mask */ |
841 | | 0x7ffff, /* dst_mask */ |
842 | | true), /* pcrel_offset */ |
843 | | |
844 | | /* ADR: (S+A-P) & 0x1fffff */ |
845 | | HOWTO (AARCH64_R (ADR_PREL_LO21), /* type */ |
846 | | 0, /* rightshift */ |
847 | | 4, /* size */ |
848 | | 21, /* bitsize */ |
849 | | true, /* pc_relative */ |
850 | | 0, /* bitpos */ |
851 | | complain_overflow_signed, /* complain_on_overflow */ |
852 | | bfd_elf_generic_reloc, /* special_function */ |
853 | | AARCH64_R_STR (ADR_PREL_LO21), /* name */ |
854 | | false, /* partial_inplace */ |
855 | | 0, /* src_mask */ |
856 | | 0x1fffff, /* dst_mask */ |
857 | | true), /* pcrel_offset */ |
858 | | |
859 | | /* ADRP: ((PG(S+A)-PG(P)) >> 12) & 0x1fffff */ |
860 | | HOWTO (AARCH64_R (ADR_PREL_PG_HI21), /* type */ |
861 | | 12, /* rightshift */ |
862 | | 4, /* size */ |
863 | | 21, /* bitsize */ |
864 | | true, /* pc_relative */ |
865 | | 0, /* bitpos */ |
866 | | complain_overflow_signed, /* complain_on_overflow */ |
867 | | bfd_elf_generic_reloc, /* special_function */ |
868 | | AARCH64_R_STR (ADR_PREL_PG_HI21), /* name */ |
869 | | false, /* partial_inplace */ |
870 | | 0, /* src_mask */ |
871 | | 0x1fffff, /* dst_mask */ |
872 | | true), /* pcrel_offset */ |
873 | | |
874 | | /* ADRP: ((PG(S+A)-PG(P)) >> 12) & 0x1fffff [no overflow check] */ |
875 | | HOWTO64 (AARCH64_R (ADR_PREL_PG_HI21_NC), /* type */ |
876 | | 12, /* rightshift */ |
877 | | 4, /* size */ |
878 | | 21, /* bitsize */ |
879 | | true, /* pc_relative */ |
880 | | 0, /* bitpos */ |
881 | | complain_overflow_dont, /* complain_on_overflow */ |
882 | | bfd_elf_generic_reloc, /* special_function */ |
883 | | AARCH64_R_STR (ADR_PREL_PG_HI21_NC), /* name */ |
884 | | false, /* partial_inplace */ |
885 | | 0, /* src_mask */ |
886 | | 0x1fffff, /* dst_mask */ |
887 | | true), /* pcrel_offset */ |
888 | | |
889 | | /* ADD: (S+A) & 0xfff [no overflow check] */ |
890 | | HOWTO (AARCH64_R (ADD_ABS_LO12_NC), /* type */ |
891 | | 0, /* rightshift */ |
892 | | 4, /* size */ |
893 | | 12, /* bitsize */ |
894 | | false, /* pc_relative */ |
895 | | 10, /* bitpos */ |
896 | | complain_overflow_dont, /* complain_on_overflow */ |
897 | | bfd_elf_generic_reloc, /* special_function */ |
898 | | AARCH64_R_STR (ADD_ABS_LO12_NC), /* name */ |
899 | | false, /* partial_inplace */ |
900 | | 0, /* src_mask */ |
901 | | 0x3ffc00, /* dst_mask */ |
902 | | false), /* pcrel_offset */ |
903 | | |
904 | | /* LD/ST8: (S+A) & 0xfff */ |
905 | | HOWTO (AARCH64_R (LDST8_ABS_LO12_NC), /* type */ |
906 | | 0, /* rightshift */ |
907 | | 4, /* size */ |
908 | | 12, /* bitsize */ |
909 | | false, /* pc_relative */ |
910 | | 0, /* bitpos */ |
911 | | complain_overflow_dont, /* complain_on_overflow */ |
912 | | bfd_elf_generic_reloc, /* special_function */ |
913 | | AARCH64_R_STR (LDST8_ABS_LO12_NC), /* name */ |
914 | | false, /* partial_inplace */ |
915 | | 0, /* src_mask */ |
916 | | 0xfff, /* dst_mask */ |
917 | | false), /* pcrel_offset */ |
918 | | |
919 | | /* Relocations for control-flow instructions. */ |
920 | | |
921 | | /* TBZ/NZ: ((S+A-P) >> 2) & 0x3fff */ |
922 | | HOWTO (AARCH64_R (TSTBR14), /* type */ |
923 | | 2, /* rightshift */ |
924 | | 4, /* size */ |
925 | | 14, /* bitsize */ |
926 | | true, /* pc_relative */ |
927 | | 0, /* bitpos */ |
928 | | complain_overflow_signed, /* complain_on_overflow */ |
929 | | bfd_elf_generic_reloc, /* special_function */ |
930 | | AARCH64_R_STR (TSTBR14), /* name */ |
931 | | false, /* partial_inplace */ |
932 | | 0, /* src_mask */ |
933 | | 0x3fff, /* dst_mask */ |
934 | | true), /* pcrel_offset */ |
935 | | |
936 | | /* B.cond: ((S+A-P) >> 2) & 0x7ffff */ |
937 | | HOWTO (AARCH64_R (CONDBR19), /* type */ |
938 | | 2, /* rightshift */ |
939 | | 4, /* size */ |
940 | | 19, /* bitsize */ |
941 | | true, /* pc_relative */ |
942 | | 0, /* bitpos */ |
943 | | complain_overflow_signed, /* complain_on_overflow */ |
944 | | bfd_elf_generic_reloc, /* special_function */ |
945 | | AARCH64_R_STR (CONDBR19), /* name */ |
946 | | false, /* partial_inplace */ |
947 | | 0, /* src_mask */ |
948 | | 0x7ffff, /* dst_mask */ |
949 | | true), /* pcrel_offset */ |
950 | | |
951 | | /* B: ((S+A-P) >> 2) & 0x3ffffff */ |
952 | | HOWTO (AARCH64_R (JUMP26), /* type */ |
953 | | 2, /* rightshift */ |
954 | | 4, /* size */ |
955 | | 26, /* bitsize */ |
956 | | true, /* pc_relative */ |
957 | | 0, /* bitpos */ |
958 | | complain_overflow_signed, /* complain_on_overflow */ |
959 | | bfd_elf_generic_reloc, /* special_function */ |
960 | | AARCH64_R_STR (JUMP26), /* name */ |
961 | | false, /* partial_inplace */ |
962 | | 0, /* src_mask */ |
963 | | 0x3ffffff, /* dst_mask */ |
964 | | true), /* pcrel_offset */ |
965 | | |
966 | | /* BL: ((S+A-P) >> 2) & 0x3ffffff */ |
967 | | HOWTO (AARCH64_R (CALL26), /* type */ |
968 | | 2, /* rightshift */ |
969 | | 4, /* size */ |
970 | | 26, /* bitsize */ |
971 | | true, /* pc_relative */ |
972 | | 0, /* bitpos */ |
973 | | complain_overflow_signed, /* complain_on_overflow */ |
974 | | bfd_elf_generic_reloc, /* special_function */ |
975 | | AARCH64_R_STR (CALL26), /* name */ |
976 | | false, /* partial_inplace */ |
977 | | 0, /* src_mask */ |
978 | | 0x3ffffff, /* dst_mask */ |
979 | | true), /* pcrel_offset */ |
980 | | |
981 | | /* LD/ST16: (S+A) & 0xffe */ |
982 | | HOWTO (AARCH64_R (LDST16_ABS_LO12_NC), /* type */ |
983 | | 1, /* rightshift */ |
984 | | 4, /* size */ |
985 | | 12, /* bitsize */ |
986 | | false, /* pc_relative */ |
987 | | 0, /* bitpos */ |
988 | | complain_overflow_dont, /* complain_on_overflow */ |
989 | | bfd_elf_generic_reloc, /* special_function */ |
990 | | AARCH64_R_STR (LDST16_ABS_LO12_NC), /* name */ |
991 | | false, /* partial_inplace */ |
992 | | 0, /* src_mask */ |
993 | | 0xffe, /* dst_mask */ |
994 | | false), /* pcrel_offset */ |
995 | | |
996 | | /* LD/ST32: (S+A) & 0xffc */ |
997 | | HOWTO (AARCH64_R (LDST32_ABS_LO12_NC), /* type */ |
998 | | 2, /* rightshift */ |
999 | | 4, /* size */ |
1000 | | 12, /* bitsize */ |
1001 | | false, /* pc_relative */ |
1002 | | 0, /* bitpos */ |
1003 | | complain_overflow_dont, /* complain_on_overflow */ |
1004 | | bfd_elf_generic_reloc, /* special_function */ |
1005 | | AARCH64_R_STR (LDST32_ABS_LO12_NC), /* name */ |
1006 | | false, /* partial_inplace */ |
1007 | | 0, /* src_mask */ |
1008 | | 0xffc, /* dst_mask */ |
1009 | | false), /* pcrel_offset */ |
1010 | | |
1011 | | /* LD/ST64: (S+A) & 0xff8 */ |
1012 | | HOWTO (AARCH64_R (LDST64_ABS_LO12_NC), /* type */ |
1013 | | 3, /* rightshift */ |
1014 | | 4, /* size */ |
1015 | | 12, /* bitsize */ |
1016 | | false, /* pc_relative */ |
1017 | | 0, /* bitpos */ |
1018 | | complain_overflow_dont, /* complain_on_overflow */ |
1019 | | bfd_elf_generic_reloc, /* special_function */ |
1020 | | AARCH64_R_STR (LDST64_ABS_LO12_NC), /* name */ |
1021 | | false, /* partial_inplace */ |
1022 | | 0, /* src_mask */ |
1023 | | 0xff8, /* dst_mask */ |
1024 | | false), /* pcrel_offset */ |
1025 | | |
1026 | | /* LD/ST128: (S+A) & 0xff0 */ |
1027 | | HOWTO (AARCH64_R (LDST128_ABS_LO12_NC), /* type */ |
1028 | | 4, /* rightshift */ |
1029 | | 4, /* size */ |
1030 | | 12, /* bitsize */ |
1031 | | false, /* pc_relative */ |
1032 | | 0, /* bitpos */ |
1033 | | complain_overflow_dont, /* complain_on_overflow */ |
1034 | | bfd_elf_generic_reloc, /* special_function */ |
1035 | | AARCH64_R_STR (LDST128_ABS_LO12_NC), /* name */ |
1036 | | false, /* partial_inplace */ |
1037 | | 0, /* src_mask */ |
1038 | | 0xff0, /* dst_mask */ |
1039 | | false), /* pcrel_offset */ |
1040 | | |
1041 | | /* Set a load-literal immediate field to bits |
1042 | | 0x1FFFFC of G(S)-P */ |
1043 | | HOWTO (AARCH64_R (GOT_LD_PREL19), /* type */ |
1044 | | 2, /* rightshift */ |
1045 | | 4, /* size */ |
1046 | | 19, /* bitsize */ |
1047 | | true, /* pc_relative */ |
1048 | | 0, /* bitpos */ |
1049 | | complain_overflow_signed, /* complain_on_overflow */ |
1050 | | bfd_elf_generic_reloc, /* special_function */ |
1051 | | AARCH64_R_STR (GOT_LD_PREL19), /* name */ |
1052 | | false, /* partial_inplace */ |
1053 | | 0, /* src_mask */ |
1054 | | 0xffffe0, /* dst_mask */ |
1055 | | true), /* pcrel_offset */ |
1056 | | |
1057 | | /* Get to the page for the GOT entry for the symbol |
1058 | | (G(S) - P) using an ADRP instruction. */ |
1059 | | HOWTO (AARCH64_R (ADR_GOT_PAGE), /* type */ |
1060 | | 12, /* rightshift */ |
1061 | | 4, /* size */ |
1062 | | 21, /* bitsize */ |
1063 | | true, /* pc_relative */ |
1064 | | 0, /* bitpos */ |
1065 | | complain_overflow_dont, /* complain_on_overflow */ |
1066 | | bfd_elf_generic_reloc, /* special_function */ |
1067 | | AARCH64_R_STR (ADR_GOT_PAGE), /* name */ |
1068 | | false, /* partial_inplace */ |
1069 | | 0, /* src_mask */ |
1070 | | 0x1fffff, /* dst_mask */ |
1071 | | true), /* pcrel_offset */ |
1072 | | |
1073 | | /* LD64: GOT offset G(S) & 0xff8 */ |
1074 | | HOWTO64 (AARCH64_R (LD64_GOT_LO12_NC), /* type */ |
1075 | | 3, /* rightshift */ |
1076 | | 4, /* size */ |
1077 | | 12, /* bitsize */ |
1078 | | false, /* pc_relative */ |
1079 | | 0, /* bitpos */ |
1080 | | complain_overflow_dont, /* complain_on_overflow */ |
1081 | | bfd_elf_generic_reloc, /* special_function */ |
1082 | | AARCH64_R_STR (LD64_GOT_LO12_NC), /* name */ |
1083 | | false, /* partial_inplace */ |
1084 | | 0, /* src_mask */ |
1085 | | 0xff8, /* dst_mask */ |
1086 | | false), /* pcrel_offset */ |
1087 | | |
1088 | | /* LD32: GOT offset G(S) & 0xffc */ |
1089 | | HOWTO32 (AARCH64_R (LD32_GOT_LO12_NC), /* type */ |
1090 | | 2, /* rightshift */ |
1091 | | 4, /* size */ |
1092 | | 12, /* bitsize */ |
1093 | | false, /* pc_relative */ |
1094 | | 0, /* bitpos */ |
1095 | | complain_overflow_dont, /* complain_on_overflow */ |
1096 | | bfd_elf_generic_reloc, /* special_function */ |
1097 | | AARCH64_R_STR (LD32_GOT_LO12_NC), /* name */ |
1098 | | false, /* partial_inplace */ |
1099 | | 0, /* src_mask */ |
1100 | | 0xffc, /* dst_mask */ |
1101 | | false), /* pcrel_offset */ |
1102 | | |
1103 | | /* Lower 16 bits of GOT offset for the symbol. */ |
1104 | | HOWTO64 (AARCH64_R (MOVW_GOTOFF_G0_NC), /* type */ |
1105 | | 0, /* rightshift */ |
1106 | | 4, /* size */ |
1107 | | 16, /* bitsize */ |
1108 | | false, /* pc_relative */ |
1109 | | 0, /* bitpos */ |
1110 | | complain_overflow_dont, /* complain_on_overflow */ |
1111 | | bfd_elf_generic_reloc, /* special_function */ |
1112 | | AARCH64_R_STR (MOVW_GOTOFF_G0_NC), /* name */ |
1113 | | false, /* partial_inplace */ |
1114 | | 0, /* src_mask */ |
1115 | | 0xffff, /* dst_mask */ |
1116 | | false), /* pcrel_offset */ |
1117 | | |
1118 | | /* Higher 16 bits of GOT offset for the symbol. */ |
1119 | | HOWTO64 (AARCH64_R (MOVW_GOTOFF_G1), /* type */ |
1120 | | 16, /* rightshift */ |
1121 | | 4, /* size */ |
1122 | | 16, /* bitsize */ |
1123 | | false, /* pc_relative */ |
1124 | | 0, /* bitpos */ |
1125 | | complain_overflow_unsigned, /* complain_on_overflow */ |
1126 | | bfd_elf_generic_reloc, /* special_function */ |
1127 | | AARCH64_R_STR (MOVW_GOTOFF_G1), /* name */ |
1128 | | false, /* partial_inplace */ |
1129 | | 0, /* src_mask */ |
1130 | | 0xffff, /* dst_mask */ |
1131 | | false), /* pcrel_offset */ |
1132 | | |
1133 | | /* LD64: GOT offset for the symbol. */ |
1134 | | HOWTO64 (AARCH64_R (LD64_GOTOFF_LO15), /* type */ |
1135 | | 3, /* rightshift */ |
1136 | | 4, /* size */ |
1137 | | 12, /* bitsize */ |
1138 | | false, /* pc_relative */ |
1139 | | 0, /* bitpos */ |
1140 | | complain_overflow_unsigned, /* complain_on_overflow */ |
1141 | | bfd_elf_generic_reloc, /* special_function */ |
1142 | | AARCH64_R_STR (LD64_GOTOFF_LO15), /* name */ |
1143 | | false, /* partial_inplace */ |
1144 | | 0, /* src_mask */ |
1145 | | 0x7ff8, /* dst_mask */ |
1146 | | false), /* pcrel_offset */ |
1147 | | |
1148 | | /* LD32: GOT offset to the page address of GOT table. |
1149 | | (G(S) - PAGE (_GLOBAL_OFFSET_TABLE_)) & 0x5ffc. */ |
1150 | | HOWTO32 (AARCH64_R (LD32_GOTPAGE_LO14), /* type */ |
1151 | | 2, /* rightshift */ |
1152 | | 4, /* size */ |
1153 | | 12, /* bitsize */ |
1154 | | false, /* pc_relative */ |
1155 | | 0, /* bitpos */ |
1156 | | complain_overflow_unsigned, /* complain_on_overflow */ |
1157 | | bfd_elf_generic_reloc, /* special_function */ |
1158 | | AARCH64_R_STR (LD32_GOTPAGE_LO14), /* name */ |
1159 | | false, /* partial_inplace */ |
1160 | | 0, /* src_mask */ |
1161 | | 0x5ffc, /* dst_mask */ |
1162 | | false), /* pcrel_offset */ |
1163 | | |
1164 | | /* LD64: GOT offset to the page address of GOT table. |
1165 | | (G(S) - PAGE (_GLOBAL_OFFSET_TABLE_)) & 0x7ff8. */ |
1166 | | HOWTO64 (AARCH64_R (LD64_GOTPAGE_LO15), /* type */ |
1167 | | 3, /* rightshift */ |
1168 | | 4, /* size */ |
1169 | | 12, /* bitsize */ |
1170 | | false, /* pc_relative */ |
1171 | | 0, /* bitpos */ |
1172 | | complain_overflow_unsigned, /* complain_on_overflow */ |
1173 | | bfd_elf_generic_reloc, /* special_function */ |
1174 | | AARCH64_R_STR (LD64_GOTPAGE_LO15), /* name */ |
1175 | | false, /* partial_inplace */ |
1176 | | 0, /* src_mask */ |
1177 | | 0x7ff8, /* dst_mask */ |
1178 | | false), /* pcrel_offset */ |
1179 | | |
1180 | | /* Get to the page for the GOT entry for the symbol |
1181 | | (G(S) - P) using an ADRP instruction. */ |
1182 | | HOWTO (AARCH64_R (TLSGD_ADR_PAGE21), /* type */ |
1183 | | 12, /* rightshift */ |
1184 | | 4, /* size */ |
1185 | | 21, /* bitsize */ |
1186 | | true, /* pc_relative */ |
1187 | | 0, /* bitpos */ |
1188 | | complain_overflow_dont, /* complain_on_overflow */ |
1189 | | bfd_elf_generic_reloc, /* special_function */ |
1190 | | AARCH64_R_STR (TLSGD_ADR_PAGE21), /* name */ |
1191 | | false, /* partial_inplace */ |
1192 | | 0, /* src_mask */ |
1193 | | 0x1fffff, /* dst_mask */ |
1194 | | true), /* pcrel_offset */ |
1195 | | |
1196 | | HOWTO (AARCH64_R (TLSGD_ADR_PREL21), /* type */ |
1197 | | 0, /* rightshift */ |
1198 | | 4, /* size */ |
1199 | | 21, /* bitsize */ |
1200 | | true, /* pc_relative */ |
1201 | | 0, /* bitpos */ |
1202 | | complain_overflow_dont, /* complain_on_overflow */ |
1203 | | bfd_elf_generic_reloc, /* special_function */ |
1204 | | AARCH64_R_STR (TLSGD_ADR_PREL21), /* name */ |
1205 | | false, /* partial_inplace */ |
1206 | | 0, /* src_mask */ |
1207 | | 0x1fffff, /* dst_mask */ |
1208 | | true), /* pcrel_offset */ |
1209 | | |
1210 | | /* ADD: GOT offset G(S) & 0xff8 [no overflow check] */ |
1211 | | HOWTO (AARCH64_R (TLSGD_ADD_LO12_NC), /* type */ |
1212 | | 0, /* rightshift */ |
1213 | | 4, /* size */ |
1214 | | 12, /* bitsize */ |
1215 | | false, /* pc_relative */ |
1216 | | 0, /* bitpos */ |
1217 | | complain_overflow_dont, /* complain_on_overflow */ |
1218 | | bfd_elf_generic_reloc, /* special_function */ |
1219 | | AARCH64_R_STR (TLSGD_ADD_LO12_NC), /* name */ |
1220 | | false, /* partial_inplace */ |
1221 | | 0, /* src_mask */ |
1222 | | 0xfff, /* dst_mask */ |
1223 | | false), /* pcrel_offset */ |
1224 | | |
1225 | | /* Lower 16 bits of GOT offset to tls_index. */ |
1226 | | HOWTO64 (AARCH64_R (TLSGD_MOVW_G0_NC), /* type */ |
1227 | | 0, /* rightshift */ |
1228 | | 4, /* size */ |
1229 | | 16, /* bitsize */ |
1230 | | false, /* pc_relative */ |
1231 | | 0, /* bitpos */ |
1232 | | complain_overflow_dont, /* complain_on_overflow */ |
1233 | | bfd_elf_generic_reloc, /* special_function */ |
1234 | | AARCH64_R_STR (TLSGD_MOVW_G0_NC), /* name */ |
1235 | | false, /* partial_inplace */ |
1236 | | 0, /* src_mask */ |
1237 | | 0xffff, /* dst_mask */ |
1238 | | false), /* pcrel_offset */ |
1239 | | |
1240 | | /* Higher 16 bits of GOT offset to tls_index. */ |
1241 | | HOWTO64 (AARCH64_R (TLSGD_MOVW_G1), /* type */ |
1242 | | 16, /* rightshift */ |
1243 | | 4, /* size */ |
1244 | | 16, /* bitsize */ |
1245 | | false, /* pc_relative */ |
1246 | | 0, /* bitpos */ |
1247 | | complain_overflow_unsigned, /* complain_on_overflow */ |
1248 | | bfd_elf_generic_reloc, /* special_function */ |
1249 | | AARCH64_R_STR (TLSGD_MOVW_G1), /* name */ |
1250 | | false, /* partial_inplace */ |
1251 | | 0, /* src_mask */ |
1252 | | 0xffff, /* dst_mask */ |
1253 | | false), /* pcrel_offset */ |
1254 | | |
1255 | | HOWTO (AARCH64_R (TLSIE_ADR_GOTTPREL_PAGE21), /* type */ |
1256 | | 12, /* rightshift */ |
1257 | | 4, /* size */ |
1258 | | 21, /* bitsize */ |
1259 | | false, /* pc_relative */ |
1260 | | 0, /* bitpos */ |
1261 | | complain_overflow_dont, /* complain_on_overflow */ |
1262 | | bfd_elf_generic_reloc, /* special_function */ |
1263 | | AARCH64_R_STR (TLSIE_ADR_GOTTPREL_PAGE21), /* name */ |
1264 | | false, /* partial_inplace */ |
1265 | | 0, /* src_mask */ |
1266 | | 0x1fffff, /* dst_mask */ |
1267 | | false), /* pcrel_offset */ |
1268 | | |
1269 | | HOWTO64 (AARCH64_R (TLSIE_LD64_GOTTPREL_LO12_NC), /* type */ |
1270 | | 3, /* rightshift */ |
1271 | | 4, /* size */ |
1272 | | 12, /* bitsize */ |
1273 | | false, /* pc_relative */ |
1274 | | 0, /* bitpos */ |
1275 | | complain_overflow_dont, /* complain_on_overflow */ |
1276 | | bfd_elf_generic_reloc, /* special_function */ |
1277 | | AARCH64_R_STR (TLSIE_LD64_GOTTPREL_LO12_NC), /* name */ |
1278 | | false, /* partial_inplace */ |
1279 | | 0, /* src_mask */ |
1280 | | 0xff8, /* dst_mask */ |
1281 | | false), /* pcrel_offset */ |
1282 | | |
1283 | | HOWTO32 (AARCH64_R (TLSIE_LD32_GOTTPREL_LO12_NC), /* type */ |
1284 | | 2, /* rightshift */ |
1285 | | 4, /* size */ |
1286 | | 12, /* bitsize */ |
1287 | | false, /* pc_relative */ |
1288 | | 0, /* bitpos */ |
1289 | | complain_overflow_dont, /* complain_on_overflow */ |
1290 | | bfd_elf_generic_reloc, /* special_function */ |
1291 | | AARCH64_R_STR (TLSIE_LD32_GOTTPREL_LO12_NC), /* name */ |
1292 | | false, /* partial_inplace */ |
1293 | | 0, /* src_mask */ |
1294 | | 0xffc, /* dst_mask */ |
1295 | | false), /* pcrel_offset */ |
1296 | | |
1297 | | HOWTO (AARCH64_R (TLSIE_LD_GOTTPREL_PREL19), /* type */ |
1298 | | 2, /* rightshift */ |
1299 | | 4, /* size */ |
1300 | | 19, /* bitsize */ |
1301 | | false, /* pc_relative */ |
1302 | | 0, /* bitpos */ |
1303 | | complain_overflow_dont, /* complain_on_overflow */ |
1304 | | bfd_elf_generic_reloc, /* special_function */ |
1305 | | AARCH64_R_STR (TLSIE_LD_GOTTPREL_PREL19), /* name */ |
1306 | | false, /* partial_inplace */ |
1307 | | 0, /* src_mask */ |
1308 | | 0x1ffffc, /* dst_mask */ |
1309 | | false), /* pcrel_offset */ |
1310 | | |
1311 | | HOWTO64 (AARCH64_R (TLSIE_MOVW_GOTTPREL_G0_NC), /* type */ |
1312 | | 0, /* rightshift */ |
1313 | | 4, /* size */ |
1314 | | 16, /* bitsize */ |
1315 | | false, /* pc_relative */ |
1316 | | 0, /* bitpos */ |
1317 | | complain_overflow_dont, /* complain_on_overflow */ |
1318 | | bfd_elf_generic_reloc, /* special_function */ |
1319 | | AARCH64_R_STR (TLSIE_MOVW_GOTTPREL_G0_NC), /* name */ |
1320 | | false, /* partial_inplace */ |
1321 | | 0, /* src_mask */ |
1322 | | 0xffff, /* dst_mask */ |
1323 | | false), /* pcrel_offset */ |
1324 | | |
1325 | | HOWTO64 (AARCH64_R (TLSIE_MOVW_GOTTPREL_G1), /* type */ |
1326 | | 16, /* rightshift */ |
1327 | | 4, /* size */ |
1328 | | 16, /* bitsize */ |
1329 | | false, /* pc_relative */ |
1330 | | 0, /* bitpos */ |
1331 | | complain_overflow_unsigned, /* complain_on_overflow */ |
1332 | | bfd_elf_generic_reloc, /* special_function */ |
1333 | | AARCH64_R_STR (TLSIE_MOVW_GOTTPREL_G1), /* name */ |
1334 | | false, /* partial_inplace */ |
1335 | | 0, /* src_mask */ |
1336 | | 0xffff, /* dst_mask */ |
1337 | | false), /* pcrel_offset */ |
1338 | | |
1339 | | /* ADD: bit[23:12] of byte offset to module TLS base address. */ |
1340 | | HOWTO (AARCH64_R (TLSLD_ADD_DTPREL_HI12), /* type */ |
1341 | | 12, /* rightshift */ |
1342 | | 4, /* size */ |
1343 | | 12, /* bitsize */ |
1344 | | false, /* pc_relative */ |
1345 | | 0, /* bitpos */ |
1346 | | complain_overflow_unsigned, /* complain_on_overflow */ |
1347 | | bfd_elf_generic_reloc, /* special_function */ |
1348 | | AARCH64_R_STR (TLSLD_ADD_DTPREL_HI12), /* name */ |
1349 | | false, /* partial_inplace */ |
1350 | | 0, /* src_mask */ |
1351 | | 0xfff, /* dst_mask */ |
1352 | | false), /* pcrel_offset */ |
1353 | | |
1354 | | /* Unsigned 12 bit byte offset to module TLS base address. */ |
1355 | | HOWTO (AARCH64_R (TLSLD_ADD_DTPREL_LO12), /* type */ |
1356 | | 0, /* rightshift */ |
1357 | | 4, /* size */ |
1358 | | 12, /* bitsize */ |
1359 | | false, /* pc_relative */ |
1360 | | 0, /* bitpos */ |
1361 | | complain_overflow_unsigned, /* complain_on_overflow */ |
1362 | | bfd_elf_generic_reloc, /* special_function */ |
1363 | | AARCH64_R_STR (TLSLD_ADD_DTPREL_LO12), /* name */ |
1364 | | false, /* partial_inplace */ |
1365 | | 0, /* src_mask */ |
1366 | | 0xfff, /* dst_mask */ |
1367 | | false), /* pcrel_offset */ |
1368 | | |
1369 | | /* No overflow check version of BFD_RELOC_AARCH64_TLSLD_ADD_DTPREL_LO12. */ |
1370 | | HOWTO (AARCH64_R (TLSLD_ADD_DTPREL_LO12_NC), /* type */ |
1371 | | 0, /* rightshift */ |
1372 | | 4, /* size */ |
1373 | | 12, /* bitsize */ |
1374 | | false, /* pc_relative */ |
1375 | | 0, /* bitpos */ |
1376 | | complain_overflow_dont, /* complain_on_overflow */ |
1377 | | bfd_elf_generic_reloc, /* special_function */ |
1378 | | AARCH64_R_STR (TLSLD_ADD_DTPREL_LO12_NC), /* name */ |
1379 | | false, /* partial_inplace */ |
1380 | | 0, /* src_mask */ |
1381 | | 0xfff, /* dst_mask */ |
1382 | | false), /* pcrel_offset */ |
1383 | | |
1384 | | /* ADD: GOT offset G(S) & 0xff8 [no overflow check] */ |
1385 | | HOWTO (AARCH64_R (TLSLD_ADD_LO12_NC), /* type */ |
1386 | | 0, /* rightshift */ |
1387 | | 4, /* size */ |
1388 | | 12, /* bitsize */ |
1389 | | false, /* pc_relative */ |
1390 | | 0, /* bitpos */ |
1391 | | complain_overflow_dont, /* complain_on_overflow */ |
1392 | | bfd_elf_generic_reloc, /* special_function */ |
1393 | | AARCH64_R_STR (TLSLD_ADD_LO12_NC), /* name */ |
1394 | | false, /* partial_inplace */ |
1395 | | 0, /* src_mask */ |
1396 | | 0xfff, /* dst_mask */ |
1397 | | false), /* pcrel_offset */ |
1398 | | |
1399 | | /* Get to the page for the GOT entry for the symbol |
1400 | | (G(S) - P) using an ADRP instruction. */ |
1401 | | HOWTO (AARCH64_R (TLSLD_ADR_PAGE21), /* type */ |
1402 | | 12, /* rightshift */ |
1403 | | 4, /* size */ |
1404 | | 21, /* bitsize */ |
1405 | | true, /* pc_relative */ |
1406 | | 0, /* bitpos */ |
1407 | | complain_overflow_signed, /* complain_on_overflow */ |
1408 | | bfd_elf_generic_reloc, /* special_function */ |
1409 | | AARCH64_R_STR (TLSLD_ADR_PAGE21), /* name */ |
1410 | | false, /* partial_inplace */ |
1411 | | 0, /* src_mask */ |
1412 | | 0x1fffff, /* dst_mask */ |
1413 | | true), /* pcrel_offset */ |
1414 | | |
1415 | | HOWTO (AARCH64_R (TLSLD_ADR_PREL21), /* type */ |
1416 | | 0, /* rightshift */ |
1417 | | 4, /* size */ |
1418 | | 21, /* bitsize */ |
1419 | | true, /* pc_relative */ |
1420 | | 0, /* bitpos */ |
1421 | | complain_overflow_signed, /* complain_on_overflow */ |
1422 | | bfd_elf_generic_reloc, /* special_function */ |
1423 | | AARCH64_R_STR (TLSLD_ADR_PREL21), /* name */ |
1424 | | false, /* partial_inplace */ |
1425 | | 0, /* src_mask */ |
1426 | | 0x1fffff, /* dst_mask */ |
1427 | | true), /* pcrel_offset */ |
1428 | | |
1429 | | /* LD/ST16: bit[11:1] of byte offset to module TLS base address. */ |
1430 | | HOWTO64 (AARCH64_R (TLSLD_LDST16_DTPREL_LO12), /* type */ |
1431 | | 1, /* rightshift */ |
1432 | | 4, /* size */ |
1433 | | 11, /* bitsize */ |
1434 | | false, /* pc_relative */ |
1435 | | 10, /* bitpos */ |
1436 | | complain_overflow_unsigned, /* complain_on_overflow */ |
1437 | | bfd_elf_generic_reloc, /* special_function */ |
1438 | | AARCH64_R_STR (TLSLD_LDST16_DTPREL_LO12), /* name */ |
1439 | | false, /* partial_inplace */ |
1440 | | 0, /* src_mask */ |
1441 | | 0x1ffc00, /* dst_mask */ |
1442 | | false), /* pcrel_offset */ |
1443 | | |
1444 | | /* Same as BFD_RELOC_AARCH64_TLSLD_LDST16_DTPREL_LO12, but no overflow check. */ |
1445 | | HOWTO64 (AARCH64_R (TLSLD_LDST16_DTPREL_LO12_NC), /* type */ |
1446 | | 1, /* rightshift */ |
1447 | | 4, /* size */ |
1448 | | 11, /* bitsize */ |
1449 | | false, /* pc_relative */ |
1450 | | 10, /* bitpos */ |
1451 | | complain_overflow_dont, /* complain_on_overflow */ |
1452 | | bfd_elf_generic_reloc, /* special_function */ |
1453 | | AARCH64_R_STR (TLSLD_LDST16_DTPREL_LO12_NC), /* name */ |
1454 | | false, /* partial_inplace */ |
1455 | | 0, /* src_mask */ |
1456 | | 0x1ffc00, /* dst_mask */ |
1457 | | false), /* pcrel_offset */ |
1458 | | |
1459 | | /* LD/ST32: bit[11:2] of byte offset to module TLS base address. */ |
1460 | | HOWTO64 (AARCH64_R (TLSLD_LDST32_DTPREL_LO12), /* type */ |
1461 | | 2, /* rightshift */ |
1462 | | 4, /* size */ |
1463 | | 10, /* bitsize */ |
1464 | | false, /* pc_relative */ |
1465 | | 10, /* bitpos */ |
1466 | | complain_overflow_unsigned, /* complain_on_overflow */ |
1467 | | bfd_elf_generic_reloc, /* special_function */ |
1468 | | AARCH64_R_STR (TLSLD_LDST32_DTPREL_LO12), /* name */ |
1469 | | false, /* partial_inplace */ |
1470 | | 0, /* src_mask */ |
1471 | | 0x3ffc00, /* dst_mask */ |
1472 | | false), /* pcrel_offset */ |
1473 | | |
1474 | | /* Same as BFD_RELOC_AARCH64_TLSLD_LDST32_DTPREL_LO12, but no overflow check. */ |
1475 | | HOWTO64 (AARCH64_R (TLSLD_LDST32_DTPREL_LO12_NC), /* type */ |
1476 | | 2, /* rightshift */ |
1477 | | 4, /* size */ |
1478 | | 10, /* bitsize */ |
1479 | | false, /* pc_relative */ |
1480 | | 10, /* bitpos */ |
1481 | | complain_overflow_dont, /* complain_on_overflow */ |
1482 | | bfd_elf_generic_reloc, /* special_function */ |
1483 | | AARCH64_R_STR (TLSLD_LDST32_DTPREL_LO12_NC), /* name */ |
1484 | | false, /* partial_inplace */ |
1485 | | 0, /* src_mask */ |
1486 | | 0xffc00, /* dst_mask */ |
1487 | | false), /* pcrel_offset */ |
1488 | | |
1489 | | /* LD/ST64: bit[11:3] of byte offset to module TLS base address. */ |
1490 | | HOWTO64 (AARCH64_R (TLSLD_LDST64_DTPREL_LO12), /* type */ |
1491 | | 3, /* rightshift */ |
1492 | | 4, /* size */ |
1493 | | 9, /* bitsize */ |
1494 | | false, /* pc_relative */ |
1495 | | 10, /* bitpos */ |
1496 | | complain_overflow_unsigned, /* complain_on_overflow */ |
1497 | | bfd_elf_generic_reloc, /* special_function */ |
1498 | | AARCH64_R_STR (TLSLD_LDST64_DTPREL_LO12), /* name */ |
1499 | | false, /* partial_inplace */ |
1500 | | 0, /* src_mask */ |
1501 | | 0x3ffc00, /* dst_mask */ |
1502 | | false), /* pcrel_offset */ |
1503 | | |
1504 | | /* Same as BFD_RELOC_AARCH64_TLSLD_LDST64_DTPREL_LO12, but no overflow check. */ |
1505 | | HOWTO64 (AARCH64_R (TLSLD_LDST64_DTPREL_LO12_NC), /* type */ |
1506 | | 3, /* rightshift */ |
1507 | | 4, /* size */ |
1508 | | 9, /* bitsize */ |
1509 | | false, /* pc_relative */ |
1510 | | 10, /* bitpos */ |
1511 | | complain_overflow_dont, /* complain_on_overflow */ |
1512 | | bfd_elf_generic_reloc, /* special_function */ |
1513 | | AARCH64_R_STR (TLSLD_LDST64_DTPREL_LO12_NC), /* name */ |
1514 | | false, /* partial_inplace */ |
1515 | | 0, /* src_mask */ |
1516 | | 0x7fc00, /* dst_mask */ |
1517 | | false), /* pcrel_offset */ |
1518 | | |
1519 | | /* LD/ST8: bit[11:0] of byte offset to module TLS base address. */ |
1520 | | HOWTO64 (AARCH64_R (TLSLD_LDST8_DTPREL_LO12), /* type */ |
1521 | | 0, /* rightshift */ |
1522 | | 4, /* size */ |
1523 | | 12, /* bitsize */ |
1524 | | false, /* pc_relative */ |
1525 | | 10, /* bitpos */ |
1526 | | complain_overflow_unsigned, /* complain_on_overflow */ |
1527 | | bfd_elf_generic_reloc, /* special_function */ |
1528 | | AARCH64_R_STR (TLSLD_LDST8_DTPREL_LO12), /* name */ |
1529 | | false, /* partial_inplace */ |
1530 | | 0, /* src_mask */ |
1531 | | 0x3ffc00, /* dst_mask */ |
1532 | | false), /* pcrel_offset */ |
1533 | | |
1534 | | /* Same as BFD_RELOC_AARCH64_TLSLD_LDST8_DTPREL_LO12, but no overflow check. */ |
1535 | | HOWTO64 (AARCH64_R (TLSLD_LDST8_DTPREL_LO12_NC), /* type */ |
1536 | | 0, /* rightshift */ |
1537 | | 4, /* size */ |
1538 | | 12, /* bitsize */ |
1539 | | false, /* pc_relative */ |
1540 | | 10, /* bitpos */ |
1541 | | complain_overflow_dont, /* complain_on_overflow */ |
1542 | | bfd_elf_generic_reloc, /* special_function */ |
1543 | | AARCH64_R_STR (TLSLD_LDST8_DTPREL_LO12_NC), /* name */ |
1544 | | false, /* partial_inplace */ |
1545 | | 0, /* src_mask */ |
1546 | | 0x3ffc00, /* dst_mask */ |
1547 | | false), /* pcrel_offset */ |
1548 | | |
1549 | | /* MOVZ: bit[15:0] of byte offset to module TLS base address. */ |
1550 | | HOWTO (AARCH64_R (TLSLD_MOVW_DTPREL_G0), /* type */ |
1551 | | 0, /* rightshift */ |
1552 | | 4, /* size */ |
1553 | | 16, /* bitsize */ |
1554 | | false, /* pc_relative */ |
1555 | | 0, /* bitpos */ |
1556 | | complain_overflow_unsigned, /* complain_on_overflow */ |
1557 | | bfd_elf_generic_reloc, /* special_function */ |
1558 | | AARCH64_R_STR (TLSLD_MOVW_DTPREL_G0), /* name */ |
1559 | | false, /* partial_inplace */ |
1560 | | 0, /* src_mask */ |
1561 | | 0xffff, /* dst_mask */ |
1562 | | false), /* pcrel_offset */ |
1563 | | |
1564 | | /* No overflow check version of BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G0. */ |
1565 | | HOWTO (AARCH64_R (TLSLD_MOVW_DTPREL_G0_NC), /* type */ |
1566 | | 0, /* rightshift */ |
1567 | | 4, /* size */ |
1568 | | 16, /* bitsize */ |
1569 | | false, /* pc_relative */ |
1570 | | 0, /* bitpos */ |
1571 | | complain_overflow_dont, /* complain_on_overflow */ |
1572 | | bfd_elf_generic_reloc, /* special_function */ |
1573 | | AARCH64_R_STR (TLSLD_MOVW_DTPREL_G0_NC), /* name */ |
1574 | | false, /* partial_inplace */ |
1575 | | 0, /* src_mask */ |
1576 | | 0xffff, /* dst_mask */ |
1577 | | false), /* pcrel_offset */ |
1578 | | |
1579 | | /* MOVZ: bit[31:16] of byte offset to module TLS base address. */ |
1580 | | HOWTO (AARCH64_R (TLSLD_MOVW_DTPREL_G1), /* type */ |
1581 | | 16, /* rightshift */ |
1582 | | 4, /* size */ |
1583 | | 16, /* bitsize */ |
1584 | | false, /* pc_relative */ |
1585 | | 0, /* bitpos */ |
1586 | | complain_overflow_unsigned, /* complain_on_overflow */ |
1587 | | bfd_elf_generic_reloc, /* special_function */ |
1588 | | AARCH64_R_STR (TLSLD_MOVW_DTPREL_G1), /* name */ |
1589 | | false, /* partial_inplace */ |
1590 | | 0, /* src_mask */ |
1591 | | 0xffff, /* dst_mask */ |
1592 | | false), /* pcrel_offset */ |
1593 | | |
1594 | | /* No overflow check version of BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G1. */ |
1595 | | HOWTO64 (AARCH64_R (TLSLD_MOVW_DTPREL_G1_NC), /* type */ |
1596 | | 16, /* rightshift */ |
1597 | | 4, /* size */ |
1598 | | 16, /* bitsize */ |
1599 | | false, /* pc_relative */ |
1600 | | 0, /* bitpos */ |
1601 | | complain_overflow_dont, /* complain_on_overflow */ |
1602 | | bfd_elf_generic_reloc, /* special_function */ |
1603 | | AARCH64_R_STR (TLSLD_MOVW_DTPREL_G1_NC), /* name */ |
1604 | | false, /* partial_inplace */ |
1605 | | 0, /* src_mask */ |
1606 | | 0xffff, /* dst_mask */ |
1607 | | false), /* pcrel_offset */ |
1608 | | |
1609 | | /* MOVZ: bit[47:32] of byte offset to module TLS base address. */ |
1610 | | HOWTO64 (AARCH64_R (TLSLD_MOVW_DTPREL_G2), /* type */ |
1611 | | 32, /* rightshift */ |
1612 | | 4, /* size */ |
1613 | | 16, /* bitsize */ |
1614 | | false, /* pc_relative */ |
1615 | | 0, /* bitpos */ |
1616 | | complain_overflow_unsigned, /* complain_on_overflow */ |
1617 | | bfd_elf_generic_reloc, /* special_function */ |
1618 | | AARCH64_R_STR (TLSLD_MOVW_DTPREL_G2), /* name */ |
1619 | | false, /* partial_inplace */ |
1620 | | 0, /* src_mask */ |
1621 | | 0xffff, /* dst_mask */ |
1622 | | false), /* pcrel_offset */ |
1623 | | |
1624 | | HOWTO64 (AARCH64_R (TLSLE_MOVW_TPREL_G2), /* type */ |
1625 | | 32, /* rightshift */ |
1626 | | 4, /* size */ |
1627 | | 16, /* bitsize */ |
1628 | | false, /* pc_relative */ |
1629 | | 0, /* bitpos */ |
1630 | | complain_overflow_unsigned, /* complain_on_overflow */ |
1631 | | bfd_elf_generic_reloc, /* special_function */ |
1632 | | AARCH64_R_STR (TLSLE_MOVW_TPREL_G2), /* name */ |
1633 | | false, /* partial_inplace */ |
1634 | | 0, /* src_mask */ |
1635 | | 0xffff, /* dst_mask */ |
1636 | | false), /* pcrel_offset */ |
1637 | | |
1638 | | HOWTO (AARCH64_R (TLSLE_MOVW_TPREL_G1), /* type */ |
1639 | | 16, /* rightshift */ |
1640 | | 4, /* size */ |
1641 | | 16, /* bitsize */ |
1642 | | false, /* pc_relative */ |
1643 | | 0, /* bitpos */ |
1644 | | complain_overflow_dont, /* complain_on_overflow */ |
1645 | | bfd_elf_generic_reloc, /* special_function */ |
1646 | | AARCH64_R_STR (TLSLE_MOVW_TPREL_G1), /* name */ |
1647 | | false, /* partial_inplace */ |
1648 | | 0, /* src_mask */ |
1649 | | 0xffff, /* dst_mask */ |
1650 | | false), /* pcrel_offset */ |
1651 | | |
1652 | | HOWTO64 (AARCH64_R (TLSLE_MOVW_TPREL_G1_NC), /* type */ |
1653 | | 16, /* rightshift */ |
1654 | | 4, /* size */ |
1655 | | 16, /* bitsize */ |
1656 | | false, /* pc_relative */ |
1657 | | 0, /* bitpos */ |
1658 | | complain_overflow_dont, /* complain_on_overflow */ |
1659 | | bfd_elf_generic_reloc, /* special_function */ |
1660 | | AARCH64_R_STR (TLSLE_MOVW_TPREL_G1_NC), /* name */ |
1661 | | false, /* partial_inplace */ |
1662 | | 0, /* src_mask */ |
1663 | | 0xffff, /* dst_mask */ |
1664 | | false), /* pcrel_offset */ |
1665 | | |
1666 | | HOWTO (AARCH64_R (TLSLE_MOVW_TPREL_G0), /* type */ |
1667 | | 0, /* rightshift */ |
1668 | | 4, /* size */ |
1669 | | 16, /* bitsize */ |
1670 | | false, /* pc_relative */ |
1671 | | 0, /* bitpos */ |
1672 | | complain_overflow_dont, /* complain_on_overflow */ |
1673 | | bfd_elf_generic_reloc, /* special_function */ |
1674 | | AARCH64_R_STR (TLSLE_MOVW_TPREL_G0), /* name */ |
1675 | | false, /* partial_inplace */ |
1676 | | 0, /* src_mask */ |
1677 | | 0xffff, /* dst_mask */ |
1678 | | false), /* pcrel_offset */ |
1679 | | |
1680 | | HOWTO (AARCH64_R (TLSLE_MOVW_TPREL_G0_NC), /* type */ |
1681 | | 0, /* rightshift */ |
1682 | | 4, /* size */ |
1683 | | 16, /* bitsize */ |
1684 | | false, /* pc_relative */ |
1685 | | 0, /* bitpos */ |
1686 | | complain_overflow_dont, /* complain_on_overflow */ |
1687 | | bfd_elf_generic_reloc, /* special_function */ |
1688 | | AARCH64_R_STR (TLSLE_MOVW_TPREL_G0_NC), /* name */ |
1689 | | false, /* partial_inplace */ |
1690 | | 0, /* src_mask */ |
1691 | | 0xffff, /* dst_mask */ |
1692 | | false), /* pcrel_offset */ |
1693 | | |
1694 | | HOWTO (AARCH64_R (TLSLE_ADD_TPREL_HI12), /* type */ |
1695 | | 12, /* rightshift */ |
1696 | | 4, /* size */ |
1697 | | 12, /* bitsize */ |
1698 | | false, /* pc_relative */ |
1699 | | 0, /* bitpos */ |
1700 | | complain_overflow_unsigned, /* complain_on_overflow */ |
1701 | | bfd_elf_generic_reloc, /* special_function */ |
1702 | | AARCH64_R_STR (TLSLE_ADD_TPREL_HI12), /* name */ |
1703 | | false, /* partial_inplace */ |
1704 | | 0, /* src_mask */ |
1705 | | 0xfff, /* dst_mask */ |
1706 | | false), /* pcrel_offset */ |
1707 | | |
1708 | | HOWTO (AARCH64_R (TLSLE_ADD_TPREL_LO12), /* type */ |
1709 | | 0, /* rightshift */ |
1710 | | 4, /* size */ |
1711 | | 12, /* bitsize */ |
1712 | | false, /* pc_relative */ |
1713 | | 0, /* bitpos */ |
1714 | | complain_overflow_unsigned, /* complain_on_overflow */ |
1715 | | bfd_elf_generic_reloc, /* special_function */ |
1716 | | AARCH64_R_STR (TLSLE_ADD_TPREL_LO12), /* name */ |
1717 | | false, /* partial_inplace */ |
1718 | | 0, /* src_mask */ |
1719 | | 0xfff, /* dst_mask */ |
1720 | | false), /* pcrel_offset */ |
1721 | | |
1722 | | HOWTO (AARCH64_R (TLSLE_ADD_TPREL_LO12_NC), /* type */ |
1723 | | 0, /* rightshift */ |
1724 | | 4, /* size */ |
1725 | | 12, /* bitsize */ |
1726 | | false, /* pc_relative */ |
1727 | | 0, /* bitpos */ |
1728 | | complain_overflow_dont, /* complain_on_overflow */ |
1729 | | bfd_elf_generic_reloc, /* special_function */ |
1730 | | AARCH64_R_STR (TLSLE_ADD_TPREL_LO12_NC), /* name */ |
1731 | | false, /* partial_inplace */ |
1732 | | 0, /* src_mask */ |
1733 | | 0xfff, /* dst_mask */ |
1734 | | false), /* pcrel_offset */ |
1735 | | |
1736 | | /* LD/ST16: bit[11:1] of byte offset to module TLS base address. */ |
1737 | | HOWTO (AARCH64_R (TLSLE_LDST16_TPREL_LO12), /* type */ |
1738 | | 1, /* rightshift */ |
1739 | | 4, /* size */ |
1740 | | 11, /* bitsize */ |
1741 | | false, /* pc_relative */ |
1742 | | 10, /* bitpos */ |
1743 | | complain_overflow_unsigned, /* complain_on_overflow */ |
1744 | | bfd_elf_generic_reloc, /* special_function */ |
1745 | | AARCH64_R_STR (TLSLE_LDST16_TPREL_LO12), /* name */ |
1746 | | false, /* partial_inplace */ |
1747 | | 0, /* src_mask */ |
1748 | | 0x1ffc00, /* dst_mask */ |
1749 | | false), /* pcrel_offset */ |
1750 | | |
1751 | | /* Same as BFD_RELOC_AARCH64_TLSLE_LDST16_TPREL_LO12, but no overflow check. */ |
1752 | | HOWTO (AARCH64_R (TLSLE_LDST16_TPREL_LO12_NC), /* type */ |
1753 | | 1, /* rightshift */ |
1754 | | 4, /* size */ |
1755 | | 11, /* bitsize */ |
1756 | | false, /* pc_relative */ |
1757 | | 10, /* bitpos */ |
1758 | | complain_overflow_dont, /* complain_on_overflow */ |
1759 | | bfd_elf_generic_reloc, /* special_function */ |
1760 | | AARCH64_R_STR (TLSLE_LDST16_TPREL_LO12_NC), /* name */ |
1761 | | false, /* partial_inplace */ |
1762 | | 0, /* src_mask */ |
1763 | | 0x1ffc00, /* dst_mask */ |
1764 | | false), /* pcrel_offset */ |
1765 | | |
1766 | | /* LD/ST32: bit[11:2] of byte offset to module TLS base address. */ |
1767 | | HOWTO (AARCH64_R (TLSLE_LDST32_TPREL_LO12), /* type */ |
1768 | | 2, /* rightshift */ |
1769 | | 4, /* size */ |
1770 | | 10, /* bitsize */ |
1771 | | false, /* pc_relative */ |
1772 | | 10, /* bitpos */ |
1773 | | complain_overflow_unsigned, /* complain_on_overflow */ |
1774 | | bfd_elf_generic_reloc, /* special_function */ |
1775 | | AARCH64_R_STR (TLSLE_LDST32_TPREL_LO12), /* name */ |
1776 | | false, /* partial_inplace */ |
1777 | | 0, /* src_mask */ |
1778 | | 0xffc00, /* dst_mask */ |
1779 | | false), /* pcrel_offset */ |
1780 | | |
1781 | | /* Same as BFD_RELOC_AARCH64_TLSLE_LDST32_TPREL_LO12, but no overflow check. */ |
1782 | | HOWTO (AARCH64_R (TLSLE_LDST32_TPREL_LO12_NC), /* type */ |
1783 | | 2, /* rightshift */ |
1784 | | 4, /* size */ |
1785 | | 10, /* bitsize */ |
1786 | | false, /* pc_relative */ |
1787 | | 10, /* bitpos */ |
1788 | | complain_overflow_dont, /* complain_on_overflow */ |
1789 | | bfd_elf_generic_reloc, /* special_function */ |
1790 | | AARCH64_R_STR (TLSLE_LDST32_TPREL_LO12_NC), /* name */ |
1791 | | false, /* partial_inplace */ |
1792 | | 0, /* src_mask */ |
1793 | | 0xffc00, /* dst_mask */ |
1794 | | false), /* pcrel_offset */ |
1795 | | |
1796 | | /* LD/ST64: bit[11:3] of byte offset to module TLS base address. */ |
1797 | | HOWTO (AARCH64_R (TLSLE_LDST64_TPREL_LO12), /* type */ |
1798 | | 3, /* rightshift */ |
1799 | | 4, /* size */ |
1800 | | 9, /* bitsize */ |
1801 | | false, /* pc_relative */ |
1802 | | 10, /* bitpos */ |
1803 | | complain_overflow_unsigned, /* complain_on_overflow */ |
1804 | | bfd_elf_generic_reloc, /* special_function */ |
1805 | | AARCH64_R_STR (TLSLE_LDST64_TPREL_LO12), /* name */ |
1806 | | false, /* partial_inplace */ |
1807 | | 0, /* src_mask */ |
1808 | | 0x7fc00, /* dst_mask */ |
1809 | | false), /* pcrel_offset */ |
1810 | | |
1811 | | /* Same as BFD_RELOC_AARCH64_TLSLE_LDST64_TPREL_LO12, but no overflow check. */ |
1812 | | HOWTO (AARCH64_R (TLSLE_LDST64_TPREL_LO12_NC), /* type */ |
1813 | | 3, /* rightshift */ |
1814 | | 4, /* size */ |
1815 | | 9, /* bitsize */ |
1816 | | false, /* pc_relative */ |
1817 | | 10, /* bitpos */ |
1818 | | complain_overflow_dont, /* complain_on_overflow */ |
1819 | | bfd_elf_generic_reloc, /* special_function */ |
1820 | | AARCH64_R_STR (TLSLE_LDST64_TPREL_LO12_NC), /* name */ |
1821 | | false, /* partial_inplace */ |
1822 | | 0, /* src_mask */ |
1823 | | 0x7fc00, /* dst_mask */ |
1824 | | false), /* pcrel_offset */ |
1825 | | |
1826 | | /* LD/ST8: bit[11:0] of byte offset to module TLS base address. */ |
1827 | | HOWTO (AARCH64_R (TLSLE_LDST8_TPREL_LO12), /* type */ |
1828 | | 0, /* rightshift */ |
1829 | | 4, /* size */ |
1830 | | 12, /* bitsize */ |
1831 | | false, /* pc_relative */ |
1832 | | 10, /* bitpos */ |
1833 | | complain_overflow_unsigned, /* complain_on_overflow */ |
1834 | | bfd_elf_generic_reloc, /* special_function */ |
1835 | | AARCH64_R_STR (TLSLE_LDST8_TPREL_LO12), /* name */ |
1836 | | false, /* partial_inplace */ |
1837 | | 0, /* src_mask */ |
1838 | | 0x3ffc00, /* dst_mask */ |
1839 | | false), /* pcrel_offset */ |
1840 | | |
1841 | | /* Same as BFD_RELOC_AARCH64_TLSLE_LDST8_TPREL_LO12, but no overflow check. */ |
1842 | | HOWTO (AARCH64_R (TLSLE_LDST8_TPREL_LO12_NC), /* type */ |
1843 | | 0, /* rightshift */ |
1844 | | 4, /* size */ |
1845 | | 12, /* bitsize */ |
1846 | | false, /* pc_relative */ |
1847 | | 10, /* bitpos */ |
1848 | | complain_overflow_dont, /* complain_on_overflow */ |
1849 | | bfd_elf_generic_reloc, /* special_function */ |
1850 | | AARCH64_R_STR (TLSLE_LDST8_TPREL_LO12_NC), /* name */ |
1851 | | false, /* partial_inplace */ |
1852 | | 0, /* src_mask */ |
1853 | | 0x3ffc00, /* dst_mask */ |
1854 | | false), /* pcrel_offset */ |
1855 | | |
1856 | | HOWTO (AARCH64_R (TLSDESC_LD_PREL19), /* type */ |
1857 | | 2, /* rightshift */ |
1858 | | 4, /* size */ |
1859 | | 19, /* bitsize */ |
1860 | | true, /* pc_relative */ |
1861 | | 0, /* bitpos */ |
1862 | | complain_overflow_dont, /* complain_on_overflow */ |
1863 | | bfd_elf_generic_reloc, /* special_function */ |
1864 | | AARCH64_R_STR (TLSDESC_LD_PREL19), /* name */ |
1865 | | false, /* partial_inplace */ |
1866 | | 0, /* src_mask */ |
1867 | | 0x0ffffe0, /* dst_mask */ |
1868 | | true), /* pcrel_offset */ |
1869 | | |
1870 | | HOWTO (AARCH64_R (TLSDESC_ADR_PREL21), /* type */ |
1871 | | 0, /* rightshift */ |
1872 | | 4, /* size */ |
1873 | | 21, /* bitsize */ |
1874 | | true, /* pc_relative */ |
1875 | | 0, /* bitpos */ |
1876 | | complain_overflow_dont, /* complain_on_overflow */ |
1877 | | bfd_elf_generic_reloc, /* special_function */ |
1878 | | AARCH64_R_STR (TLSDESC_ADR_PREL21), /* name */ |
1879 | | false, /* partial_inplace */ |
1880 | | 0, /* src_mask */ |
1881 | | 0x1fffff, /* dst_mask */ |
1882 | | true), /* pcrel_offset */ |
1883 | | |
1884 | | /* Get to the page for the GOT entry for the symbol |
1885 | | (G(S) - P) using an ADRP instruction. */ |
1886 | | HOWTO (AARCH64_R (TLSDESC_ADR_PAGE21), /* type */ |
1887 | | 12, /* rightshift */ |
1888 | | 4, /* size */ |
1889 | | 21, /* bitsize */ |
1890 | | true, /* pc_relative */ |
1891 | | 0, /* bitpos */ |
1892 | | complain_overflow_dont, /* complain_on_overflow */ |
1893 | | bfd_elf_generic_reloc, /* special_function */ |
1894 | | AARCH64_R_STR (TLSDESC_ADR_PAGE21), /* name */ |
1895 | | false, /* partial_inplace */ |
1896 | | 0, /* src_mask */ |
1897 | | 0x1fffff, /* dst_mask */ |
1898 | | true), /* pcrel_offset */ |
1899 | | |
1900 | | /* LD64: GOT offset G(S) & 0xff8. */ |
1901 | | HOWTO64 (AARCH64_R (TLSDESC_LD64_LO12), /* type */ |
1902 | | 3, /* rightshift */ |
1903 | | 4, /* size */ |
1904 | | 12, /* bitsize */ |
1905 | | false, /* pc_relative */ |
1906 | | 0, /* bitpos */ |
1907 | | complain_overflow_dont, /* complain_on_overflow */ |
1908 | | bfd_elf_generic_reloc, /* special_function */ |
1909 | | AARCH64_R_STR (TLSDESC_LD64_LO12), /* name */ |
1910 | | false, /* partial_inplace */ |
1911 | | 0, /* src_mask */ |
1912 | | 0xff8, /* dst_mask */ |
1913 | | false), /* pcrel_offset */ |
1914 | | |
1915 | | /* LD32: GOT offset G(S) & 0xffc. */ |
1916 | | HOWTO32 (AARCH64_R (TLSDESC_LD32_LO12_NC), /* type */ |
1917 | | 2, /* rightshift */ |
1918 | | 4, /* size */ |
1919 | | 12, /* bitsize */ |
1920 | | false, /* pc_relative */ |
1921 | | 0, /* bitpos */ |
1922 | | complain_overflow_dont, /* complain_on_overflow */ |
1923 | | bfd_elf_generic_reloc, /* special_function */ |
1924 | | AARCH64_R_STR (TLSDESC_LD32_LO12_NC), /* name */ |
1925 | | false, /* partial_inplace */ |
1926 | | 0, /* src_mask */ |
1927 | | 0xffc, /* dst_mask */ |
1928 | | false), /* pcrel_offset */ |
1929 | | |
1930 | | /* ADD: GOT offset G(S) & 0xfff. */ |
1931 | | HOWTO (AARCH64_R (TLSDESC_ADD_LO12), /* type */ |
1932 | | 0, /* rightshift */ |
1933 | | 4, /* size */ |
1934 | | 12, /* bitsize */ |
1935 | | false, /* pc_relative */ |
1936 | | 0, /* bitpos */ |
1937 | | complain_overflow_dont,/* complain_on_overflow */ |
1938 | | bfd_elf_generic_reloc, /* special_function */ |
1939 | | AARCH64_R_STR (TLSDESC_ADD_LO12), /* name */ |
1940 | | false, /* partial_inplace */ |
1941 | | 0, /* src_mask */ |
1942 | | 0xfff, /* dst_mask */ |
1943 | | false), /* pcrel_offset */ |
1944 | | |
1945 | | HOWTO64 (AARCH64_R (TLSDESC_OFF_G1), /* type */ |
1946 | | 16, /* rightshift */ |
1947 | | 4, /* size */ |
1948 | | 12, /* bitsize */ |
1949 | | false, /* pc_relative */ |
1950 | | 0, /* bitpos */ |
1951 | | complain_overflow_unsigned, /* complain_on_overflow */ |
1952 | | bfd_elf_generic_reloc, /* special_function */ |
1953 | | AARCH64_R_STR (TLSDESC_OFF_G1), /* name */ |
1954 | | false, /* partial_inplace */ |
1955 | | 0, /* src_mask */ |
1956 | | 0xffff, /* dst_mask */ |
1957 | | false), /* pcrel_offset */ |
1958 | | |
1959 | | HOWTO64 (AARCH64_R (TLSDESC_OFF_G0_NC), /* type */ |
1960 | | 0, /* rightshift */ |
1961 | | 4, /* size */ |
1962 | | 12, /* bitsize */ |
1963 | | false, /* pc_relative */ |
1964 | | 0, /* bitpos */ |
1965 | | complain_overflow_dont, /* complain_on_overflow */ |
1966 | | bfd_elf_generic_reloc, /* special_function */ |
1967 | | AARCH64_R_STR (TLSDESC_OFF_G0_NC), /* name */ |
1968 | | false, /* partial_inplace */ |
1969 | | 0, /* src_mask */ |
1970 | | 0xffff, /* dst_mask */ |
1971 | | false), /* pcrel_offset */ |
1972 | | |
1973 | | HOWTO64 (AARCH64_R (TLSDESC_LDR), /* type */ |
1974 | | 0, /* rightshift */ |
1975 | | 4, /* size */ |
1976 | | 12, /* bitsize */ |
1977 | | false, /* pc_relative */ |
1978 | | 0, /* bitpos */ |
1979 | | complain_overflow_dont, /* complain_on_overflow */ |
1980 | | bfd_elf_generic_reloc, /* special_function */ |
1981 | | AARCH64_R_STR (TLSDESC_LDR), /* name */ |
1982 | | false, /* partial_inplace */ |
1983 | | 0x0, /* src_mask */ |
1984 | | 0x0, /* dst_mask */ |
1985 | | false), /* pcrel_offset */ |
1986 | | |
1987 | | HOWTO64 (AARCH64_R (TLSDESC_ADD), /* type */ |
1988 | | 0, /* rightshift */ |
1989 | | 4, /* size */ |
1990 | | 12, /* bitsize */ |
1991 | | false, /* pc_relative */ |
1992 | | 0, /* bitpos */ |
1993 | | complain_overflow_dont, /* complain_on_overflow */ |
1994 | | bfd_elf_generic_reloc, /* special_function */ |
1995 | | AARCH64_R_STR (TLSDESC_ADD), /* name */ |
1996 | | false, /* partial_inplace */ |
1997 | | 0x0, /* src_mask */ |
1998 | | 0x0, /* dst_mask */ |
1999 | | false), /* pcrel_offset */ |
2000 | | |
2001 | | HOWTO (AARCH64_R (TLSDESC_CALL), /* type */ |
2002 | | 0, /* rightshift */ |
2003 | | 4, /* size */ |
2004 | | 0, /* bitsize */ |
2005 | | false, /* pc_relative */ |
2006 | | 0, /* bitpos */ |
2007 | | complain_overflow_dont, /* complain_on_overflow */ |
2008 | | bfd_elf_generic_reloc, /* special_function */ |
2009 | | AARCH64_R_STR (TLSDESC_CALL), /* name */ |
2010 | | false, /* partial_inplace */ |
2011 | | 0x0, /* src_mask */ |
2012 | | 0x0, /* dst_mask */ |
2013 | | false), /* pcrel_offset */ |
2014 | | |
2015 | | HOWTO (AARCH64_R (COPY), /* type */ |
2016 | | 0, /* rightshift */ |
2017 | | 4, /* size */ |
2018 | | 64, /* bitsize */ |
2019 | | false, /* pc_relative */ |
2020 | | 0, /* bitpos */ |
2021 | | complain_overflow_bitfield, /* complain_on_overflow */ |
2022 | | bfd_elf_generic_reloc, /* special_function */ |
2023 | | AARCH64_R_STR (COPY), /* name */ |
2024 | | true, /* partial_inplace */ |
2025 | | 0, /* src_mask */ |
2026 | | 0xffffffff, /* dst_mask */ |
2027 | | false), /* pcrel_offset */ |
2028 | | |
2029 | | HOWTO (AARCH64_R (GLOB_DAT), /* type */ |
2030 | | 0, /* rightshift */ |
2031 | | 4, /* size */ |
2032 | | 64, /* bitsize */ |
2033 | | false, /* pc_relative */ |
2034 | | 0, /* bitpos */ |
2035 | | complain_overflow_bitfield, /* complain_on_overflow */ |
2036 | | bfd_elf_generic_reloc, /* special_function */ |
2037 | | AARCH64_R_STR (GLOB_DAT), /* name */ |
2038 | | true, /* partial_inplace */ |
2039 | | 0, /* src_mask */ |
2040 | | 0xffffffff, /* dst_mask */ |
2041 | | false), /* pcrel_offset */ |
2042 | | |
2043 | | HOWTO (AARCH64_R (JUMP_SLOT), /* type */ |
2044 | | 0, /* rightshift */ |
2045 | | 4, /* size */ |
2046 | | 64, /* bitsize */ |
2047 | | false, /* pc_relative */ |
2048 | | 0, /* bitpos */ |
2049 | | complain_overflow_bitfield, /* complain_on_overflow */ |
2050 | | bfd_elf_generic_reloc, /* special_function */ |
2051 | | AARCH64_R_STR (JUMP_SLOT), /* name */ |
2052 | | true, /* partial_inplace */ |
2053 | | 0, /* src_mask */ |
2054 | | 0xffffffff, /* dst_mask */ |
2055 | | false), /* pcrel_offset */ |
2056 | | |
2057 | | HOWTO (AARCH64_R (RELATIVE), /* type */ |
2058 | | 0, /* rightshift */ |
2059 | | 4, /* size */ |
2060 | | 64, /* bitsize */ |
2061 | | false, /* pc_relative */ |
2062 | | 0, /* bitpos */ |
2063 | | complain_overflow_bitfield, /* complain_on_overflow */ |
2064 | | bfd_elf_generic_reloc, /* special_function */ |
2065 | | AARCH64_R_STR (RELATIVE), /* name */ |
2066 | | true, /* partial_inplace */ |
2067 | | 0, /* src_mask */ |
2068 | | ALL_ONES, /* dst_mask */ |
2069 | | false), /* pcrel_offset */ |
2070 | | |
2071 | | HOWTO (AARCH64_R (TLS_DTPMOD), /* type */ |
2072 | | 0, /* rightshift */ |
2073 | | 4, /* size */ |
2074 | | 64, /* bitsize */ |
2075 | | false, /* pc_relative */ |
2076 | | 0, /* bitpos */ |
2077 | | complain_overflow_dont, /* complain_on_overflow */ |
2078 | | bfd_elf_generic_reloc, /* special_function */ |
2079 | | #if ARCH_SIZE == 64 |
2080 | | AARCH64_R_STR (TLS_DTPMOD64), /* name */ |
2081 | | #else |
2082 | | AARCH64_R_STR (TLS_DTPMOD), /* name */ |
2083 | | #endif |
2084 | | false, /* partial_inplace */ |
2085 | | 0, /* src_mask */ |
2086 | | ALL_ONES, /* dst_mask */ |
2087 | | false), /* pc_reloffset */ |
2088 | | |
2089 | | HOWTO (AARCH64_R (TLS_DTPREL), /* type */ |
2090 | | 0, /* rightshift */ |
2091 | | 4, /* size */ |
2092 | | 64, /* bitsize */ |
2093 | | false, /* pc_relative */ |
2094 | | 0, /* bitpos */ |
2095 | | complain_overflow_dont, /* complain_on_overflow */ |
2096 | | bfd_elf_generic_reloc, /* special_function */ |
2097 | | #if ARCH_SIZE == 64 |
2098 | | AARCH64_R_STR (TLS_DTPREL64), /* name */ |
2099 | | #else |
2100 | | AARCH64_R_STR (TLS_DTPREL), /* name */ |
2101 | | #endif |
2102 | | false, /* partial_inplace */ |
2103 | | 0, /* src_mask */ |
2104 | | ALL_ONES, /* dst_mask */ |
2105 | | false), /* pcrel_offset */ |
2106 | | |
2107 | | HOWTO (AARCH64_R (TLS_TPREL), /* type */ |
2108 | | 0, /* rightshift */ |
2109 | | 4, /* size */ |
2110 | | 64, /* bitsize */ |
2111 | | false, /* pc_relative */ |
2112 | | 0, /* bitpos */ |
2113 | | complain_overflow_dont, /* complain_on_overflow */ |
2114 | | bfd_elf_generic_reloc, /* special_function */ |
2115 | | #if ARCH_SIZE == 64 |
2116 | | AARCH64_R_STR (TLS_TPREL64), /* name */ |
2117 | | #else |
2118 | | AARCH64_R_STR (TLS_TPREL), /* name */ |
2119 | | #endif |
2120 | | false, /* partial_inplace */ |
2121 | | 0, /* src_mask */ |
2122 | | ALL_ONES, /* dst_mask */ |
2123 | | false), /* pcrel_offset */ |
2124 | | |
2125 | | HOWTO (AARCH64_R (TLSDESC), /* type */ |
2126 | | 0, /* rightshift */ |
2127 | | 4, /* size */ |
2128 | | 64, /* bitsize */ |
2129 | | false, /* pc_relative */ |
2130 | | 0, /* bitpos */ |
2131 | | complain_overflow_dont, /* complain_on_overflow */ |
2132 | | bfd_elf_generic_reloc, /* special_function */ |
2133 | | AARCH64_R_STR (TLSDESC), /* name */ |
2134 | | false, /* partial_inplace */ |
2135 | | 0, /* src_mask */ |
2136 | | ALL_ONES, /* dst_mask */ |
2137 | | false), /* pcrel_offset */ |
2138 | | |
2139 | | HOWTO (AARCH64_R (IRELATIVE), /* type */ |
2140 | | 0, /* rightshift */ |
2141 | | 4, /* size */ |
2142 | | 64, /* bitsize */ |
2143 | | false, /* pc_relative */ |
2144 | | 0, /* bitpos */ |
2145 | | complain_overflow_bitfield, /* complain_on_overflow */ |
2146 | | bfd_elf_generic_reloc, /* special_function */ |
2147 | | AARCH64_R_STR (IRELATIVE), /* name */ |
2148 | | false, /* partial_inplace */ |
2149 | | 0, /* src_mask */ |
2150 | | ALL_ONES, /* dst_mask */ |
2151 | | false), /* pcrel_offset */ |
2152 | | |
2153 | | EMPTY_HOWTO (0), |
2154 | | }; |
2155 | | |
2156 | | static reloc_howto_type elf64_aarch64_howto_none = |
2157 | | HOWTO (R_AARCH64_NONE, /* type */ |
2158 | | 0, /* rightshift */ |
2159 | | 0, /* size */ |
2160 | | 0, /* bitsize */ |
2161 | | false, /* pc_relative */ |
2162 | | 0, /* bitpos */ |
2163 | | complain_overflow_dont,/* complain_on_overflow */ |
2164 | | bfd_elf_generic_reloc, /* special_function */ |
2165 | | "R_AARCH64_NONE", /* name */ |
2166 | | false, /* partial_inplace */ |
2167 | | 0, /* src_mask */ |
2168 | | 0, /* dst_mask */ |
2169 | | false); /* pcrel_offset */ |
2170 | | |
2171 | | /* Given HOWTO, return the bfd internal relocation enumerator. */ |
2172 | | |
2173 | | static bfd_reloc_code_real_type |
2174 | | elf64_aarch64_bfd_reloc_from_howto (reloc_howto_type *howto) |
2175 | 0 | { |
2176 | 0 | const int size |
2177 | 0 | = (int) ARRAY_SIZE (elf64_aarch64_howto_table); |
2178 | 0 | const ptrdiff_t offset |
2179 | 0 | = howto - elf64_aarch64_howto_table; |
2180 | |
|
2181 | 0 | if (offset > 0 && offset < size - 1) |
2182 | 0 | return BFD_RELOC_AARCH64_RELOC_START + offset; |
2183 | | |
2184 | 0 | if (howto == &elf64_aarch64_howto_none) |
2185 | 0 | return BFD_RELOC_AARCH64_NONE; |
2186 | | |
2187 | 0 | return BFD_RELOC_AARCH64_RELOC_START; |
2188 | 0 | } |
2189 | | |
2190 | | /* Given R_TYPE, return the bfd internal relocation enumerator. */ |
2191 | | |
2192 | | static bfd_reloc_code_real_type |
2193 | | elf64_aarch64_bfd_reloc_from_type (bfd *abfd, unsigned int r_type) |
2194 | 5 | { |
2195 | 5 | static bool initialized_p = false; |
2196 | | /* Indexed by R_TYPE, values are offsets in the howto_table. */ |
2197 | 5 | static unsigned int offsets[R_AARCH64_end]; |
2198 | | |
2199 | 5 | if (!initialized_p) |
2200 | 1 | { |
2201 | 1 | unsigned int i; |
2202 | | |
2203 | 115 | for (i = 1; i < ARRAY_SIZE (elf64_aarch64_howto_table) - 1; ++i) |
2204 | 114 | if (elf64_aarch64_howto_table[i].type != 0) |
2205 | 109 | offsets[elf64_aarch64_howto_table[i].type] = i; |
2206 | | |
2207 | 1 | initialized_p = true; |
2208 | 1 | } |
2209 | | |
2210 | 5 | if (r_type == R_AARCH64_NONE || r_type == R_AARCH64_NULL) |
2211 | 0 | return BFD_RELOC_AARCH64_NONE; |
2212 | | |
2213 | | /* PR 17512: file: b371e70a. */ |
2214 | 5 | if (r_type >= R_AARCH64_end) |
2215 | 5 | { |
2216 | 5 | _bfd_error_handler (_("%pB: unsupported relocation type %#x"), |
2217 | 5 | abfd, r_type); |
2218 | 5 | bfd_set_error (bfd_error_bad_value); |
2219 | 5 | return BFD_RELOC_AARCH64_NONE; |
2220 | 5 | } |
2221 | | |
2222 | 0 | return BFD_RELOC_AARCH64_RELOC_START + offsets[r_type]; |
2223 | 5 | } |
2224 | | |
2225 | | struct elf_aarch64_reloc_map |
2226 | | { |
2227 | | bfd_reloc_code_real_type from; |
2228 | | bfd_reloc_code_real_type to; |
2229 | | }; |
2230 | | |
2231 | | /* Map bfd generic reloc to AArch64-specific reloc. */ |
2232 | | static const struct elf_aarch64_reloc_map elf_aarch64_reloc_map[] = |
2233 | | { |
2234 | | {BFD_RELOC_NONE, BFD_RELOC_AARCH64_NONE}, |
2235 | | |
2236 | | /* Basic data relocations. */ |
2237 | | {BFD_RELOC_CTOR, BFD_RELOC_AARCH64_64}, |
2238 | | {BFD_RELOC_64, BFD_RELOC_AARCH64_64}, |
2239 | | {BFD_RELOC_32, BFD_RELOC_AARCH64_32}, |
2240 | | {BFD_RELOC_16, BFD_RELOC_AARCH64_16}, |
2241 | | {BFD_RELOC_64_PCREL, BFD_RELOC_AARCH64_64_PCREL}, |
2242 | | {BFD_RELOC_32_PCREL, BFD_RELOC_AARCH64_32_PCREL}, |
2243 | | {BFD_RELOC_16_PCREL, BFD_RELOC_AARCH64_16_PCREL}, |
2244 | | }; |
2245 | | |
2246 | | /* Given the bfd internal relocation enumerator in CODE, return the |
2247 | | corresponding howto entry. */ |
2248 | | |
2249 | | static reloc_howto_type * |
2250 | | elf64_aarch64_howto_from_bfd_reloc (bfd_reloc_code_real_type code) |
2251 | 5 | { |
2252 | 5 | unsigned int i; |
2253 | | |
2254 | | /* Convert bfd generic reloc to AArch64-specific reloc. */ |
2255 | 5 | if (code < BFD_RELOC_AARCH64_RELOC_START |
2256 | 5 | || code > BFD_RELOC_AARCH64_RELOC_END) |
2257 | 0 | for (i = 0; i < ARRAY_SIZE (elf_aarch64_reloc_map); i++) |
2258 | 0 | if (elf_aarch64_reloc_map[i].from == code) |
2259 | 0 | { |
2260 | 0 | code = elf_aarch64_reloc_map[i].to; |
2261 | 0 | break; |
2262 | 0 | } |
2263 | | |
2264 | 5 | if (code > BFD_RELOC_AARCH64_RELOC_START |
2265 | 5 | && code < BFD_RELOC_AARCH64_RELOC_END) |
2266 | 5 | if (elf64_aarch64_howto_table[code - BFD_RELOC_AARCH64_RELOC_START].type) |
2267 | 0 | return &elf64_aarch64_howto_table[code - BFD_RELOC_AARCH64_RELOC_START]; |
2268 | | |
2269 | 5 | if (code == BFD_RELOC_AARCH64_NONE) |
2270 | 5 | return &elf64_aarch64_howto_none; |
2271 | | |
2272 | 0 | return NULL; |
2273 | 5 | } |
2274 | | |
2275 | | static reloc_howto_type * |
2276 | | elf64_aarch64_howto_from_type (bfd *abfd, unsigned int r_type) |
2277 | 5 | { |
2278 | 5 | bfd_reloc_code_real_type val; |
2279 | 5 | reloc_howto_type *howto; |
2280 | | |
2281 | | #if ARCH_SIZE == 32 |
2282 | | if (r_type > 256) |
2283 | | { |
2284 | | bfd_set_error (bfd_error_bad_value); |
2285 | | return NULL; |
2286 | | } |
2287 | | #endif |
2288 | | |
2289 | 5 | if (r_type == R_AARCH64_NONE) |
2290 | 0 | return &elf64_aarch64_howto_none; |
2291 | | |
2292 | 5 | val = elf64_aarch64_bfd_reloc_from_type (abfd, r_type); |
2293 | 5 | howto = elf64_aarch64_howto_from_bfd_reloc (val); |
2294 | | |
2295 | 5 | if (howto != NULL) |
2296 | 5 | return howto; |
2297 | | |
2298 | 0 | bfd_set_error (bfd_error_bad_value); |
2299 | 0 | return NULL; |
2300 | 5 | } |
2301 | | |
2302 | | static bool |
2303 | | elf64_aarch64_info_to_howto (bfd *abfd, arelent *bfd_reloc, |
2304 | | Elf_Internal_Rela *elf_reloc) |
2305 | 5 | { |
2306 | 5 | unsigned int r_type; |
2307 | | |
2308 | 5 | r_type = ELF64_R_TYPE (elf_reloc->r_info); |
2309 | 5 | bfd_reloc->howto = elf64_aarch64_howto_from_type (abfd, r_type); |
2310 | | |
2311 | 5 | if (bfd_reloc->howto == NULL) |
2312 | 0 | { |
2313 | | /* xgettext:c-format */ |
2314 | 0 | _bfd_error_handler (_("%pB: unsupported relocation type %#x"), abfd, r_type); |
2315 | 0 | return false; |
2316 | 0 | } |
2317 | 5 | return true; |
2318 | 5 | } |
2319 | | |
2320 | | static reloc_howto_type * |
2321 | | elf64_aarch64_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED, |
2322 | | bfd_reloc_code_real_type code) |
2323 | 0 | { |
2324 | 0 | reloc_howto_type *howto = elf64_aarch64_howto_from_bfd_reloc (code); |
2325 | |
|
2326 | 0 | if (howto != NULL) |
2327 | 0 | return howto; |
2328 | | |
2329 | 0 | bfd_set_error (bfd_error_bad_value); |
2330 | 0 | return NULL; |
2331 | 0 | } |
2332 | | |
2333 | | static reloc_howto_type * |
2334 | | elf64_aarch64_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED, |
2335 | | const char *r_name) |
2336 | 0 | { |
2337 | 0 | unsigned int i; |
2338 | |
|
2339 | 0 | for (i = 1; i < ARRAY_SIZE (elf64_aarch64_howto_table) - 1; ++i) |
2340 | 0 | if (elf64_aarch64_howto_table[i].name != NULL |
2341 | 0 | && strcasecmp (elf64_aarch64_howto_table[i].name, r_name) == 0) |
2342 | 0 | return &elf64_aarch64_howto_table[i]; |
2343 | | |
2344 | 0 | return NULL; |
2345 | 0 | } |
2346 | | |
2347 | | #define TARGET_LITTLE_SYM aarch64_elf64_le_vec |
2348 | | #define TARGET_LITTLE_NAME "elf64-littleaarch64" |
2349 | | #define TARGET_BIG_SYM aarch64_elf64_be_vec |
2350 | | #define TARGET_BIG_NAME "elf64-bigaarch64" |
2351 | | |
2352 | | /* The linker script knows the section names for placement. |
2353 | | The entry_names are used to do simple name mangling on the stubs. |
2354 | | Given a function name, and its type, the stub can be found. The |
2355 | | name can be changed. The only requirement is the %s be present. */ |
2356 | 0 | #define STUB_ENTRY_NAME "__%s_veneer" |
2357 | | |
2358 | | /* Stub name for a BTI landing stub. */ |
2359 | 0 | #define BTI_STUB_ENTRY_NAME "__%s_bti_veneer" |
2360 | | |
2361 | | /* The name of the dynamic interpreter. This is put in the .interp |
2362 | | section. */ |
2363 | 0 | #define ELF_DYNAMIC_INTERPRETER "/lib/ld.so.1" |
2364 | | |
2365 | | #define AARCH64_MAX_FWD_BRANCH_OFFSET \ |
2366 | 0 | (((1 << 25) - 1) << 2) |
2367 | | #define AARCH64_MAX_BWD_BRANCH_OFFSET \ |
2368 | 0 | (-((1 << 25) << 2)) |
2369 | | |
2370 | 0 | #define AARCH64_MAX_ADRP_IMM ((1 << 20) - 1) |
2371 | 0 | #define AARCH64_MIN_ADRP_IMM (-(1 << 20)) |
2372 | | |
2373 | | static int |
2374 | | aarch64_valid_for_adrp_p (bfd_vma value, bfd_vma place) |
2375 | 0 | { |
2376 | 0 | bfd_signed_vma offset = (bfd_signed_vma) (PG (value) - PG (place)) >> 12; |
2377 | 0 | return offset <= AARCH64_MAX_ADRP_IMM && offset >= AARCH64_MIN_ADRP_IMM; |
2378 | 0 | } |
2379 | | |
2380 | | static int |
2381 | | aarch64_valid_branch_p (bfd_vma value, bfd_vma place) |
2382 | 0 | { |
2383 | 0 | bfd_signed_vma offset = (bfd_signed_vma) (value - place); |
2384 | 0 | return (offset <= AARCH64_MAX_FWD_BRANCH_OFFSET |
2385 | 0 | && offset >= AARCH64_MAX_BWD_BRANCH_OFFSET); |
2386 | 0 | } |
2387 | | |
2388 | | static const uint32_t aarch64_adrp_branch_stub [] = |
2389 | | { |
2390 | | 0x90000010, /* adrp ip0, X */ |
2391 | | /* R_AARCH64_ADR_HI21_PCREL(X) */ |
2392 | | 0x91000210, /* add ip0, ip0, :lo12:X */ |
2393 | | /* R_AARCH64_ADD_ABS_LO12_NC(X) */ |
2394 | | 0xd61f0200, /* br ip0 */ |
2395 | | }; |
2396 | | |
2397 | | static const uint32_t aarch64_long_branch_stub[] = |
2398 | | { |
2399 | | #if ARCH_SIZE == 64 |
2400 | | 0x58000090, /* ldr ip0, 1f */ |
2401 | | #else |
2402 | | 0x18000090, /* ldr wip0, 1f */ |
2403 | | #endif |
2404 | | 0x10000011, /* adr ip1, #0 */ |
2405 | | 0x8b110210, /* add ip0, ip0, ip1 */ |
2406 | | 0xd61f0200, /* br ip0 */ |
2407 | | 0x00000000, /* 1: .xword or .word |
2408 | | R_AARCH64_PREL64(X) + 12 |
2409 | | */ |
2410 | | 0x00000000, |
2411 | | }; |
2412 | | |
2413 | | static const uint32_t aarch64_bti_direct_branch_stub[] = |
2414 | | { |
2415 | | 0xd503245f, /* bti c */ |
2416 | | 0x14000000, /* b <label> */ |
2417 | | }; |
2418 | | |
2419 | | static const uint32_t aarch64_erratum_835769_stub[] = |
2420 | | { |
2421 | | 0x00000000, /* Placeholder for multiply accumulate. */ |
2422 | | 0x14000000, /* b <label> */ |
2423 | | }; |
2424 | | |
2425 | | static const uint32_t aarch64_erratum_843419_stub[] = |
2426 | | { |
2427 | | 0x00000000, /* Placeholder for LDR instruction. */ |
2428 | | 0x14000000, /* b <label> */ |
2429 | | }; |
2430 | | |
2431 | | /* Section name for stubs is the associated section name plus this |
2432 | | string. */ |
2433 | 0 | #define STUB_SUFFIX ".stub" |
2434 | | |
2435 | | enum elf_aarch64_stub_type |
2436 | | { |
2437 | | aarch64_stub_none, |
2438 | | aarch64_stub_adrp_branch, |
2439 | | aarch64_stub_long_branch, |
2440 | | aarch64_stub_bti_direct_branch, |
2441 | | aarch64_stub_erratum_835769_veneer, |
2442 | | aarch64_stub_erratum_843419_veneer, |
2443 | | }; |
2444 | | |
2445 | | struct elf_aarch64_stub_hash_entry |
2446 | | { |
2447 | | /* Base hash table entry structure. */ |
2448 | | struct bfd_hash_entry root; |
2449 | | |
2450 | | /* The stub section. */ |
2451 | | asection *stub_sec; |
2452 | | |
2453 | | /* Offset within stub_sec of the beginning of this stub. */ |
2454 | | bfd_vma stub_offset; |
2455 | | |
2456 | | /* Given the symbol's value and its section we can determine its final |
2457 | | value when building the stubs (so the stub knows where to jump). */ |
2458 | | bfd_vma target_value; |
2459 | | asection *target_section; |
2460 | | |
2461 | | enum elf_aarch64_stub_type stub_type; |
2462 | | |
2463 | | /* The symbol table entry, if any, that this was derived from. */ |
2464 | | struct elf_aarch64_link_hash_entry *h; |
2465 | | |
2466 | | /* Destination symbol type */ |
2467 | | unsigned char st_type; |
2468 | | |
2469 | | /* The target is also a stub. */ |
2470 | | bool double_stub; |
2471 | | |
2472 | | /* Where this stub is being called from, or, in the case of combined |
2473 | | stub sections, the first input section in the group. */ |
2474 | | asection *id_sec; |
2475 | | |
2476 | | /* The name for the local symbol at the start of this stub. The |
2477 | | stub name in the hash table has to be unique; this does not, so |
2478 | | it can be friendlier. */ |
2479 | | char *output_name; |
2480 | | |
2481 | | /* The instruction which caused this stub to be generated (only valid for |
2482 | | erratum 835769 workaround stubs at present). */ |
2483 | | uint32_t veneered_insn; |
2484 | | |
2485 | | /* In an erratum 843419 workaround stub, the ADRP instruction offset. */ |
2486 | | bfd_vma adrp_offset; |
2487 | | }; |
2488 | | |
2489 | | /* Used to build a map of a section. This is required for mixed-endian |
2490 | | code/data. */ |
2491 | | |
2492 | | typedef struct elf_elf_section_map |
2493 | | { |
2494 | | bfd_vma vma; |
2495 | | char type; |
2496 | | } |
2497 | | elf_aarch64_section_map; |
2498 | | |
2499 | | |
2500 | | typedef struct _aarch64_elf_section_data |
2501 | | { |
2502 | | struct bfd_elf_section_data elf; |
2503 | | unsigned int mapcount; |
2504 | | unsigned int mapsize; |
2505 | | elf_aarch64_section_map *map; |
2506 | | } |
2507 | | _aarch64_elf_section_data; |
2508 | | |
2509 | | #define elf_aarch64_section_data(sec) \ |
2510 | 0 | ((_aarch64_elf_section_data *) elf_section_data (sec)) |
2511 | | |
2512 | | /* The size of the thread control block which is defined to be two pointers. */ |
2513 | 0 | #define TCB_SIZE (ARCH_SIZE/8)*2 |
2514 | | |
2515 | | struct elf_aarch64_local_symbol |
2516 | | { |
2517 | | unsigned int got_type; |
2518 | | bfd_signed_vma got_refcount; |
2519 | | bfd_vma got_offset; |
2520 | | |
2521 | | /* Offset of the GOTPLT entry reserved for the TLS descriptor. The |
2522 | | offset is from the end of the jump table and reserved entries |
2523 | | within the PLTGOT. |
2524 | | |
2525 | | The magic value (bfd_vma) -1 indicates that an offset has not be |
2526 | | allocated. */ |
2527 | | bfd_vma tlsdesc_got_jump_table_offset; |
2528 | | }; |
2529 | | |
2530 | | struct elf_aarch64_obj_tdata |
2531 | | { |
2532 | | struct elf_obj_tdata root; |
2533 | | |
2534 | | /* local symbol descriptors */ |
2535 | | struct elf_aarch64_local_symbol *locals; |
2536 | | |
2537 | | /* Zero to warn when linking objects with incompatible enum sizes. */ |
2538 | | int no_enum_size_warning; |
2539 | | |
2540 | | /* Zero to warn when linking objects with incompatible wchar_t sizes. */ |
2541 | | int no_wchar_size_warning; |
2542 | | |
2543 | | /* All GNU_PROPERTY_AARCH64_FEATURE_1_AND properties. */ |
2544 | | uint32_t gnu_and_prop; |
2545 | | |
2546 | | /* Zero to warn when linking objects with incompatible |
2547 | | GNU_PROPERTY_AARCH64_FEATURE_1_BTI. */ |
2548 | | int no_bti_warn; |
2549 | | |
2550 | | /* PLT type based on security. */ |
2551 | | aarch64_plt_type plt_type; |
2552 | | }; |
2553 | | |
2554 | | #define elf_aarch64_tdata(bfd) \ |
2555 | 0 | ((struct elf_aarch64_obj_tdata *) (bfd)->tdata.any) |
2556 | | |
2557 | 0 | #define elf_aarch64_locals(bfd) (elf_aarch64_tdata (bfd)->locals) |
2558 | | |
2559 | | #define is_aarch64_elf(bfd) \ |
2560 | 0 | (bfd_get_flavour (bfd) == bfd_target_elf_flavour \ |
2561 | 0 | && elf_tdata (bfd) != NULL \ |
2562 | 0 | && elf_object_id (bfd) == AARCH64_ELF_DATA) |
2563 | | |
2564 | | static bool |
2565 | | elf64_aarch64_mkobject (bfd *abfd) |
2566 | 33.5k | { |
2567 | 33.5k | return bfd_elf_allocate_object (abfd, sizeof (struct elf_aarch64_obj_tdata), |
2568 | 33.5k | AARCH64_ELF_DATA); |
2569 | 33.5k | } |
2570 | | |
2571 | | #define elf_aarch64_hash_entry(ent) \ |
2572 | 0 | ((struct elf_aarch64_link_hash_entry *)(ent)) |
2573 | | |
2574 | 0 | #define GOT_UNKNOWN 0 |
2575 | 0 | #define GOT_NORMAL 1 |
2576 | 0 | #define GOT_TLS_GD 2 |
2577 | 0 | #define GOT_TLS_IE 4 |
2578 | 0 | #define GOT_TLSDESC_GD 8 |
2579 | | |
2580 | 0 | #define GOT_TLS_GD_ANY_P(type) ((type & GOT_TLS_GD) || (type & GOT_TLSDESC_GD)) |
2581 | | |
2582 | | /* AArch64 ELF linker hash entry. */ |
2583 | | struct elf_aarch64_link_hash_entry |
2584 | | { |
2585 | | struct elf_link_hash_entry root; |
2586 | | |
2587 | | /* Since PLT entries have variable size, we need to record the |
2588 | | index into .got.plt instead of recomputing it from the PLT |
2589 | | offset. */ |
2590 | | bfd_signed_vma plt_got_offset; |
2591 | | |
2592 | | /* Bit mask representing the type of GOT entry(s) if any required by |
2593 | | this symbol. */ |
2594 | | unsigned int got_type; |
2595 | | |
2596 | | /* TRUE if symbol is defined as a protected symbol. */ |
2597 | | unsigned int def_protected : 1; |
2598 | | |
2599 | | /* A pointer to the most recently used stub hash entry against this |
2600 | | symbol. */ |
2601 | | struct elf_aarch64_stub_hash_entry *stub_cache; |
2602 | | |
2603 | | /* Offset of the GOTPLT entry reserved for the TLS descriptor. The offset |
2604 | | is from the end of the jump table and reserved entries within the PLTGOT. |
2605 | | |
2606 | | The magic value (bfd_vma) -1 indicates that an offset has not |
2607 | | be allocated. */ |
2608 | | bfd_vma tlsdesc_got_jump_table_offset; |
2609 | | }; |
2610 | | |
2611 | | static unsigned int |
2612 | | elf64_aarch64_symbol_got_type (struct elf_link_hash_entry *h, |
2613 | | bfd *abfd, |
2614 | | unsigned long r_symndx) |
2615 | 0 | { |
2616 | 0 | if (h) |
2617 | 0 | return elf_aarch64_hash_entry (h)->got_type; |
2618 | | |
2619 | 0 | if (! elf_aarch64_locals (abfd)) |
2620 | 0 | return GOT_UNKNOWN; |
2621 | | |
2622 | 0 | return elf_aarch64_locals (abfd)[r_symndx].got_type; |
2623 | 0 | } |
2624 | | |
2625 | | /* Get the AArch64 elf linker hash table from a link_info structure. */ |
2626 | | #define elf_aarch64_hash_table(info) \ |
2627 | 0 | ((struct elf_aarch64_link_hash_table *) ((info)->hash)) |
2628 | | |
2629 | | #define aarch64_stub_hash_lookup(table, string, create, copy) \ |
2630 | 0 | ((struct elf_aarch64_stub_hash_entry *) \ |
2631 | 0 | bfd_hash_lookup ((table), (string), (create), (copy))) |
2632 | | |
2633 | | /* AArch64 ELF linker hash table. */ |
2634 | | struct elf_aarch64_link_hash_table |
2635 | | { |
2636 | | /* The main hash table. */ |
2637 | | struct elf_link_hash_table root; |
2638 | | |
2639 | | /* Nonzero to force PIC branch veneers. */ |
2640 | | int pic_veneer; |
2641 | | |
2642 | | /* Fix erratum 835769. */ |
2643 | | int fix_erratum_835769; |
2644 | | |
2645 | | /* Fix erratum 843419. */ |
2646 | | erratum_84319_opts fix_erratum_843419; |
2647 | | |
2648 | | /* Don't apply link-time values for dynamic relocations. */ |
2649 | | int no_apply_dynamic_relocs; |
2650 | | |
2651 | | /* The number of bytes in the initial entry in the PLT. */ |
2652 | | bfd_size_type plt_header_size; |
2653 | | |
2654 | | /* The bytes of the initial PLT entry. */ |
2655 | | const bfd_byte *plt0_entry; |
2656 | | |
2657 | | /* The number of bytes in the subsequent PLT entries. */ |
2658 | | bfd_size_type plt_entry_size; |
2659 | | |
2660 | | /* The bytes of the subsequent PLT entry. */ |
2661 | | const bfd_byte *plt_entry; |
2662 | | |
2663 | | /* For convenience in allocate_dynrelocs. */ |
2664 | | bfd *obfd; |
2665 | | |
2666 | | /* The amount of space used by the reserved portion of the sgotplt |
2667 | | section, plus whatever space is used by the jump slots. */ |
2668 | | bfd_vma sgotplt_jump_table_size; |
2669 | | |
2670 | | /* The stub hash table. */ |
2671 | | struct bfd_hash_table stub_hash_table; |
2672 | | |
2673 | | /* Linker stub bfd. */ |
2674 | | bfd *stub_bfd; |
2675 | | |
2676 | | /* Linker call-backs. */ |
2677 | | asection *(*add_stub_section) (const char *, asection *); |
2678 | | void (*layout_sections_again) (void); |
2679 | | |
2680 | | /* Array to keep track of which stub sections have been created, and |
2681 | | information on stub grouping. */ |
2682 | | struct map_stub |
2683 | | { |
2684 | | /* This is the section to which stubs in the group will be |
2685 | | attached. */ |
2686 | | asection *link_sec; |
2687 | | /* The stub section. */ |
2688 | | asection *stub_sec; |
2689 | | } *stub_group; |
2690 | | |
2691 | | /* Assorted information used by elf64_aarch64_size_stubs. */ |
2692 | | unsigned int bfd_count; |
2693 | | unsigned int top_index; |
2694 | | asection **input_list; |
2695 | | |
2696 | | /* True when two stubs are added where one targets the other, happens |
2697 | | when BTI stubs are inserted and then the stub layout must not change |
2698 | | during elf64_aarch64_build_stubs. */ |
2699 | | bool has_double_stub; |
2700 | | |
2701 | | /* JUMP_SLOT relocs for variant PCS symbols may be present. */ |
2702 | | int variant_pcs; |
2703 | | |
2704 | | /* The number of bytes in the PLT enty for the TLS descriptor. */ |
2705 | | bfd_size_type tlsdesc_plt_entry_size; |
2706 | | |
2707 | | /* Used by local STT_GNU_IFUNC symbols. */ |
2708 | | htab_t loc_hash_table; |
2709 | | void * loc_hash_memory; |
2710 | | }; |
2711 | | |
2712 | | /* Create an entry in an AArch64 ELF linker hash table. */ |
2713 | | |
2714 | | static struct bfd_hash_entry * |
2715 | | elf64_aarch64_link_hash_newfunc (struct bfd_hash_entry *entry, |
2716 | | struct bfd_hash_table *table, |
2717 | | const char *string) |
2718 | 0 | { |
2719 | 0 | struct elf_aarch64_link_hash_entry *ret = |
2720 | 0 | (struct elf_aarch64_link_hash_entry *) entry; |
2721 | | |
2722 | | /* Allocate the structure if it has not already been allocated by a |
2723 | | subclass. */ |
2724 | 0 | if (ret == NULL) |
2725 | 0 | ret = bfd_hash_allocate (table, |
2726 | 0 | sizeof (struct elf_aarch64_link_hash_entry)); |
2727 | 0 | if (ret == NULL) |
2728 | 0 | return (struct bfd_hash_entry *) ret; |
2729 | | |
2730 | | /* Call the allocation method of the superclass. */ |
2731 | 0 | ret = ((struct elf_aarch64_link_hash_entry *) |
2732 | 0 | _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry *) ret, |
2733 | 0 | table, string)); |
2734 | 0 | if (ret != NULL) |
2735 | 0 | { |
2736 | 0 | ret->got_type = GOT_UNKNOWN; |
2737 | 0 | ret->def_protected = 0; |
2738 | 0 | ret->plt_got_offset = (bfd_vma) - 1; |
2739 | 0 | ret->stub_cache = NULL; |
2740 | 0 | ret->tlsdesc_got_jump_table_offset = (bfd_vma) - 1; |
2741 | 0 | } |
2742 | |
|
2743 | 0 | return (struct bfd_hash_entry *) ret; |
2744 | 0 | } |
2745 | | |
2746 | | /* Initialize an entry in the stub hash table. */ |
2747 | | |
2748 | | static struct bfd_hash_entry * |
2749 | | stub_hash_newfunc (struct bfd_hash_entry *entry, |
2750 | | struct bfd_hash_table *table, const char *string) |
2751 | 0 | { |
2752 | | /* Allocate the structure if it has not already been allocated by a |
2753 | | subclass. */ |
2754 | 0 | if (entry == NULL) |
2755 | 0 | { |
2756 | 0 | entry = bfd_hash_allocate (table, |
2757 | 0 | sizeof (struct |
2758 | 0 | elf_aarch64_stub_hash_entry)); |
2759 | 0 | if (entry == NULL) |
2760 | 0 | return entry; |
2761 | 0 | } |
2762 | | |
2763 | | /* Call the allocation method of the superclass. */ |
2764 | 0 | entry = bfd_hash_newfunc (entry, table, string); |
2765 | 0 | if (entry != NULL) |
2766 | 0 | { |
2767 | 0 | struct elf_aarch64_stub_hash_entry *eh; |
2768 | | |
2769 | | /* Initialize the local fields. */ |
2770 | 0 | eh = (struct elf_aarch64_stub_hash_entry *) entry; |
2771 | 0 | memset (&eh->stub_sec, 0, |
2772 | 0 | (sizeof (struct elf_aarch64_stub_hash_entry) |
2773 | 0 | - offsetof (struct elf_aarch64_stub_hash_entry, stub_sec))); |
2774 | 0 | } |
2775 | |
|
2776 | 0 | return entry; |
2777 | 0 | } |
2778 | | |
2779 | | /* Compute a hash of a local hash entry. We use elf_link_hash_entry |
2780 | | for local symbol so that we can handle local STT_GNU_IFUNC symbols |
2781 | | as global symbol. We reuse indx and dynstr_index for local symbol |
2782 | | hash since they aren't used by global symbols in this backend. */ |
2783 | | |
2784 | | static hashval_t |
2785 | | elf64_aarch64_local_htab_hash (const void *ptr) |
2786 | 0 | { |
2787 | 0 | struct elf_link_hash_entry *h |
2788 | 0 | = (struct elf_link_hash_entry *) ptr; |
2789 | 0 | return ELF_LOCAL_SYMBOL_HASH (h->indx, h->dynstr_index); |
2790 | 0 | } |
2791 | | |
2792 | | /* Compare local hash entries. */ |
2793 | | |
2794 | | static int |
2795 | | elf64_aarch64_local_htab_eq (const void *ptr1, const void *ptr2) |
2796 | 0 | { |
2797 | 0 | struct elf_link_hash_entry *h1 |
2798 | 0 | = (struct elf_link_hash_entry *) ptr1; |
2799 | 0 | struct elf_link_hash_entry *h2 |
2800 | 0 | = (struct elf_link_hash_entry *) ptr2; |
2801 | |
|
2802 | 0 | return h1->indx == h2->indx && h1->dynstr_index == h2->dynstr_index; |
2803 | 0 | } |
2804 | | |
2805 | | /* Find and/or create a hash entry for local symbol. */ |
2806 | | |
2807 | | static struct elf_link_hash_entry * |
2808 | | elf64_aarch64_get_local_sym_hash (struct elf_aarch64_link_hash_table *htab, |
2809 | | bfd *abfd, const Elf_Internal_Rela *rel, |
2810 | | bool create) |
2811 | 0 | { |
2812 | 0 | struct elf_aarch64_link_hash_entry e, *ret; |
2813 | 0 | asection *sec = abfd->sections; |
2814 | 0 | hashval_t h = ELF_LOCAL_SYMBOL_HASH (sec->id, |
2815 | 0 | ELF64_R_SYM (rel->r_info)); |
2816 | 0 | void **slot; |
2817 | |
|
2818 | 0 | e.root.indx = sec->id; |
2819 | 0 | e.root.dynstr_index = ELF64_R_SYM (rel->r_info); |
2820 | 0 | slot = htab_find_slot_with_hash (htab->loc_hash_table, &e, h, |
2821 | 0 | create ? INSERT : NO_INSERT); |
2822 | |
|
2823 | 0 | if (!slot) |
2824 | 0 | return NULL; |
2825 | | |
2826 | 0 | if (*slot) |
2827 | 0 | { |
2828 | 0 | ret = (struct elf_aarch64_link_hash_entry *) *slot; |
2829 | 0 | return &ret->root; |
2830 | 0 | } |
2831 | | |
2832 | 0 | ret = (struct elf_aarch64_link_hash_entry *) |
2833 | 0 | objalloc_alloc ((struct objalloc *) htab->loc_hash_memory, |
2834 | 0 | sizeof (struct elf_aarch64_link_hash_entry)); |
2835 | 0 | if (ret) |
2836 | 0 | { |
2837 | 0 | memset (ret, 0, sizeof (*ret)); |
2838 | 0 | ret->root.indx = sec->id; |
2839 | 0 | ret->root.dynstr_index = ELF64_R_SYM (rel->r_info); |
2840 | 0 | ret->root.dynindx = -1; |
2841 | 0 | *slot = ret; |
2842 | 0 | } |
2843 | 0 | return &ret->root; |
2844 | 0 | } |
2845 | | |
2846 | | /* Copy the extra info we tack onto an elf_link_hash_entry. */ |
2847 | | |
2848 | | static void |
2849 | | elf64_aarch64_copy_indirect_symbol (struct bfd_link_info *info, |
2850 | | struct elf_link_hash_entry *dir, |
2851 | | struct elf_link_hash_entry *ind) |
2852 | 0 | { |
2853 | 0 | struct elf_aarch64_link_hash_entry *edir, *eind; |
2854 | |
|
2855 | 0 | edir = (struct elf_aarch64_link_hash_entry *) dir; |
2856 | 0 | eind = (struct elf_aarch64_link_hash_entry *) ind; |
2857 | |
|
2858 | 0 | if (ind->root.type == bfd_link_hash_indirect) |
2859 | 0 | { |
2860 | | /* Copy over PLT info. */ |
2861 | 0 | if (dir->got.refcount <= 0) |
2862 | 0 | { |
2863 | 0 | edir->got_type = eind->got_type; |
2864 | 0 | eind->got_type = GOT_UNKNOWN; |
2865 | 0 | } |
2866 | 0 | } |
2867 | |
|
2868 | 0 | _bfd_elf_link_hash_copy_indirect (info, dir, ind); |
2869 | 0 | } |
2870 | | |
2871 | | /* Merge non-visibility st_other attributes. */ |
2872 | | |
2873 | | static void |
2874 | | elf64_aarch64_merge_symbol_attribute (struct elf_link_hash_entry *h, |
2875 | | unsigned int st_other, |
2876 | | bool definition, |
2877 | | bool dynamic ATTRIBUTE_UNUSED) |
2878 | 0 | { |
2879 | 0 | if (definition) |
2880 | 0 | { |
2881 | 0 | struct elf_aarch64_link_hash_entry *eh |
2882 | 0 | = (struct elf_aarch64_link_hash_entry *)h; |
2883 | 0 | eh->def_protected = ELF_ST_VISIBILITY (st_other) == STV_PROTECTED; |
2884 | 0 | } |
2885 | |
|
2886 | 0 | unsigned int isym_sto = st_other & ~ELF_ST_VISIBILITY (-1); |
2887 | 0 | unsigned int h_sto = h->other & ~ELF_ST_VISIBILITY (-1); |
2888 | |
|
2889 | 0 | if (isym_sto == h_sto) |
2890 | 0 | return; |
2891 | | |
2892 | 0 | if (isym_sto & ~STO_AARCH64_VARIANT_PCS) |
2893 | | /* Not fatal, this callback cannot fail. */ |
2894 | 0 | _bfd_error_handler (_("unknown attribute for symbol `%s': 0x%02x"), |
2895 | 0 | h->root.root.string, isym_sto); |
2896 | | |
2897 | | /* Note: Ideally we would warn about any attribute mismatch, but |
2898 | | this api does not allow that without substantial changes. */ |
2899 | 0 | if (isym_sto & STO_AARCH64_VARIANT_PCS) |
2900 | 0 | h->other |= STO_AARCH64_VARIANT_PCS; |
2901 | 0 | } |
2902 | | |
2903 | | /* Destroy an AArch64 elf linker hash table. */ |
2904 | | |
2905 | | static void |
2906 | | elf64_aarch64_link_hash_table_free (bfd *obfd) |
2907 | 0 | { |
2908 | 0 | struct elf_aarch64_link_hash_table *ret |
2909 | 0 | = (struct elf_aarch64_link_hash_table *) obfd->link.hash; |
2910 | |
|
2911 | 0 | if (ret->loc_hash_table) |
2912 | 0 | htab_delete (ret->loc_hash_table); |
2913 | 0 | if (ret->loc_hash_memory) |
2914 | 0 | objalloc_free ((struct objalloc *) ret->loc_hash_memory); |
2915 | |
|
2916 | 0 | bfd_hash_table_free (&ret->stub_hash_table); |
2917 | 0 | _bfd_elf_link_hash_table_free (obfd); |
2918 | 0 | } |
2919 | | |
2920 | | /* Create an AArch64 elf linker hash table. */ |
2921 | | |
2922 | | static struct bfd_link_hash_table * |
2923 | | elf64_aarch64_link_hash_table_create (bfd *abfd) |
2924 | 0 | { |
2925 | 0 | struct elf_aarch64_link_hash_table *ret; |
2926 | 0 | size_t amt = sizeof (struct elf_aarch64_link_hash_table); |
2927 | |
|
2928 | 0 | ret = bfd_zmalloc (amt); |
2929 | 0 | if (ret == NULL) |
2930 | 0 | return NULL; |
2931 | | |
2932 | 0 | if (!_bfd_elf_link_hash_table_init |
2933 | 0 | (&ret->root, abfd, elf64_aarch64_link_hash_newfunc, |
2934 | 0 | sizeof (struct elf_aarch64_link_hash_entry), AARCH64_ELF_DATA)) |
2935 | 0 | { |
2936 | 0 | free (ret); |
2937 | 0 | return NULL; |
2938 | 0 | } |
2939 | | |
2940 | 0 | ret->plt_header_size = PLT_ENTRY_SIZE; |
2941 | 0 | ret->plt0_entry = elf64_aarch64_small_plt0_entry; |
2942 | 0 | ret->plt_entry_size = PLT_SMALL_ENTRY_SIZE; |
2943 | 0 | ret->plt_entry = elf64_aarch64_small_plt_entry; |
2944 | 0 | ret->tlsdesc_plt_entry_size = PLT_TLSDESC_ENTRY_SIZE; |
2945 | 0 | ret->obfd = abfd; |
2946 | 0 | ret->root.tlsdesc_got = (bfd_vma) - 1; |
2947 | |
|
2948 | 0 | if (!bfd_hash_table_init (&ret->stub_hash_table, stub_hash_newfunc, |
2949 | 0 | sizeof (struct elf_aarch64_stub_hash_entry))) |
2950 | 0 | { |
2951 | 0 | _bfd_elf_link_hash_table_free (abfd); |
2952 | 0 | return NULL; |
2953 | 0 | } |
2954 | | |
2955 | 0 | ret->loc_hash_table = htab_try_create (1024, |
2956 | 0 | elf64_aarch64_local_htab_hash, |
2957 | 0 | elf64_aarch64_local_htab_eq, |
2958 | 0 | NULL); |
2959 | 0 | ret->loc_hash_memory = objalloc_create (); |
2960 | 0 | if (!ret->loc_hash_table || !ret->loc_hash_memory) |
2961 | 0 | { |
2962 | 0 | elf64_aarch64_link_hash_table_free (abfd); |
2963 | 0 | return NULL; |
2964 | 0 | } |
2965 | 0 | ret->root.root.hash_table_free = elf64_aarch64_link_hash_table_free; |
2966 | |
|
2967 | 0 | return &ret->root.root; |
2968 | 0 | } |
2969 | | |
2970 | | /* Perform relocation R_TYPE. Returns TRUE upon success, FALSE otherwise. */ |
2971 | | |
2972 | | static bool |
2973 | | aarch64_relocate (unsigned int r_type, bfd *input_bfd, asection *input_section, |
2974 | | bfd_vma offset, bfd_vma value) |
2975 | 0 | { |
2976 | 0 | reloc_howto_type *howto; |
2977 | 0 | bfd_vma place; |
2978 | |
|
2979 | 0 | howto = elf64_aarch64_howto_from_type (input_bfd, r_type); |
2980 | 0 | place = (input_section->output_section->vma + input_section->output_offset |
2981 | 0 | + offset); |
2982 | |
|
2983 | 0 | r_type = elf64_aarch64_bfd_reloc_from_type (input_bfd, r_type); |
2984 | 0 | value = _bfd_aarch64_elf_resolve_relocation (input_bfd, r_type, place, |
2985 | 0 | value, 0, false); |
2986 | 0 | return _bfd_aarch64_elf_put_addend (input_bfd, |
2987 | 0 | input_section->contents + offset, r_type, |
2988 | 0 | howto, value) == bfd_reloc_ok; |
2989 | 0 | } |
2990 | | |
2991 | | /* Determine the type of stub needed, if any, for a call. */ |
2992 | | |
2993 | | static enum elf_aarch64_stub_type |
2994 | | aarch64_type_of_stub (asection *input_sec, |
2995 | | const Elf_Internal_Rela *rel, |
2996 | | asection *sym_sec, |
2997 | | unsigned char st_type, |
2998 | | bfd_vma destination) |
2999 | 0 | { |
3000 | 0 | bfd_vma location; |
3001 | 0 | bfd_signed_vma branch_offset; |
3002 | 0 | unsigned int r_type; |
3003 | 0 | enum elf_aarch64_stub_type stub_type = aarch64_stub_none; |
3004 | |
|
3005 | 0 | if (st_type != STT_FUNC |
3006 | 0 | && (sym_sec == input_sec)) |
3007 | 0 | return stub_type; |
3008 | | |
3009 | | /* Determine where the call point is. */ |
3010 | 0 | location = (input_sec->output_offset |
3011 | 0 | + input_sec->output_section->vma + rel->r_offset); |
3012 | |
|
3013 | 0 | branch_offset = (bfd_signed_vma) (destination - location); |
3014 | |
|
3015 | 0 | r_type = ELF64_R_TYPE (rel->r_info); |
3016 | | |
3017 | | /* We don't want to redirect any old unconditional jump in this way, |
3018 | | only one which is being used for a sibcall, where it is |
3019 | | acceptable for the IP0 and IP1 registers to be clobbered. */ |
3020 | 0 | if ((r_type == AARCH64_R (CALL26) || r_type == AARCH64_R (JUMP26)) |
3021 | 0 | && (branch_offset > AARCH64_MAX_FWD_BRANCH_OFFSET |
3022 | 0 | || branch_offset < AARCH64_MAX_BWD_BRANCH_OFFSET)) |
3023 | 0 | { |
3024 | 0 | stub_type = aarch64_stub_long_branch; |
3025 | 0 | } |
3026 | |
|
3027 | 0 | return stub_type; |
3028 | 0 | } |
3029 | | |
3030 | | /* Build a name for an entry in the stub hash table. */ |
3031 | | |
3032 | | static char * |
3033 | | elf64_aarch64_stub_name (const asection *input_section, |
3034 | | const asection *sym_sec, |
3035 | | const struct elf_aarch64_link_hash_entry *hash, |
3036 | | const Elf_Internal_Rela *rel) |
3037 | 0 | { |
3038 | 0 | char *stub_name; |
3039 | 0 | bfd_size_type len; |
3040 | |
|
3041 | 0 | if (hash) |
3042 | 0 | { |
3043 | 0 | len = 8 + 1 + strlen (hash->root.root.root.string) + 1 + 16 + 1; |
3044 | 0 | stub_name = bfd_malloc (len); |
3045 | 0 | if (stub_name != NULL) |
3046 | 0 | snprintf (stub_name, len, "%08x_%s+%" PRIx64, |
3047 | 0 | (unsigned int) input_section->id, |
3048 | 0 | hash->root.root.root.string, |
3049 | 0 | (uint64_t) rel->r_addend); |
3050 | 0 | } |
3051 | 0 | else |
3052 | 0 | { |
3053 | 0 | len = 8 + 1 + 8 + 1 + 8 + 1 + 16 + 1; |
3054 | 0 | stub_name = bfd_malloc (len); |
3055 | 0 | if (stub_name != NULL) |
3056 | 0 | snprintf (stub_name, len, "%08x_%x:%x+%" PRIx64, |
3057 | 0 | (unsigned int) input_section->id, |
3058 | 0 | (unsigned int) sym_sec->id, |
3059 | 0 | (unsigned int) ELF64_R_SYM (rel->r_info), |
3060 | 0 | (uint64_t) rel->r_addend); |
3061 | 0 | } |
3062 | |
|
3063 | 0 | return stub_name; |
3064 | 0 | } |
3065 | | |
3066 | | /* Return TRUE if symbol H should be hashed in the `.gnu.hash' section. For |
3067 | | executable PLT slots where the executable never takes the address of those |
3068 | | functions, the function symbols are not added to the hash table. */ |
3069 | | |
3070 | | static bool |
3071 | | elf_aarch64_hash_symbol (struct elf_link_hash_entry *h) |
3072 | 0 | { |
3073 | 0 | if (h->plt.offset != (bfd_vma) -1 |
3074 | 0 | && !h->def_regular |
3075 | 0 | && !h->pointer_equality_needed) |
3076 | 0 | return false; |
3077 | | |
3078 | 0 | return _bfd_elf_hash_symbol (h); |
3079 | 0 | } |
3080 | | |
3081 | | |
3082 | | /* Look up an entry in the stub hash. Stub entries are cached because |
3083 | | creating the stub name takes a bit of time. */ |
3084 | | |
3085 | | static struct elf_aarch64_stub_hash_entry * |
3086 | | elf64_aarch64_get_stub_entry (const asection *input_section, |
3087 | | const asection *sym_sec, |
3088 | | struct elf_link_hash_entry *hash, |
3089 | | const Elf_Internal_Rela *rel, |
3090 | | struct elf_aarch64_link_hash_table *htab) |
3091 | 0 | { |
3092 | 0 | struct elf_aarch64_stub_hash_entry *stub_entry; |
3093 | 0 | struct elf_aarch64_link_hash_entry *h = |
3094 | 0 | (struct elf_aarch64_link_hash_entry *) hash; |
3095 | 0 | const asection *id_sec; |
3096 | |
|
3097 | 0 | if ((input_section->flags & SEC_CODE) == 0) |
3098 | 0 | return NULL; |
3099 | | |
3100 | | /* If this input section is part of a group of sections sharing one |
3101 | | stub section, then use the id of the first section in the group. |
3102 | | Stub names need to include a section id, as there may well be |
3103 | | more than one stub used to reach say, printf, and we need to |
3104 | | distinguish between them. */ |
3105 | 0 | id_sec = htab->stub_group[input_section->id].link_sec; |
3106 | |
|
3107 | 0 | if (h != NULL && h->stub_cache != NULL |
3108 | 0 | && h->stub_cache->h == h && h->stub_cache->id_sec == id_sec) |
3109 | 0 | { |
3110 | 0 | stub_entry = h->stub_cache; |
3111 | 0 | } |
3112 | 0 | else |
3113 | 0 | { |
3114 | 0 | char *stub_name; |
3115 | |
|
3116 | 0 | stub_name = elf64_aarch64_stub_name (id_sec, sym_sec, h, rel); |
3117 | 0 | if (stub_name == NULL) |
3118 | 0 | return NULL; |
3119 | | |
3120 | 0 | stub_entry = aarch64_stub_hash_lookup (&htab->stub_hash_table, |
3121 | 0 | stub_name, false, false); |
3122 | 0 | if (h != NULL) |
3123 | 0 | h->stub_cache = stub_entry; |
3124 | |
|
3125 | 0 | free (stub_name); |
3126 | 0 | } |
3127 | | |
3128 | 0 | return stub_entry; |
3129 | 0 | } |
3130 | | |
3131 | | |
3132 | | /* Create a stub section. */ |
3133 | | |
3134 | | static asection * |
3135 | | _bfd_aarch64_create_stub_section (asection *section, |
3136 | | struct elf_aarch64_link_hash_table *htab) |
3137 | 0 | { |
3138 | 0 | size_t namelen; |
3139 | 0 | bfd_size_type len; |
3140 | 0 | char *s_name; |
3141 | |
|
3142 | 0 | namelen = strlen (section->name); |
3143 | 0 | len = namelen + sizeof (STUB_SUFFIX); |
3144 | 0 | s_name = bfd_alloc (htab->stub_bfd, len); |
3145 | 0 | if (s_name == NULL) |
3146 | 0 | return NULL; |
3147 | | |
3148 | 0 | memcpy (s_name, section->name, namelen); |
3149 | 0 | memcpy (s_name + namelen, STUB_SUFFIX, sizeof (STUB_SUFFIX)); |
3150 | 0 | return (*htab->add_stub_section) (s_name, section); |
3151 | 0 | } |
3152 | | |
3153 | | |
3154 | | /* Find or create a stub section for a link section. |
3155 | | |
3156 | | Fix or create the stub section used to collect stubs attached to |
3157 | | the specified link section. */ |
3158 | | |
3159 | | static asection * |
3160 | | _bfd_aarch64_get_stub_for_link_section (asection *link_section, |
3161 | | struct elf_aarch64_link_hash_table *htab) |
3162 | 0 | { |
3163 | 0 | if (htab->stub_group[link_section->id].stub_sec == NULL) |
3164 | 0 | htab->stub_group[link_section->id].stub_sec |
3165 | 0 | = _bfd_aarch64_create_stub_section (link_section, htab); |
3166 | 0 | return htab->stub_group[link_section->id].stub_sec; |
3167 | 0 | } |
3168 | | |
3169 | | |
3170 | | /* Find or create a stub section in the stub group for an input |
3171 | | section. */ |
3172 | | |
3173 | | static asection * |
3174 | | _bfd_aarch64_create_or_find_stub_sec (asection *section, |
3175 | | struct elf_aarch64_link_hash_table *htab) |
3176 | 0 | { |
3177 | 0 | asection *link_sec = htab->stub_group[section->id].link_sec; |
3178 | 0 | return _bfd_aarch64_get_stub_for_link_section (link_sec, htab); |
3179 | 0 | } |
3180 | | |
3181 | | |
3182 | | /* Add a new stub entry in the stub group associated with an input |
3183 | | section to the stub hash. Not all fields of the new stub entry are |
3184 | | initialised. */ |
3185 | | |
3186 | | static struct elf_aarch64_stub_hash_entry * |
3187 | | _bfd_aarch64_add_stub_entry_in_group (const char *stub_name, |
3188 | | asection *section, |
3189 | | struct elf_aarch64_link_hash_table *htab) |
3190 | 0 | { |
3191 | 0 | asection *link_sec; |
3192 | 0 | asection *stub_sec; |
3193 | 0 | struct elf_aarch64_stub_hash_entry *stub_entry; |
3194 | |
|
3195 | 0 | link_sec = htab->stub_group[section->id].link_sec; |
3196 | 0 | stub_sec = _bfd_aarch64_create_or_find_stub_sec (section, htab); |
3197 | | |
3198 | | /* Enter this entry into the linker stub hash table. */ |
3199 | 0 | stub_entry = aarch64_stub_hash_lookup (&htab->stub_hash_table, stub_name, |
3200 | 0 | true, false); |
3201 | 0 | if (stub_entry == NULL) |
3202 | 0 | { |
3203 | | /* xgettext:c-format */ |
3204 | 0 | _bfd_error_handler (_("%pB: cannot create stub entry %s"), |
3205 | 0 | section->owner, stub_name); |
3206 | 0 | return NULL; |
3207 | 0 | } |
3208 | | |
3209 | 0 | stub_entry->stub_sec = stub_sec; |
3210 | 0 | stub_entry->stub_offset = 0; |
3211 | 0 | stub_entry->id_sec = link_sec; |
3212 | |
|
3213 | 0 | return stub_entry; |
3214 | 0 | } |
3215 | | |
3216 | | /* Add a new stub entry in the final stub section to the stub hash. |
3217 | | Not all fields of the new stub entry are initialised. */ |
3218 | | |
3219 | | static struct elf_aarch64_stub_hash_entry * |
3220 | | _bfd_aarch64_add_stub_entry_after (const char *stub_name, |
3221 | | asection *link_section, |
3222 | | struct elf_aarch64_link_hash_table *htab) |
3223 | 0 | { |
3224 | 0 | asection *stub_sec; |
3225 | 0 | struct elf_aarch64_stub_hash_entry *stub_entry; |
3226 | |
|
3227 | 0 | stub_sec = NULL; |
3228 | | /* Only create the actual stub if we will end up needing it. */ |
3229 | 0 | if (htab->fix_erratum_843419 & ERRAT_ADRP) |
3230 | 0 | stub_sec = _bfd_aarch64_get_stub_for_link_section (link_section, htab); |
3231 | 0 | stub_entry = aarch64_stub_hash_lookup (&htab->stub_hash_table, stub_name, |
3232 | 0 | true, false); |
3233 | 0 | if (stub_entry == NULL) |
3234 | 0 | { |
3235 | 0 | _bfd_error_handler (_("cannot create stub entry %s"), stub_name); |
3236 | 0 | return NULL; |
3237 | 0 | } |
3238 | | |
3239 | 0 | stub_entry->stub_sec = stub_sec; |
3240 | 0 | stub_entry->stub_offset = 0; |
3241 | 0 | stub_entry->id_sec = link_section; |
3242 | |
|
3243 | 0 | return stub_entry; |
3244 | 0 | } |
3245 | | |
3246 | | |
3247 | | static bool |
3248 | | aarch64_build_one_stub (struct bfd_hash_entry *gen_entry, |
3249 | | void *in_arg) |
3250 | 0 | { |
3251 | 0 | struct elf_aarch64_stub_hash_entry *stub_entry; |
3252 | 0 | asection *stub_sec; |
3253 | 0 | bfd *stub_bfd; |
3254 | 0 | bfd_byte *loc; |
3255 | 0 | bfd_vma sym_value; |
3256 | 0 | bfd_vma veneered_insn_loc; |
3257 | 0 | bfd_vma veneer_entry_loc; |
3258 | 0 | bfd_signed_vma branch_offset = 0; |
3259 | 0 | unsigned int template_size; |
3260 | 0 | unsigned int pad_size = 0; |
3261 | 0 | const uint32_t *template; |
3262 | 0 | unsigned int i; |
3263 | 0 | struct bfd_link_info *info; |
3264 | 0 | struct elf_aarch64_link_hash_table *htab; |
3265 | | |
3266 | | /* Massage our args to the form they really have. */ |
3267 | 0 | stub_entry = (struct elf_aarch64_stub_hash_entry *) gen_entry; |
3268 | |
|
3269 | 0 | info = (struct bfd_link_info *) in_arg; |
3270 | 0 | htab = elf_aarch64_hash_table (info); |
3271 | | |
3272 | | /* Fail if the target section could not be assigned to an output |
3273 | | section. The user should fix his linker script. */ |
3274 | 0 | if (stub_entry->target_section->output_section == NULL |
3275 | 0 | && info->non_contiguous_regions) |
3276 | 0 | info->callbacks->einfo (_("%F%P: Could not assign `%pA' to an output section. " |
3277 | 0 | "Retry without " |
3278 | 0 | "--enable-non-contiguous-regions.\n"), |
3279 | 0 | stub_entry->target_section); |
3280 | |
|
3281 | 0 | stub_sec = stub_entry->stub_sec; |
3282 | | |
3283 | | /* The layout must not change when a stub may be the target of another. */ |
3284 | 0 | if (htab->has_double_stub) |
3285 | 0 | BFD_ASSERT (stub_entry->stub_offset == stub_sec->size); |
3286 | | |
3287 | | /* Make a note of the offset within the stubs for this entry. */ |
3288 | 0 | stub_entry->stub_offset = stub_sec->size; |
3289 | 0 | loc = stub_sec->contents + stub_entry->stub_offset; |
3290 | |
|
3291 | 0 | stub_bfd = stub_sec->owner; |
3292 | | |
3293 | | /* This is the address of the stub destination. */ |
3294 | 0 | sym_value = (stub_entry->target_value |
3295 | 0 | + stub_entry->target_section->output_offset |
3296 | 0 | + stub_entry->target_section->output_section->vma); |
3297 | |
|
3298 | 0 | if (stub_entry->stub_type == aarch64_stub_long_branch) |
3299 | 0 | { |
3300 | 0 | bfd_vma place = (stub_entry->stub_offset + stub_sec->output_section->vma |
3301 | 0 | + stub_sec->output_offset); |
3302 | | |
3303 | | /* See if we can relax the stub. */ |
3304 | 0 | if (aarch64_valid_for_adrp_p (sym_value, place)) |
3305 | 0 | { |
3306 | 0 | stub_entry->stub_type = aarch64_stub_adrp_branch; |
3307 | | |
3308 | | /* Avoid the relaxation changing the layout. */ |
3309 | 0 | if (htab->has_double_stub) |
3310 | 0 | pad_size = sizeof (aarch64_long_branch_stub) |
3311 | 0 | - sizeof (aarch64_adrp_branch_stub); |
3312 | 0 | } |
3313 | 0 | } |
3314 | |
|
3315 | 0 | switch (stub_entry->stub_type) |
3316 | 0 | { |
3317 | 0 | case aarch64_stub_adrp_branch: |
3318 | 0 | template = aarch64_adrp_branch_stub; |
3319 | 0 | template_size = sizeof (aarch64_adrp_branch_stub); |
3320 | 0 | break; |
3321 | 0 | case aarch64_stub_long_branch: |
3322 | 0 | template = aarch64_long_branch_stub; |
3323 | 0 | template_size = sizeof (aarch64_long_branch_stub); |
3324 | 0 | break; |
3325 | 0 | case aarch64_stub_bti_direct_branch: |
3326 | 0 | template = aarch64_bti_direct_branch_stub; |
3327 | 0 | template_size = sizeof (aarch64_bti_direct_branch_stub); |
3328 | 0 | break; |
3329 | 0 | case aarch64_stub_erratum_835769_veneer: |
3330 | 0 | template = aarch64_erratum_835769_stub; |
3331 | 0 | template_size = sizeof (aarch64_erratum_835769_stub); |
3332 | 0 | break; |
3333 | 0 | case aarch64_stub_erratum_843419_veneer: |
3334 | 0 | template = aarch64_erratum_843419_stub; |
3335 | 0 | template_size = sizeof (aarch64_erratum_843419_stub); |
3336 | 0 | break; |
3337 | 0 | default: |
3338 | 0 | abort (); |
3339 | 0 | } |
3340 | | |
3341 | 0 | for (i = 0; i < (template_size / sizeof template[0]); i++) |
3342 | 0 | { |
3343 | 0 | bfd_putl32 (template[i], loc); |
3344 | 0 | loc += 4; |
3345 | 0 | } |
3346 | |
|
3347 | 0 | template_size += pad_size; |
3348 | 0 | template_size = (template_size + 7) & ~7; |
3349 | 0 | stub_sec->size += template_size; |
3350 | |
|
3351 | 0 | switch (stub_entry->stub_type) |
3352 | 0 | { |
3353 | 0 | case aarch64_stub_adrp_branch: |
3354 | 0 | if (!aarch64_relocate (AARCH64_R (ADR_PREL_PG_HI21), stub_bfd, stub_sec, |
3355 | 0 | stub_entry->stub_offset, sym_value)) |
3356 | | /* The stub would not have been relaxed if the offset was out |
3357 | | of range. */ |
3358 | 0 | BFD_FAIL (); |
3359 | |
|
3360 | 0 | if (!aarch64_relocate (AARCH64_R (ADD_ABS_LO12_NC), stub_bfd, stub_sec, |
3361 | 0 | stub_entry->stub_offset + 4, sym_value)) |
3362 | 0 | BFD_FAIL (); |
3363 | 0 | break; |
3364 | | |
3365 | 0 | case aarch64_stub_long_branch: |
3366 | | /* We want the value relative to the address 12 bytes back from the |
3367 | | value itself. */ |
3368 | 0 | if (!aarch64_relocate (AARCH64_R (PREL64), stub_bfd, stub_sec, |
3369 | 0 | stub_entry->stub_offset + 16, sym_value + 12)) |
3370 | 0 | BFD_FAIL (); |
3371 | 0 | break; |
3372 | | |
3373 | 0 | case aarch64_stub_bti_direct_branch: |
3374 | 0 | if (!aarch64_relocate (AARCH64_R (JUMP26), stub_bfd, stub_sec, |
3375 | 0 | stub_entry->stub_offset + 4, sym_value)) |
3376 | 0 | BFD_FAIL (); |
3377 | 0 | break; |
3378 | | |
3379 | 0 | case aarch64_stub_erratum_835769_veneer: |
3380 | 0 | veneered_insn_loc = stub_entry->target_section->output_section->vma |
3381 | 0 | + stub_entry->target_section->output_offset |
3382 | 0 | + stub_entry->target_value; |
3383 | 0 | veneer_entry_loc = stub_entry->stub_sec->output_section->vma |
3384 | 0 | + stub_entry->stub_sec->output_offset |
3385 | 0 | + stub_entry->stub_offset; |
3386 | 0 | branch_offset = veneered_insn_loc - veneer_entry_loc; |
3387 | 0 | branch_offset >>= 2; |
3388 | 0 | branch_offset &= 0x3ffffff; |
3389 | 0 | bfd_putl32 (stub_entry->veneered_insn, |
3390 | 0 | stub_sec->contents + stub_entry->stub_offset); |
3391 | 0 | bfd_putl32 (template[1] | branch_offset, |
3392 | 0 | stub_sec->contents + stub_entry->stub_offset + 4); |
3393 | 0 | break; |
3394 | | |
3395 | 0 | case aarch64_stub_erratum_843419_veneer: |
3396 | 0 | if (!aarch64_relocate (AARCH64_R (JUMP26), stub_bfd, stub_sec, |
3397 | 0 | stub_entry->stub_offset + 4, sym_value + 4)) |
3398 | 0 | BFD_FAIL (); |
3399 | 0 | break; |
3400 | | |
3401 | 0 | default: |
3402 | 0 | abort (); |
3403 | 0 | } |
3404 | | |
3405 | 0 | return true; |
3406 | 0 | } |
3407 | | |
3408 | | /* As above, but don't actually build the stub. Just bump offset so |
3409 | | we know stub section sizes and record the offset for each stub so |
3410 | | a stub can target another stub (needed for BTI direct branch stub). */ |
3411 | | |
3412 | | static bool |
3413 | | aarch64_size_one_stub (struct bfd_hash_entry *gen_entry, void *in_arg) |
3414 | 0 | { |
3415 | 0 | struct elf_aarch64_stub_hash_entry *stub_entry; |
3416 | 0 | struct elf_aarch64_link_hash_table *htab; |
3417 | 0 | int size; |
3418 | | |
3419 | | /* Massage our args to the form they really have. */ |
3420 | 0 | stub_entry = (struct elf_aarch64_stub_hash_entry *) gen_entry; |
3421 | 0 | htab = (struct elf_aarch64_link_hash_table *) in_arg; |
3422 | |
|
3423 | 0 | switch (stub_entry->stub_type) |
3424 | 0 | { |
3425 | 0 | case aarch64_stub_adrp_branch: |
3426 | 0 | size = sizeof (aarch64_adrp_branch_stub); |
3427 | 0 | break; |
3428 | 0 | case aarch64_stub_long_branch: |
3429 | 0 | size = sizeof (aarch64_long_branch_stub); |
3430 | 0 | break; |
3431 | 0 | case aarch64_stub_bti_direct_branch: |
3432 | 0 | size = sizeof (aarch64_bti_direct_branch_stub); |
3433 | 0 | break; |
3434 | 0 | case aarch64_stub_erratum_835769_veneer: |
3435 | 0 | size = sizeof (aarch64_erratum_835769_stub); |
3436 | 0 | break; |
3437 | 0 | case aarch64_stub_erratum_843419_veneer: |
3438 | 0 | { |
3439 | 0 | if (htab->fix_erratum_843419 == ERRAT_ADR) |
3440 | 0 | return true; |
3441 | 0 | size = sizeof (aarch64_erratum_843419_stub); |
3442 | 0 | } |
3443 | 0 | break; |
3444 | 0 | default: |
3445 | 0 | abort (); |
3446 | 0 | } |
3447 | | |
3448 | 0 | size = (size + 7) & ~7; |
3449 | 0 | stub_entry->stub_offset = stub_entry->stub_sec->size; |
3450 | 0 | stub_entry->stub_sec->size += size; |
3451 | 0 | return true; |
3452 | 0 | } |
3453 | | |
3454 | | /* Output is BTI compatible. */ |
3455 | | |
3456 | | static bool |
3457 | | elf_aarch64_bti_p (bfd *output_bfd) |
3458 | 0 | { |
3459 | 0 | uint32_t prop = elf_aarch64_tdata (output_bfd)->gnu_and_prop; |
3460 | 0 | return prop & GNU_PROPERTY_AARCH64_FEATURE_1_BTI; |
3461 | 0 | } |
3462 | | |
3463 | | /* External entry points for sizing and building linker stubs. */ |
3464 | | |
3465 | | /* Set up various things so that we can make a list of input sections |
3466 | | for each output section included in the link. Returns -1 on error, |
3467 | | 0 when no stubs will be needed, and 1 on success. */ |
3468 | | |
3469 | | int |
3470 | | elf64_aarch64_setup_section_lists (bfd *output_bfd, |
3471 | | struct bfd_link_info *info) |
3472 | 0 | { |
3473 | 0 | bfd *input_bfd; |
3474 | 0 | unsigned int bfd_count; |
3475 | 0 | unsigned int top_id, top_index; |
3476 | 0 | asection *section; |
3477 | 0 | asection **input_list, **list; |
3478 | 0 | size_t amt; |
3479 | 0 | struct elf_aarch64_link_hash_table *htab = |
3480 | 0 | elf_aarch64_hash_table (info); |
3481 | |
|
3482 | 0 | if (!is_elf_hash_table (&htab->root.root)) |
3483 | 0 | return 0; |
3484 | | |
3485 | | /* Count the number of input BFDs and find the top input section id. */ |
3486 | 0 | for (input_bfd = info->input_bfds, bfd_count = 0, top_id = 0; |
3487 | 0 | input_bfd != NULL; input_bfd = input_bfd->link.next) |
3488 | 0 | { |
3489 | 0 | bfd_count += 1; |
3490 | 0 | for (section = input_bfd->sections; |
3491 | 0 | section != NULL; section = section->next) |
3492 | 0 | { |
3493 | 0 | if (top_id < section->id) |
3494 | 0 | top_id = section->id; |
3495 | 0 | } |
3496 | 0 | } |
3497 | 0 | htab->bfd_count = bfd_count; |
3498 | |
|
3499 | 0 | amt = sizeof (struct map_stub) * (top_id + 1); |
3500 | 0 | htab->stub_group = bfd_zmalloc (amt); |
3501 | 0 | if (htab->stub_group == NULL) |
3502 | 0 | return -1; |
3503 | | |
3504 | | /* We can't use output_bfd->section_count here to find the top output |
3505 | | section index as some sections may have been removed, and |
3506 | | _bfd_strip_section_from_output doesn't renumber the indices. */ |
3507 | 0 | for (section = output_bfd->sections, top_index = 0; |
3508 | 0 | section != NULL; section = section->next) |
3509 | 0 | { |
3510 | 0 | if (top_index < section->index) |
3511 | 0 | top_index = section->index; |
3512 | 0 | } |
3513 | |
|
3514 | 0 | htab->top_index = top_index; |
3515 | 0 | amt = sizeof (asection *) * (top_index + 1); |
3516 | 0 | input_list = bfd_malloc (amt); |
3517 | 0 | htab->input_list = input_list; |
3518 | 0 | if (input_list == NULL) |
3519 | 0 | return -1; |
3520 | | |
3521 | | /* For sections we aren't interested in, mark their entries with a |
3522 | | value we can check later. */ |
3523 | 0 | list = input_list + top_index; |
3524 | 0 | do |
3525 | 0 | *list = bfd_abs_section_ptr; |
3526 | 0 | while (list-- != input_list); |
3527 | |
|
3528 | 0 | for (section = output_bfd->sections; |
3529 | 0 | section != NULL; section = section->next) |
3530 | 0 | { |
3531 | 0 | if ((section->flags & SEC_CODE) != 0) |
3532 | 0 | input_list[section->index] = NULL; |
3533 | 0 | } |
3534 | |
|
3535 | 0 | return 1; |
3536 | 0 | } |
3537 | | |
3538 | | /* Used by elf64_aarch64_next_input_section and group_sections. */ |
3539 | 0 | #define PREV_SEC(sec) (htab->stub_group[(sec)->id].link_sec) |
3540 | | |
3541 | | /* The linker repeatedly calls this function for each input section, |
3542 | | in the order that input sections are linked into output sections. |
3543 | | Build lists of input sections to determine groupings between which |
3544 | | we may insert linker stubs. */ |
3545 | | |
3546 | | void |
3547 | | elf64_aarch64_next_input_section (struct bfd_link_info *info, asection *isec) |
3548 | 0 | { |
3549 | 0 | struct elf_aarch64_link_hash_table *htab = |
3550 | 0 | elf_aarch64_hash_table (info); |
3551 | |
|
3552 | 0 | if (isec->output_section->index <= htab->top_index) |
3553 | 0 | { |
3554 | 0 | asection **list = htab->input_list + isec->output_section->index; |
3555 | |
|
3556 | 0 | if (*list != bfd_abs_section_ptr && (isec->flags & SEC_CODE) != 0) |
3557 | 0 | { |
3558 | | /* Steal the link_sec pointer for our list. */ |
3559 | | /* This happens to make the list in reverse order, |
3560 | | which is what we want. */ |
3561 | 0 | PREV_SEC (isec) = *list; |
3562 | 0 | *list = isec; |
3563 | 0 | } |
3564 | 0 | } |
3565 | 0 | } |
3566 | | |
3567 | | /* See whether we can group stub sections together. Grouping stub |
3568 | | sections may result in fewer stubs. More importantly, we need to |
3569 | | put all .init* and .fini* stubs at the beginning of the .init or |
3570 | | .fini output sections respectively, because glibc splits the |
3571 | | _init and _fini functions into multiple parts. Putting a stub in |
3572 | | the middle of a function is not a good idea. */ |
3573 | | |
3574 | | static void |
3575 | | group_sections (struct elf_aarch64_link_hash_table *htab, |
3576 | | bfd_size_type stub_group_size, |
3577 | | bool stubs_always_after_branch) |
3578 | 0 | { |
3579 | 0 | asection **list = htab->input_list; |
3580 | |
|
3581 | 0 | do |
3582 | 0 | { |
3583 | 0 | asection *tail = *list; |
3584 | 0 | asection *head; |
3585 | |
|
3586 | 0 | if (tail == bfd_abs_section_ptr) |
3587 | 0 | continue; |
3588 | | |
3589 | | /* Reverse the list: we must avoid placing stubs at the |
3590 | | beginning of the section because the beginning of the text |
3591 | | section may be required for an interrupt vector in bare metal |
3592 | | code. */ |
3593 | 0 | #define NEXT_SEC PREV_SEC |
3594 | 0 | head = NULL; |
3595 | 0 | while (tail != NULL) |
3596 | 0 | { |
3597 | | /* Pop from tail. */ |
3598 | 0 | asection *item = tail; |
3599 | 0 | tail = PREV_SEC (item); |
3600 | | |
3601 | | /* Push on head. */ |
3602 | 0 | NEXT_SEC (item) = head; |
3603 | 0 | head = item; |
3604 | 0 | } |
3605 | |
|
3606 | 0 | while (head != NULL) |
3607 | 0 | { |
3608 | 0 | asection *curr; |
3609 | 0 | asection *next; |
3610 | 0 | bfd_vma stub_group_start = head->output_offset; |
3611 | 0 | bfd_vma end_of_next; |
3612 | |
|
3613 | 0 | curr = head; |
3614 | 0 | while (NEXT_SEC (curr) != NULL) |
3615 | 0 | { |
3616 | 0 | next = NEXT_SEC (curr); |
3617 | 0 | end_of_next = next->output_offset + next->size; |
3618 | 0 | if (end_of_next - stub_group_start >= stub_group_size) |
3619 | | /* End of NEXT is too far from start, so stop. */ |
3620 | 0 | break; |
3621 | | /* Add NEXT to the group. */ |
3622 | 0 | curr = next; |
3623 | 0 | } |
3624 | | |
3625 | | /* OK, the size from the start to the start of CURR is less |
3626 | | than stub_group_size and thus can be handled by one stub |
3627 | | section. (Or the head section is itself larger than |
3628 | | stub_group_size, in which case we may be toast.) |
3629 | | We should really be keeping track of the total size of |
3630 | | stubs added here, as stubs contribute to the final output |
3631 | | section size. */ |
3632 | 0 | do |
3633 | 0 | { |
3634 | 0 | next = NEXT_SEC (head); |
3635 | | /* Set up this stub group. */ |
3636 | 0 | htab->stub_group[head->id].link_sec = curr; |
3637 | 0 | } |
3638 | 0 | while (head != curr && (head = next) != NULL); |
3639 | | |
3640 | | /* But wait, there's more! Input sections up to stub_group_size |
3641 | | bytes after the stub section can be handled by it too. */ |
3642 | 0 | if (!stubs_always_after_branch) |
3643 | 0 | { |
3644 | 0 | stub_group_start = curr->output_offset + curr->size; |
3645 | |
|
3646 | 0 | while (next != NULL) |
3647 | 0 | { |
3648 | 0 | end_of_next = next->output_offset + next->size; |
3649 | 0 | if (end_of_next - stub_group_start >= stub_group_size) |
3650 | | /* End of NEXT is too far from stubs, so stop. */ |
3651 | 0 | break; |
3652 | | /* Add NEXT to the stub group. */ |
3653 | 0 | head = next; |
3654 | 0 | next = NEXT_SEC (head); |
3655 | 0 | htab->stub_group[head->id].link_sec = curr; |
3656 | 0 | } |
3657 | 0 | } |
3658 | 0 | head = next; |
3659 | 0 | } |
3660 | 0 | } |
3661 | 0 | while (list++ != htab->input_list + htab->top_index); |
3662 | | |
3663 | 0 | free (htab->input_list); |
3664 | 0 | } |
3665 | | |
3666 | | #undef PREV_SEC |
3667 | | #undef PREV_SEC |
3668 | | |
3669 | 0 | #define AARCH64_HINT(insn) (((insn) & 0xfffff01f) == 0xd503201f) |
3670 | 0 | #define AARCH64_PACIASP 0xd503233f |
3671 | 0 | #define AARCH64_PACIBSP 0xd503237f |
3672 | 0 | #define AARCH64_BTI_C 0xd503245f |
3673 | 0 | #define AARCH64_BTI_J 0xd503249f |
3674 | 0 | #define AARCH64_BTI_JC 0xd50324df |
3675 | | |
3676 | | /* True if the inserted stub does not break BTI compatibility. */ |
3677 | | |
3678 | | static bool |
3679 | | aarch64_bti_stub_p (bfd *input_bfd, |
3680 | | struct elf_aarch64_stub_hash_entry *stub_entry) |
3681 | 0 | { |
3682 | | /* Stubs without indirect branch are BTI compatible. */ |
3683 | 0 | if (stub_entry->stub_type != aarch64_stub_adrp_branch |
3684 | 0 | && stub_entry->stub_type != aarch64_stub_long_branch) |
3685 | 0 | return true; |
3686 | | |
3687 | | /* Return true if the target instruction is compatible with BR x16. */ |
3688 | | |
3689 | 0 | asection *section = stub_entry->target_section; |
3690 | 0 | bfd_byte loc[4]; |
3691 | 0 | file_ptr off = stub_entry->target_value; |
3692 | 0 | bfd_size_type count = sizeof (loc); |
3693 | |
|
3694 | 0 | if (!bfd_get_section_contents (input_bfd, section, loc, off, count)) |
3695 | 0 | return false; |
3696 | | |
3697 | 0 | uint32_t insn = bfd_getl32 (loc); |
3698 | 0 | if (!AARCH64_HINT (insn)) |
3699 | 0 | return false; |
3700 | 0 | return insn == AARCH64_BTI_C |
3701 | 0 | || insn == AARCH64_PACIASP |
3702 | 0 | || insn == AARCH64_BTI_JC |
3703 | 0 | || insn == AARCH64_BTI_J |
3704 | 0 | || insn == AARCH64_PACIBSP; |
3705 | 0 | } |
3706 | | |
3707 | 0 | #define AARCH64_BITS(x, pos, n) (((x) >> (pos)) & ((1 << (n)) - 1)) |
3708 | | |
3709 | 0 | #define AARCH64_RT(insn) AARCH64_BITS (insn, 0, 5) |
3710 | 0 | #define AARCH64_RT2(insn) AARCH64_BITS (insn, 10, 5) |
3711 | 0 | #define AARCH64_RA(insn) AARCH64_BITS (insn, 10, 5) |
3712 | 0 | #define AARCH64_RD(insn) AARCH64_BITS (insn, 0, 5) |
3713 | 0 | #define AARCH64_RN(insn) AARCH64_BITS (insn, 5, 5) |
3714 | 0 | #define AARCH64_RM(insn) AARCH64_BITS (insn, 16, 5) |
3715 | | |
3716 | 0 | #define AARCH64_MAC(insn) (((insn) & 0xff000000) == 0x9b000000) |
3717 | 0 | #define AARCH64_BIT(insn, n) AARCH64_BITS (insn, n, 1) |
3718 | 0 | #define AARCH64_OP31(insn) AARCH64_BITS (insn, 21, 3) |
3719 | 0 | #define AARCH64_ZR 0x1f |
3720 | | |
3721 | | /* All ld/st ops. See C4-182 of the ARM ARM. The encoding space for |
3722 | | LD_PCREL, LDST_RO, LDST_UI and LDST_UIMM cover prefetch ops. */ |
3723 | | |
3724 | 0 | #define AARCH64_LD(insn) (AARCH64_BIT (insn, 22) == 1) |
3725 | 0 | #define AARCH64_LDST(insn) (((insn) & 0x0a000000) == 0x08000000) |
3726 | 0 | #define AARCH64_LDST_EX(insn) (((insn) & 0x3f000000) == 0x08000000) |
3727 | 0 | #define AARCH64_LDST_PCREL(insn) (((insn) & 0x3b000000) == 0x18000000) |
3728 | 0 | #define AARCH64_LDST_NAP(insn) (((insn) & 0x3b800000) == 0x28000000) |
3729 | 0 | #define AARCH64_LDSTP_PI(insn) (((insn) & 0x3b800000) == 0x28800000) |
3730 | 0 | #define AARCH64_LDSTP_O(insn) (((insn) & 0x3b800000) == 0x29000000) |
3731 | 0 | #define AARCH64_LDSTP_PRE(insn) (((insn) & 0x3b800000) == 0x29800000) |
3732 | 0 | #define AARCH64_LDST_UI(insn) (((insn) & 0x3b200c00) == 0x38000000) |
3733 | 0 | #define AARCH64_LDST_PIIMM(insn) (((insn) & 0x3b200c00) == 0x38000400) |
3734 | 0 | #define AARCH64_LDST_U(insn) (((insn) & 0x3b200c00) == 0x38000800) |
3735 | 0 | #define AARCH64_LDST_PREIMM(insn) (((insn) & 0x3b200c00) == 0x38000c00) |
3736 | 0 | #define AARCH64_LDST_RO(insn) (((insn) & 0x3b200c00) == 0x38200800) |
3737 | 0 | #define AARCH64_LDST_UIMM(insn) (((insn) & 0x3b000000) == 0x39000000) |
3738 | 0 | #define AARCH64_LDST_SIMD_M(insn) (((insn) & 0xbfbf0000) == 0x0c000000) |
3739 | 0 | #define AARCH64_LDST_SIMD_M_PI(insn) (((insn) & 0xbfa00000) == 0x0c800000) |
3740 | 0 | #define AARCH64_LDST_SIMD_S(insn) (((insn) & 0xbf9f0000) == 0x0d000000) |
3741 | 0 | #define AARCH64_LDST_SIMD_S_PI(insn) (((insn) & 0xbf800000) == 0x0d800000) |
3742 | | |
3743 | | /* Classify an INSN if it is indeed a load/store. |
3744 | | |
3745 | | Return TRUE if INSN is a LD/ST instruction otherwise return FALSE. |
3746 | | |
3747 | | For scalar LD/ST instructions PAIR is FALSE, RT is returned and RT2 |
3748 | | is set equal to RT. |
3749 | | |
3750 | | For LD/ST pair instructions PAIR is TRUE, RT and RT2 are returned. */ |
3751 | | |
3752 | | static bool |
3753 | | aarch64_mem_op_p (uint32_t insn, unsigned int *rt, unsigned int *rt2, |
3754 | | bool *pair, bool *load) |
3755 | 0 | { |
3756 | 0 | uint32_t opcode; |
3757 | 0 | unsigned int r; |
3758 | 0 | uint32_t opc = 0; |
3759 | 0 | uint32_t v = 0; |
3760 | 0 | uint32_t opc_v = 0; |
3761 | | |
3762 | | /* Bail out quickly if INSN doesn't fall into the load-store |
3763 | | encoding space. */ |
3764 | 0 | if (!AARCH64_LDST (insn)) |
3765 | 0 | return false; |
3766 | | |
3767 | 0 | *pair = false; |
3768 | 0 | *load = false; |
3769 | 0 | if (AARCH64_LDST_EX (insn)) |
3770 | 0 | { |
3771 | 0 | *rt = AARCH64_RT (insn); |
3772 | 0 | *rt2 = *rt; |
3773 | 0 | if (AARCH64_BIT (insn, 21) == 1) |
3774 | 0 | { |
3775 | 0 | *pair = true; |
3776 | 0 | *rt2 = AARCH64_RT2 (insn); |
3777 | 0 | } |
3778 | 0 | *load = AARCH64_LD (insn); |
3779 | 0 | return true; |
3780 | 0 | } |
3781 | 0 | else if (AARCH64_LDST_NAP (insn) |
3782 | 0 | || AARCH64_LDSTP_PI (insn) |
3783 | 0 | || AARCH64_LDSTP_O (insn) |
3784 | 0 | || AARCH64_LDSTP_PRE (insn)) |
3785 | 0 | { |
3786 | 0 | *pair = true; |
3787 | 0 | *rt = AARCH64_RT (insn); |
3788 | 0 | *rt2 = AARCH64_RT2 (insn); |
3789 | 0 | *load = AARCH64_LD (insn); |
3790 | 0 | return true; |
3791 | 0 | } |
3792 | 0 | else if (AARCH64_LDST_PCREL (insn) |
3793 | 0 | || AARCH64_LDST_UI (insn) |
3794 | 0 | || AARCH64_LDST_PIIMM (insn) |
3795 | 0 | || AARCH64_LDST_U (insn) |
3796 | 0 | || AARCH64_LDST_PREIMM (insn) |
3797 | 0 | || AARCH64_LDST_RO (insn) |
3798 | 0 | || AARCH64_LDST_UIMM (insn)) |
3799 | 0 | { |
3800 | 0 | *rt = AARCH64_RT (insn); |
3801 | 0 | *rt2 = *rt; |
3802 | 0 | if (AARCH64_LDST_PCREL (insn)) |
3803 | 0 | *load = true; |
3804 | 0 | opc = AARCH64_BITS (insn, 22, 2); |
3805 | 0 | v = AARCH64_BIT (insn, 26); |
3806 | 0 | opc_v = opc | (v << 2); |
3807 | 0 | *load = (opc_v == 1 || opc_v == 2 || opc_v == 3 |
3808 | 0 | || opc_v == 5 || opc_v == 7); |
3809 | 0 | return true; |
3810 | 0 | } |
3811 | 0 | else if (AARCH64_LDST_SIMD_M (insn) |
3812 | 0 | || AARCH64_LDST_SIMD_M_PI (insn)) |
3813 | 0 | { |
3814 | 0 | *rt = AARCH64_RT (insn); |
3815 | 0 | *load = AARCH64_BIT (insn, 22); |
3816 | 0 | opcode = (insn >> 12) & 0xf; |
3817 | 0 | switch (opcode) |
3818 | 0 | { |
3819 | 0 | case 0: |
3820 | 0 | case 2: |
3821 | 0 | *rt2 = *rt + 3; |
3822 | 0 | break; |
3823 | | |
3824 | 0 | case 4: |
3825 | 0 | case 6: |
3826 | 0 | *rt2 = *rt + 2; |
3827 | 0 | break; |
3828 | | |
3829 | 0 | case 7: |
3830 | 0 | *rt2 = *rt; |
3831 | 0 | break; |
3832 | | |
3833 | 0 | case 8: |
3834 | 0 | case 10: |
3835 | 0 | *rt2 = *rt + 1; |
3836 | 0 | break; |
3837 | | |
3838 | 0 | default: |
3839 | 0 | return false; |
3840 | 0 | } |
3841 | 0 | return true; |
3842 | 0 | } |
3843 | 0 | else if (AARCH64_LDST_SIMD_S (insn) |
3844 | 0 | || AARCH64_LDST_SIMD_S_PI (insn)) |
3845 | 0 | { |
3846 | 0 | *rt = AARCH64_RT (insn); |
3847 | 0 | r = (insn >> 21) & 1; |
3848 | 0 | *load = AARCH64_BIT (insn, 22); |
3849 | 0 | opcode = (insn >> 13) & 0x7; |
3850 | 0 | switch (opcode) |
3851 | 0 | { |
3852 | 0 | case 0: |
3853 | 0 | case 2: |
3854 | 0 | case 4: |
3855 | 0 | *rt2 = *rt + r; |
3856 | 0 | break; |
3857 | | |
3858 | 0 | case 1: |
3859 | 0 | case 3: |
3860 | 0 | case 5: |
3861 | 0 | *rt2 = *rt + (r == 0 ? 2 : 3); |
3862 | 0 | break; |
3863 | | |
3864 | 0 | case 6: |
3865 | 0 | *rt2 = *rt + r; |
3866 | 0 | break; |
3867 | | |
3868 | 0 | case 7: |
3869 | 0 | *rt2 = *rt + (r == 0 ? 2 : 3); |
3870 | 0 | break; |
3871 | | |
3872 | 0 | default: |
3873 | 0 | return false; |
3874 | 0 | } |
3875 | 0 | return true; |
3876 | 0 | } |
3877 | | |
3878 | 0 | return false; |
3879 | 0 | } |
3880 | | |
3881 | | /* Return TRUE if INSN is multiply-accumulate. */ |
3882 | | |
3883 | | static bool |
3884 | | aarch64_mlxl_p (uint32_t insn) |
3885 | 0 | { |
3886 | 0 | uint32_t op31 = AARCH64_OP31 (insn); |
3887 | |
|
3888 | 0 | if (AARCH64_MAC (insn) |
3889 | 0 | && (op31 == 0 || op31 == 1 || op31 == 5) |
3890 | | /* Exclude MUL instructions which are encoded as a multiple accumulate |
3891 | | with RA = XZR. */ |
3892 | 0 | && AARCH64_RA (insn) != AARCH64_ZR) |
3893 | 0 | return true; |
3894 | | |
3895 | 0 | return false; |
3896 | 0 | } |
3897 | | |
3898 | | /* Some early revisions of the Cortex-A53 have an erratum (835769) whereby |
3899 | | it is possible for a 64-bit multiply-accumulate instruction to generate an |
3900 | | incorrect result. The details are quite complex and hard to |
3901 | | determine statically, since branches in the code may exist in some |
3902 | | circumstances, but all cases end with a memory (load, store, or |
3903 | | prefetch) instruction followed immediately by the multiply-accumulate |
3904 | | operation. We employ a linker patching technique, by moving the potentially |
3905 | | affected multiply-accumulate instruction into a patch region and replacing |
3906 | | the original instruction with a branch to the patch. This function checks |
3907 | | if INSN_1 is the memory operation followed by a multiply-accumulate |
3908 | | operation (INSN_2). Return TRUE if an erratum sequence is found, FALSE |
3909 | | if INSN_1 and INSN_2 are safe. */ |
3910 | | |
3911 | | static bool |
3912 | | aarch64_erratum_sequence (uint32_t insn_1, uint32_t insn_2) |
3913 | 0 | { |
3914 | 0 | uint32_t rt; |
3915 | 0 | uint32_t rt2; |
3916 | 0 | uint32_t rn; |
3917 | 0 | uint32_t rm; |
3918 | 0 | uint32_t ra; |
3919 | 0 | bool pair; |
3920 | 0 | bool load; |
3921 | |
|
3922 | 0 | if (aarch64_mlxl_p (insn_2) |
3923 | 0 | && aarch64_mem_op_p (insn_1, &rt, &rt2, &pair, &load)) |
3924 | 0 | { |
3925 | | /* Any SIMD memory op is independent of the subsequent MLA |
3926 | | by definition of the erratum. */ |
3927 | 0 | if (AARCH64_BIT (insn_1, 26)) |
3928 | 0 | return true; |
3929 | | |
3930 | | /* If not SIMD, check for integer memory ops and MLA relationship. */ |
3931 | 0 | rn = AARCH64_RN (insn_2); |
3932 | 0 | ra = AARCH64_RA (insn_2); |
3933 | 0 | rm = AARCH64_RM (insn_2); |
3934 | | |
3935 | | /* If this is a load and there's a true(RAW) dependency, we are safe |
3936 | | and this is not an erratum sequence. */ |
3937 | 0 | if (load && |
3938 | 0 | (rt == rn || rt == rm || rt == ra |
3939 | 0 | || (pair && (rt2 == rn || rt2 == rm || rt2 == ra)))) |
3940 | 0 | return false; |
3941 | | |
3942 | | /* We conservatively put out stubs for all other cases (including |
3943 | | writebacks). */ |
3944 | 0 | return true; |
3945 | 0 | } |
3946 | | |
3947 | 0 | return false; |
3948 | 0 | } |
3949 | | |
3950 | | /* Used to order a list of mapping symbols by address. */ |
3951 | | |
3952 | | static int |
3953 | | elf_aarch64_compare_mapping (const void *a, const void *b) |
3954 | 0 | { |
3955 | 0 | const elf_aarch64_section_map *amap = (const elf_aarch64_section_map *) a; |
3956 | 0 | const elf_aarch64_section_map *bmap = (const elf_aarch64_section_map *) b; |
3957 | |
|
3958 | 0 | if (amap->vma > bmap->vma) |
3959 | 0 | return 1; |
3960 | 0 | else if (amap->vma < bmap->vma) |
3961 | 0 | return -1; |
3962 | 0 | else if (amap->type > bmap->type) |
3963 | | /* Ensure results do not depend on the host qsort for objects with |
3964 | | multiple mapping symbols at the same address by sorting on type |
3965 | | after vma. */ |
3966 | 0 | return 1; |
3967 | 0 | else if (amap->type < bmap->type) |
3968 | 0 | return -1; |
3969 | 0 | else |
3970 | 0 | return 0; |
3971 | 0 | } |
3972 | | |
3973 | | |
3974 | | static char * |
3975 | | _bfd_aarch64_erratum_835769_stub_name (unsigned num_fixes) |
3976 | 0 | { |
3977 | 0 | char *stub_name = (char *) bfd_malloc |
3978 | 0 | (strlen ("__erratum_835769_veneer_") + 16); |
3979 | 0 | if (stub_name != NULL) |
3980 | 0 | sprintf (stub_name,"__erratum_835769_veneer_%d", num_fixes); |
3981 | 0 | return stub_name; |
3982 | 0 | } |
3983 | | |
3984 | | /* Scan for Cortex-A53 erratum 835769 sequence. |
3985 | | |
3986 | | Return TRUE else FALSE on abnormal termination. */ |
3987 | | |
3988 | | static bool |
3989 | | _bfd_aarch64_erratum_835769_scan (bfd *input_bfd, |
3990 | | struct bfd_link_info *info, |
3991 | | unsigned int *num_fixes_p) |
3992 | 0 | { |
3993 | 0 | asection *section; |
3994 | 0 | struct elf_aarch64_link_hash_table *htab = elf_aarch64_hash_table (info); |
3995 | 0 | unsigned int num_fixes = *num_fixes_p; |
3996 | |
|
3997 | 0 | if (htab == NULL) |
3998 | 0 | return true; |
3999 | | |
4000 | 0 | for (section = input_bfd->sections; |
4001 | 0 | section != NULL; |
4002 | 0 | section = section->next) |
4003 | 0 | { |
4004 | 0 | bfd_byte *contents = NULL; |
4005 | 0 | struct _aarch64_elf_section_data *sec_data; |
4006 | 0 | unsigned int span; |
4007 | |
|
4008 | 0 | if (elf_section_type (section) != SHT_PROGBITS |
4009 | 0 | || (elf_section_flags (section) & SHF_EXECINSTR) == 0 |
4010 | 0 | || (section->flags & SEC_EXCLUDE) != 0 |
4011 | 0 | || (section->sec_info_type == SEC_INFO_TYPE_JUST_SYMS) |
4012 | 0 | || (section->output_section == bfd_abs_section_ptr)) |
4013 | 0 | continue; |
4014 | | |
4015 | 0 | if (elf_section_data (section)->this_hdr.contents != NULL) |
4016 | 0 | contents = elf_section_data (section)->this_hdr.contents; |
4017 | 0 | else if (! bfd_malloc_and_get_section (input_bfd, section, &contents)) |
4018 | 0 | return false; |
4019 | | |
4020 | 0 | sec_data = elf_aarch64_section_data (section); |
4021 | |
|
4022 | 0 | if (sec_data->mapcount) |
4023 | 0 | qsort (sec_data->map, sec_data->mapcount, |
4024 | 0 | sizeof (elf_aarch64_section_map), elf_aarch64_compare_mapping); |
4025 | |
|
4026 | 0 | for (span = 0; span < sec_data->mapcount; span++) |
4027 | 0 | { |
4028 | 0 | unsigned int span_start = sec_data->map[span].vma; |
4029 | 0 | unsigned int span_end = ((span == sec_data->mapcount - 1) |
4030 | 0 | ? sec_data->map[0].vma + section->size |
4031 | 0 | : sec_data->map[span + 1].vma); |
4032 | 0 | unsigned int i; |
4033 | 0 | char span_type = sec_data->map[span].type; |
4034 | |
|
4035 | 0 | if (span_type == 'd') |
4036 | 0 | continue; |
4037 | | |
4038 | 0 | for (i = span_start; i + 4 < span_end; i += 4) |
4039 | 0 | { |
4040 | 0 | uint32_t insn_1 = bfd_getl32 (contents + i); |
4041 | 0 | uint32_t insn_2 = bfd_getl32 (contents + i + 4); |
4042 | |
|
4043 | 0 | if (aarch64_erratum_sequence (insn_1, insn_2)) |
4044 | 0 | { |
4045 | 0 | struct elf_aarch64_stub_hash_entry *stub_entry; |
4046 | 0 | char *stub_name = _bfd_aarch64_erratum_835769_stub_name (num_fixes); |
4047 | 0 | if (! stub_name) |
4048 | 0 | return false; |
4049 | | |
4050 | 0 | stub_entry = _bfd_aarch64_add_stub_entry_in_group (stub_name, |
4051 | 0 | section, |
4052 | 0 | htab); |
4053 | 0 | if (! stub_entry) |
4054 | 0 | return false; |
4055 | | |
4056 | 0 | stub_entry->stub_type = aarch64_stub_erratum_835769_veneer; |
4057 | 0 | stub_entry->target_section = section; |
4058 | 0 | stub_entry->target_value = i + 4; |
4059 | 0 | stub_entry->veneered_insn = insn_2; |
4060 | 0 | stub_entry->output_name = stub_name; |
4061 | 0 | num_fixes++; |
4062 | 0 | } |
4063 | 0 | } |
4064 | 0 | } |
4065 | 0 | if (elf_section_data (section)->this_hdr.contents == NULL) |
4066 | 0 | free (contents); |
4067 | 0 | } |
4068 | | |
4069 | 0 | *num_fixes_p = num_fixes; |
4070 | |
|
4071 | 0 | return true; |
4072 | 0 | } |
4073 | | |
4074 | | |
4075 | | /* Test if instruction INSN is ADRP. */ |
4076 | | |
4077 | | static bool |
4078 | | _bfd_aarch64_adrp_p (uint32_t insn) |
4079 | 0 | { |
4080 | 0 | return ((insn & AARCH64_ADRP_OP_MASK) == AARCH64_ADRP_OP); |
4081 | 0 | } |
4082 | | |
4083 | | |
4084 | | /* Helper predicate to look for cortex-a53 erratum 843419 sequence 1. */ |
4085 | | |
4086 | | static bool |
4087 | | _bfd_aarch64_erratum_843419_sequence_p (uint32_t insn_1, uint32_t insn_2, |
4088 | | uint32_t insn_3) |
4089 | 0 | { |
4090 | 0 | uint32_t rt; |
4091 | 0 | uint32_t rt2; |
4092 | 0 | bool pair; |
4093 | 0 | bool load; |
4094 | |
|
4095 | 0 | return (aarch64_mem_op_p (insn_2, &rt, &rt2, &pair, &load) |
4096 | 0 | && (!pair |
4097 | 0 | || (pair && !load)) |
4098 | 0 | && AARCH64_LDST_UIMM (insn_3) |
4099 | 0 | && AARCH64_RN (insn_3) == AARCH64_RD (insn_1)); |
4100 | 0 | } |
4101 | | |
4102 | | |
4103 | | /* Test for the presence of Cortex-A53 erratum 843419 instruction sequence. |
4104 | | |
4105 | | Return TRUE if section CONTENTS at offset I contains one of the |
4106 | | erratum 843419 sequences, otherwise return FALSE. If a sequence is |
4107 | | seen set P_VENEER_I to the offset of the final LOAD/STORE |
4108 | | instruction in the sequence. |
4109 | | */ |
4110 | | |
4111 | | static bool |
4112 | | _bfd_aarch64_erratum_843419_p (bfd_byte *contents, bfd_vma vma, |
4113 | | bfd_vma i, bfd_vma span_end, |
4114 | | bfd_vma *p_veneer_i) |
4115 | 0 | { |
4116 | 0 | uint32_t insn_1 = bfd_getl32 (contents + i); |
4117 | |
|
4118 | 0 | if (!_bfd_aarch64_adrp_p (insn_1)) |
4119 | 0 | return false; |
4120 | | |
4121 | 0 | if (span_end < i + 12) |
4122 | 0 | return false; |
4123 | | |
4124 | 0 | uint32_t insn_2 = bfd_getl32 (contents + i + 4); |
4125 | 0 | uint32_t insn_3 = bfd_getl32 (contents + i + 8); |
4126 | |
|
4127 | 0 | if ((vma & 0xfff) != 0xff8 && (vma & 0xfff) != 0xffc) |
4128 | 0 | return false; |
4129 | | |
4130 | 0 | if (_bfd_aarch64_erratum_843419_sequence_p (insn_1, insn_2, insn_3)) |
4131 | 0 | { |
4132 | 0 | *p_veneer_i = i + 8; |
4133 | 0 | return true; |
4134 | 0 | } |
4135 | | |
4136 | 0 | if (span_end < i + 16) |
4137 | 0 | return false; |
4138 | | |
4139 | 0 | uint32_t insn_4 = bfd_getl32 (contents + i + 12); |
4140 | |
|
4141 | 0 | if (_bfd_aarch64_erratum_843419_sequence_p (insn_1, insn_2, insn_4)) |
4142 | 0 | { |
4143 | 0 | *p_veneer_i = i + 12; |
4144 | 0 | return true; |
4145 | 0 | } |
4146 | | |
4147 | 0 | return false; |
4148 | 0 | } |
4149 | | |
4150 | | |
4151 | | /* Resize all stub sections. */ |
4152 | | |
4153 | | static void |
4154 | | _bfd_aarch64_resize_stubs (struct elf_aarch64_link_hash_table *htab) |
4155 | 0 | { |
4156 | 0 | asection *section; |
4157 | | |
4158 | | /* OK, we've added some stubs. Find out the new size of the |
4159 | | stub sections. */ |
4160 | 0 | for (section = htab->stub_bfd->sections; |
4161 | 0 | section != NULL; section = section->next) |
4162 | 0 | { |
4163 | | /* Ignore non-stub sections. */ |
4164 | 0 | if (!strstr (section->name, STUB_SUFFIX)) |
4165 | 0 | continue; |
4166 | | |
4167 | | /* Add space for a branch. Add 8 bytes to keep section 8 byte aligned, |
4168 | | as long branch stubs contain a 64-bit address. */ |
4169 | 0 | section->size = 8; |
4170 | 0 | } |
4171 | |
|
4172 | 0 | bfd_hash_traverse (&htab->stub_hash_table, aarch64_size_one_stub, htab); |
4173 | |
|
4174 | 0 | for (section = htab->stub_bfd->sections; |
4175 | 0 | section != NULL; section = section->next) |
4176 | 0 | { |
4177 | 0 | if (!strstr (section->name, STUB_SUFFIX)) |
4178 | 0 | continue; |
4179 | | |
4180 | | /* Empty stub section. */ |
4181 | 0 | if (section->size == 8) |
4182 | 0 | section->size = 0; |
4183 | | |
4184 | | /* Ensure all stub sections have a size which is a multiple of |
4185 | | 4096. This is important in order to ensure that the insertion |
4186 | | of stub sections does not in itself move existing code around |
4187 | | in such a way that new errata sequences are created. We only do this |
4188 | | when the ADRP workaround is enabled. If only the ADR workaround is |
4189 | | enabled then the stubs workaround won't ever be used. */ |
4190 | 0 | if (htab->fix_erratum_843419 & ERRAT_ADRP) |
4191 | 0 | if (section->size) |
4192 | 0 | section->size = BFD_ALIGN (section->size, 0x1000); |
4193 | 0 | } |
4194 | 0 | } |
4195 | | |
4196 | | /* Construct an erratum 843419 workaround stub name. */ |
4197 | | |
4198 | | static char * |
4199 | | _bfd_aarch64_erratum_843419_stub_name (asection *input_section, |
4200 | | bfd_vma offset) |
4201 | 0 | { |
4202 | 0 | const bfd_size_type len = 8 + 4 + 1 + 8 + 1 + 16 + 1; |
4203 | 0 | char *stub_name = bfd_malloc (len); |
4204 | |
|
4205 | 0 | if (stub_name != NULL) |
4206 | 0 | snprintf (stub_name, len, "e843419@%04x_%08x_%" PRIx64, |
4207 | 0 | input_section->owner->id, |
4208 | 0 | input_section->id, |
4209 | 0 | (uint64_t) offset); |
4210 | 0 | return stub_name; |
4211 | 0 | } |
4212 | | |
4213 | | /* Build a stub_entry structure describing an 843419 fixup. |
4214 | | |
4215 | | The stub_entry constructed is populated with the bit pattern INSN |
4216 | | of the instruction located at OFFSET within input SECTION. |
4217 | | |
4218 | | Returns TRUE on success. */ |
4219 | | |
4220 | | static bool |
4221 | | _bfd_aarch64_erratum_843419_fixup (uint32_t insn, |
4222 | | bfd_vma adrp_offset, |
4223 | | bfd_vma ldst_offset, |
4224 | | asection *section, |
4225 | | struct bfd_link_info *info) |
4226 | 0 | { |
4227 | 0 | struct elf_aarch64_link_hash_table *htab = elf_aarch64_hash_table (info); |
4228 | 0 | char *stub_name; |
4229 | 0 | struct elf_aarch64_stub_hash_entry *stub_entry; |
4230 | |
|
4231 | 0 | stub_name = _bfd_aarch64_erratum_843419_stub_name (section, ldst_offset); |
4232 | 0 | if (stub_name == NULL) |
4233 | 0 | return false; |
4234 | 0 | stub_entry = aarch64_stub_hash_lookup (&htab->stub_hash_table, stub_name, |
4235 | 0 | false, false); |
4236 | 0 | if (stub_entry) |
4237 | 0 | { |
4238 | 0 | free (stub_name); |
4239 | 0 | return true; |
4240 | 0 | } |
4241 | | |
4242 | | /* We always place an 843419 workaround veneer in the stub section |
4243 | | attached to the input section in which an erratum sequence has |
4244 | | been found. This ensures that later in the link process (in |
4245 | | elf64_aarch64_write_section) when we copy the veneered |
4246 | | instruction from the input section into the stub section the |
4247 | | copied instruction will have had any relocations applied to it. |
4248 | | If we placed workaround veneers in any other stub section then we |
4249 | | could not assume that all relocations have been processed on the |
4250 | | corresponding input section at the point we output the stub |
4251 | | section. */ |
4252 | | |
4253 | 0 | stub_entry = _bfd_aarch64_add_stub_entry_after (stub_name, section, htab); |
4254 | 0 | if (stub_entry == NULL) |
4255 | 0 | { |
4256 | 0 | free (stub_name); |
4257 | 0 | return false; |
4258 | 0 | } |
4259 | | |
4260 | 0 | stub_entry->adrp_offset = adrp_offset; |
4261 | 0 | stub_entry->target_value = ldst_offset; |
4262 | 0 | stub_entry->target_section = section; |
4263 | 0 | stub_entry->stub_type = aarch64_stub_erratum_843419_veneer; |
4264 | 0 | stub_entry->veneered_insn = insn; |
4265 | 0 | stub_entry->output_name = stub_name; |
4266 | |
|
4267 | 0 | return true; |
4268 | 0 | } |
4269 | | |
4270 | | |
4271 | | /* Scan an input section looking for the signature of erratum 843419. |
4272 | | |
4273 | | Scans input SECTION in INPUT_BFD looking for erratum 843419 |
4274 | | signatures, for each signature found a stub_entry is created |
4275 | | describing the location of the erratum for subsequent fixup. |
4276 | | |
4277 | | Return TRUE on successful scan, FALSE on failure to scan. |
4278 | | */ |
4279 | | |
4280 | | static bool |
4281 | | _bfd_aarch64_erratum_843419_scan (bfd *input_bfd, asection *section, |
4282 | | struct bfd_link_info *info) |
4283 | 0 | { |
4284 | 0 | struct elf_aarch64_link_hash_table *htab = elf_aarch64_hash_table (info); |
4285 | |
|
4286 | 0 | if (htab == NULL) |
4287 | 0 | return true; |
4288 | | |
4289 | 0 | if (elf_section_type (section) != SHT_PROGBITS |
4290 | 0 | || (elf_section_flags (section) & SHF_EXECINSTR) == 0 |
4291 | 0 | || (section->flags & SEC_EXCLUDE) != 0 |
4292 | 0 | || (section->sec_info_type == SEC_INFO_TYPE_JUST_SYMS) |
4293 | 0 | || (section->output_section == bfd_abs_section_ptr)) |
4294 | 0 | return true; |
4295 | | |
4296 | 0 | do |
4297 | 0 | { |
4298 | 0 | bfd_byte *contents = NULL; |
4299 | 0 | struct _aarch64_elf_section_data *sec_data; |
4300 | 0 | unsigned int span; |
4301 | |
|
4302 | 0 | if (elf_section_data (section)->this_hdr.contents != NULL) |
4303 | 0 | contents = elf_section_data (section)->this_hdr.contents; |
4304 | 0 | else if (! bfd_malloc_and_get_section (input_bfd, section, &contents)) |
4305 | 0 | return false; |
4306 | | |
4307 | 0 | sec_data = elf_aarch64_section_data (section); |
4308 | |
|
4309 | 0 | if (sec_data->mapcount) |
4310 | 0 | qsort (sec_data->map, sec_data->mapcount, |
4311 | 0 | sizeof (elf_aarch64_section_map), elf_aarch64_compare_mapping); |
4312 | |
|
4313 | 0 | for (span = 0; span < sec_data->mapcount; span++) |
4314 | 0 | { |
4315 | 0 | unsigned int span_start = sec_data->map[span].vma; |
4316 | 0 | unsigned int span_end = ((span == sec_data->mapcount - 1) |
4317 | 0 | ? sec_data->map[0].vma + section->size |
4318 | 0 | : sec_data->map[span + 1].vma); |
4319 | 0 | unsigned int i; |
4320 | 0 | char span_type = sec_data->map[span].type; |
4321 | |
|
4322 | 0 | if (span_type == 'd') |
4323 | 0 | continue; |
4324 | | |
4325 | 0 | for (i = span_start; i + 8 < span_end; i += 4) |
4326 | 0 | { |
4327 | 0 | bfd_vma vma = (section->output_section->vma |
4328 | 0 | + section->output_offset |
4329 | 0 | + i); |
4330 | 0 | bfd_vma veneer_i; |
4331 | |
|
4332 | 0 | if (_bfd_aarch64_erratum_843419_p |
4333 | 0 | (contents, vma, i, span_end, &veneer_i)) |
4334 | 0 | { |
4335 | 0 | uint32_t insn = bfd_getl32 (contents + veneer_i); |
4336 | |
|
4337 | 0 | if (!_bfd_aarch64_erratum_843419_fixup (insn, i, veneer_i, |
4338 | 0 | section, info)) |
4339 | 0 | return false; |
4340 | 0 | } |
4341 | 0 | } |
4342 | 0 | } |
4343 | | |
4344 | 0 | if (elf_section_data (section)->this_hdr.contents == NULL) |
4345 | 0 | free (contents); |
4346 | 0 | } |
4347 | 0 | while (0); |
4348 | | |
4349 | 0 | return true; |
4350 | 0 | } |
4351 | | |
4352 | | |
4353 | | /* Add stub entries for calls. |
4354 | | |
4355 | | The basic idea here is to examine all the relocations looking for |
4356 | | PC-relative calls to a target that is unreachable with a "bl" |
4357 | | instruction. */ |
4358 | | |
4359 | | static bool |
4360 | | _bfd_aarch64_add_call_stub_entries (bool *stub_changed, bfd *output_bfd, |
4361 | | struct bfd_link_info *info) |
4362 | 0 | { |
4363 | 0 | struct elf_aarch64_link_hash_table *htab = elf_aarch64_hash_table (info); |
4364 | 0 | bool need_bti = elf_aarch64_bti_p (output_bfd); |
4365 | 0 | bfd *input_bfd; |
4366 | |
|
4367 | 0 | for (input_bfd = info->input_bfds; input_bfd != NULL; |
4368 | 0 | input_bfd = input_bfd->link.next) |
4369 | 0 | { |
4370 | 0 | Elf_Internal_Shdr *symtab_hdr; |
4371 | 0 | asection *section; |
4372 | 0 | Elf_Internal_Sym *local_syms = NULL; |
4373 | |
|
4374 | 0 | if (!is_aarch64_elf (input_bfd) |
4375 | 0 | || (input_bfd->flags & BFD_LINKER_CREATED) != 0) |
4376 | 0 | continue; |
4377 | | |
4378 | | /* We'll need the symbol table in a second. */ |
4379 | 0 | symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr; |
4380 | 0 | if (symtab_hdr->sh_info == 0) |
4381 | 0 | continue; |
4382 | | |
4383 | | /* Walk over each section attached to the input bfd. */ |
4384 | 0 | for (section = input_bfd->sections; |
4385 | 0 | section != NULL; section = section->next) |
4386 | 0 | { |
4387 | 0 | Elf_Internal_Rela *internal_relocs, *irelaend, *irela; |
4388 | | |
4389 | | /* If there aren't any relocs, then there's nothing more to do. */ |
4390 | 0 | if ((section->flags & SEC_RELOC) == 0 |
4391 | 0 | || section->reloc_count == 0 |
4392 | 0 | || (section->flags & SEC_CODE) == 0) |
4393 | 0 | continue; |
4394 | | |
4395 | | /* If this section is a link-once section that will be |
4396 | | discarded, then don't create any stubs. */ |
4397 | 0 | if (section->output_section == NULL |
4398 | 0 | || section->output_section->owner != output_bfd) |
4399 | 0 | continue; |
4400 | | |
4401 | | /* Get the relocs. */ |
4402 | 0 | internal_relocs |
4403 | 0 | = _bfd_elf_link_read_relocs (input_bfd, section, NULL, |
4404 | 0 | NULL, info->keep_memory); |
4405 | 0 | if (internal_relocs == NULL) |
4406 | 0 | goto error_ret_free_local; |
4407 | | |
4408 | | /* Now examine each relocation. */ |
4409 | 0 | irela = internal_relocs; |
4410 | 0 | irelaend = irela + section->reloc_count; |
4411 | 0 | for (; irela < irelaend; irela++) |
4412 | 0 | { |
4413 | 0 | unsigned int r_type, r_indx; |
4414 | 0 | enum elf_aarch64_stub_type stub_type; |
4415 | 0 | struct elf_aarch64_stub_hash_entry *stub_entry; |
4416 | 0 | struct elf_aarch64_stub_hash_entry *stub_entry_bti; |
4417 | 0 | asection *sym_sec; |
4418 | 0 | bfd_vma sym_value; |
4419 | 0 | bfd_vma destination; |
4420 | 0 | struct elf_aarch64_link_hash_entry *hash; |
4421 | 0 | const char *sym_name; |
4422 | 0 | char *stub_name; |
4423 | 0 | char *stub_name_bti; |
4424 | 0 | const asection *id_sec; |
4425 | 0 | const asection *id_sec_bti; |
4426 | 0 | unsigned char st_type; |
4427 | 0 | bfd_size_type len; |
4428 | |
|
4429 | 0 | r_type = ELF64_R_TYPE (irela->r_info); |
4430 | 0 | r_indx = ELF64_R_SYM (irela->r_info); |
4431 | |
|
4432 | 0 | if (r_type >= (unsigned int) R_AARCH64_end) |
4433 | 0 | { |
4434 | 0 | bfd_set_error (bfd_error_bad_value); |
4435 | 0 | error_ret_free_internal: |
4436 | 0 | if (elf_section_data (section)->relocs == NULL) |
4437 | 0 | free (internal_relocs); |
4438 | 0 | goto error_ret_free_local; |
4439 | 0 | } |
4440 | | |
4441 | | /* Only look for stubs on unconditional branch and |
4442 | | branch and link instructions. */ |
4443 | 0 | if (r_type != (unsigned int) AARCH64_R (CALL26) |
4444 | 0 | && r_type != (unsigned int) AARCH64_R (JUMP26)) |
4445 | 0 | continue; |
4446 | | |
4447 | | /* Now determine the call target, its name, value, |
4448 | | section. */ |
4449 | 0 | sym_sec = NULL; |
4450 | 0 | sym_value = 0; |
4451 | 0 | destination = 0; |
4452 | 0 | hash = NULL; |
4453 | 0 | sym_name = NULL; |
4454 | 0 | if (r_indx < symtab_hdr->sh_info) |
4455 | 0 | { |
4456 | | /* It's a local symbol. */ |
4457 | 0 | Elf_Internal_Sym *sym; |
4458 | 0 | Elf_Internal_Shdr *hdr; |
4459 | |
|
4460 | 0 | if (local_syms == NULL) |
4461 | 0 | { |
4462 | 0 | local_syms |
4463 | 0 | = (Elf_Internal_Sym *) symtab_hdr->contents; |
4464 | 0 | if (local_syms == NULL) |
4465 | 0 | local_syms |
4466 | 0 | = bfd_elf_get_elf_syms (input_bfd, symtab_hdr, |
4467 | 0 | symtab_hdr->sh_info, 0, |
4468 | 0 | NULL, NULL, NULL); |
4469 | 0 | if (local_syms == NULL) |
4470 | 0 | goto error_ret_free_internal; |
4471 | 0 | } |
4472 | | |
4473 | 0 | sym = local_syms + r_indx; |
4474 | 0 | hdr = elf_elfsections (input_bfd)[sym->st_shndx]; |
4475 | 0 | sym_sec = hdr->bfd_section; |
4476 | 0 | if (!sym_sec) |
4477 | | /* This is an undefined symbol. It can never |
4478 | | be resolved. */ |
4479 | 0 | continue; |
4480 | | |
4481 | 0 | if (ELF_ST_TYPE (sym->st_info) != STT_SECTION) |
4482 | 0 | sym_value = sym->st_value; |
4483 | 0 | destination = (sym_value + irela->r_addend |
4484 | 0 | + sym_sec->output_offset |
4485 | 0 | + sym_sec->output_section->vma); |
4486 | 0 | st_type = ELF_ST_TYPE (sym->st_info); |
4487 | 0 | sym_name |
4488 | 0 | = bfd_elf_string_from_elf_section (input_bfd, |
4489 | 0 | symtab_hdr->sh_link, |
4490 | 0 | sym->st_name); |
4491 | 0 | } |
4492 | 0 | else |
4493 | 0 | { |
4494 | 0 | int e_indx; |
4495 | |
|
4496 | 0 | e_indx = r_indx - symtab_hdr->sh_info; |
4497 | 0 | hash = ((struct elf_aarch64_link_hash_entry *) |
4498 | 0 | elf_sym_hashes (input_bfd)[e_indx]); |
4499 | |
|
4500 | 0 | while (hash->root.root.type == bfd_link_hash_indirect |
4501 | 0 | || hash->root.root.type == bfd_link_hash_warning) |
4502 | 0 | hash = ((struct elf_aarch64_link_hash_entry *) |
4503 | 0 | hash->root.root.u.i.link); |
4504 | |
|
4505 | 0 | if (hash->root.root.type == bfd_link_hash_defined |
4506 | 0 | || hash->root.root.type == bfd_link_hash_defweak) |
4507 | 0 | { |
4508 | 0 | struct elf_aarch64_link_hash_table *globals = |
4509 | 0 | elf_aarch64_hash_table (info); |
4510 | 0 | sym_sec = hash->root.root.u.def.section; |
4511 | 0 | sym_value = hash->root.root.u.def.value; |
4512 | | /* For a destination in a shared library, |
4513 | | use the PLT stub as target address to |
4514 | | decide whether a branch stub is |
4515 | | needed. */ |
4516 | 0 | if (globals->root.splt != NULL && hash != NULL |
4517 | 0 | && hash->root.plt.offset != (bfd_vma) - 1) |
4518 | 0 | { |
4519 | 0 | sym_sec = globals->root.splt; |
4520 | 0 | sym_value = hash->root.plt.offset; |
4521 | 0 | if (sym_sec->output_section != NULL) |
4522 | 0 | destination = (sym_value |
4523 | 0 | + sym_sec->output_offset |
4524 | 0 | + sym_sec->output_section->vma); |
4525 | 0 | } |
4526 | 0 | else if (sym_sec->output_section != NULL) |
4527 | 0 | destination = (sym_value + irela->r_addend |
4528 | 0 | + sym_sec->output_offset |
4529 | 0 | + sym_sec->output_section->vma); |
4530 | 0 | } |
4531 | 0 | else if (hash->root.root.type == bfd_link_hash_undefined |
4532 | 0 | || (hash->root.root.type |
4533 | 0 | == bfd_link_hash_undefweak)) |
4534 | 0 | { |
4535 | | /* For a shared library, use the PLT stub as |
4536 | | target address to decide whether a long |
4537 | | branch stub is needed. |
4538 | | For absolute code, they cannot be handled. */ |
4539 | 0 | struct elf_aarch64_link_hash_table *globals = |
4540 | 0 | elf_aarch64_hash_table (info); |
4541 | |
|
4542 | 0 | if (globals->root.splt != NULL && hash != NULL |
4543 | 0 | && hash->root.plt.offset != (bfd_vma) - 1) |
4544 | 0 | { |
4545 | 0 | sym_sec = globals->root.splt; |
4546 | 0 | sym_value = hash->root.plt.offset; |
4547 | 0 | if (sym_sec->output_section != NULL) |
4548 | 0 | destination = (sym_value |
4549 | 0 | + sym_sec->output_offset |
4550 | 0 | + sym_sec->output_section->vma); |
4551 | 0 | } |
4552 | 0 | else |
4553 | 0 | continue; |
4554 | 0 | } |
4555 | 0 | else |
4556 | 0 | { |
4557 | 0 | bfd_set_error (bfd_error_bad_value); |
4558 | 0 | goto error_ret_free_internal; |
4559 | 0 | } |
4560 | 0 | st_type = ELF_ST_TYPE (hash->root.type); |
4561 | 0 | sym_name = hash->root.root.root.string; |
4562 | 0 | } |
4563 | | |
4564 | | /* Determine what (if any) linker stub is needed. */ |
4565 | 0 | stub_type = aarch64_type_of_stub (section, irela, sym_sec, |
4566 | 0 | st_type, destination); |
4567 | 0 | if (stub_type == aarch64_stub_none) |
4568 | 0 | continue; |
4569 | | |
4570 | | /* Support for grouping stub sections. */ |
4571 | 0 | id_sec = htab->stub_group[section->id].link_sec; |
4572 | | |
4573 | | /* Get the name of this stub. */ |
4574 | 0 | stub_name = elf64_aarch64_stub_name (id_sec, sym_sec, hash, |
4575 | 0 | irela); |
4576 | 0 | if (!stub_name) |
4577 | 0 | goto error_ret_free_internal; |
4578 | | |
4579 | 0 | stub_entry = |
4580 | 0 | aarch64_stub_hash_lookup (&htab->stub_hash_table, |
4581 | 0 | stub_name, false, false); |
4582 | 0 | if (stub_entry != NULL) |
4583 | 0 | { |
4584 | | /* The proper stub has already been created. */ |
4585 | 0 | free (stub_name); |
4586 | | |
4587 | | /* Always update this stub's target since it may have |
4588 | | changed after layout. */ |
4589 | 0 | stub_entry->target_value = sym_value + irela->r_addend; |
4590 | |
|
4591 | 0 | if (stub_entry->double_stub) |
4592 | 0 | { |
4593 | | /* Update the target of both stubs. */ |
4594 | |
|
4595 | 0 | id_sec_bti = htab->stub_group[sym_sec->id].link_sec; |
4596 | 0 | stub_name_bti = |
4597 | 0 | elf64_aarch64_stub_name (id_sec_bti, sym_sec, hash, |
4598 | 0 | irela); |
4599 | 0 | if (!stub_name_bti) |
4600 | 0 | goto error_ret_free_internal; |
4601 | 0 | stub_entry_bti = |
4602 | 0 | aarch64_stub_hash_lookup (&htab->stub_hash_table, |
4603 | 0 | stub_name_bti, false, false); |
4604 | 0 | BFD_ASSERT (stub_entry_bti != NULL); |
4605 | 0 | free (stub_name_bti); |
4606 | 0 | stub_entry_bti->target_value = stub_entry->target_value; |
4607 | 0 | stub_entry->target_value = stub_entry_bti->stub_offset; |
4608 | 0 | } |
4609 | 0 | continue; |
4610 | 0 | } |
4611 | | |
4612 | 0 | stub_entry = _bfd_aarch64_add_stub_entry_in_group |
4613 | 0 | (stub_name, section, htab); |
4614 | 0 | if (stub_entry == NULL) |
4615 | 0 | { |
4616 | 0 | free (stub_name); |
4617 | 0 | goto error_ret_free_internal; |
4618 | 0 | } |
4619 | | |
4620 | 0 | stub_entry->target_value = sym_value + irela->r_addend; |
4621 | 0 | stub_entry->target_section = sym_sec; |
4622 | 0 | stub_entry->stub_type = stub_type; |
4623 | 0 | stub_entry->h = hash; |
4624 | 0 | stub_entry->st_type = st_type; |
4625 | |
|
4626 | 0 | if (sym_name == NULL) |
4627 | 0 | sym_name = "unnamed"; |
4628 | 0 | len = sizeof (STUB_ENTRY_NAME) + strlen (sym_name); |
4629 | 0 | stub_entry->output_name = bfd_alloc (htab->stub_bfd, len); |
4630 | 0 | if (stub_entry->output_name == NULL) |
4631 | 0 | { |
4632 | 0 | free (stub_name); |
4633 | 0 | goto error_ret_free_internal; |
4634 | 0 | } |
4635 | | |
4636 | 0 | snprintf (stub_entry->output_name, len, STUB_ENTRY_NAME, |
4637 | 0 | sym_name); |
4638 | | |
4639 | | /* A stub with indirect jump may break BTI compatibility, so |
4640 | | insert another stub with direct jump near the target then. */ |
4641 | 0 | if (need_bti && !aarch64_bti_stub_p (input_bfd, stub_entry)) |
4642 | 0 | { |
4643 | 0 | stub_entry->double_stub = true; |
4644 | 0 | htab->has_double_stub = true; |
4645 | 0 | id_sec_bti = htab->stub_group[sym_sec->id].link_sec; |
4646 | 0 | stub_name_bti = |
4647 | 0 | elf64_aarch64_stub_name (id_sec_bti, sym_sec, hash, irela); |
4648 | 0 | if (!stub_name_bti) |
4649 | 0 | { |
4650 | 0 | free (stub_name); |
4651 | 0 | goto error_ret_free_internal; |
4652 | 0 | } |
4653 | | |
4654 | 0 | stub_entry_bti = |
4655 | 0 | aarch64_stub_hash_lookup (&htab->stub_hash_table, |
4656 | 0 | stub_name_bti, false, false); |
4657 | 0 | if (stub_entry_bti == NULL) |
4658 | 0 | stub_entry_bti = |
4659 | 0 | _bfd_aarch64_add_stub_entry_in_group (stub_name_bti, |
4660 | 0 | sym_sec, htab); |
4661 | 0 | if (stub_entry_bti == NULL) |
4662 | 0 | { |
4663 | 0 | free (stub_name); |
4664 | 0 | free (stub_name_bti); |
4665 | 0 | goto error_ret_free_internal; |
4666 | 0 | } |
4667 | | |
4668 | 0 | stub_entry_bti->target_value = sym_value + irela->r_addend; |
4669 | 0 | stub_entry_bti->target_section = sym_sec; |
4670 | 0 | stub_entry_bti->stub_type = aarch64_stub_bti_direct_branch; |
4671 | 0 | stub_entry_bti->h = hash; |
4672 | 0 | stub_entry_bti->st_type = st_type; |
4673 | |
|
4674 | 0 | len = sizeof (BTI_STUB_ENTRY_NAME) + strlen (sym_name); |
4675 | 0 | stub_entry_bti->output_name = bfd_alloc (htab->stub_bfd, len); |
4676 | 0 | if (stub_entry_bti->output_name == NULL) |
4677 | 0 | { |
4678 | 0 | free (stub_name); |
4679 | 0 | free (stub_name_bti); |
4680 | 0 | goto error_ret_free_internal; |
4681 | 0 | } |
4682 | 0 | snprintf (stub_entry_bti->output_name, len, |
4683 | 0 | BTI_STUB_ENTRY_NAME, sym_name); |
4684 | | |
4685 | | /* Update the indirect call stub to target the BTI stub. */ |
4686 | 0 | stub_entry->target_value = 0; |
4687 | 0 | stub_entry->target_section = stub_entry_bti->stub_sec; |
4688 | 0 | stub_entry->stub_type = stub_type; |
4689 | 0 | stub_entry->h = NULL; |
4690 | 0 | stub_entry->st_type = STT_FUNC; |
4691 | 0 | } |
4692 | | |
4693 | 0 | *stub_changed = true; |
4694 | 0 | } |
4695 | | |
4696 | | /* We're done with the internal relocs, free them. */ |
4697 | 0 | if (elf_section_data (section)->relocs == NULL) |
4698 | 0 | free (internal_relocs); |
4699 | 0 | } |
4700 | 0 | } |
4701 | 0 | return true; |
4702 | 0 | error_ret_free_local: |
4703 | 0 | return false; |
4704 | 0 | } |
4705 | | |
4706 | | |
4707 | | /* Determine and set the size of the stub section for a final link. */ |
4708 | | |
4709 | | bool |
4710 | | elf64_aarch64_size_stubs (bfd *output_bfd, |
4711 | | bfd *stub_bfd, |
4712 | | struct bfd_link_info *info, |
4713 | | bfd_signed_vma group_size, |
4714 | | asection * (*add_stub_section) (const char *, |
4715 | | asection *), |
4716 | | void (*layout_sections_again) (void)) |
4717 | 0 | { |
4718 | 0 | bfd_size_type stub_group_size; |
4719 | 0 | bool stubs_always_before_branch; |
4720 | 0 | struct elf_aarch64_link_hash_table *htab = elf_aarch64_hash_table (info); |
4721 | 0 | unsigned int num_erratum_835769_fixes = 0; |
4722 | | |
4723 | | /* Propagate mach to stub bfd, because it may not have been |
4724 | | finalized when we created stub_bfd. */ |
4725 | 0 | bfd_set_arch_mach (stub_bfd, bfd_get_arch (output_bfd), |
4726 | 0 | bfd_get_mach (output_bfd)); |
4727 | | |
4728 | | /* Stash our params away. */ |
4729 | 0 | htab->stub_bfd = stub_bfd; |
4730 | 0 | htab->add_stub_section = add_stub_section; |
4731 | 0 | htab->layout_sections_again = layout_sections_again; |
4732 | 0 | stubs_always_before_branch = group_size < 0; |
4733 | 0 | if (group_size < 0) |
4734 | 0 | stub_group_size = -group_size; |
4735 | 0 | else |
4736 | 0 | stub_group_size = group_size; |
4737 | |
|
4738 | 0 | if (stub_group_size == 1) |
4739 | 0 | { |
4740 | | /* Default values. */ |
4741 | | /* AArch64 branch range is +-128MB. The value used is 1MB less. */ |
4742 | 0 | stub_group_size = 127 * 1024 * 1024; |
4743 | 0 | } |
4744 | |
|
4745 | 0 | group_sections (htab, stub_group_size, stubs_always_before_branch); |
4746 | |
|
4747 | 0 | (*htab->layout_sections_again) (); |
4748 | |
|
4749 | 0 | if (htab->fix_erratum_835769) |
4750 | 0 | { |
4751 | 0 | bfd *input_bfd; |
4752 | |
|
4753 | 0 | for (input_bfd = info->input_bfds; |
4754 | 0 | input_bfd != NULL; input_bfd = input_bfd->link.next) |
4755 | 0 | { |
4756 | 0 | if (!is_aarch64_elf (input_bfd) |
4757 | 0 | || (input_bfd->flags & BFD_LINKER_CREATED) != 0) |
4758 | 0 | continue; |
4759 | | |
4760 | 0 | if (!_bfd_aarch64_erratum_835769_scan (input_bfd, info, |
4761 | 0 | &num_erratum_835769_fixes)) |
4762 | 0 | return false; |
4763 | 0 | } |
4764 | | |
4765 | 0 | _bfd_aarch64_resize_stubs (htab); |
4766 | 0 | (*htab->layout_sections_again) (); |
4767 | 0 | } |
4768 | | |
4769 | 0 | if (htab->fix_erratum_843419 != ERRAT_NONE) |
4770 | 0 | { |
4771 | 0 | bfd *input_bfd; |
4772 | |
|
4773 | 0 | for (input_bfd = info->input_bfds; |
4774 | 0 | input_bfd != NULL; |
4775 | 0 | input_bfd = input_bfd->link.next) |
4776 | 0 | { |
4777 | 0 | asection *section; |
4778 | |
|
4779 | 0 | if (!is_aarch64_elf (input_bfd) |
4780 | 0 | || (input_bfd->flags & BFD_LINKER_CREATED) != 0) |
4781 | 0 | continue; |
4782 | | |
4783 | 0 | for (section = input_bfd->sections; |
4784 | 0 | section != NULL; |
4785 | 0 | section = section->next) |
4786 | 0 | if (!_bfd_aarch64_erratum_843419_scan (input_bfd, section, info)) |
4787 | 0 | return false; |
4788 | 0 | } |
4789 | | |
4790 | 0 | _bfd_aarch64_resize_stubs (htab); |
4791 | 0 | (*htab->layout_sections_again) (); |
4792 | 0 | } |
4793 | | |
4794 | 0 | for (;;) |
4795 | 0 | { |
4796 | 0 | bool stub_changed = false; |
4797 | |
|
4798 | 0 | if (!_bfd_aarch64_add_call_stub_entries (&stub_changed, output_bfd, info)) |
4799 | 0 | return false; |
4800 | | |
4801 | 0 | if (!stub_changed) |
4802 | 0 | return true; |
4803 | | |
4804 | 0 | _bfd_aarch64_resize_stubs (htab); |
4805 | 0 | (*htab->layout_sections_again) (); |
4806 | 0 | } |
4807 | 0 | } |
4808 | | |
4809 | | /* Build all the stubs associated with the current output file. The |
4810 | | stubs are kept in a hash table attached to the main linker hash |
4811 | | table. We also set up the .plt entries for statically linked PIC |
4812 | | functions here. This function is called via aarch64_elf_finish in the |
4813 | | linker. */ |
4814 | | |
4815 | | bool |
4816 | | elf64_aarch64_build_stubs (struct bfd_link_info *info) |
4817 | 0 | { |
4818 | 0 | asection *stub_sec; |
4819 | 0 | struct bfd_hash_table *table; |
4820 | 0 | struct elf_aarch64_link_hash_table *htab; |
4821 | |
|
4822 | 0 | htab = elf_aarch64_hash_table (info); |
4823 | |
|
4824 | 0 | for (stub_sec = htab->stub_bfd->sections; |
4825 | 0 | stub_sec != NULL; stub_sec = stub_sec->next) |
4826 | 0 | { |
4827 | 0 | bfd_size_type size; |
4828 | | |
4829 | | /* Ignore non-stub sections. */ |
4830 | 0 | if (!strstr (stub_sec->name, STUB_SUFFIX)) |
4831 | 0 | continue; |
4832 | | |
4833 | | /* Allocate memory to hold the linker stubs. */ |
4834 | 0 | size = stub_sec->size; |
4835 | 0 | stub_sec->contents = bfd_zalloc (htab->stub_bfd, size); |
4836 | 0 | if (stub_sec->contents == NULL && size != 0) |
4837 | 0 | return false; |
4838 | 0 | stub_sec->size = 0; |
4839 | | |
4840 | | /* Add a branch around the stub section, and a nop, to keep it 8 byte |
4841 | | aligned, as long branch stubs contain a 64-bit address. */ |
4842 | 0 | bfd_putl32 (0x14000000 | (size >> 2), stub_sec->contents); |
4843 | 0 | bfd_putl32 (INSN_NOP, stub_sec->contents + 4); |
4844 | 0 | stub_sec->size += 8; |
4845 | 0 | } |
4846 | | |
4847 | | /* Build the stubs as directed by the stub hash table. */ |
4848 | 0 | table = &htab->stub_hash_table; |
4849 | 0 | bfd_hash_traverse (table, aarch64_build_one_stub, info); |
4850 | |
|
4851 | 0 | return true; |
4852 | 0 | } |
4853 | | |
4854 | | |
4855 | | /* Add an entry to the code/data map for section SEC. */ |
4856 | | |
4857 | | static void |
4858 | | elf64_aarch64_section_map_add (asection *sec, char type, bfd_vma vma) |
4859 | 0 | { |
4860 | 0 | struct _aarch64_elf_section_data *sec_data = |
4861 | 0 | elf_aarch64_section_data (sec); |
4862 | 0 | unsigned int newidx; |
4863 | |
|
4864 | 0 | if (sec_data->map == NULL) |
4865 | 0 | { |
4866 | 0 | sec_data->map = bfd_malloc (sizeof (elf_aarch64_section_map)); |
4867 | 0 | sec_data->mapcount = 0; |
4868 | 0 | sec_data->mapsize = 1; |
4869 | 0 | } |
4870 | |
|
4871 | 0 | newidx = sec_data->mapcount++; |
4872 | |
|
4873 | 0 | if (sec_data->mapcount > sec_data->mapsize) |
4874 | 0 | { |
4875 | 0 | sec_data->mapsize *= 2; |
4876 | 0 | sec_data->map = bfd_realloc_or_free |
4877 | 0 | (sec_data->map, sec_data->mapsize * sizeof (elf_aarch64_section_map)); |
4878 | 0 | } |
4879 | |
|
4880 | 0 | if (sec_data->map) |
4881 | 0 | { |
4882 | 0 | sec_data->map[newidx].vma = vma; |
4883 | 0 | sec_data->map[newidx].type = type; |
4884 | 0 | } |
4885 | 0 | } |
4886 | | |
4887 | | |
4888 | | /* Initialise maps of insn/data for input BFDs. */ |
4889 | | void |
4890 | | bfd_elf64_aarch64_init_maps (bfd *abfd) |
4891 | 0 | { |
4892 | 0 | Elf_Internal_Sym *isymbuf; |
4893 | 0 | Elf_Internal_Shdr *hdr; |
4894 | 0 | unsigned int i, localsyms; |
4895 | | |
4896 | | /* Make sure that we are dealing with an AArch64 elf binary. */ |
4897 | 0 | if (!is_aarch64_elf (abfd)) |
4898 | 0 | return; |
4899 | | |
4900 | 0 | if ((abfd->flags & DYNAMIC) != 0) |
4901 | 0 | return; |
4902 | | |
4903 | 0 | hdr = &elf_symtab_hdr (abfd); |
4904 | 0 | localsyms = hdr->sh_info; |
4905 | | |
4906 | | /* Obtain a buffer full of symbols for this BFD. The hdr->sh_info field |
4907 | | should contain the number of local symbols, which should come before any |
4908 | | global symbols. Mapping symbols are always local. */ |
4909 | 0 | isymbuf = bfd_elf_get_elf_syms (abfd, hdr, localsyms, 0, NULL, NULL, NULL); |
4910 | | |
4911 | | /* No internal symbols read? Skip this BFD. */ |
4912 | 0 | if (isymbuf == NULL) |
4913 | 0 | return; |
4914 | | |
4915 | 0 | for (i = 0; i < localsyms; i++) |
4916 | 0 | { |
4917 | 0 | Elf_Internal_Sym *isym = &isymbuf[i]; |
4918 | 0 | asection *sec = bfd_section_from_elf_index (abfd, isym->st_shndx); |
4919 | 0 | const char *name; |
4920 | |
|
4921 | 0 | if (sec != NULL && ELF_ST_BIND (isym->st_info) == STB_LOCAL) |
4922 | 0 | { |
4923 | 0 | name = bfd_elf_string_from_elf_section (abfd, |
4924 | 0 | hdr->sh_link, |
4925 | 0 | isym->st_name); |
4926 | |
|
4927 | 0 | if (bfd_is_aarch64_special_symbol_name |
4928 | 0 | (name, BFD_AARCH64_SPECIAL_SYM_TYPE_MAP)) |
4929 | 0 | elf64_aarch64_section_map_add (sec, name[1], isym->st_value); |
4930 | 0 | } |
4931 | 0 | } |
4932 | 0 | } |
4933 | | |
4934 | | static void |
4935 | | setup_plt_values (struct bfd_link_info *link_info, |
4936 | | aarch64_plt_type plt_type) |
4937 | 0 | { |
4938 | 0 | struct elf_aarch64_link_hash_table *globals; |
4939 | 0 | globals = elf_aarch64_hash_table (link_info); |
4940 | |
|
4941 | 0 | if (plt_type == PLT_BTI_PAC) |
4942 | 0 | { |
4943 | 0 | globals->plt0_entry = elf64_aarch64_small_plt0_bti_entry; |
4944 | | |
4945 | | /* Only in ET_EXEC we need PLTn with BTI. */ |
4946 | 0 | if (bfd_link_pde (link_info)) |
4947 | 0 | { |
4948 | 0 | globals->plt_entry_size = PLT_BTI_PAC_SMALL_ENTRY_SIZE; |
4949 | 0 | globals->plt_entry = elf64_aarch64_small_plt_bti_pac_entry; |
4950 | 0 | } |
4951 | 0 | else |
4952 | 0 | { |
4953 | 0 | globals->plt_entry_size = PLT_PAC_SMALL_ENTRY_SIZE; |
4954 | 0 | globals->plt_entry = elf64_aarch64_small_plt_pac_entry; |
4955 | 0 | } |
4956 | 0 | } |
4957 | 0 | else if (plt_type == PLT_BTI) |
4958 | 0 | { |
4959 | 0 | globals->plt0_entry = elf64_aarch64_small_plt0_bti_entry; |
4960 | | |
4961 | | /* Only in ET_EXEC we need PLTn with BTI. */ |
4962 | 0 | if (bfd_link_pde (link_info)) |
4963 | 0 | { |
4964 | 0 | globals->plt_entry_size = PLT_BTI_SMALL_ENTRY_SIZE; |
4965 | 0 | globals->plt_entry = elf64_aarch64_small_plt_bti_entry; |
4966 | 0 | } |
4967 | 0 | } |
4968 | 0 | else if (plt_type == PLT_PAC) |
4969 | 0 | { |
4970 | 0 | globals->plt_entry_size = PLT_PAC_SMALL_ENTRY_SIZE; |
4971 | 0 | globals->plt_entry = elf64_aarch64_small_plt_pac_entry; |
4972 | 0 | } |
4973 | 0 | } |
4974 | | |
4975 | | /* Set option values needed during linking. */ |
4976 | | void |
4977 | | bfd_elf64_aarch64_set_options (struct bfd *output_bfd, |
4978 | | struct bfd_link_info *link_info, |
4979 | | int no_enum_warn, |
4980 | | int no_wchar_warn, int pic_veneer, |
4981 | | int fix_erratum_835769, |
4982 | | erratum_84319_opts fix_erratum_843419, |
4983 | | int no_apply_dynamic_relocs, |
4984 | | aarch64_bti_pac_info bp_info) |
4985 | 0 | { |
4986 | 0 | struct elf_aarch64_link_hash_table *globals; |
4987 | |
|
4988 | 0 | globals = elf_aarch64_hash_table (link_info); |
4989 | 0 | globals->pic_veneer = pic_veneer; |
4990 | 0 | globals->fix_erratum_835769 = fix_erratum_835769; |
4991 | | /* If the default options are used, then ERRAT_ADR will be set by default |
4992 | | which will enable the ADRP->ADR workaround for the erratum 843419 |
4993 | | workaround. */ |
4994 | 0 | globals->fix_erratum_843419 = fix_erratum_843419; |
4995 | 0 | globals->no_apply_dynamic_relocs = no_apply_dynamic_relocs; |
4996 | |
|
4997 | 0 | BFD_ASSERT (is_aarch64_elf (output_bfd)); |
4998 | 0 | elf_aarch64_tdata (output_bfd)->no_enum_size_warning = no_enum_warn; |
4999 | 0 | elf_aarch64_tdata (output_bfd)->no_wchar_size_warning = no_wchar_warn; |
5000 | |
|
5001 | 0 | switch (bp_info.bti_type) |
5002 | 0 | { |
5003 | 0 | case BTI_WARN: |
5004 | 0 | elf_aarch64_tdata (output_bfd)->no_bti_warn = 0; |
5005 | 0 | elf_aarch64_tdata (output_bfd)->gnu_and_prop |
5006 | 0 | |= GNU_PROPERTY_AARCH64_FEATURE_1_BTI; |
5007 | 0 | break; |
5008 | | |
5009 | 0 | default: |
5010 | 0 | break; |
5011 | 0 | } |
5012 | 0 | elf_aarch64_tdata (output_bfd)->plt_type = bp_info.plt_type; |
5013 | 0 | setup_plt_values (link_info, bp_info.plt_type); |
5014 | 0 | } |
5015 | | |
5016 | | static bfd_vma |
5017 | | aarch64_calculate_got_entry_vma (struct elf_link_hash_entry *h, |
5018 | | struct elf_aarch64_link_hash_table |
5019 | | *globals, struct bfd_link_info *info, |
5020 | | bfd_vma value, bfd *output_bfd, |
5021 | | bool *unresolved_reloc_p) |
5022 | 0 | { |
5023 | 0 | bfd_vma off = (bfd_vma) - 1; |
5024 | 0 | asection *basegot = globals->root.sgot; |
5025 | 0 | bool dyn = globals->root.dynamic_sections_created; |
5026 | |
|
5027 | 0 | if (h != NULL) |
5028 | 0 | { |
5029 | 0 | BFD_ASSERT (basegot != NULL); |
5030 | 0 | off = h->got.offset; |
5031 | 0 | BFD_ASSERT (off != (bfd_vma) - 1); |
5032 | 0 | if (!WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, bfd_link_pic (info), h) |
5033 | 0 | || (bfd_link_pic (info) |
5034 | 0 | && SYMBOL_REFERENCES_LOCAL (info, h)) |
5035 | 0 | || (ELF_ST_VISIBILITY (h->other) |
5036 | 0 | && h->root.type == bfd_link_hash_undefweak)) |
5037 | 0 | { |
5038 | | /* This is actually a static link, or it is a -Bsymbolic link |
5039 | | and the symbol is defined locally. We must initialize this |
5040 | | entry in the global offset table. Since the offset must |
5041 | | always be a multiple of 8 (4 in the case of ILP32), we use |
5042 | | the least significant bit to record whether we have |
5043 | | initialized it already. |
5044 | | When doing a dynamic link, we create a .rel(a).got relocation |
5045 | | entry to initialize the value. This is done in the |
5046 | | finish_dynamic_symbol routine. */ |
5047 | 0 | if ((off & 1) != 0) |
5048 | 0 | off &= ~1; |
5049 | 0 | else |
5050 | 0 | { |
5051 | 0 | bfd_put_64 (output_bfd, value, basegot->contents + off); |
5052 | 0 | h->got.offset |= 1; |
5053 | 0 | } |
5054 | 0 | } |
5055 | 0 | else |
5056 | 0 | *unresolved_reloc_p = false; |
5057 | |
|
5058 | 0 | off = off + basegot->output_section->vma + basegot->output_offset; |
5059 | 0 | } |
5060 | |
|
5061 | 0 | return off; |
5062 | 0 | } |
5063 | | |
5064 | | /* Change R_TYPE to a more efficient access model where possible, |
5065 | | return the new reloc type. */ |
5066 | | |
5067 | | static bfd_reloc_code_real_type |
5068 | | aarch64_tls_transition_without_check (bfd_reloc_code_real_type r_type, |
5069 | | struct elf_link_hash_entry *h, |
5070 | | struct bfd_link_info *info) |
5071 | 0 | { |
5072 | 0 | bool local_exec = bfd_link_executable (info) |
5073 | 0 | && SYMBOL_REFERENCES_LOCAL (info, h); |
5074 | |
|
5075 | 0 | switch (r_type) |
5076 | 0 | { |
5077 | 0 | case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21: |
5078 | 0 | case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21: |
5079 | 0 | return (local_exec |
5080 | 0 | ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1 |
5081 | 0 | : BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21); |
5082 | | |
5083 | 0 | case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21: |
5084 | 0 | return (local_exec |
5085 | 0 | ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC |
5086 | 0 | : r_type); |
5087 | | |
5088 | 0 | case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19: |
5089 | 0 | return (local_exec |
5090 | 0 | ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1 |
5091 | 0 | : BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19); |
5092 | | |
5093 | 0 | case BFD_RELOC_AARCH64_TLSDESC_LDR: |
5094 | 0 | return (local_exec |
5095 | 0 | ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC |
5096 | 0 | : BFD_RELOC_AARCH64_NONE); |
5097 | | |
5098 | 0 | case BFD_RELOC_AARCH64_TLSDESC_OFF_G0_NC: |
5099 | 0 | return (local_exec |
5100 | 0 | ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1_NC |
5101 | 0 | : BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G0_NC); |
5102 | | |
5103 | 0 | case BFD_RELOC_AARCH64_TLSDESC_OFF_G1: |
5104 | 0 | return (local_exec |
5105 | 0 | ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G2 |
5106 | 0 | : BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G1); |
5107 | | |
5108 | 0 | case BFD_RELOC_AARCH64_TLSDESC_LD64_LO12_NC: |
5109 | 0 | case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC: |
5110 | 0 | return (local_exec |
5111 | 0 | ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC |
5112 | 0 | : BFD_RELOC_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC); |
5113 | | |
5114 | 0 | case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21: |
5115 | 0 | return local_exec ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1 : r_type; |
5116 | | |
5117 | 0 | case BFD_RELOC_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC: |
5118 | 0 | return local_exec ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC : r_type; |
5119 | | |
5120 | 0 | case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19: |
5121 | 0 | return r_type; |
5122 | | |
5123 | 0 | case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21: |
5124 | 0 | return (local_exec |
5125 | 0 | ? BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_HI12 |
5126 | 0 | : BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19); |
5127 | | |
5128 | 0 | case BFD_RELOC_AARCH64_TLSDESC_ADD: |
5129 | 0 | case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12: |
5130 | 0 | case BFD_RELOC_AARCH64_TLSDESC_CALL: |
5131 | | /* Instructions with these relocations will become NOPs. */ |
5132 | 0 | return BFD_RELOC_AARCH64_NONE; |
5133 | | |
5134 | 0 | case BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC: |
5135 | 0 | case BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21: |
5136 | 0 | case BFD_RELOC_AARCH64_TLSLD_ADR_PREL21: |
5137 | 0 | return local_exec ? BFD_RELOC_AARCH64_NONE : r_type; |
5138 | | |
5139 | 0 | #if ARCH_SIZE == 64 |
5140 | 0 | case BFD_RELOC_AARCH64_TLSGD_MOVW_G0_NC: |
5141 | 0 | return local_exec |
5142 | 0 | ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1_NC |
5143 | 0 | : BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G0_NC; |
5144 | | |
5145 | 0 | case BFD_RELOC_AARCH64_TLSGD_MOVW_G1: |
5146 | 0 | return local_exec |
5147 | 0 | ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G2 |
5148 | 0 | : BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G1; |
5149 | 0 | #endif |
5150 | | |
5151 | 0 | default: |
5152 | 0 | break; |
5153 | 0 | } |
5154 | | |
5155 | 0 | return r_type; |
5156 | 0 | } |
5157 | | |
5158 | | static unsigned int |
5159 | | aarch64_reloc_got_type (bfd_reloc_code_real_type r_type) |
5160 | 0 | { |
5161 | 0 | switch (r_type) |
5162 | 0 | { |
5163 | 0 | case BFD_RELOC_AARCH64_ADR_GOT_PAGE: |
5164 | 0 | case BFD_RELOC_AARCH64_GOT_LD_PREL19: |
5165 | 0 | case BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14: |
5166 | 0 | case BFD_RELOC_AARCH64_LD32_GOT_LO12_NC: |
5167 | 0 | case BFD_RELOC_AARCH64_LD64_GOTOFF_LO15: |
5168 | 0 | case BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15: |
5169 | 0 | case BFD_RELOC_AARCH64_LD64_GOT_LO12_NC: |
5170 | 0 | case BFD_RELOC_AARCH64_MOVW_GOTOFF_G0_NC: |
5171 | 0 | case BFD_RELOC_AARCH64_MOVW_GOTOFF_G1: |
5172 | 0 | return GOT_NORMAL; |
5173 | | |
5174 | 0 | case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC: |
5175 | 0 | case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21: |
5176 | 0 | case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21: |
5177 | 0 | case BFD_RELOC_AARCH64_TLSGD_MOVW_G0_NC: |
5178 | 0 | case BFD_RELOC_AARCH64_TLSGD_MOVW_G1: |
5179 | 0 | case BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC: |
5180 | 0 | case BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21: |
5181 | 0 | case BFD_RELOC_AARCH64_TLSLD_ADR_PREL21: |
5182 | 0 | return GOT_TLS_GD; |
5183 | | |
5184 | 0 | case BFD_RELOC_AARCH64_TLSDESC_ADD: |
5185 | 0 | case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12: |
5186 | 0 | case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21: |
5187 | 0 | case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21: |
5188 | 0 | case BFD_RELOC_AARCH64_TLSDESC_CALL: |
5189 | 0 | case BFD_RELOC_AARCH64_TLSDESC_LD32_LO12_NC: |
5190 | 0 | case BFD_RELOC_AARCH64_TLSDESC_LD64_LO12: |
5191 | 0 | case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19: |
5192 | 0 | case BFD_RELOC_AARCH64_TLSDESC_LDR: |
5193 | 0 | case BFD_RELOC_AARCH64_TLSDESC_OFF_G0_NC: |
5194 | 0 | case BFD_RELOC_AARCH64_TLSDESC_OFF_G1: |
5195 | 0 | return GOT_TLSDESC_GD; |
5196 | | |
5197 | 0 | case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21: |
5198 | 0 | case BFD_RELOC_AARCH64_TLSIE_LD32_GOTTPREL_LO12_NC: |
5199 | 0 | case BFD_RELOC_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC: |
5200 | 0 | case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19: |
5201 | 0 | case BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G0_NC: |
5202 | 0 | case BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G1: |
5203 | 0 | return GOT_TLS_IE; |
5204 | | |
5205 | 0 | default: |
5206 | 0 | break; |
5207 | 0 | } |
5208 | 0 | return GOT_UNKNOWN; |
5209 | 0 | } |
5210 | | |
5211 | | static bool |
5212 | | aarch64_can_relax_tls (bfd *input_bfd, |
5213 | | struct bfd_link_info *info, |
5214 | | bfd_reloc_code_real_type r_type, |
5215 | | struct elf_link_hash_entry *h, |
5216 | | unsigned long r_symndx) |
5217 | 0 | { |
5218 | 0 | unsigned int symbol_got_type; |
5219 | 0 | unsigned int reloc_got_type; |
5220 | |
|
5221 | 0 | if (! IS_AARCH64_TLS_RELAX_RELOC (r_type)) |
5222 | 0 | return false; |
5223 | | |
5224 | 0 | symbol_got_type = elf64_aarch64_symbol_got_type (h, input_bfd, r_symndx); |
5225 | 0 | reloc_got_type = aarch64_reloc_got_type (r_type); |
5226 | |
|
5227 | 0 | if (symbol_got_type == GOT_TLS_IE && GOT_TLS_GD_ANY_P (reloc_got_type)) |
5228 | 0 | return true; |
5229 | | |
5230 | 0 | if (!bfd_link_executable (info)) |
5231 | 0 | return false; |
5232 | | |
5233 | 0 | if (h && h->root.type == bfd_link_hash_undefweak) |
5234 | 0 | return false; |
5235 | | |
5236 | 0 | return true; |
5237 | 0 | } |
5238 | | |
5239 | | /* Given the relocation code R_TYPE, return the relaxed bfd reloc |
5240 | | enumerator. */ |
5241 | | |
5242 | | static bfd_reloc_code_real_type |
5243 | | aarch64_tls_transition (bfd *input_bfd, |
5244 | | struct bfd_link_info *info, |
5245 | | unsigned int r_type, |
5246 | | struct elf_link_hash_entry *h, |
5247 | | unsigned long r_symndx) |
5248 | 0 | { |
5249 | 0 | bfd_reloc_code_real_type bfd_r_type |
5250 | 0 | = elf64_aarch64_bfd_reloc_from_type (input_bfd, r_type); |
5251 | |
|
5252 | 0 | if (! aarch64_can_relax_tls (input_bfd, info, bfd_r_type, h, r_symndx)) |
5253 | 0 | return bfd_r_type; |
5254 | | |
5255 | 0 | return aarch64_tls_transition_without_check (bfd_r_type, h, info); |
5256 | 0 | } |
5257 | | |
5258 | | /* Return the base VMA address which should be subtracted from real addresses |
5259 | | when resolving R_AARCH64_TLS_DTPREL relocation. */ |
5260 | | |
5261 | | static bfd_vma |
5262 | | dtpoff_base (struct bfd_link_info *info) |
5263 | 0 | { |
5264 | | /* If tls_sec is NULL, we should have signalled an error already. */ |
5265 | 0 | BFD_ASSERT (elf_hash_table (info)->tls_sec != NULL); |
5266 | 0 | return elf_hash_table (info)->tls_sec->vma; |
5267 | 0 | } |
5268 | | |
5269 | | /* Return the base VMA address which should be subtracted from real addresses |
5270 | | when resolving R_AARCH64_TLS_GOTTPREL64 relocations. */ |
5271 | | |
5272 | | static bfd_vma |
5273 | | tpoff_base (struct bfd_link_info *info) |
5274 | 0 | { |
5275 | 0 | struct elf_link_hash_table *htab = elf_hash_table (info); |
5276 | | |
5277 | | /* If tls_sec is NULL, we should have signalled an error already. */ |
5278 | 0 | BFD_ASSERT (htab->tls_sec != NULL); |
5279 | |
|
5280 | 0 | bfd_vma base = align_power ((bfd_vma) TCB_SIZE, |
5281 | 0 | htab->tls_sec->alignment_power); |
5282 | 0 | return htab->tls_sec->vma - base; |
5283 | 0 | } |
5284 | | |
5285 | | static bfd_vma * |
5286 | | symbol_got_offset_ref (bfd *input_bfd, struct elf_link_hash_entry *h, |
5287 | | unsigned long r_symndx) |
5288 | 0 | { |
5289 | | /* Calculate the address of the GOT entry for symbol |
5290 | | referred to in h. */ |
5291 | 0 | if (h != NULL) |
5292 | 0 | return &h->got.offset; |
5293 | 0 | else |
5294 | 0 | { |
5295 | | /* local symbol */ |
5296 | 0 | struct elf_aarch64_local_symbol *l; |
5297 | |
|
5298 | 0 | l = elf_aarch64_locals (input_bfd); |
5299 | 0 | return &l[r_symndx].got_offset; |
5300 | 0 | } |
5301 | 0 | } |
5302 | | |
5303 | | static void |
5304 | | symbol_got_offset_mark (bfd *input_bfd, struct elf_link_hash_entry *h, |
5305 | | unsigned long r_symndx) |
5306 | 0 | { |
5307 | 0 | bfd_vma *p; |
5308 | 0 | p = symbol_got_offset_ref (input_bfd, h, r_symndx); |
5309 | 0 | *p |= 1; |
5310 | 0 | } |
5311 | | |
5312 | | static int |
5313 | | symbol_got_offset_mark_p (bfd *input_bfd, struct elf_link_hash_entry *h, |
5314 | | unsigned long r_symndx) |
5315 | 0 | { |
5316 | 0 | bfd_vma value; |
5317 | 0 | value = * symbol_got_offset_ref (input_bfd, h, r_symndx); |
5318 | 0 | return value & 1; |
5319 | 0 | } |
5320 | | |
5321 | | static bfd_vma |
5322 | | symbol_got_offset (bfd *input_bfd, struct elf_link_hash_entry *h, |
5323 | | unsigned long r_symndx) |
5324 | 0 | { |
5325 | 0 | bfd_vma value; |
5326 | 0 | value = * symbol_got_offset_ref (input_bfd, h, r_symndx); |
5327 | 0 | value &= ~1; |
5328 | 0 | return value; |
5329 | 0 | } |
5330 | | |
5331 | | static bfd_vma * |
5332 | | symbol_tlsdesc_got_offset_ref (bfd *input_bfd, struct elf_link_hash_entry *h, |
5333 | | unsigned long r_symndx) |
5334 | 0 | { |
5335 | | /* Calculate the address of the GOT entry for symbol |
5336 | | referred to in h. */ |
5337 | 0 | if (h != NULL) |
5338 | 0 | { |
5339 | 0 | struct elf_aarch64_link_hash_entry *eh; |
5340 | 0 | eh = (struct elf_aarch64_link_hash_entry *) h; |
5341 | 0 | return &eh->tlsdesc_got_jump_table_offset; |
5342 | 0 | } |
5343 | 0 | else |
5344 | 0 | { |
5345 | | /* local symbol */ |
5346 | 0 | struct elf_aarch64_local_symbol *l; |
5347 | |
|
5348 | 0 | l = elf_aarch64_locals (input_bfd); |
5349 | 0 | return &l[r_symndx].tlsdesc_got_jump_table_offset; |
5350 | 0 | } |
5351 | 0 | } |
5352 | | |
5353 | | static void |
5354 | | symbol_tlsdesc_got_offset_mark (bfd *input_bfd, struct elf_link_hash_entry *h, |
5355 | | unsigned long r_symndx) |
5356 | 0 | { |
5357 | 0 | bfd_vma *p; |
5358 | 0 | p = symbol_tlsdesc_got_offset_ref (input_bfd, h, r_symndx); |
5359 | 0 | *p |= 1; |
5360 | 0 | } |
5361 | | |
5362 | | static int |
5363 | | symbol_tlsdesc_got_offset_mark_p (bfd *input_bfd, |
5364 | | struct elf_link_hash_entry *h, |
5365 | | unsigned long r_symndx) |
5366 | 0 | { |
5367 | 0 | bfd_vma value; |
5368 | 0 | value = * symbol_tlsdesc_got_offset_ref (input_bfd, h, r_symndx); |
5369 | 0 | return value & 1; |
5370 | 0 | } |
5371 | | |
5372 | | static bfd_vma |
5373 | | symbol_tlsdesc_got_offset (bfd *input_bfd, struct elf_link_hash_entry *h, |
5374 | | unsigned long r_symndx) |
5375 | 0 | { |
5376 | 0 | bfd_vma value; |
5377 | 0 | value = * symbol_tlsdesc_got_offset_ref (input_bfd, h, r_symndx); |
5378 | 0 | value &= ~1; |
5379 | 0 | return value; |
5380 | 0 | } |
5381 | | |
5382 | | /* Data for make_branch_to_erratum_835769_stub(). */ |
5383 | | |
5384 | | struct erratum_835769_branch_to_stub_data |
5385 | | { |
5386 | | struct bfd_link_info *info; |
5387 | | asection *output_section; |
5388 | | bfd_byte *contents; |
5389 | | }; |
5390 | | |
5391 | | /* Helper to insert branches to erratum 835769 stubs in the right |
5392 | | places for a particular section. */ |
5393 | | |
5394 | | static bool |
5395 | | make_branch_to_erratum_835769_stub (struct bfd_hash_entry *gen_entry, |
5396 | | void *in_arg) |
5397 | 0 | { |
5398 | 0 | struct elf_aarch64_stub_hash_entry *stub_entry; |
5399 | 0 | struct erratum_835769_branch_to_stub_data *data; |
5400 | 0 | bfd_byte *contents; |
5401 | 0 | unsigned long branch_insn = 0; |
5402 | 0 | bfd_vma veneered_insn_loc, veneer_entry_loc; |
5403 | 0 | bfd_signed_vma branch_offset; |
5404 | 0 | unsigned int target; |
5405 | 0 | bfd *abfd; |
5406 | |
|
5407 | 0 | stub_entry = (struct elf_aarch64_stub_hash_entry *) gen_entry; |
5408 | 0 | data = (struct erratum_835769_branch_to_stub_data *) in_arg; |
5409 | |
|
5410 | 0 | if (stub_entry->target_section != data->output_section |
5411 | 0 | || stub_entry->stub_type != aarch64_stub_erratum_835769_veneer) |
5412 | 0 | return true; |
5413 | | |
5414 | 0 | contents = data->contents; |
5415 | 0 | veneered_insn_loc = stub_entry->target_section->output_section->vma |
5416 | 0 | + stub_entry->target_section->output_offset |
5417 | 0 | + stub_entry->target_value; |
5418 | 0 | veneer_entry_loc = stub_entry->stub_sec->output_section->vma |
5419 | 0 | + stub_entry->stub_sec->output_offset |
5420 | 0 | + stub_entry->stub_offset; |
5421 | 0 | branch_offset = veneer_entry_loc - veneered_insn_loc; |
5422 | |
|
5423 | 0 | abfd = stub_entry->target_section->owner; |
5424 | 0 | if (!aarch64_valid_branch_p (veneer_entry_loc, veneered_insn_loc)) |
5425 | 0 | _bfd_error_handler |
5426 | 0 | (_("%pB: error: erratum 835769 stub out " |
5427 | 0 | "of range (input file too large)"), abfd); |
5428 | |
|
5429 | 0 | target = stub_entry->target_value; |
5430 | 0 | branch_insn = 0x14000000; |
5431 | 0 | branch_offset >>= 2; |
5432 | 0 | branch_offset &= 0x3ffffff; |
5433 | 0 | branch_insn |= branch_offset; |
5434 | 0 | bfd_putl32 (branch_insn, &contents[target]); |
5435 | |
|
5436 | 0 | return true; |
5437 | 0 | } |
5438 | | |
5439 | | |
5440 | | static bool |
5441 | | _bfd_aarch64_erratum_843419_branch_to_stub (struct bfd_hash_entry *gen_entry, |
5442 | | void *in_arg) |
5443 | 0 | { |
5444 | 0 | struct elf_aarch64_stub_hash_entry *stub_entry |
5445 | 0 | = (struct elf_aarch64_stub_hash_entry *) gen_entry; |
5446 | 0 | struct erratum_835769_branch_to_stub_data *data |
5447 | 0 | = (struct erratum_835769_branch_to_stub_data *) in_arg; |
5448 | 0 | struct bfd_link_info *info; |
5449 | 0 | struct elf_aarch64_link_hash_table *htab; |
5450 | 0 | bfd_byte *contents; |
5451 | 0 | asection *section; |
5452 | 0 | bfd *abfd; |
5453 | 0 | bfd_vma place; |
5454 | 0 | uint32_t insn; |
5455 | |
|
5456 | 0 | info = data->info; |
5457 | 0 | contents = data->contents; |
5458 | 0 | section = data->output_section; |
5459 | |
|
5460 | 0 | htab = elf_aarch64_hash_table (info); |
5461 | |
|
5462 | 0 | if (stub_entry->target_section != section |
5463 | 0 | || stub_entry->stub_type != aarch64_stub_erratum_843419_veneer) |
5464 | 0 | return true; |
5465 | | |
5466 | 0 | BFD_ASSERT (((htab->fix_erratum_843419 & ERRAT_ADRP) && stub_entry->stub_sec) |
5467 | 0 | || (htab->fix_erratum_843419 & ERRAT_ADR)); |
5468 | | |
5469 | | /* Only update the stub section if we have one. We should always have one if |
5470 | | we're allowed to use the ADRP errata workaround, otherwise it is not |
5471 | | required. */ |
5472 | 0 | if (stub_entry->stub_sec) |
5473 | 0 | { |
5474 | 0 | insn = bfd_getl32 (contents + stub_entry->target_value); |
5475 | 0 | bfd_putl32 (insn, |
5476 | 0 | stub_entry->stub_sec->contents + stub_entry->stub_offset); |
5477 | 0 | } |
5478 | |
|
5479 | 0 | place = (section->output_section->vma + section->output_offset |
5480 | 0 | + stub_entry->adrp_offset); |
5481 | 0 | insn = bfd_getl32 (contents + stub_entry->adrp_offset); |
5482 | |
|
5483 | 0 | if (!_bfd_aarch64_adrp_p (insn)) |
5484 | 0 | abort (); |
5485 | | |
5486 | 0 | bfd_signed_vma imm = |
5487 | 0 | (_bfd_aarch64_sign_extend |
5488 | 0 | ((bfd_vma) _bfd_aarch64_decode_adrp_imm (insn) << 12, 33) |
5489 | 0 | - (place & 0xfff)); |
5490 | |
|
5491 | 0 | if ((htab->fix_erratum_843419 & ERRAT_ADR) |
5492 | 0 | && (imm >= AARCH64_MIN_ADRP_IMM && imm <= AARCH64_MAX_ADRP_IMM)) |
5493 | 0 | { |
5494 | 0 | insn = (_bfd_aarch64_reencode_adr_imm (AARCH64_ADR_OP, imm) |
5495 | 0 | | AARCH64_RT (insn)); |
5496 | 0 | bfd_putl32 (insn, contents + stub_entry->adrp_offset); |
5497 | | /* Stub is not needed, don't map it out. */ |
5498 | 0 | stub_entry->stub_type = aarch64_stub_none; |
5499 | 0 | } |
5500 | 0 | else if (htab->fix_erratum_843419 & ERRAT_ADRP) |
5501 | 0 | { |
5502 | 0 | bfd_vma veneered_insn_loc; |
5503 | 0 | bfd_vma veneer_entry_loc; |
5504 | 0 | bfd_signed_vma branch_offset; |
5505 | 0 | uint32_t branch_insn; |
5506 | |
|
5507 | 0 | veneered_insn_loc = stub_entry->target_section->output_section->vma |
5508 | 0 | + stub_entry->target_section->output_offset |
5509 | 0 | + stub_entry->target_value; |
5510 | 0 | veneer_entry_loc = stub_entry->stub_sec->output_section->vma |
5511 | 0 | + stub_entry->stub_sec->output_offset |
5512 | 0 | + stub_entry->stub_offset; |
5513 | 0 | branch_offset = veneer_entry_loc - veneered_insn_loc; |
5514 | |
|
5515 | 0 | abfd = stub_entry->target_section->owner; |
5516 | 0 | if (!aarch64_valid_branch_p (veneer_entry_loc, veneered_insn_loc)) |
5517 | 0 | _bfd_error_handler |
5518 | 0 | (_("%pB: error: erratum 843419 stub out " |
5519 | 0 | "of range (input file too large)"), abfd); |
5520 | |
|
5521 | 0 | branch_insn = 0x14000000; |
5522 | 0 | branch_offset >>= 2; |
5523 | 0 | branch_offset &= 0x3ffffff; |
5524 | 0 | branch_insn |= branch_offset; |
5525 | 0 | bfd_putl32 (branch_insn, contents + stub_entry->target_value); |
5526 | 0 | } |
5527 | 0 | else |
5528 | 0 | { |
5529 | 0 | abfd = stub_entry->target_section->owner; |
5530 | 0 | _bfd_error_handler |
5531 | 0 | (_("%pB: error: erratum 843419 immediate 0x%" PRIx64 |
5532 | 0 | " out of range for ADR (input file too large) and " |
5533 | 0 | "--fix-cortex-a53-843419=adr used. Run the linker with " |
5534 | 0 | "--fix-cortex-a53-843419=full instead"), |
5535 | 0 | abfd, (uint64_t) (bfd_vma) imm); |
5536 | 0 | bfd_set_error (bfd_error_bad_value); |
5537 | | /* This function is called inside a hashtable traversal and the error |
5538 | | handlers called above turn into non-fatal errors. Which means this |
5539 | | case ld returns an exit code 0 and also produces a broken object file. |
5540 | | To prevent this, issue a hard abort. */ |
5541 | 0 | BFD_FAIL (); |
5542 | 0 | } |
5543 | 0 | return true; |
5544 | 0 | } |
5545 | | |
5546 | | |
5547 | | static bool |
5548 | | elf64_aarch64_write_section (bfd *output_bfd ATTRIBUTE_UNUSED, |
5549 | | struct bfd_link_info *link_info, |
5550 | | asection *sec, |
5551 | | bfd_byte *contents) |
5552 | | |
5553 | 0 | { |
5554 | 0 | struct elf_aarch64_link_hash_table *globals = |
5555 | 0 | elf_aarch64_hash_table (link_info); |
5556 | |
|
5557 | 0 | if (globals == NULL) |
5558 | 0 | return false; |
5559 | | |
5560 | | /* Fix code to point to erratum 835769 stubs. */ |
5561 | 0 | if (globals->fix_erratum_835769) |
5562 | 0 | { |
5563 | 0 | struct erratum_835769_branch_to_stub_data data; |
5564 | |
|
5565 | 0 | data.info = link_info; |
5566 | 0 | data.output_section = sec; |
5567 | 0 | data.contents = contents; |
5568 | 0 | bfd_hash_traverse (&globals->stub_hash_table, |
5569 | 0 | make_branch_to_erratum_835769_stub, &data); |
5570 | 0 | } |
5571 | |
|
5572 | 0 | if (globals->fix_erratum_843419) |
5573 | 0 | { |
5574 | 0 | struct erratum_835769_branch_to_stub_data data; |
5575 | |
|
5576 | 0 | data.info = link_info; |
5577 | 0 | data.output_section = sec; |
5578 | 0 | data.contents = contents; |
5579 | 0 | bfd_hash_traverse (&globals->stub_hash_table, |
5580 | 0 | _bfd_aarch64_erratum_843419_branch_to_stub, &data); |
5581 | 0 | } |
5582 | |
|
5583 | 0 | return false; |
5584 | 0 | } |
5585 | | |
5586 | | /* Return TRUE if RELOC is a relocation against the base of GOT table. */ |
5587 | | |
5588 | | static bool |
5589 | | aarch64_relocation_aginst_gp_p (bfd_reloc_code_real_type reloc) |
5590 | 0 | { |
5591 | 0 | return (reloc == BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14 |
5592 | 0 | || reloc == BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15 |
5593 | 0 | || reloc == BFD_RELOC_AARCH64_LD64_GOTOFF_LO15 |
5594 | 0 | || reloc == BFD_RELOC_AARCH64_MOVW_GOTOFF_G0_NC |
5595 | 0 | || reloc == BFD_RELOC_AARCH64_MOVW_GOTOFF_G1); |
5596 | 0 | } |
5597 | | |
5598 | | /* Perform a relocation as part of a final link. The input relocation type |
5599 | | should be TLS relaxed. */ |
5600 | | |
5601 | | static bfd_reloc_status_type |
5602 | | elf64_aarch64_final_link_relocate (reloc_howto_type *howto, |
5603 | | bfd *input_bfd, |
5604 | | bfd *output_bfd, |
5605 | | asection *input_section, |
5606 | | bfd_byte *contents, |
5607 | | Elf_Internal_Rela *rel, |
5608 | | bfd_vma value, |
5609 | | struct bfd_link_info *info, |
5610 | | asection *sym_sec, |
5611 | | struct elf_link_hash_entry *h, |
5612 | | bool *unresolved_reloc_p, |
5613 | | bool save_addend, |
5614 | | bfd_vma *saved_addend, |
5615 | | Elf_Internal_Sym *sym) |
5616 | 0 | { |
5617 | 0 | Elf_Internal_Shdr *symtab_hdr; |
5618 | 0 | unsigned int r_type = howto->type; |
5619 | 0 | bfd_reloc_code_real_type bfd_r_type |
5620 | 0 | = elf64_aarch64_bfd_reloc_from_howto (howto); |
5621 | 0 | unsigned long r_symndx; |
5622 | 0 | bfd_byte *hit_data = contents + rel->r_offset; |
5623 | 0 | bfd_vma place, off, got_entry_addr = 0; |
5624 | 0 | bfd_signed_vma signed_addend; |
5625 | 0 | struct elf_aarch64_link_hash_table *globals; |
5626 | 0 | bool weak_undef_p; |
5627 | 0 | bool relative_reloc; |
5628 | 0 | asection *base_got; |
5629 | 0 | bfd_vma orig_value = value; |
5630 | 0 | bool resolved_to_zero; |
5631 | 0 | bool abs_symbol_p; |
5632 | |
|
5633 | 0 | globals = elf_aarch64_hash_table (info); |
5634 | |
|
5635 | 0 | symtab_hdr = &elf_symtab_hdr (input_bfd); |
5636 | |
|
5637 | 0 | BFD_ASSERT (is_aarch64_elf (input_bfd)); |
5638 | |
|
5639 | 0 | r_symndx = ELF64_R_SYM (rel->r_info); |
5640 | |
|
5641 | 0 | place = input_section->output_section->vma |
5642 | 0 | + input_section->output_offset + rel->r_offset; |
5643 | | |
5644 | | /* Get addend, accumulating the addend for consecutive relocs |
5645 | | which refer to the same offset. */ |
5646 | 0 | signed_addend = saved_addend ? *saved_addend : 0; |
5647 | 0 | signed_addend += rel->r_addend; |
5648 | |
|
5649 | 0 | weak_undef_p = (h ? h->root.type == bfd_link_hash_undefweak |
5650 | 0 | : bfd_is_und_section (sym_sec)); |
5651 | 0 | abs_symbol_p = h != NULL && bfd_is_abs_symbol (&h->root); |
5652 | | |
5653 | | |
5654 | | /* Since STT_GNU_IFUNC symbol must go through PLT, we handle |
5655 | | it here if it is defined in a non-shared object. */ |
5656 | 0 | if (h != NULL |
5657 | 0 | && h->type == STT_GNU_IFUNC |
5658 | 0 | && h->def_regular) |
5659 | 0 | { |
5660 | 0 | asection *plt; |
5661 | 0 | const char *name; |
5662 | 0 | bfd_vma addend = 0; |
5663 | |
|
5664 | 0 | if ((input_section->flags & SEC_ALLOC) == 0) |
5665 | 0 | { |
5666 | | /* If this is a SHT_NOTE section without SHF_ALLOC, treat |
5667 | | STT_GNU_IFUNC symbol as STT_FUNC. */ |
5668 | 0 | if (elf_section_type (input_section) == SHT_NOTE) |
5669 | 0 | goto skip_ifunc; |
5670 | | |
5671 | | /* Dynamic relocs are not propagated for SEC_DEBUGGING |
5672 | | sections because such sections are not SEC_ALLOC and |
5673 | | thus ld.so will not process them. */ |
5674 | 0 | if ((input_section->flags & SEC_DEBUGGING) != 0) |
5675 | 0 | return bfd_reloc_ok; |
5676 | | |
5677 | 0 | if (h->root.root.string) |
5678 | 0 | name = h->root.root.string; |
5679 | 0 | else |
5680 | 0 | name = bfd_elf_sym_name (input_bfd, symtab_hdr, sym, NULL); |
5681 | 0 | _bfd_error_handler |
5682 | | /* xgettext:c-format */ |
5683 | 0 | (_("%pB(%pA+%#" PRIx64 "): " |
5684 | 0 | "unresolvable %s relocation against symbol `%s'"), |
5685 | 0 | input_bfd, input_section, (uint64_t) rel->r_offset, |
5686 | 0 | howto->name, name); |
5687 | 0 | bfd_set_error (bfd_error_bad_value); |
5688 | 0 | return bfd_reloc_notsupported; |
5689 | 0 | } |
5690 | 0 | else if (h->plt.offset == (bfd_vma) -1) |
5691 | 0 | goto bad_ifunc_reloc; |
5692 | | |
5693 | | /* STT_GNU_IFUNC symbol must go through PLT. */ |
5694 | 0 | plt = globals->root.splt ? globals->root.splt : globals->root.iplt; |
5695 | 0 | value = (plt->output_section->vma + plt->output_offset + h->plt.offset); |
5696 | |
|
5697 | 0 | switch (bfd_r_type) |
5698 | 0 | { |
5699 | 0 | default: |
5700 | 0 | bad_ifunc_reloc: |
5701 | 0 | if (h->root.root.string) |
5702 | 0 | name = h->root.root.string; |
5703 | 0 | else |
5704 | 0 | name = bfd_elf_sym_name (input_bfd, symtab_hdr, sym, |
5705 | 0 | NULL); |
5706 | 0 | _bfd_error_handler |
5707 | | /* xgettext:c-format */ |
5708 | 0 | (_("%pB: relocation %s against STT_GNU_IFUNC " |
5709 | 0 | "symbol `%s' isn't handled by %s"), input_bfd, |
5710 | 0 | howto->name, name, __func__); |
5711 | 0 | bfd_set_error (bfd_error_bad_value); |
5712 | 0 | return bfd_reloc_notsupported; |
5713 | | |
5714 | 0 | case BFD_RELOC_AARCH64_64: |
5715 | 0 | if (rel->r_addend != 0) |
5716 | 0 | { |
5717 | 0 | if (h->root.root.string) |
5718 | 0 | name = h->root.root.string; |
5719 | 0 | else |
5720 | 0 | name = bfd_elf_sym_name (input_bfd, symtab_hdr, |
5721 | 0 | sym, NULL); |
5722 | 0 | _bfd_error_handler |
5723 | | /* xgettext:c-format */ |
5724 | 0 | (_("%pB: relocation %s against STT_GNU_IFUNC " |
5725 | 0 | "symbol `%s' has non-zero addend: %" PRId64), |
5726 | 0 | input_bfd, howto->name, name, (int64_t) rel->r_addend); |
5727 | 0 | bfd_set_error (bfd_error_bad_value); |
5728 | 0 | return bfd_reloc_notsupported; |
5729 | 0 | } |
5730 | | |
5731 | | /* Generate dynamic relocation only when there is a |
5732 | | non-GOT reference in a shared object. */ |
5733 | 0 | if (bfd_link_pic (info) && h->non_got_ref) |
5734 | 0 | { |
5735 | 0 | Elf_Internal_Rela outrel; |
5736 | 0 | asection *sreloc; |
5737 | | |
5738 | | /* Need a dynamic relocation to get the real function |
5739 | | address. */ |
5740 | 0 | outrel.r_offset = _bfd_elf_section_offset (output_bfd, |
5741 | 0 | info, |
5742 | 0 | input_section, |
5743 | 0 | rel->r_offset); |
5744 | 0 | if (outrel.r_offset == (bfd_vma) -1 |
5745 | 0 | || outrel.r_offset == (bfd_vma) -2) |
5746 | 0 | abort (); |
5747 | | |
5748 | 0 | outrel.r_offset += (input_section->output_section->vma |
5749 | 0 | + input_section->output_offset); |
5750 | |
|
5751 | 0 | if (h->dynindx == -1 |
5752 | 0 | || h->forced_local |
5753 | 0 | || bfd_link_executable (info)) |
5754 | 0 | { |
5755 | | /* This symbol is resolved locally. */ |
5756 | 0 | outrel.r_info = ELF64_R_INFO (0, AARCH64_R (IRELATIVE)); |
5757 | 0 | outrel.r_addend = (h->root.u.def.value |
5758 | 0 | + h->root.u.def.section->output_section->vma |
5759 | 0 | + h->root.u.def.section->output_offset); |
5760 | 0 | } |
5761 | 0 | else |
5762 | 0 | { |
5763 | 0 | outrel.r_info = ELF64_R_INFO (h->dynindx, r_type); |
5764 | 0 | outrel.r_addend = 0; |
5765 | 0 | } |
5766 | |
|
5767 | 0 | sreloc = globals->root.irelifunc; |
5768 | 0 | elf_append_rela (output_bfd, sreloc, &outrel); |
5769 | | |
5770 | | /* If this reloc is against an external symbol, we |
5771 | | do not want to fiddle with the addend. Otherwise, |
5772 | | we need to include the symbol value so that it |
5773 | | becomes an addend for the dynamic reloc. For an |
5774 | | internal symbol, we have updated addend. */ |
5775 | 0 | return bfd_reloc_ok; |
5776 | 0 | } |
5777 | | /* FALLTHROUGH */ |
5778 | 0 | case BFD_RELOC_AARCH64_CALL26: |
5779 | 0 | case BFD_RELOC_AARCH64_JUMP26: |
5780 | 0 | value = _bfd_aarch64_elf_resolve_relocation (input_bfd, bfd_r_type, |
5781 | 0 | place, value, |
5782 | 0 | signed_addend, |
5783 | 0 | weak_undef_p); |
5784 | 0 | return _bfd_aarch64_elf_put_addend (input_bfd, hit_data, bfd_r_type, |
5785 | 0 | howto, value); |
5786 | 0 | case BFD_RELOC_AARCH64_ADR_GOT_PAGE: |
5787 | 0 | case BFD_RELOC_AARCH64_GOT_LD_PREL19: |
5788 | 0 | case BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14: |
5789 | 0 | case BFD_RELOC_AARCH64_LD32_GOT_LO12_NC: |
5790 | 0 | case BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15: |
5791 | 0 | case BFD_RELOC_AARCH64_MOVW_GOTOFF_G0_NC: |
5792 | 0 | case BFD_RELOC_AARCH64_MOVW_GOTOFF_G1: |
5793 | 0 | case BFD_RELOC_AARCH64_LD64_GOTOFF_LO15: |
5794 | 0 | case BFD_RELOC_AARCH64_LD64_GOT_LO12_NC: |
5795 | 0 | base_got = globals->root.sgot; |
5796 | 0 | off = h->got.offset; |
5797 | |
|
5798 | 0 | if (base_got == NULL) |
5799 | 0 | abort (); |
5800 | | |
5801 | 0 | if (off == (bfd_vma) -1) |
5802 | 0 | { |
5803 | 0 | bfd_vma plt_index; |
5804 | | |
5805 | | /* We can't use h->got.offset here to save state, or |
5806 | | even just remember the offset, as finish_dynamic_symbol |
5807 | | would use that as offset into .got. */ |
5808 | |
|
5809 | 0 | if (globals->root.splt != NULL) |
5810 | 0 | { |
5811 | 0 | plt_index = ((h->plt.offset - globals->plt_header_size) / |
5812 | 0 | globals->plt_entry_size); |
5813 | 0 | off = (plt_index + 3) * GOT_ENTRY_SIZE; |
5814 | 0 | base_got = globals->root.sgotplt; |
5815 | 0 | } |
5816 | 0 | else |
5817 | 0 | { |
5818 | 0 | plt_index = h->plt.offset / globals->plt_entry_size; |
5819 | 0 | off = plt_index * GOT_ENTRY_SIZE; |
5820 | 0 | base_got = globals->root.igotplt; |
5821 | 0 | } |
5822 | |
|
5823 | 0 | if (h->dynindx == -1 |
5824 | 0 | || h->forced_local |
5825 | 0 | || info->symbolic) |
5826 | 0 | { |
5827 | | /* This references the local definition. We must |
5828 | | initialize this entry in the global offset table. |
5829 | | Since the offset must always be a multiple of 8, |
5830 | | we use the least significant bit to record |
5831 | | whether we have initialized it already. |
5832 | | |
5833 | | When doing a dynamic link, we create a .rela.got |
5834 | | relocation entry to initialize the value. This |
5835 | | is done in the finish_dynamic_symbol routine. */ |
5836 | 0 | if ((off & 1) != 0) |
5837 | 0 | off &= ~1; |
5838 | 0 | else |
5839 | 0 | { |
5840 | 0 | bfd_put_64 (output_bfd, value, |
5841 | 0 | base_got->contents + off); |
5842 | | /* Note that this is harmless as -1 | 1 still is -1. */ |
5843 | 0 | h->got.offset |= 1; |
5844 | 0 | } |
5845 | 0 | } |
5846 | 0 | value = (base_got->output_section->vma |
5847 | 0 | + base_got->output_offset + off); |
5848 | 0 | } |
5849 | 0 | else |
5850 | 0 | value = aarch64_calculate_got_entry_vma (h, globals, info, |
5851 | 0 | value, output_bfd, |
5852 | 0 | unresolved_reloc_p); |
5853 | |
|
5854 | 0 | if (aarch64_relocation_aginst_gp_p (bfd_r_type)) |
5855 | 0 | addend = (globals->root.sgot->output_section->vma |
5856 | 0 | + globals->root.sgot->output_offset); |
5857 | |
|
5858 | 0 | value = _bfd_aarch64_elf_resolve_relocation (input_bfd, bfd_r_type, |
5859 | 0 | place, value, |
5860 | 0 | addend, weak_undef_p); |
5861 | 0 | return _bfd_aarch64_elf_put_addend (input_bfd, hit_data, bfd_r_type, howto, value); |
5862 | 0 | case BFD_RELOC_AARCH64_ADD_LO12: |
5863 | 0 | case BFD_RELOC_AARCH64_ADR_HI21_PCREL: |
5864 | 0 | break; |
5865 | 0 | } |
5866 | 0 | } |
5867 | | |
5868 | 0 | skip_ifunc: |
5869 | 0 | resolved_to_zero = (h != NULL |
5870 | 0 | && UNDEFWEAK_NO_DYNAMIC_RELOC (info, h)); |
5871 | |
|
5872 | 0 | switch (bfd_r_type) |
5873 | 0 | { |
5874 | 0 | case BFD_RELOC_AARCH64_NONE: |
5875 | 0 | case BFD_RELOC_AARCH64_TLSDESC_ADD: |
5876 | 0 | case BFD_RELOC_AARCH64_TLSDESC_CALL: |
5877 | 0 | case BFD_RELOC_AARCH64_TLSDESC_LDR: |
5878 | 0 | *unresolved_reloc_p = false; |
5879 | 0 | return bfd_reloc_ok; |
5880 | | |
5881 | 0 | case BFD_RELOC_AARCH64_64: |
5882 | | |
5883 | | /* When generating a shared object or relocatable executable, these |
5884 | | relocations are copied into the output file to be resolved at |
5885 | | run time. */ |
5886 | 0 | if (((bfd_link_pic (info) |
5887 | 0 | || globals->root.is_relocatable_executable) |
5888 | 0 | && (input_section->flags & SEC_ALLOC) |
5889 | 0 | && (h == NULL |
5890 | 0 | || (ELF_ST_VISIBILITY (h->other) == STV_DEFAULT |
5891 | 0 | && !resolved_to_zero) |
5892 | 0 | || h->root.type != bfd_link_hash_undefweak)) |
5893 | | /* Or we are creating an executable, we may need to keep relocations |
5894 | | for symbols satisfied by a dynamic library if we manage to avoid |
5895 | | copy relocs for the symbol. */ |
5896 | 0 | || (ELIMINATE_COPY_RELOCS |
5897 | 0 | && !bfd_link_pic (info) |
5898 | 0 | && h != NULL |
5899 | 0 | && (input_section->flags & SEC_ALLOC) |
5900 | 0 | && h->dynindx != -1 |
5901 | 0 | && !h->non_got_ref |
5902 | 0 | && ((h->def_dynamic |
5903 | 0 | && !h->def_regular) |
5904 | 0 | || h->root.type == bfd_link_hash_undefweak |
5905 | 0 | || h->root.type == bfd_link_hash_undefined))) |
5906 | 0 | { |
5907 | 0 | Elf_Internal_Rela outrel; |
5908 | 0 | bfd_byte *loc; |
5909 | 0 | bool skip, relocate; |
5910 | 0 | asection *sreloc; |
5911 | |
|
5912 | 0 | *unresolved_reloc_p = false; |
5913 | |
|
5914 | 0 | skip = false; |
5915 | 0 | relocate = false; |
5916 | |
|
5917 | 0 | outrel.r_addend = signed_addend; |
5918 | 0 | outrel.r_offset = |
5919 | 0 | _bfd_elf_section_offset (output_bfd, info, input_section, |
5920 | 0 | rel->r_offset); |
5921 | 0 | if (outrel.r_offset == (bfd_vma) - 1) |
5922 | 0 | skip = true; |
5923 | 0 | else if (outrel.r_offset == (bfd_vma) - 2) |
5924 | 0 | { |
5925 | 0 | skip = true; |
5926 | 0 | relocate = true; |
5927 | 0 | } |
5928 | 0 | else if (abs_symbol_p) |
5929 | 0 | { |
5930 | | /* Local absolute symbol. */ |
5931 | 0 | skip = (h->forced_local || (h->dynindx == -1)); |
5932 | 0 | relocate = skip; |
5933 | 0 | } |
5934 | |
|
5935 | 0 | outrel.r_offset += (input_section->output_section->vma |
5936 | 0 | + input_section->output_offset); |
5937 | |
|
5938 | 0 | if (skip) |
5939 | 0 | memset (&outrel, 0, sizeof outrel); |
5940 | 0 | else if (h != NULL |
5941 | 0 | && h->dynindx != -1 |
5942 | 0 | && (!bfd_link_pic (info) |
5943 | 0 | || !(bfd_link_pie (info) || SYMBOLIC_BIND (info, h)) |
5944 | 0 | || !h->def_regular)) |
5945 | 0 | outrel.r_info = ELF64_R_INFO (h->dynindx, r_type); |
5946 | 0 | else |
5947 | 0 | { |
5948 | 0 | int symbol; |
5949 | | |
5950 | | /* On SVR4-ish systems, the dynamic loader cannot |
5951 | | relocate the text and data segments independently, |
5952 | | so the symbol does not matter. */ |
5953 | 0 | symbol = 0; |
5954 | 0 | relocate = !globals->no_apply_dynamic_relocs; |
5955 | 0 | outrel.r_info = ELF64_R_INFO (symbol, AARCH64_R (RELATIVE)); |
5956 | 0 | outrel.r_addend += value; |
5957 | 0 | } |
5958 | |
|
5959 | 0 | sreloc = elf_section_data (input_section)->sreloc; |
5960 | 0 | if (sreloc == NULL || sreloc->contents == NULL) |
5961 | 0 | return bfd_reloc_notsupported; |
5962 | | |
5963 | 0 | loc = sreloc->contents + sreloc->reloc_count++ * RELOC_SIZE (globals); |
5964 | 0 | bfd_elf64_swap_reloca_out (output_bfd, &outrel, loc); |
5965 | |
|
5966 | 0 | if (sreloc->reloc_count * RELOC_SIZE (globals) > sreloc->size) |
5967 | 0 | { |
5968 | | /* Sanity to check that we have previously allocated |
5969 | | sufficient space in the relocation section for the |
5970 | | number of relocations we actually want to emit. */ |
5971 | 0 | abort (); |
5972 | 0 | } |
5973 | | |
5974 | | /* If this reloc is against an external symbol, we do not want to |
5975 | | fiddle with the addend. Otherwise, we need to include the symbol |
5976 | | value so that it becomes an addend for the dynamic reloc. */ |
5977 | 0 | if (!relocate) |
5978 | 0 | return bfd_reloc_ok; |
5979 | | |
5980 | 0 | return _bfd_final_link_relocate (howto, input_bfd, input_section, |
5981 | 0 | contents, rel->r_offset, value, |
5982 | 0 | signed_addend); |
5983 | 0 | } |
5984 | 0 | else |
5985 | 0 | value += signed_addend; |
5986 | 0 | break; |
5987 | | |
5988 | 0 | case BFD_RELOC_AARCH64_CALL26: |
5989 | 0 | case BFD_RELOC_AARCH64_JUMP26: |
5990 | 0 | { |
5991 | 0 | asection *splt = globals->root.splt; |
5992 | 0 | bool via_plt_p = |
5993 | 0 | splt != NULL && h != NULL && h->plt.offset != (bfd_vma) - 1; |
5994 | | |
5995 | | /* A call to an undefined weak symbol is converted to a jump to |
5996 | | the next instruction unless a PLT entry will be created. |
5997 | | The jump to the next instruction is optimized as a NOP. |
5998 | | Do the same for local undefined symbols. */ |
5999 | 0 | if (weak_undef_p && ! via_plt_p) |
6000 | 0 | { |
6001 | 0 | bfd_putl32 (INSN_NOP, hit_data); |
6002 | 0 | return bfd_reloc_ok; |
6003 | 0 | } |
6004 | | |
6005 | | /* If the call goes through a PLT entry, make sure to |
6006 | | check distance to the right destination address. */ |
6007 | 0 | if (via_plt_p) |
6008 | 0 | value = (splt->output_section->vma |
6009 | 0 | + splt->output_offset + h->plt.offset); |
6010 | | |
6011 | | /* Check if a stub has to be inserted because the destination |
6012 | | is too far away. */ |
6013 | 0 | struct elf_aarch64_stub_hash_entry *stub_entry = NULL; |
6014 | | |
6015 | | /* If the branch destination is directed to plt stub, "value" will be |
6016 | | the final destination, otherwise we should plus signed_addend, it may |
6017 | | contain non-zero value, for example call to local function symbol |
6018 | | which are turned into "sec_sym + sec_off", and sec_off is kept in |
6019 | | signed_addend. */ |
6020 | 0 | if (! aarch64_valid_branch_p (via_plt_p ? value : value + signed_addend, |
6021 | 0 | place)) |
6022 | | /* The target is out of reach, so redirect the branch to |
6023 | | the local stub for this function. */ |
6024 | 0 | stub_entry = elf64_aarch64_get_stub_entry (input_section, sym_sec, h, |
6025 | 0 | rel, globals); |
6026 | 0 | if (stub_entry != NULL) |
6027 | 0 | { |
6028 | 0 | value = (stub_entry->stub_offset |
6029 | 0 | + stub_entry->stub_sec->output_offset |
6030 | 0 | + stub_entry->stub_sec->output_section->vma); |
6031 | | |
6032 | | /* We have redirected the destination to stub entry address, |
6033 | | so ignore any addend record in the original rela entry. */ |
6034 | 0 | signed_addend = 0; |
6035 | 0 | } |
6036 | 0 | } |
6037 | 0 | value = _bfd_aarch64_elf_resolve_relocation (input_bfd, bfd_r_type, |
6038 | 0 | place, value, |
6039 | 0 | signed_addend, weak_undef_p); |
6040 | 0 | *unresolved_reloc_p = false; |
6041 | 0 | break; |
6042 | | |
6043 | 0 | case BFD_RELOC_AARCH64_16_PCREL: |
6044 | 0 | case BFD_RELOC_AARCH64_32_PCREL: |
6045 | 0 | case BFD_RELOC_AARCH64_64_PCREL: |
6046 | 0 | case BFD_RELOC_AARCH64_ADR_HI21_NC_PCREL: |
6047 | 0 | case BFD_RELOC_AARCH64_ADR_HI21_PCREL: |
6048 | 0 | case BFD_RELOC_AARCH64_ADR_LO21_PCREL: |
6049 | 0 | case BFD_RELOC_AARCH64_LD_LO19_PCREL: |
6050 | 0 | case BFD_RELOC_AARCH64_MOVW_PREL_G0: |
6051 | 0 | case BFD_RELOC_AARCH64_MOVW_PREL_G0_NC: |
6052 | 0 | case BFD_RELOC_AARCH64_MOVW_PREL_G1: |
6053 | 0 | case BFD_RELOC_AARCH64_MOVW_PREL_G1_NC: |
6054 | 0 | case BFD_RELOC_AARCH64_MOVW_PREL_G2: |
6055 | 0 | case BFD_RELOC_AARCH64_MOVW_PREL_G2_NC: |
6056 | 0 | case BFD_RELOC_AARCH64_MOVW_PREL_G3: |
6057 | 0 | if (bfd_link_pic (info) |
6058 | 0 | && (input_section->flags & SEC_ALLOC) != 0 |
6059 | 0 | && (input_section->flags & SEC_READONLY) != 0 |
6060 | 0 | && !_bfd_elf_symbol_refs_local_p (h, info, 1)) |
6061 | 0 | { |
6062 | 0 | int howto_index = bfd_r_type - BFD_RELOC_AARCH64_RELOC_START; |
6063 | |
|
6064 | 0 | _bfd_error_handler |
6065 | | /* xgettext:c-format */ |
6066 | 0 | (_("%pB: relocation %s against symbol `%s' which may bind " |
6067 | 0 | "externally can not be used when making a shared object; " |
6068 | 0 | "recompile with -fPIC"), |
6069 | 0 | input_bfd, elf64_aarch64_howto_table[howto_index].name, |
6070 | 0 | h->root.root.string); |
6071 | 0 | bfd_set_error (bfd_error_bad_value); |
6072 | 0 | return bfd_reloc_notsupported; |
6073 | 0 | } |
6074 | 0 | value = _bfd_aarch64_elf_resolve_relocation (input_bfd, bfd_r_type, |
6075 | 0 | place, value, |
6076 | 0 | signed_addend, |
6077 | 0 | weak_undef_p); |
6078 | 0 | break; |
6079 | | |
6080 | 0 | case BFD_RELOC_AARCH64_BRANCH19: |
6081 | 0 | case BFD_RELOC_AARCH64_TSTBR14: |
6082 | 0 | if (h && h->root.type == bfd_link_hash_undefined) |
6083 | 0 | { |
6084 | 0 | _bfd_error_handler |
6085 | | /* xgettext:c-format */ |
6086 | 0 | (_("%pB: conditional branch to undefined symbol `%s' " |
6087 | 0 | "not allowed"), input_bfd, h->root.root.string); |
6088 | 0 | bfd_set_error (bfd_error_bad_value); |
6089 | 0 | return bfd_reloc_notsupported; |
6090 | 0 | } |
6091 | | /* Fall through. */ |
6092 | | |
6093 | 0 | case BFD_RELOC_AARCH64_16: |
6094 | 0 | #if ARCH_SIZE == 64 |
6095 | 0 | case BFD_RELOC_AARCH64_32: |
6096 | 0 | #endif |
6097 | 0 | case BFD_RELOC_AARCH64_ADD_LO12: |
6098 | 0 | case BFD_RELOC_AARCH64_LDST128_LO12: |
6099 | 0 | case BFD_RELOC_AARCH64_LDST16_LO12: |
6100 | 0 | case BFD_RELOC_AARCH64_LDST32_LO12: |
6101 | 0 | case BFD_RELOC_AARCH64_LDST64_LO12: |
6102 | 0 | case BFD_RELOC_AARCH64_LDST8_LO12: |
6103 | 0 | case BFD_RELOC_AARCH64_MOVW_G0: |
6104 | 0 | case BFD_RELOC_AARCH64_MOVW_G0_NC: |
6105 | 0 | case BFD_RELOC_AARCH64_MOVW_G0_S: |
6106 | 0 | case BFD_RELOC_AARCH64_MOVW_G1: |
6107 | 0 | case BFD_RELOC_AARCH64_MOVW_G1_NC: |
6108 | 0 | case BFD_RELOC_AARCH64_MOVW_G1_S: |
6109 | 0 | case BFD_RELOC_AARCH64_MOVW_G2: |
6110 | 0 | case BFD_RELOC_AARCH64_MOVW_G2_NC: |
6111 | 0 | case BFD_RELOC_AARCH64_MOVW_G2_S: |
6112 | 0 | case BFD_RELOC_AARCH64_MOVW_G3: |
6113 | 0 | value = _bfd_aarch64_elf_resolve_relocation (input_bfd, bfd_r_type, |
6114 | 0 | place, value, |
6115 | 0 | signed_addend, weak_undef_p); |
6116 | 0 | break; |
6117 | | |
6118 | 0 | case BFD_RELOC_AARCH64_ADR_GOT_PAGE: |
6119 | 0 | case BFD_RELOC_AARCH64_GOT_LD_PREL19: |
6120 | 0 | case BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14: |
6121 | 0 | case BFD_RELOC_AARCH64_LD32_GOT_LO12_NC: |
6122 | 0 | case BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15: |
6123 | 0 | case BFD_RELOC_AARCH64_LD64_GOT_LO12_NC: |
6124 | 0 | case BFD_RELOC_AARCH64_LD64_GOTOFF_LO15: |
6125 | 0 | case BFD_RELOC_AARCH64_MOVW_GOTOFF_G0_NC: |
6126 | 0 | case BFD_RELOC_AARCH64_MOVW_GOTOFF_G1: |
6127 | 0 | if (globals->root.sgot == NULL) |
6128 | 0 | BFD_ASSERT (h != NULL); |
6129 | |
|
6130 | 0 | relative_reloc = false; |
6131 | 0 | if (h != NULL) |
6132 | 0 | { |
6133 | 0 | bfd_vma addend = 0; |
6134 | | |
6135 | | /* If a symbol is not dynamic and is not undefined weak, bind it |
6136 | | locally and generate a RELATIVE relocation under PIC mode. |
6137 | | |
6138 | | NOTE: one symbol may be referenced by several relocations, we |
6139 | | should only generate one RELATIVE relocation for that symbol. |
6140 | | Therefore, check GOT offset mark first. */ |
6141 | 0 | if (h->dynindx == -1 |
6142 | 0 | && !h->forced_local |
6143 | 0 | && h->root.type != bfd_link_hash_undefweak |
6144 | 0 | && bfd_link_pic (info) |
6145 | 0 | && !symbol_got_offset_mark_p (input_bfd, h, r_symndx)) |
6146 | 0 | relative_reloc = true; |
6147 | |
|
6148 | 0 | value = aarch64_calculate_got_entry_vma (h, globals, info, value, |
6149 | 0 | output_bfd, |
6150 | 0 | unresolved_reloc_p); |
6151 | | /* Record the GOT entry address which will be used when generating |
6152 | | RELATIVE relocation. */ |
6153 | 0 | if (relative_reloc) |
6154 | 0 | got_entry_addr = value; |
6155 | |
|
6156 | 0 | if (aarch64_relocation_aginst_gp_p (bfd_r_type)) |
6157 | 0 | addend = (globals->root.sgot->output_section->vma |
6158 | 0 | + globals->root.sgot->output_offset); |
6159 | 0 | value = _bfd_aarch64_elf_resolve_relocation (input_bfd, bfd_r_type, |
6160 | 0 | place, value, |
6161 | 0 | addend, weak_undef_p); |
6162 | 0 | } |
6163 | 0 | else |
6164 | 0 | { |
6165 | 0 | bfd_vma addend = 0; |
6166 | 0 | struct elf_aarch64_local_symbol *locals |
6167 | 0 | = elf_aarch64_locals (input_bfd); |
6168 | |
|
6169 | 0 | if (locals == NULL) |
6170 | 0 | { |
6171 | 0 | int howto_index = bfd_r_type - BFD_RELOC_AARCH64_RELOC_START; |
6172 | 0 | _bfd_error_handler |
6173 | | /* xgettext:c-format */ |
6174 | 0 | (_("%pB: local symbol descriptor table be NULL when applying " |
6175 | 0 | "relocation %s against local symbol"), |
6176 | 0 | input_bfd, elf64_aarch64_howto_table[howto_index].name); |
6177 | 0 | abort (); |
6178 | 0 | } |
6179 | | |
6180 | 0 | off = symbol_got_offset (input_bfd, h, r_symndx); |
6181 | 0 | base_got = globals->root.sgot; |
6182 | 0 | got_entry_addr = (base_got->output_section->vma |
6183 | 0 | + base_got->output_offset + off); |
6184 | |
|
6185 | 0 | if (!symbol_got_offset_mark_p (input_bfd, h, r_symndx)) |
6186 | 0 | { |
6187 | 0 | bfd_put_64 (output_bfd, value, base_got->contents + off); |
6188 | | |
6189 | | /* For local symbol, we have done absolute relocation in static |
6190 | | linking stage. While for shared library, we need to update the |
6191 | | content of GOT entry according to the shared object's runtime |
6192 | | base address. So, we need to generate a R_AARCH64_RELATIVE reloc |
6193 | | for dynamic linker. */ |
6194 | 0 | if (bfd_link_pic (info)) |
6195 | 0 | relative_reloc = true; |
6196 | |
|
6197 | 0 | symbol_got_offset_mark (input_bfd, h, r_symndx); |
6198 | 0 | } |
6199 | | |
6200 | | /* Update the relocation value to GOT entry addr as we have transformed |
6201 | | the direct data access into indirect data access through GOT. */ |
6202 | 0 | value = got_entry_addr; |
6203 | |
|
6204 | 0 | if (aarch64_relocation_aginst_gp_p (bfd_r_type)) |
6205 | 0 | addend = base_got->output_section->vma + base_got->output_offset; |
6206 | |
|
6207 | 0 | value = _bfd_aarch64_elf_resolve_relocation (input_bfd, bfd_r_type, |
6208 | 0 | place, value, |
6209 | 0 | addend, weak_undef_p); |
6210 | 0 | } |
6211 | | |
6212 | 0 | if (relative_reloc) |
6213 | 0 | { |
6214 | 0 | asection *s; |
6215 | 0 | Elf_Internal_Rela outrel; |
6216 | |
|
6217 | 0 | s = globals->root.srelgot; |
6218 | 0 | if (s == NULL) |
6219 | 0 | abort (); |
6220 | | |
6221 | 0 | outrel.r_offset = got_entry_addr; |
6222 | 0 | outrel.r_info = ELF64_R_INFO (0, AARCH64_R (RELATIVE)); |
6223 | 0 | outrel.r_addend = orig_value; |
6224 | 0 | elf_append_rela (output_bfd, s, &outrel); |
6225 | 0 | } |
6226 | 0 | break; |
6227 | | |
6228 | 0 | case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC: |
6229 | 0 | case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21: |
6230 | 0 | case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21: |
6231 | 0 | case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21: |
6232 | 0 | case BFD_RELOC_AARCH64_TLSIE_LD32_GOTTPREL_LO12_NC: |
6233 | 0 | case BFD_RELOC_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC: |
6234 | 0 | case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19: |
6235 | 0 | case BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC: |
6236 | 0 | case BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21: |
6237 | 0 | case BFD_RELOC_AARCH64_TLSLD_ADR_PREL21: |
6238 | 0 | if (globals->root.sgot == NULL) |
6239 | 0 | return bfd_reloc_notsupported; |
6240 | | |
6241 | 0 | value = (symbol_got_offset (input_bfd, h, r_symndx) |
6242 | 0 | + globals->root.sgot->output_section->vma |
6243 | 0 | + globals->root.sgot->output_offset); |
6244 | |
|
6245 | 0 | value = _bfd_aarch64_elf_resolve_relocation (input_bfd, bfd_r_type, |
6246 | 0 | place, value, |
6247 | 0 | 0, weak_undef_p); |
6248 | 0 | *unresolved_reloc_p = false; |
6249 | 0 | break; |
6250 | | |
6251 | 0 | case BFD_RELOC_AARCH64_TLSGD_MOVW_G0_NC: |
6252 | 0 | case BFD_RELOC_AARCH64_TLSGD_MOVW_G1: |
6253 | 0 | case BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G0_NC: |
6254 | 0 | case BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G1: |
6255 | 0 | if (globals->root.sgot == NULL) |
6256 | 0 | return bfd_reloc_notsupported; |
6257 | | |
6258 | 0 | value = symbol_got_offset (input_bfd, h, r_symndx); |
6259 | 0 | value = _bfd_aarch64_elf_resolve_relocation (input_bfd, bfd_r_type, |
6260 | 0 | place, value, |
6261 | 0 | 0, weak_undef_p); |
6262 | 0 | *unresolved_reloc_p = false; |
6263 | 0 | break; |
6264 | | |
6265 | 0 | case BFD_RELOC_AARCH64_TLSLD_ADD_DTPREL_HI12: |
6266 | 0 | case BFD_RELOC_AARCH64_TLSLD_ADD_DTPREL_LO12: |
6267 | 0 | case BFD_RELOC_AARCH64_TLSLD_ADD_DTPREL_LO12_NC: |
6268 | 0 | case BFD_RELOC_AARCH64_TLSLD_LDST16_DTPREL_LO12: |
6269 | 0 | case BFD_RELOC_AARCH64_TLSLD_LDST16_DTPREL_LO12_NC: |
6270 | 0 | case BFD_RELOC_AARCH64_TLSLD_LDST32_DTPREL_LO12: |
6271 | 0 | case BFD_RELOC_AARCH64_TLSLD_LDST32_DTPREL_LO12_NC: |
6272 | 0 | case BFD_RELOC_AARCH64_TLSLD_LDST64_DTPREL_LO12: |
6273 | 0 | case BFD_RELOC_AARCH64_TLSLD_LDST64_DTPREL_LO12_NC: |
6274 | 0 | case BFD_RELOC_AARCH64_TLSLD_LDST8_DTPREL_LO12: |
6275 | 0 | case BFD_RELOC_AARCH64_TLSLD_LDST8_DTPREL_LO12_NC: |
6276 | 0 | case BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G0: |
6277 | 0 | case BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G0_NC: |
6278 | 0 | case BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G1: |
6279 | 0 | case BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G1_NC: |
6280 | 0 | case BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G2: |
6281 | 0 | { |
6282 | 0 | if (!(weak_undef_p || elf_hash_table (info)->tls_sec)) |
6283 | 0 | { |
6284 | 0 | int howto_index = bfd_r_type - BFD_RELOC_AARCH64_RELOC_START; |
6285 | 0 | _bfd_error_handler |
6286 | | /* xgettext:c-format */ |
6287 | 0 | (_("%pB: TLS relocation %s against undefined symbol `%s'"), |
6288 | 0 | input_bfd, elf64_aarch64_howto_table[howto_index].name, |
6289 | 0 | h->root.root.string); |
6290 | 0 | bfd_set_error (bfd_error_bad_value); |
6291 | 0 | return bfd_reloc_notsupported; |
6292 | 0 | } |
6293 | | |
6294 | 0 | bfd_vma def_value |
6295 | 0 | = weak_undef_p ? 0 : signed_addend - dtpoff_base (info); |
6296 | 0 | value = _bfd_aarch64_elf_resolve_relocation (input_bfd, bfd_r_type, |
6297 | 0 | place, value, |
6298 | 0 | def_value, weak_undef_p); |
6299 | 0 | break; |
6300 | 0 | } |
6301 | | |
6302 | 0 | case BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_HI12: |
6303 | 0 | case BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_LO12: |
6304 | 0 | case BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_LO12_NC: |
6305 | 0 | case BFD_RELOC_AARCH64_TLSLE_LDST16_TPREL_LO12: |
6306 | 0 | case BFD_RELOC_AARCH64_TLSLE_LDST16_TPREL_LO12_NC: |
6307 | 0 | case BFD_RELOC_AARCH64_TLSLE_LDST32_TPREL_LO12: |
6308 | 0 | case BFD_RELOC_AARCH64_TLSLE_LDST32_TPREL_LO12_NC: |
6309 | 0 | case BFD_RELOC_AARCH64_TLSLE_LDST64_TPREL_LO12: |
6310 | 0 | case BFD_RELOC_AARCH64_TLSLE_LDST64_TPREL_LO12_NC: |
6311 | 0 | case BFD_RELOC_AARCH64_TLSLE_LDST8_TPREL_LO12: |
6312 | 0 | case BFD_RELOC_AARCH64_TLSLE_LDST8_TPREL_LO12_NC: |
6313 | 0 | case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0: |
6314 | 0 | case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC: |
6315 | 0 | case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1: |
6316 | 0 | case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1_NC: |
6317 | 0 | case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G2: |
6318 | 0 | { |
6319 | 0 | if (!(weak_undef_p || elf_hash_table (info)->tls_sec)) |
6320 | 0 | { |
6321 | 0 | int howto_index = bfd_r_type - BFD_RELOC_AARCH64_RELOC_START; |
6322 | 0 | _bfd_error_handler |
6323 | | /* xgettext:c-format */ |
6324 | 0 | (_("%pB: TLS relocation %s against undefined symbol `%s'"), |
6325 | 0 | input_bfd, elf64_aarch64_howto_table[howto_index].name, |
6326 | 0 | h->root.root.string); |
6327 | 0 | bfd_set_error (bfd_error_bad_value); |
6328 | 0 | return bfd_reloc_notsupported; |
6329 | 0 | } |
6330 | | |
6331 | 0 | bfd_vma def_value |
6332 | 0 | = weak_undef_p ? 0 : signed_addend - tpoff_base (info); |
6333 | 0 | value = _bfd_aarch64_elf_resolve_relocation (input_bfd, bfd_r_type, |
6334 | 0 | place, value, |
6335 | 0 | def_value, weak_undef_p); |
6336 | 0 | *unresolved_reloc_p = false; |
6337 | 0 | break; |
6338 | 0 | } |
6339 | | |
6340 | 0 | case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12: |
6341 | 0 | case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21: |
6342 | 0 | case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21: |
6343 | 0 | case BFD_RELOC_AARCH64_TLSDESC_LD32_LO12_NC: |
6344 | 0 | case BFD_RELOC_AARCH64_TLSDESC_LD64_LO12: |
6345 | 0 | case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19: |
6346 | 0 | if (globals->root.sgot == NULL) |
6347 | 0 | return bfd_reloc_notsupported; |
6348 | 0 | value = (symbol_tlsdesc_got_offset (input_bfd, h, r_symndx) |
6349 | 0 | + globals->root.sgotplt->output_section->vma |
6350 | 0 | + globals->root.sgotplt->output_offset |
6351 | 0 | + globals->sgotplt_jump_table_size); |
6352 | |
|
6353 | 0 | value = _bfd_aarch64_elf_resolve_relocation (input_bfd, bfd_r_type, |
6354 | 0 | place, value, |
6355 | 0 | 0, weak_undef_p); |
6356 | 0 | *unresolved_reloc_p = false; |
6357 | 0 | break; |
6358 | | |
6359 | 0 | case BFD_RELOC_AARCH64_TLSDESC_OFF_G0_NC: |
6360 | 0 | case BFD_RELOC_AARCH64_TLSDESC_OFF_G1: |
6361 | 0 | if (globals->root.sgot == NULL) |
6362 | 0 | return bfd_reloc_notsupported; |
6363 | | |
6364 | 0 | value = (symbol_tlsdesc_got_offset (input_bfd, h, r_symndx) |
6365 | 0 | + globals->root.sgotplt->output_section->vma |
6366 | 0 | + globals->root.sgotplt->output_offset |
6367 | 0 | + globals->sgotplt_jump_table_size); |
6368 | |
|
6369 | 0 | value -= (globals->root.sgot->output_section->vma |
6370 | 0 | + globals->root.sgot->output_offset); |
6371 | |
|
6372 | 0 | value = _bfd_aarch64_elf_resolve_relocation (input_bfd, bfd_r_type, |
6373 | 0 | place, value, |
6374 | 0 | 0, weak_undef_p); |
6375 | 0 | *unresolved_reloc_p = false; |
6376 | 0 | break; |
6377 | | |
6378 | 0 | default: |
6379 | 0 | return bfd_reloc_notsupported; |
6380 | 0 | } |
6381 | | |
6382 | 0 | if (saved_addend) |
6383 | 0 | *saved_addend = value; |
6384 | | |
6385 | | /* Only apply the final relocation in a sequence. */ |
6386 | 0 | if (save_addend) |
6387 | 0 | return bfd_reloc_continue; |
6388 | | |
6389 | 0 | return _bfd_aarch64_elf_put_addend (input_bfd, hit_data, bfd_r_type, |
6390 | 0 | howto, value); |
6391 | 0 | } |
6392 | | |
6393 | | /* LP64 and ILP32 operates on x- and w-registers respectively. |
6394 | | Next definitions take into account the difference between |
6395 | | corresponding machine codes. R means x-register if the target |
6396 | | arch is LP64, and w-register if the target is ILP32. */ |
6397 | | |
6398 | | #if ARCH_SIZE == 64 |
6399 | 0 | # define add_R0_R0 (0x91000000) |
6400 | 0 | # define add_R0_R0_R1 (0x8b000020) |
6401 | 0 | # define add_R0_R1 (0x91400020) |
6402 | 0 | # define ldr_R0 (0x58000000) |
6403 | 0 | # define ldr_R0_mask(i) (i & 0xffffffe0) |
6404 | 0 | # define ldr_R0_x0 (0xf9400000) |
6405 | 0 | # define ldr_hw_R0 (0xf2a00000) |
6406 | 0 | # define movk_R0 (0xf2800000) |
6407 | 0 | # define movz_R0 (0xd2a00000) |
6408 | 0 | # define movz_hw_R0 (0xd2c00000) |
6409 | | #else /*ARCH_SIZE == 32 */ |
6410 | | # define add_R0_R0 (0x11000000) |
6411 | | # define add_R0_R0_R1 (0x0b000020) |
6412 | | # define add_R0_R1 (0x11400020) |
6413 | | # define ldr_R0 (0x18000000) |
6414 | | # define ldr_R0_mask(i) (i & 0xbfffffe0) |
6415 | | # define ldr_R0_x0 (0xb9400000) |
6416 | | # define ldr_hw_R0 (0x72a00000) |
6417 | | # define movk_R0 (0x72800000) |
6418 | | # define movz_R0 (0x52a00000) |
6419 | | # define movz_hw_R0 (0x52c00000) |
6420 | | #endif |
6421 | | |
6422 | | /* Structure to hold payload for _bfd_aarch64_erratum_843419_clear_stub, |
6423 | | it is used to identify the stub information to reset. */ |
6424 | | |
6425 | | struct erratum_843419_branch_to_stub_clear_data |
6426 | | { |
6427 | | bfd_vma adrp_offset; |
6428 | | asection *output_section; |
6429 | | }; |
6430 | | |
6431 | | /* Clear the erratum information for GEN_ENTRY if the ADRP_OFFSET and |
6432 | | section inside IN_ARG matches. The clearing is done by setting the |
6433 | | stub_type to none. */ |
6434 | | |
6435 | | static bool |
6436 | | _bfd_aarch64_erratum_843419_clear_stub (struct bfd_hash_entry *gen_entry, |
6437 | | void *in_arg) |
6438 | 0 | { |
6439 | 0 | struct elf_aarch64_stub_hash_entry *stub_entry |
6440 | 0 | = (struct elf_aarch64_stub_hash_entry *) gen_entry; |
6441 | 0 | struct erratum_843419_branch_to_stub_clear_data *data |
6442 | 0 | = (struct erratum_843419_branch_to_stub_clear_data *) in_arg; |
6443 | |
|
6444 | 0 | if (stub_entry->target_section != data->output_section |
6445 | 0 | || stub_entry->stub_type != aarch64_stub_erratum_843419_veneer |
6446 | 0 | || stub_entry->adrp_offset != data->adrp_offset) |
6447 | 0 | return true; |
6448 | | |
6449 | | /* Change the stub type instead of removing the entry, removing from the hash |
6450 | | table would be slower and we have already reserved the memory for the entry |
6451 | | so there wouldn't be much gain. Changing the stub also keeps around a |
6452 | | record of what was there before. */ |
6453 | 0 | stub_entry->stub_type = aarch64_stub_none; |
6454 | | |
6455 | | /* We're done and there could have been only one matching stub at that |
6456 | | particular offset, so abort further traversal. */ |
6457 | 0 | return false; |
6458 | 0 | } |
6459 | | |
6460 | | /* TLS Relaxations may relax an adrp sequence that matches the erratum 843419 |
6461 | | sequence. In this case the erratum no longer applies and we need to remove |
6462 | | the entry from the pending stub generation. This clears matching adrp insn |
6463 | | at ADRP_OFFSET in INPUT_SECTION in the stub table defined in GLOBALS. */ |
6464 | | |
6465 | | static void |
6466 | | clear_erratum_843419_entry (struct elf_aarch64_link_hash_table *globals, |
6467 | | bfd_vma adrp_offset, asection *input_section) |
6468 | 0 | { |
6469 | 0 | if (globals->fix_erratum_843419 & ERRAT_ADRP) |
6470 | 0 | { |
6471 | 0 | struct erratum_843419_branch_to_stub_clear_data data; |
6472 | 0 | data.adrp_offset = adrp_offset; |
6473 | 0 | data.output_section = input_section; |
6474 | |
|
6475 | 0 | bfd_hash_traverse (&globals->stub_hash_table, |
6476 | 0 | _bfd_aarch64_erratum_843419_clear_stub, &data); |
6477 | 0 | } |
6478 | 0 | } |
6479 | | |
6480 | | /* Handle TLS relaxations. Relaxing is possible for symbols that use |
6481 | | R_AARCH64_TLSDESC_ADR_{PAGE, LD64_LO12_NC, ADD_LO12_NC} during a static |
6482 | | link. |
6483 | | |
6484 | | Return bfd_reloc_ok if we're done, bfd_reloc_continue if the caller |
6485 | | is to then call final_link_relocate. Return other values in the |
6486 | | case of error. */ |
6487 | | |
6488 | | static bfd_reloc_status_type |
6489 | | elf64_aarch64_tls_relax (struct elf_aarch64_link_hash_table *globals, |
6490 | | bfd *input_bfd, asection *input_section, |
6491 | | bfd_byte *contents, Elf_Internal_Rela *rel, |
6492 | | struct elf_link_hash_entry *h, |
6493 | | struct bfd_link_info *info) |
6494 | 0 | { |
6495 | 0 | bool local_exec = bfd_link_executable (info) |
6496 | 0 | && SYMBOL_REFERENCES_LOCAL (info, h); |
6497 | 0 | unsigned int r_type = ELF64_R_TYPE (rel->r_info); |
6498 | 0 | unsigned long insn; |
6499 | |
|
6500 | 0 | BFD_ASSERT (globals && input_bfd && contents && rel); |
6501 | |
|
6502 | 0 | switch (elf64_aarch64_bfd_reloc_from_type (input_bfd, r_type)) |
6503 | 0 | { |
6504 | 0 | case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21: |
6505 | 0 | case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21: |
6506 | 0 | if (local_exec) |
6507 | 0 | { |
6508 | | /* GD->LE relaxation: |
6509 | | adrp x0, :tlsgd:var => movz R0, :tprel_g1:var |
6510 | | or |
6511 | | adrp x0, :tlsdesc:var => movz R0, :tprel_g1:var |
6512 | | |
6513 | | Where R is x for LP64, and w for ILP32. */ |
6514 | 0 | bfd_putl32 (movz_R0, contents + rel->r_offset); |
6515 | | /* We have relaxed the adrp into a mov, we may have to clear any |
6516 | | pending erratum fixes. */ |
6517 | 0 | clear_erratum_843419_entry (globals, rel->r_offset, input_section); |
6518 | 0 | return bfd_reloc_continue; |
6519 | 0 | } |
6520 | 0 | else |
6521 | 0 | { |
6522 | | /* GD->IE relaxation: |
6523 | | adrp x0, :tlsgd:var => adrp x0, :gottprel:var |
6524 | | or |
6525 | | adrp x0, :tlsdesc:var => adrp x0, :gottprel:var |
6526 | | */ |
6527 | 0 | return bfd_reloc_continue; |
6528 | 0 | } |
6529 | | |
6530 | 0 | case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21: |
6531 | 0 | BFD_ASSERT (0); |
6532 | 0 | break; |
6533 | | |
6534 | 0 | case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19: |
6535 | 0 | if (local_exec) |
6536 | 0 | { |
6537 | | /* Tiny TLSDESC->LE relaxation: |
6538 | | ldr x1, :tlsdesc:var => movz R0, #:tprel_g1:var |
6539 | | adr x0, :tlsdesc:var => movk R0, #:tprel_g0_nc:var |
6540 | | .tlsdesccall var |
6541 | | blr x1 => nop |
6542 | | |
6543 | | Where R is x for LP64, and w for ILP32. */ |
6544 | 0 | BFD_ASSERT (ELF64_R_TYPE (rel[1].r_info) == AARCH64_R (TLSDESC_ADR_PREL21)); |
6545 | 0 | BFD_ASSERT (ELF64_R_TYPE (rel[2].r_info) == AARCH64_R (TLSDESC_CALL)); |
6546 | |
|
6547 | 0 | rel[1].r_info = ELF64_R_INFO (ELF64_R_SYM (rel->r_info), |
6548 | 0 | AARCH64_R (TLSLE_MOVW_TPREL_G0_NC)); |
6549 | 0 | rel[2].r_info = ELF64_R_INFO (STN_UNDEF, R_AARCH64_NONE); |
6550 | |
|
6551 | 0 | bfd_putl32 (movz_R0, contents + rel->r_offset); |
6552 | 0 | bfd_putl32 (movk_R0, contents + rel->r_offset + 4); |
6553 | 0 | bfd_putl32 (INSN_NOP, contents + rel->r_offset + 8); |
6554 | 0 | return bfd_reloc_continue; |
6555 | 0 | } |
6556 | 0 | else |
6557 | 0 | { |
6558 | | /* Tiny TLSDESC->IE relaxation: |
6559 | | ldr x1, :tlsdesc:var => ldr x0, :gottprel:var |
6560 | | adr x0, :tlsdesc:var => nop |
6561 | | .tlsdesccall var |
6562 | | blr x1 => nop |
6563 | | */ |
6564 | 0 | BFD_ASSERT (ELF64_R_TYPE (rel[1].r_info) == AARCH64_R (TLSDESC_ADR_PREL21)); |
6565 | 0 | BFD_ASSERT (ELF64_R_TYPE (rel[2].r_info) == AARCH64_R (TLSDESC_CALL)); |
6566 | |
|
6567 | 0 | rel[1].r_info = ELF64_R_INFO (STN_UNDEF, R_AARCH64_NONE); |
6568 | 0 | rel[2].r_info = ELF64_R_INFO (STN_UNDEF, R_AARCH64_NONE); |
6569 | |
|
6570 | 0 | bfd_putl32 (ldr_R0, contents + rel->r_offset); |
6571 | 0 | bfd_putl32 (INSN_NOP, contents + rel->r_offset + 4); |
6572 | 0 | bfd_putl32 (INSN_NOP, contents + rel->r_offset + 8); |
6573 | 0 | return bfd_reloc_continue; |
6574 | 0 | } |
6575 | | |
6576 | 0 | case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21: |
6577 | 0 | if (local_exec) |
6578 | 0 | { |
6579 | | /* Tiny GD->LE relaxation: |
6580 | | adr x0, :tlsgd:var => mrs x1, tpidr_el0 |
6581 | | bl __tls_get_addr => add R0, R1, #:tprel_hi12:x, lsl #12 |
6582 | | nop => add R0, R0, #:tprel_lo12_nc:x |
6583 | | |
6584 | | Where R is x for LP64, and x for Ilp32. */ |
6585 | | |
6586 | | /* First kill the tls_get_addr reloc on the bl instruction. */ |
6587 | 0 | BFD_ASSERT (rel->r_offset + 4 == rel[1].r_offset); |
6588 | |
|
6589 | 0 | bfd_putl32 (0xd53bd041, contents + rel->r_offset + 0); |
6590 | 0 | bfd_putl32 (add_R0_R1, contents + rel->r_offset + 4); |
6591 | 0 | bfd_putl32 (add_R0_R0, contents + rel->r_offset + 8); |
6592 | |
|
6593 | 0 | rel[1].r_info = ELF64_R_INFO (ELF64_R_SYM (rel->r_info), |
6594 | 0 | AARCH64_R (TLSLE_ADD_TPREL_LO12_NC)); |
6595 | 0 | rel[1].r_offset = rel->r_offset + 8; |
6596 | | |
6597 | | /* Move the current relocation to the second instruction in |
6598 | | the sequence. */ |
6599 | 0 | rel->r_offset += 4; |
6600 | 0 | rel->r_info = ELF64_R_INFO (ELF64_R_SYM (rel->r_info), |
6601 | 0 | AARCH64_R (TLSLE_ADD_TPREL_HI12)); |
6602 | 0 | return bfd_reloc_continue; |
6603 | 0 | } |
6604 | 0 | else |
6605 | 0 | { |
6606 | | /* Tiny GD->IE relaxation: |
6607 | | adr x0, :tlsgd:var => ldr R0, :gottprel:var |
6608 | | bl __tls_get_addr => mrs x1, tpidr_el0 |
6609 | | nop => add R0, R0, R1 |
6610 | | |
6611 | | Where R is x for LP64, and w for Ilp32. */ |
6612 | | |
6613 | | /* First kill the tls_get_addr reloc on the bl instruction. */ |
6614 | 0 | BFD_ASSERT (rel->r_offset + 4 == rel[1].r_offset); |
6615 | 0 | rel[1].r_info = ELF64_R_INFO (STN_UNDEF, R_AARCH64_NONE); |
6616 | |
|
6617 | 0 | bfd_putl32 (ldr_R0, contents + rel->r_offset); |
6618 | 0 | bfd_putl32 (0xd53bd041, contents + rel->r_offset + 4); |
6619 | 0 | bfd_putl32 (add_R0_R0_R1, contents + rel->r_offset + 8); |
6620 | 0 | return bfd_reloc_continue; |
6621 | 0 | } |
6622 | | |
6623 | 0 | #if ARCH_SIZE == 64 |
6624 | 0 | case BFD_RELOC_AARCH64_TLSGD_MOVW_G1: |
6625 | 0 | BFD_ASSERT (ELF64_R_TYPE (rel[1].r_info) == AARCH64_R (TLSGD_MOVW_G0_NC)); |
6626 | 0 | BFD_ASSERT (rel->r_offset + 12 == rel[2].r_offset); |
6627 | 0 | BFD_ASSERT (ELF64_R_TYPE (rel[2].r_info) == AARCH64_R (CALL26)); |
6628 | |
|
6629 | 0 | if (local_exec) |
6630 | 0 | { |
6631 | | /* Large GD->LE relaxation: |
6632 | | movz x0, #:tlsgd_g1:var => movz x0, #:tprel_g2:var, lsl #32 |
6633 | | movk x0, #:tlsgd_g0_nc:var => movk x0, #:tprel_g1_nc:var, lsl #16 |
6634 | | add x0, gp, x0 => movk x0, #:tprel_g0_nc:var |
6635 | | bl __tls_get_addr => mrs x1, tpidr_el0 |
6636 | | nop => add x0, x0, x1 |
6637 | | */ |
6638 | 0 | rel[2].r_info = ELF64_R_INFO (ELF64_R_SYM (rel->r_info), |
6639 | 0 | AARCH64_R (TLSLE_MOVW_TPREL_G0_NC)); |
6640 | 0 | rel[2].r_offset = rel->r_offset + 8; |
6641 | |
|
6642 | 0 | bfd_putl32 (movz_hw_R0, contents + rel->r_offset + 0); |
6643 | 0 | bfd_putl32 (ldr_hw_R0, contents + rel->r_offset + 4); |
6644 | 0 | bfd_putl32 (movk_R0, contents + rel->r_offset + 8); |
6645 | 0 | bfd_putl32 (0xd53bd041, contents + rel->r_offset + 12); |
6646 | 0 | bfd_putl32 (add_R0_R0_R1, contents + rel->r_offset + 16); |
6647 | 0 | } |
6648 | 0 | else |
6649 | 0 | { |
6650 | | /* Large GD->IE relaxation: |
6651 | | movz x0, #:tlsgd_g1:var => movz x0, #:gottprel_g1:var, lsl #16 |
6652 | | movk x0, #:tlsgd_g0_nc:var => movk x0, #:gottprel_g0_nc:var |
6653 | | add x0, gp, x0 => ldr x0, [gp, x0] |
6654 | | bl __tls_get_addr => mrs x1, tpidr_el0 |
6655 | | nop => add x0, x0, x1 |
6656 | | */ |
6657 | 0 | rel[2].r_info = ELF64_R_INFO (STN_UNDEF, R_AARCH64_NONE); |
6658 | 0 | bfd_putl32 (0xd2a80000, contents + rel->r_offset + 0); |
6659 | 0 | bfd_putl32 (ldr_R0, contents + rel->r_offset + 8); |
6660 | 0 | bfd_putl32 (0xd53bd041, contents + rel->r_offset + 12); |
6661 | 0 | bfd_putl32 (add_R0_R0_R1, contents + rel->r_offset + 16); |
6662 | 0 | } |
6663 | 0 | return bfd_reloc_continue; |
6664 | | |
6665 | 0 | case BFD_RELOC_AARCH64_TLSGD_MOVW_G0_NC: |
6666 | 0 | return bfd_reloc_continue; |
6667 | 0 | #endif |
6668 | | |
6669 | 0 | case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19: |
6670 | 0 | return bfd_reloc_continue; |
6671 | | |
6672 | 0 | case BFD_RELOC_AARCH64_TLSDESC_LD64_LO12_NC: |
6673 | 0 | if (local_exec) |
6674 | 0 | { |
6675 | | /* GD->LE relaxation: |
6676 | | ldr xd, [x0, #:tlsdesc_lo12:var] => movk x0, :tprel_g0_nc:var |
6677 | | |
6678 | | Where R is x for lp64 mode, and w for ILP32 mode. */ |
6679 | 0 | bfd_putl32 (movk_R0, contents + rel->r_offset); |
6680 | 0 | return bfd_reloc_continue; |
6681 | 0 | } |
6682 | 0 | else |
6683 | 0 | { |
6684 | | /* GD->IE relaxation: |
6685 | | ldr xd, [x0, #:tlsdesc_lo12:var] => ldr R0, [x0, #:gottprel_lo12:var] |
6686 | | |
6687 | | Where R is x for lp64 mode, and w for ILP32 mode. */ |
6688 | 0 | insn = bfd_getl32 (contents + rel->r_offset); |
6689 | 0 | bfd_putl32 (ldr_R0_mask (insn), contents + rel->r_offset); |
6690 | 0 | return bfd_reloc_continue; |
6691 | 0 | } |
6692 | | |
6693 | 0 | case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC: |
6694 | 0 | if (local_exec) |
6695 | 0 | { |
6696 | | /* GD->LE relaxation |
6697 | | add x0, #:tlsgd_lo12:var => movk R0, :tprel_g0_nc:var |
6698 | | bl __tls_get_addr => mrs x1, tpidr_el0 |
6699 | | nop => add R0, R1, R0 |
6700 | | |
6701 | | Where R is x for lp64 mode, and w for ILP32 mode. */ |
6702 | | |
6703 | | /* First kill the tls_get_addr reloc on the bl instruction. */ |
6704 | 0 | BFD_ASSERT (rel->r_offset + 4 == rel[1].r_offset); |
6705 | 0 | rel[1].r_info = ELF64_R_INFO (STN_UNDEF, R_AARCH64_NONE); |
6706 | |
|
6707 | 0 | bfd_putl32 (movk_R0, contents + rel->r_offset); |
6708 | 0 | bfd_putl32 (0xd53bd041, contents + rel->r_offset + 4); |
6709 | 0 | bfd_putl32 (add_R0_R0_R1, contents + rel->r_offset + 8); |
6710 | 0 | return bfd_reloc_continue; |
6711 | 0 | } |
6712 | 0 | else |
6713 | 0 | { |
6714 | | /* GD->IE relaxation |
6715 | | ADD x0, #:tlsgd_lo12:var => ldr R0, [x0, #:gottprel_lo12:var] |
6716 | | BL __tls_get_addr => mrs x1, tpidr_el0 |
6717 | | R_AARCH64_CALL26 |
6718 | | NOP => add R0, R1, R0 |
6719 | | |
6720 | | Where R is x for lp64 mode, and w for ilp32 mode. */ |
6721 | |
|
6722 | 0 | BFD_ASSERT (ELF64_R_TYPE (rel[1].r_info) == AARCH64_R (CALL26)); |
6723 | | |
6724 | | /* Remove the relocation on the BL instruction. */ |
6725 | 0 | rel[1].r_info = ELF64_R_INFO (STN_UNDEF, R_AARCH64_NONE); |
6726 | | |
6727 | | /* We choose to fixup the BL and NOP instructions using the |
6728 | | offset from the second relocation to allow flexibility in |
6729 | | scheduling instructions between the ADD and BL. */ |
6730 | 0 | bfd_putl32 (ldr_R0_x0, contents + rel->r_offset); |
6731 | 0 | bfd_putl32 (0xd53bd041, contents + rel[1].r_offset); |
6732 | 0 | bfd_putl32 (add_R0_R0_R1, contents + rel[1].r_offset + 4); |
6733 | 0 | return bfd_reloc_continue; |
6734 | 0 | } |
6735 | | |
6736 | 0 | case BFD_RELOC_AARCH64_TLSDESC_ADD: |
6737 | 0 | case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12: |
6738 | 0 | case BFD_RELOC_AARCH64_TLSDESC_CALL: |
6739 | | /* GD->IE/LE relaxation: |
6740 | | add x0, x0, #:tlsdesc_lo12:var => nop |
6741 | | blr xd => nop |
6742 | | */ |
6743 | 0 | bfd_putl32 (INSN_NOP, contents + rel->r_offset); |
6744 | 0 | return bfd_reloc_ok; |
6745 | | |
6746 | 0 | case BFD_RELOC_AARCH64_TLSDESC_LDR: |
6747 | 0 | if (local_exec) |
6748 | 0 | { |
6749 | | /* GD->LE relaxation: |
6750 | | ldr xd, [gp, xn] => movk R0, #:tprel_g0_nc:var |
6751 | | |
6752 | | Where R is x for lp64 mode, and w for ILP32 mode. */ |
6753 | 0 | bfd_putl32 (movk_R0, contents + rel->r_offset); |
6754 | 0 | return bfd_reloc_continue; |
6755 | 0 | } |
6756 | 0 | else |
6757 | 0 | { |
6758 | | /* GD->IE relaxation: |
6759 | | ldr xd, [gp, xn] => ldr R0, [gp, xn] |
6760 | | |
6761 | | Where R is x for lp64 mode, and w for ILP32 mode. */ |
6762 | 0 | insn = bfd_getl32 (contents + rel->r_offset); |
6763 | 0 | bfd_putl32 (ldr_R0_mask (insn), contents + rel->r_offset); |
6764 | 0 | return bfd_reloc_ok; |
6765 | 0 | } |
6766 | | |
6767 | 0 | case BFD_RELOC_AARCH64_TLSDESC_OFF_G0_NC: |
6768 | | /* GD->LE relaxation: |
6769 | | movk xd, #:tlsdesc_off_g0_nc:var => movk R0, #:tprel_g1_nc:var, lsl #16 |
6770 | | GD->IE relaxation: |
6771 | | movk xd, #:tlsdesc_off_g0_nc:var => movk Rd, #:gottprel_g0_nc:var |
6772 | | |
6773 | | Where R is x for lp64 mode, and w for ILP32 mode. */ |
6774 | 0 | if (local_exec) |
6775 | 0 | bfd_putl32 (ldr_hw_R0, contents + rel->r_offset); |
6776 | 0 | return bfd_reloc_continue; |
6777 | | |
6778 | 0 | case BFD_RELOC_AARCH64_TLSDESC_OFF_G1: |
6779 | 0 | if (local_exec) |
6780 | 0 | { |
6781 | | /* GD->LE relaxation: |
6782 | | movz xd, #:tlsdesc_off_g1:var => movz R0, #:tprel_g2:var, lsl #32 |
6783 | | |
6784 | | Where R is x for lp64 mode, and w for ILP32 mode. */ |
6785 | 0 | bfd_putl32 (movz_hw_R0, contents + rel->r_offset); |
6786 | 0 | return bfd_reloc_continue; |
6787 | 0 | } |
6788 | 0 | else |
6789 | 0 | { |
6790 | | /* GD->IE relaxation: |
6791 | | movz xd, #:tlsdesc_off_g1:var => movz Rd, #:gottprel_g1:var, lsl #16 |
6792 | | |
6793 | | Where R is x for lp64 mode, and w for ILP32 mode. */ |
6794 | 0 | insn = bfd_getl32 (contents + rel->r_offset); |
6795 | 0 | bfd_putl32 (movz_R0 | (insn & 0x1f), contents + rel->r_offset); |
6796 | 0 | return bfd_reloc_continue; |
6797 | 0 | } |
6798 | | |
6799 | 0 | case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21: |
6800 | | /* IE->LE relaxation: |
6801 | | adrp xd, :gottprel:var => movz Rd, :tprel_g1:var |
6802 | | |
6803 | | Where R is x for lp64 mode, and w for ILP32 mode. */ |
6804 | 0 | if (local_exec) |
6805 | 0 | { |
6806 | 0 | insn = bfd_getl32 (contents + rel->r_offset); |
6807 | 0 | bfd_putl32 (movz_R0 | (insn & 0x1f), contents + rel->r_offset); |
6808 | | /* We have relaxed the adrp into a mov, we may have to clear any |
6809 | | pending erratum fixes. */ |
6810 | 0 | clear_erratum_843419_entry (globals, rel->r_offset, input_section); |
6811 | 0 | } |
6812 | 0 | return bfd_reloc_continue; |
6813 | | |
6814 | 0 | case BFD_RELOC_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC: |
6815 | | /* IE->LE relaxation: |
6816 | | ldr xd, [xm, #:gottprel_lo12:var] => movk Rd, :tprel_g0_nc:var |
6817 | | |
6818 | | Where R is x for lp64 mode, and w for ILP32 mode. */ |
6819 | 0 | if (local_exec) |
6820 | 0 | { |
6821 | 0 | insn = bfd_getl32 (contents + rel->r_offset); |
6822 | 0 | bfd_putl32 (movk_R0 | (insn & 0x1f), contents + rel->r_offset); |
6823 | 0 | } |
6824 | 0 | return bfd_reloc_continue; |
6825 | | |
6826 | 0 | case BFD_RELOC_AARCH64_TLSLD_ADR_PREL21: |
6827 | | /* LD->LE relaxation (tiny): |
6828 | | adr x0, :tlsldm:x => mrs x0, tpidr_el0 |
6829 | | bl __tls_get_addr => add R0, R0, TCB_SIZE |
6830 | | |
6831 | | Where R is x for lp64 mode, and w for ilp32 mode. */ |
6832 | 0 | if (local_exec) |
6833 | 0 | { |
6834 | 0 | BFD_ASSERT (rel->r_offset + 4 == rel[1].r_offset); |
6835 | 0 | BFD_ASSERT (ELF64_R_TYPE (rel[1].r_info) == AARCH64_R (CALL26)); |
6836 | | /* No need of CALL26 relocation for tls_get_addr. */ |
6837 | 0 | rel[1].r_info = ELF64_R_INFO (STN_UNDEF, R_AARCH64_NONE); |
6838 | 0 | bfd_putl32 (0xd53bd040, contents + rel->r_offset + 0); |
6839 | 0 | bfd_putl32 (add_R0_R0 | (TCB_SIZE << 10), |
6840 | 0 | contents + rel->r_offset + 4); |
6841 | 0 | return bfd_reloc_ok; |
6842 | 0 | } |
6843 | 0 | return bfd_reloc_continue; |
6844 | | |
6845 | 0 | case BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21: |
6846 | | /* LD->LE relaxation (small): |
6847 | | adrp x0, :tlsldm:x => mrs x0, tpidr_el0 |
6848 | | */ |
6849 | 0 | if (local_exec) |
6850 | 0 | { |
6851 | 0 | bfd_putl32 (0xd53bd040, contents + rel->r_offset); |
6852 | 0 | return bfd_reloc_ok; |
6853 | 0 | } |
6854 | 0 | return bfd_reloc_continue; |
6855 | | |
6856 | 0 | case BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC: |
6857 | | /* LD->LE relaxation (small): |
6858 | | add x0, #:tlsldm_lo12:x => add R0, R0, TCB_SIZE |
6859 | | bl __tls_get_addr => nop |
6860 | | |
6861 | | Where R is x for lp64 mode, and w for ilp32 mode. */ |
6862 | 0 | if (local_exec) |
6863 | 0 | { |
6864 | 0 | BFD_ASSERT (rel->r_offset + 4 == rel[1].r_offset); |
6865 | 0 | BFD_ASSERT (ELF64_R_TYPE (rel[1].r_info) == AARCH64_R (CALL26)); |
6866 | | /* No need of CALL26 relocation for tls_get_addr. */ |
6867 | 0 | rel[1].r_info = ELF64_R_INFO (STN_UNDEF, R_AARCH64_NONE); |
6868 | 0 | bfd_putl32 (add_R0_R0 | (TCB_SIZE << 10), |
6869 | 0 | contents + rel->r_offset + 0); |
6870 | 0 | bfd_putl32 (INSN_NOP, contents + rel->r_offset + 4); |
6871 | 0 | return bfd_reloc_ok; |
6872 | 0 | } |
6873 | 0 | return bfd_reloc_continue; |
6874 | | |
6875 | 0 | default: |
6876 | 0 | return bfd_reloc_continue; |
6877 | 0 | } |
6878 | | |
6879 | 0 | return bfd_reloc_ok; |
6880 | 0 | } |
6881 | | |
6882 | | /* Relocate an AArch64 ELF section. */ |
6883 | | |
6884 | | static int |
6885 | | elf64_aarch64_relocate_section (bfd *output_bfd, |
6886 | | struct bfd_link_info *info, |
6887 | | bfd *input_bfd, |
6888 | | asection *input_section, |
6889 | | bfd_byte *contents, |
6890 | | Elf_Internal_Rela *relocs, |
6891 | | Elf_Internal_Sym *local_syms, |
6892 | | asection **local_sections) |
6893 | 0 | { |
6894 | 0 | Elf_Internal_Shdr *symtab_hdr; |
6895 | 0 | struct elf_link_hash_entry **sym_hashes; |
6896 | 0 | Elf_Internal_Rela *rel; |
6897 | 0 | Elf_Internal_Rela *relend; |
6898 | 0 | const char *name; |
6899 | 0 | struct elf_aarch64_link_hash_table *globals; |
6900 | 0 | bool save_addend = false; |
6901 | 0 | bfd_vma addend = 0; |
6902 | |
|
6903 | 0 | globals = elf_aarch64_hash_table (info); |
6904 | |
|
6905 | 0 | symtab_hdr = &elf_symtab_hdr (input_bfd); |
6906 | 0 | sym_hashes = elf_sym_hashes (input_bfd); |
6907 | |
|
6908 | 0 | rel = relocs; |
6909 | 0 | relend = relocs + input_section->reloc_count; |
6910 | 0 | for (; rel < relend; rel++) |
6911 | 0 | { |
6912 | 0 | unsigned int r_type; |
6913 | 0 | bfd_reloc_code_real_type bfd_r_type; |
6914 | 0 | bfd_reloc_code_real_type relaxed_bfd_r_type; |
6915 | 0 | reloc_howto_type *howto; |
6916 | 0 | unsigned long r_symndx; |
6917 | 0 | Elf_Internal_Sym *sym; |
6918 | 0 | asection *sec; |
6919 | 0 | struct elf_link_hash_entry *h; |
6920 | 0 | bfd_vma relocation; |
6921 | 0 | bfd_reloc_status_type r; |
6922 | 0 | arelent bfd_reloc; |
6923 | 0 | char sym_type; |
6924 | 0 | bool unresolved_reloc = false; |
6925 | 0 | char *error_message = NULL; |
6926 | |
|
6927 | 0 | r_symndx = ELF64_R_SYM (rel->r_info); |
6928 | 0 | r_type = ELF64_R_TYPE (rel->r_info); |
6929 | |
|
6930 | 0 | bfd_reloc.howto = elf64_aarch64_howto_from_type (input_bfd, r_type); |
6931 | 0 | howto = bfd_reloc.howto; |
6932 | |
|
6933 | 0 | if (howto == NULL) |
6934 | 0 | return _bfd_unrecognized_reloc (input_bfd, input_section, r_type); |
6935 | | |
6936 | 0 | bfd_r_type = elf64_aarch64_bfd_reloc_from_howto (howto); |
6937 | |
|
6938 | 0 | h = NULL; |
6939 | 0 | sym = NULL; |
6940 | 0 | sec = NULL; |
6941 | |
|
6942 | 0 | if (r_symndx < symtab_hdr->sh_info) |
6943 | 0 | { |
6944 | 0 | sym = local_syms + r_symndx; |
6945 | 0 | sym_type = ELF64_ST_TYPE (sym->st_info); |
6946 | 0 | sec = local_sections[r_symndx]; |
6947 | | |
6948 | | /* An object file might have a reference to a local |
6949 | | undefined symbol. This is a daft object file, but we |
6950 | | should at least do something about it. NONE and NULL |
6951 | | relocations do not use the symbol and are explicitly |
6952 | | allowed to use an undefined one, so allow those. |
6953 | | Likewise for relocations against STN_UNDEF. */ |
6954 | 0 | if (r_type != R_AARCH64_NONE && r_type != R_AARCH64_NULL |
6955 | 0 | && r_symndx != STN_UNDEF |
6956 | 0 | && bfd_is_und_section (sec) |
6957 | 0 | && ELF_ST_BIND (sym->st_info) != STB_WEAK) |
6958 | 0 | (*info->callbacks->undefined_symbol) |
6959 | 0 | (info, bfd_elf_string_from_elf_section |
6960 | 0 | (input_bfd, symtab_hdr->sh_link, sym->st_name), |
6961 | 0 | input_bfd, input_section, rel->r_offset, true); |
6962 | |
|
6963 | 0 | relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel); |
6964 | | |
6965 | | /* Relocate against local STT_GNU_IFUNC symbol. */ |
6966 | 0 | if (!bfd_link_relocatable (info) |
6967 | 0 | && ELF_ST_TYPE (sym->st_info) == STT_GNU_IFUNC) |
6968 | 0 | { |
6969 | 0 | h = elf64_aarch64_get_local_sym_hash (globals, input_bfd, |
6970 | 0 | rel, false); |
6971 | 0 | if (h == NULL) |
6972 | 0 | abort (); |
6973 | | |
6974 | | /* Set STT_GNU_IFUNC symbol value. */ |
6975 | 0 | h->root.u.def.value = sym->st_value; |
6976 | 0 | h->root.u.def.section = sec; |
6977 | 0 | } |
6978 | 0 | } |
6979 | 0 | else |
6980 | 0 | { |
6981 | 0 | bool warned, ignored; |
6982 | |
|
6983 | 0 | RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel, |
6984 | 0 | r_symndx, symtab_hdr, sym_hashes, |
6985 | 0 | h, sec, relocation, |
6986 | 0 | unresolved_reloc, warned, ignored); |
6987 | | |
6988 | 0 | sym_type = h->type; |
6989 | 0 | } |
6990 | | |
6991 | 0 | if (sec != NULL && discarded_section (sec)) |
6992 | 0 | RELOC_AGAINST_DISCARDED_SECTION (info, input_bfd, input_section, |
6993 | 0 | rel, 1, relend, howto, 0, contents); |
6994 | |
|
6995 | 0 | if (bfd_link_relocatable (info)) |
6996 | 0 | continue; |
6997 | | |
6998 | 0 | if (h != NULL) |
6999 | 0 | name = h->root.root.string; |
7000 | 0 | else |
7001 | 0 | { |
7002 | 0 | name = (bfd_elf_string_from_elf_section |
7003 | 0 | (input_bfd, symtab_hdr->sh_link, sym->st_name)); |
7004 | 0 | if (name == NULL || *name == '\0') |
7005 | 0 | name = bfd_section_name (sec); |
7006 | 0 | } |
7007 | |
|
7008 | 0 | if (r_symndx != 0 |
7009 | 0 | && r_type != R_AARCH64_NONE |
7010 | 0 | && r_type != R_AARCH64_NULL |
7011 | 0 | && (h == NULL |
7012 | 0 | || h->root.type == bfd_link_hash_defined |
7013 | 0 | || h->root.type == bfd_link_hash_defweak) |
7014 | 0 | && IS_AARCH64_TLS_RELOC (bfd_r_type) != (sym_type == STT_TLS)) |
7015 | 0 | { |
7016 | 0 | _bfd_error_handler |
7017 | 0 | ((sym_type == STT_TLS |
7018 | | /* xgettext:c-format */ |
7019 | 0 | ? _("%pB(%pA+%#" PRIx64 "): %s used with TLS symbol %s") |
7020 | | /* xgettext:c-format */ |
7021 | 0 | : _("%pB(%pA+%#" PRIx64 "): %s used with non-TLS symbol %s")), |
7022 | 0 | input_bfd, |
7023 | 0 | input_section, (uint64_t) rel->r_offset, howto->name, name); |
7024 | 0 | } |
7025 | | |
7026 | | /* We relax only if we can see that there can be a valid transition |
7027 | | from a reloc type to another. |
7028 | | We call elf64_aarch64_final_link_relocate unless we're completely |
7029 | | done, i.e., the relaxation produced the final output we want. */ |
7030 | |
|
7031 | 0 | relaxed_bfd_r_type = aarch64_tls_transition (input_bfd, info, r_type, |
7032 | 0 | h, r_symndx); |
7033 | 0 | if (relaxed_bfd_r_type != bfd_r_type) |
7034 | 0 | { |
7035 | 0 | bfd_r_type = relaxed_bfd_r_type; |
7036 | 0 | howto = elf64_aarch64_howto_from_bfd_reloc (bfd_r_type); |
7037 | 0 | BFD_ASSERT (howto != NULL); |
7038 | 0 | r_type = howto->type; |
7039 | 0 | r = elf64_aarch64_tls_relax (globals, input_bfd, input_section, |
7040 | 0 | contents, rel, h, info); |
7041 | 0 | unresolved_reloc = 0; |
7042 | 0 | } |
7043 | 0 | else |
7044 | 0 | r = bfd_reloc_continue; |
7045 | | |
7046 | | /* There may be multiple consecutive relocations for the |
7047 | | same offset. In that case we are supposed to treat the |
7048 | | output of each relocation as the addend for the next. */ |
7049 | 0 | if (rel + 1 < relend |
7050 | 0 | && rel->r_offset == rel[1].r_offset |
7051 | 0 | && ELF64_R_TYPE (rel[1].r_info) != R_AARCH64_NONE |
7052 | 0 | && ELF64_R_TYPE (rel[1].r_info) != R_AARCH64_NULL) |
7053 | 0 | save_addend = true; |
7054 | 0 | else |
7055 | 0 | save_addend = false; |
7056 | |
|
7057 | 0 | if (r == bfd_reloc_continue) |
7058 | 0 | r = elf64_aarch64_final_link_relocate (howto, input_bfd, output_bfd, |
7059 | 0 | input_section, contents, rel, |
7060 | 0 | relocation, info, sec, |
7061 | 0 | h, &unresolved_reloc, |
7062 | 0 | save_addend, &addend, sym); |
7063 | |
|
7064 | 0 | switch (elf64_aarch64_bfd_reloc_from_type (input_bfd, r_type)) |
7065 | 0 | { |
7066 | 0 | case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC: |
7067 | 0 | case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21: |
7068 | 0 | case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21: |
7069 | 0 | case BFD_RELOC_AARCH64_TLSGD_MOVW_G0_NC: |
7070 | 0 | case BFD_RELOC_AARCH64_TLSGD_MOVW_G1: |
7071 | 0 | case BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC: |
7072 | 0 | case BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21: |
7073 | 0 | case BFD_RELOC_AARCH64_TLSLD_ADR_PREL21: |
7074 | 0 | if (! symbol_got_offset_mark_p (input_bfd, h, r_symndx)) |
7075 | 0 | { |
7076 | 0 | bool need_relocs = false; |
7077 | 0 | bfd_byte *loc; |
7078 | 0 | int indx; |
7079 | 0 | bfd_vma off; |
7080 | |
|
7081 | 0 | off = symbol_got_offset (input_bfd, h, r_symndx); |
7082 | 0 | indx = h && h->dynindx != -1 ? h->dynindx : 0; |
7083 | |
|
7084 | 0 | need_relocs = |
7085 | 0 | (!bfd_link_executable (info) || indx != 0) && |
7086 | 0 | (h == NULL |
7087 | 0 | || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT |
7088 | 0 | || h->root.type != bfd_link_hash_undefweak); |
7089 | |
|
7090 | 0 | BFD_ASSERT (globals->root.srelgot != NULL); |
7091 | |
|
7092 | 0 | if (need_relocs) |
7093 | 0 | { |
7094 | 0 | Elf_Internal_Rela rela; |
7095 | 0 | rela.r_info = ELF64_R_INFO (indx, AARCH64_R (TLS_DTPMOD)); |
7096 | 0 | rela.r_addend = 0; |
7097 | 0 | rela.r_offset = globals->root.sgot->output_section->vma + |
7098 | 0 | globals->root.sgot->output_offset + off; |
7099 | | |
7100 | |
|
7101 | 0 | loc = globals->root.srelgot->contents; |
7102 | 0 | loc += globals->root.srelgot->reloc_count++ |
7103 | 0 | * RELOC_SIZE (htab); |
7104 | 0 | bfd_elf64_swap_reloca_out (output_bfd, &rela, loc); |
7105 | |
|
7106 | 0 | bfd_reloc_code_real_type real_type = |
7107 | 0 | elf64_aarch64_bfd_reloc_from_type (input_bfd, r_type); |
7108 | |
|
7109 | 0 | if (real_type == BFD_RELOC_AARCH64_TLSLD_ADR_PREL21 |
7110 | 0 | || real_type == BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21 |
7111 | 0 | || real_type == BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC) |
7112 | 0 | { |
7113 | | /* For local dynamic, don't generate DTPREL in any case. |
7114 | | Initialize the DTPREL slot into zero, so we get module |
7115 | | base address when invoke runtime TLS resolver. */ |
7116 | 0 | bfd_put_64 (output_bfd, 0, |
7117 | 0 | globals->root.sgot->contents + off |
7118 | 0 | + GOT_ENTRY_SIZE); |
7119 | 0 | } |
7120 | 0 | else if (indx == 0) |
7121 | 0 | { |
7122 | 0 | bfd_put_64 (output_bfd, |
7123 | 0 | relocation - dtpoff_base (info), |
7124 | 0 | globals->root.sgot->contents + off |
7125 | 0 | + GOT_ENTRY_SIZE); |
7126 | 0 | } |
7127 | 0 | else |
7128 | 0 | { |
7129 | | /* This TLS symbol is global. We emit a |
7130 | | relocation to fixup the tls offset at load |
7131 | | time. */ |
7132 | 0 | rela.r_info = |
7133 | 0 | ELF64_R_INFO (indx, AARCH64_R (TLS_DTPREL)); |
7134 | 0 | rela.r_addend = 0; |
7135 | 0 | rela.r_offset = |
7136 | 0 | (globals->root.sgot->output_section->vma |
7137 | 0 | + globals->root.sgot->output_offset + off |
7138 | 0 | + GOT_ENTRY_SIZE); |
7139 | |
|
7140 | 0 | loc = globals->root.srelgot->contents; |
7141 | 0 | loc += globals->root.srelgot->reloc_count++ |
7142 | 0 | * RELOC_SIZE (globals); |
7143 | 0 | bfd_elf64_swap_reloca_out (output_bfd, &rela, loc); |
7144 | 0 | bfd_put_64 (output_bfd, (bfd_vma) 0, |
7145 | 0 | globals->root.sgot->contents + off |
7146 | 0 | + GOT_ENTRY_SIZE); |
7147 | 0 | } |
7148 | 0 | } |
7149 | 0 | else |
7150 | 0 | { |
7151 | 0 | bfd_put_64 (output_bfd, (bfd_vma) 1, |
7152 | 0 | globals->root.sgot->contents + off); |
7153 | 0 | bfd_put_64 (output_bfd, |
7154 | 0 | relocation - dtpoff_base (info), |
7155 | 0 | globals->root.sgot->contents + off |
7156 | 0 | + GOT_ENTRY_SIZE); |
7157 | 0 | } |
7158 | |
|
7159 | 0 | symbol_got_offset_mark (input_bfd, h, r_symndx); |
7160 | 0 | } |
7161 | 0 | break; |
7162 | | |
7163 | 0 | case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21: |
7164 | 0 | case BFD_RELOC_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC: |
7165 | 0 | case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19: |
7166 | 0 | case BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G0_NC: |
7167 | 0 | case BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G1: |
7168 | 0 | if (! symbol_got_offset_mark_p (input_bfd, h, r_symndx)) |
7169 | 0 | { |
7170 | 0 | bool need_relocs = false; |
7171 | 0 | bfd_byte *loc; |
7172 | 0 | int indx; |
7173 | 0 | bfd_vma off; |
7174 | |
|
7175 | 0 | off = symbol_got_offset (input_bfd, h, r_symndx); |
7176 | |
|
7177 | 0 | indx = h && h->dynindx != -1 ? h->dynindx : 0; |
7178 | |
|
7179 | 0 | need_relocs = |
7180 | 0 | (!bfd_link_executable (info) || indx != 0) && |
7181 | 0 | (h == NULL |
7182 | 0 | || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT |
7183 | 0 | || h->root.type != bfd_link_hash_undefweak); |
7184 | |
|
7185 | 0 | BFD_ASSERT (globals->root.srelgot != NULL); |
7186 | |
|
7187 | 0 | if (need_relocs) |
7188 | 0 | { |
7189 | 0 | Elf_Internal_Rela rela; |
7190 | |
|
7191 | 0 | if (indx == 0) |
7192 | 0 | rela.r_addend = relocation - dtpoff_base (info); |
7193 | 0 | else |
7194 | 0 | rela.r_addend = 0; |
7195 | |
|
7196 | 0 | rela.r_info = ELF64_R_INFO (indx, AARCH64_R (TLS_TPREL)); |
7197 | 0 | rela.r_offset = globals->root.sgot->output_section->vma + |
7198 | 0 | globals->root.sgot->output_offset + off; |
7199 | |
|
7200 | 0 | loc = globals->root.srelgot->contents; |
7201 | 0 | loc += globals->root.srelgot->reloc_count++ |
7202 | 0 | * RELOC_SIZE (htab); |
7203 | |
|
7204 | 0 | bfd_elf64_swap_reloca_out (output_bfd, &rela, loc); |
7205 | |
|
7206 | 0 | bfd_put_64 (output_bfd, rela.r_addend, |
7207 | 0 | globals->root.sgot->contents + off); |
7208 | 0 | } |
7209 | 0 | else |
7210 | 0 | bfd_put_64 (output_bfd, relocation - tpoff_base (info), |
7211 | 0 | globals->root.sgot->contents + off); |
7212 | |
|
7213 | 0 | symbol_got_offset_mark (input_bfd, h, r_symndx); |
7214 | 0 | } |
7215 | 0 | break; |
7216 | | |
7217 | 0 | case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12: |
7218 | 0 | case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21: |
7219 | 0 | case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21: |
7220 | 0 | case BFD_RELOC_AARCH64_TLSDESC_LD64_LO12_NC: |
7221 | 0 | case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19: |
7222 | 0 | case BFD_RELOC_AARCH64_TLSDESC_OFF_G0_NC: |
7223 | 0 | case BFD_RELOC_AARCH64_TLSDESC_OFF_G1: |
7224 | 0 | if (! symbol_tlsdesc_got_offset_mark_p (input_bfd, h, r_symndx)) |
7225 | 0 | { |
7226 | 0 | bool need_relocs = false; |
7227 | 0 | int indx = h && h->dynindx != -1 ? h->dynindx : 0; |
7228 | 0 | bfd_vma off = symbol_tlsdesc_got_offset (input_bfd, h, r_symndx); |
7229 | |
|
7230 | 0 | need_relocs = (h == NULL |
7231 | 0 | || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT |
7232 | 0 | || h->root.type != bfd_link_hash_undefweak); |
7233 | |
|
7234 | 0 | BFD_ASSERT (globals->root.srelgot != NULL); |
7235 | 0 | BFD_ASSERT (globals->root.sgot != NULL); |
7236 | |
|
7237 | 0 | if (need_relocs) |
7238 | 0 | { |
7239 | 0 | bfd_byte *loc; |
7240 | 0 | Elf_Internal_Rela rela; |
7241 | 0 | rela.r_info = ELF64_R_INFO (indx, AARCH64_R (TLSDESC)); |
7242 | |
|
7243 | 0 | rela.r_addend = 0; |
7244 | 0 | rela.r_offset = (globals->root.sgotplt->output_section->vma |
7245 | 0 | + globals->root.sgotplt->output_offset |
7246 | 0 | + off + globals->sgotplt_jump_table_size); |
7247 | |
|
7248 | 0 | if (indx == 0) |
7249 | 0 | rela.r_addend = relocation - dtpoff_base (info); |
7250 | | |
7251 | | /* Allocate the next available slot in the PLT reloc |
7252 | | section to hold our R_AARCH64_TLSDESC, the next |
7253 | | available slot is determined from reloc_count, |
7254 | | which we step. But note, reloc_count was |
7255 | | artifically moved down while allocating slots for |
7256 | | real PLT relocs such that all of the PLT relocs |
7257 | | will fit above the initial reloc_count and the |
7258 | | extra stuff will fit below. */ |
7259 | 0 | loc = globals->root.srelplt->contents; |
7260 | 0 | loc += globals->root.srelplt->reloc_count++ |
7261 | 0 | * RELOC_SIZE (globals); |
7262 | |
|
7263 | 0 | bfd_elf64_swap_reloca_out (output_bfd, &rela, loc); |
7264 | |
|
7265 | 0 | bfd_put_64 (output_bfd, (bfd_vma) 0, |
7266 | 0 | globals->root.sgotplt->contents + off + |
7267 | 0 | globals->sgotplt_jump_table_size); |
7268 | 0 | bfd_put_64 (output_bfd, (bfd_vma) 0, |
7269 | 0 | globals->root.sgotplt->contents + off + |
7270 | 0 | globals->sgotplt_jump_table_size + |
7271 | 0 | GOT_ENTRY_SIZE); |
7272 | 0 | } |
7273 | |
|
7274 | 0 | symbol_tlsdesc_got_offset_mark (input_bfd, h, r_symndx); |
7275 | 0 | } |
7276 | 0 | break; |
7277 | 0 | default: |
7278 | 0 | break; |
7279 | 0 | } |
7280 | | |
7281 | | /* Dynamic relocs are not propagated for SEC_DEBUGGING sections |
7282 | | because such sections are not SEC_ALLOC and thus ld.so will |
7283 | | not process them. */ |
7284 | 0 | if (unresolved_reloc |
7285 | 0 | && !((input_section->flags & SEC_DEBUGGING) != 0 |
7286 | 0 | && h->def_dynamic) |
7287 | 0 | && _bfd_elf_section_offset (output_bfd, info, input_section, |
7288 | 0 | +rel->r_offset) != (bfd_vma) - 1) |
7289 | 0 | { |
7290 | 0 | _bfd_error_handler |
7291 | | /* xgettext:c-format */ |
7292 | 0 | (_("%pB(%pA+%#" PRIx64 "): " |
7293 | 0 | "unresolvable %s relocation against symbol `%s'"), |
7294 | 0 | input_bfd, input_section, (uint64_t) rel->r_offset, howto->name, |
7295 | 0 | h->root.root.string); |
7296 | 0 | return false; |
7297 | 0 | } |
7298 | | |
7299 | 0 | if (r != bfd_reloc_ok && r != bfd_reloc_continue) |
7300 | 0 | { |
7301 | 0 | bfd_reloc_code_real_type real_r_type |
7302 | 0 | = elf64_aarch64_bfd_reloc_from_type (input_bfd, r_type); |
7303 | |
|
7304 | 0 | switch (r) |
7305 | 0 | { |
7306 | 0 | case bfd_reloc_overflow: |
7307 | 0 | (*info->callbacks->reloc_overflow) |
7308 | 0 | (info, (h ? &h->root : NULL), name, howto->name, (bfd_vma) 0, |
7309 | 0 | input_bfd, input_section, rel->r_offset); |
7310 | 0 | if (real_r_type == BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15 |
7311 | 0 | || real_r_type == BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14) |
7312 | 0 | { |
7313 | 0 | (*info->callbacks->warning) |
7314 | 0 | (info, |
7315 | 0 | _("too many GOT entries for -fpic, " |
7316 | 0 | "please recompile with -fPIC"), |
7317 | 0 | name, input_bfd, input_section, rel->r_offset); |
7318 | 0 | return false; |
7319 | 0 | } |
7320 | | /* Overflow can occur when a variable is referenced with a type |
7321 | | that has a larger alignment than the type with which it was |
7322 | | declared. eg: |
7323 | | file1.c: extern int foo; int a (void) { return foo; } |
7324 | | file2.c: char bar, foo, baz; |
7325 | | If the variable is placed into a data section at an offset |
7326 | | that is incompatible with the larger alignment requirement |
7327 | | overflow will occur. (Strictly speaking this is not overflow |
7328 | | but rather an alignment problem, but the bfd_reloc_ error |
7329 | | enum does not have a value to cover that situation). |
7330 | | |
7331 | | Try to catch this situation here and provide a more helpful |
7332 | | error message to the user. */ |
7333 | 0 | if (addend & (((bfd_vma) 1 << howto->rightshift) - 1) |
7334 | | /* FIXME: Are we testing all of the appropriate reloc |
7335 | | types here ? */ |
7336 | 0 | && (real_r_type == BFD_RELOC_AARCH64_LD_LO19_PCREL |
7337 | 0 | || real_r_type == BFD_RELOC_AARCH64_LDST16_LO12 |
7338 | 0 | || real_r_type == BFD_RELOC_AARCH64_LDST32_LO12 |
7339 | 0 | || real_r_type == BFD_RELOC_AARCH64_LDST64_LO12 |
7340 | 0 | || real_r_type == BFD_RELOC_AARCH64_LDST128_LO12)) |
7341 | 0 | { |
7342 | 0 | info->callbacks->warning |
7343 | 0 | (info, _("one possible cause of this error is that the \ |
7344 | 0 | symbol is being referenced in the indicated code as if it had a larger \ |
7345 | 0 | alignment than was declared where it was defined"), |
7346 | 0 | name, input_bfd, input_section, rel->r_offset); |
7347 | 0 | } |
7348 | 0 | break; |
7349 | | |
7350 | 0 | case bfd_reloc_undefined: |
7351 | 0 | (*info->callbacks->undefined_symbol) |
7352 | 0 | (info, name, input_bfd, input_section, rel->r_offset, true); |
7353 | 0 | break; |
7354 | | |
7355 | 0 | case bfd_reloc_outofrange: |
7356 | 0 | error_message = _("out of range"); |
7357 | 0 | goto common_error; |
7358 | | |
7359 | 0 | case bfd_reloc_notsupported: |
7360 | 0 | error_message = _("unsupported relocation"); |
7361 | 0 | goto common_error; |
7362 | | |
7363 | 0 | case bfd_reloc_dangerous: |
7364 | | /* error_message should already be set. */ |
7365 | 0 | goto common_error; |
7366 | | |
7367 | 0 | default: |
7368 | 0 | error_message = _("unknown error"); |
7369 | | /* Fall through. */ |
7370 | |
|
7371 | 0 | common_error: |
7372 | 0 | BFD_ASSERT (error_message != NULL); |
7373 | 0 | (*info->callbacks->reloc_dangerous) |
7374 | 0 | (info, error_message, input_bfd, input_section, rel->r_offset); |
7375 | 0 | break; |
7376 | 0 | } |
7377 | 0 | } |
7378 | | |
7379 | 0 | if (!save_addend) |
7380 | 0 | addend = 0; |
7381 | 0 | } |
7382 | | |
7383 | 0 | return true; |
7384 | 0 | } |
7385 | | |
7386 | | /* Set the right machine number. */ |
7387 | | |
7388 | | static bool |
7389 | | elf64_aarch64_object_p (bfd *abfd) |
7390 | 734 | { |
7391 | | #if ARCH_SIZE == 32 |
7392 | | bfd_default_set_arch_mach (abfd, bfd_arch_aarch64, bfd_mach_aarch64_ilp32); |
7393 | | #else |
7394 | 734 | bfd_default_set_arch_mach (abfd, bfd_arch_aarch64, bfd_mach_aarch64); |
7395 | 734 | #endif |
7396 | 734 | return true; |
7397 | 734 | } |
7398 | | |
7399 | | /* Function to keep AArch64 specific flags in the ELF header. */ |
7400 | | |
7401 | | static bool |
7402 | | elf64_aarch64_set_private_flags (bfd *abfd, flagword flags) |
7403 | 0 | { |
7404 | 0 | if (elf_flags_init (abfd) && elf_elfheader (abfd)->e_flags != flags) |
7405 | 0 | { |
7406 | 0 | } |
7407 | 0 | else |
7408 | 0 | { |
7409 | 0 | elf_elfheader (abfd)->e_flags = flags; |
7410 | 0 | elf_flags_init (abfd) = true; |
7411 | 0 | } |
7412 | |
|
7413 | 0 | return true; |
7414 | 0 | } |
7415 | | |
7416 | | /* Merge backend specific data from an object file to the output |
7417 | | object file when linking. */ |
7418 | | |
7419 | | static bool |
7420 | | elf64_aarch64_merge_private_bfd_data (bfd *ibfd, struct bfd_link_info *info) |
7421 | 0 | { |
7422 | 0 | bfd *obfd = info->output_bfd; |
7423 | 0 | flagword out_flags; |
7424 | 0 | flagword in_flags; |
7425 | 0 | bool flags_compatible = true; |
7426 | 0 | asection *sec; |
7427 | | |
7428 | | /* Check if we have the same endianess. */ |
7429 | 0 | if (!_bfd_generic_verify_endian_match (ibfd, info)) |
7430 | 0 | return false; |
7431 | | |
7432 | 0 | if (!is_aarch64_elf (ibfd) || !is_aarch64_elf (obfd)) |
7433 | 0 | return true; |
7434 | | |
7435 | | /* The input BFD must have had its flags initialised. */ |
7436 | | /* The following seems bogus to me -- The flags are initialized in |
7437 | | the assembler but I don't think an elf_flags_init field is |
7438 | | written into the object. */ |
7439 | | /* BFD_ASSERT (elf_flags_init (ibfd)); */ |
7440 | | |
7441 | 0 | in_flags = elf_elfheader (ibfd)->e_flags; |
7442 | 0 | out_flags = elf_elfheader (obfd)->e_flags; |
7443 | |
|
7444 | 0 | if (!elf_flags_init (obfd)) |
7445 | 0 | { |
7446 | | /* If the input is the default architecture and had the default |
7447 | | flags then do not bother setting the flags for the output |
7448 | | architecture, instead allow future merges to do this. If no |
7449 | | future merges ever set these flags then they will retain their |
7450 | | uninitialised values, which surprise surprise, correspond |
7451 | | to the default values. */ |
7452 | 0 | if (bfd_get_arch_info (ibfd)->the_default |
7453 | 0 | && elf_elfheader (ibfd)->e_flags == 0) |
7454 | 0 | return true; |
7455 | | |
7456 | 0 | elf_flags_init (obfd) = true; |
7457 | 0 | elf_elfheader (obfd)->e_flags = in_flags; |
7458 | |
|
7459 | 0 | if (bfd_get_arch (obfd) == bfd_get_arch (ibfd) |
7460 | 0 | && bfd_get_arch_info (obfd)->the_default) |
7461 | 0 | return bfd_set_arch_mach (obfd, bfd_get_arch (ibfd), |
7462 | 0 | bfd_get_mach (ibfd)); |
7463 | | |
7464 | 0 | return true; |
7465 | 0 | } |
7466 | | |
7467 | | /* Identical flags must be compatible. */ |
7468 | 0 | if (in_flags == out_flags) |
7469 | 0 | return true; |
7470 | | |
7471 | | /* Check to see if the input BFD actually contains any sections. If |
7472 | | not, its flags may not have been initialised either, but it |
7473 | | cannot actually cause any incompatiblity. Do not short-circuit |
7474 | | dynamic objects; their section list may be emptied by |
7475 | | elf_link_add_object_symbols. |
7476 | | |
7477 | | Also check to see if there are no code sections in the input. |
7478 | | In this case there is no need to check for code specific flags. |
7479 | | XXX - do we need to worry about floating-point format compatability |
7480 | | in data sections ? */ |
7481 | 0 | if (!(ibfd->flags & DYNAMIC)) |
7482 | 0 | { |
7483 | 0 | bool null_input_bfd = true; |
7484 | 0 | bool only_data_sections = true; |
7485 | |
|
7486 | 0 | for (sec = ibfd->sections; sec != NULL; sec = sec->next) |
7487 | 0 | { |
7488 | 0 | if ((bfd_section_flags (sec) |
7489 | 0 | & (SEC_LOAD | SEC_CODE | SEC_HAS_CONTENTS)) |
7490 | 0 | == (SEC_LOAD | SEC_CODE | SEC_HAS_CONTENTS)) |
7491 | 0 | only_data_sections = false; |
7492 | |
|
7493 | 0 | null_input_bfd = false; |
7494 | 0 | break; |
7495 | 0 | } |
7496 | |
|
7497 | 0 | if (null_input_bfd || only_data_sections) |
7498 | 0 | return true; |
7499 | 0 | } |
7500 | | |
7501 | 0 | return flags_compatible; |
7502 | 0 | } |
7503 | | |
7504 | | /* Display the flags field. */ |
7505 | | |
7506 | | static bool |
7507 | | elf64_aarch64_print_private_bfd_data (bfd *abfd, void *ptr) |
7508 | 0 | { |
7509 | 0 | FILE *file = (FILE *) ptr; |
7510 | 0 | unsigned long flags; |
7511 | |
|
7512 | 0 | BFD_ASSERT (abfd != NULL && ptr != NULL); |
7513 | | |
7514 | | /* Print normal ELF private data. */ |
7515 | 0 | _bfd_elf_print_private_bfd_data (abfd, ptr); |
7516 | |
|
7517 | 0 | flags = elf_elfheader (abfd)->e_flags; |
7518 | | /* Ignore init flag - it may not be set, despite the flags field |
7519 | | containing valid data. */ |
7520 | | |
7521 | | /* xgettext:c-format */ |
7522 | 0 | fprintf (file, _("private flags = 0x%lx:"), elf_elfheader (abfd)->e_flags); |
7523 | |
|
7524 | 0 | if (flags) |
7525 | 0 | fprintf (file, _(" <Unrecognised flag bits set>")); |
7526 | |
|
7527 | 0 | fputc ('\n', file); |
7528 | |
|
7529 | 0 | return true; |
7530 | 0 | } |
7531 | | |
7532 | | /* Return true if we need copy relocation against EH. */ |
7533 | | |
7534 | | static bool |
7535 | | need_copy_relocation_p (struct elf_aarch64_link_hash_entry *eh) |
7536 | 0 | { |
7537 | 0 | struct elf_dyn_relocs *p; |
7538 | 0 | asection *s; |
7539 | |
|
7540 | 0 | for (p = eh->root.dyn_relocs; p != NULL; p = p->next) |
7541 | 0 | { |
7542 | | /* If there is any pc-relative reference, we need to keep copy relocation |
7543 | | to avoid propagating the relocation into runtime that current glibc |
7544 | | does not support. */ |
7545 | 0 | if (p->pc_count) |
7546 | 0 | return true; |
7547 | | |
7548 | 0 | s = p->sec->output_section; |
7549 | | /* Need copy relocation if it's against read-only section. */ |
7550 | 0 | if (s != NULL && (s->flags & SEC_READONLY) != 0) |
7551 | 0 | return true; |
7552 | 0 | } |
7553 | | |
7554 | 0 | return false; |
7555 | 0 | } |
7556 | | |
7557 | | /* Adjust a symbol defined by a dynamic object and referenced by a |
7558 | | regular object. The current definition is in some section of the |
7559 | | dynamic object, but we're not including those sections. We have to |
7560 | | change the definition to something the rest of the link can |
7561 | | understand. */ |
7562 | | |
7563 | | static bool |
7564 | | elf64_aarch64_adjust_dynamic_symbol (struct bfd_link_info *info, |
7565 | | struct elf_link_hash_entry *h) |
7566 | 0 | { |
7567 | 0 | struct elf_aarch64_link_hash_table *htab; |
7568 | 0 | asection *s, *srel; |
7569 | | |
7570 | | /* If this is a function, put it in the procedure linkage table. We |
7571 | | will fill in the contents of the procedure linkage table later, |
7572 | | when we know the address of the .got section. */ |
7573 | 0 | if (h->type == STT_FUNC || h->type == STT_GNU_IFUNC || h->needs_plt) |
7574 | 0 | { |
7575 | 0 | if (h->plt.refcount <= 0 |
7576 | 0 | || (h->type != STT_GNU_IFUNC |
7577 | 0 | && (SYMBOL_CALLS_LOCAL (info, h) |
7578 | 0 | || (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT |
7579 | 0 | && h->root.type == bfd_link_hash_undefweak)))) |
7580 | 0 | { |
7581 | | /* This case can occur if we saw a CALL26 reloc in |
7582 | | an input file, but the symbol wasn't referred to |
7583 | | by a dynamic object or all references were |
7584 | | garbage collected. In which case we can end up |
7585 | | resolving. */ |
7586 | 0 | h->plt.offset = (bfd_vma) - 1; |
7587 | 0 | h->needs_plt = 0; |
7588 | 0 | } |
7589 | |
|
7590 | 0 | return true; |
7591 | 0 | } |
7592 | 0 | else |
7593 | | /* Otherwise, reset to -1. */ |
7594 | 0 | h->plt.offset = (bfd_vma) - 1; |
7595 | | |
7596 | | |
7597 | | /* If this is a weak symbol, and there is a real definition, the |
7598 | | processor independent code will have arranged for us to see the |
7599 | | real definition first, and we can just use the same value. */ |
7600 | 0 | if (h->is_weakalias) |
7601 | 0 | { |
7602 | 0 | struct elf_link_hash_entry *def = weakdef (h); |
7603 | 0 | BFD_ASSERT (def->root.type == bfd_link_hash_defined); |
7604 | 0 | h->root.u.def.section = def->root.u.def.section; |
7605 | 0 | h->root.u.def.value = def->root.u.def.value; |
7606 | 0 | if (ELIMINATE_COPY_RELOCS || info->nocopyreloc) |
7607 | 0 | h->non_got_ref = def->non_got_ref; |
7608 | 0 | return true; |
7609 | 0 | } |
7610 | | |
7611 | | /* If we are creating a shared library, we must presume that the |
7612 | | only references to the symbol are via the global offset table. |
7613 | | For such cases we need not do anything here; the relocations will |
7614 | | be handled correctly by relocate_section. */ |
7615 | 0 | if (bfd_link_pic (info)) |
7616 | 0 | return true; |
7617 | | |
7618 | | /* If there are no references to this symbol that do not use the |
7619 | | GOT, we don't need to generate a copy reloc. */ |
7620 | 0 | if (!h->non_got_ref) |
7621 | 0 | return true; |
7622 | | |
7623 | | /* If -z nocopyreloc was given, we won't generate them either. */ |
7624 | 0 | if (info->nocopyreloc) |
7625 | 0 | { |
7626 | 0 | h->non_got_ref = 0; |
7627 | 0 | return true; |
7628 | 0 | } |
7629 | | |
7630 | 0 | if (ELIMINATE_COPY_RELOCS) |
7631 | 0 | { |
7632 | 0 | struct elf_aarch64_link_hash_entry *eh; |
7633 | | /* If we don't find any dynamic relocs in read-only sections, then |
7634 | | we'll be keeping the dynamic relocs and avoiding the copy reloc. */ |
7635 | 0 | eh = (struct elf_aarch64_link_hash_entry *) h; |
7636 | 0 | if (!need_copy_relocation_p (eh)) |
7637 | 0 | { |
7638 | 0 | h->non_got_ref = 0; |
7639 | 0 | return true; |
7640 | 0 | } |
7641 | 0 | } |
7642 | | |
7643 | | /* We must allocate the symbol in our .dynbss section, which will |
7644 | | become part of the .bss section of the executable. There will be |
7645 | | an entry for this symbol in the .dynsym section. The dynamic |
7646 | | object will contain position independent code, so all references |
7647 | | from the dynamic object to this symbol will go through the global |
7648 | | offset table. The dynamic linker will use the .dynsym entry to |
7649 | | determine the address it must put in the global offset table, so |
7650 | | both the dynamic object and the regular object will refer to the |
7651 | | same memory location for the variable. */ |
7652 | | |
7653 | 0 | htab = elf_aarch64_hash_table (info); |
7654 | | |
7655 | | /* We must generate a R_AARCH64_COPY reloc to tell the dynamic linker |
7656 | | to copy the initial value out of the dynamic object and into the |
7657 | | runtime process image. */ |
7658 | 0 | if ((h->root.u.def.section->flags & SEC_READONLY) != 0) |
7659 | 0 | { |
7660 | 0 | s = htab->root.sdynrelro; |
7661 | 0 | srel = htab->root.sreldynrelro; |
7662 | 0 | } |
7663 | 0 | else |
7664 | 0 | { |
7665 | 0 | s = htab->root.sdynbss; |
7666 | 0 | srel = htab->root.srelbss; |
7667 | 0 | } |
7668 | 0 | if ((h->root.u.def.section->flags & SEC_ALLOC) != 0 && h->size != 0) |
7669 | 0 | { |
7670 | 0 | srel->size += RELOC_SIZE (htab); |
7671 | 0 | h->needs_copy = 1; |
7672 | 0 | } |
7673 | |
|
7674 | 0 | return _bfd_elf_adjust_dynamic_copy (info, h, s); |
7675 | |
|
7676 | 0 | } |
7677 | | |
7678 | | static bool |
7679 | | elf64_aarch64_allocate_local_symbols (bfd *abfd, unsigned number) |
7680 | 0 | { |
7681 | 0 | struct elf_aarch64_local_symbol *locals; |
7682 | 0 | locals = elf_aarch64_locals (abfd); |
7683 | 0 | if (locals == NULL) |
7684 | 0 | { |
7685 | 0 | locals = (struct elf_aarch64_local_symbol *) |
7686 | 0 | bfd_zalloc (abfd, number * sizeof (struct elf_aarch64_local_symbol)); |
7687 | 0 | if (locals == NULL) |
7688 | 0 | return false; |
7689 | 0 | elf_aarch64_locals (abfd) = locals; |
7690 | 0 | } |
7691 | 0 | return true; |
7692 | 0 | } |
7693 | | |
7694 | | /* Create the .got section to hold the global offset table. */ |
7695 | | |
7696 | | static bool |
7697 | | aarch64_elf_create_got_section (bfd *abfd, struct bfd_link_info *info) |
7698 | 0 | { |
7699 | 0 | const struct elf_backend_data *bed = get_elf_backend_data (abfd); |
7700 | 0 | flagword flags; |
7701 | 0 | asection *s; |
7702 | 0 | struct elf_link_hash_entry *h; |
7703 | 0 | struct elf_link_hash_table *htab = elf_hash_table (info); |
7704 | | |
7705 | | /* This function may be called more than once. */ |
7706 | 0 | if (htab->sgot != NULL) |
7707 | 0 | return true; |
7708 | | |
7709 | 0 | flags = bed->dynamic_sec_flags; |
7710 | |
|
7711 | 0 | s = bfd_make_section_anyway_with_flags (abfd, |
7712 | 0 | (bed->rela_plts_and_copies_p |
7713 | 0 | ? ".rela.got" : ".rel.got"), |
7714 | 0 | (bed->dynamic_sec_flags |
7715 | 0 | | SEC_READONLY)); |
7716 | 0 | if (s == NULL |
7717 | 0 | || !bfd_set_section_alignment (s, bed->s->log_file_align)) |
7718 | 0 | return false; |
7719 | 0 | htab->srelgot = s; |
7720 | |
|
7721 | 0 | s = bfd_make_section_anyway_with_flags (abfd, ".got", flags); |
7722 | 0 | if (s == NULL |
7723 | 0 | || !bfd_set_section_alignment (s, bed->s->log_file_align)) |
7724 | 0 | return false; |
7725 | 0 | htab->sgot = s; |
7726 | 0 | htab->sgot->size += GOT_ENTRY_SIZE; |
7727 | |
|
7728 | 0 | if (bed->want_got_sym) |
7729 | 0 | { |
7730 | | /* Define the symbol _GLOBAL_OFFSET_TABLE_ at the start of the .got |
7731 | | (or .got.plt) section. We don't do this in the linker script |
7732 | | because we don't want to define the symbol if we are not creating |
7733 | | a global offset table. */ |
7734 | 0 | h = _bfd_elf_define_linkage_sym (abfd, info, s, |
7735 | 0 | "_GLOBAL_OFFSET_TABLE_"); |
7736 | 0 | elf_hash_table (info)->hgot = h; |
7737 | 0 | if (h == NULL) |
7738 | 0 | return false; |
7739 | 0 | } |
7740 | | |
7741 | 0 | if (bed->want_got_plt) |
7742 | 0 | { |
7743 | 0 | s = bfd_make_section_anyway_with_flags (abfd, ".got.plt", flags); |
7744 | 0 | if (s == NULL |
7745 | 0 | || !bfd_set_section_alignment (s, bed->s->log_file_align)) |
7746 | 0 | return false; |
7747 | 0 | htab->sgotplt = s; |
7748 | 0 | } |
7749 | | |
7750 | | /* The first bit of the global offset table is the header. */ |
7751 | 0 | s->size += bed->got_header_size; |
7752 | |
|
7753 | 0 | return true; |
7754 | 0 | } |
7755 | | |
7756 | | /* Look through the relocs for a section during the first phase. */ |
7757 | | |
7758 | | static bool |
7759 | | elf64_aarch64_check_relocs (bfd *abfd, struct bfd_link_info *info, |
7760 | | asection *sec, const Elf_Internal_Rela *relocs) |
7761 | 0 | { |
7762 | 0 | Elf_Internal_Shdr *symtab_hdr; |
7763 | 0 | struct elf_link_hash_entry **sym_hashes; |
7764 | 0 | const Elf_Internal_Rela *rel; |
7765 | 0 | const Elf_Internal_Rela *rel_end; |
7766 | 0 | asection *sreloc; |
7767 | |
|
7768 | 0 | struct elf_aarch64_link_hash_table *htab; |
7769 | |
|
7770 | 0 | if (bfd_link_relocatable (info)) |
7771 | 0 | return true; |
7772 | | |
7773 | 0 | BFD_ASSERT (is_aarch64_elf (abfd)); |
7774 | |
|
7775 | 0 | htab = elf_aarch64_hash_table (info); |
7776 | 0 | sreloc = NULL; |
7777 | |
|
7778 | 0 | symtab_hdr = &elf_symtab_hdr (abfd); |
7779 | 0 | sym_hashes = elf_sym_hashes (abfd); |
7780 | |
|
7781 | 0 | rel_end = relocs + sec->reloc_count; |
7782 | 0 | for (rel = relocs; rel < rel_end; rel++) |
7783 | 0 | { |
7784 | 0 | struct elf_link_hash_entry *h; |
7785 | 0 | unsigned int r_symndx; |
7786 | 0 | unsigned int r_type; |
7787 | 0 | bfd_reloc_code_real_type bfd_r_type; |
7788 | 0 | Elf_Internal_Sym *isym; |
7789 | |
|
7790 | 0 | r_symndx = ELF64_R_SYM (rel->r_info); |
7791 | 0 | r_type = ELF64_R_TYPE (rel->r_info); |
7792 | |
|
7793 | 0 | if (r_symndx >= NUM_SHDR_ENTRIES (symtab_hdr)) |
7794 | 0 | { |
7795 | | /* xgettext:c-format */ |
7796 | 0 | _bfd_error_handler (_("%pB: bad symbol index: %d"), abfd, r_symndx); |
7797 | 0 | return false; |
7798 | 0 | } |
7799 | | |
7800 | 0 | if (r_symndx < symtab_hdr->sh_info) |
7801 | 0 | { |
7802 | | /* A local symbol. */ |
7803 | 0 | isym = bfd_sym_from_r_symndx (&htab->root.sym_cache, |
7804 | 0 | abfd, r_symndx); |
7805 | 0 | if (isym == NULL) |
7806 | 0 | return false; |
7807 | | |
7808 | | /* Check relocation against local STT_GNU_IFUNC symbol. */ |
7809 | 0 | if (ELF_ST_TYPE (isym->st_info) == STT_GNU_IFUNC) |
7810 | 0 | { |
7811 | 0 | h = elf64_aarch64_get_local_sym_hash (htab, abfd, rel, |
7812 | 0 | true); |
7813 | 0 | if (h == NULL) |
7814 | 0 | return false; |
7815 | | |
7816 | | /* Fake a STT_GNU_IFUNC symbol. */ |
7817 | 0 | h->type = STT_GNU_IFUNC; |
7818 | 0 | h->def_regular = 1; |
7819 | 0 | h->ref_regular = 1; |
7820 | 0 | h->forced_local = 1; |
7821 | 0 | h->root.type = bfd_link_hash_defined; |
7822 | 0 | } |
7823 | 0 | else |
7824 | 0 | h = NULL; |
7825 | 0 | } |
7826 | 0 | else |
7827 | 0 | { |
7828 | 0 | h = sym_hashes[r_symndx - symtab_hdr->sh_info]; |
7829 | 0 | while (h->root.type == bfd_link_hash_indirect |
7830 | 0 | || h->root.type == bfd_link_hash_warning) |
7831 | 0 | h = (struct elf_link_hash_entry *) h->root.u.i.link; |
7832 | 0 | } |
7833 | | |
7834 | | /* Could be done earlier, if h were already available. */ |
7835 | 0 | bfd_r_type = aarch64_tls_transition (abfd, info, r_type, h, r_symndx); |
7836 | |
|
7837 | 0 | if (h != NULL) |
7838 | 0 | { |
7839 | | /* If a relocation refers to _GLOBAL_OFFSET_TABLE_, create the .got. |
7840 | | This shows up in particular in an R_AARCH64_PREL64 in large model |
7841 | | when calculating the pc-relative address to .got section which is |
7842 | | used to initialize the gp register. */ |
7843 | 0 | if (h->root.root.string |
7844 | 0 | && strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0) |
7845 | 0 | { |
7846 | 0 | if (htab->root.dynobj == NULL) |
7847 | 0 | htab->root.dynobj = abfd; |
7848 | |
|
7849 | 0 | if (! aarch64_elf_create_got_section (htab->root.dynobj, info)) |
7850 | 0 | return false; |
7851 | | |
7852 | 0 | BFD_ASSERT (h == htab->root.hgot); |
7853 | 0 | } |
7854 | | |
7855 | | /* Create the ifunc sections for static executables. If we |
7856 | | never see an indirect function symbol nor we are building |
7857 | | a static executable, those sections will be empty and |
7858 | | won't appear in output. */ |
7859 | 0 | switch (bfd_r_type) |
7860 | 0 | { |
7861 | 0 | default: |
7862 | 0 | break; |
7863 | | |
7864 | 0 | case BFD_RELOC_AARCH64_ADD_LO12: |
7865 | 0 | case BFD_RELOC_AARCH64_ADR_GOT_PAGE: |
7866 | 0 | case BFD_RELOC_AARCH64_ADR_HI21_PCREL: |
7867 | 0 | case BFD_RELOC_AARCH64_CALL26: |
7868 | 0 | case BFD_RELOC_AARCH64_GOT_LD_PREL19: |
7869 | 0 | case BFD_RELOC_AARCH64_JUMP26: |
7870 | 0 | case BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14: |
7871 | 0 | case BFD_RELOC_AARCH64_LD32_GOT_LO12_NC: |
7872 | 0 | case BFD_RELOC_AARCH64_LD64_GOTOFF_LO15: |
7873 | 0 | case BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15: |
7874 | 0 | case BFD_RELOC_AARCH64_LD64_GOT_LO12_NC: |
7875 | 0 | case BFD_RELOC_AARCH64_MOVW_GOTOFF_G0_NC: |
7876 | 0 | case BFD_RELOC_AARCH64_MOVW_GOTOFF_G1: |
7877 | 0 | case BFD_RELOC_AARCH64_64: |
7878 | 0 | if (htab->root.dynobj == NULL) |
7879 | 0 | htab->root.dynobj = abfd; |
7880 | 0 | if (!_bfd_elf_create_ifunc_sections (htab->root.dynobj, info)) |
7881 | 0 | return false; |
7882 | 0 | break; |
7883 | 0 | } |
7884 | | |
7885 | | /* It is referenced by a non-shared object. */ |
7886 | 0 | h->ref_regular = 1; |
7887 | 0 | } |
7888 | | |
7889 | 0 | switch (bfd_r_type) |
7890 | 0 | { |
7891 | 0 | case BFD_RELOC_AARCH64_16: |
7892 | 0 | #if ARCH_SIZE == 64 |
7893 | 0 | case BFD_RELOC_AARCH64_32: |
7894 | 0 | #endif |
7895 | 0 | if (bfd_link_pic (info) && (sec->flags & SEC_ALLOC) != 0) |
7896 | 0 | { |
7897 | 0 | if (h != NULL |
7898 | | /* This is an absolute symbol. It represents a value instead |
7899 | | of an address. */ |
7900 | 0 | && (bfd_is_abs_symbol (&h->root) |
7901 | | /* This is an undefined symbol. */ |
7902 | 0 | || h->root.type == bfd_link_hash_undefined)) |
7903 | 0 | break; |
7904 | | |
7905 | | /* For local symbols, defined global symbols in a non-ABS section, |
7906 | | it is assumed that the value is an address. */ |
7907 | 0 | int howto_index = bfd_r_type - BFD_RELOC_AARCH64_RELOC_START; |
7908 | 0 | _bfd_error_handler |
7909 | | /* xgettext:c-format */ |
7910 | 0 | (_("%pB: relocation %s against `%s' can not be used when making " |
7911 | 0 | "a shared object"), |
7912 | 0 | abfd, elf64_aarch64_howto_table[howto_index].name, |
7913 | 0 | (h) ? h->root.root.string : "a local symbol"); |
7914 | 0 | bfd_set_error (bfd_error_bad_value); |
7915 | 0 | return false; |
7916 | 0 | } |
7917 | 0 | else |
7918 | 0 | break; |
7919 | | |
7920 | 0 | case BFD_RELOC_AARCH64_MOVW_G0_NC: |
7921 | 0 | case BFD_RELOC_AARCH64_MOVW_G1_NC: |
7922 | 0 | case BFD_RELOC_AARCH64_MOVW_G2_NC: |
7923 | 0 | case BFD_RELOC_AARCH64_MOVW_G3: |
7924 | 0 | if (bfd_link_pic (info)) |
7925 | 0 | { |
7926 | 0 | int howto_index = bfd_r_type - BFD_RELOC_AARCH64_RELOC_START; |
7927 | 0 | _bfd_error_handler |
7928 | | /* xgettext:c-format */ |
7929 | 0 | (_("%pB: relocation %s against `%s' can not be used when making " |
7930 | 0 | "a shared object; recompile with -fPIC"), |
7931 | 0 | abfd, elf64_aarch64_howto_table[howto_index].name, |
7932 | 0 | (h) ? h->root.root.string : "a local symbol"); |
7933 | 0 | bfd_set_error (bfd_error_bad_value); |
7934 | 0 | return false; |
7935 | 0 | } |
7936 | | /* Fall through. */ |
7937 | | |
7938 | 0 | case BFD_RELOC_AARCH64_16_PCREL: |
7939 | 0 | case BFD_RELOC_AARCH64_32_PCREL: |
7940 | 0 | case BFD_RELOC_AARCH64_64_PCREL: |
7941 | 0 | case BFD_RELOC_AARCH64_ADD_LO12: |
7942 | 0 | case BFD_RELOC_AARCH64_ADR_HI21_NC_PCREL: |
7943 | 0 | case BFD_RELOC_AARCH64_ADR_HI21_PCREL: |
7944 | 0 | case BFD_RELOC_AARCH64_ADR_LO21_PCREL: |
7945 | 0 | case BFD_RELOC_AARCH64_LDST128_LO12: |
7946 | 0 | case BFD_RELOC_AARCH64_LDST16_LO12: |
7947 | 0 | case BFD_RELOC_AARCH64_LDST32_LO12: |
7948 | 0 | case BFD_RELOC_AARCH64_LDST64_LO12: |
7949 | 0 | case BFD_RELOC_AARCH64_LDST8_LO12: |
7950 | 0 | case BFD_RELOC_AARCH64_LD_LO19_PCREL: |
7951 | 0 | if (h == NULL || bfd_link_pic (info)) |
7952 | 0 | break; |
7953 | | /* Fall through. */ |
7954 | | |
7955 | 0 | case BFD_RELOC_AARCH64_64: |
7956 | | |
7957 | | /* We don't need to handle relocs into sections not going into |
7958 | | the "real" output. */ |
7959 | 0 | if ((sec->flags & SEC_ALLOC) == 0) |
7960 | 0 | break; |
7961 | | |
7962 | 0 | if (h != NULL) |
7963 | 0 | { |
7964 | 0 | if (!bfd_link_pic (info)) |
7965 | 0 | h->non_got_ref = 1; |
7966 | |
|
7967 | 0 | h->plt.refcount += 1; |
7968 | 0 | h->pointer_equality_needed = 1; |
7969 | 0 | } |
7970 | | |
7971 | | /* No need to do anything if we're not creating a shared |
7972 | | object. */ |
7973 | 0 | if (!(bfd_link_pic (info) |
7974 | | /* If on the other hand, we are creating an executable, we |
7975 | | may need to keep relocations for symbols satisfied by a |
7976 | | dynamic library if we manage to avoid copy relocs for the |
7977 | | symbol. |
7978 | | |
7979 | | NOTE: Currently, there is no support of copy relocs |
7980 | | elimination on pc-relative relocation types, because there is |
7981 | | no dynamic relocation support for them in glibc. We still |
7982 | | record the dynamic symbol reference for them. This is |
7983 | | because one symbol may be referenced by both absolute |
7984 | | relocation (for example, BFD_RELOC_AARCH64_64) and |
7985 | | pc-relative relocation. We need full symbol reference |
7986 | | information to make correct decision later in |
7987 | | elf64_aarch64_adjust_dynamic_symbol. */ |
7988 | 0 | || (ELIMINATE_COPY_RELOCS |
7989 | 0 | && !bfd_link_pic (info) |
7990 | 0 | && h != NULL |
7991 | 0 | && (h->root.type == bfd_link_hash_defweak |
7992 | 0 | || !h->def_regular)))) |
7993 | 0 | break; |
7994 | | |
7995 | 0 | { |
7996 | 0 | struct elf_dyn_relocs *p; |
7997 | 0 | struct elf_dyn_relocs **head; |
7998 | 0 | int howto_index = bfd_r_type - BFD_RELOC_AARCH64_RELOC_START; |
7999 | | |
8000 | | /* We must copy these reloc types into the output file. |
8001 | | Create a reloc section in dynobj and make room for |
8002 | | this reloc. */ |
8003 | 0 | if (sreloc == NULL) |
8004 | 0 | { |
8005 | 0 | if (htab->root.dynobj == NULL) |
8006 | 0 | htab->root.dynobj = abfd; |
8007 | |
|
8008 | 0 | sreloc = _bfd_elf_make_dynamic_reloc_section |
8009 | 0 | (sec, htab->root.dynobj, LOG_FILE_ALIGN, abfd, /*rela? */ true); |
8010 | |
|
8011 | 0 | if (sreloc == NULL) |
8012 | 0 | return false; |
8013 | 0 | } |
8014 | | |
8015 | | /* If this is a global symbol, we count the number of |
8016 | | relocations we need for this symbol. */ |
8017 | 0 | if (h != NULL) |
8018 | 0 | { |
8019 | 0 | head = &h->dyn_relocs; |
8020 | 0 | } |
8021 | 0 | else |
8022 | 0 | { |
8023 | | /* Track dynamic relocs needed for local syms too. |
8024 | | We really need local syms available to do this |
8025 | | easily. Oh well. */ |
8026 | |
|
8027 | 0 | asection *s; |
8028 | 0 | void **vpp; |
8029 | |
|
8030 | 0 | isym = bfd_sym_from_r_symndx (&htab->root.sym_cache, |
8031 | 0 | abfd, r_symndx); |
8032 | 0 | if (isym == NULL) |
8033 | 0 | return false; |
8034 | | |
8035 | 0 | s = bfd_section_from_elf_index (abfd, isym->st_shndx); |
8036 | 0 | if (s == NULL) |
8037 | 0 | s = sec; |
8038 | | |
8039 | | /* Beware of type punned pointers vs strict aliasing |
8040 | | rules. */ |
8041 | 0 | vpp = &(elf_section_data (s)->local_dynrel); |
8042 | 0 | head = (struct elf_dyn_relocs **) vpp; |
8043 | 0 | } |
8044 | | |
8045 | 0 | p = *head; |
8046 | 0 | if (p == NULL || p->sec != sec) |
8047 | 0 | { |
8048 | 0 | size_t amt = sizeof *p; |
8049 | 0 | p = ((struct elf_dyn_relocs *) |
8050 | 0 | bfd_zalloc (htab->root.dynobj, amt)); |
8051 | 0 | if (p == NULL) |
8052 | 0 | return false; |
8053 | 0 | p->next = *head; |
8054 | 0 | *head = p; |
8055 | 0 | p->sec = sec; |
8056 | 0 | } |
8057 | | |
8058 | 0 | p->count += 1; |
8059 | |
|
8060 | 0 | if (elf64_aarch64_howto_table[howto_index].pc_relative) |
8061 | 0 | p->pc_count += 1; |
8062 | 0 | } |
8063 | 0 | break; |
8064 | | |
8065 | | /* RR: We probably want to keep a consistency check that |
8066 | | there are no dangling GOT_PAGE relocs. */ |
8067 | 0 | case BFD_RELOC_AARCH64_ADR_GOT_PAGE: |
8068 | 0 | case BFD_RELOC_AARCH64_GOT_LD_PREL19: |
8069 | 0 | case BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14: |
8070 | 0 | case BFD_RELOC_AARCH64_LD32_GOT_LO12_NC: |
8071 | 0 | case BFD_RELOC_AARCH64_LD64_GOTOFF_LO15: |
8072 | 0 | case BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15: |
8073 | 0 | case BFD_RELOC_AARCH64_LD64_GOT_LO12_NC: |
8074 | 0 | case BFD_RELOC_AARCH64_MOVW_GOTOFF_G0_NC: |
8075 | 0 | case BFD_RELOC_AARCH64_MOVW_GOTOFF_G1: |
8076 | 0 | case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12: |
8077 | 0 | case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21: |
8078 | 0 | case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21: |
8079 | 0 | case BFD_RELOC_AARCH64_TLSDESC_LD32_LO12_NC: |
8080 | 0 | case BFD_RELOC_AARCH64_TLSDESC_LD64_LO12: |
8081 | 0 | case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19: |
8082 | 0 | case BFD_RELOC_AARCH64_TLSDESC_OFF_G0_NC: |
8083 | 0 | case BFD_RELOC_AARCH64_TLSDESC_OFF_G1: |
8084 | 0 | case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC: |
8085 | 0 | case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21: |
8086 | 0 | case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21: |
8087 | 0 | case BFD_RELOC_AARCH64_TLSGD_MOVW_G0_NC: |
8088 | 0 | case BFD_RELOC_AARCH64_TLSGD_MOVW_G1: |
8089 | 0 | case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21: |
8090 | 0 | case BFD_RELOC_AARCH64_TLSIE_LD32_GOTTPREL_LO12_NC: |
8091 | 0 | case BFD_RELOC_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC: |
8092 | 0 | case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19: |
8093 | 0 | case BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G0_NC: |
8094 | 0 | case BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G1: |
8095 | 0 | case BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC: |
8096 | 0 | case BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21: |
8097 | 0 | case BFD_RELOC_AARCH64_TLSLD_ADR_PREL21: |
8098 | 0 | { |
8099 | 0 | unsigned got_type; |
8100 | 0 | unsigned old_got_type; |
8101 | |
|
8102 | 0 | got_type = aarch64_reloc_got_type (bfd_r_type); |
8103 | |
|
8104 | 0 | if (h) |
8105 | 0 | { |
8106 | 0 | h->got.refcount += 1; |
8107 | 0 | old_got_type = elf_aarch64_hash_entry (h)->got_type; |
8108 | 0 | } |
8109 | 0 | else |
8110 | 0 | { |
8111 | 0 | struct elf_aarch64_local_symbol *locals; |
8112 | |
|
8113 | 0 | if (!elf64_aarch64_allocate_local_symbols |
8114 | 0 | (abfd, symtab_hdr->sh_info)) |
8115 | 0 | return false; |
8116 | | |
8117 | 0 | locals = elf_aarch64_locals (abfd); |
8118 | 0 | BFD_ASSERT (r_symndx < symtab_hdr->sh_info); |
8119 | 0 | locals[r_symndx].got_refcount += 1; |
8120 | 0 | old_got_type = locals[r_symndx].got_type; |
8121 | 0 | } |
8122 | | |
8123 | | /* If a variable is accessed with both general dynamic TLS |
8124 | | methods, two slots may be created. */ |
8125 | 0 | if (GOT_TLS_GD_ANY_P (old_got_type) && GOT_TLS_GD_ANY_P (got_type)) |
8126 | 0 | got_type |= old_got_type; |
8127 | | |
8128 | | /* We will already have issued an error message if there |
8129 | | is a TLS/non-TLS mismatch, based on the symbol type. |
8130 | | So just combine any TLS types needed. */ |
8131 | 0 | if (old_got_type != GOT_UNKNOWN && old_got_type != GOT_NORMAL |
8132 | 0 | && got_type != GOT_NORMAL) |
8133 | 0 | got_type |= old_got_type; |
8134 | | |
8135 | | /* If the symbol is accessed by both IE and GD methods, we |
8136 | | are able to relax. Turn off the GD flag, without |
8137 | | messing up with any other kind of TLS types that may be |
8138 | | involved. */ |
8139 | 0 | if ((got_type & GOT_TLS_IE) && GOT_TLS_GD_ANY_P (got_type)) |
8140 | 0 | got_type &= ~ (GOT_TLSDESC_GD | GOT_TLS_GD); |
8141 | |
|
8142 | 0 | if (old_got_type != got_type) |
8143 | 0 | { |
8144 | 0 | if (h != NULL) |
8145 | 0 | elf_aarch64_hash_entry (h)->got_type = got_type; |
8146 | 0 | else |
8147 | 0 | { |
8148 | 0 | struct elf_aarch64_local_symbol *locals; |
8149 | 0 | locals = elf_aarch64_locals (abfd); |
8150 | 0 | BFD_ASSERT (r_symndx < symtab_hdr->sh_info); |
8151 | 0 | locals[r_symndx].got_type = got_type; |
8152 | 0 | } |
8153 | 0 | } |
8154 | |
|
8155 | 0 | if (htab->root.dynobj == NULL) |
8156 | 0 | htab->root.dynobj = abfd; |
8157 | 0 | if (! aarch64_elf_create_got_section (htab->root.dynobj, info)) |
8158 | 0 | return false; |
8159 | 0 | break; |
8160 | 0 | } |
8161 | | |
8162 | 0 | case BFD_RELOC_AARCH64_CALL26: |
8163 | 0 | case BFD_RELOC_AARCH64_JUMP26: |
8164 | | /* If this is a local symbol then we resolve it |
8165 | | directly without creating a PLT entry. */ |
8166 | 0 | if (h == NULL) |
8167 | 0 | continue; |
8168 | | |
8169 | 0 | h->needs_plt = 1; |
8170 | 0 | if (h->plt.refcount <= 0) |
8171 | 0 | h->plt.refcount = 1; |
8172 | 0 | else |
8173 | 0 | h->plt.refcount += 1; |
8174 | 0 | break; |
8175 | | |
8176 | 0 | default: |
8177 | 0 | break; |
8178 | 0 | } |
8179 | 0 | } |
8180 | | |
8181 | 0 | return true; |
8182 | 0 | } |
8183 | | |
8184 | | /* Treat mapping symbols as special target symbols. */ |
8185 | | |
8186 | | static bool |
8187 | | elf64_aarch64_is_target_special_symbol (bfd *abfd ATTRIBUTE_UNUSED, |
8188 | | asymbol *sym) |
8189 | 0 | { |
8190 | 0 | return bfd_is_aarch64_special_symbol_name (sym->name, |
8191 | 0 | BFD_AARCH64_SPECIAL_SYM_TYPE_ANY); |
8192 | 0 | } |
8193 | | |
8194 | | /* If the ELF symbol SYM might be a function in SEC, return the |
8195 | | function size and set *CODE_OFF to the function's entry point, |
8196 | | otherwise return zero. */ |
8197 | | |
8198 | | static bfd_size_type |
8199 | | elf64_aarch64_maybe_function_sym (const asymbol *sym, asection *sec, |
8200 | | bfd_vma *code_off) |
8201 | 3.74k | { |
8202 | 3.74k | bfd_size_type size; |
8203 | 3.74k | elf_symbol_type * elf_sym = (elf_symbol_type *) sym; |
8204 | | |
8205 | 3.74k | if ((sym->flags & (BSF_SECTION_SYM | BSF_FILE | BSF_OBJECT |
8206 | 3.74k | | BSF_THREAD_LOCAL | BSF_RELC | BSF_SRELC)) != 0 |
8207 | 3.74k | || sym->section != sec) |
8208 | 3.63k | return 0; |
8209 | | |
8210 | 113 | size = (sym->flags & BSF_SYNTHETIC) ? 0 : elf_sym->internal_elf_sym.st_size; |
8211 | | |
8212 | 113 | if (!(sym->flags & BSF_SYNTHETIC)) |
8213 | 113 | switch (ELF_ST_TYPE (elf_sym->internal_elf_sym.st_info)) |
8214 | 113 | { |
8215 | 113 | case STT_NOTYPE: |
8216 | | /* Ignore symbols created by the annobin plugin for gcc and clang. |
8217 | | These symbols are hidden, local, notype and have a size of 0. */ |
8218 | 113 | if (size == 0 |
8219 | 113 | && sym->flags & BSF_LOCAL |
8220 | 113 | && ELF_ST_VISIBILITY (elf_sym->internal_elf_sym.st_other) == STV_HIDDEN) |
8221 | 0 | return 0; |
8222 | | /* Fall through. */ |
8223 | 113 | case STT_FUNC: |
8224 | | /* FIXME: Allow STT_GNU_IFUNC as well ? */ |
8225 | 113 | break; |
8226 | 0 | default: |
8227 | 0 | return 0; |
8228 | 113 | } |
8229 | | |
8230 | 113 | if ((sym->flags & BSF_LOCAL) |
8231 | 113 | && bfd_is_aarch64_special_symbol_name (sym->name, |
8232 | 85 | BFD_AARCH64_SPECIAL_SYM_TYPE_ANY)) |
8233 | 12 | return 0; |
8234 | | |
8235 | 101 | *code_off = sym->value; |
8236 | | |
8237 | | /* Do not return 0 for the function's size. */ |
8238 | 101 | return size ? size : 1; |
8239 | 113 | } |
8240 | | |
8241 | | static bool |
8242 | | elf64_aarch64_find_inliner_info (bfd *abfd, |
8243 | | const char **filename_ptr, |
8244 | | const char **functionname_ptr, |
8245 | | unsigned int *line_ptr) |
8246 | 0 | { |
8247 | 0 | bool found; |
8248 | 0 | found = _bfd_dwarf2_find_inliner_info |
8249 | 0 | (abfd, filename_ptr, |
8250 | 0 | functionname_ptr, line_ptr, &elf_tdata (abfd)->dwarf2_find_line_info); |
8251 | 0 | return found; |
8252 | 0 | } |
8253 | | |
8254 | | |
8255 | | static bool |
8256 | | elf64_aarch64_init_file_header (bfd *abfd, struct bfd_link_info *link_info) |
8257 | 0 | { |
8258 | 0 | Elf_Internal_Ehdr *i_ehdrp; /* ELF file header, internal form. */ |
8259 | |
|
8260 | 0 | if (!_bfd_elf_init_file_header (abfd, link_info)) |
8261 | 0 | return false; |
8262 | | |
8263 | 0 | i_ehdrp = elf_elfheader (abfd); |
8264 | 0 | i_ehdrp->e_ident[EI_ABIVERSION] = AARCH64_ELF_ABI_VERSION; |
8265 | 0 | return true; |
8266 | 0 | } |
8267 | | |
8268 | | static enum elf_reloc_type_class |
8269 | | elf64_aarch64_reloc_type_class (const struct bfd_link_info *info ATTRIBUTE_UNUSED, |
8270 | | const asection *rel_sec ATTRIBUTE_UNUSED, |
8271 | | const Elf_Internal_Rela *rela) |
8272 | 0 | { |
8273 | 0 | struct elf_aarch64_link_hash_table *htab = elf_aarch64_hash_table (info); |
8274 | |
|
8275 | 0 | if (htab->root.dynsym != NULL |
8276 | 0 | && htab->root.dynsym->contents != NULL) |
8277 | 0 | { |
8278 | | /* Check relocation against STT_GNU_IFUNC symbol if there are |
8279 | | dynamic symbols. */ |
8280 | 0 | bfd *abfd = info->output_bfd; |
8281 | 0 | const struct elf_backend_data *bed = get_elf_backend_data (abfd); |
8282 | 0 | unsigned long r_symndx = ELF64_R_SYM (rela->r_info); |
8283 | 0 | if (r_symndx != STN_UNDEF) |
8284 | 0 | { |
8285 | 0 | Elf_Internal_Sym sym; |
8286 | 0 | if (!bed->s->swap_symbol_in (abfd, |
8287 | 0 | (htab->root.dynsym->contents |
8288 | 0 | + r_symndx * bed->s->sizeof_sym), |
8289 | 0 | 0, &sym)) |
8290 | 0 | { |
8291 | | /* xgettext:c-format */ |
8292 | 0 | _bfd_error_handler (_("%pB symbol number %lu references" |
8293 | 0 | " nonexistent SHT_SYMTAB_SHNDX section"), |
8294 | 0 | abfd, r_symndx); |
8295 | | /* Ideally an error class should be returned here. */ |
8296 | 0 | } |
8297 | 0 | else if (ELF_ST_TYPE (sym.st_info) == STT_GNU_IFUNC) |
8298 | 0 | return reloc_class_ifunc; |
8299 | 0 | } |
8300 | 0 | } |
8301 | | |
8302 | 0 | switch ((int) ELF64_R_TYPE (rela->r_info)) |
8303 | 0 | { |
8304 | 0 | case AARCH64_R (IRELATIVE): |
8305 | 0 | return reloc_class_ifunc; |
8306 | 0 | case AARCH64_R (RELATIVE): |
8307 | 0 | return reloc_class_relative; |
8308 | 0 | case AARCH64_R (JUMP_SLOT): |
8309 | 0 | return reloc_class_plt; |
8310 | 0 | case AARCH64_R (COPY): |
8311 | 0 | return reloc_class_copy; |
8312 | 0 | default: |
8313 | 0 | return reloc_class_normal; |
8314 | 0 | } |
8315 | 0 | } |
8316 | | |
8317 | | /* Handle an AArch64 specific section when reading an object file. This is |
8318 | | called when bfd_section_from_shdr finds a section with an unknown |
8319 | | type. */ |
8320 | | |
8321 | | static bool |
8322 | | elf64_aarch64_section_from_shdr (bfd *abfd, |
8323 | | Elf_Internal_Shdr *hdr, |
8324 | | const char *name, int shindex) |
8325 | 65 | { |
8326 | | /* There ought to be a place to keep ELF backend specific flags, but |
8327 | | at the moment there isn't one. We just keep track of the |
8328 | | sections by their name, instead. Fortunately, the ABI gives |
8329 | | names for all the AArch64 specific sections, so we will probably get |
8330 | | away with this. */ |
8331 | 65 | switch (hdr->sh_type) |
8332 | 65 | { |
8333 | 0 | case SHT_AARCH64_ATTRIBUTES: |
8334 | 0 | break; |
8335 | | |
8336 | 65 | default: |
8337 | 65 | return false; |
8338 | 65 | } |
8339 | | |
8340 | 0 | if (!_bfd_elf_make_section_from_shdr (abfd, hdr, name, shindex)) |
8341 | 0 | return false; |
8342 | | |
8343 | 0 | return true; |
8344 | 0 | } |
8345 | | |
8346 | | /* Process any AArch64-specific program segment types. */ |
8347 | | |
8348 | | static bool |
8349 | | elf64_aarch64_section_from_phdr (bfd *abfd ATTRIBUTE_UNUSED, |
8350 | | Elf_Internal_Phdr *hdr, |
8351 | | int hdr_index ATTRIBUTE_UNUSED, |
8352 | | const char *name ATTRIBUTE_UNUSED) |
8353 | 0 | { |
8354 | | /* Right now we only handle the PT_AARCH64_MEMTAG_MTE segment type. */ |
8355 | 0 | if (hdr == NULL || hdr->p_type != PT_AARCH64_MEMTAG_MTE) |
8356 | 0 | return false; |
8357 | | |
8358 | 0 | if (hdr->p_filesz > 0) |
8359 | 0 | { |
8360 | | /* Sections created from memory tag p_type's are always named |
8361 | | "memtag". This makes it easier for tools (for example, GDB) |
8362 | | to find them. */ |
8363 | 0 | asection *newsect = bfd_make_section_anyway (abfd, "memtag"); |
8364 | |
|
8365 | 0 | if (newsect == NULL) |
8366 | 0 | return false; |
8367 | | |
8368 | 0 | unsigned int opb = bfd_octets_per_byte (abfd, NULL); |
8369 | | |
8370 | | /* p_vaddr holds the original start address of the tagged memory |
8371 | | range. */ |
8372 | 0 | newsect->vma = hdr->p_vaddr / opb; |
8373 | | |
8374 | | /* p_filesz holds the storage size of the packed tags. */ |
8375 | 0 | newsect->size = hdr->p_filesz; |
8376 | 0 | newsect->filepos = hdr->p_offset; |
8377 | | |
8378 | | /* p_memsz holds the size of the memory range that contains tags. The |
8379 | | section's rawsize field is reused for this purpose. */ |
8380 | 0 | newsect->rawsize = hdr->p_memsz; |
8381 | | |
8382 | | /* Make sure the section's flags has SEC_HAS_CONTENTS set, otherwise |
8383 | | BFD will return all zeroes when attempting to get contents from this |
8384 | | section. */ |
8385 | 0 | newsect->flags |= SEC_HAS_CONTENTS; |
8386 | 0 | } |
8387 | | |
8388 | 0 | return true; |
8389 | 0 | } |
8390 | | |
8391 | | /* Implements the bfd_elf_modify_headers hook for aarch64. */ |
8392 | | |
8393 | | static bool |
8394 | | elf64_aarch64_modify_headers (bfd *abfd, |
8395 | | struct bfd_link_info *info) |
8396 | 0 | { |
8397 | 0 | struct elf_segment_map *m; |
8398 | 0 | unsigned int segment_count = 0; |
8399 | 0 | Elf_Internal_Phdr *p; |
8400 | |
|
8401 | 0 | for (m = elf_seg_map (abfd); m != NULL; m = m->next, segment_count++) |
8402 | 0 | { |
8403 | | /* We are only interested in the memory tag segment that will be dumped |
8404 | | to a core file. If we have no memory tags or this isn't a core file we |
8405 | | are dealing with, just skip this segment. */ |
8406 | 0 | if (m->p_type != PT_AARCH64_MEMTAG_MTE |
8407 | 0 | || bfd_get_format (abfd) != bfd_core) |
8408 | 0 | continue; |
8409 | | |
8410 | | /* For memory tag segments in core files, the size of the file contents |
8411 | | is smaller than the size of the memory range. Adjust the memory size |
8412 | | accordingly. The real memory size is held in the section's rawsize |
8413 | | field. */ |
8414 | 0 | if (m->count > 0) |
8415 | 0 | { |
8416 | 0 | p = elf_tdata (abfd)->phdr; |
8417 | 0 | p += m->idx; |
8418 | 0 | p->p_memsz = m->sections[0]->rawsize; |
8419 | 0 | p->p_flags = 0; |
8420 | 0 | p->p_paddr = 0; |
8421 | 0 | p->p_align = 0; |
8422 | 0 | } |
8423 | 0 | } |
8424 | | |
8425 | | /* Give the generic code a chance to handle the headers. */ |
8426 | 0 | return _bfd_elf_modify_headers (abfd, info); |
8427 | 0 | } |
8428 | | |
8429 | | /* A structure used to record a list of sections, independently |
8430 | | of the next and prev fields in the asection structure. */ |
8431 | | typedef struct section_list |
8432 | | { |
8433 | | asection *sec; |
8434 | | struct section_list *next; |
8435 | | struct section_list *prev; |
8436 | | } |
8437 | | section_list; |
8438 | | |
8439 | | /* Unfortunately we need to keep a list of sections for which |
8440 | | an _aarch64_elf_section_data structure has been allocated. This |
8441 | | is because it is possible for functions like elf64_aarch64_write_section |
8442 | | to be called on a section which has had an elf_data_structure |
8443 | | allocated for it (and so the used_by_bfd field is valid) but |
8444 | | for which the AArch64 extended version of this structure - the |
8445 | | _aarch64_elf_section_data structure - has not been allocated. */ |
8446 | | static section_list *sections_with_aarch64_elf_section_data = NULL; |
8447 | | |
8448 | | static void |
8449 | | record_section_with_aarch64_elf_section_data (asection *sec) |
8450 | 332 | { |
8451 | 332 | struct section_list *entry; |
8452 | | |
8453 | 332 | entry = bfd_malloc (sizeof (*entry)); |
8454 | 332 | if (entry == NULL) |
8455 | 0 | return; |
8456 | 332 | entry->sec = sec; |
8457 | 332 | entry->next = sections_with_aarch64_elf_section_data; |
8458 | 332 | entry->prev = NULL; |
8459 | 332 | if (entry->next != NULL) |
8460 | 331 | entry->next->prev = entry; |
8461 | 332 | sections_with_aarch64_elf_section_data = entry; |
8462 | 332 | } |
8463 | | |
8464 | | static struct section_list * |
8465 | | find_aarch64_elf_section_entry (asection *sec) |
8466 | 280 | { |
8467 | 280 | struct section_list *entry; |
8468 | 280 | static struct section_list *last_entry = NULL; |
8469 | | |
8470 | | /* This is a short cut for the typical case where the sections are added |
8471 | | to the sections_with_aarch64_elf_section_data list in forward order and |
8472 | | then looked up here in backwards order. This makes a real difference |
8473 | | to the ld-srec/sec64k.exp linker test. */ |
8474 | 280 | entry = sections_with_aarch64_elf_section_data; |
8475 | 280 | if (last_entry != NULL) |
8476 | 264 | { |
8477 | 264 | if (last_entry->sec == sec) |
8478 | 264 | entry = last_entry; |
8479 | 0 | else if (last_entry->next != NULL && last_entry->next->sec == sec) |
8480 | 0 | entry = last_entry->next; |
8481 | 264 | } |
8482 | | |
8483 | 544 | for (; entry; entry = entry->next) |
8484 | 544 | if (entry->sec == sec) |
8485 | 280 | break; |
8486 | | |
8487 | 280 | if (entry) |
8488 | | /* Record the entry prior to this one - it is the entry we are |
8489 | | most likely to want to locate next time. Also this way if we |
8490 | | have been called from |
8491 | | unrecord_section_with_aarch64_elf_section_data () we will not |
8492 | | be caching a pointer that is about to be freed. */ |
8493 | 280 | last_entry = entry->prev; |
8494 | | |
8495 | 280 | return entry; |
8496 | 280 | } |
8497 | | |
8498 | | static void |
8499 | | unrecord_section_with_aarch64_elf_section_data (asection *sec) |
8500 | 280 | { |
8501 | 280 | struct section_list *entry; |
8502 | | |
8503 | 280 | entry = find_aarch64_elf_section_entry (sec); |
8504 | | |
8505 | 280 | if (entry) |
8506 | 280 | { |
8507 | 280 | if (entry->prev != NULL) |
8508 | 264 | entry->prev->next = entry->next; |
8509 | 280 | if (entry->next != NULL) |
8510 | 280 | entry->next->prev = entry->prev; |
8511 | 280 | if (entry == sections_with_aarch64_elf_section_data) |
8512 | 16 | sections_with_aarch64_elf_section_data = entry->next; |
8513 | 280 | free (entry); |
8514 | 280 | } |
8515 | 280 | } |
8516 | | |
8517 | | |
8518 | | typedef struct |
8519 | | { |
8520 | | void *finfo; |
8521 | | struct bfd_link_info *info; |
8522 | | asection *sec; |
8523 | | int sec_shndx; |
8524 | | int (*func) (void *, const char *, Elf_Internal_Sym *, |
8525 | | asection *, struct elf_link_hash_entry *); |
8526 | | } output_arch_syminfo; |
8527 | | |
8528 | | enum map_symbol_type |
8529 | | { |
8530 | | AARCH64_MAP_INSN, |
8531 | | AARCH64_MAP_DATA |
8532 | | }; |
8533 | | |
8534 | | |
8535 | | /* Output a single mapping symbol. */ |
8536 | | |
8537 | | static bool |
8538 | | elf64_aarch64_output_map_sym (output_arch_syminfo *osi, |
8539 | | enum map_symbol_type type, bfd_vma offset) |
8540 | 0 | { |
8541 | 0 | static const char *names[2] = { "$x", "$d" }; |
8542 | 0 | Elf_Internal_Sym sym; |
8543 | |
|
8544 | 0 | sym.st_value = (osi->sec->output_section->vma |
8545 | 0 | + osi->sec->output_offset + offset); |
8546 | 0 | sym.st_size = 0; |
8547 | 0 | sym.st_other = 0; |
8548 | 0 | sym.st_info = ELF_ST_INFO (STB_LOCAL, STT_NOTYPE); |
8549 | 0 | sym.st_shndx = osi->sec_shndx; |
8550 | 0 | return osi->func (osi->finfo, names[type], &sym, osi->sec, NULL) == 1; |
8551 | 0 | } |
8552 | | |
8553 | | /* Output a single local symbol for a generated stub. */ |
8554 | | |
8555 | | static bool |
8556 | | elf64_aarch64_output_stub_sym (output_arch_syminfo *osi, const char *name, |
8557 | | bfd_vma offset, bfd_vma size) |
8558 | 0 | { |
8559 | 0 | Elf_Internal_Sym sym; |
8560 | |
|
8561 | 0 | sym.st_value = (osi->sec->output_section->vma |
8562 | 0 | + osi->sec->output_offset + offset); |
8563 | 0 | sym.st_size = size; |
8564 | 0 | sym.st_other = 0; |
8565 | 0 | sym.st_info = ELF_ST_INFO (STB_LOCAL, STT_FUNC); |
8566 | 0 | sym.st_shndx = osi->sec_shndx; |
8567 | 0 | return osi->func (osi->finfo, name, &sym, osi->sec, NULL) == 1; |
8568 | 0 | } |
8569 | | |
8570 | | static bool |
8571 | | aarch64_map_one_stub (struct bfd_hash_entry *gen_entry, void *in_arg) |
8572 | 0 | { |
8573 | 0 | struct elf_aarch64_stub_hash_entry *stub_entry; |
8574 | 0 | asection *stub_sec; |
8575 | 0 | bfd_vma addr; |
8576 | 0 | char *stub_name; |
8577 | 0 | output_arch_syminfo *osi; |
8578 | | |
8579 | | /* Massage our args to the form they really have. */ |
8580 | 0 | stub_entry = (struct elf_aarch64_stub_hash_entry *) gen_entry; |
8581 | 0 | osi = (output_arch_syminfo *) in_arg; |
8582 | |
|
8583 | 0 | stub_sec = stub_entry->stub_sec; |
8584 | | |
8585 | | /* Ensure this stub is attached to the current section being |
8586 | | processed. */ |
8587 | 0 | if (stub_sec != osi->sec) |
8588 | 0 | return true; |
8589 | | |
8590 | 0 | addr = (bfd_vma) stub_entry->stub_offset; |
8591 | |
|
8592 | 0 | stub_name = stub_entry->output_name; |
8593 | |
|
8594 | 0 | switch (stub_entry->stub_type) |
8595 | 0 | { |
8596 | 0 | case aarch64_stub_adrp_branch: |
8597 | 0 | if (!elf64_aarch64_output_stub_sym (osi, stub_name, addr, |
8598 | 0 | sizeof (aarch64_adrp_branch_stub))) |
8599 | 0 | return false; |
8600 | 0 | if (!elf64_aarch64_output_map_sym (osi, AARCH64_MAP_INSN, addr)) |
8601 | 0 | return false; |
8602 | 0 | break; |
8603 | 0 | case aarch64_stub_long_branch: |
8604 | 0 | if (!elf64_aarch64_output_stub_sym |
8605 | 0 | (osi, stub_name, addr, sizeof (aarch64_long_branch_stub))) |
8606 | 0 | return false; |
8607 | 0 | if (!elf64_aarch64_output_map_sym (osi, AARCH64_MAP_INSN, addr)) |
8608 | 0 | return false; |
8609 | 0 | if (!elf64_aarch64_output_map_sym (osi, AARCH64_MAP_DATA, addr + 16)) |
8610 | 0 | return false; |
8611 | 0 | break; |
8612 | 0 | case aarch64_stub_bti_direct_branch: |
8613 | 0 | if (!elf64_aarch64_output_stub_sym (osi, stub_name, addr, |
8614 | 0 | sizeof (aarch64_bti_direct_branch_stub))) |
8615 | 0 | return false; |
8616 | 0 | if (!elf64_aarch64_output_map_sym (osi, AARCH64_MAP_INSN, addr)) |
8617 | 0 | return false; |
8618 | 0 | break; |
8619 | 0 | case aarch64_stub_erratum_835769_veneer: |
8620 | 0 | if (!elf64_aarch64_output_stub_sym (osi, stub_name, addr, |
8621 | 0 | sizeof (aarch64_erratum_835769_stub))) |
8622 | 0 | return false; |
8623 | 0 | if (!elf64_aarch64_output_map_sym (osi, AARCH64_MAP_INSN, addr)) |
8624 | 0 | return false; |
8625 | 0 | break; |
8626 | 0 | case aarch64_stub_erratum_843419_veneer: |
8627 | 0 | if (!elf64_aarch64_output_stub_sym (osi, stub_name, addr, |
8628 | 0 | sizeof (aarch64_erratum_843419_stub))) |
8629 | 0 | return false; |
8630 | 0 | if (!elf64_aarch64_output_map_sym (osi, AARCH64_MAP_INSN, addr)) |
8631 | 0 | return false; |
8632 | 0 | break; |
8633 | 0 | case aarch64_stub_none: |
8634 | 0 | break; |
8635 | | |
8636 | 0 | default: |
8637 | 0 | abort (); |
8638 | 0 | } |
8639 | | |
8640 | 0 | return true; |
8641 | 0 | } |
8642 | | |
8643 | | /* Output mapping symbols for linker generated sections. */ |
8644 | | |
8645 | | static bool |
8646 | | elf64_aarch64_output_arch_local_syms (bfd *output_bfd, |
8647 | | struct bfd_link_info *info, |
8648 | | void *finfo, |
8649 | | int (*func) (void *, const char *, |
8650 | | Elf_Internal_Sym *, |
8651 | | asection *, |
8652 | | struct elf_link_hash_entry |
8653 | | *)) |
8654 | 0 | { |
8655 | 0 | output_arch_syminfo osi; |
8656 | 0 | struct elf_aarch64_link_hash_table *htab; |
8657 | |
|
8658 | 0 | if (info->strip == strip_all |
8659 | 0 | && !info->emitrelocations |
8660 | 0 | && !bfd_link_relocatable (info)) |
8661 | 0 | return true; |
8662 | | |
8663 | 0 | htab = elf_aarch64_hash_table (info); |
8664 | |
|
8665 | 0 | osi.finfo = finfo; |
8666 | 0 | osi.info = info; |
8667 | 0 | osi.func = func; |
8668 | | |
8669 | | /* Long calls stubs. */ |
8670 | 0 | if (htab->stub_bfd && htab->stub_bfd->sections) |
8671 | 0 | { |
8672 | 0 | asection *stub_sec; |
8673 | |
|
8674 | 0 | for (stub_sec = htab->stub_bfd->sections; |
8675 | 0 | stub_sec != NULL; stub_sec = stub_sec->next) |
8676 | 0 | { |
8677 | | /* Ignore non-stub sections. */ |
8678 | 0 | if (!strstr (stub_sec->name, STUB_SUFFIX)) |
8679 | 0 | continue; |
8680 | | |
8681 | 0 | osi.sec = stub_sec; |
8682 | |
|
8683 | 0 | osi.sec_shndx = _bfd_elf_section_from_bfd_section |
8684 | 0 | (output_bfd, osi.sec->output_section); |
8685 | | |
8686 | | /* The first instruction in a stub is always a branch. */ |
8687 | 0 | if (!elf64_aarch64_output_map_sym (&osi, AARCH64_MAP_INSN, 0)) |
8688 | 0 | return false; |
8689 | | |
8690 | 0 | bfd_hash_traverse (&htab->stub_hash_table, aarch64_map_one_stub, |
8691 | 0 | &osi); |
8692 | 0 | } |
8693 | 0 | } |
8694 | | |
8695 | | /* Finally, output mapping symbols for the PLT. */ |
8696 | 0 | if (!htab->root.splt || htab->root.splt->size == 0) |
8697 | 0 | return true; |
8698 | | |
8699 | 0 | osi.sec_shndx = _bfd_elf_section_from_bfd_section |
8700 | 0 | (output_bfd, htab->root.splt->output_section); |
8701 | 0 | osi.sec = htab->root.splt; |
8702 | |
|
8703 | 0 | elf64_aarch64_output_map_sym (&osi, AARCH64_MAP_INSN, 0); |
8704 | |
|
8705 | 0 | return true; |
8706 | |
|
8707 | 0 | } |
8708 | | |
8709 | | /* Allocate target specific section data. */ |
8710 | | |
8711 | | static bool |
8712 | | elf64_aarch64_new_section_hook (bfd *abfd, asection *sec) |
8713 | 332 | { |
8714 | 332 | if (!sec->used_by_bfd) |
8715 | 332 | { |
8716 | 332 | _aarch64_elf_section_data *sdata; |
8717 | 332 | size_t amt = sizeof (*sdata); |
8718 | | |
8719 | 332 | sdata = bfd_zalloc (abfd, amt); |
8720 | 332 | if (sdata == NULL) |
8721 | 0 | return false; |
8722 | 332 | sec->used_by_bfd = sdata; |
8723 | 332 | } |
8724 | | |
8725 | 332 | record_section_with_aarch64_elf_section_data (sec); |
8726 | | |
8727 | 332 | return _bfd_elf_new_section_hook (abfd, sec); |
8728 | 332 | } |
8729 | | |
8730 | | |
8731 | | static void |
8732 | | unrecord_section_via_map_over_sections (bfd *abfd ATTRIBUTE_UNUSED, |
8733 | | asection *sec, |
8734 | | void *ignore ATTRIBUTE_UNUSED) |
8735 | 280 | { |
8736 | 280 | unrecord_section_with_aarch64_elf_section_data (sec); |
8737 | 280 | } |
8738 | | |
8739 | | static bool |
8740 | | elf64_aarch64_bfd_free_cached_info (bfd *abfd) |
8741 | 3.19k | { |
8742 | 3.19k | if (abfd->sections) |
8743 | 16 | bfd_map_over_sections (abfd, |
8744 | 16 | unrecord_section_via_map_over_sections, NULL); |
8745 | | |
8746 | 3.19k | return _bfd_elf_free_cached_info (abfd); |
8747 | 3.19k | } |
8748 | | |
8749 | | /* Create dynamic sections. This is different from the ARM backend in that |
8750 | | the got, plt, gotplt and their relocation sections are all created in the |
8751 | | standard part of the bfd elf backend. */ |
8752 | | |
8753 | | static bool |
8754 | | elf64_aarch64_create_dynamic_sections (bfd *dynobj, |
8755 | | struct bfd_link_info *info) |
8756 | 0 | { |
8757 | | /* We need to create .got section. */ |
8758 | 0 | if (!aarch64_elf_create_got_section (dynobj, info)) |
8759 | 0 | return false; |
8760 | | |
8761 | 0 | return _bfd_elf_create_dynamic_sections (dynobj, info); |
8762 | 0 | } |
8763 | | |
8764 | | |
8765 | | /* Allocate space in .plt, .got and associated reloc sections for |
8766 | | dynamic relocs. */ |
8767 | | |
8768 | | static bool |
8769 | | elf64_aarch64_allocate_dynrelocs (struct elf_link_hash_entry *h, void *inf) |
8770 | 0 | { |
8771 | 0 | struct bfd_link_info *info; |
8772 | 0 | struct elf_aarch64_link_hash_table *htab; |
8773 | 0 | struct elf_aarch64_link_hash_entry *eh; |
8774 | 0 | struct elf_dyn_relocs *p; |
8775 | | |
8776 | | /* An example of a bfd_link_hash_indirect symbol is versioned |
8777 | | symbol. For example: __gxx_personality_v0(bfd_link_hash_indirect) |
8778 | | -> __gxx_personality_v0(bfd_link_hash_defined) |
8779 | | |
8780 | | There is no need to process bfd_link_hash_indirect symbols here |
8781 | | because we will also be presented with the concrete instance of |
8782 | | the symbol and elf64_aarch64_copy_indirect_symbol () will have been |
8783 | | called to copy all relevant data from the generic to the concrete |
8784 | | symbol instance. */ |
8785 | 0 | if (h->root.type == bfd_link_hash_indirect) |
8786 | 0 | return true; |
8787 | | |
8788 | 0 | if (h->root.type == bfd_link_hash_warning) |
8789 | 0 | h = (struct elf_link_hash_entry *) h->root.u.i.link; |
8790 | |
|
8791 | 0 | info = (struct bfd_link_info *) inf; |
8792 | 0 | htab = elf_aarch64_hash_table (info); |
8793 | | |
8794 | | /* Since STT_GNU_IFUNC symbol must go through PLT, we handle it |
8795 | | here if it is defined and referenced in a non-shared object. */ |
8796 | 0 | if (h->type == STT_GNU_IFUNC |
8797 | 0 | && h->def_regular) |
8798 | 0 | return true; |
8799 | 0 | else if (htab->root.dynamic_sections_created && h->plt.refcount > 0) |
8800 | 0 | { |
8801 | | /* Make sure this symbol is output as a dynamic symbol. |
8802 | | Undefined weak syms won't yet be marked as dynamic. */ |
8803 | 0 | if (h->dynindx == -1 && !h->forced_local |
8804 | 0 | && h->root.type == bfd_link_hash_undefweak) |
8805 | 0 | { |
8806 | 0 | if (!bfd_elf_link_record_dynamic_symbol (info, h)) |
8807 | 0 | return false; |
8808 | 0 | } |
8809 | | |
8810 | 0 | if (bfd_link_pic (info) || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h)) |
8811 | 0 | { |
8812 | 0 | asection *s = htab->root.splt; |
8813 | | |
8814 | | /* If this is the first .plt entry, make room for the special |
8815 | | first entry. */ |
8816 | 0 | if (s->size == 0) |
8817 | 0 | s->size += htab->plt_header_size; |
8818 | |
|
8819 | 0 | h->plt.offset = s->size; |
8820 | | |
8821 | | /* If this symbol is not defined in a regular file, and we are |
8822 | | not generating a shared library, then set the symbol to this |
8823 | | location in the .plt. This is required to make function |
8824 | | pointers compare as equal between the normal executable and |
8825 | | the shared library. */ |
8826 | 0 | if (!bfd_link_pic (info) && !h->def_regular) |
8827 | 0 | { |
8828 | 0 | h->root.u.def.section = s; |
8829 | 0 | h->root.u.def.value = h->plt.offset; |
8830 | 0 | } |
8831 | | |
8832 | | /* Make room for this entry. For now we only create the |
8833 | | small model PLT entries. We later need to find a way |
8834 | | of relaxing into these from the large model PLT entries. */ |
8835 | 0 | s->size += htab->plt_entry_size; |
8836 | | |
8837 | | /* We also need to make an entry in the .got.plt section, which |
8838 | | will be placed in the .got section by the linker script. */ |
8839 | 0 | htab->root.sgotplt->size += GOT_ENTRY_SIZE; |
8840 | | |
8841 | | /* We also need to make an entry in the .rela.plt section. */ |
8842 | 0 | htab->root.srelplt->size += RELOC_SIZE (htab); |
8843 | | |
8844 | | /* We need to ensure that all GOT entries that serve the PLT |
8845 | | are consecutive with the special GOT slots [0] [1] and |
8846 | | [2]. Any addtional relocations, such as |
8847 | | R_AARCH64_TLSDESC, must be placed after the PLT related |
8848 | | entries. We abuse the reloc_count such that during |
8849 | | sizing we adjust reloc_count to indicate the number of |
8850 | | PLT related reserved entries. In subsequent phases when |
8851 | | filling in the contents of the reloc entries, PLT related |
8852 | | entries are placed by computing their PLT index (0 |
8853 | | .. reloc_count). While other none PLT relocs are placed |
8854 | | at the slot indicated by reloc_count and reloc_count is |
8855 | | updated. */ |
8856 | |
|
8857 | 0 | htab->root.srelplt->reloc_count++; |
8858 | | |
8859 | | /* Mark the DSO in case R_<CLS>_JUMP_SLOT relocs against |
8860 | | variant PCS symbols are present. */ |
8861 | 0 | if (h->other & STO_AARCH64_VARIANT_PCS) |
8862 | 0 | htab->variant_pcs = 1; |
8863 | |
|
8864 | 0 | } |
8865 | 0 | else |
8866 | 0 | { |
8867 | 0 | h->plt.offset = (bfd_vma) - 1; |
8868 | 0 | h->needs_plt = 0; |
8869 | 0 | } |
8870 | 0 | } |
8871 | 0 | else |
8872 | 0 | { |
8873 | 0 | h->plt.offset = (bfd_vma) - 1; |
8874 | 0 | h->needs_plt = 0; |
8875 | 0 | } |
8876 | | |
8877 | 0 | eh = (struct elf_aarch64_link_hash_entry *) h; |
8878 | 0 | eh->tlsdesc_got_jump_table_offset = (bfd_vma) - 1; |
8879 | |
|
8880 | 0 | if (h->got.refcount > 0) |
8881 | 0 | { |
8882 | 0 | bool dyn; |
8883 | 0 | unsigned got_type = elf_aarch64_hash_entry (h)->got_type; |
8884 | |
|
8885 | 0 | h->got.offset = (bfd_vma) - 1; |
8886 | |
|
8887 | 0 | dyn = htab->root.dynamic_sections_created; |
8888 | | |
8889 | | /* Make sure this symbol is output as a dynamic symbol. |
8890 | | Undefined weak syms won't yet be marked as dynamic. */ |
8891 | 0 | if (dyn && h->dynindx == -1 && !h->forced_local |
8892 | 0 | && h->root.type == bfd_link_hash_undefweak) |
8893 | 0 | { |
8894 | 0 | if (!bfd_elf_link_record_dynamic_symbol (info, h)) |
8895 | 0 | return false; |
8896 | 0 | } |
8897 | | |
8898 | 0 | if (got_type == GOT_UNKNOWN) |
8899 | 0 | { |
8900 | 0 | } |
8901 | 0 | else if (got_type == GOT_NORMAL) |
8902 | 0 | { |
8903 | 0 | h->got.offset = htab->root.sgot->size; |
8904 | 0 | htab->root.sgot->size += GOT_ENTRY_SIZE; |
8905 | 0 | if ((ELF_ST_VISIBILITY (h->other) == STV_DEFAULT |
8906 | 0 | || h->root.type != bfd_link_hash_undefweak) |
8907 | 0 | && (bfd_link_pic (info) |
8908 | 0 | || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, 0, h)) |
8909 | | /* Undefined weak symbol in static PIE resolves to 0 without |
8910 | | any dynamic relocations. */ |
8911 | 0 | && !UNDEFWEAK_NO_DYNAMIC_RELOC (info, h)) |
8912 | 0 | { |
8913 | 0 | htab->root.srelgot->size += RELOC_SIZE (htab); |
8914 | 0 | } |
8915 | 0 | } |
8916 | 0 | else |
8917 | 0 | { |
8918 | 0 | int indx; |
8919 | 0 | if (got_type & GOT_TLSDESC_GD) |
8920 | 0 | { |
8921 | 0 | eh->tlsdesc_got_jump_table_offset = |
8922 | 0 | (htab->root.sgotplt->size |
8923 | 0 | - aarch64_compute_jump_table_size (htab)); |
8924 | 0 | htab->root.sgotplt->size += GOT_ENTRY_SIZE * 2; |
8925 | 0 | h->got.offset = (bfd_vma) - 2; |
8926 | 0 | } |
8927 | |
|
8928 | 0 | if (got_type & GOT_TLS_GD) |
8929 | 0 | { |
8930 | 0 | h->got.offset = htab->root.sgot->size; |
8931 | 0 | htab->root.sgot->size += GOT_ENTRY_SIZE * 2; |
8932 | 0 | } |
8933 | |
|
8934 | 0 | if (got_type & GOT_TLS_IE) |
8935 | 0 | { |
8936 | 0 | h->got.offset = htab->root.sgot->size; |
8937 | 0 | htab->root.sgot->size += GOT_ENTRY_SIZE; |
8938 | 0 | } |
8939 | |
|
8940 | 0 | indx = h && h->dynindx != -1 ? h->dynindx : 0; |
8941 | 0 | if ((ELF_ST_VISIBILITY (h->other) == STV_DEFAULT |
8942 | 0 | || h->root.type != bfd_link_hash_undefweak) |
8943 | 0 | && (!bfd_link_executable (info) |
8944 | 0 | || indx != 0 |
8945 | 0 | || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, 0, h))) |
8946 | 0 | { |
8947 | 0 | if (got_type & GOT_TLSDESC_GD) |
8948 | 0 | { |
8949 | 0 | htab->root.srelplt->size += RELOC_SIZE (htab); |
8950 | | /* Note reloc_count not incremented here! We have |
8951 | | already adjusted reloc_count for this relocation |
8952 | | type. */ |
8953 | | |
8954 | | /* TLSDESC PLT is now needed, but not yet determined. */ |
8955 | 0 | htab->root.tlsdesc_plt = (bfd_vma) - 1; |
8956 | 0 | } |
8957 | |
|
8958 | 0 | if (got_type & GOT_TLS_GD) |
8959 | 0 | htab->root.srelgot->size += RELOC_SIZE (htab) * 2; |
8960 | |
|
8961 | 0 | if (got_type & GOT_TLS_IE) |
8962 | 0 | htab->root.srelgot->size += RELOC_SIZE (htab); |
8963 | 0 | } |
8964 | 0 | } |
8965 | 0 | } |
8966 | 0 | else |
8967 | 0 | { |
8968 | 0 | h->got.offset = (bfd_vma) - 1; |
8969 | 0 | } |
8970 | | |
8971 | 0 | if (h->dyn_relocs == NULL) |
8972 | 0 | return true; |
8973 | | |
8974 | 0 | for (p = h->dyn_relocs; p != NULL; p = p->next) |
8975 | 0 | if (eh->def_protected) |
8976 | 0 | { |
8977 | | /* Disallow copy relocations against protected symbol. */ |
8978 | 0 | asection *s = p->sec->output_section; |
8979 | 0 | if (s != NULL && (s->flags & SEC_READONLY) != 0) |
8980 | 0 | { |
8981 | 0 | info->callbacks->einfo |
8982 | | /* xgettext:c-format */ |
8983 | 0 | (_ ("%F%P: %pB: copy relocation against non-copyable " |
8984 | 0 | "protected symbol `%s'\n"), |
8985 | 0 | p->sec->owner, h->root.root.string); |
8986 | 0 | return false; |
8987 | 0 | } |
8988 | 0 | } |
8989 | | |
8990 | | /* In the shared -Bsymbolic case, discard space allocated for |
8991 | | dynamic pc-relative relocs against symbols which turn out to be |
8992 | | defined in regular objects. For the normal shared case, discard |
8993 | | space for pc-relative relocs that have become local due to symbol |
8994 | | visibility changes. */ |
8995 | | |
8996 | 0 | if (bfd_link_pic (info)) |
8997 | 0 | { |
8998 | | /* Relocs that use pc_count are those that appear on a call |
8999 | | insn, or certain REL relocs that can generated via assembly. |
9000 | | We want calls to protected symbols to resolve directly to the |
9001 | | function rather than going via the plt. If people want |
9002 | | function pointer comparisons to work as expected then they |
9003 | | should avoid writing weird assembly. */ |
9004 | 0 | if (SYMBOL_CALLS_LOCAL (info, h)) |
9005 | 0 | { |
9006 | 0 | struct elf_dyn_relocs **pp; |
9007 | |
|
9008 | 0 | for (pp = &h->dyn_relocs; (p = *pp) != NULL;) |
9009 | 0 | { |
9010 | 0 | p->count -= p->pc_count; |
9011 | 0 | p->pc_count = 0; |
9012 | 0 | if (p->count == 0) |
9013 | 0 | *pp = p->next; |
9014 | 0 | else |
9015 | 0 | pp = &p->next; |
9016 | 0 | } |
9017 | 0 | } |
9018 | | |
9019 | | /* Also discard relocs on undefined weak syms with non-default |
9020 | | visibility. */ |
9021 | 0 | if (h->dyn_relocs != NULL && h->root.type == bfd_link_hash_undefweak) |
9022 | 0 | { |
9023 | 0 | if (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT |
9024 | 0 | || UNDEFWEAK_NO_DYNAMIC_RELOC (info, h)) |
9025 | 0 | h->dyn_relocs = NULL; |
9026 | | |
9027 | | /* Make sure undefined weak symbols are output as a dynamic |
9028 | | symbol in PIEs. */ |
9029 | 0 | else if (h->dynindx == -1 |
9030 | 0 | && !h->forced_local |
9031 | 0 | && h->root.type == bfd_link_hash_undefweak |
9032 | 0 | && !bfd_elf_link_record_dynamic_symbol (info, h)) |
9033 | 0 | return false; |
9034 | 0 | } |
9035 | |
|
9036 | 0 | } |
9037 | 0 | else if (ELIMINATE_COPY_RELOCS) |
9038 | 0 | { |
9039 | | /* For the non-shared case, discard space for relocs against |
9040 | | symbols which turn out to need copy relocs or are not |
9041 | | dynamic. */ |
9042 | |
|
9043 | 0 | if (!h->non_got_ref |
9044 | 0 | && ((h->def_dynamic |
9045 | 0 | && !h->def_regular) |
9046 | 0 | || (htab->root.dynamic_sections_created |
9047 | 0 | && (h->root.type == bfd_link_hash_undefweak |
9048 | 0 | || h->root.type == bfd_link_hash_undefined)))) |
9049 | 0 | { |
9050 | | /* Make sure this symbol is output as a dynamic symbol. |
9051 | | Undefined weak syms won't yet be marked as dynamic. */ |
9052 | 0 | if (h->dynindx == -1 |
9053 | 0 | && !h->forced_local |
9054 | 0 | && h->root.type == bfd_link_hash_undefweak |
9055 | 0 | && !bfd_elf_link_record_dynamic_symbol (info, h)) |
9056 | 0 | return false; |
9057 | | |
9058 | | /* If that succeeded, we know we'll be keeping all the |
9059 | | relocs. */ |
9060 | 0 | if (h->dynindx != -1) |
9061 | 0 | goto keep; |
9062 | 0 | } |
9063 | | |
9064 | 0 | h->dyn_relocs = NULL; |
9065 | |
|
9066 | 0 | keep:; |
9067 | 0 | } |
9068 | | |
9069 | | /* Finally, allocate space. */ |
9070 | 0 | for (p = h->dyn_relocs; p != NULL; p = p->next) |
9071 | 0 | { |
9072 | 0 | asection *sreloc; |
9073 | |
|
9074 | 0 | sreloc = elf_section_data (p->sec)->sreloc; |
9075 | |
|
9076 | 0 | BFD_ASSERT (sreloc != NULL); |
9077 | |
|
9078 | 0 | sreloc->size += p->count * RELOC_SIZE (htab); |
9079 | 0 | } |
9080 | |
|
9081 | 0 | return true; |
9082 | 0 | } |
9083 | | |
9084 | | /* Allocate space in .plt, .got and associated reloc sections for |
9085 | | ifunc dynamic relocs. */ |
9086 | | |
9087 | | static bool |
9088 | | elf64_aarch64_allocate_ifunc_dynrelocs (struct elf_link_hash_entry *h, |
9089 | | void *inf) |
9090 | 0 | { |
9091 | 0 | struct bfd_link_info *info; |
9092 | 0 | struct elf_aarch64_link_hash_table *htab; |
9093 | | |
9094 | | /* An example of a bfd_link_hash_indirect symbol is versioned |
9095 | | symbol. For example: __gxx_personality_v0(bfd_link_hash_indirect) |
9096 | | -> __gxx_personality_v0(bfd_link_hash_defined) |
9097 | | |
9098 | | There is no need to process bfd_link_hash_indirect symbols here |
9099 | | because we will also be presented with the concrete instance of |
9100 | | the symbol and elf64_aarch64_copy_indirect_symbol () will have been |
9101 | | called to copy all relevant data from the generic to the concrete |
9102 | | symbol instance. */ |
9103 | 0 | if (h->root.type == bfd_link_hash_indirect) |
9104 | 0 | return true; |
9105 | | |
9106 | 0 | if (h->root.type == bfd_link_hash_warning) |
9107 | 0 | h = (struct elf_link_hash_entry *) h->root.u.i.link; |
9108 | |
|
9109 | 0 | info = (struct bfd_link_info *) inf; |
9110 | 0 | htab = elf_aarch64_hash_table (info); |
9111 | | |
9112 | | /* Since STT_GNU_IFUNC symbol must go through PLT, we handle it |
9113 | | here if it is defined and referenced in a non-shared object. */ |
9114 | 0 | if (h->type == STT_GNU_IFUNC |
9115 | 0 | && h->def_regular) |
9116 | 0 | return _bfd_elf_allocate_ifunc_dyn_relocs (info, h, |
9117 | 0 | &h->dyn_relocs, |
9118 | 0 | htab->plt_entry_size, |
9119 | 0 | htab->plt_header_size, |
9120 | 0 | GOT_ENTRY_SIZE, |
9121 | 0 | false); |
9122 | 0 | return true; |
9123 | 0 | } |
9124 | | |
9125 | | /* Allocate space in .plt, .got and associated reloc sections for |
9126 | | local ifunc dynamic relocs. */ |
9127 | | |
9128 | | static int |
9129 | | elf64_aarch64_allocate_local_ifunc_dynrelocs (void **slot, void *inf) |
9130 | 0 | { |
9131 | 0 | struct elf_link_hash_entry *h |
9132 | 0 | = (struct elf_link_hash_entry *) *slot; |
9133 | |
|
9134 | 0 | if (h->type != STT_GNU_IFUNC |
9135 | 0 | || !h->def_regular |
9136 | 0 | || !h->ref_regular |
9137 | 0 | || !h->forced_local |
9138 | 0 | || h->root.type != bfd_link_hash_defined) |
9139 | 0 | abort (); |
9140 | | |
9141 | 0 | return elf64_aarch64_allocate_ifunc_dynrelocs (h, inf); |
9142 | 0 | } |
9143 | | |
9144 | | /* This is the most important function of all . Innocuosly named |
9145 | | though ! */ |
9146 | | |
9147 | | static bool |
9148 | | elf64_aarch64_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED, |
9149 | | struct bfd_link_info *info) |
9150 | 0 | { |
9151 | 0 | struct elf_aarch64_link_hash_table *htab; |
9152 | 0 | bfd *dynobj; |
9153 | 0 | asection *s; |
9154 | 0 | bool relocs; |
9155 | 0 | bfd *ibfd; |
9156 | |
|
9157 | 0 | htab = elf_aarch64_hash_table ((info)); |
9158 | 0 | dynobj = htab->root.dynobj; |
9159 | |
|
9160 | 0 | BFD_ASSERT (dynobj != NULL); |
9161 | |
|
9162 | 0 | if (htab->root.dynamic_sections_created) |
9163 | 0 | { |
9164 | 0 | if (bfd_link_executable (info) && !info->nointerp) |
9165 | 0 | { |
9166 | 0 | s = bfd_get_linker_section (dynobj, ".interp"); |
9167 | 0 | if (s == NULL) |
9168 | 0 | abort (); |
9169 | 0 | s->size = sizeof ELF_DYNAMIC_INTERPRETER; |
9170 | 0 | s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER; |
9171 | 0 | } |
9172 | 0 | } |
9173 | | |
9174 | | /* Set up .got offsets for local syms, and space for local dynamic |
9175 | | relocs. */ |
9176 | 0 | for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link.next) |
9177 | 0 | { |
9178 | 0 | struct elf_aarch64_local_symbol *locals = NULL; |
9179 | 0 | Elf_Internal_Shdr *symtab_hdr; |
9180 | 0 | asection *srel; |
9181 | 0 | unsigned int i; |
9182 | |
|
9183 | 0 | if (!is_aarch64_elf (ibfd)) |
9184 | 0 | continue; |
9185 | | |
9186 | 0 | for (s = ibfd->sections; s != NULL; s = s->next) |
9187 | 0 | { |
9188 | 0 | struct elf_dyn_relocs *p; |
9189 | |
|
9190 | 0 | for (p = (struct elf_dyn_relocs *) |
9191 | 0 | (elf_section_data (s)->local_dynrel); p != NULL; p = p->next) |
9192 | 0 | { |
9193 | 0 | if (!bfd_is_abs_section (p->sec) |
9194 | 0 | && bfd_is_abs_section (p->sec->output_section)) |
9195 | 0 | { |
9196 | | /* Input section has been discarded, either because |
9197 | | it is a copy of a linkonce section or due to |
9198 | | linker script /DISCARD/, so we'll be discarding |
9199 | | the relocs too. */ |
9200 | 0 | } |
9201 | 0 | else if (p->count != 0) |
9202 | 0 | { |
9203 | 0 | srel = elf_section_data (p->sec)->sreloc; |
9204 | 0 | srel->size += p->count * RELOC_SIZE (htab); |
9205 | 0 | if ((p->sec->output_section->flags & SEC_READONLY) != 0) |
9206 | 0 | info->flags |= DF_TEXTREL; |
9207 | 0 | } |
9208 | 0 | } |
9209 | 0 | } |
9210 | |
|
9211 | 0 | locals = elf_aarch64_locals (ibfd); |
9212 | 0 | if (!locals) |
9213 | 0 | continue; |
9214 | | |
9215 | 0 | symtab_hdr = &elf_symtab_hdr (ibfd); |
9216 | 0 | srel = htab->root.srelgot; |
9217 | 0 | for (i = 0; i < symtab_hdr->sh_info; i++) |
9218 | 0 | { |
9219 | 0 | locals[i].got_offset = (bfd_vma) - 1; |
9220 | 0 | locals[i].tlsdesc_got_jump_table_offset = (bfd_vma) - 1; |
9221 | 0 | if (locals[i].got_refcount > 0) |
9222 | 0 | { |
9223 | 0 | unsigned got_type = locals[i].got_type; |
9224 | 0 | if (got_type & GOT_TLSDESC_GD) |
9225 | 0 | { |
9226 | 0 | locals[i].tlsdesc_got_jump_table_offset = |
9227 | 0 | (htab->root.sgotplt->size |
9228 | 0 | - aarch64_compute_jump_table_size (htab)); |
9229 | 0 | htab->root.sgotplt->size += GOT_ENTRY_SIZE * 2; |
9230 | 0 | locals[i].got_offset = (bfd_vma) - 2; |
9231 | 0 | } |
9232 | |
|
9233 | 0 | if (got_type & GOT_TLS_GD) |
9234 | 0 | { |
9235 | 0 | locals[i].got_offset = htab->root.sgot->size; |
9236 | 0 | htab->root.sgot->size += GOT_ENTRY_SIZE * 2; |
9237 | 0 | } |
9238 | |
|
9239 | 0 | if (got_type & GOT_TLS_IE |
9240 | 0 | || got_type & GOT_NORMAL) |
9241 | 0 | { |
9242 | 0 | locals[i].got_offset = htab->root.sgot->size; |
9243 | 0 | htab->root.sgot->size += GOT_ENTRY_SIZE; |
9244 | 0 | } |
9245 | |
|
9246 | 0 | if (got_type == GOT_UNKNOWN) |
9247 | 0 | { |
9248 | 0 | } |
9249 | |
|
9250 | 0 | if (bfd_link_pic (info)) |
9251 | 0 | { |
9252 | 0 | if (got_type & GOT_TLSDESC_GD) |
9253 | 0 | { |
9254 | 0 | htab->root.srelplt->size += RELOC_SIZE (htab); |
9255 | | /* Note RELOC_COUNT not incremented here! */ |
9256 | 0 | htab->root.tlsdesc_plt = (bfd_vma) - 1; |
9257 | 0 | } |
9258 | |
|
9259 | 0 | if (got_type & GOT_TLS_GD) |
9260 | 0 | htab->root.srelgot->size += RELOC_SIZE (htab) * 2; |
9261 | |
|
9262 | 0 | if (got_type & GOT_TLS_IE |
9263 | 0 | || got_type & GOT_NORMAL) |
9264 | 0 | htab->root.srelgot->size += RELOC_SIZE (htab); |
9265 | 0 | } |
9266 | 0 | } |
9267 | 0 | else |
9268 | 0 | { |
9269 | 0 | locals[i].got_refcount = (bfd_vma) - 1; |
9270 | 0 | } |
9271 | 0 | } |
9272 | 0 | } |
9273 | | |
9274 | | |
9275 | | /* Allocate global sym .plt and .got entries, and space for global |
9276 | | sym dynamic relocs. */ |
9277 | 0 | elf_link_hash_traverse (&htab->root, elf64_aarch64_allocate_dynrelocs, |
9278 | 0 | info); |
9279 | | |
9280 | | /* Allocate global ifunc sym .plt and .got entries, and space for global |
9281 | | ifunc sym dynamic relocs. */ |
9282 | 0 | elf_link_hash_traverse (&htab->root, elf64_aarch64_allocate_ifunc_dynrelocs, |
9283 | 0 | info); |
9284 | | |
9285 | | /* Allocate .plt and .got entries, and space for local ifunc symbols. */ |
9286 | 0 | htab_traverse (htab->loc_hash_table, |
9287 | 0 | elf64_aarch64_allocate_local_ifunc_dynrelocs, |
9288 | 0 | info); |
9289 | | |
9290 | | /* For every jump slot reserved in the sgotplt, reloc_count is |
9291 | | incremented. However, when we reserve space for TLS descriptors, |
9292 | | it's not incremented, so in order to compute the space reserved |
9293 | | for them, it suffices to multiply the reloc count by the jump |
9294 | | slot size. */ |
9295 | |
|
9296 | 0 | if (htab->root.srelplt) |
9297 | 0 | htab->sgotplt_jump_table_size = aarch64_compute_jump_table_size (htab); |
9298 | |
|
9299 | 0 | if (htab->root.tlsdesc_plt) |
9300 | 0 | { |
9301 | 0 | if (htab->root.splt->size == 0) |
9302 | 0 | htab->root.splt->size += htab->plt_header_size; |
9303 | | |
9304 | | /* If we're not using lazy TLS relocations, don't generate the |
9305 | | GOT and PLT entry required. */ |
9306 | 0 | if ((info->flags & DF_BIND_NOW)) |
9307 | 0 | htab->root.tlsdesc_plt = 0; |
9308 | 0 | else |
9309 | 0 | { |
9310 | 0 | htab->root.tlsdesc_plt = htab->root.splt->size; |
9311 | 0 | htab->root.splt->size += htab->tlsdesc_plt_entry_size; |
9312 | |
|
9313 | 0 | htab->root.tlsdesc_got = htab->root.sgot->size; |
9314 | 0 | htab->root.sgot->size += GOT_ENTRY_SIZE; |
9315 | 0 | } |
9316 | 0 | } |
9317 | | |
9318 | | /* Init mapping symbols information to use later to distingush between |
9319 | | code and data while scanning for errata. */ |
9320 | 0 | if (htab->fix_erratum_835769 || htab->fix_erratum_843419) |
9321 | 0 | for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link.next) |
9322 | 0 | { |
9323 | 0 | if (!is_aarch64_elf (ibfd)) |
9324 | 0 | continue; |
9325 | 0 | bfd_elf64_aarch64_init_maps (ibfd); |
9326 | 0 | } |
9327 | | |
9328 | | /* We now have determined the sizes of the various dynamic sections. |
9329 | | Allocate memory for them. */ |
9330 | 0 | relocs = false; |
9331 | 0 | for (s = dynobj->sections; s != NULL; s = s->next) |
9332 | 0 | { |
9333 | 0 | if ((s->flags & SEC_LINKER_CREATED) == 0) |
9334 | 0 | continue; |
9335 | | |
9336 | 0 | if (s == htab->root.splt |
9337 | 0 | || s == htab->root.sgot |
9338 | 0 | || s == htab->root.sgotplt |
9339 | 0 | || s == htab->root.iplt |
9340 | 0 | || s == htab->root.igotplt |
9341 | 0 | || s == htab->root.sdynbss |
9342 | 0 | || s == htab->root.sdynrelro) |
9343 | 0 | { |
9344 | | /* Strip this section if we don't need it; see the |
9345 | | comment below. */ |
9346 | 0 | } |
9347 | 0 | else if (startswith (bfd_section_name (s), ".rela")) |
9348 | 0 | { |
9349 | 0 | if (s->size != 0 && s != htab->root.srelplt) |
9350 | 0 | relocs = true; |
9351 | | |
9352 | | /* We use the reloc_count field as a counter if we need |
9353 | | to copy relocs into the output file. */ |
9354 | 0 | if (s != htab->root.srelplt) |
9355 | 0 | s->reloc_count = 0; |
9356 | 0 | } |
9357 | 0 | else |
9358 | 0 | { |
9359 | | /* It's not one of our sections, so don't allocate space. */ |
9360 | 0 | continue; |
9361 | 0 | } |
9362 | | |
9363 | 0 | if (s->size == 0) |
9364 | 0 | { |
9365 | | /* If we don't need this section, strip it from the |
9366 | | output file. This is mostly to handle .rela.bss and |
9367 | | .rela.plt. We must create both sections in |
9368 | | create_dynamic_sections, because they must be created |
9369 | | before the linker maps input sections to output |
9370 | | sections. The linker does that before |
9371 | | adjust_dynamic_symbol is called, and it is that |
9372 | | function which decides whether anything needs to go |
9373 | | into these sections. */ |
9374 | 0 | s->flags |= SEC_EXCLUDE; |
9375 | 0 | continue; |
9376 | 0 | } |
9377 | | |
9378 | 0 | if ((s->flags & SEC_HAS_CONTENTS) == 0) |
9379 | 0 | continue; |
9380 | | |
9381 | | /* Allocate memory for the section contents. We use bfd_zalloc |
9382 | | here in case unused entries are not reclaimed before the |
9383 | | section's contents are written out. This should not happen, |
9384 | | but this way if it does, we get a R_AARCH64_NONE reloc instead |
9385 | | of garbage. */ |
9386 | 0 | s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->size); |
9387 | 0 | if (s->contents == NULL) |
9388 | 0 | return false; |
9389 | 0 | } |
9390 | | |
9391 | 0 | if (htab->root.dynamic_sections_created) |
9392 | 0 | { |
9393 | | /* Add some entries to the .dynamic section. We fill in the |
9394 | | values later, in elf64_aarch64_finish_dynamic_sections, but we |
9395 | | must add the entries now so that we get the correct size for |
9396 | | the .dynamic section. The DT_DEBUG entry is filled in by the |
9397 | | dynamic linker and used by the debugger. */ |
9398 | 0 | #define add_dynamic_entry(TAG, VAL) \ |
9399 | 0 | _bfd_elf_add_dynamic_entry (info, TAG, VAL) |
9400 | |
|
9401 | 0 | if (!_bfd_elf_add_dynamic_tags (output_bfd, info, relocs)) |
9402 | 0 | return false; |
9403 | | |
9404 | 0 | if (htab->root.splt->size != 0) |
9405 | 0 | { |
9406 | 0 | if (htab->variant_pcs |
9407 | 0 | && !add_dynamic_entry (DT_AARCH64_VARIANT_PCS, 0)) |
9408 | 0 | return false; |
9409 | | |
9410 | 0 | if ((elf_aarch64_tdata (output_bfd)->plt_type == PLT_BTI_PAC) |
9411 | 0 | && (!add_dynamic_entry (DT_AARCH64_BTI_PLT, 0) |
9412 | 0 | || !add_dynamic_entry (DT_AARCH64_PAC_PLT, 0))) |
9413 | 0 | return false; |
9414 | | |
9415 | 0 | else if ((elf_aarch64_tdata (output_bfd)->plt_type == PLT_BTI) |
9416 | 0 | && !add_dynamic_entry (DT_AARCH64_BTI_PLT, 0)) |
9417 | 0 | return false; |
9418 | | |
9419 | 0 | else if ((elf_aarch64_tdata (output_bfd)->plt_type == PLT_PAC) |
9420 | 0 | && !add_dynamic_entry (DT_AARCH64_PAC_PLT, 0)) |
9421 | 0 | return false; |
9422 | 0 | } |
9423 | 0 | } |
9424 | 0 | #undef add_dynamic_entry |
9425 | | |
9426 | 0 | return true; |
9427 | 0 | } |
9428 | | |
9429 | | static inline void |
9430 | | elf_aarch64_update_plt_entry (bfd *output_bfd, |
9431 | | bfd_reloc_code_real_type r_type, |
9432 | | bfd_byte *plt_entry, bfd_vma value) |
9433 | 0 | { |
9434 | 0 | reloc_howto_type *howto = elf64_aarch64_howto_from_bfd_reloc (r_type); |
9435 | | |
9436 | | /* FIXME: We should check the return value from this function call. */ |
9437 | 0 | (void) _bfd_aarch64_elf_put_addend (output_bfd, plt_entry, r_type, howto, value); |
9438 | 0 | } |
9439 | | |
9440 | | static void |
9441 | | elf64_aarch64_create_small_pltn_entry (struct elf_link_hash_entry *h, |
9442 | | struct elf_aarch64_link_hash_table |
9443 | | *htab, bfd *output_bfd, |
9444 | | struct bfd_link_info *info) |
9445 | 0 | { |
9446 | 0 | bfd_byte *plt_entry; |
9447 | 0 | bfd_vma plt_index; |
9448 | 0 | bfd_vma got_offset; |
9449 | 0 | bfd_vma gotplt_entry_address; |
9450 | 0 | bfd_vma plt_entry_address; |
9451 | 0 | Elf_Internal_Rela rela; |
9452 | 0 | bfd_byte *loc; |
9453 | 0 | asection *plt, *gotplt, *relplt; |
9454 | | |
9455 | | /* When building a static executable, use .iplt, .igot.plt and |
9456 | | .rela.iplt sections for STT_GNU_IFUNC symbols. */ |
9457 | 0 | if (htab->root.splt != NULL) |
9458 | 0 | { |
9459 | 0 | plt = htab->root.splt; |
9460 | 0 | gotplt = htab->root.sgotplt; |
9461 | 0 | relplt = htab->root.srelplt; |
9462 | 0 | } |
9463 | 0 | else |
9464 | 0 | { |
9465 | 0 | plt = htab->root.iplt; |
9466 | 0 | gotplt = htab->root.igotplt; |
9467 | 0 | relplt = htab->root.irelplt; |
9468 | 0 | } |
9469 | | |
9470 | | /* Get the index in the procedure linkage table which |
9471 | | corresponds to this symbol. This is the index of this symbol |
9472 | | in all the symbols for which we are making plt entries. The |
9473 | | first entry in the procedure linkage table is reserved. |
9474 | | |
9475 | | Get the offset into the .got table of the entry that |
9476 | | corresponds to this function. Each .got entry is GOT_ENTRY_SIZE |
9477 | | bytes. The first three are reserved for the dynamic linker. |
9478 | | |
9479 | | For static executables, we don't reserve anything. */ |
9480 | |
|
9481 | 0 | if (plt == htab->root.splt) |
9482 | 0 | { |
9483 | 0 | plt_index = (h->plt.offset - htab->plt_header_size) / htab->plt_entry_size; |
9484 | 0 | got_offset = (plt_index + 3) * GOT_ENTRY_SIZE; |
9485 | 0 | } |
9486 | 0 | else |
9487 | 0 | { |
9488 | 0 | plt_index = h->plt.offset / htab->plt_entry_size; |
9489 | 0 | got_offset = plt_index * GOT_ENTRY_SIZE; |
9490 | 0 | } |
9491 | |
|
9492 | 0 | plt_entry = plt->contents + h->plt.offset; |
9493 | 0 | plt_entry_address = plt->output_section->vma |
9494 | 0 | + plt->output_offset + h->plt.offset; |
9495 | 0 | gotplt_entry_address = gotplt->output_section->vma + |
9496 | 0 | gotplt->output_offset + got_offset; |
9497 | | |
9498 | | /* Copy in the boiler-plate for the PLTn entry. */ |
9499 | 0 | memcpy (plt_entry, htab->plt_entry, htab->plt_entry_size); |
9500 | | |
9501 | | /* First instruction in BTI enabled PLT stub is a BTI |
9502 | | instruction so skip it. */ |
9503 | 0 | if (elf_aarch64_tdata (output_bfd)->plt_type & PLT_BTI |
9504 | 0 | && elf_elfheader (output_bfd)->e_type == ET_EXEC) |
9505 | 0 | plt_entry = plt_entry + 4; |
9506 | | |
9507 | | /* Fill in the top 21 bits for this: ADRP x16, PLT_GOT + n * 8. |
9508 | | ADRP: ((PG(S+A)-PG(P)) >> 12) & 0x1fffff */ |
9509 | 0 | elf_aarch64_update_plt_entry (output_bfd, BFD_RELOC_AARCH64_ADR_HI21_PCREL, |
9510 | 0 | plt_entry, |
9511 | 0 | PG (gotplt_entry_address) - |
9512 | 0 | PG (plt_entry_address)); |
9513 | | |
9514 | | /* Fill in the lo12 bits for the load from the pltgot. */ |
9515 | 0 | elf_aarch64_update_plt_entry (output_bfd, BFD_RELOC_AARCH64_LDST64_LO12, |
9516 | 0 | plt_entry + 4, |
9517 | 0 | PG_OFFSET (gotplt_entry_address)); |
9518 | | |
9519 | | /* Fill in the lo12 bits for the add from the pltgot entry. */ |
9520 | 0 | elf_aarch64_update_plt_entry (output_bfd, BFD_RELOC_AARCH64_ADD_LO12, |
9521 | 0 | plt_entry + 8, |
9522 | 0 | PG_OFFSET (gotplt_entry_address)); |
9523 | | |
9524 | | /* All the GOTPLT Entries are essentially initialized to PLT0. */ |
9525 | 0 | bfd_put_64 (output_bfd, |
9526 | 0 | plt->output_section->vma + plt->output_offset, |
9527 | 0 | gotplt->contents + got_offset); |
9528 | |
|
9529 | 0 | rela.r_offset = gotplt_entry_address; |
9530 | |
|
9531 | 0 | if (h->dynindx == -1 |
9532 | 0 | || ((bfd_link_executable (info) |
9533 | 0 | || ELF_ST_VISIBILITY (h->other) != STV_DEFAULT) |
9534 | 0 | && h->def_regular |
9535 | 0 | && h->type == STT_GNU_IFUNC)) |
9536 | 0 | { |
9537 | | /* If an STT_GNU_IFUNC symbol is locally defined, generate |
9538 | | R_AARCH64_IRELATIVE instead of R_AARCH64_JUMP_SLOT. */ |
9539 | 0 | rela.r_info = ELF64_R_INFO (0, AARCH64_R (IRELATIVE)); |
9540 | 0 | rela.r_addend = (h->root.u.def.value |
9541 | 0 | + h->root.u.def.section->output_section->vma |
9542 | 0 | + h->root.u.def.section->output_offset); |
9543 | 0 | } |
9544 | 0 | else |
9545 | 0 | { |
9546 | | /* Fill in the entry in the .rela.plt section. */ |
9547 | 0 | rela.r_info = ELF64_R_INFO (h->dynindx, AARCH64_R (JUMP_SLOT)); |
9548 | 0 | rela.r_addend = 0; |
9549 | 0 | } |
9550 | | |
9551 | | /* Compute the relocation entry to used based on PLT index and do |
9552 | | not adjust reloc_count. The reloc_count has already been adjusted |
9553 | | to account for this entry. */ |
9554 | 0 | loc = relplt->contents + plt_index * RELOC_SIZE (htab); |
9555 | 0 | bfd_elf64_swap_reloca_out (output_bfd, &rela, loc); |
9556 | 0 | } |
9557 | | |
9558 | | /* Size sections even though they're not dynamic. We use it to setup |
9559 | | _TLS_MODULE_BASE_, if needed. */ |
9560 | | |
9561 | | static bool |
9562 | | elf64_aarch64_always_size_sections (bfd *output_bfd, |
9563 | | struct bfd_link_info *info) |
9564 | 0 | { |
9565 | 0 | asection *tls_sec; |
9566 | |
|
9567 | 0 | if (bfd_link_relocatable (info)) |
9568 | 0 | return true; |
9569 | | |
9570 | 0 | tls_sec = elf_hash_table (info)->tls_sec; |
9571 | |
|
9572 | 0 | if (tls_sec) |
9573 | 0 | { |
9574 | 0 | struct elf_link_hash_entry *tlsbase; |
9575 | |
|
9576 | 0 | tlsbase = elf_link_hash_lookup (elf_hash_table (info), |
9577 | 0 | "_TLS_MODULE_BASE_", true, true, false); |
9578 | |
|
9579 | 0 | if (tlsbase) |
9580 | 0 | { |
9581 | 0 | struct bfd_link_hash_entry *h = NULL; |
9582 | 0 | const struct elf_backend_data *bed = |
9583 | 0 | get_elf_backend_data (output_bfd); |
9584 | |
|
9585 | 0 | if (!(_bfd_generic_link_add_one_symbol |
9586 | 0 | (info, output_bfd, "_TLS_MODULE_BASE_", BSF_LOCAL, |
9587 | 0 | tls_sec, 0, NULL, false, bed->collect, &h))) |
9588 | 0 | return false; |
9589 | | |
9590 | 0 | tlsbase->type = STT_TLS; |
9591 | 0 | tlsbase = (struct elf_link_hash_entry *) h; |
9592 | 0 | tlsbase->def_regular = 1; |
9593 | 0 | tlsbase->other = STV_HIDDEN; |
9594 | 0 | (*bed->elf_backend_hide_symbol) (info, tlsbase, true); |
9595 | 0 | } |
9596 | 0 | } |
9597 | | |
9598 | 0 | return true; |
9599 | 0 | } |
9600 | | |
9601 | | /* Finish up dynamic symbol handling. We set the contents of various |
9602 | | dynamic sections here. */ |
9603 | | |
9604 | | static bool |
9605 | | elf64_aarch64_finish_dynamic_symbol (bfd *output_bfd, |
9606 | | struct bfd_link_info *info, |
9607 | | struct elf_link_hash_entry *h, |
9608 | | Elf_Internal_Sym *sym) |
9609 | 0 | { |
9610 | 0 | struct elf_aarch64_link_hash_table *htab; |
9611 | 0 | htab = elf_aarch64_hash_table (info); |
9612 | |
|
9613 | 0 | if (h->plt.offset != (bfd_vma) - 1) |
9614 | 0 | { |
9615 | 0 | asection *plt, *gotplt, *relplt; |
9616 | | |
9617 | | /* This symbol has an entry in the procedure linkage table. Set |
9618 | | it up. */ |
9619 | | |
9620 | | /* When building a static executable, use .iplt, .igot.plt and |
9621 | | .rela.iplt sections for STT_GNU_IFUNC symbols. */ |
9622 | 0 | if (htab->root.splt != NULL) |
9623 | 0 | { |
9624 | 0 | plt = htab->root.splt; |
9625 | 0 | gotplt = htab->root.sgotplt; |
9626 | 0 | relplt = htab->root.srelplt; |
9627 | 0 | } |
9628 | 0 | else |
9629 | 0 | { |
9630 | 0 | plt = htab->root.iplt; |
9631 | 0 | gotplt = htab->root.igotplt; |
9632 | 0 | relplt = htab->root.irelplt; |
9633 | 0 | } |
9634 | | |
9635 | | /* This symbol has an entry in the procedure linkage table. Set |
9636 | | it up. */ |
9637 | 0 | if ((h->dynindx == -1 |
9638 | 0 | && !((h->forced_local || bfd_link_executable (info)) |
9639 | 0 | && h->def_regular |
9640 | 0 | && h->type == STT_GNU_IFUNC)) |
9641 | 0 | || plt == NULL |
9642 | 0 | || gotplt == NULL |
9643 | 0 | || relplt == NULL) |
9644 | 0 | return false; |
9645 | | |
9646 | 0 | elf64_aarch64_create_small_pltn_entry (h, htab, output_bfd, info); |
9647 | 0 | if (!h->def_regular) |
9648 | 0 | { |
9649 | | /* Mark the symbol as undefined, rather than as defined in |
9650 | | the .plt section. */ |
9651 | 0 | sym->st_shndx = SHN_UNDEF; |
9652 | | /* If the symbol is weak we need to clear the value. |
9653 | | Otherwise, the PLT entry would provide a definition for |
9654 | | the symbol even if the symbol wasn't defined anywhere, |
9655 | | and so the symbol would never be NULL. Leave the value if |
9656 | | there were any relocations where pointer equality matters |
9657 | | (this is a clue for the dynamic linker, to make function |
9658 | | pointer comparisons work between an application and shared |
9659 | | library). */ |
9660 | 0 | if (!h->ref_regular_nonweak || !h->pointer_equality_needed) |
9661 | 0 | sym->st_value = 0; |
9662 | 0 | } |
9663 | 0 | } |
9664 | | |
9665 | 0 | if (h->got.offset != (bfd_vma) - 1 |
9666 | 0 | && elf_aarch64_hash_entry (h)->got_type == GOT_NORMAL |
9667 | | /* Undefined weak symbol in static PIE resolves to 0 without |
9668 | | any dynamic relocations. */ |
9669 | 0 | && !UNDEFWEAK_NO_DYNAMIC_RELOC (info, h)) |
9670 | 0 | { |
9671 | 0 | Elf_Internal_Rela rela; |
9672 | 0 | bfd_byte *loc; |
9673 | | |
9674 | | /* This symbol has an entry in the global offset table. Set it |
9675 | | up. */ |
9676 | 0 | if (htab->root.sgot == NULL || htab->root.srelgot == NULL) |
9677 | 0 | abort (); |
9678 | | |
9679 | 0 | rela.r_offset = (htab->root.sgot->output_section->vma |
9680 | 0 | + htab->root.sgot->output_offset |
9681 | 0 | + (h->got.offset & ~(bfd_vma) 1)); |
9682 | |
|
9683 | 0 | if (h->def_regular |
9684 | 0 | && h->type == STT_GNU_IFUNC) |
9685 | 0 | { |
9686 | 0 | if (bfd_link_pic (info)) |
9687 | 0 | { |
9688 | | /* Generate R_AARCH64_GLOB_DAT. */ |
9689 | 0 | goto do_glob_dat; |
9690 | 0 | } |
9691 | 0 | else |
9692 | 0 | { |
9693 | 0 | asection *plt; |
9694 | |
|
9695 | 0 | if (!h->pointer_equality_needed) |
9696 | 0 | abort (); |
9697 | | |
9698 | | /* For non-shared object, we can't use .got.plt, which |
9699 | | contains the real function address if we need pointer |
9700 | | equality. We load the GOT entry with the PLT entry. */ |
9701 | 0 | plt = htab->root.splt ? htab->root.splt : htab->root.iplt; |
9702 | 0 | bfd_put_64 (output_bfd, (plt->output_section->vma |
9703 | 0 | + plt->output_offset |
9704 | 0 | + h->plt.offset), |
9705 | 0 | htab->root.sgot->contents |
9706 | 0 | + (h->got.offset & ~(bfd_vma) 1)); |
9707 | 0 | return true; |
9708 | 0 | } |
9709 | 0 | } |
9710 | 0 | else if (bfd_link_pic (info) && SYMBOL_REFERENCES_LOCAL (info, h)) |
9711 | 0 | { |
9712 | 0 | if (!(h->def_regular || ELF_COMMON_DEF_P (h))) |
9713 | 0 | return false; |
9714 | | |
9715 | 0 | BFD_ASSERT ((h->got.offset & 1) != 0); |
9716 | 0 | rela.r_info = ELF64_R_INFO (0, AARCH64_R (RELATIVE)); |
9717 | 0 | rela.r_addend = (h->root.u.def.value |
9718 | 0 | + h->root.u.def.section->output_section->vma |
9719 | 0 | + h->root.u.def.section->output_offset); |
9720 | 0 | } |
9721 | 0 | else |
9722 | 0 | { |
9723 | 0 | do_glob_dat: |
9724 | 0 | BFD_ASSERT ((h->got.offset & 1) == 0); |
9725 | 0 | bfd_put_64 (output_bfd, (bfd_vma) 0, |
9726 | 0 | htab->root.sgot->contents + h->got.offset); |
9727 | 0 | rela.r_info = ELF64_R_INFO (h->dynindx, AARCH64_R (GLOB_DAT)); |
9728 | 0 | rela.r_addend = 0; |
9729 | 0 | } |
9730 | | |
9731 | 0 | loc = htab->root.srelgot->contents; |
9732 | 0 | loc += htab->root.srelgot->reloc_count++ * RELOC_SIZE (htab); |
9733 | 0 | bfd_elf64_swap_reloca_out (output_bfd, &rela, loc); |
9734 | 0 | } |
9735 | | |
9736 | 0 | if (h->needs_copy) |
9737 | 0 | { |
9738 | 0 | Elf_Internal_Rela rela; |
9739 | 0 | asection *s; |
9740 | 0 | bfd_byte *loc; |
9741 | | |
9742 | | /* This symbol needs a copy reloc. Set it up. */ |
9743 | 0 | if (h->dynindx == -1 |
9744 | 0 | || (h->root.type != bfd_link_hash_defined |
9745 | 0 | && h->root.type != bfd_link_hash_defweak) |
9746 | 0 | || htab->root.srelbss == NULL) |
9747 | 0 | abort (); |
9748 | | |
9749 | 0 | rela.r_offset = (h->root.u.def.value |
9750 | 0 | + h->root.u.def.section->output_section->vma |
9751 | 0 | + h->root.u.def.section->output_offset); |
9752 | 0 | rela.r_info = ELF64_R_INFO (h->dynindx, AARCH64_R (COPY)); |
9753 | 0 | rela.r_addend = 0; |
9754 | 0 | if (h->root.u.def.section == htab->root.sdynrelro) |
9755 | 0 | s = htab->root.sreldynrelro; |
9756 | 0 | else |
9757 | 0 | s = htab->root.srelbss; |
9758 | 0 | loc = s->contents + s->reloc_count++ * RELOC_SIZE (htab); |
9759 | 0 | bfd_elf64_swap_reloca_out (output_bfd, &rela, loc); |
9760 | 0 | } |
9761 | | |
9762 | | /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. SYM may |
9763 | | be NULL for local symbols. */ |
9764 | 0 | if (sym != NULL |
9765 | 0 | && (h == elf_hash_table (info)->hdynamic |
9766 | 0 | || h == elf_hash_table (info)->hgot)) |
9767 | 0 | sym->st_shndx = SHN_ABS; |
9768 | |
|
9769 | 0 | return true; |
9770 | 0 | } |
9771 | | |
9772 | | /* Finish up local dynamic symbol handling. We set the contents of |
9773 | | various dynamic sections here. */ |
9774 | | |
9775 | | static int |
9776 | | elf64_aarch64_finish_local_dynamic_symbol (void **slot, void *inf) |
9777 | 0 | { |
9778 | 0 | struct elf_link_hash_entry *h |
9779 | 0 | = (struct elf_link_hash_entry *) *slot; |
9780 | 0 | struct bfd_link_info *info |
9781 | 0 | = (struct bfd_link_info *) inf; |
9782 | |
|
9783 | 0 | return elf64_aarch64_finish_dynamic_symbol (info->output_bfd, |
9784 | 0 | info, h, NULL); |
9785 | 0 | } |
9786 | | |
9787 | | static void |
9788 | | elf64_aarch64_init_small_plt0_entry (bfd *output_bfd ATTRIBUTE_UNUSED, |
9789 | | struct elf_aarch64_link_hash_table |
9790 | | *htab) |
9791 | 0 | { |
9792 | | /* Fill in PLT0. Fixme:RR Note this doesn't distinguish between |
9793 | | small and large plts and at the minute just generates |
9794 | | the small PLT. */ |
9795 | | |
9796 | | /* PLT0 of the small PLT looks like this in ELF64 - |
9797 | | stp x16, x30, [sp, #-16]! // Save the reloc and lr on stack. |
9798 | | adrp x16, PLT_GOT + 16 // Get the page base of the GOTPLT |
9799 | | ldr x17, [x16, #:lo12:PLT_GOT+16] // Load the address of the |
9800 | | // symbol resolver |
9801 | | add x16, x16, #:lo12:PLT_GOT+16 // Load the lo12 bits of the |
9802 | | // GOTPLT entry for this. |
9803 | | br x17 |
9804 | | PLT0 will be slightly different in ELF32 due to different got entry |
9805 | | size. */ |
9806 | 0 | bfd_vma plt_got_2nd_ent; /* Address of GOT[2]. */ |
9807 | 0 | bfd_vma plt_base; |
9808 | | |
9809 | |
|
9810 | 0 | memcpy (htab->root.splt->contents, htab->plt0_entry, |
9811 | 0 | htab->plt_header_size); |
9812 | | |
9813 | | /* PR 26312: Explicitly set the sh_entsize to 0 so that |
9814 | | consumers do not think that the section contains fixed |
9815 | | sized objects. */ |
9816 | 0 | elf_section_data (htab->root.splt->output_section)->this_hdr.sh_entsize = 0; |
9817 | |
|
9818 | 0 | plt_got_2nd_ent = (htab->root.sgotplt->output_section->vma |
9819 | 0 | + htab->root.sgotplt->output_offset |
9820 | 0 | + GOT_ENTRY_SIZE * 2); |
9821 | |
|
9822 | 0 | plt_base = htab->root.splt->output_section->vma + |
9823 | 0 | htab->root.splt->output_offset; |
9824 | | |
9825 | | /* First instruction in BTI enabled PLT stub is a BTI |
9826 | | instruction so skip it. */ |
9827 | 0 | bfd_byte *plt0_entry = htab->root.splt->contents; |
9828 | 0 | if (elf_aarch64_tdata (output_bfd)->plt_type & PLT_BTI) |
9829 | 0 | plt0_entry = plt0_entry + 4; |
9830 | | |
9831 | | /* Fill in the top 21 bits for this: ADRP x16, PLT_GOT + n * 8. |
9832 | | ADRP: ((PG(S+A)-PG(P)) >> 12) & 0x1fffff */ |
9833 | 0 | elf_aarch64_update_plt_entry (output_bfd, BFD_RELOC_AARCH64_ADR_HI21_PCREL, |
9834 | 0 | plt0_entry + 4, |
9835 | 0 | PG (plt_got_2nd_ent) - PG (plt_base + 4)); |
9836 | |
|
9837 | 0 | elf_aarch64_update_plt_entry (output_bfd, BFD_RELOC_AARCH64_LDST64_LO12, |
9838 | 0 | plt0_entry + 8, |
9839 | 0 | PG_OFFSET (plt_got_2nd_ent)); |
9840 | |
|
9841 | 0 | elf_aarch64_update_plt_entry (output_bfd, BFD_RELOC_AARCH64_ADD_LO12, |
9842 | 0 | plt0_entry + 12, |
9843 | 0 | PG_OFFSET (plt_got_2nd_ent)); |
9844 | 0 | } |
9845 | | |
9846 | | static bool |
9847 | | elf64_aarch64_finish_dynamic_sections (bfd *output_bfd, |
9848 | | struct bfd_link_info *info) |
9849 | 0 | { |
9850 | 0 | struct elf_aarch64_link_hash_table *htab; |
9851 | 0 | bfd *dynobj; |
9852 | 0 | asection *sdyn; |
9853 | |
|
9854 | 0 | htab = elf_aarch64_hash_table (info); |
9855 | 0 | dynobj = htab->root.dynobj; |
9856 | 0 | sdyn = bfd_get_linker_section (dynobj, ".dynamic"); |
9857 | |
|
9858 | 0 | if (htab->root.dynamic_sections_created) |
9859 | 0 | { |
9860 | 0 | Elf64_External_Dyn *dyncon, *dynconend; |
9861 | |
|
9862 | 0 | if (sdyn == NULL || htab->root.sgot == NULL) |
9863 | 0 | abort (); |
9864 | | |
9865 | 0 | dyncon = (Elf64_External_Dyn *) sdyn->contents; |
9866 | 0 | dynconend = (Elf64_External_Dyn *) (sdyn->contents + sdyn->size); |
9867 | 0 | for (; dyncon < dynconend; dyncon++) |
9868 | 0 | { |
9869 | 0 | Elf_Internal_Dyn dyn; |
9870 | 0 | asection *s; |
9871 | |
|
9872 | 0 | bfd_elf64_swap_dyn_in (dynobj, dyncon, &dyn); |
9873 | |
|
9874 | 0 | switch (dyn.d_tag) |
9875 | 0 | { |
9876 | 0 | default: |
9877 | 0 | continue; |
9878 | | |
9879 | 0 | case DT_PLTGOT: |
9880 | 0 | s = htab->root.sgotplt; |
9881 | 0 | dyn.d_un.d_ptr = s->output_section->vma + s->output_offset; |
9882 | 0 | break; |
9883 | | |
9884 | 0 | case DT_JMPREL: |
9885 | 0 | s = htab->root.srelplt; |
9886 | 0 | dyn.d_un.d_ptr = s->output_section->vma + s->output_offset; |
9887 | 0 | break; |
9888 | | |
9889 | 0 | case DT_PLTRELSZ: |
9890 | 0 | s = htab->root.srelplt; |
9891 | 0 | dyn.d_un.d_val = s->size; |
9892 | 0 | break; |
9893 | | |
9894 | 0 | case DT_TLSDESC_PLT: |
9895 | 0 | s = htab->root.splt; |
9896 | 0 | dyn.d_un.d_ptr = s->output_section->vma + s->output_offset |
9897 | 0 | + htab->root.tlsdesc_plt; |
9898 | 0 | break; |
9899 | | |
9900 | 0 | case DT_TLSDESC_GOT: |
9901 | 0 | s = htab->root.sgot; |
9902 | 0 | BFD_ASSERT (htab->root.tlsdesc_got != (bfd_vma)-1); |
9903 | 0 | dyn.d_un.d_ptr = s->output_section->vma + s->output_offset |
9904 | 0 | + htab->root.tlsdesc_got; |
9905 | 0 | break; |
9906 | 0 | } |
9907 | | |
9908 | 0 | bfd_elf64_swap_dyn_out (output_bfd, &dyn, dyncon); |
9909 | 0 | } |
9910 | |
|
9911 | 0 | } |
9912 | | |
9913 | | /* Fill in the special first entry in the procedure linkage table. */ |
9914 | 0 | if (htab->root.splt && htab->root.splt->size > 0) |
9915 | 0 | { |
9916 | 0 | elf64_aarch64_init_small_plt0_entry (output_bfd, htab); |
9917 | |
|
9918 | 0 | if (htab->root.tlsdesc_plt && !(info->flags & DF_BIND_NOW)) |
9919 | 0 | { |
9920 | 0 | BFD_ASSERT (htab->root.tlsdesc_got != (bfd_vma)-1); |
9921 | 0 | bfd_put_64 (output_bfd, (bfd_vma) 0, |
9922 | 0 | htab->root.sgot->contents + htab->root.tlsdesc_got); |
9923 | |
|
9924 | 0 | const bfd_byte *entry = elf64_aarch64_tlsdesc_small_plt_entry; |
9925 | 0 | htab->tlsdesc_plt_entry_size = PLT_TLSDESC_ENTRY_SIZE; |
9926 | |
|
9927 | 0 | aarch64_plt_type type = elf_aarch64_tdata (output_bfd)->plt_type; |
9928 | 0 | if (type == PLT_BTI || type == PLT_BTI_PAC) |
9929 | 0 | { |
9930 | 0 | entry = elf64_aarch64_tlsdesc_small_plt_bti_entry; |
9931 | 0 | } |
9932 | |
|
9933 | 0 | memcpy (htab->root.splt->contents + htab->root.tlsdesc_plt, |
9934 | 0 | entry, htab->tlsdesc_plt_entry_size); |
9935 | |
|
9936 | 0 | { |
9937 | 0 | bfd_vma adrp1_addr = |
9938 | 0 | htab->root.splt->output_section->vma |
9939 | 0 | + htab->root.splt->output_offset |
9940 | 0 | + htab->root.tlsdesc_plt + 4; |
9941 | |
|
9942 | 0 | bfd_vma adrp2_addr = adrp1_addr + 4; |
9943 | |
|
9944 | 0 | bfd_vma got_addr = |
9945 | 0 | htab->root.sgot->output_section->vma |
9946 | 0 | + htab->root.sgot->output_offset; |
9947 | |
|
9948 | 0 | bfd_vma pltgot_addr = |
9949 | 0 | htab->root.sgotplt->output_section->vma |
9950 | 0 | + htab->root.sgotplt->output_offset; |
9951 | |
|
9952 | 0 | bfd_vma dt_tlsdesc_got = got_addr + htab->root.tlsdesc_got; |
9953 | |
|
9954 | 0 | bfd_byte *plt_entry = |
9955 | 0 | htab->root.splt->contents + htab->root.tlsdesc_plt; |
9956 | | |
9957 | | /* First instruction in BTI enabled PLT stub is a BTI |
9958 | | instruction so skip it. */ |
9959 | 0 | if (type & PLT_BTI) |
9960 | 0 | { |
9961 | 0 | plt_entry = plt_entry + 4; |
9962 | 0 | adrp1_addr = adrp1_addr + 4; |
9963 | 0 | adrp2_addr = adrp2_addr + 4; |
9964 | 0 | } |
9965 | | |
9966 | | /* adrp x2, DT_TLSDESC_GOT */ |
9967 | 0 | elf_aarch64_update_plt_entry (output_bfd, |
9968 | 0 | BFD_RELOC_AARCH64_ADR_HI21_PCREL, |
9969 | 0 | plt_entry + 4, |
9970 | 0 | (PG (dt_tlsdesc_got) |
9971 | 0 | - PG (adrp1_addr))); |
9972 | | |
9973 | | /* adrp x3, 0 */ |
9974 | 0 | elf_aarch64_update_plt_entry (output_bfd, |
9975 | 0 | BFD_RELOC_AARCH64_ADR_HI21_PCREL, |
9976 | 0 | plt_entry + 8, |
9977 | 0 | (PG (pltgot_addr) |
9978 | 0 | - PG (adrp2_addr))); |
9979 | | |
9980 | | /* ldr x2, [x2, #0] */ |
9981 | 0 | elf_aarch64_update_plt_entry (output_bfd, |
9982 | 0 | BFD_RELOC_AARCH64_LDST64_LO12, |
9983 | 0 | plt_entry + 12, |
9984 | 0 | PG_OFFSET (dt_tlsdesc_got)); |
9985 | | |
9986 | | /* add x3, x3, 0 */ |
9987 | 0 | elf_aarch64_update_plt_entry (output_bfd, |
9988 | 0 | BFD_RELOC_AARCH64_ADD_LO12, |
9989 | 0 | plt_entry + 16, |
9990 | 0 | PG_OFFSET (pltgot_addr)); |
9991 | 0 | } |
9992 | 0 | } |
9993 | 0 | } |
9994 | |
|
9995 | 0 | if (htab->root.sgotplt) |
9996 | 0 | { |
9997 | 0 | if (bfd_is_abs_section (htab->root.sgotplt->output_section)) |
9998 | 0 | { |
9999 | 0 | _bfd_error_handler |
10000 | 0 | (_("discarded output section: `%pA'"), htab->root.sgotplt); |
10001 | 0 | return false; |
10002 | 0 | } |
10003 | | |
10004 | | /* Fill in the first three entries in the global offset table. */ |
10005 | 0 | if (htab->root.sgotplt->size > 0) |
10006 | 0 | { |
10007 | 0 | bfd_put_64 (output_bfd, (bfd_vma) 0, htab->root.sgotplt->contents); |
10008 | | |
10009 | | /* Write GOT[1] and GOT[2], needed for the dynamic linker. */ |
10010 | 0 | bfd_put_64 (output_bfd, |
10011 | 0 | (bfd_vma) 0, |
10012 | 0 | htab->root.sgotplt->contents + GOT_ENTRY_SIZE); |
10013 | 0 | bfd_put_64 (output_bfd, |
10014 | 0 | (bfd_vma) 0, |
10015 | 0 | htab->root.sgotplt->contents + GOT_ENTRY_SIZE * 2); |
10016 | 0 | } |
10017 | |
|
10018 | 0 | if (htab->root.sgot) |
10019 | 0 | { |
10020 | 0 | if (htab->root.sgot->size > 0) |
10021 | 0 | { |
10022 | 0 | bfd_vma addr = |
10023 | 0 | sdyn ? sdyn->output_section->vma + sdyn->output_offset : 0; |
10024 | 0 | bfd_put_64 (output_bfd, addr, htab->root.sgot->contents); |
10025 | 0 | } |
10026 | 0 | } |
10027 | |
|
10028 | 0 | elf_section_data (htab->root.sgotplt->output_section)-> |
10029 | 0 | this_hdr.sh_entsize = GOT_ENTRY_SIZE; |
10030 | 0 | } |
10031 | | |
10032 | 0 | if (htab->root.sgot && htab->root.sgot->size > 0) |
10033 | 0 | elf_section_data (htab->root.sgot->output_section)->this_hdr.sh_entsize |
10034 | 0 | = GOT_ENTRY_SIZE; |
10035 | | |
10036 | | /* Fill PLT and GOT entries for local STT_GNU_IFUNC symbols. */ |
10037 | 0 | htab_traverse (htab->loc_hash_table, |
10038 | 0 | elf64_aarch64_finish_local_dynamic_symbol, |
10039 | 0 | info); |
10040 | |
|
10041 | 0 | return true; |
10042 | 0 | } |
10043 | | |
10044 | | /* Check if BTI enabled PLTs are needed. Returns the type needed. */ |
10045 | | static aarch64_plt_type |
10046 | | get_plt_type (bfd *abfd) |
10047 | 0 | { |
10048 | 0 | aarch64_plt_type ret = PLT_NORMAL; |
10049 | 0 | bfd_byte *contents, *extdyn, *extdynend; |
10050 | 0 | asection *sec = bfd_get_section_by_name (abfd, ".dynamic"); |
10051 | 0 | if (!sec |
10052 | 0 | || (sec->flags & SEC_HAS_CONTENTS) == 0 |
10053 | 0 | || sec->size < sizeof (Elf64_External_Dyn) |
10054 | 0 | || !bfd_malloc_and_get_section (abfd, sec, &contents)) |
10055 | 0 | return ret; |
10056 | 0 | extdyn = contents; |
10057 | 0 | extdynend = contents + sec->size - sizeof (Elf64_External_Dyn); |
10058 | 0 | for (; extdyn <= extdynend; extdyn += sizeof (Elf64_External_Dyn)) |
10059 | 0 | { |
10060 | 0 | Elf_Internal_Dyn dyn; |
10061 | 0 | bfd_elf64_swap_dyn_in (abfd, extdyn, &dyn); |
10062 | | |
10063 | | /* Let's check the processor specific dynamic array tags. */ |
10064 | 0 | bfd_vma tag = dyn.d_tag; |
10065 | 0 | if (tag < DT_LOPROC || tag > DT_HIPROC) |
10066 | 0 | continue; |
10067 | | |
10068 | 0 | switch (tag) |
10069 | 0 | { |
10070 | 0 | case DT_AARCH64_BTI_PLT: |
10071 | 0 | ret |= PLT_BTI; |
10072 | 0 | break; |
10073 | | |
10074 | 0 | case DT_AARCH64_PAC_PLT: |
10075 | 0 | ret |= PLT_PAC; |
10076 | 0 | break; |
10077 | | |
10078 | 0 | default: break; |
10079 | 0 | } |
10080 | 0 | } |
10081 | 0 | free (contents); |
10082 | 0 | return ret; |
10083 | 0 | } |
10084 | | |
10085 | | static long |
10086 | | elf64_aarch64_get_synthetic_symtab (bfd *abfd, |
10087 | | long symcount, |
10088 | | asymbol **syms, |
10089 | | long dynsymcount, |
10090 | | asymbol **dynsyms, |
10091 | | asymbol **ret) |
10092 | 0 | { |
10093 | 0 | elf_aarch64_tdata (abfd)->plt_type = get_plt_type (abfd); |
10094 | 0 | return _bfd_elf_get_synthetic_symtab (abfd, symcount, syms, |
10095 | 0 | dynsymcount, dynsyms, ret); |
10096 | 0 | } |
10097 | | |
10098 | | /* Return address for Ith PLT stub in section PLT, for relocation REL |
10099 | | or (bfd_vma) -1 if it should not be included. */ |
10100 | | |
10101 | | static bfd_vma |
10102 | | elf64_aarch64_plt_sym_val (bfd_vma i, const asection *plt, |
10103 | | const arelent *rel ATTRIBUTE_UNUSED) |
10104 | 0 | { |
10105 | 0 | size_t plt0_size = PLT_ENTRY_SIZE; |
10106 | 0 | size_t pltn_size = PLT_SMALL_ENTRY_SIZE; |
10107 | |
|
10108 | 0 | if (elf_aarch64_tdata (plt->owner)->plt_type == PLT_BTI_PAC) |
10109 | 0 | { |
10110 | 0 | if (elf_elfheader (plt->owner)->e_type == ET_EXEC) |
10111 | 0 | pltn_size = PLT_BTI_PAC_SMALL_ENTRY_SIZE; |
10112 | 0 | else |
10113 | 0 | pltn_size = PLT_PAC_SMALL_ENTRY_SIZE; |
10114 | 0 | } |
10115 | 0 | else if (elf_aarch64_tdata (plt->owner)->plt_type == PLT_BTI) |
10116 | 0 | { |
10117 | 0 | if (elf_elfheader (plt->owner)->e_type == ET_EXEC) |
10118 | 0 | pltn_size = PLT_BTI_SMALL_ENTRY_SIZE; |
10119 | 0 | } |
10120 | 0 | else if (elf_aarch64_tdata (plt->owner)->plt_type == PLT_PAC) |
10121 | 0 | { |
10122 | 0 | pltn_size = PLT_PAC_SMALL_ENTRY_SIZE; |
10123 | 0 | } |
10124 | |
|
10125 | 0 | return plt->vma + plt0_size + i * pltn_size; |
10126 | 0 | } |
10127 | | |
10128 | | /* Returns TRUE if NAME is an AArch64 mapping symbol. |
10129 | | The ARM ELF standard defines $x (for A64 code) and $d (for data). |
10130 | | It also allows a period initiated suffix to be added to the symbol, ie: |
10131 | | "$[adtx]\.[:sym_char]+". */ |
10132 | | |
10133 | | static bool |
10134 | | is_aarch64_mapping_symbol (const char * name) |
10135 | 151 | { |
10136 | | return name != NULL /* Paranoia. */ |
10137 | 151 | && name[0] == '$' /* Note: if objcopy --prefix-symbols has been used then |
10138 | | the mapping symbols could have acquired a prefix. |
10139 | | We do not support this here, since such symbols no |
10140 | | longer conform to the ARM ELF ABI. */ |
10141 | 151 | && (name[1] == 'd' || name[1] == 'x') |
10142 | 151 | && (name[2] == 0 || name[2] == '.'); |
10143 | | /* FIXME: Strictly speaking the symbol is only a valid mapping symbol if |
10144 | | any characters that follow the period are legal characters for the body |
10145 | | of a symbol's name. For now we just assume that this is the case. */ |
10146 | 151 | } |
10147 | | |
10148 | | /* Make sure that mapping symbols in object files are not removed via the |
10149 | | "strip --strip-unneeded" tool. These symbols might needed in order to |
10150 | | correctly generate linked files. Once an object file has been linked, |
10151 | | it should be safe to remove them. */ |
10152 | | |
10153 | | static void |
10154 | | elf64_aarch64_backend_symbol_processing (bfd *abfd, asymbol *sym) |
10155 | 2.48k | { |
10156 | 2.48k | if (((abfd->flags & (EXEC_P | DYNAMIC)) == 0) |
10157 | 2.48k | && sym->section != bfd_abs_section_ptr |
10158 | 2.48k | && is_aarch64_mapping_symbol (sym->name)) |
10159 | 2 | sym->flags |= BSF_KEEP; |
10160 | 2.48k | } |
10161 | | |
10162 | | /* Implement elf_backend_setup_gnu_properties for AArch64. It serves as a |
10163 | | wrapper function for _bfd_aarch64_elf_link_setup_gnu_properties to account |
10164 | | for the effect of GNU properties of the output_bfd. */ |
10165 | | static bfd * |
10166 | | elf64_aarch64_link_setup_gnu_properties (struct bfd_link_info *info) |
10167 | 0 | { |
10168 | 0 | uint32_t prop = elf_aarch64_tdata (info->output_bfd)->gnu_and_prop; |
10169 | 0 | bfd *pbfd = _bfd_aarch64_elf_link_setup_gnu_properties (info, &prop); |
10170 | 0 | elf_aarch64_tdata (info->output_bfd)->gnu_and_prop = prop; |
10171 | 0 | elf_aarch64_tdata (info->output_bfd)->plt_type |
10172 | 0 | |= (prop & GNU_PROPERTY_AARCH64_FEATURE_1_BTI) ? PLT_BTI : 0; |
10173 | 0 | setup_plt_values (info, elf_aarch64_tdata (info->output_bfd)->plt_type); |
10174 | 0 | return pbfd; |
10175 | 0 | } |
10176 | | |
10177 | | /* Implement elf_backend_merge_gnu_properties for AArch64. It serves as a |
10178 | | wrapper function for _bfd_aarch64_elf_merge_gnu_properties to account |
10179 | | for the effect of GNU properties of the output_bfd. */ |
10180 | | static bool |
10181 | | elf64_aarch64_merge_gnu_properties (struct bfd_link_info *info, |
10182 | | bfd *abfd, bfd *bbfd, |
10183 | | elf_property *aprop, |
10184 | | elf_property *bprop) |
10185 | 0 | { |
10186 | 0 | uint32_t prop |
10187 | 0 | = elf_aarch64_tdata (info->output_bfd)->gnu_and_prop; |
10188 | | |
10189 | | /* If output has been marked with BTI using command line argument, give out |
10190 | | warning if necessary. */ |
10191 | | /* Properties are merged per type, hence only check for warnings when merging |
10192 | | GNU_PROPERTY_AARCH64_FEATURE_1_AND. */ |
10193 | 0 | if (((aprop && aprop->pr_type == GNU_PROPERTY_AARCH64_FEATURE_1_AND) |
10194 | 0 | || (bprop && bprop->pr_type == GNU_PROPERTY_AARCH64_FEATURE_1_AND)) |
10195 | 0 | && (prop & GNU_PROPERTY_AARCH64_FEATURE_1_BTI) |
10196 | 0 | && (!elf_aarch64_tdata (info->output_bfd)->no_bti_warn)) |
10197 | 0 | { |
10198 | 0 | if ((aprop && !(aprop->u.number & GNU_PROPERTY_AARCH64_FEATURE_1_BTI)) |
10199 | 0 | || !aprop) |
10200 | 0 | { |
10201 | 0 | _bfd_error_handler (_("%pB: warning: BTI turned on by -z force-bti when " |
10202 | 0 | "all inputs do not have BTI in NOTE section."), |
10203 | 0 | abfd); |
10204 | 0 | } |
10205 | 0 | if ((bprop && !(bprop->u.number & GNU_PROPERTY_AARCH64_FEATURE_1_BTI)) |
10206 | 0 | || !bprop) |
10207 | 0 | { |
10208 | 0 | _bfd_error_handler (_("%pB: warning: BTI turned on by -z force-bti when " |
10209 | 0 | "all inputs do not have BTI in NOTE section."), |
10210 | 0 | bbfd); |
10211 | 0 | } |
10212 | 0 | } |
10213 | |
|
10214 | 0 | return _bfd_aarch64_elf_merge_gnu_properties (info, abfd, aprop, |
10215 | 0 | bprop, prop); |
10216 | 0 | } |
10217 | | |
10218 | | /* We use this so we can override certain functions |
10219 | | (though currently we don't). */ |
10220 | | |
10221 | | const struct elf_size_info elf64_aarch64_size_info = |
10222 | | { |
10223 | | sizeof (Elf64_External_Ehdr), |
10224 | | sizeof (Elf64_External_Phdr), |
10225 | | sizeof (Elf64_External_Shdr), |
10226 | | sizeof (Elf64_External_Rel), |
10227 | | sizeof (Elf64_External_Rela), |
10228 | | sizeof (Elf64_External_Sym), |
10229 | | sizeof (Elf64_External_Dyn), |
10230 | | sizeof (Elf_External_Note), |
10231 | | 4, /* Hash table entry size. */ |
10232 | | 1, /* Internal relocs per external relocs. */ |
10233 | | ARCH_SIZE, /* Arch size. */ |
10234 | | LOG_FILE_ALIGN, /* Log_file_align. */ |
10235 | | ELFCLASS64, EV_CURRENT, |
10236 | | bfd_elf64_write_out_phdrs, |
10237 | | bfd_elf64_write_shdrs_and_ehdr, |
10238 | | bfd_elf64_checksum_contents, |
10239 | | bfd_elf64_write_relocs, |
10240 | | bfd_elf64_swap_symbol_in, |
10241 | | bfd_elf64_swap_symbol_out, |
10242 | | bfd_elf64_slurp_reloc_table, |
10243 | | bfd_elf64_slurp_symbol_table, |
10244 | | bfd_elf64_swap_dyn_in, |
10245 | | bfd_elf64_swap_dyn_out, |
10246 | | bfd_elf64_swap_reloc_in, |
10247 | | bfd_elf64_swap_reloc_out, |
10248 | | bfd_elf64_swap_reloca_in, |
10249 | | bfd_elf64_swap_reloca_out |
10250 | | }; |
10251 | | |
10252 | | #define ELF_ARCH bfd_arch_aarch64 |
10253 | | #define ELF_MACHINE_CODE EM_AARCH64 |
10254 | | #define ELF_MAXPAGESIZE 0x10000 |
10255 | | #define ELF_COMMONPAGESIZE 0x1000 |
10256 | | |
10257 | | #define bfd_elf64_bfd_free_cached_info \ |
10258 | | elf64_aarch64_bfd_free_cached_info |
10259 | | |
10260 | | #define bfd_elf64_bfd_is_target_special_symbol \ |
10261 | | elf64_aarch64_is_target_special_symbol |
10262 | | |
10263 | | #define bfd_elf64_bfd_link_hash_table_create \ |
10264 | | elf64_aarch64_link_hash_table_create |
10265 | | |
10266 | | #define bfd_elf64_bfd_merge_private_bfd_data \ |
10267 | | elf64_aarch64_merge_private_bfd_data |
10268 | | |
10269 | | #define bfd_elf64_bfd_print_private_bfd_data \ |
10270 | | elf64_aarch64_print_private_bfd_data |
10271 | | |
10272 | | #define bfd_elf64_bfd_reloc_type_lookup \ |
10273 | | elf64_aarch64_reloc_type_lookup |
10274 | | |
10275 | | #define bfd_elf64_bfd_reloc_name_lookup \ |
10276 | | elf64_aarch64_reloc_name_lookup |
10277 | | |
10278 | | #define bfd_elf64_bfd_set_private_flags \ |
10279 | | elf64_aarch64_set_private_flags |
10280 | | |
10281 | | #define bfd_elf64_find_inliner_info \ |
10282 | | elf64_aarch64_find_inliner_info |
10283 | | |
10284 | | #define bfd_elf64_get_synthetic_symtab \ |
10285 | | elf64_aarch64_get_synthetic_symtab |
10286 | | |
10287 | | #define bfd_elf64_mkobject \ |
10288 | | elf64_aarch64_mkobject |
10289 | | |
10290 | | #define bfd_elf64_new_section_hook \ |
10291 | | elf64_aarch64_new_section_hook |
10292 | | |
10293 | | #define elf_backend_adjust_dynamic_symbol \ |
10294 | | elf64_aarch64_adjust_dynamic_symbol |
10295 | | |
10296 | | #define elf_backend_always_size_sections \ |
10297 | | elf64_aarch64_always_size_sections |
10298 | | |
10299 | | #define elf_backend_check_relocs \ |
10300 | | elf64_aarch64_check_relocs |
10301 | | |
10302 | | #define elf_backend_copy_indirect_symbol \ |
10303 | | elf64_aarch64_copy_indirect_symbol |
10304 | | |
10305 | | #define elf_backend_merge_symbol_attribute \ |
10306 | | elf64_aarch64_merge_symbol_attribute |
10307 | | |
10308 | | /* Create .dynbss, and .rela.bss sections in DYNOBJ, and set up shortcuts |
10309 | | to them in our hash. */ |
10310 | | #define elf_backend_create_dynamic_sections \ |
10311 | | elf64_aarch64_create_dynamic_sections |
10312 | | |
10313 | | #define elf_backend_init_index_section \ |
10314 | | _bfd_elf_init_2_index_sections |
10315 | | |
10316 | | #define elf_backend_finish_dynamic_sections \ |
10317 | | elf64_aarch64_finish_dynamic_sections |
10318 | | |
10319 | | #define elf_backend_finish_dynamic_symbol \ |
10320 | | elf64_aarch64_finish_dynamic_symbol |
10321 | | |
10322 | | #define elf_backend_object_p \ |
10323 | | elf64_aarch64_object_p |
10324 | | |
10325 | | #define elf_backend_output_arch_local_syms \ |
10326 | | elf64_aarch64_output_arch_local_syms |
10327 | | |
10328 | | #define elf_backend_maybe_function_sym \ |
10329 | | elf64_aarch64_maybe_function_sym |
10330 | | |
10331 | | #define elf_backend_plt_sym_val \ |
10332 | | elf64_aarch64_plt_sym_val |
10333 | | |
10334 | | #define elf_backend_init_file_header \ |
10335 | | elf64_aarch64_init_file_header |
10336 | | |
10337 | | #define elf_backend_relocate_section \ |
10338 | | elf64_aarch64_relocate_section |
10339 | | |
10340 | | #define elf_backend_reloc_type_class \ |
10341 | | elf64_aarch64_reloc_type_class |
10342 | | |
10343 | | #define elf_backend_section_from_shdr \ |
10344 | | elf64_aarch64_section_from_shdr |
10345 | | |
10346 | | #define elf_backend_section_from_phdr \ |
10347 | | elf64_aarch64_section_from_phdr |
10348 | | |
10349 | | #define elf_backend_modify_headers \ |
10350 | | elf64_aarch64_modify_headers |
10351 | | |
10352 | | #define elf_backend_size_dynamic_sections \ |
10353 | | elf64_aarch64_size_dynamic_sections |
10354 | | |
10355 | | #define elf_backend_size_info \ |
10356 | | elf64_aarch64_size_info |
10357 | | |
10358 | | #define elf_backend_write_section \ |
10359 | | elf64_aarch64_write_section |
10360 | | |
10361 | | #define elf_backend_symbol_processing \ |
10362 | | elf64_aarch64_backend_symbol_processing |
10363 | | |
10364 | | #define elf_backend_setup_gnu_properties \ |
10365 | | elf64_aarch64_link_setup_gnu_properties |
10366 | | |
10367 | | #define elf_backend_merge_gnu_properties \ |
10368 | | elf64_aarch64_merge_gnu_properties |
10369 | | |
10370 | | #define elf_backend_can_refcount 1 |
10371 | | #define elf_backend_can_gc_sections 1 |
10372 | | #define elf_backend_plt_readonly 1 |
10373 | | #define elf_backend_want_got_plt 1 |
10374 | | #define elf_backend_want_plt_sym 0 |
10375 | | #define elf_backend_want_dynrelro 1 |
10376 | | #define elf_backend_may_use_rel_p 0 |
10377 | | #define elf_backend_may_use_rela_p 1 |
10378 | | #define elf_backend_default_use_rela_p 1 |
10379 | | #define elf_backend_rela_normal 1 |
10380 | | #define elf_backend_dtrel_excludes_plt 1 |
10381 | | #define elf_backend_got_header_size (GOT_ENTRY_SIZE * 3) |
10382 | | #define elf_backend_default_execstack 0 |
10383 | | #define elf_backend_extern_protected_data 0 |
10384 | | #define elf_backend_hash_symbol elf_aarch64_hash_symbol |
10385 | | |
10386 | | #undef elf_backend_obj_attrs_section |
10387 | | #define elf_backend_obj_attrs_section ".ARM.attributes" |
10388 | | |
10389 | | #include "elf64-target.h" |
10390 | | |
10391 | | /* CloudABI support. */ |
10392 | | |
10393 | | #undef TARGET_LITTLE_SYM |
10394 | | #define TARGET_LITTLE_SYM aarch64_elf64_le_cloudabi_vec |
10395 | | #undef TARGET_LITTLE_NAME |
10396 | | #define TARGET_LITTLE_NAME "elf64-littleaarch64-cloudabi" |
10397 | | #undef TARGET_BIG_SYM |
10398 | | #define TARGET_BIG_SYM aarch64_elf64_be_cloudabi_vec |
10399 | | #undef TARGET_BIG_NAME |
10400 | | #define TARGET_BIG_NAME "elf64-bigaarch64-cloudabi" |
10401 | | |
10402 | | #undef ELF_OSABI |
10403 | | #define ELF_OSABI ELFOSABI_CLOUDABI |
10404 | | |
10405 | | #undef elf64_bed |
10406 | | #define elf64_bed elf64_aarch64_cloudabi_bed |
10407 | | |
10408 | | #include "elf64-target.h" |