Commit | Line | Data |
---|---|---|
cec5225b | 1 | /* AArch64-specific support for NN-bit ELF. |
2571583a | 2 | Copyright (C) 2009-2017 Free Software Foundation, Inc. |
a06ea964 NC |
3 | Contributed by ARM Ltd. |
4 | ||
5 | This file is part of BFD, the Binary File Descriptor library. | |
6 | ||
7 | This program is free software; you can redistribute it and/or modify | |
8 | it under the terms of the GNU General Public License as published by | |
9 | the Free Software Foundation; either version 3 of the License, or | |
10 | (at your option) any later version. | |
11 | ||
12 | This program is distributed in the hope that it will be useful, | |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | GNU General Public License for more details. | |
16 | ||
17 | You should have received a copy of the GNU General Public License | |
18 | along with this program; see the file COPYING3. If not, | |
19 | see <http://www.gnu.org/licenses/>. */ | |
20 | ||
21 | /* Notes on implementation: | |
22 | ||
23 | Thread Local Store (TLS) | |
24 | ||
25 | Overview: | |
26 | ||
27 | The implementation currently supports both traditional TLS and TLS | |
28 | descriptors, but only general dynamic (GD). | |
29 | ||
30 | For traditional TLS the assembler will present us with code | |
31 | fragments of the form: | |
32 | ||
33 | adrp x0, :tlsgd:foo | |
34 | R_AARCH64_TLSGD_ADR_PAGE21(foo) | |
35 | add x0, :tlsgd_lo12:foo | |
36 | R_AARCH64_TLSGD_ADD_LO12_NC(foo) | |
37 | bl __tls_get_addr | |
38 | nop | |
39 | ||
40 | For TLS descriptors the assembler will present us with code | |
41 | fragments of the form: | |
42 | ||
418009c2 | 43 | adrp x0, :tlsdesc:foo R_AARCH64_TLSDESC_ADR_PAGE21(foo) |
a06ea964 NC |
44 | ldr x1, [x0, #:tlsdesc_lo12:foo] R_AARCH64_TLSDESC_LD64_LO12(foo) |
45 | add x0, x0, #:tlsdesc_lo12:foo R_AARCH64_TLSDESC_ADD_LO12(foo) | |
46 | .tlsdesccall foo | |
47 | blr x1 R_AARCH64_TLSDESC_CALL(foo) | |
48 | ||
49 | The relocations R_AARCH64_TLSGD_{ADR_PREL21,ADD_LO12_NC} against foo | |
50 | indicate that foo is thread local and should be accessed via the | |
51 | traditional TLS mechanims. | |
52 | ||
a6bb11b2 | 53 | The relocations R_AARCH64_TLSDESC_{ADR_PAGE21,LD64_LO12_NC,ADD_LO12_NC} |
a06ea964 NC |
54 | against foo indicate that 'foo' is thread local and should be accessed |
55 | via a TLS descriptor mechanism. | |
56 | ||
57 | The precise instruction sequence is only relevant from the | |
58 | perspective of linker relaxation which is currently not implemented. | |
59 | ||
60 | The static linker must detect that 'foo' is a TLS object and | |
61 | allocate a double GOT entry. The GOT entry must be created for both | |
62 | global and local TLS symbols. Note that this is different to none | |
63 | TLS local objects which do not need a GOT entry. | |
64 | ||
65 | In the traditional TLS mechanism, the double GOT entry is used to | |
66 | provide the tls_index structure, containing module and offset | |
a6bb11b2 | 67 | entries. The static linker places the relocation R_AARCH64_TLS_DTPMOD |
a06ea964 NC |
68 | on the module entry. The loader will subsequently fixup this |
69 | relocation with the module identity. | |
70 | ||
71 | For global traditional TLS symbols the static linker places an | |
a6bb11b2 | 72 | R_AARCH64_TLS_DTPREL relocation on the offset entry. The loader |
a06ea964 NC |
73 | will subsequently fixup the offset. For local TLS symbols the static |
74 | linker fixes up offset. | |
75 | ||
76 | In the TLS descriptor mechanism the double GOT entry is used to | |
77 | provide the descriptor. The static linker places the relocation | |
78 | R_AARCH64_TLSDESC on the first GOT slot. The loader will | |
79 | subsequently fix this up. | |
80 | ||
81 | Implementation: | |
82 | ||
83 | The handling of TLS symbols is implemented across a number of | |
84 | different backend functions. The following is a top level view of | |
85 | what processing is performed where. | |
86 | ||
87 | The TLS implementation maintains state information for each TLS | |
88 | symbol. The state information for local and global symbols is kept | |
89 | in different places. Global symbols use generic BFD structures while | |
90 | local symbols use backend specific structures that are allocated and | |
91 | maintained entirely by the backend. | |
92 | ||
93 | The flow: | |
94 | ||
cec5225b | 95 | elfNN_aarch64_check_relocs() |
a06ea964 NC |
96 | |
97 | This function is invoked for each relocation. | |
98 | ||
99 | The TLS relocations R_AARCH64_TLSGD_{ADR_PREL21,ADD_LO12_NC} and | |
a6bb11b2 | 100 | R_AARCH64_TLSDESC_{ADR_PAGE21,LD64_LO12_NC,ADD_LO12_NC} are |
a06ea964 NC |
101 | spotted. One time creation of local symbol data structures are |
102 | created when the first local symbol is seen. | |
103 | ||
104 | The reference count for a symbol is incremented. The GOT type for | |
105 | each symbol is marked as general dynamic. | |
106 | ||
cec5225b | 107 | elfNN_aarch64_allocate_dynrelocs () |
a06ea964 NC |
108 | |
109 | For each global with positive reference count we allocate a double | |
110 | GOT slot. For a traditional TLS symbol we allocate space for two | |
111 | relocation entries on the GOT, for a TLS descriptor symbol we | |
112 | allocate space for one relocation on the slot. Record the GOT offset | |
113 | for this symbol. | |
114 | ||
cec5225b | 115 | elfNN_aarch64_size_dynamic_sections () |
a06ea964 NC |
116 | |
117 | Iterate all input BFDS, look for in the local symbol data structure | |
118 | constructed earlier for local TLS symbols and allocate them double | |
119 | GOT slots along with space for a single GOT relocation. Update the | |
120 | local symbol structure to record the GOT offset allocated. | |
121 | ||
cec5225b | 122 | elfNN_aarch64_relocate_section () |
a06ea964 | 123 | |
cec5225b | 124 | Calls elfNN_aarch64_final_link_relocate () |
a06ea964 NC |
125 | |
126 | Emit the relevant TLS relocations against the GOT for each TLS | |
127 | symbol. For local TLS symbols emit the GOT offset directly. The GOT | |
128 | relocations are emitted once the first time a TLS symbol is | |
129 | encountered. The implementation uses the LSB of the GOT offset to | |
130 | flag that the relevant GOT relocations for a symbol have been | |
131 | emitted. All of the TLS code that uses the GOT offset needs to take | |
132 | care to mask out this flag bit before using the offset. | |
133 | ||
cec5225b | 134 | elfNN_aarch64_final_link_relocate () |
a06ea964 NC |
135 | |
136 | Fixup the R_AARCH64_TLSGD_{ADR_PREL21, ADD_LO12_NC} relocations. */ | |
137 | ||
138 | #include "sysdep.h" | |
139 | #include "bfd.h" | |
140 | #include "libiberty.h" | |
141 | #include "libbfd.h" | |
142 | #include "bfd_stdint.h" | |
143 | #include "elf-bfd.h" | |
144 | #include "bfdlink.h" | |
1419bbe5 | 145 | #include "objalloc.h" |
a06ea964 | 146 | #include "elf/aarch64.h" |
caed7120 | 147 | #include "elfxx-aarch64.h" |
a06ea964 | 148 | |
cec5225b YZ |
149 | #define ARCH_SIZE NN |
150 | ||
151 | #if ARCH_SIZE == 64 | |
152 | #define AARCH64_R(NAME) R_AARCH64_ ## NAME | |
153 | #define AARCH64_R_STR(NAME) "R_AARCH64_" #NAME | |
a6bb11b2 YZ |
154 | #define HOWTO64(...) HOWTO (__VA_ARGS__) |
155 | #define HOWTO32(...) EMPTY_HOWTO (0) | |
cec5225b | 156 | #define LOG_FILE_ALIGN 3 |
f955cccf | 157 | #define BFD_RELOC_AARCH64_TLSDESC_LD64_LO12_NC BFD_RELOC_AARCH64_TLSDESC_LD64_LO12 |
cec5225b YZ |
158 | #endif |
159 | ||
160 | #if ARCH_SIZE == 32 | |
161 | #define AARCH64_R(NAME) R_AARCH64_P32_ ## NAME | |
162 | #define AARCH64_R_STR(NAME) "R_AARCH64_P32_" #NAME | |
a6bb11b2 YZ |
163 | #define HOWTO64(...) EMPTY_HOWTO (0) |
164 | #define HOWTO32(...) HOWTO (__VA_ARGS__) | |
cec5225b | 165 | #define LOG_FILE_ALIGN 2 |
f955cccf NC |
166 | #define BFD_RELOC_AARCH64_TLSDESC_LD32_LO12 BFD_RELOC_AARCH64_TLSDESC_LD32_LO12_NC |
167 | #define R_AARCH64_P32_TLSDESC_ADD_LO12 R_AARCH64_P32_TLSDESC_ADD_LO12_NC | |
cec5225b YZ |
168 | #endif |
169 | ||
a6bb11b2 | 170 | #define IS_AARCH64_TLS_RELOC(R_TYPE) \ |
4c0a9a6f JW |
171 | ((R_TYPE) == BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC \ |
172 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21 \ | |
3c12b054 | 173 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSGD_ADR_PREL21 \ |
3e8286c0 | 174 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSGD_MOVW_G0_NC \ |
1aa66fb1 | 175 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSGD_MOVW_G1 \ |
a6bb11b2 | 176 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21 \ |
a6bb11b2 | 177 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSIE_LD32_GOTTPREL_LO12_NC \ |
4c0a9a6f | 178 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC \ |
a6bb11b2 | 179 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19 \ |
4c0a9a6f JW |
180 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G0_NC \ |
181 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G1 \ | |
6ffe9a1b | 182 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_ADD_DTPREL_HI12 \ |
40fbed84 | 183 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_ADD_DTPREL_LO12 \ |
753999c1 | 184 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_ADD_DTPREL_LO12_NC \ |
73f925cc | 185 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC \ |
f69e4920 | 186 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21 \ |
77a69ff8 | 187 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_ADR_PREL21 \ |
07c9aa07 JW |
188 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_LDST16_DTPREL_LO12 \ |
189 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_LDST16_DTPREL_LO12_NC \ | |
190 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_LDST32_DTPREL_LO12 \ | |
191 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_LDST32_DTPREL_LO12_NC \ | |
192 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_LDST64_DTPREL_LO12 \ | |
193 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_LDST64_DTPREL_LO12_NC \ | |
194 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_LDST8_DTPREL_LO12 \ | |
195 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_LDST8_DTPREL_LO12_NC \ | |
6ffe9a1b JW |
196 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G0 \ |
197 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G0_NC \ | |
198 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G1 \ | |
199 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G1_NC \ | |
200 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G2 \ | |
a6bb11b2 | 201 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_HI12 \ |
4c0a9a6f | 202 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_LO12 \ |
a6bb11b2 | 203 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_LO12_NC \ |
a6bb11b2 YZ |
204 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0 \ |
205 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC \ | |
4c0a9a6f JW |
206 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1 \ |
207 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1_NC \ | |
208 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G2 \ | |
a6bb11b2 YZ |
209 | || (R_TYPE) == BFD_RELOC_AARCH64_TLS_DTPMOD \ |
210 | || (R_TYPE) == BFD_RELOC_AARCH64_TLS_DTPREL \ | |
211 | || (R_TYPE) == BFD_RELOC_AARCH64_TLS_TPREL \ | |
a06ea964 NC |
212 | || IS_AARCH64_TLSDESC_RELOC ((R_TYPE))) |
213 | ||
9331eea1 | 214 | #define IS_AARCH64_TLS_RELAX_RELOC(R_TYPE) \ |
f955cccf NC |
215 | ((R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_ADD \ |
216 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_ADD_LO12 \ | |
4af68b9c JW |
217 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21 \ |
218 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21 \ | |
219 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_CALL \ | |
220 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_LD_PREL19 \ | |
221 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_LDNN_LO12_NC \ | |
0484b454 RL |
222 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_LDR \ |
223 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_OFF_G0_NC \ | |
224 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_OFF_G1 \ | |
225 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_LDR \ | |
4af68b9c | 226 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21 \ |
9331eea1 JW |
227 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSGD_ADR_PREL21 \ |
228 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC \ | |
ac734732 RL |
229 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSGD_MOVW_G0_NC \ |
230 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSGD_MOVW_G1 \ | |
9331eea1 JW |
231 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21 \ |
232 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19 \ | |
233 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSIE_LDNN_GOTTPREL_LO12_NC \ | |
259364ad JW |
234 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC \ |
235 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21 \ | |
4af68b9c | 236 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_ADR_PREL21) |
9331eea1 | 237 | |
a6bb11b2 | 238 | #define IS_AARCH64_TLSDESC_RELOC(R_TYPE) \ |
4c0a9a6f JW |
239 | ((R_TYPE) == BFD_RELOC_AARCH64_TLSDESC \ |
240 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_ADD \ | |
f955cccf | 241 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_ADD_LO12 \ |
a6bb11b2 | 242 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21 \ |
389b8029 | 243 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21 \ |
4c0a9a6f | 244 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_CALL \ |
a6bb11b2 | 245 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_LD32_LO12_NC \ |
f955cccf | 246 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_LD64_LO12 \ |
a6bb11b2 | 247 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_LDR \ |
4c0a9a6f JW |
248 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_LD_PREL19 \ |
249 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_OFF_G0_NC \ | |
250 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_OFF_G1) | |
a06ea964 | 251 | |
6353d82b | 252 | #define ELIMINATE_COPY_RELOCS 1 |
a06ea964 | 253 | |
a06ea964 | 254 | /* Return size of a relocation entry. HTAB is the bfd's |
cec5225b YZ |
255 | elf_aarch64_link_hash_entry. */ |
256 | #define RELOC_SIZE(HTAB) (sizeof (ElfNN_External_Rela)) | |
a06ea964 | 257 | |
cec5225b YZ |
258 | /* GOT Entry size - 8 bytes in ELF64 and 4 bytes in ELF32. */ |
259 | #define GOT_ENTRY_SIZE (ARCH_SIZE / 8) | |
a06ea964 NC |
260 | #define PLT_ENTRY_SIZE (32) |
261 | #define PLT_SMALL_ENTRY_SIZE (16) | |
262 | #define PLT_TLSDESC_ENTRY_SIZE (32) | |
263 | ||
2d0ca824 | 264 | /* Encoding of the nop instruction. */ |
a06ea964 NC |
265 | #define INSN_NOP 0xd503201f |
266 | ||
267 | #define aarch64_compute_jump_table_size(htab) \ | |
268 | (((htab)->root.srelplt == NULL) ? 0 \ | |
269 | : (htab)->root.srelplt->reloc_count * GOT_ENTRY_SIZE) | |
270 | ||
271 | /* The first entry in a procedure linkage table looks like this | |
272 | if the distance between the PLTGOT and the PLT is < 4GB use | |
273 | these PLT entries. Note that the dynamic linker gets &PLTGOT[2] | |
274 | in x16 and needs to work out PLTGOT[1] by using an address of | |
cec5225b YZ |
275 | [x16,#-GOT_ENTRY_SIZE]. */ |
276 | static const bfd_byte elfNN_aarch64_small_plt0_entry[PLT_ENTRY_SIZE] = | |
a06ea964 NC |
277 | { |
278 | 0xf0, 0x7b, 0xbf, 0xa9, /* stp x16, x30, [sp, #-16]! */ | |
279 | 0x10, 0x00, 0x00, 0x90, /* adrp x16, (GOT+16) */ | |
caed7120 | 280 | #if ARCH_SIZE == 64 |
a06ea964 NC |
281 | 0x11, 0x0A, 0x40, 0xf9, /* ldr x17, [x16, #PLT_GOT+0x10] */ |
282 | 0x10, 0x42, 0x00, 0x91, /* add x16, x16,#PLT_GOT+0x10 */ | |
caed7120 YZ |
283 | #else |
284 | 0x11, 0x0A, 0x40, 0xb9, /* ldr w17, [x16, #PLT_GOT+0x8] */ | |
285 | 0x10, 0x22, 0x00, 0x11, /* add w16, w16,#PLT_GOT+0x8 */ | |
286 | #endif | |
a06ea964 NC |
287 | 0x20, 0x02, 0x1f, 0xd6, /* br x17 */ |
288 | 0x1f, 0x20, 0x03, 0xd5, /* nop */ | |
289 | 0x1f, 0x20, 0x03, 0xd5, /* nop */ | |
290 | 0x1f, 0x20, 0x03, 0xd5, /* nop */ | |
291 | }; | |
292 | ||
293 | /* Per function entry in a procedure linkage table looks like this | |
294 | if the distance between the PLTGOT and the PLT is < 4GB use | |
295 | these PLT entries. */ | |
cec5225b | 296 | static const bfd_byte elfNN_aarch64_small_plt_entry[PLT_SMALL_ENTRY_SIZE] = |
a06ea964 NC |
297 | { |
298 | 0x10, 0x00, 0x00, 0x90, /* adrp x16, PLTGOT + n * 8 */ | |
caed7120 | 299 | #if ARCH_SIZE == 64 |
a06ea964 NC |
300 | 0x11, 0x02, 0x40, 0xf9, /* ldr x17, [x16, PLTGOT + n * 8] */ |
301 | 0x10, 0x02, 0x00, 0x91, /* add x16, x16, :lo12:PLTGOT + n * 8 */ | |
caed7120 YZ |
302 | #else |
303 | 0x11, 0x02, 0x40, 0xb9, /* ldr w17, [x16, PLTGOT + n * 4] */ | |
304 | 0x10, 0x02, 0x00, 0x11, /* add w16, w16, :lo12:PLTGOT + n * 4 */ | |
305 | #endif | |
a06ea964 NC |
306 | 0x20, 0x02, 0x1f, 0xd6, /* br x17. */ |
307 | }; | |
308 | ||
309 | static const bfd_byte | |
cec5225b | 310 | elfNN_aarch64_tlsdesc_small_plt_entry[PLT_TLSDESC_ENTRY_SIZE] = |
a06ea964 NC |
311 | { |
312 | 0xe2, 0x0f, 0xbf, 0xa9, /* stp x2, x3, [sp, #-16]! */ | |
313 | 0x02, 0x00, 0x00, 0x90, /* adrp x2, 0 */ | |
314 | 0x03, 0x00, 0x00, 0x90, /* adrp x3, 0 */ | |
caed7120 YZ |
315 | #if ARCH_SIZE == 64 |
316 | 0x42, 0x00, 0x40, 0xf9, /* ldr x2, [x2, #0] */ | |
a06ea964 | 317 | 0x63, 0x00, 0x00, 0x91, /* add x3, x3, 0 */ |
caed7120 YZ |
318 | #else |
319 | 0x42, 0x00, 0x40, 0xb9, /* ldr w2, [x2, #0] */ | |
320 | 0x63, 0x00, 0x00, 0x11, /* add w3, w3, 0 */ | |
321 | #endif | |
322 | 0x40, 0x00, 0x1f, 0xd6, /* br x2 */ | |
a06ea964 NC |
323 | 0x1f, 0x20, 0x03, 0xd5, /* nop */ |
324 | 0x1f, 0x20, 0x03, 0xd5, /* nop */ | |
325 | }; | |
326 | ||
cec5225b YZ |
327 | #define elf_info_to_howto elfNN_aarch64_info_to_howto |
328 | #define elf_info_to_howto_rel elfNN_aarch64_info_to_howto | |
a06ea964 NC |
329 | |
330 | #define AARCH64_ELF_ABI_VERSION 0 | |
a06ea964 NC |
331 | |
332 | /* In case we're on a 32-bit machine, construct a 64-bit "-1" value. */ | |
333 | #define ALL_ONES (~ (bfd_vma) 0) | |
334 | ||
a6bb11b2 YZ |
335 | /* Indexed by the bfd interal reloc enumerators. |
336 | Therefore, the table needs to be synced with BFD_RELOC_AARCH64_* | |
337 | in reloc.c. */ | |
a06ea964 | 338 | |
a6bb11b2 | 339 | static reloc_howto_type elfNN_aarch64_howto_table[] = |
a06ea964 | 340 | { |
a6bb11b2 | 341 | EMPTY_HOWTO (0), |
a06ea964 | 342 | |
a6bb11b2 | 343 | /* Basic data relocations. */ |
a06ea964 | 344 | |
b7f28d87 JW |
345 | /* Deprecated, but retained for backwards compatibility. */ |
346 | HOWTO64 (R_AARCH64_NULL, /* type */ | |
a06ea964 | 347 | 0, /* rightshift */ |
6346d5ca | 348 | 3, /* size (0 = byte, 1 = short, 2 = long) */ |
a6bb11b2 | 349 | 0, /* bitsize */ |
a06ea964 NC |
350 | FALSE, /* pc_relative */ |
351 | 0, /* bitpos */ | |
352 | complain_overflow_dont, /* complain_on_overflow */ | |
353 | bfd_elf_generic_reloc, /* special_function */ | |
a6bb11b2 | 354 | "R_AARCH64_NULL", /* name */ |
a06ea964 NC |
355 | FALSE, /* partial_inplace */ |
356 | 0, /* src_mask */ | |
a6bb11b2 | 357 | 0, /* dst_mask */ |
a06ea964 | 358 | FALSE), /* pcrel_offset */ |
a6bb11b2 | 359 | HOWTO (R_AARCH64_NONE, /* type */ |
a06ea964 | 360 | 0, /* rightshift */ |
6346d5ca | 361 | 3, /* size (0 = byte, 1 = short, 2 = long) */ |
a06ea964 NC |
362 | 0, /* bitsize */ |
363 | FALSE, /* pc_relative */ | |
364 | 0, /* bitpos */ | |
365 | complain_overflow_dont, /* complain_on_overflow */ | |
366 | bfd_elf_generic_reloc, /* special_function */ | |
a6bb11b2 | 367 | "R_AARCH64_NONE", /* name */ |
a06ea964 NC |
368 | FALSE, /* partial_inplace */ |
369 | 0, /* src_mask */ | |
370 | 0, /* dst_mask */ | |
371 | FALSE), /* pcrel_offset */ | |
372 | ||
373 | /* .xword: (S+A) */ | |
a6bb11b2 | 374 | HOWTO64 (AARCH64_R (ABS64), /* type */ |
a06ea964 NC |
375 | 0, /* rightshift */ |
376 | 4, /* size (4 = long long) */ | |
377 | 64, /* bitsize */ | |
378 | FALSE, /* pc_relative */ | |
379 | 0, /* bitpos */ | |
380 | complain_overflow_unsigned, /* complain_on_overflow */ | |
381 | bfd_elf_generic_reloc, /* special_function */ | |
a6bb11b2 | 382 | AARCH64_R_STR (ABS64), /* name */ |
a06ea964 NC |
383 | FALSE, /* partial_inplace */ |
384 | ALL_ONES, /* src_mask */ | |
385 | ALL_ONES, /* dst_mask */ | |
386 | FALSE), /* pcrel_offset */ | |
387 | ||
388 | /* .word: (S+A) */ | |
a6bb11b2 | 389 | HOWTO (AARCH64_R (ABS32), /* type */ |
a06ea964 NC |
390 | 0, /* rightshift */ |
391 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
392 | 32, /* bitsize */ | |
393 | FALSE, /* pc_relative */ | |
394 | 0, /* bitpos */ | |
395 | complain_overflow_unsigned, /* complain_on_overflow */ | |
396 | bfd_elf_generic_reloc, /* special_function */ | |
a6bb11b2 | 397 | AARCH64_R_STR (ABS32), /* name */ |
a06ea964 NC |
398 | FALSE, /* partial_inplace */ |
399 | 0xffffffff, /* src_mask */ | |
400 | 0xffffffff, /* dst_mask */ | |
401 | FALSE), /* pcrel_offset */ | |
402 | ||
403 | /* .half: (S+A) */ | |
a6bb11b2 | 404 | HOWTO (AARCH64_R (ABS16), /* type */ |
a06ea964 NC |
405 | 0, /* rightshift */ |
406 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
407 | 16, /* bitsize */ | |
408 | FALSE, /* pc_relative */ | |
409 | 0, /* bitpos */ | |
410 | complain_overflow_unsigned, /* complain_on_overflow */ | |
411 | bfd_elf_generic_reloc, /* special_function */ | |
a6bb11b2 | 412 | AARCH64_R_STR (ABS16), /* name */ |
a06ea964 NC |
413 | FALSE, /* partial_inplace */ |
414 | 0xffff, /* src_mask */ | |
415 | 0xffff, /* dst_mask */ | |
416 | FALSE), /* pcrel_offset */ | |
417 | ||
418 | /* .xword: (S+A-P) */ | |
a6bb11b2 | 419 | HOWTO64 (AARCH64_R (PREL64), /* type */ |
a06ea964 NC |
420 | 0, /* rightshift */ |
421 | 4, /* size (4 = long long) */ | |
422 | 64, /* bitsize */ | |
423 | TRUE, /* pc_relative */ | |
424 | 0, /* bitpos */ | |
425 | complain_overflow_signed, /* complain_on_overflow */ | |
426 | bfd_elf_generic_reloc, /* special_function */ | |
a6bb11b2 | 427 | AARCH64_R_STR (PREL64), /* name */ |
a06ea964 NC |
428 | FALSE, /* partial_inplace */ |
429 | ALL_ONES, /* src_mask */ | |
430 | ALL_ONES, /* dst_mask */ | |
431 | TRUE), /* pcrel_offset */ | |
432 | ||
433 | /* .word: (S+A-P) */ | |
a6bb11b2 | 434 | HOWTO (AARCH64_R (PREL32), /* type */ |
a06ea964 NC |
435 | 0, /* rightshift */ |
436 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
437 | 32, /* bitsize */ | |
438 | TRUE, /* pc_relative */ | |
439 | 0, /* bitpos */ | |
440 | complain_overflow_signed, /* complain_on_overflow */ | |
441 | bfd_elf_generic_reloc, /* special_function */ | |
a6bb11b2 | 442 | AARCH64_R_STR (PREL32), /* name */ |
a06ea964 NC |
443 | FALSE, /* partial_inplace */ |
444 | 0xffffffff, /* src_mask */ | |
445 | 0xffffffff, /* dst_mask */ | |
446 | TRUE), /* pcrel_offset */ | |
447 | ||
448 | /* .half: (S+A-P) */ | |
a6bb11b2 | 449 | HOWTO (AARCH64_R (PREL16), /* type */ |
a06ea964 NC |
450 | 0, /* rightshift */ |
451 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
452 | 16, /* bitsize */ | |
453 | TRUE, /* pc_relative */ | |
454 | 0, /* bitpos */ | |
455 | complain_overflow_signed, /* complain_on_overflow */ | |
456 | bfd_elf_generic_reloc, /* special_function */ | |
a6bb11b2 | 457 | AARCH64_R_STR (PREL16), /* name */ |
a06ea964 NC |
458 | FALSE, /* partial_inplace */ |
459 | 0xffff, /* src_mask */ | |
460 | 0xffff, /* dst_mask */ | |
461 | TRUE), /* pcrel_offset */ | |
462 | ||
463 | /* Group relocations to create a 16, 32, 48 or 64 bit | |
464 | unsigned data or abs address inline. */ | |
465 | ||
466 | /* MOVZ: ((S+A) >> 0) & 0xffff */ | |
a6bb11b2 | 467 | HOWTO (AARCH64_R (MOVW_UABS_G0), /* type */ |
a06ea964 NC |
468 | 0, /* rightshift */ |
469 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
470 | 16, /* bitsize */ | |
471 | FALSE, /* pc_relative */ | |
472 | 0, /* bitpos */ | |
473 | complain_overflow_unsigned, /* complain_on_overflow */ | |
474 | bfd_elf_generic_reloc, /* special_function */ | |
a6bb11b2 | 475 | AARCH64_R_STR (MOVW_UABS_G0), /* name */ |
a06ea964 NC |
476 | FALSE, /* partial_inplace */ |
477 | 0xffff, /* src_mask */ | |
478 | 0xffff, /* dst_mask */ | |
479 | FALSE), /* pcrel_offset */ | |
480 | ||
481 | /* MOVK: ((S+A) >> 0) & 0xffff [no overflow check] */ | |
a6bb11b2 | 482 | HOWTO (AARCH64_R (MOVW_UABS_G0_NC), /* type */ |
a06ea964 NC |
483 | 0, /* rightshift */ |
484 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
485 | 16, /* bitsize */ | |
486 | FALSE, /* pc_relative */ | |
487 | 0, /* bitpos */ | |
488 | complain_overflow_dont, /* complain_on_overflow */ | |
489 | bfd_elf_generic_reloc, /* special_function */ | |
a6bb11b2 | 490 | AARCH64_R_STR (MOVW_UABS_G0_NC), /* name */ |
a06ea964 NC |
491 | FALSE, /* partial_inplace */ |
492 | 0xffff, /* src_mask */ | |
493 | 0xffff, /* dst_mask */ | |
494 | FALSE), /* pcrel_offset */ | |
495 | ||
496 | /* MOVZ: ((S+A) >> 16) & 0xffff */ | |
a6bb11b2 | 497 | HOWTO (AARCH64_R (MOVW_UABS_G1), /* type */ |
a06ea964 NC |
498 | 16, /* rightshift */ |
499 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
500 | 16, /* bitsize */ | |
501 | FALSE, /* pc_relative */ | |
502 | 0, /* bitpos */ | |
503 | complain_overflow_unsigned, /* complain_on_overflow */ | |
504 | bfd_elf_generic_reloc, /* special_function */ | |
a6bb11b2 | 505 | AARCH64_R_STR (MOVW_UABS_G1), /* name */ |
a06ea964 NC |
506 | FALSE, /* partial_inplace */ |
507 | 0xffff, /* src_mask */ | |
508 | 0xffff, /* dst_mask */ | |
509 | FALSE), /* pcrel_offset */ | |
510 | ||
511 | /* MOVK: ((S+A) >> 16) & 0xffff [no overflow check] */ | |
a6bb11b2 | 512 | HOWTO64 (AARCH64_R (MOVW_UABS_G1_NC), /* type */ |
a06ea964 NC |
513 | 16, /* rightshift */ |
514 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
515 | 16, /* bitsize */ | |
516 | FALSE, /* pc_relative */ | |
517 | 0, /* bitpos */ | |
518 | complain_overflow_dont, /* complain_on_overflow */ | |
519 | bfd_elf_generic_reloc, /* special_function */ | |
a6bb11b2 | 520 | AARCH64_R_STR (MOVW_UABS_G1_NC), /* name */ |
a06ea964 NC |
521 | FALSE, /* partial_inplace */ |
522 | 0xffff, /* src_mask */ | |
523 | 0xffff, /* dst_mask */ | |
524 | FALSE), /* pcrel_offset */ | |
525 | ||
526 | /* MOVZ: ((S+A) >> 32) & 0xffff */ | |
a6bb11b2 | 527 | HOWTO64 (AARCH64_R (MOVW_UABS_G2), /* type */ |
a06ea964 NC |
528 | 32, /* rightshift */ |
529 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
530 | 16, /* bitsize */ | |
531 | FALSE, /* pc_relative */ | |
532 | 0, /* bitpos */ | |
533 | complain_overflow_unsigned, /* complain_on_overflow */ | |
534 | bfd_elf_generic_reloc, /* special_function */ | |
a6bb11b2 | 535 | AARCH64_R_STR (MOVW_UABS_G2), /* name */ |
a06ea964 NC |
536 | FALSE, /* partial_inplace */ |
537 | 0xffff, /* src_mask */ | |
538 | 0xffff, /* dst_mask */ | |
539 | FALSE), /* pcrel_offset */ | |
540 | ||
541 | /* MOVK: ((S+A) >> 32) & 0xffff [no overflow check] */ | |
a6bb11b2 | 542 | HOWTO64 (AARCH64_R (MOVW_UABS_G2_NC), /* type */ |
a06ea964 NC |
543 | 32, /* rightshift */ |
544 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
545 | 16, /* bitsize */ | |
546 | FALSE, /* pc_relative */ | |
547 | 0, /* bitpos */ | |
548 | complain_overflow_dont, /* complain_on_overflow */ | |
549 | bfd_elf_generic_reloc, /* special_function */ | |
a6bb11b2 | 550 | AARCH64_R_STR (MOVW_UABS_G2_NC), /* name */ |
a06ea964 NC |
551 | FALSE, /* partial_inplace */ |
552 | 0xffff, /* src_mask */ | |
553 | 0xffff, /* dst_mask */ | |
554 | FALSE), /* pcrel_offset */ | |
555 | ||
556 | /* MOVZ: ((S+A) >> 48) & 0xffff */ | |
a6bb11b2 | 557 | HOWTO64 (AARCH64_R (MOVW_UABS_G3), /* type */ |
a06ea964 NC |
558 | 48, /* rightshift */ |
559 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
560 | 16, /* bitsize */ | |
561 | FALSE, /* pc_relative */ | |
562 | 0, /* bitpos */ | |
563 | complain_overflow_unsigned, /* complain_on_overflow */ | |
564 | bfd_elf_generic_reloc, /* special_function */ | |
a6bb11b2 | 565 | AARCH64_R_STR (MOVW_UABS_G3), /* name */ |
a06ea964 NC |
566 | FALSE, /* partial_inplace */ |
567 | 0xffff, /* src_mask */ | |
568 | 0xffff, /* dst_mask */ | |
569 | FALSE), /* pcrel_offset */ | |
570 | ||
571 | /* Group relocations to create high part of a 16, 32, 48 or 64 bit | |
572 | signed data or abs address inline. Will change instruction | |
573 | to MOVN or MOVZ depending on sign of calculated value. */ | |
574 | ||
575 | /* MOV[ZN]: ((S+A) >> 0) & 0xffff */ | |
a6bb11b2 | 576 | HOWTO (AARCH64_R (MOVW_SABS_G0), /* type */ |
a06ea964 NC |
577 | 0, /* rightshift */ |
578 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
c5e3a364 | 579 | 17, /* bitsize */ |
a06ea964 NC |
580 | FALSE, /* pc_relative */ |
581 | 0, /* bitpos */ | |
582 | complain_overflow_signed, /* complain_on_overflow */ | |
583 | bfd_elf_generic_reloc, /* special_function */ | |
a6bb11b2 | 584 | AARCH64_R_STR (MOVW_SABS_G0), /* name */ |
a06ea964 NC |
585 | FALSE, /* partial_inplace */ |
586 | 0xffff, /* src_mask */ | |
587 | 0xffff, /* dst_mask */ | |
588 | FALSE), /* pcrel_offset */ | |
589 | ||
590 | /* MOV[ZN]: ((S+A) >> 16) & 0xffff */ | |
a6bb11b2 | 591 | HOWTO64 (AARCH64_R (MOVW_SABS_G1), /* type */ |
a06ea964 NC |
592 | 16, /* rightshift */ |
593 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
c5e3a364 | 594 | 17, /* bitsize */ |
a06ea964 NC |
595 | FALSE, /* pc_relative */ |
596 | 0, /* bitpos */ | |
597 | complain_overflow_signed, /* complain_on_overflow */ | |
598 | bfd_elf_generic_reloc, /* special_function */ | |
a6bb11b2 | 599 | AARCH64_R_STR (MOVW_SABS_G1), /* name */ |
a06ea964 NC |
600 | FALSE, /* partial_inplace */ |
601 | 0xffff, /* src_mask */ | |
602 | 0xffff, /* dst_mask */ | |
603 | FALSE), /* pcrel_offset */ | |
604 | ||
605 | /* MOV[ZN]: ((S+A) >> 32) & 0xffff */ | |
a6bb11b2 | 606 | HOWTO64 (AARCH64_R (MOVW_SABS_G2), /* type */ |
a06ea964 NC |
607 | 32, /* rightshift */ |
608 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
c5e3a364 | 609 | 17, /* bitsize */ |
a06ea964 NC |
610 | FALSE, /* pc_relative */ |
611 | 0, /* bitpos */ | |
612 | complain_overflow_signed, /* complain_on_overflow */ | |
613 | bfd_elf_generic_reloc, /* special_function */ | |
a6bb11b2 | 614 | AARCH64_R_STR (MOVW_SABS_G2), /* name */ |
a06ea964 NC |
615 | FALSE, /* partial_inplace */ |
616 | 0xffff, /* src_mask */ | |
617 | 0xffff, /* dst_mask */ | |
618 | FALSE), /* pcrel_offset */ | |
619 | ||
620 | /* Relocations to generate 19, 21 and 33 bit PC-relative load/store | |
621 | addresses: PG(x) is (x & ~0xfff). */ | |
622 | ||
623 | /* LD-lit: ((S+A-P) >> 2) & 0x7ffff */ | |
a6bb11b2 | 624 | HOWTO (AARCH64_R (LD_PREL_LO19), /* type */ |
a06ea964 NC |
625 | 2, /* rightshift */ |
626 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
627 | 19, /* bitsize */ | |
628 | TRUE, /* pc_relative */ | |
629 | 0, /* bitpos */ | |
630 | complain_overflow_signed, /* complain_on_overflow */ | |
631 | bfd_elf_generic_reloc, /* special_function */ | |
a6bb11b2 | 632 | AARCH64_R_STR (LD_PREL_LO19), /* name */ |
a06ea964 NC |
633 | FALSE, /* partial_inplace */ |
634 | 0x7ffff, /* src_mask */ | |
635 | 0x7ffff, /* dst_mask */ | |
636 | TRUE), /* pcrel_offset */ | |
637 | ||
638 | /* ADR: (S+A-P) & 0x1fffff */ | |
a6bb11b2 | 639 | HOWTO (AARCH64_R (ADR_PREL_LO21), /* type */ |
a06ea964 NC |
640 | 0, /* rightshift */ |
641 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
642 | 21, /* bitsize */ | |
643 | TRUE, /* pc_relative */ | |
644 | 0, /* bitpos */ | |
645 | complain_overflow_signed, /* complain_on_overflow */ | |
646 | bfd_elf_generic_reloc, /* special_function */ | |
a6bb11b2 | 647 | AARCH64_R_STR (ADR_PREL_LO21), /* name */ |
a06ea964 NC |
648 | FALSE, /* partial_inplace */ |
649 | 0x1fffff, /* src_mask */ | |
650 | 0x1fffff, /* dst_mask */ | |
651 | TRUE), /* pcrel_offset */ | |
652 | ||
653 | /* ADRP: ((PG(S+A)-PG(P)) >> 12) & 0x1fffff */ | |
a6bb11b2 | 654 | HOWTO (AARCH64_R (ADR_PREL_PG_HI21), /* type */ |
a06ea964 NC |
655 | 12, /* rightshift */ |
656 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
657 | 21, /* bitsize */ | |
658 | TRUE, /* pc_relative */ | |
659 | 0, /* bitpos */ | |
660 | complain_overflow_signed, /* complain_on_overflow */ | |
661 | bfd_elf_generic_reloc, /* special_function */ | |
a6bb11b2 | 662 | AARCH64_R_STR (ADR_PREL_PG_HI21), /* name */ |
a06ea964 NC |
663 | FALSE, /* partial_inplace */ |
664 | 0x1fffff, /* src_mask */ | |
665 | 0x1fffff, /* dst_mask */ | |
666 | TRUE), /* pcrel_offset */ | |
667 | ||
668 | /* ADRP: ((PG(S+A)-PG(P)) >> 12) & 0x1fffff [no overflow check] */ | |
a6bb11b2 | 669 | HOWTO64 (AARCH64_R (ADR_PREL_PG_HI21_NC), /* type */ |
a06ea964 NC |
670 | 12, /* rightshift */ |
671 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
672 | 21, /* bitsize */ | |
673 | TRUE, /* pc_relative */ | |
674 | 0, /* bitpos */ | |
675 | complain_overflow_dont, /* complain_on_overflow */ | |
676 | bfd_elf_generic_reloc, /* special_function */ | |
a6bb11b2 | 677 | AARCH64_R_STR (ADR_PREL_PG_HI21_NC), /* name */ |
a06ea964 NC |
678 | FALSE, /* partial_inplace */ |
679 | 0x1fffff, /* src_mask */ | |
680 | 0x1fffff, /* dst_mask */ | |
681 | TRUE), /* pcrel_offset */ | |
682 | ||
683 | /* ADD: (S+A) & 0xfff [no overflow check] */ | |
a6bb11b2 | 684 | HOWTO (AARCH64_R (ADD_ABS_LO12_NC), /* type */ |
a06ea964 NC |
685 | 0, /* rightshift */ |
686 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
687 | 12, /* bitsize */ | |
688 | FALSE, /* pc_relative */ | |
689 | 10, /* bitpos */ | |
690 | complain_overflow_dont, /* complain_on_overflow */ | |
691 | bfd_elf_generic_reloc, /* special_function */ | |
a6bb11b2 | 692 | AARCH64_R_STR (ADD_ABS_LO12_NC), /* name */ |
a06ea964 NC |
693 | FALSE, /* partial_inplace */ |
694 | 0x3ffc00, /* src_mask */ | |
695 | 0x3ffc00, /* dst_mask */ | |
696 | FALSE), /* pcrel_offset */ | |
697 | ||
698 | /* LD/ST8: (S+A) & 0xfff */ | |
a6bb11b2 | 699 | HOWTO (AARCH64_R (LDST8_ABS_LO12_NC), /* type */ |
a06ea964 NC |
700 | 0, /* rightshift */ |
701 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
702 | 12, /* bitsize */ | |
703 | FALSE, /* pc_relative */ | |
704 | 0, /* bitpos */ | |
705 | complain_overflow_dont, /* complain_on_overflow */ | |
706 | bfd_elf_generic_reloc, /* special_function */ | |
a6bb11b2 | 707 | AARCH64_R_STR (LDST8_ABS_LO12_NC), /* name */ |
a06ea964 NC |
708 | FALSE, /* partial_inplace */ |
709 | 0xfff, /* src_mask */ | |
710 | 0xfff, /* dst_mask */ | |
711 | FALSE), /* pcrel_offset */ | |
712 | ||
713 | /* Relocations for control-flow instructions. */ | |
714 | ||
715 | /* TBZ/NZ: ((S+A-P) >> 2) & 0x3fff */ | |
a6bb11b2 | 716 | HOWTO (AARCH64_R (TSTBR14), /* type */ |
a06ea964 NC |
717 | 2, /* rightshift */ |
718 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
719 | 14, /* bitsize */ | |
720 | TRUE, /* pc_relative */ | |
721 | 0, /* bitpos */ | |
722 | complain_overflow_signed, /* complain_on_overflow */ | |
723 | bfd_elf_generic_reloc, /* special_function */ | |
a6bb11b2 | 724 | AARCH64_R_STR (TSTBR14), /* name */ |
a06ea964 NC |
725 | FALSE, /* partial_inplace */ |
726 | 0x3fff, /* src_mask */ | |
727 | 0x3fff, /* dst_mask */ | |
728 | TRUE), /* pcrel_offset */ | |
729 | ||
730 | /* B.cond: ((S+A-P) >> 2) & 0x7ffff */ | |
a6bb11b2 | 731 | HOWTO (AARCH64_R (CONDBR19), /* type */ |
a06ea964 NC |
732 | 2, /* rightshift */ |
733 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
734 | 19, /* bitsize */ | |
735 | TRUE, /* pc_relative */ | |
736 | 0, /* bitpos */ | |
737 | complain_overflow_signed, /* complain_on_overflow */ | |
738 | bfd_elf_generic_reloc, /* special_function */ | |
a6bb11b2 | 739 | AARCH64_R_STR (CONDBR19), /* name */ |
a06ea964 NC |
740 | FALSE, /* partial_inplace */ |
741 | 0x7ffff, /* src_mask */ | |
742 | 0x7ffff, /* dst_mask */ | |
743 | TRUE), /* pcrel_offset */ | |
744 | ||
a06ea964 | 745 | /* B: ((S+A-P) >> 2) & 0x3ffffff */ |
a6bb11b2 | 746 | HOWTO (AARCH64_R (JUMP26), /* type */ |
a06ea964 NC |
747 | 2, /* rightshift */ |
748 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
749 | 26, /* bitsize */ | |
750 | TRUE, /* pc_relative */ | |
751 | 0, /* bitpos */ | |
752 | complain_overflow_signed, /* complain_on_overflow */ | |
753 | bfd_elf_generic_reloc, /* special_function */ | |
a6bb11b2 | 754 | AARCH64_R_STR (JUMP26), /* name */ |
a06ea964 NC |
755 | FALSE, /* partial_inplace */ |
756 | 0x3ffffff, /* src_mask */ | |
757 | 0x3ffffff, /* dst_mask */ | |
758 | TRUE), /* pcrel_offset */ | |
759 | ||
760 | /* BL: ((S+A-P) >> 2) & 0x3ffffff */ | |
a6bb11b2 | 761 | HOWTO (AARCH64_R (CALL26), /* type */ |
a06ea964 NC |
762 | 2, /* rightshift */ |
763 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
764 | 26, /* bitsize */ | |
765 | TRUE, /* pc_relative */ | |
766 | 0, /* bitpos */ | |
767 | complain_overflow_signed, /* complain_on_overflow */ | |
768 | bfd_elf_generic_reloc, /* special_function */ | |
a6bb11b2 | 769 | AARCH64_R_STR (CALL26), /* name */ |
a06ea964 NC |
770 | FALSE, /* partial_inplace */ |
771 | 0x3ffffff, /* src_mask */ | |
772 | 0x3ffffff, /* dst_mask */ | |
773 | TRUE), /* pcrel_offset */ | |
774 | ||
775 | /* LD/ST16: (S+A) & 0xffe */ | |
a6bb11b2 | 776 | HOWTO (AARCH64_R (LDST16_ABS_LO12_NC), /* type */ |
a06ea964 NC |
777 | 1, /* rightshift */ |
778 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
779 | 12, /* bitsize */ | |
780 | FALSE, /* pc_relative */ | |
781 | 0, /* bitpos */ | |
782 | complain_overflow_dont, /* complain_on_overflow */ | |
783 | bfd_elf_generic_reloc, /* special_function */ | |
a6bb11b2 | 784 | AARCH64_R_STR (LDST16_ABS_LO12_NC), /* name */ |
a06ea964 NC |
785 | FALSE, /* partial_inplace */ |
786 | 0xffe, /* src_mask */ | |
787 | 0xffe, /* dst_mask */ | |
788 | FALSE), /* pcrel_offset */ | |
789 | ||
790 | /* LD/ST32: (S+A) & 0xffc */ | |
a6bb11b2 | 791 | HOWTO (AARCH64_R (LDST32_ABS_LO12_NC), /* type */ |
a06ea964 NC |
792 | 2, /* rightshift */ |
793 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
794 | 12, /* bitsize */ | |
795 | FALSE, /* pc_relative */ | |
796 | 0, /* bitpos */ | |
797 | complain_overflow_dont, /* complain_on_overflow */ | |
798 | bfd_elf_generic_reloc, /* special_function */ | |
a6bb11b2 | 799 | AARCH64_R_STR (LDST32_ABS_LO12_NC), /* name */ |
a06ea964 NC |
800 | FALSE, /* partial_inplace */ |
801 | 0xffc, /* src_mask */ | |
802 | 0xffc, /* dst_mask */ | |
803 | FALSE), /* pcrel_offset */ | |
804 | ||
805 | /* LD/ST64: (S+A) & 0xff8 */ | |
a6bb11b2 | 806 | HOWTO (AARCH64_R (LDST64_ABS_LO12_NC), /* type */ |
a06ea964 NC |
807 | 3, /* rightshift */ |
808 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
809 | 12, /* bitsize */ | |
810 | FALSE, /* pc_relative */ | |
811 | 0, /* bitpos */ | |
812 | complain_overflow_dont, /* complain_on_overflow */ | |
813 | bfd_elf_generic_reloc, /* special_function */ | |
a6bb11b2 | 814 | AARCH64_R_STR (LDST64_ABS_LO12_NC), /* name */ |
a06ea964 NC |
815 | FALSE, /* partial_inplace */ |
816 | 0xff8, /* src_mask */ | |
817 | 0xff8, /* dst_mask */ | |
818 | FALSE), /* pcrel_offset */ | |
819 | ||
a06ea964 | 820 | /* LD/ST128: (S+A) & 0xff0 */ |
a6bb11b2 | 821 | HOWTO (AARCH64_R (LDST128_ABS_LO12_NC), /* type */ |
a06ea964 NC |
822 | 4, /* rightshift */ |
823 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
824 | 12, /* bitsize */ | |
825 | FALSE, /* pc_relative */ | |
826 | 0, /* bitpos */ | |
827 | complain_overflow_dont, /* complain_on_overflow */ | |
828 | bfd_elf_generic_reloc, /* special_function */ | |
a6bb11b2 | 829 | AARCH64_R_STR (LDST128_ABS_LO12_NC), /* name */ |
a06ea964 NC |
830 | FALSE, /* partial_inplace */ |
831 | 0xff0, /* src_mask */ | |
832 | 0xff0, /* dst_mask */ | |
833 | FALSE), /* pcrel_offset */ | |
834 | ||
f41aef5f RE |
835 | /* Set a load-literal immediate field to bits |
836 | 0x1FFFFC of G(S)-P */ | |
a6bb11b2 | 837 | HOWTO (AARCH64_R (GOT_LD_PREL19), /* type */ |
f41aef5f RE |
838 | 2, /* rightshift */ |
839 | 2, /* size (0 = byte,1 = short,2 = long) */ | |
840 | 19, /* bitsize */ | |
841 | TRUE, /* pc_relative */ | |
842 | 0, /* bitpos */ | |
843 | complain_overflow_signed, /* complain_on_overflow */ | |
844 | bfd_elf_generic_reloc, /* special_function */ | |
a6bb11b2 | 845 | AARCH64_R_STR (GOT_LD_PREL19), /* name */ |
f41aef5f RE |
846 | FALSE, /* partial_inplace */ |
847 | 0xffffe0, /* src_mask */ | |
848 | 0xffffe0, /* dst_mask */ | |
849 | TRUE), /* pcrel_offset */ | |
850 | ||
a06ea964 NC |
851 | /* Get to the page for the GOT entry for the symbol |
852 | (G(S) - P) using an ADRP instruction. */ | |
a6bb11b2 | 853 | HOWTO (AARCH64_R (ADR_GOT_PAGE), /* type */ |
a06ea964 NC |
854 | 12, /* rightshift */ |
855 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
856 | 21, /* bitsize */ | |
857 | TRUE, /* pc_relative */ | |
858 | 0, /* bitpos */ | |
859 | complain_overflow_dont, /* complain_on_overflow */ | |
860 | bfd_elf_generic_reloc, /* special_function */ | |
a6bb11b2 | 861 | AARCH64_R_STR (ADR_GOT_PAGE), /* name */ |
a06ea964 NC |
862 | FALSE, /* partial_inplace */ |
863 | 0x1fffff, /* src_mask */ | |
864 | 0x1fffff, /* dst_mask */ | |
865 | TRUE), /* pcrel_offset */ | |
866 | ||
a6bb11b2 YZ |
867 | /* LD64: GOT offset G(S) & 0xff8 */ |
868 | HOWTO64 (AARCH64_R (LD64_GOT_LO12_NC), /* type */ | |
a06ea964 NC |
869 | 3, /* rightshift */ |
870 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
871 | 12, /* bitsize */ | |
872 | FALSE, /* pc_relative */ | |
873 | 0, /* bitpos */ | |
874 | complain_overflow_dont, /* complain_on_overflow */ | |
875 | bfd_elf_generic_reloc, /* special_function */ | |
a6bb11b2 | 876 | AARCH64_R_STR (LD64_GOT_LO12_NC), /* name */ |
a06ea964 NC |
877 | FALSE, /* partial_inplace */ |
878 | 0xff8, /* src_mask */ | |
879 | 0xff8, /* dst_mask */ | |
a6bb11b2 | 880 | FALSE), /* pcrel_offset */ |
a06ea964 | 881 | |
a6bb11b2 YZ |
882 | /* LD32: GOT offset G(S) & 0xffc */ |
883 | HOWTO32 (AARCH64_R (LD32_GOT_LO12_NC), /* type */ | |
884 | 2, /* rightshift */ | |
885 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
886 | 12, /* bitsize */ | |
887 | FALSE, /* pc_relative */ | |
888 | 0, /* bitpos */ | |
889 | complain_overflow_dont, /* complain_on_overflow */ | |
890 | bfd_elf_generic_reloc, /* special_function */ | |
891 | AARCH64_R_STR (LD32_GOT_LO12_NC), /* name */ | |
892 | FALSE, /* partial_inplace */ | |
893 | 0xffc, /* src_mask */ | |
894 | 0xffc, /* dst_mask */ | |
895 | FALSE), /* pcrel_offset */ | |
a06ea964 | 896 | |
ca632371 RL |
897 | /* Lower 16 bits of GOT offset for the symbol. */ |
898 | HOWTO64 (AARCH64_R (MOVW_GOTOFF_G0_NC), /* type */ | |
899 | 0, /* rightshift */ | |
900 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
901 | 16, /* bitsize */ | |
902 | FALSE, /* pc_relative */ | |
903 | 0, /* bitpos */ | |
904 | complain_overflow_dont, /* complain_on_overflow */ | |
905 | bfd_elf_generic_reloc, /* special_function */ | |
906 | AARCH64_R_STR (MOVW_GOTOFF_G0_NC), /* name */ | |
907 | FALSE, /* partial_inplace */ | |
908 | 0xffff, /* src_mask */ | |
909 | 0xffff, /* dst_mask */ | |
910 | FALSE), /* pcrel_offset */ | |
911 | ||
654248e7 RL |
912 | /* Higher 16 bits of GOT offset for the symbol. */ |
913 | HOWTO64 (AARCH64_R (MOVW_GOTOFF_G1), /* type */ | |
914 | 16, /* rightshift */ | |
915 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
916 | 16, /* bitsize */ | |
917 | FALSE, /* pc_relative */ | |
918 | 0, /* bitpos */ | |
919 | complain_overflow_unsigned, /* complain_on_overflow */ | |
920 | bfd_elf_generic_reloc, /* special_function */ | |
921 | AARCH64_R_STR (MOVW_GOTOFF_G1), /* name */ | |
922 | FALSE, /* partial_inplace */ | |
923 | 0xffff, /* src_mask */ | |
924 | 0xffff, /* dst_mask */ | |
925 | FALSE), /* pcrel_offset */ | |
926 | ||
87f5fbcc RL |
927 | /* LD64: GOT offset for the symbol. */ |
928 | HOWTO64 (AARCH64_R (LD64_GOTOFF_LO15), /* type */ | |
929 | 3, /* rightshift */ | |
930 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
931 | 12, /* bitsize */ | |
932 | FALSE, /* pc_relative */ | |
933 | 0, /* bitpos */ | |
934 | complain_overflow_unsigned, /* complain_on_overflow */ | |
935 | bfd_elf_generic_reloc, /* special_function */ | |
936 | AARCH64_R_STR (LD64_GOTOFF_LO15), /* name */ | |
937 | FALSE, /* partial_inplace */ | |
938 | 0x7ff8, /* src_mask */ | |
939 | 0x7ff8, /* dst_mask */ | |
940 | FALSE), /* pcrel_offset */ | |
941 | ||
3d715ce4 JW |
942 | /* LD32: GOT offset to the page address of GOT table. |
943 | (G(S) - PAGE (_GLOBAL_OFFSET_TABLE_)) & 0x5ffc. */ | |
944 | HOWTO32 (AARCH64_R (LD32_GOTPAGE_LO14), /* type */ | |
945 | 2, /* rightshift */ | |
946 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
947 | 12, /* bitsize */ | |
948 | FALSE, /* pc_relative */ | |
949 | 0, /* bitpos */ | |
950 | complain_overflow_unsigned, /* complain_on_overflow */ | |
951 | bfd_elf_generic_reloc, /* special_function */ | |
952 | AARCH64_R_STR (LD32_GOTPAGE_LO14), /* name */ | |
953 | FALSE, /* partial_inplace */ | |
954 | 0x5ffc, /* src_mask */ | |
955 | 0x5ffc, /* dst_mask */ | |
956 | FALSE), /* pcrel_offset */ | |
957 | ||
a921b5bd JW |
958 | /* LD64: GOT offset to the page address of GOT table. |
959 | (G(S) - PAGE (_GLOBAL_OFFSET_TABLE_)) & 0x7ff8. */ | |
960 | HOWTO64 (AARCH64_R (LD64_GOTPAGE_LO15), /* type */ | |
961 | 3, /* rightshift */ | |
962 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
963 | 12, /* bitsize */ | |
964 | FALSE, /* pc_relative */ | |
965 | 0, /* bitpos */ | |
966 | complain_overflow_unsigned, /* complain_on_overflow */ | |
967 | bfd_elf_generic_reloc, /* special_function */ | |
968 | AARCH64_R_STR (LD64_GOTPAGE_LO15), /* name */ | |
969 | FALSE, /* partial_inplace */ | |
970 | 0x7ff8, /* src_mask */ | |
971 | 0x7ff8, /* dst_mask */ | |
972 | FALSE), /* pcrel_offset */ | |
973 | ||
a06ea964 NC |
974 | /* Get to the page for the GOT entry for the symbol |
975 | (G(S) - P) using an ADRP instruction. */ | |
a6bb11b2 | 976 | HOWTO (AARCH64_R (TLSGD_ADR_PAGE21), /* type */ |
a06ea964 NC |
977 | 12, /* rightshift */ |
978 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
979 | 21, /* bitsize */ | |
980 | TRUE, /* pc_relative */ | |
981 | 0, /* bitpos */ | |
982 | complain_overflow_dont, /* complain_on_overflow */ | |
983 | bfd_elf_generic_reloc, /* special_function */ | |
a6bb11b2 | 984 | AARCH64_R_STR (TLSGD_ADR_PAGE21), /* name */ |
a06ea964 NC |
985 | FALSE, /* partial_inplace */ |
986 | 0x1fffff, /* src_mask */ | |
987 | 0x1fffff, /* dst_mask */ | |
988 | TRUE), /* pcrel_offset */ | |
989 | ||
3c12b054 MS |
990 | HOWTO (AARCH64_R (TLSGD_ADR_PREL21), /* type */ |
991 | 0, /* rightshift */ | |
992 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
993 | 21, /* bitsize */ | |
994 | TRUE, /* pc_relative */ | |
995 | 0, /* bitpos */ | |
996 | complain_overflow_dont, /* complain_on_overflow */ | |
997 | bfd_elf_generic_reloc, /* special_function */ | |
998 | AARCH64_R_STR (TLSGD_ADR_PREL21), /* name */ | |
999 | FALSE, /* partial_inplace */ | |
1000 | 0x1fffff, /* src_mask */ | |
1001 | 0x1fffff, /* dst_mask */ | |
1002 | TRUE), /* pcrel_offset */ | |
1003 | ||
a06ea964 | 1004 | /* ADD: GOT offset G(S) & 0xff8 [no overflow check] */ |
a6bb11b2 | 1005 | HOWTO (AARCH64_R (TLSGD_ADD_LO12_NC), /* type */ |
a06ea964 NC |
1006 | 0, /* rightshift */ |
1007 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1008 | 12, /* bitsize */ | |
1009 | FALSE, /* pc_relative */ | |
1010 | 0, /* bitpos */ | |
1011 | complain_overflow_dont, /* complain_on_overflow */ | |
1012 | bfd_elf_generic_reloc, /* special_function */ | |
a6bb11b2 | 1013 | AARCH64_R_STR (TLSGD_ADD_LO12_NC), /* name */ |
a06ea964 NC |
1014 | FALSE, /* partial_inplace */ |
1015 | 0xfff, /* src_mask */ | |
1016 | 0xfff, /* dst_mask */ | |
1017 | FALSE), /* pcrel_offset */ | |
1018 | ||
3e8286c0 RL |
1019 | /* Lower 16 bits of GOT offset to tls_index. */ |
1020 | HOWTO64 (AARCH64_R (TLSGD_MOVW_G0_NC), /* type */ | |
1021 | 0, /* rightshift */ | |
1022 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1023 | 16, /* bitsize */ | |
1024 | FALSE, /* pc_relative */ | |
1025 | 0, /* bitpos */ | |
1026 | complain_overflow_dont, /* complain_on_overflow */ | |
1027 | bfd_elf_generic_reloc, /* special_function */ | |
1028 | AARCH64_R_STR (TLSGD_MOVW_G0_NC), /* name */ | |
1029 | FALSE, /* partial_inplace */ | |
1030 | 0xffff, /* src_mask */ | |
1031 | 0xffff, /* dst_mask */ | |
1032 | FALSE), /* pcrel_offset */ | |
1033 | ||
1aa66fb1 RL |
1034 | /* Higher 16 bits of GOT offset to tls_index. */ |
1035 | HOWTO64 (AARCH64_R (TLSGD_MOVW_G1), /* type */ | |
1036 | 16, /* rightshift */ | |
1037 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1038 | 16, /* bitsize */ | |
1039 | FALSE, /* pc_relative */ | |
1040 | 0, /* bitpos */ | |
1041 | complain_overflow_unsigned, /* complain_on_overflow */ | |
1042 | bfd_elf_generic_reloc, /* special_function */ | |
1043 | AARCH64_R_STR (TLSGD_MOVW_G1), /* name */ | |
1044 | FALSE, /* partial_inplace */ | |
1045 | 0xffff, /* src_mask */ | |
1046 | 0xffff, /* dst_mask */ | |
1047 | FALSE), /* pcrel_offset */ | |
1048 | ||
a6bb11b2 | 1049 | HOWTO (AARCH64_R (TLSIE_ADR_GOTTPREL_PAGE21), /* type */ |
a06ea964 NC |
1050 | 12, /* rightshift */ |
1051 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1052 | 21, /* bitsize */ | |
1053 | FALSE, /* pc_relative */ | |
1054 | 0, /* bitpos */ | |
1055 | complain_overflow_dont, /* complain_on_overflow */ | |
1056 | bfd_elf_generic_reloc, /* special_function */ | |
a6bb11b2 | 1057 | AARCH64_R_STR (TLSIE_ADR_GOTTPREL_PAGE21), /* name */ |
a06ea964 NC |
1058 | FALSE, /* partial_inplace */ |
1059 | 0x1fffff, /* src_mask */ | |
1060 | 0x1fffff, /* dst_mask */ | |
1061 | FALSE), /* pcrel_offset */ | |
1062 | ||
a6bb11b2 | 1063 | HOWTO64 (AARCH64_R (TLSIE_LD64_GOTTPREL_LO12_NC), /* type */ |
a06ea964 NC |
1064 | 3, /* rightshift */ |
1065 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1066 | 12, /* bitsize */ | |
1067 | FALSE, /* pc_relative */ | |
1068 | 0, /* bitpos */ | |
1069 | complain_overflow_dont, /* complain_on_overflow */ | |
1070 | bfd_elf_generic_reloc, /* special_function */ | |
a6bb11b2 | 1071 | AARCH64_R_STR (TLSIE_LD64_GOTTPREL_LO12_NC), /* name */ |
a06ea964 NC |
1072 | FALSE, /* partial_inplace */ |
1073 | 0xff8, /* src_mask */ | |
1074 | 0xff8, /* dst_mask */ | |
1075 | FALSE), /* pcrel_offset */ | |
1076 | ||
a6bb11b2 YZ |
1077 | HOWTO32 (AARCH64_R (TLSIE_LD32_GOTTPREL_LO12_NC), /* type */ |
1078 | 2, /* rightshift */ | |
1079 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1080 | 12, /* bitsize */ | |
1081 | FALSE, /* pc_relative */ | |
1082 | 0, /* bitpos */ | |
1083 | complain_overflow_dont, /* complain_on_overflow */ | |
1084 | bfd_elf_generic_reloc, /* special_function */ | |
1085 | AARCH64_R_STR (TLSIE_LD32_GOTTPREL_LO12_NC), /* name */ | |
1086 | FALSE, /* partial_inplace */ | |
1087 | 0xffc, /* src_mask */ | |
1088 | 0xffc, /* dst_mask */ | |
1089 | FALSE), /* pcrel_offset */ | |
1090 | ||
1091 | HOWTO (AARCH64_R (TLSIE_LD_GOTTPREL_PREL19), /* type */ | |
bb3f9ed8 | 1092 | 2, /* rightshift */ |
a06ea964 | 1093 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
043bf05a | 1094 | 19, /* bitsize */ |
a06ea964 NC |
1095 | FALSE, /* pc_relative */ |
1096 | 0, /* bitpos */ | |
1097 | complain_overflow_dont, /* complain_on_overflow */ | |
1098 | bfd_elf_generic_reloc, /* special_function */ | |
a6bb11b2 | 1099 | AARCH64_R_STR (TLSIE_LD_GOTTPREL_PREL19), /* name */ |
a06ea964 NC |
1100 | FALSE, /* partial_inplace */ |
1101 | 0x1ffffc, /* src_mask */ | |
1102 | 0x1ffffc, /* dst_mask */ | |
1103 | FALSE), /* pcrel_offset */ | |
1104 | ||
3b957e5b RL |
1105 | HOWTO64 (AARCH64_R (TLSIE_MOVW_GOTTPREL_G0_NC), /* type */ |
1106 | 0, /* rightshift */ | |
1107 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1108 | 16, /* bitsize */ | |
1109 | FALSE, /* pc_relative */ | |
1110 | 0, /* bitpos */ | |
1111 | complain_overflow_dont, /* complain_on_overflow */ | |
1112 | bfd_elf_generic_reloc, /* special_function */ | |
1113 | AARCH64_R_STR (TLSIE_MOVW_GOTTPREL_G0_NC), /* name */ | |
1114 | FALSE, /* partial_inplace */ | |
1115 | 0xffff, /* src_mask */ | |
1116 | 0xffff, /* dst_mask */ | |
1117 | FALSE), /* pcrel_offset */ | |
1118 | ||
1119 | HOWTO64 (AARCH64_R (TLSIE_MOVW_GOTTPREL_G1), /* type */ | |
1120 | 16, /* rightshift */ | |
1121 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
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 (TLSIE_MOVW_GOTTPREL_G1), /* name */ | |
1128 | FALSE, /* partial_inplace */ | |
1129 | 0xffff, /* src_mask */ | |
1130 | 0xffff, /* dst_mask */ | |
1131 | FALSE), /* pcrel_offset */ | |
1132 | ||
49df5539 JW |
1133 | /* ADD: bit[23:12] of byte offset to module TLS base address. */ |
1134 | HOWTO (AARCH64_R (TLSLD_ADD_DTPREL_HI12), /* type */ | |
1135 | 12, /* rightshift */ | |
1136 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
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 (TLSLD_ADD_DTPREL_HI12), /* name */ | |
1143 | FALSE, /* partial_inplace */ | |
1144 | 0xfff, /* src_mask */ | |
1145 | 0xfff, /* dst_mask */ | |
1146 | FALSE), /* pcrel_offset */ | |
1147 | ||
70151fb5 JW |
1148 | /* Unsigned 12 bit byte offset to module TLS base address. */ |
1149 | HOWTO (AARCH64_R (TLSLD_ADD_DTPREL_LO12), /* type */ | |
1150 | 0, /* rightshift */ | |
1151 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1152 | 12, /* bitsize */ | |
1153 | FALSE, /* pc_relative */ | |
1154 | 0, /* bitpos */ | |
1155 | complain_overflow_unsigned, /* complain_on_overflow */ | |
1156 | bfd_elf_generic_reloc, /* special_function */ | |
1157 | AARCH64_R_STR (TLSLD_ADD_DTPREL_LO12), /* name */ | |
1158 | FALSE, /* partial_inplace */ | |
1159 | 0xfff, /* src_mask */ | |
1160 | 0xfff, /* dst_mask */ | |
1161 | FALSE), /* pcrel_offset */ | |
13289c10 JW |
1162 | |
1163 | /* No overflow check version of BFD_RELOC_AARCH64_TLSLD_ADD_DTPREL_LO12. */ | |
1164 | HOWTO (AARCH64_R (TLSLD_ADD_DTPREL_LO12_NC), /* type */ | |
1165 | 0, /* rightshift */ | |
1166 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1167 | 12, /* bitsize */ | |
1168 | FALSE, /* pc_relative */ | |
1169 | 0, /* bitpos */ | |
1170 | complain_overflow_dont, /* complain_on_overflow */ | |
1171 | bfd_elf_generic_reloc, /* special_function */ | |
1172 | AARCH64_R_STR (TLSLD_ADD_DTPREL_LO12_NC), /* name */ | |
1173 | FALSE, /* partial_inplace */ | |
1174 | 0xfff, /* src_mask */ | |
1175 | 0xfff, /* dst_mask */ | |
1176 | FALSE), /* pcrel_offset */ | |
70151fb5 | 1177 | |
a12fad50 JW |
1178 | /* ADD: GOT offset G(S) & 0xff8 [no overflow check] */ |
1179 | HOWTO (AARCH64_R (TLSLD_ADD_LO12_NC), /* type */ | |
1180 | 0, /* rightshift */ | |
1181 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1182 | 12, /* bitsize */ | |
1183 | FALSE, /* pc_relative */ | |
1184 | 0, /* bitpos */ | |
1185 | complain_overflow_dont, /* complain_on_overflow */ | |
1186 | bfd_elf_generic_reloc, /* special_function */ | |
1187 | AARCH64_R_STR (TLSLD_ADD_LO12_NC), /* name */ | |
1188 | FALSE, /* partial_inplace */ | |
1189 | 0xfff, /* src_mask */ | |
1190 | 0xfff, /* dst_mask */ | |
1191 | FALSE), /* pcrel_offset */ | |
1192 | ||
1107e076 JW |
1193 | /* Get to the page for the GOT entry for the symbol |
1194 | (G(S) - P) using an ADRP instruction. */ | |
1195 | HOWTO (AARCH64_R (TLSLD_ADR_PAGE21), /* type */ | |
1196 | 12, /* rightshift */ | |
1197 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1198 | 21, /* bitsize */ | |
1199 | TRUE, /* pc_relative */ | |
1200 | 0, /* bitpos */ | |
1201 | complain_overflow_signed, /* complain_on_overflow */ | |
1202 | bfd_elf_generic_reloc, /* special_function */ | |
1203 | AARCH64_R_STR (TLSLD_ADR_PAGE21), /* name */ | |
1204 | FALSE, /* partial_inplace */ | |
1205 | 0x1fffff, /* src_mask */ | |
1206 | 0x1fffff, /* dst_mask */ | |
1207 | TRUE), /* pcrel_offset */ | |
1208 | ||
6c37fedc JW |
1209 | HOWTO (AARCH64_R (TLSLD_ADR_PREL21), /* type */ |
1210 | 0, /* rightshift */ | |
1211 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1212 | 21, /* bitsize */ | |
1213 | TRUE, /* pc_relative */ | |
1214 | 0, /* bitpos */ | |
1215 | complain_overflow_signed, /* complain_on_overflow */ | |
1216 | bfd_elf_generic_reloc, /* special_function */ | |
1217 | AARCH64_R_STR (TLSLD_ADR_PREL21), /* name */ | |
1218 | FALSE, /* partial_inplace */ | |
1219 | 0x1fffff, /* src_mask */ | |
1220 | 0x1fffff, /* dst_mask */ | |
1221 | TRUE), /* pcrel_offset */ | |
1222 | ||
4c562523 JW |
1223 | /* LD/ST16: bit[11:1] of byte offset to module TLS base address. */ |
1224 | HOWTO64 (AARCH64_R (TLSLD_LDST16_DTPREL_LO12), /* type */ | |
1225 | 1, /* rightshift */ | |
1226 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1227 | 11, /* bitsize */ | |
1228 | FALSE, /* pc_relative */ | |
1229 | 10, /* bitpos */ | |
1230 | complain_overflow_unsigned, /* complain_on_overflow */ | |
1231 | bfd_elf_generic_reloc, /* special_function */ | |
1232 | AARCH64_R_STR (TLSLD_LDST16_DTPREL_LO12), /* name */ | |
1233 | FALSE, /* partial_inplace */ | |
1234 | 0x1ffc00, /* src_mask */ | |
1235 | 0x1ffc00, /* dst_mask */ | |
1236 | FALSE), /* pcrel_offset */ | |
1237 | ||
1238 | /* Same as BFD_RELOC_AARCH64_TLSLD_LDST16_DTPREL_LO12, but no overflow check. */ | |
1239 | HOWTO64 (AARCH64_R (TLSLD_LDST16_DTPREL_LO12_NC), /* type */ | |
1240 | 1, /* rightshift */ | |
1241 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1242 | 11, /* bitsize */ | |
1243 | FALSE, /* pc_relative */ | |
1244 | 10, /* bitpos */ | |
1245 | complain_overflow_dont, /* complain_on_overflow */ | |
1246 | bfd_elf_generic_reloc, /* special_function */ | |
1247 | AARCH64_R_STR (TLSLD_LDST16_DTPREL_LO12_NC), /* name */ | |
1248 | FALSE, /* partial_inplace */ | |
1249 | 0x1ffc00, /* src_mask */ | |
1250 | 0x1ffc00, /* dst_mask */ | |
1251 | FALSE), /* pcrel_offset */ | |
1252 | ||
1253 | /* LD/ST32: bit[11:2] of byte offset to module TLS base address. */ | |
1254 | HOWTO64 (AARCH64_R (TLSLD_LDST32_DTPREL_LO12), /* type */ | |
1255 | 2, /* rightshift */ | |
1256 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1257 | 10, /* bitsize */ | |
1258 | FALSE, /* pc_relative */ | |
1259 | 10, /* bitpos */ | |
1260 | complain_overflow_unsigned, /* complain_on_overflow */ | |
1261 | bfd_elf_generic_reloc, /* special_function */ | |
1262 | AARCH64_R_STR (TLSLD_LDST32_DTPREL_LO12), /* name */ | |
1263 | FALSE, /* partial_inplace */ | |
1264 | 0x3ffc00, /* src_mask */ | |
1265 | 0x3ffc00, /* dst_mask */ | |
1266 | FALSE), /* pcrel_offset */ | |
1267 | ||
1268 | /* Same as BFD_RELOC_AARCH64_TLSLD_LDST32_DTPREL_LO12, but no overflow check. */ | |
1269 | HOWTO64 (AARCH64_R (TLSLD_LDST32_DTPREL_LO12_NC), /* type */ | |
1270 | 2, /* rightshift */ | |
1271 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1272 | 10, /* bitsize */ | |
1273 | FALSE, /* pc_relative */ | |
1274 | 10, /* bitpos */ | |
1275 | complain_overflow_dont, /* complain_on_overflow */ | |
1276 | bfd_elf_generic_reloc, /* special_function */ | |
1277 | AARCH64_R_STR (TLSLD_LDST32_DTPREL_LO12_NC), /* name */ | |
1278 | FALSE, /* partial_inplace */ | |
1279 | 0xffc00, /* src_mask */ | |
1280 | 0xffc00, /* dst_mask */ | |
1281 | FALSE), /* pcrel_offset */ | |
1282 | ||
1283 | /* LD/ST64: bit[11:3] of byte offset to module TLS base address. */ | |
1284 | HOWTO64 (AARCH64_R (TLSLD_LDST64_DTPREL_LO12), /* type */ | |
1285 | 3, /* rightshift */ | |
1286 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1287 | 9, /* bitsize */ | |
1288 | FALSE, /* pc_relative */ | |
1289 | 10, /* bitpos */ | |
1290 | complain_overflow_unsigned, /* complain_on_overflow */ | |
1291 | bfd_elf_generic_reloc, /* special_function */ | |
1292 | AARCH64_R_STR (TLSLD_LDST64_DTPREL_LO12), /* name */ | |
1293 | FALSE, /* partial_inplace */ | |
1294 | 0x3ffc00, /* src_mask */ | |
1295 | 0x3ffc00, /* dst_mask */ | |
1296 | FALSE), /* pcrel_offset */ | |
1297 | ||
1298 | /* Same as BFD_RELOC_AARCH64_TLSLD_LDST64_DTPREL_LO12, but no overflow check. */ | |
1299 | HOWTO64 (AARCH64_R (TLSLD_LDST64_DTPREL_LO12_NC), /* type */ | |
1300 | 3, /* rightshift */ | |
1301 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1302 | 9, /* bitsize */ | |
1303 | FALSE, /* pc_relative */ | |
1304 | 10, /* bitpos */ | |
1305 | complain_overflow_dont, /* complain_on_overflow */ | |
1306 | bfd_elf_generic_reloc, /* special_function */ | |
1307 | AARCH64_R_STR (TLSLD_LDST64_DTPREL_LO12_NC), /* name */ | |
1308 | FALSE, /* partial_inplace */ | |
1309 | 0x7fc00, /* src_mask */ | |
1310 | 0x7fc00, /* dst_mask */ | |
1311 | FALSE), /* pcrel_offset */ | |
1312 | ||
1313 | /* LD/ST8: bit[11:0] of byte offset to module TLS base address. */ | |
1314 | HOWTO64 (AARCH64_R (TLSLD_LDST8_DTPREL_LO12), /* type */ | |
1315 | 0, /* rightshift */ | |
1316 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1317 | 12, /* bitsize */ | |
1318 | FALSE, /* pc_relative */ | |
1319 | 10, /* bitpos */ | |
1320 | complain_overflow_unsigned, /* complain_on_overflow */ | |
1321 | bfd_elf_generic_reloc, /* special_function */ | |
1322 | AARCH64_R_STR (TLSLD_LDST8_DTPREL_LO12), /* name */ | |
1323 | FALSE, /* partial_inplace */ | |
1324 | 0x3ffc00, /* src_mask */ | |
1325 | 0x3ffc00, /* dst_mask */ | |
1326 | FALSE), /* pcrel_offset */ | |
1327 | ||
1328 | /* Same as BFD_RELOC_AARCH64_TLSLD_LDST8_DTPREL_LO12, but no overflow check. */ | |
1329 | HOWTO64 (AARCH64_R (TLSLD_LDST8_DTPREL_LO12_NC), /* type */ | |
1330 | 0, /* rightshift */ | |
1331 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1332 | 12, /* bitsize */ | |
1333 | FALSE, /* pc_relative */ | |
1334 | 10, /* bitpos */ | |
1335 | complain_overflow_dont, /* complain_on_overflow */ | |
1336 | bfd_elf_generic_reloc, /* special_function */ | |
1337 | AARCH64_R_STR (TLSLD_LDST8_DTPREL_LO12_NC), /* name */ | |
1338 | FALSE, /* partial_inplace */ | |
1339 | 0x3ffc00, /* src_mask */ | |
1340 | 0x3ffc00, /* dst_mask */ | |
1341 | FALSE), /* pcrel_offset */ | |
1342 | ||
49df5539 JW |
1343 | /* MOVZ: bit[15:0] of byte offset to module TLS base address. */ |
1344 | HOWTO (AARCH64_R (TLSLD_MOVW_DTPREL_G0), /* type */ | |
1345 | 0, /* rightshift */ | |
1346 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1347 | 16, /* bitsize */ | |
1348 | FALSE, /* pc_relative */ | |
1349 | 0, /* bitpos */ | |
1350 | complain_overflow_unsigned, /* complain_on_overflow */ | |
1351 | bfd_elf_generic_reloc, /* special_function */ | |
1352 | AARCH64_R_STR (TLSLD_MOVW_DTPREL_G0), /* name */ | |
1353 | FALSE, /* partial_inplace */ | |
1354 | 0xffff, /* src_mask */ | |
1355 | 0xffff, /* dst_mask */ | |
1356 | FALSE), /* pcrel_offset */ | |
1357 | ||
1358 | /* No overflow check version of BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G0. */ | |
1359 | HOWTO (AARCH64_R (TLSLD_MOVW_DTPREL_G0_NC), /* type */ | |
1360 | 0, /* rightshift */ | |
1361 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1362 | 16, /* bitsize */ | |
1363 | FALSE, /* pc_relative */ | |
1364 | 0, /* bitpos */ | |
1365 | complain_overflow_dont, /* complain_on_overflow */ | |
1366 | bfd_elf_generic_reloc, /* special_function */ | |
1367 | AARCH64_R_STR (TLSLD_MOVW_DTPREL_G0_NC), /* name */ | |
1368 | FALSE, /* partial_inplace */ | |
1369 | 0xffff, /* src_mask */ | |
1370 | 0xffff, /* dst_mask */ | |
1371 | FALSE), /* pcrel_offset */ | |
1372 | ||
1373 | /* MOVZ: bit[31:16] of byte offset to module TLS base address. */ | |
1374 | HOWTO (AARCH64_R (TLSLD_MOVW_DTPREL_G1), /* type */ | |
1375 | 16, /* rightshift */ | |
1376 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1377 | 16, /* bitsize */ | |
1378 | FALSE, /* pc_relative */ | |
1379 | 0, /* bitpos */ | |
1380 | complain_overflow_unsigned, /* complain_on_overflow */ | |
1381 | bfd_elf_generic_reloc, /* special_function */ | |
1382 | AARCH64_R_STR (TLSLD_MOVW_DTPREL_G1), /* name */ | |
1383 | FALSE, /* partial_inplace */ | |
1384 | 0xffff, /* src_mask */ | |
1385 | 0xffff, /* dst_mask */ | |
1386 | FALSE), /* pcrel_offset */ | |
1387 | ||
1388 | /* No overflow check version of BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G1. */ | |
1389 | HOWTO64 (AARCH64_R (TLSLD_MOVW_DTPREL_G1_NC), /* type */ | |
1390 | 16, /* rightshift */ | |
1391 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1392 | 16, /* bitsize */ | |
1393 | FALSE, /* pc_relative */ | |
1394 | 0, /* bitpos */ | |
1395 | complain_overflow_dont, /* complain_on_overflow */ | |
1396 | bfd_elf_generic_reloc, /* special_function */ | |
1397 | AARCH64_R_STR (TLSLD_MOVW_DTPREL_G1_NC), /* name */ | |
1398 | FALSE, /* partial_inplace */ | |
1399 | 0xffff, /* src_mask */ | |
1400 | 0xffff, /* dst_mask */ | |
1401 | FALSE), /* pcrel_offset */ | |
1402 | ||
1403 | /* MOVZ: bit[47:32] of byte offset to module TLS base address. */ | |
1404 | HOWTO64 (AARCH64_R (TLSLD_MOVW_DTPREL_G2), /* type */ | |
1405 | 32, /* rightshift */ | |
1406 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1407 | 16, /* bitsize */ | |
1408 | FALSE, /* pc_relative */ | |
1409 | 0, /* bitpos */ | |
1410 | complain_overflow_unsigned, /* complain_on_overflow */ | |
1411 | bfd_elf_generic_reloc, /* special_function */ | |
1412 | AARCH64_R_STR (TLSLD_MOVW_DTPREL_G2), /* name */ | |
1413 | FALSE, /* partial_inplace */ | |
1414 | 0xffff, /* src_mask */ | |
1415 | 0xffff, /* dst_mask */ | |
1416 | FALSE), /* pcrel_offset */ | |
1417 | ||
a6bb11b2 | 1418 | HOWTO64 (AARCH64_R (TLSLE_MOVW_TPREL_G2), /* type */ |
bb3f9ed8 | 1419 | 32, /* rightshift */ |
a06ea964 | 1420 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
07875fbc | 1421 | 16, /* bitsize */ |
a06ea964 NC |
1422 | FALSE, /* pc_relative */ |
1423 | 0, /* bitpos */ | |
0172429c | 1424 | complain_overflow_unsigned, /* complain_on_overflow */ |
a06ea964 | 1425 | bfd_elf_generic_reloc, /* special_function */ |
a6bb11b2 | 1426 | AARCH64_R_STR (TLSLE_MOVW_TPREL_G2), /* name */ |
a06ea964 NC |
1427 | FALSE, /* partial_inplace */ |
1428 | 0xffff, /* src_mask */ | |
1429 | 0xffff, /* dst_mask */ | |
1430 | FALSE), /* pcrel_offset */ | |
1431 | ||
a6bb11b2 | 1432 | HOWTO (AARCH64_R (TLSLE_MOVW_TPREL_G1), /* type */ |
bb3f9ed8 | 1433 | 16, /* rightshift */ |
a06ea964 | 1434 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
07875fbc | 1435 | 16, /* bitsize */ |
a06ea964 NC |
1436 | FALSE, /* pc_relative */ |
1437 | 0, /* bitpos */ | |
1438 | complain_overflow_dont, /* complain_on_overflow */ | |
1439 | bfd_elf_generic_reloc, /* special_function */ | |
a6bb11b2 | 1440 | AARCH64_R_STR (TLSLE_MOVW_TPREL_G1), /* name */ |
a06ea964 NC |
1441 | FALSE, /* partial_inplace */ |
1442 | 0xffff, /* src_mask */ | |
1443 | 0xffff, /* dst_mask */ | |
1444 | FALSE), /* pcrel_offset */ | |
1445 | ||
a6bb11b2 | 1446 | HOWTO64 (AARCH64_R (TLSLE_MOVW_TPREL_G1_NC), /* type */ |
bb3f9ed8 | 1447 | 16, /* rightshift */ |
a06ea964 | 1448 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
07875fbc | 1449 | 16, /* bitsize */ |
a06ea964 NC |
1450 | FALSE, /* pc_relative */ |
1451 | 0, /* bitpos */ | |
1452 | complain_overflow_dont, /* complain_on_overflow */ | |
1453 | bfd_elf_generic_reloc, /* special_function */ | |
a6bb11b2 | 1454 | AARCH64_R_STR (TLSLE_MOVW_TPREL_G1_NC), /* name */ |
a06ea964 NC |
1455 | FALSE, /* partial_inplace */ |
1456 | 0xffff, /* src_mask */ | |
1457 | 0xffff, /* dst_mask */ | |
1458 | FALSE), /* pcrel_offset */ | |
1459 | ||
a6bb11b2 | 1460 | HOWTO (AARCH64_R (TLSLE_MOVW_TPREL_G0), /* type */ |
a06ea964 NC |
1461 | 0, /* rightshift */ |
1462 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
07875fbc | 1463 | 16, /* bitsize */ |
a06ea964 NC |
1464 | FALSE, /* pc_relative */ |
1465 | 0, /* bitpos */ | |
1466 | complain_overflow_dont, /* complain_on_overflow */ | |
1467 | bfd_elf_generic_reloc, /* special_function */ | |
a6bb11b2 | 1468 | AARCH64_R_STR (TLSLE_MOVW_TPREL_G0), /* name */ |
a06ea964 NC |
1469 | FALSE, /* partial_inplace */ |
1470 | 0xffff, /* src_mask */ | |
1471 | 0xffff, /* dst_mask */ | |
1472 | FALSE), /* pcrel_offset */ | |
1473 | ||
a6bb11b2 | 1474 | HOWTO (AARCH64_R (TLSLE_MOVW_TPREL_G0_NC), /* type */ |
a06ea964 NC |
1475 | 0, /* rightshift */ |
1476 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
07875fbc | 1477 | 16, /* bitsize */ |
a06ea964 NC |
1478 | FALSE, /* pc_relative */ |
1479 | 0, /* bitpos */ | |
1480 | complain_overflow_dont, /* complain_on_overflow */ | |
1481 | bfd_elf_generic_reloc, /* special_function */ | |
a6bb11b2 | 1482 | AARCH64_R_STR (TLSLE_MOVW_TPREL_G0_NC), /* name */ |
a06ea964 NC |
1483 | FALSE, /* partial_inplace */ |
1484 | 0xffff, /* src_mask */ | |
1485 | 0xffff, /* dst_mask */ | |
1486 | FALSE), /* pcrel_offset */ | |
1487 | ||
a6bb11b2 | 1488 | HOWTO (AARCH64_R (TLSLE_ADD_TPREL_HI12), /* type */ |
bb3f9ed8 | 1489 | 12, /* rightshift */ |
a06ea964 NC |
1490 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
1491 | 12, /* bitsize */ | |
1492 | FALSE, /* pc_relative */ | |
1493 | 0, /* bitpos */ | |
bab91cce | 1494 | complain_overflow_unsigned, /* complain_on_overflow */ |
a06ea964 | 1495 | bfd_elf_generic_reloc, /* special_function */ |
a6bb11b2 | 1496 | AARCH64_R_STR (TLSLE_ADD_TPREL_HI12), /* name */ |
a06ea964 NC |
1497 | FALSE, /* partial_inplace */ |
1498 | 0xfff, /* src_mask */ | |
1499 | 0xfff, /* dst_mask */ | |
1500 | FALSE), /* pcrel_offset */ | |
1501 | ||
a6bb11b2 | 1502 | HOWTO (AARCH64_R (TLSLE_ADD_TPREL_LO12), /* type */ |
a06ea964 NC |
1503 | 0, /* rightshift */ |
1504 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1505 | 12, /* bitsize */ | |
1506 | FALSE, /* pc_relative */ | |
1507 | 0, /* bitpos */ | |
36e6c140 | 1508 | complain_overflow_unsigned, /* complain_on_overflow */ |
a06ea964 | 1509 | bfd_elf_generic_reloc, /* special_function */ |
a6bb11b2 | 1510 | AARCH64_R_STR (TLSLE_ADD_TPREL_LO12), /* name */ |
a06ea964 NC |
1511 | FALSE, /* partial_inplace */ |
1512 | 0xfff, /* src_mask */ | |
1513 | 0xfff, /* dst_mask */ | |
1514 | FALSE), /* pcrel_offset */ | |
1515 | ||
a6bb11b2 | 1516 | HOWTO (AARCH64_R (TLSLE_ADD_TPREL_LO12_NC), /* type */ |
a06ea964 NC |
1517 | 0, /* rightshift */ |
1518 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1519 | 12, /* bitsize */ | |
1520 | FALSE, /* pc_relative */ | |
1521 | 0, /* bitpos */ | |
1522 | complain_overflow_dont, /* complain_on_overflow */ | |
1523 | bfd_elf_generic_reloc, /* special_function */ | |
a6bb11b2 | 1524 | AARCH64_R_STR (TLSLE_ADD_TPREL_LO12_NC), /* name */ |
a06ea964 NC |
1525 | FALSE, /* partial_inplace */ |
1526 | 0xfff, /* src_mask */ | |
1527 | 0xfff, /* dst_mask */ | |
1528 | FALSE), /* pcrel_offset */ | |
a06ea964 | 1529 | |
a6bb11b2 | 1530 | HOWTO (AARCH64_R (TLSDESC_LD_PREL19), /* type */ |
bb3f9ed8 | 1531 | 2, /* rightshift */ |
a06ea964 | 1532 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
1ada945d | 1533 | 19, /* bitsize */ |
a06ea964 NC |
1534 | TRUE, /* pc_relative */ |
1535 | 0, /* bitpos */ | |
1536 | complain_overflow_dont, /* complain_on_overflow */ | |
1537 | bfd_elf_generic_reloc, /* special_function */ | |
a6bb11b2 | 1538 | AARCH64_R_STR (TLSDESC_LD_PREL19), /* name */ |
a06ea964 | 1539 | FALSE, /* partial_inplace */ |
1ada945d MS |
1540 | 0x0ffffe0, /* src_mask */ |
1541 | 0x0ffffe0, /* dst_mask */ | |
a06ea964 NC |
1542 | TRUE), /* pcrel_offset */ |
1543 | ||
a6bb11b2 | 1544 | HOWTO (AARCH64_R (TLSDESC_ADR_PREL21), /* type */ |
a06ea964 NC |
1545 | 0, /* rightshift */ |
1546 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1547 | 21, /* bitsize */ | |
1548 | TRUE, /* pc_relative */ | |
1549 | 0, /* bitpos */ | |
1550 | complain_overflow_dont, /* complain_on_overflow */ | |
1551 | bfd_elf_generic_reloc, /* special_function */ | |
a6bb11b2 | 1552 | AARCH64_R_STR (TLSDESC_ADR_PREL21), /* name */ |
a06ea964 NC |
1553 | FALSE, /* partial_inplace */ |
1554 | 0x1fffff, /* src_mask */ | |
1555 | 0x1fffff, /* dst_mask */ | |
1556 | TRUE), /* pcrel_offset */ | |
1557 | ||
1558 | /* Get to the page for the GOT entry for the symbol | |
1559 | (G(S) - P) using an ADRP instruction. */ | |
a6bb11b2 | 1560 | HOWTO (AARCH64_R (TLSDESC_ADR_PAGE21), /* type */ |
a06ea964 NC |
1561 | 12, /* rightshift */ |
1562 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1563 | 21, /* bitsize */ | |
1564 | TRUE, /* pc_relative */ | |
1565 | 0, /* bitpos */ | |
1566 | complain_overflow_dont, /* complain_on_overflow */ | |
1567 | bfd_elf_generic_reloc, /* special_function */ | |
a6bb11b2 | 1568 | AARCH64_R_STR (TLSDESC_ADR_PAGE21), /* name */ |
a06ea964 NC |
1569 | FALSE, /* partial_inplace */ |
1570 | 0x1fffff, /* src_mask */ | |
1571 | 0x1fffff, /* dst_mask */ | |
1572 | TRUE), /* pcrel_offset */ | |
1573 | ||
a6bb11b2 | 1574 | /* LD64: GOT offset G(S) & 0xff8. */ |
f955cccf | 1575 | HOWTO64 (AARCH64_R (TLSDESC_LD64_LO12), /* type */ |
a06ea964 NC |
1576 | 3, /* rightshift */ |
1577 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1578 | 12, /* bitsize */ | |
1579 | FALSE, /* pc_relative */ | |
1580 | 0, /* bitpos */ | |
1581 | complain_overflow_dont, /* complain_on_overflow */ | |
1582 | bfd_elf_generic_reloc, /* special_function */ | |
f955cccf | 1583 | AARCH64_R_STR (TLSDESC_LD64_LO12), /* name */ |
a06ea964 | 1584 | FALSE, /* partial_inplace */ |
a6bb11b2 YZ |
1585 | 0xff8, /* src_mask */ |
1586 | 0xff8, /* dst_mask */ | |
1587 | FALSE), /* pcrel_offset */ | |
1588 | ||
1589 | /* LD32: GOT offset G(S) & 0xffc. */ | |
1590 | HOWTO32 (AARCH64_R (TLSDESC_LD32_LO12_NC), /* type */ | |
1591 | 2, /* rightshift */ | |
1592 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1593 | 12, /* bitsize */ | |
1594 | FALSE, /* pc_relative */ | |
1595 | 0, /* bitpos */ | |
1596 | complain_overflow_dont, /* complain_on_overflow */ | |
1597 | bfd_elf_generic_reloc, /* special_function */ | |
1598 | AARCH64_R_STR (TLSDESC_LD32_LO12_NC), /* name */ | |
1599 | FALSE, /* partial_inplace */ | |
1600 | 0xffc, /* src_mask */ | |
1601 | 0xffc, /* dst_mask */ | |
a06ea964 NC |
1602 | FALSE), /* pcrel_offset */ |
1603 | ||
1604 | /* ADD: GOT offset G(S) & 0xfff. */ | |
f955cccf | 1605 | HOWTO (AARCH64_R (TLSDESC_ADD_LO12), /* type */ |
a06ea964 NC |
1606 | 0, /* rightshift */ |
1607 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1608 | 12, /* bitsize */ | |
1609 | FALSE, /* pc_relative */ | |
1610 | 0, /* bitpos */ | |
f955cccf | 1611 | complain_overflow_dont,/* complain_on_overflow */ |
a06ea964 | 1612 | bfd_elf_generic_reloc, /* special_function */ |
f955cccf | 1613 | AARCH64_R_STR (TLSDESC_ADD_LO12), /* name */ |
a06ea964 NC |
1614 | FALSE, /* partial_inplace */ |
1615 | 0xfff, /* src_mask */ | |
1616 | 0xfff, /* dst_mask */ | |
1617 | FALSE), /* pcrel_offset */ | |
1618 | ||
a6bb11b2 | 1619 | HOWTO64 (AARCH64_R (TLSDESC_OFF_G1), /* type */ |
bb3f9ed8 | 1620 | 16, /* rightshift */ |
a06ea964 NC |
1621 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
1622 | 12, /* bitsize */ | |
1623 | FALSE, /* pc_relative */ | |
1624 | 0, /* bitpos */ | |
43a357f9 | 1625 | complain_overflow_unsigned, /* complain_on_overflow */ |
a06ea964 | 1626 | bfd_elf_generic_reloc, /* special_function */ |
a6bb11b2 | 1627 | AARCH64_R_STR (TLSDESC_OFF_G1), /* name */ |
a06ea964 NC |
1628 | FALSE, /* partial_inplace */ |
1629 | 0xffff, /* src_mask */ | |
1630 | 0xffff, /* dst_mask */ | |
1631 | FALSE), /* pcrel_offset */ | |
1632 | ||
a6bb11b2 | 1633 | HOWTO64 (AARCH64_R (TLSDESC_OFF_G0_NC), /* type */ |
a06ea964 NC |
1634 | 0, /* rightshift */ |
1635 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1636 | 12, /* bitsize */ | |
1637 | FALSE, /* pc_relative */ | |
1638 | 0, /* bitpos */ | |
1639 | complain_overflow_dont, /* complain_on_overflow */ | |
1640 | bfd_elf_generic_reloc, /* special_function */ | |
a6bb11b2 | 1641 | AARCH64_R_STR (TLSDESC_OFF_G0_NC), /* name */ |
a06ea964 NC |
1642 | FALSE, /* partial_inplace */ |
1643 | 0xffff, /* src_mask */ | |
1644 | 0xffff, /* dst_mask */ | |
1645 | FALSE), /* pcrel_offset */ | |
1646 | ||
a6bb11b2 | 1647 | HOWTO64 (AARCH64_R (TLSDESC_LDR), /* type */ |
a06ea964 NC |
1648 | 0, /* rightshift */ |
1649 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1650 | 12, /* bitsize */ | |
1651 | FALSE, /* pc_relative */ | |
1652 | 0, /* bitpos */ | |
1653 | complain_overflow_dont, /* complain_on_overflow */ | |
1654 | bfd_elf_generic_reloc, /* special_function */ | |
a6bb11b2 | 1655 | AARCH64_R_STR (TLSDESC_LDR), /* name */ |
a06ea964 NC |
1656 | FALSE, /* partial_inplace */ |
1657 | 0x0, /* src_mask */ | |
1658 | 0x0, /* dst_mask */ | |
1659 | FALSE), /* pcrel_offset */ | |
1660 | ||
a6bb11b2 | 1661 | HOWTO64 (AARCH64_R (TLSDESC_ADD), /* type */ |
a06ea964 NC |
1662 | 0, /* rightshift */ |
1663 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1664 | 12, /* bitsize */ | |
1665 | FALSE, /* pc_relative */ | |
1666 | 0, /* bitpos */ | |
1667 | complain_overflow_dont, /* complain_on_overflow */ | |
1668 | bfd_elf_generic_reloc, /* special_function */ | |
a6bb11b2 | 1669 | AARCH64_R_STR (TLSDESC_ADD), /* name */ |
a06ea964 NC |
1670 | FALSE, /* partial_inplace */ |
1671 | 0x0, /* src_mask */ | |
1672 | 0x0, /* dst_mask */ | |
1673 | FALSE), /* pcrel_offset */ | |
1674 | ||
a6bb11b2 | 1675 | HOWTO (AARCH64_R (TLSDESC_CALL), /* type */ |
a06ea964 NC |
1676 | 0, /* rightshift */ |
1677 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
7366006f | 1678 | 0, /* bitsize */ |
a06ea964 NC |
1679 | FALSE, /* pc_relative */ |
1680 | 0, /* bitpos */ | |
1681 | complain_overflow_dont, /* complain_on_overflow */ | |
1682 | bfd_elf_generic_reloc, /* special_function */ | |
a6bb11b2 | 1683 | AARCH64_R_STR (TLSDESC_CALL), /* name */ |
a06ea964 NC |
1684 | FALSE, /* partial_inplace */ |
1685 | 0x0, /* src_mask */ | |
1686 | 0x0, /* dst_mask */ | |
1687 | FALSE), /* pcrel_offset */ | |
a6bb11b2 YZ |
1688 | |
1689 | HOWTO (AARCH64_R (COPY), /* type */ | |
1690 | 0, /* rightshift */ | |
1691 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1692 | 64, /* bitsize */ | |
1693 | FALSE, /* pc_relative */ | |
1694 | 0, /* bitpos */ | |
1695 | complain_overflow_bitfield, /* complain_on_overflow */ | |
1696 | bfd_elf_generic_reloc, /* special_function */ | |
1697 | AARCH64_R_STR (COPY), /* name */ | |
1698 | TRUE, /* partial_inplace */ | |
1699 | 0xffffffff, /* src_mask */ | |
1700 | 0xffffffff, /* dst_mask */ | |
1701 | FALSE), /* pcrel_offset */ | |
1702 | ||
1703 | HOWTO (AARCH64_R (GLOB_DAT), /* type */ | |
1704 | 0, /* rightshift */ | |
1705 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1706 | 64, /* bitsize */ | |
1707 | FALSE, /* pc_relative */ | |
1708 | 0, /* bitpos */ | |
1709 | complain_overflow_bitfield, /* complain_on_overflow */ | |
1710 | bfd_elf_generic_reloc, /* special_function */ | |
1711 | AARCH64_R_STR (GLOB_DAT), /* name */ | |
1712 | TRUE, /* partial_inplace */ | |
1713 | 0xffffffff, /* src_mask */ | |
1714 | 0xffffffff, /* dst_mask */ | |
1715 | FALSE), /* pcrel_offset */ | |
1716 | ||
1717 | HOWTO (AARCH64_R (JUMP_SLOT), /* type */ | |
1718 | 0, /* rightshift */ | |
1719 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1720 | 64, /* bitsize */ | |
1721 | FALSE, /* pc_relative */ | |
1722 | 0, /* bitpos */ | |
1723 | complain_overflow_bitfield, /* complain_on_overflow */ | |
1724 | bfd_elf_generic_reloc, /* special_function */ | |
1725 | AARCH64_R_STR (JUMP_SLOT), /* name */ | |
1726 | TRUE, /* partial_inplace */ | |
1727 | 0xffffffff, /* src_mask */ | |
1728 | 0xffffffff, /* dst_mask */ | |
1729 | FALSE), /* pcrel_offset */ | |
1730 | ||
1731 | HOWTO (AARCH64_R (RELATIVE), /* type */ | |
1732 | 0, /* rightshift */ | |
1733 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1734 | 64, /* bitsize */ | |
1735 | FALSE, /* pc_relative */ | |
1736 | 0, /* bitpos */ | |
1737 | complain_overflow_bitfield, /* complain_on_overflow */ | |
1738 | bfd_elf_generic_reloc, /* special_function */ | |
1739 | AARCH64_R_STR (RELATIVE), /* name */ | |
1740 | TRUE, /* partial_inplace */ | |
1741 | ALL_ONES, /* src_mask */ | |
1742 | ALL_ONES, /* dst_mask */ | |
1743 | FALSE), /* pcrel_offset */ | |
1744 | ||
1745 | HOWTO (AARCH64_R (TLS_DTPMOD), /* type */ | |
1746 | 0, /* rightshift */ | |
1747 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1748 | 64, /* bitsize */ | |
1749 | FALSE, /* pc_relative */ | |
1750 | 0, /* bitpos */ | |
1751 | complain_overflow_dont, /* complain_on_overflow */ | |
1752 | bfd_elf_generic_reloc, /* special_function */ | |
da0781dc YZ |
1753 | #if ARCH_SIZE == 64 |
1754 | AARCH64_R_STR (TLS_DTPMOD64), /* name */ | |
1755 | #else | |
a6bb11b2 | 1756 | AARCH64_R_STR (TLS_DTPMOD), /* name */ |
da0781dc | 1757 | #endif |
a6bb11b2 YZ |
1758 | FALSE, /* partial_inplace */ |
1759 | 0, /* src_mask */ | |
1760 | ALL_ONES, /* dst_mask */ | |
1761 | FALSE), /* pc_reloffset */ | |
1762 | ||
1763 | HOWTO (AARCH64_R (TLS_DTPREL), /* type */ | |
1764 | 0, /* rightshift */ | |
1765 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1766 | 64, /* bitsize */ | |
1767 | FALSE, /* pc_relative */ | |
1768 | 0, /* bitpos */ | |
1769 | complain_overflow_dont, /* complain_on_overflow */ | |
1770 | bfd_elf_generic_reloc, /* special_function */ | |
da0781dc YZ |
1771 | #if ARCH_SIZE == 64 |
1772 | AARCH64_R_STR (TLS_DTPREL64), /* name */ | |
1773 | #else | |
a6bb11b2 | 1774 | AARCH64_R_STR (TLS_DTPREL), /* name */ |
da0781dc | 1775 | #endif |
a6bb11b2 YZ |
1776 | FALSE, /* partial_inplace */ |
1777 | 0, /* src_mask */ | |
1778 | ALL_ONES, /* dst_mask */ | |
1779 | FALSE), /* pcrel_offset */ | |
1780 | ||
1781 | HOWTO (AARCH64_R (TLS_TPREL), /* type */ | |
1782 | 0, /* rightshift */ | |
1783 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1784 | 64, /* bitsize */ | |
1785 | FALSE, /* pc_relative */ | |
1786 | 0, /* bitpos */ | |
1787 | complain_overflow_dont, /* complain_on_overflow */ | |
1788 | bfd_elf_generic_reloc, /* special_function */ | |
da0781dc YZ |
1789 | #if ARCH_SIZE == 64 |
1790 | AARCH64_R_STR (TLS_TPREL64), /* name */ | |
1791 | #else | |
a6bb11b2 | 1792 | AARCH64_R_STR (TLS_TPREL), /* name */ |
da0781dc | 1793 | #endif |
a6bb11b2 YZ |
1794 | FALSE, /* partial_inplace */ |
1795 | 0, /* src_mask */ | |
1796 | ALL_ONES, /* dst_mask */ | |
1797 | FALSE), /* pcrel_offset */ | |
1798 | ||
1799 | HOWTO (AARCH64_R (TLSDESC), /* type */ | |
1800 | 0, /* rightshift */ | |
1801 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1802 | 64, /* bitsize */ | |
1803 | FALSE, /* pc_relative */ | |
1804 | 0, /* bitpos */ | |
1805 | complain_overflow_dont, /* complain_on_overflow */ | |
1806 | bfd_elf_generic_reloc, /* special_function */ | |
1807 | AARCH64_R_STR (TLSDESC), /* name */ | |
1808 | FALSE, /* partial_inplace */ | |
1809 | 0, /* src_mask */ | |
1810 | ALL_ONES, /* dst_mask */ | |
1811 | FALSE), /* pcrel_offset */ | |
1812 | ||
1813 | HOWTO (AARCH64_R (IRELATIVE), /* type */ | |
1814 | 0, /* rightshift */ | |
1815 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1816 | 64, /* bitsize */ | |
1817 | FALSE, /* pc_relative */ | |
1818 | 0, /* bitpos */ | |
1819 | complain_overflow_bitfield, /* complain_on_overflow */ | |
1820 | bfd_elf_generic_reloc, /* special_function */ | |
1821 | AARCH64_R_STR (IRELATIVE), /* name */ | |
1822 | FALSE, /* partial_inplace */ | |
1823 | 0, /* src_mask */ | |
1824 | ALL_ONES, /* dst_mask */ | |
1825 | FALSE), /* pcrel_offset */ | |
1826 | ||
1827 | EMPTY_HOWTO (0), | |
a06ea964 NC |
1828 | }; |
1829 | ||
a6bb11b2 YZ |
1830 | static reloc_howto_type elfNN_aarch64_howto_none = |
1831 | HOWTO (R_AARCH64_NONE, /* type */ | |
1832 | 0, /* rightshift */ | |
6346d5ca | 1833 | 3, /* size (0 = byte, 1 = short, 2 = long) */ |
a6bb11b2 YZ |
1834 | 0, /* bitsize */ |
1835 | FALSE, /* pc_relative */ | |
1836 | 0, /* bitpos */ | |
1837 | complain_overflow_dont,/* complain_on_overflow */ | |
1838 | bfd_elf_generic_reloc, /* special_function */ | |
1839 | "R_AARCH64_NONE", /* name */ | |
1840 | FALSE, /* partial_inplace */ | |
1841 | 0, /* src_mask */ | |
1842 | 0, /* dst_mask */ | |
1843 | FALSE); /* pcrel_offset */ | |
1844 | ||
1845 | /* Given HOWTO, return the bfd internal relocation enumerator. */ | |
1846 | ||
1847 | static bfd_reloc_code_real_type | |
1848 | elfNN_aarch64_bfd_reloc_from_howto (reloc_howto_type *howto) | |
1849 | { | |
1850 | const int size | |
1851 | = (int) ARRAY_SIZE (elfNN_aarch64_howto_table); | |
1852 | const ptrdiff_t offset | |
1853 | = howto - elfNN_aarch64_howto_table; | |
1854 | ||
1855 | if (offset > 0 && offset < size - 1) | |
1856 | return BFD_RELOC_AARCH64_RELOC_START + offset; | |
1857 | ||
1858 | if (howto == &elfNN_aarch64_howto_none) | |
1859 | return BFD_RELOC_AARCH64_NONE; | |
1860 | ||
1861 | return BFD_RELOC_AARCH64_RELOC_START; | |
1862 | } | |
1863 | ||
1864 | /* Given R_TYPE, return the bfd internal relocation enumerator. */ | |
1865 | ||
1866 | static bfd_reloc_code_real_type | |
1867 | elfNN_aarch64_bfd_reloc_from_type (unsigned int r_type) | |
1868 | { | |
1869 | static bfd_boolean initialized_p = FALSE; | |
1870 | /* Indexed by R_TYPE, values are offsets in the howto_table. */ | |
1871 | static unsigned int offsets[R_AARCH64_end]; | |
1872 | ||
535b785f | 1873 | if (!initialized_p) |
a6bb11b2 YZ |
1874 | { |
1875 | unsigned int i; | |
1876 | ||
1877 | for (i = 1; i < ARRAY_SIZE (elfNN_aarch64_howto_table) - 1; ++i) | |
1878 | if (elfNN_aarch64_howto_table[i].type != 0) | |
1879 | offsets[elfNN_aarch64_howto_table[i].type] = i; | |
1880 | ||
1881 | initialized_p = TRUE; | |
1882 | } | |
1883 | ||
1884 | if (r_type == R_AARCH64_NONE || r_type == R_AARCH64_NULL) | |
1885 | return BFD_RELOC_AARCH64_NONE; | |
1886 | ||
5860e3f8 NC |
1887 | /* PR 17512: file: b371e70a. */ |
1888 | if (r_type >= R_AARCH64_end) | |
1889 | { | |
1890 | _bfd_error_handler (_("Invalid AArch64 reloc number: %d"), r_type); | |
1891 | bfd_set_error (bfd_error_bad_value); | |
1892 | return BFD_RELOC_AARCH64_NONE; | |
1893 | } | |
1894 | ||
a6bb11b2 YZ |
1895 | return BFD_RELOC_AARCH64_RELOC_START + offsets[r_type]; |
1896 | } | |
1897 | ||
1898 | struct elf_aarch64_reloc_map | |
1899 | { | |
1900 | bfd_reloc_code_real_type from; | |
1901 | bfd_reloc_code_real_type to; | |
1902 | }; | |
1903 | ||
1904 | /* Map bfd generic reloc to AArch64-specific reloc. */ | |
1905 | static const struct elf_aarch64_reloc_map elf_aarch64_reloc_map[] = | |
1906 | { | |
1907 | {BFD_RELOC_NONE, BFD_RELOC_AARCH64_NONE}, | |
1908 | ||
1909 | /* Basic data relocations. */ | |
1910 | {BFD_RELOC_CTOR, BFD_RELOC_AARCH64_NN}, | |
1911 | {BFD_RELOC_64, BFD_RELOC_AARCH64_64}, | |
1912 | {BFD_RELOC_32, BFD_RELOC_AARCH64_32}, | |
1913 | {BFD_RELOC_16, BFD_RELOC_AARCH64_16}, | |
1914 | {BFD_RELOC_64_PCREL, BFD_RELOC_AARCH64_64_PCREL}, | |
1915 | {BFD_RELOC_32_PCREL, BFD_RELOC_AARCH64_32_PCREL}, | |
1916 | {BFD_RELOC_16_PCREL, BFD_RELOC_AARCH64_16_PCREL}, | |
1917 | }; | |
1918 | ||
1919 | /* Given the bfd internal relocation enumerator in CODE, return the | |
1920 | corresponding howto entry. */ | |
1921 | ||
1922 | static reloc_howto_type * | |
1923 | elfNN_aarch64_howto_from_bfd_reloc (bfd_reloc_code_real_type code) | |
1924 | { | |
1925 | unsigned int i; | |
1926 | ||
1927 | /* Convert bfd generic reloc to AArch64-specific reloc. */ | |
1928 | if (code < BFD_RELOC_AARCH64_RELOC_START | |
1929 | || code > BFD_RELOC_AARCH64_RELOC_END) | |
1930 | for (i = 0; i < ARRAY_SIZE (elf_aarch64_reloc_map); i++) | |
1931 | if (elf_aarch64_reloc_map[i].from == code) | |
1932 | { | |
1933 | code = elf_aarch64_reloc_map[i].to; | |
1934 | break; | |
1935 | } | |
1936 | ||
1937 | if (code > BFD_RELOC_AARCH64_RELOC_START | |
1938 | && code < BFD_RELOC_AARCH64_RELOC_END) | |
1939 | if (elfNN_aarch64_howto_table[code - BFD_RELOC_AARCH64_RELOC_START].type) | |
1940 | return &elfNN_aarch64_howto_table[code - BFD_RELOC_AARCH64_RELOC_START]; | |
1941 | ||
54757ed1 AP |
1942 | if (code == BFD_RELOC_AARCH64_NONE) |
1943 | return &elfNN_aarch64_howto_none; | |
1944 | ||
a6bb11b2 YZ |
1945 | return NULL; |
1946 | } | |
1947 | ||
a06ea964 | 1948 | static reloc_howto_type * |
cec5225b | 1949 | elfNN_aarch64_howto_from_type (unsigned int r_type) |
a06ea964 | 1950 | { |
a6bb11b2 YZ |
1951 | bfd_reloc_code_real_type val; |
1952 | reloc_howto_type *howto; | |
1953 | ||
cec5225b YZ |
1954 | #if ARCH_SIZE == 32 |
1955 | if (r_type > 256) | |
1956 | { | |
1957 | bfd_set_error (bfd_error_bad_value); | |
1958 | return NULL; | |
1959 | } | |
1960 | #endif | |
1961 | ||
a6bb11b2 YZ |
1962 | if (r_type == R_AARCH64_NONE) |
1963 | return &elfNN_aarch64_howto_none; | |
a06ea964 | 1964 | |
a6bb11b2 YZ |
1965 | val = elfNN_aarch64_bfd_reloc_from_type (r_type); |
1966 | howto = elfNN_aarch64_howto_from_bfd_reloc (val); | |
a06ea964 | 1967 | |
a6bb11b2 YZ |
1968 | if (howto != NULL) |
1969 | return howto; | |
a06ea964 | 1970 | |
a06ea964 NC |
1971 | bfd_set_error (bfd_error_bad_value); |
1972 | return NULL; | |
1973 | } | |
1974 | ||
1975 | static void | |
cec5225b | 1976 | elfNN_aarch64_info_to_howto (bfd *abfd ATTRIBUTE_UNUSED, arelent *bfd_reloc, |
a06ea964 NC |
1977 | Elf_Internal_Rela *elf_reloc) |
1978 | { | |
1979 | unsigned int r_type; | |
1980 | ||
cec5225b YZ |
1981 | r_type = ELFNN_R_TYPE (elf_reloc->r_info); |
1982 | bfd_reloc->howto = elfNN_aarch64_howto_from_type (r_type); | |
a06ea964 NC |
1983 | } |
1984 | ||
a06ea964 | 1985 | static reloc_howto_type * |
cec5225b | 1986 | elfNN_aarch64_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED, |
a06ea964 NC |
1987 | bfd_reloc_code_real_type code) |
1988 | { | |
a6bb11b2 | 1989 | reloc_howto_type *howto = elfNN_aarch64_howto_from_bfd_reloc (code); |
a06ea964 | 1990 | |
a6bb11b2 YZ |
1991 | if (howto != NULL) |
1992 | return howto; | |
a06ea964 NC |
1993 | |
1994 | bfd_set_error (bfd_error_bad_value); | |
1995 | return NULL; | |
1996 | } | |
1997 | ||
1998 | static reloc_howto_type * | |
cec5225b | 1999 | elfNN_aarch64_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED, |
a06ea964 NC |
2000 | const char *r_name) |
2001 | { | |
2002 | unsigned int i; | |
2003 | ||
a6bb11b2 YZ |
2004 | for (i = 1; i < ARRAY_SIZE (elfNN_aarch64_howto_table) - 1; ++i) |
2005 | if (elfNN_aarch64_howto_table[i].name != NULL | |
2006 | && strcasecmp (elfNN_aarch64_howto_table[i].name, r_name) == 0) | |
2007 | return &elfNN_aarch64_howto_table[i]; | |
a06ea964 NC |
2008 | |
2009 | return NULL; | |
2010 | } | |
2011 | ||
6d00b590 | 2012 | #define TARGET_LITTLE_SYM aarch64_elfNN_le_vec |
cec5225b | 2013 | #define TARGET_LITTLE_NAME "elfNN-littleaarch64" |
6d00b590 | 2014 | #define TARGET_BIG_SYM aarch64_elfNN_be_vec |
cec5225b | 2015 | #define TARGET_BIG_NAME "elfNN-bigaarch64" |
a06ea964 | 2016 | |
a06ea964 NC |
2017 | /* The linker script knows the section names for placement. |
2018 | The entry_names are used to do simple name mangling on the stubs. | |
2019 | Given a function name, and its type, the stub can be found. The | |
2020 | name can be changed. The only requirement is the %s be present. */ | |
2021 | #define STUB_ENTRY_NAME "__%s_veneer" | |
2022 | ||
2023 | /* The name of the dynamic interpreter. This is put in the .interp | |
2024 | section. */ | |
2025 | #define ELF_DYNAMIC_INTERPRETER "/lib/ld.so.1" | |
2026 | ||
2027 | #define AARCH64_MAX_FWD_BRANCH_OFFSET \ | |
2028 | (((1 << 25) - 1) << 2) | |
2029 | #define AARCH64_MAX_BWD_BRANCH_OFFSET \ | |
2030 | (-((1 << 25) << 2)) | |
2031 | ||
2032 | #define AARCH64_MAX_ADRP_IMM ((1 << 20) - 1) | |
2033 | #define AARCH64_MIN_ADRP_IMM (-(1 << 20)) | |
2034 | ||
2035 | static int | |
2036 | aarch64_valid_for_adrp_p (bfd_vma value, bfd_vma place) | |
2037 | { | |
2038 | bfd_signed_vma offset = (bfd_signed_vma) (PG (value) - PG (place)) >> 12; | |
2039 | return offset <= AARCH64_MAX_ADRP_IMM && offset >= AARCH64_MIN_ADRP_IMM; | |
2040 | } | |
2041 | ||
2042 | static int | |
2043 | aarch64_valid_branch_p (bfd_vma value, bfd_vma place) | |
2044 | { | |
2045 | bfd_signed_vma offset = (bfd_signed_vma) (value - place); | |
2046 | return (offset <= AARCH64_MAX_FWD_BRANCH_OFFSET | |
2047 | && offset >= AARCH64_MAX_BWD_BRANCH_OFFSET); | |
2048 | } | |
2049 | ||
2050 | static const uint32_t aarch64_adrp_branch_stub [] = | |
2051 | { | |
2052 | 0x90000010, /* adrp ip0, X */ | |
2053 | /* R_AARCH64_ADR_HI21_PCREL(X) */ | |
2054 | 0x91000210, /* add ip0, ip0, :lo12:X */ | |
2055 | /* R_AARCH64_ADD_ABS_LO12_NC(X) */ | |
2056 | 0xd61f0200, /* br ip0 */ | |
2057 | }; | |
2058 | ||
2059 | static const uint32_t aarch64_long_branch_stub[] = | |
2060 | { | |
cec5225b | 2061 | #if ARCH_SIZE == 64 |
a06ea964 | 2062 | 0x58000090, /* ldr ip0, 1f */ |
cec5225b YZ |
2063 | #else |
2064 | 0x18000090, /* ldr wip0, 1f */ | |
2065 | #endif | |
a06ea964 NC |
2066 | 0x10000011, /* adr ip1, #0 */ |
2067 | 0x8b110210, /* add ip0, ip0, ip1 */ | |
2068 | 0xd61f0200, /* br ip0 */ | |
cec5225b YZ |
2069 | 0x00000000, /* 1: .xword or .word |
2070 | R_AARCH64_PRELNN(X) + 12 | |
a06ea964 NC |
2071 | */ |
2072 | 0x00000000, | |
2073 | }; | |
2074 | ||
68fcca92 JW |
2075 | static const uint32_t aarch64_erratum_835769_stub[] = |
2076 | { | |
2077 | 0x00000000, /* Placeholder for multiply accumulate. */ | |
2078 | 0x14000000, /* b <label> */ | |
2079 | }; | |
2080 | ||
4106101c MS |
2081 | static const uint32_t aarch64_erratum_843419_stub[] = |
2082 | { | |
2083 | 0x00000000, /* Placeholder for LDR instruction. */ | |
2084 | 0x14000000, /* b <label> */ | |
2085 | }; | |
2086 | ||
a06ea964 NC |
2087 | /* Section name for stubs is the associated section name plus this |
2088 | string. */ | |
2089 | #define STUB_SUFFIX ".stub" | |
2090 | ||
cec5225b | 2091 | enum elf_aarch64_stub_type |
a06ea964 NC |
2092 | { |
2093 | aarch64_stub_none, | |
2094 | aarch64_stub_adrp_branch, | |
2095 | aarch64_stub_long_branch, | |
68fcca92 | 2096 | aarch64_stub_erratum_835769_veneer, |
4106101c | 2097 | aarch64_stub_erratum_843419_veneer, |
a06ea964 NC |
2098 | }; |
2099 | ||
cec5225b | 2100 | struct elf_aarch64_stub_hash_entry |
a06ea964 NC |
2101 | { |
2102 | /* Base hash table entry structure. */ | |
2103 | struct bfd_hash_entry root; | |
2104 | ||
2105 | /* The stub section. */ | |
2106 | asection *stub_sec; | |
2107 | ||
2108 | /* Offset within stub_sec of the beginning of this stub. */ | |
2109 | bfd_vma stub_offset; | |
2110 | ||
2111 | /* Given the symbol's value and its section we can determine its final | |
2112 | value when building the stubs (so the stub knows where to jump). */ | |
2113 | bfd_vma target_value; | |
2114 | asection *target_section; | |
2115 | ||
cec5225b | 2116 | enum elf_aarch64_stub_type stub_type; |
a06ea964 NC |
2117 | |
2118 | /* The symbol table entry, if any, that this was derived from. */ | |
cec5225b | 2119 | struct elf_aarch64_link_hash_entry *h; |
a06ea964 NC |
2120 | |
2121 | /* Destination symbol type */ | |
2122 | unsigned char st_type; | |
2123 | ||
2124 | /* Where this stub is being called from, or, in the case of combined | |
2125 | stub sections, the first input section in the group. */ | |
2126 | asection *id_sec; | |
2127 | ||
2128 | /* The name for the local symbol at the start of this stub. The | |
2129 | stub name in the hash table has to be unique; this does not, so | |
2130 | it can be friendlier. */ | |
2131 | char *output_name; | |
68fcca92 JW |
2132 | |
2133 | /* The instruction which caused this stub to be generated (only valid for | |
2134 | erratum 835769 workaround stubs at present). */ | |
2135 | uint32_t veneered_insn; | |
4106101c MS |
2136 | |
2137 | /* In an erratum 843419 workaround stub, the ADRP instruction offset. */ | |
2138 | bfd_vma adrp_offset; | |
a06ea964 NC |
2139 | }; |
2140 | ||
2141 | /* Used to build a map of a section. This is required for mixed-endian | |
2142 | code/data. */ | |
2143 | ||
cec5225b | 2144 | typedef struct elf_elf_section_map |
a06ea964 NC |
2145 | { |
2146 | bfd_vma vma; | |
2147 | char type; | |
2148 | } | |
cec5225b | 2149 | elf_aarch64_section_map; |
a06ea964 NC |
2150 | |
2151 | ||
2152 | typedef struct _aarch64_elf_section_data | |
2153 | { | |
2154 | struct bfd_elf_section_data elf; | |
2155 | unsigned int mapcount; | |
2156 | unsigned int mapsize; | |
cec5225b | 2157 | elf_aarch64_section_map *map; |
a06ea964 NC |
2158 | } |
2159 | _aarch64_elf_section_data; | |
2160 | ||
cec5225b | 2161 | #define elf_aarch64_section_data(sec) \ |
a06ea964 NC |
2162 | ((_aarch64_elf_section_data *) elf_section_data (sec)) |
2163 | ||
4e8516b2 AP |
2164 | /* The size of the thread control block which is defined to be two pointers. */ |
2165 | #define TCB_SIZE (ARCH_SIZE/8)*2 | |
a06ea964 NC |
2166 | |
2167 | struct elf_aarch64_local_symbol | |
2168 | { | |
2169 | unsigned int got_type; | |
2170 | bfd_signed_vma got_refcount; | |
2171 | bfd_vma got_offset; | |
2172 | ||
2173 | /* Offset of the GOTPLT entry reserved for the TLS descriptor. The | |
2174 | offset is from the end of the jump table and reserved entries | |
2175 | within the PLTGOT. | |
2176 | ||
2177 | The magic value (bfd_vma) -1 indicates that an offset has not be | |
2178 | allocated. */ | |
2179 | bfd_vma tlsdesc_got_jump_table_offset; | |
2180 | }; | |
2181 | ||
2182 | struct elf_aarch64_obj_tdata | |
2183 | { | |
2184 | struct elf_obj_tdata root; | |
2185 | ||
2186 | /* local symbol descriptors */ | |
2187 | struct elf_aarch64_local_symbol *locals; | |
2188 | ||
2189 | /* Zero to warn when linking objects with incompatible enum sizes. */ | |
2190 | int no_enum_size_warning; | |
2191 | ||
2192 | /* Zero to warn when linking objects with incompatible wchar_t sizes. */ | |
2193 | int no_wchar_size_warning; | |
2194 | }; | |
2195 | ||
2196 | #define elf_aarch64_tdata(bfd) \ | |
2197 | ((struct elf_aarch64_obj_tdata *) (bfd)->tdata.any) | |
2198 | ||
cec5225b | 2199 | #define elf_aarch64_locals(bfd) (elf_aarch64_tdata (bfd)->locals) |
a06ea964 NC |
2200 | |
2201 | #define is_aarch64_elf(bfd) \ | |
2202 | (bfd_get_flavour (bfd) == bfd_target_elf_flavour \ | |
2203 | && elf_tdata (bfd) != NULL \ | |
2204 | && elf_object_id (bfd) == AARCH64_ELF_DATA) | |
2205 | ||
2206 | static bfd_boolean | |
cec5225b | 2207 | elfNN_aarch64_mkobject (bfd *abfd) |
a06ea964 NC |
2208 | { |
2209 | return bfd_elf_allocate_object (abfd, sizeof (struct elf_aarch64_obj_tdata), | |
2210 | AARCH64_ELF_DATA); | |
2211 | } | |
2212 | ||
cec5225b YZ |
2213 | #define elf_aarch64_hash_entry(ent) \ |
2214 | ((struct elf_aarch64_link_hash_entry *)(ent)) | |
a06ea964 NC |
2215 | |
2216 | #define GOT_UNKNOWN 0 | |
2217 | #define GOT_NORMAL 1 | |
2218 | #define GOT_TLS_GD 2 | |
2219 | #define GOT_TLS_IE 4 | |
2220 | #define GOT_TLSDESC_GD 8 | |
2221 | ||
2222 | #define GOT_TLS_GD_ANY_P(type) ((type & GOT_TLS_GD) || (type & GOT_TLSDESC_GD)) | |
2223 | ||
2224 | /* AArch64 ELF linker hash entry. */ | |
cec5225b | 2225 | struct elf_aarch64_link_hash_entry |
a06ea964 NC |
2226 | { |
2227 | struct elf_link_hash_entry root; | |
2228 | ||
2229 | /* Track dynamic relocs copied for this symbol. */ | |
2230 | struct elf_dyn_relocs *dyn_relocs; | |
2231 | ||
a06ea964 NC |
2232 | /* Since PLT entries have variable size, we need to record the |
2233 | index into .got.plt instead of recomputing it from the PLT | |
2234 | offset. */ | |
2235 | bfd_signed_vma plt_got_offset; | |
2236 | ||
2237 | /* Bit mask representing the type of GOT entry(s) if any required by | |
2238 | this symbol. */ | |
2239 | unsigned int got_type; | |
2240 | ||
2241 | /* A pointer to the most recently used stub hash entry against this | |
2242 | symbol. */ | |
cec5225b | 2243 | struct elf_aarch64_stub_hash_entry *stub_cache; |
a06ea964 NC |
2244 | |
2245 | /* Offset of the GOTPLT entry reserved for the TLS descriptor. The offset | |
2246 | is from the end of the jump table and reserved entries within the PLTGOT. | |
2247 | ||
2248 | The magic value (bfd_vma) -1 indicates that an offset has not | |
2249 | be allocated. */ | |
2250 | bfd_vma tlsdesc_got_jump_table_offset; | |
2251 | }; | |
2252 | ||
2253 | static unsigned int | |
cec5225b | 2254 | elfNN_aarch64_symbol_got_type (struct elf_link_hash_entry *h, |
a06ea964 NC |
2255 | bfd *abfd, |
2256 | unsigned long r_symndx) | |
2257 | { | |
2258 | if (h) | |
cec5225b | 2259 | return elf_aarch64_hash_entry (h)->got_type; |
a06ea964 | 2260 | |
cec5225b | 2261 | if (! elf_aarch64_locals (abfd)) |
a06ea964 NC |
2262 | return GOT_UNKNOWN; |
2263 | ||
cec5225b | 2264 | return elf_aarch64_locals (abfd)[r_symndx].got_type; |
a06ea964 NC |
2265 | } |
2266 | ||
a06ea964 | 2267 | /* Get the AArch64 elf linker hash table from a link_info structure. */ |
cec5225b YZ |
2268 | #define elf_aarch64_hash_table(info) \ |
2269 | ((struct elf_aarch64_link_hash_table *) ((info)->hash)) | |
a06ea964 NC |
2270 | |
2271 | #define aarch64_stub_hash_lookup(table, string, create, copy) \ | |
cec5225b | 2272 | ((struct elf_aarch64_stub_hash_entry *) \ |
a06ea964 NC |
2273 | bfd_hash_lookup ((table), (string), (create), (copy))) |
2274 | ||
2275 | /* AArch64 ELF linker hash table. */ | |
cec5225b | 2276 | struct elf_aarch64_link_hash_table |
a06ea964 NC |
2277 | { |
2278 | /* The main hash table. */ | |
2279 | struct elf_link_hash_table root; | |
2280 | ||
2281 | /* Nonzero to force PIC branch veneers. */ | |
2282 | int pic_veneer; | |
2283 | ||
68fcca92 JW |
2284 | /* Fix erratum 835769. */ |
2285 | int fix_erratum_835769; | |
2286 | ||
4106101c MS |
2287 | /* Fix erratum 843419. */ |
2288 | int fix_erratum_843419; | |
2289 | ||
2290 | /* Enable ADRP->ADR rewrite for erratum 843419 workaround. */ | |
2291 | int fix_erratum_843419_adr; | |
2292 | ||
1f56df9d JW |
2293 | /* Don't apply link-time values for dynamic relocations. */ |
2294 | int no_apply_dynamic_relocs; | |
2295 | ||
a06ea964 NC |
2296 | /* The number of bytes in the initial entry in the PLT. */ |
2297 | bfd_size_type plt_header_size; | |
2298 | ||
2299 | /* The number of bytes in the subsequent PLT etries. */ | |
2300 | bfd_size_type plt_entry_size; | |
2301 | ||
a06ea964 NC |
2302 | /* Small local sym cache. */ |
2303 | struct sym_cache sym_cache; | |
2304 | ||
2305 | /* For convenience in allocate_dynrelocs. */ | |
2306 | bfd *obfd; | |
2307 | ||
2308 | /* The amount of space used by the reserved portion of the sgotplt | |
2309 | section, plus whatever space is used by the jump slots. */ | |
2310 | bfd_vma sgotplt_jump_table_size; | |
2311 | ||
2312 | /* The stub hash table. */ | |
2313 | struct bfd_hash_table stub_hash_table; | |
2314 | ||
2315 | /* Linker stub bfd. */ | |
2316 | bfd *stub_bfd; | |
2317 | ||
2318 | /* Linker call-backs. */ | |
2319 | asection *(*add_stub_section) (const char *, asection *); | |
2320 | void (*layout_sections_again) (void); | |
2321 | ||
2322 | /* Array to keep track of which stub sections have been created, and | |
2323 | information on stub grouping. */ | |
2324 | struct map_stub | |
2325 | { | |
2326 | /* This is the section to which stubs in the group will be | |
2327 | attached. */ | |
2328 | asection *link_sec; | |
2329 | /* The stub section. */ | |
2330 | asection *stub_sec; | |
2331 | } *stub_group; | |
2332 | ||
cec5225b | 2333 | /* Assorted information used by elfNN_aarch64_size_stubs. */ |
a06ea964 | 2334 | unsigned int bfd_count; |
7292b3ac | 2335 | unsigned int top_index; |
a06ea964 NC |
2336 | asection **input_list; |
2337 | ||
2338 | /* The offset into splt of the PLT entry for the TLS descriptor | |
2339 | resolver. Special values are 0, if not necessary (or not found | |
2340 | to be necessary yet), and -1 if needed but not determined | |
2341 | yet. */ | |
2342 | bfd_vma tlsdesc_plt; | |
2343 | ||
2344 | /* The GOT offset for the lazy trampoline. Communicated to the | |
2345 | loader via DT_TLSDESC_GOT. The magic value (bfd_vma) -1 | |
2346 | indicates an offset is not allocated. */ | |
2347 | bfd_vma dt_tlsdesc_got; | |
1419bbe5 WN |
2348 | |
2349 | /* Used by local STT_GNU_IFUNC symbols. */ | |
2350 | htab_t loc_hash_table; | |
2351 | void * loc_hash_memory; | |
a06ea964 NC |
2352 | }; |
2353 | ||
a06ea964 NC |
2354 | /* Create an entry in an AArch64 ELF linker hash table. */ |
2355 | ||
2356 | static struct bfd_hash_entry * | |
cec5225b | 2357 | elfNN_aarch64_link_hash_newfunc (struct bfd_hash_entry *entry, |
a06ea964 NC |
2358 | struct bfd_hash_table *table, |
2359 | const char *string) | |
2360 | { | |
cec5225b YZ |
2361 | struct elf_aarch64_link_hash_entry *ret = |
2362 | (struct elf_aarch64_link_hash_entry *) entry; | |
a06ea964 NC |
2363 | |
2364 | /* Allocate the structure if it has not already been allocated by a | |
2365 | subclass. */ | |
2366 | if (ret == NULL) | |
2367 | ret = bfd_hash_allocate (table, | |
cec5225b | 2368 | sizeof (struct elf_aarch64_link_hash_entry)); |
a06ea964 NC |
2369 | if (ret == NULL) |
2370 | return (struct bfd_hash_entry *) ret; | |
2371 | ||
2372 | /* Call the allocation method of the superclass. */ | |
cec5225b | 2373 | ret = ((struct elf_aarch64_link_hash_entry *) |
a06ea964 NC |
2374 | _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry *) ret, |
2375 | table, string)); | |
2376 | if (ret != NULL) | |
2377 | { | |
2378 | ret->dyn_relocs = NULL; | |
a06ea964 NC |
2379 | ret->got_type = GOT_UNKNOWN; |
2380 | ret->plt_got_offset = (bfd_vma) - 1; | |
2381 | ret->stub_cache = NULL; | |
2382 | ret->tlsdesc_got_jump_table_offset = (bfd_vma) - 1; | |
2383 | } | |
2384 | ||
2385 | return (struct bfd_hash_entry *) ret; | |
2386 | } | |
2387 | ||
2388 | /* Initialize an entry in the stub hash table. */ | |
2389 | ||
2390 | static struct bfd_hash_entry * | |
2391 | stub_hash_newfunc (struct bfd_hash_entry *entry, | |
2392 | struct bfd_hash_table *table, const char *string) | |
2393 | { | |
2394 | /* Allocate the structure if it has not already been allocated by a | |
2395 | subclass. */ | |
2396 | if (entry == NULL) | |
2397 | { | |
2398 | entry = bfd_hash_allocate (table, | |
2399 | sizeof (struct | |
cec5225b | 2400 | elf_aarch64_stub_hash_entry)); |
a06ea964 NC |
2401 | if (entry == NULL) |
2402 | return entry; | |
2403 | } | |
2404 | ||
2405 | /* Call the allocation method of the superclass. */ | |
2406 | entry = bfd_hash_newfunc (entry, table, string); | |
2407 | if (entry != NULL) | |
2408 | { | |
cec5225b | 2409 | struct elf_aarch64_stub_hash_entry *eh; |
a06ea964 NC |
2410 | |
2411 | /* Initialize the local fields. */ | |
cec5225b | 2412 | eh = (struct elf_aarch64_stub_hash_entry *) entry; |
4106101c | 2413 | eh->adrp_offset = 0; |
a06ea964 NC |
2414 | eh->stub_sec = NULL; |
2415 | eh->stub_offset = 0; | |
2416 | eh->target_value = 0; | |
2417 | eh->target_section = NULL; | |
2418 | eh->stub_type = aarch64_stub_none; | |
2419 | eh->h = NULL; | |
2420 | eh->id_sec = NULL; | |
2421 | } | |
2422 | ||
2423 | return entry; | |
2424 | } | |
2425 | ||
1419bbe5 WN |
2426 | /* Compute a hash of a local hash entry. We use elf_link_hash_entry |
2427 | for local symbol so that we can handle local STT_GNU_IFUNC symbols | |
2428 | as global symbol. We reuse indx and dynstr_index for local symbol | |
2429 | hash since they aren't used by global symbols in this backend. */ | |
2430 | ||
2431 | static hashval_t | |
2432 | elfNN_aarch64_local_htab_hash (const void *ptr) | |
2433 | { | |
2434 | struct elf_link_hash_entry *h | |
2435 | = (struct elf_link_hash_entry *) ptr; | |
2436 | return ELF_LOCAL_SYMBOL_HASH (h->indx, h->dynstr_index); | |
2437 | } | |
2438 | ||
2439 | /* Compare local hash entries. */ | |
2440 | ||
2441 | static int | |
2442 | elfNN_aarch64_local_htab_eq (const void *ptr1, const void *ptr2) | |
2443 | { | |
2444 | struct elf_link_hash_entry *h1 | |
2445 | = (struct elf_link_hash_entry *) ptr1; | |
2446 | struct elf_link_hash_entry *h2 | |
2447 | = (struct elf_link_hash_entry *) ptr2; | |
2448 | ||
2449 | return h1->indx == h2->indx && h1->dynstr_index == h2->dynstr_index; | |
2450 | } | |
2451 | ||
2452 | /* Find and/or create a hash entry for local symbol. */ | |
2453 | ||
2454 | static struct elf_link_hash_entry * | |
2455 | elfNN_aarch64_get_local_sym_hash (struct elf_aarch64_link_hash_table *htab, | |
2456 | bfd *abfd, const Elf_Internal_Rela *rel, | |
2457 | bfd_boolean create) | |
2458 | { | |
2459 | struct elf_aarch64_link_hash_entry e, *ret; | |
2460 | asection *sec = abfd->sections; | |
2461 | hashval_t h = ELF_LOCAL_SYMBOL_HASH (sec->id, | |
2462 | ELFNN_R_SYM (rel->r_info)); | |
2463 | void **slot; | |
2464 | ||
2465 | e.root.indx = sec->id; | |
2466 | e.root.dynstr_index = ELFNN_R_SYM (rel->r_info); | |
2467 | slot = htab_find_slot_with_hash (htab->loc_hash_table, &e, h, | |
2468 | create ? INSERT : NO_INSERT); | |
2469 | ||
2470 | if (!slot) | |
2471 | return NULL; | |
2472 | ||
2473 | if (*slot) | |
2474 | { | |
2475 | ret = (struct elf_aarch64_link_hash_entry *) *slot; | |
2476 | return &ret->root; | |
2477 | } | |
2478 | ||
2479 | ret = (struct elf_aarch64_link_hash_entry *) | |
2480 | objalloc_alloc ((struct objalloc *) htab->loc_hash_memory, | |
2481 | sizeof (struct elf_aarch64_link_hash_entry)); | |
2482 | if (ret) | |
2483 | { | |
2484 | memset (ret, 0, sizeof (*ret)); | |
2485 | ret->root.indx = sec->id; | |
2486 | ret->root.dynstr_index = ELFNN_R_SYM (rel->r_info); | |
2487 | ret->root.dynindx = -1; | |
2488 | *slot = ret; | |
2489 | } | |
2490 | return &ret->root; | |
2491 | } | |
a06ea964 NC |
2492 | |
2493 | /* Copy the extra info we tack onto an elf_link_hash_entry. */ | |
2494 | ||
2495 | static void | |
cec5225b | 2496 | elfNN_aarch64_copy_indirect_symbol (struct bfd_link_info *info, |
a06ea964 NC |
2497 | struct elf_link_hash_entry *dir, |
2498 | struct elf_link_hash_entry *ind) | |
2499 | { | |
cec5225b | 2500 | struct elf_aarch64_link_hash_entry *edir, *eind; |
a06ea964 | 2501 | |
cec5225b YZ |
2502 | edir = (struct elf_aarch64_link_hash_entry *) dir; |
2503 | eind = (struct elf_aarch64_link_hash_entry *) ind; | |
a06ea964 NC |
2504 | |
2505 | if (eind->dyn_relocs != NULL) | |
2506 | { | |
2507 | if (edir->dyn_relocs != NULL) | |
2508 | { | |
2509 | struct elf_dyn_relocs **pp; | |
2510 | struct elf_dyn_relocs *p; | |
2511 | ||
2512 | /* Add reloc counts against the indirect sym to the direct sym | |
2513 | list. Merge any entries against the same section. */ | |
2514 | for (pp = &eind->dyn_relocs; (p = *pp) != NULL;) | |
2515 | { | |
2516 | struct elf_dyn_relocs *q; | |
2517 | ||
2518 | for (q = edir->dyn_relocs; q != NULL; q = q->next) | |
2519 | if (q->sec == p->sec) | |
2520 | { | |
2521 | q->pc_count += p->pc_count; | |
2522 | q->count += p->count; | |
2523 | *pp = p->next; | |
2524 | break; | |
2525 | } | |
2526 | if (q == NULL) | |
2527 | pp = &p->next; | |
2528 | } | |
2529 | *pp = edir->dyn_relocs; | |
2530 | } | |
2531 | ||
2532 | edir->dyn_relocs = eind->dyn_relocs; | |
2533 | eind->dyn_relocs = NULL; | |
2534 | } | |
2535 | ||
a06ea964 NC |
2536 | if (ind->root.type == bfd_link_hash_indirect) |
2537 | { | |
2538 | /* Copy over PLT info. */ | |
2539 | if (dir->got.refcount <= 0) | |
2540 | { | |
2541 | edir->got_type = eind->got_type; | |
2542 | eind->got_type = GOT_UNKNOWN; | |
2543 | } | |
2544 | } | |
2545 | ||
2546 | _bfd_elf_link_hash_copy_indirect (info, dir, ind); | |
2547 | } | |
2548 | ||
68faa637 AM |
2549 | /* Destroy an AArch64 elf linker hash table. */ |
2550 | ||
2551 | static void | |
d495ab0d | 2552 | elfNN_aarch64_link_hash_table_free (bfd *obfd) |
68faa637 AM |
2553 | { |
2554 | struct elf_aarch64_link_hash_table *ret | |
d495ab0d | 2555 | = (struct elf_aarch64_link_hash_table *) obfd->link.hash; |
68faa637 AM |
2556 | |
2557 | if (ret->loc_hash_table) | |
2558 | htab_delete (ret->loc_hash_table); | |
2559 | if (ret->loc_hash_memory) | |
2560 | objalloc_free ((struct objalloc *) ret->loc_hash_memory); | |
2561 | ||
2562 | bfd_hash_table_free (&ret->stub_hash_table); | |
d495ab0d | 2563 | _bfd_elf_link_hash_table_free (obfd); |
68faa637 AM |
2564 | } |
2565 | ||
a06ea964 NC |
2566 | /* Create an AArch64 elf linker hash table. */ |
2567 | ||
2568 | static struct bfd_link_hash_table * | |
cec5225b | 2569 | elfNN_aarch64_link_hash_table_create (bfd *abfd) |
a06ea964 | 2570 | { |
cec5225b YZ |
2571 | struct elf_aarch64_link_hash_table *ret; |
2572 | bfd_size_type amt = sizeof (struct elf_aarch64_link_hash_table); | |
a06ea964 | 2573 | |
7bf52ea2 | 2574 | ret = bfd_zmalloc (amt); |
a06ea964 NC |
2575 | if (ret == NULL) |
2576 | return NULL; | |
2577 | ||
2578 | if (!_bfd_elf_link_hash_table_init | |
cec5225b YZ |
2579 | (&ret->root, abfd, elfNN_aarch64_link_hash_newfunc, |
2580 | sizeof (struct elf_aarch64_link_hash_entry), AARCH64_ELF_DATA)) | |
a06ea964 NC |
2581 | { |
2582 | free (ret); | |
2583 | return NULL; | |
2584 | } | |
2585 | ||
a06ea964 NC |
2586 | ret->plt_header_size = PLT_ENTRY_SIZE; |
2587 | ret->plt_entry_size = PLT_SMALL_ENTRY_SIZE; | |
a06ea964 | 2588 | ret->obfd = abfd; |
a06ea964 NC |
2589 | ret->dt_tlsdesc_got = (bfd_vma) - 1; |
2590 | ||
2591 | if (!bfd_hash_table_init (&ret->stub_hash_table, stub_hash_newfunc, | |
cec5225b | 2592 | sizeof (struct elf_aarch64_stub_hash_entry))) |
a06ea964 | 2593 | { |
d495ab0d | 2594 | _bfd_elf_link_hash_table_free (abfd); |
a06ea964 NC |
2595 | return NULL; |
2596 | } | |
2597 | ||
1419bbe5 WN |
2598 | ret->loc_hash_table = htab_try_create (1024, |
2599 | elfNN_aarch64_local_htab_hash, | |
2600 | elfNN_aarch64_local_htab_eq, | |
2601 | NULL); | |
2602 | ret->loc_hash_memory = objalloc_create (); | |
2603 | if (!ret->loc_hash_table || !ret->loc_hash_memory) | |
2604 | { | |
d495ab0d | 2605 | elfNN_aarch64_link_hash_table_free (abfd); |
1419bbe5 WN |
2606 | return NULL; |
2607 | } | |
d495ab0d | 2608 | ret->root.root.hash_table_free = elfNN_aarch64_link_hash_table_free; |
1419bbe5 | 2609 | |
a06ea964 NC |
2610 | return &ret->root.root; |
2611 | } | |
2612 | ||
1d75a8e2 NC |
2613 | /* Perform relocation R_TYPE. Returns TRUE upon success, FALSE otherwise. */ |
2614 | ||
a06ea964 NC |
2615 | static bfd_boolean |
2616 | aarch64_relocate (unsigned int r_type, bfd *input_bfd, asection *input_section, | |
2617 | bfd_vma offset, bfd_vma value) | |
2618 | { | |
2619 | reloc_howto_type *howto; | |
2620 | bfd_vma place; | |
2621 | ||
cec5225b | 2622 | howto = elfNN_aarch64_howto_from_type (r_type); |
a06ea964 NC |
2623 | place = (input_section->output_section->vma + input_section->output_offset |
2624 | + offset); | |
caed7120 YZ |
2625 | |
2626 | r_type = elfNN_aarch64_bfd_reloc_from_type (r_type); | |
2627 | value = _bfd_aarch64_elf_resolve_relocation (r_type, place, value, 0, FALSE); | |
2628 | return _bfd_aarch64_elf_put_addend (input_bfd, | |
2629 | input_section->contents + offset, r_type, | |
1d75a8e2 | 2630 | howto, value) == bfd_reloc_ok; |
a06ea964 NC |
2631 | } |
2632 | ||
cec5225b | 2633 | static enum elf_aarch64_stub_type |
a06ea964 NC |
2634 | aarch64_select_branch_stub (bfd_vma value, bfd_vma place) |
2635 | { | |
2636 | if (aarch64_valid_for_adrp_p (value, place)) | |
2637 | return aarch64_stub_adrp_branch; | |
2638 | return aarch64_stub_long_branch; | |
2639 | } | |
2640 | ||
2641 | /* Determine the type of stub needed, if any, for a call. */ | |
2642 | ||
cec5225b | 2643 | static enum elf_aarch64_stub_type |
9a228467 | 2644 | aarch64_type_of_stub (asection *input_sec, |
a06ea964 | 2645 | const Elf_Internal_Rela *rel, |
f678ded7 | 2646 | asection *sym_sec, |
a06ea964 | 2647 | unsigned char st_type, |
a06ea964 NC |
2648 | bfd_vma destination) |
2649 | { | |
2650 | bfd_vma location; | |
2651 | bfd_signed_vma branch_offset; | |
2652 | unsigned int r_type; | |
cec5225b | 2653 | enum elf_aarch64_stub_type stub_type = aarch64_stub_none; |
a06ea964 | 2654 | |
f678ded7 | 2655 | if (st_type != STT_FUNC |
2f340668 | 2656 | && (sym_sec == input_sec)) |
a06ea964 NC |
2657 | return stub_type; |
2658 | ||
a06ea964 NC |
2659 | /* Determine where the call point is. */ |
2660 | location = (input_sec->output_offset | |
2661 | + input_sec->output_section->vma + rel->r_offset); | |
2662 | ||
2663 | branch_offset = (bfd_signed_vma) (destination - location); | |
2664 | ||
cec5225b | 2665 | r_type = ELFNN_R_TYPE (rel->r_info); |
a06ea964 NC |
2666 | |
2667 | /* We don't want to redirect any old unconditional jump in this way, | |
2668 | only one which is being used for a sibcall, where it is | |
2669 | acceptable for the IP0 and IP1 registers to be clobbered. */ | |
a6bb11b2 | 2670 | if ((r_type == AARCH64_R (CALL26) || r_type == AARCH64_R (JUMP26)) |
a06ea964 NC |
2671 | && (branch_offset > AARCH64_MAX_FWD_BRANCH_OFFSET |
2672 | || branch_offset < AARCH64_MAX_BWD_BRANCH_OFFSET)) | |
2673 | { | |
2674 | stub_type = aarch64_stub_long_branch; | |
2675 | } | |
2676 | ||
2677 | return stub_type; | |
2678 | } | |
2679 | ||
2680 | /* Build a name for an entry in the stub hash table. */ | |
2681 | ||
2682 | static char * | |
cec5225b | 2683 | elfNN_aarch64_stub_name (const asection *input_section, |
a06ea964 | 2684 | const asection *sym_sec, |
cec5225b | 2685 | const struct elf_aarch64_link_hash_entry *hash, |
a06ea964 NC |
2686 | const Elf_Internal_Rela *rel) |
2687 | { | |
2688 | char *stub_name; | |
2689 | bfd_size_type len; | |
2690 | ||
2691 | if (hash) | |
2692 | { | |
2693 | len = 8 + 1 + strlen (hash->root.root.root.string) + 1 + 16 + 1; | |
2694 | stub_name = bfd_malloc (len); | |
2695 | if (stub_name != NULL) | |
2696 | snprintf (stub_name, len, "%08x_%s+%" BFD_VMA_FMT "x", | |
2697 | (unsigned int) input_section->id, | |
2698 | hash->root.root.root.string, | |
2699 | rel->r_addend); | |
2700 | } | |
2701 | else | |
2702 | { | |
2703 | len = 8 + 1 + 8 + 1 + 8 + 1 + 16 + 1; | |
2704 | stub_name = bfd_malloc (len); | |
2705 | if (stub_name != NULL) | |
2706 | snprintf (stub_name, len, "%08x_%x:%x+%" BFD_VMA_FMT "x", | |
2707 | (unsigned int) input_section->id, | |
2708 | (unsigned int) sym_sec->id, | |
cec5225b | 2709 | (unsigned int) ELFNN_R_SYM (rel->r_info), |
a06ea964 NC |
2710 | rel->r_addend); |
2711 | } | |
2712 | ||
2713 | return stub_name; | |
2714 | } | |
2715 | ||
7f784814 JW |
2716 | /* Return TRUE if symbol H should be hashed in the `.gnu.hash' section. For |
2717 | executable PLT slots where the executable never takes the address of those | |
2718 | functions, the function symbols are not added to the hash table. */ | |
2719 | ||
2720 | static bfd_boolean | |
2721 | elf_aarch64_hash_symbol (struct elf_link_hash_entry *h) | |
2722 | { | |
2723 | if (h->plt.offset != (bfd_vma) -1 | |
2724 | && !h->def_regular | |
2725 | && !h->pointer_equality_needed) | |
2726 | return FALSE; | |
2727 | ||
2728 | return _bfd_elf_hash_symbol (h); | |
2729 | } | |
2730 | ||
2731 | ||
a06ea964 NC |
2732 | /* Look up an entry in the stub hash. Stub entries are cached because |
2733 | creating the stub name takes a bit of time. */ | |
2734 | ||
cec5225b YZ |
2735 | static struct elf_aarch64_stub_hash_entry * |
2736 | elfNN_aarch64_get_stub_entry (const asection *input_section, | |
a06ea964 NC |
2737 | const asection *sym_sec, |
2738 | struct elf_link_hash_entry *hash, | |
2739 | const Elf_Internal_Rela *rel, | |
cec5225b | 2740 | struct elf_aarch64_link_hash_table *htab) |
a06ea964 | 2741 | { |
cec5225b YZ |
2742 | struct elf_aarch64_stub_hash_entry *stub_entry; |
2743 | struct elf_aarch64_link_hash_entry *h = | |
2744 | (struct elf_aarch64_link_hash_entry *) hash; | |
a06ea964 NC |
2745 | const asection *id_sec; |
2746 | ||
2747 | if ((input_section->flags & SEC_CODE) == 0) | |
2748 | return NULL; | |
2749 | ||
2750 | /* If this input section is part of a group of sections sharing one | |
2751 | stub section, then use the id of the first section in the group. | |
2752 | Stub names need to include a section id, as there may well be | |
2753 | more than one stub used to reach say, printf, and we need to | |
2754 | distinguish between them. */ | |
2755 | id_sec = htab->stub_group[input_section->id].link_sec; | |
2756 | ||
2757 | if (h != NULL && h->stub_cache != NULL | |
2758 | && h->stub_cache->h == h && h->stub_cache->id_sec == id_sec) | |
2759 | { | |
2760 | stub_entry = h->stub_cache; | |
2761 | } | |
2762 | else | |
2763 | { | |
2764 | char *stub_name; | |
2765 | ||
cec5225b | 2766 | stub_name = elfNN_aarch64_stub_name (id_sec, sym_sec, h, rel); |
a06ea964 NC |
2767 | if (stub_name == NULL) |
2768 | return NULL; | |
2769 | ||
2770 | stub_entry = aarch64_stub_hash_lookup (&htab->stub_hash_table, | |
2771 | stub_name, FALSE, FALSE); | |
2772 | if (h != NULL) | |
2773 | h->stub_cache = stub_entry; | |
2774 | ||
2775 | free (stub_name); | |
2776 | } | |
2777 | ||
2778 | return stub_entry; | |
2779 | } | |
2780 | ||
a06ea964 | 2781 | |
66585675 MS |
2782 | /* Create a stub section. */ |
2783 | ||
2784 | static asection * | |
2785 | _bfd_aarch64_create_stub_section (asection *section, | |
2786 | struct elf_aarch64_link_hash_table *htab) | |
2787 | { | |
2788 | size_t namelen; | |
2789 | bfd_size_type len; | |
2790 | char *s_name; | |
2791 | ||
2792 | namelen = strlen (section->name); | |
2793 | len = namelen + sizeof (STUB_SUFFIX); | |
2794 | s_name = bfd_alloc (htab->stub_bfd, len); | |
2795 | if (s_name == NULL) | |
2796 | return NULL; | |
2797 | ||
2798 | memcpy (s_name, section->name, namelen); | |
2799 | memcpy (s_name + namelen, STUB_SUFFIX, sizeof (STUB_SUFFIX)); | |
2800 | return (*htab->add_stub_section) (s_name, section); | |
2801 | } | |
2802 | ||
2803 | ||
fc6d53be MS |
2804 | /* Find or create a stub section for a link section. |
2805 | ||
2806 | Fix or create the stub section used to collect stubs attached to | |
2807 | the specified link section. */ | |
2808 | ||
2809 | static asection * | |
2810 | _bfd_aarch64_get_stub_for_link_section (asection *link_section, | |
2811 | struct elf_aarch64_link_hash_table *htab) | |
2812 | { | |
2813 | if (htab->stub_group[link_section->id].stub_sec == NULL) | |
2814 | htab->stub_group[link_section->id].stub_sec | |
2815 | = _bfd_aarch64_create_stub_section (link_section, htab); | |
2816 | return htab->stub_group[link_section->id].stub_sec; | |
2817 | } | |
2818 | ||
2819 | ||
ef857521 MS |
2820 | /* Find or create a stub section in the stub group for an input |
2821 | section. */ | |
2822 | ||
2823 | static asection * | |
2824 | _bfd_aarch64_create_or_find_stub_sec (asection *section, | |
2825 | struct elf_aarch64_link_hash_table *htab) | |
a06ea964 | 2826 | { |
fc6d53be MS |
2827 | asection *link_sec = htab->stub_group[section->id].link_sec; |
2828 | return _bfd_aarch64_get_stub_for_link_section (link_sec, htab); | |
ef857521 MS |
2829 | } |
2830 | ||
2831 | ||
2832 | /* Add a new stub entry in the stub group associated with an input | |
2833 | section to the stub hash. Not all fields of the new stub entry are | |
2834 | initialised. */ | |
2835 | ||
2836 | static struct elf_aarch64_stub_hash_entry * | |
2837 | _bfd_aarch64_add_stub_entry_in_group (const char *stub_name, | |
2838 | asection *section, | |
2839 | struct elf_aarch64_link_hash_table *htab) | |
2840 | { | |
2841 | asection *link_sec; | |
2842 | asection *stub_sec; | |
2843 | struct elf_aarch64_stub_hash_entry *stub_entry; | |
2844 | ||
2845 | link_sec = htab->stub_group[section->id].link_sec; | |
2846 | stub_sec = _bfd_aarch64_create_or_find_stub_sec (section, htab); | |
2847 | ||
a06ea964 NC |
2848 | /* Enter this entry into the linker stub hash table. */ |
2849 | stub_entry = aarch64_stub_hash_lookup (&htab->stub_hash_table, stub_name, | |
2850 | TRUE, FALSE); | |
2851 | if (stub_entry == NULL) | |
2852 | { | |
695344c0 | 2853 | /* xgettext:c-format */ |
dae82561 | 2854 | _bfd_error_handler (_("%B: cannot create stub entry %s"), |
4eca0228 | 2855 | section->owner, stub_name); |
a06ea964 NC |
2856 | return NULL; |
2857 | } | |
2858 | ||
2859 | stub_entry->stub_sec = stub_sec; | |
2860 | stub_entry->stub_offset = 0; | |
2861 | stub_entry->id_sec = link_sec; | |
2862 | ||
2863 | return stub_entry; | |
2864 | } | |
2865 | ||
4106101c MS |
2866 | /* Add a new stub entry in the final stub section to the stub hash. |
2867 | Not all fields of the new stub entry are initialised. */ | |
2868 | ||
2869 | static struct elf_aarch64_stub_hash_entry * | |
2870 | _bfd_aarch64_add_stub_entry_after (const char *stub_name, | |
2871 | asection *link_section, | |
2872 | struct elf_aarch64_link_hash_table *htab) | |
2873 | { | |
2874 | asection *stub_sec; | |
2875 | struct elf_aarch64_stub_hash_entry *stub_entry; | |
2876 | ||
2877 | stub_sec = _bfd_aarch64_get_stub_for_link_section (link_section, htab); | |
2878 | stub_entry = aarch64_stub_hash_lookup (&htab->stub_hash_table, stub_name, | |
2879 | TRUE, FALSE); | |
2880 | if (stub_entry == NULL) | |
2881 | { | |
4eca0228 | 2882 | _bfd_error_handler (_("cannot create stub entry %s"), stub_name); |
4106101c MS |
2883 | return NULL; |
2884 | } | |
2885 | ||
2886 | stub_entry->stub_sec = stub_sec; | |
2887 | stub_entry->stub_offset = 0; | |
2888 | stub_entry->id_sec = link_section; | |
2889 | ||
2890 | return stub_entry; | |
2891 | } | |
2892 | ||
2893 | ||
a06ea964 NC |
2894 | static bfd_boolean |
2895 | aarch64_build_one_stub (struct bfd_hash_entry *gen_entry, | |
2896 | void *in_arg ATTRIBUTE_UNUSED) | |
2897 | { | |
cec5225b | 2898 | struct elf_aarch64_stub_hash_entry *stub_entry; |
a06ea964 NC |
2899 | asection *stub_sec; |
2900 | bfd *stub_bfd; | |
2901 | bfd_byte *loc; | |
2902 | bfd_vma sym_value; | |
68fcca92 JW |
2903 | bfd_vma veneered_insn_loc; |
2904 | bfd_vma veneer_entry_loc; | |
2905 | bfd_signed_vma branch_offset = 0; | |
a06ea964 NC |
2906 | unsigned int template_size; |
2907 | const uint32_t *template; | |
2908 | unsigned int i; | |
2909 | ||
2910 | /* Massage our args to the form they really have. */ | |
cec5225b | 2911 | stub_entry = (struct elf_aarch64_stub_hash_entry *) gen_entry; |
a06ea964 NC |
2912 | |
2913 | stub_sec = stub_entry->stub_sec; | |
2914 | ||
2915 | /* Make a note of the offset within the stubs for this entry. */ | |
2916 | stub_entry->stub_offset = stub_sec->size; | |
2917 | loc = stub_sec->contents + stub_entry->stub_offset; | |
2918 | ||
2919 | stub_bfd = stub_sec->owner; | |
2920 | ||
2921 | /* This is the address of the stub destination. */ | |
2922 | sym_value = (stub_entry->target_value | |
2923 | + stub_entry->target_section->output_offset | |
2924 | + stub_entry->target_section->output_section->vma); | |
2925 | ||
2926 | if (stub_entry->stub_type == aarch64_stub_long_branch) | |
2927 | { | |
2928 | bfd_vma place = (stub_entry->stub_offset + stub_sec->output_section->vma | |
2929 | + stub_sec->output_offset); | |
2930 | ||
2931 | /* See if we can relax the stub. */ | |
2932 | if (aarch64_valid_for_adrp_p (sym_value, place)) | |
2933 | stub_entry->stub_type = aarch64_select_branch_stub (sym_value, place); | |
2934 | } | |
2935 | ||
2936 | switch (stub_entry->stub_type) | |
2937 | { | |
2938 | case aarch64_stub_adrp_branch: | |
2939 | template = aarch64_adrp_branch_stub; | |
2940 | template_size = sizeof (aarch64_adrp_branch_stub); | |
2941 | break; | |
2942 | case aarch64_stub_long_branch: | |
2943 | template = aarch64_long_branch_stub; | |
2944 | template_size = sizeof (aarch64_long_branch_stub); | |
2945 | break; | |
68fcca92 JW |
2946 | case aarch64_stub_erratum_835769_veneer: |
2947 | template = aarch64_erratum_835769_stub; | |
2948 | template_size = sizeof (aarch64_erratum_835769_stub); | |
2949 | break; | |
4106101c MS |
2950 | case aarch64_stub_erratum_843419_veneer: |
2951 | template = aarch64_erratum_843419_stub; | |
2952 | template_size = sizeof (aarch64_erratum_843419_stub); | |
2953 | break; | |
a06ea964 | 2954 | default: |
8e2fe09f | 2955 | abort (); |
a06ea964 NC |
2956 | } |
2957 | ||
2958 | for (i = 0; i < (template_size / sizeof template[0]); i++) | |
2959 | { | |
2960 | bfd_putl32 (template[i], loc); | |
2961 | loc += 4; | |
2962 | } | |
2963 | ||
2964 | template_size = (template_size + 7) & ~7; | |
2965 | stub_sec->size += template_size; | |
2966 | ||
2967 | switch (stub_entry->stub_type) | |
2968 | { | |
2969 | case aarch64_stub_adrp_branch: | |
1d75a8e2 NC |
2970 | if (!aarch64_relocate (AARCH64_R (ADR_PREL_PG_HI21), stub_bfd, stub_sec, |
2971 | stub_entry->stub_offset, sym_value)) | |
a06ea964 NC |
2972 | /* The stub would not have been relaxed if the offset was out |
2973 | of range. */ | |
2974 | BFD_FAIL (); | |
2975 | ||
1d75a8e2 NC |
2976 | if (!aarch64_relocate (AARCH64_R (ADD_ABS_LO12_NC), stub_bfd, stub_sec, |
2977 | stub_entry->stub_offset + 4, sym_value)) | |
93ca8569 | 2978 | BFD_FAIL (); |
a06ea964 NC |
2979 | break; |
2980 | ||
2981 | case aarch64_stub_long_branch: | |
2982 | /* We want the value relative to the address 12 bytes back from the | |
2983 | value itself. */ | |
1d75a8e2 NC |
2984 | if (!aarch64_relocate (AARCH64_R (PRELNN), stub_bfd, stub_sec, |
2985 | stub_entry->stub_offset + 16, sym_value + 12)) | |
93ca8569 | 2986 | BFD_FAIL (); |
a06ea964 | 2987 | break; |
68fcca92 JW |
2988 | |
2989 | case aarch64_stub_erratum_835769_veneer: | |
2990 | veneered_insn_loc = stub_entry->target_section->output_section->vma | |
2991 | + stub_entry->target_section->output_offset | |
2992 | + stub_entry->target_value; | |
2993 | veneer_entry_loc = stub_entry->stub_sec->output_section->vma | |
2994 | + stub_entry->stub_sec->output_offset | |
2995 | + stub_entry->stub_offset; | |
2996 | branch_offset = veneered_insn_loc - veneer_entry_loc; | |
2997 | branch_offset >>= 2; | |
2998 | branch_offset &= 0x3ffffff; | |
2999 | bfd_putl32 (stub_entry->veneered_insn, | |
3000 | stub_sec->contents + stub_entry->stub_offset); | |
3001 | bfd_putl32 (template[1] | branch_offset, | |
3002 | stub_sec->contents + stub_entry->stub_offset + 4); | |
3003 | break; | |
3004 | ||
4106101c | 3005 | case aarch64_stub_erratum_843419_veneer: |
1d75a8e2 NC |
3006 | if (!aarch64_relocate (AARCH64_R (JUMP26), stub_bfd, stub_sec, |
3007 | stub_entry->stub_offset + 4, sym_value + 4)) | |
4106101c MS |
3008 | BFD_FAIL (); |
3009 | break; | |
3010 | ||
a06ea964 | 3011 | default: |
8e2fe09f | 3012 | abort (); |
a06ea964 NC |
3013 | } |
3014 | ||
3015 | return TRUE; | |
3016 | } | |
3017 | ||
3018 | /* As above, but don't actually build the stub. Just bump offset so | |
3019 | we know stub section sizes. */ | |
3020 | ||
3021 | static bfd_boolean | |
3022 | aarch64_size_one_stub (struct bfd_hash_entry *gen_entry, | |
3023 | void *in_arg ATTRIBUTE_UNUSED) | |
3024 | { | |
cec5225b | 3025 | struct elf_aarch64_stub_hash_entry *stub_entry; |
a06ea964 NC |
3026 | int size; |
3027 | ||
3028 | /* Massage our args to the form they really have. */ | |
cec5225b | 3029 | stub_entry = (struct elf_aarch64_stub_hash_entry *) gen_entry; |
a06ea964 NC |
3030 | |
3031 | switch (stub_entry->stub_type) | |
3032 | { | |
3033 | case aarch64_stub_adrp_branch: | |
3034 | size = sizeof (aarch64_adrp_branch_stub); | |
3035 | break; | |
3036 | case aarch64_stub_long_branch: | |
3037 | size = sizeof (aarch64_long_branch_stub); | |
3038 | break; | |
68fcca92 JW |
3039 | case aarch64_stub_erratum_835769_veneer: |
3040 | size = sizeof (aarch64_erratum_835769_stub); | |
3041 | break; | |
4106101c MS |
3042 | case aarch64_stub_erratum_843419_veneer: |
3043 | size = sizeof (aarch64_erratum_843419_stub); | |
3044 | break; | |
a06ea964 | 3045 | default: |
8e2fe09f | 3046 | abort (); |
a06ea964 NC |
3047 | } |
3048 | ||
3049 | size = (size + 7) & ~7; | |
3050 | stub_entry->stub_sec->size += size; | |
3051 | return TRUE; | |
3052 | } | |
3053 | ||
3054 | /* External entry points for sizing and building linker stubs. */ | |
3055 | ||
3056 | /* Set up various things so that we can make a list of input sections | |
3057 | for each output section included in the link. Returns -1 on error, | |
3058 | 0 when no stubs will be needed, and 1 on success. */ | |
3059 | ||
3060 | int | |
cec5225b | 3061 | elfNN_aarch64_setup_section_lists (bfd *output_bfd, |
a06ea964 NC |
3062 | struct bfd_link_info *info) |
3063 | { | |
3064 | bfd *input_bfd; | |
3065 | unsigned int bfd_count; | |
7292b3ac | 3066 | unsigned int top_id, top_index; |
a06ea964 NC |
3067 | asection *section; |
3068 | asection **input_list, **list; | |
3069 | bfd_size_type amt; | |
cec5225b YZ |
3070 | struct elf_aarch64_link_hash_table *htab = |
3071 | elf_aarch64_hash_table (info); | |
a06ea964 NC |
3072 | |
3073 | if (!is_elf_hash_table (htab)) | |
3074 | return 0; | |
3075 | ||
3076 | /* Count the number of input BFDs and find the top input section id. */ | |
3077 | for (input_bfd = info->input_bfds, bfd_count = 0, top_id = 0; | |
c72f2fb2 | 3078 | input_bfd != NULL; input_bfd = input_bfd->link.next) |
a06ea964 NC |
3079 | { |
3080 | bfd_count += 1; | |
3081 | for (section = input_bfd->sections; | |
3082 | section != NULL; section = section->next) | |
3083 | { | |
3084 | if (top_id < section->id) | |
3085 | top_id = section->id; | |
3086 | } | |
3087 | } | |
3088 | htab->bfd_count = bfd_count; | |
3089 | ||
3090 | amt = sizeof (struct map_stub) * (top_id + 1); | |
3091 | htab->stub_group = bfd_zmalloc (amt); | |
3092 | if (htab->stub_group == NULL) | |
3093 | return -1; | |
3094 | ||
3095 | /* We can't use output_bfd->section_count here to find the top output | |
3096 | section index as some sections may have been removed, and | |
3097 | _bfd_strip_section_from_output doesn't renumber the indices. */ | |
3098 | for (section = output_bfd->sections, top_index = 0; | |
3099 | section != NULL; section = section->next) | |
3100 | { | |
3101 | if (top_index < section->index) | |
3102 | top_index = section->index; | |
3103 | } | |
3104 | ||
3105 | htab->top_index = top_index; | |
3106 | amt = sizeof (asection *) * (top_index + 1); | |
3107 | input_list = bfd_malloc (amt); | |
3108 | htab->input_list = input_list; | |
3109 | if (input_list == NULL) | |
3110 | return -1; | |
3111 | ||
3112 | /* For sections we aren't interested in, mark their entries with a | |
3113 | value we can check later. */ | |
3114 | list = input_list + top_index; | |
3115 | do | |
3116 | *list = bfd_abs_section_ptr; | |
3117 | while (list-- != input_list); | |
3118 | ||
3119 | for (section = output_bfd->sections; | |
3120 | section != NULL; section = section->next) | |
3121 | { | |
3122 | if ((section->flags & SEC_CODE) != 0) | |
3123 | input_list[section->index] = NULL; | |
3124 | } | |
3125 | ||
3126 | return 1; | |
3127 | } | |
3128 | ||
cec5225b | 3129 | /* Used by elfNN_aarch64_next_input_section and group_sections. */ |
a06ea964 NC |
3130 | #define PREV_SEC(sec) (htab->stub_group[(sec)->id].link_sec) |
3131 | ||
3132 | /* The linker repeatedly calls this function for each input section, | |
3133 | in the order that input sections are linked into output sections. | |
3134 | Build lists of input sections to determine groupings between which | |
3135 | we may insert linker stubs. */ | |
3136 | ||
3137 | void | |
cec5225b | 3138 | elfNN_aarch64_next_input_section (struct bfd_link_info *info, asection *isec) |
a06ea964 | 3139 | { |
cec5225b YZ |
3140 | struct elf_aarch64_link_hash_table *htab = |
3141 | elf_aarch64_hash_table (info); | |
a06ea964 NC |
3142 | |
3143 | if (isec->output_section->index <= htab->top_index) | |
3144 | { | |
3145 | asection **list = htab->input_list + isec->output_section->index; | |
3146 | ||
3147 | if (*list != bfd_abs_section_ptr) | |
3148 | { | |
3149 | /* Steal the link_sec pointer for our list. */ | |
3150 | /* This happens to make the list in reverse order, | |
3151 | which is what we want. */ | |
3152 | PREV_SEC (isec) = *list; | |
3153 | *list = isec; | |
3154 | } | |
3155 | } | |
3156 | } | |
3157 | ||
3158 | /* See whether we can group stub sections together. Grouping stub | |
3159 | sections may result in fewer stubs. More importantly, we need to | |
3160 | put all .init* and .fini* stubs at the beginning of the .init or | |
3161 | .fini output sections respectively, because glibc splits the | |
3162 | _init and _fini functions into multiple parts. Putting a stub in | |
3163 | the middle of a function is not a good idea. */ | |
3164 | ||
3165 | static void | |
cec5225b | 3166 | group_sections (struct elf_aarch64_link_hash_table *htab, |
a06ea964 NC |
3167 | bfd_size_type stub_group_size, |
3168 | bfd_boolean stubs_always_before_branch) | |
3169 | { | |
3170 | asection **list = htab->input_list + htab->top_index; | |
3171 | ||
3172 | do | |
3173 | { | |
3174 | asection *tail = *list; | |
3175 | ||
3176 | if (tail == bfd_abs_section_ptr) | |
3177 | continue; | |
3178 | ||
3179 | while (tail != NULL) | |
3180 | { | |
3181 | asection *curr; | |
3182 | asection *prev; | |
3183 | bfd_size_type total; | |
3184 | ||
3185 | curr = tail; | |
3186 | total = tail->size; | |
3187 | while ((prev = PREV_SEC (curr)) != NULL | |
3188 | && ((total += curr->output_offset - prev->output_offset) | |
3189 | < stub_group_size)) | |
3190 | curr = prev; | |
3191 | ||
3192 | /* OK, the size from the start of CURR to the end is less | |
3193 | than stub_group_size and thus can be handled by one stub | |
3194 | section. (Or the tail section is itself larger than | |
3195 | stub_group_size, in which case we may be toast.) | |
3196 | We should really be keeping track of the total size of | |
3197 | stubs added here, as stubs contribute to the final output | |
3198 | section size. */ | |
3199 | do | |
3200 | { | |
3201 | prev = PREV_SEC (tail); | |
3202 | /* Set up this stub group. */ | |
3203 | htab->stub_group[tail->id].link_sec = curr; | |
3204 | } | |
3205 | while (tail != curr && (tail = prev) != NULL); | |
3206 | ||
3207 | /* But wait, there's more! Input sections up to stub_group_size | |
3208 | bytes before the stub section can be handled by it too. */ | |
3209 | if (!stubs_always_before_branch) | |
3210 | { | |
3211 | total = 0; | |
3212 | while (prev != NULL | |
3213 | && ((total += tail->output_offset - prev->output_offset) | |
3214 | < stub_group_size)) | |
3215 | { | |
3216 | tail = prev; | |
3217 | prev = PREV_SEC (tail); | |
3218 | htab->stub_group[tail->id].link_sec = curr; | |
3219 | } | |
3220 | } | |
3221 | tail = prev; | |
3222 | } | |
3223 | } | |
3224 | while (list-- != htab->input_list); | |
3225 | ||
3226 | free (htab->input_list); | |
3227 | } | |
3228 | ||
3229 | #undef PREV_SEC | |
3230 | ||
68fcca92 JW |
3231 | #define AARCH64_BITS(x, pos, n) (((x) >> (pos)) & ((1 << (n)) - 1)) |
3232 | ||
3233 | #define AARCH64_RT(insn) AARCH64_BITS (insn, 0, 5) | |
3234 | #define AARCH64_RT2(insn) AARCH64_BITS (insn, 10, 5) | |
3235 | #define AARCH64_RA(insn) AARCH64_BITS (insn, 10, 5) | |
3236 | #define AARCH64_RD(insn) AARCH64_BITS (insn, 0, 5) | |
3237 | #define AARCH64_RN(insn) AARCH64_BITS (insn, 5, 5) | |
3238 | #define AARCH64_RM(insn) AARCH64_BITS (insn, 16, 5) | |
3239 | ||
3240 | #define AARCH64_MAC(insn) (((insn) & 0xff000000) == 0x9b000000) | |
3241 | #define AARCH64_BIT(insn, n) AARCH64_BITS (insn, n, 1) | |
3242 | #define AARCH64_OP31(insn) AARCH64_BITS (insn, 21, 3) | |
3243 | #define AARCH64_ZR 0x1f | |
3244 | ||
3245 | /* All ld/st ops. See C4-182 of the ARM ARM. The encoding space for | |
3246 | LD_PCREL, LDST_RO, LDST_UI and LDST_UIMM cover prefetch ops. */ | |
3247 | ||
3248 | #define AARCH64_LD(insn) (AARCH64_BIT (insn, 22) == 1) | |
3249 | #define AARCH64_LDST(insn) (((insn) & 0x0a000000) == 0x08000000) | |
3250 | #define AARCH64_LDST_EX(insn) (((insn) & 0x3f000000) == 0x08000000) | |
3251 | #define AARCH64_LDST_PCREL(insn) (((insn) & 0x3b000000) == 0x18000000) | |
3252 | #define AARCH64_LDST_NAP(insn) (((insn) & 0x3b800000) == 0x28000000) | |
3253 | #define AARCH64_LDSTP_PI(insn) (((insn) & 0x3b800000) == 0x28800000) | |
3254 | #define AARCH64_LDSTP_O(insn) (((insn) & 0x3b800000) == 0x29000000) | |
3255 | #define AARCH64_LDSTP_PRE(insn) (((insn) & 0x3b800000) == 0x29800000) | |
3256 | #define AARCH64_LDST_UI(insn) (((insn) & 0x3b200c00) == 0x38000000) | |
3257 | #define AARCH64_LDST_PIIMM(insn) (((insn) & 0x3b200c00) == 0x38000400) | |
3258 | #define AARCH64_LDST_U(insn) (((insn) & 0x3b200c00) == 0x38000800) | |
3259 | #define AARCH64_LDST_PREIMM(insn) (((insn) & 0x3b200c00) == 0x38000c00) | |
3260 | #define AARCH64_LDST_RO(insn) (((insn) & 0x3b200c00) == 0x38200800) | |
3261 | #define AARCH64_LDST_UIMM(insn) (((insn) & 0x3b000000) == 0x39000000) | |
3262 | #define AARCH64_LDST_SIMD_M(insn) (((insn) & 0xbfbf0000) == 0x0c000000) | |
3263 | #define AARCH64_LDST_SIMD_M_PI(insn) (((insn) & 0xbfa00000) == 0x0c800000) | |
3264 | #define AARCH64_LDST_SIMD_S(insn) (((insn) & 0xbf9f0000) == 0x0d000000) | |
3265 | #define AARCH64_LDST_SIMD_S_PI(insn) (((insn) & 0xbf800000) == 0x0d800000) | |
3266 | ||
3d14faea MS |
3267 | /* Classify an INSN if it is indeed a load/store. |
3268 | ||
3269 | Return TRUE if INSN is a LD/ST instruction otherwise return FALSE. | |
3270 | ||
3271 | For scalar LD/ST instructions PAIR is FALSE, RT is returned and RT2 | |
3272 | is set equal to RT. | |
3273 | ||
2d0ca824 | 3274 | For LD/ST pair instructions PAIR is TRUE, RT and RT2 are returned. */ |
68fcca92 JW |
3275 | |
3276 | static bfd_boolean | |
3d14faea | 3277 | aarch64_mem_op_p (uint32_t insn, unsigned int *rt, unsigned int *rt2, |
68fcca92 JW |
3278 | bfd_boolean *pair, bfd_boolean *load) |
3279 | { | |
3280 | uint32_t opcode; | |
3281 | unsigned int r; | |
3282 | uint32_t opc = 0; | |
3283 | uint32_t v = 0; | |
3284 | uint32_t opc_v = 0; | |
3285 | ||
de194d85 | 3286 | /* Bail out quickly if INSN doesn't fall into the load-store |
68fcca92 JW |
3287 | encoding space. */ |
3288 | if (!AARCH64_LDST (insn)) | |
3289 | return FALSE; | |
3290 | ||
3291 | *pair = FALSE; | |
3292 | *load = FALSE; | |
3293 | if (AARCH64_LDST_EX (insn)) | |
3294 | { | |
3295 | *rt = AARCH64_RT (insn); | |
3d14faea | 3296 | *rt2 = *rt; |
68fcca92 JW |
3297 | if (AARCH64_BIT (insn, 21) == 1) |
3298 | { | |
3299 | *pair = TRUE; | |
3d14faea | 3300 | *rt2 = AARCH64_RT2 (insn); |
68fcca92 JW |
3301 | } |
3302 | *load = AARCH64_LD (insn); | |
3303 | return TRUE; | |
3304 | } | |
3305 | else if (AARCH64_LDST_NAP (insn) | |
3306 | || AARCH64_LDSTP_PI (insn) | |
3307 | || AARCH64_LDSTP_O (insn) | |
3308 | || AARCH64_LDSTP_PRE (insn)) | |
3309 | { | |
3310 | *pair = TRUE; | |
3311 | *rt = AARCH64_RT (insn); | |
3d14faea | 3312 | *rt2 = AARCH64_RT2 (insn); |
68fcca92 JW |
3313 | *load = AARCH64_LD (insn); |
3314 | return TRUE; | |
3315 | } | |
3316 | else if (AARCH64_LDST_PCREL (insn) | |
3317 | || AARCH64_LDST_UI (insn) | |
3318 | || AARCH64_LDST_PIIMM (insn) | |
3319 | || AARCH64_LDST_U (insn) | |
3320 | || AARCH64_LDST_PREIMM (insn) | |
3321 | || AARCH64_LDST_RO (insn) | |
3322 | || AARCH64_LDST_UIMM (insn)) | |
3323 | { | |
3324 | *rt = AARCH64_RT (insn); | |
3d14faea | 3325 | *rt2 = *rt; |
68fcca92 JW |
3326 | if (AARCH64_LDST_PCREL (insn)) |
3327 | *load = TRUE; | |
3328 | opc = AARCH64_BITS (insn, 22, 2); | |
3329 | v = AARCH64_BIT (insn, 26); | |
3330 | opc_v = opc | (v << 2); | |
3331 | *load = (opc_v == 1 || opc_v == 2 || opc_v == 3 | |
3332 | || opc_v == 5 || opc_v == 7); | |
3333 | return TRUE; | |
3334 | } | |
3335 | else if (AARCH64_LDST_SIMD_M (insn) | |
3336 | || AARCH64_LDST_SIMD_M_PI (insn)) | |
3337 | { | |
3338 | *rt = AARCH64_RT (insn); | |
3339 | *load = AARCH64_BIT (insn, 22); | |
3340 | opcode = (insn >> 12) & 0xf; | |
3341 | switch (opcode) | |
3342 | { | |
3343 | case 0: | |
3344 | case 2: | |
3d14faea | 3345 | *rt2 = *rt + 3; |
68fcca92 JW |
3346 | break; |
3347 | ||
3348 | case 4: | |
3349 | case 6: | |
3d14faea | 3350 | *rt2 = *rt + 2; |
68fcca92 JW |
3351 | break; |
3352 | ||
3353 | case 7: | |
3d14faea | 3354 | *rt2 = *rt; |
68fcca92 JW |
3355 | break; |
3356 | ||
3357 | case 8: | |
3358 | case 10: | |
3d14faea | 3359 | *rt2 = *rt + 1; |
68fcca92 JW |
3360 | break; |
3361 | ||
3362 | default: | |
3363 | return FALSE; | |
3364 | } | |
3365 | return TRUE; | |
3366 | } | |
3367 | else if (AARCH64_LDST_SIMD_S (insn) | |
3368 | || AARCH64_LDST_SIMD_S_PI (insn)) | |
3369 | { | |
3370 | *rt = AARCH64_RT (insn); | |
3371 | r = (insn >> 21) & 1; | |
3372 | *load = AARCH64_BIT (insn, 22); | |
3373 | opcode = (insn >> 13) & 0x7; | |
3374 | switch (opcode) | |
3375 | { | |
3376 | case 0: | |
3377 | case 2: | |
3378 | case 4: | |
3d14faea | 3379 | *rt2 = *rt + r; |
68fcca92 JW |
3380 | break; |
3381 | ||
3382 | case 1: | |
3383 | case 3: | |
3384 | case 5: | |
3d14faea | 3385 | *rt2 = *rt + (r == 0 ? 2 : 3); |
68fcca92 JW |
3386 | break; |
3387 | ||
3388 | case 6: | |
3d14faea | 3389 | *rt2 = *rt + r; |
68fcca92 JW |
3390 | break; |
3391 | ||
3392 | case 7: | |
3d14faea | 3393 | *rt2 = *rt + (r == 0 ? 2 : 3); |
68fcca92 JW |
3394 | break; |
3395 | ||
3396 | default: | |
3397 | return FALSE; | |
3398 | } | |
3399 | return TRUE; | |
3400 | } | |
3401 | ||
3402 | return FALSE; | |
3403 | } | |
3404 | ||
3405 | /* Return TRUE if INSN is multiply-accumulate. */ | |
3406 | ||
3407 | static bfd_boolean | |
3408 | aarch64_mlxl_p (uint32_t insn) | |
3409 | { | |
3410 | uint32_t op31 = AARCH64_OP31 (insn); | |
3411 | ||
3412 | if (AARCH64_MAC (insn) | |
3413 | && (op31 == 0 || op31 == 1 || op31 == 5) | |
3414 | /* Exclude MUL instructions which are encoded as a multiple accumulate | |
3415 | with RA = XZR. */ | |
3416 | && AARCH64_RA (insn) != AARCH64_ZR) | |
3417 | return TRUE; | |
3418 | ||
3419 | return FALSE; | |
3420 | } | |
3421 | ||
3422 | /* Some early revisions of the Cortex-A53 have an erratum (835769) whereby | |
3423 | it is possible for a 64-bit multiply-accumulate instruction to generate an | |
3424 | incorrect result. The details are quite complex and hard to | |
3425 | determine statically, since branches in the code may exist in some | |
3426 | circumstances, but all cases end with a memory (load, store, or | |
3427 | prefetch) instruction followed immediately by the multiply-accumulate | |
3428 | operation. We employ a linker patching technique, by moving the potentially | |
3429 | affected multiply-accumulate instruction into a patch region and replacing | |
3430 | the original instruction with a branch to the patch. This function checks | |
3431 | if INSN_1 is the memory operation followed by a multiply-accumulate | |
3432 | operation (INSN_2). Return TRUE if an erratum sequence is found, FALSE | |
3433 | if INSN_1 and INSN_2 are safe. */ | |
3434 | ||
3435 | static bfd_boolean | |
3436 | aarch64_erratum_sequence (uint32_t insn_1, uint32_t insn_2) | |
3437 | { | |
3438 | uint32_t rt; | |
3d14faea | 3439 | uint32_t rt2; |
68fcca92 JW |
3440 | uint32_t rn; |
3441 | uint32_t rm; | |
3442 | uint32_t ra; | |
3443 | bfd_boolean pair; | |
3444 | bfd_boolean load; | |
3445 | ||
3446 | if (aarch64_mlxl_p (insn_2) | |
3d14faea | 3447 | && aarch64_mem_op_p (insn_1, &rt, &rt2, &pair, &load)) |
68fcca92 JW |
3448 | { |
3449 | /* Any SIMD memory op is independent of the subsequent MLA | |
3450 | by definition of the erratum. */ | |
3451 | if (AARCH64_BIT (insn_1, 26)) | |
3452 | return TRUE; | |
3453 | ||
3454 | /* If not SIMD, check for integer memory ops and MLA relationship. */ | |
3455 | rn = AARCH64_RN (insn_2); | |
3456 | ra = AARCH64_RA (insn_2); | |
3457 | rm = AARCH64_RM (insn_2); | |
3458 | ||
3459 | /* If this is a load and there's a true(RAW) dependency, we are safe | |
3460 | and this is not an erratum sequence. */ | |
3461 | if (load && | |
3462 | (rt == rn || rt == rm || rt == ra | |
3d14faea | 3463 | || (pair && (rt2 == rn || rt2 == rm || rt2 == ra)))) |
68fcca92 JW |
3464 | return FALSE; |
3465 | ||
3466 | /* We conservatively put out stubs for all other cases (including | |
3467 | writebacks). */ | |
3468 | return TRUE; | |
3469 | } | |
3470 | ||
3471 | return FALSE; | |
3472 | } | |
3473 | ||
520c7b56 JW |
3474 | /* Used to order a list of mapping symbols by address. */ |
3475 | ||
3476 | static int | |
3477 | elf_aarch64_compare_mapping (const void *a, const void *b) | |
3478 | { | |
3479 | const elf_aarch64_section_map *amap = (const elf_aarch64_section_map *) a; | |
3480 | const elf_aarch64_section_map *bmap = (const elf_aarch64_section_map *) b; | |
3481 | ||
3482 | if (amap->vma > bmap->vma) | |
3483 | return 1; | |
3484 | else if (amap->vma < bmap->vma) | |
3485 | return -1; | |
3486 | else if (amap->type > bmap->type) | |
3487 | /* Ensure results do not depend on the host qsort for objects with | |
3488 | multiple mapping symbols at the same address by sorting on type | |
3489 | after vma. */ | |
3490 | return 1; | |
3491 | else if (amap->type < bmap->type) | |
3492 | return -1; | |
3493 | else | |
3494 | return 0; | |
3495 | } | |
3496 | ||
2144188d | 3497 | |
35fee8b7 MS |
3498 | static char * |
3499 | _bfd_aarch64_erratum_835769_stub_name (unsigned num_fixes) | |
3500 | { | |
3501 | char *stub_name = (char *) bfd_malloc | |
3502 | (strlen ("__erratum_835769_veneer_") + 16); | |
3503 | sprintf (stub_name,"__erratum_835769_veneer_%d", num_fixes); | |
3504 | return stub_name; | |
3505 | } | |
3506 | ||
4106101c | 3507 | /* Scan for Cortex-A53 erratum 835769 sequence. |
2144188d MS |
3508 | |
3509 | Return TRUE else FALSE on abnormal termination. */ | |
3510 | ||
68fcca92 | 3511 | static bfd_boolean |
5421cc6e MS |
3512 | _bfd_aarch64_erratum_835769_scan (bfd *input_bfd, |
3513 | struct bfd_link_info *info, | |
3514 | unsigned int *num_fixes_p) | |
68fcca92 JW |
3515 | { |
3516 | asection *section; | |
3517 | struct elf_aarch64_link_hash_table *htab = elf_aarch64_hash_table (info); | |
68fcca92 | 3518 | unsigned int num_fixes = *num_fixes_p; |
68fcca92 JW |
3519 | |
3520 | if (htab == NULL) | |
2144188d | 3521 | return TRUE; |
68fcca92 JW |
3522 | |
3523 | for (section = input_bfd->sections; | |
3524 | section != NULL; | |
3525 | section = section->next) | |
3526 | { | |
3527 | bfd_byte *contents = NULL; | |
3528 | struct _aarch64_elf_section_data *sec_data; | |
3529 | unsigned int span; | |
3530 | ||
3531 | if (elf_section_type (section) != SHT_PROGBITS | |
3532 | || (elf_section_flags (section) & SHF_EXECINSTR) == 0 | |
3533 | || (section->flags & SEC_EXCLUDE) != 0 | |
3534 | || (section->sec_info_type == SEC_INFO_TYPE_JUST_SYMS) | |
3535 | || (section->output_section == bfd_abs_section_ptr)) | |
3536 | continue; | |
3537 | ||
3538 | if (elf_section_data (section)->this_hdr.contents != NULL) | |
3539 | contents = elf_section_data (section)->this_hdr.contents; | |
3540 | else if (! bfd_malloc_and_get_section (input_bfd, section, &contents)) | |
2144188d | 3541 | return FALSE; |
68fcca92 JW |
3542 | |
3543 | sec_data = elf_aarch64_section_data (section); | |
520c7b56 JW |
3544 | |
3545 | qsort (sec_data->map, sec_data->mapcount, | |
3546 | sizeof (elf_aarch64_section_map), elf_aarch64_compare_mapping); | |
3547 | ||
68fcca92 JW |
3548 | for (span = 0; span < sec_data->mapcount; span++) |
3549 | { | |
3550 | unsigned int span_start = sec_data->map[span].vma; | |
3551 | unsigned int span_end = ((span == sec_data->mapcount - 1) | |
3552 | ? sec_data->map[0].vma + section->size | |
3553 | : sec_data->map[span + 1].vma); | |
3554 | unsigned int i; | |
3555 | char span_type = sec_data->map[span].type; | |
3556 | ||
3557 | if (span_type == 'd') | |
3558 | continue; | |
3559 | ||
3560 | for (i = span_start; i + 4 < span_end; i += 4) | |
3561 | { | |
3562 | uint32_t insn_1 = bfd_getl32 (contents + i); | |
3563 | uint32_t insn_2 = bfd_getl32 (contents + i + 4); | |
3564 | ||
3565 | if (aarch64_erratum_sequence (insn_1, insn_2)) | |
3566 | { | |
5421cc6e | 3567 | struct elf_aarch64_stub_hash_entry *stub_entry; |
35fee8b7 MS |
3568 | char *stub_name = _bfd_aarch64_erratum_835769_stub_name (num_fixes); |
3569 | if (! stub_name) | |
2144188d | 3570 | return FALSE; |
68fcca92 | 3571 | |
5421cc6e MS |
3572 | stub_entry = _bfd_aarch64_add_stub_entry_in_group (stub_name, |
3573 | section, | |
3574 | htab); | |
3575 | if (! stub_entry) | |
3576 | return FALSE; | |
68fcca92 | 3577 | |
5421cc6e MS |
3578 | stub_entry->stub_type = aarch64_stub_erratum_835769_veneer; |
3579 | stub_entry->target_section = section; | |
3580 | stub_entry->target_value = i + 4; | |
3581 | stub_entry->veneered_insn = insn_2; | |
3582 | stub_entry->output_name = stub_name; | |
68fcca92 JW |
3583 | num_fixes++; |
3584 | } | |
3585 | } | |
3586 | } | |
3587 | if (elf_section_data (section)->this_hdr.contents == NULL) | |
3588 | free (contents); | |
3589 | } | |
3590 | ||
357d1523 MS |
3591 | *num_fixes_p = num_fixes; |
3592 | ||
2144188d | 3593 | return TRUE; |
68fcca92 JW |
3594 | } |
3595 | ||
13f622ec | 3596 | |
4106101c MS |
3597 | /* Test if instruction INSN is ADRP. */ |
3598 | ||
3599 | static bfd_boolean | |
3600 | _bfd_aarch64_adrp_p (uint32_t insn) | |
3601 | { | |
3602 | return ((insn & 0x9f000000) == 0x90000000); | |
3603 | } | |
3604 | ||
3605 | ||
3606 | /* Helper predicate to look for cortex-a53 erratum 843419 sequence 1. */ | |
3607 | ||
3608 | static bfd_boolean | |
3609 | _bfd_aarch64_erratum_843419_sequence_p (uint32_t insn_1, uint32_t insn_2, | |
3610 | uint32_t insn_3) | |
3611 | { | |
3612 | uint32_t rt; | |
3613 | uint32_t rt2; | |
3614 | bfd_boolean pair; | |
3615 | bfd_boolean load; | |
3616 | ||
3617 | return (aarch64_mem_op_p (insn_2, &rt, &rt2, &pair, &load) | |
3618 | && (!pair | |
3619 | || (pair && !load)) | |
3620 | && AARCH64_LDST_UIMM (insn_3) | |
3621 | && AARCH64_RN (insn_3) == AARCH64_RD (insn_1)); | |
3622 | } | |
3623 | ||
3624 | ||
3625 | /* Test for the presence of Cortex-A53 erratum 843419 instruction sequence. | |
3626 | ||
3627 | Return TRUE if section CONTENTS at offset I contains one of the | |
3628 | erratum 843419 sequences, otherwise return FALSE. If a sequence is | |
3629 | seen set P_VENEER_I to the offset of the final LOAD/STORE | |
3630 | instruction in the sequence. | |
3631 | */ | |
3632 | ||
3633 | static bfd_boolean | |
3634 | _bfd_aarch64_erratum_843419_p (bfd_byte *contents, bfd_vma vma, | |
3635 | bfd_vma i, bfd_vma span_end, | |
3636 | bfd_vma *p_veneer_i) | |
3637 | { | |
3638 | uint32_t insn_1 = bfd_getl32 (contents + i); | |
3639 | ||
3640 | if (!_bfd_aarch64_adrp_p (insn_1)) | |
3641 | return FALSE; | |
3642 | ||
3643 | if (span_end < i + 12) | |
3644 | return FALSE; | |
3645 | ||
3646 | uint32_t insn_2 = bfd_getl32 (contents + i + 4); | |
3647 | uint32_t insn_3 = bfd_getl32 (contents + i + 8); | |
3648 | ||
3649 | if ((vma & 0xfff) != 0xff8 && (vma & 0xfff) != 0xffc) | |
3650 | return FALSE; | |
3651 | ||
3652 | if (_bfd_aarch64_erratum_843419_sequence_p (insn_1, insn_2, insn_3)) | |
3653 | { | |
3654 | *p_veneer_i = i + 8; | |
3655 | return TRUE; | |
3656 | } | |
3657 | ||
3658 | if (span_end < i + 16) | |
3659 | return FALSE; | |
3660 | ||
3661 | uint32_t insn_4 = bfd_getl32 (contents + i + 12); | |
3662 | ||
3663 | if (_bfd_aarch64_erratum_843419_sequence_p (insn_1, insn_2, insn_4)) | |
3664 | { | |
3665 | *p_veneer_i = i + 12; | |
3666 | return TRUE; | |
3667 | } | |
3668 | ||
3669 | return FALSE; | |
3670 | } | |
3671 | ||
3672 | ||
13f622ec MS |
3673 | /* Resize all stub sections. */ |
3674 | ||
3675 | static void | |
3676 | _bfd_aarch64_resize_stubs (struct elf_aarch64_link_hash_table *htab) | |
3677 | { | |
3678 | asection *section; | |
3679 | ||
3680 | /* OK, we've added some stubs. Find out the new size of the | |
3681 | stub sections. */ | |
3682 | for (section = htab->stub_bfd->sections; | |
3683 | section != NULL; section = section->next) | |
3684 | { | |
3685 | /* Ignore non-stub sections. */ | |
3686 | if (!strstr (section->name, STUB_SUFFIX)) | |
3687 | continue; | |
3688 | section->size = 0; | |
3689 | } | |
3690 | ||
3691 | bfd_hash_traverse (&htab->stub_hash_table, aarch64_size_one_stub, htab); | |
13f622ec | 3692 | |
61865519 MS |
3693 | for (section = htab->stub_bfd->sections; |
3694 | section != NULL; section = section->next) | |
3695 | { | |
3696 | if (!strstr (section->name, STUB_SUFFIX)) | |
3697 | continue; | |
3698 | ||
3699 | if (section->size) | |
3700 | section->size += 4; | |
4106101c MS |
3701 | |
3702 | /* Ensure all stub sections have a size which is a multiple of | |
3703 | 4096. This is important in order to ensure that the insertion | |
3704 | of stub sections does not in itself move existing code around | |
3705 | in such a way that new errata sequences are created. */ | |
3706 | if (htab->fix_erratum_843419) | |
3707 | if (section->size) | |
3708 | section->size = BFD_ALIGN (section->size, 0x1000); | |
3709 | } | |
3710 | } | |
3711 | ||
3712 | ||
3713 | /* Construct an erratum 843419 workaround stub name. | |
3714 | */ | |
3715 | ||
3716 | static char * | |
3717 | _bfd_aarch64_erratum_843419_stub_name (asection *input_section, | |
3718 | bfd_vma offset) | |
3719 | { | |
3720 | const bfd_size_type len = 8 + 4 + 1 + 8 + 1 + 16 + 1; | |
3721 | char *stub_name = bfd_malloc (len); | |
3722 | ||
3723 | if (stub_name != NULL) | |
3724 | snprintf (stub_name, len, "e843419@%04x_%08x_%" BFD_VMA_FMT "x", | |
3725 | input_section->owner->id, | |
3726 | input_section->id, | |
3727 | offset); | |
3728 | return stub_name; | |
3729 | } | |
3730 | ||
3731 | /* Build a stub_entry structure describing an 843419 fixup. | |
3732 | ||
3733 | The stub_entry constructed is populated with the bit pattern INSN | |
3734 | of the instruction located at OFFSET within input SECTION. | |
3735 | ||
3736 | Returns TRUE on success. */ | |
3737 | ||
3738 | static bfd_boolean | |
3739 | _bfd_aarch64_erratum_843419_fixup (uint32_t insn, | |
3740 | bfd_vma adrp_offset, | |
3741 | bfd_vma ldst_offset, | |
3742 | asection *section, | |
3743 | struct bfd_link_info *info) | |
3744 | { | |
3745 | struct elf_aarch64_link_hash_table *htab = elf_aarch64_hash_table (info); | |
3746 | char *stub_name; | |
3747 | struct elf_aarch64_stub_hash_entry *stub_entry; | |
3748 | ||
3749 | stub_name = _bfd_aarch64_erratum_843419_stub_name (section, ldst_offset); | |
3750 | stub_entry = aarch64_stub_hash_lookup (&htab->stub_hash_table, stub_name, | |
3751 | FALSE, FALSE); | |
3752 | if (stub_entry) | |
3753 | { | |
3754 | free (stub_name); | |
3755 | return TRUE; | |
3756 | } | |
3757 | ||
3758 | /* We always place an 843419 workaround veneer in the stub section | |
3759 | attached to the input section in which an erratum sequence has | |
3760 | been found. This ensures that later in the link process (in | |
3761 | elfNN_aarch64_write_section) when we copy the veneered | |
3762 | instruction from the input section into the stub section the | |
3763 | copied instruction will have had any relocations applied to it. | |
3764 | If we placed workaround veneers in any other stub section then we | |
3765 | could not assume that all relocations have been processed on the | |
3766 | corresponding input section at the point we output the stub | |
3767 | section. | |
3768 | */ | |
3769 | ||
3770 | stub_entry = _bfd_aarch64_add_stub_entry_after (stub_name, section, htab); | |
3771 | if (stub_entry == NULL) | |
3772 | { | |
3773 | free (stub_name); | |
3774 | return FALSE; | |
3775 | } | |
3776 | ||
3777 | stub_entry->adrp_offset = adrp_offset; | |
3778 | stub_entry->target_value = ldst_offset; | |
3779 | stub_entry->target_section = section; | |
3780 | stub_entry->stub_type = aarch64_stub_erratum_843419_veneer; | |
3781 | stub_entry->veneered_insn = insn; | |
3782 | stub_entry->output_name = stub_name; | |
3783 | ||
3784 | return TRUE; | |
3785 | } | |
3786 | ||
3787 | ||
3788 | /* Scan an input section looking for the signature of erratum 843419. | |
3789 | ||
3790 | Scans input SECTION in INPUT_BFD looking for erratum 843419 | |
3791 | signatures, for each signature found a stub_entry is created | |
3792 | describing the location of the erratum for subsequent fixup. | |
3793 | ||
3794 | Return TRUE on successful scan, FALSE on failure to scan. | |
3795 | */ | |
3796 | ||
3797 | static bfd_boolean | |
3798 | _bfd_aarch64_erratum_843419_scan (bfd *input_bfd, asection *section, | |
3799 | struct bfd_link_info *info) | |
3800 | { | |
3801 | struct elf_aarch64_link_hash_table *htab = elf_aarch64_hash_table (info); | |
3802 | ||
3803 | if (htab == NULL) | |
3804 | return TRUE; | |
3805 | ||
3806 | if (elf_section_type (section) != SHT_PROGBITS | |
3807 | || (elf_section_flags (section) & SHF_EXECINSTR) == 0 | |
3808 | || (section->flags & SEC_EXCLUDE) != 0 | |
3809 | || (section->sec_info_type == SEC_INFO_TYPE_JUST_SYMS) | |
3810 | || (section->output_section == bfd_abs_section_ptr)) | |
3811 | return TRUE; | |
3812 | ||
3813 | do | |
3814 | { | |
3815 | bfd_byte *contents = NULL; | |
3816 | struct _aarch64_elf_section_data *sec_data; | |
3817 | unsigned int span; | |
3818 | ||
3819 | if (elf_section_data (section)->this_hdr.contents != NULL) | |
3820 | contents = elf_section_data (section)->this_hdr.contents; | |
3821 | else if (! bfd_malloc_and_get_section (input_bfd, section, &contents)) | |
3822 | return FALSE; | |
3823 | ||
3824 | sec_data = elf_aarch64_section_data (section); | |
3825 | ||
3826 | qsort (sec_data->map, sec_data->mapcount, | |
3827 | sizeof (elf_aarch64_section_map), elf_aarch64_compare_mapping); | |
3828 | ||
3829 | for (span = 0; span < sec_data->mapcount; span++) | |
3830 | { | |
3831 | unsigned int span_start = sec_data->map[span].vma; | |
3832 | unsigned int span_end = ((span == sec_data->mapcount - 1) | |
3833 | ? sec_data->map[0].vma + section->size | |
3834 | : sec_data->map[span + 1].vma); | |
3835 | unsigned int i; | |
3836 | char span_type = sec_data->map[span].type; | |
3837 | ||
3838 | if (span_type == 'd') | |
3839 | continue; | |
3840 | ||
3841 | for (i = span_start; i + 8 < span_end; i += 4) | |
3842 | { | |
3843 | bfd_vma vma = (section->output_section->vma | |
3844 | + section->output_offset | |
3845 | + i); | |
3846 | bfd_vma veneer_i; | |
3847 | ||
3848 | if (_bfd_aarch64_erratum_843419_p | |
3849 | (contents, vma, i, span_end, &veneer_i)) | |
3850 | { | |
3851 | uint32_t insn = bfd_getl32 (contents + veneer_i); | |
3852 | ||
3853 | if (!_bfd_aarch64_erratum_843419_fixup (insn, i, veneer_i, | |
3854 | section, info)) | |
3855 | return FALSE; | |
3856 | } | |
3857 | } | |
3858 | } | |
3859 | ||
3860 | if (elf_section_data (section)->this_hdr.contents == NULL) | |
3861 | free (contents); | |
61865519 | 3862 | } |
4106101c MS |
3863 | while (0); |
3864 | ||
3865 | return TRUE; | |
61865519 | 3866 | } |
13f622ec | 3867 | |
4106101c | 3868 | |
a06ea964 NC |
3869 | /* Determine and set the size of the stub section for a final link. |
3870 | ||
3871 | The basic idea here is to examine all the relocations looking for | |
3872 | PC-relative calls to a target that is unreachable with a "bl" | |
3873 | instruction. */ | |
3874 | ||
3875 | bfd_boolean | |
cec5225b | 3876 | elfNN_aarch64_size_stubs (bfd *output_bfd, |
a06ea964 NC |
3877 | bfd *stub_bfd, |
3878 | struct bfd_link_info *info, | |
3879 | bfd_signed_vma group_size, | |
3880 | asection * (*add_stub_section) (const char *, | |
3881 | asection *), | |
3882 | void (*layout_sections_again) (void)) | |
3883 | { | |
3884 | bfd_size_type stub_group_size; | |
3885 | bfd_boolean stubs_always_before_branch; | |
5421cc6e | 3886 | bfd_boolean stub_changed = FALSE; |
cec5225b | 3887 | struct elf_aarch64_link_hash_table *htab = elf_aarch64_hash_table (info); |
68fcca92 | 3888 | unsigned int num_erratum_835769_fixes = 0; |
a06ea964 NC |
3889 | |
3890 | /* Propagate mach to stub bfd, because it may not have been | |
3891 | finalized when we created stub_bfd. */ | |
3892 | bfd_set_arch_mach (stub_bfd, bfd_get_arch (output_bfd), | |
3893 | bfd_get_mach (output_bfd)); | |
3894 | ||
3895 | /* Stash our params away. */ | |
3896 | htab->stub_bfd = stub_bfd; | |
3897 | htab->add_stub_section = add_stub_section; | |
3898 | htab->layout_sections_again = layout_sections_again; | |
3899 | stubs_always_before_branch = group_size < 0; | |
3900 | if (group_size < 0) | |
3901 | stub_group_size = -group_size; | |
3902 | else | |
3903 | stub_group_size = group_size; | |
3904 | ||
3905 | if (stub_group_size == 1) | |
3906 | { | |
3907 | /* Default values. */ | |
b9eead84 | 3908 | /* AArch64 branch range is +-128MB. The value used is 1MB less. */ |
a06ea964 NC |
3909 | stub_group_size = 127 * 1024 * 1024; |
3910 | } | |
3911 | ||
3912 | group_sections (htab, stub_group_size, stubs_always_before_branch); | |
3913 | ||
4106101c MS |
3914 | (*htab->layout_sections_again) (); |
3915 | ||
5421cc6e MS |
3916 | if (htab->fix_erratum_835769) |
3917 | { | |
3918 | bfd *input_bfd; | |
3919 | ||
3920 | for (input_bfd = info->input_bfds; | |
3921 | input_bfd != NULL; input_bfd = input_bfd->link.next) | |
3922 | if (!_bfd_aarch64_erratum_835769_scan (input_bfd, info, | |
3923 | &num_erratum_835769_fixes)) | |
3924 | return FALSE; | |
3925 | ||
4106101c MS |
3926 | _bfd_aarch64_resize_stubs (htab); |
3927 | (*htab->layout_sections_again) (); | |
3928 | } | |
3929 | ||
3930 | if (htab->fix_erratum_843419) | |
3931 | { | |
3932 | bfd *input_bfd; | |
3933 | ||
3934 | for (input_bfd = info->input_bfds; | |
3935 | input_bfd != NULL; | |
3936 | input_bfd = input_bfd->link.next) | |
3937 | { | |
3938 | asection *section; | |
3939 | ||
3940 | for (section = input_bfd->sections; | |
3941 | section != NULL; | |
3942 | section = section->next) | |
3943 | if (!_bfd_aarch64_erratum_843419_scan (input_bfd, section, info)) | |
3944 | return FALSE; | |
3945 | } | |
3946 | ||
3947 | _bfd_aarch64_resize_stubs (htab); | |
3948 | (*htab->layout_sections_again) (); | |
5421cc6e MS |
3949 | } |
3950 | ||
a06ea964 NC |
3951 | while (1) |
3952 | { | |
3953 | bfd *input_bfd; | |
a06ea964 | 3954 | |
9b9971aa MS |
3955 | for (input_bfd = info->input_bfds; |
3956 | input_bfd != NULL; input_bfd = input_bfd->link.next) | |
a06ea964 NC |
3957 | { |
3958 | Elf_Internal_Shdr *symtab_hdr; | |
3959 | asection *section; | |
3960 | Elf_Internal_Sym *local_syms = NULL; | |
3961 | ||
3962 | /* We'll need the symbol table in a second. */ | |
3963 | symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr; | |
3964 | if (symtab_hdr->sh_info == 0) | |
3965 | continue; | |
3966 | ||
3967 | /* Walk over each section attached to the input bfd. */ | |
3968 | for (section = input_bfd->sections; | |
3969 | section != NULL; section = section->next) | |
3970 | { | |
3971 | Elf_Internal_Rela *internal_relocs, *irelaend, *irela; | |
3972 | ||
3973 | /* If there aren't any relocs, then there's nothing more | |
3974 | to do. */ | |
3975 | if ((section->flags & SEC_RELOC) == 0 | |
3976 | || section->reloc_count == 0 | |
3977 | || (section->flags & SEC_CODE) == 0) | |
3978 | continue; | |
3979 | ||
3980 | /* If this section is a link-once section that will be | |
3981 | discarded, then don't create any stubs. */ | |
3982 | if (section->output_section == NULL | |
3983 | || section->output_section->owner != output_bfd) | |
3984 | continue; | |
3985 | ||
3986 | /* Get the relocs. */ | |
3987 | internal_relocs | |
3988 | = _bfd_elf_link_read_relocs (input_bfd, section, NULL, | |
3989 | NULL, info->keep_memory); | |
3990 | if (internal_relocs == NULL) | |
3991 | goto error_ret_free_local; | |
3992 | ||
3993 | /* Now examine each relocation. */ | |
3994 | irela = internal_relocs; | |
3995 | irelaend = irela + section->reloc_count; | |
3996 | for (; irela < irelaend; irela++) | |
3997 | { | |
3998 | unsigned int r_type, r_indx; | |
cec5225b YZ |
3999 | enum elf_aarch64_stub_type stub_type; |
4000 | struct elf_aarch64_stub_hash_entry *stub_entry; | |
a06ea964 NC |
4001 | asection *sym_sec; |
4002 | bfd_vma sym_value; | |
4003 | bfd_vma destination; | |
cec5225b | 4004 | struct elf_aarch64_link_hash_entry *hash; |
a06ea964 NC |
4005 | const char *sym_name; |
4006 | char *stub_name; | |
4007 | const asection *id_sec; | |
4008 | unsigned char st_type; | |
4009 | bfd_size_type len; | |
4010 | ||
cec5225b YZ |
4011 | r_type = ELFNN_R_TYPE (irela->r_info); |
4012 | r_indx = ELFNN_R_SYM (irela->r_info); | |
a06ea964 NC |
4013 | |
4014 | if (r_type >= (unsigned int) R_AARCH64_end) | |
4015 | { | |
4016 | bfd_set_error (bfd_error_bad_value); | |
4017 | error_ret_free_internal: | |
4018 | if (elf_section_data (section)->relocs == NULL) | |
4019 | free (internal_relocs); | |
4020 | goto error_ret_free_local; | |
4021 | } | |
4022 | ||
4023 | /* Only look for stubs on unconditional branch and | |
4024 | branch and link instructions. */ | |
a6bb11b2 YZ |
4025 | if (r_type != (unsigned int) AARCH64_R (CALL26) |
4026 | && r_type != (unsigned int) AARCH64_R (JUMP26)) | |
a06ea964 NC |
4027 | continue; |
4028 | ||
4029 | /* Now determine the call target, its name, value, | |
4030 | section. */ | |
4031 | sym_sec = NULL; | |
4032 | sym_value = 0; | |
4033 | destination = 0; | |
4034 | hash = NULL; | |
4035 | sym_name = NULL; | |
4036 | if (r_indx < symtab_hdr->sh_info) | |
4037 | { | |
4038 | /* It's a local symbol. */ | |
4039 | Elf_Internal_Sym *sym; | |
4040 | Elf_Internal_Shdr *hdr; | |
4041 | ||
4042 | if (local_syms == NULL) | |
4043 | { | |
4044 | local_syms | |
4045 | = (Elf_Internal_Sym *) symtab_hdr->contents; | |
4046 | if (local_syms == NULL) | |
4047 | local_syms | |
4048 | = bfd_elf_get_elf_syms (input_bfd, symtab_hdr, | |
4049 | symtab_hdr->sh_info, 0, | |
4050 | NULL, NULL, NULL); | |
4051 | if (local_syms == NULL) | |
4052 | goto error_ret_free_internal; | |
4053 | } | |
4054 | ||
4055 | sym = local_syms + r_indx; | |
4056 | hdr = elf_elfsections (input_bfd)[sym->st_shndx]; | |
4057 | sym_sec = hdr->bfd_section; | |
4058 | if (!sym_sec) | |
4059 | /* This is an undefined symbol. It can never | |
4060 | be resolved. */ | |
4061 | continue; | |
4062 | ||
4063 | if (ELF_ST_TYPE (sym->st_info) != STT_SECTION) | |
4064 | sym_value = sym->st_value; | |
4065 | destination = (sym_value + irela->r_addend | |
4066 | + sym_sec->output_offset | |
4067 | + sym_sec->output_section->vma); | |
4068 | st_type = ELF_ST_TYPE (sym->st_info); | |
4069 | sym_name | |
4070 | = bfd_elf_string_from_elf_section (input_bfd, | |
4071 | symtab_hdr->sh_link, | |
4072 | sym->st_name); | |
4073 | } | |
4074 | else | |
4075 | { | |
4076 | int e_indx; | |
4077 | ||
4078 | e_indx = r_indx - symtab_hdr->sh_info; | |
cec5225b | 4079 | hash = ((struct elf_aarch64_link_hash_entry *) |
a06ea964 NC |
4080 | elf_sym_hashes (input_bfd)[e_indx]); |
4081 | ||
4082 | while (hash->root.root.type == bfd_link_hash_indirect | |
4083 | || hash->root.root.type == bfd_link_hash_warning) | |
cec5225b | 4084 | hash = ((struct elf_aarch64_link_hash_entry *) |
a06ea964 NC |
4085 | hash->root.root.u.i.link); |
4086 | ||
4087 | if (hash->root.root.type == bfd_link_hash_defined | |
4088 | || hash->root.root.type == bfd_link_hash_defweak) | |
4089 | { | |
cec5225b YZ |
4090 | struct elf_aarch64_link_hash_table *globals = |
4091 | elf_aarch64_hash_table (info); | |
a06ea964 NC |
4092 | sym_sec = hash->root.root.u.def.section; |
4093 | sym_value = hash->root.root.u.def.value; | |
4094 | /* For a destination in a shared library, | |
4095 | use the PLT stub as target address to | |
4096 | decide whether a branch stub is | |
4097 | needed. */ | |
4098 | if (globals->root.splt != NULL && hash != NULL | |
4099 | && hash->root.plt.offset != (bfd_vma) - 1) | |
4100 | { | |
4101 | sym_sec = globals->root.splt; | |
4102 | sym_value = hash->root.plt.offset; | |
4103 | if (sym_sec->output_section != NULL) | |
4104 | destination = (sym_value | |
4105 | + sym_sec->output_offset | |
4106 | + | |
4107 | sym_sec->output_section->vma); | |
4108 | } | |
4109 | else if (sym_sec->output_section != NULL) | |
4110 | destination = (sym_value + irela->r_addend | |
4111 | + sym_sec->output_offset | |
4112 | + sym_sec->output_section->vma); | |
4113 | } | |
4114 | else if (hash->root.root.type == bfd_link_hash_undefined | |
4115 | || (hash->root.root.type | |
4116 | == bfd_link_hash_undefweak)) | |
4117 | { | |
4118 | /* For a shared library, use the PLT stub as | |
4119 | target address to decide whether a long | |
4120 | branch stub is needed. | |
4121 | For absolute code, they cannot be handled. */ | |
cec5225b YZ |
4122 | struct elf_aarch64_link_hash_table *globals = |
4123 | elf_aarch64_hash_table (info); | |
a06ea964 NC |
4124 | |
4125 | if (globals->root.splt != NULL && hash != NULL | |
4126 | && hash->root.plt.offset != (bfd_vma) - 1) | |
4127 | { | |
4128 | sym_sec = globals->root.splt; | |
4129 | sym_value = hash->root.plt.offset; | |
4130 | if (sym_sec->output_section != NULL) | |
4131 | destination = (sym_value | |
4132 | + sym_sec->output_offset | |
4133 | + | |
4134 | sym_sec->output_section->vma); | |
4135 | } | |
4136 | else | |
4137 | continue; | |
4138 | } | |
4139 | else | |
4140 | { | |
4141 | bfd_set_error (bfd_error_bad_value); | |
4142 | goto error_ret_free_internal; | |
4143 | } | |
4144 | st_type = ELF_ST_TYPE (hash->root.type); | |
4145 | sym_name = hash->root.root.root.string; | |
4146 | } | |
4147 | ||
4148 | /* Determine what (if any) linker stub is needed. */ | |
9a228467 JW |
4149 | stub_type = aarch64_type_of_stub (section, irela, sym_sec, |
4150 | st_type, destination); | |
a06ea964 NC |
4151 | if (stub_type == aarch64_stub_none) |
4152 | continue; | |
4153 | ||
4154 | /* Support for grouping stub sections. */ | |
4155 | id_sec = htab->stub_group[section->id].link_sec; | |
4156 | ||
4157 | /* Get the name of this stub. */ | |
cec5225b | 4158 | stub_name = elfNN_aarch64_stub_name (id_sec, sym_sec, hash, |
a06ea964 NC |
4159 | irela); |
4160 | if (!stub_name) | |
4161 | goto error_ret_free_internal; | |
4162 | ||
4163 | stub_entry = | |
4164 | aarch64_stub_hash_lookup (&htab->stub_hash_table, | |
4165 | stub_name, FALSE, FALSE); | |
4166 | if (stub_entry != NULL) | |
4167 | { | |
4168 | /* The proper stub has already been created. */ | |
4169 | free (stub_name); | |
4170 | continue; | |
4171 | } | |
4172 | ||
ef857521 MS |
4173 | stub_entry = _bfd_aarch64_add_stub_entry_in_group |
4174 | (stub_name, section, htab); | |
a06ea964 NC |
4175 | if (stub_entry == NULL) |
4176 | { | |
4177 | free (stub_name); | |
4178 | goto error_ret_free_internal; | |
4179 | } | |
4180 | ||
2f340668 | 4181 | stub_entry->target_value = sym_value + irela->r_addend; |
a06ea964 NC |
4182 | stub_entry->target_section = sym_sec; |
4183 | stub_entry->stub_type = stub_type; | |
4184 | stub_entry->h = hash; | |
4185 | stub_entry->st_type = st_type; | |
4186 | ||
4187 | if (sym_name == NULL) | |
4188 | sym_name = "unnamed"; | |
4189 | len = sizeof (STUB_ENTRY_NAME) + strlen (sym_name); | |
4190 | stub_entry->output_name = bfd_alloc (htab->stub_bfd, len); | |
4191 | if (stub_entry->output_name == NULL) | |
4192 | { | |
4193 | free (stub_name); | |
4194 | goto error_ret_free_internal; | |
4195 | } | |
4196 | ||
4197 | snprintf (stub_entry->output_name, len, STUB_ENTRY_NAME, | |
4198 | sym_name); | |
4199 | ||
4200 | stub_changed = TRUE; | |
4201 | } | |
4202 | ||
4203 | /* We're done with the internal relocs, free them. */ | |
4204 | if (elf_section_data (section)->relocs == NULL) | |
4205 | free (internal_relocs); | |
4206 | } | |
4207 | } | |
4208 | ||
4209 | if (!stub_changed) | |
4210 | break; | |
4211 | ||
13f622ec | 4212 | _bfd_aarch64_resize_stubs (htab); |
a06ea964 NC |
4213 | |
4214 | /* Ask the linker to do its stuff. */ | |
4215 | (*htab->layout_sections_again) (); | |
4216 | stub_changed = FALSE; | |
4217 | } | |
4218 | ||
4219 | return TRUE; | |
4220 | ||
4221 | error_ret_free_local: | |
4222 | return FALSE; | |
4223 | } | |
4224 | ||
4225 | /* Build all the stubs associated with the current output file. The | |
4226 | stubs are kept in a hash table attached to the main linker hash | |
4227 | table. We also set up the .plt entries for statically linked PIC | |
4228 | functions here. This function is called via aarch64_elf_finish in the | |
4229 | linker. */ | |
4230 | ||
4231 | bfd_boolean | |
cec5225b | 4232 | elfNN_aarch64_build_stubs (struct bfd_link_info *info) |
a06ea964 NC |
4233 | { |
4234 | asection *stub_sec; | |
4235 | struct bfd_hash_table *table; | |
cec5225b | 4236 | struct elf_aarch64_link_hash_table *htab; |
a06ea964 | 4237 | |
cec5225b | 4238 | htab = elf_aarch64_hash_table (info); |
a06ea964 NC |
4239 | |
4240 | for (stub_sec = htab->stub_bfd->sections; | |
4241 | stub_sec != NULL; stub_sec = stub_sec->next) | |
4242 | { | |
4243 | bfd_size_type size; | |
4244 | ||
4245 | /* Ignore non-stub sections. */ | |
4246 | if (!strstr (stub_sec->name, STUB_SUFFIX)) | |
4247 | continue; | |
4248 | ||
4249 | /* Allocate memory to hold the linker stubs. */ | |
4250 | size = stub_sec->size; | |
4251 | stub_sec->contents = bfd_zalloc (htab->stub_bfd, size); | |
4252 | if (stub_sec->contents == NULL && size != 0) | |
4253 | return FALSE; | |
4254 | stub_sec->size = 0; | |
61865519 MS |
4255 | |
4256 | bfd_putl32 (0x14000000 | (size >> 2), stub_sec->contents); | |
4257 | stub_sec->size += 4; | |
a06ea964 NC |
4258 | } |
4259 | ||
4260 | /* Build the stubs as directed by the stub hash table. */ | |
4261 | table = &htab->stub_hash_table; | |
4262 | bfd_hash_traverse (table, aarch64_build_one_stub, info); | |
4263 | ||
4264 | return TRUE; | |
4265 | } | |
4266 | ||
4267 | ||
4268 | /* Add an entry to the code/data map for section SEC. */ | |
4269 | ||
4270 | static void | |
cec5225b | 4271 | elfNN_aarch64_section_map_add (asection *sec, char type, bfd_vma vma) |
a06ea964 NC |
4272 | { |
4273 | struct _aarch64_elf_section_data *sec_data = | |
cec5225b | 4274 | elf_aarch64_section_data (sec); |
a06ea964 NC |
4275 | unsigned int newidx; |
4276 | ||
4277 | if (sec_data->map == NULL) | |
4278 | { | |
cec5225b | 4279 | sec_data->map = bfd_malloc (sizeof (elf_aarch64_section_map)); |
a06ea964 NC |
4280 | sec_data->mapcount = 0; |
4281 | sec_data->mapsize = 1; | |
4282 | } | |
4283 | ||
4284 | newidx = sec_data->mapcount++; | |
4285 | ||
4286 | if (sec_data->mapcount > sec_data->mapsize) | |
4287 | { | |
4288 | sec_data->mapsize *= 2; | |
4289 | sec_data->map = bfd_realloc_or_free | |
cec5225b | 4290 | (sec_data->map, sec_data->mapsize * sizeof (elf_aarch64_section_map)); |
a06ea964 NC |
4291 | } |
4292 | ||
4293 | if (sec_data->map) | |
4294 | { | |
4295 | sec_data->map[newidx].vma = vma; | |
4296 | sec_data->map[newidx].type = type; | |
4297 | } | |
4298 | } | |
4299 | ||
4300 | ||
4301 | /* Initialise maps of insn/data for input BFDs. */ | |
4302 | void | |
cec5225b | 4303 | bfd_elfNN_aarch64_init_maps (bfd *abfd) |
a06ea964 NC |
4304 | { |
4305 | Elf_Internal_Sym *isymbuf; | |
4306 | Elf_Internal_Shdr *hdr; | |
4307 | unsigned int i, localsyms; | |
4308 | ||
4309 | /* Make sure that we are dealing with an AArch64 elf binary. */ | |
4310 | if (!is_aarch64_elf (abfd)) | |
4311 | return; | |
4312 | ||
4313 | if ((abfd->flags & DYNAMIC) != 0) | |
68fcca92 | 4314 | return; |
a06ea964 NC |
4315 | |
4316 | hdr = &elf_symtab_hdr (abfd); | |
4317 | localsyms = hdr->sh_info; | |
4318 | ||
4319 | /* Obtain a buffer full of symbols for this BFD. The hdr->sh_info field | |
4320 | should contain the number of local symbols, which should come before any | |
4321 | global symbols. Mapping symbols are always local. */ | |
4322 | isymbuf = bfd_elf_get_elf_syms (abfd, hdr, localsyms, 0, NULL, NULL, NULL); | |
4323 | ||
4324 | /* No internal symbols read? Skip this BFD. */ | |
4325 | if (isymbuf == NULL) | |
4326 | return; | |
4327 | ||
4328 | for (i = 0; i < localsyms; i++) | |
4329 | { | |
4330 | Elf_Internal_Sym *isym = &isymbuf[i]; | |
4331 | asection *sec = bfd_section_from_elf_index (abfd, isym->st_shndx); | |
4332 | const char *name; | |
4333 | ||
4334 | if (sec != NULL && ELF_ST_BIND (isym->st_info) == STB_LOCAL) | |
4335 | { | |
4336 | name = bfd_elf_string_from_elf_section (abfd, | |
4337 | hdr->sh_link, | |
4338 | isym->st_name); | |
4339 | ||
4340 | if (bfd_is_aarch64_special_symbol_name | |
4341 | (name, BFD_AARCH64_SPECIAL_SYM_TYPE_MAP)) | |
cec5225b | 4342 | elfNN_aarch64_section_map_add (sec, name[1], isym->st_value); |
a06ea964 NC |
4343 | } |
4344 | } | |
4345 | } | |
4346 | ||
4347 | /* Set option values needed during linking. */ | |
4348 | void | |
cec5225b | 4349 | bfd_elfNN_aarch64_set_options (struct bfd *output_bfd, |
a06ea964 NC |
4350 | struct bfd_link_info *link_info, |
4351 | int no_enum_warn, | |
68fcca92 | 4352 | int no_wchar_warn, int pic_veneer, |
4106101c | 4353 | int fix_erratum_835769, |
1f56df9d JW |
4354 | int fix_erratum_843419, |
4355 | int no_apply_dynamic_relocs) | |
a06ea964 | 4356 | { |
cec5225b | 4357 | struct elf_aarch64_link_hash_table *globals; |
a06ea964 | 4358 | |
cec5225b | 4359 | globals = elf_aarch64_hash_table (link_info); |
a06ea964 | 4360 | globals->pic_veneer = pic_veneer; |
68fcca92 | 4361 | globals->fix_erratum_835769 = fix_erratum_835769; |
4106101c MS |
4362 | globals->fix_erratum_843419 = fix_erratum_843419; |
4363 | globals->fix_erratum_843419_adr = TRUE; | |
1f56df9d | 4364 | globals->no_apply_dynamic_relocs = no_apply_dynamic_relocs; |
a06ea964 NC |
4365 | |
4366 | BFD_ASSERT (is_aarch64_elf (output_bfd)); | |
4367 | elf_aarch64_tdata (output_bfd)->no_enum_size_warning = no_enum_warn; | |
4368 | elf_aarch64_tdata (output_bfd)->no_wchar_size_warning = no_wchar_warn; | |
4369 | } | |
4370 | ||
a06ea964 NC |
4371 | static bfd_vma |
4372 | aarch64_calculate_got_entry_vma (struct elf_link_hash_entry *h, | |
cec5225b | 4373 | struct elf_aarch64_link_hash_table |
a06ea964 NC |
4374 | *globals, struct bfd_link_info *info, |
4375 | bfd_vma value, bfd *output_bfd, | |
4376 | bfd_boolean *unresolved_reloc_p) | |
4377 | { | |
4378 | bfd_vma off = (bfd_vma) - 1; | |
4379 | asection *basegot = globals->root.sgot; | |
4380 | bfd_boolean dyn = globals->root.dynamic_sections_created; | |
4381 | ||
4382 | if (h != NULL) | |
4383 | { | |
a6bb11b2 | 4384 | BFD_ASSERT (basegot != NULL); |
a06ea964 NC |
4385 | off = h->got.offset; |
4386 | BFD_ASSERT (off != (bfd_vma) - 1); | |
0e1862bb L |
4387 | if (!WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, bfd_link_pic (info), h) |
4388 | || (bfd_link_pic (info) | |
a06ea964 NC |
4389 | && SYMBOL_REFERENCES_LOCAL (info, h)) |
4390 | || (ELF_ST_VISIBILITY (h->other) | |
4391 | && h->root.type == bfd_link_hash_undefweak)) | |
4392 | { | |
4393 | /* This is actually a static link, or it is a -Bsymbolic link | |
4394 | and the symbol is defined locally. We must initialize this | |
4395 | entry in the global offset table. Since the offset must | |
a6bb11b2 YZ |
4396 | always be a multiple of 8 (4 in the case of ILP32), we use |
4397 | the least significant bit to record whether we have | |
4398 | initialized it already. | |
a06ea964 NC |
4399 | When doing a dynamic link, we create a .rel(a).got relocation |
4400 | entry to initialize the value. This is done in the | |
4401 | finish_dynamic_symbol routine. */ | |
4402 | if ((off & 1) != 0) | |
4403 | off &= ~1; | |
4404 | else | |
4405 | { | |
cec5225b | 4406 | bfd_put_NN (output_bfd, value, basegot->contents + off); |
a06ea964 NC |
4407 | h->got.offset |= 1; |
4408 | } | |
4409 | } | |
4410 | else | |
4411 | *unresolved_reloc_p = FALSE; | |
4412 | ||
4413 | off = off + basegot->output_section->vma + basegot->output_offset; | |
4414 | } | |
4415 | ||
4416 | return off; | |
4417 | } | |
4418 | ||
4419 | /* Change R_TYPE to a more efficient access model where possible, | |
4420 | return the new reloc type. */ | |
4421 | ||
a6bb11b2 YZ |
4422 | static bfd_reloc_code_real_type |
4423 | aarch64_tls_transition_without_check (bfd_reloc_code_real_type r_type, | |
a06ea964 NC |
4424 | struct elf_link_hash_entry *h) |
4425 | { | |
4426 | bfd_boolean is_local = h == NULL; | |
a6bb11b2 | 4427 | |
a06ea964 NC |
4428 | switch (r_type) |
4429 | { | |
a6bb11b2 | 4430 | case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21: |
ce336788 | 4431 | case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21: |
a6bb11b2 YZ |
4432 | return (is_local |
4433 | ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1 | |
4434 | : BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21); | |
4435 | ||
389b8029 MS |
4436 | case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21: |
4437 | return (is_local | |
4438 | ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC | |
4439 | : r_type); | |
4440 | ||
1ada945d MS |
4441 | case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19: |
4442 | return (is_local | |
4443 | ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1 | |
4444 | : BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19); | |
4445 | ||
0484b454 RL |
4446 | case BFD_RELOC_AARCH64_TLSDESC_LDR: |
4447 | return (is_local | |
4448 | ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC | |
4449 | : BFD_RELOC_AARCH64_NONE); | |
4450 | ||
4451 | case BFD_RELOC_AARCH64_TLSDESC_OFF_G0_NC: | |
4452 | return (is_local | |
4453 | ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1_NC | |
4454 | : BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G0_NC); | |
4455 | ||
4456 | case BFD_RELOC_AARCH64_TLSDESC_OFF_G1: | |
4457 | return (is_local | |
4458 | ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G2 | |
4459 | : BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G1); | |
4460 | ||
a6bb11b2 | 4461 | case BFD_RELOC_AARCH64_TLSDESC_LDNN_LO12_NC: |
ce336788 | 4462 | case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC: |
a6bb11b2 YZ |
4463 | return (is_local |
4464 | ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC | |
4465 | : BFD_RELOC_AARCH64_TLSIE_LDNN_GOTTPREL_LO12_NC); | |
4466 | ||
4467 | case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21: | |
4468 | return is_local ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1 : r_type; | |
4469 | ||
4470 | case BFD_RELOC_AARCH64_TLSIE_LDNN_GOTTPREL_LO12_NC: | |
4471 | return is_local ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC : r_type; | |
4472 | ||
043bf05a MS |
4473 | case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19: |
4474 | return r_type; | |
4475 | ||
3c12b054 MS |
4476 | case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21: |
4477 | return (is_local | |
4478 | ? BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_HI12 | |
4479 | : BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19); | |
4480 | ||
0484b454 | 4481 | case BFD_RELOC_AARCH64_TLSDESC_ADD: |
f955cccf | 4482 | case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12: |
a6bb11b2 | 4483 | case BFD_RELOC_AARCH64_TLSDESC_CALL: |
a06ea964 | 4484 | /* Instructions with these relocations will become NOPs. */ |
a6bb11b2 YZ |
4485 | return BFD_RELOC_AARCH64_NONE; |
4486 | ||
259364ad JW |
4487 | case BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC: |
4488 | case BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21: | |
4489 | case BFD_RELOC_AARCH64_TLSLD_ADR_PREL21: | |
4490 | return is_local ? BFD_RELOC_AARCH64_NONE : r_type; | |
4491 | ||
ac734732 RL |
4492 | #if ARCH_SIZE == 64 |
4493 | case BFD_RELOC_AARCH64_TLSGD_MOVW_G0_NC: | |
4494 | return is_local | |
4495 | ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1_NC | |
4496 | : BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G0_NC; | |
4497 | ||
4498 | case BFD_RELOC_AARCH64_TLSGD_MOVW_G1: | |
4499 | return is_local | |
4500 | ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G2 | |
4501 | : BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G1; | |
4502 | #endif | |
4503 | ||
a6bb11b2 YZ |
4504 | default: |
4505 | break; | |
a06ea964 NC |
4506 | } |
4507 | ||
4508 | return r_type; | |
4509 | } | |
4510 | ||
4511 | static unsigned int | |
a6bb11b2 | 4512 | aarch64_reloc_got_type (bfd_reloc_code_real_type r_type) |
a06ea964 NC |
4513 | { |
4514 | switch (r_type) | |
4515 | { | |
a6bb11b2 YZ |
4516 | case BFD_RELOC_AARCH64_ADR_GOT_PAGE: |
4517 | case BFD_RELOC_AARCH64_GOT_LD_PREL19: | |
7018c030 | 4518 | case BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14: |
ce336788 | 4519 | case BFD_RELOC_AARCH64_LD32_GOT_LO12_NC: |
a2e1db00 | 4520 | case BFD_RELOC_AARCH64_LD64_GOTOFF_LO15: |
99ad26cb | 4521 | case BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15: |
ce336788 | 4522 | case BFD_RELOC_AARCH64_LD64_GOT_LO12_NC: |
dc8008f5 | 4523 | case BFD_RELOC_AARCH64_MOVW_GOTOFF_G0_NC: |
74a1bfe1 | 4524 | case BFD_RELOC_AARCH64_MOVW_GOTOFF_G1: |
a06ea964 NC |
4525 | return GOT_NORMAL; |
4526 | ||
ce336788 | 4527 | case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC: |
a6bb11b2 | 4528 | case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21: |
3c12b054 | 4529 | case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21: |
7ba7cfe4 | 4530 | case BFD_RELOC_AARCH64_TLSGD_MOVW_G0_NC: |
94facae3 | 4531 | case BFD_RELOC_AARCH64_TLSGD_MOVW_G1: |
73f925cc | 4532 | case BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC: |
f69e4920 | 4533 | case BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21: |
77a69ff8 | 4534 | case BFD_RELOC_AARCH64_TLSLD_ADR_PREL21: |
a06ea964 NC |
4535 | return GOT_TLS_GD; |
4536 | ||
0484b454 | 4537 | case BFD_RELOC_AARCH64_TLSDESC_ADD: |
f955cccf | 4538 | case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12: |
a6bb11b2 | 4539 | case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21: |
389b8029 | 4540 | case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21: |
a6bb11b2 | 4541 | case BFD_RELOC_AARCH64_TLSDESC_CALL: |
a6bb11b2 | 4542 | case BFD_RELOC_AARCH64_TLSDESC_LD32_LO12_NC: |
f955cccf | 4543 | case BFD_RELOC_AARCH64_TLSDESC_LD64_LO12: |
1ada945d | 4544 | case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19: |
0484b454 RL |
4545 | case BFD_RELOC_AARCH64_TLSDESC_LDR: |
4546 | case BFD_RELOC_AARCH64_TLSDESC_OFF_G0_NC: | |
4547 | case BFD_RELOC_AARCH64_TLSDESC_OFF_G1: | |
a06ea964 NC |
4548 | return GOT_TLSDESC_GD; |
4549 | ||
a6bb11b2 | 4550 | case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21: |
a6bb11b2 | 4551 | case BFD_RELOC_AARCH64_TLSIE_LD32_GOTTPREL_LO12_NC: |
ce336788 | 4552 | case BFD_RELOC_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC: |
043bf05a | 4553 | case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19: |
3b957e5b RL |
4554 | case BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G0_NC: |
4555 | case BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G1: | |
a06ea964 NC |
4556 | return GOT_TLS_IE; |
4557 | ||
a6bb11b2 YZ |
4558 | default: |
4559 | break; | |
a06ea964 NC |
4560 | } |
4561 | return GOT_UNKNOWN; | |
4562 | } | |
4563 | ||
4564 | static bfd_boolean | |
4565 | aarch64_can_relax_tls (bfd *input_bfd, | |
4566 | struct bfd_link_info *info, | |
a6bb11b2 | 4567 | bfd_reloc_code_real_type r_type, |
a06ea964 NC |
4568 | struct elf_link_hash_entry *h, |
4569 | unsigned long r_symndx) | |
4570 | { | |
4571 | unsigned int symbol_got_type; | |
4572 | unsigned int reloc_got_type; | |
4573 | ||
9331eea1 | 4574 | if (! IS_AARCH64_TLS_RELAX_RELOC (r_type)) |
a06ea964 NC |
4575 | return FALSE; |
4576 | ||
cec5225b | 4577 | symbol_got_type = elfNN_aarch64_symbol_got_type (h, input_bfd, r_symndx); |
a06ea964 NC |
4578 | reloc_got_type = aarch64_reloc_got_type (r_type); |
4579 | ||
4580 | if (symbol_got_type == GOT_TLS_IE && GOT_TLS_GD_ANY_P (reloc_got_type)) | |
4581 | return TRUE; | |
4582 | ||
0e1862bb | 4583 | if (bfd_link_pic (info)) |
a06ea964 NC |
4584 | return FALSE; |
4585 | ||
4586 | if (h && h->root.type == bfd_link_hash_undefweak) | |
4587 | return FALSE; | |
4588 | ||
4589 | return TRUE; | |
4590 | } | |
4591 | ||
a6bb11b2 YZ |
4592 | /* Given the relocation code R_TYPE, return the relaxed bfd reloc |
4593 | enumerator. */ | |
4594 | ||
4595 | static bfd_reloc_code_real_type | |
a06ea964 NC |
4596 | aarch64_tls_transition (bfd *input_bfd, |
4597 | struct bfd_link_info *info, | |
4598 | unsigned int r_type, | |
4599 | struct elf_link_hash_entry *h, | |
4600 | unsigned long r_symndx) | |
4601 | { | |
a6bb11b2 YZ |
4602 | bfd_reloc_code_real_type bfd_r_type |
4603 | = elfNN_aarch64_bfd_reloc_from_type (r_type); | |
a06ea964 | 4604 | |
a6bb11b2 YZ |
4605 | if (! aarch64_can_relax_tls (input_bfd, info, bfd_r_type, h, r_symndx)) |
4606 | return bfd_r_type; | |
4607 | ||
4608 | return aarch64_tls_transition_without_check (bfd_r_type, h); | |
a06ea964 NC |
4609 | } |
4610 | ||
4611 | /* Return the base VMA address which should be subtracted from real addresses | |
a6bb11b2 | 4612 | when resolving R_AARCH64_TLS_DTPREL relocation. */ |
a06ea964 NC |
4613 | |
4614 | static bfd_vma | |
4615 | dtpoff_base (struct bfd_link_info *info) | |
4616 | { | |
4617 | /* If tls_sec is NULL, we should have signalled an error already. */ | |
4618 | BFD_ASSERT (elf_hash_table (info)->tls_sec != NULL); | |
4619 | return elf_hash_table (info)->tls_sec->vma; | |
4620 | } | |
4621 | ||
a06ea964 NC |
4622 | /* Return the base VMA address which should be subtracted from real addresses |
4623 | when resolving R_AARCH64_TLS_GOTTPREL64 relocations. */ | |
4624 | ||
4625 | static bfd_vma | |
4626 | tpoff_base (struct bfd_link_info *info) | |
4627 | { | |
4628 | struct elf_link_hash_table *htab = elf_hash_table (info); | |
4629 | ||
4630 | /* If tls_sec is NULL, we should have signalled an error already. */ | |
ac21917f | 4631 | BFD_ASSERT (htab->tls_sec != NULL); |
a06ea964 NC |
4632 | |
4633 | bfd_vma base = align_power ((bfd_vma) TCB_SIZE, | |
4634 | htab->tls_sec->alignment_power); | |
4635 | return htab->tls_sec->vma - base; | |
4636 | } | |
4637 | ||
4638 | static bfd_vma * | |
4639 | symbol_got_offset_ref (bfd *input_bfd, struct elf_link_hash_entry *h, | |
4640 | unsigned long r_symndx) | |
4641 | { | |
4642 | /* Calculate the address of the GOT entry for symbol | |
4643 | referred to in h. */ | |
4644 | if (h != NULL) | |
4645 | return &h->got.offset; | |
4646 | else | |
4647 | { | |
4648 | /* local symbol */ | |
4649 | struct elf_aarch64_local_symbol *l; | |
4650 | ||
cec5225b | 4651 | l = elf_aarch64_locals (input_bfd); |
a06ea964 NC |
4652 | return &l[r_symndx].got_offset; |
4653 | } | |
4654 | } | |
4655 | ||
4656 | static void | |
4657 | symbol_got_offset_mark (bfd *input_bfd, struct elf_link_hash_entry *h, | |
4658 | unsigned long r_symndx) | |
4659 | { | |
4660 | bfd_vma *p; | |
4661 | p = symbol_got_offset_ref (input_bfd, h, r_symndx); | |
4662 | *p |= 1; | |
4663 | } | |
4664 | ||
4665 | static int | |
4666 | symbol_got_offset_mark_p (bfd *input_bfd, struct elf_link_hash_entry *h, | |
4667 | unsigned long r_symndx) | |
4668 | { | |
4669 | bfd_vma value; | |
4670 | value = * symbol_got_offset_ref (input_bfd, h, r_symndx); | |
4671 | return value & 1; | |
4672 | } | |
4673 | ||
4674 | static bfd_vma | |
4675 | symbol_got_offset (bfd *input_bfd, struct elf_link_hash_entry *h, | |
4676 | unsigned long r_symndx) | |
4677 | { | |
4678 | bfd_vma value; | |
4679 | value = * symbol_got_offset_ref (input_bfd, h, r_symndx); | |
4680 | value &= ~1; | |
4681 | return value; | |
4682 | } | |
4683 | ||
4684 | static bfd_vma * | |
4685 | symbol_tlsdesc_got_offset_ref (bfd *input_bfd, struct elf_link_hash_entry *h, | |
4686 | unsigned long r_symndx) | |
4687 | { | |
4688 | /* Calculate the address of the GOT entry for symbol | |
4689 | referred to in h. */ | |
4690 | if (h != NULL) | |
4691 | { | |
cec5225b YZ |
4692 | struct elf_aarch64_link_hash_entry *eh; |
4693 | eh = (struct elf_aarch64_link_hash_entry *) h; | |
a06ea964 NC |
4694 | return &eh->tlsdesc_got_jump_table_offset; |
4695 | } | |
4696 | else | |
4697 | { | |
4698 | /* local symbol */ | |
4699 | struct elf_aarch64_local_symbol *l; | |
4700 | ||
cec5225b | 4701 | l = elf_aarch64_locals (input_bfd); |
a06ea964 NC |
4702 | return &l[r_symndx].tlsdesc_got_jump_table_offset; |
4703 | } | |
4704 | } | |
4705 | ||
4706 | static void | |
4707 | symbol_tlsdesc_got_offset_mark (bfd *input_bfd, struct elf_link_hash_entry *h, | |
4708 | unsigned long r_symndx) | |
4709 | { | |
4710 | bfd_vma *p; | |
4711 | p = symbol_tlsdesc_got_offset_ref (input_bfd, h, r_symndx); | |
4712 | *p |= 1; | |
4713 | } | |
4714 | ||
4715 | static int | |
4716 | symbol_tlsdesc_got_offset_mark_p (bfd *input_bfd, | |
4717 | struct elf_link_hash_entry *h, | |
4718 | unsigned long r_symndx) | |
4719 | { | |
4720 | bfd_vma value; | |
4721 | value = * symbol_tlsdesc_got_offset_ref (input_bfd, h, r_symndx); | |
4722 | return value & 1; | |
4723 | } | |
4724 | ||
4725 | static bfd_vma | |
4726 | symbol_tlsdesc_got_offset (bfd *input_bfd, struct elf_link_hash_entry *h, | |
4727 | unsigned long r_symndx) | |
4728 | { | |
4729 | bfd_vma value; | |
4730 | value = * symbol_tlsdesc_got_offset_ref (input_bfd, h, r_symndx); | |
4731 | value &= ~1; | |
4732 | return value; | |
4733 | } | |
4734 | ||
68fcca92 JW |
4735 | /* Data for make_branch_to_erratum_835769_stub(). */ |
4736 | ||
4737 | struct erratum_835769_branch_to_stub_data | |
4738 | { | |
4106101c | 4739 | struct bfd_link_info *info; |
68fcca92 JW |
4740 | asection *output_section; |
4741 | bfd_byte *contents; | |
4742 | }; | |
4743 | ||
4744 | /* Helper to insert branches to erratum 835769 stubs in the right | |
4745 | places for a particular section. */ | |
4746 | ||
4747 | static bfd_boolean | |
4748 | make_branch_to_erratum_835769_stub (struct bfd_hash_entry *gen_entry, | |
4749 | void *in_arg) | |
4750 | { | |
4751 | struct elf_aarch64_stub_hash_entry *stub_entry; | |
4752 | struct erratum_835769_branch_to_stub_data *data; | |
4753 | bfd_byte *contents; | |
4754 | unsigned long branch_insn = 0; | |
4755 | bfd_vma veneered_insn_loc, veneer_entry_loc; | |
4756 | bfd_signed_vma branch_offset; | |
4757 | unsigned int target; | |
4758 | bfd *abfd; | |
4759 | ||
4760 | stub_entry = (struct elf_aarch64_stub_hash_entry *) gen_entry; | |
4761 | data = (struct erratum_835769_branch_to_stub_data *) in_arg; | |
4762 | ||
4763 | if (stub_entry->target_section != data->output_section | |
4764 | || stub_entry->stub_type != aarch64_stub_erratum_835769_veneer) | |
4765 | return TRUE; | |
4766 | ||
4767 | contents = data->contents; | |
4768 | veneered_insn_loc = stub_entry->target_section->output_section->vma | |
4769 | + stub_entry->target_section->output_offset | |
4770 | + stub_entry->target_value; | |
4771 | veneer_entry_loc = stub_entry->stub_sec->output_section->vma | |
4772 | + stub_entry->stub_sec->output_offset | |
4773 | + stub_entry->stub_offset; | |
4774 | branch_offset = veneer_entry_loc - veneered_insn_loc; | |
4775 | ||
4776 | abfd = stub_entry->target_section->owner; | |
4777 | if (!aarch64_valid_branch_p (veneer_entry_loc, veneered_insn_loc)) | |
4eca0228 AM |
4778 | _bfd_error_handler |
4779 | (_("%B: error: Erratum 835769 stub out " | |
4780 | "of range (input file too large)"), abfd); | |
68fcca92 JW |
4781 | |
4782 | target = stub_entry->target_value; | |
4783 | branch_insn = 0x14000000; | |
4784 | branch_offset >>= 2; | |
4785 | branch_offset &= 0x3ffffff; | |
4786 | branch_insn |= branch_offset; | |
4787 | bfd_putl32 (branch_insn, &contents[target]); | |
4788 | ||
4789 | return TRUE; | |
4790 | } | |
4791 | ||
4106101c MS |
4792 | |
4793 | static bfd_boolean | |
4794 | _bfd_aarch64_erratum_843419_branch_to_stub (struct bfd_hash_entry *gen_entry, | |
4795 | void *in_arg) | |
4796 | { | |
4797 | struct elf_aarch64_stub_hash_entry *stub_entry | |
4798 | = (struct elf_aarch64_stub_hash_entry *) gen_entry; | |
4799 | struct erratum_835769_branch_to_stub_data *data | |
4800 | = (struct erratum_835769_branch_to_stub_data *) in_arg; | |
4801 | struct bfd_link_info *info; | |
4802 | struct elf_aarch64_link_hash_table *htab; | |
4803 | bfd_byte *contents; | |
4804 | asection *section; | |
4805 | bfd *abfd; | |
4806 | bfd_vma place; | |
4807 | uint32_t insn; | |
4808 | ||
4809 | info = data->info; | |
4810 | contents = data->contents; | |
4811 | section = data->output_section; | |
4812 | ||
4813 | htab = elf_aarch64_hash_table (info); | |
4814 | ||
4815 | if (stub_entry->target_section != section | |
4816 | || stub_entry->stub_type != aarch64_stub_erratum_843419_veneer) | |
4817 | return TRUE; | |
4818 | ||
4819 | insn = bfd_getl32 (contents + stub_entry->target_value); | |
4820 | bfd_putl32 (insn, | |
4821 | stub_entry->stub_sec->contents + stub_entry->stub_offset); | |
4822 | ||
4823 | place = (section->output_section->vma + section->output_offset | |
4824 | + stub_entry->adrp_offset); | |
4825 | insn = bfd_getl32 (contents + stub_entry->adrp_offset); | |
4826 | ||
4827 | if ((insn & AARCH64_ADRP_OP_MASK) != AARCH64_ADRP_OP) | |
4828 | abort (); | |
4829 | ||
4830 | bfd_signed_vma imm = | |
4831 | (_bfd_aarch64_sign_extend | |
4832 | ((bfd_vma) _bfd_aarch64_decode_adrp_imm (insn) << 12, 33) | |
4833 | - (place & 0xfff)); | |
4834 | ||
4835 | if (htab->fix_erratum_843419_adr | |
4836 | && (imm >= AARCH64_MIN_ADRP_IMM && imm <= AARCH64_MAX_ADRP_IMM)) | |
4837 | { | |
4838 | insn = (_bfd_aarch64_reencode_adr_imm (AARCH64_ADR_OP, imm) | |
4839 | | AARCH64_RT (insn)); | |
4840 | bfd_putl32 (insn, contents + stub_entry->adrp_offset); | |
4841 | } | |
4842 | else | |
4843 | { | |
4844 | bfd_vma veneered_insn_loc; | |
4845 | bfd_vma veneer_entry_loc; | |
4846 | bfd_signed_vma branch_offset; | |
4847 | uint32_t branch_insn; | |
4848 | ||
4849 | veneered_insn_loc = stub_entry->target_section->output_section->vma | |
4850 | + stub_entry->target_section->output_offset | |
4851 | + stub_entry->target_value; | |
4852 | veneer_entry_loc = stub_entry->stub_sec->output_section->vma | |
4853 | + stub_entry->stub_sec->output_offset | |
4854 | + stub_entry->stub_offset; | |
4855 | branch_offset = veneer_entry_loc - veneered_insn_loc; | |
4856 | ||
4857 | abfd = stub_entry->target_section->owner; | |
4858 | if (!aarch64_valid_branch_p (veneer_entry_loc, veneered_insn_loc)) | |
4eca0228 | 4859 | _bfd_error_handler |
4106101c MS |
4860 | (_("%B: error: Erratum 843419 stub out " |
4861 | "of range (input file too large)"), abfd); | |
4862 | ||
4863 | branch_insn = 0x14000000; | |
4864 | branch_offset >>= 2; | |
4865 | branch_offset &= 0x3ffffff; | |
4866 | branch_insn |= branch_offset; | |
4867 | bfd_putl32 (branch_insn, contents + stub_entry->target_value); | |
4868 | } | |
4869 | return TRUE; | |
4870 | } | |
4871 | ||
4872 | ||
68fcca92 JW |
4873 | static bfd_boolean |
4874 | elfNN_aarch64_write_section (bfd *output_bfd ATTRIBUTE_UNUSED, | |
4875 | struct bfd_link_info *link_info, | |
4876 | asection *sec, | |
4877 | bfd_byte *contents) | |
4878 | ||
4879 | { | |
4880 | struct elf_aarch64_link_hash_table *globals = | |
f872121a | 4881 | elf_aarch64_hash_table (link_info); |
68fcca92 JW |
4882 | |
4883 | if (globals == NULL) | |
4884 | return FALSE; | |
4885 | ||
4886 | /* Fix code to point to erratum 835769 stubs. */ | |
4887 | if (globals->fix_erratum_835769) | |
4888 | { | |
4889 | struct erratum_835769_branch_to_stub_data data; | |
4890 | ||
4106101c | 4891 | data.info = link_info; |
68fcca92 JW |
4892 | data.output_section = sec; |
4893 | data.contents = contents; | |
4894 | bfd_hash_traverse (&globals->stub_hash_table, | |
4895 | make_branch_to_erratum_835769_stub, &data); | |
4896 | } | |
4897 | ||
4106101c MS |
4898 | if (globals->fix_erratum_843419) |
4899 | { | |
4900 | struct erratum_835769_branch_to_stub_data data; | |
4901 | ||
4902 | data.info = link_info; | |
4903 | data.output_section = sec; | |
4904 | data.contents = contents; | |
4905 | bfd_hash_traverse (&globals->stub_hash_table, | |
4906 | _bfd_aarch64_erratum_843419_branch_to_stub, &data); | |
4907 | } | |
4908 | ||
68fcca92 JW |
4909 | return FALSE; |
4910 | } | |
4911 | ||
2aff25ba JW |
4912 | /* Return TRUE if RELOC is a relocation against the base of GOT table. */ |
4913 | ||
4914 | static bfd_boolean | |
4915 | aarch64_relocation_aginst_gp_p (bfd_reloc_code_real_type reloc) | |
4916 | { | |
4917 | return (reloc == BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14 | |
4918 | || reloc == BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15 | |
4919 | || reloc == BFD_RELOC_AARCH64_LD64_GOTOFF_LO15 | |
4920 | || reloc == BFD_RELOC_AARCH64_MOVW_GOTOFF_G0_NC | |
4921 | || reloc == BFD_RELOC_AARCH64_MOVW_GOTOFF_G1); | |
4922 | } | |
4923 | ||
4e7fbb34 JW |
4924 | /* Perform a relocation as part of a final link. The input relocation type |
4925 | should be TLS relaxed. */ | |
4926 | ||
a06ea964 | 4927 | static bfd_reloc_status_type |
cec5225b | 4928 | elfNN_aarch64_final_link_relocate (reloc_howto_type *howto, |
a06ea964 NC |
4929 | bfd *input_bfd, |
4930 | bfd *output_bfd, | |
4931 | asection *input_section, | |
4932 | bfd_byte *contents, | |
4933 | Elf_Internal_Rela *rel, | |
4934 | bfd_vma value, | |
4935 | struct bfd_link_info *info, | |
4936 | asection *sym_sec, | |
4937 | struct elf_link_hash_entry *h, | |
4938 | bfd_boolean *unresolved_reloc_p, | |
4939 | bfd_boolean save_addend, | |
1419bbe5 WN |
4940 | bfd_vma *saved_addend, |
4941 | Elf_Internal_Sym *sym) | |
a06ea964 | 4942 | { |
1419bbe5 | 4943 | Elf_Internal_Shdr *symtab_hdr; |
a06ea964 | 4944 | unsigned int r_type = howto->type; |
a6bb11b2 YZ |
4945 | bfd_reloc_code_real_type bfd_r_type |
4946 | = elfNN_aarch64_bfd_reloc_from_howto (howto); | |
a06ea964 NC |
4947 | unsigned long r_symndx; |
4948 | bfd_byte *hit_data = contents + rel->r_offset; | |
96d01d93 | 4949 | bfd_vma place, off, got_entry_addr = 0; |
a06ea964 | 4950 | bfd_signed_vma signed_addend; |
cec5225b | 4951 | struct elf_aarch64_link_hash_table *globals; |
a06ea964 | 4952 | bfd_boolean weak_undef_p; |
ff07562f | 4953 | bfd_boolean relative_reloc; |
b53b1bed | 4954 | asection *base_got; |
ff07562f | 4955 | bfd_vma orig_value = value; |
a06ea964 | 4956 | |
cec5225b | 4957 | globals = elf_aarch64_hash_table (info); |
a06ea964 | 4958 | |
1419bbe5 WN |
4959 | symtab_hdr = &elf_symtab_hdr (input_bfd); |
4960 | ||
a06ea964 NC |
4961 | BFD_ASSERT (is_aarch64_elf (input_bfd)); |
4962 | ||
cec5225b | 4963 | r_symndx = ELFNN_R_SYM (rel->r_info); |
a06ea964 | 4964 | |
a06ea964 NC |
4965 | place = input_section->output_section->vma |
4966 | + input_section->output_offset + rel->r_offset; | |
4967 | ||
4968 | /* Get addend, accumulating the addend for consecutive relocs | |
4969 | which refer to the same offset. */ | |
4970 | signed_addend = saved_addend ? *saved_addend : 0; | |
4971 | signed_addend += rel->r_addend; | |
4972 | ||
4973 | weak_undef_p = (h ? h->root.type == bfd_link_hash_undefweak | |
4974 | : bfd_is_und_section (sym_sec)); | |
a6bb11b2 | 4975 | |
1419bbe5 WN |
4976 | /* Since STT_GNU_IFUNC symbol must go through PLT, we handle |
4977 | it here if it is defined in a non-shared object. */ | |
4978 | if (h != NULL | |
4979 | && h->type == STT_GNU_IFUNC | |
4980 | && h->def_regular) | |
4981 | { | |
4982 | asection *plt; | |
4983 | const char *name; | |
99ad26cb | 4984 | bfd_vma addend = 0; |
1419bbe5 | 4985 | |
545bc2b3 SN |
4986 | if ((input_section->flags & SEC_ALLOC) == 0) |
4987 | { | |
4988 | /* Dynamic relocs are not propagated for SEC_DEBUGGING | |
4989 | sections because such sections are not SEC_ALLOC and | |
4990 | thus ld.so will not process them. */ | |
4991 | if ((input_section->flags & SEC_DEBUGGING) != 0) | |
4992 | return bfd_reloc_ok; | |
4993 | ||
4994 | if (h->root.root.string) | |
4995 | name = h->root.root.string; | |
4996 | else | |
4997 | name = bfd_elf_sym_name (input_bfd, symtab_hdr, sym, NULL); | |
4998 | _bfd_error_handler | |
4999 | /* xgettext:c-format */ | |
5000 | (_("%B(%A+%#Lx): unresolvable %s relocation against symbol `%s'"), | |
5001 | input_bfd, input_section, rel->r_offset, howto->name, name); | |
5002 | bfd_set_error (bfd_error_bad_value); | |
1d75a8e2 | 5003 | return bfd_reloc_notsupported; |
545bc2b3 SN |
5004 | } |
5005 | else if (h->plt.offset == (bfd_vma) -1) | |
5006 | goto bad_ifunc_reloc; | |
1419bbe5 WN |
5007 | |
5008 | /* STT_GNU_IFUNC symbol must go through PLT. */ | |
5009 | plt = globals->root.splt ? globals->root.splt : globals->root.iplt; | |
5010 | value = (plt->output_section->vma + plt->output_offset + h->plt.offset); | |
5011 | ||
5012 | switch (bfd_r_type) | |
5013 | { | |
5014 | default: | |
545bc2b3 | 5015 | bad_ifunc_reloc: |
1419bbe5 WN |
5016 | if (h->root.root.string) |
5017 | name = h->root.root.string; | |
5018 | else | |
5019 | name = bfd_elf_sym_name (input_bfd, symtab_hdr, sym, | |
5020 | NULL); | |
4eca0228 | 5021 | _bfd_error_handler |
695344c0 | 5022 | /* xgettext:c-format */ |
1419bbe5 WN |
5023 | (_("%B: relocation %s against STT_GNU_IFUNC " |
5024 | "symbol `%s' isn't handled by %s"), input_bfd, | |
5025 | howto->name, name, __FUNCTION__); | |
5026 | bfd_set_error (bfd_error_bad_value); | |
1d75a8e2 | 5027 | return bfd_reloc_notsupported; |
1419bbe5 WN |
5028 | |
5029 | case BFD_RELOC_AARCH64_NN: | |
5030 | if (rel->r_addend != 0) | |
5031 | { | |
5032 | if (h->root.root.string) | |
5033 | name = h->root.root.string; | |
5034 | else | |
5035 | name = bfd_elf_sym_name (input_bfd, symtab_hdr, | |
5036 | sym, NULL); | |
4eca0228 | 5037 | _bfd_error_handler |
695344c0 | 5038 | /* xgettext:c-format */ |
1419bbe5 | 5039 | (_("%B: relocation %s against STT_GNU_IFUNC " |
d42c267e | 5040 | "symbol `%s' has non-zero addend: %Ld"), |
1419bbe5 WN |
5041 | input_bfd, howto->name, name, rel->r_addend); |
5042 | bfd_set_error (bfd_error_bad_value); | |
1d75a8e2 | 5043 | return bfd_reloc_notsupported; |
1419bbe5 WN |
5044 | } |
5045 | ||
5046 | /* Generate dynamic relocation only when there is a | |
5047 | non-GOT reference in a shared object. */ | |
0e1862bb | 5048 | if (bfd_link_pic (info) && h->non_got_ref) |
1419bbe5 WN |
5049 | { |
5050 | Elf_Internal_Rela outrel; | |
5051 | asection *sreloc; | |
5052 | ||
5053 | /* Need a dynamic relocation to get the real function | |
5054 | address. */ | |
5055 | outrel.r_offset = _bfd_elf_section_offset (output_bfd, | |
5056 | info, | |
5057 | input_section, | |
5058 | rel->r_offset); | |
5059 | if (outrel.r_offset == (bfd_vma) -1 | |
5060 | || outrel.r_offset == (bfd_vma) -2) | |
5061 | abort (); | |
5062 | ||
5063 | outrel.r_offset += (input_section->output_section->vma | |
5064 | + input_section->output_offset); | |
5065 | ||
5066 | if (h->dynindx == -1 | |
5067 | || h->forced_local | |
0e1862bb | 5068 | || bfd_link_executable (info)) |
1419bbe5 WN |
5069 | { |
5070 | /* This symbol is resolved locally. */ | |
5071 | outrel.r_info = ELFNN_R_INFO (0, AARCH64_R (IRELATIVE)); | |
5072 | outrel.r_addend = (h->root.u.def.value | |
5073 | + h->root.u.def.section->output_section->vma | |
5074 | + h->root.u.def.section->output_offset); | |
5075 | } | |
5076 | else | |
5077 | { | |
5078 | outrel.r_info = ELFNN_R_INFO (h->dynindx, r_type); | |
5079 | outrel.r_addend = 0; | |
5080 | } | |
5081 | ||
5082 | sreloc = globals->root.irelifunc; | |
5083 | elf_append_rela (output_bfd, sreloc, &outrel); | |
5084 | ||
5085 | /* If this reloc is against an external symbol, we | |
5086 | do not want to fiddle with the addend. Otherwise, | |
5087 | we need to include the symbol value so that it | |
5088 | becomes an addend for the dynamic reloc. For an | |
5089 | internal symbol, we have updated addend. */ | |
5090 | return bfd_reloc_ok; | |
5091 | } | |
5092 | /* FALLTHROUGH */ | |
1419bbe5 | 5093 | case BFD_RELOC_AARCH64_CALL26: |
ce336788 | 5094 | case BFD_RELOC_AARCH64_JUMP26: |
1419bbe5 WN |
5095 | value = _bfd_aarch64_elf_resolve_relocation (bfd_r_type, place, value, |
5096 | signed_addend, | |
5097 | weak_undef_p); | |
5098 | return _bfd_aarch64_elf_put_addend (input_bfd, hit_data, bfd_r_type, | |
5099 | howto, value); | |
1419bbe5 WN |
5100 | case BFD_RELOC_AARCH64_ADR_GOT_PAGE: |
5101 | case BFD_RELOC_AARCH64_GOT_LD_PREL19: | |
7018c030 | 5102 | case BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14: |
ce336788 | 5103 | case BFD_RELOC_AARCH64_LD32_GOT_LO12_NC: |
99ad26cb | 5104 | case BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15: |
dc8008f5 | 5105 | case BFD_RELOC_AARCH64_MOVW_GOTOFF_G0_NC: |
74a1bfe1 | 5106 | case BFD_RELOC_AARCH64_MOVW_GOTOFF_G1: |
a2e1db00 | 5107 | case BFD_RELOC_AARCH64_LD64_GOTOFF_LO15: |
ce336788 | 5108 | case BFD_RELOC_AARCH64_LD64_GOT_LO12_NC: |
1419bbe5 WN |
5109 | base_got = globals->root.sgot; |
5110 | off = h->got.offset; | |
5111 | ||
5112 | if (base_got == NULL) | |
5113 | abort (); | |
5114 | ||
5115 | if (off == (bfd_vma) -1) | |
5116 | { | |
5117 | bfd_vma plt_index; | |
5118 | ||
5119 | /* We can't use h->got.offset here to save state, or | |
5120 | even just remember the offset, as finish_dynamic_symbol | |
5121 | would use that as offset into .got. */ | |
5122 | ||
5123 | if (globals->root.splt != NULL) | |
5124 | { | |
b1ee0cc4 WN |
5125 | plt_index = ((h->plt.offset - globals->plt_header_size) / |
5126 | globals->plt_entry_size); | |
1419bbe5 WN |
5127 | off = (plt_index + 3) * GOT_ENTRY_SIZE; |
5128 | base_got = globals->root.sgotplt; | |
5129 | } | |
5130 | else | |
5131 | { | |
5132 | plt_index = h->plt.offset / globals->plt_entry_size; | |
5133 | off = plt_index * GOT_ENTRY_SIZE; | |
5134 | base_got = globals->root.igotplt; | |
5135 | } | |
5136 | ||
5137 | if (h->dynindx == -1 | |
5138 | || h->forced_local | |
5139 | || info->symbolic) | |
5140 | { | |
5141 | /* This references the local definition. We must | |
5142 | initialize this entry in the global offset table. | |
5143 | Since the offset must always be a multiple of 8, | |
5144 | we use the least significant bit to record | |
5145 | whether we have initialized it already. | |
5146 | ||
5147 | When doing a dynamic link, we create a .rela.got | |
5148 | relocation entry to initialize the value. This | |
5149 | is done in the finish_dynamic_symbol routine. */ | |
5150 | if ((off & 1) != 0) | |
5151 | off &= ~1; | |
5152 | else | |
5153 | { | |
5154 | bfd_put_NN (output_bfd, value, | |
5155 | base_got->contents + off); | |
5156 | /* Note that this is harmless as -1 | 1 still is -1. */ | |
5157 | h->got.offset |= 1; | |
5158 | } | |
5159 | } | |
5160 | value = (base_got->output_section->vma | |
5161 | + base_got->output_offset + off); | |
5162 | } | |
5163 | else | |
5164 | value = aarch64_calculate_got_entry_vma (h, globals, info, | |
5165 | value, output_bfd, | |
5166 | unresolved_reloc_p); | |
a0becb89 | 5167 | |
2aff25ba JW |
5168 | if (aarch64_relocation_aginst_gp_p (bfd_r_type)) |
5169 | addend = (globals->root.sgot->output_section->vma | |
5170 | + globals->root.sgot->output_offset); | |
a0becb89 | 5171 | |
1419bbe5 | 5172 | value = _bfd_aarch64_elf_resolve_relocation (bfd_r_type, place, value, |
99ad26cb | 5173 | addend, weak_undef_p); |
1419bbe5 | 5174 | return _bfd_aarch64_elf_put_addend (input_bfd, hit_data, bfd_r_type, howto, value); |
1419bbe5 | 5175 | case BFD_RELOC_AARCH64_ADD_LO12: |
ce336788 | 5176 | case BFD_RELOC_AARCH64_ADR_HI21_PCREL: |
1419bbe5 WN |
5177 | break; |
5178 | } | |
5179 | } | |
5180 | ||
a6bb11b2 | 5181 | switch (bfd_r_type) |
a06ea964 | 5182 | { |
a6bb11b2 | 5183 | case BFD_RELOC_AARCH64_NONE: |
0484b454 | 5184 | case BFD_RELOC_AARCH64_TLSDESC_ADD: |
a6bb11b2 | 5185 | case BFD_RELOC_AARCH64_TLSDESC_CALL: |
0484b454 | 5186 | case BFD_RELOC_AARCH64_TLSDESC_LDR: |
a06ea964 NC |
5187 | *unresolved_reloc_p = FALSE; |
5188 | return bfd_reloc_ok; | |
5189 | ||
a6bb11b2 | 5190 | case BFD_RELOC_AARCH64_NN: |
a06ea964 NC |
5191 | |
5192 | /* When generating a shared object or relocatable executable, these | |
5193 | relocations are copied into the output file to be resolved at | |
5194 | run time. */ | |
6353d82b JW |
5195 | if (((bfd_link_pic (info) |
5196 | || globals->root.is_relocatable_executable) | |
5197 | && (input_section->flags & SEC_ALLOC) | |
5198 | && (h == NULL | |
5199 | || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT | |
5200 | || h->root.type != bfd_link_hash_undefweak)) | |
5201 | /* Or we are creating an executable, we may need to keep relocations | |
5202 | for symbols satisfied by a dynamic library if we manage to avoid | |
5203 | copy relocs for the symbol. */ | |
5204 | || (ELIMINATE_COPY_RELOCS | |
5205 | && !bfd_link_pic (info) | |
5206 | && h != NULL | |
5207 | && (input_section->flags & SEC_ALLOC) | |
5208 | && h->dynindx != -1 | |
5209 | && !h->non_got_ref | |
5210 | && ((h->def_dynamic | |
5211 | && !h->def_regular) | |
5212 | || h->root.type == bfd_link_hash_undefweak | |
5213 | || h->root.type == bfd_link_hash_undefined))) | |
a06ea964 NC |
5214 | { |
5215 | Elf_Internal_Rela outrel; | |
5216 | bfd_byte *loc; | |
5217 | bfd_boolean skip, relocate; | |
5218 | asection *sreloc; | |
5219 | ||
5220 | *unresolved_reloc_p = FALSE; | |
5221 | ||
a06ea964 NC |
5222 | skip = FALSE; |
5223 | relocate = FALSE; | |
5224 | ||
5225 | outrel.r_addend = signed_addend; | |
5226 | outrel.r_offset = | |
5227 | _bfd_elf_section_offset (output_bfd, info, input_section, | |
5228 | rel->r_offset); | |
5229 | if (outrel.r_offset == (bfd_vma) - 1) | |
5230 | skip = TRUE; | |
5231 | else if (outrel.r_offset == (bfd_vma) - 2) | |
5232 | { | |
5233 | skip = TRUE; | |
5234 | relocate = TRUE; | |
5235 | } | |
5236 | ||
5237 | outrel.r_offset += (input_section->output_section->vma | |
5238 | + input_section->output_offset); | |
5239 | ||
5240 | if (skip) | |
5241 | memset (&outrel, 0, sizeof outrel); | |
5242 | else if (h != NULL | |
5243 | && h->dynindx != -1 | |
0e1862bb | 5244 | && (!bfd_link_pic (info) |
ac33b731 JW |
5245 | || !(bfd_link_pie (info) |
5246 | || SYMBOLIC_BIND (info, h)) | |
0e1862bb | 5247 | || !h->def_regular)) |
cec5225b | 5248 | outrel.r_info = ELFNN_R_INFO (h->dynindx, r_type); |
a06ea964 NC |
5249 | else |
5250 | { | |
5251 | int symbol; | |
5252 | ||
5253 | /* On SVR4-ish systems, the dynamic loader cannot | |
5254 | relocate the text and data segments independently, | |
5255 | so the symbol does not matter. */ | |
5256 | symbol = 0; | |
1f56df9d | 5257 | relocate = globals->no_apply_dynamic_relocs ? FALSE : TRUE; |
a6bb11b2 | 5258 | outrel.r_info = ELFNN_R_INFO (symbol, AARCH64_R (RELATIVE)); |
a06ea964 NC |
5259 | outrel.r_addend += value; |
5260 | } | |
5261 | ||
1419bbe5 WN |
5262 | sreloc = elf_section_data (input_section)->sreloc; |
5263 | if (sreloc == NULL || sreloc->contents == NULL) | |
5264 | return bfd_reloc_notsupported; | |
5265 | ||
5266 | loc = sreloc->contents + sreloc->reloc_count++ * RELOC_SIZE (globals); | |
cec5225b | 5267 | bfd_elfNN_swap_reloca_out (output_bfd, &outrel, loc); |
a06ea964 | 5268 | |
1419bbe5 | 5269 | if (sreloc->reloc_count * RELOC_SIZE (globals) > sreloc->size) |
a06ea964 NC |
5270 | { |
5271 | /* Sanity to check that we have previously allocated | |
5272 | sufficient space in the relocation section for the | |
5273 | number of relocations we actually want to emit. */ | |
5274 | abort (); | |
5275 | } | |
5276 | ||
5277 | /* If this reloc is against an external symbol, we do not want to | |
5278 | fiddle with the addend. Otherwise, we need to include the symbol | |
5279 | value so that it becomes an addend for the dynamic reloc. */ | |
5280 | if (!relocate) | |
5281 | return bfd_reloc_ok; | |
5282 | ||
5283 | return _bfd_final_link_relocate (howto, input_bfd, input_section, | |
5284 | contents, rel->r_offset, value, | |
5285 | signed_addend); | |
5286 | } | |
5287 | else | |
5288 | value += signed_addend; | |
5289 | break; | |
5290 | ||
a6bb11b2 | 5291 | case BFD_RELOC_AARCH64_CALL26: |
ce336788 | 5292 | case BFD_RELOC_AARCH64_JUMP26: |
a06ea964 NC |
5293 | { |
5294 | asection *splt = globals->root.splt; | |
5295 | bfd_boolean via_plt_p = | |
5296 | splt != NULL && h != NULL && h->plt.offset != (bfd_vma) - 1; | |
5297 | ||
5298 | /* A call to an undefined weak symbol is converted to a jump to | |
5299 | the next instruction unless a PLT entry will be created. | |
5300 | The jump to the next instruction is optimized as a NOP. | |
5301 | Do the same for local undefined symbols. */ | |
5302 | if (weak_undef_p && ! via_plt_p) | |
5303 | { | |
5304 | bfd_putl32 (INSN_NOP, hit_data); | |
5305 | return bfd_reloc_ok; | |
5306 | } | |
5307 | ||
5308 | /* If the call goes through a PLT entry, make sure to | |
5309 | check distance to the right destination address. */ | |
5310 | if (via_plt_p) | |
07f9ddfe JW |
5311 | value = (splt->output_section->vma |
5312 | + splt->output_offset + h->plt.offset); | |
5313 | ||
5314 | /* Check if a stub has to be inserted because the destination | |
5315 | is too far away. */ | |
5316 | struct elf_aarch64_stub_hash_entry *stub_entry = NULL; | |
2f340668 JW |
5317 | |
5318 | /* If the branch destination is directed to plt stub, "value" will be | |
5319 | the final destination, otherwise we should plus signed_addend, it may | |
5320 | contain non-zero value, for example call to local function symbol | |
5321 | which are turned into "sec_sym + sec_off", and sec_off is kept in | |
5322 | signed_addend. */ | |
5323 | if (! aarch64_valid_branch_p (via_plt_p ? value : value + signed_addend, | |
5324 | place)) | |
07f9ddfe JW |
5325 | /* The target is out of reach, so redirect the branch to |
5326 | the local stub for this function. */ | |
5327 | stub_entry = elfNN_aarch64_get_stub_entry (input_section, sym_sec, h, | |
5328 | rel, globals); | |
5329 | if (stub_entry != NULL) | |
2f340668 JW |
5330 | { |
5331 | value = (stub_entry->stub_offset | |
5332 | + stub_entry->stub_sec->output_offset | |
5333 | + stub_entry->stub_sec->output_section->vma); | |
5334 | ||
5335 | /* We have redirected the destination to stub entry address, | |
5336 | so ignore any addend record in the original rela entry. */ | |
5337 | signed_addend = 0; | |
5338 | } | |
a06ea964 | 5339 | } |
caed7120 YZ |
5340 | value = _bfd_aarch64_elf_resolve_relocation (bfd_r_type, place, value, |
5341 | signed_addend, weak_undef_p); | |
07f9ddfe | 5342 | *unresolved_reloc_p = FALSE; |
a06ea964 NC |
5343 | break; |
5344 | ||
dcbd20eb JW |
5345 | case BFD_RELOC_AARCH64_16_PCREL: |
5346 | case BFD_RELOC_AARCH64_32_PCREL: | |
5347 | case BFD_RELOC_AARCH64_64_PCREL: | |
ce336788 JW |
5348 | case BFD_RELOC_AARCH64_ADR_HI21_NC_PCREL: |
5349 | case BFD_RELOC_AARCH64_ADR_HI21_PCREL: | |
5350 | case BFD_RELOC_AARCH64_ADR_LO21_PCREL: | |
5351 | case BFD_RELOC_AARCH64_LD_LO19_PCREL: | |
0e1862bb | 5352 | if (bfd_link_pic (info) |
dcbd20eb JW |
5353 | && (input_section->flags & SEC_ALLOC) != 0 |
5354 | && (input_section->flags & SEC_READONLY) != 0 | |
d68f1976 | 5355 | && !SYMBOL_REFERENCES_LOCAL (info, h)) |
dcbd20eb JW |
5356 | { |
5357 | int howto_index = bfd_r_type - BFD_RELOC_AARCH64_RELOC_START; | |
5358 | ||
4eca0228 | 5359 | _bfd_error_handler |
695344c0 | 5360 | /* xgettext:c-format */ |
d68f1976 JW |
5361 | (_("%B: relocation %s against symbol `%s' which may bind " |
5362 | "externally can not be used when making a shared object; " | |
5363 | "recompile with -fPIC"), | |
dcbd20eb JW |
5364 | input_bfd, elfNN_aarch64_howto_table[howto_index].name, |
5365 | h->root.root.string); | |
5366 | bfd_set_error (bfd_error_bad_value); | |
1d75a8e2 | 5367 | return bfd_reloc_notsupported; |
dcbd20eb | 5368 | } |
1a0670f3 | 5369 | /* Fall through. */ |
dcbd20eb | 5370 | |
a6bb11b2 | 5371 | case BFD_RELOC_AARCH64_16: |
92d77487 RL |
5372 | #if ARCH_SIZE == 64 |
5373 | case BFD_RELOC_AARCH64_32: | |
5374 | #endif | |
a6bb11b2 | 5375 | case BFD_RELOC_AARCH64_ADD_LO12: |
a6bb11b2 | 5376 | case BFD_RELOC_AARCH64_BRANCH19: |
ce336788 | 5377 | case BFD_RELOC_AARCH64_LDST128_LO12: |
a6bb11b2 YZ |
5378 | case BFD_RELOC_AARCH64_LDST16_LO12: |
5379 | case BFD_RELOC_AARCH64_LDST32_LO12: | |
5380 | case BFD_RELOC_AARCH64_LDST64_LO12: | |
ce336788 | 5381 | case BFD_RELOC_AARCH64_LDST8_LO12: |
a6bb11b2 YZ |
5382 | case BFD_RELOC_AARCH64_MOVW_G0: |
5383 | case BFD_RELOC_AARCH64_MOVW_G0_NC: | |
ce336788 | 5384 | case BFD_RELOC_AARCH64_MOVW_G0_S: |
a6bb11b2 YZ |
5385 | case BFD_RELOC_AARCH64_MOVW_G1: |
5386 | case BFD_RELOC_AARCH64_MOVW_G1_NC: | |
ce336788 | 5387 | case BFD_RELOC_AARCH64_MOVW_G1_S: |
a6bb11b2 YZ |
5388 | case BFD_RELOC_AARCH64_MOVW_G2: |
5389 | case BFD_RELOC_AARCH64_MOVW_G2_NC: | |
ce336788 | 5390 | case BFD_RELOC_AARCH64_MOVW_G2_S: |
a6bb11b2 | 5391 | case BFD_RELOC_AARCH64_MOVW_G3: |
a6bb11b2 | 5392 | case BFD_RELOC_AARCH64_TSTBR14: |
caed7120 YZ |
5393 | value = _bfd_aarch64_elf_resolve_relocation (bfd_r_type, place, value, |
5394 | signed_addend, weak_undef_p); | |
a06ea964 NC |
5395 | break; |
5396 | ||
a6bb11b2 YZ |
5397 | case BFD_RELOC_AARCH64_ADR_GOT_PAGE: |
5398 | case BFD_RELOC_AARCH64_GOT_LD_PREL19: | |
7018c030 | 5399 | case BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14: |
ce336788 | 5400 | case BFD_RELOC_AARCH64_LD32_GOT_LO12_NC: |
99ad26cb | 5401 | case BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15: |
ce336788 | 5402 | case BFD_RELOC_AARCH64_LD64_GOT_LO12_NC: |
2aff25ba JW |
5403 | case BFD_RELOC_AARCH64_LD64_GOTOFF_LO15: |
5404 | case BFD_RELOC_AARCH64_MOVW_GOTOFF_G0_NC: | |
5405 | case BFD_RELOC_AARCH64_MOVW_GOTOFF_G1: | |
a06ea964 NC |
5406 | if (globals->root.sgot == NULL) |
5407 | BFD_ASSERT (h != NULL); | |
5408 | ||
ff07562f | 5409 | relative_reloc = FALSE; |
a06ea964 NC |
5410 | if (h != NULL) |
5411 | { | |
99ad26cb | 5412 | bfd_vma addend = 0; |
ff07562f JW |
5413 | |
5414 | /* If a symbol is not dynamic and is not undefined weak, bind it | |
5415 | locally and generate a RELATIVE relocation under PIC mode. | |
5416 | ||
5417 | NOTE: one symbol may be referenced by several relocations, we | |
5418 | should only generate one RELATIVE relocation for that symbol. | |
5419 | Therefore, check GOT offset mark first. */ | |
5420 | if (h->dynindx == -1 | |
5421 | && !h->forced_local | |
5422 | && h->root.type != bfd_link_hash_undefweak | |
5423 | && bfd_link_pic (info) | |
5424 | && !symbol_got_offset_mark_p (input_bfd, h, r_symndx)) | |
5425 | relative_reloc = TRUE; | |
5426 | ||
a06ea964 NC |
5427 | value = aarch64_calculate_got_entry_vma (h, globals, info, value, |
5428 | output_bfd, | |
5429 | unresolved_reloc_p); | |
ff07562f JW |
5430 | /* Record the GOT entry address which will be used when generating |
5431 | RELATIVE relocation. */ | |
5432 | if (relative_reloc) | |
5433 | got_entry_addr = value; | |
5434 | ||
2aff25ba | 5435 | if (aarch64_relocation_aginst_gp_p (bfd_r_type)) |
99ad26cb JW |
5436 | addend = (globals->root.sgot->output_section->vma |
5437 | + globals->root.sgot->output_offset); | |
caed7120 | 5438 | value = _bfd_aarch64_elf_resolve_relocation (bfd_r_type, place, value, |
99ad26cb | 5439 | addend, weak_undef_p); |
a06ea964 | 5440 | } |
b53b1bed JW |
5441 | else |
5442 | { | |
99ad26cb | 5443 | bfd_vma addend = 0; |
b53b1bed JW |
5444 | struct elf_aarch64_local_symbol *locals |
5445 | = elf_aarch64_locals (input_bfd); | |
5446 | ||
5447 | if (locals == NULL) | |
5448 | { | |
5449 | int howto_index = bfd_r_type - BFD_RELOC_AARCH64_RELOC_START; | |
4eca0228 | 5450 | _bfd_error_handler |
695344c0 | 5451 | /* xgettext:c-format */ |
b53b1bed JW |
5452 | (_("%B: Local symbol descriptor table be NULL when applying " |
5453 | "relocation %s against local symbol"), | |
5454 | input_bfd, elfNN_aarch64_howto_table[howto_index].name); | |
5455 | abort (); | |
5456 | } | |
5457 | ||
5458 | off = symbol_got_offset (input_bfd, h, r_symndx); | |
5459 | base_got = globals->root.sgot; | |
ff07562f JW |
5460 | got_entry_addr = (base_got->output_section->vma |
5461 | + base_got->output_offset + off); | |
b53b1bed JW |
5462 | |
5463 | if (!symbol_got_offset_mark_p (input_bfd, h, r_symndx)) | |
5464 | { | |
5465 | bfd_put_64 (output_bfd, value, base_got->contents + off); | |
5466 | ||
ff07562f JW |
5467 | /* For local symbol, we have done absolute relocation in static |
5468 | linking stage. While for shared library, we need to update the | |
5469 | content of GOT entry according to the shared object's runtime | |
5470 | base address. So, we need to generate a R_AARCH64_RELATIVE reloc | |
5471 | for dynamic linker. */ | |
0e1862bb | 5472 | if (bfd_link_pic (info)) |
ff07562f | 5473 | relative_reloc = TRUE; |
b53b1bed JW |
5474 | |
5475 | symbol_got_offset_mark (input_bfd, h, r_symndx); | |
5476 | } | |
5477 | ||
5478 | /* Update the relocation value to GOT entry addr as we have transformed | |
5479 | the direct data access into indirect data access through GOT. */ | |
5480 | value = got_entry_addr; | |
99ad26cb | 5481 | |
2aff25ba | 5482 | if (aarch64_relocation_aginst_gp_p (bfd_r_type)) |
99ad26cb JW |
5483 | addend = base_got->output_section->vma + base_got->output_offset; |
5484 | ||
5485 | value = _bfd_aarch64_elf_resolve_relocation (bfd_r_type, place, value, | |
5486 | addend, weak_undef_p); | |
b53b1bed | 5487 | } |
ff07562f JW |
5488 | |
5489 | if (relative_reloc) | |
5490 | { | |
5491 | asection *s; | |
5492 | Elf_Internal_Rela outrel; | |
5493 | ||
5494 | s = globals->root.srelgot; | |
5495 | if (s == NULL) | |
5496 | abort (); | |
5497 | ||
5498 | outrel.r_offset = got_entry_addr; | |
5499 | outrel.r_info = ELFNN_R_INFO (0, AARCH64_R (RELATIVE)); | |
5500 | outrel.r_addend = orig_value; | |
5501 | elf_append_rela (output_bfd, s, &outrel); | |
5502 | } | |
a2e1db00 RL |
5503 | break; |
5504 | ||
ce336788 | 5505 | case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC: |
a6bb11b2 | 5506 | case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21: |
3c12b054 | 5507 | case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21: |
a6bb11b2 | 5508 | case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21: |
a6bb11b2 | 5509 | case BFD_RELOC_AARCH64_TLSIE_LD32_GOTTPREL_LO12_NC: |
ce336788 | 5510 | case BFD_RELOC_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC: |
043bf05a | 5511 | case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19: |
73f925cc | 5512 | case BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC: |
f69e4920 | 5513 | case BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21: |
77a69ff8 | 5514 | case BFD_RELOC_AARCH64_TLSLD_ADR_PREL21: |
a06ea964 NC |
5515 | if (globals->root.sgot == NULL) |
5516 | return bfd_reloc_notsupported; | |
5517 | ||
5518 | value = (symbol_got_offset (input_bfd, h, r_symndx) | |
5519 | + globals->root.sgot->output_section->vma | |
f44a1f8e | 5520 | + globals->root.sgot->output_offset); |
a06ea964 | 5521 | |
caed7120 YZ |
5522 | value = _bfd_aarch64_elf_resolve_relocation (bfd_r_type, place, value, |
5523 | 0, weak_undef_p); | |
a06ea964 NC |
5524 | *unresolved_reloc_p = FALSE; |
5525 | break; | |
5526 | ||
7ba7cfe4 | 5527 | case BFD_RELOC_AARCH64_TLSGD_MOVW_G0_NC: |
94facae3 | 5528 | case BFD_RELOC_AARCH64_TLSGD_MOVW_G1: |
3b957e5b RL |
5529 | case BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G0_NC: |
5530 | case BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G1: | |
94facae3 RL |
5531 | if (globals->root.sgot == NULL) |
5532 | return bfd_reloc_notsupported; | |
5533 | ||
5534 | value = symbol_got_offset (input_bfd, h, r_symndx); | |
5535 | value = _bfd_aarch64_elf_resolve_relocation (bfd_r_type, place, value, | |
5536 | 0, weak_undef_p); | |
5537 | *unresolved_reloc_p = FALSE; | |
5538 | break; | |
5539 | ||
6ffe9a1b | 5540 | case BFD_RELOC_AARCH64_TLSLD_ADD_DTPREL_HI12: |
40fbed84 | 5541 | case BFD_RELOC_AARCH64_TLSLD_ADD_DTPREL_LO12: |
753999c1 | 5542 | case BFD_RELOC_AARCH64_TLSLD_ADD_DTPREL_LO12_NC: |
07c9aa07 JW |
5543 | case BFD_RELOC_AARCH64_TLSLD_LDST16_DTPREL_LO12: |
5544 | case BFD_RELOC_AARCH64_TLSLD_LDST16_DTPREL_LO12_NC: | |
5545 | case BFD_RELOC_AARCH64_TLSLD_LDST32_DTPREL_LO12: | |
5546 | case BFD_RELOC_AARCH64_TLSLD_LDST32_DTPREL_LO12_NC: | |
5547 | case BFD_RELOC_AARCH64_TLSLD_LDST64_DTPREL_LO12: | |
5548 | case BFD_RELOC_AARCH64_TLSLD_LDST64_DTPREL_LO12_NC: | |
5549 | case BFD_RELOC_AARCH64_TLSLD_LDST8_DTPREL_LO12: | |
5550 | case BFD_RELOC_AARCH64_TLSLD_LDST8_DTPREL_LO12_NC: | |
6ffe9a1b JW |
5551 | case BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G0: |
5552 | case BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G0_NC: | |
5553 | case BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G1: | |
5554 | case BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G1_NC: | |
5555 | case BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G2: | |
40fbed84 JW |
5556 | value = _bfd_aarch64_elf_resolve_relocation (bfd_r_type, place, value, |
5557 | signed_addend - dtpoff_base (info), | |
5558 | weak_undef_p); | |
5559 | break; | |
5560 | ||
a6bb11b2 YZ |
5561 | case BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_HI12: |
5562 | case BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_LO12: | |
5563 | case BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_LO12_NC: | |
5564 | case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0: | |
5565 | case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC: | |
5566 | case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1: | |
5567 | case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1_NC: | |
5568 | case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G2: | |
caed7120 YZ |
5569 | value = _bfd_aarch64_elf_resolve_relocation (bfd_r_type, place, value, |
5570 | signed_addend - tpoff_base (info), | |
5571 | weak_undef_p); | |
a06ea964 NC |
5572 | *unresolved_reloc_p = FALSE; |
5573 | break; | |
5574 | ||
f955cccf | 5575 | case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12: |
a6bb11b2 | 5576 | case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21: |
389b8029 | 5577 | case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21: |
a6bb11b2 | 5578 | case BFD_RELOC_AARCH64_TLSDESC_LD32_LO12_NC: |
f955cccf | 5579 | case BFD_RELOC_AARCH64_TLSDESC_LD64_LO12: |
1ada945d | 5580 | case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19: |
a06ea964 NC |
5581 | if (globals->root.sgot == NULL) |
5582 | return bfd_reloc_notsupported; | |
a06ea964 NC |
5583 | value = (symbol_tlsdesc_got_offset (input_bfd, h, r_symndx) |
5584 | + globals->root.sgotplt->output_section->vma | |
f44a1f8e | 5585 | + globals->root.sgotplt->output_offset |
a06ea964 NC |
5586 | + globals->sgotplt_jump_table_size); |
5587 | ||
caed7120 YZ |
5588 | value = _bfd_aarch64_elf_resolve_relocation (bfd_r_type, place, value, |
5589 | 0, weak_undef_p); | |
a06ea964 NC |
5590 | *unresolved_reloc_p = FALSE; |
5591 | break; | |
5592 | ||
0484b454 RL |
5593 | case BFD_RELOC_AARCH64_TLSDESC_OFF_G0_NC: |
5594 | case BFD_RELOC_AARCH64_TLSDESC_OFF_G1: | |
5595 | if (globals->root.sgot == NULL) | |
5596 | return bfd_reloc_notsupported; | |
5597 | ||
5598 | value = (symbol_tlsdesc_got_offset (input_bfd, h, r_symndx) | |
5599 | + globals->root.sgotplt->output_section->vma | |
5600 | + globals->root.sgotplt->output_offset | |
5601 | + globals->sgotplt_jump_table_size); | |
5602 | ||
5603 | value -= (globals->root.sgot->output_section->vma | |
5604 | + globals->root.sgot->output_offset); | |
5605 | ||
5606 | value = _bfd_aarch64_elf_resolve_relocation (bfd_r_type, place, value, | |
5607 | 0, weak_undef_p); | |
5608 | *unresolved_reloc_p = FALSE; | |
5609 | break; | |
5610 | ||
a06ea964 NC |
5611 | default: |
5612 | return bfd_reloc_notsupported; | |
5613 | } | |
5614 | ||
5615 | if (saved_addend) | |
5616 | *saved_addend = value; | |
5617 | ||
5618 | /* Only apply the final relocation in a sequence. */ | |
5619 | if (save_addend) | |
5620 | return bfd_reloc_continue; | |
5621 | ||
caed7120 YZ |
5622 | return _bfd_aarch64_elf_put_addend (input_bfd, hit_data, bfd_r_type, |
5623 | howto, value); | |
a06ea964 NC |
5624 | } |
5625 | ||
2d0ca824 YN |
5626 | /* LP64 and ILP32 operates on x- and w-registers respectively. |
5627 | Next definitions take into account the difference between | |
5628 | corresponding machine codes. R means x-register if the target | |
5629 | arch is LP64, and w-register if the target is ILP32. */ | |
5630 | ||
5631 | #if ARCH_SIZE == 64 | |
5632 | # define add_R0_R0 (0x91000000) | |
5633 | # define add_R0_R0_R1 (0x8b000020) | |
5634 | # define add_R0_R1 (0x91400020) | |
5635 | # define ldr_R0 (0x58000000) | |
5636 | # define ldr_R0_mask(i) (i & 0xffffffe0) | |
5637 | # define ldr_R0_x0 (0xf9400000) | |
5638 | # define ldr_hw_R0 (0xf2a00000) | |
5639 | # define movk_R0 (0xf2800000) | |
5640 | # define movz_R0 (0xd2a00000) | |
5641 | # define movz_hw_R0 (0xd2c00000) | |
5642 | #else /*ARCH_SIZE == 32 */ | |
5643 | # define add_R0_R0 (0x11000000) | |
5644 | # define add_R0_R0_R1 (0x0b000020) | |
5645 | # define add_R0_R1 (0x11400020) | |
5646 | # define ldr_R0 (0x18000000) | |
5647 | # define ldr_R0_mask(i) (i & 0xbfffffe0) | |
5648 | # define ldr_R0_x0 (0xb9400000) | |
5649 | # define ldr_hw_R0 (0x72a00000) | |
5650 | # define movk_R0 (0x72800000) | |
5651 | # define movz_R0 (0x52a00000) | |
5652 | # define movz_hw_R0 (0x52c00000) | |
5653 | #endif | |
5654 | ||
a06ea964 NC |
5655 | /* Handle TLS relaxations. Relaxing is possible for symbols that use |
5656 | R_AARCH64_TLSDESC_ADR_{PAGE, LD64_LO12_NC, ADD_LO12_NC} during a static | |
5657 | link. | |
5658 | ||
5659 | Return bfd_reloc_ok if we're done, bfd_reloc_continue if the caller | |
5660 | is to then call final_link_relocate. Return other values in the | |
5661 | case of error. */ | |
5662 | ||
5663 | static bfd_reloc_status_type | |
cec5225b | 5664 | elfNN_aarch64_tls_relax (struct elf_aarch64_link_hash_table *globals, |
a06ea964 | 5665 | bfd *input_bfd, bfd_byte *contents, |
06d2788c | 5666 | Elf_Internal_Rela *rel, struct elf_link_hash_entry *h) |
a06ea964 NC |
5667 | { |
5668 | bfd_boolean is_local = h == NULL; | |
cec5225b | 5669 | unsigned int r_type = ELFNN_R_TYPE (rel->r_info); |
a06ea964 NC |
5670 | unsigned long insn; |
5671 | ||
5672 | BFD_ASSERT (globals && input_bfd && contents && rel); | |
5673 | ||
a6bb11b2 | 5674 | switch (elfNN_aarch64_bfd_reloc_from_type (r_type)) |
a06ea964 | 5675 | { |
a6bb11b2 | 5676 | case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21: |
ce336788 | 5677 | case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21: |
a06ea964 NC |
5678 | if (is_local) |
5679 | { | |
5680 | /* GD->LE relaxation: | |
2d0ca824 | 5681 | adrp x0, :tlsgd:var => movz R0, :tprel_g1:var |
a06ea964 | 5682 | or |
2d0ca824 YN |
5683 | adrp x0, :tlsdesc:var => movz R0, :tprel_g1:var |
5684 | ||
5685 | Where R is x for LP64, and w for ILP32. */ | |
5686 | bfd_putl32 (movz_R0, contents + rel->r_offset); | |
a06ea964 NC |
5687 | return bfd_reloc_continue; |
5688 | } | |
5689 | else | |
5690 | { | |
5691 | /* GD->IE relaxation: | |
5692 | adrp x0, :tlsgd:var => adrp x0, :gottprel:var | |
5693 | or | |
5694 | adrp x0, :tlsdesc:var => adrp x0, :gottprel:var | |
5695 | */ | |
a06ea964 NC |
5696 | return bfd_reloc_continue; |
5697 | } | |
5698 | ||
389b8029 MS |
5699 | case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21: |
5700 | BFD_ASSERT (0); | |
5701 | break; | |
5702 | ||
1ada945d MS |
5703 | case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19: |
5704 | if (is_local) | |
5705 | { | |
5706 | /* Tiny TLSDESC->LE relaxation: | |
2d0ca824 YN |
5707 | ldr x1, :tlsdesc:var => movz R0, #:tprel_g1:var |
5708 | adr x0, :tlsdesc:var => movk R0, #:tprel_g0_nc:var | |
1ada945d MS |
5709 | .tlsdesccall var |
5710 | blr x1 => nop | |
2d0ca824 YN |
5711 | |
5712 | Where R is x for LP64, and w for ILP32. */ | |
1ada945d MS |
5713 | BFD_ASSERT (ELFNN_R_TYPE (rel[1].r_info) == AARCH64_R (TLSDESC_ADR_PREL21)); |
5714 | BFD_ASSERT (ELFNN_R_TYPE (rel[2].r_info) == AARCH64_R (TLSDESC_CALL)); | |
5715 | ||
5716 | rel[1].r_info = ELFNN_R_INFO (ELFNN_R_SYM (rel->r_info), | |
5717 | AARCH64_R (TLSLE_MOVW_TPREL_G0_NC)); | |
5718 | rel[2].r_info = ELFNN_R_INFO (STN_UNDEF, R_AARCH64_NONE); | |
5719 | ||
2d0ca824 YN |
5720 | bfd_putl32 (movz_R0, contents + rel->r_offset); |
5721 | bfd_putl32 (movk_R0, contents + rel->r_offset + 4); | |
1ada945d MS |
5722 | bfd_putl32 (INSN_NOP, contents + rel->r_offset + 8); |
5723 | return bfd_reloc_continue; | |
5724 | } | |
5725 | else | |
5726 | { | |
5727 | /* Tiny TLSDESC->IE relaxation: | |
5728 | ldr x1, :tlsdesc:var => ldr x0, :gottprel:var | |
5729 | adr x0, :tlsdesc:var => nop | |
5730 | .tlsdesccall var | |
5731 | blr x1 => nop | |
5732 | */ | |
5733 | BFD_ASSERT (ELFNN_R_TYPE (rel[1].r_info) == AARCH64_R (TLSDESC_ADR_PREL21)); | |
5734 | BFD_ASSERT (ELFNN_R_TYPE (rel[2].r_info) == AARCH64_R (TLSDESC_CALL)); | |
5735 | ||
5736 | rel[1].r_info = ELFNN_R_INFO (STN_UNDEF, R_AARCH64_NONE); | |
5737 | rel[2].r_info = ELFNN_R_INFO (STN_UNDEF, R_AARCH64_NONE); | |
5738 | ||
2d0ca824 | 5739 | bfd_putl32 (ldr_R0, contents + rel->r_offset); |
1ada945d MS |
5740 | bfd_putl32 (INSN_NOP, contents + rel->r_offset + 4); |
5741 | bfd_putl32 (INSN_NOP, contents + rel->r_offset + 8); | |
5742 | return bfd_reloc_continue; | |
5743 | } | |
5744 | ||
3c12b054 MS |
5745 | case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21: |
5746 | if (is_local) | |
5747 | { | |
5748 | /* Tiny GD->LE relaxation: | |
5749 | adr x0, :tlsgd:var => mrs x1, tpidr_el0 | |
2d0ca824 YN |
5750 | bl __tls_get_addr => add R0, R1, #:tprel_hi12:x, lsl #12 |
5751 | nop => add R0, R0, #:tprel_lo12_nc:x | |
5752 | ||
5753 | Where R is x for LP64, and x for Ilp32. */ | |
3c12b054 MS |
5754 | |
5755 | /* First kill the tls_get_addr reloc on the bl instruction. */ | |
5756 | BFD_ASSERT (rel->r_offset + 4 == rel[1].r_offset); | |
5757 | ||
5758 | bfd_putl32 (0xd53bd041, contents + rel->r_offset + 0); | |
2d0ca824 YN |
5759 | bfd_putl32 (add_R0_R1, contents + rel->r_offset + 4); |
5760 | bfd_putl32 (add_R0_R0, contents + rel->r_offset + 8); | |
3c12b054 MS |
5761 | |
5762 | rel[1].r_info = ELFNN_R_INFO (ELFNN_R_SYM (rel->r_info), | |
5763 | AARCH64_R (TLSLE_ADD_TPREL_LO12_NC)); | |
5764 | rel[1].r_offset = rel->r_offset + 8; | |
5765 | ||
5766 | /* Move the current relocation to the second instruction in | |
5767 | the sequence. */ | |
5768 | rel->r_offset += 4; | |
5769 | rel->r_info = ELFNN_R_INFO (ELFNN_R_SYM (rel->r_info), | |
5770 | AARCH64_R (TLSLE_ADD_TPREL_HI12)); | |
5771 | return bfd_reloc_continue; | |
5772 | } | |
5773 | else | |
5774 | { | |
5775 | /* Tiny GD->IE relaxation: | |
2d0ca824 | 5776 | adr x0, :tlsgd:var => ldr R0, :gottprel:var |
3c12b054 | 5777 | bl __tls_get_addr => mrs x1, tpidr_el0 |
2d0ca824 YN |
5778 | nop => add R0, R0, R1 |
5779 | ||
5780 | Where R is x for LP64, and w for Ilp32. */ | |
3c12b054 MS |
5781 | |
5782 | /* First kill the tls_get_addr reloc on the bl instruction. */ | |
5783 | BFD_ASSERT (rel->r_offset + 4 == rel[1].r_offset); | |
5784 | rel[1].r_info = ELFNN_R_INFO (STN_UNDEF, R_AARCH64_NONE); | |
5785 | ||
2d0ca824 | 5786 | bfd_putl32 (ldr_R0, contents + rel->r_offset); |
3c12b054 | 5787 | bfd_putl32 (0xd53bd041, contents + rel->r_offset + 4); |
2d0ca824 | 5788 | bfd_putl32 (add_R0_R0_R1, contents + rel->r_offset + 8); |
3c12b054 MS |
5789 | return bfd_reloc_continue; |
5790 | } | |
5791 | ||
ac734732 RL |
5792 | #if ARCH_SIZE == 64 |
5793 | case BFD_RELOC_AARCH64_TLSGD_MOVW_G1: | |
5794 | BFD_ASSERT (ELFNN_R_TYPE (rel[1].r_info) == AARCH64_R (TLSGD_MOVW_G0_NC)); | |
5795 | BFD_ASSERT (rel->r_offset + 12 == rel[2].r_offset); | |
5796 | BFD_ASSERT (ELFNN_R_TYPE (rel[2].r_info) == AARCH64_R (CALL26)); | |
5797 | ||
5798 | if (is_local) | |
5799 | { | |
5800 | /* Large GD->LE relaxation: | |
5801 | movz x0, #:tlsgd_g1:var => movz x0, #:tprel_g2:var, lsl #32 | |
5802 | movk x0, #:tlsgd_g0_nc:var => movk x0, #:tprel_g1_nc:var, lsl #16 | |
5803 | add x0, gp, x0 => movk x0, #:tprel_g0_nc:var | |
5804 | bl __tls_get_addr => mrs x1, tpidr_el0 | |
5805 | nop => add x0, x0, x1 | |
5806 | */ | |
5807 | rel[2].r_info = ELFNN_R_INFO (ELFNN_R_SYM (rel->r_info), | |
5808 | AARCH64_R (TLSLE_MOVW_TPREL_G0_NC)); | |
5809 | rel[2].r_offset = rel->r_offset + 8; | |
5810 | ||
2d0ca824 YN |
5811 | bfd_putl32 (movz_hw_R0, contents + rel->r_offset + 0); |
5812 | bfd_putl32 (ldr_hw_R0, contents + rel->r_offset + 4); | |
5813 | bfd_putl32 (movk_R0, contents + rel->r_offset + 8); | |
ac734732 | 5814 | bfd_putl32 (0xd53bd041, contents + rel->r_offset + 12); |
2d0ca824 | 5815 | bfd_putl32 (add_R0_R0_R1, contents + rel->r_offset + 16); |
ac734732 RL |
5816 | } |
5817 | else | |
5818 | { | |
5819 | /* Large GD->IE relaxation: | |
5820 | movz x0, #:tlsgd_g1:var => movz x0, #:gottprel_g1:var, lsl #16 | |
5821 | movk x0, #:tlsgd_g0_nc:var => movk x0, #:gottprel_g0_nc:var | |
5822 | add x0, gp, x0 => ldr x0, [gp, x0] | |
5823 | bl __tls_get_addr => mrs x1, tpidr_el0 | |
5824 | nop => add x0, x0, x1 | |
5825 | */ | |
5826 | rel[2].r_info = ELFNN_R_INFO (STN_UNDEF, R_AARCH64_NONE); | |
5827 | bfd_putl32 (0xd2a80000, contents + rel->r_offset + 0); | |
2d0ca824 | 5828 | bfd_putl32 (ldr_R0, contents + rel->r_offset + 8); |
ac734732 | 5829 | bfd_putl32 (0xd53bd041, contents + rel->r_offset + 12); |
2d0ca824 | 5830 | bfd_putl32 (add_R0_R0_R1, contents + rel->r_offset + 16); |
ac734732 RL |
5831 | } |
5832 | return bfd_reloc_continue; | |
5833 | ||
5834 | case BFD_RELOC_AARCH64_TLSGD_MOVW_G0_NC: | |
5835 | return bfd_reloc_continue; | |
5836 | #endif | |
5837 | ||
043bf05a MS |
5838 | case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19: |
5839 | return bfd_reloc_continue; | |
5840 | ||
a6bb11b2 | 5841 | case BFD_RELOC_AARCH64_TLSDESC_LDNN_LO12_NC: |
a06ea964 NC |
5842 | if (is_local) |
5843 | { | |
5844 | /* GD->LE relaxation: | |
5845 | ldr xd, [x0, #:tlsdesc_lo12:var] => movk x0, :tprel_g0_nc:var | |
2d0ca824 YN |
5846 | |
5847 | Where R is x for lp64 mode, and w for ILP32 mode. */ | |
5848 | bfd_putl32 (movk_R0, contents + rel->r_offset); | |
a06ea964 NC |
5849 | return bfd_reloc_continue; |
5850 | } | |
5851 | else | |
5852 | { | |
5853 | /* GD->IE relaxation: | |
2d0ca824 YN |
5854 | ldr xd, [x0, #:tlsdesc_lo12:var] => ldr R0, [x0, #:gottprel_lo12:var] |
5855 | ||
5856 | Where R is x for lp64 mode, and w for ILP32 mode. */ | |
a06ea964 | 5857 | insn = bfd_getl32 (contents + rel->r_offset); |
2d0ca824 | 5858 | bfd_putl32 (ldr_R0_mask (insn), contents + rel->r_offset); |
a06ea964 NC |
5859 | return bfd_reloc_continue; |
5860 | } | |
5861 | ||
a6bb11b2 | 5862 | case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC: |
a06ea964 NC |
5863 | if (is_local) |
5864 | { | |
5865 | /* GD->LE relaxation | |
2d0ca824 | 5866 | add x0, #:tlsgd_lo12:var => movk R0, :tprel_g0_nc:var |
a06ea964 | 5867 | bl __tls_get_addr => mrs x1, tpidr_el0 |
2d0ca824 YN |
5868 | nop => add R0, R1, R0 |
5869 | ||
5870 | Where R is x for lp64 mode, and w for ILP32 mode. */ | |
a06ea964 NC |
5871 | |
5872 | /* First kill the tls_get_addr reloc on the bl instruction. */ | |
5873 | BFD_ASSERT (rel->r_offset + 4 == rel[1].r_offset); | |
cec5225b | 5874 | rel[1].r_info = ELFNN_R_INFO (STN_UNDEF, R_AARCH64_NONE); |
a06ea964 | 5875 | |
2d0ca824 | 5876 | bfd_putl32 (movk_R0, contents + rel->r_offset); |
a06ea964 | 5877 | bfd_putl32 (0xd53bd041, contents + rel->r_offset + 4); |
2d0ca824 | 5878 | bfd_putl32 (add_R0_R0_R1, contents + rel->r_offset + 8); |
a06ea964 NC |
5879 | return bfd_reloc_continue; |
5880 | } | |
5881 | else | |
5882 | { | |
5883 | /* GD->IE relaxation | |
5cd1d8bc | 5884 | ADD x0, #:tlsgd_lo12:var => ldr R0, [x0, #:gottprel_lo12:var] |
a06ea964 NC |
5885 | BL __tls_get_addr => mrs x1, tpidr_el0 |
5886 | R_AARCH64_CALL26 | |
5cd1d8bc YN |
5887 | NOP => add R0, R1, R0 |
5888 | ||
5889 | Where R is x for lp64 mode, and w for ilp32 mode. */ | |
a06ea964 | 5890 | |
a6bb11b2 | 5891 | BFD_ASSERT (ELFNN_R_TYPE (rel[1].r_info) == AARCH64_R (CALL26)); |
a06ea964 NC |
5892 | |
5893 | /* Remove the relocation on the BL instruction. */ | |
cec5225b | 5894 | rel[1].r_info = ELFNN_R_INFO (STN_UNDEF, R_AARCH64_NONE); |
a06ea964 | 5895 | |
a06ea964 NC |
5896 | /* We choose to fixup the BL and NOP instructions using the |
5897 | offset from the second relocation to allow flexibility in | |
5898 | scheduling instructions between the ADD and BL. */ | |
2d0ca824 | 5899 | bfd_putl32 (ldr_R0_x0, contents + rel->r_offset); |
5cd1d8bc | 5900 | bfd_putl32 (0xd53bd041, contents + rel[1].r_offset); |
2d0ca824 | 5901 | bfd_putl32 (add_R0_R0_R1, contents + rel[1].r_offset + 4); |
a06ea964 NC |
5902 | return bfd_reloc_continue; |
5903 | } | |
5904 | ||
0484b454 | 5905 | case BFD_RELOC_AARCH64_TLSDESC_ADD: |
f955cccf | 5906 | case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12: |
a6bb11b2 | 5907 | case BFD_RELOC_AARCH64_TLSDESC_CALL: |
a06ea964 NC |
5908 | /* GD->IE/LE relaxation: |
5909 | add x0, x0, #:tlsdesc_lo12:var => nop | |
5910 | blr xd => nop | |
5911 | */ | |
5912 | bfd_putl32 (INSN_NOP, contents + rel->r_offset); | |
5913 | return bfd_reloc_ok; | |
5914 | ||
0484b454 RL |
5915 | case BFD_RELOC_AARCH64_TLSDESC_LDR: |
5916 | if (is_local) | |
5917 | { | |
5918 | /* GD->LE relaxation: | |
2d0ca824 YN |
5919 | ldr xd, [gp, xn] => movk R0, #:tprel_g0_nc:var |
5920 | ||
5921 | Where R is x for lp64 mode, and w for ILP32 mode. */ | |
5922 | bfd_putl32 (movk_R0, contents + rel->r_offset); | |
0484b454 RL |
5923 | return bfd_reloc_continue; |
5924 | } | |
5925 | else | |
5926 | { | |
5927 | /* GD->IE relaxation: | |
2d0ca824 YN |
5928 | ldr xd, [gp, xn] => ldr R0, [gp, xn] |
5929 | ||
5930 | Where R is x for lp64 mode, and w for ILP32 mode. */ | |
0484b454 | 5931 | insn = bfd_getl32 (contents + rel->r_offset); |
2d0ca824 | 5932 | bfd_putl32 (ldr_R0_mask (insn), contents + rel->r_offset); |
0484b454 RL |
5933 | return bfd_reloc_ok; |
5934 | } | |
5935 | ||
5936 | case BFD_RELOC_AARCH64_TLSDESC_OFF_G0_NC: | |
5937 | /* GD->LE relaxation: | |
2d0ca824 | 5938 | movk xd, #:tlsdesc_off_g0_nc:var => movk R0, #:tprel_g1_nc:var, lsl #16 |
0484b454 | 5939 | GD->IE relaxation: |
2d0ca824 YN |
5940 | movk xd, #:tlsdesc_off_g0_nc:var => movk Rd, #:gottprel_g0_nc:var |
5941 | ||
5942 | Where R is x for lp64 mode, and w for ILP32 mode. */ | |
0484b454 | 5943 | if (is_local) |
2d0ca824 | 5944 | bfd_putl32 (ldr_hw_R0, contents + rel->r_offset); |
0484b454 RL |
5945 | return bfd_reloc_continue; |
5946 | ||
5947 | case BFD_RELOC_AARCH64_TLSDESC_OFF_G1: | |
5948 | if (is_local) | |
5949 | { | |
5950 | /* GD->LE relaxation: | |
2d0ca824 YN |
5951 | movz xd, #:tlsdesc_off_g1:var => movz R0, #:tprel_g2:var, lsl #32 |
5952 | ||
5953 | Where R is x for lp64 mode, and w for ILP32 mode. */ | |
5954 | bfd_putl32 (movz_hw_R0, contents + rel->r_offset); | |
0484b454 RL |
5955 | return bfd_reloc_continue; |
5956 | } | |
5957 | else | |
5958 | { | |
5959 | /* GD->IE relaxation: | |
2d0ca824 YN |
5960 | movz xd, #:tlsdesc_off_g1:var => movz Rd, #:gottprel_g1:var, lsl #16 |
5961 | ||
5962 | Where R is x for lp64 mode, and w for ILP32 mode. */ | |
0484b454 | 5963 | insn = bfd_getl32 (contents + rel->r_offset); |
2d0ca824 | 5964 | bfd_putl32 (movz_R0 | (insn & 0x1f), contents + rel->r_offset); |
0484b454 RL |
5965 | return bfd_reloc_continue; |
5966 | } | |
5967 | ||
a6bb11b2 | 5968 | case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21: |
a06ea964 | 5969 | /* IE->LE relaxation: |
2d0ca824 YN |
5970 | adrp xd, :gottprel:var => movz Rd, :tprel_g1:var |
5971 | ||
5972 | Where R is x for lp64 mode, and w for ILP32 mode. */ | |
a06ea964 NC |
5973 | if (is_local) |
5974 | { | |
5975 | insn = bfd_getl32 (contents + rel->r_offset); | |
2d0ca824 | 5976 | bfd_putl32 (movz_R0 | (insn & 0x1f), contents + rel->r_offset); |
a06ea964 NC |
5977 | } |
5978 | return bfd_reloc_continue; | |
5979 | ||
a6bb11b2 | 5980 | case BFD_RELOC_AARCH64_TLSIE_LDNN_GOTTPREL_LO12_NC: |
a06ea964 | 5981 | /* IE->LE relaxation: |
2d0ca824 YN |
5982 | ldr xd, [xm, #:gottprel_lo12:var] => movk Rd, :tprel_g0_nc:var |
5983 | ||
5984 | Where R is x for lp64 mode, and w for ILP32 mode. */ | |
a06ea964 NC |
5985 | if (is_local) |
5986 | { | |
5987 | insn = bfd_getl32 (contents + rel->r_offset); | |
2d0ca824 | 5988 | bfd_putl32 (movk_R0 | (insn & 0x1f), contents + rel->r_offset); |
a06ea964 NC |
5989 | } |
5990 | return bfd_reloc_continue; | |
5991 | ||
259364ad JW |
5992 | case BFD_RELOC_AARCH64_TLSLD_ADR_PREL21: |
5993 | /* LD->LE relaxation (tiny): | |
5994 | adr x0, :tlsldm:x => mrs x0, tpidr_el0 | |
c1fc2d7e YN |
5995 | bl __tls_get_addr => add R0, R0, TCB_SIZE |
5996 | ||
5997 | Where R is x for lp64 mode, and w for ilp32 mode. */ | |
259364ad JW |
5998 | if (is_local) |
5999 | { | |
6000 | BFD_ASSERT (rel->r_offset + 4 == rel[1].r_offset); | |
6001 | BFD_ASSERT (ELFNN_R_TYPE (rel[1].r_info) == AARCH64_R (CALL26)); | |
6002 | /* No need of CALL26 relocation for tls_get_addr. */ | |
6003 | rel[1].r_info = ELFNN_R_INFO (STN_UNDEF, R_AARCH64_NONE); | |
6004 | bfd_putl32 (0xd53bd040, contents + rel->r_offset + 0); | |
2d0ca824 YN |
6005 | bfd_putl32 (add_R0_R0 | (TCB_SIZE << 10), |
6006 | contents + rel->r_offset + 4); | |
259364ad JW |
6007 | return bfd_reloc_ok; |
6008 | } | |
6009 | return bfd_reloc_continue; | |
6010 | ||
6011 | case BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21: | |
6012 | /* LD->LE relaxation (small): | |
6013 | adrp x0, :tlsldm:x => mrs x0, tpidr_el0 | |
6014 | */ | |
6015 | if (is_local) | |
6016 | { | |
6017 | bfd_putl32 (0xd53bd040, contents + rel->r_offset); | |
6018 | return bfd_reloc_ok; | |
6019 | } | |
6020 | return bfd_reloc_continue; | |
6021 | ||
6022 | case BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC: | |
6023 | /* LD->LE relaxation (small): | |
c1fc2d7e | 6024 | add x0, #:tlsldm_lo12:x => add R0, R0, TCB_SIZE |
259364ad | 6025 | bl __tls_get_addr => nop |
c1fc2d7e YN |
6026 | |
6027 | Where R is x for lp64 mode, and w for ilp32 mode. */ | |
259364ad JW |
6028 | if (is_local) |
6029 | { | |
6030 | BFD_ASSERT (rel->r_offset + 4 == rel[1].r_offset); | |
6031 | BFD_ASSERT (ELFNN_R_TYPE (rel[1].r_info) == AARCH64_R (CALL26)); | |
6032 | /* No need of CALL26 relocation for tls_get_addr. */ | |
6033 | rel[1].r_info = ELFNN_R_INFO (STN_UNDEF, R_AARCH64_NONE); | |
2d0ca824 YN |
6034 | bfd_putl32 (add_R0_R0 | (TCB_SIZE << 10), |
6035 | contents + rel->r_offset + 0); | |
c1fc2d7e | 6036 | bfd_putl32 (INSN_NOP, contents + rel->r_offset + 4); |
259364ad JW |
6037 | return bfd_reloc_ok; |
6038 | } | |
6039 | return bfd_reloc_continue; | |
6040 | ||
a06ea964 NC |
6041 | default: |
6042 | return bfd_reloc_continue; | |
6043 | } | |
6044 | ||
6045 | return bfd_reloc_ok; | |
6046 | } | |
6047 | ||
6048 | /* Relocate an AArch64 ELF section. */ | |
6049 | ||
6050 | static bfd_boolean | |
cec5225b | 6051 | elfNN_aarch64_relocate_section (bfd *output_bfd, |
a06ea964 NC |
6052 | struct bfd_link_info *info, |
6053 | bfd *input_bfd, | |
6054 | asection *input_section, | |
6055 | bfd_byte *contents, | |
6056 | Elf_Internal_Rela *relocs, | |
6057 | Elf_Internal_Sym *local_syms, | |
6058 | asection **local_sections) | |
6059 | { | |
6060 | Elf_Internal_Shdr *symtab_hdr; | |
6061 | struct elf_link_hash_entry **sym_hashes; | |
6062 | Elf_Internal_Rela *rel; | |
6063 | Elf_Internal_Rela *relend; | |
6064 | const char *name; | |
cec5225b | 6065 | struct elf_aarch64_link_hash_table *globals; |
a06ea964 NC |
6066 | bfd_boolean save_addend = FALSE; |
6067 | bfd_vma addend = 0; | |
6068 | ||
cec5225b | 6069 | globals = elf_aarch64_hash_table (info); |
a06ea964 NC |
6070 | |
6071 | symtab_hdr = &elf_symtab_hdr (input_bfd); | |
6072 | sym_hashes = elf_sym_hashes (input_bfd); | |
6073 | ||
6074 | rel = relocs; | |
6075 | relend = relocs + input_section->reloc_count; | |
6076 | for (; rel < relend; rel++) | |
6077 | { | |
6078 | unsigned int r_type; | |
a6bb11b2 YZ |
6079 | bfd_reloc_code_real_type bfd_r_type; |
6080 | bfd_reloc_code_real_type relaxed_bfd_r_type; | |
a06ea964 NC |
6081 | reloc_howto_type *howto; |
6082 | unsigned long r_symndx; | |
6083 | Elf_Internal_Sym *sym; | |
6084 | asection *sec; | |
6085 | struct elf_link_hash_entry *h; | |
6086 | bfd_vma relocation; | |
6087 | bfd_reloc_status_type r; | |
6088 | arelent bfd_reloc; | |
6089 | char sym_type; | |
6090 | bfd_boolean unresolved_reloc = FALSE; | |
6091 | char *error_message = NULL; | |
6092 | ||
cec5225b YZ |
6093 | r_symndx = ELFNN_R_SYM (rel->r_info); |
6094 | r_type = ELFNN_R_TYPE (rel->r_info); | |
a06ea964 | 6095 | |
47aeb64c | 6096 | howto = bfd_reloc.howto = elfNN_aarch64_howto_from_type (r_type); |
a06ea964 | 6097 | |
7fcfd62d | 6098 | if (howto == NULL) |
47aeb64c NC |
6099 | return _bfd_unrecognized_reloc (input_bfd, input_section, r_type); |
6100 | ||
a6bb11b2 | 6101 | bfd_r_type = elfNN_aarch64_bfd_reloc_from_howto (howto); |
7fcfd62d | 6102 | |
a06ea964 NC |
6103 | h = NULL; |
6104 | sym = NULL; | |
6105 | sec = NULL; | |
6106 | ||
6107 | if (r_symndx < symtab_hdr->sh_info) | |
6108 | { | |
6109 | sym = local_syms + r_symndx; | |
cec5225b | 6110 | sym_type = ELFNN_ST_TYPE (sym->st_info); |
a06ea964 NC |
6111 | sec = local_sections[r_symndx]; |
6112 | ||
6113 | /* An object file might have a reference to a local | |
6114 | undefined symbol. This is a daft object file, but we | |
6115 | should at least do something about it. */ | |
6116 | if (r_type != R_AARCH64_NONE && r_type != R_AARCH64_NULL | |
6117 | && bfd_is_und_section (sec) | |
6118 | && ELF_ST_BIND (sym->st_info) != STB_WEAK) | |
1a72702b AM |
6119 | (*info->callbacks->undefined_symbol) |
6120 | (info, bfd_elf_string_from_elf_section | |
6121 | (input_bfd, symtab_hdr->sh_link, sym->st_name), | |
6122 | input_bfd, input_section, rel->r_offset, TRUE); | |
a06ea964 | 6123 | |
a06ea964 | 6124 | relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel); |
1419bbe5 WN |
6125 | |
6126 | /* Relocate against local STT_GNU_IFUNC symbol. */ | |
0e1862bb | 6127 | if (!bfd_link_relocatable (info) |
1419bbe5 WN |
6128 | && ELF_ST_TYPE (sym->st_info) == STT_GNU_IFUNC) |
6129 | { | |
6130 | h = elfNN_aarch64_get_local_sym_hash (globals, input_bfd, | |
6131 | rel, FALSE); | |
6132 | if (h == NULL) | |
6133 | abort (); | |
6134 | ||
6135 | /* Set STT_GNU_IFUNC symbol value. */ | |
6136 | h->root.u.def.value = sym->st_value; | |
6137 | h->root.u.def.section = sec; | |
6138 | } | |
a06ea964 NC |
6139 | } |
6140 | else | |
6141 | { | |
62d887d4 | 6142 | bfd_boolean warned, ignored; |
a06ea964 NC |
6143 | |
6144 | RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel, | |
6145 | r_symndx, symtab_hdr, sym_hashes, | |
6146 | h, sec, relocation, | |
62d887d4 | 6147 | unresolved_reloc, warned, ignored); |
a06ea964 NC |
6148 | |
6149 | sym_type = h->type; | |
6150 | } | |
6151 | ||
6152 | if (sec != NULL && discarded_section (sec)) | |
6153 | RELOC_AGAINST_DISCARDED_SECTION (info, input_bfd, input_section, | |
6154 | rel, 1, relend, howto, 0, contents); | |
6155 | ||
0e1862bb | 6156 | if (bfd_link_relocatable (info)) |
2e0488d3 | 6157 | continue; |
a06ea964 NC |
6158 | |
6159 | if (h != NULL) | |
6160 | name = h->root.root.string; | |
6161 | else | |
6162 | { | |
6163 | name = (bfd_elf_string_from_elf_section | |
6164 | (input_bfd, symtab_hdr->sh_link, sym->st_name)); | |
6165 | if (name == NULL || *name == '\0') | |
6166 | name = bfd_section_name (input_bfd, sec); | |
6167 | } | |
6168 | ||
6169 | if (r_symndx != 0 | |
6170 | && r_type != R_AARCH64_NONE | |
6171 | && r_type != R_AARCH64_NULL | |
6172 | && (h == NULL | |
6173 | || h->root.type == bfd_link_hash_defined | |
6174 | || h->root.type == bfd_link_hash_defweak) | |
a6bb11b2 | 6175 | && IS_AARCH64_TLS_RELOC (bfd_r_type) != (sym_type == STT_TLS)) |
a06ea964 | 6176 | { |
4eca0228 | 6177 | _bfd_error_handler |
a06ea964 | 6178 | ((sym_type == STT_TLS |
695344c0 | 6179 | /* xgettext:c-format */ |
d42c267e | 6180 | ? _("%B(%A+%#Lx): %s used with TLS symbol %s") |
695344c0 | 6181 | /* xgettext:c-format */ |
d42c267e | 6182 | : _("%B(%A+%#Lx): %s used with non-TLS symbol %s")), |
a06ea964 | 6183 | input_bfd, |
d42c267e | 6184 | input_section, rel->r_offset, howto->name, name); |
a06ea964 NC |
6185 | } |
6186 | ||
a06ea964 NC |
6187 | /* We relax only if we can see that there can be a valid transition |
6188 | from a reloc type to another. | |
cec5225b | 6189 | We call elfNN_aarch64_final_link_relocate unless we're completely |
a06ea964 NC |
6190 | done, i.e., the relaxation produced the final output we want. */ |
6191 | ||
a6bb11b2 YZ |
6192 | relaxed_bfd_r_type = aarch64_tls_transition (input_bfd, info, r_type, |
6193 | h, r_symndx); | |
6194 | if (relaxed_bfd_r_type != bfd_r_type) | |
a06ea964 | 6195 | { |
a6bb11b2 YZ |
6196 | bfd_r_type = relaxed_bfd_r_type; |
6197 | howto = elfNN_aarch64_howto_from_bfd_reloc (bfd_r_type); | |
6198 | BFD_ASSERT (howto != NULL); | |
6199 | r_type = howto->type; | |
06d2788c | 6200 | r = elfNN_aarch64_tls_relax (globals, input_bfd, contents, rel, h); |
a06ea964 NC |
6201 | unresolved_reloc = 0; |
6202 | } | |
6203 | else | |
6204 | r = bfd_reloc_continue; | |
6205 | ||
6206 | /* There may be multiple consecutive relocations for the | |
6207 | same offset. In that case we are supposed to treat the | |
6208 | output of each relocation as the addend for the next. */ | |
6209 | if (rel + 1 < relend | |
6210 | && rel->r_offset == rel[1].r_offset | |
cec5225b YZ |
6211 | && ELFNN_R_TYPE (rel[1].r_info) != R_AARCH64_NONE |
6212 | && ELFNN_R_TYPE (rel[1].r_info) != R_AARCH64_NULL) | |
a06ea964 NC |
6213 | save_addend = TRUE; |
6214 | else | |
6215 | save_addend = FALSE; | |
6216 | ||
6217 | if (r == bfd_reloc_continue) | |
cec5225b | 6218 | r = elfNN_aarch64_final_link_relocate (howto, input_bfd, output_bfd, |
a06ea964 NC |
6219 | input_section, contents, rel, |
6220 | relocation, info, sec, | |
6221 | h, &unresolved_reloc, | |
1419bbe5 | 6222 | save_addend, &addend, sym); |
a06ea964 | 6223 | |
a6bb11b2 | 6224 | switch (elfNN_aarch64_bfd_reloc_from_type (r_type)) |
a06ea964 | 6225 | { |
ce336788 | 6226 | case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC: |
a6bb11b2 | 6227 | case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21: |
3c12b054 | 6228 | case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21: |
7ba7cfe4 | 6229 | case BFD_RELOC_AARCH64_TLSGD_MOVW_G0_NC: |
94facae3 | 6230 | case BFD_RELOC_AARCH64_TLSGD_MOVW_G1: |
73f925cc | 6231 | case BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC: |
f69e4920 | 6232 | case BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21: |
77a69ff8 | 6233 | case BFD_RELOC_AARCH64_TLSLD_ADR_PREL21: |
a06ea964 NC |
6234 | if (! symbol_got_offset_mark_p (input_bfd, h, r_symndx)) |
6235 | { | |
6236 | bfd_boolean need_relocs = FALSE; | |
6237 | bfd_byte *loc; | |
6238 | int indx; | |
6239 | bfd_vma off; | |
6240 | ||
6241 | off = symbol_got_offset (input_bfd, h, r_symndx); | |
6242 | indx = h && h->dynindx != -1 ? h->dynindx : 0; | |
6243 | ||
6244 | need_relocs = | |
0e1862bb | 6245 | (bfd_link_pic (info) || indx != 0) && |
a06ea964 NC |
6246 | (h == NULL |
6247 | || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT | |
6248 | || h->root.type != bfd_link_hash_undefweak); | |
6249 | ||
6250 | BFD_ASSERT (globals->root.srelgot != NULL); | |
6251 | ||
6252 | if (need_relocs) | |
6253 | { | |
6254 | Elf_Internal_Rela rela; | |
a6bb11b2 | 6255 | rela.r_info = ELFNN_R_INFO (indx, AARCH64_R (TLS_DTPMOD)); |
a06ea964 NC |
6256 | rela.r_addend = 0; |
6257 | rela.r_offset = globals->root.sgot->output_section->vma + | |
6258 | globals->root.sgot->output_offset + off; | |
6259 | ||
6260 | ||
6261 | loc = globals->root.srelgot->contents; | |
6262 | loc += globals->root.srelgot->reloc_count++ | |
6263 | * RELOC_SIZE (htab); | |
cec5225b | 6264 | bfd_elfNN_swap_reloca_out (output_bfd, &rela, loc); |
a06ea964 | 6265 | |
f69e4920 JW |
6266 | bfd_reloc_code_real_type real_type = |
6267 | elfNN_aarch64_bfd_reloc_from_type (r_type); | |
6268 | ||
6269 | if (real_type == BFD_RELOC_AARCH64_TLSLD_ADR_PREL21 | |
73f925cc JW |
6270 | || real_type == BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21 |
6271 | || real_type == BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC) | |
77a69ff8 JW |
6272 | { |
6273 | /* For local dynamic, don't generate DTPREL in any case. | |
6274 | Initialize the DTPREL slot into zero, so we get module | |
6275 | base address when invoke runtime TLS resolver. */ | |
6276 | bfd_put_NN (output_bfd, 0, | |
6277 | globals->root.sgot->contents + off | |
6278 | + GOT_ENTRY_SIZE); | |
6279 | } | |
6280 | else if (indx == 0) | |
a06ea964 | 6281 | { |
cec5225b | 6282 | bfd_put_NN (output_bfd, |
a06ea964 NC |
6283 | relocation - dtpoff_base (info), |
6284 | globals->root.sgot->contents + off | |
6285 | + GOT_ENTRY_SIZE); | |
6286 | } | |
6287 | else | |
6288 | { | |
6289 | /* This TLS symbol is global. We emit a | |
6290 | relocation to fixup the tls offset at load | |
6291 | time. */ | |
6292 | rela.r_info = | |
a6bb11b2 | 6293 | ELFNN_R_INFO (indx, AARCH64_R (TLS_DTPREL)); |
a06ea964 NC |
6294 | rela.r_addend = 0; |
6295 | rela.r_offset = | |
6296 | (globals->root.sgot->output_section->vma | |
6297 | + globals->root.sgot->output_offset + off | |
6298 | + GOT_ENTRY_SIZE); | |
6299 | ||
6300 | loc = globals->root.srelgot->contents; | |
6301 | loc += globals->root.srelgot->reloc_count++ | |
6302 | * RELOC_SIZE (globals); | |
cec5225b YZ |
6303 | bfd_elfNN_swap_reloca_out (output_bfd, &rela, loc); |
6304 | bfd_put_NN (output_bfd, (bfd_vma) 0, | |
a06ea964 NC |
6305 | globals->root.sgot->contents + off |
6306 | + GOT_ENTRY_SIZE); | |
6307 | } | |
6308 | } | |
6309 | else | |
6310 | { | |
cec5225b | 6311 | bfd_put_NN (output_bfd, (bfd_vma) 1, |
a06ea964 | 6312 | globals->root.sgot->contents + off); |
cec5225b | 6313 | bfd_put_NN (output_bfd, |
a06ea964 NC |
6314 | relocation - dtpoff_base (info), |
6315 | globals->root.sgot->contents + off | |
6316 | + GOT_ENTRY_SIZE); | |
6317 | } | |
6318 | ||
6319 | symbol_got_offset_mark (input_bfd, h, r_symndx); | |
6320 | } | |
6321 | break; | |
6322 | ||
a6bb11b2 YZ |
6323 | case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21: |
6324 | case BFD_RELOC_AARCH64_TLSIE_LDNN_GOTTPREL_LO12_NC: | |
043bf05a | 6325 | case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19: |
3b957e5b RL |
6326 | case BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G0_NC: |
6327 | case BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G1: | |
a06ea964 NC |
6328 | if (! symbol_got_offset_mark_p (input_bfd, h, r_symndx)) |
6329 | { | |
6330 | bfd_boolean need_relocs = FALSE; | |
6331 | bfd_byte *loc; | |
6332 | int indx; | |
6333 | bfd_vma off; | |
6334 | ||
6335 | off = symbol_got_offset (input_bfd, h, r_symndx); | |
6336 | ||
6337 | indx = h && h->dynindx != -1 ? h->dynindx : 0; | |
6338 | ||
6339 | need_relocs = | |
0e1862bb | 6340 | (bfd_link_pic (info) || indx != 0) && |
a06ea964 NC |
6341 | (h == NULL |
6342 | || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT | |
6343 | || h->root.type != bfd_link_hash_undefweak); | |
6344 | ||
6345 | BFD_ASSERT (globals->root.srelgot != NULL); | |
6346 | ||
6347 | if (need_relocs) | |
6348 | { | |
6349 | Elf_Internal_Rela rela; | |
6350 | ||
6351 | if (indx == 0) | |
6352 | rela.r_addend = relocation - dtpoff_base (info); | |
6353 | else | |
6354 | rela.r_addend = 0; | |
6355 | ||
a6bb11b2 | 6356 | rela.r_info = ELFNN_R_INFO (indx, AARCH64_R (TLS_TPREL)); |
a06ea964 NC |
6357 | rela.r_offset = globals->root.sgot->output_section->vma + |
6358 | globals->root.sgot->output_offset + off; | |
6359 | ||
6360 | loc = globals->root.srelgot->contents; | |
6361 | loc += globals->root.srelgot->reloc_count++ | |
6362 | * RELOC_SIZE (htab); | |
6363 | ||
cec5225b | 6364 | bfd_elfNN_swap_reloca_out (output_bfd, &rela, loc); |
a06ea964 | 6365 | |
cec5225b | 6366 | bfd_put_NN (output_bfd, rela.r_addend, |
a06ea964 NC |
6367 | globals->root.sgot->contents + off); |
6368 | } | |
6369 | else | |
cec5225b | 6370 | bfd_put_NN (output_bfd, relocation - tpoff_base (info), |
a06ea964 NC |
6371 | globals->root.sgot->contents + off); |
6372 | ||
6373 | symbol_got_offset_mark (input_bfd, h, r_symndx); | |
6374 | } | |
6375 | break; | |
6376 | ||
f955cccf | 6377 | case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12: |
a6bb11b2 | 6378 | case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21: |
389b8029 | 6379 | case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21: |
a6bb11b2 | 6380 | case BFD_RELOC_AARCH64_TLSDESC_LDNN_LO12_NC: |
1ada945d | 6381 | case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19: |
0484b454 RL |
6382 | case BFD_RELOC_AARCH64_TLSDESC_OFF_G0_NC: |
6383 | case BFD_RELOC_AARCH64_TLSDESC_OFF_G1: | |
a06ea964 NC |
6384 | if (! symbol_tlsdesc_got_offset_mark_p (input_bfd, h, r_symndx)) |
6385 | { | |
6386 | bfd_boolean need_relocs = FALSE; | |
6387 | int indx = h && h->dynindx != -1 ? h->dynindx : 0; | |
6388 | bfd_vma off = symbol_tlsdesc_got_offset (input_bfd, h, r_symndx); | |
6389 | ||
6390 | need_relocs = (h == NULL | |
6391 | || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT | |
6392 | || h->root.type != bfd_link_hash_undefweak); | |
6393 | ||
6394 | BFD_ASSERT (globals->root.srelgot != NULL); | |
6395 | BFD_ASSERT (globals->root.sgot != NULL); | |
6396 | ||
6397 | if (need_relocs) | |
6398 | { | |
6399 | bfd_byte *loc; | |
6400 | Elf_Internal_Rela rela; | |
a6bb11b2 YZ |
6401 | rela.r_info = ELFNN_R_INFO (indx, AARCH64_R (TLSDESC)); |
6402 | ||
a06ea964 NC |
6403 | rela.r_addend = 0; |
6404 | rela.r_offset = (globals->root.sgotplt->output_section->vma | |
6405 | + globals->root.sgotplt->output_offset | |
6406 | + off + globals->sgotplt_jump_table_size); | |
6407 | ||
6408 | if (indx == 0) | |
6409 | rela.r_addend = relocation - dtpoff_base (info); | |
6410 | ||
6411 | /* Allocate the next available slot in the PLT reloc | |
6412 | section to hold our R_AARCH64_TLSDESC, the next | |
6413 | available slot is determined from reloc_count, | |
6414 | which we step. But note, reloc_count was | |
6415 | artifically moved down while allocating slots for | |
6416 | real PLT relocs such that all of the PLT relocs | |
6417 | will fit above the initial reloc_count and the | |
6418 | extra stuff will fit below. */ | |
6419 | loc = globals->root.srelplt->contents; | |
6420 | loc += globals->root.srelplt->reloc_count++ | |
6421 | * RELOC_SIZE (globals); | |
6422 | ||
cec5225b | 6423 | bfd_elfNN_swap_reloca_out (output_bfd, &rela, loc); |
a06ea964 | 6424 | |
cec5225b | 6425 | bfd_put_NN (output_bfd, (bfd_vma) 0, |
a06ea964 NC |
6426 | globals->root.sgotplt->contents + off + |
6427 | globals->sgotplt_jump_table_size); | |
cec5225b | 6428 | bfd_put_NN (output_bfd, (bfd_vma) 0, |
a06ea964 NC |
6429 | globals->root.sgotplt->contents + off + |
6430 | globals->sgotplt_jump_table_size + | |
6431 | GOT_ENTRY_SIZE); | |
6432 | } | |
6433 | ||
6434 | symbol_tlsdesc_got_offset_mark (input_bfd, h, r_symndx); | |
6435 | } | |
6436 | break; | |
a6bb11b2 YZ |
6437 | default: |
6438 | break; | |
a06ea964 NC |
6439 | } |
6440 | ||
a06ea964 NC |
6441 | /* Dynamic relocs are not propagated for SEC_DEBUGGING sections |
6442 | because such sections are not SEC_ALLOC and thus ld.so will | |
6443 | not process them. */ | |
6444 | if (unresolved_reloc | |
6445 | && !((input_section->flags & SEC_DEBUGGING) != 0 | |
6446 | && h->def_dynamic) | |
6447 | && _bfd_elf_section_offset (output_bfd, info, input_section, | |
6448 | +rel->r_offset) != (bfd_vma) - 1) | |
6449 | { | |
4eca0228 | 6450 | _bfd_error_handler |
695344c0 | 6451 | /* xgettext:c-format */ |
d42c267e AM |
6452 | (_("%B(%A+%#Lx): unresolvable %s relocation against symbol `%s'"), |
6453 | input_bfd, input_section, rel->r_offset, howto->name, | |
a06ea964 NC |
6454 | h->root.root.string); |
6455 | return FALSE; | |
6456 | } | |
6457 | ||
6458 | if (r != bfd_reloc_ok && r != bfd_reloc_continue) | |
6459 | { | |
c674f5cd JW |
6460 | bfd_reloc_code_real_type real_r_type |
6461 | = elfNN_aarch64_bfd_reloc_from_type (r_type); | |
6462 | ||
a06ea964 NC |
6463 | switch (r) |
6464 | { | |
6465 | case bfd_reloc_overflow: | |
1a72702b AM |
6466 | (*info->callbacks->reloc_overflow) |
6467 | (info, (h ? &h->root : NULL), name, howto->name, (bfd_vma) 0, | |
6468 | input_bfd, input_section, rel->r_offset); | |
c674f5cd JW |
6469 | if (real_r_type == BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15 |
6470 | || real_r_type == BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14) | |
6471 | { | |
6472 | (*info->callbacks->warning) | |
6473 | (info, | |
6474 | _("Too many GOT entries for -fpic, " | |
6475 | "please recompile with -fPIC"), | |
6476 | name, input_bfd, input_section, rel->r_offset); | |
6477 | return FALSE; | |
6478 | } | |
027e9c75 NC |
6479 | /* Overflow can occur when a variable is referenced with a type |
6480 | that has a larger alignment than the type with which it was | |
6481 | declared. eg: | |
6482 | file1.c: extern int foo; int a (void) { return foo; } | |
6483 | file2.c: char bar, foo, baz; | |
6484 | If the variable is placed into a data section at an offset | |
6485 | that is incompatible with the larger alignment requirement | |
6486 | overflow will occur. (Strictly speaking this is not overflow | |
6487 | but rather an alignment problem, but the bfd_reloc_ error | |
6488 | enum does not have a value to cover that situation). | |
6489 | ||
6490 | Try to catch this situation here and provide a more helpful | |
6491 | error message to the user. */ | |
6492 | if (addend & ((1 << howto->rightshift) - 1) | |
6493 | /* FIXME: Are we testing all of the appropriate reloc | |
6494 | types here ? */ | |
6495 | && (real_r_type == BFD_RELOC_AARCH64_LD_LO19_PCREL | |
6496 | || real_r_type == BFD_RELOC_AARCH64_LDST16_LO12 | |
6497 | || real_r_type == BFD_RELOC_AARCH64_LDST32_LO12 | |
6498 | || real_r_type == BFD_RELOC_AARCH64_LDST64_LO12 | |
6499 | || real_r_type == BFD_RELOC_AARCH64_LDST128_LO12)) | |
6500 | { | |
6501 | info->callbacks->warning | |
6502 | (info, _("One possible cause of this error is that the \ | |
6503 | symbol is being referenced in the indicated code as if it had a larger \ | |
6504 | alignment than was declared where it was defined."), | |
6505 | name, input_bfd, input_section, rel->r_offset); | |
6506 | } | |
a06ea964 NC |
6507 | break; |
6508 | ||
6509 | case bfd_reloc_undefined: | |
1a72702b AM |
6510 | (*info->callbacks->undefined_symbol) |
6511 | (info, name, input_bfd, input_section, rel->r_offset, TRUE); | |
a06ea964 NC |
6512 | break; |
6513 | ||
6514 | case bfd_reloc_outofrange: | |
6515 | error_message = _("out of range"); | |
6516 | goto common_error; | |
6517 | ||
6518 | case bfd_reloc_notsupported: | |
6519 | error_message = _("unsupported relocation"); | |
6520 | goto common_error; | |
6521 | ||
6522 | case bfd_reloc_dangerous: | |
6523 | /* error_message should already be set. */ | |
6524 | goto common_error; | |
6525 | ||
6526 | default: | |
6527 | error_message = _("unknown error"); | |
6528 | /* Fall through. */ | |
6529 | ||
6530 | common_error: | |
6531 | BFD_ASSERT (error_message != NULL); | |
1a72702b AM |
6532 | (*info->callbacks->reloc_dangerous) |
6533 | (info, error_message, input_bfd, input_section, rel->r_offset); | |
a06ea964 NC |
6534 | break; |
6535 | } | |
6536 | } | |
027e9c75 NC |
6537 | |
6538 | if (!save_addend) | |
6539 | addend = 0; | |
a06ea964 NC |
6540 | } |
6541 | ||
6542 | return TRUE; | |
6543 | } | |
6544 | ||
6545 | /* Set the right machine number. */ | |
6546 | ||
6547 | static bfd_boolean | |
cec5225b | 6548 | elfNN_aarch64_object_p (bfd *abfd) |
a06ea964 | 6549 | { |
cec5225b YZ |
6550 | #if ARCH_SIZE == 32 |
6551 | bfd_default_set_arch_mach (abfd, bfd_arch_aarch64, bfd_mach_aarch64_ilp32); | |
6552 | #else | |
a06ea964 | 6553 | bfd_default_set_arch_mach (abfd, bfd_arch_aarch64, bfd_mach_aarch64); |
cec5225b | 6554 | #endif |
a06ea964 NC |
6555 | return TRUE; |
6556 | } | |
6557 | ||
6558 | /* Function to keep AArch64 specific flags in the ELF header. */ | |
6559 | ||
6560 | static bfd_boolean | |
cec5225b | 6561 | elfNN_aarch64_set_private_flags (bfd *abfd, flagword flags) |
a06ea964 NC |
6562 | { |
6563 | if (elf_flags_init (abfd) && elf_elfheader (abfd)->e_flags != flags) | |
6564 | { | |
6565 | } | |
6566 | else | |
6567 | { | |
6568 | elf_elfheader (abfd)->e_flags = flags; | |
6569 | elf_flags_init (abfd) = TRUE; | |
6570 | } | |
6571 | ||
6572 | return TRUE; | |
6573 | } | |
6574 | ||
a06ea964 NC |
6575 | /* Merge backend specific data from an object file to the output |
6576 | object file when linking. */ | |
6577 | ||
6578 | static bfd_boolean | |
50e03d47 | 6579 | elfNN_aarch64_merge_private_bfd_data (bfd *ibfd, struct bfd_link_info *info) |
a06ea964 | 6580 | { |
50e03d47 | 6581 | bfd *obfd = info->output_bfd; |
a06ea964 NC |
6582 | flagword out_flags; |
6583 | flagword in_flags; | |
6584 | bfd_boolean flags_compatible = TRUE; | |
6585 | asection *sec; | |
6586 | ||
6587 | /* Check if we have the same endianess. */ | |
50e03d47 | 6588 | if (!_bfd_generic_verify_endian_match (ibfd, info)) |
a06ea964 NC |
6589 | return FALSE; |
6590 | ||
6591 | if (!is_aarch64_elf (ibfd) || !is_aarch64_elf (obfd)) | |
6592 | return TRUE; | |
6593 | ||
6594 | /* The input BFD must have had its flags initialised. */ | |
6595 | /* The following seems bogus to me -- The flags are initialized in | |
6596 | the assembler but I don't think an elf_flags_init field is | |
6597 | written into the object. */ | |
6598 | /* BFD_ASSERT (elf_flags_init (ibfd)); */ | |
6599 | ||
6600 | in_flags = elf_elfheader (ibfd)->e_flags; | |
6601 | out_flags = elf_elfheader (obfd)->e_flags; | |
6602 | ||
6603 | if (!elf_flags_init (obfd)) | |
6604 | { | |
6605 | /* If the input is the default architecture and had the default | |
6606 | flags then do not bother setting the flags for the output | |
6607 | architecture, instead allow future merges to do this. If no | |
6608 | future merges ever set these flags then they will retain their | |
6609 | uninitialised values, which surprise surprise, correspond | |
6610 | to the default values. */ | |
6611 | if (bfd_get_arch_info (ibfd)->the_default | |
6612 | && elf_elfheader (ibfd)->e_flags == 0) | |
6613 | return TRUE; | |
6614 | ||
6615 | elf_flags_init (obfd) = TRUE; | |
6616 | elf_elfheader (obfd)->e_flags = in_flags; | |
6617 | ||
6618 | if (bfd_get_arch (obfd) == bfd_get_arch (ibfd) | |
6619 | && bfd_get_arch_info (obfd)->the_default) | |
6620 | return bfd_set_arch_mach (obfd, bfd_get_arch (ibfd), | |
6621 | bfd_get_mach (ibfd)); | |
6622 | ||
6623 | return TRUE; | |
6624 | } | |
6625 | ||
6626 | /* Identical flags must be compatible. */ | |
6627 | if (in_flags == out_flags) | |
6628 | return TRUE; | |
6629 | ||
6630 | /* Check to see if the input BFD actually contains any sections. If | |
6631 | not, its flags may not have been initialised either, but it | |
6632 | cannot actually cause any incompatiblity. Do not short-circuit | |
6633 | dynamic objects; their section list may be emptied by | |
6634 | elf_link_add_object_symbols. | |
6635 | ||
6636 | Also check to see if there are no code sections in the input. | |
6637 | In this case there is no need to check for code specific flags. | |
6638 | XXX - do we need to worry about floating-point format compatability | |
6639 | in data sections ? */ | |
6640 | if (!(ibfd->flags & DYNAMIC)) | |
6641 | { | |
6642 | bfd_boolean null_input_bfd = TRUE; | |
6643 | bfd_boolean only_data_sections = TRUE; | |
6644 | ||
6645 | for (sec = ibfd->sections; sec != NULL; sec = sec->next) | |
6646 | { | |
6647 | if ((bfd_get_section_flags (ibfd, sec) | |
6648 | & (SEC_LOAD | SEC_CODE | SEC_HAS_CONTENTS)) | |
6649 | == (SEC_LOAD | SEC_CODE | SEC_HAS_CONTENTS)) | |
6650 | only_data_sections = FALSE; | |
6651 | ||
6652 | null_input_bfd = FALSE; | |
6653 | break; | |
6654 | } | |
6655 | ||
6656 | if (null_input_bfd || only_data_sections) | |
6657 | return TRUE; | |
6658 | } | |
6659 | ||
6660 | return flags_compatible; | |
6661 | } | |
6662 | ||
6663 | /* Display the flags field. */ | |
6664 | ||
6665 | static bfd_boolean | |
cec5225b | 6666 | elfNN_aarch64_print_private_bfd_data (bfd *abfd, void *ptr) |
a06ea964 NC |
6667 | { |
6668 | FILE *file = (FILE *) ptr; | |
6669 | unsigned long flags; | |
6670 | ||
6671 | BFD_ASSERT (abfd != NULL && ptr != NULL); | |
6672 | ||
6673 | /* Print normal ELF private data. */ | |
6674 | _bfd_elf_print_private_bfd_data (abfd, ptr); | |
6675 | ||
6676 | flags = elf_elfheader (abfd)->e_flags; | |
6677 | /* Ignore init flag - it may not be set, despite the flags field | |
6678 | containing valid data. */ | |
6679 | ||
6680 | /* xgettext:c-format */ | |
6681 | fprintf (file, _("private flags = %lx:"), elf_elfheader (abfd)->e_flags); | |
6682 | ||
6683 | if (flags) | |
6684 | fprintf (file, _("<Unrecognised flag bits set>")); | |
6685 | ||
6686 | fputc ('\n', file); | |
6687 | ||
6688 | return TRUE; | |
6689 | } | |
6690 | ||
6691 | /* Update the got entry reference counts for the section being removed. */ | |
6692 | ||
6693 | static bfd_boolean | |
cec5225b | 6694 | elfNN_aarch64_gc_sweep_hook (bfd *abfd, |
cb8af559 NC |
6695 | struct bfd_link_info *info, |
6696 | asection *sec, | |
6697 | const Elf_Internal_Rela * relocs) | |
a06ea964 | 6698 | { |
cec5225b | 6699 | struct elf_aarch64_link_hash_table *htab; |
59c108f7 NC |
6700 | Elf_Internal_Shdr *symtab_hdr; |
6701 | struct elf_link_hash_entry **sym_hashes; | |
cb8af559 | 6702 | struct elf_aarch64_local_symbol *locals; |
59c108f7 NC |
6703 | const Elf_Internal_Rela *rel, *relend; |
6704 | ||
0e1862bb | 6705 | if (bfd_link_relocatable (info)) |
59c108f7 NC |
6706 | return TRUE; |
6707 | ||
cec5225b | 6708 | htab = elf_aarch64_hash_table (info); |
59c108f7 NC |
6709 | |
6710 | if (htab == NULL) | |
6711 | return FALSE; | |
6712 | ||
6713 | elf_section_data (sec)->local_dynrel = NULL; | |
6714 | ||
6715 | symtab_hdr = &elf_symtab_hdr (abfd); | |
6716 | sym_hashes = elf_sym_hashes (abfd); | |
6717 | ||
cec5225b | 6718 | locals = elf_aarch64_locals (abfd); |
59c108f7 NC |
6719 | |
6720 | relend = relocs + sec->reloc_count; | |
6721 | for (rel = relocs; rel < relend; rel++) | |
6722 | { | |
6723 | unsigned long r_symndx; | |
6724 | unsigned int r_type; | |
6725 | struct elf_link_hash_entry *h = NULL; | |
6726 | ||
cec5225b | 6727 | r_symndx = ELFNN_R_SYM (rel->r_info); |
8847944f | 6728 | |
59c108f7 NC |
6729 | if (r_symndx >= symtab_hdr->sh_info) |
6730 | { | |
8847944f | 6731 | |
59c108f7 NC |
6732 | h = sym_hashes[r_symndx - symtab_hdr->sh_info]; |
6733 | while (h->root.type == bfd_link_hash_indirect | |
6734 | || h->root.type == bfd_link_hash_warning) | |
6735 | h = (struct elf_link_hash_entry *) h->root.u.i.link; | |
59c108f7 NC |
6736 | } |
6737 | else | |
6738 | { | |
6739 | Elf_Internal_Sym *isym; | |
6740 | ||
8847944f | 6741 | /* A local symbol. */ |
59c108f7 NC |
6742 | isym = bfd_sym_from_r_symndx (&htab->sym_cache, |
6743 | abfd, r_symndx); | |
1419bbe5 WN |
6744 | |
6745 | /* Check relocation against local STT_GNU_IFUNC symbol. */ | |
6746 | if (isym != NULL | |
6747 | && ELF_ST_TYPE (isym->st_info) == STT_GNU_IFUNC) | |
6748 | { | |
6749 | h = elfNN_aarch64_get_local_sym_hash (htab, abfd, rel, FALSE); | |
6750 | if (h == NULL) | |
6751 | abort (); | |
6752 | } | |
6753 | } | |
6754 | ||
6755 | if (h) | |
6756 | { | |
6757 | struct elf_aarch64_link_hash_entry *eh; | |
6758 | struct elf_dyn_relocs **pp; | |
6759 | struct elf_dyn_relocs *p; | |
6760 | ||
6761 | eh = (struct elf_aarch64_link_hash_entry *) h; | |
6762 | ||
6763 | for (pp = &eh->dyn_relocs; (p = *pp) != NULL; pp = &p->next) | |
6764 | if (p->sec == sec) | |
6765 | { | |
6766 | /* Everything must go for SEC. */ | |
6767 | *pp = p->next; | |
6768 | break; | |
6769 | } | |
59c108f7 NC |
6770 | } |
6771 | ||
cec5225b | 6772 | r_type = ELFNN_R_TYPE (rel->r_info); |
a6bb11b2 | 6773 | switch (aarch64_tls_transition (abfd,info, r_type, h ,r_symndx)) |
59c108f7 | 6774 | { |
a6bb11b2 | 6775 | case BFD_RELOC_AARCH64_ADR_GOT_PAGE: |
7bcccb57 | 6776 | case BFD_RELOC_AARCH64_GOT_LD_PREL19: |
7018c030 | 6777 | case BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14: |
7bcccb57 | 6778 | case BFD_RELOC_AARCH64_LD32_GOT_LO12_NC: |
a2e1db00 | 6779 | case BFD_RELOC_AARCH64_LD64_GOTOFF_LO15: |
99ad26cb | 6780 | case BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15: |
7bcccb57 | 6781 | case BFD_RELOC_AARCH64_LD64_GOT_LO12_NC: |
dc8008f5 | 6782 | case BFD_RELOC_AARCH64_MOVW_GOTOFF_G0_NC: |
74a1bfe1 | 6783 | case BFD_RELOC_AARCH64_MOVW_GOTOFF_G1: |
f955cccf | 6784 | case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12: |
7bcccb57 | 6785 | case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21: |
389b8029 | 6786 | case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21: |
7bcccb57 | 6787 | case BFD_RELOC_AARCH64_TLSDESC_LD32_LO12_NC: |
f955cccf | 6788 | case BFD_RELOC_AARCH64_TLSDESC_LD64_LO12: |
1ada945d | 6789 | case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19: |
0484b454 RL |
6790 | case BFD_RELOC_AARCH64_TLSDESC_OFF_G0_NC: |
6791 | case BFD_RELOC_AARCH64_TLSDESC_OFF_G1: | |
a6bb11b2 | 6792 | case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC: |
7bcccb57 | 6793 | case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21: |
3c12b054 | 6794 | case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21: |
7ba7cfe4 | 6795 | case BFD_RELOC_AARCH64_TLSGD_MOVW_G0_NC: |
94facae3 | 6796 | case BFD_RELOC_AARCH64_TLSGD_MOVW_G1: |
a6bb11b2 | 6797 | case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21: |
a6bb11b2 | 6798 | case BFD_RELOC_AARCH64_TLSIE_LD32_GOTTPREL_LO12_NC: |
7bcccb57 | 6799 | case BFD_RELOC_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC: |
043bf05a | 6800 | case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19: |
3b957e5b RL |
6801 | case BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G0_NC: |
6802 | case BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G1: | |
73f925cc | 6803 | case BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC: |
f69e4920 | 6804 | case BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21: |
77a69ff8 | 6805 | case BFD_RELOC_AARCH64_TLSLD_ADR_PREL21: |
a6bb11b2 | 6806 | if (h != NULL) |
59c108f7 NC |
6807 | { |
6808 | if (h->got.refcount > 0) | |
6809 | h->got.refcount -= 1; | |
1419bbe5 WN |
6810 | |
6811 | if (h->type == STT_GNU_IFUNC) | |
6812 | { | |
6813 | if (h->plt.refcount > 0) | |
6814 | h->plt.refcount -= 1; | |
6815 | } | |
59c108f7 | 6816 | } |
cb8af559 | 6817 | else if (locals != NULL) |
59c108f7 | 6818 | { |
cb8af559 NC |
6819 | if (locals[r_symndx].got_refcount > 0) |
6820 | locals[r_symndx].got_refcount -= 1; | |
59c108f7 NC |
6821 | } |
6822 | break; | |
6823 | ||
a6bb11b2 YZ |
6824 | case BFD_RELOC_AARCH64_CALL26: |
6825 | case BFD_RELOC_AARCH64_JUMP26: | |
6826 | /* If this is a local symbol then we resolve it | |
6827 | directly without creating a PLT entry. */ | |
59c108f7 NC |
6828 | if (h == NULL) |
6829 | continue; | |
6830 | ||
6831 | if (h->plt.refcount > 0) | |
6832 | h->plt.refcount -= 1; | |
6833 | break; | |
6834 | ||
6353d82b | 6835 | case BFD_RELOC_AARCH64_ADD_LO12: |
ce336788 JW |
6836 | case BFD_RELOC_AARCH64_ADR_HI21_NC_PCREL: |
6837 | case BFD_RELOC_AARCH64_ADR_HI21_PCREL: | |
6838 | case BFD_RELOC_AARCH64_ADR_LO21_PCREL: | |
6353d82b JW |
6839 | case BFD_RELOC_AARCH64_LDST128_LO12: |
6840 | case BFD_RELOC_AARCH64_LDST16_LO12: | |
6841 | case BFD_RELOC_AARCH64_LDST32_LO12: | |
6842 | case BFD_RELOC_AARCH64_LDST64_LO12: | |
6843 | case BFD_RELOC_AARCH64_LDST8_LO12: | |
6844 | case BFD_RELOC_AARCH64_LD_LO19_PCREL: | |
614b09ce JW |
6845 | case BFD_RELOC_AARCH64_MOVW_G0_NC: |
6846 | case BFD_RELOC_AARCH64_MOVW_G1_NC: | |
6847 | case BFD_RELOC_AARCH64_MOVW_G2_NC: | |
6848 | case BFD_RELOC_AARCH64_MOVW_G3: | |
a6bb11b2 | 6849 | case BFD_RELOC_AARCH64_NN: |
6353d82b | 6850 | if (h != NULL && !bfd_link_pic (info)) |
59c108f7 NC |
6851 | { |
6852 | if (h->plt.refcount > 0) | |
6853 | h->plt.refcount -= 1; | |
6854 | } | |
6855 | break; | |
cec5225b | 6856 | |
59c108f7 NC |
6857 | default: |
6858 | break; | |
6859 | } | |
6860 | } | |
6861 | ||
a06ea964 NC |
6862 | return TRUE; |
6863 | } | |
6864 | ||
6353d82b JW |
6865 | /* Return true if we need copy relocation against EH. */ |
6866 | ||
6867 | static bfd_boolean | |
6868 | need_copy_relocation_p (struct elf_aarch64_link_hash_entry *eh) | |
6869 | { | |
6870 | struct elf_dyn_relocs *p; | |
6871 | asection *s; | |
6872 | ||
6873 | for (p = eh->dyn_relocs; p != NULL; p = p->next) | |
6874 | { | |
6875 | /* If there is any pc-relative reference, we need to keep copy relocation | |
6876 | to avoid propagating the relocation into runtime that current glibc | |
6877 | does not support. */ | |
6878 | if (p->pc_count) | |
6879 | return TRUE; | |
6880 | ||
6881 | s = p->sec->output_section; | |
6882 | /* Need copy relocation if it's against read-only section. */ | |
6883 | if (s != NULL && (s->flags & SEC_READONLY) != 0) | |
6884 | return TRUE; | |
6885 | } | |
6886 | ||
6887 | return FALSE; | |
6888 | } | |
6889 | ||
a06ea964 NC |
6890 | /* Adjust a symbol defined by a dynamic object and referenced by a |
6891 | regular object. The current definition is in some section of the | |
6892 | dynamic object, but we're not including those sections. We have to | |
6893 | change the definition to something the rest of the link can | |
6894 | understand. */ | |
6895 | ||
6896 | static bfd_boolean | |
cec5225b | 6897 | elfNN_aarch64_adjust_dynamic_symbol (struct bfd_link_info *info, |
a06ea964 NC |
6898 | struct elf_link_hash_entry *h) |
6899 | { | |
cec5225b | 6900 | struct elf_aarch64_link_hash_table *htab; |
5474d94f | 6901 | asection *s, *srel; |
a06ea964 NC |
6902 | |
6903 | /* If this is a function, put it in the procedure linkage table. We | |
6904 | will fill in the contents of the procedure linkage table later, | |
6905 | when we know the address of the .got section. */ | |
1419bbe5 | 6906 | if (h->type == STT_FUNC || h->type == STT_GNU_IFUNC || h->needs_plt) |
a06ea964 NC |
6907 | { |
6908 | if (h->plt.refcount <= 0 | |
1419bbe5 WN |
6909 | || (h->type != STT_GNU_IFUNC |
6910 | && (SYMBOL_CALLS_LOCAL (info, h) | |
6911 | || (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT | |
6912 | && h->root.type == bfd_link_hash_undefweak)))) | |
a06ea964 NC |
6913 | { |
6914 | /* This case can occur if we saw a CALL26 reloc in | |
6915 | an input file, but the symbol wasn't referred to | |
6916 | by a dynamic object or all references were | |
6917 | garbage collected. In which case we can end up | |
6918 | resolving. */ | |
6919 | h->plt.offset = (bfd_vma) - 1; | |
6920 | h->needs_plt = 0; | |
6921 | } | |
6922 | ||
6923 | return TRUE; | |
6924 | } | |
6925 | else | |
80de0c6d | 6926 | /* Otherwise, reset to -1. */ |
a06ea964 NC |
6927 | h->plt.offset = (bfd_vma) - 1; |
6928 | ||
6929 | ||
6930 | /* If this is a weak symbol, and there is a real definition, the | |
6931 | processor independent code will have arranged for us to see the | |
6932 | real definition first, and we can just use the same value. */ | |
6933 | if (h->u.weakdef != NULL) | |
6934 | { | |
6935 | BFD_ASSERT (h->u.weakdef->root.type == bfd_link_hash_defined | |
6936 | || h->u.weakdef->root.type == bfd_link_hash_defweak); | |
6937 | h->root.u.def.section = h->u.weakdef->root.u.def.section; | |
6938 | h->root.u.def.value = h->u.weakdef->root.u.def.value; | |
6939 | if (ELIMINATE_COPY_RELOCS || info->nocopyreloc) | |
6940 | h->non_got_ref = h->u.weakdef->non_got_ref; | |
6941 | return TRUE; | |
6942 | } | |
6943 | ||
6944 | /* If we are creating a shared library, we must presume that the | |
6945 | only references to the symbol are via the global offset table. | |
6946 | For such cases we need not do anything here; the relocations will | |
6947 | be handled correctly by relocate_section. */ | |
0e1862bb | 6948 | if (bfd_link_pic (info)) |
a06ea964 NC |
6949 | return TRUE; |
6950 | ||
6951 | /* If there are no references to this symbol that do not use the | |
6952 | GOT, we don't need to generate a copy reloc. */ | |
6953 | if (!h->non_got_ref) | |
6954 | return TRUE; | |
6955 | ||
6956 | /* If -z nocopyreloc was given, we won't generate them either. */ | |
6957 | if (info->nocopyreloc) | |
6958 | { | |
6959 | h->non_got_ref = 0; | |
6960 | return TRUE; | |
6961 | } | |
6962 | ||
6353d82b JW |
6963 | if (ELIMINATE_COPY_RELOCS) |
6964 | { | |
6965 | struct elf_aarch64_link_hash_entry *eh; | |
6966 | /* If we didn't find any dynamic relocs in read-only sections, then | |
6967 | we'll be keeping the dynamic relocs and avoiding the copy reloc. */ | |
6968 | eh = (struct elf_aarch64_link_hash_entry *) h; | |
6969 | if (!need_copy_relocation_p (eh)) | |
6970 | { | |
6971 | h->non_got_ref = 0; | |
6972 | return TRUE; | |
6973 | } | |
6974 | } | |
6975 | ||
a06ea964 NC |
6976 | /* We must allocate the symbol in our .dynbss section, which will |
6977 | become part of the .bss section of the executable. There will be | |
6978 | an entry for this symbol in the .dynsym section. The dynamic | |
6979 | object will contain position independent code, so all references | |
6980 | from the dynamic object to this symbol will go through the global | |
6981 | offset table. The dynamic linker will use the .dynsym entry to | |
6982 | determine the address it must put in the global offset table, so | |
6983 | both the dynamic object and the regular object will refer to the | |
6984 | same memory location for the variable. */ | |
6985 | ||
cec5225b | 6986 | htab = elf_aarch64_hash_table (info); |
a06ea964 NC |
6987 | |
6988 | /* We must generate a R_AARCH64_COPY reloc to tell the dynamic linker | |
6989 | to copy the initial value out of the dynamic object and into the | |
6990 | runtime process image. */ | |
5474d94f AM |
6991 | if ((h->root.u.def.section->flags & SEC_READONLY) != 0) |
6992 | { | |
6993 | s = htab->root.sdynrelro; | |
6994 | srel = htab->root.sreldynrelro; | |
6995 | } | |
6996 | else | |
6997 | { | |
6998 | s = htab->root.sdynbss; | |
6999 | srel = htab->root.srelbss; | |
7000 | } | |
a06ea964 NC |
7001 | if ((h->root.u.def.section->flags & SEC_ALLOC) != 0 && h->size != 0) |
7002 | { | |
5474d94f | 7003 | srel->size += RELOC_SIZE (htab); |
a06ea964 NC |
7004 | h->needs_copy = 1; |
7005 | } | |
7006 | ||
6cabe1ea | 7007 | return _bfd_elf_adjust_dynamic_copy (info, h, s); |
a06ea964 NC |
7008 | |
7009 | } | |
7010 | ||
7011 | static bfd_boolean | |
cec5225b | 7012 | elfNN_aarch64_allocate_local_symbols (bfd *abfd, unsigned number) |
a06ea964 NC |
7013 | { |
7014 | struct elf_aarch64_local_symbol *locals; | |
cec5225b | 7015 | locals = elf_aarch64_locals (abfd); |
a06ea964 NC |
7016 | if (locals == NULL) |
7017 | { | |
7018 | locals = (struct elf_aarch64_local_symbol *) | |
7019 | bfd_zalloc (abfd, number * sizeof (struct elf_aarch64_local_symbol)); | |
7020 | if (locals == NULL) | |
7021 | return FALSE; | |
cec5225b | 7022 | elf_aarch64_locals (abfd) = locals; |
a06ea964 NC |
7023 | } |
7024 | return TRUE; | |
7025 | } | |
7026 | ||
cc0efaa8 MS |
7027 | /* Create the .got section to hold the global offset table. */ |
7028 | ||
7029 | static bfd_boolean | |
7030 | aarch64_elf_create_got_section (bfd *abfd, struct bfd_link_info *info) | |
7031 | { | |
7032 | const struct elf_backend_data *bed = get_elf_backend_data (abfd); | |
7033 | flagword flags; | |
7034 | asection *s; | |
7035 | struct elf_link_hash_entry *h; | |
7036 | struct elf_link_hash_table *htab = elf_hash_table (info); | |
7037 | ||
7038 | /* This function may be called more than once. */ | |
ce558b89 | 7039 | if (htab->sgot != NULL) |
cc0efaa8 MS |
7040 | return TRUE; |
7041 | ||
7042 | flags = bed->dynamic_sec_flags; | |
7043 | ||
7044 | s = bfd_make_section_anyway_with_flags (abfd, | |
7045 | (bed->rela_plts_and_copies_p | |
7046 | ? ".rela.got" : ".rel.got"), | |
7047 | (bed->dynamic_sec_flags | |
7048 | | SEC_READONLY)); | |
7049 | if (s == NULL | |
7050 | || ! bfd_set_section_alignment (abfd, s, bed->s->log_file_align)) | |
7051 | return FALSE; | |
7052 | htab->srelgot = s; | |
7053 | ||
7054 | s = bfd_make_section_anyway_with_flags (abfd, ".got", flags); | |
7055 | if (s == NULL | |
7056 | || !bfd_set_section_alignment (abfd, s, bed->s->log_file_align)) | |
7057 | return FALSE; | |
7058 | htab->sgot = s; | |
7059 | htab->sgot->size += GOT_ENTRY_SIZE; | |
7060 | ||
7061 | if (bed->want_got_sym) | |
7062 | { | |
7063 | /* Define the symbol _GLOBAL_OFFSET_TABLE_ at the start of the .got | |
7064 | (or .got.plt) section. We don't do this in the linker script | |
7065 | because we don't want to define the symbol if we are not creating | |
7066 | a global offset table. */ | |
7067 | h = _bfd_elf_define_linkage_sym (abfd, info, s, | |
7068 | "_GLOBAL_OFFSET_TABLE_"); | |
7069 | elf_hash_table (info)->hgot = h; | |
7070 | if (h == NULL) | |
7071 | return FALSE; | |
7072 | } | |
7073 | ||
7074 | if (bed->want_got_plt) | |
7075 | { | |
7076 | s = bfd_make_section_anyway_with_flags (abfd, ".got.plt", flags); | |
7077 | if (s == NULL | |
7078 | || !bfd_set_section_alignment (abfd, s, | |
7079 | bed->s->log_file_align)) | |
7080 | return FALSE; | |
7081 | htab->sgotplt = s; | |
7082 | } | |
7083 | ||
7084 | /* The first bit of the global offset table is the header. */ | |
7085 | s->size += bed->got_header_size; | |
7086 | ||
7087 | return TRUE; | |
7088 | } | |
7089 | ||
a06ea964 NC |
7090 | /* Look through the relocs for a section during the first phase. */ |
7091 | ||
7092 | static bfd_boolean | |
cec5225b | 7093 | elfNN_aarch64_check_relocs (bfd *abfd, struct bfd_link_info *info, |
a06ea964 NC |
7094 | asection *sec, const Elf_Internal_Rela *relocs) |
7095 | { | |
7096 | Elf_Internal_Shdr *symtab_hdr; | |
7097 | struct elf_link_hash_entry **sym_hashes; | |
7098 | const Elf_Internal_Rela *rel; | |
7099 | const Elf_Internal_Rela *rel_end; | |
7100 | asection *sreloc; | |
7101 | ||
cec5225b | 7102 | struct elf_aarch64_link_hash_table *htab; |
a06ea964 | 7103 | |
0e1862bb | 7104 | if (bfd_link_relocatable (info)) |
a06ea964 NC |
7105 | return TRUE; |
7106 | ||
7107 | BFD_ASSERT (is_aarch64_elf (abfd)); | |
7108 | ||
cec5225b | 7109 | htab = elf_aarch64_hash_table (info); |
a06ea964 NC |
7110 | sreloc = NULL; |
7111 | ||
7112 | symtab_hdr = &elf_symtab_hdr (abfd); | |
7113 | sym_hashes = elf_sym_hashes (abfd); | |
a06ea964 NC |
7114 | |
7115 | rel_end = relocs + sec->reloc_count; | |
7116 | for (rel = relocs; rel < rel_end; rel++) | |
7117 | { | |
7118 | struct elf_link_hash_entry *h; | |
d42c267e | 7119 | unsigned int r_symndx; |
a06ea964 | 7120 | unsigned int r_type; |
a6bb11b2 | 7121 | bfd_reloc_code_real_type bfd_r_type; |
1419bbe5 | 7122 | Elf_Internal_Sym *isym; |
a06ea964 | 7123 | |
cec5225b YZ |
7124 | r_symndx = ELFNN_R_SYM (rel->r_info); |
7125 | r_type = ELFNN_R_TYPE (rel->r_info); | |
a06ea964 NC |
7126 | |
7127 | if (r_symndx >= NUM_SHDR_ENTRIES (symtab_hdr)) | |
7128 | { | |
695344c0 | 7129 | /* xgettext:c-format */ |
4eca0228 | 7130 | _bfd_error_handler (_("%B: bad symbol index: %d"), abfd, r_symndx); |
a06ea964 NC |
7131 | return FALSE; |
7132 | } | |
7133 | ||
ed5acf27 | 7134 | if (r_symndx < symtab_hdr->sh_info) |
1419bbe5 WN |
7135 | { |
7136 | /* A local symbol. */ | |
7137 | isym = bfd_sym_from_r_symndx (&htab->sym_cache, | |
7138 | abfd, r_symndx); | |
7139 | if (isym == NULL) | |
7140 | return FALSE; | |
7141 | ||
7142 | /* Check relocation against local STT_GNU_IFUNC symbol. */ | |
7143 | if (ELF_ST_TYPE (isym->st_info) == STT_GNU_IFUNC) | |
7144 | { | |
7145 | h = elfNN_aarch64_get_local_sym_hash (htab, abfd, rel, | |
7146 | TRUE); | |
7147 | if (h == NULL) | |
7148 | return FALSE; | |
7149 | ||
7150 | /* Fake a STT_GNU_IFUNC symbol. */ | |
7151 | h->type = STT_GNU_IFUNC; | |
7152 | h->def_regular = 1; | |
7153 | h->ref_regular = 1; | |
7154 | h->forced_local = 1; | |
7155 | h->root.type = bfd_link_hash_defined; | |
7156 | } | |
7157 | else | |
7158 | h = NULL; | |
7159 | } | |
a06ea964 NC |
7160 | else |
7161 | { | |
7162 | h = sym_hashes[r_symndx - symtab_hdr->sh_info]; | |
7163 | while (h->root.type == bfd_link_hash_indirect | |
7164 | || h->root.type == bfd_link_hash_warning) | |
7165 | h = (struct elf_link_hash_entry *) h->root.u.i.link; | |
81fbe831 AM |
7166 | |
7167 | /* PR15323, ref flags aren't set for references in the same | |
7168 | object. */ | |
bc4e12de | 7169 | h->root.non_ir_ref_regular = 1; |
a06ea964 NC |
7170 | } |
7171 | ||
7172 | /* Could be done earlier, if h were already available. */ | |
a6bb11b2 | 7173 | bfd_r_type = aarch64_tls_transition (abfd, info, r_type, h, r_symndx); |
a06ea964 | 7174 | |
1419bbe5 WN |
7175 | if (h != NULL) |
7176 | { | |
18f822a0 JW |
7177 | /* If a relocation refers to _GLOBAL_OFFSET_TABLE_, create the .got. |
7178 | This shows up in particular in an R_AARCH64_PREL64 in large model | |
7179 | when calculating the pc-relative address to .got section which is | |
7180 | used to initialize the gp register. */ | |
7181 | if (h->root.root.string | |
7182 | && strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0) | |
7183 | { | |
7184 | if (htab->root.dynobj == NULL) | |
7185 | htab->root.dynobj = abfd; | |
7186 | ||
7187 | if (! aarch64_elf_create_got_section (htab->root.dynobj, info)) | |
7188 | return FALSE; | |
7189 | ||
7190 | BFD_ASSERT (h == htab->root.hgot); | |
7191 | } | |
7192 | ||
1419bbe5 WN |
7193 | /* Create the ifunc sections for static executables. If we |
7194 | never see an indirect function symbol nor we are building | |
7195 | a static executable, those sections will be empty and | |
7196 | won't appear in output. */ | |
7197 | switch (bfd_r_type) | |
7198 | { | |
7199 | default: | |
7200 | break; | |
7201 | ||
ce336788 JW |
7202 | case BFD_RELOC_AARCH64_ADD_LO12: |
7203 | case BFD_RELOC_AARCH64_ADR_GOT_PAGE: | |
7204 | case BFD_RELOC_AARCH64_ADR_HI21_PCREL: | |
1419bbe5 | 7205 | case BFD_RELOC_AARCH64_CALL26: |
ce336788 | 7206 | case BFD_RELOC_AARCH64_GOT_LD_PREL19: |
1419bbe5 | 7207 | case BFD_RELOC_AARCH64_JUMP26: |
7018c030 | 7208 | case BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14: |
1419bbe5 | 7209 | case BFD_RELOC_AARCH64_LD32_GOT_LO12_NC: |
a2e1db00 | 7210 | case BFD_RELOC_AARCH64_LD64_GOTOFF_LO15: |
99ad26cb | 7211 | case BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15: |
1419bbe5 | 7212 | case BFD_RELOC_AARCH64_LD64_GOT_LO12_NC: |
dc8008f5 | 7213 | case BFD_RELOC_AARCH64_MOVW_GOTOFF_G0_NC: |
74a1bfe1 | 7214 | case BFD_RELOC_AARCH64_MOVW_GOTOFF_G1: |
ce336788 | 7215 | case BFD_RELOC_AARCH64_NN: |
1419bbe5 WN |
7216 | if (htab->root.dynobj == NULL) |
7217 | htab->root.dynobj = abfd; | |
7218 | if (!_bfd_elf_create_ifunc_sections (htab->root.dynobj, info)) | |
7219 | return FALSE; | |
7220 | break; | |
7221 | } | |
7222 | ||
2d0ca824 | 7223 | /* It is referenced by a non-shared object. */ |
1419bbe5 | 7224 | h->ref_regular = 1; |
bc4e12de | 7225 | h->root.non_ir_ref_regular = 1; |
1419bbe5 WN |
7226 | } |
7227 | ||
a6bb11b2 | 7228 | switch (bfd_r_type) |
a06ea964 | 7229 | { |
6353d82b JW |
7230 | case BFD_RELOC_AARCH64_MOVW_G0_NC: |
7231 | case BFD_RELOC_AARCH64_MOVW_G1_NC: | |
7232 | case BFD_RELOC_AARCH64_MOVW_G2_NC: | |
7233 | case BFD_RELOC_AARCH64_MOVW_G3: | |
7234 | if (bfd_link_pic (info)) | |
7235 | { | |
7236 | int howto_index = bfd_r_type - BFD_RELOC_AARCH64_RELOC_START; | |
7237 | _bfd_error_handler | |
7238 | /* xgettext:c-format */ | |
7239 | (_("%B: relocation %s against `%s' can not be used when making " | |
7240 | "a shared object; recompile with -fPIC"), | |
7241 | abfd, elfNN_aarch64_howto_table[howto_index].name, | |
7242 | (h) ? h->root.root.string : "a local symbol"); | |
7243 | bfd_set_error (bfd_error_bad_value); | |
7244 | return FALSE; | |
7245 | } | |
7246 | /* Fall through. */ | |
7247 | ||
7248 | case BFD_RELOC_AARCH64_16_PCREL: | |
7249 | case BFD_RELOC_AARCH64_32_PCREL: | |
7250 | case BFD_RELOC_AARCH64_64_PCREL: | |
7251 | case BFD_RELOC_AARCH64_ADD_LO12: | |
7252 | case BFD_RELOC_AARCH64_ADR_HI21_NC_PCREL: | |
7253 | case BFD_RELOC_AARCH64_ADR_HI21_PCREL: | |
7254 | case BFD_RELOC_AARCH64_ADR_LO21_PCREL: | |
7255 | case BFD_RELOC_AARCH64_LDST128_LO12: | |
7256 | case BFD_RELOC_AARCH64_LDST16_LO12: | |
7257 | case BFD_RELOC_AARCH64_LDST32_LO12: | |
7258 | case BFD_RELOC_AARCH64_LDST64_LO12: | |
7259 | case BFD_RELOC_AARCH64_LDST8_LO12: | |
7260 | case BFD_RELOC_AARCH64_LD_LO19_PCREL: | |
7261 | if (h == NULL || bfd_link_pic (info)) | |
7262 | break; | |
7263 | /* Fall through. */ | |
7264 | ||
a6bb11b2 | 7265 | case BFD_RELOC_AARCH64_NN: |
a06ea964 NC |
7266 | |
7267 | /* We don't need to handle relocs into sections not going into | |
7268 | the "real" output. */ | |
7269 | if ((sec->flags & SEC_ALLOC) == 0) | |
7270 | break; | |
7271 | ||
7272 | if (h != NULL) | |
7273 | { | |
0e1862bb | 7274 | if (!bfd_link_pic (info)) |
a06ea964 NC |
7275 | h->non_got_ref = 1; |
7276 | ||
7277 | h->plt.refcount += 1; | |
7278 | h->pointer_equality_needed = 1; | |
7279 | } | |
7280 | ||
7281 | /* No need to do anything if we're not creating a shared | |
7282 | object. */ | |
6353d82b JW |
7283 | if (!(bfd_link_pic (info) |
7284 | /* If on the other hand, we are creating an executable, we | |
7285 | may need to keep relocations for symbols satisfied by a | |
7286 | dynamic library if we manage to avoid copy relocs for the | |
7287 | symbol. | |
7288 | ||
7289 | NOTE: Currently, there is no support of copy relocs | |
7290 | elimination on pc-relative relocation types, because there is | |
7291 | no dynamic relocation support for them in glibc. We still | |
7292 | record the dynamic symbol reference for them. This is | |
7293 | because one symbol may be referenced by both absolute | |
7294 | relocation (for example, BFD_RELOC_AARCH64_NN) and | |
7295 | pc-relative relocation. We need full symbol reference | |
7296 | information to make correct decision later in | |
7297 | elfNN_aarch64_adjust_dynamic_symbol. */ | |
7298 | || (ELIMINATE_COPY_RELOCS | |
7299 | && !bfd_link_pic (info) | |
7300 | && h != NULL | |
7301 | && (h->root.type == bfd_link_hash_defweak | |
7302 | || !h->def_regular)))) | |
a06ea964 NC |
7303 | break; |
7304 | ||
7305 | { | |
7306 | struct elf_dyn_relocs *p; | |
7307 | struct elf_dyn_relocs **head; | |
6353d82b | 7308 | int howto_index = bfd_r_type - BFD_RELOC_AARCH64_RELOC_START; |
a06ea964 NC |
7309 | |
7310 | /* We must copy these reloc types into the output file. | |
7311 | Create a reloc section in dynobj and make room for | |
7312 | this reloc. */ | |
7313 | if (sreloc == NULL) | |
7314 | { | |
7315 | if (htab->root.dynobj == NULL) | |
7316 | htab->root.dynobj = abfd; | |
7317 | ||
7318 | sreloc = _bfd_elf_make_dynamic_reloc_section | |
0608afa7 | 7319 | (sec, htab->root.dynobj, LOG_FILE_ALIGN, abfd, /*rela? */ TRUE); |
a06ea964 NC |
7320 | |
7321 | if (sreloc == NULL) | |
7322 | return FALSE; | |
7323 | } | |
7324 | ||
7325 | /* If this is a global symbol, we count the number of | |
7326 | relocations we need for this symbol. */ | |
7327 | if (h != NULL) | |
7328 | { | |
cec5225b YZ |
7329 | struct elf_aarch64_link_hash_entry *eh; |
7330 | eh = (struct elf_aarch64_link_hash_entry *) h; | |
a06ea964 NC |
7331 | head = &eh->dyn_relocs; |
7332 | } | |
7333 | else | |
7334 | { | |
7335 | /* Track dynamic relocs needed for local syms too. | |
7336 | We really need local syms available to do this | |
7337 | easily. Oh well. */ | |
7338 | ||
7339 | asection *s; | |
7340 | void **vpp; | |
a06ea964 NC |
7341 | |
7342 | isym = bfd_sym_from_r_symndx (&htab->sym_cache, | |
7343 | abfd, r_symndx); | |
7344 | if (isym == NULL) | |
7345 | return FALSE; | |
7346 | ||
7347 | s = bfd_section_from_elf_index (abfd, isym->st_shndx); | |
7348 | if (s == NULL) | |
7349 | s = sec; | |
7350 | ||
7351 | /* Beware of type punned pointers vs strict aliasing | |
7352 | rules. */ | |
7353 | vpp = &(elf_section_data (s)->local_dynrel); | |
7354 | head = (struct elf_dyn_relocs **) vpp; | |
7355 | } | |
7356 | ||
7357 | p = *head; | |
7358 | if (p == NULL || p->sec != sec) | |
7359 | { | |
7360 | bfd_size_type amt = sizeof *p; | |
7361 | p = ((struct elf_dyn_relocs *) | |
7362 | bfd_zalloc (htab->root.dynobj, amt)); | |
7363 | if (p == NULL) | |
7364 | return FALSE; | |
7365 | p->next = *head; | |
7366 | *head = p; | |
7367 | p->sec = sec; | |
7368 | } | |
7369 | ||
7370 | p->count += 1; | |
7371 | ||
6353d82b JW |
7372 | if (elfNN_aarch64_howto_table[howto_index].pc_relative) |
7373 | p->pc_count += 1; | |
a06ea964 NC |
7374 | } |
7375 | break; | |
7376 | ||
7377 | /* RR: We probably want to keep a consistency check that | |
7378 | there are no dangling GOT_PAGE relocs. */ | |
a6bb11b2 | 7379 | case BFD_RELOC_AARCH64_ADR_GOT_PAGE: |
7bcccb57 | 7380 | case BFD_RELOC_AARCH64_GOT_LD_PREL19: |
7018c030 | 7381 | case BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14: |
7bcccb57 | 7382 | case BFD_RELOC_AARCH64_LD32_GOT_LO12_NC: |
a2e1db00 | 7383 | case BFD_RELOC_AARCH64_LD64_GOTOFF_LO15: |
99ad26cb | 7384 | case BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15: |
7bcccb57 | 7385 | case BFD_RELOC_AARCH64_LD64_GOT_LO12_NC: |
dc8008f5 | 7386 | case BFD_RELOC_AARCH64_MOVW_GOTOFF_G0_NC: |
74a1bfe1 | 7387 | case BFD_RELOC_AARCH64_MOVW_GOTOFF_G1: |
f955cccf | 7388 | case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12: |
7bcccb57 | 7389 | case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21: |
389b8029 | 7390 | case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21: |
7bcccb57 | 7391 | case BFD_RELOC_AARCH64_TLSDESC_LD32_LO12_NC: |
f955cccf | 7392 | case BFD_RELOC_AARCH64_TLSDESC_LD64_LO12: |
1ada945d | 7393 | case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19: |
0484b454 RL |
7394 | case BFD_RELOC_AARCH64_TLSDESC_OFF_G0_NC: |
7395 | case BFD_RELOC_AARCH64_TLSDESC_OFF_G1: | |
a6bb11b2 | 7396 | case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC: |
7bcccb57 | 7397 | case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21: |
3c12b054 | 7398 | case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21: |
7ba7cfe4 | 7399 | case BFD_RELOC_AARCH64_TLSGD_MOVW_G0_NC: |
94facae3 | 7400 | case BFD_RELOC_AARCH64_TLSGD_MOVW_G1: |
a6bb11b2 | 7401 | case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21: |
a6bb11b2 | 7402 | case BFD_RELOC_AARCH64_TLSIE_LD32_GOTTPREL_LO12_NC: |
7bcccb57 | 7403 | case BFD_RELOC_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC: |
043bf05a | 7404 | case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19: |
3b957e5b RL |
7405 | case BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G0_NC: |
7406 | case BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G1: | |
73f925cc | 7407 | case BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC: |
f69e4920 | 7408 | case BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21: |
77a69ff8 | 7409 | case BFD_RELOC_AARCH64_TLSLD_ADR_PREL21: |
b7a944fe RL |
7410 | case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1: |
7411 | case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1_NC: | |
7412 | case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G2: | |
a06ea964 NC |
7413 | { |
7414 | unsigned got_type; | |
7415 | unsigned old_got_type; | |
7416 | ||
a6bb11b2 | 7417 | got_type = aarch64_reloc_got_type (bfd_r_type); |
a06ea964 NC |
7418 | |
7419 | if (h) | |
7420 | { | |
7421 | h->got.refcount += 1; | |
cec5225b | 7422 | old_got_type = elf_aarch64_hash_entry (h)->got_type; |
a06ea964 NC |
7423 | } |
7424 | else | |
7425 | { | |
7426 | struct elf_aarch64_local_symbol *locals; | |
7427 | ||
cec5225b | 7428 | if (!elfNN_aarch64_allocate_local_symbols |
a06ea964 NC |
7429 | (abfd, symtab_hdr->sh_info)) |
7430 | return FALSE; | |
7431 | ||
cec5225b | 7432 | locals = elf_aarch64_locals (abfd); |
a06ea964 NC |
7433 | BFD_ASSERT (r_symndx < symtab_hdr->sh_info); |
7434 | locals[r_symndx].got_refcount += 1; | |
7435 | old_got_type = locals[r_symndx].got_type; | |
7436 | } | |
7437 | ||
7438 | /* If a variable is accessed with both general dynamic TLS | |
7439 | methods, two slots may be created. */ | |
7440 | if (GOT_TLS_GD_ANY_P (old_got_type) && GOT_TLS_GD_ANY_P (got_type)) | |
7441 | got_type |= old_got_type; | |
7442 | ||
7443 | /* We will already have issued an error message if there | |
7444 | is a TLS/non-TLS mismatch, based on the symbol type. | |
7445 | So just combine any TLS types needed. */ | |
7446 | if (old_got_type != GOT_UNKNOWN && old_got_type != GOT_NORMAL | |
7447 | && got_type != GOT_NORMAL) | |
7448 | got_type |= old_got_type; | |
7449 | ||
7450 | /* If the symbol is accessed by both IE and GD methods, we | |
7451 | are able to relax. Turn off the GD flag, without | |
7452 | messing up with any other kind of TLS types that may be | |
7453 | involved. */ | |
7454 | if ((got_type & GOT_TLS_IE) && GOT_TLS_GD_ANY_P (got_type)) | |
7455 | got_type &= ~ (GOT_TLSDESC_GD | GOT_TLS_GD); | |
7456 | ||
7457 | if (old_got_type != got_type) | |
7458 | { | |
7459 | if (h != NULL) | |
cec5225b | 7460 | elf_aarch64_hash_entry (h)->got_type = got_type; |
a06ea964 NC |
7461 | else |
7462 | { | |
7463 | struct elf_aarch64_local_symbol *locals; | |
cec5225b | 7464 | locals = elf_aarch64_locals (abfd); |
a06ea964 NC |
7465 | BFD_ASSERT (r_symndx < symtab_hdr->sh_info); |
7466 | locals[r_symndx].got_type = got_type; | |
7467 | } | |
7468 | } | |
7469 | ||
cc0efaa8 MS |
7470 | if (htab->root.dynobj == NULL) |
7471 | htab->root.dynobj = abfd; | |
7472 | if (! aarch64_elf_create_got_section (htab->root.dynobj, info)) | |
7473 | return FALSE; | |
a06ea964 NC |
7474 | break; |
7475 | } | |
7476 | ||
a6bb11b2 YZ |
7477 | case BFD_RELOC_AARCH64_CALL26: |
7478 | case BFD_RELOC_AARCH64_JUMP26: | |
a06ea964 NC |
7479 | /* If this is a local symbol then we resolve it |
7480 | directly without creating a PLT entry. */ | |
7481 | if (h == NULL) | |
7482 | continue; | |
7483 | ||
7484 | h->needs_plt = 1; | |
1419bbe5 WN |
7485 | if (h->plt.refcount <= 0) |
7486 | h->plt.refcount = 1; | |
7487 | else | |
7488 | h->plt.refcount += 1; | |
a06ea964 | 7489 | break; |
a6bb11b2 YZ |
7490 | |
7491 | default: | |
7492 | break; | |
a06ea964 NC |
7493 | } |
7494 | } | |
a6bb11b2 | 7495 | |
a06ea964 NC |
7496 | return TRUE; |
7497 | } | |
7498 | ||
7499 | /* Treat mapping symbols as special target symbols. */ | |
7500 | ||
7501 | static bfd_boolean | |
cec5225b | 7502 | elfNN_aarch64_is_target_special_symbol (bfd *abfd ATTRIBUTE_UNUSED, |
a06ea964 NC |
7503 | asymbol *sym) |
7504 | { | |
7505 | return bfd_is_aarch64_special_symbol_name (sym->name, | |
7506 | BFD_AARCH64_SPECIAL_SYM_TYPE_ANY); | |
7507 | } | |
7508 | ||
7509 | /* This is a copy of elf_find_function () from elf.c except that | |
7510 | AArch64 mapping symbols are ignored when looking for function names. */ | |
7511 | ||
7512 | static bfd_boolean | |
7513 | aarch64_elf_find_function (bfd *abfd ATTRIBUTE_UNUSED, | |
a06ea964 | 7514 | asymbol **symbols, |
fb167eb2 | 7515 | asection *section, |
a06ea964 NC |
7516 | bfd_vma offset, |
7517 | const char **filename_ptr, | |
7518 | const char **functionname_ptr) | |
7519 | { | |
7520 | const char *filename = NULL; | |
7521 | asymbol *func = NULL; | |
7522 | bfd_vma low_func = 0; | |
7523 | asymbol **p; | |
7524 | ||
7525 | for (p = symbols; *p != NULL; p++) | |
7526 | { | |
7527 | elf_symbol_type *q; | |
7528 | ||
7529 | q = (elf_symbol_type *) * p; | |
7530 | ||
7531 | switch (ELF_ST_TYPE (q->internal_elf_sym.st_info)) | |
7532 | { | |
7533 | default: | |
7534 | break; | |
7535 | case STT_FILE: | |
7536 | filename = bfd_asymbol_name (&q->symbol); | |
7537 | break; | |
7538 | case STT_FUNC: | |
7539 | case STT_NOTYPE: | |
7540 | /* Skip mapping symbols. */ | |
7541 | if ((q->symbol.flags & BSF_LOCAL) | |
7542 | && (bfd_is_aarch64_special_symbol_name | |
7543 | (q->symbol.name, BFD_AARCH64_SPECIAL_SYM_TYPE_ANY))) | |
7544 | continue; | |
7545 | /* Fall through. */ | |
7546 | if (bfd_get_section (&q->symbol) == section | |
7547 | && q->symbol.value >= low_func && q->symbol.value <= offset) | |
7548 | { | |
7549 | func = (asymbol *) q; | |
7550 | low_func = q->symbol.value; | |
7551 | } | |
7552 | break; | |
7553 | } | |
7554 | } | |
7555 | ||
7556 | if (func == NULL) | |
7557 | return FALSE; | |
7558 | ||
7559 | if (filename_ptr) | |
7560 | *filename_ptr = filename; | |
7561 | if (functionname_ptr) | |
7562 | *functionname_ptr = bfd_asymbol_name (func); | |
7563 | ||
7564 | return TRUE; | |
7565 | } | |
7566 | ||
7567 | ||
7568 | /* Find the nearest line to a particular section and offset, for error | |
7569 | reporting. This code is a duplicate of the code in elf.c, except | |
7570 | that it uses aarch64_elf_find_function. */ | |
7571 | ||
7572 | static bfd_boolean | |
cec5225b | 7573 | elfNN_aarch64_find_nearest_line (bfd *abfd, |
a06ea964 | 7574 | asymbol **symbols, |
fb167eb2 | 7575 | asection *section, |
a06ea964 NC |
7576 | bfd_vma offset, |
7577 | const char **filename_ptr, | |
7578 | const char **functionname_ptr, | |
fb167eb2 AM |
7579 | unsigned int *line_ptr, |
7580 | unsigned int *discriminator_ptr) | |
a06ea964 NC |
7581 | { |
7582 | bfd_boolean found = FALSE; | |
7583 | ||
fb167eb2 | 7584 | if (_bfd_dwarf2_find_nearest_line (abfd, symbols, NULL, section, offset, |
a06ea964 | 7585 | filename_ptr, functionname_ptr, |
fb167eb2 AM |
7586 | line_ptr, discriminator_ptr, |
7587 | dwarf_debug_sections, 0, | |
a06ea964 NC |
7588 | &elf_tdata (abfd)->dwarf2_find_line_info)) |
7589 | { | |
7590 | if (!*functionname_ptr) | |
fb167eb2 | 7591 | aarch64_elf_find_function (abfd, symbols, section, offset, |
a06ea964 NC |
7592 | *filename_ptr ? NULL : filename_ptr, |
7593 | functionname_ptr); | |
7594 | ||
7595 | return TRUE; | |
7596 | } | |
7597 | ||
fb167eb2 AM |
7598 | /* Skip _bfd_dwarf1_find_nearest_line since no known AArch64 |
7599 | toolchain uses DWARF1. */ | |
7600 | ||
a06ea964 NC |
7601 | if (!_bfd_stab_section_find_nearest_line (abfd, symbols, section, offset, |
7602 | &found, filename_ptr, | |
7603 | functionname_ptr, line_ptr, | |
7604 | &elf_tdata (abfd)->line_info)) | |
7605 | return FALSE; | |
7606 | ||
7607 | if (found && (*functionname_ptr || *line_ptr)) | |
7608 | return TRUE; | |
7609 | ||
7610 | if (symbols == NULL) | |
7611 | return FALSE; | |
7612 | ||
fb167eb2 | 7613 | if (!aarch64_elf_find_function (abfd, symbols, section, offset, |
a06ea964 NC |
7614 | filename_ptr, functionname_ptr)) |
7615 | return FALSE; | |
7616 | ||
7617 | *line_ptr = 0; | |
7618 | return TRUE; | |
7619 | } | |
7620 | ||
7621 | static bfd_boolean | |
cec5225b | 7622 | elfNN_aarch64_find_inliner_info (bfd *abfd, |
a06ea964 NC |
7623 | const char **filename_ptr, |
7624 | const char **functionname_ptr, | |
7625 | unsigned int *line_ptr) | |
7626 | { | |
7627 | bfd_boolean found; | |
7628 | found = _bfd_dwarf2_find_inliner_info | |
7629 | (abfd, filename_ptr, | |
7630 | functionname_ptr, line_ptr, &elf_tdata (abfd)->dwarf2_find_line_info); | |
7631 | return found; | |
7632 | } | |
7633 | ||
7634 | ||
7635 | static void | |
cec5225b | 7636 | elfNN_aarch64_post_process_headers (bfd *abfd, |
1419bbe5 | 7637 | struct bfd_link_info *link_info) |
a06ea964 NC |
7638 | { |
7639 | Elf_Internal_Ehdr *i_ehdrp; /* ELF file header, internal form. */ | |
7640 | ||
7641 | i_ehdrp = elf_elfheader (abfd); | |
a06ea964 | 7642 | i_ehdrp->e_ident[EI_ABIVERSION] = AARCH64_ELF_ABI_VERSION; |
1419bbe5 | 7643 | |
78245035 | 7644 | _bfd_elf_post_process_headers (abfd, link_info); |
a06ea964 NC |
7645 | } |
7646 | ||
7647 | static enum elf_reloc_type_class | |
cec5225b | 7648 | elfNN_aarch64_reloc_type_class (const struct bfd_link_info *info ATTRIBUTE_UNUSED, |
7e612e98 AM |
7649 | const asection *rel_sec ATTRIBUTE_UNUSED, |
7650 | const Elf_Internal_Rela *rela) | |
a06ea964 | 7651 | { |
f2e6a843 SN |
7652 | struct elf_aarch64_link_hash_table *htab = elf_aarch64_hash_table (info); |
7653 | ||
7654 | if (htab->root.dynsym != NULL | |
7655 | && htab->root.dynsym->contents != NULL) | |
7656 | { | |
7657 | /* Check relocation against STT_GNU_IFUNC symbol if there are | |
7658 | dynamic symbols. */ | |
7659 | bfd *abfd = info->output_bfd; | |
7660 | const struct elf_backend_data *bed = get_elf_backend_data (abfd); | |
7661 | unsigned long r_symndx = ELFNN_R_SYM (rela->r_info); | |
7662 | if (r_symndx != STN_UNDEF) | |
7663 | { | |
7664 | Elf_Internal_Sym sym; | |
7665 | if (!bed->s->swap_symbol_in (abfd, | |
7666 | (htab->root.dynsym->contents | |
7667 | + r_symndx * bed->s->sizeof_sym), | |
7668 | 0, &sym)) | |
7669 | { | |
7670 | /* xgettext:c-format */ | |
7671 | _bfd_error_handler (_("%B symbol number %lu references" | |
7672 | " nonexistent SHT_SYMTAB_SHNDX section"), | |
7673 | abfd, r_symndx); | |
7674 | /* Ideally an error class should be returned here. */ | |
7675 | } | |
7676 | else if (ELF_ST_TYPE (sym.st_info) == STT_GNU_IFUNC) | |
7677 | return reloc_class_ifunc; | |
7678 | } | |
7679 | } | |
7680 | ||
cec5225b | 7681 | switch ((int) ELFNN_R_TYPE (rela->r_info)) |
a06ea964 | 7682 | { |
f2e6a843 SN |
7683 | case AARCH64_R (IRELATIVE): |
7684 | return reloc_class_ifunc; | |
a6bb11b2 | 7685 | case AARCH64_R (RELATIVE): |
a06ea964 | 7686 | return reloc_class_relative; |
a6bb11b2 | 7687 | case AARCH64_R (JUMP_SLOT): |
a06ea964 | 7688 | return reloc_class_plt; |
a6bb11b2 | 7689 | case AARCH64_R (COPY): |
a06ea964 NC |
7690 | return reloc_class_copy; |
7691 | default: | |
7692 | return reloc_class_normal; | |
7693 | } | |
7694 | } | |
7695 | ||
a06ea964 NC |
7696 | /* Handle an AArch64 specific section when reading an object file. This is |
7697 | called when bfd_section_from_shdr finds a section with an unknown | |
7698 | type. */ | |
7699 | ||
7700 | static bfd_boolean | |
cec5225b | 7701 | elfNN_aarch64_section_from_shdr (bfd *abfd, |
a06ea964 NC |
7702 | Elf_Internal_Shdr *hdr, |
7703 | const char *name, int shindex) | |
7704 | { | |
7705 | /* There ought to be a place to keep ELF backend specific flags, but | |
7706 | at the moment there isn't one. We just keep track of the | |
7707 | sections by their name, instead. Fortunately, the ABI gives | |
7708 | names for all the AArch64 specific sections, so we will probably get | |
7709 | away with this. */ | |
7710 | switch (hdr->sh_type) | |
7711 | { | |
7712 | case SHT_AARCH64_ATTRIBUTES: | |
7713 | break; | |
7714 | ||
7715 | default: | |
7716 | return FALSE; | |
7717 | } | |
7718 | ||
7719 | if (!_bfd_elf_make_section_from_shdr (abfd, hdr, name, shindex)) | |
7720 | return FALSE; | |
7721 | ||
7722 | return TRUE; | |
7723 | } | |
7724 | ||
7725 | /* A structure used to record a list of sections, independently | |
7726 | of the next and prev fields in the asection structure. */ | |
7727 | typedef struct section_list | |
7728 | { | |
7729 | asection *sec; | |
7730 | struct section_list *next; | |
7731 | struct section_list *prev; | |
7732 | } | |
7733 | section_list; | |
7734 | ||
7735 | /* Unfortunately we need to keep a list of sections for which | |
7736 | an _aarch64_elf_section_data structure has been allocated. This | |
cec5225b | 7737 | is because it is possible for functions like elfNN_aarch64_write_section |
a06ea964 NC |
7738 | to be called on a section which has had an elf_data_structure |
7739 | allocated for it (and so the used_by_bfd field is valid) but | |
7740 | for which the AArch64 extended version of this structure - the | |
7741 | _aarch64_elf_section_data structure - has not been allocated. */ | |
7742 | static section_list *sections_with_aarch64_elf_section_data = NULL; | |
7743 | ||
7744 | static void | |
7745 | record_section_with_aarch64_elf_section_data (asection *sec) | |
7746 | { | |
7747 | struct section_list *entry; | |
7748 | ||
7749 | entry = bfd_malloc (sizeof (*entry)); | |
7750 | if (entry == NULL) | |
7751 | return; | |
7752 | entry->sec = sec; | |
7753 | entry->next = sections_with_aarch64_elf_section_data; | |
7754 | entry->prev = NULL; | |
7755 | if (entry->next != NULL) | |
7756 | entry->next->prev = entry; | |
7757 | sections_with_aarch64_elf_section_data = entry; | |
7758 | } | |
7759 | ||
7760 | static struct section_list * | |
7761 | find_aarch64_elf_section_entry (asection *sec) | |
7762 | { | |
7763 | struct section_list *entry; | |
7764 | static struct section_list *last_entry = NULL; | |
7765 | ||
7766 | /* This is a short cut for the typical case where the sections are added | |
7767 | to the sections_with_aarch64_elf_section_data list in forward order and | |
7768 | then looked up here in backwards order. This makes a real difference | |
7769 | to the ld-srec/sec64k.exp linker test. */ | |
7770 | entry = sections_with_aarch64_elf_section_data; | |
7771 | if (last_entry != NULL) | |
7772 | { | |
7773 | if (last_entry->sec == sec) | |
7774 | entry = last_entry; | |
7775 | else if (last_entry->next != NULL && last_entry->next->sec == sec) | |
7776 | entry = last_entry->next; | |
7777 | } | |
7778 | ||
7779 | for (; entry; entry = entry->next) | |
7780 | if (entry->sec == sec) | |
7781 | break; | |
7782 | ||
7783 | if (entry) | |
7784 | /* Record the entry prior to this one - it is the entry we are | |
7785 | most likely to want to locate next time. Also this way if we | |
7786 | have been called from | |
7787 | unrecord_section_with_aarch64_elf_section_data () we will not | |
7788 | be caching a pointer that is about to be freed. */ | |
7789 | last_entry = entry->prev; | |
7790 | ||
7791 | return entry; | |
7792 | } | |
7793 | ||
7794 | static void | |
7795 | unrecord_section_with_aarch64_elf_section_data (asection *sec) | |
7796 | { | |
7797 | struct section_list *entry; | |
7798 | ||
7799 | entry = find_aarch64_elf_section_entry (sec); | |
7800 | ||
7801 | if (entry) | |
7802 | { | |
7803 | if (entry->prev != NULL) | |
7804 | entry->prev->next = entry->next; | |
7805 | if (entry->next != NULL) | |
7806 | entry->next->prev = entry->prev; | |
7807 | if (entry == sections_with_aarch64_elf_section_data) | |
7808 | sections_with_aarch64_elf_section_data = entry->next; | |
7809 | free (entry); | |
7810 | } | |
7811 | } | |
7812 | ||
7813 | ||
7814 | typedef struct | |
7815 | { | |
7816 | void *finfo; | |
7817 | struct bfd_link_info *info; | |
7818 | asection *sec; | |
7819 | int sec_shndx; | |
7820 | int (*func) (void *, const char *, Elf_Internal_Sym *, | |
7821 | asection *, struct elf_link_hash_entry *); | |
7822 | } output_arch_syminfo; | |
7823 | ||
7824 | enum map_symbol_type | |
7825 | { | |
7826 | AARCH64_MAP_INSN, | |
7827 | AARCH64_MAP_DATA | |
7828 | }; | |
7829 | ||
7830 | ||
7831 | /* Output a single mapping symbol. */ | |
7832 | ||
7833 | static bfd_boolean | |
cec5225b | 7834 | elfNN_aarch64_output_map_sym (output_arch_syminfo *osi, |
a06ea964 NC |
7835 | enum map_symbol_type type, bfd_vma offset) |
7836 | { | |
7837 | static const char *names[2] = { "$x", "$d" }; | |
7838 | Elf_Internal_Sym sym; | |
7839 | ||
7840 | sym.st_value = (osi->sec->output_section->vma | |
7841 | + osi->sec->output_offset + offset); | |
7842 | sym.st_size = 0; | |
7843 | sym.st_other = 0; | |
7844 | sym.st_info = ELF_ST_INFO (STB_LOCAL, STT_NOTYPE); | |
7845 | sym.st_shndx = osi->sec_shndx; | |
7846 | return osi->func (osi->finfo, names[type], &sym, osi->sec, NULL) == 1; | |
7847 | } | |
7848 | ||
a06ea964 NC |
7849 | /* Output a single local symbol for a generated stub. */ |
7850 | ||
7851 | static bfd_boolean | |
cec5225b | 7852 | elfNN_aarch64_output_stub_sym (output_arch_syminfo *osi, const char *name, |
a06ea964 NC |
7853 | bfd_vma offset, bfd_vma size) |
7854 | { | |
7855 | Elf_Internal_Sym sym; | |
7856 | ||
7857 | sym.st_value = (osi->sec->output_section->vma | |
7858 | + osi->sec->output_offset + offset); | |
7859 | sym.st_size = size; | |
7860 | sym.st_other = 0; | |
7861 | sym.st_info = ELF_ST_INFO (STB_LOCAL, STT_FUNC); | |
7862 | sym.st_shndx = osi->sec_shndx; | |
7863 | return osi->func (osi->finfo, name, &sym, osi->sec, NULL) == 1; | |
7864 | } | |
7865 | ||
7866 | static bfd_boolean | |
7867 | aarch64_map_one_stub (struct bfd_hash_entry *gen_entry, void *in_arg) | |
7868 | { | |
cec5225b | 7869 | struct elf_aarch64_stub_hash_entry *stub_entry; |
a06ea964 NC |
7870 | asection *stub_sec; |
7871 | bfd_vma addr; | |
7872 | char *stub_name; | |
7873 | output_arch_syminfo *osi; | |
7874 | ||
7875 | /* Massage our args to the form they really have. */ | |
cec5225b | 7876 | stub_entry = (struct elf_aarch64_stub_hash_entry *) gen_entry; |
a06ea964 NC |
7877 | osi = (output_arch_syminfo *) in_arg; |
7878 | ||
7879 | stub_sec = stub_entry->stub_sec; | |
7880 | ||
7881 | /* Ensure this stub is attached to the current section being | |
7882 | processed. */ | |
7883 | if (stub_sec != osi->sec) | |
7884 | return TRUE; | |
7885 | ||
7886 | addr = (bfd_vma) stub_entry->stub_offset; | |
7887 | ||
7888 | stub_name = stub_entry->output_name; | |
7889 | ||
7890 | switch (stub_entry->stub_type) | |
7891 | { | |
7892 | case aarch64_stub_adrp_branch: | |
cec5225b | 7893 | if (!elfNN_aarch64_output_stub_sym (osi, stub_name, addr, |
a06ea964 NC |
7894 | sizeof (aarch64_adrp_branch_stub))) |
7895 | return FALSE; | |
cec5225b | 7896 | if (!elfNN_aarch64_output_map_sym (osi, AARCH64_MAP_INSN, addr)) |
a06ea964 NC |
7897 | return FALSE; |
7898 | break; | |
7899 | case aarch64_stub_long_branch: | |
cec5225b | 7900 | if (!elfNN_aarch64_output_stub_sym |
a06ea964 NC |
7901 | (osi, stub_name, addr, sizeof (aarch64_long_branch_stub))) |
7902 | return FALSE; | |
cec5225b | 7903 | if (!elfNN_aarch64_output_map_sym (osi, AARCH64_MAP_INSN, addr)) |
a06ea964 | 7904 | return FALSE; |
cec5225b | 7905 | if (!elfNN_aarch64_output_map_sym (osi, AARCH64_MAP_DATA, addr + 16)) |
a06ea964 NC |
7906 | return FALSE; |
7907 | break; | |
68fcca92 JW |
7908 | case aarch64_stub_erratum_835769_veneer: |
7909 | if (!elfNN_aarch64_output_stub_sym (osi, stub_name, addr, | |
7910 | sizeof (aarch64_erratum_835769_stub))) | |
7911 | return FALSE; | |
7912 | if (!elfNN_aarch64_output_map_sym (osi, AARCH64_MAP_INSN, addr)) | |
7913 | return FALSE; | |
7914 | break; | |
4106101c MS |
7915 | case aarch64_stub_erratum_843419_veneer: |
7916 | if (!elfNN_aarch64_output_stub_sym (osi, stub_name, addr, | |
7917 | sizeof (aarch64_erratum_843419_stub))) | |
7918 | return FALSE; | |
7919 | if (!elfNN_aarch64_output_map_sym (osi, AARCH64_MAP_INSN, addr)) | |
7920 | return FALSE; | |
7921 | break; | |
7922 | ||
a06ea964 | 7923 | default: |
8e2fe09f | 7924 | abort (); |
a06ea964 NC |
7925 | } |
7926 | ||
7927 | return TRUE; | |
7928 | } | |
7929 | ||
7930 | /* Output mapping symbols for linker generated sections. */ | |
7931 | ||
7932 | static bfd_boolean | |
cec5225b | 7933 | elfNN_aarch64_output_arch_local_syms (bfd *output_bfd, |
a06ea964 NC |
7934 | struct bfd_link_info *info, |
7935 | void *finfo, | |
7936 | int (*func) (void *, const char *, | |
7937 | Elf_Internal_Sym *, | |
7938 | asection *, | |
7939 | struct elf_link_hash_entry | |
7940 | *)) | |
7941 | { | |
7942 | output_arch_syminfo osi; | |
cec5225b | 7943 | struct elf_aarch64_link_hash_table *htab; |
a06ea964 | 7944 | |
cec5225b | 7945 | htab = elf_aarch64_hash_table (info); |
a06ea964 NC |
7946 | |
7947 | osi.finfo = finfo; | |
7948 | osi.info = info; | |
7949 | osi.func = func; | |
7950 | ||
7951 | /* Long calls stubs. */ | |
7952 | if (htab->stub_bfd && htab->stub_bfd->sections) | |
7953 | { | |
7954 | asection *stub_sec; | |
7955 | ||
7956 | for (stub_sec = htab->stub_bfd->sections; | |
7957 | stub_sec != NULL; stub_sec = stub_sec->next) | |
7958 | { | |
7959 | /* Ignore non-stub sections. */ | |
7960 | if (!strstr (stub_sec->name, STUB_SUFFIX)) | |
7961 | continue; | |
7962 | ||
7963 | osi.sec = stub_sec; | |
7964 | ||
7965 | osi.sec_shndx = _bfd_elf_section_from_bfd_section | |
7966 | (output_bfd, osi.sec->output_section); | |
7967 | ||
61865519 MS |
7968 | /* The first instruction in a stub is always a branch. */ |
7969 | if (!elfNN_aarch64_output_map_sym (&osi, AARCH64_MAP_INSN, 0)) | |
7970 | return FALSE; | |
7971 | ||
a06ea964 NC |
7972 | bfd_hash_traverse (&htab->stub_hash_table, aarch64_map_one_stub, |
7973 | &osi); | |
7974 | } | |
7975 | } | |
7976 | ||
7977 | /* Finally, output mapping symbols for the PLT. */ | |
7978 | if (!htab->root.splt || htab->root.splt->size == 0) | |
7979 | return TRUE; | |
7980 | ||
a06ea964 NC |
7981 | osi.sec_shndx = _bfd_elf_section_from_bfd_section |
7982 | (output_bfd, htab->root.splt->output_section); | |
7983 | osi.sec = htab->root.splt; | |
7984 | ||
73524045 | 7985 | elfNN_aarch64_output_map_sym (&osi, AARCH64_MAP_INSN, 0); |
a06ea964 NC |
7986 | |
7987 | return TRUE; | |
7988 | ||
7989 | } | |
7990 | ||
7991 | /* Allocate target specific section data. */ | |
7992 | ||
7993 | static bfd_boolean | |
cec5225b | 7994 | elfNN_aarch64_new_section_hook (bfd *abfd, asection *sec) |
a06ea964 NC |
7995 | { |
7996 | if (!sec->used_by_bfd) | |
7997 | { | |
7998 | _aarch64_elf_section_data *sdata; | |
7999 | bfd_size_type amt = sizeof (*sdata); | |
8000 | ||
8001 | sdata = bfd_zalloc (abfd, amt); | |
8002 | if (sdata == NULL) | |
8003 | return FALSE; | |
8004 | sec->used_by_bfd = sdata; | |
8005 | } | |
8006 | ||
8007 | record_section_with_aarch64_elf_section_data (sec); | |
8008 | ||
8009 | return _bfd_elf_new_section_hook (abfd, sec); | |
8010 | } | |
8011 | ||
8012 | ||
8013 | static void | |
8014 | unrecord_section_via_map_over_sections (bfd *abfd ATTRIBUTE_UNUSED, | |
8015 | asection *sec, | |
8016 | void *ignore ATTRIBUTE_UNUSED) | |
8017 | { | |
8018 | unrecord_section_with_aarch64_elf_section_data (sec); | |
8019 | } | |
8020 | ||
8021 | static bfd_boolean | |
cec5225b | 8022 | elfNN_aarch64_close_and_cleanup (bfd *abfd) |
a06ea964 NC |
8023 | { |
8024 | if (abfd->sections) | |
8025 | bfd_map_over_sections (abfd, | |
8026 | unrecord_section_via_map_over_sections, NULL); | |
8027 | ||
8028 | return _bfd_elf_close_and_cleanup (abfd); | |
8029 | } | |
8030 | ||
8031 | static bfd_boolean | |
cec5225b | 8032 | elfNN_aarch64_bfd_free_cached_info (bfd *abfd) |
a06ea964 NC |
8033 | { |
8034 | if (abfd->sections) | |
8035 | bfd_map_over_sections (abfd, | |
8036 | unrecord_section_via_map_over_sections, NULL); | |
8037 | ||
8038 | return _bfd_free_cached_info (abfd); | |
8039 | } | |
8040 | ||
a06ea964 NC |
8041 | /* Create dynamic sections. This is different from the ARM backend in that |
8042 | the got, plt, gotplt and their relocation sections are all created in the | |
8043 | standard part of the bfd elf backend. */ | |
8044 | ||
8045 | static bfd_boolean | |
cec5225b | 8046 | elfNN_aarch64_create_dynamic_sections (bfd *dynobj, |
a06ea964 NC |
8047 | struct bfd_link_info *info) |
8048 | { | |
cc0efaa8 MS |
8049 | /* We need to create .got section. */ |
8050 | if (!aarch64_elf_create_got_section (dynobj, info)) | |
8051 | return FALSE; | |
a06ea964 | 8052 | |
9d19e4fd | 8053 | return _bfd_elf_create_dynamic_sections (dynobj, info); |
a06ea964 NC |
8054 | } |
8055 | ||
8056 | ||
8057 | /* Allocate space in .plt, .got and associated reloc sections for | |
8058 | dynamic relocs. */ | |
8059 | ||
8060 | static bfd_boolean | |
cec5225b | 8061 | elfNN_aarch64_allocate_dynrelocs (struct elf_link_hash_entry *h, void *inf) |
a06ea964 NC |
8062 | { |
8063 | struct bfd_link_info *info; | |
cec5225b YZ |
8064 | struct elf_aarch64_link_hash_table *htab; |
8065 | struct elf_aarch64_link_hash_entry *eh; | |
a06ea964 NC |
8066 | struct elf_dyn_relocs *p; |
8067 | ||
8068 | /* An example of a bfd_link_hash_indirect symbol is versioned | |
8069 | symbol. For example: __gxx_personality_v0(bfd_link_hash_indirect) | |
8070 | -> __gxx_personality_v0(bfd_link_hash_defined) | |
8071 | ||
8072 | There is no need to process bfd_link_hash_indirect symbols here | |
8073 | because we will also be presented with the concrete instance of | |
cec5225b | 8074 | the symbol and elfNN_aarch64_copy_indirect_symbol () will have been |
a06ea964 | 8075 | called to copy all relevant data from the generic to the concrete |
2d0ca824 | 8076 | symbol instance. */ |
a06ea964 NC |
8077 | if (h->root.type == bfd_link_hash_indirect) |
8078 | return TRUE; | |
8079 | ||
8080 | if (h->root.type == bfd_link_hash_warning) | |
8081 | h = (struct elf_link_hash_entry *) h->root.u.i.link; | |
8082 | ||
8083 | info = (struct bfd_link_info *) inf; | |
cec5225b | 8084 | htab = elf_aarch64_hash_table (info); |
a06ea964 | 8085 | |
1419bbe5 WN |
8086 | /* Since STT_GNU_IFUNC symbol must go through PLT, we handle it |
8087 | here if it is defined and referenced in a non-shared object. */ | |
8088 | if (h->type == STT_GNU_IFUNC | |
8089 | && h->def_regular) | |
8090 | return TRUE; | |
8091 | else if (htab->root.dynamic_sections_created && h->plt.refcount > 0) | |
a06ea964 NC |
8092 | { |
8093 | /* Make sure this symbol is output as a dynamic symbol. | |
8094 | Undefined weak syms won't yet be marked as dynamic. */ | |
ff07562f JW |
8095 | if (h->dynindx == -1 && !h->forced_local |
8096 | && h->root.type == bfd_link_hash_undefweak) | |
a06ea964 NC |
8097 | { |
8098 | if (!bfd_elf_link_record_dynamic_symbol (info, h)) | |
8099 | return FALSE; | |
8100 | } | |
8101 | ||
0e1862bb | 8102 | if (bfd_link_pic (info) || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h)) |
a06ea964 NC |
8103 | { |
8104 | asection *s = htab->root.splt; | |
8105 | ||
8106 | /* If this is the first .plt entry, make room for the special | |
8107 | first entry. */ | |
8108 | if (s->size == 0) | |
8109 | s->size += htab->plt_header_size; | |
8110 | ||
8111 | h->plt.offset = s->size; | |
8112 | ||
8113 | /* If this symbol is not defined in a regular file, and we are | |
8114 | not generating a shared library, then set the symbol to this | |
8115 | location in the .plt. This is required to make function | |
8116 | pointers compare as equal between the normal executable and | |
8117 | the shared library. */ | |
0e1862bb | 8118 | if (!bfd_link_pic (info) && !h->def_regular) |
a06ea964 NC |
8119 | { |
8120 | h->root.u.def.section = s; | |
8121 | h->root.u.def.value = h->plt.offset; | |
8122 | } | |
8123 | ||
8124 | /* Make room for this entry. For now we only create the | |
8125 | small model PLT entries. We later need to find a way | |
8126 | of relaxing into these from the large model PLT entries. */ | |
8127 | s->size += PLT_SMALL_ENTRY_SIZE; | |
8128 | ||
8129 | /* We also need to make an entry in the .got.plt section, which | |
8130 | will be placed in the .got section by the linker script. */ | |
8131 | htab->root.sgotplt->size += GOT_ENTRY_SIZE; | |
8132 | ||
8133 | /* We also need to make an entry in the .rela.plt section. */ | |
8134 | htab->root.srelplt->size += RELOC_SIZE (htab); | |
8135 | ||
8136 | /* We need to ensure that all GOT entries that serve the PLT | |
8137 | are consecutive with the special GOT slots [0] [1] and | |
8138 | [2]. Any addtional relocations, such as | |
8139 | R_AARCH64_TLSDESC, must be placed after the PLT related | |
8140 | entries. We abuse the reloc_count such that during | |
8141 | sizing we adjust reloc_count to indicate the number of | |
8142 | PLT related reserved entries. In subsequent phases when | |
8143 | filling in the contents of the reloc entries, PLT related | |
8144 | entries are placed by computing their PLT index (0 | |
8145 | .. reloc_count). While other none PLT relocs are placed | |
8146 | at the slot indicated by reloc_count and reloc_count is | |
8147 | updated. */ | |
8148 | ||
8149 | htab->root.srelplt->reloc_count++; | |
8150 | } | |
8151 | else | |
8152 | { | |
8153 | h->plt.offset = (bfd_vma) - 1; | |
8154 | h->needs_plt = 0; | |
8155 | } | |
8156 | } | |
8157 | else | |
8158 | { | |
8159 | h->plt.offset = (bfd_vma) - 1; | |
8160 | h->needs_plt = 0; | |
8161 | } | |
8162 | ||
cec5225b | 8163 | eh = (struct elf_aarch64_link_hash_entry *) h; |
a06ea964 NC |
8164 | eh->tlsdesc_got_jump_table_offset = (bfd_vma) - 1; |
8165 | ||
8166 | if (h->got.refcount > 0) | |
8167 | { | |
8168 | bfd_boolean dyn; | |
cec5225b | 8169 | unsigned got_type = elf_aarch64_hash_entry (h)->got_type; |
a06ea964 NC |
8170 | |
8171 | h->got.offset = (bfd_vma) - 1; | |
8172 | ||
8173 | dyn = htab->root.dynamic_sections_created; | |
8174 | ||
8175 | /* Make sure this symbol is output as a dynamic symbol. | |
8176 | Undefined weak syms won't yet be marked as dynamic. */ | |
ff07562f JW |
8177 | if (dyn && h->dynindx == -1 && !h->forced_local |
8178 | && h->root.type == bfd_link_hash_undefweak) | |
a06ea964 NC |
8179 | { |
8180 | if (!bfd_elf_link_record_dynamic_symbol (info, h)) | |
8181 | return FALSE; | |
8182 | } | |
8183 | ||
8184 | if (got_type == GOT_UNKNOWN) | |
8185 | { | |
8186 | } | |
8187 | else if (got_type == GOT_NORMAL) | |
8188 | { | |
8189 | h->got.offset = htab->root.sgot->size; | |
8190 | htab->root.sgot->size += GOT_ENTRY_SIZE; | |
8191 | if ((ELF_ST_VISIBILITY (h->other) == STV_DEFAULT | |
8192 | || h->root.type != bfd_link_hash_undefweak) | |
0e1862bb | 8193 | && (bfd_link_pic (info) |
a06ea964 NC |
8194 | || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, 0, h))) |
8195 | { | |
8196 | htab->root.srelgot->size += RELOC_SIZE (htab); | |
8197 | } | |
8198 | } | |
8199 | else | |
8200 | { | |
8201 | int indx; | |
8202 | if (got_type & GOT_TLSDESC_GD) | |
8203 | { | |
8204 | eh->tlsdesc_got_jump_table_offset = | |
8205 | (htab->root.sgotplt->size | |
8206 | - aarch64_compute_jump_table_size (htab)); | |
8207 | htab->root.sgotplt->size += GOT_ENTRY_SIZE * 2; | |
8208 | h->got.offset = (bfd_vma) - 2; | |
8209 | } | |
8210 | ||
8211 | if (got_type & GOT_TLS_GD) | |
8212 | { | |
8213 | h->got.offset = htab->root.sgot->size; | |
8214 | htab->root.sgot->size += GOT_ENTRY_SIZE * 2; | |
8215 | } | |
8216 | ||
8217 | if (got_type & GOT_TLS_IE) | |
8218 | { | |
8219 | h->got.offset = htab->root.sgot->size; | |
8220 | htab->root.sgot->size += GOT_ENTRY_SIZE; | |
8221 | } | |
8222 | ||
8223 | indx = h && h->dynindx != -1 ? h->dynindx : 0; | |
8224 | if ((ELF_ST_VISIBILITY (h->other) == STV_DEFAULT | |
8225 | || h->root.type != bfd_link_hash_undefweak) | |
0e1862bb | 8226 | && (bfd_link_pic (info) |
a06ea964 NC |
8227 | || indx != 0 |
8228 | || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, 0, h))) | |
8229 | { | |
8230 | if (got_type & GOT_TLSDESC_GD) | |
8231 | { | |
8232 | htab->root.srelplt->size += RELOC_SIZE (htab); | |
8233 | /* Note reloc_count not incremented here! We have | |
8234 | already adjusted reloc_count for this relocation | |
8235 | type. */ | |
8236 | ||
8237 | /* TLSDESC PLT is now needed, but not yet determined. */ | |
8238 | htab->tlsdesc_plt = (bfd_vma) - 1; | |
8239 | } | |
8240 | ||
8241 | if (got_type & GOT_TLS_GD) | |
8242 | htab->root.srelgot->size += RELOC_SIZE (htab) * 2; | |
8243 | ||
8244 | if (got_type & GOT_TLS_IE) | |
8245 | htab->root.srelgot->size += RELOC_SIZE (htab); | |
8246 | } | |
8247 | } | |
8248 | } | |
8249 | else | |
8250 | { | |
8251 | h->got.offset = (bfd_vma) - 1; | |
8252 | } | |
8253 | ||
8254 | if (eh->dyn_relocs == NULL) | |
8255 | return TRUE; | |
8256 | ||
8257 | /* In the shared -Bsymbolic case, discard space allocated for | |
8258 | dynamic pc-relative relocs against symbols which turn out to be | |
8259 | defined in regular objects. For the normal shared case, discard | |
8260 | space for pc-relative relocs that have become local due to symbol | |
8261 | visibility changes. */ | |
8262 | ||
0e1862bb | 8263 | if (bfd_link_pic (info)) |
a06ea964 NC |
8264 | { |
8265 | /* Relocs that use pc_count are those that appear on a call | |
8266 | insn, or certain REL relocs that can generated via assembly. | |
8267 | We want calls to protected symbols to resolve directly to the | |
8268 | function rather than going via the plt. If people want | |
8269 | function pointer comparisons to work as expected then they | |
8270 | should avoid writing weird assembly. */ | |
8271 | if (SYMBOL_CALLS_LOCAL (info, h)) | |
8272 | { | |
8273 | struct elf_dyn_relocs **pp; | |
8274 | ||
8275 | for (pp = &eh->dyn_relocs; (p = *pp) != NULL;) | |
8276 | { | |
8277 | p->count -= p->pc_count; | |
8278 | p->pc_count = 0; | |
8279 | if (p->count == 0) | |
8280 | *pp = p->next; | |
8281 | else | |
8282 | pp = &p->next; | |
8283 | } | |
8284 | } | |
8285 | ||
8286 | /* Also discard relocs on undefined weak syms with non-default | |
8287 | visibility. */ | |
8288 | if (eh->dyn_relocs != NULL && h->root.type == bfd_link_hash_undefweak) | |
8289 | { | |
8290 | if (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT) | |
8291 | eh->dyn_relocs = NULL; | |
8292 | ||
8293 | /* Make sure undefined weak symbols are output as a dynamic | |
8294 | symbol in PIEs. */ | |
8295 | else if (h->dynindx == -1 | |
8296 | && !h->forced_local | |
ff07562f | 8297 | && h->root.type == bfd_link_hash_undefweak |
a06ea964 NC |
8298 | && !bfd_elf_link_record_dynamic_symbol (info, h)) |
8299 | return FALSE; | |
8300 | } | |
8301 | ||
8302 | } | |
8303 | else if (ELIMINATE_COPY_RELOCS) | |
8304 | { | |
8305 | /* For the non-shared case, discard space for relocs against | |
8306 | symbols which turn out to need copy relocs or are not | |
8307 | dynamic. */ | |
8308 | ||
8309 | if (!h->non_got_ref | |
8310 | && ((h->def_dynamic | |
8311 | && !h->def_regular) | |
8312 | || (htab->root.dynamic_sections_created | |
8313 | && (h->root.type == bfd_link_hash_undefweak | |
8314 | || h->root.type == bfd_link_hash_undefined)))) | |
8315 | { | |
8316 | /* Make sure this symbol is output as a dynamic symbol. | |
8317 | Undefined weak syms won't yet be marked as dynamic. */ | |
8318 | if (h->dynindx == -1 | |
8319 | && !h->forced_local | |
ff07562f | 8320 | && h->root.type == bfd_link_hash_undefweak |
a06ea964 NC |
8321 | && !bfd_elf_link_record_dynamic_symbol (info, h)) |
8322 | return FALSE; | |
8323 | ||
8324 | /* If that succeeded, we know we'll be keeping all the | |
8325 | relocs. */ | |
8326 | if (h->dynindx != -1) | |
8327 | goto keep; | |
8328 | } | |
8329 | ||
8330 | eh->dyn_relocs = NULL; | |
8331 | ||
8332 | keep:; | |
8333 | } | |
8334 | ||
8335 | /* Finally, allocate space. */ | |
8336 | for (p = eh->dyn_relocs; p != NULL; p = p->next) | |
8337 | { | |
8338 | asection *sreloc; | |
8339 | ||
8340 | sreloc = elf_section_data (p->sec)->sreloc; | |
8341 | ||
8342 | BFD_ASSERT (sreloc != NULL); | |
8343 | ||
8344 | sreloc->size += p->count * RELOC_SIZE (htab); | |
8345 | } | |
8346 | ||
8347 | return TRUE; | |
8348 | } | |
8349 | ||
1419bbe5 WN |
8350 | /* Allocate space in .plt, .got and associated reloc sections for |
8351 | ifunc dynamic relocs. */ | |
8352 | ||
8353 | static bfd_boolean | |
8354 | elfNN_aarch64_allocate_ifunc_dynrelocs (struct elf_link_hash_entry *h, | |
8355 | void *inf) | |
8356 | { | |
8357 | struct bfd_link_info *info; | |
8358 | struct elf_aarch64_link_hash_table *htab; | |
8359 | struct elf_aarch64_link_hash_entry *eh; | |
8360 | ||
8361 | /* An example of a bfd_link_hash_indirect symbol is versioned | |
8362 | symbol. For example: __gxx_personality_v0(bfd_link_hash_indirect) | |
8363 | -> __gxx_personality_v0(bfd_link_hash_defined) | |
8364 | ||
8365 | There is no need to process bfd_link_hash_indirect symbols here | |
8366 | because we will also be presented with the concrete instance of | |
8367 | the symbol and elfNN_aarch64_copy_indirect_symbol () will have been | |
8368 | called to copy all relevant data from the generic to the concrete | |
2d0ca824 | 8369 | symbol instance. */ |
1419bbe5 WN |
8370 | if (h->root.type == bfd_link_hash_indirect) |
8371 | return TRUE; | |
8372 | ||
8373 | if (h->root.type == bfd_link_hash_warning) | |
8374 | h = (struct elf_link_hash_entry *) h->root.u.i.link; | |
8375 | ||
8376 | info = (struct bfd_link_info *) inf; | |
8377 | htab = elf_aarch64_hash_table (info); | |
8378 | ||
8379 | eh = (struct elf_aarch64_link_hash_entry *) h; | |
8380 | ||
8381 | /* Since STT_GNU_IFUNC symbol must go through PLT, we handle it | |
8382 | here if it is defined and referenced in a non-shared object. */ | |
8383 | if (h->type == STT_GNU_IFUNC | |
8384 | && h->def_regular) | |
8385 | return _bfd_elf_allocate_ifunc_dyn_relocs (info, h, | |
8386 | &eh->dyn_relocs, | |
2df3368d | 8387 | NULL, |
1419bbe5 WN |
8388 | htab->plt_entry_size, |
8389 | htab->plt_header_size, | |
233cc9c1 L |
8390 | GOT_ENTRY_SIZE, |
8391 | FALSE); | |
1419bbe5 WN |
8392 | return TRUE; |
8393 | } | |
8394 | ||
8395 | /* Allocate space in .plt, .got and associated reloc sections for | |
8396 | local dynamic relocs. */ | |
8397 | ||
8398 | static bfd_boolean | |
8399 | elfNN_aarch64_allocate_local_dynrelocs (void **slot, void *inf) | |
8400 | { | |
8401 | struct elf_link_hash_entry *h | |
8402 | = (struct elf_link_hash_entry *) *slot; | |
8403 | ||
8404 | if (h->type != STT_GNU_IFUNC | |
8405 | || !h->def_regular | |
8406 | || !h->ref_regular | |
8407 | || !h->forced_local | |
8408 | || h->root.type != bfd_link_hash_defined) | |
8409 | abort (); | |
8410 | ||
8411 | return elfNN_aarch64_allocate_dynrelocs (h, inf); | |
8412 | } | |
8413 | ||
8414 | /* Allocate space in .plt, .got and associated reloc sections for | |
8415 | local ifunc dynamic relocs. */ | |
8416 | ||
8417 | static bfd_boolean | |
8418 | elfNN_aarch64_allocate_local_ifunc_dynrelocs (void **slot, void *inf) | |
8419 | { | |
8420 | struct elf_link_hash_entry *h | |
8421 | = (struct elf_link_hash_entry *) *slot; | |
8422 | ||
8423 | if (h->type != STT_GNU_IFUNC | |
8424 | || !h->def_regular | |
8425 | || !h->ref_regular | |
8426 | || !h->forced_local | |
8427 | || h->root.type != bfd_link_hash_defined) | |
8428 | abort (); | |
8429 | ||
8430 | return elfNN_aarch64_allocate_ifunc_dynrelocs (h, inf); | |
8431 | } | |
a06ea964 | 8432 | |
c2170589 JW |
8433 | /* Find any dynamic relocs that apply to read-only sections. */ |
8434 | ||
8435 | static bfd_boolean | |
8436 | aarch64_readonly_dynrelocs (struct elf_link_hash_entry * h, void * inf) | |
8437 | { | |
8438 | struct elf_aarch64_link_hash_entry * eh; | |
8439 | struct elf_dyn_relocs * p; | |
8440 | ||
8441 | eh = (struct elf_aarch64_link_hash_entry *) h; | |
8442 | for (p = eh->dyn_relocs; p != NULL; p = p->next) | |
8443 | { | |
8444 | asection *s = p->sec; | |
8445 | ||
8446 | if (s != NULL && (s->flags & SEC_READONLY) != 0) | |
8447 | { | |
8448 | struct bfd_link_info *info = (struct bfd_link_info *) inf; | |
8449 | ||
8450 | info->flags |= DF_TEXTREL; | |
8451 | ||
8452 | /* Not an error, just cut short the traversal. */ | |
8453 | return FALSE; | |
8454 | } | |
8455 | } | |
8456 | return TRUE; | |
8457 | } | |
8458 | ||
a06ea964 NC |
8459 | /* This is the most important function of all . Innocuosly named |
8460 | though ! */ | |
2d0ca824 | 8461 | |
a06ea964 | 8462 | static bfd_boolean |
cec5225b | 8463 | elfNN_aarch64_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED, |
a06ea964 NC |
8464 | struct bfd_link_info *info) |
8465 | { | |
cec5225b | 8466 | struct elf_aarch64_link_hash_table *htab; |
a06ea964 NC |
8467 | bfd *dynobj; |
8468 | asection *s; | |
8469 | bfd_boolean relocs; | |
8470 | bfd *ibfd; | |
8471 | ||
cec5225b | 8472 | htab = elf_aarch64_hash_table ((info)); |
a06ea964 NC |
8473 | dynobj = htab->root.dynobj; |
8474 | ||
8475 | BFD_ASSERT (dynobj != NULL); | |
8476 | ||
8477 | if (htab->root.dynamic_sections_created) | |
8478 | { | |
9b8b325a | 8479 | if (bfd_link_executable (info) && !info->nointerp) |
a06ea964 NC |
8480 | { |
8481 | s = bfd_get_linker_section (dynobj, ".interp"); | |
8482 | if (s == NULL) | |
8483 | abort (); | |
8484 | s->size = sizeof ELF_DYNAMIC_INTERPRETER; | |
8485 | s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER; | |
8486 | } | |
8487 | } | |
8488 | ||
8489 | /* Set up .got offsets for local syms, and space for local dynamic | |
8490 | relocs. */ | |
c72f2fb2 | 8491 | for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link.next) |
a06ea964 NC |
8492 | { |
8493 | struct elf_aarch64_local_symbol *locals = NULL; | |
8494 | Elf_Internal_Shdr *symtab_hdr; | |
8495 | asection *srel; | |
8496 | unsigned int i; | |
8497 | ||
8498 | if (!is_aarch64_elf (ibfd)) | |
8499 | continue; | |
8500 | ||
8501 | for (s = ibfd->sections; s != NULL; s = s->next) | |
8502 | { | |
8503 | struct elf_dyn_relocs *p; | |
8504 | ||
8505 | for (p = (struct elf_dyn_relocs *) | |
8506 | (elf_section_data (s)->local_dynrel); p != NULL; p = p->next) | |
8507 | { | |
8508 | if (!bfd_is_abs_section (p->sec) | |
8509 | && bfd_is_abs_section (p->sec->output_section)) | |
8510 | { | |
8511 | /* Input section has been discarded, either because | |
8512 | it is a copy of a linkonce section or due to | |
8513 | linker script /DISCARD/, so we'll be discarding | |
8514 | the relocs too. */ | |
8515 | } | |
8516 | else if (p->count != 0) | |
8517 | { | |
8518 | srel = elf_section_data (p->sec)->sreloc; | |
8519 | srel->size += p->count * RELOC_SIZE (htab); | |
8520 | if ((p->sec->output_section->flags & SEC_READONLY) != 0) | |
8521 | info->flags |= DF_TEXTREL; | |
8522 | } | |
8523 | } | |
8524 | } | |
8525 | ||
cec5225b | 8526 | locals = elf_aarch64_locals (ibfd); |
a06ea964 NC |
8527 | if (!locals) |
8528 | continue; | |
8529 | ||
8530 | symtab_hdr = &elf_symtab_hdr (ibfd); | |
8531 | srel = htab->root.srelgot; | |
8532 | for (i = 0; i < symtab_hdr->sh_info; i++) | |
8533 | { | |
8534 | locals[i].got_offset = (bfd_vma) - 1; | |
8535 | locals[i].tlsdesc_got_jump_table_offset = (bfd_vma) - 1; | |
8536 | if (locals[i].got_refcount > 0) | |
8537 | { | |
8538 | unsigned got_type = locals[i].got_type; | |
8539 | if (got_type & GOT_TLSDESC_GD) | |
8540 | { | |
8541 | locals[i].tlsdesc_got_jump_table_offset = | |
8542 | (htab->root.sgotplt->size | |
8543 | - aarch64_compute_jump_table_size (htab)); | |
8544 | htab->root.sgotplt->size += GOT_ENTRY_SIZE * 2; | |
8545 | locals[i].got_offset = (bfd_vma) - 2; | |
8546 | } | |
8547 | ||
8548 | if (got_type & GOT_TLS_GD) | |
8549 | { | |
8550 | locals[i].got_offset = htab->root.sgot->size; | |
8551 | htab->root.sgot->size += GOT_ENTRY_SIZE * 2; | |
8552 | } | |
8553 | ||
b53b1bed JW |
8554 | if (got_type & GOT_TLS_IE |
8555 | || got_type & GOT_NORMAL) | |
a06ea964 NC |
8556 | { |
8557 | locals[i].got_offset = htab->root.sgot->size; | |
8558 | htab->root.sgot->size += GOT_ENTRY_SIZE; | |
8559 | } | |
8560 | ||
8561 | if (got_type == GOT_UNKNOWN) | |
8562 | { | |
8563 | } | |
8564 | ||
0e1862bb | 8565 | if (bfd_link_pic (info)) |
a06ea964 NC |
8566 | { |
8567 | if (got_type & GOT_TLSDESC_GD) | |
8568 | { | |
8569 | htab->root.srelplt->size += RELOC_SIZE (htab); | |
8570 | /* Note RELOC_COUNT not incremented here! */ | |
8571 | htab->tlsdesc_plt = (bfd_vma) - 1; | |
8572 | } | |
8573 | ||
8574 | if (got_type & GOT_TLS_GD) | |
8575 | htab->root.srelgot->size += RELOC_SIZE (htab) * 2; | |
8576 | ||
b53b1bed JW |
8577 | if (got_type & GOT_TLS_IE |
8578 | || got_type & GOT_NORMAL) | |
a06ea964 NC |
8579 | htab->root.srelgot->size += RELOC_SIZE (htab); |
8580 | } | |
8581 | } | |
8582 | else | |
8583 | { | |
8584 | locals[i].got_refcount = (bfd_vma) - 1; | |
8585 | } | |
8586 | } | |
8587 | } | |
8588 | ||
8589 | ||
8590 | /* Allocate global sym .plt and .got entries, and space for global | |
8591 | sym dynamic relocs. */ | |
cec5225b | 8592 | elf_link_hash_traverse (&htab->root, elfNN_aarch64_allocate_dynrelocs, |
a06ea964 NC |
8593 | info); |
8594 | ||
1419bbe5 WN |
8595 | /* Allocate global ifunc sym .plt and .got entries, and space for global |
8596 | ifunc sym dynamic relocs. */ | |
8597 | elf_link_hash_traverse (&htab->root, elfNN_aarch64_allocate_ifunc_dynrelocs, | |
8598 | info); | |
8599 | ||
8600 | /* Allocate .plt and .got entries, and space for local symbols. */ | |
8601 | htab_traverse (htab->loc_hash_table, | |
8602 | elfNN_aarch64_allocate_local_dynrelocs, | |
8603 | info); | |
8604 | ||
8605 | /* Allocate .plt and .got entries, and space for local ifunc symbols. */ | |
8606 | htab_traverse (htab->loc_hash_table, | |
8607 | elfNN_aarch64_allocate_local_ifunc_dynrelocs, | |
8608 | info); | |
a06ea964 NC |
8609 | |
8610 | /* For every jump slot reserved in the sgotplt, reloc_count is | |
8611 | incremented. However, when we reserve space for TLS descriptors, | |
8612 | it's not incremented, so in order to compute the space reserved | |
8613 | for them, it suffices to multiply the reloc count by the jump | |
8614 | slot size. */ | |
8615 | ||
8616 | if (htab->root.srelplt) | |
8847944f | 8617 | htab->sgotplt_jump_table_size = aarch64_compute_jump_table_size (htab); |
a06ea964 NC |
8618 | |
8619 | if (htab->tlsdesc_plt) | |
8620 | { | |
8621 | if (htab->root.splt->size == 0) | |
8622 | htab->root.splt->size += PLT_ENTRY_SIZE; | |
8623 | ||
8624 | htab->tlsdesc_plt = htab->root.splt->size; | |
8625 | htab->root.splt->size += PLT_TLSDESC_ENTRY_SIZE; | |
8626 | ||
8627 | /* If we're not using lazy TLS relocations, don't generate the | |
8628 | GOT entry required. */ | |
8629 | if (!(info->flags & DF_BIND_NOW)) | |
8630 | { | |
8631 | htab->dt_tlsdesc_got = htab->root.sgot->size; | |
8632 | htab->root.sgot->size += GOT_ENTRY_SIZE; | |
8633 | } | |
8634 | } | |
8635 | ||
68fcca92 | 8636 | /* Init mapping symbols information to use later to distingush between |
4106101c MS |
8637 | code and data while scanning for errata. */ |
8638 | if (htab->fix_erratum_835769 || htab->fix_erratum_843419) | |
68fcca92 JW |
8639 | for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link.next) |
8640 | { | |
8641 | if (!is_aarch64_elf (ibfd)) | |
8642 | continue; | |
8643 | bfd_elfNN_aarch64_init_maps (ibfd); | |
8644 | } | |
8645 | ||
a06ea964 NC |
8646 | /* We now have determined the sizes of the various dynamic sections. |
8647 | Allocate memory for them. */ | |
8648 | relocs = FALSE; | |
8649 | for (s = dynobj->sections; s != NULL; s = s->next) | |
8650 | { | |
8651 | if ((s->flags & SEC_LINKER_CREATED) == 0) | |
8652 | continue; | |
8653 | ||
8654 | if (s == htab->root.splt | |
8655 | || s == htab->root.sgot | |
8656 | || s == htab->root.sgotplt | |
8657 | || s == htab->root.iplt | |
9d19e4fd | 8658 | || s == htab->root.igotplt |
5474d94f AM |
8659 | || s == htab->root.sdynbss |
8660 | || s == htab->root.sdynrelro) | |
a06ea964 NC |
8661 | { |
8662 | /* Strip this section if we don't need it; see the | |
8663 | comment below. */ | |
8664 | } | |
8665 | else if (CONST_STRNEQ (bfd_get_section_name (dynobj, s), ".rela")) | |
8666 | { | |
8667 | if (s->size != 0 && s != htab->root.srelplt) | |
8668 | relocs = TRUE; | |
8669 | ||
8670 | /* We use the reloc_count field as a counter if we need | |
8671 | to copy relocs into the output file. */ | |
8672 | if (s != htab->root.srelplt) | |
8673 | s->reloc_count = 0; | |
8674 | } | |
8675 | else | |
8676 | { | |
8677 | /* It's not one of our sections, so don't allocate space. */ | |
8678 | continue; | |
8679 | } | |
8680 | ||
8681 | if (s->size == 0) | |
8682 | { | |
8683 | /* If we don't need this section, strip it from the | |
8684 | output file. This is mostly to handle .rela.bss and | |
8685 | .rela.plt. We must create both sections in | |
8686 | create_dynamic_sections, because they must be created | |
8687 | before the linker maps input sections to output | |
8688 | sections. The linker does that before | |
8689 | adjust_dynamic_symbol is called, and it is that | |
8690 | function which decides whether anything needs to go | |
8691 | into these sections. */ | |
a06ea964 NC |
8692 | s->flags |= SEC_EXCLUDE; |
8693 | continue; | |
8694 | } | |
8695 | ||
8696 | if ((s->flags & SEC_HAS_CONTENTS) == 0) | |
8697 | continue; | |
8698 | ||
8699 | /* Allocate memory for the section contents. We use bfd_zalloc | |
8700 | here in case unused entries are not reclaimed before the | |
8701 | section's contents are written out. This should not happen, | |
8702 | but this way if it does, we get a R_AARCH64_NONE reloc instead | |
8703 | of garbage. */ | |
8704 | s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->size); | |
8705 | if (s->contents == NULL) | |
8706 | return FALSE; | |
8707 | } | |
8708 | ||
8709 | if (htab->root.dynamic_sections_created) | |
8710 | { | |
8711 | /* Add some entries to the .dynamic section. We fill in the | |
cec5225b | 8712 | values later, in elfNN_aarch64_finish_dynamic_sections, but we |
a06ea964 NC |
8713 | must add the entries now so that we get the correct size for |
8714 | the .dynamic section. The DT_DEBUG entry is filled in by the | |
8715 | dynamic linker and used by the debugger. */ | |
8716 | #define add_dynamic_entry(TAG, VAL) \ | |
8717 | _bfd_elf_add_dynamic_entry (info, TAG, VAL) | |
8718 | ||
0e1862bb | 8719 | if (bfd_link_executable (info)) |
a06ea964 NC |
8720 | { |
8721 | if (!add_dynamic_entry (DT_DEBUG, 0)) | |
8722 | return FALSE; | |
8723 | } | |
8724 | ||
8725 | if (htab->root.splt->size != 0) | |
8726 | { | |
8727 | if (!add_dynamic_entry (DT_PLTGOT, 0) | |
8728 | || !add_dynamic_entry (DT_PLTRELSZ, 0) | |
8729 | || !add_dynamic_entry (DT_PLTREL, DT_RELA) | |
8730 | || !add_dynamic_entry (DT_JMPREL, 0)) | |
8731 | return FALSE; | |
8732 | ||
8733 | if (htab->tlsdesc_plt | |
8734 | && (!add_dynamic_entry (DT_TLSDESC_PLT, 0) | |
8735 | || !add_dynamic_entry (DT_TLSDESC_GOT, 0))) | |
8736 | return FALSE; | |
8737 | } | |
8738 | ||
8739 | if (relocs) | |
8740 | { | |
8741 | if (!add_dynamic_entry (DT_RELA, 0) | |
8742 | || !add_dynamic_entry (DT_RELASZ, 0) | |
8743 | || !add_dynamic_entry (DT_RELAENT, RELOC_SIZE (htab))) | |
8744 | return FALSE; | |
8745 | ||
8746 | /* If any dynamic relocs apply to a read-only section, | |
8747 | then we need a DT_TEXTREL entry. */ | |
c2170589 JW |
8748 | if ((info->flags & DF_TEXTREL) == 0) |
8749 | elf_link_hash_traverse (& htab->root, aarch64_readonly_dynrelocs, | |
8750 | info); | |
8751 | ||
a06ea964 NC |
8752 | if ((info->flags & DF_TEXTREL) != 0) |
8753 | { | |
8754 | if (!add_dynamic_entry (DT_TEXTREL, 0)) | |
8755 | return FALSE; | |
8756 | } | |
8757 | } | |
8758 | } | |
8759 | #undef add_dynamic_entry | |
8760 | ||
8761 | return TRUE; | |
a06ea964 NC |
8762 | } |
8763 | ||
8764 | static inline void | |
caed7120 YZ |
8765 | elf_aarch64_update_plt_entry (bfd *output_bfd, |
8766 | bfd_reloc_code_real_type r_type, | |
8767 | bfd_byte *plt_entry, bfd_vma value) | |
a06ea964 | 8768 | { |
caed7120 YZ |
8769 | reloc_howto_type *howto = elfNN_aarch64_howto_from_bfd_reloc (r_type); |
8770 | ||
1d75a8e2 NC |
8771 | /* FIXME: We should check the return value from this function call. */ |
8772 | (void) _bfd_aarch64_elf_put_addend (output_bfd, plt_entry, r_type, howto, value); | |
a06ea964 NC |
8773 | } |
8774 | ||
8775 | static void | |
cec5225b YZ |
8776 | elfNN_aarch64_create_small_pltn_entry (struct elf_link_hash_entry *h, |
8777 | struct elf_aarch64_link_hash_table | |
1419bbe5 WN |
8778 | *htab, bfd *output_bfd, |
8779 | struct bfd_link_info *info) | |
a06ea964 NC |
8780 | { |
8781 | bfd_byte *plt_entry; | |
8782 | bfd_vma plt_index; | |
8783 | bfd_vma got_offset; | |
8784 | bfd_vma gotplt_entry_address; | |
8785 | bfd_vma plt_entry_address; | |
8786 | Elf_Internal_Rela rela; | |
8787 | bfd_byte *loc; | |
1419bbe5 WN |
8788 | asection *plt, *gotplt, *relplt; |
8789 | ||
8790 | /* When building a static executable, use .iplt, .igot.plt and | |
8791 | .rela.iplt sections for STT_GNU_IFUNC symbols. */ | |
8792 | if (htab->root.splt != NULL) | |
8793 | { | |
8794 | plt = htab->root.splt; | |
8795 | gotplt = htab->root.sgotplt; | |
8796 | relplt = htab->root.srelplt; | |
8797 | } | |
8798 | else | |
8799 | { | |
8800 | plt = htab->root.iplt; | |
8801 | gotplt = htab->root.igotplt; | |
8802 | relplt = htab->root.irelplt; | |
8803 | } | |
8804 | ||
8805 | /* Get the index in the procedure linkage table which | |
8806 | corresponds to this symbol. This is the index of this symbol | |
8807 | in all the symbols for which we are making plt entries. The | |
8808 | first entry in the procedure linkage table is reserved. | |
a06ea964 | 8809 | |
1419bbe5 WN |
8810 | Get the offset into the .got table of the entry that |
8811 | corresponds to this function. Each .got entry is GOT_ENTRY_SIZE | |
8812 | bytes. The first three are reserved for the dynamic linker. | |
692e2b8b | 8813 | |
1419bbe5 WN |
8814 | For static executables, we don't reserve anything. */ |
8815 | ||
8816 | if (plt == htab->root.splt) | |
8817 | { | |
8818 | plt_index = (h->plt.offset - htab->plt_header_size) / htab->plt_entry_size; | |
8819 | got_offset = (plt_index + 3) * GOT_ENTRY_SIZE; | |
8820 | } | |
8821 | else | |
8822 | { | |
8823 | plt_index = h->plt.offset / htab->plt_entry_size; | |
8824 | got_offset = plt_index * GOT_ENTRY_SIZE; | |
8825 | } | |
8826 | ||
8827 | plt_entry = plt->contents + h->plt.offset; | |
8828 | plt_entry_address = plt->output_section->vma | |
f44a1f8e | 8829 | + plt->output_offset + h->plt.offset; |
1419bbe5 WN |
8830 | gotplt_entry_address = gotplt->output_section->vma + |
8831 | gotplt->output_offset + got_offset; | |
a06ea964 NC |
8832 | |
8833 | /* Copy in the boiler-plate for the PLTn entry. */ | |
cec5225b | 8834 | memcpy (plt_entry, elfNN_aarch64_small_plt_entry, PLT_SMALL_ENTRY_SIZE); |
a06ea964 NC |
8835 | |
8836 | /* Fill in the top 21 bits for this: ADRP x16, PLT_GOT + n * 8. | |
8837 | ADRP: ((PG(S+A)-PG(P)) >> 12) & 0x1fffff */ | |
caed7120 YZ |
8838 | elf_aarch64_update_plt_entry (output_bfd, BFD_RELOC_AARCH64_ADR_HI21_PCREL, |
8839 | plt_entry, | |
8840 | PG (gotplt_entry_address) - | |
8841 | PG (plt_entry_address)); | |
a06ea964 NC |
8842 | |
8843 | /* Fill in the lo12 bits for the load from the pltgot. */ | |
caed7120 YZ |
8844 | elf_aarch64_update_plt_entry (output_bfd, BFD_RELOC_AARCH64_LDSTNN_LO12, |
8845 | plt_entry + 4, | |
8846 | PG_OFFSET (gotplt_entry_address)); | |
a06ea964 | 8847 | |
9aff4b7a | 8848 | /* Fill in the lo12 bits for the add from the pltgot entry. */ |
caed7120 YZ |
8849 | elf_aarch64_update_plt_entry (output_bfd, BFD_RELOC_AARCH64_ADD_LO12, |
8850 | plt_entry + 8, | |
8851 | PG_OFFSET (gotplt_entry_address)); | |
a06ea964 NC |
8852 | |
8853 | /* All the GOTPLT Entries are essentially initialized to PLT0. */ | |
cec5225b | 8854 | bfd_put_NN (output_bfd, |
1419bbe5 WN |
8855 | plt->output_section->vma + plt->output_offset, |
8856 | gotplt->contents + got_offset); | |
a06ea964 | 8857 | |
a06ea964 | 8858 | rela.r_offset = gotplt_entry_address; |
1419bbe5 WN |
8859 | |
8860 | if (h->dynindx == -1 | |
0e1862bb | 8861 | || ((bfd_link_executable (info) |
1419bbe5 WN |
8862 | || ELF_ST_VISIBILITY (h->other) != STV_DEFAULT) |
8863 | && h->def_regular | |
8864 | && h->type == STT_GNU_IFUNC)) | |
8865 | { | |
8866 | /* If an STT_GNU_IFUNC symbol is locally defined, generate | |
8867 | R_AARCH64_IRELATIVE instead of R_AARCH64_JUMP_SLOT. */ | |
8868 | rela.r_info = ELFNN_R_INFO (0, AARCH64_R (IRELATIVE)); | |
8869 | rela.r_addend = (h->root.u.def.value | |
8870 | + h->root.u.def.section->output_section->vma | |
8871 | + h->root.u.def.section->output_offset); | |
8872 | } | |
8873 | else | |
8874 | { | |
8875 | /* Fill in the entry in the .rela.plt section. */ | |
8876 | rela.r_info = ELFNN_R_INFO (h->dynindx, AARCH64_R (JUMP_SLOT)); | |
8877 | rela.r_addend = 0; | |
8878 | } | |
a06ea964 NC |
8879 | |
8880 | /* Compute the relocation entry to used based on PLT index and do | |
8881 | not adjust reloc_count. The reloc_count has already been adjusted | |
8882 | to account for this entry. */ | |
1419bbe5 | 8883 | loc = relplt->contents + plt_index * RELOC_SIZE (htab); |
cec5225b | 8884 | bfd_elfNN_swap_reloca_out (output_bfd, &rela, loc); |
a06ea964 NC |
8885 | } |
8886 | ||
8887 | /* Size sections even though they're not dynamic. We use it to setup | |
8888 | _TLS_MODULE_BASE_, if needed. */ | |
8889 | ||
8890 | static bfd_boolean | |
cec5225b | 8891 | elfNN_aarch64_always_size_sections (bfd *output_bfd, |
a06ea964 NC |
8892 | struct bfd_link_info *info) |
8893 | { | |
8894 | asection *tls_sec; | |
8895 | ||
0e1862bb | 8896 | if (bfd_link_relocatable (info)) |
a06ea964 NC |
8897 | return TRUE; |
8898 | ||
8899 | tls_sec = elf_hash_table (info)->tls_sec; | |
8900 | ||
8901 | if (tls_sec) | |
8902 | { | |
8903 | struct elf_link_hash_entry *tlsbase; | |
8904 | ||
8905 | tlsbase = elf_link_hash_lookup (elf_hash_table (info), | |
8906 | "_TLS_MODULE_BASE_", TRUE, TRUE, FALSE); | |
8907 | ||
8908 | if (tlsbase) | |
8909 | { | |
8910 | struct bfd_link_hash_entry *h = NULL; | |
8911 | const struct elf_backend_data *bed = | |
8912 | get_elf_backend_data (output_bfd); | |
8913 | ||
8914 | if (!(_bfd_generic_link_add_one_symbol | |
8915 | (info, output_bfd, "_TLS_MODULE_BASE_", BSF_LOCAL, | |
8916 | tls_sec, 0, NULL, FALSE, bed->collect, &h))) | |
8917 | return FALSE; | |
8918 | ||
8919 | tlsbase->type = STT_TLS; | |
8920 | tlsbase = (struct elf_link_hash_entry *) h; | |
8921 | tlsbase->def_regular = 1; | |
8922 | tlsbase->other = STV_HIDDEN; | |
8923 | (*bed->elf_backend_hide_symbol) (info, tlsbase, TRUE); | |
8924 | } | |
8925 | } | |
8926 | ||
8927 | return TRUE; | |
8928 | } | |
8929 | ||
8930 | /* Finish up dynamic symbol handling. We set the contents of various | |
8931 | dynamic sections here. */ | |
2d0ca824 | 8932 | |
a06ea964 | 8933 | static bfd_boolean |
cec5225b | 8934 | elfNN_aarch64_finish_dynamic_symbol (bfd *output_bfd, |
a06ea964 NC |
8935 | struct bfd_link_info *info, |
8936 | struct elf_link_hash_entry *h, | |
8937 | Elf_Internal_Sym *sym) | |
8938 | { | |
cec5225b YZ |
8939 | struct elf_aarch64_link_hash_table *htab; |
8940 | htab = elf_aarch64_hash_table (info); | |
a06ea964 NC |
8941 | |
8942 | if (h->plt.offset != (bfd_vma) - 1) | |
8943 | { | |
1419bbe5 WN |
8944 | asection *plt, *gotplt, *relplt; |
8945 | ||
a06ea964 NC |
8946 | /* This symbol has an entry in the procedure linkage table. Set |
8947 | it up. */ | |
8948 | ||
1419bbe5 WN |
8949 | /* When building a static executable, use .iplt, .igot.plt and |
8950 | .rela.iplt sections for STT_GNU_IFUNC symbols. */ | |
8951 | if (htab->root.splt != NULL) | |
8952 | { | |
8953 | plt = htab->root.splt; | |
8954 | gotplt = htab->root.sgotplt; | |
8955 | relplt = htab->root.srelplt; | |
8956 | } | |
8957 | else | |
8958 | { | |
8959 | plt = htab->root.iplt; | |
8960 | gotplt = htab->root.igotplt; | |
8961 | relplt = htab->root.irelplt; | |
8962 | } | |
8963 | ||
8964 | /* This symbol has an entry in the procedure linkage table. Set | |
8965 | it up. */ | |
8966 | if ((h->dynindx == -1 | |
0e1862bb | 8967 | && !((h->forced_local || bfd_link_executable (info)) |
1419bbe5 WN |
8968 | && h->def_regular |
8969 | && h->type == STT_GNU_IFUNC)) | |
8970 | || plt == NULL | |
8971 | || gotplt == NULL | |
8972 | || relplt == NULL) | |
f955cccf | 8973 | return FALSE; |
a06ea964 | 8974 | |
1419bbe5 | 8975 | elfNN_aarch64_create_small_pltn_entry (h, htab, output_bfd, info); |
a06ea964 NC |
8976 | if (!h->def_regular) |
8977 | { | |
8978 | /* Mark the symbol as undefined, rather than as defined in | |
46b87d49 | 8979 | the .plt section. */ |
a06ea964 | 8980 | sym->st_shndx = SHN_UNDEF; |
46b87d49 WN |
8981 | /* If the symbol is weak we need to clear the value. |
8982 | Otherwise, the PLT entry would provide a definition for | |
8983 | the symbol even if the symbol wasn't defined anywhere, | |
8984 | and so the symbol would never be NULL. Leave the value if | |
8985 | there were any relocations where pointer equality matters | |
8986 | (this is a clue for the dynamic linker, to make function | |
8987 | pointer comparisons work between an application and shared | |
8988 | library). */ | |
8989 | if (!h->ref_regular_nonweak || !h->pointer_equality_needed) | |
8990 | sym->st_value = 0; | |
a06ea964 NC |
8991 | } |
8992 | } | |
8993 | ||
8994 | if (h->got.offset != (bfd_vma) - 1 | |
cec5225b | 8995 | && elf_aarch64_hash_entry (h)->got_type == GOT_NORMAL) |
a06ea964 NC |
8996 | { |
8997 | Elf_Internal_Rela rela; | |
8998 | bfd_byte *loc; | |
8999 | ||
9000 | /* This symbol has an entry in the global offset table. Set it | |
9001 | up. */ | |
9002 | if (htab->root.sgot == NULL || htab->root.srelgot == NULL) | |
9003 | abort (); | |
9004 | ||
9005 | rela.r_offset = (htab->root.sgot->output_section->vma | |
9006 | + htab->root.sgot->output_offset | |
9007 | + (h->got.offset & ~(bfd_vma) 1)); | |
9008 | ||
49206388 WN |
9009 | if (h->def_regular |
9010 | && h->type == STT_GNU_IFUNC) | |
9011 | { | |
0e1862bb | 9012 | if (bfd_link_pic (info)) |
49206388 WN |
9013 | { |
9014 | /* Generate R_AARCH64_GLOB_DAT. */ | |
9015 | goto do_glob_dat; | |
9016 | } | |
9017 | else | |
9018 | { | |
9019 | asection *plt; | |
9020 | ||
9021 | if (!h->pointer_equality_needed) | |
9022 | abort (); | |
9023 | ||
9024 | /* For non-shared object, we can't use .got.plt, which | |
9025 | contains the real function address if we need pointer | |
9026 | equality. We load the GOT entry with the PLT entry. */ | |
9027 | plt = htab->root.splt ? htab->root.splt : htab->root.iplt; | |
9028 | bfd_put_NN (output_bfd, (plt->output_section->vma | |
9029 | + plt->output_offset | |
9030 | + h->plt.offset), | |
9031 | htab->root.sgot->contents | |
9032 | + (h->got.offset & ~(bfd_vma) 1)); | |
9033 | return TRUE; | |
9034 | } | |
9035 | } | |
0e1862bb | 9036 | else if (bfd_link_pic (info) && SYMBOL_REFERENCES_LOCAL (info, h)) |
a06ea964 | 9037 | { |
0ee3a6db | 9038 | if (!(h->def_regular || ELF_COMMON_DEF_P (h))) |
a06ea964 NC |
9039 | return FALSE; |
9040 | ||
9041 | BFD_ASSERT ((h->got.offset & 1) != 0); | |
a6bb11b2 | 9042 | rela.r_info = ELFNN_R_INFO (0, AARCH64_R (RELATIVE)); |
a06ea964 NC |
9043 | rela.r_addend = (h->root.u.def.value |
9044 | + h->root.u.def.section->output_section->vma | |
9045 | + h->root.u.def.section->output_offset); | |
9046 | } | |
9047 | else | |
9048 | { | |
49206388 | 9049 | do_glob_dat: |
a06ea964 | 9050 | BFD_ASSERT ((h->got.offset & 1) == 0); |
cec5225b | 9051 | bfd_put_NN (output_bfd, (bfd_vma) 0, |
a06ea964 | 9052 | htab->root.sgot->contents + h->got.offset); |
a6bb11b2 | 9053 | rela.r_info = ELFNN_R_INFO (h->dynindx, AARCH64_R (GLOB_DAT)); |
a06ea964 NC |
9054 | rela.r_addend = 0; |
9055 | } | |
9056 | ||
9057 | loc = htab->root.srelgot->contents; | |
9058 | loc += htab->root.srelgot->reloc_count++ * RELOC_SIZE (htab); | |
cec5225b | 9059 | bfd_elfNN_swap_reloca_out (output_bfd, &rela, loc); |
a06ea964 NC |
9060 | } |
9061 | ||
9062 | if (h->needs_copy) | |
9063 | { | |
9064 | Elf_Internal_Rela rela; | |
5474d94f | 9065 | asection *s; |
a06ea964 NC |
9066 | bfd_byte *loc; |
9067 | ||
9068 | /* This symbol needs a copy reloc. Set it up. */ | |
a06ea964 NC |
9069 | if (h->dynindx == -1 |
9070 | || (h->root.type != bfd_link_hash_defined | |
9071 | && h->root.type != bfd_link_hash_defweak) | |
9d19e4fd | 9072 | || htab->root.srelbss == NULL) |
a06ea964 NC |
9073 | abort (); |
9074 | ||
9075 | rela.r_offset = (h->root.u.def.value | |
9076 | + h->root.u.def.section->output_section->vma | |
9077 | + h->root.u.def.section->output_offset); | |
a6bb11b2 | 9078 | rela.r_info = ELFNN_R_INFO (h->dynindx, AARCH64_R (COPY)); |
a06ea964 | 9079 | rela.r_addend = 0; |
afbf7e8e | 9080 | if (h->root.u.def.section == htab->root.sdynrelro) |
5474d94f AM |
9081 | s = htab->root.sreldynrelro; |
9082 | else | |
9083 | s = htab->root.srelbss; | |
9084 | loc = s->contents + s->reloc_count++ * RELOC_SIZE (htab); | |
cec5225b | 9085 | bfd_elfNN_swap_reloca_out (output_bfd, &rela, loc); |
a06ea964 NC |
9086 | } |
9087 | ||
9088 | /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. SYM may | |
9089 | be NULL for local symbols. */ | |
9090 | if (sym != NULL | |
9637f6ef | 9091 | && (h == elf_hash_table (info)->hdynamic |
a06ea964 NC |
9092 | || h == elf_hash_table (info)->hgot)) |
9093 | sym->st_shndx = SHN_ABS; | |
9094 | ||
9095 | return TRUE; | |
9096 | } | |
9097 | ||
1419bbe5 WN |
9098 | /* Finish up local dynamic symbol handling. We set the contents of |
9099 | various dynamic sections here. */ | |
9100 | ||
9101 | static bfd_boolean | |
9102 | elfNN_aarch64_finish_local_dynamic_symbol (void **slot, void *inf) | |
9103 | { | |
9104 | struct elf_link_hash_entry *h | |
9105 | = (struct elf_link_hash_entry *) *slot; | |
9106 | struct bfd_link_info *info | |
9107 | = (struct bfd_link_info *) inf; | |
9108 | ||
9109 | return elfNN_aarch64_finish_dynamic_symbol (info->output_bfd, | |
9110 | info, h, NULL); | |
9111 | } | |
9112 | ||
a06ea964 | 9113 | static void |
cec5225b YZ |
9114 | elfNN_aarch64_init_small_plt0_entry (bfd *output_bfd ATTRIBUTE_UNUSED, |
9115 | struct elf_aarch64_link_hash_table | |
a06ea964 NC |
9116 | *htab) |
9117 | { | |
9118 | /* Fill in PLT0. Fixme:RR Note this doesn't distinguish between | |
9119 | small and large plts and at the minute just generates | |
9120 | the small PLT. */ | |
9121 | ||
cec5225b | 9122 | /* PLT0 of the small PLT looks like this in ELF64 - |
a06ea964 NC |
9123 | stp x16, x30, [sp, #-16]! // Save the reloc and lr on stack. |
9124 | adrp x16, PLT_GOT + 16 // Get the page base of the GOTPLT | |
9125 | ldr x17, [x16, #:lo12:PLT_GOT+16] // Load the address of the | |
9126 | // symbol resolver | |
9127 | add x16, x16, #:lo12:PLT_GOT+16 // Load the lo12 bits of the | |
9128 | // GOTPLT entry for this. | |
9129 | br x17 | |
cec5225b | 9130 | PLT0 will be slightly different in ELF32 due to different got entry |
2d0ca824 | 9131 | size. */ |
caed7120 | 9132 | bfd_vma plt_got_2nd_ent; /* Address of GOT[2]. */ |
a06ea964 NC |
9133 | bfd_vma plt_base; |
9134 | ||
9135 | ||
cec5225b | 9136 | memcpy (htab->root.splt->contents, elfNN_aarch64_small_plt0_entry, |
a06ea964 NC |
9137 | PLT_ENTRY_SIZE); |
9138 | elf_section_data (htab->root.splt->output_section)->this_hdr.sh_entsize = | |
9139 | PLT_ENTRY_SIZE; | |
9140 | ||
caed7120 YZ |
9141 | plt_got_2nd_ent = (htab->root.sgotplt->output_section->vma |
9142 | + htab->root.sgotplt->output_offset | |
9143 | + GOT_ENTRY_SIZE * 2); | |
a06ea964 NC |
9144 | |
9145 | plt_base = htab->root.splt->output_section->vma + | |
f44a1f8e | 9146 | htab->root.splt->output_offset; |
a06ea964 NC |
9147 | |
9148 | /* Fill in the top 21 bits for this: ADRP x16, PLT_GOT + n * 8. | |
9149 | ADRP: ((PG(S+A)-PG(P)) >> 12) & 0x1fffff */ | |
caed7120 YZ |
9150 | elf_aarch64_update_plt_entry (output_bfd, BFD_RELOC_AARCH64_ADR_HI21_PCREL, |
9151 | htab->root.splt->contents + 4, | |
9152 | PG (plt_got_2nd_ent) - PG (plt_base + 4)); | |
a06ea964 | 9153 | |
caed7120 YZ |
9154 | elf_aarch64_update_plt_entry (output_bfd, BFD_RELOC_AARCH64_LDSTNN_LO12, |
9155 | htab->root.splt->contents + 8, | |
9156 | PG_OFFSET (plt_got_2nd_ent)); | |
a06ea964 | 9157 | |
caed7120 YZ |
9158 | elf_aarch64_update_plt_entry (output_bfd, BFD_RELOC_AARCH64_ADD_LO12, |
9159 | htab->root.splt->contents + 12, | |
9160 | PG_OFFSET (plt_got_2nd_ent)); | |
a06ea964 NC |
9161 | } |
9162 | ||
9163 | static bfd_boolean | |
cec5225b | 9164 | elfNN_aarch64_finish_dynamic_sections (bfd *output_bfd, |
a06ea964 NC |
9165 | struct bfd_link_info *info) |
9166 | { | |
cec5225b | 9167 | struct elf_aarch64_link_hash_table *htab; |
a06ea964 NC |
9168 | bfd *dynobj; |
9169 | asection *sdyn; | |
9170 | ||
cec5225b | 9171 | htab = elf_aarch64_hash_table (info); |
a06ea964 NC |
9172 | dynobj = htab->root.dynobj; |
9173 | sdyn = bfd_get_linker_section (dynobj, ".dynamic"); | |
9174 | ||
9175 | if (htab->root.dynamic_sections_created) | |
9176 | { | |
cec5225b | 9177 | ElfNN_External_Dyn *dyncon, *dynconend; |
a06ea964 NC |
9178 | |
9179 | if (sdyn == NULL || htab->root.sgot == NULL) | |
9180 | abort (); | |
9181 | ||
cec5225b YZ |
9182 | dyncon = (ElfNN_External_Dyn *) sdyn->contents; |
9183 | dynconend = (ElfNN_External_Dyn *) (sdyn->contents + sdyn->size); | |
a06ea964 NC |
9184 | for (; dyncon < dynconend; dyncon++) |
9185 | { | |
9186 | Elf_Internal_Dyn dyn; | |
9187 | asection *s; | |
9188 | ||
cec5225b | 9189 | bfd_elfNN_swap_dyn_in (dynobj, dyncon, &dyn); |
a06ea964 NC |
9190 | |
9191 | switch (dyn.d_tag) | |
9192 | { | |
9193 | default: | |
9194 | continue; | |
9195 | ||
9196 | case DT_PLTGOT: | |
9197 | s = htab->root.sgotplt; | |
9198 | dyn.d_un.d_ptr = s->output_section->vma + s->output_offset; | |
9199 | break; | |
9200 | ||
9201 | case DT_JMPREL: | |
4ade44b7 AM |
9202 | s = htab->root.srelplt; |
9203 | dyn.d_un.d_ptr = s->output_section->vma + s->output_offset; | |
a06ea964 NC |
9204 | break; |
9205 | ||
9206 | case DT_PLTRELSZ: | |
c955de36 | 9207 | s = htab->root.srelplt; |
a06ea964 NC |
9208 | dyn.d_un.d_val = s->size; |
9209 | break; | |
9210 | ||
a06ea964 NC |
9211 | case DT_TLSDESC_PLT: |
9212 | s = htab->root.splt; | |
9213 | dyn.d_un.d_ptr = s->output_section->vma + s->output_offset | |
9214 | + htab->tlsdesc_plt; | |
9215 | break; | |
9216 | ||
9217 | case DT_TLSDESC_GOT: | |
9218 | s = htab->root.sgot; | |
9219 | dyn.d_un.d_ptr = s->output_section->vma + s->output_offset | |
9220 | + htab->dt_tlsdesc_got; | |
9221 | break; | |
9222 | } | |
9223 | ||
cec5225b | 9224 | bfd_elfNN_swap_dyn_out (output_bfd, &dyn, dyncon); |
a06ea964 NC |
9225 | } |
9226 | ||
9227 | } | |
9228 | ||
9229 | /* Fill in the special first entry in the procedure linkage table. */ | |
9230 | if (htab->root.splt && htab->root.splt->size > 0) | |
9231 | { | |
cec5225b | 9232 | elfNN_aarch64_init_small_plt0_entry (output_bfd, htab); |
a06ea964 NC |
9233 | |
9234 | elf_section_data (htab->root.splt->output_section)-> | |
9235 | this_hdr.sh_entsize = htab->plt_entry_size; | |
9236 | ||
9237 | ||
9238 | if (htab->tlsdesc_plt) | |
9239 | { | |
cec5225b | 9240 | bfd_put_NN (output_bfd, (bfd_vma) 0, |
a06ea964 NC |
9241 | htab->root.sgot->contents + htab->dt_tlsdesc_got); |
9242 | ||
9243 | memcpy (htab->root.splt->contents + htab->tlsdesc_plt, | |
cec5225b YZ |
9244 | elfNN_aarch64_tlsdesc_small_plt_entry, |
9245 | sizeof (elfNN_aarch64_tlsdesc_small_plt_entry)); | |
a06ea964 NC |
9246 | |
9247 | { | |
9248 | bfd_vma adrp1_addr = | |
9249 | htab->root.splt->output_section->vma | |
9250 | + htab->root.splt->output_offset + htab->tlsdesc_plt + 4; | |
9251 | ||
caed7120 | 9252 | bfd_vma adrp2_addr = adrp1_addr + 4; |
a06ea964 NC |
9253 | |
9254 | bfd_vma got_addr = | |
9255 | htab->root.sgot->output_section->vma | |
9256 | + htab->root.sgot->output_offset; | |
9257 | ||
9258 | bfd_vma pltgot_addr = | |
9259 | htab->root.sgotplt->output_section->vma | |
9260 | + htab->root.sgotplt->output_offset; | |
9261 | ||
9262 | bfd_vma dt_tlsdesc_got = got_addr + htab->dt_tlsdesc_got; | |
caed7120 YZ |
9263 | |
9264 | bfd_byte *plt_entry = | |
9265 | htab->root.splt->contents + htab->tlsdesc_plt; | |
a06ea964 NC |
9266 | |
9267 | /* adrp x2, DT_TLSDESC_GOT */ | |
caed7120 YZ |
9268 | elf_aarch64_update_plt_entry (output_bfd, |
9269 | BFD_RELOC_AARCH64_ADR_HI21_PCREL, | |
9270 | plt_entry + 4, | |
9271 | (PG (dt_tlsdesc_got) | |
9272 | - PG (adrp1_addr))); | |
a06ea964 NC |
9273 | |
9274 | /* adrp x3, 0 */ | |
caed7120 YZ |
9275 | elf_aarch64_update_plt_entry (output_bfd, |
9276 | BFD_RELOC_AARCH64_ADR_HI21_PCREL, | |
9277 | plt_entry + 8, | |
9278 | (PG (pltgot_addr) | |
9279 | - PG (adrp2_addr))); | |
a06ea964 NC |
9280 | |
9281 | /* ldr x2, [x2, #0] */ | |
caed7120 YZ |
9282 | elf_aarch64_update_plt_entry (output_bfd, |
9283 | BFD_RELOC_AARCH64_LDSTNN_LO12, | |
9284 | plt_entry + 12, | |
9285 | PG_OFFSET (dt_tlsdesc_got)); | |
a06ea964 NC |
9286 | |
9287 | /* add x3, x3, 0 */ | |
caed7120 YZ |
9288 | elf_aarch64_update_plt_entry (output_bfd, |
9289 | BFD_RELOC_AARCH64_ADD_LO12, | |
9290 | plt_entry + 16, | |
9291 | PG_OFFSET (pltgot_addr)); | |
a06ea964 NC |
9292 | } |
9293 | } | |
9294 | } | |
9295 | ||
9296 | if (htab->root.sgotplt) | |
9297 | { | |
9298 | if (bfd_is_abs_section (htab->root.sgotplt->output_section)) | |
9299 | { | |
4eca0228 | 9300 | _bfd_error_handler |
a06ea964 NC |
9301 | (_("discarded output section: `%A'"), htab->root.sgotplt); |
9302 | return FALSE; | |
9303 | } | |
9304 | ||
9305 | /* Fill in the first three entries in the global offset table. */ | |
9306 | if (htab->root.sgotplt->size > 0) | |
9307 | { | |
8db339a6 MS |
9308 | bfd_put_NN (output_bfd, (bfd_vma) 0, htab->root.sgotplt->contents); |
9309 | ||
a06ea964 | 9310 | /* Write GOT[1] and GOT[2], needed for the dynamic linker. */ |
cec5225b | 9311 | bfd_put_NN (output_bfd, |
a06ea964 NC |
9312 | (bfd_vma) 0, |
9313 | htab->root.sgotplt->contents + GOT_ENTRY_SIZE); | |
cec5225b | 9314 | bfd_put_NN (output_bfd, |
a06ea964 NC |
9315 | (bfd_vma) 0, |
9316 | htab->root.sgotplt->contents + GOT_ENTRY_SIZE * 2); | |
9317 | } | |
9318 | ||
8db339a6 MS |
9319 | if (htab->root.sgot) |
9320 | { | |
9321 | if (htab->root.sgot->size > 0) | |
9322 | { | |
9323 | bfd_vma addr = | |
9324 | sdyn ? sdyn->output_section->vma + sdyn->output_offset : 0; | |
9325 | bfd_put_NN (output_bfd, addr, htab->root.sgot->contents); | |
9326 | } | |
9327 | } | |
9328 | ||
a06ea964 NC |
9329 | elf_section_data (htab->root.sgotplt->output_section)-> |
9330 | this_hdr.sh_entsize = GOT_ENTRY_SIZE; | |
9331 | } | |
9332 | ||
9333 | if (htab->root.sgot && htab->root.sgot->size > 0) | |
9334 | elf_section_data (htab->root.sgot->output_section)->this_hdr.sh_entsize | |
9335 | = GOT_ENTRY_SIZE; | |
9336 | ||
1419bbe5 WN |
9337 | /* Fill PLT and GOT entries for local STT_GNU_IFUNC symbols. */ |
9338 | htab_traverse (htab->loc_hash_table, | |
9339 | elfNN_aarch64_finish_local_dynamic_symbol, | |
9340 | info); | |
9341 | ||
a06ea964 NC |
9342 | return TRUE; |
9343 | } | |
9344 | ||
9345 | /* Return address for Ith PLT stub in section PLT, for relocation REL | |
9346 | or (bfd_vma) -1 if it should not be included. */ | |
9347 | ||
9348 | static bfd_vma | |
cec5225b | 9349 | elfNN_aarch64_plt_sym_val (bfd_vma i, const asection *plt, |
a06ea964 NC |
9350 | const arelent *rel ATTRIBUTE_UNUSED) |
9351 | { | |
9352 | return plt->vma + PLT_ENTRY_SIZE + i * PLT_SMALL_ENTRY_SIZE; | |
9353 | } | |
9354 | ||
d691934d NC |
9355 | /* Returns TRUE if NAME is an AArch64 mapping symbol. |
9356 | The ARM ELF standard defines $x (for A64 code) and $d (for data). | |
9357 | It also allows a period initiated suffix to be added to the symbol, ie: | |
9358 | "$[adtx]\.[:sym_char]+". */ | |
9359 | ||
9360 | static bfd_boolean | |
9361 | is_aarch64_mapping_symbol (const char * name) | |
9362 | { | |
9363 | return name != NULL /* Paranoia. */ | |
9364 | && name[0] == '$' /* Note: if objcopy --prefix-symbols has been used then | |
9365 | the mapping symbols could have acquired a prefix. | |
9366 | We do not support this here, since such symbols no | |
9367 | longer conform to the ARM ELF ABI. */ | |
9368 | && (name[1] == 'd' || name[1] == 'x') | |
9369 | && (name[2] == 0 || name[2] == '.'); | |
9370 | /* FIXME: Strictly speaking the symbol is only a valid mapping symbol if | |
9371 | any characters that follow the period are legal characters for the body | |
9372 | of a symbol's name. For now we just assume that this is the case. */ | |
9373 | } | |
9374 | ||
9375 | /* Make sure that mapping symbols in object files are not removed via the | |
9376 | "strip --strip-unneeded" tool. These symbols might needed in order to | |
9377 | correctly generate linked files. Once an object file has been linked, | |
9378 | it should be safe to remove them. */ | |
9379 | ||
9380 | static void | |
9381 | elfNN_aarch64_backend_symbol_processing (bfd *abfd, asymbol *sym) | |
9382 | { | |
9383 | if (((abfd->flags & (EXEC_P | DYNAMIC)) == 0) | |
9384 | && sym->section != bfd_abs_section_ptr | |
9385 | && is_aarch64_mapping_symbol (sym->name)) | |
9386 | sym->flags |= BSF_KEEP; | |
9387 | } | |
9388 | ||
a06ea964 NC |
9389 | |
9390 | /* We use this so we can override certain functions | |
9391 | (though currently we don't). */ | |
9392 | ||
cec5225b | 9393 | const struct elf_size_info elfNN_aarch64_size_info = |
a06ea964 | 9394 | { |
cec5225b YZ |
9395 | sizeof (ElfNN_External_Ehdr), |
9396 | sizeof (ElfNN_External_Phdr), | |
9397 | sizeof (ElfNN_External_Shdr), | |
9398 | sizeof (ElfNN_External_Rel), | |
9399 | sizeof (ElfNN_External_Rela), | |
9400 | sizeof (ElfNN_External_Sym), | |
9401 | sizeof (ElfNN_External_Dyn), | |
a06ea964 NC |
9402 | sizeof (Elf_External_Note), |
9403 | 4, /* Hash table entry size. */ | |
9404 | 1, /* Internal relocs per external relocs. */ | |
cec5225b YZ |
9405 | ARCH_SIZE, /* Arch size. */ |
9406 | LOG_FILE_ALIGN, /* Log_file_align. */ | |
9407 | ELFCLASSNN, EV_CURRENT, | |
9408 | bfd_elfNN_write_out_phdrs, | |
9409 | bfd_elfNN_write_shdrs_and_ehdr, | |
9410 | bfd_elfNN_checksum_contents, | |
9411 | bfd_elfNN_write_relocs, | |
9412 | bfd_elfNN_swap_symbol_in, | |
9413 | bfd_elfNN_swap_symbol_out, | |
9414 | bfd_elfNN_slurp_reloc_table, | |
9415 | bfd_elfNN_slurp_symbol_table, | |
9416 | bfd_elfNN_swap_dyn_in, | |
9417 | bfd_elfNN_swap_dyn_out, | |
9418 | bfd_elfNN_swap_reloc_in, | |
9419 | bfd_elfNN_swap_reloc_out, | |
9420 | bfd_elfNN_swap_reloca_in, | |
9421 | bfd_elfNN_swap_reloca_out | |
a06ea964 NC |
9422 | }; |
9423 | ||
9424 | #define ELF_ARCH bfd_arch_aarch64 | |
9425 | #define ELF_MACHINE_CODE EM_AARCH64 | |
9426 | #define ELF_MAXPAGESIZE 0x10000 | |
9427 | #define ELF_MINPAGESIZE 0x1000 | |
9428 | #define ELF_COMMONPAGESIZE 0x1000 | |
9429 | ||
cec5225b YZ |
9430 | #define bfd_elfNN_close_and_cleanup \ |
9431 | elfNN_aarch64_close_and_cleanup | |
a06ea964 | 9432 | |
cec5225b YZ |
9433 | #define bfd_elfNN_bfd_free_cached_info \ |
9434 | elfNN_aarch64_bfd_free_cached_info | |
a06ea964 | 9435 | |
cec5225b YZ |
9436 | #define bfd_elfNN_bfd_is_target_special_symbol \ |
9437 | elfNN_aarch64_is_target_special_symbol | |
a06ea964 | 9438 | |
cec5225b YZ |
9439 | #define bfd_elfNN_bfd_link_hash_table_create \ |
9440 | elfNN_aarch64_link_hash_table_create | |
a06ea964 | 9441 | |
cec5225b YZ |
9442 | #define bfd_elfNN_bfd_merge_private_bfd_data \ |
9443 | elfNN_aarch64_merge_private_bfd_data | |
a06ea964 | 9444 | |
cec5225b YZ |
9445 | #define bfd_elfNN_bfd_print_private_bfd_data \ |
9446 | elfNN_aarch64_print_private_bfd_data | |
a06ea964 | 9447 | |
cec5225b YZ |
9448 | #define bfd_elfNN_bfd_reloc_type_lookup \ |
9449 | elfNN_aarch64_reloc_type_lookup | |
a06ea964 | 9450 | |
cec5225b YZ |
9451 | #define bfd_elfNN_bfd_reloc_name_lookup \ |
9452 | elfNN_aarch64_reloc_name_lookup | |
a06ea964 | 9453 | |
cec5225b YZ |
9454 | #define bfd_elfNN_bfd_set_private_flags \ |
9455 | elfNN_aarch64_set_private_flags | |
a06ea964 | 9456 | |
cec5225b YZ |
9457 | #define bfd_elfNN_find_inliner_info \ |
9458 | elfNN_aarch64_find_inliner_info | |
a06ea964 | 9459 | |
cec5225b YZ |
9460 | #define bfd_elfNN_find_nearest_line \ |
9461 | elfNN_aarch64_find_nearest_line | |
a06ea964 | 9462 | |
cec5225b YZ |
9463 | #define bfd_elfNN_mkobject \ |
9464 | elfNN_aarch64_mkobject | |
a06ea964 | 9465 | |
cec5225b YZ |
9466 | #define bfd_elfNN_new_section_hook \ |
9467 | elfNN_aarch64_new_section_hook | |
a06ea964 NC |
9468 | |
9469 | #define elf_backend_adjust_dynamic_symbol \ | |
cec5225b | 9470 | elfNN_aarch64_adjust_dynamic_symbol |
a06ea964 NC |
9471 | |
9472 | #define elf_backend_always_size_sections \ | |
cec5225b | 9473 | elfNN_aarch64_always_size_sections |
a06ea964 NC |
9474 | |
9475 | #define elf_backend_check_relocs \ | |
cec5225b | 9476 | elfNN_aarch64_check_relocs |
a06ea964 NC |
9477 | |
9478 | #define elf_backend_copy_indirect_symbol \ | |
cec5225b | 9479 | elfNN_aarch64_copy_indirect_symbol |
a06ea964 NC |
9480 | |
9481 | /* Create .dynbss, and .rela.bss sections in DYNOBJ, and set up shortcuts | |
9482 | to them in our hash. */ | |
9483 | #define elf_backend_create_dynamic_sections \ | |
cec5225b | 9484 | elfNN_aarch64_create_dynamic_sections |
a06ea964 NC |
9485 | |
9486 | #define elf_backend_init_index_section \ | |
9487 | _bfd_elf_init_2_index_sections | |
9488 | ||
a06ea964 | 9489 | #define elf_backend_finish_dynamic_sections \ |
cec5225b | 9490 | elfNN_aarch64_finish_dynamic_sections |
a06ea964 NC |
9491 | |
9492 | #define elf_backend_finish_dynamic_symbol \ | |
cec5225b | 9493 | elfNN_aarch64_finish_dynamic_symbol |
a06ea964 NC |
9494 | |
9495 | #define elf_backend_gc_sweep_hook \ | |
cec5225b | 9496 | elfNN_aarch64_gc_sweep_hook |
a06ea964 NC |
9497 | |
9498 | #define elf_backend_object_p \ | |
cec5225b | 9499 | elfNN_aarch64_object_p |
a06ea964 NC |
9500 | |
9501 | #define elf_backend_output_arch_local_syms \ | |
cec5225b | 9502 | elfNN_aarch64_output_arch_local_syms |
a06ea964 NC |
9503 | |
9504 | #define elf_backend_plt_sym_val \ | |
cec5225b | 9505 | elfNN_aarch64_plt_sym_val |
a06ea964 NC |
9506 | |
9507 | #define elf_backend_post_process_headers \ | |
cec5225b | 9508 | elfNN_aarch64_post_process_headers |
a06ea964 NC |
9509 | |
9510 | #define elf_backend_relocate_section \ | |
cec5225b | 9511 | elfNN_aarch64_relocate_section |
a06ea964 NC |
9512 | |
9513 | #define elf_backend_reloc_type_class \ | |
cec5225b | 9514 | elfNN_aarch64_reloc_type_class |
a06ea964 | 9515 | |
a06ea964 | 9516 | #define elf_backend_section_from_shdr \ |
cec5225b | 9517 | elfNN_aarch64_section_from_shdr |
a06ea964 NC |
9518 | |
9519 | #define elf_backend_size_dynamic_sections \ | |
cec5225b | 9520 | elfNN_aarch64_size_dynamic_sections |
a06ea964 NC |
9521 | |
9522 | #define elf_backend_size_info \ | |
cec5225b | 9523 | elfNN_aarch64_size_info |
a06ea964 | 9524 | |
68fcca92 JW |
9525 | #define elf_backend_write_section \ |
9526 | elfNN_aarch64_write_section | |
9527 | ||
d691934d NC |
9528 | #define elf_backend_symbol_processing \ |
9529 | elfNN_aarch64_backend_symbol_processing | |
9530 | ||
a06ea964 | 9531 | #define elf_backend_can_refcount 1 |
59c108f7 | 9532 | #define elf_backend_can_gc_sections 1 |
a06ea964 NC |
9533 | #define elf_backend_plt_readonly 1 |
9534 | #define elf_backend_want_got_plt 1 | |
9535 | #define elf_backend_want_plt_sym 0 | |
5474d94f | 9536 | #define elf_backend_want_dynrelro 1 |
a06ea964 NC |
9537 | #define elf_backend_may_use_rel_p 0 |
9538 | #define elf_backend_may_use_rela_p 1 | |
9539 | #define elf_backend_default_use_rela_p 1 | |
2e0488d3 | 9540 | #define elf_backend_rela_normal 1 |
64f52338 | 9541 | #define elf_backend_dtrel_excludes_plt 1 |
a06ea964 | 9542 | #define elf_backend_got_header_size (GOT_ENTRY_SIZE * 3) |
c495064d | 9543 | #define elf_backend_default_execstack 0 |
32f573bc | 9544 | #define elf_backend_extern_protected_data 1 |
7f784814 | 9545 | #define elf_backend_hash_symbol elf_aarch64_hash_symbol |
a06ea964 NC |
9546 | |
9547 | #undef elf_backend_obj_attrs_section | |
9548 | #define elf_backend_obj_attrs_section ".ARM.attributes" | |
9549 | ||
cec5225b | 9550 | #include "elfNN-target.h" |
a75cf613 ES |
9551 | |
9552 | /* CloudABI support. */ | |
9553 | ||
9554 | #undef TARGET_LITTLE_SYM | |
9555 | #define TARGET_LITTLE_SYM aarch64_elfNN_le_cloudabi_vec | |
9556 | #undef TARGET_LITTLE_NAME | |
9557 | #define TARGET_LITTLE_NAME "elfNN-littleaarch64-cloudabi" | |
9558 | #undef TARGET_BIG_SYM | |
9559 | #define TARGET_BIG_SYM aarch64_elfNN_be_cloudabi_vec | |
9560 | #undef TARGET_BIG_NAME | |
9561 | #define TARGET_BIG_NAME "elfNN-bigaarch64-cloudabi" | |
9562 | ||
9563 | #undef ELF_OSABI | |
9564 | #define ELF_OSABI ELFOSABI_CLOUDABI | |
9565 | ||
9566 | #undef elfNN_bed | |
9567 | #define elfNN_bed elfNN_aarch64_cloudabi_bed | |
9568 | ||
9569 | #include "elfNN-target.h" |