/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-2025 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_late_size_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 | 606 | #define PLT_ENTRY_SIZE (32) |
270 | 606 | #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 | 1 | #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 | 1.10k | { |
2195 | 1.10k | static bool initialized_p = false; |
2196 | | /* Indexed by R_TYPE, values are offsets in the howto_table. */ |
2197 | 1.10k | static unsigned int offsets[R_AARCH64_end]; |
2198 | | |
2199 | 1.10k | if (!initialized_p) |
2200 | 2 | { |
2201 | 2 | unsigned int i; |
2202 | | |
2203 | 230 | for (i = 1; i < ARRAY_SIZE (elf64_aarch64_howto_table) - 1; ++i) |
2204 | 228 | if (elf64_aarch64_howto_table[i].type != 0) |
2205 | 218 | offsets[elf64_aarch64_howto_table[i].type] = i; |
2206 | | |
2207 | 2 | initialized_p = true; |
2208 | 2 | } |
2209 | | |
2210 | 1.10k | if (r_type == R_AARCH64_NONE || r_type == R_AARCH64_NULL) |
2211 | 2 | return BFD_RELOC_AARCH64_NONE; |
2212 | | |
2213 | | /* PR 17512: file: b371e70a. */ |
2214 | 1.10k | if (r_type >= R_AARCH64_end) |
2215 | 451 | { |
2216 | 451 | _bfd_error_handler (_("%pB: unsupported relocation type %#x"), |
2217 | 451 | abfd, r_type); |
2218 | 451 | bfd_set_error (bfd_error_bad_value); |
2219 | 451 | return BFD_RELOC_AARCH64_NONE; |
2220 | 451 | } |
2221 | | |
2222 | 654 | return BFD_RELOC_AARCH64_RELOC_START + offsets[r_type]; |
2223 | 1.10k | } |
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 | 1.10k | { |
2252 | 1.10k | unsigned int i; |
2253 | | |
2254 | | /* Convert bfd generic reloc to AArch64-specific reloc. */ |
2255 | 1.10k | if (code < BFD_RELOC_AARCH64_RELOC_START |
2256 | 1.10k | || 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 | 1.10k | if (code > BFD_RELOC_AARCH64_RELOC_START |
2265 | 1.10k | && code < BFD_RELOC_AARCH64_RELOC_END) |
2266 | 1.09k | if (elf64_aarch64_howto_table[code - BFD_RELOC_AARCH64_RELOC_START].type) |
2267 | 642 | return &elf64_aarch64_howto_table[code - BFD_RELOC_AARCH64_RELOC_START]; |
2268 | | |
2269 | 465 | if (code == BFD_RELOC_AARCH64_NONE) |
2270 | 453 | return &elf64_aarch64_howto_none; |
2271 | | |
2272 | 12 | if (code == BFD_RELOC_AARCH64_BRANCH9) |
2273 | 0 | return &elf64_aarch64_howto_none; |
2274 | | |
2275 | 12 | return NULL; |
2276 | 12 | } |
2277 | | |
2278 | | static reloc_howto_type * |
2279 | | elf64_aarch64_howto_from_type (bfd *abfd, unsigned int r_type) |
2280 | 1.54k | { |
2281 | 1.54k | bfd_reloc_code_real_type val; |
2282 | 1.54k | reloc_howto_type *howto; |
2283 | | |
2284 | | #if ARCH_SIZE == 32 |
2285 | | if (r_type > 256) |
2286 | | { |
2287 | | bfd_set_error (bfd_error_bad_value); |
2288 | | return NULL; |
2289 | | } |
2290 | | #endif |
2291 | | |
2292 | 1.54k | if (r_type == R_AARCH64_NONE) |
2293 | 442 | return &elf64_aarch64_howto_none; |
2294 | | |
2295 | 1.10k | val = elf64_aarch64_bfd_reloc_from_type (abfd, r_type); |
2296 | 1.10k | howto = elf64_aarch64_howto_from_bfd_reloc (val); |
2297 | | |
2298 | 1.10k | if (howto != NULL) |
2299 | 1.09k | return howto; |
2300 | | |
2301 | 12 | bfd_set_error (bfd_error_bad_value); |
2302 | 12 | return NULL; |
2303 | 1.10k | } |
2304 | | |
2305 | | static bool |
2306 | | elf64_aarch64_info_to_howto (bfd *abfd, arelent *bfd_reloc, |
2307 | | Elf_Internal_Rela *elf_reloc) |
2308 | 1.54k | { |
2309 | 1.54k | unsigned int r_type; |
2310 | | |
2311 | 1.54k | r_type = ELF64_R_TYPE (elf_reloc->r_info); |
2312 | 1.54k | bfd_reloc->howto = elf64_aarch64_howto_from_type (abfd, r_type); |
2313 | | |
2314 | 1.54k | if (bfd_reloc->howto == NULL) |
2315 | 12 | { |
2316 | | /* xgettext:c-format */ |
2317 | 12 | _bfd_error_handler (_("%pB: unsupported relocation type %#x"), abfd, r_type); |
2318 | 12 | return false; |
2319 | 12 | } |
2320 | 1.53k | return true; |
2321 | 1.54k | } |
2322 | | |
2323 | | static reloc_howto_type * |
2324 | | elf64_aarch64_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED, |
2325 | | bfd_reloc_code_real_type code) |
2326 | 0 | { |
2327 | 0 | reloc_howto_type *howto = elf64_aarch64_howto_from_bfd_reloc (code); |
2328 | |
|
2329 | 0 | if (howto != NULL) |
2330 | 0 | return howto; |
2331 | | |
2332 | 0 | bfd_set_error (bfd_error_bad_value); |
2333 | 0 | return NULL; |
2334 | 0 | } |
2335 | | |
2336 | | static reloc_howto_type * |
2337 | | elf64_aarch64_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED, |
2338 | | const char *r_name) |
2339 | 0 | { |
2340 | 0 | unsigned int i; |
2341 | |
|
2342 | 0 | for (i = 1; i < ARRAY_SIZE (elf64_aarch64_howto_table) - 1; ++i) |
2343 | 0 | if (elf64_aarch64_howto_table[i].name != NULL |
2344 | 0 | && strcasecmp (elf64_aarch64_howto_table[i].name, r_name) == 0) |
2345 | 0 | return &elf64_aarch64_howto_table[i]; |
2346 | | |
2347 | 0 | return NULL; |
2348 | 0 | } |
2349 | | |
2350 | | #define TARGET_LITTLE_SYM aarch64_elf64_le_vec |
2351 | | #define TARGET_LITTLE_NAME "elf64-littleaarch64" |
2352 | | #define TARGET_BIG_SYM aarch64_elf64_be_vec |
2353 | | #define TARGET_BIG_NAME "elf64-bigaarch64" |
2354 | | |
2355 | | /* The linker script knows the section names for placement. |
2356 | | The entry_names are used to do simple name mangling on the stubs. |
2357 | | Given a function name, and its type, the stub can be found. The |
2358 | | name can be changed. The only requirement is the %s be present. */ |
2359 | 0 | #define STUB_ENTRY_NAME "__%s_veneer" |
2360 | | |
2361 | | /* Stub name for a BTI landing stub. */ |
2362 | 0 | #define BTI_STUB_ENTRY_NAME "__%s_bti_veneer" |
2363 | | |
2364 | | /* The name of the dynamic interpreter. This is put in the .interp |
2365 | | section. */ |
2366 | 0 | #define ELF_DYNAMIC_INTERPRETER "/lib/ld.so.1" |
2367 | | |
2368 | | #define AARCH64_MAX_FWD_BRANCH_OFFSET \ |
2369 | 0 | (((1 << 25) - 1) << 2) |
2370 | | #define AARCH64_MAX_BWD_BRANCH_OFFSET \ |
2371 | 0 | (-((1 << 25) << 2)) |
2372 | | |
2373 | 0 | #define AARCH64_MAX_ADRP_IMM ((1 << 20) - 1) |
2374 | 0 | #define AARCH64_MIN_ADRP_IMM (-(1 << 20)) |
2375 | | |
2376 | | static int |
2377 | | aarch64_valid_for_adrp_p (bfd_vma value, bfd_vma place) |
2378 | 0 | { |
2379 | 0 | bfd_signed_vma offset = (bfd_signed_vma) (PG (value) - PG (place)) >> 12; |
2380 | 0 | return offset <= AARCH64_MAX_ADRP_IMM && offset >= AARCH64_MIN_ADRP_IMM; |
2381 | 0 | } |
2382 | | |
2383 | | static int |
2384 | | aarch64_valid_branch_p (bfd_vma value, bfd_vma place) |
2385 | 0 | { |
2386 | 0 | bfd_signed_vma offset = (bfd_signed_vma) (value - place); |
2387 | 0 | return (offset <= AARCH64_MAX_FWD_BRANCH_OFFSET |
2388 | 0 | && offset >= AARCH64_MAX_BWD_BRANCH_OFFSET); |
2389 | 0 | } |
2390 | | |
2391 | | static const uint32_t aarch64_adrp_branch_stub [] = |
2392 | | { |
2393 | | 0x90000010, /* adrp ip0, X */ |
2394 | | /* R_AARCH64_ADR_HI21_PCREL(X) */ |
2395 | | 0x91000210, /* add ip0, ip0, :lo12:X */ |
2396 | | /* R_AARCH64_ADD_ABS_LO12_NC(X) */ |
2397 | | 0xd61f0200, /* br ip0 */ |
2398 | | }; |
2399 | | |
2400 | | static const uint32_t aarch64_long_branch_stub[] = |
2401 | | { |
2402 | | #if ARCH_SIZE == 64 |
2403 | | 0x58000090, /* ldr ip0, 1f */ |
2404 | | #else |
2405 | | 0x18000090, /* ldr wip0, 1f */ |
2406 | | #endif |
2407 | | 0x10000011, /* adr ip1, #0 */ |
2408 | | 0x8b110210, /* add ip0, ip0, ip1 */ |
2409 | | 0xd61f0200, /* br ip0 */ |
2410 | | 0x00000000, /* 1: .xword or .word |
2411 | | R_AARCH64_PREL64(X) + 12 |
2412 | | */ |
2413 | | 0x00000000, |
2414 | | }; |
2415 | | |
2416 | | static const uint32_t aarch64_bti_direct_branch_stub[] = |
2417 | | { |
2418 | | 0xd503245f, /* bti c */ |
2419 | | 0x14000000, /* b <label> */ |
2420 | | }; |
2421 | | |
2422 | | static const uint32_t aarch64_erratum_835769_stub[] = |
2423 | | { |
2424 | | 0x00000000, /* Placeholder for multiply accumulate. */ |
2425 | | 0x14000000, /* b <label> */ |
2426 | | }; |
2427 | | |
2428 | | static const uint32_t aarch64_erratum_843419_stub[] = |
2429 | | { |
2430 | | 0x00000000, /* Placeholder for LDR instruction. */ |
2431 | | 0x14000000, /* b <label> */ |
2432 | | }; |
2433 | | |
2434 | | /* Section name for stubs is the associated section name plus this |
2435 | | string. */ |
2436 | 0 | #define STUB_SUFFIX ".stub" |
2437 | | |
2438 | | enum elf_aarch64_stub_type |
2439 | | { |
2440 | | aarch64_stub_none, |
2441 | | aarch64_stub_adrp_branch, |
2442 | | aarch64_stub_long_branch, |
2443 | | aarch64_stub_bti_direct_branch, |
2444 | | aarch64_stub_erratum_835769_veneer, |
2445 | | aarch64_stub_erratum_843419_veneer, |
2446 | | }; |
2447 | | |
2448 | | struct elf_aarch64_stub_hash_entry |
2449 | | { |
2450 | | /* Base hash table entry structure. */ |
2451 | | struct bfd_hash_entry root; |
2452 | | |
2453 | | /* The stub section. */ |
2454 | | asection *stub_sec; |
2455 | | |
2456 | | /* Offset within stub_sec of the beginning of this stub. */ |
2457 | | bfd_vma stub_offset; |
2458 | | |
2459 | | /* Given the symbol's value and its section we can determine its final |
2460 | | value when building the stubs (so the stub knows where to jump). */ |
2461 | | bfd_vma target_value; |
2462 | | asection *target_section; |
2463 | | |
2464 | | enum elf_aarch64_stub_type stub_type; |
2465 | | |
2466 | | /* The symbol table entry, if any, that this was derived from. */ |
2467 | | struct elf_aarch64_link_hash_entry *h; |
2468 | | |
2469 | | /* Destination symbol type */ |
2470 | | unsigned char st_type; |
2471 | | |
2472 | | /* The target is also a stub. */ |
2473 | | bool double_stub; |
2474 | | |
2475 | | /* Where this stub is being called from, or, in the case of combined |
2476 | | stub sections, the first input section in the group. */ |
2477 | | asection *id_sec; |
2478 | | |
2479 | | /* The name for the local symbol at the start of this stub. The |
2480 | | stub name in the hash table has to be unique; this does not, so |
2481 | | it can be friendlier. */ |
2482 | | char *output_name; |
2483 | | |
2484 | | /* The instruction which caused this stub to be generated (only valid for |
2485 | | erratum 835769 workaround stubs at present). */ |
2486 | | uint32_t veneered_insn; |
2487 | | |
2488 | | /* In an erratum 843419 workaround stub, the ADRP instruction offset. */ |
2489 | | bfd_vma adrp_offset; |
2490 | | }; |
2491 | | |
2492 | | /* Used to build a map of a section. This is required for mixed-endian |
2493 | | code/data. */ |
2494 | | |
2495 | | typedef struct elf_elf_section_map |
2496 | | { |
2497 | | bfd_vma vma; |
2498 | | char type; |
2499 | | } |
2500 | | elf_aarch64_section_map; |
2501 | | |
2502 | | |
2503 | | typedef struct _aarch64_elf_section_data |
2504 | | { |
2505 | | struct bfd_elf_section_data elf; |
2506 | | unsigned int mapcount; |
2507 | | unsigned int mapsize; |
2508 | | elf_aarch64_section_map *map; |
2509 | | } |
2510 | | _aarch64_elf_section_data; |
2511 | | |
2512 | | #define elf_aarch64_section_data(sec) \ |
2513 | 0 | ((_aarch64_elf_section_data *) elf_section_data (sec)) |
2514 | | |
2515 | | /* The size of the thread control block which is defined to be two pointers. */ |
2516 | 0 | #define TCB_SIZE (ARCH_SIZE/8)*2 |
2517 | | |
2518 | | struct elf_aarch64_local_symbol |
2519 | | { |
2520 | | unsigned int got_type; |
2521 | | bfd_signed_vma got_refcount; |
2522 | | bfd_vma got_offset; |
2523 | | |
2524 | | /* Offset of the GOTPLT entry reserved for the TLS descriptor. The |
2525 | | offset is from the end of the jump table and reserved entries |
2526 | | within the PLTGOT. |
2527 | | |
2528 | | The magic value (bfd_vma) -1 indicates that an offset has not be |
2529 | | allocated. */ |
2530 | | bfd_vma tlsdesc_got_jump_table_offset; |
2531 | | }; |
2532 | | |
2533 | 0 | #define elf_aarch64_locals(bfd) (elf_aarch64_tdata (bfd)->locals) |
2534 | | |
2535 | | #define is_aarch64_elf(bfd) \ |
2536 | 0 | (bfd_get_flavour (bfd) == bfd_target_elf_flavour \ |
2537 | 0 | && elf_tdata (bfd) != NULL \ |
2538 | 0 | && elf_object_id (bfd) == AARCH64_ELF_DATA) |
2539 | | |
2540 | | static bool |
2541 | | elf64_aarch64_mkobject (bfd *abfd) |
2542 | 564k | { |
2543 | 564k | return bfd_elf_allocate_object (abfd, sizeof (struct elf_aarch64_obj_tdata)); |
2544 | 564k | } |
2545 | | |
2546 | | #define elf_aarch64_hash_entry(ent) \ |
2547 | 0 | ((struct elf_aarch64_link_hash_entry *)(ent)) |
2548 | | |
2549 | 0 | #define GOT_UNKNOWN 0 |
2550 | 0 | #define GOT_NORMAL 1 |
2551 | 0 | #define GOT_TLS_GD 2 |
2552 | 0 | #define GOT_TLS_IE 4 |
2553 | 0 | #define GOT_TLSDESC_GD 8 |
2554 | | |
2555 | 0 | #define GOT_TLS_GD_ANY_P(type) ((type & GOT_TLS_GD) || (type & GOT_TLSDESC_GD)) |
2556 | | |
2557 | | /* AArch64 ELF linker hash entry. */ |
2558 | | struct elf_aarch64_link_hash_entry |
2559 | | { |
2560 | | struct elf_link_hash_entry root; |
2561 | | |
2562 | | /* Since PLT entries have variable size, we need to record the |
2563 | | index into .got.plt instead of recomputing it from the PLT |
2564 | | offset. */ |
2565 | | bfd_signed_vma plt_got_offset; |
2566 | | |
2567 | | /* Bit mask representing the type of GOT entry(s) if any required by |
2568 | | this symbol. */ |
2569 | | unsigned int got_type; |
2570 | | |
2571 | | /* TRUE if symbol is defined as a protected symbol. */ |
2572 | | unsigned int def_protected : 1; |
2573 | | |
2574 | | /* A pointer to the most recently used stub hash entry against this |
2575 | | symbol. */ |
2576 | | struct elf_aarch64_stub_hash_entry *stub_cache; |
2577 | | |
2578 | | /* Offset of the GOTPLT entry reserved for the TLS descriptor. The offset |
2579 | | is from the end of the jump table and reserved entries within the PLTGOT. |
2580 | | |
2581 | | The magic value (bfd_vma) -1 indicates that an offset has not |
2582 | | be allocated. */ |
2583 | | bfd_vma tlsdesc_got_jump_table_offset; |
2584 | | }; |
2585 | | |
2586 | | static unsigned int |
2587 | | elf64_aarch64_symbol_got_type (struct elf_link_hash_entry *h, |
2588 | | bfd *abfd, |
2589 | | unsigned long r_symndx) |
2590 | 0 | { |
2591 | 0 | if (h) |
2592 | 0 | return elf_aarch64_hash_entry (h)->got_type; |
2593 | | |
2594 | 0 | if (! elf_aarch64_locals (abfd)) |
2595 | 0 | return GOT_UNKNOWN; |
2596 | | |
2597 | 0 | return elf_aarch64_locals (abfd)[r_symndx].got_type; |
2598 | 0 | } |
2599 | | |
2600 | | /* Get the AArch64 elf linker hash table from a link_info structure. */ |
2601 | | #define elf_aarch64_hash_table(info) \ |
2602 | 0 | ((struct elf_aarch64_link_hash_table *) ((info)->hash)) |
2603 | | |
2604 | | #define aarch64_stub_hash_lookup(table, string, create, copy) \ |
2605 | 0 | ((struct elf_aarch64_stub_hash_entry *) \ |
2606 | 0 | bfd_hash_lookup ((table), (string), (create), (copy))) |
2607 | | |
2608 | | /* AArch64 ELF linker hash table. */ |
2609 | | struct elf_aarch64_link_hash_table |
2610 | | { |
2611 | | /* The main hash table. */ |
2612 | | struct elf_link_hash_table root; |
2613 | | |
2614 | | /* Nonzero to force PIC branch veneers. */ |
2615 | | int pic_veneer; |
2616 | | |
2617 | | /* Fix erratum 835769. */ |
2618 | | int fix_erratum_835769; |
2619 | | |
2620 | | /* Fix erratum 843419. */ |
2621 | | erratum_84319_opts fix_erratum_843419; |
2622 | | |
2623 | | /* Don't apply link-time values for dynamic relocations. */ |
2624 | | int no_apply_dynamic_relocs; |
2625 | | |
2626 | | /* The number of bytes in the initial entry in the PLT. */ |
2627 | | bfd_size_type plt_header_size; |
2628 | | |
2629 | | /* The bytes of the initial PLT entry. */ |
2630 | | const bfd_byte *plt0_entry; |
2631 | | |
2632 | | /* The number of bytes in the subsequent PLT entries. */ |
2633 | | bfd_size_type plt_entry_size; |
2634 | | |
2635 | | /* The bytes of the subsequent PLT entry. */ |
2636 | | const bfd_byte *plt_entry; |
2637 | | |
2638 | | /* PLT entries have a common shape, but may have some pre-amble |
2639 | | instructions (such as BTI). This delta is used to factor this |
2640 | | out of the common code. */ |
2641 | | int plt_entry_delta; |
2642 | | |
2643 | | /* For convenience in allocate_dynrelocs. */ |
2644 | | bfd *obfd; |
2645 | | |
2646 | | /* The amount of space used by the reserved portion of the sgotplt |
2647 | | section, plus whatever space is used by the jump slots. */ |
2648 | | bfd_vma sgotplt_jump_table_size; |
2649 | | |
2650 | | /* The stub hash table. */ |
2651 | | struct bfd_hash_table stub_hash_table; |
2652 | | |
2653 | | /* Linker stub bfd. */ |
2654 | | bfd *stub_bfd; |
2655 | | |
2656 | | /* Linker call-backs. */ |
2657 | | asection *(*add_stub_section) (const char *, asection *); |
2658 | | void (*layout_sections_again) (void); |
2659 | | |
2660 | | /* Array to keep track of which stub sections have been created, and |
2661 | | information on stub grouping. */ |
2662 | | struct map_stub |
2663 | | { |
2664 | | /* This is the section to which stubs in the group will be |
2665 | | attached. */ |
2666 | | asection *link_sec; |
2667 | | /* The stub section. */ |
2668 | | asection *stub_sec; |
2669 | | } *stub_group; |
2670 | | |
2671 | | /* Assorted information used by elf64_aarch64_size_stubs. */ |
2672 | | unsigned int bfd_count; |
2673 | | unsigned int top_index; |
2674 | | asection **input_list; |
2675 | | |
2676 | | /* True when two stubs are added where one targets the other, happens |
2677 | | when BTI stubs are inserted and then the stub layout must not change |
2678 | | during elf64_aarch64_build_stubs. */ |
2679 | | bool has_double_stub; |
2680 | | |
2681 | | /* JUMP_SLOT relocs for variant PCS symbols may be present. */ |
2682 | | int variant_pcs; |
2683 | | |
2684 | | /* The number of bytes in the PLT enty for the TLS descriptor. */ |
2685 | | bfd_size_type tlsdesc_plt_entry_size; |
2686 | | |
2687 | | /* Used by local STT_GNU_IFUNC symbols. */ |
2688 | | htab_t loc_hash_table; |
2689 | | void * loc_hash_memory; |
2690 | | |
2691 | | /* Array of relative relocs to be emitted in DT_RELR format. */ |
2692 | | bfd_size_type relr_alloc; |
2693 | | bfd_size_type relr_count; |
2694 | | struct relr_entry |
2695 | | { |
2696 | | asection *sec; |
2697 | | bfd_vma off; |
2698 | | } *relr; |
2699 | | /* Sorted output addresses of above relative relocs. */ |
2700 | | bfd_vma *relr_sorted; |
2701 | | /* Layout recomputation count. */ |
2702 | | bfd_size_type relr_layout_iter; |
2703 | | }; |
2704 | | |
2705 | | /* Create an entry in an AArch64 ELF linker hash table. */ |
2706 | | |
2707 | | static struct bfd_hash_entry * |
2708 | | elf64_aarch64_link_hash_newfunc (struct bfd_hash_entry *entry, |
2709 | | struct bfd_hash_table *table, |
2710 | | const char *string) |
2711 | 0 | { |
2712 | 0 | struct elf_aarch64_link_hash_entry *ret = |
2713 | 0 | (struct elf_aarch64_link_hash_entry *) entry; |
2714 | | |
2715 | | /* Allocate the structure if it has not already been allocated by a |
2716 | | subclass. */ |
2717 | 0 | if (ret == NULL) |
2718 | 0 | ret = bfd_hash_allocate (table, |
2719 | 0 | sizeof (struct elf_aarch64_link_hash_entry)); |
2720 | 0 | if (ret == NULL) |
2721 | 0 | return (struct bfd_hash_entry *) ret; |
2722 | | |
2723 | | /* Call the allocation method of the superclass. */ |
2724 | 0 | ret = ((struct elf_aarch64_link_hash_entry *) |
2725 | 0 | _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry *) ret, |
2726 | 0 | table, string)); |
2727 | 0 | if (ret != NULL) |
2728 | 0 | { |
2729 | 0 | ret->got_type = GOT_UNKNOWN; |
2730 | 0 | ret->def_protected = 0; |
2731 | 0 | ret->plt_got_offset = (bfd_vma) - 1; |
2732 | 0 | ret->stub_cache = NULL; |
2733 | 0 | ret->tlsdesc_got_jump_table_offset = (bfd_vma) - 1; |
2734 | 0 | } |
2735 | |
|
2736 | 0 | return (struct bfd_hash_entry *) ret; |
2737 | 0 | } |
2738 | | |
2739 | | /* Initialize an entry in the stub hash table. */ |
2740 | | |
2741 | | static struct bfd_hash_entry * |
2742 | | stub_hash_newfunc (struct bfd_hash_entry *entry, |
2743 | | struct bfd_hash_table *table, const char *string) |
2744 | 0 | { |
2745 | | /* Allocate the structure if it has not already been allocated by a |
2746 | | subclass. */ |
2747 | 0 | if (entry == NULL) |
2748 | 0 | { |
2749 | 0 | entry = bfd_hash_allocate (table, |
2750 | 0 | sizeof (struct |
2751 | 0 | elf_aarch64_stub_hash_entry)); |
2752 | 0 | if (entry == NULL) |
2753 | 0 | return entry; |
2754 | 0 | } |
2755 | | |
2756 | | /* Call the allocation method of the superclass. */ |
2757 | 0 | entry = bfd_hash_newfunc (entry, table, string); |
2758 | 0 | if (entry != NULL) |
2759 | 0 | { |
2760 | 0 | struct elf_aarch64_stub_hash_entry *eh; |
2761 | | |
2762 | | /* Initialize the local fields. */ |
2763 | 0 | eh = (struct elf_aarch64_stub_hash_entry *) entry; |
2764 | 0 | memset (&eh->stub_sec, 0, |
2765 | 0 | (sizeof (struct elf_aarch64_stub_hash_entry) |
2766 | 0 | - offsetof (struct elf_aarch64_stub_hash_entry, stub_sec))); |
2767 | 0 | } |
2768 | |
|
2769 | 0 | return entry; |
2770 | 0 | } |
2771 | | |
2772 | | /* Compute a hash of a local hash entry. We use elf_link_hash_entry |
2773 | | for local symbol so that we can handle local STT_GNU_IFUNC symbols |
2774 | | as global symbol. We reuse indx and dynstr_index for local symbol |
2775 | | hash since they aren't used by global symbols in this backend. */ |
2776 | | |
2777 | | static hashval_t |
2778 | | elf64_aarch64_local_htab_hash (const void *ptr) |
2779 | 0 | { |
2780 | 0 | struct elf_link_hash_entry *h |
2781 | 0 | = (struct elf_link_hash_entry *) ptr; |
2782 | 0 | return ELF_LOCAL_SYMBOL_HASH (h->indx, h->dynstr_index); |
2783 | 0 | } |
2784 | | |
2785 | | /* Compare local hash entries. */ |
2786 | | |
2787 | | static int |
2788 | | elf64_aarch64_local_htab_eq (const void *ptr1, const void *ptr2) |
2789 | 0 | { |
2790 | 0 | struct elf_link_hash_entry *h1 |
2791 | 0 | = (struct elf_link_hash_entry *) ptr1; |
2792 | 0 | struct elf_link_hash_entry *h2 |
2793 | 0 | = (struct elf_link_hash_entry *) ptr2; |
2794 | |
|
2795 | 0 | return h1->indx == h2->indx && h1->dynstr_index == h2->dynstr_index; |
2796 | 0 | } |
2797 | | |
2798 | | /* Find and/or create a hash entry for local symbol. */ |
2799 | | |
2800 | | static struct elf_link_hash_entry * |
2801 | | elf64_aarch64_get_local_sym_hash (struct elf_aarch64_link_hash_table *htab, |
2802 | | bfd *abfd, const Elf_Internal_Rela *rel, |
2803 | | bool create) |
2804 | 0 | { |
2805 | 0 | struct elf_aarch64_link_hash_entry e, *ret; |
2806 | 0 | asection *sec = abfd->sections; |
2807 | 0 | hashval_t h = ELF_LOCAL_SYMBOL_HASH (sec->id, |
2808 | 0 | ELF64_R_SYM (rel->r_info)); |
2809 | 0 | void **slot; |
2810 | |
|
2811 | 0 | e.root.indx = sec->id; |
2812 | 0 | e.root.dynstr_index = ELF64_R_SYM (rel->r_info); |
2813 | 0 | slot = htab_find_slot_with_hash (htab->loc_hash_table, &e, h, |
2814 | 0 | create ? INSERT : NO_INSERT); |
2815 | |
|
2816 | 0 | if (!slot) |
2817 | 0 | return NULL; |
2818 | | |
2819 | 0 | if (*slot) |
2820 | 0 | { |
2821 | 0 | ret = (struct elf_aarch64_link_hash_entry *) *slot; |
2822 | 0 | return &ret->root; |
2823 | 0 | } |
2824 | | |
2825 | 0 | ret = (struct elf_aarch64_link_hash_entry *) |
2826 | 0 | objalloc_alloc ((struct objalloc *) htab->loc_hash_memory, |
2827 | 0 | sizeof (struct elf_aarch64_link_hash_entry)); |
2828 | 0 | if (ret) |
2829 | 0 | { |
2830 | 0 | memset (ret, 0, sizeof (*ret)); |
2831 | 0 | ret->root.indx = sec->id; |
2832 | 0 | ret->root.dynstr_index = ELF64_R_SYM (rel->r_info); |
2833 | 0 | ret->root.dynindx = -1; |
2834 | 0 | *slot = ret; |
2835 | 0 | } |
2836 | 0 | return &ret->root; |
2837 | 0 | } |
2838 | | |
2839 | | /* Copy the extra info we tack onto an elf_link_hash_entry. */ |
2840 | | |
2841 | | static void |
2842 | | elf64_aarch64_copy_indirect_symbol (struct bfd_link_info *info, |
2843 | | struct elf_link_hash_entry *dir, |
2844 | | struct elf_link_hash_entry *ind) |
2845 | 0 | { |
2846 | 0 | struct elf_aarch64_link_hash_entry *edir, *eind; |
2847 | |
|
2848 | 0 | edir = (struct elf_aarch64_link_hash_entry *) dir; |
2849 | 0 | eind = (struct elf_aarch64_link_hash_entry *) ind; |
2850 | |
|
2851 | 0 | if (ind->root.type == bfd_link_hash_indirect) |
2852 | 0 | { |
2853 | | /* Copy over PLT info. */ |
2854 | 0 | if (dir->got.refcount <= 0) |
2855 | 0 | { |
2856 | 0 | edir->got_type = eind->got_type; |
2857 | 0 | eind->got_type = GOT_UNKNOWN; |
2858 | 0 | } |
2859 | 0 | } |
2860 | |
|
2861 | 0 | _bfd_elf_link_hash_copy_indirect (info, dir, ind); |
2862 | 0 | } |
2863 | | |
2864 | | /* Merge non-visibility st_other attributes. */ |
2865 | | |
2866 | | static void |
2867 | | elf64_aarch64_merge_symbol_attribute (struct elf_link_hash_entry *h, |
2868 | | unsigned int st_other, |
2869 | | bool definition, |
2870 | | bool dynamic ATTRIBUTE_UNUSED) |
2871 | 0 | { |
2872 | 0 | if (definition) |
2873 | 0 | { |
2874 | 0 | struct elf_aarch64_link_hash_entry *eh |
2875 | 0 | = (struct elf_aarch64_link_hash_entry *)h; |
2876 | 0 | eh->def_protected = ELF_ST_VISIBILITY (st_other) == STV_PROTECTED; |
2877 | 0 | } |
2878 | |
|
2879 | 0 | unsigned int isym_sto = st_other & ~ELF_ST_VISIBILITY (-1); |
2880 | 0 | unsigned int h_sto = h->other & ~ELF_ST_VISIBILITY (-1); |
2881 | |
|
2882 | 0 | if (isym_sto == h_sto) |
2883 | 0 | return; |
2884 | | |
2885 | 0 | if (isym_sto & ~STO_AARCH64_VARIANT_PCS) |
2886 | | /* Not fatal, this callback cannot fail. */ |
2887 | 0 | _bfd_error_handler (_("unknown attribute for symbol `%s': 0x%02x"), |
2888 | 0 | h->root.root.string, isym_sto); |
2889 | | |
2890 | | /* Note: Ideally we would warn about any attribute mismatch, but |
2891 | | this api does not allow that without substantial changes. */ |
2892 | 0 | if (isym_sto & STO_AARCH64_VARIANT_PCS) |
2893 | 0 | h->other |= STO_AARCH64_VARIANT_PCS; |
2894 | 0 | } |
2895 | | |
2896 | | /* Destroy an AArch64 elf linker hash table. */ |
2897 | | |
2898 | | static void |
2899 | | elf64_aarch64_link_hash_table_free (bfd *obfd) |
2900 | 0 | { |
2901 | 0 | struct elf_aarch64_link_hash_table *ret |
2902 | 0 | = (struct elf_aarch64_link_hash_table *) obfd->link.hash; |
2903 | |
|
2904 | 0 | if (ret->loc_hash_table) |
2905 | 0 | htab_delete (ret->loc_hash_table); |
2906 | 0 | if (ret->loc_hash_memory) |
2907 | 0 | objalloc_free ((struct objalloc *) ret->loc_hash_memory); |
2908 | |
|
2909 | 0 | bfd_hash_table_free (&ret->stub_hash_table); |
2910 | 0 | _bfd_elf_link_hash_table_free (obfd); |
2911 | 0 | } |
2912 | | |
2913 | | /* Create an AArch64 elf linker hash table. */ |
2914 | | |
2915 | | static struct bfd_link_hash_table * |
2916 | | elf64_aarch64_link_hash_table_create (bfd *abfd) |
2917 | 0 | { |
2918 | 0 | struct elf_aarch64_link_hash_table *ret; |
2919 | 0 | size_t amt = sizeof (struct elf_aarch64_link_hash_table); |
2920 | |
|
2921 | 0 | ret = bfd_zmalloc (amt); |
2922 | 0 | if (ret == NULL) |
2923 | 0 | return NULL; |
2924 | | |
2925 | 0 | if (!_bfd_elf_link_hash_table_init |
2926 | 0 | (&ret->root, abfd, elf64_aarch64_link_hash_newfunc, |
2927 | 0 | sizeof (struct elf_aarch64_link_hash_entry))) |
2928 | 0 | { |
2929 | 0 | free (ret); |
2930 | 0 | return NULL; |
2931 | 0 | } |
2932 | | |
2933 | 0 | ret->plt_header_size = PLT_ENTRY_SIZE; |
2934 | 0 | ret->plt0_entry = elf64_aarch64_small_plt0_entry; |
2935 | 0 | ret->plt_entry_size = PLT_SMALL_ENTRY_SIZE; |
2936 | 0 | ret->plt_entry_delta = 0; |
2937 | 0 | ret->plt_entry = elf64_aarch64_small_plt_entry; |
2938 | 0 | ret->tlsdesc_plt_entry_size = PLT_TLSDESC_ENTRY_SIZE; |
2939 | 0 | ret->obfd = abfd; |
2940 | 0 | ret->root.tlsdesc_got = (bfd_vma) - 1; |
2941 | |
|
2942 | 0 | if (!bfd_hash_table_init (&ret->stub_hash_table, stub_hash_newfunc, |
2943 | 0 | sizeof (struct elf_aarch64_stub_hash_entry))) |
2944 | 0 | { |
2945 | 0 | _bfd_elf_link_hash_table_free (abfd); |
2946 | 0 | return NULL; |
2947 | 0 | } |
2948 | | |
2949 | 0 | ret->loc_hash_table = htab_try_create (1024, |
2950 | 0 | elf64_aarch64_local_htab_hash, |
2951 | 0 | elf64_aarch64_local_htab_eq, |
2952 | 0 | NULL); |
2953 | 0 | ret->loc_hash_memory = objalloc_create (); |
2954 | 0 | if (!ret->loc_hash_table || !ret->loc_hash_memory) |
2955 | 0 | { |
2956 | 0 | elf64_aarch64_link_hash_table_free (abfd); |
2957 | 0 | return NULL; |
2958 | 0 | } |
2959 | 0 | ret->root.root.hash_table_free = elf64_aarch64_link_hash_table_free; |
2960 | |
|
2961 | 0 | return &ret->root.root; |
2962 | 0 | } |
2963 | | |
2964 | | /* Perform relocation R_TYPE. Returns TRUE upon success, FALSE otherwise. */ |
2965 | | |
2966 | | static bool |
2967 | | aarch64_relocate (unsigned int r_type, bfd *input_bfd, asection *input_section, |
2968 | | bfd_vma offset, bfd_vma value) |
2969 | 0 | { |
2970 | 0 | reloc_howto_type *howto; |
2971 | 0 | bfd_vma place; |
2972 | |
|
2973 | 0 | howto = elf64_aarch64_howto_from_type (input_bfd, r_type); |
2974 | 0 | place = (input_section->output_section->vma + input_section->output_offset |
2975 | 0 | + offset); |
2976 | |
|
2977 | 0 | r_type = elf64_aarch64_bfd_reloc_from_type (input_bfd, r_type); |
2978 | 0 | value = _bfd_aarch64_elf_resolve_relocation (input_bfd, r_type, place, |
2979 | 0 | value, 0, false); |
2980 | 0 | return _bfd_aarch64_elf_put_addend (input_bfd, |
2981 | 0 | input_section->contents + offset, r_type, |
2982 | 0 | howto, value) == bfd_reloc_ok; |
2983 | 0 | } |
2984 | | |
2985 | | /* Determine the type of stub needed, if any, for a call. */ |
2986 | | |
2987 | | static enum elf_aarch64_stub_type |
2988 | | aarch64_type_of_stub (asection *input_sec, |
2989 | | const Elf_Internal_Rela *rel, |
2990 | | asection *sym_sec, |
2991 | | unsigned char st_type, |
2992 | | bfd_vma destination) |
2993 | 0 | { |
2994 | 0 | bfd_vma location; |
2995 | 0 | bfd_signed_vma branch_offset; |
2996 | 0 | unsigned int r_type; |
2997 | 0 | enum elf_aarch64_stub_type stub_type = aarch64_stub_none; |
2998 | |
|
2999 | 0 | if (st_type != STT_FUNC |
3000 | 0 | && (sym_sec == input_sec)) |
3001 | 0 | return stub_type; |
3002 | | |
3003 | | /* Determine where the call point is. */ |
3004 | 0 | location = (input_sec->output_offset |
3005 | 0 | + input_sec->output_section->vma + rel->r_offset); |
3006 | |
|
3007 | 0 | branch_offset = (bfd_signed_vma) (destination - location); |
3008 | |
|
3009 | 0 | r_type = ELF64_R_TYPE (rel->r_info); |
3010 | | |
3011 | | /* We don't want to redirect any old unconditional jump in this way, |
3012 | | only one which is being used for a sibcall, where it is |
3013 | | acceptable for the IP0 and IP1 registers to be clobbered. */ |
3014 | 0 | if ((r_type == AARCH64_R (CALL26) || r_type == AARCH64_R (JUMP26)) |
3015 | 0 | && (branch_offset > AARCH64_MAX_FWD_BRANCH_OFFSET |
3016 | 0 | || branch_offset < AARCH64_MAX_BWD_BRANCH_OFFSET)) |
3017 | 0 | { |
3018 | 0 | stub_type = aarch64_stub_long_branch; |
3019 | 0 | } |
3020 | |
|
3021 | 0 | return stub_type; |
3022 | 0 | } |
3023 | | |
3024 | | /* Build a name for an entry in the stub hash table. */ |
3025 | | |
3026 | | static char * |
3027 | | elf64_aarch64_stub_name (const asection *input_section, |
3028 | | const asection *sym_sec, |
3029 | | const struct elf_aarch64_link_hash_entry *hash, |
3030 | | const Elf_Internal_Rela *rel) |
3031 | 0 | { |
3032 | 0 | char *stub_name; |
3033 | 0 | bfd_size_type len; |
3034 | |
|
3035 | 0 | if (hash) |
3036 | 0 | { |
3037 | 0 | len = 8 + 1 + strlen (hash->root.root.root.string) + 1 + 16 + 1; |
3038 | 0 | stub_name = bfd_malloc (len); |
3039 | 0 | if (stub_name != NULL) |
3040 | 0 | snprintf (stub_name, len, "%08x_%s+%" PRIx64, |
3041 | 0 | (unsigned int) input_section->id, |
3042 | 0 | hash->root.root.root.string, |
3043 | 0 | (uint64_t) rel->r_addend); |
3044 | 0 | } |
3045 | 0 | else |
3046 | 0 | { |
3047 | 0 | len = 8 + 1 + 8 + 1 + 8 + 1 + 16 + 1; |
3048 | 0 | stub_name = bfd_malloc (len); |
3049 | 0 | if (stub_name != NULL) |
3050 | 0 | snprintf (stub_name, len, "%08x_%x:%x+%" PRIx64, |
3051 | 0 | (unsigned int) input_section->id, |
3052 | 0 | (unsigned int) sym_sec->id, |
3053 | 0 | (unsigned int) ELF64_R_SYM (rel->r_info), |
3054 | 0 | (uint64_t) rel->r_addend); |
3055 | 0 | } |
3056 | |
|
3057 | 0 | return stub_name; |
3058 | 0 | } |
3059 | | |
3060 | | /* Return TRUE if symbol H should be hashed in the `.gnu.hash' section. For |
3061 | | executable PLT slots where the executable never takes the address of those |
3062 | | functions, the function symbols are not added to the hash table. */ |
3063 | | |
3064 | | static bool |
3065 | | elf_aarch64_hash_symbol (struct elf_link_hash_entry *h) |
3066 | 0 | { |
3067 | 0 | if (h->plt.offset != (bfd_vma) -1 |
3068 | 0 | && !h->def_regular |
3069 | 0 | && !h->pointer_equality_needed) |
3070 | 0 | return false; |
3071 | | |
3072 | 0 | return _bfd_elf_hash_symbol (h); |
3073 | 0 | } |
3074 | | |
3075 | | |
3076 | | /* Look up an entry in the stub hash. Stub entries are cached because |
3077 | | creating the stub name takes a bit of time. */ |
3078 | | |
3079 | | static struct elf_aarch64_stub_hash_entry * |
3080 | | elf64_aarch64_get_stub_entry (const asection *input_section, |
3081 | | const asection *sym_sec, |
3082 | | struct elf_link_hash_entry *hash, |
3083 | | const Elf_Internal_Rela *rel, |
3084 | | struct elf_aarch64_link_hash_table *htab) |
3085 | 0 | { |
3086 | 0 | struct elf_aarch64_stub_hash_entry *stub_entry; |
3087 | 0 | struct elf_aarch64_link_hash_entry *h = |
3088 | 0 | (struct elf_aarch64_link_hash_entry *) hash; |
3089 | 0 | const asection *id_sec; |
3090 | |
|
3091 | 0 | if ((input_section->flags & SEC_CODE) == 0) |
3092 | 0 | return NULL; |
3093 | | |
3094 | | /* If this input section is part of a group of sections sharing one |
3095 | | stub section, then use the id of the first section in the group. |
3096 | | Stub names need to include a section id, as there may well be |
3097 | | more than one stub used to reach say, printf, and we need to |
3098 | | distinguish between them. */ |
3099 | 0 | id_sec = htab->stub_group[input_section->id].link_sec; |
3100 | |
|
3101 | 0 | if (h != NULL && h->stub_cache != NULL |
3102 | 0 | && h->stub_cache->h == h && h->stub_cache->id_sec == id_sec) |
3103 | 0 | { |
3104 | 0 | stub_entry = h->stub_cache; |
3105 | 0 | } |
3106 | 0 | else |
3107 | 0 | { |
3108 | 0 | char *stub_name; |
3109 | |
|
3110 | 0 | stub_name = elf64_aarch64_stub_name (id_sec, sym_sec, h, rel); |
3111 | 0 | if (stub_name == NULL) |
3112 | 0 | return NULL; |
3113 | | |
3114 | 0 | stub_entry = aarch64_stub_hash_lookup (&htab->stub_hash_table, |
3115 | 0 | stub_name, false, false); |
3116 | 0 | if (h != NULL) |
3117 | 0 | h->stub_cache = stub_entry; |
3118 | |
|
3119 | 0 | free (stub_name); |
3120 | 0 | } |
3121 | | |
3122 | 0 | return stub_entry; |
3123 | 0 | } |
3124 | | |
3125 | | |
3126 | | /* Create a stub section. */ |
3127 | | |
3128 | | static asection * |
3129 | | _bfd_aarch64_create_stub_section (asection *section, |
3130 | | struct elf_aarch64_link_hash_table *htab) |
3131 | 0 | { |
3132 | 0 | size_t namelen; |
3133 | 0 | bfd_size_type len; |
3134 | 0 | char *s_name; |
3135 | |
|
3136 | 0 | namelen = strlen (section->name); |
3137 | 0 | len = namelen + sizeof (STUB_SUFFIX); |
3138 | 0 | s_name = bfd_alloc (htab->stub_bfd, len); |
3139 | 0 | if (s_name == NULL) |
3140 | 0 | return NULL; |
3141 | | |
3142 | 0 | memcpy (s_name, section->name, namelen); |
3143 | 0 | memcpy (s_name + namelen, STUB_SUFFIX, sizeof (STUB_SUFFIX)); |
3144 | 0 | return (*htab->add_stub_section) (s_name, section); |
3145 | 0 | } |
3146 | | |
3147 | | |
3148 | | /* Find or create a stub section for a link section. |
3149 | | |
3150 | | Fix or create the stub section used to collect stubs attached to |
3151 | | the specified link section. */ |
3152 | | |
3153 | | static asection * |
3154 | | _bfd_aarch64_get_stub_for_link_section (asection *link_section, |
3155 | | struct elf_aarch64_link_hash_table *htab) |
3156 | 0 | { |
3157 | 0 | if (htab->stub_group[link_section->id].stub_sec == NULL) |
3158 | 0 | htab->stub_group[link_section->id].stub_sec |
3159 | 0 | = _bfd_aarch64_create_stub_section (link_section, htab); |
3160 | 0 | return htab->stub_group[link_section->id].stub_sec; |
3161 | 0 | } |
3162 | | |
3163 | | |
3164 | | /* Find or create a stub section in the stub group for an input |
3165 | | section. */ |
3166 | | |
3167 | | static asection * |
3168 | | _bfd_aarch64_create_or_find_stub_sec (asection *section, |
3169 | | struct elf_aarch64_link_hash_table *htab) |
3170 | 0 | { |
3171 | 0 | asection *link_sec = htab->stub_group[section->id].link_sec; |
3172 | 0 | return _bfd_aarch64_get_stub_for_link_section (link_sec, htab); |
3173 | 0 | } |
3174 | | |
3175 | | |
3176 | | /* Add a new stub entry in the stub group associated with an input |
3177 | | section to the stub hash. Not all fields of the new stub entry are |
3178 | | initialised. */ |
3179 | | |
3180 | | static struct elf_aarch64_stub_hash_entry * |
3181 | | _bfd_aarch64_add_stub_entry_in_group (const char *stub_name, |
3182 | | asection *section, |
3183 | | struct elf_aarch64_link_hash_table *htab) |
3184 | 0 | { |
3185 | 0 | asection *link_sec; |
3186 | 0 | asection *stub_sec; |
3187 | 0 | struct elf_aarch64_stub_hash_entry *stub_entry; |
3188 | |
|
3189 | 0 | link_sec = htab->stub_group[section->id].link_sec; |
3190 | 0 | stub_sec = _bfd_aarch64_create_or_find_stub_sec (section, htab); |
3191 | | |
3192 | | /* Enter this entry into the linker stub hash table. */ |
3193 | 0 | stub_entry = aarch64_stub_hash_lookup (&htab->stub_hash_table, stub_name, |
3194 | 0 | true, false); |
3195 | 0 | if (stub_entry == NULL) |
3196 | 0 | { |
3197 | | /* xgettext:c-format */ |
3198 | 0 | _bfd_error_handler (_("%pB: cannot create stub entry %s"), |
3199 | 0 | section->owner, stub_name); |
3200 | 0 | return NULL; |
3201 | 0 | } |
3202 | | |
3203 | 0 | stub_entry->stub_sec = stub_sec; |
3204 | 0 | stub_entry->stub_offset = 0; |
3205 | 0 | stub_entry->id_sec = link_sec; |
3206 | |
|
3207 | 0 | return stub_entry; |
3208 | 0 | } |
3209 | | |
3210 | | /* Add a new stub entry in the final stub section to the stub hash. |
3211 | | Not all fields of the new stub entry are initialised. */ |
3212 | | |
3213 | | static struct elf_aarch64_stub_hash_entry * |
3214 | | _bfd_aarch64_add_stub_entry_after (const char *stub_name, |
3215 | | asection *link_section, |
3216 | | struct elf_aarch64_link_hash_table *htab) |
3217 | 0 | { |
3218 | 0 | asection *stub_sec; |
3219 | 0 | struct elf_aarch64_stub_hash_entry *stub_entry; |
3220 | |
|
3221 | 0 | stub_sec = NULL; |
3222 | | /* Only create the actual stub if we will end up needing it. */ |
3223 | 0 | if (htab->fix_erratum_843419 & ERRAT_ADRP) |
3224 | 0 | stub_sec = _bfd_aarch64_get_stub_for_link_section (link_section, htab); |
3225 | 0 | stub_entry = aarch64_stub_hash_lookup (&htab->stub_hash_table, stub_name, |
3226 | 0 | true, false); |
3227 | 0 | if (stub_entry == NULL) |
3228 | 0 | { |
3229 | 0 | _bfd_error_handler (_("cannot create stub entry %s"), stub_name); |
3230 | 0 | return NULL; |
3231 | 0 | } |
3232 | | |
3233 | 0 | stub_entry->stub_sec = stub_sec; |
3234 | 0 | stub_entry->stub_offset = 0; |
3235 | 0 | stub_entry->id_sec = link_section; |
3236 | |
|
3237 | 0 | return stub_entry; |
3238 | 0 | } |
3239 | | |
3240 | | |
3241 | | static bool |
3242 | | aarch64_build_one_stub (struct bfd_hash_entry *gen_entry, |
3243 | | void *in_arg) |
3244 | 0 | { |
3245 | 0 | struct elf_aarch64_stub_hash_entry *stub_entry; |
3246 | 0 | asection *stub_sec; |
3247 | 0 | bfd *stub_bfd; |
3248 | 0 | bfd_byte *loc; |
3249 | 0 | bfd_vma sym_value; |
3250 | 0 | bfd_vma veneered_insn_loc; |
3251 | 0 | bfd_vma veneer_entry_loc; |
3252 | 0 | bfd_signed_vma branch_offset = 0; |
3253 | 0 | unsigned int template_size; |
3254 | 0 | unsigned int pad_size = 0; |
3255 | 0 | const uint32_t *template; |
3256 | 0 | unsigned int i; |
3257 | 0 | struct bfd_link_info *info; |
3258 | 0 | struct elf_aarch64_link_hash_table *htab; |
3259 | | |
3260 | | /* Massage our args to the form they really have. */ |
3261 | 0 | stub_entry = (struct elf_aarch64_stub_hash_entry *) gen_entry; |
3262 | |
|
3263 | 0 | info = (struct bfd_link_info *) in_arg; |
3264 | 0 | htab = elf_aarch64_hash_table (info); |
3265 | | |
3266 | | /* Fail if the target section could not be assigned to an output |
3267 | | section. The user should fix his linker script. */ |
3268 | 0 | if (stub_entry->target_section->output_section == NULL |
3269 | 0 | && info->non_contiguous_regions) |
3270 | 0 | info->callbacks->fatal (_("%P: Could not assign `%pA' to an output section. " |
3271 | 0 | "Retry without " |
3272 | 0 | "--enable-non-contiguous-regions.\n"), |
3273 | 0 | stub_entry->target_section); |
3274 | | |
3275 | 0 | stub_sec = stub_entry->stub_sec; |
3276 | | |
3277 | | /* The layout must not change when a stub may be the target of another. */ |
3278 | 0 | if (htab->has_double_stub) |
3279 | 0 | BFD_ASSERT (stub_entry->stub_offset == stub_sec->size); |
3280 | | |
3281 | | /* Make a note of the offset within the stubs for this entry. */ |
3282 | 0 | stub_entry->stub_offset = stub_sec->size; |
3283 | 0 | loc = stub_sec->contents + stub_entry->stub_offset; |
3284 | |
|
3285 | 0 | stub_bfd = stub_sec->owner; |
3286 | | |
3287 | | /* This is the address of the stub destination. */ |
3288 | 0 | sym_value = (stub_entry->target_value |
3289 | 0 | + stub_entry->target_section->output_offset |
3290 | 0 | + stub_entry->target_section->output_section->vma); |
3291 | |
|
3292 | 0 | if (stub_entry->stub_type == aarch64_stub_long_branch) |
3293 | 0 | { |
3294 | 0 | bfd_vma place = (stub_entry->stub_offset + stub_sec->output_section->vma |
3295 | 0 | + stub_sec->output_offset); |
3296 | | |
3297 | | /* See if we can relax the stub. */ |
3298 | 0 | if (aarch64_valid_for_adrp_p (sym_value, place)) |
3299 | 0 | { |
3300 | 0 | stub_entry->stub_type = aarch64_stub_adrp_branch; |
3301 | | |
3302 | | /* Avoid the relaxation changing the layout. */ |
3303 | 0 | if (htab->has_double_stub) |
3304 | 0 | pad_size = sizeof (aarch64_long_branch_stub) |
3305 | 0 | - sizeof (aarch64_adrp_branch_stub); |
3306 | 0 | } |
3307 | 0 | } |
3308 | |
|
3309 | 0 | switch (stub_entry->stub_type) |
3310 | 0 | { |
3311 | 0 | case aarch64_stub_adrp_branch: |
3312 | 0 | template = aarch64_adrp_branch_stub; |
3313 | 0 | template_size = sizeof (aarch64_adrp_branch_stub); |
3314 | 0 | break; |
3315 | 0 | case aarch64_stub_long_branch: |
3316 | 0 | template = aarch64_long_branch_stub; |
3317 | 0 | template_size = sizeof (aarch64_long_branch_stub); |
3318 | 0 | break; |
3319 | 0 | case aarch64_stub_bti_direct_branch: |
3320 | 0 | template = aarch64_bti_direct_branch_stub; |
3321 | 0 | template_size = sizeof (aarch64_bti_direct_branch_stub); |
3322 | 0 | break; |
3323 | 0 | case aarch64_stub_erratum_835769_veneer: |
3324 | 0 | template = aarch64_erratum_835769_stub; |
3325 | 0 | template_size = sizeof (aarch64_erratum_835769_stub); |
3326 | 0 | break; |
3327 | 0 | case aarch64_stub_erratum_843419_veneer: |
3328 | 0 | template = aarch64_erratum_843419_stub; |
3329 | 0 | template_size = sizeof (aarch64_erratum_843419_stub); |
3330 | 0 | break; |
3331 | 0 | default: |
3332 | 0 | abort (); |
3333 | 0 | } |
3334 | | |
3335 | 0 | for (i = 0; i < (template_size / sizeof template[0]); i++) |
3336 | 0 | { |
3337 | 0 | bfd_putl32 (template[i], loc); |
3338 | 0 | loc += 4; |
3339 | 0 | } |
3340 | |
|
3341 | 0 | template_size += pad_size; |
3342 | 0 | template_size = (template_size + 7) & ~7; |
3343 | 0 | stub_sec->size += template_size; |
3344 | |
|
3345 | 0 | switch (stub_entry->stub_type) |
3346 | 0 | { |
3347 | 0 | case aarch64_stub_adrp_branch: |
3348 | 0 | if (!aarch64_relocate (AARCH64_R (ADR_PREL_PG_HI21), stub_bfd, stub_sec, |
3349 | 0 | stub_entry->stub_offset, sym_value)) |
3350 | | /* The stub would not have been relaxed if the offset was out |
3351 | | of range. */ |
3352 | 0 | BFD_FAIL (); |
3353 | |
|
3354 | 0 | if (!aarch64_relocate (AARCH64_R (ADD_ABS_LO12_NC), stub_bfd, stub_sec, |
3355 | 0 | stub_entry->stub_offset + 4, sym_value)) |
3356 | 0 | BFD_FAIL (); |
3357 | 0 | break; |
3358 | | |
3359 | 0 | case aarch64_stub_long_branch: |
3360 | | /* We want the value relative to the address 12 bytes back from the |
3361 | | value itself. */ |
3362 | 0 | if (!aarch64_relocate (AARCH64_R (PREL64), stub_bfd, stub_sec, |
3363 | 0 | stub_entry->stub_offset + 16, sym_value + 12)) |
3364 | 0 | BFD_FAIL (); |
3365 | 0 | break; |
3366 | | |
3367 | 0 | case aarch64_stub_bti_direct_branch: |
3368 | 0 | if (!aarch64_relocate (AARCH64_R (JUMP26), stub_bfd, stub_sec, |
3369 | 0 | stub_entry->stub_offset + 4, sym_value)) |
3370 | 0 | BFD_FAIL (); |
3371 | 0 | break; |
3372 | | |
3373 | 0 | case aarch64_stub_erratum_835769_veneer: |
3374 | 0 | veneered_insn_loc = stub_entry->target_section->output_section->vma |
3375 | 0 | + stub_entry->target_section->output_offset |
3376 | 0 | + stub_entry->target_value; |
3377 | 0 | veneer_entry_loc = stub_entry->stub_sec->output_section->vma |
3378 | 0 | + stub_entry->stub_sec->output_offset |
3379 | 0 | + stub_entry->stub_offset; |
3380 | 0 | branch_offset = veneered_insn_loc - veneer_entry_loc; |
3381 | 0 | branch_offset >>= 2; |
3382 | 0 | branch_offset &= 0x3ffffff; |
3383 | 0 | bfd_putl32 (stub_entry->veneered_insn, |
3384 | 0 | stub_sec->contents + stub_entry->stub_offset); |
3385 | 0 | bfd_putl32 (template[1] | branch_offset, |
3386 | 0 | stub_sec->contents + stub_entry->stub_offset + 4); |
3387 | 0 | break; |
3388 | | |
3389 | 0 | case aarch64_stub_erratum_843419_veneer: |
3390 | 0 | if (!aarch64_relocate (AARCH64_R (JUMP26), stub_bfd, stub_sec, |
3391 | 0 | stub_entry->stub_offset + 4, sym_value + 4)) |
3392 | 0 | BFD_FAIL (); |
3393 | 0 | break; |
3394 | | |
3395 | 0 | default: |
3396 | 0 | abort (); |
3397 | 0 | } |
3398 | | |
3399 | 0 | return true; |
3400 | 0 | } |
3401 | | |
3402 | | /* As above, but don't actually build the stub. Just bump offset so |
3403 | | we know stub section sizes and record the offset for each stub so |
3404 | | a stub can target another stub (needed for BTI direct branch stub). */ |
3405 | | |
3406 | | static bool |
3407 | | aarch64_size_one_stub (struct bfd_hash_entry *gen_entry, void *in_arg) |
3408 | 0 | { |
3409 | 0 | struct elf_aarch64_stub_hash_entry *stub_entry; |
3410 | 0 | struct elf_aarch64_link_hash_table *htab; |
3411 | 0 | int size; |
3412 | | |
3413 | | /* Massage our args to the form they really have. */ |
3414 | 0 | stub_entry = (struct elf_aarch64_stub_hash_entry *) gen_entry; |
3415 | 0 | htab = (struct elf_aarch64_link_hash_table *) in_arg; |
3416 | |
|
3417 | 0 | switch (stub_entry->stub_type) |
3418 | 0 | { |
3419 | 0 | case aarch64_stub_adrp_branch: |
3420 | 0 | size = sizeof (aarch64_adrp_branch_stub); |
3421 | 0 | break; |
3422 | 0 | case aarch64_stub_long_branch: |
3423 | 0 | size = sizeof (aarch64_long_branch_stub); |
3424 | 0 | break; |
3425 | 0 | case aarch64_stub_bti_direct_branch: |
3426 | 0 | size = sizeof (aarch64_bti_direct_branch_stub); |
3427 | 0 | break; |
3428 | 0 | case aarch64_stub_erratum_835769_veneer: |
3429 | 0 | size = sizeof (aarch64_erratum_835769_stub); |
3430 | 0 | break; |
3431 | 0 | case aarch64_stub_erratum_843419_veneer: |
3432 | 0 | { |
3433 | 0 | if (htab->fix_erratum_843419 == ERRAT_ADR) |
3434 | 0 | return true; |
3435 | 0 | size = sizeof (aarch64_erratum_843419_stub); |
3436 | 0 | } |
3437 | 0 | break; |
3438 | 0 | default: |
3439 | 0 | abort (); |
3440 | 0 | } |
3441 | | |
3442 | 0 | size = (size + 7) & ~7; |
3443 | 0 | stub_entry->stub_offset = stub_entry->stub_sec->size; |
3444 | 0 | stub_entry->stub_sec->size += size; |
3445 | 0 | return true; |
3446 | 0 | } |
3447 | | |
3448 | | /* Output is BTI compatible. */ |
3449 | | |
3450 | | static bool |
3451 | | elf_aarch64_bti_p (bfd *output_bfd) |
3452 | 0 | { |
3453 | 0 | return elf_aarch64_tdata (output_bfd)->gnu_property_aarch64_feature_1_and |
3454 | 0 | & GNU_PROPERTY_AARCH64_FEATURE_1_BTI; |
3455 | 0 | } |
3456 | | |
3457 | | /* External entry points for sizing and building linker stubs. */ |
3458 | | |
3459 | | /* Set up various things so that we can make a list of input sections |
3460 | | for each output section included in the link. Returns -1 on error, |
3461 | | 0 when no stubs will be needed, and 1 on success. */ |
3462 | | |
3463 | | int |
3464 | | elf64_aarch64_setup_section_lists (bfd *output_bfd, |
3465 | | struct bfd_link_info *info) |
3466 | 0 | { |
3467 | 0 | bfd *input_bfd; |
3468 | 0 | unsigned int bfd_count; |
3469 | 0 | unsigned int top_id, top_index; |
3470 | 0 | asection *section; |
3471 | 0 | asection **input_list, **list; |
3472 | 0 | size_t amt; |
3473 | 0 | struct elf_aarch64_link_hash_table *htab = |
3474 | 0 | elf_aarch64_hash_table (info); |
3475 | |
|
3476 | 0 | if (!is_elf_hash_table (&htab->root.root)) |
3477 | 0 | return 0; |
3478 | | |
3479 | | /* Count the number of input BFDs and find the top input section id. */ |
3480 | 0 | for (input_bfd = info->input_bfds, bfd_count = 0, top_id = 0; |
3481 | 0 | input_bfd != NULL; input_bfd = input_bfd->link.next) |
3482 | 0 | { |
3483 | 0 | bfd_count += 1; |
3484 | 0 | for (section = input_bfd->sections; |
3485 | 0 | section != NULL; section = section->next) |
3486 | 0 | { |
3487 | 0 | if (top_id < section->id) |
3488 | 0 | top_id = section->id; |
3489 | 0 | } |
3490 | 0 | } |
3491 | 0 | htab->bfd_count = bfd_count; |
3492 | |
|
3493 | 0 | amt = sizeof (struct map_stub) * (top_id + 1); |
3494 | 0 | htab->stub_group = bfd_zmalloc (amt); |
3495 | 0 | if (htab->stub_group == NULL) |
3496 | 0 | return -1; |
3497 | | |
3498 | | /* We can't use output_bfd->section_count here to find the top output |
3499 | | section index as some sections may have been removed, and |
3500 | | _bfd_strip_section_from_output doesn't renumber the indices. */ |
3501 | 0 | for (section = output_bfd->sections, top_index = 0; |
3502 | 0 | section != NULL; section = section->next) |
3503 | 0 | { |
3504 | 0 | if (top_index < section->index) |
3505 | 0 | top_index = section->index; |
3506 | 0 | } |
3507 | |
|
3508 | 0 | htab->top_index = top_index; |
3509 | 0 | amt = sizeof (asection *) * (top_index + 1); |
3510 | 0 | input_list = bfd_malloc (amt); |
3511 | 0 | htab->input_list = input_list; |
3512 | 0 | if (input_list == NULL) |
3513 | 0 | return -1; |
3514 | | |
3515 | | /* For sections we aren't interested in, mark their entries with a |
3516 | | value we can check later. */ |
3517 | 0 | list = input_list + top_index; |
3518 | 0 | do |
3519 | 0 | *list = bfd_abs_section_ptr; |
3520 | 0 | while (list-- != input_list); |
3521 | |
|
3522 | 0 | for (section = output_bfd->sections; |
3523 | 0 | section != NULL; section = section->next) |
3524 | 0 | { |
3525 | 0 | if ((section->flags & SEC_CODE) != 0) |
3526 | 0 | input_list[section->index] = NULL; |
3527 | 0 | } |
3528 | |
|
3529 | 0 | return 1; |
3530 | 0 | } |
3531 | | |
3532 | | /* Used by elf64_aarch64_next_input_section and group_sections. */ |
3533 | 0 | #define PREV_SEC(sec) (htab->stub_group[(sec)->id].link_sec) |
3534 | | |
3535 | | /* The linker repeatedly calls this function for each input section, |
3536 | | in the order that input sections are linked into output sections. |
3537 | | Build lists of input sections to determine groupings between which |
3538 | | we may insert linker stubs. */ |
3539 | | |
3540 | | void |
3541 | | elf64_aarch64_next_input_section (struct bfd_link_info *info, asection *isec) |
3542 | 0 | { |
3543 | 0 | struct elf_aarch64_link_hash_table *htab = |
3544 | 0 | elf_aarch64_hash_table (info); |
3545 | |
|
3546 | 0 | if (isec->output_section->index <= htab->top_index) |
3547 | 0 | { |
3548 | 0 | asection **list = htab->input_list + isec->output_section->index; |
3549 | |
|
3550 | 0 | if (*list != bfd_abs_section_ptr && (isec->flags & SEC_CODE) != 0) |
3551 | 0 | { |
3552 | | /* Steal the link_sec pointer for our list. */ |
3553 | | /* This happens to make the list in reverse order, |
3554 | | which is what we want. */ |
3555 | 0 | PREV_SEC (isec) = *list; |
3556 | 0 | *list = isec; |
3557 | 0 | } |
3558 | 0 | } |
3559 | 0 | } |
3560 | | |
3561 | | /* See whether we can group stub sections together. Grouping stub |
3562 | | sections may result in fewer stubs. More importantly, we need to |
3563 | | put all .init* and .fini* stubs at the beginning of the .init or |
3564 | | .fini output sections respectively, because glibc splits the |
3565 | | _init and _fini functions into multiple parts. Putting a stub in |
3566 | | the middle of a function is not a good idea. */ |
3567 | | |
3568 | | static void |
3569 | | group_sections (struct elf_aarch64_link_hash_table *htab, |
3570 | | bfd_size_type stub_group_size, |
3571 | | bool stubs_always_after_branch) |
3572 | 0 | { |
3573 | 0 | asection **list = htab->input_list; |
3574 | |
|
3575 | 0 | do |
3576 | 0 | { |
3577 | 0 | asection *tail = *list; |
3578 | 0 | asection *head; |
3579 | |
|
3580 | 0 | if (tail == bfd_abs_section_ptr) |
3581 | 0 | continue; |
3582 | | |
3583 | | /* Reverse the list: we must avoid placing stubs at the |
3584 | | beginning of the section because the beginning of the text |
3585 | | section may be required for an interrupt vector in bare metal |
3586 | | code. */ |
3587 | 0 | #define NEXT_SEC PREV_SEC |
3588 | 0 | head = NULL; |
3589 | 0 | while (tail != NULL) |
3590 | 0 | { |
3591 | | /* Pop from tail. */ |
3592 | 0 | asection *item = tail; |
3593 | 0 | tail = PREV_SEC (item); |
3594 | | |
3595 | | /* Push on head. */ |
3596 | 0 | NEXT_SEC (item) = head; |
3597 | 0 | head = item; |
3598 | 0 | } |
3599 | |
|
3600 | 0 | while (head != NULL) |
3601 | 0 | { |
3602 | 0 | asection *curr; |
3603 | 0 | asection *next; |
3604 | 0 | bfd_vma stub_group_start = head->output_offset; |
3605 | 0 | bfd_vma end_of_next; |
3606 | |
|
3607 | 0 | curr = head; |
3608 | 0 | while (NEXT_SEC (curr) != NULL) |
3609 | 0 | { |
3610 | 0 | next = NEXT_SEC (curr); |
3611 | 0 | end_of_next = next->output_offset + next->size; |
3612 | 0 | if (end_of_next - stub_group_start >= stub_group_size) |
3613 | | /* End of NEXT is too far from start, so stop. */ |
3614 | 0 | break; |
3615 | | /* Add NEXT to the group. */ |
3616 | 0 | curr = next; |
3617 | 0 | } |
3618 | | |
3619 | | /* OK, the size from the start to the start of CURR is less |
3620 | | than stub_group_size and thus can be handled by one stub |
3621 | | section. (Or the head section is itself larger than |
3622 | | stub_group_size, in which case we may be toast.) |
3623 | | We should really be keeping track of the total size of |
3624 | | stubs added here, as stubs contribute to the final output |
3625 | | section size. */ |
3626 | 0 | do |
3627 | 0 | { |
3628 | 0 | next = NEXT_SEC (head); |
3629 | | /* Set up this stub group. */ |
3630 | 0 | htab->stub_group[head->id].link_sec = curr; |
3631 | 0 | } |
3632 | 0 | while (head != curr && (head = next) != NULL); |
3633 | | |
3634 | | /* But wait, there's more! Input sections up to stub_group_size |
3635 | | bytes after the stub section can be handled by it too. */ |
3636 | 0 | if (!stubs_always_after_branch) |
3637 | 0 | { |
3638 | 0 | stub_group_start = curr->output_offset + curr->size; |
3639 | |
|
3640 | 0 | while (next != NULL) |
3641 | 0 | { |
3642 | 0 | end_of_next = next->output_offset + next->size; |
3643 | 0 | if (end_of_next - stub_group_start >= stub_group_size) |
3644 | | /* End of NEXT is too far from stubs, so stop. */ |
3645 | 0 | break; |
3646 | | /* Add NEXT to the stub group. */ |
3647 | 0 | head = next; |
3648 | 0 | next = NEXT_SEC (head); |
3649 | 0 | htab->stub_group[head->id].link_sec = curr; |
3650 | 0 | } |
3651 | 0 | } |
3652 | 0 | head = next; |
3653 | 0 | } |
3654 | 0 | } |
3655 | 0 | while (list++ != htab->input_list + htab->top_index); |
3656 | | |
3657 | 0 | free (htab->input_list); |
3658 | 0 | } |
3659 | | |
3660 | | #undef PREV_SEC |
3661 | | #undef PREV_SEC |
3662 | | |
3663 | 0 | #define AARCH64_HINT(insn) (((insn) & 0xfffff01f) == 0xd503201f) |
3664 | 0 | #define AARCH64_PACIASP 0xd503233f |
3665 | 0 | #define AARCH64_PACIBSP 0xd503237f |
3666 | 0 | #define AARCH64_BTI_C 0xd503245f |
3667 | 0 | #define AARCH64_BTI_J 0xd503249f |
3668 | 0 | #define AARCH64_BTI_JC 0xd50324df |
3669 | | |
3670 | | /* True if the inserted stub does not break BTI compatibility. */ |
3671 | | |
3672 | | static bool |
3673 | | aarch64_bti_stub_p (struct bfd_link_info *info, |
3674 | | struct elf_aarch64_stub_hash_entry *stub_entry) |
3675 | 0 | { |
3676 | | /* Stubs without indirect branch are BTI compatible. */ |
3677 | 0 | if (stub_entry->stub_type != aarch64_stub_adrp_branch |
3678 | 0 | && stub_entry->stub_type != aarch64_stub_long_branch) |
3679 | 0 | return true; |
3680 | | |
3681 | | /* Return true if the target instruction is compatible with BR x16. */ |
3682 | | |
3683 | 0 | struct elf_aarch64_link_hash_table *globals = elf_aarch64_hash_table (info); |
3684 | 0 | asection *section = stub_entry->target_section; |
3685 | 0 | bfd_byte loc[4]; |
3686 | 0 | file_ptr off = stub_entry->target_value; |
3687 | 0 | bfd_size_type count = sizeof (loc); |
3688 | | |
3689 | | /* PLT code is not generated yet, so treat it specially. |
3690 | | Note: Checking elf_aarch64_obj_tdata.plt_type & PLT_BTI is not |
3691 | | enough because it only implies BTI in the PLT0 and tlsdesc PLT |
3692 | | entries. Normal PLT entries don't have BTI in a shared library |
3693 | | (because such PLT is normally not called indirectly and adding |
3694 | | the BTI when a stub targets a PLT would change the PLT layout |
3695 | | and it's too late for that here). */ |
3696 | 0 | if (section == globals->root.splt) |
3697 | 0 | memcpy (loc, globals->plt_entry, count); |
3698 | 0 | else if (!bfd_get_section_contents (section->owner, section, loc, off, count)) |
3699 | 0 | return false; |
3700 | | |
3701 | 0 | uint32_t insn = bfd_getl32 (loc); |
3702 | 0 | if (!AARCH64_HINT (insn)) |
3703 | 0 | return false; |
3704 | 0 | return insn == AARCH64_BTI_C |
3705 | 0 | || insn == AARCH64_PACIASP |
3706 | 0 | || insn == AARCH64_BTI_JC |
3707 | 0 | || insn == AARCH64_BTI_J |
3708 | 0 | || insn == AARCH64_PACIBSP; |
3709 | 0 | } |
3710 | | |
3711 | 0 | #define AARCH64_BITS(x, pos, n) (((x) >> (pos)) & ((1 << (n)) - 1)) |
3712 | | |
3713 | 0 | #define AARCH64_RT(insn) AARCH64_BITS (insn, 0, 5) |
3714 | 0 | #define AARCH64_RT2(insn) AARCH64_BITS (insn, 10, 5) |
3715 | 0 | #define AARCH64_RA(insn) AARCH64_BITS (insn, 10, 5) |
3716 | 0 | #define AARCH64_RD(insn) AARCH64_BITS (insn, 0, 5) |
3717 | 0 | #define AARCH64_RN(insn) AARCH64_BITS (insn, 5, 5) |
3718 | 0 | #define AARCH64_RM(insn) AARCH64_BITS (insn, 16, 5) |
3719 | | |
3720 | 0 | #define AARCH64_MAC(insn) (((insn) & 0xff000000) == 0x9b000000) |
3721 | 0 | #define AARCH64_BIT(insn, n) AARCH64_BITS (insn, n, 1) |
3722 | 0 | #define AARCH64_OP31(insn) AARCH64_BITS (insn, 21, 3) |
3723 | 0 | #define AARCH64_ZR 0x1f |
3724 | | |
3725 | | /* All ld/st ops. See C4-182 of the ARM ARM. The encoding space for |
3726 | | LD_PCREL, LDST_RO, LDST_UI and LDST_UIMM cover prefetch ops. */ |
3727 | | |
3728 | 0 | #define AARCH64_LD(insn) (AARCH64_BIT (insn, 22) == 1) |
3729 | 0 | #define AARCH64_LDST(insn) (((insn) & 0x0a000000) == 0x08000000) |
3730 | 0 | #define AARCH64_LDST_EX(insn) (((insn) & 0x3f000000) == 0x08000000) |
3731 | 0 | #define AARCH64_LDST_PCREL(insn) (((insn) & 0x3b000000) == 0x18000000) |
3732 | 0 | #define AARCH64_LDST_NAP(insn) (((insn) & 0x3b800000) == 0x28000000) |
3733 | 0 | #define AARCH64_LDSTP_PI(insn) (((insn) & 0x3b800000) == 0x28800000) |
3734 | 0 | #define AARCH64_LDSTP_O(insn) (((insn) & 0x3b800000) == 0x29000000) |
3735 | 0 | #define AARCH64_LDSTP_PRE(insn) (((insn) & 0x3b800000) == 0x29800000) |
3736 | 0 | #define AARCH64_LDST_UI(insn) (((insn) & 0x3b200c00) == 0x38000000) |
3737 | 0 | #define AARCH64_LDST_PIIMM(insn) (((insn) & 0x3b200c00) == 0x38000400) |
3738 | 0 | #define AARCH64_LDST_U(insn) (((insn) & 0x3b200c00) == 0x38000800) |
3739 | 0 | #define AARCH64_LDST_PREIMM(insn) (((insn) & 0x3b200c00) == 0x38000c00) |
3740 | 0 | #define AARCH64_LDST_RO(insn) (((insn) & 0x3b200c00) == 0x38200800) |
3741 | 0 | #define AARCH64_LDST_UIMM(insn) (((insn) & 0x3b000000) == 0x39000000) |
3742 | 0 | #define AARCH64_LDST_SIMD_M(insn) (((insn) & 0xbfbf0000) == 0x0c000000) |
3743 | 0 | #define AARCH64_LDST_SIMD_M_PI(insn) (((insn) & 0xbfa00000) == 0x0c800000) |
3744 | 0 | #define AARCH64_LDST_SIMD_S(insn) (((insn) & 0xbf9f0000) == 0x0d000000) |
3745 | 0 | #define AARCH64_LDST_SIMD_S_PI(insn) (((insn) & 0xbf800000) == 0x0d800000) |
3746 | | |
3747 | | /* Classify an INSN if it is indeed a load/store. |
3748 | | |
3749 | | Return TRUE if INSN is a LD/ST instruction otherwise return FALSE. |
3750 | | |
3751 | | For scalar LD/ST instructions PAIR is FALSE, RT is returned and RT2 |
3752 | | is set equal to RT. |
3753 | | |
3754 | | For LD/ST pair instructions PAIR is TRUE, RT and RT2 are returned. */ |
3755 | | |
3756 | | static bool |
3757 | | aarch64_mem_op_p (uint32_t insn, unsigned int *rt, unsigned int *rt2, |
3758 | | bool *pair, bool *load) |
3759 | 0 | { |
3760 | 0 | uint32_t opcode; |
3761 | 0 | unsigned int r; |
3762 | 0 | uint32_t opc = 0; |
3763 | 0 | uint32_t v = 0; |
3764 | 0 | uint32_t opc_v = 0; |
3765 | | |
3766 | | /* Bail out quickly if INSN doesn't fall into the load-store |
3767 | | encoding space. */ |
3768 | 0 | if (!AARCH64_LDST (insn)) |
3769 | 0 | return false; |
3770 | | |
3771 | 0 | *pair = false; |
3772 | 0 | *load = false; |
3773 | 0 | if (AARCH64_LDST_EX (insn)) |
3774 | 0 | { |
3775 | 0 | *rt = AARCH64_RT (insn); |
3776 | 0 | *rt2 = *rt; |
3777 | 0 | if (AARCH64_BIT (insn, 21) == 1) |
3778 | 0 | { |
3779 | 0 | *pair = true; |
3780 | 0 | *rt2 = AARCH64_RT2 (insn); |
3781 | 0 | } |
3782 | 0 | *load = AARCH64_LD (insn); |
3783 | 0 | return true; |
3784 | 0 | } |
3785 | 0 | else if (AARCH64_LDST_NAP (insn) |
3786 | 0 | || AARCH64_LDSTP_PI (insn) |
3787 | 0 | || AARCH64_LDSTP_O (insn) |
3788 | 0 | || AARCH64_LDSTP_PRE (insn)) |
3789 | 0 | { |
3790 | 0 | *pair = true; |
3791 | 0 | *rt = AARCH64_RT (insn); |
3792 | 0 | *rt2 = AARCH64_RT2 (insn); |
3793 | 0 | *load = AARCH64_LD (insn); |
3794 | 0 | return true; |
3795 | 0 | } |
3796 | 0 | else if (AARCH64_LDST_PCREL (insn) |
3797 | 0 | || AARCH64_LDST_UI (insn) |
3798 | 0 | || AARCH64_LDST_PIIMM (insn) |
3799 | 0 | || AARCH64_LDST_U (insn) |
3800 | 0 | || AARCH64_LDST_PREIMM (insn) |
3801 | 0 | || AARCH64_LDST_RO (insn) |
3802 | 0 | || AARCH64_LDST_UIMM (insn)) |
3803 | 0 | { |
3804 | 0 | *rt = AARCH64_RT (insn); |
3805 | 0 | *rt2 = *rt; |
3806 | 0 | if (AARCH64_LDST_PCREL (insn)) |
3807 | 0 | *load = true; |
3808 | 0 | opc = AARCH64_BITS (insn, 22, 2); |
3809 | 0 | v = AARCH64_BIT (insn, 26); |
3810 | 0 | opc_v = opc | (v << 2); |
3811 | 0 | *load = (opc_v == 1 || opc_v == 2 || opc_v == 3 |
3812 | 0 | || opc_v == 5 || opc_v == 7); |
3813 | 0 | return true; |
3814 | 0 | } |
3815 | 0 | else if (AARCH64_LDST_SIMD_M (insn) |
3816 | 0 | || AARCH64_LDST_SIMD_M_PI (insn)) |
3817 | 0 | { |
3818 | 0 | *rt = AARCH64_RT (insn); |
3819 | 0 | *load = AARCH64_BIT (insn, 22); |
3820 | 0 | opcode = (insn >> 12) & 0xf; |
3821 | 0 | switch (opcode) |
3822 | 0 | { |
3823 | 0 | case 0: |
3824 | 0 | case 2: |
3825 | 0 | *rt2 = *rt + 3; |
3826 | 0 | break; |
3827 | | |
3828 | 0 | case 4: |
3829 | 0 | case 6: |
3830 | 0 | *rt2 = *rt + 2; |
3831 | 0 | break; |
3832 | | |
3833 | 0 | case 7: |
3834 | 0 | *rt2 = *rt; |
3835 | 0 | break; |
3836 | | |
3837 | 0 | case 8: |
3838 | 0 | case 10: |
3839 | 0 | *rt2 = *rt + 1; |
3840 | 0 | break; |
3841 | | |
3842 | 0 | default: |
3843 | 0 | return false; |
3844 | 0 | } |
3845 | 0 | return true; |
3846 | 0 | } |
3847 | 0 | else if (AARCH64_LDST_SIMD_S (insn) |
3848 | 0 | || AARCH64_LDST_SIMD_S_PI (insn)) |
3849 | 0 | { |
3850 | 0 | *rt = AARCH64_RT (insn); |
3851 | 0 | r = (insn >> 21) & 1; |
3852 | 0 | *load = AARCH64_BIT (insn, 22); |
3853 | 0 | opcode = (insn >> 13) & 0x7; |
3854 | 0 | switch (opcode) |
3855 | 0 | { |
3856 | 0 | case 0: |
3857 | 0 | case 2: |
3858 | 0 | case 4: |
3859 | 0 | *rt2 = *rt + r; |
3860 | 0 | break; |
3861 | | |
3862 | 0 | case 1: |
3863 | 0 | case 3: |
3864 | 0 | case 5: |
3865 | 0 | *rt2 = *rt + (r == 0 ? 2 : 3); |
3866 | 0 | break; |
3867 | | |
3868 | 0 | case 6: |
3869 | 0 | *rt2 = *rt + r; |
3870 | 0 | break; |
3871 | | |
3872 | 0 | case 7: |
3873 | 0 | *rt2 = *rt + (r == 0 ? 2 : 3); |
3874 | 0 | break; |
3875 | | |
3876 | 0 | default: |
3877 | 0 | return false; |
3878 | 0 | } |
3879 | 0 | return true; |
3880 | 0 | } |
3881 | | |
3882 | 0 | return false; |
3883 | 0 | } |
3884 | | |
3885 | | /* Return TRUE if INSN is multiply-accumulate. */ |
3886 | | |
3887 | | static bool |
3888 | | aarch64_mlxl_p (uint32_t insn) |
3889 | 0 | { |
3890 | 0 | uint32_t op31 = AARCH64_OP31 (insn); |
3891 | |
|
3892 | 0 | if (AARCH64_MAC (insn) |
3893 | 0 | && (op31 == 0 || op31 == 1 || op31 == 5) |
3894 | | /* Exclude MUL instructions which are encoded as a multiple accumulate |
3895 | | with RA = XZR. */ |
3896 | 0 | && AARCH64_RA (insn) != AARCH64_ZR) |
3897 | 0 | return true; |
3898 | | |
3899 | 0 | return false; |
3900 | 0 | } |
3901 | | |
3902 | | /* Some early revisions of the Cortex-A53 have an erratum (835769) whereby |
3903 | | it is possible for a 64-bit multiply-accumulate instruction to generate an |
3904 | | incorrect result. The details are quite complex and hard to |
3905 | | determine statically, since branches in the code may exist in some |
3906 | | circumstances, but all cases end with a memory (load, store, or |
3907 | | prefetch) instruction followed immediately by the multiply-accumulate |
3908 | | operation. We employ a linker patching technique, by moving the potentially |
3909 | | affected multiply-accumulate instruction into a patch region and replacing |
3910 | | the original instruction with a branch to the patch. This function checks |
3911 | | if INSN_1 is the memory operation followed by a multiply-accumulate |
3912 | | operation (INSN_2). Return TRUE if an erratum sequence is found, FALSE |
3913 | | if INSN_1 and INSN_2 are safe. */ |
3914 | | |
3915 | | static bool |
3916 | | aarch64_erratum_sequence (uint32_t insn_1, uint32_t insn_2) |
3917 | 0 | { |
3918 | 0 | uint32_t rt; |
3919 | 0 | uint32_t rt2; |
3920 | 0 | uint32_t rn; |
3921 | 0 | uint32_t rm; |
3922 | 0 | uint32_t ra; |
3923 | 0 | bool pair; |
3924 | 0 | bool load; |
3925 | |
|
3926 | 0 | if (aarch64_mlxl_p (insn_2) |
3927 | 0 | && aarch64_mem_op_p (insn_1, &rt, &rt2, &pair, &load)) |
3928 | 0 | { |
3929 | | /* Any SIMD memory op is independent of the subsequent MLA |
3930 | | by definition of the erratum. */ |
3931 | 0 | if (AARCH64_BIT (insn_1, 26)) |
3932 | 0 | return true; |
3933 | | |
3934 | | /* If not SIMD, check for integer memory ops and MLA relationship. */ |
3935 | 0 | rn = AARCH64_RN (insn_2); |
3936 | 0 | ra = AARCH64_RA (insn_2); |
3937 | 0 | rm = AARCH64_RM (insn_2); |
3938 | | |
3939 | | /* If this is a load and there's a true(RAW) dependency, we are safe |
3940 | | and this is not an erratum sequence. */ |
3941 | 0 | if (load && |
3942 | 0 | (rt == rn || rt == rm || rt == ra |
3943 | 0 | || (pair && (rt2 == rn || rt2 == rm || rt2 == ra)))) |
3944 | 0 | return false; |
3945 | | |
3946 | | /* We conservatively put out stubs for all other cases (including |
3947 | | writebacks). */ |
3948 | 0 | return true; |
3949 | 0 | } |
3950 | | |
3951 | 0 | return false; |
3952 | 0 | } |
3953 | | |
3954 | | /* Used to order a list of mapping symbols by address. */ |
3955 | | |
3956 | | static int |
3957 | | elf_aarch64_compare_mapping (const void *a, const void *b) |
3958 | 0 | { |
3959 | 0 | const elf_aarch64_section_map *amap = (const elf_aarch64_section_map *) a; |
3960 | 0 | const elf_aarch64_section_map *bmap = (const elf_aarch64_section_map *) b; |
3961 | |
|
3962 | 0 | if (amap->vma > bmap->vma) |
3963 | 0 | return 1; |
3964 | 0 | else if (amap->vma < bmap->vma) |
3965 | 0 | return -1; |
3966 | 0 | else if (amap->type > bmap->type) |
3967 | | /* Ensure results do not depend on the host qsort for objects with |
3968 | | multiple mapping symbols at the same address by sorting on type |
3969 | | after vma. */ |
3970 | 0 | return 1; |
3971 | 0 | else if (amap->type < bmap->type) |
3972 | 0 | return -1; |
3973 | 0 | else |
3974 | 0 | return 0; |
3975 | 0 | } |
3976 | | |
3977 | | |
3978 | | static char * |
3979 | | _bfd_aarch64_erratum_835769_stub_name (unsigned num_fixes) |
3980 | 0 | { |
3981 | 0 | char *stub_name = (char *) bfd_malloc |
3982 | 0 | (strlen ("__erratum_835769_veneer_") + 16); |
3983 | 0 | if (stub_name != NULL) |
3984 | 0 | sprintf (stub_name,"__erratum_835769_veneer_%d", num_fixes); |
3985 | 0 | return stub_name; |
3986 | 0 | } |
3987 | | |
3988 | | /* Scan for Cortex-A53 erratum 835769 sequence. |
3989 | | |
3990 | | Return TRUE else FALSE on abnormal termination. */ |
3991 | | |
3992 | | static bool |
3993 | | _bfd_aarch64_erratum_835769_scan (bfd *input_bfd, |
3994 | | struct bfd_link_info *info, |
3995 | | unsigned int *num_fixes_p) |
3996 | 0 | { |
3997 | 0 | asection *section; |
3998 | 0 | struct elf_aarch64_link_hash_table *htab = elf_aarch64_hash_table (info); |
3999 | 0 | unsigned int num_fixes = *num_fixes_p; |
4000 | |
|
4001 | 0 | if (htab == NULL) |
4002 | 0 | return true; |
4003 | | |
4004 | 0 | for (section = input_bfd->sections; |
4005 | 0 | section != NULL; |
4006 | 0 | section = section->next) |
4007 | 0 | { |
4008 | 0 | bfd_byte *contents = NULL; |
4009 | 0 | struct _aarch64_elf_section_data *sec_data; |
4010 | 0 | unsigned int span; |
4011 | |
|
4012 | 0 | if (elf_section_type (section) != SHT_PROGBITS |
4013 | 0 | || (elf_section_flags (section) & SHF_EXECINSTR) == 0 |
4014 | 0 | || (section->flags & SEC_EXCLUDE) != 0 |
4015 | 0 | || (section->sec_info_type == SEC_INFO_TYPE_JUST_SYMS) |
4016 | 0 | || (section->output_section == bfd_abs_section_ptr)) |
4017 | 0 | continue; |
4018 | | |
4019 | 0 | if (elf_section_data (section)->this_hdr.contents != NULL) |
4020 | 0 | contents = elf_section_data (section)->this_hdr.contents; |
4021 | 0 | else if (! bfd_malloc_and_get_section (input_bfd, section, &contents)) |
4022 | 0 | return false; |
4023 | | |
4024 | 0 | sec_data = elf_aarch64_section_data (section); |
4025 | |
|
4026 | 0 | if (sec_data->mapcount) |
4027 | 0 | qsort (sec_data->map, sec_data->mapcount, |
4028 | 0 | sizeof (elf_aarch64_section_map), elf_aarch64_compare_mapping); |
4029 | |
|
4030 | 0 | for (span = 0; span < sec_data->mapcount; span++) |
4031 | 0 | { |
4032 | 0 | unsigned int span_start = sec_data->map[span].vma; |
4033 | 0 | unsigned int span_end = ((span == sec_data->mapcount - 1) |
4034 | 0 | ? sec_data->map[0].vma + section->size |
4035 | 0 | : sec_data->map[span + 1].vma); |
4036 | 0 | unsigned int i; |
4037 | 0 | char span_type = sec_data->map[span].type; |
4038 | |
|
4039 | 0 | if (span_type == 'd') |
4040 | 0 | continue; |
4041 | | |
4042 | 0 | for (i = span_start; i + 4 < span_end; i += 4) |
4043 | 0 | { |
4044 | 0 | uint32_t insn_1 = bfd_getl32 (contents + i); |
4045 | 0 | uint32_t insn_2 = bfd_getl32 (contents + i + 4); |
4046 | |
|
4047 | 0 | if (aarch64_erratum_sequence (insn_1, insn_2)) |
4048 | 0 | { |
4049 | 0 | struct elf_aarch64_stub_hash_entry *stub_entry; |
4050 | 0 | char *stub_name = _bfd_aarch64_erratum_835769_stub_name (num_fixes); |
4051 | 0 | if (! stub_name) |
4052 | 0 | return false; |
4053 | | |
4054 | 0 | stub_entry = _bfd_aarch64_add_stub_entry_in_group (stub_name, |
4055 | 0 | section, |
4056 | 0 | htab); |
4057 | 0 | if (! stub_entry) |
4058 | 0 | return false; |
4059 | | |
4060 | 0 | stub_entry->stub_type = aarch64_stub_erratum_835769_veneer; |
4061 | 0 | stub_entry->target_section = section; |
4062 | 0 | stub_entry->target_value = i + 4; |
4063 | 0 | stub_entry->veneered_insn = insn_2; |
4064 | 0 | stub_entry->output_name = stub_name; |
4065 | 0 | num_fixes++; |
4066 | 0 | } |
4067 | 0 | } |
4068 | 0 | } |
4069 | 0 | if (elf_section_data (section)->this_hdr.contents == NULL) |
4070 | 0 | free (contents); |
4071 | 0 | } |
4072 | | |
4073 | 0 | *num_fixes_p = num_fixes; |
4074 | |
|
4075 | 0 | return true; |
4076 | 0 | } |
4077 | | |
4078 | | |
4079 | | /* Test if instruction INSN is ADRP. */ |
4080 | | |
4081 | | static bool |
4082 | | _bfd_aarch64_adrp_p (uint32_t insn) |
4083 | 0 | { |
4084 | 0 | return ((insn & AARCH64_ADRP_OP_MASK) == AARCH64_ADRP_OP); |
4085 | 0 | } |
4086 | | |
4087 | | |
4088 | | /* Helper predicate to look for cortex-a53 erratum 843419 sequence 1. */ |
4089 | | |
4090 | | static bool |
4091 | | _bfd_aarch64_erratum_843419_sequence_p (uint32_t insn_1, uint32_t insn_2, |
4092 | | uint32_t insn_3) |
4093 | 0 | { |
4094 | 0 | uint32_t rt; |
4095 | 0 | uint32_t rt2; |
4096 | 0 | bool pair; |
4097 | 0 | bool load; |
4098 | |
|
4099 | 0 | return (aarch64_mem_op_p (insn_2, &rt, &rt2, &pair, &load) |
4100 | 0 | && (!pair |
4101 | 0 | || (pair && !load)) |
4102 | 0 | && AARCH64_LDST_UIMM (insn_3) |
4103 | 0 | && AARCH64_RN (insn_3) == AARCH64_RD (insn_1)); |
4104 | 0 | } |
4105 | | |
4106 | | |
4107 | | /* Test for the presence of Cortex-A53 erratum 843419 instruction sequence. |
4108 | | |
4109 | | Return TRUE if section CONTENTS at offset I contains one of the |
4110 | | erratum 843419 sequences, otherwise return FALSE. If a sequence is |
4111 | | seen set P_VENEER_I to the offset of the final LOAD/STORE |
4112 | | instruction in the sequence. |
4113 | | */ |
4114 | | |
4115 | | static bool |
4116 | | _bfd_aarch64_erratum_843419_p (bfd_byte *contents, bfd_vma vma, |
4117 | | bfd_vma i, bfd_vma span_end, |
4118 | | bfd_vma *p_veneer_i) |
4119 | 0 | { |
4120 | 0 | uint32_t insn_1 = bfd_getl32 (contents + i); |
4121 | |
|
4122 | 0 | if (!_bfd_aarch64_adrp_p (insn_1)) |
4123 | 0 | return false; |
4124 | | |
4125 | 0 | if (span_end < i + 12) |
4126 | 0 | return false; |
4127 | | |
4128 | 0 | uint32_t insn_2 = bfd_getl32 (contents + i + 4); |
4129 | 0 | uint32_t insn_3 = bfd_getl32 (contents + i + 8); |
4130 | |
|
4131 | 0 | if ((vma & 0xfff) != 0xff8 && (vma & 0xfff) != 0xffc) |
4132 | 0 | return false; |
4133 | | |
4134 | 0 | if (_bfd_aarch64_erratum_843419_sequence_p (insn_1, insn_2, insn_3)) |
4135 | 0 | { |
4136 | 0 | *p_veneer_i = i + 8; |
4137 | 0 | return true; |
4138 | 0 | } |
4139 | | |
4140 | 0 | if (span_end < i + 16) |
4141 | 0 | return false; |
4142 | | |
4143 | 0 | uint32_t insn_4 = bfd_getl32 (contents + i + 12); |
4144 | |
|
4145 | 0 | if (_bfd_aarch64_erratum_843419_sequence_p (insn_1, insn_2, insn_4)) |
4146 | 0 | { |
4147 | 0 | *p_veneer_i = i + 12; |
4148 | 0 | return true; |
4149 | 0 | } |
4150 | | |
4151 | 0 | return false; |
4152 | 0 | } |
4153 | | |
4154 | | |
4155 | | /* Resize all stub sections. */ |
4156 | | |
4157 | | static void |
4158 | | _bfd_aarch64_resize_stubs (struct elf_aarch64_link_hash_table *htab) |
4159 | 0 | { |
4160 | 0 | asection *section; |
4161 | | |
4162 | | /* OK, we've added some stubs. Find out the new size of the |
4163 | | stub sections. */ |
4164 | 0 | for (section = htab->stub_bfd->sections; |
4165 | 0 | section != NULL; section = section->next) |
4166 | 0 | { |
4167 | | /* Ignore non-stub sections. */ |
4168 | 0 | if (!strstr (section->name, STUB_SUFFIX)) |
4169 | 0 | continue; |
4170 | | |
4171 | | /* Add space for a branch. Add 8 bytes to keep section 8 byte aligned, |
4172 | | as long branch stubs contain a 64-bit address. */ |
4173 | 0 | section->size = 8; |
4174 | 0 | } |
4175 | |
|
4176 | 0 | bfd_hash_traverse (&htab->stub_hash_table, aarch64_size_one_stub, htab); |
4177 | |
|
4178 | 0 | for (section = htab->stub_bfd->sections; |
4179 | 0 | section != NULL; section = section->next) |
4180 | 0 | { |
4181 | 0 | if (!strstr (section->name, STUB_SUFFIX)) |
4182 | 0 | continue; |
4183 | | |
4184 | | /* Empty stub section. */ |
4185 | 0 | if (section->size == 8) |
4186 | 0 | section->size = 0; |
4187 | | |
4188 | | /* Ensure all stub sections have a size which is a multiple of |
4189 | | 4096. This is important in order to ensure that the insertion |
4190 | | of stub sections does not in itself move existing code around |
4191 | | in such a way that new errata sequences are created. We only do this |
4192 | | when the ADRP workaround is enabled. If only the ADR workaround is |
4193 | | enabled then the stubs workaround won't ever be used. */ |
4194 | 0 | if (htab->fix_erratum_843419 & ERRAT_ADRP) |
4195 | 0 | if (section->size) |
4196 | 0 | section->size = BFD_ALIGN (section->size, 0x1000); |
4197 | 0 | } |
4198 | 0 | } |
4199 | | |
4200 | | /* Construct an erratum 843419 workaround stub name. */ |
4201 | | |
4202 | | static char * |
4203 | | _bfd_aarch64_erratum_843419_stub_name (asection *input_section, |
4204 | | bfd_vma offset) |
4205 | 0 | { |
4206 | 0 | const bfd_size_type len = 8 + 4 + 1 + 8 + 1 + 16 + 1; |
4207 | 0 | char *stub_name = bfd_malloc (len); |
4208 | |
|
4209 | 0 | if (stub_name != NULL) |
4210 | 0 | snprintf (stub_name, len, "e843419@%04x_%08x_%" PRIx64, |
4211 | 0 | input_section->owner->id, |
4212 | 0 | input_section->id, |
4213 | 0 | (uint64_t) offset); |
4214 | 0 | return stub_name; |
4215 | 0 | } |
4216 | | |
4217 | | /* Build a stub_entry structure describing an 843419 fixup. |
4218 | | |
4219 | | The stub_entry constructed is populated with the bit pattern INSN |
4220 | | of the instruction located at OFFSET within input SECTION. |
4221 | | |
4222 | | Returns TRUE on success. */ |
4223 | | |
4224 | | static bool |
4225 | | _bfd_aarch64_erratum_843419_fixup (uint32_t insn, |
4226 | | bfd_vma adrp_offset, |
4227 | | bfd_vma ldst_offset, |
4228 | | asection *section, |
4229 | | struct bfd_link_info *info) |
4230 | 0 | { |
4231 | 0 | struct elf_aarch64_link_hash_table *htab = elf_aarch64_hash_table (info); |
4232 | 0 | char *stub_name; |
4233 | 0 | struct elf_aarch64_stub_hash_entry *stub_entry; |
4234 | |
|
4235 | 0 | stub_name = _bfd_aarch64_erratum_843419_stub_name (section, ldst_offset); |
4236 | 0 | if (stub_name == NULL) |
4237 | 0 | return false; |
4238 | 0 | stub_entry = aarch64_stub_hash_lookup (&htab->stub_hash_table, stub_name, |
4239 | 0 | false, false); |
4240 | 0 | if (stub_entry) |
4241 | 0 | { |
4242 | 0 | free (stub_name); |
4243 | 0 | return true; |
4244 | 0 | } |
4245 | | |
4246 | | /* We always place an 843419 workaround veneer in the stub section |
4247 | | attached to the input section in which an erratum sequence has |
4248 | | been found. This ensures that later in the link process (in |
4249 | | elf64_aarch64_write_section) when we copy the veneered |
4250 | | instruction from the input section into the stub section the |
4251 | | copied instruction will have had any relocations applied to it. |
4252 | | If we placed workaround veneers in any other stub section then we |
4253 | | could not assume that all relocations have been processed on the |
4254 | | corresponding input section at the point we output the stub |
4255 | | section. */ |
4256 | | |
4257 | 0 | stub_entry = _bfd_aarch64_add_stub_entry_after (stub_name, section, htab); |
4258 | 0 | if (stub_entry == NULL) |
4259 | 0 | { |
4260 | 0 | free (stub_name); |
4261 | 0 | return false; |
4262 | 0 | } |
4263 | | |
4264 | 0 | stub_entry->adrp_offset = adrp_offset; |
4265 | 0 | stub_entry->target_value = ldst_offset; |
4266 | 0 | stub_entry->target_section = section; |
4267 | 0 | stub_entry->stub_type = aarch64_stub_erratum_843419_veneer; |
4268 | 0 | stub_entry->veneered_insn = insn; |
4269 | 0 | stub_entry->output_name = stub_name; |
4270 | |
|
4271 | 0 | return true; |
4272 | 0 | } |
4273 | | |
4274 | | |
4275 | | /* Scan an input section looking for the signature of erratum 843419. |
4276 | | |
4277 | | Scans input SECTION in INPUT_BFD looking for erratum 843419 |
4278 | | signatures, for each signature found a stub_entry is created |
4279 | | describing the location of the erratum for subsequent fixup. |
4280 | | |
4281 | | Return TRUE on successful scan, FALSE on failure to scan. |
4282 | | */ |
4283 | | |
4284 | | static bool |
4285 | | _bfd_aarch64_erratum_843419_scan (bfd *input_bfd, asection *section, |
4286 | | struct bfd_link_info *info) |
4287 | 0 | { |
4288 | 0 | struct elf_aarch64_link_hash_table *htab = elf_aarch64_hash_table (info); |
4289 | |
|
4290 | 0 | if (htab == NULL) |
4291 | 0 | return true; |
4292 | | |
4293 | 0 | if (elf_section_type (section) != SHT_PROGBITS |
4294 | 0 | || (elf_section_flags (section) & SHF_EXECINSTR) == 0 |
4295 | 0 | || (section->flags & SEC_EXCLUDE) != 0 |
4296 | 0 | || (section->sec_info_type == SEC_INFO_TYPE_JUST_SYMS) |
4297 | 0 | || (section->output_section == bfd_abs_section_ptr)) |
4298 | 0 | return true; |
4299 | | |
4300 | 0 | do |
4301 | 0 | { |
4302 | 0 | bfd_byte *contents = NULL; |
4303 | 0 | struct _aarch64_elf_section_data *sec_data; |
4304 | 0 | unsigned int span; |
4305 | |
|
4306 | 0 | if (elf_section_data (section)->this_hdr.contents != NULL) |
4307 | 0 | contents = elf_section_data (section)->this_hdr.contents; |
4308 | 0 | else if (! bfd_malloc_and_get_section (input_bfd, section, &contents)) |
4309 | 0 | return false; |
4310 | | |
4311 | 0 | sec_data = elf_aarch64_section_data (section); |
4312 | |
|
4313 | 0 | if (sec_data->mapcount) |
4314 | 0 | qsort (sec_data->map, sec_data->mapcount, |
4315 | 0 | sizeof (elf_aarch64_section_map), elf_aarch64_compare_mapping); |
4316 | |
|
4317 | 0 | for (span = 0; span < sec_data->mapcount; span++) |
4318 | 0 | { |
4319 | 0 | unsigned int span_start = sec_data->map[span].vma; |
4320 | 0 | unsigned int span_end = ((span == sec_data->mapcount - 1) |
4321 | 0 | ? sec_data->map[0].vma + section->size |
4322 | 0 | : sec_data->map[span + 1].vma); |
4323 | 0 | unsigned int i; |
4324 | 0 | char span_type = sec_data->map[span].type; |
4325 | |
|
4326 | 0 | if (span_type == 'd') |
4327 | 0 | continue; |
4328 | | |
4329 | 0 | for (i = span_start; i + 8 < span_end; i += 4) |
4330 | 0 | { |
4331 | 0 | bfd_vma vma = (section->output_section->vma |
4332 | 0 | + section->output_offset |
4333 | 0 | + i); |
4334 | 0 | bfd_vma veneer_i; |
4335 | |
|
4336 | 0 | if (_bfd_aarch64_erratum_843419_p |
4337 | 0 | (contents, vma, i, span_end, &veneer_i)) |
4338 | 0 | { |
4339 | 0 | uint32_t insn = bfd_getl32 (contents + veneer_i); |
4340 | |
|
4341 | 0 | if (!_bfd_aarch64_erratum_843419_fixup (insn, i, veneer_i, |
4342 | 0 | section, info)) |
4343 | 0 | return false; |
4344 | 0 | } |
4345 | 0 | } |
4346 | 0 | } |
4347 | | |
4348 | 0 | if (elf_section_data (section)->this_hdr.contents == NULL) |
4349 | 0 | free (contents); |
4350 | 0 | } |
4351 | 0 | while (0); |
4352 | | |
4353 | 0 | return true; |
4354 | 0 | } |
4355 | | |
4356 | | |
4357 | | /* Add stub entries for calls. |
4358 | | |
4359 | | The basic idea here is to examine all the relocations looking for |
4360 | | PC-relative calls to a target that is unreachable with a "bl" |
4361 | | instruction. */ |
4362 | | |
4363 | | static bool |
4364 | | _bfd_aarch64_add_call_stub_entries (bool *stub_changed, bfd *output_bfd, |
4365 | | struct bfd_link_info *info) |
4366 | 0 | { |
4367 | 0 | struct elf_aarch64_link_hash_table *htab = elf_aarch64_hash_table (info); |
4368 | 0 | bool need_bti = elf_aarch64_bti_p (output_bfd); |
4369 | 0 | bfd *input_bfd; |
4370 | |
|
4371 | 0 | for (input_bfd = info->input_bfds; input_bfd != NULL; |
4372 | 0 | input_bfd = input_bfd->link.next) |
4373 | 0 | { |
4374 | 0 | Elf_Internal_Shdr *symtab_hdr; |
4375 | 0 | asection *section; |
4376 | 0 | Elf_Internal_Sym *local_syms = NULL; |
4377 | |
|
4378 | 0 | if (!is_aarch64_elf (input_bfd) |
4379 | 0 | || (input_bfd->flags & BFD_LINKER_CREATED) != 0) |
4380 | 0 | continue; |
4381 | | |
4382 | | /* We'll need the symbol table in a second. */ |
4383 | 0 | symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr; |
4384 | 0 | if (symtab_hdr->sh_info == 0) |
4385 | 0 | continue; |
4386 | | |
4387 | | /* Walk over each section attached to the input bfd. */ |
4388 | 0 | for (section = input_bfd->sections; |
4389 | 0 | section != NULL; section = section->next) |
4390 | 0 | { |
4391 | 0 | Elf_Internal_Rela *internal_relocs, *irelaend, *irela; |
4392 | | |
4393 | | /* If there aren't any relocs, then there's nothing more to do. */ |
4394 | 0 | if ((section->flags & SEC_RELOC) == 0 |
4395 | 0 | || section->reloc_count == 0 |
4396 | 0 | || (section->flags & SEC_CODE) == 0) |
4397 | 0 | continue; |
4398 | | |
4399 | | /* If this section is a link-once section that will be |
4400 | | discarded, then don't create any stubs. */ |
4401 | 0 | if (section->output_section == NULL |
4402 | 0 | || section->output_section->owner != output_bfd) |
4403 | 0 | continue; |
4404 | | |
4405 | | /* Get the relocs. */ |
4406 | 0 | internal_relocs |
4407 | 0 | = _bfd_elf_link_read_relocs (input_bfd, section, NULL, |
4408 | 0 | NULL, info->keep_memory); |
4409 | 0 | if (internal_relocs == NULL) |
4410 | 0 | goto error_ret_free_local; |
4411 | | |
4412 | | /* Now examine each relocation. */ |
4413 | 0 | irela = internal_relocs; |
4414 | 0 | irelaend = irela + section->reloc_count; |
4415 | 0 | for (; irela < irelaend; irela++) |
4416 | 0 | { |
4417 | 0 | unsigned int r_type, r_indx; |
4418 | 0 | enum elf_aarch64_stub_type stub_type; |
4419 | 0 | struct elf_aarch64_stub_hash_entry *stub_entry; |
4420 | 0 | struct elf_aarch64_stub_hash_entry *stub_entry_bti; |
4421 | 0 | asection *sym_sec; |
4422 | 0 | bfd_vma sym_value; |
4423 | 0 | bfd_vma destination; |
4424 | 0 | struct elf_aarch64_link_hash_entry *hash; |
4425 | 0 | const char *sym_name; |
4426 | 0 | char *stub_name; |
4427 | 0 | char *stub_name_bti; |
4428 | 0 | const asection *id_sec; |
4429 | 0 | const asection *id_sec_bti; |
4430 | 0 | unsigned char st_type; |
4431 | 0 | bfd_size_type len; |
4432 | |
|
4433 | 0 | r_type = ELF64_R_TYPE (irela->r_info); |
4434 | 0 | r_indx = ELF64_R_SYM (irela->r_info); |
4435 | |
|
4436 | 0 | if (r_type >= (unsigned int) R_AARCH64_end) |
4437 | 0 | { |
4438 | 0 | bfd_set_error (bfd_error_bad_value); |
4439 | 0 | error_ret_free_internal: |
4440 | 0 | if (elf_section_data (section)->relocs == NULL) |
4441 | 0 | free (internal_relocs); |
4442 | 0 | goto error_ret_free_local; |
4443 | 0 | } |
4444 | | |
4445 | | /* Only look for stubs on unconditional branch and |
4446 | | branch and link instructions. */ |
4447 | 0 | if (r_type != (unsigned int) AARCH64_R (CALL26) |
4448 | 0 | && r_type != (unsigned int) AARCH64_R (JUMP26)) |
4449 | 0 | continue; |
4450 | | |
4451 | | /* Now determine the call target, its name, value, |
4452 | | section. */ |
4453 | 0 | sym_sec = NULL; |
4454 | 0 | sym_value = 0; |
4455 | 0 | destination = 0; |
4456 | 0 | hash = NULL; |
4457 | 0 | sym_name = NULL; |
4458 | 0 | if (r_indx < symtab_hdr->sh_info) |
4459 | 0 | { |
4460 | | /* It's a local symbol. */ |
4461 | 0 | Elf_Internal_Sym *sym; |
4462 | 0 | Elf_Internal_Shdr *hdr; |
4463 | |
|
4464 | 0 | if (local_syms == NULL) |
4465 | 0 | { |
4466 | 0 | local_syms |
4467 | 0 | = (Elf_Internal_Sym *) symtab_hdr->contents; |
4468 | 0 | if (local_syms == NULL) |
4469 | 0 | local_syms |
4470 | 0 | = bfd_elf_get_elf_syms (input_bfd, symtab_hdr, |
4471 | 0 | symtab_hdr->sh_info, 0, |
4472 | 0 | NULL, NULL, NULL); |
4473 | 0 | if (local_syms == NULL) |
4474 | 0 | goto error_ret_free_internal; |
4475 | 0 | } |
4476 | | |
4477 | 0 | sym = local_syms + r_indx; |
4478 | 0 | hdr = elf_elfsections (input_bfd)[sym->st_shndx]; |
4479 | 0 | sym_sec = hdr->bfd_section; |
4480 | 0 | if (!sym_sec) |
4481 | | /* This is an undefined symbol. It can never |
4482 | | be resolved. */ |
4483 | 0 | continue; |
4484 | | |
4485 | 0 | if (ELF_ST_TYPE (sym->st_info) != STT_SECTION) |
4486 | 0 | sym_value = sym->st_value; |
4487 | 0 | destination = (sym_value + irela->r_addend |
4488 | 0 | + sym_sec->output_offset |
4489 | 0 | + sym_sec->output_section->vma); |
4490 | 0 | st_type = ELF_ST_TYPE (sym->st_info); |
4491 | 0 | sym_name |
4492 | 0 | = bfd_elf_string_from_elf_section (input_bfd, |
4493 | 0 | symtab_hdr->sh_link, |
4494 | 0 | sym->st_name); |
4495 | 0 | } |
4496 | 0 | else |
4497 | 0 | { |
4498 | 0 | int e_indx; |
4499 | |
|
4500 | 0 | e_indx = r_indx - symtab_hdr->sh_info; |
4501 | 0 | hash = ((struct elf_aarch64_link_hash_entry *) |
4502 | 0 | elf_sym_hashes (input_bfd)[e_indx]); |
4503 | |
|
4504 | 0 | while (hash->root.root.type == bfd_link_hash_indirect |
4505 | 0 | || hash->root.root.type == bfd_link_hash_warning) |
4506 | 0 | hash = ((struct elf_aarch64_link_hash_entry *) |
4507 | 0 | hash->root.root.u.i.link); |
4508 | |
|
4509 | 0 | if (hash->root.root.type == bfd_link_hash_defined |
4510 | 0 | || hash->root.root.type == bfd_link_hash_defweak) |
4511 | 0 | { |
4512 | 0 | struct elf_aarch64_link_hash_table *globals = |
4513 | 0 | elf_aarch64_hash_table (info); |
4514 | 0 | sym_sec = hash->root.root.u.def.section; |
4515 | 0 | sym_value = hash->root.root.u.def.value; |
4516 | | /* For a destination in a shared library, |
4517 | | use the PLT stub as target address to |
4518 | | decide whether a branch stub is |
4519 | | needed. */ |
4520 | 0 | if (globals->root.splt != NULL && hash != NULL |
4521 | 0 | && hash->root.plt.offset != (bfd_vma) - 1) |
4522 | 0 | { |
4523 | 0 | sym_sec = globals->root.splt; |
4524 | 0 | sym_value = hash->root.plt.offset; |
4525 | 0 | if (sym_sec->output_section != NULL) |
4526 | 0 | destination = (sym_value |
4527 | 0 | + sym_sec->output_offset |
4528 | 0 | + sym_sec->output_section->vma); |
4529 | 0 | } |
4530 | 0 | else if (sym_sec->output_section != NULL) |
4531 | 0 | destination = (sym_value + irela->r_addend |
4532 | 0 | + sym_sec->output_offset |
4533 | 0 | + sym_sec->output_section->vma); |
4534 | 0 | } |
4535 | 0 | else if (hash->root.root.type == bfd_link_hash_undefined |
4536 | 0 | || (hash->root.root.type |
4537 | 0 | == bfd_link_hash_undefweak)) |
4538 | 0 | { |
4539 | | /* For a shared library, use the PLT stub as |
4540 | | target address to decide whether a long |
4541 | | branch stub is needed. |
4542 | | For absolute code, they cannot be handled. */ |
4543 | 0 | struct elf_aarch64_link_hash_table *globals = |
4544 | 0 | elf_aarch64_hash_table (info); |
4545 | |
|
4546 | 0 | if (globals->root.splt != NULL && hash != NULL |
4547 | 0 | && hash->root.plt.offset != (bfd_vma) - 1) |
4548 | 0 | { |
4549 | 0 | sym_sec = globals->root.splt; |
4550 | 0 | sym_value = hash->root.plt.offset; |
4551 | 0 | if (sym_sec->output_section != NULL) |
4552 | 0 | destination = (sym_value |
4553 | 0 | + sym_sec->output_offset |
4554 | 0 | + sym_sec->output_section->vma); |
4555 | 0 | } |
4556 | 0 | else |
4557 | 0 | continue; |
4558 | 0 | } |
4559 | 0 | else |
4560 | 0 | { |
4561 | 0 | bfd_set_error (bfd_error_bad_value); |
4562 | 0 | goto error_ret_free_internal; |
4563 | 0 | } |
4564 | 0 | st_type = ELF_ST_TYPE (hash->root.type); |
4565 | 0 | sym_name = hash->root.root.root.string; |
4566 | 0 | } |
4567 | | |
4568 | | /* Determine what (if any) linker stub is needed. */ |
4569 | 0 | stub_type = aarch64_type_of_stub (section, irela, sym_sec, |
4570 | 0 | st_type, destination); |
4571 | 0 | if (stub_type == aarch64_stub_none) |
4572 | 0 | continue; |
4573 | | |
4574 | | /* Support for grouping stub sections. */ |
4575 | 0 | id_sec = htab->stub_group[section->id].link_sec; |
4576 | | |
4577 | | /* Get the name of this stub. */ |
4578 | 0 | stub_name = elf64_aarch64_stub_name (id_sec, sym_sec, hash, |
4579 | 0 | irela); |
4580 | 0 | if (!stub_name) |
4581 | 0 | goto error_ret_free_internal; |
4582 | | |
4583 | 0 | stub_entry = |
4584 | 0 | aarch64_stub_hash_lookup (&htab->stub_hash_table, |
4585 | 0 | stub_name, false, false); |
4586 | 0 | if (stub_entry != NULL) |
4587 | 0 | { |
4588 | | /* The proper stub has already been created. */ |
4589 | 0 | free (stub_name); |
4590 | | |
4591 | | /* Always update this stub's target since it may have |
4592 | | changed after layout. */ |
4593 | 0 | stub_entry->target_value = sym_value + irela->r_addend; |
4594 | |
|
4595 | 0 | if (stub_entry->double_stub) |
4596 | 0 | { |
4597 | | /* Update the target of both stubs. */ |
4598 | |
|
4599 | 0 | id_sec_bti = htab->stub_group[sym_sec->id].link_sec; |
4600 | 0 | stub_name_bti = |
4601 | 0 | elf64_aarch64_stub_name (id_sec_bti, sym_sec, hash, |
4602 | 0 | irela); |
4603 | 0 | if (!stub_name_bti) |
4604 | 0 | goto error_ret_free_internal; |
4605 | 0 | stub_entry_bti = |
4606 | 0 | aarch64_stub_hash_lookup (&htab->stub_hash_table, |
4607 | 0 | stub_name_bti, false, false); |
4608 | 0 | BFD_ASSERT (stub_entry_bti != NULL); |
4609 | 0 | free (stub_name_bti); |
4610 | 0 | stub_entry_bti->target_value = stub_entry->target_value; |
4611 | 0 | stub_entry->target_value = stub_entry_bti->stub_offset; |
4612 | 0 | } |
4613 | 0 | continue; |
4614 | 0 | } |
4615 | | |
4616 | 0 | stub_entry = _bfd_aarch64_add_stub_entry_in_group |
4617 | 0 | (stub_name, section, htab); |
4618 | 0 | if (stub_entry == NULL) |
4619 | 0 | { |
4620 | 0 | free (stub_name); |
4621 | 0 | goto error_ret_free_internal; |
4622 | 0 | } |
4623 | | |
4624 | 0 | stub_entry->target_value = sym_value + irela->r_addend; |
4625 | 0 | stub_entry->target_section = sym_sec; |
4626 | 0 | stub_entry->stub_type = stub_type; |
4627 | 0 | stub_entry->h = hash; |
4628 | 0 | stub_entry->st_type = st_type; |
4629 | |
|
4630 | 0 | if (sym_name == NULL) |
4631 | 0 | sym_name = "unnamed"; |
4632 | 0 | len = sizeof (STUB_ENTRY_NAME) + strlen (sym_name); |
4633 | 0 | stub_entry->output_name = bfd_alloc (htab->stub_bfd, len); |
4634 | 0 | if (stub_entry->output_name == NULL) |
4635 | 0 | { |
4636 | 0 | free (stub_name); |
4637 | 0 | goto error_ret_free_internal; |
4638 | 0 | } |
4639 | | |
4640 | 0 | snprintf (stub_entry->output_name, len, STUB_ENTRY_NAME, |
4641 | 0 | sym_name); |
4642 | | |
4643 | | /* A stub with indirect jump may break BTI compatibility, so |
4644 | | insert another stub with direct jump near the target then. */ |
4645 | 0 | if (need_bti && !aarch64_bti_stub_p (info, stub_entry)) |
4646 | 0 | { |
4647 | 0 | id_sec_bti = htab->stub_group[sym_sec->id].link_sec; |
4648 | | |
4649 | | /* If the stub with indirect jump and the BTI stub are in |
4650 | | the same stub group: change the indirect jump stub into |
4651 | | a BTI stub since a direct branch can reach the target. |
4652 | | The BTI landing pad is still needed in case another |
4653 | | stub indirectly jumps to it. */ |
4654 | 0 | if (id_sec_bti == id_sec) |
4655 | 0 | { |
4656 | 0 | stub_entry->stub_type = aarch64_stub_bti_direct_branch; |
4657 | 0 | goto skip_double_stub; |
4658 | 0 | } |
4659 | | |
4660 | 0 | stub_entry->double_stub = true; |
4661 | 0 | htab->has_double_stub = true; |
4662 | |
|
4663 | 0 | stub_name_bti = |
4664 | 0 | elf64_aarch64_stub_name (id_sec_bti, sym_sec, hash, irela); |
4665 | 0 | if (!stub_name_bti) |
4666 | 0 | { |
4667 | 0 | free (stub_name); |
4668 | 0 | goto error_ret_free_internal; |
4669 | 0 | } |
4670 | | |
4671 | 0 | stub_entry_bti = |
4672 | 0 | aarch64_stub_hash_lookup (&htab->stub_hash_table, |
4673 | 0 | stub_name_bti, false, false); |
4674 | 0 | if (stub_entry_bti != NULL) |
4675 | 0 | BFD_ASSERT (stub_entry_bti->stub_type |
4676 | 0 | == aarch64_stub_bti_direct_branch); |
4677 | 0 | else |
4678 | 0 | { |
4679 | 0 | stub_entry_bti = |
4680 | 0 | _bfd_aarch64_add_stub_entry_in_group (stub_name_bti, |
4681 | 0 | sym_sec, htab); |
4682 | 0 | if (stub_entry_bti == NULL) |
4683 | 0 | { |
4684 | 0 | free (stub_name); |
4685 | 0 | free (stub_name_bti); |
4686 | 0 | goto error_ret_free_internal; |
4687 | 0 | } |
4688 | | |
4689 | 0 | stub_entry_bti->target_value = |
4690 | 0 | sym_value + irela->r_addend; |
4691 | 0 | stub_entry_bti->target_section = sym_sec; |
4692 | 0 | stub_entry_bti->stub_type = |
4693 | 0 | aarch64_stub_bti_direct_branch; |
4694 | 0 | stub_entry_bti->h = hash; |
4695 | 0 | stub_entry_bti->st_type = st_type; |
4696 | |
|
4697 | 0 | len = sizeof (BTI_STUB_ENTRY_NAME) + strlen (sym_name); |
4698 | 0 | stub_entry_bti->output_name = bfd_alloc (htab->stub_bfd, |
4699 | 0 | len); |
4700 | 0 | if (stub_entry_bti->output_name == NULL) |
4701 | 0 | { |
4702 | 0 | free (stub_name); |
4703 | 0 | free (stub_name_bti); |
4704 | 0 | goto error_ret_free_internal; |
4705 | 0 | } |
4706 | 0 | snprintf (stub_entry_bti->output_name, len, |
4707 | 0 | BTI_STUB_ENTRY_NAME, sym_name); |
4708 | 0 | } |
4709 | | |
4710 | | /* Update the indirect call stub to target the BTI stub. */ |
4711 | 0 | stub_entry->target_value = 0; |
4712 | 0 | stub_entry->target_section = stub_entry_bti->stub_sec; |
4713 | 0 | stub_entry->stub_type = stub_type; |
4714 | 0 | stub_entry->h = NULL; |
4715 | 0 | stub_entry->st_type = STT_FUNC; |
4716 | 0 | } |
4717 | 0 | skip_double_stub: |
4718 | 0 | *stub_changed = true; |
4719 | 0 | } |
4720 | | |
4721 | | /* We're done with the internal relocs, free them. */ |
4722 | 0 | if (elf_section_data (section)->relocs == NULL) |
4723 | 0 | free (internal_relocs); |
4724 | 0 | } |
4725 | 0 | } |
4726 | 0 | return true; |
4727 | 0 | error_ret_free_local: |
4728 | 0 | return false; |
4729 | 0 | } |
4730 | | |
4731 | | |
4732 | | /* Determine and set the size of the stub section for a final link. */ |
4733 | | |
4734 | | bool |
4735 | | elf64_aarch64_size_stubs (bfd *output_bfd, |
4736 | | bfd *stub_bfd, |
4737 | | struct bfd_link_info *info, |
4738 | | bfd_signed_vma group_size, |
4739 | | asection * (*add_stub_section) (const char *, |
4740 | | asection *), |
4741 | | void (*layout_sections_again) (void)) |
4742 | 0 | { |
4743 | 0 | bfd_size_type stub_group_size; |
4744 | 0 | bool stubs_always_before_branch; |
4745 | 0 | struct elf_aarch64_link_hash_table *htab = elf_aarch64_hash_table (info); |
4746 | 0 | unsigned int num_erratum_835769_fixes = 0; |
4747 | | |
4748 | | /* Propagate mach to stub bfd, because it may not have been |
4749 | | finalized when we created stub_bfd. */ |
4750 | 0 | bfd_set_arch_mach (stub_bfd, bfd_get_arch (output_bfd), |
4751 | 0 | bfd_get_mach (output_bfd)); |
4752 | | |
4753 | | /* Stash our params away. */ |
4754 | 0 | htab->stub_bfd = stub_bfd; |
4755 | 0 | htab->add_stub_section = add_stub_section; |
4756 | 0 | htab->layout_sections_again = layout_sections_again; |
4757 | 0 | stubs_always_before_branch = group_size < 0; |
4758 | 0 | if (group_size < 0) |
4759 | 0 | stub_group_size = -group_size; |
4760 | 0 | else |
4761 | 0 | stub_group_size = group_size; |
4762 | |
|
4763 | 0 | if (stub_group_size == 1) |
4764 | 0 | { |
4765 | | /* Default values. */ |
4766 | | /* AArch64 branch range is +-128MB. The value used is 1MB less. */ |
4767 | 0 | stub_group_size = 127 * 1024 * 1024; |
4768 | 0 | } |
4769 | |
|
4770 | 0 | group_sections (htab, stub_group_size, stubs_always_before_branch); |
4771 | |
|
4772 | 0 | (*htab->layout_sections_again) (); |
4773 | |
|
4774 | 0 | if (htab->fix_erratum_835769) |
4775 | 0 | { |
4776 | 0 | bfd *input_bfd; |
4777 | |
|
4778 | 0 | for (input_bfd = info->input_bfds; |
4779 | 0 | input_bfd != NULL; input_bfd = input_bfd->link.next) |
4780 | 0 | { |
4781 | 0 | if (!is_aarch64_elf (input_bfd) |
4782 | 0 | || (input_bfd->flags & BFD_LINKER_CREATED) != 0) |
4783 | 0 | continue; |
4784 | | |
4785 | 0 | if (!_bfd_aarch64_erratum_835769_scan (input_bfd, info, |
4786 | 0 | &num_erratum_835769_fixes)) |
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 | if (htab->fix_erratum_843419 != ERRAT_NONE) |
4795 | 0 | { |
4796 | 0 | bfd *input_bfd; |
4797 | |
|
4798 | 0 | for (input_bfd = info->input_bfds; |
4799 | 0 | input_bfd != NULL; |
4800 | 0 | input_bfd = input_bfd->link.next) |
4801 | 0 | { |
4802 | 0 | asection *section; |
4803 | |
|
4804 | 0 | if (!is_aarch64_elf (input_bfd) |
4805 | 0 | || (input_bfd->flags & BFD_LINKER_CREATED) != 0) |
4806 | 0 | continue; |
4807 | | |
4808 | 0 | for (section = input_bfd->sections; |
4809 | 0 | section != NULL; |
4810 | 0 | section = section->next) |
4811 | 0 | if (!_bfd_aarch64_erratum_843419_scan (input_bfd, section, info)) |
4812 | 0 | return false; |
4813 | 0 | } |
4814 | | |
4815 | 0 | _bfd_aarch64_resize_stubs (htab); |
4816 | 0 | (*htab->layout_sections_again) (); |
4817 | 0 | } |
4818 | | |
4819 | 0 | for (;;) |
4820 | 0 | { |
4821 | 0 | bool stub_changed = false; |
4822 | |
|
4823 | 0 | if (!_bfd_aarch64_add_call_stub_entries (&stub_changed, output_bfd, info)) |
4824 | 0 | return false; |
4825 | | |
4826 | 0 | if (!stub_changed) |
4827 | 0 | return true; |
4828 | | |
4829 | 0 | _bfd_aarch64_resize_stubs (htab); |
4830 | 0 | (*htab->layout_sections_again) (); |
4831 | 0 | } |
4832 | 0 | } |
4833 | | |
4834 | | /* Build all the stubs associated with the current output file. The |
4835 | | stubs are kept in a hash table attached to the main linker hash |
4836 | | table. We also set up the .plt entries for statically linked PIC |
4837 | | functions here. This function is called via aarch64_elf_finish in the |
4838 | | linker. */ |
4839 | | |
4840 | | bool |
4841 | | elf64_aarch64_build_stubs (struct bfd_link_info *info) |
4842 | 0 | { |
4843 | 0 | asection *stub_sec; |
4844 | 0 | struct bfd_hash_table *table; |
4845 | 0 | struct elf_aarch64_link_hash_table *htab; |
4846 | |
|
4847 | 0 | htab = elf_aarch64_hash_table (info); |
4848 | |
|
4849 | 0 | for (stub_sec = htab->stub_bfd->sections; |
4850 | 0 | stub_sec != NULL; stub_sec = stub_sec->next) |
4851 | 0 | { |
4852 | 0 | bfd_size_type size; |
4853 | | |
4854 | | /* Ignore non-stub sections. */ |
4855 | 0 | if (!strstr (stub_sec->name, STUB_SUFFIX)) |
4856 | 0 | continue; |
4857 | | |
4858 | | /* Allocate memory to hold the linker stubs. */ |
4859 | 0 | size = stub_sec->size; |
4860 | 0 | stub_sec->contents = bfd_zalloc (htab->stub_bfd, size); |
4861 | 0 | if (stub_sec->contents == NULL && size != 0) |
4862 | 0 | return false; |
4863 | 0 | stub_sec->alloced = 1; |
4864 | 0 | stub_sec->size = 0; |
4865 | | |
4866 | | /* Add a branch around the stub section, and a nop, to keep it 8 byte |
4867 | | aligned, as long branch stubs contain a 64-bit address. */ |
4868 | 0 | bfd_putl32 (0x14000000 | (size >> 2), stub_sec->contents); |
4869 | 0 | bfd_putl32 (INSN_NOP, stub_sec->contents + 4); |
4870 | 0 | stub_sec->size += 8; |
4871 | 0 | } |
4872 | | |
4873 | | /* Build the stubs as directed by the stub hash table. */ |
4874 | 0 | table = &htab->stub_hash_table; |
4875 | 0 | bfd_hash_traverse (table, aarch64_build_one_stub, info); |
4876 | |
|
4877 | 0 | return true; |
4878 | 0 | } |
4879 | | |
4880 | | |
4881 | | /* Add an entry to the code/data map for section SEC. */ |
4882 | | |
4883 | | static void |
4884 | | elf64_aarch64_section_map_add (asection *sec, char type, bfd_vma vma) |
4885 | 0 | { |
4886 | 0 | struct _aarch64_elf_section_data *sec_data = |
4887 | 0 | elf_aarch64_section_data (sec); |
4888 | 0 | unsigned int newidx; |
4889 | |
|
4890 | 0 | if (sec_data->map == NULL) |
4891 | 0 | { |
4892 | 0 | sec_data->map = bfd_malloc (sizeof (elf_aarch64_section_map)); |
4893 | 0 | sec_data->mapcount = 0; |
4894 | 0 | sec_data->mapsize = 1; |
4895 | 0 | } |
4896 | |
|
4897 | 0 | newidx = sec_data->mapcount++; |
4898 | |
|
4899 | 0 | if (sec_data->mapcount > sec_data->mapsize) |
4900 | 0 | { |
4901 | 0 | sec_data->mapsize *= 2; |
4902 | 0 | sec_data->map = bfd_realloc_or_free |
4903 | 0 | (sec_data->map, sec_data->mapsize * sizeof (elf_aarch64_section_map)); |
4904 | 0 | } |
4905 | |
|
4906 | 0 | if (sec_data->map) |
4907 | 0 | { |
4908 | 0 | sec_data->map[newidx].vma = vma; |
4909 | 0 | sec_data->map[newidx].type = type; |
4910 | 0 | } |
4911 | 0 | } |
4912 | | |
4913 | | |
4914 | | /* Initialise maps of insn/data for input BFDs. */ |
4915 | | void |
4916 | | bfd_elf64_aarch64_init_maps (bfd *abfd) |
4917 | 0 | { |
4918 | 0 | Elf_Internal_Sym *isymbuf; |
4919 | 0 | Elf_Internal_Shdr *hdr; |
4920 | 0 | unsigned int i, localsyms; |
4921 | | |
4922 | | /* Make sure that we are dealing with an AArch64 elf binary. */ |
4923 | 0 | if (!is_aarch64_elf (abfd)) |
4924 | 0 | return; |
4925 | | |
4926 | 0 | if ((abfd->flags & DYNAMIC) != 0) |
4927 | 0 | return; |
4928 | | |
4929 | 0 | hdr = &elf_symtab_hdr (abfd); |
4930 | 0 | localsyms = hdr->sh_info; |
4931 | | |
4932 | | /* Obtain a buffer full of symbols for this BFD. The hdr->sh_info field |
4933 | | should contain the number of local symbols, which should come before any |
4934 | | global symbols. Mapping symbols are always local. */ |
4935 | 0 | isymbuf = bfd_elf_get_elf_syms (abfd, hdr, localsyms, 0, NULL, NULL, NULL); |
4936 | | |
4937 | | /* No internal symbols read? Skip this BFD. */ |
4938 | 0 | if (isymbuf == NULL) |
4939 | 0 | return; |
4940 | | |
4941 | 0 | for (i = 0; i < localsyms; i++) |
4942 | 0 | { |
4943 | 0 | Elf_Internal_Sym *isym = &isymbuf[i]; |
4944 | 0 | asection *sec = bfd_section_from_elf_index (abfd, isym->st_shndx); |
4945 | 0 | const char *name; |
4946 | |
|
4947 | 0 | if (sec != NULL && ELF_ST_BIND (isym->st_info) == STB_LOCAL) |
4948 | 0 | { |
4949 | 0 | name = bfd_elf_string_from_elf_section (abfd, |
4950 | 0 | hdr->sh_link, |
4951 | 0 | isym->st_name); |
4952 | |
|
4953 | 0 | if (bfd_is_aarch64_special_symbol_name |
4954 | 0 | (name, BFD_AARCH64_SPECIAL_SYM_TYPE_MAP)) |
4955 | 0 | elf64_aarch64_section_map_add (sec, name[1], isym->st_value); |
4956 | 0 | } |
4957 | 0 | } |
4958 | 0 | } |
4959 | | |
4960 | | static void |
4961 | | setup_plt_values (struct bfd_link_info *link_info, |
4962 | | aarch64_plt_type plt_type) |
4963 | 0 | { |
4964 | 0 | struct elf_aarch64_link_hash_table *globals; |
4965 | 0 | globals = elf_aarch64_hash_table (link_info); |
4966 | |
|
4967 | 0 | if (plt_type == PLT_BTI_PAC) |
4968 | 0 | { |
4969 | 0 | globals->plt0_entry = elf64_aarch64_small_plt0_bti_entry; |
4970 | | |
4971 | | /* Only in ET_EXEC we need PLTn with BTI. */ |
4972 | 0 | if (bfd_link_executable (link_info)) |
4973 | 0 | { |
4974 | 0 | globals->plt_entry_size = PLT_BTI_PAC_SMALL_ENTRY_SIZE; |
4975 | 0 | globals->plt_entry = elf64_aarch64_small_plt_bti_pac_entry; |
4976 | 0 | globals->plt_entry_delta = 4; |
4977 | 0 | } |
4978 | 0 | else |
4979 | 0 | { |
4980 | 0 | globals->plt_entry_size = PLT_PAC_SMALL_ENTRY_SIZE; |
4981 | 0 | globals->plt_entry = elf64_aarch64_small_plt_pac_entry; |
4982 | 0 | globals->plt_entry_delta = 0; |
4983 | 0 | } |
4984 | 0 | } |
4985 | 0 | else if (plt_type == PLT_BTI) |
4986 | 0 | { |
4987 | 0 | globals->plt0_entry = elf64_aarch64_small_plt0_bti_entry; |
4988 | | |
4989 | | /* Only in ET_EXEC we need PLTn with BTI. */ |
4990 | 0 | if (bfd_link_executable (link_info)) |
4991 | 0 | { |
4992 | 0 | globals->plt_entry_size = PLT_BTI_SMALL_ENTRY_SIZE; |
4993 | 0 | globals->plt_entry = elf64_aarch64_small_plt_bti_entry; |
4994 | 0 | globals->plt_entry_delta = 4; |
4995 | 0 | } |
4996 | 0 | } |
4997 | 0 | else if (plt_type == PLT_PAC) |
4998 | 0 | { |
4999 | 0 | globals->plt_entry_size = PLT_PAC_SMALL_ENTRY_SIZE; |
5000 | 0 | globals->plt_entry = elf64_aarch64_small_plt_pac_entry; |
5001 | 0 | } |
5002 | 0 | } |
5003 | | |
5004 | | /* Set option values needed during linking. */ |
5005 | | void |
5006 | | bfd_elf64_aarch64_set_options (struct bfd *output_bfd, |
5007 | | struct bfd_link_info *link_info, |
5008 | | int no_enum_warn, |
5009 | | int no_wchar_warn, int pic_veneer, |
5010 | | int fix_erratum_835769, |
5011 | | erratum_84319_opts fix_erratum_843419, |
5012 | | int no_apply_dynamic_relocs, |
5013 | | const aarch64_protection_opts *sw_protections) |
5014 | 0 | { |
5015 | 0 | struct elf_aarch64_link_hash_table *globals; |
5016 | |
|
5017 | 0 | globals = elf_aarch64_hash_table (link_info); |
5018 | 0 | globals->pic_veneer = pic_veneer; |
5019 | 0 | globals->fix_erratum_835769 = fix_erratum_835769; |
5020 | | /* If the default options are used, then ERRAT_ADR will be set by default |
5021 | | which will enable the ADRP->ADR workaround for the erratum 843419 |
5022 | | workaround. */ |
5023 | 0 | globals->fix_erratum_843419 = fix_erratum_843419; |
5024 | 0 | globals->no_apply_dynamic_relocs = no_apply_dynamic_relocs; |
5025 | |
|
5026 | 0 | BFD_ASSERT (is_aarch64_elf (output_bfd)); |
5027 | 0 | elf_aarch64_tdata (output_bfd)->no_enum_size_warning = no_enum_warn; |
5028 | 0 | elf_aarch64_tdata (output_bfd)->no_wchar_size_warning = no_wchar_warn; |
5029 | | |
5030 | | /* Note: gnu_property_aarch64_feature_1_and was initialized to 0 by |
5031 | | bfd_zalloc(). */ |
5032 | 0 | if (sw_protections->plt_type & PLT_BTI) |
5033 | 0 | elf_aarch64_tdata (output_bfd)->gnu_property_aarch64_feature_1_and |
5034 | 0 | |= GNU_PROPERTY_AARCH64_FEATURE_1_BTI; |
5035 | |
|
5036 | 0 | switch (sw_protections->gcs_type) |
5037 | 0 | { |
5038 | 0 | case GCS_ALWAYS: |
5039 | 0 | elf_aarch64_tdata (output_bfd)->gnu_property_aarch64_feature_1_and |
5040 | 0 | |= GNU_PROPERTY_AARCH64_FEATURE_1_GCS; |
5041 | 0 | break; |
5042 | 0 | case GCS_NEVER: |
5043 | 0 | elf_aarch64_tdata (output_bfd)->gnu_property_aarch64_feature_1_and |
5044 | 0 | &= ~GNU_PROPERTY_AARCH64_FEATURE_1_GCS; |
5045 | 0 | break; |
5046 | 0 | case GCS_IMPLICIT: |
5047 | | /* GCS feature on the output bfd will be deduced from input objects. */ |
5048 | 0 | break; |
5049 | 0 | } |
5050 | | |
5051 | 0 | elf_aarch64_tdata (output_bfd)->sw_protections = *sw_protections; |
5052 | | /* Inherit the value from '-z gcs-report' if the option '-z gcs-report-dynamic' |
5053 | | was not set on the command line. However, the inheritance mechanism is |
5054 | | capped to avoid inheriting the error level from -g gcs-report as the user |
5055 | | might want to continue to build a module without rebuilding all the shared |
5056 | | libraries. If a user also wants to error GCS issues in the shared |
5057 | | libraries, '-z gcs-report-dynamic=error' will have to be specified |
5058 | | explicitly. */ |
5059 | 0 | if (sw_protections->gcs_report_dynamic == MARKING_UNSET) |
5060 | 0 | elf_aarch64_tdata (output_bfd)->sw_protections.gcs_report_dynamic |
5061 | 0 | = (sw_protections->gcs_report == MARKING_ERROR) |
5062 | 0 | ? MARKING_WARN |
5063 | 0 | : sw_protections->gcs_report; |
5064 | |
|
5065 | 0 | elf_aarch64_tdata (output_bfd)->n_bti_issues = 0; |
5066 | 0 | elf_aarch64_tdata (output_bfd)->n_gcs_issues = 0; |
5067 | 0 | elf_aarch64_tdata (output_bfd)->n_gcs_dynamic_issues = 0; |
5068 | |
|
5069 | 0 | setup_plt_values (link_info, sw_protections->plt_type); |
5070 | 0 | } |
5071 | | |
5072 | | static bfd_vma |
5073 | | aarch64_calculate_got_entry_vma (struct elf_link_hash_entry *h, |
5074 | | struct elf_aarch64_link_hash_table |
5075 | | *globals, struct bfd_link_info *info, |
5076 | | bfd_vma value, bfd *output_bfd, |
5077 | | bool *unresolved_reloc_p) |
5078 | 0 | { |
5079 | 0 | bfd_vma off = (bfd_vma) - 1; |
5080 | 0 | asection *basegot = globals->root.sgot; |
5081 | 0 | bool dyn = globals->root.dynamic_sections_created; |
5082 | |
|
5083 | 0 | if (h != NULL) |
5084 | 0 | { |
5085 | 0 | BFD_ASSERT (basegot != NULL); |
5086 | 0 | off = h->got.offset; |
5087 | 0 | BFD_ASSERT (off != (bfd_vma) - 1); |
5088 | 0 | if (!WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, bfd_link_pic (info), h) |
5089 | 0 | || (bfd_link_pic (info) |
5090 | 0 | && SYMBOL_REFERENCES_LOCAL (info, h)) |
5091 | 0 | || (ELF_ST_VISIBILITY (h->other) |
5092 | 0 | && h->root.type == bfd_link_hash_undefweak)) |
5093 | 0 | { |
5094 | | /* This is actually a static link, or it is a -Bsymbolic link |
5095 | | and the symbol is defined locally. We must initialize this |
5096 | | entry in the global offset table. Since the offset must |
5097 | | always be a multiple of 8 (4 in the case of ILP32), we use |
5098 | | the least significant bit to record whether we have |
5099 | | initialized it already. |
5100 | | When doing a dynamic link, we create a .rel(a).got relocation |
5101 | | entry to initialize the value. This is done in the |
5102 | | finish_dynamic_symbol routine. */ |
5103 | 0 | if ((off & 1) != 0) |
5104 | 0 | off &= ~1; |
5105 | 0 | else |
5106 | 0 | { |
5107 | 0 | bfd_put_64 (output_bfd, value, basegot->contents + off); |
5108 | 0 | h->got.offset |= 1; |
5109 | 0 | } |
5110 | 0 | } |
5111 | 0 | else |
5112 | 0 | *unresolved_reloc_p = false; |
5113 | |
|
5114 | 0 | off = off + basegot->output_section->vma + basegot->output_offset; |
5115 | 0 | } |
5116 | |
|
5117 | 0 | return off; |
5118 | 0 | } |
5119 | | |
5120 | | /* Change R_TYPE to a more efficient access model where possible, |
5121 | | return the new reloc type. */ |
5122 | | |
5123 | | static bfd_reloc_code_real_type |
5124 | | aarch64_tls_transition_without_check (bfd_reloc_code_real_type r_type, |
5125 | | struct elf_link_hash_entry *h, |
5126 | | struct bfd_link_info *info) |
5127 | 0 | { |
5128 | 0 | bool local_exec = bfd_link_executable (info) |
5129 | 0 | && SYMBOL_REFERENCES_LOCAL (info, h); |
5130 | |
|
5131 | 0 | switch (r_type) |
5132 | 0 | { |
5133 | 0 | case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21: |
5134 | 0 | case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21: |
5135 | 0 | return (local_exec |
5136 | 0 | ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1 |
5137 | 0 | : BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21); |
5138 | | |
5139 | 0 | case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21: |
5140 | 0 | return (local_exec |
5141 | 0 | ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC |
5142 | 0 | : r_type); |
5143 | | |
5144 | 0 | case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19: |
5145 | 0 | return (local_exec |
5146 | 0 | ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1 |
5147 | 0 | : BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19); |
5148 | | |
5149 | 0 | case BFD_RELOC_AARCH64_TLSDESC_LDR: |
5150 | 0 | return (local_exec |
5151 | 0 | ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC |
5152 | 0 | : BFD_RELOC_AARCH64_NONE); |
5153 | | |
5154 | 0 | case BFD_RELOC_AARCH64_TLSDESC_OFF_G0_NC: |
5155 | 0 | return (local_exec |
5156 | 0 | ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1_NC |
5157 | 0 | : BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G0_NC); |
5158 | | |
5159 | 0 | case BFD_RELOC_AARCH64_TLSDESC_OFF_G1: |
5160 | 0 | return (local_exec |
5161 | 0 | ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G2 |
5162 | 0 | : BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G1); |
5163 | | |
5164 | 0 | case BFD_RELOC_AARCH64_TLSDESC_LD64_LO12_NC: |
5165 | 0 | case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC: |
5166 | 0 | return (local_exec |
5167 | 0 | ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC |
5168 | 0 | : BFD_RELOC_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC); |
5169 | | |
5170 | 0 | case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21: |
5171 | 0 | return local_exec ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1 : r_type; |
5172 | | |
5173 | 0 | case BFD_RELOC_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC: |
5174 | 0 | return local_exec ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC : r_type; |
5175 | | |
5176 | 0 | case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19: |
5177 | 0 | return r_type; |
5178 | | |
5179 | 0 | case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21: |
5180 | 0 | return (local_exec |
5181 | 0 | ? BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_HI12 |
5182 | 0 | : BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19); |
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_CALL: |
5187 | | /* Instructions with these relocations will become NOPs. */ |
5188 | 0 | return BFD_RELOC_AARCH64_NONE; |
5189 | | |
5190 | 0 | case BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC: |
5191 | 0 | case BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21: |
5192 | 0 | case BFD_RELOC_AARCH64_TLSLD_ADR_PREL21: |
5193 | 0 | return local_exec ? BFD_RELOC_AARCH64_NONE : r_type; |
5194 | | |
5195 | 0 | #if ARCH_SIZE == 64 |
5196 | 0 | case BFD_RELOC_AARCH64_TLSGD_MOVW_G0_NC: |
5197 | 0 | return local_exec |
5198 | 0 | ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1_NC |
5199 | 0 | : BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G0_NC; |
5200 | | |
5201 | 0 | case BFD_RELOC_AARCH64_TLSGD_MOVW_G1: |
5202 | 0 | return local_exec |
5203 | 0 | ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G2 |
5204 | 0 | : BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G1; |
5205 | 0 | #endif |
5206 | | |
5207 | 0 | default: |
5208 | 0 | break; |
5209 | 0 | } |
5210 | | |
5211 | 0 | return r_type; |
5212 | 0 | } |
5213 | | |
5214 | | static unsigned int |
5215 | | aarch64_reloc_got_type (bfd_reloc_code_real_type r_type) |
5216 | 0 | { |
5217 | 0 | switch (r_type) |
5218 | 0 | { |
5219 | 0 | case BFD_RELOC_AARCH64_ADR_GOT_PAGE: |
5220 | 0 | case BFD_RELOC_AARCH64_GOT_LD_PREL19: |
5221 | 0 | case BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14: |
5222 | 0 | case BFD_RELOC_AARCH64_LD32_GOT_LO12_NC: |
5223 | 0 | case BFD_RELOC_AARCH64_LD64_GOTOFF_LO15: |
5224 | 0 | case BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15: |
5225 | 0 | case BFD_RELOC_AARCH64_LD64_GOT_LO12_NC: |
5226 | 0 | case BFD_RELOC_AARCH64_MOVW_GOTOFF_G0_NC: |
5227 | 0 | case BFD_RELOC_AARCH64_MOVW_GOTOFF_G1: |
5228 | 0 | return GOT_NORMAL; |
5229 | | |
5230 | 0 | case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC: |
5231 | 0 | case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21: |
5232 | 0 | case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21: |
5233 | 0 | case BFD_RELOC_AARCH64_TLSGD_MOVW_G0_NC: |
5234 | 0 | case BFD_RELOC_AARCH64_TLSGD_MOVW_G1: |
5235 | 0 | case BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC: |
5236 | 0 | case BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21: |
5237 | 0 | case BFD_RELOC_AARCH64_TLSLD_ADR_PREL21: |
5238 | 0 | return GOT_TLS_GD; |
5239 | | |
5240 | 0 | case BFD_RELOC_AARCH64_TLSDESC_ADD: |
5241 | 0 | case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12: |
5242 | 0 | case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21: |
5243 | 0 | case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21: |
5244 | 0 | case BFD_RELOC_AARCH64_TLSDESC_CALL: |
5245 | 0 | case BFD_RELOC_AARCH64_TLSDESC_LD32_LO12_NC: |
5246 | 0 | case BFD_RELOC_AARCH64_TLSDESC_LD64_LO12: |
5247 | 0 | case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19: |
5248 | 0 | case BFD_RELOC_AARCH64_TLSDESC_LDR: |
5249 | 0 | case BFD_RELOC_AARCH64_TLSDESC_OFF_G0_NC: |
5250 | 0 | case BFD_RELOC_AARCH64_TLSDESC_OFF_G1: |
5251 | 0 | return GOT_TLSDESC_GD; |
5252 | | |
5253 | 0 | case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21: |
5254 | 0 | case BFD_RELOC_AARCH64_TLSIE_LD32_GOTTPREL_LO12_NC: |
5255 | 0 | case BFD_RELOC_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC: |
5256 | 0 | case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19: |
5257 | 0 | case BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G0_NC: |
5258 | 0 | case BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G1: |
5259 | 0 | return GOT_TLS_IE; |
5260 | | |
5261 | 0 | default: |
5262 | 0 | break; |
5263 | 0 | } |
5264 | 0 | return GOT_UNKNOWN; |
5265 | 0 | } |
5266 | | |
5267 | | static bool |
5268 | | aarch64_can_relax_tls (bfd *input_bfd, |
5269 | | struct bfd_link_info *info, |
5270 | | bfd_reloc_code_real_type r_type, |
5271 | | struct elf_link_hash_entry *h, |
5272 | | unsigned long r_symndx) |
5273 | 0 | { |
5274 | 0 | unsigned int symbol_got_type; |
5275 | 0 | unsigned int reloc_got_type; |
5276 | |
|
5277 | 0 | if (! IS_AARCH64_TLS_RELAX_RELOC (r_type)) |
5278 | 0 | return false; |
5279 | | |
5280 | 0 | symbol_got_type = elf64_aarch64_symbol_got_type (h, input_bfd, r_symndx); |
5281 | 0 | reloc_got_type = aarch64_reloc_got_type (r_type); |
5282 | |
|
5283 | 0 | if (symbol_got_type == GOT_TLS_IE && GOT_TLS_GD_ANY_P (reloc_got_type)) |
5284 | 0 | return true; |
5285 | | |
5286 | 0 | if (!bfd_link_executable (info)) |
5287 | 0 | return false; |
5288 | | |
5289 | 0 | if (h && h->root.type == bfd_link_hash_undefweak) |
5290 | 0 | return false; |
5291 | | |
5292 | 0 | return true; |
5293 | 0 | } |
5294 | | |
5295 | | /* Given the relocation code R_TYPE, return the relaxed bfd reloc |
5296 | | enumerator. */ |
5297 | | |
5298 | | static bfd_reloc_code_real_type |
5299 | | aarch64_tls_transition (bfd *input_bfd, |
5300 | | struct bfd_link_info *info, |
5301 | | unsigned int r_type, |
5302 | | struct elf_link_hash_entry *h, |
5303 | | unsigned long r_symndx) |
5304 | 0 | { |
5305 | 0 | bfd_reloc_code_real_type bfd_r_type |
5306 | 0 | = elf64_aarch64_bfd_reloc_from_type (input_bfd, r_type); |
5307 | |
|
5308 | 0 | if (! aarch64_can_relax_tls (input_bfd, info, bfd_r_type, h, r_symndx)) |
5309 | 0 | return bfd_r_type; |
5310 | | |
5311 | 0 | return aarch64_tls_transition_without_check (bfd_r_type, h, info); |
5312 | 0 | } |
5313 | | |
5314 | | /* Return the base VMA address which should be subtracted from real addresses |
5315 | | when resolving R_AARCH64_TLS_DTPREL relocation. */ |
5316 | | |
5317 | | static bfd_vma |
5318 | | dtpoff_base (struct bfd_link_info *info) |
5319 | 0 | { |
5320 | | /* If tls_sec is NULL, we should have signalled an error already. */ |
5321 | 0 | BFD_ASSERT (elf_hash_table (info)->tls_sec != NULL); |
5322 | 0 | return elf_hash_table (info)->tls_sec->vma; |
5323 | 0 | } |
5324 | | |
5325 | | /* Return the base VMA address which should be subtracted from real addresses |
5326 | | when resolving R_AARCH64_TLS_GOTTPREL64 relocations. */ |
5327 | | |
5328 | | static bfd_vma |
5329 | | tpoff_base (struct bfd_link_info *info) |
5330 | 0 | { |
5331 | 0 | struct elf_link_hash_table *htab = elf_hash_table (info); |
5332 | | |
5333 | | /* If tls_sec is NULL, we should have signalled an error already. */ |
5334 | 0 | BFD_ASSERT (htab->tls_sec != NULL); |
5335 | |
|
5336 | 0 | bfd_vma base = align_power ((bfd_vma) TCB_SIZE, |
5337 | 0 | htab->tls_sec->alignment_power); |
5338 | 0 | return htab->tls_sec->vma - base; |
5339 | 0 | } |
5340 | | |
5341 | | static bfd_vma * |
5342 | | symbol_got_offset_ref (bfd *input_bfd, struct elf_link_hash_entry *h, |
5343 | | unsigned long r_symndx) |
5344 | 0 | { |
5345 | | /* Calculate the address of the GOT entry for symbol |
5346 | | referred to in h. */ |
5347 | 0 | if (h != NULL) |
5348 | 0 | return &h->got.offset; |
5349 | 0 | else |
5350 | 0 | { |
5351 | | /* local symbol */ |
5352 | 0 | struct elf_aarch64_local_symbol *l; |
5353 | |
|
5354 | 0 | l = elf_aarch64_locals (input_bfd); |
5355 | 0 | return &l[r_symndx].got_offset; |
5356 | 0 | } |
5357 | 0 | } |
5358 | | |
5359 | | static void |
5360 | | symbol_got_offset_mark (bfd *input_bfd, struct elf_link_hash_entry *h, |
5361 | | unsigned long r_symndx) |
5362 | 0 | { |
5363 | 0 | bfd_vma *p; |
5364 | 0 | p = symbol_got_offset_ref (input_bfd, h, r_symndx); |
5365 | 0 | *p |= 1; |
5366 | 0 | } |
5367 | | |
5368 | | static int |
5369 | | symbol_got_offset_mark_p (bfd *input_bfd, struct elf_link_hash_entry *h, |
5370 | | unsigned long r_symndx) |
5371 | 0 | { |
5372 | 0 | bfd_vma value; |
5373 | 0 | value = * symbol_got_offset_ref (input_bfd, h, r_symndx); |
5374 | 0 | return value & 1; |
5375 | 0 | } |
5376 | | |
5377 | | static bfd_vma |
5378 | | symbol_got_offset (bfd *input_bfd, struct elf_link_hash_entry *h, |
5379 | | unsigned long r_symndx) |
5380 | 0 | { |
5381 | 0 | bfd_vma value; |
5382 | 0 | value = * symbol_got_offset_ref (input_bfd, h, r_symndx); |
5383 | 0 | value &= ~1; |
5384 | 0 | return value; |
5385 | 0 | } |
5386 | | |
5387 | | static bfd_vma * |
5388 | | symbol_tlsdesc_got_offset_ref (bfd *input_bfd, struct elf_link_hash_entry *h, |
5389 | | unsigned long r_symndx) |
5390 | 0 | { |
5391 | | /* Calculate the address of the GOT entry for symbol |
5392 | | referred to in h. */ |
5393 | 0 | if (h != NULL) |
5394 | 0 | { |
5395 | 0 | struct elf_aarch64_link_hash_entry *eh; |
5396 | 0 | eh = (struct elf_aarch64_link_hash_entry *) h; |
5397 | 0 | return &eh->tlsdesc_got_jump_table_offset; |
5398 | 0 | } |
5399 | 0 | else |
5400 | 0 | { |
5401 | | /* local symbol */ |
5402 | 0 | struct elf_aarch64_local_symbol *l; |
5403 | |
|
5404 | 0 | l = elf_aarch64_locals (input_bfd); |
5405 | 0 | return &l[r_symndx].tlsdesc_got_jump_table_offset; |
5406 | 0 | } |
5407 | 0 | } |
5408 | | |
5409 | | static void |
5410 | | symbol_tlsdesc_got_offset_mark (bfd *input_bfd, struct elf_link_hash_entry *h, |
5411 | | unsigned long r_symndx) |
5412 | 0 | { |
5413 | 0 | bfd_vma *p; |
5414 | 0 | p = symbol_tlsdesc_got_offset_ref (input_bfd, h, r_symndx); |
5415 | 0 | *p |= 1; |
5416 | 0 | } |
5417 | | |
5418 | | static int |
5419 | | symbol_tlsdesc_got_offset_mark_p (bfd *input_bfd, |
5420 | | struct elf_link_hash_entry *h, |
5421 | | unsigned long r_symndx) |
5422 | 0 | { |
5423 | 0 | bfd_vma value; |
5424 | 0 | value = * symbol_tlsdesc_got_offset_ref (input_bfd, h, r_symndx); |
5425 | 0 | return value & 1; |
5426 | 0 | } |
5427 | | |
5428 | | static bfd_vma |
5429 | | symbol_tlsdesc_got_offset (bfd *input_bfd, struct elf_link_hash_entry *h, |
5430 | | unsigned long r_symndx) |
5431 | 0 | { |
5432 | 0 | bfd_vma value; |
5433 | 0 | value = * symbol_tlsdesc_got_offset_ref (input_bfd, h, r_symndx); |
5434 | 0 | value &= ~1; |
5435 | 0 | return value; |
5436 | 0 | } |
5437 | | |
5438 | | /* Data for make_branch_to_erratum_835769_stub(). */ |
5439 | | |
5440 | | struct erratum_835769_branch_to_stub_data |
5441 | | { |
5442 | | struct bfd_link_info *info; |
5443 | | asection *output_section; |
5444 | | bfd_byte *contents; |
5445 | | }; |
5446 | | |
5447 | | /* Helper to insert branches to erratum 835769 stubs in the right |
5448 | | places for a particular section. */ |
5449 | | |
5450 | | static bool |
5451 | | make_branch_to_erratum_835769_stub (struct bfd_hash_entry *gen_entry, |
5452 | | void *in_arg) |
5453 | 0 | { |
5454 | 0 | struct elf_aarch64_stub_hash_entry *stub_entry; |
5455 | 0 | struct erratum_835769_branch_to_stub_data *data; |
5456 | 0 | bfd_byte *contents; |
5457 | 0 | unsigned long branch_insn = 0; |
5458 | 0 | bfd_vma veneered_insn_loc, veneer_entry_loc; |
5459 | 0 | bfd_signed_vma branch_offset; |
5460 | 0 | unsigned int target; |
5461 | 0 | bfd *abfd; |
5462 | |
|
5463 | 0 | stub_entry = (struct elf_aarch64_stub_hash_entry *) gen_entry; |
5464 | 0 | data = (struct erratum_835769_branch_to_stub_data *) in_arg; |
5465 | |
|
5466 | 0 | if (stub_entry->target_section != data->output_section |
5467 | 0 | || stub_entry->stub_type != aarch64_stub_erratum_835769_veneer) |
5468 | 0 | return true; |
5469 | | |
5470 | 0 | contents = data->contents; |
5471 | 0 | veneered_insn_loc = stub_entry->target_section->output_section->vma |
5472 | 0 | + stub_entry->target_section->output_offset |
5473 | 0 | + stub_entry->target_value; |
5474 | 0 | veneer_entry_loc = stub_entry->stub_sec->output_section->vma |
5475 | 0 | + stub_entry->stub_sec->output_offset |
5476 | 0 | + stub_entry->stub_offset; |
5477 | 0 | branch_offset = veneer_entry_loc - veneered_insn_loc; |
5478 | |
|
5479 | 0 | abfd = stub_entry->target_section->owner; |
5480 | 0 | if (!aarch64_valid_branch_p (veneer_entry_loc, veneered_insn_loc)) |
5481 | 0 | _bfd_error_handler |
5482 | 0 | (_("%pB: error: erratum 835769 stub out " |
5483 | 0 | "of range (input file too large)"), abfd); |
5484 | |
|
5485 | 0 | target = stub_entry->target_value; |
5486 | 0 | branch_insn = 0x14000000; |
5487 | 0 | branch_offset >>= 2; |
5488 | 0 | branch_offset &= 0x3ffffff; |
5489 | 0 | branch_insn |= branch_offset; |
5490 | 0 | bfd_putl32 (branch_insn, &contents[target]); |
5491 | |
|
5492 | 0 | return true; |
5493 | 0 | } |
5494 | | |
5495 | | |
5496 | | static bool |
5497 | | _bfd_aarch64_erratum_843419_branch_to_stub (struct bfd_hash_entry *gen_entry, |
5498 | | void *in_arg) |
5499 | 0 | { |
5500 | 0 | struct elf_aarch64_stub_hash_entry *stub_entry |
5501 | 0 | = (struct elf_aarch64_stub_hash_entry *) gen_entry; |
5502 | 0 | struct erratum_835769_branch_to_stub_data *data |
5503 | 0 | = (struct erratum_835769_branch_to_stub_data *) in_arg; |
5504 | 0 | struct bfd_link_info *info; |
5505 | 0 | struct elf_aarch64_link_hash_table *htab; |
5506 | 0 | bfd_byte *contents; |
5507 | 0 | asection *section; |
5508 | 0 | bfd *abfd; |
5509 | 0 | bfd_vma place; |
5510 | 0 | uint32_t insn; |
5511 | |
|
5512 | 0 | info = data->info; |
5513 | 0 | contents = data->contents; |
5514 | 0 | section = data->output_section; |
5515 | |
|
5516 | 0 | htab = elf_aarch64_hash_table (info); |
5517 | |
|
5518 | 0 | if (stub_entry->target_section != section |
5519 | 0 | || stub_entry->stub_type != aarch64_stub_erratum_843419_veneer) |
5520 | 0 | return true; |
5521 | | |
5522 | 0 | BFD_ASSERT (((htab->fix_erratum_843419 & ERRAT_ADRP) && stub_entry->stub_sec) |
5523 | 0 | || (htab->fix_erratum_843419 & ERRAT_ADR)); |
5524 | | |
5525 | | /* Only update the stub section if we have one. We should always have one if |
5526 | | we're allowed to use the ADRP errata workaround, otherwise it is not |
5527 | | required. */ |
5528 | 0 | if (stub_entry->stub_sec) |
5529 | 0 | { |
5530 | 0 | insn = bfd_getl32 (contents + stub_entry->target_value); |
5531 | 0 | bfd_putl32 (insn, |
5532 | 0 | stub_entry->stub_sec->contents + stub_entry->stub_offset); |
5533 | 0 | } |
5534 | |
|
5535 | 0 | place = (section->output_section->vma + section->output_offset |
5536 | 0 | + stub_entry->adrp_offset); |
5537 | 0 | insn = bfd_getl32 (contents + stub_entry->adrp_offset); |
5538 | |
|
5539 | 0 | if (!_bfd_aarch64_adrp_p (insn)) |
5540 | 0 | abort (); |
5541 | | |
5542 | 0 | bfd_signed_vma imm = |
5543 | 0 | (_bfd_aarch64_sign_extend |
5544 | 0 | ((bfd_vma) _bfd_aarch64_decode_adrp_imm (insn) << 12, 33) |
5545 | 0 | - (place & 0xfff)); |
5546 | |
|
5547 | 0 | if ((htab->fix_erratum_843419 & ERRAT_ADR) |
5548 | 0 | && (imm >= AARCH64_MIN_ADRP_IMM && imm <= AARCH64_MAX_ADRP_IMM)) |
5549 | 0 | { |
5550 | 0 | insn = (_bfd_aarch64_reencode_adr_imm (AARCH64_ADR_OP, imm) |
5551 | 0 | | AARCH64_RT (insn)); |
5552 | 0 | bfd_putl32 (insn, contents + stub_entry->adrp_offset); |
5553 | | /* Stub is not needed, don't map it out. */ |
5554 | 0 | stub_entry->stub_type = aarch64_stub_none; |
5555 | 0 | } |
5556 | 0 | else if (htab->fix_erratum_843419 & ERRAT_ADRP) |
5557 | 0 | { |
5558 | 0 | bfd_vma veneered_insn_loc; |
5559 | 0 | bfd_vma veneer_entry_loc; |
5560 | 0 | bfd_signed_vma branch_offset; |
5561 | 0 | uint32_t branch_insn; |
5562 | |
|
5563 | 0 | veneered_insn_loc = stub_entry->target_section->output_section->vma |
5564 | 0 | + stub_entry->target_section->output_offset |
5565 | 0 | + stub_entry->target_value; |
5566 | 0 | veneer_entry_loc = stub_entry->stub_sec->output_section->vma |
5567 | 0 | + stub_entry->stub_sec->output_offset |
5568 | 0 | + stub_entry->stub_offset; |
5569 | 0 | branch_offset = veneer_entry_loc - veneered_insn_loc; |
5570 | |
|
5571 | 0 | abfd = stub_entry->target_section->owner; |
5572 | 0 | if (!aarch64_valid_branch_p (veneer_entry_loc, veneered_insn_loc)) |
5573 | 0 | _bfd_error_handler |
5574 | 0 | (_("%pB: error: erratum 843419 stub out " |
5575 | 0 | "of range (input file too large)"), abfd); |
5576 | |
|
5577 | 0 | branch_insn = 0x14000000; |
5578 | 0 | branch_offset >>= 2; |
5579 | 0 | branch_offset &= 0x3ffffff; |
5580 | 0 | branch_insn |= branch_offset; |
5581 | 0 | bfd_putl32 (branch_insn, contents + stub_entry->target_value); |
5582 | 0 | } |
5583 | 0 | else |
5584 | 0 | { |
5585 | 0 | abfd = stub_entry->target_section->owner; |
5586 | 0 | _bfd_error_handler |
5587 | 0 | (_("%pB: error: erratum 843419 immediate 0x%" PRIx64 |
5588 | 0 | " out of range for ADR (input file too large) and " |
5589 | 0 | "--fix-cortex-a53-843419=adr used. Run the linker with " |
5590 | 0 | "--fix-cortex-a53-843419=full instead"), |
5591 | 0 | abfd, (uint64_t) (bfd_vma) imm); |
5592 | 0 | bfd_set_error (bfd_error_bad_value); |
5593 | | /* This function is called inside a hashtable traversal and the error |
5594 | | handlers called above turn into non-fatal errors. Which means this |
5595 | | case ld returns an exit code 0 and also produces a broken object file. |
5596 | | To prevent this, issue a hard abort. */ |
5597 | 0 | BFD_FAIL (); |
5598 | 0 | } |
5599 | 0 | return true; |
5600 | 0 | } |
5601 | | |
5602 | | |
5603 | | static bool |
5604 | | elf64_aarch64_write_section (bfd *output_bfd ATTRIBUTE_UNUSED, |
5605 | | struct bfd_link_info *link_info, |
5606 | | asection *sec, |
5607 | | bfd_byte *contents) |
5608 | | |
5609 | 0 | { |
5610 | 0 | struct elf_aarch64_link_hash_table *globals = |
5611 | 0 | elf_aarch64_hash_table (link_info); |
5612 | |
|
5613 | 0 | if (globals == NULL) |
5614 | 0 | return false; |
5615 | | |
5616 | | /* Fix code to point to erratum 835769 stubs. */ |
5617 | 0 | if (globals->fix_erratum_835769) |
5618 | 0 | { |
5619 | 0 | struct erratum_835769_branch_to_stub_data data; |
5620 | |
|
5621 | 0 | data.info = link_info; |
5622 | 0 | data.output_section = sec; |
5623 | 0 | data.contents = contents; |
5624 | 0 | bfd_hash_traverse (&globals->stub_hash_table, |
5625 | 0 | make_branch_to_erratum_835769_stub, &data); |
5626 | 0 | } |
5627 | |
|
5628 | 0 | if (globals->fix_erratum_843419) |
5629 | 0 | { |
5630 | 0 | struct erratum_835769_branch_to_stub_data data; |
5631 | |
|
5632 | 0 | data.info = link_info; |
5633 | 0 | data.output_section = sec; |
5634 | 0 | data.contents = contents; |
5635 | 0 | bfd_hash_traverse (&globals->stub_hash_table, |
5636 | 0 | _bfd_aarch64_erratum_843419_branch_to_stub, &data); |
5637 | 0 | } |
5638 | |
|
5639 | 0 | return false; |
5640 | 0 | } |
5641 | | |
5642 | | /* Return TRUE if RELOC is a relocation against the base of GOT table. */ |
5643 | | |
5644 | | static bool |
5645 | | aarch64_relocation_aginst_gp_p (bfd_reloc_code_real_type reloc) |
5646 | 0 | { |
5647 | 0 | return (reloc == BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14 |
5648 | 0 | || reloc == BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15 |
5649 | 0 | || reloc == BFD_RELOC_AARCH64_LD64_GOTOFF_LO15 |
5650 | 0 | || reloc == BFD_RELOC_AARCH64_MOVW_GOTOFF_G0_NC |
5651 | 0 | || reloc == BFD_RELOC_AARCH64_MOVW_GOTOFF_G1); |
5652 | 0 | } |
5653 | | |
5654 | | /* Perform a relocation as part of a final link. The input relocation type |
5655 | | should be TLS relaxed. */ |
5656 | | |
5657 | | static bfd_reloc_status_type |
5658 | | elf64_aarch64_final_link_relocate (reloc_howto_type *howto, |
5659 | | bfd *input_bfd, |
5660 | | bfd *output_bfd, |
5661 | | asection *input_section, |
5662 | | bfd_byte *contents, |
5663 | | Elf_Internal_Rela *rel, |
5664 | | bfd_vma value, |
5665 | | struct bfd_link_info *info, |
5666 | | asection *sym_sec, |
5667 | | struct elf_link_hash_entry *h, |
5668 | | bool *unresolved_reloc_p, |
5669 | | bool save_addend, |
5670 | | bfd_vma *saved_addend, |
5671 | | Elf_Internal_Sym *sym) |
5672 | 0 | { |
5673 | 0 | Elf_Internal_Shdr *symtab_hdr; |
5674 | 0 | unsigned int r_type = howto->type; |
5675 | 0 | bfd_reloc_code_real_type bfd_r_type |
5676 | 0 | = elf64_aarch64_bfd_reloc_from_howto (howto); |
5677 | 0 | unsigned long r_symndx; |
5678 | 0 | bfd_byte *hit_data = contents + rel->r_offset; |
5679 | 0 | bfd_vma place, off, got_entry_addr = 0; |
5680 | 0 | bfd_signed_vma signed_addend; |
5681 | 0 | struct elf_aarch64_link_hash_table *globals; |
5682 | 0 | bool weak_undef_p; |
5683 | 0 | bool relative_reloc; |
5684 | 0 | asection *base_got; |
5685 | 0 | bfd_vma orig_value = value; |
5686 | 0 | bool resolved_to_zero; |
5687 | 0 | bool abs_symbol_p; |
5688 | |
|
5689 | 0 | globals = elf_aarch64_hash_table (info); |
5690 | |
|
5691 | 0 | symtab_hdr = &elf_symtab_hdr (input_bfd); |
5692 | |
|
5693 | 0 | BFD_ASSERT (is_aarch64_elf (input_bfd)); |
5694 | |
|
5695 | 0 | r_symndx = ELF64_R_SYM (rel->r_info); |
5696 | |
|
5697 | 0 | place = input_section->output_section->vma |
5698 | 0 | + input_section->output_offset + rel->r_offset; |
5699 | | |
5700 | | /* Get addend, accumulating the addend for consecutive relocs |
5701 | | which refer to the same offset. */ |
5702 | 0 | signed_addend = saved_addend ? *saved_addend : 0; |
5703 | 0 | signed_addend += rel->r_addend; |
5704 | |
|
5705 | 0 | weak_undef_p = (h ? h->root.type == bfd_link_hash_undefweak |
5706 | 0 | : bfd_is_und_section (sym_sec)); |
5707 | 0 | abs_symbol_p = h != NULL && bfd_is_abs_symbol (&h->root); |
5708 | | |
5709 | | |
5710 | | /* Since STT_GNU_IFUNC symbol must go through PLT, we handle |
5711 | | it here if it is defined in a non-shared object. */ |
5712 | 0 | if (h != NULL |
5713 | 0 | && h->type == STT_GNU_IFUNC |
5714 | 0 | && h->def_regular) |
5715 | 0 | { |
5716 | 0 | asection *plt; |
5717 | 0 | const char *name; |
5718 | 0 | bfd_vma addend = 0; |
5719 | |
|
5720 | 0 | if ((input_section->flags & SEC_ALLOC) == 0) |
5721 | 0 | { |
5722 | | /* If this is a SHT_NOTE section without SHF_ALLOC, treat |
5723 | | STT_GNU_IFUNC symbol as STT_FUNC. */ |
5724 | 0 | if (elf_section_type (input_section) == SHT_NOTE) |
5725 | 0 | goto skip_ifunc; |
5726 | | |
5727 | | /* Dynamic relocs are not propagated for SEC_DEBUGGING |
5728 | | sections because such sections are not SEC_ALLOC and |
5729 | | thus ld.so will not process them. */ |
5730 | 0 | if ((input_section->flags & SEC_DEBUGGING) != 0) |
5731 | 0 | return bfd_reloc_ok; |
5732 | | |
5733 | 0 | if (h->root.root.string) |
5734 | 0 | name = h->root.root.string; |
5735 | 0 | else |
5736 | 0 | name = bfd_elf_sym_name (input_bfd, symtab_hdr, sym, NULL); |
5737 | 0 | _bfd_error_handler |
5738 | | /* xgettext:c-format */ |
5739 | 0 | (_("%pB(%pA+%#" PRIx64 "): " |
5740 | 0 | "unresolvable %s relocation against symbol `%s'"), |
5741 | 0 | input_bfd, input_section, (uint64_t) rel->r_offset, |
5742 | 0 | howto->name, name); |
5743 | 0 | bfd_set_error (bfd_error_bad_value); |
5744 | 0 | return bfd_reloc_notsupported; |
5745 | 0 | } |
5746 | 0 | else if (h->plt.offset == (bfd_vma) -1) |
5747 | 0 | goto bad_ifunc_reloc; |
5748 | | |
5749 | | /* STT_GNU_IFUNC symbol must go through PLT. */ |
5750 | 0 | plt = globals->root.splt ? globals->root.splt : globals->root.iplt; |
5751 | 0 | value = (plt->output_section->vma + plt->output_offset + h->plt.offset); |
5752 | |
|
5753 | 0 | switch (bfd_r_type) |
5754 | 0 | { |
5755 | 0 | default: |
5756 | 0 | bad_ifunc_reloc: |
5757 | 0 | if (h->root.root.string) |
5758 | 0 | name = h->root.root.string; |
5759 | 0 | else |
5760 | 0 | name = bfd_elf_sym_name (input_bfd, symtab_hdr, sym, |
5761 | 0 | NULL); |
5762 | 0 | _bfd_error_handler |
5763 | | /* xgettext:c-format */ |
5764 | 0 | (_("%pB: relocation %s against STT_GNU_IFUNC " |
5765 | 0 | "symbol `%s' isn't handled by %s"), input_bfd, |
5766 | 0 | howto->name, name, __func__); |
5767 | 0 | bfd_set_error (bfd_error_bad_value); |
5768 | 0 | return bfd_reloc_notsupported; |
5769 | | |
5770 | 0 | case BFD_RELOC_AARCH64_64: |
5771 | 0 | if (rel->r_addend != 0) |
5772 | 0 | { |
5773 | 0 | if (h->root.root.string) |
5774 | 0 | name = h->root.root.string; |
5775 | 0 | else |
5776 | 0 | name = bfd_elf_sym_name (input_bfd, symtab_hdr, |
5777 | 0 | sym, NULL); |
5778 | 0 | _bfd_error_handler |
5779 | | /* xgettext:c-format */ |
5780 | 0 | (_("%pB: relocation %s against STT_GNU_IFUNC " |
5781 | 0 | "symbol `%s' has non-zero addend: %" PRId64), |
5782 | 0 | input_bfd, howto->name, name, (int64_t) rel->r_addend); |
5783 | 0 | bfd_set_error (bfd_error_bad_value); |
5784 | 0 | return bfd_reloc_notsupported; |
5785 | 0 | } |
5786 | | |
5787 | | /* Generate dynamic relocation only when there is a |
5788 | | non-GOT reference in a shared object. */ |
5789 | 0 | if (bfd_link_pic (info) && h->non_got_ref) |
5790 | 0 | { |
5791 | 0 | Elf_Internal_Rela outrel; |
5792 | 0 | asection *sreloc; |
5793 | | |
5794 | | /* Need a dynamic relocation to get the real function |
5795 | | address. */ |
5796 | 0 | outrel.r_offset = _bfd_elf_section_offset (output_bfd, |
5797 | 0 | info, |
5798 | 0 | input_section, |
5799 | 0 | rel->r_offset); |
5800 | 0 | if (outrel.r_offset == (bfd_vma) -1 |
5801 | 0 | || outrel.r_offset == (bfd_vma) -2) |
5802 | 0 | abort (); |
5803 | | |
5804 | 0 | outrel.r_offset += (input_section->output_section->vma |
5805 | 0 | + input_section->output_offset); |
5806 | |
|
5807 | 0 | if (h->dynindx == -1 |
5808 | 0 | || h->forced_local |
5809 | 0 | || bfd_link_executable (info)) |
5810 | 0 | { |
5811 | | /* This symbol is resolved locally. */ |
5812 | 0 | outrel.r_info = ELF64_R_INFO (0, AARCH64_R (IRELATIVE)); |
5813 | 0 | outrel.r_addend = (h->root.u.def.value |
5814 | 0 | + h->root.u.def.section->output_section->vma |
5815 | 0 | + h->root.u.def.section->output_offset); |
5816 | 0 | } |
5817 | 0 | else |
5818 | 0 | { |
5819 | 0 | outrel.r_info = ELF64_R_INFO (h->dynindx, r_type); |
5820 | 0 | outrel.r_addend = 0; |
5821 | 0 | } |
5822 | |
|
5823 | 0 | sreloc = globals->root.irelifunc; |
5824 | 0 | elf_append_rela (output_bfd, sreloc, &outrel); |
5825 | | |
5826 | | /* If this reloc is against an external symbol, we |
5827 | | do not want to fiddle with the addend. Otherwise, |
5828 | | we need to include the symbol value so that it |
5829 | | becomes an addend for the dynamic reloc. For an |
5830 | | internal symbol, we have updated addend. */ |
5831 | 0 | return bfd_reloc_ok; |
5832 | 0 | } |
5833 | | /* FALLTHROUGH */ |
5834 | 0 | case BFD_RELOC_AARCH64_CALL26: |
5835 | 0 | case BFD_RELOC_AARCH64_JUMP26: |
5836 | 0 | value = _bfd_aarch64_elf_resolve_relocation (input_bfd, bfd_r_type, |
5837 | 0 | place, value, |
5838 | 0 | signed_addend, |
5839 | 0 | weak_undef_p); |
5840 | 0 | return _bfd_aarch64_elf_put_addend (input_bfd, hit_data, bfd_r_type, |
5841 | 0 | howto, value); |
5842 | 0 | case BFD_RELOC_AARCH64_ADR_GOT_PAGE: |
5843 | 0 | case BFD_RELOC_AARCH64_GOT_LD_PREL19: |
5844 | 0 | case BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14: |
5845 | 0 | case BFD_RELOC_AARCH64_LD32_GOT_LO12_NC: |
5846 | 0 | case BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15: |
5847 | 0 | case BFD_RELOC_AARCH64_MOVW_GOTOFF_G0_NC: |
5848 | 0 | case BFD_RELOC_AARCH64_MOVW_GOTOFF_G1: |
5849 | 0 | case BFD_RELOC_AARCH64_LD64_GOTOFF_LO15: |
5850 | 0 | case BFD_RELOC_AARCH64_LD64_GOT_LO12_NC: |
5851 | 0 | base_got = globals->root.sgot; |
5852 | 0 | off = h->got.offset; |
5853 | |
|
5854 | 0 | if (base_got == NULL) |
5855 | 0 | abort (); |
5856 | | |
5857 | 0 | if (off == (bfd_vma) -1) |
5858 | 0 | { |
5859 | 0 | bfd_vma plt_index; |
5860 | | |
5861 | | /* We can't use h->got.offset here to save state, or |
5862 | | even just remember the offset, as finish_dynamic_symbol |
5863 | | would use that as offset into .got. */ |
5864 | |
|
5865 | 0 | if (globals->root.splt != NULL) |
5866 | 0 | { |
5867 | 0 | plt_index = ((h->plt.offset - globals->plt_header_size) / |
5868 | 0 | globals->plt_entry_size); |
5869 | 0 | off = (plt_index + 3) * GOT_ENTRY_SIZE; |
5870 | 0 | base_got = globals->root.sgotplt; |
5871 | 0 | } |
5872 | 0 | else |
5873 | 0 | { |
5874 | 0 | plt_index = h->plt.offset / globals->plt_entry_size; |
5875 | 0 | off = plt_index * GOT_ENTRY_SIZE; |
5876 | 0 | base_got = globals->root.igotplt; |
5877 | 0 | } |
5878 | |
|
5879 | 0 | if (h->dynindx == -1 |
5880 | 0 | || h->forced_local |
5881 | 0 | || info->symbolic) |
5882 | 0 | { |
5883 | | /* This references the local definition. We must |
5884 | | initialize this entry in the global offset table. |
5885 | | Since the offset must always be a multiple of 8, |
5886 | | we use the least significant bit to record |
5887 | | whether we have initialized it already. |
5888 | | |
5889 | | When doing a dynamic link, we create a .rela.got |
5890 | | relocation entry to initialize the value. This |
5891 | | is done in the finish_dynamic_symbol routine. */ |
5892 | 0 | if ((off & 1) != 0) |
5893 | 0 | off &= ~1; |
5894 | 0 | else |
5895 | 0 | { |
5896 | 0 | bfd_put_64 (output_bfd, value, |
5897 | 0 | base_got->contents + off); |
5898 | | /* Note that this is harmless as -1 | 1 still is -1. */ |
5899 | 0 | h->got.offset |= 1; |
5900 | 0 | } |
5901 | 0 | } |
5902 | 0 | value = (base_got->output_section->vma |
5903 | 0 | + base_got->output_offset + off); |
5904 | 0 | } |
5905 | 0 | else |
5906 | 0 | value = aarch64_calculate_got_entry_vma (h, globals, info, |
5907 | 0 | value, output_bfd, |
5908 | 0 | unresolved_reloc_p); |
5909 | |
|
5910 | 0 | if (aarch64_relocation_aginst_gp_p (bfd_r_type)) |
5911 | 0 | addend = (globals->root.sgot->output_section->vma |
5912 | 0 | + globals->root.sgot->output_offset); |
5913 | |
|
5914 | 0 | value = _bfd_aarch64_elf_resolve_relocation (input_bfd, bfd_r_type, |
5915 | 0 | place, value, |
5916 | 0 | addend, weak_undef_p); |
5917 | 0 | return _bfd_aarch64_elf_put_addend (input_bfd, hit_data, bfd_r_type, howto, value); |
5918 | 0 | case BFD_RELOC_AARCH64_ADD_LO12: |
5919 | 0 | case BFD_RELOC_AARCH64_ADR_HI21_PCREL: |
5920 | 0 | break; |
5921 | 0 | } |
5922 | 0 | } |
5923 | | |
5924 | 0 | skip_ifunc: |
5925 | 0 | resolved_to_zero = (h != NULL |
5926 | 0 | && UNDEFWEAK_NO_DYNAMIC_RELOC (info, h)); |
5927 | |
|
5928 | 0 | switch (bfd_r_type) |
5929 | 0 | { |
5930 | 0 | case BFD_RELOC_AARCH64_NONE: |
5931 | 0 | case BFD_RELOC_AARCH64_TLSDESC_ADD: |
5932 | 0 | case BFD_RELOC_AARCH64_TLSDESC_CALL: |
5933 | 0 | case BFD_RELOC_AARCH64_TLSDESC_LDR: |
5934 | 0 | *unresolved_reloc_p = false; |
5935 | 0 | return bfd_reloc_ok; |
5936 | | |
5937 | 0 | case BFD_RELOC_AARCH64_64: |
5938 | | |
5939 | | /* When generating a shared library or PIE, these relocations |
5940 | | are copied into the output file to be resolved at run time. */ |
5941 | 0 | if ((bfd_link_pic (info) |
5942 | 0 | && (input_section->flags & SEC_ALLOC) |
5943 | 0 | && (h == NULL |
5944 | 0 | || (ELF_ST_VISIBILITY (h->other) == STV_DEFAULT |
5945 | 0 | && !resolved_to_zero) |
5946 | 0 | || h->root.type != bfd_link_hash_undefweak)) |
5947 | | /* Or we are creating an executable, we may need to keep relocations |
5948 | | for symbols satisfied by a dynamic library if we manage to avoid |
5949 | | copy relocs for the symbol. */ |
5950 | 0 | || (ELIMINATE_COPY_RELOCS |
5951 | 0 | && !bfd_link_pic (info) |
5952 | 0 | && h != NULL |
5953 | 0 | && (input_section->flags & SEC_ALLOC) |
5954 | 0 | && h->dynindx != -1 |
5955 | 0 | && !h->non_got_ref |
5956 | 0 | && ((h->def_dynamic |
5957 | 0 | && !h->def_regular) |
5958 | 0 | || h->root.type == bfd_link_hash_undefweak |
5959 | 0 | || h->root.type == bfd_link_hash_undefined))) |
5960 | 0 | { |
5961 | 0 | Elf_Internal_Rela outrel; |
5962 | 0 | bfd_byte *loc; |
5963 | 0 | bool skip, relocate; |
5964 | 0 | asection *sreloc; |
5965 | |
|
5966 | 0 | *unresolved_reloc_p = false; |
5967 | |
|
5968 | 0 | skip = false; |
5969 | 0 | relocate = false; |
5970 | |
|
5971 | 0 | outrel.r_addend = signed_addend; |
5972 | 0 | outrel.r_offset = |
5973 | 0 | _bfd_elf_section_offset (output_bfd, info, input_section, |
5974 | 0 | rel->r_offset); |
5975 | 0 | if (outrel.r_offset == (bfd_vma) - 1) |
5976 | 0 | skip = true; |
5977 | 0 | else if (outrel.r_offset == (bfd_vma) - 2) |
5978 | 0 | { |
5979 | 0 | skip = true; |
5980 | 0 | relocate = true; |
5981 | 0 | } |
5982 | 0 | else if (abs_symbol_p) |
5983 | 0 | { |
5984 | | /* Local absolute symbol. */ |
5985 | 0 | skip = (h->forced_local || (h->dynindx == -1)); |
5986 | 0 | relocate = skip; |
5987 | 0 | } |
5988 | |
|
5989 | 0 | outrel.r_offset += (input_section->output_section->vma |
5990 | 0 | + input_section->output_offset); |
5991 | |
|
5992 | 0 | if (skip) |
5993 | 0 | memset (&outrel, 0, sizeof outrel); |
5994 | 0 | else if (h != NULL |
5995 | 0 | && h->dynindx != -1 |
5996 | 0 | && (!bfd_link_pic (info) |
5997 | 0 | || !(bfd_link_pie (info) || SYMBOLIC_BIND (info, h)) |
5998 | 0 | || !h->def_regular)) |
5999 | 0 | outrel.r_info = ELF64_R_INFO (h->dynindx, r_type); |
6000 | 0 | else if (info->enable_dt_relr |
6001 | 0 | && input_section->alignment_power != 0 |
6002 | 0 | && rel->r_offset % 2 == 0) |
6003 | 0 | { |
6004 | | /* Don't emit a relative relocation that is packed, only |
6005 | | apply the addend. */ |
6006 | 0 | return _bfd_final_link_relocate (howto, input_bfd, input_section, |
6007 | 0 | contents, rel->r_offset, value, |
6008 | 0 | signed_addend); |
6009 | 0 | } |
6010 | 0 | else |
6011 | 0 | { |
6012 | 0 | int symbol; |
6013 | | |
6014 | | /* On SVR4-ish systems, the dynamic loader cannot |
6015 | | relocate the text and data segments independently, |
6016 | | so the symbol does not matter. */ |
6017 | 0 | symbol = 0; |
6018 | 0 | relocate = !globals->no_apply_dynamic_relocs; |
6019 | 0 | outrel.r_info = ELF64_R_INFO (symbol, AARCH64_R (RELATIVE)); |
6020 | 0 | outrel.r_addend += value; |
6021 | 0 | } |
6022 | | |
6023 | 0 | sreloc = elf_section_data (input_section)->sreloc; |
6024 | 0 | if (sreloc == NULL || sreloc->contents == NULL) |
6025 | 0 | return bfd_reloc_notsupported; |
6026 | | |
6027 | 0 | loc = sreloc->contents + sreloc->reloc_count++ * RELOC_SIZE (globals); |
6028 | 0 | bfd_elf64_swap_reloca_out (output_bfd, &outrel, loc); |
6029 | |
|
6030 | 0 | if (sreloc->reloc_count * RELOC_SIZE (globals) > sreloc->size) |
6031 | 0 | { |
6032 | | /* Sanity to check that we have previously allocated |
6033 | | sufficient space in the relocation section for the |
6034 | | number of relocations we actually want to emit. */ |
6035 | 0 | abort (); |
6036 | 0 | } |
6037 | | |
6038 | | /* If this reloc is against an external symbol, we do not want to |
6039 | | fiddle with the addend. Otherwise, we need to include the symbol |
6040 | | value so that it becomes an addend for the dynamic reloc. */ |
6041 | 0 | if (!relocate) |
6042 | 0 | return bfd_reloc_ok; |
6043 | | |
6044 | 0 | return _bfd_final_link_relocate (howto, input_bfd, input_section, |
6045 | 0 | contents, rel->r_offset, value, |
6046 | 0 | signed_addend); |
6047 | 0 | } |
6048 | 0 | else |
6049 | 0 | value += signed_addend; |
6050 | 0 | break; |
6051 | | |
6052 | 0 | case BFD_RELOC_AARCH64_CALL26: |
6053 | 0 | case BFD_RELOC_AARCH64_JUMP26: |
6054 | 0 | { |
6055 | 0 | asection *splt = globals->root.splt; |
6056 | 0 | bool via_plt_p = |
6057 | 0 | splt != NULL && h != NULL && h->plt.offset != (bfd_vma) - 1; |
6058 | | |
6059 | | /* A call to an undefined weak symbol is converted to a jump to |
6060 | | the next instruction unless a PLT entry will be created. |
6061 | | The jump to the next instruction is optimized as a NOP. |
6062 | | Do the same for local undefined symbols. */ |
6063 | 0 | if (weak_undef_p && ! via_plt_p) |
6064 | 0 | { |
6065 | 0 | bfd_putl32 (INSN_NOP, hit_data); |
6066 | 0 | return bfd_reloc_ok; |
6067 | 0 | } |
6068 | | |
6069 | | /* If the call goes through a PLT entry, make sure to |
6070 | | check distance to the right destination address. */ |
6071 | 0 | if (via_plt_p) |
6072 | 0 | value = (splt->output_section->vma |
6073 | 0 | + splt->output_offset + h->plt.offset); |
6074 | | |
6075 | | /* Check if a stub has to be inserted because the destination |
6076 | | is too far away. */ |
6077 | 0 | struct elf_aarch64_stub_hash_entry *stub_entry = NULL; |
6078 | | |
6079 | | /* If the branch destination is directed to plt stub, "value" will be |
6080 | | the final destination, otherwise we should plus signed_addend, it may |
6081 | | contain non-zero value, for example call to local function symbol |
6082 | | which are turned into "sec_sym + sec_off", and sec_off is kept in |
6083 | | signed_addend. */ |
6084 | 0 | if (! aarch64_valid_branch_p (via_plt_p ? value : value + signed_addend, |
6085 | 0 | place)) |
6086 | | /* The target is out of reach, so redirect the branch to |
6087 | | the local stub for this function. */ |
6088 | 0 | stub_entry = elf64_aarch64_get_stub_entry (input_section, sym_sec, h, |
6089 | 0 | rel, globals); |
6090 | 0 | if (stub_entry != NULL) |
6091 | 0 | { |
6092 | 0 | value = (stub_entry->stub_offset |
6093 | 0 | + stub_entry->stub_sec->output_offset |
6094 | 0 | + stub_entry->stub_sec->output_section->vma); |
6095 | | |
6096 | | /* We have redirected the destination to stub entry address, |
6097 | | so ignore any addend record in the original rela entry. */ |
6098 | 0 | signed_addend = 0; |
6099 | 0 | } |
6100 | 0 | } |
6101 | 0 | value = _bfd_aarch64_elf_resolve_relocation (input_bfd, bfd_r_type, |
6102 | 0 | place, value, |
6103 | 0 | signed_addend, weak_undef_p); |
6104 | 0 | *unresolved_reloc_p = false; |
6105 | 0 | break; |
6106 | | |
6107 | 0 | case BFD_RELOC_AARCH64_16_PCREL: |
6108 | 0 | case BFD_RELOC_AARCH64_32_PCREL: |
6109 | 0 | case BFD_RELOC_AARCH64_64_PCREL: |
6110 | 0 | case BFD_RELOC_AARCH64_ADR_HI21_NC_PCREL: |
6111 | 0 | case BFD_RELOC_AARCH64_ADR_HI21_PCREL: |
6112 | 0 | case BFD_RELOC_AARCH64_ADR_LO21_PCREL: |
6113 | 0 | case BFD_RELOC_AARCH64_LD_LO19_PCREL: |
6114 | 0 | case BFD_RELOC_AARCH64_MOVW_PREL_G0: |
6115 | 0 | case BFD_RELOC_AARCH64_MOVW_PREL_G0_NC: |
6116 | 0 | case BFD_RELOC_AARCH64_MOVW_PREL_G1: |
6117 | 0 | case BFD_RELOC_AARCH64_MOVW_PREL_G1_NC: |
6118 | 0 | case BFD_RELOC_AARCH64_MOVW_PREL_G2: |
6119 | 0 | case BFD_RELOC_AARCH64_MOVW_PREL_G2_NC: |
6120 | 0 | case BFD_RELOC_AARCH64_MOVW_PREL_G3: |
6121 | 0 | if (bfd_link_pic (info) |
6122 | 0 | && (input_section->flags & SEC_ALLOC) != 0 |
6123 | 0 | && (input_section->flags & SEC_READONLY) != 0 |
6124 | 0 | && !_bfd_elf_symbol_refs_local_p (h, info, 1)) |
6125 | 0 | { |
6126 | 0 | int howto_index = bfd_r_type - BFD_RELOC_AARCH64_RELOC_START; |
6127 | |
|
6128 | 0 | _bfd_error_handler |
6129 | | /* xgettext:c-format */ |
6130 | 0 | (_("%pB: relocation %s against symbol `%s' which may bind " |
6131 | 0 | "externally can not be used when making a shared object; " |
6132 | 0 | "recompile with -fPIC"), |
6133 | 0 | input_bfd, elf64_aarch64_howto_table[howto_index].name, |
6134 | 0 | h->root.root.string); |
6135 | 0 | bfd_set_error (bfd_error_bad_value); |
6136 | 0 | return bfd_reloc_notsupported; |
6137 | 0 | } |
6138 | 0 | value = _bfd_aarch64_elf_resolve_relocation (input_bfd, bfd_r_type, |
6139 | 0 | place, value, |
6140 | 0 | signed_addend, |
6141 | 0 | weak_undef_p); |
6142 | 0 | break; |
6143 | | |
6144 | 0 | case BFD_RELOC_AARCH64_BRANCH19: |
6145 | 0 | case BFD_RELOC_AARCH64_TSTBR14: |
6146 | 0 | if (h && h->root.type == bfd_link_hash_undefined) |
6147 | 0 | { |
6148 | 0 | _bfd_error_handler |
6149 | | /* xgettext:c-format */ |
6150 | 0 | (_("%pB: conditional branch to undefined symbol `%s' " |
6151 | 0 | "not allowed"), input_bfd, h->root.root.string); |
6152 | 0 | bfd_set_error (bfd_error_bad_value); |
6153 | 0 | return bfd_reloc_notsupported; |
6154 | 0 | } |
6155 | | /* Fall through. */ |
6156 | | |
6157 | 0 | case BFD_RELOC_AARCH64_16: |
6158 | 0 | #if ARCH_SIZE == 64 |
6159 | 0 | case BFD_RELOC_AARCH64_32: |
6160 | 0 | #endif |
6161 | 0 | case BFD_RELOC_AARCH64_ADD_LO12: |
6162 | 0 | case BFD_RELOC_AARCH64_LDST128_LO12: |
6163 | 0 | case BFD_RELOC_AARCH64_LDST16_LO12: |
6164 | 0 | case BFD_RELOC_AARCH64_LDST32_LO12: |
6165 | 0 | case BFD_RELOC_AARCH64_LDST64_LO12: |
6166 | 0 | case BFD_RELOC_AARCH64_LDST8_LO12: |
6167 | 0 | case BFD_RELOC_AARCH64_MOVW_G0: |
6168 | 0 | case BFD_RELOC_AARCH64_MOVW_G0_NC: |
6169 | 0 | case BFD_RELOC_AARCH64_MOVW_G0_S: |
6170 | 0 | case BFD_RELOC_AARCH64_MOVW_G1: |
6171 | 0 | case BFD_RELOC_AARCH64_MOVW_G1_NC: |
6172 | 0 | case BFD_RELOC_AARCH64_MOVW_G1_S: |
6173 | 0 | case BFD_RELOC_AARCH64_MOVW_G2: |
6174 | 0 | case BFD_RELOC_AARCH64_MOVW_G2_NC: |
6175 | 0 | case BFD_RELOC_AARCH64_MOVW_G2_S: |
6176 | 0 | case BFD_RELOC_AARCH64_MOVW_G3: |
6177 | 0 | value = _bfd_aarch64_elf_resolve_relocation (input_bfd, bfd_r_type, |
6178 | 0 | place, value, |
6179 | 0 | signed_addend, weak_undef_p); |
6180 | 0 | break; |
6181 | | |
6182 | 0 | case BFD_RELOC_AARCH64_ADR_GOT_PAGE: |
6183 | 0 | case BFD_RELOC_AARCH64_GOT_LD_PREL19: |
6184 | 0 | case BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14: |
6185 | 0 | case BFD_RELOC_AARCH64_LD32_GOT_LO12_NC: |
6186 | 0 | case BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15: |
6187 | 0 | case BFD_RELOC_AARCH64_LD64_GOT_LO12_NC: |
6188 | 0 | case BFD_RELOC_AARCH64_LD64_GOTOFF_LO15: |
6189 | 0 | case BFD_RELOC_AARCH64_MOVW_GOTOFF_G0_NC: |
6190 | 0 | case BFD_RELOC_AARCH64_MOVW_GOTOFF_G1: |
6191 | 0 | if (globals->root.sgot == NULL) |
6192 | 0 | BFD_ASSERT (h != NULL); |
6193 | |
|
6194 | 0 | relative_reloc = false; |
6195 | 0 | if (h != NULL) |
6196 | 0 | { |
6197 | 0 | bfd_vma addend = 0; |
6198 | | |
6199 | | /* If a symbol is not dynamic and is not undefined weak, bind it |
6200 | | locally and generate a RELATIVE relocation under PIC mode. |
6201 | | |
6202 | | NOTE: one symbol may be referenced by several relocations, we |
6203 | | should only generate one RELATIVE relocation for that symbol. |
6204 | | Therefore, check GOT offset mark first. */ |
6205 | 0 | if (h->dynindx == -1 |
6206 | 0 | && !h->forced_local |
6207 | 0 | && h->root.type != bfd_link_hash_undefweak |
6208 | 0 | && bfd_link_pic (info) |
6209 | 0 | && !symbol_got_offset_mark_p (input_bfd, h, r_symndx)) |
6210 | 0 | relative_reloc = true; |
6211 | |
|
6212 | 0 | value = aarch64_calculate_got_entry_vma (h, globals, info, value, |
6213 | 0 | output_bfd, |
6214 | 0 | unresolved_reloc_p); |
6215 | | /* Record the GOT entry address which will be used when generating |
6216 | | RELATIVE relocation. */ |
6217 | 0 | if (relative_reloc) |
6218 | 0 | got_entry_addr = value; |
6219 | |
|
6220 | 0 | if (aarch64_relocation_aginst_gp_p (bfd_r_type)) |
6221 | 0 | addend = (globals->root.sgot->output_section->vma |
6222 | 0 | + globals->root.sgot->output_offset); |
6223 | 0 | value = _bfd_aarch64_elf_resolve_relocation (input_bfd, bfd_r_type, |
6224 | 0 | place, value, |
6225 | 0 | addend, weak_undef_p); |
6226 | 0 | } |
6227 | 0 | else |
6228 | 0 | { |
6229 | 0 | bfd_vma addend = 0; |
6230 | 0 | struct elf_aarch64_local_symbol *locals |
6231 | 0 | = elf_aarch64_locals (input_bfd); |
6232 | |
|
6233 | 0 | if (locals == NULL) |
6234 | 0 | { |
6235 | 0 | int howto_index = bfd_r_type - BFD_RELOC_AARCH64_RELOC_START; |
6236 | 0 | _bfd_error_handler |
6237 | | /* xgettext:c-format */ |
6238 | 0 | (_("%pB: local symbol descriptor table be NULL when applying " |
6239 | 0 | "relocation %s against local symbol"), |
6240 | 0 | input_bfd, elf64_aarch64_howto_table[howto_index].name); |
6241 | 0 | abort (); |
6242 | 0 | } |
6243 | | |
6244 | 0 | off = symbol_got_offset (input_bfd, h, r_symndx); |
6245 | 0 | base_got = globals->root.sgot; |
6246 | 0 | got_entry_addr = (base_got->output_section->vma |
6247 | 0 | + base_got->output_offset + off); |
6248 | |
|
6249 | 0 | if (!symbol_got_offset_mark_p (input_bfd, h, r_symndx)) |
6250 | 0 | { |
6251 | 0 | bfd_put_64 (output_bfd, value, base_got->contents + off); |
6252 | | |
6253 | | /* For local symbol, we have done absolute relocation in static |
6254 | | linking stage. While for shared library, we need to update the |
6255 | | content of GOT entry according to the shared object's runtime |
6256 | | base address. So, we need to generate a R_AARCH64_RELATIVE reloc |
6257 | | for dynamic linker. */ |
6258 | 0 | if (bfd_link_pic (info)) |
6259 | 0 | relative_reloc = true; |
6260 | |
|
6261 | 0 | symbol_got_offset_mark (input_bfd, h, r_symndx); |
6262 | 0 | } |
6263 | | |
6264 | | /* Update the relocation value to GOT entry addr as we have transformed |
6265 | | the direct data access into indirect data access through GOT. */ |
6266 | 0 | value = got_entry_addr; |
6267 | |
|
6268 | 0 | if (aarch64_relocation_aginst_gp_p (bfd_r_type)) |
6269 | 0 | addend = base_got->output_section->vma + base_got->output_offset; |
6270 | |
|
6271 | 0 | value = _bfd_aarch64_elf_resolve_relocation (input_bfd, bfd_r_type, |
6272 | 0 | place, value, |
6273 | 0 | addend, weak_undef_p); |
6274 | 0 | } |
6275 | | |
6276 | | /* Emit relative relocations, but not if they are packed (DT_RELR). */ |
6277 | 0 | if (relative_reloc && !info->enable_dt_relr) |
6278 | 0 | { |
6279 | 0 | asection *s; |
6280 | 0 | Elf_Internal_Rela outrel; |
6281 | |
|
6282 | 0 | s = globals->root.srelgot; |
6283 | 0 | if (s == NULL) |
6284 | 0 | abort (); |
6285 | | |
6286 | 0 | outrel.r_offset = got_entry_addr; |
6287 | 0 | outrel.r_info = ELF64_R_INFO (0, AARCH64_R (RELATIVE)); |
6288 | 0 | outrel.r_addend = orig_value; |
6289 | 0 | elf_append_rela (output_bfd, s, &outrel); |
6290 | 0 | } |
6291 | 0 | break; |
6292 | | |
6293 | 0 | case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC: |
6294 | 0 | case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21: |
6295 | 0 | case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21: |
6296 | 0 | case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21: |
6297 | 0 | case BFD_RELOC_AARCH64_TLSIE_LD32_GOTTPREL_LO12_NC: |
6298 | 0 | case BFD_RELOC_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC: |
6299 | 0 | case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19: |
6300 | 0 | case BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC: |
6301 | 0 | case BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21: |
6302 | 0 | case BFD_RELOC_AARCH64_TLSLD_ADR_PREL21: |
6303 | 0 | if (globals->root.sgot == NULL) |
6304 | 0 | return bfd_reloc_notsupported; |
6305 | | |
6306 | 0 | value = (symbol_got_offset (input_bfd, h, r_symndx) |
6307 | 0 | + globals->root.sgot->output_section->vma |
6308 | 0 | + globals->root.sgot->output_offset); |
6309 | |
|
6310 | 0 | value = _bfd_aarch64_elf_resolve_relocation (input_bfd, bfd_r_type, |
6311 | 0 | place, value, |
6312 | 0 | 0, weak_undef_p); |
6313 | 0 | *unresolved_reloc_p = false; |
6314 | 0 | break; |
6315 | | |
6316 | 0 | case BFD_RELOC_AARCH64_TLSGD_MOVW_G0_NC: |
6317 | 0 | case BFD_RELOC_AARCH64_TLSGD_MOVW_G1: |
6318 | 0 | case BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G0_NC: |
6319 | 0 | case BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G1: |
6320 | 0 | if (globals->root.sgot == NULL) |
6321 | 0 | return bfd_reloc_notsupported; |
6322 | | |
6323 | 0 | value = symbol_got_offset (input_bfd, h, r_symndx); |
6324 | 0 | value = _bfd_aarch64_elf_resolve_relocation (input_bfd, bfd_r_type, |
6325 | 0 | place, value, |
6326 | 0 | 0, weak_undef_p); |
6327 | 0 | *unresolved_reloc_p = false; |
6328 | 0 | break; |
6329 | | |
6330 | 0 | case BFD_RELOC_AARCH64_TLSLD_ADD_DTPREL_HI12: |
6331 | 0 | case BFD_RELOC_AARCH64_TLSLD_ADD_DTPREL_LO12: |
6332 | 0 | case BFD_RELOC_AARCH64_TLSLD_ADD_DTPREL_LO12_NC: |
6333 | 0 | case BFD_RELOC_AARCH64_TLSLD_LDST16_DTPREL_LO12: |
6334 | 0 | case BFD_RELOC_AARCH64_TLSLD_LDST16_DTPREL_LO12_NC: |
6335 | 0 | case BFD_RELOC_AARCH64_TLSLD_LDST32_DTPREL_LO12: |
6336 | 0 | case BFD_RELOC_AARCH64_TLSLD_LDST32_DTPREL_LO12_NC: |
6337 | 0 | case BFD_RELOC_AARCH64_TLSLD_LDST64_DTPREL_LO12: |
6338 | 0 | case BFD_RELOC_AARCH64_TLSLD_LDST64_DTPREL_LO12_NC: |
6339 | 0 | case BFD_RELOC_AARCH64_TLSLD_LDST8_DTPREL_LO12: |
6340 | 0 | case BFD_RELOC_AARCH64_TLSLD_LDST8_DTPREL_LO12_NC: |
6341 | 0 | case BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G0: |
6342 | 0 | case BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G0_NC: |
6343 | 0 | case BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G1: |
6344 | 0 | case BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G1_NC: |
6345 | 0 | case BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G2: |
6346 | 0 | { |
6347 | 0 | if (!(weak_undef_p || elf_hash_table (info)->tls_sec)) |
6348 | 0 | { |
6349 | 0 | int howto_index = bfd_r_type - BFD_RELOC_AARCH64_RELOC_START; |
6350 | 0 | _bfd_error_handler |
6351 | | /* xgettext:c-format */ |
6352 | 0 | (_("%pB: TLS relocation %s against undefined symbol `%s'"), |
6353 | 0 | input_bfd, elf64_aarch64_howto_table[howto_index].name, |
6354 | 0 | h->root.root.string); |
6355 | 0 | bfd_set_error (bfd_error_bad_value); |
6356 | 0 | return bfd_reloc_notsupported; |
6357 | 0 | } |
6358 | | |
6359 | 0 | bfd_vma def_value |
6360 | 0 | = weak_undef_p ? 0 : signed_addend - dtpoff_base (info); |
6361 | 0 | value = _bfd_aarch64_elf_resolve_relocation (input_bfd, bfd_r_type, |
6362 | 0 | place, value, |
6363 | 0 | def_value, weak_undef_p); |
6364 | 0 | break; |
6365 | 0 | } |
6366 | | |
6367 | 0 | case BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_HI12: |
6368 | 0 | case BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_LO12: |
6369 | 0 | case BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_LO12_NC: |
6370 | 0 | case BFD_RELOC_AARCH64_TLSLE_LDST16_TPREL_LO12: |
6371 | 0 | case BFD_RELOC_AARCH64_TLSLE_LDST16_TPREL_LO12_NC: |
6372 | 0 | case BFD_RELOC_AARCH64_TLSLE_LDST32_TPREL_LO12: |
6373 | 0 | case BFD_RELOC_AARCH64_TLSLE_LDST32_TPREL_LO12_NC: |
6374 | 0 | case BFD_RELOC_AARCH64_TLSLE_LDST64_TPREL_LO12: |
6375 | 0 | case BFD_RELOC_AARCH64_TLSLE_LDST64_TPREL_LO12_NC: |
6376 | 0 | case BFD_RELOC_AARCH64_TLSLE_LDST8_TPREL_LO12: |
6377 | 0 | case BFD_RELOC_AARCH64_TLSLE_LDST8_TPREL_LO12_NC: |
6378 | 0 | case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0: |
6379 | 0 | case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC: |
6380 | 0 | case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1: |
6381 | 0 | case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1_NC: |
6382 | 0 | case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G2: |
6383 | 0 | { |
6384 | 0 | if (!(weak_undef_p || elf_hash_table (info)->tls_sec)) |
6385 | 0 | { |
6386 | 0 | int howto_index = bfd_r_type - BFD_RELOC_AARCH64_RELOC_START; |
6387 | 0 | _bfd_error_handler |
6388 | | /* xgettext:c-format */ |
6389 | 0 | (_("%pB: TLS relocation %s against undefined symbol `%s'"), |
6390 | 0 | input_bfd, elf64_aarch64_howto_table[howto_index].name, |
6391 | 0 | h->root.root.string); |
6392 | 0 | bfd_set_error (bfd_error_bad_value); |
6393 | 0 | return bfd_reloc_notsupported; |
6394 | 0 | } |
6395 | | |
6396 | 0 | bfd_vma def_value |
6397 | 0 | = weak_undef_p ? 0 : signed_addend - tpoff_base (info); |
6398 | 0 | value = _bfd_aarch64_elf_resolve_relocation (input_bfd, bfd_r_type, |
6399 | 0 | place, value, |
6400 | 0 | def_value, weak_undef_p); |
6401 | 0 | *unresolved_reloc_p = false; |
6402 | 0 | break; |
6403 | 0 | } |
6404 | | |
6405 | 0 | case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12: |
6406 | 0 | case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21: |
6407 | 0 | case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21: |
6408 | 0 | case BFD_RELOC_AARCH64_TLSDESC_LD32_LO12_NC: |
6409 | 0 | case BFD_RELOC_AARCH64_TLSDESC_LD64_LO12: |
6410 | 0 | case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19: |
6411 | 0 | if (globals->root.sgot == NULL) |
6412 | 0 | return bfd_reloc_notsupported; |
6413 | 0 | value = (symbol_tlsdesc_got_offset (input_bfd, h, r_symndx) |
6414 | 0 | + globals->root.sgotplt->output_section->vma |
6415 | 0 | + globals->root.sgotplt->output_offset |
6416 | 0 | + globals->sgotplt_jump_table_size); |
6417 | |
|
6418 | 0 | value = _bfd_aarch64_elf_resolve_relocation (input_bfd, bfd_r_type, |
6419 | 0 | place, value, |
6420 | 0 | 0, weak_undef_p); |
6421 | 0 | *unresolved_reloc_p = false; |
6422 | 0 | break; |
6423 | | |
6424 | 0 | case BFD_RELOC_AARCH64_TLSDESC_OFF_G0_NC: |
6425 | 0 | case BFD_RELOC_AARCH64_TLSDESC_OFF_G1: |
6426 | 0 | if (globals->root.sgot == NULL) |
6427 | 0 | return bfd_reloc_notsupported; |
6428 | | |
6429 | 0 | value = (symbol_tlsdesc_got_offset (input_bfd, h, r_symndx) |
6430 | 0 | + globals->root.sgotplt->output_section->vma |
6431 | 0 | + globals->root.sgotplt->output_offset |
6432 | 0 | + globals->sgotplt_jump_table_size); |
6433 | |
|
6434 | 0 | value -= (globals->root.sgot->output_section->vma |
6435 | 0 | + globals->root.sgot->output_offset); |
6436 | |
|
6437 | 0 | value = _bfd_aarch64_elf_resolve_relocation (input_bfd, bfd_r_type, |
6438 | 0 | place, value, |
6439 | 0 | 0, weak_undef_p); |
6440 | 0 | *unresolved_reloc_p = false; |
6441 | 0 | break; |
6442 | | |
6443 | 0 | default: |
6444 | 0 | return bfd_reloc_notsupported; |
6445 | 0 | } |
6446 | | |
6447 | 0 | if (saved_addend) |
6448 | 0 | *saved_addend = value; |
6449 | | |
6450 | | /* Only apply the final relocation in a sequence. */ |
6451 | 0 | if (save_addend) |
6452 | 0 | return bfd_reloc_continue; |
6453 | | |
6454 | 0 | return _bfd_aarch64_elf_put_addend (input_bfd, hit_data, bfd_r_type, |
6455 | 0 | howto, value); |
6456 | 0 | } |
6457 | | |
6458 | | /* LP64 and ILP32 operates on x- and w-registers respectively. |
6459 | | Next definitions take into account the difference between |
6460 | | corresponding machine codes. R means x-register if the target |
6461 | | arch is LP64, and w-register if the target is ILP32. */ |
6462 | | |
6463 | | #if ARCH_SIZE == 64 |
6464 | 0 | # define add_R0_R0 (0x91000000) |
6465 | 0 | # define add_R0_R0_R1 (0x8b000020) |
6466 | 0 | # define add_R0_R1 (0x91400020) |
6467 | 0 | # define ldr_R0 (0x58000000) |
6468 | 0 | # define ldr_R0_mask(i) (i & 0xffffffe0) |
6469 | 0 | # define ldr_R0_x0 (0xf9400000) |
6470 | 0 | # define ldr_hw_R0 (0xf2a00000) |
6471 | 0 | # define movk_R0 (0xf2800000) |
6472 | 0 | # define movz_R0 (0xd2a00000) |
6473 | 0 | # define movz_hw_R0 (0xd2c00000) |
6474 | | #else /*ARCH_SIZE == 32 */ |
6475 | | # define add_R0_R0 (0x11000000) |
6476 | | # define add_R0_R0_R1 (0x0b000020) |
6477 | | # define add_R0_R1 (0x11400020) |
6478 | | # define ldr_R0 (0x18000000) |
6479 | | # define ldr_R0_mask(i) (i & 0xbfffffe0) |
6480 | | # define ldr_R0_x0 (0xb9400000) |
6481 | | # define ldr_hw_R0 (0x72a00000) |
6482 | | # define movk_R0 (0x72800000) |
6483 | | # define movz_R0 (0x52a00000) |
6484 | | # define movz_hw_R0 (0x52c00000) |
6485 | | #endif |
6486 | | |
6487 | | /* Structure to hold payload for _bfd_aarch64_erratum_843419_clear_stub, |
6488 | | it is used to identify the stub information to reset. */ |
6489 | | |
6490 | | struct erratum_843419_branch_to_stub_clear_data |
6491 | | { |
6492 | | bfd_vma adrp_offset; |
6493 | | asection *output_section; |
6494 | | }; |
6495 | | |
6496 | | /* Clear the erratum information for GEN_ENTRY if the ADRP_OFFSET and |
6497 | | section inside IN_ARG matches. The clearing is done by setting the |
6498 | | stub_type to none. */ |
6499 | | |
6500 | | static bool |
6501 | | _bfd_aarch64_erratum_843419_clear_stub (struct bfd_hash_entry *gen_entry, |
6502 | | void *in_arg) |
6503 | 0 | { |
6504 | 0 | struct elf_aarch64_stub_hash_entry *stub_entry |
6505 | 0 | = (struct elf_aarch64_stub_hash_entry *) gen_entry; |
6506 | 0 | struct erratum_843419_branch_to_stub_clear_data *data |
6507 | 0 | = (struct erratum_843419_branch_to_stub_clear_data *) in_arg; |
6508 | |
|
6509 | 0 | if (stub_entry->target_section != data->output_section |
6510 | 0 | || stub_entry->stub_type != aarch64_stub_erratum_843419_veneer |
6511 | 0 | || stub_entry->adrp_offset != data->adrp_offset) |
6512 | 0 | return true; |
6513 | | |
6514 | | /* Change the stub type instead of removing the entry, removing from the hash |
6515 | | table would be slower and we have already reserved the memory for the entry |
6516 | | so there wouldn't be much gain. Changing the stub also keeps around a |
6517 | | record of what was there before. */ |
6518 | 0 | stub_entry->stub_type = aarch64_stub_none; |
6519 | | |
6520 | | /* We're done and there could have been only one matching stub at that |
6521 | | particular offset, so abort further traversal. */ |
6522 | 0 | return false; |
6523 | 0 | } |
6524 | | |
6525 | | /* TLS Relaxations may relax an adrp sequence that matches the erratum 843419 |
6526 | | sequence. In this case the erratum no longer applies and we need to remove |
6527 | | the entry from the pending stub generation. This clears matching adrp insn |
6528 | | at ADRP_OFFSET in INPUT_SECTION in the stub table defined in GLOBALS. */ |
6529 | | |
6530 | | static void |
6531 | | clear_erratum_843419_entry (struct elf_aarch64_link_hash_table *globals, |
6532 | | bfd_vma adrp_offset, asection *input_section) |
6533 | 0 | { |
6534 | 0 | if (globals->fix_erratum_843419 & ERRAT_ADRP) |
6535 | 0 | { |
6536 | 0 | struct erratum_843419_branch_to_stub_clear_data data; |
6537 | 0 | data.adrp_offset = adrp_offset; |
6538 | 0 | data.output_section = input_section; |
6539 | |
|
6540 | 0 | bfd_hash_traverse (&globals->stub_hash_table, |
6541 | 0 | _bfd_aarch64_erratum_843419_clear_stub, &data); |
6542 | 0 | } |
6543 | 0 | } |
6544 | | |
6545 | | /* Handle TLS relaxations. Relaxing is possible for symbols that use |
6546 | | R_AARCH64_TLSDESC_ADR_{PAGE, LD64_LO12_NC, ADD_LO12_NC} during a static |
6547 | | link. |
6548 | | |
6549 | | Return bfd_reloc_ok if we're done, bfd_reloc_continue if the caller |
6550 | | is to then call final_link_relocate. Return other values in the |
6551 | | case of error. */ |
6552 | | |
6553 | | static bfd_reloc_status_type |
6554 | | elf64_aarch64_tls_relax (struct elf_aarch64_link_hash_table *globals, |
6555 | | bfd *input_bfd, asection *input_section, |
6556 | | bfd_byte *contents, Elf_Internal_Rela *rel, |
6557 | | struct elf_link_hash_entry *h, |
6558 | | struct bfd_link_info *info) |
6559 | 0 | { |
6560 | 0 | bool local_exec = bfd_link_executable (info) |
6561 | 0 | && SYMBOL_REFERENCES_LOCAL (info, h); |
6562 | 0 | unsigned int r_type = ELF64_R_TYPE (rel->r_info); |
6563 | 0 | unsigned long insn; |
6564 | |
|
6565 | 0 | BFD_ASSERT (globals && input_bfd && contents && rel); |
6566 | |
|
6567 | 0 | switch (elf64_aarch64_bfd_reloc_from_type (input_bfd, r_type)) |
6568 | 0 | { |
6569 | 0 | case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21: |
6570 | 0 | case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21: |
6571 | 0 | if (local_exec) |
6572 | 0 | { |
6573 | | /* GD->LE relaxation: |
6574 | | adrp x0, :tlsgd:var => movz R0, :tprel_g1:var |
6575 | | or |
6576 | | adrp x0, :tlsdesc:var => movz R0, :tprel_g1:var |
6577 | | |
6578 | | Where R is x for LP64, and w for ILP32. */ |
6579 | 0 | bfd_putl32 (movz_R0, contents + rel->r_offset); |
6580 | | /* We have relaxed the adrp into a mov, we may have to clear any |
6581 | | pending erratum fixes. */ |
6582 | 0 | clear_erratum_843419_entry (globals, rel->r_offset, input_section); |
6583 | 0 | return bfd_reloc_continue; |
6584 | 0 | } |
6585 | 0 | else |
6586 | 0 | { |
6587 | | /* GD->IE relaxation: |
6588 | | adrp x0, :tlsgd:var => adrp x0, :gottprel:var |
6589 | | or |
6590 | | adrp x0, :tlsdesc:var => adrp x0, :gottprel:var |
6591 | | */ |
6592 | 0 | return bfd_reloc_continue; |
6593 | 0 | } |
6594 | | |
6595 | 0 | case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21: |
6596 | 0 | BFD_ASSERT (0); |
6597 | 0 | break; |
6598 | | |
6599 | 0 | case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19: |
6600 | 0 | if (local_exec) |
6601 | 0 | { |
6602 | | /* Tiny TLSDESC->LE relaxation: |
6603 | | ldr x1, :tlsdesc:var => movz R0, #:tprel_g1:var |
6604 | | adr x0, :tlsdesc:var => movk R0, #:tprel_g0_nc:var |
6605 | | .tlsdesccall var |
6606 | | blr x1 => nop |
6607 | | |
6608 | | Where R is x for LP64, and w for ILP32. */ |
6609 | 0 | BFD_ASSERT (ELF64_R_TYPE (rel[1].r_info) == AARCH64_R (TLSDESC_ADR_PREL21)); |
6610 | 0 | BFD_ASSERT (ELF64_R_TYPE (rel[2].r_info) == AARCH64_R (TLSDESC_CALL)); |
6611 | |
|
6612 | 0 | rel[1].r_info = ELF64_R_INFO (ELF64_R_SYM (rel->r_info), |
6613 | 0 | AARCH64_R (TLSLE_MOVW_TPREL_G0_NC)); |
6614 | 0 | rel[2].r_info = ELF64_R_INFO (STN_UNDEF, R_AARCH64_NONE); |
6615 | |
|
6616 | 0 | bfd_putl32 (movz_R0, contents + rel->r_offset); |
6617 | 0 | bfd_putl32 (movk_R0, contents + rel->r_offset + 4); |
6618 | 0 | bfd_putl32 (INSN_NOP, contents + rel->r_offset + 8); |
6619 | 0 | return bfd_reloc_continue; |
6620 | 0 | } |
6621 | 0 | else |
6622 | 0 | { |
6623 | | /* Tiny TLSDESC->IE relaxation: |
6624 | | ldr x1, :tlsdesc:var => ldr x0, :gottprel:var |
6625 | | adr x0, :tlsdesc:var => nop |
6626 | | .tlsdesccall var |
6627 | | blr x1 => nop |
6628 | | */ |
6629 | 0 | BFD_ASSERT (ELF64_R_TYPE (rel[1].r_info) == AARCH64_R (TLSDESC_ADR_PREL21)); |
6630 | 0 | BFD_ASSERT (ELF64_R_TYPE (rel[2].r_info) == AARCH64_R (TLSDESC_CALL)); |
6631 | |
|
6632 | 0 | rel[1].r_info = ELF64_R_INFO (STN_UNDEF, R_AARCH64_NONE); |
6633 | 0 | rel[2].r_info = ELF64_R_INFO (STN_UNDEF, R_AARCH64_NONE); |
6634 | |
|
6635 | 0 | bfd_putl32 (ldr_R0, contents + rel->r_offset); |
6636 | 0 | bfd_putl32 (INSN_NOP, contents + rel->r_offset + 4); |
6637 | 0 | bfd_putl32 (INSN_NOP, contents + rel->r_offset + 8); |
6638 | 0 | return bfd_reloc_continue; |
6639 | 0 | } |
6640 | | |
6641 | 0 | case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21: |
6642 | 0 | if (local_exec) |
6643 | 0 | { |
6644 | | /* Tiny GD->LE relaxation: |
6645 | | adr x0, :tlsgd:var => mrs x1, tpidr_el0 |
6646 | | bl __tls_get_addr => add R0, R1, #:tprel_hi12:x, lsl #12 |
6647 | | nop => add R0, R0, #:tprel_lo12_nc:x |
6648 | | |
6649 | | Where R is x for LP64, and x for Ilp32. */ |
6650 | | |
6651 | | /* First kill the tls_get_addr reloc on the bl instruction. */ |
6652 | 0 | BFD_ASSERT (rel->r_offset + 4 == rel[1].r_offset); |
6653 | |
|
6654 | 0 | bfd_putl32 (0xd53bd041, contents + rel->r_offset + 0); |
6655 | 0 | bfd_putl32 (add_R0_R1, contents + rel->r_offset + 4); |
6656 | 0 | bfd_putl32 (add_R0_R0, contents + rel->r_offset + 8); |
6657 | |
|
6658 | 0 | rel[1].r_info = ELF64_R_INFO (ELF64_R_SYM (rel->r_info), |
6659 | 0 | AARCH64_R (TLSLE_ADD_TPREL_LO12_NC)); |
6660 | 0 | rel[1].r_offset = rel->r_offset + 8; |
6661 | | |
6662 | | /* Move the current relocation to the second instruction in |
6663 | | the sequence. */ |
6664 | 0 | rel->r_offset += 4; |
6665 | 0 | rel->r_info = ELF64_R_INFO (ELF64_R_SYM (rel->r_info), |
6666 | 0 | AARCH64_R (TLSLE_ADD_TPREL_HI12)); |
6667 | 0 | return bfd_reloc_continue; |
6668 | 0 | } |
6669 | 0 | else |
6670 | 0 | { |
6671 | | /* Tiny GD->IE relaxation: |
6672 | | adr x0, :tlsgd:var => ldr R0, :gottprel:var |
6673 | | bl __tls_get_addr => mrs x1, tpidr_el0 |
6674 | | nop => add R0, R0, R1 |
6675 | | |
6676 | | Where R is x for LP64, and w for Ilp32. */ |
6677 | | |
6678 | | /* First kill the tls_get_addr reloc on the bl instruction. */ |
6679 | 0 | BFD_ASSERT (rel->r_offset + 4 == rel[1].r_offset); |
6680 | 0 | rel[1].r_info = ELF64_R_INFO (STN_UNDEF, R_AARCH64_NONE); |
6681 | |
|
6682 | 0 | bfd_putl32 (ldr_R0, contents + rel->r_offset); |
6683 | 0 | bfd_putl32 (0xd53bd041, contents + rel->r_offset + 4); |
6684 | 0 | bfd_putl32 (add_R0_R0_R1, contents + rel->r_offset + 8); |
6685 | 0 | return bfd_reloc_continue; |
6686 | 0 | } |
6687 | | |
6688 | 0 | #if ARCH_SIZE == 64 |
6689 | 0 | case BFD_RELOC_AARCH64_TLSGD_MOVW_G1: |
6690 | 0 | BFD_ASSERT (ELF64_R_TYPE (rel[1].r_info) == AARCH64_R (TLSGD_MOVW_G0_NC)); |
6691 | 0 | BFD_ASSERT (rel->r_offset + 12 == rel[2].r_offset); |
6692 | 0 | BFD_ASSERT (ELF64_R_TYPE (rel[2].r_info) == AARCH64_R (CALL26)); |
6693 | |
|
6694 | 0 | if (local_exec) |
6695 | 0 | { |
6696 | | /* Large GD->LE relaxation: |
6697 | | movz x0, #:tlsgd_g1:var => movz x0, #:tprel_g2:var, lsl #32 |
6698 | | movk x0, #:tlsgd_g0_nc:var => movk x0, #:tprel_g1_nc:var, lsl #16 |
6699 | | add x0, gp, x0 => movk x0, #:tprel_g0_nc:var |
6700 | | bl __tls_get_addr => mrs x1, tpidr_el0 |
6701 | | nop => add x0, x0, x1 |
6702 | | */ |
6703 | 0 | rel[2].r_info = ELF64_R_INFO (ELF64_R_SYM (rel->r_info), |
6704 | 0 | AARCH64_R (TLSLE_MOVW_TPREL_G0_NC)); |
6705 | 0 | rel[2].r_offset = rel->r_offset + 8; |
6706 | |
|
6707 | 0 | bfd_putl32 (movz_hw_R0, contents + rel->r_offset + 0); |
6708 | 0 | bfd_putl32 (ldr_hw_R0, contents + rel->r_offset + 4); |
6709 | 0 | bfd_putl32 (movk_R0, contents + rel->r_offset + 8); |
6710 | 0 | bfd_putl32 (0xd53bd041, contents + rel->r_offset + 12); |
6711 | 0 | bfd_putl32 (add_R0_R0_R1, contents + rel->r_offset + 16); |
6712 | 0 | } |
6713 | 0 | else |
6714 | 0 | { |
6715 | | /* Large GD->IE relaxation: |
6716 | | movz x0, #:tlsgd_g1:var => movz x0, #:gottprel_g1:var, lsl #16 |
6717 | | movk x0, #:tlsgd_g0_nc:var => movk x0, #:gottprel_g0_nc:var |
6718 | | add x0, gp, x0 => ldr x0, [gp, x0] |
6719 | | bl __tls_get_addr => mrs x1, tpidr_el0 |
6720 | | nop => add x0, x0, x1 |
6721 | | */ |
6722 | 0 | rel[2].r_info = ELF64_R_INFO (STN_UNDEF, R_AARCH64_NONE); |
6723 | 0 | bfd_putl32 (0xd2a80000, contents + rel->r_offset + 0); |
6724 | 0 | bfd_putl32 (ldr_R0, contents + rel->r_offset + 8); |
6725 | 0 | bfd_putl32 (0xd53bd041, contents + rel->r_offset + 12); |
6726 | 0 | bfd_putl32 (add_R0_R0_R1, contents + rel->r_offset + 16); |
6727 | 0 | } |
6728 | 0 | return bfd_reloc_continue; |
6729 | | |
6730 | 0 | case BFD_RELOC_AARCH64_TLSGD_MOVW_G0_NC: |
6731 | 0 | return bfd_reloc_continue; |
6732 | 0 | #endif |
6733 | | |
6734 | 0 | case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19: |
6735 | 0 | return bfd_reloc_continue; |
6736 | | |
6737 | 0 | case BFD_RELOC_AARCH64_TLSDESC_LD64_LO12_NC: |
6738 | 0 | if (local_exec) |
6739 | 0 | { |
6740 | | /* GD->LE relaxation: |
6741 | | ldr xd, [x0, #:tlsdesc_lo12:var] => movk x0, :tprel_g0_nc:var |
6742 | | |
6743 | | Where R is x for lp64 mode, and w for ILP32 mode. */ |
6744 | 0 | bfd_putl32 (movk_R0, contents + rel->r_offset); |
6745 | 0 | return bfd_reloc_continue; |
6746 | 0 | } |
6747 | 0 | else |
6748 | 0 | { |
6749 | | /* GD->IE relaxation: |
6750 | | ldr xd, [x0, #:tlsdesc_lo12:var] => ldr R0, [x0, #:gottprel_lo12:var] |
6751 | | |
6752 | | Where R is x for lp64 mode, and w for ILP32 mode. */ |
6753 | 0 | insn = bfd_getl32 (contents + rel->r_offset); |
6754 | 0 | bfd_putl32 (ldr_R0_mask (insn), contents + rel->r_offset); |
6755 | 0 | return bfd_reloc_continue; |
6756 | 0 | } |
6757 | | |
6758 | 0 | case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC: |
6759 | 0 | if (local_exec) |
6760 | 0 | { |
6761 | | /* GD->LE relaxation |
6762 | | add x0, #:tlsgd_lo12:var => movk R0, :tprel_g0_nc:var |
6763 | | bl __tls_get_addr => mrs x1, tpidr_el0 |
6764 | | nop => add R0, R1, R0 |
6765 | | |
6766 | | Where R is x for lp64 mode, and w for ILP32 mode. */ |
6767 | | |
6768 | | /* First kill the tls_get_addr reloc on the bl instruction. */ |
6769 | 0 | BFD_ASSERT (rel->r_offset + 4 == rel[1].r_offset); |
6770 | 0 | rel[1].r_info = ELF64_R_INFO (STN_UNDEF, R_AARCH64_NONE); |
6771 | |
|
6772 | 0 | bfd_putl32 (movk_R0, contents + rel->r_offset); |
6773 | 0 | bfd_putl32 (0xd53bd041, contents + rel->r_offset + 4); |
6774 | 0 | bfd_putl32 (add_R0_R0_R1, contents + rel->r_offset + 8); |
6775 | 0 | return bfd_reloc_continue; |
6776 | 0 | } |
6777 | 0 | else |
6778 | 0 | { |
6779 | | /* GD->IE relaxation |
6780 | | ADD x0, #:tlsgd_lo12:var => ldr R0, [x0, #:gottprel_lo12:var] |
6781 | | BL __tls_get_addr => mrs x1, tpidr_el0 |
6782 | | R_AARCH64_CALL26 |
6783 | | NOP => add R0, R1, R0 |
6784 | | |
6785 | | Where R is x for lp64 mode, and w for ilp32 mode. */ |
6786 | |
|
6787 | 0 | BFD_ASSERT (ELF64_R_TYPE (rel[1].r_info) == AARCH64_R (CALL26)); |
6788 | | |
6789 | | /* Remove the relocation on the BL instruction. */ |
6790 | 0 | rel[1].r_info = ELF64_R_INFO (STN_UNDEF, R_AARCH64_NONE); |
6791 | | |
6792 | | /* We choose to fixup the BL and NOP instructions using the |
6793 | | offset from the second relocation to allow flexibility in |
6794 | | scheduling instructions between the ADD and BL. */ |
6795 | 0 | bfd_putl32 (ldr_R0_x0, contents + rel->r_offset); |
6796 | 0 | bfd_putl32 (0xd53bd041, contents + rel[1].r_offset); |
6797 | 0 | bfd_putl32 (add_R0_R0_R1, contents + rel[1].r_offset + 4); |
6798 | 0 | return bfd_reloc_continue; |
6799 | 0 | } |
6800 | | |
6801 | 0 | case BFD_RELOC_AARCH64_TLSDESC_ADD: |
6802 | 0 | case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12: |
6803 | 0 | case BFD_RELOC_AARCH64_TLSDESC_CALL: |
6804 | | /* GD->IE/LE relaxation: |
6805 | | add x0, x0, #:tlsdesc_lo12:var => nop |
6806 | | blr xd => nop |
6807 | | */ |
6808 | 0 | bfd_putl32 (INSN_NOP, contents + rel->r_offset); |
6809 | 0 | return bfd_reloc_ok; |
6810 | | |
6811 | 0 | case BFD_RELOC_AARCH64_TLSDESC_LDR: |
6812 | 0 | if (local_exec) |
6813 | 0 | { |
6814 | | /* GD->LE relaxation: |
6815 | | ldr xd, [gp, xn] => movk R0, #:tprel_g0_nc:var |
6816 | | |
6817 | | Where R is x for lp64 mode, and w for ILP32 mode. */ |
6818 | 0 | bfd_putl32 (movk_R0, contents + rel->r_offset); |
6819 | 0 | return bfd_reloc_continue; |
6820 | 0 | } |
6821 | 0 | else |
6822 | 0 | { |
6823 | | /* GD->IE relaxation: |
6824 | | ldr xd, [gp, xn] => ldr R0, [gp, xn] |
6825 | | |
6826 | | Where R is x for lp64 mode, and w for ILP32 mode. */ |
6827 | 0 | insn = bfd_getl32 (contents + rel->r_offset); |
6828 | 0 | bfd_putl32 (ldr_R0_mask (insn), contents + rel->r_offset); |
6829 | 0 | return bfd_reloc_ok; |
6830 | 0 | } |
6831 | | |
6832 | 0 | case BFD_RELOC_AARCH64_TLSDESC_OFF_G0_NC: |
6833 | | /* GD->LE relaxation: |
6834 | | movk xd, #:tlsdesc_off_g0_nc:var => movk R0, #:tprel_g1_nc:var, lsl #16 |
6835 | | GD->IE relaxation: |
6836 | | movk xd, #:tlsdesc_off_g0_nc:var => movk Rd, #:gottprel_g0_nc:var |
6837 | | |
6838 | | Where R is x for lp64 mode, and w for ILP32 mode. */ |
6839 | 0 | if (local_exec) |
6840 | 0 | bfd_putl32 (ldr_hw_R0, contents + rel->r_offset); |
6841 | 0 | return bfd_reloc_continue; |
6842 | | |
6843 | 0 | case BFD_RELOC_AARCH64_TLSDESC_OFF_G1: |
6844 | 0 | if (local_exec) |
6845 | 0 | { |
6846 | | /* GD->LE relaxation: |
6847 | | movz xd, #:tlsdesc_off_g1:var => movz R0, #:tprel_g2:var, lsl #32 |
6848 | | |
6849 | | Where R is x for lp64 mode, and w for ILP32 mode. */ |
6850 | 0 | bfd_putl32 (movz_hw_R0, contents + rel->r_offset); |
6851 | 0 | return bfd_reloc_continue; |
6852 | 0 | } |
6853 | 0 | else |
6854 | 0 | { |
6855 | | /* GD->IE relaxation: |
6856 | | movz xd, #:tlsdesc_off_g1:var => movz Rd, #:gottprel_g1:var, lsl #16 |
6857 | | |
6858 | | Where R is x for lp64 mode, and w for ILP32 mode. */ |
6859 | 0 | insn = bfd_getl32 (contents + rel->r_offset); |
6860 | 0 | bfd_putl32 (movz_R0 | (insn & 0x1f), contents + rel->r_offset); |
6861 | 0 | return bfd_reloc_continue; |
6862 | 0 | } |
6863 | | |
6864 | 0 | case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21: |
6865 | | /* IE->LE relaxation: |
6866 | | adrp xd, :gottprel:var => movz Rd, :tprel_g1:var |
6867 | | |
6868 | | Where R is x for lp64 mode, and w for ILP32 mode. */ |
6869 | 0 | if (local_exec) |
6870 | 0 | { |
6871 | 0 | insn = bfd_getl32 (contents + rel->r_offset); |
6872 | 0 | bfd_putl32 (movz_R0 | (insn & 0x1f), contents + rel->r_offset); |
6873 | | /* We have relaxed the adrp into a mov, we may have to clear any |
6874 | | pending erratum fixes. */ |
6875 | 0 | clear_erratum_843419_entry (globals, rel->r_offset, input_section); |
6876 | 0 | } |
6877 | 0 | return bfd_reloc_continue; |
6878 | | |
6879 | 0 | case BFD_RELOC_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC: |
6880 | | /* IE->LE relaxation: |
6881 | | ldr xd, [xm, #:gottprel_lo12:var] => movk Rd, :tprel_g0_nc:var |
6882 | | |
6883 | | Where R is x for lp64 mode, and w for ILP32 mode. */ |
6884 | 0 | if (local_exec) |
6885 | 0 | { |
6886 | 0 | insn = bfd_getl32 (contents + rel->r_offset); |
6887 | 0 | bfd_putl32 (movk_R0 | (insn & 0x1f), contents + rel->r_offset); |
6888 | 0 | } |
6889 | 0 | return bfd_reloc_continue; |
6890 | | |
6891 | 0 | case BFD_RELOC_AARCH64_TLSLD_ADR_PREL21: |
6892 | | /* LD->LE relaxation (tiny): |
6893 | | adr x0, :tlsldm:x => mrs x0, tpidr_el0 |
6894 | | bl __tls_get_addr => add R0, R0, TCB_SIZE |
6895 | | |
6896 | | Where R is x for lp64 mode, and w for ilp32 mode. */ |
6897 | 0 | if (local_exec) |
6898 | 0 | { |
6899 | 0 | BFD_ASSERT (rel->r_offset + 4 == rel[1].r_offset); |
6900 | 0 | BFD_ASSERT (ELF64_R_TYPE (rel[1].r_info) == AARCH64_R (CALL26)); |
6901 | | /* No need of CALL26 relocation for tls_get_addr. */ |
6902 | 0 | rel[1].r_info = ELF64_R_INFO (STN_UNDEF, R_AARCH64_NONE); |
6903 | 0 | bfd_putl32 (0xd53bd040, contents + rel->r_offset + 0); |
6904 | 0 | bfd_putl32 (add_R0_R0 | (TCB_SIZE << 10), |
6905 | 0 | contents + rel->r_offset + 4); |
6906 | 0 | return bfd_reloc_ok; |
6907 | 0 | } |
6908 | 0 | return bfd_reloc_continue; |
6909 | | |
6910 | 0 | case BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21: |
6911 | | /* LD->LE relaxation (small): |
6912 | | adrp x0, :tlsldm:x => mrs x0, tpidr_el0 |
6913 | | */ |
6914 | 0 | if (local_exec) |
6915 | 0 | { |
6916 | 0 | bfd_putl32 (0xd53bd040, contents + rel->r_offset); |
6917 | 0 | return bfd_reloc_ok; |
6918 | 0 | } |
6919 | 0 | return bfd_reloc_continue; |
6920 | | |
6921 | 0 | case BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC: |
6922 | | /* LD->LE relaxation (small): |
6923 | | add x0, #:tlsldm_lo12:x => add R0, R0, TCB_SIZE |
6924 | | bl __tls_get_addr => nop |
6925 | | |
6926 | | Where R is x for lp64 mode, and w for ilp32 mode. */ |
6927 | 0 | if (local_exec) |
6928 | 0 | { |
6929 | 0 | BFD_ASSERT (rel->r_offset + 4 == rel[1].r_offset); |
6930 | 0 | BFD_ASSERT (ELF64_R_TYPE (rel[1].r_info) == AARCH64_R (CALL26)); |
6931 | | /* No need of CALL26 relocation for tls_get_addr. */ |
6932 | 0 | rel[1].r_info = ELF64_R_INFO (STN_UNDEF, R_AARCH64_NONE); |
6933 | 0 | bfd_putl32 (add_R0_R0 | (TCB_SIZE << 10), |
6934 | 0 | contents + rel->r_offset + 0); |
6935 | 0 | bfd_putl32 (INSN_NOP, contents + rel->r_offset + 4); |
6936 | 0 | return bfd_reloc_ok; |
6937 | 0 | } |
6938 | 0 | return bfd_reloc_continue; |
6939 | | |
6940 | 0 | default: |
6941 | 0 | return bfd_reloc_continue; |
6942 | 0 | } |
6943 | | |
6944 | 0 | return bfd_reloc_ok; |
6945 | 0 | } |
6946 | | |
6947 | | /* Relocate an AArch64 ELF section. */ |
6948 | | |
6949 | | static int |
6950 | | elf64_aarch64_relocate_section (bfd *output_bfd, |
6951 | | struct bfd_link_info *info, |
6952 | | bfd *input_bfd, |
6953 | | asection *input_section, |
6954 | | bfd_byte *contents, |
6955 | | Elf_Internal_Rela *relocs, |
6956 | | Elf_Internal_Sym *local_syms, |
6957 | | asection **local_sections) |
6958 | 0 | { |
6959 | 0 | Elf_Internal_Shdr *symtab_hdr; |
6960 | 0 | struct elf_link_hash_entry **sym_hashes; |
6961 | 0 | Elf_Internal_Rela *rel; |
6962 | 0 | Elf_Internal_Rela *relend; |
6963 | 0 | const char *name; |
6964 | 0 | struct elf_aarch64_link_hash_table *globals; |
6965 | 0 | bool save_addend = false; |
6966 | 0 | bfd_vma addend = 0; |
6967 | |
|
6968 | 0 | globals = elf_aarch64_hash_table (info); |
6969 | |
|
6970 | 0 | symtab_hdr = &elf_symtab_hdr (input_bfd); |
6971 | 0 | sym_hashes = elf_sym_hashes (input_bfd); |
6972 | |
|
6973 | 0 | rel = relocs; |
6974 | 0 | relend = relocs + input_section->reloc_count; |
6975 | 0 | for (; rel < relend; rel++) |
6976 | 0 | { |
6977 | 0 | unsigned int r_type; |
6978 | 0 | bfd_reloc_code_real_type bfd_r_type; |
6979 | 0 | bfd_reloc_code_real_type relaxed_bfd_r_type; |
6980 | 0 | reloc_howto_type *howto; |
6981 | 0 | unsigned long r_symndx; |
6982 | 0 | Elf_Internal_Sym *sym; |
6983 | 0 | asection *sec; |
6984 | 0 | struct elf_link_hash_entry *h; |
6985 | 0 | bfd_vma relocation; |
6986 | 0 | bfd_reloc_status_type r; |
6987 | 0 | arelent bfd_reloc; |
6988 | 0 | char sym_type; |
6989 | 0 | bool unresolved_reloc = false; |
6990 | 0 | char *error_message = NULL; |
6991 | |
|
6992 | 0 | r_symndx = ELF64_R_SYM (rel->r_info); |
6993 | 0 | r_type = ELF64_R_TYPE (rel->r_info); |
6994 | |
|
6995 | 0 | bfd_reloc.howto = elf64_aarch64_howto_from_type (input_bfd, r_type); |
6996 | 0 | howto = bfd_reloc.howto; |
6997 | |
|
6998 | 0 | if (howto == NULL) |
6999 | 0 | return _bfd_unrecognized_reloc (input_bfd, input_section, r_type); |
7000 | | |
7001 | 0 | bfd_r_type = elf64_aarch64_bfd_reloc_from_howto (howto); |
7002 | |
|
7003 | 0 | h = NULL; |
7004 | 0 | sym = NULL; |
7005 | 0 | sec = NULL; |
7006 | |
|
7007 | 0 | if (r_symndx < symtab_hdr->sh_info) |
7008 | 0 | { |
7009 | 0 | sym = local_syms + r_symndx; |
7010 | 0 | sym_type = ELF64_ST_TYPE (sym->st_info); |
7011 | 0 | sec = local_sections[r_symndx]; |
7012 | | |
7013 | | /* An object file might have a reference to a local |
7014 | | undefined symbol. This is a daft object file, but we |
7015 | | should at least do something about it. NONE and NULL |
7016 | | relocations do not use the symbol and are explicitly |
7017 | | allowed to use an undefined one, so allow those. |
7018 | | Likewise for relocations against STN_UNDEF. */ |
7019 | 0 | if (r_type != R_AARCH64_NONE && r_type != R_AARCH64_NULL |
7020 | 0 | && r_symndx != STN_UNDEF |
7021 | 0 | && bfd_is_und_section (sec) |
7022 | 0 | && ELF_ST_BIND (sym->st_info) != STB_WEAK) |
7023 | 0 | (*info->callbacks->undefined_symbol) |
7024 | 0 | (info, bfd_elf_string_from_elf_section |
7025 | 0 | (input_bfd, symtab_hdr->sh_link, sym->st_name), |
7026 | 0 | input_bfd, input_section, rel->r_offset, true); |
7027 | |
|
7028 | 0 | relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel); |
7029 | | |
7030 | | /* Relocate against local STT_GNU_IFUNC symbol. */ |
7031 | 0 | if (!bfd_link_relocatable (info) |
7032 | 0 | && ELF_ST_TYPE (sym->st_info) == STT_GNU_IFUNC) |
7033 | 0 | { |
7034 | 0 | h = elf64_aarch64_get_local_sym_hash (globals, input_bfd, |
7035 | 0 | rel, false); |
7036 | 0 | if (h == NULL) |
7037 | 0 | abort (); |
7038 | | |
7039 | | /* Set STT_GNU_IFUNC symbol value. */ |
7040 | 0 | h->root.u.def.value = sym->st_value; |
7041 | 0 | h->root.u.def.section = sec; |
7042 | 0 | } |
7043 | 0 | } |
7044 | 0 | else |
7045 | 0 | { |
7046 | 0 | bool warned, ignored; |
7047 | |
|
7048 | 0 | RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel, |
7049 | 0 | r_symndx, symtab_hdr, sym_hashes, |
7050 | 0 | h, sec, relocation, |
7051 | 0 | unresolved_reloc, warned, ignored); |
7052 | | |
7053 | 0 | sym_type = h->type; |
7054 | 0 | } |
7055 | | |
7056 | 0 | if (sec != NULL && discarded_section (sec)) |
7057 | 0 | RELOC_AGAINST_DISCARDED_SECTION (info, input_bfd, input_section, |
7058 | 0 | rel, 1, relend, howto, 0, contents); |
7059 | |
|
7060 | 0 | if (bfd_link_relocatable (info)) |
7061 | 0 | continue; |
7062 | | |
7063 | 0 | if (h != NULL) |
7064 | 0 | name = h->root.root.string; |
7065 | 0 | else |
7066 | 0 | { |
7067 | 0 | name = (bfd_elf_string_from_elf_section |
7068 | 0 | (input_bfd, symtab_hdr->sh_link, sym->st_name)); |
7069 | 0 | if (name == NULL || *name == '\0') |
7070 | 0 | name = bfd_section_name (sec); |
7071 | 0 | } |
7072 | |
|
7073 | 0 | if (r_symndx != 0 |
7074 | 0 | && r_type != R_AARCH64_NONE |
7075 | 0 | && r_type != R_AARCH64_NULL |
7076 | 0 | && (h == NULL |
7077 | 0 | || h->root.type == bfd_link_hash_defined |
7078 | 0 | || h->root.type == bfd_link_hash_defweak) |
7079 | 0 | && IS_AARCH64_TLS_RELOC (bfd_r_type) != (sym_type == STT_TLS)) |
7080 | 0 | { |
7081 | 0 | _bfd_error_handler |
7082 | 0 | ((sym_type == STT_TLS |
7083 | | /* xgettext:c-format */ |
7084 | 0 | ? _("%pB(%pA+%#" PRIx64 "): %s used with TLS symbol %s") |
7085 | | /* xgettext:c-format */ |
7086 | 0 | : _("%pB(%pA+%#" PRIx64 "): %s used with non-TLS symbol %s")), |
7087 | 0 | input_bfd, |
7088 | 0 | input_section, (uint64_t) rel->r_offset, howto->name, name); |
7089 | 0 | } |
7090 | | |
7091 | | /* We relax only if we can see that there can be a valid transition |
7092 | | from a reloc type to another. |
7093 | | We call elf64_aarch64_final_link_relocate unless we're completely |
7094 | | done, i.e., the relaxation produced the final output we want. */ |
7095 | |
|
7096 | 0 | relaxed_bfd_r_type = aarch64_tls_transition (input_bfd, info, r_type, |
7097 | 0 | h, r_symndx); |
7098 | 0 | if (relaxed_bfd_r_type != bfd_r_type) |
7099 | 0 | { |
7100 | 0 | bfd_r_type = relaxed_bfd_r_type; |
7101 | 0 | howto = elf64_aarch64_howto_from_bfd_reloc (bfd_r_type); |
7102 | 0 | BFD_ASSERT (howto != NULL); |
7103 | 0 | r_type = howto->type; |
7104 | 0 | r = elf64_aarch64_tls_relax (globals, input_bfd, input_section, |
7105 | 0 | contents, rel, h, info); |
7106 | 0 | unresolved_reloc = 0; |
7107 | 0 | } |
7108 | 0 | else |
7109 | 0 | r = bfd_reloc_continue; |
7110 | | |
7111 | | /* There may be multiple consecutive relocations for the |
7112 | | same offset. In that case we are supposed to treat the |
7113 | | output of each relocation as the addend for the next. */ |
7114 | 0 | if (rel + 1 < relend |
7115 | 0 | && rel->r_offset == rel[1].r_offset |
7116 | 0 | && ELF64_R_TYPE (rel[1].r_info) != R_AARCH64_NONE |
7117 | 0 | && ELF64_R_TYPE (rel[1].r_info) != R_AARCH64_NULL) |
7118 | 0 | save_addend = true; |
7119 | 0 | else |
7120 | 0 | save_addend = false; |
7121 | |
|
7122 | 0 | if (r == bfd_reloc_continue) |
7123 | 0 | r = elf64_aarch64_final_link_relocate (howto, input_bfd, output_bfd, |
7124 | 0 | input_section, contents, rel, |
7125 | 0 | relocation, info, sec, |
7126 | 0 | h, &unresolved_reloc, |
7127 | 0 | save_addend, &addend, sym); |
7128 | |
|
7129 | 0 | switch (elf64_aarch64_bfd_reloc_from_type (input_bfd, r_type)) |
7130 | 0 | { |
7131 | 0 | case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC: |
7132 | 0 | case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21: |
7133 | 0 | case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21: |
7134 | 0 | case BFD_RELOC_AARCH64_TLSGD_MOVW_G0_NC: |
7135 | 0 | case BFD_RELOC_AARCH64_TLSGD_MOVW_G1: |
7136 | 0 | case BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC: |
7137 | 0 | case BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21: |
7138 | 0 | case BFD_RELOC_AARCH64_TLSLD_ADR_PREL21: |
7139 | 0 | if (! symbol_got_offset_mark_p (input_bfd, h, r_symndx)) |
7140 | 0 | { |
7141 | 0 | bool need_relocs = false; |
7142 | 0 | bfd_byte *loc; |
7143 | 0 | int indx; |
7144 | 0 | bfd_vma off; |
7145 | |
|
7146 | 0 | off = symbol_got_offset (input_bfd, h, r_symndx); |
7147 | 0 | indx = h && h->dynindx != -1 ? h->dynindx : 0; |
7148 | |
|
7149 | 0 | need_relocs = |
7150 | 0 | (!bfd_link_executable (info) || indx != 0) && |
7151 | 0 | (h == NULL |
7152 | 0 | || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT |
7153 | 0 | || h->root.type != bfd_link_hash_undefweak); |
7154 | |
|
7155 | 0 | BFD_ASSERT (globals->root.srelgot != NULL); |
7156 | |
|
7157 | 0 | if (need_relocs) |
7158 | 0 | { |
7159 | 0 | Elf_Internal_Rela rela; |
7160 | 0 | rela.r_info = ELF64_R_INFO (indx, AARCH64_R (TLS_DTPMOD)); |
7161 | 0 | rela.r_addend = 0; |
7162 | 0 | rela.r_offset = globals->root.sgot->output_section->vma + |
7163 | 0 | globals->root.sgot->output_offset + off; |
7164 | | |
7165 | |
|
7166 | 0 | loc = globals->root.srelgot->contents; |
7167 | 0 | loc += globals->root.srelgot->reloc_count++ |
7168 | 0 | * RELOC_SIZE (htab); |
7169 | 0 | bfd_elf64_swap_reloca_out (output_bfd, &rela, loc); |
7170 | |
|
7171 | 0 | bfd_reloc_code_real_type real_type = |
7172 | 0 | elf64_aarch64_bfd_reloc_from_type (input_bfd, r_type); |
7173 | |
|
7174 | 0 | if (real_type == BFD_RELOC_AARCH64_TLSLD_ADR_PREL21 |
7175 | 0 | || real_type == BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21 |
7176 | 0 | || real_type == BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC) |
7177 | 0 | { |
7178 | | /* For local dynamic, don't generate DTPREL in any case. |
7179 | | Initialize the DTPREL slot into zero, so we get module |
7180 | | base address when invoke runtime TLS resolver. */ |
7181 | 0 | bfd_put_64 (output_bfd, 0, |
7182 | 0 | globals->root.sgot->contents + off |
7183 | 0 | + GOT_ENTRY_SIZE); |
7184 | 0 | } |
7185 | 0 | else if (indx == 0) |
7186 | 0 | { |
7187 | 0 | bfd_put_64 (output_bfd, |
7188 | 0 | relocation - dtpoff_base (info), |
7189 | 0 | globals->root.sgot->contents + off |
7190 | 0 | + GOT_ENTRY_SIZE); |
7191 | 0 | } |
7192 | 0 | else |
7193 | 0 | { |
7194 | | /* This TLS symbol is global. We emit a |
7195 | | relocation to fixup the tls offset at load |
7196 | | time. */ |
7197 | 0 | rela.r_info = |
7198 | 0 | ELF64_R_INFO (indx, AARCH64_R (TLS_DTPREL)); |
7199 | 0 | rela.r_addend = 0; |
7200 | 0 | rela.r_offset = |
7201 | 0 | (globals->root.sgot->output_section->vma |
7202 | 0 | + globals->root.sgot->output_offset + off |
7203 | 0 | + GOT_ENTRY_SIZE); |
7204 | |
|
7205 | 0 | loc = globals->root.srelgot->contents; |
7206 | 0 | loc += globals->root.srelgot->reloc_count++ |
7207 | 0 | * RELOC_SIZE (globals); |
7208 | 0 | bfd_elf64_swap_reloca_out (output_bfd, &rela, loc); |
7209 | 0 | bfd_put_64 (output_bfd, (bfd_vma) 0, |
7210 | 0 | globals->root.sgot->contents + off |
7211 | 0 | + GOT_ENTRY_SIZE); |
7212 | 0 | } |
7213 | 0 | } |
7214 | 0 | else |
7215 | 0 | { |
7216 | 0 | bfd_put_64 (output_bfd, (bfd_vma) 1, |
7217 | 0 | globals->root.sgot->contents + off); |
7218 | 0 | bfd_put_64 (output_bfd, |
7219 | 0 | relocation - dtpoff_base (info), |
7220 | 0 | globals->root.sgot->contents + off |
7221 | 0 | + GOT_ENTRY_SIZE); |
7222 | 0 | } |
7223 | |
|
7224 | 0 | symbol_got_offset_mark (input_bfd, h, r_symndx); |
7225 | 0 | } |
7226 | 0 | break; |
7227 | | |
7228 | 0 | case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21: |
7229 | 0 | case BFD_RELOC_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC: |
7230 | 0 | case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19: |
7231 | 0 | case BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G0_NC: |
7232 | 0 | case BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G1: |
7233 | 0 | if (! symbol_got_offset_mark_p (input_bfd, h, r_symndx)) |
7234 | 0 | { |
7235 | 0 | bool need_relocs = false; |
7236 | 0 | bfd_byte *loc; |
7237 | 0 | int indx; |
7238 | 0 | bfd_vma off; |
7239 | |
|
7240 | 0 | off = symbol_got_offset (input_bfd, h, r_symndx); |
7241 | |
|
7242 | 0 | indx = h && h->dynindx != -1 ? h->dynindx : 0; |
7243 | |
|
7244 | 0 | need_relocs = |
7245 | 0 | (!bfd_link_executable (info) || indx != 0) && |
7246 | 0 | (h == NULL |
7247 | 0 | || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT |
7248 | 0 | || h->root.type != bfd_link_hash_undefweak); |
7249 | |
|
7250 | 0 | BFD_ASSERT (globals->root.srelgot != NULL); |
7251 | |
|
7252 | 0 | if (need_relocs) |
7253 | 0 | { |
7254 | 0 | Elf_Internal_Rela rela; |
7255 | |
|
7256 | 0 | if (indx == 0) |
7257 | 0 | rela.r_addend = relocation - dtpoff_base (info); |
7258 | 0 | else |
7259 | 0 | rela.r_addend = 0; |
7260 | |
|
7261 | 0 | rela.r_info = ELF64_R_INFO (indx, AARCH64_R (TLS_TPREL)); |
7262 | 0 | rela.r_offset = globals->root.sgot->output_section->vma + |
7263 | 0 | globals->root.sgot->output_offset + off; |
7264 | |
|
7265 | 0 | loc = globals->root.srelgot->contents; |
7266 | 0 | loc += globals->root.srelgot->reloc_count++ |
7267 | 0 | * RELOC_SIZE (htab); |
7268 | |
|
7269 | 0 | bfd_elf64_swap_reloca_out (output_bfd, &rela, loc); |
7270 | |
|
7271 | 0 | bfd_put_64 (output_bfd, rela.r_addend, |
7272 | 0 | globals->root.sgot->contents + off); |
7273 | 0 | } |
7274 | 0 | else |
7275 | 0 | bfd_put_64 (output_bfd, relocation - tpoff_base (info), |
7276 | 0 | globals->root.sgot->contents + off); |
7277 | |
|
7278 | 0 | symbol_got_offset_mark (input_bfd, h, r_symndx); |
7279 | 0 | } |
7280 | 0 | break; |
7281 | | |
7282 | 0 | case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12: |
7283 | 0 | case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21: |
7284 | 0 | case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21: |
7285 | 0 | case BFD_RELOC_AARCH64_TLSDESC_LD64_LO12_NC: |
7286 | 0 | case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19: |
7287 | 0 | case BFD_RELOC_AARCH64_TLSDESC_OFF_G0_NC: |
7288 | 0 | case BFD_RELOC_AARCH64_TLSDESC_OFF_G1: |
7289 | 0 | if (! symbol_tlsdesc_got_offset_mark_p (input_bfd, h, r_symndx)) |
7290 | 0 | { |
7291 | 0 | bool need_relocs = false; |
7292 | 0 | int indx = h && h->dynindx != -1 ? h->dynindx : 0; |
7293 | 0 | bfd_vma off = symbol_tlsdesc_got_offset (input_bfd, h, r_symndx); |
7294 | |
|
7295 | 0 | need_relocs = (h == NULL |
7296 | 0 | || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT |
7297 | 0 | || h->root.type != bfd_link_hash_undefweak); |
7298 | |
|
7299 | 0 | BFD_ASSERT (globals->root.srelgot != NULL); |
7300 | 0 | BFD_ASSERT (globals->root.sgot != NULL); |
7301 | |
|
7302 | 0 | if (need_relocs) |
7303 | 0 | { |
7304 | 0 | bfd_byte *loc; |
7305 | 0 | Elf_Internal_Rela rela; |
7306 | 0 | rela.r_info = ELF64_R_INFO (indx, AARCH64_R (TLSDESC)); |
7307 | |
|
7308 | 0 | rela.r_addend = 0; |
7309 | 0 | rela.r_offset = (globals->root.sgotplt->output_section->vma |
7310 | 0 | + globals->root.sgotplt->output_offset |
7311 | 0 | + off + globals->sgotplt_jump_table_size); |
7312 | |
|
7313 | 0 | if (indx == 0) |
7314 | 0 | rela.r_addend = relocation - dtpoff_base (info); |
7315 | | |
7316 | | /* Allocate the next available slot in the PLT reloc |
7317 | | section to hold our R_AARCH64_TLSDESC, the next |
7318 | | available slot is determined from reloc_count, |
7319 | | which we step. But note, reloc_count was |
7320 | | artifically moved down while allocating slots for |
7321 | | real PLT relocs such that all of the PLT relocs |
7322 | | will fit above the initial reloc_count and the |
7323 | | extra stuff will fit below. */ |
7324 | 0 | loc = globals->root.srelplt->contents; |
7325 | 0 | loc += globals->root.srelplt->reloc_count++ |
7326 | 0 | * RELOC_SIZE (globals); |
7327 | |
|
7328 | 0 | bfd_elf64_swap_reloca_out (output_bfd, &rela, loc); |
7329 | |
|
7330 | 0 | bfd_put_64 (output_bfd, (bfd_vma) 0, |
7331 | 0 | globals->root.sgotplt->contents + off + |
7332 | 0 | globals->sgotplt_jump_table_size); |
7333 | 0 | bfd_put_64 (output_bfd, (bfd_vma) 0, |
7334 | 0 | globals->root.sgotplt->contents + off + |
7335 | 0 | globals->sgotplt_jump_table_size + |
7336 | 0 | GOT_ENTRY_SIZE); |
7337 | 0 | } |
7338 | |
|
7339 | 0 | symbol_tlsdesc_got_offset_mark (input_bfd, h, r_symndx); |
7340 | 0 | } |
7341 | 0 | break; |
7342 | 0 | default: |
7343 | 0 | break; |
7344 | 0 | } |
7345 | | |
7346 | | /* Dynamic relocs are not propagated for SEC_DEBUGGING sections |
7347 | | because such sections are not SEC_ALLOC and thus ld.so will |
7348 | | not process them. */ |
7349 | 0 | if (unresolved_reloc |
7350 | 0 | && !((input_section->flags & SEC_DEBUGGING) != 0 |
7351 | 0 | && h->def_dynamic) |
7352 | 0 | && _bfd_elf_section_offset (output_bfd, info, input_section, |
7353 | 0 | +rel->r_offset) != (bfd_vma) - 1) |
7354 | 0 | { |
7355 | 0 | _bfd_error_handler |
7356 | | /* xgettext:c-format */ |
7357 | 0 | (_("%pB(%pA+%#" PRIx64 "): " |
7358 | 0 | "unresolvable %s relocation against symbol `%s'"), |
7359 | 0 | input_bfd, input_section, (uint64_t) rel->r_offset, howto->name, |
7360 | 0 | h->root.root.string); |
7361 | 0 | return false; |
7362 | 0 | } |
7363 | | |
7364 | 0 | if (r != bfd_reloc_ok && r != bfd_reloc_continue) |
7365 | 0 | { |
7366 | 0 | bfd_reloc_code_real_type real_r_type |
7367 | 0 | = elf64_aarch64_bfd_reloc_from_type (input_bfd, r_type); |
7368 | |
|
7369 | 0 | switch (r) |
7370 | 0 | { |
7371 | 0 | case bfd_reloc_overflow: |
7372 | 0 | (*info->callbacks->reloc_overflow) |
7373 | 0 | (info, (h ? &h->root : NULL), name, howto->name, (bfd_vma) 0, |
7374 | 0 | input_bfd, input_section, rel->r_offset); |
7375 | 0 | if (real_r_type == BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15 |
7376 | 0 | || real_r_type == BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14) |
7377 | 0 | { |
7378 | 0 | (*info->callbacks->warning) |
7379 | 0 | (info, |
7380 | 0 | _("too many GOT entries for -fpic, " |
7381 | 0 | "please recompile with -fPIC"), |
7382 | 0 | name, input_bfd, input_section, rel->r_offset); |
7383 | 0 | return false; |
7384 | 0 | } |
7385 | | /* Overflow can occur when a variable is referenced with a type |
7386 | | that has a larger alignment than the type with which it was |
7387 | | declared. eg: |
7388 | | file1.c: extern int foo; int a (void) { return foo; } |
7389 | | file2.c: char bar, foo, baz; |
7390 | | If the variable is placed into a data section at an offset |
7391 | | that is incompatible with the larger alignment requirement |
7392 | | overflow will occur. (Strictly speaking this is not overflow |
7393 | | but rather an alignment problem, but the bfd_reloc_ error |
7394 | | enum does not have a value to cover that situation). |
7395 | | |
7396 | | Try to catch this situation here and provide a more helpful |
7397 | | error message to the user. */ |
7398 | 0 | if (addend & (((bfd_vma) 1 << howto->rightshift) - 1) |
7399 | | /* FIXME: Are we testing all of the appropriate reloc |
7400 | | types here ? */ |
7401 | 0 | && (real_r_type == BFD_RELOC_AARCH64_LD_LO19_PCREL |
7402 | 0 | || real_r_type == BFD_RELOC_AARCH64_LDST16_LO12 |
7403 | 0 | || real_r_type == BFD_RELOC_AARCH64_LDST32_LO12 |
7404 | 0 | || real_r_type == BFD_RELOC_AARCH64_LDST64_LO12 |
7405 | 0 | || real_r_type == BFD_RELOC_AARCH64_LDST128_LO12)) |
7406 | 0 | { |
7407 | 0 | info->callbacks->warning |
7408 | 0 | (info, _("one possible cause of this error is that the \ |
7409 | 0 | symbol is being referenced in the indicated code as if it had a larger \ |
7410 | 0 | alignment than was declared where it was defined"), |
7411 | 0 | name, input_bfd, input_section, rel->r_offset); |
7412 | 0 | } |
7413 | 0 | break; |
7414 | | |
7415 | 0 | case bfd_reloc_undefined: |
7416 | 0 | (*info->callbacks->undefined_symbol) |
7417 | 0 | (info, name, input_bfd, input_section, rel->r_offset, true); |
7418 | 0 | break; |
7419 | | |
7420 | 0 | case bfd_reloc_outofrange: |
7421 | 0 | error_message = _("out of range"); |
7422 | 0 | goto common_error; |
7423 | | |
7424 | 0 | case bfd_reloc_notsupported: |
7425 | 0 | error_message = _("unsupported relocation"); |
7426 | 0 | goto common_error; |
7427 | | |
7428 | 0 | case bfd_reloc_dangerous: |
7429 | | /* error_message should already be set. */ |
7430 | 0 | goto common_error; |
7431 | | |
7432 | 0 | default: |
7433 | 0 | error_message = _("unknown error"); |
7434 | | /* Fall through. */ |
7435 | |
|
7436 | 0 | common_error: |
7437 | 0 | BFD_ASSERT (error_message != NULL); |
7438 | 0 | (*info->callbacks->reloc_dangerous) |
7439 | 0 | (info, error_message, input_bfd, input_section, rel->r_offset); |
7440 | 0 | break; |
7441 | 0 | } |
7442 | 0 | } |
7443 | | |
7444 | 0 | if (!save_addend) |
7445 | 0 | addend = 0; |
7446 | 0 | } |
7447 | | |
7448 | 0 | return true; |
7449 | 0 | } |
7450 | | |
7451 | | /* Set the right machine number. */ |
7452 | | |
7453 | | static bool |
7454 | | elf64_aarch64_object_p (bfd *abfd) |
7455 | 4.57k | { |
7456 | | #if ARCH_SIZE == 32 |
7457 | | bfd_default_set_arch_mach (abfd, bfd_arch_aarch64, bfd_mach_aarch64_ilp32); |
7458 | | #else |
7459 | 4.57k | bfd_default_set_arch_mach (abfd, bfd_arch_aarch64, bfd_mach_aarch64); |
7460 | 4.57k | #endif |
7461 | 4.57k | return true; |
7462 | 4.57k | } |
7463 | | |
7464 | | /* Function to keep AArch64 specific flags in the ELF header. */ |
7465 | | |
7466 | | static bool |
7467 | | elf64_aarch64_set_private_flags (bfd *abfd, flagword flags) |
7468 | 0 | { |
7469 | 0 | if (elf_flags_init (abfd) && elf_elfheader (abfd)->e_flags != flags) |
7470 | 0 | { |
7471 | 0 | } |
7472 | 0 | else |
7473 | 0 | { |
7474 | 0 | elf_elfheader (abfd)->e_flags = flags; |
7475 | 0 | elf_flags_init (abfd) = true; |
7476 | 0 | } |
7477 | |
|
7478 | 0 | return true; |
7479 | 0 | } |
7480 | | |
7481 | | /* Merge backend specific data from an object file to the output |
7482 | | object file when linking. */ |
7483 | | |
7484 | | static bool |
7485 | | elf64_aarch64_merge_private_bfd_data (bfd *ibfd, struct bfd_link_info *info) |
7486 | 0 | { |
7487 | 0 | bfd *obfd = info->output_bfd; |
7488 | 0 | flagword out_flags; |
7489 | 0 | flagword in_flags; |
7490 | 0 | bool flags_compatible = true; |
7491 | 0 | asection *sec; |
7492 | | |
7493 | | /* Check if we have the same endianess. */ |
7494 | 0 | if (!_bfd_generic_verify_endian_match (ibfd, info)) |
7495 | 0 | return false; |
7496 | | |
7497 | 0 | if (!is_aarch64_elf (ibfd) || !is_aarch64_elf (obfd)) |
7498 | 0 | return true; |
7499 | | |
7500 | | /* The input BFD must have had its flags initialised. */ |
7501 | | /* The following seems bogus to me -- The flags are initialized in |
7502 | | the assembler but I don't think an elf_flags_init field is |
7503 | | written into the object. */ |
7504 | | /* BFD_ASSERT (elf_flags_init (ibfd)); */ |
7505 | | |
7506 | 0 | in_flags = elf_elfheader (ibfd)->e_flags; |
7507 | 0 | out_flags = elf_elfheader (obfd)->e_flags; |
7508 | |
|
7509 | 0 | if (!elf_flags_init (obfd)) |
7510 | 0 | { |
7511 | | /* If the input is the default architecture and had the default |
7512 | | flags then do not bother setting the flags for the output |
7513 | | architecture, instead allow future merges to do this. If no |
7514 | | future merges ever set these flags then they will retain their |
7515 | | uninitialised values, which surprise surprise, correspond |
7516 | | to the default values. */ |
7517 | 0 | if (bfd_get_arch_info (ibfd)->the_default |
7518 | 0 | && elf_elfheader (ibfd)->e_flags == 0) |
7519 | 0 | return true; |
7520 | | |
7521 | 0 | elf_flags_init (obfd) = true; |
7522 | 0 | elf_elfheader (obfd)->e_flags = in_flags; |
7523 | |
|
7524 | 0 | if (bfd_get_arch (obfd) == bfd_get_arch (ibfd) |
7525 | 0 | && bfd_get_arch_info (obfd)->the_default) |
7526 | 0 | return bfd_set_arch_mach (obfd, bfd_get_arch (ibfd), |
7527 | 0 | bfd_get_mach (ibfd)); |
7528 | | |
7529 | 0 | return true; |
7530 | 0 | } |
7531 | | |
7532 | | /* Identical flags must be compatible. */ |
7533 | 0 | if (in_flags == out_flags) |
7534 | 0 | return true; |
7535 | | |
7536 | | /* Check to see if the input BFD actually contains any sections. If |
7537 | | not, its flags may not have been initialised either, but it |
7538 | | cannot actually cause any incompatiblity. Do not short-circuit |
7539 | | dynamic objects; their section list may be emptied by |
7540 | | elf_link_add_object_symbols. |
7541 | | |
7542 | | Also check to see if there are no code sections in the input. |
7543 | | In this case there is no need to check for code specific flags. |
7544 | | XXX - do we need to worry about floating-point format compatability |
7545 | | in data sections ? */ |
7546 | 0 | if (!(ibfd->flags & DYNAMIC)) |
7547 | 0 | { |
7548 | 0 | bool null_input_bfd = true; |
7549 | 0 | bool only_data_sections = true; |
7550 | |
|
7551 | 0 | for (sec = ibfd->sections; sec != NULL; sec = sec->next) |
7552 | 0 | { |
7553 | 0 | if ((bfd_section_flags (sec) |
7554 | 0 | & (SEC_LOAD | SEC_CODE | SEC_HAS_CONTENTS)) |
7555 | 0 | == (SEC_LOAD | SEC_CODE | SEC_HAS_CONTENTS)) |
7556 | 0 | only_data_sections = false; |
7557 | |
|
7558 | 0 | null_input_bfd = false; |
7559 | 0 | break; |
7560 | 0 | } |
7561 | |
|
7562 | 0 | if (null_input_bfd || only_data_sections) |
7563 | 0 | return true; |
7564 | 0 | } |
7565 | | |
7566 | 0 | return flags_compatible; |
7567 | 0 | } |
7568 | | |
7569 | | /* Display the flags field. */ |
7570 | | |
7571 | | static bool |
7572 | | elf64_aarch64_print_private_bfd_data (bfd *abfd, void *ptr) |
7573 | 37 | { |
7574 | 37 | FILE *file = (FILE *) ptr; |
7575 | 37 | unsigned long flags; |
7576 | | |
7577 | 37 | BFD_ASSERT (abfd != NULL && ptr != NULL); |
7578 | | |
7579 | | /* Print normal ELF private data. */ |
7580 | 37 | _bfd_elf_print_private_bfd_data (abfd, ptr); |
7581 | | |
7582 | 37 | flags = elf_elfheader (abfd)->e_flags; |
7583 | | /* Ignore init flag - it may not be set, despite the flags field |
7584 | | containing valid data. */ |
7585 | | |
7586 | | /* xgettext:c-format */ |
7587 | 37 | fprintf (file, _("private flags = 0x%lx:"), elf_elfheader (abfd)->e_flags); |
7588 | | |
7589 | 37 | if (flags) |
7590 | 19 | fprintf (file, _(" <Unrecognised flag bits set>")); |
7591 | | |
7592 | 37 | fputc ('\n', file); |
7593 | | |
7594 | 37 | return true; |
7595 | 37 | } |
7596 | | |
7597 | | /* Return true if we need copy relocation against EH. */ |
7598 | | |
7599 | | static bool |
7600 | | need_copy_relocation_p (struct elf_aarch64_link_hash_entry *eh) |
7601 | 0 | { |
7602 | 0 | struct elf_dyn_relocs *p; |
7603 | 0 | asection *s; |
7604 | |
|
7605 | 0 | for (p = eh->root.dyn_relocs; p != NULL; p = p->next) |
7606 | 0 | { |
7607 | | /* If there is any pc-relative reference, we need to keep copy relocation |
7608 | | to avoid propagating the relocation into runtime that current glibc |
7609 | | does not support. */ |
7610 | 0 | if (p->pc_count) |
7611 | 0 | return true; |
7612 | | |
7613 | 0 | s = p->sec->output_section; |
7614 | | /* Need copy relocation if it's against read-only section. */ |
7615 | 0 | if (s != NULL && (s->flags & SEC_READONLY) != 0) |
7616 | 0 | return true; |
7617 | 0 | } |
7618 | | |
7619 | 0 | return false; |
7620 | 0 | } |
7621 | | |
7622 | | /* Adjust a symbol defined by a dynamic object and referenced by a |
7623 | | regular object. The current definition is in some section of the |
7624 | | dynamic object, but we're not including those sections. We have to |
7625 | | change the definition to something the rest of the link can |
7626 | | understand. */ |
7627 | | |
7628 | | static bool |
7629 | | elf64_aarch64_adjust_dynamic_symbol (struct bfd_link_info *info, |
7630 | | struct elf_link_hash_entry *h) |
7631 | 0 | { |
7632 | 0 | struct elf_aarch64_link_hash_table *htab; |
7633 | 0 | asection *s, *srel; |
7634 | | |
7635 | | /* If this is a function, put it in the procedure linkage table. We |
7636 | | will fill in the contents of the procedure linkage table later, |
7637 | | when we know the address of the .got section. */ |
7638 | 0 | if (h->type == STT_FUNC || h->type == STT_GNU_IFUNC || h->needs_plt) |
7639 | 0 | { |
7640 | 0 | if (h->plt.refcount <= 0 |
7641 | 0 | || (h->type != STT_GNU_IFUNC |
7642 | 0 | && (SYMBOL_CALLS_LOCAL (info, h) |
7643 | 0 | || (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT |
7644 | 0 | && h->root.type == bfd_link_hash_undefweak)))) |
7645 | 0 | { |
7646 | | /* This case can occur if we saw a CALL26 reloc in |
7647 | | an input file, but the symbol wasn't referred to |
7648 | | by a dynamic object or all references were |
7649 | | garbage collected. In which case we can end up |
7650 | | resolving. */ |
7651 | 0 | h->plt.offset = (bfd_vma) - 1; |
7652 | 0 | h->needs_plt = 0; |
7653 | 0 | } |
7654 | |
|
7655 | 0 | return true; |
7656 | 0 | } |
7657 | 0 | else |
7658 | | /* Otherwise, reset to -1. */ |
7659 | 0 | h->plt.offset = (bfd_vma) - 1; |
7660 | | |
7661 | | |
7662 | | /* If this is a weak symbol, and there is a real definition, the |
7663 | | processor independent code will have arranged for us to see the |
7664 | | real definition first, and we can just use the same value. */ |
7665 | 0 | if (h->is_weakalias) |
7666 | 0 | { |
7667 | 0 | struct elf_link_hash_entry *def = weakdef (h); |
7668 | 0 | BFD_ASSERT (def->root.type == bfd_link_hash_defined); |
7669 | 0 | h->root.u.def.section = def->root.u.def.section; |
7670 | 0 | h->root.u.def.value = def->root.u.def.value; |
7671 | 0 | if (ELIMINATE_COPY_RELOCS || info->nocopyreloc) |
7672 | 0 | h->non_got_ref = def->non_got_ref; |
7673 | 0 | return true; |
7674 | 0 | } |
7675 | | |
7676 | | /* If we are creating a shared library, we must presume that the |
7677 | | only references to the symbol are via the global offset table. |
7678 | | For such cases we need not do anything here; the relocations will |
7679 | | be handled correctly by relocate_section. */ |
7680 | 0 | if (bfd_link_pic (info)) |
7681 | 0 | return true; |
7682 | | |
7683 | | /* If there are no references to this symbol that do not use the |
7684 | | GOT, we don't need to generate a copy reloc. */ |
7685 | 0 | if (!h->non_got_ref) |
7686 | 0 | return true; |
7687 | | |
7688 | | /* If -z nocopyreloc was given, we won't generate them either. */ |
7689 | 0 | if (info->nocopyreloc) |
7690 | 0 | { |
7691 | 0 | h->non_got_ref = 0; |
7692 | 0 | return true; |
7693 | 0 | } |
7694 | | |
7695 | 0 | if (ELIMINATE_COPY_RELOCS) |
7696 | 0 | { |
7697 | 0 | struct elf_aarch64_link_hash_entry *eh; |
7698 | | /* If we don't find any dynamic relocs in read-only sections, then |
7699 | | we'll be keeping the dynamic relocs and avoiding the copy reloc. */ |
7700 | 0 | eh = (struct elf_aarch64_link_hash_entry *) h; |
7701 | 0 | if (!need_copy_relocation_p (eh)) |
7702 | 0 | { |
7703 | 0 | h->non_got_ref = 0; |
7704 | 0 | return true; |
7705 | 0 | } |
7706 | 0 | } |
7707 | | |
7708 | | /* We must allocate the symbol in our .dynbss section, which will |
7709 | | become part of the .bss section of the executable. There will be |
7710 | | an entry for this symbol in the .dynsym section. The dynamic |
7711 | | object will contain position independent code, so all references |
7712 | | from the dynamic object to this symbol will go through the global |
7713 | | offset table. The dynamic linker will use the .dynsym entry to |
7714 | | determine the address it must put in the global offset table, so |
7715 | | both the dynamic object and the regular object will refer to the |
7716 | | same memory location for the variable. */ |
7717 | | |
7718 | 0 | htab = elf_aarch64_hash_table (info); |
7719 | | |
7720 | | /* We must generate a R_AARCH64_COPY reloc to tell the dynamic linker |
7721 | | to copy the initial value out of the dynamic object and into the |
7722 | | runtime process image. */ |
7723 | 0 | if ((h->root.u.def.section->flags & SEC_READONLY) != 0) |
7724 | 0 | { |
7725 | 0 | s = htab->root.sdynrelro; |
7726 | 0 | srel = htab->root.sreldynrelro; |
7727 | 0 | } |
7728 | 0 | else |
7729 | 0 | { |
7730 | 0 | s = htab->root.sdynbss; |
7731 | 0 | srel = htab->root.srelbss; |
7732 | 0 | } |
7733 | 0 | if ((h->root.u.def.section->flags & SEC_ALLOC) != 0 && h->size != 0) |
7734 | 0 | { |
7735 | 0 | srel->size += RELOC_SIZE (htab); |
7736 | 0 | h->needs_copy = 1; |
7737 | 0 | } |
7738 | |
|
7739 | 0 | return _bfd_elf_adjust_dynamic_copy (info, h, s); |
7740 | |
|
7741 | 0 | } |
7742 | | |
7743 | | static bool |
7744 | | elf64_aarch64_allocate_local_symbols (bfd *abfd, unsigned number) |
7745 | 0 | { |
7746 | 0 | struct elf_aarch64_local_symbol *locals; |
7747 | 0 | locals = elf_aarch64_locals (abfd); |
7748 | 0 | if (locals == NULL) |
7749 | 0 | { |
7750 | 0 | locals = (struct elf_aarch64_local_symbol *) |
7751 | 0 | bfd_zalloc (abfd, number * sizeof (struct elf_aarch64_local_symbol)); |
7752 | 0 | if (locals == NULL) |
7753 | 0 | return false; |
7754 | 0 | elf_aarch64_locals (abfd) = locals; |
7755 | 0 | } |
7756 | 0 | return true; |
7757 | 0 | } |
7758 | | |
7759 | | /* Create the .got section to hold the global offset table. */ |
7760 | | |
7761 | | static bool |
7762 | | aarch64_elf_create_got_section (bfd *abfd, struct bfd_link_info *info) |
7763 | 0 | { |
7764 | 0 | const struct elf_backend_data *bed = get_elf_backend_data (abfd); |
7765 | 0 | flagword flags; |
7766 | 0 | asection *s; |
7767 | 0 | struct elf_link_hash_entry *h; |
7768 | 0 | struct elf_link_hash_table *htab = elf_hash_table (info); |
7769 | | |
7770 | | /* This function may be called more than once. */ |
7771 | 0 | if (htab->sgot != NULL) |
7772 | 0 | return true; |
7773 | | |
7774 | 0 | flags = bed->dynamic_sec_flags; |
7775 | |
|
7776 | 0 | s = bfd_make_section_anyway_with_flags (abfd, |
7777 | 0 | (bed->rela_plts_and_copies_p |
7778 | 0 | ? ".rela.got" : ".rel.got"), |
7779 | 0 | (bed->dynamic_sec_flags |
7780 | 0 | | SEC_READONLY)); |
7781 | 0 | if (s == NULL |
7782 | 0 | || !bfd_set_section_alignment (s, bed->s->log_file_align)) |
7783 | 0 | return false; |
7784 | 0 | htab->srelgot = s; |
7785 | |
|
7786 | 0 | s = bfd_make_section_anyway_with_flags (abfd, ".got", flags); |
7787 | 0 | if (s == NULL |
7788 | 0 | || !bfd_set_section_alignment (s, bed->s->log_file_align)) |
7789 | 0 | return false; |
7790 | 0 | htab->sgot = s; |
7791 | 0 | htab->sgot->size += GOT_ENTRY_SIZE; |
7792 | |
|
7793 | 0 | if (bed->want_got_sym) |
7794 | 0 | { |
7795 | | /* Define the symbol _GLOBAL_OFFSET_TABLE_ at the start of the .got |
7796 | | (or .got.plt) section. We don't do this in the linker script |
7797 | | because we don't want to define the symbol if we are not creating |
7798 | | a global offset table. */ |
7799 | 0 | h = _bfd_elf_define_linkage_sym (abfd, info, s, |
7800 | 0 | "_GLOBAL_OFFSET_TABLE_"); |
7801 | 0 | elf_hash_table (info)->hgot = h; |
7802 | 0 | if (h == NULL) |
7803 | 0 | return false; |
7804 | 0 | } |
7805 | | |
7806 | 0 | if (bed->want_got_plt) |
7807 | 0 | { |
7808 | 0 | s = bfd_make_section_anyway_with_flags (abfd, ".got.plt", flags); |
7809 | 0 | if (s == NULL |
7810 | 0 | || !bfd_set_section_alignment (s, bed->s->log_file_align)) |
7811 | 0 | return false; |
7812 | 0 | htab->sgotplt = s; |
7813 | 0 | } |
7814 | | |
7815 | | /* The first bit of the global offset table is the header. */ |
7816 | 0 | s->size += bed->got_header_size; |
7817 | |
|
7818 | 0 | return true; |
7819 | 0 | } |
7820 | | |
7821 | | /* Look through the relocs for a section during the first phase. */ |
7822 | | |
7823 | | static bool |
7824 | | elf64_aarch64_check_relocs (bfd *abfd, struct bfd_link_info *info, |
7825 | | asection *sec, const Elf_Internal_Rela *relocs) |
7826 | 0 | { |
7827 | 0 | Elf_Internal_Shdr *symtab_hdr; |
7828 | 0 | struct elf_link_hash_entry **sym_hashes; |
7829 | 0 | const Elf_Internal_Rela *rel; |
7830 | 0 | const Elf_Internal_Rela *rel_end; |
7831 | 0 | asection *sreloc; |
7832 | |
|
7833 | 0 | struct elf_aarch64_link_hash_table *htab; |
7834 | |
|
7835 | 0 | if (bfd_link_relocatable (info)) |
7836 | 0 | return true; |
7837 | | |
7838 | 0 | BFD_ASSERT (is_aarch64_elf (abfd)); |
7839 | |
|
7840 | 0 | htab = elf_aarch64_hash_table (info); |
7841 | 0 | sreloc = NULL; |
7842 | |
|
7843 | 0 | symtab_hdr = &elf_symtab_hdr (abfd); |
7844 | 0 | sym_hashes = elf_sym_hashes (abfd); |
7845 | |
|
7846 | 0 | rel_end = relocs + sec->reloc_count; |
7847 | 0 | for (rel = relocs; rel < rel_end; rel++) |
7848 | 0 | { |
7849 | 0 | struct elf_link_hash_entry *h; |
7850 | 0 | unsigned int r_symndx; |
7851 | 0 | unsigned int r_type; |
7852 | 0 | bfd_reloc_code_real_type bfd_r_type; |
7853 | 0 | Elf_Internal_Sym *isym; |
7854 | |
|
7855 | 0 | r_symndx = ELF64_R_SYM (rel->r_info); |
7856 | 0 | r_type = ELF64_R_TYPE (rel->r_info); |
7857 | |
|
7858 | 0 | if (r_symndx >= NUM_SHDR_ENTRIES (symtab_hdr)) |
7859 | 0 | { |
7860 | | /* xgettext:c-format */ |
7861 | 0 | _bfd_error_handler (_("%pB: bad symbol index: %d"), abfd, r_symndx); |
7862 | 0 | return false; |
7863 | 0 | } |
7864 | | |
7865 | 0 | if (r_symndx < symtab_hdr->sh_info) |
7866 | 0 | { |
7867 | | /* A local symbol. */ |
7868 | 0 | isym = bfd_sym_from_r_symndx (&htab->root.sym_cache, |
7869 | 0 | abfd, r_symndx); |
7870 | 0 | if (isym == NULL) |
7871 | 0 | return false; |
7872 | | |
7873 | | /* Check relocation against local STT_GNU_IFUNC symbol. */ |
7874 | 0 | if (ELF_ST_TYPE (isym->st_info) == STT_GNU_IFUNC) |
7875 | 0 | { |
7876 | 0 | h = elf64_aarch64_get_local_sym_hash (htab, abfd, rel, |
7877 | 0 | true); |
7878 | 0 | if (h == NULL) |
7879 | 0 | return false; |
7880 | | |
7881 | | /* Fake a STT_GNU_IFUNC symbol. */ |
7882 | 0 | h->type = STT_GNU_IFUNC; |
7883 | 0 | h->def_regular = 1; |
7884 | 0 | h->ref_regular = 1; |
7885 | 0 | h->forced_local = 1; |
7886 | 0 | h->root.type = bfd_link_hash_defined; |
7887 | 0 | } |
7888 | 0 | else |
7889 | 0 | h = NULL; |
7890 | 0 | } |
7891 | 0 | else |
7892 | 0 | { |
7893 | 0 | h = sym_hashes[r_symndx - symtab_hdr->sh_info]; |
7894 | 0 | while (h->root.type == bfd_link_hash_indirect |
7895 | 0 | || h->root.type == bfd_link_hash_warning) |
7896 | 0 | h = (struct elf_link_hash_entry *) h->root.u.i.link; |
7897 | 0 | } |
7898 | | |
7899 | | /* Could be done earlier, if h were already available. */ |
7900 | 0 | bfd_r_type = aarch64_tls_transition (abfd, info, r_type, h, r_symndx); |
7901 | |
|
7902 | 0 | if (h != NULL) |
7903 | 0 | { |
7904 | | /* If a relocation refers to _GLOBAL_OFFSET_TABLE_, create the .got. |
7905 | | This shows up in particular in an R_AARCH64_PREL64 in large model |
7906 | | when calculating the pc-relative address to .got section which is |
7907 | | used to initialize the gp register. */ |
7908 | 0 | if (h->root.root.string |
7909 | 0 | && strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0) |
7910 | 0 | { |
7911 | 0 | if (htab->root.dynobj == NULL) |
7912 | 0 | htab->root.dynobj = abfd; |
7913 | |
|
7914 | 0 | if (! aarch64_elf_create_got_section (htab->root.dynobj, info)) |
7915 | 0 | return false; |
7916 | | |
7917 | 0 | BFD_ASSERT (h == htab->root.hgot); |
7918 | 0 | } |
7919 | | |
7920 | | /* Create the ifunc sections for static executables. If we |
7921 | | never see an indirect function symbol nor we are building |
7922 | | a static executable, those sections will be empty and |
7923 | | won't appear in output. */ |
7924 | 0 | switch (bfd_r_type) |
7925 | 0 | { |
7926 | 0 | default: |
7927 | 0 | break; |
7928 | | |
7929 | 0 | case BFD_RELOC_AARCH64_ADD_LO12: |
7930 | 0 | case BFD_RELOC_AARCH64_ADR_GOT_PAGE: |
7931 | 0 | case BFD_RELOC_AARCH64_ADR_HI21_PCREL: |
7932 | 0 | case BFD_RELOC_AARCH64_CALL26: |
7933 | 0 | case BFD_RELOC_AARCH64_GOT_LD_PREL19: |
7934 | 0 | case BFD_RELOC_AARCH64_JUMP26: |
7935 | 0 | case BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14: |
7936 | 0 | case BFD_RELOC_AARCH64_LD32_GOT_LO12_NC: |
7937 | 0 | case BFD_RELOC_AARCH64_LD64_GOTOFF_LO15: |
7938 | 0 | case BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15: |
7939 | 0 | case BFD_RELOC_AARCH64_LD64_GOT_LO12_NC: |
7940 | 0 | case BFD_RELOC_AARCH64_MOVW_GOTOFF_G0_NC: |
7941 | 0 | case BFD_RELOC_AARCH64_MOVW_GOTOFF_G1: |
7942 | 0 | case BFD_RELOC_AARCH64_64: |
7943 | 0 | if (htab->root.dynobj == NULL) |
7944 | 0 | htab->root.dynobj = abfd; |
7945 | 0 | if (!_bfd_elf_create_ifunc_sections (htab->root.dynobj, info)) |
7946 | 0 | return false; |
7947 | 0 | break; |
7948 | 0 | } |
7949 | | |
7950 | | /* It is referenced by a non-shared object. */ |
7951 | 0 | h->ref_regular = 1; |
7952 | 0 | } |
7953 | | |
7954 | 0 | switch (bfd_r_type) |
7955 | 0 | { |
7956 | 0 | case BFD_RELOC_AARCH64_16: |
7957 | 0 | #if ARCH_SIZE == 64 |
7958 | 0 | case BFD_RELOC_AARCH64_32: |
7959 | 0 | #endif |
7960 | 0 | if (bfd_link_pic (info) && (sec->flags & SEC_ALLOC) != 0) |
7961 | 0 | { |
7962 | 0 | if (h != NULL |
7963 | | /* This is an absolute symbol. It represents a value instead |
7964 | | of an address. */ |
7965 | 0 | && (bfd_is_abs_symbol (&h->root) |
7966 | | /* This is an undefined symbol. */ |
7967 | 0 | || h->root.type == bfd_link_hash_undefined)) |
7968 | 0 | break; |
7969 | | |
7970 | | /* For local symbols, defined global symbols in a non-ABS section, |
7971 | | it is assumed that the value is an address. */ |
7972 | 0 | int howto_index = bfd_r_type - BFD_RELOC_AARCH64_RELOC_START; |
7973 | 0 | _bfd_error_handler |
7974 | | /* xgettext:c-format */ |
7975 | 0 | (_("%pB: relocation %s against `%s' can not be used when making " |
7976 | 0 | "a shared object"), |
7977 | 0 | abfd, elf64_aarch64_howto_table[howto_index].name, |
7978 | 0 | (h) ? h->root.root.string : "a local symbol"); |
7979 | 0 | bfd_set_error (bfd_error_bad_value); |
7980 | 0 | return false; |
7981 | 0 | } |
7982 | 0 | else |
7983 | 0 | break; |
7984 | | |
7985 | 0 | case BFD_RELOC_AARCH64_MOVW_G0_NC: |
7986 | 0 | case BFD_RELOC_AARCH64_MOVW_G1_NC: |
7987 | 0 | case BFD_RELOC_AARCH64_MOVW_G2_NC: |
7988 | 0 | case BFD_RELOC_AARCH64_MOVW_G3: |
7989 | 0 | if (bfd_link_pic (info)) |
7990 | 0 | { |
7991 | 0 | int howto_index = bfd_r_type - BFD_RELOC_AARCH64_RELOC_START; |
7992 | 0 | _bfd_error_handler |
7993 | | /* xgettext:c-format */ |
7994 | 0 | (_("%pB: relocation %s against `%s' can not be used when making " |
7995 | 0 | "a shared object; recompile with -fPIC"), |
7996 | 0 | abfd, elf64_aarch64_howto_table[howto_index].name, |
7997 | 0 | (h) ? h->root.root.string : "a local symbol"); |
7998 | 0 | bfd_set_error (bfd_error_bad_value); |
7999 | 0 | return false; |
8000 | 0 | } |
8001 | | /* Fall through. */ |
8002 | | |
8003 | 0 | case BFD_RELOC_AARCH64_16_PCREL: |
8004 | 0 | case BFD_RELOC_AARCH64_32_PCREL: |
8005 | 0 | case BFD_RELOC_AARCH64_64_PCREL: |
8006 | 0 | case BFD_RELOC_AARCH64_ADD_LO12: |
8007 | 0 | case BFD_RELOC_AARCH64_ADR_HI21_NC_PCREL: |
8008 | 0 | case BFD_RELOC_AARCH64_ADR_HI21_PCREL: |
8009 | 0 | case BFD_RELOC_AARCH64_ADR_LO21_PCREL: |
8010 | 0 | case BFD_RELOC_AARCH64_LDST128_LO12: |
8011 | 0 | case BFD_RELOC_AARCH64_LDST16_LO12: |
8012 | 0 | case BFD_RELOC_AARCH64_LDST32_LO12: |
8013 | 0 | case BFD_RELOC_AARCH64_LDST64_LO12: |
8014 | 0 | case BFD_RELOC_AARCH64_LDST8_LO12: |
8015 | 0 | case BFD_RELOC_AARCH64_LD_LO19_PCREL: |
8016 | 0 | if (h == NULL || bfd_link_pic (info)) |
8017 | 0 | break; |
8018 | | /* Fall through. */ |
8019 | | |
8020 | 0 | case BFD_RELOC_AARCH64_64: |
8021 | | |
8022 | | /* We don't need to handle relocs into sections not going into |
8023 | | the "real" output. */ |
8024 | 0 | if ((sec->flags & SEC_ALLOC) == 0) |
8025 | 0 | break; |
8026 | | |
8027 | 0 | if (h != NULL) |
8028 | 0 | { |
8029 | 0 | if (!bfd_link_pic (info)) |
8030 | 0 | h->non_got_ref = 1; |
8031 | |
|
8032 | 0 | h->plt.refcount += 1; |
8033 | 0 | h->pointer_equality_needed = 1; |
8034 | 0 | } |
8035 | | |
8036 | | /* No need to do anything if we're not creating a shared |
8037 | | object. */ |
8038 | 0 | if (!(bfd_link_pic (info) |
8039 | | /* If on the other hand, we are creating an executable, we |
8040 | | may need to keep relocations for symbols satisfied by a |
8041 | | dynamic library if we manage to avoid copy relocs for the |
8042 | | symbol. |
8043 | | |
8044 | | NOTE: Currently, there is no support of copy relocs |
8045 | | elimination on pc-relative relocation types, because there is |
8046 | | no dynamic relocation support for them in glibc. We still |
8047 | | record the dynamic symbol reference for them. This is |
8048 | | because one symbol may be referenced by both absolute |
8049 | | relocation (for example, BFD_RELOC_AARCH64_64) and |
8050 | | pc-relative relocation. We need full symbol reference |
8051 | | information to make correct decision later in |
8052 | | elf64_aarch64_adjust_dynamic_symbol. */ |
8053 | 0 | || (ELIMINATE_COPY_RELOCS |
8054 | 0 | && !bfd_link_pic (info) |
8055 | 0 | && h != NULL |
8056 | 0 | && (h->root.type == bfd_link_hash_defweak |
8057 | 0 | || !h->def_regular)))) |
8058 | 0 | break; |
8059 | | |
8060 | 0 | { |
8061 | 0 | struct elf_dyn_relocs *p; |
8062 | 0 | struct elf_dyn_relocs **head; |
8063 | 0 | int howto_index = bfd_r_type - BFD_RELOC_AARCH64_RELOC_START; |
8064 | | |
8065 | | /* We must copy these reloc types into the output file. |
8066 | | Create a reloc section in dynobj and make room for |
8067 | | this reloc. */ |
8068 | 0 | if (sreloc == NULL) |
8069 | 0 | { |
8070 | 0 | if (htab->root.dynobj == NULL) |
8071 | 0 | htab->root.dynobj = abfd; |
8072 | |
|
8073 | 0 | sreloc = _bfd_elf_make_dynamic_reloc_section |
8074 | 0 | (sec, htab->root.dynobj, LOG_FILE_ALIGN, abfd, /*rela? */ true); |
8075 | |
|
8076 | 0 | if (sreloc == NULL) |
8077 | 0 | return false; |
8078 | 0 | } |
8079 | | |
8080 | | /* If this is a global symbol, we count the number of |
8081 | | relocations we need for this symbol. */ |
8082 | 0 | if (h != NULL) |
8083 | 0 | { |
8084 | 0 | head = &h->dyn_relocs; |
8085 | 0 | } |
8086 | 0 | else |
8087 | 0 | { |
8088 | | /* Track dynamic relocs needed for local syms too. |
8089 | | We really need local syms available to do this |
8090 | | easily. Oh well. */ |
8091 | |
|
8092 | 0 | asection *s; |
8093 | 0 | void **vpp; |
8094 | |
|
8095 | 0 | isym = bfd_sym_from_r_symndx (&htab->root.sym_cache, |
8096 | 0 | abfd, r_symndx); |
8097 | 0 | if (isym == NULL) |
8098 | 0 | return false; |
8099 | | |
8100 | 0 | s = bfd_section_from_elf_index (abfd, isym->st_shndx); |
8101 | 0 | if (s == NULL) |
8102 | 0 | s = sec; |
8103 | | |
8104 | | /* Beware of type punned pointers vs strict aliasing |
8105 | | rules. */ |
8106 | 0 | vpp = &(elf_section_data (s)->local_dynrel); |
8107 | 0 | head = (struct elf_dyn_relocs **) vpp; |
8108 | 0 | } |
8109 | | |
8110 | 0 | p = *head; |
8111 | 0 | if (p == NULL || p->sec != sec) |
8112 | 0 | { |
8113 | 0 | size_t amt = sizeof *p; |
8114 | 0 | p = ((struct elf_dyn_relocs *) |
8115 | 0 | bfd_zalloc (htab->root.dynobj, amt)); |
8116 | 0 | if (p == NULL) |
8117 | 0 | return false; |
8118 | 0 | p->next = *head; |
8119 | 0 | *head = p; |
8120 | 0 | p->sec = sec; |
8121 | 0 | } |
8122 | | |
8123 | 0 | p->count += 1; |
8124 | |
|
8125 | 0 | if (elf64_aarch64_howto_table[howto_index].pc_relative) |
8126 | 0 | p->pc_count += 1; |
8127 | 0 | } |
8128 | 0 | break; |
8129 | | |
8130 | | /* RR: We probably want to keep a consistency check that |
8131 | | there are no dangling GOT_PAGE relocs. */ |
8132 | 0 | case BFD_RELOC_AARCH64_ADR_GOT_PAGE: |
8133 | 0 | case BFD_RELOC_AARCH64_GOT_LD_PREL19: |
8134 | 0 | case BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14: |
8135 | 0 | case BFD_RELOC_AARCH64_LD32_GOT_LO12_NC: |
8136 | 0 | case BFD_RELOC_AARCH64_LD64_GOTOFF_LO15: |
8137 | 0 | case BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15: |
8138 | 0 | case BFD_RELOC_AARCH64_LD64_GOT_LO12_NC: |
8139 | 0 | case BFD_RELOC_AARCH64_MOVW_GOTOFF_G0_NC: |
8140 | 0 | case BFD_RELOC_AARCH64_MOVW_GOTOFF_G1: |
8141 | 0 | case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12: |
8142 | 0 | case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21: |
8143 | 0 | case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21: |
8144 | 0 | case BFD_RELOC_AARCH64_TLSDESC_LD32_LO12_NC: |
8145 | 0 | case BFD_RELOC_AARCH64_TLSDESC_LD64_LO12: |
8146 | 0 | case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19: |
8147 | 0 | case BFD_RELOC_AARCH64_TLSDESC_OFF_G0_NC: |
8148 | 0 | case BFD_RELOC_AARCH64_TLSDESC_OFF_G1: |
8149 | 0 | case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC: |
8150 | 0 | case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21: |
8151 | 0 | case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21: |
8152 | 0 | case BFD_RELOC_AARCH64_TLSGD_MOVW_G0_NC: |
8153 | 0 | case BFD_RELOC_AARCH64_TLSGD_MOVW_G1: |
8154 | 0 | case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21: |
8155 | 0 | case BFD_RELOC_AARCH64_TLSIE_LD32_GOTTPREL_LO12_NC: |
8156 | 0 | case BFD_RELOC_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC: |
8157 | 0 | case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19: |
8158 | 0 | case BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G0_NC: |
8159 | 0 | case BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G1: |
8160 | 0 | case BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC: |
8161 | 0 | case BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21: |
8162 | 0 | case BFD_RELOC_AARCH64_TLSLD_ADR_PREL21: |
8163 | 0 | { |
8164 | 0 | unsigned got_type; |
8165 | 0 | unsigned old_got_type; |
8166 | |
|
8167 | 0 | got_type = aarch64_reloc_got_type (bfd_r_type); |
8168 | |
|
8169 | 0 | if (h) |
8170 | 0 | { |
8171 | 0 | h->got.refcount += 1; |
8172 | 0 | old_got_type = elf_aarch64_hash_entry (h)->got_type; |
8173 | 0 | } |
8174 | 0 | else |
8175 | 0 | { |
8176 | 0 | struct elf_aarch64_local_symbol *locals; |
8177 | |
|
8178 | 0 | if (!elf64_aarch64_allocate_local_symbols |
8179 | 0 | (abfd, symtab_hdr->sh_info)) |
8180 | 0 | return false; |
8181 | | |
8182 | 0 | locals = elf_aarch64_locals (abfd); |
8183 | 0 | BFD_ASSERT (r_symndx < symtab_hdr->sh_info); |
8184 | 0 | locals[r_symndx].got_refcount += 1; |
8185 | 0 | old_got_type = locals[r_symndx].got_type; |
8186 | 0 | } |
8187 | | |
8188 | | /* If a variable is accessed with both general dynamic TLS |
8189 | | methods, two slots may be created. */ |
8190 | 0 | if (GOT_TLS_GD_ANY_P (old_got_type) && GOT_TLS_GD_ANY_P (got_type)) |
8191 | 0 | got_type |= old_got_type; |
8192 | | |
8193 | | /* We will already have issued an error message if there |
8194 | | is a TLS/non-TLS mismatch, based on the symbol type. |
8195 | | So just combine any TLS types needed. */ |
8196 | 0 | if (old_got_type != GOT_UNKNOWN && old_got_type != GOT_NORMAL |
8197 | 0 | && got_type != GOT_NORMAL) |
8198 | 0 | got_type |= old_got_type; |
8199 | | |
8200 | | /* If the symbol is accessed by both IE and GD methods, we |
8201 | | are able to relax. Turn off the GD flag, without |
8202 | | messing up with any other kind of TLS types that may be |
8203 | | involved. */ |
8204 | 0 | if ((got_type & GOT_TLS_IE) && GOT_TLS_GD_ANY_P (got_type)) |
8205 | 0 | got_type &= ~ (GOT_TLSDESC_GD | GOT_TLS_GD); |
8206 | |
|
8207 | 0 | if (old_got_type != got_type) |
8208 | 0 | { |
8209 | 0 | if (h != NULL) |
8210 | 0 | elf_aarch64_hash_entry (h)->got_type = got_type; |
8211 | 0 | else |
8212 | 0 | { |
8213 | 0 | struct elf_aarch64_local_symbol *locals; |
8214 | 0 | locals = elf_aarch64_locals (abfd); |
8215 | 0 | BFD_ASSERT (r_symndx < symtab_hdr->sh_info); |
8216 | 0 | locals[r_symndx].got_type = got_type; |
8217 | 0 | } |
8218 | 0 | } |
8219 | |
|
8220 | 0 | if (htab->root.dynobj == NULL) |
8221 | 0 | htab->root.dynobj = abfd; |
8222 | 0 | if (! aarch64_elf_create_got_section (htab->root.dynobj, info)) |
8223 | 0 | return false; |
8224 | 0 | break; |
8225 | 0 | } |
8226 | | |
8227 | 0 | case BFD_RELOC_AARCH64_CALL26: |
8228 | 0 | case BFD_RELOC_AARCH64_JUMP26: |
8229 | | /* If this is a local symbol then we resolve it |
8230 | | directly without creating a PLT entry. */ |
8231 | 0 | if (h == NULL) |
8232 | 0 | continue; |
8233 | | |
8234 | 0 | h->needs_plt = 1; |
8235 | 0 | if (h->plt.refcount <= 0) |
8236 | 0 | h->plt.refcount = 1; |
8237 | 0 | else |
8238 | 0 | h->plt.refcount += 1; |
8239 | 0 | break; |
8240 | | |
8241 | 0 | default: |
8242 | 0 | break; |
8243 | 0 | } |
8244 | 0 | } |
8245 | | |
8246 | 0 | return true; |
8247 | 0 | } |
8248 | | |
8249 | | /* Treat mapping symbols as special target symbols. */ |
8250 | | |
8251 | | static bool |
8252 | | elf64_aarch64_is_target_special_symbol (bfd *abfd ATTRIBUTE_UNUSED, |
8253 | | asymbol *sym) |
8254 | 0 | { |
8255 | 0 | return bfd_is_aarch64_special_symbol_name (sym->name, |
8256 | 0 | BFD_AARCH64_SPECIAL_SYM_TYPE_ANY); |
8257 | 0 | } |
8258 | | |
8259 | | /* If the ELF symbol SYM might be a function in SEC, return the |
8260 | | function size and set *CODE_OFF to the function's entry point, |
8261 | | otherwise return zero. */ |
8262 | | |
8263 | | static bfd_size_type |
8264 | | elf64_aarch64_maybe_function_sym (const asymbol *sym, asection *sec, |
8265 | | bfd_vma *code_off) |
8266 | 2.23k | { |
8267 | 2.23k | bfd_size_type size; |
8268 | 2.23k | elf_symbol_type * elf_sym = (elf_symbol_type *) sym; |
8269 | | |
8270 | 2.23k | if ((sym->flags & (BSF_SECTION_SYM | BSF_FILE | BSF_OBJECT |
8271 | 2.23k | | BSF_THREAD_LOCAL | BSF_RELC | BSF_SRELC)) != 0 |
8272 | 2.23k | || sym->section != sec) |
8273 | 2.11k | return 0; |
8274 | | |
8275 | 126 | size = (sym->flags & BSF_SYNTHETIC) ? 0 : elf_sym->internal_elf_sym.st_size; |
8276 | | |
8277 | 126 | if (!(sym->flags & BSF_SYNTHETIC)) |
8278 | 126 | switch (ELF_ST_TYPE (elf_sym->internal_elf_sym.st_info)) |
8279 | 126 | { |
8280 | 67 | case STT_NOTYPE: |
8281 | | /* Ignore symbols created by the annobin plugin for gcc and clang. |
8282 | | These symbols are hidden, local, notype and have a size of 0. */ |
8283 | 67 | if (size == 0 |
8284 | 67 | && sym->flags & BSF_LOCAL |
8285 | 67 | && ELF_ST_VISIBILITY (elf_sym->internal_elf_sym.st_other) == STV_HIDDEN) |
8286 | 0 | return 0; |
8287 | | /* Fall through. */ |
8288 | 96 | case STT_FUNC: |
8289 | | /* FIXME: Allow STT_GNU_IFUNC as well ? */ |
8290 | 96 | break; |
8291 | 30 | default: |
8292 | 30 | return 0; |
8293 | 126 | } |
8294 | | |
8295 | 96 | if ((sym->flags & BSF_LOCAL) |
8296 | 96 | && bfd_is_aarch64_special_symbol_name (sym->name, |
8297 | 73 | BFD_AARCH64_SPECIAL_SYM_TYPE_ANY)) |
8298 | 0 | return 0; |
8299 | | |
8300 | 96 | *code_off = sym->value; |
8301 | | |
8302 | | /* Do not return 0 for the function's size. */ |
8303 | 96 | return size ? size : 1; |
8304 | 96 | } |
8305 | | |
8306 | | static bool |
8307 | | elf64_aarch64_find_inliner_info (bfd *abfd, |
8308 | | const char **filename_ptr, |
8309 | | const char **functionname_ptr, |
8310 | | unsigned int *line_ptr) |
8311 | 0 | { |
8312 | 0 | bool found; |
8313 | 0 | found = _bfd_dwarf2_find_inliner_info |
8314 | 0 | (abfd, filename_ptr, |
8315 | 0 | functionname_ptr, line_ptr, &elf_tdata (abfd)->dwarf2_find_line_info); |
8316 | 0 | return found; |
8317 | 0 | } |
8318 | | |
8319 | | |
8320 | | static bool |
8321 | | elf64_aarch64_init_file_header (bfd *abfd, struct bfd_link_info *link_info) |
8322 | 1 | { |
8323 | 1 | Elf_Internal_Ehdr *i_ehdrp; /* ELF file header, internal form. */ |
8324 | | |
8325 | 1 | if (!_bfd_elf_init_file_header (abfd, link_info)) |
8326 | 0 | return false; |
8327 | | |
8328 | 1 | i_ehdrp = elf_elfheader (abfd); |
8329 | 1 | i_ehdrp->e_ident[EI_ABIVERSION] = AARCH64_ELF_ABI_VERSION; |
8330 | 1 | return true; |
8331 | 1 | } |
8332 | | |
8333 | | static enum elf_reloc_type_class |
8334 | | elf64_aarch64_reloc_type_class (const struct bfd_link_info *info ATTRIBUTE_UNUSED, |
8335 | | const asection *rel_sec ATTRIBUTE_UNUSED, |
8336 | | const Elf_Internal_Rela *rela) |
8337 | 0 | { |
8338 | 0 | struct elf_aarch64_link_hash_table *htab = elf_aarch64_hash_table (info); |
8339 | |
|
8340 | 0 | if (htab->root.dynsym != NULL |
8341 | 0 | && htab->root.dynsym->contents != NULL) |
8342 | 0 | { |
8343 | | /* Check relocation against STT_GNU_IFUNC symbol if there are |
8344 | | dynamic symbols. */ |
8345 | 0 | bfd *abfd = info->output_bfd; |
8346 | 0 | const struct elf_backend_data *bed = get_elf_backend_data (abfd); |
8347 | 0 | unsigned long r_symndx = ELF64_R_SYM (rela->r_info); |
8348 | 0 | if (r_symndx != STN_UNDEF) |
8349 | 0 | { |
8350 | 0 | Elf_Internal_Sym sym; |
8351 | 0 | if (!bed->s->swap_symbol_in (abfd, |
8352 | 0 | (htab->root.dynsym->contents |
8353 | 0 | + r_symndx * bed->s->sizeof_sym), |
8354 | 0 | 0, &sym)) |
8355 | 0 | { |
8356 | | /* xgettext:c-format */ |
8357 | 0 | _bfd_error_handler (_("%pB symbol number %lu references" |
8358 | 0 | " nonexistent SHT_SYMTAB_SHNDX section"), |
8359 | 0 | abfd, r_symndx); |
8360 | | /* Ideally an error class should be returned here. */ |
8361 | 0 | } |
8362 | 0 | else if (ELF_ST_TYPE (sym.st_info) == STT_GNU_IFUNC) |
8363 | 0 | return reloc_class_ifunc; |
8364 | 0 | } |
8365 | 0 | } |
8366 | | |
8367 | 0 | switch ((int) ELF64_R_TYPE (rela->r_info)) |
8368 | 0 | { |
8369 | 0 | case AARCH64_R (IRELATIVE): |
8370 | 0 | return reloc_class_ifunc; |
8371 | 0 | case AARCH64_R (RELATIVE): |
8372 | 0 | return reloc_class_relative; |
8373 | 0 | case AARCH64_R (JUMP_SLOT): |
8374 | 0 | return reloc_class_plt; |
8375 | 0 | case AARCH64_R (COPY): |
8376 | 0 | return reloc_class_copy; |
8377 | 0 | default: |
8378 | 0 | return reloc_class_normal; |
8379 | 0 | } |
8380 | 0 | } |
8381 | | |
8382 | | /* Handle an AArch64 specific section when reading an object file. This is |
8383 | | called when bfd_section_from_shdr finds a section with an unknown |
8384 | | type. */ |
8385 | | |
8386 | | static bool |
8387 | | elf64_aarch64_section_from_shdr (bfd *abfd, |
8388 | | Elf_Internal_Shdr *hdr, |
8389 | | const char *name, int shindex) |
8390 | 6.53k | { |
8391 | | /* There ought to be a place to keep ELF backend specific flags, but |
8392 | | at the moment there isn't one. We just keep track of the |
8393 | | sections by their name, instead. Fortunately, the ABI gives |
8394 | | names for all the AArch64 specific sections, so we will probably get |
8395 | | away with this. */ |
8396 | 6.53k | switch (hdr->sh_type) |
8397 | 6.53k | { |
8398 | 0 | case SHT_AARCH64_ATTRIBUTES: |
8399 | 0 | break; |
8400 | | |
8401 | 6.53k | default: |
8402 | 6.53k | return false; |
8403 | 6.53k | } |
8404 | | |
8405 | 0 | if (!_bfd_elf_make_section_from_shdr (abfd, hdr, name, shindex)) |
8406 | 0 | return false; |
8407 | | |
8408 | 0 | return true; |
8409 | 0 | } |
8410 | | |
8411 | | /* Process any AArch64-specific program segment types. */ |
8412 | | |
8413 | | static bool |
8414 | | elf64_aarch64_section_from_phdr (bfd *abfd ATTRIBUTE_UNUSED, |
8415 | | Elf_Internal_Phdr *hdr, |
8416 | | int hdr_index ATTRIBUTE_UNUSED, |
8417 | | const char *name ATTRIBUTE_UNUSED) |
8418 | 17 | { |
8419 | | /* Right now we only handle the PT_AARCH64_MEMTAG_MTE segment type. */ |
8420 | 17 | if (hdr == NULL || hdr->p_type != PT_AARCH64_MEMTAG_MTE) |
8421 | 17 | return false; |
8422 | | |
8423 | 0 | if (hdr->p_filesz > 0) |
8424 | 0 | { |
8425 | | /* Sections created from memory tag p_type's are always named |
8426 | | "memtag". This makes it easier for tools (for example, GDB) |
8427 | | to find them. */ |
8428 | 0 | asection *newsect = bfd_make_section_anyway (abfd, "memtag"); |
8429 | |
|
8430 | 0 | if (newsect == NULL) |
8431 | 0 | return false; |
8432 | | |
8433 | 0 | unsigned int opb = bfd_octets_per_byte (abfd, NULL); |
8434 | | |
8435 | | /* p_vaddr holds the original start address of the tagged memory |
8436 | | range. */ |
8437 | 0 | newsect->vma = hdr->p_vaddr / opb; |
8438 | | |
8439 | | /* p_filesz holds the storage size of the packed tags. */ |
8440 | 0 | newsect->size = hdr->p_filesz; |
8441 | 0 | newsect->filepos = hdr->p_offset; |
8442 | | |
8443 | | /* p_memsz holds the size of the memory range that contains tags. The |
8444 | | section's rawsize field is reused for this purpose. */ |
8445 | 0 | newsect->rawsize = hdr->p_memsz; |
8446 | | |
8447 | | /* Make sure the section's flags has SEC_HAS_CONTENTS set, otherwise |
8448 | | BFD will return all zeroes when attempting to get contents from this |
8449 | | section. */ |
8450 | 0 | newsect->flags |= SEC_HAS_CONTENTS; |
8451 | 0 | } |
8452 | | |
8453 | 0 | return true; |
8454 | 0 | } |
8455 | | |
8456 | | /* Implements the bfd_elf_modify_headers hook for aarch64. */ |
8457 | | |
8458 | | static bool |
8459 | | elf64_aarch64_modify_headers (bfd *abfd, |
8460 | | struct bfd_link_info *info) |
8461 | 1 | { |
8462 | 1 | struct elf_segment_map *m; |
8463 | 1 | unsigned int segment_count = 0; |
8464 | 1 | Elf_Internal_Phdr *p; |
8465 | | |
8466 | 8 | for (m = elf_seg_map (abfd); m != NULL; m = m->next, segment_count++) |
8467 | 7 | { |
8468 | | /* We are only interested in the memory tag segment that will be dumped |
8469 | | to a core file. If we have no memory tags or this isn't a core file we |
8470 | | are dealing with, just skip this segment. */ |
8471 | 7 | if (m->p_type != PT_AARCH64_MEMTAG_MTE |
8472 | 7 | || bfd_get_format (abfd) != bfd_core) |
8473 | 7 | continue; |
8474 | | |
8475 | | /* For memory tag segments in core files, the size of the file contents |
8476 | | is smaller than the size of the memory range. Adjust the memory size |
8477 | | accordingly. The real memory size is held in the section's rawsize |
8478 | | field. */ |
8479 | 0 | if (m->count > 0) |
8480 | 0 | { |
8481 | 0 | p = elf_tdata (abfd)->phdr; |
8482 | 0 | p += m->idx; |
8483 | 0 | p->p_memsz = m->sections[0]->rawsize; |
8484 | 0 | p->p_flags = 0; |
8485 | 0 | p->p_paddr = 0; |
8486 | 0 | p->p_align = 0; |
8487 | 0 | } |
8488 | 0 | } |
8489 | | |
8490 | | /* Give the generic code a chance to handle the headers. */ |
8491 | 1 | return _bfd_elf_modify_headers (abfd, info); |
8492 | 1 | } |
8493 | | |
8494 | | |
8495 | | typedef struct |
8496 | | { |
8497 | | void *finfo; |
8498 | | struct bfd_link_info *info; |
8499 | | asection *sec; |
8500 | | int sec_shndx; |
8501 | | int (*func) (void *, const char *, Elf_Internal_Sym *, |
8502 | | asection *, struct elf_link_hash_entry *); |
8503 | | } output_arch_syminfo; |
8504 | | |
8505 | | enum map_symbol_type |
8506 | | { |
8507 | | AARCH64_MAP_INSN, |
8508 | | AARCH64_MAP_DATA |
8509 | | }; |
8510 | | |
8511 | | |
8512 | | /* Output a single mapping symbol. */ |
8513 | | |
8514 | | static bool |
8515 | | elf64_aarch64_output_map_sym (output_arch_syminfo *osi, |
8516 | | enum map_symbol_type type, bfd_vma offset) |
8517 | 0 | { |
8518 | 0 | static const char *names[2] = { "$x", "$d" }; |
8519 | 0 | Elf_Internal_Sym sym; |
8520 | |
|
8521 | 0 | sym.st_value = (osi->sec->output_section->vma |
8522 | 0 | + osi->sec->output_offset + offset); |
8523 | 0 | sym.st_size = 0; |
8524 | 0 | sym.st_other = 0; |
8525 | 0 | sym.st_info = ELF_ST_INFO (STB_LOCAL, STT_NOTYPE); |
8526 | 0 | sym.st_shndx = osi->sec_shndx; |
8527 | 0 | return osi->func (osi->finfo, names[type], &sym, osi->sec, NULL) == 1; |
8528 | 0 | } |
8529 | | |
8530 | | /* Output a single local symbol for a generated stub. */ |
8531 | | |
8532 | | static bool |
8533 | | elf64_aarch64_output_stub_sym (output_arch_syminfo *osi, const char *name, |
8534 | | bfd_vma offset, bfd_vma size) |
8535 | 0 | { |
8536 | 0 | Elf_Internal_Sym sym; |
8537 | |
|
8538 | 0 | sym.st_value = (osi->sec->output_section->vma |
8539 | 0 | + osi->sec->output_offset + offset); |
8540 | 0 | sym.st_size = size; |
8541 | 0 | sym.st_other = 0; |
8542 | 0 | sym.st_info = ELF_ST_INFO (STB_LOCAL, STT_FUNC); |
8543 | 0 | sym.st_shndx = osi->sec_shndx; |
8544 | 0 | return osi->func (osi->finfo, name, &sym, osi->sec, NULL) == 1; |
8545 | 0 | } |
8546 | | |
8547 | | static bool |
8548 | | aarch64_map_one_stub (struct bfd_hash_entry *gen_entry, void *in_arg) |
8549 | 0 | { |
8550 | 0 | struct elf_aarch64_stub_hash_entry *stub_entry; |
8551 | 0 | asection *stub_sec; |
8552 | 0 | bfd_vma addr; |
8553 | 0 | char *stub_name; |
8554 | 0 | output_arch_syminfo *osi; |
8555 | | |
8556 | | /* Massage our args to the form they really have. */ |
8557 | 0 | stub_entry = (struct elf_aarch64_stub_hash_entry *) gen_entry; |
8558 | 0 | osi = (output_arch_syminfo *) in_arg; |
8559 | |
|
8560 | 0 | stub_sec = stub_entry->stub_sec; |
8561 | | |
8562 | | /* Ensure this stub is attached to the current section being |
8563 | | processed. */ |
8564 | 0 | if (stub_sec != osi->sec) |
8565 | 0 | return true; |
8566 | | |
8567 | 0 | addr = (bfd_vma) stub_entry->stub_offset; |
8568 | |
|
8569 | 0 | stub_name = stub_entry->output_name; |
8570 | |
|
8571 | 0 | switch (stub_entry->stub_type) |
8572 | 0 | { |
8573 | 0 | case aarch64_stub_adrp_branch: |
8574 | 0 | if (!elf64_aarch64_output_stub_sym (osi, stub_name, addr, |
8575 | 0 | sizeof (aarch64_adrp_branch_stub))) |
8576 | 0 | return false; |
8577 | 0 | if (!elf64_aarch64_output_map_sym (osi, AARCH64_MAP_INSN, addr)) |
8578 | 0 | return false; |
8579 | 0 | break; |
8580 | 0 | case aarch64_stub_long_branch: |
8581 | 0 | if (!elf64_aarch64_output_stub_sym |
8582 | 0 | (osi, stub_name, addr, sizeof (aarch64_long_branch_stub))) |
8583 | 0 | return false; |
8584 | 0 | if (!elf64_aarch64_output_map_sym (osi, AARCH64_MAP_INSN, addr)) |
8585 | 0 | return false; |
8586 | 0 | if (!elf64_aarch64_output_map_sym (osi, AARCH64_MAP_DATA, addr + 16)) |
8587 | 0 | return false; |
8588 | 0 | break; |
8589 | 0 | case aarch64_stub_bti_direct_branch: |
8590 | 0 | if (!elf64_aarch64_output_stub_sym (osi, stub_name, addr, |
8591 | 0 | sizeof (aarch64_bti_direct_branch_stub))) |
8592 | 0 | return false; |
8593 | 0 | if (!elf64_aarch64_output_map_sym (osi, AARCH64_MAP_INSN, addr)) |
8594 | 0 | return false; |
8595 | 0 | break; |
8596 | 0 | case aarch64_stub_erratum_835769_veneer: |
8597 | 0 | if (!elf64_aarch64_output_stub_sym (osi, stub_name, addr, |
8598 | 0 | sizeof (aarch64_erratum_835769_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_erratum_843419_veneer: |
8604 | 0 | if (!elf64_aarch64_output_stub_sym (osi, stub_name, addr, |
8605 | 0 | sizeof (aarch64_erratum_843419_stub))) |
8606 | 0 | return false; |
8607 | 0 | if (!elf64_aarch64_output_map_sym (osi, AARCH64_MAP_INSN, addr)) |
8608 | 0 | return false; |
8609 | 0 | break; |
8610 | 0 | case aarch64_stub_none: |
8611 | 0 | break; |
8612 | | |
8613 | 0 | default: |
8614 | 0 | abort (); |
8615 | 0 | } |
8616 | | |
8617 | 0 | return true; |
8618 | 0 | } |
8619 | | |
8620 | | /* Output mapping symbols for linker generated sections. */ |
8621 | | |
8622 | | static bool |
8623 | | elf64_aarch64_output_arch_local_syms (bfd *output_bfd, |
8624 | | struct bfd_link_info *info, |
8625 | | void *finfo, |
8626 | | int (*func) (void *, const char *, |
8627 | | Elf_Internal_Sym *, |
8628 | | asection *, |
8629 | | struct elf_link_hash_entry |
8630 | | *)) |
8631 | 0 | { |
8632 | 0 | output_arch_syminfo osi; |
8633 | 0 | struct elf_aarch64_link_hash_table *htab; |
8634 | |
|
8635 | 0 | if (info->strip == strip_all |
8636 | 0 | && !info->emitrelocations |
8637 | 0 | && !bfd_link_relocatable (info)) |
8638 | 0 | return true; |
8639 | | |
8640 | 0 | htab = elf_aarch64_hash_table (info); |
8641 | |
|
8642 | 0 | osi.finfo = finfo; |
8643 | 0 | osi.info = info; |
8644 | 0 | osi.func = func; |
8645 | | |
8646 | | /* Long calls stubs. */ |
8647 | 0 | if (htab->stub_bfd && htab->stub_bfd->sections) |
8648 | 0 | { |
8649 | 0 | asection *stub_sec; |
8650 | |
|
8651 | 0 | for (stub_sec = htab->stub_bfd->sections; |
8652 | 0 | stub_sec != NULL; stub_sec = stub_sec->next) |
8653 | 0 | { |
8654 | | /* Ignore non-stub sections. */ |
8655 | 0 | if (!strstr (stub_sec->name, STUB_SUFFIX)) |
8656 | 0 | continue; |
8657 | | |
8658 | 0 | osi.sec = stub_sec; |
8659 | |
|
8660 | 0 | osi.sec_shndx = _bfd_elf_section_from_bfd_section |
8661 | 0 | (output_bfd, osi.sec->output_section); |
8662 | | |
8663 | | /* The first instruction in a stub is always a branch. */ |
8664 | 0 | if (!elf64_aarch64_output_map_sym (&osi, AARCH64_MAP_INSN, 0)) |
8665 | 0 | return false; |
8666 | | |
8667 | 0 | bfd_hash_traverse (&htab->stub_hash_table, aarch64_map_one_stub, |
8668 | 0 | &osi); |
8669 | 0 | } |
8670 | 0 | } |
8671 | | |
8672 | | /* Finally, output mapping symbols for the PLT. */ |
8673 | 0 | if (!htab->root.splt || htab->root.splt->size == 0) |
8674 | 0 | return true; |
8675 | | |
8676 | 0 | osi.sec_shndx = _bfd_elf_section_from_bfd_section |
8677 | 0 | (output_bfd, htab->root.splt->output_section); |
8678 | 0 | osi.sec = htab->root.splt; |
8679 | |
|
8680 | 0 | elf64_aarch64_output_map_sym (&osi, AARCH64_MAP_INSN, 0); |
8681 | |
|
8682 | 0 | return true; |
8683 | |
|
8684 | 0 | } |
8685 | | |
8686 | | /* Allocate target specific section data. */ |
8687 | | |
8688 | | static bool |
8689 | | elf64_aarch64_new_section_hook (bfd *abfd, asection *sec) |
8690 | 9.32k | { |
8691 | 9.32k | _aarch64_elf_section_data *sdata; |
8692 | | |
8693 | 9.32k | sdata = bfd_zalloc (abfd, sizeof (*sdata)); |
8694 | 9.32k | if (sdata == NULL) |
8695 | 0 | return false; |
8696 | 9.32k | sec->used_by_bfd = sdata; |
8697 | | |
8698 | 9.32k | return _bfd_elf_new_section_hook (abfd, sec); |
8699 | 9.32k | } |
8700 | | |
8701 | | |
8702 | | /* Create dynamic sections. This is different from the ARM backend in that |
8703 | | the got, plt, gotplt and their relocation sections are all created in the |
8704 | | standard part of the bfd elf backend. */ |
8705 | | |
8706 | | static bool |
8707 | | elf64_aarch64_create_dynamic_sections (bfd *dynobj, |
8708 | | struct bfd_link_info *info) |
8709 | 0 | { |
8710 | | /* We need to create .got section. */ |
8711 | 0 | if (!aarch64_elf_create_got_section (dynobj, info)) |
8712 | 0 | return false; |
8713 | | |
8714 | 0 | return _bfd_elf_create_dynamic_sections (dynobj, info); |
8715 | 0 | } |
8716 | | |
8717 | | |
8718 | | /* Allocate space in .plt, .got and associated reloc sections for |
8719 | | dynamic relocs. */ |
8720 | | |
8721 | | static bool |
8722 | | elf64_aarch64_allocate_dynrelocs (struct elf_link_hash_entry *h, void *inf) |
8723 | 0 | { |
8724 | 0 | struct bfd_link_info *info; |
8725 | 0 | struct elf_aarch64_link_hash_table *htab; |
8726 | 0 | struct elf_aarch64_link_hash_entry *eh; |
8727 | 0 | struct elf_dyn_relocs *p; |
8728 | | |
8729 | | /* An example of a bfd_link_hash_indirect symbol is versioned |
8730 | | symbol. For example: __gxx_personality_v0(bfd_link_hash_indirect) |
8731 | | -> __gxx_personality_v0(bfd_link_hash_defined) |
8732 | | |
8733 | | There is no need to process bfd_link_hash_indirect symbols here |
8734 | | because we will also be presented with the concrete instance of |
8735 | | the symbol and elf64_aarch64_copy_indirect_symbol () will have been |
8736 | | called to copy all relevant data from the generic to the concrete |
8737 | | symbol instance. */ |
8738 | 0 | if (h->root.type == bfd_link_hash_indirect) |
8739 | 0 | return true; |
8740 | | |
8741 | 0 | if (h->root.type == bfd_link_hash_warning) |
8742 | 0 | h = (struct elf_link_hash_entry *) h->root.u.i.link; |
8743 | |
|
8744 | 0 | info = (struct bfd_link_info *) inf; |
8745 | 0 | htab = elf_aarch64_hash_table (info); |
8746 | | |
8747 | | /* Since STT_GNU_IFUNC symbol must go through PLT, we handle it |
8748 | | here if it is defined and referenced in a non-shared object. */ |
8749 | 0 | if (h->type == STT_GNU_IFUNC |
8750 | 0 | && h->def_regular) |
8751 | 0 | return true; |
8752 | 0 | else if (htab->root.dynamic_sections_created && h->plt.refcount > 0) |
8753 | 0 | { |
8754 | | /* Make sure this symbol is output as a dynamic symbol. |
8755 | | Undefined weak syms won't yet be marked as dynamic. */ |
8756 | 0 | if (h->dynindx == -1 && !h->forced_local |
8757 | 0 | && h->root.type == bfd_link_hash_undefweak) |
8758 | 0 | { |
8759 | 0 | if (!bfd_elf_link_record_dynamic_symbol (info, h)) |
8760 | 0 | return false; |
8761 | 0 | } |
8762 | | |
8763 | 0 | if (bfd_link_pic (info) || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h)) |
8764 | 0 | { |
8765 | 0 | asection *s = htab->root.splt; |
8766 | | |
8767 | | /* If this is the first .plt entry, make room for the special |
8768 | | first entry. */ |
8769 | 0 | if (s->size == 0) |
8770 | 0 | s->size += htab->plt_header_size; |
8771 | |
|
8772 | 0 | h->plt.offset = s->size; |
8773 | | |
8774 | | /* If this symbol is not defined in a regular file, and we are |
8775 | | not generating a shared library, then set the symbol to this |
8776 | | location in the .plt. This is required to make function |
8777 | | pointers compare as equal between the normal executable and |
8778 | | the shared library. */ |
8779 | 0 | if (!bfd_link_pic (info) && !h->def_regular) |
8780 | 0 | { |
8781 | 0 | h->root.u.def.section = s; |
8782 | 0 | h->root.u.def.value = h->plt.offset; |
8783 | 0 | } |
8784 | | |
8785 | | /* Make room for this entry. For now we only create the |
8786 | | small model PLT entries. We later need to find a way |
8787 | | of relaxing into these from the large model PLT entries. */ |
8788 | 0 | s->size += htab->plt_entry_size; |
8789 | | |
8790 | | /* We also need to make an entry in the .got.plt section, which |
8791 | | will be placed in the .got section by the linker script. */ |
8792 | 0 | htab->root.sgotplt->size += GOT_ENTRY_SIZE; |
8793 | | |
8794 | | /* We also need to make an entry in the .rela.plt section. */ |
8795 | 0 | htab->root.srelplt->size += RELOC_SIZE (htab); |
8796 | | |
8797 | | /* We need to ensure that all GOT entries that serve the PLT |
8798 | | are consecutive with the special GOT slots [0] [1] and |
8799 | | [2]. Any addtional relocations, such as |
8800 | | R_AARCH64_TLSDESC, must be placed after the PLT related |
8801 | | entries. We abuse the reloc_count such that during |
8802 | | sizing we adjust reloc_count to indicate the number of |
8803 | | PLT related reserved entries. In subsequent phases when |
8804 | | filling in the contents of the reloc entries, PLT related |
8805 | | entries are placed by computing their PLT index (0 |
8806 | | .. reloc_count). While other none PLT relocs are placed |
8807 | | at the slot indicated by reloc_count and reloc_count is |
8808 | | updated. */ |
8809 | |
|
8810 | 0 | htab->root.srelplt->reloc_count++; |
8811 | | |
8812 | | /* Mark the DSO in case R_<CLS>_JUMP_SLOT relocs against |
8813 | | variant PCS symbols are present. */ |
8814 | 0 | if (h->other & STO_AARCH64_VARIANT_PCS) |
8815 | 0 | htab->variant_pcs = 1; |
8816 | |
|
8817 | 0 | } |
8818 | 0 | else |
8819 | 0 | { |
8820 | 0 | h->plt.offset = (bfd_vma) - 1; |
8821 | 0 | h->needs_plt = 0; |
8822 | 0 | } |
8823 | 0 | } |
8824 | 0 | else |
8825 | 0 | { |
8826 | 0 | h->plt.offset = (bfd_vma) - 1; |
8827 | 0 | h->needs_plt = 0; |
8828 | 0 | } |
8829 | | |
8830 | 0 | eh = (struct elf_aarch64_link_hash_entry *) h; |
8831 | 0 | eh->tlsdesc_got_jump_table_offset = (bfd_vma) - 1; |
8832 | |
|
8833 | 0 | if (h->got.refcount > 0) |
8834 | 0 | { |
8835 | 0 | bool dyn; |
8836 | 0 | unsigned got_type = elf_aarch64_hash_entry (h)->got_type; |
8837 | |
|
8838 | 0 | h->got.offset = (bfd_vma) - 1; |
8839 | |
|
8840 | 0 | dyn = htab->root.dynamic_sections_created; |
8841 | | |
8842 | | /* Make sure this symbol is output as a dynamic symbol. |
8843 | | Undefined weak syms won't yet be marked as dynamic. */ |
8844 | 0 | if (dyn && h->dynindx == -1 && !h->forced_local |
8845 | 0 | && h->root.type == bfd_link_hash_undefweak) |
8846 | 0 | { |
8847 | 0 | if (!bfd_elf_link_record_dynamic_symbol (info, h)) |
8848 | 0 | return false; |
8849 | 0 | } |
8850 | | |
8851 | 0 | if (got_type == GOT_UNKNOWN) |
8852 | 0 | { |
8853 | 0 | } |
8854 | 0 | else if (got_type == GOT_NORMAL) |
8855 | 0 | { |
8856 | 0 | h->got.offset = htab->root.sgot->size; |
8857 | 0 | htab->root.sgot->size += GOT_ENTRY_SIZE; |
8858 | 0 | if ((ELF_ST_VISIBILITY (h->other) == STV_DEFAULT |
8859 | 0 | || h->root.type != bfd_link_hash_undefweak) |
8860 | 0 | && (bfd_link_pic (info) |
8861 | 0 | || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, 0, h)) |
8862 | | /* Undefined weak symbol in static PIE resolves to 0 without |
8863 | | any dynamic relocations. */ |
8864 | 0 | && !UNDEFWEAK_NO_DYNAMIC_RELOC (info, h)) |
8865 | 0 | { |
8866 | 0 | htab->root.srelgot->size += RELOC_SIZE (htab); |
8867 | 0 | } |
8868 | 0 | } |
8869 | 0 | else |
8870 | 0 | { |
8871 | 0 | int indx; |
8872 | 0 | if (got_type & GOT_TLSDESC_GD) |
8873 | 0 | { |
8874 | 0 | eh->tlsdesc_got_jump_table_offset = |
8875 | 0 | (htab->root.sgotplt->size |
8876 | 0 | - aarch64_compute_jump_table_size (htab)); |
8877 | 0 | htab->root.sgotplt->size += GOT_ENTRY_SIZE * 2; |
8878 | 0 | h->got.offset = (bfd_vma) - 2; |
8879 | 0 | } |
8880 | |
|
8881 | 0 | if (got_type & GOT_TLS_GD) |
8882 | 0 | { |
8883 | 0 | h->got.offset = htab->root.sgot->size; |
8884 | 0 | htab->root.sgot->size += GOT_ENTRY_SIZE * 2; |
8885 | 0 | } |
8886 | |
|
8887 | 0 | if (got_type & GOT_TLS_IE) |
8888 | 0 | { |
8889 | 0 | h->got.offset = htab->root.sgot->size; |
8890 | 0 | htab->root.sgot->size += GOT_ENTRY_SIZE; |
8891 | 0 | } |
8892 | |
|
8893 | 0 | indx = h && h->dynindx != -1 ? h->dynindx : 0; |
8894 | 0 | if ((ELF_ST_VISIBILITY (h->other) == STV_DEFAULT |
8895 | 0 | || h->root.type != bfd_link_hash_undefweak) |
8896 | 0 | && (!bfd_link_executable (info) |
8897 | 0 | || indx != 0 |
8898 | 0 | || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, 0, h))) |
8899 | 0 | { |
8900 | 0 | if (got_type & GOT_TLSDESC_GD) |
8901 | 0 | { |
8902 | 0 | htab->root.srelplt->size += RELOC_SIZE (htab); |
8903 | | /* Note reloc_count not incremented here! We have |
8904 | | already adjusted reloc_count for this relocation |
8905 | | type. */ |
8906 | | |
8907 | | /* TLSDESC PLT is now needed, but not yet determined. */ |
8908 | 0 | htab->root.tlsdesc_plt = (bfd_vma) - 1; |
8909 | 0 | } |
8910 | |
|
8911 | 0 | if (got_type & GOT_TLS_GD) |
8912 | 0 | htab->root.srelgot->size += RELOC_SIZE (htab) * 2; |
8913 | |
|
8914 | 0 | if (got_type & GOT_TLS_IE) |
8915 | 0 | htab->root.srelgot->size += RELOC_SIZE (htab); |
8916 | 0 | } |
8917 | 0 | } |
8918 | 0 | } |
8919 | 0 | else |
8920 | 0 | { |
8921 | 0 | h->got.offset = (bfd_vma) - 1; |
8922 | 0 | } |
8923 | | |
8924 | 0 | if (h->dyn_relocs == NULL) |
8925 | 0 | return true; |
8926 | | |
8927 | 0 | for (p = h->dyn_relocs; p != NULL; p = p->next) |
8928 | 0 | if (eh->def_protected) |
8929 | 0 | { |
8930 | | /* Disallow copy relocations against protected symbol. */ |
8931 | 0 | asection *s = p->sec->output_section; |
8932 | 0 | if (s != NULL && (s->flags & SEC_READONLY) != 0) |
8933 | 0 | { |
8934 | 0 | info->callbacks->fatal |
8935 | | /* xgettext:c-format */ |
8936 | 0 | (_ ("%P: %pB: copy relocation against non-copyable " |
8937 | 0 | "protected symbol `%s'\n"), |
8938 | 0 | p->sec->owner, h->root.root.string); |
8939 | 0 | return false; |
8940 | 0 | } |
8941 | 0 | } |
8942 | | |
8943 | | /* In the shared -Bsymbolic case, discard space allocated for |
8944 | | dynamic pc-relative relocs against symbols which turn out to be |
8945 | | defined in regular objects. For the normal shared case, discard |
8946 | | space for pc-relative relocs that have become local due to symbol |
8947 | | visibility changes. */ |
8948 | | |
8949 | 0 | if (bfd_link_pic (info)) |
8950 | 0 | { |
8951 | | /* Relocs that use pc_count are those that appear on a call |
8952 | | insn, or certain REL relocs that can generated via assembly. |
8953 | | We want calls to protected symbols to resolve directly to the |
8954 | | function rather than going via the plt. If people want |
8955 | | function pointer comparisons to work as expected then they |
8956 | | should avoid writing weird assembly. */ |
8957 | 0 | if (SYMBOL_CALLS_LOCAL (info, h)) |
8958 | 0 | { |
8959 | 0 | struct elf_dyn_relocs **pp; |
8960 | |
|
8961 | 0 | for (pp = &h->dyn_relocs; (p = *pp) != NULL;) |
8962 | 0 | { |
8963 | 0 | p->count -= p->pc_count; |
8964 | 0 | p->pc_count = 0; |
8965 | 0 | if (p->count == 0) |
8966 | 0 | *pp = p->next; |
8967 | 0 | else |
8968 | 0 | pp = &p->next; |
8969 | 0 | } |
8970 | 0 | } |
8971 | | |
8972 | | /* Also discard relocs on undefined weak syms with non-default |
8973 | | visibility. */ |
8974 | 0 | if (h->dyn_relocs != NULL && h->root.type == bfd_link_hash_undefweak) |
8975 | 0 | { |
8976 | 0 | if (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT |
8977 | 0 | || UNDEFWEAK_NO_DYNAMIC_RELOC (info, h)) |
8978 | 0 | h->dyn_relocs = NULL; |
8979 | | |
8980 | | /* Make sure undefined weak symbols are output as a dynamic |
8981 | | symbol in PIEs. */ |
8982 | 0 | else if (h->dynindx == -1 |
8983 | 0 | && !h->forced_local |
8984 | 0 | && h->root.type == bfd_link_hash_undefweak |
8985 | 0 | && !bfd_elf_link_record_dynamic_symbol (info, h)) |
8986 | 0 | return false; |
8987 | 0 | } |
8988 | |
|
8989 | 0 | } |
8990 | 0 | else if (ELIMINATE_COPY_RELOCS) |
8991 | 0 | { |
8992 | | /* For the non-shared case, discard space for relocs against |
8993 | | symbols which turn out to need copy relocs or are not |
8994 | | dynamic. */ |
8995 | |
|
8996 | 0 | if (!h->non_got_ref |
8997 | 0 | && ((h->def_dynamic |
8998 | 0 | && !h->def_regular) |
8999 | 0 | || (htab->root.dynamic_sections_created |
9000 | 0 | && (h->root.type == bfd_link_hash_undefweak |
9001 | 0 | || h->root.type == bfd_link_hash_undefined)))) |
9002 | 0 | { |
9003 | | /* Make sure this symbol is output as a dynamic symbol. |
9004 | | Undefined weak syms won't yet be marked as dynamic. */ |
9005 | 0 | if (h->dynindx == -1 |
9006 | 0 | && !h->forced_local |
9007 | 0 | && h->root.type == bfd_link_hash_undefweak |
9008 | 0 | && !bfd_elf_link_record_dynamic_symbol (info, h)) |
9009 | 0 | return false; |
9010 | | |
9011 | | /* If that succeeded, we know we'll be keeping all the |
9012 | | relocs. */ |
9013 | 0 | if (h->dynindx != -1) |
9014 | 0 | goto keep; |
9015 | 0 | } |
9016 | | |
9017 | 0 | h->dyn_relocs = NULL; |
9018 | |
|
9019 | 0 | keep:; |
9020 | 0 | } |
9021 | | |
9022 | | /* Finally, allocate space. */ |
9023 | 0 | for (p = h->dyn_relocs; p != NULL; p = p->next) |
9024 | 0 | { |
9025 | 0 | asection *sreloc; |
9026 | |
|
9027 | 0 | sreloc = elf_section_data (p->sec)->sreloc; |
9028 | |
|
9029 | 0 | BFD_ASSERT (sreloc != NULL); |
9030 | |
|
9031 | 0 | sreloc->size += p->count * RELOC_SIZE (htab); |
9032 | 0 | } |
9033 | |
|
9034 | 0 | return true; |
9035 | 0 | } |
9036 | | |
9037 | | /* Allocate space in .plt, .got and associated reloc sections for |
9038 | | ifunc dynamic relocs. */ |
9039 | | |
9040 | | static bool |
9041 | | elf64_aarch64_allocate_ifunc_dynrelocs (struct elf_link_hash_entry *h, |
9042 | | void *inf) |
9043 | 0 | { |
9044 | 0 | struct bfd_link_info *info; |
9045 | 0 | struct elf_aarch64_link_hash_table *htab; |
9046 | | |
9047 | | /* An example of a bfd_link_hash_indirect symbol is versioned |
9048 | | symbol. For example: __gxx_personality_v0(bfd_link_hash_indirect) |
9049 | | -> __gxx_personality_v0(bfd_link_hash_defined) |
9050 | | |
9051 | | There is no need to process bfd_link_hash_indirect symbols here |
9052 | | because we will also be presented with the concrete instance of |
9053 | | the symbol and elf64_aarch64_copy_indirect_symbol () will have been |
9054 | | called to copy all relevant data from the generic to the concrete |
9055 | | symbol instance. */ |
9056 | 0 | if (h->root.type == bfd_link_hash_indirect) |
9057 | 0 | return true; |
9058 | | |
9059 | 0 | if (h->root.type == bfd_link_hash_warning) |
9060 | 0 | h = (struct elf_link_hash_entry *) h->root.u.i.link; |
9061 | |
|
9062 | 0 | info = (struct bfd_link_info *) inf; |
9063 | 0 | htab = elf_aarch64_hash_table (info); |
9064 | | |
9065 | | /* Since STT_GNU_IFUNC symbol must go through PLT, we handle it |
9066 | | here if it is defined and referenced in a non-shared object. */ |
9067 | 0 | if (h->type == STT_GNU_IFUNC |
9068 | 0 | && h->def_regular) |
9069 | 0 | return _bfd_elf_allocate_ifunc_dyn_relocs (info, h, |
9070 | 0 | &h->dyn_relocs, |
9071 | 0 | htab->plt_entry_size, |
9072 | 0 | htab->plt_header_size, |
9073 | 0 | GOT_ENTRY_SIZE, |
9074 | 0 | false); |
9075 | 0 | return true; |
9076 | 0 | } |
9077 | | |
9078 | | /* Allocate space in .plt, .got and associated reloc sections for |
9079 | | local ifunc dynamic relocs. */ |
9080 | | |
9081 | | static int |
9082 | | elf64_aarch64_allocate_local_ifunc_dynrelocs (void **slot, void *inf) |
9083 | 0 | { |
9084 | 0 | struct elf_link_hash_entry *h |
9085 | 0 | = (struct elf_link_hash_entry *) *slot; |
9086 | |
|
9087 | 0 | if (h->type != STT_GNU_IFUNC |
9088 | 0 | || !h->def_regular |
9089 | 0 | || !h->ref_regular |
9090 | 0 | || !h->forced_local |
9091 | 0 | || h->root.type != bfd_link_hash_defined) |
9092 | 0 | abort (); |
9093 | | |
9094 | 0 | return elf64_aarch64_allocate_ifunc_dynrelocs (h, inf); |
9095 | 0 | } |
9096 | | |
9097 | | /* Record a relative relocation that will be emitted packed (DT_RELR). |
9098 | | Called after relocation sections are sized, so undo the size accounting |
9099 | | for this relocation. */ |
9100 | | |
9101 | | static bool |
9102 | | record_relr (struct elf_aarch64_link_hash_table *htab, asection *sec, |
9103 | | bfd_vma off, asection *sreloc) |
9104 | 0 | { |
9105 | | /* Undo the relocation section size accounting. */ |
9106 | 0 | BFD_ASSERT (sreloc->size >= RELOC_SIZE (htab)); |
9107 | 0 | sreloc->size -= RELOC_SIZE (htab); |
9108 | | /* The packing format uses the last bit of the address so that |
9109 | | must be aligned. We don't pack relocations that may not be |
9110 | | aligned even though the final output address could end up |
9111 | | aligned, to avoid complex sizing logic for a rare case. */ |
9112 | 0 | BFD_ASSERT (off % 2 == 0 && sec->alignment_power > 0); |
9113 | 0 | if (htab->relr_count >= htab->relr_alloc) |
9114 | 0 | { |
9115 | 0 | if (htab->relr_alloc == 0) |
9116 | 0 | htab->relr_alloc = 4096; |
9117 | 0 | else |
9118 | 0 | htab->relr_alloc *= 2; |
9119 | 0 | htab->relr = bfd_realloc (htab->relr, |
9120 | 0 | htab->relr_alloc * sizeof (*htab->relr)); |
9121 | 0 | if (htab->relr == NULL) |
9122 | 0 | return false; |
9123 | 0 | } |
9124 | 0 | htab->relr[htab->relr_count].sec = sec; |
9125 | 0 | htab->relr[htab->relr_count].off = off; |
9126 | 0 | htab->relr_count++; |
9127 | 0 | return true; |
9128 | 0 | } |
9129 | | |
9130 | | /* Follow elf64_aarch64_allocate_dynrelocs, but only record relative |
9131 | | relocations against the GOT and undo their previous size accounting. */ |
9132 | | |
9133 | | static bool |
9134 | | record_relr_dyn_got_relocs (struct elf_link_hash_entry *h, void *inf) |
9135 | 0 | { |
9136 | |
|
9137 | 0 | if (h->root.type == bfd_link_hash_indirect) |
9138 | 0 | return true; |
9139 | 0 | if (h->root.type == bfd_link_hash_warning) |
9140 | 0 | h = (struct elf_link_hash_entry *) h->root.u.i.link; |
9141 | 0 | if (h->type == STT_GNU_IFUNC && h->def_regular) |
9142 | 0 | return true; |
9143 | 0 | if (h->got.refcount <= 0) |
9144 | 0 | return true; |
9145 | 0 | if (elf_aarch64_hash_entry (h)->got_type != GOT_NORMAL) |
9146 | 0 | return true; |
9147 | | |
9148 | 0 | struct bfd_link_info *info = (struct bfd_link_info *) inf; |
9149 | 0 | struct elf_aarch64_link_hash_table *htab = elf_aarch64_hash_table (info); |
9150 | |
|
9151 | 0 | if ((ELF_ST_VISIBILITY (h->other) == STV_DEFAULT |
9152 | 0 | || h->root.type != bfd_link_hash_undefweak) |
9153 | 0 | && bfd_link_pic (info) |
9154 | | /* Undefined weak symbol in static PIE resolves to 0 without |
9155 | | any dynamic relocations. */ |
9156 | 0 | && !UNDEFWEAK_NO_DYNAMIC_RELOC (info, h)) |
9157 | 0 | { |
9158 | 0 | bool relative_reloc = SYMBOL_REFERENCES_LOCAL (info, h) |
9159 | 0 | && !bfd_is_abs_symbol (&h->root); |
9160 | 0 | if (relative_reloc) |
9161 | 0 | if (!record_relr (htab, htab->root.sgot, h->got.offset, |
9162 | 0 | htab->root.srelgot)) |
9163 | 0 | return false; |
9164 | 0 | } |
9165 | 0 | return true; |
9166 | 0 | } |
9167 | | |
9168 | | /* Record packed relative relocs against the GOT for local symbols. |
9169 | | Undo the size accounting of elf64_aarch64_late_size_sections. */ |
9170 | | |
9171 | | static bool |
9172 | | record_relr_local_got_relocs (bfd *input_bfd, struct bfd_link_info *info) |
9173 | 0 | { |
9174 | 0 | struct elf_aarch64_local_symbol *locals; |
9175 | 0 | Elf_Internal_Shdr *symtab_hdr; |
9176 | 0 | struct elf_aarch64_link_hash_table *htab; |
9177 | |
|
9178 | 0 | if (!bfd_link_pic (info)) |
9179 | 0 | return true; |
9180 | | |
9181 | 0 | locals = elf_aarch64_locals (input_bfd); |
9182 | 0 | if (locals == NULL) |
9183 | 0 | return true; |
9184 | | |
9185 | 0 | symtab_hdr = &elf_symtab_hdr (input_bfd); |
9186 | 0 | htab = elf_aarch64_hash_table (info); |
9187 | 0 | for (unsigned int i = 0; i < symtab_hdr->sh_info; i++) |
9188 | 0 | { |
9189 | 0 | bfd_vma off = locals[i].got_offset; |
9190 | 0 | if (locals[i].got_refcount <= 0) |
9191 | 0 | continue; |
9192 | 0 | if ((locals[i].got_type & GOT_NORMAL) == 0) |
9193 | 0 | continue; |
9194 | | |
9195 | | /* FIXME: If the local symbol is in SHN_ABS then emitting |
9196 | | a relative relocation is not correct, but it seems to |
9197 | | be wrong in elf64_aarch64_final_link_relocate too. */ |
9198 | 0 | if (!record_relr (htab, htab->root.sgot, off, htab->root.srelgot)) |
9199 | 0 | return false; |
9200 | 0 | } |
9201 | 0 | return true; |
9202 | 0 | } |
9203 | | |
9204 | | /* Follows the logic of elf64_aarch64_relocate_section to decide which |
9205 | | relocations will become relative and possible to pack. Ignore |
9206 | | relocations against the GOT, those are handled separately per-symbol. |
9207 | | Undo the size accounting of the packed relocations and record them |
9208 | | so the relr section can be sized later. */ |
9209 | | |
9210 | | static bool |
9211 | | record_relr_non_got_relocs (bfd *input_bfd, struct bfd_link_info *info, |
9212 | | asection *sec) |
9213 | 0 | { |
9214 | 0 | const Elf_Internal_Rela *relocs; |
9215 | 0 | const Elf_Internal_Rela *rel; |
9216 | 0 | const Elf_Internal_Rela *rel_end; |
9217 | 0 | asection *sreloc; |
9218 | 0 | struct elf_aarch64_link_hash_table *htab; |
9219 | 0 | Elf_Internal_Shdr *symtab_hdr; |
9220 | 0 | struct elf_link_hash_entry **sym_hashes; |
9221 | |
|
9222 | 0 | if (sec->reloc_count == 0) |
9223 | 0 | return true; |
9224 | 0 | if ((sec->flags & (SEC_RELOC | SEC_ALLOC | SEC_DEBUGGING)) |
9225 | 0 | != (SEC_RELOC | SEC_ALLOC)) |
9226 | 0 | return true; |
9227 | 0 | if (sec->alignment_power == 0) |
9228 | 0 | return true; |
9229 | 0 | if (discarded_section (sec)) |
9230 | 0 | return true; |
9231 | 0 | sreloc = elf_section_data (sec)->sreloc; |
9232 | 0 | if (sreloc == NULL) |
9233 | 0 | return true; |
9234 | 0 | htab = elf_aarch64_hash_table (info); |
9235 | 0 | symtab_hdr = &elf_symtab_hdr (input_bfd); |
9236 | 0 | sym_hashes = elf_sym_hashes (input_bfd); |
9237 | 0 | relocs = _bfd_elf_link_info_read_relocs (input_bfd, info, sec, NULL, NULL, |
9238 | 0 | info->keep_memory); |
9239 | 0 | BFD_ASSERT (relocs != NULL); |
9240 | 0 | rel_end = relocs + sec->reloc_count; |
9241 | 0 | for (rel = relocs; rel < rel_end; rel++) |
9242 | 0 | { |
9243 | 0 | unsigned int r_symndx = ELF64_R_SYM (rel->r_info); |
9244 | 0 | unsigned int r_type = ELF64_R_TYPE (rel->r_info); |
9245 | |
|
9246 | 0 | bfd_reloc_code_real_type bfd_r_type |
9247 | 0 | = elf64_aarch64_bfd_reloc_from_type (input_bfd, r_type); |
9248 | | /* Handle relocs that can become R_AARCH64_RELATIVE, |
9249 | | but not ones against the GOT as those are handled |
9250 | | separately per-symbol. */ |
9251 | 0 | if (bfd_r_type != BFD_RELOC_AARCH64_64) |
9252 | 0 | continue; |
9253 | | /* Can only pack relocation against an aligned address. */ |
9254 | 0 | if (rel->r_offset % 2 != 0) |
9255 | 0 | continue; |
9256 | | |
9257 | 0 | struct elf_link_hash_entry *h = NULL; |
9258 | 0 | asection *def_sec = NULL; |
9259 | 0 | bool resolved_to_zero = false; |
9260 | 0 | if (r_symndx < symtab_hdr->sh_info) |
9261 | 0 | { |
9262 | | /* A local symbol. */ |
9263 | 0 | Elf_Internal_Sym *isym; |
9264 | 0 | isym = bfd_sym_from_r_symndx (&htab->root.sym_cache, |
9265 | 0 | input_bfd, r_symndx); |
9266 | 0 | BFD_ASSERT (isym != NULL); |
9267 | 0 | if (ELF_ST_TYPE (isym->st_info) == STT_GNU_IFUNC) |
9268 | 0 | continue; |
9269 | 0 | def_sec = bfd_section_from_elf_index (input_bfd, isym->st_shndx); |
9270 | 0 | } |
9271 | 0 | else |
9272 | 0 | { |
9273 | 0 | h = sym_hashes[r_symndx - symtab_hdr->sh_info]; |
9274 | 0 | while (h->root.type == bfd_link_hash_indirect |
9275 | 0 | || h->root.type == bfd_link_hash_warning) |
9276 | 0 | h = (struct elf_link_hash_entry *) h->root.u.i.link; |
9277 | | |
9278 | | /* Filter out symbols that cannot have a relative reloc. */ |
9279 | 0 | if (h->dyn_relocs == NULL) |
9280 | 0 | continue; |
9281 | 0 | if (bfd_is_abs_symbol (&h->root)) |
9282 | 0 | continue; |
9283 | 0 | if (h->type == STT_GNU_IFUNC) |
9284 | 0 | continue; |
9285 | | |
9286 | 0 | if (h->root.type == bfd_link_hash_defined |
9287 | 0 | || h->root.type == bfd_link_hash_defweak) |
9288 | 0 | def_sec = h->root.u.def.section; |
9289 | 0 | resolved_to_zero = UNDEFWEAK_NO_DYNAMIC_RELOC (info, h); |
9290 | 0 | } |
9291 | 0 | if (def_sec != NULL && discarded_section (def_sec)) |
9292 | 0 | continue; |
9293 | | /* Same logic as in elf64_aarch64_final_link_relocate. |
9294 | | Except conditionals trimmed that cannot result a reltive reloc. */ |
9295 | 0 | if (bfd_link_pic (info) |
9296 | 0 | && (h == NULL |
9297 | 0 | || (ELF_ST_VISIBILITY (h->other) == STV_DEFAULT |
9298 | 0 | && !resolved_to_zero) |
9299 | 0 | || h->root.type != bfd_link_hash_undefweak)) |
9300 | 0 | { |
9301 | 0 | if (h != NULL |
9302 | 0 | && h->dynindx != -1 |
9303 | 0 | && (!(bfd_link_pie (info) || SYMBOLIC_BIND (info, h)) |
9304 | 0 | || !h->def_regular)) |
9305 | 0 | continue; |
9306 | 0 | if (!record_relr (htab, sec, rel->r_offset, sreloc)) |
9307 | 0 | return false; |
9308 | 0 | } |
9309 | 0 | } |
9310 | 0 | return true; |
9311 | 0 | } |
9312 | | |
9313 | | static int |
9314 | | cmp_relr_addr (const void *p, const void *q) |
9315 | 0 | { |
9316 | 0 | const bfd_vma *a = p; |
9317 | 0 | const bfd_vma *b = q; |
9318 | 0 | return *a < *b ? -1 : *a > *b ? 1 : 0; |
9319 | 0 | } |
9320 | | |
9321 | | /* Produce a malloc'd sorted array of reloc addresses in htab->relr_sorted. |
9322 | | Returns false on allocation failure. */ |
9323 | | |
9324 | | static bool |
9325 | | sort_relr (struct bfd_link_info *info, |
9326 | | struct elf_aarch64_link_hash_table *htab) |
9327 | 0 | { |
9328 | 0 | if (htab->relr_count == 0) |
9329 | 0 | return true; |
9330 | | |
9331 | 0 | bfd_vma *addr = htab->relr_sorted; |
9332 | 0 | if (addr == NULL) |
9333 | 0 | { |
9334 | 0 | addr = bfd_malloc (htab->relr_count * sizeof (*addr)); |
9335 | 0 | if (addr == NULL) |
9336 | 0 | return false; |
9337 | 0 | htab->relr_sorted = addr; |
9338 | 0 | } |
9339 | | |
9340 | 0 | for (bfd_size_type i = 0; i < htab->relr_count; i++) |
9341 | 0 | { |
9342 | 0 | bfd_vma off = _bfd_elf_section_offset (info->output_bfd, info, |
9343 | 0 | htab->relr[i].sec, |
9344 | 0 | htab->relr[i].off); |
9345 | 0 | addr[i] = htab->relr[i].sec->output_section->vma |
9346 | 0 | + htab->relr[i].sec->output_offset |
9347 | 0 | + off; |
9348 | 0 | } |
9349 | 0 | qsort (addr, htab->relr_count, sizeof (*addr), cmp_relr_addr); |
9350 | 0 | return true; |
9351 | 0 | } |
9352 | | |
9353 | | /* Size of a relr entry and a relocated location. */ |
9354 | 0 | #define RELR_SZ (ARCH_SIZE / 8) |
9355 | | /* Number of consecutive locations a relr bitmap entry references. */ |
9356 | 0 | #define RELR_N (ARCH_SIZE - 1) |
9357 | | |
9358 | | /* Size .relr.dyn whenever the layout changes, the number of packed |
9359 | | relocs are unchanged but the packed representation can. */ |
9360 | | |
9361 | | bool |
9362 | | elf64_aarch64_size_relative_relocs (struct bfd_link_info *info, |
9363 | | bool *need_layout) |
9364 | 0 | { |
9365 | 0 | struct elf_aarch64_link_hash_table *htab = elf_aarch64_hash_table (info); |
9366 | 0 | asection *srelrdyn = htab->root.srelrdyn; |
9367 | 0 | *need_layout = false; |
9368 | |
|
9369 | 0 | if (!sort_relr (info, htab)) |
9370 | 0 | return false; |
9371 | 0 | bfd_vma *addr = htab->relr_sorted; |
9372 | |
|
9373 | 0 | BFD_ASSERT (srelrdyn != NULL); |
9374 | 0 | bfd_size_type oldsize = srelrdyn->size; |
9375 | 0 | srelrdyn->size = 0; |
9376 | 0 | for (bfd_size_type i = 0; i < htab->relr_count; ) |
9377 | 0 | { |
9378 | 0 | bfd_vma base = addr[i]; |
9379 | 0 | i++; |
9380 | 0 | srelrdyn->size += RELR_SZ; |
9381 | 0 | base += RELR_SZ; |
9382 | 0 | for (;;) |
9383 | 0 | { |
9384 | 0 | bfd_size_type start_i = i; |
9385 | 0 | while (i < htab->relr_count |
9386 | 0 | && addr[i] - base < RELR_N * RELR_SZ |
9387 | 0 | && (addr[i] - base) % RELR_SZ == 0) |
9388 | 0 | i++; |
9389 | 0 | if (i == start_i) |
9390 | 0 | break; |
9391 | 0 | srelrdyn->size += RELR_SZ; |
9392 | 0 | base += RELR_N * RELR_SZ; |
9393 | 0 | } |
9394 | 0 | } |
9395 | 0 | if (srelrdyn->size != oldsize) |
9396 | 0 | { |
9397 | 0 | *need_layout = true; |
9398 | | /* Stop after a few iterations in case the layout does not converge, |
9399 | | we can do this when the size would shrink. */ |
9400 | 0 | if (htab->relr_layout_iter++ > 5 && srelrdyn->size < oldsize) |
9401 | 0 | { |
9402 | 0 | srelrdyn->size = oldsize; |
9403 | 0 | *need_layout = false; |
9404 | 0 | } |
9405 | 0 | } |
9406 | 0 | return true; |
9407 | 0 | } |
9408 | | |
9409 | | /* Emit the .relr.dyn section after it is sized and the layout is fixed. */ |
9410 | | |
9411 | | bool |
9412 | | elf64_aarch64_finish_relative_relocs (struct bfd_link_info *info) |
9413 | 0 | { |
9414 | 0 | struct elf_aarch64_link_hash_table *htab = elf_aarch64_hash_table (info); |
9415 | 0 | asection *srelrdyn = htab->root.srelrdyn; |
9416 | 0 | bfd *dynobj = htab->root.dynobj; |
9417 | |
|
9418 | 0 | if (srelrdyn == NULL || srelrdyn->size == 0) |
9419 | 0 | return true; |
9420 | 0 | srelrdyn->contents = bfd_alloc (dynobj, srelrdyn->size); |
9421 | 0 | if (srelrdyn->contents == NULL) |
9422 | 0 | return false; |
9423 | 0 | srelrdyn->alloced = 1; |
9424 | 0 | bfd_vma *addr = htab->relr_sorted; |
9425 | 0 | bfd_byte *loc = srelrdyn->contents; |
9426 | 0 | for (bfd_size_type i = 0; i < htab->relr_count; ) |
9427 | 0 | { |
9428 | 0 | bfd_vma base = addr[i]; |
9429 | 0 | i++; |
9430 | 0 | bfd_put_64 (dynobj, base, loc); |
9431 | 0 | loc += RELR_SZ; |
9432 | 0 | base += RELR_SZ; |
9433 | 0 | for (;;) |
9434 | 0 | { |
9435 | 0 | bfd_vma bits = 0; |
9436 | 0 | while (i < htab->relr_count) |
9437 | 0 | { |
9438 | 0 | bfd_vma delta = addr[i] - base; |
9439 | 0 | if (delta >= RELR_N * RELR_SZ || delta % RELR_SZ != 0) |
9440 | 0 | break; |
9441 | 0 | bits |= (bfd_vma) 1 << (delta / RELR_SZ); |
9442 | 0 | i++; |
9443 | 0 | } |
9444 | 0 | if (bits == 0) |
9445 | 0 | break; |
9446 | 0 | bfd_put_64 (dynobj, (bits << 1) | 1, loc); |
9447 | 0 | loc += RELR_SZ; |
9448 | 0 | base += RELR_N * RELR_SZ; |
9449 | 0 | } |
9450 | 0 | } |
9451 | 0 | free (addr); |
9452 | 0 | htab->relr_sorted = NULL; |
9453 | | /* Pad any excess with 1's, a do-nothing encoding. */ |
9454 | 0 | while (loc < srelrdyn->contents + srelrdyn->size) |
9455 | 0 | { |
9456 | 0 | bfd_put_64 (dynobj, 1, loc); |
9457 | 0 | loc += RELR_SZ; |
9458 | 0 | } |
9459 | 0 | return true; |
9460 | 0 | } |
9461 | | |
9462 | | /* This is the most important function of all . Innocuosly named |
9463 | | though ! */ |
9464 | | |
9465 | | static bool |
9466 | | elf64_aarch64_late_size_sections (bfd *output_bfd ATTRIBUTE_UNUSED, |
9467 | | struct bfd_link_info *info) |
9468 | 0 | { |
9469 | 0 | struct elf_aarch64_link_hash_table *htab; |
9470 | 0 | bfd *dynobj; |
9471 | 0 | asection *s; |
9472 | 0 | bool relocs; |
9473 | 0 | bfd *ibfd; |
9474 | |
|
9475 | 0 | htab = elf_aarch64_hash_table ((info)); |
9476 | 0 | dynobj = htab->root.dynobj; |
9477 | |
|
9478 | 0 | if (dynobj == NULL) |
9479 | 0 | return true; |
9480 | | |
9481 | 0 | if (htab->root.dynamic_sections_created) |
9482 | 0 | { |
9483 | 0 | if (bfd_link_executable (info) && !info->nointerp) |
9484 | 0 | { |
9485 | 0 | s = bfd_get_linker_section (dynobj, ".interp"); |
9486 | 0 | if (s == NULL) |
9487 | 0 | abort (); |
9488 | 0 | s->size = sizeof ELF_DYNAMIC_INTERPRETER; |
9489 | 0 | s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER; |
9490 | 0 | s->alloced = 1; |
9491 | 0 | } |
9492 | 0 | } |
9493 | | |
9494 | | /* Set up .got offsets for local syms, and space for local dynamic |
9495 | | relocs. */ |
9496 | 0 | for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link.next) |
9497 | 0 | { |
9498 | 0 | struct elf_aarch64_local_symbol *locals = NULL; |
9499 | 0 | Elf_Internal_Shdr *symtab_hdr; |
9500 | 0 | asection *srel; |
9501 | 0 | unsigned int i; |
9502 | |
|
9503 | 0 | if (!is_aarch64_elf (ibfd)) |
9504 | 0 | continue; |
9505 | | |
9506 | 0 | for (s = ibfd->sections; s != NULL; s = s->next) |
9507 | 0 | { |
9508 | 0 | struct elf_dyn_relocs *p; |
9509 | |
|
9510 | 0 | for (p = (struct elf_dyn_relocs *) |
9511 | 0 | (elf_section_data (s)->local_dynrel); p != NULL; p = p->next) |
9512 | 0 | { |
9513 | 0 | if (discarded_section (p->sec)) |
9514 | 0 | { |
9515 | | /* Input section has been discarded, either because |
9516 | | it is a copy of a linkonce section or due to |
9517 | | linker script /DISCARD/, so we'll be discarding |
9518 | | the relocs too. */ |
9519 | 0 | } |
9520 | 0 | else if (p->count != 0) |
9521 | 0 | { |
9522 | 0 | srel = elf_section_data (p->sec)->sreloc; |
9523 | 0 | srel->size += p->count * RELOC_SIZE (htab); |
9524 | 0 | if ((p->sec->output_section->flags & SEC_READONLY) != 0) |
9525 | 0 | info->flags |= DF_TEXTREL; |
9526 | 0 | } |
9527 | 0 | } |
9528 | 0 | } |
9529 | |
|
9530 | 0 | locals = elf_aarch64_locals (ibfd); |
9531 | 0 | if (!locals) |
9532 | 0 | continue; |
9533 | | |
9534 | 0 | symtab_hdr = &elf_symtab_hdr (ibfd); |
9535 | 0 | srel = htab->root.srelgot; |
9536 | 0 | for (i = 0; i < symtab_hdr->sh_info; i++) |
9537 | 0 | { |
9538 | 0 | locals[i].got_offset = (bfd_vma) - 1; |
9539 | 0 | locals[i].tlsdesc_got_jump_table_offset = (bfd_vma) - 1; |
9540 | 0 | if (locals[i].got_refcount > 0) |
9541 | 0 | { |
9542 | 0 | unsigned got_type = locals[i].got_type; |
9543 | 0 | if (got_type & GOT_TLSDESC_GD) |
9544 | 0 | { |
9545 | 0 | locals[i].tlsdesc_got_jump_table_offset = |
9546 | 0 | (htab->root.sgotplt->size |
9547 | 0 | - aarch64_compute_jump_table_size (htab)); |
9548 | 0 | htab->root.sgotplt->size += GOT_ENTRY_SIZE * 2; |
9549 | 0 | locals[i].got_offset = (bfd_vma) - 2; |
9550 | 0 | } |
9551 | |
|
9552 | 0 | if (got_type & GOT_TLS_GD) |
9553 | 0 | { |
9554 | 0 | locals[i].got_offset = htab->root.sgot->size; |
9555 | 0 | htab->root.sgot->size += GOT_ENTRY_SIZE * 2; |
9556 | 0 | } |
9557 | |
|
9558 | 0 | if (got_type & GOT_TLS_IE |
9559 | 0 | || got_type & GOT_NORMAL) |
9560 | 0 | { |
9561 | 0 | locals[i].got_offset = htab->root.sgot->size; |
9562 | 0 | htab->root.sgot->size += GOT_ENTRY_SIZE; |
9563 | 0 | } |
9564 | |
|
9565 | 0 | if (got_type == GOT_UNKNOWN) |
9566 | 0 | { |
9567 | 0 | } |
9568 | |
|
9569 | 0 | if (bfd_link_pic (info)) |
9570 | 0 | { |
9571 | 0 | if (got_type & GOT_TLSDESC_GD) |
9572 | 0 | { |
9573 | 0 | htab->root.srelplt->size += RELOC_SIZE (htab); |
9574 | | /* Note RELOC_COUNT not incremented here! */ |
9575 | 0 | htab->root.tlsdesc_plt = (bfd_vma) - 1; |
9576 | 0 | } |
9577 | |
|
9578 | 0 | if (got_type & GOT_TLS_GD) |
9579 | 0 | htab->root.srelgot->size += RELOC_SIZE (htab) * 2; |
9580 | |
|
9581 | 0 | if (got_type & GOT_TLS_IE |
9582 | 0 | || got_type & GOT_NORMAL) |
9583 | 0 | htab->root.srelgot->size += RELOC_SIZE (htab); |
9584 | 0 | } |
9585 | 0 | } |
9586 | 0 | else |
9587 | 0 | { |
9588 | 0 | locals[i].got_refcount = (bfd_vma) - 1; |
9589 | 0 | } |
9590 | 0 | } |
9591 | 0 | } |
9592 | | |
9593 | | |
9594 | | /* Allocate global sym .plt and .got entries, and space for global |
9595 | | sym dynamic relocs. */ |
9596 | 0 | elf_link_hash_traverse (&htab->root, elf64_aarch64_allocate_dynrelocs, |
9597 | 0 | info); |
9598 | | |
9599 | | /* Allocate global ifunc sym .plt and .got entries, and space for global |
9600 | | ifunc sym dynamic relocs. */ |
9601 | 0 | elf_link_hash_traverse (&htab->root, elf64_aarch64_allocate_ifunc_dynrelocs, |
9602 | 0 | info); |
9603 | | |
9604 | | /* Allocate .plt and .got entries, and space for local ifunc symbols. */ |
9605 | 0 | htab_traverse (htab->loc_hash_table, |
9606 | 0 | elf64_aarch64_allocate_local_ifunc_dynrelocs, |
9607 | 0 | info); |
9608 | | |
9609 | | /* For every jump slot reserved in the sgotplt, reloc_count is |
9610 | | incremented. However, when we reserve space for TLS descriptors, |
9611 | | it's not incremented, so in order to compute the space reserved |
9612 | | for them, it suffices to multiply the reloc count by the jump |
9613 | | slot size. */ |
9614 | |
|
9615 | 0 | if (htab->root.srelplt) |
9616 | 0 | htab->sgotplt_jump_table_size = aarch64_compute_jump_table_size (htab); |
9617 | |
|
9618 | 0 | if (htab->root.tlsdesc_plt) |
9619 | 0 | { |
9620 | 0 | if (htab->root.splt->size == 0) |
9621 | 0 | htab->root.splt->size += htab->plt_header_size; |
9622 | | |
9623 | | /* If we're not using lazy TLS relocations, don't generate the |
9624 | | GOT and PLT entry required. */ |
9625 | 0 | if ((info->flags & DF_BIND_NOW)) |
9626 | 0 | htab->root.tlsdesc_plt = 0; |
9627 | 0 | else |
9628 | 0 | { |
9629 | 0 | htab->root.tlsdesc_plt = htab->root.splt->size; |
9630 | 0 | htab->root.splt->size += htab->tlsdesc_plt_entry_size; |
9631 | |
|
9632 | 0 | htab->root.tlsdesc_got = htab->root.sgot->size; |
9633 | 0 | htab->root.sgot->size += GOT_ENTRY_SIZE; |
9634 | 0 | } |
9635 | 0 | } |
9636 | | |
9637 | | /* Record the relative relocations that will be packed and undo the |
9638 | | size allocation for them in .rela.*. The size of .relr.dyn will be |
9639 | | computed later iteratively since it depends on the final layout. */ |
9640 | 0 | if (info->enable_dt_relr && !bfd_link_relocatable (info)) |
9641 | 0 | { |
9642 | 0 | elf_link_hash_traverse (&htab->root, record_relr_dyn_got_relocs, info); |
9643 | |
|
9644 | 0 | for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link.next) |
9645 | 0 | { |
9646 | 0 | if (!is_aarch64_elf (ibfd)) |
9647 | 0 | continue; |
9648 | | |
9649 | 0 | for (s = ibfd->sections; s != NULL; s = s->next) |
9650 | 0 | if (!record_relr_non_got_relocs (ibfd, info, s)) |
9651 | 0 | return false; |
9652 | | |
9653 | 0 | if (!record_relr_local_got_relocs (ibfd, info)) |
9654 | 0 | return false; |
9655 | 0 | } |
9656 | 0 | } |
9657 | | |
9658 | | /* Init mapping symbols information to use later to distingush between |
9659 | | code and data while scanning for errata. */ |
9660 | 0 | if (htab->fix_erratum_835769 || htab->fix_erratum_843419) |
9661 | 0 | for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link.next) |
9662 | 0 | { |
9663 | 0 | if (!is_aarch64_elf (ibfd)) |
9664 | 0 | continue; |
9665 | 0 | bfd_elf64_aarch64_init_maps (ibfd); |
9666 | 0 | } |
9667 | | |
9668 | | /* We now have determined the sizes of the various dynamic sections. |
9669 | | Allocate memory for them. */ |
9670 | 0 | relocs = false; |
9671 | 0 | for (s = dynobj->sections; s != NULL; s = s->next) |
9672 | 0 | { |
9673 | 0 | if ((s->flags & SEC_LINKER_CREATED) == 0) |
9674 | 0 | continue; |
9675 | | |
9676 | 0 | if (s == htab->root.splt |
9677 | 0 | || s == htab->root.sgot |
9678 | 0 | || s == htab->root.sgotplt |
9679 | 0 | || s == htab->root.iplt |
9680 | 0 | || s == htab->root.igotplt |
9681 | 0 | || s == htab->root.sdynbss |
9682 | 0 | || s == htab->root.sdynrelro) |
9683 | 0 | { |
9684 | | /* Strip this section if we don't need it; see the |
9685 | | comment below. */ |
9686 | 0 | } |
9687 | 0 | else if (startswith (bfd_section_name (s), ".rela")) |
9688 | 0 | { |
9689 | 0 | if (s->size != 0 && s != htab->root.srelplt) |
9690 | 0 | relocs = true; |
9691 | | |
9692 | | /* We use the reloc_count field as a counter if we need |
9693 | | to copy relocs into the output file. */ |
9694 | 0 | if (s != htab->root.srelplt) |
9695 | 0 | s->reloc_count = 0; |
9696 | 0 | } |
9697 | 0 | else if (s == htab->root.srelrdyn) |
9698 | 0 | { |
9699 | | /* Remove .relr.dyn based on relr_count, not size, since |
9700 | | it is not sized yet. */ |
9701 | 0 | if (htab->relr_count == 0) |
9702 | 0 | s->flags |= SEC_EXCLUDE; |
9703 | 0 | else |
9704 | | /* Force dynamic tags for relocs even if there are no |
9705 | | .rela* relocs, required for setting DT_TEXTREL. */ |
9706 | 0 | relocs = true; |
9707 | | /* Allocate contents later. */ |
9708 | 0 | continue; |
9709 | 0 | } |
9710 | 0 | else |
9711 | 0 | { |
9712 | | /* It's not one of our sections, so don't allocate space. */ |
9713 | 0 | continue; |
9714 | 0 | } |
9715 | | |
9716 | 0 | if (s->size == 0) |
9717 | 0 | { |
9718 | | /* If we don't need this section, strip it from the |
9719 | | output file. This is mostly to handle .rela.bss and |
9720 | | .rela.plt. We must create both sections in |
9721 | | create_dynamic_sections, because they must be created |
9722 | | before the linker maps input sections to output |
9723 | | sections. The linker does that before |
9724 | | adjust_dynamic_symbol is called, and it is that |
9725 | | function which decides whether anything needs to go |
9726 | | into these sections. */ |
9727 | 0 | s->flags |= SEC_EXCLUDE; |
9728 | 0 | continue; |
9729 | 0 | } |
9730 | | |
9731 | 0 | if ((s->flags & SEC_HAS_CONTENTS) == 0) |
9732 | 0 | continue; |
9733 | | |
9734 | | /* Allocate memory for the section contents. We use bfd_zalloc |
9735 | | here in case unused entries are not reclaimed before the |
9736 | | section's contents are written out. This should not happen, |
9737 | | but this way if it does, we get a R_AARCH64_NONE reloc instead |
9738 | | of garbage. */ |
9739 | 0 | s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->size); |
9740 | 0 | if (s->contents == NULL) |
9741 | 0 | return false; |
9742 | 0 | s->alloced = 1; |
9743 | 0 | } |
9744 | | |
9745 | 0 | if (htab->root.dynamic_sections_created) |
9746 | 0 | { |
9747 | | /* Add some entries to the .dynamic section. We fill in the |
9748 | | values later, in elf64_aarch64_finish_dynamic_sections, but we |
9749 | | must add the entries now so that we get the correct size for |
9750 | | the .dynamic section. The DT_DEBUG entry is filled in by the |
9751 | | dynamic linker and used by the debugger. */ |
9752 | 0 | #define add_dynamic_entry(TAG, VAL) \ |
9753 | 0 | _bfd_elf_add_dynamic_entry (info, TAG, VAL) |
9754 | |
|
9755 | 0 | if (!_bfd_elf_add_dynamic_tags (output_bfd, info, relocs)) |
9756 | 0 | return false; |
9757 | | |
9758 | 0 | if (htab->root.splt->size != 0) |
9759 | 0 | { |
9760 | 0 | if (htab->variant_pcs |
9761 | 0 | && !add_dynamic_entry (DT_AARCH64_VARIANT_PCS, 0)) |
9762 | 0 | return false; |
9763 | | |
9764 | 0 | aarch64_plt_type plt_type |
9765 | 0 | = elf_aarch64_tdata (output_bfd)->sw_protections.plt_type; |
9766 | 0 | if ((plt_type == PLT_BTI_PAC) |
9767 | 0 | && (!add_dynamic_entry (DT_AARCH64_BTI_PLT, 0) |
9768 | 0 | || !add_dynamic_entry (DT_AARCH64_PAC_PLT, 0))) |
9769 | 0 | return false; |
9770 | | |
9771 | 0 | else if ((plt_type == PLT_BTI) |
9772 | 0 | && !add_dynamic_entry (DT_AARCH64_BTI_PLT, 0)) |
9773 | 0 | return false; |
9774 | | |
9775 | 0 | else if ((plt_type == PLT_PAC) |
9776 | 0 | && !add_dynamic_entry (DT_AARCH64_PAC_PLT, 0)) |
9777 | 0 | return false; |
9778 | 0 | } |
9779 | 0 | } |
9780 | 0 | #undef add_dynamic_entry |
9781 | | |
9782 | 0 | return true; |
9783 | 0 | } |
9784 | | |
9785 | | static inline void |
9786 | | elf_aarch64_update_plt_entry (bfd *output_bfd, |
9787 | | bfd_reloc_code_real_type r_type, |
9788 | | bfd_byte *plt_entry, bfd_vma value) |
9789 | 0 | { |
9790 | 0 | reloc_howto_type *howto = elf64_aarch64_howto_from_bfd_reloc (r_type); |
9791 | | |
9792 | | /* FIXME: We should check the return value from this function call. */ |
9793 | 0 | (void) _bfd_aarch64_elf_put_addend (output_bfd, plt_entry, r_type, howto, value); |
9794 | 0 | } |
9795 | | |
9796 | | static void |
9797 | | elf64_aarch64_create_small_pltn_entry (struct elf_link_hash_entry *h, |
9798 | | struct elf_aarch64_link_hash_table |
9799 | | *htab, bfd *output_bfd, |
9800 | | struct bfd_link_info *info) |
9801 | 0 | { |
9802 | 0 | bfd_byte *plt_entry; |
9803 | 0 | bfd_vma plt_index; |
9804 | 0 | bfd_vma got_offset; |
9805 | 0 | bfd_vma gotplt_entry_address; |
9806 | 0 | bfd_vma plt_entry_address; |
9807 | 0 | Elf_Internal_Rela rela; |
9808 | 0 | bfd_byte *loc; |
9809 | 0 | asection *plt, *gotplt, *relplt; |
9810 | | |
9811 | | /* When building a static executable, use .iplt, .igot.plt and |
9812 | | .rela.iplt sections for STT_GNU_IFUNC symbols. */ |
9813 | 0 | if (htab->root.splt != NULL) |
9814 | 0 | { |
9815 | 0 | plt = htab->root.splt; |
9816 | 0 | gotplt = htab->root.sgotplt; |
9817 | 0 | relplt = htab->root.srelplt; |
9818 | 0 | } |
9819 | 0 | else |
9820 | 0 | { |
9821 | 0 | plt = htab->root.iplt; |
9822 | 0 | gotplt = htab->root.igotplt; |
9823 | 0 | relplt = htab->root.irelplt; |
9824 | 0 | } |
9825 | | |
9826 | | /* Get the index in the procedure linkage table which |
9827 | | corresponds to this symbol. This is the index of this symbol |
9828 | | in all the symbols for which we are making plt entries. The |
9829 | | first entry in the procedure linkage table is reserved. |
9830 | | |
9831 | | Get the offset into the .got table of the entry that |
9832 | | corresponds to this function. Each .got entry is GOT_ENTRY_SIZE |
9833 | | bytes. The first three are reserved for the dynamic linker. |
9834 | | |
9835 | | For static executables, we don't reserve anything. */ |
9836 | |
|
9837 | 0 | if (plt == htab->root.splt) |
9838 | 0 | { |
9839 | 0 | plt_index = (h->plt.offset - htab->plt_header_size) / htab->plt_entry_size; |
9840 | 0 | got_offset = (plt_index + 3) * GOT_ENTRY_SIZE; |
9841 | 0 | } |
9842 | 0 | else |
9843 | 0 | { |
9844 | 0 | plt_index = h->plt.offset / htab->plt_entry_size; |
9845 | 0 | got_offset = plt_index * GOT_ENTRY_SIZE; |
9846 | 0 | } |
9847 | |
|
9848 | 0 | plt_entry = plt->contents + h->plt.offset; |
9849 | 0 | plt_entry_address = plt->output_section->vma |
9850 | 0 | + plt->output_offset + h->plt.offset; |
9851 | 0 | gotplt_entry_address = gotplt->output_section->vma + |
9852 | 0 | gotplt->output_offset + got_offset; |
9853 | | |
9854 | | /* Copy in the boiler-plate for the PLTn entry. */ |
9855 | 0 | memcpy (plt_entry, htab->plt_entry, htab->plt_entry_size); |
9856 | | |
9857 | | /* Allow for any delta (such as a BTI instruction) before the common |
9858 | | sequence. */ |
9859 | 0 | plt_entry += htab->plt_entry_delta; |
9860 | | |
9861 | | /* Fill in the top 21 bits for this: ADRP x16, PLT_GOT + n * 8. |
9862 | | ADRP: ((PG(S+A)-PG(P)) >> 12) & 0x1fffff */ |
9863 | 0 | elf_aarch64_update_plt_entry (output_bfd, BFD_RELOC_AARCH64_ADR_HI21_PCREL, |
9864 | 0 | plt_entry, |
9865 | 0 | PG (gotplt_entry_address) - |
9866 | 0 | PG (plt_entry_address)); |
9867 | | |
9868 | | /* Fill in the lo12 bits for the load from the pltgot. */ |
9869 | 0 | elf_aarch64_update_plt_entry (output_bfd, BFD_RELOC_AARCH64_LDST64_LO12, |
9870 | 0 | plt_entry + 4, |
9871 | 0 | PG_OFFSET (gotplt_entry_address)); |
9872 | | |
9873 | | /* Fill in the lo12 bits for the add from the pltgot entry. */ |
9874 | 0 | elf_aarch64_update_plt_entry (output_bfd, BFD_RELOC_AARCH64_ADD_LO12, |
9875 | 0 | plt_entry + 8, |
9876 | 0 | PG_OFFSET (gotplt_entry_address)); |
9877 | | |
9878 | | /* All the GOTPLT Entries are essentially initialized to PLT0. */ |
9879 | 0 | bfd_put_64 (output_bfd, |
9880 | 0 | plt->output_section->vma + plt->output_offset, |
9881 | 0 | gotplt->contents + got_offset); |
9882 | |
|
9883 | 0 | rela.r_offset = gotplt_entry_address; |
9884 | |
|
9885 | 0 | if (h->dynindx == -1 |
9886 | 0 | || ((bfd_link_executable (info) |
9887 | 0 | || ELF_ST_VISIBILITY (h->other) != STV_DEFAULT) |
9888 | 0 | && h->def_regular |
9889 | 0 | && h->type == STT_GNU_IFUNC)) |
9890 | 0 | { |
9891 | | /* If an STT_GNU_IFUNC symbol is locally defined, generate |
9892 | | R_AARCH64_IRELATIVE instead of R_AARCH64_JUMP_SLOT. */ |
9893 | 0 | rela.r_info = ELF64_R_INFO (0, AARCH64_R (IRELATIVE)); |
9894 | 0 | rela.r_addend = (h->root.u.def.value |
9895 | 0 | + h->root.u.def.section->output_section->vma |
9896 | 0 | + h->root.u.def.section->output_offset); |
9897 | 0 | } |
9898 | 0 | else |
9899 | 0 | { |
9900 | | /* Fill in the entry in the .rela.plt section. */ |
9901 | 0 | rela.r_info = ELF64_R_INFO (h->dynindx, AARCH64_R (JUMP_SLOT)); |
9902 | 0 | rela.r_addend = 0; |
9903 | 0 | } |
9904 | | |
9905 | | /* Compute the relocation entry to used based on PLT index and do |
9906 | | not adjust reloc_count. The reloc_count has already been adjusted |
9907 | | to account for this entry. */ |
9908 | 0 | loc = relplt->contents + plt_index * RELOC_SIZE (htab); |
9909 | 0 | bfd_elf64_swap_reloca_out (output_bfd, &rela, loc); |
9910 | 0 | } |
9911 | | |
9912 | | /* Size sections even though they're not dynamic. We use it to setup |
9913 | | _TLS_MODULE_BASE_, if needed. */ |
9914 | | |
9915 | | static bool |
9916 | | elf64_aarch64_early_size_sections (bfd *output_bfd, |
9917 | | struct bfd_link_info *info) |
9918 | 0 | { |
9919 | 0 | asection *tls_sec; |
9920 | |
|
9921 | 0 | if (bfd_link_relocatable (info)) |
9922 | 0 | return true; |
9923 | | |
9924 | 0 | tls_sec = elf_hash_table (info)->tls_sec; |
9925 | |
|
9926 | 0 | if (tls_sec) |
9927 | 0 | { |
9928 | 0 | struct elf_link_hash_entry *tlsbase; |
9929 | |
|
9930 | 0 | tlsbase = elf_link_hash_lookup (elf_hash_table (info), |
9931 | 0 | "_TLS_MODULE_BASE_", true, true, false); |
9932 | |
|
9933 | 0 | if (tlsbase) |
9934 | 0 | { |
9935 | 0 | struct bfd_link_hash_entry *h = NULL; |
9936 | 0 | const struct elf_backend_data *bed = |
9937 | 0 | get_elf_backend_data (output_bfd); |
9938 | |
|
9939 | 0 | if (!(_bfd_generic_link_add_one_symbol |
9940 | 0 | (info, output_bfd, "_TLS_MODULE_BASE_", BSF_LOCAL, |
9941 | 0 | tls_sec, 0, NULL, false, bed->collect, &h))) |
9942 | 0 | return false; |
9943 | | |
9944 | 0 | tlsbase->type = STT_TLS; |
9945 | 0 | tlsbase = (struct elf_link_hash_entry *) h; |
9946 | 0 | tlsbase->def_regular = 1; |
9947 | 0 | tlsbase->other = STV_HIDDEN; |
9948 | 0 | (*bed->elf_backend_hide_symbol) (info, tlsbase, true); |
9949 | 0 | } |
9950 | 0 | } |
9951 | | |
9952 | 0 | return true; |
9953 | 0 | } |
9954 | | |
9955 | | /* Finish up dynamic symbol handling. We set the contents of various |
9956 | | dynamic sections here. */ |
9957 | | |
9958 | | static bool |
9959 | | elf64_aarch64_finish_dynamic_symbol (bfd *output_bfd, |
9960 | | struct bfd_link_info *info, |
9961 | | struct elf_link_hash_entry *h, |
9962 | | Elf_Internal_Sym *sym) |
9963 | 0 | { |
9964 | 0 | struct elf_aarch64_link_hash_table *htab; |
9965 | 0 | htab = elf_aarch64_hash_table (info); |
9966 | |
|
9967 | 0 | if (h->plt.offset != (bfd_vma) - 1) |
9968 | 0 | { |
9969 | 0 | asection *plt, *gotplt, *relplt; |
9970 | | |
9971 | | /* This symbol has an entry in the procedure linkage table. Set |
9972 | | it up. */ |
9973 | | |
9974 | | /* When building a static executable, use .iplt, .igot.plt and |
9975 | | .rela.iplt sections for STT_GNU_IFUNC symbols. */ |
9976 | 0 | if (htab->root.splt != NULL) |
9977 | 0 | { |
9978 | 0 | plt = htab->root.splt; |
9979 | 0 | gotplt = htab->root.sgotplt; |
9980 | 0 | relplt = htab->root.srelplt; |
9981 | 0 | } |
9982 | 0 | else |
9983 | 0 | { |
9984 | 0 | plt = htab->root.iplt; |
9985 | 0 | gotplt = htab->root.igotplt; |
9986 | 0 | relplt = htab->root.irelplt; |
9987 | 0 | } |
9988 | | |
9989 | | /* This symbol has an entry in the procedure linkage table. Set |
9990 | | it up. */ |
9991 | 0 | if ((h->dynindx == -1 |
9992 | 0 | && !((h->forced_local || bfd_link_executable (info)) |
9993 | 0 | && h->def_regular |
9994 | 0 | && h->type == STT_GNU_IFUNC)) |
9995 | 0 | || plt == NULL |
9996 | 0 | || gotplt == NULL |
9997 | 0 | || relplt == NULL) |
9998 | 0 | abort (); |
9999 | | |
10000 | 0 | elf64_aarch64_create_small_pltn_entry (h, htab, output_bfd, info); |
10001 | 0 | if (!h->def_regular) |
10002 | 0 | { |
10003 | | /* Mark the symbol as undefined, rather than as defined in |
10004 | | the .plt section. */ |
10005 | 0 | sym->st_shndx = SHN_UNDEF; |
10006 | | /* If the symbol is weak we need to clear the value. |
10007 | | Otherwise, the PLT entry would provide a definition for |
10008 | | the symbol even if the symbol wasn't defined anywhere, |
10009 | | and so the symbol would never be NULL. Leave the value if |
10010 | | there were any relocations where pointer equality matters |
10011 | | (this is a clue for the dynamic linker, to make function |
10012 | | pointer comparisons work between an application and shared |
10013 | | library). */ |
10014 | 0 | if (!h->ref_regular_nonweak || !h->pointer_equality_needed) |
10015 | 0 | sym->st_value = 0; |
10016 | 0 | } |
10017 | 0 | } |
10018 | | |
10019 | 0 | if (h->got.offset != (bfd_vma) - 1 |
10020 | 0 | && elf_aarch64_hash_entry (h)->got_type == GOT_NORMAL |
10021 | | /* Undefined weak symbol in static PIE resolves to 0 without |
10022 | | any dynamic relocations. */ |
10023 | 0 | && !UNDEFWEAK_NO_DYNAMIC_RELOC (info, h)) |
10024 | 0 | { |
10025 | 0 | Elf_Internal_Rela rela; |
10026 | 0 | bfd_byte *loc; |
10027 | | |
10028 | | /* This symbol has an entry in the global offset table. Set it |
10029 | | up. */ |
10030 | 0 | if (htab->root.sgot == NULL || htab->root.srelgot == NULL) |
10031 | 0 | abort (); |
10032 | | |
10033 | 0 | rela.r_offset = (htab->root.sgot->output_section->vma |
10034 | 0 | + htab->root.sgot->output_offset |
10035 | 0 | + (h->got.offset & ~(bfd_vma) 1)); |
10036 | |
|
10037 | 0 | if (h->def_regular |
10038 | 0 | && h->type == STT_GNU_IFUNC) |
10039 | 0 | { |
10040 | 0 | if (bfd_link_pic (info)) |
10041 | 0 | { |
10042 | | /* Generate R_AARCH64_GLOB_DAT. */ |
10043 | 0 | goto do_glob_dat; |
10044 | 0 | } |
10045 | 0 | else |
10046 | 0 | { |
10047 | 0 | asection *plt; |
10048 | |
|
10049 | 0 | if (!h->pointer_equality_needed) |
10050 | 0 | abort (); |
10051 | | |
10052 | | /* For non-shared object, we can't use .got.plt, which |
10053 | | contains the real function address if we need pointer |
10054 | | equality. We load the GOT entry with the PLT entry. */ |
10055 | 0 | plt = htab->root.splt ? htab->root.splt : htab->root.iplt; |
10056 | 0 | bfd_put_64 (output_bfd, (plt->output_section->vma |
10057 | 0 | + plt->output_offset |
10058 | 0 | + h->plt.offset), |
10059 | 0 | htab->root.sgot->contents |
10060 | 0 | + (h->got.offset & ~(bfd_vma) 1)); |
10061 | 0 | return true; |
10062 | 0 | } |
10063 | 0 | } |
10064 | 0 | else if (bfd_link_pic (info) && SYMBOL_REFERENCES_LOCAL (info, h)) |
10065 | 0 | { |
10066 | 0 | if (!(h->def_regular || ELF_COMMON_DEF_P (h))) |
10067 | 0 | return false; |
10068 | 0 | BFD_ASSERT ((h->got.offset & 1) != 0); |
10069 | | /* Don't emit relative relocs if they are packed. */ |
10070 | 0 | if (info->enable_dt_relr) |
10071 | 0 | goto skip_got_reloc; |
10072 | 0 | rela.r_info = ELF64_R_INFO (0, AARCH64_R (RELATIVE)); |
10073 | 0 | rela.r_addend = (h->root.u.def.value |
10074 | 0 | + h->root.u.def.section->output_section->vma |
10075 | 0 | + h->root.u.def.section->output_offset); |
10076 | 0 | } |
10077 | 0 | else |
10078 | 0 | { |
10079 | 0 | do_glob_dat: |
10080 | 0 | BFD_ASSERT ((h->got.offset & 1) == 0); |
10081 | 0 | bfd_put_64 (output_bfd, (bfd_vma) 0, |
10082 | 0 | htab->root.sgot->contents + h->got.offset); |
10083 | 0 | rela.r_info = ELF64_R_INFO (h->dynindx, AARCH64_R (GLOB_DAT)); |
10084 | 0 | rela.r_addend = 0; |
10085 | 0 | } |
10086 | | |
10087 | 0 | loc = htab->root.srelgot->contents; |
10088 | 0 | loc += htab->root.srelgot->reloc_count++ * RELOC_SIZE (htab); |
10089 | 0 | bfd_elf64_swap_reloca_out (output_bfd, &rela, loc); |
10090 | 0 | } |
10091 | 0 | skip_got_reloc: |
10092 | |
|
10093 | 0 | if (h->needs_copy) |
10094 | 0 | { |
10095 | 0 | Elf_Internal_Rela rela; |
10096 | 0 | asection *s; |
10097 | 0 | bfd_byte *loc; |
10098 | | |
10099 | | /* This symbol needs a copy reloc. Set it up. */ |
10100 | 0 | if (h->dynindx == -1 |
10101 | 0 | || (h->root.type != bfd_link_hash_defined |
10102 | 0 | && h->root.type != bfd_link_hash_defweak) |
10103 | 0 | || htab->root.srelbss == NULL) |
10104 | 0 | abort (); |
10105 | | |
10106 | 0 | rela.r_offset = (h->root.u.def.value |
10107 | 0 | + h->root.u.def.section->output_section->vma |
10108 | 0 | + h->root.u.def.section->output_offset); |
10109 | 0 | rela.r_info = ELF64_R_INFO (h->dynindx, AARCH64_R (COPY)); |
10110 | 0 | rela.r_addend = 0; |
10111 | 0 | if (h->root.u.def.section == htab->root.sdynrelro) |
10112 | 0 | s = htab->root.sreldynrelro; |
10113 | 0 | else |
10114 | 0 | s = htab->root.srelbss; |
10115 | 0 | loc = s->contents + s->reloc_count++ * RELOC_SIZE (htab); |
10116 | 0 | bfd_elf64_swap_reloca_out (output_bfd, &rela, loc); |
10117 | 0 | } |
10118 | | |
10119 | | /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. SYM may |
10120 | | be NULL for local symbols. */ |
10121 | 0 | if (sym != NULL |
10122 | 0 | && (h == elf_hash_table (info)->hdynamic |
10123 | 0 | || h == elf_hash_table (info)->hgot)) |
10124 | 0 | sym->st_shndx = SHN_ABS; |
10125 | |
|
10126 | 0 | return true; |
10127 | 0 | } |
10128 | | |
10129 | | /* Finish up local dynamic symbol handling. We set the contents of |
10130 | | various dynamic sections here. */ |
10131 | | |
10132 | | static int |
10133 | | elf64_aarch64_finish_local_dynamic_symbol (void **slot, void *inf) |
10134 | 0 | { |
10135 | 0 | struct elf_link_hash_entry *h |
10136 | 0 | = (struct elf_link_hash_entry *) *slot; |
10137 | 0 | struct bfd_link_info *info |
10138 | 0 | = (struct bfd_link_info *) inf; |
10139 | |
|
10140 | 0 | return elf64_aarch64_finish_dynamic_symbol (info->output_bfd, |
10141 | 0 | info, h, NULL); |
10142 | 0 | } |
10143 | | |
10144 | | static void |
10145 | | elf64_aarch64_init_small_plt0_entry (bfd *output_bfd ATTRIBUTE_UNUSED, |
10146 | | struct elf_aarch64_link_hash_table |
10147 | | *htab) |
10148 | 0 | { |
10149 | | /* Fill in PLT0. Fixme:RR Note this doesn't distinguish between |
10150 | | small and large plts and at the minute just generates |
10151 | | the small PLT. */ |
10152 | | |
10153 | | /* PLT0 of the small PLT looks like this in ELF64 - |
10154 | | stp x16, x30, [sp, #-16]! // Save the reloc and lr on stack. |
10155 | | adrp x16, PLT_GOT + 16 // Get the page base of the GOTPLT |
10156 | | ldr x17, [x16, #:lo12:PLT_GOT+16] // Load the address of the |
10157 | | // symbol resolver |
10158 | | add x16, x16, #:lo12:PLT_GOT+16 // Load the lo12 bits of the |
10159 | | // GOTPLT entry for this. |
10160 | | br x17 |
10161 | | PLT0 will be slightly different in ELF32 due to different got entry |
10162 | | size. */ |
10163 | 0 | bfd_vma plt_got_2nd_ent; /* Address of GOT[2]. */ |
10164 | 0 | bfd_vma plt_base; |
10165 | | |
10166 | |
|
10167 | 0 | memcpy (htab->root.splt->contents, htab->plt0_entry, |
10168 | 0 | htab->plt_header_size); |
10169 | | |
10170 | | /* PR 26312: Explicitly set the sh_entsize to 0 so that |
10171 | | consumers do not think that the section contains fixed |
10172 | | sized objects. */ |
10173 | 0 | elf_section_data (htab->root.splt->output_section)->this_hdr.sh_entsize = 0; |
10174 | |
|
10175 | 0 | plt_got_2nd_ent = (htab->root.sgotplt->output_section->vma |
10176 | 0 | + htab->root.sgotplt->output_offset |
10177 | 0 | + GOT_ENTRY_SIZE * 2); |
10178 | |
|
10179 | 0 | plt_base = htab->root.splt->output_section->vma + |
10180 | 0 | htab->root.splt->output_offset; |
10181 | | |
10182 | | /* First instruction in BTI enabled PLT stub is a BTI |
10183 | | instruction so skip it. */ |
10184 | 0 | bfd_byte *plt0_entry = htab->root.splt->contents; |
10185 | 0 | if (elf_aarch64_tdata (output_bfd)->sw_protections.plt_type & PLT_BTI) |
10186 | 0 | plt0_entry = plt0_entry + 4; |
10187 | | |
10188 | | /* Fill in the top 21 bits for this: ADRP x16, PLT_GOT + n * 8. |
10189 | | ADRP: ((PG(S+A)-PG(P)) >> 12) & 0x1fffff */ |
10190 | 0 | elf_aarch64_update_plt_entry (output_bfd, BFD_RELOC_AARCH64_ADR_HI21_PCREL, |
10191 | 0 | plt0_entry + 4, |
10192 | 0 | PG (plt_got_2nd_ent) - PG (plt_base + 4)); |
10193 | |
|
10194 | 0 | elf_aarch64_update_plt_entry (output_bfd, BFD_RELOC_AARCH64_LDST64_LO12, |
10195 | 0 | plt0_entry + 8, |
10196 | 0 | PG_OFFSET (plt_got_2nd_ent)); |
10197 | |
|
10198 | 0 | elf_aarch64_update_plt_entry (output_bfd, BFD_RELOC_AARCH64_ADD_LO12, |
10199 | 0 | plt0_entry + 12, |
10200 | 0 | PG_OFFSET (plt_got_2nd_ent)); |
10201 | 0 | } |
10202 | | |
10203 | | static bool |
10204 | | elf64_aarch64_finish_dynamic_sections (bfd *output_bfd, |
10205 | | struct bfd_link_info *info) |
10206 | 0 | { |
10207 | 0 | struct elf_aarch64_link_hash_table *htab; |
10208 | 0 | bfd *dynobj; |
10209 | 0 | asection *sdyn; |
10210 | |
|
10211 | 0 | htab = elf_aarch64_hash_table (info); |
10212 | 0 | dynobj = htab->root.dynobj; |
10213 | 0 | sdyn = bfd_get_linker_section (dynobj, ".dynamic"); |
10214 | |
|
10215 | 0 | if (htab->root.dynamic_sections_created) |
10216 | 0 | { |
10217 | 0 | Elf64_External_Dyn *dyncon, *dynconend; |
10218 | |
|
10219 | 0 | if (sdyn == NULL || htab->root.sgot == NULL) |
10220 | 0 | abort (); |
10221 | | |
10222 | 0 | dyncon = (Elf64_External_Dyn *) sdyn->contents; |
10223 | 0 | dynconend = (Elf64_External_Dyn *) (sdyn->contents + sdyn->size); |
10224 | 0 | for (; dyncon < dynconend; dyncon++) |
10225 | 0 | { |
10226 | 0 | Elf_Internal_Dyn dyn; |
10227 | 0 | asection *s; |
10228 | |
|
10229 | 0 | bfd_elf64_swap_dyn_in (dynobj, dyncon, &dyn); |
10230 | |
|
10231 | 0 | switch (dyn.d_tag) |
10232 | 0 | { |
10233 | 0 | default: |
10234 | 0 | continue; |
10235 | | |
10236 | 0 | case DT_PLTGOT: |
10237 | 0 | s = htab->root.sgotplt; |
10238 | 0 | dyn.d_un.d_ptr = s->output_section->vma + s->output_offset; |
10239 | 0 | break; |
10240 | | |
10241 | 0 | case DT_JMPREL: |
10242 | 0 | s = htab->root.srelplt; |
10243 | 0 | dyn.d_un.d_ptr = s->output_section->vma + s->output_offset; |
10244 | 0 | break; |
10245 | | |
10246 | 0 | case DT_PLTRELSZ: |
10247 | 0 | s = htab->root.srelplt; |
10248 | 0 | dyn.d_un.d_val = s->size; |
10249 | 0 | break; |
10250 | | |
10251 | 0 | case DT_TLSDESC_PLT: |
10252 | 0 | s = htab->root.splt; |
10253 | 0 | dyn.d_un.d_ptr = s->output_section->vma + s->output_offset |
10254 | 0 | + htab->root.tlsdesc_plt; |
10255 | 0 | break; |
10256 | | |
10257 | 0 | case DT_TLSDESC_GOT: |
10258 | 0 | s = htab->root.sgot; |
10259 | 0 | BFD_ASSERT (htab->root.tlsdesc_got != (bfd_vma)-1); |
10260 | 0 | dyn.d_un.d_ptr = s->output_section->vma + s->output_offset |
10261 | 0 | + htab->root.tlsdesc_got; |
10262 | 0 | break; |
10263 | 0 | } |
10264 | | |
10265 | 0 | bfd_elf64_swap_dyn_out (output_bfd, &dyn, dyncon); |
10266 | 0 | } |
10267 | |
|
10268 | 0 | } |
10269 | | |
10270 | | /* Fill in the special first entry in the procedure linkage table. */ |
10271 | 0 | if (htab->root.splt && htab->root.splt->size > 0) |
10272 | 0 | { |
10273 | 0 | elf64_aarch64_init_small_plt0_entry (output_bfd, htab); |
10274 | |
|
10275 | 0 | if (htab->root.tlsdesc_plt && !(info->flags & DF_BIND_NOW)) |
10276 | 0 | { |
10277 | 0 | BFD_ASSERT (htab->root.tlsdesc_got != (bfd_vma)-1); |
10278 | 0 | bfd_put_64 (output_bfd, (bfd_vma) 0, |
10279 | 0 | htab->root.sgot->contents + htab->root.tlsdesc_got); |
10280 | |
|
10281 | 0 | const bfd_byte *entry = elf64_aarch64_tlsdesc_small_plt_entry; |
10282 | 0 | htab->tlsdesc_plt_entry_size = PLT_TLSDESC_ENTRY_SIZE; |
10283 | |
|
10284 | 0 | aarch64_plt_type type |
10285 | 0 | = elf_aarch64_tdata (output_bfd)->sw_protections.plt_type; |
10286 | 0 | if (type == PLT_BTI || type == PLT_BTI_PAC) |
10287 | 0 | { |
10288 | 0 | entry = elf64_aarch64_tlsdesc_small_plt_bti_entry; |
10289 | 0 | } |
10290 | |
|
10291 | 0 | memcpy (htab->root.splt->contents + htab->root.tlsdesc_plt, |
10292 | 0 | entry, htab->tlsdesc_plt_entry_size); |
10293 | |
|
10294 | 0 | { |
10295 | 0 | bfd_vma adrp1_addr = |
10296 | 0 | htab->root.splt->output_section->vma |
10297 | 0 | + htab->root.splt->output_offset |
10298 | 0 | + htab->root.tlsdesc_plt + 4; |
10299 | |
|
10300 | 0 | bfd_vma adrp2_addr = adrp1_addr + 4; |
10301 | |
|
10302 | 0 | bfd_vma got_addr = |
10303 | 0 | htab->root.sgot->output_section->vma |
10304 | 0 | + htab->root.sgot->output_offset; |
10305 | |
|
10306 | 0 | bfd_vma pltgot_addr = |
10307 | 0 | htab->root.sgotplt->output_section->vma |
10308 | 0 | + htab->root.sgotplt->output_offset; |
10309 | |
|
10310 | 0 | bfd_vma dt_tlsdesc_got = got_addr + htab->root.tlsdesc_got; |
10311 | |
|
10312 | 0 | bfd_byte *plt_entry = |
10313 | 0 | htab->root.splt->contents + htab->root.tlsdesc_plt; |
10314 | | |
10315 | | /* First instruction in BTI enabled PLT stub is a BTI |
10316 | | instruction so skip it. */ |
10317 | 0 | if (type & PLT_BTI) |
10318 | 0 | { |
10319 | 0 | plt_entry = plt_entry + 4; |
10320 | 0 | adrp1_addr = adrp1_addr + 4; |
10321 | 0 | adrp2_addr = adrp2_addr + 4; |
10322 | 0 | } |
10323 | | |
10324 | | /* adrp x2, DT_TLSDESC_GOT */ |
10325 | 0 | elf_aarch64_update_plt_entry (output_bfd, |
10326 | 0 | BFD_RELOC_AARCH64_ADR_HI21_PCREL, |
10327 | 0 | plt_entry + 4, |
10328 | 0 | (PG (dt_tlsdesc_got) |
10329 | 0 | - PG (adrp1_addr))); |
10330 | | |
10331 | | /* adrp x3, 0 */ |
10332 | 0 | elf_aarch64_update_plt_entry (output_bfd, |
10333 | 0 | BFD_RELOC_AARCH64_ADR_HI21_PCREL, |
10334 | 0 | plt_entry + 8, |
10335 | 0 | (PG (pltgot_addr) |
10336 | 0 | - PG (adrp2_addr))); |
10337 | | |
10338 | | /* ldr x2, [x2, #0] */ |
10339 | 0 | elf_aarch64_update_plt_entry (output_bfd, |
10340 | 0 | BFD_RELOC_AARCH64_LDST64_LO12, |
10341 | 0 | plt_entry + 12, |
10342 | 0 | PG_OFFSET (dt_tlsdesc_got)); |
10343 | | |
10344 | | /* add x3, x3, 0 */ |
10345 | 0 | elf_aarch64_update_plt_entry (output_bfd, |
10346 | 0 | BFD_RELOC_AARCH64_ADD_LO12, |
10347 | 0 | plt_entry + 16, |
10348 | 0 | PG_OFFSET (pltgot_addr)); |
10349 | 0 | } |
10350 | 0 | } |
10351 | 0 | } |
10352 | |
|
10353 | 0 | if (htab->root.sgotplt) |
10354 | 0 | { |
10355 | 0 | if (bfd_is_abs_section (htab->root.sgotplt->output_section)) |
10356 | 0 | { |
10357 | 0 | _bfd_error_handler |
10358 | 0 | (_("discarded output section: `%pA'"), htab->root.sgotplt); |
10359 | 0 | return false; |
10360 | 0 | } |
10361 | | |
10362 | | /* Fill in the first three entries in the global offset table. */ |
10363 | 0 | if (htab->root.sgotplt->size > 0) |
10364 | 0 | { |
10365 | 0 | bfd_put_64 (output_bfd, (bfd_vma) 0, htab->root.sgotplt->contents); |
10366 | | |
10367 | | /* Write GOT[1] and GOT[2], needed for the dynamic linker. */ |
10368 | 0 | bfd_put_64 (output_bfd, |
10369 | 0 | (bfd_vma) 0, |
10370 | 0 | htab->root.sgotplt->contents + GOT_ENTRY_SIZE); |
10371 | 0 | bfd_put_64 (output_bfd, |
10372 | 0 | (bfd_vma) 0, |
10373 | 0 | htab->root.sgotplt->contents + GOT_ENTRY_SIZE * 2); |
10374 | 0 | } |
10375 | |
|
10376 | 0 | if (htab->root.sgot) |
10377 | 0 | { |
10378 | 0 | if (htab->root.sgot->size > 0) |
10379 | 0 | { |
10380 | 0 | bfd_vma addr = |
10381 | 0 | sdyn ? sdyn->output_section->vma + sdyn->output_offset : 0; |
10382 | 0 | bfd_put_64 (output_bfd, addr, htab->root.sgot->contents); |
10383 | 0 | } |
10384 | 0 | } |
10385 | |
|
10386 | 0 | elf_section_data (htab->root.sgotplt->output_section)-> |
10387 | 0 | this_hdr.sh_entsize = GOT_ENTRY_SIZE; |
10388 | 0 | } |
10389 | | |
10390 | 0 | if (htab->root.sgot && htab->root.sgot->size > 0) |
10391 | 0 | elf_section_data (htab->root.sgot->output_section)->this_hdr.sh_entsize |
10392 | 0 | = GOT_ENTRY_SIZE; |
10393 | | |
10394 | | /* Fill PLT and GOT entries for local STT_GNU_IFUNC symbols. */ |
10395 | 0 | htab_traverse (htab->loc_hash_table, |
10396 | 0 | elf64_aarch64_finish_local_dynamic_symbol, |
10397 | 0 | info); |
10398 | |
|
10399 | 0 | return true; |
10400 | 0 | } |
10401 | | |
10402 | | /* Check if BTI enabled PLTs are needed. Returns the type needed. */ |
10403 | | static aarch64_plt_type |
10404 | | get_plt_type (bfd *abfd) |
10405 | 8 | { |
10406 | 8 | aarch64_plt_type ret = PLT_NORMAL; |
10407 | 8 | bfd_byte *contents, *extdyn, *extdynend; |
10408 | 8 | asection *sec = bfd_get_section_by_name (abfd, ".dynamic"); |
10409 | 8 | if (!sec |
10410 | 8 | || (sec->flags & SEC_HAS_CONTENTS) == 0 |
10411 | 8 | || sec->size < sizeof (Elf64_External_Dyn) |
10412 | 8 | || !bfd_malloc_and_get_section (abfd, sec, &contents)) |
10413 | 1 | return ret; |
10414 | 7 | extdyn = contents; |
10415 | 7 | extdynend = contents + sec->size - sizeof (Elf64_External_Dyn); |
10416 | 222 | for (; extdyn <= extdynend; extdyn += sizeof (Elf64_External_Dyn)) |
10417 | 215 | { |
10418 | 215 | Elf_Internal_Dyn dyn; |
10419 | 215 | bfd_elf64_swap_dyn_in (abfd, extdyn, &dyn); |
10420 | | |
10421 | | /* Let's check the processor specific dynamic array tags. */ |
10422 | 215 | bfd_vma tag = dyn.d_tag; |
10423 | 215 | if (tag < DT_LOPROC || tag > DT_HIPROC) |
10424 | 215 | continue; |
10425 | | |
10426 | 0 | switch (tag) |
10427 | 0 | { |
10428 | 0 | case DT_AARCH64_BTI_PLT: |
10429 | 0 | ret |= PLT_BTI; |
10430 | 0 | break; |
10431 | | |
10432 | 0 | case DT_AARCH64_PAC_PLT: |
10433 | 0 | ret |= PLT_PAC; |
10434 | 0 | break; |
10435 | | |
10436 | 0 | default: break; |
10437 | 0 | } |
10438 | 0 | } |
10439 | 7 | free (contents); |
10440 | 7 | return ret; |
10441 | 7 | } |
10442 | | |
10443 | | static long |
10444 | | elf64_aarch64_get_synthetic_symtab (bfd *abfd, |
10445 | | long symcount, |
10446 | | asymbol **syms, |
10447 | | long dynsymcount, |
10448 | | asymbol **dynsyms, |
10449 | | asymbol **ret) |
10450 | 8 | { |
10451 | 8 | elf_aarch64_tdata (abfd)->sw_protections.plt_type = get_plt_type (abfd); |
10452 | 8 | return _bfd_elf_get_synthetic_symtab (abfd, symcount, syms, |
10453 | 8 | dynsymcount, dynsyms, ret); |
10454 | 8 | } |
10455 | | |
10456 | | /* Return address for Ith PLT stub in section PLT, for relocation REL |
10457 | | or (bfd_vma) -1 if it should not be included. */ |
10458 | | |
10459 | | static bfd_vma |
10460 | | elf64_aarch64_plt_sym_val (bfd_vma i, const asection *plt, |
10461 | | const arelent *rel ATTRIBUTE_UNUSED) |
10462 | 606 | { |
10463 | 606 | size_t plt0_size = PLT_ENTRY_SIZE; |
10464 | 606 | size_t pltn_size = PLT_SMALL_ENTRY_SIZE; |
10465 | | |
10466 | 606 | aarch64_plt_type plt_type |
10467 | 606 | = elf_aarch64_tdata (plt->owner)->sw_protections.plt_type; |
10468 | 606 | if (plt_type == PLT_BTI_PAC) |
10469 | 0 | { |
10470 | 0 | if (elf_elfheader (plt->owner)->e_type == ET_EXEC) |
10471 | 0 | pltn_size = PLT_BTI_PAC_SMALL_ENTRY_SIZE; |
10472 | 0 | else |
10473 | 0 | pltn_size = PLT_PAC_SMALL_ENTRY_SIZE; |
10474 | 0 | } |
10475 | 606 | else if (plt_type == PLT_BTI) |
10476 | 0 | { |
10477 | 0 | if (elf_elfheader (plt->owner)->e_type == ET_EXEC) |
10478 | 0 | pltn_size = PLT_BTI_SMALL_ENTRY_SIZE; |
10479 | 0 | } |
10480 | 606 | else if (plt_type == PLT_PAC) |
10481 | 0 | { |
10482 | 0 | pltn_size = PLT_PAC_SMALL_ENTRY_SIZE; |
10483 | 0 | } |
10484 | | |
10485 | 606 | return plt->vma + plt0_size + i * pltn_size; |
10486 | 606 | } |
10487 | | |
10488 | | /* Returns TRUE if NAME is an AArch64 mapping symbol. |
10489 | | The ARM ELF standard defines $x (for A64 code) and $d (for data). |
10490 | | It also allows a period initiated suffix to be added to the symbol, ie: |
10491 | | "$[adtx]\.[:sym_char]+". */ |
10492 | | |
10493 | | static bool |
10494 | | is_aarch64_mapping_symbol (const char * name) |
10495 | 2.40k | { |
10496 | 2.40k | return name != NULL /* Paranoia. */ |
10497 | 2.40k | && name[0] == '$' /* Note: if objcopy --prefix-symbols has been used then |
10498 | | the mapping symbols could have acquired a prefix. |
10499 | | We do not support this here, since such symbols no |
10500 | | longer conform to the ARM ELF ABI. */ |
10501 | 2.40k | && (name[1] == 'd' || name[1] == 'x') |
10502 | 2.40k | && (name[2] == 0 || name[2] == '.'); |
10503 | | /* FIXME: Strictly speaking the symbol is only a valid mapping symbol if |
10504 | | any characters that follow the period are legal characters for the body |
10505 | | of a symbol's name. For now we just assume that this is the case. */ |
10506 | 2.40k | } |
10507 | | |
10508 | | /* Make sure that mapping symbols in object files are not removed via the |
10509 | | "strip --strip-unneeded" tool. These symbols might needed in order to |
10510 | | correctly generate linked files. Once an object file has been linked, |
10511 | | it should be safe to remove them. */ |
10512 | | |
10513 | | static void |
10514 | | elf64_aarch64_backend_symbol_processing (bfd *abfd, asymbol *sym) |
10515 | 11.3k | { |
10516 | 11.3k | if (((abfd->flags & (EXEC_P | DYNAMIC)) == 0) |
10517 | 11.3k | && sym->section != bfd_abs_section_ptr |
10518 | 11.3k | && is_aarch64_mapping_symbol (sym->name)) |
10519 | 0 | sym->flags |= BSF_KEEP; |
10520 | 11.3k | } |
10521 | | |
10522 | | /* Implement elf_backend_setup_gnu_properties for AArch64. It serves as a |
10523 | | wrapper function for _bfd_aarch64_elf_link_setup_gnu_properties to account |
10524 | | for the effect of GNU properties of the output_bfd. */ |
10525 | | static bfd * |
10526 | | elf64_aarch64_link_setup_gnu_properties (struct bfd_link_info *info) |
10527 | 0 | { |
10528 | 0 | bfd *pbfd = _bfd_aarch64_elf_link_setup_gnu_properties (info); |
10529 | | |
10530 | | /* When BTI is forced on the command line, information flows from plt_type to |
10531 | | outprop, so plt_type has already been set and outprop don't have any effect |
10532 | | on plt_type. |
10533 | | Whereas if BTI is inferred from the input bfds, information flows from |
10534 | | outprop to plt_type. If the property GNU_PROPERTY_AARCH64_FEATURE_1_BTI |
10535 | | has been set on all the input bfds, then BTI is set on the output bfd and |
10536 | | plt_type is updated accordingly. */ |
10537 | 0 | struct elf_aarch64_obj_tdata * tdata = elf_aarch64_tdata (info->output_bfd); |
10538 | 0 | uint32_t outprop = tdata->gnu_property_aarch64_feature_1_and; |
10539 | 0 | if (outprop & GNU_PROPERTY_AARCH64_FEATURE_1_BTI) |
10540 | 0 | tdata->sw_protections.plt_type |= PLT_BTI; |
10541 | 0 | setup_plt_values (info, tdata->sw_protections.plt_type); |
10542 | 0 | return pbfd; |
10543 | 0 | } |
10544 | | |
10545 | | /* Implement elf_backend_merge_gnu_properties for AArch64. It serves as a |
10546 | | wrapper function for _bfd_aarch64_elf_merge_gnu_properties to account |
10547 | | for the effect of GNU properties of the output_bfd. */ |
10548 | | static bool |
10549 | | elf64_aarch64_merge_gnu_properties (struct bfd_link_info *info, |
10550 | | bfd *abfd, bfd *bbfd, |
10551 | | elf_property *aprop, |
10552 | | elf_property *bprop) |
10553 | 0 | { |
10554 | 0 | uint32_t outprop |
10555 | 0 | = elf_aarch64_tdata (info->output_bfd)->gnu_property_aarch64_feature_1_and; |
10556 | | |
10557 | | /* Properties are merged per type, hence only check for warnings when merging |
10558 | | GNU_PROPERTY_AARCH64_FEATURE_1_AND. */ |
10559 | 0 | if ((aprop && aprop->pr_type == GNU_PROPERTY_AARCH64_FEATURE_1_AND) |
10560 | 0 | || (bprop && bprop->pr_type == GNU_PROPERTY_AARCH64_FEATURE_1_AND)) |
10561 | 0 | { |
10562 | 0 | const aarch64_protection_opts *sw_protections |
10563 | 0 | = &elf_aarch64_tdata (info->output_bfd)->sw_protections; |
10564 | 0 | aarch64_feature_marking_report bti_report = sw_protections->bti_report; |
10565 | 0 | aarch64_feature_marking_report gcs_report = sw_protections->gcs_report; |
10566 | | |
10567 | | /* If output has been marked with BTI using command line argument, give |
10568 | | out warning if necessary. */ |
10569 | 0 | if ((outprop & GNU_PROPERTY_AARCH64_FEATURE_1_BTI) |
10570 | 0 | && (bti_report != MARKING_NONE)) |
10571 | 0 | { |
10572 | 0 | if (!aprop || !(aprop->u.number & GNU_PROPERTY_AARCH64_FEATURE_1_BTI)) |
10573 | 0 | _bfd_aarch64_elf_check_bti_report (info, abfd); |
10574 | 0 | if (!bprop || !(bprop->u.number & GNU_PROPERTY_AARCH64_FEATURE_1_BTI)) |
10575 | 0 | _bfd_aarch64_elf_check_bti_report (info, bbfd); |
10576 | 0 | } |
10577 | | |
10578 | | /* If the output has been marked with GCS using '-z gcs' and the input is |
10579 | | missing GCS feature tag, throw a warning/error in accordance with |
10580 | | -z gcs-report=warning/error. */ |
10581 | 0 | if ((outprop & GNU_PROPERTY_AARCH64_FEATURE_1_GCS) |
10582 | 0 | && gcs_report != MARKING_NONE) |
10583 | 0 | { |
10584 | 0 | if (!aprop || !(aprop->u.number & GNU_PROPERTY_AARCH64_FEATURE_1_GCS)) |
10585 | 0 | _bfd_aarch64_elf_check_gcs_report (info, abfd); |
10586 | 0 | if (!bprop || !(bprop->u.number & GNU_PROPERTY_AARCH64_FEATURE_1_GCS)) |
10587 | 0 | _bfd_aarch64_elf_check_gcs_report (info, bbfd); |
10588 | 0 | } |
10589 | 0 | } |
10590 | |
|
10591 | 0 | return _bfd_aarch64_elf_merge_gnu_properties (info, abfd, aprop, |
10592 | 0 | bprop, outprop); |
10593 | 0 | } |
10594 | | |
10595 | | /* We use this so we can override certain functions |
10596 | | (though currently we don't). */ |
10597 | | |
10598 | | const struct elf_size_info elf64_aarch64_size_info = |
10599 | | { |
10600 | | sizeof (Elf64_External_Ehdr), |
10601 | | sizeof (Elf64_External_Phdr), |
10602 | | sizeof (Elf64_External_Shdr), |
10603 | | sizeof (Elf64_External_Rel), |
10604 | | sizeof (Elf64_External_Rela), |
10605 | | sizeof (Elf64_External_Sym), |
10606 | | sizeof (Elf64_External_Dyn), |
10607 | | sizeof (Elf_External_Note), |
10608 | | 4, /* Hash table entry size. */ |
10609 | | 1, /* Internal relocs per external relocs. */ |
10610 | | ARCH_SIZE, /* Arch size. */ |
10611 | | LOG_FILE_ALIGN, /* Log_file_align. */ |
10612 | | ELFCLASS64, EV_CURRENT, |
10613 | | bfd_elf64_write_out_phdrs, |
10614 | | bfd_elf64_write_shdrs_and_ehdr, |
10615 | | bfd_elf64_checksum_contents, |
10616 | | bfd_elf64_write_relocs, |
10617 | | bfd_elf64_swap_symbol_in, |
10618 | | bfd_elf64_swap_symbol_out, |
10619 | | bfd_elf64_slurp_reloc_table, |
10620 | | bfd_elf64_slurp_symbol_table, |
10621 | | bfd_elf64_swap_dyn_in, |
10622 | | bfd_elf64_swap_dyn_out, |
10623 | | bfd_elf64_swap_reloc_in, |
10624 | | bfd_elf64_swap_reloc_out, |
10625 | | bfd_elf64_swap_reloca_in, |
10626 | | bfd_elf64_swap_reloca_out |
10627 | | }; |
10628 | | |
10629 | | #define ELF_ARCH bfd_arch_aarch64 |
10630 | | #define ELF_TARGET_ID AARCH64_ELF_DATA |
10631 | | #define ELF_MACHINE_CODE EM_AARCH64 |
10632 | | #define ELF_MAXPAGESIZE 0x10000 |
10633 | | #define ELF_COMMONPAGESIZE 0x1000 |
10634 | | |
10635 | | #define bfd_elf64_bfd_is_target_special_symbol \ |
10636 | | elf64_aarch64_is_target_special_symbol |
10637 | | |
10638 | | #define bfd_elf64_bfd_link_hash_table_create \ |
10639 | | elf64_aarch64_link_hash_table_create |
10640 | | |
10641 | | #define bfd_elf64_bfd_merge_private_bfd_data \ |
10642 | | elf64_aarch64_merge_private_bfd_data |
10643 | | |
10644 | | #define bfd_elf64_bfd_print_private_bfd_data \ |
10645 | | elf64_aarch64_print_private_bfd_data |
10646 | | |
10647 | | #define bfd_elf64_bfd_reloc_type_lookup \ |
10648 | | elf64_aarch64_reloc_type_lookup |
10649 | | |
10650 | | #define bfd_elf64_bfd_reloc_name_lookup \ |
10651 | | elf64_aarch64_reloc_name_lookup |
10652 | | |
10653 | | #define bfd_elf64_bfd_set_private_flags \ |
10654 | | elf64_aarch64_set_private_flags |
10655 | | |
10656 | | #define bfd_elf64_find_inliner_info \ |
10657 | | elf64_aarch64_find_inliner_info |
10658 | | |
10659 | | #define bfd_elf64_get_synthetic_symtab \ |
10660 | | elf64_aarch64_get_synthetic_symtab |
10661 | | |
10662 | | #define bfd_elf64_mkobject \ |
10663 | | elf64_aarch64_mkobject |
10664 | | |
10665 | | #define bfd_elf64_new_section_hook \ |
10666 | | elf64_aarch64_new_section_hook |
10667 | | |
10668 | | #define elf_backend_adjust_dynamic_symbol \ |
10669 | | elf64_aarch64_adjust_dynamic_symbol |
10670 | | |
10671 | | #define elf_backend_early_size_sections \ |
10672 | | elf64_aarch64_early_size_sections |
10673 | | |
10674 | | #define elf_backend_check_relocs \ |
10675 | | elf64_aarch64_check_relocs |
10676 | | |
10677 | | #define elf_backend_copy_indirect_symbol \ |
10678 | | elf64_aarch64_copy_indirect_symbol |
10679 | | |
10680 | | #define elf_backend_merge_symbol_attribute \ |
10681 | | elf64_aarch64_merge_symbol_attribute |
10682 | | |
10683 | | /* Create .dynbss, and .rela.bss sections in DYNOBJ, and set up shortcuts |
10684 | | to them in our hash. */ |
10685 | | #define elf_backend_create_dynamic_sections \ |
10686 | | elf64_aarch64_create_dynamic_sections |
10687 | | |
10688 | | #define elf_backend_init_index_section \ |
10689 | | _bfd_elf_init_2_index_sections |
10690 | | |
10691 | | #define elf_backend_finish_dynamic_sections \ |
10692 | | elf64_aarch64_finish_dynamic_sections |
10693 | | |
10694 | | #define elf_backend_finish_dynamic_symbol \ |
10695 | | elf64_aarch64_finish_dynamic_symbol |
10696 | | |
10697 | | #define elf_backend_object_p \ |
10698 | | elf64_aarch64_object_p |
10699 | | |
10700 | | #define elf_backend_output_arch_local_syms \ |
10701 | | elf64_aarch64_output_arch_local_syms |
10702 | | |
10703 | | #define elf_backend_maybe_function_sym \ |
10704 | | elf64_aarch64_maybe_function_sym |
10705 | | |
10706 | | #define elf_backend_plt_sym_val \ |
10707 | | elf64_aarch64_plt_sym_val |
10708 | | |
10709 | | #define elf_backend_init_file_header \ |
10710 | | elf64_aarch64_init_file_header |
10711 | | |
10712 | | #define elf_backend_relocate_section \ |
10713 | | elf64_aarch64_relocate_section |
10714 | | |
10715 | | #define elf_backend_reloc_type_class \ |
10716 | | elf64_aarch64_reloc_type_class |
10717 | | |
10718 | | #define elf_backend_section_from_shdr \ |
10719 | | elf64_aarch64_section_from_shdr |
10720 | | |
10721 | | #define elf_backend_section_from_phdr \ |
10722 | | elf64_aarch64_section_from_phdr |
10723 | | |
10724 | | #define elf_backend_modify_headers \ |
10725 | | elf64_aarch64_modify_headers |
10726 | | |
10727 | | #define elf_backend_late_size_sections \ |
10728 | | elf64_aarch64_late_size_sections |
10729 | | |
10730 | | #define elf_backend_size_info \ |
10731 | | elf64_aarch64_size_info |
10732 | | |
10733 | | #define elf_backend_write_section \ |
10734 | | elf64_aarch64_write_section |
10735 | | |
10736 | | #define elf_backend_symbol_processing \ |
10737 | | elf64_aarch64_backend_symbol_processing |
10738 | | |
10739 | | #define elf_backend_setup_gnu_properties \ |
10740 | | elf64_aarch64_link_setup_gnu_properties |
10741 | | |
10742 | | #define elf_backend_merge_gnu_properties \ |
10743 | | elf64_aarch64_merge_gnu_properties |
10744 | | |
10745 | | #define elf_backend_size_relative_relocs \ |
10746 | | elf64_aarch64_size_relative_relocs |
10747 | | |
10748 | | #define elf_backend_finish_relative_relocs \ |
10749 | | elf64_aarch64_finish_relative_relocs |
10750 | | |
10751 | | #define elf_backend_can_refcount 1 |
10752 | | #define elf_backend_can_gc_sections 1 |
10753 | | #define elf_backend_plt_readonly 1 |
10754 | | #define elf_backend_want_got_plt 1 |
10755 | | #define elf_backend_want_plt_sym 0 |
10756 | | #define elf_backend_want_dynrelro 1 |
10757 | | #define elf_backend_may_use_rel_p 0 |
10758 | | #define elf_backend_may_use_rela_p 1 |
10759 | | #define elf_backend_default_use_rela_p 1 |
10760 | | #define elf_backend_rela_normal 1 |
10761 | | #define elf_backend_dtrel_excludes_plt 1 |
10762 | | #define elf_backend_got_header_size (GOT_ENTRY_SIZE * 3) |
10763 | | #define elf_backend_default_execstack 0 |
10764 | | #define elf_backend_extern_protected_data 0 |
10765 | | #define elf_backend_hash_symbol elf_aarch64_hash_symbol |
10766 | | |
10767 | | #undef elf_backend_obj_attrs_section |
10768 | | #define elf_backend_obj_attrs_section SEC_AARCH64_ATTRIBUTES |
10769 | | |
10770 | | #include "elf64-target.h" |
10771 | | |
10772 | | /* CloudABI support. */ |
10773 | | |
10774 | | #undef TARGET_LITTLE_SYM |
10775 | | #define TARGET_LITTLE_SYM aarch64_elf64_le_cloudabi_vec |
10776 | | #undef TARGET_LITTLE_NAME |
10777 | | #define TARGET_LITTLE_NAME "elf64-littleaarch64-cloudabi" |
10778 | | #undef TARGET_BIG_SYM |
10779 | | #define TARGET_BIG_SYM aarch64_elf64_be_cloudabi_vec |
10780 | | #undef TARGET_BIG_NAME |
10781 | | #define TARGET_BIG_NAME "elf64-bigaarch64-cloudabi" |
10782 | | |
10783 | | #undef ELF_OSABI |
10784 | | #define ELF_OSABI ELFOSABI_CLOUDABI |
10785 | | |
10786 | | #undef elf64_bed |
10787 | | #define elf64_bed elf64_aarch64_cloudabi_bed |
10788 | | |
10789 | | #include "elf64-target.h" |