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