]>
Commit | Line | Data |
---|---|---|
cec5225b | 1 | /* AArch64-specific support for NN-bit ELF. |
b3adc24a | 2 | Copyright (C) 2009-2020 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 | |
07d6d2b8 | 34 | R_AARCH64_TLSGD_ADR_PAGE21(foo) |
a06ea964 | 35 | add x0, :tlsgd_lo12:foo |
07d6d2b8 | 36 | R_AARCH64_TLSGD_ADD_LO12_NC(foo) |
a06ea964 NC |
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 | ||
07d6d2b8 AM |
43 | adrp x0, :tlsdesc:foo R_AARCH64_TLSDESC_ADR_PAGE21(foo) |
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) | |
a06ea964 | 46 | .tlsdesccall foo |
07d6d2b8 | 47 | blr x1 R_AARCH64_TLSDESC_CALL(foo) |
a06ea964 NC |
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" | |
a06ea964 NC |
142 | #include "elf-bfd.h" |
143 | #include "bfdlink.h" | |
1419bbe5 | 144 | #include "objalloc.h" |
a06ea964 | 145 | #include "elf/aarch64.h" |
caed7120 | 146 | #include "elfxx-aarch64.h" |
a8bfaadb | 147 | #include "cpu-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 | ||
f7d2c675 SP |
160 | #define MORELLO_R(NAME) R_MORELLO_ ## NAME |
161 | #define MORELLO_R_STR(NAME) "R_MORELLO_" #NAME | |
162 | ||
cec5225b YZ |
163 | #if ARCH_SIZE == 32 |
164 | #define AARCH64_R(NAME) R_AARCH64_P32_ ## NAME | |
165 | #define AARCH64_R_STR(NAME) "R_AARCH64_P32_" #NAME | |
a6bb11b2 YZ |
166 | #define HOWTO64(...) EMPTY_HOWTO (0) |
167 | #define HOWTO32(...) HOWTO (__VA_ARGS__) | |
cec5225b | 168 | #define LOG_FILE_ALIGN 2 |
07d6d2b8 AM |
169 | #define BFD_RELOC_AARCH64_TLSDESC_LD32_LO12 BFD_RELOC_AARCH64_TLSDESC_LD32_LO12_NC |
170 | #define R_AARCH64_P32_TLSDESC_ADD_LO12 R_AARCH64_P32_TLSDESC_ADD_LO12_NC | |
cec5225b YZ |
171 | #endif |
172 | ||
a6bb11b2 | 173 | #define IS_AARCH64_TLS_RELOC(R_TYPE) \ |
4c0a9a6f JW |
174 | ((R_TYPE) == BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC \ |
175 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21 \ | |
3c12b054 | 176 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSGD_ADR_PREL21 \ |
3e8286c0 | 177 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSGD_MOVW_G0_NC \ |
1aa66fb1 | 178 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSGD_MOVW_G1 \ |
a6bb11b2 | 179 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21 \ |
a6bb11b2 | 180 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSIE_LD32_GOTTPREL_LO12_NC \ |
4c0a9a6f | 181 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC \ |
a6bb11b2 | 182 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19 \ |
4c0a9a6f JW |
183 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G0_NC \ |
184 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G1 \ | |
6ffe9a1b | 185 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_ADD_DTPREL_HI12 \ |
40fbed84 | 186 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_ADD_DTPREL_LO12 \ |
753999c1 | 187 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_ADD_DTPREL_LO12_NC \ |
73f925cc | 188 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC \ |
f69e4920 | 189 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21 \ |
77a69ff8 | 190 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_ADR_PREL21 \ |
07c9aa07 JW |
191 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_LDST16_DTPREL_LO12 \ |
192 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_LDST16_DTPREL_LO12_NC \ | |
193 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_LDST32_DTPREL_LO12 \ | |
194 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_LDST32_DTPREL_LO12_NC \ | |
195 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_LDST64_DTPREL_LO12 \ | |
196 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_LDST64_DTPREL_LO12_NC \ | |
197 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_LDST8_DTPREL_LO12 \ | |
198 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_LDST8_DTPREL_LO12_NC \ | |
6ffe9a1b JW |
199 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G0 \ |
200 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G0_NC \ | |
201 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G1 \ | |
202 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G1_NC \ | |
203 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G2 \ | |
a6bb11b2 | 204 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_HI12 \ |
4c0a9a6f | 205 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_LO12 \ |
a6bb11b2 | 206 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_LO12_NC \ |
e04ef022 RL |
207 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_LDST16_TPREL_LO12 \ |
208 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_LDST16_TPREL_LO12_NC \ | |
209 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_LDST32_TPREL_LO12 \ | |
210 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_LDST32_TPREL_LO12_NC \ | |
211 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_LDST64_TPREL_LO12 \ | |
212 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_LDST64_TPREL_LO12_NC \ | |
213 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_LDST8_TPREL_LO12 \ | |
214 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_LDST8_TPREL_LO12_NC \ | |
a6bb11b2 YZ |
215 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0 \ |
216 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC \ | |
4c0a9a6f JW |
217 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1 \ |
218 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1_NC \ | |
219 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G2 \ | |
a6bb11b2 YZ |
220 | || (R_TYPE) == BFD_RELOC_AARCH64_TLS_DTPMOD \ |
221 | || (R_TYPE) == BFD_RELOC_AARCH64_TLS_DTPREL \ | |
222 | || (R_TYPE) == BFD_RELOC_AARCH64_TLS_TPREL \ | |
a06ea964 NC |
223 | || IS_AARCH64_TLSDESC_RELOC ((R_TYPE))) |
224 | ||
9331eea1 | 225 | #define IS_AARCH64_TLS_RELAX_RELOC(R_TYPE) \ |
f955cccf NC |
226 | ((R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_ADD \ |
227 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_ADD_LO12 \ | |
4ca9b406 | 228 | || (R_TYPE) == BFD_RELOC_MORELLO_TLSDESC_ADR_PAGE20 \ |
4af68b9c JW |
229 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21 \ |
230 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21 \ | |
4ca9b406 | 231 | || (R_TYPE) == BFD_RELOC_MORELLO_TLSDESC_CALL \ |
4af68b9c JW |
232 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_CALL \ |
233 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_LD_PREL19 \ | |
4ca9b406 | 234 | || (R_TYPE) == BFD_RELOC_MORELLO_TLSDESC_LD128_LO12 \ |
4af68b9c | 235 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_LDNN_LO12_NC \ |
0484b454 RL |
236 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_LDR \ |
237 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_OFF_G0_NC \ | |
238 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_OFF_G1 \ | |
239 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_LDR \ | |
4af68b9c | 240 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21 \ |
9331eea1 JW |
241 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSGD_ADR_PREL21 \ |
242 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC \ | |
ac734732 RL |
243 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSGD_MOVW_G0_NC \ |
244 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSGD_MOVW_G1 \ | |
9331eea1 JW |
245 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21 \ |
246 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19 \ | |
247 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSIE_LDNN_GOTTPREL_LO12_NC \ | |
259364ad JW |
248 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC \ |
249 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21 \ | |
4af68b9c | 250 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_ADR_PREL21) |
9331eea1 | 251 | |
a6bb11b2 | 252 | #define IS_AARCH64_TLSDESC_RELOC(R_TYPE) \ |
4c0a9a6f JW |
253 | ((R_TYPE) == BFD_RELOC_AARCH64_TLSDESC \ |
254 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_ADD \ | |
f955cccf | 255 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_ADD_LO12 \ |
a6bb11b2 | 256 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21 \ |
4ca9b406 | 257 | || (R_TYPE) == BFD_RELOC_MORELLO_TLSDESC_ADR_PAGE20 \ |
389b8029 | 258 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21 \ |
4c0a9a6f | 259 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_CALL \ |
4ca9b406 | 260 | || (R_TYPE) == BFD_RELOC_MORELLO_TLSDESC_CALL \ |
a6bb11b2 | 261 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_LD32_LO12_NC \ |
f955cccf | 262 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_LD64_LO12 \ |
4ca9b406 | 263 | || (R_TYPE) == BFD_RELOC_MORELLO_TLSDESC_LD128_LO12 \ |
a6bb11b2 | 264 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_LDR \ |
4c0a9a6f JW |
265 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_LD_PREL19 \ |
266 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_OFF_G0_NC \ | |
267 | || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_OFF_G1) | |
a06ea964 | 268 | |
6353d82b | 269 | #define ELIMINATE_COPY_RELOCS 1 |
a06ea964 | 270 | |
a06ea964 | 271 | /* Return size of a relocation entry. HTAB is the bfd's |
cec5225b YZ |
272 | elf_aarch64_link_hash_entry. */ |
273 | #define RELOC_SIZE(HTAB) (sizeof (ElfNN_External_Rela)) | |
a06ea964 | 274 | |
a1bdea65 SP |
275 | /* GOT Entry size - 16 bytes in C64, 8 bytes in ELF64 and 4 bytes in ELF32. */ |
276 | #define GOT_ENTRY_SIZE(htab) (ARCH_SIZE >> (3 - htab->c64_rel)) | |
277 | #define GOT_RESERVED_HEADER_SLOTS (3) | |
07d6d2b8 AM |
278 | #define PLT_ENTRY_SIZE (32) |
279 | #define PLT_SMALL_ENTRY_SIZE (16) | |
280 | #define PLT_TLSDESC_ENTRY_SIZE (32) | |
37c18eed | 281 | /* PLT sizes with BTI insn. */ |
68bb0359 | 282 | #define PLT_BTI_SMALL_ENTRY_SIZE (24) |
1dbade74 | 283 | /* PLT sizes with PAC insn. */ |
68bb0359 | 284 | #define PLT_PAC_SMALL_ENTRY_SIZE (24) |
1dbade74 | 285 | /* PLT sizes with BTI and PAC insn. */ |
1dbade74 | 286 | #define PLT_BTI_PAC_SMALL_ENTRY_SIZE (24) |
a06ea964 | 287 | |
2d0ca824 | 288 | /* Encoding of the nop instruction. */ |
a06ea964 NC |
289 | #define INSN_NOP 0xd503201f |
290 | ||
291 | #define aarch64_compute_jump_table_size(htab) \ | |
292 | (((htab)->root.srelplt == NULL) ? 0 \ | |
a1bdea65 | 293 | : (htab)->root.srelplt->reloc_count * GOT_ENTRY_SIZE (htab)) |
a06ea964 NC |
294 | |
295 | /* The first entry in a procedure linkage table looks like this | |
296 | if the distance between the PLTGOT and the PLT is < 4GB use | |
297 | these PLT entries. Note that the dynamic linker gets &PLTGOT[2] | |
298 | in x16 and needs to work out PLTGOT[1] by using an address of | |
cec5225b YZ |
299 | [x16,#-GOT_ENTRY_SIZE]. */ |
300 | static const bfd_byte elfNN_aarch64_small_plt0_entry[PLT_ENTRY_SIZE] = | |
a06ea964 NC |
301 | { |
302 | 0xf0, 0x7b, 0xbf, 0xa9, /* stp x16, x30, [sp, #-16]! */ | |
303 | 0x10, 0x00, 0x00, 0x90, /* adrp x16, (GOT+16) */ | |
caed7120 | 304 | #if ARCH_SIZE == 64 |
a06ea964 NC |
305 | 0x11, 0x0A, 0x40, 0xf9, /* ldr x17, [x16, #PLT_GOT+0x10] */ |
306 | 0x10, 0x42, 0x00, 0x91, /* add x16, x16,#PLT_GOT+0x10 */ | |
caed7120 YZ |
307 | #else |
308 | 0x11, 0x0A, 0x40, 0xb9, /* ldr w17, [x16, #PLT_GOT+0x8] */ | |
309 | 0x10, 0x22, 0x00, 0x11, /* add w16, w16,#PLT_GOT+0x8 */ | |
310 | #endif | |
a06ea964 NC |
311 | 0x20, 0x02, 0x1f, 0xd6, /* br x17 */ |
312 | 0x1f, 0x20, 0x03, 0xd5, /* nop */ | |
313 | 0x1f, 0x20, 0x03, 0xd5, /* nop */ | |
314 | 0x1f, 0x20, 0x03, 0xd5, /* nop */ | |
315 | }; | |
316 | ||
68bb0359 | 317 | static const bfd_byte elfNN_aarch64_small_plt0_bti_entry[PLT_ENTRY_SIZE] = |
37c18eed SD |
318 | { |
319 | 0x5f, 0x24, 0x03, 0xd5, /* bti c. */ | |
320 | 0xf0, 0x7b, 0xbf, 0xa9, /* stp x16, x30, [sp, #-16]! */ | |
321 | 0x10, 0x00, 0x00, 0x90, /* adrp x16, (GOT+16) */ | |
322 | #if ARCH_SIZE == 64 | |
323 | 0x11, 0x0A, 0x40, 0xf9, /* ldr x17, [x16, #PLT_GOT+0x10] */ | |
324 | 0x10, 0x42, 0x00, 0x91, /* add x16, x16,#PLT_GOT+0x10 */ | |
325 | #else | |
326 | 0x11, 0x0A, 0x40, 0xb9, /* ldr w17, [x16, #PLT_GOT+0x8] */ | |
327 | 0x10, 0x22, 0x00, 0x11, /* add w16, w16,#PLT_GOT+0x8 */ | |
328 | #endif | |
329 | 0x20, 0x02, 0x1f, 0xd6, /* br x17 */ | |
330 | 0x1f, 0x20, 0x03, 0xd5, /* nop */ | |
331 | 0x1f, 0x20, 0x03, 0xd5, /* nop */ | |
1dbade74 SD |
332 | }; |
333 | ||
e19e9199 SP |
334 | /* The C64 PLT0. */ |
335 | static const bfd_byte elfNN_c64_small_plt0_entry[PLT_ENTRY_SIZE] = | |
336 | { | |
337 | 0xf0, 0x7b, 0xbf, 0x62, /* stp c16, c30, [csp, #-32]! */ | |
338 | 0x10, 0x00, 0x80, 0x90, /* adrp c16, (GOT+16) */ | |
339 | 0x11, 0x0a, 0x40, 0xc2, /* ldr c17, [c16, #PLT_GOT+0x10] */ | |
340 | 0x10, 0x02, 0x00, 0x02, /* add c16, c16,#PLT_GOT+0x10 */ | |
341 | 0x20, 0x12, 0xc2, 0xc2, /* br c17 */ | |
342 | 0x1f, 0x20, 0x03, 0xd5, /* nop */ | |
343 | 0x1f, 0x20, 0x03, 0xd5, /* nop */ | |
344 | 0x1f, 0x20, 0x03, 0xd5, /* nop */ | |
345 | }; | |
346 | ||
a06ea964 NC |
347 | /* Per function entry in a procedure linkage table looks like this |
348 | if the distance between the PLTGOT and the PLT is < 4GB use | |
37c18eed | 349 | these PLT entries. Use BTI versions of the PLTs when enabled. */ |
cec5225b | 350 | static const bfd_byte elfNN_aarch64_small_plt_entry[PLT_SMALL_ENTRY_SIZE] = |
a06ea964 NC |
351 | { |
352 | 0x10, 0x00, 0x00, 0x90, /* adrp x16, PLTGOT + n * 8 */ | |
caed7120 | 353 | #if ARCH_SIZE == 64 |
a06ea964 NC |
354 | 0x11, 0x02, 0x40, 0xf9, /* ldr x17, [x16, PLTGOT + n * 8] */ |
355 | 0x10, 0x02, 0x00, 0x91, /* add x16, x16, :lo12:PLTGOT + n * 8 */ | |
caed7120 YZ |
356 | #else |
357 | 0x11, 0x02, 0x40, 0xb9, /* ldr w17, [x16, PLTGOT + n * 4] */ | |
358 | 0x10, 0x02, 0x00, 0x11, /* add w16, w16, :lo12:PLTGOT + n * 4 */ | |
359 | #endif | |
a06ea964 NC |
360 | 0x20, 0x02, 0x1f, 0xd6, /* br x17. */ |
361 | }; | |
362 | ||
e19e9199 SP |
363 | /* The C64 PLT. */ |
364 | static const bfd_byte elfNN_c64_small_plt_entry[PLT_SMALL_ENTRY_SIZE] = | |
365 | { | |
366 | 0x10, 0x00, 0x80, 0x90, /* adrp c16, PLTGOT + offset */ | |
367 | 0x11, 0x02, 0x40, 0xc2, /* ldr c17, [c16, PLTGOT + offset] */ | |
368 | 0x10, 0x02, 0x00, 0x02, /* add c16, c16, :lo12:PLTGOT + offset */ | |
369 | 0x20, 0x12, 0xc2, 0xc2, /* br c17. */ | |
370 | }; | |
371 | ||
37c18eed SD |
372 | static const bfd_byte |
373 | elfNN_aarch64_small_plt_bti_entry[PLT_BTI_SMALL_ENTRY_SIZE] = | |
374 | { | |
375 | 0x5f, 0x24, 0x03, 0xd5, /* bti c. */ | |
376 | 0x10, 0x00, 0x00, 0x90, /* adrp x16, PLTGOT + n * 8 */ | |
377 | #if ARCH_SIZE == 64 | |
378 | 0x11, 0x02, 0x40, 0xf9, /* ldr x17, [x16, PLTGOT + n * 8] */ | |
379 | 0x10, 0x02, 0x00, 0x91, /* add x16, x16, :lo12:PLTGOT + n * 8 */ | |
380 | #else | |
381 | 0x11, 0x02, 0x40, 0xb9, /* ldr w17, [x16, PLTGOT + n * 4] */ | |
382 | 0x10, 0x02, 0x00, 0x11, /* add w16, w16, :lo12:PLTGOT + n * 4 */ | |
383 | #endif | |
384 | 0x20, 0x02, 0x1f, 0xd6, /* br x17. */ | |
68bb0359 | 385 | 0x1f, 0x20, 0x03, 0xd5, /* nop */ |
37c18eed SD |
386 | }; |
387 | ||
1dbade74 SD |
388 | static const bfd_byte |
389 | elfNN_aarch64_small_plt_pac_entry[PLT_PAC_SMALL_ENTRY_SIZE] = | |
390 | { | |
391 | 0x10, 0x00, 0x00, 0x90, /* adrp x16, PLTGOT + n * 8 */ | |
392 | #if ARCH_SIZE == 64 | |
393 | 0x11, 0x02, 0x40, 0xf9, /* ldr x17, [x16, PLTGOT + n * 8] */ | |
394 | 0x10, 0x02, 0x00, 0x91, /* add x16, x16, :lo12:PLTGOT + n * 8 */ | |
395 | #else | |
396 | 0x11, 0x02, 0x40, 0xb9, /* ldr w17, [x16, PLTGOT + n * 4] */ | |
397 | 0x10, 0x02, 0x00, 0x11, /* add w16, w16, :lo12:PLTGOT + n * 4 */ | |
398 | #endif | |
399 | 0x9f, 0x21, 0x03, 0xd5, /* autia1716 */ | |
400 | 0x20, 0x02, 0x1f, 0xd6, /* br x17. */ | |
68bb0359 | 401 | 0x1f, 0x20, 0x03, 0xd5, /* nop */ |
1dbade74 SD |
402 | }; |
403 | ||
404 | static const bfd_byte | |
405 | elfNN_aarch64_small_plt_bti_pac_entry[PLT_BTI_PAC_SMALL_ENTRY_SIZE] = | |
406 | { | |
407 | 0x5f, 0x24, 0x03, 0xd5, /* bti c. */ | |
408 | 0x10, 0x00, 0x00, 0x90, /* adrp x16, PLTGOT + n * 8 */ | |
409 | #if ARCH_SIZE == 64 | |
410 | 0x11, 0x02, 0x40, 0xf9, /* ldr x17, [x16, PLTGOT + n * 8] */ | |
411 | 0x10, 0x02, 0x00, 0x91, /* add x16, x16, :lo12:PLTGOT + n * 8 */ | |
412 | #else | |
413 | 0x11, 0x02, 0x40, 0xb9, /* ldr w17, [x16, PLTGOT + n * 4] */ | |
414 | 0x10, 0x02, 0x00, 0x11, /* add w16, w16, :lo12:PLTGOT + n * 4 */ | |
415 | #endif | |
416 | 0x9f, 0x21, 0x03, 0xd5, /* autia1716 */ | |
417 | 0x20, 0x02, 0x1f, 0xd6, /* br x17. */ | |
418 | }; | |
419 | ||
a06ea964 | 420 | static const bfd_byte |
cec5225b | 421 | elfNN_aarch64_tlsdesc_small_plt_entry[PLT_TLSDESC_ENTRY_SIZE] = |
a06ea964 NC |
422 | { |
423 | 0xe2, 0x0f, 0xbf, 0xa9, /* stp x2, x3, [sp, #-16]! */ | |
424 | 0x02, 0x00, 0x00, 0x90, /* adrp x2, 0 */ | |
425 | 0x03, 0x00, 0x00, 0x90, /* adrp x3, 0 */ | |
caed7120 YZ |
426 | #if ARCH_SIZE == 64 |
427 | 0x42, 0x00, 0x40, 0xf9, /* ldr x2, [x2, #0] */ | |
a06ea964 | 428 | 0x63, 0x00, 0x00, 0x91, /* add x3, x3, 0 */ |
caed7120 YZ |
429 | #else |
430 | 0x42, 0x00, 0x40, 0xb9, /* ldr w2, [x2, #0] */ | |
431 | 0x63, 0x00, 0x00, 0x11, /* add w3, w3, 0 */ | |
432 | #endif | |
433 | 0x40, 0x00, 0x1f, 0xd6, /* br x2 */ | |
a06ea964 NC |
434 | 0x1f, 0x20, 0x03, 0xd5, /* nop */ |
435 | 0x1f, 0x20, 0x03, 0xd5, /* nop */ | |
436 | }; | |
437 | ||
37c18eed | 438 | static const bfd_byte |
68bb0359 | 439 | elfNN_aarch64_tlsdesc_small_plt_bti_entry[PLT_TLSDESC_ENTRY_SIZE] = |
37c18eed SD |
440 | { |
441 | 0x5f, 0x24, 0x03, 0xd5, /* bti c. */ | |
442 | 0xe2, 0x0f, 0xbf, 0xa9, /* stp x2, x3, [sp, #-16]! */ | |
443 | 0x02, 0x00, 0x00, 0x90, /* adrp x2, 0 */ | |
444 | 0x03, 0x00, 0x00, 0x90, /* adrp x3, 0 */ | |
445 | #if ARCH_SIZE == 64 | |
446 | 0x42, 0x00, 0x40, 0xf9, /* ldr x2, [x2, #0] */ | |
447 | 0x63, 0x00, 0x00, 0x91, /* add x3, x3, 0 */ | |
448 | #else | |
449 | 0x42, 0x00, 0x40, 0xb9, /* ldr w2, [x2, #0] */ | |
450 | 0x63, 0x00, 0x00, 0x11, /* add w3, w3, 0 */ | |
451 | #endif | |
452 | 0x40, 0x00, 0x1f, 0xd6, /* br x2 */ | |
453 | 0x1f, 0x20, 0x03, 0xd5, /* nop */ | |
37c18eed SD |
454 | }; |
455 | ||
4ca9b406 SP |
456 | static const bfd_byte |
457 | elfNN_aarch64_tlsdesc_small_plt_c64_entry[PLT_TLSDESC_ENTRY_SIZE] = | |
458 | { | |
459 | 0xe2, 0x8f, 0xbf, 0x62, /* stp c2, c3, [sp, #-16]! */ | |
460 | 0x02, 0x00, 0x80, 0x90, /* adrp c2, 0 */ | |
461 | 0x03, 0x00, 0x80, 0x90, /* adrp c3, 0 */ | |
462 | 0x42, 0x00, 0x40, 0xc2, /* ldr c2, [c2, #0] */ | |
463 | 0x63, 0x00, 0x00, 0x02, /* add c3, c3, 0 */ | |
464 | 0x40, 0x10, 0xc2, 0xc2, /* br c2 */ | |
465 | 0x1f, 0x20, 0x03, 0xd5, /* nop */ | |
466 | 0x1f, 0x20, 0x03, 0xd5, /* nop */ | |
467 | }; | |
468 | ||
07d6d2b8 AM |
469 | #define elf_info_to_howto elfNN_aarch64_info_to_howto |
470 | #define elf_info_to_howto_rel elfNN_aarch64_info_to_howto | |
a06ea964 NC |
471 | |
472 | #define AARCH64_ELF_ABI_VERSION 0 | |
a06ea964 NC |
473 | |
474 | /* In case we're on a 32-bit machine, construct a 64-bit "-1" value. */ | |
475 | #define ALL_ONES (~ (bfd_vma) 0) | |
476 | ||
a6bb11b2 YZ |
477 | /* Indexed by the bfd interal reloc enumerators. |
478 | Therefore, the table needs to be synced with BFD_RELOC_AARCH64_* | |
479 | in reloc.c. */ | |
a06ea964 | 480 | |
a6bb11b2 | 481 | static reloc_howto_type elfNN_aarch64_howto_table[] = |
a06ea964 | 482 | { |
a6bb11b2 | 483 | EMPTY_HOWTO (0), |
a06ea964 | 484 | |
a6bb11b2 | 485 | /* Basic data relocations. */ |
a06ea964 | 486 | |
b7f28d87 JW |
487 | /* Deprecated, but retained for backwards compatibility. */ |
488 | HOWTO64 (R_AARCH64_NULL, /* type */ | |
a06ea964 | 489 | 0, /* rightshift */ |
6346d5ca | 490 | 3, /* size (0 = byte, 1 = short, 2 = long) */ |
a6bb11b2 | 491 | 0, /* bitsize */ |
a06ea964 NC |
492 | FALSE, /* pc_relative */ |
493 | 0, /* bitpos */ | |
494 | complain_overflow_dont, /* complain_on_overflow */ | |
495 | bfd_elf_generic_reloc, /* special_function */ | |
a6bb11b2 | 496 | "R_AARCH64_NULL", /* name */ |
a06ea964 NC |
497 | FALSE, /* partial_inplace */ |
498 | 0, /* src_mask */ | |
a6bb11b2 | 499 | 0, /* dst_mask */ |
a06ea964 | 500 | FALSE), /* pcrel_offset */ |
a6bb11b2 | 501 | HOWTO (R_AARCH64_NONE, /* type */ |
a06ea964 | 502 | 0, /* rightshift */ |
6346d5ca | 503 | 3, /* size (0 = byte, 1 = short, 2 = long) */ |
a06ea964 NC |
504 | 0, /* bitsize */ |
505 | FALSE, /* pc_relative */ | |
506 | 0, /* bitpos */ | |
507 | complain_overflow_dont, /* complain_on_overflow */ | |
508 | bfd_elf_generic_reloc, /* special_function */ | |
a6bb11b2 | 509 | "R_AARCH64_NONE", /* name */ |
a06ea964 NC |
510 | FALSE, /* partial_inplace */ |
511 | 0, /* src_mask */ | |
512 | 0, /* dst_mask */ | |
513 | FALSE), /* pcrel_offset */ | |
514 | ||
515 | /* .xword: (S+A) */ | |
a6bb11b2 | 516 | HOWTO64 (AARCH64_R (ABS64), /* type */ |
a06ea964 NC |
517 | 0, /* rightshift */ |
518 | 4, /* size (4 = long long) */ | |
519 | 64, /* bitsize */ | |
520 | FALSE, /* pc_relative */ | |
521 | 0, /* bitpos */ | |
522 | complain_overflow_unsigned, /* complain_on_overflow */ | |
523 | bfd_elf_generic_reloc, /* special_function */ | |
a6bb11b2 | 524 | AARCH64_R_STR (ABS64), /* name */ |
a06ea964 NC |
525 | FALSE, /* partial_inplace */ |
526 | ALL_ONES, /* src_mask */ | |
527 | ALL_ONES, /* dst_mask */ | |
528 | FALSE), /* pcrel_offset */ | |
529 | ||
530 | /* .word: (S+A) */ | |
a6bb11b2 | 531 | HOWTO (AARCH64_R (ABS32), /* type */ |
a06ea964 NC |
532 | 0, /* rightshift */ |
533 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
534 | 32, /* bitsize */ | |
535 | FALSE, /* pc_relative */ | |
536 | 0, /* bitpos */ | |
537 | complain_overflow_unsigned, /* complain_on_overflow */ | |
538 | bfd_elf_generic_reloc, /* special_function */ | |
a6bb11b2 | 539 | AARCH64_R_STR (ABS32), /* name */ |
a06ea964 NC |
540 | FALSE, /* partial_inplace */ |
541 | 0xffffffff, /* src_mask */ | |
542 | 0xffffffff, /* dst_mask */ | |
543 | FALSE), /* pcrel_offset */ | |
544 | ||
545 | /* .half: (S+A) */ | |
a6bb11b2 | 546 | HOWTO (AARCH64_R (ABS16), /* type */ |
a06ea964 NC |
547 | 0, /* rightshift */ |
548 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
549 | 16, /* bitsize */ | |
550 | FALSE, /* pc_relative */ | |
551 | 0, /* bitpos */ | |
552 | complain_overflow_unsigned, /* complain_on_overflow */ | |
553 | bfd_elf_generic_reloc, /* special_function */ | |
a6bb11b2 | 554 | AARCH64_R_STR (ABS16), /* name */ |
a06ea964 NC |
555 | FALSE, /* partial_inplace */ |
556 | 0xffff, /* src_mask */ | |
557 | 0xffff, /* dst_mask */ | |
558 | FALSE), /* pcrel_offset */ | |
559 | ||
560 | /* .xword: (S+A-P) */ | |
a6bb11b2 | 561 | HOWTO64 (AARCH64_R (PREL64), /* type */ |
a06ea964 NC |
562 | 0, /* rightshift */ |
563 | 4, /* size (4 = long long) */ | |
564 | 64, /* bitsize */ | |
565 | TRUE, /* pc_relative */ | |
566 | 0, /* bitpos */ | |
567 | complain_overflow_signed, /* complain_on_overflow */ | |
568 | bfd_elf_generic_reloc, /* special_function */ | |
a6bb11b2 | 569 | AARCH64_R_STR (PREL64), /* name */ |
a06ea964 NC |
570 | FALSE, /* partial_inplace */ |
571 | ALL_ONES, /* src_mask */ | |
572 | ALL_ONES, /* dst_mask */ | |
573 | TRUE), /* pcrel_offset */ | |
574 | ||
575 | /* .word: (S+A-P) */ | |
a6bb11b2 | 576 | HOWTO (AARCH64_R (PREL32), /* type */ |
a06ea964 NC |
577 | 0, /* rightshift */ |
578 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
579 | 32, /* bitsize */ | |
580 | TRUE, /* pc_relative */ | |
581 | 0, /* bitpos */ | |
582 | complain_overflow_signed, /* complain_on_overflow */ | |
583 | bfd_elf_generic_reloc, /* special_function */ | |
a6bb11b2 | 584 | AARCH64_R_STR (PREL32), /* name */ |
a06ea964 NC |
585 | FALSE, /* partial_inplace */ |
586 | 0xffffffff, /* src_mask */ | |
587 | 0xffffffff, /* dst_mask */ | |
588 | TRUE), /* pcrel_offset */ | |
589 | ||
590 | /* .half: (S+A-P) */ | |
a6bb11b2 | 591 | HOWTO (AARCH64_R (PREL16), /* type */ |
a06ea964 NC |
592 | 0, /* rightshift */ |
593 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
594 | 16, /* bitsize */ | |
595 | TRUE, /* pc_relative */ | |
596 | 0, /* bitpos */ | |
597 | complain_overflow_signed, /* complain_on_overflow */ | |
598 | bfd_elf_generic_reloc, /* special_function */ | |
a6bb11b2 | 599 | AARCH64_R_STR (PREL16), /* name */ |
a06ea964 NC |
600 | FALSE, /* partial_inplace */ |
601 | 0xffff, /* src_mask */ | |
602 | 0xffff, /* dst_mask */ | |
603 | TRUE), /* pcrel_offset */ | |
604 | ||
605 | /* Group relocations to create a 16, 32, 48 or 64 bit | |
606 | unsigned data or abs address inline. */ | |
607 | ||
608 | /* MOVZ: ((S+A) >> 0) & 0xffff */ | |
a6bb11b2 | 609 | HOWTO (AARCH64_R (MOVW_UABS_G0), /* type */ |
a06ea964 NC |
610 | 0, /* rightshift */ |
611 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
612 | 16, /* bitsize */ | |
613 | FALSE, /* pc_relative */ | |
614 | 0, /* bitpos */ | |
615 | complain_overflow_unsigned, /* complain_on_overflow */ | |
616 | bfd_elf_generic_reloc, /* special_function */ | |
a6bb11b2 | 617 | AARCH64_R_STR (MOVW_UABS_G0), /* name */ |
a06ea964 NC |
618 | FALSE, /* partial_inplace */ |
619 | 0xffff, /* src_mask */ | |
620 | 0xffff, /* dst_mask */ | |
621 | FALSE), /* pcrel_offset */ | |
622 | ||
623 | /* MOVK: ((S+A) >> 0) & 0xffff [no overflow check] */ | |
a6bb11b2 | 624 | HOWTO (AARCH64_R (MOVW_UABS_G0_NC), /* type */ |
a06ea964 NC |
625 | 0, /* rightshift */ |
626 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
627 | 16, /* bitsize */ | |
628 | FALSE, /* pc_relative */ | |
629 | 0, /* bitpos */ | |
630 | complain_overflow_dont, /* complain_on_overflow */ | |
631 | bfd_elf_generic_reloc, /* special_function */ | |
a6bb11b2 | 632 | AARCH64_R_STR (MOVW_UABS_G0_NC), /* name */ |
a06ea964 NC |
633 | FALSE, /* partial_inplace */ |
634 | 0xffff, /* src_mask */ | |
635 | 0xffff, /* dst_mask */ | |
636 | FALSE), /* pcrel_offset */ | |
637 | ||
638 | /* MOVZ: ((S+A) >> 16) & 0xffff */ | |
a6bb11b2 | 639 | HOWTO (AARCH64_R (MOVW_UABS_G1), /* type */ |
a06ea964 NC |
640 | 16, /* rightshift */ |
641 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
642 | 16, /* bitsize */ | |
643 | FALSE, /* pc_relative */ | |
644 | 0, /* bitpos */ | |
645 | complain_overflow_unsigned, /* complain_on_overflow */ | |
646 | bfd_elf_generic_reloc, /* special_function */ | |
a6bb11b2 | 647 | AARCH64_R_STR (MOVW_UABS_G1), /* name */ |
a06ea964 NC |
648 | FALSE, /* partial_inplace */ |
649 | 0xffff, /* src_mask */ | |
650 | 0xffff, /* dst_mask */ | |
651 | FALSE), /* pcrel_offset */ | |
652 | ||
653 | /* MOVK: ((S+A) >> 16) & 0xffff [no overflow check] */ | |
a6bb11b2 | 654 | HOWTO64 (AARCH64_R (MOVW_UABS_G1_NC), /* type */ |
a06ea964 NC |
655 | 16, /* rightshift */ |
656 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
657 | 16, /* bitsize */ | |
658 | FALSE, /* pc_relative */ | |
659 | 0, /* bitpos */ | |
660 | complain_overflow_dont, /* complain_on_overflow */ | |
661 | bfd_elf_generic_reloc, /* special_function */ | |
a6bb11b2 | 662 | AARCH64_R_STR (MOVW_UABS_G1_NC), /* name */ |
a06ea964 NC |
663 | FALSE, /* partial_inplace */ |
664 | 0xffff, /* src_mask */ | |
665 | 0xffff, /* dst_mask */ | |
666 | FALSE), /* pcrel_offset */ | |
667 | ||
668 | /* MOVZ: ((S+A) >> 32) & 0xffff */ | |
a6bb11b2 | 669 | HOWTO64 (AARCH64_R (MOVW_UABS_G2), /* type */ |
a06ea964 NC |
670 | 32, /* rightshift */ |
671 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
672 | 16, /* bitsize */ | |
673 | FALSE, /* pc_relative */ | |
674 | 0, /* bitpos */ | |
675 | complain_overflow_unsigned, /* complain_on_overflow */ | |
676 | bfd_elf_generic_reloc, /* special_function */ | |
a6bb11b2 | 677 | AARCH64_R_STR (MOVW_UABS_G2), /* name */ |
a06ea964 NC |
678 | FALSE, /* partial_inplace */ |
679 | 0xffff, /* src_mask */ | |
680 | 0xffff, /* dst_mask */ | |
681 | FALSE), /* pcrel_offset */ | |
682 | ||
683 | /* MOVK: ((S+A) >> 32) & 0xffff [no overflow check] */ | |
a6bb11b2 | 684 | HOWTO64 (AARCH64_R (MOVW_UABS_G2_NC), /* type */ |
a06ea964 NC |
685 | 32, /* rightshift */ |
686 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
687 | 16, /* bitsize */ | |
688 | FALSE, /* pc_relative */ | |
689 | 0, /* bitpos */ | |
690 | complain_overflow_dont, /* complain_on_overflow */ | |
691 | bfd_elf_generic_reloc, /* special_function */ | |
a6bb11b2 | 692 | AARCH64_R_STR (MOVW_UABS_G2_NC), /* name */ |
a06ea964 NC |
693 | FALSE, /* partial_inplace */ |
694 | 0xffff, /* src_mask */ | |
695 | 0xffff, /* dst_mask */ | |
696 | FALSE), /* pcrel_offset */ | |
697 | ||
698 | /* MOVZ: ((S+A) >> 48) & 0xffff */ | |
a6bb11b2 | 699 | HOWTO64 (AARCH64_R (MOVW_UABS_G3), /* type */ |
a06ea964 NC |
700 | 48, /* rightshift */ |
701 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
702 | 16, /* bitsize */ | |
703 | FALSE, /* pc_relative */ | |
704 | 0, /* bitpos */ | |
705 | complain_overflow_unsigned, /* complain_on_overflow */ | |
706 | bfd_elf_generic_reloc, /* special_function */ | |
a6bb11b2 | 707 | AARCH64_R_STR (MOVW_UABS_G3), /* name */ |
a06ea964 NC |
708 | FALSE, /* partial_inplace */ |
709 | 0xffff, /* src_mask */ | |
710 | 0xffff, /* dst_mask */ | |
711 | FALSE), /* pcrel_offset */ | |
712 | ||
713 | /* Group relocations to create high part of a 16, 32, 48 or 64 bit | |
714 | signed data or abs address inline. Will change instruction | |
715 | to MOVN or MOVZ depending on sign of calculated value. */ | |
716 | ||
717 | /* MOV[ZN]: ((S+A) >> 0) & 0xffff */ | |
a6bb11b2 | 718 | HOWTO (AARCH64_R (MOVW_SABS_G0), /* type */ |
a06ea964 NC |
719 | 0, /* rightshift */ |
720 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
c5e3a364 | 721 | 17, /* bitsize */ |
a06ea964 NC |
722 | FALSE, /* pc_relative */ |
723 | 0, /* bitpos */ | |
724 | complain_overflow_signed, /* complain_on_overflow */ | |
725 | bfd_elf_generic_reloc, /* special_function */ | |
a6bb11b2 | 726 | AARCH64_R_STR (MOVW_SABS_G0), /* name */ |
a06ea964 NC |
727 | FALSE, /* partial_inplace */ |
728 | 0xffff, /* src_mask */ | |
729 | 0xffff, /* dst_mask */ | |
730 | FALSE), /* pcrel_offset */ | |
731 | ||
732 | /* MOV[ZN]: ((S+A) >> 16) & 0xffff */ | |
a6bb11b2 | 733 | HOWTO64 (AARCH64_R (MOVW_SABS_G1), /* type */ |
a06ea964 NC |
734 | 16, /* rightshift */ |
735 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
c5e3a364 | 736 | 17, /* bitsize */ |
a06ea964 NC |
737 | FALSE, /* pc_relative */ |
738 | 0, /* bitpos */ | |
739 | complain_overflow_signed, /* complain_on_overflow */ | |
740 | bfd_elf_generic_reloc, /* special_function */ | |
a6bb11b2 | 741 | AARCH64_R_STR (MOVW_SABS_G1), /* name */ |
a06ea964 NC |
742 | FALSE, /* partial_inplace */ |
743 | 0xffff, /* src_mask */ | |
744 | 0xffff, /* dst_mask */ | |
745 | FALSE), /* pcrel_offset */ | |
746 | ||
747 | /* MOV[ZN]: ((S+A) >> 32) & 0xffff */ | |
a6bb11b2 | 748 | HOWTO64 (AARCH64_R (MOVW_SABS_G2), /* type */ |
a06ea964 NC |
749 | 32, /* rightshift */ |
750 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
c5e3a364 | 751 | 17, /* bitsize */ |
a06ea964 NC |
752 | FALSE, /* pc_relative */ |
753 | 0, /* bitpos */ | |
754 | complain_overflow_signed, /* complain_on_overflow */ | |
755 | bfd_elf_generic_reloc, /* special_function */ | |
a6bb11b2 | 756 | AARCH64_R_STR (MOVW_SABS_G2), /* name */ |
a06ea964 NC |
757 | FALSE, /* partial_inplace */ |
758 | 0xffff, /* src_mask */ | |
759 | 0xffff, /* dst_mask */ | |
760 | FALSE), /* pcrel_offset */ | |
761 | ||
32247401 RL |
762 | /* Group relocations to create a 16, 32, 48 or 64 bit |
763 | PC relative address inline. */ | |
764 | ||
765 | /* MOV[NZ]: ((S+A-P) >> 0) & 0xffff */ | |
e30d1fa1 | 766 | HOWTO (AARCH64_R (MOVW_PREL_G0), /* type */ |
32247401 RL |
767 | 0, /* rightshift */ |
768 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
769 | 17, /* bitsize */ | |
770 | TRUE, /* pc_relative */ | |
771 | 0, /* bitpos */ | |
772 | complain_overflow_signed, /* complain_on_overflow */ | |
773 | bfd_elf_generic_reloc, /* special_function */ | |
774 | AARCH64_R_STR (MOVW_PREL_G0), /* name */ | |
775 | FALSE, /* partial_inplace */ | |
776 | 0xffff, /* src_mask */ | |
777 | 0xffff, /* dst_mask */ | |
778 | TRUE), /* pcrel_offset */ | |
779 | ||
780 | /* MOVK: ((S+A-P) >> 0) & 0xffff [no overflow check] */ | |
e30d1fa1 | 781 | HOWTO (AARCH64_R (MOVW_PREL_G0_NC), /* type */ |
32247401 RL |
782 | 0, /* rightshift */ |
783 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
784 | 16, /* bitsize */ | |
785 | TRUE, /* pc_relative */ | |
786 | 0, /* bitpos */ | |
787 | complain_overflow_dont, /* complain_on_overflow */ | |
788 | bfd_elf_generic_reloc, /* special_function */ | |
789 | AARCH64_R_STR (MOVW_PREL_G0_NC), /* name */ | |
790 | FALSE, /* partial_inplace */ | |
791 | 0xffff, /* src_mask */ | |
792 | 0xffff, /* dst_mask */ | |
793 | TRUE), /* pcrel_offset */ | |
794 | ||
795 | /* MOV[NZ]: ((S+A-P) >> 16) & 0xffff */ | |
e30d1fa1 | 796 | HOWTO (AARCH64_R (MOVW_PREL_G1), /* type */ |
32247401 RL |
797 | 16, /* rightshift */ |
798 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
799 | 17, /* bitsize */ | |
800 | TRUE, /* pc_relative */ | |
801 | 0, /* bitpos */ | |
802 | complain_overflow_signed, /* complain_on_overflow */ | |
803 | bfd_elf_generic_reloc, /* special_function */ | |
804 | AARCH64_R_STR (MOVW_PREL_G1), /* name */ | |
805 | FALSE, /* partial_inplace */ | |
806 | 0xffff, /* src_mask */ | |
807 | 0xffff, /* dst_mask */ | |
808 | TRUE), /* pcrel_offset */ | |
809 | ||
810 | /* MOVK: ((S+A-P) >> 16) & 0xffff [no overflow check] */ | |
811 | HOWTO64 (AARCH64_R (MOVW_PREL_G1_NC), /* type */ | |
812 | 16, /* rightshift */ | |
813 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
814 | 16, /* bitsize */ | |
815 | TRUE, /* pc_relative */ | |
816 | 0, /* bitpos */ | |
817 | complain_overflow_dont, /* complain_on_overflow */ | |
818 | bfd_elf_generic_reloc, /* special_function */ | |
819 | AARCH64_R_STR (MOVW_PREL_G1_NC), /* name */ | |
820 | FALSE, /* partial_inplace */ | |
821 | 0xffff, /* src_mask */ | |
822 | 0xffff, /* dst_mask */ | |
823 | TRUE), /* pcrel_offset */ | |
824 | ||
825 | /* MOV[NZ]: ((S+A-P) >> 32) & 0xffff */ | |
826 | HOWTO64 (AARCH64_R (MOVW_PREL_G2), /* type */ | |
827 | 32, /* rightshift */ | |
828 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
829 | 17, /* bitsize */ | |
830 | TRUE, /* pc_relative */ | |
831 | 0, /* bitpos */ | |
832 | complain_overflow_signed, /* complain_on_overflow */ | |
833 | bfd_elf_generic_reloc, /* special_function */ | |
834 | AARCH64_R_STR (MOVW_PREL_G2), /* name */ | |
835 | FALSE, /* partial_inplace */ | |
836 | 0xffff, /* src_mask */ | |
837 | 0xffff, /* dst_mask */ | |
838 | TRUE), /* pcrel_offset */ | |
839 | ||
840 | /* MOVK: ((S+A-P) >> 32) & 0xffff [no overflow check] */ | |
841 | HOWTO64 (AARCH64_R (MOVW_PREL_G2_NC), /* type */ | |
842 | 32, /* rightshift */ | |
843 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
844 | 16, /* bitsize */ | |
845 | TRUE, /* pc_relative */ | |
846 | 0, /* bitpos */ | |
847 | complain_overflow_dont, /* complain_on_overflow */ | |
848 | bfd_elf_generic_reloc, /* special_function */ | |
849 | AARCH64_R_STR (MOVW_PREL_G2_NC), /* name */ | |
850 | FALSE, /* partial_inplace */ | |
851 | 0xffff, /* src_mask */ | |
852 | 0xffff, /* dst_mask */ | |
853 | TRUE), /* pcrel_offset */ | |
854 | ||
855 | /* MOV[NZ]: ((S+A-P) >> 48) & 0xffff */ | |
856 | HOWTO64 (AARCH64_R (MOVW_PREL_G3), /* type */ | |
857 | 48, /* rightshift */ | |
858 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
859 | 16, /* bitsize */ | |
860 | TRUE, /* pc_relative */ | |
861 | 0, /* bitpos */ | |
862 | complain_overflow_dont, /* complain_on_overflow */ | |
863 | bfd_elf_generic_reloc, /* special_function */ | |
864 | AARCH64_R_STR (MOVW_PREL_G3), /* name */ | |
865 | FALSE, /* partial_inplace */ | |
866 | 0xffff, /* src_mask */ | |
867 | 0xffff, /* dst_mask */ | |
868 | TRUE), /* pcrel_offset */ | |
869 | ||
a06ea964 NC |
870 | /* Relocations to generate 19, 21 and 33 bit PC-relative load/store |
871 | addresses: PG(x) is (x & ~0xfff). */ | |
872 | ||
f7d2c675 SP |
873 | /* LD-lit: ((S+A-P) >> 4) & 0x1ffff */ |
874 | HOWTO64 (MORELLO_R (LD_PREL_LO17), /* type */ | |
875 | 4, /* rightshift */ | |
876 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
877 | 17, /* bitsize */ | |
878 | TRUE, /* pc_relative */ | |
879 | 0, /* bitpos */ | |
880 | complain_overflow_signed, /* complain_on_overflow */ | |
881 | bfd_elf_generic_reloc, /* special_function */ | |
882 | MORELLO_R_STR (LD_PREL_LO17), /* name */ | |
883 | FALSE, /* partial_inplace */ | |
884 | 0x1ffff, /* src_mask */ | |
885 | 0x1ffff, /* dst_mask */ | |
886 | TRUE), /* pcrel_offset */ | |
887 | ||
a06ea964 | 888 | /* LD-lit: ((S+A-P) >> 2) & 0x7ffff */ |
a6bb11b2 | 889 | HOWTO (AARCH64_R (LD_PREL_LO19), /* type */ |
a06ea964 NC |
890 | 2, /* rightshift */ |
891 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
892 | 19, /* bitsize */ | |
893 | TRUE, /* pc_relative */ | |
894 | 0, /* bitpos */ | |
895 | complain_overflow_signed, /* complain_on_overflow */ | |
896 | bfd_elf_generic_reloc, /* special_function */ | |
a6bb11b2 | 897 | AARCH64_R_STR (LD_PREL_LO19), /* name */ |
a06ea964 NC |
898 | FALSE, /* partial_inplace */ |
899 | 0x7ffff, /* src_mask */ | |
900 | 0x7ffff, /* dst_mask */ | |
901 | TRUE), /* pcrel_offset */ | |
902 | ||
92504105 SP |
903 | /* C64 ADRP: ((PG(S+A)-PG(P)) >> 12) & 0xfffff */ |
904 | HOWTO64 (MORELLO_R (ADR_PREL_PG_HI20), /* type */ | |
905 | 12, /* rightshift */ | |
906 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
907 | 20, /* bitsize */ | |
908 | TRUE, /* pc_relative */ | |
909 | 0, /* bitpos */ | |
910 | complain_overflow_signed, /* complain_on_overflow */ | |
911 | bfd_elf_generic_reloc, /* special_function */ | |
912 | MORELLO_R_STR (ADR_PREL_PG_HI20), /* name */ | |
913 | FALSE, /* partial_inplace */ | |
914 | 0xfffff, /* src_mask */ | |
915 | 0xfffff, /* dst_mask */ | |
916 | TRUE), /* pcrel_offset */ | |
917 | ||
918 | /* C64 ADRP: ((PG(S+A)-PG(P)) >> 12) & 0xfffff [no overflow check] */ | |
919 | HOWTO64 (MORELLO_R (ADR_PREL_PG_HI20_NC), /* type */ | |
920 | 12, /* rightshift */ | |
921 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
922 | 20, /* bitsize */ | |
923 | TRUE, /* pc_relative */ | |
924 | 0, /* bitpos */ | |
925 | complain_overflow_dont, /* complain_on_overflow */ | |
926 | bfd_elf_generic_reloc, /* special_function */ | |
927 | MORELLO_R_STR (ADR_PREL_PG_HI20_NC), /* name */ | |
928 | FALSE, /* partial_inplace */ | |
929 | 0xfffff, /* src_mask */ | |
930 | 0xfffff, /* dst_mask */ | |
931 | TRUE), /* pcrel_offset */ | |
932 | ||
a06ea964 | 933 | /* ADR: (S+A-P) & 0x1fffff */ |
a6bb11b2 | 934 | HOWTO (AARCH64_R (ADR_PREL_LO21), /* type */ |
a06ea964 NC |
935 | 0, /* rightshift */ |
936 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
937 | 21, /* bitsize */ | |
938 | TRUE, /* pc_relative */ | |
939 | 0, /* bitpos */ | |
940 | complain_overflow_signed, /* complain_on_overflow */ | |
941 | bfd_elf_generic_reloc, /* special_function */ | |
a6bb11b2 | 942 | AARCH64_R_STR (ADR_PREL_LO21), /* name */ |
a06ea964 NC |
943 | FALSE, /* partial_inplace */ |
944 | 0x1fffff, /* src_mask */ | |
945 | 0x1fffff, /* dst_mask */ | |
946 | TRUE), /* pcrel_offset */ | |
947 | ||
948 | /* ADRP: ((PG(S+A)-PG(P)) >> 12) & 0x1fffff */ | |
a6bb11b2 | 949 | HOWTO (AARCH64_R (ADR_PREL_PG_HI21), /* type */ |
a06ea964 NC |
950 | 12, /* rightshift */ |
951 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
952 | 21, /* bitsize */ | |
953 | TRUE, /* pc_relative */ | |
954 | 0, /* bitpos */ | |
955 | complain_overflow_signed, /* complain_on_overflow */ | |
956 | bfd_elf_generic_reloc, /* special_function */ | |
a6bb11b2 | 957 | AARCH64_R_STR (ADR_PREL_PG_HI21), /* name */ |
a06ea964 NC |
958 | FALSE, /* partial_inplace */ |
959 | 0x1fffff, /* src_mask */ | |
960 | 0x1fffff, /* dst_mask */ | |
961 | TRUE), /* pcrel_offset */ | |
962 | ||
963 | /* ADRP: ((PG(S+A)-PG(P)) >> 12) & 0x1fffff [no overflow check] */ | |
a6bb11b2 | 964 | HOWTO64 (AARCH64_R (ADR_PREL_PG_HI21_NC), /* type */ |
a06ea964 NC |
965 | 12, /* rightshift */ |
966 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
967 | 21, /* bitsize */ | |
968 | TRUE, /* pc_relative */ | |
969 | 0, /* bitpos */ | |
970 | complain_overflow_dont, /* complain_on_overflow */ | |
971 | bfd_elf_generic_reloc, /* special_function */ | |
a6bb11b2 | 972 | AARCH64_R_STR (ADR_PREL_PG_HI21_NC), /* name */ |
a06ea964 NC |
973 | FALSE, /* partial_inplace */ |
974 | 0x1fffff, /* src_mask */ | |
975 | 0x1fffff, /* dst_mask */ | |
976 | TRUE), /* pcrel_offset */ | |
977 | ||
978 | /* ADD: (S+A) & 0xfff [no overflow check] */ | |
a6bb11b2 | 979 | HOWTO (AARCH64_R (ADD_ABS_LO12_NC), /* type */ |
a06ea964 NC |
980 | 0, /* rightshift */ |
981 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
982 | 12, /* bitsize */ | |
983 | FALSE, /* pc_relative */ | |
984 | 10, /* bitpos */ | |
985 | complain_overflow_dont, /* complain_on_overflow */ | |
986 | bfd_elf_generic_reloc, /* special_function */ | |
a6bb11b2 | 987 | AARCH64_R_STR (ADD_ABS_LO12_NC), /* name */ |
a06ea964 NC |
988 | FALSE, /* partial_inplace */ |
989 | 0x3ffc00, /* src_mask */ | |
990 | 0x3ffc00, /* dst_mask */ | |
991 | FALSE), /* pcrel_offset */ | |
992 | ||
993 | /* LD/ST8: (S+A) & 0xfff */ | |
a6bb11b2 | 994 | HOWTO (AARCH64_R (LDST8_ABS_LO12_NC), /* type */ |
a06ea964 NC |
995 | 0, /* rightshift */ |
996 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
997 | 12, /* bitsize */ | |
998 | FALSE, /* pc_relative */ | |
999 | 0, /* bitpos */ | |
1000 | complain_overflow_dont, /* complain_on_overflow */ | |
1001 | bfd_elf_generic_reloc, /* special_function */ | |
a6bb11b2 | 1002 | AARCH64_R_STR (LDST8_ABS_LO12_NC), /* name */ |
a06ea964 NC |
1003 | FALSE, /* partial_inplace */ |
1004 | 0xfff, /* src_mask */ | |
1005 | 0xfff, /* dst_mask */ | |
1006 | FALSE), /* pcrel_offset */ | |
1007 | ||
1008 | /* Relocations for control-flow instructions. */ | |
1009 | ||
1010 | /* TBZ/NZ: ((S+A-P) >> 2) & 0x3fff */ | |
a6bb11b2 | 1011 | HOWTO (AARCH64_R (TSTBR14), /* type */ |
a06ea964 NC |
1012 | 2, /* rightshift */ |
1013 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1014 | 14, /* bitsize */ | |
1015 | TRUE, /* pc_relative */ | |
1016 | 0, /* bitpos */ | |
1017 | complain_overflow_signed, /* complain_on_overflow */ | |
1018 | bfd_elf_generic_reloc, /* special_function */ | |
a6bb11b2 | 1019 | AARCH64_R_STR (TSTBR14), /* name */ |
a06ea964 NC |
1020 | FALSE, /* partial_inplace */ |
1021 | 0x3fff, /* src_mask */ | |
1022 | 0x3fff, /* dst_mask */ | |
1023 | TRUE), /* pcrel_offset */ | |
1024 | ||
1025 | /* B.cond: ((S+A-P) >> 2) & 0x7ffff */ | |
a6bb11b2 | 1026 | HOWTO (AARCH64_R (CONDBR19), /* type */ |
a06ea964 NC |
1027 | 2, /* rightshift */ |
1028 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1029 | 19, /* bitsize */ | |
1030 | TRUE, /* pc_relative */ | |
1031 | 0, /* bitpos */ | |
1032 | complain_overflow_signed, /* complain_on_overflow */ | |
1033 | bfd_elf_generic_reloc, /* special_function */ | |
a6bb11b2 | 1034 | AARCH64_R_STR (CONDBR19), /* name */ |
a06ea964 NC |
1035 | FALSE, /* partial_inplace */ |
1036 | 0x7ffff, /* src_mask */ | |
1037 | 0x7ffff, /* dst_mask */ | |
1038 | TRUE), /* pcrel_offset */ | |
1039 | ||
a06ea964 | 1040 | /* B: ((S+A-P) >> 2) & 0x3ffffff */ |
a6bb11b2 | 1041 | HOWTO (AARCH64_R (JUMP26), /* type */ |
a06ea964 NC |
1042 | 2, /* rightshift */ |
1043 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1044 | 26, /* bitsize */ | |
1045 | TRUE, /* pc_relative */ | |
1046 | 0, /* bitpos */ | |
1047 | complain_overflow_signed, /* complain_on_overflow */ | |
1048 | bfd_elf_generic_reloc, /* special_function */ | |
a6bb11b2 | 1049 | AARCH64_R_STR (JUMP26), /* name */ |
a06ea964 NC |
1050 | FALSE, /* partial_inplace */ |
1051 | 0x3ffffff, /* src_mask */ | |
1052 | 0x3ffffff, /* dst_mask */ | |
1053 | TRUE), /* pcrel_offset */ | |
1054 | ||
1055 | /* BL: ((S+A-P) >> 2) & 0x3ffffff */ | |
a6bb11b2 | 1056 | HOWTO (AARCH64_R (CALL26), /* type */ |
a06ea964 NC |
1057 | 2, /* rightshift */ |
1058 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1059 | 26, /* bitsize */ | |
1060 | TRUE, /* pc_relative */ | |
1061 | 0, /* bitpos */ | |
1062 | complain_overflow_signed, /* complain_on_overflow */ | |
1063 | bfd_elf_generic_reloc, /* special_function */ | |
a6bb11b2 | 1064 | AARCH64_R_STR (CALL26), /* name */ |
a06ea964 NC |
1065 | FALSE, /* partial_inplace */ |
1066 | 0x3ffffff, /* src_mask */ | |
1067 | 0x3ffffff, /* dst_mask */ | |
1068 | TRUE), /* pcrel_offset */ | |
1069 | ||
e19e9199 SP |
1070 | /* TBZ/NZ: ((S+A-P) >> 2) & 0x3fff */ |
1071 | HOWTO64 (MORELLO_R (TSTBR14), /* type */ | |
1072 | 2, /* rightshift */ | |
1073 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1074 | 14, /* bitsize */ | |
1075 | TRUE, /* pc_relative */ | |
1076 | 0, /* bitpos */ | |
1077 | complain_overflow_signed, /* complain_on_overflow */ | |
1078 | bfd_elf_generic_reloc, /* special_function */ | |
1079 | MORELLO_R_STR (TSTBR14), /* name */ | |
1080 | FALSE, /* partial_inplace */ | |
1081 | 0x3fff, /* src_mask */ | |
1082 | 0x3fff, /* dst_mask */ | |
1083 | TRUE), /* pcrel_offset */ | |
1084 | ||
1085 | /* B.cond: ((S+A-P) >> 2) & 0x7ffff */ | |
1086 | HOWTO64 (MORELLO_R (CONDBR19), /* type */ | |
1087 | 2, /* rightshift */ | |
1088 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1089 | 19, /* bitsize */ | |
1090 | TRUE, /* pc_relative */ | |
1091 | 0, /* bitpos */ | |
1092 | complain_overflow_signed, /* complain_on_overflow */ | |
1093 | bfd_elf_generic_reloc, /* special_function */ | |
1094 | MORELLO_R_STR (CONDBR19), /* name */ | |
1095 | FALSE, /* partial_inplace */ | |
1096 | 0x7ffff, /* src_mask */ | |
1097 | 0x7ffff, /* dst_mask */ | |
1098 | TRUE), /* pcrel_offset */ | |
1099 | ||
1100 | /* B: ((S+A-P) >> 2) & 0x3ffffff */ | |
1101 | HOWTO64 (MORELLO_R (JUMP26), /* type */ | |
1102 | 2, /* rightshift */ | |
1103 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1104 | 26, /* bitsize */ | |
1105 | TRUE, /* pc_relative */ | |
1106 | 0, /* bitpos */ | |
1107 | complain_overflow_signed, /* complain_on_overflow */ | |
1108 | bfd_elf_generic_reloc, /* special_function */ | |
1109 | MORELLO_R_STR (JUMP26), /* name */ | |
1110 | FALSE, /* partial_inplace */ | |
1111 | 0x3ffffff, /* src_mask */ | |
1112 | 0x3ffffff, /* dst_mask */ | |
1113 | TRUE), /* pcrel_offset */ | |
1114 | ||
1115 | /* BL: ((S+A-P) >> 2) & 0x3ffffff */ | |
1116 | HOWTO64 (MORELLO_R (CALL26), /* type */ | |
1117 | 2, /* rightshift */ | |
1118 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1119 | 26, /* bitsize */ | |
1120 | TRUE, /* pc_relative */ | |
1121 | 0, /* bitpos */ | |
1122 | complain_overflow_signed, /* complain_on_overflow */ | |
1123 | bfd_elf_generic_reloc, /* special_function */ | |
1124 | MORELLO_R_STR (CALL26), /* name */ | |
1125 | FALSE, /* partial_inplace */ | |
1126 | 0x3ffffff, /* src_mask */ | |
1127 | 0x3ffffff, /* dst_mask */ | |
1128 | TRUE), /* pcrel_offset */ | |
1129 | ||
a06ea964 | 1130 | /* LD/ST16: (S+A) & 0xffe */ |
a6bb11b2 | 1131 | HOWTO (AARCH64_R (LDST16_ABS_LO12_NC), /* type */ |
a06ea964 NC |
1132 | 1, /* rightshift */ |
1133 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1134 | 12, /* bitsize */ | |
1135 | FALSE, /* pc_relative */ | |
1136 | 0, /* bitpos */ | |
1137 | complain_overflow_dont, /* complain_on_overflow */ | |
1138 | bfd_elf_generic_reloc, /* special_function */ | |
a6bb11b2 | 1139 | AARCH64_R_STR (LDST16_ABS_LO12_NC), /* name */ |
a06ea964 NC |
1140 | FALSE, /* partial_inplace */ |
1141 | 0xffe, /* src_mask */ | |
1142 | 0xffe, /* dst_mask */ | |
1143 | FALSE), /* pcrel_offset */ | |
1144 | ||
1145 | /* LD/ST32: (S+A) & 0xffc */ | |
a6bb11b2 | 1146 | HOWTO (AARCH64_R (LDST32_ABS_LO12_NC), /* type */ |
a06ea964 NC |
1147 | 2, /* rightshift */ |
1148 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1149 | 12, /* bitsize */ | |
1150 | FALSE, /* pc_relative */ | |
1151 | 0, /* bitpos */ | |
1152 | complain_overflow_dont, /* complain_on_overflow */ | |
1153 | bfd_elf_generic_reloc, /* special_function */ | |
a6bb11b2 | 1154 | AARCH64_R_STR (LDST32_ABS_LO12_NC), /* name */ |
a06ea964 NC |
1155 | FALSE, /* partial_inplace */ |
1156 | 0xffc, /* src_mask */ | |
1157 | 0xffc, /* dst_mask */ | |
1158 | FALSE), /* pcrel_offset */ | |
1159 | ||
1160 | /* LD/ST64: (S+A) & 0xff8 */ | |
a6bb11b2 | 1161 | HOWTO (AARCH64_R (LDST64_ABS_LO12_NC), /* type */ |
a06ea964 NC |
1162 | 3, /* rightshift */ |
1163 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1164 | 12, /* bitsize */ | |
1165 | FALSE, /* pc_relative */ | |
1166 | 0, /* bitpos */ | |
1167 | complain_overflow_dont, /* complain_on_overflow */ | |
1168 | bfd_elf_generic_reloc, /* special_function */ | |
a6bb11b2 | 1169 | AARCH64_R_STR (LDST64_ABS_LO12_NC), /* name */ |
a06ea964 NC |
1170 | FALSE, /* partial_inplace */ |
1171 | 0xff8, /* src_mask */ | |
1172 | 0xff8, /* dst_mask */ | |
1173 | FALSE), /* pcrel_offset */ | |
1174 | ||
a06ea964 | 1175 | /* LD/ST128: (S+A) & 0xff0 */ |
a6bb11b2 | 1176 | HOWTO (AARCH64_R (LDST128_ABS_LO12_NC), /* type */ |
a06ea964 NC |
1177 | 4, /* rightshift */ |
1178 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1179 | 12, /* bitsize */ | |
1180 | FALSE, /* pc_relative */ | |
1181 | 0, /* bitpos */ | |
1182 | complain_overflow_dont, /* complain_on_overflow */ | |
1183 | bfd_elf_generic_reloc, /* special_function */ | |
a6bb11b2 | 1184 | AARCH64_R_STR (LDST128_ABS_LO12_NC), /* name */ |
a06ea964 NC |
1185 | FALSE, /* partial_inplace */ |
1186 | 0xff0, /* src_mask */ | |
1187 | 0xff0, /* dst_mask */ | |
1188 | FALSE), /* pcrel_offset */ | |
1189 | ||
f41aef5f RE |
1190 | /* Set a load-literal immediate field to bits |
1191 | 0x1FFFFC of G(S)-P */ | |
a6bb11b2 | 1192 | HOWTO (AARCH64_R (GOT_LD_PREL19), /* type */ |
f41aef5f RE |
1193 | 2, /* rightshift */ |
1194 | 2, /* size (0 = byte,1 = short,2 = long) */ | |
1195 | 19, /* bitsize */ | |
1196 | TRUE, /* pc_relative */ | |
1197 | 0, /* bitpos */ | |
1198 | complain_overflow_signed, /* complain_on_overflow */ | |
1199 | bfd_elf_generic_reloc, /* special_function */ | |
a6bb11b2 | 1200 | AARCH64_R_STR (GOT_LD_PREL19), /* name */ |
f41aef5f RE |
1201 | FALSE, /* partial_inplace */ |
1202 | 0xffffe0, /* src_mask */ | |
1203 | 0xffffe0, /* dst_mask */ | |
1204 | TRUE), /* pcrel_offset */ | |
1205 | ||
a06ea964 NC |
1206 | /* Get to the page for the GOT entry for the symbol |
1207 | (G(S) - P) using an ADRP instruction. */ | |
a6bb11b2 | 1208 | HOWTO (AARCH64_R (ADR_GOT_PAGE), /* type */ |
a06ea964 NC |
1209 | 12, /* rightshift */ |
1210 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1211 | 21, /* bitsize */ | |
1212 | TRUE, /* pc_relative */ | |
1213 | 0, /* bitpos */ | |
1214 | complain_overflow_dont, /* complain_on_overflow */ | |
1215 | bfd_elf_generic_reloc, /* special_function */ | |
a6bb11b2 | 1216 | AARCH64_R_STR (ADR_GOT_PAGE), /* name */ |
a06ea964 NC |
1217 | FALSE, /* partial_inplace */ |
1218 | 0x1fffff, /* src_mask */ | |
1219 | 0x1fffff, /* dst_mask */ | |
1220 | TRUE), /* pcrel_offset */ | |
1221 | ||
92504105 SP |
1222 | /* Get to the page for the GOT entry for the symbol |
1223 | (G(S) - P) using a C64 ADRP instruction. */ | |
1224 | HOWTO64 (MORELLO_R (ADR_GOT_PAGE), /* type */ | |
1225 | 12, /* rightshift */ | |
1226 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1227 | 20, /* bitsize */ | |
1228 | TRUE, /* pc_relative */ | |
1229 | 0, /* bitpos */ | |
1230 | complain_overflow_dont, /* complain_on_overflow */ | |
1231 | bfd_elf_generic_reloc, /* special_function */ | |
1232 | MORELLO_R_STR (ADR_GOT_PAGE), /* name */ | |
1233 | FALSE, /* partial_inplace */ | |
1234 | 0xfffff, /* src_mask */ | |
1235 | 0xfffff, /* dst_mask */ | |
1236 | TRUE), /* pcrel_offset */ | |
1237 | ||
a6bb11b2 YZ |
1238 | /* LD64: GOT offset G(S) & 0xff8 */ |
1239 | HOWTO64 (AARCH64_R (LD64_GOT_LO12_NC), /* type */ | |
a06ea964 NC |
1240 | 3, /* rightshift */ |
1241 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1242 | 12, /* bitsize */ | |
1243 | FALSE, /* pc_relative */ | |
1244 | 0, /* bitpos */ | |
1245 | complain_overflow_dont, /* complain_on_overflow */ | |
1246 | bfd_elf_generic_reloc, /* special_function */ | |
a6bb11b2 | 1247 | AARCH64_R_STR (LD64_GOT_LO12_NC), /* name */ |
a06ea964 NC |
1248 | FALSE, /* partial_inplace */ |
1249 | 0xff8, /* src_mask */ | |
1250 | 0xff8, /* dst_mask */ | |
a6bb11b2 | 1251 | FALSE), /* pcrel_offset */ |
a06ea964 | 1252 | |
a1bdea65 SP |
1253 | /* LD128: GOT offset G(S) & 0xff0 */ |
1254 | HOWTO64 (MORELLO_R (LD128_GOT_LO12_NC), /* type */ | |
1255 | 4, /* rightshift */ | |
1256 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1257 | 12, /* bitsize */ | |
1258 | FALSE, /* pc_relative */ | |
1259 | 0, /* bitpos */ | |
1260 | complain_overflow_dont, /* complain_on_overflow */ | |
1261 | bfd_elf_generic_reloc, /* special_function */ | |
1262 | MORELLO_R_STR (LD128_GOT_LO12_NC), /* name */ | |
1263 | FALSE, /* partial_inplace */ | |
1264 | 0xff0, /* src_mask */ | |
1265 | 0xff0, /* dst_mask */ | |
1266 | FALSE), /* pcrel_offset */ | |
1267 | ||
a6bb11b2 YZ |
1268 | /* LD32: GOT offset G(S) & 0xffc */ |
1269 | HOWTO32 (AARCH64_R (LD32_GOT_LO12_NC), /* type */ | |
1270 | 2, /* rightshift */ | |
1271 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1272 | 12, /* bitsize */ | |
1273 | FALSE, /* pc_relative */ | |
1274 | 0, /* bitpos */ | |
1275 | complain_overflow_dont, /* complain_on_overflow */ | |
1276 | bfd_elf_generic_reloc, /* special_function */ | |
1277 | AARCH64_R_STR (LD32_GOT_LO12_NC), /* name */ | |
1278 | FALSE, /* partial_inplace */ | |
1279 | 0xffc, /* src_mask */ | |
1280 | 0xffc, /* dst_mask */ | |
1281 | FALSE), /* pcrel_offset */ | |
a06ea964 | 1282 | |
ca632371 RL |
1283 | /* Lower 16 bits of GOT offset for the symbol. */ |
1284 | HOWTO64 (AARCH64_R (MOVW_GOTOFF_G0_NC), /* type */ | |
1285 | 0, /* rightshift */ | |
1286 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1287 | 16, /* bitsize */ | |
1288 | FALSE, /* pc_relative */ | |
1289 | 0, /* bitpos */ | |
1290 | complain_overflow_dont, /* complain_on_overflow */ | |
1291 | bfd_elf_generic_reloc, /* special_function */ | |
1292 | AARCH64_R_STR (MOVW_GOTOFF_G0_NC), /* name */ | |
1293 | FALSE, /* partial_inplace */ | |
1294 | 0xffff, /* src_mask */ | |
1295 | 0xffff, /* dst_mask */ | |
1296 | FALSE), /* pcrel_offset */ | |
1297 | ||
654248e7 RL |
1298 | /* Higher 16 bits of GOT offset for the symbol. */ |
1299 | HOWTO64 (AARCH64_R (MOVW_GOTOFF_G1), /* type */ | |
1300 | 16, /* rightshift */ | |
1301 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1302 | 16, /* bitsize */ | |
1303 | FALSE, /* pc_relative */ | |
1304 | 0, /* bitpos */ | |
1305 | complain_overflow_unsigned, /* complain_on_overflow */ | |
1306 | bfd_elf_generic_reloc, /* special_function */ | |
1307 | AARCH64_R_STR (MOVW_GOTOFF_G1), /* name */ | |
1308 | FALSE, /* partial_inplace */ | |
1309 | 0xffff, /* src_mask */ | |
1310 | 0xffff, /* dst_mask */ | |
1311 | FALSE), /* pcrel_offset */ | |
1312 | ||
87f5fbcc RL |
1313 | /* LD64: GOT offset for the symbol. */ |
1314 | HOWTO64 (AARCH64_R (LD64_GOTOFF_LO15), /* type */ | |
1315 | 3, /* rightshift */ | |
1316 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1317 | 12, /* bitsize */ | |
1318 | FALSE, /* pc_relative */ | |
1319 | 0, /* bitpos */ | |
1320 | complain_overflow_unsigned, /* complain_on_overflow */ | |
1321 | bfd_elf_generic_reloc, /* special_function */ | |
1322 | AARCH64_R_STR (LD64_GOTOFF_LO15), /* name */ | |
1323 | FALSE, /* partial_inplace */ | |
1324 | 0x7ff8, /* src_mask */ | |
1325 | 0x7ff8, /* dst_mask */ | |
1326 | FALSE), /* pcrel_offset */ | |
1327 | ||
3d715ce4 JW |
1328 | /* LD32: GOT offset to the page address of GOT table. |
1329 | (G(S) - PAGE (_GLOBAL_OFFSET_TABLE_)) & 0x5ffc. */ | |
1330 | HOWTO32 (AARCH64_R (LD32_GOTPAGE_LO14), /* type */ | |
1331 | 2, /* rightshift */ | |
1332 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1333 | 12, /* bitsize */ | |
1334 | FALSE, /* pc_relative */ | |
1335 | 0, /* bitpos */ | |
1336 | complain_overflow_unsigned, /* complain_on_overflow */ | |
1337 | bfd_elf_generic_reloc, /* special_function */ | |
1338 | AARCH64_R_STR (LD32_GOTPAGE_LO14), /* name */ | |
1339 | FALSE, /* partial_inplace */ | |
1340 | 0x5ffc, /* src_mask */ | |
1341 | 0x5ffc, /* dst_mask */ | |
1342 | FALSE), /* pcrel_offset */ | |
1343 | ||
a921b5bd JW |
1344 | /* LD64: GOT offset to the page address of GOT table. |
1345 | (G(S) - PAGE (_GLOBAL_OFFSET_TABLE_)) & 0x7ff8. */ | |
1346 | HOWTO64 (AARCH64_R (LD64_GOTPAGE_LO15), /* type */ | |
1347 | 3, /* rightshift */ | |
1348 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1349 | 12, /* bitsize */ | |
1350 | FALSE, /* pc_relative */ | |
1351 | 0, /* bitpos */ | |
1352 | complain_overflow_unsigned, /* complain_on_overflow */ | |
1353 | bfd_elf_generic_reloc, /* special_function */ | |
1354 | AARCH64_R_STR (LD64_GOTPAGE_LO15), /* name */ | |
1355 | FALSE, /* partial_inplace */ | |
1356 | 0x7ff8, /* src_mask */ | |
1357 | 0x7ff8, /* dst_mask */ | |
1358 | FALSE), /* pcrel_offset */ | |
1359 | ||
a06ea964 NC |
1360 | /* Get to the page for the GOT entry for the symbol |
1361 | (G(S) - P) using an ADRP instruction. */ | |
a6bb11b2 | 1362 | HOWTO (AARCH64_R (TLSGD_ADR_PAGE21), /* type */ |
a06ea964 NC |
1363 | 12, /* rightshift */ |
1364 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1365 | 21, /* bitsize */ | |
1366 | TRUE, /* pc_relative */ | |
1367 | 0, /* bitpos */ | |
1368 | complain_overflow_dont, /* complain_on_overflow */ | |
1369 | bfd_elf_generic_reloc, /* special_function */ | |
a6bb11b2 | 1370 | AARCH64_R_STR (TLSGD_ADR_PAGE21), /* name */ |
a06ea964 NC |
1371 | FALSE, /* partial_inplace */ |
1372 | 0x1fffff, /* src_mask */ | |
1373 | 0x1fffff, /* dst_mask */ | |
1374 | TRUE), /* pcrel_offset */ | |
1375 | ||
3c12b054 MS |
1376 | HOWTO (AARCH64_R (TLSGD_ADR_PREL21), /* type */ |
1377 | 0, /* rightshift */ | |
1378 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1379 | 21, /* bitsize */ | |
1380 | TRUE, /* pc_relative */ | |
1381 | 0, /* bitpos */ | |
1382 | complain_overflow_dont, /* complain_on_overflow */ | |
1383 | bfd_elf_generic_reloc, /* special_function */ | |
1384 | AARCH64_R_STR (TLSGD_ADR_PREL21), /* name */ | |
1385 | FALSE, /* partial_inplace */ | |
1386 | 0x1fffff, /* src_mask */ | |
1387 | 0x1fffff, /* dst_mask */ | |
1388 | TRUE), /* pcrel_offset */ | |
1389 | ||
a06ea964 | 1390 | /* ADD: GOT offset G(S) & 0xff8 [no overflow check] */ |
a6bb11b2 | 1391 | HOWTO (AARCH64_R (TLSGD_ADD_LO12_NC), /* type */ |
a06ea964 NC |
1392 | 0, /* rightshift */ |
1393 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1394 | 12, /* bitsize */ | |
1395 | FALSE, /* pc_relative */ | |
1396 | 0, /* bitpos */ | |
1397 | complain_overflow_dont, /* complain_on_overflow */ | |
1398 | bfd_elf_generic_reloc, /* special_function */ | |
a6bb11b2 | 1399 | AARCH64_R_STR (TLSGD_ADD_LO12_NC), /* name */ |
a06ea964 NC |
1400 | FALSE, /* partial_inplace */ |
1401 | 0xfff, /* src_mask */ | |
1402 | 0xfff, /* dst_mask */ | |
1403 | FALSE), /* pcrel_offset */ | |
1404 | ||
3e8286c0 RL |
1405 | /* Lower 16 bits of GOT offset to tls_index. */ |
1406 | HOWTO64 (AARCH64_R (TLSGD_MOVW_G0_NC), /* type */ | |
1407 | 0, /* rightshift */ | |
1408 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1409 | 16, /* bitsize */ | |
1410 | FALSE, /* pc_relative */ | |
1411 | 0, /* bitpos */ | |
1412 | complain_overflow_dont, /* complain_on_overflow */ | |
1413 | bfd_elf_generic_reloc, /* special_function */ | |
1414 | AARCH64_R_STR (TLSGD_MOVW_G0_NC), /* name */ | |
1415 | FALSE, /* partial_inplace */ | |
1416 | 0xffff, /* src_mask */ | |
1417 | 0xffff, /* dst_mask */ | |
1418 | FALSE), /* pcrel_offset */ | |
1419 | ||
1aa66fb1 RL |
1420 | /* Higher 16 bits of GOT offset to tls_index. */ |
1421 | HOWTO64 (AARCH64_R (TLSGD_MOVW_G1), /* type */ | |
1422 | 16, /* rightshift */ | |
1423 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1424 | 16, /* bitsize */ | |
1425 | FALSE, /* pc_relative */ | |
1426 | 0, /* bitpos */ | |
1427 | complain_overflow_unsigned, /* complain_on_overflow */ | |
1428 | bfd_elf_generic_reloc, /* special_function */ | |
1429 | AARCH64_R_STR (TLSGD_MOVW_G1), /* name */ | |
1430 | FALSE, /* partial_inplace */ | |
1431 | 0xffff, /* src_mask */ | |
1432 | 0xffff, /* dst_mask */ | |
1433 | FALSE), /* pcrel_offset */ | |
1434 | ||
a6bb11b2 | 1435 | HOWTO (AARCH64_R (TLSIE_ADR_GOTTPREL_PAGE21), /* type */ |
a06ea964 NC |
1436 | 12, /* rightshift */ |
1437 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1438 | 21, /* bitsize */ | |
1439 | FALSE, /* pc_relative */ | |
1440 | 0, /* bitpos */ | |
1441 | complain_overflow_dont, /* complain_on_overflow */ | |
1442 | bfd_elf_generic_reloc, /* special_function */ | |
a6bb11b2 | 1443 | AARCH64_R_STR (TLSIE_ADR_GOTTPREL_PAGE21), /* name */ |
a06ea964 NC |
1444 | FALSE, /* partial_inplace */ |
1445 | 0x1fffff, /* src_mask */ | |
1446 | 0x1fffff, /* dst_mask */ | |
1447 | FALSE), /* pcrel_offset */ | |
1448 | ||
a6bb11b2 | 1449 | HOWTO64 (AARCH64_R (TLSIE_LD64_GOTTPREL_LO12_NC), /* type */ |
a06ea964 NC |
1450 | 3, /* rightshift */ |
1451 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1452 | 12, /* bitsize */ | |
1453 | FALSE, /* pc_relative */ | |
1454 | 0, /* bitpos */ | |
1455 | complain_overflow_dont, /* complain_on_overflow */ | |
1456 | bfd_elf_generic_reloc, /* special_function */ | |
a6bb11b2 | 1457 | AARCH64_R_STR (TLSIE_LD64_GOTTPREL_LO12_NC), /* name */ |
a06ea964 NC |
1458 | FALSE, /* partial_inplace */ |
1459 | 0xff8, /* src_mask */ | |
1460 | 0xff8, /* dst_mask */ | |
1461 | FALSE), /* pcrel_offset */ | |
1462 | ||
a6bb11b2 YZ |
1463 | HOWTO32 (AARCH64_R (TLSIE_LD32_GOTTPREL_LO12_NC), /* type */ |
1464 | 2, /* rightshift */ | |
1465 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1466 | 12, /* bitsize */ | |
1467 | FALSE, /* pc_relative */ | |
1468 | 0, /* bitpos */ | |
1469 | complain_overflow_dont, /* complain_on_overflow */ | |
1470 | bfd_elf_generic_reloc, /* special_function */ | |
1471 | AARCH64_R_STR (TLSIE_LD32_GOTTPREL_LO12_NC), /* name */ | |
1472 | FALSE, /* partial_inplace */ | |
1473 | 0xffc, /* src_mask */ | |
1474 | 0xffc, /* dst_mask */ | |
1475 | FALSE), /* pcrel_offset */ | |
1476 | ||
1477 | HOWTO (AARCH64_R (TLSIE_LD_GOTTPREL_PREL19), /* type */ | |
bb3f9ed8 | 1478 | 2, /* rightshift */ |
a06ea964 | 1479 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
043bf05a | 1480 | 19, /* bitsize */ |
a06ea964 NC |
1481 | FALSE, /* pc_relative */ |
1482 | 0, /* bitpos */ | |
1483 | complain_overflow_dont, /* complain_on_overflow */ | |
1484 | bfd_elf_generic_reloc, /* special_function */ | |
a6bb11b2 | 1485 | AARCH64_R_STR (TLSIE_LD_GOTTPREL_PREL19), /* name */ |
a06ea964 NC |
1486 | FALSE, /* partial_inplace */ |
1487 | 0x1ffffc, /* src_mask */ | |
1488 | 0x1ffffc, /* dst_mask */ | |
1489 | FALSE), /* pcrel_offset */ | |
1490 | ||
3b957e5b RL |
1491 | HOWTO64 (AARCH64_R (TLSIE_MOVW_GOTTPREL_G0_NC), /* type */ |
1492 | 0, /* rightshift */ | |
1493 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1494 | 16, /* bitsize */ | |
1495 | FALSE, /* pc_relative */ | |
1496 | 0, /* bitpos */ | |
1497 | complain_overflow_dont, /* complain_on_overflow */ | |
1498 | bfd_elf_generic_reloc, /* special_function */ | |
1499 | AARCH64_R_STR (TLSIE_MOVW_GOTTPREL_G0_NC), /* name */ | |
1500 | FALSE, /* partial_inplace */ | |
1501 | 0xffff, /* src_mask */ | |
1502 | 0xffff, /* dst_mask */ | |
1503 | FALSE), /* pcrel_offset */ | |
1504 | ||
1505 | HOWTO64 (AARCH64_R (TLSIE_MOVW_GOTTPREL_G1), /* type */ | |
1506 | 16, /* rightshift */ | |
1507 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1508 | 16, /* bitsize */ | |
1509 | FALSE, /* pc_relative */ | |
1510 | 0, /* bitpos */ | |
1511 | complain_overflow_unsigned, /* complain_on_overflow */ | |
1512 | bfd_elf_generic_reloc, /* special_function */ | |
1513 | AARCH64_R_STR (TLSIE_MOVW_GOTTPREL_G1), /* name */ | |
1514 | FALSE, /* partial_inplace */ | |
1515 | 0xffff, /* src_mask */ | |
1516 | 0xffff, /* dst_mask */ | |
1517 | FALSE), /* pcrel_offset */ | |
1518 | ||
49df5539 JW |
1519 | /* ADD: bit[23:12] of byte offset to module TLS base address. */ |
1520 | HOWTO (AARCH64_R (TLSLD_ADD_DTPREL_HI12), /* type */ | |
1521 | 12, /* rightshift */ | |
1522 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1523 | 12, /* bitsize */ | |
1524 | FALSE, /* pc_relative */ | |
1525 | 0, /* bitpos */ | |
1526 | complain_overflow_unsigned, /* complain_on_overflow */ | |
1527 | bfd_elf_generic_reloc, /* special_function */ | |
1528 | AARCH64_R_STR (TLSLD_ADD_DTPREL_HI12), /* name */ | |
1529 | FALSE, /* partial_inplace */ | |
1530 | 0xfff, /* src_mask */ | |
1531 | 0xfff, /* dst_mask */ | |
1532 | FALSE), /* pcrel_offset */ | |
1533 | ||
70151fb5 JW |
1534 | /* Unsigned 12 bit byte offset to module TLS base address. */ |
1535 | HOWTO (AARCH64_R (TLSLD_ADD_DTPREL_LO12), /* type */ | |
1536 | 0, /* rightshift */ | |
1537 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1538 | 12, /* bitsize */ | |
1539 | FALSE, /* pc_relative */ | |
1540 | 0, /* bitpos */ | |
1541 | complain_overflow_unsigned, /* complain_on_overflow */ | |
1542 | bfd_elf_generic_reloc, /* special_function */ | |
1543 | AARCH64_R_STR (TLSLD_ADD_DTPREL_LO12), /* name */ | |
1544 | FALSE, /* partial_inplace */ | |
1545 | 0xfff, /* src_mask */ | |
1546 | 0xfff, /* dst_mask */ | |
1547 | FALSE), /* pcrel_offset */ | |
13289c10 JW |
1548 | |
1549 | /* No overflow check version of BFD_RELOC_AARCH64_TLSLD_ADD_DTPREL_LO12. */ | |
1550 | HOWTO (AARCH64_R (TLSLD_ADD_DTPREL_LO12_NC), /* type */ | |
1551 | 0, /* rightshift */ | |
1552 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1553 | 12, /* bitsize */ | |
1554 | FALSE, /* pc_relative */ | |
1555 | 0, /* bitpos */ | |
1556 | complain_overflow_dont, /* complain_on_overflow */ | |
1557 | bfd_elf_generic_reloc, /* special_function */ | |
1558 | AARCH64_R_STR (TLSLD_ADD_DTPREL_LO12_NC), /* name */ | |
1559 | FALSE, /* partial_inplace */ | |
1560 | 0xfff, /* src_mask */ | |
1561 | 0xfff, /* dst_mask */ | |
1562 | FALSE), /* pcrel_offset */ | |
70151fb5 | 1563 | |
a12fad50 JW |
1564 | /* ADD: GOT offset G(S) & 0xff8 [no overflow check] */ |
1565 | HOWTO (AARCH64_R (TLSLD_ADD_LO12_NC), /* type */ | |
1566 | 0, /* rightshift */ | |
1567 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1568 | 12, /* bitsize */ | |
1569 | FALSE, /* pc_relative */ | |
1570 | 0, /* bitpos */ | |
1571 | complain_overflow_dont, /* complain_on_overflow */ | |
1572 | bfd_elf_generic_reloc, /* special_function */ | |
1573 | AARCH64_R_STR (TLSLD_ADD_LO12_NC), /* name */ | |
1574 | FALSE, /* partial_inplace */ | |
1575 | 0xfff, /* src_mask */ | |
1576 | 0xfff, /* dst_mask */ | |
1577 | FALSE), /* pcrel_offset */ | |
1578 | ||
1107e076 JW |
1579 | /* Get to the page for the GOT entry for the symbol |
1580 | (G(S) - P) using an ADRP instruction. */ | |
1581 | HOWTO (AARCH64_R (TLSLD_ADR_PAGE21), /* type */ | |
1582 | 12, /* rightshift */ | |
1583 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1584 | 21, /* bitsize */ | |
1585 | TRUE, /* pc_relative */ | |
1586 | 0, /* bitpos */ | |
1587 | complain_overflow_signed, /* complain_on_overflow */ | |
1588 | bfd_elf_generic_reloc, /* special_function */ | |
1589 | AARCH64_R_STR (TLSLD_ADR_PAGE21), /* name */ | |
1590 | FALSE, /* partial_inplace */ | |
1591 | 0x1fffff, /* src_mask */ | |
1592 | 0x1fffff, /* dst_mask */ | |
1593 | TRUE), /* pcrel_offset */ | |
1594 | ||
6c37fedc JW |
1595 | HOWTO (AARCH64_R (TLSLD_ADR_PREL21), /* type */ |
1596 | 0, /* rightshift */ | |
1597 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1598 | 21, /* bitsize */ | |
1599 | TRUE, /* pc_relative */ | |
1600 | 0, /* bitpos */ | |
1601 | complain_overflow_signed, /* complain_on_overflow */ | |
1602 | bfd_elf_generic_reloc, /* special_function */ | |
1603 | AARCH64_R_STR (TLSLD_ADR_PREL21), /* name */ | |
1604 | FALSE, /* partial_inplace */ | |
1605 | 0x1fffff, /* src_mask */ | |
1606 | 0x1fffff, /* dst_mask */ | |
1607 | TRUE), /* pcrel_offset */ | |
1608 | ||
4c562523 JW |
1609 | /* LD/ST16: bit[11:1] of byte offset to module TLS base address. */ |
1610 | HOWTO64 (AARCH64_R (TLSLD_LDST16_DTPREL_LO12), /* type */ | |
1611 | 1, /* rightshift */ | |
1612 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1613 | 11, /* bitsize */ | |
1614 | FALSE, /* pc_relative */ | |
1615 | 10, /* bitpos */ | |
1616 | complain_overflow_unsigned, /* complain_on_overflow */ | |
1617 | bfd_elf_generic_reloc, /* special_function */ | |
1618 | AARCH64_R_STR (TLSLD_LDST16_DTPREL_LO12), /* name */ | |
1619 | FALSE, /* partial_inplace */ | |
1620 | 0x1ffc00, /* src_mask */ | |
1621 | 0x1ffc00, /* dst_mask */ | |
1622 | FALSE), /* pcrel_offset */ | |
1623 | ||
1624 | /* Same as BFD_RELOC_AARCH64_TLSLD_LDST16_DTPREL_LO12, but no overflow check. */ | |
1625 | HOWTO64 (AARCH64_R (TLSLD_LDST16_DTPREL_LO12_NC), /* type */ | |
1626 | 1, /* rightshift */ | |
1627 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1628 | 11, /* bitsize */ | |
1629 | FALSE, /* pc_relative */ | |
1630 | 10, /* bitpos */ | |
1631 | complain_overflow_dont, /* complain_on_overflow */ | |
1632 | bfd_elf_generic_reloc, /* special_function */ | |
1633 | AARCH64_R_STR (TLSLD_LDST16_DTPREL_LO12_NC), /* name */ | |
1634 | FALSE, /* partial_inplace */ | |
1635 | 0x1ffc00, /* src_mask */ | |
1636 | 0x1ffc00, /* dst_mask */ | |
1637 | FALSE), /* pcrel_offset */ | |
1638 | ||
1639 | /* LD/ST32: bit[11:2] of byte offset to module TLS base address. */ | |
1640 | HOWTO64 (AARCH64_R (TLSLD_LDST32_DTPREL_LO12), /* type */ | |
1641 | 2, /* rightshift */ | |
1642 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1643 | 10, /* bitsize */ | |
1644 | FALSE, /* pc_relative */ | |
1645 | 10, /* bitpos */ | |
1646 | complain_overflow_unsigned, /* complain_on_overflow */ | |
1647 | bfd_elf_generic_reloc, /* special_function */ | |
1648 | AARCH64_R_STR (TLSLD_LDST32_DTPREL_LO12), /* name */ | |
1649 | FALSE, /* partial_inplace */ | |
1650 | 0x3ffc00, /* src_mask */ | |
1651 | 0x3ffc00, /* dst_mask */ | |
1652 | FALSE), /* pcrel_offset */ | |
1653 | ||
1654 | /* Same as BFD_RELOC_AARCH64_TLSLD_LDST32_DTPREL_LO12, but no overflow check. */ | |
1655 | HOWTO64 (AARCH64_R (TLSLD_LDST32_DTPREL_LO12_NC), /* type */ | |
1656 | 2, /* rightshift */ | |
1657 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1658 | 10, /* bitsize */ | |
1659 | FALSE, /* pc_relative */ | |
1660 | 10, /* bitpos */ | |
1661 | complain_overflow_dont, /* complain_on_overflow */ | |
1662 | bfd_elf_generic_reloc, /* special_function */ | |
1663 | AARCH64_R_STR (TLSLD_LDST32_DTPREL_LO12_NC), /* name */ | |
1664 | FALSE, /* partial_inplace */ | |
1665 | 0xffc00, /* src_mask */ | |
1666 | 0xffc00, /* dst_mask */ | |
1667 | FALSE), /* pcrel_offset */ | |
1668 | ||
1669 | /* LD/ST64: bit[11:3] of byte offset to module TLS base address. */ | |
1670 | HOWTO64 (AARCH64_R (TLSLD_LDST64_DTPREL_LO12), /* type */ | |
1671 | 3, /* rightshift */ | |
1672 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1673 | 9, /* bitsize */ | |
1674 | FALSE, /* pc_relative */ | |
1675 | 10, /* bitpos */ | |
1676 | complain_overflow_unsigned, /* complain_on_overflow */ | |
1677 | bfd_elf_generic_reloc, /* special_function */ | |
1678 | AARCH64_R_STR (TLSLD_LDST64_DTPREL_LO12), /* name */ | |
1679 | FALSE, /* partial_inplace */ | |
1680 | 0x3ffc00, /* src_mask */ | |
1681 | 0x3ffc00, /* dst_mask */ | |
1682 | FALSE), /* pcrel_offset */ | |
1683 | ||
1684 | /* Same as BFD_RELOC_AARCH64_TLSLD_LDST64_DTPREL_LO12, but no overflow check. */ | |
1685 | HOWTO64 (AARCH64_R (TLSLD_LDST64_DTPREL_LO12_NC), /* type */ | |
1686 | 3, /* rightshift */ | |
1687 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1688 | 9, /* bitsize */ | |
1689 | FALSE, /* pc_relative */ | |
1690 | 10, /* bitpos */ | |
1691 | complain_overflow_dont, /* complain_on_overflow */ | |
1692 | bfd_elf_generic_reloc, /* special_function */ | |
1693 | AARCH64_R_STR (TLSLD_LDST64_DTPREL_LO12_NC), /* name */ | |
1694 | FALSE, /* partial_inplace */ | |
1695 | 0x7fc00, /* src_mask */ | |
1696 | 0x7fc00, /* dst_mask */ | |
1697 | FALSE), /* pcrel_offset */ | |
1698 | ||
1699 | /* LD/ST8: bit[11:0] of byte offset to module TLS base address. */ | |
1700 | HOWTO64 (AARCH64_R (TLSLD_LDST8_DTPREL_LO12), /* type */ | |
1701 | 0, /* rightshift */ | |
1702 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1703 | 12, /* bitsize */ | |
1704 | FALSE, /* pc_relative */ | |
1705 | 10, /* bitpos */ | |
1706 | complain_overflow_unsigned, /* complain_on_overflow */ | |
1707 | bfd_elf_generic_reloc, /* special_function */ | |
1708 | AARCH64_R_STR (TLSLD_LDST8_DTPREL_LO12), /* name */ | |
1709 | FALSE, /* partial_inplace */ | |
1710 | 0x3ffc00, /* src_mask */ | |
1711 | 0x3ffc00, /* dst_mask */ | |
1712 | FALSE), /* pcrel_offset */ | |
1713 | ||
1714 | /* Same as BFD_RELOC_AARCH64_TLSLD_LDST8_DTPREL_LO12, but no overflow check. */ | |
1715 | HOWTO64 (AARCH64_R (TLSLD_LDST8_DTPREL_LO12_NC), /* type */ | |
1716 | 0, /* rightshift */ | |
1717 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1718 | 12, /* bitsize */ | |
1719 | FALSE, /* pc_relative */ | |
1720 | 10, /* bitpos */ | |
1721 | complain_overflow_dont, /* complain_on_overflow */ | |
1722 | bfd_elf_generic_reloc, /* special_function */ | |
1723 | AARCH64_R_STR (TLSLD_LDST8_DTPREL_LO12_NC), /* name */ | |
1724 | FALSE, /* partial_inplace */ | |
1725 | 0x3ffc00, /* src_mask */ | |
1726 | 0x3ffc00, /* dst_mask */ | |
1727 | FALSE), /* pcrel_offset */ | |
1728 | ||
49df5539 JW |
1729 | /* MOVZ: bit[15:0] of byte offset to module TLS base address. */ |
1730 | HOWTO (AARCH64_R (TLSLD_MOVW_DTPREL_G0), /* type */ | |
1731 | 0, /* rightshift */ | |
1732 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1733 | 16, /* bitsize */ | |
1734 | FALSE, /* pc_relative */ | |
1735 | 0, /* bitpos */ | |
1736 | complain_overflow_unsigned, /* complain_on_overflow */ | |
1737 | bfd_elf_generic_reloc, /* special_function */ | |
1738 | AARCH64_R_STR (TLSLD_MOVW_DTPREL_G0), /* name */ | |
1739 | FALSE, /* partial_inplace */ | |
1740 | 0xffff, /* src_mask */ | |
1741 | 0xffff, /* dst_mask */ | |
1742 | FALSE), /* pcrel_offset */ | |
1743 | ||
1744 | /* No overflow check version of BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G0. */ | |
1745 | HOWTO (AARCH64_R (TLSLD_MOVW_DTPREL_G0_NC), /* type */ | |
1746 | 0, /* rightshift */ | |
1747 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1748 | 16, /* bitsize */ | |
1749 | FALSE, /* pc_relative */ | |
1750 | 0, /* bitpos */ | |
1751 | complain_overflow_dont, /* complain_on_overflow */ | |
1752 | bfd_elf_generic_reloc, /* special_function */ | |
1753 | AARCH64_R_STR (TLSLD_MOVW_DTPREL_G0_NC), /* name */ | |
1754 | FALSE, /* partial_inplace */ | |
1755 | 0xffff, /* src_mask */ | |
1756 | 0xffff, /* dst_mask */ | |
1757 | FALSE), /* pcrel_offset */ | |
1758 | ||
1759 | /* MOVZ: bit[31:16] of byte offset to module TLS base address. */ | |
1760 | HOWTO (AARCH64_R (TLSLD_MOVW_DTPREL_G1), /* type */ | |
1761 | 16, /* rightshift */ | |
1762 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1763 | 16, /* bitsize */ | |
1764 | FALSE, /* pc_relative */ | |
1765 | 0, /* bitpos */ | |
1766 | complain_overflow_unsigned, /* complain_on_overflow */ | |
1767 | bfd_elf_generic_reloc, /* special_function */ | |
1768 | AARCH64_R_STR (TLSLD_MOVW_DTPREL_G1), /* name */ | |
1769 | FALSE, /* partial_inplace */ | |
1770 | 0xffff, /* src_mask */ | |
1771 | 0xffff, /* dst_mask */ | |
1772 | FALSE), /* pcrel_offset */ | |
1773 | ||
1774 | /* No overflow check version of BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G1. */ | |
1775 | HOWTO64 (AARCH64_R (TLSLD_MOVW_DTPREL_G1_NC), /* type */ | |
1776 | 16, /* rightshift */ | |
1777 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1778 | 16, /* bitsize */ | |
1779 | FALSE, /* pc_relative */ | |
1780 | 0, /* bitpos */ | |
1781 | complain_overflow_dont, /* complain_on_overflow */ | |
1782 | bfd_elf_generic_reloc, /* special_function */ | |
1783 | AARCH64_R_STR (TLSLD_MOVW_DTPREL_G1_NC), /* name */ | |
1784 | FALSE, /* partial_inplace */ | |
1785 | 0xffff, /* src_mask */ | |
1786 | 0xffff, /* dst_mask */ | |
1787 | FALSE), /* pcrel_offset */ | |
1788 | ||
1789 | /* MOVZ: bit[47:32] of byte offset to module TLS base address. */ | |
1790 | HOWTO64 (AARCH64_R (TLSLD_MOVW_DTPREL_G2), /* type */ | |
1791 | 32, /* rightshift */ | |
1792 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1793 | 16, /* bitsize */ | |
1794 | FALSE, /* pc_relative */ | |
1795 | 0, /* bitpos */ | |
1796 | complain_overflow_unsigned, /* complain_on_overflow */ | |
1797 | bfd_elf_generic_reloc, /* special_function */ | |
1798 | AARCH64_R_STR (TLSLD_MOVW_DTPREL_G2), /* name */ | |
1799 | FALSE, /* partial_inplace */ | |
1800 | 0xffff, /* src_mask */ | |
1801 | 0xffff, /* dst_mask */ | |
1802 | FALSE), /* pcrel_offset */ | |
1803 | ||
a6bb11b2 | 1804 | HOWTO64 (AARCH64_R (TLSLE_MOVW_TPREL_G2), /* type */ |
bb3f9ed8 | 1805 | 32, /* rightshift */ |
a06ea964 | 1806 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
07875fbc | 1807 | 16, /* bitsize */ |
a06ea964 NC |
1808 | FALSE, /* pc_relative */ |
1809 | 0, /* bitpos */ | |
0172429c | 1810 | complain_overflow_unsigned, /* complain_on_overflow */ |
a06ea964 | 1811 | bfd_elf_generic_reloc, /* special_function */ |
a6bb11b2 | 1812 | AARCH64_R_STR (TLSLE_MOVW_TPREL_G2), /* name */ |
a06ea964 NC |
1813 | FALSE, /* partial_inplace */ |
1814 | 0xffff, /* src_mask */ | |
1815 | 0xffff, /* dst_mask */ | |
1816 | FALSE), /* pcrel_offset */ | |
1817 | ||
a6bb11b2 | 1818 | HOWTO (AARCH64_R (TLSLE_MOVW_TPREL_G1), /* type */ |
bb3f9ed8 | 1819 | 16, /* rightshift */ |
a06ea964 | 1820 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
07875fbc | 1821 | 16, /* bitsize */ |
a06ea964 NC |
1822 | FALSE, /* pc_relative */ |
1823 | 0, /* bitpos */ | |
1824 | complain_overflow_dont, /* complain_on_overflow */ | |
1825 | bfd_elf_generic_reloc, /* special_function */ | |
a6bb11b2 | 1826 | AARCH64_R_STR (TLSLE_MOVW_TPREL_G1), /* name */ |
a06ea964 NC |
1827 | FALSE, /* partial_inplace */ |
1828 | 0xffff, /* src_mask */ | |
1829 | 0xffff, /* dst_mask */ | |
1830 | FALSE), /* pcrel_offset */ | |
1831 | ||
a6bb11b2 | 1832 | HOWTO64 (AARCH64_R (TLSLE_MOVW_TPREL_G1_NC), /* type */ |
bb3f9ed8 | 1833 | 16, /* rightshift */ |
a06ea964 | 1834 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
07875fbc | 1835 | 16, /* bitsize */ |
a06ea964 NC |
1836 | FALSE, /* pc_relative */ |
1837 | 0, /* bitpos */ | |
1838 | complain_overflow_dont, /* complain_on_overflow */ | |
1839 | bfd_elf_generic_reloc, /* special_function */ | |
a6bb11b2 | 1840 | AARCH64_R_STR (TLSLE_MOVW_TPREL_G1_NC), /* name */ |
a06ea964 NC |
1841 | FALSE, /* partial_inplace */ |
1842 | 0xffff, /* src_mask */ | |
1843 | 0xffff, /* dst_mask */ | |
1844 | FALSE), /* pcrel_offset */ | |
1845 | ||
a6bb11b2 | 1846 | HOWTO (AARCH64_R (TLSLE_MOVW_TPREL_G0), /* type */ |
a06ea964 NC |
1847 | 0, /* rightshift */ |
1848 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
07875fbc | 1849 | 16, /* bitsize */ |
a06ea964 NC |
1850 | FALSE, /* pc_relative */ |
1851 | 0, /* bitpos */ | |
1852 | complain_overflow_dont, /* complain_on_overflow */ | |
1853 | bfd_elf_generic_reloc, /* special_function */ | |
a6bb11b2 | 1854 | AARCH64_R_STR (TLSLE_MOVW_TPREL_G0), /* name */ |
a06ea964 NC |
1855 | FALSE, /* partial_inplace */ |
1856 | 0xffff, /* src_mask */ | |
1857 | 0xffff, /* dst_mask */ | |
1858 | FALSE), /* pcrel_offset */ | |
1859 | ||
a6bb11b2 | 1860 | HOWTO (AARCH64_R (TLSLE_MOVW_TPREL_G0_NC), /* type */ |
a06ea964 NC |
1861 | 0, /* rightshift */ |
1862 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
07875fbc | 1863 | 16, /* bitsize */ |
a06ea964 NC |
1864 | FALSE, /* pc_relative */ |
1865 | 0, /* bitpos */ | |
1866 | complain_overflow_dont, /* complain_on_overflow */ | |
1867 | bfd_elf_generic_reloc, /* special_function */ | |
a6bb11b2 | 1868 | AARCH64_R_STR (TLSLE_MOVW_TPREL_G0_NC), /* name */ |
a06ea964 NC |
1869 | FALSE, /* partial_inplace */ |
1870 | 0xffff, /* src_mask */ | |
1871 | 0xffff, /* dst_mask */ | |
1872 | FALSE), /* pcrel_offset */ | |
1873 | ||
a6bb11b2 | 1874 | HOWTO (AARCH64_R (TLSLE_ADD_TPREL_HI12), /* type */ |
bb3f9ed8 | 1875 | 12, /* rightshift */ |
a06ea964 NC |
1876 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
1877 | 12, /* bitsize */ | |
1878 | FALSE, /* pc_relative */ | |
1879 | 0, /* bitpos */ | |
bab91cce | 1880 | complain_overflow_unsigned, /* complain_on_overflow */ |
a06ea964 | 1881 | bfd_elf_generic_reloc, /* special_function */ |
a6bb11b2 | 1882 | AARCH64_R_STR (TLSLE_ADD_TPREL_HI12), /* name */ |
a06ea964 NC |
1883 | FALSE, /* partial_inplace */ |
1884 | 0xfff, /* src_mask */ | |
1885 | 0xfff, /* dst_mask */ | |
1886 | FALSE), /* pcrel_offset */ | |
1887 | ||
a6bb11b2 | 1888 | HOWTO (AARCH64_R (TLSLE_ADD_TPREL_LO12), /* type */ |
a06ea964 NC |
1889 | 0, /* rightshift */ |
1890 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1891 | 12, /* bitsize */ | |
1892 | FALSE, /* pc_relative */ | |
1893 | 0, /* bitpos */ | |
36e6c140 | 1894 | complain_overflow_unsigned, /* complain_on_overflow */ |
a06ea964 | 1895 | bfd_elf_generic_reloc, /* special_function */ |
a6bb11b2 | 1896 | AARCH64_R_STR (TLSLE_ADD_TPREL_LO12), /* name */ |
a06ea964 NC |
1897 | FALSE, /* partial_inplace */ |
1898 | 0xfff, /* src_mask */ | |
1899 | 0xfff, /* dst_mask */ | |
1900 | FALSE), /* pcrel_offset */ | |
1901 | ||
a6bb11b2 | 1902 | HOWTO (AARCH64_R (TLSLE_ADD_TPREL_LO12_NC), /* type */ |
a06ea964 NC |
1903 | 0, /* rightshift */ |
1904 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1905 | 12, /* bitsize */ | |
1906 | FALSE, /* pc_relative */ | |
1907 | 0, /* bitpos */ | |
1908 | complain_overflow_dont, /* complain_on_overflow */ | |
1909 | bfd_elf_generic_reloc, /* special_function */ | |
a6bb11b2 | 1910 | AARCH64_R_STR (TLSLE_ADD_TPREL_LO12_NC), /* name */ |
a06ea964 NC |
1911 | FALSE, /* partial_inplace */ |
1912 | 0xfff, /* src_mask */ | |
1913 | 0xfff, /* dst_mask */ | |
1914 | FALSE), /* pcrel_offset */ | |
a06ea964 | 1915 | |
84f1b9fb RL |
1916 | /* LD/ST16: bit[11:1] of byte offset to module TLS base address. */ |
1917 | HOWTO (AARCH64_R (TLSLE_LDST16_TPREL_LO12), /* type */ | |
1918 | 1, /* rightshift */ | |
1919 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1920 | 11, /* bitsize */ | |
1921 | FALSE, /* pc_relative */ | |
1922 | 10, /* bitpos */ | |
1923 | complain_overflow_unsigned, /* complain_on_overflow */ | |
1924 | bfd_elf_generic_reloc, /* special_function */ | |
1925 | AARCH64_R_STR (TLSLE_LDST16_TPREL_LO12), /* name */ | |
1926 | FALSE, /* partial_inplace */ | |
1927 | 0x1ffc00, /* src_mask */ | |
1928 | 0x1ffc00, /* dst_mask */ | |
1929 | FALSE), /* pcrel_offset */ | |
1930 | ||
1931 | /* Same as BFD_RELOC_AARCH64_TLSLE_LDST16_TPREL_LO12, but no overflow check. */ | |
1932 | HOWTO (AARCH64_R (TLSLE_LDST16_TPREL_LO12_NC), /* type */ | |
1933 | 1, /* rightshift */ | |
1934 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1935 | 11, /* bitsize */ | |
1936 | FALSE, /* pc_relative */ | |
1937 | 10, /* bitpos */ | |
1938 | complain_overflow_dont, /* complain_on_overflow */ | |
1939 | bfd_elf_generic_reloc, /* special_function */ | |
1940 | AARCH64_R_STR (TLSLE_LDST16_TPREL_LO12_NC), /* name */ | |
1941 | FALSE, /* partial_inplace */ | |
1942 | 0x1ffc00, /* src_mask */ | |
1943 | 0x1ffc00, /* dst_mask */ | |
1944 | FALSE), /* pcrel_offset */ | |
1945 | ||
1946 | /* LD/ST32: bit[11:2] of byte offset to module TLS base address. */ | |
1947 | HOWTO (AARCH64_R (TLSLE_LDST32_TPREL_LO12), /* type */ | |
1948 | 2, /* rightshift */ | |
1949 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1950 | 10, /* bitsize */ | |
1951 | FALSE, /* pc_relative */ | |
1952 | 10, /* bitpos */ | |
1953 | complain_overflow_unsigned, /* complain_on_overflow */ | |
1954 | bfd_elf_generic_reloc, /* special_function */ | |
1955 | AARCH64_R_STR (TLSLE_LDST32_TPREL_LO12), /* name */ | |
1956 | FALSE, /* partial_inplace */ | |
1957 | 0xffc00, /* src_mask */ | |
1958 | 0xffc00, /* dst_mask */ | |
1959 | FALSE), /* pcrel_offset */ | |
1960 | ||
1961 | /* Same as BFD_RELOC_AARCH64_TLSLE_LDST32_TPREL_LO12, but no overflow check. */ | |
1962 | HOWTO (AARCH64_R (TLSLE_LDST32_TPREL_LO12_NC), /* type */ | |
1963 | 2, /* rightshift */ | |
1964 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1965 | 10, /* bitsize */ | |
1966 | FALSE, /* pc_relative */ | |
1967 | 10, /* bitpos */ | |
1968 | complain_overflow_dont, /* complain_on_overflow */ | |
1969 | bfd_elf_generic_reloc, /* special_function */ | |
1970 | AARCH64_R_STR (TLSLE_LDST32_TPREL_LO12_NC), /* name */ | |
1971 | FALSE, /* partial_inplace */ | |
1972 | 0xffc00, /* src_mask */ | |
1973 | 0xffc00, /* dst_mask */ | |
1974 | FALSE), /* pcrel_offset */ | |
1975 | ||
1976 | /* LD/ST64: bit[11:3] of byte offset to module TLS base address. */ | |
1977 | HOWTO (AARCH64_R (TLSLE_LDST64_TPREL_LO12), /* type */ | |
1978 | 3, /* rightshift */ | |
1979 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1980 | 9, /* bitsize */ | |
1981 | FALSE, /* pc_relative */ | |
1982 | 10, /* bitpos */ | |
1983 | complain_overflow_unsigned, /* complain_on_overflow */ | |
1984 | bfd_elf_generic_reloc, /* special_function */ | |
1985 | AARCH64_R_STR (TLSLE_LDST64_TPREL_LO12), /* name */ | |
1986 | FALSE, /* partial_inplace */ | |
1987 | 0x7fc00, /* src_mask */ | |
1988 | 0x7fc00, /* dst_mask */ | |
1989 | FALSE), /* pcrel_offset */ | |
1990 | ||
1991 | /* Same as BFD_RELOC_AARCH64_TLSLE_LDST64_TPREL_LO12, but no overflow check. */ | |
1992 | HOWTO (AARCH64_R (TLSLE_LDST64_TPREL_LO12_NC), /* type */ | |
1993 | 3, /* rightshift */ | |
1994 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1995 | 9, /* bitsize */ | |
1996 | FALSE, /* pc_relative */ | |
1997 | 10, /* bitpos */ | |
1998 | complain_overflow_dont, /* complain_on_overflow */ | |
1999 | bfd_elf_generic_reloc, /* special_function */ | |
2000 | AARCH64_R_STR (TLSLE_LDST64_TPREL_LO12_NC), /* name */ | |
2001 | FALSE, /* partial_inplace */ | |
2002 | 0x7fc00, /* src_mask */ | |
2003 | 0x7fc00, /* dst_mask */ | |
2004 | FALSE), /* pcrel_offset */ | |
2005 | ||
2006 | /* LD/ST8: bit[11:0] of byte offset to module TLS base address. */ | |
2007 | HOWTO (AARCH64_R (TLSLE_LDST8_TPREL_LO12), /* type */ | |
2008 | 0, /* rightshift */ | |
2009 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
2010 | 12, /* bitsize */ | |
2011 | FALSE, /* pc_relative */ | |
2012 | 10, /* bitpos */ | |
2013 | complain_overflow_unsigned, /* complain_on_overflow */ | |
2014 | bfd_elf_generic_reloc, /* special_function */ | |
2015 | AARCH64_R_STR (TLSLE_LDST8_TPREL_LO12), /* name */ | |
2016 | FALSE, /* partial_inplace */ | |
2017 | 0x3ffc00, /* src_mask */ | |
2018 | 0x3ffc00, /* dst_mask */ | |
2019 | FALSE), /* pcrel_offset */ | |
2020 | ||
2021 | /* Same as BFD_RELOC_AARCH64_TLSLE_LDST8_TPREL_LO12, but no overflow check. */ | |
2022 | HOWTO (AARCH64_R (TLSLE_LDST8_TPREL_LO12_NC), /* type */ | |
2023 | 0, /* rightshift */ | |
2024 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
2025 | 12, /* bitsize */ | |
2026 | FALSE, /* pc_relative */ | |
2027 | 10, /* bitpos */ | |
2028 | complain_overflow_dont, /* complain_on_overflow */ | |
2029 | bfd_elf_generic_reloc, /* special_function */ | |
2030 | AARCH64_R_STR (TLSLE_LDST8_TPREL_LO12_NC), /* name */ | |
2031 | FALSE, /* partial_inplace */ | |
2032 | 0x3ffc00, /* src_mask */ | |
2033 | 0x3ffc00, /* dst_mask */ | |
2034 | FALSE), /* pcrel_offset */ | |
2035 | ||
a6bb11b2 | 2036 | HOWTO (AARCH64_R (TLSDESC_LD_PREL19), /* type */ |
bb3f9ed8 | 2037 | 2, /* rightshift */ |
a06ea964 | 2038 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
1ada945d | 2039 | 19, /* bitsize */ |
a06ea964 NC |
2040 | TRUE, /* pc_relative */ |
2041 | 0, /* bitpos */ | |
2042 | complain_overflow_dont, /* complain_on_overflow */ | |
2043 | bfd_elf_generic_reloc, /* special_function */ | |
a6bb11b2 | 2044 | AARCH64_R_STR (TLSDESC_LD_PREL19), /* name */ |
a06ea964 | 2045 | FALSE, /* partial_inplace */ |
1ada945d MS |
2046 | 0x0ffffe0, /* src_mask */ |
2047 | 0x0ffffe0, /* dst_mask */ | |
a06ea964 NC |
2048 | TRUE), /* pcrel_offset */ |
2049 | ||
a6bb11b2 | 2050 | HOWTO (AARCH64_R (TLSDESC_ADR_PREL21), /* type */ |
a06ea964 NC |
2051 | 0, /* rightshift */ |
2052 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
2053 | 21, /* bitsize */ | |
2054 | TRUE, /* pc_relative */ | |
2055 | 0, /* bitpos */ | |
2056 | complain_overflow_dont, /* complain_on_overflow */ | |
2057 | bfd_elf_generic_reloc, /* special_function */ | |
a6bb11b2 | 2058 | AARCH64_R_STR (TLSDESC_ADR_PREL21), /* name */ |
a06ea964 NC |
2059 | FALSE, /* partial_inplace */ |
2060 | 0x1fffff, /* src_mask */ | |
2061 | 0x1fffff, /* dst_mask */ | |
2062 | TRUE), /* pcrel_offset */ | |
2063 | ||
2064 | /* Get to the page for the GOT entry for the symbol | |
2065 | (G(S) - P) using an ADRP instruction. */ | |
a6bb11b2 | 2066 | HOWTO (AARCH64_R (TLSDESC_ADR_PAGE21), /* type */ |
a06ea964 NC |
2067 | 12, /* rightshift */ |
2068 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
2069 | 21, /* bitsize */ | |
2070 | TRUE, /* pc_relative */ | |
2071 | 0, /* bitpos */ | |
2072 | complain_overflow_dont, /* complain_on_overflow */ | |
2073 | bfd_elf_generic_reloc, /* special_function */ | |
a6bb11b2 | 2074 | AARCH64_R_STR (TLSDESC_ADR_PAGE21), /* name */ |
a06ea964 NC |
2075 | FALSE, /* partial_inplace */ |
2076 | 0x1fffff, /* src_mask */ | |
2077 | 0x1fffff, /* dst_mask */ | |
2078 | TRUE), /* pcrel_offset */ | |
2079 | ||
a6bb11b2 | 2080 | /* LD64: GOT offset G(S) & 0xff8. */ |
f955cccf | 2081 | HOWTO64 (AARCH64_R (TLSDESC_LD64_LO12), /* type */ |
a06ea964 NC |
2082 | 3, /* rightshift */ |
2083 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
2084 | 12, /* bitsize */ | |
2085 | FALSE, /* pc_relative */ | |
2086 | 0, /* bitpos */ | |
2087 | complain_overflow_dont, /* complain_on_overflow */ | |
2088 | bfd_elf_generic_reloc, /* special_function */ | |
f955cccf | 2089 | AARCH64_R_STR (TLSDESC_LD64_LO12), /* name */ |
a06ea964 | 2090 | FALSE, /* partial_inplace */ |
a6bb11b2 YZ |
2091 | 0xff8, /* src_mask */ |
2092 | 0xff8, /* dst_mask */ | |
2093 | FALSE), /* pcrel_offset */ | |
2094 | ||
2095 | /* LD32: GOT offset G(S) & 0xffc. */ | |
2096 | HOWTO32 (AARCH64_R (TLSDESC_LD32_LO12_NC), /* type */ | |
2097 | 2, /* rightshift */ | |
2098 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
2099 | 12, /* bitsize */ | |
2100 | FALSE, /* pc_relative */ | |
2101 | 0, /* bitpos */ | |
2102 | complain_overflow_dont, /* complain_on_overflow */ | |
2103 | bfd_elf_generic_reloc, /* special_function */ | |
2104 | AARCH64_R_STR (TLSDESC_LD32_LO12_NC), /* name */ | |
2105 | FALSE, /* partial_inplace */ | |
2106 | 0xffc, /* src_mask */ | |
2107 | 0xffc, /* dst_mask */ | |
a06ea964 NC |
2108 | FALSE), /* pcrel_offset */ |
2109 | ||
2110 | /* ADD: GOT offset G(S) & 0xfff. */ | |
f955cccf | 2111 | HOWTO (AARCH64_R (TLSDESC_ADD_LO12), /* type */ |
a06ea964 NC |
2112 | 0, /* rightshift */ |
2113 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
2114 | 12, /* bitsize */ | |
2115 | FALSE, /* pc_relative */ | |
2116 | 0, /* bitpos */ | |
f955cccf | 2117 | complain_overflow_dont,/* complain_on_overflow */ |
a06ea964 | 2118 | bfd_elf_generic_reloc, /* special_function */ |
f955cccf | 2119 | AARCH64_R_STR (TLSDESC_ADD_LO12), /* name */ |
a06ea964 NC |
2120 | FALSE, /* partial_inplace */ |
2121 | 0xfff, /* src_mask */ | |
2122 | 0xfff, /* dst_mask */ | |
2123 | FALSE), /* pcrel_offset */ | |
2124 | ||
a6bb11b2 | 2125 | HOWTO64 (AARCH64_R (TLSDESC_OFF_G1), /* type */ |
bb3f9ed8 | 2126 | 16, /* rightshift */ |
a06ea964 NC |
2127 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
2128 | 12, /* bitsize */ | |
2129 | FALSE, /* pc_relative */ | |
2130 | 0, /* bitpos */ | |
43a357f9 | 2131 | complain_overflow_unsigned, /* complain_on_overflow */ |
a06ea964 | 2132 | bfd_elf_generic_reloc, /* special_function */ |
a6bb11b2 | 2133 | AARCH64_R_STR (TLSDESC_OFF_G1), /* name */ |
a06ea964 NC |
2134 | FALSE, /* partial_inplace */ |
2135 | 0xffff, /* src_mask */ | |
2136 | 0xffff, /* dst_mask */ | |
2137 | FALSE), /* pcrel_offset */ | |
2138 | ||
a6bb11b2 | 2139 | HOWTO64 (AARCH64_R (TLSDESC_OFF_G0_NC), /* type */ |
a06ea964 NC |
2140 | 0, /* rightshift */ |
2141 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
2142 | 12, /* bitsize */ | |
2143 | FALSE, /* pc_relative */ | |
2144 | 0, /* bitpos */ | |
2145 | complain_overflow_dont, /* complain_on_overflow */ | |
2146 | bfd_elf_generic_reloc, /* special_function */ | |
a6bb11b2 | 2147 | AARCH64_R_STR (TLSDESC_OFF_G0_NC), /* name */ |
a06ea964 NC |
2148 | FALSE, /* partial_inplace */ |
2149 | 0xffff, /* src_mask */ | |
2150 | 0xffff, /* dst_mask */ | |
2151 | FALSE), /* pcrel_offset */ | |
2152 | ||
a6bb11b2 | 2153 | HOWTO64 (AARCH64_R (TLSDESC_LDR), /* type */ |
a06ea964 NC |
2154 | 0, /* rightshift */ |
2155 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
2156 | 12, /* bitsize */ | |
2157 | FALSE, /* pc_relative */ | |
2158 | 0, /* bitpos */ | |
2159 | complain_overflow_dont, /* complain_on_overflow */ | |
2160 | bfd_elf_generic_reloc, /* special_function */ | |
a6bb11b2 | 2161 | AARCH64_R_STR (TLSDESC_LDR), /* name */ |
a06ea964 NC |
2162 | FALSE, /* partial_inplace */ |
2163 | 0x0, /* src_mask */ | |
2164 | 0x0, /* dst_mask */ | |
2165 | FALSE), /* pcrel_offset */ | |
2166 | ||
a6bb11b2 | 2167 | HOWTO64 (AARCH64_R (TLSDESC_ADD), /* type */ |
a06ea964 NC |
2168 | 0, /* rightshift */ |
2169 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
2170 | 12, /* bitsize */ | |
2171 | FALSE, /* pc_relative */ | |
2172 | 0, /* bitpos */ | |
2173 | complain_overflow_dont, /* complain_on_overflow */ | |
2174 | bfd_elf_generic_reloc, /* special_function */ | |
a6bb11b2 | 2175 | AARCH64_R_STR (TLSDESC_ADD), /* name */ |
a06ea964 NC |
2176 | FALSE, /* partial_inplace */ |
2177 | 0x0, /* src_mask */ | |
2178 | 0x0, /* dst_mask */ | |
2179 | FALSE), /* pcrel_offset */ | |
2180 | ||
a6bb11b2 | 2181 | HOWTO (AARCH64_R (TLSDESC_CALL), /* type */ |
a06ea964 NC |
2182 | 0, /* rightshift */ |
2183 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
7366006f | 2184 | 0, /* bitsize */ |
a06ea964 NC |
2185 | FALSE, /* pc_relative */ |
2186 | 0, /* bitpos */ | |
2187 | complain_overflow_dont, /* complain_on_overflow */ | |
2188 | bfd_elf_generic_reloc, /* special_function */ | |
a6bb11b2 | 2189 | AARCH64_R_STR (TLSDESC_CALL), /* name */ |
a06ea964 NC |
2190 | FALSE, /* partial_inplace */ |
2191 | 0x0, /* src_mask */ | |
2192 | 0x0, /* dst_mask */ | |
2193 | FALSE), /* pcrel_offset */ | |
a6bb11b2 | 2194 | |
4ca9b406 SP |
2195 | /* Get to the page for the GOT entry for the symbol |
2196 | (G(S) - P) using an ADRP instruction. */ | |
2197 | HOWTO64 (MORELLO_R (TLSDESC_ADR_PAGE20), /* type */ | |
2198 | 12, /* rightshift */ | |
2199 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
2200 | 20, /* bitsize */ | |
2201 | TRUE, /* pc_relative */ | |
2202 | 0, /* bitpos */ | |
2203 | complain_overflow_dont, /* complain_on_overflow */ | |
2204 | bfd_elf_generic_reloc, /* special_function */ | |
2205 | MORELLO_R_STR (TLSDESC_ADR_PAGE20), /* name */ | |
2206 | FALSE, /* partial_inplace */ | |
2207 | 0xfffff, /* src_mask */ | |
2208 | 0xfffff, /* dst_mask */ | |
2209 | TRUE), /* pcrel_offset */ | |
2210 | ||
2211 | /* LD128: GOT offset G(S) & 0xff0. */ | |
2212 | HOWTO64 (MORELLO_R (TLSDESC_LD128_LO12), /* type */ | |
2213 | 4, /* rightshift */ | |
2214 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
2215 | 12, /* bitsize */ | |
2216 | FALSE, /* pc_relative */ | |
2217 | 0, /* bitpos */ | |
2218 | complain_overflow_dont, /* complain_on_overflow */ | |
2219 | bfd_elf_generic_reloc, /* special_function */ | |
2220 | MORELLO_R_STR (TLSDESC_LD128_LO12), /* name */ | |
2221 | FALSE, /* partial_inplace */ | |
2222 | 0xff0, /* src_mask */ | |
2223 | 0xff0, /* dst_mask */ | |
2224 | FALSE), /* pcrel_offset */ | |
2225 | ||
2226 | HOWTO64 (MORELLO_R (TLSDESC_CALL), /* type */ | |
2227 | 0, /* rightshift */ | |
2228 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
2229 | 0, /* bitsize */ | |
2230 | FALSE, /* pc_relative */ | |
2231 | 0, /* bitpos */ | |
2232 | complain_overflow_dont, /* complain_on_overflow */ | |
2233 | bfd_elf_generic_reloc, /* special_function */ | |
2234 | MORELLO_R_STR (TLSDESC_CALL), /* name */ | |
2235 | FALSE, /* partial_inplace */ | |
2236 | 0x0, /* src_mask */ | |
2237 | 0x0, /* dst_mask */ | |
2238 | FALSE), /* pcrel_offset */ | |
2239 | ||
a6bb11b2 YZ |
2240 | HOWTO (AARCH64_R (COPY), /* type */ |
2241 | 0, /* rightshift */ | |
2242 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
2243 | 64, /* bitsize */ | |
2244 | FALSE, /* pc_relative */ | |
2245 | 0, /* bitpos */ | |
2246 | complain_overflow_bitfield, /* complain_on_overflow */ | |
2247 | bfd_elf_generic_reloc, /* special_function */ | |
2248 | AARCH64_R_STR (COPY), /* name */ | |
2249 | TRUE, /* partial_inplace */ | |
2250 | 0xffffffff, /* src_mask */ | |
2251 | 0xffffffff, /* dst_mask */ | |
2252 | FALSE), /* pcrel_offset */ | |
2253 | ||
2254 | HOWTO (AARCH64_R (GLOB_DAT), /* type */ | |
2255 | 0, /* rightshift */ | |
2256 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
2257 | 64, /* bitsize */ | |
2258 | FALSE, /* pc_relative */ | |
2259 | 0, /* bitpos */ | |
2260 | complain_overflow_bitfield, /* complain_on_overflow */ | |
2261 | bfd_elf_generic_reloc, /* special_function */ | |
2262 | AARCH64_R_STR (GLOB_DAT), /* name */ | |
2263 | TRUE, /* partial_inplace */ | |
2264 | 0xffffffff, /* src_mask */ | |
2265 | 0xffffffff, /* dst_mask */ | |
2266 | FALSE), /* pcrel_offset */ | |
2267 | ||
2268 | HOWTO (AARCH64_R (JUMP_SLOT), /* type */ | |
2269 | 0, /* rightshift */ | |
2270 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
2271 | 64, /* bitsize */ | |
2272 | FALSE, /* pc_relative */ | |
2273 | 0, /* bitpos */ | |
2274 | complain_overflow_bitfield, /* complain_on_overflow */ | |
2275 | bfd_elf_generic_reloc, /* special_function */ | |
2276 | AARCH64_R_STR (JUMP_SLOT), /* name */ | |
2277 | TRUE, /* partial_inplace */ | |
2278 | 0xffffffff, /* src_mask */ | |
2279 | 0xffffffff, /* dst_mask */ | |
2280 | FALSE), /* pcrel_offset */ | |
2281 | ||
2282 | HOWTO (AARCH64_R (RELATIVE), /* type */ | |
2283 | 0, /* rightshift */ | |
2284 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
2285 | 64, /* bitsize */ | |
2286 | FALSE, /* pc_relative */ | |
2287 | 0, /* bitpos */ | |
2288 | complain_overflow_bitfield, /* complain_on_overflow */ | |
2289 | bfd_elf_generic_reloc, /* special_function */ | |
2290 | AARCH64_R_STR (RELATIVE), /* name */ | |
2291 | TRUE, /* partial_inplace */ | |
2292 | ALL_ONES, /* src_mask */ | |
2293 | ALL_ONES, /* dst_mask */ | |
2294 | FALSE), /* pcrel_offset */ | |
2295 | ||
2296 | HOWTO (AARCH64_R (TLS_DTPMOD), /* type */ | |
2297 | 0, /* rightshift */ | |
2298 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
2299 | 64, /* bitsize */ | |
2300 | FALSE, /* pc_relative */ | |
2301 | 0, /* bitpos */ | |
2302 | complain_overflow_dont, /* complain_on_overflow */ | |
2303 | bfd_elf_generic_reloc, /* special_function */ | |
da0781dc YZ |
2304 | #if ARCH_SIZE == 64 |
2305 | AARCH64_R_STR (TLS_DTPMOD64), /* name */ | |
2306 | #else | |
a6bb11b2 | 2307 | AARCH64_R_STR (TLS_DTPMOD), /* name */ |
da0781dc | 2308 | #endif |
a6bb11b2 YZ |
2309 | FALSE, /* partial_inplace */ |
2310 | 0, /* src_mask */ | |
2311 | ALL_ONES, /* dst_mask */ | |
2312 | FALSE), /* pc_reloffset */ | |
2313 | ||
2314 | HOWTO (AARCH64_R (TLS_DTPREL), /* type */ | |
2315 | 0, /* rightshift */ | |
2316 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
2317 | 64, /* bitsize */ | |
2318 | FALSE, /* pc_relative */ | |
2319 | 0, /* bitpos */ | |
2320 | complain_overflow_dont, /* complain_on_overflow */ | |
2321 | bfd_elf_generic_reloc, /* special_function */ | |
da0781dc YZ |
2322 | #if ARCH_SIZE == 64 |
2323 | AARCH64_R_STR (TLS_DTPREL64), /* name */ | |
2324 | #else | |
a6bb11b2 | 2325 | AARCH64_R_STR (TLS_DTPREL), /* name */ |
da0781dc | 2326 | #endif |
a6bb11b2 YZ |
2327 | FALSE, /* partial_inplace */ |
2328 | 0, /* src_mask */ | |
2329 | ALL_ONES, /* dst_mask */ | |
2330 | FALSE), /* pcrel_offset */ | |
2331 | ||
2332 | HOWTO (AARCH64_R (TLS_TPREL), /* type */ | |
2333 | 0, /* rightshift */ | |
2334 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
2335 | 64, /* bitsize */ | |
2336 | FALSE, /* pc_relative */ | |
2337 | 0, /* bitpos */ | |
2338 | complain_overflow_dont, /* complain_on_overflow */ | |
2339 | bfd_elf_generic_reloc, /* special_function */ | |
da0781dc YZ |
2340 | #if ARCH_SIZE == 64 |
2341 | AARCH64_R_STR (TLS_TPREL64), /* name */ | |
2342 | #else | |
a6bb11b2 | 2343 | AARCH64_R_STR (TLS_TPREL), /* name */ |
da0781dc | 2344 | #endif |
a6bb11b2 YZ |
2345 | FALSE, /* partial_inplace */ |
2346 | 0, /* src_mask */ | |
2347 | ALL_ONES, /* dst_mask */ | |
2348 | FALSE), /* pcrel_offset */ | |
2349 | ||
2350 | HOWTO (AARCH64_R (TLSDESC), /* type */ | |
2351 | 0, /* rightshift */ | |
2352 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
2353 | 64, /* bitsize */ | |
2354 | FALSE, /* pc_relative */ | |
2355 | 0, /* bitpos */ | |
2356 | complain_overflow_dont, /* complain_on_overflow */ | |
2357 | bfd_elf_generic_reloc, /* special_function */ | |
2358 | AARCH64_R_STR (TLSDESC), /* name */ | |
2359 | FALSE, /* partial_inplace */ | |
2360 | 0, /* src_mask */ | |
2361 | ALL_ONES, /* dst_mask */ | |
2362 | FALSE), /* pcrel_offset */ | |
2363 | ||
2364 | HOWTO (AARCH64_R (IRELATIVE), /* type */ | |
2365 | 0, /* rightshift */ | |
2366 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
2367 | 64, /* bitsize */ | |
2368 | FALSE, /* pc_relative */ | |
2369 | 0, /* bitpos */ | |
2370 | complain_overflow_bitfield, /* complain_on_overflow */ | |
2371 | bfd_elf_generic_reloc, /* special_function */ | |
2372 | AARCH64_R_STR (IRELATIVE), /* name */ | |
2373 | FALSE, /* partial_inplace */ | |
2374 | 0, /* src_mask */ | |
2375 | ALL_ONES, /* dst_mask */ | |
2376 | FALSE), /* pcrel_offset */ | |
2377 | ||
40bbb79e SP |
2378 | HOWTO64 (MORELLO_R (CAPINIT), /* type */ |
2379 | 0, /* rightshift */ | |
2380 | 4, /* size (0 = byte, 1 = short, 2 = long) */ | |
2381 | 0, /* bitsize */ | |
2382 | FALSE, /* pc_relative */ | |
2383 | 0, /* bitpos */ | |
2384 | complain_overflow_dont, /* complain_on_overflow */ | |
2385 | bfd_elf_generic_reloc, /* special_function */ | |
2386 | MORELLO_R_STR (CAPINIT), /* name */ | |
2387 | FALSE, /* partial_inplace */ | |
2388 | ALL_ONES, /* src_mask */ | |
2389 | ALL_ONES, /* dst_mask */ | |
2390 | FALSE), /* pcrel_offset */ | |
2391 | ||
a1bdea65 SP |
2392 | HOWTO64 (MORELLO_R (GLOB_DAT),/* type */ |
2393 | 0, /* rightshift */ | |
2394 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
2395 | 64, /* bitsize */ | |
2396 | FALSE, /* pc_relative */ | |
2397 | 0, /* bitpos */ | |
2398 | complain_overflow_bitfield, /* complain_on_overflow */ | |
2399 | bfd_elf_generic_reloc, /* special_function */ | |
2400 | MORELLO_R_STR (GLOB_DAT), /* name */ | |
2401 | TRUE, /* partial_inplace */ | |
2402 | 0xffffffff, /* src_mask */ | |
2403 | 0xffffffff, /* dst_mask */ | |
2404 | FALSE), /* pcrel_offset */ | |
2405 | ||
e19e9199 SP |
2406 | HOWTO64 (MORELLO_R (JUMP_SLOT), /* type */ |
2407 | 0, /* rightshift */ | |
2408 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
2409 | 64, /* bitsize */ | |
2410 | FALSE, /* pc_relative */ | |
2411 | 0, /* bitpos */ | |
2412 | complain_overflow_bitfield, /* complain_on_overflow */ | |
2413 | bfd_elf_generic_reloc, /* special_function */ | |
2414 | MORELLO_R_STR (JUMP_SLOT), /* name */ | |
2415 | TRUE, /* partial_inplace */ | |
2416 | 0xffffffff, /* src_mask */ | |
2417 | 0xffffffff, /* dst_mask */ | |
2418 | FALSE), /* pcrel_offset */ | |
2419 | ||
2420 | HOWTO64 (MORELLO_R (RELATIVE), /* type */ | |
40bbb79e SP |
2421 | 0, /* rightshift */ |
2422 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
2423 | 64, /* bitsize */ | |
2424 | FALSE, /* pc_relative */ | |
2425 | 0, /* bitpos */ | |
2426 | complain_overflow_bitfield, /* complain_on_overflow */ | |
2427 | bfd_elf_generic_reloc, /* special_function */ | |
2428 | MORELLO_R_STR (RELATIVE), /* name */ | |
2429 | TRUE, /* partial_inplace */ | |
2430 | ALL_ONES, /* src_mask */ | |
2431 | ALL_ONES, /* dst_mask */ | |
2432 | FALSE), /* pcrel_offset */ | |
2433 | ||
e19e9199 SP |
2434 | HOWTO64 (MORELLO_R (IRELATIVE), /* type */ |
2435 | 0, /* rightshift */ | |
2436 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
2437 | 64, /* bitsize */ | |
2438 | FALSE, /* pc_relative */ | |
2439 | 0, /* bitpos */ | |
2440 | complain_overflow_bitfield, /* complain_on_overflow */ | |
2441 | bfd_elf_generic_reloc, /* special_function */ | |
2442 | MORELLO_R_STR (IRELATIVE), /* name */ | |
2443 | FALSE, /* partial_inplace */ | |
2444 | 0, /* src_mask */ | |
2445 | ALL_ONES, /* dst_mask */ | |
2446 | FALSE), /* pcrel_offset */ | |
2447 | ||
4ca9b406 SP |
2448 | HOWTO64 (MORELLO_R (TLSDESC), /* type */ |
2449 | 0, /* rightshift */ | |
2450 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
2451 | 64, /* bitsize */ | |
2452 | FALSE, /* pc_relative */ | |
2453 | 0, /* bitpos */ | |
2454 | complain_overflow_dont, /* complain_on_overflow */ | |
2455 | bfd_elf_generic_reloc, /* special_function */ | |
2456 | MORELLO_R_STR (TLSDESC), /* name */ | |
2457 | FALSE, /* partial_inplace */ | |
2458 | 0, /* src_mask */ | |
2459 | ALL_ONES, /* dst_mask */ | |
2460 | FALSE), /* pcrel_offset */ | |
2461 | ||
a6bb11b2 | 2462 | EMPTY_HOWTO (0), |
a06ea964 NC |
2463 | }; |
2464 | ||
a6bb11b2 YZ |
2465 | static reloc_howto_type elfNN_aarch64_howto_none = |
2466 | HOWTO (R_AARCH64_NONE, /* type */ | |
2467 | 0, /* rightshift */ | |
6346d5ca | 2468 | 3, /* size (0 = byte, 1 = short, 2 = long) */ |
a6bb11b2 YZ |
2469 | 0, /* bitsize */ |
2470 | FALSE, /* pc_relative */ | |
2471 | 0, /* bitpos */ | |
2472 | complain_overflow_dont,/* complain_on_overflow */ | |
2473 | bfd_elf_generic_reloc, /* special_function */ | |
2474 | "R_AARCH64_NONE", /* name */ | |
2475 | FALSE, /* partial_inplace */ | |
2476 | 0, /* src_mask */ | |
2477 | 0, /* dst_mask */ | |
2478 | FALSE); /* pcrel_offset */ | |
2479 | ||
2480 | /* Given HOWTO, return the bfd internal relocation enumerator. */ | |
2481 | ||
2482 | static bfd_reloc_code_real_type | |
2483 | elfNN_aarch64_bfd_reloc_from_howto (reloc_howto_type *howto) | |
2484 | { | |
2485 | const int size | |
2486 | = (int) ARRAY_SIZE (elfNN_aarch64_howto_table); | |
2487 | const ptrdiff_t offset | |
2488 | = howto - elfNN_aarch64_howto_table; | |
2489 | ||
2490 | if (offset > 0 && offset < size - 1) | |
2491 | return BFD_RELOC_AARCH64_RELOC_START + offset; | |
2492 | ||
2493 | if (howto == &elfNN_aarch64_howto_none) | |
2494 | return BFD_RELOC_AARCH64_NONE; | |
2495 | ||
2496 | return BFD_RELOC_AARCH64_RELOC_START; | |
2497 | } | |
2498 | ||
2499 | /* Given R_TYPE, return the bfd internal relocation enumerator. */ | |
2500 | ||
2501 | static bfd_reloc_code_real_type | |
0aa13fee | 2502 | elfNN_aarch64_bfd_reloc_from_type (bfd *abfd, unsigned int r_type) |
a6bb11b2 YZ |
2503 | { |
2504 | static bfd_boolean initialized_p = FALSE; | |
2505 | /* Indexed by R_TYPE, values are offsets in the howto_table. */ | |
2506 | static unsigned int offsets[R_AARCH64_end]; | |
2507 | ||
535b785f | 2508 | if (!initialized_p) |
a6bb11b2 YZ |
2509 | { |
2510 | unsigned int i; | |
2511 | ||
2512 | for (i = 1; i < ARRAY_SIZE (elfNN_aarch64_howto_table) - 1; ++i) | |
2513 | if (elfNN_aarch64_howto_table[i].type != 0) | |
2514 | offsets[elfNN_aarch64_howto_table[i].type] = i; | |
2515 | ||
2516 | initialized_p = TRUE; | |
2517 | } | |
2518 | ||
2519 | if (r_type == R_AARCH64_NONE || r_type == R_AARCH64_NULL) | |
2520 | return BFD_RELOC_AARCH64_NONE; | |
2521 | ||
5860e3f8 NC |
2522 | /* PR 17512: file: b371e70a. */ |
2523 | if (r_type >= R_AARCH64_end) | |
2524 | { | |
0aa13fee AM |
2525 | _bfd_error_handler (_("%pB: unsupported relocation type %#x"), |
2526 | abfd, r_type); | |
5860e3f8 NC |
2527 | bfd_set_error (bfd_error_bad_value); |
2528 | return BFD_RELOC_AARCH64_NONE; | |
2529 | } | |
2530 | ||
a6bb11b2 YZ |
2531 | return BFD_RELOC_AARCH64_RELOC_START + offsets[r_type]; |
2532 | } | |
2533 | ||
2534 | struct elf_aarch64_reloc_map | |
2535 | { | |
2536 | bfd_reloc_code_real_type from; | |
2537 | bfd_reloc_code_real_type to; | |
2538 | }; | |
2539 | ||
2540 | /* Map bfd generic reloc to AArch64-specific reloc. */ | |
2541 | static const struct elf_aarch64_reloc_map elf_aarch64_reloc_map[] = | |
2542 | { | |
2543 | {BFD_RELOC_NONE, BFD_RELOC_AARCH64_NONE}, | |
2544 | ||
2545 | /* Basic data relocations. */ | |
2546 | {BFD_RELOC_CTOR, BFD_RELOC_AARCH64_NN}, | |
2547 | {BFD_RELOC_64, BFD_RELOC_AARCH64_64}, | |
2548 | {BFD_RELOC_32, BFD_RELOC_AARCH64_32}, | |
2549 | {BFD_RELOC_16, BFD_RELOC_AARCH64_16}, | |
2550 | {BFD_RELOC_64_PCREL, BFD_RELOC_AARCH64_64_PCREL}, | |
2551 | {BFD_RELOC_32_PCREL, BFD_RELOC_AARCH64_32_PCREL}, | |
2552 | {BFD_RELOC_16_PCREL, BFD_RELOC_AARCH64_16_PCREL}, | |
2553 | }; | |
2554 | ||
2555 | /* Given the bfd internal relocation enumerator in CODE, return the | |
2556 | corresponding howto entry. */ | |
2557 | ||
2558 | static reloc_howto_type * | |
2559 | elfNN_aarch64_howto_from_bfd_reloc (bfd_reloc_code_real_type code) | |
2560 | { | |
2561 | unsigned int i; | |
2562 | ||
2563 | /* Convert bfd generic reloc to AArch64-specific reloc. */ | |
2564 | if (code < BFD_RELOC_AARCH64_RELOC_START | |
2565 | || code > BFD_RELOC_AARCH64_RELOC_END) | |
2566 | for (i = 0; i < ARRAY_SIZE (elf_aarch64_reloc_map); i++) | |
2567 | if (elf_aarch64_reloc_map[i].from == code) | |
2568 | { | |
2569 | code = elf_aarch64_reloc_map[i].to; | |
2570 | break; | |
2571 | } | |
2572 | ||
2573 | if (code > BFD_RELOC_AARCH64_RELOC_START | |
2574 | && code < BFD_RELOC_AARCH64_RELOC_END) | |
2575 | if (elfNN_aarch64_howto_table[code - BFD_RELOC_AARCH64_RELOC_START].type) | |
2576 | return &elfNN_aarch64_howto_table[code - BFD_RELOC_AARCH64_RELOC_START]; | |
2577 | ||
54757ed1 AP |
2578 | if (code == BFD_RELOC_AARCH64_NONE) |
2579 | return &elfNN_aarch64_howto_none; | |
2580 | ||
a6bb11b2 YZ |
2581 | return NULL; |
2582 | } | |
2583 | ||
a06ea964 | 2584 | static reloc_howto_type * |
0aa13fee | 2585 | elfNN_aarch64_howto_from_type (bfd *abfd, unsigned int r_type) |
a06ea964 | 2586 | { |
a6bb11b2 YZ |
2587 | bfd_reloc_code_real_type val; |
2588 | reloc_howto_type *howto; | |
2589 | ||
cec5225b YZ |
2590 | #if ARCH_SIZE == 32 |
2591 | if (r_type > 256) | |
2592 | { | |
2593 | bfd_set_error (bfd_error_bad_value); | |
2594 | return NULL; | |
2595 | } | |
2596 | #endif | |
2597 | ||
a6bb11b2 YZ |
2598 | if (r_type == R_AARCH64_NONE) |
2599 | return &elfNN_aarch64_howto_none; | |
a06ea964 | 2600 | |
0aa13fee | 2601 | val = elfNN_aarch64_bfd_reloc_from_type (abfd, r_type); |
a6bb11b2 | 2602 | howto = elfNN_aarch64_howto_from_bfd_reloc (val); |
a06ea964 | 2603 | |
a6bb11b2 YZ |
2604 | if (howto != NULL) |
2605 | return howto; | |
a06ea964 | 2606 | |
a06ea964 NC |
2607 | bfd_set_error (bfd_error_bad_value); |
2608 | return NULL; | |
2609 | } | |
2610 | ||
f3185997 | 2611 | static bfd_boolean |
0aa13fee | 2612 | elfNN_aarch64_info_to_howto (bfd *abfd, arelent *bfd_reloc, |
a06ea964 NC |
2613 | Elf_Internal_Rela *elf_reloc) |
2614 | { | |
2615 | unsigned int r_type; | |
2616 | ||
cec5225b | 2617 | r_type = ELFNN_R_TYPE (elf_reloc->r_info); |
0aa13fee | 2618 | bfd_reloc->howto = elfNN_aarch64_howto_from_type (abfd, r_type); |
f3185997 NC |
2619 | |
2620 | if (bfd_reloc->howto == NULL) | |
2621 | { | |
2622 | /* xgettext:c-format */ | |
2623 | _bfd_error_handler (_("%pB: unsupported relocation type %#x"), abfd, r_type); | |
2624 | return FALSE; | |
2625 | } | |
2626 | return TRUE; | |
a06ea964 NC |
2627 | } |
2628 | ||
a06ea964 | 2629 | static reloc_howto_type * |
cec5225b | 2630 | elfNN_aarch64_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED, |
a06ea964 NC |
2631 | bfd_reloc_code_real_type code) |
2632 | { | |
a6bb11b2 | 2633 | reloc_howto_type *howto = elfNN_aarch64_howto_from_bfd_reloc (code); |
a06ea964 | 2634 | |
a6bb11b2 YZ |
2635 | if (howto != NULL) |
2636 | return howto; | |
a06ea964 NC |
2637 | |
2638 | bfd_set_error (bfd_error_bad_value); | |
2639 | return NULL; | |
2640 | } | |
2641 | ||
2642 | static reloc_howto_type * | |
cec5225b | 2643 | elfNN_aarch64_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED, |
a06ea964 NC |
2644 | const char *r_name) |
2645 | { | |
2646 | unsigned int i; | |
2647 | ||
a6bb11b2 YZ |
2648 | for (i = 1; i < ARRAY_SIZE (elfNN_aarch64_howto_table) - 1; ++i) |
2649 | if (elfNN_aarch64_howto_table[i].name != NULL | |
2650 | && strcasecmp (elfNN_aarch64_howto_table[i].name, r_name) == 0) | |
2651 | return &elfNN_aarch64_howto_table[i]; | |
a06ea964 NC |
2652 | |
2653 | return NULL; | |
2654 | } | |
2655 | ||
07d6d2b8 AM |
2656 | #define TARGET_LITTLE_SYM aarch64_elfNN_le_vec |
2657 | #define TARGET_LITTLE_NAME "elfNN-littleaarch64" | |
2658 | #define TARGET_BIG_SYM aarch64_elfNN_be_vec | |
2659 | #define TARGET_BIG_NAME "elfNN-bigaarch64" | |
a06ea964 | 2660 | |
a06ea964 NC |
2661 | /* The linker script knows the section names for placement. |
2662 | The entry_names are used to do simple name mangling on the stubs. | |
2663 | Given a function name, and its type, the stub can be found. The | |
2664 | name can be changed. The only requirement is the %s be present. */ | |
50e192f0 | 2665 | #define STUB_ENTRY_NAME "__%s%s_veneer" |
a06ea964 NC |
2666 | |
2667 | /* The name of the dynamic interpreter. This is put in the .interp | |
2668 | section. */ | |
2669 | #define ELF_DYNAMIC_INTERPRETER "/lib/ld.so.1" | |
2670 | ||
2671 | #define AARCH64_MAX_FWD_BRANCH_OFFSET \ | |
2672 | (((1 << 25) - 1) << 2) | |
2673 | #define AARCH64_MAX_BWD_BRANCH_OFFSET \ | |
2674 | (-((1 << 25) << 2)) | |
2675 | ||
2676 | #define AARCH64_MAX_ADRP_IMM ((1 << 20) - 1) | |
2677 | #define AARCH64_MIN_ADRP_IMM (-(1 << 20)) | |
2678 | ||
50e192f0 SP |
2679 | #define C64_MAX_ADRP_IMM ((1 << 19) - 1) |
2680 | #define C64_MIN_ADRP_IMM (-(1 << 19)) | |
2681 | ||
2682 | static bfd_boolean | |
2683 | aarch64_branch_reloc_p (unsigned int r_type) | |
2684 | { | |
2685 | switch (r_type) | |
2686 | { | |
2687 | case MORELLO_R (JUMP26): | |
2688 | case MORELLO_R (CALL26): | |
2689 | case AARCH64_R (JUMP26): | |
2690 | case AARCH64_R (CALL26): | |
2691 | return TRUE; | |
2692 | ||
2693 | default: break; | |
2694 | } | |
2695 | ||
2696 | return FALSE; | |
2697 | } | |
2698 | ||
a06ea964 NC |
2699 | static int |
2700 | aarch64_valid_for_adrp_p (bfd_vma value, bfd_vma place) | |
2701 | { | |
2702 | bfd_signed_vma offset = (bfd_signed_vma) (PG (value) - PG (place)) >> 12; | |
2703 | return offset <= AARCH64_MAX_ADRP_IMM && offset >= AARCH64_MIN_ADRP_IMM; | |
2704 | } | |
2705 | ||
50e192f0 SP |
2706 | static bfd_boolean |
2707 | c64_valid_for_adrp_p (bfd_vma value, bfd_vma place) | |
2708 | { | |
2709 | bfd_signed_vma offset = (bfd_signed_vma) (PG (value) - PG (place)) >> 12; | |
2710 | return offset <= C64_MAX_ADRP_IMM && offset >= C64_MIN_ADRP_IMM; | |
2711 | } | |
2712 | ||
a06ea964 NC |
2713 | static int |
2714 | aarch64_valid_branch_p (bfd_vma value, bfd_vma place) | |
2715 | { | |
2716 | bfd_signed_vma offset = (bfd_signed_vma) (value - place); | |
2717 | return (offset <= AARCH64_MAX_FWD_BRANCH_OFFSET | |
2718 | && offset >= AARCH64_MAX_BWD_BRANCH_OFFSET); | |
2719 | } | |
2720 | ||
2721 | static const uint32_t aarch64_adrp_branch_stub [] = | |
2722 | { | |
2723 | 0x90000010, /* adrp ip0, X */ | |
2724 | /* R_AARCH64_ADR_HI21_PCREL(X) */ | |
2725 | 0x91000210, /* add ip0, ip0, :lo12:X */ | |
2726 | /* R_AARCH64_ADD_ABS_LO12_NC(X) */ | |
2727 | 0xd61f0200, /* br ip0 */ | |
2728 | }; | |
2729 | ||
2730 | static const uint32_t aarch64_long_branch_stub[] = | |
2731 | { | |
cec5225b | 2732 | #if ARCH_SIZE == 64 |
a06ea964 | 2733 | 0x58000090, /* ldr ip0, 1f */ |
cec5225b YZ |
2734 | #else |
2735 | 0x18000090, /* ldr wip0, 1f */ | |
2736 | #endif | |
a06ea964 NC |
2737 | 0x10000011, /* adr ip1, #0 */ |
2738 | 0x8b110210, /* add ip0, ip0, ip1 */ | |
2739 | 0xd61f0200, /* br ip0 */ | |
cec5225b YZ |
2740 | 0x00000000, /* 1: .xword or .word |
2741 | R_AARCH64_PRELNN(X) + 12 | |
a06ea964 NC |
2742 | */ |
2743 | 0x00000000, | |
2744 | }; | |
2745 | ||
68fcca92 JW |
2746 | static const uint32_t aarch64_erratum_835769_stub[] = |
2747 | { | |
2748 | 0x00000000, /* Placeholder for multiply accumulate. */ | |
2749 | 0x14000000, /* b <label> */ | |
2750 | }; | |
2751 | ||
4106101c MS |
2752 | static const uint32_t aarch64_erratum_843419_stub[] = |
2753 | { | |
2754 | 0x00000000, /* Placeholder for LDR instruction. */ | |
2755 | 0x14000000, /* b <label> */ | |
2756 | }; | |
2757 | ||
50e192f0 SP |
2758 | static const uint32_t aarch64_c64_branch_stub [] = |
2759 | { | |
2760 | 0xc2c273e0, /* bx #4 */ | |
2761 | 0x90800010, /* adrp c16, X */ | |
2762 | /* R_MORELLO_ADR_HI20_PCREL(X) */ | |
2763 | 0x02000210, /* add c16, c16, :lo12:X */ | |
2764 | /* R_AARCH64_ADD_ABS_LO12_NC(X) */ | |
2765 | 0xc2c21200, /* br c16 */ | |
2766 | }; | |
2767 | ||
2768 | static const uint32_t c64_aarch64_branch_stub [] = | |
2769 | { | |
2770 | 0x90800010, /* adrp c16, X */ | |
2771 | /* R_MORELLO_ADR_HI20_PCREL(X) */ | |
2772 | 0x02000210, /* add c16, c16, :lo12:X */ | |
2773 | /* R_AARCH64_ADD_ABS_LO12_NC(X) */ | |
2774 | 0xc2c21200, /* br c16 */ | |
2775 | }; | |
2776 | ||
a06ea964 NC |
2777 | /* Section name for stubs is the associated section name plus this |
2778 | string. */ | |
2779 | #define STUB_SUFFIX ".stub" | |
2780 | ||
cec5225b | 2781 | enum elf_aarch64_stub_type |
a06ea964 NC |
2782 | { |
2783 | aarch64_stub_none, | |
2784 | aarch64_stub_adrp_branch, | |
2785 | aarch64_stub_long_branch, | |
68fcca92 | 2786 | aarch64_stub_erratum_835769_veneer, |
4106101c | 2787 | aarch64_stub_erratum_843419_veneer, |
50e192f0 SP |
2788 | aarch64_stub_branch_c64, |
2789 | c64_stub_branch_aarch64, | |
2790 | c64_stub_branch_c64, | |
a06ea964 NC |
2791 | }; |
2792 | ||
cec5225b | 2793 | struct elf_aarch64_stub_hash_entry |
a06ea964 NC |
2794 | { |
2795 | /* Base hash table entry structure. */ | |
2796 | struct bfd_hash_entry root; | |
2797 | ||
2798 | /* The stub section. */ | |
2799 | asection *stub_sec; | |
2800 | ||
2801 | /* Offset within stub_sec of the beginning of this stub. */ | |
2802 | bfd_vma stub_offset; | |
2803 | ||
2804 | /* Given the symbol's value and its section we can determine its final | |
2805 | value when building the stubs (so the stub knows where to jump). */ | |
2806 | bfd_vma target_value; | |
2807 | asection *target_section; | |
2808 | ||
cec5225b | 2809 | enum elf_aarch64_stub_type stub_type; |
a06ea964 NC |
2810 | |
2811 | /* The symbol table entry, if any, that this was derived from. */ | |
cec5225b | 2812 | struct elf_aarch64_link_hash_entry *h; |
a06ea964 NC |
2813 | |
2814 | /* Destination symbol type */ | |
2815 | unsigned char st_type; | |
2816 | ||
2817 | /* Where this stub is being called from, or, in the case of combined | |
2818 | stub sections, the first input section in the group. */ | |
2819 | asection *id_sec; | |
2820 | ||
2821 | /* The name for the local symbol at the start of this stub. The | |
2822 | stub name in the hash table has to be unique; this does not, so | |
2823 | it can be friendlier. */ | |
2824 | char *output_name; | |
68fcca92 JW |
2825 | |
2826 | /* The instruction which caused this stub to be generated (only valid for | |
2827 | erratum 835769 workaround stubs at present). */ | |
2828 | uint32_t veneered_insn; | |
4106101c MS |
2829 | |
2830 | /* In an erratum 843419 workaround stub, the ADRP instruction offset. */ | |
2831 | bfd_vma adrp_offset; | |
a06ea964 NC |
2832 | }; |
2833 | ||
2834 | /* Used to build a map of a section. This is required for mixed-endian | |
2835 | code/data. */ | |
2836 | ||
cec5225b | 2837 | typedef struct elf_elf_section_map |
a06ea964 NC |
2838 | { |
2839 | bfd_vma vma; | |
2840 | char type; | |
2841 | } | |
cec5225b | 2842 | elf_aarch64_section_map; |
a06ea964 NC |
2843 | |
2844 | ||
2845 | typedef struct _aarch64_elf_section_data | |
2846 | { | |
2847 | struct bfd_elf_section_data elf; | |
2848 | unsigned int mapcount; | |
2849 | unsigned int mapsize; | |
cec5225b | 2850 | elf_aarch64_section_map *map; |
f0070c1e | 2851 | bfd_boolean sorted; |
a06ea964 NC |
2852 | } |
2853 | _aarch64_elf_section_data; | |
2854 | ||
cec5225b | 2855 | #define elf_aarch64_section_data(sec) \ |
a06ea964 NC |
2856 | ((_aarch64_elf_section_data *) elf_section_data (sec)) |
2857 | ||
f0070c1e SP |
2858 | /* Used to order a list of mapping symbols by address. */ |
2859 | ||
2860 | static int | |
2861 | elf_aarch64_compare_mapping (const void *a, const void *b) | |
2862 | { | |
2863 | const elf_aarch64_section_map *amap = (const elf_aarch64_section_map *) a; | |
2864 | const elf_aarch64_section_map *bmap = (const elf_aarch64_section_map *) b; | |
2865 | ||
2866 | if (amap->vma > bmap->vma) | |
2867 | return 1; | |
2868 | else if (amap->vma < bmap->vma) | |
2869 | return -1; | |
2870 | else if (amap->type > bmap->type) | |
2871 | /* Ensure results do not depend on the host qsort for objects with | |
2872 | multiple mapping symbols at the same address by sorting on type | |
2873 | after vma. */ | |
2874 | return 1; | |
2875 | else if (amap->type < bmap->type) | |
2876 | return -1; | |
2877 | else | |
2878 | return 0; | |
2879 | } | |
2880 | ||
2881 | static _aarch64_elf_section_data * | |
2882 | elf_aarch64_section_data_get (asection *sec) | |
2883 | { | |
2884 | _aarch64_elf_section_data *sec_data = elf_aarch64_section_data(sec); | |
2885 | ||
2886 | /* A section that does not have aarch64 section data, so it does not have any | |
2887 | map information. Assume A64. */ | |
2888 | if (sec_data == NULL || !sec_data->elf.is_target_section_data) | |
2889 | return NULL; | |
2890 | ||
2891 | if (sec_data->sorted) | |
2892 | goto done; | |
2893 | ||
2894 | qsort (sec_data->map, sec_data->mapcount, sizeof (elf_aarch64_section_map), | |
2895 | elf_aarch64_compare_mapping); | |
2896 | ||
2897 | sec_data->sorted = TRUE; | |
2898 | ||
2899 | done: | |
2900 | return sec_data; | |
2901 | } | |
2902 | ||
2903 | /* Returns TRUE if the label with st_value as VALUE is within a C64 code | |
2904 | section or not. */ | |
2905 | ||
2906 | static bfd_boolean | |
2907 | c64_value_p (asection *section, unsigned int value) | |
2908 | { | |
2909 | struct _aarch64_elf_section_data *sec_data = | |
2910 | elf_aarch64_section_data_get (section); | |
2911 | ||
2912 | if (sec_data == NULL) | |
2913 | return FALSE; | |
2914 | ||
2915 | unsigned int span; | |
2916 | ||
2917 | for (span = 0; span < sec_data->mapcount; span++) | |
2918 | { | |
2919 | unsigned int span_start = sec_data->map[span].vma; | |
2920 | unsigned int span_end = ((span == sec_data->mapcount - 1) | |
2921 | ? sec_data->map[0].vma + section->size | |
2922 | : sec_data->map[span + 1].vma); | |
2923 | char span_type = sec_data->map[span].type; | |
2924 | ||
2925 | if (span_start <= value && value < span_end && span_type == 'c') | |
2926 | return TRUE; | |
2927 | } | |
2928 | return FALSE; | |
2929 | } | |
2930 | ||
4e8516b2 AP |
2931 | /* The size of the thread control block which is defined to be two pointers. */ |
2932 | #define TCB_SIZE (ARCH_SIZE/8)*2 | |
a06ea964 NC |
2933 | |
2934 | struct elf_aarch64_local_symbol | |
2935 | { | |
2936 | unsigned int got_type; | |
2937 | bfd_signed_vma got_refcount; | |
2938 | bfd_vma got_offset; | |
2939 | ||
2940 | /* Offset of the GOTPLT entry reserved for the TLS descriptor. The | |
2941 | offset is from the end of the jump table and reserved entries | |
2942 | within the PLTGOT. | |
2943 | ||
2944 | The magic value (bfd_vma) -1 indicates that an offset has not be | |
2945 | allocated. */ | |
2946 | bfd_vma tlsdesc_got_jump_table_offset; | |
2947 | }; | |
2948 | ||
2949 | struct elf_aarch64_obj_tdata | |
2950 | { | |
2951 | struct elf_obj_tdata root; | |
2952 | ||
2953 | /* local symbol descriptors */ | |
2954 | struct elf_aarch64_local_symbol *locals; | |
2955 | ||
2956 | /* Zero to warn when linking objects with incompatible enum sizes. */ | |
2957 | int no_enum_size_warning; | |
2958 | ||
2959 | /* Zero to warn when linking objects with incompatible wchar_t sizes. */ | |
2960 | int no_wchar_size_warning; | |
cd702818 SD |
2961 | |
2962 | /* All GNU_PROPERTY_AARCH64_FEATURE_1_AND properties. */ | |
2963 | uint32_t gnu_and_prop; | |
37c18eed SD |
2964 | |
2965 | /* Zero to warn when linking objects with incompatible | |
2966 | GNU_PROPERTY_AARCH64_FEATURE_1_BTI. */ | |
2967 | int no_bti_warn; | |
2968 | ||
2969 | /* PLT type based on security. */ | |
2970 | aarch64_plt_type plt_type; | |
f0070c1e SP |
2971 | |
2972 | /* Flag to check if section maps have been initialised for all sections in | |
2973 | this object. */ | |
2974 | bfd_boolean secmaps_initialised; | |
a06ea964 NC |
2975 | }; |
2976 | ||
2977 | #define elf_aarch64_tdata(bfd) \ | |
2978 | ((struct elf_aarch64_obj_tdata *) (bfd)->tdata.any) | |
2979 | ||
cec5225b | 2980 | #define elf_aarch64_locals(bfd) (elf_aarch64_tdata (bfd)->locals) |
a06ea964 NC |
2981 | |
2982 | #define is_aarch64_elf(bfd) \ | |
2983 | (bfd_get_flavour (bfd) == bfd_target_elf_flavour \ | |
2984 | && elf_tdata (bfd) != NULL \ | |
2985 | && elf_object_id (bfd) == AARCH64_ELF_DATA) | |
2986 | ||
2987 | static bfd_boolean | |
cec5225b | 2988 | elfNN_aarch64_mkobject (bfd *abfd) |
a06ea964 NC |
2989 | { |
2990 | return bfd_elf_allocate_object (abfd, sizeof (struct elf_aarch64_obj_tdata), | |
2991 | AARCH64_ELF_DATA); | |
2992 | } | |
2993 | ||
cec5225b YZ |
2994 | #define elf_aarch64_hash_entry(ent) \ |
2995 | ((struct elf_aarch64_link_hash_entry *)(ent)) | |
a06ea964 NC |
2996 | |
2997 | #define GOT_UNKNOWN 0 | |
2998 | #define GOT_NORMAL 1 | |
2999 | #define GOT_TLS_GD 2 | |
3000 | #define GOT_TLS_IE 4 | |
3001 | #define GOT_TLSDESC_GD 8 | |
a1bdea65 | 3002 | #define GOT_CAP 16 |
a06ea964 NC |
3003 | |
3004 | #define GOT_TLS_GD_ANY_P(type) ((type & GOT_TLS_GD) || (type & GOT_TLSDESC_GD)) | |
3005 | ||
3006 | /* AArch64 ELF linker hash entry. */ | |
cec5225b | 3007 | struct elf_aarch64_link_hash_entry |
a06ea964 NC |
3008 | { |
3009 | struct elf_link_hash_entry root; | |
3010 | ||
a06ea964 NC |
3011 | /* Since PLT entries have variable size, we need to record the |
3012 | index into .got.plt instead of recomputing it from the PLT | |
3013 | offset. */ | |
3014 | bfd_signed_vma plt_got_offset; | |
3015 | ||
3016 | /* Bit mask representing the type of GOT entry(s) if any required by | |
3017 | this symbol. */ | |
3018 | unsigned int got_type; | |
3019 | ||
3020 | /* A pointer to the most recently used stub hash entry against this | |
3021 | symbol. */ | |
cec5225b | 3022 | struct elf_aarch64_stub_hash_entry *stub_cache; |
a06ea964 NC |
3023 | |
3024 | /* Offset of the GOTPLT entry reserved for the TLS descriptor. The offset | |
3025 | is from the end of the jump table and reserved entries within the PLTGOT. | |
3026 | ||
3027 | The magic value (bfd_vma) -1 indicates that an offset has not | |
3028 | be allocated. */ | |
3029 | bfd_vma tlsdesc_got_jump_table_offset; | |
3030 | }; | |
3031 | ||
3032 | static unsigned int | |
cec5225b | 3033 | elfNN_aarch64_symbol_got_type (struct elf_link_hash_entry *h, |
a06ea964 NC |
3034 | bfd *abfd, |
3035 | unsigned long r_symndx) | |
3036 | { | |
3037 | if (h) | |
cec5225b | 3038 | return elf_aarch64_hash_entry (h)->got_type; |
a06ea964 | 3039 | |
cec5225b | 3040 | if (! elf_aarch64_locals (abfd)) |
a06ea964 NC |
3041 | return GOT_UNKNOWN; |
3042 | ||
cec5225b | 3043 | return elf_aarch64_locals (abfd)[r_symndx].got_type; |
a06ea964 NC |
3044 | } |
3045 | ||
a06ea964 | 3046 | /* Get the AArch64 elf linker hash table from a link_info structure. */ |
cec5225b YZ |
3047 | #define elf_aarch64_hash_table(info) \ |
3048 | ((struct elf_aarch64_link_hash_table *) ((info)->hash)) | |
a06ea964 NC |
3049 | |
3050 | #define aarch64_stub_hash_lookup(table, string, create, copy) \ | |
cec5225b | 3051 | ((struct elf_aarch64_stub_hash_entry *) \ |
a06ea964 NC |
3052 | bfd_hash_lookup ((table), (string), (create), (copy))) |
3053 | ||
3054 | /* AArch64 ELF linker hash table. */ | |
cec5225b | 3055 | struct elf_aarch64_link_hash_table |
a06ea964 NC |
3056 | { |
3057 | /* The main hash table. */ | |
3058 | struct elf_link_hash_table root; | |
3059 | ||
3060 | /* Nonzero to force PIC branch veneers. */ | |
3061 | int pic_veneer; | |
3062 | ||
68fcca92 JW |
3063 | /* Fix erratum 835769. */ |
3064 | int fix_erratum_835769; | |
3065 | ||
4106101c | 3066 | /* Fix erratum 843419. */ |
739b5c9c | 3067 | erratum_84319_opts fix_erratum_843419; |
4106101c | 3068 | |
1f56df9d JW |
3069 | /* Don't apply link-time values for dynamic relocations. */ |
3070 | int no_apply_dynamic_relocs; | |
3071 | ||
a06ea964 NC |
3072 | /* The number of bytes in the initial entry in the PLT. */ |
3073 | bfd_size_type plt_header_size; | |
3074 | ||
37c18eed SD |
3075 | /* The bytes of the initial PLT entry. */ |
3076 | const bfd_byte *plt0_entry; | |
3077 | ||
3078 | /* The number of bytes in the subsequent PLT entries. */ | |
a06ea964 NC |
3079 | bfd_size_type plt_entry_size; |
3080 | ||
37c18eed SD |
3081 | /* The bytes of the subsequent PLT entry. */ |
3082 | const bfd_byte *plt_entry; | |
3083 | ||
a06ea964 NC |
3084 | /* For convenience in allocate_dynrelocs. */ |
3085 | bfd *obfd; | |
3086 | ||
3087 | /* The amount of space used by the reserved portion of the sgotplt | |
3088 | section, plus whatever space is used by the jump slots. */ | |
3089 | bfd_vma sgotplt_jump_table_size; | |
3090 | ||
3091 | /* The stub hash table. */ | |
3092 | struct bfd_hash_table stub_hash_table; | |
3093 | ||
3094 | /* Linker stub bfd. */ | |
3095 | bfd *stub_bfd; | |
3096 | ||
3097 | /* Linker call-backs. */ | |
3098 | asection *(*add_stub_section) (const char *, asection *); | |
3099 | void (*layout_sections_again) (void); | |
3100 | ||
3101 | /* Array to keep track of which stub sections have been created, and | |
3102 | information on stub grouping. */ | |
3103 | struct map_stub | |
3104 | { | |
3105 | /* This is the section to which stubs in the group will be | |
3106 | attached. */ | |
3107 | asection *link_sec; | |
3108 | /* The stub section. */ | |
3109 | asection *stub_sec; | |
3110 | } *stub_group; | |
3111 | ||
cec5225b | 3112 | /* Assorted information used by elfNN_aarch64_size_stubs. */ |
a06ea964 | 3113 | unsigned int bfd_count; |
7292b3ac | 3114 | unsigned int top_index; |
a06ea964 NC |
3115 | asection **input_list; |
3116 | ||
823710d5 SN |
3117 | /* JUMP_SLOT relocs for variant PCS symbols may be present. */ |
3118 | int variant_pcs; | |
3119 | ||
37c18eed SD |
3120 | /* The number of bytes in the PLT enty for the TLS descriptor. */ |
3121 | bfd_size_type tlsdesc_plt_entry_size; | |
3122 | ||
1419bbe5 WN |
3123 | /* Used by local STT_GNU_IFUNC symbols. */ |
3124 | htab_t loc_hash_table; | |
3125 | void * loc_hash_memory; | |
40bbb79e SP |
3126 | |
3127 | /* Used for capability relocations. */ | |
3128 | asection *srelcaps; | |
a1bdea65 | 3129 | int c64_rel; |
7ff36d1a | 3130 | bfd_boolean c64_output; |
a06ea964 NC |
3131 | }; |
3132 | ||
a06ea964 NC |
3133 | /* Create an entry in an AArch64 ELF linker hash table. */ |
3134 | ||
3135 | static struct bfd_hash_entry * | |
cec5225b | 3136 | elfNN_aarch64_link_hash_newfunc (struct bfd_hash_entry *entry, |
a06ea964 NC |
3137 | struct bfd_hash_table *table, |
3138 | const char *string) | |
3139 | { | |
cec5225b YZ |
3140 | struct elf_aarch64_link_hash_entry *ret = |
3141 | (struct elf_aarch64_link_hash_entry *) entry; | |
a06ea964 NC |
3142 | |
3143 | /* Allocate the structure if it has not already been allocated by a | |
3144 | subclass. */ | |
3145 | if (ret == NULL) | |
3146 | ret = bfd_hash_allocate (table, | |
cec5225b | 3147 | sizeof (struct elf_aarch64_link_hash_entry)); |
a06ea964 NC |
3148 | if (ret == NULL) |
3149 | return (struct bfd_hash_entry *) ret; | |
3150 | ||
3151 | /* Call the allocation method of the superclass. */ | |
cec5225b | 3152 | ret = ((struct elf_aarch64_link_hash_entry *) |
a06ea964 NC |
3153 | _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry *) ret, |
3154 | table, string)); | |
3155 | if (ret != NULL) | |
3156 | { | |
a06ea964 NC |
3157 | ret->got_type = GOT_UNKNOWN; |
3158 | ret->plt_got_offset = (bfd_vma) - 1; | |
3159 | ret->stub_cache = NULL; | |
3160 | ret->tlsdesc_got_jump_table_offset = (bfd_vma) - 1; | |
3161 | } | |
3162 | ||
3163 | return (struct bfd_hash_entry *) ret; | |
3164 | } | |
3165 | ||
3166 | /* Initialize an entry in the stub hash table. */ | |
3167 | ||
3168 | static struct bfd_hash_entry * | |
3169 | stub_hash_newfunc (struct bfd_hash_entry *entry, | |
3170 | struct bfd_hash_table *table, const char *string) | |
3171 | { | |
3172 | /* Allocate the structure if it has not already been allocated by a | |
3173 | subclass. */ | |
3174 | if (entry == NULL) | |
3175 | { | |
3176 | entry = bfd_hash_allocate (table, | |
3177 | sizeof (struct | |
cec5225b | 3178 | elf_aarch64_stub_hash_entry)); |
a06ea964 NC |
3179 | if (entry == NULL) |
3180 | return entry; | |
3181 | } | |
3182 | ||
3183 | /* Call the allocation method of the superclass. */ | |
3184 | entry = bfd_hash_newfunc (entry, table, string); | |
3185 | if (entry != NULL) | |
3186 | { | |
cec5225b | 3187 | struct elf_aarch64_stub_hash_entry *eh; |
a06ea964 NC |
3188 | |
3189 | /* Initialize the local fields. */ | |
cec5225b | 3190 | eh = (struct elf_aarch64_stub_hash_entry *) entry; |
4106101c | 3191 | eh->adrp_offset = 0; |
a06ea964 NC |
3192 | eh->stub_sec = NULL; |
3193 | eh->stub_offset = 0; | |
3194 | eh->target_value = 0; | |
3195 | eh->target_section = NULL; | |
3196 | eh->stub_type = aarch64_stub_none; | |
3197 | eh->h = NULL; | |
3198 | eh->id_sec = NULL; | |
3199 | } | |
3200 | ||
3201 | return entry; | |
3202 | } | |
3203 | ||
1419bbe5 WN |
3204 | /* Compute a hash of a local hash entry. We use elf_link_hash_entry |
3205 | for local symbol so that we can handle local STT_GNU_IFUNC symbols | |
3206 | as global symbol. We reuse indx and dynstr_index for local symbol | |
3207 | hash since they aren't used by global symbols in this backend. */ | |
3208 | ||
3209 | static hashval_t | |
3210 | elfNN_aarch64_local_htab_hash (const void *ptr) | |
3211 | { | |
3212 | struct elf_link_hash_entry *h | |
3213 | = (struct elf_link_hash_entry *) ptr; | |
3214 | return ELF_LOCAL_SYMBOL_HASH (h->indx, h->dynstr_index); | |
3215 | } | |
3216 | ||
3217 | /* Compare local hash entries. */ | |
3218 | ||
3219 | static int | |
3220 | elfNN_aarch64_local_htab_eq (const void *ptr1, const void *ptr2) | |
3221 | { | |
3222 | struct elf_link_hash_entry *h1 | |
3223 | = (struct elf_link_hash_entry *) ptr1; | |
3224 | struct elf_link_hash_entry *h2 | |
3225 | = (struct elf_link_hash_entry *) ptr2; | |
3226 | ||
3227 | return h1->indx == h2->indx && h1->dynstr_index == h2->dynstr_index; | |
3228 | } | |
3229 | ||
3230 | /* Find and/or create a hash entry for local symbol. */ | |
3231 | ||
3232 | static struct elf_link_hash_entry * | |
3233 | elfNN_aarch64_get_local_sym_hash (struct elf_aarch64_link_hash_table *htab, | |
3234 | bfd *abfd, const Elf_Internal_Rela *rel, | |
3235 | bfd_boolean create) | |
3236 | { | |
3237 | struct elf_aarch64_link_hash_entry e, *ret; | |
3238 | asection *sec = abfd->sections; | |
3239 | hashval_t h = ELF_LOCAL_SYMBOL_HASH (sec->id, | |
3240 | ELFNN_R_SYM (rel->r_info)); | |
3241 | void **slot; | |
3242 | ||
3243 | e.root.indx = sec->id; | |
3244 | e.root.dynstr_index = ELFNN_R_SYM (rel->r_info); | |
3245 | slot = htab_find_slot_with_hash (htab->loc_hash_table, &e, h, | |
3246 | create ? INSERT : NO_INSERT); | |
3247 | ||
3248 | if (!slot) | |
3249 | return NULL; | |
3250 | ||
3251 | if (*slot) | |
3252 | { | |
3253 | ret = (struct elf_aarch64_link_hash_entry *) *slot; | |
3254 | return &ret->root; | |
3255 | } | |
3256 | ||
3257 | ret = (struct elf_aarch64_link_hash_entry *) | |
3258 | objalloc_alloc ((struct objalloc *) htab->loc_hash_memory, | |
3259 | sizeof (struct elf_aarch64_link_hash_entry)); | |
3260 | if (ret) | |
3261 | { | |
3262 | memset (ret, 0, sizeof (*ret)); | |
3263 | ret->root.indx = sec->id; | |
3264 | ret->root.dynstr_index = ELFNN_R_SYM (rel->r_info); | |
3265 | ret->root.dynindx = -1; | |
3266 | *slot = ret; | |
3267 | } | |
3268 | return &ret->root; | |
3269 | } | |
a06ea964 NC |
3270 | |
3271 | /* Copy the extra info we tack onto an elf_link_hash_entry. */ | |
3272 | ||
3273 | static void | |
cec5225b | 3274 | elfNN_aarch64_copy_indirect_symbol (struct bfd_link_info *info, |
a06ea964 NC |
3275 | struct elf_link_hash_entry *dir, |
3276 | struct elf_link_hash_entry *ind) | |
3277 | { | |
cec5225b | 3278 | struct elf_aarch64_link_hash_entry *edir, *eind; |
a06ea964 | 3279 | |
cec5225b YZ |
3280 | edir = (struct elf_aarch64_link_hash_entry *) dir; |
3281 | eind = (struct elf_aarch64_link_hash_entry *) ind; | |
a06ea964 | 3282 | |
a06ea964 NC |
3283 | if (ind->root.type == bfd_link_hash_indirect) |
3284 | { | |
3285 | /* Copy over PLT info. */ | |
3286 | if (dir->got.refcount <= 0) | |
3287 | { | |
3288 | edir->got_type = eind->got_type; | |
3289 | eind->got_type = GOT_UNKNOWN; | |
3290 | } | |
3291 | } | |
3292 | ||
3293 | _bfd_elf_link_hash_copy_indirect (info, dir, ind); | |
3294 | } | |
3295 | ||
823710d5 SN |
3296 | /* Merge non-visibility st_other attributes. */ |
3297 | ||
3298 | static void | |
3299 | elfNN_aarch64_merge_symbol_attribute (struct elf_link_hash_entry *h, | |
3300 | const Elf_Internal_Sym *isym, | |
3301 | bfd_boolean definition ATTRIBUTE_UNUSED, | |
3302 | bfd_boolean dynamic ATTRIBUTE_UNUSED) | |
3303 | { | |
3304 | unsigned int isym_sto = isym->st_other & ~ELF_ST_VISIBILITY (-1); | |
3305 | unsigned int h_sto = h->other & ~ELF_ST_VISIBILITY (-1); | |
3306 | ||
3307 | if (isym_sto == h_sto) | |
3308 | return; | |
3309 | ||
3310 | if (isym_sto & ~STO_AARCH64_VARIANT_PCS) | |
3311 | /* Not fatal, this callback cannot fail. */ | |
3312 | _bfd_error_handler (_("unknown attribute for symbol `%s': 0x%02x"), | |
3313 | h->root.root.string, isym_sto); | |
3314 | ||
3315 | /* Note: Ideally we would warn about any attribute mismatch, but | |
3316 | this api does not allow that without substantial changes. */ | |
3317 | if (isym_sto & STO_AARCH64_VARIANT_PCS) | |
3318 | h->other |= STO_AARCH64_VARIANT_PCS; | |
3319 | } | |
3320 | ||
68faa637 AM |
3321 | /* Destroy an AArch64 elf linker hash table. */ |
3322 | ||
3323 | static void | |
d495ab0d | 3324 | elfNN_aarch64_link_hash_table_free (bfd *obfd) |
68faa637 AM |
3325 | { |
3326 | struct elf_aarch64_link_hash_table *ret | |
d495ab0d | 3327 | = (struct elf_aarch64_link_hash_table *) obfd->link.hash; |
68faa637 AM |
3328 | |
3329 | if (ret->loc_hash_table) | |
3330 | htab_delete (ret->loc_hash_table); | |
3331 | if (ret->loc_hash_memory) | |
3332 | objalloc_free ((struct objalloc *) ret->loc_hash_memory); | |
3333 | ||
3334 | bfd_hash_table_free (&ret->stub_hash_table); | |
d495ab0d | 3335 | _bfd_elf_link_hash_table_free (obfd); |
68faa637 AM |
3336 | } |
3337 | ||
a06ea964 NC |
3338 | /* Create an AArch64 elf linker hash table. */ |
3339 | ||
3340 | static struct bfd_link_hash_table * | |
cec5225b | 3341 | elfNN_aarch64_link_hash_table_create (bfd *abfd) |
a06ea964 | 3342 | { |
cec5225b | 3343 | struct elf_aarch64_link_hash_table *ret; |
986f0783 | 3344 | size_t amt = sizeof (struct elf_aarch64_link_hash_table); |
a06ea964 | 3345 | |
7bf52ea2 | 3346 | ret = bfd_zmalloc (amt); |
a06ea964 NC |
3347 | if (ret == NULL) |
3348 | return NULL; | |
3349 | ||
3350 | if (!_bfd_elf_link_hash_table_init | |
cec5225b YZ |
3351 | (&ret->root, abfd, elfNN_aarch64_link_hash_newfunc, |
3352 | sizeof (struct elf_aarch64_link_hash_entry), AARCH64_ELF_DATA)) | |
a06ea964 NC |
3353 | { |
3354 | free (ret); | |
3355 | return NULL; | |
3356 | } | |
3357 | ||
a06ea964 | 3358 | ret->plt_header_size = PLT_ENTRY_SIZE; |
37c18eed | 3359 | ret->plt0_entry = elfNN_aarch64_small_plt0_entry; |
a06ea964 | 3360 | ret->plt_entry_size = PLT_SMALL_ENTRY_SIZE; |
37c18eed SD |
3361 | ret->plt_entry = elfNN_aarch64_small_plt_entry; |
3362 | ret->tlsdesc_plt_entry_size = PLT_TLSDESC_ENTRY_SIZE; | |
a06ea964 | 3363 | ret->obfd = abfd; |
9bcc30e4 | 3364 | ret->root.tlsdesc_got = (bfd_vma) - 1; |
a06ea964 NC |
3365 | |
3366 | if (!bfd_hash_table_init (&ret->stub_hash_table, stub_hash_newfunc, | |
cec5225b | 3367 | sizeof (struct elf_aarch64_stub_hash_entry))) |
a06ea964 | 3368 | { |
d495ab0d | 3369 | _bfd_elf_link_hash_table_free (abfd); |
a06ea964 NC |
3370 | return NULL; |
3371 | } | |
3372 | ||
1419bbe5 WN |
3373 | ret->loc_hash_table = htab_try_create (1024, |
3374 | elfNN_aarch64_local_htab_hash, | |
3375 | elfNN_aarch64_local_htab_eq, | |
3376 | NULL); | |
3377 | ret->loc_hash_memory = objalloc_create (); | |
3378 | if (!ret->loc_hash_table || !ret->loc_hash_memory) | |
3379 | { | |
d495ab0d | 3380 | elfNN_aarch64_link_hash_table_free (abfd); |
1419bbe5 WN |
3381 | return NULL; |
3382 | } | |
d495ab0d | 3383 | ret->root.root.hash_table_free = elfNN_aarch64_link_hash_table_free; |
1419bbe5 | 3384 | |
a06ea964 NC |
3385 | return &ret->root.root; |
3386 | } | |
3387 | ||
1d75a8e2 NC |
3388 | /* Perform relocation R_TYPE. Returns TRUE upon success, FALSE otherwise. */ |
3389 | ||
a06ea964 NC |
3390 | static bfd_boolean |
3391 | aarch64_relocate (unsigned int r_type, bfd *input_bfd, asection *input_section, | |
3392 | bfd_vma offset, bfd_vma value) | |
3393 | { | |
3394 | reloc_howto_type *howto; | |
3395 | bfd_vma place; | |
3396 | ||
0aa13fee | 3397 | howto = elfNN_aarch64_howto_from_type (input_bfd, r_type); |
a06ea964 NC |
3398 | place = (input_section->output_section->vma + input_section->output_offset |
3399 | + offset); | |
caed7120 | 3400 | |
0aa13fee | 3401 | r_type = elfNN_aarch64_bfd_reloc_from_type (input_bfd, r_type); |
652afeef TC |
3402 | value = _bfd_aarch64_elf_resolve_relocation (input_bfd, r_type, place, |
3403 | value, 0, FALSE); | |
caed7120 YZ |
3404 | return _bfd_aarch64_elf_put_addend (input_bfd, |
3405 | input_section->contents + offset, r_type, | |
1d75a8e2 | 3406 | howto, value) == bfd_reloc_ok; |
a06ea964 NC |
3407 | } |
3408 | ||
50e192f0 SP |
3409 | /* Return interworking stub for a relocation. */ |
3410 | ||
3411 | static enum elf_aarch64_stub_type | |
3412 | aarch64_interwork_stub (unsigned int r_type, | |
3413 | bfd_boolean branch_to_c64) | |
3414 | { | |
3415 | switch (r_type) | |
3416 | { | |
3417 | case MORELLO_R (JUMP26): | |
3418 | case MORELLO_R (CALL26): | |
3419 | if (!branch_to_c64) | |
3420 | return c64_stub_branch_aarch64; | |
3421 | break; | |
3422 | case AARCH64_R (JUMP26): | |
3423 | case AARCH64_R (CALL26): | |
3424 | if (branch_to_c64) | |
3425 | return aarch64_stub_branch_c64; | |
3426 | break; | |
3427 | default: | |
3428 | break; | |
3429 | } | |
3430 | ||
3431 | return aarch64_stub_none; | |
3432 | } | |
3433 | ||
cec5225b | 3434 | static enum elf_aarch64_stub_type |
a06ea964 NC |
3435 | aarch64_select_branch_stub (bfd_vma value, bfd_vma place) |
3436 | { | |
3437 | if (aarch64_valid_for_adrp_p (value, place)) | |
3438 | return aarch64_stub_adrp_branch; | |
3439 | return aarch64_stub_long_branch; | |
3440 | } | |
3441 | ||
3442 | /* Determine the type of stub needed, if any, for a call. */ | |
3443 | ||
cec5225b | 3444 | static enum elf_aarch64_stub_type |
9a228467 | 3445 | aarch64_type_of_stub (asection *input_sec, |
a06ea964 | 3446 | const Elf_Internal_Rela *rel, |
f678ded7 | 3447 | asection *sym_sec, |
a06ea964 | 3448 | unsigned char st_type, |
a06ea964 NC |
3449 | bfd_vma destination) |
3450 | { | |
3451 | bfd_vma location; | |
3452 | bfd_signed_vma branch_offset; | |
50e192f0 | 3453 | unsigned int r_type = ELFNN_R_TYPE (rel->r_info); |
cec5225b | 3454 | enum elf_aarch64_stub_type stub_type = aarch64_stub_none; |
a06ea964 | 3455 | |
f678ded7 | 3456 | if (st_type != STT_FUNC |
2f340668 | 3457 | && (sym_sec == input_sec)) |
a06ea964 NC |
3458 | return stub_type; |
3459 | ||
a06ea964 NC |
3460 | /* Determine where the call point is. */ |
3461 | location = (input_sec->output_offset | |
3462 | + input_sec->output_section->vma + rel->r_offset); | |
3463 | ||
3464 | branch_offset = (bfd_signed_vma) (destination - location); | |
3465 | ||
50e192f0 SP |
3466 | /* For A64 <-> C64 branches we only come here for jumps to PLT. Treat them |
3467 | as regular branches and leave the interworking to PLT. */ | |
3468 | if (branch_offset > AARCH64_MAX_FWD_BRANCH_OFFSET | |
3469 | || branch_offset < AARCH64_MAX_BWD_BRANCH_OFFSET) | |
a06ea964 | 3470 | { |
50e192f0 SP |
3471 | switch (r_type) |
3472 | { | |
3473 | /* We don't want to redirect any old unconditional jump in this way, | |
3474 | only one which is being used for a sibcall, where it is | |
3475 | acceptable for the IP0 and IP1 registers to be clobbered. */ | |
3476 | case AARCH64_R (CALL26): | |
3477 | case AARCH64_R (JUMP26): | |
3478 | return aarch64_stub_long_branch; | |
3479 | case MORELLO_R (CALL26): | |
3480 | case MORELLO_R (JUMP26): | |
3481 | return c64_stub_branch_c64; | |
3482 | default: | |
3483 | break; | |
3484 | } | |
a06ea964 NC |
3485 | } |
3486 | ||
50e192f0 SP |
3487 | return aarch64_stub_none; |
3488 | } | |
3489 | ||
3490 | /* Return a string to add as suffix to a veneer name. */ | |
3491 | ||
3492 | static const char * | |
3493 | aarch64_lookup_stub_type_suffix (enum elf_aarch64_stub_type stub_type) | |
3494 | { | |
3495 | switch (stub_type) | |
3496 | { | |
3497 | case aarch64_stub_branch_c64: | |
3498 | return "_a64c64"; | |
3499 | case c64_stub_branch_aarch64: | |
3500 | return "_c64a64"; | |
3501 | break; | |
3502 | default: | |
3503 | return ""; | |
3504 | } | |
a06ea964 NC |
3505 | } |
3506 | ||
3507 | /* Build a name for an entry in the stub hash table. */ | |
3508 | ||
3509 | static char * | |
cec5225b | 3510 | elfNN_aarch64_stub_name (const asection *input_section, |
a06ea964 | 3511 | const asection *sym_sec, |
cec5225b | 3512 | const struct elf_aarch64_link_hash_entry *hash, |
50e192f0 SP |
3513 | const Elf_Internal_Rela *rel, |
3514 | enum elf_aarch64_stub_type stub_type) | |
a06ea964 NC |
3515 | { |
3516 | char *stub_name; | |
3517 | bfd_size_type len; | |
50e192f0 | 3518 | const char *suffix = aarch64_lookup_stub_type_suffix (stub_type);; |
a06ea964 NC |
3519 | |
3520 | if (hash) | |
3521 | { | |
3522 | len = 8 + 1 + strlen (hash->root.root.root.string) + 1 + 16 + 1; | |
3523 | stub_name = bfd_malloc (len); | |
3524 | if (stub_name != NULL) | |
50e192f0 | 3525 | snprintf (stub_name, len, "%08x_%s%s+%" BFD_VMA_FMT "x", |
a06ea964 NC |
3526 | (unsigned int) input_section->id, |
3527 | hash->root.root.root.string, | |
50e192f0 | 3528 | suffix, rel->r_addend); |
a06ea964 NC |
3529 | } |
3530 | else | |
3531 | { | |
3532 | len = 8 + 1 + 8 + 1 + 8 + 1 + 16 + 1; | |
3533 | stub_name = bfd_malloc (len); | |
3534 | if (stub_name != NULL) | |
50e192f0 | 3535 | snprintf (stub_name, len, "%08x_%x:%x%s+%" BFD_VMA_FMT "x", |
a06ea964 NC |
3536 | (unsigned int) input_section->id, |
3537 | (unsigned int) sym_sec->id, | |
cec5225b | 3538 | (unsigned int) ELFNN_R_SYM (rel->r_info), |
50e192f0 | 3539 | suffix, rel->r_addend); |
a06ea964 NC |
3540 | } |
3541 | ||
3542 | return stub_name; | |
3543 | } | |
3544 | ||
7f784814 JW |
3545 | /* Return TRUE if symbol H should be hashed in the `.gnu.hash' section. For |
3546 | executable PLT slots where the executable never takes the address of those | |
3547 | functions, the function symbols are not added to the hash table. */ | |
3548 | ||
3549 | static bfd_boolean | |
3550 | elf_aarch64_hash_symbol (struct elf_link_hash_entry *h) | |
3551 | { | |
3552 | if (h->plt.offset != (bfd_vma) -1 | |
3553 | && !h->def_regular | |
3554 | && !h->pointer_equality_needed) | |
3555 | return FALSE; | |
3556 | ||
3557 | return _bfd_elf_hash_symbol (h); | |
3558 | } | |
3559 | ||
a06ea964 NC |
3560 | /* Look up an entry in the stub hash. Stub entries are cached because |
3561 | creating the stub name takes a bit of time. */ | |
3562 | ||
cec5225b YZ |
3563 | static struct elf_aarch64_stub_hash_entry * |
3564 | elfNN_aarch64_get_stub_entry (const asection *input_section, | |
a06ea964 NC |
3565 | const asection *sym_sec, |
3566 | struct elf_link_hash_entry *hash, | |
3567 | const Elf_Internal_Rela *rel, | |
50e192f0 SP |
3568 | struct elf_aarch64_link_hash_table *htab, |
3569 | enum elf_aarch64_stub_type stub_type) | |
a06ea964 | 3570 | { |
cec5225b YZ |
3571 | struct elf_aarch64_stub_hash_entry *stub_entry; |
3572 | struct elf_aarch64_link_hash_entry *h = | |
3573 | (struct elf_aarch64_link_hash_entry *) hash; | |
a06ea964 NC |
3574 | const asection *id_sec; |
3575 | ||
3576 | if ((input_section->flags & SEC_CODE) == 0) | |
3577 | return NULL; | |
3578 | ||
3579 | /* If this input section is part of a group of sections sharing one | |
3580 | stub section, then use the id of the first section in the group. | |
3581 | Stub names need to include a section id, as there may well be | |
3582 | more than one stub used to reach say, printf, and we need to | |
3583 | distinguish between them. */ | |
3584 | id_sec = htab->stub_group[input_section->id].link_sec; | |
3585 | ||
3586 | if (h != NULL && h->stub_cache != NULL | |
3587 | && h->stub_cache->h == h && h->stub_cache->id_sec == id_sec) | |
3588 | { | |
3589 | stub_entry = h->stub_cache; | |
3590 | } | |
3591 | else | |
3592 | { | |
3593 | char *stub_name; | |
3594 | ||
50e192f0 | 3595 | stub_name = elfNN_aarch64_stub_name (id_sec, sym_sec, h, rel, stub_type); |
a06ea964 NC |
3596 | if (stub_name == NULL) |
3597 | return NULL; | |
3598 | ||
3599 | stub_entry = aarch64_stub_hash_lookup (&htab->stub_hash_table, | |
3600 | stub_name, FALSE, FALSE); | |
3601 | if (h != NULL) | |
3602 | h->stub_cache = stub_entry; | |
3603 | ||
3604 | free (stub_name); | |
3605 | } | |
3606 | ||
3607 | return stub_entry; | |
3608 | } | |
3609 | ||
a06ea964 | 3610 | |
66585675 MS |
3611 | /* Create a stub section. */ |
3612 | ||
3613 | static asection * | |
3614 | _bfd_aarch64_create_stub_section (asection *section, | |
3615 | struct elf_aarch64_link_hash_table *htab) | |
3616 | { | |
3617 | size_t namelen; | |
3618 | bfd_size_type len; | |
3619 | char *s_name; | |
3620 | ||
3621 | namelen = strlen (section->name); | |
3622 | len = namelen + sizeof (STUB_SUFFIX); | |
3623 | s_name = bfd_alloc (htab->stub_bfd, len); | |
3624 | if (s_name == NULL) | |
3625 | return NULL; | |
3626 | ||
3627 | memcpy (s_name, section->name, namelen); | |
3628 | memcpy (s_name + namelen, STUB_SUFFIX, sizeof (STUB_SUFFIX)); | |
3629 | return (*htab->add_stub_section) (s_name, section); | |
3630 | } | |
3631 | ||
3632 | ||
fc6d53be MS |
3633 | /* Find or create a stub section for a link section. |
3634 | ||
3635 | Fix or create the stub section used to collect stubs attached to | |
3636 | the specified link section. */ | |
3637 | ||
3638 | static asection * | |
3639 | _bfd_aarch64_get_stub_for_link_section (asection *link_section, | |
3640 | struct elf_aarch64_link_hash_table *htab) | |
3641 | { | |
3642 | if (htab->stub_group[link_section->id].stub_sec == NULL) | |
3643 | htab->stub_group[link_section->id].stub_sec | |
3644 | = _bfd_aarch64_create_stub_section (link_section, htab); | |
3645 | return htab->stub_group[link_section->id].stub_sec; | |
3646 | } | |
3647 | ||
3648 | ||
ef857521 MS |
3649 | /* Find or create a stub section in the stub group for an input |
3650 | section. */ | |
3651 | ||
3652 | static asection * | |
3653 | _bfd_aarch64_create_or_find_stub_sec (asection *section, | |
3654 | struct elf_aarch64_link_hash_table *htab) | |
a06ea964 | 3655 | { |
fc6d53be MS |
3656 | asection *link_sec = htab->stub_group[section->id].link_sec; |
3657 | return _bfd_aarch64_get_stub_for_link_section (link_sec, htab); | |
ef857521 MS |
3658 | } |
3659 | ||
3660 | ||
3661 | /* Add a new stub entry in the stub group associated with an input | |
3662 | section to the stub hash. Not all fields of the new stub entry are | |
3663 | initialised. */ | |
3664 | ||
3665 | static struct elf_aarch64_stub_hash_entry * | |
3666 | _bfd_aarch64_add_stub_entry_in_group (const char *stub_name, | |
3667 | asection *section, | |
3668 | struct elf_aarch64_link_hash_table *htab) | |
3669 | { | |
3670 | asection *link_sec; | |
3671 | asection *stub_sec; | |
3672 | struct elf_aarch64_stub_hash_entry *stub_entry; | |
3673 | ||
3674 | link_sec = htab->stub_group[section->id].link_sec; | |
3675 | stub_sec = _bfd_aarch64_create_or_find_stub_sec (section, htab); | |
3676 | ||
a06ea964 NC |
3677 | /* Enter this entry into the linker stub hash table. */ |
3678 | stub_entry = aarch64_stub_hash_lookup (&htab->stub_hash_table, stub_name, | |
3679 | TRUE, FALSE); | |
3680 | if (stub_entry == NULL) | |
3681 | { | |
695344c0 | 3682 | /* xgettext:c-format */ |
871b3ab2 | 3683 | _bfd_error_handler (_("%pB: cannot create stub entry %s"), |
4eca0228 | 3684 | section->owner, stub_name); |
a06ea964 NC |
3685 | return NULL; |
3686 | } | |
3687 | ||
3688 | stub_entry->stub_sec = stub_sec; | |
3689 | stub_entry->stub_offset = 0; | |
3690 | stub_entry->id_sec = link_sec; | |
3691 | ||
3692 | return stub_entry; | |
3693 | } | |
3694 | ||
4106101c MS |
3695 | /* Add a new stub entry in the final stub section to the stub hash. |
3696 | Not all fields of the new stub entry are initialised. */ | |
3697 | ||
3698 | static struct elf_aarch64_stub_hash_entry * | |
3699 | _bfd_aarch64_add_stub_entry_after (const char *stub_name, | |
3700 | asection *link_section, | |
3701 | struct elf_aarch64_link_hash_table *htab) | |
3702 | { | |
3703 | asection *stub_sec; | |
3704 | struct elf_aarch64_stub_hash_entry *stub_entry; | |
3705 | ||
739b5c9c TC |
3706 | stub_sec = NULL; |
3707 | /* Only create the actual stub if we will end up needing it. */ | |
3708 | if (htab->fix_erratum_843419 & ERRAT_ADRP) | |
3709 | stub_sec = _bfd_aarch64_get_stub_for_link_section (link_section, htab); | |
4106101c MS |
3710 | stub_entry = aarch64_stub_hash_lookup (&htab->stub_hash_table, stub_name, |
3711 | TRUE, FALSE); | |
3712 | if (stub_entry == NULL) | |
3713 | { | |
4eca0228 | 3714 | _bfd_error_handler (_("cannot create stub entry %s"), stub_name); |
4106101c MS |
3715 | return NULL; |
3716 | } | |
3717 | ||
3718 | stub_entry->stub_sec = stub_sec; | |
3719 | stub_entry->stub_offset = 0; | |
3720 | stub_entry->id_sec = link_section; | |
3721 | ||
3722 | return stub_entry; | |
3723 | } | |
3724 | ||
3725 | ||
a06ea964 NC |
3726 | static bfd_boolean |
3727 | aarch64_build_one_stub (struct bfd_hash_entry *gen_entry, | |
abf874aa | 3728 | void *in_arg) |
a06ea964 | 3729 | { |
cec5225b | 3730 | struct elf_aarch64_stub_hash_entry *stub_entry; |
a06ea964 NC |
3731 | asection *stub_sec; |
3732 | bfd *stub_bfd; | |
3733 | bfd_byte *loc; | |
3734 | bfd_vma sym_value; | |
68fcca92 JW |
3735 | bfd_vma veneered_insn_loc; |
3736 | bfd_vma veneer_entry_loc; | |
3737 | bfd_signed_vma branch_offset = 0; | |
a06ea964 NC |
3738 | unsigned int template_size; |
3739 | const uint32_t *template; | |
3740 | unsigned int i; | |
abf874aa | 3741 | struct bfd_link_info *info; |
a06ea964 NC |
3742 | |
3743 | /* Massage our args to the form they really have. */ | |
cec5225b | 3744 | stub_entry = (struct elf_aarch64_stub_hash_entry *) gen_entry; |
a06ea964 | 3745 | |
abf874aa CL |
3746 | info = (struct bfd_link_info *) in_arg; |
3747 | ||
3748 | /* Fail if the target section could not be assigned to an output | |
3749 | section. The user should fix his linker script. */ | |
3750 | if (stub_entry->target_section->output_section == NULL | |
3751 | && info->non_contiguous_regions) | |
53215f21 CL |
3752 | info->callbacks->einfo (_("%F%P: Could not assign '%pA' to an output section. " |
3753 | "Retry without " | |
3754 | "--enable-non-contiguous-regions.\n"), | |
3755 | stub_entry->target_section); | |
abf874aa | 3756 | |
a06ea964 NC |
3757 | stub_sec = stub_entry->stub_sec; |
3758 | ||
3759 | /* Make a note of the offset within the stubs for this entry. */ | |
3760 | stub_entry->stub_offset = stub_sec->size; | |
3761 | loc = stub_sec->contents + stub_entry->stub_offset; | |
3762 | ||
3763 | stub_bfd = stub_sec->owner; | |
3764 | ||
3765 | /* This is the address of the stub destination. */ | |
3766 | sym_value = (stub_entry->target_value | |
3767 | + stub_entry->target_section->output_offset | |
3768 | + stub_entry->target_section->output_section->vma); | |
3769 | ||
50e192f0 SP |
3770 | bfd_vma place = (stub_entry->stub_offset + stub_sec->output_section->vma |
3771 | + stub_sec->output_offset); | |
3772 | ||
a06ea964 NC |
3773 | if (stub_entry->stub_type == aarch64_stub_long_branch) |
3774 | { | |
a06ea964 NC |
3775 | /* See if we can relax the stub. */ |
3776 | if (aarch64_valid_for_adrp_p (sym_value, place)) | |
3777 | stub_entry->stub_type = aarch64_select_branch_stub (sym_value, place); | |
3778 | } | |
3779 | ||
50e192f0 SP |
3780 | if ((stub_entry->stub_type == aarch64_stub_branch_c64 |
3781 | || stub_entry->stub_type == c64_stub_branch_aarch64 | |
3782 | || stub_entry->stub_type == c64_stub_branch_c64) | |
3783 | && !c64_valid_for_adrp_p (sym_value, place)) | |
3784 | { | |
3785 | _bfd_error_handler | |
3786 | (_("%s: stub target out of range for %s branch"), | |
3787 | stub_entry->output_name, | |
3788 | (stub_entry->stub_type == aarch64_stub_branch_c64 | |
3789 | ? "A64 to C64" : "C64 to A64")); | |
3790 | bfd_set_error (bfd_error_bad_value); | |
3791 | return FALSE; | |
3792 | } | |
3793 | ||
a06ea964 NC |
3794 | switch (stub_entry->stub_type) |
3795 | { | |
3796 | case aarch64_stub_adrp_branch: | |
3797 | template = aarch64_adrp_branch_stub; | |
3798 | template_size = sizeof (aarch64_adrp_branch_stub); | |
3799 | break; | |
3800 | case aarch64_stub_long_branch: | |
3801 | template = aarch64_long_branch_stub; | |
3802 | template_size = sizeof (aarch64_long_branch_stub); | |
3803 | break; | |
68fcca92 JW |
3804 | case aarch64_stub_erratum_835769_veneer: |
3805 | template = aarch64_erratum_835769_stub; | |
3806 | template_size = sizeof (aarch64_erratum_835769_stub); | |
3807 | break; | |
4106101c MS |
3808 | case aarch64_stub_erratum_843419_veneer: |
3809 | template = aarch64_erratum_843419_stub; | |
3810 | template_size = sizeof (aarch64_erratum_843419_stub); | |
3811 | break; | |
50e192f0 SP |
3812 | case aarch64_stub_branch_c64: |
3813 | template = aarch64_c64_branch_stub; | |
3814 | template_size = sizeof (aarch64_c64_branch_stub); | |
3815 | break; | |
3816 | case c64_stub_branch_aarch64: | |
3817 | case c64_stub_branch_c64: | |
3818 | template = c64_aarch64_branch_stub; | |
3819 | template_size = sizeof (c64_aarch64_branch_stub); | |
3820 | break; | |
a06ea964 | 3821 | default: |
8e2fe09f | 3822 | abort (); |
a06ea964 NC |
3823 | } |
3824 | ||
3825 | for (i = 0; i < (template_size / sizeof template[0]); i++) | |
3826 | { | |
3827 | bfd_putl32 (template[i], loc); | |
3828 | loc += 4; | |
3829 | } | |
3830 | ||
3831 | template_size = (template_size + 7) & ~7; | |
3832 | stub_sec->size += template_size; | |
3833 | ||
50e192f0 SP |
3834 | bfd_vma stub_offset = stub_entry->stub_offset; |
3835 | ||
a06ea964 NC |
3836 | switch (stub_entry->stub_type) |
3837 | { | |
3838 | case aarch64_stub_adrp_branch: | |
1d75a8e2 NC |
3839 | if (!aarch64_relocate (AARCH64_R (ADR_PREL_PG_HI21), stub_bfd, stub_sec, |
3840 | stub_entry->stub_offset, sym_value)) | |
a06ea964 NC |
3841 | /* The stub would not have been relaxed if the offset was out |
3842 | of range. */ | |
3843 | BFD_FAIL (); | |
3844 | ||
1d75a8e2 NC |
3845 | if (!aarch64_relocate (AARCH64_R (ADD_ABS_LO12_NC), stub_bfd, stub_sec, |
3846 | stub_entry->stub_offset + 4, sym_value)) | |
93ca8569 | 3847 | BFD_FAIL (); |
a06ea964 NC |
3848 | break; |
3849 | ||
3850 | case aarch64_stub_long_branch: | |
3851 | /* We want the value relative to the address 12 bytes back from the | |
07d6d2b8 | 3852 | value itself. */ |
1d75a8e2 NC |
3853 | if (!aarch64_relocate (AARCH64_R (PRELNN), stub_bfd, stub_sec, |
3854 | stub_entry->stub_offset + 16, sym_value + 12)) | |
93ca8569 | 3855 | BFD_FAIL (); |
a06ea964 | 3856 | break; |
68fcca92 JW |
3857 | |
3858 | case aarch64_stub_erratum_835769_veneer: | |
3859 | veneered_insn_loc = stub_entry->target_section->output_section->vma | |
3860 | + stub_entry->target_section->output_offset | |
3861 | + stub_entry->target_value; | |
3862 | veneer_entry_loc = stub_entry->stub_sec->output_section->vma | |
3863 | + stub_entry->stub_sec->output_offset | |
3864 | + stub_entry->stub_offset; | |
3865 | branch_offset = veneered_insn_loc - veneer_entry_loc; | |
3866 | branch_offset >>= 2; | |
3867 | branch_offset &= 0x3ffffff; | |
3868 | bfd_putl32 (stub_entry->veneered_insn, | |
3869 | stub_sec->contents + stub_entry->stub_offset); | |
3870 | bfd_putl32 (template[1] | branch_offset, | |
3871 | stub_sec->contents + stub_entry->stub_offset + 4); | |
3872 | break; | |
3873 | ||
4106101c | 3874 | case aarch64_stub_erratum_843419_veneer: |
1d75a8e2 NC |
3875 | if (!aarch64_relocate (AARCH64_R (JUMP26), stub_bfd, stub_sec, |
3876 | stub_entry->stub_offset + 4, sym_value + 4)) | |
4106101c MS |
3877 | BFD_FAIL (); |
3878 | break; | |
3879 | ||
50e192f0 SP |
3880 | case aarch64_stub_branch_c64: |
3881 | stub_offset += 4; | |
3882 | /* Fall through. */ | |
3883 | case c64_stub_branch_aarch64: | |
3884 | case c64_stub_branch_c64: | |
3885 | if (!aarch64_relocate (R_MORELLO_ADR_PREL_PG_HI20, stub_bfd, stub_sec, | |
3886 | stub_offset, sym_value)) | |
3887 | /* We fail early if offset is out of range. */ | |
3888 | BFD_FAIL (); | |
3889 | ||
3890 | if (!aarch64_relocate (AARCH64_R (ADD_ABS_LO12_NC), stub_bfd, stub_sec, | |
3891 | stub_offset + 4, sym_value)) | |
3892 | BFD_FAIL (); | |
3893 | break; | |
3894 | ||
a06ea964 | 3895 | default: |
8e2fe09f | 3896 | abort (); |
a06ea964 NC |
3897 | } |
3898 | ||
3899 | return TRUE; | |
3900 | } | |
3901 | ||
3902 | /* As above, but don't actually build the stub. Just bump offset so | |
3903 | we know stub section sizes. */ | |
3904 | ||
3905 | static bfd_boolean | |
739b5c9c | 3906 | aarch64_size_one_stub (struct bfd_hash_entry *gen_entry, void *in_arg) |
a06ea964 | 3907 | { |
cec5225b | 3908 | struct elf_aarch64_stub_hash_entry *stub_entry; |
739b5c9c | 3909 | struct elf_aarch64_link_hash_table *htab; |
a06ea964 NC |
3910 | int size; |
3911 | ||
3912 | /* Massage our args to the form they really have. */ | |
cec5225b | 3913 | stub_entry = (struct elf_aarch64_stub_hash_entry *) gen_entry; |
739b5c9c | 3914 | htab = (struct elf_aarch64_link_hash_table *) in_arg; |
a06ea964 NC |
3915 | |
3916 | switch (stub_entry->stub_type) | |
3917 | { | |
3918 | case aarch64_stub_adrp_branch: | |
3919 | size = sizeof (aarch64_adrp_branch_stub); | |
3920 | break; | |
3921 | case aarch64_stub_long_branch: | |
3922 | size = sizeof (aarch64_long_branch_stub); | |
3923 | break; | |
68fcca92 JW |
3924 | case aarch64_stub_erratum_835769_veneer: |
3925 | size = sizeof (aarch64_erratum_835769_stub); | |
3926 | break; | |
4106101c | 3927 | case aarch64_stub_erratum_843419_veneer: |
739b5c9c TC |
3928 | { |
3929 | if (htab->fix_erratum_843419 == ERRAT_ADR) | |
3930 | return TRUE; | |
3931 | size = sizeof (aarch64_erratum_843419_stub); | |
3932 | } | |
4106101c | 3933 | break; |
50e192f0 SP |
3934 | case aarch64_stub_branch_c64: |
3935 | size = sizeof (aarch64_c64_branch_stub); | |
3936 | break; | |
3937 | case c64_stub_branch_aarch64: | |
3938 | case c64_stub_branch_c64: | |
3939 | size = sizeof (c64_aarch64_branch_stub); | |
3940 | break; | |
a06ea964 | 3941 | default: |
8e2fe09f | 3942 | abort (); |
a06ea964 NC |
3943 | } |
3944 | ||
3945 | size = (size + 7) & ~7; | |
3946 | stub_entry->stub_sec->size += size; | |
3947 | return TRUE; | |
3948 | } | |
3949 | ||
3950 | /* External entry points for sizing and building linker stubs. */ | |
3951 | ||
3952 | /* Set up various things so that we can make a list of input sections | |
3953 | for each output section included in the link. Returns -1 on error, | |
3954 | 0 when no stubs will be needed, and 1 on success. */ | |
3955 | ||
3956 | int | |
cec5225b | 3957 | elfNN_aarch64_setup_section_lists (bfd *output_bfd, |
a06ea964 NC |
3958 | struct bfd_link_info *info) |
3959 | { | |
3960 | bfd *input_bfd; | |
3961 | unsigned int bfd_count; | |
7292b3ac | 3962 | unsigned int top_id, top_index; |
a06ea964 NC |
3963 | asection *section; |
3964 | asection **input_list, **list; | |
986f0783 | 3965 | size_t amt; |
cec5225b YZ |
3966 | struct elf_aarch64_link_hash_table *htab = |
3967 | elf_aarch64_hash_table (info); | |
a06ea964 NC |
3968 | |
3969 | if (!is_elf_hash_table (htab)) | |
3970 | return 0; | |
3971 | ||
3972 | /* Count the number of input BFDs and find the top input section id. */ | |
3973 | for (input_bfd = info->input_bfds, bfd_count = 0, top_id = 0; | |
c72f2fb2 | 3974 | input_bfd != NULL; input_bfd = input_bfd->link.next) |
a06ea964 NC |
3975 | { |
3976 | bfd_count += 1; | |
3977 | for (section = input_bfd->sections; | |
3978 | section != NULL; section = section->next) | |
3979 | { | |
3980 | if (top_id < section->id) | |
3981 | top_id = section->id; | |
3982 | } | |
3983 | } | |
3984 | htab->bfd_count = bfd_count; | |
3985 | ||
3986 | amt = sizeof (struct map_stub) * (top_id + 1); | |
3987 | htab->stub_group = bfd_zmalloc (amt); | |
3988 | if (htab->stub_group == NULL) | |
3989 | return -1; | |
3990 | ||
3991 | /* We can't use output_bfd->section_count here to find the top output | |
3992 | section index as some sections may have been removed, and | |
3993 | _bfd_strip_section_from_output doesn't renumber the indices. */ | |
3994 | for (section = output_bfd->sections, top_index = 0; | |
3995 | section != NULL; section = section->next) | |
3996 | { | |
3997 | if (top_index < section->index) | |
3998 | top_index = section->index; | |
3999 | } | |
4000 | ||
4001 | htab->top_index = top_index; | |
4002 | amt = sizeof (asection *) * (top_index + 1); | |
4003 | input_list = bfd_malloc (amt); | |
4004 | htab->input_list = input_list; | |
4005 | if (input_list == NULL) | |
4006 | return -1; | |
4007 | ||
4008 | /* For sections we aren't interested in, mark their entries with a | |
4009 | value we can check later. */ | |
4010 | list = input_list + top_index; | |
4011 | do | |
4012 | *list = bfd_abs_section_ptr; | |
4013 | while (list-- != input_list); | |
4014 | ||
4015 | for (section = output_bfd->sections; | |
4016 | section != NULL; section = section->next) | |
4017 | { | |
4018 | if ((section->flags & SEC_CODE) != 0) | |
4019 | input_list[section->index] = NULL; | |
4020 | } | |
4021 | ||
4022 | return 1; | |
4023 | } | |
4024 | ||
cec5225b | 4025 | /* Used by elfNN_aarch64_next_input_section and group_sections. */ |
a06ea964 NC |
4026 | #define PREV_SEC(sec) (htab->stub_group[(sec)->id].link_sec) |
4027 | ||
4028 | /* The linker repeatedly calls this function for each input section, | |
4029 | in the order that input sections are linked into output sections. | |
4030 | Build lists of input sections to determine groupings between which | |
4031 | we may insert linker stubs. */ | |
4032 | ||
4033 | void | |
cec5225b | 4034 | elfNN_aarch64_next_input_section (struct bfd_link_info *info, asection *isec) |
a06ea964 | 4035 | { |
cec5225b YZ |
4036 | struct elf_aarch64_link_hash_table *htab = |
4037 | elf_aarch64_hash_table (info); | |
a06ea964 NC |
4038 | |
4039 | if (isec->output_section->index <= htab->top_index) | |
4040 | { | |
4041 | asection **list = htab->input_list + isec->output_section->index; | |
4042 | ||
cff69cf4 | 4043 | if (*list != bfd_abs_section_ptr && (isec->flags & SEC_CODE) != 0) |
a06ea964 NC |
4044 | { |
4045 | /* Steal the link_sec pointer for our list. */ | |
4046 | /* This happens to make the list in reverse order, | |
4047 | which is what we want. */ | |
4048 | PREV_SEC (isec) = *list; | |
4049 | *list = isec; | |
4050 | } | |
4051 | } | |
4052 | } | |
4053 | ||
4054 | /* See whether we can group stub sections together. Grouping stub | |
4055 | sections may result in fewer stubs. More importantly, we need to | |
4056 | put all .init* and .fini* stubs at the beginning of the .init or | |
4057 | .fini output sections respectively, because glibc splits the | |
4058 | _init and _fini functions into multiple parts. Putting a stub in | |
4059 | the middle of a function is not a good idea. */ | |
4060 | ||
4061 | static void | |
cec5225b | 4062 | group_sections (struct elf_aarch64_link_hash_table *htab, |
a06ea964 | 4063 | bfd_size_type stub_group_size, |
cff69cf4 | 4064 | bfd_boolean stubs_always_after_branch) |
a06ea964 | 4065 | { |
cff69cf4 | 4066 | asection **list = htab->input_list; |
a06ea964 NC |
4067 | |
4068 | do | |
4069 | { | |
4070 | asection *tail = *list; | |
cff69cf4 | 4071 | asection *head; |
a06ea964 NC |
4072 | |
4073 | if (tail == bfd_abs_section_ptr) | |
4074 | continue; | |
4075 | ||
cff69cf4 WD |
4076 | /* Reverse the list: we must avoid placing stubs at the |
4077 | beginning of the section because the beginning of the text | |
4078 | section may be required for an interrupt vector in bare metal | |
4079 | code. */ | |
4080 | #define NEXT_SEC PREV_SEC | |
4081 | head = NULL; | |
a06ea964 | 4082 | while (tail != NULL) |
cff69cf4 WD |
4083 | { |
4084 | /* Pop from tail. */ | |
4085 | asection *item = tail; | |
4086 | tail = PREV_SEC (item); | |
4087 | ||
4088 | /* Push on head. */ | |
4089 | NEXT_SEC (item) = head; | |
4090 | head = item; | |
4091 | } | |
4092 | ||
4093 | while (head != NULL) | |
a06ea964 NC |
4094 | { |
4095 | asection *curr; | |
cff69cf4 WD |
4096 | asection *next; |
4097 | bfd_vma stub_group_start = head->output_offset; | |
4098 | bfd_vma end_of_next; | |
a06ea964 | 4099 | |
cff69cf4 WD |
4100 | curr = head; |
4101 | while (NEXT_SEC (curr) != NULL) | |
4102 | { | |
4103 | next = NEXT_SEC (curr); | |
4104 | end_of_next = next->output_offset + next->size; | |
4105 | if (end_of_next - stub_group_start >= stub_group_size) | |
4106 | /* End of NEXT is too far from start, so stop. */ | |
4107 | break; | |
4108 | /* Add NEXT to the group. */ | |
4109 | curr = next; | |
4110 | } | |
a06ea964 | 4111 | |
cff69cf4 | 4112 | /* OK, the size from the start to the start of CURR is less |
a06ea964 | 4113 | than stub_group_size and thus can be handled by one stub |
cff69cf4 | 4114 | section. (Or the head section is itself larger than |
a06ea964 NC |
4115 | stub_group_size, in which case we may be toast.) |
4116 | We should really be keeping track of the total size of | |
4117 | stubs added here, as stubs contribute to the final output | |
4118 | section size. */ | |
4119 | do | |
4120 | { | |
cff69cf4 | 4121 | next = NEXT_SEC (head); |
a06ea964 | 4122 | /* Set up this stub group. */ |
cff69cf4 | 4123 | htab->stub_group[head->id].link_sec = curr; |
a06ea964 | 4124 | } |
cff69cf4 | 4125 | while (head != curr && (head = next) != NULL); |
a06ea964 NC |
4126 | |
4127 | /* But wait, there's more! Input sections up to stub_group_size | |
cff69cf4 WD |
4128 | bytes after the stub section can be handled by it too. */ |
4129 | if (!stubs_always_after_branch) | |
a06ea964 | 4130 | { |
cff69cf4 WD |
4131 | stub_group_start = curr->output_offset + curr->size; |
4132 | ||
4133 | while (next != NULL) | |
a06ea964 | 4134 | { |
cff69cf4 WD |
4135 | end_of_next = next->output_offset + next->size; |
4136 | if (end_of_next - stub_group_start >= stub_group_size) | |
4137 | /* End of NEXT is too far from stubs, so stop. */ | |
4138 | break; | |
4139 | /* Add NEXT to the stub group. */ | |
4140 | head = next; | |
4141 | next = NEXT_SEC (head); | |
4142 | htab->stub_group[head->id].link_sec = curr; | |
a06ea964 NC |
4143 | } |
4144 | } | |
cff69cf4 | 4145 | head = next; |
a06ea964 NC |
4146 | } |
4147 | } | |
cff69cf4 | 4148 | while (list++ != htab->input_list + htab->top_index); |
a06ea964 NC |
4149 | |
4150 | free (htab->input_list); | |
4151 | } | |
4152 | ||
cff69cf4 | 4153 | #undef PREV_SEC |
a06ea964 NC |
4154 | #undef PREV_SEC |
4155 | ||
68fcca92 JW |
4156 | #define AARCH64_BITS(x, pos, n) (((x) >> (pos)) & ((1 << (n)) - 1)) |
4157 | ||
4158 | #define AARCH64_RT(insn) AARCH64_BITS (insn, 0, 5) | |
4159 | #define AARCH64_RT2(insn) AARCH64_BITS (insn, 10, 5) | |
4160 | #define AARCH64_RA(insn) AARCH64_BITS (insn, 10, 5) | |
4161 | #define AARCH64_RD(insn) AARCH64_BITS (insn, 0, 5) | |
4162 | #define AARCH64_RN(insn) AARCH64_BITS (insn, 5, 5) | |
4163 | #define AARCH64_RM(insn) AARCH64_BITS (insn, 16, 5) | |
4164 | ||
4165 | #define AARCH64_MAC(insn) (((insn) & 0xff000000) == 0x9b000000) | |
4166 | #define AARCH64_BIT(insn, n) AARCH64_BITS (insn, n, 1) | |
4167 | #define AARCH64_OP31(insn) AARCH64_BITS (insn, 21, 3) | |
4168 | #define AARCH64_ZR 0x1f | |
4169 | ||
4170 | /* All ld/st ops. See C4-182 of the ARM ARM. The encoding space for | |
4171 | LD_PCREL, LDST_RO, LDST_UI and LDST_UIMM cover prefetch ops. */ | |
4172 | ||
4173 | #define AARCH64_LD(insn) (AARCH64_BIT (insn, 22) == 1) | |
4174 | #define AARCH64_LDST(insn) (((insn) & 0x0a000000) == 0x08000000) | |
4175 | #define AARCH64_LDST_EX(insn) (((insn) & 0x3f000000) == 0x08000000) | |
4176 | #define AARCH64_LDST_PCREL(insn) (((insn) & 0x3b000000) == 0x18000000) | |
4177 | #define AARCH64_LDST_NAP(insn) (((insn) & 0x3b800000) == 0x28000000) | |
4178 | #define AARCH64_LDSTP_PI(insn) (((insn) & 0x3b800000) == 0x28800000) | |
4179 | #define AARCH64_LDSTP_O(insn) (((insn) & 0x3b800000) == 0x29000000) | |
4180 | #define AARCH64_LDSTP_PRE(insn) (((insn) & 0x3b800000) == 0x29800000) | |
4181 | #define AARCH64_LDST_UI(insn) (((insn) & 0x3b200c00) == 0x38000000) | |
4182 | #define AARCH64_LDST_PIIMM(insn) (((insn) & 0x3b200c00) == 0x38000400) | |
4183 | #define AARCH64_LDST_U(insn) (((insn) & 0x3b200c00) == 0x38000800) | |
4184 | #define AARCH64_LDST_PREIMM(insn) (((insn) & 0x3b200c00) == 0x38000c00) | |
4185 | #define AARCH64_LDST_RO(insn) (((insn) & 0x3b200c00) == 0x38200800) | |
4186 | #define AARCH64_LDST_UIMM(insn) (((insn) & 0x3b000000) == 0x39000000) | |
4187 | #define AARCH64_LDST_SIMD_M(insn) (((insn) & 0xbfbf0000) == 0x0c000000) | |
4188 | #define AARCH64_LDST_SIMD_M_PI(insn) (((insn) & 0xbfa00000) == 0x0c800000) | |
4189 | #define AARCH64_LDST_SIMD_S(insn) (((insn) & 0xbf9f0000) == 0x0d000000) | |
4190 | #define AARCH64_LDST_SIMD_S_PI(insn) (((insn) & 0xbf800000) == 0x0d800000) | |
4191 | ||
3d14faea MS |
4192 | /* Classify an INSN if it is indeed a load/store. |
4193 | ||
4194 | Return TRUE if INSN is a LD/ST instruction otherwise return FALSE. | |
4195 | ||
4196 | For scalar LD/ST instructions PAIR is FALSE, RT is returned and RT2 | |
4197 | is set equal to RT. | |
4198 | ||
2d0ca824 | 4199 | For LD/ST pair instructions PAIR is TRUE, RT and RT2 are returned. */ |
68fcca92 JW |
4200 | |
4201 | static bfd_boolean | |
3d14faea | 4202 | aarch64_mem_op_p (uint32_t insn, unsigned int *rt, unsigned int *rt2, |
68fcca92 JW |
4203 | bfd_boolean *pair, bfd_boolean *load) |
4204 | { | |
4205 | uint32_t opcode; | |
4206 | unsigned int r; | |
4207 | uint32_t opc = 0; | |
4208 | uint32_t v = 0; | |
4209 | uint32_t opc_v = 0; | |
4210 | ||
de194d85 | 4211 | /* Bail out quickly if INSN doesn't fall into the load-store |
68fcca92 JW |
4212 | encoding space. */ |
4213 | if (!AARCH64_LDST (insn)) | |
4214 | return FALSE; | |
4215 | ||
4216 | *pair = FALSE; | |
4217 | *load = FALSE; | |
4218 | if (AARCH64_LDST_EX (insn)) | |
4219 | { | |
4220 | *rt = AARCH64_RT (insn); | |
3d14faea | 4221 | *rt2 = *rt; |
68fcca92 | 4222 | if (AARCH64_BIT (insn, 21) == 1) |
07d6d2b8 | 4223 | { |
68fcca92 | 4224 | *pair = TRUE; |
3d14faea | 4225 | *rt2 = AARCH64_RT2 (insn); |
68fcca92 JW |
4226 | } |
4227 | *load = AARCH64_LD (insn); | |
4228 | return TRUE; | |
4229 | } | |
4230 | else if (AARCH64_LDST_NAP (insn) | |
4231 | || AARCH64_LDSTP_PI (insn) | |
4232 | || AARCH64_LDSTP_O (insn) | |
4233 | || AARCH64_LDSTP_PRE (insn)) | |
4234 | { | |
4235 | *pair = TRUE; | |
4236 | *rt = AARCH64_RT (insn); | |
3d14faea | 4237 | *rt2 = AARCH64_RT2 (insn); |
68fcca92 JW |
4238 | *load = AARCH64_LD (insn); |
4239 | return TRUE; | |
4240 | } | |
4241 | else if (AARCH64_LDST_PCREL (insn) | |
4242 | || AARCH64_LDST_UI (insn) | |
4243 | || AARCH64_LDST_PIIMM (insn) | |
4244 | || AARCH64_LDST_U (insn) | |
4245 | || AARCH64_LDST_PREIMM (insn) | |
4246 | || AARCH64_LDST_RO (insn) | |
4247 | || AARCH64_LDST_UIMM (insn)) | |
4248 | { | |
4249 | *rt = AARCH64_RT (insn); | |
3d14faea | 4250 | *rt2 = *rt; |
68fcca92 JW |
4251 | if (AARCH64_LDST_PCREL (insn)) |
4252 | *load = TRUE; | |
4253 | opc = AARCH64_BITS (insn, 22, 2); | |
4254 | v = AARCH64_BIT (insn, 26); | |
4255 | opc_v = opc | (v << 2); | |
4256 | *load = (opc_v == 1 || opc_v == 2 || opc_v == 3 | |
4257 | || opc_v == 5 || opc_v == 7); | |
4258 | return TRUE; | |
4259 | } | |
4260 | else if (AARCH64_LDST_SIMD_M (insn) | |
4261 | || AARCH64_LDST_SIMD_M_PI (insn)) | |
4262 | { | |
4263 | *rt = AARCH64_RT (insn); | |
4264 | *load = AARCH64_BIT (insn, 22); | |
4265 | opcode = (insn >> 12) & 0xf; | |
4266 | switch (opcode) | |
4267 | { | |
4268 | case 0: | |
4269 | case 2: | |
3d14faea | 4270 | *rt2 = *rt + 3; |
68fcca92 JW |
4271 | break; |
4272 | ||
4273 | case 4: | |
4274 | case 6: | |
3d14faea | 4275 | *rt2 = *rt + 2; |
68fcca92 JW |
4276 | break; |
4277 | ||
4278 | case 7: | |
3d14faea | 4279 | *rt2 = *rt; |
68fcca92 JW |
4280 | break; |
4281 | ||
4282 | case 8: | |
4283 | case 10: | |
3d14faea | 4284 | *rt2 = *rt + 1; |
68fcca92 JW |
4285 | break; |
4286 | ||
4287 | default: | |
4288 | return FALSE; | |
4289 | } | |
4290 | return TRUE; | |
4291 | } | |
4292 | else if (AARCH64_LDST_SIMD_S (insn) | |
4293 | || AARCH64_LDST_SIMD_S_PI (insn)) | |
4294 | { | |
4295 | *rt = AARCH64_RT (insn); | |
4296 | r = (insn >> 21) & 1; | |
4297 | *load = AARCH64_BIT (insn, 22); | |
4298 | opcode = (insn >> 13) & 0x7; | |
4299 | switch (opcode) | |
4300 | { | |
4301 | case 0: | |
4302 | case 2: | |
4303 | case 4: | |
3d14faea | 4304 | *rt2 = *rt + r; |
68fcca92 JW |
4305 | break; |
4306 | ||
4307 | case 1: | |
4308 | case 3: | |
4309 | case 5: | |
3d14faea | 4310 | *rt2 = *rt + (r == 0 ? 2 : 3); |
68fcca92 JW |
4311 | break; |
4312 | ||
4313 | case 6: | |
3d14faea | 4314 | *rt2 = *rt + r; |
68fcca92 JW |
4315 | break; |
4316 | ||
4317 | case 7: | |
3d14faea | 4318 | *rt2 = *rt + (r == 0 ? 2 : 3); |
68fcca92 JW |
4319 | break; |
4320 | ||
4321 | default: | |
4322 | return FALSE; | |
4323 | } | |
4324 | return TRUE; | |
4325 | } | |
4326 | ||
4327 | return FALSE; | |
4328 | } | |
4329 | ||
4330 | /* Return TRUE if INSN is multiply-accumulate. */ | |
4331 | ||
4332 | static bfd_boolean | |
4333 | aarch64_mlxl_p (uint32_t insn) | |
4334 | { | |
4335 | uint32_t op31 = AARCH64_OP31 (insn); | |
4336 | ||
4337 | if (AARCH64_MAC (insn) | |
4338 | && (op31 == 0 || op31 == 1 || op31 == 5) | |
4339 | /* Exclude MUL instructions which are encoded as a multiple accumulate | |
4340 | with RA = XZR. */ | |
4341 | && AARCH64_RA (insn) != AARCH64_ZR) | |
4342 | return TRUE; | |
4343 | ||
4344 | return FALSE; | |
4345 | } | |
4346 | ||
4347 | /* Some early revisions of the Cortex-A53 have an erratum (835769) whereby | |
4348 | it is possible for a 64-bit multiply-accumulate instruction to generate an | |
4349 | incorrect result. The details are quite complex and hard to | |
4350 | determine statically, since branches in the code may exist in some | |
4351 | circumstances, but all cases end with a memory (load, store, or | |
4352 | prefetch) instruction followed immediately by the multiply-accumulate | |
4353 | operation. We employ a linker patching technique, by moving the potentially | |
4354 | affected multiply-accumulate instruction into a patch region and replacing | |
4355 | the original instruction with a branch to the patch. This function checks | |
4356 | if INSN_1 is the memory operation followed by a multiply-accumulate | |
4357 | operation (INSN_2). Return TRUE if an erratum sequence is found, FALSE | |
4358 | if INSN_1 and INSN_2 are safe. */ | |
4359 | ||
4360 | static bfd_boolean | |
4361 | aarch64_erratum_sequence (uint32_t insn_1, uint32_t insn_2) | |
4362 | { | |
4363 | uint32_t rt; | |
3d14faea | 4364 | uint32_t rt2; |
68fcca92 JW |
4365 | uint32_t rn; |
4366 | uint32_t rm; | |
4367 | uint32_t ra; | |
4368 | bfd_boolean pair; | |
4369 | bfd_boolean load; | |
4370 | ||
4371 | if (aarch64_mlxl_p (insn_2) | |
3d14faea | 4372 | && aarch64_mem_op_p (insn_1, &rt, &rt2, &pair, &load)) |
68fcca92 JW |
4373 | { |
4374 | /* Any SIMD memory op is independent of the subsequent MLA | |
4375 | by definition of the erratum. */ | |
4376 | if (AARCH64_BIT (insn_1, 26)) | |
4377 | return TRUE; | |
4378 | ||
4379 | /* If not SIMD, check for integer memory ops and MLA relationship. */ | |
4380 | rn = AARCH64_RN (insn_2); | |
4381 | ra = AARCH64_RA (insn_2); | |
4382 | rm = AARCH64_RM (insn_2); | |
4383 | ||
4384 | /* If this is a load and there's a true(RAW) dependency, we are safe | |
4385 | and this is not an erratum sequence. */ | |
4386 | if (load && | |
4387 | (rt == rn || rt == rm || rt == ra | |
3d14faea | 4388 | || (pair && (rt2 == rn || rt2 == rm || rt2 == ra)))) |
68fcca92 JW |
4389 | return FALSE; |
4390 | ||
4391 | /* We conservatively put out stubs for all other cases (including | |
4392 | writebacks). */ | |
4393 | return TRUE; | |
4394 | } | |
4395 | ||
4396 | return FALSE; | |
4397 | } | |
4398 | ||
2144188d | 4399 | |
35fee8b7 MS |
4400 | static char * |
4401 | _bfd_aarch64_erratum_835769_stub_name (unsigned num_fixes) | |
4402 | { | |
4403 | char *stub_name = (char *) bfd_malloc | |
4404 | (strlen ("__erratum_835769_veneer_") + 16); | |
bb69498c NC |
4405 | if (stub_name != NULL) |
4406 | sprintf (stub_name,"__erratum_835769_veneer_%d", num_fixes); | |
35fee8b7 MS |
4407 | return stub_name; |
4408 | } | |
4409 | ||
4106101c | 4410 | /* Scan for Cortex-A53 erratum 835769 sequence. |
2144188d MS |
4411 | |
4412 | Return TRUE else FALSE on abnormal termination. */ | |
4413 | ||
68fcca92 | 4414 | static bfd_boolean |
5421cc6e MS |
4415 | _bfd_aarch64_erratum_835769_scan (bfd *input_bfd, |
4416 | struct bfd_link_info *info, | |
4417 | unsigned int *num_fixes_p) | |
68fcca92 JW |
4418 | { |
4419 | asection *section; | |
4420 | struct elf_aarch64_link_hash_table *htab = elf_aarch64_hash_table (info); | |
68fcca92 | 4421 | unsigned int num_fixes = *num_fixes_p; |
68fcca92 JW |
4422 | |
4423 | if (htab == NULL) | |
2144188d | 4424 | return TRUE; |
68fcca92 JW |
4425 | |
4426 | for (section = input_bfd->sections; | |
4427 | section != NULL; | |
4428 | section = section->next) | |
4429 | { | |
4430 | bfd_byte *contents = NULL; | |
4431 | struct _aarch64_elf_section_data *sec_data; | |
4432 | unsigned int span; | |
4433 | ||
4434 | if (elf_section_type (section) != SHT_PROGBITS | |
4435 | || (elf_section_flags (section) & SHF_EXECINSTR) == 0 | |
4436 | || (section->flags & SEC_EXCLUDE) != 0 | |
4437 | || (section->sec_info_type == SEC_INFO_TYPE_JUST_SYMS) | |
4438 | || (section->output_section == bfd_abs_section_ptr)) | |
4439 | continue; | |
4440 | ||
4441 | if (elf_section_data (section)->this_hdr.contents != NULL) | |
4442 | contents = elf_section_data (section)->this_hdr.contents; | |
4443 | else if (! bfd_malloc_and_get_section (input_bfd, section, &contents)) | |
2144188d | 4444 | return FALSE; |
68fcca92 JW |
4445 | |
4446 | sec_data = elf_aarch64_section_data (section); | |
520c7b56 | 4447 | |
ccf61261 NC |
4448 | if (sec_data->mapcount) |
4449 | qsort (sec_data->map, sec_data->mapcount, | |
4450 | sizeof (elf_aarch64_section_map), elf_aarch64_compare_mapping); | |
520c7b56 | 4451 | |
68fcca92 JW |
4452 | for (span = 0; span < sec_data->mapcount; span++) |
4453 | { | |
4454 | unsigned int span_start = sec_data->map[span].vma; | |
4455 | unsigned int span_end = ((span == sec_data->mapcount - 1) | |
4456 | ? sec_data->map[0].vma + section->size | |
4457 | : sec_data->map[span + 1].vma); | |
4458 | unsigned int i; | |
4459 | char span_type = sec_data->map[span].type; | |
4460 | ||
4461 | if (span_type == 'd') | |
4462 | continue; | |
4463 | ||
4464 | for (i = span_start; i + 4 < span_end; i += 4) | |
4465 | { | |
4466 | uint32_t insn_1 = bfd_getl32 (contents + i); | |
4467 | uint32_t insn_2 = bfd_getl32 (contents + i + 4); | |
4468 | ||
4469 | if (aarch64_erratum_sequence (insn_1, insn_2)) | |
4470 | { | |
5421cc6e | 4471 | struct elf_aarch64_stub_hash_entry *stub_entry; |
35fee8b7 MS |
4472 | char *stub_name = _bfd_aarch64_erratum_835769_stub_name (num_fixes); |
4473 | if (! stub_name) | |
2144188d | 4474 | return FALSE; |
68fcca92 | 4475 | |
5421cc6e MS |
4476 | stub_entry = _bfd_aarch64_add_stub_entry_in_group (stub_name, |
4477 | section, | |
4478 | htab); | |
4479 | if (! stub_entry) | |
4480 | return FALSE; | |
68fcca92 | 4481 | |
5421cc6e MS |
4482 | stub_entry->stub_type = aarch64_stub_erratum_835769_veneer; |
4483 | stub_entry->target_section = section; | |
4484 | stub_entry->target_value = i + 4; | |
4485 | stub_entry->veneered_insn = insn_2; | |
4486 | stub_entry->output_name = stub_name; | |
68fcca92 JW |
4487 | num_fixes++; |
4488 | } | |
4489 | } | |
4490 | } | |
4491 | if (elf_section_data (section)->this_hdr.contents == NULL) | |
4492 | free (contents); | |
4493 | } | |
4494 | ||
357d1523 MS |
4495 | *num_fixes_p = num_fixes; |
4496 | ||
2144188d | 4497 | return TRUE; |
68fcca92 JW |
4498 | } |
4499 | ||
13f622ec | 4500 | |
4106101c MS |
4501 | /* Test if instruction INSN is ADRP. */ |
4502 | ||
4503 | static bfd_boolean | |
4504 | _bfd_aarch64_adrp_p (uint32_t insn) | |
4505 | { | |
9fca35fc | 4506 | return ((insn & AARCH64_ADRP_OP_MASK) == AARCH64_ADRP_OP); |
4106101c MS |
4507 | } |
4508 | ||
4509 | ||
4510 | /* Helper predicate to look for cortex-a53 erratum 843419 sequence 1. */ | |
4511 | ||
4512 | static bfd_boolean | |
4513 | _bfd_aarch64_erratum_843419_sequence_p (uint32_t insn_1, uint32_t insn_2, | |
4514 | uint32_t insn_3) | |
4515 | { | |
4516 | uint32_t rt; | |
4517 | uint32_t rt2; | |
4518 | bfd_boolean pair; | |
4519 | bfd_boolean load; | |
4520 | ||
4521 | return (aarch64_mem_op_p (insn_2, &rt, &rt2, &pair, &load) | |
4522 | && (!pair | |
4523 | || (pair && !load)) | |
4524 | && AARCH64_LDST_UIMM (insn_3) | |
4525 | && AARCH64_RN (insn_3) == AARCH64_RD (insn_1)); | |
4526 | } | |
4527 | ||
4528 | ||
4529 | /* Test for the presence of Cortex-A53 erratum 843419 instruction sequence. | |
4530 | ||
4531 | Return TRUE if section CONTENTS at offset I contains one of the | |
4532 | erratum 843419 sequences, otherwise return FALSE. If a sequence is | |
4533 | seen set P_VENEER_I to the offset of the final LOAD/STORE | |
4534 | instruction in the sequence. | |
4535 | */ | |
4536 | ||
4537 | static bfd_boolean | |
4538 | _bfd_aarch64_erratum_843419_p (bfd_byte *contents, bfd_vma vma, | |
4539 | bfd_vma i, bfd_vma span_end, | |
4540 | bfd_vma *p_veneer_i) | |
4541 | { | |
4542 | uint32_t insn_1 = bfd_getl32 (contents + i); | |
4543 | ||
4544 | if (!_bfd_aarch64_adrp_p (insn_1)) | |
4545 | return FALSE; | |
4546 | ||
4547 | if (span_end < i + 12) | |
4548 | return FALSE; | |
4549 | ||
4550 | uint32_t insn_2 = bfd_getl32 (contents + i + 4); | |
4551 | uint32_t insn_3 = bfd_getl32 (contents + i + 8); | |
4552 | ||
4553 | if ((vma & 0xfff) != 0xff8 && (vma & 0xfff) != 0xffc) | |
4554 | return FALSE; | |
4555 | ||
4556 | if (_bfd_aarch64_erratum_843419_sequence_p (insn_1, insn_2, insn_3)) | |
4557 | { | |
4558 | *p_veneer_i = i + 8; | |
4559 | return TRUE; | |
4560 | } | |
4561 | ||
4562 | if (span_end < i + 16) | |
4563 | return FALSE; | |
4564 | ||
4565 | uint32_t insn_4 = bfd_getl32 (contents + i + 12); | |
4566 | ||
4567 | if (_bfd_aarch64_erratum_843419_sequence_p (insn_1, insn_2, insn_4)) | |
4568 | { | |
4569 | *p_veneer_i = i + 12; | |
4570 | return TRUE; | |
4571 | } | |
4572 | ||
4573 | return FALSE; | |
4574 | } | |
4575 | ||
4576 | ||
13f622ec MS |
4577 | /* Resize all stub sections. */ |
4578 | ||
4579 | static void | |
4580 | _bfd_aarch64_resize_stubs (struct elf_aarch64_link_hash_table *htab) | |
4581 | { | |
4582 | asection *section; | |
4583 | ||
4584 | /* OK, we've added some stubs. Find out the new size of the | |
4585 | stub sections. */ | |
4586 | for (section = htab->stub_bfd->sections; | |
4587 | section != NULL; section = section->next) | |
4588 | { | |
4589 | /* Ignore non-stub sections. */ | |
4590 | if (!strstr (section->name, STUB_SUFFIX)) | |
4591 | continue; | |
4592 | section->size = 0; | |
4593 | } | |
4594 | ||
4595 | bfd_hash_traverse (&htab->stub_hash_table, aarch64_size_one_stub, htab); | |
13f622ec | 4596 | |
61865519 MS |
4597 | for (section = htab->stub_bfd->sections; |
4598 | section != NULL; section = section->next) | |
4599 | { | |
4600 | if (!strstr (section->name, STUB_SUFFIX)) | |
4601 | continue; | |
4602 | ||
9a2ebffd JW |
4603 | /* Add space for a branch. Add 8 bytes to keep section 8 byte aligned, |
4604 | as long branch stubs contain a 64-bit address. */ | |
61865519 | 4605 | if (section->size) |
9a2ebffd | 4606 | section->size += 8; |
4106101c MS |
4607 | |
4608 | /* Ensure all stub sections have a size which is a multiple of | |
4609 | 4096. This is important in order to ensure that the insertion | |
4610 | of stub sections does not in itself move existing code around | |
739b5c9c TC |
4611 | in such a way that new errata sequences are created. We only do this |
4612 | when the ADRP workaround is enabled. If only the ADR workaround is | |
4613 | enabled then the stubs workaround won't ever be used. */ | |
4614 | if (htab->fix_erratum_843419 & ERRAT_ADRP) | |
4106101c MS |
4615 | if (section->size) |
4616 | section->size = BFD_ALIGN (section->size, 0x1000); | |
4617 | } | |
4618 | } | |
4619 | ||
9a2ebffd | 4620 | /* Construct an erratum 843419 workaround stub name. */ |
4106101c MS |
4621 | |
4622 | static char * | |
4623 | _bfd_aarch64_erratum_843419_stub_name (asection *input_section, | |
4624 | bfd_vma offset) | |
4625 | { | |
4626 | const bfd_size_type len = 8 + 4 + 1 + 8 + 1 + 16 + 1; | |
4627 | char *stub_name = bfd_malloc (len); | |
4628 | ||
4629 | if (stub_name != NULL) | |
4630 | snprintf (stub_name, len, "e843419@%04x_%08x_%" BFD_VMA_FMT "x", | |
4631 | input_section->owner->id, | |
4632 | input_section->id, | |
4633 | offset); | |
4634 | return stub_name; | |
4635 | } | |
4636 | ||
4637 | /* Build a stub_entry structure describing an 843419 fixup. | |
4638 | ||
4639 | The stub_entry constructed is populated with the bit pattern INSN | |
4640 | of the instruction located at OFFSET within input SECTION. | |
4641 | ||
4642 | Returns TRUE on success. */ | |
4643 | ||
4644 | static bfd_boolean | |
4645 | _bfd_aarch64_erratum_843419_fixup (uint32_t insn, | |
4646 | bfd_vma adrp_offset, | |
4647 | bfd_vma ldst_offset, | |
4648 | asection *section, | |
4649 | struct bfd_link_info *info) | |
4650 | { | |
4651 | struct elf_aarch64_link_hash_table *htab = elf_aarch64_hash_table (info); | |
4652 | char *stub_name; | |
4653 | struct elf_aarch64_stub_hash_entry *stub_entry; | |
4654 | ||
4655 | stub_name = _bfd_aarch64_erratum_843419_stub_name (section, ldst_offset); | |
bb69498c NC |
4656 | if (stub_name == NULL) |
4657 | return FALSE; | |
4106101c MS |
4658 | stub_entry = aarch64_stub_hash_lookup (&htab->stub_hash_table, stub_name, |
4659 | FALSE, FALSE); | |
4660 | if (stub_entry) | |
4661 | { | |
4662 | free (stub_name); | |
4663 | return TRUE; | |
4664 | } | |
4665 | ||
4666 | /* We always place an 843419 workaround veneer in the stub section | |
4667 | attached to the input section in which an erratum sequence has | |
4668 | been found. This ensures that later in the link process (in | |
4669 | elfNN_aarch64_write_section) when we copy the veneered | |
4670 | instruction from the input section into the stub section the | |
4671 | copied instruction will have had any relocations applied to it. | |
4672 | If we placed workaround veneers in any other stub section then we | |
4673 | could not assume that all relocations have been processed on the | |
4674 | corresponding input section at the point we output the stub | |
bb69498c | 4675 | section. */ |
4106101c MS |
4676 | |
4677 | stub_entry = _bfd_aarch64_add_stub_entry_after (stub_name, section, htab); | |
4678 | if (stub_entry == NULL) | |
4679 | { | |
4680 | free (stub_name); | |
4681 | return FALSE; | |
4682 | } | |
4683 | ||
4684 | stub_entry->adrp_offset = adrp_offset; | |
4685 | stub_entry->target_value = ldst_offset; | |
4686 | stub_entry->target_section = section; | |
4687 | stub_entry->stub_type = aarch64_stub_erratum_843419_veneer; | |
4688 | stub_entry->veneered_insn = insn; | |
4689 | stub_entry->output_name = stub_name; | |
4690 | ||
4691 | return TRUE; | |
4692 | } | |
4693 | ||
4694 | ||
4695 | /* Scan an input section looking for the signature of erratum 843419. | |
4696 | ||
4697 | Scans input SECTION in INPUT_BFD looking for erratum 843419 | |
4698 | signatures, for each signature found a stub_entry is created | |
4699 | describing the location of the erratum for subsequent fixup. | |
4700 | ||
4701 | Return TRUE on successful scan, FALSE on failure to scan. | |
4702 | */ | |
4703 | ||
4704 | static bfd_boolean | |
4705 | _bfd_aarch64_erratum_843419_scan (bfd *input_bfd, asection *section, | |
4706 | struct bfd_link_info *info) | |
4707 | { | |
4708 | struct elf_aarch64_link_hash_table *htab = elf_aarch64_hash_table (info); | |
4709 | ||
4710 | if (htab == NULL) | |
4711 | return TRUE; | |
4712 | ||
4713 | if (elf_section_type (section) != SHT_PROGBITS | |
4714 | || (elf_section_flags (section) & SHF_EXECINSTR) == 0 | |
4715 | || (section->flags & SEC_EXCLUDE) != 0 | |
4716 | || (section->sec_info_type == SEC_INFO_TYPE_JUST_SYMS) | |
4717 | || (section->output_section == bfd_abs_section_ptr)) | |
4718 | return TRUE; | |
4719 | ||
4720 | do | |
4721 | { | |
4722 | bfd_byte *contents = NULL; | |
4723 | struct _aarch64_elf_section_data *sec_data; | |
4724 | unsigned int span; | |
4725 | ||
4726 | if (elf_section_data (section)->this_hdr.contents != NULL) | |
4727 | contents = elf_section_data (section)->this_hdr.contents; | |
4728 | else if (! bfd_malloc_and_get_section (input_bfd, section, &contents)) | |
4729 | return FALSE; | |
4730 | ||
4731 | sec_data = elf_aarch64_section_data (section); | |
4732 | ||
ccf61261 NC |
4733 | if (sec_data->mapcount) |
4734 | qsort (sec_data->map, sec_data->mapcount, | |
4735 | sizeof (elf_aarch64_section_map), elf_aarch64_compare_mapping); | |
4106101c MS |
4736 | |
4737 | for (span = 0; span < sec_data->mapcount; span++) | |
4738 | { | |
4739 | unsigned int span_start = sec_data->map[span].vma; | |
4740 | unsigned int span_end = ((span == sec_data->mapcount - 1) | |
4741 | ? sec_data->map[0].vma + section->size | |
4742 | : sec_data->map[span + 1].vma); | |
4743 | unsigned int i; | |
4744 | char span_type = sec_data->map[span].type; | |
4745 | ||
4746 | if (span_type == 'd') | |
4747 | continue; | |
4748 | ||
4749 | for (i = span_start; i + 8 < span_end; i += 4) | |
4750 | { | |
4751 | bfd_vma vma = (section->output_section->vma | |
4752 | + section->output_offset | |
4753 | + i); | |
4754 | bfd_vma veneer_i; | |
4755 | ||
4756 | if (_bfd_aarch64_erratum_843419_p | |
4757 | (contents, vma, i, span_end, &veneer_i)) | |
4758 | { | |
4759 | uint32_t insn = bfd_getl32 (contents + veneer_i); | |
4760 | ||
4761 | if (!_bfd_aarch64_erratum_843419_fixup (insn, i, veneer_i, | |
4762 | section, info)) | |
4763 | return FALSE; | |
4764 | } | |
4765 | } | |
4766 | } | |
4767 | ||
4768 | if (elf_section_data (section)->this_hdr.contents == NULL) | |
4769 | free (contents); | |
61865519 | 4770 | } |
4106101c MS |
4771 | while (0); |
4772 | ||
4773 | return TRUE; | |
61865519 | 4774 | } |
13f622ec | 4775 | |
7ff36d1a SP |
4776 | static bfd_boolean |
4777 | section_start_symbol (bfd *abfd ATTRIBUTE_UNUSED, asection *section, | |
4778 | void *valp) | |
4779 | { | |
4780 | return section->vma == *(bfd_vma *)valp; | |
4781 | } | |
4782 | ||
4783 | /* Capability format functions. */ | |
4784 | ||
4785 | static unsigned | |
4786 | exponent (uint64_t len) | |
4787 | { | |
4788 | #define CAP_MAX_EXPONENT 50 | |
4789 | /* Size is a 65 bit value, so there's an implicit 0 MSB. */ | |
4790 | unsigned zeroes = __builtin_clzl (len) + 1; | |
4791 | ||
4792 | /* All bits up to and including CAP_MW - 2 are zero. */ | |
4793 | if (CAP_MAX_EXPONENT < zeroes) | |
4794 | return (unsigned) -1; | |
4795 | else | |
4796 | return CAP_MAX_EXPONENT - zeroes; | |
4797 | #undef CAP_MAX_EXPONENT | |
4798 | } | |
4799 | ||
dbd880c7 | 4800 | #define ONES(x) ((1ULL << (x)) - 1) |
7ff36d1a SP |
4801 | #define ALIGN_UP(x, a) (((x) + ONES (a)) & (~ONES (a))) |
4802 | ||
4803 | static bfd_boolean | |
5a9e7a18 | 4804 | c64_valid_cap_range (bfd_vma *basep, bfd_vma *limitp, unsigned *alignmentp) |
7ff36d1a SP |
4805 | { |
4806 | bfd_vma base = *basep, size = *limitp - *basep; | |
4807 | ||
4808 | unsigned e, old_e; | |
5a9e7a18 | 4809 | *alignmentp = 1; |
7ff36d1a SP |
4810 | |
4811 | if ((e = exponent (size)) == (unsigned) -1) | |
4812 | return TRUE; | |
4813 | ||
4814 | size = ALIGN_UP (size, e + 3); | |
4815 | old_e = e; | |
4816 | e = exponent (size); | |
4817 | if (old_e != e) | |
4818 | size = ALIGN_UP (size, e + 3); | |
4819 | ||
4820 | base = ALIGN_UP (base, e + 3); | |
4821 | ||
5a9e7a18 | 4822 | *alignmentp = e+3; |
7ff36d1a SP |
4823 | if (base == *basep && *limitp == base + size) |
4824 | return TRUE; | |
4825 | ||
4826 | *basep = base; | |
4827 | *limitp = base + size; | |
4828 | return FALSE; | |
4829 | } | |
4830 | ||
4831 | struct sec_change_queue | |
4832 | { | |
4833 | asection *sec; | |
4834 | struct sec_change_queue *next; | |
4835 | }; | |
4836 | ||
4837 | /* Queue up the change, sorted in order of the output section vma. */ | |
4838 | ||
4839 | static void | |
4840 | queue_section_padding (struct sec_change_queue **queue, asection *sec) | |
4841 | { | |
4842 | struct sec_change_queue *q = *queue, *last_q = NULL, *n; | |
4843 | ||
4844 | while (q != NULL) | |
4845 | { | |
4846 | if (q->sec->vma > sec->vma) | |
4847 | break; | |
4848 | last_q = q; | |
4849 | q = q->next; | |
4850 | } | |
4851 | ||
4852 | n = bfd_zmalloc (sizeof (struct sec_change_queue)); | |
4853 | ||
4854 | if (last_q == NULL) | |
4855 | *queue = n; | |
4856 | else | |
4857 | { | |
4858 | n->next = q; | |
4859 | last_q->next = n; | |
4860 | } | |
4861 | ||
4862 | n->sec = sec; | |
4863 | } | |
4864 | ||
4865 | /* Check if the bounds covering all sections between LOW_SEC and HIGH_SEC will | |
4866 | get rounded off in the Morello capability format and if it does, queue up a | |
4867 | change to fix up the section layout. */ | |
4868 | static inline void | |
4869 | record_section_change (asection *sec, struct sec_change_queue **queue) | |
4870 | { | |
4871 | bfd_vma low = sec->vma; | |
4872 | bfd_vma high = sec->vma + sec->size; | |
5a9e7a18 | 4873 | unsigned alignment; |
7ff36d1a | 4874 | |
b3d71cf9 MM |
4875 | if (!c64_valid_cap_range (&low, &high, &alignment) |
4876 | || sec->alignment_power < alignment) | |
7ff36d1a SP |
4877 | queue_section_padding (queue, sec); |
4878 | } | |
4879 | ||
4880 | /* Make sure that all capabilities that refer to sections have bounds that | |
4881 | won't overlap with neighbouring sections. This is needed in two specific | |
4882 | cases. The first case is that of PCC, which needs to span across all | |
5a9e7a18 MM |
4883 | readonly sections as well as the GOT and PLT sections in the output binary. |
4884 | The second case is that of linker and ldscript defined symbols that indicate | |
4885 | start and/or end of sections and/or zero-sized symbols. | |
7ff36d1a SP |
4886 | |
4887 | In both cases, overlap of capability bounds are avoided by aligning the base | |
4888 | of the section and if necessary, adding a pad at the end of the section so | |
4889 | that the section following it starts only after the pad. */ | |
4890 | ||
5fa80905 AC |
4891 | static bfd_vma pcc_low; |
4892 | static bfd_vma pcc_high; | |
7ff36d1a SP |
4893 | void |
4894 | elfNN_c64_resize_sections (bfd *output_bfd, struct bfd_link_info *info, | |
4895 | void (*c64_pad_section) (asection *, bfd_vma), | |
4896 | void (*layout_sections_again) (void)) | |
4897 | { | |
4898 | asection *sec, *pcc_low_sec = NULL, *pcc_high_sec = NULL; | |
4899 | struct elf_aarch64_link_hash_table *htab = elf_aarch64_hash_table (info); | |
4900 | bfd_vma low = (bfd_vma) -1, high = 0; | |
2d99dff6 | 4901 | bfd *input_bfd; |
e2314302 | 4902 | unsigned align = 0; |
7ff36d1a SP |
4903 | |
4904 | htab->layout_sections_again = layout_sections_again; | |
4905 | ||
4906 | if (!htab->c64_output) | |
4907 | return; | |
4908 | ||
4909 | struct sec_change_queue *queue = NULL; | |
4910 | ||
4911 | /* First, walk through all the relocations to find those referring to linker | |
4912 | defined and ldscript defined symbols since we set their range to their | |
4913 | output sections. */ | |
2d99dff6 | 4914 | for (input_bfd = info->input_bfds; |
7ff36d1a SP |
4915 | htab->c64_rel && input_bfd != NULL; input_bfd = input_bfd->link.next) |
4916 | { | |
4917 | Elf_Internal_Shdr *symtab_hdr; | |
4918 | ||
4919 | symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr; | |
4920 | if (symtab_hdr->sh_info == 0) | |
4921 | continue; | |
4922 | ||
4923 | for (sec = input_bfd->sections; sec != NULL; sec = sec->next) | |
4924 | { | |
4925 | Elf_Internal_Rela *irelaend, *irela; | |
4926 | ||
4927 | /* If there aren't any relocs, then there's nothing more to do. */ | |
4928 | if ((sec->flags & SEC_RELOC) == 0 || sec->reloc_count == 0) | |
4929 | continue; | |
4930 | ||
4931 | irela = _bfd_elf_link_read_relocs (input_bfd, sec, NULL, NULL, | |
4932 | info->keep_memory); | |
4933 | if (irela == NULL) | |
4934 | continue; | |
4935 | ||
4936 | /* Now examine each relocation. */ | |
4937 | irelaend = irela + sec->reloc_count; | |
4938 | for (; irela < irelaend; irela++) | |
4939 | { | |
4940 | unsigned int r_indx; | |
4941 | struct elf_link_hash_entry *h; | |
4942 | int e_indx; | |
4943 | asection *os; | |
4944 | ||
4945 | r_indx = ELFNN_R_SYM (irela->r_info); | |
4946 | ||
4947 | /* Linker defined or linker script defined symbols are always in | |
4948 | the symbol hash. */ | |
4949 | if (r_indx < symtab_hdr->sh_info) | |
4950 | continue; | |
4951 | ||
4952 | e_indx = r_indx - symtab_hdr->sh_info; | |
4953 | h = elf_sym_hashes (input_bfd)[e_indx]; | |
4954 | ||
4955 | /* XXX Does this ever happen? */ | |
4956 | if (h == NULL) | |
4957 | continue; | |
4958 | ||
4959 | os = h->root.u.def.section->output_section; | |
4960 | ||
4961 | if (h->root.linker_def) | |
4962 | record_section_change (os, &queue); | |
4963 | else if (h->root.ldscript_def) | |
4964 | { | |
4965 | const char *name = h->root.root.string; | |
4966 | size_t len = strlen (name); | |
4967 | ||
4968 | if (len > 8 && name[0] == '_' && name[1] == '_' | |
4969 | && (!strncmp (name + 2, "start_", 6) | |
4970 | || !strcmp (name + len - 6, "_start"))) | |
7ff36d1a SP |
4971 | { |
4972 | bfd_vma value = os->vma + os->size; | |
4973 | ||
4974 | os = bfd_sections_find_if (info->output_bfd, | |
4975 | section_start_symbol, &value); | |
4976 | ||
4977 | if (os != NULL) | |
4978 | record_section_change (os, &queue); | |
4979 | } | |
4980 | /* XXX We're overfitting here because the offset of H within | |
4981 | the output section is not yet resolved and ldscript | |
4982 | defined symbols do not have input section information. */ | |
4983 | else | |
4984 | record_section_change (os, &queue); | |
4985 | } | |
4986 | } | |
4987 | } | |
4988 | } | |
4989 | ||
4990 | /* Next, walk through output sections to find the PCC span and add a padding | |
4991 | at the end to ensure that PCC bounds don't bleed into neighbouring | |
4992 | sections. For now PCC needs to encompass all code sections, .got, .plt | |
4993 | and .got.plt. */ | |
4994 | for (sec = output_bfd->sections; sec != NULL; sec = sec->next) | |
4995 | { | |
4996 | /* XXX This is a good place to figure out if there are any readable or | |
4997 | writable sections in the PCC range that are not in the list of | |
4998 | sections we want the PCC to span and then warn the user of it. */ | |
4999 | ||
5000 | #define NOT_OP_SECTION(s) ((s) == NULL || (s)->output_section != sec) | |
5001 | ||
0e02111b | 5002 | if ((sec->flags & SEC_READONLY) == 0 |
7ff36d1a SP |
5003 | && NOT_OP_SECTION (htab->root.sgotplt) |
5004 | && NOT_OP_SECTION (htab->root.igotplt) | |
5005 | && NOT_OP_SECTION (htab->root.sgot) | |
5006 | && NOT_OP_SECTION (htab->root.splt) | |
0e02111b MM |
5007 | && NOT_OP_SECTION (htab->root.iplt) |
5008 | && (sec->vma < info->relro_start | |
5009 | || sec->vma >= info->relro_end)) | |
5010 | continue; | |
5011 | if ((sec->flags & SEC_ALLOC) == 0) | |
7ff36d1a SP |
5012 | continue; |
5013 | ||
5014 | if (sec->vma < low) | |
5015 | { | |
5016 | low = sec->vma; | |
5017 | pcc_low_sec = sec; | |
5018 | } | |
5019 | if (sec->vma + sec->size > high) | |
5020 | { | |
5021 | high = sec->vma + sec->size; | |
5022 | pcc_high_sec = sec; | |
5023 | } | |
5024 | ||
5025 | #undef NOT_OP_SECTION | |
5026 | } | |
5027 | ||
5028 | /* Sequentially add alignment and padding as required. We also need to | |
5029 | account for the PCC-related alignment and padding here since its | |
5030 | requirements could change based on the range of sections it encompasses | |
5031 | and whether they need to be padded or aligned. */ | |
5032 | while (queue) | |
5033 | { | |
7ff36d1a SP |
5034 | bfd_vma padding = 0; |
5035 | ||
5036 | low = queue->sec->vma; | |
5037 | high = queue->sec->vma + queue->sec->size; | |
5038 | ||
5a9e7a18 | 5039 | if (!c64_valid_cap_range (&low, &high, &align)) |
7ff36d1a | 5040 | { |
2d3eb3ca | 5041 | padding = high - low - queue->sec->size; |
7ff36d1a SP |
5042 | |
5043 | if (queue->sec != pcc_high_sec) | |
5044 | { | |
5045 | c64_pad_section (queue->sec, padding); | |
5046 | padding = 0; | |
5047 | } | |
5048 | } | |
b3d71cf9 MM |
5049 | if (queue->sec->alignment_power < align) |
5050 | queue->sec->alignment_power = align; | |
7ff36d1a | 5051 | |
7ff36d1a SP |
5052 | (*htab->layout_sections_again) (); |
5053 | ||
5054 | struct sec_change_queue *queue_free = queue; | |
5055 | ||
5056 | queue = queue->next; | |
5057 | free (queue_free); | |
5058 | } | |
5fa80905 | 5059 | |
e2314302 MM |
5060 | /* Always ensure that the PCC range has precise Morello bounds. |
5061 | Whether or not there are any individual sections that need to be adjusted | |
5062 | to give precise bounds. */ | |
5063 | if (pcc_low_sec != NULL) | |
5fa80905 | 5064 | { |
e2314302 MM |
5065 | BFD_ASSERT (pcc_high_sec); |
5066 | ||
5067 | bfd_vma pcc_low_tmp; | |
5068 | bfd_vma pcc_high_tmp; | |
5069 | ||
5070 | /* We have to be a little careful about the padding we introduce. The | |
5071 | padding we could calculate here may not be the padding that we would | |
5072 | want after the very first section in the PCC bounds has been aligned | |
5073 | properly. That change in the start address propagated through a few | |
5074 | different sections with their own alignment requirements can easily | |
5075 | change the length of the region we want the PCC to span. | |
5076 | Even more tricky, that change in length could change the alignment we | |
5077 | want. We don't proove that the alignment requirement converges, | |
5078 | but believe that it should (there is only so much space that existing | |
5079 | alignment requirements could trigger to be added -- a section with an | |
5080 | alignment requirement of 16 can only really add 15 bytes to the | |
5081 | length). */ | |
5082 | bfd_boolean valid_range = FALSE; | |
5083 | while (TRUE) { | |
5084 | pcc_low_tmp = pcc_low_sec->vma; | |
5085 | pcc_high_tmp = pcc_high_sec->vma + pcc_high_sec->size; | |
5086 | valid_range = | |
5087 | c64_valid_cap_range (&pcc_low_tmp, &pcc_high_tmp, &align); | |
5088 | if (pcc_low_sec->alignment_power >= align) | |
5089 | break; | |
5090 | pcc_low_sec->alignment_power = align; | |
5091 | (*htab->layout_sections_again) (); | |
5092 | } | |
5093 | ||
5094 | /* We have calculated the bottom and top address that we want in the | |
5095 | above call to c64_valid_cap_range. We have also aligned the lowest | |
5096 | section in the PCC range to where we want it. Just have to add the | |
5097 | padding remaining if needs be. */ | |
5098 | if (!valid_range) | |
5099 | { | |
5100 | BFD_ASSERT (pcc_low_tmp == pcc_low_sec->vma); | |
5101 | bfd_vma current_length = | |
5102 | (pcc_high_sec->vma + pcc_high_sec->size) - pcc_low_sec->vma; | |
5103 | bfd_vma desired_length = (pcc_high_tmp - pcc_low_tmp); | |
5104 | bfd_vma padding = desired_length - current_length; | |
5105 | c64_pad_section (pcc_high_sec, padding); | |
5106 | } | |
5107 | /* Layout sections since it affects the final range of PCC. */ | |
5108 | (*htab->layout_sections_again) (); | |
5109 | ||
5fa80905 AC |
5110 | pcc_low = pcc_low_sec->vma; |
5111 | pcc_high = pcc_high_sec->vma + pcc_high_sec->size; | |
5112 | } | |
7ff36d1a | 5113 | } |
4106101c | 5114 | |
a06ea964 NC |
5115 | /* Determine and set the size of the stub section for a final link. |
5116 | ||
5117 | The basic idea here is to examine all the relocations looking for | |
50e192f0 SP |
5118 | PC-relative calls to a target that either needs a PE state change (A64 to |
5119 | C64 or vice versa) or in case of unconditional branches (B/BL), is | |
5120 | unreachable. */ | |
a06ea964 NC |
5121 | |
5122 | bfd_boolean | |
cec5225b | 5123 | elfNN_aarch64_size_stubs (bfd *output_bfd, |
a06ea964 NC |
5124 | bfd *stub_bfd, |
5125 | struct bfd_link_info *info, | |
5126 | bfd_signed_vma group_size, | |
5127 | asection * (*add_stub_section) (const char *, | |
5128 | asection *), | |
5129 | void (*layout_sections_again) (void)) | |
5130 | { | |
5131 | bfd_size_type stub_group_size; | |
5132 | bfd_boolean stubs_always_before_branch; | |
5421cc6e | 5133 | bfd_boolean stub_changed = FALSE; |
cec5225b | 5134 | struct elf_aarch64_link_hash_table *htab = elf_aarch64_hash_table (info); |
68fcca92 | 5135 | unsigned int num_erratum_835769_fixes = 0; |
a06ea964 NC |
5136 | |
5137 | /* Propagate mach to stub bfd, because it may not have been | |
5138 | finalized when we created stub_bfd. */ | |
5139 | bfd_set_arch_mach (stub_bfd, bfd_get_arch (output_bfd), | |
5140 | bfd_get_mach (output_bfd)); | |
5141 | ||
5142 | /* Stash our params away. */ | |
5143 | htab->stub_bfd = stub_bfd; | |
5144 | htab->add_stub_section = add_stub_section; | |
5145 | htab->layout_sections_again = layout_sections_again; | |
5146 | stubs_always_before_branch = group_size < 0; | |
5147 | if (group_size < 0) | |
5148 | stub_group_size = -group_size; | |
5149 | else | |
5150 | stub_group_size = group_size; | |
5151 | ||
5152 | if (stub_group_size == 1) | |
5153 | { | |
5154 | /* Default values. */ | |
b9eead84 | 5155 | /* AArch64 branch range is +-128MB. The value used is 1MB less. */ |
a06ea964 NC |
5156 | stub_group_size = 127 * 1024 * 1024; |
5157 | } | |
5158 | ||
5159 | group_sections (htab, stub_group_size, stubs_always_before_branch); | |
5160 | ||
4106101c MS |
5161 | (*htab->layout_sections_again) (); |
5162 | ||
5421cc6e MS |
5163 | if (htab->fix_erratum_835769) |
5164 | { | |
5165 | bfd *input_bfd; | |
5166 | ||
5167 | for (input_bfd = info->input_bfds; | |
5168 | input_bfd != NULL; input_bfd = input_bfd->link.next) | |
8c803a2d AM |
5169 | { |
5170 | if (!is_aarch64_elf (input_bfd) | |
5171 | || (input_bfd->flags & BFD_LINKER_CREATED) != 0) | |
5172 | continue; | |
5173 | ||
5174 | if (!_bfd_aarch64_erratum_835769_scan (input_bfd, info, | |
5175 | &num_erratum_835769_fixes)) | |
5176 | return FALSE; | |
5177 | } | |
5421cc6e | 5178 | |
4106101c MS |
5179 | _bfd_aarch64_resize_stubs (htab); |
5180 | (*htab->layout_sections_again) (); | |
5181 | } | |
5182 | ||
739b5c9c | 5183 | if (htab->fix_erratum_843419 != ERRAT_NONE) |
4106101c MS |
5184 | { |
5185 | bfd *input_bfd; | |
5186 | ||
5187 | for (input_bfd = info->input_bfds; | |
5188 | input_bfd != NULL; | |
5189 | input_bfd = input_bfd->link.next) | |
5190 | { | |
5191 | asection *section; | |
5192 | ||
8c803a2d AM |
5193 | if (!is_aarch64_elf (input_bfd) |
5194 | || (input_bfd->flags & BFD_LINKER_CREATED) != 0) | |
5195 | continue; | |
5196 | ||
4106101c MS |
5197 | for (section = input_bfd->sections; |
5198 | section != NULL; | |
5199 | section = section->next) | |
5200 | if (!_bfd_aarch64_erratum_843419_scan (input_bfd, section, info)) | |
5201 | return FALSE; | |
5202 | } | |
5203 | ||
5204 | _bfd_aarch64_resize_stubs (htab); | |
5205 | (*htab->layout_sections_again) (); | |
5421cc6e MS |
5206 | } |
5207 | ||
a06ea964 NC |
5208 | while (1) |
5209 | { | |
5210 | bfd *input_bfd; | |
a06ea964 | 5211 | |
9b9971aa MS |
5212 | for (input_bfd = info->input_bfds; |
5213 | input_bfd != NULL; input_bfd = input_bfd->link.next) | |
a06ea964 NC |
5214 | { |
5215 | Elf_Internal_Shdr *symtab_hdr; | |
5216 | asection *section; | |
a06ea964 | 5217 | |
8c803a2d AM |
5218 | if (!is_aarch64_elf (input_bfd) |
5219 | || (input_bfd->flags & BFD_LINKER_CREATED) != 0) | |
5220 | continue; | |
5221 | ||
a06ea964 NC |
5222 | /* We'll need the symbol table in a second. */ |
5223 | symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr; | |
5224 | if (symtab_hdr->sh_info == 0) | |
5225 | continue; | |
5226 | ||
5227 | /* Walk over each section attached to the input bfd. */ | |
5228 | for (section = input_bfd->sections; | |
5229 | section != NULL; section = section->next) | |
5230 | { | |
5231 | Elf_Internal_Rela *internal_relocs, *irelaend, *irela; | |
5232 | ||
5233 | /* If there aren't any relocs, then there's nothing more | |
5234 | to do. */ | |
5235 | if ((section->flags & SEC_RELOC) == 0 | |
5236 | || section->reloc_count == 0 | |
5237 | || (section->flags & SEC_CODE) == 0) | |
5238 | continue; | |
5239 | ||
5240 | /* If this section is a link-once section that will be | |
5241 | discarded, then don't create any stubs. */ | |
5242 | if (section->output_section == NULL | |
5243 | || section->output_section->owner != output_bfd) | |
5244 | continue; | |
5245 | ||
5246 | /* Get the relocs. */ | |
5247 | internal_relocs | |
5248 | = _bfd_elf_link_read_relocs (input_bfd, section, NULL, | |
5249 | NULL, info->keep_memory); | |
5250 | if (internal_relocs == NULL) | |
5251 | goto error_ret_free_local; | |
5252 | ||
5253 | /* Now examine each relocation. */ | |
5254 | irela = internal_relocs; | |
5255 | irelaend = irela + section->reloc_count; | |
5256 | for (; irela < irelaend; irela++) | |
5257 | { | |
5258 | unsigned int r_type, r_indx; | |
50e192f0 | 5259 | enum elf_aarch64_stub_type stub_type = aarch64_stub_none; |
cec5225b | 5260 | struct elf_aarch64_stub_hash_entry *stub_entry; |
a06ea964 NC |
5261 | asection *sym_sec; |
5262 | bfd_vma sym_value; | |
5263 | bfd_vma destination; | |
cec5225b | 5264 | struct elf_aarch64_link_hash_entry *hash; |
a06ea964 NC |
5265 | const char *sym_name; |
5266 | char *stub_name; | |
5267 | const asection *id_sec; | |
5268 | unsigned char st_type; | |
5269 | bfd_size_type len; | |
50e192f0 SP |
5270 | unsigned branch_to_c64 = FALSE; |
5271 | const char *suffix; | |
a06ea964 | 5272 | |
cec5225b YZ |
5273 | r_type = ELFNN_R_TYPE (irela->r_info); |
5274 | r_indx = ELFNN_R_SYM (irela->r_info); | |
a06ea964 NC |
5275 | |
5276 | if (r_type >= (unsigned int) R_AARCH64_end) | |
5277 | { | |
5278 | bfd_set_error (bfd_error_bad_value); | |
5279 | error_ret_free_internal: | |
5280 | if (elf_section_data (section)->relocs == NULL) | |
5281 | free (internal_relocs); | |
5282 | goto error_ret_free_local; | |
5283 | } | |
5284 | ||
5285 | /* Only look for stubs on unconditional branch and | |
5286 | branch and link instructions. */ | |
50e192f0 | 5287 | if (!aarch64_branch_reloc_p (r_type)) |
a06ea964 NC |
5288 | continue; |
5289 | ||
5290 | /* Now determine the call target, its name, value, | |
5291 | section. */ | |
5292 | sym_sec = NULL; | |
5293 | sym_value = 0; | |
5294 | destination = 0; | |
5295 | hash = NULL; | |
5296 | sym_name = NULL; | |
5297 | if (r_indx < symtab_hdr->sh_info) | |
5298 | { | |
5299 | /* It's a local symbol. */ | |
f0070c1e SP |
5300 | Elf_Internal_Sym *sym = |
5301 | bfd_sym_from_r_symndx (&htab->root.sym_cache, | |
5302 | input_bfd, r_indx); | |
5303 | if (sym == NULL) | |
5304 | goto error_ret_free_internal; | |
a06ea964 | 5305 | |
50e192f0 SP |
5306 | branch_to_c64 |= (sym->st_target_internal |
5307 | & ST_BRANCH_TO_C64); | |
5308 | ||
f0070c1e SP |
5309 | Elf_Internal_Shdr *hdr = |
5310 | elf_elfsections (input_bfd)[sym->st_shndx]; | |
a06ea964 | 5311 | |
a06ea964 NC |
5312 | sym_sec = hdr->bfd_section; |
5313 | if (!sym_sec) | |
5314 | /* This is an undefined symbol. It can never | |
5315 | be resolved. */ | |
5316 | continue; | |
5317 | ||
5318 | if (ELF_ST_TYPE (sym->st_info) != STT_SECTION) | |
5319 | sym_value = sym->st_value; | |
5320 | destination = (sym_value + irela->r_addend | |
5321 | + sym_sec->output_offset | |
5322 | + sym_sec->output_section->vma); | |
5323 | st_type = ELF_ST_TYPE (sym->st_info); | |
5324 | sym_name | |
5325 | = bfd_elf_string_from_elf_section (input_bfd, | |
5326 | symtab_hdr->sh_link, | |
5327 | sym->st_name); | |
50e192f0 SP |
5328 | |
5329 | /* Get the interworking stub if needed. */ | |
5330 | stub_type = aarch64_interwork_stub (r_type, | |
5331 | branch_to_c64); | |
a06ea964 NC |
5332 | } |
5333 | else | |
5334 | { | |
5335 | int e_indx; | |
50e192f0 SP |
5336 | struct elf_aarch64_link_hash_table *globals = |
5337 | elf_aarch64_hash_table (info); | |
a06ea964 NC |
5338 | |
5339 | e_indx = r_indx - symtab_hdr->sh_info; | |
cec5225b | 5340 | hash = ((struct elf_aarch64_link_hash_entry *) |
a06ea964 NC |
5341 | elf_sym_hashes (input_bfd)[e_indx]); |
5342 | ||
5343 | while (hash->root.root.type == bfd_link_hash_indirect | |
5344 | || hash->root.root.type == bfd_link_hash_warning) | |
cec5225b | 5345 | hash = ((struct elf_aarch64_link_hash_entry *) |
a06ea964 NC |
5346 | hash->root.root.u.i.link); |
5347 | ||
50e192f0 SP |
5348 | /* Static executable. */ |
5349 | if (globals->root.splt == NULL || hash == NULL | |
5350 | || hash->root.plt.offset == (bfd_vma) - 1) | |
5351 | { | |
5352 | branch_to_c64 |= (hash->root.target_internal | |
5353 | & ST_BRANCH_TO_C64); | |
5354 | stub_type = aarch64_interwork_stub (r_type, | |
5355 | branch_to_c64); | |
5356 | } | |
5357 | ||
a06ea964 NC |
5358 | if (hash->root.root.type == bfd_link_hash_defined |
5359 | || hash->root.root.type == bfd_link_hash_defweak) | |
5360 | { | |
a06ea964 NC |
5361 | sym_sec = hash->root.root.u.def.section; |
5362 | sym_value = hash->root.root.u.def.value; | |
5363 | /* For a destination in a shared library, | |
5364 | use the PLT stub as target address to | |
5365 | decide whether a branch stub is | |
5366 | needed. */ | |
5367 | if (globals->root.splt != NULL && hash != NULL | |
5368 | && hash->root.plt.offset != (bfd_vma) - 1) | |
5369 | { | |
5370 | sym_sec = globals->root.splt; | |
5371 | sym_value = hash->root.plt.offset; | |
5372 | if (sym_sec->output_section != NULL) | |
5373 | destination = (sym_value | |
5374 | + sym_sec->output_offset | |
5375 | + | |
5376 | sym_sec->output_section->vma); | |
5377 | } | |
5378 | else if (sym_sec->output_section != NULL) | |
5379 | destination = (sym_value + irela->r_addend | |
5380 | + sym_sec->output_offset | |
5381 | + sym_sec->output_section->vma); | |
5382 | } | |
5383 | else if (hash->root.root.type == bfd_link_hash_undefined | |
5384 | || (hash->root.root.type | |
5385 | == bfd_link_hash_undefweak)) | |
5386 | { | |
5387 | /* For a shared library, use the PLT stub as | |
5388 | target address to decide whether a long | |
5389 | branch stub is needed. | |
5390 | For absolute code, they cannot be handled. */ | |
a06ea964 NC |
5391 | |
5392 | if (globals->root.splt != NULL && hash != NULL | |
5393 | && hash->root.plt.offset != (bfd_vma) - 1) | |
5394 | { | |
5395 | sym_sec = globals->root.splt; | |
5396 | sym_value = hash->root.plt.offset; | |
5397 | if (sym_sec->output_section != NULL) | |
5398 | destination = (sym_value | |
5399 | + sym_sec->output_offset | |
5400 | + | |
5401 | sym_sec->output_section->vma); | |
5402 | } | |
5403 | else | |
5404 | continue; | |
5405 | } | |
5406 | else | |
5407 | { | |
5408 | bfd_set_error (bfd_error_bad_value); | |
5409 | goto error_ret_free_internal; | |
5410 | } | |
5411 | st_type = ELF_ST_TYPE (hash->root.type); | |
5412 | sym_name = hash->root.root.root.string; | |
5413 | } | |
5414 | ||
5415 | /* Determine what (if any) linker stub is needed. */ | |
50e192f0 SP |
5416 | if (stub_type == aarch64_stub_none) |
5417 | stub_type = aarch64_type_of_stub (section, irela, sym_sec, | |
5418 | st_type, destination); | |
5419 | ||
a06ea964 NC |
5420 | if (stub_type == aarch64_stub_none) |
5421 | continue; | |
5422 | ||
5423 | /* Support for grouping stub sections. */ | |
5424 | id_sec = htab->stub_group[section->id].link_sec; | |
5425 | ||
5426 | /* Get the name of this stub. */ | |
cec5225b | 5427 | stub_name = elfNN_aarch64_stub_name (id_sec, sym_sec, hash, |
50e192f0 | 5428 | irela, stub_type); |
a06ea964 NC |
5429 | if (!stub_name) |
5430 | goto error_ret_free_internal; | |
5431 | ||
5432 | stub_entry = | |
5433 | aarch64_stub_hash_lookup (&htab->stub_hash_table, | |
5434 | stub_name, FALSE, FALSE); | |
5435 | if (stub_entry != NULL) | |
5436 | { | |
5437 | /* The proper stub has already been created. */ | |
5438 | free (stub_name); | |
3da64fe4 RA |
5439 | /* Always update this stub's target since it may have |
5440 | changed after layout. */ | |
5441 | stub_entry->target_value = sym_value + irela->r_addend; | |
50e192f0 SP |
5442 | |
5443 | /* Set LSB for A64 to C64 branch. */ | |
5444 | if (branch_to_c64) | |
5445 | stub_entry->target_value |= 1; | |
5446 | ||
a06ea964 NC |
5447 | continue; |
5448 | } | |
5449 | ||
ef857521 MS |
5450 | stub_entry = _bfd_aarch64_add_stub_entry_in_group |
5451 | (stub_name, section, htab); | |
a06ea964 NC |
5452 | if (stub_entry == NULL) |
5453 | { | |
5454 | free (stub_name); | |
5455 | goto error_ret_free_internal; | |
5456 | } | |
5457 | ||
2f340668 | 5458 | stub_entry->target_value = sym_value + irela->r_addend; |
50e192f0 SP |
5459 | /* Set LSB for A64 to C64 branch. */ |
5460 | if (branch_to_c64) | |
5461 | stub_entry->target_value |= 1; | |
5462 | ||
a06ea964 NC |
5463 | stub_entry->target_section = sym_sec; |
5464 | stub_entry->stub_type = stub_type; | |
5465 | stub_entry->h = hash; | |
5466 | stub_entry->st_type = st_type; | |
5467 | ||
50e192f0 SP |
5468 | suffix = aarch64_lookup_stub_type_suffix (stub_type); |
5469 | ||
a06ea964 NC |
5470 | if (sym_name == NULL) |
5471 | sym_name = "unnamed"; | |
50e192f0 SP |
5472 | len = (sizeof (STUB_ENTRY_NAME) + strlen (sym_name) |
5473 | + strlen (suffix)); | |
a06ea964 NC |
5474 | stub_entry->output_name = bfd_alloc (htab->stub_bfd, len); |
5475 | if (stub_entry->output_name == NULL) | |
5476 | { | |
5477 | free (stub_name); | |
5478 | goto error_ret_free_internal; | |
5479 | } | |
5480 | ||
5481 | snprintf (stub_entry->output_name, len, STUB_ENTRY_NAME, | |
50e192f0 | 5482 | sym_name, suffix); |
a06ea964 NC |
5483 | |
5484 | stub_changed = TRUE; | |
5485 | } | |
5486 | ||
5487 | /* We're done with the internal relocs, free them. */ | |
5488 | if (elf_section_data (section)->relocs == NULL) | |
5489 | free (internal_relocs); | |
5490 | } | |
5491 | } | |
5492 | ||
5493 | if (!stub_changed) | |
5494 | break; | |
5495 | ||
13f622ec | 5496 | _bfd_aarch64_resize_stubs (htab); |
a06ea964 NC |
5497 | |
5498 | /* Ask the linker to do its stuff. */ | |
5499 | (*htab->layout_sections_again) (); | |
5500 | stub_changed = FALSE; | |
5501 | } | |
5502 | ||
5503 | return TRUE; | |
5504 | ||
dc1e8a47 | 5505 | error_ret_free_local: |
a06ea964 NC |
5506 | return FALSE; |
5507 | } | |
5508 | ||
5509 | /* Build all the stubs associated with the current output file. The | |
5510 | stubs are kept in a hash table attached to the main linker hash | |
5511 | table. We also set up the .plt entries for statically linked PIC | |
5512 | functions here. This function is called via aarch64_elf_finish in the | |
5513 | linker. */ | |
5514 | ||
5515 | bfd_boolean | |
cec5225b | 5516 | elfNN_aarch64_build_stubs (struct bfd_link_info *info) |
a06ea964 NC |
5517 | { |
5518 | asection *stub_sec; | |
5519 | struct bfd_hash_table *table; | |
cec5225b | 5520 | struct elf_aarch64_link_hash_table *htab; |
a06ea964 | 5521 | |
cec5225b | 5522 | htab = elf_aarch64_hash_table (info); |
a06ea964 NC |
5523 | |
5524 | for (stub_sec = htab->stub_bfd->sections; | |
5525 | stub_sec != NULL; stub_sec = stub_sec->next) | |
5526 | { | |
5527 | bfd_size_type size; | |
5528 | ||
5529 | /* Ignore non-stub sections. */ | |
5530 | if (!strstr (stub_sec->name, STUB_SUFFIX)) | |
5531 | continue; | |
5532 | ||
5533 | /* Allocate memory to hold the linker stubs. */ | |
5534 | size = stub_sec->size; | |
5535 | stub_sec->contents = bfd_zalloc (htab->stub_bfd, size); | |
5536 | if (stub_sec->contents == NULL && size != 0) | |
5537 | return FALSE; | |
5538 | stub_sec->size = 0; | |
61865519 | 5539 | |
9a2ebffd JW |
5540 | /* Add a branch around the stub section, and a nop, to keep it 8 byte |
5541 | aligned, as long branch stubs contain a 64-bit address. */ | |
61865519 | 5542 | bfd_putl32 (0x14000000 | (size >> 2), stub_sec->contents); |
9a2ebffd JW |
5543 | bfd_putl32 (INSN_NOP, stub_sec->contents + 4); |
5544 | stub_sec->size += 8; | |
a06ea964 NC |
5545 | } |
5546 | ||
5547 | /* Build the stubs as directed by the stub hash table. */ | |
5548 | table = &htab->stub_hash_table; | |
50e192f0 SP |
5549 | |
5550 | bfd_error_type save_error = bfd_get_error (); | |
5551 | bfd_set_error (bfd_error_no_error); | |
a06ea964 NC |
5552 | bfd_hash_traverse (table, aarch64_build_one_stub, info); |
5553 | ||
50e192f0 SP |
5554 | if (bfd_get_error () != bfd_error_no_error) |
5555 | return FALSE; | |
5556 | ||
5557 | bfd_set_error (save_error); | |
5558 | ||
a06ea964 NC |
5559 | return TRUE; |
5560 | } | |
5561 | ||
5562 | ||
5563 | /* Add an entry to the code/data map for section SEC. */ | |
5564 | ||
5565 | static void | |
f0070c1e SP |
5566 | elfNN_aarch64_section_map_add (bfd *abfd, asection *sec, char type, |
5567 | bfd_vma vma) | |
a06ea964 NC |
5568 | { |
5569 | struct _aarch64_elf_section_data *sec_data = | |
cec5225b | 5570 | elf_aarch64_section_data (sec); |
a06ea964 NC |
5571 | unsigned int newidx; |
5572 | ||
f0070c1e SP |
5573 | /* The aarch64 section hook was not called for this section. */ |
5574 | if (!sec_data->elf.is_target_section_data) | |
5575 | { | |
5576 | struct _aarch64_elf_section_data *newdata = | |
5577 | bfd_zalloc (abfd, sizeof (*newdata)); | |
5578 | ||
5579 | if (newdata == NULL) | |
5580 | return; | |
5581 | ||
5582 | newdata->elf = sec_data->elf; | |
5583 | newdata->elf.is_target_section_data = TRUE; | |
5584 | free (sec_data); | |
5585 | sec->used_by_bfd = sec_data = newdata; | |
5586 | } | |
5587 | ||
a06ea964 NC |
5588 | if (sec_data->map == NULL) |
5589 | { | |
cec5225b | 5590 | sec_data->map = bfd_malloc (sizeof (elf_aarch64_section_map)); |
a06ea964 NC |
5591 | sec_data->mapcount = 0; |
5592 | sec_data->mapsize = 1; | |
5593 | } | |
5594 | ||
5595 | newidx = sec_data->mapcount++; | |
5596 | ||
5597 | if (sec_data->mapcount > sec_data->mapsize) | |
5598 | { | |
5599 | sec_data->mapsize *= 2; | |
5600 | sec_data->map = bfd_realloc_or_free | |
cec5225b | 5601 | (sec_data->map, sec_data->mapsize * sizeof (elf_aarch64_section_map)); |
a06ea964 NC |
5602 | } |
5603 | ||
5604 | if (sec_data->map) | |
5605 | { | |
5606 | sec_data->map[newidx].vma = vma; | |
5607 | sec_data->map[newidx].type = type; | |
5608 | } | |
5609 | } | |
5610 | ||
5611 | ||
5612 | /* Initialise maps of insn/data for input BFDs. */ | |
5613 | void | |
7ff36d1a | 5614 | bfd_elfNN_aarch64_init_maps (bfd *abfd, struct bfd_link_info *info) |
a06ea964 NC |
5615 | { |
5616 | Elf_Internal_Sym *isymbuf; | |
5617 | Elf_Internal_Shdr *hdr; | |
5618 | unsigned int i, localsyms; | |
5619 | ||
5620 | /* Make sure that we are dealing with an AArch64 elf binary. */ | |
5621 | if (!is_aarch64_elf (abfd)) | |
5622 | return; | |
5623 | ||
f0070c1e SP |
5624 | if (elf_aarch64_tdata (abfd)->secmaps_initialised) |
5625 | return; | |
5626 | ||
a06ea964 | 5627 | if ((abfd->flags & DYNAMIC) != 0) |
68fcca92 | 5628 | return; |
a06ea964 NC |
5629 | |
5630 | hdr = &elf_symtab_hdr (abfd); | |
5631 | localsyms = hdr->sh_info; | |
5632 | ||
5633 | /* Obtain a buffer full of symbols for this BFD. The hdr->sh_info field | |
5634 | should contain the number of local symbols, which should come before any | |
5635 | global symbols. Mapping symbols are always local. */ | |
5636 | isymbuf = bfd_elf_get_elf_syms (abfd, hdr, localsyms, 0, NULL, NULL, NULL); | |
5637 | ||
5638 | /* No internal symbols read? Skip this BFD. */ | |
5639 | if (isymbuf == NULL) | |
5640 | return; | |
5641 | ||
7ff36d1a SP |
5642 | struct elf_aarch64_link_hash_table *htab = elf_aarch64_hash_table ((info)); |
5643 | ||
a06ea964 NC |
5644 | for (i = 0; i < localsyms; i++) |
5645 | { | |
5646 | Elf_Internal_Sym *isym = &isymbuf[i]; | |
5647 | asection *sec = bfd_section_from_elf_index (abfd, isym->st_shndx); | |
5648 | const char *name; | |
5649 | ||
5650 | if (sec != NULL && ELF_ST_BIND (isym->st_info) == STB_LOCAL) | |
5651 | { | |
5652 | name = bfd_elf_string_from_elf_section (abfd, | |
5653 | hdr->sh_link, | |
5654 | isym->st_name); | |
5655 | ||
5656 | if (bfd_is_aarch64_special_symbol_name | |
5657 | (name, BFD_AARCH64_SPECIAL_SYM_TYPE_MAP)) | |
7ff36d1a SP |
5658 | { |
5659 | elfNN_aarch64_section_map_add (abfd, sec, name[1], | |
5660 | isym->st_value); | |
5661 | if (!htab->c64_output && name[1] == 'c') | |
5662 | htab->c64_output = TRUE; | |
5663 | } | |
a06ea964 NC |
5664 | } |
5665 | } | |
f0070c1e | 5666 | elf_aarch64_tdata (abfd)->secmaps_initialised = TRUE; |
a06ea964 NC |
5667 | } |
5668 | ||
37c18eed SD |
5669 | static void |
5670 | setup_plt_values (struct bfd_link_info *link_info, | |
5671 | aarch64_plt_type plt_type) | |
5672 | { | |
5673 | struct elf_aarch64_link_hash_table *globals; | |
5674 | globals = elf_aarch64_hash_table (link_info); | |
5675 | ||
e19e9199 SP |
5676 | /* Set up plt stubs in case we need C64 PLT. Override BTI/PAC since they're |
5677 | not compatible. PLT stub sizes are the same as the default ones. */ | |
5678 | if (globals->c64_rel) | |
5679 | { | |
5680 | if (plt_type != PLT_NORMAL) | |
5681 | _bfd_error_handler | |
5682 | (_("ignoring C64-incompatible extensions: %s"), | |
5683 | (plt_type == PLT_BTI_PAC ? "BTI, PAC" | |
5684 | : plt_type == PLT_BTI ? "BTI" : "PAC")); | |
5685 | ||
5686 | globals->plt0_entry = elfNN_c64_small_plt0_entry; | |
5687 | globals->plt_entry = elfNN_c64_small_plt_entry; | |
5688 | return; | |
5689 | } | |
5690 | ||
1dbade74 SD |
5691 | if (plt_type == PLT_BTI_PAC) |
5692 | { | |
68bb0359 | 5693 | globals->plt0_entry = elfNN_aarch64_small_plt0_bti_entry; |
1dbade74 SD |
5694 | |
5695 | /* Only in ET_EXEC we need PLTn with BTI. */ | |
5696 | if (bfd_link_pde (link_info)) | |
5697 | { | |
5698 | globals->plt_entry_size = PLT_BTI_PAC_SMALL_ENTRY_SIZE; | |
5699 | globals->plt_entry = elfNN_aarch64_small_plt_bti_pac_entry; | |
5700 | } | |
5701 | else | |
5702 | { | |
5703 | globals->plt_entry_size = PLT_PAC_SMALL_ENTRY_SIZE; | |
5704 | globals->plt_entry = elfNN_aarch64_small_plt_pac_entry; | |
5705 | } | |
5706 | } | |
5707 | else if (plt_type == PLT_BTI) | |
37c18eed | 5708 | { |
37c18eed | 5709 | globals->plt0_entry = elfNN_aarch64_small_plt0_bti_entry; |
37c18eed SD |
5710 | |
5711 | /* Only in ET_EXEC we need PLTn with BTI. */ | |
5712 | if (bfd_link_pde (link_info)) | |
5713 | { | |
5714 | globals->plt_entry_size = PLT_BTI_SMALL_ENTRY_SIZE; | |
5715 | globals->plt_entry = elfNN_aarch64_small_plt_bti_entry; | |
5716 | } | |
5717 | } | |
1dbade74 SD |
5718 | else if (plt_type == PLT_PAC) |
5719 | { | |
1dbade74 SD |
5720 | globals->plt_entry_size = PLT_PAC_SMALL_ENTRY_SIZE; |
5721 | globals->plt_entry = elfNN_aarch64_small_plt_pac_entry; | |
5722 | } | |
37c18eed SD |
5723 | } |
5724 | ||
a06ea964 NC |
5725 | /* Set option values needed during linking. */ |
5726 | void | |
cec5225b | 5727 | bfd_elfNN_aarch64_set_options (struct bfd *output_bfd, |
a06ea964 NC |
5728 | struct bfd_link_info *link_info, |
5729 | int no_enum_warn, | |
68fcca92 | 5730 | int no_wchar_warn, int pic_veneer, |
4106101c | 5731 | int fix_erratum_835769, |
739b5c9c | 5732 | erratum_84319_opts fix_erratum_843419, |
37c18eed SD |
5733 | int no_apply_dynamic_relocs, |
5734 | aarch64_bti_pac_info bp_info) | |
a06ea964 | 5735 | { |
cec5225b | 5736 | struct elf_aarch64_link_hash_table *globals; |
a06ea964 | 5737 | |
cec5225b | 5738 | globals = elf_aarch64_hash_table (link_info); |
a06ea964 | 5739 | globals->pic_veneer = pic_veneer; |
68fcca92 | 5740 | globals->fix_erratum_835769 = fix_erratum_835769; |
739b5c9c TC |
5741 | /* If the default options are used, then ERRAT_ADR will be set by default |
5742 | which will enable the ADRP->ADR workaround for the erratum 843419 | |
5743 | workaround. */ | |
4106101c | 5744 | globals->fix_erratum_843419 = fix_erratum_843419; |
1f56df9d | 5745 | globals->no_apply_dynamic_relocs = no_apply_dynamic_relocs; |
a1bdea65 | 5746 | globals->c64_rel = 0; |
a06ea964 NC |
5747 | |
5748 | BFD_ASSERT (is_aarch64_elf (output_bfd)); | |
5749 | elf_aarch64_tdata (output_bfd)->no_enum_size_warning = no_enum_warn; | |
5750 | elf_aarch64_tdata (output_bfd)->no_wchar_size_warning = no_wchar_warn; | |
37c18eed SD |
5751 | |
5752 | switch (bp_info.bti_type) | |
5753 | { | |
5754 | case BTI_WARN: | |
5755 | elf_aarch64_tdata (output_bfd)->no_bti_warn = 0; | |
5756 | elf_aarch64_tdata (output_bfd)->gnu_and_prop | |
5757 | |= GNU_PROPERTY_AARCH64_FEATURE_1_BTI; | |
5758 | break; | |
5759 | ||
5760 | default: | |
5761 | break; | |
5762 | } | |
5763 | elf_aarch64_tdata (output_bfd)->plt_type = bp_info.plt_type; | |
f0070c1e | 5764 | elf_aarch64_tdata (output_bfd)->secmaps_initialised = FALSE; |
a06ea964 NC |
5765 | } |
5766 | ||
a06ea964 NC |
5767 | static bfd_vma |
5768 | aarch64_calculate_got_entry_vma (struct elf_link_hash_entry *h, | |
cec5225b | 5769 | struct elf_aarch64_link_hash_table |
a06ea964 NC |
5770 | *globals, struct bfd_link_info *info, |
5771 | bfd_vma value, bfd *output_bfd, | |
5772 | bfd_boolean *unresolved_reloc_p) | |
5773 | { | |
5774 | bfd_vma off = (bfd_vma) - 1; | |
5775 | asection *basegot = globals->root.sgot; | |
5776 | bfd_boolean dyn = globals->root.dynamic_sections_created; | |
5777 | ||
5778 | if (h != NULL) | |
5779 | { | |
a6bb11b2 | 5780 | BFD_ASSERT (basegot != NULL); |
a06ea964 NC |
5781 | off = h->got.offset; |
5782 | BFD_ASSERT (off != (bfd_vma) - 1); | |
0e1862bb L |
5783 | if (!WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, bfd_link_pic (info), h) |
5784 | || (bfd_link_pic (info) | |
a06ea964 NC |
5785 | && SYMBOL_REFERENCES_LOCAL (info, h)) |
5786 | || (ELF_ST_VISIBILITY (h->other) | |
5787 | && h->root.type == bfd_link_hash_undefweak)) | |
5788 | { | |
5789 | /* This is actually a static link, or it is a -Bsymbolic link | |
5790 | and the symbol is defined locally. We must initialize this | |
5791 | entry in the global offset table. Since the offset must | |
a6bb11b2 YZ |
5792 | always be a multiple of 8 (4 in the case of ILP32), we use |
5793 | the least significant bit to record whether we have | |
5794 | initialized it already. | |
a06ea964 NC |
5795 | When doing a dynamic link, we create a .rel(a).got relocation |
5796 | entry to initialize the value. This is done in the | |
5797 | finish_dynamic_symbol routine. */ | |
5798 | if ((off & 1) != 0) | |
5799 | off &= ~1; | |
5800 | else | |
5801 | { | |
cec5225b | 5802 | bfd_put_NN (output_bfd, value, basegot->contents + off); |
a06ea964 NC |
5803 | h->got.offset |= 1; |
5804 | } | |
5805 | } | |
5806 | else | |
5807 | *unresolved_reloc_p = FALSE; | |
5808 | ||
5809 | off = off + basegot->output_section->vma + basegot->output_offset; | |
5810 | } | |
5811 | ||
5812 | return off; | |
5813 | } | |
5814 | ||
5815 | /* Change R_TYPE to a more efficient access model where possible, | |
5816 | return the new reloc type. */ | |
5817 | ||
a6bb11b2 YZ |
5818 | static bfd_reloc_code_real_type |
5819 | aarch64_tls_transition_without_check (bfd_reloc_code_real_type r_type, | |
4ca9b406 SP |
5820 | struct bfd_link_info *info, |
5821 | struct elf_link_hash_entry *h, | |
5822 | bfd_boolean morello_reloc) | |
a06ea964 NC |
5823 | { |
5824 | bfd_boolean is_local = h == NULL; | |
a6bb11b2 | 5825 | |
a06ea964 NC |
5826 | switch (r_type) |
5827 | { | |
4ca9b406 SP |
5828 | case BFD_RELOC_MORELLO_TLSDESC_ADR_PAGE20: |
5829 | return (is_local || !bfd_link_pic (info) | |
5830 | ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1 | |
5831 | : r_type); | |
5832 | ||
a6bb11b2 | 5833 | case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21: |
ce336788 | 5834 | case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21: |
a6bb11b2 YZ |
5835 | return (is_local |
5836 | ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1 | |
5837 | : BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21); | |
5838 | ||
389b8029 MS |
5839 | case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21: |
5840 | return (is_local | |
5841 | ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC | |
5842 | : r_type); | |
5843 | ||
1ada945d MS |
5844 | case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19: |
5845 | return (is_local | |
5846 | ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1 | |
5847 | : BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19); | |
5848 | ||
0484b454 RL |
5849 | case BFD_RELOC_AARCH64_TLSDESC_LDR: |
5850 | return (is_local | |
5851 | ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC | |
5852 | : BFD_RELOC_AARCH64_NONE); | |
5853 | ||
5854 | case BFD_RELOC_AARCH64_TLSDESC_OFF_G0_NC: | |
5855 | return (is_local | |
5856 | ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1_NC | |
5857 | : BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G0_NC); | |
5858 | ||
5859 | case BFD_RELOC_AARCH64_TLSDESC_OFF_G1: | |
5860 | return (is_local | |
5861 | ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G2 | |
5862 | : BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G1); | |
5863 | ||
4ca9b406 SP |
5864 | case BFD_RELOC_MORELLO_TLSDESC_LD128_LO12: |
5865 | return ((is_local || !bfd_link_pie (info) | |
5866 | ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC : r_type)); | |
5867 | ||
a6bb11b2 | 5868 | case BFD_RELOC_AARCH64_TLSDESC_LDNN_LO12_NC: |
ce336788 | 5869 | case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC: |
a6bb11b2 YZ |
5870 | return (is_local |
5871 | ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC | |
5872 | : BFD_RELOC_AARCH64_TLSIE_LDNN_GOTTPREL_LO12_NC); | |
5873 | ||
5874 | case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21: | |
5875 | return is_local ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1 : r_type; | |
5876 | ||
5877 | case BFD_RELOC_AARCH64_TLSIE_LDNN_GOTTPREL_LO12_NC: | |
5878 | return is_local ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC : r_type; | |
5879 | ||
043bf05a MS |
5880 | case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19: |
5881 | return r_type; | |
5882 | ||
3c12b054 MS |
5883 | case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21: |
5884 | return (is_local | |
5885 | ? BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_HI12 | |
5886 | : BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19); | |
5887 | ||
4ca9b406 SP |
5888 | case BFD_RELOC_MORELLO_TLSDESC_CALL: |
5889 | return ((is_local || !bfd_link_pie (info)) | |
5890 | ? BFD_RELOC_AARCH64_NONE : r_type); | |
5891 | ||
f955cccf | 5892 | case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12: |
4ca9b406 SP |
5893 | if (morello_reloc && !is_local && bfd_link_pie (info)) |
5894 | return r_type; | |
5895 | /* Fall through. */ | |
5896 | case BFD_RELOC_AARCH64_TLSDESC_ADD: | |
a6bb11b2 | 5897 | case BFD_RELOC_AARCH64_TLSDESC_CALL: |
4ca9b406 SP |
5898 | /* Instructions with these relocations will be fully resolved during the |
5899 | transition into either a NOP in the A64 case or movk and add in | |
5900 | C64. */ | |
a6bb11b2 YZ |
5901 | return BFD_RELOC_AARCH64_NONE; |
5902 | ||
259364ad JW |
5903 | case BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC: |
5904 | case BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21: | |
5905 | case BFD_RELOC_AARCH64_TLSLD_ADR_PREL21: | |
5906 | return is_local ? BFD_RELOC_AARCH64_NONE : r_type; | |
5907 | ||
ac734732 RL |
5908 | #if ARCH_SIZE == 64 |
5909 | case BFD_RELOC_AARCH64_TLSGD_MOVW_G0_NC: | |
5910 | return is_local | |
5911 | ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1_NC | |
5912 | : BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G0_NC; | |
5913 | ||
5914 | case BFD_RELOC_AARCH64_TLSGD_MOVW_G1: | |
5915 | return is_local | |
5916 | ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G2 | |
5917 | : BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G1; | |
5918 | #endif | |
5919 | ||
a6bb11b2 YZ |
5920 | default: |
5921 | break; | |
a06ea964 NC |
5922 | } |
5923 | ||
5924 | return r_type; | |
5925 | } | |
5926 | ||
5927 | static unsigned int | |
a6bb11b2 | 5928 | aarch64_reloc_got_type (bfd_reloc_code_real_type r_type) |
a06ea964 NC |
5929 | { |
5930 | switch (r_type) | |
5931 | { | |
a6bb11b2 YZ |
5932 | case BFD_RELOC_AARCH64_ADR_GOT_PAGE: |
5933 | case BFD_RELOC_AARCH64_GOT_LD_PREL19: | |
7018c030 | 5934 | case BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14: |
ce336788 | 5935 | case BFD_RELOC_AARCH64_LD32_GOT_LO12_NC: |
a2e1db00 | 5936 | case BFD_RELOC_AARCH64_LD64_GOTOFF_LO15: |
99ad26cb | 5937 | case BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15: |
ce336788 | 5938 | case BFD_RELOC_AARCH64_LD64_GOT_LO12_NC: |
dc8008f5 | 5939 | case BFD_RELOC_AARCH64_MOVW_GOTOFF_G0_NC: |
74a1bfe1 | 5940 | case BFD_RELOC_AARCH64_MOVW_GOTOFF_G1: |
a06ea964 NC |
5941 | return GOT_NORMAL; |
5942 | ||
a1bdea65 SP |
5943 | case BFD_RELOC_MORELLO_ADR_GOT_PAGE: |
5944 | case BFD_RELOC_MORELLO_LD128_GOT_LO12_NC: | |
5945 | return GOT_CAP; | |
5946 | ||
ce336788 | 5947 | case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC: |
a6bb11b2 | 5948 | case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21: |
3c12b054 | 5949 | case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21: |
7ba7cfe4 | 5950 | case BFD_RELOC_AARCH64_TLSGD_MOVW_G0_NC: |
94facae3 | 5951 | case BFD_RELOC_AARCH64_TLSGD_MOVW_G1: |
73f925cc | 5952 | case BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC: |
f69e4920 | 5953 | case BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21: |
77a69ff8 | 5954 | case BFD_RELOC_AARCH64_TLSLD_ADR_PREL21: |
a06ea964 NC |
5955 | return GOT_TLS_GD; |
5956 | ||
4ca9b406 SP |
5957 | case BFD_RELOC_MORELLO_TLSDESC_ADR_PAGE20: |
5958 | case BFD_RELOC_MORELLO_TLSDESC_CALL: | |
5959 | case BFD_RELOC_MORELLO_TLSDESC_LD128_LO12: | |
5960 | return GOT_TLSDESC_GD | GOT_CAP; | |
5961 | ||
0484b454 | 5962 | case BFD_RELOC_AARCH64_TLSDESC_ADD: |
f955cccf | 5963 | case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12: |
a6bb11b2 | 5964 | case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21: |
389b8029 | 5965 | case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21: |
a6bb11b2 | 5966 | case BFD_RELOC_AARCH64_TLSDESC_CALL: |
a6bb11b2 | 5967 | case BFD_RELOC_AARCH64_TLSDESC_LD32_LO12_NC: |
f955cccf | 5968 | case BFD_RELOC_AARCH64_TLSDESC_LD64_LO12: |
1ada945d | 5969 | case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19: |
0484b454 RL |
5970 | case BFD_RELOC_AARCH64_TLSDESC_LDR: |
5971 | case BFD_RELOC_AARCH64_TLSDESC_OFF_G0_NC: | |
5972 | case BFD_RELOC_AARCH64_TLSDESC_OFF_G1: | |
a06ea964 NC |
5973 | return GOT_TLSDESC_GD; |
5974 | ||
a6bb11b2 | 5975 | case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21: |
a6bb11b2 | 5976 | case BFD_RELOC_AARCH64_TLSIE_LD32_GOTTPREL_LO12_NC: |
ce336788 | 5977 | case BFD_RELOC_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC: |
043bf05a | 5978 | case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19: |
3b957e5b RL |
5979 | case BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G0_NC: |
5980 | case BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G1: | |
a06ea964 NC |
5981 | return GOT_TLS_IE; |
5982 | ||
a6bb11b2 YZ |
5983 | default: |
5984 | break; | |
a06ea964 NC |
5985 | } |
5986 | return GOT_UNKNOWN; | |
5987 | } | |
5988 | ||
5989 | static bfd_boolean | |
5990 | aarch64_can_relax_tls (bfd *input_bfd, | |
5991 | struct bfd_link_info *info, | |
4ca9b406 | 5992 | const Elf_Internal_Rela *rel, |
a06ea964 NC |
5993 | struct elf_link_hash_entry *h, |
5994 | unsigned long r_symndx) | |
5995 | { | |
5996 | unsigned int symbol_got_type; | |
5997 | unsigned int reloc_got_type; | |
5998 | ||
4ca9b406 SP |
5999 | bfd_reloc_code_real_type bfd_r_type |
6000 | = elfNN_aarch64_bfd_reloc_from_type (input_bfd, | |
6001 | ELFNN_R_TYPE (rel->r_info)); | |
6002 | ||
6003 | if (! IS_AARCH64_TLS_RELAX_RELOC (bfd_r_type)) | |
a06ea964 NC |
6004 | return FALSE; |
6005 | ||
cec5225b | 6006 | symbol_got_type = elfNN_aarch64_symbol_got_type (h, input_bfd, r_symndx); |
4ca9b406 | 6007 | reloc_got_type = aarch64_reloc_got_type (bfd_r_type); |
a06ea964 NC |
6008 | |
6009 | if (symbol_got_type == GOT_TLS_IE && GOT_TLS_GD_ANY_P (reloc_got_type)) | |
6010 | return TRUE; | |
6011 | ||
6dda7875 | 6012 | if (!bfd_link_executable (info)) |
a06ea964 NC |
6013 | return FALSE; |
6014 | ||
6015 | if (h && h->root.type == bfd_link_hash_undefweak) | |
6016 | return FALSE; | |
6017 | ||
6018 | return TRUE; | |
6019 | } | |
6020 | ||
a6bb11b2 YZ |
6021 | /* Given the relocation code R_TYPE, return the relaxed bfd reloc |
6022 | enumerator. */ | |
6023 | ||
6024 | static bfd_reloc_code_real_type | |
a06ea964 NC |
6025 | aarch64_tls_transition (bfd *input_bfd, |
6026 | struct bfd_link_info *info, | |
4ca9b406 | 6027 | const Elf_Internal_Rela *rel, |
a06ea964 NC |
6028 | struct elf_link_hash_entry *h, |
6029 | unsigned long r_symndx) | |
6030 | { | |
a6bb11b2 | 6031 | bfd_reloc_code_real_type bfd_r_type |
4ca9b406 SP |
6032 | = elfNN_aarch64_bfd_reloc_from_type (input_bfd, |
6033 | ELFNN_R_TYPE (rel->r_info)); | |
6034 | ||
6035 | if (! aarch64_can_relax_tls (input_bfd, info, rel, h, r_symndx)) | |
6036 | return bfd_r_type; | |
a06ea964 | 6037 | |
4ca9b406 SP |
6038 | bfd_boolean morello_reloc = (bfd_r_type == BFD_RELOC_AARCH64_TLSDESC_ADD_LO12 |
6039 | && (ELFNN_R_TYPE (rel[1].r_info) | |
6040 | == MORELLO_R (TLSDESC_CALL))); | |
6041 | ||
6042 | /* GD -> IE is not supported for Morello TLSDESC yet. We do however allow | |
6043 | lowering of GD -> LE for static non-pie executables. XXX It ought to be | |
6044 | safe to do this for A64 as well but it is not implemented yet. */ | |
6045 | if (h != NULL && morello_reloc && bfd_link_pie (info)) | |
a6bb11b2 YZ |
6046 | return bfd_r_type; |
6047 | ||
4ca9b406 SP |
6048 | return aarch64_tls_transition_without_check (bfd_r_type, info, h, |
6049 | morello_reloc); | |
a06ea964 NC |
6050 | } |
6051 | ||
6052 | /* Return the base VMA address which should be subtracted from real addresses | |
a6bb11b2 | 6053 | when resolving R_AARCH64_TLS_DTPREL relocation. */ |
a06ea964 NC |
6054 | |
6055 | static bfd_vma | |
6056 | dtpoff_base (struct bfd_link_info *info) | |
6057 | { | |
6058 | /* If tls_sec is NULL, we should have signalled an error already. */ | |
6059 | BFD_ASSERT (elf_hash_table (info)->tls_sec != NULL); | |
6060 | return elf_hash_table (info)->tls_sec->vma; | |
6061 | } | |
6062 | ||
a06ea964 NC |
6063 | /* Return the base VMA address which should be subtracted from real addresses |
6064 | when resolving R_AARCH64_TLS_GOTTPREL64 relocations. */ | |
6065 | ||
6066 | static bfd_vma | |
6067 | tpoff_base (struct bfd_link_info *info) | |
6068 | { | |
6069 | struct elf_link_hash_table *htab = elf_hash_table (info); | |
6070 | ||
6071 | /* If tls_sec is NULL, we should have signalled an error already. */ | |
ac21917f | 6072 | BFD_ASSERT (htab->tls_sec != NULL); |
a06ea964 NC |
6073 | |
6074 | bfd_vma base = align_power ((bfd_vma) TCB_SIZE, | |
6075 | htab->tls_sec->alignment_power); | |
6076 | return htab->tls_sec->vma - base; | |
6077 | } | |
6078 | ||
6079 | static bfd_vma * | |
6080 | symbol_got_offset_ref (bfd *input_bfd, struct elf_link_hash_entry *h, | |
6081 | unsigned long r_symndx) | |
6082 | { | |
6083 | /* Calculate the address of the GOT entry for symbol | |
6084 | referred to in h. */ | |
6085 | if (h != NULL) | |
6086 | return &h->got.offset; | |
6087 | else | |
6088 | { | |
6089 | /* local symbol */ | |
6090 | struct elf_aarch64_local_symbol *l; | |
6091 | ||
cec5225b | 6092 | l = elf_aarch64_locals (input_bfd); |
a06ea964 NC |
6093 | return &l[r_symndx].got_offset; |
6094 | } | |
6095 | } | |
6096 | ||
6097 | static void | |
6098 | symbol_got_offset_mark (bfd *input_bfd, struct elf_link_hash_entry *h, | |
6099 | unsigned long r_symndx) | |
6100 | { | |
6101 | bfd_vma *p; | |
6102 | p = symbol_got_offset_ref (input_bfd, h, r_symndx); | |
6103 | *p |= 1; | |
6104 | } | |
6105 | ||
6106 | static int | |
6107 | symbol_got_offset_mark_p (bfd *input_bfd, struct elf_link_hash_entry *h, | |
6108 | unsigned long r_symndx) | |
6109 | { | |
6110 | bfd_vma value; | |
6111 | value = * symbol_got_offset_ref (input_bfd, h, r_symndx); | |
6112 | return value & 1; | |
6113 | } | |
6114 | ||
6115 | static bfd_vma | |
6116 | symbol_got_offset (bfd *input_bfd, struct elf_link_hash_entry *h, | |
6117 | unsigned long r_symndx) | |
6118 | { | |
6119 | bfd_vma value; | |
6120 | value = * symbol_got_offset_ref (input_bfd, h, r_symndx); | |
6121 | value &= ~1; | |
6122 | return value; | |
6123 | } | |
6124 | ||
6125 | static bfd_vma * | |
6126 | symbol_tlsdesc_got_offset_ref (bfd *input_bfd, struct elf_link_hash_entry *h, | |
6127 | unsigned long r_symndx) | |
6128 | { | |
6129 | /* Calculate the address of the GOT entry for symbol | |
6130 | referred to in h. */ | |
6131 | if (h != NULL) | |
6132 | { | |
cec5225b YZ |
6133 | struct elf_aarch64_link_hash_entry *eh; |
6134 | eh = (struct elf_aarch64_link_hash_entry *) h; | |
a06ea964 NC |
6135 | return &eh->tlsdesc_got_jump_table_offset; |
6136 | } | |
6137 | else | |
6138 | { | |
6139 | /* local symbol */ | |
6140 | struct elf_aarch64_local_symbol *l; | |
6141 | ||
cec5225b | 6142 | l = elf_aarch64_locals (input_bfd); |
a06ea964 NC |
6143 | return &l[r_symndx].tlsdesc_got_jump_table_offset; |
6144 | } | |
6145 | } | |
6146 | ||
6147 | static void | |
6148 | symbol_tlsdesc_got_offset_mark (bfd *input_bfd, struct elf_link_hash_entry *h, | |
6149 | unsigned long r_symndx) | |
6150 | { | |
6151 | bfd_vma *p; | |
6152 | p = symbol_tlsdesc_got_offset_ref (input_bfd, h, r_symndx); | |
6153 | *p |= 1; | |
6154 | } | |
6155 | ||
6156 | static int | |
6157 | symbol_tlsdesc_got_offset_mark_p (bfd *input_bfd, | |
6158 | struct elf_link_hash_entry *h, | |
6159 | unsigned long r_symndx) | |
6160 | { | |
6161 | bfd_vma value; | |
6162 | value = * symbol_tlsdesc_got_offset_ref (input_bfd, h, r_symndx); | |
6163 | return value & 1; | |
6164 | } | |
6165 | ||
6166 | static bfd_vma | |
6167 | symbol_tlsdesc_got_offset (bfd *input_bfd, struct elf_link_hash_entry *h, | |
6168 | unsigned long r_symndx) | |
6169 | { | |
6170 | bfd_vma value; | |
6171 | value = * symbol_tlsdesc_got_offset_ref (input_bfd, h, r_symndx); | |
6172 | value &= ~1; | |
6173 | return value; | |
6174 | } | |
6175 | ||
68fcca92 JW |
6176 | /* Data for make_branch_to_erratum_835769_stub(). */ |
6177 | ||
6178 | struct erratum_835769_branch_to_stub_data | |
6179 | { | |
4106101c | 6180 | struct bfd_link_info *info; |
68fcca92 JW |
6181 | asection *output_section; |
6182 | bfd_byte *contents; | |
6183 | }; | |
6184 | ||
6185 | /* Helper to insert branches to erratum 835769 stubs in the right | |
6186 | places for a particular section. */ | |
6187 | ||
6188 | static bfd_boolean | |
6189 | make_branch_to_erratum_835769_stub (struct bfd_hash_entry *gen_entry, | |
6190 | void *in_arg) | |
6191 | { | |
6192 | struct elf_aarch64_stub_hash_entry *stub_entry; | |
6193 | struct erratum_835769_branch_to_stub_data *data; | |
6194 | bfd_byte *contents; | |
6195 | unsigned long branch_insn = 0; | |
6196 | bfd_vma veneered_insn_loc, veneer_entry_loc; | |
6197 | bfd_signed_vma branch_offset; | |
6198 | unsigned int target; | |
6199 | bfd *abfd; | |
6200 | ||
6201 | stub_entry = (struct elf_aarch64_stub_hash_entry *) gen_entry; | |
6202 | data = (struct erratum_835769_branch_to_stub_data *) in_arg; | |
6203 | ||
6204 | if (stub_entry->target_section != data->output_section | |
6205 | || stub_entry->stub_type != aarch64_stub_erratum_835769_veneer) | |
6206 | return TRUE; | |
6207 | ||
6208 | contents = data->contents; | |
6209 | veneered_insn_loc = stub_entry->target_section->output_section->vma | |
6210 | + stub_entry->target_section->output_offset | |
6211 | + stub_entry->target_value; | |
6212 | veneer_entry_loc = stub_entry->stub_sec->output_section->vma | |
6213 | + stub_entry->stub_sec->output_offset | |
6214 | + stub_entry->stub_offset; | |
6215 | branch_offset = veneer_entry_loc - veneered_insn_loc; | |
6216 | ||
6217 | abfd = stub_entry->target_section->owner; | |
6218 | if (!aarch64_valid_branch_p (veneer_entry_loc, veneered_insn_loc)) | |
4eca0228 | 6219 | _bfd_error_handler |
90b6238f | 6220 | (_("%pB: error: erratum 835769 stub out " |
4eca0228 | 6221 | "of range (input file too large)"), abfd); |
68fcca92 JW |
6222 | |
6223 | target = stub_entry->target_value; | |
6224 | branch_insn = 0x14000000; | |
6225 | branch_offset >>= 2; | |
6226 | branch_offset &= 0x3ffffff; | |
6227 | branch_insn |= branch_offset; | |
6228 | bfd_putl32 (branch_insn, &contents[target]); | |
6229 | ||
6230 | return TRUE; | |
6231 | } | |
6232 | ||
4106101c MS |
6233 | |
6234 | static bfd_boolean | |
6235 | _bfd_aarch64_erratum_843419_branch_to_stub (struct bfd_hash_entry *gen_entry, | |
6236 | void *in_arg) | |
6237 | { | |
6238 | struct elf_aarch64_stub_hash_entry *stub_entry | |
6239 | = (struct elf_aarch64_stub_hash_entry *) gen_entry; | |
6240 | struct erratum_835769_branch_to_stub_data *data | |
6241 | = (struct erratum_835769_branch_to_stub_data *) in_arg; | |
6242 | struct bfd_link_info *info; | |
6243 | struct elf_aarch64_link_hash_table *htab; | |
6244 | bfd_byte *contents; | |
6245 | asection *section; | |
6246 | bfd *abfd; | |
6247 | bfd_vma place; | |
6248 | uint32_t insn; | |
6249 | ||
6250 | info = data->info; | |
6251 | contents = data->contents; | |
6252 | section = data->output_section; | |
6253 | ||
6254 | htab = elf_aarch64_hash_table (info); | |
6255 | ||
6256 | if (stub_entry->target_section != section | |
6257 | || stub_entry->stub_type != aarch64_stub_erratum_843419_veneer) | |
6258 | return TRUE; | |
6259 | ||
739b5c9c TC |
6260 | BFD_ASSERT (((htab->fix_erratum_843419 & ERRAT_ADRP) && stub_entry->stub_sec) |
6261 | || (htab->fix_erratum_843419 & ERRAT_ADR)); | |
6262 | ||
6263 | /* Only update the stub section if we have one. We should always have one if | |
6264 | we're allowed to use the ADRP errata workaround, otherwise it is not | |
6265 | required. */ | |
6266 | if (stub_entry->stub_sec) | |
6267 | { | |
6268 | insn = bfd_getl32 (contents + stub_entry->target_value); | |
6269 | bfd_putl32 (insn, | |
6270 | stub_entry->stub_sec->contents + stub_entry->stub_offset); | |
6271 | } | |
4106101c MS |
6272 | |
6273 | place = (section->output_section->vma + section->output_offset | |
6274 | + stub_entry->adrp_offset); | |
6275 | insn = bfd_getl32 (contents + stub_entry->adrp_offset); | |
6276 | ||
9fca35fc | 6277 | if (!_bfd_aarch64_adrp_p (insn)) |
4106101c MS |
6278 | abort (); |
6279 | ||
6280 | bfd_signed_vma imm = | |
6281 | (_bfd_aarch64_sign_extend | |
6282 | ((bfd_vma) _bfd_aarch64_decode_adrp_imm (insn) << 12, 33) | |
6283 | - (place & 0xfff)); | |
6284 | ||
739b5c9c | 6285 | if ((htab->fix_erratum_843419 & ERRAT_ADR) |
4106101c MS |
6286 | && (imm >= AARCH64_MIN_ADRP_IMM && imm <= AARCH64_MAX_ADRP_IMM)) |
6287 | { | |
92504105 | 6288 | insn = (_bfd_aarch64_reencode_adr_imm (AARCH64_ADR_OP, imm, 0) |
4106101c MS |
6289 | | AARCH64_RT (insn)); |
6290 | bfd_putl32 (insn, contents + stub_entry->adrp_offset); | |
739b5c9c TC |
6291 | /* Stub is not needed, don't map it out. */ |
6292 | stub_entry->stub_type = aarch64_stub_none; | |
4106101c | 6293 | } |
739b5c9c | 6294 | else if (htab->fix_erratum_843419 & ERRAT_ADRP) |
4106101c MS |
6295 | { |
6296 | bfd_vma veneered_insn_loc; | |
6297 | bfd_vma veneer_entry_loc; | |
6298 | bfd_signed_vma branch_offset; | |
6299 | uint32_t branch_insn; | |
6300 | ||
6301 | veneered_insn_loc = stub_entry->target_section->output_section->vma | |
6302 | + stub_entry->target_section->output_offset | |
6303 | + stub_entry->target_value; | |
6304 | veneer_entry_loc = stub_entry->stub_sec->output_section->vma | |
6305 | + stub_entry->stub_sec->output_offset | |
6306 | + stub_entry->stub_offset; | |
6307 | branch_offset = veneer_entry_loc - veneered_insn_loc; | |
6308 | ||
6309 | abfd = stub_entry->target_section->owner; | |
6310 | if (!aarch64_valid_branch_p (veneer_entry_loc, veneered_insn_loc)) | |
4eca0228 | 6311 | _bfd_error_handler |
90b6238f | 6312 | (_("%pB: error: erratum 843419 stub out " |
4106101c MS |
6313 | "of range (input file too large)"), abfd); |
6314 | ||
6315 | branch_insn = 0x14000000; | |
6316 | branch_offset >>= 2; | |
6317 | branch_offset &= 0x3ffffff; | |
6318 | branch_insn |= branch_offset; | |
6319 | bfd_putl32 (branch_insn, contents + stub_entry->target_value); | |
6320 | } | |
739b5c9c TC |
6321 | else |
6322 | { | |
6323 | abfd = stub_entry->target_section->owner; | |
6324 | _bfd_error_handler | |
64672071 | 6325 | (_("%pB: error: erratum 843419 immediate 0x%" BFD_VMA_FMT "x " |
739b5c9c TC |
6326 | "out of range for ADR (input file too large) and " |
6327 | "--fix-cortex-a53-843419=adr used. Run the linker with " | |
6328 | "--fix-cortex-a53-843419=full instead"), abfd, imm); | |
6329 | bfd_set_error (bfd_error_bad_value); | |
6330 | /* This function is called inside a hashtable traversal and the error | |
6331 | handlers called above turn into non-fatal errors. Which means this | |
6332 | case ld returns an exit code 0 and also produces a broken object file. | |
6333 | To prevent this, issue a hard abort. */ | |
6334 | BFD_FAIL (); | |
6335 | } | |
4106101c MS |
6336 | return TRUE; |
6337 | } | |
6338 | ||
6339 | ||
68fcca92 JW |
6340 | static bfd_boolean |
6341 | elfNN_aarch64_write_section (bfd *output_bfd ATTRIBUTE_UNUSED, | |
6342 | struct bfd_link_info *link_info, | |
6343 | asection *sec, | |
6344 | bfd_byte *contents) | |
6345 | ||
6346 | { | |
6347 | struct elf_aarch64_link_hash_table *globals = | |
f872121a | 6348 | elf_aarch64_hash_table (link_info); |
68fcca92 JW |
6349 | |
6350 | if (globals == NULL) | |
6351 | return FALSE; | |
6352 | ||
6353 | /* Fix code to point to erratum 835769 stubs. */ | |
6354 | if (globals->fix_erratum_835769) | |
6355 | { | |
6356 | struct erratum_835769_branch_to_stub_data data; | |
6357 | ||
4106101c | 6358 | data.info = link_info; |
68fcca92 JW |
6359 | data.output_section = sec; |
6360 | data.contents = contents; | |
6361 | bfd_hash_traverse (&globals->stub_hash_table, | |
6362 | make_branch_to_erratum_835769_stub, &data); | |
6363 | } | |
6364 | ||
4106101c MS |
6365 | if (globals->fix_erratum_843419) |
6366 | { | |
6367 | struct erratum_835769_branch_to_stub_data data; | |
6368 | ||
6369 | data.info = link_info; | |
6370 | data.output_section = sec; | |
6371 | data.contents = contents; | |
6372 | bfd_hash_traverse (&globals->stub_hash_table, | |
6373 | _bfd_aarch64_erratum_843419_branch_to_stub, &data); | |
6374 | } | |
6375 | ||
68fcca92 JW |
6376 | return FALSE; |
6377 | } | |
6378 | ||
2aff25ba JW |
6379 | /* Return TRUE if RELOC is a relocation against the base of GOT table. */ |
6380 | ||
6381 | static bfd_boolean | |
6382 | aarch64_relocation_aginst_gp_p (bfd_reloc_code_real_type reloc) | |
6383 | { | |
6384 | return (reloc == BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14 | |
6385 | || reloc == BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15 | |
6386 | || reloc == BFD_RELOC_AARCH64_LD64_GOTOFF_LO15 | |
6387 | || reloc == BFD_RELOC_AARCH64_MOVW_GOTOFF_G0_NC | |
6388 | || reloc == BFD_RELOC_AARCH64_MOVW_GOTOFF_G1); | |
6389 | } | |
6390 | ||
40bbb79e SP |
6391 | /* Build capability meta data, i.e. size and permissions for a capability. */ |
6392 | ||
6393 | static bfd_vma | |
e10c835d | 6394 | cap_meta (size_t size, const asection *sec, bfd_boolean *guessed) |
40bbb79e SP |
6395 | { |
6396 | ||
6397 | if (size >= (1ULL << 56)) | |
6398 | return (bfd_vma) -1; | |
6399 | ||
b235f0e0 MM |
6400 | /* N.b. We are only ever using this function for Morello. |
6401 | Morello is little-endian. | |
6402 | We are returning a 64bit sized integer. | |
6403 | The format this metadata is supposed to fit is | |
6404 | | 56 bit length | 8 bit permissions | | |
6405 | This means that (in little endian layout) we need to put the 56 bit size | |
6406 | in the *lower* bits of the uint64_t. */ | |
6407 | uint64_t flags = 0; | |
40bbb79e | 6408 | if (sec->flags & SEC_CODE) |
b235f0e0 MM |
6409 | flags = 4; |
6410 | else if (sec->flags & SEC_READONLY | |
6411 | || sec->flags & SEC_ROM) | |
6412 | flags = 1; | |
6413 | else if (sec->flags & SEC_ALLOC) | |
6414 | flags = 2; | |
40bbb79e | 6415 | |
e10c835d MM |
6416 | /* We should usually be able to derive a valid set of permissions |
6417 | from the section flags. We know that when a relocation is against an | |
6418 | SHN_ABS symbol the section has no associated flags and we must guess. | |
6419 | ||
6420 | As it stands we don't know of any other instances where we do not have | |
6421 | permission flags on a section. We choose to allow instances that we do | |
6422 | not know of rather than abort on them so that if the guess is correct we | |
6423 | don't hamper anyone progressing. */ | |
b235f0e0 | 6424 | if (flags == 0) |
e10c835d MM |
6425 | { |
6426 | flags = 2; | |
6427 | *guessed = TRUE; | |
6428 | } | |
6429 | ||
b235f0e0 | 6430 | return size | (flags << 56); |
40bbb79e SP |
6431 | } |
6432 | ||
5fa80905 AC |
6433 | enum c64_section_perm_type { |
6434 | C64_SYM_UNKNOWN = 0, | |
6435 | C64_SYM_STANDARD, | |
6436 | C64_SYM_LINKER_DEF, | |
6437 | C64_SYM_LDSCRIPT_DEF, | |
6438 | C64_SYM_LDSCRIPT_START, | |
6439 | }; | |
6440 | ||
6441 | static enum c64_section_perm_type | |
6442 | c64_symbol_section_adjustment (struct elf_link_hash_entry *h, bfd_vma value, | |
6443 | asection *sym_sec, asection **ret_sec, | |
6444 | struct bfd_link_info *info) | |
6445 | { | |
6446 | if (!sym_sec) | |
6447 | return C64_SYM_UNKNOWN; | |
6448 | ||
6449 | *ret_sec = sym_sec; | |
6450 | if (!h) | |
6451 | return C64_SYM_STANDARD; | |
6452 | ||
6453 | /* Linker defined symbols are always at the start of the section they | |
6454 | track. */ | |
6455 | if (h->root.linker_def) | |
6456 | return C64_SYM_LINKER_DEF; | |
6457 | else if (h->root.ldscript_def) | |
6458 | { | |
6459 | const char *name = h->root.root.string; | |
6460 | size_t len = strlen (name); | |
6461 | ||
6462 | bfd_vma size = sym_sec->size - (value - sym_sec->vma); | |
6463 | /* The special case: the symbol is at the end of the section. | |
6464 | This could either mean that it is an end symbol or it is the | |
6465 | start of the output section following the symbol. We try to | |
6466 | guess if it is a start of the next section by reading its | |
6467 | name. This is a compatibility hack, ideally linker scripts | |
6468 | should be written such that start symbols are defined within | |
6469 | the output section it intends to track. */ | |
6470 | if (size == 0 | |
6471 | && (len > 8 && name[0] == '_' && name[1] == '_' | |
6472 | && (!strncmp (name + 2, "start_", 6) | |
6473 | || !strcmp (name + len - 6, "_start")))) | |
6474 | { | |
6475 | asection *s = bfd_sections_find_if (info->output_bfd, | |
6476 | section_start_symbol, | |
6477 | &value); | |
6478 | if (s != NULL) | |
6479 | { | |
6480 | *ret_sec = s; | |
6481 | return C64_SYM_LDSCRIPT_START; | |
6482 | } | |
6483 | } | |
6484 | return C64_SYM_LDSCRIPT_DEF; | |
6485 | } | |
6486 | return C64_SYM_STANDARD; | |
6487 | } | |
6488 | ||
40bbb79e SP |
6489 | static bfd_reloc_status_type |
6490 | c64_fixup_frag (bfd *input_bfd, struct bfd_link_info *info, | |
e10c835d MM |
6491 | bfd_reloc_code_real_type bfd_r_type, Elf_Internal_Sym *sym, |
6492 | struct elf_link_hash_entry *h, asection *sym_sec, | |
6493 | asection *reloc_sec, bfd_byte *frag_loc, bfd_vma value, | |
6494 | bfd_signed_vma addend, bfd_vma r_offset) | |
40bbb79e | 6495 | { |
5fa80905 AC |
6496 | BFD_ASSERT (h || sym); |
6497 | bfd_vma size = sym ? sym->st_size : h->size; | |
40bbb79e SP |
6498 | asection *perm_sec = sym_sec; |
6499 | bfd_boolean bounds_ok = FALSE; | |
6500 | ||
e10c835d MM |
6501 | const int aarch64_reloc_idx = bfd_r_type - BFD_RELOC_AARCH64_RELOC_START; |
6502 | const char *reloc_name = elfNN_aarch64_howto_table[aarch64_reloc_idx].name; | |
7401203c MM |
6503 | const char *sym_name; |
6504 | ||
6505 | if (sym) | |
6506 | { | |
6507 | Elf_Internal_Shdr *symtab_hdr = &elf_symtab_hdr (input_bfd); | |
6508 | sym_name = (bfd_elf_string_from_elf_section (input_bfd, | |
6509 | symtab_hdr->sh_link, | |
6510 | sym->st_name)); | |
6511 | } | |
6512 | else | |
6513 | sym_name = h->root.root.string; | |
6514 | ||
5fa80905 | 6515 | if (size == 0 && sym_sec) |
40bbb79e | 6516 | { |
5fa80905 AC |
6517 | bounds_ok = TRUE; |
6518 | enum c64_section_perm_type type | |
6519 | = c64_symbol_section_adjustment (h, value, sym_sec, &perm_sec, info); | |
40bbb79e | 6520 | |
5fa80905 | 6521 | switch (type) |
40bbb79e | 6522 | { |
5fa80905 AC |
6523 | case C64_SYM_STANDARD: |
6524 | break; | |
6525 | case C64_SYM_LINKER_DEF: | |
6526 | size = perm_sec->output_section->size; | |
6527 | break; | |
6528 | case C64_SYM_LDSCRIPT_DEF: | |
6529 | size = perm_sec->size - (value - perm_sec->vma); | |
6530 | break; | |
6531 | case C64_SYM_LDSCRIPT_START: | |
6532 | size = perm_sec->size; | |
6533 | break; | |
6534 | default: | |
6535 | abort (); | |
40bbb79e SP |
6536 | } |
6537 | } | |
6538 | ||
6539 | /* Negative addends are not allowed for capability symbols. */ | |
6540 | if (addend < 0 || (bfd_vma) addend > size) | |
6541 | return bfd_reloc_outofrange; | |
6542 | ||
5fa80905 | 6543 | bfd_vma base = value, limit = value + size; |
5a9e7a18 | 6544 | unsigned align = 0; |
40bbb79e | 6545 | |
5a9e7a18 | 6546 | if (!bounds_ok && !c64_valid_cap_range (&base, &limit, &align)) |
40bbb79e | 6547 | { |
7401203c MM |
6548 | /* Just warn about this. It's not a requirement that bounds on |
6549 | objects should be precise, so there's no reason to error out on | |
6550 | such an object. */ | |
40bbb79e | 6551 | /* xgettext:c-format */ |
7401203c MM |
6552 | _bfd_error_handler |
6553 | (_("%pB: capability range for '%s' may exceed object bounds"), | |
6554 | input_bfd, sym_name); | |
40bbb79e SP |
6555 | } |
6556 | ||
5fa80905 AC |
6557 | if (perm_sec && perm_sec->flags & SEC_CODE) |
6558 | { | |
6559 | /* Any symbol pointing into an executable section gets bounds according | |
6560 | to PCC. In this case the relocation is set up so that the value is | |
6561 | the base of the PCC, the addend is the offset from the PCC base to the | |
6562 | VA that we want, and the size is the length of the PCC range. | |
6563 | In this function we only use `value` to check the bounds make sense, | |
6564 | which is somewhat superfluous when we're using pcc_high and pcc_low | |
6565 | since we already enforced that in elfNN_c64_resize_sections. No harm | |
6566 | in instead checking that the bounds on the object that were requested | |
6567 | made sense even if they were overridden because this symbol points | |
6568 | into an executable section. | |
6569 | ||
6570 | `size` on the other hand is part of the fragment that we output to and | |
6571 | we need to change it in order to have functions that can access global | |
6572 | data or jump to other functions. */ | |
6573 | size = pcc_high - pcc_low; | |
6574 | } | |
6575 | ||
40bbb79e SP |
6576 | if (perm_sec != NULL) |
6577 | { | |
e10c835d MM |
6578 | bfd_boolean permissions_guessed = FALSE; |
6579 | bfd_vma frag = cap_meta (size, perm_sec, &permissions_guessed); | |
40bbb79e SP |
6580 | |
6581 | if (frag == (bfd_vma) -1) | |
6582 | return bfd_reloc_outofrange; | |
6583 | ||
e10c835d MM |
6584 | if (permissions_guessed) |
6585 | { | |
6586 | _bfd_error_handler (_("%pB(%pA+%#" PRIx64 "): " | |
6587 | "warning: relocation %s against symbol '%s' in " | |
6588 | "section without permission flags '%s'. " | |
6589 | "Assuming Read-Write."), | |
6590 | input_bfd, reloc_sec, r_offset, reloc_name, | |
6591 | sym_name, perm_sec->name); | |
6592 | } | |
6593 | ||
40bbb79e SP |
6594 | bfd_put_64 (input_bfd, frag, frag_loc); |
6595 | } | |
6596 | ||
6597 | return bfd_reloc_continue; | |
5fa80905 | 6598 | } |
40bbb79e | 6599 | |
5fa80905 AC |
6600 | /* Given either a local symbol SYM or global symbol H, do we need to adjust |
6601 | capability relocations against the symbol due to the fact that it points to | |
6602 | a code section? */ | |
6603 | static bfd_boolean | |
6604 | c64_symbol_adjust (struct elf_link_hash_entry *h, | |
6605 | bfd_vma value, asection *sym_sec, struct bfd_link_info *info, | |
6606 | bfd_vma *adjust_addr) | |
6607 | { | |
6608 | asection *tmp_sec; | |
6609 | enum c64_section_perm_type type | |
6610 | = c64_symbol_section_adjustment (h, value, sym_sec, &tmp_sec, info); | |
6611 | ||
6612 | if (type == C64_SYM_UNKNOWN) | |
6613 | return FALSE; | |
6614 | ||
6615 | if (tmp_sec->flags & SEC_CODE) | |
40bbb79e | 6616 | { |
5fa80905 AC |
6617 | *adjust_addr = pcc_low; |
6618 | return TRUE; | |
40bbb79e | 6619 | } |
5fa80905 AC |
6620 | |
6621 | return FALSE; | |
40bbb79e SP |
6622 | } |
6623 | ||
4e7fbb34 JW |
6624 | /* Perform a relocation as part of a final link. The input relocation type |
6625 | should be TLS relaxed. */ | |
6626 | ||
a06ea964 | 6627 | static bfd_reloc_status_type |
cec5225b | 6628 | elfNN_aarch64_final_link_relocate (reloc_howto_type *howto, |
a06ea964 NC |
6629 | bfd *input_bfd, |
6630 | bfd *output_bfd, | |
6631 | asection *input_section, | |
6632 | bfd_byte *contents, | |
6633 | Elf_Internal_Rela *rel, | |
6634 | bfd_vma value, | |
6635 | struct bfd_link_info *info, | |
6636 | asection *sym_sec, | |
6637 | struct elf_link_hash_entry *h, | |
6638 | bfd_boolean *unresolved_reloc_p, | |
6639 | bfd_boolean save_addend, | |
1419bbe5 WN |
6640 | bfd_vma *saved_addend, |
6641 | Elf_Internal_Sym *sym) | |
a06ea964 | 6642 | { |
1419bbe5 | 6643 | Elf_Internal_Shdr *symtab_hdr; |
a06ea964 | 6644 | unsigned int r_type = howto->type; |
a6bb11b2 YZ |
6645 | bfd_reloc_code_real_type bfd_r_type |
6646 | = elfNN_aarch64_bfd_reloc_from_howto (howto); | |
a06ea964 NC |
6647 | unsigned long r_symndx; |
6648 | bfd_byte *hit_data = contents + rel->r_offset; | |
96d01d93 | 6649 | bfd_vma place, off, got_entry_addr = 0; |
a06ea964 | 6650 | bfd_signed_vma signed_addend; |
cec5225b | 6651 | struct elf_aarch64_link_hash_table *globals; |
a06ea964 | 6652 | bfd_boolean weak_undef_p; |
ff07562f | 6653 | bfd_boolean relative_reloc; |
b53b1bed | 6654 | asection *base_got; |
ff07562f | 6655 | bfd_vma orig_value = value; |
ddb7fd0f | 6656 | bfd_boolean resolved_to_zero; |
0c1ded8d | 6657 | bfd_boolean abs_symbol_p; |
f0070c1e | 6658 | Elf_Internal_Sym *isym = NULL; |
50e192f0 SP |
6659 | bfd_boolean c64_rtype = FALSE; |
6660 | bfd_boolean to_c64 = FALSE; | |
a06ea964 | 6661 | |
cec5225b | 6662 | globals = elf_aarch64_hash_table (info); |
a06ea964 | 6663 | |
1419bbe5 WN |
6664 | symtab_hdr = &elf_symtab_hdr (input_bfd); |
6665 | ||
a06ea964 NC |
6666 | BFD_ASSERT (is_aarch64_elf (input_bfd)); |
6667 | ||
cec5225b | 6668 | r_symndx = ELFNN_R_SYM (rel->r_info); |
a06ea964 | 6669 | |
a06ea964 NC |
6670 | place = input_section->output_section->vma |
6671 | + input_section->output_offset + rel->r_offset; | |
6672 | ||
6673 | /* Get addend, accumulating the addend for consecutive relocs | |
6674 | which refer to the same offset. */ | |
6675 | signed_addend = saved_addend ? *saved_addend : 0; | |
6676 | signed_addend += rel->r_addend; | |
6677 | ||
6678 | weak_undef_p = (h ? h->root.type == bfd_link_hash_undefweak | |
6679 | : bfd_is_und_section (sym_sec)); | |
c691de6a | 6680 | abs_symbol_p = h != NULL && bfd_is_abs_symbol (&h->root); |
0c1ded8d | 6681 | |
f0070c1e | 6682 | if (sym) |
50e192f0 SP |
6683 | { |
6684 | isym = bfd_sym_from_r_symndx (&globals->root.sym_cache, input_bfd, | |
6685 | r_symndx); | |
6686 | BFD_ASSERT (isym != NULL); | |
6687 | to_c64 = (isym->st_target_internal & ST_BRANCH_TO_C64) != 0; | |
6688 | } | |
6689 | else | |
6690 | to_c64 = (h->target_internal & ST_BRANCH_TO_C64) != 0; | |
f0070c1e | 6691 | |
a6bb11b2 | 6692 | |
1419bbe5 WN |
6693 | /* Since STT_GNU_IFUNC symbol must go through PLT, we handle |
6694 | it here if it is defined in a non-shared object. */ | |
6695 | if (h != NULL | |
6696 | && h->type == STT_GNU_IFUNC | |
6697 | && h->def_regular) | |
6698 | { | |
6699 | asection *plt; | |
6700 | const char *name; | |
99ad26cb | 6701 | bfd_vma addend = 0; |
1419bbe5 | 6702 | |
545bc2b3 SN |
6703 | if ((input_section->flags & SEC_ALLOC) == 0) |
6704 | { | |
f657f8c4 NC |
6705 | /* If this is a SHT_NOTE section without SHF_ALLOC, treat |
6706 | STT_GNU_IFUNC symbol as STT_FUNC. */ | |
6707 | if (elf_section_type (input_section) == SHT_NOTE) | |
6708 | goto skip_ifunc; | |
6709 | ||
545bc2b3 SN |
6710 | /* Dynamic relocs are not propagated for SEC_DEBUGGING |
6711 | sections because such sections are not SEC_ALLOC and | |
6712 | thus ld.so will not process them. */ | |
6713 | if ((input_section->flags & SEC_DEBUGGING) != 0) | |
6714 | return bfd_reloc_ok; | |
6715 | ||
6716 | if (h->root.root.string) | |
6717 | name = h->root.root.string; | |
6718 | else | |
6719 | name = bfd_elf_sym_name (input_bfd, symtab_hdr, sym, NULL); | |
6720 | _bfd_error_handler | |
6721 | /* xgettext:c-format */ | |
2dcf00ce AM |
6722 | (_("%pB(%pA+%#" PRIx64 "): " |
6723 | "unresolvable %s relocation against symbol `%s'"), | |
6724 | input_bfd, input_section, (uint64_t) rel->r_offset, | |
6725 | howto->name, name); | |
545bc2b3 | 6726 | bfd_set_error (bfd_error_bad_value); |
1d75a8e2 | 6727 | return bfd_reloc_notsupported; |
545bc2b3 SN |
6728 | } |
6729 | else if (h->plt.offset == (bfd_vma) -1) | |
6730 | goto bad_ifunc_reloc; | |
1419bbe5 WN |
6731 | |
6732 | /* STT_GNU_IFUNC symbol must go through PLT. */ | |
6733 | plt = globals->root.splt ? globals->root.splt : globals->root.iplt; | |
6734 | value = (plt->output_section->vma + plt->output_offset + h->plt.offset); | |
6735 | ||
6736 | switch (bfd_r_type) | |
6737 | { | |
6738 | default: | |
dc1e8a47 | 6739 | bad_ifunc_reloc: |
1419bbe5 WN |
6740 | if (h->root.root.string) |
6741 | name = h->root.root.string; | |
6742 | else | |
6743 | name = bfd_elf_sym_name (input_bfd, symtab_hdr, sym, | |
6744 | NULL); | |
4eca0228 | 6745 | _bfd_error_handler |
695344c0 | 6746 | /* xgettext:c-format */ |
871b3ab2 | 6747 | (_("%pB: relocation %s against STT_GNU_IFUNC " |
1419bbe5 WN |
6748 | "symbol `%s' isn't handled by %s"), input_bfd, |
6749 | howto->name, name, __FUNCTION__); | |
6750 | bfd_set_error (bfd_error_bad_value); | |
1d75a8e2 | 6751 | return bfd_reloc_notsupported; |
1419bbe5 WN |
6752 | |
6753 | case BFD_RELOC_AARCH64_NN: | |
6754 | if (rel->r_addend != 0) | |
6755 | { | |
6756 | if (h->root.root.string) | |
6757 | name = h->root.root.string; | |
6758 | else | |
6759 | name = bfd_elf_sym_name (input_bfd, symtab_hdr, | |
6760 | sym, NULL); | |
4eca0228 | 6761 | _bfd_error_handler |
695344c0 | 6762 | /* xgettext:c-format */ |
871b3ab2 | 6763 | (_("%pB: relocation %s against STT_GNU_IFUNC " |
2dcf00ce AM |
6764 | "symbol `%s' has non-zero addend: %" PRId64), |
6765 | input_bfd, howto->name, name, (int64_t) rel->r_addend); | |
1419bbe5 | 6766 | bfd_set_error (bfd_error_bad_value); |
1d75a8e2 | 6767 | return bfd_reloc_notsupported; |
1419bbe5 WN |
6768 | } |
6769 | ||
6770 | /* Generate dynamic relocation only when there is a | |
6771 | non-GOT reference in a shared object. */ | |
0e1862bb | 6772 | if (bfd_link_pic (info) && h->non_got_ref) |
1419bbe5 WN |
6773 | { |
6774 | Elf_Internal_Rela outrel; | |
6775 | asection *sreloc; | |
6776 | ||
6777 | /* Need a dynamic relocation to get the real function | |
6778 | address. */ | |
6779 | outrel.r_offset = _bfd_elf_section_offset (output_bfd, | |
6780 | info, | |
6781 | input_section, | |
6782 | rel->r_offset); | |
6783 | if (outrel.r_offset == (bfd_vma) -1 | |
6784 | || outrel.r_offset == (bfd_vma) -2) | |
6785 | abort (); | |
6786 | ||
6787 | outrel.r_offset += (input_section->output_section->vma | |
6788 | + input_section->output_offset); | |
6789 | ||
6790 | if (h->dynindx == -1 | |
6791 | || h->forced_local | |
0e1862bb | 6792 | || bfd_link_executable (info)) |
1419bbe5 WN |
6793 | { |
6794 | /* This symbol is resolved locally. */ | |
e19e9199 SP |
6795 | outrel.r_info = (elf_aarch64_hash_entry (h)->got_type |
6796 | == GOT_CAP | |
6797 | ? ELFNN_R_INFO (0, MORELLO_R (IRELATIVE)) | |
6798 | : ELFNN_R_INFO (0, AARCH64_R (IRELATIVE))); | |
1419bbe5 WN |
6799 | outrel.r_addend = (h->root.u.def.value |
6800 | + h->root.u.def.section->output_section->vma | |
6801 | + h->root.u.def.section->output_offset); | |
6802 | } | |
6803 | else | |
6804 | { | |
6805 | outrel.r_info = ELFNN_R_INFO (h->dynindx, r_type); | |
6806 | outrel.r_addend = 0; | |
6807 | } | |
6808 | ||
6809 | sreloc = globals->root.irelifunc; | |
6810 | elf_append_rela (output_bfd, sreloc, &outrel); | |
6811 | ||
6812 | /* If this reloc is against an external symbol, we | |
6813 | do not want to fiddle with the addend. Otherwise, | |
6814 | we need to include the symbol value so that it | |
6815 | becomes an addend for the dynamic reloc. For an | |
6816 | internal symbol, we have updated addend. */ | |
6817 | return bfd_reloc_ok; | |
6818 | } | |
6819 | /* FALLTHROUGH */ | |
e19e9199 SP |
6820 | case BFD_RELOC_MORELLO_CALL26: |
6821 | case BFD_RELOC_MORELLO_JUMP26: | |
1419bbe5 | 6822 | case BFD_RELOC_AARCH64_CALL26: |
ce336788 | 6823 | case BFD_RELOC_AARCH64_JUMP26: |
652afeef TC |
6824 | value = _bfd_aarch64_elf_resolve_relocation (input_bfd, bfd_r_type, |
6825 | place, value, | |
1419bbe5 WN |
6826 | signed_addend, |
6827 | weak_undef_p); | |
6828 | return _bfd_aarch64_elf_put_addend (input_bfd, hit_data, bfd_r_type, | |
6829 | howto, value); | |
1419bbe5 | 6830 | case BFD_RELOC_AARCH64_ADR_GOT_PAGE: |
92504105 | 6831 | case BFD_RELOC_MORELLO_ADR_GOT_PAGE: |
1419bbe5 | 6832 | case BFD_RELOC_AARCH64_GOT_LD_PREL19: |
7018c030 | 6833 | case BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14: |
ce336788 | 6834 | case BFD_RELOC_AARCH64_LD32_GOT_LO12_NC: |
99ad26cb | 6835 | case BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15: |
dc8008f5 | 6836 | case BFD_RELOC_AARCH64_MOVW_GOTOFF_G0_NC: |
74a1bfe1 | 6837 | case BFD_RELOC_AARCH64_MOVW_GOTOFF_G1: |
a2e1db00 | 6838 | case BFD_RELOC_AARCH64_LD64_GOTOFF_LO15: |
ce336788 | 6839 | case BFD_RELOC_AARCH64_LD64_GOT_LO12_NC: |
a1bdea65 | 6840 | case BFD_RELOC_MORELLO_LD128_GOT_LO12_NC: |
1419bbe5 WN |
6841 | base_got = globals->root.sgot; |
6842 | off = h->got.offset; | |
6843 | ||
6844 | if (base_got == NULL) | |
6845 | abort (); | |
6846 | ||
6847 | if (off == (bfd_vma) -1) | |
6848 | { | |
6849 | bfd_vma plt_index; | |
6850 | ||
6851 | /* We can't use h->got.offset here to save state, or | |
6852 | even just remember the offset, as finish_dynamic_symbol | |
6853 | would use that as offset into .got. */ | |
6854 | ||
6855 | if (globals->root.splt != NULL) | |
6856 | { | |
b1ee0cc4 WN |
6857 | plt_index = ((h->plt.offset - globals->plt_header_size) / |
6858 | globals->plt_entry_size); | |
a1bdea65 | 6859 | off = (plt_index + 3) * GOT_ENTRY_SIZE (globals); |
1419bbe5 WN |
6860 | base_got = globals->root.sgotplt; |
6861 | } | |
6862 | else | |
6863 | { | |
6864 | plt_index = h->plt.offset / globals->plt_entry_size; | |
a1bdea65 | 6865 | off = plt_index * GOT_ENTRY_SIZE (globals); |
1419bbe5 WN |
6866 | base_got = globals->root.igotplt; |
6867 | } | |
6868 | ||
6869 | if (h->dynindx == -1 | |
6870 | || h->forced_local | |
6871 | || info->symbolic) | |
6872 | { | |
6873 | /* This references the local definition. We must | |
6874 | initialize this entry in the global offset table. | |
6875 | Since the offset must always be a multiple of 8, | |
6876 | we use the least significant bit to record | |
6877 | whether we have initialized it already. | |
6878 | ||
6879 | When doing a dynamic link, we create a .rela.got | |
6880 | relocation entry to initialize the value. This | |
6881 | is done in the finish_dynamic_symbol routine. */ | |
6882 | if ((off & 1) != 0) | |
6883 | off &= ~1; | |
6884 | else | |
6885 | { | |
6886 | bfd_put_NN (output_bfd, value, | |
6887 | base_got->contents + off); | |
6888 | /* Note that this is harmless as -1 | 1 still is -1. */ | |
6889 | h->got.offset |= 1; | |
6890 | } | |
6891 | } | |
6892 | value = (base_got->output_section->vma | |
6893 | + base_got->output_offset + off); | |
6894 | } | |
6895 | else | |
6896 | value = aarch64_calculate_got_entry_vma (h, globals, info, | |
6897 | value, output_bfd, | |
6898 | unresolved_reloc_p); | |
a0becb89 | 6899 | |
2aff25ba JW |
6900 | if (aarch64_relocation_aginst_gp_p (bfd_r_type)) |
6901 | addend = (globals->root.sgot->output_section->vma | |
6902 | + globals->root.sgot->output_offset); | |
a0becb89 | 6903 | |
652afeef TC |
6904 | value = _bfd_aarch64_elf_resolve_relocation (input_bfd, bfd_r_type, |
6905 | place, value, | |
99ad26cb | 6906 | addend, weak_undef_p); |
1419bbe5 | 6907 | return _bfd_aarch64_elf_put_addend (input_bfd, hit_data, bfd_r_type, howto, value); |
1419bbe5 | 6908 | case BFD_RELOC_AARCH64_ADD_LO12: |
ce336788 | 6909 | case BFD_RELOC_AARCH64_ADR_HI21_PCREL: |
92504105 | 6910 | case BFD_RELOC_MORELLO_ADR_HI20_PCREL: |
1419bbe5 WN |
6911 | break; |
6912 | } | |
6913 | } | |
6914 | ||
f657f8c4 | 6915 | skip_ifunc: |
ddb7fd0f L |
6916 | resolved_to_zero = (h != NULL |
6917 | && UNDEFWEAK_NO_DYNAMIC_RELOC (info, h)); | |
6918 | ||
a6bb11b2 | 6919 | switch (bfd_r_type) |
a06ea964 | 6920 | { |
a6bb11b2 | 6921 | case BFD_RELOC_AARCH64_NONE: |
0484b454 | 6922 | case BFD_RELOC_AARCH64_TLSDESC_ADD: |
a6bb11b2 | 6923 | case BFD_RELOC_AARCH64_TLSDESC_CALL: |
0484b454 | 6924 | case BFD_RELOC_AARCH64_TLSDESC_LDR: |
4ca9b406 | 6925 | case BFD_RELOC_MORELLO_TLSDESC_CALL: |
a06ea964 NC |
6926 | *unresolved_reloc_p = FALSE; |
6927 | return bfd_reloc_ok; | |
6928 | ||
a6bb11b2 | 6929 | case BFD_RELOC_AARCH64_NN: |
a06ea964 NC |
6930 | |
6931 | /* When generating a shared object or relocatable executable, these | |
07d6d2b8 AM |
6932 | relocations are copied into the output file to be resolved at |
6933 | run time. */ | |
6353d82b JW |
6934 | if (((bfd_link_pic (info) |
6935 | || globals->root.is_relocatable_executable) | |
6936 | && (input_section->flags & SEC_ALLOC) | |
6937 | && (h == NULL | |
ddb7fd0f L |
6938 | || (ELF_ST_VISIBILITY (h->other) == STV_DEFAULT |
6939 | && !resolved_to_zero) | |
6353d82b JW |
6940 | || h->root.type != bfd_link_hash_undefweak)) |
6941 | /* Or we are creating an executable, we may need to keep relocations | |
6942 | for symbols satisfied by a dynamic library if we manage to avoid | |
6943 | copy relocs for the symbol. */ | |
6944 | || (ELIMINATE_COPY_RELOCS | |
6945 | && !bfd_link_pic (info) | |
6946 | && h != NULL | |
6947 | && (input_section->flags & SEC_ALLOC) | |
6948 | && h->dynindx != -1 | |
6949 | && !h->non_got_ref | |
6950 | && ((h->def_dynamic | |
6951 | && !h->def_regular) | |
6952 | || h->root.type == bfd_link_hash_undefweak | |
6953 | || h->root.type == bfd_link_hash_undefined))) | |
a06ea964 NC |
6954 | { |
6955 | Elf_Internal_Rela outrel; | |
6956 | bfd_byte *loc; | |
6957 | bfd_boolean skip, relocate; | |
6958 | asection *sreloc; | |
6959 | ||
6960 | *unresolved_reloc_p = FALSE; | |
6961 | ||
a06ea964 NC |
6962 | skip = FALSE; |
6963 | relocate = FALSE; | |
6964 | ||
6965 | outrel.r_addend = signed_addend; | |
6966 | outrel.r_offset = | |
6967 | _bfd_elf_section_offset (output_bfd, info, input_section, | |
6968 | rel->r_offset); | |
6969 | if (outrel.r_offset == (bfd_vma) - 1) | |
6970 | skip = TRUE; | |
6971 | else if (outrel.r_offset == (bfd_vma) - 2) | |
6972 | { | |
6973 | skip = TRUE; | |
6974 | relocate = TRUE; | |
6975 | } | |
0c1ded8d RL |
6976 | else if (abs_symbol_p) |
6977 | { | |
6978 | /* Local absolute symbol. */ | |
6979 | skip = (h->forced_local || (h->dynindx == -1)); | |
6980 | relocate = skip; | |
6981 | } | |
a06ea964 NC |
6982 | |
6983 | outrel.r_offset += (input_section->output_section->vma | |
6984 | + input_section->output_offset); | |
6985 | ||
6986 | if (skip) | |
6987 | memset (&outrel, 0, sizeof outrel); | |
6988 | else if (h != NULL | |
6989 | && h->dynindx != -1 | |
0e1862bb | 6990 | && (!bfd_link_pic (info) |
0c1ded8d | 6991 | || !(bfd_link_pie (info) || SYMBOLIC_BIND (info, h)) |
0e1862bb | 6992 | || !h->def_regular)) |
cec5225b | 6993 | outrel.r_info = ELFNN_R_INFO (h->dynindx, r_type); |
a06ea964 NC |
6994 | else |
6995 | { | |
6996 | int symbol; | |
6997 | ||
6998 | /* On SVR4-ish systems, the dynamic loader cannot | |
6999 | relocate the text and data segments independently, | |
7000 | so the symbol does not matter. */ | |
7001 | symbol = 0; | |
1f56df9d | 7002 | relocate = globals->no_apply_dynamic_relocs ? FALSE : TRUE; |
a6bb11b2 | 7003 | outrel.r_info = ELFNN_R_INFO (symbol, AARCH64_R (RELATIVE)); |
a06ea964 NC |
7004 | outrel.r_addend += value; |
7005 | } | |
7006 | ||
1419bbe5 WN |
7007 | sreloc = elf_section_data (input_section)->sreloc; |
7008 | if (sreloc == NULL || sreloc->contents == NULL) | |
7009 | return bfd_reloc_notsupported; | |
7010 | ||
7011 | loc = sreloc->contents + sreloc->reloc_count++ * RELOC_SIZE (globals); | |
cec5225b | 7012 | bfd_elfNN_swap_reloca_out (output_bfd, &outrel, loc); |
a06ea964 | 7013 | |
1419bbe5 | 7014 | if (sreloc->reloc_count * RELOC_SIZE (globals) > sreloc->size) |
a06ea964 NC |
7015 | { |
7016 | /* Sanity to check that we have previously allocated | |
7017 | sufficient space in the relocation section for the | |
7018 | number of relocations we actually want to emit. */ | |
7019 | abort (); | |
7020 | } | |
7021 | ||
7022 | /* If this reloc is against an external symbol, we do not want to | |
7023 | fiddle with the addend. Otherwise, we need to include the symbol | |
7024 | value so that it becomes an addend for the dynamic reloc. */ | |
7025 | if (!relocate) | |
7026 | return bfd_reloc_ok; | |
7027 | ||
7028 | return _bfd_final_link_relocate (howto, input_bfd, input_section, | |
7029 | contents, rel->r_offset, value, | |
7030 | signed_addend); | |
7031 | } | |
7032 | else | |
7033 | value += signed_addend; | |
7034 | break; | |
7035 | ||
e19e9199 SP |
7036 | case BFD_RELOC_MORELLO_CALL26: |
7037 | case BFD_RELOC_MORELLO_JUMP26: | |
a6bb11b2 | 7038 | case BFD_RELOC_AARCH64_CALL26: |
ce336788 | 7039 | case BFD_RELOC_AARCH64_JUMP26: |
a06ea964 NC |
7040 | { |
7041 | asection *splt = globals->root.splt; | |
c7cd2917 SP |
7042 | bfd_boolean via_plt_p = |
7043 | splt != NULL && h != NULL && h->plt.offset != (bfd_vma) - 1; | |
a06ea964 NC |
7044 | |
7045 | /* A call to an undefined weak symbol is converted to a jump to | |
7046 | the next instruction unless a PLT entry will be created. | |
7047 | The jump to the next instruction is optimized as a NOP. | |
7048 | Do the same for local undefined symbols. */ | |
7049 | if (weak_undef_p && ! via_plt_p) | |
7050 | { | |
7051 | bfd_putl32 (INSN_NOP, hit_data); | |
7052 | return bfd_reloc_ok; | |
7053 | } | |
7054 | ||
7055 | /* If the call goes through a PLT entry, make sure to | |
7056 | check distance to the right destination address. */ | |
7057 | if (via_plt_p) | |
07f9ddfe JW |
7058 | value = (splt->output_section->vma |
7059 | + splt->output_offset + h->plt.offset); | |
7060 | ||
7061 | /* Check if a stub has to be inserted because the destination | |
7062 | is too far away. */ | |
7063 | struct elf_aarch64_stub_hash_entry *stub_entry = NULL; | |
2f340668 | 7064 | |
50e192f0 SP |
7065 | enum elf_aarch64_stub_type c64_stub = aarch64_stub_none; |
7066 | ||
7067 | /* Figure out if we need an interworking stub and if yes, what | |
7068 | kind. */ | |
7069 | if (!via_plt_p) | |
7070 | c64_stub = aarch64_interwork_stub (r_type, to_c64); | |
7071 | ||
2f340668 JW |
7072 | /* If the branch destination is directed to plt stub, "value" will be |
7073 | the final destination, otherwise we should plus signed_addend, it may | |
7074 | contain non-zero value, for example call to local function symbol | |
7075 | which are turned into "sec_sym + sec_off", and sec_off is kept in | |
7076 | signed_addend. */ | |
50e192f0 SP |
7077 | if (c64_stub != aarch64_stub_none |
7078 | || (aarch64_branch_reloc_p (r_type) | |
7079 | && !aarch64_valid_branch_p ((via_plt_p ? value | |
7080 | : value + signed_addend), place))) | |
7081 | { | |
7082 | /* The target is out of reach, so redirect the branch to | |
7083 | the local stub for this function. */ | |
7084 | stub_entry = elfNN_aarch64_get_stub_entry (input_section, sym_sec, | |
7085 | h, rel, globals, | |
7086 | c64_stub); | |
7087 | } | |
7088 | ||
07f9ddfe | 7089 | if (stub_entry != NULL) |
2f340668 JW |
7090 | { |
7091 | value = (stub_entry->stub_offset | |
7092 | + stub_entry->stub_sec->output_offset | |
7093 | + stub_entry->stub_sec->output_section->vma); | |
7094 | ||
7095 | /* We have redirected the destination to stub entry address, | |
7096 | so ignore any addend record in the original rela entry. */ | |
7097 | signed_addend = 0; | |
7098 | } | |
a06ea964 | 7099 | } |
652afeef TC |
7100 | value = _bfd_aarch64_elf_resolve_relocation (input_bfd, bfd_r_type, |
7101 | place, value, | |
caed7120 | 7102 | signed_addend, weak_undef_p); |
07f9ddfe | 7103 | *unresolved_reloc_p = FALSE; |
a06ea964 NC |
7104 | break; |
7105 | ||
dcbd20eb JW |
7106 | case BFD_RELOC_AARCH64_16_PCREL: |
7107 | case BFD_RELOC_AARCH64_32_PCREL: | |
7108 | case BFD_RELOC_AARCH64_64_PCREL: | |
ce336788 JW |
7109 | case BFD_RELOC_AARCH64_ADR_HI21_NC_PCREL: |
7110 | case BFD_RELOC_AARCH64_ADR_HI21_PCREL: | |
92504105 SP |
7111 | case BFD_RELOC_MORELLO_ADR_HI20_NC_PCREL: |
7112 | case BFD_RELOC_MORELLO_ADR_HI20_PCREL: | |
ce336788 JW |
7113 | case BFD_RELOC_AARCH64_ADR_LO21_PCREL: |
7114 | case BFD_RELOC_AARCH64_LD_LO19_PCREL: | |
f7d2c675 | 7115 | case BFD_RELOC_MORELLO_LD_LO17_PCREL: |
1daf502a RL |
7116 | case BFD_RELOC_AARCH64_MOVW_PREL_G0: |
7117 | case BFD_RELOC_AARCH64_MOVW_PREL_G0_NC: | |
7118 | case BFD_RELOC_AARCH64_MOVW_PREL_G1: | |
7119 | case BFD_RELOC_AARCH64_MOVW_PREL_G1_NC: | |
7120 | case BFD_RELOC_AARCH64_MOVW_PREL_G2: | |
7121 | case BFD_RELOC_AARCH64_MOVW_PREL_G2_NC: | |
7122 | case BFD_RELOC_AARCH64_MOVW_PREL_G3: | |
0e1862bb | 7123 | if (bfd_link_pic (info) |
dcbd20eb JW |
7124 | && (input_section->flags & SEC_ALLOC) != 0 |
7125 | && (input_section->flags & SEC_READONLY) != 0 | |
d68f1976 | 7126 | && !SYMBOL_REFERENCES_LOCAL (info, h)) |
dcbd20eb JW |
7127 | { |
7128 | int howto_index = bfd_r_type - BFD_RELOC_AARCH64_RELOC_START; | |
7129 | ||
4eca0228 | 7130 | _bfd_error_handler |
695344c0 | 7131 | /* xgettext:c-format */ |
871b3ab2 | 7132 | (_("%pB: relocation %s against symbol `%s' which may bind " |
d68f1976 JW |
7133 | "externally can not be used when making a shared object; " |
7134 | "recompile with -fPIC"), | |
dcbd20eb JW |
7135 | input_bfd, elfNN_aarch64_howto_table[howto_index].name, |
7136 | h->root.root.string); | |
7137 | bfd_set_error (bfd_error_bad_value); | |
1d75a8e2 | 7138 | return bfd_reloc_notsupported; |
dcbd20eb | 7139 | } |
c7cd2917 SP |
7140 | value = _bfd_aarch64_elf_resolve_relocation (input_bfd, bfd_r_type, |
7141 | place, value, | |
7142 | signed_addend, | |
7143 | weak_undef_p); | |
8b21361b | 7144 | |
f0070c1e SP |
7145 | if (bfd_r_type == BFD_RELOC_AARCH64_ADR_LO21_PCREL && isym != NULL |
7146 | && isym->st_target_internal & ST_BRANCH_TO_C64) | |
8b21361b | 7147 | value |= 1; |
c7cd2917 SP |
7148 | break; |
7149 | ||
e19e9199 SP |
7150 | case BFD_RELOC_MORELLO_BRANCH19: |
7151 | case BFD_RELOC_MORELLO_TSTBR14: | |
50e192f0 SP |
7152 | c64_rtype = TRUE; |
7153 | /* Fall through. */ | |
c7cd2917 SP |
7154 | case BFD_RELOC_AARCH64_BRANCH19: |
7155 | case BFD_RELOC_AARCH64_TSTBR14: | |
7156 | if (h && h->root.type == bfd_link_hash_undefined) | |
7157 | { | |
7158 | _bfd_error_handler | |
7159 | /* xgettext:c-format */ | |
7160 | (_("%pB: conditional branch to undefined symbol `%s' " | |
7161 | "not allowed"), input_bfd, h->root.root.string); | |
7162 | bfd_set_error (bfd_error_bad_value); | |
7163 | return bfd_reloc_notsupported; | |
7164 | } | |
50e192f0 SP |
7165 | { |
7166 | int howto_index = bfd_r_type - BFD_RELOC_AARCH64_RELOC_START; | |
7167 | ||
7168 | if ((c64_rtype && !to_c64) || (!c64_rtype && to_c64)) | |
7169 | { | |
7170 | _bfd_error_handler | |
7171 | /* xgettext:c-format */ | |
7172 | (_("%pB: interworking not supported on relocation %s"), | |
7173 | input_bfd, elfNN_aarch64_howto_table[howto_index].name); | |
7174 | return bfd_reloc_notsupported; | |
7175 | } | |
7176 | } | |
1a0670f3 | 7177 | /* Fall through. */ |
dcbd20eb | 7178 | |
a6bb11b2 | 7179 | case BFD_RELOC_AARCH64_16: |
92d77487 RL |
7180 | #if ARCH_SIZE == 64 |
7181 | case BFD_RELOC_AARCH64_32: | |
7182 | #endif | |
a6bb11b2 | 7183 | case BFD_RELOC_AARCH64_ADD_LO12: |
ce336788 | 7184 | case BFD_RELOC_AARCH64_LDST128_LO12: |
a6bb11b2 YZ |
7185 | case BFD_RELOC_AARCH64_LDST16_LO12: |
7186 | case BFD_RELOC_AARCH64_LDST32_LO12: | |
7187 | case BFD_RELOC_AARCH64_LDST64_LO12: | |
ce336788 | 7188 | case BFD_RELOC_AARCH64_LDST8_LO12: |
a6bb11b2 YZ |
7189 | case BFD_RELOC_AARCH64_MOVW_G0: |
7190 | case BFD_RELOC_AARCH64_MOVW_G0_NC: | |
ce336788 | 7191 | case BFD_RELOC_AARCH64_MOVW_G0_S: |
a6bb11b2 YZ |
7192 | case BFD_RELOC_AARCH64_MOVW_G1: |
7193 | case BFD_RELOC_AARCH64_MOVW_G1_NC: | |
ce336788 | 7194 | case BFD_RELOC_AARCH64_MOVW_G1_S: |
a6bb11b2 YZ |
7195 | case BFD_RELOC_AARCH64_MOVW_G2: |
7196 | case BFD_RELOC_AARCH64_MOVW_G2_NC: | |
ce336788 | 7197 | case BFD_RELOC_AARCH64_MOVW_G2_S: |
a6bb11b2 | 7198 | case BFD_RELOC_AARCH64_MOVW_G3: |
652afeef TC |
7199 | value = _bfd_aarch64_elf_resolve_relocation (input_bfd, bfd_r_type, |
7200 | place, value, | |
caed7120 | 7201 | signed_addend, weak_undef_p); |
f0070c1e SP |
7202 | if (bfd_r_type == BFD_RELOC_AARCH64_ADD_LO12 && isym != NULL |
7203 | && isym->st_target_internal & ST_BRANCH_TO_C64) | |
8b21361b SP |
7204 | value |= 1; |
7205 | ||
a06ea964 NC |
7206 | break; |
7207 | ||
a6bb11b2 | 7208 | case BFD_RELOC_AARCH64_ADR_GOT_PAGE: |
92504105 | 7209 | case BFD_RELOC_MORELLO_ADR_GOT_PAGE: |
a6bb11b2 | 7210 | case BFD_RELOC_AARCH64_GOT_LD_PREL19: |
7018c030 | 7211 | case BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14: |
ce336788 | 7212 | case BFD_RELOC_AARCH64_LD32_GOT_LO12_NC: |
99ad26cb | 7213 | case BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15: |
ce336788 | 7214 | case BFD_RELOC_AARCH64_LD64_GOT_LO12_NC: |
a1bdea65 | 7215 | case BFD_RELOC_MORELLO_LD128_GOT_LO12_NC: |
2aff25ba JW |
7216 | case BFD_RELOC_AARCH64_LD64_GOTOFF_LO15: |
7217 | case BFD_RELOC_AARCH64_MOVW_GOTOFF_G0_NC: | |
7218 | case BFD_RELOC_AARCH64_MOVW_GOTOFF_G1: | |
8d4edc5f SP |
7219 | off = symbol_got_offset (input_bfd, h, r_symndx); |
7220 | base_got = globals->root.sgot; | |
5fa80905 | 7221 | |
c50aec72 MM |
7222 | bfd_boolean c64_reloc = |
7223 | (bfd_r_type == BFD_RELOC_MORELLO_LD128_GOT_LO12_NC | |
7224 | || bfd_r_type == BFD_RELOC_MORELLO_ADR_GOT_PAGE); | |
8d4edc5f | 7225 | |
5fa80905 AC |
7226 | if (signed_addend != 0) |
7227 | { | |
7228 | int howto_index = bfd_r_type - BFD_RELOC_AARCH64_RELOC_START; | |
7229 | _bfd_error_handler | |
7230 | /* xgettext:c-format */ | |
7231 | (_("%pB: symbol plus addend can not be placed into the GOT " | |
7232 | "for relocation %s"), | |
7233 | input_bfd, elfNN_aarch64_howto_table[howto_index].name); | |
7234 | abort (); | |
7235 | } | |
7236 | ||
8d4edc5f | 7237 | if (base_got == NULL) |
a06ea964 NC |
7238 | BFD_ASSERT (h != NULL); |
7239 | ||
ff07562f | 7240 | relative_reloc = FALSE; |
a06ea964 NC |
7241 | if (h != NULL) |
7242 | { | |
99ad26cb | 7243 | bfd_vma addend = 0; |
5fa80905 | 7244 | bfd_vma frag_value; |
ff07562f JW |
7245 | |
7246 | /* If a symbol is not dynamic and is not undefined weak, bind it | |
7247 | locally and generate a RELATIVE relocation under PIC mode. | |
7248 | ||
7249 | NOTE: one symbol may be referenced by several relocations, we | |
7250 | should only generate one RELATIVE relocation for that symbol. | |
8d4edc5f SP |
7251 | Therefore, check GOT offset mark first. |
7252 | ||
7253 | NOTE2: Symbol references via GOT in C64 static binaries without | |
7254 | PIC should always have relative relocations, so we do that here | |
7255 | early. */ | |
7256 | if (((h->dynindx == -1 | |
7257 | && !h->forced_local | |
7258 | && h->root.type != bfd_link_hash_undefweak | |
7259 | && bfd_link_pic (info)) | |
7260 | || (!bfd_link_pic (info) && bfd_link_executable (info) | |
7261 | && c64_reloc)) | |
ff07562f JW |
7262 | && !symbol_got_offset_mark_p (input_bfd, h, r_symndx)) |
7263 | relative_reloc = TRUE; | |
7264 | ||
5fa80905 AC |
7265 | if (c64_reloc |
7266 | && c64_symbol_adjust (h, value, sym_sec, info, &frag_value)) | |
7267 | signed_addend = (value | h->target_internal) - frag_value; | |
7268 | else | |
7269 | frag_value = value | h->target_internal; | |
7270 | ||
c50aec72 | 7271 | value = aarch64_calculate_got_entry_vma (h, globals, info, |
5fa80905 | 7272 | frag_value, |
a06ea964 NC |
7273 | output_bfd, |
7274 | unresolved_reloc_p); | |
ff07562f JW |
7275 | /* Record the GOT entry address which will be used when generating |
7276 | RELATIVE relocation. */ | |
7277 | if (relative_reloc) | |
8d4edc5f | 7278 | got_entry_addr = value; |
ff07562f | 7279 | |
2aff25ba | 7280 | if (aarch64_relocation_aginst_gp_p (bfd_r_type)) |
99ad26cb JW |
7281 | addend = (globals->root.sgot->output_section->vma |
7282 | + globals->root.sgot->output_offset); | |
652afeef TC |
7283 | value = _bfd_aarch64_elf_resolve_relocation (input_bfd, bfd_r_type, |
7284 | place, value, | |
99ad26cb | 7285 | addend, weak_undef_p); |
a06ea964 | 7286 | } |
b53b1bed JW |
7287 | else |
7288 | { | |
99ad26cb | 7289 | bfd_vma addend = 0; |
b53b1bed JW |
7290 | struct elf_aarch64_local_symbol *locals |
7291 | = elf_aarch64_locals (input_bfd); | |
7292 | ||
7293 | if (locals == NULL) | |
7294 | { | |
7295 | int howto_index = bfd_r_type - BFD_RELOC_AARCH64_RELOC_START; | |
4eca0228 | 7296 | _bfd_error_handler |
695344c0 | 7297 | /* xgettext:c-format */ |
90b6238f | 7298 | (_("%pB: local symbol descriptor table be NULL when applying " |
b53b1bed JW |
7299 | "relocation %s against local symbol"), |
7300 | input_bfd, elfNN_aarch64_howto_table[howto_index].name); | |
7301 | abort (); | |
7302 | } | |
7303 | ||
ff07562f JW |
7304 | got_entry_addr = (base_got->output_section->vma |
7305 | + base_got->output_offset + off); | |
b53b1bed JW |
7306 | |
7307 | if (!symbol_got_offset_mark_p (input_bfd, h, r_symndx)) | |
7308 | { | |
5fa80905 AC |
7309 | bfd_vma frag_value; |
7310 | ||
7311 | if (c64_reloc | |
7312 | && c64_symbol_adjust (h, value, sym_sec, info, &frag_value)) | |
7313 | signed_addend = (value | sym->st_target_internal) - frag_value; | |
7314 | else | |
7315 | frag_value = value | sym->st_target_internal; | |
7316 | ||
7317 | bfd_put_64 (output_bfd, frag_value, base_got->contents + off); | |
b53b1bed | 7318 | |
ff07562f JW |
7319 | /* For local symbol, we have done absolute relocation in static |
7320 | linking stage. While for shared library, we need to update the | |
7321 | content of GOT entry according to the shared object's runtime | |
7322 | base address. So, we need to generate a R_AARCH64_RELATIVE reloc | |
7323 | for dynamic linker. */ | |
c50aec72 MM |
7324 | if (bfd_link_pic (info) |
7325 | || (!bfd_link_pic (info) && bfd_link_executable (info) | |
7326 | && c64_reloc)) | |
ff07562f | 7327 | relative_reloc = TRUE; |
b53b1bed JW |
7328 | |
7329 | symbol_got_offset_mark (input_bfd, h, r_symndx); | |
7330 | } | |
7331 | ||
7332 | /* Update the relocation value to GOT entry addr as we have transformed | |
7333 | the direct data access into indirect data access through GOT. */ | |
7334 | value = got_entry_addr; | |
99ad26cb | 7335 | |
2aff25ba | 7336 | if (aarch64_relocation_aginst_gp_p (bfd_r_type)) |
99ad26cb JW |
7337 | addend = base_got->output_section->vma + base_got->output_offset; |
7338 | ||
652afeef TC |
7339 | value = _bfd_aarch64_elf_resolve_relocation (input_bfd, bfd_r_type, |
7340 | place, value, | |
99ad26cb | 7341 | addend, weak_undef_p); |
b53b1bed | 7342 | } |
ff07562f JW |
7343 | |
7344 | if (relative_reloc) | |
7345 | { | |
7346 | asection *s; | |
7347 | Elf_Internal_Rela outrel; | |
7348 | ||
a1bdea65 SP |
7349 | enum elf_aarch64_reloc_type rtype = AARCH64_R (RELATIVE); |
7350 | ||
8d4edc5f SP |
7351 | s = globals->root.srelgot; |
7352 | ||
a1bdea65 SP |
7353 | /* For a C64 relative relocation, also add size and permissions into |
7354 | the frag. */ | |
c50aec72 | 7355 | if (c64_reloc) |
a1bdea65 SP |
7356 | { |
7357 | bfd_reloc_status_type ret; | |
7358 | ||
e10c835d MM |
7359 | ret = c64_fixup_frag (input_bfd, info, bfd_r_type, sym, h, |
7360 | sym_sec, s, base_got->contents + off + 8, | |
7361 | orig_value, 0, off); | |
a1bdea65 SP |
7362 | |
7363 | if (ret != bfd_reloc_continue) | |
7364 | return ret; | |
7365 | ||
7366 | rtype = MORELLO_R (RELATIVE); | |
8d4edc5f SP |
7367 | |
7368 | if (bfd_link_executable (info) && !bfd_link_pic (info)) | |
7369 | s = globals->srelcaps; | |
7370 | ||
5fa80905 | 7371 | outrel.r_addend = signed_addend; |
a1bdea65 SP |
7372 | } |
7373 | else | |
7374 | outrel.r_addend = orig_value; | |
7375 | ||
ff07562f JW |
7376 | if (s == NULL) |
7377 | abort (); | |
7378 | ||
7379 | outrel.r_offset = got_entry_addr; | |
a1bdea65 | 7380 | outrel.r_info = ELFNN_R_INFO (0, rtype); |
ff07562f JW |
7381 | elf_append_rela (output_bfd, s, &outrel); |
7382 | } | |
a2e1db00 RL |
7383 | break; |
7384 | ||
ce336788 | 7385 | case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC: |
a6bb11b2 | 7386 | case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21: |
3c12b054 | 7387 | case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21: |
a6bb11b2 | 7388 | case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21: |
a6bb11b2 | 7389 | case BFD_RELOC_AARCH64_TLSIE_LD32_GOTTPREL_LO12_NC: |
ce336788 | 7390 | case BFD_RELOC_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC: |
043bf05a | 7391 | case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19: |
73f925cc | 7392 | case BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC: |
f69e4920 | 7393 | case BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21: |
77a69ff8 | 7394 | case BFD_RELOC_AARCH64_TLSLD_ADR_PREL21: |
a06ea964 NC |
7395 | if (globals->root.sgot == NULL) |
7396 | return bfd_reloc_notsupported; | |
7397 | ||
7398 | value = (symbol_got_offset (input_bfd, h, r_symndx) | |
7399 | + globals->root.sgot->output_section->vma | |
f44a1f8e | 7400 | + globals->root.sgot->output_offset); |
a06ea964 | 7401 | |
652afeef TC |
7402 | value = _bfd_aarch64_elf_resolve_relocation (input_bfd, bfd_r_type, |
7403 | place, value, | |
caed7120 | 7404 | 0, weak_undef_p); |
a06ea964 NC |
7405 | *unresolved_reloc_p = FALSE; |
7406 | break; | |
7407 | ||
7ba7cfe4 | 7408 | case BFD_RELOC_AARCH64_TLSGD_MOVW_G0_NC: |
94facae3 | 7409 | case BFD_RELOC_AARCH64_TLSGD_MOVW_G1: |
3b957e5b RL |
7410 | case BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G0_NC: |
7411 | case BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G1: | |
94facae3 RL |
7412 | if (globals->root.sgot == NULL) |
7413 | return bfd_reloc_notsupported; | |
7414 | ||
7415 | value = symbol_got_offset (input_bfd, h, r_symndx); | |
652afeef TC |
7416 | value = _bfd_aarch64_elf_resolve_relocation (input_bfd, bfd_r_type, |
7417 | place, value, | |
94facae3 RL |
7418 | 0, weak_undef_p); |
7419 | *unresolved_reloc_p = FALSE; | |
7420 | break; | |
7421 | ||
6ffe9a1b | 7422 | case BFD_RELOC_AARCH64_TLSLD_ADD_DTPREL_HI12: |
40fbed84 | 7423 | case BFD_RELOC_AARCH64_TLSLD_ADD_DTPREL_LO12: |
753999c1 | 7424 | case BFD_RELOC_AARCH64_TLSLD_ADD_DTPREL_LO12_NC: |
07c9aa07 JW |
7425 | case BFD_RELOC_AARCH64_TLSLD_LDST16_DTPREL_LO12: |
7426 | case BFD_RELOC_AARCH64_TLSLD_LDST16_DTPREL_LO12_NC: | |
7427 | case BFD_RELOC_AARCH64_TLSLD_LDST32_DTPREL_LO12: | |
7428 | case BFD_RELOC_AARCH64_TLSLD_LDST32_DTPREL_LO12_NC: | |
7429 | case BFD_RELOC_AARCH64_TLSLD_LDST64_DTPREL_LO12: | |
7430 | case BFD_RELOC_AARCH64_TLSLD_LDST64_DTPREL_LO12_NC: | |
7431 | case BFD_RELOC_AARCH64_TLSLD_LDST8_DTPREL_LO12: | |
7432 | case BFD_RELOC_AARCH64_TLSLD_LDST8_DTPREL_LO12_NC: | |
6ffe9a1b JW |
7433 | case BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G0: |
7434 | case BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G0_NC: | |
7435 | case BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G1: | |
7436 | case BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G1_NC: | |
7437 | case BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G2: | |
652afeef TC |
7438 | { |
7439 | if (!(weak_undef_p || elf_hash_table (info)->tls_sec)) | |
7440 | { | |
7441 | int howto_index = bfd_r_type - BFD_RELOC_AARCH64_RELOC_START; | |
7442 | _bfd_error_handler | |
7443 | /* xgettext:c-format */ | |
7444 | (_("%pB: TLS relocation %s against undefined symbol `%s'"), | |
7445 | input_bfd, elfNN_aarch64_howto_table[howto_index].name, | |
7446 | h->root.root.string); | |
7447 | bfd_set_error (bfd_error_bad_value); | |
7448 | return bfd_reloc_notsupported; | |
7449 | } | |
7450 | ||
7451 | bfd_vma def_value | |
7452 | = weak_undef_p ? 0 : signed_addend - dtpoff_base (info); | |
7453 | value = _bfd_aarch64_elf_resolve_relocation (input_bfd, bfd_r_type, | |
7454 | place, value, | |
7455 | def_value, weak_undef_p); | |
7456 | break; | |
7457 | } | |
40fbed84 | 7458 | |
a6bb11b2 YZ |
7459 | case BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_HI12: |
7460 | case BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_LO12: | |
7461 | case BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_LO12_NC: | |
e04ef022 RL |
7462 | case BFD_RELOC_AARCH64_TLSLE_LDST16_TPREL_LO12: |
7463 | case BFD_RELOC_AARCH64_TLSLE_LDST16_TPREL_LO12_NC: | |
7464 | case BFD_RELOC_AARCH64_TLSLE_LDST32_TPREL_LO12: | |
7465 | case BFD_RELOC_AARCH64_TLSLE_LDST32_TPREL_LO12_NC: | |
7466 | case BFD_RELOC_AARCH64_TLSLE_LDST64_TPREL_LO12: | |
7467 | case BFD_RELOC_AARCH64_TLSLE_LDST64_TPREL_LO12_NC: | |
7468 | case BFD_RELOC_AARCH64_TLSLE_LDST8_TPREL_LO12: | |
7469 | case BFD_RELOC_AARCH64_TLSLE_LDST8_TPREL_LO12_NC: | |
a6bb11b2 YZ |
7470 | case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0: |
7471 | case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC: | |
7472 | case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1: | |
7473 | case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1_NC: | |
7474 | case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G2: | |
652afeef TC |
7475 | { |
7476 | if (!(weak_undef_p || elf_hash_table (info)->tls_sec)) | |
7477 | { | |
7478 | int howto_index = bfd_r_type - BFD_RELOC_AARCH64_RELOC_START; | |
7479 | _bfd_error_handler | |
7480 | /* xgettext:c-format */ | |
7481 | (_("%pB: TLS relocation %s against undefined symbol `%s'"), | |
7482 | input_bfd, elfNN_aarch64_howto_table[howto_index].name, | |
7483 | h->root.root.string); | |
7484 | bfd_set_error (bfd_error_bad_value); | |
7485 | return bfd_reloc_notsupported; | |
7486 | } | |
7487 | ||
7488 | bfd_vma def_value | |
7489 | = weak_undef_p ? 0 : signed_addend - tpoff_base (info); | |
7490 | value = _bfd_aarch64_elf_resolve_relocation (input_bfd, bfd_r_type, | |
7491 | place, value, | |
7492 | def_value, weak_undef_p); | |
7493 | *unresolved_reloc_p = FALSE; | |
7494 | break; | |
7495 | } | |
a06ea964 | 7496 | |
f955cccf | 7497 | case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12: |
a6bb11b2 | 7498 | case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21: |
4ca9b406 | 7499 | case BFD_RELOC_MORELLO_TLSDESC_ADR_PAGE20: |
389b8029 | 7500 | case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21: |
a6bb11b2 | 7501 | case BFD_RELOC_AARCH64_TLSDESC_LD32_LO12_NC: |
f955cccf | 7502 | case BFD_RELOC_AARCH64_TLSDESC_LD64_LO12: |
1ada945d | 7503 | case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19: |
4ca9b406 | 7504 | case BFD_RELOC_MORELLO_TLSDESC_LD128_LO12: |
a06ea964 NC |
7505 | if (globals->root.sgot == NULL) |
7506 | return bfd_reloc_notsupported; | |
a06ea964 NC |
7507 | value = (symbol_tlsdesc_got_offset (input_bfd, h, r_symndx) |
7508 | + globals->root.sgotplt->output_section->vma | |
f44a1f8e | 7509 | + globals->root.sgotplt->output_offset |
a06ea964 NC |
7510 | + globals->sgotplt_jump_table_size); |
7511 | ||
652afeef TC |
7512 | value = _bfd_aarch64_elf_resolve_relocation (input_bfd, bfd_r_type, |
7513 | place, value, | |
caed7120 | 7514 | 0, weak_undef_p); |
a06ea964 NC |
7515 | *unresolved_reloc_p = FALSE; |
7516 | break; | |
7517 | ||
0484b454 RL |
7518 | case BFD_RELOC_AARCH64_TLSDESC_OFF_G0_NC: |
7519 | case BFD_RELOC_AARCH64_TLSDESC_OFF_G1: | |
7520 | if (globals->root.sgot == NULL) | |
7521 | return bfd_reloc_notsupported; | |
7522 | ||
7523 | value = (symbol_tlsdesc_got_offset (input_bfd, h, r_symndx) | |
7524 | + globals->root.sgotplt->output_section->vma | |
7525 | + globals->root.sgotplt->output_offset | |
7526 | + globals->sgotplt_jump_table_size); | |
7527 | ||
7528 | value -= (globals->root.sgot->output_section->vma | |
7529 | + globals->root.sgot->output_offset); | |
7530 | ||
652afeef TC |
7531 | value = _bfd_aarch64_elf_resolve_relocation (input_bfd, bfd_r_type, |
7532 | place, value, | |
0484b454 RL |
7533 | 0, weak_undef_p); |
7534 | *unresolved_reloc_p = FALSE; | |
7535 | break; | |
7536 | ||
40bbb79e SP |
7537 | case BFD_RELOC_MORELLO_CAPINIT: |
7538 | { | |
7539 | Elf_Internal_Rela outrel; | |
7540 | ||
7541 | if (input_section->flags & SEC_READONLY) | |
7542 | { | |
7543 | _bfd_error_handler | |
7544 | /* xgettext:c-format */ | |
7545 | (_("%pB: capability relocation section must be writable"), | |
7546 | input_bfd); | |
7547 | bfd_set_error (bfd_error_bad_value); | |
7548 | return bfd_reloc_notsupported; | |
7549 | } | |
7550 | ||
7551 | outrel.r_offset = _bfd_elf_section_offset (output_bfd, info, | |
7552 | input_section, | |
7553 | rel->r_offset); | |
7554 | ||
7555 | outrel.r_offset += (input_section->output_section->vma | |
7556 | + input_section->output_offset); | |
7557 | ||
7558 | /* Capability-aligned. */ | |
7559 | if (outrel.r_offset & 0xf) | |
7560 | return bfd_reloc_overflow; | |
7561 | ||
7562 | bfd_reloc_status_type ret; | |
7563 | ||
e10c835d MM |
7564 | ret = c64_fixup_frag (input_bfd, info, bfd_r_type, sym, h, sym_sec, |
7565 | input_section, hit_data + 8, value, | |
7566 | signed_addend, rel->r_offset); | |
40bbb79e SP |
7567 | |
7568 | if (ret != bfd_reloc_continue) | |
7569 | return ret; | |
7570 | ||
7571 | outrel.r_addend = signed_addend; | |
5fa80905 | 7572 | value |= (h != NULL ? h->target_internal : sym->st_target_internal); |
40bbb79e SP |
7573 | |
7574 | /* Emit a dynamic relocation if we are building PIC. */ | |
7575 | if (h != NULL | |
7576 | && h->dynindx != -1 | |
7577 | && bfd_link_pic (info) | |
7578 | && !SYMBOL_REFERENCES_LOCAL (info, h)) | |
7579 | outrel.r_info = ELFNN_R_INFO (h->dynindx, r_type); | |
7580 | else | |
7581 | outrel.r_info = ELFNN_R_INFO (0, MORELLO_R (RELATIVE)); | |
7582 | ||
5fa80905 AC |
7583 | /* Symbols without size information get bounds to the |
7584 | whole section: adjust the base of the capability to the | |
7585 | start of the section and set the addend to obtain the | |
7586 | correct address for the symbol. */ | |
7587 | bfd_vma new_value; | |
7588 | if (c64_symbol_adjust (h, value, sym_sec, info, &new_value)) | |
7589 | { | |
7590 | outrel.r_addend += (value - new_value); | |
7591 | value = new_value; | |
7592 | } | |
40bbb79e SP |
7593 | |
7594 | asection *s = globals->srelcaps; | |
7595 | ||
7596 | elf_append_rela (output_bfd, s, &outrel); | |
7597 | *unresolved_reloc_p = FALSE; | |
7598 | } | |
7599 | break; | |
7600 | ||
a06ea964 NC |
7601 | default: |
7602 | return bfd_reloc_notsupported; | |
7603 | } | |
7604 | ||
7605 | if (saved_addend) | |
7606 | *saved_addend = value; | |
7607 | ||
7608 | /* Only apply the final relocation in a sequence. */ | |
7609 | if (save_addend) | |
7610 | return bfd_reloc_continue; | |
7611 | ||
caed7120 YZ |
7612 | return _bfd_aarch64_elf_put_addend (input_bfd, hit_data, bfd_r_type, |
7613 | howto, value); | |
a06ea964 NC |
7614 | } |
7615 | ||
2d0ca824 YN |
7616 | /* LP64 and ILP32 operates on x- and w-registers respectively. |
7617 | Next definitions take into account the difference between | |
7618 | corresponding machine codes. R means x-register if the target | |
7619 | arch is LP64, and w-register if the target is ILP32. */ | |
7620 | ||
7621 | #if ARCH_SIZE == 64 | |
7622 | # define add_R0_R0 (0x91000000) | |
7623 | # define add_R0_R0_R1 (0x8b000020) | |
7624 | # define add_R0_R1 (0x91400020) | |
7625 | # define ldr_R0 (0x58000000) | |
7626 | # define ldr_R0_mask(i) (i & 0xffffffe0) | |
7627 | # define ldr_R0_x0 (0xf9400000) | |
7628 | # define ldr_hw_R0 (0xf2a00000) | |
7629 | # define movk_R0 (0xf2800000) | |
7630 | # define movz_R0 (0xd2a00000) | |
7631 | # define movz_hw_R0 (0xd2c00000) | |
7632 | #else /*ARCH_SIZE == 32 */ | |
7633 | # define add_R0_R0 (0x11000000) | |
7634 | # define add_R0_R0_R1 (0x0b000020) | |
7635 | # define add_R0_R1 (0x11400020) | |
7636 | # define ldr_R0 (0x18000000) | |
7637 | # define ldr_R0_mask(i) (i & 0xbfffffe0) | |
7638 | # define ldr_R0_x0 (0xb9400000) | |
7639 | # define ldr_hw_R0 (0x72a00000) | |
7640 | # define movk_R0 (0x72800000) | |
7641 | # define movz_R0 (0x52a00000) | |
7642 | # define movz_hw_R0 (0x52c00000) | |
7643 | #endif | |
7644 | ||
9fca35fc TC |
7645 | /* Structure to hold payload for _bfd_aarch64_erratum_843419_clear_stub, |
7646 | it is used to identify the stub information to reset. */ | |
7647 | ||
7648 | struct erratum_843419_branch_to_stub_clear_data | |
7649 | { | |
7650 | bfd_vma adrp_offset; | |
7651 | asection *output_section; | |
7652 | }; | |
7653 | ||
7654 | /* Clear the erratum information for GEN_ENTRY if the ADRP_OFFSET and | |
7655 | section inside IN_ARG matches. The clearing is done by setting the | |
7656 | stub_type to none. */ | |
7657 | ||
7658 | static bfd_boolean | |
7659 | _bfd_aarch64_erratum_843419_clear_stub (struct bfd_hash_entry *gen_entry, | |
7660 | void *in_arg) | |
7661 | { | |
7662 | struct elf_aarch64_stub_hash_entry *stub_entry | |
7663 | = (struct elf_aarch64_stub_hash_entry *) gen_entry; | |
7664 | struct erratum_843419_branch_to_stub_clear_data *data | |
7665 | = (struct erratum_843419_branch_to_stub_clear_data *) in_arg; | |
7666 | ||
7667 | if (stub_entry->target_section != data->output_section | |
7668 | || stub_entry->stub_type != aarch64_stub_erratum_843419_veneer | |
7669 | || stub_entry->adrp_offset != data->adrp_offset) | |
7670 | return TRUE; | |
7671 | ||
7672 | /* Change the stub type instead of removing the entry, removing from the hash | |
7673 | table would be slower and we have already reserved the memory for the entry | |
7674 | so there wouldn't be much gain. Changing the stub also keeps around a | |
7675 | record of what was there before. */ | |
7676 | stub_entry->stub_type = aarch64_stub_none; | |
7677 | ||
7678 | /* We're done and there could have been only one matching stub at that | |
7679 | particular offset, so abort further traversal. */ | |
7680 | return FALSE; | |
7681 | } | |
7682 | ||
7683 | /* TLS Relaxations may relax an adrp sequence that matches the erratum 843419 | |
7684 | sequence. In this case the erratum no longer applies and we need to remove | |
7685 | the entry from the pending stub generation. This clears matching adrp insn | |
7686 | at ADRP_OFFSET in INPUT_SECTION in the stub table defined in GLOBALS. */ | |
7687 | ||
7688 | static void | |
7689 | clear_erratum_843419_entry (struct elf_aarch64_link_hash_table *globals, | |
7690 | bfd_vma adrp_offset, asection *input_section) | |
7691 | { | |
739b5c9c | 7692 | if (globals->fix_erratum_843419 & ERRAT_ADRP) |
9fca35fc TC |
7693 | { |
7694 | struct erratum_843419_branch_to_stub_clear_data data; | |
7695 | data.adrp_offset = adrp_offset; | |
7696 | data.output_section = input_section; | |
7697 | ||
7698 | bfd_hash_traverse (&globals->stub_hash_table, | |
7699 | _bfd_aarch64_erratum_843419_clear_stub, &data); | |
7700 | } | |
7701 | } | |
7702 | ||
4ca9b406 SP |
7703 | #define BUILD_MOVZ(_reg, _imm) (movz_R0 \ |
7704 | | ((((_imm) >> 16) & 0xffff) << 5) \ | |
7705 | | (_reg)) | |
7706 | #define BUILD_MOVK(_reg, _imm) (movk_R0 | (((_imm) & 0xffff) << 5) | (_reg)) | |
7707 | ||
a06ea964 NC |
7708 | /* Handle TLS relaxations. Relaxing is possible for symbols that use |
7709 | R_AARCH64_TLSDESC_ADR_{PAGE, LD64_LO12_NC, ADD_LO12_NC} during a static | |
7710 | link. | |
7711 | ||
7712 | Return bfd_reloc_ok if we're done, bfd_reloc_continue if the caller | |
7713 | is to then call final_link_relocate. Return other values in the | |
7714 | case of error. */ | |
7715 | ||
7716 | static bfd_reloc_status_type | |
4ca9b406 SP |
7717 | elfNN_aarch64_tls_relax (bfd *input_bfd, struct bfd_link_info *info, |
7718 | asection *input_section, | |
9fca35fc | 7719 | bfd_byte *contents, Elf_Internal_Rela *rel, |
4ca9b406 | 7720 | struct elf_link_hash_entry *h, unsigned long r_symndx) |
a06ea964 NC |
7721 | { |
7722 | bfd_boolean is_local = h == NULL; | |
4ca9b406 | 7723 | |
cec5225b | 7724 | unsigned int r_type = ELFNN_R_TYPE (rel->r_info); |
a06ea964 | 7725 | unsigned long insn; |
4ca9b406 SP |
7726 | bfd_vma sym_size = 0; |
7727 | struct elf_aarch64_link_hash_table *globals = elf_aarch64_hash_table (info); | |
a06ea964 NC |
7728 | |
7729 | BFD_ASSERT (globals && input_bfd && contents && rel); | |
7730 | ||
4ca9b406 SP |
7731 | if (is_local) |
7732 | { | |
7733 | if (h != NULL) | |
7734 | sym_size = h->size; | |
7735 | else | |
7736 | { | |
7737 | Elf_Internal_Sym *sym; | |
7738 | ||
7739 | sym = bfd_sym_from_r_symndx (&globals->root.sym_cache, input_bfd, | |
7740 | r_symndx); | |
7741 | BFD_ASSERT (sym != NULL); | |
7742 | sym_size = sym->st_size; | |
7743 | } | |
7744 | } | |
7745 | ||
0aa13fee | 7746 | switch (elfNN_aarch64_bfd_reloc_from_type (input_bfd, r_type)) |
a06ea964 | 7747 | { |
4ca9b406 SP |
7748 | case BFD_RELOC_MORELLO_TLSDESC_ADR_PAGE20: |
7749 | if (is_local || !bfd_link_pic (info)) | |
7750 | { | |
7751 | /* GD->LE relaxation: | |
7752 | nop => movz x1, objsize_hi16 | |
7753 | adrp x0, :tlsdesc:var => movz x0, :tprel_g1:var */ | |
7754 | bfd_putl32 (BUILD_MOVZ(1, sym_size), contents + rel->r_offset - 4); | |
7755 | bfd_putl32 (movz_R0, contents + rel->r_offset); | |
7756 | ||
7757 | /* We have relaxed the adrp into a mov, we may have to clear any | |
7758 | pending erratum fixes. */ | |
7759 | clear_erratum_843419_entry (globals, rel->r_offset, input_section); | |
7760 | return bfd_reloc_continue; | |
7761 | } | |
7762 | else | |
7763 | { | |
7764 | /* GD->IE relaxation: Not implemented. */ | |
7765 | return bfd_reloc_continue; | |
7766 | } | |
a6bb11b2 | 7767 | case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21: |
ce336788 | 7768 | case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21: |
a06ea964 NC |
7769 | if (is_local) |
7770 | { | |
7771 | /* GD->LE relaxation: | |
2d0ca824 | 7772 | adrp x0, :tlsgd:var => movz R0, :tprel_g1:var |
a06ea964 | 7773 | or |
2d0ca824 YN |
7774 | adrp x0, :tlsdesc:var => movz R0, :tprel_g1:var |
7775 | ||
7776 | Where R is x for LP64, and w for ILP32. */ | |
7777 | bfd_putl32 (movz_R0, contents + rel->r_offset); | |
9fca35fc TC |
7778 | /* We have relaxed the adrp into a mov, we may have to clear any |
7779 | pending erratum fixes. */ | |
7780 | clear_erratum_843419_entry (globals, rel->r_offset, input_section); | |
a06ea964 NC |
7781 | return bfd_reloc_continue; |
7782 | } | |
7783 | else | |
7784 | { | |
7785 | /* GD->IE relaxation: | |
7786 | adrp x0, :tlsgd:var => adrp x0, :gottprel:var | |
7787 | or | |
7788 | adrp x0, :tlsdesc:var => adrp x0, :gottprel:var | |
7789 | */ | |
a06ea964 NC |
7790 | return bfd_reloc_continue; |
7791 | } | |
7792 | ||
389b8029 MS |
7793 | case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21: |
7794 | BFD_ASSERT (0); | |
7795 | break; | |
7796 | ||
1ada945d MS |
7797 | case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19: |
7798 | if (is_local) | |
7799 | { | |
7800 | /* Tiny TLSDESC->LE relaxation: | |
07d6d2b8 AM |
7801 | ldr x1, :tlsdesc:var => movz R0, #:tprel_g1:var |
7802 | adr x0, :tlsdesc:var => movk R0, #:tprel_g0_nc:var | |
1ada945d | 7803 | .tlsdesccall var |
07d6d2b8 | 7804 | blr x1 => nop |
2d0ca824 YN |
7805 | |
7806 | Where R is x for LP64, and w for ILP32. */ | |
1ada945d MS |
7807 | BFD_ASSERT (ELFNN_R_TYPE (rel[1].r_info) == AARCH64_R (TLSDESC_ADR_PREL21)); |
7808 | BFD_ASSERT (ELFNN_R_TYPE (rel[2].r_info) == AARCH64_R (TLSDESC_CALL)); | |
7809 | ||
7810 | rel[1].r_info = ELFNN_R_INFO (ELFNN_R_SYM (rel->r_info), | |
7811 | AARCH64_R (TLSLE_MOVW_TPREL_G0_NC)); | |
7812 | rel[2].r_info = ELFNN_R_INFO (STN_UNDEF, R_AARCH64_NONE); | |
7813 | ||
2d0ca824 YN |
7814 | bfd_putl32 (movz_R0, contents + rel->r_offset); |
7815 | bfd_putl32 (movk_R0, contents + rel->r_offset + 4); | |
1ada945d MS |
7816 | bfd_putl32 (INSN_NOP, contents + rel->r_offset + 8); |
7817 | return bfd_reloc_continue; | |
7818 | } | |
7819 | else | |
7820 | { | |
7821 | /* Tiny TLSDESC->IE relaxation: | |
07d6d2b8 AM |
7822 | ldr x1, :tlsdesc:var => ldr x0, :gottprel:var |
7823 | adr x0, :tlsdesc:var => nop | |
1ada945d | 7824 | .tlsdesccall var |
07d6d2b8 | 7825 | blr x1 => nop |
1ada945d MS |
7826 | */ |
7827 | BFD_ASSERT (ELFNN_R_TYPE (rel[1].r_info) == AARCH64_R (TLSDESC_ADR_PREL21)); | |
7828 | BFD_ASSERT (ELFNN_R_TYPE (rel[2].r_info) == AARCH64_R (TLSDESC_CALL)); | |
7829 | ||
7830 | rel[1].r_info = ELFNN_R_INFO (STN_UNDEF, R_AARCH64_NONE); | |
7831 | rel[2].r_info = ELFNN_R_INFO (STN_UNDEF, R_AARCH64_NONE); | |
7832 | ||
2d0ca824 | 7833 | bfd_putl32 (ldr_R0, contents + rel->r_offset); |
1ada945d MS |
7834 | bfd_putl32 (INSN_NOP, contents + rel->r_offset + 4); |
7835 | bfd_putl32 (INSN_NOP, contents + rel->r_offset + 8); | |
7836 | return bfd_reloc_continue; | |
7837 | } | |
7838 | ||
3c12b054 MS |
7839 | case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21: |
7840 | if (is_local) | |
7841 | { | |
7842 | /* Tiny GD->LE relaxation: | |
07d6d2b8 AM |
7843 | adr x0, :tlsgd:var => mrs x1, tpidr_el0 |
7844 | bl __tls_get_addr => add R0, R1, #:tprel_hi12:x, lsl #12 | |
7845 | nop => add R0, R0, #:tprel_lo12_nc:x | |
2d0ca824 YN |
7846 | |
7847 | Where R is x for LP64, and x for Ilp32. */ | |
3c12b054 MS |
7848 | |
7849 | /* First kill the tls_get_addr reloc on the bl instruction. */ | |
7850 | BFD_ASSERT (rel->r_offset + 4 == rel[1].r_offset); | |
7851 | ||
7852 | bfd_putl32 (0xd53bd041, contents + rel->r_offset + 0); | |
2d0ca824 YN |
7853 | bfd_putl32 (add_R0_R1, contents + rel->r_offset + 4); |
7854 | bfd_putl32 (add_R0_R0, contents + rel->r_offset + 8); | |
3c12b054 MS |
7855 | |
7856 | rel[1].r_info = ELFNN_R_INFO (ELFNN_R_SYM (rel->r_info), | |
7857 | AARCH64_R (TLSLE_ADD_TPREL_LO12_NC)); | |
7858 | rel[1].r_offset = rel->r_offset + 8; | |
7859 | ||
7860 | /* Move the current relocation to the second instruction in | |
7861 | the sequence. */ | |
7862 | rel->r_offset += 4; | |
7863 | rel->r_info = ELFNN_R_INFO (ELFNN_R_SYM (rel->r_info), | |
7864 | AARCH64_R (TLSLE_ADD_TPREL_HI12)); | |
7865 | return bfd_reloc_continue; | |
7866 | } | |
7867 | else | |
7868 | { | |
7869 | /* Tiny GD->IE relaxation: | |
07d6d2b8 AM |
7870 | adr x0, :tlsgd:var => ldr R0, :gottprel:var |
7871 | bl __tls_get_addr => mrs x1, tpidr_el0 | |
7872 | nop => add R0, R0, R1 | |
2d0ca824 YN |
7873 | |
7874 | Where R is x for LP64, and w for Ilp32. */ | |
3c12b054 MS |
7875 | |
7876 | /* First kill the tls_get_addr reloc on the bl instruction. */ | |
7877 | BFD_ASSERT (rel->r_offset + 4 == rel[1].r_offset); | |
7878 | rel[1].r_info = ELFNN_R_INFO (STN_UNDEF, R_AARCH64_NONE); | |
7879 | ||
2d0ca824 | 7880 | bfd_putl32 (ldr_R0, contents + rel->r_offset); |
3c12b054 | 7881 | bfd_putl32 (0xd53bd041, contents + rel->r_offset + 4); |
2d0ca824 | 7882 | bfd_putl32 (add_R0_R0_R1, contents + rel->r_offset + 8); |
3c12b054 MS |
7883 | return bfd_reloc_continue; |
7884 | } | |
7885 | ||
ac734732 RL |
7886 | #if ARCH_SIZE == 64 |
7887 | case BFD_RELOC_AARCH64_TLSGD_MOVW_G1: | |
7888 | BFD_ASSERT (ELFNN_R_TYPE (rel[1].r_info) == AARCH64_R (TLSGD_MOVW_G0_NC)); | |
7889 | BFD_ASSERT (rel->r_offset + 12 == rel[2].r_offset); | |
7890 | BFD_ASSERT (ELFNN_R_TYPE (rel[2].r_info) == AARCH64_R (CALL26)); | |
7891 | ||
7892 | if (is_local) | |
7893 | { | |
7894 | /* Large GD->LE relaxation: | |
07d6d2b8 | 7895 | movz x0, #:tlsgd_g1:var => movz x0, #:tprel_g2:var, lsl #32 |
ac734732 | 7896 | movk x0, #:tlsgd_g0_nc:var => movk x0, #:tprel_g1_nc:var, lsl #16 |
07d6d2b8 AM |
7897 | add x0, gp, x0 => movk x0, #:tprel_g0_nc:var |
7898 | bl __tls_get_addr => mrs x1, tpidr_el0 | |
7899 | nop => add x0, x0, x1 | |
ac734732 RL |
7900 | */ |
7901 | rel[2].r_info = ELFNN_R_INFO (ELFNN_R_SYM (rel->r_info), | |
7902 | AARCH64_R (TLSLE_MOVW_TPREL_G0_NC)); | |
7903 | rel[2].r_offset = rel->r_offset + 8; | |
7904 | ||
2d0ca824 YN |
7905 | bfd_putl32 (movz_hw_R0, contents + rel->r_offset + 0); |
7906 | bfd_putl32 (ldr_hw_R0, contents + rel->r_offset + 4); | |
7907 | bfd_putl32 (movk_R0, contents + rel->r_offset + 8); | |
ac734732 | 7908 | bfd_putl32 (0xd53bd041, contents + rel->r_offset + 12); |
2d0ca824 | 7909 | bfd_putl32 (add_R0_R0_R1, contents + rel->r_offset + 16); |
ac734732 RL |
7910 | } |
7911 | else | |
7912 | { | |
7913 | /* Large GD->IE relaxation: | |
07d6d2b8 | 7914 | movz x0, #:tlsgd_g1:var => movz x0, #:gottprel_g1:var, lsl #16 |
ac734732 | 7915 | movk x0, #:tlsgd_g0_nc:var => movk x0, #:gottprel_g0_nc:var |
07d6d2b8 AM |
7916 | add x0, gp, x0 => ldr x0, [gp, x0] |
7917 | bl __tls_get_addr => mrs x1, tpidr_el0 | |
7918 | nop => add x0, x0, x1 | |
ac734732 RL |
7919 | */ |
7920 | rel[2].r_info = ELFNN_R_INFO (STN_UNDEF, R_AARCH64_NONE); | |
7921 | bfd_putl32 (0xd2a80000, contents + rel->r_offset + 0); | |
2d0ca824 | 7922 | bfd_putl32 (ldr_R0, contents + rel->r_offset + 8); |
ac734732 | 7923 | bfd_putl32 (0xd53bd041, contents + rel->r_offset + 12); |
2d0ca824 | 7924 | bfd_putl32 (add_R0_R0_R1, contents + rel->r_offset + 16); |
ac734732 RL |
7925 | } |
7926 | return bfd_reloc_continue; | |
7927 | ||
7928 | case BFD_RELOC_AARCH64_TLSGD_MOVW_G0_NC: | |
7929 | return bfd_reloc_continue; | |
7930 | #endif | |
7931 | ||
043bf05a MS |
7932 | case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19: |
7933 | return bfd_reloc_continue; | |
7934 | ||
4ca9b406 SP |
7935 | case BFD_RELOC_MORELLO_TLSDESC_LD128_LO12: |
7936 | if (is_local || !bfd_link_pic (info)) | |
7937 | { | |
7938 | /* GD->LE relaxation: | |
7939 | ldr xd, [x0, #:tlsdesc_lo12:var] => movk x0, :tprel_g0_nc:var */ | |
7940 | bfd_putl32 (movk_R0, contents + rel->r_offset); | |
7941 | return bfd_reloc_continue; | |
7942 | } | |
7943 | else | |
7944 | { | |
7945 | /* GD->IE relaxation: not implemented. */ | |
7946 | return bfd_reloc_continue; | |
7947 | } | |
a6bb11b2 | 7948 | case BFD_RELOC_AARCH64_TLSDESC_LDNN_LO12_NC: |
a06ea964 NC |
7949 | if (is_local) |
7950 | { | |
7951 | /* GD->LE relaxation: | |
7952 | ldr xd, [x0, #:tlsdesc_lo12:var] => movk x0, :tprel_g0_nc:var | |
2d0ca824 YN |
7953 | |
7954 | Where R is x for lp64 mode, and w for ILP32 mode. */ | |
7955 | bfd_putl32 (movk_R0, contents + rel->r_offset); | |
a06ea964 NC |
7956 | return bfd_reloc_continue; |
7957 | } | |
7958 | else | |
7959 | { | |
7960 | /* GD->IE relaxation: | |
2d0ca824 YN |
7961 | ldr xd, [x0, #:tlsdesc_lo12:var] => ldr R0, [x0, #:gottprel_lo12:var] |
7962 | ||
7963 | Where R is x for lp64 mode, and w for ILP32 mode. */ | |
a06ea964 | 7964 | insn = bfd_getl32 (contents + rel->r_offset); |
2d0ca824 | 7965 | bfd_putl32 (ldr_R0_mask (insn), contents + rel->r_offset); |
a06ea964 NC |
7966 | return bfd_reloc_continue; |
7967 | } | |
7968 | ||
a6bb11b2 | 7969 | case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC: |
a06ea964 NC |
7970 | if (is_local) |
7971 | { | |
7972 | /* GD->LE relaxation | |
07d6d2b8 AM |
7973 | add x0, #:tlsgd_lo12:var => movk R0, :tprel_g0_nc:var |
7974 | bl __tls_get_addr => mrs x1, tpidr_el0 | |
7975 | nop => add R0, R1, R0 | |
2d0ca824 YN |
7976 | |
7977 | Where R is x for lp64 mode, and w for ILP32 mode. */ | |
a06ea964 NC |
7978 | |
7979 | /* First kill the tls_get_addr reloc on the bl instruction. */ | |
7980 | BFD_ASSERT (rel->r_offset + 4 == rel[1].r_offset); | |
cec5225b | 7981 | rel[1].r_info = ELFNN_R_INFO (STN_UNDEF, R_AARCH64_NONE); |
a06ea964 | 7982 | |
2d0ca824 | 7983 | bfd_putl32 (movk_R0, contents + rel->r_offset); |
a06ea964 | 7984 | bfd_putl32 (0xd53bd041, contents + rel->r_offset + 4); |
2d0ca824 | 7985 | bfd_putl32 (add_R0_R0_R1, contents + rel->r_offset + 8); |
a06ea964 NC |
7986 | return bfd_reloc_continue; |
7987 | } | |
7988 | else | |
7989 | { | |
7990 | /* GD->IE relaxation | |
07d6d2b8 AM |
7991 | ADD x0, #:tlsgd_lo12:var => ldr R0, [x0, #:gottprel_lo12:var] |
7992 | BL __tls_get_addr => mrs x1, tpidr_el0 | |
a06ea964 | 7993 | R_AARCH64_CALL26 |
07d6d2b8 | 7994 | NOP => add R0, R1, R0 |
5cd1d8bc YN |
7995 | |
7996 | Where R is x for lp64 mode, and w for ilp32 mode. */ | |
a06ea964 | 7997 | |
a6bb11b2 | 7998 | BFD_ASSERT (ELFNN_R_TYPE (rel[1].r_info) == AARCH64_R (CALL26)); |
a06ea964 NC |
7999 | |
8000 | /* Remove the relocation on the BL instruction. */ | |
cec5225b | 8001 | rel[1].r_info = ELFNN_R_INFO (STN_UNDEF, R_AARCH64_NONE); |
a06ea964 | 8002 | |
a06ea964 NC |
8003 | /* We choose to fixup the BL and NOP instructions using the |
8004 | offset from the second relocation to allow flexibility in | |
8005 | scheduling instructions between the ADD and BL. */ | |
2d0ca824 | 8006 | bfd_putl32 (ldr_R0_x0, contents + rel->r_offset); |
5cd1d8bc | 8007 | bfd_putl32 (0xd53bd041, contents + rel[1].r_offset); |
2d0ca824 | 8008 | bfd_putl32 (add_R0_R0_R1, contents + rel[1].r_offset + 4); |
a06ea964 NC |
8009 | return bfd_reloc_continue; |
8010 | } | |
8011 | ||
4ca9b406 SP |
8012 | case BFD_RELOC_MORELLO_TLSDESC_CALL: |
8013 | /* GD->LE relaxation: | |
8014 | blr cd => add c0, c2, x0 */ | |
8015 | if (is_local || !bfd_link_pic (info)) | |
8016 | { | |
8017 | bfd_putl32 (0xc2a06040, contents + rel->r_offset); | |
8018 | return bfd_reloc_ok; | |
8019 | } | |
8020 | else | |
8021 | goto set_nop; | |
8022 | ||
f955cccf | 8023 | case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12: |
4ca9b406 SP |
8024 | /* GD->LE relaxation: |
8025 | ldr cd, [c0, #:tlsdesc_lo12:var] => movk x1, objsize_lo16 */ | |
8026 | if ((is_local || !bfd_link_pic (info)) | |
8027 | && ELFNN_R_TYPE (rel[1].r_info) == MORELLO_R (TLSDESC_CALL)) | |
8028 | { | |
8029 | bfd_putl32 (BUILD_MOVK(1, sym_size), contents + rel->r_offset); | |
8030 | return bfd_reloc_continue; | |
8031 | } | |
8032 | ||
8033 | /* Fall through. */ | |
8034 | case BFD_RELOC_AARCH64_TLSDESC_ADD: | |
a6bb11b2 | 8035 | case BFD_RELOC_AARCH64_TLSDESC_CALL: |
a06ea964 | 8036 | /* GD->IE/LE relaxation: |
07d6d2b8 AM |
8037 | add x0, x0, #:tlsdesc_lo12:var => nop |
8038 | blr xd => nop | |
a06ea964 | 8039 | */ |
4ca9b406 | 8040 | set_nop: |
a06ea964 NC |
8041 | bfd_putl32 (INSN_NOP, contents + rel->r_offset); |
8042 | return bfd_reloc_ok; | |
8043 | ||
0484b454 RL |
8044 | case BFD_RELOC_AARCH64_TLSDESC_LDR: |
8045 | if (is_local) | |
8046 | { | |
8047 | /* GD->LE relaxation: | |
2d0ca824 YN |
8048 | ldr xd, [gp, xn] => movk R0, #:tprel_g0_nc:var |
8049 | ||
8050 | Where R is x for lp64 mode, and w for ILP32 mode. */ | |
8051 | bfd_putl32 (movk_R0, contents + rel->r_offset); | |
0484b454 RL |
8052 | return bfd_reloc_continue; |
8053 | } | |
8054 | else | |
8055 | { | |
8056 | /* GD->IE relaxation: | |
2d0ca824 YN |
8057 | ldr xd, [gp, xn] => ldr R0, [gp, xn] |
8058 | ||
8059 | Where R is x for lp64 mode, and w for ILP32 mode. */ | |
0484b454 | 8060 | insn = bfd_getl32 (contents + rel->r_offset); |
2d0ca824 | 8061 | bfd_putl32 (ldr_R0_mask (insn), contents + rel->r_offset); |
0484b454 RL |
8062 | return bfd_reloc_ok; |
8063 | } | |
8064 | ||
8065 | case BFD_RELOC_AARCH64_TLSDESC_OFF_G0_NC: | |
8066 | /* GD->LE relaxation: | |
2d0ca824 | 8067 | movk xd, #:tlsdesc_off_g0_nc:var => movk R0, #:tprel_g1_nc:var, lsl #16 |
0484b454 | 8068 | GD->IE relaxation: |
2d0ca824 YN |
8069 | movk xd, #:tlsdesc_off_g0_nc:var => movk Rd, #:gottprel_g0_nc:var |
8070 | ||
8071 | Where R is x for lp64 mode, and w for ILP32 mode. */ | |
0484b454 | 8072 | if (is_local) |
2d0ca824 | 8073 | bfd_putl32 (ldr_hw_R0, contents + rel->r_offset); |
0484b454 RL |
8074 | return bfd_reloc_continue; |
8075 | ||
8076 | case BFD_RELOC_AARCH64_TLSDESC_OFF_G1: | |
8077 | if (is_local) | |
8078 | { | |
8079 | /* GD->LE relaxation: | |
2d0ca824 YN |
8080 | movz xd, #:tlsdesc_off_g1:var => movz R0, #:tprel_g2:var, lsl #32 |
8081 | ||
8082 | Where R is x for lp64 mode, and w for ILP32 mode. */ | |
8083 | bfd_putl32 (movz_hw_R0, contents + rel->r_offset); | |
0484b454 RL |
8084 | return bfd_reloc_continue; |
8085 | } | |
8086 | else | |
8087 | { | |
8088 | /* GD->IE relaxation: | |
2d0ca824 YN |
8089 | movz xd, #:tlsdesc_off_g1:var => movz Rd, #:gottprel_g1:var, lsl #16 |
8090 | ||
8091 | Where R is x for lp64 mode, and w for ILP32 mode. */ | |
0484b454 | 8092 | insn = bfd_getl32 (contents + rel->r_offset); |
2d0ca824 | 8093 | bfd_putl32 (movz_R0 | (insn & 0x1f), contents + rel->r_offset); |
0484b454 RL |
8094 | return bfd_reloc_continue; |
8095 | } | |
8096 | ||
a6bb11b2 | 8097 | case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21: |
a06ea964 | 8098 | /* IE->LE relaxation: |
07d6d2b8 | 8099 | adrp xd, :gottprel:var => movz Rd, :tprel_g1:var |
2d0ca824 YN |
8100 | |
8101 | Where R is x for lp64 mode, and w for ILP32 mode. */ | |
a06ea964 NC |
8102 | if (is_local) |
8103 | { | |
8104 | insn = bfd_getl32 (contents + rel->r_offset); | |
2d0ca824 | 8105 | bfd_putl32 (movz_R0 | (insn & 0x1f), contents + rel->r_offset); |
9fca35fc TC |
8106 | /* We have relaxed the adrp into a mov, we may have to clear any |
8107 | pending erratum fixes. */ | |
8108 | clear_erratum_843419_entry (globals, rel->r_offset, input_section); | |
a06ea964 NC |
8109 | } |
8110 | return bfd_reloc_continue; | |
8111 | ||
a6bb11b2 | 8112 | case BFD_RELOC_AARCH64_TLSIE_LDNN_GOTTPREL_LO12_NC: |
a06ea964 | 8113 | /* IE->LE relaxation: |
07d6d2b8 | 8114 | ldr xd, [xm, #:gottprel_lo12:var] => movk Rd, :tprel_g0_nc:var |
2d0ca824 YN |
8115 | |
8116 | Where R is x for lp64 mode, and w for ILP32 mode. */ | |
a06ea964 NC |
8117 | if (is_local) |
8118 | { | |
8119 | insn = bfd_getl32 (contents + rel->r_offset); | |
2d0ca824 | 8120 | bfd_putl32 (movk_R0 | (insn & 0x1f), contents + rel->r_offset); |
a06ea964 NC |
8121 | } |
8122 | return bfd_reloc_continue; | |
8123 | ||
259364ad JW |
8124 | case BFD_RELOC_AARCH64_TLSLD_ADR_PREL21: |
8125 | /* LD->LE relaxation (tiny): | |
8126 | adr x0, :tlsldm:x => mrs x0, tpidr_el0 | |
c1fc2d7e YN |
8127 | bl __tls_get_addr => add R0, R0, TCB_SIZE |
8128 | ||
8129 | Where R is x for lp64 mode, and w for ilp32 mode. */ | |
259364ad JW |
8130 | if (is_local) |
8131 | { | |
8132 | BFD_ASSERT (rel->r_offset + 4 == rel[1].r_offset); | |
8133 | BFD_ASSERT (ELFNN_R_TYPE (rel[1].r_info) == AARCH64_R (CALL26)); | |
8134 | /* No need of CALL26 relocation for tls_get_addr. */ | |
8135 | rel[1].r_info = ELFNN_R_INFO (STN_UNDEF, R_AARCH64_NONE); | |
8136 | bfd_putl32 (0xd53bd040, contents + rel->r_offset + 0); | |
2d0ca824 YN |
8137 | bfd_putl32 (add_R0_R0 | (TCB_SIZE << 10), |
8138 | contents + rel->r_offset + 4); | |
259364ad JW |
8139 | return bfd_reloc_ok; |
8140 | } | |
8141 | return bfd_reloc_continue; | |
8142 | ||
8143 | case BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21: | |
8144 | /* LD->LE relaxation (small): | |
8145 | adrp x0, :tlsldm:x => mrs x0, tpidr_el0 | |
8146 | */ | |
8147 | if (is_local) | |
8148 | { | |
8149 | bfd_putl32 (0xd53bd040, contents + rel->r_offset); | |
8150 | return bfd_reloc_ok; | |
8151 | } | |
8152 | return bfd_reloc_continue; | |
8153 | ||
8154 | case BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC: | |
8155 | /* LD->LE relaxation (small): | |
c1fc2d7e | 8156 | add x0, #:tlsldm_lo12:x => add R0, R0, TCB_SIZE |
259364ad | 8157 | bl __tls_get_addr => nop |
c1fc2d7e YN |
8158 | |
8159 | Where R is x for lp64 mode, and w for ilp32 mode. */ | |
259364ad JW |
8160 | if (is_local) |
8161 | { | |
8162 | BFD_ASSERT (rel->r_offset + 4 == rel[1].r_offset); | |
8163 | BFD_ASSERT (ELFNN_R_TYPE (rel[1].r_info) == AARCH64_R (CALL26)); | |
8164 | /* No need of CALL26 relocation for tls_get_addr. */ | |
8165 | rel[1].r_info = ELFNN_R_INFO (STN_UNDEF, R_AARCH64_NONE); | |
2d0ca824 YN |
8166 | bfd_putl32 (add_R0_R0 | (TCB_SIZE << 10), |
8167 | contents + rel->r_offset + 0); | |
c1fc2d7e | 8168 | bfd_putl32 (INSN_NOP, contents + rel->r_offset + 4); |
259364ad JW |
8169 | return bfd_reloc_ok; |
8170 | } | |
8171 | return bfd_reloc_continue; | |
8172 | ||
a06ea964 NC |
8173 | default: |
8174 | return bfd_reloc_continue; | |
8175 | } | |
8176 | ||
8177 | return bfd_reloc_ok; | |
8178 | } | |
8179 | ||
8180 | /* Relocate an AArch64 ELF section. */ | |
8181 | ||
8182 | static bfd_boolean | |
cec5225b | 8183 | elfNN_aarch64_relocate_section (bfd *output_bfd, |
a06ea964 NC |
8184 | struct bfd_link_info *info, |
8185 | bfd *input_bfd, | |
8186 | asection *input_section, | |
8187 | bfd_byte *contents, | |
8188 | Elf_Internal_Rela *relocs, | |
8189 | Elf_Internal_Sym *local_syms, | |
8190 | asection **local_sections) | |
8191 | { | |
8192 | Elf_Internal_Shdr *symtab_hdr; | |
8193 | struct elf_link_hash_entry **sym_hashes; | |
8194 | Elf_Internal_Rela *rel; | |
8195 | Elf_Internal_Rela *relend; | |
8196 | const char *name; | |
cec5225b | 8197 | struct elf_aarch64_link_hash_table *globals; |
a06ea964 NC |
8198 | bfd_boolean save_addend = FALSE; |
8199 | bfd_vma addend = 0; | |
8200 | ||
cec5225b | 8201 | globals = elf_aarch64_hash_table (info); |
a06ea964 NC |
8202 | |
8203 | symtab_hdr = &elf_symtab_hdr (input_bfd); | |
8204 | sym_hashes = elf_sym_hashes (input_bfd); | |
8205 | ||
8206 | rel = relocs; | |
8207 | relend = relocs + input_section->reloc_count; | |
8208 | for (; rel < relend; rel++) | |
8209 | { | |
8210 | unsigned int r_type; | |
a6bb11b2 YZ |
8211 | bfd_reloc_code_real_type bfd_r_type; |
8212 | bfd_reloc_code_real_type relaxed_bfd_r_type; | |
a06ea964 NC |
8213 | reloc_howto_type *howto; |
8214 | unsigned long r_symndx; | |
8215 | Elf_Internal_Sym *sym; | |
8216 | asection *sec; | |
8217 | struct elf_link_hash_entry *h; | |
8218 | bfd_vma relocation; | |
8219 | bfd_reloc_status_type r; | |
8220 | arelent bfd_reloc; | |
8221 | char sym_type; | |
8222 | bfd_boolean unresolved_reloc = FALSE; | |
8223 | char *error_message = NULL; | |
8224 | ||
cec5225b YZ |
8225 | r_symndx = ELFNN_R_SYM (rel->r_info); |
8226 | r_type = ELFNN_R_TYPE (rel->r_info); | |
a06ea964 | 8227 | |
0aa13fee AM |
8228 | bfd_reloc.howto = elfNN_aarch64_howto_from_type (input_bfd, r_type); |
8229 | howto = bfd_reloc.howto; | |
a06ea964 | 8230 | |
7fcfd62d | 8231 | if (howto == NULL) |
47aeb64c NC |
8232 | return _bfd_unrecognized_reloc (input_bfd, input_section, r_type); |
8233 | ||
a6bb11b2 | 8234 | bfd_r_type = elfNN_aarch64_bfd_reloc_from_howto (howto); |
7fcfd62d | 8235 | |
a06ea964 NC |
8236 | h = NULL; |
8237 | sym = NULL; | |
8238 | sec = NULL; | |
8239 | ||
8240 | if (r_symndx < symtab_hdr->sh_info) | |
8241 | { | |
8242 | sym = local_syms + r_symndx; | |
cec5225b | 8243 | sym_type = ELFNN_ST_TYPE (sym->st_info); |
a06ea964 NC |
8244 | sec = local_sections[r_symndx]; |
8245 | ||
8246 | /* An object file might have a reference to a local | |
8247 | undefined symbol. This is a daft object file, but we | |
8248 | should at least do something about it. */ | |
8249 | if (r_type != R_AARCH64_NONE && r_type != R_AARCH64_NULL | |
8250 | && bfd_is_und_section (sec) | |
8251 | && ELF_ST_BIND (sym->st_info) != STB_WEAK) | |
1a72702b AM |
8252 | (*info->callbacks->undefined_symbol) |
8253 | (info, bfd_elf_string_from_elf_section | |
8254 | (input_bfd, symtab_hdr->sh_link, sym->st_name), | |
8255 | input_bfd, input_section, rel->r_offset, TRUE); | |
a06ea964 | 8256 | |
a06ea964 | 8257 | relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel); |
1419bbe5 WN |
8258 | |
8259 | /* Relocate against local STT_GNU_IFUNC symbol. */ | |
0e1862bb | 8260 | if (!bfd_link_relocatable (info) |
1419bbe5 WN |
8261 | && ELF_ST_TYPE (sym->st_info) == STT_GNU_IFUNC) |
8262 | { | |
8263 | h = elfNN_aarch64_get_local_sym_hash (globals, input_bfd, | |
8264 | rel, FALSE); | |
8265 | if (h == NULL) | |
8266 | abort (); | |
8267 | ||
8268 | /* Set STT_GNU_IFUNC symbol value. */ | |
8269 | h->root.u.def.value = sym->st_value; | |
8270 | h->root.u.def.section = sec; | |
8271 | } | |
a06ea964 NC |
8272 | } |
8273 | else | |
8274 | { | |
62d887d4 | 8275 | bfd_boolean warned, ignored; |
a06ea964 NC |
8276 | |
8277 | RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel, | |
8278 | r_symndx, symtab_hdr, sym_hashes, | |
8279 | h, sec, relocation, | |
62d887d4 | 8280 | unresolved_reloc, warned, ignored); |
a06ea964 NC |
8281 | |
8282 | sym_type = h->type; | |
8283 | } | |
8284 | ||
8285 | if (sec != NULL && discarded_section (sec)) | |
8286 | RELOC_AGAINST_DISCARDED_SECTION (info, input_bfd, input_section, | |
8287 | rel, 1, relend, howto, 0, contents); | |
8288 | ||
0e1862bb | 8289 | if (bfd_link_relocatable (info)) |
2e0488d3 | 8290 | continue; |
a06ea964 NC |
8291 | |
8292 | if (h != NULL) | |
8293 | name = h->root.root.string; | |
8294 | else | |
8295 | { | |
8296 | name = (bfd_elf_string_from_elf_section | |
8297 | (input_bfd, symtab_hdr->sh_link, sym->st_name)); | |
8298 | if (name == NULL || *name == '\0') | |
fd361982 | 8299 | name = bfd_section_name (sec); |
a06ea964 NC |
8300 | } |
8301 | ||
8302 | if (r_symndx != 0 | |
8303 | && r_type != R_AARCH64_NONE | |
8304 | && r_type != R_AARCH64_NULL | |
8305 | && (h == NULL | |
8306 | || h->root.type == bfd_link_hash_defined | |
8307 | || h->root.type == bfd_link_hash_defweak) | |
a6bb11b2 | 8308 | && IS_AARCH64_TLS_RELOC (bfd_r_type) != (sym_type == STT_TLS)) |
a06ea964 | 8309 | { |
4eca0228 | 8310 | _bfd_error_handler |
a06ea964 | 8311 | ((sym_type == STT_TLS |
695344c0 | 8312 | /* xgettext:c-format */ |
2dcf00ce | 8313 | ? _("%pB(%pA+%#" PRIx64 "): %s used with TLS symbol %s") |
695344c0 | 8314 | /* xgettext:c-format */ |
2dcf00ce | 8315 | : _("%pB(%pA+%#" PRIx64 "): %s used with non-TLS symbol %s")), |
a06ea964 | 8316 | input_bfd, |
2dcf00ce | 8317 | input_section, (uint64_t) rel->r_offset, howto->name, name); |
a06ea964 NC |
8318 | } |
8319 | ||
f3ecc5c8 AC |
8320 | if (r_symndx |
8321 | && h | |
8322 | && IS_AARCH64_TLS_RELOC (bfd_r_type) | |
8323 | && h->root.type == bfd_link_hash_undefweak) | |
8324 | /* We have already warned about these in aarch64_check_relocs, | |
8325 | so just skip over them. */ | |
8326 | continue; | |
8327 | ||
a06ea964 | 8328 | /* We relax only if we can see that there can be a valid transition |
07d6d2b8 AM |
8329 | from a reloc type to another. |
8330 | We call elfNN_aarch64_final_link_relocate unless we're completely | |
8331 | done, i.e., the relaxation produced the final output we want. */ | |
a06ea964 | 8332 | |
4ca9b406 | 8333 | relaxed_bfd_r_type = aarch64_tls_transition (input_bfd, info, rel, |
a6bb11b2 YZ |
8334 | h, r_symndx); |
8335 | if (relaxed_bfd_r_type != bfd_r_type) | |
a06ea964 | 8336 | { |
a6bb11b2 YZ |
8337 | bfd_r_type = relaxed_bfd_r_type; |
8338 | howto = elfNN_aarch64_howto_from_bfd_reloc (bfd_r_type); | |
8339 | BFD_ASSERT (howto != NULL); | |
8340 | r_type = howto->type; | |
4ca9b406 SP |
8341 | r = elfNN_aarch64_tls_relax (input_bfd, info, input_section, |
8342 | contents, rel, h, r_symndx); | |
a06ea964 NC |
8343 | unresolved_reloc = 0; |
8344 | } | |
8345 | else | |
8346 | r = bfd_reloc_continue; | |
8347 | ||
8348 | /* There may be multiple consecutive relocations for the | |
07d6d2b8 AM |
8349 | same offset. In that case we are supposed to treat the |
8350 | output of each relocation as the addend for the next. */ | |
a06ea964 NC |
8351 | if (rel + 1 < relend |
8352 | && rel->r_offset == rel[1].r_offset | |
cec5225b YZ |
8353 | && ELFNN_R_TYPE (rel[1].r_info) != R_AARCH64_NONE |
8354 | && ELFNN_R_TYPE (rel[1].r_info) != R_AARCH64_NULL) | |
a06ea964 NC |
8355 | save_addend = TRUE; |
8356 | else | |
8357 | save_addend = FALSE; | |
8358 | ||
8359 | if (r == bfd_reloc_continue) | |
cec5225b | 8360 | r = elfNN_aarch64_final_link_relocate (howto, input_bfd, output_bfd, |
a06ea964 NC |
8361 | input_section, contents, rel, |
8362 | relocation, info, sec, | |
8363 | h, &unresolved_reloc, | |
1419bbe5 | 8364 | save_addend, &addend, sym); |
a06ea964 | 8365 | |
4ca9b406 SP |
8366 | bfd_boolean c64_rtype = FALSE; |
8367 | ||
0aa13fee | 8368 | switch (elfNN_aarch64_bfd_reloc_from_type (input_bfd, r_type)) |
a06ea964 | 8369 | { |
ce336788 | 8370 | case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC: |
a6bb11b2 | 8371 | case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21: |
3c12b054 | 8372 | case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21: |
7ba7cfe4 | 8373 | case BFD_RELOC_AARCH64_TLSGD_MOVW_G0_NC: |
94facae3 | 8374 | case BFD_RELOC_AARCH64_TLSGD_MOVW_G1: |
73f925cc | 8375 | case BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC: |
f69e4920 | 8376 | case BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21: |
77a69ff8 | 8377 | case BFD_RELOC_AARCH64_TLSLD_ADR_PREL21: |
a06ea964 NC |
8378 | if (! symbol_got_offset_mark_p (input_bfd, h, r_symndx)) |
8379 | { | |
8380 | bfd_boolean need_relocs = FALSE; | |
8381 | bfd_byte *loc; | |
8382 | int indx; | |
8383 | bfd_vma off; | |
8384 | ||
8385 | off = symbol_got_offset (input_bfd, h, r_symndx); | |
8386 | indx = h && h->dynindx != -1 ? h->dynindx : 0; | |
8387 | ||
8388 | need_relocs = | |
6dda7875 | 8389 | (!bfd_link_executable (info) || indx != 0) && |
a06ea964 NC |
8390 | (h == NULL |
8391 | || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT | |
8392 | || h->root.type != bfd_link_hash_undefweak); | |
8393 | ||
8394 | BFD_ASSERT (globals->root.srelgot != NULL); | |
8395 | ||
8396 | if (need_relocs) | |
8397 | { | |
8398 | Elf_Internal_Rela rela; | |
a6bb11b2 | 8399 | rela.r_info = ELFNN_R_INFO (indx, AARCH64_R (TLS_DTPMOD)); |
a06ea964 NC |
8400 | rela.r_addend = 0; |
8401 | rela.r_offset = globals->root.sgot->output_section->vma + | |
8402 | globals->root.sgot->output_offset + off; | |
8403 | ||
8404 | ||
8405 | loc = globals->root.srelgot->contents; | |
8406 | loc += globals->root.srelgot->reloc_count++ | |
8407 | * RELOC_SIZE (htab); | |
cec5225b | 8408 | bfd_elfNN_swap_reloca_out (output_bfd, &rela, loc); |
a06ea964 | 8409 | |
f69e4920 | 8410 | bfd_reloc_code_real_type real_type = |
0aa13fee | 8411 | elfNN_aarch64_bfd_reloc_from_type (input_bfd, r_type); |
f69e4920 JW |
8412 | |
8413 | if (real_type == BFD_RELOC_AARCH64_TLSLD_ADR_PREL21 | |
73f925cc JW |
8414 | || real_type == BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21 |
8415 | || real_type == BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC) | |
77a69ff8 JW |
8416 | { |
8417 | /* For local dynamic, don't generate DTPREL in any case. | |
8418 | Initialize the DTPREL slot into zero, so we get module | |
8419 | base address when invoke runtime TLS resolver. */ | |
8420 | bfd_put_NN (output_bfd, 0, | |
8421 | globals->root.sgot->contents + off | |
a1bdea65 | 8422 | + GOT_ENTRY_SIZE (globals)); |
77a69ff8 JW |
8423 | } |
8424 | else if (indx == 0) | |
a06ea964 | 8425 | { |
cec5225b | 8426 | bfd_put_NN (output_bfd, |
a06ea964 NC |
8427 | relocation - dtpoff_base (info), |
8428 | globals->root.sgot->contents + off | |
a1bdea65 | 8429 | + GOT_ENTRY_SIZE (globals)); |
a06ea964 NC |
8430 | } |
8431 | else | |
8432 | { | |
8433 | /* This TLS symbol is global. We emit a | |
8434 | relocation to fixup the tls offset at load | |
8435 | time. */ | |
8436 | rela.r_info = | |
a6bb11b2 | 8437 | ELFNN_R_INFO (indx, AARCH64_R (TLS_DTPREL)); |
a06ea964 NC |
8438 | rela.r_addend = 0; |
8439 | rela.r_offset = | |
8440 | (globals->root.sgot->output_section->vma | |
8441 | + globals->root.sgot->output_offset + off | |
a1bdea65 | 8442 | + GOT_ENTRY_SIZE (globals)); |
a06ea964 NC |
8443 | |
8444 | loc = globals->root.srelgot->contents; | |
8445 | loc += globals->root.srelgot->reloc_count++ | |
8446 | * RELOC_SIZE (globals); | |
cec5225b YZ |
8447 | bfd_elfNN_swap_reloca_out (output_bfd, &rela, loc); |
8448 | bfd_put_NN (output_bfd, (bfd_vma) 0, | |
a06ea964 | 8449 | globals->root.sgot->contents + off |
a1bdea65 | 8450 | + GOT_ENTRY_SIZE (globals)); |
a06ea964 NC |
8451 | } |
8452 | } | |
8453 | else | |
8454 | { | |
cec5225b | 8455 | bfd_put_NN (output_bfd, (bfd_vma) 1, |
a06ea964 | 8456 | globals->root.sgot->contents + off); |
cec5225b | 8457 | bfd_put_NN (output_bfd, |
a06ea964 NC |
8458 | relocation - dtpoff_base (info), |
8459 | globals->root.sgot->contents + off | |
a1bdea65 | 8460 | + GOT_ENTRY_SIZE (globals)); |
a06ea964 NC |
8461 | } |
8462 | ||
8463 | symbol_got_offset_mark (input_bfd, h, r_symndx); | |
8464 | } | |
8465 | break; | |
8466 | ||
a6bb11b2 YZ |
8467 | case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21: |
8468 | case BFD_RELOC_AARCH64_TLSIE_LDNN_GOTTPREL_LO12_NC: | |
043bf05a | 8469 | case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19: |
3b957e5b RL |
8470 | case BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G0_NC: |
8471 | case BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G1: | |
a06ea964 NC |
8472 | if (! symbol_got_offset_mark_p (input_bfd, h, r_symndx)) |
8473 | { | |
8474 | bfd_boolean need_relocs = FALSE; | |
8475 | bfd_byte *loc; | |
8476 | int indx; | |
8477 | bfd_vma off; | |
8478 | ||
8479 | off = symbol_got_offset (input_bfd, h, r_symndx); | |
8480 | ||
8481 | indx = h && h->dynindx != -1 ? h->dynindx : 0; | |
8482 | ||
8483 | need_relocs = | |
6dda7875 | 8484 | (!bfd_link_executable (info) || indx != 0) && |
a06ea964 NC |
8485 | (h == NULL |
8486 | || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT | |
8487 | || h->root.type != bfd_link_hash_undefweak); | |
8488 | ||
8489 | BFD_ASSERT (globals->root.srelgot != NULL); | |
8490 | ||
8491 | if (need_relocs) | |
8492 | { | |
8493 | Elf_Internal_Rela rela; | |
8494 | ||
8495 | if (indx == 0) | |
8496 | rela.r_addend = relocation - dtpoff_base (info); | |
8497 | else | |
8498 | rela.r_addend = 0; | |
8499 | ||
a6bb11b2 | 8500 | rela.r_info = ELFNN_R_INFO (indx, AARCH64_R (TLS_TPREL)); |
a06ea964 NC |
8501 | rela.r_offset = globals->root.sgot->output_section->vma + |
8502 | globals->root.sgot->output_offset + off; | |
8503 | ||
8504 | loc = globals->root.srelgot->contents; | |
8505 | loc += globals->root.srelgot->reloc_count++ | |
8506 | * RELOC_SIZE (htab); | |
8507 | ||
cec5225b | 8508 | bfd_elfNN_swap_reloca_out (output_bfd, &rela, loc); |
a06ea964 | 8509 | |
cec5225b | 8510 | bfd_put_NN (output_bfd, rela.r_addend, |
a06ea964 NC |
8511 | globals->root.sgot->contents + off); |
8512 | } | |
8513 | else | |
cec5225b | 8514 | bfd_put_NN (output_bfd, relocation - tpoff_base (info), |
a06ea964 NC |
8515 | globals->root.sgot->contents + off); |
8516 | ||
8517 | symbol_got_offset_mark (input_bfd, h, r_symndx); | |
8518 | } | |
8519 | break; | |
8520 | ||
4ca9b406 SP |
8521 | case BFD_RELOC_MORELLO_TLSDESC_ADR_PAGE20: |
8522 | case BFD_RELOC_MORELLO_TLSDESC_LD128_LO12: | |
8523 | c64_rtype = TRUE; | |
8524 | /* Fall through. */ | |
8525 | ||
f955cccf | 8526 | case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12: |
a6bb11b2 | 8527 | case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21: |
389b8029 | 8528 | case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21: |
a6bb11b2 | 8529 | case BFD_RELOC_AARCH64_TLSDESC_LDNN_LO12_NC: |
1ada945d | 8530 | case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19: |
0484b454 RL |
8531 | case BFD_RELOC_AARCH64_TLSDESC_OFF_G0_NC: |
8532 | case BFD_RELOC_AARCH64_TLSDESC_OFF_G1: | |
a06ea964 NC |
8533 | if (! symbol_tlsdesc_got_offset_mark_p (input_bfd, h, r_symndx)) |
8534 | { | |
8535 | bfd_boolean need_relocs = FALSE; | |
8536 | int indx = h && h->dynindx != -1 ? h->dynindx : 0; | |
8537 | bfd_vma off = symbol_tlsdesc_got_offset (input_bfd, h, r_symndx); | |
8538 | ||
8539 | need_relocs = (h == NULL | |
8540 | || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT | |
8541 | || h->root.type != bfd_link_hash_undefweak); | |
8542 | ||
8543 | BFD_ASSERT (globals->root.srelgot != NULL); | |
8544 | BFD_ASSERT (globals->root.sgot != NULL); | |
8545 | ||
8546 | if (need_relocs) | |
8547 | { | |
8548 | bfd_byte *loc; | |
8549 | Elf_Internal_Rela rela; | |
4ca9b406 SP |
8550 | |
8551 | rela.r_info = ELFNN_R_INFO (indx, | |
8552 | (c64_rtype ? MORELLO_R (TLSDESC) | |
8553 | : AARCH64_R (TLSDESC))); | |
a6bb11b2 | 8554 | |
a06ea964 NC |
8555 | rela.r_addend = 0; |
8556 | rela.r_offset = (globals->root.sgotplt->output_section->vma | |
8557 | + globals->root.sgotplt->output_offset | |
8558 | + off + globals->sgotplt_jump_table_size); | |
8559 | ||
8560 | if (indx == 0) | |
8561 | rela.r_addend = relocation - dtpoff_base (info); | |
8562 | ||
8563 | /* Allocate the next available slot in the PLT reloc | |
8564 | section to hold our R_AARCH64_TLSDESC, the next | |
8565 | available slot is determined from reloc_count, | |
8566 | which we step. But note, reloc_count was | |
8567 | artifically moved down while allocating slots for | |
8568 | real PLT relocs such that all of the PLT relocs | |
8569 | will fit above the initial reloc_count and the | |
8570 | extra stuff will fit below. */ | |
8571 | loc = globals->root.srelplt->contents; | |
8572 | loc += globals->root.srelplt->reloc_count++ | |
8573 | * RELOC_SIZE (globals); | |
8574 | ||
cec5225b | 8575 | bfd_elfNN_swap_reloca_out (output_bfd, &rela, loc); |
a06ea964 | 8576 | |
cec5225b | 8577 | bfd_put_NN (output_bfd, (bfd_vma) 0, |
a06ea964 NC |
8578 | globals->root.sgotplt->contents + off + |
8579 | globals->sgotplt_jump_table_size); | |
cec5225b | 8580 | bfd_put_NN (output_bfd, (bfd_vma) 0, |
a06ea964 NC |
8581 | globals->root.sgotplt->contents + off + |
8582 | globals->sgotplt_jump_table_size + | |
a1bdea65 | 8583 | GOT_ENTRY_SIZE (globals)); |
a06ea964 NC |
8584 | } |
8585 | ||
8586 | symbol_tlsdesc_got_offset_mark (input_bfd, h, r_symndx); | |
8587 | } | |
8588 | break; | |
a6bb11b2 YZ |
8589 | default: |
8590 | break; | |
a06ea964 NC |
8591 | } |
8592 | ||
a06ea964 | 8593 | /* Dynamic relocs are not propagated for SEC_DEBUGGING sections |
07d6d2b8 AM |
8594 | because such sections are not SEC_ALLOC and thus ld.so will |
8595 | not process them. */ | |
a06ea964 NC |
8596 | if (unresolved_reloc |
8597 | && !((input_section->flags & SEC_DEBUGGING) != 0 | |
8598 | && h->def_dynamic) | |
8599 | && _bfd_elf_section_offset (output_bfd, info, input_section, | |
8600 | +rel->r_offset) != (bfd_vma) - 1) | |
8601 | { | |
4eca0228 | 8602 | _bfd_error_handler |
695344c0 | 8603 | /* xgettext:c-format */ |
2dcf00ce AM |
8604 | (_("%pB(%pA+%#" PRIx64 "): " |
8605 | "unresolvable %s relocation against symbol `%s'"), | |
8606 | input_bfd, input_section, (uint64_t) rel->r_offset, howto->name, | |
a06ea964 NC |
8607 | h->root.root.string); |
8608 | return FALSE; | |
8609 | } | |
8610 | ||
8611 | if (r != bfd_reloc_ok && r != bfd_reloc_continue) | |
8612 | { | |
c674f5cd | 8613 | bfd_reloc_code_real_type real_r_type |
0aa13fee | 8614 | = elfNN_aarch64_bfd_reloc_from_type (input_bfd, r_type); |
c674f5cd | 8615 | |
a06ea964 NC |
8616 | switch (r) |
8617 | { | |
8618 | case bfd_reloc_overflow: | |
1a72702b AM |
8619 | (*info->callbacks->reloc_overflow) |
8620 | (info, (h ? &h->root : NULL), name, howto->name, (bfd_vma) 0, | |
8621 | input_bfd, input_section, rel->r_offset); | |
c674f5cd JW |
8622 | if (real_r_type == BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15 |
8623 | || real_r_type == BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14) | |
8624 | { | |
8625 | (*info->callbacks->warning) | |
8626 | (info, | |
90b6238f | 8627 | _("too many GOT entries for -fpic, " |
c674f5cd JW |
8628 | "please recompile with -fPIC"), |
8629 | name, input_bfd, input_section, rel->r_offset); | |
8630 | return FALSE; | |
8631 | } | |
027e9c75 NC |
8632 | /* Overflow can occur when a variable is referenced with a type |
8633 | that has a larger alignment than the type with which it was | |
8634 | declared. eg: | |
8635 | file1.c: extern int foo; int a (void) { return foo; } | |
8636 | file2.c: char bar, foo, baz; | |
8637 | If the variable is placed into a data section at an offset | |
8638 | that is incompatible with the larger alignment requirement | |
8639 | overflow will occur. (Strictly speaking this is not overflow | |
8640 | but rather an alignment problem, but the bfd_reloc_ error | |
8641 | enum does not have a value to cover that situation). | |
8642 | ||
8643 | Try to catch this situation here and provide a more helpful | |
8644 | error message to the user. */ | |
26009aa7 | 8645 | if (addend & (((bfd_vma) 1 << howto->rightshift) - 1) |
027e9c75 NC |
8646 | /* FIXME: Are we testing all of the appropriate reloc |
8647 | types here ? */ | |
8648 | && (real_r_type == BFD_RELOC_AARCH64_LD_LO19_PCREL | |
8649 | || real_r_type == BFD_RELOC_AARCH64_LDST16_LO12 | |
8650 | || real_r_type == BFD_RELOC_AARCH64_LDST32_LO12 | |
8651 | || real_r_type == BFD_RELOC_AARCH64_LDST64_LO12 | |
8652 | || real_r_type == BFD_RELOC_AARCH64_LDST128_LO12)) | |
8653 | { | |
8654 | info->callbacks->warning | |
90b6238f | 8655 | (info, _("one possible cause of this error is that the \ |
027e9c75 | 8656 | symbol is being referenced in the indicated code as if it had a larger \ |
90b6238f | 8657 | alignment than was declared where it was defined"), |
027e9c75 NC |
8658 | name, input_bfd, input_section, rel->r_offset); |
8659 | } | |
40bbb79e SP |
8660 | |
8661 | if (real_r_type == BFD_RELOC_MORELLO_CAPINIT) | |
8662 | info->callbacks->warning | |
8663 | (info, _("relocation offset must be capability aligned"), | |
8664 | name, input_bfd, input_section, rel->r_offset); | |
a06ea964 NC |
8665 | break; |
8666 | ||
8667 | case bfd_reloc_undefined: | |
1a72702b AM |
8668 | (*info->callbacks->undefined_symbol) |
8669 | (info, name, input_bfd, input_section, rel->r_offset, TRUE); | |
a06ea964 NC |
8670 | break; |
8671 | ||
8672 | case bfd_reloc_outofrange: | |
8673 | error_message = _("out of range"); | |
8674 | goto common_error; | |
8675 | ||
8676 | case bfd_reloc_notsupported: | |
8677 | error_message = _("unsupported relocation"); | |
8678 | goto common_error; | |
8679 | ||
8680 | case bfd_reloc_dangerous: | |
8681 | /* error_message should already be set. */ | |
8682 | goto common_error; | |
8683 | ||
8684 | default: | |
8685 | error_message = _("unknown error"); | |
8686 | /* Fall through. */ | |
8687 | ||
8688 | common_error: | |
8689 | BFD_ASSERT (error_message != NULL); | |
1a72702b AM |
8690 | (*info->callbacks->reloc_dangerous) |
8691 | (info, error_message, input_bfd, input_section, rel->r_offset); | |
a06ea964 NC |
8692 | break; |
8693 | } | |
8694 | } | |
027e9c75 NC |
8695 | |
8696 | if (!save_addend) | |
8697 | addend = 0; | |
a06ea964 NC |
8698 | } |
8699 | ||
8700 | return TRUE; | |
8701 | } | |
8702 | ||
8703 | /* Set the right machine number. */ | |
8704 | ||
8705 | static bfd_boolean | |
cec5225b | 8706 | elfNN_aarch64_object_p (bfd *abfd) |
a06ea964 | 8707 | { |
cec5225b YZ |
8708 | #if ARCH_SIZE == 32 |
8709 | bfd_default_set_arch_mach (abfd, bfd_arch_aarch64, bfd_mach_aarch64_ilp32); | |
8710 | #else | |
a06ea964 | 8711 | bfd_default_set_arch_mach (abfd, bfd_arch_aarch64, bfd_mach_aarch64); |
cec5225b | 8712 | #endif |
a06ea964 NC |
8713 | return TRUE; |
8714 | } | |
8715 | ||
8716 | /* Function to keep AArch64 specific flags in the ELF header. */ | |
8717 | ||
8718 | static bfd_boolean | |
cec5225b | 8719 | elfNN_aarch64_set_private_flags (bfd *abfd, flagword flags) |
a06ea964 NC |
8720 | { |
8721 | if (elf_flags_init (abfd) && elf_elfheader (abfd)->e_flags != flags) | |
8722 | { | |
8723 | } | |
8724 | else | |
8725 | { | |
8726 | elf_elfheader (abfd)->e_flags = flags; | |
8727 | elf_flags_init (abfd) = TRUE; | |
8728 | } | |
8729 | ||
8730 | return TRUE; | |
8731 | } | |
8732 | ||
a06ea964 NC |
8733 | /* Merge backend specific data from an object file to the output |
8734 | object file when linking. */ | |
8735 | ||
8736 | static bfd_boolean | |
50e03d47 | 8737 | elfNN_aarch64_merge_private_bfd_data (bfd *ibfd, struct bfd_link_info *info) |
a06ea964 | 8738 | { |
50e03d47 | 8739 | bfd *obfd = info->output_bfd; |
a06ea964 NC |
8740 | flagword out_flags; |
8741 | flagword in_flags; | |
f8180c20 | 8742 | bfd_boolean flags_compatible = FALSE; |
a06ea964 NC |
8743 | asection *sec; |
8744 | ||
8745 | /* Check if we have the same endianess. */ | |
50e03d47 | 8746 | if (!_bfd_generic_verify_endian_match (ibfd, info)) |
a06ea964 NC |
8747 | return FALSE; |
8748 | ||
8749 | if (!is_aarch64_elf (ibfd) || !is_aarch64_elf (obfd)) | |
8750 | return TRUE; | |
8751 | ||
8752 | /* The input BFD must have had its flags initialised. */ | |
8753 | /* The following seems bogus to me -- The flags are initialized in | |
8754 | the assembler but I don't think an elf_flags_init field is | |
8755 | written into the object. */ | |
8756 | /* BFD_ASSERT (elf_flags_init (ibfd)); */ | |
8757 | ||
8758 | in_flags = elf_elfheader (ibfd)->e_flags; | |
8759 | out_flags = elf_elfheader (obfd)->e_flags; | |
8760 | ||
8761 | if (!elf_flags_init (obfd)) | |
8762 | { | |
f8180c20 MM |
8763 | elf_flags_init (obfd) = TRUE; |
8764 | ||
a06ea964 | 8765 | /* If the input is the default architecture and had the default |
07d6d2b8 AM |
8766 | flags then do not bother setting the flags for the output |
8767 | architecture, instead allow future merges to do this. If no | |
8768 | future merges ever set these flags then they will retain their | |
8769 | uninitialised values, which surprise surprise, correspond | |
8770 | to the default values. */ | |
a06ea964 NC |
8771 | if (bfd_get_arch_info (ibfd)->the_default |
8772 | && elf_elfheader (ibfd)->e_flags == 0) | |
8773 | return TRUE; | |
8774 | ||
a06ea964 NC |
8775 | elf_elfheader (obfd)->e_flags = in_flags; |
8776 | ||
8777 | if (bfd_get_arch (obfd) == bfd_get_arch (ibfd) | |
8778 | && bfd_get_arch_info (obfd)->the_default) | |
8779 | return bfd_set_arch_mach (obfd, bfd_get_arch (ibfd), | |
8780 | bfd_get_mach (ibfd)); | |
8781 | ||
8782 | return TRUE; | |
8783 | } | |
8784 | ||
8785 | /* Identical flags must be compatible. */ | |
8786 | if (in_flags == out_flags) | |
8787 | return TRUE; | |
8788 | ||
8789 | /* Check to see if the input BFD actually contains any sections. If | |
8790 | not, its flags may not have been initialised either, but it | |
8791 | cannot actually cause any incompatiblity. Do not short-circuit | |
8792 | dynamic objects; their section list may be emptied by | |
8793 | elf_link_add_object_symbols. | |
8794 | ||
8795 | Also check to see if there are no code sections in the input. | |
8796 | In this case there is no need to check for code specific flags. | |
8797 | XXX - do we need to worry about floating-point format compatability | |
f8180c20 MM |
8798 | in data sections ? |
8799 | ||
8800 | We definitely need to check for data sections if one set of flags is | |
8801 | targetting the PURECAP abi and another is not. Pointers being | |
8802 | capabilities in data sections can not be glossed over. */ | |
a06ea964 NC |
8803 | if (!(ibfd->flags & DYNAMIC)) |
8804 | { | |
8805 | bfd_boolean null_input_bfd = TRUE; | |
f8180c20 MM |
8806 | bfd_boolean only_data_sections |
8807 | = !(in_flags & EF_AARCH64_CHERI_PURECAP | |
8808 | || out_flags & EF_AARCH64_CHERI_PURECAP); | |
a06ea964 NC |
8809 | |
8810 | for (sec = ibfd->sections; sec != NULL; sec = sec->next) | |
8811 | { | |
fd361982 | 8812 | if ((bfd_section_flags (sec) |
a06ea964 NC |
8813 | & (SEC_LOAD | SEC_CODE | SEC_HAS_CONTENTS)) |
8814 | == (SEC_LOAD | SEC_CODE | SEC_HAS_CONTENTS)) | |
8815 | only_data_sections = FALSE; | |
8816 | ||
8817 | null_input_bfd = FALSE; | |
8818 | break; | |
8819 | } | |
8820 | ||
8821 | if (null_input_bfd || only_data_sections) | |
8822 | return TRUE; | |
8823 | } | |
8824 | ||
8825 | return flags_compatible; | |
8826 | } | |
8827 | ||
8828 | /* Display the flags field. */ | |
8829 | ||
8830 | static bfd_boolean | |
cec5225b | 8831 | elfNN_aarch64_print_private_bfd_data (bfd *abfd, void *ptr) |
a06ea964 NC |
8832 | { |
8833 | FILE *file = (FILE *) ptr; | |
8834 | unsigned long flags; | |
8835 | ||
8836 | BFD_ASSERT (abfd != NULL && ptr != NULL); | |
8837 | ||
8838 | /* Print normal ELF private data. */ | |
8839 | _bfd_elf_print_private_bfd_data (abfd, ptr); | |
8840 | ||
8841 | flags = elf_elfheader (abfd)->e_flags; | |
8842 | /* Ignore init flag - it may not be set, despite the flags field | |
8843 | containing valid data. */ | |
8844 | ||
8845 | /* xgettext:c-format */ | |
8846 | fprintf (file, _("private flags = %lx:"), elf_elfheader (abfd)->e_flags); | |
8847 | ||
8848 | if (flags) | |
8849 | fprintf (file, _("<Unrecognised flag bits set>")); | |
8850 | ||
8851 | fputc ('\n', file); | |
8852 | ||
8853 | return TRUE; | |
8854 | } | |
8855 | ||
6353d82b JW |
8856 | /* Return true if we need copy relocation against EH. */ |
8857 | ||
8858 | static bfd_boolean | |
8859 | need_copy_relocation_p (struct elf_aarch64_link_hash_entry *eh) | |
8860 | { | |
8861 | struct elf_dyn_relocs *p; | |
8862 | asection *s; | |
8863 | ||
190eb1dd | 8864 | for (p = eh->root.dyn_relocs; p != NULL; p = p->next) |
6353d82b JW |
8865 | { |
8866 | /* If there is any pc-relative reference, we need to keep copy relocation | |
8867 | to avoid propagating the relocation into runtime that current glibc | |
8868 | does not support. */ | |
8869 | if (p->pc_count) | |
8870 | return TRUE; | |
8871 | ||
8872 | s = p->sec->output_section; | |
8873 | /* Need copy relocation if it's against read-only section. */ | |
8874 | if (s != NULL && (s->flags & SEC_READONLY) != 0) | |
8875 | return TRUE; | |
8876 | } | |
8877 | ||
8878 | return FALSE; | |
8879 | } | |
8880 | ||
a06ea964 NC |
8881 | /* Adjust a symbol defined by a dynamic object and referenced by a |
8882 | regular object. The current definition is in some section of the | |
8883 | dynamic object, but we're not including those sections. We have to | |
8884 | change the definition to something the rest of the link can | |
8885 | understand. */ | |
8886 | ||
8887 | static bfd_boolean | |
cec5225b | 8888 | elfNN_aarch64_adjust_dynamic_symbol (struct bfd_link_info *info, |
a06ea964 NC |
8889 | struct elf_link_hash_entry *h) |
8890 | { | |
cec5225b | 8891 | struct elf_aarch64_link_hash_table *htab; |
5474d94f | 8892 | asection *s, *srel; |
a06ea964 NC |
8893 | |
8894 | /* If this is a function, put it in the procedure linkage table. We | |
8895 | will fill in the contents of the procedure linkage table later, | |
8896 | when we know the address of the .got section. */ | |
1419bbe5 | 8897 | if (h->type == STT_FUNC || h->type == STT_GNU_IFUNC || h->needs_plt) |
a06ea964 NC |
8898 | { |
8899 | if (h->plt.refcount <= 0 | |
1419bbe5 WN |
8900 | || (h->type != STT_GNU_IFUNC |
8901 | && (SYMBOL_CALLS_LOCAL (info, h) | |
8902 | || (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT | |
8903 | && h->root.type == bfd_link_hash_undefweak)))) | |
a06ea964 NC |
8904 | { |
8905 | /* This case can occur if we saw a CALL26 reloc in | |
8906 | an input file, but the symbol wasn't referred to | |
8907 | by a dynamic object or all references were | |
8908 | garbage collected. In which case we can end up | |
8909 | resolving. */ | |
8910 | h->plt.offset = (bfd_vma) - 1; | |
8911 | h->needs_plt = 0; | |
8912 | } | |
8913 | ||
8914 | return TRUE; | |
8915 | } | |
8916 | else | |
80de0c6d | 8917 | /* Otherwise, reset to -1. */ |
a06ea964 NC |
8918 | h->plt.offset = (bfd_vma) - 1; |
8919 | ||
8920 | ||
8921 | /* If this is a weak symbol, and there is a real definition, the | |
8922 | processor independent code will have arranged for us to see the | |
8923 | real definition first, and we can just use the same value. */ | |
60d67dc8 | 8924 | if (h->is_weakalias) |
a06ea964 | 8925 | { |
60d67dc8 AM |
8926 | struct elf_link_hash_entry *def = weakdef (h); |
8927 | BFD_ASSERT (def->root.type == bfd_link_hash_defined); | |
8928 | h->root.u.def.section = def->root.u.def.section; | |
8929 | h->root.u.def.value = def->root.u.def.value; | |
a06ea964 | 8930 | if (ELIMINATE_COPY_RELOCS || info->nocopyreloc) |
60d67dc8 | 8931 | h->non_got_ref = def->non_got_ref; |
a06ea964 NC |
8932 | return TRUE; |
8933 | } | |
8934 | ||
8935 | /* If we are creating a shared library, we must presume that the | |
8936 | only references to the symbol are via the global offset table. | |
8937 | For such cases we need not do anything here; the relocations will | |
8938 | be handled correctly by relocate_section. */ | |
0e1862bb | 8939 | if (bfd_link_pic (info)) |
a06ea964 NC |
8940 | return TRUE; |
8941 | ||
8942 | /* If there are no references to this symbol that do not use the | |
8943 | GOT, we don't need to generate a copy reloc. */ | |
8944 | if (!h->non_got_ref) | |
8945 | return TRUE; | |
8946 | ||
8947 | /* If -z nocopyreloc was given, we won't generate them either. */ | |
8948 | if (info->nocopyreloc) | |
8949 | { | |
8950 | h->non_got_ref = 0; | |
8951 | return TRUE; | |
8952 | } | |
8953 | ||
6353d82b JW |
8954 | if (ELIMINATE_COPY_RELOCS) |
8955 | { | |
8956 | struct elf_aarch64_link_hash_entry *eh; | |
dce2246a | 8957 | /* If we don't find any dynamic relocs in read-only sections, then |
6353d82b JW |
8958 | we'll be keeping the dynamic relocs and avoiding the copy reloc. */ |
8959 | eh = (struct elf_aarch64_link_hash_entry *) h; | |
8960 | if (!need_copy_relocation_p (eh)) | |
8961 | { | |
8962 | h->non_got_ref = 0; | |
8963 | return TRUE; | |
8964 | } | |
8965 | } | |
8966 | ||
a06ea964 NC |
8967 | /* We must allocate the symbol in our .dynbss section, which will |
8968 | become part of the .bss section of the executable. There will be | |
8969 | an entry for this symbol in the .dynsym section. The dynamic | |
8970 | object will contain position independent code, so all references | |
8971 | from the dynamic object to this symbol will go through the global | |
8972 | offset table. The dynamic linker will use the .dynsym entry to | |
8973 | determine the address it must put in the global offset table, so | |
8974 | both the dynamic object and the regular object will refer to the | |
8975 | same memory location for the variable. */ | |
8976 | ||
cec5225b | 8977 | htab = elf_aarch64_hash_table (info); |
a06ea964 NC |
8978 | |
8979 | /* We must generate a R_AARCH64_COPY reloc to tell the dynamic linker | |
8980 | to copy the initial value out of the dynamic object and into the | |
8981 | runtime process image. */ | |
5474d94f AM |
8982 | if ((h->root.u.def.section->flags & SEC_READONLY) != 0) |
8983 | { | |
8984 | s = htab->root.sdynrelro; | |
8985 | srel = htab->root.sreldynrelro; | |
8986 | } | |
8987 | else | |
8988 | { | |
8989 | s = htab->root.sdynbss; | |
8990 | srel = htab->root.srelbss; | |
8991 | } | |
a06ea964 NC |
8992 | if ((h->root.u.def.section->flags & SEC_ALLOC) != 0 && h->size != 0) |
8993 | { | |
5474d94f | 8994 | srel->size += RELOC_SIZE (htab); |
a06ea964 NC |
8995 | h->needs_copy = 1; |
8996 | } | |
8997 | ||
6cabe1ea | 8998 | return _bfd_elf_adjust_dynamic_copy (info, h, s); |
a06ea964 NC |
8999 | |
9000 | } | |
9001 | ||
9002 | static bfd_boolean | |
cec5225b | 9003 | elfNN_aarch64_allocate_local_symbols (bfd *abfd, unsigned number) |
a06ea964 NC |
9004 | { |
9005 | struct elf_aarch64_local_symbol *locals; | |
cec5225b | 9006 | locals = elf_aarch64_locals (abfd); |
a06ea964 NC |
9007 | if (locals == NULL) |
9008 | { | |
9009 | locals = (struct elf_aarch64_local_symbol *) | |
9010 | bfd_zalloc (abfd, number * sizeof (struct elf_aarch64_local_symbol)); | |
9011 | if (locals == NULL) | |
9012 | return FALSE; | |
cec5225b | 9013 | elf_aarch64_locals (abfd) = locals; |
a06ea964 NC |
9014 | } |
9015 | return TRUE; | |
9016 | } | |
9017 | ||
a1bdea65 SP |
9018 | /* Initialise the .got section to hold the global offset table. */ |
9019 | ||
9020 | static void | |
9021 | aarch64_elf_init_got_section (bfd *abfd, struct bfd_link_info *info) | |
9022 | { | |
9023 | const struct elf_backend_data *bed = get_elf_backend_data (abfd); | |
9024 | asection *s; | |
9025 | struct elf_aarch64_link_hash_table *globals = elf_aarch64_hash_table (info); | |
9026 | unsigned int align = bed->s->log_file_align + globals->c64_rel; | |
9027 | ||
9028 | if (globals->root.sgot != NULL) | |
9029 | { | |
9030 | bfd_set_section_alignment (globals->root.srelgot, | |
9031 | bed->s->log_file_align); | |
9032 | bfd_set_section_alignment (globals->root.sgot, align); | |
9033 | globals->root.sgot->size += GOT_ENTRY_SIZE (globals); | |
9034 | } | |
9035 | ||
8d4edc5f SP |
9036 | /* Track capability initialisation for static non-PIE binaries. */ |
9037 | if (bfd_link_executable (info) && !bfd_link_pic (info) | |
9038 | && globals->srelcaps == NULL) | |
9039 | globals->srelcaps = globals->root.srelgot; | |
9040 | ||
a1bdea65 SP |
9041 | if (globals->root.igotplt != NULL) |
9042 | bfd_set_section_alignment (globals->root.igotplt, align); | |
9043 | ||
9044 | s = globals->root.sgot; | |
9045 | ||
9046 | if (globals->root.sgotplt != NULL) | |
9047 | { | |
9048 | bfd_set_section_alignment (globals->root.sgotplt, align); | |
9049 | s = globals->root.sgotplt; | |
9050 | } | |
9051 | ||
9052 | /* The first bit of the global offset table is the header. */ | |
9053 | if (s != NULL) | |
9054 | s->size += bed->got_header_size (info); | |
9055 | } | |
9056 | ||
cc0efaa8 MS |
9057 | /* Create the .got section to hold the global offset table. */ |
9058 | ||
9059 | static bfd_boolean | |
9060 | aarch64_elf_create_got_section (bfd *abfd, struct bfd_link_info *info) | |
9061 | { | |
9062 | const struct elf_backend_data *bed = get_elf_backend_data (abfd); | |
9063 | flagword flags; | |
9064 | asection *s; | |
9065 | struct elf_link_hash_entry *h; | |
9066 | struct elf_link_hash_table *htab = elf_hash_table (info); | |
9067 | ||
9068 | /* This function may be called more than once. */ | |
ce558b89 | 9069 | if (htab->sgot != NULL) |
cc0efaa8 MS |
9070 | return TRUE; |
9071 | ||
9072 | flags = bed->dynamic_sec_flags; | |
9073 | ||
9074 | s = bfd_make_section_anyway_with_flags (abfd, | |
9075 | (bed->rela_plts_and_copies_p | |
9076 | ? ".rela.got" : ".rel.got"), | |
9077 | (bed->dynamic_sec_flags | |
9078 | | SEC_READONLY)); | |
a1bdea65 | 9079 | if (s == NULL) |
cc0efaa8 MS |
9080 | return FALSE; |
9081 | htab->srelgot = s; | |
9082 | ||
9083 | s = bfd_make_section_anyway_with_flags (abfd, ".got", flags); | |
a1bdea65 | 9084 | if (s == NULL) |
cc0efaa8 MS |
9085 | return FALSE; |
9086 | htab->sgot = s; | |
cc0efaa8 MS |
9087 | |
9088 | if (bed->want_got_sym) | |
9089 | { | |
9090 | /* Define the symbol _GLOBAL_OFFSET_TABLE_ at the start of the .got | |
9091 | (or .got.plt) section. We don't do this in the linker script | |
9092 | because we don't want to define the symbol if we are not creating | |
9093 | a global offset table. */ | |
9094 | h = _bfd_elf_define_linkage_sym (abfd, info, s, | |
9095 | "_GLOBAL_OFFSET_TABLE_"); | |
9096 | elf_hash_table (info)->hgot = h; | |
9097 | if (h == NULL) | |
9098 | return FALSE; | |
9099 | } | |
9100 | ||
9101 | if (bed->want_got_plt) | |
9102 | { | |
9103 | s = bfd_make_section_anyway_with_flags (abfd, ".got.plt", flags); | |
a1bdea65 | 9104 | if (s == NULL) |
cc0efaa8 MS |
9105 | return FALSE; |
9106 | htab->sgotplt = s; | |
9107 | } | |
9108 | ||
cc0efaa8 MS |
9109 | return TRUE; |
9110 | } | |
9111 | ||
a06ea964 NC |
9112 | /* Look through the relocs for a section during the first phase. */ |
9113 | ||
9114 | static bfd_boolean | |
cec5225b | 9115 | elfNN_aarch64_check_relocs (bfd *abfd, struct bfd_link_info *info, |
a06ea964 NC |
9116 | asection *sec, const Elf_Internal_Rela *relocs) |
9117 | { | |
9118 | Elf_Internal_Shdr *symtab_hdr; | |
9119 | struct elf_link_hash_entry **sym_hashes; | |
9120 | const Elf_Internal_Rela *rel; | |
9121 | const Elf_Internal_Rela *rel_end; | |
9122 | asection *sreloc; | |
9123 | ||
cec5225b | 9124 | struct elf_aarch64_link_hash_table *htab; |
a06ea964 | 9125 | |
0e1862bb | 9126 | if (bfd_link_relocatable (info)) |
a06ea964 NC |
9127 | return TRUE; |
9128 | ||
9129 | BFD_ASSERT (is_aarch64_elf (abfd)); | |
9130 | ||
cec5225b | 9131 | htab = elf_aarch64_hash_table (info); |
a06ea964 NC |
9132 | sreloc = NULL; |
9133 | ||
9134 | symtab_hdr = &elf_symtab_hdr (abfd); | |
9135 | sym_hashes = elf_sym_hashes (abfd); | |
a06ea964 | 9136 | |
7ff36d1a | 9137 | bfd_elfNN_aarch64_init_maps (abfd, info); |
f0070c1e | 9138 | |
a06ea964 NC |
9139 | rel_end = relocs + sec->reloc_count; |
9140 | for (rel = relocs; rel < rel_end; rel++) | |
9141 | { | |
9142 | struct elf_link_hash_entry *h; | |
f3ecc5c8 | 9143 | unsigned int r_symndx, r_type; |
a6bb11b2 | 9144 | bfd_reloc_code_real_type bfd_r_type; |
1419bbe5 | 9145 | Elf_Internal_Sym *isym; |
a06ea964 | 9146 | |
cec5225b | 9147 | r_symndx = ELFNN_R_SYM (rel->r_info); |
f3ecc5c8 AC |
9148 | r_type = ELFNN_R_TYPE (rel->r_info); |
9149 | bfd_r_type = elfNN_aarch64_bfd_reloc_from_type (abfd, r_type); | |
a06ea964 NC |
9150 | |
9151 | if (r_symndx >= NUM_SHDR_ENTRIES (symtab_hdr)) | |
9152 | { | |
695344c0 | 9153 | /* xgettext:c-format */ |
871b3ab2 | 9154 | _bfd_error_handler (_("%pB: bad symbol index: %d"), abfd, r_symndx); |
a06ea964 NC |
9155 | return FALSE; |
9156 | } | |
9157 | ||
ed5acf27 | 9158 | if (r_symndx < symtab_hdr->sh_info) |
1419bbe5 WN |
9159 | { |
9160 | /* A local symbol. */ | |
f1dfbfdb | 9161 | isym = bfd_sym_from_r_symndx (&htab->root.sym_cache, |
1419bbe5 WN |
9162 | abfd, r_symndx); |
9163 | if (isym == NULL) | |
9164 | return FALSE; | |
9165 | ||
9166 | /* Check relocation against local STT_GNU_IFUNC symbol. */ | |
9167 | if (ELF_ST_TYPE (isym->st_info) == STT_GNU_IFUNC) | |
9168 | { | |
9169 | h = elfNN_aarch64_get_local_sym_hash (htab, abfd, rel, | |
9170 | TRUE); | |
9171 | if (h == NULL) | |
9172 | return FALSE; | |
9173 | ||
9174 | /* Fake a STT_GNU_IFUNC symbol. */ | |
9175 | h->type = STT_GNU_IFUNC; | |
9176 | h->def_regular = 1; | |
9177 | h->ref_regular = 1; | |
9178 | h->forced_local = 1; | |
9179 | h->root.type = bfd_link_hash_defined; | |
9180 | } | |
9181 | else | |
9182 | h = NULL; | |
9183 | } | |
a06ea964 NC |
9184 | else |
9185 | { | |
9186 | h = sym_hashes[r_symndx - symtab_hdr->sh_info]; | |
9187 | while (h->root.type == bfd_link_hash_indirect | |
9188 | || h->root.type == bfd_link_hash_warning) | |
9189 | h = (struct elf_link_hash_entry *) h->root.u.i.link; | |
9190 | } | |
9191 | ||
f3ecc5c8 AC |
9192 | /* Ignore TLS relocations against weak undef symbols and warn about them. |
9193 | The behaviour of weak TLS variables is not well defined. Since making | |
9194 | these well behaved is not a priority for Morello, we simply ignore | |
9195 | TLS relocations against such symbols here to avoid the linker crashing | |
9196 | on these and to enable making progress in other areas. */ | |
9197 | if (r_symndx | |
9198 | && h | |
9199 | && IS_AARCH64_TLS_RELOC (bfd_r_type) | |
9200 | && h->root.type == bfd_link_hash_undefweak) | |
9201 | { | |
9202 | int howto_index = bfd_r_type - BFD_RELOC_AARCH64_RELOC_START; | |
9203 | _bfd_error_handler (_("%pB(%pA+%#" PRIx64 "): ignoring TLS relocation " | |
9204 | "%s against undef weak symbol %s"), | |
9205 | abfd, sec, | |
9206 | (uint64_t) rel->r_offset, | |
9207 | elfNN_aarch64_howto_table[howto_index].name, | |
9208 | h->root.root.string); | |
9209 | continue; | |
9210 | } | |
9211 | ||
a06ea964 | 9212 | /* Could be done earlier, if h were already available. */ |
4ca9b406 | 9213 | bfd_r_type = aarch64_tls_transition (abfd, info, rel, h, r_symndx); |
a06ea964 | 9214 | |
1419bbe5 WN |
9215 | if (h != NULL) |
9216 | { | |
18f822a0 JW |
9217 | /* If a relocation refers to _GLOBAL_OFFSET_TABLE_, create the .got. |
9218 | This shows up in particular in an R_AARCH64_PREL64 in large model | |
9219 | when calculating the pc-relative address to .got section which is | |
9220 | used to initialize the gp register. */ | |
9221 | if (h->root.root.string | |
9222 | && strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0) | |
9223 | { | |
9224 | if (htab->root.dynobj == NULL) | |
9225 | htab->root.dynobj = abfd; | |
9226 | ||
9227 | if (! aarch64_elf_create_got_section (htab->root.dynobj, info)) | |
9228 | return FALSE; | |
9229 | ||
9230 | BFD_ASSERT (h == htab->root.hgot); | |
9231 | } | |
9232 | ||
1419bbe5 WN |
9233 | /* Create the ifunc sections for static executables. If we |
9234 | never see an indirect function symbol nor we are building | |
9235 | a static executable, those sections will be empty and | |
9236 | won't appear in output. */ | |
9237 | switch (bfd_r_type) | |
9238 | { | |
9239 | default: | |
9240 | break; | |
9241 | ||
e19e9199 SP |
9242 | case BFD_RELOC_MORELLO_CALL26: |
9243 | case BFD_RELOC_MORELLO_JUMP26: | |
9244 | /* For dynamic symbols record caller information so that we can | |
9245 | decide what kind of PLT stubs to emit. */ | |
9246 | if (h != NULL) | |
9247 | elf_aarch64_hash_entry (h)->got_type = GOT_CAP; | |
9248 | /* Fall through. */ | |
9249 | ||
ce336788 JW |
9250 | case BFD_RELOC_AARCH64_ADD_LO12: |
9251 | case BFD_RELOC_AARCH64_ADR_GOT_PAGE: | |
92504105 | 9252 | case BFD_RELOC_MORELLO_ADR_GOT_PAGE: |
ce336788 | 9253 | case BFD_RELOC_AARCH64_ADR_HI21_PCREL: |
92504105 | 9254 | case BFD_RELOC_MORELLO_ADR_HI20_PCREL: |
1419bbe5 | 9255 | case BFD_RELOC_AARCH64_CALL26: |
ce336788 | 9256 | case BFD_RELOC_AARCH64_GOT_LD_PREL19: |
1419bbe5 | 9257 | case BFD_RELOC_AARCH64_JUMP26: |
7018c030 | 9258 | case BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14: |
1419bbe5 | 9259 | case BFD_RELOC_AARCH64_LD32_GOT_LO12_NC: |
a2e1db00 | 9260 | case BFD_RELOC_AARCH64_LD64_GOTOFF_LO15: |
99ad26cb | 9261 | case BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15: |
1419bbe5 | 9262 | case BFD_RELOC_AARCH64_LD64_GOT_LO12_NC: |
a1bdea65 | 9263 | case BFD_RELOC_MORELLO_LD128_GOT_LO12_NC: |
dc8008f5 | 9264 | case BFD_RELOC_AARCH64_MOVW_GOTOFF_G0_NC: |
74a1bfe1 | 9265 | case BFD_RELOC_AARCH64_MOVW_GOTOFF_G1: |
ce336788 | 9266 | case BFD_RELOC_AARCH64_NN: |
1419bbe5 WN |
9267 | if (htab->root.dynobj == NULL) |
9268 | htab->root.dynobj = abfd; | |
9269 | if (!_bfd_elf_create_ifunc_sections (htab->root.dynobj, info)) | |
9270 | return FALSE; | |
9271 | break; | |
9272 | } | |
9273 | ||
2d0ca824 | 9274 | /* It is referenced by a non-shared object. */ |
1419bbe5 | 9275 | h->ref_regular = 1; |
1419bbe5 WN |
9276 | } |
9277 | ||
a6bb11b2 | 9278 | switch (bfd_r_type) |
a06ea964 | 9279 | { |
79e74192 RL |
9280 | case BFD_RELOC_AARCH64_16: |
9281 | #if ARCH_SIZE == 64 | |
9282 | case BFD_RELOC_AARCH64_32: | |
9283 | #endif | |
279b2f94 | 9284 | if (bfd_link_pic (info) && (sec->flags & SEC_ALLOC) != 0) |
79e74192 | 9285 | { |
279b2f94 RL |
9286 | if (h != NULL |
9287 | /* This is an absolute symbol. It represents a value instead | |
9288 | of an address. */ | |
c691de6a | 9289 | && (bfd_is_abs_symbol (&h->root) |
279b2f94 RL |
9290 | /* This is an undefined symbol. */ |
9291 | || h->root.type == bfd_link_hash_undefined)) | |
9292 | break; | |
9293 | ||
9294 | /* For local symbols, defined global symbols in a non-ABS section, | |
9295 | it is assumed that the value is an address. */ | |
79e74192 RL |
9296 | int howto_index = bfd_r_type - BFD_RELOC_AARCH64_RELOC_START; |
9297 | _bfd_error_handler | |
9298 | /* xgettext:c-format */ | |
871b3ab2 | 9299 | (_("%pB: relocation %s against `%s' can not be used when making " |
79e74192 RL |
9300 | "a shared object"), |
9301 | abfd, elfNN_aarch64_howto_table[howto_index].name, | |
9302 | (h) ? h->root.root.string : "a local symbol"); | |
9303 | bfd_set_error (bfd_error_bad_value); | |
9304 | return FALSE; | |
9305 | } | |
9306 | else | |
9307 | break; | |
9308 | ||
6353d82b JW |
9309 | case BFD_RELOC_AARCH64_MOVW_G0_NC: |
9310 | case BFD_RELOC_AARCH64_MOVW_G1_NC: | |
9311 | case BFD_RELOC_AARCH64_MOVW_G2_NC: | |
9312 | case BFD_RELOC_AARCH64_MOVW_G3: | |
9313 | if (bfd_link_pic (info)) | |
9314 | { | |
9315 | int howto_index = bfd_r_type - BFD_RELOC_AARCH64_RELOC_START; | |
9316 | _bfd_error_handler | |
9317 | /* xgettext:c-format */ | |
871b3ab2 | 9318 | (_("%pB: relocation %s against `%s' can not be used when making " |
6353d82b JW |
9319 | "a shared object; recompile with -fPIC"), |
9320 | abfd, elfNN_aarch64_howto_table[howto_index].name, | |
9321 | (h) ? h->root.root.string : "a local symbol"); | |
9322 | bfd_set_error (bfd_error_bad_value); | |
9323 | return FALSE; | |
9324 | } | |
9325 | /* Fall through. */ | |
9326 | ||
9327 | case BFD_RELOC_AARCH64_16_PCREL: | |
9328 | case BFD_RELOC_AARCH64_32_PCREL: | |
9329 | case BFD_RELOC_AARCH64_64_PCREL: | |
9330 | case BFD_RELOC_AARCH64_ADD_LO12: | |
9331 | case BFD_RELOC_AARCH64_ADR_HI21_NC_PCREL: | |
9332 | case BFD_RELOC_AARCH64_ADR_HI21_PCREL: | |
92504105 SP |
9333 | case BFD_RELOC_MORELLO_ADR_HI20_NC_PCREL: |
9334 | case BFD_RELOC_MORELLO_ADR_HI20_PCREL: | |
6353d82b JW |
9335 | case BFD_RELOC_AARCH64_ADR_LO21_PCREL: |
9336 | case BFD_RELOC_AARCH64_LDST128_LO12: | |
9337 | case BFD_RELOC_AARCH64_LDST16_LO12: | |
9338 | case BFD_RELOC_AARCH64_LDST32_LO12: | |
9339 | case BFD_RELOC_AARCH64_LDST64_LO12: | |
9340 | case BFD_RELOC_AARCH64_LDST8_LO12: | |
9341 | case BFD_RELOC_AARCH64_LD_LO19_PCREL: | |
f7d2c675 | 9342 | case BFD_RELOC_MORELLO_LD_LO17_PCREL: |
6353d82b JW |
9343 | if (h == NULL || bfd_link_pic (info)) |
9344 | break; | |
9345 | /* Fall through. */ | |
9346 | ||
a6bb11b2 | 9347 | case BFD_RELOC_AARCH64_NN: |
a06ea964 NC |
9348 | |
9349 | /* We don't need to handle relocs into sections not going into | |
9350 | the "real" output. */ | |
9351 | if ((sec->flags & SEC_ALLOC) == 0) | |
9352 | break; | |
9353 | ||
9354 | if (h != NULL) | |
9355 | { | |
0e1862bb | 9356 | if (!bfd_link_pic (info)) |
a06ea964 NC |
9357 | h->non_got_ref = 1; |
9358 | ||
9359 | h->plt.refcount += 1; | |
9360 | h->pointer_equality_needed = 1; | |
9361 | } | |
9362 | ||
9363 | /* No need to do anything if we're not creating a shared | |
9364 | object. */ | |
6353d82b JW |
9365 | if (!(bfd_link_pic (info) |
9366 | /* If on the other hand, we are creating an executable, we | |
9367 | may need to keep relocations for symbols satisfied by a | |
9368 | dynamic library if we manage to avoid copy relocs for the | |
9369 | symbol. | |
9370 | ||
9371 | NOTE: Currently, there is no support of copy relocs | |
9372 | elimination on pc-relative relocation types, because there is | |
9373 | no dynamic relocation support for them in glibc. We still | |
9374 | record the dynamic symbol reference for them. This is | |
9375 | because one symbol may be referenced by both absolute | |
9376 | relocation (for example, BFD_RELOC_AARCH64_NN) and | |
9377 | pc-relative relocation. We need full symbol reference | |
9378 | information to make correct decision later in | |
9379 | elfNN_aarch64_adjust_dynamic_symbol. */ | |
9380 | || (ELIMINATE_COPY_RELOCS | |
9381 | && !bfd_link_pic (info) | |
9382 | && h != NULL | |
9383 | && (h->root.type == bfd_link_hash_defweak | |
9384 | || !h->def_regular)))) | |
a06ea964 NC |
9385 | break; |
9386 | ||
9387 | { | |
9388 | struct elf_dyn_relocs *p; | |
9389 | struct elf_dyn_relocs **head; | |
6353d82b | 9390 | int howto_index = bfd_r_type - BFD_RELOC_AARCH64_RELOC_START; |
a06ea964 NC |
9391 | |
9392 | /* We must copy these reloc types into the output file. | |
9393 | Create a reloc section in dynobj and make room for | |
9394 | this reloc. */ | |
9395 | if (sreloc == NULL) | |
9396 | { | |
9397 | if (htab->root.dynobj == NULL) | |
9398 | htab->root.dynobj = abfd; | |
9399 | ||
9400 | sreloc = _bfd_elf_make_dynamic_reloc_section | |
0608afa7 | 9401 | (sec, htab->root.dynobj, LOG_FILE_ALIGN, abfd, /*rela? */ TRUE); |
a06ea964 NC |
9402 | |
9403 | if (sreloc == NULL) | |
9404 | return FALSE; | |
9405 | } | |
9406 | ||
9407 | /* If this is a global symbol, we count the number of | |
9408 | relocations we need for this symbol. */ | |
9409 | if (h != NULL) | |
9410 | { | |
190eb1dd | 9411 | head = &h->dyn_relocs; |
a06ea964 NC |
9412 | } |
9413 | else | |
9414 | { | |
9415 | /* Track dynamic relocs needed for local syms too. | |
9416 | We really need local syms available to do this | |
9417 | easily. Oh well. */ | |
9418 | ||
9419 | asection *s; | |
9420 | void **vpp; | |
a06ea964 | 9421 | |
f1dfbfdb | 9422 | isym = bfd_sym_from_r_symndx (&htab->root.sym_cache, |
a06ea964 NC |
9423 | abfd, r_symndx); |
9424 | if (isym == NULL) | |
9425 | return FALSE; | |
9426 | ||
9427 | s = bfd_section_from_elf_index (abfd, isym->st_shndx); | |
9428 | if (s == NULL) | |
9429 | s = sec; | |
9430 | ||
9431 | /* Beware of type punned pointers vs strict aliasing | |
9432 | rules. */ | |
9433 | vpp = &(elf_section_data (s)->local_dynrel); | |
9434 | head = (struct elf_dyn_relocs **) vpp; | |
9435 | } | |
9436 | ||
9437 | p = *head; | |
9438 | if (p == NULL || p->sec != sec) | |
9439 | { | |
986f0783 | 9440 | size_t amt = sizeof *p; |
a06ea964 NC |
9441 | p = ((struct elf_dyn_relocs *) |
9442 | bfd_zalloc (htab->root.dynobj, amt)); | |
9443 | if (p == NULL) | |
9444 | return FALSE; | |
9445 | p->next = *head; | |
9446 | *head = p; | |
9447 | p->sec = sec; | |
9448 | } | |
9449 | ||
9450 | p->count += 1; | |
9451 | ||
6353d82b JW |
9452 | if (elfNN_aarch64_howto_table[howto_index].pc_relative) |
9453 | p->pc_count += 1; | |
a06ea964 NC |
9454 | } |
9455 | break; | |
9456 | ||
9457 | /* RR: We probably want to keep a consistency check that | |
9458 | there are no dangling GOT_PAGE relocs. */ | |
92504105 | 9459 | case BFD_RELOC_MORELLO_ADR_GOT_PAGE: |
a1bdea65 | 9460 | case BFD_RELOC_MORELLO_LD128_GOT_LO12_NC: |
4ca9b406 SP |
9461 | case BFD_RELOC_MORELLO_TLSDESC_ADR_PAGE20: |
9462 | case BFD_RELOC_MORELLO_TLSDESC_LD128_LO12: | |
a1bdea65 SP |
9463 | htab->c64_rel = 1; |
9464 | /* Fall through. */ | |
9465 | ||
9466 | case BFD_RELOC_AARCH64_ADR_GOT_PAGE: | |
7bcccb57 | 9467 | case BFD_RELOC_AARCH64_GOT_LD_PREL19: |
7018c030 | 9468 | case BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14: |
7bcccb57 | 9469 | case BFD_RELOC_AARCH64_LD32_GOT_LO12_NC: |
a2e1db00 | 9470 | case BFD_RELOC_AARCH64_LD64_GOTOFF_LO15: |
99ad26cb | 9471 | case BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15: |
7bcccb57 | 9472 | case BFD_RELOC_AARCH64_LD64_GOT_LO12_NC: |
dc8008f5 | 9473 | case BFD_RELOC_AARCH64_MOVW_GOTOFF_G0_NC: |
74a1bfe1 | 9474 | case BFD_RELOC_AARCH64_MOVW_GOTOFF_G1: |
f955cccf | 9475 | case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12: |
7bcccb57 | 9476 | case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21: |
389b8029 | 9477 | case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21: |
7bcccb57 | 9478 | case BFD_RELOC_AARCH64_TLSDESC_LD32_LO12_NC: |
f955cccf | 9479 | case BFD_RELOC_AARCH64_TLSDESC_LD64_LO12: |
1ada945d | 9480 | case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19: |
0484b454 RL |
9481 | case BFD_RELOC_AARCH64_TLSDESC_OFF_G0_NC: |
9482 | case BFD_RELOC_AARCH64_TLSDESC_OFF_G1: | |
a6bb11b2 | 9483 | case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC: |
7bcccb57 | 9484 | case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21: |
3c12b054 | 9485 | case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21: |
7ba7cfe4 | 9486 | case BFD_RELOC_AARCH64_TLSGD_MOVW_G0_NC: |
94facae3 | 9487 | case BFD_RELOC_AARCH64_TLSGD_MOVW_G1: |
a6bb11b2 | 9488 | case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21: |
a6bb11b2 | 9489 | case BFD_RELOC_AARCH64_TLSIE_LD32_GOTTPREL_LO12_NC: |
7bcccb57 | 9490 | case BFD_RELOC_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC: |
043bf05a | 9491 | case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19: |
3b957e5b RL |
9492 | case BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G0_NC: |
9493 | case BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G1: | |
73f925cc | 9494 | case BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC: |
f69e4920 | 9495 | case BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21: |
77a69ff8 | 9496 | case BFD_RELOC_AARCH64_TLSLD_ADR_PREL21: |
a06ea964 NC |
9497 | { |
9498 | unsigned got_type; | |
9499 | unsigned old_got_type; | |
9500 | ||
a6bb11b2 | 9501 | got_type = aarch64_reloc_got_type (bfd_r_type); |
a06ea964 NC |
9502 | |
9503 | if (h) | |
9504 | { | |
9505 | h->got.refcount += 1; | |
cec5225b | 9506 | old_got_type = elf_aarch64_hash_entry (h)->got_type; |
a06ea964 NC |
9507 | } |
9508 | else | |
9509 | { | |
9510 | struct elf_aarch64_local_symbol *locals; | |
9511 | ||
cec5225b | 9512 | if (!elfNN_aarch64_allocate_local_symbols |
a06ea964 NC |
9513 | (abfd, symtab_hdr->sh_info)) |
9514 | return FALSE; | |
9515 | ||
cec5225b | 9516 | locals = elf_aarch64_locals (abfd); |
a06ea964 NC |
9517 | BFD_ASSERT (r_symndx < symtab_hdr->sh_info); |
9518 | locals[r_symndx].got_refcount += 1; | |
9519 | old_got_type = locals[r_symndx].got_type; | |
9520 | } | |
9521 | ||
9522 | /* If a variable is accessed with both general dynamic TLS | |
9523 | methods, two slots may be created. */ | |
9524 | if (GOT_TLS_GD_ANY_P (old_got_type) && GOT_TLS_GD_ANY_P (got_type)) | |
9525 | got_type |= old_got_type; | |
9526 | ||
9527 | /* We will already have issued an error message if there | |
9528 | is a TLS/non-TLS mismatch, based on the symbol type. | |
9529 | So just combine any TLS types needed. */ | |
9530 | if (old_got_type != GOT_UNKNOWN && old_got_type != GOT_NORMAL | |
a1bdea65 SP |
9531 | && got_type != GOT_NORMAL && old_got_type != GOT_CAP |
9532 | && got_type != GOT_CAP) | |
a06ea964 NC |
9533 | got_type |= old_got_type; |
9534 | ||
9535 | /* If the symbol is accessed by both IE and GD methods, we | |
9536 | are able to relax. Turn off the GD flag, without | |
9537 | messing up with any other kind of TLS types that may be | |
9538 | involved. */ | |
9539 | if ((got_type & GOT_TLS_IE) && GOT_TLS_GD_ANY_P (got_type)) | |
9540 | got_type &= ~ (GOT_TLSDESC_GD | GOT_TLS_GD); | |
9541 | ||
4ca9b406 SP |
9542 | /* Prefer the capability reference. */ |
9543 | if ((old_got_type & GOT_CAP) && (got_type & GOT_NORMAL)) | |
9544 | { | |
9545 | got_type &= ~GOT_NORMAL; | |
9546 | got_type |= GOT_CAP; | |
9547 | } | |
9548 | ||
9549 | if (old_got_type != got_type) | |
a06ea964 NC |
9550 | { |
9551 | if (h != NULL) | |
cec5225b | 9552 | elf_aarch64_hash_entry (h)->got_type = got_type; |
a06ea964 NC |
9553 | else |
9554 | { | |
9555 | struct elf_aarch64_local_symbol *locals; | |
cec5225b | 9556 | locals = elf_aarch64_locals (abfd); |
a06ea964 NC |
9557 | BFD_ASSERT (r_symndx < symtab_hdr->sh_info); |
9558 | locals[r_symndx].got_type = got_type; | |
9559 | } | |
9560 | } | |
9561 | ||
cc0efaa8 MS |
9562 | if (htab->root.dynobj == NULL) |
9563 | htab->root.dynobj = abfd; | |
9564 | if (! aarch64_elf_create_got_section (htab->root.dynobj, info)) | |
9565 | return FALSE; | |
a06ea964 NC |
9566 | break; |
9567 | } | |
9568 | ||
e19e9199 SP |
9569 | case BFD_RELOC_MORELLO_CALL26: |
9570 | case BFD_RELOC_MORELLO_JUMP26: | |
9571 | htab->c64_rel = 1; | |
9572 | if (h != NULL) | |
9573 | elf_aarch64_hash_entry (h)->got_type = GOT_CAP; | |
9574 | ||
9575 | /* Fall through. */ | |
a6bb11b2 YZ |
9576 | case BFD_RELOC_AARCH64_CALL26: |
9577 | case BFD_RELOC_AARCH64_JUMP26: | |
a06ea964 | 9578 | if (h == NULL) |
f0070c1e SP |
9579 | { |
9580 | isym = bfd_sym_from_r_symndx (&htab->root.sym_cache, abfd, | |
9581 | r_symndx); | |
9582 | if (isym == NULL) | |
9583 | return FALSE; | |
9584 | ||
9585 | asection *s = bfd_section_from_elf_index (abfd, isym->st_shndx); | |
9586 | ||
9587 | if (s == NULL) | |
9588 | s = sec; | |
9589 | ||
9590 | if (c64_value_p (s, isym->st_value)) | |
9591 | isym->st_target_internal |= ST_BRANCH_TO_C64; | |
9592 | ||
9593 | /* If this is a local symbol then we resolve it | |
9594 | directly without creating a PLT entry. */ | |
9595 | continue; | |
9596 | } | |
9597 | ||
9598 | if (h->root.type == bfd_link_hash_defined | |
9599 | || h->root.type == bfd_link_hash_defweak) | |
9600 | { | |
9601 | asection *sym_sec = h->root.u.def.section; | |
9602 | bfd_vma sym_value = h->root.u.def.value; | |
9603 | ||
9604 | if (sym_sec != NULL && c64_value_p (sym_sec, sym_value)) | |
9605 | h->target_internal |= ST_BRANCH_TO_C64; | |
9606 | } | |
a06ea964 NC |
9607 | |
9608 | h->needs_plt = 1; | |
1419bbe5 WN |
9609 | if (h->plt.refcount <= 0) |
9610 | h->plt.refcount = 1; | |
9611 | else | |
9612 | h->plt.refcount += 1; | |
a06ea964 | 9613 | break; |
a6bb11b2 | 9614 | |
40bbb79e SP |
9615 | case BFD_RELOC_MORELLO_CAPINIT: |
9616 | if (htab->srelcaps == NULL) | |
9617 | { | |
9618 | if (htab->root.dynobj == NULL) | |
9619 | htab->root.dynobj = abfd; | |
9620 | ||
9621 | sreloc = _bfd_elf_make_dynamic_reloc_section | |
9622 | (sec, htab->root.dynobj, LOG_FILE_ALIGN, | |
9623 | abfd, /*rela? */ TRUE); | |
9624 | ||
9625 | if (sreloc == NULL) | |
9626 | return FALSE; | |
9627 | ||
9628 | htab->srelcaps = sreloc; | |
9629 | } | |
9630 | htab->srelcaps->size += RELOC_SIZE (htab); | |
9631 | ||
9632 | break; | |
9633 | ||
a6bb11b2 YZ |
9634 | default: |
9635 | break; | |
a06ea964 NC |
9636 | } |
9637 | } | |
a6bb11b2 | 9638 | |
a06ea964 NC |
9639 | return TRUE; |
9640 | } | |
9641 | ||
9642 | /* Treat mapping symbols as special target symbols. */ | |
9643 | ||
9644 | static bfd_boolean | |
cec5225b | 9645 | elfNN_aarch64_is_target_special_symbol (bfd *abfd ATTRIBUTE_UNUSED, |
a06ea964 NC |
9646 | asymbol *sym) |
9647 | { | |
9648 | return bfd_is_aarch64_special_symbol_name (sym->name, | |
9649 | BFD_AARCH64_SPECIAL_SYM_TYPE_ANY); | |
9650 | } | |
9651 | ||
e7679060 AM |
9652 | /* If the ELF symbol SYM might be a function in SEC, return the |
9653 | function size and set *CODE_OFF to the function's entry point, | |
9654 | otherwise return zero. */ | |
a06ea964 | 9655 | |
e7679060 AM |
9656 | static bfd_size_type |
9657 | elfNN_aarch64_maybe_function_sym (const asymbol *sym, asection *sec, | |
9658 | bfd_vma *code_off) | |
9659 | { | |
9660 | bfd_size_type size; | |
a06ea964 | 9661 | |
e7679060 AM |
9662 | if ((sym->flags & (BSF_SECTION_SYM | BSF_FILE | BSF_OBJECT |
9663 | | BSF_THREAD_LOCAL | BSF_RELC | BSF_SRELC)) != 0 | |
9664 | || sym->section != sec) | |
9665 | return 0; | |
a06ea964 | 9666 | |
e7679060 AM |
9667 | if (!(sym->flags & BSF_SYNTHETIC)) |
9668 | switch (ELF_ST_TYPE (((elf_symbol_type *) sym)->internal_elf_sym.st_info)) | |
9669 | { | |
a06ea964 NC |
9670 | case STT_FUNC: |
9671 | case STT_NOTYPE: | |
a06ea964 | 9672 | break; |
e7679060 AM |
9673 | default: |
9674 | return 0; | |
9675 | } | |
a06ea964 | 9676 | |
e7679060 AM |
9677 | if ((sym->flags & BSF_LOCAL) |
9678 | && bfd_is_aarch64_special_symbol_name (sym->name, | |
9679 | BFD_AARCH64_SPECIAL_SYM_TYPE_ANY)) | |
9680 | return 0; | |
a06ea964 | 9681 | |
e7679060 AM |
9682 | *code_off = sym->value; |
9683 | size = 0; | |
9684 | if (!(sym->flags & BSF_SYNTHETIC)) | |
9685 | size = ((elf_symbol_type *) sym)->internal_elf_sym.st_size; | |
9686 | if (size == 0) | |
9687 | size = 1; | |
9688 | return size; | |
a06ea964 NC |
9689 | } |
9690 | ||
9691 | static bfd_boolean | |
cec5225b | 9692 | elfNN_aarch64_find_inliner_info (bfd *abfd, |
a06ea964 NC |
9693 | const char **filename_ptr, |
9694 | const char **functionname_ptr, | |
9695 | unsigned int *line_ptr) | |
9696 | { | |
9697 | bfd_boolean found; | |
9698 | found = _bfd_dwarf2_find_inliner_info | |
9699 | (abfd, filename_ptr, | |
9700 | functionname_ptr, line_ptr, &elf_tdata (abfd)->dwarf2_find_line_info); | |
9701 | return found; | |
9702 | } | |
9703 | ||
9704 | ||
ed7e9d0b AM |
9705 | static bfd_boolean |
9706 | elfNN_aarch64_init_file_header (bfd *abfd, struct bfd_link_info *link_info) | |
a06ea964 NC |
9707 | { |
9708 | Elf_Internal_Ehdr *i_ehdrp; /* ELF file header, internal form. */ | |
9709 | ||
ed7e9d0b AM |
9710 | if (!_bfd_elf_init_file_header (abfd, link_info)) |
9711 | return FALSE; | |
9712 | ||
a06ea964 | 9713 | i_ehdrp = elf_elfheader (abfd); |
a06ea964 | 9714 | i_ehdrp->e_ident[EI_ABIVERSION] = AARCH64_ELF_ABI_VERSION; |
ed7e9d0b | 9715 | return TRUE; |
a06ea964 NC |
9716 | } |
9717 | ||
9718 | static enum elf_reloc_type_class | |
cec5225b | 9719 | elfNN_aarch64_reloc_type_class (const struct bfd_link_info *info ATTRIBUTE_UNUSED, |
7e612e98 AM |
9720 | const asection *rel_sec ATTRIBUTE_UNUSED, |
9721 | const Elf_Internal_Rela *rela) | |
a06ea964 | 9722 | { |
f2e6a843 SN |
9723 | struct elf_aarch64_link_hash_table *htab = elf_aarch64_hash_table (info); |
9724 | ||
9725 | if (htab->root.dynsym != NULL | |
9726 | && htab->root.dynsym->contents != NULL) | |
9727 | { | |
9728 | /* Check relocation against STT_GNU_IFUNC symbol if there are | |
9729 | dynamic symbols. */ | |
9730 | bfd *abfd = info->output_bfd; | |
9731 | const struct elf_backend_data *bed = get_elf_backend_data (abfd); | |
9732 | unsigned long r_symndx = ELFNN_R_SYM (rela->r_info); | |
9733 | if (r_symndx != STN_UNDEF) | |
9734 | { | |
9735 | Elf_Internal_Sym sym; | |
9736 | if (!bed->s->swap_symbol_in (abfd, | |
9737 | (htab->root.dynsym->contents | |
9738 | + r_symndx * bed->s->sizeof_sym), | |
9739 | 0, &sym)) | |
9740 | { | |
9741 | /* xgettext:c-format */ | |
871b3ab2 | 9742 | _bfd_error_handler (_("%pB symbol number %lu references" |
f2e6a843 SN |
9743 | " nonexistent SHT_SYMTAB_SHNDX section"), |
9744 | abfd, r_symndx); | |
9745 | /* Ideally an error class should be returned here. */ | |
9746 | } | |
9747 | else if (ELF_ST_TYPE (sym.st_info) == STT_GNU_IFUNC) | |
9748 | return reloc_class_ifunc; | |
9749 | } | |
9750 | } | |
9751 | ||
cec5225b | 9752 | switch ((int) ELFNN_R_TYPE (rela->r_info)) |
a06ea964 | 9753 | { |
f2e6a843 | 9754 | case AARCH64_R (IRELATIVE): |
e19e9199 | 9755 | case MORELLO_R (IRELATIVE): |
f2e6a843 | 9756 | return reloc_class_ifunc; |
a6bb11b2 | 9757 | case AARCH64_R (RELATIVE): |
e19e9199 | 9758 | case MORELLO_R (RELATIVE): |
a06ea964 | 9759 | return reloc_class_relative; |
a6bb11b2 | 9760 | case AARCH64_R (JUMP_SLOT): |
e19e9199 | 9761 | case MORELLO_R (JUMP_SLOT): |
a06ea964 | 9762 | return reloc_class_plt; |
a6bb11b2 | 9763 | case AARCH64_R (COPY): |
a06ea964 NC |
9764 | return reloc_class_copy; |
9765 | default: | |
9766 | return reloc_class_normal; | |
9767 | } | |
9768 | } | |
9769 | ||
a06ea964 NC |
9770 | /* Handle an AArch64 specific section when reading an object file. This is |
9771 | called when bfd_section_from_shdr finds a section with an unknown | |
9772 | type. */ | |
9773 | ||
9774 | static bfd_boolean | |
cec5225b | 9775 | elfNN_aarch64_section_from_shdr (bfd *abfd, |
a06ea964 NC |
9776 | Elf_Internal_Shdr *hdr, |
9777 | const char *name, int shindex) | |
9778 | { | |
9779 | /* There ought to be a place to keep ELF backend specific flags, but | |
9780 | at the moment there isn't one. We just keep track of the | |
9781 | sections by their name, instead. Fortunately, the ABI gives | |
9782 | names for all the AArch64 specific sections, so we will probably get | |
9783 | away with this. */ | |
9784 | switch (hdr->sh_type) | |
9785 | { | |
9786 | case SHT_AARCH64_ATTRIBUTES: | |
9787 | break; | |
9788 | ||
9789 | default: | |
9790 | return FALSE; | |
9791 | } | |
9792 | ||
9793 | if (!_bfd_elf_make_section_from_shdr (abfd, hdr, name, shindex)) | |
9794 | return FALSE; | |
9795 | ||
9796 | return TRUE; | |
9797 | } | |
9798 | ||
a06ea964 NC |
9799 | typedef struct |
9800 | { | |
9801 | void *finfo; | |
9802 | struct bfd_link_info *info; | |
9803 | asection *sec; | |
9804 | int sec_shndx; | |
9805 | int (*func) (void *, const char *, Elf_Internal_Sym *, | |
9806 | asection *, struct elf_link_hash_entry *); | |
9807 | } output_arch_syminfo; | |
9808 | ||
9809 | enum map_symbol_type | |
9810 | { | |
9811 | AARCH64_MAP_INSN, | |
e19e9199 SP |
9812 | AARCH64_MAP_DATA, |
9813 | AARCH64_MAP_C64, | |
a06ea964 NC |
9814 | }; |
9815 | ||
9816 | ||
9817 | /* Output a single mapping symbol. */ | |
9818 | ||
9819 | static bfd_boolean | |
cec5225b | 9820 | elfNN_aarch64_output_map_sym (output_arch_syminfo *osi, |
a06ea964 NC |
9821 | enum map_symbol_type type, bfd_vma offset) |
9822 | { | |
3979cf50 | 9823 | static const char *names[3] = { "$x", "$d", "$c" }; |
a06ea964 NC |
9824 | Elf_Internal_Sym sym; |
9825 | ||
9826 | sym.st_value = (osi->sec->output_section->vma | |
9827 | + osi->sec->output_offset + offset); | |
9828 | sym.st_size = 0; | |
9829 | sym.st_other = 0; | |
9830 | sym.st_info = ELF_ST_INFO (STB_LOCAL, STT_NOTYPE); | |
9831 | sym.st_shndx = osi->sec_shndx; | |
8b21361b | 9832 | sym.st_target_internal = 0; |
a06ea964 NC |
9833 | return osi->func (osi->finfo, names[type], &sym, osi->sec, NULL) == 1; |
9834 | } | |
9835 | ||
a06ea964 NC |
9836 | /* Output a single local symbol for a generated stub. */ |
9837 | ||
9838 | static bfd_boolean | |
cec5225b | 9839 | elfNN_aarch64_output_stub_sym (output_arch_syminfo *osi, const char *name, |
a06ea964 NC |
9840 | bfd_vma offset, bfd_vma size) |
9841 | { | |
9842 | Elf_Internal_Sym sym; | |
9843 | ||
9844 | sym.st_value = (osi->sec->output_section->vma | |
9845 | + osi->sec->output_offset + offset); | |
9846 | sym.st_size = size; | |
9847 | sym.st_other = 0; | |
9848 | sym.st_info = ELF_ST_INFO (STB_LOCAL, STT_FUNC); | |
9849 | sym.st_shndx = osi->sec_shndx; | |
8b21361b | 9850 | sym.st_target_internal = 0; |
a06ea964 NC |
9851 | return osi->func (osi->finfo, name, &sym, osi->sec, NULL) == 1; |
9852 | } | |
9853 | ||
9854 | static bfd_boolean | |
9855 | aarch64_map_one_stub (struct bfd_hash_entry *gen_entry, void *in_arg) | |
9856 | { | |
cec5225b | 9857 | struct elf_aarch64_stub_hash_entry *stub_entry; |
a06ea964 NC |
9858 | asection *stub_sec; |
9859 | bfd_vma addr; | |
9860 | char *stub_name; | |
9861 | output_arch_syminfo *osi; | |
9862 | ||
9863 | /* Massage our args to the form they really have. */ | |
cec5225b | 9864 | stub_entry = (struct elf_aarch64_stub_hash_entry *) gen_entry; |
a06ea964 NC |
9865 | osi = (output_arch_syminfo *) in_arg; |
9866 | ||
9867 | stub_sec = stub_entry->stub_sec; | |
9868 | ||
9869 | /* Ensure this stub is attached to the current section being | |
9870 | processed. */ | |
9871 | if (stub_sec != osi->sec) | |
9872 | return TRUE; | |
9873 | ||
9874 | addr = (bfd_vma) stub_entry->stub_offset; | |
9875 | ||
9876 | stub_name = stub_entry->output_name; | |
9877 | ||
9878 | switch (stub_entry->stub_type) | |
9879 | { | |
9880 | case aarch64_stub_adrp_branch: | |
cec5225b | 9881 | if (!elfNN_aarch64_output_stub_sym (osi, stub_name, addr, |
a06ea964 NC |
9882 | sizeof (aarch64_adrp_branch_stub))) |
9883 | return FALSE; | |
cec5225b | 9884 | if (!elfNN_aarch64_output_map_sym (osi, AARCH64_MAP_INSN, addr)) |
a06ea964 NC |
9885 | return FALSE; |
9886 | break; | |
9887 | case aarch64_stub_long_branch: | |
cec5225b | 9888 | if (!elfNN_aarch64_output_stub_sym |
a06ea964 NC |
9889 | (osi, stub_name, addr, sizeof (aarch64_long_branch_stub))) |
9890 | return FALSE; | |
cec5225b | 9891 | if (!elfNN_aarch64_output_map_sym (osi, AARCH64_MAP_INSN, addr)) |
a06ea964 | 9892 | return FALSE; |
cec5225b | 9893 | if (!elfNN_aarch64_output_map_sym (osi, AARCH64_MAP_DATA, addr + 16)) |
a06ea964 NC |
9894 | return FALSE; |
9895 | break; | |
68fcca92 JW |
9896 | case aarch64_stub_erratum_835769_veneer: |
9897 | if (!elfNN_aarch64_output_stub_sym (osi, stub_name, addr, | |
9898 | sizeof (aarch64_erratum_835769_stub))) | |
9899 | return FALSE; | |
9900 | if (!elfNN_aarch64_output_map_sym (osi, AARCH64_MAP_INSN, addr)) | |
9901 | return FALSE; | |
9902 | break; | |
4106101c MS |
9903 | case aarch64_stub_erratum_843419_veneer: |
9904 | if (!elfNN_aarch64_output_stub_sym (osi, stub_name, addr, | |
9905 | sizeof (aarch64_erratum_843419_stub))) | |
9906 | return FALSE; | |
9907 | if (!elfNN_aarch64_output_map_sym (osi, AARCH64_MAP_INSN, addr)) | |
9908 | return FALSE; | |
9909 | break; | |
50e192f0 SP |
9910 | case aarch64_stub_branch_c64: |
9911 | if (!elfNN_aarch64_output_stub_sym (osi, stub_name, addr, | |
9912 | sizeof (aarch64_c64_branch_stub))) | |
9913 | return FALSE; | |
9914 | if (!elfNN_aarch64_output_map_sym (osi, AARCH64_MAP_C64, addr)) | |
9915 | return FALSE; | |
9916 | break; | |
9917 | case c64_stub_branch_aarch64: | |
9918 | case c64_stub_branch_c64: | |
9919 | if (!elfNN_aarch64_output_stub_sym (osi, stub_name, addr, | |
9920 | sizeof (c64_aarch64_branch_stub))) | |
9921 | return FALSE; | |
9922 | if (!elfNN_aarch64_output_map_sym (osi, AARCH64_MAP_C64, addr)) | |
9923 | return FALSE; | |
9924 | break; | |
9fca35fc TC |
9925 | case aarch64_stub_none: |
9926 | break; | |
4106101c | 9927 | |
a06ea964 | 9928 | default: |
8e2fe09f | 9929 | abort (); |
a06ea964 NC |
9930 | } |
9931 | ||
9932 | return TRUE; | |
9933 | } | |
9934 | ||
9935 | /* Output mapping symbols for linker generated sections. */ | |
9936 | ||
9937 | static bfd_boolean | |
cec5225b | 9938 | elfNN_aarch64_output_arch_local_syms (bfd *output_bfd, |
a06ea964 NC |
9939 | struct bfd_link_info *info, |
9940 | void *finfo, | |
9941 | int (*func) (void *, const char *, | |
9942 | Elf_Internal_Sym *, | |
9943 | asection *, | |
9944 | struct elf_link_hash_entry | |
9945 | *)) | |
9946 | { | |
9947 | output_arch_syminfo osi; | |
cec5225b | 9948 | struct elf_aarch64_link_hash_table *htab; |
a06ea964 | 9949 | |
cec5225b | 9950 | htab = elf_aarch64_hash_table (info); |
a06ea964 NC |
9951 | |
9952 | osi.finfo = finfo; | |
9953 | osi.info = info; | |
9954 | osi.func = func; | |
9955 | ||
9956 | /* Long calls stubs. */ | |
9957 | if (htab->stub_bfd && htab->stub_bfd->sections) | |
9958 | { | |
9959 | asection *stub_sec; | |
9960 | ||
9961 | for (stub_sec = htab->stub_bfd->sections; | |
9962 | stub_sec != NULL; stub_sec = stub_sec->next) | |
9963 | { | |
9964 | /* Ignore non-stub sections. */ | |
9965 | if (!strstr (stub_sec->name, STUB_SUFFIX)) | |
9966 | continue; | |
9967 | ||
9968 | osi.sec = stub_sec; | |
9969 | ||
9970 | osi.sec_shndx = _bfd_elf_section_from_bfd_section | |
9971 | (output_bfd, osi.sec->output_section); | |
9972 | ||
61865519 MS |
9973 | /* The first instruction in a stub is always a branch. */ |
9974 | if (!elfNN_aarch64_output_map_sym (&osi, AARCH64_MAP_INSN, 0)) | |
9975 | return FALSE; | |
9976 | ||
a06ea964 NC |
9977 | bfd_hash_traverse (&htab->stub_hash_table, aarch64_map_one_stub, |
9978 | &osi); | |
9979 | } | |
9980 | } | |
9981 | ||
9982 | /* Finally, output mapping symbols for the PLT. */ | |
9983 | if (!htab->root.splt || htab->root.splt->size == 0) | |
9984 | return TRUE; | |
9985 | ||
a06ea964 NC |
9986 | osi.sec_shndx = _bfd_elf_section_from_bfd_section |
9987 | (output_bfd, htab->root.splt->output_section); | |
9988 | osi.sec = htab->root.splt; | |
9989 | ||
e19e9199 SP |
9990 | elfNN_aarch64_output_map_sym (&osi, (htab->c64_rel ? AARCH64_MAP_C64 |
9991 | : AARCH64_MAP_INSN), 0); | |
a06ea964 NC |
9992 | |
9993 | return TRUE; | |
9994 | ||
9995 | } | |
9996 | ||
9997 | /* Allocate target specific section data. */ | |
9998 | ||
9999 | static bfd_boolean | |
cec5225b | 10000 | elfNN_aarch64_new_section_hook (bfd *abfd, asection *sec) |
a06ea964 NC |
10001 | { |
10002 | if (!sec->used_by_bfd) | |
10003 | { | |
10004 | _aarch64_elf_section_data *sdata; | |
986f0783 | 10005 | size_t amt = sizeof (*sdata); |
a06ea964 NC |
10006 | |
10007 | sdata = bfd_zalloc (abfd, amt); | |
10008 | if (sdata == NULL) | |
10009 | return FALSE; | |
f0070c1e | 10010 | sdata->elf.is_target_section_data = TRUE; |
a06ea964 NC |
10011 | sec->used_by_bfd = sdata; |
10012 | } | |
10013 | ||
a06ea964 NC |
10014 | return _bfd_elf_new_section_hook (abfd, sec); |
10015 | } | |
10016 | ||
10017 | ||
a06ea964 NC |
10018 | /* Create dynamic sections. This is different from the ARM backend in that |
10019 | the got, plt, gotplt and their relocation sections are all created in the | |
10020 | standard part of the bfd elf backend. */ | |
10021 | ||
10022 | static bfd_boolean | |
cec5225b | 10023 | elfNN_aarch64_create_dynamic_sections (bfd *dynobj, |
a06ea964 NC |
10024 | struct bfd_link_info *info) |
10025 | { | |
cc0efaa8 MS |
10026 | /* We need to create .got section. */ |
10027 | if (!aarch64_elf_create_got_section (dynobj, info)) | |
10028 | return FALSE; | |
a06ea964 | 10029 | |
9d19e4fd | 10030 | return _bfd_elf_create_dynamic_sections (dynobj, info); |
a06ea964 NC |
10031 | } |
10032 | ||
10033 | ||
10034 | /* Allocate space in .plt, .got and associated reloc sections for | |
10035 | dynamic relocs. */ | |
10036 | ||
10037 | static bfd_boolean | |
cec5225b | 10038 | elfNN_aarch64_allocate_dynrelocs (struct elf_link_hash_entry *h, void *inf) |
a06ea964 NC |
10039 | { |
10040 | struct bfd_link_info *info; | |
cec5225b YZ |
10041 | struct elf_aarch64_link_hash_table *htab; |
10042 | struct elf_aarch64_link_hash_entry *eh; | |
a06ea964 NC |
10043 | struct elf_dyn_relocs *p; |
10044 | ||
10045 | /* An example of a bfd_link_hash_indirect symbol is versioned | |
10046 | symbol. For example: __gxx_personality_v0(bfd_link_hash_indirect) | |
10047 | -> __gxx_personality_v0(bfd_link_hash_defined) | |
10048 | ||
10049 | There is no need to process bfd_link_hash_indirect symbols here | |
10050 | because we will also be presented with the concrete instance of | |
cec5225b | 10051 | the symbol and elfNN_aarch64_copy_indirect_symbol () will have been |
a06ea964 | 10052 | called to copy all relevant data from the generic to the concrete |
2d0ca824 | 10053 | symbol instance. */ |
a06ea964 NC |
10054 | if (h->root.type == bfd_link_hash_indirect) |
10055 | return TRUE; | |
10056 | ||
10057 | if (h->root.type == bfd_link_hash_warning) | |
10058 | h = (struct elf_link_hash_entry *) h->root.u.i.link; | |
10059 | ||
10060 | info = (struct bfd_link_info *) inf; | |
cec5225b | 10061 | htab = elf_aarch64_hash_table (info); |
a06ea964 | 10062 | |
1419bbe5 WN |
10063 | /* Since STT_GNU_IFUNC symbol must go through PLT, we handle it |
10064 | here if it is defined and referenced in a non-shared object. */ | |
10065 | if (h->type == STT_GNU_IFUNC | |
10066 | && h->def_regular) | |
10067 | return TRUE; | |
10068 | else if (htab->root.dynamic_sections_created && h->plt.refcount > 0) | |
a06ea964 NC |
10069 | { |
10070 | /* Make sure this symbol is output as a dynamic symbol. | |
07d6d2b8 | 10071 | Undefined weak syms won't yet be marked as dynamic. */ |
ff07562f JW |
10072 | if (h->dynindx == -1 && !h->forced_local |
10073 | && h->root.type == bfd_link_hash_undefweak) | |
a06ea964 NC |
10074 | { |
10075 | if (!bfd_elf_link_record_dynamic_symbol (info, h)) | |
10076 | return FALSE; | |
10077 | } | |
10078 | ||
0e1862bb | 10079 | if (bfd_link_pic (info) || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h)) |
a06ea964 NC |
10080 | { |
10081 | asection *s = htab->root.splt; | |
10082 | ||
10083 | /* If this is the first .plt entry, make room for the special | |
10084 | first entry. */ | |
10085 | if (s->size == 0) | |
10086 | s->size += htab->plt_header_size; | |
10087 | ||
10088 | h->plt.offset = s->size; | |
10089 | ||
10090 | /* If this symbol is not defined in a regular file, and we are | |
10091 | not generating a shared library, then set the symbol to this | |
10092 | location in the .plt. This is required to make function | |
10093 | pointers compare as equal between the normal executable and | |
10094 | the shared library. */ | |
0e1862bb | 10095 | if (!bfd_link_pic (info) && !h->def_regular) |
a06ea964 NC |
10096 | { |
10097 | h->root.u.def.section = s; | |
10098 | h->root.u.def.value = h->plt.offset; | |
10099 | } | |
10100 | ||
10101 | /* Make room for this entry. For now we only create the | |
10102 | small model PLT entries. We later need to find a way | |
10103 | of relaxing into these from the large model PLT entries. */ | |
37c18eed | 10104 | s->size += htab->plt_entry_size; |
a06ea964 NC |
10105 | |
10106 | /* We also need to make an entry in the .got.plt section, which | |
10107 | will be placed in the .got section by the linker script. */ | |
a1bdea65 | 10108 | htab->root.sgotplt->size += GOT_ENTRY_SIZE (htab); |
a06ea964 NC |
10109 | |
10110 | /* We also need to make an entry in the .rela.plt section. */ | |
10111 | htab->root.srelplt->size += RELOC_SIZE (htab); | |
10112 | ||
10113 | /* We need to ensure that all GOT entries that serve the PLT | |
10114 | are consecutive with the special GOT slots [0] [1] and | |
10115 | [2]. Any addtional relocations, such as | |
10116 | R_AARCH64_TLSDESC, must be placed after the PLT related | |
10117 | entries. We abuse the reloc_count such that during | |
10118 | sizing we adjust reloc_count to indicate the number of | |
10119 | PLT related reserved entries. In subsequent phases when | |
10120 | filling in the contents of the reloc entries, PLT related | |
10121 | entries are placed by computing their PLT index (0 | |
10122 | .. reloc_count). While other none PLT relocs are placed | |
10123 | at the slot indicated by reloc_count and reloc_count is | |
10124 | updated. */ | |
10125 | ||
10126 | htab->root.srelplt->reloc_count++; | |
823710d5 SN |
10127 | |
10128 | /* Mark the DSO in case R_<CLS>_JUMP_SLOT relocs against | |
10129 | variant PCS symbols are present. */ | |
10130 | if (h->other & STO_AARCH64_VARIANT_PCS) | |
10131 | htab->variant_pcs = 1; | |
10132 | ||
a06ea964 NC |
10133 | } |
10134 | else | |
10135 | { | |
10136 | h->plt.offset = (bfd_vma) - 1; | |
10137 | h->needs_plt = 0; | |
10138 | } | |
10139 | } | |
10140 | else | |
10141 | { | |
10142 | h->plt.offset = (bfd_vma) - 1; | |
10143 | h->needs_plt = 0; | |
10144 | } | |
10145 | ||
cec5225b | 10146 | eh = (struct elf_aarch64_link_hash_entry *) h; |
a06ea964 NC |
10147 | eh->tlsdesc_got_jump_table_offset = (bfd_vma) - 1; |
10148 | ||
10149 | if (h->got.refcount > 0) | |
10150 | { | |
10151 | bfd_boolean dyn; | |
cec5225b | 10152 | unsigned got_type = elf_aarch64_hash_entry (h)->got_type; |
a06ea964 NC |
10153 | |
10154 | h->got.offset = (bfd_vma) - 1; | |
10155 | ||
10156 | dyn = htab->root.dynamic_sections_created; | |
10157 | ||
10158 | /* Make sure this symbol is output as a dynamic symbol. | |
07d6d2b8 | 10159 | Undefined weak syms won't yet be marked as dynamic. */ |
ff07562f JW |
10160 | if (dyn && h->dynindx == -1 && !h->forced_local |
10161 | && h->root.type == bfd_link_hash_undefweak) | |
a06ea964 NC |
10162 | { |
10163 | if (!bfd_elf_link_record_dynamic_symbol (info, h)) | |
10164 | return FALSE; | |
10165 | } | |
10166 | ||
10167 | if (got_type == GOT_UNKNOWN) | |
10168 | { | |
10169 | } | |
a1bdea65 SP |
10170 | else if (got_type == GOT_NORMAL |
10171 | || got_type == GOT_CAP) | |
a06ea964 NC |
10172 | { |
10173 | h->got.offset = htab->root.sgot->size; | |
a1bdea65 | 10174 | htab->root.sgot->size += GOT_ENTRY_SIZE (htab); |
a06ea964 NC |
10175 | if ((ELF_ST_VISIBILITY (h->other) == STV_DEFAULT |
10176 | || h->root.type != bfd_link_hash_undefweak) | |
0e1862bb | 10177 | && (bfd_link_pic (info) |
a377ae2a SN |
10178 | || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, 0, h)) |
10179 | /* Undefined weak symbol in static PIE resolves to 0 without | |
10180 | any dynamic relocations. */ | |
10181 | && !UNDEFWEAK_NO_DYNAMIC_RELOC (info, h)) | |
a06ea964 NC |
10182 | { |
10183 | htab->root.srelgot->size += RELOC_SIZE (htab); | |
10184 | } | |
8d4edc5f SP |
10185 | else if (bfd_link_executable (info) && !bfd_link_pic (info)) |
10186 | htab->srelcaps->size += RELOC_SIZE (htab); | |
a06ea964 NC |
10187 | } |
10188 | else | |
10189 | { | |
10190 | int indx; | |
10191 | if (got_type & GOT_TLSDESC_GD) | |
10192 | { | |
10193 | eh->tlsdesc_got_jump_table_offset = | |
10194 | (htab->root.sgotplt->size | |
10195 | - aarch64_compute_jump_table_size (htab)); | |
a1bdea65 | 10196 | htab->root.sgotplt->size += GOT_ENTRY_SIZE (htab) * 2; |
a06ea964 NC |
10197 | h->got.offset = (bfd_vma) - 2; |
10198 | } | |
10199 | ||
10200 | if (got_type & GOT_TLS_GD) | |
10201 | { | |
10202 | h->got.offset = htab->root.sgot->size; | |
a1bdea65 | 10203 | htab->root.sgot->size += GOT_ENTRY_SIZE (htab) * 2; |
a06ea964 NC |
10204 | } |
10205 | ||
10206 | if (got_type & GOT_TLS_IE) | |
10207 | { | |
10208 | h->got.offset = htab->root.sgot->size; | |
a1bdea65 | 10209 | htab->root.sgot->size += GOT_ENTRY_SIZE (htab); |
a06ea964 NC |
10210 | } |
10211 | ||
10212 | indx = h && h->dynindx != -1 ? h->dynindx : 0; | |
10213 | if ((ELF_ST_VISIBILITY (h->other) == STV_DEFAULT | |
10214 | || h->root.type != bfd_link_hash_undefweak) | |
6dda7875 | 10215 | && (!bfd_link_executable (info) |
a06ea964 | 10216 | || indx != 0 |
4ca9b406 SP |
10217 | || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, 0, h) |
10218 | /* On Morello support only TLSDESC_GD to TLSLE relaxation; | |
10219 | for everything else we must emit a dynamic relocation. */ | |
10220 | || got_type & GOT_CAP)) | |
a06ea964 NC |
10221 | { |
10222 | if (got_type & GOT_TLSDESC_GD) | |
10223 | { | |
10224 | htab->root.srelplt->size += RELOC_SIZE (htab); | |
10225 | /* Note reloc_count not incremented here! We have | |
10226 | already adjusted reloc_count for this relocation | |
10227 | type. */ | |
10228 | ||
10229 | /* TLSDESC PLT is now needed, but not yet determined. */ | |
9bcc30e4 | 10230 | htab->root.tlsdesc_plt = (bfd_vma) - 1; |
a06ea964 NC |
10231 | } |
10232 | ||
10233 | if (got_type & GOT_TLS_GD) | |
10234 | htab->root.srelgot->size += RELOC_SIZE (htab) * 2; | |
10235 | ||
10236 | if (got_type & GOT_TLS_IE) | |
10237 | htab->root.srelgot->size += RELOC_SIZE (htab); | |
10238 | } | |
10239 | } | |
10240 | } | |
10241 | else | |
10242 | { | |
10243 | h->got.offset = (bfd_vma) - 1; | |
10244 | } | |
10245 | ||
190eb1dd | 10246 | if (h->dyn_relocs == NULL) |
a06ea964 NC |
10247 | return TRUE; |
10248 | ||
10249 | /* In the shared -Bsymbolic case, discard space allocated for | |
10250 | dynamic pc-relative relocs against symbols which turn out to be | |
10251 | defined in regular objects. For the normal shared case, discard | |
10252 | space for pc-relative relocs that have become local due to symbol | |
10253 | visibility changes. */ | |
10254 | ||
0e1862bb | 10255 | if (bfd_link_pic (info)) |
a06ea964 NC |
10256 | { |
10257 | /* Relocs that use pc_count are those that appear on a call | |
07d6d2b8 AM |
10258 | insn, or certain REL relocs that can generated via assembly. |
10259 | We want calls to protected symbols to resolve directly to the | |
10260 | function rather than going via the plt. If people want | |
10261 | function pointer comparisons to work as expected then they | |
10262 | should avoid writing weird assembly. */ | |
a06ea964 NC |
10263 | if (SYMBOL_CALLS_LOCAL (info, h)) |
10264 | { | |
10265 | struct elf_dyn_relocs **pp; | |
10266 | ||
190eb1dd | 10267 | for (pp = &h->dyn_relocs; (p = *pp) != NULL;) |
a06ea964 NC |
10268 | { |
10269 | p->count -= p->pc_count; | |
10270 | p->pc_count = 0; | |
10271 | if (p->count == 0) | |
10272 | *pp = p->next; | |
10273 | else | |
10274 | pp = &p->next; | |
10275 | } | |
10276 | } | |
10277 | ||
10278 | /* Also discard relocs on undefined weak syms with non-default | |
07d6d2b8 | 10279 | visibility. */ |
190eb1dd | 10280 | if (h->dyn_relocs != NULL && h->root.type == bfd_link_hash_undefweak) |
a06ea964 | 10281 | { |
ddb7fd0f L |
10282 | if (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT |
10283 | || UNDEFWEAK_NO_DYNAMIC_RELOC (info, h)) | |
190eb1dd | 10284 | h->dyn_relocs = NULL; |
a06ea964 NC |
10285 | |
10286 | /* Make sure undefined weak symbols are output as a dynamic | |
10287 | symbol in PIEs. */ | |
10288 | else if (h->dynindx == -1 | |
10289 | && !h->forced_local | |
ff07562f | 10290 | && h->root.type == bfd_link_hash_undefweak |
a06ea964 NC |
10291 | && !bfd_elf_link_record_dynamic_symbol (info, h)) |
10292 | return FALSE; | |
10293 | } | |
10294 | ||
10295 | } | |
10296 | else if (ELIMINATE_COPY_RELOCS) | |
10297 | { | |
10298 | /* For the non-shared case, discard space for relocs against | |
07d6d2b8 AM |
10299 | symbols which turn out to need copy relocs or are not |
10300 | dynamic. */ | |
a06ea964 NC |
10301 | |
10302 | if (!h->non_got_ref | |
10303 | && ((h->def_dynamic | |
10304 | && !h->def_regular) | |
10305 | || (htab->root.dynamic_sections_created | |
10306 | && (h->root.type == bfd_link_hash_undefweak | |
10307 | || h->root.type == bfd_link_hash_undefined)))) | |
10308 | { | |
10309 | /* Make sure this symbol is output as a dynamic symbol. | |
10310 | Undefined weak syms won't yet be marked as dynamic. */ | |
10311 | if (h->dynindx == -1 | |
10312 | && !h->forced_local | |
ff07562f | 10313 | && h->root.type == bfd_link_hash_undefweak |
a06ea964 NC |
10314 | && !bfd_elf_link_record_dynamic_symbol (info, h)) |
10315 | return FALSE; | |
10316 | ||
10317 | /* If that succeeded, we know we'll be keeping all the | |
10318 | relocs. */ | |
10319 | if (h->dynindx != -1) | |
10320 | goto keep; | |
10321 | } | |
10322 | ||
190eb1dd | 10323 | h->dyn_relocs = NULL; |
a06ea964 NC |
10324 | |
10325 | keep:; | |
10326 | } | |
10327 | ||
10328 | /* Finally, allocate space. */ | |
190eb1dd | 10329 | for (p = h->dyn_relocs; p != NULL; p = p->next) |
a06ea964 NC |
10330 | { |
10331 | asection *sreloc; | |
10332 | ||
10333 | sreloc = elf_section_data (p->sec)->sreloc; | |
10334 | ||
10335 | BFD_ASSERT (sreloc != NULL); | |
10336 | ||
10337 | sreloc->size += p->count * RELOC_SIZE (htab); | |
10338 | } | |
10339 | ||
10340 | return TRUE; | |
10341 | } | |
10342 | ||
1419bbe5 WN |
10343 | /* Allocate space in .plt, .got and associated reloc sections for |
10344 | ifunc dynamic relocs. */ | |
10345 | ||
10346 | static bfd_boolean | |
10347 | elfNN_aarch64_allocate_ifunc_dynrelocs (struct elf_link_hash_entry *h, | |
10348 | void *inf) | |
10349 | { | |
10350 | struct bfd_link_info *info; | |
10351 | struct elf_aarch64_link_hash_table *htab; | |
1419bbe5 WN |
10352 | |
10353 | /* An example of a bfd_link_hash_indirect symbol is versioned | |
10354 | symbol. For example: __gxx_personality_v0(bfd_link_hash_indirect) | |
10355 | -> __gxx_personality_v0(bfd_link_hash_defined) | |
10356 | ||
10357 | There is no need to process bfd_link_hash_indirect symbols here | |
10358 | because we will also be presented with the concrete instance of | |
10359 | the symbol and elfNN_aarch64_copy_indirect_symbol () will have been | |
10360 | called to copy all relevant data from the generic to the concrete | |
2d0ca824 | 10361 | symbol instance. */ |
1419bbe5 WN |
10362 | if (h->root.type == bfd_link_hash_indirect) |
10363 | return TRUE; | |
10364 | ||
10365 | if (h->root.type == bfd_link_hash_warning) | |
10366 | h = (struct elf_link_hash_entry *) h->root.u.i.link; | |
10367 | ||
10368 | info = (struct bfd_link_info *) inf; | |
10369 | htab = elf_aarch64_hash_table (info); | |
10370 | ||
1419bbe5 WN |
10371 | /* Since STT_GNU_IFUNC symbol must go through PLT, we handle it |
10372 | here if it is defined and referenced in a non-shared object. */ | |
10373 | if (h->type == STT_GNU_IFUNC | |
10374 | && h->def_regular) | |
10375 | return _bfd_elf_allocate_ifunc_dyn_relocs (info, h, | |
190eb1dd | 10376 | &h->dyn_relocs, |
1419bbe5 WN |
10377 | htab->plt_entry_size, |
10378 | htab->plt_header_size, | |
a1bdea65 | 10379 | GOT_ENTRY_SIZE (htab), |
233cc9c1 | 10380 | FALSE); |
1419bbe5 WN |
10381 | return TRUE; |
10382 | } | |
10383 | ||
1419bbe5 WN |
10384 | /* Allocate space in .plt, .got and associated reloc sections for |
10385 | local ifunc dynamic relocs. */ | |
10386 | ||
10387 | static bfd_boolean | |
10388 | elfNN_aarch64_allocate_local_ifunc_dynrelocs (void **slot, void *inf) | |
10389 | { | |
10390 | struct elf_link_hash_entry *h | |
10391 | = (struct elf_link_hash_entry *) *slot; | |
10392 | ||
10393 | if (h->type != STT_GNU_IFUNC | |
10394 | || !h->def_regular | |
10395 | || !h->ref_regular | |
10396 | || !h->forced_local | |
10397 | || h->root.type != bfd_link_hash_defined) | |
10398 | abort (); | |
10399 | ||
10400 | return elfNN_aarch64_allocate_ifunc_dynrelocs (h, inf); | |
10401 | } | |
a06ea964 | 10402 | |
a06ea964 NC |
10403 | /* This is the most important function of all . Innocuosly named |
10404 | though ! */ | |
2d0ca824 | 10405 | |
a06ea964 | 10406 | static bfd_boolean |
a1bdea65 | 10407 | elfNN_aarch64_size_dynamic_sections (bfd *output_bfd, |
a06ea964 NC |
10408 | struct bfd_link_info *info) |
10409 | { | |
cec5225b | 10410 | struct elf_aarch64_link_hash_table *htab; |
a06ea964 NC |
10411 | bfd *dynobj; |
10412 | asection *s; | |
10413 | bfd_boolean relocs; | |
10414 | bfd *ibfd; | |
10415 | ||
cec5225b | 10416 | htab = elf_aarch64_hash_table ((info)); |
a06ea964 NC |
10417 | dynobj = htab->root.dynobj; |
10418 | ||
10419 | BFD_ASSERT (dynobj != NULL); | |
10420 | ||
10421 | if (htab->root.dynamic_sections_created) | |
10422 | { | |
9b8b325a | 10423 | if (bfd_link_executable (info) && !info->nointerp) |
a06ea964 NC |
10424 | { |
10425 | s = bfd_get_linker_section (dynobj, ".interp"); | |
10426 | if (s == NULL) | |
10427 | abort (); | |
10428 | s->size = sizeof ELF_DYNAMIC_INTERPRETER; | |
10429 | s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER; | |
10430 | } | |
10431 | } | |
10432 | ||
a1bdea65 SP |
10433 | aarch64_elf_init_got_section (output_bfd, info); |
10434 | ||
e19e9199 SP |
10435 | setup_plt_values (info, elf_aarch64_tdata (output_bfd)->plt_type); |
10436 | ||
a06ea964 NC |
10437 | /* Set up .got offsets for local syms, and space for local dynamic |
10438 | relocs. */ | |
c72f2fb2 | 10439 | for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link.next) |
a06ea964 NC |
10440 | { |
10441 | struct elf_aarch64_local_symbol *locals = NULL; | |
10442 | Elf_Internal_Shdr *symtab_hdr; | |
10443 | asection *srel; | |
10444 | unsigned int i; | |
10445 | ||
10446 | if (!is_aarch64_elf (ibfd)) | |
10447 | continue; | |
10448 | ||
10449 | for (s = ibfd->sections; s != NULL; s = s->next) | |
10450 | { | |
10451 | struct elf_dyn_relocs *p; | |
10452 | ||
10453 | for (p = (struct elf_dyn_relocs *) | |
10454 | (elf_section_data (s)->local_dynrel); p != NULL; p = p->next) | |
10455 | { | |
10456 | if (!bfd_is_abs_section (p->sec) | |
10457 | && bfd_is_abs_section (p->sec->output_section)) | |
10458 | { | |
10459 | /* Input section has been discarded, either because | |
10460 | it is a copy of a linkonce section or due to | |
10461 | linker script /DISCARD/, so we'll be discarding | |
10462 | the relocs too. */ | |
10463 | } | |
10464 | else if (p->count != 0) | |
10465 | { | |
10466 | srel = elf_section_data (p->sec)->sreloc; | |
10467 | srel->size += p->count * RELOC_SIZE (htab); | |
10468 | if ((p->sec->output_section->flags & SEC_READONLY) != 0) | |
10469 | info->flags |= DF_TEXTREL; | |
10470 | } | |
10471 | } | |
10472 | } | |
10473 | ||
cec5225b | 10474 | locals = elf_aarch64_locals (ibfd); |
a06ea964 NC |
10475 | if (!locals) |
10476 | continue; | |
10477 | ||
10478 | symtab_hdr = &elf_symtab_hdr (ibfd); | |
10479 | srel = htab->root.srelgot; | |
10480 | for (i = 0; i < symtab_hdr->sh_info; i++) | |
10481 | { | |
10482 | locals[i].got_offset = (bfd_vma) - 1; | |
10483 | locals[i].tlsdesc_got_jump_table_offset = (bfd_vma) - 1; | |
10484 | if (locals[i].got_refcount > 0) | |
10485 | { | |
10486 | unsigned got_type = locals[i].got_type; | |
10487 | if (got_type & GOT_TLSDESC_GD) | |
10488 | { | |
10489 | locals[i].tlsdesc_got_jump_table_offset = | |
10490 | (htab->root.sgotplt->size | |
10491 | - aarch64_compute_jump_table_size (htab)); | |
a1bdea65 | 10492 | htab->root.sgotplt->size += GOT_ENTRY_SIZE (htab) * 2; |
a06ea964 NC |
10493 | locals[i].got_offset = (bfd_vma) - 2; |
10494 | } | |
10495 | ||
10496 | if (got_type & GOT_TLS_GD) | |
10497 | { | |
10498 | locals[i].got_offset = htab->root.sgot->size; | |
a1bdea65 | 10499 | htab->root.sgot->size += GOT_ENTRY_SIZE (htab) * 2; |
a06ea964 NC |
10500 | } |
10501 | ||
b53b1bed | 10502 | if (got_type & GOT_TLS_IE |
a1bdea65 SP |
10503 | || got_type & GOT_NORMAL |
10504 | || got_type & GOT_CAP) | |
a06ea964 NC |
10505 | { |
10506 | locals[i].got_offset = htab->root.sgot->size; | |
a1bdea65 | 10507 | htab->root.sgot->size += GOT_ENTRY_SIZE (htab); |
a06ea964 NC |
10508 | } |
10509 | ||
10510 | if (got_type == GOT_UNKNOWN) | |
10511 | { | |
10512 | } | |
10513 | ||
0e1862bb | 10514 | if (bfd_link_pic (info)) |
a06ea964 NC |
10515 | { |
10516 | if (got_type & GOT_TLSDESC_GD) | |
10517 | { | |
10518 | htab->root.srelplt->size += RELOC_SIZE (htab); | |
10519 | /* Note RELOC_COUNT not incremented here! */ | |
9bcc30e4 | 10520 | htab->root.tlsdesc_plt = (bfd_vma) - 1; |
a06ea964 NC |
10521 | } |
10522 | ||
10523 | if (got_type & GOT_TLS_GD) | |
10524 | htab->root.srelgot->size += RELOC_SIZE (htab) * 2; | |
10525 | ||
b53b1bed | 10526 | if (got_type & GOT_TLS_IE |
a1bdea65 SP |
10527 | || got_type & GOT_NORMAL |
10528 | || got_type & GOT_CAP) | |
a06ea964 NC |
10529 | htab->root.srelgot->size += RELOC_SIZE (htab); |
10530 | } | |
8d4edc5f SP |
10531 | /* Static binary; put relocs into srelcaps. */ |
10532 | else if (bfd_link_executable (info) && (got_type & GOT_CAP)) | |
10533 | htab->srelcaps->size += RELOC_SIZE (htab); | |
a06ea964 NC |
10534 | } |
10535 | else | |
10536 | { | |
10537 | locals[i].got_refcount = (bfd_vma) - 1; | |
10538 | } | |
10539 | } | |
10540 | } | |
10541 | ||
10542 | ||
10543 | /* Allocate global sym .plt and .got entries, and space for global | |
10544 | sym dynamic relocs. */ | |
cec5225b | 10545 | elf_link_hash_traverse (&htab->root, elfNN_aarch64_allocate_dynrelocs, |
a06ea964 NC |
10546 | info); |
10547 | ||
1419bbe5 WN |
10548 | /* Allocate global ifunc sym .plt and .got entries, and space for global |
10549 | ifunc sym dynamic relocs. */ | |
10550 | elf_link_hash_traverse (&htab->root, elfNN_aarch64_allocate_ifunc_dynrelocs, | |
10551 | info); | |
10552 | ||
1419bbe5 WN |
10553 | /* Allocate .plt and .got entries, and space for local ifunc symbols. */ |
10554 | htab_traverse (htab->loc_hash_table, | |
10555 | elfNN_aarch64_allocate_local_ifunc_dynrelocs, | |
10556 | info); | |
a06ea964 | 10557 | |
d6cf562a MM |
10558 | if (bfd_link_executable (info) |
10559 | && !bfd_link_pic (info) | |
10560 | && htab->srelcaps | |
10561 | && htab->srelcaps->size > 0) | |
10562 | { | |
10563 | struct elf_link_hash_entry *h; | |
10564 | ||
10565 | h = _bfd_elf_define_linkage_sym (output_bfd, info, | |
10566 | htab->srelcaps, | |
10567 | "__rela_dyn_start"); | |
10568 | h = _bfd_elf_define_linkage_sym (output_bfd, info, | |
10569 | htab->srelcaps, | |
10570 | "__rela_dyn_end"); | |
10571 | ||
10572 | h->root.u.def.value = htab->srelcaps->vma + htab->srelcaps->size; | |
10573 | } | |
10574 | ||
a06ea964 NC |
10575 | /* For every jump slot reserved in the sgotplt, reloc_count is |
10576 | incremented. However, when we reserve space for TLS descriptors, | |
10577 | it's not incremented, so in order to compute the space reserved | |
10578 | for them, it suffices to multiply the reloc count by the jump | |
10579 | slot size. */ | |
10580 | ||
10581 | if (htab->root.srelplt) | |
8847944f | 10582 | htab->sgotplt_jump_table_size = aarch64_compute_jump_table_size (htab); |
a06ea964 | 10583 | |
9bcc30e4 | 10584 | if (htab->root.tlsdesc_plt) |
a06ea964 NC |
10585 | { |
10586 | if (htab->root.splt->size == 0) | |
37c18eed | 10587 | htab->root.splt->size += htab->plt_header_size; |
a06ea964 | 10588 | |
a06ea964 | 10589 | /* If we're not using lazy TLS relocations, don't generate the |
ce12121b | 10590 | GOT and PLT entry required. */ |
9bcc30e4 L |
10591 | if ((info->flags & DF_BIND_NOW)) |
10592 | htab->root.tlsdesc_plt = 0; | |
10593 | else | |
a06ea964 | 10594 | { |
9bcc30e4 | 10595 | htab->root.tlsdesc_plt = htab->root.splt->size; |
ce12121b TC |
10596 | htab->root.splt->size += htab->tlsdesc_plt_entry_size; |
10597 | ||
9bcc30e4 | 10598 | htab->root.tlsdesc_got = htab->root.sgot->size; |
a1bdea65 | 10599 | htab->root.sgot->size += GOT_ENTRY_SIZE (htab); |
a06ea964 NC |
10600 | } |
10601 | } | |
10602 | ||
68fcca92 | 10603 | /* Init mapping symbols information to use later to distingush between |
4106101c MS |
10604 | code and data while scanning for errata. */ |
10605 | if (htab->fix_erratum_835769 || htab->fix_erratum_843419) | |
68fcca92 JW |
10606 | for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link.next) |
10607 | { | |
10608 | if (!is_aarch64_elf (ibfd)) | |
10609 | continue; | |
7ff36d1a | 10610 | bfd_elfNN_aarch64_init_maps (ibfd, info); |
68fcca92 JW |
10611 | } |
10612 | ||
a06ea964 NC |
10613 | /* We now have determined the sizes of the various dynamic sections. |
10614 | Allocate memory for them. */ | |
10615 | relocs = FALSE; | |
10616 | for (s = dynobj->sections; s != NULL; s = s->next) | |
10617 | { | |
10618 | if ((s->flags & SEC_LINKER_CREATED) == 0) | |
10619 | continue; | |
10620 | ||
10621 | if (s == htab->root.splt | |
10622 | || s == htab->root.sgot | |
10623 | || s == htab->root.sgotplt | |
10624 | || s == htab->root.iplt | |
9d19e4fd | 10625 | || s == htab->root.igotplt |
5474d94f AM |
10626 | || s == htab->root.sdynbss |
10627 | || s == htab->root.sdynrelro) | |
a06ea964 NC |
10628 | { |
10629 | /* Strip this section if we don't need it; see the | |
10630 | comment below. */ | |
10631 | } | |
fd361982 | 10632 | else if (CONST_STRNEQ (bfd_section_name (s), ".rela")) |
a06ea964 NC |
10633 | { |
10634 | if (s->size != 0 && s != htab->root.srelplt) | |
10635 | relocs = TRUE; | |
10636 | ||
10637 | /* We use the reloc_count field as a counter if we need | |
10638 | to copy relocs into the output file. */ | |
10639 | if (s != htab->root.srelplt) | |
10640 | s->reloc_count = 0; | |
10641 | } | |
10642 | else | |
10643 | { | |
10644 | /* It's not one of our sections, so don't allocate space. */ | |
10645 | continue; | |
10646 | } | |
10647 | ||
10648 | if (s->size == 0) | |
10649 | { | |
10650 | /* If we don't need this section, strip it from the | |
10651 | output file. This is mostly to handle .rela.bss and | |
10652 | .rela.plt. We must create both sections in | |
10653 | create_dynamic_sections, because they must be created | |
10654 | before the linker maps input sections to output | |
10655 | sections. The linker does that before | |
10656 | adjust_dynamic_symbol is called, and it is that | |
10657 | function which decides whether anything needs to go | |
10658 | into these sections. */ | |
a06ea964 NC |
10659 | s->flags |= SEC_EXCLUDE; |
10660 | continue; | |
10661 | } | |
10662 | ||
10663 | if ((s->flags & SEC_HAS_CONTENTS) == 0) | |
10664 | continue; | |
10665 | ||
10666 | /* Allocate memory for the section contents. We use bfd_zalloc | |
07d6d2b8 AM |
10667 | here in case unused entries are not reclaimed before the |
10668 | section's contents are written out. This should not happen, | |
10669 | but this way if it does, we get a R_AARCH64_NONE reloc instead | |
10670 | of garbage. */ | |
a06ea964 NC |
10671 | s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->size); |
10672 | if (s->contents == NULL) | |
10673 | return FALSE; | |
10674 | } | |
10675 | ||
10676 | if (htab->root.dynamic_sections_created) | |
10677 | { | |
10678 | /* Add some entries to the .dynamic section. We fill in the | |
07d6d2b8 AM |
10679 | values later, in elfNN_aarch64_finish_dynamic_sections, but we |
10680 | must add the entries now so that we get the correct size for | |
10681 | the .dynamic section. The DT_DEBUG entry is filled in by the | |
10682 | dynamic linker and used by the debugger. */ | |
a06ea964 NC |
10683 | #define add_dynamic_entry(TAG, VAL) \ |
10684 | _bfd_elf_add_dynamic_entry (info, TAG, VAL) | |
10685 | ||
3084d7a2 L |
10686 | if (!_bfd_elf_add_dynamic_tags (output_bfd, info, relocs)) |
10687 | return FALSE; | |
a06ea964 NC |
10688 | |
10689 | if (htab->root.splt->size != 0) | |
10690 | { | |
823710d5 SN |
10691 | if (htab->variant_pcs |
10692 | && !add_dynamic_entry (DT_AARCH64_VARIANT_PCS, 0)) | |
10693 | return FALSE; | |
10694 | ||
1dbade74 SD |
10695 | if ((elf_aarch64_tdata (output_bfd)->plt_type == PLT_BTI_PAC) |
10696 | && (!add_dynamic_entry (DT_AARCH64_BTI_PLT, 0) | |
10697 | || !add_dynamic_entry (DT_AARCH64_PAC_PLT, 0))) | |
10698 | return FALSE; | |
10699 | ||
10700 | else if ((elf_aarch64_tdata (output_bfd)->plt_type == PLT_BTI) | |
10701 | && !add_dynamic_entry (DT_AARCH64_BTI_PLT, 0)) | |
10702 | return FALSE; | |
10703 | ||
10704 | else if ((elf_aarch64_tdata (output_bfd)->plt_type == PLT_PAC) | |
10705 | && !add_dynamic_entry (DT_AARCH64_PAC_PLT, 0)) | |
37c18eed | 10706 | return FALSE; |
a06ea964 | 10707 | } |
a06ea964 NC |
10708 | } |
10709 | #undef add_dynamic_entry | |
10710 | ||
10711 | return TRUE; | |
a06ea964 NC |
10712 | } |
10713 | ||
10714 | static inline void | |
caed7120 YZ |
10715 | elf_aarch64_update_plt_entry (bfd *output_bfd, |
10716 | bfd_reloc_code_real_type r_type, | |
10717 | bfd_byte *plt_entry, bfd_vma value) | |
a06ea964 | 10718 | { |
caed7120 YZ |
10719 | reloc_howto_type *howto = elfNN_aarch64_howto_from_bfd_reloc (r_type); |
10720 | ||
1d75a8e2 NC |
10721 | /* FIXME: We should check the return value from this function call. */ |
10722 | (void) _bfd_aarch64_elf_put_addend (output_bfd, plt_entry, r_type, howto, value); | |
a06ea964 NC |
10723 | } |
10724 | ||
e19e9199 SP |
10725 | static void |
10726 | aarch64_update_c64_plt_entry (bfd *output_bfd, bfd_byte *plt_entry, | |
10727 | bfd_vma plt_base, bfd_vma plt_got_ent) | |
10728 | { | |
10729 | /* Fill in the top 20 bits for this: ADRP c16, PLT_GOT + n * 16. | |
10730 | ADRP: ((PG(S+A)-PG(P)) >> 12) & 0xfffff */ | |
10731 | elf_aarch64_update_plt_entry (output_bfd, BFD_RELOC_MORELLO_ADR_HI20_PCREL, | |
10732 | plt_entry, | |
10733 | PG (plt_got_ent) - PG (plt_base)); | |
10734 | ||
10735 | elf_aarch64_update_plt_entry (output_bfd, | |
10736 | BFD_RELOC_AARCH64_LDST128_LO12, | |
10737 | plt_entry + 4, | |
10738 | PG_OFFSET (plt_got_ent)); | |
10739 | ||
10740 | elf_aarch64_update_plt_entry (output_bfd, BFD_RELOC_AARCH64_ADD_LO12, | |
10741 | plt_entry + 8, | |
10742 | PG_OFFSET (plt_got_ent)); | |
10743 | } | |
10744 | ||
a06ea964 | 10745 | static void |
cec5225b YZ |
10746 | elfNN_aarch64_create_small_pltn_entry (struct elf_link_hash_entry *h, |
10747 | struct elf_aarch64_link_hash_table | |
1419bbe5 WN |
10748 | *htab, bfd *output_bfd, |
10749 | struct bfd_link_info *info) | |
a06ea964 NC |
10750 | { |
10751 | bfd_byte *plt_entry; | |
10752 | bfd_vma plt_index; | |
10753 | bfd_vma got_offset; | |
10754 | bfd_vma gotplt_entry_address; | |
10755 | bfd_vma plt_entry_address; | |
10756 | Elf_Internal_Rela rela; | |
10757 | bfd_byte *loc; | |
1419bbe5 WN |
10758 | asection *plt, *gotplt, *relplt; |
10759 | ||
10760 | /* When building a static executable, use .iplt, .igot.plt and | |
10761 | .rela.iplt sections for STT_GNU_IFUNC symbols. */ | |
10762 | if (htab->root.splt != NULL) | |
10763 | { | |
10764 | plt = htab->root.splt; | |
10765 | gotplt = htab->root.sgotplt; | |
10766 | relplt = htab->root.srelplt; | |
10767 | } | |
10768 | else | |
10769 | { | |
10770 | plt = htab->root.iplt; | |
10771 | gotplt = htab->root.igotplt; | |
10772 | relplt = htab->root.irelplt; | |
10773 | } | |
10774 | ||
10775 | /* Get the index in the procedure linkage table which | |
10776 | corresponds to this symbol. This is the index of this symbol | |
10777 | in all the symbols for which we are making plt entries. The | |
10778 | first entry in the procedure linkage table is reserved. | |
a06ea964 | 10779 | |
1419bbe5 WN |
10780 | Get the offset into the .got table of the entry that |
10781 | corresponds to this function. Each .got entry is GOT_ENTRY_SIZE | |
10782 | bytes. The first three are reserved for the dynamic linker. | |
692e2b8b | 10783 | |
1419bbe5 WN |
10784 | For static executables, we don't reserve anything. */ |
10785 | ||
10786 | if (plt == htab->root.splt) | |
10787 | { | |
10788 | plt_index = (h->plt.offset - htab->plt_header_size) / htab->plt_entry_size; | |
a1bdea65 | 10789 | got_offset = (plt_index + 3) * GOT_ENTRY_SIZE (htab); |
1419bbe5 WN |
10790 | } |
10791 | else | |
10792 | { | |
10793 | plt_index = h->plt.offset / htab->plt_entry_size; | |
a1bdea65 | 10794 | got_offset = plt_index * GOT_ENTRY_SIZE (htab); |
1419bbe5 WN |
10795 | } |
10796 | ||
10797 | plt_entry = plt->contents + h->plt.offset; | |
10798 | plt_entry_address = plt->output_section->vma | |
f44a1f8e | 10799 | + plt->output_offset + h->plt.offset; |
1419bbe5 WN |
10800 | gotplt_entry_address = gotplt->output_section->vma + |
10801 | gotplt->output_offset + got_offset; | |
a06ea964 NC |
10802 | |
10803 | /* Copy in the boiler-plate for the PLTn entry. */ | |
37c18eed SD |
10804 | memcpy (plt_entry, htab->plt_entry, htab->plt_entry_size); |
10805 | ||
e19e9199 SP |
10806 | if (htab->c64_rel) |
10807 | aarch64_update_c64_plt_entry (output_bfd, plt_entry, plt_entry_address, | |
10808 | gotplt_entry_address); | |
10809 | else | |
10810 | { | |
a06ea964 | 10811 | |
e19e9199 SP |
10812 | /* First instruction in BTI enabled PLT stub is a BTI |
10813 | instruction so skip it. */ | |
10814 | if (elf_aarch64_tdata (output_bfd)->plt_type & PLT_BTI | |
10815 | && elf_elfheader (output_bfd)->e_type == ET_EXEC) | |
10816 | plt_entry = plt_entry + 4; | |
a06ea964 | 10817 | |
e19e9199 SP |
10818 | /* Fill in the top 21 bits for this: ADRP x16, PLT_GOT + n * 8. |
10819 | ADRP: ((PG(S+A)-PG(P)) >> 12) & 0x1fffff */ | |
10820 | elf_aarch64_update_plt_entry (output_bfd, | |
10821 | BFD_RELOC_AARCH64_ADR_HI21_PCREL, | |
10822 | plt_entry, | |
10823 | PG (gotplt_entry_address) - | |
10824 | PG (plt_entry_address)); | |
a06ea964 | 10825 | |
e19e9199 SP |
10826 | /* Fill in the lo12 bits for the load from the pltgot. */ |
10827 | elf_aarch64_update_plt_entry (output_bfd, BFD_RELOC_AARCH64_LDSTNN_LO12, | |
10828 | plt_entry + 4, | |
10829 | PG_OFFSET (gotplt_entry_address)); | |
a06ea964 | 10830 | |
e19e9199 SP |
10831 | /* Fill in the lo12 bits for the add from the pltgot entry. */ |
10832 | elf_aarch64_update_plt_entry (output_bfd, BFD_RELOC_AARCH64_ADD_LO12, | |
10833 | plt_entry + 8, | |
10834 | PG_OFFSET (gotplt_entry_address)); | |
10835 | } | |
10836 | ||
10837 | /* All the GOTPLT Entries are essentially initialized to PLT0. Set LSB if | |
10838 | the PLT is C64. */ | |
10839 | bfd_vma plt0 = ((plt->output_section->vma + plt->output_offset) | |
10840 | | htab->c64_rel); | |
10841 | bfd_put_NN (output_bfd, plt0, gotplt->contents + got_offset); | |
a06ea964 | 10842 | |
a06ea964 | 10843 | rela.r_offset = gotplt_entry_address; |
1419bbe5 WN |
10844 | |
10845 | if (h->dynindx == -1 | |
0e1862bb | 10846 | || ((bfd_link_executable (info) |
1419bbe5 WN |
10847 | || ELF_ST_VISIBILITY (h->other) != STV_DEFAULT) |
10848 | && h->def_regular | |
10849 | && h->type == STT_GNU_IFUNC)) | |
10850 | { | |
10851 | /* If an STT_GNU_IFUNC symbol is locally defined, generate | |
10852 | R_AARCH64_IRELATIVE instead of R_AARCH64_JUMP_SLOT. */ | |
e19e9199 SP |
10853 | rela.r_info = (elf_aarch64_hash_entry (h)->got_type == GOT_CAP |
10854 | ? ELFNN_R_INFO (0, MORELLO_R (IRELATIVE)) | |
10855 | : ELFNN_R_INFO (0, AARCH64_R (IRELATIVE))); | |
1419bbe5 WN |
10856 | rela.r_addend = (h->root.u.def.value |
10857 | + h->root.u.def.section->output_section->vma | |
10858 | + h->root.u.def.section->output_offset); | |
10859 | } | |
10860 | else | |
10861 | { | |
10862 | /* Fill in the entry in the .rela.plt section. */ | |
e19e9199 SP |
10863 | rela.r_info = (elf_aarch64_hash_entry (h)->got_type == GOT_CAP |
10864 | ? ELFNN_R_INFO (h->dynindx, MORELLO_R (JUMP_SLOT)) | |
10865 | : ELFNN_R_INFO (h->dynindx, AARCH64_R (JUMP_SLOT))); | |
1419bbe5 WN |
10866 | rela.r_addend = 0; |
10867 | } | |
a06ea964 NC |
10868 | |
10869 | /* Compute the relocation entry to used based on PLT index and do | |
10870 | not adjust reloc_count. The reloc_count has already been adjusted | |
10871 | to account for this entry. */ | |
1419bbe5 | 10872 | loc = relplt->contents + plt_index * RELOC_SIZE (htab); |
cec5225b | 10873 | bfd_elfNN_swap_reloca_out (output_bfd, &rela, loc); |
a06ea964 NC |
10874 | } |
10875 | ||
10876 | /* Size sections even though they're not dynamic. We use it to setup | |
10877 | _TLS_MODULE_BASE_, if needed. */ | |
10878 | ||
10879 | static bfd_boolean | |
cec5225b | 10880 | elfNN_aarch64_always_size_sections (bfd *output_bfd, |
a06ea964 NC |
10881 | struct bfd_link_info *info) |
10882 | { | |
10883 | asection *tls_sec; | |
10884 | ||
0e1862bb | 10885 | if (bfd_link_relocatable (info)) |
a06ea964 NC |
10886 | return TRUE; |
10887 | ||
10888 | tls_sec = elf_hash_table (info)->tls_sec; | |
10889 | ||
10890 | if (tls_sec) | |
10891 | { | |
10892 | struct elf_link_hash_entry *tlsbase; | |
10893 | ||
10894 | tlsbase = elf_link_hash_lookup (elf_hash_table (info), | |
10895 | "_TLS_MODULE_BASE_", TRUE, TRUE, FALSE); | |
10896 | ||
10897 | if (tlsbase) | |
10898 | { | |
10899 | struct bfd_link_hash_entry *h = NULL; | |
10900 | const struct elf_backend_data *bed = | |
10901 | get_elf_backend_data (output_bfd); | |
10902 | ||
10903 | if (!(_bfd_generic_link_add_one_symbol | |
10904 | (info, output_bfd, "_TLS_MODULE_BASE_", BSF_LOCAL, | |
10905 | tls_sec, 0, NULL, FALSE, bed->collect, &h))) | |
10906 | return FALSE; | |
10907 | ||
10908 | tlsbase->type = STT_TLS; | |
10909 | tlsbase = (struct elf_link_hash_entry *) h; | |
10910 | tlsbase->def_regular = 1; | |
10911 | tlsbase->other = STV_HIDDEN; | |
10912 | (*bed->elf_backend_hide_symbol) (info, tlsbase, TRUE); | |
10913 | } | |
10914 | } | |
10915 | ||
10916 | return TRUE; | |
10917 | } | |
10918 | ||
10919 | /* Finish up dynamic symbol handling. We set the contents of various | |
10920 | dynamic sections here. */ | |
2d0ca824 | 10921 | |
a06ea964 | 10922 | static bfd_boolean |
cec5225b | 10923 | elfNN_aarch64_finish_dynamic_symbol (bfd *output_bfd, |
a06ea964 NC |
10924 | struct bfd_link_info *info, |
10925 | struct elf_link_hash_entry *h, | |
10926 | Elf_Internal_Sym *sym) | |
10927 | { | |
cec5225b YZ |
10928 | struct elf_aarch64_link_hash_table *htab; |
10929 | htab = elf_aarch64_hash_table (info); | |
a06ea964 NC |
10930 | |
10931 | if (h->plt.offset != (bfd_vma) - 1) | |
10932 | { | |
1419bbe5 WN |
10933 | asection *plt, *gotplt, *relplt; |
10934 | ||
a06ea964 | 10935 | /* This symbol has an entry in the procedure linkage table. Set |
07d6d2b8 | 10936 | it up. */ |
a06ea964 | 10937 | |
1419bbe5 WN |
10938 | /* When building a static executable, use .iplt, .igot.plt and |
10939 | .rela.iplt sections for STT_GNU_IFUNC symbols. */ | |
10940 | if (htab->root.splt != NULL) | |
10941 | { | |
10942 | plt = htab->root.splt; | |
10943 | gotplt = htab->root.sgotplt; | |
10944 | relplt = htab->root.srelplt; | |
10945 | } | |
10946 | else | |
10947 | { | |
10948 | plt = htab->root.iplt; | |
10949 | gotplt = htab->root.igotplt; | |
10950 | relplt = htab->root.irelplt; | |
10951 | } | |
10952 | ||
10953 | /* This symbol has an entry in the procedure linkage table. Set | |
10954 | it up. */ | |
10955 | if ((h->dynindx == -1 | |
0e1862bb | 10956 | && !((h->forced_local || bfd_link_executable (info)) |
1419bbe5 WN |
10957 | && h->def_regular |
10958 | && h->type == STT_GNU_IFUNC)) | |
10959 | || plt == NULL | |
10960 | || gotplt == NULL | |
10961 | || relplt == NULL) | |
f955cccf | 10962 | return FALSE; |
a06ea964 | 10963 | |
1419bbe5 | 10964 | elfNN_aarch64_create_small_pltn_entry (h, htab, output_bfd, info); |
a06ea964 NC |
10965 | if (!h->def_regular) |
10966 | { | |
10967 | /* Mark the symbol as undefined, rather than as defined in | |
46b87d49 | 10968 | the .plt section. */ |
a06ea964 | 10969 | sym->st_shndx = SHN_UNDEF; |
46b87d49 WN |
10970 | /* If the symbol is weak we need to clear the value. |
10971 | Otherwise, the PLT entry would provide a definition for | |
10972 | the symbol even if the symbol wasn't defined anywhere, | |
10973 | and so the symbol would never be NULL. Leave the value if | |
10974 | there were any relocations where pointer equality matters | |
10975 | (this is a clue for the dynamic linker, to make function | |
10976 | pointer comparisons work between an application and shared | |
10977 | library). */ | |
10978 | if (!h->ref_regular_nonweak || !h->pointer_equality_needed) | |
10979 | sym->st_value = 0; | |
a06ea964 NC |
10980 | } |
10981 | } | |
10982 | ||
a1bdea65 SP |
10983 | bfd_boolean is_c64 = elf_aarch64_hash_entry (h)->got_type == GOT_CAP; |
10984 | ||
a06ea964 | 10985 | if (h->got.offset != (bfd_vma) - 1 |
a1bdea65 SP |
10986 | && (elf_aarch64_hash_entry (h)->got_type == GOT_NORMAL |
10987 | || elf_aarch64_hash_entry (h)->got_type == GOT_CAP) | |
a377ae2a SN |
10988 | /* Undefined weak symbol in static PIE resolves to 0 without |
10989 | any dynamic relocations. */ | |
10990 | && !UNDEFWEAK_NO_DYNAMIC_RELOC (info, h)) | |
a06ea964 NC |
10991 | { |
10992 | Elf_Internal_Rela rela; | |
10993 | bfd_byte *loc; | |
10994 | ||
10995 | /* This symbol has an entry in the global offset table. Set it | |
07d6d2b8 | 10996 | up. */ |
a06ea964 NC |
10997 | if (htab->root.sgot == NULL || htab->root.srelgot == NULL) |
10998 | abort (); | |
10999 | ||
11000 | rela.r_offset = (htab->root.sgot->output_section->vma | |
11001 | + htab->root.sgot->output_offset | |
11002 | + (h->got.offset & ~(bfd_vma) 1)); | |
11003 | ||
49206388 WN |
11004 | if (h->def_regular |
11005 | && h->type == STT_GNU_IFUNC) | |
11006 | { | |
0e1862bb | 11007 | if (bfd_link_pic (info)) |
49206388 WN |
11008 | { |
11009 | /* Generate R_AARCH64_GLOB_DAT. */ | |
11010 | goto do_glob_dat; | |
11011 | } | |
11012 | else | |
11013 | { | |
11014 | asection *plt; | |
11015 | ||
11016 | if (!h->pointer_equality_needed) | |
11017 | abort (); | |
11018 | ||
11019 | /* For non-shared object, we can't use .got.plt, which | |
11020 | contains the real function address if we need pointer | |
11021 | equality. We load the GOT entry with the PLT entry. */ | |
11022 | plt = htab->root.splt ? htab->root.splt : htab->root.iplt; | |
11023 | bfd_put_NN (output_bfd, (plt->output_section->vma | |
11024 | + plt->output_offset | |
11025 | + h->plt.offset), | |
11026 | htab->root.sgot->contents | |
11027 | + (h->got.offset & ~(bfd_vma) 1)); | |
11028 | return TRUE; | |
11029 | } | |
11030 | } | |
0e1862bb | 11031 | else if (bfd_link_pic (info) && SYMBOL_REFERENCES_LOCAL (info, h)) |
a06ea964 | 11032 | { |
0ee3a6db | 11033 | if (!(h->def_regular || ELF_COMMON_DEF_P (h))) |
a06ea964 NC |
11034 | return FALSE; |
11035 | ||
11036 | BFD_ASSERT ((h->got.offset & 1) != 0); | |
a1bdea65 SP |
11037 | if (is_c64) |
11038 | { | |
11039 | rela.r_info = ELFNN_R_INFO (0, MORELLO_R (RELATIVE)); | |
11040 | rela.r_addend = 0; | |
11041 | } | |
11042 | else | |
11043 | { | |
11044 | rela.r_info = ELFNN_R_INFO (0, AARCH64_R (RELATIVE)); | |
11045 | rela.r_addend = (h->root.u.def.value | |
11046 | + h->root.u.def.section->output_section->vma | |
11047 | + h->root.u.def.section->output_offset); | |
11048 | } | |
a06ea964 NC |
11049 | } |
11050 | else | |
11051 | { | |
dc1e8a47 | 11052 | do_glob_dat: |
a06ea964 | 11053 | BFD_ASSERT ((h->got.offset & 1) == 0); |
cec5225b | 11054 | bfd_put_NN (output_bfd, (bfd_vma) 0, |
a06ea964 | 11055 | htab->root.sgot->contents + h->got.offset); |
a1bdea65 SP |
11056 | rela.r_info = ELFNN_R_INFO (h->dynindx, |
11057 | (is_c64 ? MORELLO_R (GLOB_DAT) | |
11058 | : AARCH64_R (GLOB_DAT))); | |
a06ea964 NC |
11059 | rela.r_addend = 0; |
11060 | } | |
11061 | ||
11062 | loc = htab->root.srelgot->contents; | |
11063 | loc += htab->root.srelgot->reloc_count++ * RELOC_SIZE (htab); | |
cec5225b | 11064 | bfd_elfNN_swap_reloca_out (output_bfd, &rela, loc); |
a06ea964 NC |
11065 | } |
11066 | ||
11067 | if (h->needs_copy) | |
11068 | { | |
11069 | Elf_Internal_Rela rela; | |
5474d94f | 11070 | asection *s; |
a06ea964 NC |
11071 | bfd_byte *loc; |
11072 | ||
11073 | /* This symbol needs a copy reloc. Set it up. */ | |
a06ea964 NC |
11074 | if (h->dynindx == -1 |
11075 | || (h->root.type != bfd_link_hash_defined | |
11076 | && h->root.type != bfd_link_hash_defweak) | |
9d19e4fd | 11077 | || htab->root.srelbss == NULL) |
a06ea964 NC |
11078 | abort (); |
11079 | ||
11080 | rela.r_offset = (h->root.u.def.value | |
11081 | + h->root.u.def.section->output_section->vma | |
11082 | + h->root.u.def.section->output_offset); | |
a6bb11b2 | 11083 | rela.r_info = ELFNN_R_INFO (h->dynindx, AARCH64_R (COPY)); |
a06ea964 | 11084 | rela.r_addend = 0; |
afbf7e8e | 11085 | if (h->root.u.def.section == htab->root.sdynrelro) |
5474d94f AM |
11086 | s = htab->root.sreldynrelro; |
11087 | else | |
11088 | s = htab->root.srelbss; | |
11089 | loc = s->contents + s->reloc_count++ * RELOC_SIZE (htab); | |
cec5225b | 11090 | bfd_elfNN_swap_reloca_out (output_bfd, &rela, loc); |
a06ea964 NC |
11091 | } |
11092 | ||
11093 | /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. SYM may | |
11094 | be NULL for local symbols. */ | |
11095 | if (sym != NULL | |
9637f6ef | 11096 | && (h == elf_hash_table (info)->hdynamic |
a06ea964 NC |
11097 | || h == elf_hash_table (info)->hgot)) |
11098 | sym->st_shndx = SHN_ABS; | |
11099 | ||
11100 | return TRUE; | |
11101 | } | |
11102 | ||
1419bbe5 WN |
11103 | /* Finish up local dynamic symbol handling. We set the contents of |
11104 | various dynamic sections here. */ | |
11105 | ||
11106 | static bfd_boolean | |
11107 | elfNN_aarch64_finish_local_dynamic_symbol (void **slot, void *inf) | |
11108 | { | |
11109 | struct elf_link_hash_entry *h | |
11110 | = (struct elf_link_hash_entry *) *slot; | |
11111 | struct bfd_link_info *info | |
11112 | = (struct bfd_link_info *) inf; | |
11113 | ||
11114 | return elfNN_aarch64_finish_dynamic_symbol (info->output_bfd, | |
11115 | info, h, NULL); | |
11116 | } | |
11117 | ||
a06ea964 | 11118 | static void |
cec5225b YZ |
11119 | elfNN_aarch64_init_small_plt0_entry (bfd *output_bfd ATTRIBUTE_UNUSED, |
11120 | struct elf_aarch64_link_hash_table | |
a06ea964 NC |
11121 | *htab) |
11122 | { | |
11123 | /* Fill in PLT0. Fixme:RR Note this doesn't distinguish between | |
11124 | small and large plts and at the minute just generates | |
11125 | the small PLT. */ | |
11126 | ||
cec5225b | 11127 | /* PLT0 of the small PLT looks like this in ELF64 - |
a06ea964 NC |
11128 | stp x16, x30, [sp, #-16]! // Save the reloc and lr on stack. |
11129 | adrp x16, PLT_GOT + 16 // Get the page base of the GOTPLT | |
11130 | ldr x17, [x16, #:lo12:PLT_GOT+16] // Load the address of the | |
11131 | // symbol resolver | |
11132 | add x16, x16, #:lo12:PLT_GOT+16 // Load the lo12 bits of the | |
11133 | // GOTPLT entry for this. | |
11134 | br x17 | |
cec5225b | 11135 | PLT0 will be slightly different in ELF32 due to different got entry |
2d0ca824 | 11136 | size. */ |
caed7120 | 11137 | bfd_vma plt_got_2nd_ent; /* Address of GOT[2]. */ |
a06ea964 NC |
11138 | bfd_vma plt_base; |
11139 | ||
11140 | ||
37c18eed SD |
11141 | memcpy (htab->root.splt->contents, htab->plt0_entry, |
11142 | htab->plt_header_size); | |
4d3bb356 SN |
11143 | |
11144 | /* PR 26312: Explicitly set the sh_entsize to 0 so that | |
11145 | consumers do not think that the section contains fixed | |
11146 | sized objects. */ | |
11147 | elf_section_data (htab->root.splt->output_section)->this_hdr.sh_entsize = 0; | |
a06ea964 | 11148 | |
caed7120 YZ |
11149 | plt_got_2nd_ent = (htab->root.sgotplt->output_section->vma |
11150 | + htab->root.sgotplt->output_offset | |
a1bdea65 | 11151 | + GOT_ENTRY_SIZE (htab) * 2); |
a06ea964 NC |
11152 | |
11153 | plt_base = htab->root.splt->output_section->vma + | |
f44a1f8e | 11154 | htab->root.splt->output_offset; |
a06ea964 | 11155 | |
e19e9199 SP |
11156 | bfd_byte *plt0_entry = htab->root.splt->contents; |
11157 | ||
11158 | if (htab->c64_rel) | |
11159 | { | |
11160 | aarch64_update_c64_plt_entry (output_bfd, plt0_entry + 4, | |
11161 | plt_base + 4, plt_got_2nd_ent); | |
11162 | return; | |
11163 | } | |
11164 | ||
37c18eed SD |
11165 | /* First instruction in BTI enabled PLT stub is a BTI |
11166 | instruction so skip it. */ | |
37c18eed SD |
11167 | if (elf_aarch64_tdata (output_bfd)->plt_type & PLT_BTI) |
11168 | plt0_entry = plt0_entry + 4; | |
11169 | ||
a06ea964 NC |
11170 | /* Fill in the top 21 bits for this: ADRP x16, PLT_GOT + n * 8. |
11171 | ADRP: ((PG(S+A)-PG(P)) >> 12) & 0x1fffff */ | |
caed7120 | 11172 | elf_aarch64_update_plt_entry (output_bfd, BFD_RELOC_AARCH64_ADR_HI21_PCREL, |
37c18eed | 11173 | plt0_entry + 4, |
caed7120 | 11174 | PG (plt_got_2nd_ent) - PG (plt_base + 4)); |
a06ea964 | 11175 | |
caed7120 | 11176 | elf_aarch64_update_plt_entry (output_bfd, BFD_RELOC_AARCH64_LDSTNN_LO12, |
37c18eed | 11177 | plt0_entry + 8, |
caed7120 | 11178 | PG_OFFSET (plt_got_2nd_ent)); |
a06ea964 | 11179 | |
caed7120 | 11180 | elf_aarch64_update_plt_entry (output_bfd, BFD_RELOC_AARCH64_ADD_LO12, |
37c18eed | 11181 | plt0_entry + 12, |
caed7120 | 11182 | PG_OFFSET (plt_got_2nd_ent)); |
a06ea964 NC |
11183 | } |
11184 | ||
11185 | static bfd_boolean | |
cec5225b | 11186 | elfNN_aarch64_finish_dynamic_sections (bfd *output_bfd, |
a06ea964 NC |
11187 | struct bfd_link_info *info) |
11188 | { | |
cec5225b | 11189 | struct elf_aarch64_link_hash_table *htab; |
a06ea964 NC |
11190 | bfd *dynobj; |
11191 | asection *sdyn; | |
11192 | ||
cec5225b | 11193 | htab = elf_aarch64_hash_table (info); |
a06ea964 NC |
11194 | dynobj = htab->root.dynobj; |
11195 | sdyn = bfd_get_linker_section (dynobj, ".dynamic"); | |
11196 | ||
11197 | if (htab->root.dynamic_sections_created) | |
11198 | { | |
cec5225b | 11199 | ElfNN_External_Dyn *dyncon, *dynconend; |
a06ea964 NC |
11200 | |
11201 | if (sdyn == NULL || htab->root.sgot == NULL) | |
11202 | abort (); | |
11203 | ||
cec5225b YZ |
11204 | dyncon = (ElfNN_External_Dyn *) sdyn->contents; |
11205 | dynconend = (ElfNN_External_Dyn *) (sdyn->contents + sdyn->size); | |
a06ea964 NC |
11206 | for (; dyncon < dynconend; dyncon++) |
11207 | { | |
11208 | Elf_Internal_Dyn dyn; | |
11209 | asection *s; | |
11210 | ||
cec5225b | 11211 | bfd_elfNN_swap_dyn_in (dynobj, dyncon, &dyn); |
a06ea964 NC |
11212 | |
11213 | switch (dyn.d_tag) | |
11214 | { | |
11215 | default: | |
11216 | continue; | |
11217 | ||
11218 | case DT_PLTGOT: | |
11219 | s = htab->root.sgotplt; | |
11220 | dyn.d_un.d_ptr = s->output_section->vma + s->output_offset; | |
11221 | break; | |
11222 | ||
11223 | case DT_JMPREL: | |
4ade44b7 AM |
11224 | s = htab->root.srelplt; |
11225 | dyn.d_un.d_ptr = s->output_section->vma + s->output_offset; | |
a06ea964 NC |
11226 | break; |
11227 | ||
11228 | case DT_PLTRELSZ: | |
c955de36 | 11229 | s = htab->root.srelplt; |
a06ea964 NC |
11230 | dyn.d_un.d_val = s->size; |
11231 | break; | |
11232 | ||
a06ea964 NC |
11233 | case DT_TLSDESC_PLT: |
11234 | s = htab->root.splt; | |
11235 | dyn.d_un.d_ptr = s->output_section->vma + s->output_offset | |
9bcc30e4 | 11236 | + htab->root.tlsdesc_plt; |
a06ea964 NC |
11237 | break; |
11238 | ||
11239 | case DT_TLSDESC_GOT: | |
11240 | s = htab->root.sgot; | |
9bcc30e4 | 11241 | BFD_ASSERT (htab->root.tlsdesc_got != (bfd_vma)-1); |
a06ea964 | 11242 | dyn.d_un.d_ptr = s->output_section->vma + s->output_offset |
9bcc30e4 | 11243 | + htab->root.tlsdesc_got; |
a06ea964 NC |
11244 | break; |
11245 | } | |
11246 | ||
cec5225b | 11247 | bfd_elfNN_swap_dyn_out (output_bfd, &dyn, dyncon); |
a06ea964 NC |
11248 | } |
11249 | ||
11250 | } | |
11251 | ||
11252 | /* Fill in the special first entry in the procedure linkage table. */ | |
11253 | if (htab->root.splt && htab->root.splt->size > 0) | |
11254 | { | |
cec5225b | 11255 | elfNN_aarch64_init_small_plt0_entry (output_bfd, htab); |
a06ea964 | 11256 | |
9bcc30e4 | 11257 | if (htab->root.tlsdesc_plt && !(info->flags & DF_BIND_NOW)) |
a06ea964 | 11258 | { |
9bcc30e4 | 11259 | BFD_ASSERT (htab->root.tlsdesc_got != (bfd_vma)-1); |
cec5225b | 11260 | bfd_put_NN (output_bfd, (bfd_vma) 0, |
9bcc30e4 | 11261 | htab->root.sgot->contents + htab->root.tlsdesc_got); |
a06ea964 | 11262 | |
37c18eed SD |
11263 | const bfd_byte *entry = elfNN_aarch64_tlsdesc_small_plt_entry; |
11264 | htab->tlsdesc_plt_entry_size = PLT_TLSDESC_ENTRY_SIZE; | |
11265 | ||
4ca9b406 SP |
11266 | unsigned adrp_rtype = BFD_RELOC_AARCH64_ADR_HI21_PCREL; |
11267 | unsigned ldr_rtype = BFD_RELOC_AARCH64_LDSTNN_LO12; | |
11268 | ||
37c18eed | 11269 | aarch64_plt_type type = elf_aarch64_tdata (output_bfd)->plt_type; |
4ca9b406 SP |
11270 | if (htab->c64_rel) |
11271 | { | |
11272 | entry = elfNN_aarch64_tlsdesc_small_plt_c64_entry; | |
11273 | adrp_rtype = BFD_RELOC_MORELLO_ADR_HI20_PCREL; | |
11274 | ldr_rtype = BFD_RELOC_AARCH64_LDST128_LO12; | |
11275 | } | |
11276 | else if (type == PLT_BTI || type == PLT_BTI_PAC) | |
37c18eed SD |
11277 | { |
11278 | entry = elfNN_aarch64_tlsdesc_small_plt_bti_entry; | |
37c18eed SD |
11279 | } |
11280 | ||
9bcc30e4 | 11281 | memcpy (htab->root.splt->contents + htab->root.tlsdesc_plt, |
37c18eed | 11282 | entry, htab->tlsdesc_plt_entry_size); |
a06ea964 NC |
11283 | |
11284 | { | |
11285 | bfd_vma adrp1_addr = | |
11286 | htab->root.splt->output_section->vma | |
9bcc30e4 L |
11287 | + htab->root.splt->output_offset |
11288 | + htab->root.tlsdesc_plt + 4; | |
a06ea964 | 11289 | |
caed7120 | 11290 | bfd_vma adrp2_addr = adrp1_addr + 4; |
a06ea964 NC |
11291 | |
11292 | bfd_vma got_addr = | |
11293 | htab->root.sgot->output_section->vma | |
11294 | + htab->root.sgot->output_offset; | |
11295 | ||
11296 | bfd_vma pltgot_addr = | |
11297 | htab->root.sgotplt->output_section->vma | |
11298 | + htab->root.sgotplt->output_offset; | |
11299 | ||
9bcc30e4 | 11300 | bfd_vma dt_tlsdesc_got = got_addr + htab->root.tlsdesc_got; |
caed7120 YZ |
11301 | |
11302 | bfd_byte *plt_entry = | |
9bcc30e4 | 11303 | htab->root.splt->contents + htab->root.tlsdesc_plt; |
a06ea964 | 11304 | |
37c18eed SD |
11305 | /* First instruction in BTI enabled PLT stub is a BTI |
11306 | instruction so skip it. */ | |
11307 | if (type & PLT_BTI) | |
11308 | { | |
11309 | plt_entry = plt_entry + 4; | |
11310 | adrp1_addr = adrp1_addr + 4; | |
11311 | adrp2_addr = adrp2_addr + 4; | |
11312 | } | |
11313 | ||
a06ea964 | 11314 | /* adrp x2, DT_TLSDESC_GOT */ |
caed7120 | 11315 | elf_aarch64_update_plt_entry (output_bfd, |
4ca9b406 | 11316 | adrp_rtype, |
caed7120 YZ |
11317 | plt_entry + 4, |
11318 | (PG (dt_tlsdesc_got) | |
11319 | - PG (adrp1_addr))); | |
a06ea964 NC |
11320 | |
11321 | /* adrp x3, 0 */ | |
caed7120 | 11322 | elf_aarch64_update_plt_entry (output_bfd, |
4ca9b406 | 11323 | adrp_rtype, |
caed7120 YZ |
11324 | plt_entry + 8, |
11325 | (PG (pltgot_addr) | |
11326 | - PG (adrp2_addr))); | |
a06ea964 NC |
11327 | |
11328 | /* ldr x2, [x2, #0] */ | |
caed7120 | 11329 | elf_aarch64_update_plt_entry (output_bfd, |
4ca9b406 | 11330 | ldr_rtype, |
caed7120 YZ |
11331 | plt_entry + 12, |
11332 | PG_OFFSET (dt_tlsdesc_got)); | |
a06ea964 NC |
11333 | |
11334 | /* add x3, x3, 0 */ | |
caed7120 YZ |
11335 | elf_aarch64_update_plt_entry (output_bfd, |
11336 | BFD_RELOC_AARCH64_ADD_LO12, | |
11337 | plt_entry + 16, | |
11338 | PG_OFFSET (pltgot_addr)); | |
a06ea964 NC |
11339 | } |
11340 | } | |
11341 | } | |
11342 | ||
11343 | if (htab->root.sgotplt) | |
11344 | { | |
11345 | if (bfd_is_abs_section (htab->root.sgotplt->output_section)) | |
11346 | { | |
4eca0228 | 11347 | _bfd_error_handler |
871b3ab2 | 11348 | (_("discarded output section: `%pA'"), htab->root.sgotplt); |
a06ea964 NC |
11349 | return FALSE; |
11350 | } | |
11351 | ||
11352 | /* Fill in the first three entries in the global offset table. */ | |
11353 | if (htab->root.sgotplt->size > 0) | |
11354 | { | |
8db339a6 MS |
11355 | bfd_put_NN (output_bfd, (bfd_vma) 0, htab->root.sgotplt->contents); |
11356 | ||
a06ea964 | 11357 | /* Write GOT[1] and GOT[2], needed for the dynamic linker. */ |
cec5225b | 11358 | bfd_put_NN (output_bfd, |
a06ea964 | 11359 | (bfd_vma) 0, |
a1bdea65 | 11360 | htab->root.sgotplt->contents + GOT_ENTRY_SIZE (htab)); |
cec5225b | 11361 | bfd_put_NN (output_bfd, |
a06ea964 | 11362 | (bfd_vma) 0, |
a1bdea65 SP |
11363 | (htab->root.sgotplt->contents |
11364 | + GOT_ENTRY_SIZE (htab) * 2)); | |
a06ea964 NC |
11365 | } |
11366 | ||
8db339a6 MS |
11367 | if (htab->root.sgot) |
11368 | { | |
11369 | if (htab->root.sgot->size > 0) | |
11370 | { | |
11371 | bfd_vma addr = | |
11372 | sdyn ? sdyn->output_section->vma + sdyn->output_offset : 0; | |
11373 | bfd_put_NN (output_bfd, addr, htab->root.sgot->contents); | |
11374 | } | |
11375 | } | |
11376 | ||
a06ea964 | 11377 | elf_section_data (htab->root.sgotplt->output_section)-> |
a1bdea65 | 11378 | this_hdr.sh_entsize = GOT_ENTRY_SIZE (htab); |
a06ea964 NC |
11379 | } |
11380 | ||
11381 | if (htab->root.sgot && htab->root.sgot->size > 0) | |
11382 | elf_section_data (htab->root.sgot->output_section)->this_hdr.sh_entsize | |
a1bdea65 | 11383 | = GOT_ENTRY_SIZE (htab); |
a06ea964 | 11384 | |
1419bbe5 WN |
11385 | /* Fill PLT and GOT entries for local STT_GNU_IFUNC symbols. */ |
11386 | htab_traverse (htab->loc_hash_table, | |
11387 | elfNN_aarch64_finish_local_dynamic_symbol, | |
11388 | info); | |
11389 | ||
a06ea964 NC |
11390 | return TRUE; |
11391 | } | |
11392 | ||
37c18eed SD |
11393 | /* Check if BTI enabled PLTs are needed. Returns the type needed. */ |
11394 | static aarch64_plt_type | |
11395 | get_plt_type (bfd *abfd) | |
11396 | { | |
11397 | aarch64_plt_type ret = PLT_NORMAL; | |
11398 | bfd_byte *contents, *extdyn, *extdynend; | |
11399 | asection *sec = bfd_get_section_by_name (abfd, ".dynamic"); | |
11400 | if (!sec || !bfd_malloc_and_get_section (abfd, sec, &contents)) | |
11401 | return ret; | |
11402 | extdyn = contents; | |
11403 | extdynend = contents + sec->size; | |
11404 | for (; extdyn < extdynend; extdyn += sizeof (ElfNN_External_Dyn)) | |
11405 | { | |
11406 | Elf_Internal_Dyn dyn; | |
11407 | bfd_elfNN_swap_dyn_in (abfd, extdyn, &dyn); | |
11408 | ||
11409 | /* Let's check the processor specific dynamic array tags. */ | |
11410 | bfd_vma tag = dyn.d_tag; | |
11411 | if (tag < DT_LOPROC || tag > DT_HIPROC) | |
11412 | continue; | |
11413 | ||
11414 | switch (tag) | |
11415 | { | |
11416 | case DT_AARCH64_BTI_PLT: | |
1dbade74 SD |
11417 | ret |= PLT_BTI; |
11418 | break; | |
11419 | ||
11420 | case DT_AARCH64_PAC_PLT: | |
11421 | ret |= PLT_PAC; | |
37c18eed SD |
11422 | break; |
11423 | ||
11424 | default: break; | |
11425 | } | |
11426 | } | |
11427 | free (contents); | |
11428 | return ret; | |
11429 | } | |
11430 | ||
11431 | static long | |
11432 | elfNN_aarch64_get_synthetic_symtab (bfd *abfd, | |
11433 | long symcount, | |
11434 | asymbol **syms, | |
11435 | long dynsymcount, | |
11436 | asymbol **dynsyms, | |
11437 | asymbol **ret) | |
11438 | { | |
11439 | elf_aarch64_tdata (abfd)->plt_type = get_plt_type (abfd); | |
11440 | return _bfd_elf_get_synthetic_symtab (abfd, symcount, syms, | |
11441 | dynsymcount, dynsyms, ret); | |
11442 | } | |
11443 | ||
a06ea964 NC |
11444 | /* Return address for Ith PLT stub in section PLT, for relocation REL |
11445 | or (bfd_vma) -1 if it should not be included. */ | |
11446 | ||
11447 | static bfd_vma | |
cec5225b | 11448 | elfNN_aarch64_plt_sym_val (bfd_vma i, const asection *plt, |
a06ea964 NC |
11449 | const arelent *rel ATTRIBUTE_UNUSED) |
11450 | { | |
37c18eed SD |
11451 | size_t plt0_size = PLT_ENTRY_SIZE; |
11452 | size_t pltn_size = PLT_SMALL_ENTRY_SIZE; | |
11453 | ||
1dbade74 SD |
11454 | if (elf_aarch64_tdata (plt->owner)->plt_type == PLT_BTI_PAC) |
11455 | { | |
1dbade74 SD |
11456 | if (elf_elfheader (plt->owner)->e_type == ET_EXEC) |
11457 | pltn_size = PLT_BTI_PAC_SMALL_ENTRY_SIZE; | |
11458 | else | |
11459 | pltn_size = PLT_PAC_SMALL_ENTRY_SIZE; | |
11460 | } | |
11461 | else if (elf_aarch64_tdata (plt->owner)->plt_type == PLT_BTI) | |
37c18eed | 11462 | { |
37c18eed SD |
11463 | if (elf_elfheader (plt->owner)->e_type == ET_EXEC) |
11464 | pltn_size = PLT_BTI_SMALL_ENTRY_SIZE; | |
11465 | } | |
1dbade74 SD |
11466 | else if (elf_aarch64_tdata (plt->owner)->plt_type == PLT_PAC) |
11467 | { | |
1dbade74 SD |
11468 | pltn_size = PLT_PAC_SMALL_ENTRY_SIZE; |
11469 | } | |
11470 | ||
37c18eed | 11471 | return plt->vma + plt0_size + i * pltn_size; |
a06ea964 NC |
11472 | } |
11473 | ||
d691934d NC |
11474 | /* Returns TRUE if NAME is an AArch64 mapping symbol. |
11475 | The ARM ELF standard defines $x (for A64 code) and $d (for data). | |
11476 | It also allows a period initiated suffix to be added to the symbol, ie: | |
11477 | "$[adtx]\.[:sym_char]+". */ | |
11478 | ||
11479 | static bfd_boolean | |
11480 | is_aarch64_mapping_symbol (const char * name) | |
11481 | { | |
11482 | return name != NULL /* Paranoia. */ | |
11483 | && name[0] == '$' /* Note: if objcopy --prefix-symbols has been used then | |
11484 | the mapping symbols could have acquired a prefix. | |
11485 | We do not support this here, since such symbols no | |
11486 | longer conform to the ARM ELF ABI. */ | |
3979cf50 | 11487 | && (name[1] == 'd' || name[1] == 'x' || name[1] == 'c') |
d691934d NC |
11488 | && (name[2] == 0 || name[2] == '.'); |
11489 | /* FIXME: Strictly speaking the symbol is only a valid mapping symbol if | |
11490 | any characters that follow the period are legal characters for the body | |
11491 | of a symbol's name. For now we just assume that this is the case. */ | |
11492 | } | |
11493 | ||
11494 | /* Make sure that mapping symbols in object files are not removed via the | |
11495 | "strip --strip-unneeded" tool. These symbols might needed in order to | |
11496 | correctly generate linked files. Once an object file has been linked, | |
11497 | it should be safe to remove them. */ | |
11498 | ||
11499 | static void | |
11500 | elfNN_aarch64_backend_symbol_processing (bfd *abfd, asymbol *sym) | |
11501 | { | |
11502 | if (((abfd->flags & (EXEC_P | DYNAMIC)) == 0) | |
11503 | && sym->section != bfd_abs_section_ptr | |
11504 | && is_aarch64_mapping_symbol (sym->name)) | |
11505 | sym->flags |= BSF_KEEP; | |
11506 | } | |
11507 | ||
cd702818 SD |
11508 | /* Implement elf_backend_setup_gnu_properties for AArch64. It serves as a |
11509 | wrapper function for _bfd_aarch64_elf_link_setup_gnu_properties to account | |
11510 | for the effect of GNU properties of the output_bfd. */ | |
11511 | static bfd * | |
11512 | elfNN_aarch64_link_setup_gnu_properties (struct bfd_link_info *info) | |
11513 | { | |
11514 | uint32_t prop = elf_aarch64_tdata (info->output_bfd)->gnu_and_prop; | |
11515 | bfd *pbfd = _bfd_aarch64_elf_link_setup_gnu_properties (info, &prop); | |
11516 | elf_aarch64_tdata (info->output_bfd)->gnu_and_prop = prop; | |
37c18eed SD |
11517 | elf_aarch64_tdata (info->output_bfd)->plt_type |
11518 | |= (prop & GNU_PROPERTY_AARCH64_FEATURE_1_BTI) ? PLT_BTI : 0; | |
cd702818 SD |
11519 | return pbfd; |
11520 | } | |
11521 | ||
11522 | /* Implement elf_backend_merge_gnu_properties for AArch64. It serves as a | |
11523 | wrapper function for _bfd_aarch64_elf_merge_gnu_properties to account | |
11524 | for the effect of GNU properties of the output_bfd. */ | |
11525 | static bfd_boolean | |
11526 | elfNN_aarch64_merge_gnu_properties (struct bfd_link_info *info, | |
4e539114 | 11527 | bfd *abfd, bfd *bbfd, |
cd702818 SD |
11528 | elf_property *aprop, |
11529 | elf_property *bprop) | |
11530 | { | |
11531 | uint32_t prop | |
11532 | = elf_aarch64_tdata (info->output_bfd)->gnu_and_prop; | |
37c18eed SD |
11533 | |
11534 | /* If output has been marked with BTI using command line argument, give out | |
11535 | warning if necessary. */ | |
4e539114 SD |
11536 | /* Properties are merged per type, hence only check for warnings when merging |
11537 | GNU_PROPERTY_AARCH64_FEATURE_1_AND. */ | |
11538 | if (((aprop && aprop->pr_type == GNU_PROPERTY_AARCH64_FEATURE_1_AND) | |
11539 | || (bprop && bprop->pr_type == GNU_PROPERTY_AARCH64_FEATURE_1_AND)) | |
11540 | && (prop & GNU_PROPERTY_AARCH64_FEATURE_1_BTI) | |
37c18eed SD |
11541 | && (!elf_aarch64_tdata (info->output_bfd)->no_bti_warn)) |
11542 | { | |
11543 | if ((aprop && !(aprop->u.number & GNU_PROPERTY_AARCH64_FEATURE_1_BTI)) | |
4e539114 | 11544 | || !aprop) |
37c18eed | 11545 | { |
8bf6d176 | 11546 | _bfd_error_handler (_("%pB: warning: BTI turned on by -z force-bti when " |
4e539114 SD |
11547 | "all inputs do not have BTI in NOTE section."), |
11548 | abfd); | |
11549 | } | |
11550 | if ((bprop && !(bprop->u.number & GNU_PROPERTY_AARCH64_FEATURE_1_BTI)) | |
11551 | || !bprop) | |
11552 | { | |
8bf6d176 | 11553 | _bfd_error_handler (_("%pB: warning: BTI turned on by -z force-bti when " |
4e539114 SD |
11554 | "all inputs do not have BTI in NOTE section."), |
11555 | bbfd); | |
37c18eed SD |
11556 | } |
11557 | } | |
11558 | ||
cd702818 SD |
11559 | return _bfd_aarch64_elf_merge_gnu_properties (info, abfd, aprop, |
11560 | bprop, prop); | |
11561 | } | |
a06ea964 | 11562 | |
8b21361b SP |
11563 | /* Demangle c64 function symbols as we read them in. */ |
11564 | ||
11565 | static bfd_boolean | |
11566 | aarch64_elfNN_swap_symbol_in (bfd * abfd, | |
11567 | const void *psrc, | |
11568 | const void *pshn, | |
11569 | Elf_Internal_Sym *dst) | |
11570 | { | |
11571 | if (!bfd_elfNN_swap_symbol_in (abfd, psrc, pshn, dst)) | |
11572 | return FALSE; | |
11573 | ||
11574 | dst->st_target_internal = 0; | |
11575 | ||
11576 | if (ELF_ST_TYPE (dst->st_info) == STT_FUNC | |
11577 | || ELF_ST_TYPE (dst->st_info) == STT_GNU_IFUNC) | |
11578 | { | |
11579 | dst->st_target_internal = dst->st_value & ST_BRANCH_TO_C64; | |
11580 | dst->st_value &= ~(bfd_vma) ST_BRANCH_TO_C64; | |
11581 | } | |
11582 | ||
11583 | return TRUE; | |
11584 | } | |
11585 | ||
11586 | ||
11587 | /* Mangle c64 function symbols as we write them out. */ | |
11588 | ||
11589 | static void | |
11590 | aarch64_elfNN_swap_symbol_out (bfd *abfd, | |
11591 | const Elf_Internal_Sym *src, | |
11592 | void *cdst, | |
11593 | void *shndx) | |
11594 | { | |
11595 | Elf_Internal_Sym newsym = *src; | |
11596 | ||
11597 | if ((ELF_ST_TYPE (newsym.st_info) == STT_FUNC | |
11598 | || ELF_ST_TYPE (newsym.st_info) == STT_GNU_IFUNC) | |
11599 | && newsym.st_shndx != SHN_UNDEF) | |
11600 | newsym.st_value |= newsym.st_target_internal; | |
11601 | ||
11602 | bfd_elfNN_swap_symbol_out (abfd, &newsym, cdst, shndx); | |
11603 | } | |
11604 | ||
a1bdea65 SP |
11605 | /* Define the size of a GOT element for the generic mid-end. */ |
11606 | ||
11607 | static bfd_vma | |
11608 | elfNN_aarch64_got_elt_size (bfd *abfd ATTRIBUTE_UNUSED, | |
11609 | struct bfd_link_info *info, | |
11610 | struct elf_link_hash_entry *h ATTRIBUTE_UNUSED, | |
11611 | bfd *ibfd ATTRIBUTE_UNUSED, | |
11612 | unsigned long symndx ATTRIBUTE_UNUSED) | |
11613 | { | |
11614 | struct elf_aarch64_link_hash_table *htab = elf_aarch64_hash_table (info); | |
11615 | ||
11616 | return GOT_ENTRY_SIZE (htab); | |
11617 | } | |
11618 | ||
f938669f SP |
11619 | /* Define the size of a GOT header, which is the minimum size of the GOT section |
11620 | when one is needed. */ | |
11621 | ||
11622 | static bfd_vma | |
a1bdea65 | 11623 | elfNN_aarch64_got_header_size (struct bfd_link_info *info) |
f938669f | 11624 | { |
a1bdea65 SP |
11625 | struct elf_aarch64_link_hash_table *htab = elf_aarch64_hash_table (info); |
11626 | ||
11627 | return GOT_ENTRY_SIZE (htab) * GOT_RESERVED_HEADER_SLOTS; | |
f938669f SP |
11628 | } |
11629 | ||
fa6ca5e2 SP |
11630 | /* Identify the 'C' in the CIE augmentation string. */ |
11631 | ||
11632 | static bfd_boolean | |
11633 | elf64_aarch64_eh_frame_augmentation_char (const char aug) | |
11634 | { | |
11635 | return aug == 'C'; | |
11636 | } | |
11637 | ||
a06ea964 NC |
11638 | /* We use this so we can override certain functions |
11639 | (though currently we don't). */ | |
11640 | ||
cec5225b | 11641 | const struct elf_size_info elfNN_aarch64_size_info = |
a06ea964 | 11642 | { |
cec5225b YZ |
11643 | sizeof (ElfNN_External_Ehdr), |
11644 | sizeof (ElfNN_External_Phdr), | |
11645 | sizeof (ElfNN_External_Shdr), | |
11646 | sizeof (ElfNN_External_Rel), | |
11647 | sizeof (ElfNN_External_Rela), | |
11648 | sizeof (ElfNN_External_Sym), | |
11649 | sizeof (ElfNN_External_Dyn), | |
a06ea964 NC |
11650 | sizeof (Elf_External_Note), |
11651 | 4, /* Hash table entry size. */ | |
11652 | 1, /* Internal relocs per external relocs. */ | |
cec5225b YZ |
11653 | ARCH_SIZE, /* Arch size. */ |
11654 | LOG_FILE_ALIGN, /* Log_file_align. */ | |
11655 | ELFCLASSNN, EV_CURRENT, | |
11656 | bfd_elfNN_write_out_phdrs, | |
11657 | bfd_elfNN_write_shdrs_and_ehdr, | |
11658 | bfd_elfNN_checksum_contents, | |
11659 | bfd_elfNN_write_relocs, | |
8b21361b SP |
11660 | aarch64_elfNN_swap_symbol_in, |
11661 | aarch64_elfNN_swap_symbol_out, | |
cec5225b YZ |
11662 | bfd_elfNN_slurp_reloc_table, |
11663 | bfd_elfNN_slurp_symbol_table, | |
11664 | bfd_elfNN_swap_dyn_in, | |
11665 | bfd_elfNN_swap_dyn_out, | |
11666 | bfd_elfNN_swap_reloc_in, | |
11667 | bfd_elfNN_swap_reloc_out, | |
11668 | bfd_elfNN_swap_reloca_in, | |
11669 | bfd_elfNN_swap_reloca_out | |
a06ea964 NC |
11670 | }; |
11671 | ||
11672 | #define ELF_ARCH bfd_arch_aarch64 | |
11673 | #define ELF_MACHINE_CODE EM_AARCH64 | |
11674 | #define ELF_MAXPAGESIZE 0x10000 | |
11675 | #define ELF_MINPAGESIZE 0x1000 | |
11676 | #define ELF_COMMONPAGESIZE 0x1000 | |
11677 | ||
cec5225b YZ |
11678 | #define bfd_elfNN_bfd_is_target_special_symbol \ |
11679 | elfNN_aarch64_is_target_special_symbol | |
a06ea964 | 11680 | |
07d6d2b8 | 11681 | #define bfd_elfNN_bfd_link_hash_table_create \ |
cec5225b | 11682 | elfNN_aarch64_link_hash_table_create |
a06ea964 | 11683 | |
cec5225b YZ |
11684 | #define bfd_elfNN_bfd_merge_private_bfd_data \ |
11685 | elfNN_aarch64_merge_private_bfd_data | |
a06ea964 | 11686 | |
cec5225b YZ |
11687 | #define bfd_elfNN_bfd_print_private_bfd_data \ |
11688 | elfNN_aarch64_print_private_bfd_data | |
a06ea964 | 11689 | |
cec5225b YZ |
11690 | #define bfd_elfNN_bfd_reloc_type_lookup \ |
11691 | elfNN_aarch64_reloc_type_lookup | |
a06ea964 | 11692 | |
cec5225b YZ |
11693 | #define bfd_elfNN_bfd_reloc_name_lookup \ |
11694 | elfNN_aarch64_reloc_name_lookup | |
a06ea964 | 11695 | |
cec5225b YZ |
11696 | #define bfd_elfNN_bfd_set_private_flags \ |
11697 | elfNN_aarch64_set_private_flags | |
a06ea964 | 11698 | |
cec5225b YZ |
11699 | #define bfd_elfNN_find_inliner_info \ |
11700 | elfNN_aarch64_find_inliner_info | |
a06ea964 | 11701 | |
37c18eed SD |
11702 | #define bfd_elfNN_get_synthetic_symtab \ |
11703 | elfNN_aarch64_get_synthetic_symtab | |
11704 | ||
cec5225b YZ |
11705 | #define bfd_elfNN_mkobject \ |
11706 | elfNN_aarch64_mkobject | |
a06ea964 | 11707 | |
cec5225b YZ |
11708 | #define bfd_elfNN_new_section_hook \ |
11709 | elfNN_aarch64_new_section_hook | |
a06ea964 NC |
11710 | |
11711 | #define elf_backend_adjust_dynamic_symbol \ | |
cec5225b | 11712 | elfNN_aarch64_adjust_dynamic_symbol |
a06ea964 NC |
11713 | |
11714 | #define elf_backend_always_size_sections \ | |
cec5225b | 11715 | elfNN_aarch64_always_size_sections |
a06ea964 NC |
11716 | |
11717 | #define elf_backend_check_relocs \ | |
cec5225b | 11718 | elfNN_aarch64_check_relocs |
a06ea964 NC |
11719 | |
11720 | #define elf_backend_copy_indirect_symbol \ | |
cec5225b | 11721 | elfNN_aarch64_copy_indirect_symbol |
a06ea964 | 11722 | |
823710d5 SN |
11723 | #define elf_backend_merge_symbol_attribute \ |
11724 | elfNN_aarch64_merge_symbol_attribute | |
11725 | ||
a06ea964 NC |
11726 | /* Create .dynbss, and .rela.bss sections in DYNOBJ, and set up shortcuts |
11727 | to them in our hash. */ | |
11728 | #define elf_backend_create_dynamic_sections \ | |
cec5225b | 11729 | elfNN_aarch64_create_dynamic_sections |
a06ea964 NC |
11730 | |
11731 | #define elf_backend_init_index_section \ | |
11732 | _bfd_elf_init_2_index_sections | |
11733 | ||
a06ea964 | 11734 | #define elf_backend_finish_dynamic_sections \ |
cec5225b | 11735 | elfNN_aarch64_finish_dynamic_sections |
a06ea964 NC |
11736 | |
11737 | #define elf_backend_finish_dynamic_symbol \ | |
cec5225b | 11738 | elfNN_aarch64_finish_dynamic_symbol |
a06ea964 | 11739 | |
a06ea964 | 11740 | #define elf_backend_object_p \ |
cec5225b | 11741 | elfNN_aarch64_object_p |
a06ea964 | 11742 | |
07d6d2b8 | 11743 | #define elf_backend_output_arch_local_syms \ |
cec5225b | 11744 | elfNN_aarch64_output_arch_local_syms |
a06ea964 | 11745 | |
e7679060 AM |
11746 | #define elf_backend_maybe_function_sym \ |
11747 | elfNN_aarch64_maybe_function_sym | |
11748 | ||
a06ea964 | 11749 | #define elf_backend_plt_sym_val \ |
cec5225b | 11750 | elfNN_aarch64_plt_sym_val |
a06ea964 | 11751 | |
ed7e9d0b AM |
11752 | #define elf_backend_init_file_header \ |
11753 | elfNN_aarch64_init_file_header | |
a06ea964 NC |
11754 | |
11755 | #define elf_backend_relocate_section \ | |
cec5225b | 11756 | elfNN_aarch64_relocate_section |
a06ea964 NC |
11757 | |
11758 | #define elf_backend_reloc_type_class \ | |
cec5225b | 11759 | elfNN_aarch64_reloc_type_class |
a06ea964 | 11760 | |
a06ea964 | 11761 | #define elf_backend_section_from_shdr \ |
cec5225b | 11762 | elfNN_aarch64_section_from_shdr |
a06ea964 NC |
11763 | |
11764 | #define elf_backend_size_dynamic_sections \ | |
cec5225b | 11765 | elfNN_aarch64_size_dynamic_sections |
a06ea964 NC |
11766 | |
11767 | #define elf_backend_size_info \ | |
cec5225b | 11768 | elfNN_aarch64_size_info |
a06ea964 | 11769 | |
68fcca92 JW |
11770 | #define elf_backend_write_section \ |
11771 | elfNN_aarch64_write_section | |
11772 | ||
d691934d NC |
11773 | #define elf_backend_symbol_processing \ |
11774 | elfNN_aarch64_backend_symbol_processing | |
11775 | ||
cd702818 SD |
11776 | #define elf_backend_setup_gnu_properties \ |
11777 | elfNN_aarch64_link_setup_gnu_properties | |
11778 | ||
11779 | #define elf_backend_merge_gnu_properties \ | |
11780 | elfNN_aarch64_merge_gnu_properties | |
11781 | ||
f938669f SP |
11782 | #define elf_backend_got_header_size \ |
11783 | elfNN_aarch64_got_header_size | |
11784 | ||
a1bdea65 SP |
11785 | #define elf_backend_got_elt_size \ |
11786 | elfNN_aarch64_got_elt_size | |
11787 | ||
fa6ca5e2 SP |
11788 | #define elf_backend_eh_frame_augmentation_char \ |
11789 | elf64_aarch64_eh_frame_augmentation_char | |
11790 | ||
a06ea964 | 11791 | #define elf_backend_can_refcount 1 |
59c108f7 | 11792 | #define elf_backend_can_gc_sections 1 |
a06ea964 NC |
11793 | #define elf_backend_plt_readonly 1 |
11794 | #define elf_backend_want_got_plt 1 | |
11795 | #define elf_backend_want_plt_sym 0 | |
5474d94f | 11796 | #define elf_backend_want_dynrelro 1 |
a06ea964 NC |
11797 | #define elf_backend_may_use_rel_p 0 |
11798 | #define elf_backend_may_use_rela_p 1 | |
11799 | #define elf_backend_default_use_rela_p 1 | |
07d6d2b8 | 11800 | #define elf_backend_rela_normal 1 |
64f52338 | 11801 | #define elf_backend_dtrel_excludes_plt 1 |
c495064d | 11802 | #define elf_backend_default_execstack 0 |
32f573bc | 11803 | #define elf_backend_extern_protected_data 1 |
7f784814 | 11804 | #define elf_backend_hash_symbol elf_aarch64_hash_symbol |
a06ea964 | 11805 | |
07d6d2b8 | 11806 | #undef elf_backend_obj_attrs_section |
a06ea964 NC |
11807 | #define elf_backend_obj_attrs_section ".ARM.attributes" |
11808 | ||
cec5225b | 11809 | #include "elfNN-target.h" |
a75cf613 ES |
11810 | |
11811 | /* CloudABI support. */ | |
11812 | ||
11813 | #undef TARGET_LITTLE_SYM | |
11814 | #define TARGET_LITTLE_SYM aarch64_elfNN_le_cloudabi_vec | |
11815 | #undef TARGET_LITTLE_NAME | |
11816 | #define TARGET_LITTLE_NAME "elfNN-littleaarch64-cloudabi" | |
11817 | #undef TARGET_BIG_SYM | |
11818 | #define TARGET_BIG_SYM aarch64_elfNN_be_cloudabi_vec | |
11819 | #undef TARGET_BIG_NAME | |
11820 | #define TARGET_BIG_NAME "elfNN-bigaarch64-cloudabi" | |
11821 | ||
11822 | #undef ELF_OSABI | |
11823 | #define ELF_OSABI ELFOSABI_CLOUDABI | |
11824 | ||
11825 | #undef elfNN_bed | |
11826 | #define elfNN_bed elfNN_aarch64_cloudabi_bed | |
11827 | ||
11828 | #include "elfNN-target.h" |